summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/.cvsignore16
-rw-r--r--cpukit/ChangeLog13199
-rw-r--r--cpukit/ChangeLog-pre20079531
-rw-r--r--cpukit/Doxyfile.in1561
-rw-r--r--cpukit/Makefile.am193
-rw-r--r--cpukit/NEWS7
-rw-r--r--cpukit/acinclude.m461
-rw-r--r--cpukit/aclocal/canonical-target-name.m427
-rw-r--r--cpukit/aclocal/canonicalize-tools.m415
-rw-r--r--cpukit/aclocal/check-func.m423
-rw-r--r--cpukit/aclocal/check-multiprocessing.m49
-rw-r--r--cpukit/aclocal/check-networking.m432
-rw-r--r--cpukit/aclocal/check-newlib.m430
-rw-r--r--cpukit/aclocal/check-posix.m420
-rw-r--r--cpukit/aclocal/check-rtems-debug.m47
-rw-r--r--cpukit/aclocal/check-smp.m419
-rw-r--r--cpukit/aclocal/check-tool.m411
-rw-r--r--cpukit/aclocal/enable-multiprocessing.m412
-rw-r--r--cpukit/aclocal/enable-networking.m414
-rw-r--r--cpukit/aclocal/enable-posix.m423
-rw-r--r--cpukit/aclocal/enable-rtems-debug.m412
-rw-r--r--cpukit/aclocal/enable-smp.m418
-rw-r--r--cpukit/aclocal/env-rtemscpu.m48
-rw-r--r--cpukit/aclocal/gcc-pipe.m421
-rw-r--r--cpukit/aclocal/gcc-sanity.m4114
-rw-r--r--cpukit/aclocal/gcc-weak.m419
-rw-r--r--cpukit/aclocal/multi.m450
-rw-r--r--cpukit/aclocal/multilib.m414
-rw-r--r--cpukit/aclocal/prog-cc.m441
-rw-r--r--cpukit/aclocal/prog-ccas.m48
-rw-r--r--cpukit/aclocal/rtems-ampolish.m412
-rw-r--r--cpukit/aclocal/rtems-top.m472
-rw-r--r--cpukit/aclocal/version.m44
-rw-r--r--cpukit/automake/compile.am10
-rw-r--r--cpukit/automake/local.am5
-rw-r--r--cpukit/automake/multilib.am36
-rw-r--r--cpukit/automake/subdirs.am32
-rw-r--r--cpukit/configure.ac370
-rwxr-xr-xcpukit/doxy-filter21
-rw-r--r--cpukit/ftpd/.cvsignore2
-rw-r--r--cpukit/ftpd/Makefile.am13
-rw-r--r--cpukit/ftpd/ftpd.c2080
-rw-r--r--cpukit/ftpd/ftpd.h65
-rw-r--r--cpukit/ftpd/preinstall.am25
-rw-r--r--cpukit/include/rtems/bsd/sys/cdefs.h180
-rw-r--r--cpukit/include/rtems/bsd/sys/queue.h602
-rw-r--r--cpukit/include/rtems/bspIo.h76
-rw-r--r--cpukit/include/rtems/btimer.h54
-rw-r--r--cpukit/include/rtems/concat.h22
-rw-r--r--cpukit/include/rtems/endian.h224
-rw-r--r--cpukit/include/rtems/fs.h65
-rw-r--r--cpukit/include/rtems/irq-extension.h270
-rw-r--r--cpukit/include/rtems/irq.h214
-rw-r--r--cpukit/include/rtems/pci.h1236
-rw-r--r--cpukit/include/rtems/status-checks.h345
-rw-r--r--cpukit/include/rtems/userenv.h88
-rw-r--r--cpukit/include/sys/priority.h2
-rw-r--r--cpukit/libblock/.cvsignore2
-rw-r--r--cpukit/libblock/Makefile.am37
-rw-r--r--cpukit/libblock/README14
-rw-r--r--cpukit/libblock/include/rtems/bdbuf.h594
-rw-r--r--cpukit/libblock/include/rtems/bdpart.h409
-rw-r--r--cpukit/libblock/include/rtems/blkdev.h276
-rw-r--r--cpukit/libblock/include/rtems/diskdevs.h341
-rw-r--r--cpukit/libblock/include/rtems/flashdisk.h366
-rw-r--r--cpukit/libblock/include/rtems/ide_part_table.h217
-rw-r--r--cpukit/libblock/include/rtems/media.h521
-rw-r--r--cpukit/libblock/include/rtems/nvdisk-sram.h25
-rw-r--r--cpukit/libblock/include/rtems/nvdisk.h209
-rw-r--r--cpukit/libblock/include/rtems/ramdisk.h243
-rw-r--r--cpukit/libblock/src/bdbuf.c2989
-rw-r--r--cpukit/libblock/src/bdpart-create.c160
-rw-r--r--cpukit/libblock/src/bdpart-dump.c97
-rw-r--r--cpukit/libblock/src/bdpart-mount.c184
-rw-r--r--cpukit/libblock/src/bdpart-read.c348
-rw-r--r--cpukit/libblock/src/bdpart-register.c163
-rw-r--r--cpukit/libblock/src/bdpart-sort.c48
-rw-r--r--cpukit/libblock/src/bdpart-write.c302
-rw-r--r--cpukit/libblock/src/blkdev-ops.c32
-rw-r--r--cpukit/libblock/src/blkdev.c263
-rw-r--r--cpukit/libblock/src/diskdevs.c589
-rw-r--r--cpukit/libblock/src/flashdisk.c2603
-rw-r--r--cpukit/libblock/src/ide_part_table.c594
-rw-r--r--cpukit/libblock/src/media-desc.c72
-rw-r--r--cpukit/libblock/src/media-dev-ident.c47
-rw-r--r--cpukit/libblock/src/media-path.c86
-rw-r--r--cpukit/libblock/src/media-server.c152
-rw-r--r--cpukit/libblock/src/media.c1012
-rw-r--r--cpukit/libblock/src/nvdisk-sram.c68
-rw-r--r--cpukit/libblock/src/nvdisk.c845
-rw-r--r--cpukit/libblock/src/ramdisk-config.c90
-rw-r--r--cpukit/libblock/src/ramdisk-driver.c134
-rw-r--r--cpukit/libblock/src/ramdisk-init.c126
-rw-r--r--cpukit/libblock/src/show_bdbuf.c909
-rw-r--r--cpukit/libcsupport/.cvsignore2
-rw-r--r--cpukit/libcsupport/Makefile.am133
-rw-r--r--cpukit/libcsupport/include/clockdrv.h52
-rw-r--r--cpukit/libcsupport/include/console.h162
-rw-r--r--cpukit/libcsupport/include/iosupp.h46
-rw-r--r--cpukit/libcsupport/include/motorola/mc68230.h74
-rw-r--r--cpukit/libcsupport/include/motorola/mc68681.h309
-rw-r--r--cpukit/libcsupport/include/ringbuf.h55
-rw-r--r--cpukit/libcsupport/include/rtc.h116
-rw-r--r--cpukit/libcsupport/include/rtems/assoc.h120
-rw-r--r--cpukit/libcsupport/include/rtems/error.h60
-rw-r--r--cpukit/libcsupport/include/rtems/framebuffer.h158
-rwxr-xr-xcpukit/libcsupport/include/rtems/gxx_wrappers.h78
-rw-r--r--cpukit/libcsupport/include/rtems/libcsupport.h81
-rw-r--r--cpukit/libcsupport/include/rtems/libio.h1685
-rw-r--r--cpukit/libcsupport/include/rtems/libio_.h246
-rw-r--r--cpukit/libcsupport/include/rtems/malloc.h186
-rw-r--r--cpukit/libcsupport/include/rtems/termiostypes.h210
-rw-r--r--cpukit/libcsupport/include/rtems/watchdogdrv.h73
-rw-r--r--cpukit/libcsupport/include/spurious.h45
-rw-r--r--cpukit/libcsupport/include/sys/filio.h59
-rw-r--r--cpukit/libcsupport/include/sys/ioccom.h104
-rw-r--r--cpukit/libcsupport/include/sys/ioctl.h66
-rw-r--r--cpukit/libcsupport/include/sys/sockio.h92
-rw-r--r--cpukit/libcsupport/include/sys/statvfs.h52
-rw-r--r--cpukit/libcsupport/include/sys/termios.h198
-rw-r--r--cpukit/libcsupport/include/sys/ttycom.h141
-rw-r--r--cpukit/libcsupport/include/sys/utsname.h52
-rw-r--r--cpukit/libcsupport/include/timerdrv.h34
-rw-r--r--cpukit/libcsupport/include/vmeintr.h59
-rw-r--r--cpukit/libcsupport/include/zilog/z8036.h106
-rw-r--r--cpukit/libcsupport/include/zilog/z8530.h97
-rw-r--r--cpukit/libcsupport/include/zilog/z8536.h114
-rw-r--r--cpukit/libcsupport/preinstall.am118
-rw-r--r--cpukit/libcsupport/src/CASES23
-rw-r--r--cpukit/libcsupport/src/README37
-rw-r--r--cpukit/libcsupport/src/TODO14
-rw-r--r--cpukit/libcsupport/src/__assert.c52
-rw-r--r--cpukit/libcsupport/src/__getpid.c17
-rw-r--r--cpukit/libcsupport/src/__gettod.c86
-rw-r--r--cpukit/libcsupport/src/__times.c114
-rw-r--r--cpukit/libcsupport/src/__usrenv.c27
-rw-r--r--cpukit/libcsupport/src/_calloc_r.c30
-rw-r--r--cpukit/libcsupport/src/_free_r.c29
-rw-r--r--cpukit/libcsupport/src/_malloc_r.c29
-rw-r--r--cpukit/libcsupport/src/_realloc_r.c30
-rw-r--r--cpukit/libcsupport/src/_rename_r.c113
-rw-r--r--cpukit/libcsupport/src/access.c48
-rw-r--r--cpukit/libcsupport/src/assoclocalbyname.c31
-rw-r--r--cpukit/libcsupport/src/assoclocalbyremote.c31
-rw-r--r--cpukit/libcsupport/src/assoclocalbyremotebitfield.c34
-rw-r--r--cpukit/libcsupport/src/assocnamebad.c40
-rw-r--r--cpukit/libcsupport/src/assocnamebylocal.c31
-rw-r--r--cpukit/libcsupport/src/assocnamebylocalbitfield.c38
-rw-r--r--cpukit/libcsupport/src/assocnamebyremote.c33
-rw-r--r--cpukit/libcsupport/src/assocnamebyremotebitfield.c39
-rw-r--r--cpukit/libcsupport/src/assocptrbylocal.c34
-rw-r--r--cpukit/libcsupport/src/assocptrbyname.c35
-rw-r--r--cpukit/libcsupport/src/assocptrbyremote.c34
-rw-r--r--cpukit/libcsupport/src/assocremotebylocal.c31
-rw-r--r--cpukit/libcsupport/src/assocremotebylocalbitfield.c33
-rw-r--r--cpukit/libcsupport/src/assocremotebyname.c31
-rw-r--r--cpukit/libcsupport/src/base_fs.c114
-rw-r--r--cpukit/libcsupport/src/calloc.c41
-rw-r--r--cpukit/libcsupport/src/cfgetispeed.c32
-rw-r--r--cpukit/libcsupport/src/cfgetospeed.c32
-rw-r--r--cpukit/libcsupport/src/cfsetispeed.c40
-rw-r--r--cpukit/libcsupport/src/cfsetospeed.c40
-rw-r--r--cpukit/libcsupport/src/chdir.c57
-rw-r--r--cpukit/libcsupport/src/chmod.c46
-rw-r--r--cpukit/libcsupport/src/chown.c54
-rw-r--r--cpukit/libcsupport/src/chroot.c55
-rw-r--r--cpukit/libcsupport/src/close.c57
-rw-r--r--cpukit/libcsupport/src/ctermid.c42
-rw-r--r--cpukit/libcsupport/src/dup.c26
-rw-r--r--cpukit/libcsupport/src/dup2.c52
-rw-r--r--cpukit/libcsupport/src/envlock.c108
-rw-r--r--cpukit/libcsupport/src/error.c209
-rw-r--r--cpukit/libcsupport/src/eval.c151
-rw-r--r--cpukit/libcsupport/src/fchdir.c82
-rw-r--r--cpukit/libcsupport/src/fchmod.c45
-rw-r--r--cpukit/libcsupport/src/fchown.c42
-rw-r--r--cpukit/libcsupport/src/fcntl.c184
-rw-r--r--cpukit/libcsupport/src/fdatasync.c39
-rw-r--r--cpukit/libcsupport/src/flockfile.c22
-rw-r--r--cpukit/libcsupport/src/fpathconf.c87
-rw-r--r--cpukit/libcsupport/src/free.c55
-rw-r--r--cpukit/libcsupport/src/freenode.c20
-rw-r--r--cpukit/libcsupport/src/fstat.c72
-rw-r--r--cpukit/libcsupport/src/fsync.c39
-rw-r--r--cpukit/libcsupport/src/ftruncate.c51
-rw-r--r--cpukit/libcsupport/src/ftrylockfile.c25
-rw-r--r--cpukit/libcsupport/src/funlockfile.c22
-rw-r--r--cpukit/libcsupport/src/getchark.c25
-rw-r--r--cpukit/libcsupport/src/getcwd.c291
-rw-r--r--cpukit/libcsupport/src/getdents.c55
-rw-r--r--cpukit/libcsupport/src/getegid.c24
-rw-r--r--cpukit/libcsupport/src/geteuid.c31
-rw-r--r--cpukit/libcsupport/src/getgid.c18
-rw-r--r--cpukit/libcsupport/src/getgroups.c23
-rw-r--r--cpukit/libcsupport/src/getlogin.c61
-rw-r--r--cpukit/libcsupport/src/getpagesize.c22
-rw-r--r--cpukit/libcsupport/src/getpgrp.c31
-rw-r--r--cpukit/libcsupport/src/getpid.c41
-rw-r--r--cpukit/libcsupport/src/getppid.c25
-rw-r--r--cpukit/libcsupport/src/getpwent.c438
-rw-r--r--cpukit/libcsupport/src/getrusage.c54
-rw-r--r--cpukit/libcsupport/src/getuid.c28
-rw-r--r--cpukit/libcsupport/src/gxx_wrappers.c295
-rw-r--r--cpukit/libcsupport/src/ioctl.c54
-rw-r--r--cpukit/libcsupport/src/isatty.c35
-rw-r--r--cpukit/libcsupport/src/isatty_r.c35
-rw-r--r--cpukit/libcsupport/src/issetugid.c16
-rw-r--r--cpukit/libcsupport/src/kill_noposix.c48
-rw-r--r--cpukit/libcsupport/src/lchown.c31
-rw-r--r--cpukit/libcsupport/src/libio.c278
-rw-r--r--cpukit/libcsupport/src/libio_init.c89
-rw-r--r--cpukit/libcsupport/src/libio_sockets.c73
-rw-r--r--cpukit/libcsupport/src/link.c94
-rw-r--r--cpukit/libcsupport/src/lseek.c94
-rw-r--r--cpukit/libcsupport/src/lstat.c22
-rw-r--r--cpukit/libcsupport/src/malloc.c83
-rw-r--r--cpukit/libcsupport/src/malloc_deferred.c60
-rw-r--r--cpukit/libcsupport/src/malloc_dirtier.c30
-rw-r--r--cpukit/libcsupport/src/malloc_get_statistics.c33
-rw-r--r--cpukit/libcsupport/src/malloc_initialize.c114
-rw-r--r--cpukit/libcsupport/src/malloc_p.h45
-rw-r--r--cpukit/libcsupport/src/malloc_report_statistics.c26
-rw-r--r--cpukit/libcsupport/src/malloc_report_statistics_plugin.c61
-rw-r--r--cpukit/libcsupport/src/malloc_sbrk_helpers.c112
-rw-r--r--cpukit/libcsupport/src/malloc_statistics_helpers.c75
-rw-r--r--cpukit/libcsupport/src/malloc_walk.c28
-rw-r--r--cpukit/libcsupport/src/mallocfreespace.c42
-rw-r--r--cpukit/libcsupport/src/mallocgetheapptr.c26
-rw-r--r--cpukit/libcsupport/src/mallocinfo.c39
-rw-r--r--cpukit/libcsupport/src/mallocsetheapptr.c28
-rw-r--r--cpukit/libcsupport/src/mkdir.c30
-rw-r--r--cpukit/libcsupport/src/mkfifo.c28
-rw-r--r--cpukit/libcsupport/src/mknod.c73
-rw-r--r--cpukit/libcsupport/src/mount-mgr.c169
-rw-r--r--cpukit/libcsupport/src/mount-mktgt.c56
-rw-r--r--cpukit/libcsupport/src/mount.c282
-rw-r--r--cpukit/libcsupport/src/newlibc_exit.c160
-rw-r--r--cpukit/libcsupport/src/newlibc_init.c41
-rw-r--r--cpukit/libcsupport/src/newlibc_reent.c170
-rw-r--r--cpukit/libcsupport/src/open.c215
-rw-r--r--cpukit/libcsupport/src/open_dev_console.c51
-rw-r--r--cpukit/libcsupport/src/pathconf.c41
-rw-r--r--cpukit/libcsupport/src/pipe.c32
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c44
-rw-r--r--cpukit/libcsupport/src/printk.c39
-rw-r--r--cpukit/libcsupport/src/printk_plugin.c34
-rw-r--r--cpukit/libcsupport/src/privateenv.c204
-rw-r--r--cpukit/libcsupport/src/putk.c30
-rw-r--r--cpukit/libcsupport/src/read.c67
-rw-r--r--cpukit/libcsupport/src/readdir_r.c30
-rw-r--r--cpukit/libcsupport/src/readlink.c48
-rw-r--r--cpukit/libcsupport/src/readv.c120
-rw-r--r--cpukit/libcsupport/src/realloc.c88
-rw-r--r--cpukit/libcsupport/src/rmdir.c95
-rw-r--r--cpukit/libcsupport/src/rtems_heap_extend.c45
-rw-r--r--cpukit/libcsupport/src/rtems_malloc.c56
-rw-r--r--cpukit/libcsupport/src/rtems_memalign.c72
-rw-r--r--cpukit/libcsupport/src/rtems_mkdir.c141
-rw-r--r--cpukit/libcsupport/src/setegid.c26
-rw-r--r--cpukit/libcsupport/src/seteuid.c24
-rw-r--r--cpukit/libcsupport/src/setgid.c21
-rw-r--r--cpukit/libcsupport/src/setpgid.c24
-rw-r--r--cpukit/libcsupport/src/setsid.c21
-rw-r--r--cpukit/libcsupport/src/setuid.c30
-rw-r--r--cpukit/libcsupport/src/stat.c97
-rw-r--r--cpukit/libcsupport/src/statvfs.c52
-rw-r--r--cpukit/libcsupport/src/strlcat.c41
-rw-r--r--cpukit/libcsupport/src/strlcpy.c49
-rw-r--r--cpukit/libcsupport/src/sup_fs_get_start_loc.c48
-rw-r--r--cpukit/libcsupport/src/sup_fs_get_sym_start_loc.c47
-rw-r--r--cpukit/libcsupport/src/sup_fs_is_separator.c30
-rw-r--r--cpukit/libcsupport/src/symlink.c42
-rw-r--r--cpukit/libcsupport/src/sync.c101
-rw-r--r--cpukit/libcsupport/src/tcdrain.c36
-rw-r--r--cpukit/libcsupport/src/tcflow.c44
-rw-r--r--cpukit/libcsupport/src/tcflush.c50
-rw-r--r--cpukit/libcsupport/src/tcgetattr.c36
-rw-r--r--cpukit/libcsupport/src/tcgetpgrp.c28
-rw-r--r--cpukit/libcsupport/src/tcsendbreak.c36
-rw-r--r--cpukit/libcsupport/src/tcsetattr.c51
-rw-r--r--cpukit/libcsupport/src/tcsetpgrp.c36
-rw-r--r--cpukit/libcsupport/src/termios.c1480
-rw-r--r--cpukit/libcsupport/src/termios_baud2index.c50
-rw-r--r--cpukit/libcsupport/src/termios_baud2num.c33
-rw-r--r--cpukit/libcsupport/src/termios_baudtable.c42
-rw-r--r--cpukit/libcsupport/src/termios_num2baud.c32
-rw-r--r--cpukit/libcsupport/src/termios_setinitialbaud.c33
-rw-r--r--cpukit/libcsupport/src/termiosinitialize.c54
-rw-r--r--cpukit/libcsupport/src/truncate.c43
-rw-r--r--cpukit/libcsupport/src/ttyname.c118
-rw-r--r--cpukit/libcsupport/src/umask.c33
-rw-r--r--cpukit/libcsupport/src/unlink.c103
-rw-r--r--cpukit/libcsupport/src/unmount.c162
-rw-r--r--cpukit/libcsupport/src/utime.c47
-rw-r--r--cpukit/libcsupport/src/utimes.c33
-rw-r--r--cpukit/libcsupport/src/utsname.c49
-rw-r--r--cpukit/libcsupport/src/vprintk.c191
-rw-r--r--cpukit/libcsupport/src/write.c53
-rw-r--r--cpukit/libcsupport/src/write_r.c40
-rw-r--r--cpukit/libcsupport/src/writev.c128
-rw-r--r--cpukit/libfs/.cvsignore3
-rw-r--r--cpukit/libfs/Makefile.am103
-rw-r--r--cpukit/libfs/README29
-rw-r--r--cpukit/libfs/preinstall.am7
-rw-r--r--cpukit/libfs/src/defaults/default_chown.c23
-rw-r--r--cpukit/libfs/src/defaults/default_close.c19
-rw-r--r--cpukit/libfs/src/defaults/default_evalformake.c32
-rw-r--r--cpukit/libfs/src/defaults/default_evalpath.c25
-rw-r--r--cpukit/libfs/src/defaults/default_evaluate_link.c23
-rw-r--r--cpukit/libfs/src/defaults/default_fchmod.c22
-rw-r--r--cpukit/libfs/src/defaults/default_fcntl.c22
-rw-r--r--cpukit/libfs/src/defaults/default_fdatasync.c21
-rw-r--r--cpukit/libfs/src/defaults/default_fpathconf.c22
-rw-r--r--cpukit/libfs/src/defaults/default_freenode.c22
-rw-r--r--cpukit/libfs/src/defaults/default_fsmount.c22
-rw-r--r--cpukit/libfs/src/defaults/default_fstat.c22
-rw-r--r--cpukit/libfs/src/defaults/default_fsunmount.c21
-rw-r--r--cpukit/libfs/src/defaults/default_fsync.c21
-rw-r--r--cpukit/libfs/src/defaults/default_ftruncate.c22
-rw-r--r--cpukit/libfs/src/defaults/default_handlers.c39
-rw-r--r--cpukit/libfs/src/defaults/default_ioctl.c23
-rw-r--r--cpukit/libfs/src/defaults/default_link.c24
-rw-r--r--cpukit/libfs/src/defaults/default_lseek.c23
-rw-r--r--cpukit/libfs/src/defaults/default_mknod.c24
-rw-r--r--cpukit/libfs/src/defaults/default_mount.c21
-rw-r--r--cpukit/libfs/src/defaults/default_node_type.c29
-rw-r--r--cpukit/libfs/src/defaults/default_open.c24
-rw-r--r--cpukit/libfs/src/defaults/default_ops.c43
-rw-r--r--cpukit/libfs/src/defaults/default_read.c23
-rw-r--r--cpukit/libfs/src/defaults/default_readlink.c23
-rw-r--r--cpukit/libfs/src/defaults/default_rename.c24
-rw-r--r--cpukit/libfs/src/defaults/default_rmnod.c22
-rw-r--r--cpukit/libfs/src/defaults/default_statvfs.c22
-rw-r--r--cpukit/libfs/src/defaults/default_symlink.c23
-rw-r--r--cpukit/libfs/src/defaults/default_unlink.c22
-rw-r--r--cpukit/libfs/src/defaults/default_unmount.c21
-rw-r--r--cpukit/libfs/src/defaults/default_utime.c24
-rw-r--r--cpukit/libfs/src/defaults/default_write.c23
-rw-r--r--cpukit/libfs/src/devfs/devclose.c41
-rw-r--r--cpukit/libfs/src/devfs/devfs.h280
-rw-r--r--cpukit/libfs/src/devfs/devfs_eval.c85
-rw-r--r--cpukit/libfs/src/devfs/devfs_init.c92
-rw-r--r--cpukit/libfs/src/devfs/devfs_mknod.c81
-rw-r--r--cpukit/libfs/src/devfs/devfs_node_type.c26
-rw-r--r--cpukit/libfs/src/devfs/devfs_show.c36
-rw-r--r--cpukit/libfs/src/devfs/devioctl.c45
-rw-r--r--cpukit/libfs/src/devfs/devopen.c42
-rw-r--r--cpukit/libfs/src/devfs/devread.c48
-rw-r--r--cpukit/libfs/src/devfs/devstat.c46
-rw-r--r--cpukit/libfs/src/devfs/devwrite.c48
-rw-r--r--cpukit/libfs/src/dosfs/.cvsignore4
-rw-r--r--cpukit/libfs/src/dosfs/dosfs.h88
-rw-r--r--cpukit/libfs/src/dosfs/fat.c863
-rw-r--r--cpukit/libfs/src/dosfs/fat.h517
-rw-r--r--cpukit/libfs/src/dosfs/fat_fat_operations.c436
-rw-r--r--cpukit/libfs/src/dosfs/fat_fat_operations.h59
-rw-r--r--cpukit/libfs/src/dosfs/fat_file.c993
-rw-r--r--cpukit/libfs/src/dosfs/fat_file.h192
-rw-r--r--cpukit/libfs/src/dosfs/msdos.h467
-rw-r--r--cpukit/libfs/src/dosfs/msdos_conv.c317
-rw-r--r--cpukit/libfs/src/dosfs/msdos_create.c267
-rw-r--r--cpukit/libfs/src/dosfs/msdos_dir.c706
-rw-r--r--cpukit/libfs/src/dosfs/msdos_eval.c437
-rw-r--r--cpukit/libfs/src/dosfs/msdos_file.c503
-rw-r--r--cpukit/libfs/src/dosfs/msdos_format.c1127
-rw-r--r--cpukit/libfs/src/dosfs/msdos_free.c56
-rw-r--r--cpukit/libfs/src/dosfs/msdos_fsunmount.c70
-rw-r--r--cpukit/libfs/src/dosfs/msdos_handlers_dir.c36
-rw-r--r--cpukit/libfs/src/dosfs/msdos_handlers_file.c36
-rw-r--r--cpukit/libfs/src/dosfs/msdos_init.c64
-rw-r--r--cpukit/libfs/src/dosfs/msdos_initsupp.c149
-rw-r--r--cpukit/libfs/src/dosfs/msdos_misc.c1731
-rw-r--r--cpukit/libfs/src/dosfs/msdos_mknod.c84
-rw-r--r--cpukit/libfs/src/dosfs/msdos_node_type.c58
-rw-r--r--cpukit/libfs/src/dosfs/msdos_rename.c92
-rw-r--r--cpukit/libfs/src/imfs/.cvsignore5
-rw-r--r--cpukit/libfs/src/imfs/deviceerrno.c73
-rw-r--r--cpukit/libfs/src/imfs/deviceio.c233
-rw-r--r--cpukit/libfs/src/imfs/fifoimfs_init.c61
-rw-r--r--cpukit/libfs/src/imfs/imfs.h574
-rw-r--r--cpukit/libfs/src/imfs/imfs_chown.c56
-rw-r--r--cpukit/libfs/src/imfs/imfs_config.c35
-rw-r--r--cpukit/libfs/src/imfs/imfs_creat.c170
-rw-r--r--cpukit/libfs/src/imfs/imfs_debug.c159
-rw-r--r--cpukit/libfs/src/imfs/imfs_directory.c317
-rw-r--r--cpukit/libfs/src/imfs/imfs_eval.c663
-rw-r--r--cpukit/libfs/src/imfs/imfs_fchmod.c56
-rw-r--r--cpukit/libfs/src/imfs/imfs_fdatasync.c29
-rw-r--r--cpukit/libfs/src/imfs/imfs_fifo.c148
-rw-r--r--cpukit/libfs/src/imfs/imfs_fsunmount.c94
-rw-r--r--cpukit/libfs/src/imfs/imfs_getchild.c66
-rw-r--r--cpukit/libfs/src/imfs/imfs_gtkn.c91
-rw-r--r--cpukit/libfs/src/imfs/imfs_handlers_device.c41
-rw-r--r--cpukit/libfs/src/imfs/imfs_handlers_directory.c41
-rw-r--r--cpukit/libfs/src/imfs/imfs_handlers_link.c41
-rw-r--r--cpukit/libfs/src/imfs/imfs_handlers_memfile.c41
-rw-r--r--cpukit/libfs/src/imfs/imfs_init.c61
-rw-r--r--cpukit/libfs/src/imfs/imfs_initsupp.c119
-rw-r--r--cpukit/libfs/src/imfs/imfs_link.c78
-rw-r--r--cpukit/libfs/src/imfs/imfs_load_tar.c186
-rw-r--r--cpukit/libfs/src/imfs/imfs_mknod.c76
-rw-r--r--cpukit/libfs/src/imfs/imfs_mount.c53
-rw-r--r--cpukit/libfs/src/imfs/imfs_ntype.c32
-rw-r--r--cpukit/libfs/src/imfs/imfs_readlink.c43
-rw-r--r--cpukit/libfs/src/imfs/imfs_rename.c54
-rw-r--r--cpukit/libfs/src/imfs/imfs_rmnod.c77
-rw-r--r--cpukit/libfs/src/imfs/imfs_stat.c81
-rw-r--r--cpukit/libfs/src/imfs/imfs_symlink.c77
-rw-r--r--cpukit/libfs/src/imfs/imfs_unlink.c82
-rw-r--r--cpukit/libfs/src/imfs/imfs_unmount.c62
-rw-r--r--cpukit/libfs/src/imfs/imfs_utime.c42
-rw-r--r--cpukit/libfs/src/imfs/ioman.c93
-rw-r--r--cpukit/libfs/src/imfs/memfile.c975
-rw-r--r--cpukit/libfs/src/imfs/miniimfs_init.c61
-rw-r--r--cpukit/libfs/src/nfsclient/.cvsignore2
-rw-r--r--cpukit/libfs/src/nfsclient/ChangeLog.slac112
-rw-r--r--cpukit/libfs/src/nfsclient/LICENSE44
-rw-r--r--cpukit/libfs/src/nfsclient/Makefile.am74
-rw-r--r--cpukit/libfs/src/nfsclient/README548
-rw-r--r--cpukit/libfs/src/nfsclient/preinstall.am51
-rw-r--r--cpukit/libfs/src/nfsclient/proto/mount_prot.h144
-rw-r--r--cpukit/libfs/src/nfsclient/proto/mount_prot.x161
-rw-r--r--cpukit/libfs/src/nfsclient/proto/mount_prot_xdr.c104
-rw-r--r--cpukit/libfs/src/nfsclient/proto/nfs_prot.h453
-rw-r--r--cpukit/libfs/src/nfsclient/proto/nfs_prot.x1268
-rw-r--r--cpukit/libfs/src/nfsclient/proto/nfs_prot_xdr.c621
-rw-r--r--cpukit/libfs/src/nfsclient/rfc1094.txt1258
-rw-r--r--cpukit/libfs/src/nfsclient/src/cexphelp.c20
-rw-r--r--cpukit/libfs/src/nfsclient/src/dirutils.c385
-rw-r--r--cpukit/libfs/src/nfsclient/src/librtemsNfs.h180
-rw-r--r--cpukit/libfs/src/nfsclient/src/nfs.c3354
-rw-r--r--cpukit/libfs/src/nfsclient/src/nfs.modini.c31
-rw-r--r--cpukit/libfs/src/nfsclient/src/nfsTest.c381
-rw-r--r--cpukit/libfs/src/nfsclient/src/rpcio.c1792
-rw-r--r--cpukit/libfs/src/nfsclient/src/rpcio.h209
-rw-r--r--cpukit/libfs/src/nfsclient/src/rpcio.modini.c19
-rw-r--r--cpukit/libfs/src/nfsclient/src/sock_mbuf.c283
-rw-r--r--cpukit/libfs/src/nfsclient/src/xdr_mbuf.c539
-rw-r--r--cpukit/libfs/src/pipe/fifo.c585
-rw-r--r--cpukit/libfs/src/pipe/pipe.c79
-rw-r--r--cpukit/libfs/src/pipe/pipe.h116
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-bitmaps-ut.c398
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-bitmaps.c646
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-bitmaps.h303
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-block-pos.h239
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-block.c800
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-block.h324
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c92
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-buffer-devio.c61
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-buffer.c484
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-buffer.h265
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-data.h87
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-dir-hash.c341
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-dir-hash.h34
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-dir.c760
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-dir.h206
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-file-system-fwd.h27
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-file-system.c320
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-file-system.h402
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-file.c596
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-file.h393
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-format.c644
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-format.h90
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-group.c361
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-group.h163
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-inode.c402
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-inode.h693
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-link.c458
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-link.h112
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-mutex.c72
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-mutex.h108
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c271
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c245
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c354
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems-utils.c244
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems.c1286
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-rtems.h329
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-shell.c753
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-shell.h44
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-trace.c159
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-trace.h129
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs.h30
-rw-r--r--cpukit/libgnat/.cvsignore2
-rw-r--r--cpukit/libgnat/Makefile.am17
-rw-r--r--cpukit/libgnat/ada_intrsupp.c146
-rw-r--r--cpukit/libgnat/adasupp.c36
-rw-r--r--cpukit/libi2c/.cvsignore2
-rw-r--r--cpukit/libi2c/Makefile.am11
-rw-r--r--cpukit/libi2c/README_libi2c367
-rw-r--r--cpukit/libi2c/libi2c.c778
-rw-r--r--cpukit/libi2c/libi2c.h510
-rw-r--r--cpukit/libmd/.cvsignore2
-rw-r--r--cpukit/libmd/Makefile.am15
-rw-r--r--cpukit/libmd/md4.c301
-rw-r--r--cpukit/libmd/md4.h57
-rw-r--r--cpukit/libmd/md5.c312
-rw-r--r--cpukit/libmd/md5.h68
-rw-r--r--cpukit/libmd/preinstall.am7
-rw-r--r--cpukit/libmisc/.cvsignore2
-rw-r--r--cpukit/libmisc/Makefile.am161
-rw-r--r--cpukit/libmisc/README23
-rw-r--r--cpukit/libmisc/bspcmdline/bspcmdline.h128
-rw-r--r--cpukit/libmisc/bspcmdline/bspcmdline_get.c23
-rw-r--r--cpukit/libmisc/bspcmdline/bspcmdline_getparam.c67
-rw-r--r--cpukit/libmisc/bspcmdline/bspcmdline_getparamraw.c37
-rw-r--r--cpukit/libmisc/bspcmdline/bspcmdline_getparamrhs.c48
-rw-r--r--cpukit/libmisc/capture/README255
-rw-r--r--cpukit/libmisc/capture/capture-cli.c1622
-rw-r--r--cpukit/libmisc/capture/capture-cli.h56
-rw-r--r--cpukit/libmisc/capture/capture.c1938
-rw-r--r--cpukit/libmisc/capture/capture.h1042
-rw-r--r--cpukit/libmisc/cpuuse/README21
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagedata.c28
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereport.c205
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereset.c60
-rw-r--r--cpukit/libmisc/cpuuse/cpuuse.h51
-rw-r--r--cpukit/libmisc/devnull/devnull.c184
-rw-r--r--cpukit/libmisc/devnull/devnull.h73
-rw-r--r--cpukit/libmisc/dummy/README23
-rw-r--r--cpukit/libmisc/dummy/dummy-networking.c44
-rw-r--r--cpukit/libmisc/dummy/dummy.c38
-rw-r--r--cpukit/libmisc/dumpbuf/dumpbuf.c80
-rw-r--r--cpukit/libmisc/dumpbuf/dumpbuf.h39
-rw-r--r--cpukit/libmisc/fb/fb.h91
-rw-r--r--cpukit/libmisc/fb/mw_print.c92
-rw-r--r--cpukit/libmisc/fb/mw_uid.c150
-rw-r--r--cpukit/libmisc/fb/mw_uid.h185
-rw-r--r--cpukit/libmisc/fsmount/README24
-rw-r--r--cpukit/libmisc/fsmount/fsmount.c138
-rw-r--r--cpukit/libmisc/fsmount/fsmount.h209
-rw-r--r--cpukit/libmisc/monitor/README97
-rw-r--r--cpukit/libmisc/monitor/mon-command.c244
-rw-r--r--cpukit/libmisc/monitor/mon-config.c136
-rw-r--r--cpukit/libmisc/monitor/mon-driver.c144
-rw-r--r--cpukit/libmisc/monitor/mon-editor.c643
-rw-r--r--cpukit/libmisc/monitor/mon-extension.c102
-rw-r--r--cpukit/libmisc/monitor/mon-itask.c121
-rw-r--r--cpukit/libmisc/monitor/mon-manager.c55
-rw-r--r--cpukit/libmisc/monitor/mon-monitor.c529
-rw-r--r--cpukit/libmisc/monitor/mon-mpci.c163
-rw-r--r--cpukit/libmisc/monitor/mon-network.c342
-rw-r--r--cpukit/libmisc/monitor/mon-object.c423
-rw-r--r--cpukit/libmisc/monitor/mon-part.c72
-rw-r--r--cpukit/libmisc/monitor/mon-prmisc.c259
-rw-r--r--cpukit/libmisc/monitor/mon-queue.c68
-rw-r--r--cpukit/libmisc/monitor/mon-region.c73
-rw-r--r--cpukit/libmisc/monitor/mon-sema.c84
-rw-r--r--cpukit/libmisc/monitor/mon-server.c309
-rw-r--r--cpukit/libmisc/monitor/mon-symbols.c490
-rw-r--r--cpukit/libmisc/monitor/mon-task.c105
-rw-r--r--cpukit/libmisc/monitor/monitor.h531
-rw-r--r--cpukit/libmisc/monitor/symbols.h64
-rw-r--r--cpukit/libmisc/mouse/README214
-rw-r--r--cpukit/libmisc/mouse/mouse_parser.c311
-rw-r--r--cpukit/libmisc/mouse/mouse_parser.h108
-rw-r--r--cpukit/libmisc/mouse/serial_mouse.c184
-rw-r--r--cpukit/libmisc/mouse/serial_mouse.h156
-rw-r--r--cpukit/libmisc/preinstall.am9
-rw-r--r--cpukit/libmisc/serdbg/README138
-rw-r--r--cpukit/libmisc/serdbg/serdbg.c92
-rw-r--r--cpukit/libmisc/serdbg/serdbg.h187
-rw-r--r--cpukit/libmisc/serdbg/serdbgcnf.h89
-rw-r--r--cpukit/libmisc/serdbg/serdbgio.c256
-rw-r--r--cpukit/libmisc/serdbg/termios_printk.c241
-rw-r--r--cpukit/libmisc/serdbg/termios_printk.h104
-rw-r--r--cpukit/libmisc/serdbg/termios_printk_cnf.h78
-rw-r--r--cpukit/libmisc/shell/README27
-rw-r--r--cpukit/libmisc/shell/cat_file.c37
-rw-r--r--cpukit/libmisc/shell/cmds.c77
-rw-r--r--cpukit/libmisc/shell/cmp-ls.c204
-rw-r--r--cpukit/libmisc/shell/dd-args.c507
-rw-r--r--cpukit/libmisc/shell/dd-conv.c272
-rw-r--r--cpukit/libmisc/shell/dd-conv_tab.c288
-rw-r--r--cpukit/libmisc/shell/dd-misc.c112
-rw-r--r--cpukit/libmisc/shell/dd-position.c193
-rw-r--r--cpukit/libmisc/shell/dd.h108
-rw-r--r--cpukit/libmisc/shell/err.c64
-rw-r--r--cpukit/libmisc/shell/err.h84
-rw-r--r--cpukit/libmisc/shell/errx.c64
-rw-r--r--cpukit/libmisc/shell/extern-cp.h91
-rw-r--r--cpukit/libmisc/shell/extern-dd.h106
-rw-r--r--cpukit/libmisc/shell/extern-ls.h192
-rw-r--r--cpukit/libmisc/shell/fdisk.c280
-rw-r--r--cpukit/libmisc/shell/filemode.c154
-rw-r--r--cpukit/libmisc/shell/fts.c1244
-rw-r--r--cpukit/libmisc/shell/fts.h146
-rw-r--r--cpukit/libmisc/shell/hexdump-conv.c186
-rw-r--r--cpukit/libmisc/shell/hexdump-display.c431
-rw-r--r--cpukit/libmisc/shell/hexdump-odsyntax.c451
-rw-r--r--cpukit/libmisc/shell/hexdump-parse.c531
-rw-r--r--cpukit/libmisc/shell/hexdump.h183
-rw-r--r--cpukit/libmisc/shell/hexsyntax.c158
-rw-r--r--cpukit/libmisc/shell/internal.h37
-rw-r--r--cpukit/libmisc/shell/login_check.c62
-rw-r--r--cpukit/libmisc/shell/login_prompt.c209
-rw-r--r--cpukit/libmisc/shell/main_alias.c45
-rw-r--r--cpukit/libmisc/shell/main_blksync.c77
-rw-r--r--cpukit/libmisc/shell/main_cat.c60
-rw-r--r--cpukit/libmisc/shell/main_cd.c26
-rw-r--r--cpukit/libmisc/shell/main_chdir.c54
-rw-r--r--cpukit/libmisc/shell/main_chmod.c70
-rw-r--r--cpukit/libmisc/shell/main_chroot.c53
-rw-r--r--cpukit/libmisc/shell/main_cp.c555
-rw-r--r--cpukit/libmisc/shell/main_cpuuse.c61
-rw-r--r--cpukit/libmisc/shell/main_date.c80
-rw-r--r--cpukit/libmisc/shell/main_dd.c565
-rw-r--r--cpukit/libmisc/shell/main_debugrfs.c35
-rw-r--r--cpukit/libmisc/shell/main_dir.c26
-rw-r--r--cpukit/libmisc/shell/main_echo.c142
-rw-r--r--cpukit/libmisc/shell/main_exit.c26
-rw-r--r--cpukit/libmisc/shell/main_getenv.c49
-rw-r--r--cpukit/libmisc/shell/main_halt.c40
-rw-r--r--cpukit/libmisc/shell/main_help.c152
-rw-r--r--cpukit/libmisc/shell/main_hexdump.c168
-rw-r--r--cpukit/libmisc/shell/main_id.c67
-rw-r--r--cpukit/libmisc/shell/main_ifconfig.c243
-rw-r--r--cpukit/libmisc/shell/main_ln.c309
-rw-r--r--cpukit/libmisc/shell/main_logoff.c44
-rw-r--r--cpukit/libmisc/shell/main_ls.c776
-rw-r--r--cpukit/libmisc/shell/main_mallocinfo.c63
-rw-r--r--cpukit/libmisc/shell/main_mdump.c96
-rw-r--r--cpukit/libmisc/shell/main_medit.c79
-rw-r--r--cpukit/libmisc/shell/main_mfill.c77
-rw-r--r--cpukit/libmisc/shell/main_mkdir.c55
-rw-r--r--cpukit/libmisc/shell/main_mknod.c463
-rw-r--r--cpukit/libmisc/shell/main_mkrfs.c35
-rw-r--r--cpukit/libmisc/shell/main_mmove.c79
-rw-r--r--cpukit/libmisc/shell/main_mount.c133
-rw-r--r--cpukit/libmisc/shell/main_mount_nfs.c70
-rw-r--r--cpukit/libmisc/shell/main_msdosfmt.c185
-rw-r--r--cpukit/libmisc/shell/main_mv.c491
-rw-r--r--cpukit/libmisc/shell/main_mwdump.c95
-rw-r--r--cpukit/libmisc/shell/main_netstats.c138
-rw-r--r--cpukit/libmisc/shell/main_perioduse.c63
-rw-r--r--cpukit/libmisc/shell/main_pwd.c45
-rw-r--r--cpukit/libmisc/shell/main_rm.c709
-rw-r--r--cpukit/libmisc/shell/main_rmdir.c51
-rw-r--r--cpukit/libmisc/shell/main_route.c153
-rw-r--r--cpukit/libmisc/shell/main_rtc.c173
-rw-r--r--cpukit/libmisc/shell/main_setenv.c72
-rw-r--r--cpukit/libmisc/shell/main_sleep.c74
-rw-r--r--cpukit/libmisc/shell/main_stackuse.c44
-rw-r--r--cpukit/libmisc/shell/main_time.c84
-rw-r--r--cpukit/libmisc/shell/main_tty.c44
-rw-r--r--cpukit/libmisc/shell/main_umask.c62
-rw-r--r--cpukit/libmisc/shell/main_unmount.c74
-rw-r--r--cpukit/libmisc/shell/main_unsetenv.c43
-rw-r--r--cpukit/libmisc/shell/main_whoami.c48
-rw-r--r--cpukit/libmisc/shell/main_wkspaceinfo.c59
-rw-r--r--cpukit/libmisc/shell/mknod-pack_dev.c300
-rw-r--r--cpukit/libmisc/shell/mknod-pack_dev.h52
-rw-r--r--cpukit/libmisc/shell/pathnames-mv.h40
-rw-r--r--cpukit/libmisc/shell/print-ls.c492
-rw-r--r--cpukit/libmisc/shell/print_heapinfo.c37
-rw-r--r--cpukit/libmisc/shell/pwcache.c120
-rw-r--r--cpukit/libmisc/shell/shell.c987
-rw-r--r--cpukit/libmisc/shell/shell.h292
-rw-r--r--cpukit/libmisc/shell/shell_cmdset.c234
-rw-r--r--cpukit/libmisc/shell/shell_getchar.c176
-rw-r--r--cpukit/libmisc/shell/shell_getprompt.c49
-rw-r--r--cpukit/libmisc/shell/shell_makeargs.c68
-rw-r--r--cpukit/libmisc/shell/shell_script.c351
-rw-r--r--cpukit/libmisc/shell/shellconfig.c21
-rw-r--r--cpukit/libmisc/shell/shellconfig.h438
-rw-r--r--cpukit/libmisc/shell/utils-cp.c496
-rw-r--r--cpukit/libmisc/shell/utils-ls.c117
-rw-r--r--cpukit/libmisc/shell/verr.c75
-rw-r--r--cpukit/libmisc/shell/verrx.c68
-rw-r--r--cpukit/libmisc/shell/vis.c387
-rw-r--r--cpukit/libmisc/shell/vis.h91
-rw-r--r--cpukit/libmisc/shell/vwarn.c74
-rw-r--r--cpukit/libmisc/shell/vwarnx.c67
-rw-r--r--cpukit/libmisc/shell/warn.c64
-rw-r--r--cpukit/libmisc/shell/warnx.c64
-rw-r--r--cpukit/libmisc/shell/write_file.c43
-rw-r--r--cpukit/libmisc/stackchk/README53
-rw-r--r--cpukit/libmisc/stackchk/check.c515
-rw-r--r--cpukit/libmisc/stackchk/internal.h95
-rw-r--r--cpukit/libmisc/stackchk/stackchk.h135
-rw-r--r--cpukit/libmisc/stringto/stringto.h246
-rw-r--r--cpukit/libmisc/stringto/stringtodouble.c58
-rw-r--r--cpukit/libmisc/stringto/stringtofloat.c58
-rw-r--r--cpukit/libmisc/stringto/stringtoint.c73
-rw-r--r--cpukit/libmisc/stringto/stringtolong.c59
-rw-r--r--cpukit/libmisc/stringto/stringtolongdouble.c58
-rw-r--r--cpukit/libmisc/stringto/stringtolonglong.c68
-rw-r--r--cpukit/libmisc/stringto/stringtopointer.c47
-rw-r--r--cpukit/libmisc/stringto/stringtounsignedchar.c66
-rw-r--r--cpukit/libmisc/stringto/stringtounsignedint.c66
-rw-r--r--cpukit/libmisc/stringto/stringtounsignedlong.c59
-rw-r--r--cpukit/libmisc/stringto/stringtounsignedlonglong.c64
-rw-r--r--cpukit/libmisc/untar/README26
-rw-r--r--cpukit/libmisc/untar/untar.c384
-rw-r--r--cpukit/libmisc/untar/untar.h49
-rw-r--r--cpukit/libmisc/uuid/COPYING25
-rw-r--r--cpukit/libmisc/uuid/README14
-rw-r--r--cpukit/libmisc/uuid/clear.c47
-rw-r--r--cpukit/libmisc/uuid/compare.c59
-rw-r--r--cpukit/libmisc/uuid/copy.c49
-rw-r--r--cpukit/libmisc/uuid/gen_uuid.c670
-rw-r--r--cpukit/libmisc/uuid/isnull.c52
-rw-r--r--cpukit/libmisc/uuid/pack.c73
-rw-r--r--cpukit/libmisc/uuid/parse.c83
-rw-r--r--cpukit/libmisc/uuid/unpack.c67
-rw-r--r--cpukit/libmisc/uuid/unparse.c80
-rw-r--r--cpukit/libmisc/uuid/uuid.h103
-rw-r--r--cpukit/libmisc/uuid/uuidP.h63
-rw-r--r--cpukit/libmisc/uuid/uuid_time.c175
-rw-r--r--cpukit/libmisc/uuid/uuidd.h53
-rw-r--r--cpukit/libnetworking/.cvsignore2
-rw-r--r--cpukit/libnetworking/Makefile.am209
-rw-r--r--cpukit/libnetworking/README72
-rw-r--r--cpukit/libnetworking/arpa/ftp.h111
-rw-r--r--cpukit/libnetworking/arpa/inet.h146
-rw-r--r--cpukit/libnetworking/arpa/nameser.h453
-rw-r--r--cpukit/libnetworking/arpa/nameser_compat.h194
-rw-r--r--cpukit/libnetworking/bpfilter.h5
-rw-r--r--cpukit/libnetworking/dev/mii/mii.h206
-rw-r--r--cpukit/libnetworking/ifaddrs.h56
-rw-r--r--cpukit/libnetworking/kern/kern_mib.c385
-rw-r--r--cpukit/libnetworking/kern/kern_subr.c155
-rw-r--r--cpukit/libnetworking/kern/kern_sysctl.c1541
-rw-r--r--cpukit/libnetworking/kern/uipc_domain.c219
-rw-r--r--cpukit/libnetworking/kern/uipc_mbuf.c741
-rw-r--r--cpukit/libnetworking/kern/uipc_socket.c1104
-rw-r--r--cpukit/libnetworking/kern/uipc_socket2.c940
-rw-r--r--cpukit/libnetworking/lib/README5
-rw-r--r--cpukit/libnetworking/lib/ftpfs.c1345
-rw-r--r--cpukit/libnetworking/lib/getprotoby.c50
-rw-r--r--cpukit/libnetworking/lib/rtems_bsdnet_ntp.c218
-rw-r--r--cpukit/libnetworking/lib/syslog.c194
-rw-r--r--cpukit/libnetworking/lib/tftpDriver.c1119
-rw-r--r--cpukit/libnetworking/libc/base64.c316
-rw-r--r--cpukit/libnetworking/libc/byteorder.377
-rw-r--r--cpukit/libnetworking/libc/ether_addr.c230
-rw-r--r--cpukit/libnetworking/libc/ethers.3193
-rw-r--r--cpukit/libnetworking/libc/gethostbydns.c775
-rw-r--r--cpukit/libnetworking/libc/gethostbyht.c318
-rw-r--r--cpukit/libnetworking/libc/gethostbyname.3305
-rw-r--r--cpukit/libnetworking/libc/gethostbynis.c141
-rw-r--r--cpukit/libnetworking/libc/gethostnamadr.c429
-rw-r--r--cpukit/libnetworking/libc/gethostname.c28
-rw-r--r--cpukit/libnetworking/libc/getifaddrs.c419
-rw-r--r--cpukit/libnetworking/libc/getnetbydns.c312
-rw-r--r--cpukit/libnetworking/libc/getnetbyht.c172
-rw-r--r--cpukit/libnetworking/libc/getnetbynis.c176
-rw-r--r--cpukit/libnetworking/libc/getnetent.3159
-rw-r--r--cpukit/libnetworking/libc/getnetnamadr.c190
-rw-r--r--cpukit/libnetworking/libc/getproto.c62
-rw-r--r--cpukit/libnetworking/libc/getprotoent.3147
-rw-r--r--cpukit/libnetworking/libc/getprotoent.c121
-rw-r--r--cpukit/libnetworking/libc/getprotoname.c69
-rw-r--r--cpukit/libnetworking/libc/getservbyname.c101
-rw-r--r--cpukit/libnetworking/libc/getservbyport.c94
-rw-r--r--cpukit/libnetworking/libc/getservent.3156
-rw-r--r--cpukit/libnetworking/libc/getservent.c281
-rw-r--r--cpukit/libnetworking/libc/herror.c121
-rw-r--r--cpukit/libnetworking/libc/if_indextoname.c91
-rw-r--r--cpukit/libnetworking/libc/if_nameindex.c150
-rw-r--r--cpukit/libnetworking/libc/inet.3210
-rw-r--r--cpukit/libnetworking/libc/inet_addr.c179
-rw-r--r--cpukit/libnetworking/libc/inet_lnaof.c61
-rw-r--r--cpukit/libnetworking/libc/inet_makeaddr.c65
-rw-r--r--cpukit/libnetworking/libc/inet_net_ntop.c139
-rw-r--r--cpukit/libnetworking/libc/inet_net_pton.c206
-rw-r--r--cpukit/libnetworking/libc/inet_neta.c83
-rw-r--r--cpukit/libnetworking/libc/inet_netof.c60
-rw-r--r--cpukit/libnetworking/libc/inet_network.c92
-rw-r--r--cpukit/libnetworking/libc/inet_ntoa.c60
-rw-r--r--cpukit/libnetworking/libc/inet_ntop.c193
-rw-r--r--cpukit/libnetworking/libc/inet_pton.c214
-rw-r--r--cpukit/libnetworking/libc/linkaddr.3138
-rw-r--r--cpukit/libnetworking/libc/linkaddr.c164
-rw-r--r--cpukit/libnetworking/libc/map_v4v6.c125
-rw-r--r--cpukit/libnetworking/libc/ns.3131
-rw-r--r--cpukit/libnetworking/libc/ns_addr.c229
-rw-r--r--cpukit/libnetworking/libc/ns_name.c593
-rw-r--r--cpukit/libnetworking/libc/ns_netint.c54
-rw-r--r--cpukit/libnetworking/libc/ns_ntoa.c102
-rw-r--r--cpukit/libnetworking/libc/ns_parse.c190
-rw-r--r--cpukit/libnetworking/libc/ns_print.c746
-rw-r--r--cpukit/libnetworking/libc/ns_ttl.c151
-rw-r--r--cpukit/libnetworking/libc/nsap_addr.c105
-rw-r--r--cpukit/libnetworking/libc/rcmd.3204
-rw-r--r--cpukit/libnetworking/libc/rcmd.c547
-rw-r--r--cpukit/libnetworking/libc/recv.c53
-rw-r--r--cpukit/libnetworking/libc/res_comp.c248
-rw-r--r--cpukit/libnetworking/libc/res_config.h20
-rw-r--r--cpukit/libnetworking/libc/res_data.c83
-rw-r--r--cpukit/libnetworking/libc/res_debug.c971
-rw-r--r--cpukit/libnetworking/libc/res_init.c501
-rw-r--r--cpukit/libnetworking/libc/res_mkquery.c197
-rw-r--r--cpukit/libnetworking/libc/res_mkupdate.c413
-rw-r--r--cpukit/libnetworking/libc/res_query.c410
-rw-r--r--cpukit/libnetworking/libc/res_send.c936
-rw-r--r--cpukit/libnetworking/libc/res_stubs.c79
-rw-r--r--cpukit/libnetworking/libc/res_update.c519
-rw-r--r--cpukit/libnetworking/libc/resolver.3352
-rw-r--r--cpukit/libnetworking/libc/send.c53
-rw-r--r--cpukit/libnetworking/libc/strsep.c88
-rw-r--r--cpukit/libnetworking/loop.h20
-rw-r--r--cpukit/libnetworking/machine/cpu.h5
-rw-r--r--cpukit/libnetworking/machine/cpufunc.h5
-rw-r--r--cpukit/libnetworking/machine/in_cksum.h227
-rw-r--r--cpukit/libnetworking/machine/limits.h5
-rw-r--r--cpukit/libnetworking/machine/vmparam.h5
-rw-r--r--cpukit/libnetworking/memory.h5
-rw-r--r--cpukit/libnetworking/net/bpf.h236
-rw-r--r--cpukit/libnetworking/net/ethernet.h387
-rw-r--r--cpukit/libnetworking/net/if.c784
-rw-r--r--cpukit/libnetworking/net/if.h305
-rw-r--r--cpukit/libnetworking/net/if_arp.h132
-rw-r--r--cpukit/libnetworking/net/if_dl.h86
-rw-r--r--cpukit/libnetworking/net/if_ethersubr.c899
-rw-r--r--cpukit/libnetworking/net/if_llc.h166
-rw-r--r--cpukit/libnetworking/net/if_loop.c288
-rw-r--r--cpukit/libnetworking/net/if_media.h531
-rw-r--r--cpukit/libnetworking/net/if_ppp.c1751
-rw-r--r--cpukit/libnetworking/net/if_ppp.h141
-rw-r--r--cpukit/libnetworking/net/if_pppvar.h158
-rw-r--r--cpukit/libnetworking/net/if_types.h255
-rw-r--r--cpukit/libnetworking/net/if_var.h256
-rw-r--r--cpukit/libnetworking/net/netisr.h77
-rw-r--r--cpukit/libnetworking/net/ppp_comp.h168
-rw-r--r--cpukit/libnetworking/net/ppp_defs.h162
-rw-r--r--cpukit/libnetworking/net/ppp_tty.c952
-rw-r--r--cpukit/libnetworking/net/radix.c1043
-rw-r--r--cpukit/libnetworking/net/radix.h162
-rw-r--r--cpukit/libnetworking/net/raw_cb.c155
-rw-r--r--cpukit/libnetworking/net/raw_cb.h76
-rw-r--r--cpukit/libnetworking/net/raw_usrreq.c307
-rw-r--r--cpukit/libnetworking/net/route.c947
-rw-r--r--cpukit/libnetworking/net/route.h296
-rw-r--r--cpukit/libnetworking/net/rtsock.c801
-rw-r--r--cpukit/libnetworking/net/slcompress.c601
-rw-r--r--cpukit/libnetworking/net/slcompress.h157
-rw-r--r--cpukit/libnetworking/netdb.h198
-rw-r--r--cpukit/libnetworking/netinet/icmp_var.h80
-rw-r--r--cpukit/libnetworking/netinet/if_ether.c642
-rw-r--r--cpukit/libnetworking/netinet/if_ether.h178
-rw-r--r--cpukit/libnetworking/netinet/igmp.c471
-rw-r--r--cpukit/libnetworking/netinet/igmp.h96
-rw-r--r--cpukit/libnetworking/netinet/igmp_var.h105
-rw-r--r--cpukit/libnetworking/netinet/in.c709
-rw-r--r--cpukit/libnetworking/netinet/in.h461
-rw-r--r--cpukit/libnetworking/netinet/in_cksum.c177
-rw-r--r--cpukit/libnetworking/netinet/in_cksum_arm.h277
-rw-r--r--cpukit/libnetworking/netinet/in_cksum_i386.h204
-rw-r--r--cpukit/libnetworking/netinet/in_cksum_m68k.h222
-rw-r--r--cpukit/libnetworking/netinet/in_cksum_powerpc.h174
-rw-r--r--cpukit/libnetworking/netinet/in_pcb.c738
-rw-r--r--cpukit/libnetworking/netinet/in_pcb.h153
-rw-r--r--cpukit/libnetworking/netinet/in_proto.c216
-rw-r--r--cpukit/libnetworking/netinet/in_rmx.c387
-rw-r--r--cpukit/libnetworking/netinet/in_systm.h61
-rw-r--r--cpukit/libnetworking/netinet/in_var.h238
-rw-r--r--cpukit/libnetworking/netinet/ip.h231
-rw-r--r--cpukit/libnetworking/netinet/ip_divert.c385
-rw-r--r--cpukit/libnetworking/netinet/ip_fw.c1079
-rw-r--r--cpukit/libnetworking/netinet/ip_fw.h183
-rw-r--r--cpukit/libnetworking/netinet/ip_icmp.c771
-rw-r--r--cpukit/libnetworking/netinet/ip_icmp.h212
-rw-r--r--cpukit/libnetworking/netinet/ip_input.c1506
-rw-r--r--cpukit/libnetworking/netinet/ip_mroute.c2231
-rw-r--r--cpukit/libnetworking/netinet/ip_mroute.h271
-rw-r--r--cpukit/libnetworking/netinet/ip_output.c1327
-rw-r--r--cpukit/libnetworking/netinet/ip_var.h216
-rw-r--r--cpukit/libnetworking/netinet/raw_ip.c492
-rw-r--r--cpukit/libnetworking/netinet/tcp.h140
-rw-r--r--cpukit/libnetworking/netinet/tcp_debug.c171
-rw-r--r--cpukit/libnetworking/netinet/tcp_debug.h69
-rw-r--r--cpukit/libnetworking/netinet/tcp_fsm.h92
-rw-r--r--cpukit/libnetworking/netinet/tcp_input.c2148
-rw-r--r--cpukit/libnetworking/netinet/tcp_output.c755
-rw-r--r--cpukit/libnetworking/netinet/tcp_seq.h102
-rw-r--r--cpukit/libnetworking/netinet/tcp_subr.c729
-rw-r--r--cpukit/libnetworking/netinet/tcp_timer.c384
-rw-r--r--cpukit/libnetworking/netinet/tcp_timer.h133
-rw-r--r--cpukit/libnetworking/netinet/tcp_usrreq.c845
-rw-r--r--cpukit/libnetworking/netinet/tcp_var.h418
-rw-r--r--cpukit/libnetworking/netinet/tcpip.h65
-rw-r--r--cpukit/libnetworking/netinet/udp.h51
-rw-r--r--cpukit/libnetworking/netinet/udp_usrreq.c730
-rw-r--r--cpukit/libnetworking/netinet/udp_var.h106
-rw-r--r--cpukit/libnetworking/nfs/bootp_subr.c1213
-rw-r--r--cpukit/libnetworking/nfs/nfsproto.h424
-rw-r--r--cpukit/libnetworking/nfs/rpcv2.h111
-rw-r--r--cpukit/libnetworking/nfs/xdr_subs.h90
-rw-r--r--cpukit/libnetworking/nfsclient/nfsargs.h95
-rw-r--r--cpukit/libnetworking/nfsclient/nfsdiskless.h96
-rw-r--r--cpukit/libnetworking/opt_atalk.h5
-rw-r--r--cpukit/libnetworking/opt_bdg.h5
-rw-r--r--cpukit/libnetworking/opt_compat.h5
-rw-r--r--cpukit/libnetworking/opt_inet.h5
-rw-r--r--cpukit/libnetworking/opt_inet6.h5
-rw-r--r--cpukit/libnetworking/opt_ipfw.h5
-rw-r--r--cpukit/libnetworking/opt_ipsec.h5
-rw-r--r--cpukit/libnetworking/opt_ipx.h5
-rw-r--r--cpukit/libnetworking/opt_mac.h5
-rw-r--r--cpukit/libnetworking/opt_mrouting.h5
-rw-r--r--cpukit/libnetworking/opt_netgraph.h5
-rw-r--r--cpukit/libnetworking/opt_ppp.h11
-rw-r--r--cpukit/libnetworking/opt_tcpdebug.h16
-rw-r--r--cpukit/libnetworking/poll.h6
-rw-r--r--cpukit/libnetworking/preinstall.am443
-rw-r--r--cpukit/libnetworking/resolv.h306
-rw-r--r--cpukit/libnetworking/rtems/bsdnet/_types.h44
-rw-r--r--cpukit/libnetworking/rtems/bsdnet/servers.h21
-rw-r--r--cpukit/libnetworking/rtems/dhcp.h49
-rw-r--r--cpukit/libnetworking/rtems/ftpfs.h162
-rw-r--r--cpukit/libnetworking/rtems/mkrootfs.c246
-rw-r--r--cpukit/libnetworking/rtems/mkrootfs.h81
-rw-r--r--cpukit/libnetworking/rtems/rtems_bootp.c42
-rw-r--r--cpukit/libnetworking/rtems/rtems_bsdnet.h317
-rw-r--r--cpukit/libnetworking/rtems/rtems_bsdnet_internal.h205
-rw-r--r--cpukit/libnetworking/rtems/rtems_bsdnet_malloc_starvation.c19
-rw-r--r--cpukit/libnetworking/rtems/rtems_dhcp.c1231
-rw-r--r--cpukit/libnetworking/rtems/rtems_dhcp_failsafe.c372
-rw-r--r--cpukit/libnetworking/rtems/rtems_dhcp_failsafe.h29
-rw-r--r--cpukit/libnetworking/rtems/rtems_glue.c1310
-rw-r--r--cpukit/libnetworking/rtems/rtems_malloc_mbuf.c39
-rw-r--r--cpukit/libnetworking/rtems/rtems_mii_ioctl.c172
-rw-r--r--cpukit/libnetworking/rtems/rtems_mii_ioctl.h141
-rw-r--r--cpukit/libnetworking/rtems/rtems_mii_ioctl_kern.c259
-rw-r--r--cpukit/libnetworking/rtems/rtems_select.c178
-rw-r--r--cpukit/libnetworking/rtems/rtems_showicmpstat.c70
-rw-r--r--cpukit/libnetworking/rtems/rtems_showifstat.c157
-rw-r--r--cpukit/libnetworking/rtems/rtems_showipstat.c63
-rw-r--r--cpukit/libnetworking/rtems/rtems_showmbuf.c69
-rw-r--r--cpukit/libnetworking/rtems/rtems_showroute.c240
-rw-r--r--cpukit/libnetworking/rtems/rtems_showtcpstat.c106
-rw-r--r--cpukit/libnetworking/rtems/rtems_showudpstat.c52
-rw-r--r--cpukit/libnetworking/rtems/rtems_socketpair.c51
-rw-r--r--cpukit/libnetworking/rtems/rtems_syscall.c782
-rw-r--r--cpukit/libnetworking/rtems/sghostname.c53
-rw-r--r--cpukit/libnetworking/rtems/tftp.h45
-rw-r--r--cpukit/libnetworking/sys/callout.h53
-rw-r--r--cpukit/libnetworking/sys/conf.h60
-rw-r--r--cpukit/libnetworking/sys/domain.h71
-rw-r--r--cpukit/libnetworking/sys/kernel.h189
-rw-r--r--cpukit/libnetworking/sys/libkern.h94
-rw-r--r--cpukit/libnetworking/sys/linker_set.h93
-rw-r--r--cpukit/libnetworking/sys/malloc.h355
-rw-r--r--cpukit/libnetworking/sys/mbuf.h440
-rw-r--r--cpukit/libnetworking/sys/mount.h123
-rw-r--r--cpukit/libnetworking/sys/poll.h104
-rw-r--r--cpukit/libnetworking/sys/proc.h8
-rw-r--r--cpukit/libnetworking/sys/protosw.h300
-rw-r--r--cpukit/libnetworking/sys/reboot.h106
-rw-r--r--cpukit/libnetworking/sys/resourcevar.h5
-rw-r--r--cpukit/libnetworking/sys/select.h70
-rw-r--r--cpukit/libnetworking/sys/signalvar.h175
-rw-r--r--cpukit/libnetworking/sys/socket.h407
-rw-r--r--cpukit/libnetworking/sys/socketvar.h273
-rw-r--r--cpukit/libnetworking/sys/sysctl.h642
-rw-r--r--cpukit/libnetworking/sys/syslog.h194
-rw-r--r--cpukit/libnetworking/sys/systm.h107
-rw-r--r--cpukit/libnetworking/sys/ttydefaults.h97
-rw-r--r--cpukit/libnetworking/sys/ucred.h57
-rw-r--r--cpukit/libnetworking/sys/uio.h102
-rw-r--r--cpukit/libnetworking/sys/un.h79
-rw-r--r--cpukit/libnetworking/syslog.h5
-rw-r--r--cpukit/libnetworking/vm/vm.h99
-rw-r--r--cpukit/libnetworking/vm/vm_extern.h45
-rw-r--r--cpukit/libnetworking/vm/vm_kern.h81
-rw-r--r--cpukit/libnetworking/vm/vm_param.h133
-rw-r--r--cpukit/librpc/.cvsignore2
-rw-r--r--cpukit/librpc/Makefile.am91
-rw-r--r--cpukit/librpc/README_RTEMS64
-rw-r--r--cpukit/librpc/include/rpc/auth.h260
-rw-r--r--cpukit/librpc/include/rpc/auth_unix.h84
-rw-r--r--cpukit/librpc/include/rpc/clnt.h312
-rw-r--r--cpukit/librpc/include/rpc/clnt_soc.h106
-rw-r--r--cpukit/librpc/include/rpc/clnt_stat.h83
-rw-r--r--cpukit/librpc/include/rpc/pmap_clnt.h85
-rw-r--r--cpukit/librpc/include/rpc/pmap_prot.h104
-rw-r--r--cpukit/librpc/include/rpc/pmap_rmt.h63
-rw-r--r--cpukit/librpc/include/rpc/rpc.h116
-rw-r--r--cpukit/librpc/include/rpc/rpc_com.h68
-rw-r--r--cpukit/librpc/include/rpc/rpc_msg.h199
-rw-r--r--cpukit/librpc/include/rpc/rpcent.h71
-rw-r--r--cpukit/librpc/include/rpc/svc.h289
-rw-r--r--cpukit/librpc/include/rpc/svc_auth.h56
-rw-r--r--cpukit/librpc/include/rpc/svc_soc.h123
-rw-r--r--cpukit/librpc/include/rpc/types.h68
-rw-r--r--cpukit/librpc/include/rpc/xdr.h312
-rw-r--r--cpukit/librpc/include/rpcsvc/bootparam_prot.x103
-rw-r--r--cpukit/librpc/include/rpcsvc/crypt.x91
-rw-r--r--cpukit/librpc/include/rpcsvc/key_prot.x282
-rw-r--r--cpukit/librpc/include/rpcsvc/klm_prot.x139
-rw-r--r--cpukit/librpc/include/rpcsvc/mount.x257
-rw-r--r--cpukit/librpc/include/rpcsvc/nfs_prot.x1265
-rw-r--r--cpukit/librpc/include/rpcsvc/nis.x466
-rw-r--r--cpukit/librpc/include/rpcsvc/nis_cache.x87
-rw-r--r--cpukit/librpc/include/rpcsvc/nis_callback.x76
-rw-r--r--cpukit/librpc/include/rpcsvc/nis_db.h162
-rw-r--r--cpukit/librpc/include/rpcsvc/nis_object.x317
-rw-r--r--cpukit/librpc/include/rpcsvc/nis_tags.h137
-rw-r--r--cpukit/librpc/include/rpcsvc/nislib.h317
-rw-r--r--cpukit/librpc/include/rpcsvc/nlm_prot.x183
-rw-r--r--cpukit/librpc/include/rpcsvc/pmap_prot.x284
-rw-r--r--cpukit/librpc/include/rpcsvc/rex.x235
-rw-r--r--cpukit/librpc/include/rpcsvc/rnusers.x122
-rw-r--r--cpukit/librpc/include/rpcsvc/rquota.x67
-rw-r--r--cpukit/librpc/include/rpcsvc/rstat.x151
-rw-r--r--cpukit/librpc/include/rpcsvc/rwall.x57
-rw-r--r--cpukit/librpc/include/rpcsvc/sm_inter.x122
-rw-r--r--cpukit/librpc/include/rpcsvc/spray.x90
-rw-r--r--cpukit/librpc/include/rpcsvc/yp.x379
-rw-r--r--cpukit/librpc/include/rpcsvc/yp_prot.h329
-rw-r--r--cpukit/librpc/include/rpcsvc/ypclnt.h93
-rw-r--r--cpukit/librpc/include/rpcsvc/yppasswd.x75
-rw-r--r--cpukit/librpc/include/rpcsvc/ypupdate_prot.x88
-rw-r--r--cpukit/librpc/include/rpcsvc/ypxfrd.x173
-rw-r--r--cpukit/librpc/preinstall.am89
-rw-r--r--cpukit/librpc/src/rpc/DISCLAIMER28
-rw-r--r--cpukit/librpc/src/rpc/README233
-rw-r--r--cpukit/librpc/src/rpc/auth_none.c138
-rw-r--r--cpukit/librpc/src/rpc/auth_unix.c345
-rw-r--r--cpukit/librpc/src/rpc/authunix_prot.c71
-rw-r--r--cpukit/librpc/src/rpc/bindresvport.3106
-rw-r--r--cpukit/librpc/src/rpc/bindresvport.c160
-rw-r--r--cpukit/librpc/src/rpc/clnt_generic.c145
-rw-r--r--cpukit/librpc/src/rpc/clnt_perror.c259
-rw-r--r--cpukit/librpc/src/rpc/clnt_raw.c248
-rw-r--r--cpukit/librpc/src/rpc/clnt_simple.c127
-rw-r--r--cpukit/librpc/src/rpc/clnt_tcp.c605
-rw-r--r--cpukit/librpc/src/rpc/clnt_udp.c571
-rw-r--r--cpukit/librpc/src/rpc/des_crypt.3130
-rw-r--r--cpukit/librpc/src/rpc/get_myaddress.c117
-rw-r--r--cpukit/librpc/src/rpc/getrpcent.398
-rw-r--r--cpukit/librpc/src/rpc/getrpcent.c301
-rw-r--r--cpukit/librpc/src/rpc/getrpcport.331
-rw-r--r--cpukit/librpc/src/rpc/getrpcport.c69
-rw-r--r--cpukit/librpc/src/rpc/netname.c139
-rw-r--r--cpukit/librpc/src/rpc/netnamer.c331
-rw-r--r--cpukit/librpc/src/rpc/pmap_clnt.c151
-rw-r--r--cpukit/librpc/src/rpc/pmap_getmaps.c92
-rw-r--r--cpukit/librpc/src/rpc/pmap_getport.c98
-rw-r--r--cpukit/librpc/src/rpc/pmap_prot.c63
-rw-r--r--cpukit/librpc/src/rpc/pmap_prot2.c122
-rw-r--r--cpukit/librpc/src/rpc/pmap_rmt.c441
-rw-r--r--cpukit/librpc/src/rpc/publickey.347
-rw-r--r--cpukit/librpc/src/rpc/publickey.538
-rw-r--r--cpukit/librpc/src/rpc/rpc.31767
-rw-r--r--cpukit/librpc/src/rpc/rpc.535
-rw-r--r--cpukit/librpc/src/rpc/rpc_callmsg.c196
-rw-r--r--cpukit/librpc/src/rpc/rpc_commondata.c45
-rw-r--r--cpukit/librpc/src/rpc/rpc_dtablesize.c65
-rw-r--r--cpukit/librpc/src/rpc/rpc_prot.c336
-rw-r--r--cpukit/librpc/src/rpc/rpc_secure.3254
-rw-r--r--cpukit/librpc/src/rpc/rpcdname.c84
-rw-r--r--cpukit/librpc/src/rpc/rstat.158
-rw-r--r--cpukit/librpc/src/rpc/rstat_svc.822
-rw-r--r--cpukit/librpc/src/rpc/rtems_portmapper.c500
-rw-r--r--cpukit/librpc/src/rpc/rtems_rpc.c97
-rw-r--r--cpukit/librpc/src/rpc/rtime.347
-rw-r--r--cpukit/librpc/src/rpc/rtime.c163
-rw-r--r--cpukit/librpc/src/rpc/svc.c499
-rw-r--r--cpukit/librpc/src/rpc/svc_auth.c220
-rw-r--r--cpukit/librpc/src/rpc/svc_auth_unix.c152
-rw-r--r--cpukit/librpc/src/rpc/svc_raw.c173
-rw-r--r--cpukit/librpc/src/rpc/svc_run.c89
-rw-r--r--cpukit/librpc/src/rpc/svc_simple.c161
-rw-r--r--cpukit/librpc/src/rpc/svc_tcp.c489
-rw-r--r--cpukit/librpc/src/rpc/svc_udp.c484
-rw-r--r--cpukit/librpc/src/xdr/xdr.3837
-rw-r--r--cpukit/librpc/src/xdr/xdr.c860
-rw-r--r--cpukit/librpc/src/xdr/xdr_array.c160
-rw-r--r--cpukit/librpc/src/xdr/xdr_float.c342
-rw-r--r--cpukit/librpc/src/xdr/xdr_mem.c245
-rw-r--r--cpukit/librpc/src/xdr/xdr_rec.c608
-rw-r--r--cpukit/librpc/src/xdr/xdr_reference.c142
-rw-r--r--cpukit/librpc/src/xdr/xdr_sizeof.c167
-rw-r--r--cpukit/librpc/src/xdr/xdr_stdio.c194
-rw-r--r--cpukit/mghttpd/.cvsignore1
-rw-r--r--cpukit/mghttpd/Makefile.am16
-rw-r--r--cpukit/mghttpd/mongoose.1181
-rw-r--r--cpukit/mghttpd/mongoose.c4739
-rw-r--r--cpukit/mghttpd/mongoose.h253
-rw-r--r--cpukit/mghttpd/preinstall.am39
-rw-r--r--cpukit/posix/.cvsignore2
-rw-r--r--cpukit/posix/Makefile.am195
-rw-r--r--cpukit/posix/include/aio.h167
-rw-r--r--cpukit/posix/include/mqueue.h172
-rw-r--r--cpukit/posix/include/rtems/posix/aio_misc.h108
-rw-r--r--cpukit/posix/include/rtems/posix/barrier.h88
-rw-r--r--cpukit/posix/include/rtems/posix/cancel.h62
-rw-r--r--cpukit/posix/include/rtems/posix/cond.h181
-rw-r--r--cpukit/posix/include/rtems/posix/config.h77
-rw-r--r--cpukit/posix/include/rtems/posix/key.h103
-rw-r--r--cpukit/posix/include/rtems/posix/mqueue.h248
-rw-r--r--cpukit/posix/include/rtems/posix/mutex.h192
-rw-r--r--cpukit/posix/include/rtems/posix/posixapi.h30
-rw-r--r--cpukit/posix/include/rtems/posix/priority.h91
-rw-r--r--cpukit/posix/include/rtems/posix/psignal.h121
-rw-r--r--cpukit/posix/include/rtems/posix/pthread.h175
-rw-r--r--cpukit/posix/include/rtems/posix/ptimer.h94
-rw-r--r--cpukit/posix/include/rtems/posix/rwlock.h88
-rw-r--r--cpukit/posix/include/rtems/posix/semaphore.h198
-rw-r--r--cpukit/posix/include/rtems/posix/sigset.h42
-rw-r--r--cpukit/posix/include/rtems/posix/spinlock.h88
-rw-r--r--cpukit/posix/include/rtems/posix/threadsup.h95
-rw-r--r--cpukit/posix/include/rtems/posix/time.h59
-rw-r--r--cpukit/posix/include/rtems/posix/timer.h107
-rw-r--r--cpukit/posix/include/semaphore.h124
-rw-r--r--cpukit/posix/inline/rtems/posix/barrier.inl89
-rw-r--r--cpukit/posix/inline/rtems/posix/cond.inl70
-rw-r--r--cpukit/posix/inline/rtems/posix/key.inl86
-rw-r--r--cpukit/posix/inline/rtems/posix/mqueue.inl160
-rw-r--r--cpukit/posix/inline/rtems/posix/mutex.inl63
-rw-r--r--cpukit/posix/inline/rtems/posix/priority.inl37
-rw-r--r--cpukit/posix/inline/rtems/posix/pthread.inl77
-rw-r--r--cpukit/posix/inline/rtems/posix/rwlock.inl89
-rw-r--r--cpukit/posix/inline/rtems/posix/semaphore.inl92
-rw-r--r--cpukit/posix/inline/rtems/posix/spinlock.inl89
-rw-r--r--cpukit/posix/inline/rtems/posix/timer.inl98
-rw-r--r--cpukit/posix/preinstall.am162
-rw-r--r--cpukit/posix/src/.cvsignore4
-rw-r--r--cpukit/posix/src/README.mqueue38
-rw-r--r--cpukit/posix/src/_execve.c28
-rw-r--r--cpukit/posix/src/adjtime.c104
-rw-r--r--cpukit/posix/src/aio_cancel.c126
-rw-r--r--cpukit/posix/src/aio_error.c38
-rw-r--r--cpukit/posix/src/aio_fsync.c63
-rw-r--r--cpukit/posix/src/aio_misc.c556
-rw-r--r--cpukit/posix/src/aio_read.c65
-rw-r--r--cpukit/posix/src/aio_return.c37
-rw-r--r--cpukit/posix/src/aio_suspend.c31
-rw-r--r--cpukit/posix/src/aio_write.c65
-rw-r--r--cpukit/posix/src/alarm.c76
-rw-r--r--cpukit/posix/src/barrierattrdestroy.c41
-rw-r--r--cpukit/posix/src/barrierattrgetpshared.c37
-rw-r--r--cpukit/posix/src/barrierattrinit.c36
-rw-r--r--cpukit/posix/src/barrierattrsetpshared.c44
-rw-r--r--cpukit/posix/src/cancel.c67
-rw-r--r--cpukit/posix/src/canceleval.c38
-rw-r--r--cpukit/posix/src/cancelrun.c54
-rw-r--r--cpukit/posix/src/cleanuppop.c77
-rw-r--r--cpukit/posix/src/cleanuppush.c64
-rw-r--r--cpukit/posix/src/clockgetcpuclockid.c38
-rw-r--r--cpukit/posix/src/clockgetenableattr.c38
-rw-r--r--cpukit/posix/src/clockgetres.c65
-rw-r--r--cpukit/posix/src/clockgettime.c65
-rw-r--r--cpukit/posix/src/clocksetenableattr.c38
-rw-r--r--cpukit/posix/src/clocksettime.c59
-rw-r--r--cpukit/posix/src/cond.c59
-rw-r--r--cpukit/posix/src/condattrdestroy.c42
-rw-r--r--cpukit/posix/src/condattrgetpshared.c43
-rw-r--r--cpukit/posix/src/condattrinit.c42
-rw-r--r--cpukit/posix/src/condattrsetpshared.c50
-rw-r--r--cpukit/posix/src/condbroadcast.c37
-rw-r--r--cpukit/posix/src/conddefaultattributes.c35
-rw-r--r--cpukit/posix/src/conddestroy.c67
-rw-r--r--cpukit/posix/src/condget.c60
-rw-r--r--cpukit/posix/src/condinit.c84
-rw-r--r--cpukit/posix/src/condsignal.c37
-rw-r--r--cpukit/posix/src/condsignalsupp.c66
-rw-r--r--cpukit/posix/src/condtimedwait.c70
-rw-r--r--cpukit/posix/src/condwait.c43
-rw-r--r--cpukit/posix/src/condwaitsupp.c122
-rw-r--r--cpukit/posix/src/execl.c32
-rw-r--r--cpukit/posix/src/execle.c32
-rw-r--r--cpukit/posix/src/execlp.c32
-rw-r--r--cpukit/posix/src/execv.c31
-rw-r--r--cpukit/posix/src/execve.c32
-rw-r--r--cpukit/posix/src/execvp.c31
-rw-r--r--cpukit/posix/src/fork.c25
-rw-r--r--cpukit/posix/src/getitimer.c39
-rw-r--r--cpukit/posix/src/key.c58
-rw-r--r--cpukit/posix/src/keycreate.c99
-rw-r--r--cpukit/posix/src/keydelete.c60
-rw-r--r--cpukit/posix/src/keyfreememory.c29
-rw-r--r--cpukit/posix/src/keygetspecific.c59
-rw-r--r--cpukit/posix/src/keyrundestructors.c69
-rw-r--r--cpukit/posix/src/keysetspecific.c59
-rw-r--r--cpukit/posix/src/kill.c32
-rw-r--r--cpukit/posix/src/kill_r.c37
-rw-r--r--cpukit/posix/src/killinfo.c351
-rw-r--r--cpukit/posix/src/lio_listio.c32
-rw-r--r--cpukit/posix/src/mprotect.c36
-rw-r--r--cpukit/posix/src/mqueue.c87
-rw-r--r--cpukit/posix/src/mqueueclose.c85
-rw-r--r--cpukit/posix/src/mqueuecreatesupp.c153
-rw-r--r--cpukit/posix/src/mqueuedeletesupp.c82
-rw-r--r--cpukit/posix/src/mqueuegetattr.c88
-rw-r--r--cpukit/posix/src/mqueuenametoid.c67
-rw-r--r--cpukit/posix/src/mqueuenotify.c116
-rw-r--r--cpukit/posix/src/mqueueopen.c155
-rw-r--r--cpukit/posix/src/mqueuereceive.c64
-rw-r--r--cpukit/posix/src/mqueuerecvsupp.c128
-rw-r--r--cpukit/posix/src/mqueuesend.c64
-rw-r--r--cpukit/posix/src/mqueuesendsupp.c133
-rw-r--r--cpukit/posix/src/mqueuesetattr.c90
-rw-r--r--cpukit/posix/src/mqueuetimedreceive.c88
-rw-r--r--cpukit/posix/src/mqueuetimedsend.c88
-rw-r--r--cpukit/posix/src/mqueuetranslatereturncode.c62
-rw-r--r--cpukit/posix/src/mqueueunlink.c75
-rw-r--r--cpukit/posix/src/mutex.c79
-rw-r--r--cpukit/posix/src/mutexattrdestroy.c40
-rw-r--r--cpukit/posix/src/mutexattrgetprioceiling.c41
-rw-r--r--cpukit/posix/src/mutexattrgetprotocol.c41
-rw-r--r--cpukit/posix/src/mutexattrgetpshared.c41
-rw-r--r--cpukit/posix/src/mutexattrgettype.c45
-rw-r--r--cpukit/posix/src/mutexattrinit.c40
-rw-r--r--cpukit/posix/src/mutexattrsetprioceiling.c44
-rw-r--r--cpukit/posix/src/mutexattrsetprotocol.c49
-rw-r--r--cpukit/posix/src/mutexattrsetpshared.c48
-rw-r--r--cpukit/posix/src/mutexattrsettype.c47
-rw-r--r--cpukit/posix/src/mutexdestroy.c68
-rw-r--r--cpukit/posix/src/mutexget.c91
-rw-r--r--cpukit/posix/src/mutexgetprioceiling.c63
-rw-r--r--cpukit/posix/src/mutexinit.c188
-rw-r--r--cpukit/posix/src/mutexlock.c41
-rw-r--r--cpukit/posix/src/mutexlocksupp.c70
-rw-r--r--cpukit/posix/src/mutexsetprioceiling.c91
-rw-r--r--cpukit/posix/src/mutextimedlock.c83
-rw-r--r--cpukit/posix/src/mutextranslatereturncode.c61
-rw-r--r--cpukit/posix/src/mutextrylock.c41
-rw-r--r--cpukit/posix/src/mutexunlock.c64
-rw-r--r--cpukit/posix/src/nanosleep.c107
-rw-r--r--cpukit/posix/src/pause.c40
-rw-r--r--cpukit/posix/src/pbarrier.c57
-rw-r--r--cpukit/posix/src/pbarrierdestroy.c73
-rw-r--r--cpukit/posix/src/pbarrierinit.c116
-rw-r--r--cpukit/posix/src/pbarriertranslatereturncode.c56
-rw-r--r--cpukit/posix/src/pbarrierwait.c71
-rw-r--r--cpukit/posix/src/posixtimespecabsolutetimeout.c88
-rw-r--r--cpukit/posix/src/prwlock.c45
-rw-r--r--cpukit/posix/src/prwlockdestroy.c80
-rw-r--r--cpukit/posix/src/prwlockinit.c110
-rw-r--r--cpukit/posix/src/prwlockrdlock.c73
-rw-r--r--cpukit/posix/src/prwlocktimedrdlock.c105
-rw-r--r--cpukit/posix/src/prwlocktimedwrlock.c104
-rw-r--r--cpukit/posix/src/prwlocktranslatereturncode.c55
-rw-r--r--cpukit/posix/src/prwlocktryrdlock.c74
-rw-r--r--cpukit/posix/src/prwlocktrywrlock.c73
-rw-r--r--cpukit/posix/src/prwlockunlock.c64
-rw-r--r--cpukit/posix/src/prwlockwrlock.c73
-rw-r--r--cpukit/posix/src/psignal.c224
-rw-r--r--cpukit/posix/src/psignalchecksignal.c113
-rw-r--r--cpukit/posix/src/psignalclearprocesssignals.c58
-rw-r--r--cpukit/posix/src/psignalclearsignals.c99
-rw-r--r--cpukit/posix/src/psignalsetprocesssignals.c46
-rw-r--r--cpukit/posix/src/psignalunblockthread.c120
-rw-r--r--cpukit/posix/src/pspin.c57
-rw-r--r--cpukit/posix/src/pspindestroy.c73
-rw-r--r--cpukit/posix/src/pspininit.c78
-rw-r--r--cpukit/posix/src/pspinlock.c64
-rw-r--r--cpukit/posix/src/pspinlocktranslatereturncode.c58
-rw-r--r--cpukit/posix/src/pspintrylock.c64
-rw-r--r--cpukit/posix/src/pspinunlock.c64
-rw-r--r--cpukit/posix/src/psxpriorityisvalid.c27
-rw-r--r--cpukit/posix/src/psxtransschedparam.c73
-rw-r--r--cpukit/posix/src/pthread.c366
-rw-r--r--cpukit/posix/src/pthreadatfork.c37
-rw-r--r--cpukit/posix/src/pthreadattrdestroy.c32
-rw-r--r--cpukit/posix/src/pthreadattrgetdetachstate.c31
-rw-r--r--cpukit/posix/src/pthreadattrgetguardsize.c33
-rw-r--r--cpukit/posix/src/pthreadattrgetinheritsched.c31
-rw-r--r--cpukit/posix/src/pthreadattrgetschedparam.c31
-rw-r--r--cpukit/posix/src/pthreadattrgetschedpolicy.c31
-rw-r--r--cpukit/posix/src/pthreadattrgetscope.c31
-rw-r--r--cpukit/posix/src/pthreadattrgetstack.c35
-rw-r--r--cpukit/posix/src/pthreadattrgetstackaddr.c31
-rw-r--r--cpukit/posix/src/pthreadattrgetstacksize.c31
-rw-r--r--cpukit/posix/src/pthreadattrinit.c33
-rw-r--r--cpukit/posix/src/pthreadattrsetdetachstate.c38
-rw-r--r--cpukit/posix/src/pthreadattrsetguardsize.c36
-rw-r--r--cpukit/posix/src/pthreadattrsetinheritsched.c41
-rw-r--r--cpukit/posix/src/pthreadattrsetschedparam.c31
-rw-r--r--cpukit/posix/src/pthreadattrsetschedpolicy.c43
-rw-r--r--cpukit/posix/src/pthreadattrsetscope.c43
-rw-r--r--cpukit/posix/src/pthreadattrsetstack.c42
-rw-r--r--cpukit/posix/src/pthreadattrsetstackaddr.c31
-rw-r--r--cpukit/posix/src/pthreadattrsetstacksize.c37
-rw-r--r--cpukit/posix/src/pthreadcreate.c232
-rw-r--r--cpukit/posix/src/pthreaddetach.c51
-rw-r--r--cpukit/posix/src/pthreadequal.c93
-rw-r--r--cpukit/posix/src/pthreadexit.c67
-rw-r--r--cpukit/posix/src/pthreadgetcpuclockid.c30
-rw-r--r--cpukit/posix/src/pthreadgetcputime.c31
-rw-r--r--cpukit/posix/src/pthreadgetschedparam.c63
-rw-r--r--cpukit/posix/src/pthreadinitthreads.c87
-rw-r--r--cpukit/posix/src/pthreadjoin.c75
-rw-r--r--cpukit/posix/src/pthreadkill.c80
-rw-r--r--cpukit/posix/src/pthreadonce.c44
-rw-r--r--cpukit/posix/src/pthreadself.c27
-rw-r--r--cpukit/posix/src/pthreadsetcputime.c38
-rw-r--r--cpukit/posix/src/pthreadsetschedparam.c107
-rw-r--r--cpukit/posix/src/pthreadsigmask.c72
-rw-r--r--cpukit/posix/src/ptimer.c72
-rw-r--r--cpukit/posix/src/rwlockattrdestroy.c41
-rw-r--r--cpukit/posix/src/rwlockattrgetpshared.c37
-rw-r--r--cpukit/posix/src/rwlockattrinit.c36
-rw-r--r--cpukit/posix/src/rwlockattrsetpshared.c44
-rw-r--r--cpukit/posix/src/sched_getparam.c30
-rw-r--r--cpukit/posix/src/sched_getprioritymax.c41
-rw-r--r--cpukit/posix/src/sched_getprioritymin.c41
-rw-r--r--cpukit/posix/src/sched_getscheduler.c33
-rw-r--r--cpukit/posix/src/sched_rr_get_interval.c45
-rw-r--r--cpukit/posix/src/sched_setparam.c34
-rw-r--r--cpukit/posix/src/sched_setscheduler.c36
-rw-r--r--cpukit/posix/src/sched_yield.c35
-rw-r--r--cpukit/posix/src/semaphore.c60
-rw-r--r--cpukit/posix/src/semaphorecreatesupp.c113
-rw-r--r--cpukit/posix/src/semaphoredeletesupp.c50
-rw-r--r--cpukit/posix/src/semaphorenametoid.c63
-rw-r--r--cpukit/posix/src/semaphoretranslatereturncode.c59
-rw-r--r--cpukit/posix/src/semaphorewaitsupp.c73
-rw-r--r--cpukit/posix/src/semclose.c64
-rw-r--r--cpukit/posix/src/semdestroy.c67
-rw-r--r--cpukit/posix/src/semgetvalue.c59
-rw-r--r--cpukit/posix/src/seminit.c58
-rw-r--r--cpukit/posix/src/semopen.c136
-rw-r--r--cpukit/posix/src/sempost.c66
-rw-r--r--cpukit/posix/src/semtimedwait.c81
-rw-r--r--cpukit/posix/src/semtrywait.c42
-rw-r--r--cpukit/posix/src/semunlink.c67
-rw-r--r--cpukit/posix/src/semwait.c42
-rw-r--r--cpukit/posix/src/setcancelstate.c66
-rw-r--r--cpukit/posix/src/setcanceltype.c65
-rw-r--r--cpukit/posix/src/setitimer.c43
-rw-r--r--cpukit/posix/src/sigaction.c93
-rw-r--r--cpukit/posix/src/sigaddset.c40
-rw-r--r--cpukit/posix/src/sigdelset.c44
-rw-r--r--cpukit/posix/src/sigemptyset.c33
-rw-r--r--cpukit/posix/src/sigfillset.c33
-rw-r--r--cpukit/posix/src/sigismember.c42
-rw-r--r--cpukit/posix/src/signal_2.c54
-rw-r--r--cpukit/posix/src/sigpending.c40
-rw-r--r--cpukit/posix/src/sigprocmask.c38
-rw-r--r--cpukit/posix/src/sigqueue.c32
-rw-r--r--cpukit/posix/src/sigsuspend.c59
-rw-r--r--cpukit/posix/src/sigtimedwait.c177
-rw-r--r--cpukit/posix/src/sigwait.c44
-rw-r--r--cpukit/posix/src/sigwaitinfo.c33
-rw-r--r--cpukit/posix/src/sysconf.c55
-rw-r--r--cpukit/posix/src/testcancel.c57
-rw-r--r--cpukit/posix/src/timercreate.c97
-rw-r--r--cpukit/posix/src/timerdelete.c63
-rw-r--r--cpukit/posix/src/timergetoverrun.c58
-rw-r--r--cpukit/posix/src/timergettime.c77
-rw-r--r--cpukit/posix/src/timerinserthelper.c57
-rw-r--r--cpukit/posix/src/timersettime.c136
-rw-r--r--cpukit/posix/src/timertsr.c81
-rw-r--r--cpukit/posix/src/ualarm.c105
-rw-r--r--cpukit/posix/src/vfork.c23
-rw-r--r--cpukit/posix/src/wait.c28
-rw-r--r--cpukit/posix/src/waitpid.c30
-rw-r--r--cpukit/pppd/.cvsignore2
-rw-r--r--cpukit/pppd/Makefile.am21
-rw-r--r--cpukit/pppd/README29
-rw-r--r--cpukit/pppd/STATUS27
-rw-r--r--cpukit/pppd/auth.c1128
-rw-r--r--cpukit/pppd/cbcp.c456
-rw-r--r--cpukit/pppd/cbcp.h26
-rw-r--r--cpukit/pppd/ccp.c1228
-rw-r--r--cpukit/pppd/ccp.h48
-rw-r--r--cpukit/pppd/chap.c858
-rw-r--r--cpukit/pppd/chap.h124
-rw-r--r--cpukit/pppd/chap_ms.c338
-rw-r--r--cpukit/pppd/chap_ms.h33
-rw-r--r--cpukit/pppd/chat.c854
-rw-r--r--cpukit/pppd/demand.c347
-rw-r--r--cpukit/pppd/example/Makefile-user45
-rw-r--r--cpukit/pppd/example/README15
-rw-r--r--cpukit/pppd/example/init.c24
-rw-r--r--cpukit/pppd/example/netconfig.h36
-rw-r--r--cpukit/pppd/example/ppp.conf27
-rw-r--r--cpukit/pppd/example/pppd.options9
-rw-r--r--cpukit/pppd/example/pppdapp.c146
-rw-r--r--cpukit/pppd/example/system.h42
-rw-r--r--cpukit/pppd/fsm.c764
-rw-r--r--cpukit/pppd/fsm.h144
-rw-r--r--cpukit/pppd/ipcp.c1772
-rw-r--r--cpukit/pppd/ipcp.h73
-rw-r--r--cpukit/pppd/lcp.c1953
-rw-r--r--cpukit/pppd/lcp.h88
-rw-r--r--cpukit/pppd/magic.c58
-rw-r--r--cpukit/pppd/magic.h23
-rw-r--r--cpukit/pppd/options.c1520
-rw-r--r--cpukit/pppd/patchlevel.h6
-rw-r--r--cpukit/pppd/pathnames.h43
-rw-r--r--cpukit/pppd/pppd.81480
-rw-r--r--cpukit/pppd/pppd.h663
-rw-r--r--cpukit/pppd/preinstall.am43
-rw-r--r--cpukit/pppd/rtemsdialer.h24
-rw-r--r--cpukit/pppd/rtemsmain.c896
-rw-r--r--cpukit/pppd/rtemspppd.c228
-rw-r--r--cpukit/pppd/rtemspppd.h40
-rw-r--r--cpukit/pppd/sys-rtems.c1340
-rw-r--r--cpukit/pppd/upap.c631
-rw-r--r--cpukit/pppd/upap.h87
-rw-r--r--cpukit/pppd/utils.c827
-rw-r--r--cpukit/preinstall.am394
-rw-r--r--cpukit/rtems/.cvsignore2
-rw-r--r--cpukit/rtems/Makefile.am149
-rw-r--r--cpukit/rtems/include/rtems.h207
-rw-r--r--cpukit/rtems/include/rtems/rtems/asr.h156
-rw-r--r--cpukit/rtems/include/rtems/rtems/attr.h198
-rw-r--r--cpukit/rtems/include/rtems/rtems/barrier.h205
-rw-r--r--cpukit/rtems/include/rtems/rtems/barriermp.h151
-rw-r--r--cpukit/rtems/include/rtems/rtems/cache.h158
-rw-r--r--cpukit/rtems/include/rtems/rtems/clock.h267
-rw-r--r--cpukit/rtems/include/rtems/rtems/config.h151
-rw-r--r--cpukit/rtems/include/rtems/rtems/dpmem.h164
-rw-r--r--cpukit/rtems/include/rtems/rtems/event.h166
-rw-r--r--cpukit/rtems/include/rtems/rtems/eventmp.h138
-rw-r--r--cpukit/rtems/include/rtems/rtems/eventset.h135
-rw-r--r--cpukit/rtems/include/rtems/rtems/intr.h136
-rw-r--r--cpukit/rtems/include/rtems/rtems/message.h313
-rw-r--r--cpukit/rtems/include/rtems/rtems/modes.h111
-rw-r--r--cpukit/rtems/include/rtems/rtems/mp.h57
-rw-r--r--cpukit/rtems/include/rtems/rtems/msgmp.h166
-rw-r--r--cpukit/rtems/include/rtems/rtems/object.h356
-rw-r--r--cpukit/rtems/include/rtems/rtems/options.h78
-rw-r--r--cpukit/rtems/include/rtems/rtems/part.h180
-rw-r--r--cpukit/rtems/include/rtems/rtems/partmp.h151
-rw-r--r--cpukit/rtems/include/rtems/rtems/ratemon.h517
-rw-r--r--cpukit/rtems/include/rtems/rtems/region.h292
-rw-r--r--cpukit/rtems/include/rtems/rtems/regionmp.h155
-rw-r--r--cpukit/rtems/include/rtems/rtems/rtemsapi.h32
-rw-r--r--cpukit/rtems/include/rtems/rtems/sem.h244
-rw-r--r--cpukit/rtems/include/rtems/rtems/semmp.h175
-rw-r--r--cpukit/rtems/include/rtems/rtems/signal.h87
-rw-r--r--cpukit/rtems/include/rtems/rtems/signalmp.h138
-rw-r--r--cpukit/rtems/include/rtems/rtems/status.h220
-rw-r--r--cpukit/rtems/include/rtems/rtems/support.h117
-rw-r--r--cpukit/rtems/include/rtems/rtems/taskmp.h156
-rw-r--r--cpukit/rtems/include/rtems/rtems/tasks.h505
-rw-r--r--cpukit/rtems/include/rtems/rtems/timer.h408
-rw-r--r--cpukit/rtems/include/rtems/rtems/types.h238
-rw-r--r--cpukit/rtems/inline/rtems/rtems/asr.inl119
-rw-r--r--cpukit/rtems/inline/rtems/rtems/attr.inl197
-rw-r--r--cpukit/rtems/inline/rtems/rtems/barrier.inl89
-rw-r--r--cpukit/rtems/inline/rtems/rtems/dpmem.inl90
-rw-r--r--cpukit/rtems/inline/rtems/rtems/event.inl33
-rw-r--r--cpukit/rtems/inline/rtems/rtems/eventset.inl94
-rw-r--r--cpukit/rtems/inline/rtems/rtems/message.inl83
-rw-r--r--cpukit/rtems/inline/rtems/rtems/modes.inl136
-rw-r--r--cpukit/rtems/inline/rtems/rtems/options.inl61
-rw-r--r--cpukit/rtems/inline/rtems/rtems/part.inl175
-rw-r--r--cpukit/rtems/inline/rtems/rtems/ratemon.inl127
-rw-r--r--cpukit/rtems/inline/rtems/rtems/region.inl115
-rw-r--r--cpukit/rtems/inline/rtems/rtems/sem.inl110
-rw-r--r--cpukit/rtems/inline/rtems/rtems/status.inl62
-rw-r--r--cpukit/rtems/inline/rtems/rtems/support.inl63
-rw-r--r--cpukit/rtems/inline/rtems/rtems/tasks.inl86
-rw-r--r--cpukit/rtems/inline/rtems/rtems/timer.inl126
-rw-r--r--cpukit/rtems/mainpage.h950
-rw-r--r--cpukit/rtems/preinstall.am234
-rw-r--r--cpukit/rtems/src/attr.c31
-rw-r--r--cpukit/rtems/src/barrier.c65
-rw-r--r--cpukit/rtems/src/barriercreate.c92
-rw-r--r--cpukit/rtems/src/barrierdata.c23
-rw-r--r--cpukit/rtems/src/barrierdelete.c73
-rw-r--r--cpukit/rtems/src/barrierident.c56
-rw-r--r--cpukit/rtems/src/barrierrelease.c67
-rw-r--r--cpukit/rtems/src/barriertranslatereturncode.c53
-rw-r--r--cpukit/rtems/src/barrierwait.c70
-rw-r--r--cpukit/rtems/src/clockget.c76
-rw-r--r--cpukit/rtems/src/clockgetsecondssinceepoch.c38
-rw-r--r--cpukit/rtems/src/clockgettickspersecond.c31
-rw-r--r--cpukit/rtems/src/clockgettickssinceboot.c29
-rw-r--r--cpukit/rtems/src/clockgettod.c58
-rw-r--r--cpukit/rtems/src/clockgettodtimeval.c39
-rw-r--r--cpukit/rtems/src/clockgetuptime.c51
-rw-r--r--cpukit/rtems/src/clockset.c61
-rw-r--r--cpukit/rtems/src/clocksetnsecshandler.c49
-rw-r--r--cpukit/rtems/src/clocktick.c55
-rw-r--r--cpukit/rtems/src/clocktodtoseconds.c85
-rw-r--r--cpukit/rtems/src/clocktodvalidate.c79
-rw-r--r--cpukit/rtems/src/dpmem.c57
-rw-r--r--cpukit/rtems/src/dpmemcreate.c88
-rw-r--r--cpukit/rtems/src/dpmemdata.c22
-rw-r--r--cpukit/rtems/src/dpmemdelete.c66
-rw-r--r--cpukit/rtems/src/dpmemexternal2internal.c79
-rw-r--r--cpukit/rtems/src/dpmemident.c59
-rw-r--r--cpukit/rtems/src/dpmeminternal2external.c80
-rw-r--r--cpukit/rtems/src/event.c48
-rw-r--r--cpukit/rtems/src/eventdata.c22
-rw-r--r--cpukit/rtems/src/eventmp.c193
-rw-r--r--cpukit/rtems/src/eventreceive.c69
-rw-r--r--cpukit/rtems/src/eventseize.c133
-rw-r--r--cpukit/rtems/src/eventsend.c78
-rw-r--r--cpukit/rtems/src/eventsurrender.c116
-rw-r--r--cpukit/rtems/src/eventtimeout.c93
-rw-r--r--cpukit/rtems/src/intrbody.c74
-rw-r--r--cpukit/rtems/src/intrcatch.c61
-rw-r--r--cpukit/rtems/src/mp.c45
-rw-r--r--cpukit/rtems/src/msg.c81
-rw-r--r--cpukit/rtems/src/msgdata.c23
-rw-r--r--cpukit/rtems/src/msgmp.c510
-rw-r--r--cpukit/rtems/src/msgqallocate.c56
-rw-r--r--cpukit/rtems/src/msgqbroadcast.c113
-rw-r--r--cpukit/rtems/src/msgqcreate.c165
-rw-r--r--cpukit/rtems/src/msgqdelete.c107
-rw-r--r--cpukit/rtems/src/msgqflush.c94
-rw-r--r--cpukit/rtems/src/msgqgetnumberpending.c91
-rw-r--r--cpukit/rtems/src/msgqident.c71
-rw-r--r--cpukit/rtems/src/msgqreceive.c113
-rw-r--r--cpukit/rtems/src/msgqsend.c112
-rw-r--r--cpukit/rtems/src/msgqtranslatereturncode.c81
-rw-r--r--cpukit/rtems/src/msgqurgent.c111
-rw-r--r--cpukit/rtems/src/part.c69
-rw-r--r--cpukit/rtems/src/partcreate.c129
-rw-r--r--cpukit/rtems/src/partdata.c22
-rw-r--r--cpukit/rtems/src/partdelete.c92
-rw-r--r--cpukit/rtems/src/partgetbuffer.c87
-rw-r--r--cpukit/rtems/src/partident.c57
-rw-r--r--cpukit/rtems/src/partmp.c307
-rw-r--r--cpukit/rtems/src/partreturnbuffer.c79
-rw-r--r--cpukit/rtems/src/ratemon.c60
-rw-r--r--cpukit/rtems/src/ratemoncancel.c68
-rw-r--r--cpukit/rtems/src/ratemoncreate.c81
-rw-r--r--cpukit/rtems/src/ratemondata.c22
-rw-r--r--cpukit/rtems/src/ratemondelete.c66
-rw-r--r--cpukit/rtems/src/ratemongetstatistics.c91
-rw-r--r--cpukit/rtems/src/ratemongetstatus.c118
-rw-r--r--cpukit/rtems/src/ratemonident.c58
-rw-r--r--cpukit/rtems/src/ratemonperiod.c374
-rw-r--r--cpukit/rtems/src/ratemonreportstatistics.c209
-rw-r--r--cpukit/rtems/src/ratemonresetall.c55
-rw-r--r--cpukit/rtems/src/ratemonresetstatistics.c65
-rw-r--r--cpukit/rtems/src/ratemontimeout.c83
-rw-r--r--cpukit/rtems/src/region.c70
-rw-r--r--cpukit/rtems/src/regioncreate.c118
-rw-r--r--cpukit/rtems/src/regiondata.c22
-rw-r--r--cpukit/rtems/src/regiondelete.c82
-rw-r--r--cpukit/rtems/src/regionextend.c96
-rw-r--r--cpukit/rtems/src/regiongetfreeinfo.c88
-rw-r--r--cpukit/rtems/src/regiongetinfo.c80
-rw-r--r--cpukit/rtems/src/regiongetsegment.c131
-rw-r--r--cpukit/rtems/src/regiongetsegmentsize.c83
-rw-r--r--cpukit/rtems/src/regionident.c61
-rw-r--r--cpukit/rtems/src/regionmp.c315
-rw-r--r--cpukit/rtems/src/regionprocessqueue.c87
-rw-r--r--cpukit/rtems/src/regionresizesegment.c109
-rw-r--r--cpukit/rtems/src/regionreturnsegment.c111
-rw-r--r--cpukit/rtems/src/rtclock.c26
-rw-r--r--cpukit/rtems/src/rtemsbuildid.c31
-rw-r--r--cpukit/rtems/src/rtemsbuildname.c31
-rw-r--r--cpukit/rtems/src/rtemsobjectapimaximumclass.c27
-rw-r--r--cpukit/rtems/src/rtemsobjectapiminimumclass.c29
-rw-r--r--cpukit/rtems/src/rtemsobjectgetapiclassname.c81
-rw-r--r--cpukit/rtems/src/rtemsobjectgetapiname.c42
-rw-r--r--cpukit/rtems/src/rtemsobjectgetclassicname.c55
-rw-r--r--cpukit/rtems/src/rtemsobjectgetclassinfo.c59
-rw-r--r--cpukit/rtems/src/rtemsobjectgetname.c33
-rw-r--r--cpukit/rtems/src/rtemsobjectidapimaximum.c26
-rw-r--r--cpukit/rtems/src/rtemsobjectidapiminimum.c26
-rw-r--r--cpukit/rtems/src/rtemsobjectidgetapi.c28
-rw-r--r--cpukit/rtems/src/rtemsobjectidgetclass.c28
-rw-r--r--cpukit/rtems/src/rtemsobjectidgetindex.c28
-rw-r--r--cpukit/rtems/src/rtemsobjectidgetnode.c28
-rw-r--r--cpukit/rtems/src/rtemsobjectsetname.c64
-rw-r--r--cpukit/rtems/src/rtemstimer.c64
-rw-r--r--cpukit/rtems/src/rtemstimerdata.c22
-rw-r--r--cpukit/rtems/src/sem.c93
-rw-r--r--cpukit/rtems/src/semcreate.c231
-rw-r--r--cpukit/rtems/src/semdata.c22
-rw-r--r--cpukit/rtems/src/semdelete.c136
-rw-r--r--cpukit/rtems/src/semflush.c102
-rw-r--r--cpukit/rtems/src/semident.c81
-rw-r--r--cpukit/rtems/src/semmp.c367
-rw-r--r--cpukit/rtems/src/semobtain.c121
-rw-r--r--cpukit/rtems/src/semrelease.c119
-rw-r--r--cpukit/rtems/src/semtranslatereturncode.c137
-rw-r--r--cpukit/rtems/src/signal.c51
-rw-r--r--cpukit/rtems/src/signalcatch.c69
-rw-r--r--cpukit/rtems/src/signalmp.c192
-rw-r--r--cpukit/rtems/src/signalsend.c92
-rw-r--r--cpukit/rtems/src/taskcreate.c229
-rw-r--r--cpukit/rtems/src/taskdata.c22
-rw-r--r--cpukit/rtems/src/taskdelete.c110
-rw-r--r--cpukit/rtems/src/taskgetnote.c116
-rw-r--r--cpukit/rtems/src/taskident.c72
-rw-r--r--cpukit/rtems/src/taskinitusers.c92
-rw-r--r--cpukit/rtems/src/taskissuspended.c80
-rw-r--r--cpukit/rtems/src/taskmode.c125
-rw-r--r--cpukit/rtems/src/taskmp.c343
-rw-r--r--cpukit/rtems/src/taskrestart.c83
-rw-r--r--cpukit/rtems/src/taskresume.c85
-rw-r--r--cpukit/rtems/src/tasks.c305
-rw-r--r--cpukit/rtems/src/taskself.c24
-rw-r--r--cpukit/rtems/src/tasksetnote.c109
-rw-r--r--cpukit/rtems/src/tasksetpriority.c102
-rw-r--r--cpukit/rtems/src/taskstart.c88
-rw-r--r--cpukit/rtems/src/tasksuspend.c86
-rw-r--r--cpukit/rtems/src/taskvariable_invoke_dtor.c43
-rw-r--r--cpukit/rtems/src/taskvariableadd.c87
-rw-r--r--cpukit/rtems/src/taskvariabledelete.c76
-rw-r--r--cpukit/rtems/src/taskvariableget.c78
-rw-r--r--cpukit/rtems/src/taskwakeafter.c69
-rw-r--r--cpukit/rtems/src/taskwakewhen.c87
-rw-r--r--cpukit/rtems/src/timercancel.c66
-rw-r--r--cpukit/rtems/src/timercreate.c78
-rw-r--r--cpukit/rtems/src/timerdelete.c67
-rw-r--r--cpukit/rtems/src/timerfireafter.c103
-rw-r--r--cpukit/rtems/src/timerfirewhen.c91
-rw-r--r--cpukit/rtems/src/timergetinfo.c75
-rw-r--r--cpukit/rtems/src/timerident.c60
-rw-r--r--cpukit/rtems/src/timerreset.c93
-rw-r--r--cpukit/rtems/src/timerserver.c583
-rw-r--r--cpukit/rtems/src/timerserverfireafter.c109
-rw-r--r--cpukit/rtems/src/timerserverfirewhen.c96
-rw-r--r--cpukit/rtems/src/workspace.c75
-rw-r--r--cpukit/sapi/.cvsignore2
-rw-r--r--cpukit/sapi/Makefile.am36
-rw-r--r--cpukit/sapi/include/confdefs.h2342
-rw-r--r--cpukit/sapi/include/rtems/README133
-rw-r--r--cpukit/sapi/include/rtems/chain.h140
-rw-r--r--cpukit/sapi/include/rtems/config.h273
-rw-r--r--cpukit/sapi/include/rtems/extension.h259
-rw-r--r--cpukit/sapi/include/rtems/fatal.h53
-rw-r--r--cpukit/sapi/include/rtems/init.h100
-rw-r--r--cpukit/sapi/include/rtems/io.h204
-rw-r--r--cpukit/sapi/include/rtems/mptables.h28
-rw-r--r--cpukit/sapi/include/rtems/sptables.h75
-rw-r--r--cpukit/sapi/inline/rtems/chain.inl561
-rw-r--r--cpukit/sapi/inline/rtems/extension.inl52
-rw-r--r--cpukit/sapi/preinstall.am78
-rw-r--r--cpukit/sapi/src/chainappendnotify.c44
-rw-r--r--cpukit/sapi/src/chaingetnotify.c44
-rw-r--r--cpukit/sapi/src/chaingetwait.c55
-rw-r--r--cpukit/sapi/src/chainprependnotify.c44
-rw-r--r--cpukit/sapi/src/debug.c59
-rw-r--r--cpukit/sapi/src/exinit.c242
-rw-r--r--cpukit/sapi/src/exshutdown.c49
-rw-r--r--cpukit/sapi/src/extension.c52
-rw-r--r--cpukit/sapi/src/extensioncreate.c64
-rw-r--r--cpukit/sapi/src/extensiondata.c23
-rw-r--r--cpukit/sapi/src/extensiondelete.c54
-rw-r--r--cpukit/sapi/src/extensionident.c45
-rw-r--r--cpukit/sapi/src/fatal.c40
-rw-r--r--cpukit/sapi/src/getversionstring.c21
-rw-r--r--cpukit/sapi/src/io.c101
-rw-r--r--cpukit/sapi/src/ioclose.c48
-rw-r--r--cpukit/sapi/src/iocontrol.c48
-rw-r--r--cpukit/sapi/src/iodata.c22
-rw-r--r--cpukit/sapi/src/ioinitialize.c48
-rw-r--r--cpukit/sapi/src/ioopen.c48
-rw-r--r--cpukit/sapi/src/ioread.c48
-rw-r--r--cpukit/sapi/src/ioregisterdriver.c115
-rw-r--r--cpukit/sapi/src/iounregisterdriver.c57
-rw-r--r--cpukit/sapi/src/iowrite.c48
-rw-r--r--cpukit/sapi/src/posixapi.c88
-rw-r--r--cpukit/sapi/src/rtemsapi.c82
-rw-r--r--cpukit/score/.cvsignore2
-rw-r--r--cpukit/score/Makefile.am247
-rw-r--r--cpukit/score/cpu/.cvsignore2
-rw-r--r--cpukit/score/cpu/Makefile.am26
-rw-r--r--cpukit/score/cpu/arm/.cvsignore2
-rw-r--r--cpukit/score/cpu/arm/ChangeLog655
-rw-r--r--cpukit/score/cpu/arm/Makefile.am22
-rw-r--r--cpukit/score/cpu/arm/arm_exc_abort.S135
-rw-r--r--cpukit/score/cpu/arm/arm_exc_handler_high.c121
-rw-r--r--cpukit/score/cpu/arm/arm_exc_handler_low.S164
-rw-r--r--cpukit/score/cpu/arm/arm_exc_interrupt.S177
-rw-r--r--cpukit/score/cpu/arm/cpu.c125
-rw-r--r--cpukit/score/cpu/arm/cpu_asm.S80
-rw-r--r--cpukit/score/cpu/arm/preinstall.am45
-rw-r--r--cpukit/score/cpu/arm/rtems/asm.h178
-rw-r--r--cpukit/score/cpu/arm/rtems/score/arm.h98
-rw-r--r--cpukit/score/cpu/arm/rtems/score/cpu.h495
-rw-r--r--cpukit/score/cpu/arm/rtems/score/cpu_asm.h41
-rw-r--r--cpukit/score/cpu/arm/rtems/score/types.h55
-rw-r--r--cpukit/score/cpu/avr/.cvsignore2
-rw-r--r--cpukit/score/cpu/avr/ChangeLog349
-rw-r--r--cpukit/score/cpu/avr/Makefile.am58
-rw-r--r--cpukit/score/cpu/avr/README5
-rw-r--r--cpukit/score/cpu/avr/avr/boot.h677
-rw-r--r--cpukit/score/cpu/avr/avr/common.h323
-rw-r--r--cpukit/score/cpu/avr/avr/crc16.h39
-rw-r--r--cpukit/score/cpu/avr/avr/delay.h39
-rw-r--r--cpukit/score/cpu/avr/avr/eeprom.h606
-rw-r--r--cpukit/score/cpu/avr/avr/fuse.h269
-rw-r--r--cpukit/score/cpu/avr/avr/interrupt.h344
-rw-r--r--cpukit/score/cpu/avr/avr/io.h420
-rw-r--r--cpukit/score/cpu/avr/avr/io1200.h270
-rw-r--r--cpukit/score/cpu/avr/avr/io2313.h371
-rw-r--r--cpukit/score/cpu/avr/avr/io2323.h204
-rw-r--r--cpukit/score/cpu/avr/avr/io2333.h444
-rw-r--r--cpukit/score/cpu/avr/avr/io2343.h209
-rw-r--r--cpukit/score/cpu/avr/avr/io43u32x.h436
-rw-r--r--cpukit/score/cpu/avr/avr/io43u35x.h428
-rw-r--r--cpukit/score/cpu/avr/avr/io4414.h485
-rw-r--r--cpukit/score/cpu/avr/avr/io4433.h473
-rw-r--r--cpukit/score/cpu/avr/avr/io4434.h567
-rw-r--r--cpukit/score/cpu/avr/avr/io76c711.h493
-rw-r--r--cpukit/score/cpu/avr/avr/io8515.h486
-rw-r--r--cpukit/score/cpu/avr/avr/io8534.h216
-rw-r--r--cpukit/score/cpu/avr/avr/io8535.h568
-rw-r--r--cpukit/score/cpu/avr/avr/io86r401.h308
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwm1.h1121
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwm216.h1181
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwm2b.h1392
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwm316.h1224
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwm3b.h1392
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwm81.h1025
-rw-r--r--cpukit/score/cpu/avr/avr/io90pwmx.h1371
-rw-r--r--cpukit/score/cpu/avr/avr/io90scr100.h1698
-rw-r--r--cpukit/score/cpu/avr/avr/ioa6289.h844
-rw-r--r--cpukit/score/cpu/avr/avr/ioat94k.h557
-rw-r--r--cpukit/score/cpu/avr/avr/iocan128.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iocan32.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iocan64.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iocanxx.h1978
-rw-r--r--cpukit/score/cpu/avr/avr/iom103.h675
-rw-r--r--cpukit/score/cpu/avr/avr/iom128.h1203
-rw-r--r--cpukit/score/cpu/avr/avr/iom1280.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom1281.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom1284p.h1132
-rw-r--r--cpukit/score/cpu/avr/avr/iom128rfa1.h5373
-rw-r--r--cpukit/score/cpu/avr/avr/iom16.h614
-rw-r--r--cpukit/score/cpu/avr/avr/iom161.h673
-rw-r--r--cpukit/score/cpu/avr/avr/iom162.h952
-rw-r--r--cpukit/score/cpu/avr/avr/iom163.h639
-rw-r--r--cpukit/score/cpu/avr/avr/iom164.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom165.h820
-rw-r--r--cpukit/score/cpu/avr/avr/iom165p.h822
-rw-r--r--cpukit/score/cpu/avr/avr/iom168.h91
-rw-r--r--cpukit/score/cpu/avr/avr/iom168p.h874
-rw-r--r--cpukit/score/cpu/avr/avr/iom169.h1107
-rw-r--r--cpukit/score/cpu/avr/avr/iom169p.h1030
-rw-r--r--cpukit/score/cpu/avr/avr/iom169pa.h1472
-rw-r--r--cpukit/score/cpu/avr/avr/iom16a.h904
-rw-r--r--cpukit/score/cpu/avr/avr/iom16hva.h75
-rw-r--r--cpukit/score/cpu/avr/avr/iom16hva2.h871
-rw-r--r--cpukit/score/cpu/avr/avr/iom16hvb.h1039
-rw-r--r--cpukit/score/cpu/avr/avr/iom16m1.h1548
-rw-r--r--cpukit/score/cpu/avr/avr/iom16u2.h980
-rw-r--r--cpukit/score/cpu/avr/avr/iom16u4.h1357
-rw-r--r--cpukit/score/cpu/avr/avr/iom2560.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom2561.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom32.h696
-rw-r--r--cpukit/score/cpu/avr/avr/iom323.h688
-rw-r--r--cpukit/score/cpu/avr/avr/iom324.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom324pa.h1355
-rw-r--r--cpukit/score/cpu/avr/avr/iom325.h821
-rw-r--r--cpukit/score/cpu/avr/avr/iom3250.h911
-rw-r--r--cpukit/score/cpu/avr/avr/iom328p.h875
-rw-r--r--cpukit/score/cpu/avr/avr/iom329.h1003
-rw-r--r--cpukit/score/cpu/avr/avr/iom3290.h1155
-rw-r--r--cpukit/score/cpu/avr/avr/iom32c1.h1297
-rw-r--r--cpukit/score/cpu/avr/avr/iom32hvb.h885
-rw-r--r--cpukit/score/cpu/avr/avr/iom32m1.h1571
-rw-r--r--cpukit/score/cpu/avr/avr/iom32u2.h980
-rw-r--r--cpukit/score/cpu/avr/avr/iom32u4.h1504
-rw-r--r--cpukit/score/cpu/avr/avr/iom32u6.h1411
-rw-r--r--cpukit/score/cpu/avr/avr/iom406.h768
-rw-r--r--cpukit/score/cpu/avr/avr/iom48.h87
-rw-r--r--cpukit/score/cpu/avr/avr/iom48p.h868
-rw-r--r--cpukit/score/cpu/avr/avr/iom64.h1227
-rw-r--r--cpukit/score/cpu/avr/avr/iom640.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom644.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom644p.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iom644pa.h1370
-rw-r--r--cpukit/score/cpu/avr/avr/iom645.h816
-rw-r--r--cpukit/score/cpu/avr/avr/iom6450.h907
-rw-r--r--cpukit/score/cpu/avr/avr/iom649.h992
-rw-r--r--cpukit/score/cpu/avr/avr/iom6490.h1144
-rw-r--r--cpukit/score/cpu/avr/avr/iom649p.h1477
-rw-r--r--cpukit/score/cpu/avr/avr/iom64c1.h1298
-rw-r--r--cpukit/score/cpu/avr/avr/iom64hve.h1020
-rw-r--r--cpukit/score/cpu/avr/avr/iom64m1.h1549
-rw-r--r--cpukit/score/cpu/avr/avr/iom8.h614
-rw-r--r--cpukit/score/cpu/avr/avr/iom8515.h636
-rw-r--r--cpukit/score/cpu/avr/avr/iom8535.h715
-rw-r--r--cpukit/score/cpu/avr/avr/iom88.h91
-rw-r--r--cpukit/score/cpu/avr/avr/iom88p.h874
-rw-r--r--cpukit/score/cpu/avr/avr/iom88pa.h1167
-rw-r--r--cpukit/score/cpu/avr/avr/iom8hva.h70
-rw-r--r--cpukit/score/cpu/avr/avr/iom8u2.h967
-rw-r--r--cpukit/score/cpu/avr/avr/iomx8.h735
-rw-r--r--cpukit/score/cpu/avr/avr/iomxx0_1.h1553
-rw-r--r--cpukit/score/cpu/avr/avr/iomxx4.h869
-rw-r--r--cpukit/score/cpu/avr/avr/iomxxhva.h523
-rw-r--r--cpukit/score/cpu/avr/avr/iotn11.h234
-rw-r--r--cpukit/score/cpu/avr/avr/iotn12.h265
-rw-r--r--cpukit/score/cpu/avr/avr/iotn13.h364
-rw-r--r--cpukit/score/cpu/avr/avr/iotn13a.h384
-rw-r--r--cpukit/score/cpu/avr/avr/iotn15.h333
-rw-r--r--cpukit/score/cpu/avr/avr/iotn167.h832
-rw-r--r--cpukit/score/cpu/avr/avr/iotn22.h205
-rw-r--r--cpukit/score/cpu/avr/avr/iotn2313.h633
-rw-r--r--cpukit/score/cpu/avr/avr/iotn2313a.h769
-rw-r--r--cpukit/score/cpu/avr/avr/iotn24.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn24a.h831
-rw-r--r--cpukit/score/cpu/avr/avr/iotn25.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn26.h385
-rw-r--r--cpukit/score/cpu/avr/avr/iotn261.h88
-rw-r--r--cpukit/score/cpu/avr/avr/iotn261a.h976
-rw-r--r--cpukit/score/cpu/avr/avr/iotn28.h275
-rw-r--r--cpukit/score/cpu/avr/avr/iotn4313.h769
-rw-r--r--cpukit/score/cpu/avr/avr/iotn43u.h575
-rw-r--r--cpukit/score/cpu/avr/avr/iotn44.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn44a.h831
-rw-r--r--cpukit/score/cpu/avr/avr/iotn45.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn461.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn461a.h976
-rw-r--r--cpukit/score/cpu/avr/avr/iotn48.h757
-rw-r--r--cpukit/score/cpu/avr/avr/iotn84.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn85.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn861.h89
-rw-r--r--cpukit/score/cpu/avr/avr/iotn861a.h976
-rw-r--r--cpukit/score/cpu/avr/avr/iotn87.h847
-rw-r--r--cpukit/score/cpu/avr/avr/iotn88.h757
-rw-r--r--cpukit/score/cpu/avr/avr/iotnx4.h456
-rw-r--r--cpukit/score/cpu/avr/avr/iotnx5.h416
-rw-r--r--cpukit/score/cpu/avr/avr/iotnx61.h515
-rw-r--r--cpukit/score/cpu/avr/avr/iousb1286.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iousb1287.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iousb162.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iousb646.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iousb647.h94
-rw-r--r--cpukit/score/cpu/avr/avr/iousb82.h88
-rw-r--r--cpukit/score/cpu/avr/avr/iousbxx2.h766
-rw-r--r--cpukit/score/cpu/avr/avr/iousbxx6_7.h1285
-rw-r--r--cpukit/score/cpu/avr/avr/iox128a1.h7140
-rw-r--r--cpukit/score/cpu/avr/avr/iox128a3.h6890
-rw-r--r--cpukit/score/cpu/avr/avr/iox128d3.h5646
-rw-r--r--cpukit/score/cpu/avr/avr/iox16a4.h6645
-rw-r--r--cpukit/score/cpu/avr/avr/iox16d4.h5542
-rw-r--r--cpukit/score/cpu/avr/avr/iox192a3.h6890
-rw-r--r--cpukit/score/cpu/avr/avr/iox192d3.h5646
-rw-r--r--cpukit/score/cpu/avr/avr/iox256a3.h6890
-rw-r--r--cpukit/score/cpu/avr/avr/iox256a3b.h6892
-rw-r--r--cpukit/score/cpu/avr/avr/iox256d3.h5456
-rw-r--r--cpukit/score/cpu/avr/avr/iox32a4.h6645
-rw-r--r--cpukit/score/cpu/avr/avr/iox32d4.h5545
-rw-r--r--cpukit/score/cpu/avr/avr/iox64a1.h7140
-rw-r--r--cpukit/score/cpu/avr/avr/iox64a3.h6890
-rw-r--r--cpukit/score/cpu/avr/avr/iox64d3.h5660
-rw-r--r--cpukit/score/cpu/avr/avr/lock.h239
-rw-r--r--cpukit/score/cpu/avr/avr/parity.h39
-rw-r--r--cpukit/score/cpu/avr/avr/pgmspace.h882
-rw-r--r--cpukit/score/cpu/avr/avr/portpins.h549
-rw-r--r--cpukit/score/cpu/avr/avr/power.h1475
-rw-r--r--cpukit/score/cpu/avr/avr/sfr_defs.h269
-rw-r--r--cpukit/score/cpu/avr/avr/signal.h39
-rw-r--r--cpukit/score/cpu/avr/avr/signature.h84
-rw-r--r--cpukit/score/cpu/avr/avr/sleep.h588
-rw-r--r--cpukit/score/cpu/avr/avr/version.h90
-rw-r--r--cpukit/score/cpu/avr/avr/wdt.h441
-rw-r--r--cpukit/score/cpu/avr/cpu.c172
-rw-r--r--cpukit/score/cpu/avr/cpu_asm.S461
-rw-r--r--cpukit/score/cpu/avr/preinstall.am642
-rw-r--r--cpukit/score/cpu/avr/rtems/asm.h463
-rw-r--r--cpukit/score/cpu/avr/rtems/score/avr.h110
-rw-r--r--cpukit/score/cpu/avr/rtems/score/cpu.h1162
-rw-r--r--cpukit/score/cpu/avr/rtems/score/cpu_asm.h72
-rw-r--r--cpukit/score/cpu/avr/rtems/score/types.h44
-rw-r--r--cpukit/score/cpu/bfin/.cvsignore2
-rw-r--r--cpukit/score/cpu/bfin/ChangeLog232
-rw-r--r--cpukit/score/cpu/bfin/Makefile.am22
-rw-r--r--cpukit/score/cpu/bfin/cpu.c214
-rw-r--r--cpukit/score/cpu/bfin/cpu_asm.S582
-rw-r--r--cpukit/score/cpu/bfin/preinstall.am58
-rw-r--r--cpukit/score/cpu/bfin/rtems/asm.h125
-rw-r--r--cpukit/score/cpu/bfin/rtems/bfin/bf533.h394
-rw-r--r--cpukit/score/cpu/bfin/rtems/bfin/bfin.h85
-rw-r--r--cpukit/score/cpu/bfin/rtems/score/bfin.h65
-rw-r--r--cpukit/score/cpu/bfin/rtems/score/cpu.h1264
-rw-r--r--cpukit/score/cpu/bfin/rtems/score/cpu_asm.h27
-rw-r--r--cpukit/score/cpu/bfin/rtems/score/types.h45
-rw-r--r--cpukit/score/cpu/h8300/.cvsignore2
-rw-r--r--cpukit/score/cpu/h8300/ChangeLog489
-rw-r--r--cpukit/score/cpu/h8300/Makefile.am19
-rw-r--r--cpukit/score/cpu/h8300/README31
-rw-r--r--cpukit/score/cpu/h8300/cpu.c158
-rw-r--r--cpukit/score/cpu/h8300/cpu_asm.S225
-rw-r--r--cpukit/score/cpu/h8300/preinstall.am41
-rw-r--r--cpukit/score/cpu/h8300/rtems/asm.h117
-rw-r--r--cpukit/score/cpu/h8300/rtems/score/cpu.h1146
-rw-r--r--cpukit/score/cpu/h8300/rtems/score/h8300.h43
-rw-r--r--cpukit/score/cpu/h8300/rtems/score/types.h44
-rw-r--r--cpukit/score/cpu/i386/.cvsignore2
-rw-r--r--cpukit/score/cpu/i386/ChangeLog515
-rw-r--r--cpukit/score/cpu/i386/Makefile.am20
-rw-r--r--cpukit/score/cpu/i386/cpu.c244
-rw-r--r--cpukit/score/cpu/i386/cpu_asm.S320
-rw-r--r--cpukit/score/cpu/i386/preinstall.am53
-rw-r--r--cpukit/score/cpu/i386/rtems/asm.h139
-rw-r--r--cpukit/score/cpu/i386/rtems/score/cpu.h660
-rw-r--r--cpukit/score/cpu/i386/rtems/score/i386.h246
-rw-r--r--cpukit/score/cpu/i386/rtems/score/idtr.h66
-rw-r--r--cpukit/score/cpu/i386/rtems/score/interrupts.h79
-rw-r--r--cpukit/score/cpu/i386/rtems/score/registers.h72
-rw-r--r--cpukit/score/cpu/i386/rtems/score/types.h44
-rw-r--r--cpukit/score/cpu/i386/sse_test.c954
-rw-r--r--cpukit/score/cpu/lm32/.cvsignore2
-rw-r--r--cpukit/score/cpu/lm32/ChangeLog114
-rw-r--r--cpukit/score/cpu/lm32/Makefile.am19
-rw-r--r--cpukit/score/cpu/lm32/cpu.c174
-rw-r--r--cpukit/score/cpu/lm32/cpu_asm.S205
-rw-r--r--cpukit/score/cpu/lm32/irq.c93
-rw-r--r--cpukit/score/cpu/lm32/preinstall.am45
-rw-r--r--cpukit/score/cpu/lm32/rtems/asm.h125
-rw-r--r--cpukit/score/cpu/lm32/rtems/score/cpu.h1266
-rw-r--r--cpukit/score/cpu/lm32/rtems/score/cpu_asm.h74
-rw-r--r--cpukit/score/cpu/lm32/rtems/score/lm32.h111
-rw-r--r--cpukit/score/cpu/lm32/rtems/score/types.h52
-rw-r--r--cpukit/score/cpu/m32c/.cvsignore2
-rw-r--r--cpukit/score/cpu/m32c/ChangeLog98
-rw-r--r--cpukit/score/cpu/m32c/Makefile.am22
-rw-r--r--cpukit/score/cpu/m32c/context_init.c81
-rw-r--r--cpukit/score/cpu/m32c/context_switch.S68
-rw-r--r--cpukit/score/cpu/m32c/cpu.c165
-rw-r--r--cpukit/score/cpu/m32c/cpu_asm.c105
-rw-r--r--cpukit/score/cpu/m32c/preinstall.am54
-rw-r--r--cpukit/score/cpu/m32c/rtems/asm.h125
-rw-r--r--cpukit/score/cpu/m32c/rtems/score/cpu.h1186
-rw-r--r--cpukit/score/cpu/m32c/rtems/score/cpu_asm.h72
-rw-r--r--cpukit/score/cpu/m32c/rtems/score/m32c.h72
-rw-r--r--cpukit/score/cpu/m32c/rtems/score/types.h49
-rw-r--r--cpukit/score/cpu/m32c/varvects.S47
-rw-r--r--cpukit/score/cpu/m32c/varvects.h54
-rw-r--r--cpukit/score/cpu/m32r/.cvsignore2
-rw-r--r--cpukit/score/cpu/m32r/ChangeLog68
-rw-r--r--cpukit/score/cpu/m32r/Makefile.am21
-rw-r--r--cpukit/score/cpu/m32r/context_init.c56
-rw-r--r--cpukit/score/cpu/m32r/context_switch.S69
-rw-r--r--cpukit/score/cpu/m32r/cpu.c126
-rw-r--r--cpukit/score/cpu/m32r/cpu_asm.c95
-rw-r--r--cpukit/score/cpu/m32r/preinstall.am50
-rw-r--r--cpukit/score/cpu/m32r/rtems/asm.h125
-rw-r--r--cpukit/score/cpu/m32r/rtems/score/cpu.h1247
-rw-r--r--cpukit/score/cpu/m32r/rtems/score/cpu_asm.h72
-rw-r--r--cpukit/score/cpu/m32r/rtems/score/m32r.h66
-rw-r--r--cpukit/score/cpu/m32r/rtems/score/types.h49
-rw-r--r--cpukit/score/cpu/m68k/.cvsignore2
-rw-r--r--cpukit/score/cpu/m68k/ChangeLog641
-rw-r--r--cpukit/score/cpu/m68k/Makefile.am24
-rw-r--r--cpukit/score/cpu/m68k/cpu.c213
-rw-r--r--cpukit/score/cpu/m68k/cpu_asm.S386
-rw-r--r--cpukit/score/cpu/m68k/preinstall.am62
-rw-r--r--cpukit/score/cpu/m68k/rtems/asm.h151
-rw-r--r--cpukit/score/cpu/m68k/rtems/m68k/m68302.h660
-rw-r--r--cpukit/score/cpu/m68k/rtems/m68k/m68360.h896
-rw-r--r--cpukit/score/cpu/m68k/rtems/m68k/qsm.h204
-rw-r--r--cpukit/score/cpu/m68k/rtems/m68k/sim.h333
-rw-r--r--cpukit/score/cpu/m68k/rtems/score/cpu.h753
-rw-r--r--cpukit/score/cpu/m68k/rtems/score/m68k.h504
-rw-r--r--cpukit/score/cpu/m68k/rtems/score/types.h44
-rw-r--r--cpukit/score/cpu/mips/.cvsignore2
-rw-r--r--cpukit/score/cpu/mips/ChangeLog685
-rw-r--r--cpukit/score/cpu/mips/Makefile.am22
-rw-r--r--cpukit/score/cpu/mips/cpu.c325
-rw-r--r--cpukit/score/cpu/mips/cpu_asm.S1137
-rw-r--r--cpukit/score/cpu/mips/preinstall.am54
-rw-r--r--cpukit/score/cpu/mips/rtems/asm.h159
-rw-r--r--cpukit/score/cpu/mips/rtems/mips/idtcpu.h697
-rw-r--r--cpukit/score/cpu/mips/rtems/mips/iregdef.h332
-rw-r--r--cpukit/score/cpu/mips/rtems/score/cpu.h1156
-rw-r--r--cpukit/score/cpu/mips/rtems/score/mips.h283
-rw-r--r--cpukit/score/cpu/mips/rtems/score/types.h45
-rw-r--r--cpukit/score/cpu/nios2/.cvsignore2
-rw-r--r--cpukit/score/cpu/nios2/ChangeLog141
-rw-r--r--cpukit/score/cpu/nios2/Makefile.am25
-rw-r--r--cpukit/score/cpu/nios2/cpu.c180
-rw-r--r--cpukit/score/cpu/nios2/cpu_asm.S386
-rw-r--r--cpukit/score/cpu/nios2/irq.c91
-rw-r--r--cpukit/score/cpu/nios2/preinstall.am45
-rw-r--r--cpukit/score/cpu/nios2/rtems/asm.h97
-rw-r--r--cpukit/score/cpu/nios2/rtems/score/cpu.h1310
-rw-r--r--cpukit/score/cpu/nios2/rtems/score/cpu_asm.h74
-rw-r--r--cpukit/score/cpu/nios2/rtems/score/nios2.h62
-rw-r--r--cpukit/score/cpu/nios2/rtems/score/types.h44
-rw-r--r--cpukit/score/cpu/no_cpu/.cvsignore2
-rw-r--r--cpukit/score/cpu/no_cpu/ChangeLog420
-rw-r--r--cpukit/score/cpu/no_cpu/Makefile.am19
-rw-r--r--cpukit/score/cpu/no_cpu/cpu.c168
-rw-r--r--cpukit/score/cpu/no_cpu/cpu_asm.c184
-rw-r--r--cpukit/score/cpu/no_cpu/preinstall.am45
-rw-r--r--cpukit/score/cpu/no_cpu/rtems/asm.h125
-rw-r--r--cpukit/score/cpu/no_cpu/rtems/score/cpu.h1246
-rw-r--r--cpukit/score/cpu/no_cpu/rtems/score/cpu_asm.h72
-rw-r--r--cpukit/score/cpu/no_cpu/rtems/score/no_cpu.h69
-rw-r--r--cpukit/score/cpu/no_cpu/rtems/score/types.h49
-rw-r--r--cpukit/score/cpu/powerpc/.cvsignore2
-rw-r--r--cpukit/score/cpu/powerpc/ChangeLog945
-rw-r--r--cpukit/score/cpu/powerpc/Makefile.am22
-rw-r--r--cpukit/score/cpu/powerpc/cpu.c17
-rw-r--r--cpukit/score/cpu/powerpc/preinstall.am50
-rw-r--r--cpukit/score/cpu/powerpc/rtems/asm.h271
-rw-r--r--cpukit/score/cpu/powerpc/rtems/powerpc/registers.h541
-rw-r--r--cpukit/score/cpu/powerpc/rtems/score/cpu.h979
-rw-r--r--cpukit/score/cpu/powerpc/rtems/score/powerpc.h168
-rw-r--r--cpukit/score/cpu/powerpc/rtems/score/types.h59
-rw-r--r--cpukit/score/cpu/sh/.cvsignore2
-rw-r--r--cpukit/score/cpu/sh/ChangeLog478
-rw-r--r--cpukit/score/cpu/sh/Makefile.am19
-rw-r--r--cpukit/score/cpu/sh/context.c230
-rw-r--r--cpukit/score/cpu/sh/cpu.c230
-rw-r--r--cpukit/score/cpu/sh/preinstall.am45
-rw-r--r--cpukit/score/cpu/sh/rtems/asm.h136
-rw-r--r--cpukit/score/cpu/sh/rtems/score/cpu.h891
-rw-r--r--cpukit/score/cpu/sh/rtems/score/sh.h277
-rw-r--r--cpukit/score/cpu/sh/rtems/score/sh_io.h51
-rw-r--r--cpukit/score/cpu/sh/rtems/score/types.h55
-rw-r--r--cpukit/score/cpu/sparc/.cvsignore2
-rw-r--r--cpukit/score/cpu/sparc/ChangeLog496
-rw-r--r--cpukit/score/cpu/sparc/Makefile.am19
-rw-r--r--cpukit/score/cpu/sparc/README110
-rw-r--r--cpukit/score/cpu/sparc/cpu.c333
-rw-r--r--cpukit/score/cpu/sparc/cpu_asm.S357
-rw-r--r--cpukit/score/cpu/sparc/preinstall.am41
-rw-r--r--cpukit/score/cpu/sparc/rtems/asm.h119
-rw-r--r--cpukit/score/cpu/sparc/rtems/score/cpu.h1023
-rw-r--r--cpukit/score/cpu/sparc/rtems/score/sparc.h236
-rw-r--r--cpukit/score/cpu/sparc/rtems/score/types.h44
-rw-r--r--cpukit/score/cpu/sparc64/.cvsignore2
-rw-r--r--cpukit/score/cpu/sparc64/ChangeLog71
-rw-r--r--cpukit/score/cpu/sparc64/Makefile.am22
-rw-r--r--cpukit/score/cpu/sparc64/README15
-rw-r--r--cpukit/score/cpu/sparc64/context.S322
-rw-r--r--cpukit/score/cpu/sparc64/cpu.c116
-rw-r--r--cpukit/score/cpu/sparc64/preinstall.am41
-rw-r--r--cpukit/score/cpu/sparc64/rtems/asm.h102
-rw-r--r--cpukit/score/cpu/sparc64/rtems/score/cpu.h1067
-rw-r--r--cpukit/score/cpu/sparc64/rtems/score/sparc64.h341
-rw-r--r--cpukit/score/cpu/sparc64/rtems/score/types.h44
-rw-r--r--cpukit/score/include/rtems/bspsmp.h233
-rw-r--r--cpukit/score/include/rtems/debug.h81
-rw-r--r--cpukit/score/include/rtems/score/.cvsignore1
-rw-r--r--cpukit/score/include/rtems/score/address.h43
-rw-r--r--cpukit/score/include/rtems/score/apiext.h133
-rw-r--r--cpukit/score/include/rtems/score/apimutex.h116
-rw-r--r--cpukit/score/include/rtems/score/basedefs.h175
-rw-r--r--cpukit/score/include/rtems/score/bitfield.h106
-rw-r--r--cpukit/score/include/rtems/score/chain.h258
-rw-r--r--cpukit/score/include/rtems/score/context.h180
-rw-r--r--cpukit/score/include/rtems/score/copyrt.h42
-rw-r--r--cpukit/score/include/rtems/score/corebarrier.h202
-rw-r--r--cpukit/score/include/rtems/score/coremsg.h451
-rw-r--r--cpukit/score/include/rtems/score/coremutex.h468
-rw-r--r--cpukit/score/include/rtems/score/corerwlock.h235
-rw-r--r--cpukit/score/include/rtems/score/coresem.h209
-rw-r--r--cpukit/score/include/rtems/score/corespinlock.h163
-rw-r--r--cpukit/score/include/rtems/score/heap.h662
-rw-r--r--cpukit/score/include/rtems/score/interr.h115
-rw-r--r--cpukit/score/include/rtems/score/isr.h212
-rw-r--r--cpukit/score/include/rtems/score/mpci.h404
-rw-r--r--cpukit/score/include/rtems/score/mppkt.h123
-rw-r--r--cpukit/score/include/rtems/score/object.h845
-rw-r--r--cpukit/score/include/rtems/score/objectmp.h188
-rw-r--r--cpukit/score/include/rtems/score/percpu.h257
-rw-r--r--cpukit/score/include/rtems/score/priority.h85
-rw-r--r--cpukit/score/include/rtems/score/prioritybitmap.h124
-rw-r--r--cpukit/score/include/rtems/score/protectedheap.h165
-rw-r--r--cpukit/score/include/rtems/score/scheduler.h122
-rw-r--r--cpukit/score/include/rtems/score/schedulerpriority.h194
-rw-r--r--cpukit/score/include/rtems/score/schedulersimple.h199
-rw-r--r--cpukit/score/include/rtems/score/smplock.h95
-rw-r--r--cpukit/score/include/rtems/score/stack.h69
-rw-r--r--cpukit/score/include/rtems/score/states.h127
-rw-r--r--cpukit/score/include/rtems/score/sysstate.h98
-rw-r--r--cpukit/score/include/rtems/score/thread.h790
-rw-r--r--cpukit/score/include/rtems/score/threadmp.h88
-rw-r--r--cpukit/score/include/rtems/score/threadq.h300
-rw-r--r--cpukit/score/include/rtems/score/threadsync.h58
-rw-r--r--cpukit/score/include/rtems/score/timespec.h247
-rw-r--r--cpukit/score/include/rtems/score/timestamp.h426
-rw-r--r--cpukit/score/include/rtems/score/timestamp64.h370
-rw-r--r--cpukit/score/include/rtems/score/tod.h255
-rw-r--r--cpukit/score/include/rtems/score/tqdata.h116
-rw-r--r--cpukit/score/include/rtems/score/userext.h331
-rw-r--r--cpukit/score/include/rtems/score/watchdog.h323
-rw-r--r--cpukit/score/include/rtems/score/wkspace.h106
-rw-r--r--cpukit/score/include/rtems/seterr.h47
-rw-r--r--cpukit/score/include/rtems/system.h64
-rw-r--r--cpukit/score/inline/rtems/score/address.inl143
-rw-r--r--cpukit/score/inline/rtems/score/chain.inl647
-rw-r--r--cpukit/score/inline/rtems/score/corebarrier.inl66
-rw-r--r--cpukit/score/inline/rtems/score/coremsg.inl263
-rw-r--r--cpukit/score/inline/rtems/score/coremutex.inl229
-rw-r--r--cpukit/score/inline/rtems/score/corerwlock.inl51
-rw-r--r--cpukit/score/inline/rtems/score/coresem.inl115
-rw-r--r--cpukit/score/inline/rtems/score/corespinlock.inl63
-rw-r--r--cpukit/score/inline/rtems/score/heap.inl243
-rw-r--r--cpukit/score/inline/rtems/score/isr.inl58
-rw-r--r--cpukit/score/inline/rtems/score/mppkt.inl61
-rw-r--r--cpukit/score/inline/rtems/score/object.inl357
-rw-r--r--cpukit/score/inline/rtems/score/objectmp.inl71
-rw-r--r--cpukit/score/inline/rtems/score/priority.inl53
-rw-r--r--cpukit/score/inline/rtems/score/prioritybitmap.inl193
-rw-r--r--cpukit/score/inline/rtems/score/scheduler.inl165
-rw-r--r--cpukit/score/inline/rtems/score/schedulerpriority.inl195
-rw-r--r--cpukit/score/inline/rtems/score/schedulersimple.inl53
-rw-r--r--cpukit/score/inline/rtems/score/stack.inl113
-rw-r--r--cpukit/score/inline/rtems/score/states.inl377
-rw-r--r--cpukit/score/inline/rtems/score/sysstate.inl104
-rw-r--r--cpukit/score/inline/rtems/score/thread.inl353
-rw-r--r--cpukit/score/inline/rtems/score/threadmp.inl64
-rw-r--r--cpukit/score/inline/rtems/score/threadq.inl36
-rw-r--r--cpukit/score/inline/rtems/score/tod.inl79
-rw-r--r--cpukit/score/inline/rtems/score/tqdata.inl73
-rw-r--r--cpukit/score/inline/rtems/score/watchdog.inl262
-rw-r--r--cpukit/score/inline/rtems/score/wkspace.inl34
-rw-r--r--cpukit/score/preinstall.am337
-rw-r--r--cpukit/score/src/Unlimited.txt364
-rw-r--r--cpukit/score/src/apiext.c113
-rw-r--r--cpukit/score/src/apimutex.c37
-rw-r--r--cpukit/score/src/apimutexallocate.c39
-rw-r--r--cpukit/score/src/apimutexlock.c34
-rw-r--r--cpukit/score/src/apimutexunlock.c30
-rw-r--r--cpukit/score/src/chain.c61
-rw-r--r--cpukit/score/src/chainappend.c46
-rw-r--r--cpukit/score/src/chainappendempty.c44
-rw-r--r--cpukit/score/src/chainextract.c44
-rw-r--r--cpukit/score/src/chainget.c51
-rw-r--r--cpukit/score/src/chaingetempty.c44
-rw-r--r--cpukit/score/src/chaininsert.c47
-rw-r--r--cpukit/score/src/chainprependempty.c44
-rw-r--r--cpukit/score/src/corebarrier.c57
-rw-r--r--cpukit/score/src/corebarrierrelease.c70
-rw-r--r--cpukit/score/src/corebarrierwait.c78
-rw-r--r--cpukit/score/src/coremsg.c120
-rw-r--r--cpukit/score/src/coremsgbroadcast.c116
-rw-r--r--cpukit/score/src/coremsgclose.c77
-rw-r--r--cpukit/score/src/coremsgflush.c55
-rw-r--r--cpukit/score/src/coremsgflushsupp.c106
-rw-r--r--cpukit/score/src/coremsgflushwait.c72
-rw-r--r--cpukit/score/src/coremsginsert.c133
-rw-r--r--cpukit/score/src/coremsgseize.c157
-rw-r--r--cpukit/score/src/coremsgsubmit.c180
-rw-r--r--cpukit/score/src/coremutex.c94
-rw-r--r--cpukit/score/src/coremutexflush.c55
-rw-r--r--cpukit/score/src/coremutexseize.c78
-rw-r--r--cpukit/score/src/coremutexseizeintr.c33
-rw-r--r--cpukit/score/src/coremutexsurrender.c231
-rw-r--r--cpukit/score/src/corerwlock.c61
-rw-r--r--cpukit/score/src/corerwlockobtainread.c108
-rw-r--r--cpukit/score/src/corerwlockobtainwrite.c99
-rw-r--r--cpukit/score/src/corerwlockrelease.c106
-rw-r--r--cpukit/score/src/corerwlocktimeout.c55
-rw-r--r--cpukit/score/src/coresem.c63
-rw-r--r--cpukit/score/src/coresemflush.c58
-rw-r--r--cpukit/score/src/coresemseize.c88
-rw-r--r--cpukit/score/src/coresemsurrender.c76
-rw-r--r--cpukit/score/src/corespinlock.c53
-rw-r--r--cpukit/score/src/corespinlockrelease.c72
-rw-r--r--cpukit/score/src/corespinlockwait.c114
-rw-r--r--cpukit/score/src/coretod.c47
-rw-r--r--cpukit/score/src/coretodget.c56
-rw-r--r--cpukit/score/src/coretodgetuptime.c56
-rw-r--r--cpukit/score/src/coretodgetuptimetimespec.c44
-rw-r--r--cpukit/score/src/coretodmsecstoticks.c25
-rw-r--r--cpukit/score/src/coretodset.c62
-rw-r--r--cpukit/score/src/coretodtickle.c60
-rw-r--r--cpukit/score/src/coretodtickspersec.c24
-rw-r--r--cpukit/score/src/coretodusectoticks.c25
-rw-r--r--cpukit/score/src/heap.c488
-rw-r--r--cpukit/score/src/heapallocate.c280
-rw-r--r--cpukit/score/src/heapextend.c243
-rw-r--r--cpukit/score/src/heapfree.c215
-rw-r--r--cpukit/score/src/heapgetfreeinfo.c54
-rw-r--r--cpukit/score/src/heapgetinfo.c57
-rw-r--r--cpukit/score/src/heapresizeblock.c119
-rw-r--r--cpukit/score/src/heapsizeofuserarea.c58
-rw-r--r--cpukit/score/src/heapwalk.c421
-rw-r--r--cpukit/score/src/interr.c65
-rw-r--r--cpukit/score/src/isr.c83
-rw-r--r--cpukit/score/src/iterateoverthreads.c55
-rw-r--r--cpukit/score/src/mpci.c540
-rw-r--r--cpukit/score/src/objectallocate.c102
-rw-r--r--cpukit/score/src/objectapimaximumclass.c36
-rw-r--r--cpukit/score/src/objectclose.c28
-rw-r--r--cpukit/score/src/objectextendinformation.c266
-rw-r--r--cpukit/score/src/objectfree.c69
-rw-r--r--cpukit/score/src/objectget.c108
-rw-r--r--cpukit/score/src/objectgetinfo.c62
-rw-r--r--cpukit/score/src/objectgetinfoid.c28
-rw-r--r--cpukit/score/src/objectgetisr.c86
-rw-r--r--cpukit/score/src/objectgetnameasstring.c96
-rw-r--r--cpukit/score/src/objectgetnext.c103
-rw-r--r--cpukit/score/src/objectgetnoprotection.c79
-rw-r--r--cpukit/score/src/objectidtoname.c79
-rw-r--r--cpukit/score/src/objectinitializeinformation.c178
-rw-r--r--cpukit/score/src/objectmp.c307
-rw-r--r--cpukit/score/src/objectnamespaceremove.c40
-rw-r--r--cpukit/score/src/objectnametoid.c102
-rw-r--r--cpukit/score/src/objectnametoidstring.c87
-rw-r--r--cpukit/score/src/objectsetname.c69
-rw-r--r--cpukit/score/src/objectshrinkinformation.c102
-rw-r--r--cpukit/score/src/percpu.c64
-rw-r--r--cpukit/score/src/pheapallocate.c46
-rw-r--r--cpukit/score/src/pheapextend.c41
-rw-r--r--cpukit/score/src/pheapfree.c38
-rw-r--r--cpukit/score/src/pheapgetblocksize.c39
-rw-r--r--cpukit/score/src/pheapgetfreeinfo.c42
-rw-r--r--cpukit/score/src/pheapgetinfo.c43
-rw-r--r--cpukit/score/src/pheapgetsize.c32
-rw-r--r--cpukit/score/src/pheapinit.c27
-rw-r--r--cpukit/score/src/pheapresizeblock.c43
-rw-r--r--cpukit/score/src/pheapwalk.c50
-rw-r--r--cpukit/score/src/scheduler.c25
-rw-r--r--cpukit/score/src/schedulerpriority.c33
-rw-r--r--cpukit/score/src/schedulerpriorityallocate.c35
-rw-r--r--cpukit/score/src/schedulerpriorityblock.c42
-rw-r--r--cpukit/score/src/schedulerpriorityenqueue.c26
-rw-r--r--cpukit/score/src/schedulerpriorityenqueuefirst.c27
-rw-r--r--cpukit/score/src/schedulerpriorityextract.c27
-rw-r--r--cpukit/score/src/schedulerpriorityfree.c29
-rw-r--r--cpukit/score/src/schedulerpriorityschedule.c25
-rw-r--r--cpukit/score/src/schedulerpriorityunblock.c48
-rw-r--r--cpukit/score/src/schedulerpriorityupdate.c42
-rw-r--r--cpukit/score/src/schedulerpriorityyield.c55
-rw-r--r--cpukit/score/src/schedulersimple.c84
-rw-r--r--cpukit/score/src/schedulersimpleblock.c39
-rw-r--r--cpukit/score/src/schedulersimpleenqueue.c29
-rw-r--r--cpukit/score/src/schedulersimpleenqueuefirst.c28
-rw-r--r--cpukit/score/src/schedulersimpleextract.c28
-rw-r--r--cpukit/score/src/schedulersimplereadyqueueenqueue.c48
-rw-r--r--cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c52
-rw-r--r--cpukit/score/src/schedulersimpleschedule.c34
-rw-r--r--cpukit/score/src/schedulersimpleunblock.c47
-rw-r--r--cpukit/score/src/schedulersimpleyield.c42
-rw-r--r--cpukit/score/src/smp.c153
-rw-r--r--cpukit/score/src/smplock.c49
-rw-r--r--cpukit/score/src/thread.c123
-rw-r--r--cpukit/score/src/threadblockingoperationcancel.c89
-rw-r--r--cpukit/score/src/threadchangepriority.c99
-rw-r--r--cpukit/score/src/threadclearstate.c58
-rw-r--r--cpukit/score/src/threadclose.c104
-rw-r--r--cpukit/score/src/threadcreateidle.c106
-rw-r--r--cpukit/score/src/threaddelayended.c71
-rw-r--r--cpukit/score/src/threaddispatch.c193
-rw-r--r--cpukit/score/src/threadget.c100
-rw-r--r--cpukit/score/src/threadhandler.c189
-rw-r--r--cpukit/score/src/threadinitialize.c242
-rw-r--r--cpukit/score/src/threadloadenv.c74
-rw-r--r--cpukit/score/src/threadmp.c168
-rw-r--r--cpukit/score/src/threadq.c66
-rw-r--r--cpukit/score/src/threadqdequeue.c72
-rw-r--r--cpukit/score/src/threadqdequeuefifo.c79
-rw-r--r--cpukit/score/src/threadqdequeuepriority.c125
-rw-r--r--cpukit/score/src/threadqenqueue.c97
-rw-r--r--cpukit/score/src/threadqenqueuefifo.c78
-rw-r--r--cpukit/score/src/threadqenqueuepriority.c197
-rw-r--r--cpukit/score/src/threadqextract.c58
-rw-r--r--cpukit/score/src/threadqextractfifo.c78
-rw-r--r--cpukit/score/src/threadqextractpriority.c125
-rw-r--r--cpukit/score/src/threadqextractwithproxy.c67
-rw-r--r--cpukit/score/src/threadqfirst.c54
-rw-r--r--cpukit/score/src/threadqfirstfifo.c50
-rw-r--r--cpukit/score/src/threadqfirstpriority.c57
-rw-r--r--cpukit/score/src/threadqflush.c62
-rw-r--r--cpukit/score/src/threadqprocesstimeout.c57
-rw-r--r--cpukit/score/src/threadqrequeue.c74
-rw-r--r--cpukit/score/src/threadqtimeout.c60
-rw-r--r--cpukit/score/src/threadready.c51
-rw-r--r--cpukit/score/src/threadreset.c67
-rw-r--r--cpukit/score/src/threadrestart.c68
-rw-r--r--cpukit/score/src/threadsetpriority.c30
-rw-r--r--cpukit/score/src/threadsetstate.c58
-rw-r--r--cpukit/score/src/threadsettransient.c56
-rw-r--r--cpukit/score/src/threadstackallocate.c84
-rw-r--r--cpukit/score/src/threadstackfree.c62
-rw-r--r--cpukit/score/src/threadstart.c69
-rw-r--r--cpukit/score/src/threadstartmultitasking.c91
-rw-r--r--cpukit/score/src/threadtickletimeslice.c105
-rw-r--r--cpukit/score/src/timespecaddto.c51
-rw-r--r--cpukit/score/src/timespecdivide.c59
-rw-r--r--cpukit/score/src/timespecdividebyinteger.c53
-rw-r--r--cpukit/score/src/timespecfromticks.c35
-rw-r--r--cpukit/score/src/timespecgreaterthan.c42
-rw-r--r--cpukit/score/src/timespecisvalid.c43
-rw-r--r--cpukit/score/src/timespeclessthan.c42
-rw-r--r--cpukit/score/src/timespecsubtract.c41
-rw-r--r--cpukit/score/src/timespectoticks.c50
-rw-r--r--cpukit/score/src/ts64addto.c34
-rw-r--r--cpukit/score/src/ts64divide.c52
-rw-r--r--cpukit/score/src/ts64dividebyinteger.c35
-rw-r--r--cpukit/score/src/ts64equalto.c34
-rw-r--r--cpukit/score/src/ts64getnanoseconds.c33
-rw-r--r--cpukit/score/src/ts64getseconds.c33
-rw-r--r--cpukit/score/src/ts64greaterthan.c34
-rw-r--r--cpukit/score/src/ts64lessthan.c34
-rw-r--r--cpukit/score/src/ts64set.c39
-rw-r--r--cpukit/score/src/ts64settozero.c33
-rw-r--r--cpukit/score/src/ts64subtract.c35
-rw-r--r--cpukit/score/src/ts64toticks.c40
-rw-r--r--cpukit/score/src/ts64totimespec.c35
-rw-r--r--cpukit/score/src/userext.c61
-rw-r--r--cpukit/score/src/userextaddset.c45
-rw-r--r--cpukit/score/src/userextremoveset.c39
-rw-r--r--cpukit/score/src/userextthreadbegin.c81
-rw-r--r--cpukit/score/src/userextthreadcreate.c52
-rw-r--r--cpukit/score/src/userextthreaddelete.c46
-rw-r--r--cpukit/score/src/userextthreadrestart.c46
-rw-r--r--cpukit/score/src/userextthreadstart.c46
-rw-r--r--cpukit/score/src/userextthreadswitch.c43
-rw-r--r--cpukit/score/src/watchdog.c42
-rw-r--r--cpukit/score/src/watchdogadjust.c87
-rw-r--r--cpukit/score/src/watchdogadjusttochain.c83
-rw-r--r--cpukit/score/src/watchdoginsert.c100
-rw-r--r--cpukit/score/src/watchdognanoseconds.c31
-rw-r--r--cpukit/score/src/watchdogremove.c73
-rw-r--r--cpukit/score/src/watchdogreport.c41
-rw-r--r--cpukit/score/src/watchdogreportchain.c50
-rw-r--r--cpukit/score/src/watchdogtickle.c129
-rw-r--r--cpukit/score/src/wkspace.c125
-rw-r--r--cpukit/telnetd/.cvsignore2
-rw-r--r--cpukit/telnetd/Makefile.am21
-rw-r--r--cpukit/telnetd/README27
-rw-r--r--cpukit/telnetd/check_passwd.c109
-rw-r--r--cpukit/telnetd/des.c879
-rw-r--r--cpukit/telnetd/genpw.c79
-rw-r--r--cpukit/telnetd/icmds.c64
-rw-r--r--cpukit/telnetd/passwd.h27
-rw-r--r--cpukit/telnetd/preinstall.am49
-rw-r--r--cpukit/telnetd/pty.c654
-rw-r--r--cpukit/telnetd/pty.h70
-rw-r--r--cpukit/telnetd/telnetd.c512
-rw-r--r--cpukit/telnetd/telnetd.h112
-rw-r--r--cpukit/wrapup/.cvsignore2
-rw-r--r--cpukit/wrapup/Makefile.am113
-rw-r--r--cpukit/wrapup/preinstall.am24
-rw-r--r--cpukit/zlib/.cvsignore2
-rw-r--r--cpukit/zlib/ChangeLog1152
-rw-r--r--cpukit/zlib/ChangeLog.zlib1130
-rw-r--r--cpukit/zlib/Makefile5
-rw-r--r--cpukit/zlib/Makefile.am28
-rw-r--r--cpukit/zlib/Makefile.in252
-rw-r--r--cpukit/zlib/algorithm.txt209
-rw-r--r--cpukit/zlib/amiga/Makefile.pup69
-rw-r--r--cpukit/zlib/amiga/Makefile.sas68
-rw-r--r--cpukit/zlib/as400/bndsrc132
-rw-r--r--cpukit/zlib/as400/compile.clp123
-rw-r--r--cpukit/zlib/as400/readme.txt111
-rw-r--r--cpukit/zlib/as400/zlib.inc331
-rwxr-xr-xcpukit/zlib/configure546
-rw-r--r--cpukit/zlib/contrib/README.contrib77
-rw-r--r--cpukit/zlib/contrib/ada/buffer_demo.adb106
-rw-r--r--cpukit/zlib/contrib/ada/mtest.adb156
-rw-r--r--cpukit/zlib/contrib/ada/read.adb156
-rw-r--r--cpukit/zlib/contrib/ada/readme.txt65
-rw-r--r--cpukit/zlib/contrib/ada/test.adb463
-rw-r--r--cpukit/zlib/contrib/ada/zlib-streams.adb225
-rw-r--r--cpukit/zlib/contrib/ada/zlib-streams.ads114
-rw-r--r--cpukit/zlib/contrib/ada/zlib-thin.adb141
-rw-r--r--cpukit/zlib/contrib/ada/zlib-thin.ads450
-rw-r--r--cpukit/zlib/contrib/ada/zlib.adb701
-rw-r--r--cpukit/zlib/contrib/ada/zlib.ads328
-rw-r--r--cpukit/zlib/contrib/ada/zlib.gpr20
-rw-r--r--cpukit/zlib/contrib/asm586/README.58643
-rw-r--r--cpukit/zlib/contrib/asm586/match.S364
-rw-r--r--cpukit/zlib/contrib/asm686/README.68651
-rw-r--r--cpukit/zlib/contrib/asm686/match.S343
-rw-r--r--cpukit/zlib/contrib/blast/Makefile8
-rw-r--r--cpukit/zlib/contrib/blast/README4
-rw-r--r--cpukit/zlib/contrib/blast/blast.c444
-rw-r--r--cpukit/zlib/contrib/blast/blast.h71
-rw-r--r--cpukit/zlib/contrib/blast/test.pkbin8 -> 0 bytes
-rw-r--r--cpukit/zlib/contrib/blast/test.txt1
-rw-r--r--cpukit/zlib/contrib/delphi/ZLib.pas557
-rw-r--r--cpukit/zlib/contrib/delphi/ZLibConst.pas11
-rw-r--r--cpukit/zlib/contrib/delphi/readme.txt76
-rw-r--r--cpukit/zlib/contrib/delphi/zlibd32.mak99
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib.build33
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib.chmbin72726 -> 0 bytes
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib.sln21
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs58
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs202
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs83
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/CodecBase.cs198
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/Deflater.cs106
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.cs288
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj141
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/GZipStream.cs301
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/Inflater.cs105
-rw-r--r--cpukit/zlib/contrib/dotzlib/DotZLib/UnitTests.cs274
-rw-r--r--cpukit/zlib/contrib/dotzlib/LICENSE_1_0.txt23
-rw-r--r--cpukit/zlib/contrib/dotzlib/readme.txt58
-rw-r--r--cpukit/zlib/contrib/infback9/README1
-rw-r--r--cpukit/zlib/contrib/infback9/infback9.c617
-rw-r--r--cpukit/zlib/contrib/infback9/infback9.h37
-rw-r--r--cpukit/zlib/contrib/infback9/inffix9.h107
-rw-r--r--cpukit/zlib/contrib/infback9/inflate9.h47
-rw-r--r--cpukit/zlib/contrib/infback9/inftree9.c324
-rw-r--r--cpukit/zlib/contrib/infback9/inftree9.h61
-rw-r--r--cpukit/zlib/contrib/inflate86/inffas86.c1157
-rw-r--r--cpukit/zlib/contrib/inflate86/inffast.S1368
-rw-r--r--cpukit/zlib/contrib/iostream/test.cpp24
-rw-r--r--cpukit/zlib/contrib/iostream/zfstream.cpp329
-rw-r--r--cpukit/zlib/contrib/iostream/zfstream.h128
-rw-r--r--cpukit/zlib/contrib/iostream2/zstream.h307
-rw-r--r--cpukit/zlib/contrib/iostream2/zstream_test.cpp25
-rw-r--r--cpukit/zlib/contrib/iostream3/README35
-rw-r--r--cpukit/zlib/contrib/iostream3/TODO17
-rw-r--r--cpukit/zlib/contrib/iostream3/test.cc50
-rw-r--r--cpukit/zlib/contrib/iostream3/zfstream.cc479
-rw-r--r--cpukit/zlib/contrib/iostream3/zfstream.h466
-rw-r--r--cpukit/zlib/contrib/masm686/match.asm413
-rw-r--r--cpukit/zlib/contrib/masmx64/bld_ml64.bat2
-rw-r--r--cpukit/zlib/contrib/masmx64/gvmat64.asm553
-rw-r--r--cpukit/zlib/contrib/masmx64/inffas8664.c186
-rw-r--r--cpukit/zlib/contrib/masmx64/inffasx64.asm396
-rw-r--r--cpukit/zlib/contrib/masmx64/inffasx64.objbin5913 -> 0 bytes
-rw-r--r--cpukit/zlib/contrib/masmx64/readme.txt31
-rw-r--r--cpukit/zlib/contrib/masmx86/bld_ml32.bat2
-rw-r--r--cpukit/zlib/contrib/masmx86/gvmat32.asm972
-rw-r--r--cpukit/zlib/contrib/masmx86/gvmat32c.c62
-rw-r--r--cpukit/zlib/contrib/masmx86/inffas32.asm1083
-rwxr-xr-xcpukit/zlib/contrib/masmx86/mkasm.bat3
-rw-r--r--cpukit/zlib/contrib/masmx86/readme.txt27
-rw-r--r--cpukit/zlib/contrib/minizip/ChangeLogUnzip67
-rw-r--r--cpukit/zlib/contrib/minizip/Makefile25
-rw-r--r--cpukit/zlib/contrib/minizip/crypt.h131
-rw-r--r--cpukit/zlib/contrib/minizip/ioapi.c235
-rw-r--r--cpukit/zlib/contrib/minizip/ioapi.h200
-rw-r--r--cpukit/zlib/contrib/minizip/iowin32.c389
-rw-r--r--cpukit/zlib/contrib/minizip/iowin32.h28
-rw-r--r--cpukit/zlib/contrib/minizip/miniunz.c648
-rw-r--r--cpukit/zlib/contrib/minizip/minizip.c507
-rw-r--r--cpukit/zlib/contrib/minizip/mztools.c281
-rw-r--r--cpukit/zlib/contrib/minizip/mztools.h31
-rw-r--r--cpukit/zlib/contrib/minizip/unzip.c2125
-rw-r--r--cpukit/zlib/contrib/minizip/unzip.h437
-rw-r--r--cpukit/zlib/contrib/minizip/zip.c2004
-rw-r--r--cpukit/zlib/contrib/minizip/zip.h362
-rw-r--r--cpukit/zlib/contrib/pascal/example.pas599
-rw-r--r--cpukit/zlib/contrib/pascal/readme.txt76
-rw-r--r--cpukit/zlib/contrib/pascal/zlibd32.mak99
-rw-r--r--cpukit/zlib/contrib/pascal/zlibpas.pas236
-rw-r--r--cpukit/zlib/contrib/puff/Makefile8
-rw-r--r--cpukit/zlib/contrib/puff/README63
-rw-r--r--cpukit/zlib/contrib/puff/puff.c955
-rw-r--r--cpukit/zlib/contrib/puff/puff.h31
-rw-r--r--cpukit/zlib/contrib/puff/zeros.rawbin1213 -> 0 bytes
-rw-r--r--cpukit/zlib/contrib/testzlib/testzlib.c275
-rw-r--r--cpukit/zlib/contrib/testzlib/testzlib.sln21
-rw-r--r--cpukit/zlib/contrib/testzlib/testzlib.txt10
-rw-r--r--cpukit/zlib/contrib/testzlib/testzlib.vcproj124
-rw-r--r--cpukit/zlib/contrib/untgz/Makefile14
-rw-r--r--cpukit/zlib/contrib/untgz/Makefile.msc17
-rw-r--r--cpukit/zlib/contrib/untgz/untgz.c674
-rw-r--r--cpukit/zlib/contrib/vstudio/readme.txt60
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/miniunz.vcproj126
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/minizip.vcproj126
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/zlib.rc32
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/zlibstat.vcproj246
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/zlibvc.def92
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/zlibvc.sln78
-rw-r--r--cpukit/zlib/contrib/vstudio/vc7/zlibvc.vcproj445
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/miniunz.vcproj566
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/minizip.vcproj563
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/testzlib.vcproj948
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/testzlibdll.vcproj567
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/zlib.rc32
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/zlibstat.vcproj870
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/zlibvc.def92
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/zlibvc.sln144
-rw-r--r--cpukit/zlib/contrib/vstudio/vc8/zlibvc.vcproj1219
-rw-r--r--cpukit/zlib/crc32.c2
-rw-r--r--cpukit/zlib/example.c565
-rw-r--r--cpukit/zlib/examples/README.examples49
-rw-r--r--cpukit/zlib/examples/fitblk.c233
-rw-r--r--cpukit/zlib/examples/gzappend.c500
-rw-r--r--cpukit/zlib/examples/gzjoin.c448
-rw-r--r--cpukit/zlib/examples/gzlog.c1058
-rw-r--r--cpukit/zlib/examples/gzlog.h89
-rw-r--r--cpukit/zlib/examples/zlib_how.html545
-rw-r--r--cpukit/zlib/examples/zpipe.c205
-rw-r--r--cpukit/zlib/gzio.c1026
-rw-r--r--cpukit/zlib/make_vms.com804
-rw-r--r--cpukit/zlib/minigzip.c435
-rw-r--r--cpukit/zlib/msdos/Makefile.bor115
-rw-r--r--cpukit/zlib/msdos/Makefile.dj2104
-rw-r--r--cpukit/zlib/msdos/Makefile.emx69
-rw-r--r--cpukit/zlib/msdos/Makefile.msc112
-rw-r--r--cpukit/zlib/msdos/Makefile.tc100
-rw-r--r--cpukit/zlib/old/Makefile.riscos151
-rw-r--r--cpukit/zlib/old/README3
-rw-r--r--cpukit/zlib/old/descrip.mms48
-rw-r--r--cpukit/zlib/old/os2/Makefile.os2136
-rw-r--r--cpukit/zlib/old/os2/zlib.def51
-rw-r--r--cpukit/zlib/old/visual-basic.txt160
-rw-r--r--cpukit/zlib/old/zlib.html971
-rw-r--r--cpukit/zlib/preinstall.am42
-rw-r--r--cpukit/zlib/projects/README.projects41
-rw-r--r--cpukit/zlib/projects/visualc6/README.txt73
-rw-r--r--cpukit/zlib/projects/visualc6/example.dsp278
-rw-r--r--cpukit/zlib/projects/visualc6/minigzip.dsp278
-rw-r--r--cpukit/zlib/projects/visualc6/zlib.dsp621
-rw-r--r--cpukit/zlib/projects/visualc6/zlib.dsw59
-rw-r--r--cpukit/zlib/qnx/package.qpg141
-rw-r--r--cpukit/zlib/win32/DLL_FAQ.txt397
-rw-r--r--cpukit/zlib/win32/Makefile.bor110
-rw-r--r--cpukit/zlib/win32/Makefile.emx69
-rw-r--r--cpukit/zlib/win32/Makefile.gcc164
-rw-r--r--cpukit/zlib/win32/Makefile.msc157
-rw-r--r--cpukit/zlib/win32/VisualC.txt3
-rw-r--r--cpukit/zlib/win32/zlib.def74
-rw-r--r--cpukit/zlib/win32/zlib1.rc40
-rw-r--r--cpukit/zlib/zconf.h9
-rw-r--r--cpukit/zlib/zconf.in.h332
2500 files changed, 603474 insertions, 46925 deletions
diff --git a/cpukit/.cvsignore b/cpukit/.cvsignore
new file mode 100644
index 0000000000..5c181fbb08
--- /dev/null
+++ b/cpukit/.cvsignore
@@ -0,0 +1,16 @@
+aclocal.m4
+autom4te*.cache
+config.cache
+config.guess
+config.h.in
+config.log
+config.status
+config.sub
+configure
+depcomp
+install-sh
+Makefile
+Makefile.in
+missing
+mkinstalldirs
+stamp-h.in
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
new file mode 100644
index 0000000000..eee80b12c9
--- /dev/null
+++ b/cpukit/ChangeLog
@@ -0,0 +1,13199 @@
+2011-03-16 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ PR 1729/cpukit
+ * configure.ac, sapi/include/confdefs.h, sapi/src/exinit.c,
+ score/Makefile.am, score/preinstall.am,
+ score/cpu/i386/rtems/score/cpu.h, score/cpu/sparc/cpu_asm.S,
+ score/cpu/sparc/rtems/score/cpu.h,
+ score/include/rtems/score/basedefs.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/percpu.h, score/src/percpu.c,
+ score/src/thread.c, score/src/threadcreateidle.c: Add next step in
+ SMP support. This adds an allocated array of the Per_CPU structures
+ to support multiple cpus vs a single instance of the structure which
+ is still used if SMP support is disabled. Configuration support is
+ also added to explicitly enable or disable SMP. But SMP can only be
+ enabled for the CPUs which will support it initially -- SPARC and
+ i386. With the stub BSP support, a BSP can be run as a single core
+ SMP system from an RTEMS data structure standpoint.
+ * aclocal/check-smp.m4, aclocal/enable-smp.m4,
+ score/include/rtems/bspsmp.h, score/include/rtems/score/smplock.h,
+ score/src/smp.c, score/src/smplock.c: New files.
+
+2011-03-16 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ PR 1743/cpu
+ * sapi/include/confdefs.h, score/Makefile.am, score/preinstall.am: Add
+ Simple Priority Scheduler as complement to existing Deterministic
+ Priority Scheduler. This scheduler serves both as an example and as a
+ lighter weight implementation for smaller systems.
+ * score/include/rtems/score/schedulersimple.h,
+ score/inline/rtems/score/schedulersimple.inl,
+ score/src/schedulersimple.c, score/src/schedulersimpleblock.c,
+ score/src/schedulersimpleenqueue.c,
+ score/src/schedulersimpleenqueuefirst.c,
+ score/src/schedulersimpleextract.c,
+ score/src/schedulersimplereadyqueueenqueue.c,
+ score/src/schedulersimplereadyqueueenqueuefirst.c,
+ score/src/schedulersimpleschedule.c,
+ score/src/schedulersimpleunblock.c, score/src/schedulersimpleyield.c:
+ New files.
+
+2011-03-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadyieldprocessor.c: Removed. File is no longer
+ even compiled. It was an oversight to leave it.
+
+2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/taskresume.c, score/Makefile.am,
+ score/include/rtems/score/thread.h: Convert _Thread_Resume and
+ _Thread_Suspend into macros.
+ * score/src/threadresume.c, score/src/threadsuspend.c: Removed.
+
+2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/cpuuse/cpuusagereport.c: Make compile again.
+
+2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_setenv.c: Revert after discussion. Mark as
+ intentional in Coverity.
+
+2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/dosfs/msdos_format.c: Address Coverity issue 183 which was
+ where an expression evaluated to a constant and issue 185 which was a
+ potential (although unlikely in expected usage) time-of-check,
+ time-of-use race condition.
+
+2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_setenv.c: Address Coverity issue 134 which
+ recommends using strnXXX methods.
+
+2011-03-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/cpuuse/cpuusagereport.c: Avoid assumptions on execution
+ context.
+
+2011-03-15 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-rtems-file.c,
+ libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-rtems.h:
+ The fix to the removal of file_info from iop was broken. The
+ node_access field must be the inode number in the RFS because the
+ file system ops provides no way to tell is a stat call is the
+ result of stat, fstat, or lstat. The solution is to move the file
+ handle to node_access_2 which is also shared with doff but these
+ do not overlap.
+
+2011-03-15 Chris Johns <chrisj@rtems.org>
+
+ PR 1757/filesystem
+ * libfs/src/rfs/rtems-rfs-block-pos.h: Fix the bug in equal
+ compare.
+
+2011-03-15 Chris Johns <chrisj@rtems.org>
+
+ PR 1763/shell
+ * libmisc/shell/hexdump-conv.c: Remove debug hacks.
+
+ PR 1757/filesystem
+ * libfs/src/rfs/rtems-rfs-block-pos.h,
+ libfs/src/rfs/rtems-rfs-block.h, libfs/src/rfs/rtems-rfs-file.c,
+ libfs/src/rfs/rtems-rfs-rtems-file.c: Set the file size in
+ iop-size when a file is open. Fix lseek to end of file then write
+ for sizes less than half the file system block size.
+ * libfs/src/rfs/rtems-rfs-rtems-dev.c,
+ libfs/src/rfs/rtems-rfs-rtems-dir.c,
+ libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-rtems.h:
+ Fix the fstat and fchmod calls due to the change in the iop struct
+ where pathinfo went away. The node_access field in pathinfo was
+ overloaded.
+
+2011-03-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/mouse/mouse_parser.c, libmisc/mouse/serial_mouse.c: Remove
+ include of bsp.h
+
+2011-03-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/deviceerrno.c: Add RTEMS_INVALID_CLOCK,
+ RTEMS_INVALID_NODE, and RTEMS_NOT_CONFIGURED.
+
+2011-03-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1762/cpukit
+ * Makefile.am, preinstall.am, libmisc/Makefile.am, wrapup/Makefile.am:
+ Add generic serial mouse driver and mouse parser. The parser code was
+ in the pc386 BSP but was generic so cleaned up and placed here.
+ Serial mouse driver itself is new.
+ * libmisc/mouse/README, libmisc/mouse/mouse_parser.c,
+ libmisc/mouse/mouse_parser.h, libmisc/mouse/serial_mouse.c,
+ libmisc/mouse/serial_mouse.h: New files.
+
+2011-03-14 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * score/include/rtems/score/sysstate.h: Spelling.
+
+2011-03-10 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/rtems/extension.h: Documentation.
+
+2011-03-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadget.c: Remove conditional since this path can be
+ tested with and without POSIX enabled.
+
+2011-03-08 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * score/src/objectinitializeinformation.c: Reverse sense of conditional
+ and improve comment. Comment was right but brief, conditional was
+ backwards.
+
+2011-03-08 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ PR 1759/cpukit
+ * posix/src/cancel.c, posix/src/pthreaddetach.c,
+ posix/src/pthreadequal.c, posix/src/pthreadgetschedparam.c,
+ posix/src/pthreadjoin.c, posix/src/pthreadkill.c,
+ posix/src/pthreadsetschedparam.c: Some POSIX pthread services did not
+ support using Classic API Task Ids.
+
+2011-03-08 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * score/include/rtems/score/schedulerpriority.h: Enqueue first entry
+ said enqueue. Caught while running coverage.
+
+2011-03-07 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * include/rtems/irq-extension.h: Documentation.
+ * libmisc/monitor/mon-prmisc.c: Fix for multiprocessing configuration.
+ * libmisc/cpuuse/cpuusagereport.c: Fix calculation in case a thread
+ dispatch happends in the meantime. The percent values will not sum up
+ to one hundred percent.
+
+2011-03-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4, aclocal/version.m4:
+ Rename RTEMS_API into _RTEMS_API.
+
+2011-03-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Typos.
+
+2011-03-03 Chris Johns <chrisj@rtems.org>
+
+ PR 1749/filesystem
+ * libcsupport/src/mknod.c, libfs/src/rfs/rtems-rfs-inode.c:
+ Fix the incorrect handling of the file type in the mode value
+ to reject invalid types as per the standard.
+
+2011-03-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/if_ether.c,
+ libnetworking/netinet/in.c,
+ libnetworking/netinet/in_pcb.c,
+ libnetworking/netinet/in_pcb.h,
+ libnetworking/netinet/in_proto.c,
+ libnetworking/netinet/in_rmx.c,
+ libnetworking/netinet/in_var.h,
+ libnetworking/netinet/ip_divert.c,
+ libnetworking/netinet/ip_fw.c,
+ libnetworking/netinet/ip_mroute.c,
+ libnetworking/netinet/ip_output.c,
+ libnetworking/netinet/raw_ip.c,
+ libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/tcp_output.c,
+ libnetworking/netinet/tcp_subr.c,
+ libnetworking/netinet/tcp_timer.c,
+ libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/netinet/udp_usrreq.c:
+ Use <sys/queue.h> instead of <rtems/bsd/sys/queue.h.
+ * libnetworking/rtems/rtems_showicmpstat.c,
+ libnetworking/rtems/rtems_showifstat.c,
+ libnetworking/rtems/rtems_showipstat.c,
+ libnetworking/rtems/rtems_showmbuf.c,
+ libnetworking/rtems/rtems_showroute.c,
+ libnetworking/rtems/rtems_showtcpstat.c,
+ libnetworking/rtems/rtems_showudpstat.c:
+ Use <sys/queue.h> instead of <rtems/bsd/sys/queue.h.
+ * libnetworking/kern/kern_subr.c, libnetworking/kern/kern_sysctl.c,
+ libnetworking/kern/uipc_socket.c, libnetworking/kern/uipc_socket2.c:
+ Use <sys/queue.h> instead of <rtems/bsd/sys/queue.h.
+ * libnetworking/net/if.c, libnetworking/net/if.h,
+ libnetworking/net/if_media.h, libnetworking/net/if_var.h,
+ libnetworking/net/raw_cb.c, libnetworking/net/raw_cb.h,
+ libnetworking/net/raw_usrreq.c, libnetworking/net/route.c,
+ libnetworking/net/rtsock.c:
+ Use <sys/queue.h> instead of <rtems/bsd/sys/queue.h.
+ * libnetworking/sys/mount.h, libnetworking/sys/socketvar.h,
+ libnetworking/sys/sysctl.h:
+ Use <sys/queue.h> instead of <rtems/bsd/sys/queue.h.
+
+2011-03-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Rework checks for mandated headers tar.h,
+ errno.h, sched.h, sys/cdefs.h, sys/queue.h.
+
+2011-03-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove unused AM_CONDITIONAL([NEED_SYS_CDEFS_H]).
+ Remove unused AM_CONDITIONAL([NEED_SYS_QUEUE_H]).
+
+2011-03-01 Chris Johns <chrisj@rtems.org>
+
+ * score/src/heapfree.c, score/src/heapresizeblock.c: PR 1746. Move
+ protection block checks to after the block address has been
+ checked as a valid heap address. Add a special case in the heap
+ free for a NULL address.
+
+2011-02-27 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * score/include/rtems/score/schedulerpriority.h,
+ score/src/schedulerpriority.c, score/src/schedulerpriorityextract.c,
+ score/src/schedulerpriorityupdate.c: Formatting.
+
+2011-02-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/rtems/rtems_mii_ioctl_kern.c: Do not use IFM_ACTIVE
+ and IFM_AVALID in the media word.
+ * libnetworking/net/if_media.h: Hack to get libbsdport interface
+ drivers working.
+
+2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/sleep_noposix.c: Remove.
+ * libcsupport/Makefile.am: Reflect changes above.
+ * posix/src/sleep.c, posix/src/usleep.c: Remove.
+ * posix/Makefile.am: Reflect changes above.
+ * configure.ac: Error out if libc doesn't provide sleep, usleep.
+
+2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/canonical-target-name.m4:
+ Stop pretending no_cpu* was buildable.
+ Derive RTEMS_CPU from "$host_cpu".
+ Error out if "$host" doesn't match "*-*-rtems*".
+
+2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/check-networking.m4, aclocal/check-posix.m4:
+ Rebase check on "$host".
+
+2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/creat.c: Remove.
+ * libcsupport/Makefile.am: Reflect changes above.
+ * configure.ac: Error out if libc doesn't provide creat.
+
+2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/opendir.c, libcsupport/src/closedir.c,
+ libcsupport/src/readdir.c, libcsupport/src/rewinddir.c,
+ libcsupport/src/scandir.c, libcsupport/src/seekdir.c,
+ libcsupport/src/telldir.c: Remove.
+ * libcsupport/Makefile.am: Reflect changes above.
+ * configure.ac: Error out if libc doesn't provide
+ opendir, closedir, readdir, rewinddir, scandir, seekdir,
+ telldir.
+
+2011-02-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/sys/statvfs.h: Remove include <sys/cdefs.h>
+ (unused). Add C++ guards. Declare functions extern.
+
+2011-02-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/timer.h: Add missing includes.
+
+2011-02-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/ip_icmp.c, libnetworking/netinet/ip_icmp.h:
+ Misc. changes from FreeBSD.
+ * libnetworking/netinet/tcp_var.h: Include <netinet/tcp_timer.h>.
+
+2011-02-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/in_systm.h,
+ libnetworking/netinet/tcp_debug.c,
+ libnetworking/netinet/tcp_debug.h, libnetworking/netinet/tcp_seq.h,
+ libnetworking/netinet/tcp_var.h, libnetworking/netinet/tcpip.h:
+ Misc changes from FreeBSD.
+
+2011-02-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_pppvar.h: Add "extern C++" guards.
+ Add header guard.
+ * libnetworking/sys/signalvar.h: Comment out unused code.
+
+2011-02-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/mqueue.h: Relocate "extern C++" guards.
+ * posix/include/rtems/posix/key.h: Add missing includes.
+ * libnetworking/machine/in_cksum.h: Add missing includes.
+ * libcsupport/include/clockdrv.h, libcsupport/include/console.h,
+ libcsupport/include/spurious.h, libcsupport/include/rtems/error.h,
+ libcsupport/include/rtems/libcsupport.h: Add missing includes.
+
+2011-02-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/vm/vm_kern.h: Comment out unused vars.
+
+2011-02-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/mqueue.h: Relocate "extern C++" guards.
+ * sapi/include/rtems/fatal.h: Add missing includes.
+ * score/include/rtems/score/tod.h: Add missing includes.
+ * ftpd/ftpd.h: Add missing includes.
+ * libmisc/devnull/devnull.h, libmisc/stackchk/stackchk.h:
+ Fix header guard. Add missing includes.
+ * score/include/rtems/debug.h, score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/timespec.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl: Add missing includes.
+ * rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/options.inl: Add missing includes.
+ * libfs/src/dosfs/msdos_misc.c: Don't include <strings.h>.
+
+2011-02-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/inline/rtems/rtems/status.inl: Add missing include.
+
+2011-02-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/media-path.c: Remove warnings.
+
+2011-02-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h,
+ score/include/rtems/score/schedulerpriority.h: Add comments.
+
+2011-02-21 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/confdefs.h,
+ score/include/rtems/score/schedulerpriority.h: C++ compatibility.
+
+2011-02-21 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c: Workaround for some firewalls.
+
+2011-02-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h, score/Makefile.am,
+ score/include/rtems/score/scheduler.h,
+ score/include/rtems/score/schedulerpriority.h,
+ score/include/rtems/score/thread.h,
+ score/inline/rtems/score/scheduler.inl,
+ score/inline/rtems/score/schedulerpriority.inl,
+ score/src/scheduler.c, score/src/schedulerpriority.c,
+ score/src/schedulerpriorityblock.c,
+ score/src/schedulerpriorityschedule.c,
+ score/src/schedulerpriorityunblock.c,
+ score/src/schedulerpriorityyield.c, score/src/threadchangepriority.c,
+ score/src/threadclose.c, score/src/threadinitialize.c,
+ score/src/threadsetpriority.c, score/src/threadsettransient.c:
+ Significant clean up on Scheduler Plugin Interface. Names were
+ shortened. Missing operations added. Many scheduler files had
+ unneeded includes removed. Made pointer to scheduler information in
+ Thread_Control and Scheduler_Control a void * pointer because the
+ thread and scheduler wrapper should be unaware of scheduler types AND
+ this is broken for user provided schedulers.
+ * score/src/schedulerpriorityallocate.c,
+ score/src/schedulerpriorityenqueue.c,
+ score/src/schedulerpriorityenqueuefirst.c,
+ score/src/schedulerpriorityextract.c,
+ score/src/schedulerpriorityfree.c,
+ score/src/schedulerpriorityupdate.c: New files.
+ * score/src/schedulerprioritythreadschedulerallocate.c,
+ score/src/schedulerprioritythreadschedulerfree.c,
+ score/src/schedulerprioritythreadschedulerupdate.c: Removed.
+
+2011-02-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ score/include/rtems/score/scheduler.h,
+ score/include/rtems/score/schedulerpriority.h,
+ score/inline/rtems/score/scheduler.inl,
+ score/inline/rtems/score/schedulerpriority.inl,
+ score/src/scheduler.c, score/src/schedulerpriority.c,
+ score/src/schedulerpriorityblock.c,
+ score/src/schedulerpriorityschedule.c,
+ score/src/schedulerprioritythreadschedulerallocate.c,
+ score/src/schedulerprioritythreadschedulerfree.c,
+ score/src/schedulerprioritythreadschedulerupdate.c,
+ score/src/schedulerpriorityunblock.c,
+ score/src/schedulerpriorityyield.c, score/src/threadchangepriority.c,
+ score/src/threadclearstate.c, score/src/threadclose.c,
+ score/src/threadinitialize.c, score/src/threadready.c,
+ score/src/threadresume.c, score/src/threadsetpriority.c,
+ score/src/threadsetstate.c, score/src/threadsuspend.c: Simplify the
+ pluggable scheduler interface. Its configuration made a table
+ of available schedulers and set a pointer to one of the.
+ This was heavy handed since you can only use one scheduler
+ in an application. This configuration mechanism resulted in a
+ scheduler pointer being passed around when you could put all
+ scheduler configuration in an initialized structure.
+
+2011-02-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/fb/mw_uid.c, libmisc/fb/mw_uid.h: Clean
+ up. Add Doxygen style comments. Add method to print uid structure.
+ * libmisc/fb/mw_print.c: New file.
+
+2011-02-17 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/bdpart.h (rtems_bdpart_format):
+ Preserve previous API.
+ * libblock/src/bdpart-create.c, libblock/src/bdpart-read.c,
+ libblock/src/bdpart-write.c: Reflect changes above.
+ * libmisc/shell/fdisk.c: Reflect changes above.
+
+2011-02-17 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/rtems_heap_extend.c: New file.
+ * libcsupport/Makefile.am: Reflect change from above.
+ * libcsupport/include/rtems/malloc.h: Declare rtems_heap_extend().
+ * score/include/rtems/score/heap.h: Documentation.
+
+2011-02-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/wkspace.c: Removed NULL pointer check from
+ _Workspace_Free().
+
+2011-02-15 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * libmisc/capture/capture.c, posix/src/keyfreememory.c,
+ posix/src/pthread.c, score/include/rtems/score/wkspace.h,
+ score/src/objectextendinformation.c,
+ score/src/objectnamespaceremove.c, score/src/objectsetname.c,
+ score/src/threadclose.c, score/src/threadinitialize.c,
+ score/src/wkspace.c: Many places were checking for a NULL pointer
+ before calling _Workspace_Free. By moving the check into
+ _Workspace_Free, we eliminate a number of conditional paths and make
+ it harder to return a NULL pointer.
+
+2011-02-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coremutex.h: Returns tests to running
+ state.
+
+2011-02-14 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * rtems/src/semtranslatereturncode.c, score/src/coremutexsurrender.c:
+ Now all conditionals have the correct sense and all tests pass.
+
+2011-02-14 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * score/include/rtems/score/coremutex.h,
+ score/inline/rtems/score/coremutex.inl, score/src/apimutexallocate.c:
+ Fix direction of conditional and eliminate use of nesting is error
+ when POSIX is disabled.
+
+2011-02-11 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coremutex.h,
+ score/src/coremutexsurrender.c,
+ score/src/objectinitializeinformation.c: Disable code not reachable
+ when POSIX is not enabled.
+
+2011-02-11 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * score/include/rtems/score/context.h: Spacing.
+
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/basedefs.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2011-02-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/bdpart.h (rtems_bdpart_format):
+ Eliminate unnamed union (Non c99-compliant).
+ * libblock/src/bdpart-create.c, libblock/src/bdpart-read.c,
+ libblock/src/bdpart-write.c: Reflect changes above.
+ * libmisc/shell/fdisk.c: Reflect changes above.
+
+2011-02-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * sapi/include/confdefs.h: Fix typo.
+
+2011-02-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/btimer.h: New.
+ * Makefile.am: Add rtems/btimer.h
+ * libcsupport/include/timerdrv.h: Reflect having split out functions
+ to rtems/btimer.h.
+
+2011-02-08 Brett Swimley <bswimley@advanced.pro>
+
+ * libfs/src/rfs/rtems-rfs-rtems.c: Fix bug where the eval path did
+ not close an inode.
+
+2011-02-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Require autoconf-2.68, automake-1.11.1.
+
+2011-02-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/hexdump-display.c:
+ Eliminate bcopy, bzero, bcmp, index (Obsolete).
+ * libmisc/shell/hexdump-parse.c: Eliminate index (Obsolete).
+ * libmisc/shell/hexsyntax.c: Eliminate rindex (Obsolete).
+ * libmisc/shell/main_hexdump.c: Eliminate rindex (Obsolete).
+ * libmisc/shell/main_rm.c: Eliminate rindex (Obsolete).
+
+2011-02-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1733/cpukit
+ * score/src/isr.c: If target architecture does nto require stack
+ initialization, then do not perform adjustment.
+
+2011-02-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/printk.c: Fix typo.
+
+2011-02-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/stringto/stringtounsignedchar.c,
+ libmisc/stringto/stringtounsignedint.c: Reformat range check.
+ * libmisc/Makefile.am: Add stringto/stringtolongdouble.c.
+ * libmisc/stringto/stringtolongdouble.c: New.
+ * libmisc/stringto/stringto.h: Rename header-guard.
+ Add rtems_string_to_long_double.
+ * libmisc/stringto/stringtoint.c: Reformat range check.
+ Add check for result==0.
+ * libmisc/stringto/stringtofloat.c: Reformat range check.
+ Add check for result = -HUGE_VALF.
+ * libmisc/stringto/stringtodouble.c: Reformat range check.
+ Add check for result = -HUGE_VAL.
+ * libmisc/stringto/stringtolonglong.c: Reformat range check.
+ c99 portability improvements. Add check for result==0.
+ * libmisc/stringto/stringtounsignedlonglong.c: Reformat range check.
+ c99 portability improvements.
+ * libmisc/stringto/stringtounsignedlong.c: Reformat range check.
+ * libmisc/stringto/stringtolong.c: Reformat range check.
+ Add check for result==0.
+
+2011-02-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/Makefile.am: Remove stringto/stringto_template.h.
+ * libmisc/stringto/stringto_template.h: Remove.
+
+ * libmisc/stringto/stringtodouble.c,
+ libmisc/stringto/stringtofloat.c: Rework.
+
+ * libmisc/stringto/stringtolong.c,
+ libmisc/stringto/stringtolonglong.c,
+ libmisc/stringto/stringtounsignedlong.c,
+ libmisc/stringto/stringtounsignedlonglong.c:
+ Rework.
+
+2011-01-31 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/stringto/stringtoint.c,
+ libmisc/stringto/stringtounsignedint.c,
+ libmisc/stringto/stringtounsignedchar.c: Rework.
+
+ * libmisc/stringto/stringtopointer.c: Rework.
+
+2011-01-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * include/rtems/bspIo.h, include/rtems/concat.h, include/rtems/irq.h,
+ score/cpu/i386/rtems/score/idtr.h,
+ score/cpu/powerpc/rtems/powerpc/registers.h,
+ score/src/objectidtoname.c, score/src/schedulerpriorityblock.c,
+ score/src/schedulerpriorityschedule.c,
+ score/src/schedulerpriorityunblock.c,
+ score/src/schedulerpriorityyield.c, score/src/thread.c,
+ score/src/threadchangepriority.c, score/src/threadclearstate.c,
+ score/src/threadclose.c, score/src/threadcreateidle.c,
+ score/src/threaddelayended.c, score/src/threaddispatch.c,
+ score/src/threadget.c, score/src/threadhandler.c,
+ score/src/threadinitialize.c, score/src/threadloadenv.c,
+ score/src/threadready.c, score/src/threadreset.c,
+ score/src/threadrestart.c, score/src/threadresume.c,
+ score/src/threadsetpriority.c, score/src/threadsetstate.c,
+ score/src/threadsettransient.c, score/src/threadstackallocate.c,
+ score/src/threadstackfree.c, score/src/threadstart.c,
+ score/src/threadstartmultitasking.c, score/src/threadsuspend.c,
+ score/src/threadtickletimeslice.c, score/src/threadyieldprocessor.c:
+ Fix typo where license said found in found in.
+
+2011-01-21 Eric Norum <wenorum@lbl.gov>
+
+ * libmisc/capture/capture.c: Avoid using TCB of task just deleted.
+
+2011-01-21 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/blkdev-ops.c: New file.
+ * libblock/Makefile.am: Reflect change from above.
+ * libblock/include/rtems/blkdev.h: Declare rtems_blkdev_generic_ops.
+
+2011-01-20 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/show_bdbuf.c, score/src/objectmp.c,
+ score/src/threadmp.c: Avoid chain API violations.
+
+2011-01-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_dd.c: Make symbol unique to avoid conflict with
+ same name in <sys/stat.h>.
+
+2011-01-17 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/src/aio_cancel.c: Fixed ending of if braces.
+
+2011-01-17 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/src/aio_misc.c: Add debug information. Fixed idle_threads/
+ active_threads issues. Fixed infinite loop in rtems_aio_handle().
+
+2011-01-08 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/src/aio_misc.c: Fix rtems_aio_remove_req did not iterate
+ over chain.
+ * posix/src/aio_cancel.c: Add debug information. Add check for
+ bad file descriptor. Add else branch for cancel request on empty
+ IQ chain.
+
+2011-01-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/error.c: Scheduler Simulator compilation always
+ defines __RTEMS_VIOLATE_KERNEL_VISIBILITY__. So avoid redefinition
+ warning.
+
+2011-01-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_readlink.c: readlink
+ filesystem entry should return ssize_t.
+
+2011-01-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/aio_cancel.c: Use perfd field not next_fd.
+
+2011-01-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/nfsclient/src/nfs.c: readlink filesystem entry should
+ return ssize_t.
+
+2010-12-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/dosfs/msdos_misc.c: Create short file names acceptable for
+ Windows.
+ * libfs/src/dosfs/msdos_conv.c: Fixed convertion of half seconds to
+ seconds.
+
+2010-12-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_misc.c,
+ libfs/src/dosfs/msdos_create.c: Create valid create and modfied date
+ and time.
+
+2010-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+ Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ Add RTEMS Scheduler Simulator.
+ * sapi/include/confdefs.h: This adds some simple conditional
+ logic to disable portions of the configuration that are NOT supported
+ when configuring an RTEMS instance for use with a Scheduler Simulator
+ instance.
+
+2010-12-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/cpuuse/cpuusagereport.c: We have to take the time since the
+ last context switch before the uptime.
+
+2010-12-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/watchdognanoseconds.c: New file.
+ * score/Makefile.am: Reflect change above.
+ * score/include/rtems/score/watchdog.h, score/src/coretodget.c,
+ score/src/coretodgetuptime.c: Do not allow NULL as nanoseconds since
+ last tick handler pointer.
+
+2010-12-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/loop.h, libnetworking/net/if_loop.c,
+ libnetworking/rtems/rtems_glue.c, libmisc/dummy/dummy-networking.c:
+ Initialize loop back interface during normal initialization via
+ rtems_bsdnet_initialize_network().
+
+2010-12-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * configure.ac, posix/src/signal_2.c: sighandler_t is defined
+ conditionally in some versions of newlib and unconditionally in
+ others. Make sure we always compile.
+
+2010-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Revert
+ previous commit due to too many broken linker command files. The
+ HAVE_INITFINI_ARRAY is defined for nearly all targets by Newlib, but
+ only few linker command files respect this.
+
+2010-11-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Added
+ support for .preinit_array, .init_array and .fini_array sections.
+
+2010-11-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/confdefs.h, score/include/rtems/score/scheduler.h,
+ score/inline/rtems/score/scheduler.inl,
+ score/inline/rtems/score/schedulerpriority.inl,
+ score/src/schedulerpriority.c,
+ score/src/schedulerprioritythreadschedulerallocate.c,
+ score/src/schedulerprioritythreadschedulerfree.c,
+ score/src/schedulerprioritythreadschedulerupdate.c,
+ score/src/schedulerpriorityyield.c: Added attribute unused. Renamed
+ types and fields to follow the Score naming conventions.
+
+2010-11-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/scheduler.h,
+ score/include/rtems/score/schedulerpriority.h: Whitespace removal.
+ Moved C++ extern directive.
+
+2010-11-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1711/cpukit
+ * score/inline/rtems/score/chain.inl, score/src/chain.c: New functions
+ _Chain_Immutable_head(), _Chain_Immutable_tail(),
+ _Chain_Immutable_first(), and _Chain_Immutable_last(). The
+ Chain_Control is now a union to avoid casts. The function
+ _Chain_Is_empty() takes now a const pointer parameter.
+
+2010-11-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/dosfs/fat_file.c, libfs/src/imfs/imfs_debug.c,
+ libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_getchild.c,
+ posix/src/killinfo.c, score/inline/rtems/score/schedulerpriority.inl,
+ score/inline/rtems/score/watchdog.inl, score/src/apiext.c,
+ score/src/chain.c, score/src/coremsgflushsupp.c,
+ score/src/coremsginsert.c, score/src/objectshrinkinformation.c,
+ score/src/schedulerpriorityyield.c,
+ score/src/threadqdequeuepriority.c,
+ score/src/threadqenqueuepriority.c,
+ score/src/threadqextractpriority.c, score/src/threadqfirstfifo.c,
+ score/src/threadqfirstpriority.c, score/src/threadyieldprocessor.c,
+ score/src/userextthreadbegin.c, score/src/userextthreadcreate.c,
+ score/src/userextthreaddelete.c, score/src/userextthreadrestart.c,
+ score/src/userextthreadstart.c, score/src/userextthreadswitch.c,
+ score/src/watchdogreportchain.c: Avoid chain API violations.
+
+2010-11-24 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1647/cpukit
+ * posix/src/nanosleep.c, posix/src/sched_yield.c,
+ rtems/src/taskwakeafter.c, sapi/include/confdefs.h,
+ sapi/include/rtems/config.h, sapi/src/exinit.c, score/Makefile.am,
+ score/preinstall.am, score/include/rtems/score/prioritybitmap.h,
+ score/include/rtems/score/thread.h,
+ score/inline/rtems/score/thread.inl, score/src/thread.c,
+ score/src/threadchangepriority.c, score/src/threadclearstate.c,
+ score/src/threadclose.c, score/src/threadinitialize.c,
+ score/src/threadready.c, score/src/threadresume.c,
+ score/src/threadsetpriority.c, score/src/threadsetstate.c,
+ score/src/threadsettransient.c, score/src/threadsuspend.c,
+ score/src/threadtickletimeslice.c: Refactor scheduler out of thread
+ handler to facilitate alternate scheduler implementations.
+ * score/src/threadyieldprocessor.c: Removed.
+ * score/src/schedulerprioritythreadschedulerupdate.c,
+ score/src/schedulerprioritythreadschedulerfree.c,
+ score/src/schedulerpriorityblock.c, score/src/scheduler.c,
+ score/src/schedulerprioritythreadschedulerallocate.c,
+ score/src/schedulerpriorityunblock.c,
+ score/src/schedulerpriority.c, score/src/schedulerpriorityyield.c,
+ score/include/rtems/score/schedulerpriority.h,
+ score/include/rtems/score/scheduler.h,
+ score/inline/rtems/score/scheduler.inl,
+ score/inline/rtems/score/schedulerpriority.inl: New files.
+
+2010-11-23 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/iterateoverthreads.c, libmisc/cpuuse/cpuusagereport.c:
+ Fixed NULL pointer access in case POSIX API is disabled.
+
+2010-11-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/monitor/mon-monitor.c: Fixed broken monitor command list.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1718/cpukit
+ * sapi/include/confdefs.h: POSIX threads are allocated twice the
+ minimum stack space by default. confdefs.h only accounts for one
+ minimum -- not the 2x factor.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1717/cpukit
+ * libcsupport/src/gxx_wrappers.c: Free memory on error.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-monitor.c: Move node code into multiprocessing
+ ifdef.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectnametoid.c, score/src/objectnametoidstring.c:
+ Remove useless variable pointed out by clang.
+ * score/src/threadstackallocate.c: Remove useless variable
+ initialization pointed out by clang.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/ratemonreportstatistics.c, rtems/src/ratemonresetall.c:
+ Remove unchecked return status pointed out by clang.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/putk.c: Remove useless variable initialization
+ pointed out by clang.
+
+2010-11-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/userext.h: Documentation.
+
+2010-11-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/watchdoginsert.c: Removed superfluous cast and use
+ appropriate API function. This special case handling is obsolete
+ since 2006 with the introduction of compiler memory barriers in the
+ interrupt routines. Removed obsolete comments.
+
+2010-11-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Make compile again.
+ * sapi/src/io.c, score/src/heap.c: Address dead assignment
+ issues found by clang.
+
+2010-11-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Address casting issue highlighted by clang.
+ There was no need for an intermediate cast to a structure pointer.
+
+2010-11-01 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/include/rtems/posix/aio_misc.h, posix/src/aio_misc.c: Small
+ fixes.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/psignalunblockthread.c: Formatting.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/mutextimedlock.c: Check status local variable not
+ lock_status.
+
+2010-10-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c: Do not fall back to BOOTP server address
+ in case hostname was not specified.
+
+2010-10-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c: Fixed a special case with no username and
+ password.
+
+2010-10-19 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-rtems-file.c: Add missing unlock in
+ write. Return the error code in close.
+
+2010-10-11 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-trace.c,
+ libfs/src/rfs/rtems-rfs-trace.h: Add inode-delete.
+ * libfs/src/rfs/rtems-rfs-shell.c: Fix formatting.
+ * libfs/src/rfs/rtems-rfs-rtems-dir.c: Use ssize_t. Fix spelling.
+ * libfs/src/rfs/rtems-rfs-block.c: Fix rtems_rfs_block_get_bpos to
+ return the position correctly. A bpos does not have any special
+ processing. Do no reset the buffer handle when shrinking
+ indirectly.
+ * libfs/src/rfs/rtems-rfs-inode.c: Add trace.
+ * libfs/src/rfs/rtems-rfs-format.c: Fix comments.
+ * libfs/src/rfs/rtems-rfs-group.c: Limit the inodes to the blocks
+ in a group so the accounting works.
+ * libfs/src/rfs/rtems-rfs-dir.c: PR 1705. Fix handling the offsets
+ when deleting an entry.
+ * libfs/src/rfs/rtems-rfs-buffer.h: Remove
+ rtems_rfs_buffer_handle_reset. It is not needed and dangerous.
+
+2010-10-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: pthread_attr* functions are in <pthread.h>, not in
+ <pthreads.h>.
+ * aclocal/check-func.m4: Linearize checks.
+ Add missing $2 to AC_CHECK_DECL.
+
+2010-10-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, configure.ac: Revert accident commit adding libdbm to
+ build.
+
+2010-10-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, configure.ac, posix/Makefile.am, posix/src/pthread.c:
+ Add pthread_attr_getstack, pthread_attr_setstack,
+ pthread_attr_getguardsize, and pthread_attr_setguardsize.
+ * posix/src/pthreadattrgetguardsize.c, posix/src/pthreadattrgetstack.c,
+ posix/src/pthreadattrsetguardsize.c, posix/src/pthreadattrsetstack.c:
+ New files.
+
+2010-09-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * posix/src/psignal.c: Fixed NULL pointer access.
+
+2010-09-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/defaults/default_close.c: Return 0 instead of an error
+ status.
+
+2010-09-13 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmd/md5.h: C++ compatibility.
+
+2010-09-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add checks for pthread_attr_getguardsize,
+ pthread_attr_setguardsize, pthread_attr_setstack,
+ pthread_attr_getstack.
+
+2010-09-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1698/cpukit
+ * libcsupport/src/privateenv.c: Check return values of
+ rtems_filesystem_evaluate_path().
+
+2010-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1696/networking:
+ * libnetworking/arpa/inet.h: Partial update from FreeBSD.
+ #include <rtems/endian.h>.
+ Remove addr2ascii, ascii2addr.
+
+2010-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/addr2ascii.c,
+ libnetworking/libc/ascii2addr.c,
+ libnetworking/libc/addr2ascii.3: Remove.
+ * libnetworking/Makefile.am: Reflect changes above.
+
+2010-08-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/devctl.h, posix/src/devctl.c: Remove.
+ * posix/Makefile.am: Remove devctl.
+
+2010-08-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/killinfo.c: Ensure interested is non-NULL before using it.
+
+2010-08-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/privateenv.c: Add macro to test status when
+ RTEMS_DEBUG is enabled. Note than evaluation of root directory should
+ always work.
+
+2010-08-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/getlogin.c: Modify to use strncpy() on all paths.
+
+2010-08-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1694/shell
+ * libmisc/shell/main_setenv.c: Address memory leak identified by
+ Coverity.
+
+2010-08-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/pipe/pipe.c: Remove unreachable line flagged by Coverity as
+ dead code.
+
+2010-08-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/ctermid.c: Add comment explaining that this use of
+ strcpy() is a potential buffer overrun but because the API does not
+ provide a way to know the length of the user provided buffer, there
+ is nothing we can do about it.
+
+2010-08-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_date.c: Use snprintf() not sprintf().
+
+2010-08-27 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1693/filesystem
+ * libfs/src/imfs/memfile.c: IMFS_memfile_get_block_pointer() was
+ checking incorrect pointer and thus had dead code.
+
+2010-08-27 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1692/filesystem
+ * libcsupport/include/rtems/libio.h, libfs/src/devfs/devfs_eval.c,
+ libfs/src/imfs/imfs_eval.c: Fix implementation and use of
+ rtems_libio_is_valid_perms().
+
+2010-08-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/defaults/default_evalpath.c,
+ libfs/src/defaults/default_evaluate_link.c: Removed superfluous
+ assignment.
+
+2010-08-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/mount.c, libcsupport/src/mount-mgr.c: Avoid
+ strcpy().
+
+2010-08-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/sync.c: Add comment explaining why the return value
+ from fsync() and fdatasync() is not checked.
+
+2010-08-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-symbols.c: Fix length of buffer passed to
+ strncpy() so there is room for a NULL terminator.
+
+2010-08-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/eval.c: Make some filesystem implementation
+ correctness checks conditional on RTEMS_DEBUG.
+
+2010-08-26 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/defaults/default_evaluate_link.c: Remove assignment.
+
+ * libfs/src/rfs/rtems-rfs-file.c: Check then load the inode is not
+ present on the close.
+
+ * libfs/src/rfs/rtems-rfs-format.c: Initialise the buffer chain.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 93/NO_EFFECT
+ Coverity Id 94/NO_EFFECT
+ * libcsupport/src/readv.c, libcsupport/src/writev.c: size_t is unsigned
+ so it is useless to check for < 0.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 125
+ Coverity Id 126
+ * libi2c/libi2c.c: Use strncpy and snprintf.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/coremsginsert.c: Fix typo.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 148/STRAY_SEMICOLON
+ * score/src/coremsginsert.c: Slightly modify macro.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 169
+ * libmisc/stackchk/check.c: Readd line accidentally deleted between
+ 1.67 and 1.68.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 163
+ * libmisc/stackchk/check.c: Adjust conditional compilation.
+
+2010-08-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 164/UNINIT
+ Coverity Id 165/UNINIT
+ * posix/src/prwlockinit.c, posix/src/pspininit.c,
+ score/include/rtems/score/corespinlock.h,
+ score/inline/rtems/score/corerwlock.inl,
+ score/inline/rtems/score/corespinlock.inl: Add initialization helpers
+ for score rwlock and spinlock. Use them from POSIX.
+
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/free.c, libcsupport/src/malloc.c,
+ libcsupport/src/malloc_initialize.c: Remove heap walks in case
+ RTEMS_DEBUG is defined.
+
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1672/cpukit
+ * score/include/rtems/score/heap.h, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapextend.c,
+ score/src/heapfree.c, score/src/heapresizeblock.c,
+ score/src/heapsizeofuserarea.c: Added heap protection in case
+ RTEMS_DEBUG is defined.
+
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/imfs/imfs_fcntl.c: Removed file.
+ * libfs/Makefile.am: Reflect change from above.
+ * libfs/src/defaults/default_fcntl.c: Return 0 instead of -1 and errno.
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_fifo.c,
+ libfs/src/imfs/imfs_handlers_directory.c,
+ libfs/src/imfs/imfs_handlers_memfile.c, libfs/src/nfsclient/src/nfs.c,
+ libfs/src/rfs/rtems-rfs-rtems-dir.c,
+ libfs/src/rfs/rtems-rfs-rtems-file.c, libfs/src/rfs/rtems-rfs-rtems.c,
+ libfs/src/rfs/rtems-rfs-rtems.h: Use default file system handlers.
+
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/media.h, libblock/src/media-server.c: Use
+ chains instead of a message queue.
+
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ CID 114/SECURE_CODING
+ * libblock/src/media.c: Avoid strcpy().
+
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ CID 113/SECURE_CODING
+ * libblock/src/media-path.c: Avoid strcpy(). Style. Use assert() to
+ avoid dead code.
+
+2010-08-24 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1673/cpukit
+ * sapi/src/chainappendnotify.c, sapi/src/chaingetnotify.c,
+ sapi/src/chaingetwait.c, sapi/src/chainprependnotify.c: New files.
+ * sapi/Makefile.am: Reflect changes above.
+ * sapi/include/rtems/chain.h: Declare
+ rtems_chain_append_with_notification(),
+ rtems_chain_prepend_with_notification(),
+ rtems_chain_get_with_notification(), and rtems_chain_get_with_wait().
+ * sapi/inline/rtems/chain.inl: Define
+ rtems_chain_append_with_empty_check(),
+ rtems_chain_prepend_with_empty_check(), and
+ rtems_chain_get_with_empty_check().
+
+2010-08-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/untar/untar.c: Return if open fails.
+ Use ssize_t for read() return value.
+ * posix/src/aio_cancel.c: Spray pthread_mutex_unlocks.
+ * posix/src/aio_read.c: aio_nbytes is always >= 0.
+ * posix/src/aio_write.c: aio_nbytes is always >= 0.
+ Fix typo in comment.
+
+2010-08-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/sys/utsname.h: Remove times().
+ Remove unnecessary includes.
+ Introduce SYS_NMLN (From freebsd).
+ * libcsupport/src/utsname.c: Rework uname().
+
+2010-08-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/read.c, libcsupport/src/write.c: Remove redundant
+ check for 0 size request.
+
+2010-08-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/open.c: Spacing.
+
+2010-08-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libi2c/libi2c.c: Fix typo in va_end().
+
+2010-08-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
+ libcsupport/src/ioctl.c, libfs/src/dosfs/fat_file.c: Add va_end().
+
+2010-08-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ CID 79/DEADCODE
+ CID 78/DEADCODE
+ CID 77/DEADCODE
+ CID 76/DEADCODE
+ * posix/src/condtimedwait.c, posix/src/mutextimedlock.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/semtimedwait.c: Resolve various dead code issues identified
+ by Coverity scanner.
+
+2010-08-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ CID 99
+ CID 100
+ CID 101
+ CID 102
+ * libfs/src/dosfs/fat_file.c, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_misc.c: Resolve invalid use of const identified
+ by Coverity scanner.
+
+2010-08-23 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1673/cpukit
+ * score/src/chainappendempty.c, score/src/chaingetempty.c,
+ score/src/chainprependempty.c: New files.
+ * score/Makefile.am: Reflect changes above.
+ * score/include/rtems/score/chain.h: Declare
+ _Chain_Append_with_empty_check(), _Chain_Prepend_with_empty_check(),
+ and _Chain_Get_with_empty_check().
+ * score/inline/rtems/score/chain.inl: Define
+ _Chain_Append_with_empty_check_unprotected(),
+ _Chain_Prepend_with_empty_check_unprotected(), and
+ _Chain_Get_with_empty_check_unprotected().
+
+2010-08-23 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1671/cpukit
+ * libcsupport/include/rtems/gxx_wrappers.h: New file.
+ * libcsupport/Makefile.am, libcsupport/preinstall.am: Reflect change
+ above.
+ * libcsupport/src/gxx_wrappers.c: Include <rtems/gxx_wrappers.h>. Use
+ _Internal_error_Occurred() instead of rtems_panic().
+ * score/include/rtems/score/interr.h: Added
+ INTERNAL_ERROR_GXX_KEY_ADD_FAILED and
+ INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED.
+
+2010-08-20 <yann.sionneau@telecom-sudparis.eu>
+
+ * libmisc/fb/fb.h: Add constants for buffer modes.
+
+2010-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/aio_misc.h: Add decl for aio_request_queue.
+ * posix/src/aio_misc.c: Add aio_request_queue.
+
+2010-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/aio_misc.h: Remove rtems_aio_request_s,
+ rtems_aio_request_chain_s, rtems_aio_queue_s;
+ * posix/include/aio.h: Separate LIO-modes from LIO-opcodes (From
+ freebsd).
+
+2010-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * sapi/include/rtems/chain.h: Move extern "C".
+
+2010-08-16 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/include/aio.h: Add LIO_SYNC.
+ * posix/include/rtems/posix/aio_misc.h: Add aio_request_queue,
+ Cosmetics.
+ * posix/src/aio_cancel.c, posix/src/aio_fsync.c, posix/src/aio_misc.c:
+ Rework.
+
+2010-08-19 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1680/cpukit
+ * score/src/isr.c: Correct initialization of _CPU_Interrupt_stack_high
+ to properly do the alignment. This most likely only would have caused
+ a propblem on CPUs where the stack grows down and have strict
+ alignment.
+
+2010-08-18 Chris Johns <chrisj@rtems.org>
+
+ PR 1677/filesystem
+ * libfs/src/imfs/imfs_creat.c: Fix creating of a file. Lost in the
+ change from a switch statement.
+
+2010-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/aio_misc.h: Remove
+ rtems_aio_queue_s.size (Unused).
+ * posix/src/aio_misc.c: Remove aio_request_queue.size.
+ Cosmetics.
+
+2010-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Reflect aio-changes.
+
+2010-08-16 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/src/aio_misc.c: New.
+ * posix/src/aio_error.c, posix/src/aio_read.c,
+ * posix/src/aio_return.c, posix/src/aio_write.c:
+ New implementation.
+
+2010-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Add include/rtems/posix/aio_misc.h.
+
+2010-08-16 Alin Rus <alin.codejunkie@gmail.com>
+
+ * posix/include/aio.h: Extend struct aiocb.
+ * posix/include/rtems/posix/aio_misc.h: New.
+
+2010-08-13 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/media.c: Use unprotected chain extract.
+
+2010-08-13 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/media.h, libblock/src/media-desc.c,
+ libblock/src/media-dev-ident.c, libblock/src/media-path.c,
+ libblock/src/media-server.c, libblock/src/media.c: New files.
+ * Makefile.am, preinstall.am, libblock/Makefile.am: Reflect changes
+ above.
+
+2010-08-13 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/imfs/imfs_eval.c: Add the missing ';' for the debug
+ case.
+
+2010-08-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/confdefs.h: Include <rtems.h> to resolve all
+ dependencies.
+
+2010-08-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1658/cpukit
+ * sapi/src/exshutdown.c, score/include/rtems/score/interr.h: If the
+ system is not up, consider it a fatal error.
+
+2010-08-09 Bharath Suri <bharath.s.jois@gmail.com>
+
+ PR 1662/filesystem
+ * libcsupport/src/termios.c: osem is now released before attempt
+ to delete in rtems_termios_close.
+
+2010-08-09 Bharath Suri <bharath.s.jois@gmail.com>
+
+ PR 1660/filesystem
+ * libfs/src/pipe/fifo.c, libfs/src/pipe/pipe.h: Changed
+ int pipe_release to void pipe_release.
+ * libfs/src/imfs/imfs_fifo.c: Corresponding change to
+ IMFS_fifo_close since pipe_release does not return any error.
+ * libfs/src/imfs/imfs_initsupp.c: Changes to improve
+ IMFS_determine_bytes_per_block
+
+2010-08-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1661/testing
+ * libcsupport/Makefile.am, libcsupport/include/rtems/libcsupport.h: Add
+ public methods to get/set malloc heap pointer so the tests do not
+ have to peer behind the API.
+ * libcsupport/src/mallocgetheapptr.c,
+ libcsupport/src/mallocsetheapptr.c: New files.
+
+2010-08-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/inline/rtems/score/object.inl: Use attribute unused in
+ _Objects_Is_local_id().
+
+2010-08-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/Makefile.am, rtems/preinstall.am: Install
+ <rtems/rtems/mainpage.h> to allow documentation generation.
+
+2010-08-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/include/rtems.h, rtems/mainpage.h,
+ rtems/include/rtems/rtems/types.h: Documentation.
+
+2010-08-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1604/cpukit
+ * rtems/src/regioncreate.c: Removed superfluous parameter check.
+
+2010-08-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1615/cpukit
+ * posix/src/keyrundestructors.c: Improved POSIX compliance. Now we may
+ have an unlimited number of iterations.
+
+2010-08-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/inline/rtems/chain.inl: Added
+ rtems_chain_extract_unprotected().
+
+2010-08-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/aio.h, posix/src/aio_return.c:
+ Let aio_return return ssize_t (Mandated by POSIX).
+
+2010-08-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs.h: Fix typo.
+
+2010-08-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/getegid.c, libcsupport/src/geteuid.c,
+ libcsupport/src/getpid.c, libcsupport/src/getppid.c,
+ libcsupport/src/getuid.c, libcsupport/src/setegid.c,
+ libcsupport/src/seteuid.c, libcsupport/src/setsid.c
+ libcsupport/src/setuid.c: Remove redundant includes.
+
+2010-08-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1649/cpukit
+ * libcsupport/Makefile.am, libcsupport/src/getgid.c: Make sure all get
+ and set gid and egid routines are present and in their own files.
+ * libcsupport/src/setegid.c, libcsupport/src/setgid.c: New files.
+
+2010-08-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Apply RTEMS_CHECK_FUNC for set/get*id family of
+ functions. Extend set/get*id family of checks.
+ * aclocal/check-func.m4: New.
+
+2010-08-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add checks for [get|set][e][uid,gid] family of
+ functions.
+
+2010-08-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_readlink.c,
+ libfs/src/pipe/fifo.c: Clean up for coverage improvements and
+ formatting.
+
+2010-08-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: If this port does not allocate the
+ interrupt stack, then it must always be a thread stack. Do not
+ include code to print the interrupt stack information.
+
+2010-08-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/base_fs.c, libcsupport/src/rtems_mkdir.c: Formatting.
+
+2010-07-30 Bharath Suri <bharath.s.jois@gmail.com>
+
+ PR 1645/cpukit
+ * libcsupport/src/getuid.c: Moved setuid() routine to its own
+ file.
+ * libcsupport/src/setuid.c: New file with setuid() routine.
+ * libcsupport/src/seteuid.c: New file with seteuid() routine.
+
+2010-07-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/fstat.c, libcsupport/src/rmdir.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
+ libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_getchild.c,
+ libfs/src/imfs/memfile.c: Add IMFS_assert. Clean up and remove all
+ checks which are redundant with system call layer. Formatting.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * posix/src/psignalunblockthread.c, posix/src/pthreadkill.c,
+ rtems/src/signalsend.c, score/include/rtems/score/percpu.h,
+ score/inline/rtems/score/thread.inl, score/src/thread.c,
+ score/src/threadchangepriority.c, score/src/threadclearstate.c,
+ score/src/threaddispatch.c, score/src/threadready.c,
+ score/src/threadresume.c, score/src/threadsetstate.c,
+ score/src/threadstartmultitasking.c, score/src/threadsuspend.c,
+ score/src/threadyieldprocessor.c: Rename _Context_Switch_necessary to
+ _Thread_Dispatch_necessary to more properly reflect the intent.
+
+2010-07-30 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ * sapi/include/confdefs.h: Add configuration macros for Go
+ requirements.
+
+2010-07-29 Bharath Suri <bharath.s.jois@gmail.com>
+
+ PR 1620/cpukit
+ * libcsupport/src/privateenv.c: Significant clean up and rework to
+ improve testability.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * sapi/src/exinit.c, score/Makefile.am, score/preinstall.am,
+ score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/thread.h,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/thread.inl,
+ score/src/threadchangepriority.c, score/src/threadclearstate.c,
+ score/src/threadready.c, score/src/threadresume.c,
+ score/src/threadsetpriority.c, score/src/threadsetstate.c,
+ score/src/threadsettransient.c, score/src/threadsuspend.c:
+ Refactoring of priority handling, to isolate the bitmap
+ implementation of priorities in the supercore so that priority
+ management is a little more modular. This change is in anticipation
+ of scheduler implementations that can select how they manage tracking
+ priority levels / finding the highest priority ready task. Note that
+ most of the changes here are simple renaming, to clarify the use of
+ the bitmap-based priority management.
+ * score/include/rtems/score/prioritybitmap.h,
+ score/inline/rtems/score/prioritybitmap.inl: New files.
+
+2010-07-29 Joel Sherrill <joel.sherril@OARcorp.com>
+
+ * posix/src/psignalunblockthread.c: Clean up and simplify.
+
+2010-07-28 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ * posix/src/condinit.c, posix/src/condwaitsupp.c,
+ posix/src/psignalunblockthread.c: Clean up some signal interruption
+ code.
+
+2010-07-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/keycreate.c: Fix typo.
+
+2010-07-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs_load_tar.c, libmisc/untar/untar.c: Now supports
+ both pax and GNU tar created tar files.
+
+2010-07-27 Joel Sherrill <joel.sherril@OARcorp.com>
+
+ * posix/src/sigsuspend.c: Do not assert unless RTEMS_DEBUG is defined.
+
+2010-07-27 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ PR 1629/cpukit
+ * posix/src/sigsuspend.c: sigsuspend() was not completely following the
+ POSIX specification.
+
+2010-07-27 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ PR 1630/cpukit
+ * posix/src/psignalchecksignal.c, posix/src/sigtimedwait.c:
+ sigtimedwait() was not completely following the POSIX specification.
+
+2010-07-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/threadget.c: Conditionalize a check that can only occur
+ when POSIX is disabled.
+
+2010-07-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/taskmode.c, score/inline/rtems/score/thread.inl: Rework a
+ bit to eliminate unreachable path for task blocked while calling
+ rtems_task_mode() on itself.
+
+2010-07-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Spelling.
+
+2010-07-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/privateenv.c, libmisc/cpuuse/cpuusagereport.c,
+ posix/Makefile.am, posix/include/rtems/posix/key.h,
+ posix/src/keycreate.c, posix/src/keydelete.c,
+ score/src/iterateoverthreads.c: Since removing ITRON, the loop over
+ all APIs for tasks has a path that cannot be reached. Either modify
+ the code or mark tests for NULL as RTEMS_DEBUG.
+ * posix/src/keyfreememory.c: New file.
+
+2010-07-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs_load_tar.c: Formatting.
+
+2010-07-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Do not cover up user configuation mistakes
+ on filesystems -- cite them as errors.
+
+2010-07-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/ratemonperiod.c: Remove tabs.
+
+2010-07-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/ratemonperiod.c: Use if not switch since all cases of enum
+ are not valid and switch was generating dead code.
+
+2010-07-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/init.h: Mark rtems_shutdown_executive as a
+ noreturn method.
+
+2010-07-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/gxx_wrappers.c: Free contents of key not key itself.
+ Kye pointer will never be malloc'ed.
+
+2010-07-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/src/termios_baud2num.c,
+ libcsupport/src/termios_num2baud.c: Use RTEMS associations to
+ simplify code and make easier for coverage.
+ * libcsupport/src/termios_baudtable.c: New file.
+
+2010-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1627/testing
+ * libfs/src/devfs/devstat.c:
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/link.c: Do not overwrite errno with return status.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/basedefs.h: New file.
+ * score/Makefile.am, score/preinstall.am: Reflect change above.
+ * score/include/rtems/score/percpu.h: Include <rtems/score/cpu.h>.
+ * score/include/rtems/system.h: Moved definition of SCORE_EXTERN,
+ SAPI_EXTERN, RTEMS_EXTERN, POSIX_EXTERN, RTEMS_INLINE_ROUTINE,
+ RTEMS_COMPILER_MEMORY_BARRIER, RTEMS_COMPILER_NO_RETURN_ATTRIBUTE,
+ RTEMS_COMPILER_DEPRECATED_ATTRIBUTE, TRUE, and FALSE to
+ <rtems/score/basedefs.h>.
+ Removed include of <rtems/score/cpu.h>, <stdint.h> and <stddef.h>.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmd/md4.c: Removed definition of TRUE and FALSE.
+
+2010-07-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/privateenv.c: Fix bug.
+
+2010-07-15 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ PR 1607/cpukit
+ * score/src/coremutexsurrender.c: Clean up and split out helper
+ routines.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/imfs/imfs.h: Changed IMFS_jnode_types_t to an enum.
+ Removed IMFS_NUMBER_OF_TYPES define.
+ * libfs/src/imfs/imfs_debug.c: Removed IMFS_types.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio_.h: Removed rtems_filesystem_null_handlers.
+ * libcsupport/src/fs_null_handlers.c: Removed file.
+ * libcsupport/Makefile.am: Reflect change above.
+ * libfs/src/nfsclient/src/nfs.c, libfs/src/imfs/imfs_creat.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/imfs/miniimfs_init.c: Use
+ rtems_filesystem_handlers_default instead of
+ rtems_filesystem_null_handlers.
+ * libnetworking/lib/ftpfs.c, libnetworking/lib/tftpDriver.c:
+ Initialize handler and operations table with proper defaults.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio.h: Removed file_info and handlers
+ fields in rtems_libio_t.
+ * libcsupport/src/close.c, libcsupport/src/fcntl.c,
+ libcsupport/src/fdatasync.c, libcsupport/src/fstat.c,
+ libcsupport/src/fsync.c, libcsupport/src/ftruncate.c,
+ libcsupport/src/getdents.c, libcsupport/src/ioctl.c,
+ libcsupport/src/libio_sockets.c, libcsupport/src/lseek.c,
+ libcsupport/src/open.c, libcsupport/src/read.c,
+ libcsupport/src/readv.c, libcsupport/src/write.c,
+ libcsupport/src/writev.c, libfs/src/devfs/devclose.c,
+ libfs/src/devfs/devioctl.c, libfs/src/devfs/devopen.c,
+ libfs/src/devfs/devread.c, libfs/src/devfs/devwrite.c
+ libfs/src/dosfs/msdos_dir.c libfs/src/dosfs/msdos_file.c
+ libfs/src/imfs/deviceio.c libfs/src/imfs/imfs_directory.c
+ libfs/src/imfs/imfs_fifo.c libfs/src/imfs/memfile.c
+ libfs/src/nfsclient/src/nfs.c libfs/src/rfs/rtems-rfs-rtems-file.c
+ libfs/src/rfs/rtems-rfs-rtems.h libnetworking/lib/ftpfs.c: Reflect
+ changes above.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_node_type.c: Fixed
+ devFS_node_type() prototype.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/seterr.h: Include <errno.h>.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio.h: Changed
+ rtems_filesystem_node_types_t to an enum. Declare
+ rtems_filesystem_handlers_default,
+ rtems_filesystem_operations_default,
+ rtems_filesystem_default_evalpath(),
+ rtems_filesystem_default_evalformake, and
+ rtems_filesystem_default_node_type().
+ * libfs/src/dosfs/msdos.h: Fixed msdos_node_type() prototype.
+ * libfs/src/defaults/default_evalformake.c,
+ libfs/src/defaults/default_handlers.c,
+ libfs/src/defaults/default_node_type.c,
+ libfs/src/defaults/default_ops.c: New files.
+ * libfs/Makefile.am: Reflect changes above.
+
+2010-07-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/rtems/rtems_syscall.c: Fix warning.
+
+2010-07-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/Makefile.am: Remove reference to imfs_free.c,
+ wrapup/Makefile.am: Split devfs into its own library.
+ * libfs/src/imfs/fifoimfs_init.c, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_init.c, libfs/src/rfs/rtems-rfs-rtems.c:
+ Use default freenode implementation.
+ * libfs/src/imfs/imfs_free.c: Removed.
+
+2010-07-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1612/networking
+ * ChangeLog, libcsupport/src/libio_sockets.c: Sockets need to have
+ handlers in place. Null is no longer allowed.
+
+2010-07-13 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ PR 1614/filesystem
+ * libfs/src/imfs/fifoimfs_init.c, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_load_tar.c: Fix rtems_tarfs_load to work with
+ pipe filesystem.
+
+2010-07-12 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ PR 1612/networking
+ * libnetworking/rtems/rtems_syscall.c: Replaced null socket handlers
+ with default handlers. Null handlers are no longer allowed.
+
+2010-07-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am: Do not build libio_sockets.c if networking
+ is not enabled.
+
+2010-07-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am: Remove these files as they are uused.
+ * libcsupport/src/__brk.c, libcsupport/src/__sbrk.c: Removed.
+
+2010-07-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/__times.c: Formatting.
+
+2010-07-09 Bharath Suri <bharath.s.jois@gmail.com>
+
+ * libfs/src/pipe/pipe.c: Check for err before setting the errno
+ and returning -1 to the caller.
+
+2010-07-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc_initialize.c: Clean up sbrk path now that a
+ test is available.
+
+2010-07-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/open.c: Formatting and improve comment.
+
+2010-07-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1606/cpukit
+ * score/include/rtems/score/interr.h: Remove
+ INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS since it is not generated.
+
+2010-07-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/imfs/ioman.c: Remove unneeded operation check.
+
+2010-07-06 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/isrthreaddispatch.c: Removed file.
+ * score/Makefile.am: Reflect change above.
+ * score/include/rtems/score/isr.h: Removed _ISR_Thread_dispatch()
+ declaration.
+
+2010-07-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/getrusage.c: Formatting.
+
+2010-07-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/getlogin.c: Formatting. Add EFAULT.
+ * libcsupport/src/termios.c: Formatting.
+
+2010-07-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/include/rtems/ide_part_table.h, libblock/src/bdbuf.c,
+ libcsupport/src/__times.c, libcsupport/src/libio_init.c,
+ libcsupport/src/mallocfreespace.c, libcsupport/src/mount-mgr.c,
+ libcsupport/src/mount.c, libcsupport/src/rewinddir.c,
+ libcsupport/src/seekdir.c, libcsupport/src/telldir.c,
+ libcsupport/src/unmount.c, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/fat_fat_operations.c, libfs/src/dosfs/msdos_create.c,
+ libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_eval.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_format.c,
+ libfs/src/dosfs/msdos_fsunmount.c, libfs/src/dosfs/msdos_initsupp.c,
+ libfs/src/dosfs/msdos_rename.c, libmisc/cpuuse/cpuusagereport.c,
+ libmisc/shell/vis.c, libmisc/stackchk/check.c, sapi/src/posixapi.c,
+ telnetd/telnetd.c: Remove include of assert.h when it is not needed.
+
+2010-07-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/libio.h, libfs/src/defaults/default_read.c,
+ libfs/src/defaults/default_readlink.c,
+ libfs/src/rfs/rtems-rfs-rtems.c: Correct types and prototypes to
+ eliminate warnings.
+
+2010-07-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/dosfs/msdos_handlers_dir.c,
+ libfs/src/dosfs/msdos_handlers_file.c, libfs/src/imfs/imfs_fifo.c,
+ libfs/src/imfs/imfs_handlers_device.c,
+ libfs/src/imfs/imfs_handlers_directory.c,
+ libfs/src/imfs/imfs_handlers_link.c,
+ libfs/src/imfs/imfs_handlers_memfile.c,
+ libfs/src/imfs/miniimfs_init.c, libfs/src/rfs/rtems-rfs-rtems-dev.c,
+ libfs/src/rfs/rtems-rfs-rtems-dir.c,
+ libfs/src/rfs/rtems-rfs-rtems-file.c: Turn NULLs into default
+ handlers.
+
+2010-07-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/_rename_r.c, libcsupport/src/getdents.c,
+ libcsupport/src/unlink.c, libcsupport/src/utime.c,
+ libcsupport/src/writev.c: Remove remaining checks for missing
+ handlers.
+
+2010-07-01 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ PR 1597/cpukit
+ * libcsupport/Makefile.am, libcsupport/src/chown.c: Add lchown() and
+ utimes().
+ * libcsupport/src/lchown.c, libcsupport/src/utimes.c: New files.
+
+2010-07-01 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ PR 1529/cpukit
+ * utime.c: Change file access time and modified time to
+ current time if pointer to struct utimbuf is NULL.
+ * imfs_utime.c: Upon successful completion, imfs_utime() marks
+ the time of the last file status change, st_ctime, to be updated.
+
+2010-07-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/rtems_memalign.c, score/include/rtems/score/heap.h:
+ Remove stray references to malloc boundary.
+
+2010-07-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1594/filesystem
+ * libfs/src/imfs/memfile.c: Include assert.h
+
+2010-07-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/getegid.c, libcsupport/src/gxx_wrappers.c,
+ libcsupport/src/issetugid.c: Formatting and spacing.
+
+2010-07-01 Jennifer Averett <Jennifer.Averett@OARcorp.com>
+
+ * libcsupport/src/chdir.c, libcsupport/src/chmod.c,
+ libcsupport/src/chown.c, libcsupport/src/close.c,
+ libcsupport/src/eval.c, libcsupport/src/fchdir.c,
+ libcsupport/src/fchmod.c, libcsupport/src/fchown.c,
+ libcsupport/src/fcntl.c, libcsupport/src/fdatasync.c,
+ libcsupport/src/freenode.c, libcsupport/src/fstat.c,
+ libcsupport/src/fsync.c, libcsupport/src/ftruncate.c,
+ libcsupport/src/ioctl.c, libcsupport/src/link.c,
+ libcsupport/src/lseek.c, libcsupport/src/mknod.c,
+ libcsupport/src/mount.c, libcsupport/src/open.c,
+ libcsupport/src/read.c, libcsupport/src/readlink.c,
+ libcsupport/src/readv.c, libcsupport/src/rmdir.c,
+ libcsupport/src/stat.c, libcsupport/src/statvfs.c,
+ libcsupport/src/symlink.c, libcsupport/src/unlink.c,
+ libcsupport/src/unmount.c, libcsupport/src/write.c: Removed
+ filesystem checks for NULL methods checks from the main posix
+ rountines. These are now required to have at a miminum default
+ routines in the tables.
+
+2010-07-01 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio_.h: Removed
+ rtems_filesystem_mount_table_control.
+ * libcsupport/include/rtems/libio.h, libcsupport/src/mount-mgr.c,
+ libcsupport/src/mount.c libcsupport/src/statvfs.c,
+ libcsupport/src/unmount.c, libmisc/shell/main_mount.c: Documentation.
+ Removed rtems_filesystem_mounts_first() and
+ rtems_filesystem_mounts_next(). Added
+ rtems_filesystem_mount_iterate(). Changed return type of
+ rtems_filesystem_iterate(). Removed rtems_filesystem_nodes_equal().
+
+2010-07-01 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/nfsclient/src/nfs.c, libfs/src/nfsclient/src/nfs.c,
+ libfs/src/nfsclient/src/librtemsNfs.h: Renamed
+ rtems_nfsfs_initialize() in rtems_nfs_initialize().
+ * sapi/include/confdefs.h: Reflect changes above. Renamed
+ *_miniIMFS in *_MINIIMFS. Renamed *_NFSFS in *_NFS.
+
+2010-06-30 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1472/cpukit
+ * libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
+ libcsupport/src/free.c, libcsupport/src/malloc.c,
+ libcsupport/src/malloc_initialize.c, libcsupport/src/realloc.c,
+ libcsupport/src/rtems_memalign.c: Remove malloc boundary code. It has
+ not been used since before 4.6 and is bitrotted.
+ * libcsupport/src/malloc_boundary.c: Removed.
+
+2010-06-30 Jennifer.Averett <Jennifer.Averett@OARcorp.com>
+
+ * libcsupport/include/rtems/libio.h, libfs/Makefile.am: Added
+ filesystem default mknod method.
+ * libfs/src/defaults/default_mknod.c: New file.
+
+2010-06-29 Jennifer.Averett <Jennifer.Averett@OARcorp.com>
+
+ * libcsupport/include/rtems/libio.h, libfs/Makefile.am,
+ libfs/src/defaults/default_chown.c,
+ libfs/src/defaults/default_evalpath.c,
+ libfs/src/defaults/default_freenode.c,
+ libfs/src/defaults/default_fsmount.c,
+ libfs/src/defaults/default_link.c,
+ libfs/src/defaults/default_mount.c,
+ libfs/src/defaults/default_rename.c,
+ libfs/src/defaults/default_statvfs.c,
+ libfs/src/defaults/default_symlink.c,
+ libfs/src/defaults/default_unlink.c,
+ libfs/src/defaults/default_utime.c, libfs/src/devfs/devfs_init.c,
+ libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs_init.c,
+ libfs/src/nfsclient/src/nfs.c, libfs/src/rfs/rtems-rfs-rtems.c,
+ wrapup/Makefile.am: Fixed typo in default names. Added default
+ methods into filesystem tables.
+ * libfs/src/defaults/default_close.c,
+ libfs/src/defaults/default_evaluate_link.c,
+ libfs/src/defaults/default_fpathconf.c,
+ libfs/src/defaults/default_fsunmount.c,
+ libfs/src/defaults/default_open.c,
+ libfs/src/defaults/default_unmount.c: New files.
+
+2010-06-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * configure.ac, score/include/rtems/score/percpu.h: Add
+ __RTEMS_SIZEOF_VOID_P__ to cpuopts.h so percpu.h has this information
+ available during build and after installation.
+
+2010-06-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/tftpDriver.c: rtems_tftp_ops and
+ rtems_tftp_handlers are now const and static.
+ * libnetworking/rtems/tftp.h: Removed
+ rtems_bsdnet_initialize_tftp_filesystem and rtems_tftp_ops.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/defaults/default_chown.c,
+ libfs/src/defaults/default_evalpath.c,
+ libfs/src/defaults/default_fchmod.c,
+ libfs/src/defaults/default_fcntl.c,
+ libfs/src/defaults/default_fdatasync.c,
+ libfs/src/defaults/default_freenode.c,
+ libfs/src/defaults/default_fsmount.c,
+ libfs/src/defaults/default_fstat.c,
+ libfs/src/defaults/default_fsync.c,
+ libfs/src/defaults/default_ftruncate.c,
+ libfs/src/defaults/default_ioctl.c,
+ libfs/src/defaults/default_link.c,
+ libfs/src/defaults/default_lseek.c,
+ libfs/src/defaults/default_mount.c,
+ libfs/src/defaults/default_read.c,
+ libfs/src/defaults/default_readlink.c,
+ libfs/src/defaults/default_rename.c,
+ libfs/src/defaults/default_rmnod.c,
+ libfs/src/defaults/default_statvfs.c,
+ libfs/src/defaults/default_symlink.c,
+ libfs/src/defaults/default_unlink.c,
+ libfs/src/defaults/default_utime.c,
+ libfs/src/defaults/default_write.c: Add include of rtems/seterr.h
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * configure.ac, posix/src/killinfo.c,
+ posix/src/psignalclearprocesssignals.c,
+ posix/src/psignalsetprocesssignals.c,
+ posix/src/psignalunblockthread.c, posix/src/pthreadcreate.c,
+ posix/src/pthreadkill.c, posix/src/pthreadsigmask.c,
+ rtems/src/signalsend.c, rtems/src/taskmode.c, score/Makefile.am,
+ score/preinstall.am, score/include/rtems/system.h,
+ score/include/rtems/score/context.h, score/include/rtems/score/isr.h,
+ score/include/rtems/score/thread.h, score/src/isr.c,
+ score/src/isrthreaddispatch.c, score/src/thread.c,
+ score/src/threaddispatch.c, score/src/threadloadenv.c: Add a per cpu
+ data structure which contains the information required by RTEMS for
+ each CPU core. This encapsulates information such as thread
+ executing, heir, idle and dispatch needed.
+ * score/include/rtems/score/percpu.h, score/src/percpu.c: New files.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/libio_sockets.c: Use
+ rtems_set_errno_and_return_minus_one() where it was missed before.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/__brk.c, libcsupport/src/__gettod.c,
+ libcsupport/src/__times.c, libcsupport/src/fchdir.c,
+ libcsupport/src/ftrylockfile.c, libcsupport/src/getpwent.c,
+ libcsupport/src/gxx_wrappers.c, libcsupport/src/libio_sockets.c,
+ libcsupport/src/pipe.c: Use rtems_set_errno_and_return_minus_one()
+ where it was missed before.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/error.h, libcsupport/src/error.c: Clean up
+ so rtems_panic() can be a noreturn method. This eliminates some
+ unreachable and thus untestable code.
+
+2010-06-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/termios.c: Formatting.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/dumpbuf/dumpbuf.c, libmisc/dumpbuf/dumpbuf.h: Add const.
+
+2010-06-25 Jennifer Averett <Jennifer.Averett@OARcorp.com
+
+ * libcsupport/include/rtems/libio.h, libfs/Makefile.am: Added default
+ filesystem handlers.
+ * libfs/src/defaults/default_chown.c,
+ libfs/src/defaults/default_evalpath.c,
+ libfs/src/defaults/default_fchmod.c,
+ libfs/src/defaults/default_fcntl.c,
+ libfs/src/defaults/default_fdatasync.c,
+ libfs/src/defaults/default_freenode.c,
+ libfs/src/defaults/default_fsmount.c,
+ libfs/src/defaults/default_fstat.c,
+ libfs/src/defaults/default_fsync.c,
+ libfs/src/defaults/default_ftruncate.c,
+ libfs/src/defaults/default_ioctl.c,
+ libfs/src/defaults/default_link.c,
+ libfs/src/defaults/default_lseek.c,
+ libfs/src/defaults/default_mount.c,
+ libfs/src/defaults/default_read.c,
+ libfs/src/defaults/default_readlink.c,
+ libfs/src/defaults/default_rename.c,
+ libfs/src/defaults/default_rmnod.c,
+ libfs/src/defaults/default_statvfs.c,
+ libfs/src/defaults/default_symlink.c,
+ libfs/src/defaults/default_unlink.c,
+ libfs/src/defaults/default_utime.c,
+ libfs/src/defaults/default_write.c: New files.
+
+2010-06-24 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1589/cpukit
+ * score/Makefile.am, score/include/rtems/score/thread.h,
+ score/inline/rtems/score/thread.inl: Make _Thread_Evaluate_mode() an
+ inline method. It is only used in one place and relatively simple.
+ * score/src/threadevaluatemode.c: Removed.
+
+2010-06-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/imfs/memfile.c: Fix assert.
+
+2010-06-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/read.c, libcsupport/src/write.c: read(2) and write(2)
+ should return 0 when passed a count of 0 after verifying other
+ possible errors.
+
+2010-06-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/imfs/imfs_creat.c: Fix warning.
+
+2010-06-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c,
+ libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_getchild.c,
+ libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/ioman.c,
+ libfs/src/imfs/memfile.c: Evaluate all assert calls in IMFS. Either
+ made them conditional on RTEMS_DEBUG or eliminated them.
+
+2010-06-24 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1590/cpukit
+ * score/Makefile.am, score/include/rtems/score/thread.h,
+ score/src/threadtickletimeslice.c: Remove _Thread_Reset_timeslice and
+ replaces its single use with a call to the functionally equivalent
+ _Thread_Yield_processor().
+ * score/src/threadresettimeslice.c: Removed.
+
+2010-06-24 Bharath Suri <bharath.s.jois@gmail.com>
+
+ PR 1542/filesystem
+ PR 1585/filesystem
+ * libfs/src/pipe/fifo.c: pipe_control_t was not deallocated if
+ fifo_open() was attempted with (O_WRONLY|O_NONBLOCK).
+ Mutex was locked too many times on this path and we needed an unlock.
+
+2010-06-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1587/filesystem
+ Coverity Id 35
+ * libfs/src/rfs/rtems-rfs-shell.c: Address possible NULL dereference.
+
+2010-06-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/stackchk/check.c: More clean up and coverage improvements..
+
+2010-06-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/stackchk/check.c: Clean up to improve coverage.
+
+2010-06-23 Chris Johns <chrisj@rtems.org>
+
+ PR 1577/filesystem
+ * libfs/src/pipe/fifo.c: Fixed the error codes returned on open.
+
+2010-06-23 Chris Johns <chrisj@rtems.org>
+
+ * rtems/Makefile.am: Remove the stray 'c' file.
+
+2010-06-22 Jennifer Averett <Jennifer.Averett@OARcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/include/rtems/libio_.h: Moved
+ method to free a node from a define to an external method.
+ * libcsupport/src/freenode.c: New file.
+
+2010-06-22 Jennifer Averett <Jennifer.Averett@OARcorp.com>
+
+ * posix/src/nanosleep.c, posix/src/timersettime.c: Removed redundent
+ code and cleaned up error checking code.
+
+2010-06-22 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/mount.c: Fixed string assignment in mount entry
+ allocation.
+
+2010-06-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/keycreate.c, posix/src/killinfo.c: Remove more ITRON
+ references.
+
+2010-06-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1581/cpukit
+ * libcsupport/include/rtems/malloc.h, sapi/include/confdefs.h: Remove
+ extra * on function pointer declaration.
+
+2010-06-21 Peter Dufault <dufault@hda.com>
+
+ PR 1570/cpukit
+ * posix/src/semtimedwait.c: This routine is supposed to return -1/errno
+ NOT the status directly.
+
+2010-06-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1554/cpukit
+ Coverity Id 17
+ * libi2c/libi2c.c, score/src/objectextendinformation.c: Fix memory leak
+ on error.
+
+2010-06-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1559/misc
+ Coverity Id 16
+ * libmisc/monitor/mon-editor.c: Fix buffer overflow.
+
+2010-06-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Add parameters for FIFOs and pipes since
+ they are distinct to the user.
+
+2010-06-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Add CONFIGURE_MAXIMUM_FIFOS to account for
+ resources per FIFO instance.
+
+2010-06-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/mkrootfs.h: doxygen cosmetics.
+ * libnetworking/netinet/if_ether.c: Misc. 64bit fixes from FreeBSD.
+ * libfs/src/nfsclient/src/rpcio.c: Misc. 64bit fixes.
+
+2010-06-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/object.h: Remove OBJECTS_ITRON_API.
+ * rtems/src/rtemsobjectidapimaximum.c: Remove OBJECTS_ITRON_API.
+ * score/include/rtems/score/object.h: Remove OBJECTS_ITRON_API.
+ * score/include/rtems/score/thread.h: Remove ITRON.
+ * score/include/rtems/score/interr.h: Remove ITRON.
+ * rtems/mainpage.h: Remove comment referring to ITRON.
+ * rtems/src/rtemsobjectgetapiname.c: Remove ITRON.
+ * sapi/include/rtems/config.h: Remove ITRON.
+ * score/src/objectapimaximumclass.c: Remove OBJECTS_ITRON_API.
+ * score/include/rtems/system.h: Remove ITRON_EXTERN.
+ * score/src/apiext.c: Remove comment referring to ITRON.
+ * score/include/rtems/score/object.h: Remove Objects_ITRON_API.
+ * rtems/src/rtemsobjectgetapiclassname.c,
+ sapi/include/rtems/config.h, sapi/src/exinit.c:
+ Remove RTEMS_ITRON_API conditional blocks.
+ * sapi/Makefile.am: Remove src/itronapi.c.
+ * sapi/src/itronapi.c: Remove.
+ * score/src/threadsuspend.c, score/src/threadresume.c,
+ score/src/threadreset.c, score/src/threadinitialize.c,
+ score/src/apiext.c, score/include/rtems/score/thread.h,
+ score/include/rtems/score/coresem.h:
+ Remove RTEMS_ITRON_API conditional blocks.
+
+2010-06-18 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-file-block.c: Clean up uint64_t maths.
+
+2010-06-18 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-file-system.h,
+ libfs/src/rfs/rtems-rfs-file-system.c: Move questionable macros to
+ C functions.
+
+2010-06-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Remove ITRON configuration parameters.
+
+2010-06-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Remove RTEMS_COVERAGE conditionals.
+
+2010-06-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/object.h,
+ score/include/rtems/score/thread.h: Remove prototypes for ITRON
+ only methods removed by Ralf.
+
+2010-06-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * itron/Makefile.am, itron/preinstall.am
+ itron/include/itron.h, itron/include/itronsys/README
+ itron/include/itronsys/eventflags.h,
+ itron/include/itronsys/fmempool.h,
+ itron/include/itronsys/intr.h,
+ itron/include/itronsys/mbox.h,
+ itron/include/itronsys/msgbuffer.h,
+ itron/include/itronsys/network.h,
+ itron/include/itronsys/port.h,
+ itron/include/itronsys/semaphore.h,
+ itron/include/itronsys/status.h,
+ itron/include/itronsys/sysmgmt.h,
+ itron/include/itronsys/task.h,
+ itron/include/itronsys/time.h,
+ itron/include/itronsys/types.h,
+ itron/include/itronsys/vmempool.h,
+ itron/include/rtems/itron/README,
+ itron/include/rtems/itron/config.h,
+ itron/include/rtems/itron/eventflags.h,
+ itron/include/rtems/itron/fmempool.h,
+ itron/include/rtems/itron/intr.h,
+ itron/include/rtems/itron/itronapi.h,
+ itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/network.h,
+ itron/include/rtems/itron/object.h,
+ itron/include/rtems/itron/port.h,
+ itron/include/rtems/itron/semaphore.h,
+ itron/include/rtems/itron/sysmgmt.h,
+ itron/include/rtems/itron/task.h,
+ itron/include/rtems/itron/time.h,
+ itron/include/rtems/itron/vmempool.h,
+ itron/inline/rtems/itron/eventflags.inl,
+ itron/inline/rtems/itron/fmempool.inl,
+ itron/inline/rtems/itron/intr.inl,
+ itron/inline/rtems/itron/mbox.inl,
+ itron/inline/rtems/itron/msgbuffer.inl,
+ itron/inline/rtems/itron/network.inl,
+ itron/inline/rtems/itron/port.inl,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/inline/rtems/itron/sysmgmt.inl,
+ itron/inline/rtems/itron/task.inl,
+ itron/inline/rtems/itron/time.inl,
+ itron/inline/rtems/itron/vmempool.inl,
+ itron/src/TODO, itron/src/acp_por.c,
+ itron/src/act_cyc.c, itron/src/cal_por.c, itron/src/can_wup.c,
+ itron/src/chg_iXX.c, itron/src/chg_pri.c, itron/src/clr_flg.c,
+ itron/src/cre_flg.c, itron/src/cre_mbf.c, itron/src/cre_mbx.c,
+ itron/src/cre_mpf.c, itron/src/cre_mpl.c, itron/src/cre_por.c,
+ itron/src/cre_sem.c, itron/src/cre_tsk.c, itron/src/def_alm.c,
+ itron/src/def_cyc.c, itron/src/def_exc.c, itron/src/def_int.c,
+ itron/src/def_svc.c, itron/src/del_flg.c, itron/src/del_mbf.c,
+ itron/src/del_mbx.c, itron/src/del_mpf.c, itron/src/del_mpl.c,
+ itron/src/del_por.c, itron/src/del_sem.c, itron/src/del_tsk.c,
+ itron/src/dis_dsp.c, itron/src/dis_int.c, itron/src/dly_tsk.c,
+ itron/src/ena_dsp.c, itron/src/ena_int.c, itron/src/eventflags.c,
+ itron/src/exd_tsk.c, itron/src/ext_tsk.c, itron/src/fmempool.c,
+ itron/src/frsm_tsk.c, itron/src/fwd_por.c, itron/src/get_blf.c,
+ itron/src/get_blk.c, itron/src/get_tid.c, itron/src/get_tim.c,
+ itron/src/get_ver.c, itron/src/itroninittasks.c, itron/src/itronintr.c,
+ itron/src/itronsem.c, itron/src/itrontime.c, itron/src/loc_cpu.c,
+ itron/src/mbox.c, itron/src/mboxtranslatereturncode.c,
+ itron/src/msgbuffer.c, itron/src/msgbuffertranslatereturncode.c,
+ itron/src/network.c, itron/src/nget_nod.c, itron/src/nget_ver.c,
+ itron/src/nrea_dat.c, itron/src/nwri_dat.c, itron/src/pacp_por.c,
+ itron/src/pcal_por.c, itron/src/pget_blf.c, itron/src/pget_blk.c,
+ itron/src/pol_flg.c, itron/src/port.c, itron/src/prcv_mbf.c,
+ itron/src/prcv_mbx.c, itron/src/preq_sem.c, itron/src/psnd_mbf.c,
+ itron/src/rcv_mbf.c, itron/src/rcv_mbx.c, itron/src/ref_alm.c,
+ itron/src/ref_cfg.c, itron/src/ref_cyc.c, itron/src/ref_flg.c,
+ itron/src/ref_iXX.c, itron/src/ref_mbf.c, itron/src/ref_mbx.c,
+ itron/src/ref_mpf.c, itron/src/ref_mpl.c, itron/src/ref_por.c,
+ itron/src/ref_sem.c, itron/src/ref_sys.c, itron/src/ref_tsk.c,
+ itron/src/rel_blf.c, itron/src/rel_blk.c, itron/src/rel_wai.c,
+ itron/src/ret_int.c, itron/src/ret_tmr.c, itron/src/ret_wup.c,
+ itron/src/rot_rdq.c, itron/src/rpl_rdv.c, itron/src/rsm_tsk.c,
+ itron/src/set_flg.c, itron/src/set_tim.c, itron/src/sig_sem.c,
+ itron/src/slp_tsk.c, itron/src/snd_mbf.c, itron/src/snd_mbx.c,
+ itron/src/sta_tsk.c, itron/src/sus_tsk.c, itron/src/sysmgmt.c,
+ itron/src/tacp_por.c, itron/src/task.c, itron/src/tcal_por.c,
+ itron/src/ter_tsk.c, itron/src/tget_blf.c, itron/src/tget_blk.c,
+ itron/src/trcv_mbf.c, itron/src/trcv_mbx.c, itron/src/tslp_tsk.c,
+ itron/src/tsnd_mbf.c, itron/src/twai_flg.c, itron/src/twai_sem.c,
+ itron/src/unl_cpu.c, itron/src/vmempool.c, itron/src/wai_flg.c,
+ itron/src/wai_sem.c, itron/src/wup_tsk.c: Remove (Abandoned).
+
+2010-06-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * wrapup/Makefile.am, score/Makefile.am: Remove LIBITRON.
+ * score/src/objectallocatebyindex.c, score/src/objectgetbyindex.c,
+ score/src/threadrotatequeue.c: Remove.
+ * Makefile.am: Remove itron.
+ * configure.ac: Remove itron.
+ * aclocal/check-itron.m4, aclocal/enable-itron.m4: Remove.
+
+2010-06-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-file-system.h: Revert previous change.
+ Force RTEMS_RFS_VERSION_MASK to be 32bit.
+ * libfs/src/rfs/rtems-rfs-rtems-dir.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-format.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-file-system.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-rtems-file.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-buffer.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-shell.c: Various 64bit fixes.
+
+2010-06-17 Chris Johns <chrisj@rtems.org>
+
+ libfs/src/rfs/rtems-rfs-bitmaps.h,
+ libfs/src/rfs/rtems-rfs-block-pos.h,
+ libfs/src/rfs/rtems-rfs-block.h: PR 1556. Struct clean up.
+
+2010-06-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-shell.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-bitmaps-ut.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-group.c: Various 64bit fixes.
+
+2010-06-16 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1453/cpukit
+ * posix/Makefile.am: newlib uses sysconf() for _CLOCKS_PER_SEC_ so
+ enable it even when POSIX threads are disabled.
+
+2010-06-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-file.c: Various 64bit fixes.
+
+2010-06-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectallocate.c: Add conditionally compiled debug code to
+ printk a message when an object allocation error occurs. This should
+ be helpful in identifying when a ported package required more
+ resources.
+
+2010-06-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-inode.c: Various 64bit fixes.
+ * libfs/src/rfs/rtems-rfs-rtems.c: Various 64bit fixes.
+ Add PRIomode_t.
+ * libfs/src/rfs/rtems-rfs-buffer-bdbuf.c:
+ Various 64bit fixes.
+
+2010-06-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1556/cpukit
+ * libfs/src/rfs/rtems-rfs-bitmaps.h,
+ libfs/src/rfs/rtems-rfs-block-pos.h,
+ libfs/src/rfs/rtems-rfs-buffer.h,
+ libfs/src/rfs/rtems-rfs-file-system-fwd.h,
+ libfs/src/rfs/rtems-rfs-file-system.h,
+ libfs/src/rfs/rtems-rfs-file.h,
+ libfs/src/rfs/rtems-rfs-format.h,
+ libfs/src/rfs/rtems-rfs-group.h,
+ libfs/src/rfs/rtems-rfs-inode.h:
+ Rename "struct rtems_rfs_*_t" into "struct _rtems_rfs_*".
+ * libfs/src/rfs/rtems-rfs-shell.c: Remove rtems_rfs_shell_cmd_t.
+
+2010-06-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1566/filesystem
+ * libnetworking/rtems/mkrootfs.c, libnetworking/rtems/mkrootfs.h:
+ Let rtems_rootfs_append_host_rec take an in_addr_t as first arg.
+ * libnetworking/rtems/rtems_dhcp.c, libnetworking/nfs/bootp_subr.c:
+ Reflect changes above.
+
+2010-06-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-dir.c: Various 64bit compatibility fixes.
+ Add PRIdoff_t.
+ Remove stray "\"s.
+ * libfs/src/rfs/rtems-rfs-link.c: Various 64bit compatibility fixes.
+
+2010-06-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1561/cpukit
+ * configure.ac, score/cpu/Makefile.am: Merge SPARC64 port.
+
+2010-06-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/psignal.c: Formatting.
+
+2010-06-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/pthread.h: Improve comments.
+
+2010-06-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-file-system.h: Remove bogus typecast.
+ * libfs/src/rfs/rtems-rfs-block.c, libfs/src/rfs/rtems-rfs-buffer.c,
+ libnetworking/nfs/bootp_subr.c: Misc. 64bit-compatibility fixes.
+ * posix/include/rtems/posix/pthread.h: Remove stray comment.
+ Work-around doxygen comment bug.
+
+2010-06-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/ip_fw.c, libnetworking/netinet/ip_input.c:
+ Misc. 64bit-compatibility fixes.
+
+2010-06-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/print-ls.c, libmisc/shell/main_msdosfmt.c:
+ Include <inttypes.h>.
+ Misc. 64bit-compatibility fixes.
+
+2010-06-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmd/md5.h: Revert Sebastian's patch.
+
+2010-06-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/libio_.h: Fix broken doxygen
+ meta comment.
+
+2010-06-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1553/filesystem
+ Coverity Id 37
+ * libblock/src/flashdisk.c: Fix two paths which should have returned an
+ error but did not have the return statement.
+
+2010-06-14 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmd/md5.h: Define MD5_DIGEST_SIZE.
+
+2010-06-14 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1555/cpukit
+ * Makefile.am, preinstall.am: Install md4.h and md5.h headers.
+
+2010-06-14 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/confdefs.h: Do not define a filesystem if
+ CONFIGURE_APPLICATION_DISABLE_FILESYSTEM is defined.
+
+2010-06-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Doxygen.in: Use @PERL@ instead of hard-coded /usr/bin/perl.
+
+2010-06-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/mkrootfs.h,
+ posix/include/rtems/posix/pthread.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/timestamp.h: Move 'extern "C"'.
+ * posix/include/rtems/posix/threadsup.h: Add extern "C".
+ * libnetworking/netinet/in_pcb.c:
+ Eliminate "ushort".
+ * libfs/src/pipe/fifo.c, libfs/src/pipe/pipe.h:
+ Eliminate "uint".
+
+2010-06-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/tar.h, libcsupport/include/tar.h: Remove.
+ * configure.ac: Require toolchain to provide tar.h.
+ * libfs/src/imfs/imfs_load_tar.c, libmisc/untar/untar.h:
+ Use <tar.h> instead of <rtems/tar.h>.
+
+2010-06-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/libio.h: Fix typo in doxygen comment.
+
+2010-06-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/pipe/fifo.c: Remove unused variable to fix warning.
+ * libnetworking/rtems/mkrootfs.c: Add include to fix warning.
+ * rtems/src/tasksetpriority.c: Fix spacing.
+
+2010-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/inline/rtems/rtems/status.inl: Fix broken doxygen comment.
+
+2010-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Doxygen.in: Activate INCLUDE_GRAPH and
+ INCLUDED_BY_GRAPH.
+
+2010-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/timestamp.h,
+ score/include/rtems/score/timestamp64.h,
+ score/include/rtems/score/watchdog.h:
+ Misc. doxygen fixes.
+
+2010-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/devctl.h: Move mal-placed @file.
+
+2010-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/devfs/devfs.h, libfs/src/rfs/rtems-rfs-block-pos.h,
+ libfs/src/rfs/rtems-rfs-block.h, libfs/src/rfs/rtems-rfs-dir.h,
+ libfs/src/rfs/rtems-rfs-group.h, libfs/src/rfs/rtems-rfs-inode.h:
+ Fix broken doxygen commands.
+
+2010-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Doxygen.in: Update.
+ Misc. fixes.
+ * doxy-filter: New (Copy of ../tools/build/doxy-filter).
+ * Makefile.am: Add doxy-filter.
+
+2010-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove c4x.
+ * score/cpu/Makefile.am: Remove c4x.
+
+2010-06-10 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/unmount.c: Removed obsolete declarations. Fixed
+ invalid memory free.
+
+2010-06-10 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/rtems/ftpfs.h, libnetworking/lib/ftpfs.c: Removed
+ rtems_ftpfs_mount().
+
+2010-06-10 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/mount-mktgt.c: New file.
+ * libcsupport/Makefile.am: Reflect change above.
+ * libcsupport/include/rtems/libio.h: Declare
+ mount_and_make_target_path().
+
+2010-06-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/rtems/ftpfs.h, libnetworking/lib/ftpfs.c: Added
+ rtems_ftpfs_mount() again. Documentation.
+
+2010-06-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio.h, sapi/include/confdefs.h: Added
+ and use defines for file system types.
+
+2010-06-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/mount.c: Fixed NULL pointer access.
+
+2010-06-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am, configure.ac: Remove support for shttpd.
+ * aclocal/enable-shttpd.m4: Remove.
+
+2010-06-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am, configure.ac: Remove support for httpd (GoAhead).
+ * aclocal/enable-httpd.m4: Remove.
+
+2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio.h: Documentation.
+
+2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/imfs/imfs_creat.c: Reject creation of FIFOs if support is
+ disabled.
+
+2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1524/filesystem
+ * libcsupport/src/rtems_mkdir.c: New file.
+ * libcsupport/src/Makefile.am: Reflect change above.
+ * libcsupport/include/rtems/libio.h: Added rtems_mkdir().
+ * libmisc/fsmount/fsmount.h, libmisc/fsmount/fsmount.c,
+ libblock/src/bdpart-mount.c, libnetworking/rtems/mkrootfs.h,
+ libnetworking/rtems/mkrootfs.c, libfs/src/pipe/pipe.c: Use
+ rtems_mkdir(). Removed rtems_fsmount_create_mount_point() and
+ rtems_rootfs_mkdir().
+
+2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/imfs/fifoimfs_init.c: New file.
+ * libfs/Makefile.am: Reflect change above.
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
+ libfs/src/imfs/miniimfs_init.c, libfs/src/pipe/fifo.c,
+ libfs/src/pipe/pipe.c, libfs/src/pipe/pipe.h: Pipe support is now
+ link-time optional.
+ * sapi/include/confdefs.h: Reflect changes above.
+
+2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_rmnod.c: Added and use
+ IMFS_create_orphan() and IMFS_check_node_remove().
+ * libfs/src/imfs/deviceio.c, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/imfs_fifo.c: Use IMFS_create_orphan() and
+ IMFS_check_node_remove().
+ * libfs/src/imfs/imfs_handlers_memfile.c, libfs/src/imfs/memfile.c:
+ Use IMFS_rmnod() and IMFS_check_node_remove() instead of
+ memfile_rmnod() and memfile_check_rmnod().
+
+2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/devfs/devclose.c, libfs/src/devfs/devopen.c,
+ libfs/src/imfs/deviceerrno.c, libfs/src/imfs/deviceio.c,
+ libfs/src/rfs/rtems-rfs-rtems-dev.c: Changed rtems_deviceio_errno() to
+ cope with a status code of RTEMS_SUCCESSFUL. Removed dependency on
+ association framework.
+
+2010-06-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/version.m4: Bump RTEMS_API to 4.11.
+ Bump _RTEMS_VERSION to 4.10.99.0.
+
+2010-06-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/tcflow.c, libcsupport/src/tcflush.c: Add switches
+ to detect bad input.
+ * libcsupport/src/tcsetpgrp.c: Fix typo.
+
+2010-06-07 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio_.h: Declare
+ rtems_filesystem_mount_table_control.
+ * libcsupport/include/rtems/libio.h: Removed
+ rtems_filesystem_table_first(), rtems_filesystem_table_next() and
+ rtems_filesystem_table_node_t declarations. Declare
+ rtems_per_filesystem_routine, rtems_filesystem_iterate() and
+ rtems_filesystem_get_mount_handler().
+ * libcsupport/src/mount.c: Added rtems_filesystem_mounts_first() and
+ rtems_filesystem_mounts_next(). Simplify mount(). Removed
+ rtems_filesystem_mount_table_control_init. Use
+ rtems_filesystem_get_mount_handler().
+ * libcsupport/src/mount-mgr.c: Removed rtems_filesystem_mounts_first() and
+ rtems_filesystem_mounts_next(). Added rtems_filesystem_iterate() and
+ rtems_filesystem_get_mount_handler(). Use rtems_libio_lock() and
+ rtems_libio_unlock();
+ * sapi/include/confdefs.h, libmisc/shell/main_mount.c: Update for
+ mount API changes.
+
+2010-06-07 Bharath Suri <bharath.s.jois@gmail.com>
+
+ * libcsupport/include/rtems/libio_.h: Removed macros
+ rtems_filesystem_is_separator
+ rtems_filesystem_get_start_loc
+ rtems_filesystem_get_sym_start_loc
+ and added them as files under libcsupport/src/
+
+ * libcsupport/src/: Added new files
+ libcsupport/src/sup_fs_get_start_loc.c
+ libcsupport/src/sup_fs_get_sym_start_loc.c
+ libcsupport/src/sup_fs_is_separator.c
+
+ * libcsupport/Makefile.am: Changes to accommodate new
+ files under libcsupport/src/
+
+2010-06-07 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/heap.h: Declare
+ _Heap_Get_first_and_last_block(). Removed Heap_Extend_status.
+ Changed return type of _Heap_Extend() to bool.
+ * score/inline/rtems/score/heap.inl: Define
+ _Heap_Set_last_block_size().
+ * score/src/heap.c: Define and use _Heap_Get_first_and_last_block().
+ * score/src/heapgetinfo.c: Removed assert statements. Do not count
+ the last block. This ensures that all size values are an integral
+ multiple of the page size which is consistent with the other
+ statistics.
+ * score/src/heapextend.c: Implemented support for scattered heap
+ areas.
+ * score/src/heapwalk.c: Dump also last block. Changes for new first
+ and last block values.
+ * ./score/src/pheapextend.c, rtems/src/regionextend.c: Update for
+ _Heap_Extend() changes.
+
+2010-06-03 Chris Johns <chrisj@rtems.org>
+
+ * sapi/include/confdefs.h: PR 1543. Make default file system when
+ nothing is defined IMFS not miniIMFS.
+
+2010-06-01 Chris Johns <chrisj@rtems.org>
+
+ * libcsupport/include/rtems/libio.h: Make the struct name the same
+ as the typedef.
+ * sapi/include/confdefs.h: Fixes for use in C++.
+
+2010-06-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/print-ls.c: Remove (long) cast of st_ino.
+ * libcsupport/include/rtems/libio.h, libcsupport/src/mount-mgr.c:
+ Add missing 'const'.
+ * libfs/src/nfsclient/src/xdr_mbuf.c: Warning removal.
+
+2010-05-31 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/libio.h: Remove if 0 section. Formatting.
+
+2010-05-31 Chris Johns <chrisj@rtems.org>
+
+ * libcsupport/Makefile.am: Add mount-mgr.c.
+ * libcsupport/src/mount-mgr.c: New.
+ * include/rtems/fs.h: Added rtems_filesystem_location_mount.
+ * libcsupport/include/rtems/libio.h, libcsupport/src/mount.c: New
+ mount interface. It is similar to Linux.
+ * libcsupport/include/rtems/libio_.h: Remove the
+ init_fs_mount_table call.
+ * libcsupport/src/base_fs.c: Remove init_fs_mount_table_call. Use
+ the new mount call. Remove setting the root node in the global
+ pathloc. Mount does this now.
+ * libcsupport/src/privateenv.c: Remove the hack to set the root
+ mount table entry in the environment.
+ * libcsupport/src/unmount.cL Free the target string.
+ * libblock/src/bdpart-mount.c: New mount API.
+
+ * libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_init.c,
+ libfs/src/dosfs/dosfs.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c,
+ libfs/src/imfs/miniimfs_init.c,
+ libfs/src/nfsclient/src/librtemsNfs.h,
+ libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs.h,
+ libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h,
+ libnetworking/rtems/tftp.h: New mount_h API.
+
+ * libfs/src/devfs/devfs_eval.c: Local include of extern ops.
+ * libfs/src/nfsclient/src/nfs.c: New mount API. Removed the mount
+ me call and fixed the initialisation to happen when mounting.
+
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Remove mount
+ filesystem files.
+
+ * libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h: Updated to
+ the new mount table values.
+
+ * libmisc/shell/main_mount_ftp.c,
+ libmisc/shell/main_mount_msdos.c, libmisc/shell/main_mount_rfs.c,
+ libmisc/shell/main_mount_tftp.c: Removed.
+
+ * libmisc/shell/main_mount.c: Use the new mount API. Also access
+ the file system table for the file system types.
+
+ * libnetworking/lib/tftpDriver.c: Updated to the new mount
+ API. Fixed to allow mounting from any mount point. Also can now
+ have more than file system mounted.
+
+ * sapi/include/confdefs.h: Add file system configuration support.
+
+2010-05-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/rpcio.c: Warning removal.
+
+2010-05-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1531/newlib:
+ * libmisc/shell/fts.c:
+ Add local copy of ALIGN().
+
+2010-05-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.c:
+ Use uintptr_t and void* in _offsetof().
+ * libnetworking/netinet/raw_ip.c:
+ Cast nam to uintptr_t instead of int.
+ * libnetworking/libc/gethostnamadr.c:
+ Cast addr to uintptr_t instead of size_t.
+ * libfs/src/nfsclient/src/xdr_mbuf.c (xdrmbuf_setup):
+ Cast addr to uintptr_t instead of size_t.
+ * librpc/src/xdr/xdr_mem.c (xdr_memcreate):
+ Cast addr to uintptr_t instead of size_t.
+ * libfs/src/nfsclient/src/dirutils.c: Add PRIomode_t, PRIdoff_t.
+ * configure.ac: Add AC_CHECK_SIZEOF(mode_t), AC_CHECK_SIZEOF(off_t).
+
+2010-05-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-rtems.c: Use size_t for node_len.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/gethostnamadr.c:
+ Try to make crazy address arithmetic more portable.
+ * libfs/src/nfsclient/src/xdr_mbuf.c:
+ Use void* arithmetic instead of u_long arithmetic.
+ * libnetworking/netinet/raw_ip.c,
+ libnetworking/netinet/udp_usrreq.c:
+ Cast mbufs to uintptr_t instead of u_long.
+ * libnetworking/rtems/rtems_mii_ioctl.h,
+ libnetworking/rtems/rtems_mii_ioctl_kern.c:
+ Use uint32_t instead of int as ioctl cmd arg.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/ftpfs.c, libnetworking/lib/tftpDriver.c:
+ Use size_t instead of int for pathnamelen.
+ * libfs/src/rfs/rtems-rfs-rtems.c:
+ Use size_t instead of int for pathlen.
+ Use %zi to print pathlen.
+ * libcsupport/include/rtems/libio.h:
+ Use size_t instead of int for pathnamelen.
+ * libcsupport/include/rtems/libio_.h, libcsupport/src/eval.c:
+ Use size_t instead of int for pathnamelen.
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c:
+ Use size_t instead of int for pathnamelen.
+ * libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_eval.c:
+ Use size_t instead of int for pathnamelen.
+ * libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_eval.c:
+ Use size_t instead of int for pathnamelen.
+ * libfs/src/nfsclient/src/nfs.c:
+ Use uint32_t instead of u_int_t for readarg and writearg.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/nfs.c: Introduce union nfs_evalpath_arg.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/clnt_udp.c:
+ Revert to using u_long instead of rpcprog_t, rpcvers_t
+ to stay bug-ward compatible to freebsd.
+ * librpc/src/xdr/xdr_mem.c: Cosmetics from freebsd.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/rpcio.c:
+ Cast pointers to uintptr_t instead of long.
+ xids are uint32_t not u_long.
+ * libfs/src/nfsclient/src/nfs.c (NFS_MAKE_DEV_T_INO_HACK,
+ NFS_MAKE_DEV_T): Cast "id"'s to rtems_device_minor_number.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/rpcio.c, libfs/src/nfsclient/src/rpcio.h:
+ Use rpcprog_t for "program args", use rpcvers_t for "version args".
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/rtems_portmapper.c: Reflect changes to librpc.
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/clnt.h, librpc/include/rpc/rpc_msg.h,
+ librpc/src/rpc/clnt_generic.c, librpc/src/rpc/clnt_raw.c,
+ librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/clnt_udp.c,
+ librpc/src/rpc/pmap_clnt.c, librpc/src/rpc/pmap_getmaps.c
+ librpc/src/rpc/pmap_getport.c:
+ Partial merger from freebsd (portability fixes).
+
+2010-05-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/socketvar.h (struct sockbuf):
+ Use void* instead of caddr_t.
+ * libfs/src/nfsclient/src/rpcio.c:
+ Use address to rpciod in calls to rxWakeupCB.
+ * libnetworking/sys/socket.h (struct sockwakeup):
+ Use void* instead of caddr_t.
+ * librpc/include/rpc/xdr.h: Cosmetics from freebsd.
+
+2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/clnt_udp.c: Cosmetics from freebsd.
+
+2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/clnt_tcp.c: Partial merger from freebsd
+ (Fix strict-aliasing).
+
+2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/clnt_raw.c: Partial merger from freebsd
+ (Improved 16 bit compatibility; Fix strict-aliasing).
+
+2010-05-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/rpc_prot.c: Partial merger from freebsd
+ (Improved 64 bit compatibility; bug fix).
+
+2010-05-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1528/cpukit
+ * libcsupport/src/malloc_boundary.c: Cast to intptr_t* instead of
+ int32_t* for 16 bit target compliance.
+
+2010-05-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/nvdisk.h, libblock/src/nvdisk-sram.c:
+ Use pointer arithmetic instead of int32_t arithmetic for 16bit
+ compatibility.
+
+2010-05-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/fts.c: Cast to uintptr_t instead of long for better
+ 16bit target compliance.
+
+2010-05-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-bitmaps-ut.c: Use "16 bit int" arg
+ in call to srand if "32 bit int" doesn't fit into "int".
+
+2010-05-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c:
+ Cast argp to uintptr_t temporary instead of uint32_t temporary
+ (Avoid incompatible pointer casts on 16bit targets).
+
+2010-05-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * automake/compile.am: (Temporarily) Add -Werror=overflow,
+ -Werror=pointer-to-int-cast, -Werror=int-to-pointer-cast.
+
+2010-05-20 Bharath Suri <bharath.s.jois@gmail.com>
+
+ * libcsupport/src/_rename_r.c: Avoid overwriting of errno by
+ _rename_r to invalid values.
+
+2010-05-18 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/diskdevs.c, libblock/include/rtems/blkdev.h,
+ libblock/src/bdbuf.c: PR 1448/filesystem.
+
+ * libblock/include/rtems/blkdev.h, libblock/src/bdbuf.c: PR
+ 1514/filesystem.
+
+2010-05-17 Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
+
+ PR 1449/cpukit
+ * libblock/src/diskdevs.c: rtems_disk_next() will now implicitly
+ obtain the returned disk.
+ * libblock/include/rtems/diskdevs.h: Documentation.
+
+2010-05-15 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_stat.c: PR1419. Return a device for the IMFS.
+
+2010-05-14 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/flashdisk.c: Clean up on initialisation errors.
+
+2010-05-07 Arnout Vandecappelle <arnout@mind.be>
+
+ PR 1511/networking
+ * ftpd/ftpd.c: Abort RETR for directories.
+
+2010-05-03 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/confdefs.h: New define CONFIGURE_SEMAPHORES for the
+ overall count of required semaphores. New define
+ CONFIGURE_LIBBLOCK_SEMAPHORES for the count of required disk and bdbuf
+ semaphores.
+
+2010-05-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add missing "&&".
+
+2010-05-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/Makefile.am: Add libcsupport/src/flockfile.c,
+ libcsupport/src/ftrylockfile.c, libcsupport/src/funlockfile.c.
+ * libcsupport/src/flockfile.c, libcsupport/src/ftrylockfile.c,
+ libcsupport/src/funlockfile.c: New (stub functions).
+
+2010-04-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio_.h, libcsupport/src/envlock.c,
+ libcsupport/src/libio.c: Added and use rtems_libio_lock() and
+ rtems_libio_unlock(). Cleaned up includes and declarations. Do not
+ use RTEMS_NO_PRIORITY for unused ceiling priority in
+ rtems_semaphore_create().
+
+2010-04-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c: Format changes. Fixed pathname
+ allocation in rtems_ftpfs_eval_path(). Send QUIT command during
+ file close.
+
+2010-04-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/dosfs/msdos_format.c: Added missing va_end().
+
+2010-04-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/bdpart.c: Removed file.
+ * libblock/src/bdpart-create.c, libblock/src/bdpart-dump.c,
+ libblock/src/bdpart-mount.c, libblock/src/bdpart-read.c,
+ libblock/src/bdpart-register.c, libblock/src/bdpart-sort.c,
+ libblock/src/bdpart-write.c: New files.
+ * libblock/include/rtems/bdpart.h: Moved some definitions from bdpart.c.
+ * libblock/Makefile.am: Update for file changes.
+
+2010-04-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/inline/rtems/chain.inl: Added missing functions.
+
+2010-04-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * posix/src/alarm.c, posix/src/psignal.c, posix/src/ualarm.c:
+ Moved watchdog control objects to reduce dependencies.
+
+2010-04-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1507/filesystem
+ * libblock/src/bdbuf.c: Avoid NULL pointer access.
+
+ * libblock/src/diskdevs.c: Fixed bounds check in rtems_disk_next().
+
+2010-04-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/clnt_udp.c, librpc/src/xdr/xdr_mem.c:
+ Use [u]intptr_t instead of [u_]long for better 16bit compliance.
+
+2010-04-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/enable-itron.m4, aclocal/check-itron.m4: Replace
+ RTEMS_HAS_ITRON_API with enable_itron.
+ * librpc/src/rpc/pmap_rmt.c: Use uintptr_t for better 16bit
+ compliance.
+
+2010-04-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/enable-itron.m4: Cosmetics.
+ * httpd/Makefile.am: Use LIBHTTPD.
+ * shttpd/Makefile.am: Use LIBSHTTPD.
+ * configure.ac: Add RTEMS_ENABLE_SHTTPD, RTEMS_ENABLE_HTTPD.
+ Introduce AM_CONDITIONALS LIBHTTPD, LIBSHTTPD.
+ * aclocal/enable-httpd.m4, aclocal/enable-shttpd.m4: New.
+
+2010-04-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/map_v4v6.c: Use uintptr_t instead of u_long for
+ better 16bit target compliance.
+
+2010-04-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/chdir.c: Check for NULL pointer.
+
+2010-04-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/rfs/rtems-rfs-bitmaps-ut.c: Fix warning.
+
+2010-04-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/stringto/stringto_template.h: Remove warning.
+
+2010-04-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/pthread.c: Make default pthread_attr_t match the
+ conditionals in the version in newlib. This way it will always be
+ right.
+
+2010-04-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/readv.c: Check for < 0 on iov_len, not <= 0. A
+ readv() with all iov_len equal to 0 should have no effect.
+
+2010-04-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/mbuf.h: Use uintptr_t instead of u_long
+ for 16bit target compliance.
+ * libnetworking/libc/gethostbydns.c: Use uintptr_t instead of u_long
+ for 16bit target compliance.
+ * libnetworking/sys/sysctl.h: Change sysctl_oid->arg2 into int32_t
+ for 16bit target compliance.
+
+2010-04-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/fts.c (fts_pow2): Rebase fts_pow2 on
+ SIZEOF_SIZE_T * CHAR_BIT.
+
+2010-04-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/gcc-sanity.m4: Add RTEMS_CHECK_GCC_PRINTF_LD_OFF_T,
+ RTEMS_CHECK_GCC_PRINTF_LLD_OFF_T.
+
+2010-04-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/io_dir.c: Cast consts to size_t (Avoid overflows on implicit
+ const casts on 16bit targets).
+
+2010-04-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/system.h: Let RTEMS_offsetof return uintptr_t
+ instead of uint32_t (16bit target compatibility).
+
+2010-04-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-part.c, libmisc/monitor/mon-region.c:
+ Use rtems_monitor_dump_addr instead of rtems_monitor_dump_hex
+ to print addresses.
+
+2010-04-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-prmisc.c, libmisc/monitor/monitor.h:
+ Add rtems_monitor_dump_addr().
+ * libmisc/monitor/mon-symbols.c: 16bit target fixes.
+
+2010-04-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/ftpfs.c: 16bit target fixes:
+ Use ioctl_command_t as arg to rtems_ftpfs_do_ioctl.
+ Explicitly cast to uint32_t in char[] to uint32_t
+ conversion.
+
+2010-04-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Check for sched.h.
+ * configure.ac: Check for WORD_BIT, LONG_BIT.
+ * configure.ac: Check for flockfile, funlockfile, ftrylockfile.
+
+2010-04-12 Chris Johns <chrisj@rtems.org>
+
+ libfs/src/rfs/rtems-rfs-buffer-bdbuf.c,
+ libfs/src/rfs/rtems-rfs-buffer.c, libfs/src/rfs/rtems-rfs-data.h,
+ libfs/src/rfs/rtems-rfs-dir.c,
+ libfs/src/rfs/rtems-rfs-file-system.c,
+ libfs/src/rfs/rtems-rfs-format.c, libfs/src/rfs/rtems-rfs-inode.h,
+ libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-rtems.h,
+ libfs/src/rfs/rtems-rfs-shell.c: Fix for PR1502. Clean up problems
+ on 16bit targets.
+
+2010-04-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/stackchk/check.c: Remove bogus casts.
+ Use PRIxPTR to printk pointers.
+
+2010-04-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/blkdev.c: Fixed disk delete.
+ * libblock/src/diskdevs.c: Obtain/release disk during open/close.
+ This avoids unprotected usage of private disk variables.
+
+2010-04-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/object.h: Documentation.
+
+2010-04-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/wkspace.c: Remove duplicate include.
+
+2010-04-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h: Add const
+ to fix warning. Spacing.
+
+2010-04-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/system.h: Fix warnings about TRUE/FALSE not
+ defined on ARM target. This file need to be clean from .S files.
+
+2010-04-05 Thomas Znidar <t.znidar@embed-it.com>
+
+ * libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h: Add reset
+ command.
+
+2010-04-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/rtems_bspnet_ntp.c: #include <unistd.h>.
+
+2010-04-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/sched.h: Remove.
+ * posix/Makefile.am: Remove include/sched.h.
+
+2010-04-03 Joel Sherrill <joel.sherrill@oarcorp.org>
+
+ * posix/src/psxtransschedparam.c, posix/src/pthread.c,
+ posix/src/pthreadcreate.c: Reflect POSIX sched_parm changes.
+
+2010-04-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/auth.c, shttpd/config.c, shttpd/io_cgi.c,
+ shttpd/io_file.c, shttpd/io_socket.c, shttpd/shttpd.c:
+ #include <unistd.h>.
+
+2010-04-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/select.h: #include <sys/time.h>.
+
+2010-04-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/isatty_r.c, libcsupport/src/malloc_sbrk_helpers.c:
+ #include <unistd.h>.
+ * posix/src/sched_rr_get_interval.c: #include <unistd.h>.
+
+2010-03-30 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/dosfs/msdos_misc.c: Fix PR1491.
+
+2010-03-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/isrthreaddispatch.c: Add include of config.h
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/stringto/stringto_template.h: Reorder includes.
+ * libmisc/stringto/stringtodouble.c,
+ libmisc/stringto/stringtofloat.c,
+ libmisc/stringto/stringtoint.c,
+ libmisc/stringto/stringtolong.c,
+ libmisc/stringto/stringtolonglong.c,
+ libmisc/stringto/stringtopointer.c
+ libmisc/stringto/stringtounsignedchar.c
+ libmisc/stringto/stringtounsignedint.c
+ libmisc/stringto/stringtounsignedlong.c
+ libmisc/stringto/stringtounsignedlonglong.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/getnetnamadr.c,
+ librpc/src/rpc/svc.c:
+ Add HAVE_STRINGS_H for better POSIX compliance.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.c, libnetworking/net/if_ethersubr.c,
+ libnetworking/net/if_loop.c, libnetworking/net/if_ppp.c,
+ libnetworking/net/ppp_tty.c, libnetworking/net/radix.c,
+ libnetworking/net/raw_cb.c, libnetworking/net/raw_usrreq.c,
+ libnetworking/net/route.c, libnetworking/net/rtsock.c,
+ libnetworking/net/slcompress.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/if_ether.c, libnetworking/netinet/igmp.c,
+ libnetworking/netinet/in.c, libnetworking/netinet/in_cksum.c,
+ libnetworking/netinet/in_pcb.c, libnetworking/netinet/in_proto.c,
+ libnetworking/netinet/in_rmx.c, libnetworking/netinet/ip_divert.c,
+ libnetworking/netinet/ip_fw.c, libnetworking/netinet/ip_icmp.c,
+ libnetworking/netinet/ip_input.c, libnetworking/netinet/ip_mroute.c,
+ libnetworking/netinet/ip_output.c, libnetworking/netinet/raw_ip.c,
+ libnetworking/netinet/tcp_debug.c, libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/tcp_output.c, libnetworking/netinet/tcp_subr.c,
+ libnetworking/netinet/tcp_timer.c, libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/netinet/udp_usrreq.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/ftpfs.c, libnetworking/lib/getprotoby.c,
+ libnetworking/lib/rtems_bsdnet_ntp.c, libnetworking/lib/syslog.c,
+ libnetworking/lib/tftpDriver.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/getifaddrs.c,
+ * libnetworking/libc/if_indextoname.c,
+ libnetworking/libc/if_nameindex.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmd/md4.c, libmd/md5.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/Makefile.am: Add stringto/stringto_template.h to
+ libstringto_a_SOURCES.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/pipe/pipe.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/bdpart.c, libblock/src/ramdisk-config.c,
+ libblock/src/ramdisk-driver.c, libblock/src/ramdisk-init.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/xdr/xdr.c, librpc/src/xdr/xdr_array.c,
+ librpc/src/xdr/xdr_float.c, librpc/src/xdr/xdr_mem.c,
+ librpc/src/xdr/xdr_rec.c, librpc/src/xdr/xdr_reference.c,
+ librpc/src/xdr/xdr_sizeof.c, librpc/src/xdr/xdr_stdio.c
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/auth_none.c, librpc/src/rpc/auth_unix.c,
+ librpc/src/rpc/authunix_prot.c, librpc/src/rpc/bindresvport.c,
+ librpc/src/rpc/clnt_generic.c, librpc/src/rpc/clnt_perror.c,
+ librpc/src/rpc/clnt_raw.c, librpc/src/rpc/clnt_simple.c,
+ librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/clnt_udp.c,
+ librpc/src/rpc/get_myaddress.c, librpc/src/rpc/getrpcent.c,
+ librpc/src/rpc/getrpcport.c, librpc/src/rpc/netname.c,
+ librpc/src/rpc/netnamer.c, librpc/src/rpc/pmap_clnt.c,
+ librpc/src/rpc/pmap_getmaps.c, librpc/src/rpc/pmap_getport.c,
+ librpc/src/rpc/pmap_prot.c, librpc/src/rpc/pmap_prot2.c,
+ librpc/src/rpc/pmap_rmt.c, librpc/src/rpc/rpc_callmsg.c,
+ librpc/src/rpc/rpc_commondata.c, librpc/src/rpc/rpc_dtablesize.c,
+ librpc/src/rpc/rpc_prot.c, librpc/src/rpc/rpcdname.c,
+ librpc/src/rpc/rtems_portmapper.c, librpc/src/rpc/rtems_rpc.c,
+ librpc/src/rpc/rtime.c, librpc/src/rpc/svc.c,
+ librpc/src/rpc/svc_auth.c, librpc/src/rpc/svc_auth_unix.c,
+ librpc/src/rpc/svc_raw.c, librpc/src/rpc/svc_run.c,
+ librpc/src/rpc/svc_simple.c, librpc/src/rpc/svc_tcp.c,
+ librpc/src/rpc/svc_udp.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libgnat/ada_intrsupp.c, telnetd/check_passwd.c, telnetd/des.c,
+ telnetd/genpw.c: Add include of config.h
+
+2010-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/termios_baud2index.c,
+ libcsupport/src/termios_baud2num.c, libcsupport/src/termios_num2baud.c
+ libcsupport/src/termios_setinitialbaud.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/bspcmdline/bspcmdline.h: Minimize includes.
+ * libmisc/bspcmdline/bspcmdline_get.c,
+ libmisc/bspcmdline/bspcmdline_getparam.c,
+ libmisc/bspcmdline/bspcmdline_getparamraw.c,
+ libmisc/bspcmdline/bspcmdline_getparamrhs.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/uuid/clear.c, libmisc/uuid/compare.c,
+ libmisc/uuid/copy.c, libmisc/uuid/isnull.c,
+ libmisc/uuid/pack.c, libmisc/uuid/parse.c,
+ libmisc/uuid/unpack.c, libmisc/uuid/unparse.c,
+ libmisc/uuid/uuid_time.c:
+ Add HAVE_CONFIG_H guards around #include "config.h".
+
+2010-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-symbols.c:
+ Add HAVE_STRINGS_H for better POSIX compliance.
+
+2010-03-27 Chris Johns <chrisj@rtems.org>
+
+ libfs/src/nfsclient/src/cexphelp.c,
+ libfs/src/nfsclient/src/dirutils.c,
+ libfs/src/nfsclient/src/nfs.modini.c,
+ libfs/src/nfsclient/src/nfsTest.c,
+ libfs/src/nfsclient/src/rpcio.c,
+ libfs/src/nfsclient/src/rpcio.modini.c,
+ libfs/src/nfsclient/src/sock_mbuf.c,
+ libfs/src/nfsclient/src/xdr_mbuf.c,
+ libfs/src/rfs/rtems-rfs-bitmaps-ut.c,
+ libfs/src/rfs/rtems-rfs-bitmaps.c,
+ libfs/src/rfs/rtems-rfs-block.c,
+ libfs/src/rfs/rtems-rfs-buffer-bdbuf.c,
+ libfs/src/rfs/rtems-rfs-buffer-devio.c,
+ libfs/src/rfs/rtems-rfs-buffer.c,
+ libfs/src/rfs/rtems-rfs-dir-hash.c, libfs/src/rfs/rtems-rfs-dir.c,
+ libfs/src/rfs/rtems-rfs-file-system.c,
+ libfs/src/rfs/rtems-rfs-file.c, libfs/src/rfs/rtems-rfs-format.c,
+ libfs/src/rfs/rtems-rfs-group.c, libfs/src/rfs/rtems-rfs-inode.c,
+ libfs/src/rfs/rtems-rfs-link.c, libfs/src/rfs/rtems-rfs-mutex.c,
+ libfs/src/rfs/rtems-rfs-rtems-dev.c,
+ libfs/src/rfs/rtems-rfs-rtems-dir.c,
+ libfs/src/rfs/rtems-rfs-rtems-file.c,
+ libfs/src/rfs/rtems-rfs-rtems-utils.c,
+ libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-shell.c,
+ libfs/src/rfs/rtems-rfs-trace.c: Add HAVE_CONFIG_H support to let
+ files receive configure defines.
+
+2010-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/gethostbydns.c, libnetworking/libc/gethostbyht.c,
+ libnetworking/libc/gethostnamadr.c, libnetworking/libc/getnetbyht.c,
+ libnetworking/libc/linkaddr.c, libnetworking/libc/ns_print.c,
+ libnetworking/libc/res_debug.c, libnetworking/libc/res_query.c,
+ libnetworking/libc/res_send.c, libnetworking/libc/res_update.c:
+ Add HAVE_STRINGS_H for better POSIX compliance.
+
+2010-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-command.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/hexdump-display.c, libmisc/shell/hexdump-parse.c,
+ libmisc/shell/hexsyntax.c, libmisc/shell/main_hexdump.c,
+ libmisc/shell/main_rm.c:
+ Add HAVE_STRINGS_H for better POSIX compliance.
+
+2010-03-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/auth.c, shttpd/io_emb.c, shttpd/mime_type.c,
+ shttpd/shttpd.c: Add HAVE_STRINGS_H for better POSIX compliance.
+
+2010-03-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/dd-args.c, libmisc/shell/dd-conv.c,
+ libmisc/shell/dd-conv_tab.c, libmisc/shell/dd-misc.c,
+ libmisc/shell/dd-position.c, libmisc/shell/fdisk.c,
+ libmisc/shell/fts.c, libmisc/shell/hexdump-conv.c,
+ libmisc/shell/hexdump-display.c, libmisc/shell/hexdump-odsyntax.c,
+ libmisc/shell/hexdump-parse.c, libmisc/shell/hexsyntax.c,
+ libmisc/shell/login_check.c, libmisc/shell/login_prompt.c,
+ libmisc/shell/main_dd.c, libmisc/shell/main_hexdump.c,
+ libmisc/shell/main_ln.c, libmisc/shell/main_mknod.c,
+ libmisc/shell/main_rtc.c, libmisc/shell/mknod-pack_dev.c:
+ Add HAVE_CONFIG_H support to let files receive configure defines.
+
+2010-03-26 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/dosfs/msdos_misc.c: Part fix to PR1491.
+
+2010-03-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/rfs/rtems-rfs-bitmaps-ut.c,
+ libfs/src/rfs/rtems-rfs-block.c, libfs/src/rfs/rtems-rfs-buffer.c,
+ libfs/src/rfs/rtems-rfs-dir.c, libfs/src/rfs/rtems-rfs-file.c,
+ libfs/src/rfs/rtems-rfs-format.c, libfs/src/rfs/rtems-rfs-group.c,
+ libfs/src/rfs/rtems-rfs-rtems-file.c,
+ libfs/src/rfs/rtems-rfs-shell.c: Fix printf format warning. Primarily
+ for size_t.
+
+2010-03-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/sleep_noposix.c: Fix warning and bug.
+
+2010-03-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell_makeargs.c: Fix bugs introduced by patch
+ attempting to add quoted arguments.
+
+2010-03-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/ide_part_table.c: Functionality of
+ rtems_ide_part_table_get() and rtems_ide_part_table_free() was needed
+ internally but those routines are deprecated from the public API. So
+ move their contents to private static routines. Using the private
+ routines in this file avoids deprecation warnings and leaves
+ functional, although deprecated, versions for potential use by
+ applications.
+
+2010-03-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ftpd/ftpd.c, httpd/asp.c, httpd/ejparse.c, httpd/emfdb.c,
+ httpd/misc.c, httpd/um.c, httpd/webs.c, httpd/websuemf.c,
+ libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_format.c,
+ libfs/src/dosfs/msdos_misc.c, libfs/src/nfsclient/src/nfs.c,
+ libmisc/capture/capture-cli.c, libmisc/monitor/mon-network.c,
+ libmisc/shell/hexdump-odsyntax.c, libmisc/shell/main_ifconfig.c,
+ libmisc/shell/shell.c, libmisc/shell/shell_makeargs.c,
+ libmisc/uuid/parse.c, libnetworking/libc/gethostbydns.c,
+ libnetworking/libc/gethostbyht.c, libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/getnetnamadr.c, libnetworking/libc/inet_addr.c,
+ libnetworking/libc/inet_network.c, libnetworking/libc/res_debug.c,
+ libnetworking/libc/res_init.c, libnetworking/libc/res_query.c,
+ libnetworking/rtems/rtems_mii_ioctl.c,
+ score/src/objectgetnameasstring.c: Readdress use of ctype methods per
+ recommendation from D.J. Delorie on the newlib mailing list. We
+ should pass an unsigned char into these methods.
+
+2010-03-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libfs/src/dosfs/msdos_misc.c: Do not overwrite errno in case
+ fat_file_write() returns with an error status.
+
+2010-03-11 Ken Peters <kptrs@yahoo.com>
+
+ PR 1456/cpukit
+ * libcsupport/src/ttyname.c: ttyname_r() when called directly (not via
+ ttyname()) does not prefix the caller provided buffer with the
+ predefined _PATH_DEV string (/dev/). Thus the directory search fails
+ and no tty name is returned to the caller.
+
+2010-03-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ftpd/ftpd.c, httpd/uemf.c, httpd/um.c, httpd/webs.c,
+ httpd/websuemf.c, libblock/src/diskdevs.c,
+ libmisc/capture/capture-cli.c, libmisc/monitor/mon-network.c,
+ libmisc/shell/hexdump-odsyntax.c, libmisc/shell/main_ifconfig.c,
+ libmisc/uuid/parse.c, libnetworking/lib/ftpfs.c,
+ libnetworking/libc/gethostbyht.c, libnetworking/libc/getnetnamadr.c,
+ libnetworking/libc/inet_network.c,
+ libnetworking/rtems/rtems_mii_ioctl.c,
+ score/src/objectgetnameasstring.c: Fix warnings for ctype methods.
+
+2010-03-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell_makeargs.c: Fix warnings.
+
+2010-03-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1458/cpukit
+ * rtems/inline/rtems/rtems/asr.inl: Do not enable signals by default.
+ Wait for a signal handler to be installed.
+
+2010-03-11 Andrei Mozzhuhin <nopscmn@gmail.com>
+
+ PR 1496/shell
+ * libmisc/shell/shell_makeargs.c: Add support for quoted arguments.
+
+2010-03-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/interr.h,
+ score/src/objectinitializeinformation.c: Add new fatal error for
+ configuring unlimited and maximum of 0.
+
+2010-03-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am: Remove duplicate file from list.
+
+2010-03-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/ramdisk-config.c: Revert accidental commit.
+
+2010-03-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/ramdisk-config.c, sapi/include/confdefs.h:
+ CONFIGURE_DISABLE_CLASSIC_NOTEPADS is typo of
+ CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS. Fix it.
+
+2010-03-04 Chris Johns <chrisj@rtems.org>
+
+ * libcsupport/include/rtems/libio.h, libcsupport/src/_rename_r.c:
+ Add a rename file op and have rename use it.
+
+ * libfs/Makefile.am, libfs/src/dosfs/msdos_rename.c,
+ libfs/src/imfs/imfs_rename.c: New files to support the rename file
+ op.
+
+ * libfs/src/imfs/imfs.h: Add rename interface.
+
+ * libfs/src/imfs/imfs_init.c: Add rename handler.
+
+ * libfs/src/imfs/miniimfs_init.c: Fix up ops struct.
+
+ * libfs/src/dosfs/msdos.h: Add msdos_rename and remove
+ msdos_file_link.
+
+ * libfs/src/dosfs/msdos_create.c: Remove the link call.
+
+ * libfs/src/dosfs/msdos_eval.c: Fix a path parsing bug.
+
+ * libfs/src/dosfs/msdos_init.c: Add rename handler and clean up
+ the struct naming.
+
+ * libfs/src/rfs/rtems-rfs-link.c, libfs/src/rfs/rtems-rfs-link.h:
+ Change the link call to allow linking of directories if told to
+ and change the unlink to handle unlink directories that are not
+ empty so rename can be supported.
+
+ * libfs/src/rfs/rtems-rfs-rtems-dir.c: Fix the link/unlink calls.
+
+ * libfs/src/rfs/rtems-rfs-rtems.c: Add a rename handler. Fix the
+ link/unlink calls.
+
+ * libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_format.c,
+ libfs/src/dosfs/msdos_misc.c, httpd/asp.c,
+ libfs/src/nfsclient/src/nfs.c: Work around a newlib warning when
+ using the is*() family of calls.
+
+2010-03-01 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-buffer.h: Add `rtems_rfs_buffer_handle_reset'.
+
+2010-02-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell_script.c: Fix typo.
+
+2010-02-26 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-block.c: Reset a buffer handle after
+ moving down an indirection level.
+
+ * libfs/src/rfs/rtems-rfs-dir.c: Move directory entry validation
+ into a macro and use the macro. Fix the range check on the ino so
+ all inodes can be used.
+
+ * libfs/src/rfs/rtems-rfs-file-system.c,
+ libfs/src/rfs/rtems-rfs-file-system.h:: Add a version number to
+ the superblock. Use RTEMS_RFS_INODE_SIZE.
+
+ * libfs/src/rfs/rtems-rfs-file.c: Fix the size offset on partial
+ block lengths. Set the size in the file handle on a truncate to
+ 0.
+
+ * libfs/src/rfs/rtems-rfs-format.c: Add a version number to
+ the superblock. Use RTEMS_RFS_INODE_SIZE. A better set of defaults
+ for small disks.
+
+ * libfs/src/rfs/rtems-rfs-inode.c: Use RTEMS_RFS_INODE_SIZE. Free
+ the allocated inode if it cannot be opened.
+
+ * libfs/src/rfs/rtems-rfs-inode.h: Add RTEMS_RFS_INODE_SIZE.
+
+ * libfs/src/rfs/rtems-rfs-rtems-file.c: Move some of the iop
+ acceses inside the fs lock.
+
+ * libfs/src/rfs/rtems-rfs-shell.c: Use RTEMS_RFS_INODE_SIZE.
+
+2010-02-24 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/main_msdosfmt.c, libmisc/shell/shellconfig.h: Fix
+ the alias as I did understand how it worked.
+
+ * libfs/src/dosfs/msdos_format.c: Test for a block device.
+
+2010-02-23 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-dir.c: Fix printf format warning for a
+ 64bit off_t.
+
+ * libfs/src/rfs/rtems-rfs-file-system.h: Add a macro to get the
+ file system flags.
+
+ * libfs/src/rfs/rtems-rfs-group.c,
+ libfs/src/rfs/rtems-rfs-group.h: Add rtems_rfs_group_usage.
+
+ * libfs/src/rfs/rtems-rfs-rtems.c: Fill in all the fields in the
+ statvfs struct.
+
+ * libfs/src/rfs/rtems-rfs-shell.c: Use rtems_rfs_group_usage.
+
+2010-02-20 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/dosfs/fat.c, libfs/src/rfs/rtems-rfs-buffer.c: Block
+ devices are now block device nodes and not character device
+ nodes.
+
+2010-02-19 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/diskdevs.c: Create the devices as block devices.
+
+ * libmisc/shell/main_debugrfs.c, libmisc/shell/main_mkrfs.c,
+ libmisc/shell/main_mount_rfs.c: New.
+
+ * libmisc/shell/main_msdosfmt.c: Change the command to mkdos and
+ alias the old name.
+
+ * libmisc/shell/shellconfig.h, libmisc/Makefile.am: Add RFS
+ support.
+
+ * libfs/src/rfs/rtems-rfs-shell.c,
+ libfs/src/rfs/rtems-rfs-shell.h: Move the format command code into
+ the shell file.
+
+2010-02-18 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/rfs/rtems-rfs-bitmaps.c,
+ libfs/src/rfs/rtems-rfs-bitmaps.h,
+ libfs/src/rfs/rtems-rfs-bitmaps-ut.c,
+ libfs/src/rfs/rtems-rfs-block.c, libfs/src/rfs/rtems-rfs-block.h,
+ libfs/src/rfs/rtems-rfs-block-pos.h,
+ libfs/src/rfs/rtems-rfs-buffer-bdbuf.c,
+ libfs/src/rfs/rtems-rfs-buffer.c,
+ libfs/src/rfs/rtems-rfs-buffer-devio.c,
+ libfs/src/rfs/rtems-rfs-buffer.h, libfs/src/rfs/rtems-rfs-data.h,
+ libfs/src/rfs/rtems-rfs-dir.c, libfs/src/rfs/rtems-rfs-dir.h,
+ libfs/src/rfs/rtems-rfs-dir-hash.c,
+ libfs/src/rfs/rtems-rfs-dir-hash.h,
+ libfs/src/rfs/rtems-rfs-file.c, libfs/src/rfs/rtems-rfs-file.h,
+ libfs/src/rfs/rtems-rfs-file-system.c,
+ libfs/src/rfs/rtems-rfs-file-system-fwd.h,
+ libfs/src/rfs/rtems-rfs-file-system.h,
+ libfs/src/rfs/rtems-rfs-format.c,
+ libfs/src/rfs/rtems-rfs-format.h, libfs/src/rfs/rtems-rfs-group.c,
+ libfs/src/rfs/rtems-rfs-group.h, libfs/src/rfs/rtems-rfs.h,
+ libfs/src/rfs/rtems-rfs-inode.c, libfs/src/rfs/rtems-rfs-inode.h,
+ libfs/src/rfs/rtems-rfs-link.c, libfs/src/rfs/rtems-rfs-link.h,
+ libfs/src/rfs/rtems-rfs-mutex.c, libfs/src/rfs/rtems-rfs-mutex.h,
+ libfs/src/rfs/rtems-rfs-rtems.c,
+ libfs/src/rfs/rtems-rfs-rtems-dev.c,
+ libfs/src/rfs/rtems-rfs-rtems-dir.c,
+ libfs/src/rfs/rtems-rfs-rtems-file.c,
+ libfs/src/rfs/rtems-rfs-rtems.h,
+ libfs/src/rfs/rtems-rfs-rtems-utils.c,
+ libfs/src/rfs/rtems-rfs-shell.c, libfs/src/rfs/rtems-rfs-shell.h,
+ libfs/src/rfs/rtems-rfs-trace.c, libfs/src/rfs/rtems-rfs-trace.h:
+ New.
+
+ * Makefile.am, preinstall.am, libfs/Makefile.am,
+ wrapup/Makefile.am: Updated with the RFS support.
+
+ * libfs/README: Updated after 10 years.
+
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk-driver.c: Updated to the new error reporting
+ in libblock.
+
+ * libmisc/shell/main_ls.c, libmisc/shell/print-ls.c: Fix printing
+ the size in long mode.
+
+ * libnetworking/nfs/bootp_subr.c,
+ libnetworking/rtems/rtems_bootp.c,
+ libnetworking/rtems/rtems_bsdnet_internal.h: Return the BOOTP/DHCP
+ to the forever behaviour of 4.9 with the ability to call BOOTP and
+ control the process if required.
+
+2010-02-16 Chris Johns <chrisj@rtems.org>
+
+ * libcsupport/src/open.c: Tighten the open handler check.
+
+2010-02-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/rmdir.c, libcsupport/src/unlink.c: Free the
+ allocated pathloc.
+
+2010-02-01 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/fts.c: Updated to the latest NetBSD version to
+ resolve heap allocation bugs.
+ * libmisc/shell/main_ls.c, libmisc/shell/print-ls.c: Fix printing
+ size bugs.
+ * libnetworking/rtems/mkrootfs.c: Fix byte order bug when creating
+ the loopback interface address.
+
+2010-01-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
+ * libblock/src/bdbuf.c: Fixed invalid chain extract.
+
+2010-01-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/bdbuf.h: Documentation. New states
+ RTEMS_BDBUF_STATE_ACCESS_PURGED and RTEMS_BDBUF_STATE_TRANSFER_PURGED.
+ Declare rtems_bdbuf_purge_dev() and rtems_bdbuf_purge_major().
+ * libblock/src/bdbuf.c: Implemented ability to purge buffers from the
+ cache depending on the device identifier or major number. See test
+ "libtests/block10".
+
+2010-01-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/userextaddapiset.c: Removed file.
+ * score/Makefile.am: Update for removed file.
+ * sapi/include/rtems/extension.h, sapi/src/extensioncreate.c,
+ score/include/rtems/score/userext.h: The function
+ _User_extensions_Add_API_set is now inline. Added const qualifier to
+ extension table parameter in extension create and set functions.
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 30
+ * libmisc/shell/hexdump-parse.c:
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 1
+ * libmisc/shell/fts.c:
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 7
+ Coverity Id 8
+ * libblock/src/bdpart.c: Verify libblock is really set after
+ rtems_bdbuf_read() before using it.
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 5
+ * score/src/objectextendinformation.c: Check object_blocks for NULL to
+ determine when to allocate object block table.
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 27
+ * libmisc/fsmount/fsmount.c: Ensure calloc() returns memory and then we
+ do not have to check null when freeing it. Coverity noted it was used
+ before being checked for NULL.
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 3
+ * libmisc/shell/shell.c: Remove dead code path and fix warning.
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/hexdump-parse.c: Fix uninitialized warning.
+
+2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 30
+ * libmisc/shell/hexdump-parse.c: Add free(pr) before returning.
+
+2010-01-20 Chris Johns <chrisj@rtems.org>
+
+ Coverity Id 6
+ * libmisc/shell/hexdump-parse.c: Modify conditional to avoid NULL
+ dereference.
+
+2010-01-20 Chris Johns <chrisj@rtems.org>
+
+ Coverity Id 9
+ * libmisc/shell/main_ls.c: Modify conditional to avoid NULL
+ dereference.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 10
+ * libblock/src/bdbuf.c: Rework loop conditional to avoid potential use
+ of NULL pointer.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 23
+ * libmisc/monitor/mon-monitor.c: Add fclose() of file.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/ide_part_table.c: Another error path without a
+ free(sector).
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 28
+ * libcsupport/src/termios.c: Set then unconditionally to avoid
+ potential paths where it might be used uninitialized. Recommended by
+ Eric Norum.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 18
+ * libmisc/shell/fts.c: Add free(parent) to correct leak.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 24
+ * libblock/src/ide_part_table.c: Initialize sector to NULL and add
+ free(sector) on error return path from get_sector() to fix potential
+ leak.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 25
+ * libblock/src/ide_part_table.c: Add free(sector) on error return path
+ to fix leak.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 5
+ * score/src/objectinitializeinformation.c: Do not modify maximum
+ parameter. Clean up and simplify code. This should help the Coverity
+ path analysis to avoid reporting issues.
+
+2010-01-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
+ libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c,
+ libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c,
+ libfs/src/imfs/imfs_symlink.c: Create special helper method for
+ creating the j-node for the root directory. This lets us assume that
+ every j-node created otherwise has a parent node.
+
+2010-01-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/bdbuf.h: Documentation. Renamed
+ RTEMS_BDBUF_STATE_EMPTY in RTEMS_BDBUF_STATE_FREE. Renamed
+ RTEMS_BDBUF_STATE_FRESH in RTEMS_BDBUF_STATE_EMPTY. Renamed
+ RTEMS_BDBUF_STATE_ACCESS in RTEMS_BDBUF_STATE_ACCESS_CACHED. New
+ state RTEMS_BDBUF_STATE_ACCESS_EMPTY. Removed error field from
+ rtems_bdbuf_buffer.
+ * libblock/include/rtems/blkdev.h: Documentation. Removed error
+ field from block device IO control.
+ * libblock/src/bdbuf.c: Update for block device API change. New block
+ device driver error policies. A transfer error or a write to a
+ deleted disk will invalidate the block data now. See test
+ "libtests/block09". A get and release sequence will no longer trigger
+ a disk write.
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk-driver.c: Update for block device API change.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 27
+ * libblock/src/ramdisk-config.c: Coverity notes that the
+ calloc() is a resource leak. This is allocating memory for
+ a RAM disk which will persist for the life of the system. RTEMS
+ has no "de-initialize" driver call so there is no corresponding
+ free(r). Coverity is correct that it is never freed but this is
+ not a problem.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Fix warning.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 12
+ * libfs/src/imfs/memfile.c: Check for NULL return value.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 19
+ Coverity Id 20
+ Coverity Id 21
+ * libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_load_tar.c,
+ libfs/src/imfs/imfs_mknod.c: Add comment to explain allocation is
+ for life of file, not scope of method.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 12
+ Coverity Id 13
+ Coverity Id 14
+ Coverity Id 15
+ * libmisc/stackchk/check.c: Rewrote loop to avoid possible buffer
+ overruns when the pattern area size is not a multiple of 16. There
+ were no current ports impacted by this but better to be safe.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ Coverity Id 22
+ * libfs/src/imfs/imfs_symlink.c: Add comment to explain why this
+ is not a resource leak.
+
+2010-01-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/imfs_symlink.c: Spacing.
+
+2009-12-28 Shrikant Gaikwad <n3oo3n@gmail.com>
+
+ * cpukit/libfs/src/pipe/pipe.c Restructured code to remove the
+ goto statements.
+
+2009-12-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/lib/ftpfs.c: Use EINVAL not EBADRQC.
+
+2009-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/login_prompt.c: Switch from non-canonical mode with
+ timeout (Case C) to blocking IO waiting for single character on
+ login. In Case C mode, you cannot tell EOF from no data available.
+ This means we cannot tell when a telnet connection is dropped. This
+ was changed from 4.9 and resulted in breakage.
+
+2009-12-01 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ PR 1474
+ * libblock/include/rtems/diskdevs.h, libblock/src/bdbuf.c,
+ libblock/src/blkdev.c: Pass only physical disc devices to the block
+ device driver. Reject direct usage of RTEMS_BLKIO_REQUEST though an
+ IO control. Renamed and removed disk device structure access methods.
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk-driver.c: Update for block device API change.
+
+2009-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/clock.h: Eliminate unused type
+ rtems_clock_time_value.
+
+2009-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/termios.c, libfs/src/dosfs/msdos_format.c,
+ libfs/src/nfsclient/src/nfs.c, libfs/src/pipe/fifo.c,
+ libnetworking/lib/rtems_bsdnet_ntp.c, libnetworking/lib/tftpDriver.c,
+ libnetworking/rtems/rtems_glue.c, libnetworking/rtems/rtems_select.c:
+ Eliminate uses of deprecated rtems_clock_get() and replace with
+ properly typed routine.
+
+2009-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * telnetd/telnetd.c: Honor configuration setting for telnet daemon
+ stack size.
+
+2009-12-15 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/semmp.h,
+ rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h,
+ rtems/src/dpmemcreate.c, rtems/src/dpmemdelete.c,
+ rtems/src/dpmemexternal2internal.c, rtems/src/dpmemident.c,
+ rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c,
+ rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c,
+ rtems/src/msgqdelete.c, rtems/src/msgqflush.c,
+ rtems/src/msgqgetnumberpending.c, rtems/src/msgqident.c,
+ rtems/src/msgqreceive.c, rtems/src/msgqsend.c,
+ rtems/src/msgqurgent.c, rtems/src/partcreate.c,
+ rtems/src/partdelete.c, rtems/src/partgetbuffer.c,
+ rtems/src/partident.c, rtems/src/partreturnbuffer.c,
+ rtems/src/ratemoncancel.c, rtems/src/ratemoncreate.c,
+ rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c,
+ rtems/src/regioncreate.c, rtems/src/regiondelete.c,
+ rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionident.c,
+ rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c,
+ rtems/src/signalmp.c, rtems/src/signalsend.c, rtems/src/taskcreate.c,
+ rtems/src/taskdelete.c, rtems/src/taskgetnote.c,
+ rtems/src/taskident.c, rtems/src/taskissuspended.c,
+ rtems/src/taskrestart.c, rtems/src/taskresume.c,
+ rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c,
+ rtems/src/tasksuspend.c, rtems/src/timercancel.c,
+ rtems/src/timercreate.c, rtems/src/timerdelete.c,
+ rtems/src/timerfireafter.c, rtems/src/timerfirewhen.c,
+ rtems/src/timergetinfo.c, rtems/src/timerident.c,
+ rtems/src/timerreset.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c: Changed Objects_Id to rtems_id in
+ the public API.
+
+2009-12-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1483/cpukit
+ * include/rtems/pci.h: Rename pci_config into rtems_pci_config_t.
+
+2009-12-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1482
+ * posix/src/timersettime.c: Exit dispatching critical section.
+
+2009-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1480/cpukit
+ * rtems/src/ratemonperiod.c: Use _Rate_monotonic_Update_statistics()
+ when period is expired, not _Rate_monotonic_Initiate_statistics().
+ The cound of missed periods was never updated.
+
+2009-12-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * telnetd/pty.c:
+ Reflect changes to rtems_termios_callbacks->write.
+
+2009-12-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/libio.h: Change termios-write to ssize_t
+ write(...., size_t).
+
+2009-12-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Unconditionally build src/sigprocmask.c.
+ * posix/src/sigprocmask.c: Provide stub if RTEMS_POSIX_API
+ is disabled.
+
+2009-12-08 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonperiod.c: Factored out common code to ensure
+ consistent behavior between rtems_rate_monotonic_get_status and
+ rtems_rate_monotonic_report_statistics.
+
+2009-12-07 Cindy Cicalese <cicalese@mitre.org>
+
+ PR 1477/cpukit
+ * score/src/objectsetname.c: Ensure destination is NULL terminated.
+ String copy was not getting the NULL.
+
+2009-12-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/uio.h: Include <sys/types.h>.
+ Use ssize_t for uio_resid in struct uio (From FreeBSD).
+
+2009-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Unconditionally build
+ posix/src/sigaddset.c, posix/src/sigdelset.c,
+ posix/src/sigfillset.c, posix/src/sigemptyset.c,
+ posix/src/sigismember.c.
+
+2009-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/src/sigaddset.c, posix/src/sigdelset.c,
+ posix/src/sigemptyset.c, posix/src/sigfillset.c,
+ posix/src/sigismember.c, posix/src/sigprocmask.c:
+ Remove unnecessary includes.
+
+2009-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Unconditionally install
+ posix/include/rtems/posix/sigset.h.
+ * posix/include/rtems/posix/psignal.h: Reflect having split out
+ posix/include/rtems/posix/sigset.h.
+ * posix/include/rtems/posix/sigset.h: New (Split out from
+ posix/include/rtems/posix/psignal.h).
+
+2009-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Unconditionally build src/wait.c src/waitpid.c.
+ * posix/Makefile.am: Unconditionally build src/fork.c, src/vfork.c.
+
+2009-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac, posix/Makefile.am, wrapup/Makefile.am:
+ Eliminate AM_CONDITIONAL LIBPOSIX.
+
+2009-12-02 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * libcsupport/src/__times.c, libmisc/cpuuse/cpuusagedata.c,
+ libmisc/cpuuse/cpuusagereport.c, libmisc/cpuuse/cpuusagereset.c,
+ rtems/include/rtems/rtems/types.h, rtems/src/ratemongetstatistics.c,
+ rtems/src/ratemonreportstatistics.c, score/src/threaddispatch.c,
+ score/src/threadinitialize.c, score/src/threadtickletimeslice.c:
+ Updated copyright line.
+
+2009-12-02 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * configure.ac, libcsupport/src/__times.c,
+ libmisc/cpuuse/cpuusagedata.c, libmisc/cpuuse/cpuusagereport.c,
+ libmisc/cpuuse/cpuusagereset.c, rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/types.h, rtems/src/ratemongetstatistics.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c,
+ rtems/src/ratemonreportstatistics.c,
+ score/include/rtems/score/thread.h, score/src/threaddispatch.c,
+ score/src/threadinitialize.c, score/src/threadtickletimeslice.c:
+ Changed the configuration of statistics granularity to use just one
+ define.
+
+2009-12-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/def.h: Use __m32c__ for m32c.
+
+2009-12-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/def.h: Shrink default URI_MAX to 32767.
+ Add special cases for sizeof(size_t) < 2.
+
+2009-12-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/stringto/stringto.h, libmisc/stringto/stringto_template.h:
+ Tidy up as part of adding new test.
+
+2009-12-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am: Split no_posix.c so using sleep() does not
+ pull in kill() stubs.
+ * libcsupport/src/kill_noposix.c, libcsupport/src/sleep_noposix.c:
+ New files.
+ * libcsupport/src/no_posix.c: Removed.
+
+2009-12-01 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/vprintk.c: Fixed usage of va_arg().
+
+2009-11-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/login_prompt.c: Fix problem where timeout on login
+ prompt at console results in tight loop repeating login prompt.
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/threaddelayended.c: Clear only the states that are used to
+ block until someone calls _Thread_Delay_ended().
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/protectedheap.h,
+ score/src/pheapallocate.c: Changed base implementation of protected
+ heap allocations to use _Heap_Allocate_aligned_with_boundary().
+ * libcsupport/include/rtems/malloc.h, libcsupport/src/rtems_malloc.c:
+ Check system state. Process deferred frees. Renamed rtems_malloc() in
+ rtems_heap_allocate_aligned_with_boundary().
+ * score/src/pheapallocatealigned.c: Removed file.
+ * score/Makefile.am: Update for removed file.
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/bdbuf.h: Documentation.
+ * libblock/include/rtems/blkdev.h: Avoid designated initializers for
+ C++ compatibility.
+ * libblock/src/bdbuf.c: Fixed invalid state transition from FRESH to
+ CACHED.
+ * libblock/src/ide_part_table.c: Free memory in case of an error.
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/vprintk.c: Fixed output of unsigned integers.
+ Changed type of boolean variables to bool. Use unsigned integer type
+ for radix and width parameters.
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/chain.h, sapi/include/rtems/chain.h: Added
+ defines for initialization of empty chains.
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/termios.c: Obtain output semaphore before drain
+ output during close to prevent an infinite output drain loop.
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/shell/shell.c: Added format string to fprintf().
+
+2009-11-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/include/rtems/rtems/timer.h: Added timer server control block
+ Timer_server_Control. Removed _Timer_Server thread pointer. Added
+ _Timer_server pointer to the default timer server control block.
+ * rtems/src/rtemstimer.c, rtems/src/timerreset.c,
+ rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c:
+ Update for changes above.
+ * rtems/src/timerserver.c: Rework of the timer server implementation.
+ It is now possible to insert timers without the help of the timer
+ server thread. This reduces the need for a thread dispatch. The
+ timer server can now block on any resource type. Timer callbacks can
+ even wait for time.
+
+2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell.c: Always duplicate the environment passed to us
+ because we will delete it when the shell exits. If we do not
+ duplicate it, we could end up freeing memory which was not allocated
+ from the heap or double freeing it.
+
+2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/login_prompt.c: Properly process EOF and do not depend
+ on ungetc() to propagate the status back.
+
+2009-11-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/thread.inl: Eliminate unused variable and
+ code.
+
+2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1460/cpukit
+ * rtems/include/rtems/rtems/object.h,
+ rtems/src/rtemsobjectapimaximumclass.c,
+ rtems/src/rtemsobjectgetapiclassname.c,
+ rtems/src/rtemsobjectgetapiname.c,
+ rtems/src/rtemsobjectgetclassinfo.c,
+ rtems/src/rtemsobjectidapimaximum.c,
+ rtems/src/rtemsobjectidapiminimum.c, rtems/src/rtemsobjectidgetapi.c,
+ rtems/src/rtemsobjectidgetclass.c, rtems/src/rtemsobjectidgetindex.c,
+ rtems/src/rtemsobjectidgetnode.c: Change return type on methods
+ accessing portions of RTEMS Ids to int. This allows -1 to be return
+ on error.
+
+2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * mghttpd/mongoose.c: crypto_sw table is not used when SSL is disabled.
+ RTEMS does not have flockfile/funlockfile.
+
+2009-11-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Add mghttpd.
+
+2009-11-18 Thomas Doefler <Thomas.Doerfler@embedded-brains.de>
+
+ * libblock/include/rtems/blkdev.h, libblock/include/bdbuf.h,
+ libblock/src/bdbuf.c: various changes
+
+2009-11-19 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/check-networking.m4: Do NOT disable networking for the
+ avr and the m32c.
+
+2009-11-19 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/hexdump-odsyntax.c: Remove special casing
+ the h8300, avr, sh2e.
+
+2009-11-19 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/malloc_boundary.c: Avoid implicit type cast
+ (https://www.rtems.org/bugzilla/show_bug.cgi?id=1472#c1).
+
+2009-11-18 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/main_getenv.c, libmisc/shell/main_setenv.c,
+ libmisc/shell/main_unsetenv.c: New. The shell can now play with
+ environment variables.
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add setenv,
+ getenv, and unsetenv to the shell.
+
+2009-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add mghttpd/Makefile.
+ * mghttpd/mongoose.c: Various 16bit fixes.
+ Add HAVE_CONFIG_H.
+ Add HAVE_SYS_MMAN_H HAVE_DLFCN_H.
+ Convert to unix encoding.
+
+2009-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * mghttpd/Makefile.am: New.
+ * mghttpd/mongoose.c, mghttpd/mongoose.h, mghttpd/mongoose.1:
+ Import from svn http://mongoose.googlecode.com/svn/trunk (r477).
+
+2009-11-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/capture/capture-cli.c: Cast pointer to intptr_t to
+ print it (Casting to int32_t is wrong).
+
+2009-11-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * telnetd/telnetd.c (telnetd_dflt_spawn): Adjust prototype.
+
+2009-11-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/blkdev.h, libblock/src/blkdev.c: Changed set
+ and get IO controls to use the buffer argument for data exchange.
+
+2009-11-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
+ libcsupport/src/rtems_malloc.c: New function rtems_malloc().
+
+2009-11-11 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ PR 1471/cpukit
+ * libmisc/cpuuse/cpuusagereport.c: Rework statement to ensure 64-bit
+ multiplication is used to avoid overflow with intermediate value.
+
+2009-11-10 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ PR 1468/cpukit
+ * score/src/timespecdividebyinteger.c: Rework statement to ensure
+ 64-bit multiplication is used.
+
+2009-11-10 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ PR 1462/cpukit
+ * rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemonperiod.c: Fine
+ tune previous patch after analysis in application.
+
+2009-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/dosfs/msdos_format.c: Rework to avoid overflow on 16-bit
+ targets.
+
+2009-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/open_dev_console.c: Use constant numbers to avoid
+ overflow when shifting on 16-bit targets.
+
+2009-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/src/fatal.c: Formatting.
+
+2009-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl: Eliminate use of local
+ variable. This local variable causes unused variable warnings
+ on some ports.
+
+2009-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/thread.h: Revert accidentally committed
+ change. It is possible that _Thread_Dispatch_disable_level can be an
+ 8-bit variable but this impacts assembly and must be carefully
+ considered.
+
+2009-11-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/capture/capture.h (RTEMS_CAPTURE_CONTROL_FROM_MASK):
+ Use UINT32_C(1) to avoid overflow in implict typecast on 16bit
+ targets.
+
+2009-11-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * itron/src/chg_pri.c, itron/src/cre_tsk.c,
+ itron/src/eventflags.c, itron/src/fmempool.c,
+ itron/src/frsm_tsk.c, itron/src/itroninittasks.c,
+ itron/src/itronsem.c, itron/src/mbox.c, itron/src/msgbuffer.c,
+ itron/src/port.c, itron/src/rsm_tsk.c, itron/src/snd_mbx.c,
+ itron/src/task.c, itron/src/vmempool.c: Eliminate TRUE/FALSE in
+ favor of true/false.
+
+2009-11-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/bdbuf.c: Cast bdbuf->state to int32_t
+ before shifting << 16 (Can not shift an enum by << 16 on 16bit).
+
+2009-11-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_conv.c,
+ libfs/src/dosfs/msdos_misc.c: Use uint16_t instead of
+ "unsigned short" to circumvent warnings on 16bit targets.
+
+2009-11-02 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/bdbuf.c: Fixed buffer recycling. See test
+ "libtests/block03".
+
+2009-11-02 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/bdbuf.c: Wake-up access waiters after sync. See test
+ "libtests/block04".
+
+2009-10-30 Glenn Humphrey <glenn.humphrey@oarcorp.com>
+
+ PR pr1462/cpukit
+ * rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemontimeout.c,
+ score/include/rtems/score/thread.h: Fix bugs in rate monotonic
+ statistics.
+
+2009-10-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/semcreate.c: Fix mismatched brace in multiprocessing code.
+
+2009-10-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/bdbuf.c: Fixed group usage counting. See test
+ "libtests/block02".
+
+2009-10-30 Ralf Corsépius <ralf.corsepiu@rtems.org>
+
+ * aclocal/gcc-sanity.m4: New.
+ * configure.ac: Add RTEMS_CHECK_GCC_SANITY.
+
+2009-10-29 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/src/isr.c: Check if CPU defined _CPU_Interrupt_stack_setup()
+ macro hook for setting up the interrupt stack (alignment, reserving
+ space etc.) after the framework allocates it.
+
+2009-10-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/bdbuf.h: Reorderd AVL node fields to save
+ space.
+ * libblock/src/bdbuf.c: Fixed printf() formats. New structure for
+ waiters synchronization. Added BDBUF_INVALID_DEV define. New error
+ handling in rtems_bdbuf_init().
+ * libblock/src/bdpart.c, libblock/src/blkdev.c: Release disk in case
+ of an error.
+
+2009-10-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/ramdisk.h, libblock/src/ramdisk-driver.c:
+ Aded ramdisk_register().
+
+2009-10-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/prog-cc.m4: Remove RTEMS_CFLAGS.
+ Rework CFLAGS setup.
+ * automake/compile.am: Remove RTEMS_CFLAGS.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/cpu/Makefile.am: Update DIST_SUBDIRS.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/flashdisk.h: Use UINT32_C consts to
+ avoid implicit int-cast overflows in RTEMS_FDISK_KBYTES.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/error.h: Use ordinal constants for
+ RTEMS_ERROR_ERRNO, RTEMS_ERROR_PANIC, RTEMS_ERROR_ABORT to avoid
+ implicit constant conversion overflows on 16bit-int targets.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/uuid/uuid_time.c: Add cast to uint32_t to allow 16bit
+ shift on 16bit-int targets.
+ * libmisc/uuid/gen_uuid.c: Add HAVE_CONFIG_H guard.
+ Include <limits.h>. Shift pid_t's by (sizeof(pid_t)*CHAR_BIT)>>1
+ instead of hard-coded 16 to permit building on non 16bit-int
+ targets.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/extern-ls.h: Remove DAYSPERNYEAR, SECSPERDAY.
+ * libmisc/shell/print-ls.c: Add DAYSPERNYEAR, SECSPERDAY.
+ Add casts to time_t on constants in DAYSPERNYEAR, SECSPERDAY for
+ 16bit-int targets.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/dd-args.c: Use uint_least32_t instead of u_int,
+ force 32bit constants to make code functional on 16bit-int targets.
+
+2009-10-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove -fasm.
+
+2009-10-21 Till Straumann <strauman@slac.stanford.edu>
+
+ * sapi/include/rtems/config.h: Fixed typos (wrong case) in macro
+ expansion for rtems_configuration_get_device_driver_table()
+ and rtems_configuration_get_user_extension_table()
+
+2009-10-21 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * include/rtems/irq-extension.h: Removed vector argument from
+ rtems_interrupt_handler type.
+
+2009-10-20 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/cpu/i386/cpu.c, score/cpu/i386/cpu.h: let the default
+ exception handler print a stack trace.
+
+2009-10-20 Till Straumann <strauman@slac.stanford.edu>
+
+ PR1424/networking
+ * libnetworking/net/rtsock.c: (merged from BSD) copy information
+ out to user buffer.
+
+2009-10-20 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/ramdisk.h: Documentation.
+ * libblock/src/ramdisk-driver.c: Compile trace support conditionally.
+
+2009-10-20 Chris Johns <chrisj@rtems.org>
+
+ * libnetworking/rtems/rtems_mii_ioctl_kern.c: Added IFM_ACTIVE and
+ IFM_AVALID to the status for a link up. These are the supported
+ but in the BSD stack. Before IFM_LINK_OK was set and this is a
+ spare bit.
+
+2009-10-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/diskdevs.h: Documentation. Added field to
+ rtems_disk_device.
+ * libblock/include/rtems/blkdev.h: New request code
+ RTEMS_BLKIO_DELETED.
+ * libblock/src/diskdevs.c: Major rewrite. Changed the way disks are
+ deleted. Disks will be now deleted if they are not in use or upon
+ last release. The IO control handler will be invoked if a physical
+ disk is deleted with the RTEMS_BLKIO_DELETED request code. Logical
+ disks increase now the usage count of the associated physical disk.
+
+2009-10-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/ramdisk.c: Removed file.
+ * libblock/src/ramdisk-config.c, libblock/src/ramdisk-driver.c,
+ libblock/src/ramdisk-init.c: New files.
+ * libblock/include/rtems/ramdisk.h: Split up RAM disk functions to
+ support static and runtime configuration.
+ * libblock/Makefile.am: Update.
+
+2009-10-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/no_libc.c: Remove.
+ * libcsupport/Makefile.am: Remove no_libc.c.
+ * libcsupport/src/newlibc_reent.c: Eliminate RTEMS_UNIX.
+ * libcsupport/src/newlibc_exit.c: Eliminate RTEMS_UNIX.
+ * libcsupport/src/base_fs.c: Eliminate RTEMS_UNIX.
+ * libcsupport/src/stat.c: Eliminate RTEMS_UNIX.
+ * libmisc/monitor/mon-editor.c: Eliminate RTEMS_UNIX.
+ * libcsupport/include/rtems/libcsupport.h: Remove RTEMS_UNIX, hpux.
+ Fix extern "C" {}.
+ * libfs/src/imfs/ioman.c: Remove RTEMS_UNIX, __linux__.
+
+2009-10-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadhandler.c: Remove comment mentioning unix port.
+
+2009-10-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * wrapup/Makefile.am: Remove UNIX.
+ * configure.ac: Remove UNIX AM_CONDITIONAL.
+ * libfs/Makefile.am: Unconditionally build src/pipe/fifo.c
+ src/pipe/pipe.c src/pipe/pipe.h.
+ * libblock/Makefile.am: Unconditionally build libblock.
+ * Makefile.am: Unconditional build libblock.
+ * libfs/src/imfs/imfs_unixstub.c, libfs/src/devfs/devfs_unixstub.c:
+ Remove (unused).
+ * libfs/Makefile.am: Remove libfs/src/imfs/imfs_unixstub.c,
+ libfs/src/devfs/devfs_unixstub.c.
+
+2009-10-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/unixlibc.c, libcsupport/src/unixlibc_io.c,
+ libcsupport/src/hosterr.c: Remove (unused).
+ * libcsupport/Makefile.am: Remove libcsupport/src/unixlibc.c,
+ libcsupport/src/unixlibc_io.c, libcsupport/src/hosterr.c.
+
+2009-10-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/sysv-ipc.m4: Remove (unused).
+ * configure.ac: Remove RTEMS_UNIX, RTEMS_UNIXLIB.
+
+2009-10-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove some unix-specific checks.
+ Remove unix-CPU_CONTEXT size checking.
+ Remove enable-unixlib.
+ Remove unix subdir.
+ * aclocal/canonical-target-name.m4, aclocal/check-networking.m4,
+ aclocal/check-posix.m4, aclocal/enable-posix.m4:
+ Remove unix/posix.
+
+2009-10-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/cpu/Makefile.am: Remove unix subdir.
+
+2009-10-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/bdbuf.h: Use size_t for swapout_workers.
+ * libblock/src/bdpart.c: Add __attribute__((unused)) to suppress
+ warnings.
+ * libblock/src/bdbuf.c: Fix broken printf formats.
+ Use size_t for sizes.
+
+2009-10-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/error.h: Introduce rtems_error_code_t.
+ Minor portability code-massaging.
+ * libcsupport/src/error.c: Reflect having introduced
+ rtems_error_code_t.
+
+2009-10-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/interr.h: Introduce Internal_errors_t.
+ * score/src/interr.c, score/include/rtems/score/userext.h,
+ score/src/userextthreadbegin.c: Reflect having introduced
+ Internal_errors_t.
+
+2009-10-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/include/rtems/diskdevs.h: Added driver data pointer to IO
+ control function. The IO control handler takes now the disk device as
+ first parameter instead of the physical device number.
+ * cpukit/libblock/include/rtems/blkdev.h, libblock/src/bdbuf.c,
+ libblock/src/blkdev.c, libblock/src/diskdevs.c, libblock/src/nvdisk.c,
+ libblock/src/flashdisk.c, libblock/src/ramdisk.c: Update for block
+ device API change.
+
+2009-10-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/alarm.c: If 0 seconds do not insert timer.
+ * rtems/src/regionextend.c: Eliminate warning. Use default else.
+
+2009-10-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/thread.inl, score/src/threaddispatch.c:
+ Correct conditionals so _Thread_Enable_dispatch() is always inlined
+ when intended.
+
+2009-10-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/threadsup.h, posix/src/cancel.c,
+ posix/src/canceleval.c: Make psxcancel run again.
+ _POSIX_Thread_Exit() can be called on running thread or another
+ thread when it is cancelled.
+
+2009-10-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c,
+ posix/src/mutextimedlock.c, posix/src/prwlocktimedrdlock.c,
+ posix/src/prwlocktimedwrlock.c, posix/src/semtimedwait.c: Switch from
+ switch to if's because only one value needed to be tested. This
+ shrinks the code and makes it easier to do coverage analysis on.
+
+2009-10-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/object.inl: _Objects_Get_local_object() is
+ only called from places where the index is known to be valid.
+ _Objects_Set_local_object() already assumed this. Eliminates
+ unreachable code.
+
+2009-10-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/timerserver.c: Indentation.
+
+2009-10-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/regiondelete.c, rtems/src/regionextend.c,
+ rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c,
+ rtems/src/regiongetsegment.c, rtems/src/regionresizesegment.c,
+ rtems/src/regionreturnsegment.c: Avoid initializing status code. This
+ generates dead code on some targets. Add default case to eliminate
+ unitialized variable warning.
+
+2009-10-09 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * cpukit/sapi/include/rtems/io.h: Documentation.
+ * cpukit/sapi/src/ioregisterdriver.c: Call from interrupt context is
+ an error.
+ * cpukit/sapi/src/iounregisterdriver.c: Disable preemption during
+ critical section.
+
+2009-10-09 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/main_mknod.c: Fixed build problem with networking
+ disabled.
+
+2009-10-08 Chris Johns <chrisj@rtems.org>
+
+ * Makefile.am, preinstall.am: Added statvfs.h.
+ * libcsupport/Makefile.am: Add statvfs.c.
+ * libcsupport/include/sys/statvfs.h, libcsupport/src/statvfs.c:
+ New.
+ * libcsupport/include/rtems/libio.h: Add a file system handler for
+ the statvfs call.
+ * libfs/src/devfs/devfs_init.c, libfs/src/dosfs/msdos_init.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/nfsclient/src/nfs.c: Set the
+ statvfs handler to NULL.
+ * include/rtems/fs.h: Add a second node access field for the RFS
+ file system to hold a directory offset while the existing field
+ holds the inode number. This save a rescan of the directory when
+ working with directories.
+ * libblock/include/rtems/bdbuf.h: Added references and user fields
+ to the buffer descriptor.
+ * libblock/src/bdbuf.c: Added dynamic buffer support for different
+ block sizes. Fixed a number of bugs.
+ * libblock/src/blkdev.c: Release the disk device on an error.
+ * libblock/src/diskdevs.c: Set the block size to the media block
+ size during initialisation of the disk device.
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk.c: Updated the drivers to handle variable
+ block sizes.
+ * libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Release any
+ buffers when an error occurs. The FAT buffer layer hangs onto a
+ single buffer while mounted. This should be fixed.
+ * sapi/inline/rtems/chain.inl: Added rtems_chain_set_off_chain,
+ rtems_chain_is_node_off_chain, and rtems_chain_previous.
+ * score/inline/rtems/score/chain.inl: Added _Chain_Set_off_chain,
+ and _Chain_Is_node_off_chain.
+ * libmisc/shell/main_ln.c, libmisc/shell/main_mknod.c,
+ libmisc/shell/mknod-pack_dev.c, libmisc/shell/mknod-pack_dev.h:
+ New shell commands.
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added ln and
+ mknod commands.
+ * libmisc/shell/hexdump-display.c: Fixed the reopen bug which
+ showed up as a free with a bad pointer.
+ * libmisc/shell/main_mount.c: List the user adding file system
+ when listing the available file systems to mount.
+ * libmisc/shell/utils-cp.c: Remove the fixed static copy buffer
+ and use a large dynamic buffer.
+ * score/inline/rtems/score/address.inl, score/src/coremsgsubmit.c,
+ score/src/objectallocate.c, score/src/objectfree.c: Remove
+ warnings.
+
+2009-10-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/src/ioregisterdriver.c: Reowork so this is a context switch
+ disable critical section not interrupt disable critical section.
+ Hopefully eliminated dead code which showed up in coverage runs.
+
+2009-10-04 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * sapi/include/rtems/io.h, sapi/src/ioregisterdriver.c: Documenation.
+ rtems_io_lookup_name() is now deprecated. Added
+ rtems_io_driver_io_error(). rtems_io_register_driver() is now
+ thread-safe.
+
+2009-10-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/ratemonreportstatistics.c: owner field is always set so
+ safe to use. Reformat.
+ * rtems/src/regionresizesegment.c: Always evaluate the blocked queue
+ if the resize succeeded.
+ * rtems/src/tasksetnote.c: Spacing.
+
+2009-10-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/psignal.h: Add extern for ualarm timer.
+ * posix/src/alarm.c, posix/src/ualarm.c: Change from switch to if since
+ many enumerated values have no action.
+ * posix/src/psignal.c: Initialize ualarm and alarm timers.
+
+2009-10-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-driver.c: Fix warning if
+ defined(RTEMS_USE_16_BIT_OBJECT).
+ * libmisc/monitor/mon-prmisc.c: Fix warning if
+ defined(RTEMS_USE_16_BIT_OBJECT).
+
+2009-10-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1445/bsps
+ * include/rtems/pci.h:
+ Make pci_[read|write]_config* static inline, again.
+
+2009-10-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/pci.h: Add another missing prototype.
+
+2009-09-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/pci.h: Add missing prototype.
+
+2009-09-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/fstat.c, libcsupport/src/fcntl.c,
+ libcsupport/src/calloc.c, libcsupport/src/isatty_r.c,
+ libcsupport/src/issetugid.c, libcsupport/src/lseek.c,
+ libcsupport/src/read.c, libcsupport/src/getpid.c:
+ Rework autoconf defines.
+
+2009-09-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/_rename_r.c: Rework autoconf defines.
+ Remove unused includes.
+ * libcsupport/src/__gettod.c: Rework autoconf defines.
+ Eliminate RTEMS_UNIX.
+ * libcsupport/src/_calloc_r.c, libcsupport/src/_realloc_r.c:
+ Rework autoconf defines.
+ * libcsupport/src/open.c, libcsupport/src/close.c:
+ Rework autoconf defines.
+ * libcsupport/src/tcflow.c: Remove unused includes.
+ * libcsupport/src/__sbrk.c: Eliminate RTEMS_UNIX.
+ * libcsupport/src/_free_r.c, libcsupport/src/_malloc_r.c:
+ Rework autoconf defines.
+ * libcsupport/src/malloc_boundary.c: Comment out checkMallocArena
+ (unused).
+ * libcsupport/src/__assert.c: Rework autoconf defines.
+ * libcsupport/src/__brk.c: Eliminate RTEMS_UNIX.
+ Remove unused includes.
+ * libcsupport/src/getgroups.c: Remove unused includes.
+ * libcsupport/src/setpgid.c: Remove unused includes.
+ * libcsupport/src/malloc_p.h: Remove #include <inttypes.h>.
+
+2009-09-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/ppp_tty.c: Reflect termios_baud_to_number having
+ been renamed to rtems_termios_baud_to_number.
+
+2009-09-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/termios_setinitialbaud.c:
+ Include rtems/termiostypes.h.
+ Rename termios_set_initial_baud into rtems_termios_set_initial_baud.
+ * libcsupport/src/termios_num2baud.c:
+ Include rtems/termiostypes.h.
+ Rename termios_number_to_baud into rtems_number_to_baud.
+ * libcsupport/src/termios_baud2num.c:
+ Include rtems/termiostypes.h.
+ Rename termios_baud_to_number into rtems_termios_baud_to_number.
+ * libcsupport/src/termios_baud2index.c:
+ Include rtems/termiostypes.h.
+ Rename termios_baud_to_index into rtems_termios_baud_to_index.
+ * libcsupport/include/rtems/termiostypes.h: Include stdlib.h.
+ Add rtems_termios_baud_t.
+ Rename termios_number_to_baud into rtems_termios_number_to_baud,
+ termios_baud_to_number into rtems_termios_baud_to_number,
+ termios_baud_to_index into rtems_termios_baud_to_index.
+
+2009-09-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/tftpDriver.c: Remove vim: meta-tags.
+
+2009-09-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/src/heapwalk.c(Heap_Walk_printer): Add missing return type.
+ * libnetworking/lib/tftpDriver.c (rtems_tftp_eval_path):
+ Add missing parameter pathlen.
+ * libmisc/shell/hexdump-conv.c: Use %lc instead of %C.
+
+2009-09-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/regiondelete.c, rtems/src/regiongetfreeinfo.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/regionreturnsegment.c: Remove warnings.
+
+2009-09-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectidtoname.c: Remove error which cannot be reached
+ since API that calls this checks the error first.
+ * score/src/objectsetname.c: Adjust handling of length.
+
+2009-09-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/regiondelete.c, rtems/src/regiongetfreeinfo.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/regionreturnsegment.c: Do not initialize return status to
+ RTEMS_INTERNAL_ERROR.
+
+2009-09-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * include/rtems/pci.h: Revert extern inline patch.
+
+2009-09-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/capture/capture.c, posix/src/pthread.c, rtems/src/tasks.c,
+ score/include/rtems/score/userext.h: Eliminate use of deprecated
+ rtems_extension. Re-add prototype for _User_extensions_Add_API_set.
+
+2009-09-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/libcsupport.h,
+ libcsupport/src/newlibc_reent.c: Eliminate use of deprecated
+ rtems_extension.
+
+2009-09-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am: Re-add file accidentally deleted by Sebastian.
+
+2009-09-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/thread.inl: Restore the BSP context -- do
+ not save the current. This routine is also marked as not returning
+ which saves the exit path code.
+
+2009-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * include/rtems/pci.h: Change extern inline to static inline.
+
+2009-09-25 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * sapi/include/rtems/extension.h, sapi/src/extensiondelete.c,
+ sapi/src/extensionident.c, sapi/src/extensioncreate.c,
+ sapi/inline/rtems/extension.inl, score/include/rtems/score/userext.h,
+ score/src/userextthreaddelete.c, score/src/userext.c,
+ score/src/userextthreadcreate.c, score/src/userextremoveset.c,
+ score/src/userextthreadbegin.c, score/src/userextaddset.c,
+ score/src/userextthreadstart.c, score/src/userextthreadswitch.c,
+ score/src/userextthreadrestart.c: Documentation. The types
+ User_extensions_routine and rtems_extension are now deprecated.
+ Removed unused types User_extensions_thread_post_switch_extension and
+ rtems_task_post_switch_extension. Renamed _User_extensions_Add_API_set()
+ in _User_extensions_Add_set(). Renamed _User_extensions_Add_set() in
+ _User_extensions_Add_set_with_table().
+ * score/src/userextaddapiset.c: Removed file.
+ * score/Makefile.am: Update.
+
+2009-09-25 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/src/heap.c, score/include/rtems/score/heap.h: Reduced alignment
+ requirement for CPU_ALIGNMENT from four to two.
+
+2009-09-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/include/rtems/posix/threadsup.h: Add no return atrribute to
+ _POSIX_Thread_Exit().
+
+2009-09-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/hexdump-odsyntax.c: Fix failure on SH2e where there is
+ only single precision float.
+
+2009-09-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/getpagesize.c, posix/Makefile.am: Eliminate one copy
+ of getpagesize() and make it return an int.
+ * posix/src/getpagesize.c: Removed.
+
+2009-09-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am: Add getpagesize(). Now required by GNU Ada.
+ * posix/src/getpagesize.c: New file.
+
+2009-09-16 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/userextaddapiset.c: Disable code that is only used when
+ ITRON or POSIX is enabled.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/utils-cp.c: Include <utime.h> instead of
+ <sys/utime.h> for better POSIX compilance.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/malloc_p.h: Rely upon uintmax_t and PRIuMAX being
+ provided.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/libio_init.c, libcsupport/src/libio.c:
+ Reflect rtems_libio_number_iops being uint32_t.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/libio_init.c: Remove extern uint32_t
+ rtems_libio_number_iops.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/fcntl.c, libcsupport/src/malloc_boundary.c,
+ libcsupport/src/newlibc_reent.c, libcsupport/src/printk_plugin.c,
+ libcsupport/src/stat.c, libcsupport/src/tcflow.c,
+ libcsupport/src/tcflush.c, libcsupport/src/tcsendbreak.c,
+ libcsupport/src/tcsetpgrp.c, libcsupport/src/unlink.c,
+ libcsupport/src/unmount.c, libcsupport/src/write_r.c:
+ Add __attribute__((unused)) to function arguments.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/__brk.c, libcsupport/src/__gettod.c,
+ libcsupport/src/__sbrk.c, libcsupport/src/__times.c,
+ libcsupport/src/_calloc_r.c, libcsupport/src/_free_r.c,
+ libcsupport/src/_malloc_r.c, libcsupport/src/_realloc_r.c,
+ libcsupport/src/_rename_r.c, libcsupport/src/assocnamebad.c,
+ libcsupport/src/close.c, libcsupport/src/envlock.c,
+ libcsupport/src/fstat.c, libcsupport/src/getgroups.c,
+ libcsupport/src/getpid.c, libcsupport/src/isatty_r.c,
+ libcsupport/src/link.c, libcsupport/src/lseek.c,
+ libcsupport/src/open.c, libcsupport/src/read.c,
+ libcsupport/src/setpgid.c: Add __attribute__((unused)) to function
+ arguments.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1441/cpukit
+ * libcsupport/src/tcgetprgrp.c: Remove.
+ * libcsupport/src/tcgetpgrp.c: New (Renamed from
+ libcsupport/src/tcgetprgrp.c).
+ * libcsupport/Makefile.am: Add libcsupport/src/tcgetpgrp.c.
+ Remove libcsupport/src/tcgetprgrp.c.
+
+2009-09-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/getpwent.c: Ansify.
+
+2009-09-14 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/src/heapalignupuptr.c, score/src/heapallocatealigned.c:
+ Removed files.
+ * score/Makefile.am: Update.
+
+2009-09-14 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/src/wkspace.c: Removed work space area consistency checks.
+ * libblock/include/rtems/ide_part_table.h: Functions are now
+ deprecated.
+ * libcsupport/include/rtems/libcsupport.h, libcsupport/src/calloc.c,
+ libcsupport/src/malloc_boundary.c,
+ libcsupport/src/malloc_initialize.c,
+ libcsupport/src/malloc_report_statistics_plugin.c,
+ libcsupport/src/malloc_statistics_helpers.c,
+ libcsupport/src/malloc_walk.c, libcsupport/src/realloc.c,
+ rtems/inline/rtems/rtems/region.inl: Update for heap API changes.
+
+2009-09-14 Christian Mauderer <christian.mauderer@embedded-brains.de>
+
+ * libcsupport/src/vprintk.c: Fixed warnings. Print nothing in case the
+ pointer to the string is NULL.
+
+2009-09-14 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/src/wkspace.c: Removed work space area consistency checks.
+ * libblock/include/rtems/ide_part_table.h: Functions are now
+ deprecated.
+ * libcsupport/include/rtems/libcsupport.h, libcsupport/src/calloc.c,
+ libcsupport/src/malloc_boundary.c,
+ libcsupport/src/malloc_initialize.c,
+ libcsupport/src/malloc_report_statistics_plugin.c,
+ libcsupport/src/malloc_statistics_helpers.c,
+ libcsupport/src/malloc_walk.c, libcsupport/src/realloc.c,
+ rtems/inline/rtems/rtems/region.inl: Update for heap API changes.
+
+2009-09-14 Christian Mauderer <christian.mauderer@embedded-brains.de>
+
+ * libcsupport/src/vprintk.c: Fixed warnings. Print nothing in case the
+ pointer to the string is NULL.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/nanosleep.c: Disable EINTR case when POSIX is disabled
+ because it cannot happen.
+
+2009-09-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/coremsg.inl: Fix compilation issue when
+ notifications are not enabled.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/thread.h, score/src/threadinitialize.c,
+ score/src/threadstackfree.c: Disable capability for API to let user
+ provide thread stack when no API configured includes this capability.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/coresem.h, score/src/coresemseize.c:
+ Disable body of _CORE_semaphore_Seize() if it is not used because all
+ APIs using it are disabled.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/tod.h: Fix typo.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/config.h: Add
+ rtems_configuration_get_maximum_semaphores().
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am, posix/src/clockgetres.c: Add clockgetres.c to set
+ of clock and delayt methods built when POSIX threads are disabled.
+ Ensure it builds when POSIX is disabled.
+
+2009-09-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/coremsgbroadcast.c: Fix typo.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/coremsgsubmit.c: Remove extra #else.
+
+2009-09-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/coremsg.inl, score/src/coremsg.c,
+ score/src/coremsgbroadcast.c, score/src/coremsginsert.c,
+ score/src/coremsgseize.c, score/src/coremsgsubmit.c: Add wrappers for
+ accessing message priority. Since these are empty when priority-based
+ message queues are disabled, this eliminates some of the
+ conditionals.
+
+2009-09-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/coremsgseize.c: Fix typo.
+
+2009-09-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/coremsg.h,
+ score/inline/rtems/score/coremsg.inl, score/src/coremsg.c,
+ score/src/coremsginsert.c, score/src/coremsgseize.c,
+ score/src/coremsgsubmit.c, score/src/objectnametoidstring.c: Disable
+ the Core Message Queue features of notification, priority messages,
+ and blocking sends when no API requires them.
+
+2009-09-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/thread.h, score/src/threadhandler.c,
+ score/src/threadinitialize.c, score/src/threadtickletimeslice.c:
+ Disable thread protocol and scheduling capabilities not exercised
+ when POSIX or ITRON API is disabled.
+
+2009-09-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/object.h,
+ score/inline/rtems/score/object.inl,
+ score/src/objectgetnameasstring.c, score/src/objectidtoname.c,
+ score/src/objectinitializeinformation.c,
+ score/src/objectnamespaceremove.c, score/src/objectnametoidstring.c,
+ score/src/objectsetname.c, score/src/thread.c,
+ score/src/threadcreateidle.c: Disable object string name support when
+ POSIX is not enabled.
+
+2009-09-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/capture/capture.c: Use public API to obtain object name.
+
+2009-09-09 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/include/rtems/score/heap.h, score/inline/rtems/score/heap.inl,
+ score/src/heapallocate.c, score/src/heap.c, score/src/heapextend.c,
+ score/src/heapresizeblock.c, score/src/heapwalk.c: Documenation.
+ Simplified block resize. Improved heap walk. Changed heap layout to
+ avoid a special case for _Heap_Is_used() and _Heap_Is_free().
+ * libmisc/stackchk/check.c: Update for heap API changes.
+
+2009-09-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/issetugid.c: New (relocated from libnetworking).
+ * libnetworking/rtems/issetugid.c: Remove.
+ * libnetworking/Makefile.am: Reflect changes above.
+ * libcsupport/Makefile.am: Reflect changes above.
+
+2009-09-06 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * libcsupport/src/free.c, libmisc/stackchk/check.c,
+ rtems/include/rtems/rtems/region.h, rtems/src/regioncreate.c,
+ rtems/src/regionextend.c, rtems/src/regiongetinfo.c,
+ rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c,
+ rtems/src/regionresizesegment.c, score/src/pheapallocate.c,
+ score/src/pheapallocatealigned.c, score/src/pheapextend.c,
+ score/src/pheapfree.c, score/src/pheapgetblocksize.c,
+ score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c,
+ score/src/pheapgetsize.c, score/src/pheapinit.c,
+ score/src/pheapresizeblock.c, score/src/pheapwalk.c:
+ Update for heap API changes.
+ * score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/object.h: Documentation.
+ * score/include/rtems/score/heap.h,
+ score/include/rtems/score/protectedheap.h,
+ score/inline/rtems/score/heap.inl, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapallocatealigned.c,
+ score/src/heapextend.c, score/src/heapfree.c,
+ score/src/heapgetfreeinfo.c, score/src/heapgetinfo.c,
+ score/src/heapresizeblock.c, score/src/heapsizeofuserarea.c,
+ score/src/heapwalk.c: Overall cleanup. Added boundary constraint to
+ allocation function. More changes follow.
+
+2009-09-04 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * rtems/src/taskmode.c, sapi/src/exshutdown.c,
+ score/include/rtems/score/sysstate.h,
+ score/inline/rtems/score/sysstate.inl: Added
+ _System_state_Is_shutdown(). Removed direct uses of
+ _System_state_Current. Documentation.
+
+2009-08-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/malloc_initialize.c, sapi/src/exinit.c,
+ score/src/threadstartmultitasking.c: Fix spacing.
+ * libmisc/stackchk/check.c: Move variable into compiler specific conditional.
+
+2009-08-26 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/inline/rtems/score/address.inl: Added const qualifier
+ to parameters. Added cast to _Addresses_Subtract() fix a warning.
+
+2009-08-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/devfs/devfs.h: Fix spelling error.
+
+2009-08-26 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * sapi/include/rtems/config.h: Changed stack allocator signature to
+ match the one of _Workspace_Allocate().
+
+2009-08-24 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * libmisc/stackchk/check.c, rtems/src/regionreturnsegment.c,
+ rtems/src/regiongetsegmentsize.c, src/heapalignupuptr.c,
+ src/heapallocatealigned.c, src/heapallocate.c, src/heap.c,
+ src/heapextend.c, src/heapfree.c, src/heapgetfreeinfo.c,
+ src/heapgetinfo.c, src/heapresizeblock.c, src/heapsizeofuserarea.c,
+ src/heapwalk.c, src/pheapgetblocksize.c, inline/rtems/score/heap.inl,
+ include/rtems/score/heap.h: Overall cleanup. Changed all types for
+ addresses, sizes, offsets and alignments to uintptr_t. Reformatted.
+ Added variables for clarity. Renamed various objects. Enabled
+ _HAssert() for all instances. More changes follow.
+
+2009-08-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/devfs/devfs_eval.c: Fix bug where use of strncmp() resulted
+ in a partial match being considered a full name match. On ERC32,
+ looking for /dev/console would match /dev/console_b first.
+
+2009-08-21 Roxana Leontie <roxana.leontie@gmail.com>
+
+ * Makefile.am, preinstall.am, libmisc/Makefile.am: Changed the name of
+ mw-fb directory into fb. Relocated files.
+ * libmisc/fb/fb.h, libmisc/fb/mw_uid.c, libmisc/fb/mw_uid.h: New files.
+ * libmisc/mw-fb/fb.h, libmisc/mw-fb/mw_uid.c, libmisc/mw-fb/mw_uid.h:
+ Removed.
+
+2009-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h, score/Makefile.am,
+ score/include/rtems/score/thread.h: Only instantiate
+ _Thread_Idle_body() if it is going ot be used.
+ * score/src/threadidlebody.c: Removed.
+
+2009-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/pthread.c: Address sporadic server edge cases. Do not
+ change priority if thread is holding a priority ceiling or
+ inheritance mutex. Do not change it if it looks like the thread has
+ manually changed its priority. Style cleanup on file with new
+ comments added.
+
+2009-08-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/heapallocatealigned.c: Remove unused label.
+
+2009-08-18 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * score/src/heapallocatealigned.c: Change break to continue to fix
+ issue encountered on ARM. Fix indentation.
+
+2009-08-18 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/timerreset.c: Rework to ease analysis.
+
+2009-08-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * aclocal/check-networking.m4: Disable BSD TCP/IP for small memory
+ targets.
+
+2009-08-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/clockget.c: Restructure to ease coverage analysis of
+ deprecated routine.
+
+2009-08-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libi2c/libi2c.c: Fix warnings.
+
+2009-08-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/termios_baud2num.c: B134 should return 134 not 135.
+
+2009-08-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/malloc_boundary.c: This is currently non-funcitonal.
+ Do not build it when doing coverage until it works again.
+ * sapi/include/confdefs.h: Address linking errors when building for
+ configuration.
+
+2009-08-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am: Obsolete coverage file.
+ * libcsupport/src/end_profile.c: Removed.
+
+2009-08-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/preinstall.am,
+ posix/Makefile.am, posix/preinstall.am, rtems/Makefile.am,
+ rtems/preinstall.am, score/Makefile.am, score/preinstall.am: Revert
+ modifications accidentally committed.
+
+2009-08-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/debug.h: Fix typo.
+
+2009-08-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/__times.c, libfs/src/nfsclient/src/nfsTest.c,
+ libfs/src/nfsclient/src/rpcio.c: Convert calls to legacy routine
+ rtems_clock_get( RTEMS_CLOCK_GET_xxx, ..) to rtems_clock_get_xxx().
+
+2009-08-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/heapresizeblock.c: Remove printk's that were accidentally
+ committed.
+
+2009-08-09 Xi Yang <hiyangxi@gmail.com>
+
+ * libcsupport/Makefile.am, posix/Makefile.am, rtems/Makefile.am,
+ sapi/Makefile.am, score/Makefile.am,
+ score/include/rtems/score/heap.h: HEAP_BLOCK_USED_OVERHEAD was under
+ by one uint32_t. This showed up in the unlimited and heapwalk tests
+ on ARM targets.
+
+2009-08-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectextendinformation.c: Minor rework to eliminate
+ uncovered ranges introduced by Chris' patch.
+
+2009-08-06 Chris Johns <chrisj@rtems.org>
+
+ * score/src/objectextendinformation.c: Ensure that nothing is moved or
+ copied until all memory is successfully allocated.
+
+2009-08-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mqueuecreatesupp.c, posix/src/mqueuenametoid.c,
+ posix/src/mqueueopen.c, posix/src/semaphorecreatesupp.c: Tinker with
+ error handling for name too long. Use strnlen to ensure we do not run
+ off the end of the maximum length string.
+
+2009-08-06 Christian Mauderer <christian.mauderer@embedded-brains.de>
+
+ * rtems/include/rtems/rtems/types.h: Improve documentation.
+
+2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/bspcmdline/bspcmdline.h, libmisc/bspcmdline/bspcmdline_get.c,
+ libmisc/bspcmdline/bspcmdline_getparam.c,
+ libmisc/bspcmdline/bspcmdline_getparamraw.c,
+ libmisc/bspcmdline/bspcmdline_getparamrhs.c: Add rtems_ as prefix to
+ all routines.
+
+2009-08-06 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/bdbuf.c: Fix group user logic.
+ * libblock/include/rtems/blkdev.h, libblock/src/blkdev.c,
+ libblock/src/nvdisk.c, libblock/src/flashdisk.c: Add set block
+ size, and get media block size support.
+
+2009-08-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/sigaction.c: _POSIX_signals_Clear_process_signals now takes
+ signal number not mask.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am, rtems/Makefile.am, rtems/preinstall.am,
+ sapi/Makefile.am, sapi/preinstall.am, score/Makefile.am,
+ score/preinstall.am, score/include/rtems/score/heap.h,
+ score/inline/rtems/score/heap.inl: Remove inline version now that it
+ is in a C file.
+ * libcsupport/src/end_profile.c: New file.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am: Move from inline to body to avoid path explosion
+ from inlining this. Makes coverage analysis easier.
+ * score/src/heapalignupuptr.c: New file.
+
+2009-08-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/bspcmdline/bspcmdline.h, libmisc/bspcmdline/bspcmdline_get.c,
+ libmisc/bspcmdline/bspcmdline_getparam.c,
+ libmisc/bspcmdline/bspcmdline_getparamraw.c,
+ libmisc/bspcmdline/bspcmdline_getparamrhs.c: New files.
+ Missed in previous commit.
+
+2009-08-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, preinstall.am, libmisc/Makefile.am, wrapup/Makefile.am:
+ Add new BSP Boot Command Line helper routines. Recently boot_card()
+ has grown the ability to have a command line string pointer. These
+ routines provide an interface to that string.
+
+2009-08-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Fix typo.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/psignalclearsignals.c: Add comments.
+
+2009-08-05 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libio_.h,
+ libcsupport/src/fs_null_handlers.c: Null handlers are now const.
+ * libi2c/libi2c.c, libi2c/libi2c.h: Documentation. Do not create
+ semaphores on the fly.
+ * cpukit/libblock/src/bdpart.c: Fixed format specifier.
+ * cpukit/libblock/include/rtems/bdbuf.h, rtems/include/rtems.h,
+ rtems/include/rtems/rtems/asr.h, rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/barrier.h,
+ rtems/include/rtems/rtems/barriermp.h,
+ rtems/include/rtems/rtems/cache.h, rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h, rtems/include/rtems/rtems/dpmem.h,
+ rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/eventmp.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/intr.h, rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/modes.h, rtems/include/rtems/rtems/mp.h,
+ rtems/include/rtems/rtems/msgmp.h, rtems/include/rtems/rtems/object.h,
+ rtems/include/rtems/rtems/part.h, rtems/include/rtems/rtems/partmp.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/rtemsapi.h, rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/semmp.h, rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/status.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h, rtems/include/rtems/rtems/tasks.h,
+ rtems/include/rtems/rtems/timer.h, rtems/include/rtems/rtems/types.h,
+ rtems/inline/rtems/rtems/support.inl: Documentation.
+ * include/rtems/irq-extension.h: Documentation. Added API for
+ interrupt servers.
+
+2009-08-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Account for memory for POSIX message queue
+ file descriptors.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mqueuecreatesupp.c: Now that the number of POSIX message
+ queues and message queue descriptors are independently configured,
+ this code is reachable.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/include/rtems/posix/psignal.h, posix/src/mqueuecreatesupp.c,
+ posix/src/psignalclearprocesssignals.c,
+ posix/src/psignalclearsignals.c: Minor rework to ease coverage
+ analysis.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/intr.h, rtems/src/intrcatch.c: Disable
+ rtems_interrupt_catch on targets which do not use the simple vectored
+ interrupt model.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/heapallocatealigned.c: Fix spacing.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/wkspace.c: Improve debug output.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/include/rtems/posix/config.h, posix/src/mqueue.c,
+ sapi/include/confdefs.h: Add configuration of posix message queue
+ file descriptors as separate entity.
+
+2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/region.h: Use new name.
+ * score/include/rtems/debug.h: Fix spacing.
+
+2009-08-05 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/dummy/dummy-networking.c: New.
+ * libmisc/dummy/dummy.c, libmisc/Makefile.am: Move
+ trhe networking configuration into a separate file so
+ configuration varations do not cause conflicts.
+ * score/inline/rtems/score/object.inl,
+ score/include/rtems/score/object.h: Remove warnings.
+ * score/inline/rtems/score/object.inl: Add _Chain_First,
+ _Chain_Last, _Chain_Mext, and _Chain_Previous.
+ * sapi/inline/rtems/chain.inl: Add rtems_chain_first,
+ rtems_chain_last, rtems_chain_mext, and rtems_chain_previous.
+ * libblock/include/rtems/diskdevs.h: Remove the bdbuf pool id and
+ block_size_log2. Add media_block_size.
+ * libblock/src/diskdevs.c: Remove size restrictions on block
+ size. Add media block size initialisation. Remove comment to clean
+ up the bdbuf cache.
+ * libblock/src/blkdev.c: Remove references to
+ block_size_log2. Allow any block size.
+ * libblock/include/rtems/bdbuf.h, libblock/src/bdbuf.c: Remove all
+ references to pools and make the cache handle demand driver
+ variable buffer size allocation. Added worker threads support the
+ swapout task.
+ * sapi/include/confdefs.h: Updated the bdbuf configutation.
+
+2009-08-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Account for allocation of user extension
+ data area pointers.
+
+2009-08-03 Roxana Leontie <roxana.leontie@gmail.com>
+
+ * Makefile.am, preinstall.am, libmisc/Makefile.am: changed the
+ references to mw_fb.h into fb.h
+ * libmisc/mw-fb/mw_fb.h: renamed fb.h
+
+2009-08-03 Roger Dahlkvist <ruppe@kth.se>
+
+ * score/cpu/Makefile.am: nios2 was not in the list.
+
+2009-08-02 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/psignal.c: Simplify implementation to ease coverage
+ analysis.
+
+2009-08-02 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/support.h: Fix comments.
+
+2009-08-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/psxtransschedparam.c, posix/src/pthread.c: Add error checks
+ for 0 time on sporadic scheduler replenish period and initial budget.
+ This avoids having to correct for it in the TSR, so we can eliminate
+ the check for ticks == 0 there.
+
+2009-08-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/heap.inl, score/src/heapresizeblock.c:
+ Simplify routine.
+
+2009-08-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/heap.inl: Revert accidental commit.
+
+2009-08-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/heap.inl, score/src/heapwalk.c: Do not
+ inline code to check if newline should be printed. It leads to branch
+ path explosion which is really hard to get coverage on.
+
+2009-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/heapgetinfo.c: Simplify implementation.
+
+2009-07-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadinitialize.c: Rework so there is only one error exit
+ path. This required setting every variable that contains memory
+ allocated from the workspace to NULL early and using that assumption
+ in the one failed exit path.
+
+2009-07-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/wkspace.c: Add debug printks.
+
+2009-07-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/mqueuedeletesupp.c: Mark unreachable section as
+ RTEMS_DEBUG.
+
+2009-07-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/killinfo.c: Add _Thread_Enable_dispatch() on EAGAIN
+ error case. Add debug print on loop processing threads waiting
+ for signal.
+ * posix/src/psignal.c: When the sigwait() Thread Queue processing loop
+ was changed to FIFO, I forgot to change the initialization to match.
+
+2009-07-29 Roxana Leontie <roxana.leontie@gmail.com>
+
+ * libmisc/mw-fb/mw_fb.h: Cleaned code and added some more structures.
+
+2009-07-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/preinstall.am,
+ sapi/include/confdefs.h: Add configuration and basic device driver
+ ver definition for frame buffer device.
+ * libcsupport/include/rtems/framebuffer.h: New file.
+
+2009-07-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Makefile.am, score/preinstall.am: SuperCore Spinlock is only
+ used by POSIX API. Do not build it when POSIX is not enabled.
+
+2009-07-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/src/ioregisterdriver.c: Fix spacing.
+
+2009-07-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/killinfo.c: Rework to make easier to analyze for code
+ coverage and to simplify so it is easier to analyze for correctness.
+
+2009-07-24 Roxana Leontie <roxana.leontie@gmail.com>
+
+ * libmisc/mw-fb/mw_fb.h: divided fb_screeninfo structure into
+ fb_var_screeninfo and fb_fix_screeninfo
+
+2009-07-23 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/enable-itron.m4: Default to not building itron.
+
+2009-07-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/timerreset.c: Mark an unreachable path that is a sanity
+ check as conditional on RTEMS_DEBUG.
+
+2009-07-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/iterateoverthreads.c: Restructure a bit to make analysis
+ easier.
+
+2009-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/main_chmod.c,
+ libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
+ libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
+ libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
+ libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
+ libmisc/shell/shell_script.c, libmisc/stringto/stringto.h,
+ libmisc/stringto/stringto_template.h: Convert return type from bool
+ to rtems_status_code and add rtems_string_to_pointer. Perform
+ associated clean up and changes for return type change.
+ * libmisc/stringto/stringtopointer.c: New file.
+
+2009-07-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/killinfo.c: Clean up. Avoid NULL pointer case.
+
+2009-07-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/states.inl: Add
+ _States_Is_interruptible_by_signal. Add more DOxygen comments and
+ clean up.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_help.c: Provide a few more characters for command
+ names.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_mdump.c, libmisc/shell/main_mwdump.c: Fine tune
+ printf format.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/regionextend.c: Remove warning.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/semaphore.h, posix/include/rtems/posix/semaphore.h:
+ Move SEM_FAILED from private file to public file since it is defined
+ by POSIX.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_mount.c: Eliminate warning.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/main_chmod.c,
+ libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
+ libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
+ libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
+ libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
+ libmisc/shell/shell.h, libmisc/shell/shell_script.c,
+ libmisc/stringto/stringto_template.h: Convert all shell code to use
+ stringto.h mehods with better error checking.
+ * libmisc/shell/str2int.c: Removed.
+
+2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, preinstall.am, libmisc/Makefile.am, wrapup/Makefile.am:
+ Add the stringto family of string to number converters. These are
+ error checking wrappers for the strtoXXX methods and do their best to
+ return false if the conversion failed. The error checking required
+ for this is tedious and error prone. Hence better to have in a family
+ of helper routines.
+ * libmisc/stringto/stringto.h, libmisc/stringto/stringto_template.h,
+ libmisc/stringto/stringtodouble.c, libmisc/stringto/stringtofloat.c,
+ libmisc/stringto/stringtoint.c, libmisc/stringto/stringtolong.c,
+ libmisc/stringto/stringtolonglong.c,
+ libmisc/stringto/stringtounsignedchar.c,
+ libmisc/stringto/stringtounsignedint.c,
+ libmisc/stringto/stringtounsignedlong.c,
+ libmisc/stringto/stringtounsignedlonglong.c: New files.
+
+2009-07-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/include/rtems/posix/key.h, posix/src/keycreate.c,
+ posix/src/keydelete.c, posix/src/keyrundestructors.c: Restructure a
+ bit to make it easier to do coverage analysis. Eliminate is_active
+ member of control structure because it was redundant with very the
+ key object was open or closed.
+
+2009-07-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/eventseize.c, rtems/src/eventsurrender.c,
+ rtems/src/eventtimeout.c: Clean up and minor rework as a side-effect
+ of coverage analysis.
+
+2009-07-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/src/debug.c, score/include/rtems/debug.h: Rename
+ _Debug_Is_enabled to rtems_is_debug_enabled.
+
+2009-07-21 Roxana Leontie <roxana.leontie@gmail.com>
+
+ * libmisc/Makefile.am, libmisc/mw-fb/mw_fb.h: mw_fb.h eliminated the
+ ufb_* calls and replaced some of the ioctl structures and numbers
+ with the linux framebuffer equivalents
+ * libmisc/mw-fb/mw_fb.c: Removed.
+
+2009-07-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/cancel.h, posix/src/cancel.c,
+ posix/src/canceleval.c, posix/src/setcancelstate.c,
+ posix/src/setcanceltype.c: Fix a minor bug in the previous
+ modification which resulted in psxcancel failing.
+
+2009-07-21 Santosh G Vattam <vattam.santosh@gmail.com>
+
+ * posix/Makefile.am, posix/include/rtems/posix/cancel.h,
+ posix/src/cancel.c, posix/src/setcancelstate.c,
+ posix/src/setcanceltype.c: Add
+ _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch method to
+ avoid duplication of code and ease coverage analysis.
+ * posix/src/canceleval.c: New file.
+
+2009-07-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/corebarrierwait.c: Reverse order of tests to increase test
+ coverage.
+
+2009-07-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/ratemongetstatus.c: Fix spacing.
+
+2009-07-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mutexattrgettype.c: Restructure a bit to make code coverage
+ analysis easier.
+
+2009-07-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/watchdogadjusttochain.c: Correct bug in recent rework.
+ Coverage not impacted.
+
+2009-07-13 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/src/isrthreaddispatch.c: New file.
+ * score/include/rtems/score/isr.h: Added prototype.
+ * score/Makefile.am: Update.
+
+2009-07-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac, score/src/threadqenqueuepriority.c: Add
+ RTEMS_DO_NOT_UNROLL_THREADQ_ENQUEUE_PRIORITY to give user ability to
+ disable the loop in _Thread_queue_Enqueue_priority from being
+ unrolled. This reduces code size and makes coverage analysis easier.
+
+2009-07-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/watchdogadjusttochain.c: Rework to ease code coverage
+ analysis.
+
+2009-07-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/semcreate.c: Clean up rework to eliminate the goto and fix
+ a bug introduced by rework.
+
+2009-07-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/heap.c: Remove unneeded include.
+
+2009-07-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/semcreate.c: Restructure to simplify and improve ability to
+ anlize this routine for coverage.
+
+2009-07-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectgetinfo.c: Clean up and eliminate unreachable code.
+
+2009-07-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/rtemsobjectapimaximumclass.c,
+ score/include/rtems/score/object.h,
+ score/src/objectapimaximumclass.c, score/src/objectgetinfo.c: Change
+ return type of API maximum class methods to unsigned.
+
+2009-07-07 Chris Johns <chrisj@rtems.org>
+
+ * score/src/objectshrinkinformation.c: Rework loop to simplify and
+ remove dead code.
+
+2009-07-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * ChangeLog, posix/src/mutexsetprioceiling.c: Remove warning.
+
+2009-07-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mutexsetprioceiling.c: Remove warning.
+
+2009-07-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mutexsetprioceiling.c: Restructure to eliminate code
+ paths which are unreachable. Also add more comments.
+ * score/src/coremutexsurrender.c: Mark some code as RTEMS_DEBUG only
+ since it cannot be hit unless coremutexseize.c is broken.
+
+2009-07-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mutexget.c: Restructure to improve ability to do coverage
+ analysis.
+
+2009-07-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/psxtransschedparam.c: Restructure to avoid untestable code
+ being generated by switch.
+
+2009-07-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/coremsgsubmit.c: Move impossible case inside an RTEMS_DEBUG
+ conditional.
+
+2009-07-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am, posix/src/mutex.c, posix/src/mutexinit.c: Add
+ initial support for the pthread mutex type attribute added by UNIX98.
+ It can be normal, recursive, errorcheck or default.
+ * posix/src/mutexattrgettype.c, posix/src/mutexattrsettype.c: New files.
+
+2009-07-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/taskinitusers.c: Restructure to eliminate dead check --
+ loop will not be executed when 0 tasks. Also improved comments and
+ eliminated a local variable.
+
+2009-07-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/apiext.c: Unreachable API Extension paths marked as either
+ unused or only with certain APIs.
+
+2009-07-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * itron/src/task.c, posix/src/pthread.c, rtems/src/tasks.c,
+ sapi/src/exinit.c, score/include/rtems/score/apiext.h,
+ score/src/apiext.c: No APIs currently implemented use the
+ predriver_hook so disable it until such time as it is used.
+
+2009-07-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/sigtimedwait.c: Restructure to improve coverage. Improve
+ comments.
+
+2009-07-03 Daniel Hellstrom <daniel@gaisler.com>
+
+ * sapi/src/exinit.c, score/include/rtems/score/objectmp.h,
+ score/src/objectmp.c: Ensure local node number is set early enough in
+ MP configurations.
+
+2009-07-02 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/coremsg.h, score/src/coremsgflushwait.c:
+ Mark _CORE_message_queue_Flush_waiting_threads with
+ FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API since there is no way to
+ reach it via an API.
+
+2009-07-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/tod.h: Correct name of parameter.
+
+2009-06-30 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/prwlocktimedrdlock.c: Restructure if slightly to make to
+ make it easier to analyze for coverage.
+
+2009-06-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/killinfo.c, posix/src/mutexinit.c, posix/src/psignal.c,
+ posix/src/psignalchecksignal.c, posix/src/pthread.c,
+ posix/src/pthreadexit.c, posix/src/pthreadinitthreads.c: Remove
+ includes of <assert.h> where possible. Make other uses conditional on
+ ifdef RTEMS_DEBUG.
+
+2009-06-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am, posix/include/rtems/posix/priority.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/inline/rtems/posix/priority.inl, posix/src/killinfo.c,
+ posix/src/pthread.c, posix/src/pthreadcreate.c,
+ posix/src/pthreadsetschedparam.c: Various modifications to improve
+ binary code coverage analysis. Some of these are to mark code as
+ debug only. Some are to break conditional expressions into multiple
+ lines. Some are to move inline methods that are not time critical
+ into subroutines to make them easier to test. Inlining them multiple
+ times means that their logic paths are spread across multiple
+ methods. This explodes the test cases required.
+ * posix/src/psxpriorityisvalid.c, posix/src/psxtransschedparam.c: New files.
+
+2009-06-18 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/regionextend.c: Restructure to eliminate dead code being
+ generated.
+
+2009-06-18 Chris Johns <chrisj@rtems.org>
+
+ * telnetd/des.c: Split the des_f struct into smaller parts so
+ targets that cannot address large structs can be supported.
+
+2009-06-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectshrinkinformation.c: Fix spelling error.
+
+2009-06-18 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/hexdump-odsyntax.c: H8300 has the same size float
+ and double. Fix error in case statement.
+
+2009-06-18 Chris Johns <chrisj@rtems.org>
+
+ * score/cpu/mips/rtems/mips/idtcpu.h: Missed another WAIT
+ define. Removed.
+
+2009-06-17 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/extern-dd.h: Delcare the conv arrays extern to
+ stop PPC link errors.
+ * libmisc/shell/main_time.c, libmisc/Makefile.am,
+ libmisc/shell/shellconfig.h: Add a time command.
+
+ * libmisc/shell/shellconfig.h,
+2009-06-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * include/rtems/bspIo.h, libcsupport/Makefile.am: Add putk().
+ * libcsupport/src/putk.c: New file.
+
+2009-06-15 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/killinfo.c: Make easier to map coverage data.
+
+2009-06-15 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/hexdump-odsyntax.c: AVR has the same size float
+ and double. Fix error in case statement.
+ * libmisc/shell/main_dd.c: Remove sys/conf.h header. It is not
+ available if networking is disabled.
+
+2009-06-15 Chris Johns <chrisj@rtems.org>
+
+ * score/cpu/mips/rtems/mips/idtcpu.h: Remote WAIT define. Horrible
+ overload.
+
+2009-06-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/heapwalk.c: Remove include of stdlib.h since abort was not
+ called anymore.
+
+2009-06-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/region.h,
+ rtems/src/rtemsobjectgetclassinfo.c, score/src/heapwalk.c,
+ score/src/objectgetnameasstring.c, score/src/objectsetname.c,
+ score/src/timespecdivide.c, score/src/ts64divide.c: Remove include of
+ stdio.h
+
+2009-06-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk.c, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/msdos_format.c: Eliminate using the GNU/Linux
+ specific error numbers EBADRQC and ENOTBLK. Switch to EINVAL and
+ ENOTTY as appropriate.
+
+2009-06-12 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/dd-args.c, libmisc/shell/dd-conv.c,
+ libmisc/shell/dd-conv_tab.c, libmisc/shell/dd-misc.c,
+ libmisc/shell/dd-position.c, libmisc/shell/dd.h,
+ libmisc/shell/extern-dd.h, libmisc/shell/hexdump-conv.c,
+ libmisc/shell/hexdump-display.c, libmisc/shell/hexdump-odsyntax.c,
+ libmisc/shell/hexdump-parse.c, libmisc/shell/hexdump.h,
+ libmisc/shell/hexsyntax.c, libmisc/shell/main_dd.c,
+ libmisc/shell/main_hexdump.c: New.
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add dd and
+ hexdump commands.
+
+2009-06-12 Chris Johns <chrisj@rtems.org>
+
+ * libblock/include/rtems/flashdisk.h,
+ libblock/include/rtems/nvdisk.h, libblock/src/flashdisk.c,
+ libblock/src/nvdisk.c: Change names to match the RAM disk change.
+ * libcsupport/src/eval.c: Remove some warnings.
+
+2009-06-12 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/bdbuf.c: Update comments.
+ * libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the
+ device from the rdev field of the stat buf.
+ * libcsupport/include/rtems/libio.h: Add a path length to evalpath
+ handler. Add parent locations to rmmod and unlink handlers.
+ * libcsupport/include/rtems/libio_.h: Add a path length to
+ rtems_filesystem_evaluate_path. Add
+ rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname,
+ and rtems_filesystem_prefix_separators. Remove
+ rtems_filesystem_evaluate_parent.
+ * libcsupport/src/base_fs.c, libcsupport/src/chdir.c,
+ libcsupport/src/chmod.c, libcsupport/src/chown.c,
+ libcsupport/src/chroot.c, libcsupport/src/fchdir.c,
+ libcsupport/src/link.c, libcsupport/src/mount.c,
+ libcsupport/src/open.c, libcsupport/src/privateenv.c,
+ libcsupport/src/readlink.c, libcsupport/src/unmount.c,
+ libcsupport/src/utime.c, libcsupport/src/unmount.c,
+ libcsupport/src/utime.c, libfs/src/devfs/devfs.h,
+ libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c,
+ libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c,
+ libnetworking/lib/ftpfs.c: Add the length parameter to the eval
+ call.
+ * libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators,
+ rtems_filesystem_dirname,
+ rtems_filesystem_evaluate_relative_path. Add the length parameter
+ to the eval call.
+ * libcsupport/src/rmdir.c: Find the parent pathloc then the node
+ pathloc from that node. Remove the call to find the parent given
+ the node pathloc.
+ * libcsupport/src/stat.c: Add the length parameter to the eval
+ call. Set the device into the rdev field.
+ * libcsupport/src/unlink.c: Find the parent pathloc then the node
+ pathloc from that node. Remove the call to find the parent given
+ the node pathloc.
+ * libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the
+ disk device number from the stat rdev field.
+ * libfs/src/dosfs/msdos.h: Add the length parameter to the eval
+ call. Add the parent pathloc to the rmnod handler.
+ * libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod
+ handler.
+ * libfs/src/dosfs/msdos_eval.c: Add the length parameter to the
+ eval and token call.
+ * libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the
+ rmnod handler.
+ * libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for
+ only the allowed flags. Add the missing flags spec'ed in the POSIX
+ standard.
+ * libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c,
+ libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the
+ parent node. Currently ignored in the IMFS.
+ * libfs/src/imfs/imfs_stat.c: Return the device number in the rdev
+ field.
+ * libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add
+ the length parameter to the token call.
+ * libfs/src/nfsclient/src/nfs.c: Add the length parameter to the
+ eval call and parent node to the rmnod and unlink command.
+ * libmisc/shell/internal.h: Remove the libc mounter decl to make
+ public.
+ * libmisc/shell/main_mount.c: Add support for hooking external
+ mount support for new file systems.
+ * libmisc/shell/shell.h: Add helper functions for the mount
+ command.
+
+2009-06-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/corespinlockwait.c: Mark timeout code which is not
+ currently exercised by any API with the
+ FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API conditional.
+
+2009-06-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Fix minor error when application has its own
+ initialization task table.
+
+2009-06-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/heapwalk.c: Verify addresses are aligned.
+
+2009-06-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/assoc.h,
+ libcsupport/include/rtems/malloc.h: Add extern "C" {} guards.
+ * libcsupport/include/rtems/libio_.h: Move extern "C" {} guards.
+
+2009-06-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/thread.h, score/src/threadinitialize.c,
+ score/src/threadreset.c, score/src/threadresume.c,
+ score/src/threadsuspend.c: Nesting count on thread suspension is only
+ supported from ITRON API so disable if ITRON is disabled.
+
+2009-06-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/thread.h, score/src/threadhandler.c: Merge
+ conditional code from main and init/fini C++ constructors so the body
+ of this method reads better. Mark thread prototypes which are not
+ currently exercised by any APIs with
+ FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API conditional.
+
+2009-05-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1415/cpukit
+ * rtems/src/semcreate.c, rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coremutex.h,
+ score/inline/rtems/score/coremutex.inl, score/src/coremutex.c:
+ Address two paths where a task with a priority above the ceiling
+ could obtain a priority ceiling mutex.
+
+2009-05-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtc.h: New RTC driver interface.
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added RTC command.
+ * libmisc/shell/main_rtc.c: New file.
+
+2009-05-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1413/cpukit
+ * rtems/src/timerserver.c: Fix bug where server based timers which
+ reinitiated themselves did not get reinserted onto timer chain.
+
+2009-05-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * librpc/src/xdr/xdr_float.c: Change detection logic for h8300.
+
+2009-05-18 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1412/cpukit
+ * score/src/coremutex.c: Add missing braces. Broken with strict mutex
+ code added.
+
+2009-05-15 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/getitimer.c, posix/src/setitimer.c: Add error checks and
+ clean up so coverage analysis is possible.
+
+2009-05-15 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/sysconf.c: Restructure to improve coverage analysis.
+
+2009-05-15 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/src/printk.c: Restructure to
+ make analysis and coverage easier. Now 100% covered.
+ * libcsupport/src/vprintk.c: New file.
+
+2009-05-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1411/cpukit
+ * rtems/src/workspace.c, score/include/rtems/score/protectedheap.h,
+ score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c: Improve
+ workspace wrapper methods.
+
+2009-05-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/login_prompt.c, libmisc/shell/shell_script.c,
+ rtems/include/rtems/rtems/timer.h: Fix warnings.
+
+2009-05-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/psignal.h,
+ rtems/inline/rtems/rtems/support.inl: Remove warnings.
+
+2009-05-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/config.h: Switch from ssize_t to uintptr_t for
+ work space size since it is larger than a single allocatable object.
+
+2009-05-08 Chris Johns <chrisj@rtems.org>
+
+ * cpukit/libblock/src/bdpart.c, libmisc/shell/main_msdosfmt.c,
+ libmisc/shell/main_rm.c, libnetworking/libc/gethostnamadr.c,
+ score/include/rtems/score/bitfield.h,
+ score/inline/rtems/score/priority.inl: Remove warnings.
+
+2009-05-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectgetnext.c: Add checks for NULL pointers.
+
+2009-05-07 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h: Added
+ timeouts. Options are now per file system instance.
+
+2009-05-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/uuid/gen_uuid.c, libnetworking/lib/syslog.c,
+ telnetd/telnetd.c: Fixed warnings.
+
+2009-05-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am:
+ * libcsupport/src/isatty_r.c: New file.
+
+2009-05-06 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/uuid/README: New file.
+
+2009-05-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/part.h,
+ rtems/inline/rtems/rtems/region.inl: Fix warnings.
+
+2009-05-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/heap.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/tod.inl: Remove warnings.
+
+2009-05-05 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/system.h: Added
+ RTEMS_COMPILER_DEPRECATED_ATTRIBUTE define.
+ * include/rtems/endian.h:
+ Added functions to translate integers to/from byte streams.
+ * libnetworking/lib/ftpfs.c: Added timeout for active data connection
+ accept. Return EIO for close() errors. Changed PORT format string.
+ Fixed connection termination after store errors on passive connections.
+ Added magic device identifier for stat().
+ * libmisc/uuid/clear.c, libmisc/uuid/compare.c, libmisc/uuid/copy.c,
+ libmisc/uuid/COPYING, libmisc/uuid/gen_uuid.c, libmisc/uuid/isnull.c,
+ libmisc/uuid/pack.c, libmisc/uuid/parse.c, libmisc/uuid/unpack.c,
+ libmisc/uuid/unparse.c, libmisc/uuid/uuidd.h, libmisc/uuid/uuid.h,
+ libmisc/uuid/uuidP.h, libmisc/uuid/uuid_time.c: New files.
+ * Makefile.am, preinstall.am, libblock/Makefile.am,
+ libmisc/Makefile.am, wrapup/Makefile.am: Update.
+ * libblock/include/rtems/bdpart.h, libblock/src/bdpart.c,
+ libmisc/shell/fdisk.c: New files.
+ * libmisc/shell/shellconfig.h: Added FDISK command.
+ * libblock/include/rtems/blkdev.h, libblock/include/rtems/diskdevs.h:
+ Documentation.
+ * libblock/include/rtems/ramdisk.h, libblock/src/ramdisk.c,
+ libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h:
+ Documentation. Changed integer types to match block device types.
+ Added const qualifier whenever possible. Added
+ rtems_fsmount_create_mount_point() prototype.
+ * libfs/src/dosfs/msdos_format.c: Added check for NULL.
+
+2009-05-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * telnetd/telnetd.h: Spacing.
+
+2009-05-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/clock.h, rtems/src/clocktodtoseconds.c,
+ rtems/src/clocktodvalidate.c: Add const to parameter.
+
+2009-05-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell.c, libmisc/stackchk/check.c: Eliminate warnings.
+
+2009-05-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/condtimedwait.c, posix/src/mutextimedlock.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/semopen.c: Silence warnings.
+
+2009-04-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * sapi/include/confdefs.h, libblock/include/rtems/bdbuf.h: Changed
+ type of rtems_bdbuf_pool_configuration_size to size_t.
+
+ * libblock/include/rtems/bdbuf.h, libblock/include/rtems/blkdev.h,
+ libblock/include/rtems/diskdevs.h, libblock/src/bdbuf.c,
+ libblock/src/blkdev.c, libblock/src/diskdevs.c: Buffer pool
+ allocation is now cache aligned. The cache functions are
+ currently not available on all platforms so the cache line size is
+ fixed to 32 bytes for now. Changed various integer types which
+ refer to block sizes, numbers and indexes. Fixed logical block
+ indexes in buffer get and read function. It is now possible to
+ delete logical disks. Modified documentation
+
+2009-04-29 Chris Johns <chrisj@rtems.org>
+
+ * libcsupport/include/rtems/libio.h: Add rtems_off64_t for
+ internal use. Update the internal off_t to the 64bit offset.
+
+ * libnetworking/lib/ftpfs.c, libnetworking/lib/tftpDriver.c,
+ libfs/src/nfsclient/src/nfs.c, libfs/src/imfs/imfs_fifo.c,
+ libfs/src/imfs/memfile.c, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/deviceio.c: Change off_t to
+ rtems_off64_t.
+
+ * libmisc/shell/main_msdosfmt.c: Add an info level so the format
+ code can tell the user what is happening. Add more options to
+ control the format configuration.
+
+ * libfs/src/dosfs/msdos_format.c: Add a print function to display
+ the format progress and print statements. Select a better default
+ cluster size depending on the size of the disk. This lowers the
+ size of the FAT on large disks. Read and maintain the MRB
+ partition information.
+
+ * libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.h,
+ libfs/src/dosfs/fat_file.c, libfs/src/dosfs/fat_file.h,
+ libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_conv.c,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_file.c,
+ libfs/src/dosfs/msdos_handlers_dir.c,
+ libfs/src/dosfs/msdos_handlers_file.c,
+ libfs/src/dosfs/msdos_init.c, libfs/src/dosfs/msdos_initsupp.c,
+ libfs/src/dosfs/msdos_misc.c, libfs/src/dosfs/msdos_mknod.c: Add
+ long file name support. Change off_t to rtems_off64_t.
+
+ * libblock/include/rtems/ide_part_table.h: Add MRB partition table
+ size.
+
+2009-04-28 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/bdbuf.c: Flush the transfer sync event before
+ blocking in a read.
+
+2009-04-28 Chris Johns <chrisj@rtems.org>
+
+ * libnetworking/nfs/bootp_subr.c: Fixed PR1384. The route set in
+ the initialise pass is not deleted so an exists error is
+ returned. Ignore the error. Print the server address as an IP
+ address not hex digits.
+
+ * libnetworking/rtems/rtems_dhcp.c: Fixed
+ PR1338. Close the socket, handle the returned event flags.
+
+2009-04-28 Chris Johns <chrisj@rtems.org>
+
+ * sapi/include/confdefs.h: Add a prototype for Init with C linkage
+ and define Init task command line arguments if confdefs.h provides
+ an Init entry point.
+
+2009-04-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Disable LIBSHELL for unix targets.
+
+2009-04-15 Wei-Tsun Sun <wsun013@gmail.com>
+
+ * libcsupport/src/malloc_initialize.c: Add dummy
+ RTEMS_Malloc_Initialize.
+
+2009-04-14 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/rtems/rtems_mii_ioctl_kern.c: poll BMSR twice
+ to clear latched link-status low.
+
+2009-04-14 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * Makefile.am, preinstall.am, libmisc/shell/login.h: Removed login.h.
+ * libmisc/shell/login_check.c, libmisc/shell/login_prompt.c,
+ libmisc/shell/shell.c, libmisc/shell/shell.h: Changed copyright
+ notices. Moved shell login declarations to shell.h.
+ * telnetd/check_passwd.c, telnetd/telnetd.c, telnetd/telnetd.h: Changed
+ copyright notices. Update for shell login changes.
+
+2009-04-03 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c: Fixed return codes of open handler.
+ Request reply after data write connection close.
+
+2009-04-02 Ralf Corsépius <ralfcorsepius@rtems.org>
+
+ * aclocal/check-rtems-debug.m4: Add missing ','.
+
+2009-03-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/symlink.c: Check if path evaluation handler exists.
+ * libnetworking/lib/ftpfs.c: Cleanup.
+
+2009-03-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * Makefile.am, preinstall.am, libmisc/Makefile.am,
+ libmisc/shell/shell.c, libmisc/shell/shell.h, telnetd/check_passwd.c,
+ telnetd/telnetd.c, telnetd/telnetd.h:
+ Generalized login check.
+ * libmisc/shell/login.h, libmisc/shell/login_check.c,
+ libmisc/shell/login_prompt.c: New files.
+ * libmisc/stackchk/check.c: Changed format for blown stack message.
+ * libcsupport/src/libio_sockets.c: Removed superfluous cast.
+ * libnetworking/rtems/ftpfs.h: Documentation.
+
+2009-03-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/shell/shell.h: Pointer to
+ oparations table for mount command is now const.
+ * libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h: Rewrite of
+ the FTP file system which implements now the trivial command state
+ machines of RFC 959. For the data transfer passive (= default) and
+ active (= fallback) modes are now supported.
+ * libmisc/shell/main_mount_ftp.c: Update for FTP file system changes.
+
+2009-03-12 Santosh G Vattam <vattam.santosh@gmail.com>
+
+ PR 1378/filesystem
+ * libfs/src/imfs/deviceio.c: IMFS device lseek should return the
+ current offset.
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * ftpd/ftpd.h: Add extern C.
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1393/cpukit
+ * posix/src/mutextranslatereturncode.c: Add entry to table for
+ CORE_MUTEX_RELEASE_NOT_ORDER.
+
+2009-03-11 Ralf Corsépius <ralfcorsepius@rtems.org>
+
+ * configure.ac: Check for __assert().
+ * libcsupport/src/__assert.c: Conditionally build __assert().
+
+2009-03-10 Ralf Corsépius <ralfcorsepius@rtems.org>
+
+ * configure.ac: Check for creat().
+ * libcsupport/src/creat.c: Build conditionally.
+
+2009-03-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1376/filesystem
+ * libcsupport/include/rtems/libio.h, libfs/src/dosfs/fat_file.c,
+ libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_dir.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/imfs/deviceio.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/imfs_fifo.c, libfs/src/imfs/memfile.c,
+ libfs/src/nfsclient/src/nfs.c: lseek handlers should return off_t.
+
+2009-03-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/heap.inl: Use the correct fields and do end
+ - begin.
+
+2009-03-05 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/src/malloc_initialize.c: Fixed invalid function
+ parameter.
+
+2009-03-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc_initialize.c, score/Makefile.am,
+ score/include/rtems/score/protectedheap.h,
+ score/inline/rtems/score/heap.inl: Get total heap size correct when
+ using unified C Program Heap and RTEMS Workspace.
+ * score/src/pheapgetsize.c: New file.
+
+2009-03-02 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1388/cpukit
+ * rtems/src/semcreate.c: Classic Semaphores allow both priority inherit
+ and ceiling attributes to be set on semaphore create. These
+ attributes are mutually exclusive and this should be an error.
+
+2009-02-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/shell/shell.c, libmisc/shell/shell.h: Changed type for
+ boolean values from 'int' to 'bool'. Added option 'login' to enable or
+ disable a login prompt. Changed intialization of global shell
+ environment to static initialization. Changed stack size type to
+ 'size_t' conforming to classic API.
+
+ * libmisc/shell/shellconfig.h: Fixed some typos.
+
+2009-02-20 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * include/sys/priority.h: New.
+ * Makefile.am: Add include/sys/priority.h
+
+2009-02-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * include/rtems/irq-extension.h, include/rtems/irq.h: Spelling errors
+ and spacing.
+
+2009-02-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Re-add boolean when
+ building BSD code. This is used by at least one of the BSD NIC
+ drivers I am currently porting. I am trying out
+
+2009-02-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add halt command to
+ shell which results in the shutting RTEMS down.
+ * libmisc/shell/main_halt.c: New file.
+
+2009-02-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1377/shell
+ * libmisc/shell/main_netstats.c: Remove #if 0 which should not have
+ been there anyway.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/config.h, score/include/rtems/score/thread.h,
+ score/src/threadidlebody.c: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/src/exinit.c: Eliminate _CPU_Thread_dispatch_pointer and passing
+ address of _Thread_Dispatch to _CPU_Initialize. Clean up comments.
+
+2009-02-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1374/misc
+ * libmisc/stackchk/check.c: Fix printk formatting string.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/src/exinit.c: Interrupts are guaranteed to be disabled by
+ boot_card(), do not do it here as well.
+
+2009-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/kernel.h: Remove PSEUDO_*
+ (Unused, not in FreeBSD).
+ * libnetworking/sys/kernel.h: Remove struct linker_set (Unused).
+ * libnetworking/net/if_loop.c: Remove PSEUDO_SET (Unused).
+ * libnetworking/kern/uipc_domain.c: Remove domain_set (Unused).
+ * libnetworking/sys/kernel.h: Remove execsw_set,
+ si_elem_t (Unused, not in FreeBSD).
+ #include <sys/linker_set.h>.
+ Add #ifdef _KERNEL guards (From FreeBSD).
+
+2009-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/kernel.h: Remove hostnamelen, domainnamelen,
+ lbolt, tickdelta, timedelta (Unused, not in FreeBSD).
+
+2009-02-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/vm/vm.h: Cosmetics from FreeBSD.
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Remove struct
+ vm_page, vm_page_t, boolean_t (Unused).
+ * libnetworking/nfs/bootp_subr.c,
+ libnetworking/nfsclient/nfsdiskless.h:
+ Cosmetics from FreeBSD.
+ * libnetworking/rtems/rtems_bsdnet_internal.h:
+ Remove struct file (Unused).
+
+2009-02-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/socketvar.h: Remove struct file,
+ soo_ioctl, soo_select, soo_stat, getsock (Unused).
+
+2009-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+ * posix/include/sched.h, posix/src/sched_getparam.c:
+ Make sched_getparam() POSIX compliant.
+
+2009-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Don't install libcsupport/include/tar.h.
+
+2009-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/canonical-target-name.m4, aclocal/enable-posix.m4:
+ Remove comment referring to HPUX.
+
+2009-02-05 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/lib/ftpfs.c: Enable write and mount filesystem
+ with read-write access.
+
+2009-02-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * ftpd/ftpd.c: Change SIX_MONTHS to time_t.
+ * sapi/include/rtems/io.h: Move extern "C" brace after includes.
+
+2009-02-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_ppp.h: Eliminate pppattach, pppintr
+ (Unused).
+ * libnetworking/net/if_ppp.c: Eliminate pppintr (Unused).
+
+2009-02-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/rtems_dhcp.c: Remove #define KERNEL.
+ * libnetworking/Makefile.am, libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/rtems_dhcp.c:
+ Remove -D_COMPILING_BSD_KERNEL_ (Unused).
+ * libnetworking/Makefile.am: Remove -DKERNEL.
+ * libnetworking/rtems/rtems_mii_ioctl.c: Remove #undef KERNEL.
+ * libnetworking/nfs/bootp_subr.c: #include <sys/ucred.h>.
+ * libcsupport/include/sys/ioccom.h: Remove #define KERNEL,
+ #define _KERNEL.
+ * libfs/src/nfsclient/src/rpcio.c,
+ libfs/src/nfsclient/src/sock_mbuf.c,
+ libfs/src/nfsclient/src/xdr_mbuf.c: Remove #define KERNEL.
+ * libfs/src/dosfs/fat_file.h, libfs/src/dosfs/fat_fat_operations.h:
+ Move extern "C" brace after includes.
+
+2009-02-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/src/barrierattrdestroy.c, posix/src/barrierattrinit.c,
+ posix/src/cond.c, posix/src/condattrdestroy.c,
+ posix/src/condbroadcast.c, posix/src/conddefaultattributes.c,
+ posix/src/condsignal.c, posix/src/condtimedwait.c,
+ posix/src/condwait.c, posix/src/key.c, posix/src/keycreate.c,
+ posix/src/keydelete.c, posix/src/keyrundestructors.c,
+ posix/src/killinfo.c, posix/src/mqueue.c,
+ posix/src/mqueuecreatesupp.c, posix/src/mqueueopen.c,
+ posix/src/mqueuereceive.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c,
+ posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c,
+ posix/src/mqueueunlink.c, posix/src/mutex.c,
+ posix/src/mutexattrdestroy.c, posix/src/mutexinit.c,
+ posix/src/mutexlock.c, posix/src/mutextimedlock.c,
+ posix/src/mutextrylock.c, posix/src/pbarrier.c,
+ posix/src/prwlock.c, posix/src/prwlockrdlock.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/prwlocktryrdlock.c, posix/src/prwlocktrywrlock.c,
+ posix/src/prwlockwrlock.c, posix/src/psignalunblockthread.c,
+ posix/src/pspin.c, posix/src/pspinlock.c,
+ posix/src/pspintrylock.c, posix/src/pthread.c,
+ posix/src/pthreadattrdestroy.c, posix/src/pthreadcreate.c,
+ posix/src/pthreadinitthreads.c, posix/src/pthreadkill.c,
+ posix/src/pthreadonce.c, posix/src/pthreadsetschedparam.c,
+ posix/src/ptimer.c, posix/src/rwlockattrdestroy.c,
+ posix/src/rwlockattrinit.c, posix/src/semaphore.c,
+ posix/src/semaphorecreatesupp.c, posix/src/semdestroy.c,
+ posix/src/semopen.c, posix/src/semtrywait.c,
+ posix/src/semunlink.c, posix/src/semwait.c:
+ Eliminate TRUE/FALSE.
+
+2009-01-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/object.h: Maximum index if 0xffff not 0xff
+ when using 32-bit ids. This resulted in unlimited configurations not
+ being able to create more than 255 objects of a class.
+
+2009-01-29 Nickolay Semyonov-Kolchin <nbkolchin@gmail.com>
+
+ PR 1359/cpukit
+ * libcsupport/src/libio.c: rtems_libio_allocate:
+ rtems_libio_iop_freelist incorrectly zeroed on semaphore error. Now
+ checks error and does not modify anything until sure it has created
+ semaphore.
+
+2009-01-29 Gene Smith <gene.smith@siemens.com>
+
+ PR 1363/filesystem
+ * libfs/src/dosfs/fat.h: Fix issue where 32 bit values are not written
+ correctly in FAT f/s data.
+
+2009-01-29 Eric Norum <norume@aps.anl.gov>
+
+ PR 1364/cpukit
+ * libcsupport/src/gxx_wrappers.c: Fix compilation problems when
+ diagnostics enabled.
+
+2009-01-23 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/shell.c: Fix command line parsing of valid
+ characters.
+
+2009-01-21 Nickolay Kolchin <nbkolchin@gmail.com>
+ Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1357/cpukit
+ * rtems/src/tasks.c: Ensure creating a task with no ASR is honored.
+
+2009-01-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/tasks.c: Initialize event_condition to 0 just because.
+
+2009-01-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * librpc/src/xdr/xdr_float.c: M32C has no native float but GCC soft
+ float should be IEEE format.
+
+2009-01-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectextendinformation.c: Fold two paths into one.
+
+2009-01-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/src/barrier.c, rtems/src/barrierwait.c,
+ rtems/src/clocktodvalidate.c, rtems/src/dpmem.c,
+ rtems/src/msg.c, rtems/src/msgmp.c, rtems/src/msgqcreate.c,
+ rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/part.c,
+ rtems/src/partcreate.c, rtems/src/partmp.c, rtems/src/ratemon.c,
+ rtems/src/region.c, rtems/src/regionmp.c, rtems/src/rtemstimer.c,
+ rtems/src/sem.c, rtems/src/semcreate.c, rtems/src/semmp.c,
+ rtems/src/semobtain.c, rtems/src/signalsend.c, rtems/src/taskcreate.c,
+ rtems/src/taskinitusers.c, rtems/src/taskmode.c, rtems/src/taskmp.c,
+ rtems/src/taskresume.c, rtems/src/tasks.c,
+ rtems/src/tasksetpriority.c: Eliminate TRUE/FALSE.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/gxx_wrappers.c, posix/include/mqueue.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/inline/rtems/posix/barrier.inl,
+ posix/inline/rtems/posix/key.inl,
+ posix/inline/rtems/posix/mqueue.inl,
+ posix/inline/rtems/posix/rwlock.inl,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/inline/rtems/posix/spinlock.inl,
+ posix/inline/rtems/posix/timer.inl, posix/src/condget.c,
+ posix/src/mqueuenametoid.c, posix/src/mutexget.c,
+ posix/src/semaphorenametoid.c, posix/src/semopen.c,
+ sapi/src/itronapi.c, sapi/src/posixapi.c: Make changes necessary for
+ all tests to run on SPARC with 16-bit Ids. This required ensuring
+ that all POSIX and compilering binding code makes a distinction
+ between the public Id type (e.g. pthread_t, etc.) and the RTEMS
+ Object_Id type. All POSIX Object Get routines should not take the
+ POSIX Id type as the argument. Sixteen bit RTEMS Ids should be placed
+ into the 32-bits reserved by the POSIX API type in a uniform manner
+ now. This removed all assumptions that the external Id types in POSIX
+ and ITRON are the same as the internal Object Id type.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/inline/rtems/itron/semaphore.inl: THREAD_STATUS_PROXY_BLOCKING
+ should only be defined in multiprocessing configurations.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/key.h: Remove redundant prototypes for
+ inlines.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1351/cpukit
+ * sapi/include/confdefs.h: Mask off unlimited object bit before using
+ configured number in calculations.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/object.h,
+ score/src/objectallocatebyindex.c: Object index should be int.
+ Fix bug when index is negative.
+ * score/src/objectextendinformation.c: Do not allow maximum number
+ of allocated objects to exceed maximum representable in index
+ field of Object Id.
+ * score/src/objectgetisr.c: Use same code that is in _Objects_Get
+ to extract index field of Object Id.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/itronsys/types.h: ITRON types should follow native
+ integer size.
+
+2009-01-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/sys-rtems.c: Remove stray ';' introducing unreachable code.
+ * libcsupport/src/error.c: Remove hpux9 anachronism.
+
+2009-01-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am:
+ Install libnetworking/sys/uio.h if building for NEWLIB.
+ * libnetworking/Makefile.am:
+ Remove installation of libnetworking/sys/uio.h.
+ * libcsupport/Makefile.am: Build writev.c/readv.c for NEWLIB.
+ * libfs/src/imfs/imfs_eval.c: Add braces to suppress gcc warning on
+ empty 'else' block.
+
+2009-01-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/scandir.c: Use external scandir if available.
+
+2009-01-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/tftpDriver.c: Add __attribute__((unused)) to
+ unused function args.
+ * libnetworking/lib/tftpDriver.c: Use INADDR_ANY/INADDR_BROADCAST.
+ * libnetworking/netinet/in.h: Add in_addr_t.
+ Re-base "struct in_addr" on in_addr_t (mandated by POSIX).
+ * libnetworking/netinet/in.h: Remove struct ip_opts (unused).
+
+2009-01-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * ftpd/ftpd.c: Add __attribute__((unused)) to unused function args.
+ * libmisc/capture/capture-cli.c, libmisc/capture/capture.c,
+ libmisc/devnull/devnull.c, libmisc/monitor/mon-command.c,
+ libmisc/monitor/mon-config.c, libmisc/monitor/mon-driver.c,
+ libmisc/monitor/mon-extension.c, libmisc/monitor/mon-itask.c,
+ libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-network.c,
+ libmisc/monitor/mon-part.c, libmisc/monitor/mon-queue.c,
+ libmisc/monitor/mon-region.c, libmisc/monitor/mon-sema.c,
+ libmisc/monitor/mon-server.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/mon-task.c, libmisc/mw-fb/mw_fb.c,
+ libmisc/mw-fb/mw_uid.c, libmisc/serdbg/termios_printk.c,
+ libmisc/shell/cmds.c, libmisc/shell/fts.c, libmisc/shell/main_cp.c
+ libmisc/shell/main_id.c, libmisc/shell/main_logoff.c,
+ libmisc/shell/main_mount_nfs.c, libmisc/shell/main_pwd.c,
+ libmisc/shell/main_stackuse.c, libmisc/shell/main_tty.c,
+ libmisc/shell/main_whoami.c, libmisc/shell/main_wkspaceinfo.c,
+ libmisc/shell/shell_script.c, libmisc/shell/utils-cp.c,
+ libmisc/shell/utils-ls.c, libmisc/shell/verr.c,
+ libmisc/shell/verrx.c, libmisc/stackchk/check.c:
+ Add __attribute__((unused)) to unused function args.
+
+2009-01-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/blkdev.c, libblock/src/flashdisk.c,
+ libblock/src/nvdisk-sram.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk.c:
+ Add __attribute__((unused)) to unused function args.
+
+2009-01-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/src/_execve.c, posix/src/aio_cancel.c,
+ posix/src/aio_error.c, posix/src/aio_fsync.c,
+ posix/src/aio_read.c, posix/src/aio_return.c,
+ posix/src/aio_suspend.c, posix/src/aio_write.c, posix/src/alarm.c,
+ posix/src/devctl.c, posix/src/lio_listio.c, posix/src/mprotect.c,
+ posix/src/pbarrierwait.c, posix/src/psignal.c, posix/src/pthread.c,
+ posix/src/pthreadatfork.c, posix/src/sched_getparam.c,
+ posix/src/sched_getscheduler.c, posix/src/sched_setparam.c,
+ posix/src/sched_setscheduler.c, posix/src/timertsr.c.
+ posix/src/ualarm.c: Add __attribute__((unused)) to unused function
+ args.
+
+2009-01-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/aio.h, posix/src/aio_suspend.c: Make aio_suspend()
+ POSIX-compliant.
+
+2009-01-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * itron/src/acp_por.c, itron/src/act_cyc.c, itron/src/cal_por.c,
+ itron/src/can_wup.c, itron/src/chg_iXX.c, itron/src/clr_flg.c,
+ itron/src/cre_flg.c, itron/src/cre_mpf.c, itron/src/cre_mpl.c,
+ itron/src/cre_por.c, itron/src/def_alm.c, itron/src/def_cyc.c,
+ itron/src/def_int.c, itron/src/del_flg.c, itron/src/del_mpf.c,
+ itron/src/del_mpl.c, itron/src/del_por.c, itron/src/dis_int.c,
+ itron/src/ena_int.c, itron/src/fwd_por.c, itron/src/get_blf.c,
+ itron/src/get_blk.c, itron/src/get_tim.c, itron/src/pacp_por.c,
+ itron/src/pcal_por.c, itron/src/pget_blf.c, itron/src/pget_blk.c,
+ itron/src/pol_flg.c, itron/src/ref_alm.c, itron/src/ref_cyc.c,
+ itron/src/ref_flg.c, itron/src/ref_iXX.c, itron/src/ref_mpf.c,
+ itron/src/ref_mpl.c, itron/src/ref_por.c, itron/src/rel_blf.c,
+ itron/src/rel_blk.c, itron/src/ret_wup.c, itron/src/rpl_rdv.c,
+ itron/src/set_flg.c, itron/src/set_tim.c, itron/src/sta_tsk.c,
+ itron/src/tacp_por.c, itron/src/tcal_por.c, itron/src/tget_blf.c,
+ itron/src/tget_blk.c, itron/src/tslp_tsk.c, itron/src/twai_flg.c,
+ itron/src/wai_flg.c, itron/src/wup_tsk.c:
+ Add __attribute__((unused)) to unused function args.
+
+2008-12-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/src/threaddelayended.c, score/src/threadqextractfifo.c,
+ score/src/threadqextractpriority.c, score/src/threadqflush.c,
+ score/src/threadqtimeout.c:
+ Add __attribute__((unused)) to unused function args.
+ * score/src/threadblockingoperationcancel.c: Remove nested include.
+ Add __attribute__((unused)) to unused function args.
+
+2008-12-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/src/coremutexsurrender.c, score/src/coremsgsubmit.c,
+ score/src/coremsgbroadcast.c, score/src/corebarrierrelease.c:
+ Add __attribute__((unused)) to unused function args.
+ * score/inline/rtems/score/sysstate.inl:
+ Add __attribute__((unused)) to unused function args.
+ * rtems/src/timerserver.c: Remove _Timer_Server_body warnings.
+
+2008-12-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Require <errno.h>. Cleanup comments.
+ Remove check for <sys/errno.h>.
+
+2008-12-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/Makefile.am: Move src/malloc_p.h to *_SOURCES.
+ * rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/clock.h:
+ Eliminate TRUE/FALSE.
+
+2008-12-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libi2c/libi2c.c: Add missing initializers.
+ * libmisc/dummy/dummy.c: Add missing initializers.
+ * libnetworking/netinet/ip_icmp.c: Add missing initializers.
+ * libnetworking/netinet/ip_input.c: Add missing initializers.
+ * libnetworking/netinet/raw_ip.c: Add missing initializers.
+ * libnetworking/netinet/udp_usrreq.c: Add missing initializers.
+ * libnetworking/rtems/rtems_syscall.c: Add missing initializers.
+ * librpc/src/rpc/rtems_rpc.c: Add missing initializers.
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/nfs.c: Add missing initializers.
+ * libnetworking/netinet/ip_divert.c: Add missing initializers.
+ * libnetworking/netinet/if_ether.c: Add missing initializers.
+ * libfs/src/nfsclient/src/rpcio.c: Add missing initializers.
+ * libnetworking/netinet/in_proto.c: Add missing initializers.
+ * libnetworking/net/rtsock.c: Add missing initializers.
+ * libnetworking/libc/res_debug.c: Add missing initializers.
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/corebarrier.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/corespinlock.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/watchdog.inl:
+ Eliminate TRUE/FALSE.
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.c, libnetworking/net/if_ethersubr.c
+ libnetworking/net/if_loop.c, libnetworking/net/raw_cb.c,,
+ libnetworking/net/raw_usrreq.c, libnetworking/netinet/in.c,
+ libnetworking/netinet/in_pcb.c, libnetworking/netinet/ip_divert.c,
+ libnetworking/netinet/ip_input.c, libnetworking/netinet/ip_mroute.c,
+ libnetworking/netinet/ip_output.c, libnetworking/netinet/raw_ip.c,
+ libnetworking/netinet/tcp_debug.c, libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/tcp_output.c, libnetworking/netinet/tcp_subr.c,
+ libnetworking/netinet/tcp_timer.c, libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/netinet/udp_usrreq.c,
+ libnetworking/rtems/rtems_mii_ioctl_kern.c,
+ libnetworking/rtems/rtems_select.c,
+ libnetworking/rtems/rtems_socketpair.c,
+ libnetworking/rtems/rtems_syscall.c:
+ Include <errno.h> (POSIX,C99) instead of <sys/errno.h> (BSD'ism).
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/context.h,
+ score/include/rtems/score/corebarrier.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/corerwlock.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h,
+ score/include/rtems/score/isr.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/protectedheap.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/tod.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/wkspace.h:
+ Eliminate TRUE/FALSE.
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/src/apimutex.c, score/src/apimutexallocate.c,
+ score/src/apimutexlock.c, score/src/corebarrierwait.c,
+ score/src/coremsg.c, score/src/coremsgseize.c,
+ score/src/coremutexseize.c, score/src/coremutexsurrender.c,
+ score/src/coresemseize.c, score/src/coretod.c,
+ score/src/coretodset.c, score/src/heapfree.c,
+ score/src/heapsizeofuserarea.c, score/src/heapwalk.c,
+ score/src/interr.c, score/src/isr.c,
+ score/src/mpci.c, score/src/objectinitializeinformation.c,
+ score/src/objectmp.c, score/src/objectnametoid.c,
+ score/src/objectnametoidstring.c, score/src/objectsetname.c,
+ score/src/thread.c, score/src/threadblockingoperationcancel.c,
+ score/src/threadchangepriority.c, score/src/threadclearstate.c,
+ score/src/threadcreateidle.c, score/src/threaddispatch.c,
+ score/src/threadevaluatemode.c, score/src/threadhandler.c,
+ score/src/threadinitialize.c, score/src/threadmp.c,
+ score/src/threadqextractpriority.c,
+ score/src/threadqextractwithproxy.c,
+ score/src/threadqrequeue.c, score/src/threadready.c,
+ score/src/threadresettimeslice.c, score/src/threadrestart.c,
+ score/src/threadresume.c, score/src/threadrotatequeue.c,
+ score/src/threadsetstate.c, score/src/threadstartmultitasking.c,
+ score/src/threadsuspend.c, score/src/threadyieldprocessor.c,
+ score/src/timespecgreaterthan.c, score/src/timespecisvalid.c,
+ score/src/timespeclessthan.c, score/src/userextthreadcreate.c,
+ score/src/wkspace.c: Eliminate TRUE/FALSE.
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libi2c/libi2c.h: Change header guard to RTEMS conventions.
+ Add extern's.
+
+2008-12-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/canonical-target-name.m4: Remove tic4x.
+
+2008-12-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc_statistics_helpers.c: Use intptr_t not
+ ssize_t.
+
+2008-12-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/object.inl, score/src/objectgetbyindex.c:
+ Fix issues when using 16-bit object Ids.
+
+2008-12-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/itronsys/types.h: Derive ITRON ID type from Objects_Id
+ to avoid sizing mismatches.
+
+2008-12-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/dpmemcreate.c: Spacing.
+ * rtems/src/timerserver.c: Move error check to RTEMS_DEBUG. Cannot
+ happen under normal circumstances.
+
+2008-12-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/ide_part_table.c: Fixed NULL pointer access.
+ * libmisc/monitor/mon-command.c, libmisc/monitor/mon-editor.c,
+ libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h,
+ libmisc/shell/cmds.c: The list of registered monitor commands is now
+ private and only accessible via a lookup and iterate function.
+
+2008-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/regionmp.h, sapi/include/rtems/config.h,
+ sapi/src/exinit.c, score/Makefile.am,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h, score/src/objectmp.c: Eliminate
+ Object Handler Initialization routine since it was all for MP
+ configurations.
+ * score/src/object.c: Removed.
+
+2008-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/cmds.c: Revert back to public. Used to execute monitor
+ commands in test code.
+
+2008-12-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h:
+ Fixed incompatible return value.
+
+ * libmisc/cpuuse/cpuusagereport.c: Changed output format.
+
+ * libmisc/Makefile.am, libmisc/monitor/mon-editor.c: New file.
+
+ * libmisc/capture/capture-cli.c, libmisc/monitor/mon-command.c,
+ libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/monitor.h, libmisc/shell/cat_file.c,
+ libmisc/shell/cmds.c, libmisc/shell/internal.h,
+ libmisc/shell/main_help.c, libmisc/shell/shell.c,
+ libmisc/shell/shell.h, libmisc/shell/shell_cmdset.c,
+ libmisc/shell/shell_getchar.c, libmisc/shell/str2int.c: Various global
+ data is now read only. Added 'const' qualifier to many pointer
+ parameters. It is no longer possible to remove monitor commands.
+ Moved monitor line editor into a separate file to avoid unnecessary
+ dependencies.
+
+2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/extension.h, sapi/include/rtems/io.h,
+ sapi/src/exinit.c, sapi/src/extension.c, sapi/src/io.c,
+ score/include/rtems/score/mpci.h, score/include/rtems/score/object.h,
+ score/include/rtems/score/thread.h, score/include/rtems/score/tod.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/wkspace.h, score/src/coretod.c,
+ score/src/mpci.c, score/src/object.c, score/src/thread.c,
+ score/src/userext.c, score/src/wkspace.c: Convert SAPI manager and
+ SuperCore Handler initialization routines to directly pull parameters
+ from configuration table.
+
+2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/rtems/itron/config.h,
+ itron/include/rtems/itron/eventflags.h,
+ itron/include/rtems/itron/fmempool.h,
+ itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/port.h,
+ itron/include/rtems/itron/semaphore.h,
+ itron/include/rtems/itron/task.h,
+ itron/include/rtems/itron/vmempool.h, itron/src/eventflags.c,
+ itron/src/fmempool.c, itron/src/itroninittasks.c,
+ itron/src/itronsem.c, itron/src/mbox.c, itron/src/msgbuffer.c,
+ itron/src/port.c, itron/src/task.c, itron/src/vmempool.c,
+ sapi/src/itronapi.c: Convert ITRON manager initialization routines to
+ directly pull parameters from configuration table.
+
+2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/config.h: Fix typo.
+
+2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/barrier.h,
+ posix/include/rtems/posix/cond.h, posix/include/rtems/posix/key.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/psignal.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/ptimer.h,
+ posix/include/rtems/posix/rwlock.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/spinlock.h,
+ posix/include/rtems/posix/timer.h, posix/src/cond.c, posix/src/key.c,
+ posix/src/mqueue.c, posix/src/mutex.c, posix/src/pbarrier.c,
+ posix/src/prwlock.c, posix/src/psignal.c, posix/src/pspin.c,
+ posix/src/pthread.c, posix/src/pthreadinitthreads.c,
+ posix/src/ptimer.c, posix/src/semaphore.c, sapi/src/posixapi.c:
+ Convert POSIX manager initialization routines to directly pull
+ parameters from configuration table.
+
+2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/barrier.h,
+ rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h, rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h,
+ rtems/src/barrier.c, rtems/src/dpmem.c, rtems/src/msg.c,
+ rtems/src/part.c, rtems/src/ratemon.c, rtems/src/region.c,
+ rtems/src/rtemstimer.c, rtems/src/sem.c, rtems/src/tasks.c,
+ sapi/src/rtemsapi.c: Convert manager initialization routines to
+ directly pull parameters from configuration table. Eliminate empty
+ routines sportted.
+ * rtems/src/intr.c: Removed.
+
+2008-12-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove include/rtems/stdint.h.
+ * include/rtems/stdint.h: Remove.
+ * configure.ac: Require stdint.h.
+ * score/include/rtems/score/timespec.h: #include <stdint.h>,
+ #include <time.h>. Remove bogus #include <sys/types.h>.
+
+2008-12-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-config.c: Configuration table entry
+ work_space_size was not removed.
+
+2008-12-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libblock/src/bdbuf.c, libmisc/capture/capture-cli.c,
+ libmisc/capture/capture.c, libmisc/mw-fb/mw_uid.c,
+ rtems/include/rtems/rtems/support.h, score/Makefile.am,
+ score/include/rtems/score/tod.h, score/src/coretod.c,
+ score/src/coretodtickle.c: Eliminate all public use of TOD conversion
+ routines. Eliminate _TOD_Microseconds_per_tick and let every place
+ use the field directly from the Configuration Table. This required
+ moving some methods from macros to bodies.
+ * score/src/coretodmsecstoticks.c, score/src/coretodtickspersec.c,
+ score/src/coretodusectoticks.c: New files.
+
+2008-12-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/__times.c, posix/src/adjtime.c,
+ posix/src/clockgetres.c, posix/src/sysconf.c,
+ rtems/src/clockgettickspersecond.c, rtems/src/clockgettod.c,
+ rtems/src/clockset.c, rtems/src/clocktodvalidate.c,
+ score/src/timespecfromticks.c, score/src/timespectoticks.c,
+ score/src/ts64toticks.c: More case converted to use configuration
+ table entry not _TOD_Microseconds_per_tick.
+
+2008-12-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libgnat/adasupp.c: Add helper method so Ada binding does not
+ reference _TOD_Microseconds_per_tick.
+
+2008-12-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/config.h: Remove commented out lines. Add macro
+ for rtems_configuration_get_nanoseconds_per_tick().
+
+2008-12-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/rtems/itron/itronapi.h, libmisc/capture/capture.c,
+ libmisc/monitor/mon-config.c, libmisc/monitor/mon-driver.c,
+ libmisc/monitor/mon-itask.c, libmisc/monitor/mon-mpci.c,
+ posix/include/rtems/posix/config.h,
+ posix/include/rtems/posix/posixapi.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/rtemsapi.h, rtems/src/taskinitusers.c,
+ sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/init.h, sapi/src/exinit.c, sapi/src/itronapi.c,
+ sapi/src/posixapi.c, sapi/src/rtemsapi.c, score/src/isr.c,
+ score/src/thread.c, score/src/threadcreateidle.c,
+ score/src/threadstackallocate.c, score/src/threadstackfree.c,
+ score/src/wkspace.c: Eliminate pointers to API configuration tables
+ in the main configuration table. Reference the main configuration
+ table and the API configuration tables directly using the confdefs.h
+ version rather than obtaining a pointer to it. This eliminated some
+ variables, a potential fatal error, some unnecessary default
+ configuration structures. Overall, about a 4.5% reduction in the code
+ size for minimum and hello on the SPARC.
+
+2008-12-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/types.h: Fix incorrect type name.
+
+2008-12-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/realloc.c, rtems/include/rtems/rtems/region.h,
+ rtems/src/regioncreate.c, rtems/src/regionextend.c,
+ rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c,
+ rtems/src/regionmp.c, rtems/src/regionresizesegment.c,
+ sapi/include/rtems/config.h, score/include/rtems/score/heap.h,
+ score/include/rtems/score/protectedheap.h, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapallocatealigned.c,
+ score/src/heapextend.c, score/src/heapresizeblock.c,
+ score/src/heapsizeofuserarea.c, score/src/pheapallocate.c,
+ score/src/pheapallocatealigned.c, score/src/pheapextend.c,
+ score/src/pheapgetblocksize.c, score/src/pheapresizeblock.c: Change
+ sizes of heap/region and allocated objects in heap to intptr_t so
+ they can be larger than a single allocatable object (e.g. size_t).
+
+2008-12-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/src/chg_pri.c, itron/src/cre_tsk.c, itron/src/rot_rdq.c,
+ posix/Makefile.am, posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/priority.h, posix/src/mutex.c,
+ score/include/rtems/score/priority.h: Run all tests successfully with
+ maxixum number of priorities as 16 instead of 256. This was done by
+ temporarily modifying the score priority.h maximum. This allowed
+ testing of all API code to ensure that it worked properly with a
+ reduced number of priorities. Most modifications were to switch from
+ hard-coded maximum to using the SuperCore variable based upon
+ configured number.
+ * posix/src/mutexdefaultattributes.c: Removed.
+
+2008-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/address.inl: Make offset arguments intptr_t
+ not int32_t.
+
+2008-12-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_arp.h, libnetworking/net/route.h:
+ Include <sys/socket.h> to make header self contained.
+
+2008-12-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * zlib/zconf.h: #include <stdint.h> instead of <rtems/stdint.h>.
+ * score/cpu/arm/rtems/score/types.h,
+ score/cpu/avr/rtems/score/types.h,
+ score/cpu/bfin/rtems/score/types.h,
+ score/cpu/c4x/rtems/score/types.h,
+ score/cpu/h8300/rtems/score/types.h,
+ score/cpu/i386/rtems/score/types.h,
+ score/cpu/lm32/rtems/score/types.h,
+ score/cpu/m32c/rtems/score/types.h,
+ score/cpu/m32r/rtems/score/types.h,
+ score/cpu/m68k/rtems/score/types.h,
+ score/cpu/mips/rtems/score/types.h,
+ score/cpu/nios2/rtems/score/types.h,
+ score/cpu/no_cpu/rtems/score/types.h,
+ score/cpu/powerpc/rtems/score/types.h,
+ score/cpu/sh/rtems/score/types.h,
+ score/cpu/sparc/rtems/score/types.h,
+ score/cpu/unix/rtems/score/types.h:
+ #include <stdint.h> instead of <rtems/stdint.h>.
+
+2008-12-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/readdir.c, libmd/md4.h, libmd/md5.h,
+ libmisc/mw-fb/mw_fb.h, libnetworking/net/ppp_defs.h,
+ libnetworking/net/slcompress.c, libnetworking/rtems/bsdnet/_types.h,
+ libnetworking/sys/sysctl.h, librpc/include/rpc/types.h, pppd/pppd.h,
+ rtems/include/rtems/rtems/types.h, score/include/rtems/system.h:
+ #include <stdint.h> instead of <rtems/stdint.h>.
+
+2008-12-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/prog-cc.m4: Use -r instead of -Wl,-r to build *.rels.
+ * libcsupport/src/strlcat.c: Add prototypes.
+ * libmisc/Makefile.am: Remove stray "\".
+
+2008-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/types.h, rtems/src/ratemongetstatistics.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c,
+ rtems/src/ratemonreportstatistics.c,
+ score/include/rtems/score/thread.h, score/src/coretodgetuptime.c:
+ Make all Thread and Period Statistics use publicly defined types. Do
+ not leak the SuperCore Timestamp type through the APIs.
+
+2008-12-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Makefile.am, score/preinstall.am,
+ score/include/rtems/score/timespec.h,
+ score/include/rtems/score/timestamp.h: Add 64-bit implementation of
+ SuperCore Timestamps. Tested on PowerPC/psim and SPARC/sis.
+ * score/include/rtems/score/timestamp64.h, score/src/ts64addto.c,
+ score/src/ts64divide.c, score/src/ts64dividebyinteger.c,
+ score/src/ts64equalto.c, score/src/ts64getnanoseconds.c,
+ score/src/ts64getseconds.c, score/src/ts64greaterthan.c,
+ score/src/ts64lessthan.c, score/src/ts64set.c,
+ score/src/ts64settozero.c, score/src/ts64subtract.c,
+ score/src/ts64toticks.c, score/src/ts64totimespec.c: New files.
+
+2008-12-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libblock/src/bdbuf.c: Fix typo having crept in during
+ boolean->bool transition.
+
+2008-12-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/cpu/unix/cpu.c: Add prototypes, eliminate nested externs.
+
+2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/__times.c, libmisc/cpuuse/cpuusagereport.c,
+ libmisc/cpuuse/cpuusagereset.c, posix/src/clockgettime.c,
+ posix/src/pthread.c, posix/src/timersettime.c,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/src/clockgetsecondssinceepoch.c, rtems/src/clockgetuptime.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c,
+ rtems/src/ratemonreportstatistics.c, rtems/src/taskwakewhen.c,
+ rtems/src/timerfirewhen.c, rtems/src/timerserver.c,
+ rtems/src/timerserverfirewhen.c, score/Makefile.am,
+ score/preinstall.am, score/include/rtems/score/thread.h,
+ score/include/rtems/score/tod.h, score/src/coretod.c,
+ score/src/coretodget.c, score/src/coretodgetuptime.c,
+ score/src/coretodset.c, score/src/coretodtickle.c,
+ score/src/threaddispatch.c, score/src/threadinitialize.c: Add
+ SuperCore handler Timestamp to provide an opaque class for the
+ representation and manipulation of uptime, time of day, and the
+ difference between two timestamps. By using SuperCore Timestamp, it
+ is clear which methods and APIs really have to be struct timespec and
+ which can be in an optimized native format.
+ * score/include/rtems/score/timestamp.h,
+ score/src/coretodgetuptimetimespec.c: New files.
+
+2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/nfsclient/src/nfs.c: Use
+ rtems_clock_get_seconds_since_epoch() from public API.
+
+2008-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/Makefile.am: Remove RTEMS_RELLDFLAGS.
+ * aclocal/prog-cc.m4: Add RTEMS_RELLDFLAGS hack.
+ * libfs/src/nfsclient/src/dirutils.c: #include <limits.h>.
+
+2008-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/clock.h: #include <sys/time.h>
+ * librpc/include/rpc/rpcent.h: #include <rpc/types.h>.
+ * librpc/include/rpc/xdr.h: #include <rtems/bsd/sys/cdefs.h>.
+
+2008-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/devfs/devfs.h: Add missing "extern"s.
+ * libfs/src/imfs/imfs.h: Add missing "extern"s
+ * libfs/src/pipe/pipe.h: Add missing "extern"s.
+ Add extern "C" {}.
+
+2008-12-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/cpu/arm/cpu.c, score/cpu/avr/cpu.c, score/cpu/bfin/cpu.c,
+ score/cpu/c4x/cpu.c, score/cpu/h8300/cpu.c, score/cpu/i386/cpu.c,
+ score/cpu/lm32/cpu.c, score/cpu/m32c/cpu.c, score/cpu/m32r/cpu.c,
+ score/cpu/mips/cpu.c, score/cpu/nios2/cpu.c, score/cpu/no_cpu/cpu.c,
+ score/cpu/sh/cpu.c, score/cpu/sparc/cpu.c, score/cpu/unix/cpu.c:
+ Fix typo.
+
+2008-12-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/timespec.h: Remove unnecessary includes.
+ Fix typo.
+ * posix/include/rtems/posix/time.h, score/src/coretodget.c,
+ score/src/coretodgetuptime.c: Add required include files which
+ were formerly included from timespec.h
+
+2008-12-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/pipe/fifo.c: Do not include .inl files directly. Use .h
+ files with kernel visibility violated until functionality exposed.
+
+2008-12-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Check for functions in newlib.
+ * posix/Makefile.am: Unconditionally compile files which now
+ are in newlib.
+ * libcsupport/Makefile.am: Unconditionally compile files which now
+ are in newlib.
+
+2008-12-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/src/execl.c, posix/src/execle.c,
+ posix/src/execlp.c, posix/src/execv.c,
+ posix/src/execve.c, posix/src/execvp.c,
+ posix/src/sleep.c, posix/src/usleep.c:
+ Compile contents conditionally.
+
+2008-12-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/closedir.c, libcsupport/src/getcwd.c,
+ libcsupport/src/isatty.c, libcsupport/src/opendir.c,
+ libcsupport/src/readdir.c, libcsupport/src/readdir_r.c,
+ libcsupport/src/rewinddir.c, libcsupport/src/seekdir.c,
+ libcsupport/src/telldir.c, libcsupport/src/ttyname.c:
+ Compile contents conditionally.
+
+2008-12-04 Jukka Pietarinen <jukka.pietarinen@mrf.fi>
+
+ * configure.ac, librpc/src/xdr/xdr_float.c, score/cpu/Makefile.am: Add
+ Lattice Mico32 support.
+
+2008-12-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1348/cpukit
+ * rtems/src/ratemonperiod.c: Properly handle period statistics after
+ cpu usage information is reset while a period is running.
+
+2008-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1347/cpukit
+ * rtems/include/rtems/rtems/timer.h, rtems/src/rtemstimer.c,
+ rtems/src/timerreset.c, rtems/src/timerserver.c,
+ rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c,
+ score/Makefile.am, score/include/rtems/score/watchdog.h: Rework Timer
+ Server to ensure that the context allows for blocking, allocating
+ memory, and acquiring semaphores and mutexes.
+ * score/src/watchdogadjusttochain.c: New file.
+
+2008-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1346/cpukit
+ * rtems/include/rtems/rtems/ratemon.h: Sense of rate monotonic
+ statistics nanoseconds or ticks granularity conditional is backwards.
+
+2008-12-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/pipe/fifo.c: Actually disable initializing pipes as
+ requested in confdefs.h.
+
+2008-12-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Add disable of pipes by default since they
+ use resources which are otherwise not accounted for. Eventually the
+ resources will have to be properly configured.
+
+2008-12-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/Makefile.am: Add stub for devide filesystem for unix port.
+ * libfs/src/devfs/devfs_unixstub.c: New file.
+
+2008-12-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/workspace.c: Revert ssize_t patch.
+
+2008-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Makefile.am, score/include/rtems/score/watchdog.h: Add
+ _Watchdog_Report and _Watchdog_Report_chain as debug assist routines.
+ They are NOT to be used in directives.
+ * score/src/watchdogreport.c, score/src/watchdogreportchain.c:
+ New files.
+
+2008-11-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/watchdogadjust.c, score/src/watchdogtickle.c: Spacing.
+
+2008-11-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1341/cpukit
+ * sapi/include/confdefs.h: The following macros were missing
+ the _Configure_From_workspace() wrapper on their size estimate:
+ + CONFIGURE_INTERRUPT_STACK_MEMORY
+ + CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API
+ + CONFIGURE_INTERRUPT_VECTOR_TABLE
+ + CONFIGURE_MEMORY_FOR_STATIC_EXTENSIONS
+ In addition, there was a duplicate definition of
+ CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API.
+
+2008-11-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add AC_CHECK_FUNC's to check functions migrating
+ into newlib.
+
+2008-11-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/psignal.h: Fix typo in converting method
+ from macro to static inline.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am, posix/include/rtems/posix/psignal.h: Add stubs for
+ gettimer() and setitimer().
+ * posix/src/getitimer.c, posix/src/setitimer.c: New files.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, posix/Makefile.am: Comment out including
+ files which contain routines which are now provided by the newlib
+ posix subdirectory. Document a few which come from the unix directory.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1340/cpukit
+ * sapi/inline/rtems/chain.inl: Add rtems_chain_initialize to public
+ chain API.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/heap.h,
+ score/include/rtems/score/protectedheap.h,
+ score/include/rtems/score/wkspace.h, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapallocatealigned.c,
+ score/src/heapextend.c, score/src/heapresizeblock.c,
+ score/src/heapsizeofuserarea.c, score/src/pheapgetblocksize.c,
+ score/src/wkspace.c: Revert use of ssize_t. This type is not
+ guaranteed to be able to represent a positive number greater than the
+ size of a single allocatable object. We needed a type that is able to
+ represent the size of a pool of multiple allocatable objects or
+ potentially nearly all memory.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Do not
+ think about running init/fini on AVR. We do not know what mechanism
+ it uses but this is not it.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1306/cpukit
+ * posix/inline/rtems/posix/priority.inl: Eliminate hard coded numbers
+ in favor of existing macros.
+
+2008-11-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am: Add dummy vfork() implementation.
+ * posix/src/vfork.c: New file.
+
+2008-11-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1336/cpukit
+ * sapi/inline/rtems/chain.inl: Add rtems_chain_prepend_unprotected and
+ rtems_chain_append_unprotected.
+
+2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am: Add getrusage().
+ * libcsupport/src/getrusage.c: New file.
+
+2008-11-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/timespecaddto.c: Fix typo.
+
+2008-11-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/ttyname.c: Change third parameter of ttyname to be
+ size_t instead of int.
+
+2008-11-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * librpc/src/xdr/xdr_float.c: Add M32C, M32R, and Blackfin.
+
+2008-11-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadhandler.c: M32R uses different name for init.
+
+2008-11-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am: Add _execve() so we can use newlib posix support
+ directory and eliminate code in RTEMS.
+ * posix/src/_execve.c: New file.
+
+2008-11-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1333/cpukit
+ * libcsupport/include/rtems/termiostypes.h: Typo on type name -- should
+ be rtems_device_minor_number.
+
+2008-10-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1331/networking
+ * libmisc/shell/shell.c, telnetd/check_passwd.c, telnetd/telnetd.c,
+ telnetd/telnetd.h: Improve comments and explanation of options to
+ rtems_telnetd_initialize. Add extra newline to login sequence from
+ shell.
+
+2008-10-14 Tim Cussins <timcussins@eml.cc>
+
+ PR 1330/cpukit
+ * libcsupport/src/free.c: Should print begin field not start field.
+
+2008-10-14 Wei Shen <cquark@gmail.com>
+
+ * Makefile.am, preinstall.am, libcsupport/src/mknod.c,
+ libcsupport/src/open.c, libcsupport/src/pipe.c, libfs/Makefile.am,
+ libfs/preinstall.am, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c,
+ libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_initsupp.c,
+ libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_stat.c,
+ libfs/src/imfs/memfile.c: Initial commit of POSIX pipe support.
+ * libfs/src/imfs/imfs_fifo.c, libfs/src/pipe/fifo.c,
+ libfs/src/pipe/pipe.c, libfs/src/pipe/pipe.h: New files.
+
+2008-10-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/printk.c: Addresses can be larger than integers
+ so use long for %p formats.
+ * score/inline/rtems/score/address.inl: Offsets can be positive or
+ negative, so use int32_t. Also do math with intptr_t since there
+ are cases where the number of bits in an address do not equal the
+ number of bits in an integer.
+ * score/inline/rtems/score/heap.inl: Offsets can be positive or
+ negative, so use int32_t.
+
+2008-10-03 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * configure.ac: Add m32r.
+ * libcsupport/src/newlibc_exit.c: For some odd reason, the fini
+ symbol for the m32r in C needs an extra leading _.
+
+2008-10-02 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libnetworking/rtems/rtems_glue.c: Copy nothing in
+ rtems_bsdnet_parse_driver_name() if namep is NULL.
+
+ * include/rtems/status-checks.h: Added prefix "RTEMS" for all macros.
+ Doxygen style comments. Cleanup.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/cpu/Makefile.am: Add new M32R port. It is just a beginning but
+ the BSP is functional enough to initialize and shutdown RTEMS.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * configure.ac: Revert trash committed. Shell builds with m32c now.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * configure.ac, score/cpu/Makefile.am: Initial addition of M32C port.
+ This is still a work in process but most tests do run on simulator.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/utils-cp.c: Do not put a 64K buffer on the stack.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/priority.inl: Use simple integer as loop
+ counter.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-monitor.c, rtems/include/rtems/rtems/types.h: Do
+ not have fp context type when no hardware or software floating point
+ is available.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc_statistics_helpers.c,
+ libcsupport/src/realloc.c, rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/workspace.c, sapi/include/confdefs.h,
+ score/include/rtems/score/heap.h,
+ score/include/rtems/score/protectedheap.h,
+ score/include/rtems/score/wkspace.h, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapallocatealigned.c,
+ score/src/heapextend.c, score/src/heapresizeblock.c,
+ score/src/heapsizeofuserarea.c, score/src/pheapgetblocksize.c,
+ score/src/wkspace.c: Change size_t to ssize_t on all Heap, Workspace
+ and Region calls. On 16-bit architectures, size_t can be 16-bits
+ which would limit sizes to 64K.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_cp.c, libmisc/shell/main_ls.c,
+ libmisc/shell/main_mv.c, libmisc/shell/main_netstats.c,
+ libmisc/shell/main_rm.c, libmisc/shell/shell_script.c: Newlib >
+ 1.16.0 requires __need_getopt_newlib to be defined to get visibility
+ on the reentrancy extensions.
+
+2008-10-01 Gene Smith <gene.smith@siemens.com>
+
+ PR 1328/cpukit
+ * libmisc/shell/main_mdump.c, libmisc/shell/main_mwdump.c: Fix printing
+ of more than 256 bytes.
+
+2008-09-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libi2c/libi2c.h: Added definitions for asynchronous read and write IO
+ commands.
+
+2008-09-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1316/cpukit
+ * score/src/coremsgbroadcast.c: Give error when message is too large
+ like when sending a message. This was the documented behavior.
+
+2008-09-26 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/lib/rtems_bsdnet_ntp.c: Final resolution of this
+ "small" port number change.
+
+2008-09-25 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/lib/rtems_bsdnet_ntp.c: Revert previous patch.
+
+2008-09-25 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/lib/rtems_bsdnet_ntp.c: Revert previous patch.
+
+2008-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/imfs/deviceio.c: Eliminate duplicate implementation.
+
+2008-09-24 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1326/cpukit
+ * libi2c/libi2c.c: Use int for return value when negative values
+ possible.
+
+2008-09-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/ftpfs.c: Use ssize_t for read retval (Fix
+ comparision of unsigned < 0).
+
+2008-09-23 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/lib/rtems_bsdnet_ntp.c: Let TCP/IP stack pick port
+ rather than hard coding selection.
+
+2008-09-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * include/rtems/bspIo.h, libcsupport/Makefile.am: Add genchark() for
+ polled debug input from the same device as printk().
+ * libcsupport/src/getchark.c: New file.
+
+2008-09-22 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/version.m4: Bump RTEMS_API to 4.10.
+ Bump _RTEMS_VERSION to 4.9.99.0.
+
+2008-09-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_mallocinfo.c, libmisc/shell/main_wkspaceinfo.c:
+ Include information on whether C Program Heap and RTEMS Workspace are
+ separate.
+
+2008-09-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/Makefile.am: Do not build nfsclient if no networking.
+
+2008-09-18 Miao Yan <yanmiaobest@gmail.com>
+
+ * libfs/src/devfs/devclose.c, libfs/src/devfs/devfs_eval.c,
+ libfs/src/devfs/devioctl.c, libfs/src/devfs/devopen.c,
+ libfs/src/devfs/devread.c, libfs/src/devfs/devwrite.c: Fix warnings.
+
+2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Doxyfile.in, rtems/mainpage.h, score/include/rtems/system.h: Move to
+ generating Doxygen for more of CPU Kit.
+ * rtems/Doxyfile, score/Doxyfile, score/mainpage.h: Removed.
+
+2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * configure.ac: Add generated Doxyfile which can process entire set of
+ preinstalled .h files.
+ * Doxyfile.in: New file.
+
+2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Rename STACK_CHECKER_ON to more appropriate
+ CONFIGURE_STACK_CHECKER_ENABLED.
+
+2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libfs/src/devfs/devclose.c, libfs/src/devfs/devfs_init.c,
+ libfs/src/devfs/devfs_show.c, libfs/src/devfs/devioctl.c,
+ libfs/src/devfs/devopen.c, libfs/src/devfs/devread.c,
+ libfs/src/devfs/devwrite.c: Fix warnings.
+
+2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/free.c, libcsupport/src/malloc.c,
+ libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h,
+ libcsupport/src/malloc_sbrk_helpers.c,
+ libcsupport/src/malloc_statistics_helpers.c,
+ libcsupport/src/malloc_walk.c, libcsupport/src/mallocfreespace.c,
+ libcsupport/src/mallocinfo.c, libcsupport/src/realloc.c,
+ libcsupport/src/rtems_memalign.c, sapi/include/confdefs.h,
+ score/inline/rtems/score/thread.inl: Add support for optionally
+ having a unified work area. In other words, the RTEMS Workspace and C
+ Program Heap are the same pool of memory.
+
+2008-09-17 Miao Yan <yanmiaobest@gmail.com>
+
+ * Makefile.am, preinstall.am, libcsupport/Makefile.am,
+ libcsupport/include/rtems/libcsupport.h,
+ libcsupport/include/rtems/libio.h, libcsupport/src/base_fs.c,
+ libcsupport/src/libio_init.c, libcsupport/src/newlibc_exit.c,
+ libcsupport/src/newlibc_init.c, libcsupport/src/sync.c,
+ libfs/Makefile.am, libfs/src/imfs/deviceio.c,
+ sapi/include/confdefs.h: Merge GSOC project code to add simple device
+ only filesystem (devfs), optionally completely drop out filesystem,
+ and to clean up disabling newlib reentrancy support. This dropped 17K
+ from the minimum.exe for sparc/sis and arm/rtl22xx_t now has a 15K
+ code space.
+ * libcsupport/src/__usrenv.c, libcsupport/src/newlibc_reent.c,
+ libfs/src/devfs/devclose.c, libfs/src/devfs/devfs.h,
+ libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devfs_init.c,
+ libfs/src/devfs/devfs_mknod.c, libfs/src/devfs/devfs_node_type.c,
+ libfs/src/devfs/devfs_show.c, libfs/src/devfs/devioctl.c,
+ libfs/src/devfs/devopen.c, libfs/src/devfs/devread.c,
+ libfs/src/devfs/devstat.c, libfs/src/devfs/devwrite.c,
+ libfs/src/imfs/deviceerrno.c: New files.
+ * libcsupport/src/newlibc.c: Removed.
+
+2008-09-16 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Revert previous patch. Does not apply to
+ head.
+
+2008-09-16 Gene Smith <gene.smith@siemens.com>
+
+ PR 564/cpukit
+ * sapi/include/confdefs.h: Fix incorrect name. Was missed in an earlier
+ renaming sweep.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/types.h: Do not define rtems_boolean,
+ rtems_single, rtems_double unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac, aclocal/canonical-target-name.m4: Readd NIOS2 and TI
+ C4x. Accidentally not done on 4.9 branch. :(
+ * score/cpu/c4x/.cvsignore, score/cpu/c4x/ChangeLog,
+ score/cpu/c4x/Makefile.am, score/cpu/c4x/cpu.c,
+ score/cpu/c4x/cpu_asm.S, score/cpu/c4x/irq.c,
+ score/cpu/c4x/preinstall.am, score/cpu/c4x/rtems/asm.h,
+ score/cpu/c4x/rtems/score/c4x.h, score/cpu/c4x/rtems/score/cpu.h,
+ score/cpu/c4x/rtems/score/cpu_asm.h,
+ score/cpu/c4x/rtems/score/types.h, score/cpu/c4x/rtems/tic4x/c4xio.h,
+ score/cpu/nios2/.cvsignore, score/cpu/nios2/ChangeLog,
+ score/cpu/nios2/Makefile.am, score/cpu/nios2/cpu.c,
+ score/cpu/nios2/cpu_asm.S, score/cpu/nios2/irq.c,
+ score/cpu/nios2/preinstall.am, score/cpu/nios2/rtems/asm.h,
+ score/cpu/nios2/rtems/score/cpu.h,
+ score/cpu/nios2/rtems/score/cpu_asm.h,
+ score/cpu/nios2/rtems/score/nios2.h,
+ score/cpu/nios2/rtems/score/types.h: New files.
+
+2008-09-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac, aclocal/canonical-target-name.m4,
+ score/cpu/Makefile.am: Remove TI C4x and NIOS2 ports from 4.9 branch.
+ * score/cpu/c4x/.cvsignore, score/cpu/c4x/ChangeLog,
+ score/cpu/c4x/Makefile.am, score/cpu/c4x/cpu.c,
+ score/cpu/c4x/cpu_asm.S, score/cpu/c4x/irq.c,
+ score/cpu/c4x/preinstall.am, score/cpu/c4x/rtems/asm.h,
+ score/cpu/c4x/rtems/score/c4x.h, score/cpu/c4x/rtems/score/cpu.h,
+ score/cpu/c4x/rtems/score/cpu_asm.h,
+ score/cpu/c4x/rtems/score/types.h, score/cpu/c4x/rtems/tic4x/c4xio.h,
+ score/cpu/nios2/.cvsignore, score/cpu/nios2/ChangeLog,
+ score/cpu/nios2/Makefile.am, score/cpu/nios2/cpu.c,
+ score/cpu/nios2/cpu_asm.S, score/cpu/nios2/irq.c,
+ score/cpu/nios2/preinstall.am, score/cpu/nios2/rtems/asm.h,
+ score/cpu/nios2/rtems/score/cpu.h,
+ score/cpu/nios2/rtems/score/cpu_asm.h,
+ score/cpu/nios2/rtems/score/nios2.h,
+ score/cpu/nios2/rtems/score/types.h: Removed.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Add debug information for
+ per task allocations.
+ * score/src/objectextendinformation.c: Do not allocate memory for name
+ tables because we do not use name tables any longer.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadinitialize.c: _Stack_Ensure_minimum was being called
+ here and in _Thread_Stack_Allocate.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/libio_.h, libcsupport/src/libio_sockets.c,
+ libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos.h,
+ libfs/src/imfs/deviceio.c, libmisc/monitor/mon-monitor.c,
+ libmisc/monitor/mon-object.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/monitor.h, libmisc/stackchk/internal.h,
+ rtems/inline/rtems/rtems/part.inl, score/include/rtems/system.h,
+ score/include/rtems/score/bitfield.h, score/src/mpci.c,
+ score/src/objectextendinformation.c, score/src/threadmp.c: Remove
+ extraneous spaces.
+
+2008-09-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/auth.c, pppd/ccp.c, pppd/chap.c, pppd/ipcp.c, pppd/lcp.c,
+ pppd/options.c, pppd/upap.c: Add missing initializers.
+
+2008-09-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * httpd/webrom.c: Add missing initializers.
+ * libblock/include/rtems/bdbuf.h, libblock/include/rtems/diskdevs.h,
+ libblock/include/rtems/ramdisk.h: Use "#include <..>" to include
+ public headers.
+
+2008-09-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/in_cksum_arm.h:
+ Stop using old-style function definitions.
+ * configure.ac: Remove score/cpu/arm/thumb/Makefile.
+
+2008-09-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * itron/include/itronsys/types.h: Eliminate "boolean".
+ * libmisc/monitor/mon-prmisc.c: Add missing initializers.
+
+2008-09-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/ramdisk.h,
+ libfs/src/nfsclient/proto/mount_prot.x: Convert to Unix file format.
+
+2008-09-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/include/clockdrv.h: The Shared Memory Driver no longer
+ requires the special IOCTL in Clock_control. This was a hack which
+ has existed since before the Classic API Timer Manager was
+ implemented. All implementations of and references to Clock_control
+ were removed.
+
+2008-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/corebarrier.c, score/src/corebarrierrelease.c,
+ score/src/corebarrierwait.c, score/src/coremsg.c,
+ score/src/coremsgbroadcast.c, score/src/coremsgclose.c,
+ score/src/coremsgflush.c, score/src/coremsgflushsupp.c,
+ score/src/coremsgflushwait.c, score/src/coremsginsert.c,
+ score/src/coremsgseize.c, score/src/coremsgsubmit.c,
+ score/src/corerwlock.c, score/src/coresem.c,
+ score/src/coresemflush.c, score/src/coresemseize.c,
+ score/src/coresemsurrender.c, score/src/corespinlock.c,
+ score/src/threadblockingoperationcancel.c,
+ score/src/threadqenqueue.c: Remove unnecessary include of mpci.h.
+
+2008-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/msgmp.c, rtems/src/msgqtranslatereturncode.c,
+ rtems/src/semmp.c, rtems/src/semtranslatereturncode.c: Correct
+ confusion over SuperCore proxy blocking status and Classic API proxy
+ blocking status constants.
+
+2008-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectgetinfo.c: Correct for multiprocessor systems when
+ all object instances within a particular class are remote.
+
+2008-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/assocnamebad.c: Correct file name in message.
+
+2008-09-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Make sure
+ CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER is defined to 0 in single
+ processor configurations.
+
+2008-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Account for needed a Classic API Timer when
+ using the Shared Memory MPCI driver.
+
+2008-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/mpci.h,
+ score/inline/rtems/score/threadmp.inl, score/src/mpci.c: Eliminate
+ dependencies between MP .h files.
+
+2008-09-05 Eric Norum <norume@aps.anl.gov>
+
+ * libfs/src/nfsclient/src/rpcio.c: Correct breakage introduced by Joel
+ removing asserts with side-effects.
+
+2008-09-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * sapi/include/rtems/config.h,
+ sapi/inline/rtems/chain.inl,
+ sapi/inline/rtems/extension.inl,
+ sapi/src/debug.c,
+ sapi/src/extension.c,
+ sapi/src/ioregisterdriver.c: Convert to "bool".
+ * rtems/src/clocktodvalidate.c,
+ rtems/src/intrbody.c,
+ rtems/src/msgmp.c,
+ rtems/src/msgqcreate.c,
+ rtems/src/msgqreceive.c,
+ rtems/src/partmp.c,
+ rtems/src/regionmp.c,
+ rtems/src/semmp.c,
+ rtems/src/signalsend.c,
+ rtems/src/taskcreate.c,
+ rtems/src/taskmode.c,
+ rtems/src/taskmp.c,
+ rtems/src/tasks.c,
+ rtems/src/timerserver.c,
+ rtems/src/workspace.c: Convert to "bool".
+ * rtems/inline/rtems/rtems/asr.inl,
+ rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/barrier.inl,
+ rtems/inline/rtems/rtems/dpmem.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/tasks.inl,
+ rtems/inline/rtems/rtems/timer.inl: Convert to "bool".
+ * rtems/include/rtems/rtems/asr.h,
+ rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/object.h,
+ rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/support.h: Convert to "bool".
+ * score/src/corebarrierwait.c,
+ score/src/coremsg.c,
+ score/src/coremsginsert.c,
+ score/src/coremsgseize.c,
+ score/src/coremsgsubmit.c,
+ score/src/coremutexseize.c,
+ score/src/corerwlockobtainread.c,
+ score/src/corerwlockobtainwrite.c,
+ score/src/coresemseize.c,
+ score/src/corespinlockwait.c,
+ score/src/heapfree.c,
+ score/src/heapresizeblock.c,
+ score/src/heapsizeofuserarea.c,
+ score/src/heapwalk.c,
+ score/src/interr.c,
+ score/src/objectinitializeinformation.c,
+ score/src/objectmp.c,
+ score/src/objectnametoid.c,
+ score/src/objectsetname.c,
+ score/src/pheapextend.c,
+ score/src/pheapfree.c,
+ score/src/pheapgetblocksize.c,
+ score/src/pheapresizeblock.c,
+ score/src/pheapwalk.c,
+ score/src/threadchangepriority.c,
+ score/src/threaddispatch.c,
+ score/src/threadevaluatemode.c,
+ score/src/threadinitialize.c,
+ score/src/threadloadenv.c,
+ score/src/threadqextractpriority.c,
+ score/src/threadqextractwithproxy.c,
+ score/src/threadrestart.c,
+ score/src/threadresume.c,
+ score/src/threadstart.c,
+ score/src/timespecgreaterthan.c,
+ score/src/timespecisvalid.c,
+ score/src/timespeclessthan.c,
+ score/src/userextthreadbegin.c,
+ score/src/userextthreadcreate.c,
+ score/src/wkspace.c: Convert to "bool".
+ * score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/corebarrier.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/corespinlock.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/objectmp.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/threadmp.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/watchdog.inl:
+ Convert to "bool".
+ * score/include/rtems/debug.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/corebarrier.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/corerwlock.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/corespinlock.h,
+ score/include/rtems/score/heap.h,
+ score/include/rtems/score/interr.h,
+ score/include/rtems/score/isr.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/protectedheap.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/timespec.h,
+ score/include/rtems/score/tod.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/wkspace.h:
+ Convert to "bool".
+ * score/src/object.c: Stop using old-style function definitions.
+
+2008-09-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/semaphore.h,
+ itron/inline/rtems/itron/eventflags.inl,
+ itron/inline/rtems/itron/fmempool.inl,
+ itron/inline/rtems/itron/mbox.inl,
+ itron/inline/rtems/itron/msgbuffer.inl,
+ itron/inline/rtems/itron/port.inl,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/inline/rtems/itron/task.inl,
+ itron/inline/rtems/itron/vmempool.inl,
+ itron/src/cre_tsk.c, itron/src/sta_tsk.c,
+ itron/src/task.c, itron/src/trcv_mbf.c,
+ itron/src/trcv_mbx.c, itron/src/tsnd_mbf.c,
+ itron/src/twai_sem.c: Convert to "bool".
+
+2008-09-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/key.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/priority.h,
+ posix/include/rtems/posix/psignal.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/timer.h: Convert to "bool".
+ * posix/inline/rtems/posix/barrier.inl,
+ posix/inline/rtems/posix/cond.inl,
+ posix/inline/rtems/posix/key.inl,
+ posix/inline/rtems/posix/mqueue.inl,
+ posix/inline/rtems/posix/mutex.inl,
+ posix/inline/rtems/posix/priority.inl,
+ posix/inline/rtems/posix/pthread.inl,
+ posix/inline/rtems/posix/rwlock.inl,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/inline/rtems/posix/spinlock.inl,
+ posix/inline/rtems/posix/timer.inl: Convert to "bool".
+ * posix/src/cancel.c,
+ posix/src/condsignalsupp.c,
+ posix/src/condtimedwait.c,
+ posix/src/condwaitsupp.c,
+ posix/src/keyrundestructors.c,
+ posix/src/killinfo.c,
+ posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesendsupp.c,
+ posix/src/mqueuetimedreceive.c,
+ posix/src/mqueuetimedsend.c,
+ posix/src/mutexlocksupp.c,
+ posix/src/mutextimedlock.c,
+ posix/src/prwlocktimedrdlock.c,
+ posix/src/prwlocktimedwrlock.c,
+ posix/src/psignal.c,
+ posix/src/psignalchecksignal.c,
+ posix/src/psignalclearsignals.c,
+ posix/src/psignalunblockthread.c,
+ posix/src/pthread.c,
+ posix/src/pthreadcreate.c,
+ posix/src/pthreadkill.c,
+ posix/src/pthreadsigmask.c,
+ posix/src/semaphorewaitsupp.c,
+ posix/src/semtimedwait.c,
+ posix/src/setcancelstate.c,
+ posix/src/setcanceltype.c,
+ posix/src/sigtimedwait.c,
+ posix/src/testcancel.c,
+ posix/src/timerinserthelper.c,
+ posix/src/timersettime.c,
+ posix/src/timertsr.c: Convert to "bool".
+
+2008-09-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/ftpfs.c: Use bool instead of boolean.
+ * libi2c/libi2c.c, libi2c/libi2c.h: Use bool instead of boolean.
+ * libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_eval.c,
+ libfs/src/dosfs/msdos_format.c, libfs/src/dosfs/msdos_misc.c,
+ libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/ioman.c:
+ Use "bool" instead of "rtems_boolean|boolean".
+ * libfs/src/imfs/imfs_eval.c: Change "done" to bool.
+ * libfs/src/nfsclient/src/xdr_mbuf.c: Stop using old-style
+ definitions.
+
+2008-09-03 Cindy Cicalese <cicalese@mitre.org>
+
+ * libmisc/shell/shell.c: FALSE accidentally changed to true in switch
+ to bool type.
+
+2008-09-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Add CONFIGURE_BSP_PREREQUISITE_DRIVERS and
+ CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS.
+
+2008-09-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1301/cpukit
+ * sapi/src/debug.c: Let _Debug_Is_enabled return TRUE|FALSE.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/timerdrv.h,
+ libcsupport/include/rtems/libcsupport.h,
+ libcsupport/src/chdir.c, libcsupport/src/chmod.c,
+ libcsupport/src/chown.c, libcsupport/src/free.c,
+ libcsupport/src/link.c, libcsupport/src/lstat.c,
+ libcsupport/src/malloc.c, libcsupport/src/malloc_deferred.c,
+ libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h,
+ libcsupport/src/mount.c, libcsupport/src/newlibc.c,
+ libcsupport/src/open.c, libcsupport/src/readlink.c,
+ libcsupport/src/readv.c, libcsupport/src/rmdir.c,
+ libcsupport/src/stat.c, libcsupport/src/termios.c,
+ libcsupport/src/unlink.c, libcsupport/src/unmount.c,
+ libcsupport/src/utime.c, libcsupport/src/writev.c:
+ Convert using "bool".
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/auth_none.c, librpc/src/rpc/authunix_prot.c,
+ librpc/src/rpc/bindresvport.c, librpc/src/rpc/clnt_generic.c,
+ librpc/src/rpc/clnt_udp.c, librpc/src/rpc/getrpcent.c,
+ librpc/src/rpc/netname.c, librpc/src/rpc/netnamer.c,
+ librpc/src/rpc/pmap_clnt.c, librpc/src/rpc/pmap_getmaps.c,
+ librpc/src/rpc/pmap_getport.c, librpc/src/rpc/pmap_prot.c,
+ librpc/src/rpc/pmap_prot2.c, librpc/src/rpc/rpc_callmsg.c,
+ librpc/src/rpc/svc_run.c, librpc/src/xdr/xdr.c,
+ librpc/src/xdr/xdr_array.c, librpc/src/xdr/xdr_float.c,
+ librpc/src/xdr/xdr_reference.c:
+ Stop using old-style function definitions.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/capture/capture-cli.c, libmisc/capture/capture.c,
+ libmisc/capture/capture.h:
+ Convert to using "bool".
+ * libmisc/serdbg/serdbg.c, libmisc/serdbg/serdbg.h,
+ libmisc/serdbg/serdbgcnf.h, libmisc/serdbg/serdbgio.c,
+ libmisc/serdbg/termios_printk.c:
+ Convert to using "bool".
+ * libmisc/shell/main_logoff.c, libmisc/shell/shell.c,
+ libmisc/shell/shell.h:
+ Convert to using "bool".
+ * libmisc/monitor/mon-command.c, libmisc/monitor/mon-config.c,
+ libmisc/monitor/mon-driver.c, libmisc/monitor/mon-extension.c,
+ libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c,
+ libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-network.c,
+ libmisc/monitor/mon-object.c, libmisc/monitor/mon-part.c,
+ libmisc/monitor/mon-queue.c, libmisc/monitor/mon-region.c,
+ libmisc/monitor/mon-sema.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/mon-task.c, libmisc/monitor/monitor.h:
+ Convert to using "bool".
+ * libmisc/stackchk/check.c, libmisc/stackchk/internal.h,
+ libmisc/stackchk/stackchk.h:
+ Convert to using "bool".
+ * libblock/include/rtems/bdbuf.h, libblock/src/bdbuf.c,
+ libblock/src/diskdevs.c, libblock/src/ide_part_table.c,
+ libblock/src/ramdisk.c, libblock/src/show_bdbuf.c:
+ Convert to using "bool".
+ * libblock/src/nvdisk-sram.c: Add missing HAVE_CONFIG_H.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * httpd/asp.c, httpd/balloc.c, httpd/default.c,
+ httpd/emfdb.c, httpd/form.c, httpd/handler.c,
+ httpd/md5c.c, httpd/security.c, httpd/sock.c,
+ httpd/socket.c, httpd/sym.c, httpd/uemf.c, httpd/um.c,
+ httpd/webmain.c, httpd/webs.c, httpd/websuemf.c:
+ Stop using old-style function definitions.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/addr2ascii.c,
+ libnetworking/libc/ascii2addr.c,
+ libnetworking/libc/base64.c,
+ libnetworking/libc/gethostbyht.c,
+ libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/getnetbyht.c,
+ libnetworking/libc/getservbyport.c,
+ libnetworking/libc/getservent.c,
+ libnetworking/libc/herror.c,
+ libnetworking/libc/inet_addr.c,
+ libnetworking/libc/inet_lnaof.c,
+ libnetworking/libc/inet_netof.c,
+ libnetworking/libc/inet_network.c,
+ libnetworking/libc/inet_ntoa.c,
+ libnetworking/libc/inet_ntop.c,
+ libnetworking/libc/inet_pton.c,
+ libnetworking/libc/linkaddr.c,
+ libnetworking/libc/map_v4v6.c,
+ libnetworking/libc/res_comp.c,
+ libnetworking/libc/res_debug.c,
+ libnetworking/libc/res_init.c,
+ libnetworking/libc/res_mkquery.c,
+ libnetworking/libc/res_query.c,
+ libnetworking/nfs/bootp_subr.c,
+ libnetworking/rtems/rtems_glue.c:
+ Stop using old-style function definitions.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/if_ether.c,
+ libnetworking/netinet/igmp.c,
+ libnetworking/netinet/in.c,
+ libnetworking/netinet/in_pcb.c,
+ libnetworking/netinet/ip_icmp.c,
+ libnetworking/netinet/ip_input.c,
+ libnetworking/netinet/ip_mroute.c,
+ libnetworking/netinet/ip_output.c,
+ libnetworking/netinet/raw_ip.c,
+ libnetworking/netinet/tcp_debug.c,
+ libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/tcp_output.c,
+ libnetworking/netinet/tcp_subr.c,
+ libnetworking/netinet/tcp_timer.c,
+ libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/netinet/udp_usrreq.c:
+ Stop using old-style function definitions.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/tcp_var.h: Fix broken declaration of
+ tcp_trace().
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/res_comp.c,
+ libnetworking/netinet/igmp.c,
+ libnetworking/netinet/in_cksum.c,
+ libnetworking/netinet/in_proto.c,
+ libnetworking/netinet/tcp_debug.c,
+ libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/tcp_output.c,
+ libnetworking/netinet/tcp_timer.c:
+ Remove BSD "Add clause" (From FreeBSD).
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_ethersubr.c, libnetworking/net/if_loop.c,
+ libnetworking/net/if_ppp.c, libnetworking/net/ppp_tty.c,
+ libnetworking/net/radix.c, libnetworking/net/raw_cb.c,
+ libnetworking/net/raw_usrreq.c, libnetworking/net/route.c,
+ libnetworking/net/rtsock.c, libnetworking/net/slcompress.c:
+ Stop using old-style function definitions.
+
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/kern/uipc_domain.c, libnetworking/kern/uipc_mbuf.c
+ libnetworking/kern/uipc_socket.c, libnetworking/kern/uipc_socket2.c:
+ Stop using old-style function definitions.
+
+2008-08-31 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/timerdrv.h: Rename timer driver methods to follow
+ RTEMS programming conventions.
+
+2008-08-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am, rtems/src/tasksetpriority.c: Improve comments and
+ wrapping.
+
+2008-08-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * ftpd/ftpd.c: Fix prototype.
+
+2008-08-27 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/shell.c, libmisc/shell/shell.h:
+ Split out rtems_shell_get_prompt() so it can be overridden by the
+ user.
+ * libmisc/shell/shell_getprompt.c: New file.
+
+2008-08-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/getproto.c, libnetworking/libc/getprotoent.c,
+ libnetworking/libc/getprotoname.c,
+ libnetworking/libc/getservbyname.c,
+ libnetworking/libc/inet_makeaddr.c, libnetworking/libc/recv.c,
+ libnetworking/libc/send.c: Stop using old-style
+ function-definitions.
+
+2008-08-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/fsmount/fsmount.c: Convert to using bool.
+
+2008-08-26 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libbcsupport/src/printk_plugin.c: properly terminate va_list
+ processing with va_end
+
+2008-08-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/auth.c, pppd/ccp.c, pppd/chap.c, pppd/chat.c,
+ pppd/demand.c, pppd/fsm.c, pppd/ipcp.c, pppd/lcp.c,
+ pppd/magic.c, pppd/options.c, pppd/rtemsmain.c,
+ pppd/sys-rtems.c, pppd/upap.c, pppd/utils.c:
+ Stop using old-style function-definitions.
+
+2008-08-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/bdbuf.c, libblock/src/diskdevs.c,
+ libblock/src/ide_part_table.c, libblock/src/ramdisk.c:
+ s/rtems_boolean/bool/g.
+
+2008-08-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmd/md4.c, libmd/md5.c:
+ Stop using old-style function-definitions.
+ * libcsupport/src/closedir.c, libcsupport/src/getcwd.c,
+ libcsupport/src/mount.c, libcsupport/src/newlibc.c,
+ libcsupport/src/opendir.c, libcsupport/src/readdir.c,
+ libcsupport/src/scandir.c:
+ Stop using old-style function-definitions.
+
+2008-08-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/malloc_boundary.c: Use %zi to print size_t.
+ * libmisc/capture/capture.c, libmisc/shell/fts.c:
+ Stop using old-style function-definitions.
+
+2008-08-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libblock/include/rtems/bdbuf.h, libblock/include/rtems/diskdevs.h,
+ libblock/src/bdbuf.c, libblock/src/blkdev.c, libblock/src/diskdevs.c,
+ libblock/src/ramdisk.c: Eliminate sign mismatch warnings.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-network.c: Use memset instead of bzero.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/internal.h: Don't include "config.h".
+ Adjust header guard.
+ * libmisc/shell/cmp-ls.c, libmisc/shell/err.c,
+ libmisc/shell/errx.c, libmisc/shell/filemode.c,
+ libmisc/shell/fts.c, libmisc/shell/main_cp.c,
+ libmisc/shell/main_ls.c, libmisc/shell/main_mv.c,
+ libmisc/shell/main_rm.c, libmisc/shell/print-ls.c,
+ libmisc/shell/pwcache.c, libmisc/shell/shellconfig.c,
+ libmisc/shell/utils-cp.c, libmisc/shell/utils-ls.c,
+ libmisc/shell/verr.c, libmisc/shell/verrx.c,
+ libmisc/shell/vis.c, libmisc/shell/vwarn.c,
+ libmisc/shell/vwarnx.c, libmisc/shell/warn.c,
+ libmisc/shell/warnx.c: Include "config.h".
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-network.c, libmisc/monitor/mon-part.c,
+ libmisc/monitor/mon-region.c, libmisc/monitor/mon-sema.c:
+ Include "config.h".
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/main_ifconfig.c: Use memset instead of bzero.
+ * ftpd/ftpd.c: Don't use annonymous unions.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/flashdisk.c: Remove bool, true, false.
+
+2008-08-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/dummy/dummy.c: Add missing initializers.
+ * score/src/threadinitialize.c: Change type of loop counter.
+
+2008-08-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/error.c, libmisc/dummy/dummy.c,
+ rtems/src/rtemsobjectgetapiclassname.c,
+ rtems/src/rtemsobjectgetapiname.c: Add 0 for missing initializers.
+
+2008-08-20 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * include/rtems/status-checks.h: Fixed integer conversion warning.
+
+2008-08-20 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Abort if stdbool.h is not c99 compliant.
+
+2008-08-20 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/pppd.h: Use stdbool.h. Remove local bool.
+
+2008-08-20 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add AC_HEADER_STDBOOL.
+ * libblock/src/nvdisk.c: Remove bool, true, false (unused, clashes
+ with C99/POSIX).
+
+2008-08-19 Cedric Aubert <cedric_aubert@yahoo.fr>
+
+ PR 500/misc
+ * libcsupport/src/termios.c: Avoid potential buffer overflow.
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libnetworking/kern/kern_sysctl.c, libnetworking/libc/res_debug.c: Fix
+ warnings.
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libfs/src/nfsclient/src/nfs.c, libfs/src/nfsclient/src/rpcio.c:
+ Remove some warnings. Using ASSERT/assert macros confuses gcc who is
+ unsure actions take place. More importantly if you ever compiled with
+ NDEBUG set wrong, intended actions would not occur. Likely I did not
+ catch all of these.
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * httpd/uemf.h: Add empty braces to macro.
+
+2008-08-19 Tim FitzGeorge <tim.fitzgeorge@astrium.eads.net>
+
+ PR 1296/cpukit.
+ * posix/src/timersettime.c: POSIX timers use incorrect repeat interval.
+ This patch fixes the following problems in timer_settime: 1) Uses
+ value.it_interval for repeat period. 2) Corrects test for incorrect
+ value of it_value.tv_nsec (should reject 1000000000).
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/threadmp.inl: Add include of
+ rtems/score/mpci.h and remove extern.
+
+2008-08-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/clockdrv.h: Add Clock_Exit prototype.
+
+2008-08-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/inline/rtems/rtems/asr.inl,
+ rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/barrier.inl,
+ rtems/inline/rtems/rtems/dpmem.inl,
+ rtems/inline/rtems/rtems/event.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/tasks.inl,
+ rtems/inline/rtems/rtems/timer.inl,
+ Add header guard to force indirect inclusion.
+ * score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/corebarrier.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/corerwlock.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/corespinlock.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/objectmp.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/threadmp.inl,
+ score/inline/rtems/score/threadq.inl,
+ score/inline/rtems/score/tod.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/watchdog.inl,
+ score/inline/rtems/score/wkspace.inl:
+ Add header guard to force indirect inclusion.
+ * posix/inline/rtems/posix/barrier.inl,
+ posix/inline/rtems/posix/cond.inl,
+ posix/inline/rtems/posix/key.inl,
+ posix/inline/rtems/posix/mqueue.inl,
+ posix/inline/rtems/posix/mutex.inl,
+ posix/inline/rtems/posix/priority.inl,
+ posix/inline/rtems/posix/pthread.inl,
+ posix/inline/rtems/posix/rwlock.inl,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/inline/rtems/posix/spinlock.inl,
+ posix/inline/rtems/posix/timer.inl:
+ Add header guard to force indirect inclusion.
+ * itron/inline/rtems/itron/eventflags.inl,
+ itron/inline/rtems/itron/fmempool.inl,
+ itron/inline/rtems/itron/intr.inl,
+ itron/inline/rtems/itron/mbox.inl,
+ itron/inline/rtems/itron/msgbuffer.inl,
+ itron/inline/rtems/itron/network.inl,
+ itron/inline/rtems/itron/port.inl,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/inline/rtems/itron/sysmgmt.inl,
+ itron/inline/rtems/itron/task.inl,
+ itron/inline/rtems/itron/time.inl,
+ itron/inline/rtems/itron/vmempool.inl:
+ Add header guard to force indirect inclusion.
+ * sapi/inline/rtems/chain.inl:
+ Add header guard to force indirect inclusion.
+
+2008-08-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/object.h: Use _RTEMS_RTEMS_OBJECT_H as
+ header guard.
+
+2008-08-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/in_cksum_arm.h, score/cpu/arm/cpu.c
+ score/cpu/h8300/rtems/score/cpu.h: Add missing prototypes.
+
+2008-08-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/lib/ftpfs.c, libnetworking/libc/inet_ntoa.c,
+ libnetworking/libc/rcmd.c, libnetworking/nfs/bootp_subr.c,
+ libnetworking/rtems/rtems_glue.c,
+ libnetworking/rtems/rtems_malloc_mbuf.c,
+ libnetworking/rtems/rtems_showicmpstat.c, libnetworking/sys/malloc.h:
+ Fix some warnings.
+
+2008-08-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/libcsupport.h, libcsupport/src/scandir.c,
+ libmisc/cpuuse/cpuusagereset.c, libmisc/monitor/mon-monitor.c,
+ libmisc/serdbg/serdbg.c, libmisc/serdbg/serdbg.h,
+ libnetworking/netinet/in_cksum_powerpc.h, shttpd/compat_rtems.h: Fix
+ warnings.
+
+2008-08-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/rtems/itron/task.h, itron/src/def_cyc.c,
+ itron/src/task.c, libcsupport/src/newlibc_exit.c,
+ libcsupport/src/sync.c, libfs/src/imfs/imfs_fchmod.c,
+ posix/include/rtems/posix/pthread.h, posix/src/pthread.c,
+ posix/src/sysconf.c, rtems/include/rtems/rtems/tasks.h,
+ rtems/src/tasks.c, score/include/rtems/score/stack.h,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/thread.inl, score/src/threadhandler.c: Fix
+ various nested-externs warnings.
+
+2008-08-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/src/newlibc.c: Split libc_init()
+ into a separate file to avoid linkage dependencies on newlibc.c which
+ in turn pulls in fclose() and other C library methods.
+ * libcsupport/src/newlibc_init.c: New file.
+
+2008-08-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/prog-cc.m4: Add -Wnested-externs.
+
+2008-08-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/ppp_tty.c: Remove bogus local decl of
+ termios_baud_to_number(int).
+ * libnetworking/netinet/in_cksum_i386.h: Add missing prototype.
+ * libnetworking/netinet/in_cksum.c: Add missing prototypes.
+ * librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/svc_tcp.c:
+ Add missing prototypes.
+
+2008-08-16 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/librtemsNfs.h: Add missing prototype.
+
+2008-08-16 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/prog-cc.m4: Add -Wimplicit-function-declaration
+ -Wstrict-prototypes to RTEMS_CFLAGS.
+
+2008-08-15 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1297/cpukit
+ * posix/src/prwlockinit.c: Fix NULL attribute pointer handling.
+
+2008-08-14 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/status.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/object.h: Removed extraneous commas.
+
+2008-08-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/msgmp.h: Fix MP code missed by Sebastian.
+
+2008-08-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libmisc/monitor/monitor.h, rtems/include/rtems/rtems/tasks.h,
+ score/include/rtems/score/thread.h, score/src/threadreset.c,
+ score/src/threadrestart.c, score/src/threadstart.c: New type
+ Thread_Entry_numeric_type for numeric arguments in thread entry
+ functions with at least one numeric argument.
+
+2008-08-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/sysstate.h,
+ score/inline/rtems/score/sysstate.inl, score/src/thread.c: Make
+ _System_state_Is_multiprocessing unused when multiprocessing is not
+ enabled. Saves one more variable from single processor configuration.
+
+2008-08-07 Chris Johns <chrisj@rtems.org>
+
+ * libcsupport/src/_rename_r.c: Fixed return code bug. Add a check
+ to see if the 'to' path was a directory and removed the directory.
+
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added the mv
+ command.
+
+ * libmisc/shell/main_mv.c, libmisc/shell/pathnames-mv.h: New.
+
+2008-08-06 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/bdbuf.c: PR1272. Fixed similar possible issues in
+ the new bdbuf code.
+
+2008-08-06 Brett Swimley <brett.swimley@aedbozeman.com>
+
+ PR 1192/filesystem
+ * libblock/src/diskdevs.c: PR1192. Update the disktap pointer
+ after the realloc.
+
+2008-08-06 Till Straumann <strauman@slac.stanford.edu>
+
+ * libblock/src/diskdevs.c: PR1269. Delete the semaphore rather
+ than release it.
+
+2008-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 537/bsps
+ * libcsupport/include/rtems/libcsupport.h, libcsupport/src/newlibc.c,
+ libcsupport/src/no_libc.c, libcsupport/src/unixlibc.c: Eliminate
+ vestiges of ticks_per_timeslice controlling newlib reentrancy. The
+ parameter was ignored in libc_init().
+
+2008-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 741/networking
+ * libmisc/dummy/dummy.c: Add dummy network configuration.
+
+2008-08-05 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/include/rtems/rtems/sem.h, rtems/src/semobtain.c:
+ Changed option set type to rtems_option.
+
+ * score/src/objectgetinfo.c: Check return value of
+ _Objects_API_maximum_class().
+
+ * libmisc/monitor/mon-mpci.c, libmisc/monitor/monitor.h,
+ rtems/include/rtems/rtems/message.h, rtems/src/msgmp.c,
+ rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c,
+ rtems/src/msgqcreate.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c,
+ rtems/src/msgqurgent.c, score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/mpci.h, score/include/rtems/score/thread.h,
+ score/inline/rtems/score/coremsg.inl, score/src/coremsg.c,
+ score/src/coremsgbroadcast.c, score/src/coremsgseize.c,
+ score/src/coremsgsubmit.c:
+ Removed parameters of _Message_queue_Allocate(). Changed option set
+ type to rtems_option. Changed type of maximum message and packet size
+ to size_t. Changed the input buffer type for message send functions to
+ "const void *". Changed the pointer to the second return argument in
+ the thread wait information to a union. This union can contain a
+ pointer to an immutable or a mutable object. This is somewhat fragile.
+ An alternative would be to add a third pointer for immutable objects,
+ but this would increase the structure size.
+
+2008-08-05 Xudong Guan <xudong.guan@criticalsoftware.com>
+
+ PR 1212/cpukit
+ * rtems/src/taskmode.c, score/src/threadtickletimeslice.c: Time slicing
+ will not happen if the task mode is changed from a non-timeslicing
+ mode to timeslicing mode if it is done by the executing thread (e.g.
+ in its task body). This change includes sp44 to demonstrate the
+ problem and verify the correction.
+
+2008-08-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c: Fix
+ warnings.
+
+2008-08-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1265/cpukit
+ * score/include/rtems/score/object.h,
+ score/src/objectallocatebyindex.c: Rename index argument to avoid
+ warning when rtems.h and string.h are included at the same time by
+ user code.
+
+2008-08-03 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/tftpDriver.c: Add prototypes.
+ * pppd/rtemsmain.c: Add prototypes.
+ * zlib/crc32.c: Add prototypes.
+
+2008-08-02 Chris Johns (chrisj@rtems.org>
+
+ * libblock/include/rtems/blkdev.h: Remove count and start from
+ rtems_blkdev_request. Add RTEMS_BLKDEV_START_BLOCK macro.
+
+ * libblock/src/bdbuf.c: Add read ahead blocks always consecutive
+ comment. Change count to bufnum and remove start references. Sort
+ the transfer list so blocks are consecutive where possible.
+
+ * libblock/src/blkdev.c, libblock/src/nvdisk.c,
+ libblock/src/ramdisk.c: Change count to bufnum and remove start
+ references.
+
+2008-08-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * telnetd/telnetd.c: Add missing prototypes.
+ Remove unused local declations.
+
+2008-08-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/gethostbydns.c,
+ libnetworking/libc/gethostbyht.c,
+ libnetworking/libc/gethostbynis.c,
+ libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/getnetbydns.c,
+ libnetworking/libc/getnetbynis.c,
+ libnetworking/libc/getnetnamadr.c,
+ libnetworking/libc/nsap_addr.c,
+ libnetworking/libc/res_debug.c,
+ libnetworking/libc/res_send.c: Add missing prototypes.
+
+2008-08-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libi2c/libi2c.c, libi2c/libi2c.h: Add missing prototypes.
+ * libmd/md4.c, libmd/md5.c: Add missing prototypes.
+ * libmisc/monitor/mon-command.c, libmisc/shell/filemode.c,
+ libmisc/shell/shell_script.c: Add missing prototypes.
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/nfsclient/src/xdr_mbuf.c: Add prototypes.
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/clnt.h: Cleanup.
+ * librpc/include/rpc/svc.h: Cleanup.
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/xdr/xdr_mem.c librpc/src/xdr/xdr_rec.c
+ librpc/src/xdr/xdr_sizeof.c, librpc/src/xdr/xdr_stdio.c:
+ Misc. ansifications. Add prototypes.
+
+2008-08-01 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/msgqsend.c, rtems/src/msgqurgent.c: Fix typos.
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/getrpcport.c: Misc. ansifications.
+ * librpc/src/rpc/getrpcent.c: Remove stray local decls.
+ Misc. ansifications.
+ * librpc/src/rpc/clnt_perror.c: Misc. ansifications.
+ * librpc/src/rpc/get_myaddress.c: Misc. ansifications.
+ * librpc/src/rpc/svc_auth_unix.c: Misc. ansifications.
+ * librpc/src/rpc/pmap_clnt.c: Remove stray clnt_perror().
+ * librpc/src/rpc/clnt_tcp.c: Add missing prototypes.
+ * librpc/src/rpc/clnt_raw.c: Add missing prototypes.
+ * librpc/src/rpc/clnt_udp.c: Add missing prototypes.
+ * librpc/src/rpc/svc_auth.c: Add missing prototypes.
+ * librpc/src/rpc/svc_raw.c: Add missing prototypes.
+ * librpc/src/rpc/svc_tcp.c: Add missing prototypes.
+ * librpc/src/rpc/svc_udp.c: Add missing prototypes.
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/svc.c: Add missing prototypes.
+ * librpc/src/xdr/xdr_rec.c: Remove register vars.
+ * librpc/src/xdr/xdr_mem.c: Misc. ansifications.
+ * librpc/src/rpc/svc_tcp.c: Misc. ansifications.
+ * librpc/src/rpc/clnt_tcp.c: Misc. ansifications.
+ * librpc/src/rpc/svc_raw.c: Misc. ansifications.
+ * librpc/src/xdr/xdr_rec.c: Misc. ansifications.
+ * librpc/src/rpc/svc_simple.c: Add missing prototypes.
+ * librpc/src/rpc/rtems_portmapper.c: Add missing prototypes.
+ * librpc/src/rpc/rpcdname.c: Add missing prototypes.
+ * librpc/src/rpc/rpc_prot.c: Misc. ansifications.
+ * librpc/src/rpc/pmap_rmt.c: Misc. ansifications.
+ * librpc/src/rpc/clnt_simple.c: Misc. ansifications.
+ * librpc/src/rpc/auth_unix.c: Misc. ansifications.
+ Add missing prototypes.
+ * librpc/src/rpc/rtime.c, librpc/src/rpc/svc_udp.c:
+ Misc. ansifications.
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/auth_unix.h, librpc/include/rpc/pmap_clnt.h,
+ librpc/include/rpc/pmap_prot.h, librpc/include/rpc/pmap_rmt.h,
+ librpc/include/rpc/rpc_msg.h, librpc/include/rpc/svc_auth.h,
+ librpc/include/rpcsvc/yppasswd.x, librpc/src/rpc/netnamer.c,
+ librpc/src/rpc/svc_udp.c, librpc/src/xdr/xdr_rec.c,
+ librpc/include/rpcsvc/ypclnt.h, librpc/include/rpcsvc/yp_prot.h:
+ Eliminate __P().
+
+2008-08-01 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/thread.h: Add missing prototype.
+ * score/inline/rtems/score/thread.inl: Add missing prototypes.
+ * libfs/src/nfsclient/src/nfs.c: Add missing prototype.
+ * libnetworking/lib/ftpfs.c, libnetworking/libc/rcmd.c,
+ libnetworking/netinet/in_cksum_m68k.h,
+ libnetworking/netinet/ip_divert.c, libnetworking/rtems/ftpfs.h,
+ libnetworking/rtems/mkrootfs.c, libnetworking/rtems/mkrootfs.h,
+ libnetworking/rtems/rtems_showroute.c: Add missing prototypes.
+ * itron/include/itronsys/types.h: Add missing prototype.
+ * ftpd/ftpd.c: Fix broken prototype.
+ * libblock/include/rtems/bdbuf.h, libblock/src/bdbuf.c:
+ Add missing prototypes.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/shell/main_rm.c: sys/mount.h is not available when networking
+ is disabled but luckily it is not even needed to compile.
+
+2008-07-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/main_netstats.c: Add missing prototypes.
+ * libmisc/shell/main_wkspaceinfo.c: Remove classinfo_tester.
+ * shttpd/compat_rtems.c: Replace C++-comments with C-comments.
+
+2008-07-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * httpd/emfdb.h, httpd/socket.c, httpd/uemf.c, httpd/uemf.h,
+ httpd/um.h, httpd/webmain.c, httpd/webs.c, httpd/webs.h,
+ httpd/wsIntrn.h: Add missing protoypes.
+
+2008-07-29 Tim Cussins <timcussins@eml.cc>
+
+ * ChangeLog, libmisc/monitor/mon-object.c: Add mising RTEMS_POSIX_API
+ conditional.
+
+2008-07-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-monitor.c: Remove stray arg from function
+ call.
+
+2008-07-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * ftpd/ftpd.c, ftpd/ftpd.h: Add missing prototypes.
+
+2008-07-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/capture/capture.h, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/monitor.h: Add missing prototypes.
+ * score/inline/rtems/score/tod.inl: Add prototypes.
+ * score/src/coretodset.c: Remove stray args in function call.
+ * libcsupport/include/rtems/libcsupport.h,
+ libcsupport/include/rtems/libio_.h,
+ libcsupport/src/malloc_statistics_helpers.c,
+ libcsupport/src/scandir.c: Add prototypes.
+ * telnetd/pty.c: Add prototypes. Remove misc. C++-code pollution.
+ * posix/src/prwlocktrywrlock.c, posix/src/prwlocktryrdlock.c,
+ posix/src/prwlockrdlock.c: Use C-style comments.
+
+2008-07-29 Chris Johns <chrisj@rtems.org>
+
+ * libblock/src/nvdisk.c: Fix block compile bug.
+
+2008-07-29 Chris Johns <chrisj@rtems.org>
+
+ * libblock/include/rtems/bdbuf.h, cpukit/libblock/src/bdbuf.c:
+ Update the comments.
+
+2008-07-29 Chris Johns <chrisj@rtems.org>
+
+ * libblock/Makefile.am: Removed src/show_bdbuf.c.
+
+ * libblock/src/show_bdbuf.c: Removed.
+
+ * libblock/include/rtems/bdbuf.h, cpukit/libblock/src/bdbuf.c:
+ Rewritten the bdbuf code. Remove pre-emption disable, score
+ access, fixed many bugs and increased performance.
+
+ * libblock/include/rtems/blkdev.h: Added
+ RTEMS_BLKDEV_CAPABILITIES block device request. Cleaned up
+ comments. Added block and user fields to the sg buffer
+ request. Move to rtems_* namespace.
+
+ * libblock/include/rtems/diskdevs.h,
+ cpukit/libblock/src/diskdevs.c: Move to rtems_* namespace. Add a
+ capabilities field for drivers. Change rtems_disk_lookup to
+ rtems_disk_obtain to match the release call. You do not lookup and
+ release a disk, you obtain and release a disk.
+
+ * libblock/include/rtems/ide_part_table.h,
+ libblock/include/rtems/ramdisk.h, libblock/src/ide_part_table.c:
+ Move to rtems_* namespace.
+
+ * libblock/include/rtems/nvdisk.h: Formatting change.
+
+ * libblock/src/blkdev.c: Move to rtems_* namespace. Change
+ rtems_disk_lookup to rtems_disk_obtain
+
+ * libblock/src/flashdisk.c: Move to rtems_* namespace. Use the new
+ support for the block number in the scatter/grather request
+ struct. This allows non-continuous buffer requests for those
+ drivers that can support increasing performance.
+
+ * libblock/src/nvdisk.c: Move to rtems_* namespace. Removed
+ warnings. Added better error checking. Fixed some comments.
+
+ * libblock/src/ramdisk.c: Move to rtems_* namespace. Added some
+ trace functions to help debugging upper layers. Use the new
+ support for the block number in the scatter/grather request
+ struct. This allows non-continuous buffer requests for those
+ drivers that can support increasing performance.
+
+ * libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Use new chains
+ API. Removed temporary hack and changed
+ set_errno_and_return_minus_one to
+ rtems_set_errno_and_return_minus_one. Move fat_buf_access from
+ header and stopped it being inlined. Updated to libblock changes.
+
+ * libfs/src/dosfs/fat_fat_operations.c,
+ libfs/src/dosfs/fat_file.c, libfs/src/dosfs/msdos_create.c,
+ libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_eval.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_format.c,
+ libfs/src/dosfs/msdos_free.c, libfs/src/dosfs/msdos_initsupp.c,
+ libfs/src/dosfs/msdos_misc.c, libfs/src/dosfs/msdos_mknod.c: Use
+ new chains API. Removed temporary hack and changed
+ set_errno_and_return_minus_one to
+ rtems_set_errno_and_return_minus_one. Updated to libblock changes.
+
+ * libmisc/Makefile.am: Add new ls and rm command files.
+
+ * libmisc/shell/cmp-ls.c, libmisc/shell/extern-ls.h,
+ libmisc/shell/filemode.c, libmisc/shell/print-ls.c,
+ libmisc/shell/pwcache.c, libmisc/shell/utils-ls.c,
+ libmisc/shell/vis.c, shell/vis.h: New.
+
+ * libmisc/shell/extern-cp.h, libmisc/shell/main_cp.c,
+ libmisc/shell/utils-cp.c: Fixed the usage call bug.
+
+ * libmisc/shell/main_blksync.c: Updated to the new block IO ioctl
+ command.
+
+ * libmisc/shell/main_ls.c, libmisc/shell/main_rm.c: Updated to BSD
+ commands with more features.
+
+ * score/src/coremutex.c: Fix the strict order mutex code.
+
+ * libmisc/shell/shell.c: Change shell tasks mode to be timeslice
+ and no ASR.
+
+ * sapi/include/confdefs.h: Change ata_driver_task_priority to
+ rtems_ata_driver_task_priority. Add the new BD buf cache
+ parameters with defaults.
+
+ * score/src/interr.c: Do not return if the CPU halt call returns.
+
+2008-07-24 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtems/libcsupport.h: Moved declaration of
+ bsp_libc_init() into new bootcard.h.
+
+ * cpukit/include/rtems/irq-extension.h: New function
+ rtems_interrupt_handler_iterate() for system information and
+ diagnostics.
+
+2008-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell_script.c: Clean up code for command not found
+ including the error message.
+
+2008-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-extension.c, libmisc/monitor/mon-itask.c,
+ libmisc/monitor/mon-part.c, libmisc/monitor/mon-prmisc.c,
+ libmisc/monitor/mon-queue.c, libmisc/monitor/mon-region.c,
+ libmisc/monitor/mon-sema.c, libmisc/monitor/mon-task.c,
+ libmisc/monitor/monitor.h: Use rtems_object_get_name() instead of
+ internal routine. This makes it possible to also print string names
+ of POSIX objects. Adjust task report to realign since we can have
+ longer names.
+
+2008-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h, score/src/threadcreateidle.c: Idle thread
+ body is now completely configured via the Configuration table.
+
+2008-07-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1291/cpukit
+ * itron/inline/rtems/itron/semaphore.inl, itron/src/twai_sem.c,
+ posix/include/mqueue.h, posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/time.h, posix/src/condtimedwait.c,
+ posix/src/mqueuereceive.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c,
+ posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c,
+ posix/src/mutextimedlock.c, posix/src/mutextranslatereturncode.c,
+ posix/src/posixtimespecabsolutetimeout.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/semaphoretranslatereturncode.c,
+ posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c,
+ posix/src/semtrywait.c, posix/src/semwait.c,
+ posix/src/sigtimedwait.c, posix/src/timersettime.c,
+ posix/src/ualarm.c, rtems/src/semobtain.c,
+ rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h, score/src/coresemseize.c: This
+ patch addresses issues on implementation of the timeout on the
+ following POSIX services. Some of these services incorrectly took a
+ timeout as a relative time. Others would compute a 0 delta to timeout
+ if the absolute time and the current time were equal and thus
+ incorrectly block the caller forever. The root of the confusion is
+ that POSIX specifies that if the timeout is incorrect (e.g. in the
+ past, is now, or is numerically invalid), that it does not matter if
+ the call would succeed without blocking. This is in contrast to RTEMS
+ programming style where all errors are checked before any critical
+ sections are entered. This fix implemented a more uniform way of
+ handling POSIX absolute time timeouts.
+ + pthread_cond_timedwait - could block forever
+ + mq_timedreceive - used relative not absolute time
+ + mq_timedsend - used relative not absolute time
+ + pthread_mutex_timedlock - used relative not absolute time
+ + pthread_rwlock_timedrdlock- used relative not absolute time
+ + pthread_rwlock_timedwrlock- used relative not absolute time
+ + sem_timedwait - could block forever
+
+2008-07-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/monitor.h, libmisc/shell/main_chmod.c,
+ libmisc/shell/main_tty.c, libmisc/shell/main_umask.c,
+ libmisc/shell/main_whoami.c: Add pthread command to monitor when
+ POSIX is enabled. Remove include of rtems/monitor.h from files not
+ related.
+
+2008-07-16 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/cpu/powerpc/rtems/new-exceptions/cpu.h:
+ use ppc_interrupt_get_disable_mask() to determine
+ which bits to set/clear from _CPU_ISR_Set_level().
+
+2008-07-16 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/cpu/powerpc/rtems/powerpc/registers.h:
+ added ppc_interrupt_get_disable_mask() inline function.
+
+2008-07-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shellconfig.h, libmisc/stackchk/stackchk.h: Fix typos.
+
+2008-07-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell.c, libmisc/shell/shell.h: New argument sequence
+ for rtems_shell_init(). This makes it possible to run the shell
+ forever or invoke it from a program as a subroutine, have a user
+ enter commands, and wait for it to exit.
+
+2008-07-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems.h, sapi/Makefile.am: Add simple helper to get
+ RTEMS version string.
+ * sapi/src/getversionstring.c: New file.
+
+2008-07-10 Peter Rasmussen <Peter.Rasmussen@embedded-brains.de>
+
+ * score/cpu/m68k/cpu_asm.S, cpukit/score/cpu/m68k/rtems/asm.h,
+ cpukit/score/cpu/m68k/rtems/score/cpu.h,
+ score/cpu/m68k/rtems/score/m68k.h:
+
+ added support to save coldfire FPU/EMAC context
+
+2008-07-10 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libi2c/libi2c.c, libi2c/libi2c.h:
+ make buffer passed to *write* functions a const pointer
+
+
+2008-07-10 Till Straumann <strauman@slac.stanford.edu>
+
+ * cpukit/score/cpu/powerpc/rtems/new-exceptions/cpu.h,
+ cpukit/score/cpu/powerpc/rtems/score/cpu.h,
+ cpukit/score/cpu/powerpc/rtems/score/powerpc.h:
+ Removed all macro definitions which depended on
+ the compiler defining a PPC CPU-model dependent
+ symbol.
+ Macros which were not used by cpukit have been
+ moved to libcpu/powerpc/rtems/powerpc/powerpc.h.
+
+2008-07-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * include/rtems/status-checks.h: Fix style.
+
+2008-07-10 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/include/rtems/rtems/intr.h: Documentation.
+
+ * cpukit/include/rtems/irq-extension.h: Extension of the RTEMS
+ Interrupt Manager (shared handler and handler with a handle).
+
+
+2008-07-09 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * cpukit/include/rtems/status-checks.h: Macros for status code and
+ return value checks.
+
+ * cpukit/libmisc/shell/shell.c: Restore terminal settings on exit.
+
+ * cpukit/libfs/src/dosfs/msdos_dir.c,
+ cpukit/libfs/src/dosfs/msdos_file.c: Added S_IRWXU, S_IRWXG and S_IRWXO
+ to file mode.
+
+ * cpukit/libi2c/libi2c.h, cpukit/libi2c/libi2c.c: Modified error
+ messages. Driver operations table is now constant. New entry in the
+ rtems_libi2c_tfr_mode_t structure: idle_char. This character will be
+ continuously transmitted in read only functions.
+
+2008-07-03 Chris Johns <chrisj@rtems.org>
+
+ * cpukit/libcsupport/include/chain.h: Removed. Use the SAPI
+ interface that is supported.
+
+ * cpukit/libcsupport/Makefile.am,
+ cpukit/libcsupport/preinstall.am: Remove chain.h header
+ references.
+
+ * cpukit/sapi/include/rtems/chain.h,
+ cpukit/sapi/inline/rtems/chain.inl: New. A supported chains
+ interface.
+
+ * cpukit/sapi/Makefile.am, cpukit/sapi/preinstall.am: Updated to
+ include the new chains interface.
+
+ * cpukit/libfs/src/imfs/imfs.h,
+ cpukit/libfs/src/imfs/imfs_creat.c,
+ cpukit/libfs/src/imfs/imfs_debug.c,
+ cpukit/libfs/src/imfs/imfs_directory.c,
+ cpukit/libfs/src/imfs/imfs_fsunmount.c,
+ cpukit/libfs/src/imfs/imfs_getchild.c,
+ cpukit/libfs/src/imfs/imfs_load_tar.c,
+ cpukit/libfs/src/imfs/imfs_rmnod.c,
+ cpukit/libfs/src/imfs/memfile.c,
+ cpukit/libfs/src/nfsclient/src/nfs.c,
+ cpukit/libcsupport/include/rtems/libio.h,
+ cpukit/libcsupport/src/malloc_deferred.c,
+ cpukit/libcsupport/src/mount.c,
+ cpukit/libcsupport/src/privateenv.c,
+ cpukit/libcsupport/src/unmount.c: Change to the new chains
+ interface.
+
+ * cpukit/libcsupport/src/malloc_boundary.c: Remove warning.
+
+2008-07-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/thread.h,
+ score/src/threaddispatch.c, score/src/threadinitialize.c:
+ Support rtems_ada_self iff __RTEMS_ADA__ is given.
+
+2008-07-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell_script.c: Remove unused function.
+
+2008-07-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add __RTEMS_ADA__.
+
+2008-07-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/Makefile.am, libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/getservbyname.c,
+ libnetworking/libc/getservbyport.c: Add initial versions of
+ getservbyport_r(), gethostbyaddr_r(), and getservbyport_r(). At this
+ point they are just simple weappers for the version without the _r in
+ the name.
+
+2008-07-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-prmisc.c, rtems/include/rtems/rtems/attr.h:
+ Review association tables in monitor.
+
+2008-06-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac, rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/thread.h,
+ score/inline/rtems/score/coremutex.inl,
+ score/src/coremutex.c, score/src/coremutexsurrender.c,
+ score/src/threadinitialize.c:
+ Rename __STRICT_ORDER_MUTEX__ to __RTEMS_STRICT_ORDER_MUTEX__.
+
+2008-06-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add AM_CONDITIONAL(LIBGNAT).
+ * libgnat/Makefile.am: Use LIBGNAT.
+ * wrapup/Makefile.am: Use LIBGNAT.
+
+2008-06-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * acinclude.m4: Add magic to update cpuopt.h.
+ * configure.ac: Remove magic to update cpuopt.h.
+
+2008-06-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * acinclude.m4: Add _RTEMS_CPUOPT_INIT, _RTEMS_CPUOPT_FINI.
+ * configure.ac: Apply _RTEMS_CPU_INIT, _RTEMS_CPUOPT_FINI.
+ Cleanup mal-formated RTEMS_CPUOPT's.
+
+2008-06-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4: Require AC_DISABLE_OPTION_CHECKING.
+ AC_PREREQ(2.62).
+
+2008-06-19 Matthew Riek <matthew.riek@ibiscomputer.com.au>
+
+ * sapi/include/confdefs.h: Use the PRIORITY_DEFAULT_MAXIMUM rather
+ than a number.
+
+2008-06-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: When you disabled newlib reentrancy, it
+ still reserved memory for the reentrancy structure. This is about 1K
+ per task. On psim, we now reserve only 1936 bytes and only 240 remain
+ after all allocations. Further analysis will be required to narrow
+ that down. In addition, the new constant CONFIGURE_CONFDEFS_DEBUG can
+ be defined and the structure named Configuration_Memory_Debug will be
+ instantiated. This structure contains many of the component values
+ that go into the memory reservation computation. This is helpful when
+ tracking down problems.
+
+2008-06-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: The math in the _Configure_Object_RAM macro
+ was always adding heap overhead even when the number of objects
+ configured was zero and we would not do an allocation. This resulted
+ in an over estimation of the amount of Workspace required (~2K on
+ minimum.exe on PowerPC).
+
+2008-06-17 Chris Johns <chrisj@rtems.org>
+
+ * cpukit/sapi/include/confdefs.h: Add missing quote to string to
+ remove warning.
+
+ * cpukit/score/cpu/m68k/rtems/score/m68k.h: Add the default
+ priority level for large memory Coldfires.
+
+2008-06-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/src/taskgetnote.c,
+ rtems/src/tasks.c, rtems/src/tasksetnote.c, sapi/include/confdefs.h:
+ Add CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS.
+
+2008-06-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h, score/include/rtems/score/priority.h: Add
+ CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION and
+ CONFIGURE_MAXIMUM_PRIORITY.
+
+2008-06-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/include/rtems/posix/pthread.h, posix/src/pthread.c,
+ posix/src/pthreadcreate.c, rtems/include/rtems.h, rtems/src/attr.c,
+ sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ score/inline/rtems/score/stack.inl, score/src/isr.c,
+ score/src/mpci.c, score/src/threadcreateidle.c,
+ score/src/threadinitialize.c, score/src/threadstackallocate.c: Add
+ ability for application to configure minimum stack size. Add
+ RTEMS_CONFIGURED_MINIMUM_STACK_SIZE constant so user can clearly
+ indicate they want the configured as opposed to the recommended
+ minimum stack size.
+
+2008-06-10 Chris Johns <chrisj@rtems.org>
+
+ * score/include/rtems/score/priority.h: Let the CPU define the
+ maximum and minimum priority levels to reduce the amount of memory
+ thread chains use.
+
+2008-06-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems.h, rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/dpmem.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/object.h, rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h, rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h,
+ rtems/include/rtems/rtems/types.h, rtems/src/ratemonperiod.c: Improve
+ Classic API Doxygen.
+
+2008-06-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemonperiod.c,
+ score/include/rtems/score/thread.h: Complete previous patch. Add
+ typedef for cpu usage statistics.
+
+2008-06-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/__times.c, libmisc/cpuuse/cpuusagereport.c,
+ libmisc/cpuuse/cpuusagereset.c, libmisc/monitor/mon-task.c,
+ rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonperiod.c, score/include/rtems/score/thread.h,
+ score/src/threaddispatch.c, score/src/threadinitialize.c,
+ score/src/threadtickletimeslice.c: Add typedefs for cpu usage and
+ period timing statistics. Also renamed related variables and
+ structure members so they are the same whether you are using
+ nanosecond (e.g. struct timespec) or ticks (e.g. uint32_t)
+ granularity. This lays the groundwork for future cleanup.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Rework to be more accurate on allocation. In
+ particular, there was a report from that Matthew Riek that memory was
+ being reserved twice for the IDLE task. This was covering up other
+ places that under allocated memory. Before I was done, I had reworked
+ the file to be easier to read, maintain and be more accurate.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/isr.h, score/src/isr.c: Use
+ CPU_SIMPLE_VECTORED_INTERRUPTS porting parameter to avoid allocating
+ memory for vector table.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/wkspace.c: Fix error in comment.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/psignal.c: Do not allocate any memory for queued signals if
+ the configuration parameter is 0. Before we would end up with an
+ allocation of 0 which rounded up and wasted some memory when POSIX
+ was configured.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/newlibc_exit.c: Only run the fini section on exit if
+ the target toolset uses init/fini sections.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * itron/include/rtems/itron/task.h, itron/src/task.c: ITRON currently
+ has no functional data in the user extension data area structure so
+ this disables the definition, allocation and deallocation of that
+ structure. If we ever have to add data to it, then it will be easy to
+ reenable.
+
+2008-06-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectgetinfo.c, score/src/objectidtoname.c,
+ score/src/threadget.c: Make sure the pointer to the API object table
+ is valid before derefencing it.
+
+2008-06-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/interr.h, score/src/interr.c: Convention
+ calls for leading underscore on private RTEMS variables.
+
+2008-05-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/object.h,
+ score/include/rtems/score/watchdog.h: Move #include's out of
+ extern "C" {}.
+
+2008-05-30 Till Straumann <strauman@slac.stanford.edu>
+
+ * libfs/src/nfsclient/src/nfs.c:BUGFIX: must not attempt to
+ release node if rtems_filesystem_evaluate_path() fails
+ in nfs_eval_link() since pathloc contains no valid node.
+
+2008-05-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell_getchar.c: Minor change so dropping connection
+ while at prompt results in shell logging out and connection still
+ being available.
+
+2008-05-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Call
+ fini() as part of exit(). This avoids atexit() being a required
+ function.
+
+2008-05-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell.c: Minor change so dropping connection during
+ login prompt results in connection still being available.
+
+
+2008-05-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/object.h,
+ rtems/include/rtems/rtems/types.h: Added new defines OBJECTS_ID_NONE
+ and RTEMS_ID_NONE. No object can have this ID.
+
+2008-05-27 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * include/rtems/fs.h, libblock/include/rtems/diskdevs.h,
+ libblock/src/diskdevs.c, libcsupport/include/rtems/libio.h,
+ libcsupport/src/base_fs.c, libcsupport/src/error.c,
+ libcsupport/src/libio.c, libcsupport/src/mount.c, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_handlers_dir.c,
+ libfs/src/dosfs/msdos_handlers_file.c, libfs/src/dosfs/msdos_init.c,
+ libfs/src/dosfs/msdos_initsupp.c, libfs/src/imfs/deviceio.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_config.c,
+ libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_getchild.c,
+ libfs/src/imfs/imfs_handlers_device.c,
+ libfs/src/imfs/imfs_handlers_directory.c,
+ libfs/src/imfs/imfs_handlers_link.c,
+ libfs/src/imfs/imfs_handlers_memfile.c, libfs/src/imfs/imfs_init.c,
+ libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_symlink.c,
+ libfs/src/imfs/imfs_unixstub.c, libfs/src/imfs/miniimfs_init.c,
+ posix/include/rtems/posix/psignal.h, posix/src/psignal.c,
+ rtems/include/rtems/rtems/status.h, rtems/src/semtranslatereturncode.c,
+ sapi/include/confdefs.h, sapi/include/rtems/io.h,
+ sapi/src/ioregisterdriver.c, sapi/src/itronapi.c, sapi/src/posixapi.c:
+ Added const qualifier to various pointers and data tables to
+ reduce size of data area.
+ IMFS: Fixed creation of symbolic links to avoid a compiler warning.
+ DOSFS: Use LibBlock instead of read() to read the boot record.
+
+2008-05-27 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * libcsupport/include/console.h: New define: CONSOLE_DEVICE_NAME.
+
+2008-05-27 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * libcsupport/src/printk.c:
+ Bugfix: String output without width option.
+
+2008-05-27 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
+
+ * libnetworking/net/if_ppp.c, libnetworking/net/if_pppvar.h:
+ Bugfix: Moved definition of ppp_softc into source file.
+
+2008-05-23 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/netinet/ip_output.c: when fragmenting
+ multicast packets M_MCAST must be set on all fragments.
+ This was fixed in FreeBSD ip_output.c 1.82 on 1998/8/23 !
+ (see my email to rtems-users from 2008/5/15).
+
+2008-05-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/rtems/itron/task.h, itron/src/del_tsk.c,
+ itron/src/exd_tsk.c, itron/src/task.c,
+ posix/include/rtems/posix/threadsup.h, posix/src/cancel.c,
+ posix/src/cancelrun.c, posix/src/pthread.c, posix/src/pthreadexit.c,
+ posix/src/setcancelstate.c, posix/src/setcanceltype.c,
+ posix/src/testcancel.c, rtems/src/taskdelete.c,
+ score/inline/rtems/score/object.inl, score/src/objectclose.c,
+ score/src/threadclose.c: Make all task delete/exit/cancel routines
+ follow the same critical section pattern. Also ensure that POSIX
+ cancelation routines are run at thread exit.
+
+2008-05-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/termios_baud2index.c,
+ libcsupport/src/termios_baud2num.c,
+ libcsupport/src/termios_num2baud.c,
+ libcsupport/src/termios_setinitialbaud.c: New files.
+
+2008-05-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/preinstall.am,
+ libcsupport/include/rtems/termiostypes.h: Move termios helper
+ routines from libchip to libcsupport. Add routine which makes it easy
+ for a termios device driver to inform termios of its default baud
+ rate. This avoids inconsistencies in later termios settings changes.
+
+2008-05-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/include/rtems/watchdogdrv.h: Finish writing comments.
+
+2008-05-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/preinstall.am, sapi/include/confdefs.h: Add baseline
+ interface for Watchdog Driver.
+ * libcsupport/include/rtems/watchdogdrv.h: New file.
+
+2008-05-16 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/src/threadchangepriority.c: Just in case the transient
+ state was set when we entered, ensure that it is still set when
+ we exit.
+ * score/src/threadclose.c: When a thread is being deleted, it should
+ go into the dormant state -- not the transient state.
+
+2008-05-15 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libi2c/libi2c.h, libi2c/libi2c.h: added interface to query
+ driver private data
+
+2008-05-13 Eric Norum: <norume@aps.anl.gov>
+
+ * cpukit/libcsupport/src/mallocinfo.c: Add locks around non-atomic
+ structure assignment.
+
+2008-05-13 Robert S. Grimes <rsg@alum.mit.edu>
+
+ * libi2c/libi2c.h: Fix typo.
+
+2008-05-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * pppd/example/system.h: Fix path in example -- NOT COMPILED WITH
+ CPUKIT.
+
+2008-05-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/rtems/init.h, sapi/src/exinit.c: Refactored and renamed
+ initialization routines to rtems_initialize_data_structures,
+ rtems_initialize_before_drivers, rtems_initialize_device_drivers, and
+ rtems_initialize_start_multitasking. This opened the sequence up so
+ that bootcard() could provide a more robust and flexible framework
+ which is easier to explain and understand. This also lays the
+ groundwork for sharing the division of available memory between the
+ RTEMS workspace and heap and the C library initialization across all
+ BSPs.
+
+2008-05-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/src/exinit.c, score/src/threadstartmultitasking.c: Improve
+ comments.
+
+2008-05-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectget.c: Improve comments and readability.
+
+2008-05-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/message.h, sapi/include/confdefs.h,
+ score/src/coresemseize.c, score/src/threadhandler.c: Comment
+ improvements from class.
+
+2008-05-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1285/rtems
+ * sapi/include/rtems/config.h: Remove obsolete
+ rtems_configuration_get_maximum_devices().
+
+2008-05-01 Chris Johns <chrisj@rtems.org>
+
+ * libblock/include/rtems/nvdisk-sram.h,
+ libblock/include/rtems/nvdisk.h,
+ libblock/src/nvdisk-sram.c,
+ libblock/src/nvdisk.c: New. A Non-volatile memory disk drive.
+ * Makefile.am, preinstall.am, libblock/Makefile.am: Updated for
+ the NV disk driver.
+
+2008-05-01 Maarten Van Es <maarten@mind.be>
+
+ * libnetworking/rtems/rtems_dhcp.c: Removed panic()s. Added
+ interface for rtems_dhcp_failsafe.
+ * libnetworking/rtems/rtems_dhcp.h: Added interface for
+ rtems_dhcp_failsafe.
+
+2008-05-01 Arnout Vandecappelle <arnout@mind.be>
+
+ * libnetworking/nfs/bootp_subr: Allow some errors for sosend() and
+ return on timeout in bootpc_call(). Removed panic()s.
+ * libnetworking/rtems/rtems_glue.c: Fix the cast for the
+ SIOCAIFADDR ioctl call.
+ * libnetworking/rtems/rtems_dhcp_failsafe.c,
+ libnetworking/rtems/rtems_dhcp_failsafe.h: New.
+ * libnetworking/Makefile.am, libnetworking/preinstall.am: Added
+ rtems_dhcp_failsafe.c and rtems_dhcp_failsafe.h files.
+
+2008-04-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/timer.h: Fix typo.
+
+2008-04-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems.h, rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/status.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h,
+ rtems/inline/rtems/rtems/sem.inl: More Doxygen warnings removed.
+
+2008-04-28 Daron Chabot <daron.chabot@usask.ca>
+
+ * posix/src/keycreate.c, posix/src/pthreadequal.c,
+ rtems/src/semtranslatereturncode.c,
+ score/src/threadblockingoperationcancel.c: Fix compilation errors
+ when --enable-rtems-debug is used.
+
+2008-04-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/system.h: Fix typo in comment.
+
+2008-04-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/partmp.h, sapi/include/confdefs.h: Fix
+ typos added with recent changes.
+
+2008-04-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/include/rtems/libio.h: Remove
+ rtems_termios_reserve_resources. It is obsolete.
+ * libcsupport/src/termiosreserveresources.c: Removed.
+
+2008-04-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/mainpage.h: New file.
+
+2008-04-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/Doxyfile, rtems/include/rtems/rtems/asr.h,
+ rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/barrier.h,
+ rtems/include/rtems/rtems/barriermp.h,
+ rtems/include/rtems/rtems/cache.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/eventmp.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/modes.h, rtems/include/rtems/rtems/mp.h,
+ rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/options.h,
+ rtems/include/rtems/rtems/part.h, rtems/include/rtems/rtems/partmp.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/rtemsapi.h,
+ rtems/include/rtems/rtems/sem.h, rtems/include/rtems/rtems/semmp.h,
+ rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/status.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h,
+ rtems/include/rtems/rtems/types.h, rtems/inline/rtems/rtems/asr.inl,
+ rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/barrier.inl,
+ rtems/inline/rtems/rtems/dpmem.inl,
+ rtems/inline/rtems/rtems/event.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/timer.inl: More Doxygen improvements.
+
+2008-04-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems.h, rtems/include/rtems/rtems/asr.h,
+ rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/barrier.h,
+ rtems/include/rtems/rtems/barriermp.h,
+ rtems/include/rtems/rtems/cache.h, rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/eventmp.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/modes.h, rtems/include/rtems/rtems/mp.h,
+ rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/object.h,
+ rtems/include/rtems/rtems/options.h,
+ rtems/include/rtems/rtems/part.h, rtems/include/rtems/rtems/partmp.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/rtemsapi.h,
+ rtems/include/rtems/rtems/sem.h, rtems/include/rtems/rtems/semmp.h,
+ rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/status.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h,
+ rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h,
+ rtems/include/rtems/rtems/types.h, rtems/inline/rtems/rtems/asr.inl,
+ rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/barrier.inl,
+ rtems/inline/rtems/rtems/dpmem.inl,
+ rtems/inline/rtems/rtems/event.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/tasks.inl,
+ rtems/inline/rtems/rtems/timer.inl: Initial conversion of Classic API
+ header files to Doxygen.
+ * rtems/Doxyfile: New file.
+
+2008-04-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/key.c: Include <limits.h>
+ * posix/src/psignal.c, rtems/src/tasks.c: Do not attempt to process
+ a NULL extension block.
+
+2008-04-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/dummy/dummy.c, sapi/include/confdefs.h: Add checks for
+ application configuration errors. If any POSIX objects or a POSIX
+ init thread is configured without POSIX being configure, then error
+ out. Similarly for ITRON. Add
+ CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER configuration
+ parameter so the application has to explicitly configure the Clock
+ driver in or out if the Timer driver is not configured. Also verify
+ RTEMS was built for multiprocessing, if the user tries to configure a
+ multiprocessing application.
+
+2008-04-12 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/shell.c, libmisc/shell/shell.h,
+ libmisc/shell/shell_script.c: Add support to echo the commands to
+ stdout. This is useful with the -v script option to show commands
+ as the run. Also added support to chdir to the directory the task
+ invoking the script is in.
+ * libmisc/shell/extern-cp.h, libmisc/shell/main_cp.c,
+ libmisc/shell/utils-cp.c: Update tro the latest FreeBSD version.
+ * libcsupport/Makefile.am, libcsupport/src/fchown.c: Add fchown
+ support.
+
+2008-04-09 Madhusudan.C.S <madhusudancs@gmail.com>
+
+ * score/include/rtems/score/tod.h: Fix typo.
+
+2008-04-08 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/shell.c: Copy the cmd line to a buffer to split
+ into argv parts. Was using the command line history buffer so the
+ history was being corrupted.
+
+2008-04-03 Chris Johns <chrisj@rtems.org>
+
+ * libfs/src/nfsclient/src/librtemsNfs.h,
+ libfs/src/nfsclient/src/nfs.c: Remove CEXP references. CEXP is
+ external to RTEMS and even if in the cpukit it should not cross
+ reference in this way.
+ * libmisc/shell/shell_getchar.c: New. Taken from the monitor.
+ * libmisc/Makefile.am: Add shell_getchar.c and clean up a little
+ in the shell area.
+ * libmisc/shell/shell.c, libmisc/shell/shell.h: Add line editting
+ support.
+
+2008-03-29 Chris Johns <chrisj@rtems.org>
+
+ * librpc/include/rpc/clnt.h: Added the missing __BEGIN_DECLS as
+ reported to the mailing list by Pierre Kestener
+ (pierre.kestener@cea.fr).
+
+2008-03-25 Till Straumann <strauman@slac.stanford.edu>
+
+ * shttpd/log.c: Activate SPLIT_SNPRINTF for gcc <= 4.2.3 and
+ coldfire.
+
+2008-03-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/cmds.c: Directly register the command structure to
+ avoid unnecessary duplication of static strings. We know best this
+ time.
+
+2008-03-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Do not reserve 2 * minimum stack size
+ for the ITRON initialization tasks ALL the time.
+ Do not reserve memory for the object name table since it does not
+ exist any longer.
+ * sapi/include/rtems/sptables.h: Fix typo.
+
+2008-03-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/clock.h,
+ rtems/src/clockget.c:
+ * rtems/src/clockgetsecondssinceepoch.c,
+ rtems/src/clockgettickspersecond.c,
+ rtems/src/clockgettickssinceboot.c, rtems/src/clockgettod.c,
+ rtems/src/clockgettodtimeval.c: New files.
+ Refactored rtems_clock_get into 5 methods which are single purpose
+ and more strongly typed. They are:
+ rtems_clock_get_tod - Get TOD in Classic API structure
+ rtems_clock_get_tod_timeval - Get TOD in struct timeval
+ rtems_clock_get_seconds_since_epoch - Get TOD as seconds since 1988
+ rtems_clock_get_ticks_since_boot - Get ticks since boot
+ rtems_clock_get_ticks_per_second - Get ticks per second
+
+2008-03-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_cp.c, libmisc/shell/main_netstats.c,
+ libmisc/shell/shell_script.c: Add memset() of getopt_data to
+ ensure it is zeroed out each time we use getopt_r().
+ * libmisc/shell/shell.c: Do not echo commands if input is not a tty.
+ This makes the scripts behave more like UNIX scripts.
+
+2008-03-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/Makefile.am: Make clock_settime() available always just like
+ clock_gettime().
+
+2008-03-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/copyrt.h: Update year.
+
+2008-03-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/gxx_wrappers.c: Add rtems_gxx_mutex_destroy as needed
+ by gcc newer than the 4.3 release series.
+
+2008-03-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/main_cp.c,
+ libmisc/shell/main_cpuuse.c, libmisc/shell/main_date.c,
+ libmisc/shell/main_mallocinfo.c, libmisc/shell/main_netstats.c,
+ libmisc/shell/main_perioduse.c, libmisc/shell/main_stackuse.c,
+ libmisc/shell/main_wkspaceinfo.c, libmisc/shell/print_heapinfo.c,
+ libmisc/shell/shell.c, libmisc/shell/shell.h,
+ libmisc/shell/shell_makeargs.c, libmisc/shell/shellconfig.c,
+ libmisc/shell/shellconfig.h, libmisc/shell/write_file.c: Add initial
+ capability to automatically execute a script from the filesystem. Add
+ echo command from NetBSD and sleep command.
+ * libmisc/shell/main_echo.c, libmisc/shell/main_sleep.c,
+ libmisc/shell/shell_script.c: New files.
+
+2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/rtems/itron/task.h, itron/src/cre_tsk.c,
+ posix/src/pthreadcreate.c, rtems/src/taskcreate.c,
+ rtems/src/taskdelete.c, rtems/src/timerserver.c,
+ score/src/threadclose.c, score/src/threadcreateidle.c,
+ score/src/threadinitialize.c: Switch task create and delete
+ operations to using API Allocator Mutex. This moves almost all uses
+ of the RTEMS Workspace from dispatching disabled to mutex protected
+ which should improve deterministic behavior. The implementation was
+ carefully done to allow task create and delete extensions to invoke
+ more services. In particular, a task delete extension should be able
+ to do mutex and file operations.
+
+2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am: Turn on NFS mount support when networking is
+ enabled.
+
+2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/chroot.c: Formatting.
+
+2008-02-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/cat_file.c, libmisc/shell/main_alias.c,
+ libmisc/shell/main_blksync.c, libmisc/shell/main_cat.c,
+ libmisc/shell/main_chdir.c, libmisc/shell/main_chmod.c,
+ libmisc/shell/main_chroot.c, libmisc/shell/main_cpuuse.c,
+ libmisc/shell/main_date.c, libmisc/shell/main_help.c,
+ libmisc/shell/main_id.c, libmisc/shell/main_logoff.c,
+ libmisc/shell/main_ls.c, libmisc/shell/main_mallocinfo.c,
+ libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
+ libmisc/shell/main_mfill.c, libmisc/shell/main_mkdir.c,
+ libmisc/shell/main_mmove.c, libmisc/shell/main_mount.c,
+ libmisc/shell/main_mount_nfs.c, libmisc/shell/main_msdosfmt.c,
+ libmisc/shell/main_mwdump.c, libmisc/shell/main_perioduse.c,
+ libmisc/shell/main_pwd.c, libmisc/shell/main_rm.c,
+ libmisc/shell/main_rmdir.c, libmisc/shell/main_stackuse.c,
+ libmisc/shell/main_tty.c, libmisc/shell/main_umask.c,
+ libmisc/shell/main_unmount.c, libmisc/shell/main_whoami.c,
+ libmisc/shell/shell.h: Clean up done while writing documentation.
+ Some command improvements such as date now allows setting of the
+ current TOD. Often commands did not use stdout/stderr per
+ expectations and did not return -1 on an error.
+
+2008-02-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac, libfs/Makefile.am: Add nfsclient to cpukit. Although
+ the use of RPC/XDR could be an issue, the code does build multilib
+ across all targets. There are a few remaining warnings to deal with.
+ * libfs/src/nfsclient/.cvsignore, libfs/src/nfsclient/ChangeLog.slac,
+ libfs/src/nfsclient/LICENSE, libfs/src/nfsclient/Makefile.am,
+ libfs/src/nfsclient/README, libfs/src/nfsclient/preinstall.am,
+ libfs/src/nfsclient/rfc1094.txt,
+ libfs/src/nfsclient/proto/mount_prot.h,
+ libfs/src/nfsclient/proto/mount_prot.x,
+ libfs/src/nfsclient/proto/mount_prot_xdr.c,
+ libfs/src/nfsclient/proto/nfs_prot.h,
+ libfs/src/nfsclient/proto/nfs_prot.x,
+ libfs/src/nfsclient/proto/nfs_prot_xdr.c,
+ libfs/src/nfsclient/src/cexphelp.c,
+ libfs/src/nfsclient/src/dirutils.c,
+ libfs/src/nfsclient/src/librtemsNfs.h, libfs/src/nfsclient/src/nfs.c,
+ libfs/src/nfsclient/src/nfs.modini.c,
+ libfs/src/nfsclient/src/nfsTest.c, libfs/src/nfsclient/src/rpcio.c,
+ libfs/src/nfsclient/src/rpcio.h,
+ libfs/src/nfsclient/src/rpcio.modini.c,
+ libfs/src/nfsclient/src/sock_mbuf.c,
+ libfs/src/nfsclient/src/xdr_mbuf.c: New files.
+
+2008-02-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/rtems/config.h, sapi/include/rtems/sptables.h: Add
+ missing field to default multiprocessing configuration table. Also
+ document fields in Doxygen format.
+
+2008-02-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/regionmp.c, score/src/objectnametoidstring.c: Fix some
+ warnings.
+
+2008-02-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add netstats
+ command to access statistics reporting functions in TCP/IP stack.
+ * libmisc/shell/main_netstats.c: New file.
+
+2008-02-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/main_wkspaceinfo.c,
+ libmisc/shell/shell.c, libmisc/shell/shellconfig.h: Add route and
+ ifconfig commands. The code for these was previously in the
+ networking guide. Disable NFS filesystem mount until that code is in
+ cpukit.
+ * libmisc/shell/main_ifconfig.c, libmisc/shell/main_route.c: New files.
+
+2008-02-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/preinstall.am, libcsupport/preinstall.am:
+ Revert Joel's 2008-01-31 screw up.
+
+2008-02-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/timer.h: Add c++ guards.
+ * posix/src/cond.c, posix/src/mutex.c, posix/src/pbarrier.c,
+ posix/src/prwlock.c, posix/src/pspin.c: Include <limits.h>.
+ * libcsupport/include/motorola/mc68230.h: Prefix defines with
+ MC68230_ to avoid preprocessor clashes.
+
+2008-02-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/mqueueunlink.c, score/Makefile.am,
+ score/include/rtems/score/object.h,
+ score/inline/rtems/score/object.inl: Enhance
+ _Objects_Namespace_remove() to handle freeing object names which are
+ strings. All changed _Objects_Close() to call
+ _Objects_Namespace_remove(). The resulting code was then moved from
+ inline routines to function calls.
+ * score/src/objectclose.c, score/src/objectnamespaceremove.c: New files.
+
+2008-02-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/printk.c: Added width and padding for %s.
+ * libmisc/cpuuse/cpuusagereport.c: Support object names that are
+ strings longer than 4 chanracters.
+
+2008-02-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1277/networking
+ * libnetworking/netinet/in_cksum_i386.h: Use q instead of r in
+ constraint for assembly language. This restricts the register choice
+ to the a-d registers.
+
+2008-02-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/kern/uipc_socket2.c,
+ libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/netinet/udp_usrreq.c,
+ libnetworking/rtems/rtems_bsdnet.h, libnetworking/rtems/rtems_glue.c:
+ Add configuration parameters for network stack efficiency multiplier
+ and default socket buffer sizes. Change default multiplier from 8 to
+ 2 to match GNU/Linux. This has no impact on performance on the BSPs
+ tested.
+
+2008-02-04 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/support.h: Added
+ workspace manipulation routines for testing.
+ * rtems/src/workspace.c: New file.
+
+2008-02-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/rtemsobjectsetname.c, score/src/objectgetinfoid.c,
+ score/src/objectgetnameasstring.c, score/src/objectidtoname.c: Handle
+ Object Id of SELF.
+
+2008-01-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/clockgettime.c, posix/src/clocksettime.c,
+ Minor modifications to improve testability.
+ * posix/src/pthreadcreate.c: Add NULL check for thread entry.
+
+2008-01-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/pthreadinitthreads.c: Clean up error paths.
+
+2008-01-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/preinstall.am, posix/preinstall.am: Revert temporary
+ changes which aid in coverage testing.
+
+2008-01-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/cond.c, posix/src/key.c, posix/src/mqueuenametoid.c,
+ posix/src/mutex.c, posix/src/pbarrier.c, posix/src/prwlock.c,
+ posix/src/pspin.c, posix/src/pthread.c, posix/src/ptimer.c,
+ posix/src/semaphorenametoid.c: Add option for all POSIX objects
+ whether named or unnamed to have a string name. If the API does
+ not directly support having a name, then the user must explicitly
+ assign it using rtems_object_set_name().
+ * rtems/src/rtemsobjectgetapiclassname.c: Improved testability.
+ * score/include/rtems/score/object.h,
+ score/src/objectgetnameasstring.c, score/src/objectnametoidstring.c,
+ score/src/objectsetname.c: Modifications required to pass testing of
+ recently modified object name operations. Also eliminated
+ multiprocessing related code that was not reachable.
+
+2008-01-31 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/src/timersettime.c: Fix to remove warning.
+
+2008-01-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/posix_memalign.c: Remove warning.
+
+2008-01-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/object.h, score/src/objectgetinfo.c,
+ rtems/include/rtems/rtems/object.h,
+ rtems/src/rtemsobjectgetapiclassname.c,
+ rtems/src/rtemsobjectgetclassinfo.c: class is a C++ keyword and
+ cannot be used as a parameter.
+
+2008-01-30 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am, score/include/rtems/score/threadq.h,
+ score/inline/rtems/score/threadq.inl: _Thread_queue_Process_timeout
+ was really too complex to be inlined.
+ * score/src/threadqprocesstimeout.c: New file.
+
+2008-01-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Doxyfile: Revert Doxygen version changes.
+
+2008-01-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Doxyfile: Update to latest Doxygen format.
+ * score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/corebarrier.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/corerwlock.h,
+ score/include/rtems/score/heap.h, score/include/rtems/score/object.h,
+ score/include/rtems/score/protectedheap.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadsync.h,
+ score/include/rtems/score/tod.h,
+ score/inline/rtems/score/corerwlock.inl,
+ score/inline/rtems/score/corespinlock.inl: Remove most doxygen
+ warnings.
+
+2008-01-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/rtemsobjectgetapiclassname.c: Class name strings are not
+ available when API is disabled. Do not attempt to use them.
+
+2008-01-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/system.h: First cut at Doxygen mainpage.
+
+2008-01-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/src/exd_tsk.c, itron/src/task.c, libmisc/capture/capture.c,
+ libmisc/monitor/mon-config.c, libmisc/monitor/mon-driver.c,
+ libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c,
+ libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/mon-symbols.c, posix/src/cancelrun.c,
+ posix/src/pthreadexit.c, rtems/Makefile.am, rtems/preinstall.am,
+ rtems/include/rtems.h, rtems/include/rtems/rtems/support.h,
+ rtems/inline/rtems/rtems/tasks.inl, rtems/src/eventmp.c,
+ rtems/src/msgmp.c, rtems/src/partmp.c, rtems/src/regionmp.c,
+ rtems/src/rtemsobjectgetname.c, rtems/src/semmp.c,
+ rtems/src/signalmp.c, rtems/src/taskdelete.c, rtems/src/taskmp.c,
+ rtems/src/timerserver.c, score/Makefile.am,
+ score/include/rtems/score/object.h,
+ score/inline/rtems/score/object.inl, score/src/Unlimited.txt,
+ score/src/objectgetnameasstring.c,
+ score/src/threadqextractwithproxy.c: Add new Object Services
+ collection. This changed the name of a few previously public but
+ undocumented services and added a some new services.
+ * rtems/include/rtems/rtems/object.h, rtems/src/rtemsbuildid.c,
+ rtems/src/rtemsbuildname.c, rtems/src/rtemsobjectapimaximumclass.c,
+ rtems/src/rtemsobjectapiminimumclass.c,
+ rtems/src/rtemsobjectgetapiclassname.c,
+ rtems/src/rtemsobjectgetapiname.c,
+ rtems/src/rtemsobjectgetclassicname.c,
+ rtems/src/rtemsobjectgetclassinfo.c,
+ rtems/src/rtemsobjectidapimaximum.c,
+ rtems/src/rtemsobjectidapiminimum.c, rtems/src/rtemsobjectidgetapi.c,
+ rtems/src/rtemsobjectidgetclass.c, rtems/src/rtemsobjectidgetindex.c,
+ rtems/src/rtemsobjectidgetnode.c, rtems/src/rtemsobjectsetname.c,
+ score/src/objectapimaximumclass.c, score/src/objectgetinfo.c,
+ score/src/objectgetinfoid.c, score/src/objectsetname.c: New files.
+ * rtems/src/rtemsidtoname.c: Removed.
+
+2008-01-29 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * score/src/corerwlockrelease.c, score/src/coresemseize.c: Changed
+ switch statements to if statements.
+
+2008-01-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
+ libcsupport/src/malloc_walk.c, libcsupport/src/posix_memalign.c,
+ libcsupport/src/realloc.c, score/src/heapwalk.c: Add rtems_memalign
+ as helper and as exposed nmemalign variant with few restrictions.
+ Also turn on compilation of _Heap_Walk but make forced calls to it
+ conditionally compiled. This should allow more flexibility to the
+ user as to run-time checking of the heap.
+ * libcsupport/src/rtems_memalign.c: New file.
+
+2008-01-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h, score/src/mpci.c, score/src/objectmp.c,
+ score/src/objectnametoid.c, score/src/objectnametoidstring.c:
+ Multiprocessing compiles again and survives initialization. The
+ recent object name and confdefs.h changes had broken it.
+
+2008-01-25 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * sapi/include/rtems/fatal.h, score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/interr.h,
+ score/inline/rtems/score/thread.inl, score/src/coremutexseize.c:
+ Modifications to aid in full path testing.
+
+2008-01-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/mqueuesendsupp.c: Remove warning.
+
+2008-01-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/include/rtems/assoc.h: rtems_assoc_ptr_by_local should be
+ in public API.
+
+2008-01-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/object.h,
+ score/src/objectextendinformation.c,
+ score/src/objectinitializeinformation.c,
+ score/src/objectshrinkinformation.c: Eliminate name_table since it is
+ not used.
+
+2008-01-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectnametoidstring.c: New file.
+
+2008-01-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * itron/include/rtems/itron/object.h, itron/src/cre_tsk.c,
+ libblock/src/show_bdbuf.c, libmisc/capture/capture-cli.c,
+ libmisc/capture/capture.c, libmisc/monitor/mon-manager.c,
+ libmisc/stackchk/check.c, posix/src/condinit.c,
+ posix/src/keycreate.c, posix/src/mqueuecreatesupp.c,
+ posix/src/mqueuedeletesupp.c, posix/src/mqueuenametoid.c,
+ posix/src/mqueueopen.c, posix/src/mqueueunlink.c,
+ posix/src/mutexinit.c, posix/src/pbarrierinit.c,
+ posix/src/prwlockinit.c, posix/src/pspininit.c,
+ posix/src/pthreadcreate.c, posix/src/pthreadexit.c,
+ posix/src/semaphorecreatesupp.c, posix/src/semaphorenametoid.c,
+ posix/src/timercreate.c, rtems/src/barrierident.c,
+ rtems/src/dpmemident.c, rtems/src/msgqident.c, rtems/src/partident.c,
+ rtems/src/ratemonident.c, rtems/src/regionident.c,
+ rtems/src/semident.c, rtems/src/taskident.c, rtems/src/timerident.c,
+ sapi/src/extensionident.c, score/Makefile.am,
+ score/include/rtems/score/object.h,
+ score/inline/rtems/score/object.inl, score/src/apimutexallocate.c,
+ score/src/objectextendinformation.c,
+ score/src/objectgetnameasstring.c, score/src/objectmp.c,
+ score/src/objectnametoid.c: Convert the Objects_Name type from a
+ simple type to a union of an unsigned 32 bit integer and a pointer.
+ This should help eliminate weird casts between u32 and pointers in
+ various places. The APIs now have to explicitly call _u32 or _string
+ versions of helper routines. This should also simplify things and
+ eliminate the need for ugly casts in some cases.
+ * score/src/objectclearname.c, score/src/objectcomparenameraw.c,
+ score/src/objectcomparenamestring.c, score/src/objectcopynameraw.c,
+ score/src/objectcopynamestring.c: Removed.
+
+2008-01-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadblockingoperationcancel.c: Clean up.
+ * score/src/threadqextract.c: Restructure to eliminate dead code.
+
+2008-01-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/eventsurrender.c, rtems/src/ratemonperiod.c,
+ score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c,
+ score/src/threadqdequeuepriority.c: Fix bugs encountered while
+ testing and clean up more code.
+
+2008-01-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadqfirst.c: Remove switch.
+
+2008-01-22 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/include/rtems/rtems/event.h,
+ rtems/inline/rtems/rtems/eventset.inl, rtems/src/event.c,
+ rtems/src/eventseize.c, rtems/src/eventsurrender.c,
+ rtems/src/eventtimeout.c, score/Makefile.am, score/preinstall.am,
+ score/include/rtems/score/interr.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/tqdata.h,
+ score/inline/rtems/score/threadq.inl,
+ score/inline/rtems/score/tqdata.inl, score/src/threadq.c,
+ score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c,
+ score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c,
+ score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c,
+ score/src/threadqextract.c, score/src/threadqextractfifo.c,
+ score/src/threadqextractpriority.c,
+ score/src/threadqextractwithproxy.c, score/src/threadqfirst.c,
+ score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c,
+ score/src/threadqflush.c, score/src/threadqrequeue.c,
+ score/src/threadqtimeout.c: Refactor thread queue enqueue and event
+ blocking synchronization critical sections. This resulted in three
+ copies of essentially the same hard to test critical section code
+ becoming the one shared routine _Thread_blocking_operation_Cancel. In
+ addition, the thread queue and event code now share a common
+ synchronization enumerated type. Along the way, switches were
+ reworked to eliminate dead code generated by gcc and comments and
+ copyrights were updated.
+ * score/include/rtems/score/threadsync.h,
+ score/src/threadblockingoperationcancel.c: New files.
+
+2008-01-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libi2c/README_libi2c: Correct spelling error.
+ * score/src/threadclearstate.c: Improve comment.
+
+2008-01-18 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/include/rtems/posix/timer.h, posix/src/cleanuppop.c,
+ posix/src/cleanuppush.c, posix/src/mqueueclose.c,
+ posix/src/timergettime.c, posix/src/timersettime.c,
+ score/include/rtems/score/timespec.h:
+
+2008-01-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/shell/Makefile.am: Don't use make variables.
+
+2008-01-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell.c: When stdin or stdout is NULL, just use
+ existing one.
+
+2008-01-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/wkspace.inl, score/src/wkspace.c: Do not
+ inline _Workspace_Free or _Workspace_Allocate since they are not
+ always inlined and actually smaller overall as subroutines. They are
+ not particularly time critical so inlining is not absolutely
+ necessary.
+
+2008-01-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/Makefile.am, posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/mutex.h, posix/inline/rtems/posix/cond.inl,
+ posix/inline/rtems/posix/mutex.inl: Do not include POSIX Mutex or
+ Condition Variable object get helpers because they are more
+ complicated than the norm. They can implicitly perform a create. They
+ cross the line as being too complex and large to inline since they
+ negatively impact size and binary test coverage.
+ * posix/src/condget.c, posix/src/mutexget.c: New files.
+
+2008-01-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am: Add src/malloc_dirtier.c.
+ * libcsupport/include/rtems/malloc.h: Add malloc dirty support.
+ * libcsupport/src/malloc_p.h: Correct prototype.
+
+2008-01-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/include/rtems/score/coremutex.h,
+ score/src/coremutexseizeintr.c: Fix conditional code for inlining
+ _CORE_mutex_Seize_interrupt_trylock() and add comments.
+
+2008-01-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Add CONFIGURE_MALLOC_DIRTY.
+
+2008-01-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
+ libcsupport/src/free.c, libcsupport/src/malloc.c,
+ libcsupport/src/malloc_deferred.c,
+ libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h,
+ libcsupport/src/malloc_sbrk_helpers.c,
+ libcsupport/src/posix_memalign.c: Place all deferred free code and
+ place it in subroutines. Add plugin for dirtying allocated memory to
+ assist in debugging. Clean up comments and spacing as needed.
+ * libcsupport/src/malloc_dirtier.c: New file.
+
+2008-01-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectgetnoprotection.c: Eliminate duplicate exit path code
+ when there is an error.
+
+2008-01-09 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/src/keycreate.c, rtems/src/eventseize.c,
+ score/include/rtems/score/interr.h: Rearranged source to allow more
+ test coverage.
+
+2008-01-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/__assert.c: Clean up and make __assert() call
+ __assert_func().
+
+2008-01-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/__assert.c: Newlib 1.16.0 adds __assert_func(). We
+ need to have it also.
+
+2008-01-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am: Add malloc_sbrk_helpers.c.
+ * libcsupport/include/rtems/malloc.h,
+ libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c,
+ libcsupport/src/malloc_p.h,
+ libcsupport/src/malloc_statistics_helpers.c: Make sbrk()
+ support pluggable and optional. This eliminates the need for
+ heap extend and sbrk in the minimum footprint which is ~2.5K on
+ the SPARC.
+ * sapi/include/confdefs.h: Add the following configuration points:
+ + CONFIGURE_MALLOC_STATISTICS
+ + CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
+ * libcsupport/src/malloc_sbrk_helpers.c: New file.
+
+2008-01-08 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am: Add missing file.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-manager.c: Style. Eliminate tabs.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am: Add new files.
+ * libmisc/shell/internal.h: Prototype for rtems_shell_print_heap_info()
+ * libmisc/shell/main_mallocinfo.c: Use rtems_shell_print_heap_info().
+ * libmisc/shell/shellconfig.h: Add wkspace command.
+ * libmisc/shell/main_wkspaceinfo.c,
+ libmisc/shell/print_heapinfo.c: New files.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/isr.inl: Fix spacing.
+ * score/src/apimutexallocate.c: Fix spacing.
+ * score/src/coremsgseize.c: Check for message pending instead of
+ message pending count to avoid dead code from inlined chain routine.
+ It checks if the chain is empty so is redundant to count == 0.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/eventseize.c, rtems/src/eventtimeout.c: Minor style clean
+ up.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/pthreadcreate.c: Add commit.
+ * posix/src/pthreadinitthreads.c: Fix line length.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/object.inl: Add _Objects_Is_api_valid.
+
+2008-01-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/threadget.c: Use _Objects_Is_api_valid rather than open
+ coding it.
+
+2008-01-05 Chris Johns <chrisj@rtems.org>
+
+ * configure.ac: Fix typo in the strict order mutex CPU OPTs test.
+ * libmisc/shell/shell.c: Handle '#' comment characters correctly.
+ * libblock/include/rtems/flashdisk.h: Add docmentation about the
+ control fields. Add more control fields to handle the flash when
+ full.
+ * libblock/src/flashdisk.c: Fix the descriptor erase test so it
+ detects a descriptor is erased. Add support for unavailable blocks
+ the user can configure. Print the used list as a diag. Fix the bug
+ when a page is detected as failed and present on more than one
+ queue. Add a count to the queues so queue length can be used to
+ manage compaction.
+
+2008-01-03 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/src/threadhandler.c, sapi/src/exshutdown.c:
+ cannot call _fini via atexit() from rtems_shutdown_executive()
+ because at the point where rtems_shutdown_executive is called
+ the C-library is already dead.
+ Instead, register an atexit(_fini) after calling _init().
+
+2007-12-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am: _rename_r is required by newlib 1.16.0.
+ Hopefully this implementation is OK.
+ * libcsupport/src/_rename_r.c: New file.
+
+2007-12-22 Chris Johns <chrisj@rtems.org>
+
+ * configure.ac: fixed bug that always enabled strict order
+ mutexes.
+ * score/inline/rtems/score/coremutex.inl: Fixed coding standard.
+ * score/src/coremutex.c: Add the holder's thread to the lock_mutex
+ list if the mutex is initialised locked.
+ * libnetworking/rtems/rtems_glue.c: Changed semaphore error
+ message to show the error is an rtems-net error.
+ * libmisc/monitor/mon-network.c: Removed warnings.
+ * telnetd/icmds.c: Changed shell_* to rtems_shell_*.
+ * score/Makefile.am: Fixed typo that stopped 'make tags' working.
+ * libmisc/shell/err.c, libmisc/shell/err.h, libmisc/shell/errx.c,
+ libmisc/shell/extern-cp.h, libmisc/shell/fts.c,
+ libmisc/shell/fts.h, libmisc/shell/main_cp.c,
+ libmisc/shell/utils-cp.c, libmisc/shell/verr.c,
+ libmisc/shell/verrx.c, libmisc/shell/vwarn.c,
+ libmisc/shell/vwarnx.c, libmisc/shell/warn.c,
+ libmisc/shell/warnx.c: New. Ported from BSD.
+ * libmisc/shell/shellconfig.h: Add the cp command.
+ * libmisc/Makefile.am: Add the new files to the shell.
+ * libmisc/shell/shell.c, libmisc/shell/shell.h: Add scripting
+ support.
+ * libblock/src/flashdisk.c: Fixed disk drive count size setting
+ bug.
+
+2007-12-21 Xi Yang <hiyangxi@gmail.com>
+
+ * rtems/src/semtranslatereturncode.c: Add support for proper stacking
+ of priority inheritance on mutexes as well as enforce proper order of
+ release.
+
+2007-12-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac, score/include/rtems/score/coremutex.h,
+ score/inline/rtems/score/coremutex.inl: Add the ability to disable
+ inlining coremutex seize. This reduces the code size and also
+ improves the process of coverage analysis.
+ * score/src/coremutexseizeintr.c: New file.
+
+2007-12-21 Xi Yang <hiyangxi@gmail.com>
+
+ * configure.ac, score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/thread.h,
+ score/inline/rtems/score/coremutex.inl,
+ score/src/coremutexsurrender.c, score/src/threadinitialize.c: Add
+ support for proper stacking of priority inheritance on mutexes as
+ well as enforce proper order of release.
+
+2007-12-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1268/cpukit
+ * libcsupport/include/rtems/assoc.h: There is no
+ rtems_assoc_ptr_by_value method.
+
+2007-12-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/sync.c: Make sync() POSIX-compliant.
+ * libcsupport/src/__gettod.c: Make gettimeofday() POSIX-compliant.
+
+2007-12-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/killinfo.c: Clean up and eliminate some dead code paths.
+
+2007-12-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/include/rtems/posix/timer.h: Include rtems/score/object.h.
+
+2007-12-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/tasks.h: Add
+ rtems_task_self() directive.
+ * rtems/src/taskself.c: New file.
+
+2007-12-20 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/Makefile.am, posix/src/kill.c, posix/src/killinfo.c: Split file
+ and resolved copyright information.
+ * posix/src/kill_r.c: New file.
+
+2007-12-20 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/src/ualarm.c: Fixed bug where iteration did not work correctly.
+
+2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Revert. Requires info not available at
+ preprocessing time.
+
+2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Catch the error when the user lowers the
+ maximum number of drivers below the number of statically configured
+ ones.
+
+2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/src/extension.c, sapi/src/extensioncreate.c,
+ sapi/src/extensiondelete.c, sapi/src/extensionident.c: Extension
+ Manager clean up. Update object id switches to new pattern. Catch
+ some NULL parameter errors.
+
+2007-12-19 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/src/psignalunblockthread.c: Remove source that
+
+2007-12-19 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/src/psignalchecksignal.c: Make assert active during debug mode
+ only
+
+2007-12-19 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ * posix/src/psignal.c: Move source around to enable path testing
+
+2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
+ libcsupport/src/free.c, libcsupport/src/malloc.c,
+ libcsupport/src/malloc_p.h,
+ libcsupport/src/malloc_report_statistics_plugin.c,
+ libmisc/shell/shell.c, libmisc/shell/shell.h,
+ score/src/objectinitializeinformation.c: Add posix_memalign. Split
+ out management of deferred frees to subroutines.
+ * libcsupport/src/malloc_deferred.c, libcsupport/src/posix_memalign.c: New files.
+
+2007-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/preinstall.am,
+ libcsupport/src/malloc.c, libcsupport/src/mallocinfo.c,
+ libmisc/Makefile.am, libmisc/shell/main_mallocinfo.c,
+ libmisc/shell/shellconfig.h: Split malloc.c into multiple files with
+ one function per file. Also split out statistics into a separate file
+ which can be plugged in dynamically. Right now, it is always in. I
+ suspect that splitting the file removed more code than leaving
+ statistics in. I tinkered with malloc information command in the
+ shell. I resurrected the malloc arena code as malloc boundary. This
+ code is now compiled all the time even though it does not appear to
+ work.
+ * libcsupport/include/rtems/malloc.h, libcsupport/src/_calloc_r.c,
+ libcsupport/src/_free_r.c, libcsupport/src/_malloc_r.c,
+ libcsupport/src/_realloc_r.c, libcsupport/src/calloc.c,
+ libcsupport/src/free.c, libcsupport/src/malloc_boundary.c,
+ libcsupport/src/malloc_get_statistics.c,
+ libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h,
+ libcsupport/src/malloc_report_statistics.c,
+ libcsupport/src/malloc_report_statistics_plugin.c,
+ libcsupport/src/malloc_statistics_helpers.c,
+ libcsupport/src/malloc_walk.c, libcsupport/src/realloc.c,
+ libmisc/shell/main_perioduse.c: New files.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_alias.c, libmisc/shell/main_blksync.c,
+ libmisc/shell/main_cat.c, libmisc/shell/main_cd.c,
+ libmisc/shell/main_chdir.c, libmisc/shell/main_chmod.c,
+ libmisc/shell/main_chroot.c, libmisc/shell/main_cpuuse.c,
+ libmisc/shell/main_date.c, libmisc/shell/main_dir.c,
+ libmisc/shell/main_exit.c, libmisc/shell/main_help.c,
+ libmisc/shell/main_id.c, libmisc/shell/main_logoff.c,
+ libmisc/shell/main_ls.c, libmisc/shell/main_mallocinfo.c,
+ libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
+ libmisc/shell/main_mfill.c, libmisc/shell/main_mkdir.c,
+ libmisc/shell/main_mmove.c, libmisc/shell/main_mount.c,
+ libmisc/shell/main_mount_ftp.c, libmisc/shell/main_mount_msdos.c,
+ libmisc/shell/main_mount_nfs.c, libmisc/shell/main_mount_tftp.c,
+ libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
+ libmisc/shell/main_pwd.c, libmisc/shell/main_rm.c,
+ libmisc/shell/main_rmdir.c, libmisc/shell/main_stackuse.c,
+ libmisc/shell/main_tty.c, libmisc/shell/main_umask.c,
+ libmisc/shell/main_unmount.c, libmisc/shell/main_whoami.c,
+ libmisc/shell/shell_cmdset.c, libmisc/shell/shellconfig.h: Change
+ rtems_Shell_ to rtems_shell_.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add malloc command
+ with info and dump as replacement for older command. Fix what looked
+ like a typo for mount sub-commands.
+ * libmisc/shell/main_mallocinfo.c: New file.
+ * libmisc/shell/main_mallocdump.c: Removed.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/src/mallocfreespace.c: Add
+ malloc_info() routine.
+ * libcsupport/src/mallocinfo.c: New file.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Add print of current stack pointer and
+ stack info even if stack checker is not initialized.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/printk.c: Style.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/threadqextractwithproxy.c: Conditionalize code that is only
+ required in multiprocessing configuration.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/objectget.c: Revert.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/timergettime.c: Include rtems/score/timespec.h
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/preinstall.am, posix/include/aio.h, posix/include/devctl.h,
+ posix/include/mqueue.h, posix/include/sched.h,
+ posix/include/semaphore.h, posix/include/rtems/posix/cancel.h,
+ posix/include/rtems/posix/priority.h,
+ posix/include/rtems/posix/psignal.h,
+ posix/include/rtems/posix/threadsup.h,
+ posix/include/rtems/posix/timer.h,
+ posix/inline/rtems/posix/priority.inl,
+ posix/src/barrierattrdestroy.c, posix/src/barrierattrgetpshared.c,
+ posix/src/barrierattrinit.c, posix/src/barrierattrsetpshared.c,
+ posix/src/cancel.c, posix/src/cancelrun.c, posix/src/cleanuppop.c,
+ posix/src/cleanuppush.c, posix/src/cond.c,
+ posix/src/condattrdestroy.c, posix/src/condattrgetpshared.c,
+ posix/src/condattrinit.c, posix/src/condattrsetpshared.c,
+ posix/src/condbroadcast.c, posix/src/conddefaultattributes.c,
+ posix/src/conddestroy.c, posix/src/condinit.c,
+ posix/src/condsignal.c, posix/src/condsignalsupp.c,
+ posix/src/condwait.c, posix/src/condwaitsupp.c, posix/src/key.c,
+ posix/src/keycreate.c, posix/src/keydelete.c,
+ posix/src/keygetspecific.c, posix/src/keyrundestructors.c,
+ posix/src/keysetspecific.c, posix/src/mqueue.c,
+ posix/src/mqueueclose.c, posix/src/mqueuecreatesupp.c,
+ posix/src/mqueuedeletesupp.c, posix/src/mqueuegetattr.c,
+ posix/src/mqueuenametoid.c, posix/src/mqueuenotify.c,
+ posix/src/mqueueopen.c, posix/src/mqueuereceive.c,
+ posix/src/mqueuerecvsupp.c, posix/src/mqueuesend.c,
+ posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c,
+ posix/src/mqueueunlink.c, posix/src/mutex.c,
+ posix/src/mutexattrdestroy.c, posix/src/mutexattrgetprioceiling.c,
+ posix/src/mutexattrgetprotocol.c, posix/src/mutexattrgetpshared.c,
+ posix/src/mutexattrinit.c, posix/src/mutexattrsetprioceiling.c,
+ posix/src/mutexattrsetprotocol.c, posix/src/mutexattrsetpshared.c,
+ posix/src/mutexdefaultattributes.c, posix/src/mutexdestroy.c,
+ posix/src/mutexgetprioceiling.c, posix/src/mutexlock.c,
+ posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c,
+ posix/src/mutextrylock.c, posix/src/mutexunlock.c,
+ posix/src/psignal.c, posix/src/psignalchecksignal.c,
+ posix/src/psignalclearprocesssignals.c,
+ posix/src/psignalclearsignals.c,
+ posix/src/psignalsetprocesssignals.c,
+ posix/src/psignalunblockthread.c, posix/src/ptimer.c,
+ posix/src/rwlockattrdestroy.c, posix/src/rwlockattrgetpshared.c,
+ posix/src/rwlockattrinit.c, posix/src/rwlockattrsetpshared.c,
+ posix/src/semaphore.c, posix/src/semaphoredeletesupp.c,
+ posix/src/semaphorenametoid.c, posix/src/semaphorewaitsupp.c,
+ posix/src/semclose.c, posix/src/semdestroy.c,
+ posix/src/semgetvalue.c, posix/src/seminit.c, posix/src/semopen.c,
+ posix/src/sempost.c, posix/src/semtrywait.c, posix/src/semunlink.c,
+ posix/src/semwait.c, posix/src/setcancelstate.c,
+ posix/src/setcanceltype.c, posix/src/sysconf.c,
+ posix/src/testcancel.c: Add missing copyright statements.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/mainpage.h: Sweep to make sure grep for COPYRIGHT passes.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/Makefile.am, posix/preinstall.am,
+ posix/include/rtems/posix/timer.h, score/src/objectget.c: Split POSIX
+ Timer implementation into multiple files. Add obvious error checks
+ for NULL parameters. Attempt to reduce include files.
+ * posix/src/timercreate.c, posix/src/timerdelete.c,
+ posix/src/timergetoverrun.c, posix/src/timergettime.c,
+ posix/src/timerinserthelper.c, posix/src/timersettime.c,
+ posix/src/timertsr.c: New files.
+ * posix/src/ptimer1.c: Removed.
+
+2007-12-17 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/main_blksync.c, libmisc/shell/main_msdosfmt.c,
+ libmisc/shell/main_unmount.c: New.
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add the
+ blksync, msdosfmt, and unmount commands.
+
+2007-12-17 Chris Johns <chrisj@rtems.org>
+
+ * libnetworking/rtems/tftp.h: Provide a decl to the TFTP file
+ system opts table.
+ * libnetworking/rtems/ftpfs.h: Provide a decl to the FTP file
+ system opts table.
+ * libmisc/Makefile.am: Add the mount command and supporting files.
+ * libmisc/preinstall.am: Rebuilt.
+ * libmisc/shell/cat_file.c, libmisc/shell/cmds.c,
+ libmisc/shell/main_alias.c, libmisc/shell/main_cat.c,
+ libmisc/shell/main_cd.c, libmisc/shell/main_chdir.c,
+ libmisc/shell/main_chmod.c, libmisc/shell/main_chroot.c,
+ libmisc/shell/main_cpuuse.c, libmisc/shell/main_date.c,
+ libmisc/shell/main_dir.c, libmisc/shell/main_exit.c,
+ libmisc/shell/main_help.c, libmisc/shell/main_id.c,
+ libmisc/shell/main_logoff.c, libmisc/shell/main_ls.c,
+ libmisc/shell/main_mallocdump.c, libmisc/shell/main_mdump.c,
+ libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c,
+ libmisc/shell/main_mkdir.c, libmisc/shell/main_mmove.c,
+ libmisc/shell/main_mwdump.c, libmisc/shell/main_pwd.c,
+ libmisc/shell/main_rm.c, libmisc/shell/main_rmdir.c,
+ libmisc/shell/main_stackuse.c, libmisc/shell/main_tty.c,
+ libmisc/shell/main_umask.c, libmisc/shell/main_whoami.c,
+ libmisc/shell/shell.c, libmisc/shell/shell_cmdset.c,
+ libmisc/shell/shell_makeargs.c, libmisc/shell/str2int.c,
+ libmisc/shell/write_file.c: Move all shell_* types, variables and
+ functions to rtems_shell_* to avoid namespace clashes with
+ applications. The is an RTEMS shell after all.
+ * libmisc/shell/shell.h, libmisc/shell/internal.h,
+ libmisc/shell/shellconfig.h: Move all shell_* types, variables and
+ functions to rtems_shell_* to avoid namespace clashes with
+ applications. Add the mount command supporting types.
+ * libmisc/shell/main_mount.c, libmisc/shell/main_mount_ftp.c,
+ libmisc/shell/main_mount_msdos.c, libmisc/shell/main_mount_nfs.c,
+ libmisc/shell/main_mount_tftp.c: New.
+
+2007-12-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Revert Joel's 2007-06-13 NDEBUG patch.
+
+2007-12-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/cat_file.c,
+ libmisc/shell/shell_makeargs.c, libmisc/shell/shellconfig.h: Rename
+ cmd_XXX.c to main_XXX.c. Add cpuuse and stackuse commands.
+ * libmisc/shell/main_alias.c, libmisc/shell/main_cat.c,
+ libmisc/shell/main_cd.c, libmisc/shell/main_chdir.c,
+ libmisc/shell/main_chmod.c, libmisc/shell/main_chroot.c,
+ libmisc/shell/main_cpuuse.c, libmisc/shell/main_date.c,
+ libmisc/shell/main_dir.c, libmisc/shell/main_exit.c,
+ libmisc/shell/main_help.c, libmisc/shell/main_id.c,
+ libmisc/shell/main_logoff.c, libmisc/shell/main_ls.c,
+ libmisc/shell/main_mallocdump.c, libmisc/shell/main_mdump.c,
+ libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c,
+ libmisc/shell/main_mkdir.c, libmisc/shell/main_mmove.c,
+ libmisc/shell/main_mwdump.c, libmisc/shell/main_pwd.c,
+ libmisc/shell/main_rm.c, libmisc/shell/main_rmdir.c,
+ libmisc/shell/main_stackuse.c, libmisc/shell/main_tty.c,
+ libmisc/shell/main_umask.c, libmisc/shell/main_whoami.c: New files.
+ * libmisc/shell/cmd_alias.c, libmisc/shell/cmd_cat.c,
+ libmisc/shell/cmd_cd.c, libmisc/shell/cmd_chdir.c,
+ libmisc/shell/cmd_chmod.c, libmisc/shell/cmd_chroot.c,
+ libmisc/shell/cmd_date.c, libmisc/shell/cmd_dir.c,
+ libmisc/shell/cmd_exit.c, libmisc/shell/cmd_help.c,
+ libmisc/shell/cmd_id.c, libmisc/shell/cmd_logoff.c,
+ libmisc/shell/cmd_ls.c, libmisc/shell/cmd_mallocdump.c,
+ libmisc/shell/cmd_mdump.c, libmisc/shell/cmd_medit.c,
+ libmisc/shell/cmd_mfill.c, libmisc/shell/cmd_mkdir.c,
+ libmisc/shell/cmd_mmove.c, libmisc/shell/cmd_mwdump.c,
+ libmisc/shell/cmd_pwd.c, libmisc/shell/cmd_rm.c,
+ libmisc/shell/cmd_rmdir.c, libmisc/shell/cmd_tty.c,
+ libmisc/shell/cmd_umask.c, libmisc/shell/cmd_whoami.c: Removed.
+
+2007-12-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am: _Thread_Rotate_ready_queue is only used by ITRON
+ API.
+
+2007-12-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/sleep.c, posix/src/usleep.c: Add copyright header.
+ * rtems/src/ratemonreportstatistics.c, rtems/src/timerserver.c:
+ Minor cleanup to improve testability and eliminate dead code.
+
+2007-12-12 Chris Johns <chrisj@rtems.org>
+
+ * libblock/include/rtems/flashdisk.h, libblock/src/flashdisk.c:
+ Add RTEMS license details.
+
+2007-12-12 Chris Johns <chrisj@rtems.org>
+
+ * Makefile.am, preinstall.am: Added
+ libblock/include/rtems/flashdisk.h to the installed header list.
+ * libblock/Makefile.am: Add flashdisk.c to the files to build.
+ * libblock/include/rtems/flashdisk.h, libblock/src/flashdisk.c:
+ New.
+
+2007-12-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/preinstall.am, posix/preinstall.am, rtems/Makefile.am,
+ rtems/preinstall.am, sapi/Makefile.am, sapi/preinstall.am,
+ score/Makefile.am, score/preinstall.am: Revert testing patch.
+
+2007-12-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/sched_rr_get_interval.c: Fix warning.
+
+2007-12-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/Makefile.am, posix/src/clockgetcpuclockid.c,
+ posix/src/clockgetenableattr.c, posix/src/clockgettime.c,
+ posix/src/clocksetenableattr.c, posix/src/clocksettime.c,
+ posix/src/devctl.c, posix/src/execl.c, posix/src/execle.c,
+ posix/src/execlp.c, posix/src/execv.c, posix/src/execve.c,
+ posix/src/execvp.c, posix/src/fork.c, posix/src/mutexinit.c,
+ posix/src/pthreadatfork.c, posix/src/pthreadgetcpuclockid.c,
+ posix/src/pthreadkill.c, posix/src/semaphorecreatesupp.c,
+ posix/src/sysconf.c, posix/src/wait.c, posix/src/waitpid.c: Split
+ files into one function per file.
+ * posix/src/aio_cancel.c, posix/src/aio_error.c, posix/src/aio_fsync.c,
+ posix/src/aio_read.c, posix/src/aio_return.c,
+ posix/src/aio_suspend.c, posix/src/aio_write.c,
+ posix/src/lio_listio.c, posix/src/sched_getparam.c,
+ posix/src/sched_getprioritymax.c, posix/src/sched_getprioritymin.c,
+ posix/src/sched_getscheduler.c, posix/src/sched_rr_get_interval.c,
+ posix/src/sched_setparam.c, posix/src/sched_setscheduler.c,
+ posix/src/sched_yield.c: New files.
+ * posix/src/aio.c, posix/src/sched.c, posix/src/types.c: Removed.
+
+2007-12-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/preinstall.am, posix/preinstall.am, posix/src/aio.c,
+ posix/src/clockgetcpuclockid.c, posix/src/clockgetenableattr.c,
+ posix/src/clockgettime.c, posix/src/clocksetenableattr.c,
+ posix/src/clocksettime.c, posix/src/devctl.c,
+ posix/src/pthreadcreate.c, posix/src/pthreadgetcpuclockid.c,
+ posix/src/types.c, rtems/preinstall.am, sapi/Makefile.am,
+ sapi/preinstall.am, score/Makefile.am, score/preinstall.am: Eliminate
+ POSIX_NOT_IMPLEMENTED(). Return ENOSYS instead.
+
+2007-12-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/src/adjtime.c: Clean up and verify against behavior documented
+ in GNU/Linux man page provided with Fedora 7.
+
+2007-12-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libgnat/Makefile.am, wrapup/Makefile.am: Another attempt at the
+ automake variables.
+
+2007-12-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/tasks.h,
+ rtems/src/tasks.c, rtems/src/taskvariableadd.c,
+ rtems/src/taskvariabledelete.c: Add test code for task variables to
+ improve coverage.
+ * rtems/src/taskvariable_invoke_dtor.c: New file.
+
+2007-12-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/preinstall.am: Revert debug patch.
+
+2007-12-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/shell/cmd_ls.c: Add include of <sys/stat.h> needed for UNIX
+ BSP.
+
+2007-12-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libgnat/Makefile.am: Handle POSIX being disabled correctly.
+
+2007-12-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am: Only used by ITRON so do not build if ITRON is
+ disabled.
+
+2007-12-12 Chris Johns <chrisj@rtems.org>
+
+ * Makefile.am: Added libmisc/shell/shellconfig.h to the installed
+ header list.
+ * libmisc/shell/shell_cmdset.c: Let the Initial command add occur
+ in any order rather than before any commands have been added. Also
+ made the command's strings be copies rather than references.
+ * sapi/src/ioregisterdriver.c: Return the I/O initialise calls result.
+
+2007-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, configure.ac, posix/Makefile.am, wrapup/Makefile.am:
+ Move Ada support code that is untestable from the Standard RTEMS Test
+ Suite into its own directory. All code in score, posix, rtems, and
+ sapi should be testable by the Standard RTEMS Test Suites. It was
+ buried under POSIX before so this should be a clearer location
+ anyway.
+ * libgnat/.cvsignore, libgnat/Makefile.am, libgnat/ada_intrsupp.c,
+ libgnat/adasupp.c: New files.
+ * posix/src/ada_intrsupp.c, posix/src/adasupp.c: Removed.
+
+2007-12-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/pheapallocatealigned.c, score/src/pheapgetblocksize.c:
+ Reverse file contents.
+
+2007-12-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/rtems/config.h: Correct idle task prototype.
+
+2007-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/shell/cmd_help.c, libmisc/shell/cmds.c,
+ libmisc/shell/internal.h, libmisc/shell/shell.c,
+ libmisc/shell/shell.h, libmisc/shell/shellconfig.h: Command set
+ processing now separated from main command loop. Addition of user
+ commands and aliases tested. Monitor registration now explicit.
+ * libmisc/shell/shell_cmdset.c, libmisc/shell/shell_makeargs.c,
+ libmisc/shell/write_file.c: New files.
+
+2007-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am: Fix typo.
+
+2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog, preinstall.am, libmisc/Makefile.am, libmisc/shell/cmds.c,
+ libmisc/shell/shell.c, libmisc/shell/shell.h: Split shell commands
+ into multiple files and add initial stages of command configuration.
+ This seems to work but the monitor commands need to be integrated
+ this way and the ability to configure user commands needs to be
+ tested.
+ * libmisc/shell/cat_file.c, libmisc/shell/cmd_alias.c,
+ libmisc/shell/cmd_cat.c, libmisc/shell/cmd_cd.c,
+ libmisc/shell/cmd_chdir.c, libmisc/shell/cmd_chmod.c,
+ libmisc/shell/cmd_chroot.c, libmisc/shell/cmd_date.c,
+ libmisc/shell/cmd_dir.c, libmisc/shell/cmd_exit.c,
+ libmisc/shell/cmd_help.c, libmisc/shell/cmd_id.c,
+ libmisc/shell/cmd_logoff.c, libmisc/shell/cmd_ls.c,
+ libmisc/shell/cmd_mallocdump.c, libmisc/shell/cmd_mdump.c,
+ libmisc/shell/cmd_medit.c, libmisc/shell/cmd_mfill.c,
+ libmisc/shell/cmd_mkdir.c, libmisc/shell/cmd_mmove.c,
+ libmisc/shell/cmd_mwdump.c, libmisc/shell/cmd_pwd.c,
+ libmisc/shell/cmd_rm.c, libmisc/shell/cmd_rmdir.c,
+ libmisc/shell/cmd_tty.c, libmisc/shell/cmd_umask.c,
+ libmisc/shell/cmd_whoami.c, libmisc/shell/internal.h,
+ libmisc/shell/shellconfig.c, libmisc/shell/shellconfig.h,
+ libmisc/shell/str2int.c: New files.
+
+2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/cpu/no_cpu/rtems/score/cpu.h: Fix Doxygen.
+
+2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/config.h: Fix idle thread prototype.
+
+2007-12-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Separate the concept of configuring the
+ interrupt stack size from actually reserving memory for it in the
+ RTEMS Workspace.
+
+2007-12-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * httpd/Makefile.am, httpd/preinstall.am: rtems_webserver.h must be
+ installed. It is the initialization interface for both GoAhead and
+ Simple HTTPD.
+
+2007-12-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/config.h: Correct previous commit.
+
+2007-12-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/rtems/config.h: Commit temporary fix so
+ interrupt_stack_size is accessible before RTEMS is initialized.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/init.h, sapi/src/exinit.c,
+ score/include/rtems/system.h, score/src/isr.c: Move
+ interrupt_stack_size field from CPU Table to Configuration Table.
+ Eliminate CPU Table from all ports. Delete references to CPU Table in
+ all forms.
+
+2007-12-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/rtems/config.h: Add accessory macros for Configuration
+ Table fields merged from CPU Table.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/malloc.c, libmisc/monitor/mon-command.c,
+ posix/preinstall.am, posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/semaphore.h, posix/src/conddestroy.c,
+ posix/src/mutexdestroy.c, posix/src/mutexinit.c,
+ posix/src/mutexsetprioceiling.c, posix/src/mutexunlock.c,
+ sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/init.h, sapi/include/rtems/sptables.h,
+ sapi/src/exinit.c, score/include/rtems/system.h,
+ score/include/rtems/score/mpci.h, score/src/mpci.c,
+ score/src/thread.c, score/src/threadcreateidle.c,
+ score/src/threadstackallocate.c, score/src/threadstackfree.c,
+ score/src/wkspace.c: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-12-03 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/shell/shell.h: Added comments for the parameters to the
+ shell_init function.
+ * libmisc/shell/shell.c: Only set cflags if tcflags is
+ non-zero. This means the shell can use the current cflags settings
+ and the application does not need to know the baudrate etc.
+ * libmisc/capture/capture.h: Fix the comment.
+
+2007-11-30 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/barrierdelete.c, rtems/src/barrierrelease.c,
+ rtems/src/barriertranslatereturncode.c, rtems/src/barrierwait.c,
+ rtems/src/clockget.c, rtems/src/dpmemdelete.c,
+ rtems/src/dpmemexternal2internal.c,
+ rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c,
+ rtems/src/eventtimeout.c, rtems/src/msgqbroadcast.c,
+ rtems/src/msgqdelete.c, rtems/src/msgqflush.c,
+ rtems/src/msgqgetnumberpending.c, rtems/src/msgqreceive.c,
+ rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/partdelete.c,
+ rtems/src/partgetbuffer.c, rtems/src/partreturnbuffer.c,
+ rtems/src/ratemoncancel.c, rtems/src/ratemondelete.c,
+ rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c,
+ rtems/src/ratemontimeout.c, rtems/src/semdelete.c,
+ rtems/src/semflush.c, rtems/src/semobtain.c, rtems/src/semrelease.c,
+ rtems/src/semtranslatereturncode.c, rtems/src/signalsend.c,
+ rtems/src/taskdelete.c, rtems/src/taskgetnote.c,
+ rtems/src/taskissuspended.c, rtems/src/taskrestart.c,
+ rtems/src/taskresume.c, rtems/src/tasksetnote.c,
+ rtems/src/tasksetpriority.c, rtems/src/taskstart.c,
+ rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c,
+ rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c,
+ rtems/src/timercancel.c, rtems/src/timerdelete.c,
+ rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c,
+ rtems/src/timerreset.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c: Restructured all code with
+ the switch (location) pattern so that OBJECTS_LOCAL is first
+ and we can fall into it and the OBJECTS_ERROR case breaks
+ to a return RTEMS_INVALID_ID. This eliminates the return
+ RTEMS_INTERNAL_ERROR at the bottom of each of these files which
+ was unreachable and untestable code. This resulted in a code
+ savings of approximately 20 bytes per file on the SPARC/ERC32.
+
+2007-11-30 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * posix/Makefile.am: Restructed to move the
+ OBJECTS_LOCAL case to the top of the switch statement and
+ eliminate the fall-through return of POSIX_BOTTOM_REACHED. These
+ changes produced simplier assembly code and allowed for complete
+ test coverage. Also applied some consistency to the functions
+ that translate the core status codes to POSIX status codes.
+
+2007-11-30 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/semaphore.h, posix/src/cancel.c,
+ posix/src/conddestroy.c, posix/src/condsignalsupp.c,
+ posix/src/condwaitsupp.c, posix/src/keydelete.c,
+ posix/src/keygetspecific.c, posix/src/keysetspecific.c,
+ posix/src/mqueueclose.c, posix/src/mqueuegetattr.c,
+ posix/src/mqueuenotify.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c,
+ posix/src/mqueuetranslatereturncode.c, posix/src/mutexdestroy.c,
+ posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c,
+ posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c,
+ posix/src/mutexunlock.c, posix/src/pbarrierdestroy.c,
+ posix/src/pbarriertranslatereturncode.c, posix/src/pbarrierwait.c,
+ posix/src/prwlockdestroy.c, posix/src/prwlockrdlock.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/prwlocktranslatereturncode.c, posix/src/prwlocktryrdlock.c,
+ posix/src/prwlocktrywrlock.c, posix/src/prwlockunlock.c,
+ posix/src/prwlockwrlock.c, posix/src/pspindestroy.c,
+ posix/src/pspinlock.c, posix/src/pspinlocktranslatereturncode.c,
+ posix/src/pspintrylock.c, posix/src/pspinunlock.c,
+ posix/src/pthreaddetach.c, posix/src/pthreadequal.c,
+ posix/src/pthreadgetschedparam.c, posix/src/pthreadjoin.c,
+ posix/src/pthreadkill.c, posix/src/pthreadsetschedparam.c,
+ posix/src/ptimer1.c, posix/src/semaphorewaitsupp.c,
+ posix/src/semclose.c, posix/src/semdestroy.c,
+ posix/src/semgetvalue.c, posix/src/sempost.c, posix/src/types.c,
+ rtems/src/msgqtranslatereturncode.c, rtems/src/semobtain.c,
+ rtems/src/timerfireafter.c, score/include/rtems/system.h,
+ score/include/rtems/score/corebarrier.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h: Restructed to move the
+ OBJECTS_LOCAL case to the top of the switch statement and
+ eliminate the fall-through return of POSIX_BOTTOM_REACHED. These
+ changes produced simplier assembly code and allowed for complete
+ test coverage. Also applied some consistency to the functions
+ that translate the core status codes to POSIX status codes.
+ * posix/src/mutextranslatereturncode.c,
+ posix/src/semaphoretranslatereturncode.c: New files.
+ * posix/src/mutexfromcorestatus.c: Removed.
+
+2007-11-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/inline/rtems/posix/priority.inl: Fix typo.
+
+2007-11-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/src/exinit.c, score/include/rtems/score/object.h,
+ score/include/rtems/score/thread.h, score/src/object.c,
+ score/src/thread.c: Conditionally compile out more code that is
+ specific to multiprocessor configurations.
+
+2007-11-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am, posix/preinstall.am, posix/src/cancel.c,
+ posix/src/conddestroy.c, posix/src/condinit.c,
+ posix/src/condsignalsupp.c, posix/src/condwaitsupp.c,
+ posix/src/mqueueclose.c, posix/src/mqueuecreatesupp.c,
+ posix/src/mqueuedeletesupp.c, posix/src/mqueuegetattr.c,
+ posix/src/mqueuenotify.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c,
+ posix/src/mqueueunlink.c, posix/src/mutexattrdestroy.c,
+ posix/src/mutexattrgetprioceiling.c,
+ posix/src/mutexattrgetprotocol.c, posix/src/mutexattrgetpshared.c,
+ posix/src/mutexattrinit.c, posix/src/mutexattrsetprioceiling.c,
+ posix/src/mutexattrsetprotocol.c, posix/src/mutexattrsetpshared.c,
+ posix/src/mutexdefaultattributes.c, posix/src/mutexdestroy.c,
+ posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c,
+ posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c,
+ posix/src/mutexunlock.c, posix/src/semaphorecreatesupp.c,
+ posix/src/semaphoredeletesupp.c, posix/src/semaphorewaitsupp.c,
+ posix/src/semclose.c, posix/src/semdestroy.c,
+ posix/src/semgetvalue.c, posix/src/sempost.c, posix/src/semunlink.c,
+ posix/src/types.c, score/cpu/powerpc/rtems/old-exceptions/cpu.h:
+ Remove all pretense of POSIX MP support. The support in place was
+ only a shell. This should make maintenance easier.
+ * posix/include/rtems/posix/condmp.h,
+ posix/include/rtems/posix/mqueuemp.h,
+ posix/include/rtems/posix/mutexmp.h,
+ posix/include/rtems/posix/pthreadmp.h,
+ posix/include/rtems/posix/semaphoremp.h, posix/src/condmp.c,
+ posix/src/mutexmp.c, posix/src/semaphoremp.c: Removed.
+
+2007-11-27 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac, score/inline/rtems/score/thread.inl,
+ score/src/threaddispatch.c: Add ability for user to disable inlining
+ of _Thread_Enable_dispatch. This can save code space but more
+ importantly it means the binary generated does not have code inlined
+ that is difficult to test and very seldom executed.
+
+2007-11-27 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ rtems/include/rtems/rtems/barrier.h,
+ score/src/corerwlockobtainread.c, score/src/corerwlockobtainwrite.c,
+ score/src/corerwlockrelease.c: Fixed several implementation errors.
+
+2007-11-27 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * rtems/src/regioncreate.c, rtems/src/regiondelete.c,
+ rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/regionreturnsegment.c: Restructed to move the OBJECTS_LOCAL
+ case to the top of the switch statement, have a single exit with one
+ call to _RTEMS_Unlock_allocator and eliminate the fall-through return
+ of RTEMS_INTERNAL_ERROR. These changes produced simplier assembly
+ code and allowed for complete test coverage.
+
+2007-11-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h,
+ score/cpu/powerpc/rtems/old-exceptions/cpu.h: Add
+ CONFIGURE_APPLICATION_EXTRA_DRIVERS.
+
+2007-11-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Add CONFIGURE_APPLICATION_EXTRA_DRIVERS.
+
+2007-11-27 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libnetworking/netinet/in_cksum.c: ARM optimized version does not
+ support Thumb.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * telnetd/pty.c, telnetd/telnetd.c, telnetd/telnetd.h: Style clean up.
+ Now works on gen5200/icecube.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/printk.c, score/src/objectget.c: Fix spacing.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc.c: Do not assert on free of bad pointer.
+
+2007-11-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/thread.h: Fix spelling error.
+
+2007-11-17 Till Straumann <strauman@slac.stanford.edu>
+
+ * libi2c/libi2c.c, libi2c/libi2c.h, libi2c/README_libi2c:
+ Added checks so that use of 'stdio' is avoided (falling
+ back to 'printk') before the system is up.
+ Publish driver entry points so that the libi2c driver could
+ be added to the applications 'device driver table'.
+ This is not fully implemented yet, though, since in addition to
+ initializing libi2c the low-level i2c bus drivers as well
+ as high-level i2c device drivers need to be registered
+ with the library.
+ Updated README_libi2c accordingly.
+
+2007-11-17 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/rtems/rtems_glue.c: let rtems_bsdnet_ifconfig
+ (SIOCGIFMEDIA) pass the user parameter down to the ioctl
+ so that it knows what PHY they want to look at.
+
+2007-11-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/apimutexlock.c, score/src/apimutexunlock.c: Functions were
+ in opposite files. Whoops!
+
+2007-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/shell.c, libmisc/shell/shell.h: Much cleanup but much
+ of the focus was on the beginning stages of making the login checker
+ pluggable just like the shell.
+
+2007-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/mprotect.c: Update comments.
+
+2007-11-09 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am: Add support for Ada95 interrupt tasks. This
+ will require gcc 4.3 or newer.
+ * posix/src/ada_intrsupp.c: New file.
+
+2007-11-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/src/exinit.c, score/Makefile.am,
+ score/include/rtems/score/apimutex.h: API Mutex calls should never
+ have been inlined. Inlining them lead to many inlined copies of core
+ mutex lock. This lead to over 2K savings in the SPARC/ERC32
+ minimum.exe.
+ * score/src/apimutex.c, score/src/apimutexallocate.c,
+ score/src/apimutexlock.c, score/src/apimutexunlock.c: New files.
+
+2007-11-07 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/include/rtems/score/isr.h: added RTEMS_COMPILER_MEMORY_BARRIER
+ around _CPU_ISR_Set_level().
+
+2007-11-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/inline/rtems/score/object.inl: During test coverage analysis,
+ we identified this sanity check which should have been conditional on
+ RTEMS_DEBUG since it can NOT be tripped during normal RTEMS
+ operations. With all APIs enabled, this saved 352 bytes from the
+ minimum executable on the SPARC/ERC32.
+
+2007-11-07 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/system.h, score/include/rtems/score/interr.h: Add
+ compiler conditional attribute for methods that do not return. This
+ avoids gcc generating unreachable code following calls to
+ _Internal_error_Occurred.
+
+2007-11-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac: Add ARM/Thumb Makefile.
+
+2007-11-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1266/cpukit
+ * posix/src/keycreate.c, posix/src/keyrundestructors.c: Use API instead
+ of class for key indexing.
+
+2007-11-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * telnetd/icmds.c, telnetd/pty.c, telnetd/telnetd.c, telnetd/telnetd.h:
+ Fix headers and formatting.
+
+2007-11-06 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ Miscellaneous changes made after a review against the POSIX spec.
+ * posix/src/pbarrierinit.c, posix/src/prwlockinit.c: If the caller
+ passes a NULL in the attributes parameter, default attributes are used.
+ * posix/src/prwlockdestroy.c: If there is at least one thread
+ waiting, do not allow deletion.
+ * posix/src/prwlockwrlock.c: Corrected parameter passed to the core
+ operation used to obtain a RWLock for writing.
+ * posix/src/pspinlocktranslatereturncode.c,
+ score/include/rtems/score/corespinlock.h,
+ score/src/corespinlockrelease.c: If the current thread is not the
+ holder of the lock, do not allow an unlock and return EPERM.
+ * score/src/corerwlockobtainwrite.c: Corrected to use the operation
+ for queueing with a timeout handler.
+
+2007-11-02 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/cpu/sparc/cpu.c, score/cpu/sparc/rtems/score/cpu.h,
+ score/include/rtems/score/context.h, score/src/threadhandler.c: Fix
+ stack so gdb backtrace does not print corrupted frame message after
+ _Thread_Handler. Daniel Hellstrom <daniel@gaisler.com> provided the
+ SPARC implementation and I made it more general.
+
+2007-10-26 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * libmisc/cpuuse/cpuusagereport.c, rtems/src/ratemonreportstatistics.c:
+ Cleaned up reports and fixed a bug related the printf format which
+ resulted in lack of leading zeroes and misleading magnitude.
+ * score/src/timespecdivide.c: Fixed bugs related to zero divide case.
+
+2007-10-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * itron/src/can_wup.c, itron/src/chg_pri.c, itron/src/del_mbf.c,
+ itron/src/del_mbx.c, itron/src/del_sem.c, itron/src/del_tsk.c,
+ itron/src/frsm_tsk.c, itron/src/ref_mbf.c, itron/src/ref_mbx.c,
+ itron/src/ref_sem.c, itron/src/ref_tsk.c, itron/src/rel_wai.c,
+ itron/src/rsm_tsk.c, itron/src/sig_sem.c, itron/src/snd_mbx.c,
+ itron/src/sta_tsk.c, itron/src/sus_tsk.c, itron/src/ter_tsk.c,
+ itron/src/trcv_mbf.c, itron/src/trcv_mbx.c, itron/src/tsnd_mbf.c,
+ itron/src/twai_sem.c, posix/src/cancel.c, posix/src/conddestroy.c,
+ posix/src/condinit.c, posix/src/condsignalsupp.c,
+ posix/src/condwaitsupp.c, posix/src/keydelete.c,
+ posix/src/keygetspecific.c, posix/src/keysetspecific.c,
+ posix/src/mqueueclose.c, posix/src/mqueuegetattr.c,
+ posix/src/mqueuenotify.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c,
+ posix/src/mutexdestroy.c, posix/src/mutexgetprioceiling.c,
+ posix/src/mutexinit.c, posix/src/mutexlocksupp.c,
+ posix/src/mutexsetprioceiling.c, posix/src/mutexunlock.c,
+ posix/src/pbarrierdestroy.c, posix/src/pbarrierwait.c,
+ posix/src/prwlockdestroy.c, posix/src/prwlockrdlock.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/prwlocktryrdlock.c, posix/src/prwlocktrywrlock.c,
+ posix/src/prwlockunlock.c, posix/src/prwlockwrlock.c,
+ posix/src/pspindestroy.c, posix/src/pspinlock.c,
+ posix/src/pspintrylock.c, posix/src/pspinunlock.c,
+ posix/src/pthreaddetach.c, posix/src/pthreadequal.c,
+ posix/src/pthreadgetschedparam.c, posix/src/pthreadjoin.c,
+ posix/src/pthreadkill.c, posix/src/pthreadsetschedparam.c,
+ posix/src/ptimer1.c, posix/src/semaphorewaitsupp.c,
+ posix/src/semclose.c, posix/src/semdestroy.c,
+ posix/src/semgetvalue.c, posix/src/sempost.c, posix/src/types.c,
+ rtems/src/barrierdelete.c, rtems/src/barrierrelease.c,
+ rtems/src/barrierwait.c, rtems/src/dpmemdelete.c,
+ rtems/src/dpmemexternal2internal.c,
+ rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c,
+ rtems/src/eventtimeout.c, rtems/src/msgqbroadcast.c,
+ rtems/src/msgqdelete.c, rtems/src/msgqflush.c,
+ rtems/src/msgqgetnumberpending.c, rtems/src/msgqreceive.c,
+ rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/partdelete.c,
+ rtems/src/partgetbuffer.c, rtems/src/partreturnbuffer.c,
+ rtems/src/ratemoncancel.c, rtems/src/ratemondelete.c,
+ rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c,
+ rtems/src/ratemontimeout.c, rtems/src/regiondelete.c,
+ rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/regionreturnsegment.c, rtems/src/semdelete.c,
+ rtems/src/semflush.c, rtems/src/semobtain.c, rtems/src/semrelease.c,
+ rtems/src/signalsend.c, rtems/src/taskdelete.c,
+ rtems/src/taskgetnote.c, rtems/src/taskissuspended.c,
+ rtems/src/taskrestart.c, rtems/src/taskresume.c,
+ rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c,
+ rtems/src/taskstart.c, rtems/src/tasksuspend.c,
+ rtems/src/taskvariableadd.c, rtems/src/taskvariabledelete.c,
+ rtems/src/taskvariableget.c, rtems/src/timercancel.c,
+ rtems/src/timerdelete.c, rtems/src/timerfireafter.c,
+ rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c,
+ rtems/src/timerreset.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c, sapi/src/extensiondelete.c,
+ score/include/rtems/score/object.h, score/src/corerwlocktimeout.c,
+ score/src/mpci.c, score/src/objectgetnameasstring.c,
+ score/src/threaddelayended.c, score/src/threadqtimeout.c: When
+ multiprocessing is disabled, do not even allow the constant
+ OBJECTS_REMOTE to appear in the source. Even at -O2, the presence of
+ a case OBJECTS_REMOTE in each id->pointer _Objects_Get switch results
+ in the generation of binary code which can NOT be reached.
+
+2007-10-26 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/Makefile.am, score/include/rtems/score/thread.h,
+ score/inline/rtems/score/thread.inl: No longer inline _Thread_Get. It
+ resulted in unnessary code explosion, many uncovered paths when
+ looking at binary executable coverage, and only optimized getting
+ self. Id translations were still getting pushed to a subroutine call
+ to _Objects_Get. Later the non-inlined version can be further
+ optimized to get Ids in range for the current API, then self, then
+ look at other APIs.
+ * score/src/threadget.c: New file.
+
+2007-10-26 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libi2c/README-libi2c
+ document structure of libi2c library
+
+2007-10-25 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libi2c/libi2c.c, libi2c/libi2c.h:
+ extend API to support SPI devices
+ made libi2c.h C++-proof
+
+2007-10-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/assoc.c: Removed. Accidentally included routine
+ also in another file. Mistake after splitting.
+ * libcsupport/Makefile.am: Reflect file removal.
+
+2007-10-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netdb.h, libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/getnetnamadr.c: Adjust to POSIX.
+ Minor updates from FreeBSD.
+
+2007-10-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/copyrt.h: Update year.
+
+2007-10-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/copyrt.h: Update year.
+
+2007-10-11 Daniel Hellstrom <daniel@gaisler.com>
+
+ * libi2c/libi2c.c, libi2c/libi2c.h: Add message about needing IMFS.
+ Fixed check of status when registering driver. Add use of strerror().
+
+2007-10-04 Keith Robertson <kjrobert@alumni.uwaterloo.ca>,
+ Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/ifaddrs.h, libnetworking/libc/getifaddrs.c,
+ libnetworking/libc/if_indextoname.c,
+ libnetworking/libc/if_nameindex.c: New (from FreeBSD)
+ * Makefile.am: Add files above.
+ * libnetworking/net/if.h: Add if_nameindex (from FreeBSD).
+
+2007-09-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Eliminate output with little information.
+ Always print a blown message using the same routine. Now works with
+ GNAT RTS -fstack-checking if you have patch for the RTEMS specific
+ support in your GCC version.
+
+2007-09-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/gxx_wrappers.c: Revert.
+
+2007-09-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/gxx_wrappers.c, libmisc/monitor/mon-mpci.c: Use
+ PRId32 to fix warning.
+
+2007-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * telnetd/passwd.h: New file.
+
+2007-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * telnetd/README, telnetd/pty.c, telnetd/pty.h, telnetd/telnetd.c,
+ telnetd/telnetd.h: telnetd rewrite.
+ * telnetd/check_passwd.c, telnetd/des.c, telnetd/genpw.c: New files.
+
+2007-09-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1262/filesystem
+ * libcsupport/Makefile.am, libnetworking/libc/herror.c,
+ libnetworking/libc/res_send.c, libnetworking/sys/uio.h,
+ telnetd/Makefile.am, telnetd/README, telnetd/preinstall.am,
+ telnetd/pty.c, telnetd/telnetd.c: Add support for readv() and
+ writev() including documentation and test case.
+ * libcsupport/src/readv.c, libcsupport/src/writev.c: New files.
+
+2007-09-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libnetworking/Makefile.am: Add dummy socketpair() implementation to
+ document what is required to provide a fully functional
+ implementation.
+ * libnetworking/rtems/rtems_socketpair.c: New file.
+
+2007-09-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/version.m4: Bump RTEMS_API to 4.9.
+ Bump RTEMS_VERSION to 4.8.99.0.
+
+2007-09-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/read.c, libcsupport/src/write.c: Fix spacing.
+
+2007-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/semaphorecreatesupp.c: Fixed warning.
+
+2007-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/dumpbuf/dumpbuf.c: Use printk.
+
+2007-09-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/ppp_defs.h: Include rtems/stdint.h.
+ Use uint32_t for ext_accm.
+
+2007-09-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/auth.c, pppd/demand.c, pppd/ipcp.c, pppd/ipcp.h,
+ pppd/lcp.c, pppd/lcp.h, pppd/magic.c, pppd/magic.h, pppd/options.c,
+ pppd/pppd.h, pppd/sys-rtems.c, pppd/utils.c: Convert to using C99
+ fixed-size types instead of BSD fixed-size types.
+
+2007-09-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Fix alignment of output.
+
+2007-09-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/monitor.h: Add network commands that were in the
+ network supplement but not in the code.
+ * libmisc/monitor/mon-network.c: New file.
+
+2007-09-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1261/cpukit
+ * posix/src/semaphorecreatesupp.c: Initialize all fields during
+ semaphore creation.
+
+2007-09-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1260/cpukit
+ * posix/src/pthread.c: Get initial signals blocked from creating
+ thread not from ourselves.
+
+2007-09-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/watchdogtickle.c: Remove tabs.
+
+2007-09-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1259/rtems
+ * rtems/src/taskcreate.c: Initialize is_global in all cases since
+ memory is not guaranteed to be zero.
+
+2007-09-12 Sergei Organov <osv@javad.com>
+
+ PR 1258/rtems
+ * cpukit/score/src/heapallocatealigned.c (block_allocate): New routine.
+ * cpukit/score/src/heapallocatealigned.c (_Heap_Allocate_aligned):
+ Use block_allocate() instead of _Heap_Block_allocate(). Replace
+ _Heap_Head(the_heap)->next with equivalent _Heap_First(the_heap).
+ * cpukit/score/src/heap.c (_Heap_Allocate): fix comments according
+ to changed block split strategy in _Heap_Allocate_aligned().
+
+2007-09-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/printk.c: Remove unnecessary comments.
+
+2007-09-10 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libmisc/monitor/mon-monitor.c:
+ Corrected linked list of rtems_monitor_commands
+
+2007-09-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc.c: If RTEMS_HEAP_DEBUG is defined, add heap
+ walk on init, malloc, and free. The ability to walk the heap appears
+ to disappeared during the rework of the C Program heap to skip the
+ Region.
+
+2007-09-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/heap.c: Style.
+ * score/src/heapwalk.c: Add more information to prints.
+ * score/src/pheapwalk.c: Do not lock allocator mutex if dispatching
+ is disabled.
+
+2007-09-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/src/printk.c:
+ * libcsupport/src/printk_plugin.c: New file.
+ include/rtems/bspIo.h, libmisc/cpuuse/cpuusagereport.c,
+ libmisc/cpuuse/cpuuse.h, libmisc/stackchk/check.c,
+ libmisc/stackchk/stackchk.h: rtems/include/rtems/rtems/ratemon.h,
+ rtems/src/ratemonreportstatistics.c: Added capability to specify
+ your own "printf" routine to various reporting functions. This
+ added an XXX_with_plugin as the underlying implementation for
+ + rtems_rate_monotonic_report_statistics
+ + rtems_stack_checker_report_usage
+ + rtems_cpu_usage_report
+ As demonstration, the http netdemo can now print out stack
+ and cpu usage reports.
+
+2007-09-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * shttpd/compat_rtems.c: Style clean up.
+
+2007-09-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/ratemonperiod.c: Clean up.
+ * rtems/src/ratemonreportstatistics.c: Clarify period statistics output.
+
+2007-09-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-monitor.c: Fix warnings and typo.
+
+2007-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/untar/untar.c, libmisc/untar/untar.h: Clean up prototype.
+
+2007-09-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am: Add new files.
+
+2007-09-05 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libmisc/monitor/mon-object.c,
+ * libmisc/monitor/monitor.h, libmisc/monitor/mon-part.c,
+ * libmisc/monitor/mon-region.c, libmisc/monitor/mon-sema.c,
+ * libmisc/monitor/mon-task, libmisc/Makefile.am:
+ Added functionality for osmonweb support
+
+2007-09-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/monitor.h: Merge minor parts of Thomas' improvements
+ that are needed by osmonweb.
+
+2007-09-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/untar/untar.c, libmisc/untar/untar.h: Add const to char *.
+ Use printk.
+
+2007-08-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/include/rtems/rtems/clock.h, score/src/threadhandler.c: Fix
+ spacing and spelling.
+
+2007-08-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1256/networking
+ * ftpd/ftpd.c: Fix unaligned access.
+
+2007-08-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/Makefile.am: Always build nanosleep.
+
+2007-08-17 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/capture/README: Minor copyright change.
+ * libmisc/capture/capture-cli.c, libmisc/capture/capture.c,
+ libmisc/capture/capture.h: Fixed the memory leak when lots of
+ tasks are being created and deleted. Improved the trigger
+ interface so all task type actions can be caught.
+
+2007-08-13 Chris Johns <chrisj@rtems.org>
+
+ * score/include/rtems/score/object.h: Point the
+ OBJECTS_RTEMS_CLASSES_LAST macro to the last entry.
+
+2007-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1248/networking
+ * libnetworking/rtems/rtems_glue.c: Luke Stras <luke@spacequest.com>
+ reported that when no interfaces are successfully attached, the
+ default route is broken and may result in a jump to an illegal
+ address.
+
+2007-07-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/inline/rtems/score/priority.inl: Use size_t instead of
+ uint32_t for array index.
+
+2007-07-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/in_cksum_m68k.h: Use __mcoldfire__ to
+ identify coldfire cpus.
+
+2007-07-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/log.c: Activate SPLIT_SNPRINTF for gcc <= 4.2.1 and
+ coldfire.
+
+2007-07-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/log.c: Add preliminary version of SPLIT_SNPRINTF to
+ work-around bug m68k/coldfire -fomit-frame-pointer bug
+ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32307.
+
+2007-07-27 Chris Johns <chrisj@rtems.org>
+
+ * wrapup/Makefile.am: Create archive from a file for hosts
+ with a limited command line size.
+
+2007-07-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/bspIo.h, include/rtems/pci.h:
+ Add extern "C" guards. Reported by
+ Robert S. Grimes <rsg@alum.mit.edu>.
+
+2007-07-24 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/cpuuse/cpuusagereport.c, libmisc/cpuuse/cpuusagereset.c,
+ score/src/timespecdivide.c: Fix various math and reporting bugs. Now
+ the time appears to be reported correctly and add up to what is
+ expected.
+
+2007-07-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/Makefile.am: Prefix all non-public symbols with _shttp_.
+ * shttpd/compat_rtems.c: Don't build my_stat for rtems.
+ * shttpd/defs.h: Don't build most of my_* wrappers for rtems.
+
+2007-07-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/cpuuse/cpuusagereport.c,
+ libmisc/cpuuse/cpuusagereset.c: Fix bug where cpu usage calculation
+ was always using uptime not time since last cpu usage reset when
+ using nanoseconds granularity.
+ * libmisc/cpuuse/cpuusagedata.c: New file.
+
+2007-07-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/mount.c: Allow null for output parameter.
+
+2007-07-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * shttpd/compat_rtems.c, shttpd/compat_rtems.h: Add port to listen on
+ to shttpd initialization.
+
+2007-07-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/malloc.c: Clean up Malloc debug code.
+ * score/include/rtems/score/heap.h: Spacing.
+ * score/inline/rtems/score/thread.inl:
+ * score/src/heapfree.c. Clean up and add explicit check of the address
+ being freed actually being in the heap.
+ * score/src/heapwalk.c: Switch to printk and do not call abort.
+
+2007-07-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/stackchk/check.c: Make checking the integrity of the pattern
+ area contingent on the stack checker user extension having been
+ initialized.
+
+2007-06-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libnetworking/rtems/rtems_syscall.c: Remove RTEMS versions of send()
+ and recv(). We already had the BSD versions and these conflict
+ sometimes when linking.
+
+2007-06-21 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libnetworking/rtems/mkrootfs.h, libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h: Add extern __cplusplus.
+
+2007-06-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Do not instantiate initialization
+ thas/thread pointer tables for an API that is not configured.
+
+2007-06-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am:
+ * libcsupport/src/open_dev_console.c: New file.
+
+2007-06-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/corerwlock.c: Make sure structure is fully initialized.
+ When reused, some fields will not be zero like at initialization.
+
+2007-06-20 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: POSIX threads use twice the minimum stack
+ size. Account for this.
+
+2007-06-13 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * configure.ac: Add NDEBUG as a command line compilation option.
+
+2007-06-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmd/.cvsignore: New file.
+
+2007-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/defs.h: Eliminate my_strncasecmp.
+ * shttpd/string.c: Eliminate my_strncasecmp.
+
+2007-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * wrapup/Makefile.am: Pickup ../libmd/libmd.a.
+ * pppd/Makefile.am: Reflect moving out md*.
+ * pppd/md4.h, pppd/md4.c, pppd/md5.c, pppd/md5.h: Remove (moved to
+ libmd).
+ * libmd/Makefile.am, libmd/md4.c, libmd/md4.h, libmd/md5.c,
+ libmd/md5.h, libmd/preinstall.am: New (moved out from pppd).
+ * configure.ac, Makefile.am: Add libmd.
+
+2007-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/defs.h: Eliminate my_strlcpy.
+ * shttpd/string.c: Eliminate my_strlcpy.
+
+2007-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/defs.h: Eliminate my_strdup, my_strndup.
+ * shttpd/string.c: Eliminate my_strdup, my_strndup.
+ * shttpd/Makefile.am: Add -DHAVE_MD5 to use md5 routines from
+ libmd.a.
+
+2007-06-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * wrapup/Makefile.am: Add libmd.a.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/Makefile.am: Remove md5 and md4 from libpppd.a.
+ Add pppd/libmd.a.
+ * pppd/md4.c: Don't include pppd.h.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/shttpd.ico, shttpd/resources.rc: Remove (Unused).
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/Makefile.am: Conditionally build on LIBNETWORKING.
+ * shttpd/compat_rtems.h: Include <arpa/inet.h>.
+ Add config.h support.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/compat_rtems.h: Define closesocket.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * shttpd/compat_rtems.h: Add IS_DIRSEP_CHAR.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+ * shttpd/compat_rtems.h, shttpd/compat_rtems.c:
+ Use size_t for stack sizes.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac, Makefile.am: Add shttpd.
+ * shttpd/Makefile.am: New.
+ * shttpd/auth.c, shttpd/cgi.c, shttpd/compat_rtems.c,
+ shttpd/compat_rtems.h, shttpd/compat_unix.c, shttpd/compat_unix.h,
+ shttpd/compat_win32.c, shttpd/compat_win32.h, shttpd/compat_wince.c,
+ shttpd/compat_wince.h, shttpd/config.c, shttpd/defs.h,
+ shttpd/io_cgi.c, shttpd/io_dir.c, shttpd/io_emb.c, shttpd/io_file.c,
+ shttpd/io.h, shttpd/io_socket.c, shttpd/io_ssl.c, shttpd/llist.h,
+ shttpd/log.c, shttpd/Makefile, shttpd/md5.c, shttpd/md5.h,
+ shttpd/mime_type.c, shttpd/resources.rc, shttpd/shttpd.1,
+ shttpd/shttpd.c, shttpd/shttpd.h, shttpd/shttpd.ico, shttpd/ssl.h,
+ shttpd/standalone.c, shttpd/std_includes.h, shttpd/string.c:
+ Import from shttpd-1.37.tar.gz.
+
+2007-06-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove "pad" from CPU_CONTEXT.
+
+2007-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/coremsg.c: Formatting.
+
+2007-05-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/include/rtems/score/copyrt.h: Update copyright notice.
+
+2007-05-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/Makefile.am, sapi/include/rtems/io.h, sapi/src/io.c: Split into
+ one function per file execpt io.c which contains required
+ initialization methods.
+ * sapi/src/ioclose.c, sapi/src/iocontrol.c, sapi/src/iodata.c,
+ sapi/src/ioinitialize.c, sapi/src/ioopen.c, sapi/src/ioread.c,
+ sapi/src/ioregisterdriver.c, sapi/src/iounregisterdriver.c,
+ sapi/src/iowrite.c: New files.
+
+2007-05-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h, sapi/src/io.c: Readded code to copy driver
+ table into Workspace but now it is only done if the application needs
+ extra slots for dynamic driver registration. Cleaned up
+ rtems_io_register_driver and rtems_io_unregister_driver code and
+ added numerous error cases to register.
+
+2007-05-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/Makefile.am, libmisc/monitor/mon-object.c,
+ libmisc/monitor/monitor.h, sapi/include/confdefs.h,
+ sapi/include/rtems/config.h, sapi/include/rtems/io.h,
+ sapi/src/exinit.c, sapi/src/io.c: Eliminate maximum_drivers
+ configuration parameter since it was used to configure a no longer
+ used feature. Device names are now part of the filesystem not in a
+ table. This also eliminated the variables _IO_Number_of_devices and
+ _IO_Driver_name_table from RTEMS as well as the memory allocation
+ used to populate _IO_Driver_name_table.
+ * libmisc/monitor/mon-dname.c: Removed.
+
+2007-05-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * sapi/include/confdefs.h: Add CONFIGURE_MESSAGE_BUFFER_MEMORY so there
+ is less dependence on CONFIGURE_MEMORY_OVERHEAD. Do not arbitrarily
+ add 1 to CONFIGURE_MEMORY_OVERHEAD so we do not waste a kilobyte for
+ unused Workspace. Round the workspace required size to an 8 byte
+ boundary instead of a 0x400 byte one. We may end up needing to add 8
+ bytes again to account for the alignment rounding.
+
+2007-05-23 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ Yu Chen <chyyuu@gmail.com>
+ * score/src/corespinlockwait.c: Per question posted as
+ http://www.rtems.org/ml/rtems-users/2007/may/msg00180.html, changed
+ logical operator to <=.
+
+2007-05-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/cpu/arm/cpu.c, score/cpu/avr/cpu.c, score/cpu/bfin/cpu.c,
+ score/cpu/c4x/cpu.c, score/cpu/h8300/cpu.c, score/cpu/i386/cpu.c,
+ score/cpu/m68k/cpu.c, score/cpu/mips/cpu.c, score/cpu/nios2/cpu.c,
+ score/cpu/no_cpu/cpu.c, score/cpu/sh/cpu.c, score/cpu/sparc/cpu.c,
+ cpukit/sapi/src/exinit.c: Move copying of CPU Table to shared
+ executive initialization.
+
+2007-05-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/corerwlockrelease.c: Do not dereference NULL.
+
+2007-05-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/barrier.h,
+ rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/message.h, rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/ratemon.h, rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/sem.h, rtems/include/rtems/rtems/tasks.h,
+ rtems/include/rtems/rtems/timer.h, sapi/Makefile.am,
+ sapi/include/rtems/extension.h: Split Classic API data instantiation
+ into individual files. This reduces the size of the BSS section when
+ an optional manager stub is used. Some tests showed about a 600 byte
+ reduction in BSS size.
+ * rtems/src/taskinitusers.c, sapi/src/rtemsapi.c, rtems/src/tasks.c:
+ Eliminated the variables _RTEMS_tasks_User_initialization_tasks and
+ _RTEMS_tasks_Number_of_initialization_tasks because they were only
+ used in one place after initialized. It was a waste of space.
+ * rtems/src/barrierdata.c, rtems/src/dpmem.c, rtems/src/dpmemdata.c,
+ rtems/src/eventdata.c, rtems/src/msgdata.c, rtems/src/partdata.c,
+ rtems/src/ratemondata.c, rtems/src/regiondata.c,
+ rtems/src/rtemstimerdata.c, rtems/src/semdata.c, rtems/src/taskdata.c,
+ sapi/src/extensiondata.c: New files.
+
+2007-05-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/Makefile.am, libmisc/cpuuse/README: Split remaining CPU Usage
+ functionality into multiple files to eliminate unnecessary cohesion.
+ Update README.
+ * libmisc/cpuuse/cpuusagereport.c, libmisc/cpuuse/cpuusagereset.c:
+ New files.
+ * libmisc/cpuuse/cpuuse.c: Removed.
+
+2007-05-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/src/ratemonperiod.c: Fix math ordering bug which resulted in a
+ negative value in some circumstances. Also cleaned up to share uptime
+ declaration.
+
+2007-05-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog, configure.ac, libcsupport/src/__times.c,
+ libmisc/cpuuse/cpuuse.c, libmisc/stackchk/check.c,
+ rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c,
+ rtems/src/ratemonresetall.c, rtems/src/ratemontimeout.c,
+ score/Makefile.am, score/include/rtems/score/thread.h,
+ score/include/rtems/score/timespec.h, score/src/threaddispatch.c,
+ score/src/threadinitialize.c, score/src/threadtickletimeslice.c,
+ score/src/timespecdivide.c: Add nanoseconds granularity to the rate
+ monotonic period statistics and CPU usage statistics. This capability
+ is enabled by default although may be conditionally disabled by the
+ user. It could be too much overhead on small targets but it does not
+ appear to be bad in early testing. Its impact on code size has not
+ been evaluated either. It is possible that both forms of statistics
+ gathering could be disabled with further tweaking of the conditional
+ compilation.
+ * score/src/timespecdividebyinteger.c: New file.
+
+2007-05-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/cpuuse/cpuuse.c: Use rtems_object_get_name and eliminate
+ functionally similar code here. Also cleanup print formats.
+
+2007-05-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/src/objectgetnameasstring.c: Internal threads use string names
+ so in the current RTEMS source string object name can NOT be
+ disabled. It is probably worth considering converting the internal
+ threads to uint32_t style names so all the support for string names
+ can be conditionally disabled.
+
+2007-05-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Makefile.am, score/include/rtems/score/timespec.h: Add division
+ and greater than operations for timespecs.
+ * score/src/timespecdivide.c, score/src/timespecgreaterthan.c:
+ New files.
+
+2007-05-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/src/objectgetnameasstring.c: Remove bogus ifdef
+ RTEMS_POSIX_API.
+
+2007-05-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, preinstall.am, libmisc/Makefile.am, rtems/Makefile.am,
+ rtems/include/rtems.h, rtems/include/rtems/rtems/ratemon.h,
+ rtems/inline/rtems/rtems/ratemon.inl, rtems/src/ratemoncancel.c,
+ rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemontimeout.c,
+ score/Makefile.am, score/include/rtems/score/object.h,
+ score/src/threadhandler.c, wrapup/Makefile.am: Integrate Rate
+ Monotonic Statistics and Period Usage into Rate Monotonic Manager.
+ Added the following directives: rtems_rate_monotonic_get_statistics,
+ rtems_rate_monotonic_reset_statistics,
+ rtems_rate_monotonic_reset_all_statistics,
+ rtems_rate_monotonic_report_statistics, and rtems_object_get_name.
+ Obsoleted the rtems/rtmonuse.h file as a public interface.
+ * rtems/src/ratemongetstatistics.c,
+ rtems/src/ratemonreportstatistics.c, rtems/src/ratemonresetall.c,
+ rtems/src/ratemonresetstatistics.c, rtems/src/rtemsobjectgetname.c,
+ score/src/objectgetnameasstring.c: New files.
+ * libmisc/rtmonuse/rtmonuse.c, libmisc/rtmonuse/rtmonuse.h: Removed.
+
+2007-05-14 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/Makefile.am, libcsupport/src/unixlibc.c: Split off dummry
+ rtems_io_register_name for use on unix.
+ * libcsupport/src/unixlibc_io.c: New file.
+
+2007-05-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * score/src/coremsgseize.c: A blocking sender's message size was
+ pulled out of the wrong field in the Wait information structure.
+ * score/src/objectallocate.c: With the new optional manager support,
+ we only stub out the initialization. This makes it possible to attempt
+ to create an object with the information structure only initialized
+ with all zeros. This ensures we return an error cleanly in this case.
+
+2007-05-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/src/region.c, sapi/src/exinit.c: Now that the Region is
+ an optional manager, we cannot depend on it do initialize the
+ internal Allocator Mutex. This was always a questionable place to
+ do it, so this is a cleanup.
+
+2007-05-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/cpuuse/cpuuse.c, libmisc/stackchk/check.c,
+ libmisc/stackchk/stackchk.h: Clean up as side-effect of making them
+ suitable for inclusion in the Users Guide.
+
+2007-05-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog: Move all ChangeLog entries for 2006 and earlier to
+ ChangeLog-pre2007.
+ * ChangeLog-pre2007: New file.
+
+2007-05-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1241/rtems
+ * score/src/threadchangepriority.c, score/src/threadqrequeue.c: Close
+ critical section window added with requeueing support.
+
+2007-05-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/cdefs.h,
+ libcsupport/include/sys/cdefs.h: Remove.
+ * Makefile.am: Remove libcsupport/include/sys/cdefs.h.
+ * libcsupport/Makefile.am: Remove include/rtems/cdefs.h.
+ * include/rtems/bsd/sys/queue.h, libcsupport/include/sys/ioccom.h,
+ libnetworking/netdb.h, libnetworking/resolv.h,
+ libnetworking/arpa/inet.h, libnetworking/arpa/nameser.h,
+ libnetworking/libc/gethostbydns.c, libnetworking/libc/res_stubs.c,
+ libnetworking/machine/in_cksum.h, libnetworking/net/ethernet.h,
+ libnetworking/net/if.h, libnetworking/net/if_dl.h,
+ libnetworking/netinet/ip.h, libnetworking/netinet/tcp.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/sys/libkern.h, libnetworking/sys/mount.h,
+ libnetworking/sys/poll.h, libnetworking/sys/socket.h,
+ libnetworking/sys/sysctl.h, libnetworking/sys/syslog.h,
+ libnetworking/sys/uio.h, libnetworking/sys/un.h,
+ librpc/include/rpc/auth.h, librpc/include/rpc/auth_unix.h,
+ librpc/include/rpc/clnt.h, librpc/include/rpc/clnt_soc.h,
+ librpc/include/rpc/pmap_clnt.h, librpc/include/rpc/pmap_prot.h,
+ librpc/include/rpc/pmap_rmt.h, librpc/include/rpc/svc.h,
+ librpc/include/rpc/svc_soc.h, librpc/include/rpc/xdr.h,
+ librpc/include/rpcsvc/ypclnt.h, librpc/include/rpc/rpc_com.h:
+ Include <rtems/bsd/sys/cdefs.h> instead of <sys/cdefs.h>.
+
+2007-05-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Reflect introduction of
+ include/rtems/bsd/sys/cdefs.h.
+ * include/rtems/bsd/sys/cdefs.h: New.
+
+2007-05-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Reflect having removed sys/queue.h.
+ * libnetworking/sys/queue.h: Remove.
+
+2007-05-10 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/xdr/xdr_float.c: Include <rtems/endian.h> instead of
+ <machine/endian.h>.
+ * libnetworking/rtems/rtems_showroute.c,
+ libnetworking/rtems/rtems_showipstat.c,
+ libnetworking/rtems/rtems_showtcpstat.c,
+ libnetworking/rtems/rtems_showicmpstat.c,
+ libnetworking/rtems/rtems_showmbuf.c,
+ libnetworking/rtems/rtems_showudpstat.c,
+ libnetworking/rtems/rtems_showifstat.c, libnetworking/net/if.c,
+ libnetworking/net/raw_cb.c, libnetworking/net/route.c,
+ libnetworking/net/rtsock.c, libnetworking/net/raw_usrreq.c,
+ libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/netinet/tcp_timer.c, libnetworking/netinet/if_ether.c,
+ libnetworking/netinet/tcp_debug.c, libnetworking/netinet/ip_fw.c,
+ libnetworking/netinet/ip_output.c,
+ libnetworking/netinet/ip_mroute.c, libnetworking/netinet/in_proto.c,
+ libnetworking/netinet/udp_usrreq.c,
+ libnetworking/netinet/tcp_output.c,
+ libnetworking/netinet/tcp_subr.c, libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/in_rmx.c, libnetworking/netinet/in_pcb.c,
+ libnetworking/netinet/raw_ip.c, libnetworking/netinet/ip_divert.c,
+ libnetworking/netinet/in.c, libnetworking/kern/uipc_socket2.c,
+ libnetworking/kern/kern_sysctl.c, libnetworking/kern/uipc_socket.c,
+ libnetworking/kern/kern_subr.c: Include <rtems/bsd/sys/queue.h>
+ instead of <sys/queue.h>.
+ * libnetworking/sys/socketvar.h, libnetworking/sys/mount.h,
+ libnetworking/sys/sysctl.h, libnetworking/net/raw_cb.h,
+ libnetworking/net/if.h, libnetworking/net/if_media.h,
+ libnetworking/net/if_var.h, libnetworking/netinet/in_var.h,
+ libnetworking/netinet/in_pcb.h: Include <rtems/bsd/sys/queue.h>
+ instead of <sys/queue.h>.
+ * Makefile.am: Reflect addition of include/rtems/bsd/sys/queue.h.
+ * include/rtems/bsd/sys/queue.h: New (Copied from
+ libnetworking/sys/queue.h).
+
+2007-05-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/include/rtems/libcsupport.h, libcsupport/src/newlibc.c,
+ sapi/Makefile.am, sapi/include/confdefs.h, sapi/src/exinit.c,
+ score/Makefile.am, score/preinstall.am,
+ score/include/rtems/score/userext.h, score/src/chain.c,
+ score/src/userext.c: Switch to newlib reentrancy extension being
+ installed in the initial set instead of using rtems_extension_create.
+ While implementing this, noticed that user extensions and chain code
+ had multiple functions in a single file which is not desirable in the
+ SuperCore and API portions of RTEMS, so split these into multiple
+ files with one function per file. Also noticed that some of user
+ extension code was inlined for no particular reason so moved that to
+ C bodies. Split executive shutdown from initialization since not
+ every application shuts down. Moved __fini call to executive shutdown
+ to be more symmetrical with where it is called at startup.
+ * sapi/src/exshutdown.c, score/src/chainappend.c,
+ score/src/chainextract.c, score/src/chainget.c,
+ score/src/chaininsert.c, score/src/userextaddapiset.c,
+ score/src/userextaddset.c, score/src/userextremoveset.c,
+ score/src/userextthreadbegin.c, score/src/userextthreadcreate.c,
+ score/src/userextthreaddelete.c, score/src/userextthreadrestart.c,
+ score/src/userextthreadstart.c, score/src/userextthreadswitch.c: New
+ files.
+ * score/inline/rtems/score/userext.inl: Removed.
+
+2007-05-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libcsupport/src/error.c, sapi/include/rtems/config.h: Do not
+ reference _Configuration_MP_table if multiprocessing is disabled.
+
+2007-05-09 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-server.c: Do not
+ reference _Configuration_MP_table if multiprocessing is disabled.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/machine/endian.h: Remove.
+ * libnetworking/Makefile.am: Remove machine/endian.h.
+ * libnetworking/arpa/nameser_compat.h, libnetworking/netinet/in.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h: Include
+ <rtems/endian.h> instead of <machine/endian.h>.
+ * Makefile.am: Add include/rtems/endian.h.
+ * include/rtems/endian.h: New (Copied from
+ libnetworking/machine/endian.h).
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/readdir.c, libnetworking/net/slcompress.c,
+ pppd/md4.h, pppd/md5.h, pppd/pppd.h,
+ score/cpu/m68k/rtems/score/m68k.h: Include <rtems/stdint.h> instead
+ of <stdint.h>.
+ * libnetworking/machine/endian.h: Remove
+ CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+ * NEWS: new.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ PR 1243
+ * pppd/auth.c (set_allowed_addrs): Remove bogus dereference.
+
+2007-05-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/machine/endian.h: Convert htons, htonl, ntohs, ntohl
+ to inline functions, using uint[16,32]_t.
+ * libnetworking/netdb.h: Change netent->n_net to uint32_t to comply
+ with SUSv3.
+ * telnetd/icmds.c: Add HAVE_CONFIG_H magic.
+ * rtems/src/regionprocessqueue.c, score/src/heapresizeblock.c
+ score/src/threadqrequeue.c, ftpd/ftpd.c, libblock/src/show_bdbuf.c:
+ Add HAVE_CONFIG_H magic.
+ * libnetworking/libc/gethostbydns.c,
+ libnetworking/libc/inet_net_ntop.c,
+ libnetworking/libc/inet_pton.c: Eliminate __P.
+ * librpc/src/rpc/rtime.c: Use uint32_t instead of unsigned long for
+ return value of ntohl (POSIX requirement).
+ Use UINT32_C macros to avoid overflows on 16bit targets.
+ Eliminate __P.
+ * configure.ac: Check for working PRIxPTR.
+
+2007-05-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/thread.h, score/inline/rtems/score/stack.inl
+ score/src/threadinitialize.c, score/src/threadstackallocate.c:
+ Use size_t for stack sizes.
+
+2007-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog, libcsupport/src/malloc.c,
+ libcsupport/src/mallocfreespace.c, sapi/include/confdefs.h,
+ score/Makefile.am, score/preinstall.am: malloc never blocks so the
+ Region Manager is quite heavy for implementing this. This patch
+ implements the C Program Heap directly in terms of the new Protected
+ Heap handler. This handler is a direct use of a SuperCore Heap in
+ conjunction with the Allocator Mutex used internally by RTEMS. This
+ saves 3184 bytes on most SPARC test executables.
+ * score/include/rtems/score/protectedheap.h, score/src/pheapallocate.c,
+ score/src/pheapallocatealigned.c, score/src/pheapextend.c,
+ score/src/pheapfree.c, score/src/pheapgetblocksize.c,
+ score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c,
+ score/src/pheapinit.c, score/src/pheapresizeblock.c,
+ score/src/pheapwalk.c: New files.
+
+2007-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/rmdir.c: Fixed spacing.
+ * libcsupport/Makefile.am, libcsupport/src/newlibc.c: Split _exit from
+ newlibc.c. It is not required for minimum executing and drops 624
+ from SPARC minimum executable.
+ * libcsupport/src/newlibc_exit.c: New file.
+
+2007-04-17 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/Makefile.am, itron/src/eventflags.c, itron/src/fmempool.c,
+ itron/src/itronintr.c, itron/src/itrontime.c, itron/src/network.c,
+ itron/src/port.c, itron/src/sysmgmt.c, itron/src/task.c,
+ itron/src/vmempool.c, posix/Makefile.am, posix/src/pthread.c,
+ rtems/src/taskinitusers.c, rtems/src/tasks.c,
+ sapi/include/confdefs.h, sapi/src/io.c: Various modification to
+ reduce executable size. Most were refactoring of files. Split ITRON
+ API files. Implemented mechanism to avoid initialization task/thread
+ loop being linked in when that style of task initialization was not
+ being used.
+ * itron/src/acp_por.c, itron/src/act_cyc.c, itron/src/cal_por.c,
+ itron/src/chg_iXX.c, itron/src/clr_flg.c, itron/src/cre_flg.c,
+ itron/src/cre_mpf.c, itron/src/cre_mpl.c, itron/src/cre_por.c,
+ itron/src/def_alm.c, itron/src/def_cyc.c, itron/src/def_exc.c,
+ itron/src/def_int.c, itron/src/def_svc.c, itron/src/del_flg.c,
+ itron/src/del_mpf.c, itron/src/del_mpl.c, itron/src/del_por.c,
+ itron/src/dis_int.c, itron/src/dly_tsk.c, itron/src/ena_int.c,
+ itron/src/fwd_por.c, itron/src/get_blf.c, itron/src/get_blk.c,
+ itron/src/get_tim.c, itron/src/get_ver.c, itron/src/itroninittasks.c,
+ itron/src/loc_cpu.c, itron/src/nget_nod.c, itron/src/nget_ver.c,
+ itron/src/nrea_dat.c, itron/src/nwri_dat.c, itron/src/pacp_por.c,
+ itron/src/pcal_por.c, itron/src/pget_blf.c, itron/src/pget_blk.c,
+ itron/src/pol_flg.c, itron/src/ref_alm.c, itron/src/ref_cfg.c,
+ itron/src/ref_cyc.c, itron/src/ref_flg.c, itron/src/ref_iXX.c,
+ itron/src/ref_mpf.c, itron/src/ref_mpl.c, itron/src/ref_por.c,
+ itron/src/ref_sys.c, itron/src/rel_blf.c, itron/src/rel_blk.c,
+ itron/src/ret_int.c, itron/src/ret_tmr.c, itron/src/ret_wup.c,
+ itron/src/rpl_rdv.c, itron/src/set_flg.c, itron/src/set_tim.c,
+ itron/src/tacp_por.c, itron/src/tcal_por.c, itron/src/tget_blf.c,
+ itron/src/tget_blk.c, itron/src/twai_flg.c, itron/src/unl_cpu.c,
+ itron/src/wai_flg.c, posix/src/pthreadinitthreads.c: New files.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/thread.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+
+2007-04-16 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1240/filesystem
+ * libfs/src/imfs/imfs_rmnod.c: Fix link when removing a symlink. Memory
+ for filename was not being freed.
+
+2007-04-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/utils.c: Use uintptr_t instead of unsigned long.
+
+2007-04-16 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/rsm_tsk.c: Correct error returned.
+
+2007-04-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Redefine LIBPOSIX to !UNIX.
+ * posix/src/usleep.c, libcsupport/src/readlink.c:
+ Update API to SUSv3.
+
+2007-04-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Unconditionally build src/sleep.c,
+ src/usleep.c.
+ * posix/src/clockgettime.c: #ifdef CLOCK_MONOTONIC the
+ CLOCK_MONOTONIC case.
+ * score/inline/rtems/score/tod.inl: Include <sys/time.h>.
+
+2007-04-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Cosmetics.
+ * configure.ac: Add AM_CONDITIONAL(HAS_PTHREADS).
+ * httpd/Makefile.am: Use HAS_PTHREADS instead of LIBPOSIX.
+
+2007-04-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am, wrapup/Makefile.am, configure.ac: Rename
+ AM_CONDITIONAL(HAS_POSIX) into LIBPOSIX.
+ * posix/src/clockgettime.c, posix/src/clocksettime.c: Don't include
+ rtems/posix/time.h.
+ * posix/src/nanosleep.c: Include rtems/score/timespec.h instead of
+ rtems/posix/time.h.
+ * score/include/rtems/score/object.h: Use size_t for byte sizes.
+
+2007-04-12 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/rsm_tsk.c: Correct error returned.
+
+2007-04-09 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * include/rtems/pci.h: Added device ID for MOTOROLA_HAWK
+
+2007-04-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/newlibc.c: Add __ATTRIBUTE_IMPURE_PTR__
+ (Fixes "relocation truncated to fit: R_MIPS_GPREL16" against
+ _impure_ptr bug).
+ Fix abuse of _REENT_INIT().
+
+2007-04-05 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/itrontime.c: Fix typo.
+ * score/include/rtems/score/tod.h: Add TOD_TICKS_PER_SECOND macro.
+ * score/src/iterateoverthreads.c: Safely take NULL as argument.
+ * score/src/threaddispatch.c: Formatting.
+
+2007-04-05 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/Makefile.am: Fix formatting.
+
+2007-04-05 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/Makefile.am, posix/include/rtems/posix/time.h,
+ posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c,
+ posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c,
+ posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c,
+ posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c,
+ posix/src/pthread.c, posix/src/pthreadcreate.c,
+ posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c,
+ posix/src/sched.c, posix/src/semtimedwait.c,
+ posix/src/sigtimedwait.c, posix/src/ualarm.c,
+ rtems/src/clocktodtoseconds.c, score/Makefile.am,
+ score/preinstall.am, score/include/rtems/score/tod.h,
+ score/inline/rtems/score/tod.inl, score/src/coretod.c,
+ score/src/coretodget.c, score/src/coretodgetuptime.c,
+ score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec
+ manipulation routines in the SuperCore. Use them everywhere possible.
+ This lead to significant cleanup in the API routines and eliminated
+ some of the same code from the POSIX API. At this point, the
+ SuperCore keeps time in POSIX timespec format properly from 1970. You
+ just cannot set it before 1988 in keeping with RTEMS traditional
+ behavior.
+ * score/include/rtems/score/timespec.h, score/src/timespecaddto.c,
+ score/src/timespecfromticks.c, score/src/timespecisvalid.c,
+ score/src/timespeclessthan.c, score/src/timespecsubtract.c,
+ score/src/timespectoticks.c: New files.
+ * posix/src/posixintervaltotimespec.c,
+ posix/src/posixtimespecsubtract.c,
+ posix/src/posixtimespectointerval.c: Removed.
+
+2007-04-04 Joel Sherrill <joel@OARcorp.com>
+
+ * score/Makefile.am, score/include/rtems/score/tod.h,
+ score/inline/rtems/score/tod.inl: Make _TOD_Tickle_ticks a real
+ non-inlined routine. It should only be used once so there is little
+ advantage to inlining it.
+ * score/src/coretodtickle.c: New file.
+
+2007-04-02 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/Makefile.am, score/src/objectgetnoprotection.c: Eliminate some
+ dead code.
+ * posix/src/time.c: Removed.
+
+2007-04-02 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/include/rtems/posix/timer.h, posix/src/alarm.c,
+ posix/src/posixtimespectointerval.c, posix/src/ptimer1.c,
+ posix/src/sysconf.c, posix/src/ualarm.c, rtems/src/clockget.c,
+ rtems/src/clocktodvalidate.c, score/include/rtems/score/tod.h,
+ score/inline/rtems/score/tod.inl, score/src/coretod.c: Eliminate
+ TOD_Ticks_per_second variable.
+
+2007-04-02 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/itrontime.c, libcsupport/src/__gettod.c,
+ posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h,
+ posix/src/clockgettime.c, posix/src/clocksettime.c,
+ posix/src/nanosleep.c, posix/src/posixtimespecsubtract.c,
+ posix/src/posixtimespectointerval.c, posix/src/ptimer1.c,
+ posix/src/sleep.c, rtems/Makefile.am,
+ rtems/include/rtems/rtems/clock.h, rtems/include/rtems/rtems/timer.h,
+ rtems/include/rtems/rtems/types.h, rtems/src/clockget.c,
+ rtems/src/clockset.c, rtems/src/clocktodtoseconds.c,
+ rtems/src/clocktodvalidate.c, rtems/src/taskwakewhen.c,
+ score/Makefile.am, score/include/rtems/score/tod.h,
+ score/inline/rtems/score/tod.inl, score/src/coretod.c,
+ score/src/coretodset.c: Convert from Classic API style TOD_Control as
+ fundamental time structure to POSIX struct timespec. Add
+ clock_get_uptime().
+ * rtems/src/clockgetuptime.c, score/src/coretodget.c,
+ score/src/coretodgetuptime.c: New files.
+ * score/src/coretodtickle.c, score/src/coretodtoseconds.c,
+ score/src/coretodvalidate.c: Removed.
+
+2007-04-02 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/printk.c: Add %p support.
+
+2007-04-02 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/stackchk/check.c: Add code to check validity of frame pointer
+ in addition to the pattern area being overwritten. Also do some
+ cleanup.
+
+2007-03-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/pci.h: Further stdint.h fixed-size types.
+
+2007-03-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * include/rtems/pci.h: Use stdint.h fixed size-types.
+
+2007-03-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Move libc/send.c to libc_a_SOURCES.
+ * libnetworking/Makefile.am: Move libc/recv.c to libc_a_SOURCES.
+ * libnetworking/Makefile.am: Move libc/res_config.h to
+ libc_a_SOURCES (File is being used).
+ * libnetworking/libc/iso_addr.c, libnetworking/libc/iso_addr.3:
+ Remove (Unused).
+ * libnetworking/Makefile.am: Remove libc/iso_addr.c, libc/iso_addr.3.
+ * libnetworking/net/ppp-deflate.c, libnetworking/net/bsd-comp.c:
+ Remove (Unused).
+ * libnetworking/Makefile.am: Remove net/ppp-deflate.c, net/bsd-comp.c.
+
+2007-03-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/addr2ascii.c, libnetworking/libc/ascii2addr.c,
+ libnetworking/libc/base64.c, libnetworking/libc/ether_addr.c,
+ libnetworking/libc/gethostbydns.c, libnetworking/libc/gethostbyht.c,
+ libnetworking/libc/gethostbynis.c,
+ libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/gethostname.c, libnetworking/libc/getnetbydns.c,
+ libnetworking/libc/getnetbyht.c, libnetworking/libc/getnetbynis.c,
+ libnetworking/libc/getnetnamadr.c, libnetworking/libc/getproto.c,
+ libnetworking/libc/getprotoent.c, libnetworking/libc/getprotoname.c,
+ libnetworking/libc/getservbyname.c,
+ libnetworking/libc/getservbyport.c, libnetworking/libc/getservent.c,
+ libnetworking/libc/herror.c, libnetworking/libc/inet_addr.c,
+ libnetworking/libc/inet_lnaof.c, libnetworking/libc/inet_makeaddr.c,
+ libnetworking/libc/inet_net_ntop.c,
+ libnetworking/libc/inet_net_pton.c, libnetworking/libc/inet_neta.c,
+ libnetworking/libc/inet_netof.c, libnetworking/libc/inet_network.c,
+ libnetworking/libc/inet_ntoa.c, libnetworking/libc/inet_ntop.c,
+ libnetworking/libc/inet_pton.c, libnetworking/libc/iso_addr.c,
+ libnetworking/libc/linkaddr.c, libnetworking/libc/map_v4v6.c,
+ libnetworking/libc/ns_addr.c, libnetworking/libc/ns_name.c,
+ libnetworking/libc/ns_netint.c, libnetworking/libc/ns_ntoa.c,
+ libnetworking/libc/ns_parse.c, libnetworking/libc/ns_print.c,
+ libnetworking/libc/ns_ttl.c, libnetworking/libc/nsap_addr.c,
+ libnetworking/libc/rcmd.c, libnetworking/libc/recv.c,
+ libnetworking/libc/res_comp.c, libnetworking/libc/res_data.c,
+ libnetworking/libc/res_debug.c, libnetworking/libc/res_init.c,
+ libnetworking/libc/res_mkquery.c, libnetworking/libc/res_mkupdate.c,
+ libnetworking/libc/res_query.c, libnetworking/libc/res_send.c,
+ libnetworking/libc/res_stubs.c, libnetworking/libc/res_update.c,
+ libnetworking/libc/send.c, libnetworking/libc/strsep.c: Eliminate
+ SCCS, LINT. Add HAVE_CONFIG_H.
+ * libcsupport/src/__assert.c: Add HAVE_CONFIG_H.
+
+2007-03-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/tasks.h: Change rtems_task_argument to
+ uintptr_t.
+
+2007-03-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/ip_icmp.c, libnetworking/netinet/ip_input.c,
+ libnetworking/netinet/ip_output.c: Further _IP_VHL removal preps.
+
+2007-03-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/ip.h: Add FreeBSD's alignment macros.
+ * libnetworking/net/netisr.h: Partial update from FreeBSD.
+ * libcsupport/src/getpwent.c: Remove bogus cast to long.
+ * libnetworking/libc/strsep.c: Don't build if provided by libc.
+ * libnetworking/libc/rcmd.c: Eliminate __P(). Cosmetics.
+ * libnetworking/sys/select.h: Remove selrecord, selwakeup (Unused).
+ * libnetworking/netinet/ip_output.c: Preps to eliminate _IP_VHL
+ (Abandoned in FreeBSD). Misc mergers from upstream FreeBSD.
+ * libnetworking/netinet/ip_input.c: Preps to eliminate _IP_VHL
+ (Abandoned in FreeBSD). Misc mergers from upstream FreeBSD.
+ * libnetworking/netinet/ip_icmp.c: Preps to eliminate _IP_VHL
+ (Abandoned in FreeBSD).
+ * libnetworking/netinet/tcp_subr.c: Preps to eliminate _IP_VHL
+ (Abandoned in FreeBSD).
+ * libnetworking/netinet/raw_ip.c: Preps to eliminate _IP_VHL
+ (Abandoned in FreeBSD).
+ * libnetworking/netinet/ip_output.c: Partial update from FreeBSD.
+ * libnetworking/netinet/ip_fw.c: Eliminate __P().
+
+2007-03-28 Chris Johns <chrisj@rtems.org>
+
+ * rtems/Makefile.am, rtems/include/rtems/rtems/clock.h,
+ score/include/rtems/score/watchdog.h: Add support for a handler to
+ obtain the number of nanoseconds since the last clock tick. The
+ primary interface for this is rtems_clock_set_nanoseconds_extension.
+ Subsequent commits from Joel will redo the TOD support to use this
+ capability.
+ * rtems/src/clocksetnsecshandler.c: New file.
+
+2007-03-28 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1234/cpukit
+ * libcsupport/Makefile.am: Provide printk() based implementation of
+ __assert() to reduce dependencies in executables.
+ * libcsupport/src/__assert.c: New file.
+
+2007-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/clnt_tcp.c (clnttcp_create):
+ Use uintptr_t for "disrupt". Remove bogus (long) cast.
+ * libnetworking/net/ppp-comp.h: Remove (Unused).
+ * libnetworking/Makefile.am: Remove net/ppp-comp.h.
+ * libnetworking/sys/buf.h: Remove (Unused).
+ * libnetworking/Makefile.am: Remove sys/buf.h.
+ * libnetworking/kern/kern_sysctl.c,
+ libnetworking/kern/uipc_socket2.c: Include <sys/queue.h> instead of
+ <sys/buf.h>.
+ * libcsupport/include/sys/sockio.h: Partial update from
+ FreeBSD.
+
+2007-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/ip_output.c: Use uint32_t optlen.
+ * libnetworking/netinet/igmp.c: Eliminate __P().
+ * libnetworking/netinet/in.c: Eliminate __P().
+ * libnetworking/netinet/tcp_subr.c: Eliminate __P().
+ * libnetworking/netinet/in_pcb.c: Eliminate __P().
+ * libnetworking/netinet/ip_output.c: Eliminate __P().
+
+2007-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/protosw.h (pr_usrreqs.pru_attach,
+ pr_usrreqs.pru_control, pr_usrreqs.pru_rcvd, pr_usrreqs.pru_rcvoob):
+ Change int args to intptr_t because they are casted to pointers.
+ * libnetworking/netinet/tcp_usrreq.c,
+ libnetworking/kern/uipc_socket2.c: Reflect changes to sys/protosw.h.
+
+2007-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/rtems_glue.c: Cast to intptr_t instead of
+ "long", because long is not guaranteed to be castable to char*.
+ * libnetworking/netinet/ip_input.c: Eliminate __P().
+ Change "int next" to "int32_t next" for 16bit targets.
+ * libnetworking/netinet/tcp_input.c: Eliminate __P().
+ * libnetworking/netinet/in_rmx.c: Eliminate __P().
+ * libnetworking/netinet/tcp_usrreq.c: Eliminate __P().
+ * libnetworking/netinet/udp_usrreq.c: Eliminate __P().
+ * libnetworking/nfs/bootp_subr.c: Eliminate __P().
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Eliminate __P().
+ * libnetworking/kern/uipc_domain.c: Eliminate __P().
+
+2007-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/pppcompress.h, libnetworking/net/pppcompress.c:
+ Remove (Abandoned in FreeBSD).
+ * libnetworking/Makefile.am: Remove net/pppcompress.c,
+ net/pppcompress.h.
+ * libnetworking/net/if_ppp.c: Use net/slcompress.h instead of
+ net/pppcompress.h.
+ * libnetworking/net/slcompress.h: Cosmetics from FreeBSD.
+ * libnetworking/net/ppp_tty.c: Use net/slcompress.h instead of
+ net/pppcompress.h.
+
+2007-03-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/pppcompress.h: Eliminate __P().
+ * libnetworking/net/if_pppvar.h: Cosmetics from FreeBSD.
+ * libnetworking/net/if_llc.h: Update from FreeBSD.
+
+2007-03-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * pppd/ccp.c, pppd/options.c: Include <net/ppp_comp.h> instead of
+ <net/ppp-comp.h>.
+ * libnetworking/net/ppp-comp.h: Include <net/ppp_comp.h>.
+ Warn about using it.
+ * libnetworking/Makefile.am: Add net/ppp_comp.h.
+ * libnetworking/net/ppp_comp.h: New (copy of ppp-comp.h).
+ * libnetworking/net/ppp-comp.h: Eliminate __P(). Cosmetics from
+ FreeBSD.
+ * libnetworking/machine/in_cksum.h: Eliminate __P().
+ * pppd/auth.c, pppd/cbcp.c, pppd/ccp.c, pppd/chap.c,
+ pppd/chap_ms.c, pppd/chat.c, pppd/demand.c, pppd/fsm.c,
+ pppd/ipcp.c, pppd/lcp.c, pppd/options.c, pppd/rtemsmain.c,
+ pppd/sys-rtems.c, pppd/upap.c, pppd/utils.c:
+ Eliminate __P().
+ * libcsupport/src/scandir.c: Eliminate __P().
+ * pppd/chap.h, pppd/chap_ms.h, pppd/fsm.h, pppd/ipcp.h,
+ pppd/lcp.h, pppd/magic.h, pppd/md4.h, pppd/pppd.h, pppd/upap.h:
+ Eliminate __P().
+ * libnetworking/netinet/ip_mroute.c: Eliminate __P().
+ * libnetworking/netinet/ip_mroute.h: Partial update from FreeBSD.
+ * libnetworking/net/raw_cb.c: Sync with FreeBSD.
+
+2007-03-26 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1231/cpukit
+ * posix/src/adasupp.c, posix/src/clockgetcpuclockid.c,
+ posix/src/clockgetenableattr.c, posix/src/clockgetres.c,
+ posix/src/clockgettime.c, posix/src/clocksetenableattr.c,
+ posix/src/mutex.c, posix/src/mutexattrdestroy.c,
+ posix/src/mutexattrgetprioceiling.c,
+ posix/src/mutexattrgetprotocol.c, posix/src/mutexattrgetpshared.c,
+ posix/src/mutexattrinit.c, posix/src/mutexattrsetprioceiling.c,
+ posix/src/mutexattrsetprotocol.c, posix/src/mutexattrsetpshared.c,
+ posix/src/mutexdefaultattributes.c, posix/src/mutexdestroy.c,
+ posix/src/mutexgetprioceiling.c, posix/src/mutexlock.c,
+ posix/src/mutexlocksupp.c, posix/src/mutexmp.c,
+ posix/src/mutexsetprioceiling.c, posix/src/mutextimedlock.c,
+ posix/src/mutextrylock.c, posix/src/mutexunlock.c,
+ posix/src/nanosleep.c, posix/src/posixintervaltotimespec.c,
+ posix/src/posixtimespecsubtract.c,
+ posix/src/posixtimespectointerval.c,
+ posix/src/psignalclearprocesssignals.c,
+ posix/src/psignalclearsignals.c,
+ posix/src/psignalsetprocesssignals.c,
+ posix/src/psignalunblockthread.c, posix/src/ptimer.c,
+ posix/src/ptimer1.c, posix/src/sched.c, posix/src/time.c: Remove
+ unneeded includes of assert.h
+
+2007-03-26 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/include/rtems/assoc.h: Pick up the include file
+ changes associated with the file splitting.
+
+2007-03-26 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/Makefile.am: Pick up the Makefile changes associated
+ with the file splitting.
+
+2007-03-26 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/assoc.c, libcsupport/src/libio.c,
+ libcsupport/src/write.c: Split files to shrink minimum.exe. Hopefully
+ this will not be deemed necessary to commit to the 4.7 branch.
+ * libcsupport/src/assoclocalbyname.c,
+ libcsupport/src/assoclocalbyremote.c,
+ libcsupport/src/assoclocalbyremotebitfield.c,
+ libcsupport/src/assocnamebylocal.c,
+ libcsupport/src/assocnamebylocalbitfield.c,
+ libcsupport/src/assocnamebyremote.c,
+ libcsupport/src/assocnamebyremotebitfield.c,
+ libcsupport/src/assocptrbylocal.c, libcsupport/src/assocptrbyname.c,
+ libcsupport/src/assocptrbyremote.c,
+ libcsupport/src/assocremotebylocal.c,
+ libcsupport/src/assocremotebylocalbitfield.c,
+ libcsupport/src/assocremotebyname.c, libcsupport/src/libio_init.c,
+ libcsupport/src/write_r.c: New files.
+
+2007-03-26 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/__gettod.c: Replace incorrect comment about timezone
+ support and remove deadcode. Replace with comment explaining that
+ behavior is compatible with GNU/Linux per Eric Norum.
+
+2007-03-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/ppp_defs.h, libnetworking/net/if_ppp.h:
+ Partial update from FreeBSD.
+ * libnetworking/netinet/if_ether.h: Eliminate __P().
+ * libnetworking/netinet/ip_var.h: Eliminate __P().
+ * libnetworking/netinet/in.h: Eliminate __P().
+ * libnetworking/netinet/tcp_var.h: Eliminate __P().
+
+2007-03-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/udp_var.h: Cosmetics from FreeBSD.
+ Remove __P();
+ * libnetworking/netinet/in_pcb.h: More partial updates from FreeBSD.
+
+2007-03-25 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/in_var.h: Remove __P().
+ * libnetworking/netinet/in_systm.h: Remove __P().
+ * libnetworking/netinet/in_pcb.h: Partial updates from FreeBSD.
+ * libnetworking/sys/socketvar.h: Cosmetics from FreeBSD.
+ * libnetworking/netinet/if_ether.c: Remove __P().
+ * libnetworking/net/raw_cb.h, libnetworking/net/raw_usrreq.c:
+ More updates from FreeBSD.
+ * libnetworking/net/raw_cb.h, libnetworking/net/raw_usrreq.c,
+ libnetworking/net/route.h: Partial update from FreeBSD.
+
+2007-03-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Remove nfs/krpc.h.
+ * libnetworking/nfs/krpc.h: Remove (Unused).
+ * libnetworking/kern/kern_subr.c: Remove #ifdef'ed vax code.
+ * libnetworking/Makefile.am: Remove nfs/nfs.h.
+ * libnetworking/nfs/nfs.h: Remove (Unused).
+
+2007-03-19 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/buf.h: Remove unused/non-implemented bsd kernel
+ symbols.
+ * libnetworking/sys/conf.h: Don't include machine/conf.h.
+ Update copyright notice.
+ Remove unused/non-implemented declarations.
+ * libnetworking/Makefile.am: Remove machine/conf.h.
+ * libnetworking/machine/conf.h: Remove.
+
+2007-03-19 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/systm.h: Update copyright notice from FreeBSD.
+ Remove many non-supported/unused declarations.
+
+2007-03-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/ucred.h: Remove crcopy, crdup, crfree, crget,
+ crhold (Unused/non-implemented).
+
+2007-03-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/ucred.h: Remove __P().
+ * libnetworking/sys/callout.h: Remove __P().
+ * libnetworking/sys/domain.h: Remove __P().
+ * libnetworking/sys/socketvar.h: Remove __P().
+ * libnetworking/sys/socket.h: Remove __P().
+ * libnetworking/sys/select.h: Remove __P().
+ * libnetworking/sys/kernel.h: Remove __P().
+ * libnetworking/sys/protosw.h: Remove __P().
+ * libnetworking/sys/conf.h: Remove bdevsw, cdevsw, swdevt (Unused).
+ * libnetworking/sys/systm.h: Remove nblkdev, nchrdev,
+ swdevt, nswdev, nswap (Unused).
+
+2007-03-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/conf.h: Remove non-implemented/unused symbols.
+ * libnetworking/net/ppp_tty.c: Use struct rtems_termios_linesw
+ instead of struct linesw (PR 1229)
+ * libnetworking/sys/systm.h: Comment out copyin/copyout to work
+ around clash with defines from rtems_bsdnet_internal.h.
+ * score/src/heapwalk.c: include stdlib.h.
+
+2007-03-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/buf.h, libnetworking/sys/conf.h:
+ Remove __P().
+ * libnetworking/net/if.h, libnetworking/net/if_ppp.h,
+ libnetworking/sys/signalvar.h, libnetworking/sys/systm.h:
+ Remove __P().
+ * libcsupport/include/rtems/termiostypes.h,
+ libcsupport/src/termios.c: Prefix linesw, struct linesw, nwlinesw
+ with rtems_termios_*.
+ * libnetworking/sys/conf.h: Remove linesw, struct linesw, nlinesw.
+ (Clash with termiostypes.h - PR 1229).
+
+2007-03-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/wkspace.inl, score/src/wkspace.c:
+ Change _Workspace_Handler_initialization and
+ _Workspace_Allocate_or_fatal_error to using size_t.
+ * libnetworking/sys/rtprio.h: Remove (Unused).
+ * libnetworking/Makefile.am: Remove sys/rtprio.h.
+
+2007-03-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/mbuf.h, libnetworking/sys/rtprio.h:
+ Remove __P().
+
+2007-03-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/assocnamebad.c: Remove dead code. Use PRI* macros
+ to fix warnings.
+ * score/include/rtems/score/stack.h: Use size_t for stack sizes.
+ * score/include/rtems/score/chain.h, score/src/chain.c:
+ Change _Chain_Initialize to using size_t.
+
+2007-03-12 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/dumpbuf/dumpbuf.c, libmisc/dumpbuf/dumpbuf.h: Rename
+ Dump_Buffer to rtems_print_buffer.
+
+2007-03-12 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/heapallocatealigned.c, score/src/threadqrequeue.c: Correct
+ license URL and/or fix mistake in copyright notice. Both of these
+ mistakes appear to be from code submitted after these changes were
+ made previously.
+
+2007-03-10 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1226/cpukit
+ * sapi/include/confdefs.h: CONFIGURE_HAS_OWN_MULTIPROCESSING_TABLE not
+ CONFIGURE_HAS_OWN_MULTIPROCESING_TABLE.
+
+2007-03-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/imfs.h: Fix comment.
+
+2007-03-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/imfs.h: Fix comment.
+
+2007-03-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/stackchk/check.c, libmisc/stackchk/internal.h,
+ libmisc/stackchk/stackchk.h: Change dump usage to report usage.
+
+2007-03-08 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/Makefile.am, rtems/src/msgqsend.c, rtems/src/msgqurgent.c:
+ Remove wrapper for message queue send and urgent and implement them
+ directly. There was an unnecessary function call layer in addition to
+ conditions in the shared routine. Directly coding both directives is
+ simpler and should result in smaller code.
+ * rtems/src/msgqsubmit.c: Removed.
+
+2007-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1222/cpukit
+ * score/Makefile.am, score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/threadq.h,
+ score/inline/rtems/score/coremutex.inl, score/src/coremsgsubmit.c,
+ score/src/coremutexsurrender.c, score/src/threadchangepriority.c,
+ score/src/threadclearstate.c, score/src/threadhandler.c,
+ score/src/threadinitialize.c, score/src/threadqdequeuefifo.c,
+ score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c,
+ score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c,
+ score/src/threadqextractfifo.c, score/src/threadqextractpriority.c,
+ score/src/threadsetstate.c: Enhance so that when the prioirity of a
+ thread that is blocked on a priority based thread queue is changed,
+ that its placement in the queue is reevaluated based upon the new
+ priority. This enhancement includes modifications to the SuperCore as
+ well as new test cases.
+ * score/src/threadqrequeue.c: New file.
+
+2007-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/src/exinit.c: Fix spacing.
+
+2007-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1221/cpukit
+ * posix/src/pthreadequal.c: Fix critical section nesting.
+
+2007-02-22 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/Makefile.am: Move getpagesize.c to newlib-only
+ compiled files.
+
+2007-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * wrapup/Makefile.am: Use MKDIR_P instead of mkdir_p.
+
+2007-02-16 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/Makefile.am: Remove macros/README.
+
+2007-02-11 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/heap.h, score/src/heap.c,
+ score/src/heapallocatealigned.c, score/src/heapresizeblock.c:
+ More size_t for heap-sizes.
+ * score/include/rtems/score/heap.h, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapextend.c: Use size_t for
+ heap-sizes.
+ * libnetworking/resolv.h: Typo fixes. Remove __P().
+
+2007-02-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/tasks.h, rtems/src/taskcreate.c:
+ Use size_t for stack-sizes.
+
+2007-02-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/vm/vm_extern.h: Remove non-implemented/unused
+ functions.
+ * configure.ac: Check for intmax_t, uintptr_t, intptr_t,
+ pthread.h, pthread_rwlock_t, pthread_barrier_t, pthread_spinlock_t.
+
+2007-02-06 Till Straumann <strauman@slac.stanford.edu>
+
+ * libcsupport/src/gxx_wrappers.c: fix PR#690. Supply
+ taskvar dtor to plug memory leak. Applied patch attached
+ to PR#690.
+
+2007-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/getpagesize.c: New (moved from posix/src).
+ * posix/src/getpagesize.c: Removed.
+ * posix/Makefile.am: Remove references to getpagesize.c.
+ * libcsupport/Makefile.am: Add getpagesize.c.
+
+2007-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/src/sysconf.c: Add support for _SC_PAGESIZE (PR 1215).
+ * posix/src/mqueuesendsupp.c: Remove cast to make broken const cast
+ visible.
+ * score/inline/rtems/score/coremsg.inl: More size_t and consts.
+
+2007-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/src/msgqsend.c: Use size_t for sizes.
+ * rtems/src/msgqurgent.c: Use size_t for sizes.
+ * rtems/src/msgqbroadcast.c: Use size_t for sizes.
+ * rtems/src/msgmp.c: Use size_t for sizes.
+ * rtems/src/msgqsubmit.c: Use size_t for sizes.
+ * rtems/include/rtems/rtems/msgmp.h: Use size_t for sizes.
+ * rtems/include/rtems/rtems/message.h: Use size_t for sizes.
+ * score/inline/rtems/score/coremsg.inl: Use size_t for sizes.
+
+2007-02-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * itron/src/trcv_mbf.c: Use size_t for sizes.
+ * libmisc/monitor/mon-object.c: Use size_t for sizes.
+ * libmisc/monitor/mon-server.c: Use size_t for sizes.
+ * libmisc/monitor/monitor.h: Use size_t for sizes.
+ * libmisc/mw-fb/mw_uid.c: Use size_t for sizes.
+ * rtems/include/rtems/rtems/message.h: Use size_t for sizes.
+ * rtems/src/msgqreceive.c: Use size_t for sizes.
+ * posix/src/mqueuerecvsupp.c: Use size_t for sizes.
+ * score/src/coremsgseize.c: Use size_t for sizes.
+
+2007-02-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/mqueue.h: Use size_t for sizes.
+ * posix/src/mqueuesendsupp.c: Use size_t for sizes.
+ * score/include/rtems/score/coremsg.h: Use size_t for sizes.
+ * score/src/coremsgbroadcast.c: Use size_t for sizes.
+ * score/src/coremsgsubmit.c: Use size_t for sizes.
+
+2007-01-30 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/show_bdbuf.c: Use inttypes.h macros.
+
+2007-01-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/mw-fb/mw_fb.h: Eliminate __u32, __u16.
+
+2007-01-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/gethostbyht.c: Remove warning on unused vars.
+ Remove isblank (supposed to be provided by libc).
+
+2007-01-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/src/show_bdbuf.c: Convert from DOS to UNIX.
+
+2007-01-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/system.h: Remove __RTEMS_MAJOR__,
+ __RTEMS_MINOR__, __RTEMS_REVISION__ (moved to cpuopt.h).
+ * configure.ac: Dynamically derive __ __RTEMS_MAJOR__,
+ __RTEMS_MINOR__, __RTEMS_REVISION__ from _RTEMS_VERSION.
+ Add __RTEMS_MAJOR__, __RTEMS_MINOR__,__RTEMS_REVISION__ to cpuopt.h.
+
+2007-01-26 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/system.h:
+ #define __RTEMS_MINOR__ 7 (BZ 1206).
+
+2007-01-20 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libblock/src/bdbuf.c, libblock/include/bdbuf.h:
+ export some internal variables to make them available in
+ "show_bdbuf" monitor add-on
+
+2007-01-16 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/rtems/rtems_mii_ioctl.c,
+ libnetworking/rtems/rtems_mii_ioctl.h,
+ libnetworking/rtems/rtems_mii_ioctl_kern.c,
+ libi2c/libi2c.c, libi2c/libi2c.h:
+ Added SLAC/Stanford Authorship Note / Copyright + Liability Disclaimer.
+
+2007-01-09 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/error.c: rtems_progname is no longer defined in
+ the BSP startup since it never held a meaningful value.
+
+2007-01-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/aio.h: s/aoi_lio_opcode/aio_lio_opcode/
+ (BZ 1203).
diff --git a/cpukit/ChangeLog-pre2007 b/cpukit/ChangeLog-pre2007
new file mode 100644
index 0000000000..a008768ecc
--- /dev/null
+++ b/cpukit/ChangeLog-pre2007
@@ -0,0 +1,9531 @@
+2006-12-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * backward/rtc.h, backward/vmeintr.h, backward/confdefs.h,
+ backward/clockdrv.h, backward/itron.h, backward/console.h,
+ backward/imfs.h, backward/iosupp.h, backward/chain.h,
+ backward/motorola/mc68681.h, backward/motorola/mc68230.h,
+ backward/spurious.h, backward/rtemspppd.h, backward/zilog/z8536.h,
+ backward/zilog/z8030.h, backward/zilog/z8036.h, backward/dosfs.h,
+ backward/rtemsdialer.h, backward/asm.h, backward/timerdrv.h,
+ backward/ringbuf.h, backward/ftpd.h:
+ Abandon.
+
+2006-12-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/types.h: Abandon backward compatibility
+ types.
+ * include/rtems/stdint.h: Abandon DEPRECATED_TYPES.
+ * configure.ac: Abandon DEPRECATED_TYPES/--enable-deprecated.
+ * Makefile.am: Abandon DEPRECATED_TYPES.
+
+2006-12-13 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-ampolish.m4: Use am_aux_dir/ampolish3.
+
+2006-12-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-ampolish.m4: Require AM_MAINTAINER_MODE.
+ * aclocal/rtems-top.m4: Remove RTEMS_AMPOLISH3.
+ * configure.ac: Add RTEMS_AMPOLISH3.
+ * rtems/src/barrierrelease.c: Remove stray rtems_unsigned32.
+
+2006-12-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libfs/src/imfs/imfs.h: Remove
+ increment_and_check_linkcounts (unused),
+ decrement_linkcounts (unused, broken).
+
+2006-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/route.c, libnetworking/netinet/ip_input.c,
+ libnetworking/sys/domain.h: Cosmetics from FreeBSD.
+
+2006-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/rtems_glue.c: Remove local
+ extern strdup.
+
+2006-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/libio.h, libcsupport/src/read.c,
+ libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_dir.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/imfs/deviceio.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/memfile.c, libnetworking/lib/ftpfs.c,
+ libnetworking/lib/tftpDriver.c, libnetworking/rtems/rtems_syscall.c:
+ Use size_t instead of uint32_t for read/write count-args.
+
+2006-12-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/src/timerserverfirewhen.c: Remove local
+ extern _Timer_Seconds_chain.
+ * rtems/src/timerserverfireafter.c: Remove local
+ extern _Timer_Ticks_chain.
+
+2006-12-06 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/object.h, score/src/objectclearname.c,
+ score/src/objectcopynameraw.c, score/src/objectcopynamestring.c:
+ Add const qualifiers, use size_t where appropriate.
+
+2006-12-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/inline/rtems/score/thread.inl: Add const qualifiers to work
+ around aliasing effects.
+
+2006-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/inline/rtems/score/chain.inl: Add const qualifiers (works
+ around 651 aliasing bugs).
+
+2006-12-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/src/prwlockunlock.c, rtems/Makefile.am,
+ rtems/src/barrierrelease.c, rtems/src/barrierwait.c,
+ score/src/corerwlockobtainread.c, score/src/corerwlockrelease.c:
+ Complete implementation of barrier as the rest of the test code is
+ now implemented. Also add blocking code to rwlock.
+
+2006-12-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: New BUG-REPORT address.
+
+2006-11-27 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/src/threadget.c: Remove (Unused).
+ * score/Makefile.am: Removing score/src/threadget.c.
+
+2006-11-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libblock/Makefile.am: Don't include preinstall.am.
+ * libblock/preinstall.am: Remove.
+
+2006-11-20 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove ampolish3.
+
+2006-11-18 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/heapwalk.c: Do not use printk yet since many BSPs do not
+ prove the hooks for printk yet. This will require enough BSP changes
+ to delay until 4.8.
+
+2006-11-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add check for uintmax_t.
+ * libcsupport/src/malloc.c: Use uintmax_t instead of uint64_t for
+ MALLOC_STATS statistics. Use inttypes.h PRIxXXX macros for
+ printing.
+
+2006-11-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/check-networking.m4: Integrate type checks.
+ * configure.ac: Use rtems_cv_HAS_NETWORKING instead of
+ HAS_NETWORKING.
+
+2006-11-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/check-itron.m4: Integrate ITRON-type checks.
+ * configure.ac: Remove ITRON-type checks.
+ Move RTEMS_CHECK* after type-checks.
+
+2006-11-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove $LIBRPC.
+ * configure.ac: Check for uint64_t, int64_t.
+ * configure.ac, Makefile.am, configure.ac, ftpd/Makefile.am,
+ httpd/Makefile.am, libnetworking/Makefile.am, pppd/Makefile.am,
+ telnetd/Makefile.am, wrapup/Makefile.am: Replace
+ AM_CONDITIONAL(HAS_NETWORKING) with AM_CONDITIONAL(LIBNETWORKING).
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * score/inline/rtems/score/object.inl, score/src/objectnametoid.c:
+ Properly honor searching only local node even when on single CPU
+ system.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/coresemseize.c: Add missing ISR enable.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/heapwalk.c: Use printk not printf.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/rtmonuse/rtmonuse.c: Do not use float for calculations.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/sync.c: Do not dereference NULL reent.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/semtimedwait.c: Used wrong constant for blocking with bad
+ timeout value.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/semtimedwait.c: Reverse accidentally included
+ semtimedwait.c.
+
+2006-11-17 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/keygetspecific.c, posix/src/keysetspecific.c,
+ posix/src/semtimedwait.c: Correct indexing of key data to use api and
+ index NOT class and index. Class is always 1.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Suppress itron if int8/int16_t are not provided.
+ * configure.ac, Makefile.am, itron/Makefile.am, wrapup/Makefile.am:
+ Introduce AM_CONDITIONAL(LIBITRON).
+ Remove AM_CONDITIONAL(HAS_ITRON).
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * wrapup/Makefile.am: Introduce AM_CONDITIONAL(LIBDOSFS).
+ * configure.ac, Makefile.am, libfs/Makefile.am:
+ Introduce AM_CONDITIONAL(LIBDOSFS).
+
+2006-11-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/gethostbydns.c, libnetworking/libc/linkaddr.c,
+ libnetworking/libc/map_v4v6.c: Cosmetic updates from FreeBSD.
+ Eliminate bcopy in favor of memcpy.
+
+2006-11-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Add timeout() define.
+ * libnetworking/rtems/rtems_glue.c: Rename timeout() into
+ rtems_bsdnet_timeout().
+ * libnetworking/sys/malloc.h: Remove contigmalloc (non-implemented).
+ Remove __P-guards from malloc, free.
+
+2006-11-15 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/src/io.c: Fix spacing.
+ * sapi/include/confdefs.h: Enable includes needed for new objects.
+
+2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h: Enable memory for new objects.
+
+2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * posix/Makefile.am: Add file missed in previous commit.
+ * posix/src/posixtimespecabsolutetimeout.c: New file.
+
+2006-11-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove RTEMS_AMPOLISH3.
+ Add checks for uint8_t, int8_t, uint16_t, int16_t,
+ uint32_t, int32_t.
+ * aclocal/rtems-ampolish.m4: Pick up ampolish3 from ac_aux_dir.
+ * aclocal/rtems-top.m4: Add RTEMS_AMPOLISH3.
+ * ampolish3: Remove.
+
+2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/inline/rtems/score/threadq.inl, score/src/corerwlocktimeout.c:
+ New files.
+
+2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libcsupport/src/termios.c, posix/Makefile.am, posix/preinstall.am,
+ posix/include/rtems/posix/config.h, posix/include/rtems/posix/time.h,
+ sapi/src/posixapi.c, score/Makefile.am, score/preinstall.am,
+ score/include/rtems/score/corerwlock.h,
+ score/include/rtems/score/threadq.h,
+ score/src/corerwlockobtainread.c, score/src/threadqenqueue.c,
+ score/src/threadqtimeout.c: Adding POSIX barriers, POSIX spinlocks,
+ and partial implementation of POSIX rwlocks.
+ * posix/include/rtems/posix/barrier.h,
+ posix/include/rtems/posix/rwlock.h,
+ posix/include/rtems/posix/spinlock.h,
+ posix/inline/rtems/posix/barrier.inl,
+ posix/inline/rtems/posix/rwlock.inl,
+ posix/inline/rtems/posix/spinlock.inl,
+ posix/src/barrierattrdestroy.c, posix/src/barrierattrgetpshared.c,
+ posix/src/barrierattrinit.c, posix/src/barrierattrsetpshared.c,
+ posix/src/pbarrier.c, posix/src/pbarrierdestroy.c,
+ posix/src/pbarrierinit.c, posix/src/pbarriertranslatereturncode.c,
+ posix/src/pbarrierwait.c, posix/src/prwlock.c,
+ posix/src/prwlockdestroy.c, posix/src/prwlockinit.c,
+ posix/src/prwlockrdlock.c, posix/src/prwlocktimedrdlock.c,
+ posix/src/prwlocktimedwrlock.c,
+ posix/src/prwlocktranslatereturncode.c, posix/src/prwlocktryrdlock.c,
+ posix/src/prwlocktrywrlock.c, posix/src/prwlockunlock.c,
+ posix/src/prwlockwrlock.c, posix/src/pspin.c,
+ posix/src/pspindestroy.c, posix/src/pspininit.c,
+ posix/src/pspinlock.c, posix/src/pspinlocktranslatereturncode.c,
+ posix/src/pspintrylock.c, posix/src/pspinunlock.c,
+ posix/src/rwlockattrdestroy.c, posix/src/rwlockattrgetpshared.c,
+ posix/src/rwlockattrinit.c, posix/src/rwlockattrsetpshared.c: New files.
+
+2006-11-14 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Require inttypes.h, check for stdint.h.
+
+2006-11-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am, configure.ac: Remove RTEMS_PROVIDES_STDINT_H,
+ RTEMS_PROVIDES_INTTYPES_H.
+
+2006-11-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/stdint.h, libcsupport/include/inttypes.h:
+ Remove.
+
+2006-11-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * score/Doxyfile: Remove RTEMS_INLINES.
+
+2006-11-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * librpc/src/xdr/xdr_float.c: Add bfin.
+
+2006-11-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove redundant AC_CHECK_HEADER([stdint.h]),
+ AC_CHECK_HEADER([inttypes.h]). Now implicitly checked.
+
+2006-11-02 Steven Johnson <sjohnson@sakuraindustries.com>
+
+ * libnetworking/netdb.h, libnetworking/libc/gethostbyht.c,
+ libnetworking/libc/gethostnamadr.c: This patch adds a functional
+ gethostbyname_r to RTEMS. We were having problems with multiple
+ threads calling gethostbyname, so we decided the best way to deal
+ with it was to do it properly, rather than kludge up our code to make
+ gethostbyname safe. We have found several slightly different
+ parameter lists for this function, it does not seem to be standard.
+ The one we used has the linux interface. In RTEMS there was an
+ existing gethostbyname_r inside a #ifdef _THREAD_SAFE which was NOT
+ Threadsafe, as this just called gethostbyname. So we have placed all
+ of the additional code inside the #ifdef _THREAD_SAFE.
+
+2006-10-30 Joel Sherrill <joel@OARcorp.com>
+
+ PR 841/rtems
+ * itron/inline/rtems/itron/semaphore.inl, itron/src/twai_sem.c,
+ posix/include/rtems/posix/semaphore.h,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c,
+ posix/src/semwait.c, rtems/src/semobtain.c,
+ rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coresem.h, score/src/coresemseize.c: Make
+ sem_timedwait more conformant to Open Group specification.
+
+2006-10-25 Jennifer Averett <jennifer@oarcorp.com>
+
+ * libcsupport/src/termios.c: Change attribute of semaphore. It was
+ counting interrupts not acting as a condition synchronization mutex.
+ Since the caller did not always need to obtain the semaphore, it was
+ not being decremented until there was no data. This could occur after
+ hours of running a system and thousands of interrupts. The code in
+ fillBufferQueue would spin until it had consumed all of those
+ semaphore counts.
+
+2006-10-23 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.ac, score/cpu/Makefile.am: Add bfin.
+
+2006-10-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/enable-inlines.m4, aclocal/prog-gnat.m4: Remove (Unused).
+
+2006-10-19 Joel Sherrill <joel@OARcorp.com>
+
+ * score/Makefile.am, score/preinstall.am: Add pieces missed in previous
+ commit.
+
+2006-10-19 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.ac, itron/Makefile.am, itron/preinstall.am,
+ posix/Makefile.am, posix/preinstall.am, rtems/Makefile.am,
+ rtems/preinstall.am, sapi/Makefile.am, sapi/preinstall.am,
+ score/Makefile.am, score/preinstall.am, score/include/rtems/system.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/thread.h, score/src/chain.c,
+ score/src/coremutexseize.c, score/src/threadget.c: Remove all macro
+ implementations and use only the static inline. Static inline
+ functions are now well supported so there is no reason for duplicate
+ maintenance.
+ * itron/macros/rtems/itron/eventflags.inl,
+ itron/macros/rtems/itron/fmempool.inl,
+ itron/macros/rtems/itron/intr.inl, itron/macros/rtems/itron/mbox.inl,
+ itron/macros/rtems/itron/msgbuffer.inl,
+ itron/macros/rtems/itron/network.inl,
+ itron/macros/rtems/itron/port.inl,
+ itron/macros/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/sysmgmt.inl,
+ itron/macros/rtems/itron/task.inl, itron/macros/rtems/itron/time.inl,
+ itron/macros/rtems/itron/vmempool.inl,
+ posix/macros/rtems/posix/cond.inl, posix/macros/rtems/posix/key.inl,
+ posix/macros/rtems/posix/mqueue.inl,
+ posix/macros/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/priority.inl,
+ posix/macros/rtems/posix/pthread.inl,
+ posix/macros/rtems/posix/semaphore.inl,
+ posix/macros/rtems/posix/timer.inl, rtems/macros/rtems/rtems/asr.inl,
+ rtems/macros/rtems/rtems/attr.inl,
+ rtems/macros/rtems/rtems/barrier.inl,
+ rtems/macros/rtems/rtems/dpmem.inl,
+ rtems/macros/rtems/rtems/event.inl,
+ rtems/macros/rtems/rtems/eventset.inl,
+ rtems/macros/rtems/rtems/message.inl,
+ rtems/macros/rtems/rtems/modes.inl,
+ rtems/macros/rtems/rtems/options.inl,
+ rtems/macros/rtems/rtems/part.inl,
+ rtems/macros/rtems/rtems/ratemon.inl,
+ rtems/macros/rtems/rtems/region.inl,
+ rtems/macros/rtems/rtems/sem.inl,
+ rtems/macros/rtems/rtems/status.inl,
+ rtems/macros/rtems/rtems/support.inl,
+ rtems/macros/rtems/rtems/tasks.inl,
+ rtems/macros/rtems/rtems/timer.inl, sapi/macros/rtems/extension.inl,
+ score/macros/README, score/macros/rtems/score/address.inl,
+ score/macros/rtems/score/chain.inl,
+ score/macros/rtems/score/corebarrier.inl,
+ score/macros/rtems/score/coremsg.inl,
+ score/macros/rtems/score/coremutex.inl,
+ score/macros/rtems/score/corerwlock.inl,
+ score/macros/rtems/score/coresem.inl,
+ score/macros/rtems/score/corespinlock.inl,
+ score/macros/rtems/score/heap.inl, score/macros/rtems/score/isr.inl,
+ score/macros/rtems/score/mppkt.inl,
+ score/macros/rtems/score/object.inl,
+ score/macros/rtems/score/objectmp.inl,
+ score/macros/rtems/score/priority.inl,
+ score/macros/rtems/score/stack.inl,
+ score/macros/rtems/score/states.inl,
+ score/macros/rtems/score/sysstate.inl,
+ score/macros/rtems/score/thread.inl,
+ score/macros/rtems/score/threadmp.inl,
+ score/macros/rtems/score/tod.inl,
+ score/macros/rtems/score/tqdata.inl,
+ score/macros/rtems/score/userext.inl,
+ score/macros/rtems/score/watchdog.inl,
+ score/macros/rtems/score/wkspace.inl: Removed.
+
+2006-10-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * sapi/include/confdefs.h:
+ s/STACK_CHECKER_EXTENSION/RTEMS_STACK_CHECKER_EXTENSION/
+ (Reflect 2006-09-13's changes to libmisc/stackchk).
+
+2006-10-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4: Remove RTEMS_API.
+ * aclocal/version.m4: Add RTEMS_API. Bump RTEMS_API to 4.8.
+
+2006-10-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4: Bump RTEMS_API to 4.8.
+
+2006-10-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libmisc/capture/capture-cli.c: Use size_t instead of int.
+
+2006-10-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/version.m4: Bump version to 4.7.99.0.
+
+2006-10-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Require autoconf-2.60. Require automake-1.10.
+
+2006-10-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Require autoconf-2.60.
+
+2006-10-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * configure.ac, aclocal/multi.m4, aclocal/prog-cc.m4, aclocal/prog-ccas.m4
+ automake/compile.am: Adaptations to automake-1.10.
+
+2006-09-29 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/monitor/mon-command.c: Flush stdout after updating the
+ command line.
+
+2006-09-14 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/route.c, librpc/src/rpc/auth_none.c,
+ librpc/src/rpc/auth_unix.c, librpc/src/rpc/authunix_prot.c,
+ librpc/src/rpc/rpc_callmsg.c, librpc/src/rpc/rpc_prot.c,
+ librpc/src/rpc/rtems_portmapper.c: Removed warnings.
+
+2006-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * sapi/include/confdefs.h, sapi/src/posixapi.c, sapi/src/rtemsapi.c:
+ Add Classic API Barriers and commented out hooks to initialize .
+
+2006-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/Makefile.am, rtems/preinstall.am, rtems/include/rtems.h,
+ rtems/include/rtems/rtems/attr.h, rtems/include/rtems/rtems/config.h,
+ rtems/inline/rtems/rtems/attr.inl, rtems/macros/rtems/rtems/attr.inl:
+ Add Classic API Barriers.
+ * rtems/include/rtems/rtems/barrier.h,
+ rtems/include/rtems/rtems/barriermp.h,
+ rtems/inline/rtems/rtems/barrier.inl,
+ rtems/macros/rtems/rtems/barrier.inl, rtems/src/barrier.c,
+ rtems/src/barriercreate.c, rtems/src/barrierdelete.c,
+ rtems/src/barrierident.c, rtems/src/barrierrelease.c,
+ rtems/src/barriertranslatereturncode.c, rtems/src/barrierwait.c:
+ New files.
+
+2006-09-25 Joel Sherrill <joel@oarcorp.com>
+
+ * score/Makefile.am, score/preinstall.am,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/states.h,
+ score/inline/rtems/score/coresem.inl: Add SuperCore Barriers,
+ SpinLocks and a partial implementation of RWLocks.
+ * score/include/rtems/score/corebarrier.h,
+ score/include/rtems/score/corerwlock.h,
+ score/include/rtems/score/corespinlock.h,
+ score/inline/rtems/score/corebarrier.inl,
+ score/inline/rtems/score/corerwlock.inl,
+ score/inline/rtems/score/corespinlock.inl,
+ score/macros/rtems/score/corebarrier.inl,
+ score/macros/rtems/score/corerwlock.inl,
+ score/macros/rtems/score/corespinlock.inl, score/src/corebarrier.c,
+ score/src/corebarrierrelease.c, score/src/corebarrierwait.c,
+ score/src/corerwlock.c, score/src/corerwlockobtainread.c,
+ score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c,
+ score/src/corespinlock.c, score/src/corespinlockrelease.c,
+ score/src/corespinlockwait.c: New files.
+
+2006-09-14 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/route.c, librpc/src/rpc/auth_none.c,
+ librpc/src/rpc/auth_unix.c, librpc/src/rpc/authunix_prot.c,
+ librpc/src/rpc/rpc_callmsg.c, librpc/src/rpc/rpc_prot.c,
+ librpc/src/rpc/rtems_portmapper.c: Removed warnings.
+
+2006-09-14 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/cpuuse/cpuuse.c, libmisc/cpuuse/cpuuse.h: Promote CPU Usage
+ to first class citizen. Rename to start with rtems_ and include
+ documentation in user guide.
+
+2006-09-13 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/rtems/rtems_malloc_mbuf.c: Removed warning by adding
+ prototype of malloc.
+
+2006-09-13 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/stackchk/check.c, libmisc/stackchk/internal.h,
+ libmisc/stackchk/stackchk.h: Move stack to first class citizen
+ status. Include it in User Manual and rename to start with rtems_.
+
+2006-09-11 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/mw-fb/mw_fb.c, libmisc/mw-fb/mw_fb.h, libmisc/mw-fb/mw_uid.c,
+ libmisc/mw-fb/mw_uid.h: Remove warning.
+
+2006-09-11 Jerry Needell <jerry.needell@unh.edu>
+
+ * libnetworking/netinet/in_cksum.c: Joel should have used int32_t not
+ uint32_t when removing warnings.
+
+2006-09-08 Ken Peters <ken.peters@jpl.nasa.gov>
+
+ PR 1170/rtems
+ * rtems/src/timerserver.c: Timer Server created the TIME task with a
+ hard-coded hexadecimal number instead of using rtems_build_name. This
+ resulted in a byte-swapped name on some platforms.
+
+2006-09-06 Chris Johns <chrisj@rtems.org>
+
+ * pppd/pppd.h: Fix the bug in name change. The UNTIMEOUT
+ macro did not use the ppp version.
+
+2006-09-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/if_loop.c: Remove warning.
+
+2006-09-01 Till Straumann <strauman@slac.stanford.edu>
+
+ * pppd/rtems.main.c, pppd/pppd.h: renamed 'untimeout'
+ to 'pppuntimeout' to avoid name clash with [future]
+ bsdnet kernel routine.
+
+2006-09-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/malloc.c, libnetworking/rtems/rtems_glue.c,
+ libnetworking/sys/mbuf.h: Remove warnings -- use uintptr_t or
+ properly sized integers.
+
+2006-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * ftpd/ftpd.c, libcsupport/include/sys/ioccom.h,
+ libcsupport/src/ioctl.c, libnetworking/kern/uipc_mbuf.c,
+ libnetworking/libc/inet_addr.c, libnetworking/net/ethernet.h,
+ libnetworking/net/if.c, libnetworking/net/if_ethersubr.c,
+ libnetworking/net/if_ppp.c, libnetworking/net/if_pppvar.h,
+ libnetworking/net/if_var.h, libnetworking/net/ppp_tty.c,
+ libnetworking/netinet/in_cksum.c, libnetworking/nfs/bootp_subr.c,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/sys/mbuf.h, pppd/md4.c, pppd/pppd.h: Remove warnings
+ due to improper use of int which shows up on 16 bit targets. Added
+ ioctl_command_t since IOCTL command argument does not reliably fit
+ into 16 bits.
+
+2006-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/include/sys/ioccom.h, libnetworking/kern/uipc_socket2.c,
+ libnetworking/net/ethernet.h, libnetworking/net/if.h,
+ libnetworking/net/if_ethersubr.c, libnetworking/net/if_ppp.c,
+ libnetworking/net/if_pppvar.h, libnetworking/net/ppp_tty.c,
+ libnetworking/net/pppcompress.c, libnetworking/net/slcompress.c,
+ libnetworking/netinet/in.h, libnetworking/netinet/ip_icmp.c,
+ libnetworking/netinet/tcp.h, libnetworking/netinet/tcp_seq.h,
+ libnetworking/sys/protosw.h, libnetworking/sys/socketvar.h: Remove
+ warnings. Most of the warnings were 16/32 bit integer sizing issues.
+ Some constants had L appended, some had casts add, some types were
+ changed to reflect a bit width requirement.
+
+2006-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/cpuuse/cpuuse.c, libmisc/monitor/mon-command.c,
+ libmisc/monitor/mon-driver.c, libmisc/monitor/mon-symbols.c,
+ libmisc/rtmonuse/rtmonuse.c, libmisc/stackchk/check.c,
+ libnetworking/libc/res_debug.c, telnetd/telnetd.c: Remove printf
+ format warnings.
+
+2006-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/utsname.c, libnetworking/libc/res_debug.c,
+ libnetworking/net/if_media.h, libnetworking/rtems/rtems_mii_ioctl.c,
+ librpc/src/rpc/svc_simple.c: Remove printf format warnings.
+
+2006-08-29 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/capture/capture-cli.c: Remove printf format warnings.
+
+2006-08-29 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/score/object.h: _Objects_Local_node is a uint16_t
+ so cast the _Objects_Local_node constant to 1.
+
+2006-08-29 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_eval.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_free.c,
+ libfs/src/dosfs/msdos_fsunmount.c, libfs/src/dosfs/msdos_init.c,
+ libfs/src/dosfs/msdos_misc.c, libfs/src/dosfs/msdos_mknod.c,
+ libfs/src/imfs/imfs_debug.c: Remove warnings.
+
+2006-08-21 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/net/if_ethersubr.c: (ether_ioctl)
+ Return error for unknown/unsupported ioctl command.
+ (Change merged from freeBSD).
+
+2006-08-15 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/kern/kern_sysctl.c: Change int to int32_t.
+ * libnetworking/net/if_loop.c: Add cast to long.
+ These plus a patch to machine/param.h let the h8300 build multilib.
+
+2006-08-10 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/rtems/rtems_mii_ioctl_kern.c:
+ fixed wrong calculation of 1000baseTx autonegotiation
+ result.
+
+2006-08-09 Kolja Waschk <waschk@telos.de>
+
+ * configure.ac, librpc/src/xdr/xdr_float.c, score/cpu/Makefile.am: New
+ port to Altera NIOS II.
+
+2006-08-08 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/rtems/rtems_mii_ioctl_kern.c:
+ read ANER and include partner's autoneg
+ capability when determining active link parameters.
+
+2006-07-12 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 1110/networking
+ * libnetworking/machine/in_cksum.h: Replaced PPC and
+ i386 assembly algorithms (must not assume carry bit is preserved
+ across multiple asms). Added packet header as a 'm' input
+ operand for all CPU variants. Added carry bit to clobber list.
+
+2006-07-12 Till Straumann <strauman@slac.stanford.edu>
+
+ * pppd/sys-rtems.c: fixed error message so that the correct
+ ioctl is reported.
+
+2006-07-11 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1124/rtems
+ * score/include/rtems/score/threadq.h, score/src/coremutexseize.c,
+ score/src/coremutexsurrender.c, score/src/threadqenqueue.c,
+ score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c:
+ The placement of the changing a thread's priority when using priority
+ ceiling should be on the successful transfer of the mutex -- not when
+ the thread tries to acquire. Plus the lack of a dispatch disable
+ point lead to the potential for a thread timing out and already
+ having inherited the ceiling priority.
+
+2006-07-09 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * libblock/src/bdbuf.c:
+ * libblock/include/bdbuf.h:
+ (PR1118) fetch priority for swapout task from a variable,
+ not a fixed configuration value.
+
+ * libfs/src/imfs/imfs.h:
+ * libfs/src/imfs/imfs_initsupp.c:
+ (PR1118) fetch bytes_per_block value from a configuration variable,
+ not from a preprocessor macro
+
+ * sapi/include/confdefs.h:
+ (PR1118) add configuration mechanisms for:
+ - ATA task priority
+ - swapout task priority
+ - libblock basic configuration
+ conditionally add ata driver to device driver table
+ conditionally add ide driver to device driver table
+
+ * libcsupport/include/sys/cdefs.h:
+ * libnetworking/include/sys/linker_set.h:
+ (PR1119) change attribute "unused" to "used" for sysctl data structures
+
+ * libmisc/shell/shell.c:
+ (PR1120) adapt stdio redirection to current newlib behaviour
+
+2006-06-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Add ampolish3.
+
+2006-06-28 Ralf Corsépius <ralf.corsepius@rtems.org>
+ * ampolish3: New.
+ * aclocal/rtems-ampolish.m4: Reflect using in-sourcetree ampolish3.
+
+2006-06-24 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_var.h: #include <sys/queue.h>.
+ Cosmetics from FreeBSD.
+
+2006-06-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/cdefs.h: Partial update from freebsd.
+
+2006-06-22 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1101/rtems
+ * libcsupport/src/base_fs.c: Remove extra endif.
+
+2006-06-22 Joel Sherrill <joel@OARcorp.com>
+
+ PR 1101/rtems
+ * libcsupport/src/base_fs.c, rtems/src/taskcreate.c, rtems/src/tasks.c,
+ score/src/coremutex.c: Remove dead code.
+
+2006-06-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/libio.h: Add extern "C" {}.
+
+2006-06-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/src/mqueue.c: Remove duplicate #include <limits.h>.
+ PR 1088/rtems
+ * posix/src/ptimer.c: Add missing #include <limits.h>.
+
+2006-06-08 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/Makefile.am, posix/preinstall.am,
+ posix/include/rtems/posix/timer.h, posix/src/ptimer.c,
+ posix/src/ptimer1.c, sapi/src/posixapi.c,
+ score/include/rtems/score/object.h:
+
+2006-06-02 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/trcv_mbf.c, posix/src/semopen.c,
+ rtems/src/taskvariableadd.c, score/macros/rtems/score/heap.inl: Fix
+ warnings.
+
+2006-05-31 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/netinet/ip_icmp.c: Update icps_allecho counter.
+
+2006-05-30 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/netinet/icmp_var.h, libnetworking/netinet/ip_icmp.c,
+ libnetworking/rtems/rtems_showicmpstat.c: Add flag to inhibit ICMP
+ replies.
+
+2006-05-25 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/Makefile.am, libnetworking/Makefile.in,
+ libnetworking/rtems/rtems_bsdnet.h, libnetworking/rtems/rtems_glue.c,
+ libnetworking/rtems/rtems_malloc_mbuf.c: Provide customisable mbuf
+ allocation. Patch from Steven Johnson <sjohnson@sakuraindustries.com>
+
+2006-05-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-ampolish.m4: New.
+ * configure.ac: Use RTEMS_AMPOLISH3.
+
+2006-04-27 Eric Norum <norume@aps.anl.gov>
+
+ * telnetd/pty.c: Accept <CR><NUL> as equivalent to <CR><LF>.
+
+2006-04-27 Eric Norum <norume@aps.anl.gov>
+
+ * libmisc/capture/capture.h, libmisc/capture/capture.c
+ Add ability to free information on task delete.
+
+2006-04-18 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-4.6.99.3.
+
+2006-04-13 Joel Sherrill <joel@OARcorp.com>
+
+ PR 949/networking
+ * libnetworking/sys/socket.h: GNU/Linux is wrong in making
+ MSG_DONTWAIT public. It is strictly BSD and not SUSV. See
+ http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html
+ for clarification.
+
+2006-04-12 Lars Munch <lars@segv.dk>
+
+ PR 949/networking
+ * libnetworking/sys/socket.h: Make MSG_DONTWAIT public as in GNU/Linux.
+
+2006-04-06 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/inline/rtems/posix/mutex.inl,
+ posix/inline/rtems/posix/timer.inl,
+ posix/macros/rtems/posix/cond.inl,
+ posix/macros/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/timer.inl: Fix warnings.
+
+ * score/inline/rtems/score/threadmp.inl,
+ score/macros/rtems/score/threadmp.inl: Fix compile error.
+
+2006-04-05 Joel Sherrill <joel@OARcorp.com>
+ Victor V. Vengerov <Victor.Vengerov@oktetlabs.ru>
+
+ * score/include/rtems/score/mpci.h,
+ score/include/rtems/score/threadmp.h,
+ score/inline/rtems/score/threadmp.inl,
+ score/macros/rtems/score/threadmp.inl, score/src/threadmp.c,
+ score/src/threadqenqueue.c: Victor spotted the problem that
+ _MPCI_Receive_server_tcb and _Thread_MP_Receive were duplicate
+ variables and needed to be set to the same value. I took that
+ idea and just removed _Thread_MP_Receive. All uses are now
+ _MPCI_Receive_server_tcb.
+
+2006-03-27 Eric Norum <norume@aps.anl.gov>
+
+ * libmisc/monitor/prmisc.c: Eliminate undesired sign-extension.
+
+2006-03-08 Joel Sherrill <joel@OARcorp.com>
+
+ PR 761/rtems
+ * score/src/threadhandler.c: Add volatile cast so test is weak function
+ is present will do something. Otherwise, it can be assume by gcc to
+ always be a true condition.
+
+2006-03-08 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/macros/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/task.inl: Fix warnings.
+ * posix/macros/rtems/posix/cond.inl: Fix typo.
+ * score/macros/rtems/score/heap.inl: Fix missed type change.
+
+2006-03-07 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 830/filesystem
+ * libcsupport/src/termios.c: termios ioctl(FIONREAD) reported wrong
+ number of characters. So add chars in low-level/raw buffer to total
+ count.
+
+2006-03-07 Steven Johnson <sjohnson@sakuraindustries.com>
+
+ PR 850/rtems
+ * score/src/watchdogtickle.c: A Watchdog (used to timeout an event)
+ with a delay of 1 sometimes does not seem to timeout. The problem
+ occurs, because for whatever reason when the watchdog tickle function
+ executes, the watchdog->delta_interval is 0. it is then decremented
+ before being tested, becomes huge and so doesnt time out. It is
+ thought there is a race condition where the watchdog->delta_interval
+ is calculated by reference to a head (also with a delay of 1). But
+ before it can be added after the head, the head is removed, so the
+ new head now has a delay of 0.
+
+2006-03-07 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ PR 852/filesystem
+ * libblock/src/bdbuf.c: Increase performance of MSDOS file accesses by
+ using a simple read-ahead and write-combining scheme. Improvement is
+ dramatic.
+
+2006-03-07 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 886/filesystem
+ * libcsupport/src/libio.c: fcntl(fd,F_GETFL) fails to set O_NONBLOCK if
+ the descriptor is in non-blocking mode.
+
+2006-03-07 Joel Sherrill <joel@OARcorp.com>
+
+ PR 866/rtems
+ * score/include/rtems/system.h, score/include/rtems/score/isr.h,
+ score/inline/rtems/score/thread.inl,
+ score/macros/rtems/score/thread.inl: Added memory barriers to enter
+ and exit of dispatching and interrupt critical sections so GCC will
+ not optimize and reorder code out of a critical section.
+
+2006-02-08 Thomas Rauscher <trauscher@loytec.com>
+
+ PR 890/networking
+ * httpd/webs.c: The webservers enters an infinite loop when a POST
+ request with less data than indicated in the Content-Length header is
+ received. It also consumes additional heap memory and a file
+ descriptor for each invalid POST.
+
+2006-02-01 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/inline/rtems/posix/cond.inl, posix/macros/rtems/posix/cond.inl,
+ posix/src/conddestroy.c: Remove warnings.
+
+2006-02-01 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/src/tasks.c, rtems/src/taskvariableadd.c,
+ rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c: Remove
+ warnings.
+
+2006-01-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/include/intr.h, posix/include/rtems/posix/intr.h
+ posix/inline/rtems/posix/intr.inl.
+ posix/macros/rtems/posix/intr.inl, posix/src/intr.c:
+ Remove (Unused, dead).
+ * posix/Makefile.am: Reflect changes above. Rework.
+
+2006-01-18 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * posix/Makefile.am: Build devctl.
+
+2006-01-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/Makefile.am: Rework.
+ * score/Makefile.am: Rework.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ Large patch to improve Doxygen output. As a side-effect, grammar and
+ spelling errors were corrected, spacing errors were address, and some
+ variable names were improved.
+ * libmisc/monitor/mon-object.c, libmisc/monitor/monitor.h:
+ Account for changing OBJECTS_NO_CLASS to OBJECTS_CLASSIC_NO_CLASS.
+ * score/Doxyfile: Set output directory. Predefine some macro values.
+ Turn on graphical output.
+ * score/include/rtems/debug.h, score/include/rtems/seterr.h,
+ score/include/rtems/system.h, score/include/rtems/score/address.h,
+ score/include/rtems/score/apiext.h,
+ score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h, score/include/rtems/score/interr.h,
+ score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h,
+ score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h, score/include/rtems/score/tod.h,
+ score/include/rtems/score/tqdata.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/tqdata.inl, score/macros/README,
+ score/src/heap.c, score/src/threadmp.c, score/src/threadready.c,
+ score/src/threadstartmultitasking.c: Improve generated Doxygen
+ output. Fix spelling and grammar errors in comments. Correct names of
+ some variables and propagate changes.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ Large patch to improve Doxygen output. As a side-effect, grammar and
+ spelling errors were corrected, spacing errors were address, and some
+ variable names were improved.
+ * libmisc/monitor/mon-object.c, libmisc/monitor/monitor.h:
+ Account for changing OBJECTS_NO_CLASS to OBJECTS_CLASSIC_NO_CLASS.
+ * score/Doxyfile: Set output directory. Predefine some macro values.
+ Turn on graphical output.
+ * score/cpu/arm/rtems/score/cpu.h,
+ score/cpu/avr/rtems/score/cpu.h, score/cpu/c4x/rtems/score/cpu.h,
+ score/cpu/h8300/rtems/score/cpu.h, score/cpu/m68k/rtems/score/cpu.h,
+ score/cpu/mips/rtems/score/cpu.h, score/cpu/no_cpu/rtems/asm.h,
+ score/cpu/no_cpu/rtems/score/cpu.h,
+ score/cpu/no_cpu/rtems/score/types.h,
+ score/cpu/powerpc/rtems/new-exceptions/cpu.h,
+ score/cpu/powerpc/rtems/old-exceptions/cpu.h,
+ score/cpu/powerpc/rtems/score/cpu.h, score/cpu/sh/rtems/score/cpu.h,
+ score/cpu/sparc/rtems/score/cpu.h, score/cpu/unix/rtems/score/cpu.h,
+ score/include/rtems/debug.h, score/include/rtems/seterr.h,
+ score/include/rtems/system.h, score/include/rtems/score/address.h,
+ score/include/rtems/score/apiext.h,
+ score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h, score/include/rtems/score/interr.h,
+ score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h,
+ score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h, score/include/rtems/score/tod.h,
+ score/include/rtems/score/tqdata.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/tqdata.inl, score/macros/README,
+ score/src/heap.c, score/src/threadmp.c, score/src/threadready.c,
+ score/src/threadstartmultitasking.c: Improve generated Doxygen
+ output. Fix spelling and grammar errors in comments. Correct names of
+ some variables and propagate changes.
+
+2006-01-15 Eric Norum <norume@aps.anl.gov>
+
+ * posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/cond.inl, posix/macros/rtems/posix/mutex.inl:
+ Keep compiler happy by making some casts explicit.
+
+2006-01-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove doxygen support having accidentially slipped
+ into, though yesterday's patch.
+
+2006-01-12 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am, ftpd/Makefile.am, httpd/Makefile.am,
+ itron/Makefile.am, libblock/Makefile.am, libcsupport/Makefile.am,
+ libfs/Makefile.am, libmisc/Makefile.am, libnetworking/Makefile.am,
+ librpc/Makefile.am, posix/Makefile.am, pppd/Makefile.am,
+ rtems/Makefile.am, sapi/Makefile.am, score/Makefile.am,
+ score/cpu/arm/Makefile.am, score/cpu/avr/Makefile.am,
+ score/cpu/c4x/Makefile.am, score/cpu/h8300/Makefile.am,
+ score/cpu/i386/Makefile.am, score/cpu/m68k/Makefile.am,
+ score/cpu/mips/Makefile.am, score/cpu/no_cpu/Makefile.am,
+ score/cpu/powerpc/Makefile.am, score/cpu/sh/Makefile.am,
+ score/cpu/sparc/Makefile.am, score/cpu/unix/Makefile.am,
+ telnetd/Makefile.am, zlib/Makefile.am: Remove all-local:.
+
+2006-01-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/error.c: include and use inttypes.h.
+
+2006-01-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/rtems/rtems_mii_ioctl.h: Fix formatting.
+
+2006-01-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/unixlibc.c, libfs/src/imfs/ioman.c: Change
+ rtems_io_register_name to take a const char *.
+
+2006-01-08 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/rtems/io.h, sapi/src/io.c: Change rtems_io_register_name
+ to take a const char *.
+
+2005-12-09 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 849/networking
+ * librpc/src/rpc/rtems_portmapper.c: Increased stack size
+ by ARGSIZE to prevent overrun.
+
+2005-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: New header guard for cpuopts.h.
+
+2005-11-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Re-add rtems/rtems_mii_ioctl.h,
+ rtems/rtems_mii_ioctl.c, rtems/rtems_mii_ioctl_kern.c.
+ Add dev/mii/mii.h, net/if_media.h (Moved from c/src/libchip).
+ * libnetworking/net/if_media.h, libnetworking/dev/mii/mii.h:
+ New (Moved from c/src/libchip).
+ * libnetworking/rtems/rtems_mii_ioctl.h: Reflect mii.h and
+ if_media.h having moved.
+
+2005-11-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * automake/local.am: Remove depend.
+
+2005-11-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * include/rtems/stdint.h: Disable RTEMS proprietary fixed-size types.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add RTEMS_NETWORKING to cpuopts.h.
+ Add RTEMS_DEPRECATED_TYPES to config.h.
+ Add AC_CONFIG_COMMANDS(preinstall-stamp) magic.
+ Misc. cleanups.
+
+2005-11-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/if.h: Add forward reference declaration to
+ struct mbuf so ifru_tap callback is properly typed.
+ * libnetworking/rtems/rtems_bsdnet.h: Add definition of _BSD_VISIBLE
+ which needs to be defined so various pieces of the .h files are
+ visible to device drives.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Comment out using
+ rtems/rtems_mii_ioctl.h, rtems/rtems_mii_ioctl.c,
+ rtems/rtems_mii_ioctl_kern.c.
+
+2005-11-07 Michael Siers <mikes@poliac.com>
+
+ * pppd/rtemspppd.c, pppd/rtemspppd.h: Per confirmation from Michael add
+ missing copyright notice.
+
+2005-11-06 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libi2c/libi2c.c: Include config.h.
+ * libi2c/libi2c.c, libi2c/libi2c.h,
+ libnetworking/rtems/rtems_mii_ioctl.h,
+ libnetworking/rtems/rtems_mii_ioctl_kern.c,
+ score/src/heap.c: Eliminate obsolete types.
+
+2005-11-03 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * httpd/Makefile.am: Remove bogus noinst_LIBRARIES.
+
+2005-11-02 Till Straumann <strauman@slac.stanford.edu>
+
+ * libnetworking/Makefile.am,
+ libnetworking/preinstall.am: Added simple implementation of ethernet
+ media ioctl SIOCSIFMEDIA/SIOCGIFMEDIA for mii compliant phys.
+ * libnetworking/rtems/rtems_mii_ioctl.c,
+ libnetworking/rtems/rtems_mii_ioctl.h,
+ libnetworking/rtems/rtems_mii_ioctl_kern.c: New files.
+
+2005-11-02 Till Straumann <strauman@slac.stanford.edu>
+
+ * libi2c/Makefile.am, libi2c/Makefile.in, libi2c/libi2c.c,
+ libi2c/libi2c.h: New files.
+ * Makefile.am, configure.ac, preinstall.am, wrapup/Makefile.am: added a
+ simple API/library for i2c devices and drivers for i2c 2-byte eeproms
+ and a ds1621 temperature sensor; API is documented in libi2c.h
+
+2005-11-02 Fredic Praca <freebsd-fr.org>
+
+ PR 842/networking
+ * libnetworking/libc/gethostbydns.c: Avoid use of dprintf(). Rename
+ dprintf to debugprintf().
+
+2005-11-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/zlib.c: Remove.
+ * libnetworking/net/zlib.h: Remove.
+ * libnetworking/Makefile.am: Reflect changes above.
+
+2005-11-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * pppd/Makefile.am: Fix typo.
+
+2005-10-31 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 840/rtems:
+ * include/rtems/irq.h: Fix several typos.
+
+2005-10-30 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add zlib.
+ * Makefile.am: Add zlib.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/zlib.h, libnetworking/net/zlib.c:
+ Update from FreeBSD.
+ * libnetworking/opt_ppp.h: New.
+ * libnetworking/net/ppp.h: Remove.
+ * libnetworking/net/if_ppp.c, libnetworking/net/ppp_tty.c:
+ Reflect changes above. Cosmetics from FreeBSD.
+ * libnetworking/Makefile.am: Don't install loop.h.
+ Add opt_ppp.h, remove net/ppp.h.
+ * include/rtems/concat.h: Add EXPAND0, CONCAT0.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * telnetd/Makefile.am: Only build if LIBSHELL is available.
+
+2005-10-26 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * pppd/Makefile.am, pppd/auth.c, pppd/chap.c, pppd/md5.c, pppd/md5.h,
+ pppd/pppd.h: Misc. minor fixes.
+
+2005-10-26 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add pppd.
+ * Makefile.am: Add pppd.
+
+2005-10-26 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * pppd/Makefile.am:
+ Install rtemsdialer.h, rtemspppd.h to $(includedir)/rtems.
+ * pppd/ipxcp.c, pppd/ipxcp.h: Remove (Unused).
+ * backward/rtemspppd.h, backward/rtemsdialer.h: New.
+ * Makefile.am: Add backward/rtemspppd.h, backward/rtemsdialer.h.
+
+2005-10-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * telnet/Makefile.am: Install libtelnetd.a.
+
+2005-10-25 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/rtems/rtems_showifstat.c: Don't sign-extend address components.
+
+
+2005-10-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Add telnetd.
+ * configure.ac: Add telnetd.
+
+2005-10-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * telnetd/icmds.c: Rename register_icmds to
+ _rtems_telnet_register_icmds. Make main_* functions static.
+ * telnetd/pty.c: Make many functions static.
+ Rename rtems_telnetd_maximum_ptys to rtems_pty_maximum_ptys.
+ * telnetd/pty.h: Reflect changes above.
+ Rename get_pty to rtems_pty_get. New header guards.
+ * telnetd/telnetd.c: Reflect changes above.
+ * telnetd/telnetd.h: New header guards.
+
+2005-10-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * telnet/telnet.h, telnet/telnet.c: Rename
+ rtems_initialize_telnetd to rtems_telnetd_initialize,
+ main_telnetd to rtems_telnetd_main,
+ register_telnetd to rtems_telnetd_register.
+
+2005-10-25 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/confdefs.h, telnetd/pty.c, telnetd/pty.h: Attempt
+ to fix MAX_PTYS and provide a real configuration entry. This should
+ make telnetd some suitable for inclusion in cpukit.
+
+2005-10-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/dosfs/msdos_misc.c: Revert to vers. 1.9.
+
+2005-10-06 Joel Sherrill <joel@OARcorp.com>
+
+ PR 828/filesystems
+ * libfs/src/dosfs/msdos_misc.c: Problem retracted. Revert patch.
+
+2005-10-04 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 829/rtems
+ * rtems/src/tasks.c, rtems/src/taskvariabledelete.c: If task variables
+ are deleted from a different context (i.e., executing context !=
+ owner of the task variable. The owner meaning the task that
+ registered the dtor in question) the argument passed to the task
+ variable dtor must be tvar and not *ptr which yields the executing
+ task's value of the task variable instead of the owner's.
+
+2005-09-29 Eric Norum <norume@aps.anl.gov>
+
+ PR 835/rtems_misc
+ * libmisc/cpuuse/cpuuse.c: Remove floating point calculations and the
+ C preprocessor conditions which enabled them.
+
+2005-09-25 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/rtems/init.h, sapi/src/exinit.c: Remove unused and
+ obsolete rtems_initialize_executive.
+
+2005-09-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/mount.h: Cosmetical update from FreeBSD.
+ Remove non-implemented interfaces (vfs, nfs, fsstat, etc.).
+ * configure.ac: Check for sys/errno.h.
+
+2005-09-16 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Cosmetics.
+ * libnetworking/nfs/rpcv2.h: Update from FreeBSD.
+ * libnetworking/nfs/bootp_subr.c: Remove superfluous includes.
+ * libnetworking/nfs/xdr_subs.h: Partial update from FreeBSD.
+ * libnetworking/netinet/in.h: Partial update from FreeBSD.
+ * libnetworking/nfs/nfsproto.h: Partial update from FreeBSD.
+
+2005-09-02 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-4.6.99.2.
+
+2005-09-01 Joel Sherrill <joel@OARcorp.com>
+
+ PR 820/rtems
+ * score/inline/rtems/score/coremsg.inl,
+ score/macros/rtems/score/coremsg.inl, score/src/coremsginsert.c:
+ Increment of pending message count should be atomic with insertion on
+ the pending message chain. Determination of the need to call the
+ notification handler should also be in this atomic section of code.
+
+2005-09-01 Joel Sherrill <joel@OARcorp.com>
+
+ PR 796/rtems
+ * posix/src/semtimedwait.c: sem_timedwait is supposed to use absolute
+ time for timeout specification. This patch is a modified version of
+ the one suggested by Peter Dufault.
+
+2005-09-01 Nuno Costa <nuno-costa@iol.pt>
+
+ PR 804
+ * sapi/include/confdefs.h: Memory for POSIX timers not accounted for.
+ Patch adapted from edit comment in PR filed.
+
+2005-08-31 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 819/filesystem
+ * libcsupport/src/ttyname_r.c: Remove.
+ * libcsupport/src/ttyname.c: Partial update from FreeBSD.
+ * libcsupport/Makefile.am: Reflect changes above.
+
+2005-08-18 Andrew Sinclair <Andrew.Sinclair@elprotech.com>
+
+ PR 807/rtems
+ * rtems/src/timerfireafter.c, rtems/src/timerserverfireafter.c: First
+ patch returned without exitting dispatching critical section.
+
+2005-08-17 Nuno Costa <nuno-costa@iol.pt>
+
+ PR 805/rtems
+ * posix/include/rtems/posix/timer.h: Due to bad choice of error
+ constants by original submitter, it was impossible to create more
+ than 10 POSIX timers.
+
+2005-08-17 Andrew Sinclair <Andrew.Sinclair@elprotech.com>
+
+ PR 807/rtems
+ * rtems/src/timerfireafter.c, rtems/src/timerserverfireafter.c,
+ score/src/watchdoginsert.c: Tighten critical section checks on an ISR
+ using the same timer being inserted by a lower priority ISR or
+ interupt task.
+
+2005-08-17 Nickolay Semyonov <snob@oktetlabs.ru>
+
+ PR 744/filesystem
+ * libcsupport/src/unlink.c, libfs/src/dosfs/msdos_eval.c: DOSFS did not
+ support permissions on directories so the check performed by unlink
+ would always fail. The unlink code was modified to support a not
+ supported status being returned.
+
+2005-08-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * posix/include/mqueue.h, posix/src/mqueuetimedreceive.c:
+ ssize_t mq_timedreceive() (POSIX compliance).
+ * wrapup/Makefile.am: Use librtemscpu_a_LIBRARIES.
+
+2005-08-12 Chris Johns <chrisj@rtems.org>
+
+ PR 808/rtems_misc
+ * libcsupport/src/printk.c: Fix bug where specifying field width
+ crashed on pc386 BSP.
+
+2005-08-06 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/nfs/bootp_subr.c: Don't include
+ nfs/nfs.h, nfs/krpc.h.
+
+2005-08-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_create.c,
+ libfs/src/dosfs/msdos_eval.c, libfs/src/dosfs/msdos_file.c,
+ libfs/src/dosfs/msdos_free.c, libfs/src/dosfs/msdos_fsunmount.c,
+ libfs/src/dosfs/msdos_init.c, libfs/src/dosfs/msdos_misc.c,
+ libfs/src/dosfs/msdos_mknod.c:
+ Introduce msdos_status_t (dosfs statii are at least 32bit, not int).
+
+2005-08-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Add libnetworking/memory.h
+ * libnetworking/Makefile.am: Remove memory.h
+
+2005-08-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 817/rtems
+ * libcsupport/src/gxx_wrappers.c: Rename
+ rtems_gxx_recursive_mutex_init_function to
+ rtems_gxx_recursive_mutex_init.
+
+2005-08-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/syslog.h: Partial update from FreeBSD.
+
+2005-07-08 Eric Norum <norume@aps.anl.gov>
+
+ * libcsupport/src/open.c: Pass along errno from failed ftruncate().
+
+2005-07-06 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/lib/syslog.c: Fix spelling mistake.
+ * libnetworking/sys/uio.h: Partial update from FreeBSD.
+ * libnetworking/kern/kern_subr.c: Reflect changes above.
+
+2005-07-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 810/rtems
+ * libblock/include/rtems/ide_part_table.h: Add C++ guards.
+
+2005-06-17 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/if.h: Avoid use of struct mbuf to avoid unintended
+ dependencies added by the RTEMS specific tap interface.
+
+2005-06-09 Jacques Seronie Vivien <jacques.seronievivien@astrium.eads.net>
+
+ PR 790/rtems
+ * sapi/src/extensioncreate.c, sapi/src/extensionident.c: Correct use of
+ name. This was missed when the other ident services in rtems/src
+ where changed.
+
+2005-05-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.h: Partial update from FreeBSD.
+ * libnetworking/netinet/if_ether.h: Remove BYTE_PACK.
+ * libnetworking/netinet/ip_var.h: Remove BYTE_PACK.
+ * libnetworking/netinet/ip_divert.c: Fix broken comment.
+
+2005-05-26 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/lib/ftpfs.c, librpc/include/rpc/svc.h,
+ librpc/src/rpc/get_myaddress.c, librpc/src/rpc/pmap_getmaps.c,
+ librpc/src/rpc/pmap_getport.c: Remove warnings.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/clnt.h, librpc/include/rpc/svc.h,
+ src/rpc/pmap_rmt.c: Use void* instead of caddr_t.
+ Cosmetics from FreeBSD.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/auth_des.h: Remove (Unused, unsupported).
+ * librpc/include/rpc/rpc.h, librpc/Makefile.am: Reflect removing
+ auth_des.h.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+ * librpc/include/rpc/rpc_com.h, librpc/include/rpc/rpc_msg.h,
+ librpc/src/rpc/svc_simple.c: Minor fixes.
+ * include/rpc/clnt.h, include/rpc/svc.h,
+ librpc/include/rpc/clnt.h, librpc/include/rpc/clnt_soc.h,
+ src/rpc/clnt_perror.c: More updates from FreeBSD.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/svc.h: Partial update from FreeBSD.
+ * librpc/include/rpc/clnt.h: Partial update from FreeBSD.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/clnt_soc.h, librpc/include/rpc/svc_soc.h:
+ New (Partial update from FreeBSD).
+ * librpc/Makefile.am: Reflect changes above.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/des_crypt.h: Remove (Unused, unsupported).
+ * librpc/Makefile.am: Reflect changes above.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/des.h: Remove (Unused, unsupported).
+ * librpc/Makefile.am: Reflect changes above.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/auth_des.c,
+ librpc/src/rpc/auth_time.c,
+ librpc/src/rpc/authdes_prot.c,
+ librpc/src/rpc/clnt_unix.c,
+ librpc/src/rpc/crypt_client.c,
+ librpc/src/rpc/des_crypt.c,
+ librpc/src/rpc/des_soft.c,
+ librpc/src/rpc/getpublickey.c,
+ librpc/src/rpc/key_call.c,
+ librpc/src/rpc/key_prot_xdr.c,
+ librpc/src/rpc/svc_auth_des.c,
+ librpc/src/rpc/svc_unix.c: Remove (Unused, obsolete).
+ * librpc/Makefile.am: Reflect changes above.
+
+2005-05-25 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/src/rpc/PSD.doc/rpc.prog.ms,
+ librpc/src/rpc/PSD.doc/rpcgen.ms,
+ librpc/src/rpc/PSD.doc/nfs.rfc.ms,
+ librpc/src/rpc/PSD.doc/xdr.rfc.ms,
+ librpc/src/rpc/PSD.doc/rpc.rfc.ms,
+ librpc/src/rpc/PSD.doc/xdr.nts.ms:
+ Remove (Unused, obsolete).
+ * librpc/Makefile.am: Reflect changes above.
+
+2005-05-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/arpa/telnet.h: Remove (Unused, Non-POSIX/SUSV3).
+ * libnetworking/Makefile.am: Reflect removing arpa/telnet.h.
+
+2005-05-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/arpa/nameser.h: Update from FreeBSD.
+ * libnetworking/libc/ns_parse.c: Reflect changes above.
+ * libnetworking/netinet/ip.h: Remove BYTE_PACK.
+ Add __packed. Partial update from FreeBSD.
+ * libnetworking/netinet/ip_divert.c: Cosmetics from FreeBSD.
+
+2005-05-23 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/rtems/rtems_showicmpstat.c
+ * libnetworking/netinet/ip_icmp.c: note that a panic has been avoided
+
+2005-05-23 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR rtems_misc/795
+ * Makefile.am: Remove ada.
+ * configure.ac: Remove ada.
+
+2005-05-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/ip_icmp.c: Partial update from FreeBSD.
+ * libnetworking/sys/mbuf.h: Partial update from FreeBSD.
+ * libnetworking/netinet/ip_icmp.h: Update from FreeBSD.
+ Abandon BYTE_PACK.
+ * libnetworking/netdb.h: Update from FreeBSD.
+
+2005-05-20 Sergei Organov <osv@javad.ru>
+
+ PR networking/772.
+ * libnetworking/rtems/rtems_select.c (socket_select): fixed bug
+ setting SB_WAIT flag of so_rcv instead of so_snd when FWRITE.
+
+2005-05-20 Sergei Organov <osv@topconrd.ru>
+
+ PR 749/networking
+ * libnetworking/rtems/rtems_showroute.c: Avoid NULL dereference.
+
+2005-05-14 Sergei Organov <osv@topconrd.ru>
+
+ PR 746/rtems
+ Optimize realloc(). The problem is that realloc() can neither grow
+ nor shrink efficiently the current memory region without support
+ from underlying heap/region modules. The patch introduces one new
+ routine for each of heap and region modules, _Heap_Resize_block(),
+ and rtems_region_resize_segment(), respectively, and uses the
+ latter to optimize realloc().
+
+ The implementation of _Heap_Resize_block() lead to changing of the
+ heap allocation strategy: now the heap manager, when splits larger
+ free block into used and new free parts, makes the first part of
+ the block used, not the last one as it was before. Due to this new
+ strategy, _Heap_Resize_block() never needs to change the user
+ pointer.
+
+ Caveat: unlike previous heap implementation, first few bytes of
+ the contents of the memory allocated from the heap are now almost
+ never all zero. This can trigger bugs in client code that have not
+ been visible before this patch.
+
+ * libcsupport/src/malloc.c (realloc): try to resize segment in
+ place using new rtems_region_resize_segment() routine before
+ falling back to the malloc()/free() method.
+ * score/src/heap.c:
+ (_Heap_Initialize): change initial heap layout to reflect new
+ allocation strategy of using of the lower part of a previously
+ free block when splitting it for the purpose of allocation.
+ (_Heap_Block_allocate): when split, make the lower part used, and
+ leave the upper part free. Return type changed from Heap_Block* to
+ uint32_t.
+ * score/include/rtems/score/heap.h:
+ (Heap_Statistics): added 'resizes' field.
+ (Heap_Resize_status): new enum.
+ (_Heap_Resize_block): new routine.
+ (_Heap_Block_allocate): return type changed from Heap_Block* to
+ uint32_t.
+ * score/src/heapwalk.c: reflect new heap layout in checks.
+ * score/src/heapsizeofuserarea.c: more assertions added.
+ * score/src/heapresizeblock.c: new file.
+ (_Heap_Resize_block): new routine.
+ * score/src/heapfree.c: reverse the checks _Heap_Is_block_in() and
+ _Heap_Is_prev_used() on entry to be in this order.
+ * score/src/heapallocate.c, score/src/heapallocatealigned.c:
+ ignore return value of _Heap_Block_allocate().
+ * score/Makefile.am (HEAP_C_FILES): added src/heapresizeblock.c.
+ * rtems/include/rtems/rtems/region.h:
+ (rtems_region_resize_segment): new interface routine.
+ (_Region_Process_queue): new internal routine called from
+ rtems_region_resize_segment() and rtems_region_return_segment().
+ * rtems/src/regionreturnsegment.c: move queue management code into
+ the new internal routine _Region_Process_queue() and call it.
+
+ * rtems/src/regionresizesegment.c: new file.
+ (rtems_region_resize_segment): new interface routine.
+ * rtems/src/regionprocessqueue.c: new file.
+ (_Region_Process_queue): new internal routine containing queue
+ management code factored out from 'regionreturnsegment.c'.
+ * rtems/Makefile.am (REGION_C_FILES): Added
+ src/regionresizesegment.c, and src/regionprocessqueue.c.
+ * ada/rtems.adb, ada/rtems.ads: Added Region_Resize_Segment.
+
+2005-05-20 Eric Norum <norume@aps.anl.gov>
+
+ PR 793/networking
+ * libnetworking/netinet/ip_icmp.c: Malicious ICMP packet causes panic.
+ Just ignore it.
+
+2005-05-18 Chris Johns <chrisj@rtems.org>
+
+ * libmisc/capture/capture-cli.c: Fix the output of ctload when
+ there exists a large number of tasks.
+
+2005-05-17 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ * Makefile.am, preinstall.am: Added a common irq.h
+ * include/rtems/irq.h: New file.
+
+2005-05-14 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/tcp_usrreq.c: Cosmetics from FreeBSD.
+ * libnetworking/netinet/tcp_subr.c: Partical update from FreeBSD.
+
+2005-05-12 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Let --enable-deprecated default to "no".
+ * libnetworking/net/if_arp.h: Remove BYTE_PACK.
+ * libnetworking/net/if_llc.h: Update from FreeBSD, add __packed.
+ * libnetworking/net/route.h: Partial update from FreeBSD.
+ * libnetworking/netinet/if_ether.c: Partial update from FreeBSD.
+ * libnetworking/netinet/tcp_var.h: Partial update from FreeBSD.
+ * libnetworking/netinet/tcp_input.c: Reflect changes to tcp_var.h.
+ * libnetworking/netinet/tcp.h: Partial update from FreeBSD.
+ Remove BYTE_PACK.
+ * libnetworking/netinet/ip_var.h: Partial update from FreeBSD.
+ Remove some useless BYTE_PACKs.
+
+2005-05-12 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 784/networking
+ * libnetworking/net/if_arp.h, libnetworking/netinet/if_ether.h,
+ libnetworking/netinet/ip_icmp.h, libnetworking/netinet/ip_var.h,
+ libnetworking/netinet/tcp.h: Define BYTE_PACK.
+
+2005-05-11 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/rtsock.c: Abandon AF_NS.
+ * libnetworking/sys/socket.h: Abandon AF_NS, PF_NS.
+
+2005-05-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * httpd/socket.c: socklen_t.
+ * librpc/include/rpc/svc.h: Cosmetical update from FreeBSD.
+ * librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/clnt_udp.c,
+ librpc/src/rpc/pmap_rmt.c, librpc/src/rpc/rtime.c,
+ librpc/src/rpc/svc_tcp.c, librpc/src/rpc/svc_udp.c: socklen_t.
+ * ftpd/ftpd.c: socklen_t.
+ * libnetworking/lib/rtems_bsdnet_ntp.c: socklen_t.
+ * libnetworking/libc/rcmd.c: socklen_t.
+ * libnetworking/libc/res_send.c: socklen_t.
+
+2005-05-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.h: Remove IFI_* (obsolete, unused).
+ * libnetworking/net/if_var.h: Remove if_ipending (obsolete, unused).
+
+2005-05-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/un.h: Partial update from FreeBSD.
+ Remove non-implemented functions/variables.
+
+2005-05-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/bsdnet/_types.h: New.
+ * Makefile.am: Add rtems_bsdnet_HEADERS.
+ * libnetworking/Makefile.am: Remove rtems_bsdnet_HEADERS.
+ * preinstall.am, libnetworking/preinstall.am: Regenerate.
+ * libcsupport/include/sys/cdefs.h: Partial update from FreeBSD.
+ * libnetworking/arpa/inet.h: Partial update from FreeBSD.
+ * libnetworking/netinet/in.h: Partial update from FreeBSD.
+ * libnetworking/sys/socket.h: Partial update from FreeBSD.
+ * librpc/src/rpc/bindresvport.c: socklen_t.
+ * libnetworking/sys/mbuf.h: Ansification.
+ * libnetworking/kern/uipc_mbuf.c: Partial update from FreeBSD.
+ * libnetworking/libc/inet_addr.c: in_addr_t.
+ * libnetworking/lib/tftpDriver.c: socklen_t.
+ * libnetworking/libc/inet_lnaof.c: in_addr_t.
+ * libnetworking/libc/inet_makeaddr.c: in_addr_t.
+ * libnetworking/libc/inet_netof.c: in_addr_t.
+ * libnetworking/libc/inet_network.c: in_addr_t.
+ * libnetworking/libc/inet_ntop.c: Ansify, socklen_t.
+ * libnetworking/lib/ftpfs.c: socklen_t, PRIu32.
+
+2005-05-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/arpa/inet.h: Add in_addr_t, in_port_t.
+ * libnetworking/netinet/in.h: Sync in_port_t with arpa/inet.h.
+ * libnetworking/sys/socket.h: Include <sys/types.h>.
+ Remove in_port_t. Misc. updates from FreeBSD.
+
+2005-05-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/in.h: Partial update from FreeBSD.
+ Remove BYTE_PACK.
+ * libnetworking/netinet/ip.h: Add BYTE_PACK.
+ * libnetworking/sys/socket.h: Partial update from FreeBSD.
+
+2005-05-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/netinet/if_ether.c: Cosmetics from FreeBSD.
+ * libnetworking/libc/inet_addr.c: Cosmetics from FreeBSD.
+ * libnetworking/netinet/in.h: Cosmetics from FreeBSD.
+ * libnetworking/sys/socket.h: Cosmetics from FreeBSD.
+
+2005-05-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/un.h: Cosmetical updates from FreeBSD.
+ * libnetworking/net/if_var.h: More partial updates from FreeBSD.
+ * libnetworking/rtems/rtems_bsdnet.h: Eliminate rtems_* fixed size
+ types.
+
+2005-05-06 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/rtems/rtems_showifstat.c: Remove warning.
+ * libnetworking/net/if.h: Revert include of sys/mbuf.h in this .h file
+ since it causes other problems.
+
+2005-05-06 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/termios.c: Removed warnings.
+
+2005-05-06 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/if.h, libnetworking/net/if_ppp.c,
+ libnetworking/net/ppp_tty.c: Removed warnings.
+
+2005-05-06 Joel Sherrill <joel@OARcorp.com>
+
+ * libblock/src/blkdev.c, libfs/src/dosfs/fat_file.c,
+ libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_dir.c,
+ libfs/src/dosfs/msdos_initsupp.c, libfs/src/dosfs/msdos_misc.c:
+ Removed warnings.
+
+2005-05-04 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ * include/rtems/pci.h: Name change to support common PCI interface
+
+2005-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/include/ringbuf.h: Use uint8_t instead of char for raw
+ data buffer.
+
+2005-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ PR 775/core
+ * rtems/src/regiongetfreeinfo.c: Return RTEMS_SUCCESSFUL instead of
+ RTEMS_INVALID_ADDRESS on success path.
+
+2005-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_load_tar.c: Use uint8_t
+ instead of char for raw data buffer.
+
+2005-05-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/kern/kern_mib.c, libnetworking/sys/libkern.h:
+ Update from FreeBSD.
+
+2005-04-30 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: fix evaluating --enable-ada.
+
+2005-04-29 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ * score/src/objectidtoname.c: Removed warnings
+
+2005-04-28 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/kern/kern_sysctl.c, libnetworking/libc/inet_ntop.c,
+ libnetworking/net/if_ppp.c, libnetworking/net/pppcompress.c,
+ libnetworking/net/slcompress.c, libnetworking/netinet/ip_output.c,
+ libnetworking/netinet/udp_usrreq.c, libnetworking/nfs/bootp_subr.c,
+ libnetworking/rtems/rtems_select.c,
+ libnetworking/rtems/rtems_showifstat.c,
+ libnetworking/rtems/rtems_showroute.c,
+ libnetworking/rtems/rtems_syscall.c: Fixed type mismatch and
+ uninitialized variable warnings.
+
+2005-04-28 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/objectidtoname.c: Fixed spacing.
+
+2005-04-28 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ * score/src/objectidtoname.c: Add enable dispatch
+
+2005-04-28 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ * configure.ac: Remove or32-rtems
+
+2005-04-23 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/cpu/Makefile.am: Remove or32 (target abandoned).
+
+2005-04-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.h: Update from FreeBSD.
+ * libnetworking/net/if_loop.c: Reflect updates.
+ * libnetworking/net/if_ppp.c: Reflect updates.
+ * libnetworking/net/if_types.h: Update from FreeBSD.
+ * libnetworking/net/ethernet.h: Add RTEMS outdated either_input.
+ * libnetworking/net/if.c: Partial update from FreeBSD.
+ * libnetworking/net/if_ethersubr.c: Partial update from FreeBSD.
+ * libnetworking/net/if_var.h: New (extracted from net/if.h).
+ * libnetworking/Makefile.am: Add net/if_var.h.
+
+2005-04-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if.c, libnetworking/net/if.h,
+ libnetworking/sys/mbuf.h: Cosmetics from FreeBSD.
+
+2005-04-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/mount.h: More updates from FreeBSD.
+ Remove ufs, mfs, dosfs, isofs.
+ * libnetworking/nfsclient/nfsargs.h: More updates from FreeBSD.
+
+2005-04-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/rtsock.c: More updates from FreeBSD.
+
+2005-04-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/mount.h: Remove nfs_args.
+ * libnetworking/nfsclient/nfsargs.h: New (extracted from
+ sys/mount.h).
+ * libnetworking/nfsclient/nfsdiskless.h: New (Relocated from nfs/).
+ * libnetworking/nfs/nfsdiskless.h: Remove.
+ * libnetworking/net/netisr.h: Partial update from FreeBSD.
+ * libnetworking/net/rtsock.c: Cosmetical update from FreeBSD.
+ * libnetworking/sys/socket.h: Cosmetical update from FreeBSD.
+ * libnetworking/sys/queue.h: Cosmetical update from FreeBSD.
+ Remove special casing of arm/mips.
+ * libnetworking/nfs/bootp_subr.c: Reflect having introduced nfsclient/.
+ * libnetworking/Makefile.am: Remove changes above.
+
+2005-04-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_arp.h, libnetworking/netinet/ip.h,
+ libnetworking/netinet/ip_icmp.c: Partial updates from FreeBSD.
+
+2005-04-14 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_arp.h, libnetworking/net/if_ethersubr.c,
+ libnetworking/netinet/if_ether.h,
+ libnetworking/netinet/in.h: Partial updates from FreeBSD.
+
+2005-04-14 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/arpa/inet.h, libnetworking/net/if_dl.h:
+ Cosmetical update from FreeBSD.
+
+2005-04-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/monitor/mon-symbols.c: size_t.
+
+2005-03-14 Joel Sherrill <joel@OARcorp.com>
+
+ * include/rtems/pci.h: Continue PCI API unification. All use
+ pci_find_device().
+
+2005-03-14 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ * libnetworking/netinet/in_cksum_m68k.h: Change back to lcsum[12]_lbl
+ to temporary labels.
+
+2005-03-10 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/netinet/in_cksum_m68k.h: Change back to lcsum[12]_lbl
+ since my fix did not fix all issues.
+
+2005-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/netinet/in_cksum_m68k.h: Change lcsum[12]_lbl to
+ temporary inline assembly labels to remove compilation error.
+
+2005-03-04 Joel Sherrill <joel@OARcorp.com>
+
+ * include/rtems/pci.h: Clean up and reformatting. Make PCI initialize
+ function part of the unified PCI API.
+
+2005-03-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Check for newlib with stdint.h/inttypes.h.
+ * Makefile.am: Conditionally use external stdint.h/inttypes.h for
+ newlib.
+
+2005-02-22 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4: Rework rtems_updir handling to work around
+ ash cd'ing to '/' for 'cd .//'.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 764/networking
+ * libnetworking/sys/sysctl.h: include <rtems/stdint.h>.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/objectmp.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/threadmp.inl,
+ score/inline/rtems/score/tod.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/userext.inl,
+ score/inline/rtems/score/watchdog.inl,
+ score/inline/rtems/score/wkspace.inl,
+ score/macros/rtems/score/address.inl,
+ score/macros/rtems/score/chain.inl,
+ score/macros/rtems/score/coremsg.inl,
+ score/macros/rtems/score/coremutex.inl,
+ score/macros/rtems/score/coresem.inl,
+ score/macros/rtems/score/heap.inl,
+ score/macros/rtems/score/isr.inl,
+ score/macros/rtems/score/mppkt.inl,
+ score/macros/rtems/score/object.inl,
+ score/macros/rtems/score/objectmp.inl,
+ score/macros/rtems/score/priority.inl,
+ score/macros/rtems/score/stack.inl,
+ score/macros/rtems/score/states.inl,
+ score/macros/rtems/score/sysstate.inl,
+ score/macros/rtems/score/thread.inl,
+ score/macros/rtems/score/threadmp.inl,
+ score/macros/rtems/score/tod.inl,
+ score/macros/rtems/score/tqdata.inl,
+ score/macros/rtems/score/userext.inl,
+ score/macros/rtems/score/watchdog.inl,
+ score/macros/rtems/score/wkspace.inl: New header guards.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/inline/rtems/rtems/asr.inl,
+ rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/dpmem.inl,
+ rtems/inline/rtems/rtems/event.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/tasks.inl,
+ rtems/inline/rtems/rtems/timer.inl,
+ rtems/macros/rtems/rtems/asr.inl,
+ rtems/macros/rtems/rtems/attr.inl,
+ rtems/macros/rtems/rtems/dpmem.inl,
+ rtems/macros/rtems/rtems/event.inl,
+ rtems/macros/rtems/rtems/eventset.inl,
+ rtems/macros/rtems/rtems/message.inl,
+ rtems/macros/rtems/rtems/modes.inl,
+ rtems/macros/rtems/rtems/options.inl,
+ rtems/macros/rtems/rtems/part.inl,
+ rtems/macros/rtems/rtems/ratemon.inl,
+ rtems/macros/rtems/rtems/region.inl,
+ rtems/macros/rtems/rtems/sem.inl,
+ rtems/macros/rtems/rtems/status.inl,
+ rtems/macros/rtems/rtems/support.inl,
+ rtems/macros/rtems/rtems/tasks.inl,
+ rtems/macros/rtems/rtems/timer.inl: New header guards.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * itron/inline/rtems/itron/eventflags.inl,
+ itron/inline/rtems/itron/fmempool.inl,
+ itron/inline/rtems/itron/intr.inl,
+ itron/inline/rtems/itron/mbox.inl,
+ itron/inline/rtems/itron/msgbuffer.inl,
+ itron/inline/rtems/itron/network.inl,
+ itron/inline/rtems/itron/port.inl,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/inline/rtems/itron/sysmgmt.inl,
+ itron/inline/rtems/itron/task.inl,
+ itron/inline/rtems/itron/time.inl,
+ itron/inline/rtems/itron/vmempool.inl,
+ itron/macros/rtems/itron/eventflags.inl,
+ itron/macros/rtems/itron/fmempool.inl,
+ itron/macros/rtems/itron/intr.inl,
+ itron/macros/rtems/itron/mbox.inl,
+ itron/macros/rtems/itron/msgbuffer.inl,
+ itron/macros/rtems/itron/network.inl,
+ itron/macros/rtems/itron/port.inl,
+ itron/macros/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/sysmgmt.inl,
+ itron/macros/rtems/itron/task.inl,
+ itron/macros/rtems/itron/time.inl,
+ itron/macros/rtems/itron/vmempool.inl: New header guards.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * posix/inline/rtems/posix/cond.inl,
+ posix/inline/rtems/posix/intr.inl,
+ posix/inline/rtems/posix/key.inl,
+ posix/inline/rtems/posix/mqueue.inl,
+ posix/inline/rtems/posix/mutex.inl,
+ posix/inline/rtems/posix/priority.inl,
+ posix/inline/rtems/posix/pthread.inl,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/inline/rtems/posix/timer.inl,
+ posix/macros/rtems/posix/cond.inl,
+ posix/macros/rtems/posix/intr.inl,
+ posix/macros/rtems/posix/key.inl,
+ posix/macros/rtems/posix/mqueue.inl,
+ posix/macros/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/priority.inl,
+ posix/macros/rtems/posix/pthread.inl,
+ posix/macros/rtems/posix/semaphore.inl,
+ posix/macros/rtems/posix/timer.inl: New header guards.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * posix/include/aio.h, posix/include/devctl.h,
+ posix/include/intr.h, posix/include/mqueue.h,
+ posix/include/sched.h, posix/include/semaphore.h,
+ posix/include/rtems/posix/cancel.h,
+ posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/condmp.h,
+ posix/include/rtems/posix/config.h,
+ posix/include/rtems/posix/intr.h,
+ posix/include/rtems/posix/key.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mqueuemp.h,
+ posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/mutexmp.h,
+ posix/include/rtems/posix/posixapi.h,
+ posix/include/rtems/posix/priority.h,
+ posix/include/rtems/posix/psignal.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/pthreadmp.h,
+ posix/include/rtems/posix/ptimer.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/semaphoremp.h,
+ posix/include/rtems/posix/threadsup.h,
+ posix/include/rtems/posix/time.h,
+ posix/include/rtems/posix/timer.h: New header guards.
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * backward/asm.h, backward/chain.h, backward/clockdrv.h,
+ backward/confdefs.h, backward/console.h, backward/dosfs.h,
+ backward/ftpd.h, backward/imfs.h, backward/iosupp.h,
+ backward/itron.h, backward/ringbuf.h, backward/rtc.h,
+ backward/spurious.h, backward/timerdrv.h, backward/vmeintr.h,
+ backward/motorola/mc68230.h, backward/motorola/mc68681.h,
+ backward/zilog/z8030.h, backward/zilog/z8036.h,
+ backward/zilog/z8536.h:
+ New header guards.
+
+2005-02-19 Joel Sherrill <joel@OARcorp.com>
+
+ PR doc/763
+ * score/Doxyfile: Fixed path to no_cpu.
+
+2005-02-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Check for external ampolish3.
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/vm/vm_extern.h, libnetworking/vm/vm_kern.h:
+ Update from FreeBSD.
+
+2005-02-17 Joel Sherrill <joel@OARcorp.com>
+
+ * include/rtems/pci.h: Merge differences from
+ libbsp/powerpc/shared/pci/pci.h.
+
+2005-02-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/vm/vm_param.h: Update from FreeBSD.
+
+2005-02-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/diskdevs.h: Use uint32_t for ictrl req
+ argument (16bit target compliance).
+
+2005-02-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/ramdisk.h:
+ size_t rtems_ramdisk_configuration_size.
+ * libblock/src/ramdisk.c: Adaptations for 16bit target compliance.
+
+2005-02-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/sys/sysctl.h (struct sysctl_oid): uint32_t
+ oid_kind (16bit target compliance).
+
+2005-02-12 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Remove LIBSCORECPU.
+ * wrapup/Makefile.am: Reflect changes above.
+
+2005-02-10 Joel Sherrill <joel@OARcorp.com>
+
+ PR 753/rtems
+ * score/include/rtems/score/object.h,
+ score/src/objectinitializeinformation.c: Configured number of objects
+ needs to be of a type with more bits than Objects_Maximum to support
+ configuring unlimited objects. The type for configuring the maximum
+ number of objects should probably always be the same fundamental type
+ as Object Id. For 16-bit Id configurations, the constant
+ OBJECTS_UNLIMITED_OBJECTS was changed to 0x8000 to move in this
+ direction.
+
+2005-02-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/untar/untar.c (_rtems_octal2ulong): Replace.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * ftpd/Makefile.am: Split preinstallation rules in to separate
+ preinstall.am-files.
+ * ftpd/preinstall.am: New (Generated from corresponding Makefile.am).
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/Makefile.am: Split preinstallation rules in to separate
+ preinstall.am-files.
+ * librpc/preinstall.am: New (Generated from corresponding Makefile.am).
+
+2005-02-08 Eric Norum <norum@aps.anl.gov>
+
+ * libfs/Makefile.am, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/imfs_handlers_memfile.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
+ libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/linearfile.c,
+ libfs/src/imfs/memfile.c, libfs/src/imfs/miniimfs_init.c: Add
+ 'copy-on-write' semantics to rtems_tarfs_load().
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * httpd/Makefile.am: Split preinstallation rules in to separate
+ preinstall.am-files.
+ * httpd/preinstall.am: New (Generated from corresponding Makefile.am).
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * itron/Makefile.am, libcsupport/Makefile.am,
+ libnetworking/Makefile.am, posix/Makefile.am,
+ rtems/Makefile.am, sapi/Makefile.am,
+ score/Makefile.am, wrapup/Makefile.am,
+ Makefile.am: Split preinstallation rules in to separate
+ preinstall.am-files.
+ * itron/preinstall.am, libcsupport/preinstall.am,
+ libnetworking/preinstall.am, posix/preinstall.am,
+ rtems/preinstall.am, sapi/preinstall.am,
+ score/preinstall.am, wrapup/preinstall.am,
+ preinstall.am: New (Generated from corresponding Makefile.ams).
+ * configure.ac: Add AM_CONDITIONAL(AMPOLISH3)-stub.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * configure.ac: Add new header guard to cpuopts.h.
+ * Makefile.am: Add libfs, libblock, ftpd header install rules.
+ * libfs/Makefile.am, libblock/Makefile.am, ftpd/Makefile.am: Remove
+ header install rules.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4 (rtems_updir): Quote sed args.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_ppp.c, libnetworking/net/if_pppvar.h:
+ Ansification, cosmetics from FreeBSD.
+
+2005-02-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_load_tar.c,
+ libmisc/untar/untar.c, libmisc/untar/untar.h:
+ Various generalizations and fixes.
+
+2005-02-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Add include/rtems/tar.h.
+ Merge-in header rules from libmisc/Makefile.am
+ * libmisc/Makefile.am: Remove header rules.
+ Remove lib-specific CPPFLAGS.
+ * configure.ac: Add checks for <tar.h>
+
+2005-02-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * include/rtems/tar.h: New.
+
+2005-02-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/Makefile.am: Build libfs/src/imfs/imfs_load_tar.c.
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/libc/res_init.c, libnetworking/netinet/in.h,
+ libnetworking/netinet/in_pcb.c, libnetworking/netinet/raw_ip.c:
+ Misc. part. updates from FreeBSD.
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * automake/compile.am: Remove depend: (Redundant).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/sem.h, rtems/src/semcreate.c,
+ rtems/src/semdelete.c, rtems/src/semflush.c,
+ rtems/src/semident.c, rtems/src/semobtain.c,
+ rtems/src/semrelease.c: Use rtems_id for semaphores.
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/rtems/libio.h: Use rtems_id for semaphores.
+ Use char* for buffer.
+ * backward/ftpd.h: New.
+ * Makefile.am: Reflect having added backward/ftpd.h.
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 756/rtems
+ * ftpd/ftpd.c, ftpd/ftpd.h, ftpd/Makefile.am: New (relocated from
+ /c/src/libnetworking/ftpd)
+ * ftpd/ftd.h: New header guards.
+ * ftpd/Makefile.am: Install libftd.a, install ftp.h to rtems/ftp.h.
+ * configure.ac: Add ftpd/Makefile.
+ * Makefile.am: Add ftpd.
+
+2005-02-03 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/clnt_stat.h, librpc/include/rpc/rpcent.h:
+ New (From FreeBSD).
+ * librpc/include/rpc/rpc.h: Partial update from FreeBSD.
+ * librpc/Makefile.am: Reflect changes above.
+
+2005-02-03 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/types.h: Partial update from FreeBSD.
+ Use stdint.h types instead of sys/types.h.
+ * librpc/src/rpc/bindresvport.c: Partial update from FreeBSD.
+
+2005-02-03 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 755/rtems
+ * libnetworking/libc/res_init.c, libnetworking/lib/rtems_bsdnet_ntp.c,
+ libnetworking/nfs/bootp_subr.c: Include <rtems/bsdnet/servers.h>.
+
+2005-02-03 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 755/rtems
+ * libnetworking/rtems_glue.c:
+ Rename rtems_bsdnet_nameservers to _rtems_bsdnet_nameservers.
+ Rename rtems_bsdnet_ntpservers to _rtems_bsdnet_ntpservers.
+ Add new rtems_bsdnet_nameservers, rtems_bsdnet_ntpservers as
+ pointers to _rtems_bsdnet_*servers arrays.
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Remove
+ rtems_bsdnet_nameserver, rtems_bsdnet_nameserver_count.
+ * libnetworking/rtems/rtems_bsdnet.h: Remove
+ rtems_bsdnet_ntpserver, rtems_bsdnet_ntp_count.
+ * libnetworking/rtems/bsdnet/servers.h: New.
+ * libnetworking/opt_ipsec.h: New (BSD compatibility).
+ * libnetworking/Makefile.am: Reflect changes above.
+
+2005-02-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/ftpfs.h, libnetworking/rtems/mkrootfs.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/tftp.h: New header guards.
+
+2005-02-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/rtems/issetugid.c,
+ libnetworking/rtems/mkrootfs.c,
+ libnetworking/rtems/rtems_bootp.c,
+ libnetworking/rtems/rtems_bsdnet_malloc_starvation.c,
+ libnetworking/rtems/rtems_glue.c,
+ libnetworking/rtems/rtems_select.c,
+ libnetworking/rtems/rtems_showicmpstat.c,
+ libnetworking/rtems/rtems_showifstat.c,
+ libnetworking/rtems/rtems_showipstat.c,
+ libnetworking/rtems/rtems_showmbuf.c,
+ libnetworking/rtems/rtems_showroute.c,
+ libnetworking/rtems/rtems_showtcpstat.c,
+ libnetworking/rtems/rtems_showudpstat.c,
+ libnetworking/rtems/rtems_syscall.c,
+ libnetworking/rtems/sghostname.c: Include config.h.
+
+2005-02-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libblock/include/rtems/bdbuf.h,
+ libblock/include/rtems/ide_part_table.h, libblock/src/blkdev.c,
+ libcsupport/include/rtems/termiostypes.h, libcsupport/src/termios.c,
+ posix/macros/rtems/posix/cond.inl,
+ posix/macros/rtems/posix/mutex.inl : Remove warnings.
+
+2005-02-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/prog-cc.m4: Remove refs to gcc-isystem.m4.
+ * aclocal/gcc-isystem.m4: Remove (Unused).
+
+2005-01-28 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/rtems/rtems_glue.c: Remove dead variable.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * itron/include/itron.h,
+ itron/include/itronsys/eventflags.h,
+ itron/include/itronsys/fmempool.h,
+ itron/include/itronsys/intr.h,
+ itron/include/itronsys/mbox.h,
+ itron/include/itronsys/msgbuffer.h,
+ itron/include/itronsys/network.h,
+ itron/include/itronsys/port.h,
+ itron/include/itronsys/semaphore.h,
+ itron/include/itronsys/status.h,
+ itron/include/itronsys/sysmgmt.h,
+ itron/include/itronsys/task.h,
+ itron/include/itronsys/time.h,
+ itron/include/itronsys/types.h,
+ itron/include/itronsys/vmempool.h,
+ itron/include/rtems/itron/config.h,
+ itron/include/rtems/itron/eventflags.h,
+ itron/include/rtems/itron/fmempool.h,
+ itron/include/rtems/itron/intr.h,
+ itron/include/rtems/itron/itronapi.h,
+ itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/network.h,
+ itron/include/rtems/itron/object.h,
+ itron/include/rtems/itron/port.h,
+ itron/include/rtems/itron/semaphore.h,
+ itron/include/rtems/itron/sysmgmt.h,
+ itron/include/rtems/itron/task.h,
+ itron/include/rtems/itron/time.h,
+ itron/include/rtems/itron/vmempool.h: New header guards.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/bdbuf.h, libblock/include/rtems/blkdev.h,
+ libblock/include/rtems/diskdevs.h,
+ libblock/include/rtems/ide_part_table.h,
+ libblock/include/rtems/ramdisk.h,
+ libfs/src/dosfs/dosfs.h, libfs/src/imfs/imfs.h:
+ New header guards.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/inttypes.h: New header guard.
+ Fix doxygen preamble.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/motorola/mc68230.h,
+ libcsupport/include/motorola/mc68681.h,
+ libcsupport/include/chain.h,
+ libcsupport/include/clockdrv.h,
+ libcsupport/include/console.h,
+ libcsupport/include/iosupp.h,
+ libcsupport/include/ringbuf.h,
+ libcsupport/include/rtc.h,
+ libcsupport/include/spurious.h,
+ libcsupport/include/timerdrv.h,
+ libcsupport/include/vmeintr.h,
+ libcsupport/include/rtems/libio.h,
+ libcsupport/include/rtems/assoc.h,
+ libcsupport/include/rtems/error.h,
+ libcsupport/include/rtems/libcsupport.h,
+ libcsupport/include/rtems/libio_.h,
+ libcsupport/include/rtems/termiostypes.h,
+ libcsupport/include/rtems/cdefs.h,
+ libcsupport/include/zilog/z8036.h,
+ libcsupport/include/zilog/z8530.h,
+ libcsupport/include/zilog/z8536.h: New header guards.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * include/rtems/bspIo.h, include/rtems/concat.h,
+ include/rtems/fs.h, include/rtems/pci.h,
+ include/rtems/stdint.h, include/rtems/userenv.h:
+ New header guards.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/include/rtems.h, rtems/include/rtems/rtems/asr.h,
+ rtems/include/rtems/rtems/attr.h, rtems/include/rtems/rtems/cache.h,
+ rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/dpmem.h,
+ rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/eventmp.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/modes.h, rtems/include/rtems/rtems/mp.h,
+ rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/options.h,
+ rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/partmp.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/rtemsapi.h,
+ rtems/include/rtems/rtems/sem.h, rtems/include/rtems/rtems/semmp.h,
+ rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/status.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h,
+ rtems/include/rtems/rtems/tasks.h,
+ rtems/include/rtems/rtems/timer.h,
+ rtems/include/rtems/rtems/types.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/extension.h, sapi/include/rtems/fatal.h,
+ sapi/include/rtems/init.h, sapi/include/rtems/io.h,
+ sapi/include/rtems/mptables.h, sapi/include/rtems/sptables.h,
+ score/include/rtems/debug.h, score/include/rtems/seterr.h,
+ score/include/rtems/system.h, score/include/rtems/score/address.h,
+ score/include/rtems/score/apiext.h,
+ score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/copyrt.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h,
+ score/include/rtems/score/interr.h, score/include/rtems/score/isr.h,
+ score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h: New header guard.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * automake/compile.am: Remove RTEMS_CPPFLAGS.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_pppvar.h: Ansify.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * include/rtems/userenv.h: Set up LOGIN_NAME_MAX iff not having been
+ defined before.
+
+2005-01-28 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * sapi/src/debug.c, sapi/src/exinit.c, sapi/src/extension.c,
+ sapi/src/extensioncreate.c, sapi/src/extensiondelete.c,
+ sapi/src/extensionident.c, sapi/src/fatal.c, sapi/src/io.c,
+ sapi/src/itronapi.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c:
+ Include config.h.
+
+2005-01-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/lstat.c, libcsupport/src/readdir_r.c:
+ Include config.h.
+
+2005-01-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/untar/untar.h: New prototype to eleminate warnings.
+ * libmisc/untar/untar.c: Cosmetics, add symlinks.
+
+2005-01-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/tar.h: New (SUSv3).
+ * Makefile.am: Integrate newlib-specific headers.
+ Add libcsupport/include/tar.h.
+ * libcsupport/Makefile.am: Remove newlib-specific headers.
+
+2005-01-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/fsmount/fsmount.c: Include config.h.
+
+2005-01-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/src/apiext.c, score/src/chain.c, score/src/coremsg.c,
+ score/src/coremsgbroadcast.c, score/src/coremsgclose.c,
+ score/src/coremsgflush.c, score/src/coremsgflushsupp.c,
+ score/src/coremsgflushwait.c, score/src/coremsginsert.c,
+ score/src/coremsgseize.c, score/src/coremsgsubmit.c,
+ score/src/coremutex.c, score/src/coremutexflush.c,
+ score/src/coremutexseize.c, score/src/coremutexsurrender.c,
+ score/src/coresem.c, score/src/coresemflush.c,
+ score/src/coresemseize.c, score/src/coresemsurrender.c,
+ score/src/coretod.c, score/src/coretodset.c,
+ score/src/coretodtickle.c, score/src/coretodtoseconds.c,
+ score/src/coretodvalidate.c, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapallocatealigned.c,
+ score/src/heapextend.c, score/src/heapfree.c,
+ score/src/heapgetfreeinfo.c, score/src/heapgetinfo.c,
+ score/src/heapsizeofuserarea.c, score/src/heapwalk.c,
+ score/src/interr.c, score/src/isr.c, score/src/iterateoverthreads.c,
+ score/src/mpci.c, score/src/object.c, score/src/objectallocate.c,
+ score/src/objectallocatebyindex.c, score/src/objectclearname.c,
+ score/src/objectcomparenameraw.c,
+ score/src/objectcomparenamestring.c, score/src/objectcopynameraw.c,
+ score/src/objectcopynamestring.c,
+ score/src/objectextendinformation.c, score/src/objectfree.c,
+ score/src/objectget.c, score/src/objectgetbyindex.c,
+ score/src/objectgetisr.c, score/src/objectgetnext.c,
+ score/src/objectgetnoprotection.c, score/src/objectidtoname.c,
+ score/src/objectinitializeinformation.c, score/src/objectmp.c,
+ score/src/objectnametoid.c, score/src/objectshrinkinformation.c,
+ score/src/thread.c, score/src/threadchangepriority.c,
+ score/src/threadclearstate.c, score/src/threadclose.c,
+ score/src/threadcreateidle.c, score/src/threaddelayended.c,
+ score/src/threaddispatch.c, score/src/threadevaluatemode.c,
+ score/src/threadget.c, score/src/threadhandler.c,
+ score/src/threadidlebody.c, score/src/threadinitialize.c,
+ score/src/threadloadenv.c, score/src/threadmp.c,
+ score/src/threadq.c, score/src/threadqdequeue.c,
+ score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c,
+ score/src/threadqenqueue.c, score/src/threadqenqueuefifo.c,
+ score/src/threadqenqueuepriority.c, score/src/threadqextract.c,
+ score/src/threadqextractfifo.c, score/src/threadqextractpriority.c,
+ score/src/threadqextractwithproxy.c, score/src/threadqfirst.c,
+ score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c,
+ score/src/threadqflush.c, score/src/threadqtimeout.c,
+ score/src/threadready.c, score/src/threadreset.c,
+ score/src/threadresettimeslice.c, score/src/threadrestart.c,
+ score/src/threadresume.c, score/src/threadrotatequeue.c,
+ score/src/threadsetpriority.c, score/src/threadsetstate.c,
+ score/src/threadsettransient.c, score/src/threadstackallocate.c,
+ score/src/threadstackfree.c, score/src/threadstart.c,
+ score/src/threadstartmultitasking.c, score/src/threadsuspend.c,
+ score/src/threadtickletimeslice.c, score/src/threadyieldprocessor.c,
+ score/src/userext.c, score/src/watchdog.c,
+ score/src/watchdogadjust.c, score/src/watchdoginsert.c,
+ score/src/watchdogremove.c, score/src/watchdogtickle.c,
+ score/src/wkspace.c: Include config.h.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * include/rtems/stdint.h: Add signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/heap.h: Use uintptr_t for _H_uptr_t.
+ * score/inline/rtems/score/address.inl: Remove
+ RTEMS_CPU_HAS_16_BIT_ADDRESSES.
+ Use uintptr_t for void* to address casts.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/stdint.h: Use __PTRDIFF_TYPE__ for intptr_t.
+
+2005-01-23 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * sapi/src/fatal.c, score/src/interr.c:
+ Remove volatile on return type.
+
+2005-01-20 Sergei Organov <osv@topconrd.ru>
+
+ PR 536/rtems
+ Heap manager re-implementation to consume less memory and still satisfy
+ alignment requirements.
+
+ * score/src/heap.c, score/src/heapallocate.c, score/src/heapextend.c,
+ score/src/heapfree.c, score/src/heapgetinfo.c,
+ score/src/heapgetfreeinfo.c, core/src/heapsizeofuserarea.c,
+ score/src/heapwalk.c, core/macros/rtems/score/heap.inl,
+ score/inline/rtems/score/heap.inl,
+ score/include/rtems/score/heap.h: Reimplemented.
+ * score/src/heapallocatealigned.c: new file
+ * score/Makefile.am: HEAP_C_FILES: add score/src/heapallocatealigned.c
+
+2005-01-20 Joel Sherrill <joel@OARcorp.com>
+
+ PR 745/rtems
+ * rtems/src/ratemoncreate.c, rtems/src/timercreate.c: Make sure
+ internal timer structures are initialized so object control reuse is
+ safe.
+
+2005-01-20 Joel Sherrill <joel@OARcorp.com>
+
+ PR 740/rtems
+ * score/src/heapgetfreeinfo.c: Return size of largest not of last block.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/dosfs/fat.c (fat_init_volume_info): Reflect
+ fs_info->sec_buf being a uint8_t.
+ * libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c:
+ Eliminate warnings.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/dosfs/msdos_misc.c
+ (msdos_get_dotdot_dir_info_cluster_num_and_offset):
+ Remove cur_node (Unused).
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/termios.c: Remove unnecessary type casts.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * sapi/include/rtems/io.h : size_t device_name_length.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * sapi/include/rtems/fatal.h, score/include/rtems/score/interr.h:
+ Remove volatile on return type.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * itron/inline/rtems/itron/task.inl (_ITRON_Task_Priority_to_Core,
+ _ITRON_tasks_Core_to_Priority): Correct return types.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/src/attr.c, rtems/src/clockget.c, rtems/src/clockset.c,
+ rtems/src/clocktick.c, rtems/src/dpmem.c, rtems/src/dpmemcreate.c,
+ rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c,
+ rtems/src/dpmemident.c, rtems/src/dpmeminternal2external.c,
+ rtems/src/event.c, rtems/src/eventmp.c, rtems/src/eventreceive.c,
+ rtems/src/eventseize.c, rtems/src/eventsend.c,
+ rtems/src/eventsurrender.c, rtems/src/eventtimeout.c,
+ rtems/src/intr.c, rtems/src/intrbody.c, rtems/src/intrcatch.c,
+ rtems/src/mp.c, rtems/src/msg.c, rtems/src/msgmp.c,
+ rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c,
+ rtems/src/msgqcreate.c, rtems/src/msgqdelete.c,
+ rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c,
+ rtems/src/msgqident.c, rtems/src/msgqreceive.c,
+ rtems/src/msgqsend.c, rtems/src/msgqsubmit.c,
+ rtems/src/msgqtranslatereturncode.c, rtems/src/msgqurgent.c,
+ rtems/src/part.c, rtems/src/partcreate.c, rtems/src/partdelete.c,
+ rtems/src/partgetbuffer.c, rtems/src/partident.c,
+ rtems/src/partmp.c, rtems/src/partreturnbuffer.c,
+ rtems/src/ratemon.c, rtems/src/ratemoncancel.c,
+ rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c,
+ rtems/src/ratemonperiod.c, rtems/src/ratemontimeout.c,
+ rtems/src/region.c, rtems/src/regioncreate.c,
+ rtems/src/regiondelete.c, rtems/src/regionextend.c,
+ rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c,
+ rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c,
+ rtems/src/regionident.c, rtems/src/regionmp.c,
+ rtems/src/regionreturnsegment.c, rtems/src/rtclock.c,
+ rtems/src/rtemsidtoname.c, rtems/src/rtemstimer.c, rtems/src/sem.c,
+ rtems/src/semcreate.c, rtems/src/semdelete.c, rtems/src/semflush.c,
+ rtems/src/semident.c, rtems/src/semmp.c, rtems/src/semobtain.c,
+ rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c,
+ rtems/src/signal.c, rtems/src/signalcatch.c, rtems/src/signalmp.c,
+ rtems/src/signalsend.c, rtems/src/taskcreate.c,
+ rtems/src/taskdelete.c, rtems/src/taskgetnote.c,
+ rtems/src/taskident.c, rtems/src/taskinitusers.c,
+ rtems/src/taskissuspended.c, rtems/src/taskmode.c,
+ rtems/src/taskmp.c, rtems/src/taskrestart.c, rtems/src/taskresume.c,
+ rtems/src/tasks.c, rtems/src/tasksetnote.c,
+ rtems/src/tasksetpriority.c, rtems/src/taskstart.c,
+ rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c,
+ rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c,
+ rtems/src/taskwakeafter.c, rtems/src/taskwakewhen.c,
+ rtems/src/timercancel.c, rtems/src/timercreate.c,
+ rtems/src/timerdelete.c, rtems/src/timerfireafter.c,
+ rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c,
+ rtems/src/timerident.c, rtems/src/timerreset.c,
+ rtems/src/timerserver.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c: Include config.h.
+
+2005-01-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/inline/rtems/score/userext.inl: Include <string.h>.
+
+2005-01-14 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 742/rtems
+ * score/include/rtems/system.h: Remove stringify().
+
+2005-01-13 Joel Sherrill <joel@oarcorp.com>
+ Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/src/gxx_wrapper.c: Reflect GCC-4.0's gthr-rtems.h.
+
+2005-01-09 Joel Sherrill <joel@oarcorp.com>
+
+ * librpc/include/rpc/clnt.h, librpc/src/rpc/authunix_prot.c,
+ librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/pmap_prot2.c,
+ librpc/src/rpc/pmap_rmt.c, librpc/src/rpc/rtems_portmapper.c,
+ librpc/src/rpc/svc_simple.c: Fix warnings.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/auth_des.h, librpc/include/rpc/xdr.h,
+ librpc/src/rpc/auth_des.c, librpc/src/rpc/auth_unix.c,
+ librpc/src/rpc/rpc_prot.c, librpc/src/xdr/xdr.c:
+ Misc. ansi-fications, misc. updates from FreeBSD.
+
+2005-01-07 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/libc/res_debug.c: Added const to eliminate warnings.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/xdr.h: Remove questionable comments.
+ * librpc/include/rpc/auth.h: Remove __P, ansi-fy.
+ * librpc/src/rpc/auth_none.c: Reflect changes above.
+ Partial update from FreeBSD.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/mutex.h: Cosmetics.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/svc.h, librpc/include/rpc/xdr.h:
+ Remove __P(xx).
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * httpd/Makefile.am, itron/Makefile.am, libblock/Makefile.am,
+ libcsupport/Makefile.am, libfs/Makefile.am, libmisc/Makefile.am,
+ libnetworking/Makefile.am, librpc/Makefile.am, posix/Makefile.am,
+ rtems/Makefile.am, sapi/Makefile.am, score/Makefile.am:
+ Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/rtems-flags.m4: Remove (Unused).
+
+2005-01-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/prog-ccas.m4: Remove $(GCCSPECS).
+
+2005-01-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/src/eventsurrender.c: Remove bogus type casts.
+ * sapi/Makefile.am: Eliminate *_FILES.
+
+2005-01-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/env-rtemscpu.m4: Remove CFLAGS_OPTIMIZE_V.
+ Remove CPU_CFLAGS.
+ * aclocal/prog-cc.m4: Don't invoke _RTEMS_FLAGS to set up
+ RTEMS_CFLAGS.
+ * automake/compile.am: AM_CFLAGS = RTEMS_CFLAGS.
+ Remove CPPFLAGS, CFLAGS, CPU_CFLAGS, CFLAGS_OPTIMIZE.
+ Cleanup comments.
+
+2005-01-05 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/env-rtemscpu.m4: Remove CFLAGS_DEBUG_V.
+ * aclocal/prog-cc.m4: Remove RTEMS_USE_GCC.
+ * automake/compile.am: Cleanup comments. Remove ASFLAGS.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * automake/compile.am, httpd/Makefile.am, itron/Makefile.am,
+ libblock/Makefile.am, libcsupport/Makefile.am, libfs/Makefile.am,
+ libmisc/Makefile.am, libnetworking/Makefile.am, librpc/Makefile.am,
+ posix/Makefile.am, rtems/Makefile.am, sapi/Makefile.am,
+ score/Makefile.am, wrapup/Makefile.am:
+ Remove build-variant support.
+
+2004-12-30 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * httpd/Makefile.am: Remove -DOS="RTEMS".
+ * httpd/rtems_webserver.h: Add doxygen preamble.
+ Add C++ guards.
+
+2004-12-29 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/score/chain.h:
+ Use uint32_t instead of unsigned32.
+ * score/src/chain.c: Remove superfluous type cast.
+
+2004-12-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * posix/include/aio.h, posix/include/devctl.h,
+ posix/include/intr.h, posix/include/mqueue.h,
+ posix/include/sched.h, posix/include/semaphore.h,
+ posix/src/ptimer.c, posix/src/ptimer1.c:
+ Include <unistd.h> instead of <sys/features.h> to pick up
+ _POSIX_* defines (Mandated by POSIX).
+
+2004-12-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/system.h: Don't define NULL, include
+ <stddef.h>.
+
+2004-12-03 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/if_ethersubr.c,
+ libnetworking/net/radix.h,
+ libnetworking/netinet/if_ether.h,
+ libnetworking/netinet/igmp_var.h,
+ libnetworking/netinet/in_var.h,
+ libnetworking/netinet/tcp_timer.h,
+ libnetworking/netinet/udp_usrreq.c,
+ libnetworking/rtems/rtems_glue.c:
+ Misc. updates from FreeBSD and bugfixes tripped by GCC-4.0.0.
+
+2004-12-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/kern/kern_sysctl.c,
+ libnetworking/sys/sysctl.h: Add SYSCTL_CHILDREN_SET.
+ (Update from FreeBSD for GCC-4.0.0).
+
+2004-12-02 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/kern/kern_sysctl.c, libnetworking/netinet/ip_mroute.c,
+ libnetworking/sys/socketvar.h: Remove warnings.
+
+2004-12-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/net/radix.c, libnetworking/net/radix.h,
+ libnetworking/net/route.h, libnetworking/netinet/if_ether.h,
+ libnetworking/netinet/in_var.h, libnetworking/netinet/tcp_timer.h,
+ libnetworking/netinet/udp_usrreq.c, libnetworking/netinet/udp_var.h,
+ libnetworking/sys/callout.h, libnetworking/sys/socketvar.h,
+ libnetworking/sys/sysctl.h: Cosmetics from FreeBSD.
+
+2004-12-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libmisc/capture/capture-cli.h, libmisc/capture/capture.h,
+ libmisc/monitor/monitor.h, libmisc/rtmonuse/rtmonuse.h,
+ libmisc/shell/shell.h: Partial doxygenification.
+ * libmisc/capture/capture.h: Use INT32_C for constants.
+
+2004-12-02 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/chain.h,
+ libcsupport/include/clockdrv.h,
+ libcsupport/include/console.h,
+ libcsupport/include/iosupp.h,
+ libcsupport/include/ringbuf.h,
+ libcsupport/include/rtc.h,
+ libcsupport/include/spurious.h,
+ libcsupport/include/timerdrv.h,
+ libcsupport/include/vmeintr.h,
+ libcsupport/include/motorola/mc68230.h,
+ libcsupport/include/motorola/mc68681.h,
+ libcsupport/include/rtems/assoc.h,
+ libcsupport/include/rtems/cdefs.h,
+ libcsupport/include/rtems/error.h,
+ libcsupport/include/rtems/libcsupport.h,
+ libcsupport/include/rtems/libio.h,
+ libcsupport/include/rtems/libio_.h,
+ libcsupport/include/rtems/termiostypes.h,
+ libcsupport/include/zilog/z8036.h,
+ libcsupport/include/zilog/z8530.h,
+ libcsupport/include/zilog/z8536.h: Add doxygen preamble.
+
+2004-11-29 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/mallocfreespace.c, rtems/Makefile.am,
+ rtems/include/rtems/rtems/region.h, score/Makefile.am,
+ score/include/rtems/score/heap.h, score/src/heapgetinfo.c: Add
+ capability to return information about just the free blocks in a
+ region or heap. Also changed the semantics of free space available
+ to be the largest block of memory that can be allocated.
+ * rtems/src/regiongetfreeinfo.c, score/src/heapgetfreeinfo.c: New files.
+ : score/include/rtems/score/object.h,
+ score/src/objectinitializeinformation.c: Remove warning.
+
+2004-11-22 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/score/object.h, score/src/objectclearname.c,
+ score/src/objectcopynamestring.c: Fixing warning led to making
+ changes to multiple prototypes for object support routines.
+
+2004-11-22 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/ttyname_r.c: Remove warning for using _fstat.
+
+2004-11-22 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * aclocal/enable-itron.m4, aclocal/check-itron.m4:
+ Allow building itron for unix.
+
+2004-11-22 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Don't install bpfilter.h (Private
+ header).
+
+2004-11-22 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libblock/include/rtems/bdbuf.h,
+ libblock/include/rtems/blkdev.h,
+ libblock/include/rtems/diskdevs.h,
+ libblock/include/rtems/ide_part_table.h,
+ libblock/include/rtems/ramdisk.h:
+ Add doxygen preamble.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/extension.h, sapi/include/rtems/fatal.h,
+ sapi/include/rtems/init.h, sapi/include/rtems/io.h,
+ sapi/include/rtems/sptables.h, sapi/inline/rtems/extension.inl,
+ sapi/macros/rtems/extension.inl: Add doxygen preamble.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * score/include/rtems/debug.h, score/include/rtems/seterr.h,
+ score/include/rtems/system.h, score/include/rtems/score/address.h,
+ score/include/rtems/score/apiext.h,
+ score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/copyrt.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h,
+ score/include/rtems/score/interr.h, score/include/rtems/score/isr.h,
+ score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/heap.inl, score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/objectmp.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/threadmp.inl,
+ score/inline/rtems/score/tod.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/userext.inl,
+ score/inline/rtems/score/watchdog.inl,
+ score/inline/rtems/score/wkspace.inl,
+ score/macros/rtems/score/object.inl: Adjust doxygen @file.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * posix/include/aio.h, posix/include/devctl.h, posix/include/intr.h,
+ posix/include/mqueue.h, posix/include/sched.h,
+ posix/include/semaphore.h, posix/include/rtems/posix/cancel.h,
+ posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/condmp.h,
+ posix/include/rtems/posix/config.h,
+ posix/include/rtems/posix/intr.h, posix/include/rtems/posix/key.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mqueuemp.h,
+ posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/mutexmp.h,
+ posix/include/rtems/posix/posixapi.h,
+ posix/include/rtems/posix/priority.h,
+ posix/include/rtems/posix/psignal.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/pthreadmp.h,
+ posix/include/rtems/posix/ptimer.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/semaphoremp.h,
+ posix/include/rtems/posix/threadsup.h,
+ posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h,
+ posix/inline/rtems/posix/cond.inl,
+ posix/inline/rtems/posix/intr.inl, posix/inline/rtems/posix/key.inl,
+ posix/inline/rtems/posix/mqueue.inl,
+ posix/inline/rtems/posix/mutex.inl,
+ posix/inline/rtems/posix/priority.inl,
+ posix/inline/rtems/posix/pthread.inl,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/inline/rtems/posix/timer.inl,
+ posix/macros/rtems/posix/cond.inl,
+ posix/macros/rtems/posix/intr.inl, posix/macros/rtems/posix/key.inl,
+ posix/macros/rtems/posix/mqueue.inl,
+ posix/macros/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/priority.inl,
+ posix/macros/rtems/posix/pthread.inl,
+ posix/macros/rtems/posix/semaphore.inl,
+ posix/macros/rtems/posix/timer.inl: Add doxygen preamble.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * itron/include/itron.h, itron/include/itronsys/eventflags.h,
+ itron/include/itronsys/fmempool.h, itron/include/itronsys/intr.h,
+ itron/include/itronsys/mbox.h, itron/include/itronsys/msgbuffer.h,
+ itron/include/itronsys/network.h, itron/include/itronsys/port.h,
+ itron/include/itronsys/semaphore.h, itron/include/itronsys/status.h,
+ itron/include/itronsys/sysmgmt.h, itron/include/itronsys/task.h,
+ itron/include/itronsys/time.h, itron/include/itronsys/types.h,
+ itron/include/itronsys/vmempool.h,
+ itron/include/rtems/itron/config.h,
+ itron/include/rtems/itron/eventflags.h,
+ itron/include/rtems/itron/fmempool.h,
+ itron/include/rtems/itron/intr.h,
+ itron/include/rtems/itron/itronapi.h,
+ itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/network.h,
+ itron/include/rtems/itron/object.h,
+ itron/include/rtems/itron/port.h,
+ itron/include/rtems/itron/semaphore.h,
+ itron/include/rtems/itron/sysmgmt.h,
+ itron/include/rtems/itron/task.h, itron/include/rtems/itron/time.h,
+ itron/include/rtems/itron/vmempool.h,
+ itron/inline/rtems/itron/eventflags.inl,
+ itron/inline/rtems/itron/fmempool.inl,
+ itron/inline/rtems/itron/intr.inl,
+ itron/inline/rtems/itron/mbox.inl,
+ itron/inline/rtems/itron/msgbuffer.inl,
+ itron/inline/rtems/itron/network.inl,
+ itron/inline/rtems/itron/port.inl,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/inline/rtems/itron/sysmgmt.inl,
+ itron/inline/rtems/itron/task.inl,
+ itron/inline/rtems/itron/time.inl,
+ itron/inline/rtems/itron/vmempool.inl,
+ itron/macros/rtems/itron/eventflags.inl,
+ itron/macros/rtems/itron/fmempool.inl,
+ itron/macros/rtems/itron/intr.inl,
+ itron/macros/rtems/itron/mbox.inl,
+ itron/macros/rtems/itron/msgbuffer.inl,
+ itron/macros/rtems/itron/network.inl,
+ itron/macros/rtems/itron/port.inl,
+ itron/macros/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/sysmgmt.inl,
+ itron/macros/rtems/itron/task.inl,
+ itron/macros/rtems/itron/time.inl,
+ itron/macros/rtems/itron/vmempool.inl: Add doxygen preamble.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/types.h: Include <rtems/stdint.h>.
+ * librpc/src/rpc/clnt_raw.c, librpc/src/rpc/rpcdname.c,
+ librpc/src/rpc/rtems_portmapper.c, librpc/src/rpc/svc.c,
+ librpc/src/rpc/svc_simple.c: Misc. cast-related fixes.
+ Convert to ANSI.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * librpc/include/rpc/rpc.h (struct _rtems_rpc_task_variables):
+ Use pointers to types instead of void* to avoid casts.
+ * librpc/src/rpc/clnt_perror.c, librpc/src/rpc/clnt_raw.c,
+ librpc/src/rpc/clnt_simple.c, librpc/src/rpc/rpcdname.c,
+ librpc/src/rpc/svc.c, librpc/src/rpc/svc_auth.c,
+ librpc/src/rpc/svc_simple.c:
+ Eliminate lvalue casts gcc-3.4 warns about.
+
+2004-11-20 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libfs/src/dosfs/dosfs.h: Add doxygen preamble.
+ * libfs/src/dosfs/msdos.h: Remove RC_OK.
+ * libfs/src/dosfs/msdos_format.c: Remove unnecessary casts.
+
+2004-11-20 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 720/filesystem:
+ * libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos_format.c:
+ Adaptations to msdos_format.
+ (From Thomas Doerfler <Thomas.Doerfler@imd-systems.de>).
+
+ * libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos_format.c:
+ Adaptations to RTEMS-4.7.
+
+2004-11-20 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 720/filesystem:
+ * libfs/src/dosfs/msdos_format.c: New
+ (From Thomas Doerfler <Thomas.Doerfler@imd-systems.de>).
+ * libfs/Makefile.am: Reflect changes above:
+
+2004-11-20 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * libcsupport/include/stdint.h: Move mal-placed comment.
+
+2004-11-10 Joel Sherrill <joel@oarcorp.com>
+
+ * include/rtems/pci.h: BSPs use the name BSP_pci_configuration not pci.
+ Also need to address that this largely duplicates
+ libbsp/powerpc/pci/pci.h but that file is not used when both are
+ included due to the same double inclusion protection.
+
+2004-11-09 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/include/stdint.h: Fixed name in @file.
+
+2004-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/sys/_stdint.h: Remove.
+ * libcsupport/include/sys/_inttypes.h: Remove.
+ * libcsupport/include/stdint.h: Replace with former sys/_stdint.h.
+ Add INT<N>_C, various additions.
+ * libcsupport/include/inttypes.h: Replace with former
+ sys/_inttypes.h.
+ * libcsupport/Makefile.am: Reflect changes above.
+
+2004-11-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * backward/asm.h: Add doxygen preamble.
+ * backward/chain.h: Add doxygen preamble.
+ * backward/clockdrv.h: Add doxygen preamble.
+ * backward/confdefs.h: Add doxygen preamble.
+ * backward/console.h: Add doxygen preamble.
+ * backward/dosfs.h: Add doxygen preamble.
+ * backward/imfs.h: Add doxygen preamble.
+ * backward/iosupp.h: Add doxygen preamble.
+ * backward/itron.h: Add doxygen preamble.
+ * backward/ringbuf.h: Add doxygen preamble.
+ * backward/rtc.h: Add doxygen preamble.
+ * backward/spurious.h: Add doxygen preamble.
+ * backward/timerdrv.h: Add doxygen preamble.
+ * backward/vmeintr.h: Add doxygen preamble.
+ * backward/motorola/mc68230.h: Add doxygen preamble.
+ * backward/motorola/mc68681.h: Add doxygen preamble.
+ * backward/zilog/z8030.h: Add doxygen preamble.
+ * backward/zilog/z8036.h: Add doxygen preamble.
+ * backward/zilog/z8536.h: Add doxygen preamble.
+
+2004-11-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * libcsupport/include/sys/_stdint.h: Special-case int64_t (GCC has
+ __LONG_LONG_MAX__, while POSIX mandates LLONG_MAX. This break
+ __EXP(LONG_LONG_MAX)).
+
+2004-11-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/machine/endian.h: Protect BYTE_ORDER from double
+ definition.
+
+2004-11-05 Ralf Corsepius <ralf_corsepiu@rtems.org>
+
+ * configure.ac: Remove RTEMS_USES_INTTYPES_H. Require inttypes.h.
+ * include/rtems/stdint.h: Remove "wild guesses", require inttypes.h.
+ * libcsupport/include/inttypes.h: Cleanup.
+ * libcsupport/include/stdint.h: Cleanup.
+
+2004-11-04 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * include/sys/_stdint.h: Various changes.
+ Add *leastN_t types. Add INTN_{MIN|MAX} macros.
+ Add doxygen preamble.
+ * include/sys/_inttypes.h: Add doxygen preamble.
+ Reflect changes above.
+ * libcsupport/include/stdint.h: Add doxygen preamble.
+ * libcsupport/include/inttypes.h: Add doxygen preamble.
+ * configure.ac: Add doxygen preamble to cpuopts.h.
+
+2004-11-02 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/mqueueunlink.c, posix/src/semunlink.c,
+ score/inline/rtems/score/object.inl,
+ score/macros/rtems/score/object.inl: _Objects_Is_local_id() should be
+ avoided in single CPU configurations but always available in the
+ Objects Handlers API.
+
+2004-11-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/include/rtems.h,
+ rtems/inline/rtems/rtems/asr.inl,
+ rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/dpmem.inl,
+ rtems/inline/rtems/rtems/event.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/tasks.inl,
+ rtems/inline/rtems/rtems/timer.inl,
+ rtems/macros/rtems/rtems/asr.inl,
+ rtems/macros/rtems/rtems/attr.inl,
+ rtems/macros/rtems/rtems/dpmem.inl,
+ rtems/macros/rtems/rtems/event.inl,
+ rtems/macros/rtems/rtems/eventset.inl,
+ rtems/macros/rtems/rtems/message.inl,
+ rtems/macros/rtems/rtems/modes.inl,
+ rtems/macros/rtems/rtems/options.inl,
+ rtems/macros/rtems/rtems/part.inl,
+ rtems/macros/rtems/rtems/ratemon.inl,
+ rtems/macros/rtems/rtems/region.inl,
+ rtems/macros/rtems/rtems/sem.inl,
+ rtems/macros/rtems/rtems/status.inl,
+ rtems/macros/rtems/rtems/support.inl,
+ rtems/macros/rtems/rtems/tasks.inl,
+ rtems/macros/rtems/rtems/timer.inl: Add doxygen preamble.
+
+2004-11-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/include/rtems.h,
+ rtems/include/rtems/rtems/asr.h,
+ rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/cache.h,
+ rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/dpmem.h,
+ rtems/include/rtems/rtems/event.h,
+ rtems/include/rtems/rtems/eventmp.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/modes.h,
+ rtems/include/rtems/rtems/mp.h,
+ rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/options.h,
+ rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/partmp.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/rtemsapi.h,
+ rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/semmp.h,
+ rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/status.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h,
+ rtems/include/rtems/rtems/tasks.h,
+ rtems/include/rtems/rtems/timer.h,
+ rtems/include/rtems/rtems/types.h: Add doxygen preamble.
+
+2004-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/monitor/mon-manager.c, libmisc/monitor/mon-object.c: Remove
+ references to _Object_Is_local in single processor configurations.
+
+2004-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/coresemsurrender.c, score/src/objectnametoid.c: All
+ _Objects_Is_Local... should only be called if multiprocessing is
+ enabled.
+
+2004-11-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/tasks.h, rtems/src/taskstart.c:
+ rtems_task_start(..., rtems_task_argument argument );
+
+2004-11-01 Joel Sherrill <joel@oarcorp.com>
+
+ * score/cpu/no_cpu/rtems/score/cpu.h, score/include/rtems/debug.h,
+ score/include/rtems/seterr.h, score/include/rtems/system.h,
+ score/include/rtems/score/address.h,
+ score/include/rtems/score/apiext.h,
+ score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/context.h,
+ score/include/rtems/score/copyrt.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h, score/include/rtems/score/interr.h,
+ score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h,
+ score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h, score/include/rtems/score/tod.h,
+ score/include/rtems/score/tqdata.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/heap.inl, score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/objectmp.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/threadmp.inl,
+ score/inline/rtems/score/tod.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/userext.inl,
+ score/inline/rtems/score/watchdog.inl,
+ score/inline/rtems/score/wkspace.inl: Add Doxygen comments -- working
+ modifications which are not complete and may have broken code.
+ Committing so work and testing can proceed.
+ * score/Doxyfile, score/mainpage.h: New files.
+
+2004-11-01 Joel Sherrill <joel@oarcorp.com>
+
+ * score/include/rtems/score/object.h,
+ score/inline/rtems/score/object.inl,
+ score/macros/rtems/score/object.inl: Add first cut of optional
+ 16 bit object Id as space reduction for small systems (TinyRTEMS).
+
+2004-11-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * monitor/monitor.h: Let rtems_monitor_config_dump return int.
+ * monitor/mon-config.c: Ditto. Use PRI*N macros.
+ * monitor/mon-itask.c, monitor/mon-prmisc.c: Use PRI*N macros.
+
+2004-11-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/monitor/monitor.h: Let rtems_monitor_config_dump return int.
+ * libmisc/monitor/mon-config.c: Ditto. Use PRI*N macros.
+ * libmisc/monitor/mon-itask.c, libmisc/monitor/mon-prmisc.c: Use
+ PRI*N macros.
+
+2004-11-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove -ansi (Cygwin breaks with it).
+ * libcsupport/include/stdint.h: Use sys/_stdint.h to setup fixed
+ size types.
+ * libcsupport/include/sys/_inttypes.h: Add SCN*N macros.
+
+2004-11-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/src/utsname.c: Revert yesterdays patch.
+
+2004-10-31 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/utsname.c: Fix typo.
+
+2004-10-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * score/src/coremsg.c: Eliminate unsigned32.
+ * score/include/rtems/system.h: Set __RTEMS_REVISION__ to 99.
+ * librpc/include/rpc/xdr.h: Use elipsis in xdrproc_t prototype.
+
+2004-10-28 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/inttypes.h: #include <sys/_inttypes.h>
+ * libcsupport/src/utsname.c: Don't include sptables.h.
+ Include <inttypes.h>. Use PRId32 instead of "%d".
+
+2004-10-28 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/rtems/_inttypes.h: Remove.
+ * libcsupport/include/rtems/_stdint.h: Remove.
+ * libcsupport/include/sys/_inttypes.h: New.
+ * libcsupport/include/sys/_stdint.h: New.
+ * libcsupport/Makefile.am: Reflect changes above.
+ * configure.ac: Reflect changes above.
+
+2004-10-28 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove RTEMS_CPUOPT([RTEMS_MULTILIBS],..).
+ (Unused).
+
+2004-10-27 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/monitor/mon-prmisc.c, libmisc/monitor/monitor.h: Let rtems_monitor_dump
+ return int's not uint32_t (They are printf return values).
+
+2004-10-27 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Add score/cpu/no_cpu/Makefile.
+
+2004-10-27 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am, configure.ac: Add httpd.
+ * httpd/asp.c, httpd/balloc.c, httpd/cgi.c, httpd/default.c,
+ httpd/ej.h, httpd/ejIntrn.h, httpd/ejlex.c, httpd/ejparse.c,
+ httpd/emfdb.c, httpd/emfdb.h, httpd/form.c, httpd/handler.c,
+ httpd/h.c, httpd/license.txt, httpd/Makefile.am, httpd/md5c.c,
+ httpd/md5.h, httpd/mime.c, httpd/misc.c, httpd/NOTES, httpd/ringq.c,
+ httpd/rom.c, httpd/rtems_webserver.h, httpd/security.c,
+ httpd/sock.c, httpd/socket.c, httpd/sockGen.c, httpd/sym.c,
+ httpd/uemf.c, httpd/uemf.h, httpd/um.c, httpd/um.h, httpd/umui.c,
+ httpd/url.c, httpd/value.c, httpd/wbase64.c, httpd/webcomp.c,
+ httpd/webmain.c, httpd/webpage.c, httpd/webrom.c, httpd/webs.c,
+ httpd/websda.c, httpd/websda.h, httpd/webs.h, httpd/websSSL.c,
+ httpd/websSSL.h, httpd/websuemf.c, httpd/wsIntrn.h: New (Moved from
+ c/src/libnetworking/rtems_webserver).
+ * httpd/Makefile.am: Install libhttpd.a.
+
+2004-10-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/rtems/_inttypes.h: Undefine __PRIN defines.
+ * libcsupport/include/rtems/_stdint.h: Apply GNUC-limits to GCC >= 3.3, only.
+ Add _rtems_*_t_defined defines. Add extern "C".
+
+2004-10-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/rtems/_stdint.h: New.
+ * libcsupport/include/rtems/_inttypes.h: New.
+ * libcsupport/Makefile.am: Reflect changes above.
+
+2004-10-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libfs/src/dosfs/msdos_conv.c:
+ Replace BSD fixed-size types with POSIX fixed-size types.
+ Replace SECONDSTO1980 with DAYSTO1980.
+ Make macros 16bit clean.
+
+2004-10-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/sys/ioccom.h: Cosmetical update from FreeBSD.
+ * libcsupport/include/sys/ioctl.h: Cosmetical update from FreeBSD.
+ Remove sys/compat_ioctl.h section (Meaningless with RTEMS).
+
+2004-10-25 Eric Norum <norume@aps.anl.gov>
+
+ * libnetworking/net/if_ethersubr.c: Working version of ether_sprintf().
+ * cpukit/librpc/include/rpc/xdr.h: No kernel/user distinction.
+
+2004-10-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Reflect changes below.
+ * libnetworking/net/slcompress.h: New (from FreeBSD).
+ * libnetworking/net/slcompress.c: New (from FreeBSD).
+
+2004-10-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/stdint.h: Add intptr_t uintptr_t.
+ * libnetworking/kern/kern_sysctl.c: Remove uintptr_t.
+ Cosmetics.
+ * libnetworking/opt_compat.h: New.
+
+2004-10-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/opt_atalk.h, libnetworking/opt_bdg.h,
+ libnetworking/opt_inet.h, libnetworking/opt_inet6.h,
+ libnetworking/opt_ipx.h, libnetworking/opt_mac.h,
+ libnetworking/opt_netgraph.h: New (Stubs).
+ * libnetworking/net/if_loop.c: Cosmetical update from FreeBSD.
+ * libnetworking/net/if_ethersubr.c: Update from FreeBSD.
+ * libnetworking/net/if.h: Update from FreeBSD.
+
+2004-10-21 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/net/ethernet.h: Remove BYTE_PACK.
+
+2004-10-21 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/net/if.h; Cosmetical updates from FreeBSD.
+ Remove if_poll* (Not implemented in RTEMS, abandoned by FreeBSD).
+ * libnetworking/net/if_ethersubr.c: Cosmetical updates from FreeBSD.
+ Add ether_sprintf.
+ * libnetworking/net/ethernet.h: Update from FreeBSD.
+
+2004-10-21 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/monitor/mon-prmisc.c, libmisc/monitor/monitor.h:
+ rtems_monitor_dump_char(char ch).
+
+2004-10-20 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * automake/compile.am: Remove RTEMS_CFLAGS_*_V.
+
+2004-10-15 Joel Sherrill <joel@OARcorp.com>
+
+ PR 692/rtems
+ * rtems/src/regiongetsegment.c, rtems/src/regionreturnsegment.c: The
+ Region Manager did not follow the proper protocol when blocking and
+ unblocking tasks waiting on buffers. This was a bug introduced with
+ the transition to an Allocation Mutex.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.ac, libmisc/cpuuse/README, libmisc/stackchk/README,
+ librpc/src/xdr/xdr_float.c, score/cpu/Makefile.am,
+ score/include/rtems/score/mppkt.h: i960 obsoleted and all references
+ removed.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * score/cpu/i960/.cvsignore, score/cpu/i960/ChangeLog,
+ score/cpu/i960/Makefile.am, score/cpu/i960/asm.h,
+ score/cpu/i960/cpu.c, score/cpu/i960/cpu_asm.S,
+ score/cpu/i960/rtems/score/cpu.h, score/cpu/i960/rtems/score/i960.h,
+ score/cpu/i960/rtems/score/types.h: Removed.
+
+2004-09-27 Joel Sherrill <joel@OARcorp.com>
+
+ PR 294/rtems
+ * posix/src/pthread.c: POSIX thread exit handler now confirms that it
+ created the executing thread before implicitly exitting it.
+
+2004-09-27 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/stackchk/check.c: Spacing.
+
+2004-09-24 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Require automake > 1.9.
+
+2004-09-24 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Add score/cpu/avr/Makefile.am.
+ * score/cpu/Makefile.am: Add avr.
+ * libnetworking/Makefile.am: Don't include subdirs.am.
+
+2004-09-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * librpc/src/xdr/xdr_float.c: Add __AVR__.
+
+2004-09-21 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * aclocal/gcc-weak.m4: New (Extracted from cpukit/configure.ac).
+ * configure.ac: Add RTEMS_CHECK_GCC_WEAK.
+
+2004-09-17 Joel Sherrill <joel@OARcorp.com>
+
+ PR 677/misc
+ * libmisc/dumpbuf/dumpbuf.h, libmisc/fsmount/fsmount.h,
+ libmisc/rtmonuse/rtmonuse.h, libmisc/serdbg/serdbg.h,
+ libmisc/serdbg/serdbgcnf.h, libmisc/serdbg/termios_printk.h,
+ libmisc/serdbg/termios_printk_cnf.h, libmisc/untar/untar.h: Add
+ extern C wrappers.
+
+2004-09-17 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 676/networking
+ * libnetworking/nfs/bootp_subr.c: /etc/resolv.conf contains NTP instead
+ of DNS servers.
+
+2004-08-18 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ PR 673/make_build
+ * aclocal/rtems-top.m4 (RTEMS_TOP): Add further quotes.
+
+2004-07-28 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-4.6.99.1.
+
+2004-07-25 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 620/networking
+ * libnetworking/lib/rtems_bsdnet_ntp.c,
+ libnetworking/rtems/rtems_bsdnet.h: Enhance NTP API.
+
+2004-07-25 Thomas Rauscher <trauscher@loytec.com>
+
+ PR 609/rtems
+ * score/src/threaddispatch.c: Close race condition between
+ _Thread_Dispatch and _Thread_Tickle_timeslice.
+
+2004-07-25 Victor Vengerov <Victor.Vengerov@oktetlabs.ru>
+
+ PR 654/rtems
+ * score/src/threadinitialize.c: Initialize the per thread watchdog
+ timer. When the thread control block is reused, we cannot depend on
+ it being zeroed.
+
+2004-07-24 Mick Davis <mickd@microsol.iinet.net.au>
+
+ PR 641/rtems
+ * rtems/src/eventsurrender.c: The problem here is that events may be
+ lost when sent to a task which enters rtems_event_receive() with options
+ set to wait with a timeout and to return on receipt of any event. The
+ events are sent from an interrupt source such as a timer service
+ routine. If more than one set of events is sent to the task before it
+ returns, the first event set may be overwritten.
+
+2004-07-24 Joel Sherrill <joel@OARcorp.com>
+
+ PR 661/rtems
+ * score/src/objectmp.c: Fix invalid dereference.
+
+2004-07-24 Joel Sherrill <joel@OARcorp.com>
+
+ PR 660/rtems
+ * score/cpu/m68k/rtems/score/m68k.h, score/cpu/mips/cpu_asm.S,
+ score/src/threadinitialize.c, score/src/threadstackallocate.c: Check
+ for overflow when allocating stack.
+
+2004-07-24 Joel Sherrill <joel@OARcorp.com>
+
+ PR 659/rtems
+ * score/src/heapsizeofuserarea.c: Check that address specified is in
+ the heap.
+
+2004-07-24 Joel Sherrill <joel@OARcorp.com>
+
+ PR 652/rtems
+ * rtems/src/signalsend.c: Return RTEMS_INVALID_NUMBER when sending an
+ empty signal set.
+
+2004-07-14 Joel Sherrill <joel@OARcorp.com>
+
+ PR 650/rtems
+ * score/src/coremsg.c: Check for mathemathical overflow when calculating
+ amount of memory to allocate for message buffers.
+
+2004-07-14 Joel Sherrill <joel@OARcorp.com>
+
+ PR 651/core
+ * rtems/src/taskident.c: Add NULL check for id.
+
+2004-06-29 Joel Sherrill <joel@OARcorp.com>
+
+ PR 631/rtems
+ * rtems/src/msgqcreate.c: Return unsatisfied from message_queue_create
+ when unable to allocate message buffer memory.
+
+2004-05-21 Joel Sherrill <joel@OARcorp.com>
+
+ PR 628/rtems
+ * posix/src/killinfo.c, posix/src/pthreadkill.c, posix/src/ptimer1.c,
+ posix/src/sigaction.c, posix/src/sigaddset.c, posix/src/sigsuspend.c:
+ Signal set of 0 is supposed to return EINVAL. In addition
+ timer_create needed to return an error if the clock was not
+ CLOCK_REALTIME.
+
+2004-05-21 Joel Sherrill <joel@OARcorp.com>
+
+ PR 629/rtems
+ * cpukit/src/mqueuecreatesupp.c: Return EINVAL is mq_maxmsg is
+ <= 0, not <.
+
+2004-05-21 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 626/networking
+ * libnetworking/rtems/rtems_showifstat.c: Use unsigned char to avoid
+ printing leading FFFFFF for byte values > 127.
+
+2004-05-06 Joel Sherrill <joel@OARcorp.com>
+
+ PR 618/rtems
+ * rtems/include/rtems/rtems/status.h, rtems/src/clockget.c,
+ rtems/src/clockset.c, rtems/src/dpmemcreate.c,
+ rtems/src/dpmemexternal2internal.c,
+ rtems/src/dpmeminternal2external.c, rtems/src/eventmp.c,
+ rtems/src/eventreceive.c, rtems/src/eventsend.c,
+ rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c,
+ rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c,
+ rtems/src/msgqreceive.c, rtems/src/msgqsubmit.c,
+ rtems/src/partcreate.c, rtems/src/partdelete.c,
+ rtems/src/partgetbuffer.c, rtems/src/ratemoncancel.c,
+ rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c,
+ rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c,
+ rtems/src/ratemonperiod.c, rtems/src/regioncreate.c,
+ rtems/src/regiondelete.c, rtems/src/regionextend.c,
+ rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c,
+ rtems/src/regionreturnsegment.c, rtems/src/semcreate.c,
+ rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semident.c,
+ rtems/src/taskcreate.c, rtems/src/taskgetnote.c,
+ rtems/src/taskmode.c, rtems/src/taskrestart.c,
+ rtems/src/taskresume.c, rtems/src/tasksetnote.c,
+ rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c,
+ rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c,
+ rtems/src/taskwakewhen.c, rtems/src/timercreate.c,
+ rtems/src/timerdelete.c, rtems/src/timerfireafter.c,
+ rtems/src/timerfirewhen.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c, score/include/rtems/score/object.h,
+ score/src/coretodvalidate.c, score/src/objectnametoid.c: Add NULL
+ checks.
+
+2004-04-30 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/kern/kern_sysctl.c: sysctl_register_all cannot be
+ static with RTEMS.
+
+2004-04-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/netinet/in.c: Partial update from FreeBSD.
+
+2004-04-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/kern/kern_sysctl.c: Partial updates from FreeBSD.
+
+2004-04-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/netinet/igmp_var.h: Cosmetic updates from FreeBSD.
+ * libnetworking/sys/sysctl.h: Update from FreeBSD.
+ * libnetworking/sys/socketvar.h: Update from FreeBSD.
+
+2004-04-24 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/sys/protosw.h: More partial updates from FreeBSD.
+
+2004-04-24 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/net/route.c: Reflect changes to radix.h.
+
+2004-04-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/net/radix.h, libnetworking/net/radix.c: Partial
+ update from FreeBSD.
+
+2004-04-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/sys/socket.h: Further update from FreeBSD
+ (Add sa_family_t).
+
+2004-04-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/sys/protosw.h: Partial update from FreeBSD.
+ * libnetworking/sys/socket.h: Partial update from FreeBSD.
+ * libnetworking/rtems/rtems_syscall.c: Reflect changes to socket.h.
+
+2004-04-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/kern/uipc_socket.c: Partial update from FreeBSD
+ (Remove adv-clause from copyright notice).
+ * libnetworking/netinet/igmp_var.h: Partial update from FreeBSD.
+
+2004-04-20 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/net/bpf.h, libnetworking/net/if.h,
+ libnetworking/net/if_dl.h, libnetworking/net/if_ppp.h,
+ libnetworking/net/netisr.h, libnetworking/net/pppcompress.c,
+ libnetworking/net/radix.c, libnetworking/net/radix.h,
+ libnetworking/net/raw_cb.h, libnetworking/net/route.h,
+ libnetworking/netinet/icmp_var.h, libnetworking/netinet/if_ether.h,
+ libnetworking/netinet/igmp_var.h, libnetworking/netinet/in.h,
+ libnetworking/netinet/in_pcb.h, libnetworking/netinet/in_systm.h,
+ libnetworking/netinet/in_var.h, libnetworking/netinet/ip_fw.h,
+ libnetworking/netinet/ip_icmp.h, libnetworking/netinet/ip_mroute.h,
+ libnetworking/netinet/ip_var.h, libnetworking/netinet/tcp_debug.h,
+ libnetworking/netinet/tcp_seq.h, libnetworking/netinet/tcp_timer.h,
+ libnetworking/netinet/tcp_var.h, libnetworking/netinet/udp_var.h,
+ libnetworking/nfs/nfs.h, libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/sys/buf.h, libnetworking/sys/callout.h,
+ libnetworking/sys/conf.h, libnetworking/sys/domain.h,
+ libnetworking/sys/malloc.h, libnetworking/sys/mbuf.h,
+ libnetworking/sys/mount.h, libnetworking/sys/protosw.h,
+ libnetworking/sys/queue.h, libnetworking/sys/rtprio.h,
+ libnetworking/sys/select.h, libnetworking/sys/signalvar.h,
+ libnetworking/sys/socket.h, libnetworking/sys/socketvar.h,
+ libnetworking/sys/sysctl.h, libnetworking/sys/syslog.h,
+ libnetworking/sys/ucred.h, libnetworking/sys/uio.h,
+ libnetworking/vm/vm.h, libnetworking/vm/vm_extern.h,
+ libnetworking/vm/vm_param.h: Use -D_KERNEL instead of -DKERNEL for
+ greater FreeBSD compliance.
+
+2004-04-20 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Add -D_KERNEL to CPPFLAGS.
+
+2004-04-20 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/net/bpf.h: Partial update from FreeBSD.
+
+2004-04-19 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/sys/sysctl.h: Partial update from FreeBSD.
+ * libnetworking/kern/kern_sysctl.c: Partial update from FreeBSD.
+
+2004-04-17 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libfs/src/imfs/imfs_debug.c, libfs/src/imfs/memfile.c:
+ Use fprintf(stdout,...) instead of printf.
+
+2004-04-17 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libblock/src/ide_part_table.c: Use fprintf(stdout,...) instead of
+ printf.
+
+2004-04-17 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/capture/capture-cli.c, libmisc/cpuuse/cpuuse.c,
+ libmisc/dumpbuf/dumpbuf.c, libmisc/fsmount/fsmount.c,
+ libmisc/monitor/mon-command.c, libmisc/monitor/mon-config.c,
+ libmisc/monitor/mon-dname.c, libmisc/monitor/mon-driver.c,
+ libmisc/monitor/mon-extension.c, libmisc/monitor/mon-itask.c,
+ libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-mpci.c,
+ libmisc/monitor/mon-object.c, libmisc/monitor/mon-prmisc.c,
+ libmisc/monitor/mon-queue.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/mon-task.c, libmisc/rtmonuse/rtmonuse.c,
+ libmisc/shell/cmds.c, libmisc/shell/shell.c, libmisc/shell/shell.h,
+ libmisc/stackchk/check.c, libmisc/untar/untar.c: Use
+ fprintf(stdout,...) instead of printf.
+
+2004-04-14 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * sapi/include/rtems/sptables.h: Remove _RTEMS_version.
+
+2004-04-14 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/Makefile.am: Install include_sys_HEADERS for NEWLIB
+ only. Merge sys/cdefs.h into general include_sys_HEADERS.
+
+2004-04-13 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/types.h: Include <rtems/stdint.h>
+ instead of <stdint.h>.
+ Conditionally typedef rtems*signed64 types.
+ * score/include/rtems/system.h: Include <rtems/stdint.h> instead of
+ <stdint.h>.
+
+2004-04-13 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Rework stdint.h/inttypes.h support.
+ Add RTEMS_USES_STDINT_H. Add RTEMS_USES_INTTYPES_H.
+ Remove NEED_STDINT_H. Remove NEED_INTTYPES_H.
+ Remove termios-flag detection.
+ * libcsupport/Makefile.am: Install include/stdint.h and
+ include/inttypes.h for NEWLIB only.
+ * libcsupport/include/stdint.h: Rework; Now newlib specific.
+ * libcsupport/src/termios.c: Make newlib specific.
+ * include/rtems/stdint.h: Rework; Now wrapper to <stdint.h>.
+
+2004-04-12 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * acinclude.m4 (RTEMS_CPUOPT): Use AC_DEFINE_UNQUOTED.
+ * backward/motorola/mc68681.h, backward/motorola/mc68230.h,
+ backward/zilog/z8536.h, backward/zilog/z8036.h,
+ backward/zilog/z8030.h: New.
+ * Makefile.am: Reflect having added new files above.
+
+2004-04-09 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * wrapup/Makefile.am: Add libblock for !UNIX only.
+
+2004-04-09 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libblock/Makefile.am: Build libblock for !UNIX only.
+ * libcsupport/Makefile.am: Build $(TERMIOS_C_FILES) for !UNIX only.
+
+2004-04-09 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libblock/Makefile.am: Remove LIBC_DEFINES (Unsupported).
+ * libfs/Makefile.am: Remove LIBC_DEFINES (Unsupported).
+
+2004-04-08 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/Makefile.am: Install sys/ioccom.h for NEWLIB only.
+
+2004-04-08 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/Makefile.am: Remove $(LIBC_DEFINES) (Unsupported).
+ Install motorola-headers to $(includedir)/rtems/motorola.
+ Install zilog-headers to $(includedir)/rtems/zilog.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * score/cpu/Makefile.am: Add unix to DIST_SUBDIRS.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * aclocal/rtems-cpu-subdirs.m4: Remove (Unused).
+ * configure.ac: Remove RTEMS_CPU_SUBDIRS([score/cpu]).
+ Add RTEMS_CHECK_SYSV_UNIX.
+ Add score/cpu/*/Makefile.
+ * score/cpu/Makefile.am: Add DIST_SUBDIRS.
+
+2004-04-05 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Add AC_CHECK_SIZEOF([CPU_CONTEXT]..).
+ Add SIZEOF_CPU_CONTEXT to cpuopts.h.
+ Add RTEMS_PROG_CCAS.
+ * acinclude.m4: Use unquoted "here" document to propagate $3 to
+ cpuopts.tmp.
+
+2004-04-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: AM_CPPFLAGS += -I$(srcdir).
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Remove USHRT_MAX.
+
+2004-04-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/Makefile.am: Fix typo.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/poll.h: Replace with sys/poll.h wrapper.
+ * libnetworking/sys/poll.h: New (Original FreeBSD file).
+ * libnetworking/Makefile.am: Don't install opt_ipfw.h,
+ opt_mrouting.h, opt_tcpdebug.h. Add sys/poll.h.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/serdbg/serdbgcnf.h: Include <rtems/serdbg.h> instead of
+ <serdbg.h>
+ * libmisc/serdbg/termios_printk_cnf.h: Include <rtems/termios_printk.h>
+ instead of <termios_printk.h>.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/Makefile.am: Install serdbg.h, serdbgcnf.h,
+ termios_printk.h, termios_printk_cnf.h to $(includedir)/rtems.
+ * libmisc/serdbg/serdbg.c: Include <rtems/serdbg.h> instead of
+ <serdbg.h>.
+ * libmisc/serdbg/serdbgio.c: Include <rtems/serdbg.h> instead of
+ <serdbg.h>.
+ * libmisc/serdbg/termios_printk.c: Include <rtems/termios_printk.h>
+ instead of <termios_printk.h>.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/dummy/dummy.c: Include <rtems/confdefs.h> instead of <confdefs.h>.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * backward/confdefs.h: New.
+ * Makefile.am: Add backward/confdefs.h.
+ Add conditional DEPRECATED.
+ * configure.ac: Add --enable-deprecated.
+ Add conditional DEPRECATED.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * sapi/Makefile.am: Install confdefs.h to $(includedir)/rtems.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Add backward/*.h headers.
+ * itron/Makefile.am: Install itron.h to $(includedir)/rtems.
+ * libcsupport/Makefile.am: Install RTEMS specific headers to
+ $(includedir)/rtems.
+ * libfs/Makefile.am: Install imfs.h and dosfs.h to
+ $(includedir)/rtems.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libblock/include/rtems/bdbuf.h: Include <rtems/chain.h> instead of <chain.h>.
+ * libblock/include/rtems/ide_part_table.h: Include <rtems/chain.h> instead of <chain.h>.
+ * libcsupport/src/malloc.c: Include <rtems/chain.h> instead of <chain.h>.
+ * libcsupport/src/mount.c: Include <rtems/chain.h> instead of <chain.h>.
+ * libcsupport/src/unmount.c: Include <rtems/chain.h> instead of <chain.h>.
+ * libfs/src/imfs/imfs.h: Include <rtems/chain.h> instead of <chain.h>.
+ * libfs/src/imfs/imfs_directory.c: Include <rtems/chain.h> instead of <chain.h>.
+ * libfs/src/imfs/imfs_load_tar.c: Include <rtems/chain.h> instead of <chain.h>.
+ * sapi/include/confdefs.h: Include <rtems/clockdrv.h> instead of <clockdrv.h>.
+ * sapi/include/confdefs.h: Include <rtems/console.h> instead of <console.h>.
+ * libfs/src/imfs/imfs_load_tar.c: Include <rtems/imfs.h> instead of <imfs.h>.
+ * libmisc/shell/cmds.c: Include <rtems/imfs.h> instead of <imfs.h>.
+ * libmisc/fsmount/fsmount.c: Include <rtems/imfs.h> instead of <imfs.h>.
+ * sapi/include/confdefs.h: Include <rtems/imfs.h> instead of <imfs.h>.
+ * itron/src/can_wup.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/chg_pri.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/cre_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/cre_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/cre_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/cre_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/del_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/del_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/del_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/del_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/dis_dsp.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ena_dsp.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/eventflags.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/exd_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ext_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/fmempool.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/frsm_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/get_tid.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/itronintr.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/itronsem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/itrontime.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/mbox.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/mboxtranslatereturncode.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/msgbuffer.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/msgbuffertranslatereturncode.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/network.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/port.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/prcv_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/prcv_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/preq_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/psnd_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/rcv_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/rcv_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ref_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ref_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ref_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ref_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/rel_wai.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/rot_rdq.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/rsm_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/sig_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/slp_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/snd_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/snd_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/sta_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/sus_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/sysmgmt.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/task.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/ter_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/trcv_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/trcv_mbx.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/tslp_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/tsnd_mbf.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/twai_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/vmempool.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/wai_sem.c: Include <rtems/itron.h> instead of <itron.h>.
+ * itron/src/wup_tsk.c: Include <rtems/itron.h> instead of <itron.h>.
+ * sapi/include/rtems/config.h: Include <rtems/itron.h> instead of <itron.h>.
+ * sapi/include/confdefs.h: Include <rtems/itron.h> instead of <itron.h>.
+ * sapi/src/itronapi.c: Include <rtems/itron.h> instead of <itron.h>.
+ * sapi/include/confdefs.h: Include <rtems/rtc.h> instead of <rtc.h>.
+ * sapi/include/confdefs.h: Include <rtems/timerdrv.h> instead of <timerdrv.h>.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * backward/asm.h, backward/chain.h, backward/clockdrv.h,
+ backward/console.h, backward/dosfs.h, backward/imfs.h,
+ backward/iosupp.h, backward/itron.h, backward/ringbuf.h,
+ backward/rtc.h, backward/spurious.h, backward/timerdrv.h,
+ backward/vmeintr.h: New.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/include/rtems/rtems/region.h:
+ Include stddef.h for size_t.
+ (rtems_region_get_segment_size): Use size_t instead of uint32_t for "size" (3rd arg).
+ * rtems/src/regiongetsegmentsize.c: Reflect changes above.
+ * libcsupport/src/malloc.c: Reflect changes above.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4: Don't AC_SUBST(PROJECT_ROOT).
+ Add project_libdir, project_include and libdir.
+ * aclocal/env-rtemscpu.m4: Remove all references to RTEMS_BSP.
+ Remove project_libdir, project_include and libdir.
+ Unconditionally use CPU_CFLAGS, CFLAGS_OPTIMIZE_V, CFLAGS_DEBUG_V.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libnetworking/lib/ftpfs.c, libnetworking/lib/rtems_bsdnet_ntp.c,
+ libnetworking/lib/tftpDriver.c, libnetworking/machine/endian.h,
+ libnetworking/net/if_ppp.c, libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/rtems/rtems_glue.c,
+ libnetworking/rtems/rtems_syscall.c: Convert to using c99 fixed size
+ types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * score/include/rtems/debug.h, score/include/rtems/score/bitfield.h,
+ score/include/rtems/score/chain.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h,
+ score/include/rtems/score/heap.h,
+ score/include/rtems/score/interr.h, score/include/rtems/score/isr.h,
+ score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h,
+ score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h,
+ score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h,
+ score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coresem.inl,
+ score/inline/rtems/score/heap.inl, score/inline/rtems/score/isr.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/userext.inl,
+ score/inline/rtems/score/wkspace.inl,
+ score/macros/rtems/score/address.inl,
+ score/macros/rtems/score/heap.inl,
+ score/macros/rtems/score/object.inl,
+ score/macros/rtems/score/priority.inl,
+ score/macros/rtems/score/userext.inl: Convert to using c99 fixed
+ size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/extension.h, sapi/include/rtems/fatal.h,
+ sapi/include/rtems/init.h, sapi/include/rtems/io.h,
+ sapi/src/exinit.c, sapi/src/extension.c, sapi/src/fatal.c,
+ sapi/src/io.c: Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/include/rtems.h,
+ rtems/include/rtems/rtems/asr.h,
+ rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h,
+ rtems/include/rtems/rtems/dpmem.h,
+ rtems/include/rtems/rtems/eventset.h,
+ rtems/include/rtems/rtems/message.h,
+ rtems/include/rtems/rtems/modes.h,
+ rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/options.h,
+ rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h,
+ rtems/include/rtems/rtems/tasks.h,
+ rtems/include/rtems/rtems/timer.h,
+ rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/region.inl,
+ rtems/macros/rtems/rtems/part.inl,
+ rtems/src/attr.c,
+ rtems/src/dpmem.c,
+ rtems/src/dpmemcreate.c,
+ rtems/src/dpmemexternal2internal.c,
+ rtems/src/dpmeminternal2external.c,
+ rtems/src/eventseize.c,
+ rtems/src/msg.c,
+ rtems/src/msgmp.c,
+ rtems/src/msgqallocate.c,
+ rtems/src/msgqbroadcast.c,
+ rtems/src/msgqcreate.c,
+ rtems/src/msgqflush.c,
+ rtems/src/msgqgetnumberpending.c,
+ rtems/src/msgqident.c,
+ rtems/src/msgqreceive.c,
+ rtems/src/msgqsend.c,
+ rtems/src/msgqsubmit.c,
+ rtems/src/msgqtranslatereturncode.c,
+ rtems/src/msgqurgent.c,
+ rtems/src/part.c,
+ rtems/src/partcreate.c,
+ rtems/src/partident.c,
+ rtems/src/partmp.c,
+ rtems/src/ratemon.c,
+ rtems/src/region.c,
+ rtems/src/regioncreate.c,
+ rtems/src/regionextend.c,
+ rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c,
+ rtems/src/regionmp.c,
+ rtems/src/regionreturnsegment.c,
+ rtems/src/rtemstimer.c,
+ rtems/src/sem.c,
+ rtems/src/semcreate.c,
+ rtems/src/semident.c,
+ rtems/src/semmp.c,
+ rtems/src/semobtain.c,
+ rtems/src/semtranslatereturncode.c,
+ rtems/src/taskcreate.c,
+ rtems/src/taskgetnote.c,
+ rtems/src/taskident.c,
+ rtems/src/taskinitusers.c,
+ rtems/src/taskmp.c,
+ rtems/src/taskrestart.c,
+ rtems/src/tasks.c,
+ rtems/src/tasksetnote.c,
+ rtems/src/taskstart.c,
+ rtems/src/timerserver.c: Convert to using c99 fixed size types.
+
+2004-04-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * score/src/Unlimited.txt, score/src/chain.c, score/src/coremsg.c,
+ score/src/coremsgbroadcast.c, score/src/coremsgclose.c,
+ score/src/coremsgflush.c, score/src/coremsgflushsupp.c,
+ score/src/coremsgseize.c, score/src/coremsgsubmit.c,
+ score/src/coremutex.c, score/src/coremutexflush.c,
+ score/src/coresem.c, score/src/coresemflush.c, score/src/coretod.c,
+ score/src/coretodtickle.c, score/src/coretodtoseconds.c,
+ score/src/coretodvalidate.c, score/src/heap.c,
+ score/src/heapallocate.c, score/src/heapextend.c,
+ score/src/heapfree.c, score/src/heapsizeofuserarea.c,
+ score/src/interr.c, score/src/iterateoverthreads.c,
+ score/src/mpci.c, score/src/object.c, score/src/objectallocate.c,
+ score/src/objectallocatebyindex.c, score/src/objectclearname.c,
+ score/src/objectcomparenameraw.c,
+ score/src/objectcomparenamestring.c, score/src/objectcopynameraw.c,
+ score/src/objectcopynamestring.c,
+ score/src/objectextendinformation.c, score/src/objectfree.c,
+ score/src/objectget.c, score/src/objectgetbyindex.c,
+ score/src/objectgetisr.c, score/src/objectgetnoprotection.c,
+ score/src/objectidtoname.c, score/src/objectinitializeinformation.c,
+ score/src/objectmp.c, score/src/objectnametoid.c,
+ score/src/objectshrinkinformation.c, score/src/thread.c,
+ score/src/threadcreateidle.c, score/src/threadget.c,
+ score/src/threadidlebody.c, score/src/threadinitialize.c,
+ score/src/threadmp.c, score/src/threadq.c,
+ score/src/threadqdequeuepriority.c,
+ score/src/threadqenqueuepriority.c,
+ score/src/threadqfirstpriority.c, score/src/threadqflush.c,
+ score/src/threadreset.c, score/src/threadrestart.c,
+ score/src/threadsettransient.c, score/src/threadstackallocate.c,
+ score/src/threadstart.c, score/src/userext.c,
+ score/src/watchdoginsert.c, score/src/wkspace.c: Convert to using
+ c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ PR 561/rtems
+ * include/rtems/concat.h: New.
+ * Makefile.am: Add include/rtems/concat.h.
+
+ PR 589/rtems
+ * Makefile.am: Add include/rtems/pci.h.
+
+ * Makefile.am: Include automake/compile.am.
+ * configure.ac: RTEMS_TOP([..],[]).
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * aclocal/rtems-top.m4: Add MULTISUBDIR. Add MULTIBUILDTOP.
+ Add rtems_updir. Remove version.m4 check.
+ Add PROJECT_ROOT/with_project_root processing.
+ Add PROJECT_INCLUDE. Add PROJECT_LIB.
+ * aclocal/env-rtemscpu.a4: Remove cpukit_topdir.
+ Remove with_project_root processing. Remove PROJECT_INCLUDE,
+ PROJECT_LIB.
+
+2004-03-26 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libmisc/capture/capture-cli.c, libmisc/capture/capture.c,
+ libmisc/capture/capture.h, libmisc/cpuuse/cpuuse.c,
+ libmisc/devnull/devnull.c, libmisc/fsmount/fsmount.h,
+ libmisc/monitor/mon-config.c, libmisc/monitor/mon-dname.c,
+ libmisc/monitor/mon-driver.c, libmisc/monitor/mon-extension.c,
+ libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c,
+ libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-queue.c,
+ libmisc/monitor/mon-server.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/monitor.h, libmisc/monitor/symbols.h,
+ libmisc/mw-fb/mw_uid.c, libmisc/rtmonuse/rtmonuse.c,
+ libmisc/serdbg/serdbg.h, libmisc/serdbg/serdbgio.c,
+ libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h,
+ libmisc/shell/shell.c, libmisc/shell/shell.h, libmisc/stackchk/check.c,
+ libmisc/stackchk/internal.h: Convert to using c99 fixed size types.
+
+2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * itron/include/itronsys/mbox.h, itron/include/itronsys/types.h,
+ itron/include/rtems/itron/eventflags.h,
+ itron/include/rtems/itron/fmempool.h,
+ itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/port.h,
+ itron/include/rtems/itron/semaphore.h,
+ itron/include/rtems/itron/task.h,
+ itron/include/rtems/itron/vmempool.h,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/semaphore.inl, itron/src/eventflags.c,
+ itron/src/fmempool.c, itron/src/itronsem.c, itron/src/mbox.c,
+ itron/src/msgbuffer.c, itron/src/port.c, itron/src/snd_mbx.c,
+ itron/src/task.c, itron/src/trcv_mbx.c, itron/src/vmempool.c:
+ Convert to using c99 fixed size types.
+
+2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/intr.h, posix/include/rtems/posix/key.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/threadsup.h,
+ posix/include/rtems/posix/timer.h, posix/src/cond.c,
+ posix/src/intr.c, posix/src/key.c, posix/src/keycreate.c,
+ posix/src/keydelete.c, posix/src/keygetspecific.c,
+ posix/src/keyrundestructors.c, posix/src/keysetspecific.c,
+ posix/src/killinfo.c, posix/src/mqueue.c,
+ posix/src/mqueuerecvsupp.c, posix/src/mqueuesendsupp.c,
+ posix/src/mqueuetranslatereturncode.c, posix/src/mutex.c,
+ posix/src/posixintervaltotimespec.c,
+ posix/src/posixtimespecsubtract.c, posix/src/psignal.c,
+ posix/src/pthread.c, posix/src/ptimer1.c, posix/src/semaphore.c,
+ posix/src/sysconf.c: Convert to using c99 fixed size types.
+
+2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * score/include/rtems/system.h: include <stdint.h>.
+
+2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ PR/589 rtems
+ * include/rtems/pci.h: New (Moved from c/src/libchip/network/pci.h).
+
+2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/src/malloc.c: Remove lvalue casts.
+
+2004-03-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libcsupport/include/chain.h, libcsupport/include/clockdrv.h,
+ libcsupport/include/ringbuf.h, libcsupport/include/spurious.h,
+ libcsupport/include/timerdrv.h, libcsupport/include/vmeintr.h,
+ libcsupport/include/motorola/mc68230.h,
+ libcsupport/include/rtems/assoc.h, libcsupport/include/rtems/libio.h,
+ libcsupport/include/rtems/libio_.h,
+ libcsupport/include/rtems/termiostypes.h,
+ libcsupport/include/zilog/z8036.h, libcsupport/include/zilog/z8530.h,
+ libcsupport/include/zilog/z8536.h, libcsupport/src/__gettod.c,
+ libcsupport/src/assoc.c, libcsupport/src/assocnamebad.c,
+ libcsupport/src/error.c, libcsupport/src/libio.c,
+ libcsupport/src/libio_sockets.c, libcsupport/src/malloc.c,
+ libcsupport/src/no_libc.c, libcsupport/src/termios.c,
+ libcsupport/src/termiosreserveresources.c: Convert to using c99
+ fixed-size types.
+
+2004-03-22 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h,
+ libfs/src/dosfs/fat_fat_operations.c,
+ libfs/src/dosfs/fat_fat_operations.h, libfs/src/dosfs/fat_file.c,
+ libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_dir.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_initsupp.c,
+ libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/deviceio.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/linearfile.c,
+ libfs/src/imfs/memfile.c: Convert to using c99 fixed-size types.
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/net/radix.c: Remove warning.
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/shell/cmds.c: Remove warning.
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/lib/ftpfs.c: Switch bcopy to memcpy.
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/newlibc.c, libcsupport/src/sync.c: Eliminate
+ warnings. Explicitly defeat __STRICT_ANSI__ since both
+ legitimately use routines beyond ANSI.
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * cpukit/libblock/src/bdbuf.c: Initialize pointer to avoid warning.
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * score/macros/rtems/score/chain.inl, score/src/objectidtoname.c:
+ Add cast to avoid type punning warning in gcc 3.3.
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ *
+
+2004-03-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libblock/src/bdbuf.c, libblock/src/ramdisk.c,
+ libcsupport/src/newlibc.c, libcsupport/src/sync.c,
+ libmisc/cpuuse/cpuuse.c, libmisc/monitor/mon-symbols.c,
+ libmisc/shell/cmds.c, libmisc/shell/shell.c,
+ libnetworking/kern/kern_sysctl.c, libnetworking/lib/ftpfs.c,
+ libnetworking/lib/tftpDriver.c, libnetworking/libc/gethostbydns.c,
+ libnetworking/libc/gethostbyht.c, libnetworking/libc/gethostnamadr.c,
+ libnetworking/libc/getnetbyht.c, libnetworking/libc/getnetnamadr.c,
+ libnetworking/libc/inet_addr.c, libnetworking/libc/linkaddr.c,
+ libnetworking/libc/map_v4v6.c, libnetworking/libc/ns_print.c,
+ libnetworking/libc/ns_ttl.c, libnetworking/libc/nsap_addr.c,
+ libnetworking/libc/rcmd.c, libnetworking/libc/res_debug.c,
+ libnetworking/libc/res_mkupdate.c, libnetworking/libc/res_query.c,
+ libnetworking/libc/res_send.c, libnetworking/libc/res_update.c,
+ libnetworking/net/radix.c, libnetworking/rtems/mkrootfs.c,
+ librpc/src/rpc/clnt_perror.c, librpc/src/rpc/rtems_rpc.c,
+ librpc/src/rpc/svc.c, sapi/include/confdefs.h,
+ score/macros/rtems/score/chain.inl, score/src/objectidtoname.c:
+
+2004-02-26 Thomas Rauscher <trauscher@loytec.com.
+
+ PR 584/RTEMS
+ * rtems/src/eventtimeout.c: Fix critical section window.
+
+2004-02-26 Joel Sherrill <joel@OARcorp.com>
+
+ PR 582/core
+ * posix/src/mqueue.c, posix/src/mqueuecreatesupp.c,
+ posix/src/mqueuedeletesupp.c, posix/src/mqueueunlink.c: Use memory
+ from workspace to avoid use of mutex during dispatch disable critical
+ section. Besides memory for object names should come from the
+ Workspace anyway.
+
+2004-02-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/version.m4: 4.6.99.0.
+
+2004-02-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/Makefile.am: Remove ACLOCAL_AMFLAGS.
+
+2004-01-30 Wilfried Busalski <w.busalski@lancier-monitoring.de>
+
+ PR pppd/564
+ * libnetworking/net/if_ppp.c, libnetworking/net/if_pppvar.h,
+ libnetworking/net/ppp_tty.c: ppp0 Interface lose packets if the
+ system use a slow baudrate for the modem or the tcp/ip-packet is
+ fragmented.
+
+2004-01-30 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog, rtems/Makefile.am, rtems/include/rtems/rtems/support.h:
+ Reverse developmental patches accidentally committed.
+
+2004-01-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * ChangeLog: Merge-in libnetworking/ChangeLog.
+ * ChangeLog: Merge-in libcsupport/ChangeLog.
+ * ChangeLog: Merge-in libblock/ChangeLog, libfs/ChangeLog.
+ * ChangeLog: Merge-in libmisc/ChangeLog, librpc/ChangeLog.
+ * ChangeLog: Merge-in itron/ChangeLog, posix/ChangeLog, score/ChangeLog,
+ sapi/ChangeLog, rtems/ChangeLog.
+ * libblock/ChangeLog, libfs/ChangeLog, libcsupport/ChangeLog,
+ libmisc/ChangeLog, librpc/ChangeLog, libnetworking/ChangeLog,
+ itron/ChangeLog, posix/ChangeLog, score/ChangeLog, sapi/ChangeLog,
+ rtems/ChangeLog: Remove.
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/rtems-top.m4: Remove PROJECT_ROOT. Prepend ../ to $1.
+ * aclocal/env-rtemscpu.m4: Reworked.
+ * configure.ac: RTEMS_TOP([.]).
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, itron/Makefile.am, posix/Makefile.am, score/Makefile.am,
+ sapi/Makefile.am, rtems/Makefile.am, libmisc/Makefile.am,
+ librpc/Makefile.am, libblock/Makefile.am, libfs/Makefile.am,
+ libcsupport/Makefile.am, libnetworking/Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Remove $(ARCH)/$(dirstamp). Add TMPINSTALL_FILES
+ to CLEANFILES.
+ * automake/local.am: Remove depend-am.
+ * automake/subdirs.am: Remove depend-recursive.
+ * score/Makefile.am: Re-add dirstamps to PREINSTALL_FILES. Add
+ PREINSTALL_FILES to CLEANFILES. Add cpuopts.h to DISTCLEANFILES.
+ * Makefile.am, itron/Makefile.am, posix/Makefile.am, sapi/Makefile.am,
+ rtems/Makefile.am, libmisc/Makefile.am, librpc/Makefile.am,
+ libblock/Makefile.am, libfs/Makefile.am, libcsupport/Makefile.am,
+ libnetworking/Makefile.am: Re-add dirstamps to PREINSTALL_FILES. Add
+ PREINSTALL_FILES to CLEANFILES.
+ * libnetworking/netinet/in_cksum.c: #include netinet/in_cksum_<cpu>.h.
+
+2004-01-13 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR/549 networking
+ * libnetworking/netinet/in_cksum_powerpc.h: New (copy of
+ in_cksum_powerpc.c).
+ * libnetworking/netinet/in_cksum_i386.h: New (copy of in_cksum_i386.c).
+ * libnetworking/netinet/in_cksum_arm.h: New (copy of in_cksum_arm.c).
+ * libnetworking/netinet/in_cksum_m68k.c: New (copy of in_cksum_m68k.c).
+ * libnetworking/netinet/in_cksum_i386.c,
+ libnetworking/netinet/in_cksum_arm.c,
+ libnetworking/netinet/in_cksum_powerpc.c,
+ libnetworking/netinet/in_cksum_m68k.c: Remove.
+ * libnetworking/netinet/Makefile.am: Reflect changes above.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+ * score/cpu/Makefile.am: Use @RTEMS_CPU@ instead of $(RTEMS_CPU).
+ PR 548/rtems
+ * libcsupport/Makefile.am: Add src/envlock.c.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/rtems-top.m4: Don't AC_SUBST PROJECT_ROOT. Remove
+ PROJECT_TOPdir (Unused).
+ * aclocal/env-rtemscpu.m4: Remove PROJECT_RELEASE. Expand
+ ${PROJECT_ROOT}. Remove RTEMS_ENABLE_BARE (Unused). Don't AC_SUBST
+ RTEMS_BSP.
+ * aclocal/enable-bare.m4: Remove (Unused).
+ * aclocal/rtems-top.m4: Remove check for cpukit/aclocal/version.m4.
+ Remove gnu-make endif HACK (Unused).
+ * wrapup/Makefile.am: Include compile.am. Use TMP_LIBS instead of LIBS
+ to avoid potential conflicts with auto*tools' LIBS. Reflect new
+ locations of libscorecpu*.a.
+ * Makefile.am: Remove AUTOMAKE_FILES.
+ * automake/compile.am: Replace contents with contents of
+ automake/amcompile.am.
+ * automake/amcompile.am, automake/lib.am: Remove.
+ * configure.ac, aclocal/enable-bare.m4, aclocal/enable-inlines.m4,
+ aclocal/enable-itron.m4, aclocal/enable-multiprocessing.m4,
+ aclocal/enable-networking.m4, aclocal/enable-posix.m4,
+ aclocal/enable-rtems-debug.m4, aclocal/multi.m4, aclocal/multilib.m4:
+ Use AS_HELP_STRING instead of AC_HELP_STRING (deprecated in
+ autoconf-2.59).
+ * automake/local.am: Remove clean-local, depend-gcc.
+ * itron/Makefile.am, posix/Makefile.am, score/Makefile.am: Include
+ compile.am, again.
+ * score/macros/rtems/score/README: Remove (Redundant with macros/README).
+ * sapi/Makefile.am, rtems/Makefile.am: Include compile.am, again.
+ * libmisc/Makefile.am: Include compile.am again. Misc fixes.
+ * librpc/Makefile.am: Include compile.am, again. Put man-pages into
+ EXTRA_DIST to work around automake not distributing conditionally
+ installed *_MANS. Distribute include/rpcsvc.
+ * libblock/Makefile.am: Include compile.am, again. Eliminate C_FILES.
+ Reformat.
+ * libfs/Makefile.am: Include compile.am, again. Reformat/Cleanup.
+ * libcsupport/Makefile.am: Reformat, add UNUSED_FILES.
+ * libcsupport/Makefile.am: Include compile.am, again. Eliminate
+ DOC_FILES.
+ * libnetworking/Makefile.am: Include compile.am, again. Cleanup.
+
+2004-01-08 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Cosmetics.
+ * aclocal/enable-networking.m4: Don't AC_SUBST(RTEMS_HAS_NETWORKING).
+ * aclocal/check-networking.m4: Don't AC_SUBST(HAS_NETWORKING).
+ * automake/amcompile.am: Remove $(ARCH).
+ * wrapup/Makefile.am: Add $(ARCH). Remove compile.am, lib.am. Include
+ amcompile.am.
+ * wrapup/Makefile.am: Use ../*/*$(LIB_VARIANT).a instead of
+ $(ARCH)/lib*.a.
+ * wrapup/Makefile.am: Reflect changes to libblock/Makefile.am. Reflect
+ changes to libcsupport/Makefile.am.
+ * itron/Makefile.am: Add libs to CLEANFILES. Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * itron/Makefile.am: Build libitron$(LIB_VARIANT).a instead of
+ $(ARCH)/libitron.a.
+ * posix/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * posix/Makefile.am: Build libposix$(LIB_VARIANT).a instead of
+ $(ARCH)/libposix.a.
+ * score/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * score/Makefile.am: Build libscore$(LIB_VARIANT).a instead of
+ $(ARCH)/libscore.a.
+ * sapi/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * sapi/Makefile.am: Build libsapi$(LIB_VARIANT).a instead of
+ $(ARCH)/libsapi.a.
+ * rtems/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * rtems/Makefile.am: Build librtems$(LIB_VARIANT).a instead of
+ $(ARCH)/librtems.a.
+ * libmisc/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * libmisc/Makefile.am: Build lib*$(LIB_VARIANT).a instead of
+ $(ARCH)/lib*.a.
+ * librpc/Makefile.am: Add libs to CLEANFILES. Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * librpc/Makefile.am: Build lib*$(LIB_VARIANT).a instead of
+ $(ARCH)/lib*.a.
+ * libblock/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * libblock/include/rtems/blkdev.h,
+ libblock/include/rtems/ide_part_table.h, libblock/src/bdbuf.c,
+ libblock/src/ide_part_table.c, libblock/src/ramdisk.c: Switch to using
+ c99 fixed size types instead of RTEMS-types.
+ * libblock/Makefile.am: Build libblock$(LIB_VARIANT).a instead of
+ $(ARCH)/libblock.a.
+ * libfs/Makefile.am: Add libs to CLEANFILES. Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * libfs/Makefile.am: Build lib*$(LIB_VARIANT).a instead of
+ $(ARCH)/lib*.a.
+ * libcsupport/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES =
+ lib*_a_SOURCES.
+ * libcsupport/Makefile.am: Build libcsupport$(LIB_VARIANT).a instead of
+ $(ARCH)/libcsupport.a.
+ * libnetworking/Makefile.am: Remove *C_FILES.
+ * libnetworking/Makefile.am: Add libs to CLEANFILES Set lib*_g_a_SOURCES
+ = lib*_a_SOURCES.
+ * libnetworking/Makefile.am: Build lib*$(LIB_VARIANT).a instead of
+ $(ARCH)/lib*.a.
+
+2004-01-07 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Reflect changes to library Makefile.ams.
+ * automake/amcompile.am: New.
+ * configure.ac: Add subdir-objects, AM_PROG_CC_C_O.
+ * itron/Makefile.am, posix/Makefile.am, score/Makefile.am,
+ sapi/Makefile.am, rtems/Makefile.am, libmisc/Makefile.am,
+ librpc/Makefile.am, libblock/Makefile.am, libfs/Makefile.am,
+ libcsupport/Makefile.am, libnetworking/Makefile.am: Build library using
+ EXTRA_LIBRARIES and automake rules.
+
+2004-01-07 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/rtems-cpu-subdirs.m4, score/cpu/Makefile.am: mips64orion port
+ removed as mips port more completely covers the MIPS family.
+ * score/cpu/mips64orion/.cvsignore, score/cpu/mips64orion/ChangeLog,
+ score/cpu/mips64orion/Makefile.am, score/cpu/mips64orion/asm.h,
+ score/cpu/mips64orion/configure.ac, score/cpu/mips64orion/cpu.c,
+ score/cpu/mips64orion/cpu_asm.S, score/cpu/mips64orion/cpu_asm.h,
+ score/cpu/mips64orion/idtcpu.h, score/cpu/mips64orion/idtmon.h,
+ score/cpu/mips64orion/iregdef.h, score/cpu/mips64orion/rtems/.cvsignore,
+ score/cpu/mips64orion/rtems/score/.cvsignore,
+ score/cpu/mips64orion/rtems/score/cpu.h,
+ score/cpu/mips64orion/rtems/score/mips64orion.h,
+ score/cpu/mips64orion/rtems/score/types.h: Removed.
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Include rtems/cdefs.h so
+ things compile.
+
+2003-12-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Use $(mkdir_p) instead of $(mkinstalldirs).
+
+2003-12-17 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-20031217-test.
+
+2003-12-16 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 533/bsps
+ * score/startup/linkcmds: Update linkcmds for gcc 3.3.2.
+
+2003-12-16 Joel Sherrill <joel@OARcorp.com>
+
+ PR 543/rtems
+ * score/src/threadclose.c: Make the task delete extension run outside a
+ dispatch disabled critical section so extensions can free resources.
+ PR 542/filesystem
+ * libcsupport/include/rtems/libio_.h: Add rtems_libio_iop_to_descriptor
+ macro to convert iop to the corresponding integer file descriptor.
+
+2003-12-13 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/env-rtemscpu.m4: Remove stray '/' in PROJECT_LIB.
+ * wrapup/Makefile.am: Remove duplicate $(PROJECT_LIB) rule.
+ * aclocal/env-rtemscpu.m4: Add PROJECT_LIB.
+ * wrapup/Makefile.am: Use $(PROJECT_LIB) instead of
+ ${PROJECT_RELEASE}/lib.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, wrapup/Makefile.am: Use mkdir_p. Remove dirs from
+ PRE/TMPINSTALL_FILES.
+ * wrapup/Makefile.am: Reworked.
+ * aclocal/lead-dot.m4: Remove (Use the version in automake-1.8).
+ * automake/lib.am: Remove $(project_libdir)$(MULTISUBDIR).
+ * aclocal/env-rtemscpu.m4: Reflect new definition of project_lib.
+ * Makefile.am: Remove BUILT_SOURCES.
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+ * itron/Makefile.am, posix/Makefile.am, score/Makefile.am,
+ sapi/Makefile.am, rtems/Makefile.am, libmisc/Makefile.am,
+ librpc/Makefile.am, libblock/Makefile.am, libfs/Makefile.am,
+ libcsupport/Makefile.am: Use mkdir_p. Remove dirs from
+ PRE/TMPINSTALL_FILES.
+ * libcsupport/Makefile.am: Remove BUILT_SOURCES.
+ * libnetworking/Makefile.am: Use mkdir_p. Remove dirs from
+ PRE/TMPINSTALL_FILES.
+
+2003-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/Makefile.am: Cosmetics.
+
+2003-12-11 Joel Sherrill <joel@OARcorp.com>
+
+ PR 540/rtems_misc
+ * libmisc/cpuuse/cpuuse.c, libmisc/rtmonuse/rtmonuse.c: Correct object
+ name printing.
+ PR 531/rtems_misc
+ * libmisc/rtmonuse/rtmonuse.c, libmisc/stackchk/check.c: Correct
+ indexing.
+
+2003-12-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libblock/src/ata.c: Remove.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Add $(ARCH)/$(dirstamp) rules.
+ * wrapup/Makefile.am: Reflect $(dirstamp) changes.
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+ * aclocal/lead-dot.m4: New (from automake-1.7f).
+ * aclocal/rtems-top.m4: Require AM_SET_LEADING_DOT. Add
+ AC_SUBST(dirstamp).
+ * itron/Makefile.am: Add $(dirstamp) to compilation rules.
+ * itron/Makefile.am: Add $(dirstamp) to preinstallation rules. Remove
+ MACROS.
+ * posix/Makefile.am: Add $(dirstamp) to compilation rules.
+ * posix/Makefile.am: Add $(dirstamp) to preinstallation rules. Remove
+ MACROS.
+ * score/Makefile.am: Add $(dirstamp) to compilation rules.
+ * score/Makefile.am: Add $(dirstamp) to preinstallation rules. Remove
+ MACROS.
+ * sapi/Makefile.am: Add $(dirstamp) to compilation rules. Add
+ AM_CPPFLAGS += -I$(top_builddir).
+ * sapi/Makefile.am: Add $(dirstamp) to preinstallation rules. Remove
+ MACROS.
+ * rtems/Makefile.am: Add $(dirstamp) to compilation rules. Add
+ AM_CPPFLAGS += -I$(top_builddir).
+ * rtems/Makefile.am: Add $(dirstamp) to preinstallation rules. Remove
+ MACROS.
+ * libmisc/Makefile.am: Add $(dirstamp) to compilation rules. Fix misc.
+ typos.
+ * libmisc/Makefile.am: Add $(dirstamp) to preinstallation rules.
+ * librpc/Makefile.am: Add $(dirstamp) to compilation rules.
+ * librpc/Makefile.am: Add $(dirstamp) to preinstallation rules.
+ * libblock/Makefile.am: Add $(dirstamp) to compilation rules.
+ * libblock/Makefile.am: Add $(dirstamp) to preinstallation rules.
+ * libfs/Makefile.am: Add $(dirstamp) to compilation rules.
+ * libfs/Makefile.am: Add $(dirstamp) to preinstallation rules.
+ * libcsupport/Makefile.am: Add $(dirstamp) to compilation rules.
+ * libcsupport/Makefile.am: Add $(dirstamp) to preinstallation rules.
+ * libnetworking/Makefile.am: Add $(dirstamp) to compilation rules.
+ * libnetworking/Makefile.am: Fix libc_OBJS.
+ * libnetworking/Makefile.am: Add $(dirstamp) to preinstallation rules.
+ Restore libc/$(ARCH)/lib.a.
+
+2003-11-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Reflect having removed libnetworking/libc/Makefile.am,
+ libnetworking/lib/Makefile.am.
+ * configure.ac: Reflect changes to libmisc/*.
+ * libmisc/Makefile.am: Reformat.
+ * libmisc/capture/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dummy/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/fsmount/Makefile.am,
+ libmisc/monitor/Makefile.am, libmisc/mw-fb/Makefile.am,
+ libmisc/rtmonuse/Makefile.am, libmisc/serdbg/Makefile.am,
+ libmisc/shell/Makefile.am, libmisc/stackchk/Makefile.am,
+ libmisc/untar/Makefile.am: Remove.
+ * libmisc/Makefile.am: Merge-in the Makefile.ams above.
+ * libnetworking/libc/Makefile.am, libnetworking/lib/Makefile.am: Remove.
+ * libnetworking/Makefile.am: Merge-in the Makefile.ams above.
+
+2003-11-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Merge-in former libmisc/wrapup/Makefile.am.
+ * configure.ac: Reflect changes to libfs Makefile.ams. Remove
+ libmisc/wrapup/Makefile.
+ * configure.ac: Use here-documents to generate cpuopts.tmp. Various
+ fixes and changes to argument processing. Reflect changes to librpc
+ Makefile.ams.
+ * acinclude.m4: Use here-documents to generate cpuopts.tmp.
+ * aclocal/check-itron.m4: Remove HAS_IRON_API.
+ * aclocal/check-multiprocessing.m4: Remove HAS_MP.
+ * aclocal/check-posix.m4: Remove HAS_POSIX_API.
+ * libmisc/wrapup/Makefile.am, libmisc/wrapup/.cvsignore: Remove.
+ * libmisc/Makefile.am: Reflect changes above.
+ * librpc/src/rpc/Makefile.am, librpc/src/xdr/Makefile.am,
+ librpc/src/Makefile.am: Removed.
+ * librpc/Makefile.am: Merge-in src/rpc/Makefile.am, src/xdr/Makefile.am,
+ src/Makefile.am. Various fixes. Reformat.
+ * librpc/include/rpc/rpc.hinclude/rpc/rpc.h: Rename struct
+ rtems_rpc_task_variables into struct _rtems_rpc_task_variables (Avoid
+ symbol conflict between struct and variable). struct
+ _rtems_rpc_task_variables *rtems_rpc_task_variables; Reflect changes
+ above.
+ * librpc/src/rpc/clnt_perror.c, librpc/src/rpc/clnt_raw.c,
+ librpc/src/rpc/clnt_simple.c, librpc/src/rpc/rpcdname.c,
+ librpc/src/rpc/rtems_rpc.c, librpc/src/rpc/svc.c, librpc/
+ src/rpc/svc_auth.c, librpc/src/rpc/svc_raw.c,
+ librpc/src/rpc/svc_simple.c: Reflect changes above.
+ * libfs/Makefile.am: Merge-in src/Makefile.am, src/imfs/Makefile.am,
+ src/dosfs/Makefile.am.
+ * libfs/src/Makefile.am, libfs/src/imfs/Makefile.am,
+ libfs/src/dosfs/Makefile.am: Removed.
+
+2003-11-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/canonicalize-tools.m4, aclocal/check-itron.m4,
+ aclocal/check-multiprocessing.m4, aclocal/check-newlib.m4,
+ aclocal/check-posix.m4, aclocal/check-rtems-debug.m4,
+ aclocal/check-tool.m4, aclocal/enable-bare.m4,
+ aclocal/enable-inlines.m4, aclocal/enable-itron.m4,
+ aclocal/enable-multiprocessing.m4, aclocal/enable-networking.m4,
+ aclocal/enable-posix.m4, aclocal/enable-rtems-debug.m4,
+ aclocal/env-rtemscpu.m4, aclocal/gcc-isystem.m4, aclocal/gcc-pipe.m4,
+ aclocal/multi.m4, aclocal/multilib.m4, aclocal/prog-cc.m4,
+ aclocal/rtems-top.m4, aclocal/sysv-ipc.m4: Fix underquoting to silence
+ automake-1.8.
+
+2003-11-26 Joel Sherrill <joel@OARcorp.com>
+
+ PR 524/filesystem
+ * libcsupport/src/newlibc.c: Address 1K buffer leak from incomplete
+ cleanup of newlib reentrancy handler.
+ PR 523/filesystem
+ * libcsupport/src/malloc.c: Make malloc family safer for use from ISRs
+ and dispatching critical sections. If in a critical section while doing
+ a free(), then the free is deferred until the next malloc() attempt.
+
+2003-11-25 Joel Sherrill <joel@OARcorp.com>
+
+ PR 526/rtems
+ * score/src/threadcreateidle.c: Idle task name should be a string and
+ PR484 broke this.
+
+2003-11-25 Jennifer Averett <jennifer@OARcorp.com>
+
+ PR 519/filesystem
+ * libcsupport/include/rtems/libio_.h, libcsupport/src/eval.c,
+ libcsupport/src/rmdir.c, libcsupport/src/unlink.c: Check write
+ permissions in parent directory for file or directory delete.
+
+2003-11-24 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use RTEMS_INLINES instead of USE_INLINES. Elimimate
+ INLINESdir.
+ * aclocal/enable-inlines.m4: Ditto. Remove RTEMS_USE_MACROS.
+ * .cvsignore: Add config.h.in.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Make RTEMS_DEBUG an RTEMS_CPUOPT.
+ PR 525/rtems
+ * score/include/rtems/system.h: Use RTEMS_INLINES instead of USE_INLINES.
+ * score/include/rtems/score/chain.h, score/include/rtems/score/thread.h,
+ score/src/chain.c, score/src/coremutexseize.c, score/src/threadget.c:
+ Ditto.
+ * score/Makefile.am: Don't use gmake to preinstall.
+ * sapi/Makefile.am: Reworked.
+
+2003-11-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Reflect having removed libnetworking/wrapup.
+ * configure.ac: Ditto.
+ * itron/Makefile.am, posix/Makefile.am, rtems/Makefile.am,
+ libblock/Makefile.am: Reworked.
+ * libcsupport/include/rtems/cdefs.h: Use _RTEMS_CDEFS_H guards.
+ * libcsupport/include/rtems/cdefs.h: New.
+ * libcsupport/Makefile.am: Completely reworked.
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Include rtems/cdefs.h
+ instead of sys/cdefs.h (Nonportable).
+ * libnetworking/wrapup/Makefile.am: Removed.
+ * libnetworking/Makefile.am: Reworked.
+
+2003-11-20 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * acinclude.m4: New.
+ * configure.ac: Don't use AUTOHEADER to generate cpuopts.h. Add local
+ autoheader config.h.
+ * aclocal/canonical-target-name.m4: Require AC_CANONICAL_HOST.
+ * aclocal/enable-inlines.m4: Remove USE_MACROS (Unused).
+ * itron/Makefile.am: Remove src/config.h. AM_CPPFLAGS +=
+ -I$(top_builddir).
+ * posix/Makefile.am: Remove src/config.h AM_CPPFLAGS +=
+ -I$(top_builddir).
+ * libmisc/capture/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dummy/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/monitor/Makefile.am,
+ libmisc/mw-fb/Makefile.am, libmisc/rtmonuse/Makefile.am,
+ libmisc/serdbg/Makefile.am, libmisc/shell/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am: Remove
+ config.h. AM_CPPFLAGS += -I$(top_builddir).
+ * libblock/Makefile.am: AM_CPPFLAGS += -I$(top_builddir). Use
+ AM_CPPFLAGS instead of AM_CFLAGS.
+ * libblock/src/ata.c: Include config.h.
+ * libblock/src/bdbuf.c, libblock/src/blkdev.c, libblock/src/diskdevs.c,
+ libblock/src/ide_part_table.c, libblock/src/ramdisk.c: Ditto.
+ * libfs/src/dosfs/Makefile.am, libfs/src/imfs/Makefile.am: Remove
+ config.h AM_CPPFLAGS += -I$(top_builddir).
+ * itron/src/config.h, posix/src/config.h, libmisc/capture/config.h,
+ libmisc/cpuuse/config.h, libmisc/devnull/config.h,
+ libmisc/dummy/config.h, libmisc/dumpbuf/config.h,
+ libmisc/monitor/config.h, libmisc/mw-fb/config.h,
+ libmisc/rtmonuse/config.h, libmisc/serdbg/config.h,
+ libmisc/stackchk/config.h, libmisc/shell/config.h,
+ libmisc/untar/config.h, libfs/src/dosfs/config.h,
+ libfs/src/imfs/config.h, libcsupport/src/config.h: Remove.
+ * libcsupport/src/Makefile.am: AM_CPPFLAGS += -I$(top_builddir).
+
+2003-11-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libfs/Makefile.am: Cosmetics.
+
+2003-10-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/src/regiongetsegment.c: Remove unneccessary typecast in
+ assignment to thread->Wait.return_argment.
+
+2003-10-22 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ PR 515/filesystem
+ * libfs/src/dosfs/fat_fat_operations.c: Remove commented out code.
+
+2003-10-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 509/filesystem
+ * libfs/src/dosfs/fat.c: _fat_block_read and _fat_block_write return
+ error codes instead of -1 in case of errors, as they are supposed to do
+ according to the comments documenting these functions.
+
+2003-10-22 Joel Sherrill <joel@OARcorp.com>
+
+ PR 512/core
+ * rtems/src/tasks.c, rtems/src/taskvariabledelete.c: Run task variable
+ destructor when task variable is deleted. Also some style cleanup.
+ PR 440/filesystem
+ * libfs/src/dosfs/fat_fat_operations.c: Improve write speed with FAT12
+ and FAT16 filesystems. Previously merged on 4.6 branch.
+ * libfs/ChangeLog: Correct line length.
+ PR 511/filesystem
+ * libcsupport/src/malloc.c: Add deferred free and protect against C
+ Program Heap operations while in a dispatch disable critical section or
+ ISR.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/check-posix.m4: Add m4-quotes. Require
+ RTEMS_CANONICAL_TARGET_CPU instead of RTEMS_CHECK_CPU.
+ * aclocal/canonical-host.m4: Remove.
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+ * aclocal/sysv-ipc.m4: Remove reference to RTEMS_CANONICAL_HOST.
+ * aclocal/canonical-target-name.m4: Use AC_CANONICAL_HOST instead of
+ AC_CANONICAL_TARGET. Use $host instead of $target.
+ * aclocal/check-multiprocessing.m4: Add m4-quotes. Remove
+ RTEMS_CHECK_CPU.
+ * aclocal/check-itron.m4, aclocal/check-networking.m4: Add m4-quotes.
+ Require RTEMS_CANONICAL_TARGET_CPU instead of RTEMS_CHECK_CPU.
+ * aclocal/check-cpu.m4: Remove.
+ * aclocal/canonical-target-name.m4: Add m4-quotes.
+ * configure.ac: Merge-in former aclocal/check-cpu.m4.
+ * posix/src/cancelrun.c, posix/src/pthreadexit.c,
+ posix/src/pthreadjoin.c, posix/ src/sigtimedwait.c: Remove unnecessary
+ typecasts in assignments to thread->Wait.return_argument.
+ * score/src/coremsgseize.c, score/src/coremsgsubmit.c: Remove
+ unnecessary typecasts in assignments to thread->Wait.return_argument.
+ * libmisc/capture/capture-cli.c: Reflect new rtems_monitor_command_arg_t.
+ * librpc/src/rpc/Makefile.am, librpc/src/xdr/Makefile.am: Remove __P
+ from AM_CPPFLAGS. Rely on sys/cdefs.h providing it.
+ * libfs/src/dosfs/Makefile.am: noinst_HEADERS += fat.h.
+ * libfs/src/dosfs/msdos_file.c (msdos_file_read,
+ libfs/msdos_file_write): Use '0' as initial value for ret instead of
+ RC_OK.
+ * libfs/src/dosfs/msdos_conv.c: Remove isupper, islower, toupper,
+ tolower (Unused).
+
+2003-10-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Check for sys/cdefs.h.
+ * aclocal/env-rtems-cpu.m4: Add project_includedir. Deprecate
+ PROJECT_INCLUDE. Change project_includedir to $(PROJECT_ROOT)/include
+ for multilibs.
+
+2003-10-13 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/cleanuppop.c, posix/src/cleanuppush.c: Protect use of
+ _Workspace_Allocate and _Workspec_Free.
+
+2003-10-02 Phil Torre <ptorre@zetron.com>
+
+ PR 504/rtems
+ * score/include/rtems/score/coremutex.h: Add fatal error check for a
+ task blocking on a mutex when thread dispatching is disabled.
+ PR 504/rtems
+ * libcsupport/src/newlibc.c: Fix memory allocation of libc extension so
+ it is dispatch disabled safe See PR for detailed explanation.
+
+2003-09-26 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 498/rtems
+ * libcsupport/src/printk.c: RTEMS printk() does not support the %i
+ format which is used by a lot of driver/BSP etc. code. The trivial patch
+ allows %i/%I as an alias for %d/%D.
+
+2003-09-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 495/rtems_misc
+ * libmisc/capture/capture-cli.c, libmisc/monitor/mon-command.c,
+ libmisc/monitor/mon-config.c, libmisc/monitor/mon-monitor.c,
+ libmisc/monitor/mon-object.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/monitor.h, libmisc/shell/cmds.c: Move to making libmisc
+ 16/32 bit clean.
+
+2003-09-26 Joel Sherrill <joel@OARcorp.com>
+
+ * score/cpu/hppa1.1/.cvsignore, score/cpu/hppa1.1/ChangeLog,
+ score/cpu/hppa1.1/Makefile.am, score/cpu/hppa1.1/configure.ac,
+ score/cpu/hppa1.1/cpu.c, score/cpu/hppa1.1/cpu_asm.S,
+ score/cpu/hppa1.1/rtems/.cvsignore,
+ score/cpu/hppa1.1/rtems/score/.cvsignore,
+ score/cpu/hppa1.1/rtems/score/cpu.h,
+ score/cpu/hppa1.1/rtems/score/cpu_asm.h,
+ score/cpu/hppa1.1/rtems/score/hppa.h,
+ score/cpu/hppa1.1/rtems/score/types.h: Removed.
+ PR 492/filesystem
+ * libfs/src/dosfs/fat_file.c: Fix inconsistent types in va_args call.
+
+2003-09-24 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, librpc/Makefile.am: Merge-in include/Makefile.am.
+ * include/Makefile.am, librpc/include/Makefile.am: Remove.
+ * configure.ac: Reflect having removed include/Makefile.am and
+ librpc/include/Makefile.am.
+
+2003-09-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/monitor/monitor.h: Add rtems_monitor_commands[] (Illegally
+ applied by shell/). Remove ifdef(__mips64) (Make broken code visible
+ again).
+ * libmisc/monitor/mon-command.c: Add several ifndef RTEMS_UNIX to avoid
+ warnings.
+ * libmisc/monitor/mon-monitor.c: Remove RTEMS_CPU_HAS_16_BIT_ADDRESSES
+ (Make broken code visible again).
+ * libmisc/shell/cmds.c: Remove local decls of rtems_monitor_commands[].
+
+2003-09-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/monitor/monitor.h: Remove STREQ, STNEQ (pollute namespace),
+ RTEMS_MONITOR_PROMPT (pollutes namespace, useless).
+ * libmisc/monitor/mon-command.c: Add RTEMS_MONITOR_PROMPT.
+ * libmisc/monitor/mon-monitor.c: Apply private version of STREQ.
+ * libmisc/monitor/symbols.h: Convert to private header.
+ * libmisc/monitor/monitor.h: Don't include symbols.h. Add forward decls.
+ for symbols from symbols.h.
+ * libmisc/monitor/Makefile.am: Don't install symbols.h.
+ * libmisc/monitor/mon-symbols.c: Include "symbols.h".
+
+2003-09-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 489/rtems
+ * score/include/rtems/score/thread.h: Change struct
+ Thread_Control_struct.libc_reent to using struct _reent*.
+ * score/inline/rtems/score/thread.inl: Reflect change above.
+ PR 489/rtems
+ * libcsupport/src/newlibc.c: Reflect struct
+ Thread_Control_struct.libc_reent having changed from void * to struct
+ _reent*.
+
+2003-09-15 Jay Monkman <jtm@smoothsmoothie.com>
+
+ PR 482/networking
+ * libnetworking/rtems/rtems_glue.c: Network interfaces can't be taken
+ down.
+ PR 481/networking
+ * libnetworking/net/ethernet.h, libnetworking/net/if_arp.h,
+ libnetworking/netinet/if_ether.h: Network structs should be packed.
+
+2003-09-13 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libcsupport/src/sync.c: Don't undef __STRICT_ANSI__. Use struct _reent
+ (struct reent doesn't exist).
+ PR 486/rtems
+ * libcsupport/src/newlib.c: Unconditionally include <stdio.h>.
+
+2003-09-11 Joel Sherrill <joel@OARcorp.com>
+
+ PR 488/rtems
+ * rtems/src/taskcreate.c, rtems/src/tasks.c: Ensure notepads are zeroed.
+
+2003-09-09 Ralf Corsepius <ralf_corsepius@rtems.com>
+
+ PR 487/filesystem
+ * libfs/src/dosfs/fat_file.c: Correct typing per gcc 3.3 warnings.
+
+2003-09-08 Mikec Ivica <mikici@acm.org>
+
+ * score/inline/rtems/score/userext.inl,
+ score/macros/rtems/score/userext.inl: Add missing cast.
+
+2003-09-08 Derick Hammond <derick@perkinstechnologies.com.au>
+
+ PR 484/rtems
+ * score/src/threadcreateidle.c: Idle task name was initialized
+ incorrectly.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * include/rtems/bspIo.h, include/rtems/fs.h, include/rtems/userenv.h,
+ itron/include/itron.h, itron/include/itronsys/eventflags.h,
+ itron/include/itronsys/fmempool.h, itron/include/itronsys/intr.h,
+ itron/include/itronsys/mbox.h, itron/include/itronsys/msgbuffer.h,
+ itron/include/itronsys/network.h, itron/include/itronsys/port.h,
+ itron/include/itronsys/semaphore.h, itron/include/itronsys/status.h,
+ itron/include/itronsys/sysmgmt.h, itron/include/itronsys/task.h,
+ itron/include/itronsys/time.h, itron/include/itronsys/types.h,
+ itron/include/itronsys/vmempool.h, itron/include/rtems/itron/config.h,
+ itron/include/rtems/itron/eventflags.h,
+ itron/include/rtems/itron/fmempool.h, itron/include/rtems/itron/intr.h,
+ itron/include/rtems/itron/itronapi.h, itron/include/rtems/itron/mbox.h,
+ itron/include/rtems/itron/msgbuffer.h,
+ itron/include/rtems/itron/network.h, itron/include/rtems/itron/object.h,
+ itron/include/rtems/itron/port.h, itron/include/rtems/itron/semaphore.h,
+ itron/include/rtems/itron/sysmgmt.h, itron/include/rtems/itron/task.h,
+ itron/include/rtems/itron/time.h, itron/include/rtems/itron/vmempool.h,
+ itron/inline/rtems/itron/eventflags.inl,
+ itron/inline/rtems/itron/fmempool.inl,
+ itron/inline/rtems/itron/intr.inl, itron/inline/rtems/itron/mbox.inl,
+ itron/inline/rtems/itron/msgbuffer.inl,
+ itron/inline/rtems/itron/network.inl, itron/inline/rtems/itron/port.inl,
+ itron/inline/rtems/itron/semaphore.inl,
+ itron/inline/rtems/itron/sysmgmt.inl, itron/inline/rtems/itron/task.inl,
+ itron/inline/rtems/itron/time.inl,
+ itron/inline/rtems/itron/vmempool.inl,
+ itron/macros/rtems/itron/eventflags.inl,
+ itron/macros/rtems/itron/fmempool.inl,
+ itron/macros/rtems/itron/intr.inl, itron/macros/rtems/itron/mbox.inl,
+ itron/macros/rtems/itron/msgbuffer.inl,
+ itron/macros/rtems/itron/network.inl, itron/macros/rtems/itron/port.inl,
+ itron/macros/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/sysmgmt.inl, itron/macros/rtems/itron/task.inl,
+ itron/macros/rtems/itron/time.inl,
+ itron/macros/rtems/itron/vmempool.inl, itron/src/can_wup.c,
+ itron/src/chg_pri.c, itron/src/cre_mbf.c, itron/src/cre_mbx.c,
+ itron/src/cre_sem.c, itron/src/cre_tsk.c, itron/src/del_mbf.c,
+ itron/src/del_mbx.c, itron/src/del_sem.c, itron/src/del_tsk.c,
+ itron/src/dis_dsp.c, itron/src/ena_dsp.c, itron/src/eventflags.c,
+ itron/src/exd_tsk.c, itron/src/ext_tsk.c, itron/src/fmempool.c,
+ itron/src/frsm_tsk.c, itron/src/get_tid.c, itron/src/itronintr.c,
+ itron/src/itronsem.c, itron/src/itrontime.c, itron/src/mbox.c,
+ itron/src/mboxtranslatereturncode.c, itron/src/msgbuffer.c,
+ itron/src/msgbuffertranslatereturncode.c, itron/src/network.c,
+ itron/src/port.c, itron/src/prcv_mbf.c, itron/src/prcv_mbx.c,
+ itron/src/preq_sem.c, itron/src/psnd_mbf.c, itron/src/rcv_mbf.c,
+ itron/src/rcv_mbx.c, itron/src/ref_mbf.c, itron/src/ref_mbx.c,
+ itron/src/ref_sem.c, itron/src/ref_tsk.c, itron/src/rel_wai.c,
+ itron/src/rot_rdq.c, itron/src/rsm_tsk.c, itron/src/sig_sem.c,
+ itron/src/slp_tsk.c, itron/src/snd_mbf.c, itron/src/snd_mbx.c,
+ itron/src/sta_tsk.c, itron/src/sus_tsk.c, itron/src/sysmgmt.c,
+ itron/src/task.c, itron/src/ter_tsk.c, itron/src/trcv_mbf.c,
+ itron/src/trcv_mbx.c, itron/src/tslp_tsk.c, itron/src/tsnd_mbf.c,
+ itron/src/twai_sem.c, itron/src/vmempool.c, itron/src/wai_sem.c,
+ itron/src/wup_tsk.c, posix/include/rtems/posix/cond.h,
+ posix/include/rtems/posix/condmp.h, posix/include/rtems/posix/config.h,
+ posix/include/rtems/posix/intr.h, posix/include/rtems/posix/key.h,
+ posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/mqueuemp.h, posix/include/rtems/posix/mutex.h,
+ posix/include/rtems/posix/mutexmp.h,
+ posix/include/rtems/posix/posixapi.h,
+ posix/include/rtems/posix/pthread.h,
+ posix/include/rtems/posix/pthreadmp.h,
+ posix/include/rtems/posix/ptimer.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/semaphoremp.h,
+ posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/intr.inl,
+ posix/inline/rtems/posix/key.inl, posix/inline/rtems/posix/mqueue.inl,
+ posix/inline/rtems/posix/mutex.inl,
+ posix/inline/rtems/posix/pthread.inl,
+ posix/inline/rtems/posix/semaphore.inl,
+ posix/inline/rtems/posix/timer.inl, posix/macros/rtems/posix/cond.inl,
+ posix/macros/rtems/posix/intr.inl, posix/macros/rtems/posix/key.inl,
+ posix/macros/rtems/posix/mqueue.inl, posix/macros/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/pthread.inl,
+ posix/macros/rtems/posix/semaphore.inl,
+ posix/macros/rtems/posix/timer.inl, posix/src/alarm.c, posix/src/kill.c,
+ posix/src/killinfo.c, posix/src/mqueuetranslatereturncode.c,
+ posix/src/pause.c, posix/src/pthreadattrdestroy.c,
+ posix/src/pthreadattrgetdetachstate.c,
+ posix/src/pthreadattrgetinheritsched.c,
+ posix/src/pthreadattrgetschedparam.c,
+ posix/src/pthreadattrgetschedpolicy.c, posix/src/pthreadattrgetscope.c,
+ posix/src/pthreadattrgetstackaddr.c,
+ posix/src/pthreadattrgetstacksize.c, posix/src/pthreadattrinit.c,
+ posix/src/pthreadattrsetdetachstate.c,
+ posix/src/pthreadattrsetinheritsched.c,
+ posix/src/pthreadattrsetschedparam.c,
+ posix/src/pthreadattrsetschedpolicy.c, posix/src/pthreadattrsetscope.c,
+ posix/src/pthreadattrsetstackaddr.c,
+ posix/src/pthreadattrsetstacksize.c, posix/src/pthreadcreate.c,
+ posix/src/pthreaddetach.c, posix/src/pthreadequal.c,
+ posix/src/pthreadexit.c, posix/src/pthreadgetcpuclockid.c,
+ posix/src/pthreadgetcputime.c, posix/src/pthreadgetschedparam.c,
+ posix/src/pthreadjoin.c, posix/src/pthreadkill.c,
+ posix/src/pthreadonce.c, posix/src/pthreadself.c,
+ posix/src/pthreadsetcputime.c, posix/src/pthreadsetschedparam.c,
+ posix/src/pthreadsigmask.c, posix/src/sigaction.c,
+ posix/src/sigaddset.c, posix/src/sigdelset.c, posix/src/sigemptyset.c,
+ posix/src/sigfillset.c, posix/src/sigismember.c, posix/src/signal_2.c,
+ posix/src/sigpending.c, posix/src/sigprocmask.c, posix/src/sigqueue.c,
+ posix/src/sigsuspend.c, posix/src/sigtimedwait.c, posix/src/sigwait.c,
+ posix/src/sigwaitinfo.c, posix/src/ualarm.c,
+ score/include/rtems/debug.h, score/include/rtems/seterr.h,
+ score/include/rtems/system.h, score/include/rtems/score/address.h,
+ score/include/rtems/score/apiext.h,
+ score/include/rtems/score/apimutex.h,
+ score/include/rtems/score/bitfield.h, score/include/rtems/score/chain.h,
+ score/include/rtems/score/context.h, score/include/rtems/score/copyrt.h,
+ score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h, score/include/rtems/score/heap.h,
+ score/include/rtems/score/interr.h, score/include/rtems/score/isr.h,
+ score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h,
+ score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h,
+ score/include/rtems/score/priority.h, score/include/rtems/score/stack.h,
+ score/include/rtems/score/states.h,
+ score/include/rtems/score/sysstate.h,
+ score/include/rtems/score/thread.h,
+ score/include/rtems/score/threadmp.h,
+ score/include/rtems/score/threadq.h, score/include/rtems/score/tod.h,
+ score/include/rtems/score/tqdata.h, score/include/rtems/score/userext.h,
+ score/include/rtems/score/watchdog.h,
+ score/include/rtems/score/wkspace.h,
+ score/inline/rtems/score/address.inl,
+ score/inline/rtems/score/chain.inl,
+ score/inline/rtems/score/coremsg.inl,
+ score/inline/rtems/score/coremutex.inl,
+ score/inline/rtems/score/coresem.inl, score/inline/rtems/score/heap.inl,
+ score/inline/rtems/score/isr.inl, score/inline/rtems/score/mppkt.inl,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/objectmp.inl,
+ score/inline/rtems/score/priority.inl,
+ score/inline/rtems/score/stack.inl, score/inline/rtems/score/states.inl,
+ score/inline/rtems/score/sysstate.inl,
+ score/inline/rtems/score/thread.inl,
+ score/inline/rtems/score/threadmp.inl, score/inline/rtems/score/tod.inl,
+ score/inline/rtems/score/tqdata.inl,
+ score/inline/rtems/score/userext.inl,
+ score/inline/rtems/score/watchdog.inl,
+ score/inline/rtems/score/wkspace.inl,
+ score/macros/rtems/score/address.inl,
+ score/macros/rtems/score/chain.inl,
+ score/macros/rtems/score/coremsg.inl,
+ score/macros/rtems/score/coremutex.inl,
+ score/macros/rtems/score/coresem.inl, score/macros/rtems/score/heap.inl,
+ score/macros/rtems/score/isr.inl, score/macros/rtems/score/mppkt.inl,
+ score/macros/rtems/score/object.inl,
+ score/macros/rtems/score/objectmp.inl,
+ score/macros/rtems/score/priority.inl,
+ score/macros/rtems/score/stack.inl, score/macros/rtems/score/states.inl,
+ score/macros/rtems/score/sysstate.inl,
+ score/macros/rtems/score/thread.inl,
+ score/macros/rtems/score/threadmp.inl, score/macros/rtems/score/tod.inl,
+ score/macros/rtems/score/tqdata.inl,
+ score/macros/rtems/score/userext.inl,
+ score/macros/rtems/score/watchdog.inl,
+ score/macros/rtems/score/wkspace.inl, score/src/apiext.c,
+ score/src/chain.c, score/src/coremsg.c, score/src/coremsgbroadcast.c,
+ score/src/coremsgclose.c, score/src/coremsgflush.c,
+ score/src/coremsgflushsupp.c, score/src/coremsgflushwait.c,
+ score/src/coremsginsert.c, score/src/coremsgseize.c,
+ score/src/coremsgsubmit.c, score/src/coremutex.c,
+ score/src/coremutexflush.c, score/src/coremutexseize.c,
+ score/src/coremutexsurrender.c, score/src/coresem.c,
+ score/src/coresemflush.c, score/src/coresemseize.c,
+ score/src/coresemsurrender.c, score/src/coretod.c,
+ score/src/coretodset.c, score/src/coretodtickle.c,
+ score/src/coretodtoseconds.c, score/src/coretodvalidate.c,
+ score/src/heap.c, score/src/heapallocate.c, score/src/heapextend.c,
+ score/src/heapfree.c, score/src/heapgetinfo.c,
+ score/src/heapsizeofuserarea.c, score/src/heapwalk.c,
+ score/src/interr.c, score/src/isr.c, score/src/iterateoverthreads.c,
+ score/src/mpci.c, score/src/object.c, score/src/objectallocate.c,
+ score/src/objectallocatebyindex.c, score/src/objectclearname.c,
+ score/src/objectcomparenameraw.c, score/src/objectcomparenamestring.c,
+ score/src/objectcopynameraw.c, score/src/objectcopynamestring.c,
+ score/src/objectextendinformation.c, score/src/objectfree.c,
+ score/src/objectget.c, score/src/objectgetbyindex.c,
+ score/src/objectgetisr.c, score/src/objectgetnext.c,
+ score/src/objectgetnoprotection.c, score/src/objectidtoname.c,
+ score/src/objectinitializeinformation.c, score/src/objectmp.c,
+ score/src/objectnametoid.c, score/src/objectshrinkinformation.c,
+ score/src/thread.c, score/src/threadchangepriority.c,
+ score/src/threadclearstate.c, score/src/threadclose.c,
+ score/src/threadcreateidle.c, score/src/threaddelayended.c,
+ score/src/threaddispatch.c, score/src/threadevaluatemode.c,
+ score/src/threadget.c, score/src/threadhandler.c,
+ score/src/threadidlebody.c, score/src/threadinitialize.c,
+ score/src/threadloadenv.c, score/src/threadmp.c, score/src/threadq.c,
+ score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c,
+ score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c,
+ score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c,
+ score/src/threadqextract.c, score/src/threadqextractfifo.c,
+ score/src/threadqextractpriority.c, score/src/threadqextractwithproxy.c,
+ score/src/threadqfirst.c, score/src/threadqfirstfifo.c,
+ score/src/threadqfirstpriority.c, score/src/threadqflush.c,
+ score/src/threadqtimeout.c, score/src/threadready.c,
+ score/src/threadreset.c, score/src/threadresettimeslice.c,
+ score/src/threadrestart.c, score/src/threadresume.c,
+ score/src/threadrotatequeue.c, score/src/threadsetpriority.c,
+ score/src/threadsetstate.c, score/src/threadsettransient.c,
+ score/src/threadstackallocate.c, score/src/threadstackfree.c,
+ score/src/threadstart.c, score/src/threadstartmultitasking.c,
+ score/src/threadsuspend.c, score/src/threadtickletimeslice.c,
+ score/src/threadyieldprocessor.c, score/src/userext.c,
+ score/src/watchdog.c, score/src/watchdogadjust.c,
+ score/src/watchdoginsert.c, score/src/watchdogremove.c,
+ score/src/watchdogtickle.c, score/src/wkspace.c,
+ sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/extension.h, sapi/include/rtems/fatal.h,
+ sapi/include/rtems/init.h, sapi/include/rtems/io.h,
+ sapi/include/rtems/mptables.h, sapi/include/rtems/sptables.h,
+ sapi/include/rtems/sptables.h.in, sapi/inline/rtems/extension.inl,
+ sapi/macros/rtems/extension.inl, sapi/src/debug.c, sapi/src/exinit.c,
+ sapi/src/extension.c, sapi/src/extensioncreate.c,
+ sapi/src/extensiondelete.c, sapi/src/extensionident.c, sapi/src/fatal.c,
+ sapi/src/io.c, sapi/src/itronapi.c, sapi/src/posixapi.c,
+ sapi/src/rtemsapi.c, rtems/include/rtems.h,
+ rtems/include/rtems/rtems/asr.h, rtems/include/rtems/rtems/attr.h,
+ rtems/include/rtems/rtems/cache.h, rtems/include/rtems/rtems/clock.h,
+ rtems/include/rtems/rtems/config.h, rtems/include/rtems/rtems/dpmem.h,
+ rtems/include/rtems/rtems/event.h, rtems/include/rtems/rtems/eventmp.h,
+ rtems/include/rtems/rtems/eventset.h, rtems/include/rtems/rtems/intr.h,
+ rtems/include/rtems/rtems/message.h, rtems/include/rtems/rtems/modes.h,
+ rtems/include/rtems/rtems/mp.h, rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/options.h, rtems/include/rtems/rtems/part.h,
+ rtems/include/rtems/rtems/partmp.h, rtems/include/rtems/rtems/ratemon.h,
+ rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/regionmp.h,
+ rtems/include/rtems/rtems/rtemsapi.h, rtems/include/rtems/rtems/sem.h,
+ rtems/include/rtems/rtems/semmp.h, rtems/include/rtems/rtems/signal.h,
+ rtems/include/rtems/rtems/signalmp.h,
+ rtems/include/rtems/rtems/status.h, rtems/include/rtems/rtems/support.h,
+ rtems/include/rtems/rtems/taskmp.h, rtems/include/rtems/rtems/tasks.h,
+ rtems/include/rtems/rtems/timer.h, rtems/include/rtems/rtems/types.h,
+ rtems/inline/rtems/rtems/asr.inl, rtems/inline/rtems/rtems/attr.inl,
+ rtems/inline/rtems/rtems/dpmem.inl, rtems/inline/rtems/rtems/event.inl,
+ rtems/inline/rtems/rtems/eventset.inl,
+ rtems/inline/rtems/rtems/message.inl,
+ rtems/inline/rtems/rtems/modes.inl,
+ rtems/inline/rtems/rtems/options.inl, rtems/inline/rtems/rtems/part.inl,
+ rtems/inline/rtems/rtems/ratemon.inl,
+ rtems/inline/rtems/rtems/region.inl, rtems/inline/rtems/rtems/sem.inl,
+ rtems/inline/rtems/rtems/status.inl,
+ rtems/inline/rtems/rtems/support.inl,
+ rtems/inline/rtems/rtems/tasks.inl, rtems/inline/rtems/rtems/timer.inl,
+ rtems/macros/rtems/rtems/asr.inl, rtems/macros/rtems/rtems/attr.inl,
+ rtems/macros/rtems/rtems/dpmem.inl, rtems/macros/rtems/rtems/event.inl,
+ rtems/macros/rtems/rtems/eventset.inl,
+ rtems/macros/rtems/rtems/message.inl,
+ rtems/macros/rtems/rtems/modes.inl,
+ rtems/macros/rtems/rtems/options.inl, rtems/macros/rtems/rtems/part.inl,
+ rtems/macros/rtems/rtems/ratemon.inl,
+ rtems/macros/rtems/rtems/region.inl, rtems/macros/rtems/rtems/sem.inl,
+ rtems/macros/rtems/rtems/status.inl,
+ rtems/macros/rtems/rtems/support.inl,
+ rtems/macros/rtems/rtems/tasks.inl, rtems/macros/rtems/rtems/timer.inl,
+ rtems/src/attr.c, rtems/src/clockget.c, rtems/src/clockset.c,
+ rtems/src/clocktick.c, rtems/src/dpmem.c, rtems/src/dpmemcreate.c,
+ rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c,
+ rtems/src/dpmemident.c, rtems/src/dpmeminternal2external.c,
+ rtems/src/event.c, rtems/src/eventmp.c, rtems/src/eventreceive.c,
+ rtems/src/eventseize.c, rtems/src/eventsend.c,
+ rtems/src/eventsurrender.c, rtems/src/eventtimeout.c, rtems/src/intr.c,
+ rtems/src/intrbody.c, rtems/src/intrcatch.c, rtems/src/mp.c,
+ rtems/src/msg.c, rtems/src/msgmp.c, rtems/src/msgqallocate.c,
+ rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c,
+ rtems/src/msgqdelete.c, rtems/src/msgqflush.c,
+ rtems/src/msgqgetnumberpending.c, rtems/src/msgqident.c,
+ rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqsubmit.c,
+ rtems/src/msgqtranslatereturncode.c, rtems/src/msgqurgent.c,
+ rtems/src/part.c, rtems/src/partcreate.c, rtems/src/partdelete.c,
+ rtems/src/partgetbuffer.c, rtems/src/partident.c, rtems/src/partmp.c,
+ rtems/src/partreturnbuffer.c, rtems/src/ratemon.c,
+ rtems/src/ratemoncancel.c, rtems/src/ratemoncreate.c,
+ rtems/src/ratemondelete.c, rtems/src/ratemongetstatus.c,
+ rtems/src/ratemonident.c, rtems/src/ratemonperiod.c,
+ rtems/src/ratemontimeout.c, rtems/src/region.c,
+ rtems/src/regioncreate.c, rtems/src/regiondelete.c,
+ rtems/src/regionextend.c, rtems/src/regiongetinfo.c,
+ rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c,
+ rtems/src/regionident.c, rtems/src/regionmp.c,
+ rtems/src/regionreturnsegment.c, rtems/src/rtclock.c,
+ rtems/src/rtemsidtoname.c, rtems/src/rtemstimer.c, rtems/src/sem.c,
+ rtems/src/semcreate.c, rtems/src/semdelete.c, rtems/src/semflush.c,
+ rtems/src/semident.c, rtems/src/semmp.c, rtems/src/semobtain.c,
+ rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c,
+ rtems/src/signal.c, rtems/src/signalcatch.c, rtems/src/signalmp.c,
+ rtems/src/signalsend.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c,
+ rtems/src/taskgetnote.c, rtems/src/taskident.c,
+ rtems/src/taskinitusers.c, rtems/src/taskissuspended.c,
+ rtems/src/taskmode.c, rtems/src/taskmp.c, rtems/src/taskrestart.c,
+ rtems/src/taskresume.c, rtems/src/tasks.c, rtems/src/tasksetnote.c,
+ rtems/src/tasksetpriority.c, rtems/src/taskstart.c,
+ rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c,
+ rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c,
+ rtems/src/taskwakeafter.c, rtems/src/taskwakewhen.c,
+ rtems/src/timercancel.c, rtems/src/timercreate.c,
+ rtems/src/timerdelete.c, rtems/src/timerfireafter.c,
+ rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c,
+ rtems/src/timerident.c, rtems/src/timerreset.c, rtems/src/timerserver.c,
+ rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c,
+ libmisc/cpuuse/cpuuse.c, libmisc/cpuuse/cpuuse.h,
+ libmisc/devnull/devnull.c, libmisc/devnull/devnull.h,
+ libmisc/dummy/dummy.c, libmisc/dumpbuf/dumpbuf.c,
+ libmisc/dumpbuf/dumpbuf.h, libmisc/fsmount/fsmount.c,
+ libmisc/fsmount/fsmount.h, libmisc/serdbg/serdbgio.c,
+ libmisc/serdbg/termios_printk.c, libmisc/stackchk/check.c,
+ libmisc/stackchk/internal.h, libmisc/stackchk/stackchk.h,
+ libmisc/untar/untar.c, libmisc/untar/untar.h,
+ libblock/include/rtems/ide_part_table.h, libblock/src/ata.c,
+ libblock/src/ide_part_table.c, libfs/src/dosfs/dosfs.h,
+ libfs/src/dosfs/fat.h, libfs/src/dosfs/fat_fat_operations.h,
+ libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_dir.c,
+ libfs/src/dosfs/msdos_eval.c, libfs/src/dosfs/msdos_file.c,
+ libfs/src/dosfs/msdos_free.c, libfs/src/dosfs/msdos_fsunmount.c,
+ libfs/src/dosfs/msdos_handlers_dir.c,
+ libfs/src/dosfs/msdos_handlers_file.c, libfs/src/dosfs/msdos_init.c,
+ libfs/src/dosfs/msdos_initsupp.c, libfs/src/dosfs/msdos_misc.c,
+ libfs/src/dosfs/msdos_mknod.c, libfs/src/dosfs/msdos_node_type.c,
+ libfs/src/imfs/deviceio.c, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_chown.c, libfs/src/imfs/imfs_config.c,
+ libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c,
+ libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/imfs_fcntl.c,
+ libfs/src/imfs/imfs_fdatasync.c, libfs/src/imfs/imfs_free.c,
+ libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_getchild.c,
+ libfs/src/imfs/imfs_gtkn.c, libfs/src/imfs/imfs_handlers_device.c,
+ libfs/src/imfs/imfs_handlers_directory.c,
+ libfs/src/imfs/imfs_handlers_link.c,
+ libfs/src/imfs/imfs_handlers_memfile.c, libfs/src/imfs/imfs_init.c,
+ libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c,
+ libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_mount.c,
+ libfs/src/imfs/imfs_ntype.c, libfs/src/imfs/imfs_readlink.c,
+ libfs/src/imfs/imfs_rmnod.c, libfs/src/imfs/imfs_stat.c,
+ libfs/src/imfs/imfs_symlink.c, libfs/src/imfs/imfs_unixstub.c,
+ libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/imfs_unmount.c,
+ libfs/src/imfs/imfs_utime.c, libfs/src/imfs/ioman.c,
+ libfs/src/imfs/linearfile.c, libfs/src/imfs/memfile.c,
+ libfs/src/imfs/miniimfs_init.c, libcsupport/include/chain.h,
+ libcsupport/include/clockdrv.h, libcsupport/include/console.h,
+ libcsupport/include/iosupp.h, libcsupport/include/rtc.h,
+ libcsupport/include/spurious.h, libcsupport/include/timerdrv.h,
+ libcsupport/include/vmeintr.h, libcsupport/include/motorola/mc68230.h,
+ libcsupport/include/rtems/libcsupport.h,
+ libcsupport/include/rtems/libio.h, libcsupport/include/rtems/libio_.h,
+ libcsupport/include/rtems/termiostypes.h,
+ libcsupport/include/sys/termios.h, libcsupport/include/zilog/z8036.h,
+ libcsupport/include/zilog/z8530.h, libcsupport/include/zilog/z8536.h,
+ libcsupport/src/__brk.c, libcsupport/src/__gettod.c,
+ libcsupport/src/__sbrk.c, libcsupport/src/__times.c,
+ libcsupport/src/access.c, libcsupport/src/base_fs.c,
+ libcsupport/src/cfgetispeed.c, libcsupport/src/cfgetospeed.c,
+ libcsupport/src/cfsetispeed.c, libcsupport/src/cfsetospeed.c,
+ libcsupport/src/chdir.c, libcsupport/src/chmod.c,
+ libcsupport/src/chown.c, libcsupport/src/chroot.c,
+ libcsupport/src/close.c, libcsupport/src/ctermid.c,
+ libcsupport/src/dup.c, libcsupport/src/dup2.c, libcsupport/src/eval.c,
+ libcsupport/src/fchdir.c, libcsupport/src/fchmod.c,
+ libcsupport/src/fcntl.c, libcsupport/src/fdatasync.c,
+ libcsupport/src/fpathconf.c, libcsupport/src/fs_null_handlers.c,
+ libcsupport/src/fstat.c, libcsupport/src/fsync.c,
+ libcsupport/src/ftruncate.c, libcsupport/src/getdents.c,
+ libcsupport/src/getpwent.c, libcsupport/src/hosterr.c,
+ libcsupport/src/ioctl.c, libcsupport/src/isatty.c,
+ libcsupport/src/libio.c, libcsupport/src/libio_sockets.c,
+ libcsupport/src/link.c, libcsupport/src/lseek.c,
+ libcsupport/src/lstat.c, libcsupport/src/malloc.c,
+ libcsupport/src/mallocfreespace.c, libcsupport/src/mkdir.c,
+ libcsupport/src/mkfifo.c, libcsupport/src/mknod.c,
+ libcsupport/src/mount.c, libcsupport/src/newlibc.c,
+ libcsupport/src/no_libc.c, libcsupport/src/no_posix.c,
+ libcsupport/src/open.c, libcsupport/src/pathconf.c,
+ libcsupport/src/pipe.c, libcsupport/src/privateenv.c,
+ libcsupport/src/read.c, libcsupport/src/readlink.c,
+ libcsupport/src/rewinddir.c, libcsupport/src/rmdir.c,
+ libcsupport/src/seekdir.c, libcsupport/src/stat.c,
+ libcsupport/src/symlink.c, libcsupport/src/sync.c,
+ libcsupport/src/tcdrain.c, libcsupport/src/tcflow.c,
+ libcsupport/src/tcflush.c, libcsupport/src/tcgetattr.c,
+ libcsupport/src/tcgetprgrp.c, libcsupport/src/tcsendbreak.c,
+ libcsupport/src/tcsetattr.c, libcsupport/src/tcsetpgrp.c,
+ libcsupport/src/telldir.c, libcsupport/src/termios.c,
+ libcsupport/src/termiosinitialize.c, libcsupport/src/truncate.c,
+ libcsupport/src/umask.c, libcsupport/src/unixlibc.c,
+ libcsupport/src/unlink.c, libcsupport/src/unmount.c,
+ libcsupport/src/utime.c, libcsupport/src/write.c,
+ libnetworking/rtems/mkrootfs.c, libnetworking/rtems/mkrootfs.h: URL for
+ license changed.
+ PR 479/rtems_misc
+ * libcsupport/src/malloc.c: Per multiple standards realloc does not free
+ the original memory if the allocation of the requested larger block
+ fails.
+
+2003-09-03 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/msdos_create.c: Remove unused variable warning.
+
+2003-09-02 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/open.c: Fix typo.
+ * libcsupport/src/malloc.c: Remove test define left in.
+
+2003-09-02 Jiri Gaisler <jiri@gaisler.com>
+
+ PR 476/networking
+ * libnetworking/machine/in_cksum.h: Fix in_cksum calculation on SPARC.
+
+2003-09-02 Ilya Alexeev <ilya@continuum.ru>
+
+ PR 472/filesystem
+ src/malloc.c: Need to include apimutex.h when MALLOC_STATS is defined.
+
+2003-08-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/rtems-top.m4: Add RTEMS_API.
+ AC_DEFAULT_PREFIX([/opt/rtems-][RTEMS_API]).
+
+2003-08-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/rtems-debug.m4: Remove.
+ * aclocal/enable-rtems-debug.m4, aclocal/check-rtems-debug.m4: New
+ (Split out from rtems-debug.m4).
+ * automake/local.am: Remove "debug".
+ PR 449/rtems:
+ * posix/src/getegid.c, posix/src/geteuid.c, posix/src/getgid.c,
+ posix/src/getgroups.c, posix/src/getlogin.c, posix/src/getpgrp.c,
+ posix/src/getpid.c, posix/src/getppid.c, posix/src/getuid.c,
+ posix/src/setpgid.c, posix/src/setsid.c: Remove (Moved to
+ ../libcsupport/src).
+ * posix/Makefile.am: Reflect changes above.
+ PR 449/rtems:
+ * libcsupport/src/getegid.c, libcsupport/src/geteuid.c,
+ libcsupport/src/getgid.c, libcsupport/src/getgroups.c,
+ libcsupport/src/getlogin.c, libcsupport/src/getpgrp.c,
+ libcsupport/src/getpid.c, libcsupport/src/getppid.c,
+ libcsupport/src/getuid.c, libcsupport/src/setpgid.c,
+ libcsupport/src/setsid.c: New (Copied from ../posix/src).
+ * libcsupport/src/no_posix: Remove getpid and _getpid_r.
+ * libcsupport/Makefile.am: Reflect changes above.
+
+2003-08-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/fsmount/Makefile.am: Fix path to automake-includes.
+
+2003-08-14 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/mqueuenametoid.c, posix/src/semaphorenametoid.c: Added ID to
+ name lookup service and changed name of id/name translation status code.
+ This propagated to multiple functions. The user API service added was
+ rtems_object_id_to_name().
+ PR 92/rtems
+ * posix/Makefile.am, posix/src/alarm.c, posix/src/psignal.c: Added
+ ualarm() and usleep().
+ * posix/src/ualarm.c, posix/src/usleep.c: New files.
+ * score/Makefile.am, score/include/rtems/score/object.h,
+ score/include/rtems/score/objectmp.h, score/src/objectmp.c,
+ score/src/objectnametoid.c: Added ID to name lookup service and changed
+ name of id/name translation status code. This propagated to multiple
+ functions. The user API service added was rtems_object_id_to_name().
+ * score/src/objectidtoname.c: New file.
+ PR 408/filesystem
+ * score/score/Makefile.am, score/score/include/rtems/score/thread.h:
+ Added sync() service. As part of adding this service, the new RTEMS
+ service rtems_iterate_over_all_threads() was also added. This new
+ service makes it easier to iterate over all the tasks/threads in a
+ system and perform an action on them.
+ * score/score/src/iterateoverthreads.c: New file.
+ * score/ChangeLog: Fixed screwup.
+ * sapi/src/extensionident.c, rtems/Makefile.am, rtems/include/rtems.h,
+ rtems/include/rtems/rtems/status.h, rtems/src/dpmemident.c,
+ rtems/src/msgqident.c, rtems/src/partident.c, rtems/src/ratemonident.c,
+ rtems/src/regionident.c, rtems/src/semident.c, rtems/src/taskident.c,
+ rtems/src/timerident.c: Added ID to name lookup service and changed name
+ of id/name translation status code. This propagated to multiple
+ functions. The user API service added was rtems_object_id_to_name().
+ * rtems/src/rtemsidtoname.c: New file.
+ PR 408/filesystem
+ * libmisc/cpuuse/cpuuse.c: Added sync() service. As part of adding this
+ service, the new RTEMS service rtems_iterate_over_all_threads() was also
+ added. This new service makes it easier to iterate over all the
+ tasks/threads in a system and perform an action on them. This change is
+ to use the new thread iteration service.
+ * libcsupport/Makefile.am: Add fileio to list of interactive tests.
+ * libcsupport/src/sync.c: New (Copied from ../posix/src). New file.
+
+2003-08-13 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/fsmount/.cvsignore: New file.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-08-11 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.ac: Removed duplicate entry.
+
+2003-08-08 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add libmisc/fsmount/Makefile.
+
+2003-08-06 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 435/networking
+ * libnetworking/rtems/rtems_showifstat.c: rtems_showifstat misses
+ printing the netmask.
+
+2003-08-06 Thomas Doerfler<Thomas.Doerfler@imd-systems.de>
+
+ PR 369/filesystem
+ * libmisc/Makefile.am, libmisc/shell/cmds.c, libmisc/wrapup/Makefile.am:
+ sample application to show the use of the DOSFS functions.
+ * libmisc/fsmount/Makefile.am, libmisc/fsmount/README,
+ libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h: New files.
+
+2003-08-05 Till Strauman <strauman@slac.stanford.edu>
+
+ PR 436/rtems_misc
+ * libmisc/monitor/mon-monitor.c: monitor registered commands list
+ manipulation bugs.
+ PR 442/filesystem
+ * libcsupport/src/open.c: file never closed if ftruncate() fails in
+ open().
+
+2003-08-05 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ PR 440/filesystem
+ * libfs/src/dosfs/fat_fat_operations.c: Improve write data speed for
+ DOSFS FAT12/FAT16 systems.
+ PR 439/filesystem
+ * libfs/src/dosfs/fat_file.c: flush temporary buffer when closing files.
+
+2003-08-05 <djc915@mail.usask.ca>
+
+ PR 443/filesystem
+ * libfs/src/imfs/deviceio.c: deviceio.c mishandles return codes.
+
+2003-08-04 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ PR 441/filesystem
+ * libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_create.c,
+ libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_init.c,
+ libfs/src/dosfs/msdos_mknod.c: add rename support to DOSFS.
+
+2003-07-24 Jennifer Averett <jennifer.averett@OARcorp.com>
+
+ PR 434/filesystem
+ * libfs/src/imfs/imfs_init.c, libfs/src/imfs/miniimfs_init.c: Modified
+ to return error code.
+ * libfs/src/imfs/imfs_initsup.c: Modified to set error upon memory
+ failure.
+
+2003-07-18 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 430/rtems
+ * score/include/rtems/score/watchdog.h: _Watchdog_Ticks_since_boot
+ should be a VOLATILE variable.
+ * score/src/watchdoginsert.c: 'restart' algorithm needs to enforce
+ reloading the list head in case a TICK interrupt during ISR_Flash()
+ modified the list. This is achieved by a proper VOLATILE cast. Also
+ _Watchdog_Sync_count++ should be protected by _ISR_Disable (prevent
+ corruption in case ISR calls watchdoginsert).
+ * score/src/watchdogadjust.c: ISR protection added.
+ * score/src/watchdogtickle.c: ISR protection added. NOTE: PowerPC BSPs
+ using the new exception processing MUST BE UPDATED to maintain
+ _ISR_Nest_level. See also PR288 which provides fixes for the affected
+ BSPs distributed with RTEMS.
+
+2003-07-16 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/ChangeLog: Correct format.
+
+2003-07-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Remove '/' after $(DESTDIR).
+ * wrapup/Makefile.am: Remove bogus $(MULTISUBDIR).
+
+2003-07-15 Chris Johns <cjohns@cybertec.com.au>
+
+ PR 431/filesystem
+ * libfs/src/dosfs/msdos.h: MSDOS Volume semaphore timeout is now NO
+ TIMEOUT. MSDOS volume opertations will wait for ever.
+
+2003-07-08 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Merge-in librpc/configure.ac.
+ * Makefile.am: Add librpc to SUBDIRS. Remove @subdirs@.
+ * configure.ac: Merge-in libcsupport/configure.ac.
+ * Makefile.am: Add libcsupport to SUBDIRS.
+ * configure.ac: Merge-in posix/configure.ac. Merge-in
+ itron/configure.ac. Misc. cosmetical changes.
+ * Makefile.am: Add posix, itron to SUBDIRS.
+ * configure.ac: Merge-in libnetworking/configure.ac. Remove "rtems-"
+ from RTEMS_VERSION. Add AC_CHECK_FUNCS([strsep strcasecmp snprintf]).
+ * Makefile.am: Add libmisc to SUBDIRS.
+ * configure.ac: Merge-in libmisc/configure.ac.
+ * Makefile.am: Add libmisc to SUBDIRS.
+ * configure.ac: Merge-in libfs/configure.ac.
+ * Makefile.am: Add libfs to SUBDIRS.
+ * configure.ac: Merge-in libblock/configure.ac.
+ * Makefile.am: Add libblock to SUBDIRS.
+ * configure.ac: Merge-in ada/configure.ac.
+ * Makefile.am: Add ada to SUBDIRS.
+ * itron/configure.ac: Remove (Merged-in into ../configure.ac).
+ * itron/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * itron/src/config.h: New.
+ * posix/configure.ac: Remove (Merged-in into ../configure.ac).
+ * posix/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * posix/src/config.h: New.
+ * score/cpu/Makefile.am: Add DIST_SUBDIRS = $(RTEMS_CPU).
+ * libmisc/configure.ac: Remove (Merged into ../configure.ac).
+ * libmisc/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * libmisc/capture/config.h: New.
+ * libmisc/capture/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/cpuuse/config.h: New.
+ * libmisc/cpuuse/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/devnull/config.h: New.
+ * libmisc/devnull/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/dummy/config.h: New.
+ * libmisc/dummy/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/dumpbuf/config.h: New.
+ * libmisc/dumpbuf/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/monitor/config.h: New.
+ * libmisc/monitor/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/mw-fb/config.h: New.
+ * libmisc/mw-fb/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/rtmonuse/config.h: New.
+ * libmisc/rtmonuse/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/serdbg/config.h: New.
+ * libmisc/serdbg/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/shell/config.h: New.
+ * libmisc/shell/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/stackchk/config.h: New.
+ * libmisc/stackchk/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/untar/config.h: New.
+ * libmisc/untar/Makefile.am: Add config.h. Reflect having merged
+ configure.ac into ../configure.ac.
+ * libmisc/wrapup/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * libmisc/capture/capture-cli.c, libmisc/capture/capture.c,
+ libmisc/cpuuse/cpuuse.c, libmisc/devnull/devnull.c,
+ libmisc/dummy/dummy.c, libmisc/dumpbuf/dumpbuf.c,
+ libmisc/monitor/mon-command.c, libmisc/monitor/mon-config.c,
+ libmisc/monitor/mon-dname.c, libmisc/monitor/mon-driver.c,
+ libmisc/monitor/mon-extension.c, libmisc/monitor/mon-itask.c,
+ libmisc/monitor/mon-manager.c, libmisc/monitor/mon-monitor.c,
+ libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-queue.c,
+ libmisc/monitor/mon-server.c, libmisc/monitor/mon-symbols.c,
+ libmisc/monitor/mon-task.c, libmisc/mw-fb/mw_fb.c,
+ libmisc/mw-fb/mw_uid.c, libmisc/rtmonuse/rtmonuse.c,
+ libmisc/serdbg/serdbg.c, libmisc/serdbg/serdbgio.c,
+ libmisc/serdbg/termios_printk.c, libmisc/shell/cmds.c,
+ libmisc/stackchk/check.c, libmisc/untar/untar.c: Add config-header
+ support.
+ * librpc/configure.ac: Remove (Merged-in into ../configure.ac).
+ * librpc/Makefile.am, librpc/include/Makefile.am,
+ librpc/src/Makefile.am, librpc/src/rpc/Makefile.am,
+ librpc/src/xdr/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * libblock/configure.ac: Remove (Merged into ../configure.ac).
+ * libblock/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * libfs/configure.ac: Remove (Merged-in into ../configure.ac).
+ * libfs/Makefile.am, libfs/src/Makefile.am, libfs/src/dosfs/Makefile.am,
+ libfs/src/imfs/Makefile.am: Reflect having merged configure.ac into
+ ../configure.ac.
+ * libfs/src/dosfs/config.h: New.
+ * libfs/src/dosfs/Makefile.am: Add config.h.
+ * libfs/src/imfsfs/config.h: New.
+ * libfs/src/imfs/Makefile.am: Add config.h. Remove COMMON_C_FILES,
+ DOC_FILES (Unused).
+ * libfs/src/dosfs/fat.c: include config-header "config.h".
+ * libfs/src/dosfs/fat_fat_operations.c, libfs/src/dosfs/fat_file.c,
+ libfs/src/dosfs/msdos_conv.c: Ditto.
+ * libcsupport/configure.ac: Remove (Merged-in into ../configure.ac).
+ * libcsupport/Makefile.am: DOC_FILES = src/TODO src/CASES, Reflect
+ having merged configure.ac into ../configure.ac.
+ * libcsupport/src/config.h: New.
+ * libnetworking/configure.ac: Remove (Merged into ../configure.ac).
+ * libnetworking/Makefile.am, libnetworking/libc/Makefile.am,
+ libnetworking/lib/Makefile.am, libnetworking/wrapup/Makefile.am: Reflect
+ having merged configure.ac into ../configure.ac.
+ * libnetworking/kern/kern_mib.c: Use RTEMS_VERSION to setup osrelease.
+
+2003-07-08 Joel Sherrill <joel@OARcorp.com>
+
+ PR 419/rtems
+ * libcsupport/src/termios.c: Removed warning.
+
+2003-07-07 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/configure.ac: Remove RTEMS_BSP from
+ RTEMS_CHECK_MULTIPROCESSING.
+
+2003-07-07 Joel Sherrill <joel@OARcorp.com>
+
+ PR 417/rtems
+ * score/src/coresemsurrender.c: Correct incorrect check for
+ maximum_count reported by Sergei Organov <osv@topconrd.ru>.
+
+2003-07-03 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20030703.
+
+2003-07-02 Chris Johns <cjohns@cybertec.com.au>
+
+ * libfs/src/dosfs/Makefile.am, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_conv.c, libfs/src/dosfs/msdos_create.c,
+ libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_misc.c: Patch from
+ Victor V. Vengerov <vvv@oktet.ru> to remove Linux code.
+ * libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Comment have been
+ updated.
+ * libcsupport/include/rtems/libio.h, libcsupport/src/termios.c: Add the
+ rtems_termios_bufsize call.
+
+2003-06-13 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/threadloadenv.c: Removed warnings.
+
+2003-06-12 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/objectmp.c, rtems/include/rtems/rtems/msgmp.h,
+ rtems/include/rtems/rtems/partmp.h,
+ rtems/include/rtems/rtems/regionmp.h, rtems/include/rtems/rtems/semmp.h,
+ rtems/src/msgmp.c, rtems/src/partmp.c, rtems/src/regionmp.c,
+ rtems/src/semmp.c: Removed warnings.
+
+2003-06-10 Phil Torre <ptorre@zetron.com>
+
+ PR 411/filesystem
+ * libfs/src/imfs/imfs_unlink.c: Fix bug where renaming a memfile and
+ then unlinking it causes a memory leak.
+
+2003-06-04 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/stackchk/check.c, libblock/src/ide_part_table.c: Removed
+ warnings.
+
+2003-05-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/include/rtems/rtems/types.h: Include stdint.h.
+ * libcsupport/Makefile.am: Conditionally install stdint.h/inttypes.h.
+ * libcsupport/configure.ac: Check for system-stdint.h/inttypes.h.
+
+2003-05-29 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/rtems/rtems_syscall.c: Removed warnings.
+
+2003-05-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 409/core
+ * include/Makefile.am: Add rtems/stdint.h.
+ * include/rtems/stdint.h: New.
+ PR 321/bsps
+ * aclocal/env-rtemscpu.m4: Remove support for profile-variant.
+ * automake/compile.am, automake/local.am: Ditto.
+ PR 409:
+ * rtems/include/rtems/rtems/types.h: Include rtems/stdint.h. Apply
+ c99-types to typedef rtems_[un]signed[8|16|32|64].
+ PR 409:
+ * libcsupport/include/stdint.h: Include rtems/stdint.h.
+
+2003-05-15 cjohns@cybertec.com.au <cjohns@cybertec.com.au>
+
+ * libnetworking/netinet/in.h: PR406 - Added INET_ADDRSTRLEN per the
+ SUSv3 standard.
+
+2003-05-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Remove LIBSUFFIX_VA (unused).
+
+2003-05-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/env-rtemscpu.m4: Merge-in env-rtemsbsp.m4.
+ * aclocal/env-rtemsbsp.m4, aclocal/enable-rtemsbsp.m4: Remove.
+ * aclocal/env-rtemscpu.m4: Remove stray '/' in setting up
+ project_libdir.
+
+2003-04-17 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ PR 399/rtems_misc
+ * libcsupport/src/termios.c: In canonical mode, when input is present in
+ the input buffer that contains an EOL character and some following
+ characters, a read call read data behind the EOL character, although it
+ should stop reading with the EOL character.
+
+2003-04-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/dummy/Makefile.am: Remove stray dummy.rel.
+ * libcsupport/src/no_posix.c: include <reent.h> instead of <sys/reent.h>.
+
+2003-04-17 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20030417.
+
+2003-04-16 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 389/rtems
+ * libcsupport/src/no_posix.c: Correct _kill_r() prototype and make it
+ conditional on newlib.
+
+2003-04-15 Joel Sherrill <joel@OARcorp.com>
+
+ PR 388/networking
+ * libnetworking/kern/kern_sysctl.c: Revert previous patch and use
+ strlcpy() now that it is available. Also fixed some warnings.
+
+2003-04-11 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20020411.
+
+2003-04-03 Eri Valette <eric.valette@free.fr>
+
+ PR 381/core
+ * libcsupport/src/newlibc.c: Switch from using _REENT_INIT to
+ _REEINT_INIT_PTR to fix strange run-time problem where EIP was corrupted
+ on pc386 BSP.
+
+2003-03-27 Joel Sherrill <joel@OARcorp.com>
+
+ * libblock/Makefile.am: ATA code depends upon libchip/ide which is not
+ allowed in the cpukit source code since it must be buildable independent
+ of any BSP. These files were moved to libchip/ide.
+ * libblock/include/rtems/ata.h, libblock/include/rtems/ata_internal.h,
+ libblock/src/ata.c: Removed.
+ * libnetworking/kern/kern_sysctl.c: Converted from BSP strlcpy() to
+ strncpy().
+
+2003-03-25 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ PR 367/filesystem
+ * libblock/Makefile.am, libblock/include/rtems/ide_part_table.h,
+ libblock/src/ata.c, libblock/src/ide_part_table.c: Some bugs were still
+ present in the DOSFS implementation: - FAT12 did not work properly on
+ Big-Endian machines - Some synchronization and error handling problems
+ were present - Some legal codings for EOC were not recognized.
+ PR 367/filesystem
+ * libfs/src/dosfs/Makefile.am, libfs/src/dosfs/fat.c,
+ libfs/src/dosfs/fat.h, libfs/src/dosfs/fat_fat_operations.c,
+ libfs/src/dosfs/fat_file.c, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_dir.c: Some bugs were still present in the DOSFS
+ implementation: - FAT12 did not work properly on Big-Endian machines. -
+ Some synchronization and error handling problems were present. - Some
+ legal codings for EOC were not recognized.
+
+2003-03-25 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/rtems/rtems_bsdnet_malloc_starvation.c: Fixed name of
+ include file.
+
+2003-03-18 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 356/bsps
+ * score/src/threadhandlerc: This patch makes RTEMS/PowerPC eabi
+ compliant. Let Thread_Handler verify that _init/_main are non-NULL
+ before calling them (gives the linker script/user more freedom to handle
+ special cases).
+ PR 356/bsps
+ * libnetworking/sys/linker_set.h: This patch makes RTEMS/PowerPC eabi
+ compliant. Declare all linker-script defined addresses as variables of
+ unknown size and not as short objects like 'int', 'void*' etc. Since
+ only addresses are used and never those variable's values, the type used
+ in a declaration is not important.
+
+2003-03-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libcsupport/configure.ac: AC_CHECK_FUNCS(strlcpy strlcat).
+ * libcsupport/src/strlcat.c, libcsupport/src/strlcpy.c: New (extracted
+ from pppd/utils.c).
+ * libcsupport/Makefile.am: Add BSD_C_FILES, strlcat.c, strlcpy.c.
+
+2003-03-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Remove '/' after $(DESTDIR) to work around Cygwin
+ mistreating paths.
+
+2003-03-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Reflect changes to project_libdir.
+ * aclocal/env-rtemscpu.m4: Remove obsolete comment. Add MULTISUBDIR to
+ project_libdir.
+ * aclocal/env-rtemscpu.m4: Remove RTEMS_ROOT (Unused).
+ * aclocal/env-rtemsbsp.m4: Remove RTEMS_ROOT (Unused). Remove
+ RTEMS_PROJECT_ROOT (Unused).
+ * aclocal/tool-paths.m4: Delete.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+ * aclocal/rtems-top.m4: Add AC_CONFIG_AUX_DIR.
+ * configure.ac: AC_PREREQ(2.57).
+ * configure.ac: Remove sptables.h.in.
+ * itron/configure.ac: Remove AC_CONFIG_AUX_DIR.
+ * sapi/Makefile.am: Remove stray reference to sptables.h.in.
+ * sapi/include/rtems/sptables.h: New.
+ * sapi/include/rtems/sptables.h.in, sapi/include/.cvsignore,
+ sapi/include/rtems/.cvsignore, sapi/inline/.cvsignore,
+ sapi/inline/rtems/.cvsignore, sapi/macros/.cvsignore,
+ sapi/macros/rtems/.cvsignore, sapi/src/.cvsignore: Remove.
+ * libmisc/configure.ac, libblock/configure.ac, libfs/configure.ac,
+ libcsupport/configure.ac, libnetworking/configure.ac: Remove
+ AC_CONFIG_AUX_DIR.
+ * libnetworking/netinet/in_chksum.c: Remove duplicate case to include
+ in_chksum_arm.c.
+
+2003-02-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_SUBST(RTEMS_VERSION). AC_DEFINE(RTEMS_VERSION)
+ to propagate it through cpuopts.h.
+ * sapi/include/rtems/sptables.h.in: Remove RTEMS_VERSION (Moved to
+ cpuopts.h).
+
+2003-02-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: AC_SUBST(RTEMS_VERSION,_RTEMS_VERSION).
+
+2003-02-20 Wolfram Wadepohl <W.Wadepohl@indumat.de>
+
+ PR 357/rtems_misc
+ * libcsupport/src/termios.c (rtems_termios_open): Fixed code the
+ incorrectly checked that the wrong pointer during allocation was NULL.
+
+2003-02-20 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 351/networking
+ * libnetworking/nfs/bootp_subr.c: Fix ridiculous leak in bootp and use
+ strdup_bootp_realloc() everywhere for sake of consistency.
+
+2003-02-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/gcc-isystem.m4: New.
+ * aclocal/gcc-specs.m4: Remove.
+ * aclocal/prog-cc.m4: Remove RTEMS_GCC_SPECS. Add RTEMS_GCC_ISYSTEM.
+ Reformat setting up RTEMS_CPPFLAGS.
+ * automake/local.am: Introduce depend-gcc. Remove ${ARCH}.
+ * automake/compile.am: Remove GCCSPECS, GCC_SPECS, CONFIG.CC, CC, CPP.
+ Add ${ARCH}. depend-gcc.
+ * aclocal/prog-cc.m4: Set up RTEMS_CPPFLAGS.
+ * aclocal/env-rtemscpu.m4: Remove GCC_SPECS.
+ * aclocal/env-rtemsbsp.m4: Remove GCC_SPECS. capture/capture-cli.c: Add
+ proper definition to avoid compiler warnings. Apply int = getchar().
+ * libcsupport/src/privateenv.c: Fix prototype for free_user_env.
+
+2003-02-14 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 352/rtems_misc
+ * libmisc/shell/shell.c: make rtems_shell main task an FP enabled task.
+
+2003-02-14 Joel Sherrill <joel@OARcorp.com>
+
+ AMD a29k declared obsolete.
+ * score/cpu/Makefile.am: Removed reference.
+ * score/cpu/a29k/.cvsignore, score/cpu/a29k/ChangeLog,
+ score/cpu/a29k/Makefile.am, score/cpu/a29k/amd.ah, score/cpu/a29k/asm.h,
+ score/cpu/a29k/configure.ac, score/cpu/a29k/cpu.c,
+ score/cpu/a29k/cpu_asm.S, score/cpu/a29k/pswmacro.ah,
+ score/cpu/a29k/register.ah, score/cpu/a29k/sig.S,
+ score/cpu/a29k/rtems/.cvsignore, score/cpu/a29k/rtems/score/.cvsignore,
+ score/cpu/a29k/rtems/score/a29k.h, score/cpu/a29k/rtems/score/cpu.h,
+ score/cpu/a29k/rtems/score/cpu_asm.h,
+ score/cpu/a29k/rtems/score/types.h: Removed.
+
+2003-02-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/canonical-target-name.m4: Transform tic4x -> RTEMS_CPU=c4x.
+
+2003-02-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * itron/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * itron/configure.ac: AC_PREREQ(2.57).
+ * posix/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * posix/configure.ac: AC_PREREQ(2.57).
+ * librpc/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * librpc/configure.ac: AC_PREREQ(2.57).
+ * libblock/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * libblock/configure.ac: AC_PREREQ(2.57).
+ * libfs/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * libfs/configure.ac: AC_PREREQ(2.57).
+ * libcsupport/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * libcsupport/configure.ac: AC_PREREQ(2.57).
+ * libnetworking/configure.ac: AM_INIT_AUTOMAKE([1.7.2]).
+ * libnetworking/configure.ac: AC_PREREQ(2.57).
+
+2003-02-11 Mike Siers <mikes@poliac.com>
+
+ * libnetworking/rtems/rtems_glue.c: A small patch to the network daemon
+ task code. I just added code to check the return value of the
+ rtems_bsdnet_event_receive function. Only when this function returns a
+ SUCCESSFUL status, will the event flags be checked. This is more of a
+ code cleanup issue than a bug. The patch will just ensure the ipintr()
+ and arpintr() functions are only called when a event is signaled.
+
+2003-02-06 Mike Siers <mikes@poliac.com>
+
+ PR 342/networking
+ * libnetworking/kern/uipc_mbuf.c: The RTEMS version of the m_copyback is
+ changing the m_len value of the mbuf. I looked into the source from
+ another BSD system and the mbuf length is not changed inside this
+ function. The m_copyback function is only being used in the
+ net/rtsock.c file. So I think this problem is only visable under
+ certain routing table conditions.
+
+2003-02-06 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/include/sys/ioccom.h: Include <sys/types.h> not
+ <machine/types.h> so Linux port builds.
+
+2003-02-05 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 340/filesystem
+ * libcsupport/src/fcntl.c: Add missing _fcntl_r assumed to exist by
+ newlib.
+
+2003-02-05 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ PR 341/networking
+ * libnetworking/lib/ftpfs.c: Account for NULL at end of strings when
+ malloc()'ing memory.
+
+2003-02-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/include/sys/ioccom.h: Fix so not using internal RTEMS
+ types in libc code.
+
+2003-02-03 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 339/filesystem
+ * libcsupport/src/chroot.c: Fix violation of FS node object copy
+ semantics.
+
+2003-02-03 Steven Johnson <sjohnson@neurizon.net>
+
+ PR 338/filesystem
+ * libfs/src/imfs/ioman.c: Fix reentrancy problem with
+ rtems_io_lookup_name() (API change).
+
+2003-02-03 Joel Sherrill <joel@OARcorp.com>
+
+ PR 338/filesystem
+ * sapi/include/rtems/io.h, sapi/src/io.c: Side-effect of fixing
+ reentrancy problem with rtems_io_lookup_name() (API change).
+ PR 338/filesystem
+ * libcsupport/src/unixlibc.c: Side-effect of fixing reentrancy problem
+ with rtems_io_lookup_name() (API change).
+
+2003-01-28 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20030128.
+ * libnetworking/Makefile.am: Add kern/kern_sysctl.c to Makefile.am so
+ networking tests build. This was subsequently reported as PR337 before I
+ committed the fix.
+
+2003-01-27 Till Straumann <strauman@SLAC.Stanford.edu>
+
+ * libnetworking/libc/getproto.c, libnetworking/libc/getprotoname.c:
+ modification to call getprotoent_static() if fopen() on /etc/protocols
+ fails.
+
+2003-01-27 Juan Zamorano <jzamora@fi.upm.es>
+
+ * posix/src/ptimer1.c: Correct problem which could lead to overflow in
+ time math.
+
+2003-01-27 Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+
+ * libblock/src/blkdev.c: Per PR331 fix bug which is tripped by writing
+ 512 byte blocks to 512 byte aligned positions.
+
+2003-01-27 Dan Smisko <dan@balanced.com>
+
+ * libmisc/stackchk/check.c: Fix problem where _Objects_Get_information()
+ will dereference a null pointer when checking the interrupt stack. If
+ there's something at 0, you may be ok at run time but it is wrong.
+ * libmisc/monitor/mon-command.c: Correct two potential NULL references.
+
+2003-01-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/local.am: Remove distclean-local. Remove PROJECT_TOOLS.
+
+2003-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Remove CLEAN_DEPEND (Unused). Remove
+ CLOBBER_DEPEND (Unused).
+
+2003-01-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/netinet/tcp_subr.c, libnetworking/netinet/udp_usrreq.c:
+ Add args to INP_INFO_RLOCK, INP_INFO_RUNLOCK, INP_LOCK, INP_UNLOCK
+ macros.
+
+2003-01-10 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libcsupport/Makefile.am: Eliminate OBJS.
+
+2003-01-10 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/objectmp.c: Corrected use of name parameter to reflect that
+ it is actually the name not a pointer to the name.
+ * rtems/src/msg.c, rtems/src/part.c, rtems/src/sem.c, rtems/src/tasks.c:
+ Correct object class control structure initialization for
+ multiprocessing configurations.
+ * libcsupport/include/rtems/libio.h: Rename __dev_t to __rtems_dev_t to
+ avoid conflict with GNU/Linux header files.
+
+2003-01-03 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 303
+ * libcsupport/src/base_fs.c, libcsupport/src/getpwent.c,
+ libcsupport/src/privateenv.c: Fix violation of node_access copy
+ symantics.
+
+2003-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/ChangeLog: Corrected entry for sysconf.c which did not include
+ PR.
+
+2003-01-03 Jitendra Vegiraju <jvegiraju@netscape.net>
+
+ * libnetworking/sys/queue.h: Fix alignment problem on ARM.
+
+2003-01-03 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * posix/src/mqueueopen.c: Actually open the message queue descriptor so
+ it is available for others to use.
+
+2003-01-03 Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+
+ * libblock/src/ata.c, libblock/src/bdbuf.c: Correct invocation of
+ rtems_task_mode() so the task's preemption mode setting is properly
+ maintained.
+ * libfs/src/dosfs/msdos_initsupp.c: Specify inherited priority as 0
+ since this is a FIFO queuing semaphore.
+
+2003-01-03 Chris Johns <cjohns@cybertec.com.au>
+
+ * libnetworking/Makefile.am: Added sys/linker_set.h.
+ * libnetworking/kern/Makefile.am: Added kern_mib.c and kern_sysctl.c.
+ * libnetworking/kern/uipc_socket.c: OID changed from KERN_SOMAXCONN to
+ KIPC_SOMAXCONN.
+ * libnetworking/kern/uipc_socket2.c: OID changed from KERN_MAXSOCKBUF to
+ KIPC_MAXSOCKBUF.
+ * libnetworking/net/if_ethersubr.c: FreeBSD 2.2.2 does not have a
+ _net_link node while 5.0 does.
+ * libnetworking/net/if_ppp.c: Removed the TEXT_SET define as these
+ macros are now implemented.
+ * libnetworking/net/rtsock.c: Enable sysctl support plus fix the bug
+ with the lastest FreeBSD sysctl header file.
+ * libnetworking/netinet/icmp_var.h: FreeBSD 2.2.2 does not have a
+ _net_inet_icmp node while 5.0 does.
+ * libnetworking/netinet/if_ether.c: FreeBSD 2.2.2 does not have a
+ _net_link_ether node while 5.0 does.
+ * libnetworking/netinet/igmp_var.h: FreeBSD 2.2.2 does not have a
+ _net_inet_igmp node while 5.0 does.
+ * libnetworking/netinet/in_pcb.c: Fixed the arguments to the sysctl
+ call. Add inp_gencnt and ipi_count. These are used when listing
+ connections.
+ * libnetworking/netinet/in_pcb.h: Added counters to aid the listing of
+ connections.
+ * libnetworking/netinet/in_var.h: Provide the _net_inet_ip and
+ _net_inet_raw nodes.
+ * libnetworking/netinet/ip_fw.c: Disable the firewall sysctl calls.
+ * libnetworking/netinet/tcp_subr.c: Merge tcp_pcblist from the lastest
+ FreeBSD source.
+ * libnetworking/netinet/tcp_var.h: Add structures needed by net-snmp to
+ list connections.
+ * libnetworking/netinet/udp_usrreq.c: Merged udp_pcblist from the
+ lastest FreeBSD source.
+ * libnetworking/netinet/udp_var.h: Added the sysctl id UDPCTL_PCBLIST.
+ Used by net-snmp.
+ * libnetworking/rtems_glue.c: Call sysctl_register_all when initialising
+ the network stack to register all the sysctl calls. These are in the
+ special sections and required an updated linker script.
+ * libnetworking/rtems/rtems_syscall.c: Add the sysctl call.
+ * libnetworking/sys/kernel.h: Use the lastest FreeBSD method of handling
+ sysctl structures. This now held in the sys/linker_set.h file.
+ * libnetworking/sys/queue.h: This is from the lastest FreeBSD code with
+ the circular code merged back in as it is not used in the lastest
+ FreeBSD kernel.
+ * libnetworking/sys/sysctl.h: The lastest sysctl. This was needed to use
+ with the new linker set method. The FreeBSD 2.2.2 version has asm hacks.
+ The lastest version of the FreeBSD does not have these hacks. It uses
+ gcc attribute directives.
+
+2002-12-26 Till Straumann <strauman@slac.stanford.edu
+
+ * libcsupport/src/fchdir.c: PR302 fix violation of FS node object copy
+ semantics.
+
+2002-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Remove $(RTEMS_BSP_CFLAGS).
+
+2002-12-18 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/Makefile.am: Include netinet sources.
+
+2002-12-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Fix path to libxdr and librpc (Another typo in
+ from the 2002-12-12 patch).
+
+2002-12-13 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Fix typo in yesterday's patch.
+
+2002-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Don't create $ARCH. Use install-data-local to
+ install librtemscpu.a.
+ * wrapup/Makefile.am: Add libmisc.
+ * configure.ac: Add AC_CONFIG_SUBDIR(libmisc).
+ * itron/Makefile.am, posix/Makefile.am: Don't create $ARCH as
+ side-effect of compilation.
+ * score/Makefile.am: Don't create $ARCH.
+ * sapi/Makefile.am: Don't create $ARCH as side-effect of compilation.
+ * rtems/Makefile.am: Don't create $ARCH as side-effect of compilation.
+ Re-order all-local.
+ * libmisc/configure.ac: Require autoconf-2.57+automake-1.7.2.
+ * libmisc/capture/Makefile.am: Eliminate C_O_FILES.
+ * libmisc/cpuuse/Makefile.am, libmisc/devnull/Makefile.am,
+ libmisc/dummy/Makefile.am, libmisc/dumpbuf/Makefile.am,
+ libmisc/monitor/Makefile.am, libmisc/rtmonuse/Makefile.am,
+ libmisc/serdbg/Makefile.am, libmisc/shell/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am: Ditto.
+ * libmisc/mw-fb/Makefile.am: Eliminate C_O_FILES. Eliminate SRCS. Moving
+ libmisc from rtems/c/src to rtems/cpukit.
+ * libmisc/Makefile.am: Reflect new path.
+ * libmisc/configure.ac: Reflect new path. Use RTEMS_ENV_RTEMSCPU
+ instead of RTEMS_ENV_RTEMSBSP. Remove RTEMS_PROJECT_ROOT.
+ * libmisc/capture/Makefile.am: Reflect new path. Remove OBJS from
+ all-local.
+ * libmisc/cpuuse/Makefile.am, libmisc/devnull/Makefile.am,
+ libmisc/dummy/Makefile.am, libmisc/dumpbuf/Makefile.am,
+ libmisc/monitor/Makefile.am, libmisc/mw-fb/Makefile.am,
+ libmisc/rtmonuse/Makefile.am, libmisc/serdbg/Makefile.am,
+ libmisc/shell/Makefile.am, libmisc/stackchk/Makefile.am,
+ libmisc/untar/Makefile.am: Ditto.
+ * libmisc/wrapup/Makefile.am: Reflect new path.
+ * libblock/Makefile.am: Eliminate C_O_FILES. Eliminate SRCS.
+ * libfs/src/imfs/Makefile.am: Eliminate C_O_FILES.
+ * libfs/src/dosfs/Makefile.am: Ditto.
+ * libnetworking/Makefile.am: Merge-in kern/Makefile.am, net/Makefile.am,
+ netinet/Makefile.am, netinet/Makefile.am, nfs/Makefile.am,
+ rtems/Makefile.am.
+ * libnetworking/kern/Makefile.am, libnetworking/net/Makefile.am,
+ libnetworking/netinet/Makefile.am, libnetworking/nfs/Makefile.am,
+ libnetworking/rtems/Makefile.am: Remove.
+ * libnetworking/wrapup/Makefile.am: Reflect changes above.
+ * libnetworking/configure.ac: Ditto.
+
+2002-12-11 Vladimir Nesic <vnesic@dkts.co.yu>
+
+ * posix/src/cancelrun.c, posix/src/cleanuppop.c: Get the last real node
+ not the permanent null last node.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/kern/Makefile.am: Remove C_O_FILES. Don't let all-local
+ depend on $OBJS).
+ * libnetworking/lib/Makefile.am, libnetworking/libc/Makefile.am,
+ libnetworking/net/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/nfs/Makefile.am, libnetworking/rtems/Makefile.am: Ditto.
+
+2002-12-10 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/configure.ac: Remove RTEMS_CHECK_CUSTOM_BSP.
+ * libmisc/capture/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dummy/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/monitor/Makefile.am,
+ libmisc/mw-fb/Makefile.am, libmisc/rtmonuse/Makefile.am,
+ libmisc/serdbg/Makefile.am, libmisc/shell/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am,
+ libmisc/wrapup/Makefile.am: Don't include @RTEMS_BSP@.cfg.
+
+2002-12-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/env-rtemsbsp.m4, aclocal/env-rtemscpu.m4: Remove
+ RTEMS_CHECK_CUSTOM_BSP.
+ * aclocal/check-bsps.m4: Remove.
+ * wrapup/Makefile.am: Remove *_OBJS, use LIBS+= instead.
+ * configure.ac: Require autoconf >= 2.54, automake-1.7.2.
+ * wrapup/Makefile.am, configure.ac: Reflect changes to score/.
+ * wrapup/Makefile.am, configure.ac: Reflect changes to sapi/.
+ * configure.ac: Add AC_SUBST(INLINEdir).
+ * wrapup/Makefile.am, configure.ac: Reflect changes to rtems/.
+ * wrapup/Makefile.am: Reflect changes to posix/. Reflect changes to
+ itron/.
+ * itron/include/Makefile.am, itron/inline/Makefile.am,
+ itron/macros/Makefile.am, itron/src/Makefile.am: Remove.
+ * itron/Makefile.am: Merge-in removed Makefile.ams.
+ * itron/configure.ac: Reflect changes above.
+ * posix/include/Makefile.am, posix/inline/Makefile.am,
+ posix/macros/Makefile.am, posix/src/Makefile.am: Remove.
+ * posix/Makefile.am: Merge-in removed Makefile.ams.
+ * posix/configure.ac: Reflect changes above.
+ * score/Makefile.am: Fix macro-file installation.
+ * score/Makefile.am: Move include/rtems/score/cpuopts.h to STD_H_FILES.
+ * score/include/Makefile.am, score/inline/Makefile.am,
+ score/macros/Makefile.am, score/src/Makefile.am: Remove.
+ * score/Makefile.am: Merge-in removed Makefile.ams.
+ * sapi/include/Makefile.am, sapi/inline/Makefile.am,
+ sapi/macros/Makefile.am, sapi/src/Makefile.am: Remove.
+ * sapi/Makefile.am: Merge-in removed Makefile.ams.
+ * rtems/include/Makefile.am, rtems/inline/Makefile.am,
+ rtems/macros/Makefile.am, rtems/src/Makefile.am: Remove.
+ * rtems/Makefile.am: Merge-in removed Makefile.ams.
+
+2002-12-06 Vladimir Nesic <vnesic@dkts.co.yu>
+
+ * posix/inline/rtems/posix/cond.inl, posix/macros/rtems/posix/cond.inl:
+ Implemented PTHREAD_COND_INITIALIZER support. Vladimir implemented the
+ inline version and Joel adapted it to the macro version.
+
+2002-12-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Rework *FLAGS, AM_*FLAGS handling.
+ * automake/multilib.am: Don't include @RTEMS_BSP@.cfg.
+ * automake/compile.am: Remove hard-coded CFLAGS_PROFILE_V. Add
+ autoconf-supplied CPU_CFLAGS, CFLAGS_OPTIMIZE_V, CFLAGS_DEBUG_V,
+ CFLAGS_PROFILE_V. Hard-code RTEMS_CFLAGS_PROFILE = -pg.
+ * aclocal/prog-cc.m4: Sync with toplevel/aclocal/prog-cc.m4. Remove
+ GCCSED.
+ * aclocal/env-rtemsbsp.m4: Add AC_ARG_VAR for CPU_CFLAGS,
+ CFLAGS_OPTIMIZE_V, CFLAGS_DEBUG_V, CFLAGS_PROFILE_V.
+ * aclocal/rtems-flags.m4: New.
+ * libcsupport/configure.ac: Add various checks to enhance portability.
+ * libcsupport/src/termios.c: Reflect changes to configure.ac.
+
+2002-12-06 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/malloc.c: Fixed code that incorrected did a disable
+ dispatch instead of locking and unlocking the allocator mutex.
+
+2002-12-02 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/include/rtems/posix/timer.h, posix/src/keygetspecific.c,
+ posix/src/posixtimespecsubtract.c, posix/src/ptimer1.c,
+ posix/src/semunlink.c: Added casts to eliminate warnings on 16-bit
+ targets like the h8300.
+ * score/include/rtems/score/object.h, score/include/rtems/score/tod.h,
+ rtems/include/rtems/rtems/support.h: Added casts to eliminate warnings
+ on 16 bit targets like the h8300.
+ * libmisc/stackchk/check.c: Better handling of task name.
+ * libblock/src/bdbuf.c: Added cast to remove warning.
+ * libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos.h: Added casts to remove
+ warnings on 16 bit targets like the h8300.
+ * libcsupport/include/rtems/libio.h: Internally use a union of an
+ unsigned64 and major/minor device so we don't get into trouble shifting.
+ The h8300 seemed to be impossible to remove warnings otherwise.
+ Eventually the structure definition of a dev_t might be better anyway.
+ * libcsupport/include/sys/ioccom.h: Added casts to remove warnings on 16
+ bit targets.
+
+2002-11-29 Eric Norum <eric.norum@usask.ca>
+
+ PR 316
+ * posix/src/sysconf.c: Add support for _SC_GETPW_R_SIZE_MAX. Return
+ error rather than panic if argument is unsupported.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Remove CFLAGS_DEBUG_OPTIMIZE_V (Unused).
+ * aclocal/sysv-ipc.m4: Adaptation to autoconf-2.5x.
+ * aclocal/check-newlib.m4: Sync with ../aclocal/check-newlib.m4.
+ * itron/configure.ac: Cosmetical fixes.
+ * itron/configure.ac: Fix package name.
+ * posix/configure.ac: Cosmetical fixes.
+ * posix/configure.ac, librpc/configure.ac, libblock/configure.ac: Fix
+ package name.
+ * libfs/configure.ac: Cosmetical fixes.
+ * libfs/configure.ac: Fix package name.
+ * libcsupport/configure.ac: Cosmetical fixes.
+ * libcsupport/configure.ac, libnetworking/configure.ac: Fix package name.
+
+2002-11-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * include/rtems/libio_.h: Remove.
+ * libcsupport/configure.ac: Check for sys/cdefs.h, Add NEED_SYS_CDEFS_H.
+ Add check for CHAR_BIT.
+ * libcsupport/Makefile.am: Conditionally install sys/cdefs.h iff using
+ newlib or if the host does not provide sys/cdefs.h (Fixes Linux/posix).
+ * libcsupport/configure.ac: Remove -ansi -fasm. Add checks to diagnose
+ potential system header conflicts.
+ * libcsupport/Makefile.am: Unconditionally install sys/cdefs.h.
+ * libnetworking/Makefile.am: Merge-in HEADER-handling from
+ net/Makefile.am, netinet/Makefile.am, nfs/Makefile.am.
+ * libnetworking/net/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/nfs/Makefile.am: Remove *_HEADERS.
+
+2002-11-18 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20021118.
+
+2002-11-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * include/rtems/userenv.h: Rely upon <limits.h> for
+ _POSIX_LOGIN_NAME_MAX.
+ * aclocal/prog-cc.m4: Acknowledge configuration-time CFLAGS.
+ * automake/compile.am: Acknowledge configuration-time CFLAGS. Remove
+ CFLAGS_DEFAULT.
+ * libmisc/monitor/mon-commands.c: Removed warnings for RTEMS_UNIX.
+ * libblock/src/diskdevs.c: Include <unistd.h> to remove warning.
+ * libnetworking/Makefile.am: Merge-in arpa/Makefile.am,
+ machine/Makefile.am, sys/Makefile.am, vm/Makefile.am. Add . to SUBDIRS.
+ * libnetworking/arpa/Makefile.am, libnetworking/machine/Makefile.am,
+ libnetworking/sys/Makefile.am, libnetworking/vm/Makefile.am: Remove.
+ * libnetworking/configure.ac: Reflect changes above.
+
+2002-11-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/capture/Makefile.am, libmisc/serdbg/Makefile.am: Remove
+ AUTOMAKE_OPTIONS.
+ * libmisc/serdbg/serdbgio.c: Add #include <unistd.h>.
+ * libmisc/shell/Makefile.am, libmisc/wrapup/Makefile.am: Add
+ RTEMS_LIBSHELL conditional.
+ * libmisc/configure.ac: Check for stdio assignments. Add RTEMS_LIBSHELL
+ conditional.
+
+2002-11-14 Joel Sherrill <joel@OARcorp.com>
+
+ * score/macros/rtems/score/object.inl: Keep consistent with inline
+ version.
+
+2002-11-13 Paul Whitfield <paulw@microsol.iinet.net.au>
+
+ * rtems/src/regionreturnsegment.c: When RTEMS_REGION_SHRED_ON_FREE is
+ set, there should have been an & in front of size.
+
+2002-11-11 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20021111.
+
+2002-11-07 <strauman@slac.stanford.edu>
+
+ * libcsupport/src/mount.c: Per PR297, correct fs_mountme failure paths.
+
+2002-11-06 Chris Johns <ccj@acm.org>
+
+ * libnetworking/sys/select.h: Add C++ to C external.
+
+2002-11-04 Joel Sherrill <joel@OARcorp.com>
+
+ * librpc/src/rpc/pmap_rmt.c: Removed warnings.
+
+2002-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/kern/uipc_mbuf.c: Comment out m0 in m_copydata to
+ suppress warning.
+
+2002-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog, posix/ChangeLog: Corrected.
+ * libmisc/stackchk/check.c: Removed warnings.
+ * libcsupport/ChangeLog, libnetworking/ChangeLog: Corrected.
+
+2002-11-01 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/nfs/bootp_subr.c, libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/rtems_glue.c: Till Straumann's patch (PR295) to use
+ bootp option 129 to get command line string. Till Straumann's patch to
+ change inet_ntoa->inet_ntop.
+
+2002-10-31 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/heapgetinfo.c: Fixed comment.
+ * score/src/mpci.c: Removed warning.
+ * rtems/src/regiongetinfo.c: Corrected return value check.
+ * libmisc/stackchk/check.c: Removed warning.
+ * librpc/src/rpc/svc_run.c: Remove warning.
+ * libcsupport/src/mallocfreespace.c: Corrected sense of status check to
+ match change inside RTEMS.
+ * libcsupport/src/newlibc.c: Removed warning.
+ * libnetworking/libc/rcmd.c, libnetworking/netinet/in_cksum_arm.c:
+ Removed warnings.
+
+2002-10-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/check-bsp-cache.m4: Remove.
+
+2002-10-30 Eric Norum <eric.norum@usask.ca>
+
+ * include/rtems/bspIo.h: Add vprintk function for kernel printing from
+ routines which have already obtained the va_list pointer.
+ * posix/src/psignal.c: Fix counting problem which resulted in too many
+ entries being in the POSIX signals default behavior table.
+ * posix/src/psignal.c: Reflect changes to signal names in newlib.
+ * libcsupport/src/printk.c: Add vprintk function for kernel printing
+ from routines which have already obtained the va_list pointer.
+
+2002-10-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/multilib.m4: Remove RTEMS_ENABLE_MULTILIB_MASTER.
+
+2002-10-28 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/threadhandler.c: Prototype _init() and _main() if they are
+ needed to avoid a warning.
+ * rtems/src/timerserver.c: Add useless return to avoid warning.
+ * librpc/src/rpc/clnt_tcp.c, librpc/src/rpc/clnt_udp.c,
+ librpc/src/rpc/pmap_rmt.c, librpc/src/rpc/rtime.c,
+ librpc/src/rpc/svc_tcp.c: Add include of <sys/select.h> to eliminate
+ warning.
+ * librpc/src/rpc/rpcdname.c: Add prototype of getdomainname() to
+ eliminate warning.
+ * libcsupport/include/rtems/libio.h: Change
+ rtems_filesystem_node_types_t from enumeration to int to eliminate
+ warnings when values are overridden.
+ * Pass to eliminate warnings.
+ * libnetworking/kern/uipc_mbuf.c: Conditional SYSINIT() usage on
+ __rtems__. Fix return statement without a value.
+ * libnetworking/lib/ftpfs.c: read and write filesystem routines return
+ ssize_t.
+ * libnetworking/lib/syslog.c: Add include of <string.h> to eliminate
+ warning.
+ * libnetworking/lib/tftpDriver.c: read and write filesystem routines
+ return ssize_t.
+ * libnetworking/libc/gethostbydns.c: Prototype abort().
+ * libnetworking/libc/inet_ntoa.c: Prototype strcpy().
+ * libnetworking/libc/rcmd.c: Add include of <sys/select.h>.
+ * libnetworking/net/if_loop.c: Turn token at end of endif to comment.
+ * libnetworking/net/rtsock.c, libnetworking/nfs/bootp_subr.c:
+ Conditional SYSINIT() usage on __rtems__.
+ * libnetworking/rtems/rtems_bootp.c: Add include of
+ <rtems/rtems_bsdnet_internal.h>.
+ * libnetworking/rtems/rtems_bsdnet_internal.h: Added prototypes for
+ memcpy() and memset() since the BSD code tries to avoid using libc .h
+ files since it is used to being in the kernel.
+ * libnetworking/rtems/rtems_syscall.c: read and write filesystem
+ routines return ssize_t.
+
+2002-10-28 Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+
+ * libblock/*: Added ATA support.
+ * libblock/include/rtems/blkdev.h: Added last IO status.
+ * libblock/include/rtems/ata.h, libblock/include/rtems/ata_internal.h,
+ libblock/include/rtems/ide_part_table.h, libblock/src/ata.c,
+ libblock/src/ide_part_table.c: New files.
+
+2002-10-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/monitor/mon-command.c: Don't build rtems_monitor_line_editor
+ for RTEMS_UNIX to avoid gcc warning.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac, itron/configure.ac, posix/configure.ac,
+ librpc/configure.ac, libblock/configure.ac, libfs/configure.ac,
+ libcsupport/configure.ac, libnetworking/configure.ac: Add nostdinc to
+ AM_INIT_AUTOMAKE.
+ * libnetworking/Makefile.am: Remove bogus reference to CHANGELOG.
+
+2002-10-24 Fabrizio Pirovano <pirovano.thysys@tiscalinet.it>
+
+ * libmisc/capture/capture.c, libmisc/monitor/mon-manager.c,
+ libmisc/stackchk/check.c: Patch to remove problems introduced by object
+ name rework.
+
+2002-10-24 <strauman@slac.stanford.edu>
+
+ * libcsupport/src/eval.c: Per PR293, added freenode calls for evaluate
+ link failures.
+
+2002-10-23 <strauman@slac.stanford.edu>
+
+ PR 290
+ * src/mount.c: Add check for ops->node_type_h.
+ PR 291
+ * src/mknod.c: Remove erroneous call to freenod.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore, itron/.cvsignore, posix/.cvsignore, libmisc/.cvsignore,
+ librpc/.cvsignore, libblock/.cvsignore, libfs/.cvsignore,
+ libcsupport/.cvsignore, libnetworking/.cvsignore: Reformat. Add
+ autom4te*cache. Remove autom4te.cache.
+
+2002-10-21 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-20021021-test.
+
+2002-10-13 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/net/if_ethersubr.c: Add comments to #endif NETATALK to
+ stop gcc from complaining.
+
+2002-10-07 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20021007.
+
+2002-10-07 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/netinet/tcp_var.h: Corrected typo in ARM alignment patch
+ which broke all other ports.
+
+2002-10-04 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-JUNK.
+ * aclocal/version.m4: Updated to rtems-ss-20021004.
+
+2002-10-04 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * libnetworking/netinet/in_cksum.c, libnetworking/netinet/ip_icmp.h,
+ libnetworking/netinet/ip_input.c, libnetworking/netinet/tcp_input.c,
+ libnetworking/netinet/tcp_subr.c, libnetworking/netinet/tcp_var.h,
+ libnetworking/sys/queue.h: Address alignment requirements for the ARM.
+ * libnetworking/rtems/rtems_glue.c: Add IP aliasing ioctls SIOCAIFADDR
+ and SIOCDIFADDR.
+
+2002-10-02 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/kern/uipc_socket.c: Make sure that small non-zero delays
+ work. Suggested cleanup from Eric Norum.
+
+2002-10-02 Jennifer Averett <jennifer@OARcorp.com>
+
+ * libfs/src/imfs/memfile.c: Fixed case where last close of unlinked file
+ did not remove the resources associated with that file. Reported by
+ Till Straumann <strauman@slac.stanford.edu> on the mailing list.
+
+2002-10-02 Eric Norum <eric.norum@usask.ca>
+
+ * libcsupport/src/getpwent.c: Per PR283, reimplement to address
+ reentrancy problems.
+ * libcsupport/src/getgrent.c: Removed as functionality is now just a
+ wrapper for common routines in src/getpwent.c.
+ * libcsupport/Makefile.am: Reflect file removal.
+ * libnetworking/rtems/mkrootfs.c: As part of PR283, remove redundant
+ code that creates /etc/passwd and /etc/group.
+
+2002-09-16 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/netinet/Makefile.am, libnetworking/netinet/udp_usrreq.c:
+ Back off some of the IP_FORWARD patch as it appears to not compile in
+ the current tree.
+
+2002-09-14 Vyacheslav V. Burdjanadze <wr@zelax.ru>
+
+ * libnetworking/kern/uipc_mbuf.c, libnetworking/sys/mbuf.h,
+ libnetworking/netinet/udp_usrreq.c: Add optional UDP broadcast
+ forwarding support.
+ * libnetworking/netinet/Makefile.am: Defined FORWARD_PROTOCOL to enabled
+ UDP broadcast forwarding.
+
+2002-09-14 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/psignal.c: Remove duplication from rtems/posix/psignal.h.
+ * rtems/src/dpmemcreate.c, rtems/src/dpmemident.c,
+ rtems/src/msgqcreate.c, rtems/src/msgqident.c, rtems/src/partcreate.c,
+ rtems/src/partident.c, rtems/src/ratemoncreate.c,
+ rtems/src/ratemonident.c, rtems/src/regioncreate.c,
+ rtems/src/regionident.c, rtems/src/semcreate.c, rtems/src/semident.c,
+ rtems/src/taskcreate.c, rtems/src/taskident.c, rtems/src/timercreate.c,
+ rtems/src/timerident.c: Added casts to Objects_Name to eliminate
+ warnings.
+ * libfs/src/dosfs/fat.c, libfs/src/imfs/deviceio.c,
+ libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/memfile.c: Eliminated
+ warnings. A lot of this focus was on changing read and write entry
+ points to return ssize_t as read(2) and write(2) now do.
+ * libcsupport/include/rtems/libio.h: Change rtems_filesystem_read_t and
+ rtems_filesystem_write_t to return ssize_t to match read(2) and write(2)
+ respectively.
+ * libnetworking/kern/uipc_socket.c: Fix case on SO_RCVTIMEO and
+ SO_SNDTIMEO where conversion into ticks can result in a 0 ticks timeout
+ which is the same as requesting no timeout. Reported by Sergei Organov
+ <osv@javad.ru>.
+
+2002-09-14 Eric Norum <eric.norum@usask.ca>
+
+ * libcsupport/src/readdir_r.c: New file.
+ * libcsupport/Makefile.am: Reflect above.
+
+2002-09-07 Joel Sherrill <joel@OARcorp.com>
+
+ * libblock/src/bdbuf.c: Previous fix for PR282 regressed mutex changes.
+
+2002-09-06 Alexander M. Kukuta <kam@oktet.ru>
+
+ * libblock/src/bdbuf.c: Per PR282, correct problem in function
+ rtems_bdbuf_read() where device ioctl() is called with the logical
+ device number used instead of corresponding physical device number.
+
+2002-09-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/netinet/in_cksum.c: #include <string.h> for puts in
+ generic routines.
+
+2002-08-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/shell/shell.c: #include <time.h>.
+ * libmisc/wrapup/Makefile.am: Eliminate LIBNAME.
+
+2002-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/src/io.c: Fixed some spacing.
+
+2002-08-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/Makefile.am: Remove cpuopt.h generation.
+ * configure.ac: Correct package name. Don't build ada if POSIX is
+ disabled. Generate cpuopt.h on the fly, filter out autoconf-2.53 PACKAGE
+ crap.
+ * aclocal/prog-gnat.m4: New.
+ * configure.ac: Add ada subdir handling.
+
+2002-08-21 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/adjtime.c: New file -- adjtime() support required by the
+ Network Time Protocol (NTP) port to RTEMS.
+ * posix/src/Makefile.am: Modified to reflect above.
+
+2002-08-20 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/bsp-alias.m4: Remove.
+
+2002-08-20 Joel Sherrill <joel@OARcorp.com>
+
+ * librpc/src/xdr/xdr_stdio.c: Per PR268, add include of <netinet/in.h>
+ to avoid warning on ntohl().
+
+2002-08-20 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/rtems/rtems_glue.c: Per PR270, the BSD network code
+ expects that the value of the number of seconds since boot is non-zero.
+ The RTEMS network initialization code assures this by waiting for a
+ second. A more efficient technique is to simply wait until the number
+ of seconds since boot is non-zero.
+
+2002-08-14 Joel Sherrill <joel@OARcorp.com>
+
+ * score/macros/rtems/score/coremsg.inl: Add <string.h> to remove warning.
+ * score/src/threadidlebody.c: Add return 0 to avoid warning.
+
+2002-08-12 Eric Norum <eric.norum@usask.ca>
+
+ * libcsupport/src/write.c (_write_r): Change prototype to match newlib's
+ reent.h.
+
+2002-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/capture/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dummy/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/monitor/Makefile.am,
+ libmisc/mw-fb/Makefile.am, libmisc/rtmonuse/Makefile.am,
+ libmisc/serdbg/Makefile.am, libmisc/shell/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am: Use .$(OBJEXT)
+ instead of .o.
+ * librpc/src/rpc/rtems_portmapper.c: include <stdlib.h> (Get rid of
+ gcc31 warnings about abort/exit).
+
+2002-08-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/shell/Makefile.am: Remove shell.h from EXTRA_DIST.
+
+2002-08-09 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/cancelrun.c: Remove check for PTHREAD_CANCELED not being
+ defined to ensure that newlib patch includes it.
+ * libnetworking/libc/getservent.c: Per PR265, add #include
+ <netinet/in.h> for ntohl() function.
+
+2002-08-07 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add missing ',' to librpc activation. Add
+ AC_MSG_CHECKING/AC_MSG_RESULT.
+ * aclocal/check-networking.m4: Let AC_MSG_CHECKING refer to CPU.
+ * configure.ac: Fix bug in librpc activation, having introduced by
+ yesterday's patch.
+
+2002-08-07 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/version.m4: Updated to rtems-ss-20020807.
+ * libnetworking/netinet/in.h: Per PR263, added include of
+ <machine/endian.h> to <netinet/in.h> so it includes prototypes of
+ ntohl() family of routines.
+
+2002-08-07 Chris Johns <ccj@acm.org>
+
+ * score/src/coretodset.c: Correct calculation of ticks until next
+ section boundary. It was incorrectly based upon current time not the
+ time that is being set.
+
+2002-08-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/env-rtemsbsp.m4: Remove RTEMS_CONFIG_PER_BSP.
+ * aclocal/env-rtemscpu.m4: Remove RTEMS_CONFIG_PER_BSP. Use AS_IF
+ instead of if/then/else/fi.
+
+2002-08-06 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.ac, librpc/configure.ac: or32 does not currently support
+ librpc.
+
+2002-08-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Use librtems.a.
+ * wrapup/Makefile.am: Use libsapi.a.
+ * sapi/src/Makefile.am: Add libsapi.a.
+ * rtems/src/Makefile.am: Add librtems.a.
+ * libnetworking/wrapup/Makefile.am: Don't install.
+
+2002-08-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/cpuuse/cpuuse.c (CPU_usage_Dump) : Corrected so it honors when
+ an object name is raw versus being a string.
+ * libnetworking/machine/param.h, libnetworking/sys/syslimits.h: In the
+ continued effort to eliminate .h conflicts between newlib and RTEMS,
+ these were moved to newlib.
+ * libnetworking/machine/Makefile.am, libnetworking/sys/Makefile.am:
+ Reflect above.
+
+2002-07-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Use libscore.a.
+ * aclocal/canonicalize-tools.m4, automake/lib.am: Remove LD.
+ * Makefile.am: Put preinstall-stamp into CLEANFILES.
+ * aclocal/rtems-top.m4: Use with_project_root and MULTIBUILDTOP to
+ compose PROJECT_TOPdir (Fixes hppa1.1/genoffset problem).
+ * wrapup/Makefile.am: LIBBLOCK_OBJS = ../libblock/$(ARCH)/libblock.a.
+ * posix/src/mqueuecreatesupp.c: #include <stdlib.h> (malloc).
+ * score/src/Makefile.am: Build into libscore.a.
+ * libblock/Makefile.am: Merge src/Makefile.am.
+ * libblock/src/Makefile.am: Remove.
+ * libblock/configure.ac: Remove src/Makefile.am.
+ * libfs/wrapup/Makefile.am, libfs/wrapup/.cvsignore: Remove.
+ * libfs/Makefile.am: Remove wrapup SUBDIR.
+ * libfs/configure.ac: Remove wrapup/Makefile.
+
+2002-07-31 Joel Sherrill <joel@OARcorp.com>
+
+ * aclocal/rtems-cpu-subdirs.m4: Removed the or16 port was just a stub
+ and only the OR32 port is getting worked on.
+
+2002-07-30 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/stackchk/check.c: Don't reference the RTEMS allocated
+ interrupt stack if the port doesn't configure using it.
+ * libcsupport/include/sys/utime.h: Removed as file is now part of the
+ RTEMS newlib support.
+ * libcsupport/Makefile.am: Reflect above.
+ * libcsupport/include/rtems/termiostypes.h: Avoid use of __P.
+ * libnetworking/sys/param.h: Removed as a simpler version of this file
+ is now part of the RTEMS newlib support.
+ * libnetworking/sys/Makefile.am: Modified to reflect above.
+ * libnetworking/machine/types.h: Removed as a simpler version of this
+ file is now part of the RTEMS newlib support.
+ * libnetworking/machine/Makefile.am, libnetworking/machine/endian.h,
+ libnetworking/nfs/bootp_subr.c,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/sys/Makefile.am, libnetworking/sys/systm.h: Minor
+ modifications to use the simpler machine/types.h. Mostly more complete
+ sets of #include's to account for machine/types.h no longer doing this.
+
+2002-07-30 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * libnetworking/netinet/in_cksum.c,
+ libnetworking/netinet/in_cksum_arm.c: Added ARM in_cksum support.
+
+2002-07-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * librpc/src/rpc/Makefile.am: Merge src/rpc/PSD.doc/Makefile.am.
+ * librpc/include/Makefile.am: Merge include/rpc/Makefile.am. Merge
+ include/rpcsvc/Makefile.am.
+ * librpc/include/rpc/Makefile.am, librpc/include/rpcsvc/Makefile.am,
+ librpc/src/rpc/PSD.doc/Makefile.am: Remove.
+ * librpc/configure.ac: Remove duplicate AC_PROG_RANLIB. Remove
+ include/rpc/Makefile. Remove include/rpcsvc/Makefile. Remove
+ src/rpc/PSD.doc/Makefile.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-24 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/wrapup/Makefile.am: Temporarily don't include serdbg since it
+ causes some BSPs to not link "main(){}" as required by autoconf.
+ * libnetworking/sys/select.h: Add a prototype of select() to avoid
+ warnings. In particular a C++ application using select() required a
+ prototype.
+ * libnetworking/Makefile.am, libnetworking/libc/res_send.c: Do not
+ install or use <poll.h> since RTEMS does not support it.
+
+2002-07-23 Joel Sherrill <joel@OARcorp.com>
+
+ * librpc/src/rpc/pmap_clnt.c (pmap_set): Changed prototype to match .h.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Use .$(OBJEXT) instead of .o.
+ * wrapup/Makefile.am: Use project_libdir instead of
+ $(PROJECT_RELEASE)/lib. Eliminate LIBNAME. Pickup *.o's instead of
+ *.rels for CPU_OBJS. Manually create $(project_libdir)$(MULTISUBDIR).
+ * automake/lib.am: Use project_libdir instead of $(PROJECT_RELEASE)/lib.
+ * aclocal/env-rtemsbsp.m4, aclocal/env-rtemscpu.m4: Remove
+ RTEMS_BSP_SPECS, PROJECT_RELEASE. Add project_libdir, libdir. New
+ GCC_SPECS. Various cleanups.
+ * aclocal/rtems-top.m4: New PROJECT_ROOT handling.
+ * automake/compile.am: Remove RTEMS_BSP_SPECS, LD* flags, LINK,
+ references to bsp_specs. Use project_libdir instead of
+ $(PROJECT_RELEASE)/lib.
+ * itron/src/Makefile.am: Use .$(OBJEXT) instead of .o.
+ * itron/src/Makefile.am: Use AM_CPPFLAGS instead of INCLUDES.
+ * posix/src/Makefile.am: Use .$(OBJEXT) instead of .o.
+ * posix/src/Makefile.am: Use AM_CPPFLAGS instead of INCLUDES.
+ * score/src/Makefile.am, sapi/src/Makefile.am, rtems/src/Makefile.am,
+ librpc/src/xdr/Makefile.am, librpc/src/rpc/Makefile.am: Use .$(OBJEXT)
+ instead of .o.
+ * librpc/src/xdr/Makefile.am, librpc/src/rpc/Makefile.am: Eliminate
+ LIBNAME.
+ * libblock/src/Makefile.am: Use .$(OBJEXT) instead of .o.
+ * libblock/src/Makefile.am: Eliminate LIBNAME. Cosmetical cleanups.
+ * libcsupport/Makefile.am: Use .$(OBJEXT) instead of .o.
+ * libcsupport/Makefile.am: Eliminate LIBNAME. Use AM_CPPFLAGS instead of
+ INCLUDES (Upcoming automake standard).
+ * libnetworking/kern/Makefile.am: Use .$(OBJEXT) instead of .o.
+ * libnetworking/lib/Makefile.am, libnetworking/libc/Makefile.am,
+ libnetworking/net/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/nfs/Makefile.am, libnetworking/rtems/Makefile.am,
+ libnetworking/wrapup/Makefile.am: Ditto.
+ * libnetworking/kern/Makefile.am: Eliminate LIBNAME.
+ * libnetworking/lib/Makefile.am, libnetworking/libc/Makefile.am,
+ libnetworking/net/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/nfs/Makefile.am, libnetworking/rtems/Makefile.am: Ditto.
+ * libnetworking/wrapup/Makefile.am: Use project_libdir instead of
+ $(PROJECT_RELEASE)/lib.
+
+2002-07-22 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/score/apimutex.h (_API_Mutex_Lock): Per PR253 add
+ the missing _ISR_Disable. This fix was already applied to the old
+ location (c/src/exec/score/...).
+
+2002-07-20 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/capture/capture.c, libmisc/capture/capture-cli.c: include
+ <string.h> for memset.
+
+2002-07-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/rtems-top.m4: Reflect relocation of c/src/exec to cpukit.
+ * aclocal/check-cpu.m4, aclocal/check-bsps.m4: Ditto.
+
+2002-07-17 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * libnetworking/netinet/in.h, libnetworking/netinet/ip.h,
+ libnetworking/netinet/ip_var.h, libnetworking/netinet/tcp.h: Modified to
+ added packed attribute.o.
+
+2002-07-16 Joel Sherrill <joel@OARcorp.com>
+
+ * score/macros/rtems/score/object.inl: Corrected typos in
+ _Objects_Open, _Objects_Close, and _Objects_Namespace_remove.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/multilib.am: Add install-multi.
+ * aclocal/rtems-top.m4: Reflect new RTEMS_TOPdir to detecting
+ version.m4. Add --with-project-root. Reflect --with-project-root to
+ setting up PROJECT_ROOT.
+ * aclocal/env-rtemscpu.m4: Reflect new RTEMS_TOPdir (HACK).
+ * aclocal/check-cpu.m4, aclocal/check-bsps.m4: Reflect new RTEMS_TOPdir.
+ * configure.ac: RTEMS_TOP(..).
+ * itron/configure.ac, posix/configure.ac, librpc/configure.ac,
+ libblock/configure.ac, libfs/configure.ac, libcsupport/configure.ac,
+ libnetworking/configure.ac: RTEMS_TOP(../..).
+
+2002-07-05 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/include/rtems/posix/cancel.h, posix/src/cancel.c,
+ posix/src/cancelrun.c, posix/src/mqueue.c, posix/src/pthread.c,
+ posix/src/semaphore.c, posix/src/setcancelstate.c,
+ posix/src/setcanceltype.c, posix/src/testcancel.c: Per PR164, corrected
+ the behavior of thread cancellation and did some cleanup as a
+ side-effect.
+ * score/macros/rtems/score/object.inl: Corrected implementation of
+ _Objects_Open, _Objects_Close, and _Objects_Namespace_remove to be
+ consistent with the inline implementation.
+ * rtems/src/dpmemident.c, rtems/src/msgqident.c, rtems/src/partident.c,
+ rtems/src/ratemonident.c, rtems/src/regionident.c, rtems/src/semident.c,
+ rtems/src/timerident.c: Corrected use of name parameter to be
+ consistent with fixes implemented to string name processing which were
+ committed with the POSIX Message Queue update.
+
+2002-07-04 Joel Sherrill <joel@OARcorp.com>
+
+ * Jump table for single entry point removed.
+ * sapi/include/rtems/directives.h, sapi/src/entrytable.c: Removed.
+ * sapi/include/Makefile.am, sapi/src/Makefile.am, sapi/src/exinit.c:
+ Modified to reflect above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Install by using cpulibdir, cpulib_DATA.
+ * aclocal/check-bsp-cache.m4: Remove RTEMS_BSP_FAMILY.
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+ * aclocal/project-root.m4: Remove.
+ * aclocal/enable-multiprocessing.m4: Fix typo.
+ * aclocal/prog-cc.m4: Remove obsolete comments. Comment out GCCSED.
+ * itron/configure.ac, posix/configure.ac, librpc/configure.ac,
+ libblock/configure.ac, libfs/configure.ac, libcsupport/configure.ac,
+ libnetworking/configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-07-01 Joel Sherrill <joel@OARcorp.com>
+
+ * Mega patch merge to change the format of the object IDs to loosen the
+ dependency between the SCORE and the various APIs. There was
+ considerable work to simplify the object name management and it appears
+ that the name_table field is no longer needed. This patch also includes
+ the addition of the internal mutex which is currently only used to
+ protect some types of allocation and deallocation. This significantly
+ can reduce context switch latency under certain circumstances. In
+ particular, some heap/region operations were O(n) and had dispatching
+ disabled. This should help enormously. With this merge, the patch is
+ not as clean as it should be. In particular, the documentation has not
+ been modified to reflect the new object ID layout, the IDs in the test
+ screens are not updated, and _Objects_Get_information needs to be a real
+ routine not inlined. As part of this patch a lot of MP code for
+ thread/proxy blocking was made conditional and cleaned up.
+ * itron/src/cre_mbf.c, itron/src/cre_sem.c, itron/src/eventflags.c,
+ itron/src/fmempool.c, itron/src/itronsem.c, itron/src/mbox.c,
+ itron/src/msgbuffer.c, itron/src/port.c, itron/src/task.c,
+ itron/src/vmempool.c: Modified as part of above.
+ * Mega patch merge to change the format of the object IDs to loosen the
+ dependency between the SCORE and the various APIs. There was
+ considerable work to simplify the object name management and it appears
+ that the name_table field is no longer needed. This patch also includes
+ the addition of the internal mutex which is currently only used to
+ protect some types of allocation and deallocation. This significantly
+ can reduce context switch latency under certain circumstances. In
+ particular, some heap/region operations were O(n) and had dispatching
+ disabled. This should help enormously. With this merge, the patch is
+ not as clean as it should be. In particular, the documentation has not
+ been modified to reflect the new object ID layout, the IDs in the test
+ screens are not updated, and _Objects_Get_information needs to be a real
+ routine not inlined. As part of this patch a lot of MP code for
+ thread/proxy blocking was made conditional and cleaned up.
+ * posix/include/rtems/posix/key.h, posix/src/cond.c,
+ posix/src/condinit.c, posix/src/intr.c, posix/src/key.c,
+ posix/src/keycreate.c, posix/src/keydelete.c, posix/src/killinfo.c,
+ posix/src/mqueue.c, posix/src/mqueuecreatesupp.c, posix/src/mutex.c,
+ posix/src/mutexinit.c, posix/src/psignal.c, posix/src/pthread.c,
+ posix/src/semaphore.c, posix/src/semaphorecreatesupp.c: Modified as part
+ of above.
+ * Mega patch merge to change the format of the object IDs to loosen the
+ dependency between the SCORE and the various APIs. There was
+ considerable work to simplify the object name management and it appears
+ that the name_table field is no longer needed. This patch also includes
+ the addition of the internal mutex which is currently only used to
+ protect some types of allocation and deallocation. This significantly
+ can reduce context switch latency under certain circumstances. In
+ particular, some heap/region operations were O(n) and had dispatching
+ disabled. This should help enormously. With this merge, the patch is
+ not as clean as it should be. In particular, the documentation has not
+ been modified to reflect the new object ID layout, the IDs in the test
+ screens are not updated, and _Objects_Get_information needs to be a real
+ routine not inlined. As part of this patch a lot of MP code for
+ thread/proxy blocking was made conditional and cleaned up.
+ * score/include/Makefile.am, score/include/rtems/score/coremsg.h,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h, score/include/rtems/score/object.h,
+ score/include/rtems/score/threadq.h,
+ score/inline/rtems/score/object.inl,
+ score/inline/rtems/score/thread.inl,
+ score/macros/rtems/score/object.inl, score/src/Makefile.am,
+ score/src/coremsg.c, score/src/coremutex.c, score/src/coresem.c,
+ score/src/mpci.c, score/src/objectcomparenameraw.c,
+ score/src/objectextendinformation.c,
+ score/src/objectinitializeinformation.c, score/src/objectnametoid.c,
+ score/src/thread.c, score/src/threadclose.c, score/src/threadget.c,
+ score/src/threadq.c, score/src/threadqextractwithproxy.c: Modified as
+ part of above.
+ * score/include/rtems/score/apimutex.h,
+ score/src/objectgetnoprotection.c: New files.
+ * Mega patch merge to change the format of the object IDs to loosen the
+ dependency between the SCORE and the various APIs. There was
+ considerable work to simplify the object name management and it appears
+ that the name_table field is no longer needed. This patch also includes
+ the addition of the internal mutex which is currently only used to
+ protect some types of allocation and deallocation. This significantly
+ can reduce context switch latency under certain circumstances. In
+ particular, some heap/region operations were O(n) and had dispatching
+ disabled. This should help enormously. With this merge, the patch is
+ not as clean as it should be. In particular, the documentation has not
+ been modified to reflect the new object ID layout, the IDs in the test
+ screens are not updated, and _Objects_Get_information needs to be a real
+ routine not inlined. As part of this patch a lot of MP code for
+ thread/proxy blocking was made conditional and cleaned up.
+ * sapi/include/confdefs.h, sapi/src/exinit.c, sapi/src/extension.c,
+ sapi/src/itronapi.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c: Modified
+ as part of above.
+ * Mega patch merge to change the format of the object IDs to loosen the
+ dependency between the SCORE and the various APIs. There was
+ considerable work to simplify the object name management and it appears
+ that the name_table field is no longer needed. This patch also includes
+ the addition of the internal mutex which is currently only used to
+ protect some types of allocation and deallocation. This significantly
+ can reduce context switch latency under certain circumstances. In
+ particular, some heap/region operations were O(n) and had dispatching
+ disabled. This should help enormously. With this merge, the patch is
+ not as clean as it should be. In particular, the documentation has not
+ been modified to reflect the new object ID layout, the IDs in the test
+ screens are not updated, and _Objects_Get_information needs to be a real
+ routine not inlined. As part of this patch a lot of MP code for
+ thread/proxy blocking was made conditional and cleaned up.
+ * rtems/include/rtems.h, rtems/inline/rtems/rtems/region.inl,
+ rtems/macros/rtems/rtems/region.inl, rtems/src/dpmem.c,
+ rtems/src/dpmemcreate.c, rtems/src/msg.c, rtems/src/msgqcreate.c,
+ rtems/src/part.c, rtems/src/partcreate.c, rtems/src/ratemon.c,
+ rtems/src/ratemoncreate.c, rtems/src/region.c, rtems/src/regioncreate.c,
+ rtems/src/regiondelete.c, rtems/src/regionextend.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionident.c,
+ rtems/src/regionreturnsegment.c, rtems/src/rtemstimer.c,
+ rtems/src/sem.c, rtems/src/semcreate.c, rtems/src/taskcreate.c,
+ rtems/src/taskident.c, rtems/src/tasks.c, rtems/src/timercreate.c:
+ Modified as part of above.
+ * libmisc/capture/capture-cli.c, libmisc/cpuuse/cpuuse.c,
+ libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
+ libmisc/monitor/monitor.h: Corrected use of _Objects_Information_table
+ now that it is a two dimensional array based upon API and class. In
+ addition, in the monitor, corrected an error which occured when a
+ target has 64 bit pointers.
+ * libmisc/stackchk/check.c: Corrected use of _Objects_Information_table
+ now that it is a two dimensional array based upon API and class.
+ * Mega patch merge to change the format of the object IDs to loosen the
+ dependency between the SCORE and the various APIs. There was
+ considerable work to simplify the object name management and it appears
+ that the name_table field is no longer needed. This patch also includes
+ the addition of the internal mutex which is currently only used to
+ protect some types of allocation and deallocation. This significantly
+ can reduce context switch latency under certain circumstances. In
+ particular, some heap/region operations were O(n) and had dispatching
+ disabled. This should help enormously. With this merge, the patch is
+ not as clean as it should be. In particular, the documentation has not
+ been modified to reflect the new object ID layout, the IDs in the test
+ screens are not updated, and _Objects_Get_information needs to be a real
+ routine not inlined. As part of this patch a lot of MP code for
+ thread/proxy blocking was made conditional and cleaned up.
+ * libblock/src/bdbuf.c: Modified as part of above.
+ * libcsupport/src/__times.c: Corrected from previous attempt to cleanup.
+
+2002-06-28 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/__times.c: Cleaned up comments, return more
+ information, and eliminated the fatal error on clock not set since it
+ cannot occur.
+
+2002-06-27 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ * Addition of a ftp client filesystem, comparable to the tftp one.
+ * libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h: New files.
+ * libnetworking/lib/Makefile.am, libnetworking/rtems/Makefile.am:
+ Modified to reflect above.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/prog-ccas.m4: New.
+ * aclocal/canonicalize-tools.m4: Remove AS, OBJCOPY, NM, SIZE, STRIP.
+ RTEMS_GCC_PRINT.
+ * aclocal/check-multiprocessing.m4: Fix typo.
+ * automake/compile.am: Remove CXX support. Replace AS by CCAS. Remove
+ LINK_LIBS, LINK_OBJS, LINK_FILES.
+ * configure.ac: Use AC_CONFIG_AUX_DIR(..).
+ * itron/configure.ac, posix/configure.ac, librpc/configure.ac,
+ libblock/configure.ac, libfs/configure.ac, libcsupport/configure.ac,
+ libnetworking/configure.ac: Use AC_CONFIG_AUX_DIR(../..). Add
+ AC_PROG_RANLIB.
+
+2002-06-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove references to RTEMS_BSP.
+ * aclocal/check-multiprocessing.m4: Remove references to RTEMS_BSP.
+ Allow building w/ --enable-multiprocessing --enable-multilib.
+ * aclocal/enable-multiprocessing.m4: Eliminate RTEMS_HAS_MULTIPROCESSING.
+ * itron/configure.ac: Remove references to RTEMS_BSP.
+ * itron/src/Makefile.am: Add libitron.a.
+ * posix/configure.ac: Remove references to RTEMS_BSP.
+ * posix/src/Makefile.am: Add libposix.a.
+ * libmisc/wrapup/Makefile.am: Don't preinstall libmisc.a.
+ * libblock/src/Makefile.am: Don't preinstall libblock.a.
+ * libfs/wrapup/Makefile.am: Don't preinstall libfs.a.
+ * libnetworking/wrapup/Makefile.am: Don't preinstall libnetworking.a.
+
+2002-06-25 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ * With the addition of serdbg, the standard polled I/O functions for
+ gdbstub and/or printk are optionally routed to any termios-aware device
+ driver, that supports polled mode. See libmisc/serdbg/README.
+ * libmisc/serdbg/Makefile.am, libmisc/serdbg/README,
+ libmisc/serdbg/serdbg.c, libmisc/serdbg/serdbg.h,
+ libmisc/serdbg/serdbgcnf.h, libmisc/serdbg/serdbgio.c,
+ libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h,
+ libmisc/serdbg/termios_printk_cnf.h, libmisc/serdbg/.cvsignore: New
+ files.
+ * libmisc/configure.ac, libmisc/Makefile.am, libmisc/wrapup/Makefile.am:
+ Modified to reflect addition.
+
+2002-06-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Fix stupid typo in previous patch.
+ * configure.ac: Add librpc. AC_PROG_RANLIB.
+ * wrapup/Makefile.am: Add librpc. Use relative path to lib*.a for
+ POSIX_OBJS, ITRON_OBJS, NETWORKING_OBJS.
+ * librpc/configure.ac: RTEMS_TOP(../../../..).
+ AC_CONFIG_AUX_DIR(../../../..). Remove RTEMS_CANONICAL_HOST. Use
+ RTEMS_ENV_RTEMSCPU. Add AC_PROG_RANLIB.
+ * librpc/include/rpc/Makefile.am, librpc/include/Makefile.am,
+ librpc/include/rpcsvc/Makefile.am: Include
+ $(top_srcdir)/../automake/*.am.
+ * librpc/Makefile.am: Include $(top_srcdir)/../automake/*.am.
+ ACLOCAL_AMFLAGS = -I ../aclocal.
+ * librpc/src/rpc/PSD.doc/Makefile.am, librpc/src/rpc/Makefile.am,
+ librpc/src/xdr/Makefile.am, librpc/src/Makefile.am: Include
+ $(top_srcdir)/../automake/*.am.
+
+2002-06-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * aclocal/subdirs.m4: Remove.
+
+2002-06-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Use relative path to lib*.a for LIBCSUPPORT_OBJS,
+ LIBBLOCK_OBJS, LIBDOSFS_OBJS, LIBIMFS_OBJS.
+ * libblock/Makefile.am: Merge-in include/Makefile.am.
+ * libblock/include/Makefile.am: Remove.
+ * libblock/configure.ac: Reflect changes above.
+ * libnetworking/Makefile.am: Remove commented out net-apps.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/automake/*.am. Use aclocal.
+ * sapi/include/Makefile.am, sapi/Makefile.am, sapi/inline/Makefile.am,
+ sapi/macros/Makefile.am, sapi/src/Makefile.am,
+ score/include/Makefile.am, score/Makefile.am, score/cpu/Makefile.am,
+ score/inline/Makefile.am, score/macros/Makefile.am,
+ score/src/Makefile.am, wrapup/Makefile.am, include/Makefile.am,
+ rtems/include/Makefile.am, rtems/Makefile.am, rtems/inline/Makefile.am,
+ rtems/macros/Makefile.am, rtems/src/Makefile.am: Include
+ $(top_srcdir)/automake/*.am.
+ * aclocal/bsp-alias.m4: Copied over from aclocal/.
+ * aclocal/canonical-host.m4, aclocal/canonical-target-name.m4,
+ aclocal/canonicalize-tools.m4, aclocal/check-bsp-cache.m4,
+ aclocal/check-bsps.m4, aclocal/check-cpu.m4, aclocal/check-itron.m4,
+ aclocal/check-multiprocessing.m4, aclocal/check-networking.m4,
+ aclocal/check-newlib.m4, aclocal/check-posix.m4, aclocal/check-tool.m4,
+ aclocal/enable-bare.m4, aclocal/enable-inlines.m4,
+ aclocal/enable-itron.m4, aclocal/enable-multiprocessing.m4,
+ aclocal/enable-networking.m4, aclocal/enable-posix.m4,
+ aclocal/enable-rtemsbsp.m4, aclocal/env-rtemsbsp.m4,
+ aclocal/env-rtemscpu.m4, aclocal/gcc-pipe.m4, aclocal/gcc-specs.m4,
+ aclocal/multi.m4, aclocal/multilib.m4, aclocal/prog-cc.m4,
+ aclocal/project-root.m4, aclocal/rtems-cpu-subdirs.m4,
+ aclocal/rtems-debug.m4, aclocal/rtems-top.m4, aclocal/subdirs.m4,
+ aclocal/sysv-ipc.m4, aclocal/tool-paths.m4, aclocal/version.m4: Ditto.
+ * itron/include/Makefile.am: Include $(top_srcdir)/../automake/*.am.
+ * itron/Makefile.am: Include $(top_srcdir)/../automake/*.am. Use
+ ../aclocal.
+ * itron/inline/Makefile.am, itron/macros/Makefile.am,
+ itron/src/Makefile.am, posix/include/Makefile.am: Include
+ $(top_srcdir)/../automake/*.am.
+ * posix/Makefile.am: Include $(top_srcdir)/../automake/*.am. Use
+ ../aclocal.
+ * posix/inline/Makefile.am, posix/macros/Makefile.am,
+ posix/src/Makefile.am, libblock/include/Makefile.am: Include
+ $(top_srcdir)/../automake/*.am.
+ * libblock/Makefile.am: Include $(top_srcdir)/../automake/*.am. Use
+ ../aclocal.
+ * libblock/src/Makefile.am, libfs/src/dosfs/Makefile.am,
+ libfs/src/Makefile.am, libfs/src/imfs/Makefile.am: Include
+ $(top_srcdir)/../automake/*.am.
+ * libfs/Makefile.am: Include $(top_srcdir)/../automake/*.am. Use
+ ../aclocal.
+ * libfs/wrapup/Makefile.am: Include $(top_srcdir)/../automake/*.am.
+ * libcsupport/Makefile.am: Merge src/Makefile.am.
+ * libcsupport/configure.ac: Reflect changes above.
+ * libcsupport/src/Makefile.am: Remove.
+ * libcsupport/Makefile.am: Include $(top_srcdir)/../automake/*.am. Use
+ ../aclocal.
+ * libcsupport/src/Makefile.am, libnetworking/arpa/Makefile.am,
+ libnetworking/kern/Makefile.am: Include $(top_srcdir)/../automake/*.am.
+ * libnetworking/Makefile.am: Include $(top_srcdir)/../automake/*.am. Use
+ ../aclocal.
+ * libnetworking/lib/Makefile.am, libnetworking/libc/Makefile.am,
+ libnetworking/machine/Makefile.am, libnetworking/net/Makefile.am,
+ libnetworking/netinet/Makefile.am, libnetworking/nfs/Makefile.am,
+ libnetworking/rtems/Makefile.am, libnetworking/sys/Makefile.am,
+ libnetworking/vm/Makefile.am, libnetworking/wrapup/Makefile.am: Include
+ $(top_srcdir)/../automake/*.am.
+
+2002-06-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * automake/compile.am, automake/lib.am, automake/local.am,
+ automake/multilib.am, automake/subdirs.am: Copied over from automake/.
+ * Makefile.am: Add automake/*.am.
+
+2002-06-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/rtems/Makefile.am: include multilib.am instead of
+ RTEMS_BSP.cfg.
+
+2002-05-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/configure.ac: Remove RTEMS_CHECK_POSIX_API. Remove
+ RTEMS_ENABLE_POSIX. Remove RTEMS_CHECK_CUSTOM_BSP. Remove
+ RTEMS_ENABLE_POSIX.
+
+2002-05-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add libnetworking.
+ * wrapup/Makefile.am: Ditto. Relocate c/src/libnetworking.
+ * libnetworking/Makefile.am: Reflect moval.
+ * libnetworking/machine/Makefile.am, libnetworking/net/Makefile.am,
+ libnetworking/lib/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/vm/Makefile.am, libnetworking/libc/Makefile.am,
+ libnetworking/sys/Makefile.am, libnetworking/arpa/Makefile.am,
+ libnetworking/nfs/Makefile.am, libnetworking/kern/Makefile.am,
+ libnetworking/rtems/Makefile.am, libnetworking/configure.ac: Ditto.
+ * libnetworking/wrapup/Makefile.am: Ditto. Remove references to
+ networking apps.
+
+2002-05-24 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/configure.ac, libmisc/Makefile.am: Remove references to rootfs.
+
+2002-05-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add libblock. Add libfs. Add AM_CONDITIONAL(UNIX).
+ * wrapup/Makefile.am: Add libblock, libfs/dosfs, libfs/imfs.
+ * libblock/configure.ac, libblock/Makefile.am,
+ libblock/include/Makefile.am, libblock/src/Makefile.am: Reflect move
+ from c/src/libblock to c/src/exec/libblock.
+ * libfs/configure.ac: Reflect move from c/src/libfs to c/src/exec/libfs.
+ * libfs/Makefile.am, libfs/src/Makefile.am, libfs/src/dosfs/Makefile.am,
+ libfs/src/imfs/Makefile.am, libfs/wrapup/Makefile.am: Ditto.
+ * libnetworking/rtems_telnetd/pty.c: Remove bsp.h. Include
+ <rtems/bspIo.h>.
+
+2002-05-16 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/rootfs/.cvsignore, libmisc/rootfs/Makefile.am,
+ libmisc/rootfs/mkrootfs.h, libmisc/rootfs/mkrootfs.c: Remove.
+ * libmisc/configure.ac: Remove rootfs and NETWORKING macros.
+ * libmisc/wrapup/Makefile.am: Remove rootfs and HAS_NETWORKING.
+ * libnetworking/rtems/mkrootfs.c: Add (relocated from libmisc/rootfs).
+ * libnetworking/rtems/mkrootfs.h: Ditto.
+ * libnetworking/rtems/Makefile.am: Reflect changes above.
+
+2002-05-16 Chris Johns <ccj@acm.org>
+
+ PR 194
+ * libmisc/*: Added the Capture engine.
+ * libmisc/capture/Makefile.am, libmisc/capture/README,
+ libmisc/capture/capture-cli.c, libmisc/capture/capture-cli.h,
+ libmisc/capture/capture.c, libmisc/capture/capture.h,
+ libmisc/capture/.cvsignore: New files.
+ * libmisc/Makefile.am, libmisc/configure.ac, libmisc/wrapup/Makefile.am:
+ Modified to reflect addition.
+
+2002-05-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add libcsupport.
+ * wrapup/Makefile.am: Ditto.
+ * Makefile.am: Add preinstall-stamp.
+
+2002-05-15 Chris Johns <ccj@acm.org>
+
+ * score/include/rtems/score/thread.h,
+ score/inline/rtems/score/thread.inl, score/src/threaddispatch.c,
+ score/src/threadinitialize.c: Move the C library re-enterrant support
+ directly into the thread dispatch code. RTEMS needs libc and so
+ requiring libc to use a user extension with its overhead is not the best
+ solution. This patch lowers the overhead to 2 pointer moves.
+
+2002-05-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/sys/ioctl.h, libnetworking/sys/sockio.h,
+ libnetworking/sys/filio.h: Remove.
+ * libnetworking/sys/Makefile.am: Reflect changes above.
+
+2002-05-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/Makefile.am: Work-around to autoconf-2.53 adding
+ PACKAGE_* to autoheaders - sed out *PACKAGE* from cpuopts-tmp.h.
+
+2002-05-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * posix/include/sys/utsname.h: Remove.
+ * posix/include/Makefile.am: Reflect changes above.
+ * posix/src/utsname.c: Remove.
+ * posix/src/Makefile.am: Reflect changes above.
+
+2002-05-01 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/machine/in_cksum.h: Per PR200 fix multi-line inline
+ assembly to satisfy gcc 3.1 and newer.
+
+2002-04-26 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/netinet/in_cksum_i386.c: Add volatile so the more
+ agressive optimization in gcc 3.1 does not reorder things.
+
+2002-04-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Remove targopts.h.
+ * libnetworking/pppd/utils.c: Adapt to gcc-3.x.
+
+2002-04-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Add the sparc to the target supporting
+ multlibs.
+
+2002-04-16 Chris Johns <ccj@acm.org>
+
+ * score/src/threadinitialize.c: Per PR181, clear the array of user
+ extension pointers. This lets user extensions that have hooked the
+ switch handler know if a task has been processed by the user extension
+ before. If a user extension is created after a task is started it may
+ not know it.
+
+2002-04-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove ENABLE_GCC28.
+
+2002-04-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Add i386 to multilib-able targets.
+
+2002-04-11 Chris Johns <ccj@acm.org>
+
+ PR 59/networking
+ * libnetworking/c/src/libnetworking/rtems/rtems_bsdnet.h: Add the
+ drv_ctrl driver control block field to the ifconfig network driver
+ structure. This field is needed by the i82586 driver which was ported
+ from NetBSD as it had better hardware abstraction.
+
+2002-04-10 Victor V. Vengerov <vvv@oktet.ru>
+
+ PR 385/filesystem
+ * libblock/src/ramdisk.c: The "from" and "to" locations are calculated
+ as the start of the block within the ram that data is to be transferred
+ from/to for reads and writes respectively. However, within the loops,
+ the "from" and "to" locations are never updated. The loop should have
+ been updated as: from += rd->block_size; and to += rd->block_size;
+ within the for loops in the ramdisk_read and ramdisk_write routines,
+ respectively.
+
+2002-04-08 Chris Johns <ccj@acm.org>
+
+ * Per PR142, make task switch extension its own list.
+ * posix/src/pthread.c (_POSIX_Threads_User_extensions): Reflect above.
+ * Per PR141 and PR174, make task switch extension its own list and fix
+ all odd problems introduced by providing macro version.
+ * score/inline/rtems/score/userext.inl: Fix.
+ * Per PR142, make task switch extension its own list.
+ * score/include/rtems/score/userext.h: Reflect above by adding
+ User_extensions_Switch_control and adding it to User_extenions_Control.
+ * score/inline/rtems/score/userext.inl: Allocate all memory in one chunk
+ to minimize overhead. Address processing dedicated switch chain.
+ * Per PR142, make task switch extension its own list.
+ * score/include/rtems/score/userext.h: Reflect above by adding
+ User_extensions_Switch_control and adding it to User_extenions_Control.
+ * score/inline/rtems/score/userext.inl: Allocate all memory in one chunk
+ to minimize overhead. Address processing dedicated switch chain.
+ * Per PR142, make task switch extension its own list.
+ * rtems/src/tasks.c (_RTEMS_tasks_User_extensions): Reflect above.
+
+2002-04-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * include/rtems/bspIo.h: Fix cpp-guards, remove references to i386.
+ * posix/src/psignal.c: Include <stdlib.h>.
+ * libblock/src/ramdisk.c, libblock/src/blkdev.c,
+ libfs/src/imfs/imfs_getchild.c: include <string.h>.
+ * libfs/src/imfs/imfs_gtkn.c, libfs/src/imfs/ioman.c,
+ libfs/src/imfs/linearfile.c, libfs/src/imfs/memfile.c: Include
+ <string.h>.
+ * libnetworking/ChangeLog: Fix dates.
+
+2002-04-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/monitor/mon-monitor.c: Replace done with return (gcc3).
+ * libfs/src/dosfs/fat.h: Include <string.h>. Remove DBG1 and DBG2
+ (unused).
+ * Per PR169.
+ * libfs/src/dosfs/config.h.in, libfs/src/dosfs/stamp-h2.in: Removed from
+ CVS.
+
+2002-04-03 Alexander Kukuta <kam@oktet.ru>
+
+ * libblock/include/rtems/bdbuf.h: Address PR168 by changing
+ bdbuf_buffer.avl.bal and bdbuf_buffer.avl.cache to signed char instead
+ of char.
+
+2002-04-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * posix/src/getegid.c: Remove <errno.h>.
+ * posix/src/geteuid.c, posix/src/getgid.c, posix/src/getuid.c: Ditto.
+ * posix/src/getlogin.c: Move <errno.h>.
+
+2002-03-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/libc/rcmd.c: Replace __rtems w/ __rtems__.
+
+2002-03-27 Thomas.Doerfler@imd-systems.de
+
+ PR 144
+ * libnetworking/nfs/bootp_subr.c bootpc_init(): Performs a write to
+ memory address 0 when called for the first time. This is done when
+ trying to clear the variable "dhcp_hostname".
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * include/Makefile.am, Makefile.am, wrapup/Makefile.am: Remove
+ AUTOMAKE_OPTIONS.
+ * itron/configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * itron/include/Makefile.am, itron/Makefile.am,
+ itron/inline/Makefile.am, itron/macros/Makefile.am,
+ itron/src/Makefile.am: Remove AUTOMAKE_OPTIONS.
+ * posix/configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * posix/src/Makefile.am, posix/Makefile.am, posix/include/Makefile.am,
+ posix/inline/Makefile.am, posix/macros/Makefile.am,
+ score/cpu/Makefile.am, score/src/Makefile.am, score/Makefile.am,
+ score/include/Makefile.am, score/inline/Makefile.am,
+ score/macros/Makefile.am, sapi/Makefile.am, sapi/include/Makefile.am,
+ sapi/inline/Makefile.am, sapi/macros/Makefile.am, sapi/src/Makefile.am,
+ rtems/Makefile.am, rtems/include/Makefile.am, rtems/inline/Makefile.am,
+ rtems/macros/Makefile.am, rtems/src/Makefile.am: Remove AUTOMAKE_OPTIONS.
+ * libmisc/configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * libmisc/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dummy/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/monitor/Makefile.am,
+ libmisc/mw-fb/Makefile.am, libmisc/rootfs/Makefile.am,
+ libmisc/rtmonuse/Makefile.am, libmisc/shell/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am,
+ libmisc/wrapup/Makefile.am: Remove AUTOMAKE_OPTIONS.
+ * librpc/configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * librpc/include/rpc/Makefile.am, librpc/include/Makefile.am,
+ librpc/include/rpcsvc/Makefile.am, librpc/Makefile.am,
+ librpc/src/rpc/PSD.doc/Makefile.am, librpc/src/rpc/Makefile.am,
+ librpc/src/xdr/Makefile.am, librpc/src/Makefile.am: Remove
+ AUTOMAKE_OPTIONS.
+ * libblock/configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * libblock/include/Makefile.am, libblock/Makefile.am,
+ libblock/src/Makefile.am: Remove AUTOMAKE_OPTIONS.
+ * libfs/src/dosfs/fat_file.c: Remove bsp.h. fat_file_write(.. const
+ char*buf ..).
+ * libfs/src/dosfs/fat_file.h: fat_file_write(.. const char*buf ..).
+ * libfs/configure.ac: AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * libfs/src/dosfs/Makefile.am, libfs/src/Makefile.am,
+ libfs/src/imfs/Makefile.am, libfs/Makefile.am, libfs/wrapup/Makefile.am:
+ Remove AUTOMAKE_OPTIONS.
+ * libnetworking/configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS). AM_INIT_AUTOMAKE([no-define
+ foreign 1.6]).
+ * libnetworking/arpa/Makefile.am, libnetworking/kern/Makefile.am,
+ libnetworking/Makefile.am, libnetworking/lib/Makefile.am,
+ libnetworking/libc/Makefile.am, libnetworking/machine/Makefile.am,
+ libnetworking/net/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/nfs/Makefile.am, libnetworking/pppd/Makefile.am,
+ libnetworking/rtems/Makefile.am,
+ libnetworking/rtems_servers/Makefile.am,
+ libnetworking/rtems_telnetd/Makefile.am,
+ libnetworking/rtems_webserver/Makefile.am,
+ libnetworking/sys/Makefile.am, libnetworking/vm/Makefile.am,
+ libnetworking/wrapup/Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-03-27 Ilya Alexeev <ilya@continuum.ru>
+
+ PR 162
+ * libnetworking/net/if_ppp.c ppp_txdaemon(),
+ libnetworking/net/if_pppvar.h pppstart(): Local variables must not be
+ used in a device write routines. Now ppp_softc structure have own
+ character for writing to device (sc_outchar). I think that converting
+ local variables to static is not a right solution, because problems will
+ occur in the case of two or more ppp instances.
+ * libnetworking/net/ppp_tty.c pppstart(): Type of the ioffset variable
+ must be u_long, otherwise in the case of the big output packet endless
+ loop may occur.
+
+2002-03-25 Eric Norum <norume@aps.anl.gov>
+
+ PR 374/networking
+ * libnetworking/Makefile.am, libnetworking/rtems/rtems_bsdnet.h,
+ libnetworking/rtems/rtems_glue.c: The patch sent as part of PR270 got
+ applied to the wrong place. The effect was that (1) startup was no
+ faster than before and (2) malloc starvation messages came way too
+ quickly. The attached patch fixes both these problems and also provides
+ a mechanism for applications to handle malloc starvation conditions as
+ they see fit.
+ * libnetworking/rtems/rtems_bsdnet_malloc_starvation.c: New file.
+
+2002-03-21 Ilya Alexeev <ilya@continuum.ru>
+
+ * libnetworking/net/if_ppp.c, libnetworking/net/ppp_tty.c: Initial
+ preparations for multiple PPPD connections.
+
+2002-03-21 Alexander Kukuta <kam@oktet.ru>
+
+ * libblock/src/bdbuf.c (avl_insert, libblock/avl_remove): Reimplemented
+ from scratch to avoid using GPLed sources in RTEMS core.
+ * libblock/src/bdbuf.c, libblock/include/rtems/bdbuf.h: Remove "binary
+ tree" implementation which was used for debugging only.
+
+2002-03-20 Chris Johns <ccj@acm.org>
+
+ PR 192
+ * libmisc/monitor/mon-command.c: The RTEMS monitor makes everything
+ lowercase. The capture engine need to set triggers or watches on task
+ with uppercase names. Also stop the monitor repeating command when
+ enter is pressed.
+ PR 148.
+ * libmisc/monitor/mon-prmisc.c: Fixed to print task states correctly.
+
+2002-03-16 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 140
+ * libfs/src/dosfs/config.h.in, libfs/src/dosfs/stamp-h2.in: Removed.
+ * libfs/.cvsignore: Add config.h*, stamp-h*.
+ * libfs/configure.ac: Remove AC_SRC_DIR(.../dosfs.h). Remove
+ AM_CONFIG_HEADER(src/dosfs/config.h). Remove
+ AM_CONFIG_HEADER(src/imfs/config.h). Add AM_CONFIG_HEADER(config.h).
+ * libfs/src/dosfs/Makefile.am, libfs/src/imfs/Makefile.am: INCLUDES =
+ -I../...
+
+2002-03-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 130
+ * libfs/src/dosfs/Makefile.am: Reworked, Disable dosfs for UNIX.
+ * libfs/wrapup/Makefile.am: Disable dosfs for UNIX.
+
+2002-03-13 Victor V. Vengerov <vvv@oktet.ru>
+
+ * libblock/src/bdbuf.c (find_or_assign_buffer,
+ libblock/rtems_bdbuf_read, libblock/rtems_bdbuf_sync,
+ libblock/rtems_bdbuf_syncdev, libblock/bdbuf_swapout_task): Fix bug:
+ disable interrupts and set level properly before _CORE_mutex_Seize
+ invocation).
+
+2002-03-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Add __RTEMS_REVISION__.
+
+2002-03-01 Eric Norum <eric.norum@usask.ca>
+
+ * posix/src/pthreadonce.c: Task is not preemptable while running a
+ pthread_once init function. This is slightly less heavy handed than
+ disabling dispatching and seems better than consuming a mutex.
+
+2002-02-28 Victor V. Vengerov <vvv@oktet.ru>
+
+ * DOS filesystem including FAT12, FAT16, and FAT32 support submitted.
+ * libfs/src/dosfs, libfs/src/dosfs/Makefile.am,
+ libfs/src/dosfs/stamp-h2.in, libfs/src/dosfs/config.h.in,
+ libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h,
+ libfs/src/dosfs/fat_fat_operations.c,
+ libfs/src/dosfs/fat_fat_operations.h, libfs/src/dosfs/fat_file.c,
+ libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h,
+ libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_dir.c,
+ libfs/src/dosfs/msdos_eval.c, libfs/src/dosfs/msdos_file.c,
+ libfs/src/dosfs/msdos_free.c, libfs/src/dosfs/msdos_fsunmount.c,
+ libfs/src/dosfs/msdos_handlers_dir.c,
+ libfs/src/dosfs/msdos_handlers_file.c, libfs/src/dosfs/msdos_init.c,
+ libfs/src/dosfs/msdos_initsupp.c, libfs/src/dosfs/msdos_misc.c,
+ libfs/src/dosfs/msdos_mknod.c, libfs/src/dosfs/msdos_node_type.c,
+ libfs/src/dosfs/.cvsignore: New files.
+ * libfs/configure.ac, libfs/src/Makefile.am, libfs/wrapup/Makefile.am:
+ Modified to reflect addition.
+
+2002-02-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Add __RTEMS_MAJOR__, __RTEMS_MINOR__.
+
+2002-02-28 Joel Sherrill <joel@OARcorp.com>
+
+ * Submitted by Victor V. Vengerov <vvv@oktet.ru> and merged into the
+ RTEMS source.
+ * libblock/ChangeLog, libblock/Makefile.am, libblock/README,
+ libblock/configure.ac, libblock/include/Makefile.am,
+ libblock/include/rtems/bdbuf.h, libblock/include/rtems/blkdev.h,
+ libblock/include/rtems/diskdevs.h, libblock/include/rtems/ramdisk.h,
+ libblock/include/rtems/.cvsignore, libblock/include/.cvsignore,
+ libblock/src/Makefile.am, libblock/src/bdbuf.c, libblock/src/blkdev.c,
+ libblock/src/diskdevs.c, libblock/src/ramdisk.c,
+ libblock/src/.cvsignore, libblock/.cvsignore: New files.
+
+2002-02-27 Ilya Alexeev <ilya@continuum.ru>
+
+ * libnetworking/net/if_ppp.c, libnetworking/pppd/auth.c,
+ libnetworking/pppd/chat.c, libnetworking/pppd/pppd.h,
+ libnetworking/pppd/sys-rtems.c: Add server with pap-authorization
+ capabilities as well as eliminate some warnings.
+
+2002-02-27 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/net/radix.c: Properly handle fetching the default route
+ when there is no route. This was a bug in the original FreeBSD code and
+ this fix is from an updated version of their code.
+
+2002-02-16 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.clib/tftpDriver.c: Fix TFTP block number
+ checking.
+
+2002-02-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * posix/src/getegid.c: Add #include <rtems/userenv.h>. Remove #include
+ <rtems/libio_.h>.
+ * posix/src/geteuid.c, posix/src/getgid.c, posix/src/getlogin.c,
+ posix/src/getuid.c: Ditto.
+
+2002-02-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Readded reference to wrapup.
+ * posix/configure.ac: AC_CONFIG_SRCDIR([src/pthreads.c]).
+ * posix/src/psignal.c: #include <string.h>.
+ * libnetworking/pppd/sys-rtems.c: Remove unused variable status from
+ dodefaultroute.
+
+2002-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/lib/tftpDriver.c: Remove set_errno_and_return_minus_one,
+ include <rtems/seterr.h>.
+
+2002-02-01 Mike Siers <mikes@poliac.com>
+
+ * libnetworking/pppd/rtemspppd.c (rtems_pppd_disconnect): Modified to
+ avoid bringing the link down too fast. NOTE: Mike reports successfully
+ running at 56K baud on a direct link.
+
+2002-01-31 Mike Siers <mikes@poliac.com>
+
+ * libnetworking/pppd/rtemsdialer.h: New file missed in previous commit.
+ * libnetworking/*: Update of PPPD support which eliminates the
+ requirement that drivers be in the termios TASK_DRIVEN mode. Mike did
+ significant testing and reports that it seems to be more stable and
+ handle larger packets better. This patch replaces the termios tasks
+ with more general pppd network driver tasks. The functions pppinput()
+ and pppstart() get called from the interrupt service routine.
+ * libnetworking/Makefile.am, libnetworking/configure.ac,
+ libnetworking/net/Makefile.am, libnetworking/net/bpf.h,
+ libnetworking/net/ethernet.h, libnetworking/net/if.c,
+ libnetworking/net/if.h, libnetworking/net/if_arp.h,
+ libnetworking/net/if_dl.h, libnetworking/net/if_ethersubr.c,
+ libnetworking/net/if_llc.h, libnetworking/net/if_loop.c,
+ libnetworking/net/if_ppp.h, libnetworking/net/if_pppvar.h,
+ libnetworking/net/if_types.h, libnetworking/net/netisr.h,
+ libnetworking/net/ppp-comp.h, libnetworking/net/ppp_defs.h,
+ libnetworking/net/pppcompress.h, libnetworking/net/radix.c,
+ libnetworking/net/radix.h, libnetworking/net/raw_cb.c,
+ libnetworking/net/raw_cb.h, libnetworking/net/raw_usrreq.c,
+ libnetworking/net/route.c, libnetworking/net/route.h,
+ libnetworking/net/rtsock.c, libnetworking/pppd/Makefile.am,
+ libnetworking/pppd/README, libnetworking/pppd/STATUS,
+ libnetworking/pppd/auth.c, libnetworking/pppd/cbcp.c,
+ libnetworking/pppd/ccp.c, libnetworking/pppd/ccp.h,
+ libnetworking/pppd/chap.c, libnetworking/pppd/chap.h,
+ libnetworking/pppd/chap_ms.c, libnetworking/pppd/chap_ms.h,
+ libnetworking/pppd/chat.c, libnetworking/pppd/demand.c,
+ libnetworking/pppd/fsm.c, libnetworking/pppd/fsm.h,
+ libnetworking/pppd/ipcp.c, libnetworking/pppd/ipcp.h,
+ libnetworking/pppd/ipxcp.c, libnetworking/pppd/ipxcp.h,
+ libnetworking/pppd/lcp.c, libnetworking/pppd/lcp.h,
+ libnetworking/pppd/magic.c, libnetworking/pppd/magic.h,
+ libnetworking/pppd/options.c, libnetworking/pppd/patchlevel.h,
+ libnetworking/pppd/pathnames.h, libnetworking/pppd/pppd.8,
+ libnetworking/pppd/pppd.h, libnetworking/pppd/rtemsmain.c,
+ libnetworking/pppd/rtemspppd.c, libnetworking/pppd/rtemspppd.h,
+ libnetworking/pppd/sys-rtems.c, libnetworking/pppd/upap.c,
+ libnetworking/pppd/upap.h, libnetworking/pppd/utils.c,
+ libnetworking/pppd/example/README,
+ libnetworking/pppd/example/netconfig.h,
+ libnetworking/wrapup/Makefile.am: Modified.
+ * libnetworking/net/bsd-comp.c, libnetworking/net/if_ppp.c,
+ libnetworking/net/ppp-deflate.c, libnetworking/net/ppp.h,
+ libnetworking/net/ppp_tty.c, libnetworking/net/pppcompress.c,
+ libnetworking/net/zlib.c, libnetworking/net/zlib.h: New file.
+ * libnetworking/modem/, libnetworking/modem/.cvsignore,
+ libnetworking/modem/Makefile.am, libnetworking/modem/ppp.c,
+ libnetworking/modem/ppp.h, libnetworking/modem/ppp_tty.c,
+ libnetworking/modem/pppcompress.c: Subdirectory removed.
+
+2002-01-29 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/score/watchdog.h: Added WATCHDOG_MAXIMUM_INTERVAL.
+
+2002-01-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/shell/shell.c: Remove #undef __STRICT_ANSI__.
+
+2002-01-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/configure.ac: Fix tests for GCC.
+
+2002-01-24 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/configure.ac: Add check for weak function attribute. Remove
+ AM_CONDITIONAL([RTEMS_LIBSHELL]. Add AM_CONDITIONAL(LIBSHELL),
+ AM_CONDITIONAL(LIBSERDBG).
+ * libmisc/capture/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dummy/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/monitor/Makefile.am,
+ libmisc/mw-fb/Makefile.am, libmisc/rtmonuse/Makefile.am: Use *.a instead
+ of *-tmp.a.
+ * libmisc/serdbg/Makefile.am: Use *.a instead of *-tmp.a. Build iff
+ LIBSERDBG is true.
+ * libmisc/shell/Makefile.am: Use *.a instead of *-tmp.a. Build iff
+ LIBSHELL is true.
+ * libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am: Use *.a
+ instead of *-tmp.a.
+ * libmisc/wrapup/Makefile.am: Reflect changes above.
+
+2002-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/rtems_telnetd/pty.c: Move config.h to were it belongs.
+ Remove printf (Reported by Till Straumann <strauman@SLAC.Stanford.EDU>).
+
+2002-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Fix typo in yesterday's change:
+ RTEMS_MULTILIBS.
+
+2002-01-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Apply @subdirs. Remove POSIX_SUBDIRS. Remove
+ ITRON_SUBDIRS.
+ * configure.ac: Rework enable_unixlib handling. Add RTEMS_MULTILIBS to
+ cpuopts.h.
+ * include/Makefile.am: Add rtems/fs.h, rtems/userenv.h. Add
+ $(PROJECT_INCLUDE)/rtems. Remove libio_.h.
+
+2002-01-07 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/Makefile.am: Add install-hook. Remove SIZE_RTEMS.
+ * include/rtems/fs.h: New, extracted from libio_.h.
+ * include/rtems/userenv.h: New. extracted from libio_.h.
+ * libmisc/rootfs/Makefile.am: Use include_rtems_HEADERS instead of
+ H_FILES.
+ * libfs/src/imfs/imfs_load_tar.c: Add include <sys/types.h>. Add include
+ <sys/stat.h>. Add include <fcntl.h>.
+ * libfs/src/imfs/imfs_rmnod.c: Add include <stdlib.h>.
+
+2002-01-07 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/optman/, posix/optman/.cvsignore, posix/optman/Makefile.am,
+ sapi/optman/, sapi/optman/.cvsignore, sapi/optman/Makefile.am,
+ sapi/optman/no-ext.c, sapi/optman/no-io.c, rtems/optman/,
+ rtems/optman/.cvsignore, rtems/optman/Makefile.am,
+ rtems/optman/no-dpmem.c, rtems/optman/no-event.c, rtems/optman/no-mp.c,
+ rtems/optman/no-msg.c, rtems/optman/no-part.c, rtems/optman/no-region.c,
+ rtems/optman/no-rtmon.c, rtems/optman/no-sem.c,
+ rtems/optman/no-signal.c, rtems/optman/no-timer.c: Removed entire
+ contents of optman/ directory since it has been moved.
+
+2002-01-06 Joel Sherrill <joel@OARcorp.com>
+
+ * wrapup/.cvsignore: Readded.
+ * include/.cvsignore: New file.
+
+2002-01-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/seterr.h: Add do {..} while (0) in defines. Rename
+ set_errno_and_return_minus_one into rtems_set_errno_and_return_minus_one.
+ * libmisc/mw-fb/mw_uid.c: Apply rtems_set_errno_and_return_minus_one.
+ * libfs/src/imfs/imfs_eval.c, libfs/src/imfs/memfile.c,
+ libfs/src/imfs/imfs_readlink.c, libfs/src/imfs/imfs_unlink.c,
+ libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_chown.c,
+ libfs/src/imfs/ioman.c, libfs/src/imfs/imfs_mount.c,
+ libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_stat.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/imfs_symlink.c,
+ libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/linearfile.c,
+ libfs/src/imfs/imfs_unmount.c: Include <rtems/seterr.h>. Apply
+ rtems_set_errno_and_return_minus_one.
+ * libfs/src/imfs/imfs.h: Apply rtems_set_errno_and_return_minus_one.
+ Comment out increment_and_check_linkcounts.
+
+2002-01-04 Joel Sherrill <joel@OARcorp.com>
+
+ * Makefile.am, configure.ac: Remove references to wrapup subdirectory.
+
+2001-12-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AS_IF instead of if/then/else. Add
+ AC_DEFINE_UNQUOTED(RTEMS_UNIX) for RTEMS_CPU==unix. Add
+ AC_DEFINE_UNQUOTED(RTEMS_UNIXLIB) for RTEMS_CPU==unix. Add
+ include/Makefile to CONFIG_FILES. Add AC_ENABLE_MULITLIB. Remove
+ wrapup/rtems, wrapup/itron, wrapup/posix. Remove */optman/Makefile from
+ CONFIG_FILES.
+ * Makefile.am: Add include to SUBDIRS.
+ * rtems/Makefile.am, sapi/Makefile.am: Remove optman from SUBDIRS.
+ * include/Makefile.am: New file.
+ * include/rtems/bspIo.h, include/rtems/libio_.h: Relocated from
+ lib/include.
+ * posix/configure.ac: Remove optman/Makefile from CONFIG_FILES.
+ * posix/Makefile.am: Remove optman from SUBDIRS.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/posix/Makefile.am, wrapup/itron/Makefile.am,
+ wrapup/rtems/Makefile.am, Makefile.am, itron/src/Makefile.am: Add
+ multilib support.
+ * posix/optman/Makefile.am: Add multilib support. Remove ASM4FLAGS.
+ * posix/src/Makefile.am: Add multilib support.
+ * score/inline/rtems/score/object.inl,
+ score/macros/rtems/score/object.inl: Add add casts to Objects_Id in
+ _Objects_Build_ids to avoid implicit typecasts from enum to int16 on
+ bit16 targets (here: h8300).
+ * score/src/Makefile.am, sapi/optman/Makefile.am, sapi/src/Makefile.am,
+ rtems/src/Makefile.am, rtems/optman/Makefile.am: Add multilib support.
+
+2001-12-18 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.c: Allow chdir() to work on TFTP
+ `directories' (path names with a / at the end) while disallowing open()
+ operations on TFTP `directories'.
+
+2001-12-07 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.c: Restore write capability.
+
+2001-11-29 Victor V. Vengerov <vvv@oktet.ru>
+
+ * AVL trees implementation added.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ PR 91
+ * score/include/rtems/score/isr.h, score/inline/rtems/score/isr.inl,
+ score/macros/rtems/score/isr.inl: Modified to allow any port to provide
+ its own implementation of the macro _ISR_Is_in_progress. If the port
+ overrides this macro, it must provide a non-inlined function
+ implementation.
+
+2001-11-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libfs/wrapup/Makefile.am: Remove HAS_IMFS.
+
+2001-11-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libfs/src/imfs/Makefile.am: Cleanup.
+ * libnetworking/arpa/Makefile.am: Remove stray lines.
+
+2001-11-20 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/threadhandler.c: When __USE__MAIN__ is defined by the
+ toolset, invoke the global constructors via __main. Reported as tested
+ by Alexandra Kossovsky <sasha@oktet.ru> and Victor V. Vengerov
+ <vvv@oktet.ru> in conjunction with a new set of tool RPMs
+ (gcc2.95.3newlib1.9.0-3). This was tracked as GNATS PR tools/84.
+
+2001-11-16 Victor V. Vengerov <vvv@oktet.ru>
+
+ * libblock/include/rtems/bdbuf.h,
+ libblock/src/bdbuf.c(rtems_bdbuf_syncdev): New.
+
+2001-11-07 Victor V. Vengerov <vvv@oktet.ru>
+
+ * libblock/ChangeLog: New file.
+ * libblock/src/, libblock/include/, libblock/include/rtems/: New
+ directories.
+ * libblock/README, libblock/configure.ac, libblock/Makefile.am,
+ libblock/src/Makefile.am, libblock/include/Makefile.am,
+ libblock/include/rtems/bdbuf.h include/rtems/blkdev.h
+ include/rtems/diskdevs.h include/rtems/ramdisk.h src/bdbuf.c
+ src/blkdev.c src/diskdevs.c src/ramdisk.c: New files.
+
+2001-11-07 Joel Sherrill <joel@OARcorp.com>
+
+ Discovered while fixing PR36 reported by Todor.Todorov@barco.com.
+ * itron/include/rtems/itron/object.h: Corrected _ITRON_Objects_Get() to
+ use _Objects_Get_by_index().
+ PR 36 (Reported by Todor.Todorov@barco.com)
+ * score/include/rtems/score/object.h: Added prototype for
+ _Objects_Get_by_index().
+ * score/src/objectget.c, score/src/objectgetisr.c: Corrected procedure
+ for getting index from Id so it is correct and optimal for both single
+ and multiprocessor configurations.
+
+2001-11-07 Jennifer Averett <jennifer@OARcorp.com>
+
+ Reported by Ibragimov Ilya <ibr@oktet.ru> and tracked as PR49.
+ * libfs/ src/imfs/imfs_directory.c: Do not calculate the offset twice.
+
+2001-10-26 Victor V. Vengerov <vvv@oktet.ru>
+
+ * libfs/src/imfs/imfs_load_tar.c: Minor modification so this will
+ compile with gcc-2.95.3 with the arguments "-m5200 -O4".
+
+2001-10-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/macros/Makefile.am: Replace INLINES w/ MACROS (Fix stupid typo
+ in previous patch).
+
+2001-10-23 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/macros/rtems/rtems/asr.nil: Fixed typo.
+
+2001-10-22 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/threadhandler.c: Use __USE_INIT_FINI__ since USE_INIT_FINI
+ pollutes the application namespace.
+
+2001-10-18 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.c: Properly handles ../ components in
+ chdir() and open() operations within the TFTP file system.
+
+2001-10-16 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use RTEMS_CPU_SUBDIRS to make autoconf-2.52 happy.
+ * configure.ac: Use AC_CONFIG_SUBDIRS for posix and itron. Reflect
+ changes to configuration of rtems, score and sapi subdirs.
+ * Makefile.am: require automake-1.5.
+ * itron/include/itronsys/Makefile.am, itron/include/rtems/Makefile.am,
+ itron/include/rtems/itron/Makefile.am, itron/inline/rtems/Makefile.am,
+ itron/inline/rtems/itron/Makefile.am, itron/macros/rtems/Makefile.am,
+ itron/macros/rtems/itron/Makefile.am: Remove.
+ * itron/include/Makefile.am, itron/inline/Makefile.am,
+ itron/macros/Makefile.am: handle subdirs.
+ * itron/configure.ac: Reflect changes above.
+ * posix/include/sys/Makefile.am, posix/include/rtems/Makefile.am,
+ posix/include/rtems/posix/Makefile.am: Remove.
+ * posix/include/Makefile.am: Handle subdirs.
+ * posix/inline/rtems/Makefile.am, posix/inline/rtems/posix/Makefile.am:
+ Remove.
+ * posix/inline/Makefile.am: Handle subdirs.
+ * posix/macros/rtems/Makefile.am, posix/macros/rtems/posix/Makefile.am:
+ Remove.
+ * posix/macros/Makefile.am: Handle subdirs.
+ * posix/configure.ac: Reflect changes above.
+ * score/include/rtems/Makefile.am, score/include/rtems/Makefile.am:
+ Remove.
+ * score/include/Makefile.am: Handle subdirs, require automake-1.5.
+ * score/macros/rtems/Makefile.am, score/macros/rtems/score/Makefile.am:
+ Remove.
+ * score/macros/Makefile.am: Handle subdirs, require automake-1.5.
+ * score/inline/rtems/Makefile.am, score/inline/rtems/score/Makefile.am:
+ Remove.
+ * score/inline/Makefile.am: Handle subdirs, require automake-1.5.
+ * score/Makefile.am: require automake-1.5.
+ * sapi/include/rtems/Makefile.am: Remove.
+ * sapi/include/Makefile.am: Handle subdirs, require automake-1.5.
+ * sapi/inline/rtems/Makefile.am: Remove.
+ * sapi/inline/Makefile.am: Handle subdirs, require automake-1.5.
+ * sapi/macros/rtems/Makefile.am: Remove.
+ * sapi/Makefile.am: require automake-1.5.
+ * rtems/include/rtems/Makefile.am,
+ rtems/include/rtems/rtems/Makefile.am: Remove.
+ * rtems/include/Makefile.am: Handle subdirs, require automake-1.5.
+ * rtems/inline/rtems/Makefile.am, rtems/inline/rtems/rtems/Makefile.am:
+ Remove.
+ * rtems/inline/Makefile.am: Handle subdirs, require automake-1.5.
+ * rtems/macros/rtems/Makefile.am, rtems/macros/rtems/rtems/Makefile.am:
+ Remove.
+ * rtems/macros: Handle subdirs, require automake-1.5.
+ * rtems/Makefile.am: require automake-1.5.
+
+2001-10-16 Joel Sherrill <joel@OARcorp.com>
+
+ * score/.cvsignore: Add stamp-h.in.
+ * score/include/Makefile.am: Fixed path to cpuopts-tmp.h.
+
+2001-10-16 Chris Johns <ccj@acm.org>
+
+ * sapi/include/confdefs.h, sapi/include/rtems/config.h,
+ sapi/include/rtems/io.h, sapi/optman/no-io.c, sapi/src/exinit.c,
+ sapi/src/io.c: Added a device driver register/unregister interface to
+ allow device drivers to be installed and removed at runtime. This means
+ you do not need devices present in the device table when you build.
+ * libfs/imfs/imfs_load_tar.c: Changed the code around to remove an
+ internal compiler error on the Coldfire target.
+
+2001-10-12 Mike Siers <mikes@poliac.com>
+
+ * Update to stable working state.
+ * libnetworking/modem_example/16550.h,
+ libnetworking/modem_example/README, libnetworking/modem_example/modem.c,
+ libnetworking/modem_example/modem.h, libnetworking/modem_example/ppp.c,
+ libnetworking/modem_example/ppp.h,
+ libnetworking/modem_example/pppcompress.c: Files removed.
+ * libnetworking/pppd/example/pppd.options: New file.
+ * libnetworking/pppd/README, libnetworking/pppd/STATUS,
+ libnetworking/pppd/cbcp.c, libnetworking/pppd/cbcp.h,
+ libnetworking/pppd/chat.c, libnetworking/pppd/pppd.h,
+ libnetworking/pppd/rtemsmain.c: Updated.
+
+2001-10-12 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/rtems/directives.h, libmisc/rootfs/mkrootfs.c,
+ libmisc/rootfs/mkrootfs.h: Fixed typo.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+ * itron/.cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * itron/configure.in: Remove.
+ * itron/configure.ac: New file, generated from configure.in by
+ autoupdate.
+ * posix/.cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * posix/configure.in: Remove.
+ * posix/configure.ac: New file, generated from configure.in by
+ autoupdate.
+ * libmisc/.cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * libmisc/configure.in: Remove.
+ * libmisc/configure.ac: New file, generated from configure.in by
+ autoupdate.
+ * librpc/.cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * librpc/configure.in: Remove.
+ * librpc/configure.ac: New file, generated from configure.in by
+ autoupdate.
+ * libfs/.cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * libfs/configure.in: Remove.
+ * libfs/configure.ac: New file, generated from configure.in by
+ autoupdate.
+ * libnetworking/.cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * libnetworking/configure.in: Remove.
+ * libnetworking/configure.ac: New file, generated from configure.in by
+ autoupdate.
+
+2001-10-10 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/imfs_getchild.c: Correct length of static string as
+ reported by Ibragimov Ilya <ibr@oktet.ru>.
+
+2001-09-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/score/Makefile.am,
+ score/include/rtems/Makefile.am, score/inline/rtems/score/Makefile.am,
+ score/macros/rtems/score/Makefile.am, sapi/include/rtems/Makefile.am,
+ sapi/include/Makefile.am, sapi/inline/rtems/Makefile.am,
+ sapi/macros/rtems/Makefile.am, rtems/include/rtems/rtems/Makefile.am,
+ rtems/include/Makefile.am, rtems/inline/rtems/rtems/Makefile.am,
+ rtems/macros/rtems/rtems/Makefile.am, libmisc/untar/Makefile.am,
+ libmisc/monitor/Makefile.am, libmisc/shell/Makefile.am,
+ libmisc/devnull/Makefile.am, libmisc/dumpbuf/Makefile.am,
+ libmisc/mw-fb/Makefile.am, libmisc/stackchk/Makefile.am,
+ libmisc/rtmonuse/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/rootfs/Makefile.am, librpc/include/rpc/Makefile.am,
+ libfs/src/imfs/Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-09-28 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/mqueueopen.c, posix/src/semopen.c: Clarify type on va_arg.
+ * libmisc/dummy/dummy.c: Now a useful configuration that starts main().
+ * libmisc/wrapup/Makefile.am: Include a base level configuration in
+ RTEMS library.
+
+2001-09-27 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/ChangeLog: Fixed typo in date.
+
+2001-09-27 Eric Norum <eric.norum@usask.ca>
+
+ * score/src/threadhandler.c: Now process C++ global constructors (_init)
+ as part of the first task execution not in BSP space. This depends on
+ the toolset defining USE_INIT_FINI so you have to have the right toolset
+ version.
+ * libnetworking/lib/tftpDriver.c: Add limited chdir() support to the
+ TFTP filesystem.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * itron/include/itronsys/Makefile.am,
+ itron/include/rtems/itron/Makefile.am, itron/include/Makefile.am,
+ itron/inline/rtems/itron/Makefile.am,
+ itron/macros/rtems/itron/Makefile.am, posix/include/sys/Makefile.am,
+ posix/include/rtems/posix/Makefile.am, posix/include/Makefile.am,
+ posix/inline/rtems/posix/Makefile.am,
+ posix/macros/rtems/posix/Makefile.am,
+ score/include/rtems/score/Makefile.am, score/include/rtems/Makefile.am,
+ score/inline/rtems/score/Makefile.am,
+ score/macros/rtems/score/Makefile.am, libnetworking/machine/Makefile.am,
+ libnetworking/net/Makefile.am, libnetworking/netinet/Makefile.am,
+ libnetworking/vm/Makefile.am, libnetworking/pppd/Makefile.am,
+ libnetworking/sys/Makefile.am, libnetworking/rtems_servers/Makefile.am,
+ libnetworking/arpa/Makefile.am, libnetworking/nfs/Makefile.am,
+ libnetworking/rtems_webserver/Makefile.am,
+ libnetworking/rtems/Makefile.am,
+ libnetworking/rtems_telnetd/Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-09-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/rtems/Makefile.am: Fix comments to make automake-1.5 happy.
+ * itron/src/Makefile.am: Revamp INCLUDES handling to make automake-1.5
+ happy.
+ * posix/optman/Makefile.am: Adapt ASM4FLAGS to automake-1.5 happy.
+ * posix/src/Makefile.am: Adapt INCLUDES to make automake-1.5 happy.
+ * sapi/optman/Makefile.am: Adapt ASM4FLAGS to automake-1.5.
+ * libfs/src/imfs/Makefile.am: Revamp INCLUDES handling to make
+ automake-1.5 happy.
+ * libnetworking/Makefile.am: Use PREINSTALL_FILES = to make automake-1.5
+ happy.
+
+2001-09-21 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/configure.in, libmisc/rootfs/Makefile.am: Added conditional to
+ make sure rootfs does not get built with networking is disabled. Also
+ added include of compile.am to rootfs/Makefile.am.
+ * libmisc/wrapup/Makefile.am: Added rootfs conditionally if networking
+ enabled.
+
+2001-09-19 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.c: Add some debugging capability.
+
+2001-09-19 Chris Johns <ccj@acm.org>
+
+ * Added support for populating the initial "root" filesystem with
+ information obtained via the DHCP response.
+ * libmisc/rootfs: New directory.
+ * libmisc/rootfs/.cvsignore, libmisc/rootfs/Makefile.am,
+ libmisc/rootfs/mkrootfs.c, libmisc/rootfs/mkrootfs.h: New files.
+ * libmisc/configure.in, libmisc/Makefile.am: Modified to reflect
+ addition.
+ * nfs/bootp_subr.c, rtems/rtems_bootp.c, rtems/rtems_bsdnet.h,
+ rtems/rtems_bsdnet_internal.h Added support for populating the initial
+ "root" filesystem with information obtained via the DHCP response.
+
+2001-09-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/aclocal/canonical-target-name.m4: Use AC_CANONICAL_TARGET
+ instead of AC_CANONICAL_SYSTEM.
+ * libmisc/aclocal/config-subdirs.m4: Use AS_MKDIR_P instead of
+ mkinstalldirs and mkdir.
+ * libmisc/aclocal/target.m4: Obsolete RTEMS_OUTPUT_BUILD_SUBDIRS, hack
+ RTEMS_CONFIG_BUILD_SUBDIRS, introduce _RTEMS_OUTPUT_BUILD_SUBDIRS.
+ * libmisc/aclocal/canonical-target-name.m4: Use AC_CANONICAL_TARGET
+ instead of AC_CANONICAL_SYSTEM.
+ * libmisc/aclocal/config-subdirs.m4: Use AS_MKDIR_P instead of
+ mkinstalldirs and mkdir.
+ * libmisc/aclocal/target.m4: Obsolete RTEMS_OUTPUT_BUILD_SUBDIRS, hack
+ RTEMS_CONFIG_BUILD_SUBDIRS, introduce _RTEMS_OUTPUT_BUILD_SUBDIRS.
+
+2001-09-14 Fernando Ruiz <fernando.ruiz@ctv.es>
+
+ * rtems/src/tasks.c: Dereference pointer passed to destructor.
+ * libmisc/shell/shell.c: Don't close file it wasn't open.
+
+2001-09-13 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/sysconf.c: Fix typo syntax error accidentally committed.
+ * posix/src/mprotect.c: New file. Stub required by some gcc's to pass
+ tests. In particular, about 350 ACATS tests fail if this is not present.
+ * posix/src/getpagesize.c: Ditto.
+ * posix/src/sysconf.c: Addition of Solaris value for _SC_STACK_PROT
+ required to pass about 350 ACATS test cases.
+ * posix/src/Makefile.am: Added new files.
+ * libmisc/devnull/devnull.c: Eliminate warning.
+
+2001-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/macros/rtems/posix/mqueue.inl: Add cast so negation works.
+ * score/ src/coremutex.c, score/src/coremutexseize.c,
+ score/src/coremutexsurrender.c, score/inline/rtems/score/coremutex.inl:
+ The per thread field resource_count should only be manipulated when a
+ mutex is priority ceiling or priority inherit. This was reported by
+ Chris Johns <ccj@acm.org> who also noticed that the use of switches for
+ all disciplines generated less efficient code than using explicit tests
+ for the one or two cases we were really interested in. Further review
+ of his modifications made it apparent that the "isa" methods to test
+ mutex discipline were not being used so this modification was swept into
+ the code as well.
+ * score/src/coremutexseize.c: Add missing code for proper handling of
+ nesting acquisitions. This only impacts building with inlines disabled
+ on the source with the "fast mutex" optimizations. This was post the 4.5
+ branch and did not impact released versions.
+ * rtems/inline/rtems/rtems/attr.inl: Correct typo and use correct
+ attribute RTEMS_SYSTEM_TASK. Reported by Chris Johns <ccj@acm.org>.
+
+2001-08-16 Mike Siers <mikes@poliac.com>
+
+ * libnetworking/pppd/STATUS: Updated by Joel based upon email from Mike.
+ * libnetworking/pppd/cbcp.c, libnetworking/pppd/cbcp.h: Readded files.
+ These support callback functionality that has not even been compiled
+ under RTEMS yet.
+ * libnetworking/pppd/*: Update of PPPD to 2.3.11 from 2.3.5 and addition
+ of an example application. - renamed error() function because of
+ namespace problems. - removed calls to the exit() function. - removed
+ extra files from the pppd source directory. - defined pppd task constant
+ values in rtemspppd.h. - modifyied example code to get actual tick per
+ second value. - placed the pppd 2.3.11 man page file (pppd.8) into the
+ pppd directory.
+ * libnetworking/pppd/cbcp.c, libnetworking/pppd/cbcp.h,
+ libnetworking/pppd/main.c, libnetworking/pppd/ppp_tty.c,
+ libnetworking/pppd/pppmain.c, libnetworking/pppd/rtems-ppp.c,
+ libnetworking/pppd/rtems-ppp.c: Deleted.
+ * libnetworking/pppd/pppd.8, libnetworking/pppd/rtemsmain.c,
+ libnetworking/pppd/rtemspppd.c, libnetworking/pppd/rtemspppd.h,
+ libnetworking/pppd/sys-rtems.c, libnetworking/pppd/utils.c,
+ libnetworking/pppd/example/Makefile, libnetworking/pppd/example/README,
+ libnetworking/pppd/example/init.c,
+ libnetworking/pppd/example/netconfig.h,
+ libnetworking/pppd/example/ppp.conf,
+ libnetworking/pppd/example/pppdapp.c,
+ libnetworking/pppd/example/system.h: New files.
+ * libnetworking/modem/ppp_tty.c, libnetworking/net/if_ppp.h,
+ libnetworking/pppd/Makefile.am, libnetworking/pppd/README,
+ libnetworking/pppd/STATUS, libnetworking/pppd/auth.c,
+ libnetworking/pppd/ccp.c, libnetworking/pppd/ccp.h,
+ libnetworking/pppd/chap.c, libnetworking/pppd/chap.h,
+ libnetworking/pppd/chap_ms.c, libnetworking/pppd/chap_ms.h,
+ libnetworking/pppd/chat.c, libnetworking/pppd/demand.c,
+ libnetworking/pppd/fsm.c, libnetworking/pppd/fsm.h,
+ libnetworking/pppd/ipcp.c, libnetworking/pppd/ipcp.h,
+ libnetworking/pppd/ipxcp.c, libnetworking/pppd/ipxcp.h,
+ libnetworking/pppd/lcp.c, libnetworking/pppd/lcp.h,
+ libnetworking/pppd/magic.c, libnetworking/pppd/magic.h,
+ libnetworking/pppd/options.c, libnetworking/pppd/patchlevel.h,
+ libnetworking/pppd/pathnames.h, libnetworking/pppd/pppd.h,
+ libnetworking/pppd/upap.c, libnetworking/pppd/upap.h: Modified.
+
+2001-08-16 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/mqueuesendsupp.c: Account for possibly blocking during the
+ core send operation.
+ * score/src/coremutexsurrender.c: Use holder thread not executing thread
+ because even though they may and often are the same it is not guaranteed
+ unless the proper attribute is set.
+ * score/include/rtems/score/coremsg.h, score/src/coremsgsubmit.c: Add a
+ new return status to account for blocking sends. Otherwise, the caller
+ will think that the returned message status will have the ultimate
+ results of the operation. If the send times out, the final status will
+ be in the return_code of the thread.
+ * rtems/src/msgqsubmit.c: Add a comment indicating that we do not have
+ to account for possibly blocking during the core send operation because
+ Classic API message queue send is always non-blocking.
+ * libnetworking/pppd/example/Makefile: Removed.
+ * libnetworking/pppd/example/Makefile-user: Added was Makefile. Renamed
+ to avoid bootstrap -c clobbering it.
+ * libnetworking/rtems_telnetd/.cvsignore: New file.
+
+2001-08-09 Keith Outwater <vac4050@cae597.rsc.raytheon.com>
+
+ * libmisc/monitor/mon-command.c: Add support for partial command
+ matching. The monitor used to have this functionality before it was
+ overhauled to support addition of user commands.
+
+2001-08-09 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/snd_mbx.c, itron/src/tsnd_mbf.c, posix/src/mqueuesendsupp.c,
+ score/include/rtems/score/coremsg.h,
+ score/inline/rtems/score/coremsg.inl, score/src/coremsgsubmit.c,
+ rtems/src/msgqsubmit.c: Unblocking message queue operations should NOT
+ use _Thread_Executing for return status since it is permissible to
+ invoke message send operations from an ISR. This was reported by Suvrat
+ Gupta <suvrat@utstar.com>.
+
+2001-08-09 Fernando-Ruiz Casas <correo@fernando-ruiz.com>
+
+ * libmisc/shell/pty.c: Moved to libnetworking/rtems_telnetd.
+ * libmisc/shell/Makefile.am, libmisc/shell/README, libmisc/shell/cmds.c,
+ libmisc/shell/shell.c, libmisc/shell/shell.h: Updates.
+ * libfs/src/imfs/imfs_eval.c: The CD_UP problem in imfs_eval has been
+ touched. The order of the questions is the key.
+ * libnetworking/Makefile.am, libnetworking/configure.in,
+ libnetworking/rtems_servers/Makefile.am,
+ libnetworking/rtems_servers/telnetd.c,
+ libnetworking/rtems_servers/telnetd.h,
+ libnetworking/rtems_telnetd/Makefile.am,
+ libnetworking/rtems_telnetd/README, libnetworking/rtems_telnetd/icmds.c,
+ libnetworking/rtems_telnetd/pty.c, libnetworking/rtems_telnetd/pty.h,
+ libnetworking/rtems_telnetd/telnetd.c,
+ libnetworking/rtems_telnetd/telnetd.h, libnetworking/wrapup/Makefile.am:
+ - pty and telnetd have a new subdir rtems_telnetd to avoid the side
+ effect when ftpd change. - the tcp/ip stats have been implemented into
+ icmds.c and started when telnetd daemon is started.
+ * libnetworking/rtems_servers/telnetd.c,
+ libnetworking/rtems_servers/telnetd.h: Removed.
+ * libnetworking/rtems_telnetd: New directory.
+ * libnetworking/rtems_telnetd/Makefile.am,
+ libnetworking/rtems_telnetd/README, libnetworking/rtems_telnetd/icmds.c,
+ libnetworking/rtems_telnetd/pty.c, libnetworking/rtems_telnetd/pty.h,
+ libnetworking/rtems_telnetd/telnetd.c,
+ libnetworking/rtems_telnetd/telnetd.h: New files.
+
+2001-07-06 Thomas Doerfler <Thomas.Doerfler@imd-systems.de>
+
+ * libfs/src/imfs/deviceio.c: Make sure errno gets set to reflect the
+ status from the driver.
+
+2001-06-14 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/shell/telnetd.c, libmisc/shell/telnetd.h: Moved to
+ libnetworking/rtems_servers so the network stack to address network
+ depenendency.
+ * libmisc/shell/Makefile.am: Modified to reflect above.
+ * libnetworking/rtems_servers/telnetd.c, libnetworking/shell/telnetd.h:
+ Moved from libmisc/shell so the network stack to address network
+ depenendency.
+ * libnetworking/rtems_servers/Makefile.am: Modified to reflect above.
+
+2001-05-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/rtems_servers/Makefile.am: Deleted blank lines.
+
+2001-05-25 Sergei Organov <osv@javad.ru>
+
+ * score/macros/rtems/score/coresem.inl,
+ score/inline/rtems/score/coresem.inl: Cut and paste problem incorrectly
+ enabled interrupts twice with the first time being too early.
+
+2001-05-25 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/shell/cmds.c: Removed code from inappropriate source.
+ * libfs/src/imfs/imfs_initsupp.c: Create the root node with the desired
+ permissions. Nodes should be created with the right permissions because
+ chmod() is not supported by the miniIMFS so changing after creation is
+ not possible.
+
+2001-05-24 Joel Sherrill <joel@OARcorp.com>
+
+ * libcsupport/src/.cvsignore: New file.
+
+2001-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
+
+ * posix/src/getegid.c, posix/src/geteuid.c, posix/src/getgid.c,
+ posix/src/getlogin.c, posix/src/getuid.c: Now save their values in
+ private user environment.
+ * libmisc/monitor/mon-prmisc.c: Correct print line.
+ * libmisc/shell/Makefile.am: Added new file telnetd.c.
+ * libmisc/shell/telnetd.c, libmisc/shell/telnetd.h, libmisc/shell/pty.c:
+ New files.
+ * libmisc/shell/shell.c, libmisc/shell/cmds.c, libmisc/shell/shell.h:
+ Numerous improvments: - The shell_init has a new parameter 'forever'
+ because in /dev/console you need that this process runs forever but in
+ tcp/ip not. (respawn?) - A new task for every session opened trought
+ tcp/ip telnet client. (the chargen,daytime and more are possible of
+ implementation but I ask me if they are necesary) - Exit from the
+ session delete the task and when the client fails too. - More cmds have
+ been implemented. (very reduced version of these) umask, chmod, id,
+ whoami, rm, cat, ... - A reduced line edit has been implemented. Ctrl-C
+ abort the input, Ctrl-d in the first position gives EOF (logout). '\b'
+ and DEL makes the rubout operation. I think that readline() for every
+ session spents a lot of resources.
+
+2001-05-17 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/macros/rtems/posix/mqueue.inl: Implemented missing routines to
+ support message queue FDs.
+ * score/macros/rtems/score/thread..inl: Implemented missing routines for
+ new libc reentrancy support.
+
+2001-05-14 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/src/threaddispatch.c, score/src/threadhandler.c: Per PR211 fix
+ saving/restoring floating point context. The fpsave and fprestore
+ routines are only used in a executing context which _is_ fp and hence
+ has the FPU enabled. The current behavior required the FPU always to be
+ on which is very dangerous if lazy context switching is used. [Joel
+ Note: Some ports explicitly enabled the FPU in the FP save and restore
+ routines to avoid this.] The patch also makes sure (on powerpc only)
+ that the FPU is disabled for integer tasks. Note that this is crucial if
+ deferred fp context switching is used. Otherwise, fp context corruption
+ may go undetected! Also note that even tasks which merely push/pop FP
+ registers to/from the stack without modifying them still MUST be FP
+ tasks - otherwise (if lazy FP context switching is used), FP register
+ corruption (of other, FP, tasks may occur)! Furthermore, (on PPC) by
+ default, lazy FP context save/restore is _disabled_.
+
+2001-05-14 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/dummy/Makefile.am, libmisc/wrapup/Makefile.am: Fixed to
+ generate a library of the same name.
+ * libnetworking/ChangeLog: Corrected -- entry should have been in
+ libchip.
+
+2001-05-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/score/.cvsignore: Add stamp-h, cpuopts.h,
+ cpuopts.h.in, cpuopts-tmp.h.
+ * libnetworking/libc/Makefile.am: Remove -D__STRICT_ANSI__.
+
+2001-05-09 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/src/exinit.c: Slightly rework initialization so there is a valid
+ thread as _Thread_Executing when the pre_tasking hook is called. This
+ allows one directives and malloc to potentially use mutex protection.
+
+2001-04-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/shell/cmds.c, libmisc/shell/shell.c: Remove fileno-hacks.
+ * libmisc/monitor/mon-symbols.c: Remove #undef __STRICT_ANSI__.
+
+2001-04-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.in, itron/configure.in, posix/configure.in,
+ libfs/configure.in: Add [-ansi -fasm] to RTEMS_PROG_CC_FOR_TARGET.
+
+2001-04-26 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/include/rtems/posix/mqueue.h,
+ posix/inline/rtems/posix/mqueue.inl, posix/src/mqueue.c,
+ posix/src/mqueueclose.c, posix/src/mqueuecreatesupp.c,
+ posix/src/mqueuegetattr.c, posix/src/mqueuenotify.c,
+ posix/src/mqueueopen.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c: Per PR81 reworked
+ to add a message queue descriptor separate from the underlying message
+ queue. This allows non-blocking to follow the "open" not the underlying
+ queue.
+ * score/src/objectcomparenamestring.c: Fix typos.
+ * score/include/rtems/score/object.h,
+ score/inline/rtems/score/object.inl, score/
+ src/objectcomparenamestring.c: Address PR81 that reworked POSIX message
+ queues to add a descriptor separate from the underlying message queue.
+ This allows non-blocking to follow the "open" not the underlying queue.
+ As part of debugging this it became clear that
+ _Objects_Compare_name_string was broken and a simple version using
+ strncmp() was substituted.
+
+2001-04-24 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/memfile.c (memfile_open): Did not set iop->size and
+ thus the value was incorrect. Before this field was cleared, this
+ resulted in the value from the last time that IOP was used being still
+ in place. Discovered by Andrew Bythell <abythell@nortelnetworks.com>.
+
+2001-04-24 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/rtems_bsdnet_ntp.c: Modifications to make the RTEMS
+ NTP synchronization a little more robust -- no NTP daemon yet, but at
+ least it trys a little harder when the primary NTP server is down.
+
+2001-04-22 Joel Sherrill <joel@OARcorp.com>
+
+ * itron/src/task.c (_ITRON_Task_User_extensions): Add new fields to be
+ correct in respect to newly added fields for separate switch list.
+
+2001-04-20 Radzislaw Galler <rgaller@et.put.poznan.pl>
+
+ * libnetworking/modem/ppp.c, libnetworking/pppd/main.c,
+ libnetworking/pppd/pppmain.c, libnetworking/pppd/rtems-ppp.c,
+ libnetworking/pppd/modem_example/modem.c,
+ libnetworking/pppd/modem_example/ppp.c: Translated Polish comments and
+ other strings into English.
+ * libnetworking/pppd/STATUS: updated to reflect the changes.
+
+2001-04-20 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/devnull/devnull.c (null_initialize): Added check to ensure
+ that the driver is only initialized once. Otherwise, it will abort when
+ the device /dev/null is present. (null_write): Do not dereference a NULL
+ pointer.
+ * libfs/src/imfs/imfs_debug.c (IMFS_print_jnode): Modified to print only
+ information that does not vary based on target or memory configuration.
+ The old prints are still there in case they are needed in the future to
+ debug. Printing target dependent addresses makes the test output vary
+ by target unnecessarily.
+
+2001-04-20 Jake Janovetz <janovetz@uiuc.edu>
+
+ * libnetworking/rtems_servers/ftpd.c: Correct argument so hooks work
+ again.
+
+2001-04-20 Fernando Ruiz Casas <correo@fernando-ruiz.com>
+
+ * Added initial shell functionality.
+ * libmisc/Makefile.am, libmisc/configure.in, libmisc/wrapup/Makefile.am:
+ Reflect having added shell.
+ * libmisc/shell/.cvsignore, libmisc/shell/Makefile.am,
+ libmisc/shell/README, libmisc/shell/cmds.c, libmisc/shell/shell.c,
+ libmisc/shell/shell.h: New files.
+
+2001-04-16 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/confdefs.h: Fix real-time clock support.
+
+2001-04-11 Joel Sherrill <joel@OARcorp.com>
+
+ * score/macros/rtems/score/userext.inl: Now works after merging patch
+ for functionality requested in PR174.
+ * score/inline/rtems/score/userext.inl: Added a comment explaining the
+ order in which routines appear since it is not the obvious order.
+
+2001-04-08 Joel Sherrill <joel@OARcorp.com>
+
+ * score/macros/rtems/score/object.inl: Corrected arguments.
+ * score/macros/rtems/score/userext.inl: Updated to reflect modifications
+ to inline version from PR142.
+ * score/inline/rtems/score/userext.inl: Cleanup as side-effect of above.
+ * rtems/src/tasks.c: Pre-initialized switch extension for list.
+ * rtems/macros/rtems/score/timer.inl: Corrected typo on end of line.
+
+2001-04-04 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/dosfs/Makefile.am: Per PR129 do not install as many files to
+ the $(includedir).
+
+2001-03-29 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR126, configuration structures now match docs.
+ * sapi/include/rtems/config.h: Use public data types.
+ * Per PR126, configuration structures now match docs.
+ * rtems/include/rtems/rtems/config.h: Use public data types.
+ * Per PR147 addressed problems when reseting and inserting a timer into
+ a timer chain that did not honor time passage since the last time the
+ timer server was scheduled and the new insertion.
+ * rtems/include/rtems/rtems/timer.h, rtems/src/timerreset.c,
+ rtems/src/timerserver.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c: Broke up the "reset server" routine
+ into a set of very specific routines that allowed the server to be
+ unscheduled, timer chains to be "synchronized" with the current time
+ before inserting a new timer.
+
+2001-03-28 Joel Sherrill <joel@OARcorp.com>
+
+ * PR132 requested some tinkering ot lower memory.
+ * sapi/include/confdefs.h: Lowered footprint of device driver table and
+ statically configure user extensions. Now if no static extensions are
+ configured, then the table is not instantiated.
+
+2001-03-26 Zoltan Kocsi <zoltan@bendor.com.au>
+
+ * rtems/src/eventsurrender.c: Clear event condition when task is
+ unblocked. This makes sure that subsequent event send thinks the task is
+ still blocked and overwrites the initial events received.
+
+2001-03-23 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/memfile.c: Reapply fix from bug report from Jose
+ Sturniolo <jsturnio@nec.com.ar> where NULL pointer was dereferenced when
+ freeing a triply indirect file. The fix was applied to the 4.5 release
+ branch and not the development branch.
+
+2001-03-20 Till Straumann <strauman@SLAC.Stanford.EDU>
+
+ * PR158
+ * libnetworking/libc/rcmd.c, libnetworking/libc/rcmd.c: Enable the
+ rcmd() library call by commenting out the parts that deal with signals.
+ This enables RTEMS to 'rsh' command to a server connecting fd to remote
+ stdio. The 'server-side' parts of this file which deal with
+ authentication are disabled since they are not needed.
+
+2001-03-19 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/sys/utsname.h: Added C++ wrapper.
+
+2001-03-15 Ralf Corsepius <corsepius@faw.uni-ulm.de>
+
+ * libnetworking/include/.cvsignore: Remove dangling file.
+
+2001-03-15 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/src/extension.c: Split to reduce minimum code size per PR134.
+ * sapi/src/extensioncreate.c, sapi/src/extensiondelete.c,
+ sapi/src/extensionident.c: New files. src/Makefile.am: Modified to
+ reflect above.
+
+2001-03-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/.cvsignore: Added stamp-h1.in.
+
+2001-02-07 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.in: AC_DEFINE RTEMS_UNIX if RTEMS_CPU=unix.
+
+2001-02-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libmisc/monitor/mon-command.c: Use #if defined(RTEMS_UNIX).
+
+2001-02-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * itron/include/Makefile.am, itron/include/itronsys/Makefile.am,
+ itron/include/rtems/itron/Makefile.am,
+ itron/inline/rtems/itron/Makefile.am,
+ itron/macros/rtems/itron/Makefile.am, posix/include/Makefile.am,
+ posix/include/rtems/posix/Makefile.am, posix/include/sys/Makefile.am,
+ posix/inline/rtems/posix/Makefile.am,
+ posix/macros/rtems/posix/Makefile.am: Apply include_*HEADERS instead of
+ H_FILES.
+ * include/rtems/Makefile.am, include/rtems/score/Makefile.am,
+ inline/rtems/score/Makefile.am, macros/rtems/score/Makefile.am Apply
+ include_*HEADERS instead of H_FILES.
+ * sapi/include/Makefile.am, sapi/include/rtems/Makefile.am,
+ sapi/inline/rtems/Makefile.am, sapi/macros/rtems/Makefile.am,
+ rtems/include/Makefile.am, rtems/include/rtems/rtems/Makefile.am,
+ rtems/inline/rtems/rtems/Makefile.am,
+ rtems/macros/rtems/rtems/Makefile.am, rtems/ rtems/optman/Makefile.am,
+ libmisc/untar/Makefile.am, libmisc/monitor/Makefile.am,
+ libmisc/dummy/Makefile.am, libmisc/devnull/Makefile.am,
+ libmisc/dumpbuf/Makefile.am, libmisc/mw-fb/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/rtmonuse/Makefile.am,
+ libmisc/cpuuse/Makefile.am, librpc/include/rpc/Makefile.am,
+ libfs/src/imfs/Makefile.am, libnetworking/Makefile.am,
+ libnetworking/arpa/Makefile.am, libnetworking/machine/Makefile.am,
+ libnetworking/net/Makefile.am, libnetworking/ netinet/Makefile.am,
+ libnetworking/nfs/Makefile.am, libnetworking/rtems/Makefile.am,
+ libnetworking/ rtems_servers/Makefile.am,
+ libnetworking/rtems_webserver/Makefile.am,
+ libnetworking/sys/Makefile.am, libnetworking/vm/Makefile.am: Apply
+ include_*HEADERS instead of H_FILES.
+ * libnetworking/include/Makefile.am: Remove.
+ * libnetworking/Makefile.am: Add handling of *.h files.
+ * libnetworking/configure.in: Remove include/Makefile.
+
+2001-01-31 Sergei Organov <osv@javad.ru>
+
+ * libnetworking/rtems_servers/ftp.d: Following changes: - Hacks with
+ current dir and root dir removed in favor of new libio support for
+ task-local current and root directories. - Bug in `close_data_socket()'
+ introduced by previous change fixed. - `command_pasv()' changed to set
+ timeout on socket we are listening on and code fixed to don't close
+ socket twice on error. - `serr()' changed to clear `errno'. -
+ `data_socket()' changed to clear `errno' before `bind()'. - `session()'
+ changed to clear `errno' before processing session. -
+ `close_data_socket()' fixed to close both active and passive sockets. -
+ Initialize info->data_socket to -1 in `daemon()'. - Initialize `fname'
+ to empty string in `exec_command()'.
+
+2001-01-31 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/include/rtems/rtems/timer.h: Missed merging these modifications
+ in previous merge of new timer functionality.
+
+2001-01-29 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/objectextendinformation.c: Added include of string.h to
+ eliminate warning.
+ * Fixed bug where resetting a timer that was not at the head of one of
+ the task timer chains resulted in the Timer Server task waking up too
+ far in the future.
+ * Added rtems_timer_get_information() directive to support testing.
+ * src/timerserver.c, include/rtems/rtems/timer.h,
+ * rtems/src/timergetinfo.c: New file.
+ * rtems/src/Makefile.am: Modified to reflect above.
+
+2001-01-28 Ralf Corsepius <corsepiu@faw.uni-ulm.d>
+
+ * sapi/include/confdefs.h: define CONFIGURE_NEWLIB_EXTENSION 0 if not
+ using NEWLIB, cleanup related comment.
+
+2001-01-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * sapi/include/confdefs.h: include cpuopts.h, replace stubdr w/ devnull.
+
+2001-01-25 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.c: Reduce first timeout interval. This
+ improves throughput on systems which are dropping packets. Only the
+ first timeout is reduced. This keeps the number of extra packets down
+ on networks that are very busy and dropping lots of packets.
+
+2001-01-24 Sergei Organov <osv@javad.ru>
+
+ * libnetworking/rtems_servers/ftpd.c,
+ libnetworking/rtems_servers/ftpd.h: - Timeouts on sockets implemented.
+ 'idle' field added to configuration. No timeout by default to keep
+ backward compatibility. Note: SITE IDLE command not implemented yet. -
+ Basic global access control implemented. 'access' field added to
+ configuration. No access limitations by default to keep backward
+ compatibility. - Anchor data socket for active mode (using self IP and
+ port 20.) - Fixed default data port support (still not tested). - Don't
+ allow IP address different from originating host in PORT command to
+ improve security. - Fixed bug in MDTM command. - Check for correctness
+ of parsing of argument in command_port(). - Fixed squeeze_path() to
+ don't allow names like 'NAME/smth' where 'NAME' is not a directory. -
+ Command parsing a little bit improved: command names are now converted
+ to upper-case to be more compatible with RFC (command names are not
+ case-sensitive.). - Reformat comments so that they have RTEMS
+ look-and-feel. - Fixed DELE, SITE CHMOD, RMD, MKD broken by previous
+ changes. - True ASCII mode implemented (doesn't work for hooks and
+ /dev/null) - Passive mode implemented, PASV command added. - Default
+ port for data connection could be used (untested, can't find ftp client
+ that doesn't send PORT command). - SYST reply changed to UNIX, as former
+ RTEMS isn't registered name. - Reply codes reviewed and fixed.
+
+2001-01-24 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * posix/configure.in: Add src/config.h.
+ * posix/src/Makefile.am: Add INCLUDES += -I. to pickup config.h.
+ * posix/src/.cvsignore: Add config.h and stamp-h.
+ * posix/src/*.c: Add config.h support.
+
+2001-01-23 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/alarm.c: Eliminated use of C++ style comments.
+
+2001-01-22 Michael Hamel <mhamel@adi.co.nz>
+
+ * posix/include/rtems/posix/semaphore.h,
+ posix/inline/rtems/posix/semaphore.inl, posix/ src/ptimer1.c,
+ posix/include/rtems/posix/semaphore.h,
+ posix/inline/rtems/posix/semaphore.inl, posix/src/alarm.c,
+ posix/src/ptimer1.c, posix/src/semaphorenametoid.c, posix/src/semopen.c,
+ posix/src/semunlink.c, rtems/include/rtems.h, rtems/src/signalcatch.c:
+ Modifications to make CodeWarrior happy.
+
+2001-01-22 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/include/rtems/rtems/timer.h, rtems/src/timerserver.c: Add
+ priority argument to rtems_timer_initiate_server().
+
+2001-01-18 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/system.h, rtems/include/rtems/system.h: Only
+ include cpuopts.h when building a multilib configuration. Some ports
+ still need targopts.h but this small modification lets those ports work
+ non-multilib while fixing being fixed for multilib.
+
+2001-01-17 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: Deleted duplicate blank line.
+
+2001-01-16 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libfs/configure.in: Add src/imfs/config.h.
+ * libfs/src/imfs/Makefile.am: Add INCLUDES += -I. to pickup config.h.
+ * libfs/src/imfs/.cvsignore: Add config.h and stamp-h.
+ * libfs/src/imfs/*.c: Add config.h support.
+
+2001-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/inline/rtems/posix/mutex.inl (_POSIX_Mutex_Get_support):
+ Corrected name of routine in header.
+ * rtems/Added task-based timers to the Timer Manager. This added three
+ new directives: - rtems_timer_initiate_server -
+ rtems_timer_server_fire_after - rtems_timer_server_fire_when In the
+ process of doing this, a number of cleanups were made.
+ * rtems/src/timerserver.c, rtems/src/timerserverfireafter.c,
+ rtems/src/timerserverfirewhen.c: New files.
+ * rtems/include/timer/timer.h: Added new prototypes and supporting types.
+ * rtems/inline/rtems/rtems/timer.h, rtems/macros/rtems/rtems/timer.h:
+ Enhanced _Timer_Is_interval_class() to cover the class
+ TIMER_INTERVAL_ON_TASK.
+ * rtems/src/Makefile.am: Accounted for new files.
+ * rtems/src/rtemstimer.c: Added initialization of _Timer_Server variable.
+ * rtems/src/timercancel.c, rtems/src/timerreset.c: Account for addition
+ of timer classes. Also corrected the headers.
+ * rtems/src/timercreate.c, rtems/src/timerdelete.c,
+ rtems/src/timerfireafter.c, rtems/ src/timerfireafter.c,
+ rtems/src/timerident.c: Corrected header.
+ * rtems/src/taskmode.c: Ensure the this service does not dispatch before
+ tasking is enabled at initialization time.
+
+2001-01-12 Sergei Organov <osv@javad.ru>
+
+ * libnetworking/rtems_servers/ftpd.c,
+ libnetworking/rtems_servers/ftpd.h: - use pool of pre-created threads to
+ handle sessions instead of creating/deleting threads on the fly. - LIST
+ output is now similar to what "/bin/ls -al" would output, thus FTP
+ clients such Netscape are happy with it. - LIST NAME now works (both for
+ files and directories) - added support for NLST, CDUP, and MDTM FTP
+ commands to make more FTP clients happy . - keep track of CWD for every
+ session separately. - ability to specify root directory name for FTPD in
+ configuration table. FTPD will then create illusion for FTP clients that
+ this is actually root directory. - ignore options sent in commands, thus
+ LIST -al FILE works and doesn't try to list "-al" directory. - buffers
+ are allocated on stack instead of heap where possible to eliminate
+ malloc/free calls (avoid possible heap fragmentation troubles). - drop
+ using of task notepad to pass parameters - use function arguments
+ instead. - use snprintf() instead of sprintf() as the latter is unsafe.
+ - use of PF_INET in socket() instead of AF_INET.
+
+2001-01-12 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/clockgetres.c: Fixed match problem. We are not converting
+ an interval to a timespec -- it is actually a real number of
+ microseconds.
+ * posix/src/README.mqueue: Enhanced example.
+
+2001-01-12 Jake Janovetz <janovetz@uiuc.edu>
+
+ * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
+ libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/imfs_handlers_memfile.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
+ libfs/src/imfs/imfs_stat.c, libfs/src/imfs/memfile.c,
+ libfs/src/imfs/miniimfs_init.c: Final developmental update to "tarfs".
+ When rtems_tarfs_load() is called, it checks the permissions on each
+ file. If there is write permission, it just creates a standard file
+ using "creat()" and therefore, uses the IMFS MEMORY_FILE. If there is no
+ write permission, it creates a LINEAR_FILE node with the appropriate
+ properties. If the permission is ever changed to writeable, IMFS_fchmod
+ converts it to a regular memory file.
+
+2001-01-08 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/src/threadinitialize.c: Removed warning.
+
+2001-01-08 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/threadinitialize.c: Fix my bad hack of Ralf's fp_area
+ warning removal patch. :(.
+
+2001-01-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * itron/configure.in: Add src/config.h.
+ * itron/src/Makefile.am: Add INCLUDES += -I. to pickup config.h.
+ * itron/src/.cvsignore: Add config.h and stamp-h.
+ * itron/src/*.c: Add config.h support.
+
+2001-01-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libmisc/devnull: New addition. Moved from libcpu/sh.
+ * libmisc/devnull/devnull.c, libmisc/devnull/devnull.h,
+ libmisc/devnull/.cvsignore, libmisc/ devnull/Makefile.am: New files.
+ * libmisc/Makefile.am, libmisc/configure.in, libmisc/wrapup/Makefile.am:
+ Modified to reflect addition of above.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/isr.c: Modify to properly dereference _ISR_Vector_table now
+ that it is dynamically allocated.
+
+2001-01-02 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/CHANGELOG: Removed.
+ * libnetworking/README: Merged CHANGELOG contents as initial changes.
+
+2000-12-19 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/pthreadgetschedparam.c: Do not set output parameters if the
+ pointers are NULL.
+ * score/src/isr.c: Allocate the _ISR_Vector_table all the time not just
+ when we are allocating an interrupt stack.
+
+2000-12-14 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/lib/tftpDriver.c: Added write capability.
+
+2000-12-13 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/score/isr.h, score/src/isr.c: Allocate it from the
+ workspace rather than explicitly declaring it. This allows the size to
+ be a non-constant from the perspective of score/cpu.
+
+2000-12-12 Jake Janovetz <janovetz@uiuc.edu>
+
+ * libfs/src/imfs/linearfile.c, libfs/src/imfs/imfs_load_tar.c: New files.
+ * libfs/src/imfs/Makefile.am, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c,
+ libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_handlers_memfile.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
+ libfs/src/imfs/imfs_stat.c, libfs/src/imfs/miniimfs_init.c: Added
+ "tarfs". This is not really a tar filesystem. It is a way to load a tar
+ image into the IMFS but actually leave bulky file contents in the
+ original tar image. It essentially adds the linear file type and
+ associated support and a loader routine.
+
+2000-12-08 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/libc/linkaddr.c: Initialized variable to remove warning.
+ * libnetworking/modem/ppp.c, libnetworking/modem/ppp_tty.c: Made
+ numerous variable declarations conditional on PPP_COMPRESS and
+ PPP_FILTER. Commented out variables that were not used because the code
+ using them was commented out. Removed totally unused variables.
+ * libnetworking/modem/pppcompress.c: Added parentheses to avoid warnings.
+ * libnetworking/pppd/pppmain.c: Removed numerous warnings.
+
+2000-12-06 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/pthreadgetcpuclockid.c: Add include of <rtems/system.h> to
+ eliminate warning.
+ * rtems/src/regiongetinfo.c: Removed unused variable to eliminate
+ warning.
+
+2000-12-01 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.in: Removed error check for enabling macros with either
+ POSIX or ITRON API.
+ * Added macro support to ITRON API. This is known to compile.
+ * itron/Makefile.am: Added macros directory.
+ * itron/configure.in: Removed error check for enabling macros.
+ * itron/macros/.cvsignore, itron/macros/Makefile.am,
+ itron/macros/rtems/.cvsignore, itron/macros/rtems/Makefile.am,
+ itron/macros/rtems/itron/.cvsignore,
+ itron/macros/rtems/itron/Makefile.am,
+ itron/macros/rtems/itron/eventflags.inl,
+ itron/macros/rtems/itron/fmempool.inl,
+ itron/macros/rtems/itron/intr.inl, itron/macros/rtems/itron/mbox.inl,
+ itron/macros/rtems/itron/msgbuffer.inl,
+ itron/macros/rtems/itron/network.inl, itron/macros/rtems/itron/port.inl,
+ itron/macros/rtems/itron/semaphore.inl,
+ itron/macros/rtems/itron/sysmgmt.inl, itron/macros/rtems/itron/task.inl,
+ itron/macros/rtems/itron/time.inl,
+ itron/macros/rtems/itron/vmempool.inl: New files.
+ * posix/include/rtems/posix/cond.h: #if 0'ed out prototype of
+ _POSIX_Condition_variables_Get to avoid conflict with macro
+ implementation.
+ * Added macro support to POSIX API. This is known to compile.
+ * posix/macros/rtems/posix/cond.inl, posix/macros/rtems/posix/intr.inl,
+ posix/macros/rtems/posix/key.inl, posix/macros/rtems/posix/mqueue.inl,
+ posix/macros/rtems/posix/mutex.inl,
+ posix/macros/rtems/posix/priority.inl,
+ posix/macros/rtems/posix/pthread.inl,
+ posix/macros/rtems/posix/semaphore.inl,
+ posix/macros/rtems/posix/timer.inl: New files.
+ * posix/configure.in: Removed error check for enabling macros.
+ * posix/rtems/posix/mutex.h: #if 0'ed out prototypes for inlined
+ routines since you cannot have prototypes for macros.
+ * posix/macros/rtems/posix/Makefile.am: Added files.
+ * score/macros/rtems/score/coresem.inl: Removed comments since
+ convention calls for comments to be in inline versin.
+ * score/macros/rtems/score/object.inl (Objects_Get_local_object): Fixed
+ style to use _ prefix on variable names and use parentheses.
+ * score/macros/rtems/score/object.inl (_Objects_Namespace_remove): Added.
+
+2000-11-30 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/inline/rtems/posix/mqueue.inl: Removed explicit dependency on
+ abs().
+ * General effort to make things compile with macros not inlines
+ * score/inline/rtems/score/coremutex.inl: Added comment indicating for
+ macros there is another copy of _CORE_mutex_Seize_interrupt_trylock() in
+ src/coremutexseize.c.
+ * score/src/coremutexseize.c: Added body of
+ _CORE_mutex_Seize_interrupt_trylock() for macro case.
+ * score/macros/rtems/score/coremutex.inl: Added prototype for
+ _CORE_mutex_Seize_interrupt_trylock() since there is a real body when
+ macros are enabled.
+ * score/macros/rtems/score/coresem.inl: Added macro implementation of
+ _CORE_semaphore_Seize_isr_disable.
+ * score/macros/score/Makefile.am: Fixed typos.
+ * score/rtems/score/address.inl: Correct macro implementation of
+ _Addresses_Is_aligned() so it would compile.
+ * score/macros/rtems/score/coremsg.inl: Added closing parentheses.
+ * rtems/src/msgqsubmit.c: Modified multiprocessing conditional so this
+ would compile with both macros and inlines.
+ * rtems/macros/rtems/rtems/sem.inl: Added macro implementation of
+ _Semaphore_Get_interrupt_disable().
+ * libmisc/mw-fb/mw_uid.c: Removed unnecessary dependency on <bsp.h>.
+ * libnetworking/modem/ppp_tty.c: Changed to include
+ <rtems/termiostypes.h> since that is an RTEMS specific header file.
+ * libnetworking/sys/ttycom.h: Moved to lib/include/sys.
+ * libnetworking/Makefile.am: Modified to reflect above.
+
+2000-11-28 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/memfile.c: Bug report from Sturniolo Jose
+ <jsturnio@nec.com.ar> where NULL pointer was dereferenced.
+
+2000-11-28 Chris Johns <ccj@acm.org>
+
+ * score/src/heapallocate.c: Do not allow the size to overflow when
+ adjusting it. A test allocated a stack of -1 (~0). This actually
+ resulted in a stack being allocated but with a size of 0xb. The
+ allocator did not test the size to see if it rolled through 0 and so
+ allowed the allocation to happen, the thread to get created. The task
+ crashed as you would expect.
+
+2000-11-27 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/sysconf.c: Add support for _SC_CLK_TCK and _SC_OPEN_MAX.
+ * libnetworking/libc/res_init.c: Fix typo - adding missing # on include.
+
+2000-11-25 Eric Norum <eric.norum@usask.ca>
+
+ * libnetworking/libc/res_init.c: Move include to avoid compiler dumping
+ core.
+
+2000-11-25 Antti P Miettinen <antti.p.miettinen@nokia.com>
+
+ * libnetworking/wrapup/Makefile.am, libnetworking/configure.in,
+ libnetworking/Makefile.am: Added modem subdir.
+ * libnetworking/net/Makefile.am: Added if_pppvar.h, pppcompress.h.
+ * libnetworking/pppd/Makefile.am: Added pppmain.c (which needs work).
+ * libnetworking/pppd/chat.c, libnetworking/pppd/fsm.c,
+ libnetworking/pppd/fsm.h, libnetworking/pppd/ipxcp.c,
+ libnetworking/pppd/main.c, libnetworking/pppd/ppp_tty.c,
+ libnetworking/pppd/upap.c: Changes from Thomas Doerfler
+ <Thomas.Doerfler@imd-systems.de> and cosmetic changes by me. Actually
+ main.c and ppp_tty.c should be scratched. The modem subdir has the real
+ ppp_tty.c and the real pppd main is in pppmain.c.
+
+2000-11-17 Jennifer Averret <jennifer@OARcorp.com>
+
+ * libfs/src/imfs/imfs_eval.c: Always return imaginary node at mount
+ points.
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, itron/Makefile.am, posix/Makefile.am,
+ libmisc/Makefile.am, librpc/Makefile.am, libfs/Makefile.am,
+ libnetworking/Makefile.am: Use ... instead of RTEMS_TOPdir in
+ ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, itron/Makefile.am, posix/Makefile.am,
+ libmisc/Makefile.am, librpc/Makefile.am, libfs/Makefile.am,
+ libnetworking/Makefile.am: Switch to ACLOCAL_AMFLAGS = -I
+ $(RTEMS_TOPdir)/aclocal.
+
+2000-11-02 Joel Sherrill <joel@OARcorp.com>
+
+ * score/include/rtems/system.h: Use proper conditional (RTEMS_POSIX_API)
+ so prototypes for POSIX_MP_NOT_IMPLEMENTED(), POSIX_NOT_IMPLEMENTED(),
+ POSIX_BOTTOM_REACHED() are actually included.
+ * score/include/rtems/system.h: Add prototypes for
+ POSIX_MP_NOT_IMPLEMENTED(), POSIX_NOT_IMPLEMENTED(),
+ POSIX_BOTTOM_REACHED() removed from newlib.
+
+2000-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/Makefile.am, libfs/src/imfs/deviceio.c,
+ libfs/src/imfs/imfs_chown.c, libfs/src/imfs/imfs_config.c,
+ libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c,
+ libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_eval.c,
+ libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/imfs_free.c,
+ libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_gtkn.c,
+ libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
+ libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_mknod.c,
+ libfs/src/imfs/imfs_mount.c, libfs/src/imfs/imfs_readlink.c,
+ libfs/src/imfs/imfs_rmnod.c, libfs/src/imfs/imfs_stat.c,
+ libfs/src/imfs/imfs_symlink.c, libfs/src/imfs/imfs_unixstub.c,
+ libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/imfs_unmount.c,
+ libfs/src/imfs/imfs_utime.c, libfs/src/imfs/ioman.c,
+ libfs/src/imfs/memfile.c, libfs/src/imfs/miniimfs_init.c: assoc.h,
+ error.h, libio_.h, libio.h, and libcsupport.h moved from libc to
+ lib/include/rtems and now must be referenced as <rtems/XXX.h>. Now we
+ do not have to reach up and over to libc to pick them up.
+
+2000-10-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * posix/configure.in: Cleanup comments.
+
+2000-10-30 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/include/Makefile.am: Updated to reflect files merged into
+ newlib. This resulted in some definitions moving to other files and thus
+ some secondary effects in RTEMS source code.
+ * posix/include/unistd.h: Removed. Now use newlib's.
+ * posix/include/rtems/posix/mqueue.h: Add include of <signal.h>.
+ * posix/include/rtems/posix/threadsup.h: Add include of <sys/signal.h>.
+ * posix/src/execv.c, posix/src/execve.c, posix/src/execvp.c: Corrected
+ prototype to agree with newlib.
+ * posix/src/psignal.c: Rewrote reference to <siginfo.h> in comment since
+ that file no longer exists.
+ * posix/src/pthreadkill.c, posix/src/sigaction.c: Added include of
+ <signal.h>.
+ * posix/src/sigtimedwait.c: Rewrote reference to <siginfo.h> in comment
+ since that file no longer exists.
+ * POSIX include files merged into newlib. This resulted in some
+ definitions moving to other files and thus some secondary effects in
+ RTEMS source code.
+ * sapi/include/confdefs.h: Replaced include of <sys/siginfo.h> with
+ <signal.h> since that file no longer exists.
+ * POSIX include files merged into newlib. This resulted in some
+ definitions moving to other files and thus some secondary effects in
+ RTEMS source code.
+ * librpc/src/rpc/Makefile.am, librpc/src/rpc/auth_time.c,
+ librpc/src/rpc/clnt_simple.c, librpc/src/rpc/clnt_tcp.c,
+ librpc/src/rpc/clnt_udp.c, librpc/src/rpc/clnt_unix.c,
+ librpc/src/rpc/get_myaddress.c, librpc/src/rpc/pmap_clnt.c,
+ librpc/src/rpc/pmap_getmaps.c, librpc/src/rpc/pmap_getport.c,
+ librpc/src/rpc/pmap_rmt.c, librpc/src/rpc/rtime.c,
+ librpc/src/rpc/svc_tcp.c, librpc/src/rpc/svc_udp.c,
+ librpc/src/rpc/svc_unix.c: Use of _read, _write, and _close as macros
+ conflicted with newlib's use of these as routine names. They were
+ renamed to include "_RPC_" prefix.
+ * POSIX include files merged into newlib. This resulted in some
+ definitions moving to other files and thus some secondary effects in
+ RTEMS source code.
+ * libnetworking/machine/types.h: Added _CLOCKID_T_ and _TIMER_T_ to be
+ in sync with newlib's <machine/types.h>.
+ * libnetworking/rtems/rtems_bsdnet_internal.h: newlib now includes
+ definition of struct itimerval in <sys/time.h>.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, itron/Makefile.am, posix/Makefile.am,
+ libmisc/Makefile.am, librpc/Makefile.am, libnetworking/Makefile.am:
+ ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros. Switch to GNU
+ canonicalization.
+
+2000-10-24 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libfs/Makefile.am, libfs/configure.in: Introduce GNU canonicalization
+ to libfs/. The approach is currently a bit of a hack as GNU
+ canonicalization does not support the per-BSP build some of the other
+ directories require. As more of the tree is converted, this will become
+ less of an issue.
+
+2000-10-24 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/src/imfs/imfs_config.c: New file containing IMFS configuration
+ information split from libc/base_fs.c.
+ * libfs/src/imfs/ioman.c: New file. Moved from lib/libc. Missed
+ previously.
+ * libfs/src/imfs/Makefile.am: Added imfs_config.c and ioman.c.
+
+2000-10-19 Joel Sherrill <joel@OARcorp.com>
+
+ * libfs/.cvsignore, libfs/src/.cvsignore, libfs/src/imfs/.cvsignore,
+ libfs/wrapup/.cvsignore: New files.
+
+2000-10-19 Antti P Miettinen <anmietti@trshp.ntc.nokia.com>
+
+ * libnetworking/lib/tftpDriver.c: add comments to handlers struct
+ function pointers.
+ * libnetworking/rtems/rtems_glue.c: move pointer arithmetic to be
+ _after_ pointer has been checked against NULL.
+
+2000-10-18 Nick Simon <Nick.SIMON@syntegra.bt.co.uk>
+
+ * score/src/heapgetinfo.c, score/include/rtems/score/heap.h,
+ score/src/Makefile.am: Added _Heap_Get_information() and information
+ control block.
+ * score/src/heapgetinfo.c: New file.
+
+2000-10-18 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/confdefs.h: Set CONFIGURE_INIT_TASK_STACK_SIZE to 0 if
+ there is no Classic API Initialization Tasks Table defined.
+ * sapi/include/confdefs.h: Modified code that accounts for
+ initialization task/threads with greater than minimum stack sizes so it
+ would compile even if optional APIs are disabled.
+ * rtems/src/regiongetinfo.c, rtems/include/rtems/rtems/region.h,
+ rtems/include/rtems/rtems/types.h, rtems/src/Makefile.am: Added
+ region_get_information() and information control block.
+ * rtems/src/regiongetinfo.c: New file.
+
+2000-10-18 Chris Johns <ccj@acm.org>
+
+ * libfs created.
+ * libfs/src, libfs/src/imfs, libfs/wrapup: New directories.
+ * libfs/ChangeLog, libfs/Makefile.am, libfs/README, libfs/configure.in,
+ libfs/src/Makefile.am, libfs/wrapup/Makefile.am: New files.
+ * libfs/src/imfs/deviceio.c, libfs/src/imfs/imfs_getchild.c,
+ libfs/src/imfs/imfs_readlink.c, libfs/src/imfs/imfs.h,
+ libfs/src/imfs/imfs_gtkn.c, libfs/src/imfs/imfs_rmnod.c,
+ libfs/src/imfs/imfs_chown.c, libfs/src/imfs/imfs_handlers_device.c,
+ libfs/src/imfs/imfs_stat.c, libfs/src/imfs/imfs_creat.c,
+ libfs/src/imfs/imfs_handlers_directory.c, libfs/src/imfs/imfs_symlink.c,
+ libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_handlers_link.c,
+ libfs/src/imfs/imfs_unixstub.c, libfs/src/imfs/imfs_directory.c,
+ libfs/src/imfs/imfs_handlers_memfile.c, libfs/src/imfs/imfs_unlink.c,
+ libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c,
+ libfs/src/imfs/imfs_unmount.c, libfs/src/imfs/imfs_fchmod.c,
+ libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_utime.c,
+ libfs/src/imfs/imfs_fcntl.c, libfs/src/imfs/imfs_link.c,
+ libfs/src/imfs/memfile.c, libfs/src/imfs/imfs_fdatasync.c,
+ libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/miniimfs_init.c,
+ libfs/src/imfs/imfs_free.c, libfs/src/imfs/imfs_mount.c,
+ libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_ntype.c: New files.
+ Moved from libc.
+ * libnetworking/pppd/ipxcp.c: Fixed a typo.
+
+2000-10-12 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/confdefs.h: Account for initialization tasks and threads
+ which use larger than minimum stack sizes.
+
+2000-09-29 Stephan Merker <merker@decrc.abb.de>
+
+ * rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemonperiod.c,
+ rtems/src/ratemontimeout.c: Add next_length field so period length can
+ be changed by the the sequence period(X), period(not X) with no
+ intervening cancel or expiration.
+
+2000-09-28 Joel Sherrill <joel@OARcorp.com>
+
+ * sapi/include/rtems/io.h (rtems_driver_address_table): Added "_entry"
+ to all names.
+ * sapi/src/io.c: Accounted for above.
+ * libmisc/monitor/mon-driver.c: Accounted for addition of "_entry" to
+ fields in rtems_driver_address_table.
+ * libnetworking/rtems_webserver/Makefile.am,
+ libnetworking/rtems_webserver/base64.c,
+ libnetworking/rtems_webserver/base64.c: Renamed base64.c to wbase64.c.
+ * libnetworking/rtems_webserver/sock.c: Added file missed in merger.
+
+2000-09-25 Joel Sherrill <joel@OARcorp.com>
+
+ * score/rtems/system.h: Switched a29k and hppa1.1 to using cpuopts.h not
+ targopts.h to reduce dependency on BSP.
+
+2000-09-22 Joel Sherrill <joel@OARcorp.com>
+
+ * librpc/src/xdr/xdr_float.c: Added A29K support.
+ * libnetworking/machine/types.h, libnetworking/pppd/pppd.h,
+ libnetworking/rtems/rtems_bsdnet_internal.h,
+ libnetworking/rtems_webserver/webmain.c: machine/types.h should not
+ have included rtems.h. It is now including precisely the least amount
+ of low level, yet portable .h files to get the basic RTEMS types
+ defined. This rippled into other files since rtems_bsdnet_internal.h
+ used machine/types.h to include rtems.h.
+
+2000-09-20 Joel Sherrill <joel@OARcorp.com>
+
+ * score/src/objectgetbyindex.c: Do not enable dispatching on an error
+ path it was not disabled on.
+
+2000-09-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/rtems/Makefile.am: Use PROJECT_TOPdir in path to size_rtems.
+ * libnetworking/ChangeLog: Cleanup.
+
+2000-09-05 Joel Sherrill <joel@OARcorp.com>
+
+ * libnetworking/rtems/rtems_syscall.c: Changed from O_NONBLOCK to
+ internal RTEMS_LIBIO_FLAGS_NO_DELAY to avoid O_NONBLOCK/O_NDELAY
+ confusion and to work with the converted flags.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * wrapup/itron/Makefile.am, wrapup/posix/Makefile.am,
+ wrapup/rtems/Makefile.am, itron/src/Makefile.am, posix/src/Makefile.am,
+ posix/optman/Makefile.am, score/src/Makefile.am, sapi/src/Makefile.am,
+ sapi/optman/Makefile.am, rtems/optman/Makefile.am,
+ rtems/src/Makefile.am, libmisc/cpuuse/Makefile.am,
+ libmisc/dummy/Makefile.am, libmisc/dumpbuf/Makefile.am,
+ libmisc/monitor/Makefile.am, libmisc/rtmonuse/Makefile.am,
+ libmisc/stackchk/Makefile.am, libmisc/untar/Makefile.am,
+ libmisc/wrapup/Makefile.am, libmisc/mw-fb/Makefile.am,
+ librpc/src/rpc/Makefile.am, librpc/src/xdr/Makefile.am,
+ libnetworking/kern/Makefile.am, libnetworking/lib/Makefile.am,
+ libnetworking/libc/Makefile.am, libnetworking/net/Makefile.am,
+ libnetworking/netinet/Makefile.am, libnetworking/nfs/Makefile.am,
+ libnetworking/pppd/Makefile.am, libnetworking/rtems/Makefile.am,
+ libnetworking/rtems_servers/Makefile.am,
+ libnetworking/rtems_webserver/Makefile.am,
+ libnetworking/wrapup/Makefile.am: Include compile.am.
+
+2000-09-01 Rosimildo daSilva <rdasilva@connecttel.com>
+
+ * libnetworking/emfdb.c: Removed stray semi-colon. Reported on GoAhead
+ mailing lists by Jim Rudnicki <jdrudnicki@yahoo.com>.
+
+2000-08-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * libnetworking/netinet/tcp_input.c: Spelling corrections.
+
+2000-08-31 Joel Sherrill <joel@OARcorp.com>
+
+ * Merged version 2.1 of GoAhead webserver. This update was submitted by
+ Antti P Miettinen <antti.p.miettinen@nokia.com>.
+ * libnetworking/NOTES, libnetworking/base64.c, libnetworking/ejIntrn.h,
+ libnetworking/emfdb.c, libnetworking/emfdb.h, libnetworking/md5.h,
+ libnetworking/md5c.c, libnetworking/ um.c, libnetworking/um.h: New files.
+ * libnetworking/wbase64.c: Removed.
+ * libnetworking/Makefile.am, libnetworking/asp.c,
+ libnetworking/balloc.c, libnetworking/default.c, libnetworking/ej.h,
+ libnetworking/ejlex.c, libnetworking/ejparse.c, libnetworking/ form.c,
+ libnetworking/h.c, libnetworking/handler.c, libnetworking/mime.c,
+ libnetworking/misc.c, libnetworking/ringq.c, libnetworking/rom.c,
+ libnetworking/security.c, libnetworking/ socket.c, libnetworking/sym.c,
+ libnetworking/uemf.c, libnetworking/uemf.h, libnetworking/url.c,
+ libnetworking/value.c, libnetworking/webcomp.c, libnetworking/webmain.c,
+ libnetworking/ webpage.c, libnetworking/webrom.c, libnetworking/webs.c,
+ libnetworking/webs.h, libnetworking/websuemf.c, libnetworking/wsIntrn.h:
+ Modified.
+
+2000-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/Many files, score/Many files, libmisc/Many files: Moved
+ posix/include/rtems/posix/seterr.h to score/include/rtems/seterr.h so
+ it would be available within all APIs.
+ * libmisc/mw-fb/.cvsignore, libnetworking/rtems_webserver/license.txt:
+ New file.
+
+2000-08-30 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/taskstart.c: Removed 1st cut at rtems_task_start_main_style.
+ Only committed this so it could be easily revisited as we discussing
+ moving main() to user space from BSP space.
+ * rtems/taskstart.c: Added 1st cut at rtems_task_start_main_style.
+
+2000-08-26 Rosimildo da Silva <rdasilva@connecttel.com>
+
+ * Added generic Micro FrameBuffer interface for MicroWindows. This
+ interface allows MicroWindows to under RTEMS. A sample driver has been
+ developed for the pc386 BSP. See pc386/fb_vga.c as a sample.
+ * Added Uniform Input Device interface for MicroWindows. See PC386 bsp
+ for sample drivers for mouse and keyboard (console).
+ * libmisc/mw-bf: New directory.
+ * libmisc/Makefile.am, libmisc/configure.in, libmisc/wrapup/Makefile.am:
+ Account for mw-fb.
+ * libmisc/mw-fb/Makefile.am, libmisc/mw-fb/mw_fb.c,
+ libmisc/mw-fb/mw_fb.h, libmisc/mw-fb/mw_uid.c, libmisc/mw-fb/mw_uid.h:
+ New file.
+
+2000-08-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * posix/inline/rtems/posix/timer.inl, posix/include/rtems/posix/timer.h,
+ posix/ inline/rtems/posix/Makefile.am, posix/src/ptimer1.c: Redid the
+ style of src/ptimer1.c. Continued effort to make the POSIX Timer
+ implementation match that of other managers. Added data structures
+ required to use SuperCore Object Handler.
+
+2000-08-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * score/include/rtems/system.h: Include cpuopts.h for __i386__.
+
+2000-08-15 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/src/ptimer1.c: Minor formatting fixes.
+ * posix/src/ptimer1.c: Removed unused routine PRINT_ERRNO_S.
+ * posix/src/ptimer1.c: Removed unnecessary routine COPY_ITIMERSPEC_S and
+ used structure copy instead.
+ * posix/src/ptimer1.c: Renamed timer_alive_t to POSIX_Timer_Control.
+ * posix/include/rtems/posix/timer.h: Ditto.
+ * posix/src/ptimer1.c: Switched to using
+ set_errno_and_return_minus_one() to ensure that errno was always set.
+ * posix/src/ptimer1.c (timer_settime): Converted use of rtems_clock_get
+ to use SuperCore _TOD_Current variable.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog, itron/ChangeLog, posix/ChangeLog, score/ChangeLog,
+ sapi/ChangeLog, rtems/ChangeLog, libmisc/ChangeLog, librpc/ChangeLog,
+ libnetworking/ChangeLog: New file.
+
diff --git a/cpukit/Doxyfile.in b/cpukit/Doxyfile.in
new file mode 100644
index 0000000000..1de80b6f0a
--- /dev/null
+++ b/cpukit/Doxyfile.in
@@ -0,0 +1,1561 @@
+# Doxyfile 1.6.2-20100208
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+# TAG = value [value, ...]
+# For lists items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME = "RTEMS CPU Kit with SuperCore"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER = @PACKAGE_VERSION@
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = cpukit_doxy
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian,
+# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak,
+# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH = ../lib/include
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF = YES
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF = YES
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 8
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it parses.
+# With this tag you can assign which parser to use for a given extension.
+# Doxygen has a built-in mapping, but you can override or extend it using this tag.
+# The format is ext=language, where ext is a file extension, and language is one of
+# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP,
+# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat
+# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran),
+# use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate getter
+# and setter methods for a property. Setting this option to YES (the default)
+# will make doxygen to replace the get and set methods by a property in the
+# documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING = YES
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penality.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will rougly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols
+
+SYMBOL_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespace are hidden.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
+# will list include files with double quotes in the documentation
+# rather than with sharp brackets.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES = NO
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.
+# This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by
+# doxygen. The layout file controls the global structure of the generated output files
+# in an output format independent way. The create the layout file that represents
+# doxygen's defaults, run doxygen with the -l option. You can optionally specify a
+# file name after the option, if omitted DoxygenLayout.xml will be used as the name
+# of the layout file.
+
+LAYOUT_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = ../lib/include
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
+
+FILE_PATTERNS = *.h \
+ *.inl
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE = score/mainpage.h
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+# If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER = @top_srcdir@/doxy-filter
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.
+# Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.
+# The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = YES
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code.
+# Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# If the HTML_TIMESTAMP tag is set to YES then the generated HTML
+# documentation will contain the timesstamp.
+
+HTML_TIMESTAMP = NO
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET =
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting
+# this to NO can help when comparing the output of multiple runs.
+
+HTML_TIMESTAMP = NO
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
+# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information.
+
+GENERATE_DOCSET = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER
+# are set, an additional index file will be generated that can be used as input for
+# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated
+# HTML documentation.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add.
+# For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
+# will be generated, which together with the HTML files, form an Eclipse help
+# plugin. To install this plugin and make it available under the help contents
+# menu in Eclipse, the contents of the directory containing the HTML and XML
+# files needs to be copied into the plugins directory of eclipse. The name of
+# the directory within the plugins directory should be the same as
+# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before the help appears.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have
+# this name.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE = 4
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to YES, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
+# Windows users are probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW = NO
+
+# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories,
+# and Class Hierarchy pages using a tree view instead of an ordered list.
+
+USE_INLINE_TREES = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE = 10
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box for the HTML output. The underlying search engine uses javascript
+# and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) there is already a search function so this one should
+# typically be disabled. For large projects the javascript based search engine
+# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
+
+SEARCHENGINE = NO
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be implemented using a PHP enabled web server instead of at the web client using Javascript. Doxygen will generate the search PHP script and index
+# file to put on the web server. The advantage of the server based approach is that it scales better to large projects and allows full text search. The disadvances is that it is more difficult to setup
+# and does not have live searching capabilities.
+
+SERVER_BASED_SEARCH = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+# Note that when enabling USE_PDFLATEX this option is only used for
+# generating bitmaps for formulas in the HTML output, but not in the
+# Makefile that is written to the output directory.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = NO
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES = NO
+
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.
+# This is useful
+# if you want to understand what is going on.
+# On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED = FALSE=0 \
+ CPU_USE_GENERIC_BITFIELD_DATA=0 \
+ __attribute__(x)= \
+ RTEMS_COMPILER_NO_RETURN_ATTRIBUTE= \
+ RTEMS_COMPILER_DEPRECATED_ATTRIBUTE=
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
+# the parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+#
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = @PERL@
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
+# powerful graphs.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = YES
+
+# By default doxygen will write a font called FreeSans.ttf to the output
+# directory and reference it in all dot files that doxygen generates. This
+# font does not include all possible unicode characters however, so when you need
+# these (or just want a differently looking font) you can specify the font name
+# using DOT_FONTNAME. You need need to make sure dot is able to find the font,
+# which can be done by putting it in a standard location or by setting the
+# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory
+# containing the font.
+
+DOT_FONTNAME = FreeSans
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the output directory to look for the
+# FreeSans.ttf font (which doxygen will put there itself). If you specify a
+# different font using DOT_FONTNAME you can set the path where dot
+# can find it using this tag.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
new file mode 100644
index 0000000000..ec7466f1ca
--- /dev/null
+++ b/cpukit/Makefile.am
@@ -0,0 +1,193 @@
+##
+## $Id$
+##
+
+ACLOCAL_AMFLAGS = -I aclocal
+
+include $(top_srcdir)/automake/compile.am
+include $(top_srcdir)/automake/multilib.am
+
+# librtemscpu
+SUBDIRS = . score rtems sapi posix
+SUBDIRS += libcsupport libblock libfs
+SUBDIRS += libnetworking librpc
+SUBDIRS += libi2c
+SUBDIRS += libmisc
+SUBDIRS += libmd
+SUBDIRS += libgnat
+SUBDIRS += wrapup
+
+SUBDIRS += zlib
+
+# applications
+SUBDIRS += ftpd
+SUBDIRS += telnetd
+SUBDIRS += pppd
+SUBDIRS += mghttpd
+
+noinst_DATA = preinstall-stamp
+preinstall-stamp:
+ $(MAKE) $(AM_MAKEFLAGS) preinstall
+ touch preinstall-stamp
+CLEANFILES = preinstall-stamp
+
+include_HEADERS =
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS =
+
+include_rtems_rtemsdir = $(includedir)/rtems/rtems
+include_rtems_rtems_HEADERS =
+
+include_rtems_bsd_sysdir = $(include_rtemsdir)/bsd/sys
+include_rtems_bsd_sys_HEADERS = include/rtems/bsd/sys/queue.h
+include_rtems_bsd_sys_HEADERS += include/rtems/bsd/sys/cdefs.h
+
+include_uuiddir = $(includedir)/uuid
+include_uuid_HEADERS = libmisc/uuid/uuid.h
+
+if NEWLIB
+include_sysdir = $(includedir)/sys
+include_sys_HEADERS =
+
+include_HEADERS += libnetworking/memory.h \
+ libmd/md4.h \
+ libmd/md5.h
+
+include_sys_HEADERS += libcsupport/include/sys/ioccom.h \
+ libcsupport/include/sys/filio.h libcsupport/include/sys/ioctl.h \
+ libcsupport/include/sys/statvfs.h libcsupport/include/sys/sockio.h \
+ libcsupport/include/sys/ttycom.h libcsupport/include/sys/termios.h \
+ libcsupport/include/sys/utsname.h
+
+include_sys_HEADERS += libnetworking/sys/uio.h
+include_sys_HEADERS += include/sys/priority.h
+
+if LIBNETWORKING
+include_rtems_bsdnetdir = $(includedir)/rtems/bsdnet
+include_rtems_bsdnet_HEADERS = libnetworking/rtems/bsdnet/servers.h
+include_rtems_bsdnet_HEADERS += libnetworking/rtems/bsdnet/_types.h
+endif
+endif
+
+include_rtems_HEADERS += include/rtems/bspIo.h include/rtems/userenv.h \
+ include/rtems/fs.h include/rtems/pci.h \
+ include/rtems/concat.h \
+ include/rtems/status-checks.h
+
+include_rtems_HEADERS += include/rtems/btimer.h
+include_rtems_HEADERS += include/rtems/endian.h
+
+## should be conditional and only installed for PowerPC, x86, and ARM
+include_rtems_HEADERS += include/rtems/irq.h
+
+include_rtems_HEADERS += include/rtems/irq-extension.h
+
+## libfs
+include_rtems_HEADERS += libfs/src/imfs/imfs.h
+
+## POSIX FIFO/pipe
+include_rtems_HEADERS += libfs/src/pipe/pipe.h
+
+## devfs
+include_rtems_HEADERS += libfs/src/devfs/devfs.h
+
+if LIBDOSFS
+include_rtems_HEADERS += libfs/src/dosfs/dosfs.h
+endif
+
+# RFS
+include_rtems_HEADERS += \
+ libfs/src/rfs/rtems-rfs.h \
+ libfs/src/rfs/rtems-rfs-format.h \
+ libfs/src/rfs/rtems-rfs-shell.h
+include_rtems_rfsdir = $(include_rtemsdir)/rfs
+include_rtems_rfs_HEADERS = \
+ libfs/src/rfs/rtems-rfs-bitmaps.h \
+ libfs/src/rfs/rtems-rfs-block-pos.h \
+ libfs/src/rfs/rtems-rfs-block.h \
+ libfs/src/rfs/rtems-rfs-buffer.h \
+ libfs/src/rfs/rtems-rfs-data.h \
+ libfs/src/rfs/rtems-rfs-dir.h \
+ libfs/src/rfs/rtems-rfs-dir-hash.h \
+ libfs/src/rfs/rtems-rfs-file.h \
+ libfs/src/rfs/rtems-rfs-file-system-fwd.h \
+ libfs/src/rfs/rtems-rfs-file-system.h \
+ libfs/src/rfs/rtems-rfs-group.h \
+ libfs/src/rfs/rtems-rfs-inode.h \
+ libfs/src/rfs/rtems-rfs-link.h \
+ libfs/src/rfs/rtems-rfs-mutex.h \
+ libfs/src/rfs/rtems-rfs-trace.h
+
+## libblock
+include_rtems_HEADERS += libblock/include/rtems/bdbuf.h \
+ libblock/include/rtems/blkdev.h libblock/include/rtems/diskdevs.h \
+ libblock/include/rtems/flashdisk.h libblock/include/rtems/ramdisk.h \
+ libblock/include/rtems/nvdisk.h libblock/include/rtems/nvdisk-sram.h \
+ libblock/include/rtems/ide_part_table.h \
+ libblock/include/rtems/bdpart.h \
+ libblock/include/rtems/media.h
+
+## ftpd
+if LIBNETWORKING
+include_rtems_HEADERS += ftpd/ftpd.h
+endif
+
+## bspcmdline
+include_rtems_HEADERS += libmisc/bspcmdline/bspcmdline.h
+
+## capture
+include_rtems_HEADERS += libmisc/capture/capture.h \
+ libmisc/capture/capture-cli.h
+
+## cpuuse
+include_rtems_HEADERS += libmisc/cpuuse/cpuuse.h
+
+## devnull
+include_rtems_HEADERS += libmisc/devnull/devnull.h
+
+## dumpbuf
+include_rtems_HEADERS += libmisc/dumpbuf/dumpbuf.h
+
+## monitor
+include_rtems_HEADERS += libmisc/monitor/monitor.h
+
+## fb
+include_rtems_HEADERS += libmisc/fb/fb.h libmisc/fb/mw_uid.h
+
+## mouse
+include_rtems_HEADERS += libmisc/mouse/mouse_parser.h \
+ libmisc/mouse/serial_mouse.h
+
+## shell
+if LIBSHELL
+include_rtems_HEADERS += libmisc/shell/shell.h libmisc/shell/shellconfig.h
+endif
+
+## stringto
+include_rtems_HEADERS += libmisc/stringto/stringto.h
+
+## i2c
+include_rtems_HEADERS += libi2c/libi2c.h
+
+## serdbg
+if LIBSERDBG
+include_rtems_HEADERS += libmisc/serdbg/serdbgcnf.h libmisc/serdbg/serdbg.h \
+ libmisc/serdbg/termios_printk_cnf.h libmisc/serdbg/termios_printk.h
+endif
+
+## stackchk
+include_rtems_HEADERS += libmisc/stackchk/stackchk.h
+
+## libuntar
+include_rtems_HEADERS += libmisc/untar/untar.h
+
+## fsmount
+include_rtems_HEADERS += libmisc/fsmount/fsmount.h
+
+## HACK: doxygen filter.
+EXTRA_DIST = doxy-filter
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/subdirs.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/NEWS b/cpukit/NEWS
new file mode 100644
index 0000000000..205fecdb0e
--- /dev/null
+++ b/cpukit/NEWS
@@ -0,0 +1,7 @@
+Major changes since rtems-4.7.0:
+
+2007-05-09 Remove define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES (formerly in
+ score/cpu/<cpu>/score/rtems/cpu.h)
+
+ This define has not been used in RTEMS code and therefore has been
+ removed without substitute.
diff --git a/cpukit/acinclude.m4 b/cpukit/acinclude.m4
new file mode 100644
index 0000000000..da6084de90
--- /dev/null
+++ b/cpukit/acinclude.m4
@@ -0,0 +1,61 @@
+# RTEMS_CPUOPT(NAME,CONDITION,VALUE,EXPLANATION)
+
+AC_DEFUN([_RTEMS_CPUOPT_INIT],[
+AC_BEFORE([_RTEMS_CPUOPT])
+cat >>cpuopts.tmp <<\_ACEOF
+/**
+ * @file rtems/score/cpuopts.h
+ */
+
+/* target cpu dependent options file */
+/* automatically generated -- DO NOT EDIT!! */
+#ifndef _RTEMS_SCORE_CPUOPTS_H
+#define _RTEMS_SCORE_CPUOPTS_H
+_ACEOF
+])
+
+AC_DEFUN([RTEMS_CPUOPT],[
+AC_REQUIRE([_RTEMS_CPUOPT_INIT])
+AC_BEFORE([_RTEMS_CPUOPT_FINI])
+ if $2; then
+cat >>cpuopts.tmp <<_ACEOF
+
+/* $4 */
+#define $1 $3
+_ACEOF
+## FIXME: Duplicate the define to the autoheader
+## Sanity check - Should be removed in future
+ AC_DEFINE_UNQUOTED([$1],[$3],[$4])
+ else
+cat >>cpuopts.tmp <<\_ACEOF
+
+/* $4 */
+/* #undef $1 */
+_ACEOF
+ fi
+])
+
+AC_DEFUN([_RTEMS_CPUOPT_FINI],[
+cat >>cpuopts.tmp <<\_ACEOF
+
+#endif /* _RTEMS_SCORE_CPUOPTS_H */
+_ACEOF
+
+AS_MKDIR_P(score/include/rtems/score)
+AS_IF([test -f score/include/rtems/score/cpuopts.h],
+[
+ AS_IF([cmp -s score/include/rtems/score/cpuopts.h cpuopts.tmp 2>/dev/null],
+ [
+ AC_MSG_NOTICE([score/include/rtems/score/cpuopts.h is unchanged])
+ rm -f cpuopts.tmp
+ ],[
+ AC_MSG_NOTICE([creating score/include/rtems/score/cpuopts.h])
+ rm -f score/include/rtems/score/cpuopts.h
+ mv cpuopts.tmp score/include/rtems/score/cpuopts.h
+ ])
+],[
+ AC_MSG_NOTICE([creating score/include/rtems/score/cpuopts.h])
+ rm -f score/include/rtems/score/cpuopts.h
+ mv cpuopts.tmp score/include/rtems/score/cpuopts.h
+])
+])
diff --git a/cpukit/aclocal/canonical-target-name.m4 b/cpukit/aclocal/canonical-target-name.m4
new file mode 100644
index 0000000000..230583bf8c
--- /dev/null
+++ b/cpukit/aclocal/canonical-target-name.m4
@@ -0,0 +1,27 @@
+dnl
+dnl $Id$
+dnl
+
+dnl canonicalize target cpu
+dnl NOTE: Most rtems targets do not fullfil autoconf's
+dnl target naming conventions "processor-vendor-os"
+dnl Therefore autoconf's AC_CANONICAL_TARGET will fail for them
+dnl and we have to fix it for rtems ourselves
+
+AC_DEFUN([RTEMS_CANONICAL_TARGET_CPU],
+[AC_REQUIRE([AC_CANONICAL_HOST])
+AC_MSG_CHECKING(rtems target cpu)
+case "${host}" in
+*-*-rtems*)
+ RTEMS_CPU="$host_cpu";;
+*)
+ ;;
+esac
+AS_IF([test -n "$RTEMS_CPU"],
+[dnl
+AC_MSG_RESULT($RTEMS_CPU)],
+[dnl
+AC_MSG_RESULT([<none>])
+AC_MSG_ERROR([unsupported host $host])])
+AC_SUBST(RTEMS_CPU)
+])
diff --git a/cpukit/aclocal/canonicalize-tools.m4 b/cpukit/aclocal/canonicalize-tools.m4
new file mode 100644
index 0000000000..540c9a4c29
--- /dev/null
+++ b/cpukit/aclocal/canonicalize-tools.m4
@@ -0,0 +1,15 @@
+dnl
+dnl $Id$
+dnl
+dnl Set target tools
+dnl
+
+AC_DEFUN([RTEMS_CANONICALIZE_TOOLS],
+[AC_REQUIRE([RTEMS_PROG_CC])dnl
+
+dnl FIXME: What shall be done if these tools are not available?
+ RTEMS_CHECK_TOOL(AR,ar,no)
+
+dnl special treatment of ranlib
+ RTEMS_CHECK_TOOL(RANLIB,ranlib,:)
+])
diff --git a/cpukit/aclocal/check-func.m4 b/cpukit/aclocal/check-func.m4
new file mode 100644
index 0000000000..92787e1b87
--- /dev/null
+++ b/cpukit/aclocal/check-func.m4
@@ -0,0 +1,23 @@
+# $Id$
+
+# Check whether FUNCTION is declared in INCLUDES
+# and whether rtems_stub_FUNCTION or FUNCTION is supplied.
+
+# RTEMS_CHECK_FUNC(FUNCTION[,INCLUDES])
+AC_DEFUN([RTEMS_CHECK_FUNC],
+[AC_REQUIRE([RTEMS_CHECK_NEWLIB])
+AC_CHECK_DECLS([$1],,,[$2])
+
+AC_CACHE_CHECK([for $1],[ac_cv_$1],[
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[$2]],[[rtems_stub_$1()]])],
+ [ac_cv_$1="stub"],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[$2]],[[$1()]])],
+ [ac_cv_$1="yes"],
+ [ac_cv_$1="no"])
+ ])
+ ])
+AS_IF([test "$ac_cv_$1" = yes],
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]$1),[1],[Define to 1 if you have the `$1' function.])])
+])
diff --git a/cpukit/aclocal/check-multiprocessing.m4 b/cpukit/aclocal/check-multiprocessing.m4
new file mode 100644
index 0000000000..ca4338b09a
--- /dev/null
+++ b/cpukit/aclocal/check-multiprocessing.m4
@@ -0,0 +1,9 @@
+dnl
+dnl $Id$
+dnl
+
+AC_DEFUN([RTEMS_CHECK_MULTIPROCESSING],
+[dnl
+AC_REQUIRE([RTEMS_ENV_RTEMSCPU])dnl
+AC_REQUIRE([RTEMS_ENABLE_MULTIPROCESSING])dnl
+])
diff --git a/cpukit/aclocal/check-networking.m4 b/cpukit/aclocal/check-networking.m4
new file mode 100644
index 0000000000..1b8fe38fd9
--- /dev/null
+++ b/cpukit/aclocal/check-networking.m4
@@ -0,0 +1,32 @@
+dnl $Id$
+dnl
+AC_DEFUN([RTEMS_CHECK_NETWORKING],
+[dnl
+AC_REQUIRE([RTEMS_CANONICAL_TARGET_CPU])dnl
+AC_REQUIRE([RTEMS_ENABLE_NETWORKING])dnl
+
+AC_CACHE_CHECK([whether CPU supports networking],
+ rtems_cv_HAS_NETWORKING,
+ [dnl
+ case "$host" in
+ *-*-rtems*)
+ AS_IF([test "${RTEMS_HAS_NETWORKING}" = "yes"],[
+# suppress libnetworking if one these types is not available
+ AS_IF([test x"$ac_cv_type_int8_t" = xyes \
+ && test x"$ac_cv_type_uint8_t" = xyes \
+ && test x"$ac_cv_type_int16_t" = xyes \
+ && test x"$ac_cv_type_uint16_t" = xyes \
+ && test x"$ac_cv_type_int32_t" = xyes \
+ && test x"$ac_cv_type_uint32_t" = xyes \
+ && test x"$ac_cv_type_int64_t" = xyes \
+ && test x"$ac_cv_type_uint64_t" = xyes],
+ [rtems_cv_HAS_NETWORKING=yes],
+ [rtems_cv_HAS_NETWORKING=no])
+ ],[
+ rtems_cv_HAS_NETWORKING=disabled
+ ])
+ ;;
+ esac
+ ])
+ ])
+])
diff --git a/cpukit/aclocal/check-newlib.m4 b/cpukit/aclocal/check-newlib.m4
new file mode 100644
index 0000000000..bbf5f68dc2
--- /dev/null
+++ b/cpukit/aclocal/check-newlib.m4
@@ -0,0 +1,30 @@
+dnl $Id$
+
+AC_DEFUN([RTEMS_CHECK_NEWLIB],
+[dnl
+AC_REQUIRE([RTEMS_PROG_CC_FOR_TARGET])dnl
+AC_REQUIRE([RTEMS_CANONICALIZE_TOOLS])dnl
+AC_CACHE_CHECK([for RTEMS newlib],
+ rtems_cv_use_newlib,
+ [
+dnl some versions of newlib provide not_required_by_rtems
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[extern void not_required_by_rtems() ;]],
+ [[not_required_by_rtems()]])],
+ [rtems_cv_use_newlib="yes"],[])
+
+dnl some versions of newlib provide rtems_provides_crt0()
+ AS_IF([test -z "$rtems_cv_use_newlib"],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[extern void rtems_provides_crt0() ;]],
+ [[rtems_provides_crt0()]])],
+ [rtems_cv_use_newlib="yes"],[rtems_cv_use_newlib="no"])
+ ])
+ ])
+ RTEMS_USE_NEWLIB="$rtems_cv_use_newlib"
+ AC_SUBST(RTEMS_USE_NEWLIB)
+
+ AS_IF([test x"${RTEMS_USE_NEWLIB}" = x"yes"],
+ [ AC_DEFINE_UNQUOTED(RTEMS_NEWLIB,1,[if using newlib])]
+ )
+])
diff --git a/cpukit/aclocal/check-posix.m4 b/cpukit/aclocal/check-posix.m4
new file mode 100644
index 0000000000..a00dc2456b
--- /dev/null
+++ b/cpukit/aclocal/check-posix.m4
@@ -0,0 +1,20 @@
+dnl $Id$
+dnl
+AC_DEFUN([RTEMS_CHECK_POSIX_API],
+[dnl
+AC_REQUIRE([RTEMS_CANONICAL_TARGET_CPU])dnl
+AC_REQUIRE([RTEMS_ENABLE_POSIX])dnl
+
+AC_CACHE_CHECK([whether CPU supports libposix],
+ rtems_cv_HAS_POSIX_API,
+ [dnl
+ case "$host" in
+ *-*-rtems*)
+ if test "${RTEMS_HAS_POSIX_API}" = "yes"; then
+ rtems_cv_HAS_POSIX_API="yes";
+ else
+ rtems_cv_HAS_POSIX_API="disabled";
+ fi
+ ;;
+ esac])
+])
diff --git a/cpukit/aclocal/check-rtems-debug.m4 b/cpukit/aclocal/check-rtems-debug.m4
new file mode 100644
index 0000000000..ef5c14efef
--- /dev/null
+++ b/cpukit/aclocal/check-rtems-debug.m4
@@ -0,0 +1,7 @@
+## $Id$
+
+AC_DEFUN([RTEMS_CHECK_RTEMS_DEBUG],
+[AC_REQUIRE([RTEMS_ENABLE_RTEMS_DEBUG])
+AS_IF([test x"${enable_rtems_debug}" = x"yes"],
+ [AC_DEFINE_UNQUOTED(RTEMS_DEBUG,1,[if RTEMS_DEBUG is enabled])])
+])
diff --git a/cpukit/aclocal/check-smp.m4 b/cpukit/aclocal/check-smp.m4
new file mode 100644
index 0000000000..294f5c9d2c
--- /dev/null
+++ b/cpukit/aclocal/check-smp.m4
@@ -0,0 +1,19 @@
+dnl $Id$
+dnl
+AC_DEFUN([RTEMS_CHECK_SMP],
+[dnl
+AC_REQUIRE([RTEMS_ENABLE_SMP])dnl
+
+AC_CACHE_CHECK([whether CPU supports libposix],
+ rtems_cv_HAS_SMP,
+ [dnl
+ case "$RTEMS_CPU" in
+ *)
+ if test "${RTEMS_HAS_SMP}" = "yes"; then
+ rtems_cv_HAS_SMP="yes";
+ else
+ rtems_cv_HAS_SMP="disabled";
+ fi
+ ;;
+ esac])
+])
diff --git a/cpukit/aclocal/check-tool.m4 b/cpukit/aclocal/check-tool.m4
new file mode 100644
index 0000000000..4c412c074a
--- /dev/null
+++ b/cpukit/aclocal/check-tool.m4
@@ -0,0 +1,11 @@
+dnl $Id$
+
+## Check for a cross tool, similar to AC_CHECK_TOOL, but do not fall back to
+## the un-prefixed version of PROG-TO-CHECK-FOR.
+dnl RTEMS_CHECK_TOOL(VARIABLE, PROG-TO-CHECK-FOR[, VALUE-IF-NOT-FOUND [, PATH]])
+AC_DEFUN([RTEMS_CHECK_TOOL],
+[
+ AS_IF([test "x$build_alias" != "x$host_alias"],
+ [rtems_tool_prefix=${ac_tool_prefix}])
+ AC_CHECK_PROG($1, ${rtems_tool_prefix}$2, ${rtems_tool_prefix}$2, $3, $4)
+])
diff --git a/cpukit/aclocal/enable-multiprocessing.m4 b/cpukit/aclocal/enable-multiprocessing.m4
new file mode 100644
index 0000000000..f664800e40
--- /dev/null
+++ b/cpukit/aclocal/enable-multiprocessing.m4
@@ -0,0 +1,12 @@
+dnl $Id$
+
+AC_DEFUN([RTEMS_ENABLE_MULTIPROCESSING],
+[
+AC_ARG_ENABLE(multiprocessing,
+AS_HELP_STRING(--enable-multiprocessing,enable multiprocessing interface),
+[case "${enable_multiprocessing}" in
+ yes) ;;
+ no) ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for enable-multiprocessing option) ;;
+esac],[enable_multiprocessing=no])
+])
diff --git a/cpukit/aclocal/enable-networking.m4 b/cpukit/aclocal/enable-networking.m4
new file mode 100644
index 0000000000..a7be7b4df7
--- /dev/null
+++ b/cpukit/aclocal/enable-networking.m4
@@ -0,0 +1,14 @@
+dnl $Id$
+
+AC_DEFUN([RTEMS_ENABLE_NETWORKING],
+[
+## AC_BEFORE([$0], [RTEMS_CHECK_NETWORKING])dnl
+
+AC_ARG_ENABLE(networking,
+AS_HELP_STRING(--enable-networking,enable TCP/IP stack),
+[case "${enableval}" in
+ yes) RTEMS_HAS_NETWORKING=yes ;;
+ no) RTEMS_HAS_NETWORKING=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for enable-networking option) ;;
+esac],[RTEMS_HAS_NETWORKING=yes])
+])
diff --git a/cpukit/aclocal/enable-posix.m4 b/cpukit/aclocal/enable-posix.m4
new file mode 100644
index 0000000000..8859e54e7f
--- /dev/null
+++ b/cpukit/aclocal/enable-posix.m4
@@ -0,0 +1,23 @@
+dnl $Id$
+
+AC_DEFUN([RTEMS_ENABLE_POSIX],
+[
+## AC_BEFORE([$0], [RTEMS_CHECK_POSIX_API])dnl
+
+AC_ARG_ENABLE(posix,
+AS_HELP_STRING(--enable-posix,enable posix interface),
+[case "${enableval}" in
+ yes) RTEMS_HAS_POSIX_API=yes ;;
+ no) RTEMS_HAS_POSIX_API=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for enable-posix option) ;;
+esac],[RTEMS_HAS_POSIX_API=yes])
+
+case "${host}" in
+ no_cpu-*rtems*)
+ RTEMS_HAS_POSIX_API=no
+ ;;
+ *)
+ ;;
+esac
+AC_SUBST(RTEMS_HAS_POSIX_API)
+])
diff --git a/cpukit/aclocal/enable-rtems-debug.m4 b/cpukit/aclocal/enable-rtems-debug.m4
new file mode 100644
index 0000000000..ada9fe30f4
--- /dev/null
+++ b/cpukit/aclocal/enable-rtems-debug.m4
@@ -0,0 +1,12 @@
+## $Id$
+
+AC_DEFUN([RTEMS_ENABLE_RTEMS_DEBUG],
+[
+AC_ARG_ENABLE(rtems-debug,
+AS_HELP_STRING(--enable-rtems-debug,enable RTEMS_DEBUG),
+[case "${enable_rtems_debug}" in
+ yes) enable_rtems_debug=yes ;;
+ no) enable_rtems_debug=no ;;
+ *) AC_MSG_ERROR([bad value ${enable_rtems_debug} for RTEMS_DEBUG]) ;;
+esac],[enable_rtems_debug=no])
+])
diff --git a/cpukit/aclocal/enable-smp.m4 b/cpukit/aclocal/enable-smp.m4
new file mode 100644
index 0000000000..84561f8bbd
--- /dev/null
+++ b/cpukit/aclocal/enable-smp.m4
@@ -0,0 +1,18 @@
+dnl $Id$
+
+AC_DEFUN([RTEMS_ENABLE_SMP],
+[
+## AC_BEFORE([$0], [RTEMS_CHECK_SMP])dnl
+
+AC_ARG_ENABLE(smp,
+[AS_HELP_STRING([--enable-smp],[enable smp interface])],
+[case "${enableval}" in
+ yes) case "${RTEMS_CPU}" in
+ sparc|i386) RTEMS_HAS_SMP=yes ;;
+ *) RTEMS_HAS_SMP=no ;;
+ esac
+ ;;
+ no) RTEMS_HAS_SMP=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for enable-smp option) ;;
+esac],[RTEMS_HAS_SMP=no])
+])
diff --git a/cpukit/aclocal/env-rtemscpu.m4 b/cpukit/aclocal/env-rtemscpu.m4
new file mode 100644
index 0000000000..65dea4ef49
--- /dev/null
+++ b/cpukit/aclocal/env-rtemscpu.m4
@@ -0,0 +1,8 @@
+dnl $Id$
+
+AC_DEFUN([RTEMS_ENV_RTEMSCPU],
+[
+ AC_REQUIRE([RTEMS_ENABLE_MULTILIB])
+
+ AM_CONDITIONAL([MULTILIB],[test x"$multilib" = x"yes"])
+])
diff --git a/cpukit/aclocal/gcc-pipe.m4 b/cpukit/aclocal/gcc-pipe.m4
new file mode 100644
index 0000000000..2a04629bb2
--- /dev/null
+++ b/cpukit/aclocal/gcc-pipe.m4
@@ -0,0 +1,21 @@
+dnl
+dnl $Id$
+dnl
+dnl Check whether the target compiler accepts -pipe
+dnl
+
+AC_DEFUN([RTEMS_GCC_PIPE],
+[AC_REQUIRE([RTEMS_PROG_CC])
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_CACHE_CHECK(whether $CC accepts --pipe,rtems_cv_gcc_pipe,
+[
+rtems_cv_gcc_pipe=no
+if test x"$GCC" = x"yes"; then
+ echo 'void f(){}' >conftest.c
+ if test -z "`${CC} --pipe -c conftest.c 2>&1`";then
+ rtems_cv_gcc_pipe=yes
+ fi
+ rm -f conftest*
+fi
+])
+])
diff --git a/cpukit/aclocal/gcc-sanity.m4 b/cpukit/aclocal/gcc-sanity.m4
new file mode 100644
index 0000000000..0177009e28
--- /dev/null
+++ b/cpukit/aclocal/gcc-sanity.m4
@@ -0,0 +1,114 @@
+# Some GCC sanity checks to check for known bugs in the rtems gcc toolchains
+
+# Internal macro
+# _RTEMS_GCC_WARNING(msg,cache-variable,include,main)
+AC_DEFUN([_RTEMS_GCC_WARNING],[
+ AC_CACHE_CHECK([$1],
+ [$2],[
+ AS_IF([test x"$GCC" = xyes],[
+ save_CFLAGS=$CFLAGS
+ CFLAGS="-Wall -Werror"])
+
+ AC_COMPILE_IFELSE([
+ AC_LANG_PROGRAM([$3],[$4])],
+ [$2=yes],
+ [$2=no])
+
+ AS_IF([test x"$GCC" = xyes],[
+ CFLAGS=$save_CFLAGS])
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRIxPTR],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%" PRIxPTR, uintptr_t) works],
+ [rtems_cv_PRIxPTR],[
+ #include <inttypes.h>
+ #include <stdio.h>
+ ],[
+ uintptr_t ptr = 42;
+ printf("%" PRIxPTR "\n", ptr);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRIuPTR],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%" PRIuPTR, uintptr_t) works],
+ [rtems_cv_PRIuPTR],[
+ #include <inttypes.h>
+ #include <stdio.h>
+ ],[
+ uintptr_t ptr = 42;
+ printf("%" PRIuPTR "\n", ptr);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRIdPTR],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%" PRIdPTR, intptr_t) works],
+ [rtems_cv_PRIdPTR],[
+ #include <inttypes.h>
+ #include <stdio.h>
+ ],[
+ intptr_t ptr = -1;
+ printf("%" PRIdPTR "\n", ptr);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRINTF_ZU_SIZE_T],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%zu", size_t) works],
+ [rtems_cv_PRINTF_ZU_SIZE_T],[
+ #include <sys/types.h>
+ #include <stdio.h>
+ ],[
+ size_t sz = 1;
+ printf("%zu\n", sz);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRINTF_ZD_SSIZE_T],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%zd", ssize_t) works],
+ [rtems_cv_PRINTF_ZD_SSIZE_T],[
+ #include <sys/types.h>
+ #include <stdio.h>
+ ],[
+ ssize_t sz = 1;
+ printf("%zd\n", sz);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRINTF_LD_OFF_T],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%ld", off_t) works],
+ [rtems_cv_PRINTF_LD_OFF_T],[
+ #include <sys/types.h>
+ #include <stdio.h>
+ ],[
+ off_t off = 1;
+ printf("%ld\n", off);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_PRINTF_LLD_OFF_T],[
+ _RTEMS_GCC_WARNING(
+ [if printf("%lld", off_t) works],
+ [rtems_cv_PRINTF_LLD_OFF_T],[
+ #include <sys/types.h>
+ #include <stdio.h>
+ ],[
+ off_t off = 1;
+ printf("%lld\n", off);
+ ])
+])
+
+AC_DEFUN([RTEMS_CHECK_GCC_SANITY],[
+RTEMS_CHECK_GCC_PRIxPTR
+RTEMS_CHECK_GCC_PRIuPTR
+RTEMS_CHECK_GCC_PRIdPTR
+RTEMS_CHECK_GCC_PRINTF_ZU_SIZE_T
+RTEMS_CHECK_GCC_PRINTF_ZD_SSIZE_T
+RTEMS_CHECK_GCC_PRINTF_LD_OFF_T
+RTEMS_CHECK_GCC_PRINTF_LLD_OFF_T
+])
diff --git a/cpukit/aclocal/gcc-weak.m4 b/cpukit/aclocal/gcc-weak.m4
new file mode 100644
index 0000000000..73cfb28e7e
--- /dev/null
+++ b/cpukit/aclocal/gcc-weak.m4
@@ -0,0 +1,19 @@
+AC_DEFUN([RTEMS_CHECK_GCC_WEAK],[
+AC_CACHE_CHECK([whether $CC supports function __attribute__((weak))],
+[rtems_cv_cc_attribute_weak],[
+ AS_IF([test x"$GCC" = xyes],[
+ save_CFLAGS=$CFLAGS
+ CFLAGS=-Werror])
+
+ AC_COMPILE_IFELSE([
+ AC_LANG_PROGRAM(
+ [void myfunc(char c) __attribute__ ((weak));
+ void myfunc(char c) {}],
+ [])],
+ [rtems_cv_cc_attribute_weak=yes],
+ [rtems_cv_cc_attribute_weak=no])
+
+ AS_IF([test x"$GCC" = xyes],[
+ CFLAGS=$save_CFLAGS])
+])
+])
diff --git a/cpukit/aclocal/multi.m4 b/cpukit/aclocal/multi.m4
new file mode 100644
index 0000000000..7cdc3cb023
--- /dev/null
+++ b/cpukit/aclocal/multi.m4
@@ -0,0 +1,50 @@
+#serial 99
+
+AC_DEFUN([AC_ENABLE_MULTILIB],
+[
+AC_ARG_ENABLE(multilib,
+AS_HELP_STRING(--enable-multilib,build many library versions (default=no)),
+[case "${enableval}" in
+ yes) multilib=yes ;;
+ no) multilib=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for multilib option) ;;
+ esac], [multilib=no])dnl
+
+AM_CONDITIONAL(MULTILIB,test x"${multilib}" = x"yes")
+
+dnl We may get other options which we don't document:
+dnl --with-target-subdir, --with-multisrctop, --with-multisubdir
+
+if test "[$]{srcdir}" = "."; then
+ if test "[$]{with_target_subdir}" != "."; then
+ multilib_basedir="[$]{srcdir}/[$]{with_multisrctop}../ifelse([$2],,,[$2])"
+ else
+ multilib_basedir="[$]{srcdir}/[$]{with_multisrctop}ifelse([$2],,,[$2])"
+ fi
+else
+ multilib_basedir="[$]{srcdir}/ifelse([$2],,,[$2])"
+fi
+AC_SUBST(multilib_basedir)
+
+if test "${multilib}" = "yes"; then
+ multilib_arg="--enable-multilib"
+else
+ multilib_arg=
+fi
+
+AC_CONFIG_COMMANDS([default-1],[case " $CONFIG_FILES " in
+ *" ]m4_if([$1],,Makefile,[$1])[ "*)
+ ac_file=]m4_if([$1],,Makefile,[$1])[ . ${multilib_basedir}/config-ml.in
+esac],[
+ srcdir=${srcdir}
+ host=${host}
+ target=${target}
+ with_multisrctop="${with_multisrctop}"
+ with_target_subdir="${with_target_subdir}"
+ with_multisubdir="${with_multisubdir}"
+ ac_configure_args="${multilib_arg} ${ac_configure_args}"
+ CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+ multilib_basedir=${multilib_basedir}
+ CC="${CC}"
+])
+])
diff --git a/cpukit/aclocal/multilib.m4 b/cpukit/aclocal/multilib.m4
new file mode 100644
index 0000000000..90e6217780
--- /dev/null
+++ b/cpukit/aclocal/multilib.m4
@@ -0,0 +1,14 @@
+dnl This provides configure definitions used for multilib support
+
+AC_DEFUN([RTEMS_ENABLE_MULTILIB],
+[
+AC_ARG_ENABLE(multilib,
+AS_HELP_STRING(--enable-multilib,build many library versions (default=no)),
+[case "${enableval}" in
+ yes) multilib=yes ;;
+ no) multilib=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for multilib option) ;;
+ esac], [multilib=no])dnl
+
+AM_CONDITIONAL([MULTILIB],[test x"${multilib}" = x"yes"])
+])
diff --git a/cpukit/aclocal/prog-cc.m4 b/cpukit/aclocal/prog-cc.m4
new file mode 100644
index 0000000000..6de5b33d57
--- /dev/null
+++ b/cpukit/aclocal/prog-cc.m4
@@ -0,0 +1,41 @@
+dnl
+dnl $Id$
+dnl
+dnl Check for target gcc
+dnl
+
+AC_DEFUN([RTEMS_PROG_CC],
+[
+AC_BEFORE([$0], [AC_PROG_CPP])dnl
+AC_BEFORE([$0], [AC_PROG_CC])dnl
+AC_BEFORE([$0], [RTEMS_CANONICALIZE_TOOLS])dnl
+
+RTEMS_CHECK_TOOL(CC,gcc)
+test -z "$CC" && \
+ AC_MSG_ERROR([no acceptable cc found in \$PATH])
+AC_PROG_CC
+AC_PROG_CPP
+])
+
+AC_DEFUN([RTEMS_PROG_CC_FOR_TARGET],
+[
+# Was CFLAGS set?
+rtems_cv_CFLAGS_set="${CFLAGS+set}"
+dnl check target cc
+RTEMS_PROG_CC
+dnl check if the target compiler may use --pipe
+RTEMS_GCC_PIPE
+test "$rtems_cv_gcc_pipe" = "yes" && CC="$CC --pipe"
+
+# Append warning flags if CFLAGS wasn't set.
+AS_IF([test "$GCC" = yes && test "$rtems_cv_CFLAGS_set" != set],
+[CFLAGS="$CFLAGS -Wall -Wimplicit-function-declaration -Wstrict-prototypes -Wnested-externs"])
+
+RTEMS_CPPFLAGS="-I\$(top_builddir) -I\$(PROJECT_INCLUDE)"
+AC_SUBST(RTEMS_CPPFLAGS)
+
+AS_IF([test "$GCC" = yes],[
+ RTEMS_RELLDFLAGS="-qnolinkcmds -nostdlib -r"
+])
+AC_SUBST(RTEMS_RELLDFLAGS)
+])
diff --git a/cpukit/aclocal/prog-ccas.m4 b/cpukit/aclocal/prog-ccas.m4
new file mode 100644
index 0000000000..15b1a2c9b8
--- /dev/null
+++ b/cpukit/aclocal/prog-ccas.m4
@@ -0,0 +1,8 @@
+## $Id$
+
+AC_DEFUN([RTEMS_PROG_CCAS],
+[
+AC_REQUIRE([RTEMS_PROG_CC])
+AM_PROG_AS
+AC_SUBST(RTEMS_CCASFLAGS,["-DASM \$(CFLAGS)"])
+])
diff --git a/cpukit/aclocal/rtems-ampolish.m4 b/cpukit/aclocal/rtems-ampolish.m4
new file mode 100644
index 0000000000..328df7afcb
--- /dev/null
+++ b/cpukit/aclocal/rtems-ampolish.m4
@@ -0,0 +1,12 @@
+# $Id$
+
+AC_DEFUN([RTEMS_AMPOLISH3],
+[
+AC_REQUIRE([AM_MAINTAINER_MODE])
+AC_PATH_PROG([PERL],[perl],[])
+AC_SUBST(AMPOLISH3,["\$(PERL) ${am_aux_dir}/ampolish3"])
+AM_CONDITIONAL([AMPOLISH3],
+[test x"$USE_MAINTAINER_MODE" = x"yes" \
+ && test -n "${PERL}"])
+])
+
diff --git a/cpukit/aclocal/rtems-top.m4 b/cpukit/aclocal/rtems-top.m4
new file mode 100644
index 0000000000..357ea55c4d
--- /dev/null
+++ b/cpukit/aclocal/rtems-top.m4
@@ -0,0 +1,72 @@
+dnl $Id$
+
+# AC_DISABLE_OPTION_CHECKING is not available before 2.62
+AC_PREREQ(2.62)
+
+dnl
+dnl RTEMS_TOP($1)
+dnl
+dnl $1 .. relative path from this configure.ac to the toplevel configure.ac
+dnl
+AC_DEFUN([RTEMS_TOP],
+[dnl
+AC_REQUIRE([RTEMS_VERSIONING])
+AC_REQUIRE([AM_SET_LEADING_DOT])
+AC_REQUIRE([AC_DISABLE_OPTION_CHECKING])
+AC_CONFIG_AUX_DIR([$1])
+AC_CHECK_PROGS(MAKE, gmake make)
+AC_BEFORE([$0], [AM_INIT_AUTOMAKE])dnl
+
+AC_PREFIX_DEFAULT([/opt/rtems-][_RTEMS_API])
+
+AC_SUBST([RTEMS_TOPdir],["$1"])
+
+# HACK: The sed pattern below strips of "../", corresponding to "cpukit/"
+rtems_updir=m4_if([$2],[],[`echo "$1/" | sed 's,^\.\.\/,,'`],[$2/])
+
+AS_IF([test -n "$with_multisubdir"],
+ [MULTIBUILDTOP=`echo "/$with_multisubdir" | sed 's,/[[^\\/]]*,../,g'`])
+AC_SUBST(MULTIBUILDTOP)
+
+AS_IF([test -n "$with_multisubdir"],
+ [MULTISUBDIR="/$with_multisubdir"])
+AC_SUBST(MULTISUBDIR)
+
+AC_ARG_WITH([project-root],[
+AS_HELP_STRING(--with-project-root,directory to pre-install files into)],[
+## Make sure to have a terminating '/'
+case "${with_project_root}" in
+*/) ;;
+*) with_project_root="${with_project_root}/" ;;
+esac
+
+case "${with_project_root}" in
+ [[\\/$]]* | ?:[[\\/]]* ) # absolute directory
+ PROJECT_ROOT=${with_project_root}
+ ;;
+ *) # relative directory
+ sav0dir=`pwd` && cd ./${rtems_updir}
+ sav1dir=`pwd` && cd ../${MULTIBUILDTOP}
+ sav2dir=`pwd` && cd "$sav0dir"
+ mydir=`echo "$sav1dir" | sed "s,^$sav2dir${MULTISUBDIR}/,,"`
+ PROJECT_ROOT='$(top_builddir)'/${rtems_updir}'../$(MULTIBUILDTOP)'${mydir}/${with_project_root}
+ ;;
+esac],[
+## Defaults: Note: Two different defaults!
+## ../ for multilib
+## '.' for non-multilib
+AS_IF([test "$enable_multilib" = "yes"],[
+ PROJECT_ROOT='$(top_builddir)'/${rtems_updir}'../$(MULTIBUILDTOP)'],[
+ PROJECT_ROOT='$(top_builddir)'/${rtems_updir}])
+])
+
+AC_SUBST([PROJECT_INCLUDE],["${PROJECT_ROOT}lib/include"])
+AC_SUBST([PROJECT_LIB],["${PROJECT_ROOT}lib\$(MULTISUBDIR)"])
+
+libdir="${libdir}\$(MULTISUBDIR)"
+
+AC_SUBST([project_libdir],["\$(libdir)"])
+AC_SUBST([project_includedir],["\$(includedir)"])
+
+AC_SUBST([dirstamp],[\${am__leading_dot}dirstamp])
+])dnl
diff --git a/cpukit/aclocal/version.m4 b/cpukit/aclocal/version.m4
new file mode 100644
index 0000000000..6ca81ac661
--- /dev/null
+++ b/cpukit/aclocal/version.m4
@@ -0,0 +1,4 @@
+AC_DEFUN([RTEMS_VERSIONING],
+m4_define([_RTEMS_VERSION],[4.10.99.0]))
+
+m4_define([_RTEMS_API],[4.11])
diff --git a/cpukit/automake/compile.am b/cpukit/automake/compile.am
new file mode 100644
index 0000000000..1fe10fee5c
--- /dev/null
+++ b/cpukit/automake/compile.am
@@ -0,0 +1,10 @@
+##
+## $Id$
+##
+
+AM_CPPFLAGS = @RTEMS_CPPFLAGS@
+AM_CFLAGS =
+AM_CFLAGS += -Werror=overflow
+AM_CFLAGS += -Werror=pointer-to-int-cast
+AM_CFLAGS += -Werror=int-to-pointer-cast
+AM_CCASFLAGS = @RTEMS_CCASFLAGS@
diff --git a/cpukit/automake/local.am b/cpukit/automake/local.am
new file mode 100644
index 0000000000..68160311b5
--- /dev/null
+++ b/cpukit/automake/local.am
@@ -0,0 +1,5 @@
+## $Id$
+
+preinstall-am: $(PREINSTALL_FILES)
+preinstall: preinstall-am
+.PHONY: preinstall preinstall-am
diff --git a/cpukit/automake/multilib.am b/cpukit/automake/multilib.am
new file mode 100644
index 0000000000..9f2024f8d9
--- /dev/null
+++ b/cpukit/automake/multilib.am
@@ -0,0 +1,36 @@
+## $Id$
+
+if MULTILIB
+MULTISRCTOP =
+MULTIDIRS =
+MULTIDO = true
+MULTICLEAN = true
+endif
+
+# Multilib support rules
+.PHONY: all-multi install-multi mostlyclean-multi clean-multi distclean-multi \
+ maintainer-clean-multi
+
+if MULTILIB
+all-recursive: all-multi
+install-recursive: install-multi
+
+mostlyclean-recursive: mostlyclean-multi
+clean-recursive: clean-multi
+distclean-recursive: distclean-multi
+maintainer-clean-recursive: maintainer-clean-multi
+
+all-multi:
+ $(MULTIDO) $(AM_MAKEFLAGS) DO=all multi-do
+install-multi:
+ $(MULTIDO) $(AM_MAKEFLAGS) DO=install multi-do
+
+mostlyclean-multi:
+ $(MULTICLEAN) $(AM_MAKEFLAGS) DO=mostlyclean multi-clean
+clean-multi:
+ $(MULTICLEAN) $(AM_MAKEFLAGS) DO=clean multi-clean
+distclean-multi:
+ $(MULTICLEAN) $(AM_MAKEFLAGS) DO=distclean multi-clean
+maintainer-clean-multi:
+ $(MULTICLEAN) $(AM_MAKEFLAGS) DO=maintainer-clean multi-clean
+endif
diff --git a/cpukit/automake/subdirs.am b/cpukit/automake/subdirs.am
new file mode 100644
index 0000000000..61e421f18b
--- /dev/null
+++ b/cpukit/automake/subdirs.am
@@ -0,0 +1,32 @@
+## $Id$
+
+## Borrowed from automake-1.4 and adapted to RTEMS
+
+## NOTE: This is a temporary work-around to keep
+## RTEMS's non automake standard make targets working.
+## Once automake is fully integrated these make targets
+## and this file will probably be removed
+
+preinstall-recursive:
+ @set fnord $(MAKEFLAGS); amf=$$2; \
+ dot_seen=no; \
+ target=`echo $@ | sed s/-recursive//`; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+## This trick allows "-k" to keep its natural meaning when running a
+## recursive rule.
+ || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+ fi; test -z "$$fail"
+
+preinstall: preinstall-recursive
+.PHONY: preinstall-recursive
diff --git a/cpukit/configure.ac b/cpukit/configure.ac
new file mode 100644
index 0000000000..4a771add3d
--- /dev/null
+++ b/cpukit/configure.ac
@@ -0,0 +1,370 @@
+## Process this file with autoconf to produce a configure script.
+##
+## $Id$
+
+AC_PREREQ([2.68])
+AC_INIT([rtems-cpukit],[_RTEMS_VERSION],[http://www.rtems.org/bugzilla])
+AC_CONFIG_SRCDIR([score])
+RTEMS_TOP([..],[])
+
+RTEMS_CANONICAL_TARGET_CPU
+
+AM_INIT_AUTOMAKE([no-define nostdinc subdir-objects foreign 1.11.1])
+AM_MAINTAINER_MODE
+
+RTEMS_ENABLE_MULTILIB
+RTEMS_ENABLE_MULTIPROCESSING
+RTEMS_ENABLE_POSIX
+RTEMS_ENABLE_RTEMS_DEBUG
+RTEMS_ENABLE_NETWORKING
+
+RTEMS_ENV_RTEMSCPU
+RTEMS_CHECK_RTEMS_DEBUG
+
+# Is this a supported CPU?
+AC_MSG_CHECKING([if cpu $RTEMS_CPU is supported])
+if test -d "$srcdir/score/cpu/$RTEMS_CPU"; then
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_ERROR(no)
+fi
+
+RTEMS_PROG_CC_FOR_TARGET
+RTEMS_PROG_CCAS
+RTEMS_CANONICALIZE_TOOLS
+AM_PROG_CC_C_O
+AC_PROG_RANLIB
+
+RTEMS_CHECK_NEWLIB
+
+# BSD-isms, used throughout the sources
+# Not really used by this configure script
+# FIXME: They should be eliminated if possible.
+AC_CHECK_FUNCS([strsep strcasecmp snprintf])
+AC_CHECK_FUNCS([strdup strndup strncasecmp])
+AC_CHECK_FUNCS([bcopy bcmp])
+AC_CHECK_FUNCS([isascii fileno])
+
+# <FIXME>
+# Check for functions supplied by newlib >= 1.17.0
+# Newlib's posix/ directory
+AC_CHECK_FUNCS([readdir_r isatty])
+AC_CHECK_FUNCS([creat \
+ opendir closedir readdir rewinddir scandir seekdir \
+ sleep \
+ telldir \
+ usleep],,
+ [rtems_missing_func="$ac_func";break])
+AS_IF([test -n "$rtems_missing_func"],
+ AC_MSG_ERROR([Missing function $rtems_missing_func in libc])])
+AC_CHECK_FUNCS([__assert])
+AC_CHECK_FUNCS([execl execlp execle execv execvp execve])
+AC_CHECK_FUNCS([regcomp regexec regerror regfree])
+
+# Mandated by POSIX, decls not present in some versions of newlib
+AC_CHECK_DECLS([flockfile],[AC_CHECK_FUNCS([flockfile])],,[#include <stdio.h>])
+AC_CHECK_DECLS([funlockfile],[AC_CHECK_FUNCS([funlockfile])],,[#include <stdio.h>])
+AC_CHECK_DECLS([ftrylockfile],[AC_CHECK_FUNCS([ftrylockfile])],,[#include <stdio.h>])
+
+# Mandated by POSIX, decls not present in some versions of newlib,
+# some versions stubbed in newlib's rtems crt0
+RTEMS_CHECK_FUNC([seteuid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([geteuid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([setegid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([getegid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([setuid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([getuid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([setgid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([getgid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([setsid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([getsid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([setpgid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([getpgid],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([setpgrp],[#include <unistd.h>])
+RTEMS_CHECK_FUNC([getpgrp],[#include <unistd.h>])
+
+# pthread-functions not declared in some versions of newlib.
+RTEMS_CHECK_FUNC([pthread_attr_getguardsize],[#include <pthread.h>])
+RTEMS_CHECK_FUNC([pthread_attr_setguardsize],[#include <pthread.h>])
+RTEMS_CHECK_FUNC([pthread_attr_setstack],[#include <pthread.h>])
+RTEMS_CHECK_FUNC([pthread_attr_getstack],[#include <pthread.h>])
+
+# Newlib's unix/ directory
+AC_CHECK_FUNCS([ttyname getcwd])
+# </FIXME>
+
+# Check if the installed toolchain provides these headers
+# and error out if not.
+AC_CHECK_HEADERS([tar.h errno.h sched.h sys/cdefs.h sys/queue.h],,
+ [rtems_missing_header="$ac_header";break])
+AS_IF([test -n "$rtems_missing_header"],
+ AC_MSG_ERROR([Missing required header $rtems_missing_header])])
+
+## error out if libc doesn't provide stdint.h
+AS_IF([test x"${ac_cv_header_stdint_h}" != xyes],
+[AC_MSG_ERROR([Required header stdint.h not found])])
+
+## error out if libc doesn't provide inttypes.h
+AS_IF([test x"${ac_cv_header_inttypes_h}" != xyes],
+[AC_MSG_ERROR([Required header inttypes.h not found])])
+
+AC_HEADER_STDBOOL
+AS_IF([test x"${ac_cv_header_stdbool_h}" != xyes],
+[AC_MSG_ERROR([No sufficient stdbool.h found])])
+
+AC_CHECK_TYPES([ uint8_t, int8_t])
+AC_CHECK_TYPES([uint16_t, int16_t])
+AC_CHECK_TYPES([uint32_t, int32_t])
+AC_CHECK_TYPES([uint64_t, int64_t])
+AC_CHECK_TYPES([uintmax_t, intmax_t])
+AC_CHECK_TYPES([uintptr_t, intptr_t])
+
+# Some toolchain sanity checks and diagnostics
+RTEMS_CHECK_GCC_SANITY
+
+# These are conditionally defined by the toolchain
+# FIXME: we should either conditionally compile those parts in
+# RTEMS depending on them, or abort - For now, simply check.
+AC_CHECK_HEADER([pthread.h],[
+ AC_CHECK_TYPES([pthread_rwlock_t])
+ AC_CHECK_TYPES([pthread_barrier_t])
+ AC_CHECK_TYPES([pthread_spinlock_t])
+])
+
+AC_CHECK_HEADER([signal.h],[
+ AC_CHECK_TYPES([sighandler_t])
+])
+
+RTEMS_CHECK_MULTIPROCESSING
+RTEMS_CHECK_POSIX_API
+RTEMS_CHECK_NETWORKING
+RTEMS_CHECK_SMP
+
+rtems_major=`echo _RTEMS_VERSION | sed "s/\..*//"`
+rtems_minor=`echo _RTEMS_VERSION | sed "s/[[0-9]][[0-9]]*\.//;s/\..*//"`
+rtems_revision=`echo _RTEMS_VERSION | sed "s/[[0-9]][[0-9]]*\.//;s/[[0-9]][[0-9]]*\.//;s/\..*//"`
+
+## This is needed to generate the field offsets of the per CPU
+## data structure so they can be accessed from assembly code.
+AC_CHECK_SIZEOF([void *])
+
+_RTEMS_CPUOPT_INIT
+
+RTEMS_CPUOPT([RTEMS_DEBUG],
+ [test x"${enable_rtems_debug}" = x"yes"],
+ [1],
+ [if RTEMS_DEBUG is enabled])
+
+RTEMS_CPUOPT([RTEMS_MULTIPROCESSING],
+ [test x"$enable_multiprocessing" = xyes],
+ [1],
+ [if multiprocessing is enabled])
+
+RTEMS_CPUOPT([RTEMS_NEWLIB],
+ [test x"$RTEMS_USE_NEWLIB" = xyes],
+ [1],
+ [if using newlib])
+
+RTEMS_CPUOPT([RTEMS_POSIX_API],
+ [test x"$rtems_cv_HAS_POSIX_API" = xyes],
+ [1],
+ [if posix api is supported])
+
+RTEMS_CPUOPT([RTEMS_SMP],
+ [test x"$RTEMS_HAS_SMP" = xyes],
+ [1],
+ [if SMP is enabled])
+
+RTEMS_CPUOPT([RTEMS_NETWORKING],
+ [test x"$rtems_cv_HAS_NETWORKING" = xyes],
+ [1],
+ [if networking is enabled])
+
+RTEMS_CPUOPT([RTEMS_VERSION],
+ [true],
+ ["]_RTEMS_VERSION["],
+ [RTEMS version string])
+
+RTEMS_CPUOPT([__RTEMS_USE_TICKS_FOR_STATISTICS__],
+ [test x"${USE_TICKS_FOR_STATISTICS}" = x"1"],
+ [1],
+ [disable nanosecond granularity for statistics])
+
+RTEMS_CPUOPT([__RTEMS_USE_TICKS_CPU_USAGE_STATISTICS__],
+ [test x"${USE_TICKS_FOR_CPU_USAGE_STATISTICS}" = x"1"],
+ [1],
+ [disable nanosecond granularity for cpu usage statistics])
+
+RTEMS_CPUOPT([__RTEMS_USE_TICKS_RATE_MONOTONIC_STATISTICS__],
+ [test x"${USE_TICKS_FOR_RATE_MONOTONIC_STATISTICS}" = x"1"],
+ [1],
+ [disable nanosecond granularity for period statistics])
+
+## This improves both the size and coverage analysis.
+RTEMS_CPUOPT([__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__],
+ [test x"${RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH}" = x"1"],
+ [1],
+ [disable inlining _Thread_Enable_dispatch])
+
+## This improves both the size and coverage analysis.
+RTEMS_CPUOPT([__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__],
+ [test x"${RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE}" = x"1"],
+ [1],
+ [disable inlining _Thread_Enable_dispatch])
+
+## This improves both the size and coverage analysis.
+RTEMS_CPUOPT([__RTEMS_DO_NOT_UNROLL_THREADQ_ENQUEUE_PRIORITY__],
+ [test x"${RTEMS_DO_NOT_UNROLL_THREADQ_ENQUEUE_PRIORITY}" = x"1"],
+ [1],
+ [disable inlining _Thread_queue_Enqueue_priority])
+
+## This gives the same behavior as 4.8 and older
+RTEMS_CPUOPT([__RTEMS_STRICT_ORDER_MUTEX__],
+ [test x"${ENABLE_STRICT_ORDER_MUTEX}" = x"1"],
+ [1],
+ [disable strict order mutex])
+
+## Deactivate ada bindings
+RTEMS_CPUOPT([__RTEMS_ADA__],
+ [test x"${enable_ada}" = x"yes"],
+ [1],
+ [Define to 1 if ada/gnat bindings are built-in])
+
+## Then we propagate a private copy of the value into cpuopts.h
+## so it is always available to the RTEMS header files.
+
+RTEMS_CPUOPT([__RTEMS_SIZEOF_VOID_P__],
+ [true],
+ [$ac_cv_sizeof_void_p],
+ [Size of a void * pointer])
+
+RTEMS_CPUOPT([__RTEMS_MAJOR__],
+ [true],
+ [$rtems_major],
+ [major version portion of an RTEMS release])
+
+RTEMS_CPUOPT([__RTEMS_MINOR__],
+ [true],
+ [$rtems_minor],
+ [minor version portion of an RTEMS release])
+
+RTEMS_CPUOPT([__RTEMS_REVISION__],
+ [true],
+ [$rtems_revision],
+ [revision version portion of an RTEMS release])
+
+_RTEMS_CPUOPT_FINI
+
+AC_ENABLE_MULTILIB([Makefile],[..])
+
+# libmisc/shell/* wants to assign file descriptors to stdio file descriptors.
+AC_MSG_CHECKING([for assignable stdio])
+AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <stdio.h>],
+ [stdin = fopen("/tmp", "r")])],
+ [HAVE_ASSIGNABLE_STDIO=yes],
+ [HAVE_ASSIGNABLE_STDIO=no])
+AC_MSG_RESULT([$HAVE_ASSIGNABLE_STDIO])
+
+# libmisc/serdbg exploits weak symbols
+RTEMS_CHECK_GCC_WEAK
+
+# FIXME: These checks are only in here to provide
+# configuration-time diagnostics and are not really used.
+AC_CHECK_DECLS([_POSIX_LOGIN_NAME_MAX],,,[#include <limits.h>])
+AC_CHECK_DECLS([CHAR_BIT],,,[#include <limits.h>])
+
+# FIXME: We should get rid of this.
+# So far, only used in libfs/src/nfsclient/src/dirutils.c
+AC_CHECK_SIZEOF([mode_t])
+AC_CHECK_SIZEOF([off_t])
+
+# FIXME: Mandatory in SUSv4, optional in SUSv3.
+# Not implemented in GCC/newlib, so far.
+AC_CHECK_DECLS([WORD_BIT],,,[#include <limits.h>])
+AC_CHECK_DECLS([LONG_BIT],,,[#include <limits.h>])
+
+## BSD-ism, excluded from POSIX, but available on most platforms
+AC_CHECK_DECLS([sbrk],,,[#include <unistd.h>])
+
+## Check if libc provides BSD's strlcpy/strlcat
+AC_CHECK_FUNCS(strlcpy strlcat)
+
+# ... far too many conditionals ...
+AM_CONDITIONAL(LIBRPC,[test x"$rtems_cv_HAS_NETWORKING" = x"yes"])
+AM_CONDITIONAL(NEWLIB,test x"$RTEMS_USE_NEWLIB" = x"yes")
+
+AM_CONDITIONAL(HAS_MP,test x"$enable_multiprocessing" = x"yes" )
+AM_CONDITIONAL(HAS_SMP,[test "$RTEMS_HAS_SMP" = "yes"])
+
+AM_CONDITIONAL(HAS_PTHREADS,test x"$rtems_cv_HAS_POSIX_API" = x"yes")
+AM_CONDITIONAL(LIBNETWORKING,test x"$rtems_cv_HAS_NETWORKING" = x"yes")
+
+AM_CONDITIONAL([LIBSHELL],[test x"$HAVE_ASSIGNABLE_STDIO" = x"yes"])
+AM_CONDITIONAL([LIBSERDBG],[test x"$rtems_cv_cc_attribute_weak" = x"yes"])
+AM_CONDITIONAL([LIBGNAT],[test x"$rtems_cv_HAS_POSIX_API" = x"yes" \
+&& test x"$enable_ada" = x"yes"])
+
+AM_CONDITIONAL([LIBDOSFS],[dnl
+test x"$ac_cv_type_uint8_t" = xyes \
+&& test x"$ac_cv_type_uint16_t" = xyes])
+
+AC_CONFIG_HEADER(config.h)
+
+## These are needed by the NFS Client
+AC_CHECK_PROG(RPCGEN,rpcgen,rpcgen)
+AM_CONDITIONAL([RPCTOOLS],[test "$RPCGEN" = rpcgen \
+&& test -n "$AWK" \
+&& test "$enable_rpcgen" = yes])
+
+RTEMS_AMPOLISH3
+
+# Explicitly list all Makefiles here
+AC_CONFIG_FILES([
+Doxyfile
+Makefile
+rtems/Makefile
+sapi/Makefile
+score/Makefile
+score/cpu/Makefile
+score/cpu/arm/Makefile
+score/cpu/bfin/Makefile
+score/cpu/avr/Makefile
+score/cpu/h8300/Makefile
+score/cpu/i386/Makefile
+score/cpu/lm32/Makefile
+score/cpu/m68k/Makefile
+score/cpu/m32c/Makefile
+score/cpu/m32r/Makefile
+score/cpu/mips/Makefile
+score/cpu/nios2/Makefile
+score/cpu/powerpc/Makefile
+score/cpu/sh/Makefile
+score/cpu/sparc/Makefile
+score/cpu/sparc64/Makefile
+score/cpu/no_cpu/Makefile
+posix/Makefile
+libblock/Makefile
+libfs/Makefile
+libfs/src/nfsclient/Makefile
+libgnat/Makefile
+libcsupport/Makefile
+libnetworking/Makefile
+librpc/Makefile
+libmisc/Makefile
+libi2c/Makefile
+libmd/Makefile
+zlib/Makefile
+ftpd/Makefile
+telnetd/Makefile
+pppd/Makefile
+mghttpd/Makefile
+wrapup/Makefile])
+
+AC_CONFIG_COMMANDS([preinstall-stamp],
+[test -z "$with_multisubdir" && ${MAKE} preinstall-stamp],
+[MAKE=${MAKE}
+with_multisubdir="$with_multisubdir"])
+
+AC_OUTPUT
diff --git a/cpukit/doxy-filter b/cpukit/doxy-filter
new file mode 100755
index 0000000000..1d47b0806d
--- /dev/null
+++ b/cpukit/doxy-filter
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# doxygen input filter
+# $Id$
+
+# usage: doxy-filter <input-file-name>
+# Reads <input-file> and writes to stdout.
+
+file=$1
+
+# Does file contain a doxygen @file directive?
+if ! grep -q '@file' $file >/dev/null ; then
+# No, add one
+echo "/** @file $file */"
+cat $file
+else
+# Yes, adjust path to work around doxygen not being able to
+# distinguish file names properly
+exec sed -e "s,@file.*$,@file $file," $file
+fi
+
diff --git a/cpukit/ftpd/.cvsignore b/cpukit/ftpd/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/ftpd/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/ftpd/Makefile.am b/cpukit/ftpd/Makefile.am
new file mode 100644
index 0000000000..2155b23c28
--- /dev/null
+++ b/cpukit/ftpd/Makefile.am
@@ -0,0 +1,13 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+if LIBNETWORKING
+project_lib_LIBRARIES = libftpd.a
+libftpd_a_SOURCES = ftpd.c ftpd.h
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/ftpd/ftpd.c b/cpukit/ftpd/ftpd.c
new file mode 100644
index 0000000000..f6895754ca
--- /dev/null
+++ b/cpukit/ftpd/ftpd.c
@@ -0,0 +1,2080 @@
+/* FIXME: 1. Parse command is a hack. We can do better.
+ * 2. Some sort of access control?
+ * 3. OSV: hooks support seems to be bad, as it requires storing of
+ * entire input file in memory. Seem to be better to change it to
+ * something more reasonable, like having
+ * 'hook_write(void const *buf, int count)' routine that will be
+ * called multiple times while file is being received.
+ * 4. OSV: Remove hack with "/dev/null"?
+ *
+ * FTP Server Daemon
+ *
+ * Submitted by: Jake Janovetz <janovetz@tempest.ece.uiuc.edu>
+ *
+ * Changed by: Sergei Organov <osv@javad.ru> (OSV)
+ *
+ * Changes:
+ *
+ * 2001-01-31 Sergei Organov <osv@javad.ru>
+ *
+ * * Hacks with current dir and root dir removed in favor of new libio
+ * support for task-local current and root directories.
+ *
+ * 2001-01-30 Sergei Organov <osv@javad.ru>
+ *
+ * * Bug in `close_data_socket()' introduced by previous change fixed.
+ * * `command_pasv()' changed to set timeout on socket we are listening on
+ * and code fixed to don't close socket twice on error.
+ * * `serr()' changed to clear `errno'.
+ * * `data_socket()' changed to clear `errno' before `bind()'.
+ * * `session()' changed to clear `errno' before processing session.
+ *
+ * 2001-01-29 Sergei Organov <osv@javad.ru>
+ *
+ * * `close_data_socket()' fixed to close both active and passive sockets
+ * * Initialize info->data_socket to -1 in `daemon()'
+ * * Initialize `fname' to empty string in `exec_command()'
+ *
+ * 2001-01-22 Sergei Organov <osv@javad.ru>
+ *
+ * * Timeouts on sockets implemented. 'idle' field added to
+ * configuration. No timeout by default to keep backward compatibility.
+ * Note: SITE IDLE command not implemented yet.
+ * * Basic global access control implemented. 'access' field added to
+ * configuration. No access limitations by default to keep backward
+ * compatibility.
+ *
+ * 2001-01-17 Sergei Organov <osv@javad.ru>
+ *
+ * * Anchor data socket for active mode (using self IP and port 20.)
+ * * Fixed default data port support (still not tested).
+ * * Don't allow IP address different from originating host in
+ * PORT command to improve security.
+ * * Fixed bug in MDTM command.
+ * * Check for correctness of parsing of argument in command_port().
+ * * Fixed squeeze_path() to don't allow names like 'NAME/smth' where
+ * 'NAME' is not a directory.
+ * * Command parsing a little bit improved: command names are now
+ * converted to upper-case to be more compatible with RFC (command
+ * names are not case-sensitive.)
+ * * Reformat comments so that they have RTEMS look-and-feel.
+ *
+ * 2001-01-16 Sergei Organov <osv@javad.ru>
+ *
+ * * Fixed DELE, SITE CHMOD, RMD, MKD broken by previous changes
+ * * True ASCII mode implemented (doesn't work for hooks and /dev/null)
+ * * Passive mode implemented, PASV command added.
+ * * Default port for data connection could be used (untested, can't find
+ * ftp client that doesn't send PORT command)
+ * * SYST reply changed to UNIX, as former RTEMS isn't registered name.
+ * * Reply codes reviewed and fixed.
+ *
+ * 2001-01-08 Sergei Organov <osv@javad.ru>
+ *
+ * * use pool of pre-created threads to handle sessions
+ * * LIST output now similar to what "/bin/ls -al" would output, thus
+ * FTP clients could parse it.
+ * * LIST NAME now works (both for files and directories)
+ * * keep track of CWD for every session separately
+ * * ability to specify root directory name in configuration table
+ * * options sent in commands are ignored, thus LIST -al FILE works
+ * * added support for NLST, CDUP and MDTM commands
+ * * buffers are allocated on stack instead of heap where possible
+ * * drop using of task notepad to pass parameters - use function
+ * arguments instead
+ * * various bug-fixes, e.g., use of PF_INET in socket() instead of
+ * AF_INET, use snprintf() instead of sprintf() everywhere for safety,
+ * etc.
+ *
+ * $Id$
+ */
+
+/*************************************************************************
+ * ftpd.c
+ *************************************************************************
+ * Description:
+ *
+ * This file contains the daemon which services requests that appear
+ * on the FTP port. This server is compatible with FTP, but it
+ * also provides 'hooks' to make it usable in situations where files
+ * are not used/necessary. Once the server is started, it runs
+ * forever.
+ *
+ *
+ * Organization:
+ *
+ * The FTP daemon is started upon boot along with a (configurable)
+ * number of tasks to handle sessions. It runs all the time and
+ * waits for connections on the known FTP port (21). When
+ * a connection is made, it wakes-up a 'session' task. That
+ * session then interacts with the remote host. When the session
+ * is complete, the session task goes to sleep. The daemon still
+ * runs, however.
+ *
+ *
+ * Supported commands are:
+ *
+ * RETR xxx - Sends a file from the client.
+ * STOR xxx - Receives a file from the client. xxx = filename.
+ * LIST xxx - Sends a file list to the client.
+ * NLST xxx - Sends a file list to the client.
+ * USER - Does nothing.
+ * PASS - Does nothing.
+ * SYST - Replies with the system type (`RTEMS').
+ * DELE xxx - Delete file xxx.
+ * MKD xxx - Create directory xxx.
+ * RMD xxx - Remove directory xxx.
+ * PWD - Print working directory.
+ * CWD xxx - Change working directory.
+ * CDUP - Change to upper directory.
+ * SITE CHMOD xxx yyy - Change permissions on file yyy to xxx.
+ * PORT a,b,c,d,x,y - Setup for a data port to IP address a.b.c.d
+ * and port (x*256 + y).
+ * MDTM xxx - Send file modification date/time to the client.
+ * xxx = filename.
+ * PASV - Use passive mode data connection.
+ *
+ *
+ * The public routines contained in this file are:
+ *
+ * rtems_initialize_ftpd - Initializes and starts the server daemon,
+ * then returns to its caller.
+ *
+ *------------------------------------------------------------------------
+ * Jake Janovetz
+ * University of Illinois
+ * 1406 West Green Street
+ * Urbana IL 61801
+ *************************************************************************
+ * Change History:
+ * 12/01/97 - Creation (JWJ)
+ * 2001-01-08 - Changes by OSV
+ *************************************************************************/
+
+/*************************************************************************
+ * Meanings of first and second digits of reply codes:
+ *
+ * Reply: Description:
+ *-------- --------------
+ * 1yz Positive preliminary reply. The action is being started but
+ * expect another reply before sending another command.
+ * 2yz Positive completion reply. A new command can be sent.
+ * 3yz Positive intermediate reply. The command has been accepted
+ * but another command must be sent.
+ * 4yz Transient negative completion reply. The requested action did
+ * not take place, but the error condition is temporary so the
+ * command can be reissued later.
+ * 5yz Permanent negative completion reply. The command was not
+ * accepted and should not be retried.
+ *-------------------------------------------------------------------------
+ * x0z Syntax errors.
+ * x1z Information.
+ * x2z Connections. Replies referring to the control or data
+ * connections.
+ * x3z Authentication and accounting. Replies for the login or
+ * accounting commands.
+ * x4z Unspecified.
+ * x5z Filesystem status.
+ *************************************************************************/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/error.h>
+#include <rtems/libio.h>
+#include <rtems/userenv.h>
+#include <syslog.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/ftp.h>
+#include <netinet/in.h>
+
+#include "ftpd.h"
+
+
+#ifdef __GNUC__
+/* change to #if 1 to disable syslog entirely */
+#if 0
+#undef syslog
+#define syslog(a, b, ...) while(0){}
+#endif
+#endif
+
+#define FTPD_SERVER_MESSAGE "RTEMS FTP server (Version 1.1-JWJ) ready."
+
+#define FTPD_SYSTYPE "UNIX Type: L8"
+
+/* Seem to be unused */
+#if 0
+#define FTPD_WELCOME_MESSAGE \
+ "Welcome to the RTEMS FTP server.\n" \
+ "\n" \
+ "Login accepted.\n"
+#endif
+
+/* Various buffer sizes */
+enum
+{
+ FTPD_BUFSIZE = 256, /* Size for temporary buffers */
+ FTPD_DATASIZE = 1024, /* Size for file transfer buffers */
+ FTPD_STACKSIZE = 8 * 1024, /* Tasks stack size */
+};
+
+/* Event to be used by session tasks for waiting */
+enum
+{
+ FTPD_RTEMS_EVENT = RTEMS_EVENT_1
+};
+
+/* Configuration table */
+extern struct rtems_ftpd_configuration rtems_ftpd_configuration;
+
+/* this is not prototyped in strict ansi mode */
+FILE *fdopen (int fildes, const char *mode);
+
+/*PAGE
+ * SessionInfo structure.
+ *
+ * The following structure is allocated for each session.
+ */
+typedef struct
+{
+ struct sockaddr_in ctrl_addr; /* Control connection self address */
+ struct sockaddr_in data_addr; /* Data address set by PORT command */
+ struct sockaddr_in def_addr; /* Default address for data */
+ int use_default; /* 1 - use default address for data */
+ FILE *ctrl_fp; /* File pointer for control connection */
+ int ctrl_socket; /* Socket for ctrl connection */
+ int pasv_socket; /* Socket for PASV connection */
+ int data_socket; /* Socket for data connection */
+ int idle; /* Timeout in seconds */
+ int xfer_mode; /* Transfer mode (ASCII/binary) */
+ rtems_id tid; /* Task id */
+} FTPD_SessionInfo_t;
+
+
+/*
+ * TaskPool structure.
+ */
+typedef struct
+{
+ FTPD_SessionInfo_t *info;
+ FTPD_SessionInfo_t **queue;
+ int count;
+ int head;
+ int tail;
+ rtems_id mutex;
+ rtems_id sem;
+} FTPD_TaskPool_t;
+
+/*
+ * Task pool instance.
+ */
+static FTPD_TaskPool_t task_pool;
+
+/*
+ * Root directory
+ */
+
+static char const* ftpd_root = "/";
+
+/*
+ * Default idle timeout for sockets in seconds.
+ */
+static int ftpd_timeout = 0;
+
+/*
+ * Global access flags.
+ */
+static int ftpd_access = 0;
+
+/*PAGE
+ *
+ * serr
+ *
+ * Return error string corresponding to current 'errno'.
+ *
+ */
+static char const*
+serr(void)
+{
+ int err = errno;
+ errno = 0;
+ return strerror(err);
+}
+
+/*PAGE
+ *
+ * Utility routines for access control.
+ *
+ */
+
+static int
+can_read(void)
+{
+ return (ftpd_access & FTPD_NO_READ) == 0;
+}
+
+static int
+can_write(void)
+{
+ return (ftpd_access & FTPD_NO_WRITE) == 0;
+}
+
+/*PAGE
+ *
+ * Task pool management routines
+ *
+ */
+
+
+/*PAGE
+ *
+ * task_pool_done
+ *
+ * Cleanup task pool.
+ *
+ * Input parameters:
+ * count - number of entries in task pool to cleanup
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+task_pool_done(int count)
+{
+ int i;
+ for(i = 0; i < count; ++i)
+ rtems_task_delete(task_pool.info[i].tid);
+ if(task_pool.info)
+ free(task_pool.info);
+ if(task_pool.queue)
+ free(task_pool.queue);
+ if(task_pool.mutex != (rtems_id)-1)
+ rtems_semaphore_delete(task_pool.mutex);
+ if(task_pool.sem != (rtems_id)-1)
+ rtems_semaphore_delete(task_pool.sem);
+ task_pool.info = 0;
+ task_pool.queue = 0;
+ task_pool.count = 0;
+ task_pool.sem = -1;
+ task_pool.mutex = -1;
+}
+
+/*PAGE
+ *
+ * task_pool_init
+ *
+ * Initialize task pool.
+ *
+ * Input parameters:
+ * count - number of entries in task pool to create
+ * priority - priority tasks are started with
+ *
+ * Output parameters:
+ * returns 1 on success, 0 on failure.
+ *
+ */
+static void session(rtems_task_argument arg); /* Forward declare */
+
+static int
+task_pool_init(int count, rtems_task_priority priority)
+{
+ int i;
+ rtems_status_code sc;
+ char id = 'a';
+
+ task_pool.count = 0;
+ task_pool.head = task_pool.tail = 0;
+ task_pool.mutex = (rtems_id)-1;
+ task_pool.sem = (rtems_id)-1;
+
+ sc = rtems_semaphore_create(
+ rtems_build_name('F', 'T', 'P', 'M'),
+ 1,
+ RTEMS_DEFAULT_ATTRIBUTES
+ | RTEMS_BINARY_SEMAPHORE
+ | RTEMS_INHERIT_PRIORITY
+ | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &task_pool.mutex);
+
+ if(sc == RTEMS_SUCCESSFUL)
+ sc = rtems_semaphore_create(
+ rtems_build_name('F', 'T', 'P', 'S'),
+ count,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ RTEMS_NO_PRIORITY,
+ &task_pool.sem);
+
+ if(sc != RTEMS_SUCCESSFUL) {
+ task_pool_done(0);
+ syslog(LOG_ERR, "ftpd: Can not create semaphores");
+ return 0;
+ }
+
+ task_pool.info = (FTPD_SessionInfo_t*)
+ malloc(sizeof(FTPD_SessionInfo_t) * count);
+ task_pool.queue = (FTPD_SessionInfo_t**)
+ malloc(sizeof(FTPD_SessionInfo_t*) * count);
+ if (NULL == task_pool.info || NULL == task_pool.queue)
+ {
+ task_pool_done(0);
+ syslog(LOG_ERR, "ftpd: Not enough memory");
+ return 0;
+ }
+
+ for(i = 0; i < count; ++i)
+ {
+ FTPD_SessionInfo_t *info = &task_pool.info[i];
+ sc = rtems_task_create(rtems_build_name('F', 'T', 'P', id),
+ priority, FTPD_STACKSIZE,
+ RTEMS_PREEMPT | RTEMS_NO_TIMESLICE |
+ RTEMS_NO_ASR | RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
+ &info->tid);
+ if (sc == RTEMS_SUCCESSFUL)
+ {
+ sc = rtems_task_start(
+ info->tid, session, (rtems_task_argument)info);
+ if (sc != RTEMS_SUCCESSFUL)
+ task_pool_done(i);
+ }
+ else
+ task_pool_done(i + 1);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ syslog(LOG_ERR, "ftpd: Could not create/start FTPD session: %s",
+ rtems_status_text(sc));
+ return 0;
+ }
+ task_pool.queue[i] = task_pool.info + i;
+ if (++id > 'z')
+ id = 'a';
+ }
+ task_pool.count = count;
+ return 1;
+}
+
+/*PAGE
+ *
+ * task_pool_obtain
+ *
+ * Obtain free task from task pool.
+ *
+ * Input parameters:
+ * NONE
+ *
+ * Output parameters:
+ * returns pointer to the corresponding SessionInfo structure on success,
+ * NULL if there are no free tasks in the pool.
+ *
+ */
+static FTPD_SessionInfo_t*
+task_pool_obtain(void)
+{
+ FTPD_SessionInfo_t* info = 0;
+ rtems_status_code sc;
+ sc = rtems_semaphore_obtain(task_pool.sem, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc == RTEMS_SUCCESSFUL)
+ {
+ rtems_semaphore_obtain(task_pool.mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ info = task_pool.queue[task_pool.head];
+ if(++task_pool.head >= task_pool.count)
+ task_pool.head = 0;
+ rtems_semaphore_release(task_pool.mutex);
+ }
+ return info;
+}
+
+/*PAGE
+ *
+ * task_pool_release
+ *
+ * Return task obtained by 'obtain()' back to the task pool.
+ *
+ * Input parameters:
+ * info - pointer to corresponding SessionInfo structure.
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+task_pool_release(FTPD_SessionInfo_t* info)
+{
+ rtems_semaphore_obtain(task_pool.mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ task_pool.queue[task_pool.tail] = info;
+ if(++task_pool.tail >= task_pool.count)
+ task_pool.tail = 0;
+ rtems_semaphore_release(task_pool.mutex);
+ rtems_semaphore_release(task_pool.sem);
+}
+
+/*
+ * End of task pool routines
+ */
+
+/*PAGE
+ *
+ * Function: send_reply
+ *
+ *
+ * This procedure sends a reply to the client via the control
+ * connection.
+ *
+ *
+ * Input parameters:
+ * code - 3-digit reply code.
+ * text - Reply text.
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+send_reply(FTPD_SessionInfo_t *info, int code, char *text)
+{
+ char const* s = (info->xfer_mode == TYPE_A) ? "\r" : "";
+ /* If a text reply exists, add it to the reply data. */
+ if (text != NULL)
+ fprintf(info->ctrl_fp, "%d %.70s%s\n", code, text, s);
+ else
+ fprintf(info->ctrl_fp, "%d%s\n", code, s);
+ fflush(info->ctrl_fp);
+}
+
+
+/*PAGE
+ *
+ * close_socket
+ *
+ * Close socket.
+ *
+ * Input parameters:
+ * s - socket descriptor.
+ * seconds - number of seconds the timeout should be,
+ * if >= 0 - infinite timeout (no timeout).
+ *
+ * Output parameters:
+ * returns 1 on success, 0 on failure.
+ */
+static int
+set_socket_timeout(int s, int seconds)
+{
+ int res = 0;
+ struct timeval tv;
+ int len = sizeof(tv);
+
+ if(seconds < 0)
+ seconds = 0;
+ tv.tv_usec = 0;
+ tv.tv_sec = seconds;
+ if(0 != setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, len))
+ syslog(LOG_ERR, "ftpd: Can't set send timeout on socket: %s.", serr());
+ else if(0 != setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, len))
+ syslog(LOG_ERR, "ftpd: Can't set receive timeout on socket: %s.", serr());
+ else
+ res = 1;
+ return res;
+}
+
+/*PAGE
+ *
+ * close_socket
+ *
+ * Close socket.
+ *
+ * Input parameters:
+ * s - socket descriptor to be closed.
+ *
+ * Output parameters:
+ * returns 1 on success, 0 on failure
+ */
+static int
+close_socket(int s)
+{
+ if (0 <= s)
+ {
+ if (0 != close(s))
+ {
+ shutdown(s, 2);
+ if (0 != close(s))
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/*PAGE
+ *
+ * data_socket
+ *
+ * Create data socket for session.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ *
+ * Output parameters:
+ * returns socket descriptor, or -1 if failure
+ *
+ */
+static int
+data_socket(FTPD_SessionInfo_t *info)
+{
+ int s = info->pasv_socket;
+ if(0 > s)
+ {
+ int on = 1;
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if(0 > s)
+ send_reply(info, 425, "Can't create data socket.");
+ else if(0 > setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
+ {
+ close_socket(s);
+ s = -1;
+ }
+ else
+ {
+ struct sockaddr_in data_source;
+ int tries;
+
+ /* anchor socket to avoid multi-homing problems */
+ data_source = info->ctrl_addr;
+ data_source.sin_port = htons(20); /* ftp-data port */
+ for(tries = 1; tries < 10; ++tries)
+ {
+ errno = 0;
+ if(bind(s, (struct sockaddr *)&data_source, sizeof(data_source)) >= 0)
+ break;
+ if (errno != EADDRINUSE)
+ tries = 10;
+ else
+ rtems_task_wake_after(tries * 10);
+ }
+ if(tries >= 10)
+ {
+ send_reply(info, 425, "Can't bind data socket.");
+ close_socket(s);
+ s = -1;
+ }
+ else
+ {
+ struct sockaddr_in *data_dest =
+ (info->use_default) ? &info->def_addr : &info->data_addr;
+ if(0 > connect(s, (struct sockaddr *)data_dest, sizeof(*data_dest)))
+ {
+ send_reply(info, 425, "Can't connect data socket.");
+ close_socket(s);
+ s = -1;
+ }
+ }
+ }
+ }
+ info->data_socket = s;
+ info->use_default = 1;
+ if(s >= 0)
+ set_socket_timeout(s, info->idle);
+ return s;
+}
+
+/*PAGE
+ *
+ * close_data_socket
+ *
+ * Close data socket for session.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+close_data_socket(FTPD_SessionInfo_t *info)
+{
+ /* As at most one data socket could be open simultaneously and in some cases
+ data_socket == pasv_socket, we select socket to close, then close it. */
+ int s = info->data_socket;
+ if(0 > s)
+ s = info->pasv_socket;
+ if(!close_socket(s))
+ syslog(LOG_ERR, "ftpd: Error closing data socket.");
+ info->data_socket = -1;
+ info->pasv_socket = -1;
+ info->use_default = 1;
+}
+
+/*PAGE
+ *
+ * close_stream
+ *
+ * Close control stream of session.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+close_stream(FTPD_SessionInfo_t* info)
+{
+ if (NULL != info->ctrl_fp)
+ {
+ if (0 != fclose(info->ctrl_fp))
+ {
+ syslog(LOG_ERR, "ftpd: Could not close control stream: %s", serr());
+ }
+ else
+ info->ctrl_socket = -1;
+ }
+
+ if (!close_socket(info->ctrl_socket))
+ syslog(LOG_ERR, "ftpd: Could not close control socket: %s", serr());
+
+ info->ctrl_fp = NULL;
+ info->ctrl_socket = -1;
+}
+
+
+/*PAGE
+ *
+ * send_mode_reply
+ *
+ * Sends BINARY/ASCII reply string depending on current transfer mode.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+send_mode_reply(FTPD_SessionInfo_t *info)
+{
+ if(info->xfer_mode == TYPE_I)
+ send_reply(info, 150, "Opening BINARY mode data connection.");
+ else
+ send_reply(info, 150, "Opening ASCII mode data connection.");
+}
+
+/*PAGE
+ *
+ * command_retrieve
+ *
+ * Perform the "RETR" command (send file to client).
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * char *filename - source filename.
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+command_retrieve(FTPD_SessionInfo_t *info, char const *filename)
+{
+ int s = -1;
+ int fd = -1;
+ char buf[FTPD_DATASIZE];
+ struct stat stat_buf;
+ int res = 0;
+
+ if(!can_read())
+ {
+ send_reply(info, 550, "Access denied.");
+ return;
+ }
+
+ if (0 > (fd = open(filename, O_RDONLY)))
+ {
+ send_reply(info, 550, "Error opening file.");
+ return;
+ }
+
+ if (fstat(fd, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode))
+ {
+ if (-1 != fd)
+ close(fd);
+ send_reply(info, 550, "Is a directory.");
+ return;
+ }
+
+ send_mode_reply(info);
+
+ s = data_socket(info);
+
+ if (0 <= s)
+ {
+ int n = -1;
+
+ if(info->xfer_mode == TYPE_I)
+ {
+ while ((n = read(fd, buf, FTPD_DATASIZE)) > 0)
+ {
+ if(send(s, buf, n, 0) != n)
+ break;
+ }
+ }
+ else if (info->xfer_mode == TYPE_A)
+ {
+ int rest = 0;
+ while (rest == 0 && (n = read(fd, buf, FTPD_DATASIZE)) > 0)
+ {
+ char const* e = buf;
+ char const* b;
+ int i;
+ rest = n;
+ do
+ {
+ char lf = '\0';
+
+ b = e;
+ for(i = 0; i < rest; ++i, ++e)
+ {
+ if(*e == '\n')
+ {
+ lf = '\n';
+ break;
+ }
+ }
+ if(send(s, b, i, 0) != i)
+ break;
+ if(lf == '\n')
+ {
+ if(send(s, "\r\n", 2, 0) != 2)
+ break;
+ ++e;
+ ++i;
+ }
+ }
+ while((rest -= i) > 0);
+ }
+ }
+
+ if (0 == n)
+ {
+ if (0 == close(fd))
+ {
+ fd = -1;
+ res = 1;
+ }
+ }
+ }
+
+ if (-1 != fd)
+ close(fd);
+
+ if (0 == res)
+ send_reply(info, 451, "File read error.");
+ else
+ send_reply(info, 226, "Transfer complete.");
+
+ close_data_socket(info);
+
+ return;
+}
+
+
+/*PAGE
+ *
+ * discard
+ *
+ * Analog of `write' routine that just discards passed data
+ *
+ * Input parameters:
+ * fd - file descriptor (ignored)
+ * buf - data to write (ignored)
+ * count - number of bytes in `buf'
+ *
+ * Output parameters:
+ * returns `count'
+ *
+ */
+static ssize_t
+discard(int fd, void const* buf, size_t count)
+{
+ (void)fd;
+ (void)buf;
+ return count;
+}
+
+/*PAGE
+ *
+ * command_store
+ *
+ * Performs the "STOR" command (receive data from client).
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * char *filename - Destination filename.
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+command_store(FTPD_SessionInfo_t *info, char const *filename)
+{
+ int s;
+ int n;
+ unsigned long size = 0;
+ struct rtems_ftpd_hook *usehook = NULL;
+ char buf[FTPD_DATASIZE];
+ int res = 1;
+ int bare_lfs = 0;
+ int null = 0;
+ typedef ssize_t (*WriteProc)(int, void const*, size_t);
+ WriteProc wrt = &write;
+
+ if(!can_write())
+ {
+ send_reply(info, 550, "Access denied.");
+ return;
+ }
+
+ send_mode_reply(info);
+
+ s = data_socket(info);
+ if(0 > s)
+ return;
+
+ null = !strcmp("/dev/null", filename);
+ if (null)
+ {
+ /* File "/dev/null" just throws data away.
+ * FIXME: this is hack. Using `/dev/null' filesystem entry would be
+ * better.
+ */
+ wrt = &discard;
+ }
+
+ if (!null && rtems_ftpd_configuration.hooks != NULL)
+ {
+
+ /* Search our list of hooks to see if we need to do something special. */
+ struct rtems_ftpd_hook *hook;
+ int i;
+
+ i = 0;
+ hook = &rtems_ftpd_configuration.hooks[i++];
+ while (hook->filename != NULL)
+ {
+ if (!strcmp(hook->filename, filename))
+ {
+ usehook = hook;
+ break;
+ }
+ hook = &rtems_ftpd_configuration.hooks[i++];
+ }
+ }
+
+ if (usehook != NULL)
+ {
+ /*
+ * OSV: FIXME: Small buffer could be used and hook routine
+ * called multiple times instead. Alternatively, the support could be
+ * removed entirely in favor of configuring RTEMS pseudo-device with
+ * given name.
+ */
+
+ char *bigBufr;
+ size_t filesize = rtems_ftpd_configuration.max_hook_filesize + 1;
+
+ /*
+ * Allocate space for our "file".
+ */
+ bigBufr = (char *)malloc(filesize);
+ if (bigBufr == NULL)
+ {
+ send_reply(info, 451, "Local resource failure: malloc.");
+ close_data_socket(info);
+ return;
+ }
+
+ /*
+ * Retrieve the file into our buffer space.
+ */
+ size = 0;
+ while ((n = recv(s, bigBufr + size, filesize - size, 0)) > 0)
+ {
+ size += n;
+ }
+ if (size >= filesize)
+ {
+ send_reply(info, 451, "File too long: buffer size exceeded.");
+ free(bigBufr);
+ close_data_socket(info);
+ return;
+ }
+
+ /*
+ * Call our hook.
+ */
+ res = (usehook->hook_function)(bigBufr, size) == 0;
+ free(bigBufr);
+ if(!res)
+ {
+ send_reply(info, 451, "File processing failed.");
+ close_data_socket(info);
+ return;
+ }
+ }
+ else
+ {
+ /* Data transfer to regular file or /dev/null. */
+ int fd = 0;
+
+ if(!null)
+ fd = creat(filename,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+
+ if (0 > fd)
+ {
+ send_reply(info, 550, "Error creating file.");
+ close_data_socket(info);
+ return;
+ }
+
+ if(info->xfer_mode == TYPE_I)
+ {
+ while ((n = recv(s, buf, FTPD_DATASIZE, 0)) > 0)
+ {
+ if (wrt(fd, buf, n) != n)
+ {
+ res = 0;
+ break;
+ }
+ }
+ }
+ else if(info->xfer_mode == TYPE_A)
+ {
+ int rest = 0;
+ int pended_cr = 0;
+ while (res && rest == 0 && (n = recv(s, buf, FTPD_DATASIZE, 0)) > 0)
+ {
+ char const* e = buf;
+ char const* b;
+ int i;
+
+ rest = n;
+ if(pended_cr && *e != '\n')
+ {
+ char const lf = '\r';
+ pended_cr = 0;
+ if(wrt(fd, &lf, 1) != 1)
+ {
+ res = 0;
+ break;
+ }
+ }
+ do
+ {
+ int count;
+ int sub = 0;
+
+ b = e;
+ for(i = 0; i < rest; ++i, ++e)
+ {
+ int pcr = pended_cr;
+ pended_cr = 0;
+ if(*e == '\r')
+ {
+ pended_cr = 1;
+ }
+ else if(*e == '\n')
+ {
+ if(pcr)
+ {
+ sub = 2;
+ ++i;
+ ++e;
+ break;
+ }
+ ++bare_lfs;
+ }
+ }
+ if(res == 0)
+ break;
+ count = i - sub - pended_cr;
+ if(count > 0 && wrt(fd, b, count) != count)
+ {
+ res = 0;
+ break;
+ }
+ if(sub == 2 && wrt(fd, e - 1, 1) != 1)
+ res = 0;
+ }
+ while((rest -= i) > 0);
+ }
+ }
+
+ if (0 > close(fd) || res == 0)
+ {
+ send_reply(info, 452, "Error writing file.");
+ close_data_socket(info);
+ return;
+ }
+ }
+
+ if (bare_lfs > 0)
+ {
+ snprintf(buf, FTPD_BUFSIZE,
+ "Transfer complete. WARNING! %d bare linefeeds received in ASCII mode.",
+ bare_lfs);
+ send_reply(info, 226, buf);
+ }
+ else
+ send_reply(info, 226, "Transfer complete.");
+ close_data_socket(info);
+
+}
+
+
+/*PAGE
+ *
+ * send_dirline
+ *
+ * Sends one line of LIST command reply corresponding to single file.
+ *
+ * Input parameters:
+ * s - socket descriptor to send data to
+ * wide - if 0, send only file name. If not 0, send 'stat' info as well in
+ * "ls -l" format.
+ * curTime - current time
+ * path - path to be prepended to what is given by 'add'
+ * add - path to be appended to what is given by 'path', the resulting path
+ * is then passed to 'stat()' routine
+ * name - file name to be reported in output
+ * buf - buffer for temporary data
+ *
+ * Output parameters:
+ * returns 0 on failure, 1 on success
+ *
+ */
+static int
+send_dirline(int s, int wide, time_t curTime, char const* path,
+ char const* add, char const* fname, char* buf)
+{
+ if(wide)
+ {
+ struct stat stat_buf;
+
+ int plen = strlen(path);
+ int alen = strlen(add);
+ if(plen == 0)
+ {
+ buf[plen++] = '/';
+ buf[plen] = '\0';
+ }
+ else
+ {
+ strcpy(buf, path);
+ if(alen > 0 && buf[plen - 1] != '/')
+ {
+ buf[plen++] = '/';
+ if(plen >= FTPD_BUFSIZE)
+ return 0;
+ buf[plen] = '\0';
+ }
+ }
+ if(plen + alen >= FTPD_BUFSIZE)
+ return 0;
+ strcpy(buf + plen, add);
+
+ if (stat(buf, &stat_buf) == 0)
+ {
+ int len;
+ struct tm bt;
+ time_t tf = stat_buf.st_mtime;
+ enum { SIZE = 80 };
+ time_t SIX_MONTHS = (365L*24L*60L*60L)/2L;
+ char timeBuf[SIZE];
+ gmtime_r(&tf, &bt);
+ if(curTime > tf + SIX_MONTHS || tf > curTime + SIX_MONTHS)
+ strftime (timeBuf, SIZE, "%b %d %Y", &bt);
+ else
+ strftime (timeBuf, SIZE, "%b %d %H:%M", &bt);
+
+ len = snprintf(buf, FTPD_BUFSIZE,
+ "%c%c%c%c%c%c%c%c%c%c 1 %5d %5d %11u %s %s\r\n",
+ (S_ISLNK(stat_buf.st_mode)?('l'):
+ (S_ISDIR(stat_buf.st_mode)?('d'):('-'))),
+ (stat_buf.st_mode & S_IRUSR)?('r'):('-'),
+ (stat_buf.st_mode & S_IWUSR)?('w'):('-'),
+ (stat_buf.st_mode & S_IXUSR)?('x'):('-'),
+ (stat_buf.st_mode & S_IRGRP)?('r'):('-'),
+ (stat_buf.st_mode & S_IWGRP)?('w'):('-'),
+ (stat_buf.st_mode & S_IXGRP)?('x'):('-'),
+ (stat_buf.st_mode & S_IROTH)?('r'):('-'),
+ (stat_buf.st_mode & S_IWOTH)?('w'):('-'),
+ (stat_buf.st_mode & S_IXOTH)?('x'):('-'),
+ (int)stat_buf.st_uid,
+ (int)stat_buf.st_gid,
+ (int)stat_buf.st_size,
+ timeBuf,
+ fname
+ );
+
+ if(send(s, buf, len, 0) != len)
+ return 0;
+ }
+ }
+ else
+ {
+ int len = snprintf(buf, FTPD_BUFSIZE, "%s\r\n", fname);
+ if(send(s, buf, len, 0) != len)
+ return 0;
+ }
+ return 1;
+}
+
+/*PAGE
+ *
+ * command_list
+ *
+ * Send file list to client.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * char *fname - File (or directory) to list.
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+command_list(FTPD_SessionInfo_t *info, char const *fname, int wide)
+{
+ int s;
+ DIR *dirp = 0;
+ struct dirent *dp = 0;
+ struct stat stat_buf;
+ char buf[FTPD_BUFSIZE];
+ time_t curTime;
+ int sc = 1;
+
+ send_reply(info, 150, "Opening ASCII mode data connection for LIST.");
+
+ s = data_socket(info);
+ if(0 > s)
+ {
+ syslog(LOG_ERR, "ftpd: Error connecting to data socket.");
+ return;
+ }
+
+ if(fname[0] == '\0')
+ fname = ".";
+
+ if (0 > stat(fname, &stat_buf))
+ {
+ snprintf(buf, FTPD_BUFSIZE,
+ "%s: No such file or directory.\r\n", fname);
+ send(s, buf, strlen(buf), 0);
+ }
+ else if (S_ISDIR(stat_buf.st_mode) && (NULL == (dirp = opendir(fname))))
+ {
+ snprintf(buf, FTPD_BUFSIZE,
+ "%s: Can not open directory.\r\n", fname);
+ send(s, buf, strlen(buf), 0);
+ }
+ else
+ {
+ time(&curTime);
+ if(!dirp && *fname)
+ sc = sc && send_dirline(s, wide, curTime, fname, "", fname, buf);
+ else {
+ /* FIXME: need "." and ".." only when '-a' option is given */
+ sc = sc && send_dirline(s, wide, curTime, fname, "", ".", buf);
+ sc = sc && send_dirline(s, wide, curTime, fname,
+ (strcmp(fname, ftpd_root) ? ".." : ""), "..", buf);
+ while (sc && (dp = readdir(dirp)) != NULL)
+ sc = sc &&
+ send_dirline(s, wide, curTime, fname, dp->d_name, dp->d_name, buf);
+ }
+ }
+
+ if(dirp)
+ closedir(dirp);
+ close_data_socket(info);
+
+ if(sc)
+ send_reply(info, 226, "Transfer complete.");
+ else
+ send_reply(info, 426, "Connection aborted.");
+}
+
+
+/*PAGE
+ *
+ * command_cwd
+ *
+ * Change current working directory.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * dir - directory name passed in CWD command
+ *
+ * Output parameters:
+ * NONE
+ *
+ */
+static void
+command_cwd(FTPD_SessionInfo_t *info, char *dir)
+{
+ if(chdir(dir) == 0)
+ send_reply(info, 250, "CWD command successful.");
+ else
+ send_reply(info, 550, "CWD command failed.");
+}
+
+
+/*PAGE
+ *
+ * command_pwd
+ *
+ * Send current working directory to client.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+command_pwd(FTPD_SessionInfo_t *info)
+{
+ char buf[FTPD_BUFSIZE];
+ char const* cwd;
+ errno = 0;
+ buf[0] = '"';
+ cwd = getcwd(buf + 1, FTPD_BUFSIZE - 4);
+ if(cwd)
+ {
+ int len = strlen(cwd);
+ static char const txt[] = "\" is the current directory.";
+ int size = sizeof(txt);
+ if(len + size + 1 >= FTPD_BUFSIZE)
+ size = FTPD_BUFSIZE - len - 2;
+ memcpy(buf + len + 1, txt, size);
+ buf[len + size] = '\0';
+ send_reply(info, 250, buf);
+ }
+ else {
+ snprintf(buf, FTPD_BUFSIZE, "Error: %s.", serr());
+ send_reply(info, 452, buf);
+ }
+}
+
+/*PAGE
+ *
+ * command_mdtm
+ *
+ * Handle FTP MDTM command (send file modification time to client)/
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * fname - file name passed in MDTM command
+ *
+ * Output parameters:
+ * info->cwd is set to new CWD value.
+ */
+static void
+command_mdtm(FTPD_SessionInfo_t *info, char const* fname)
+{
+ struct stat stbuf;
+ char buf[FTPD_BUFSIZE];
+
+ if (0 > stat(fname, &stbuf))
+ {
+ snprintf(buf, FTPD_BUFSIZE, "%s: %s.", fname, serr());
+ send_reply(info, 550, buf);
+ }
+ else
+ {
+ struct tm *t = gmtime(&stbuf.st_mtime);
+ snprintf(buf, FTPD_BUFSIZE, "%04d%02d%02d%02d%02d%02d",
+ 1900 + t->tm_year,
+ t->tm_mon+1, t->tm_mday,
+ t->tm_hour, t->tm_min, t->tm_sec);
+ send_reply(info, 213, buf);
+ }
+}
+
+/*PAGE
+ *
+ * command_port
+ *
+ * This procedure fills address for data connection given the IP address and
+ * port of the remote machine.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * args - arguments to the "PORT" command.
+ *
+ * Output parameters:
+ * info->data_addr is set according to arguments of the PORT command.
+ * info->use_default is set to 0 on success, 1 on failure.
+ */
+static void
+command_port(FTPD_SessionInfo_t *info, char const *args)
+{
+ enum { NUM_FIELDS = 6 };
+ unsigned int a[NUM_FIELDS];
+ int n;
+
+ close_data_socket(info);
+
+ n = sscanf(args, "%u,%u,%u,%u,%u,%u", a+0, a+1, a+2, a+3, a+4, a+5);
+ if(NUM_FIELDS == n)
+ {
+ int i;
+ union {
+ uint8_t b[NUM_FIELDS];
+ struct {
+ uint32_t ip;
+ uint16_t port;
+ } u ;
+ } ip_info;
+
+ for(i = 0; i < NUM_FIELDS; ++i)
+ {
+ if(a[i] > 255)
+ break;
+ ip_info.b[i] = (uint8_t)a[i];
+ }
+
+ if(i == NUM_FIELDS)
+ {
+ /* Note: while it contradicts with RFC959, we don't allow PORT command
+ * to specify IP address different than those of the originating client
+ * for the sake of safety. */
+ if (ip_info.u.ip == info->def_addr.sin_addr.s_addr)
+ {
+ info->data_addr.sin_addr.s_addr = ip_info.u.ip;
+ info->data_addr.sin_port = ip_info.u.port;
+ info->data_addr.sin_family = AF_INET;
+ memset(info->data_addr.sin_zero, 0, sizeof(info->data_addr.sin_zero));
+
+ info->use_default = 0;
+ send_reply(info, 200, "PORT command successful.");
+ return; /* success */
+ }
+ else
+ {
+ send_reply(info, 425, "Address doesn't match peer's IP.");
+ return;
+ }
+ }
+ }
+ send_reply(info, 501, "Syntax error.");
+}
+
+
+/*PAGE
+ *
+ * command_pasv
+ *
+ * Handle FTP PASV command.
+ * Open socket, listen for and accept connection on it.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ *
+ * Output parameters:
+ * info->pasv_socket is set to the descriptor of the data socket
+ */
+static void
+command_pasv(FTPD_SessionInfo_t *info)
+{
+ int s = -1;
+ int err = 1;
+
+ close_data_socket(info);
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ syslog(LOG_ERR, "ftpd: Error creating PASV socket: %s", serr());
+ else
+ {
+ struct sockaddr_in addr;
+ socklen_t addrLen = sizeof(addr);
+
+ addr = info->ctrl_addr;
+ addr.sin_port = htons(0);
+
+ if (0 > bind(s, (struct sockaddr *)&addr, addrLen))
+ syslog(LOG_ERR, "ftpd: Error binding PASV socket: %s", serr());
+ else if (0 > listen(s, 1))
+ syslog(LOG_ERR, "ftpd: Error listening on PASV socket: %s", serr());
+ else if(set_socket_timeout(s, info->idle))
+ {
+ char buf[FTPD_BUFSIZE];
+ unsigned char const *ip, *p;
+
+ getsockname(s, (struct sockaddr *)&addr, &addrLen);
+ ip = (unsigned char const*)&(addr.sin_addr);
+ p = (unsigned char const*)&(addr.sin_port);
+ snprintf(buf, FTPD_BUFSIZE, "Entering passive mode (%u,%u,%u,%u,%u,%u).",
+ ip[0], ip[1], ip[2], ip[3], p[0], p[1]);
+ send_reply(info, 227, buf);
+
+ info->pasv_socket = accept(s, (struct sockaddr *)&addr, &addrLen);
+ if (0 > info->pasv_socket)
+ syslog(LOG_ERR, "ftpd: Error accepting PASV connection: %s", serr());
+ else
+ {
+ close_socket(s);
+ s = -1;
+ err = 0;
+ }
+ }
+ }
+ if(err)
+ {
+ /* (OSV) The note is from FreeBSD FTPD.
+ * Note: a response of 425 is not mentioned as a possible response to
+ * the PASV command in RFC959. However, it has been blessed as a
+ * legitimate response by Jon Postel in a telephone conversation
+ * with Rick Adams on 25 Jan 89. */
+ send_reply(info, 425, "Can't open passive connection.");
+ close_socket(s);
+ }
+}
+
+
+/*PAGE
+ *
+ * skip_options
+ *
+ * Utility routine to skip options (if any) from input command.
+ *
+ * Input parameters:
+ * p - pointer to pointer to command
+ *
+ * Output parameters:
+ * p - is changed to point to first non-option argument
+ */
+static void
+skip_options(char **p)
+{
+ char* buf = *p;
+ char* last = NULL;
+ while(1) {
+ while(isspace((unsigned char)*buf))
+ ++buf;
+ if(*buf == '-') {
+ if(*++buf == '-') { /* `--' should terminate options */
+ if(isspace((unsigned char)*++buf)) {
+ last = buf;
+ do ++buf;
+ while(isspace((unsigned char)*buf));
+ break;
+ }
+ }
+ while(*buf && !isspace((unsigned char)*buf))
+ ++buf;
+ last = buf;
+ }
+ else
+ break;
+ }
+ if(last)
+ *last = '\0';
+ *p = buf;
+}
+
+/*PAGE
+ *
+ * split_command
+ *
+ * Split command into command itself, options, and arguments. Command itself
+ * is converted to upper case.
+ *
+ * Input parameters:
+ * buf - initial command string
+ *
+ * Output parameter:
+ * buf - is modified by inserting '\0' at ends of split entities
+ * cmd - upper-cased command code
+ * opts - string containing all the options
+ * args - string containing all the arguments
+ */
+void
+split_command(char *buf, char **cmd, char **opts, char **args)
+{
+ char* eoc;
+ char* p = buf;
+ while(isspace((unsigned char)*p))
+ ++p;
+ *cmd = p;
+ while(*p && !isspace((unsigned char)*p))
+ {
+ *p = toupper((unsigned char)*p);
+ ++p;
+ }
+ eoc = p;
+ if(*p)
+ *p++ = '\0';
+ while(isspace((unsigned char)*p))
+ ++p;
+ *opts = p;
+ skip_options(&p);
+ *args = p;
+ if(*opts == p)
+ *opts = eoc;
+ while(*p && *p != '\r' && *p != '\n')
+ ++p;
+ if(*p)
+ *p++ = '\0';
+}
+
+/*PAGE
+ *
+ * exec_command
+ *
+ * Parse and execute FTP command.
+ *
+ * FIXME: This section is somewhat of a hack. We should have a better
+ * way to parse commands.
+ *
+ * Input parameters:
+ * info - corresponding SessionInfo structure
+ * cmd - command to be executed (upper-case)
+ * args - arguments of the command
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
+{
+ char fname[FTPD_BUFSIZE];
+ int wrong_command = 0;
+
+ fname[0] = '\0';
+
+ if (!strcmp("PORT", cmd))
+ {
+ command_port(info, args);
+ }
+ else if (!strcmp("PASV", cmd))
+ {
+ command_pasv(info);
+ }
+ else if (!strcmp("RETR", cmd))
+ {
+ sscanf(args, "%254s", fname);
+ command_retrieve(info, fname);
+ }
+ else if (!strcmp("STOR", cmd))
+ {
+ sscanf(args, "%254s", fname);
+ command_store(info, fname);
+ }
+ else if (!strcmp("LIST", cmd))
+ {
+ sscanf(args, "%254s", fname);
+ command_list(info, fname, 1);
+ }
+ else if (!strcmp("NLST", cmd))
+ {
+ sscanf(args, "%254s", fname);
+ command_list(info, fname, 0);
+ }
+ else if (!strcmp("MDTM", cmd))
+ {
+ sscanf(args, "%254s", fname);
+ command_mdtm(info, fname);
+ }
+ else if (!strcmp("SYST", cmd))
+ {
+ send_reply(info, 215, FTPD_SYSTYPE);
+ }
+ else if (!strcmp("TYPE", cmd))
+ {
+ if (args[0] == 'I')
+ {
+ info->xfer_mode = TYPE_I;
+ send_reply(info, 200, "Type set to I.");
+ }
+ else if (args[0] == 'A')
+ {
+ info->xfer_mode = TYPE_A;
+ send_reply(info, 200, "Type set to A.");
+ }
+ else
+ {
+ info->xfer_mode = TYPE_I;
+ send_reply(info, 504, "Type not implemented. Set to I.");
+ }
+ }
+ else if (!strcmp("USER", cmd) || !strcmp("PASS", cmd))
+ {
+ send_reply(info, 230, "User logged in.");
+ }
+ else if (!strcmp("DELE", cmd))
+ {
+ if(!can_write())
+ {
+ send_reply(info, 550, "Access denied.");
+ }
+ else if (
+ 1 == sscanf(args, "%254s", fname) &&
+ unlink(fname) == 0)
+ {
+ send_reply(info, 257, "DELE successful.");
+ }
+ else
+ {
+ send_reply(info, 550, "DELE failed.");
+ }
+ }
+ else if (!strcmp("SITE", cmd))
+ {
+ char* opts;
+ split_command(args, &cmd, &opts, &args);
+ if(!strcmp("CHMOD", cmd))
+ {
+ int mask;
+
+ if(!can_write())
+ {
+ send_reply(info, 550, "Access denied.");
+ }
+ else if(
+ 2 == sscanf(args, "%o %254s", &mask, fname) &&
+ chmod(fname, (mode_t)mask) == 0)
+ {
+ send_reply(info, 257, "CHMOD successful.");
+ }
+ else
+ {
+ send_reply(info, 550, "CHMOD failed.");
+ }
+ }
+ else
+ wrong_command = 1;
+ }
+ else if (!strcmp("RMD", cmd))
+ {
+ if(!can_write())
+ {
+ send_reply(info, 550, "Access denied.");
+ }
+ else if (
+ 1 == sscanf(args, "%254s", fname) &&
+ rmdir(fname) == 0)
+ {
+ send_reply(info, 257, "RMD successful.");
+ }
+ else
+ {
+ send_reply(info, 550, "RMD failed.");
+ }
+ }
+ else if (!strcmp("MKD", cmd))
+ {
+ if(!can_write())
+ {
+ send_reply(info, 550, "Access denied.");
+ }
+ else if (
+ 1 == sscanf(args, "%254s", fname) &&
+ mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0)
+ {
+ send_reply(info, 257, "MKD successful.");
+ }
+ else
+ {
+ send_reply(info, 550, "MKD failed.");
+ }
+ }
+ else if (!strcmp("CWD", cmd))
+ {
+ sscanf(args, "%254s", fname);
+ command_cwd(info, fname);
+ }
+ else if (!strcmp("CDUP", cmd))
+ {
+ command_cwd(info, "..");
+ }
+ else if (!strcmp("PWD", cmd))
+ {
+ command_pwd(info);
+ }
+ else
+ wrong_command = 1;
+
+ if(wrong_command)
+ send_reply(info, 500, "Command not understood.");
+}
+
+
+/*PAGE
+ *
+ * session
+ *
+ * This task handles single session. It is waked up when the FTP daemon gets a
+ * service request from a remote machine. Here, we watch for commands that
+ * will come through the control connection. These commands are then parsed
+ * and executed until the connection is closed, either unintentionally or
+ * intentionally with the "QUIT" command.
+ *
+ * Input parameters:
+ * arg - pointer to corresponding SessionInfo.
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+session(rtems_task_argument arg)
+{
+ FTPD_SessionInfo_t *const info = (FTPD_SessionInfo_t *)arg;
+ int chroot_made = 0;
+
+ rtems_libio_set_private_env();
+
+ /* chroot() can fail here because the directory may not exist yet. */
+ chroot_made = chroot(ftpd_root) == 0;
+
+ while(1)
+ {
+ rtems_event_set set;
+
+ rtems_event_receive(FTPD_RTEMS_EVENT, RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT,
+ &set);
+
+ chroot_made = chroot_made || chroot(ftpd_root) == 0;
+ chdir("/");
+
+ errno = 0;
+
+ send_reply(info, 220, FTPD_SERVER_MESSAGE);
+
+ while (1)
+ {
+ char buf[FTPD_BUFSIZE];
+ char *cmd, *opts, *args;
+
+ if (fgets(buf, FTPD_BUFSIZE, info->ctrl_fp) == NULL)
+ {
+ syslog(LOG_INFO, "ftpd: Connection aborted.");
+ break;
+ }
+
+ split_command(buf, &cmd, &opts, &args);
+
+ if (!strcmp("QUIT", cmd))
+ {
+ send_reply(info, 221, "Goodbye.");
+ break;
+ }
+ else
+ {
+ exec_command(info, cmd, args);
+ }
+ }
+
+ /* Close connection and put ourselves back into the task pool. */
+ close_data_socket(info);
+ close_stream(info);
+ task_pool_release(info);
+ }
+}
+
+
+/*PAGE
+ *
+ * daemon
+ *
+ * This task runs forever. It waits for service requests on the FTP port
+ * (port 21 by default). When a request is received, it opens a new session
+ * to handle those requests until the connection is closed.
+ *
+ * Input parameters:
+ * NONE
+ *
+ * Output parameters:
+ * NONE
+ */
+static void
+daemon(rtems_task_argument args __attribute__((unused)))
+{
+ int s;
+ socklen_t addrLen;
+ struct sockaddr_in addr;
+ FTPD_SessionInfo_t *info = NULL;
+
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ syslog(LOG_ERR, "ftpd: Error creating socket: %s", serr());
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(rtems_ftpd_configuration.port);
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
+
+ if (0 > bind(s, (struct sockaddr *)&addr, sizeof(addr)))
+ syslog(LOG_ERR, "ftpd: Error binding control socket: %s", serr());
+ else if (0 > listen(s, 1))
+ syslog(LOG_ERR, "ftpd: Error listening on control socket: %s", serr());
+ else while (1)
+ {
+ int ss;
+ addrLen = sizeof(addr);
+ ss = accept(s, (struct sockaddr *)&addr, &addrLen);
+ if (0 > ss)
+ syslog(LOG_ERR, "ftpd: Error accepting control connection: %s", serr());
+ else if(!set_socket_timeout(ss, ftpd_timeout))
+ close_socket(ss);
+ else
+ {
+ info = task_pool_obtain();
+ if (NULL == info)
+ {
+ close_socket(ss);
+ }
+ else
+ {
+ info->ctrl_socket = ss;
+ if ((info->ctrl_fp = fdopen(info->ctrl_socket, "r+")) == NULL)
+ {
+ syslog(LOG_ERR, "ftpd: fdopen() on socket failed: %s", serr());
+ close_stream(info);
+ task_pool_release(info);
+ }
+ else
+ {
+ /* Initialize corresponding SessionInfo structure */
+ info->def_addr = addr;
+ if(0 > getsockname(ss, (struct sockaddr *)&addr, &addrLen))
+ {
+ syslog(LOG_ERR, "ftpd: getsockname(): %s", serr());
+ close_stream(info);
+ task_pool_release(info);
+ }
+ else
+ {
+ info->use_default = 1;
+ info->ctrl_addr = addr;
+ info->pasv_socket = -1;
+ info->data_socket = -1;
+ info->xfer_mode = TYPE_A;
+ info->data_addr.sin_port =
+ htons(ntohs(info->ctrl_addr.sin_port) - 1);
+ info->idle = ftpd_timeout;
+ /* Wakeup the session task. The task will call task_pool_release
+ after it closes connection. */
+ rtems_event_send(info->tid, FTPD_RTEMS_EVENT);
+ }
+ }
+ }
+ }
+ }
+ rtems_task_delete(RTEMS_SELF);
+}
+
+
+/*PAGE
+ *
+ * rtems_ftpd_start
+ *
+ * Here, we start the FTPD task which waits for FTP requests and services
+ * them. This procedure returns to its caller once the task is started.
+ *
+ *
+ * Input parameters:
+ *
+ * Output parameters:
+ * returns RTEMS_SUCCESSFUL on successful start of the daemon.
+ */
+int
+rtems_initialize_ftpd(void)
+{
+ rtems_status_code sc;
+ rtems_id tid;
+ rtems_task_priority priority;
+ int count;
+
+ if (rtems_ftpd_configuration.port == 0)
+ {
+ rtems_ftpd_configuration.port = FTPD_CONTROL_PORT;
+ }
+
+ if (rtems_ftpd_configuration.priority == 0)
+ {
+ rtems_ftpd_configuration.priority = 40;
+ }
+ priority = rtems_ftpd_configuration.priority;
+
+ ftpd_timeout = rtems_ftpd_configuration.idle;
+ if (ftpd_timeout < 0)
+ ftpd_timeout = 0;
+ rtems_ftpd_configuration.idle = ftpd_timeout;
+
+ ftpd_access = rtems_ftpd_configuration.access;
+
+ if (rtems_ftpd_configuration.tasks_count <= 0)
+ rtems_ftpd_configuration.tasks_count = 1;
+ count = rtems_ftpd_configuration.tasks_count;
+
+ if (!task_pool_init(count, priority))
+ {
+ syslog(LOG_ERR, "ftpd: Could not initialize task pool.");
+ return RTEMS_UNSATISFIED;
+ }
+
+ sc = rtems_task_create(rtems_build_name('F', 'T', 'P', 'D'),
+ priority, FTPD_STACKSIZE,
+ RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR |
+ RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
+ &tid);
+
+ if (sc == RTEMS_SUCCESSFUL)
+ {
+ sc = rtems_task_start(tid, daemon, 0);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_task_delete(tid);
+ }
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ task_pool_done(count);
+ syslog(LOG_ERR, "ftpd: Could not create/start FTP daemon: %s",
+ rtems_status_text(sc));
+ return RTEMS_UNSATISFIED;
+ }
+
+ ftpd_root = "/";
+ if (
+ rtems_ftpd_configuration.root &&
+ rtems_ftpd_configuration.root[0] == '/'
+ )
+ ftpd_root = rtems_ftpd_configuration.root;
+
+ rtems_ftpd_configuration.root = ftpd_root;
+
+ syslog(LOG_INFO, "ftpd: FTP daemon started (%d session%s max)",
+ count, ((count > 1) ? "s" : ""));
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/ftpd/ftpd.h b/cpukit/ftpd/ftpd.h
new file mode 100644
index 0000000000..26b39f2d89
--- /dev/null
+++ b/cpukit/ftpd/ftpd.h
@@ -0,0 +1,65 @@
+/*
+ * FTP Server Information
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_FTPD_H
+#define _RTEMS_FTPD_H
+
+#include <rtems/rtems/tasks.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define FTPD_CONTROL_PORT 21
+
+/* FTPD access control flags */
+enum
+{
+ FTPD_NO_WRITE = 0x1,
+ FTPD_NO_READ = 0x2,
+ FTPD_NO_RW = FTPD_NO_WRITE | FTPD_NO_READ
+};
+
+typedef int (*rtems_ftpd_hookfunction)(char *, size_t);
+
+struct rtems_ftpd_hook
+{
+ char *filename;
+ rtems_ftpd_hookfunction hook_function;
+};
+
+struct rtems_ftpd_configuration
+{
+ rtems_task_priority priority; /* FTPD task priority */
+ unsigned long max_hook_filesize; /* Maximum buffersize */
+ /* for hooks */
+ int port; /* Well-known port */
+ struct rtems_ftpd_hook *hooks; /* List of hooks */
+ char const *root; /* Root for FTPD or 0 for / */
+ int tasks_count; /* Max. connections */
+ int idle; /* Idle timeout in seoconds
+ or 0 for no (inf) timeout */
+ int access; /* 0 - r/w, 1 - read-only,
+ 2 - write-only,
+ 3 - browse-only */
+};
+
+/*
+ * Reply codes.
+ */
+#define PRELIM 1 /* positive preliminary */
+#define COMPLETE 2 /* positive completion */
+#define CONTINUE 3 /* positive intermediate */
+#define TRANSIENT 4 /* transient negative completion */
+#define ERROR 5 /* permanent negative completion */
+
+int rtems_initialize_ftpd(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_FTPD_H */
diff --git a/cpukit/ftpd/preinstall.am b/cpukit/ftpd/preinstall.am
new file mode 100644
index 0000000000..85ae87d6db
--- /dev/null
+++ b/cpukit/ftpd/preinstall.am
@@ -0,0 +1,25 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+if LIBNETWORKING
+$(PROJECT_LIB)/libftpd.a: libftpd.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libftpd.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libftpd.a
+endif
diff --git a/cpukit/include/rtems/bsd/sys/cdefs.h b/cpukit/include/rtems/bsd/sys/cdefs.h
new file mode 100644
index 0000000000..0cbc601929
--- /dev/null
+++ b/cpukit/include/rtems/bsd/sys/cdefs.h
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Berkeley Software Design, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/sys/cdefs.h,v 1.87 2005/03/07 15:40:25 stefanf Exp $
+ */
+
+/*
+ * $Id$
+ */
+#ifndef _SYS_CDEFS_H_
+#define _SYS_CDEFS_H_
+
+#if defined(__cplusplus)
+#define __BEGIN_DECLS extern "C" {
+#define __END_DECLS }
+#else
+#define __BEGIN_DECLS
+#define __END_DECLS
+#endif
+
+/*
+ * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
+ * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
+ * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
+ * in between its arguments. __CONCAT can also concatenate double-quoted
+ * strings produced by the __STRING macro, but this only works with ANSI C.
+ *
+ * __XSTRING is like __STRING, but it expands any macros in its argument
+ * first. It is only available with ANSI C.
+ */
+#if defined(__STDC__) || defined(__cplusplus)
+#define __P(protos) protos /* full-blown ANSI C */
+#define __CONCAT1(x,y) x ## y
+#define __CONCAT(x,y) __CONCAT1(x,y)
+#define __STRING(x) #x /* stringify without expanding x */
+#define __XSTRING(x) __STRING(x) /* expand x, then stringify */
+
+#define __const const /* define reserved names to standard */
+#define __signed signed
+#define __volatile volatile
+#if defined(__cplusplus)
+#define __inline inline /* convert to C++ keyword */
+#else
+#ifndef __GNUC__
+#define __inline /* delete GCC keyword */
+#endif /* !__GNUC__ */
+#endif /* !__cplusplus */
+
+#else /* !(__STDC__ || __cplusplus) */
+#define __P(protos) () /* traditional C preprocessor */
+#define __CONCAT(x,y) x/**/y
+#define __STRING(x) "x"
+
+#ifndef __GNUC__
+#define __const /* delete pseudo-ANSI C keywords */
+#define __inline
+#define __signed
+#define __volatile
+/*
+ * In non-ANSI C environments, new programs will want ANSI-only C keywords
+ * deleted from the program and old programs will want them left alone.
+ * When using a compiler other than gcc, programs using the ANSI C keywords
+ * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
+ * When using "gcc -traditional", we assume that this is the intent; if
+ * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
+ */
+#ifndef NO_ANSI_KEYWORDS
+#define const /* delete ANSI C keywords */
+#define inline
+#define signed
+#define volatile
+#endif /* !NO_ANSI_KEYWORDS */
+#endif /* !__GNUC__ */
+#endif /* !(__STDC__ || __cplusplus) */
+
+/*
+ * GCC1 and some versions of GCC2 declare dead (non-returning) and
+ * pure (no side effects) functions using "volatile" and "const";
+ * unfortunately, these then cause warnings under "-ansi -pedantic".
+ * GCC2.5 uses a new, peculiar __attribute__((attrs)) style. All of
+ * these work for GNU C++ (modulo a slight glitch in the C++ grammar
+ * in the distribution version of 2.5.5).
+ */
+#if __GNUC__ < 2
+#define __dead
+#define __dead2
+#define __pure
+#define __pure2
+#define __unused
+#define __used
+#define __attribute__(x)
+#endif
+#if __GNUC__ == 2 && __GNUC_MINOR__ < 5
+#define __dead __volatile
+#define __dead2
+#define __pure __const
+#define __pure2
+#define __unused
+#define __used
+#endif
+#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
+#define __dead
+#define __dead2 __attribute__((__noreturn__))
+#define __pure
+#define __pure2 __attribute__((__const__))
+#define __unused
+#define __used
+#endif
+#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3
+#define __dead
+#define __dead2 __attribute__((__noreturn__))
+#define __pure
+#define __pure2 __attribute__((__const__))
+#define __unused __attribute__((__unused__))
+#define __used __attribute__((__used__))
+#endif
+
+#ifdef __GNUC__
+#ifdef __STDC__
+#define __weak_reference(sym,alias) \
+ __asm__(".stabs \"_" #alias "\",11,0,0,0"); \
+ __asm__(".stabs \"_" #sym "\",1,0,0,0")
+#define __warn_references(sym,msg) \
+ __asm__(".stabs \"" msg "\",30,0,0,0"); \
+ __asm__(".stabs \"_" #sym "\",1,0,0,0")
+#else
+#define __weak_reference(sym,alias) \
+ __asm__(".stabs \"_/**/alias\",11,0,0,0"); \
+ __asm__(".stabs \"_/**/sym\",1,0,0,0")
+#define __warn_references(sym,msg) \
+ __asm__(".stabs msg,30,0,0,0"); \
+ __asm__(".stabs \"_/**/sym\",1,0,0,0")
+#endif
+#endif
+
+#define __IDSTRING(name,string) \
+ static const char name[] __attribute__((__unused__)) = string
+
+#ifndef __RCSID
+#define __RCSID(s) __IDSTRING(rcsid,s)
+#endif
+
+#ifndef __RCSID_SOURCE
+#define __RCSID_SOURCE(s) __IDSTRING(rcsid_source,s)
+#endif
+
+#ifndef __COPYRIGHT
+#define __COPYRIGHT(s) __IDSTRING(copyright,s)
+#endif
+
+#endif /* !_SYS_CDEFS_H_ */
diff --git a/cpukit/include/rtems/bsd/sys/queue.h b/cpukit/include/rtems/bsd/sys/queue.h
new file mode 100644
index 0000000000..4869f730e6
--- /dev/null
+++ b/cpukit/include/rtems/bsd/sys/queue.h
@@ -0,0 +1,602 @@
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)queue.h 8.5 (Berkeley) 8/20/94
+ * $FreeBSD: src/sys/sys/queue.h,v 1.60 2005/03/02 21:33:29 joerg Exp $
+ */
+
+#ifndef _RTEMS_BSD_SYS_QUEUE_H
+#define _RTEMS_BSD_SYS_QUEUE_H
+
+#include <rtems/bsd/sys/cdefs.h>
+
+/*
+ * This file defines four types of data structures: singly-linked lists,
+ * singly-linked tail queues, lists and tail queues.
+ *
+ * A singly-linked list is headed by a single forward pointer. The elements
+ * are singly linked for minimum space and pointer manipulation overhead at
+ * the expense of O(n) removal for arbitrary elements. New elements can be
+ * added to the list after an existing element or at the head of the list.
+ * Elements being removed from the head of the list should use the explicit
+ * macro for this purpose for optimum efficiency. A singly-linked list may
+ * only be traversed in the forward direction. Singly-linked lists are ideal
+ * for applications with large datasets and few or no removals or for
+ * implementing a LIFO queue.
+ *
+ * A singly-linked tail queue is headed by a pair of pointers, one to the
+ * head of the list and the other to the tail of the list. The elements are
+ * singly linked for minimum space and pointer manipulation overhead at the
+ * expense of O(n) removal for arbitrary elements. New elements can be added
+ * to the list after an existing element, at the head of the list, or at the
+ * end of the list. Elements being removed from the head of the tail queue
+ * should use the explicit macro for this purpose for optimum efficiency.
+ * A singly-linked tail queue may only be traversed in the forward direction.
+ * Singly-linked tail queues are ideal for applications with large datasets
+ * and few or no removals or for implementing a FIFO queue.
+ *
+ * A list is headed by a single forward pointer (or an array of forward
+ * pointers for a hash table header). The elements are doubly linked
+ * so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before
+ * or after an existing element or at the head of the list. A list
+ * may only be traversed in the forward direction.
+ *
+ * A tail queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or
+ * after an existing element, at the head of the list, or at the end of
+ * the list. A tail queue may be traversed in either direction.
+ *
+ * For details on the use of these macros, see the queue(3) manual page.
+ *
+ *
+ * SLIST LIST STAILQ TAILQ
+ * _HEAD + + + +
+ * _HEAD_INITIALIZER + + + +
+ * _ENTRY + + + +
+ * _INIT + + + +
+ * _EMPTY + + + +
+ * _FIRST + + + +
+ * _NEXT + + + +
+ * _PREV - - - +
+ * _LAST - - + +
+ * _FOREACH + + + +
+ * _FOREACH_REVERSE - - - +
+ * _INSERT_HEAD + + + +
+ * _INSERT_BEFORE - + - +
+ * _INSERT_AFTER + + + +
+ * _INSERT_TAIL - - + +
+ * _CONCAT - - + +
+ * _REMOVE_HEAD + - + -
+ * _REMOVE + + + +
+ *
+ */
+#define QUEUE_MACRO_DEBUG 0
+#if QUEUE_MACRO_DEBUG
+/* Store the last 2 places the queue element or head was altered */
+struct qm_trace {
+ char * lastfile;
+ int lastline;
+ char * prevfile;
+ int prevline;
+};
+
+#define TRACEBUF struct qm_trace trace;
+#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
+
+#define QMD_TRACE_HEAD(head) do { \
+ (head)->trace.prevline = (head)->trace.lastline; \
+ (head)->trace.prevfile = (head)->trace.lastfile; \
+ (head)->trace.lastline = __LINE__; \
+ (head)->trace.lastfile = __FILE__; \
+} while (0)
+
+#define QMD_TRACE_ELEM(elem) do { \
+ (elem)->trace.prevline = (elem)->trace.lastline; \
+ (elem)->trace.prevfile = (elem)->trace.lastfile; \
+ (elem)->trace.lastline = __LINE__; \
+ (elem)->trace.lastfile = __FILE__; \
+} while (0)
+
+#else
+#define QMD_TRACE_ELEM(elem)
+#define QMD_TRACE_HEAD(head)
+#define TRACEBUF
+#define TRASHIT(x)
+#endif /* QUEUE_MACRO_DEBUG */
+
+/*
+ * Singly-linked List declarations.
+ */
+#define SLIST_HEAD(name, type) \
+struct name { \
+ struct type *slh_first; /* first element */ \
+}
+
+#define SLIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define SLIST_ENTRY(type) \
+struct { \
+ struct type *sle_next; /* next element */ \
+}
+
+/*
+ * Singly-linked List functions.
+ */
+#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
+
+#define SLIST_FIRST(head) ((head)->slh_first)
+
+#define SLIST_FOREACH(var, head, field) \
+ for ((var) = SLIST_FIRST((head)); \
+ (var); \
+ (var) = SLIST_NEXT((var), field))
+
+#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
+ for ((varp) = &SLIST_FIRST((head)); \
+ ((var) = *(varp)) != NULL; \
+ (varp) = &SLIST_NEXT((var), field))
+
+#define SLIST_INIT(head) do { \
+ SLIST_FIRST((head)) = NULL; \
+} while (0)
+
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
+ SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
+ SLIST_NEXT((slistelm), field) = (elm); \
+} while (0)
+
+#define SLIST_INSERT_HEAD(head, elm, field) do { \
+ SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
+ SLIST_FIRST((head)) = (elm); \
+} while (0)
+
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
+
+#define SLIST_REMOVE(head, elm, type, field) do { \
+ if (SLIST_FIRST((head)) == (elm)) { \
+ SLIST_REMOVE_HEAD((head), field); \
+ } \
+ else { \
+ struct type *curelm = SLIST_FIRST((head)); \
+ while (SLIST_NEXT(curelm, field) != (elm)) \
+ curelm = SLIST_NEXT(curelm, field); \
+ SLIST_NEXT(curelm, field) = \
+ SLIST_NEXT(SLIST_NEXT(curelm, field), field); \
+ } \
+} while (0)
+
+#define SLIST_REMOVE_HEAD(head, field) do { \
+ SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
+} while (0)
+
+/*
+ * Singly-linked Tail queue declarations.
+ */
+#define STAILQ_HEAD(name, type) \
+struct name { \
+ struct type *stqh_first;/* first element */ \
+ struct type **stqh_last;/* addr of last next element */ \
+}
+
+#define STAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).stqh_first }
+
+#define STAILQ_ENTRY(type) \
+struct { \
+ struct type *stqe_next; /* next element */ \
+}
+
+/*
+ * Singly-linked Tail queue functions.
+ */
+#define STAILQ_CONCAT(head1, head2) do { \
+ if (!STAILQ_EMPTY((head2))) { \
+ *(head1)->stqh_last = (head2)->stqh_first; \
+ (head1)->stqh_last = (head2)->stqh_last; \
+ STAILQ_INIT((head2)); \
+ } \
+} while (0)
+
+#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
+
+#define STAILQ_FIRST(head) ((head)->stqh_first)
+
+#define STAILQ_FOREACH(var, head, field) \
+ for((var) = STAILQ_FIRST((head)); \
+ (var); \
+ (var) = STAILQ_NEXT((var), field))
+
+#define STAILQ_INIT(head) do { \
+ STAILQ_FIRST((head)) = NULL; \
+ (head)->stqh_last = &STAILQ_FIRST((head)); \
+} while (0)
+
+#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
+ if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \
+ STAILQ_NEXT((tqelm), field) = (elm); \
+} while (0)
+
+#define STAILQ_INSERT_HEAD(head, elm, field) do { \
+ if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \
+ STAILQ_FIRST((head)) = (elm); \
+} while (0)
+
+#define STAILQ_INSERT_TAIL(head, elm, field) do { \
+ STAILQ_NEXT((elm), field) = NULL; \
+ *(head)->stqh_last = (elm); \
+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \
+} while (0)
+
+#define STAILQ_LAST(head, type, field) \
+ (STAILQ_EMPTY((head)) ? \
+ NULL : \
+ ((struct type *) \
+ ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
+
+#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
+
+#define STAILQ_REMOVE(head, elm, type, field) do { \
+ if (STAILQ_FIRST((head)) == (elm)) { \
+ STAILQ_REMOVE_HEAD((head), field); \
+ } \
+ else { \
+ struct type *curelm = STAILQ_FIRST((head)); \
+ while (STAILQ_NEXT(curelm, field) != (elm)) \
+ curelm = STAILQ_NEXT(curelm, field); \
+ if ((STAILQ_NEXT(curelm, field) = \
+ STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
+ (head)->stqh_last = &STAILQ_NEXT((curelm), field);\
+ } \
+} while (0)
+
+#define STAILQ_REMOVE_HEAD(head, field) do { \
+ if ((STAILQ_FIRST((head)) = \
+ STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
+ (head)->stqh_last = &STAILQ_FIRST((head)); \
+} while (0)
+
+#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \
+ if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
+ (head)->stqh_last = &STAILQ_FIRST((head)); \
+} while (0)
+
+/*
+ * List declarations.
+ */
+#define LIST_HEAD(name, type) \
+struct name { \
+ struct type *lh_first; /* first element */ \
+}
+
+#define LIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define LIST_ENTRY(type) \
+struct { \
+ struct type *le_next; /* next element */ \
+ struct type **le_prev; /* address of previous next element */ \
+}
+
+/*
+ * List functions.
+ */
+
+#define LIST_EMPTY(head) ((head)->lh_first == NULL)
+
+#define LIST_FIRST(head) ((head)->lh_first)
+
+#define LIST_FOREACH(var, head, field) \
+ for ((var) = LIST_FIRST((head)); \
+ (var); \
+ (var) = LIST_NEXT((var), field))
+
+#define LIST_INIT(head) do { \
+ LIST_FIRST((head)) = NULL; \
+} while (0)
+
+#define LIST_INSERT_AFTER(listelm, elm, field) do { \
+ if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
+ LIST_NEXT((listelm), field)->field.le_prev = \
+ &LIST_NEXT((elm), field); \
+ LIST_NEXT((listelm), field) = (elm); \
+ (elm)->field.le_prev = &LIST_NEXT((listelm), field); \
+} while (0)
+
+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.le_prev = (listelm)->field.le_prev; \
+ LIST_NEXT((elm), field) = (listelm); \
+ *(listelm)->field.le_prev = (elm); \
+ (listelm)->field.le_prev = &LIST_NEXT((elm), field); \
+} while (0)
+
+#define LIST_INSERT_HEAD(head, elm, field) do { \
+ if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
+ LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
+ LIST_FIRST((head)) = (elm); \
+ (elm)->field.le_prev = &LIST_FIRST((head)); \
+} while (0)
+
+#define LIST_NEXT(elm, field) ((elm)->field.le_next)
+
+#define LIST_REMOVE(elm, field) do { \
+ if (LIST_NEXT((elm), field) != NULL) \
+ LIST_NEXT((elm), field)->field.le_prev = \
+ (elm)->field.le_prev; \
+ *(elm)->field.le_prev = LIST_NEXT((elm), field); \
+} while (0)
+
+/*
+ * Tail queue declarations.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+ TRACEBUF \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+ TRACEBUF \
+}
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_CONCAT(head1, head2, field) do { \
+ if (!TAILQ_EMPTY(head2)) { \
+ *(head1)->tqh_last = (head2)->tqh_first; \
+ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
+ (head1)->tqh_last = (head2)->tqh_last; \
+ TAILQ_INIT((head2)); \
+ QMD_TRACE_HEAD(head); \
+ QMD_TRACE_HEAD(head2); \
+ } \
+} while (0)
+
+#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
+
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+
+#define TAILQ_FOREACH(var, head, field) \
+ for ((var) = TAILQ_FIRST((head)); \
+ (var); \
+ (var) = TAILQ_NEXT((var), field))
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for ((var) = TAILQ_LAST((head), headname); \
+ (var); \
+ (var) = TAILQ_PREV((var), headname, field))
+
+#define TAILQ_INIT(head) do { \
+ TAILQ_FIRST((head)) = NULL; \
+ (head)->tqh_last = &TAILQ_FIRST((head)); \
+ QMD_TRACE_HEAD(head); \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
+ TAILQ_NEXT((elm), field)->field.tqe_prev = \
+ &TAILQ_NEXT((elm), field); \
+ else { \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ QMD_TRACE_HEAD(head); \
+ } \
+ TAILQ_NEXT((listelm), field) = (elm); \
+ (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
+ QMD_TRACE_ELEM(&(elm)->field); \
+ QMD_TRACE_ELEM(&listelm->field); \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ TAILQ_NEXT((elm), field) = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
+ QMD_TRACE_ELEM(&(elm)->field); \
+ QMD_TRACE_ELEM(&listelm->field); \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
+ TAILQ_FIRST((head))->field.tqe_prev = \
+ &TAILQ_NEXT((elm), field); \
+ else \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ TAILQ_FIRST((head)) = (elm); \
+ (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
+ QMD_TRACE_HEAD(head); \
+ QMD_TRACE_ELEM(&(elm)->field); \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ TAILQ_NEXT((elm), field) = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ QMD_TRACE_HEAD(head); \
+ QMD_TRACE_ELEM(&(elm)->field); \
+} while (0)
+
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field)) != NULL) \
+ TAILQ_NEXT((elm), field)->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else { \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ QMD_TRACE_HEAD(head); \
+ } \
+ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
+ TRASHIT((elm)->field.tqe_next); \
+ TRASHIT((elm)->field.tqe_prev); \
+ QMD_TRACE_ELEM(&(elm)->field); \
+} while (0)
+
+
+/*
+ * Circular queue definitions.
+ */
+#define CIRCLEQ_HEAD(name, type) \
+struct name { \
+ struct type *cqh_first; /* first element */ \
+ struct type *cqh_last; /* last element */ \
+}
+
+#define CIRCLEQ_ENTRY(type) \
+struct { \
+ struct type *cqe_next; /* next element */ \
+ struct type *cqe_prev; /* previous element */ \
+}
+
+/*
+ * Circular queue functions.
+ */
+#define CIRCLEQ_INIT(head) { \
+ (head)->cqh_first = (void *)(head); \
+ (head)->cqh_last = (void *)(head); \
+}
+
+#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \
+ (elm)->field.cqe_next = (listelm)->field.cqe_next; \
+ (elm)->field.cqe_prev = (listelm); \
+ if ((listelm)->field.cqe_next == (void *)(head)) \
+ (head)->cqh_last = (elm); \
+ else \
+ (listelm)->field.cqe_next->field.cqe_prev = (elm); \
+ (listelm)->field.cqe_next = (elm); \
+}
+
+#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \
+ (elm)->field.cqe_next = (listelm); \
+ (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
+ if ((listelm)->field.cqe_prev == (void *)(head)) \
+ (head)->cqh_first = (elm); \
+ else \
+ (listelm)->field.cqe_prev->field.cqe_next = (elm); \
+ (listelm)->field.cqe_prev = (elm); \
+}
+
+#define CIRCLEQ_INSERT_HEAD(head, elm, field) { \
+ (elm)->field.cqe_next = (head)->cqh_first; \
+ (elm)->field.cqe_prev = (void *)(head); \
+ if ((head)->cqh_last == (void *)(head)) \
+ (head)->cqh_last = (elm); \
+ else \
+ (head)->cqh_first->field.cqe_prev = (elm); \
+ (head)->cqh_first = (elm); \
+}
+
+#define CIRCLEQ_INSERT_TAIL(head, elm, field) { \
+ (elm)->field.cqe_next = (void *)(head); \
+ (elm)->field.cqe_prev = (head)->cqh_last; \
+ if ((head)->cqh_first == (void *)(head)) \
+ (head)->cqh_first = (elm); \
+ else \
+ (head)->cqh_last->field.cqe_next = (elm); \
+ (head)->cqh_last = (elm); \
+}
+
+#define CIRCLEQ_REMOVE(head, elm, field) { \
+ if ((elm)->field.cqe_next == (void *)(head)) \
+ (head)->cqh_last = (elm)->field.cqe_prev; \
+ else \
+ (elm)->field.cqe_next->field.cqe_prev = \
+ (elm)->field.cqe_prev; \
+ if ((elm)->field.cqe_prev == (void *)(head)) \
+ (head)->cqh_first = (elm)->field.cqe_next; \
+ else \
+ (elm)->field.cqe_prev->field.cqe_next = \
+ (elm)->field.cqe_next; \
+}
+
+#ifdef _KERNEL
+
+/*
+ * XXX insque() and remque() are an old way of handling certain queues.
+ * They bogusly assumes that all queue heads look alike.
+ */
+
+
+#ifdef __GNUC__
+
+struct quehead {
+ struct quehead *qh_link;
+ struct quehead *qh_rlink;
+};
+
+static __inline void
+insque(void *a, void *b)
+{
+ struct quehead *element = (struct quehead *)a,
+ *head = (struct quehead *)b;
+
+ element->qh_link = head->qh_link;
+ element->qh_rlink = head;
+ head->qh_link = element;
+ element->qh_link->qh_rlink = element;
+}
+
+static __inline void
+remque(void *a)
+{
+ struct quehead *element = (struct quehead *)a;
+
+ element->qh_link->qh_rlink = element->qh_rlink;
+ element->qh_rlink->qh_link = element->qh_link;
+ element->qh_rlink = 0;
+}
+
+#else /* !__GNUC__ */
+
+void insque(void *a, void *b);
+void remque(void *a);
+
+#endif /* __GNUC__ */
+
+#endif /* _KERNEL */
+
+#endif /* !_RTEMS_BSD_SYS_QUEUE_H */
diff --git a/cpukit/include/rtems/bspIo.h b/cpukit/include/rtems/bspIo.h
new file mode 100644
index 0000000000..372dbd4970
--- /dev/null
+++ b/cpukit/include/rtems/bspIo.h
@@ -0,0 +1,76 @@
+/* bspIo.h
+ *
+ * This include file contains declaration of interface that
+ * will be provided by the file contained in this directory.
+ *
+ * COPYRIGHT (c) 1998 valette@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+#ifndef _RTEMS_BSPIO_H
+#define _RTEMS_BSPIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * All the functions declared as extern after this comment
+ * MUST be implemented in each BSP. Using this function,
+ * this directory contains shared code that export higher level
+ * functionnality described after the next command.
+ */
+typedef void (*BSP_output_char_function_type) (char c);
+typedef int (*BSP_polling_getchar_function_type) (void);
+
+extern BSP_output_char_function_type BSP_output_char;
+extern BSP_polling_getchar_function_type BSP_poll_char;
+
+/*
+ * All the function declared as extern after this comment
+ * are available for each BSP by compiling and linking
+ * the files contained in this directory PROVIDED definition
+ * and initialisation of the previous variable are done.
+ */
+#include <stdarg.h>
+
+/**
+ * This method polls for a key in the simplest possible fashion
+ * from whatever the debug console device is.
+ *
+ * @return If a character is available, it is returned. Otherwise
+ * this method returns -1.
+ *
+ * @note This method uses the BSP_poll_char pointer to a BSP
+ * provided method.
+ */
+extern int getchark(void);
+extern void vprintk(const char *fmt, va_list ap);
+extern void printk(const char *fmt, ...);
+extern void putk(const char *s);
+
+/*
+ * This routine is passed into RTEMS reporting functions
+ * that may have their output redirected. In particular,
+ * the cpu usage, period usage, and stack usage reporting
+ * functions use this. If the user provides their
+ * own "printf plugin", then they may redirect those reports
+ * as they see fit.
+ */
+extern int printk_plugin(void *context, const char *fmt, ...);
+
+/*
+ * Type definition for function which can be plugged in to
+ * certain reporting routines to redirect the output
+ */
+typedef int (*rtems_printk_plugin_t)(void *, const char *format, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/include/rtems/btimer.h b/cpukit/include/rtems/btimer.h
new file mode 100644
index 0000000000..b74a6f6bce
--- /dev/null
+++ b/cpukit/include/rtems/btimer.h
@@ -0,0 +1,54 @@
+/**
+ * @file rtems/btimer.h
+ *
+ * RTEMS benchmark timer API for all boards.
+ */
+
+/*
+ * COPYRIGHT (c) 2011 Ralf Corsépius Ulm/Germany
+ *
+ * Derived from libcsupport/include/timerdrv.h:
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * All the functions declared as extern after this comment
+ * MUST be implemented in each BSP.
+ */
+
+#ifndef _RTEMS_BTIMER_H
+#define _RTEMS_BTIMER_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <rtems/rtems/status.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* functions */
+
+extern void benchmark_timer_initialize( void );
+
+extern uint32_t benchmark_timer_read( void );
+
+extern rtems_status_code benchmark_timer_empty_function( void );
+
+extern void benchmark_timer_disable_subtracting_average_overhead(
+ bool find_flag
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/include/rtems/concat.h b/cpukit/include/rtems/concat.h
new file mode 100644
index 0000000000..02d45f21a4
--- /dev/null
+++ b/cpukit/include/rtems/concat.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2004,2005 Ralf Corsepius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_CONCAT_H
+#define _RTEMS_CONCAT_H
+
+/* ANSI concatenation macros. */
+
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#define EXPAND0(x) x
+#define CONCAT0(a,b) EXPAND0(a)EXPAND0(b)
+
+#endif
diff --git a/cpukit/include/rtems/endian.h b/cpukit/include/rtems/endian.h
new file mode 100644
index 0000000000..1321d244c2
--- /dev/null
+++ b/cpukit/include/rtems/endian.h
@@ -0,0 +1,224 @@
+/*
+ * $Id$
+ */
+
+#ifndef _RTEMS_ENDIAN_H
+#define _RTEMS_ENDIAN_H
+
+#include <rtems.h>
+
+/*
+ * BSD-style endian declaration
+ */
+#define BIG_ENDIAN 4321
+#define LITTLE_ENDIAN 1234
+
+#ifndef BYTE_ORDER
+#if CPU_BIG_ENDIAN
+# define BYTE_ORDER BIG_ENDIAN
+#elif CPU_LITTLE_ENDIAN
+# define BYTE_ORDER LITTLE_ENDIAN
+#else
+# error "Can't decide which end is which!"
+#endif
+#endif
+
+#if ( CPU_BIG_ENDIAN == TRUE )
+
+/*
+ * Very simply on big endian CPUs
+ */
+
+static inline uint32_t ntohl( uint32_t _x )
+{
+ return _x;
+}
+
+static inline uint16_t ntohs( uint16_t _x )
+{
+ return _x;
+}
+
+static inline uint32_t htonl( uint32_t _x )
+{
+ return _x;
+}
+
+static inline uint16_t htons( uint16_t _x )
+{
+ return _x;
+}
+
+#define NTOHS(x)
+#define HTONS(x)
+#define NTOHL(x)
+#define HTONL(x)
+
+#elif ( CPU_LITTLE_ENDIAN == TRUE )
+
+/*
+ * A little more complicated on little endian CPUs
+ */
+
+static inline uint32_t ntohl( uint32_t _x )
+{
+ return CPU_swap_u32(_x);
+}
+
+static inline uint16_t ntohs( uint16_t _x )
+{
+ return CPU_swap_u16(_x);
+}
+
+static inline uint32_t htonl( uint32_t _x )
+{
+ return CPU_swap_u32(_x);
+}
+
+static inline uint16_t htons( uint16_t _x )
+{
+ return CPU_swap_u16(_x);
+}
+
+#define NTOHS(x) (x) = ntohs(x)
+#define HTONS(x) (x) = htons(x)
+#define NTOHL(x) (x) = ntohl(x)
+#define HTONL(x) (x) = htonl(x)
+
+#else
+#error "Unknown endian-ness for this cpu"
+#endif
+
+static inline uint16_t rtems_uint16_from_little_endian( const uint8_t *data)
+{
+ uint16_t value = 0;
+ ssize_t i = 0;
+
+ for (i = 1; i >= 0; --i) {
+ value = (uint16_t) ((value << 8) + data [i]);
+ }
+
+ return value;
+}
+
+static inline uint32_t rtems_uint32_from_little_endian( const uint8_t *data)
+{
+ uint32_t value = 0;
+ ssize_t i = 0;
+
+ for (i = 3; i >= 0; --i) {
+ value = (value << 8) + data [i];
+ }
+
+ return value;
+}
+
+static inline uint64_t rtems_uint64_from_little_endian( const uint8_t *data)
+{
+ uint64_t value = 0;
+ ssize_t i = 0;
+
+ for (i = 7; i >= 0; --i) {
+ value = (value << 8) + (uint64_t) data [i];
+ }
+
+ return value;
+}
+
+static inline uint16_t rtems_uint16_from_big_endian( const uint8_t *data)
+{
+ uint16_t value = 0;
+ size_t i = 0;
+
+ for (i = 0; i < 2; ++i) {
+ value = (uint16_t) ((value << 8) + data [i]);
+ }
+
+ return value;
+}
+
+static inline uint32_t rtems_uint32_from_big_endian( const uint8_t *data)
+{
+ uint32_t value = 0;
+ size_t i = 0;
+
+ for (i = 0; i < 4; ++i) {
+ value = (value << 8) + (uint32_t) data [i];
+ }
+
+ return value;
+}
+
+static inline uint64_t rtems_uint64_from_big_endian( const uint8_t *data)
+{
+ uint64_t value = 0;
+ size_t i = 0;
+
+ for (i = 0; i < 8; ++i) {
+ value = (value << 8) + (uint64_t) data [i];
+ }
+
+ return value;
+}
+
+static inline void rtems_uint16_to_little_endian( uint16_t value, uint8_t *data)
+{
+ size_t i = 0;
+
+ for (i = 0; i < 2; ++i) {
+ data [i] = (uint8_t) value;
+ value >>= 8;
+ }
+}
+
+static inline void rtems_uint32_to_little_endian( uint32_t value, uint8_t *data)
+{
+ size_t i = 0;
+
+ for (i = 0; i < 4; ++i) {
+ data [i] = (uint8_t) value;
+ value >>= 8;
+ }
+}
+
+static inline void rtems_uint64_to_little_endian( uint64_t value, uint8_t *data)
+{
+ size_t i = 0;
+
+ for (i = 0; i < 8; ++i) {
+ data [i] = (uint8_t) value;
+ value >>= 8;
+ }
+}
+
+static inline void rtems_uint16_to_big_endian( uint16_t value, uint8_t *data)
+{
+ ssize_t i = 0;
+
+ for (i = 1; i >= 0; --i) {
+ data [i] = (uint8_t) value;
+ value >>= 8;
+ }
+}
+
+static inline void rtems_uint32_to_big_endian( uint32_t value, uint8_t *data)
+{
+ ssize_t i = 0;
+
+ for (i = 3; i >= 0; --i) {
+ data [i] = (uint8_t) value;
+ value >>= 8;
+ }
+}
+
+static inline void rtems_uint64_to_big_endian( uint64_t value, uint8_t *data)
+{
+ ssize_t i = 0;
+
+ for (i = 7; i >= 0; --i) {
+ data [i] = (uint8_t) value;
+ value >>= 8;
+ }
+}
+
+#endif /* _RTEMS_ENDIAN_H */
diff --git a/cpukit/include/rtems/fs.h b/cpukit/include/rtems/fs.h
new file mode 100644
index 0000000000..cd8a8d5457
--- /dev/null
+++ b/cpukit/include/rtems/fs.h
@@ -0,0 +1,65 @@
+/*
+ * Some basic filesystem types
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_FS_H
+#define _RTEMS_FS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * File descriptor Table Information
+ */
+
+/* Forward declarations */
+
+/* FIXME: shouldn't this better not be here? */
+typedef struct rtems_libio_tt rtems_libio_t;
+
+typedef struct rtems_filesystem_location_info_tt
+ rtems_filesystem_location_info_t;
+
+struct rtems_filesystem_mount_table_entry_tt;
+typedef struct rtems_filesystem_mount_table_entry_tt
+ rtems_filesystem_mount_table_entry_t;
+
+typedef struct _rtems_filesystem_file_handlers_r
+ rtems_filesystem_file_handlers_r;
+typedef struct _rtems_filesystem_operations_table
+ rtems_filesystem_operations_table;
+
+/*
+ * Structure used to determine a location/filesystem in the tree.
+ */
+
+struct rtems_filesystem_location_info_tt
+{
+ void *node_access;
+ void *node_access_2;
+ const rtems_filesystem_file_handlers_r *handlers;
+ const rtems_filesystem_operations_table *ops;
+ rtems_filesystem_mount_table_entry_t *mt_entry;
+};
+
+/*
+ * Return the mount table entry for a path location.
+ */
+#define rtems_filesystem_location_mount(_pl) ((_pl)->mt_entry)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/include/rtems/irq-extension.h b/cpukit/include/rtems/irq-extension.h
new file mode 100644
index 0000000000..ad6f0b209c
--- /dev/null
+++ b/cpukit/include/rtems/irq-extension.h
@@ -0,0 +1,270 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_interrupt_extension
+ *
+ * @brief Header file for the Interrupt Manager Extension.
+ */
+
+/*
+ * Based on concepts of Pavel Pisa, Till Straumann and Eric Valette.
+ *
+ * Copyright (c) 2008
+ * Embedded Brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * rtems@embedded-brains.de
+ *
+ * The license and distribution terms for this file may be found in the file
+ * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef RTEMS_IRQ_EXTENSION_H
+#define RTEMS_IRQ_EXTENSION_H
+
+#include <rtems.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup rtems_interrupt_extension Interrupt Manager Extension
+ *
+ * @ingroup ClassicINTR
+ *
+ * In addition to the Classic API interrupt handler with a handle are
+ * supported. You can also install multiple shared handler for one interrupt
+ * vector.
+ *
+ * @{
+ */
+
+/**
+ * @brief Makes the interrupt handler unique. Prevents other handler from
+ * using the same interrupt vector.
+ */
+#define RTEMS_INTERRUPT_UNIQUE ((rtems_option) 0x00000001)
+
+/**
+ * @brief Allows that this interrupt handler may share a common interrupt
+ * vector with other handler.
+ */
+#define RTEMS_INTERRUPT_SHARED ((rtems_option) 0x00000000)
+
+/**
+ * @brief Returns true if the interrupt handler unique option is set.
+ */
+#define RTEMS_INTERRUPT_IS_UNIQUE( options) \
+ ((options) & RTEMS_INTERRUPT_UNIQUE)
+
+/**
+ * @brief Returns true if the interrupt handler shared option is set.
+ */
+#define RTEMS_INTERRUPT_IS_SHARED( options) \
+ (!RTEMS_INTERRUPT_IS_UNIQUE( options))
+
+/**
+ * @brief Interrupt handler routine type.
+ */
+typedef void (*rtems_interrupt_handler)(void *);
+
+/**
+ * @brief Installs the interrupt handler routine @a handler for the interrupt
+ * vector with number @a vector.
+ *
+ * You can set one of the mutually exclusive options
+ *
+ * - @ref RTEMS_INTERRUPT_UNIQUE
+ * - @ref RTEMS_INTERRUPT_SHARED
+ *
+ * with the @a options parameter for the interrupt handler.
+ *
+ * The handler routine shall be called with argument @a arg when dispatched.
+ * The order in which the shared interrupt handlers are dispatched for one
+ * vector is BSP dependent.
+ *
+ * If the option @ref RTEMS_INTERRUPT_UNIQUE is set then it shall be ensured
+ * that this handler will be the only one for this vector.
+ *
+ * You can provide an informative description @a info. This may be used for
+ * system debugging and status tools. The string has to be persistent during
+ * the handler life time.
+ *
+ * This function may block.
+ *
+ * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
+ * @retval RTEMS_CALLED_FROM_ISR If this function is called from interrupt
+ * context this shall be returned.
+ * @retval RTEMS_INVALID_ADDRESS If the handler address is NULL this shall be
+ * returned.
+ * @retval RTEMS_INVALID_ID If the vector number is out of range this shall be
+ * returned.
+ * @retval RTEMS_INVALID_NUMBER If an option is not applicable this shall be
+ * returned.
+ * @retval RTEMS_RESOURCE_IN_USE If the vector is already occupied with a
+ * unique handler this shall be returned. If a unique handler should be
+ * installed and there is already a handler installed this shall be returned.
+ * @retval RTEMS_TOO_MANY If a handler with this argument is already installed
+ * for the vector this shall be returned.
+ * @retval RTEMS_IO_ERROR Reserved for board support package specific error
+ * conditions.
+ */
+rtems_status_code rtems_interrupt_handler_install(
+ rtems_vector_number vector,
+ const char *info,
+ rtems_option options,
+ rtems_interrupt_handler handler,
+ void *arg
+);
+
+/**
+ * @brief Removes the interrupt handler routine @a handler with argument @a arg
+ * for the interrupt vector with number @a vector.
+ *
+ * This function may block.
+ *
+ * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
+ * @retval RTEMS_CALLED_FROM_ISR If this function is called from interrupt
+ * context this shall be returned.
+ * @retval RTEMS_INVALID_ADDRESS If the handler address is NULL this shall be
+ * returned.
+ * @retval RTEMS_INVALID_ID If the vector number is out of range this shall be
+ * returned.
+ * @retval RTEMS_UNSATISFIED If the handler with its argument is not installed
+ * for the vector this shall be returned.
+ * @retval RTEMS_IO_ERROR Reserved for board support package specific error
+ * conditions.
+ */
+rtems_status_code rtems_interrupt_handler_remove(
+ rtems_vector_number vector,
+ rtems_interrupt_handler handler,
+ void *arg
+);
+
+/**
+ * @brief Interrupt handler iteration routine type.
+ *
+ * @see rtems_interrupt_handler_iterate()
+ */
+typedef void (*rtems_interrupt_per_handler_routine)(
+ void *, const char *, rtems_option, rtems_interrupt_handler, void *
+);
+
+/**
+ * @brief Iterates over all installed interrupt handler of the interrupt vector
+ * with number @a vector.
+ *
+ * For each installed handler of the vector the function @a routine will be
+ * called with the supplied argument @a arg and the handler information,
+ * options, routine and argument.
+ *
+ * This function is intended for system information and diagnostics.
+ *
+ * This function may block. Never install or remove an interrupt handler
+ * within the iteration routine. This may result in a deadlock.
+ *
+ * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
+ * @retval RTEMS_CALLED_FROM_ISR If this function is called from interrupt
+ * context this shall be returned.
+ * @retval RTEMS_INVALID_ID If the vector number is out of range this shall be
+ * returned.
+ * @retval RTEMS_IO_ERROR Reserved for board support package specific error
+ * conditions.
+ */
+rtems_status_code rtems_interrupt_handler_iterate(
+ rtems_vector_number vector,
+ rtems_interrupt_per_handler_routine routine,
+ void *arg
+);
+
+/**
+ * @brief Initializes an interrupt server task.
+ *
+ * The task will have the priority @a priority, the stack size @a stack_size,
+ * the modes @a modes and the attributes @a attributes. The identifier of the
+ * server task will be returned in @a server. Interrupt handlers can be
+ * installed on the server with rtems_interrupt_server_handler_install() and
+ * removed with rtems_interrupt_server_handler_remove() using this identifier.
+ * In case of an interrupt the request will be forwarded to the server. The
+ * handlers are executed within the server context. If one handler blocks on
+ * something this may delay the processing of other handlers.
+ *
+ * The server identifier pointer @a server may be @a NULL to initialize the
+ * default server.
+ *
+ * This function may block.
+ *
+ * @see rtems_task_create().
+ *
+ * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
+ * @retval RTEMS_INCORRECT_STATE If the default server is already initialized
+ * this shall be returned.
+ * @retval RTEMS_IO_ERROR Reserved for board support package specific error
+ * conditions.
+ */
+rtems_status_code rtems_interrupt_server_initialize(
+ rtems_task_priority priority,
+ size_t stack_size,
+ rtems_mode modes,
+ rtems_attribute attributes,
+ rtems_id *server
+);
+
+/**
+ * @brief Installs the interrupt handler routine @a handler for the interrupt
+ * vector with number @a vector on the server @a server.
+ *
+ * The handler routine will be executed on the corresponding interrupt server
+ * task. A server identifier @a server of @c RTEMS_ID_NONE may be used to
+ * install the handler on the default server.
+ *
+ * This function may block.
+ *
+ * @see rtems_interrupt_handler_install().
+ *
+ * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
+ * @retval RTEMS_INCORRECT_STATE If the interrupt handler server is not
+ * initialized this shall be returned.
+ * @retval * For other errors see rtems_interrupt_handler_install().
+ */
+rtems_status_code rtems_interrupt_server_handler_install(
+ rtems_id server,
+ rtems_vector_number vector,
+ const char *info,
+ rtems_option options,
+ rtems_interrupt_handler handler,
+ void *arg
+);
+
+/**
+ * @brief Removes the interrupt handler routine @a handler with argument @a arg
+ * for the interrupt vector with number @a vector from the server @a server.
+ *
+ * A server identifier @a server of @c RTEMS_ID_NONE may be used to remove the
+ * handler from the default server.
+ *
+ * This function may block.
+ *
+ * @see rtems_interrupt_handler_remove().
+ *
+ * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
+ * @retval RTEMS_INCORRECT_STATE If the interrupt handler server is not
+ * initialized this shall be returned.
+ * @retval * For other errors see rtems_interrupt_handler_remove().
+ */
+rtems_status_code rtems_interrupt_server_handler_remove(
+ rtems_id server,
+ rtems_vector_number vector,
+ rtems_interrupt_handler handler,
+ void *arg
+);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RTEMS_IRQ_EXTENSION_H */
diff --git a/cpukit/include/rtems/irq.h b/cpukit/include/rtems/irq.h
new file mode 100644
index 0000000000..0da13067b4
--- /dev/null
+++ b/cpukit/include/rtems/irq.h
@@ -0,0 +1,214 @@
+/*
+ *
+ * This include file describe the data structure and the functions implemented
+ * by rtems to write interrupt handlers.
+ *
+ * CopyRight (C) 1998 valette@crf.canon.fr
+ *
+ * This code is heavilly inspired by the public specification of STREAM V2
+ * that can be found at :
+ *
+ * <http://www.chorus.com/Documentation/index.html> by following
+ * the STREAM API Specification Document link.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_IRQ_H
+#define _RTEMS_IRQ_H
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * Type definition for RTEMS managed interrupts
+ */
+typedef unsigned char rtems_irq_prio;
+struct __rtems_irq_connect_data__; /* forward declaratiuon */
+
+typedef unsigned int rtems_irq_number;
+typedef void *rtems_irq_hdl_param;
+typedef void (*rtems_irq_hdl) (rtems_irq_hdl_param);
+typedef void (*rtems_irq_enable) (const struct __rtems_irq_connect_data__*);
+typedef void (*rtems_irq_disable) (const struct __rtems_irq_connect_data__*);
+typedef int (*rtems_irq_is_enabled) (const struct __rtems_irq_connect_data__*);
+
+typedef struct __rtems_irq_connect_data__ {
+ /*
+ * IRQ line
+ */
+ rtems_irq_number name;
+ /*
+ * handler. See comment on handler properties below in function prototype.
+ */
+ rtems_irq_hdl hdl;
+ /*
+ * Handler handle to store private data
+ */
+ rtems_irq_hdl_param handle;
+ /*
+ * function for enabling interrupts at device level (ONLY!).
+ * The BSP code will automatically enable it at i8259s level.
+ * RATIONALE : anyway such code has to exist in current driver code.
+ * It is usually called immediately AFTER connecting the interrupt handler.
+ * RTEMS may well need such a function when restoring normal interrupt
+ * processing after a debug session.
+ *
+ */
+ rtems_irq_enable on;
+ /*
+ * function for disabling interrupts at device level (ONLY!).
+ * The code will disable it at i8259s level. RATIONALE : anyway
+ * such code has to exist for clean shutdown. It is usually called
+ * BEFORE disconnecting the interrupt. RTEMS may well need such
+ * a function when disabling normal interrupt processing for
+ * a debug session. May well be a NOP function.
+ */
+ rtems_irq_disable off;
+ /*
+ * function enabling to know what interrupt may currently occur
+ * if someone manipulates the i8259s interrupt mask without care...
+ */
+ rtems_irq_is_enabled isOn;
+
+#ifdef BSP_SHARED_HANDLER_SUPPORT
+ /*
+ * Set to -1 for vectors forced to have only 1 handler
+ */
+ void *next_handler;
+#endif
+
+} rtems_irq_connect_data;
+
+typedef struct {
+ /*
+ * size of all the table fields (*Tbl) described below.
+ */
+ unsigned int irqNb;
+ /*
+ * Default handler used when disconnecting interrupts.
+ */
+ rtems_irq_connect_data defaultEntry;
+ /*
+ * Table containing initials/current value.
+ */
+ rtems_irq_connect_data* irqHdlTbl;
+ /*
+ * actual value of BSP_ISA_IRQ_VECTOR_BASE...
+ */
+ rtems_irq_number irqBase;
+ /*
+ * software priorities associated with interrupts.
+ * if (*irqPrio [i] > intrPrio [j] it means that
+ * interrupt handler hdl connected for interrupt name i
+ * will not be interrupted by the handler connected for interrupt j
+ * The interrupt source will be physically masked at i8259 level.
+ */
+ rtems_irq_prio* irqPrioTbl;
+} rtems_irq_global_settings;
+
+/*-------------------------------------------------------------------------+
+| Function Prototypes.
++--------------------------------------------------------------------------*/
+/*
+ * -------------------- RTEMS Single Irq Handler Mngt Routines ----------------
+ */
+/*
+ * function to connect a particular irq handler. This hanlder will NOT be called
+ * directly as the result of the corresponding interrupt. Instead, a RTEMS
+ * irq prologue will be called that will :
+ *
+ * 1) save the C scratch registers,
+ * 2) switch to a interrupt stack if the interrupt is not nested,
+ * 3) store the current i8259s' interrupt masks
+ * 4) modify them to disable the current interrupt at 8259 level (and may
+ * be others depending on software priorities)
+ * 5) aknowledge the i8259s',
+ * 6) demask the processor,
+ * 7) call the application handler
+ *
+ * As a result the hdl function provided
+ *
+ * a) can perfectly be written is C,
+ * b) may also well directly call the part of the RTEMS API that can be
+ * used from interrupt level,
+ * c) It only responsible for handling the jobs that need to be done at
+ * the device level including (aknowledging/re-enabling the interrupt at
+ * device level, getting the data,...)
+ *
+ * When returning from the function, the following will be performed by
+ * the RTEMS irq epilogue :
+ *
+ * 1) masks the interrupts again,
+ * 2) restore the original i8259s' interrupt masks
+ * 3) switch back on the orinal stack if needed,
+ * 4) perform rescheduling when necessary,
+ * 5) restore the C scratch registers...
+ * 6) restore initial execution flow
+ *
+ */
+int BSP_install_rtems_irq_handler (const rtems_irq_connect_data*);
+/*
+ * function to get the current RTEMS irq handler for ptr->name. It enables to
+ * define hanlder chain...
+ */
+int BSP_get_current_rtems_irq_handler (rtems_irq_connect_data* ptr);
+/*
+ * function to get disconnect the RTEMS irq handler for ptr->name.
+ * This function checks that the value given is the current one for safety reason.
+ * The user can use the previous function to get it.
+ */
+int BSP_remove_rtems_irq_handler (const rtems_irq_connect_data*);
+
+
+/*
+ * ----------------- RTEMS Shared Irq Handler Mngt Routines ----------------
+ */
+#ifdef BSP_SHARED_HANDLER_SUPPORT
+int BSP_install_rtems_shared_irq_handler (const rtems_irq_connect_data*);
+#endif
+
+/*
+ * ----------------- RTEMS Global Irq Handler Mngt Routines ----------------
+ */
+/*
+ * (Re) Initialize the RTEMS interrupt management.
+ *
+ * The result of calling this function will be the same as if each individual
+ * handler (config->irqHdlTbl[i].hdl) different from "config->defaultEntry.hdl"
+ * has been individualy connected via
+ * BSP_install_rtems_irq_handler(&config->irqHdlTbl[i])
+ * And each handler currently equal to config->defaultEntry.hdl
+ * has been previously disconnected via
+ * BSP_remove_rtems_irq_handler (&config->irqHdlTbl[i])
+ *
+ * This is to say that all information given will be used and not just
+ * only the space.
+ *
+ * CAUTION : the various table address contained in config will be used
+ * directly by the interrupt mangement code in order to save
+ * data size so they must stay valid after the call => they should
+ * not be modified or declared on a stack.
+ */
+
+int BSP_rtems_irq_mngt_set(rtems_irq_global_settings* config);
+
+/*
+ * (Re) get info on current RTEMS interrupt management.
+ */
+int BSP_rtems_irq_mngt_get(rtems_irq_global_settings**);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ASM */
+#endif /* _RTEMS_IRQ_H */
diff --git a/cpukit/include/rtems/pci.h b/cpukit/include/rtems/pci.h
new file mode 100644
index 0000000000..0b47d9275c
--- /dev/null
+++ b/cpukit/include/rtems/pci.h
@@ -0,0 +1,1236 @@
+/*
+ *
+ * PCI defines and function prototypes
+ * Copyright 1994, Drew Eckhardt
+ * Copyright 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *
+ * For more information, please consult the following manuals (look at
+ * http://www.pcisig.com/ for how to get them):
+ *
+ * PCI BIOS Specification
+ * PCI Local Bus Specification
+ * PCI to PCI Bridge Specification
+ * PCI System Design Guide
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_PCI_H
+#define _RTEMS_PCI_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Under PCI, each device has 256 bytes of configuration address space,
+ * of which the first 64 bytes are standardized as follows:
+ */
+#define PCI_VENDOR_ID 0x00 /* 16 bits */
+#define PCI_DEVICE_ID 0x02 /* 16 bits */
+
+#define PCI_COMMAND 0x04 /* 16 bits */
+#define PCI_COMMAND_IO 0x0001 /* Enable response in I/O space */
+#define PCI_COMMAND_MEMORY 0x0002 /* Enable response in Memory space */
+#define PCI_COMMAND_MASTER 0x0004 /* Enable bus mastering */
+#define PCI_COMMAND_SPECIAL 0x0008 /* Enable response to special cycles */
+#define PCI_COMMAND_INVALIDATE 0x0010 /* Use memory write and invalidate */
+#define PCI_COMMAND_VGA_PALETTE 0x0020 /* Enable palette snooping */
+#define PCI_COMMAND_PARITY 0x0040 /* Enable parity checking */
+#define PCI_COMMAND_WAIT 0x0080 /* Enable address/data stepping */
+#define PCI_COMMAND_SERR 0x0100 /* Enable SERR */
+#define PCI_COMMAND_FAST_BACK 0x0200 /* Enable back-to-back writes */
+
+#define PCI_STATUS 0x06 /* 16 bits */
+#define PCI_STATUS_66MHZ 0x0020 /* Support 66 Mhz PCI 2.1 bus */
+#define PCI_STATUS_UDF 0x0040 /* Support User Definable Features */
+#define PCI_STATUS_FAST_BACK 0x0080 /* Accept fast-back to back */
+#define PCI_STATUS_PARITY 0x0100 /* Detected parity error */
+#define PCI_STATUS_DEVSEL_MASK 0x0600 /* DEVSEL timing */
+#define PCI_STATUS_DEVSEL_FAST 0x0000
+#define PCI_STATUS_DEVSEL_MEDIUM 0x0200
+#define PCI_STATUS_DEVSEL_SLOW 0x0400
+#define PCI_STATUS_SIG_TARGET_ABORT 0x0800 /* Set on target abort */
+#define PCI_STATUS_REC_TARGET_ABORT 0x1000 /* Master ack of " */
+#define PCI_STATUS_REC_MASTER_ABORT 0x2000 /* Set on master abort */
+#define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /* Set when we drive SERR */
+#define PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */
+
+#define PCI_CLASS_REVISION 0x08 /* High 24 bits are class, low 8 revision */
+#define PCI_REVISION_ID 0x08 /* Revision ID */
+#define PCI_CLASS_PROG 0x09 /* Reg. Level Programming Interface */
+#define PCI_CLASS_DEVICE 0x0a /* Device class */
+#define PCI_CACHE_LINE_SIZE 0x0c /* 8 bits */
+#define PCI_LATENCY_TIMER 0x0d /* 8 bits */
+
+#define PCI_HEADER_TYPE 0x0e /* 8 bits */
+#define PCI_HEADER_TYPE_NORMAL 0
+#define PCI_HEADER_TYPE_BRIDGE 1
+#define PCI_HEADER_TYPE_CARDBUS 2
+
+#define PCI_BIST 0x0f /* 8 bits */
+#define PCI_BIST_CODE_MASK 0x0f /* Return result */
+#define PCI_BIST_START 0x40 /* 1 to start BIST, 2 secs or less */
+#define PCI_BIST_CAPABLE 0x80 /* 1 if BIST capable */
+
+/*
+ * Base addresses specify locations in memory or I/O space.
+ * Decoded size can be determined by writing a value of
+ * 0xffffffff to the register, and reading it back. Only
+ * 1 bits are decoded.
+ */
+#define PCI_BASE_ADDRESS_0 0x10 /* 32 bits */
+#define PCI_BASE_ADDRESS_1 0x14 /* 32 bits [htype 0,1 only] */
+#define PCI_BASE_ADDRESS_2 0x18 /* 32 bits [htype 0 only] */
+#define PCI_BASE_ADDRESS_3 0x1c /* 32 bits */
+#define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */
+#define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */
+#define PCI_BASE_ADDRESS_SPACE 0x01 /* 0 = memory, 1 = I/O */
+#define PCI_BASE_ADDRESS_SPACE_IO 0x01
+#define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00
+#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06
+#define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00 /* 32 bit address */
+#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M */
+#define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */
+#define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */
+#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL)
+#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL)
+/* bit 1 is reserved if address_space = 1 */
+
+/* Header type 0 (normal devices) */
+#define PCI_CARDBUS_CIS 0x28
+#define PCI_SUBSYSTEM_VENDOR_ID 0x2c
+#define PCI_SUBSYSTEM_ID 0x2e
+#define PCI_ROM_ADDRESS 0x30/* Bits 31..11 address, 10..1 reserved */
+#define PCI_ROM_ADDRESS_ENABLE 0x01
+#define PCI_ROM_ADDRESS_MASK (~0x7ffUL)
+
+/* 0x34-0x3b are reserved */
+#define PCI_INTERRUPT_LINE 0x3c /* 8 bits */
+#define PCI_INTERRUPT_PIN 0x3d /* 8 bits */
+#define PCI_MIN_GNT 0x3e /* 8 bits */
+#define PCI_MAX_LAT 0x3f /* 8 bits */
+
+/* Header type 1 (PCI-to-PCI bridges) */
+#define PCI_PRIMARY_BUS 0x18 /* Primary bus number */
+#define PCI_SECONDARY_BUS 0x19 /* Secondary bus number */
+#define PCI_SUBORDINATE_BUS 0x1a /* Highest bus number behind the bridge */
+#define PCI_SEC_LATENCY_TIMER 0x1b /* Latency timer for secondary interface */
+#define PCI_IO_BASE 0x1c /* I/O range behind the bridge */
+#define PCI_IO_LIMIT 0x1d
+#define PCI_IO_RANGE_TYPE_MASK 0x0f /* I/O bridging type */
+#define PCI_IO_RANGE_TYPE_16 0x00
+#define PCI_IO_RANGE_TYPE_32 0x01
+#define PCI_IO_RANGE_MASK ~0x0f
+
+#define PCI_SEC_STATUS 0x1e /* Secondary status register, only bit 14 used */
+
+#define PCI_MEMORY_BASE 0x20 /* Memory range behind */
+#define PCI_MEMORY_LIMIT 0x22
+#define PCI_MEMORY_RANGE_TYPE_MASK 0x0f
+#define PCI_MEMORY_RANGE_MASK ~0x0f
+#define PCI_PREF_MEMORY_BASE 0x24 /* Prefetchable memory range behind */
+#define PCI_PREF_MEMORY_LIMIT 0x26
+#define PCI_PREF_RANGE_TYPE_MASK 0x0f
+#define PCI_PREF_RANGE_TYPE_32 0x00
+#define PCI_PREF_RANGE_TYPE_64 0x01
+#define PCI_PREF_RANGE_MASK ~0x0f
+#define PCI_PREF_BASE_UPPER32 0x28 /* Upper half of prefetchable memory */
+#define PCI_PREF_LIMIT_UPPER32 0x2c
+#define PCI_IO_BASE_UPPER16 0x30 /* Upper half of I/O addresses */
+#define PCI_IO_LIMIT_UPPER16 0x32
+/* 0x34-0x3b is reserved */
+#define PCI_ROM_ADDRESS1 0x38 /* Same as PCI_ROM_ADDRESS, but for htype 1 */
+/* 0x3c-0x3d are same as for htype 0 */
+#define PCI_BRIDGE_CONTROL 0x3e
+#define PCI_BRIDGE_CTL_PARITY 0x01 /* Enable parity detection on secondary interface */
+#define PCI_BRIDGE_CTL_SERR 0x02 /* The same for SERR forwarding */
+#define PCI_BRIDGE_CTL_NO_ISA 0x04 /* Disable bridging of ISA ports */
+#define PCI_BRIDGE_CTL_VGA 0x08 /* Forward VGA addresses */
+#define PCI_BRIDGE_CTL_MASTER_ABORT 0x20 /* Report master aborts */
+#define PCI_BRIDGE_CTL_BUS_RESET 0x40 /* Secondary bus reset */
+#define PCI_BRIDGE_CTL_FAST_BACK 0x80 /* Fast Back2Back enabled */
+ /* on secondary interface */
+
+/* Header type 2 (CardBus bridges) */
+/* 0x14-0x15 reserved */
+#define PCI_CB_SEC_STATUS 0x16 /* Secondary status */
+#define PCI_CB_PRIMARY_BUS 0x18 /* PCI bus number */
+#define PCI_CB_CARD_BUS 0x19 /* CardBus bus number */
+#define PCI_CB_SUBORDINATE_BUS 0x1a /* Subordinate bus number */
+#define PCI_CB_LATENCY_TIMER 0x1b /* CardBus latency timer */
+#define PCI_CB_MEMORY_BASE_0 0x1c
+#define PCI_CB_MEMORY_LIMIT_0 0x20
+#define PCI_CB_MEMORY_BASE_1 0x24
+#define PCI_CB_MEMORY_LIMIT_1 0x28
+#define PCI_CB_IO_BASE_0 0x2c
+#define PCI_CB_IO_BASE_0_HI 0x2e
+#define PCI_CB_IO_LIMIT_0 0x30
+#define PCI_CB_IO_LIMIT_0_HI 0x32
+#define PCI_CB_IO_BASE_1 0x34
+#define PCI_CB_IO_BASE_1_HI 0x36
+#define PCI_CB_IO_LIMIT_1 0x38
+#define PCI_CB_IO_LIMIT_1_HI 0x3a
+#define PCI_CB_IO_RANGE_MASK ~0x03
+/* 0x3c-0x3d are same as for htype 0 */
+
+#define PCI_CB_BRIDGE_CONTROL 0x3e
+#define PCI_CB_BRIDGE_CTL_PARITY 0x01 /* Similar to standard bridge */
+ /* control register */
+#define PCI_CB_BRIDGE_CTL_SERR 0x02
+#define PCI_CB_BRIDGE_CTL_ISA 0x04
+#define PCI_CB_BRIDGE_CTL_VGA 0x08
+#define PCI_CB_BRIDGE_CTL_MASTER_ABORT 0x20
+#define PCI_CB_BRIDGE_CTL_CB_RESET 0x40 /* CardBus reset */
+#define PCI_CB_BRIDGE_CTL_16BIT_INT 0x80 /* Enable interrupt for */
+ /* 16-bit cards */
+#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 0x100 /* Prefetch enable for */
+ /* both memory regions */
+#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM1 0x200
+#define PCI_CB_BRIDGE_CTL_POST_WRITES 0x400
+
+#define PCI_CB_SUBSYSTEM_VENDOR_ID 0x40
+#define PCI_CB_SUBSYSTEM_ID 0x42
+
+/* 16-bit PC Card legacy mode base address (ExCa) */
+#define PCI_CB_LEGACY_MODE_BASE 0x44
+
+/* 0x48-0x7f reserved */
+
+/* Device classes and subclasses */
+
+#define PCI_CLASS_NOT_DEFINED 0x0000
+#define PCI_CLASS_NOT_DEFINED_VGA 0x0001
+
+#define PCI_BASE_CLASS_STORAGE 0x01
+#define PCI_CLASS_STORAGE_SCSI 0x0100
+#define PCI_CLASS_STORAGE_IDE 0x0101
+#define PCI_CLASS_STORAGE_FLOPPY 0x0102
+#define PCI_CLASS_STORAGE_IPI 0x0103
+#define PCI_CLASS_STORAGE_RAID 0x0104
+#define PCI_CLASS_STORAGE_OTHER 0x0180
+
+#define PCI_BASE_CLASS_NETWORK 0x02
+#define PCI_CLASS_NETWORK_ETHERNET 0x0200
+#define PCI_CLASS_NETWORK_TOKEN_RING 0x0201
+#define PCI_CLASS_NETWORK_FDDI 0x0202
+#define PCI_CLASS_NETWORK_ATM 0x0203
+#define PCI_CLASS_NETWORK_OTHER 0x0280
+
+#define PCI_BASE_CLASS_DISPLAY 0x03
+#define PCI_CLASS_DISPLAY_VGA 0x0300
+#define PCI_CLASS_DISPLAY_XGA 0x0301
+#define PCI_CLASS_DISPLAY_OTHER 0x0380
+
+#define PCI_BASE_CLASS_MULTIMEDIA 0x04
+#define PCI_CLASS_MULTIMEDIA_VIDEO 0x0400
+#define PCI_CLASS_MULTIMEDIA_AUDIO 0x0401
+#define PCI_CLASS_MULTIMEDIA_OTHER 0x0480
+
+#define PCI_BASE_CLASS_MEMORY 0x05
+#define PCI_CLASS_MEMORY_RAM 0x0500
+#define PCI_CLASS_MEMORY_FLASH 0x0501
+#define PCI_CLASS_MEMORY_OTHER 0x0580
+
+#define PCI_BASE_CLASS_BRIDGE 0x06
+#define PCI_CLASS_BRIDGE_HOST 0x0600
+#define PCI_CLASS_BRIDGE_ISA 0x0601
+#define PCI_CLASS_BRIDGE_EISA 0x0602
+#define PCI_CLASS_BRIDGE_MC 0x0603
+#define PCI_CLASS_BRIDGE_PCI 0x0604
+#define PCI_CLASS_BRIDGE_PCMCIA 0x0605
+#define PCI_CLASS_BRIDGE_NUBUS 0x0606
+#define PCI_CLASS_BRIDGE_CARDBUS 0x0607
+#define PCI_CLASS_BRIDGE_OTHER 0x0680
+
+#define PCI_BASE_CLASS_COMMUNICATION 0x07
+#define PCI_CLASS_COMMUNICATION_SERIAL 0x0700
+#define PCI_CLASS_COMMUNICATION_PARALLEL 0x0701
+#define PCI_CLASS_COMMUNICATION_OTHER 0x0780
+
+#define PCI_BASE_CLASS_SYSTEM 0x08
+#define PCI_CLASS_SYSTEM_PIC 0x0800
+#define PCI_CLASS_SYSTEM_DMA 0x0801
+#define PCI_CLASS_SYSTEM_TIMER 0x0802
+#define PCI_CLASS_SYSTEM_RTC 0x0803
+#define PCI_CLASS_SYSTEM_OTHER 0x0880
+
+#define PCI_BASE_CLASS_INPUT 0x09
+#define PCI_CLASS_INPUT_KEYBOARD 0x0900
+#define PCI_CLASS_INPUT_PEN 0x0901
+#define PCI_CLASS_INPUT_MOUSE 0x0902
+#define PCI_CLASS_INPUT_OTHER 0x0980
+
+#define PCI_BASE_CLASS_DOCKING 0x0a
+#define PCI_CLASS_DOCKING_GENERIC 0x0a00
+#define PCI_CLASS_DOCKING_OTHER 0x0a01
+
+#define PCI_BASE_CLASS_PROCESSOR 0x0b
+#define PCI_CLASS_PROCESSOR_386 0x0b00
+#define PCI_CLASS_PROCESSOR_486 0x0b01
+#define PCI_CLASS_PROCESSOR_PENTIUM 0x0b02
+#define PCI_CLASS_PROCESSOR_ALPHA 0x0b10
+#define PCI_CLASS_PROCESSOR_POWERPC 0x0b20
+#define PCI_CLASS_PROCESSOR_CO 0x0b40
+
+#define PCI_BASE_CLASS_SERIAL 0x0c
+#define PCI_CLASS_SERIAL_FIREWIRE 0x0c00
+#define PCI_CLASS_SERIAL_ACCESS 0x0c01
+#define PCI_CLASS_SERIAL_SSA 0x0c02
+#define PCI_CLASS_SERIAL_USB 0x0c03
+#define PCI_CLASS_SERIAL_FIBER 0x0c04
+
+#define PCI_CLASS_OTHERS 0xff
+
+/*
+ * Vendor and card ID's: sort these numerically according to vendor
+ * (and according to card ID within vendor). Send all updates to
+ * <linux-pcisupport@cck.uni-kl.de>.
+ */
+#define PCI_VENDOR_ID_COMPAQ 0x0e11
+#define PCI_DEVICE_ID_COMPAQ_1280 0x3033
+#define PCI_DEVICE_ID_COMPAQ_TRIFLEX 0x4000
+#define PCI_DEVICE_ID_COMPAQ_SMART2P 0xae10
+#define PCI_DEVICE_ID_COMPAQ_NETEL100 0xae32
+#define PCI_DEVICE_ID_COMPAQ_NETEL10 0xae34
+#define PCI_DEVICE_ID_COMPAQ_NETFLEX3I 0xae35
+#define PCI_DEVICE_ID_COMPAQ_NETEL100D 0xae40
+#define PCI_DEVICE_ID_COMPAQ_NETEL100PI 0xae43
+#define PCI_DEVICE_ID_COMPAQ_NETEL100I 0xb011
+#define PCI_DEVICE_ID_COMPAQ_THUNDER 0xf130
+#define PCI_DEVICE_ID_COMPAQ_NETFLEX3B 0xf150
+
+#define PCI_VENDOR_ID_NCR 0x1000
+#define PCI_DEVICE_ID_NCR_53C810 0x0001
+#define PCI_DEVICE_ID_NCR_53C820 0x0002
+#define PCI_DEVICE_ID_NCR_53C825 0x0003
+#define PCI_DEVICE_ID_NCR_53C815 0x0004
+#define PCI_DEVICE_ID_NCR_53C860 0x0006
+#define PCI_DEVICE_ID_NCR_53C896 0x000b
+#define PCI_DEVICE_ID_NCR_53C895 0x000c
+#define PCI_DEVICE_ID_NCR_53C885 0x000d
+#define PCI_DEVICE_ID_NCR_53C875 0x000f
+#define PCI_DEVICE_ID_NCR_53C875J 0x008f
+
+#define PCI_VENDOR_ID_ATI 0x1002
+#define PCI_DEVICE_ID_ATI_68800 0x4158
+#define PCI_DEVICE_ID_ATI_215CT222 0x4354
+#define PCI_DEVICE_ID_ATI_210888CX 0x4358
+#define PCI_DEVICE_ID_ATI_215GB 0x4742
+#define PCI_DEVICE_ID_ATI_215GD 0x4744
+#define PCI_DEVICE_ID_ATI_215GI 0x4749
+#define PCI_DEVICE_ID_ATI_215GP 0x4750
+#define PCI_DEVICE_ID_ATI_215GQ 0x4751
+#define PCI_DEVICE_ID_ATI_215GT 0x4754
+#define PCI_DEVICE_ID_ATI_215GTB 0x4755
+#define PCI_DEVICE_ID_ATI_210888GX 0x4758
+#define PCI_DEVICE_ID_ATI_215LG 0x4c47
+#define PCI_DEVICE_ID_ATI_264LT 0x4c54
+#define PCI_DEVICE_ID_ATI_264VT 0x5654
+
+#define PCI_VENDOR_ID_VLSI 0x1004
+#define PCI_DEVICE_ID_VLSI_82C592 0x0005
+#define PCI_DEVICE_ID_VLSI_82C593 0x0006
+#define PCI_DEVICE_ID_VLSI_82C594 0x0007
+#define PCI_DEVICE_ID_VLSI_82C597 0x0009
+#define PCI_DEVICE_ID_VLSI_82C541 0x000c
+#define PCI_DEVICE_ID_VLSI_82C543 0x000d
+#define PCI_DEVICE_ID_VLSI_82C532 0x0101
+#define PCI_DEVICE_ID_VLSI_82C534 0x0102
+#define PCI_DEVICE_ID_VLSI_82C535 0x0104
+#define PCI_DEVICE_ID_VLSI_82C147 0x0105
+#define PCI_DEVICE_ID_VLSI_VAS96011 0x0702
+
+#define PCI_VENDOR_ID_ADL 0x1005
+#define PCI_DEVICE_ID_ADL_2301 0x2301
+
+#define PCI_VENDOR_ID_NS 0x100b
+#define PCI_DEVICE_ID_NS_87415 0x0002
+#define PCI_DEVICE_ID_NS_87410 0xd001
+
+#define PCI_VENDOR_ID_TSENG 0x100c
+#define PCI_DEVICE_ID_TSENG_W32P_2 0x3202
+#define PCI_DEVICE_ID_TSENG_W32P_b 0x3205
+#define PCI_DEVICE_ID_TSENG_W32P_c 0x3206
+#define PCI_DEVICE_ID_TSENG_W32P_d 0x3207
+#define PCI_DEVICE_ID_TSENG_ET6000 0x3208
+
+#define PCI_VENDOR_ID_WEITEK 0x100e
+#define PCI_DEVICE_ID_WEITEK_P9000 0x9001
+#define PCI_DEVICE_ID_WEITEK_P9100 0x9100
+
+#define PCI_VENDOR_ID_DEC 0x1011
+#define PCI_DEVICE_ID_DEC_BRD 0x0001
+#define PCI_DEVICE_ID_DEC_TULIP 0x0002
+#define PCI_DEVICE_ID_DEC_TGA 0x0004
+#define PCI_DEVICE_ID_DEC_TULIP_FAST 0x0009
+#define PCI_DEVICE_ID_DEC_TGA2 0x000D
+#define PCI_DEVICE_ID_DEC_FDDI 0x000F
+#define PCI_DEVICE_ID_DEC_TULIP_PLUS 0x0014
+#define PCI_DEVICE_ID_DEC_21142 0x0019
+#define PCI_DEVICE_ID_DEC_21052 0x0021
+#define PCI_DEVICE_ID_DEC_21150 0x0022
+#define PCI_DEVICE_ID_DEC_21152 0x0024
+
+#define PCI_VENDOR_ID_CIRRUS 0x1013
+#define PCI_DEVICE_ID_CIRRUS_7548 0x0038
+#define PCI_DEVICE_ID_CIRRUS_5430 0x00a0
+#define PCI_DEVICE_ID_CIRRUS_5434_4 0x00a4
+#define PCI_DEVICE_ID_CIRRUS_5434_8 0x00a8
+#define PCI_DEVICE_ID_CIRRUS_5436 0x00ac
+#define PCI_DEVICE_ID_CIRRUS_5446 0x00b8
+#define PCI_DEVICE_ID_CIRRUS_5480 0x00bc
+#define PCI_DEVICE_ID_CIRRUS_5464 0x00d4
+#define PCI_DEVICE_ID_CIRRUS_5465 0x00d6
+#define PCI_DEVICE_ID_CIRRUS_6729 0x1100
+#define PCI_DEVICE_ID_CIRRUS_6832 0x1110
+#define PCI_DEVICE_ID_CIRRUS_7542 0x1200
+#define PCI_DEVICE_ID_CIRRUS_7543 0x1202
+#define PCI_DEVICE_ID_CIRRUS_7541 0x1204
+
+#define PCI_VENDOR_ID_IBM 0x1014
+#define PCI_DEVICE_ID_IBM_FIRE_CORAL 0x000a
+#define PCI_DEVICE_ID_IBM_TR 0x0018
+#define PCI_DEVICE_ID_IBM_82G2675 0x001d
+#define PCI_DEVICE_ID_IBM_MCA 0x0020
+#define PCI_DEVICE_ID_IBM_82351 0x0022
+#define PCI_DEVICE_ID_IBM_SERVERAID 0x002e
+#define PCI_DEVICE_ID_IBM_TR_WAKE 0x003e
+#define PCI_DEVICE_ID_IBM_MPIC 0x0046
+#define PCI_DEVICE_ID_IBM_3780IDSP 0x007d
+#define PCI_DEVICE_ID_IBM_MPIC_2 0xffff
+
+#define PCI_VENDOR_ID_WD 0x101c
+#define PCI_DEVICE_ID_WD_7197 0x3296
+
+#define PCI_VENDOR_ID_AMD 0x1022
+#define PCI_DEVICE_ID_AMD_LANCE 0x2000
+#define PCI_DEVICE_ID_AMD_SCSI 0x2020
+
+#define PCI_VENDOR_ID_TRIDENT 0x1023
+#define PCI_DEVICE_ID_TRIDENT_9397 0x9397
+#define PCI_DEVICE_ID_TRIDENT_9420 0x9420
+#define PCI_DEVICE_ID_TRIDENT_9440 0x9440
+#define PCI_DEVICE_ID_TRIDENT_9660 0x9660
+#define PCI_DEVICE_ID_TRIDENT_9750 0x9750
+
+#define PCI_VENDOR_ID_AI 0x1025
+#define PCI_DEVICE_ID_AI_M1435 0x1435
+
+#define PCI_VENDOR_ID_MATROX 0x102B
+#define PCI_DEVICE_ID_MATROX_MGA_2 0x0518
+#define PCI_DEVICE_ID_MATROX_MIL 0x0519
+#define PCI_DEVICE_ID_MATROX_MYS 0x051A
+#define PCI_DEVICE_ID_MATROX_MIL_2 0x051b
+#define PCI_DEVICE_ID_MATROX_MIL_2_AGP 0x051f
+#define PCI_DEVICE_ID_MATROX_MGA_IMP 0x0d10
+
+#define PCI_VENDOR_ID_CT 0x102c
+#define PCI_DEVICE_ID_CT_65545 0x00d8
+#define PCI_DEVICE_ID_CT_65548 0x00dc
+#define PCI_DEVICE_ID_CT_65550 0x00e0
+#define PCI_DEVICE_ID_CT_65554 0x00e4
+#define PCI_DEVICE_ID_CT_65555 0x00e5
+
+#define PCI_VENDOR_ID_MIRO 0x1031
+#define PCI_DEVICE_ID_MIRO_36050 0x5601
+
+#define PCI_VENDOR_ID_NEC 0x1033
+#define PCI_DEVICE_ID_NEC_PCX2 0x0046
+
+#define PCI_VENDOR_ID_FD 0x1036
+#define PCI_DEVICE_ID_FD_36C70 0x0000
+
+#define PCI_VENDOR_ID_SI 0x1039
+#define PCI_DEVICE_ID_SI_5591_AGP 0x0001
+#define PCI_DEVICE_ID_SI_6202 0x0002
+#define PCI_DEVICE_ID_SI_503 0x0008
+#define PCI_DEVICE_ID_SI_ACPI 0x0009
+#define PCI_DEVICE_ID_SI_5597_VGA 0x0200
+#define PCI_DEVICE_ID_SI_6205 0x0205
+#define PCI_DEVICE_ID_SI_501 0x0406
+#define PCI_DEVICE_ID_SI_496 0x0496
+#define PCI_DEVICE_ID_SI_601 0x0601
+#define PCI_DEVICE_ID_SI_5107 0x5107
+#define PCI_DEVICE_ID_SI_5511 0x5511
+#define PCI_DEVICE_ID_SI_5513 0x5513
+#define PCI_DEVICE_ID_SI_5571 0x5571
+#define PCI_DEVICE_ID_SI_5591 0x5591
+#define PCI_DEVICE_ID_SI_5597 0x5597
+#define PCI_DEVICE_ID_SI_7001 0x7001
+
+#define PCI_VENDOR_ID_HP 0x103c
+#define PCI_DEVICE_ID_HP_J2585A 0x1030
+#define PCI_DEVICE_ID_HP_J2585B 0x1031
+
+#define PCI_VENDOR_ID_PCTECH 0x1042
+#define PCI_DEVICE_ID_PCTECH_RZ1000 0x1000
+#define PCI_DEVICE_ID_PCTECH_RZ1001 0x1001
+#define PCI_DEVICE_ID_PCTECH_SAMURAI_0 0x3000
+#define PCI_DEVICE_ID_PCTECH_SAMURAI_1 0x3010
+#define PCI_DEVICE_ID_PCTECH_SAMURAI_IDE 0x3020
+
+#define PCI_VENDOR_ID_DPT 0x1044
+#define PCI_DEVICE_ID_DPT 0xa400
+
+#define PCI_VENDOR_ID_OPTI 0x1045
+#define PCI_DEVICE_ID_OPTI_92C178 0xc178
+#define PCI_DEVICE_ID_OPTI_82C557 0xc557
+#define PCI_DEVICE_ID_OPTI_82C558 0xc558
+#define PCI_DEVICE_ID_OPTI_82C621 0xc621
+#define PCI_DEVICE_ID_OPTI_82C700 0xc700
+#define PCI_DEVICE_ID_OPTI_82C701 0xc701
+#define PCI_DEVICE_ID_OPTI_82C814 0xc814
+#define PCI_DEVICE_ID_OPTI_82C822 0xc822
+#define PCI_DEVICE_ID_OPTI_82C825 0xd568
+
+#define PCI_VENDOR_ID_SGS 0x104a
+#define PCI_DEVICE_ID_SGS_2000 0x0008
+#define PCI_DEVICE_ID_SGS_1764 0x0009
+
+#define PCI_VENDOR_ID_BUSLOGIC 0x104B
+#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140
+#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040
+#define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130
+
+#define PCI_VENDOR_ID_TI 0x104c
+#define PCI_DEVICE_ID_TI_TVP4010 0x3d04
+#define PCI_DEVICE_ID_TI_TVP4020 0x3d07
+#define PCI_DEVICE_ID_TI_PCI1130 0xac12
+#define PCI_DEVICE_ID_TI_PCI1031 0xac13
+#define PCI_DEVICE_ID_TI_PCI1131 0xac15
+#define PCI_DEVICE_ID_TI_PCI1250 0xac16
+#define PCI_DEVICE_ID_TI_PCI1220 0xac17
+
+#define PCI_VENDOR_ID_OAK 0x104e
+#define PCI_DEVICE_ID_OAK_OTI107 0x0107
+
+#define PCI_VENDOR_ID_WINBOND2 0x1050
+#define PCI_DEVICE_ID_WINBOND2_89C940 0x0940
+
+#define PCI_VENDOR_ID_MOTOROLA 0x1057
+#define PCI_DEVICE_ID_MOTOROLA_MPC105 0x0001
+#define PCI_DEVICE_ID_MOTOROLA_MPC106 0x0002
+#define PCI_DEVICE_ID_MOTOROLA_RAVEN 0x4801
+#define PCI_DEVICE_ID_MOTOROLA_HAWK 0x4803
+
+#define PCI_VENDOR_ID_PROMISE 0x105a
+#define PCI_DEVICE_ID_PROMISE_20246 0x4d33
+#define PCI_DEVICE_ID_PROMISE_5300 0x5300
+
+#define PCI_VENDOR_ID_N9 0x105d
+#define PCI_DEVICE_ID_N9_I128 0x2309
+#define PCI_DEVICE_ID_N9_I128_2 0x2339
+#define PCI_DEVICE_ID_N9_I128_T2R 0x493d
+
+#define PCI_VENDOR_ID_UMC 0x1060
+#define PCI_DEVICE_ID_UMC_UM8673F 0x0101
+#define PCI_DEVICE_ID_UMC_UM8891A 0x0891
+#define PCI_DEVICE_ID_UMC_UM8886BF 0x673a
+#define PCI_DEVICE_ID_UMC_UM8886A 0x886a
+#define PCI_DEVICE_ID_UMC_UM8881F 0x8881
+#define PCI_DEVICE_ID_UMC_UM8886F 0x8886
+#define PCI_DEVICE_ID_UMC_UM9017F 0x9017
+#define PCI_DEVICE_ID_UMC_UM8886N 0xe886
+#define PCI_DEVICE_ID_UMC_UM8891N 0xe891
+
+#define PCI_VENDOR_ID_X 0x1061
+#define PCI_DEVICE_ID_X_AGX016 0x0001
+
+#define PCI_VENDOR_ID_PICOP 0x1066
+#define PCI_DEVICE_ID_PICOP_PT86C52X 0x0001
+#define PCI_DEVICE_ID_PICOP_PT80C524 0x8002
+
+#define PCI_VENDOR_ID_APPLE 0x106b
+#define PCI_DEVICE_ID_APPLE_BANDIT 0x0001
+#define PCI_DEVICE_ID_APPLE_GC 0x0002
+#define PCI_DEVICE_ID_APPLE_HYDRA 0x000e
+
+#define PCI_VENDOR_ID_NEXGEN 0x1074
+#define PCI_DEVICE_ID_NEXGEN_82C501 0x4e78
+
+#define PCI_VENDOR_ID_QLOGIC 0x1077
+#define PCI_DEVICE_ID_QLOGIC_ISP1020 0x1020
+#define PCI_DEVICE_ID_QLOGIC_ISP1022 0x1022
+
+#define PCI_VENDOR_ID_CYRIX 0x1078
+#define PCI_DEVICE_ID_CYRIX_5510 0x0000
+#define PCI_DEVICE_ID_CYRIX_PCI_MASTER 0x0001
+#define PCI_DEVICE_ID_CYRIX_5520 0x0002
+#define PCI_DEVICE_ID_CYRIX_5530_LEGACY 0x0100
+#define PCI_DEVICE_ID_CYRIX_5530_SMI 0x0101
+#define PCI_DEVICE_ID_CYRIX_5530_IDE 0x0102
+#define PCI_DEVICE_ID_CYRIX_5530_AUDIO 0x0103
+#define PCI_DEVICE_ID_CYRIX_5530_VIDEO 0x0104
+
+#define PCI_VENDOR_ID_LEADTEK 0x107d
+#define PCI_DEVICE_ID_LEADTEK_805 0x0000
+
+#define PCI_VENDOR_ID_CONTAQ 0x1080
+#define PCI_DEVICE_ID_CONTAQ_82C599 0x0600
+#define PCI_DEVICE_ID_CONTAQ_82C693 0xc693
+
+#define PCI_VENDOR_ID_FOREX 0x1083
+
+#define PCI_VENDOR_ID_OLICOM 0x108d
+#define PCI_DEVICE_ID_OLICOM_OC3136 0x0001
+#define PCI_DEVICE_ID_OLICOM_OC2315 0x0011
+#define PCI_DEVICE_ID_OLICOM_OC2325 0x0012
+#define PCI_DEVICE_ID_OLICOM_OC2183 0x0013
+#define PCI_DEVICE_ID_OLICOM_OC2326 0x0014
+#define PCI_DEVICE_ID_OLICOM_OC6151 0x0021
+
+#define PCI_VENDOR_ID_SUN 0x108e
+#define PCI_DEVICE_ID_SUN_EBUS 0x1000
+#define PCI_DEVICE_ID_SUN_HAPPYMEAL 0x1001
+#define PCI_DEVICE_ID_SUN_SIMBA 0x5000
+#define PCI_DEVICE_ID_SUN_PBM 0x8000
+#define PCI_DEVICE_ID_SUN_SABRE 0xa000
+
+#define PCI_VENDOR_ID_CMD 0x1095
+#define PCI_DEVICE_ID_CMD_640 0x0640
+#define PCI_DEVICE_ID_CMD_643 0x0643
+#define PCI_DEVICE_ID_CMD_646 0x0646
+#define PCI_DEVICE_ID_CMD_647 0x0647
+#define PCI_DEVICE_ID_CMD_670 0x0670
+
+#define PCI_VENDOR_ID_VISION 0x1098
+#define PCI_DEVICE_ID_VISION_QD8500 0x0001
+#define PCI_DEVICE_ID_VISION_QD8580 0x0002
+
+#define PCI_VENDOR_ID_BROOKTREE 0x109e
+#define PCI_DEVICE_ID_BROOKTREE_848 0x0350
+#define PCI_DEVICE_ID_BROOKTREE_849A 0x0351
+#define PCI_DEVICE_ID_BROOKTREE_8474 0x8474
+
+#define PCI_VENDOR_ID_SIERRA 0x10a8
+#define PCI_DEVICE_ID_SIERRA_STB 0x0000
+
+#define PCI_VENDOR_ID_ACC 0x10aa
+#define PCI_DEVICE_ID_ACC_2056 0x0000
+
+#define PCI_VENDOR_ID_WINBOND 0x10ad
+#define PCI_DEVICE_ID_WINBOND_83769 0x0001
+#define PCI_DEVICE_ID_WINBOND_82C105 0x0105
+#define PCI_DEVICE_ID_WINBOND_83C553 0x0565
+
+#define PCI_VENDOR_ID_DATABOOK 0x10b3
+#define PCI_DEVICE_ID_DATABOOK_87144 0xb106
+
+#define PCI_VENDOR_ID_PLX 0x10b5
+#define PCI_DEVICE_ID_PLX_9050 0x9050
+#define PCI_DEVICE_ID_PLX_9060 0x9060
+#define PCI_DEVICE_ID_PLX_9060ES 0x906E
+#define PCI_DEVICE_ID_PLX_9060SD 0x906D
+#define PCI_DEVICE_ID_PLX_9080 0x9080
+
+#define PCI_VENDOR_ID_MADGE 0x10b6
+#define PCI_DEVICE_ID_MADGE_MK2 0x0002
+#define PCI_DEVICE_ID_MADGE_C155S 0x1001
+
+#define PCI_VENDOR_ID_3COM 0x10b7
+#define PCI_DEVICE_ID_3COM_3C339 0x3390
+#define PCI_DEVICE_ID_3COM_3C590 0x5900
+#define PCI_DEVICE_ID_3COM_3C595TX 0x5950
+#define PCI_DEVICE_ID_3COM_3C595T4 0x5951
+#define PCI_DEVICE_ID_3COM_3C595MII 0x5952
+#define PCI_DEVICE_ID_3COM_3C900TPO 0x9000
+#define PCI_DEVICE_ID_3COM_3C900COMBO 0x9001
+#define PCI_DEVICE_ID_3COM_3C905TX 0x9050
+#define PCI_DEVICE_ID_3COM_3C905T4 0x9051
+#define PCI_DEVICE_ID_3COM_3C905B_TX 0x9055
+
+#define PCI_VENDOR_ID_SMC 0x10b8
+#define PCI_DEVICE_ID_SMC_EPIC100 0x0005
+
+#define PCI_VENDOR_ID_AL 0x10b9
+#define PCI_DEVICE_ID_AL_M1445 0x1445
+#define PCI_DEVICE_ID_AL_M1449 0x1449
+#define PCI_DEVICE_ID_AL_M1451 0x1451
+#define PCI_DEVICE_ID_AL_M1461 0x1461
+#define PCI_DEVICE_ID_AL_M1489 0x1489
+#define PCI_DEVICE_ID_AL_M1511 0x1511
+#define PCI_DEVICE_ID_AL_M1513 0x1513
+#define PCI_DEVICE_ID_AL_M1521 0x1521
+#define PCI_DEVICE_ID_AL_M1523 0x1523
+#define PCI_DEVICE_ID_AL_M1531 0x1531
+#define PCI_DEVICE_ID_AL_M1533 0x1533
+#define PCI_DEVICE_ID_AL_M3307 0x3307
+#define PCI_DEVICE_ID_AL_M4803 0x5215
+#define PCI_DEVICE_ID_AL_M5219 0x5219
+#define PCI_DEVICE_ID_AL_M5229 0x5229
+#define PCI_DEVICE_ID_AL_M5237 0x5237
+#define PCI_DEVICE_ID_AL_M7101 0x7101
+
+#define PCI_VENDOR_ID_MITSUBISHI 0x10ba
+
+#define PCI_VENDOR_ID_SURECOM 0x10bd
+#define PCI_DEVICE_ID_SURECOM_NE34 0x0e34
+
+#define PCI_VENDOR_ID_NEOMAGIC 0x10c8
+#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_NM2070 0x0001
+#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128V 0x0002
+#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128ZV 0x0003
+#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_NM2160 0x0004
+
+#define PCI_VENDOR_ID_ASP 0x10cd
+#define PCI_DEVICE_ID_ASP_ABP940 0x1200
+#define PCI_DEVICE_ID_ASP_ABP940U 0x1300
+#define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
+
+#define PCI_VENDOR_ID_MACRONIX 0x10d9
+#define PCI_DEVICE_ID_MACRONIX_MX98713 0x0512
+#define PCI_DEVICE_ID_MACRONIX_MX987x5 0x0531
+
+#define PCI_VENDOR_ID_CERN 0x10dc
+#define PCI_DEVICE_ID_CERN_SPSB_PMC 0x0001
+#define PCI_DEVICE_ID_CERN_SPSB_PCI 0x0002
+#define PCI_DEVICE_ID_CERN_HIPPI_DST 0x0021
+#define PCI_DEVICE_ID_CERN_HIPPI_SRC 0x0022
+
+#define PCI_VENDOR_ID_NVIDIA 0x10de
+
+#define PCI_VENDOR_ID_IMS 0x10e0
+#define PCI_DEVICE_ID_IMS_8849 0x8849
+
+#define PCI_VENDOR_ID_TEKRAM2 0x10e1
+#define PCI_DEVICE_ID_TEKRAM2_690c 0x690c
+
+#define PCI_VENDOR_ID_TUNDRA 0x10e3
+#define PCI_DEVICE_ID_TUNDRA_CA91C042 0x0000
+
+#define PCI_VENDOR_ID_AMCC 0x10e8
+#define PCI_DEVICE_ID_AMCC_MYRINET 0x8043
+#define PCI_DEVICE_ID_AMCC_PARASTATION 0x8062
+#define PCI_DEVICE_ID_AMCC_S5933 0x807d
+#define PCI_DEVICE_ID_AMCC_S5933_HEPC3 0x809c
+
+#define PCI_VENDOR_ID_INTERG 0x10ea
+#define PCI_DEVICE_ID_INTERG_1680 0x1680
+#define PCI_DEVICE_ID_INTERG_1682 0x1682
+
+#define PCI_VENDOR_ID_REALTEK 0x10ec
+#define PCI_DEVICE_ID_REALTEK_8029 0x8029
+#define PCI_DEVICE_ID_REALTEK_8129 0x8129
+#define PCI_DEVICE_ID_REALTEK_8139 0x8139
+
+#define PCI_VENDOR_ID_TRUEVISION 0x10fa
+#define PCI_DEVICE_ID_TRUEVISION_T1000 0x000c
+
+#define PCI_VENDOR_ID_INIT 0x1101
+#define PCI_DEVICE_ID_INIT_320P 0x9100
+#define PCI_DEVICE_ID_INIT_360P 0x9500
+
+#define PCI_VENDOR_ID_TTI 0x1103
+#define PCI_DEVICE_ID_TTI_HPT343 0x0003
+
+#define PCI_VENDOR_ID_VIA 0x1106
+#define PCI_DEVICE_ID_VIA_82C505 0x0505
+#define PCI_DEVICE_ID_VIA_82C561 0x0561
+#define PCI_DEVICE_ID_VIA_82C586_1 0x0571
+#define PCI_DEVICE_ID_VIA_82C576 0x0576
+#define PCI_DEVICE_ID_VIA_82C585 0x0585
+#define PCI_DEVICE_ID_VIA_82C586_0 0x0586
+#define PCI_DEVICE_ID_VIA_82C595 0x0595
+#define PCI_DEVICE_ID_VIA_82C597_0 0x0597
+#define PCI_DEVICE_ID_VIA_82C926 0x0926
+#define PCI_DEVICE_ID_VIA_82C416 0x1571
+#define PCI_DEVICE_ID_VIA_82C595_97 0x1595
+#define PCI_DEVICE_ID_VIA_82C586_2 0x3038
+#define PCI_DEVICE_ID_VIA_82C586_3 0x3040
+#define PCI_DEVICE_ID_VIA_86C100A 0x6100
+#define PCI_DEVICE_ID_VIA_82C597_1 0x8597
+
+#define PCI_VENDOR_ID_VORTEX 0x1119
+#define PCI_DEVICE_ID_VORTEX_GDT60x0 0x0000
+#define PCI_DEVICE_ID_VORTEX_GDT6000B 0x0001
+#define PCI_DEVICE_ID_VORTEX_GDT6x10 0x0002
+#define PCI_DEVICE_ID_VORTEX_GDT6x20 0x0003
+#define PCI_DEVICE_ID_VORTEX_GDT6530 0x0004
+#define PCI_DEVICE_ID_VORTEX_GDT6550 0x0005
+#define PCI_DEVICE_ID_VORTEX_GDT6x17 0x0006
+#define PCI_DEVICE_ID_VORTEX_GDT6x27 0x0007
+#define PCI_DEVICE_ID_VORTEX_GDT6537 0x0008
+#define PCI_DEVICE_ID_VORTEX_GDT6557 0x0009
+#define PCI_DEVICE_ID_VORTEX_GDT6x15 0x000a
+#define PCI_DEVICE_ID_VORTEX_GDT6x25 0x000b
+#define PCI_DEVICE_ID_VORTEX_GDT6535 0x000c
+#define PCI_DEVICE_ID_VORTEX_GDT6555 0x000d
+#define PCI_DEVICE_ID_VORTEX_GDT6x17RP 0x0100
+#define PCI_DEVICE_ID_VORTEX_GDT6x27RP 0x0101
+#define PCI_DEVICE_ID_VORTEX_GDT6537RP 0x0102
+#define PCI_DEVICE_ID_VORTEX_GDT6557RP 0x0103
+#define PCI_DEVICE_ID_VORTEX_GDT6x11RP 0x0104
+#define PCI_DEVICE_ID_VORTEX_GDT6x21RP 0x0105
+#define PCI_DEVICE_ID_VORTEX_GDT6x17RP1 0x0110
+#define PCI_DEVICE_ID_VORTEX_GDT6x27RP1 0x0111
+#define PCI_DEVICE_ID_VORTEX_GDT6537RP1 0x0112
+#define PCI_DEVICE_ID_VORTEX_GDT6557RP1 0x0113
+#define PCI_DEVICE_ID_VORTEX_GDT6x11RP1 0x0114
+#define PCI_DEVICE_ID_VORTEX_GDT6x21RP1 0x0115
+#define PCI_DEVICE_ID_VORTEX_GDT6x17RP2 0x0120
+#define PCI_DEVICE_ID_VORTEX_GDT6x27RP2 0x0121
+#define PCI_DEVICE_ID_VORTEX_GDT6537RP2 0x0122
+#define PCI_DEVICE_ID_VORTEX_GDT6557RP2 0x0123
+#define PCI_DEVICE_ID_VORTEX_GDT6x11RP2 0x0124
+#define PCI_DEVICE_ID_VORTEX_GDT6x21RP2 0x0125
+
+#define PCI_VENDOR_ID_EF 0x111a
+#define PCI_DEVICE_ID_EF_ATM_FPGA 0x0000
+#define PCI_DEVICE_ID_EF_ATM_ASIC 0x0002
+
+#define PCI_VENDOR_ID_FORE 0x1127
+#define PCI_DEVICE_ID_FORE_PCA200PC 0x0210
+#define PCI_DEVICE_ID_FORE_PCA200E 0x0300
+
+#define PCI_VENDOR_ID_IMAGINGTECH 0x112f
+#define PCI_DEVICE_ID_IMAGINGTECH_ICPCI 0x0000
+
+#define PCI_VENDOR_ID_PHILIPS 0x1131
+#define PCI_DEVICE_ID_PHILIPS_SAA7145 0x7145
+#define PCI_DEVICE_ID_PHILIPS_SAA7146 0x7146
+
+#define PCI_VENDOR_ID_CYCLONE 0x113c
+#define PCI_DEVICE_ID_CYCLONE_SDK 0x0001
+
+#define PCI_VENDOR_ID_ALLIANCE 0x1142
+#define PCI_DEVICE_ID_ALLIANCE_PROMOTIO 0x3210
+#define PCI_DEVICE_ID_ALLIANCE_PROVIDEO 0x6422
+#define PCI_DEVICE_ID_ALLIANCE_AT24 0x6424
+#define PCI_DEVICE_ID_ALLIANCE_AT3D 0x643d
+
+#define PCI_VENDOR_ID_SK 0x1148
+#define PCI_DEVICE_ID_SK_FP 0x4000
+#define PCI_DEVICE_ID_SK_TR 0x4200
+#define PCI_DEVICE_ID_SK_GE 0x4300
+
+#define PCI_VENDOR_ID_VMIC 0x114a
+#define PCI_DEVICE_ID_VMIC_VME 0x7587
+
+#define PCI_VENDOR_ID_DIGI 0x114f
+#define PCI_DEVICE_ID_DIGI_EPC 0x0002
+#define PCI_DEVICE_ID_DIGI_RIGHTSWITCH 0x0003
+#define PCI_DEVICE_ID_DIGI_XEM 0x0004
+#define PCI_DEVICE_ID_DIGI_XR 0x0005
+#define PCI_DEVICE_ID_DIGI_CX 0x0006
+#define PCI_DEVICE_ID_DIGI_XRJ 0x0009
+#define PCI_DEVICE_ID_DIGI_EPCJ 0x000a
+#define PCI_DEVICE_ID_DIGI_XR_920 0x0027
+
+#define PCI_VENDOR_ID_MUTECH 0x1159
+#define PCI_DEVICE_ID_MUTECH_MV1000 0x0001
+
+#define PCI_VENDOR_ID_RENDITION 0x1163
+#define PCI_DEVICE_ID_RENDITION_VERITE 0x0001
+#define PCI_DEVICE_ID_RENDITION_VERITE2100 0x2000
+
+#define PCI_VENDOR_ID_TOSHIBA 0x1179
+#define PCI_DEVICE_ID_TOSHIBA_601 0x0601
+#define PCI_DEVICE_ID_TOSHIBA_TOPIC95 0x060a
+#define PCI_DEVICE_ID_TOSHIBA_TOPIC97 0x060f
+
+#define PCI_VENDOR_ID_RICOH 0x1180
+#define PCI_DEVICE_ID_RICOH_RL5C465 0x0465
+#define PCI_DEVICE_ID_RICOH_RL5C466 0x0466
+#define PCI_DEVICE_ID_RICOH_RL5C475 0x0475
+#define PCI_DEVICE_ID_RICOH_RL5C478 0x0478
+
+#define PCI_VENDOR_ID_ARTOP 0x1191
+#define PCI_DEVICE_ID_ARTOP_ATP8400 0x0004
+#define PCI_DEVICE_ID_ARTOP_ATP850UF 0x0005
+
+#define PCI_VENDOR_ID_ZEITNET 0x1193
+#define PCI_DEVICE_ID_ZEITNET_1221 0x0001
+#define PCI_DEVICE_ID_ZEITNET_1225 0x0002
+
+#define PCI_VENDOR_ID_OMEGA 0x119b
+#define PCI_DEVICE_ID_OMEGA_82C092G 0x1221
+
+#define PCI_VENDOR_ID_LITEON 0x11ad
+#define PCI_DEVICE_ID_LITEON_LNE100TX 0x0002
+
+#define PCI_VENDOR_ID_NP 0x11bc
+#define PCI_DEVICE_ID_NP_PCI_FDDI 0x0001
+
+#define PCI_VENDOR_ID_ATT 0x11c1
+#define PCI_DEVICE_ID_ATT_L56XMF 0x0440
+
+#define PCI_VENDOR_ID_SPECIALIX 0x11cb
+#define PCI_DEVICE_ID_SPECIALIX_IO8 0x2000
+#define PCI_DEVICE_ID_SPECIALIX_XIO 0x4000
+#define PCI_DEVICE_ID_SPECIALIX_RIO 0x8000
+
+#define PCI_VENDOR_ID_AURAVISION 0x11d1
+#define PCI_DEVICE_ID_AURAVISION_VXP524 0x01f7
+
+#define PCI_VENDOR_ID_IKON 0x11d5
+#define PCI_DEVICE_ID_IKON_10115 0x0115
+#define PCI_DEVICE_ID_IKON_10117 0x0117
+
+#define PCI_VENDOR_ID_ZORAN 0x11de
+#define PCI_DEVICE_ID_ZORAN_36057 0x6057
+#define PCI_DEVICE_ID_ZORAN_36120 0x6120
+
+#define PCI_VENDOR_ID_KINETIC 0x11f4
+#define PCI_DEVICE_ID_KINETIC_2915 0x2915
+
+#define PCI_VENDOR_ID_COMPEX 0x11f6
+#define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112
+#define PCI_DEVICE_ID_COMPEX_RL2000 0x1401
+
+#define PCI_VENDOR_ID_RP 0x11fe
+#define PCI_DEVICE_ID_RP32INTF 0x0001
+#define PCI_DEVICE_ID_RP8INTF 0x0002
+#define PCI_DEVICE_ID_RP16INTF 0x0003
+#define PCI_DEVICE_ID_RP4QUAD 0x0004
+#define PCI_DEVICE_ID_RP8OCTA 0x0005
+#define PCI_DEVICE_ID_RP8J 0x0006
+#define PCI_DEVICE_ID_RPP4 0x000A
+#define PCI_DEVICE_ID_RPP8 0x000B
+#define PCI_DEVICE_ID_RP8M 0x000C
+
+#define PCI_VENDOR_ID_CYCLADES 0x120e
+#define PCI_DEVICE_ID_CYCLOM_Y_Lo 0x0100
+#define PCI_DEVICE_ID_CYCLOM_Y_Hi 0x0101
+#define PCI_DEVICE_ID_CYCLOM_Z_Lo 0x0200
+#define PCI_DEVICE_ID_CYCLOM_Z_Hi 0x0201
+
+#define PCI_VENDOR_ID_ESSENTIAL 0x120f
+#define PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER 0x0001
+
+#define PCI_VENDOR_ID_O2 0x1217
+#define PCI_DEVICE_ID_O2_6729 0x6729
+#define PCI_DEVICE_ID_O2_6730 0x673a
+#define PCI_DEVICE_ID_O2_6832 0x6832
+#define PCI_DEVICE_ID_O2_6836 0x6836
+
+#define PCI_VENDOR_ID_3DFX 0x121a
+#define PCI_DEVICE_ID_3DFX_VOODOO 0x0001
+#define PCI_DEVICE_ID_3DFX_VOODOO2 0x0002
+
+#define PCI_VENDOR_ID_SIGMADES 0x1236
+#define PCI_DEVICE_ID_SIGMADES_6425 0x6401
+
+#define PCI_VENDOR_ID_CCUBE 0x123f
+
+#define PCI_VENDOR_ID_DIPIX 0x1246
+
+#define PCI_VENDOR_ID_STALLION 0x124d
+#define PCI_DEVICE_ID_STALLION_ECHPCI832 0x0000
+#define PCI_DEVICE_ID_STALLION_ECHPCI864 0x0002
+#define PCI_DEVICE_ID_STALLION_EIOPCI 0x0003
+
+#define PCI_VENDOR_ID_OPTIBASE 0x1255
+#define PCI_DEVICE_ID_OPTIBASE_FORGE 0x1110
+#define PCI_DEVICE_ID_OPTIBASE_FUSION 0x1210
+#define PCI_DEVICE_ID_OPTIBASE_VPLEX 0x2110
+#define PCI_DEVICE_ID_OPTIBASE_VPLEXCC 0x2120
+#define PCI_DEVICE_ID_OPTIBASE_VQUEST 0x2130
+
+#define PCI_VENDOR_ID_SATSAGEM 0x1267
+#define PCI_DEVICE_ID_SATSAGEM_PCR2101 0x5352
+#define PCI_DEVICE_ID_SATSAGEM_TELSATTURBO 0x5a4b
+
+#define PCI_VENDOR_ID_HUGHES 0x1273
+#define PCI_DEVICE_ID_HUGHES_DIRECPC 0x0002
+
+#define PCI_VENDOR_ID_ENSONIQ 0x1274
+#define PCI_DEVICE_ID_ENSONIQ_AUDIOPCI 0x5000
+
+#define PCI_VENDOR_ID_ALTEON 0x12ae
+#define PCI_DEVICE_ID_ALTEON_ACENIC 0x0001
+
+#define PCI_VENDOR_ID_PICTUREL 0x12c5
+#define PCI_DEVICE_ID_PICTUREL_PCIVST 0x0081
+
+#define PCI_VENDOR_ID_NVIDIA_SGS 0x12d2
+#define PCI_DEVICE_ID_NVIDIA_SGS_RIVA128 0x0018
+
+#define PCI_VENDOR_ID_CBOARDS 0x1307
+#define PCI_DEVICE_ID_CBOARDS_DAS1602_16 0x0001
+
+#define PCI_VENDOR_ID_SYMPHONY 0x1c1c
+#define PCI_DEVICE_ID_SYMPHONY_101 0x0001
+
+#define PCI_VENDOR_ID_TEKRAM 0x1de1
+#define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29
+
+#define PCI_VENDOR_ID_3DLABS 0x3d3d
+#define PCI_DEVICE_ID_3DLABS_300SX 0x0001
+#define PCI_DEVICE_ID_3DLABS_500TX 0x0002
+#define PCI_DEVICE_ID_3DLABS_DELTA 0x0003
+#define PCI_DEVICE_ID_3DLABS_PERMEDIA 0x0004
+#define PCI_DEVICE_ID_3DLABS_MX 0x0006
+
+#define PCI_VENDOR_ID_AVANCE 0x4005
+#define PCI_DEVICE_ID_AVANCE_ALG2064 0x2064
+#define PCI_DEVICE_ID_AVANCE_2302 0x2302
+
+#define PCI_VENDOR_ID_NETVIN 0x4a14
+#define PCI_DEVICE_ID_NETVIN_NV5000SC 0x5000
+
+#define PCI_VENDOR_ID_S3 0x5333
+#define PCI_DEVICE_ID_S3_PLATO_PXS 0x0551
+#define PCI_DEVICE_ID_S3_ViRGE 0x5631
+#define PCI_DEVICE_ID_S3_TRIO 0x8811
+#define PCI_DEVICE_ID_S3_AURORA64VP 0x8812
+#define PCI_DEVICE_ID_S3_TRIO64UVP 0x8814
+#define PCI_DEVICE_ID_S3_ViRGE_VX 0x883d
+#define PCI_DEVICE_ID_S3_868 0x8880
+#define PCI_DEVICE_ID_S3_928 0x88b0
+#define PCI_DEVICE_ID_S3_864_1 0x88c0
+#define PCI_DEVICE_ID_S3_864_2 0x88c1
+#define PCI_DEVICE_ID_S3_964_1 0x88d0
+#define PCI_DEVICE_ID_S3_964_2 0x88d1
+#define PCI_DEVICE_ID_S3_968 0x88f0
+#define PCI_DEVICE_ID_S3_TRIO64V2 0x8901
+#define PCI_DEVICE_ID_S3_PLATO_PXG 0x8902
+#define PCI_DEVICE_ID_S3_ViRGE_DXGX 0x8a01
+#define PCI_DEVICE_ID_S3_ViRGE_GX2 0x8a10
+#define PCI_DEVICE_ID_S3_ViRGE_MX 0x8c01
+#define PCI_DEVICE_ID_S3_ViRGE_MXP 0x8c02
+#define PCI_DEVICE_ID_S3_ViRGE_MXPMV 0x8c03
+#define PCI_DEVICE_ID_S3_SONICVIBES 0xca00
+
+#define PCI_VENDOR_ID_INTEL 0x8086
+#define PCI_DEVICE_ID_INTEL_82375 0x0482
+#define PCI_DEVICE_ID_INTEL_82424 0x0483
+#define PCI_DEVICE_ID_INTEL_82378 0x0484
+#define PCI_DEVICE_ID_INTEL_82430 0x0486
+#define PCI_DEVICE_ID_INTEL_82434 0x04a3
+#define PCI_DEVICE_ID_INTEL_82092AA_0 0x1221
+#define PCI_DEVICE_ID_INTEL_82092AA_1 0x1222
+#define PCI_DEVICE_ID_INTEL_7116 0x1223
+#define PCI_DEVICE_ID_INTEL_82596 0x1226
+#define PCI_DEVICE_ID_INTEL_82865 0x1227
+#define PCI_DEVICE_ID_INTEL_82557 0x1229
+#define PCI_DEVICE_ID_INTEL_82437 0x122d
+#define PCI_DEVICE_ID_INTEL_82371FB_0 0x122e
+#define PCI_DEVICE_ID_INTEL_82371FB_1 0x1230
+#define PCI_DEVICE_ID_INTEL_82371MX 0x1234
+#define PCI_DEVICE_ID_INTEL_82437MX 0x1235
+#define PCI_DEVICE_ID_INTEL_82441 0x1237
+#define PCI_DEVICE_ID_INTEL_82380FB 0x124b
+#define PCI_DEVICE_ID_INTEL_82439 0x1250
+#define PCI_DEVICE_ID_INTEL_82371SB_0 0x7000
+#define PCI_DEVICE_ID_INTEL_82371SB_1 0x7010
+#define PCI_DEVICE_ID_INTEL_82371SB_2 0x7020
+#define PCI_DEVICE_ID_INTEL_82437VX 0x7030
+#define PCI_DEVICE_ID_INTEL_82439TX 0x7100
+#define PCI_DEVICE_ID_INTEL_82371AB_0 0x7110
+#define PCI_DEVICE_ID_INTEL_82371AB 0x7111
+#define PCI_DEVICE_ID_INTEL_82371AB_2 0x7112
+#define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113
+#define PCI_DEVICE_ID_INTEL_82443LX_0 0x7180
+#define PCI_DEVICE_ID_INTEL_82443LX_1 0x7181
+#define PCI_DEVICE_ID_INTEL_82443BX_0 0x7190
+#define PCI_DEVICE_ID_INTEL_82443BX_1 0x7191
+#define PCI_DEVICE_ID_INTEL_82443BX_2 0x7192
+#define PCI_DEVICE_ID_INTEL_P6 0x84c4
+#define PCI_DEVICE_ID_INTEL_82450GX 0x84c5
+
+#define PCI_VENDOR_ID_KTI 0x8e2e
+#define PCI_DEVICE_ID_KTI_ET32P2 0x3000
+
+#define PCI_VENDOR_ID_ADAPTEC 0x9004
+#define PCI_DEVICE_ID_ADAPTEC_7810 0x1078
+#define PCI_DEVICE_ID_ADAPTEC_7850 0x5078
+#define PCI_DEVICE_ID_ADAPTEC_7855 0x5578
+#define PCI_DEVICE_ID_ADAPTEC_5800 0x5800
+#define PCI_DEVICE_ID_ADAPTEC_1480A 0x6075
+#define PCI_DEVICE_ID_ADAPTEC_7860 0x6078
+#define PCI_DEVICE_ID_ADAPTEC_7861 0x6178
+#define PCI_DEVICE_ID_ADAPTEC_7870 0x7078
+#define PCI_DEVICE_ID_ADAPTEC_7871 0x7178
+#define PCI_DEVICE_ID_ADAPTEC_7872 0x7278
+#define PCI_DEVICE_ID_ADAPTEC_7873 0x7378
+#define PCI_DEVICE_ID_ADAPTEC_7874 0x7478
+#define PCI_DEVICE_ID_ADAPTEC_7895 0x7895
+#define PCI_DEVICE_ID_ADAPTEC_7880 0x8078
+#define PCI_DEVICE_ID_ADAPTEC_7881 0x8178
+#define PCI_DEVICE_ID_ADAPTEC_7882 0x8278
+#define PCI_DEVICE_ID_ADAPTEC_7883 0x8378
+#define PCI_DEVICE_ID_ADAPTEC_7884 0x8478
+#define PCI_DEVICE_ID_ADAPTEC_1030 0x8b78
+
+#define PCI_VENDOR_ID_ADAPTEC2 0x9005
+#define PCI_DEVICE_ID_ADAPTEC2_2940U2 0x0010
+#define PCI_DEVICE_ID_ADAPTEC2_7890 0x001f
+#define PCI_DEVICE_ID_ADAPTEC2_3940U2 0x0050
+#define PCI_DEVICE_ID_ADAPTEC2_7896 0x005f
+
+#define PCI_VENDOR_ID_ATRONICS 0x907f
+#define PCI_DEVICE_ID_ATRONICS_2015 0x2015
+
+#define PCI_VENDOR_ID_HOLTEK 0x9412
+#define PCI_DEVICE_ID_HOLTEK_6565 0x6565
+
+#define PCI_VENDOR_ID_TIGERJET 0xe159
+#define PCI_DEVICE_ID_TIGERJET_300 0x0001
+
+#define PCI_VENDOR_ID_ARK 0xedd8
+#define PCI_DEVICE_ID_ARK_STING 0xa091
+#define PCI_DEVICE_ID_ARK_STINGARK 0xa099
+#define PCI_DEVICE_ID_ARK_2000MT 0xa0a1
+/*
+ * The PCI interface treats multi-function devices as independent
+ * devices. The slot/function address of each device is encoded
+ * in a single byte as follows:
+ *
+ * 7:3 = slot
+ * 2:0 = function
+ */
+#define PCI_DEVFN(_slot,_func) ((((_slot) & 0x1f) << 3) | ((_func) & 0x07))
+#define PCI_SLOT(_devfn) (((_devfn) >> 3) & 0x1f)
+#define PCI_FUNC(_devfn) ((_devfn) & 0x07)
+
+/*
+ * Error values that may be returned by the PCI bios.
+ */
+#define PCIBIOS_SUCCESSFUL 0x00
+#define PCIBIOS_FUNC_NOT_SUPPORTED 0x81
+#define PCIBIOS_BAD_VENDOR_ID 0x83
+#define PCIBIOS_DEVICE_NOT_FOUND 0x86
+#define PCIBIOS_BAD_REGISTER_NUMBER 0x87
+#define PCIBIOS_SET_FAILED 0x88
+#define PCIBIOS_BUFFER_TOO_SMALL 0x89
+
+/* T. Straumann, 7/31/2001: increased to 32 - PMC slots are not
+ * scanned on mvme2306 otherwise
+ */
+#define PCI_MAX_DEVICES 32
+#define PCI_MAX_FUNCTIONS 8
+
+typedef struct {
+ int (*read_config_byte)(unsigned char, unsigned char, unsigned char,
+ unsigned char, uint8_t *);
+ int (*read_config_word)(unsigned char, unsigned char, unsigned char,
+ unsigned char, uint16_t *);
+ int (*read_config_dword)(unsigned char, unsigned char, unsigned char,
+ unsigned char, uint32_t *);
+ int (*write_config_byte)(unsigned char, unsigned char, unsigned char,
+ unsigned char, uint8_t);
+ int (*write_config_word)(unsigned char, unsigned char, unsigned char,
+ unsigned char, uint16_t);
+ int (*write_config_dword)(unsigned char, unsigned char, unsigned char,
+ unsigned char, uint32_t);
+} pci_config_access_functions;
+
+/* Error codes for pci_initialize */
+#define PCIB_ERR_SUCCESS (0)
+#define PCIB_ERR_UNINITIALIZED (-1) /* PCI BIOS is not initilized */
+#define PCIB_ERR_NOTPRESENT (-2) /* PCI BIOS not present */
+#define PCIB_ERR_NOFUNC (-3) /* Function not supported */
+#define PCIB_ERR_BADVENDOR (-4) /* Bad Vendor ID */
+#define PCIB_ERR_DEVNOTFOUND (-5) /* Device not found */
+#define PCIB_ERR_BADREG (-6) /* Bad register number */
+
+extern int pci_initialize(void);
+
+typedef struct {
+ volatile unsigned char* pci_config_addr;
+ volatile unsigned char* pci_config_data;
+ const pci_config_access_functions* pci_functions;
+} rtems_pci_config_t;
+
+extern rtems_pci_config_t BSP_pci_configuration;
+
+static inline int
+pci_read_config_byte(
+ unsigned char bus,
+ unsigned char slot,
+ unsigned char function,
+ unsigned char where,
+ uint8_t *val)
+{
+ return BSP_pci_configuration.pci_functions->read_config_byte(
+ bus, slot, function, where, val);
+}
+
+static inline int
+pci_read_config_word(
+ unsigned char bus,
+ unsigned char slot,
+ unsigned char function,
+ unsigned char where,
+ uint16_t *val)
+{
+ return BSP_pci_configuration.pci_functions->read_config_word(
+ bus, slot, function, where, val);
+}
+
+static inline int
+pci_read_config_dword(
+ unsigned char bus,
+ unsigned char slot,
+ unsigned char function,
+ unsigned char where,
+ uint32_t *val)
+{
+ return BSP_pci_configuration.pci_functions->read_config_dword(bus, slot, function, where, val);
+}
+
+static inline int
+pci_write_config_byte(
+ unsigned char bus,
+ unsigned char slot,
+ unsigned char function,
+ unsigned char where,
+ uint8_t val)
+{
+ return BSP_pci_configuration.pci_functions->write_config_byte(
+ bus, slot, function, where, val);
+}
+
+static inline int
+pci_write_config_word(
+ unsigned char bus,
+ unsigned char slot,
+ unsigned char function,
+ unsigned char where,
+ uint16_t val)
+{
+ return BSP_pci_configuration.pci_functions->write_config_word(
+ bus, slot, function, where, val);
+}
+
+static inline int
+pci_write_config_dword(
+ unsigned char bus,
+ unsigned char slot,
+ unsigned char function,
+ unsigned char where,
+ uint32_t val)
+{
+ return BSP_pci_configuration.pci_functions->write_config_dword(
+ bus, slot, function, where, val);
+}
+
+/* scan for a specific device */
+/* find a particular PCI device
+ * (currently, only bus0 is scanned for device/fun0)
+ *
+ * RETURNS: zero on success, bus/dev/fun in *pbus / *pdev / *pfun
+ */
+int
+pci_find_device(
+ unsigned short vendorid,
+ unsigned short deviceid,
+ int instance,
+ int *pbus,
+ int *pdev,
+ int *pfun
+);
+
+/*
+ * Return the number of PCI busses in the system
+ */
+extern unsigned char pci_bus_count(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_PCI_H */
diff --git a/cpukit/include/rtems/status-checks.h b/cpukit/include/rtems/status-checks.h
new file mode 100644
index 0000000000..bb924e8b07
--- /dev/null
+++ b/cpukit/include/rtems/status-checks.h
@@ -0,0 +1,345 @@
+/**
+ * @file
+ *
+ * @brief Header file for status checks.
+ *
+ * @warning Do not include this file in other header files. Use it only in
+ * source files.
+ */
+
+/*
+ * Copyright (c) 2008
+ * Embedded Brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * rtems@embedded-brains.de
+ *
+ * The license and distribution terms for this file may be found in the file
+ * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef RTEMS_STATUS_CHECKS_H
+#define RTEMS_STATUS_CHECKS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup rtems_status_checks Status Checks
+ *
+ * @{
+ */
+
+/**
+ * @name Print Macros
+ *
+ * @{
+ */
+
+/**
+ * @brief General purpose debug print macro.
+ */
+#ifdef DEBUG
+ #ifndef RTEMS_DEBUG_PRINT
+ #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
+ #define RTEMS_DEBUG_PRINT( fmt, ...) \
+ printk( "%s: " fmt, __func__, ##__VA_ARGS__)
+ #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
+ #include <stdio.h>
+ #define RTEMS_DEBUG_PRINT( fmt, ...) \
+ printf( "%s: " fmt, __func__, ##__VA_ARGS__)
+ #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
+ #endif /* RTEMS_DEBUG_PRINT */
+#else /* DEBUG */
+ #ifdef RTEMS_DEBUG_PRINT
+ #warning RTEMS_DEBUG_PRINT was defined, but DEBUG was undefined
+ #undef RTEMS_DEBUG_PRINT
+ #endif /* RTEMS_DEBUG_PRINT */
+ #define RTEMS_DEBUG_PRINT( fmt, ...)
+#endif /* DEBUG */
+
+/**
+ * @brief Macro to print debug messages for successful operations.
+ */
+#define RTEMS_DEBUG_OK( msg) \
+ RTEMS_DEBUG_PRINT( "Ok: %s\n", msg)
+
+/**
+ * @brief General purpose system log print macro.
+ */
+#ifndef RTEMS_SYSLOG_PRINT
+ #ifdef RTEMS_STATUS_CHECKS_USE_PRINTK
+ #define RTEMS_SYSLOG_PRINT( fmt, ...) \
+ printk( fmt, ##__VA_ARGS__)
+ #else /* RTEMS_STATUS_CHECKS_USE_PRINTK */
+ #include <stdio.h>
+ #define RTEMS_SYSLOG_PRINT( fmt, ...) \
+ printf( fmt, ##__VA_ARGS__)
+ #endif /* RTEMS_STATUS_CHECKS_USE_PRINTK */
+#endif /* RTEMS_SYSLOG_PRINT */
+
+/**
+ * @brief General purpose system log macro.
+ */
+#define RTEMS_SYSLOG( fmt, ...) \
+ RTEMS_SYSLOG_PRINT( "%s: " fmt, __func__, ##__VA_ARGS__)
+
+/**
+ * @brief General purpose system log macro for warnings.
+ */
+#define RTEMS_SYSLOG_WARNING( fmt, ...) \
+ RTEMS_SYSLOG( "Warning: " fmt, ##__VA_ARGS__)
+
+/**
+ * @brief Macro to generate a system log warning message if the status code @a
+ * sc is not equal to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_SYSLOG_WARNING_SC( sc, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_WARNING( "SC = %i: %s\n", (int) sc, msg); \
+ }
+
+/**
+ * @brief General purpose system log macro for errors.
+ */
+#define RTEMS_SYSLOG_ERROR( fmt, ...) \
+ RTEMS_SYSLOG( "Error: " fmt, ##__VA_ARGS__)
+
+/**
+ * @brief Macro for system log error messages with status code.
+ */
+#define RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg) \
+ RTEMS_SYSLOG_ERROR( "SC = %i: %s\n", (int) sc, msg);
+
+/**
+ * @brief Macro for system log error messages with return value.
+ */
+#define RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg) \
+ RTEMS_SYSLOG_ERROR( "RV = %i: %s\n", (int) rv, msg);
+
+/**
+ * @brief Macro to generate a system log error message if the status code @a
+ * sc is not equal to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_SYSLOG_ERROR_SC( sc, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ }
+
+/**
+ * @brief Macro to generate a system log error message if the return value @a
+ * rv is less than zero.
+ */
+#define RTEMS_SYSLOG_ERROR_RV( rv, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ }
+
+/** @} */
+
+/**
+ * @name Check Macros
+ *
+ * @{
+ */
+
+/**
+ * @brief Prints message @a msg and returns with status code @a sc if the status
+ * code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_CHECK_SC( sc, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ return (rtems_status_code) sc; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and returns with a return value of negative @a sc
+ * if the status code @a sc is not equal to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_CHECK_SC_RV( sc, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ return -((int) (sc)); \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and returns if the status code @a sc is not equal
+ * to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_CHECK_SC_VOID( sc, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ return; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and delete the current task if the status code
+ * @a sc is not equal to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_CHECK_SC_TASK( sc, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ (void) rtems_task_delete( RTEMS_SELF); \
+ return; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and returns with a return value @a rv if the
+ * return value @a rv is less than zero.
+ */
+#define RTEMS_CHECK_RV( rv, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ return (int) rv; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and returns with status code @ref RTEMS_IO_ERROR
+ * if the return value @a rv is less than zero.
+ */
+#define RTEMS_CHECK_RV_SC( rv, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ return RTEMS_IO_ERROR; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and returns if the return value @a rv is less
+ * than zero.
+ */
+#define RTEMS_CHECK_RV_VOID( rv, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ return; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and delete the current task if the return value
+ * @a rv is less than zero.
+ */
+#define RTEMS_CHECK_RV_TASK( rv, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ (void) rtems_task_delete( RTEMS_SELF); \
+ return; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/** @} */
+
+/**
+ * @name Cleanup Macros
+ *
+ * @{
+ */
+
+/**
+ * @brief Prints message @a msg and jumps to @a label if the status code @a sc
+ * is not equal to @ref RTEMS_SUCCESSFUL.
+ */
+#define RTEMS_CLEANUP_SC( sc, label, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ goto label; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and jumps to @a label if the status code @a sc
+ * is not equal to @ref RTEMS_SUCCESSFUL. The return value variable @a rv will
+ * be set to a negative @a sc in this case.
+ */
+#define RTEMS_CLEANUP_SC_RV( sc, rv, label, msg) \
+ if ((rtems_status_code) (sc) != RTEMS_SUCCESSFUL) { \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ rv = -((int) (sc)); \
+ goto label; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and jumps to @a label if the return value @a rv
+ * is less than zero.
+ */
+#define RTEMS_CLEANUP_RV( rv, label, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ goto label; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and jumps to @a label if the return value @a rv
+ * is less than zero. The status code variable @a sc will be set to @ref
+ * RTEMS_IO_ERROR in this case.
+ */
+#define RTEMS_CLEANUP_RV_SC( rv, sc, label, msg) \
+ if ((int) (rv) < 0) { \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ sc = RTEMS_IO_ERROR; \
+ goto label; \
+ } else { \
+ RTEMS_DEBUG_OK( msg); \
+ }
+
+/**
+ * @brief Prints message @a msg and jumps to @a label.
+ */
+#define RTEMS_DO_CLEANUP( label, msg) \
+ do { \
+ RTEMS_SYSLOG_ERROR( msg); \
+ goto label; \
+ } while (0)
+
+/**
+ * @brief Prints message @a msg, sets the status code variable @a sc to @a val
+ * and jumps to @a label.
+ */
+#define RTEMS_DO_CLEANUP_SC( val, sc, label, msg) \
+ do { \
+ sc = (rtems_status_code) val; \
+ RTEMS_SYSLOG_ERROR_WITH_SC( sc, msg); \
+ goto label; \
+ } while (0)
+
+/**
+ * @brief Prints message @a msg, sets the return value variable @a rv to @a val
+ * and jumps to @a label.
+ */
+#define RTEMS_DO_CLEANUP_RV( val, rv, label, msg) \
+ do { \
+ rv = (int) val; \
+ RTEMS_SYSLOG_ERROR_WITH_RV( rv, msg); \
+ goto label; \
+ } while (0)
+
+/** @} */
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RTEMS_STATUS_CHECKS_H */
diff --git a/cpukit/include/rtems/userenv.h b/cpukit/include/rtems/userenv.h
new file mode 100644
index 0000000000..b16374a6dc
--- /dev/null
+++ b/cpukit/include/rtems/userenv.h
@@ -0,0 +1,88 @@
+/*
+ * Libio Internal Information
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_USERENV_H
+#define _RTEMS_USERENV_H
+
+#include <rtems.h>
+#include <rtems/fs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * External structures
+ */
+
+/*
+ * According to IEEE Std 1003.1-2001,
+ * limits.h is supposed to provide _POSIX_LOGIN_NAME_MAX
+ * FIXME: We should not rely on this.
+ */
+#include <limits.h>
+
+#ifndef LOGIN_NAME_MAX
+#ifdef _POSIX_LOGIN_NAME_MAX
+#define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
+#else
+/* Fallback */
+#define LOGIN_NAME_MAX 9
+#endif
+#endif
+
+typedef struct {
+ rtems_id task_id;
+ rtems_filesystem_location_info_t current_directory;
+ rtems_filesystem_location_info_t root_directory;
+ /* Default mode for all files. */
+ mode_t umask;
+ nlink_t link_counts;
+ /* _POSIX_types */
+ uid_t uid;
+ gid_t gid;
+ uid_t euid;
+ gid_t egid;
+ char login_buffer[LOGIN_NAME_MAX];
+
+ pid_t pgrp; /* process group id */
+} rtems_user_env_t;
+
+extern rtems_user_env_t * rtems_current_user_env;
+extern rtems_user_env_t rtems_global_user_env;
+
+#define rtems_filesystem_current (rtems_current_user_env->current_directory)
+#define rtems_filesystem_root (rtems_current_user_env->root_directory)
+#define rtems_filesystem_link_counts (rtems_current_user_env->link_counts)
+#define rtems_filesystem_umask (rtems_current_user_env->umask)
+
+#define _POSIX_types_Uid (rtems_current_user_env->uid)
+#define _POSIX_types_Gid (rtems_current_user_env->gid)
+#define _POSIX_types_Euid (rtems_current_user_env->euid)
+#define _POSIX_types_Egid (rtems_current_user_env->egid)
+#define _POSIX_types_Getlogin_buffer (rtems_current_user_env->login_buffer)
+
+
+/*
+ * Instantiate a private copy of the per user information for the calling task.
+ */
+
+rtems_status_code rtems_libio_set_private_env(void);
+rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/include/sys/priority.h b/cpukit/include/sys/priority.h
new file mode 100644
index 0000000000..0dade6d62d
--- /dev/null
+++ b/cpukit/include/sys/priority.h
@@ -0,0 +1,2 @@
+
+/* For now, intentionally empty */
diff --git a/cpukit/libblock/.cvsignore b/cpukit/libblock/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libblock/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libblock/Makefile.am b/cpukit/libblock/Makefile.am
new file mode 100644
index 0000000000..15c3852da4
--- /dev/null
+++ b/cpukit/libblock/Makefile.am
@@ -0,0 +1,37 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+noinst_LIBRARIES = libblock.a
+libblock_a_SOURCES = src/bdbuf.c \
+ src/blkdev.c \
+ src/blkdev-ops.c \
+ src/diskdevs.c \
+ src/flashdisk.c \
+ src/ramdisk-driver.c \
+ src/ramdisk-init.c \
+ src/ramdisk-config.c \
+ src/ide_part_table.c \
+ src/nvdisk.c \
+ src/nvdisk-sram.c \
+ src/bdpart-create.c \
+ src/bdpart-dump.c \
+ src/bdpart-mount.c \
+ src/bdpart-read.c \
+ src/bdpart-register.c \
+ src/bdpart-sort.c \
+ src/bdpart-write.c \
+ src/media-path.c \
+ src/media.c \
+ src/media-server.c \
+ src/media-desc.c \
+ src/media-dev-ident.c \
+ include/rtems/bdbuf.h include/rtems/blkdev.h \
+ include/rtems/diskdevs.h include/rtems/flashdisk.h \
+ include/rtems/ramdisk.h include/rtems/nvdisk.h include/rtems/nvdisk-sram.h \
+ include/rtems/ide_part_table.h
+
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libblock/README b/cpukit/libblock/README
new file mode 100644
index 0000000000..671cc7f645
--- /dev/null
+++ b/cpukit/libblock/README
@@ -0,0 +1,14 @@
+#
+# $Id$
+#
+
+This directory contains the block device (HDD, CDROMs, etc) support code.
+It includes:
+ - block device driver interface
+ - generic open/close/read/write/ioctl primitives for block device drivers
+ - disk I/O buffering
+ - logical disk support
+ - RAM disk block device driver
+
+Victor V. Vengerov, <vvv@oktet.ru>
+November, 7 2001
diff --git a/cpukit/libblock/include/rtems/bdbuf.h b/cpukit/libblock/include/rtems/bdbuf.h
new file mode 100644
index 0000000000..66a9bbf59b
--- /dev/null
+++ b/cpukit/libblock/include/rtems/bdbuf.h
@@ -0,0 +1,594 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdbuf
+ *
+ * Block device buffer management.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * Copyright (C) 2008,2009 Chris Johns <chrisj@rtems.org>
+ * Rewritten to remove score mutex access. Fixes many performance
+ * issues.
+ * Change to support demand driven variable buffer sizes.
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * @(#) bdbuf.h,v 1.9 2005/02/02 00:06:18 joel Exp
+ */
+
+#ifndef _RTEMS_BDBUF_H
+#define _RTEMS_BDBUF_H
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/chain.h>
+
+#include <rtems/blkdev.h>
+#include <rtems/diskdevs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup rtems_libblock Block Device Library
+ *
+ * Block device modules.
+ */
+
+/**
+ * @defgroup rtems_bdbuf Block Device Buffer Management
+ *
+ * @ingroup rtems_libblock
+ *
+ * The Block Device Buffer Management implements a cache between the disk
+ * devices and file systems. The code provides read ahead and write queuing to
+ * the drivers and fast cache look-up using an AVL tree.
+ *
+ * The block size used by a file system can be set at runtime and must be a
+ * multiple of the disk device block size. The disk device's physical block
+ * size is called the media block size. The file system can set the block size
+ * it uses to a larger multiple of the media block size. The driver must be
+ * able to handle buffers sizes larger than one media block.
+ *
+ * The user configures the amount of memory to be used as buffers in the cache,
+ * and the minimum and maximum buffer size. The cache will allocate additional
+ * memory for the buffer descriptors and groups. There are enough buffer
+ * descriptors allocated so all the buffer memory can be used as minimum sized
+ * buffers.
+ *
+ * The cache is a single pool of buffers. The buffer memory is divided into
+ * groups where the size of buffer memory allocated to a group is the maximum
+ * buffer size. A group's memory can be divided down into small buffer sizes
+ * that are a multiple of 2 of the minimum buffer size. A group is the minimum
+ * allocation unit for buffers of a specific size. If a buffer of maximum size
+ * is request the group will have a single buffer. If a buffer of minimum size
+ * is requested the group is divided into minimum sized buffers and the
+ * remaining buffers are held ready for use. A group keeps track of which
+ * buffers are with a file system or driver and groups who have buffer in use
+ * cannot be realloced. Groups with no buffers in use can be taken and
+ * realloced to a new size. This is how buffers of different sizes move around
+ * the cache.
+
+ * The buffers are held in various lists in the cache. All buffers follow this
+ * state machine:
+ *
+ * @dot
+ * digraph state {
+ * size="16,8";
+ * f [label="FREE",style="filled",fillcolor="aquamarine"];
+ * e [label="EMPTY",style="filled",fillcolor="seagreen"];
+ * c [label="CACHED",style="filled",fillcolor="chartreuse"];
+ * ac [label="ACCESS CACHED",style="filled",fillcolor="royalblue"];
+ * am [label="ACCESS MODIFIED",style="filled",fillcolor="royalblue"];
+ * ae [label="ACCESS EMPTY",style="filled",fillcolor="royalblue"];
+ * ap [label="ACCESS PURGED",style="filled",fillcolor="royalblue"];
+ * t [label="TRANSFER",style="filled",fillcolor="red"];
+ * tp [label="TRANSFER PURGED",style="filled",fillcolor="red"];
+ * s [label="SYNC",style="filled",fillcolor="red"];
+ * m [label="MODIFIED",style="filled",fillcolor="gold"];
+ * i [label="INITIAL"];
+ *
+ * legend_transfer [label="Transfer Wake-Up",fontcolor="red",shape="none"];
+ * legend_access [label="Access Wake-Up",fontcolor="royalblue",shape="none"];
+ *
+ * i -> f [label="Init"];
+ * f -> e [label="Buffer Recycle"];
+ * e -> ae [label="Get"];
+ * e -> t [label="Read"];
+ * e -> f [label="Nobody Waits"];
+ * c -> ac [label="Get\nRead"];
+ * c -> e [label="Buffer Recycle\nPurge"];
+ * c -> f [label="Reallocate\nBlock Size Changed"];
+ * t -> c [label="Transfer Done",color="red",fontcolor="red"];
+ * t -> e [label="Transfer Error",color="red",fontcolor="red"];
+ * t -> tp [label="Purge"];
+ * tp -> e [label="Transfer Done\nTransfer Error",color="red",fontcolor="red"];
+ * m -> t [label="Swapout"];
+ * m -> s [label="Block Size Changed"];
+ * m -> am [label="Get\nRead"];
+ * m -> e [label="Purge"];
+ * ac -> m [label="Release Modified",color="royalblue",fontcolor="royalblue"];
+ * ac -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
+ * ac -> c [label="Release",color="royalblue",fontcolor="royalblue"];
+ * ac -> ap [label="Purge"];
+ * am -> m [label="Release\nRelease Modified",color="royalblue",fontcolor="royalblue"];
+ * am -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
+ * am -> ap [label="Purge"];
+ * ae -> m [label="Release Modified",color="royalblue",fontcolor="royalblue"];
+ * ae -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
+ * ae -> e [label="Release",color="royalblue",fontcolor="royalblue"];
+ * ae -> ap [label="Purge"];
+ * ap -> e [label="Release\nRelease Modified\nSync",color="royalblue",fontcolor="royalblue"];
+ * s -> t [label="Swapout"];
+ * s -> e [label="Purge",color="red",fontcolor="red"];
+ * }
+ * @enddot
+ *
+ * Empty or cached buffers are added to the LRU list and removed from this
+ * queue when a caller requests a buffer. This is referred to as getting a
+ * buffer in the code and the event get in the state diagram. The buffer is
+ * assigned to a block and inserted to the AVL based on the block/device key.
+ * If the block is to be read by the user and not in the cache it is transfered
+ * from the disk into memory. If no buffers are on the LRU list the modified
+ * list is checked. If buffers are on the modified the swap out task will be
+ * woken. The request blocks until a buffer is available for recycle.
+ *
+ * A block being accessed is given to the file system layer and not accessible
+ * to another requester until released back to the cache. The same goes to a
+ * buffer in the transfer state. The transfer state means being read or
+ * written. If the file system has modifed the block and releases it as
+ * modified it placed on the cache's modified list and a hold timer
+ * initialised. The buffer is held for the hold time before being written to
+ * disk. Buffers are held for a configurable period of time on the modified
+ * list as a write sets the state to transfer and this locks the buffer out
+ * from the file system until the write completes. Buffers are often accessed
+ * and modified in a series of small updates so if sent to the disk when
+ * released as modified the user would have to block waiting until it had been
+ * written. This would be a performance problem.
+ *
+ * The code performs multiple block reads and writes. Multiple block reads or
+ * read ahead increases performance with hardware that supports it. It also
+ * helps with a large cache as the disk head movement is reduced. It however
+ * is a speculative operation so excessive use can remove valuable and needed
+ * blocks from the cache.
+ *
+ * The cache has the following lists of buffers:
+ * - LRU: Accessed or transfered buffers released in least recently used
+ * order. Empty buffers will be placed to the front.
+ * - Modified: Buffers waiting to be written to disk.
+ * - Sync: Buffers to be synchronized with the disk.
+ *
+ * A cache look-up will be performed to find a suitable buffer. A suitable
+ * buffer is one that matches the same allocation size as the device the buffer
+ * is for. The a buffer's group has no buffers in use with the file system or
+ * driver the group is reallocated. This means the buffers in the group are
+ * invalidated, resized and placed on the LRU queue. There is a performance
+ * issue with this design. The reallocation of a group may forced recently
+ * accessed buffers out of the cache when they should not. The design should be
+ * change to have groups on a LRU list if they have no buffers in use.
+ *
+ * @{
+ */
+
+/**
+ * @brief State of a buffer of the cache.
+ *
+ * The state has several implications. Depending on the state a buffer can be
+ * in the AVL tree, in a list, in use by an entity and a group user or not.
+ *
+ * <table>
+ * <tr>
+ * <th>State</th><th>Valid Data</th><th>AVL Tree</th>
+ * <th>LRU List</th><th>Modified List</th><th>Synchronization List</th>
+ * <th>Group User</th><th>External User</th>
+ * </tr>
+ * <tr>
+ * <td>FREE</td><td></td><td></td>
+ * <td>X</td><td></td><td></td><td></td><td></td>
+ * </tr>
+ * <tr>
+ * <td>EMPTY</td><td></td><td>X</td>
+ * <td></td><td></td><td></td><td></td><td></td>
+ * </tr>
+ * <tr>
+ * <td>CACHED</td><td>X</td><td>X</td>
+ * <td>X</td><td></td><td></td><td></td><td></td>
+ * </tr>
+ * <tr>
+ * <td>ACCESS CACHED</td><td>X</td><td>X</td>
+ * <td></td><td></td><td></td><td>X</td><td>X</td>
+ * </tr>
+ * <tr>
+ * <td>ACCESS MODIFIED</td><td>X</td><td>X</td>
+ * <td></td><td></td><td></td><td>X</td><td>X</td>
+ * </tr>
+ * <tr>
+ * <td>ACCESS EMPTY</td><td></td><td>X</td>
+ * <td></td><td></td><td></td><td>X</td><td>X</td>
+ * </tr>
+ * <tr>
+ * <td>ACCESS PURGED</td><td></td><td>X</td>
+ * <td></td><td></td><td></td><td>X</td><td>X</td>
+ * </tr>
+ * <tr>
+ * <td>MODIFIED</td><td>X</td><td>X</td>
+ * <td></td><td>X</td><td></td><td>X</td><td></td>
+ * </tr>
+ * <tr>
+ * <td>SYNC</td><td>X</td><td>X</td>
+ * <td></td><td></td><td>X</td><td>X</td><td></td>
+ * </tr>
+ * <tr>
+ * <td>TRANSFER</td><td>X</td><td>X</td>
+ * <td></td><td></td><td></td><td>X</td><td>X</td>
+ * </tr>
+ * <tr>
+ * <td>TRANSFER PURGED</td><td></td><td>X</td>
+ * <td></td><td></td><td></td><td>X</td><td>X</td>
+ * </tr>
+ * </table>
+ */
+typedef enum
+{
+ /**
+ * @brief Free.
+ */
+ RTEMS_BDBUF_STATE_FREE = 0,
+
+ /**
+ * @brief Empty.
+ */
+ RTEMS_BDBUF_STATE_EMPTY,
+
+ /**
+ * @brief Cached.
+ */
+ RTEMS_BDBUF_STATE_CACHED,
+
+ /**
+ * @brief Accessed by upper layer with cached data.
+ */
+ RTEMS_BDBUF_STATE_ACCESS_CACHED,
+
+ /**
+ * @brief Accessed by upper layer with modified data.
+ */
+ RTEMS_BDBUF_STATE_ACCESS_MODIFIED,
+
+ /**
+ * @brief Accessed by upper layer with invalid data.
+ */
+ RTEMS_BDBUF_STATE_ACCESS_EMPTY,
+
+ /**
+ * @brief Accessed by upper layer with purged data.
+ */
+ RTEMS_BDBUF_STATE_ACCESS_PURGED,
+
+ /**
+ * @brief Modified by upper layer.
+ */
+ RTEMS_BDBUF_STATE_MODIFIED,
+
+ /**
+ * @brief Scheduled for synchronization.
+ */
+ RTEMS_BDBUF_STATE_SYNC,
+
+ /**
+ * @brief In transfer by block device driver.
+ */
+ RTEMS_BDBUF_STATE_TRANSFER,
+
+ /**
+ * @brief In transfer by block device driver and purged.
+ */
+ RTEMS_BDBUF_STATE_TRANSFER_PURGED
+} rtems_bdbuf_buf_state;
+
+/**
+ * Forward reference to the block.
+ */
+struct rtems_bdbuf_group;
+typedef struct rtems_bdbuf_group rtems_bdbuf_group;
+
+/**
+ * To manage buffers we using buffer descriptors (BD). A BD holds a buffer plus
+ * a range of other information related to managing the buffer in the cache. To
+ * speed-up buffer lookup descriptors are organized in AVL-Tree. The fields
+ * 'dev' and 'block' are search keys.
+ */
+typedef struct rtems_bdbuf_buffer
+{
+ rtems_chain_node link; /**< Link the BD onto a number of lists. */
+
+ struct rtems_bdbuf_avl_node
+ {
+ struct rtems_bdbuf_buffer* left; /**< Left Child */
+ struct rtems_bdbuf_buffer* right; /**< Right Child */
+ signed char cache; /**< Cache */
+ signed char bal; /**< The balance of the sub-tree */
+ } avl;
+
+ dev_t dev; /**< device number */
+
+ rtems_blkdev_bnum block; /**< block number on the device */
+
+ unsigned char* buffer; /**< Pointer to the buffer memory area */
+
+ volatile rtems_bdbuf_buf_state state; /**< State of the buffer. */
+
+ volatile uint32_t waiters; /**< The number of threads waiting on this
+ * buffer. */
+ rtems_bdbuf_group* group; /**< Pointer to the group of BDs this BD is
+ * part of. */
+ volatile uint32_t hold_timer; /**< Timer to indicate how long a buffer
+ * has been held in the cache modified. */
+
+ int references; /**< Allow reference counting by owner. */
+ void* user; /**< User data. */
+} rtems_bdbuf_buffer;
+
+/**
+ * A group is a continuous block of buffer descriptors. A group covers the
+ * maximum configured buffer size and is the allocation size for the buffers to
+ * a specific buffer size. If you allocate a buffer to be a specific size, all
+ * buffers in the group, if there are more than 1 will also be that size. The
+ * number of buffers in a group is a multiple of 2, ie 1, 2, 4, 8, etc.
+ */
+struct rtems_bdbuf_group
+{
+ rtems_chain_node link; /**< Link the groups on a LRU list if they
+ * have no buffers in use. */
+ size_t bds_per_group; /**< The number of BD allocated to this
+ * group. This value must be a multiple of
+ * 2. */
+ uint32_t users; /**< How many users the block has. */
+ rtems_bdbuf_buffer* bdbuf; /**< First BD this block covers. */
+};
+
+/**
+ * Buffering configuration definition. See confdefs.h for support on using this
+ * structure.
+ */
+typedef struct rtems_bdbuf_config {
+ uint32_t max_read_ahead_blocks; /**< Number of blocks to read
+ * ahead. */
+ uint32_t max_write_blocks; /**< Number of blocks to write
+ * at once. */
+ rtems_task_priority swapout_priority; /**< Priority of the swap out
+ * task. */
+ uint32_t swapout_period; /**< Period swapout checks buf
+ * timers. */
+ uint32_t swap_block_hold; /**< Period a buffer is held. */
+ size_t swapout_workers; /**< The number of worker
+ * threads for the swapout
+ * task. */
+ rtems_task_priority swapout_worker_priority; /**< Priority of the swap out
+ * task. */
+ size_t size; /**< Size of memory in the
+ * cache */
+ uint32_t buffer_min; /**< Minimum buffer size. */
+ uint32_t buffer_max; /**< Maximum buffer size
+ * supported. It is also the
+ * allocation size. */
+} rtems_bdbuf_config;
+
+/**
+ * External reference to the configuration.
+ *
+ * The configuration is provided by the application.
+ */
+extern const rtems_bdbuf_config rtems_bdbuf_configuration;
+
+/**
+ * The max_read_ahead_blocks value is altered if there are fewer buffers
+ * than this defined max. This stops thrashing in the cache.
+ */
+#define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT 0
+
+/**
+ * Default maximum number of blocks to write at once.
+ */
+#define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT 16
+
+/**
+ * Default swap-out task priority.
+ */
+#define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT 15
+
+/**
+ * Default swap-out task swap period in milli seconds.
+ */
+#define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
+
+/**
+ * Default swap-out task block hold time in milli seconds.
+ */
+#define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT 1000
+
+/**
+ * Default swap-out worker tasks. Currently disabled.
+ */
+#define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT 0
+
+/**
+ * Default swap-out worker task priority. The same as the swapout task.
+ */
+#define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
+ RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
+
+/**
+ * Default size of memory allocated to the cache.
+ */
+#define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
+
+/**
+ * Default minimum size of buffers.
+ */
+#define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
+
+/**
+ * Default maximum size of buffers.
+ */
+#define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
+
+/**
+ * Prepare buffering layer to work - initialize buffer descritors and (if it is
+ * neccessary) buffers. After initialization all blocks is placed into the
+ * ready state.
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_init (void);
+
+/**
+ * Get block buffer for data to be written into. The buffers is set to the
+ * access or modifed access state. If the buffer is in the cache and modified
+ * the state is access modified else the state is access. This buffer contents
+ * are not initialised if the buffer is not already in the cache. If the block
+ * is already resident in memory it is returned how-ever if not in memory the
+ * buffer is not read from disk. This call is used when writing the whole block
+ * on a disk rather than just changing a part of it. If there is no buffers
+ * available this call will block. A buffer obtained with this call will not be
+ * involved in a transfer request and will not be returned to another user
+ * until released. If the buffer is already with a user when this call is made
+ * the call is blocked until the buffer is returned. The highest priority
+ * waiter will obtain the buffer first.
+ *
+ * The block number is the linear block number. This is relative to the start
+ * of the partition on the media.
+ *
+ * @param device Device number (constructed of major and minor device number)
+ * @param block Linear media block number
+ * @param bd Reference to the buffer descriptor pointer.
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_get (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
+
+/**
+ * Get the block buffer and if not already in the cache read from the disk. If
+ * specified block already cached return. The buffer is set to the access or
+ * modifed access state. If the buffer is in the cache and modified the state
+ * is access modified else the state is access. If block is already being read
+ * from disk for being written to disk this call blocks. If the buffer is
+ * waiting to be written it is removed from modified queue and returned to the
+ * user. If the buffer is not in the cache a new buffer is obtained and the
+ * data read from disk. The call may block until these operations complete. A
+ * buffer obtained with this call will not be involved in a transfer request
+ * and will not be returned to another user until released. If the buffer is
+ * already with a user when this call is made the call is blocked until the
+ * buffer is returned. The highest priority waiter will obtain the buffer
+ * first.
+ *
+ * @param device Device number (constructed of major and minor device number)
+ * @param block Linear media block number
+ * @param bd Reference to the buffer descriptor pointer.
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_read (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
+
+/**
+ * Release the buffer obtained by a read call back to the cache. If the buffer
+ * was obtained by a get call and was not already in the cache the release
+ * modified call should be used. A buffer released with this call obtained by a
+ * get call may not be in sync with the contents on disk. If the buffer was in
+ * the cache and modified before this call it will be returned to the modified
+ * queue. The buffers is returned to the end of the LRU list.
+ *
+ * @param bd Reference to the buffer descriptor.
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
+
+/**
+ * Release the buffer allocated with a get or read call placing it on the
+ * modidied list. If the buffer was not released modified before the hold
+ * timer is set to the configuration value. If the buffer had been released
+ * modified before but not written to disk the hold timer is not updated. The
+ * buffer will be written to disk when the hold timer has expired, there are
+ * not more buffers available in the cache and a get or read buffer needs one
+ * or a sync call has been made. If the buffer is obtained with a get or read
+ * before the hold timer has expired the buffer will be returned to the user.
+ *
+ * @param bd Reference to the buffer descriptor.
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
+
+/**
+ * Release the buffer as modified and wait until it has been synchronized with
+ * the disk by writing it. This buffer will be the first to be transfer to disk
+ * and other buffers may also be written if the maximum number of blocks in a
+ * requests allows it.
+ *
+ * @note This code does not lock the sync mutex and stop additions to the
+ * modified queue.
+
+ * @param bd Reference to the buffer descriptor.
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
+
+/**
+ * Synchronize all modified buffers for this device with the disk and wait
+ * until the transfers have completed. The sync mutex for the cache is locked
+ * stopping the addition of any further modifed buffers. It is only the
+ * currently modified buffers that are written.
+ *
+ * @note Nesting calls to sync multiple devices will be handled sequentially. A
+ * nested call will be blocked until the first sync request has complete.
+ *
+ * @param dev Block device number
+ *
+ * @return RTEMS status code (RTEMS_SUCCESSFUL if operation completed
+ * successfully or error code if error is occured)
+ */
+rtems_status_code
+rtems_bdbuf_syncdev (dev_t dev);
+
+/**
+ * @brief Purges all buffers that matches the device identifier @a dev.
+ *
+ * This may result in loss of data.
+ */
+void
+rtems_bdbuf_purge_dev (dev_t dev);
+
+/**
+ * @brief Purges all buffers that matches the device major number @a major.
+ *
+ * This may result in loss of data.
+ */
+void
+rtems_bdbuf_purge_major (rtems_device_major_number major);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libblock/include/rtems/bdpart.h b/cpukit/libblock/include/rtems/bdpart.h
new file mode 100644
index 0000000000..907866eb43
--- /dev/null
+++ b/cpukit/libblock/include/rtems/bdpart.h
@@ -0,0 +1,409 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef RTEMS_BDPART_H
+#define RTEMS_BDPART_H
+
+#include <uuid/uuid.h>
+
+#include <rtems.h>
+#include <rtems/blkdev.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup rtems_bdpart Block Device Partition Management
+ *
+ * @ingroup rtems_libblock
+ *
+ * This module provides functions to manage partitions of a disk device.
+ *
+ * A @ref rtems_disk "disk" is a set of blocks which are identified by a
+ * consecutive set of non-negative integers starting at zero. There are also
+ * logical disks which contain a subset of consecutive disk blocks. The
+ * logical disks are used to represent the partitions of a disk. The disk
+ * devices are accessed via the @ref rtems_disk "block device buffer module".
+ *
+ * The partition format on the physical disk will be converted to an internal
+ * representation. It is possible to convert the internal representation into
+ * a specific output format and write it to the physical disk. One of the
+ * constrains for the internal representation was to support the GPT format
+ * easily.
+ *
+ * Currently two physical partition formats are supported. These are the MBR
+ * and the GPT format. Please note that the GPT support is not implemented.
+ * With MBR format we mean the partition format of the wide spread IBM
+ * PC-compatible systems. The GPT format is defined in the Extensible Firmware
+ * Interface (EFI).
+ *
+ * The most common task will be to read the partition information of a disk and
+ * register logical disks for each partition. This can be done with the
+ * rtems_bdpart_register_from_disk() function. Afterwards you can
+ * @ref rtems_fsmount "mount" the file systems within the partitions.
+ *
+ * You can read the partition information from a disk with rtems_bdpart_read()
+ * and write it to the disk with rtems_bdpart_write().
+ *
+ * To create a partition table from scratch for a disk use
+ * rtems_bdpart_create().
+ *
+ * You can access some disk functions with the shell command @c fdisk.
+ *
+ * References used to create this module:
+ * - <a href="http://en.wikipedia.org/wiki/UUID">Universally Unique Identifier</a>
+ * - <a href="http://en.wikipedia.org/wiki/Globally_Unique_Identifier">Globally Unique Identifier</a>
+ * - <a href="http://en.wikipedia.org/wiki/Disk_partitioning">Disk Paritioning</a>
+ * - <a href="http://en.wikipedia.org/wiki/GUID_Partition_Table">GUID Partition Table</a>
+ * - <a href="http://en.wikipedia.org/wiki/Master_boot_record">Master Boot Record</a>
+ * - <a href="http://en.wikipedia.org/wiki/Extended_boot_record">Extended Boot Record</a>
+ * - <a href="http://en.wikipedia.org/wiki/Cylinder-head-sector">Cylinder Head Sector</a>
+ * - <a href="http://www.win.tue.nl/~aeb/partitions/partition_types-1.html">Partition Types</a>
+ *
+ * @{
+ */
+
+/**
+ * @name MBR Partition Types and Flags
+ *
+ * @{
+ */
+
+#define RTEMS_BDPART_MBR_EMPTY 0x0U
+
+#define RTEMS_BDPART_MBR_FAT_12 0x1U
+
+#define RTEMS_BDPART_MBR_FAT_16 0x4U
+
+#define RTEMS_BDPART_MBR_FAT_16_LBA 0xeU
+
+#define RTEMS_BDPART_MBR_FAT_32 0xbU
+
+#define RTEMS_BDPART_MBR_FAT_32_LBA 0xcU
+
+#define RTEMS_BDPART_MBR_EXTENDED 0x5U
+
+#define RTEMS_BDPART_MBR_DATA 0xdaU
+
+#define RTEMS_BDPART_MBR_GPT 0xeeU
+
+#define RTEMS_BDPART_MBR_FLAG_ACTIVE 0x80U
+
+/** @} */
+
+/**
+ * Recommended maximum partition table size.
+ */
+#define RTEMS_BDPART_PARTITION_NUMBER_HINT 16
+
+/**
+ * Partition description.
+ */
+typedef struct rtems_bdpart_partition {
+ /**
+ * Block index for partition begin.
+ */
+ rtems_blkdev_bnum begin;
+
+ /**
+ * Block index for partition end (this block is not a part of the partition).
+ */
+ rtems_blkdev_bnum end;
+
+ /**
+ * Partition type.
+ */
+ uuid_t type;
+
+ /**
+ * Partition ID.
+ */
+ uuid_t id;
+
+ /**
+ * Partition flags.
+ */
+ uint64_t flags;
+} rtems_bdpart_partition;
+
+/**
+ * Disk format for the partition tables.
+ */
+typedef enum {
+ /**
+ * Type value for MBR format.
+ */
+ RTEMS_BDPART_FORMAT_MBR,
+
+ /**
+ * Type value for GPT format.
+ */
+ RTEMS_BDPART_FORMAT_GPT
+} rtems_bdpart_format_type;
+
+/**
+ * Disk format description.
+ */
+typedef union {
+ /**
+ * Format type.
+ */
+ rtems_bdpart_format_type type;
+
+ /**
+ * MBR format fields.
+ */
+ struct {
+ rtems_bdpart_format_type type;
+
+ /**
+ * Disk ID in MBR at offset 440.
+ */
+ uint32_t disk_id;
+
+ /**
+ * This option is used for partition table creation and validation checks
+ * before a write to the disk. It ensures that the first primary
+ * partition and the logical partitions start at head one and sector one
+ * under the virtual one head and 63 sectors geometry. Each begin and
+ * end of a partition will be aligned to the virtual cylinder boundary.
+ */
+ bool dos_compatibility;
+ } mbr;
+
+ /**
+ * GPT format fields.
+ */
+ struct {
+ rtems_bdpart_format_type type;
+
+ /**
+ * Disk ID in GPT header.
+ */
+ uuid_t disk_id;
+ } gpt;
+} rtems_bdpart_format;
+
+/**
+ * Reads the partition information from the physical disk device with name
+ * @a disk_name.
+ *
+ * The partition information will be stored in the partition table
+ * @a partitions with a maximum of @a count partitions. The number of actual
+ * partitions will be stored in @a count. If there are more partitions than
+ * space for storage an error status will be returned. The partition table
+ * format recognized on the disk will be stored in @a format.
+ */
+rtems_status_code rtems_bdpart_read(
+ const char *disk_name,
+ rtems_bdpart_format *format,
+ rtems_bdpart_partition *partitions,
+ size_t *count
+);
+
+/**
+ * Sorts the partition table @a partitions with @a count partitions to have
+ * ascending begin blocks
+ */
+void rtems_bdpart_sort( rtems_bdpart_partition *partitions, size_t count);
+
+/**
+ * Writes the partition table to the physical disk device with name
+ * @a disk_name.
+ *
+ * The partition table @a partitions with @a count partitions will be written
+ * to the disk. The output format for the partition table on the disk is
+ * specified by @a format. There are some consistency checks applied to the
+ * partition table. The partition table must be sorted such that the begin
+ * blocks are in ascending order. This can be done with the
+ * rtems_bdpart_sort() function. The partitions must not overlap. The
+ * partitions must have a positive size. The partitions must be within the
+ * disk. Depending on the output format there are additional constrains.
+ */
+rtems_status_code rtems_bdpart_write(
+ const char *disk_name,
+ const rtems_bdpart_format *format,
+ const rtems_bdpart_partition *partitions,
+ size_t count
+);
+
+/**
+ * Creates a partition table in @a partitions with @a count partitions for the
+ * physical disk device with name @a disk_name.
+ *
+ * The array of positive integer weights in @a distribution must have exactly
+ * @a count elements. The weights in the distribution array are summed up.
+ * Each weight is then divided by the sum to obtain the disk fraction which
+ * forms the corresponding partition. The partition boundaries are generated
+ * with respect to the output format in @a format.
+ */
+rtems_status_code rtems_bdpart_create(
+ const char *disk_name,
+ const rtems_bdpart_format *format,
+ rtems_bdpart_partition *partitions,
+ const unsigned *distribution,
+ size_t count
+);
+
+/**
+ * Registers the partitions as logical disks for the physical disk device with
+ * name @a disk_name.
+ *
+ * For each partition of the partition table @a partitions with @a count
+ * partitions a logical disk is registered. The partition number equals the
+ * partition table index plus one. The name of the logical disk device is the
+ * concatenation of the physical disk device name and the partition number.
+ */
+rtems_status_code rtems_bdpart_register(
+ const char *disk_name,
+ const rtems_bdpart_partition *partitions,
+ size_t count
+);
+
+/**
+ * Reads the partition table from the disk device with name @a disk_name and
+ * registers the partitions as logical disks.
+ *
+ * @see rtems_bdpart_register() and rtems_fsmount().
+ */
+rtems_status_code rtems_bdpart_register_from_disk( const char *disk_name);
+
+/**
+ * Deletes the logical disks associated with the partitions of the disk device
+ * with name @a disk_name.
+ *
+ * The partition table @a partitions with @a count partitions will be used to
+ * determine which disks need to be deleted. It may be obtained from
+ * rtems_bdpart_read().
+ */
+rtems_status_code rtems_bdpart_unregister(
+ const char *disk_name,
+ const rtems_bdpart_partition *partitions,
+ size_t count
+);
+
+/**
+ * Mounts all supported file systems inside the logical disks derived from the
+ * partitions of the physical disk device with name @a disk_name.
+ *
+ * For each partition in the partition table @a partitions with @a count
+ * partitions it will be checked if it contains a supported file system. In
+ * this case a mount point derived from the disk name will be created in the
+ * mount base path @a mount_base. The file system will be mounted there. The
+ * partition number equals the partition table index plus one. The mount point
+ * name for each partition will be the concatenation of the mount base path,
+ * the disk device file name and the parition number.
+ *
+ * @see rtems_bdpart_read().
+ */
+rtems_status_code rtems_bdpart_mount(
+ const char *disk_name,
+ const rtems_bdpart_partition *partitions,
+ size_t count,
+ const char *mount_base
+);
+
+/**
+ * Unmounts all file systems mounted with rtems_bdpart_mount().
+ */
+rtems_status_code rtems_bdpart_unmount(
+ const char *disk_name,
+ const rtems_bdpart_partition *partitions,
+ size_t count,
+ const char *mount_base
+);
+
+/**
+ * Prints the partition table @a partitions with @a count partitions to
+ * standard output.
+ */
+void rtems_bdpart_dump( const rtems_bdpart_partition *partitions, size_t count);
+
+/**
+ * Returns the partition type for the MBR partition type value @a mbr_type in
+ * @a type.
+ */
+void rtems_bdpart_to_partition_type( uint8_t mbr_type, uuid_t type);
+
+/**
+ * Converts the partition type in @a type to the MBR partition type.
+ *
+ * The result will be stored in @a mbr_type. Returns @c true in case of a
+ * successful convertion and otherwise @c false. Both arguments must not be
+ * @c NULL.
+ */
+bool rtems_bdpart_to_mbr_partition_type(
+ const uuid_t type,
+ uint8_t *mbr_type
+);
+
+/** @} */
+
+#define RTEMS_BDPART_MBR_CYLINDER_SIZE 63
+
+#define RTEMS_BDPART_NUMBER_SIZE 4
+
+#define RTEMS_BDPART_BLOCK_SIZE 512
+
+#define RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE 16
+
+#define RTEMS_BDPART_MBR_OFFSET_TABLE_0 446
+
+#define RTEMS_BDPART_MBR_OFFSET_TABLE_1 \
+ (RTEMS_BDPART_MBR_OFFSET_TABLE_0 + RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE)
+
+#define RTEMS_BDPART_MBR_OFFSET_DISK_ID 440
+
+#define RTEMS_BDPART_MBR_OFFSET_SIGNATURE_0 510
+
+#define RTEMS_BDPART_MBR_OFFSET_SIGNATURE_1 511
+
+#define RTEMS_BDPART_MBR_SIGNATURE_0 0x55U
+
+#define RTEMS_BDPART_MBR_SIGNATURE_1 0xaaU
+
+#define RTEMS_BDPART_MBR_OFFSET_BEGIN 8
+
+#define RTEMS_BDPART_MBR_OFFSET_SIZE 12
+
+#define RTEMS_BDPART_MBR_OFFSET_TYPE 4
+
+#define RTEMS_BDPART_MBR_OFFSET_FLAGS 0
+
+static inline uint8_t rtems_bdpart_mbr_partition_type(
+ const uuid_t type
+)
+{
+ return type [0];
+}
+
+rtems_status_code rtems_bdpart_get_disk_data(
+ const char *disk_name,
+ dev_t *disk,
+ rtems_blkdev_bnum *disk_end
+);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RTEMS_BDPART_H */
diff --git a/cpukit/libblock/include/rtems/blkdev.h b/cpukit/libblock/include/rtems/blkdev.h
new file mode 100644
index 0000000000..e9fa86b248
--- /dev/null
+++ b/cpukit/libblock/include/rtems/blkdev.h
@@ -0,0 +1,276 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_blkdev
+ *
+ * Block device management.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#ifndef _RTEMS_BLKDEV_H
+#define _RTEMS_BLKDEV_H
+
+#include <rtems.h>
+#include <rtems/diskdevs.h>
+#include <sys/ioctl.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup rtems_blkdev Block Device Management
+ *
+ * @ingroup rtems_libblock
+ *
+ * Interface between device drivers and the
+ * @ref rtems_bdbuf "block device buffer module".
+ *
+ * The heart of the block device driver is the @ref RTEMS_BLKIO_REQUEST IO
+ * control. This call puts IO @ref rtems_blkdev_request "requests" to the block
+ * device for asynchronous processing. When a driver executes a request, it
+ * invokes the request done callback function to finish the request.
+ *
+ * @{
+ */
+
+/**
+ * Block device request type.
+ *
+ * @warning The sync request is an IO one and only used from the cache. Use the
+ * Block IO when operating at the device level. We need a sync request
+ * to avoid requests looping for ever.
+ */
+typedef enum rtems_blkdev_request_op {
+ RTEMS_BLKDEV_REQ_READ, /**< Read the requested blocks of data. */
+ RTEMS_BLKDEV_REQ_WRITE, /**< Write the requested blocks of data. */
+ RTEMS_BLKDEV_REQ_SYNC /**< Sync any data with the media. */
+} rtems_blkdev_request_op;
+
+/**
+ * @brief Block device request done callback function type.
+ *
+ * The first parameter @a arg must be the argument provided by the block device
+ * request structure @ref rtems_blkdev_request.
+ *
+ * The second parameter @a status should contain the status of the operation:
+ * - @c RTEMS_SUCCESSFUL Operation was successful.
+ * - @c RTEMS_IO_ERROR Some sort of input or output error.
+ * - @c RTEMS_UNSATISFIED Media no more present.
+ */
+typedef void (*rtems_blkdev_request_cb)(void *arg, rtems_status_code status);
+
+/**
+ * Block device scatter or gather buffer structure.
+ */
+typedef struct rtems_blkdev_sg_buffer {
+ /**
+ * Block index.
+ */
+ rtems_blkdev_bnum block;
+
+ /**
+ * Buffer length.
+ */
+ uint32_t length;
+
+ /**
+ * Buffer pointer.
+ */
+ void *buffer;
+
+ /**
+ * User pointer.
+ */
+ void *user;
+} rtems_blkdev_sg_buffer;
+
+/**
+ * The block device request structure is used to read or write a number of
+ * blocks from or to the device.
+ *
+ * TODO: The use of these req blocks is not a great design. The req is a
+ * struct with a single 'bufs' declared in the req struct and the
+ * others are added in the outer level struct. This relies on the
+ * structs joining as a single array and that assumes the compiler
+ * packs the structs. Why not just place on a list ? The BD has a
+ * node that can be used.
+ */
+typedef struct rtems_blkdev_request {
+ /**
+ * Block device operation (read or write).
+ */
+ rtems_blkdev_request_op req;
+
+ /**
+ * Request done callback function.
+ */
+ rtems_blkdev_request_cb req_done;
+
+ /**
+ * Argument to be passed to callback function.
+ */
+ void *done_arg;
+
+ /**
+ * Last IO operation completion status.
+ */
+ rtems_status_code status;
+
+ /**
+ * Number of blocks for this request.
+ */
+ uint32_t bufnum;
+
+ /**
+ * The task requesting the IO operation.
+ */
+ rtems_id io_task;
+
+ /**
+ * List of scatter or gather buffers.
+ */
+ rtems_blkdev_sg_buffer bufs[0];
+} rtems_blkdev_request;
+
+/**
+ * The start block in a request.
+ *
+ * Only valid if the driver has returned the @ref RTEMS_BLKIO_CAPABILITIES of
+ * @ref RTEMS_BLKDEV_CAP_MULTISECTOR_CONT.
+ */
+#define RTEMS_BLKDEV_START_BLOCK(req) (req->bufs[0].block)
+
+/**
+ * @name IO Control Request Codes
+ *
+ * @{
+ */
+
+#define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request)
+#define RTEMS_BLKIO_GETMEDIABLKSIZE _IOR('B', 2, uint32_t)
+#define RTEMS_BLKIO_GETBLKSIZE _IOR('B', 3, uint32_t)
+#define RTEMS_BLKIO_SETBLKSIZE _IOW('B', 4, uint32_t)
+#define RTEMS_BLKIO_GETSIZE _IOR('B', 5, rtems_blkdev_bnum)
+#define RTEMS_BLKIO_SYNCDEV _IO('B', 6)
+#define RTEMS_BLKIO_DELETED _IO('B', 7)
+#define RTEMS_BLKIO_CAPABILITIES _IO('B', 8)
+
+/** @} */
+
+/**
+ * Only consecutive multi-sector buffer requests are supported.
+ *
+ * This option means the cache will only supply multiple buffers that are
+ * inorder so the ATA multi-sector command for example can be used. This is a
+ * hack to work around the current ATA driver.
+ */
+#define RTEMS_BLKDEV_CAP_MULTISECTOR_CONT (1 << 0)
+
+/**
+ * The driver will accept a sync call. A sync call is made to a driver
+ * after a bdbuf cache sync has finished.
+ */
+#define RTEMS_BLKDEV_CAP_SYNC (1 << 1)
+
+/**
+ * The device driver interface conventions suppose that a driver may contain an
+ * initialize, open, close, read, write and IO control entry points. These
+ * primitives (except initialize) can be implemented in a generic fashion based
+ * upon the supplied block device driver IO control handler. Every block device
+ * driver should provide an initialize entry point, which registers the
+ * appropriate IO control handler.
+ */
+#define RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \
+ rtems_blkdev_generic_open, \
+ rtems_blkdev_generic_close, \
+ rtems_blkdev_generic_read, \
+ rtems_blkdev_generic_write, \
+ rtems_blkdev_generic_ioctl
+
+/**
+ * Generic block device read primitive.
+ *
+ * Implemented using block device buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+);
+
+/**
+ * Generic block device write primitive.
+ *
+ * Implemented using block device buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+);
+
+/**
+ * Generic block device open primitive.
+ *
+ * Implemented using block device buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+);
+
+/**
+ * Generic block device close primitive.
+ *
+ * Implemented using block device buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+);
+
+/**
+ * Generic block device IO control primitive.
+ *
+ * Implemented using block device buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_ioctl(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+);
+
+/**
+ * Common IO control primitive.
+ *
+ * Use this in all block devices to handle the common set of ioctl requests.
+ */
+int
+rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
+
+/**
+ * @brief Generic block operations driver address table.
+ */
+extern const rtems_driver_address_table rtems_blkdev_generic_ops;
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libblock/include/rtems/diskdevs.h b/cpukit/libblock/include/rtems/diskdevs.h
new file mode 100644
index 0000000000..8884999d95
--- /dev/null
+++ b/cpukit/libblock/include/rtems/diskdevs.h
@@ -0,0 +1,341 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_disk
+ *
+ * @brief Block device disk management API.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#ifndef _RTEMS_DISKDEVS_H
+#define _RTEMS_DISKDEVS_H
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct rtems_disk_device rtems_disk_device;
+
+/**
+ * @defgroup rtems_disk Block Device Disk Management
+ *
+ * @ingroup rtems_libblock
+ *
+ * @brief This module provides functions to manage disk devices.
+ *
+ * A disk is a set of blocks which are identified by a consecutive set of
+ * non-negative integers starting at zero. There are also logical disks which
+ * contain a subset of consecutive disk blocks. The logical disks are used to
+ * represent the partitions of a disk. The disk devices are accessed via the
+ * @ref rtems_bdbuf "block device buffer module".
+ *
+ * @{
+ */
+
+/**
+ * @brief Block device block index type.
+ */
+typedef uint32_t rtems_blkdev_bnum;
+
+/**
+ * @brief Block device IO control handler type.
+ */
+typedef int (*rtems_block_device_ioctl)(
+ rtems_disk_device *dd,
+ uint32_t req,
+ void *argp
+);
+
+/**
+ * @brief Description of a disk device (logical and physical disks).
+ *
+ * An array of pointer tables to rtems_disk_device structures is maintained.
+ * The first table will be indexed by the major number and the second table
+ * will be indexed by the minor number. This allows quick lookup using a data
+ * structure of moderated size.
+ */
+struct rtems_disk_device {
+ /**
+ * @brief Device identifier (concatenation of major and minor number).
+ */
+ dev_t dev;
+
+ /**
+ * @brief Physical device identifier (equals the @c dev entry if it specifies a
+ * physical device).
+ */
+ rtems_disk_device *phys_dev;
+
+ /**
+ * @brief Driver capabilities.
+ */
+ uint32_t capabilities;
+
+ /**
+ * @brief Disk device name.
+ */
+ char *name;
+
+ /**
+ * @brief Usage counter.
+ *
+ * Devices cannot be deleted if they are in use.
+ */
+ unsigned uses;
+
+ /**
+ * @brief Start block number.
+ *
+ * Equals zero for physical devices. It is a block offset to the related
+ * physical device for logical device.
+ */
+ rtems_blkdev_bnum start;
+
+ /**
+ * @brief Size of the physical or logical disk in blocks.
+ */
+ rtems_blkdev_bnum size;
+
+ /**
+ * @brief Device block size in bytes.
+ *
+ * This is the minimum transfer unit. It can be any size.
+ */
+ uint32_t block_size;
+
+ /**
+ * @brief Device media block size in bytes.
+ *
+ * This is the media transfer unit the hardware defaults to.
+ */
+ uint32_t media_block_size;
+
+ /**
+ * @brief IO control handler for this disk.
+ */
+ rtems_block_device_ioctl ioctl;
+
+ /**
+ * @brief Private data for the disk driver.
+ */
+ void *driver_data;
+
+ /**
+ * @brief Indicates that this disk should be deleted as soon as the last user
+ * releases this disk.
+ */
+ bool deleted;
+};
+
+/**
+ * @name Disk Device Data
+ *
+ * @{
+ */
+
+static inline dev_t rtems_disk_get_device_identifier(
+ const rtems_disk_device *dd
+)
+{
+ return dd->dev;
+}
+
+static inline rtems_device_major_number rtems_disk_get_major_number(
+ const rtems_disk_device *dd
+)
+{
+ return rtems_filesystem_dev_major_t(dd->dev);
+}
+
+static inline rtems_device_minor_number rtems_disk_get_minor_number(
+ const rtems_disk_device *dd
+)
+{
+ return rtems_filesystem_dev_minor_t(dd->dev);
+}
+
+static inline void *rtems_disk_get_driver_data(
+ const rtems_disk_device *dd
+)
+{
+ return dd->driver_data;
+}
+
+static inline uint32_t rtems_disk_get_media_block_size(
+ const rtems_disk_device *dd
+)
+{
+ return dd->media_block_size;
+}
+
+/** @} */
+
+/**
+ * @name Disk Device Maintainance
+ *
+ * @{
+ */
+
+/**
+ * @brief Creates a physical disk with device identifier @a dev.
+ *
+ * The block size @a block_size must be positive. The disk will have
+ * @a block_count blocks. The block index starts with zero. The associated disk
+ * device driver will be invoked via the IO control handler @a handler. A
+ * device node will be registered in the file system with absolute path @a
+ * name, if @a name is not @c NULL. This function is usually invoked from a
+ * block device driver during initialization when a physical device is detected
+ * in the system. The device driver provides an IO control handler to allow
+ * block device operations.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
+ * @retval RTEMS_INVALID_ADDRESS IO control handler is @c NULL.
+ * @retval RTEMS_INVALID_NUMBER Block size is zero.
+ * @retval RTEMS_NO_MEMORY Not enough memory.
+ * @retval RTEMS_RESOURCE_IN_USE Disk device descriptor is already in use.
+ * @retval RTEMS_UNSATISFIED Cannot create device node.
+ */
+rtems_status_code rtems_disk_create_phys(
+ dev_t dev,
+ uint32_t block_size,
+ rtems_blkdev_bnum block_count,
+ rtems_block_device_ioctl handler,
+ void *driver_data,
+ const char *name
+);
+
+/**
+ * @brief Creates a logical disk with device identifier @a dev.
+ *
+ * A logical disk manages a subset of consecutive blocks contained in the
+ * physical disk with identifier @a phys. The start block index of the logical
+ * disk device is @a begin_block. The block count of the logcal disk will be
+ * @a block_count. The blocks must be within the range of blocks managed by
+ * the associated physical disk device. A device node will be registered in
+ * the file system with absolute path @a name, if @a name is not @c NULL. The
+ * block size and IO control handler are inherited by the physical disk.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
+ * @retval RTEMS_INVALID_ID Specified physical disk identifier does not
+ * correspond to a physical disk.
+ * @retval RTEMS_INVALID_NUMBER Begin block or block count are out of range.
+ * @retval RTEMS_NO_MEMORY Not enough memory.
+ * @retval RTEMS_RESOURCE_IN_USE Disk device descriptor for logical disk
+ * identifier is already in use.
+ * @retval RTEMS_UNSATISFIED Cannot create device node.
+ */
+rtems_status_code rtems_disk_create_log(
+ dev_t dev,
+ dev_t phys,
+ rtems_blkdev_bnum begin_block,
+ rtems_blkdev_bnum block_count,
+ const char *name
+);
+
+/**
+ * @brief Deletes a physical or logical disk device with identifier @a dev.
+ *
+ * Marks the disk device as deleted. When a physical disk device is deleted,
+ * all corresponding logical disk devices will marked as deleted too. Disks
+ * that are marked as deleted and have a usage counter of zero will be deleted.
+ * The corresponding device nodes will be removed from the file system. In
+ * case of a physical disk deletion the IO control handler will be invoked with
+ * a RTEMS_BLKIO_DELETED request. Disks that are still in use will be deleted
+ * upon release.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
+ * @retval RTEMS_INVALID_ID No disk for specified device identifier.
+ */
+rtems_status_code rtems_disk_delete(dev_t dev);
+
+/**
+ * @brief Returns the disk device descriptor for the device identifier @a dev.
+ *
+ * Increments usage counter by one. You should release the disk device
+ * descriptor with rtems_disk_release().
+ *
+ * @return Pointer to the disk device descriptor or @c NULL if no corresponding
+ * disk exists.
+ */
+rtems_disk_device *rtems_disk_obtain(dev_t dev);
+
+/**
+ * @brief Releases the disk device descriptor @a dd.
+ *
+ * Decrements usage counter by one.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ */
+rtems_status_code rtems_disk_release(rtems_disk_device *dd);
+
+/** @} */
+
+/**
+ * @name Disk Management
+ *
+ * @{
+ */
+
+/**
+ * @brief Initializes the disk device management.
+ *
+ * This functions returns successful if the disk device management is already
+ * initialized. There is no protection against concurrent access.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful initialization.
+ * @retval RTEMS_NO_MEMORY Not enough memory or no semaphore available.
+ * @retval RTEMS_UNSATISFIED Block device buffer initialization failed.
+ */
+rtems_status_code rtems_disk_io_initialize(void);
+
+/**
+ * @brief Releases all resources allocated for disk device management.
+ *
+ * There is no protection against concurrent access. If parts of the system
+ * are still in use the behaviour is undefined.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ */
+rtems_status_code rtems_disk_io_done(void);
+
+/** @} */
+
+/** @} */
+
+/**
+ * @brief Disk device iterator.
+ *
+ * Returns the next disk device descriptor with a device identifier larger than
+ * @a dev. If there is no such device, @c NULL will be returned. Use minus
+ * one to start the search.
+ *
+ * @code
+ * rtems_status_code sc = RTEMS_SUCCESSFUL;
+ * rtems_disk_device *dd = (dev_t) -1;
+ *
+ * while (sc == RTEMS_SUCCESSFUL && (dd = rtems_disk_next(dev)) != NULL) {
+ * dev = rtems_disk_get_device_identifier(dd);
+ * sc = rtems_disk_release(dd);
+ * }
+ * @endcode
+ */
+rtems_disk_device *rtems_disk_next(dev_t dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libblock/include/rtems/flashdisk.h b/cpukit/libblock/include/rtems/flashdisk.h
new file mode 100644
index 0000000000..c24b9b08be
--- /dev/null
+++ b/cpukit/libblock/include/rtems/flashdisk.h
@@ -0,0 +1,366 @@
+/*
+ * flashdisk.h -- Flash disk block device implementation
+ *
+ * Copyright (C) 2007 Chris Johns
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if !defined (_RTEMS_FLASHDISK_H_)
+#define _RTEMS_FLASHDISK_H_
+
+#include <stdint.h>
+#include <sys/ioctl.h>
+
+#include <rtems.h>
+
+/**
+ * The base name of the flash disks.
+ */
+#define RTEMS_FLASHDISK_DEVICE_BASE_NAME "/dev/fdd"
+
+/**
+ * Flash disk specific ioctl request types. To use open the
+ * device and issue the ioctl call.
+ *
+ * @code
+ * int fd = open ("/dev/flashdisk0", O_WRONLY, 0);
+ * if (fd < 0)
+ * {
+ * printf ("driver open failed: %s\n", strerror (errno));
+ * exit (1);
+ * }
+ * if (ioctl (fd, RTEMS_FDISK_IOCTL_ERASE_DISK) < 0)
+ * {
+ * printf ("driver erase failed: %s\n", strerror (errno));
+ * exit (1);
+ * }
+ * close (fd);
+ * @endcode
+ */
+#define RTEMS_FDISK_IOCTL_ERASE_DISK _IO('B', 128)
+#define RTEMS_FDISK_IOCTL_COMPACT _IO('B', 129)
+#define RTEMS_FDISK_IOCTL_ERASE_USED _IO('B', 130)
+#define RTEMS_FDISK_IOCTL_MONITORING _IO('B', 131)
+#define RTEMS_FDISK_IOCTL_INFO_LEVEL _IO('B', 132)
+#define RTEMS_FDISK_IOCTL_PRINT_STATUS _IO('B', 133)
+
+/**
+ * Flash Disk Monitoring Data allows a user to obtain
+ * the current status of the disk.
+ */
+typedef struct rtems_fdisk_monitor_data
+{
+ uint32_t block_size;
+ uint32_t block_count;
+ uint32_t unavail_blocks;
+ uint32_t device_count;
+ uint32_t segment_count;
+ uint32_t page_count;
+ uint32_t blocks_used;
+ uint32_t segs_available;
+ uint32_t segs_used;
+ uint32_t segs_failed;
+ uint32_t seg_erases;
+ uint32_t pages_desc;
+ uint32_t pages_active;
+ uint32_t pages_used;
+ uint32_t pages_bad;
+ uint32_t info_level;
+} rtems_fdisk_monitor_data;
+
+/**
+ * Flash Segment Descriptor holds, number of continuous segments in the
+ * device of this type, the base segment number in the device, the
+ * address offset of the base segment in the device, and the size of
+ * segment.
+ *
+ * Typically this structure is part of a table of segments in the
+ * device which is referenced in the flash disk configuration table.
+ * The reference is kept in the driver and used all the time to
+ * manage the flash device, therefore it must always exist.
+ */
+typedef struct rtems_fdisk_segment_desc
+{
+ uint16_t count; /**< Number of segments of this type in a row. */
+ uint16_t segment; /**< The base segment number. */
+ uint32_t offset; /**< Address offset of base segment in device. */
+ uint32_t size; /**< Size of the segment in bytes. */
+} rtems_fdisk_segment_desc;
+
+/**
+ * Return the number of kilo-bytes.
+ */
+#define RTEMS_FDISK_KBYTES(_k) (UINT32_C(1024) * (_k))
+
+/**
+ * Forward declaration of the device descriptor.
+ */
+struct rtems_fdisk_device_desc;
+
+/**
+ * Flash Low Level driver handlers.
+
+ * Typically this structure is part of a table of handlers in the
+ * device which is referenced in the flash disk configuration table.
+ * The reference is kept in the driver and used all the time to
+ * manage the flash device, therefore it must always exist.
+ */
+typedef struct rtems_fdisk_driver_handlers
+{
+ /**
+ * Read data from the device into the buffer. Return an errno
+ * error number if the device cannot be read. A segment descriptor
+ * can describe more than one segment in a device if the device has
+ * repeating segments. The segment number is the device segment to
+ * access and the segment descriptor must reference the segment
+ * being requested. For example the segment number must resided in
+ * the range [base, base + count).
+ *
+ * @param sd The segment descriptor.
+ * @param device The device to read data from.
+ * @param segment The segment within the device to read.
+ * @param offset The offset in the segment to read.
+ * @param buffer The buffer to read the data into.
+ * @param size The amount of data to read.
+ * @retval 0 No error.
+ * @retval EIO The read did not complete.
+ */
+ int (*read) (const rtems_fdisk_segment_desc* sd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ void* buffer,
+ uint32_t size);
+
+ /**
+ * Write data from the buffer to the device. Return an errno
+ * error number if the device cannot be written to. A segment
+ * descriptor can describe more than segment in a device if the
+ * device has repeating segments. The segment number is the device
+ * segment to access and the segment descriptor must reference
+ * the segment being requested. For example the segment number must
+ * resided in the range [base, base + count).
+ *
+ * @param sd The segment descriptor.
+ * @param device The device to write data from.
+ * @param segment The segment within the device to write to.
+ * @param offset The offset in the segment to write.
+ * @param buffer The buffer to write the data from.
+ * @param size The amount of data to write.
+ * @retval 0 No error.
+ * @retval EIO The write did not complete or verify.
+ */
+ int (*write) (const rtems_fdisk_segment_desc* sd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ const void* buffer,
+ uint32_t size);
+
+ /**
+ * Blank a segment in the device. Return an errno error number
+ * if the device cannot be read or is not blank. A segment descriptor
+ * can describe more than segment in a device if the device has
+ * repeating segments. The segment number is the device segment to
+ * access and the segment descriptor must reference the segment
+ * being requested. For example the segment number must resided in
+ * the range [base, base + count).
+ *
+ * @param sd The segment descriptor.
+ * @param device The device to read data from.
+ * @param segment The segment within the device to read.
+ * @param offset The offset in the segment to checl.
+ * @param size The amount of data to check.
+ * @retval 0 No error.
+ * @retval EIO The segment is not blank.
+ */
+ int (*blank) (const rtems_fdisk_segment_desc* sd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ uint32_t size);
+
+ /**
+ * Verify data in the buffer to the data in the device. Return an
+ * errno error number if the device cannot be read. A segment
+ * descriptor can describe more than segment in a device if the
+ * device has repeating segments. The segment number is the
+ * segment to access and the segment descriptor must reference
+ * the device segment being requested. For example the segment number
+ * must resided in the range [base, base + count).
+ *
+ * @param sd The segment descriptor.
+ * @param device The device to verify data in.
+ * @param segment The segment within the device to verify.
+ * @param offset The offset in the segment to verify.
+ * @param buffer The buffer to verify the data in the device with.
+ * @param size The amount of data to verify.
+ * @retval 0 No error.
+ * @retval EIO The data did not verify.
+ */
+ int (*verify) (const rtems_fdisk_segment_desc* sd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ const void* buffer,
+ uint32_t size);
+
+ /**
+ * Erase the segment. Return an errno error number if the
+ * segment cannot be erased. A segment descriptor can describe
+ * more than segment in a device if the device has repeating
+ * segments. The segment number is the device segment to access and
+ * the segment descriptor must reference the segment being requested.
+ *
+ * @param sd The segment descriptor.
+ * @param device The device to erase the segment of.
+ * @param segment The segment within the device to erase.
+ * @retval 0 No error.
+ * @retval EIO The segment was not erased.
+ */
+ int (*erase) (const rtems_fdisk_segment_desc* sd,
+ uint32_t device,
+ uint32_t segment);
+
+ /**
+ * Erase the device. Return an errno error number if the
+ * segment cannot be erased. A segment descriptor can describe
+ * more than segment in a device if the device has repeating
+ * segments. The segment number is the segment to access and
+ * the segment descriptor must reference the segment being requested.
+ *
+ * @param sd The segment descriptor.
+ * @param device The device to erase.
+ * @retval 0 No error.
+ * @retval EIO The device was not erased.
+ */
+ int (*erase_device) (const struct rtems_fdisk_device_desc* dd,
+ uint32_t device);
+
+} rtems_fdisk_driver_handlers;
+
+/**
+ * Flash Device Descriptor holds the segments in a device. The
+ * placing of the segments in a device decriptor allows the
+ * low level driver to share the segment descriptors for a
+ * number of devices.
+ *
+ * Typically this structure is part of a table of segments in the
+ * device which is referenced in the flash disk configuration table.
+ * The reference is kept in the driver and used all the time to
+ * manage the flash device, therefore it must always exist.
+ */
+typedef struct rtems_fdisk_device_desc
+{
+ uint32_t segment_count; /**< Number of segments. */
+ const rtems_fdisk_segment_desc* segments; /**< Array of segments. */
+ const rtems_fdisk_driver_handlers* flash_ops; /**< Device handlers. */
+} rtems_fdisk_device_desc;
+
+/**
+ * RTEMS Flash Disk configuration table used to initialise the
+ * driver.
+ *
+ * The unavailable blocks count is the number of blocks less than the
+ * available number of blocks the file system is given. This means there
+ * will always be that number of blocks available when the file system
+ * thinks the disk is full. The compaction code needs blocks to compact
+ * with so you will never be able to have all the blocks allocated to the
+ * file system and be able to full the disk.
+ *
+ * The compacting segment count is the number of segments that are
+ * moved into a new segment. A high number will mean more segments with
+ * low active page counts and high used page counts will be moved into
+ * avaliable pages how-ever this extends the compaction time due to
+ * time it takes the erase the pages. There is no pont making this number
+ * greater than the maximum number of pages in a segment.
+ *
+ * The available compacting segment count is the level when compaction occurs
+ * when writing. If you set this to 0 then compaction will fail because
+ * there will be no segments to compact into.
+ *
+ * The info level can be 0 for off with error, and abort messages allowed.
+ * Level 1 is warning messages, level 1 is informational messages, and level 3
+ * is debugging type prints. The info level can be turned off with a compile
+ * time directive on the command line to the compiler of:
+ *
+ * -DRTEMS_FDISK_TRACE=0
+ */
+typedef struct rtems_flashdisk_config
+{
+ uint32_t block_size; /**< The block size. */
+ uint32_t device_count; /**< The number of devices. */
+ const rtems_fdisk_device_desc* devices; /**< The device descriptions. */
+ uint32_t flags; /**< Set of flags to control
+ driver. */
+ uint32_t unavail_blocks; /**< Number of blocks not
+ available to the file sys. */
+ uint32_t compact_segs; /**< Max number of segs to
+ compact in one pass. */
+ uint32_t avail_compact_segs; /**< The number of segments
+ when compaction occurs
+ when writing. */
+ uint32_t info_level; /**< Default info level. */
+} rtems_flashdisk_config;
+
+/*
+ * Driver flags.
+ */
+
+/**
+ * Leave the erasing of used segment to the background handler.
+ */
+#define RTEMS_FDISK_BACKGROUND_ERASE (1 << 0)
+
+/**
+ * Leave the compacting of of used segment to the background handler.
+ */
+#define RTEMS_FDISK_BACKGROUND_COMPACT (1 << 1)
+
+/**
+ * Check the pages during initialisation to see which pages are
+ * valid and which are not. This could slow down initialising the
+ * disk driver.
+ */
+#define RTEMS_FDISK_CHECK_PAGES (1 << 2)
+
+/**
+ * Blank check the flash device before writing to them. This is needed if
+ * you think you have a driver or device problem.
+ */
+#define RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE (1 << 3)
+
+/**
+ * Flash disk device driver initialization. Place in a table as the
+ * initialisation entry and remainder of the entries are the
+ * RTEMS block device generic handlers.
+ *
+ * @param major Flash disk major device number.
+ * @param minor Minor device number, not applicable.
+ * @param arg Initialization argument, not applicable.
+ * @return The rtems_device_driver is actually just
+ * rtems_status_code.
+ */
+rtems_device_driver
+rtems_fdisk_initialize (rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void* arg);
+
+/**
+ * External reference to the configuration. Please supply.
+ * Support is present in confdefs.h for providing this variable.
+ */
+extern const rtems_flashdisk_config rtems_flashdisk_configuration[];
+
+/**
+ * External reference to the number of configurations. Please supply.
+ * Support is present in confdefs.h for providing this variable.
+ */
+extern uint32_t rtems_flashdisk_configuration_size;
+
+#endif
diff --git a/cpukit/libblock/include/rtems/ide_part_table.h b/cpukit/libblock/include/rtems/ide_part_table.h
new file mode 100644
index 0000000000..c6fe587e02
--- /dev/null
+++ b/cpukit/libblock/include/rtems/ide_part_table.h
@@ -0,0 +1,217 @@
+/**
+ * @file rtems/ide_part_table.h
+ *
+ * Support for "MS-DOS-style" partition tables
+ */
+
+/*
+ * Copyright (C) 2002 OKTET Ltd., St.-Petersburg, Russia
+ *
+ * Author: Konstantin Abramenko <Konstantin.Abramenko@oktet.ru>
+ * Alexander Kukuta <Alexander.Kukuta@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ *****************************************************************************/
+
+#ifndef _RTEMS_IDE_PART_TABLE_H
+#define _RTEMS_IDE_PART_TABLE_H
+
+#include <rtems/chain.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <rtems.h>
+#include <rtems/blkdev.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/bdbuf.h>
+#include <rtems/seterr.h>
+
+/* Minor base number for all logical devices */
+#define RTEMS_IDE_SECTOR_BITS 9
+#define RTEMS_IDE_SECTOR_SIZE 512
+#define RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE 16
+#define RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER 63
+#define RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER 4
+#define RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX 16
+
+#define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA1 0x55
+#define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA2 0xaa
+#define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_OFFSET 0x1fe
+#define RTEMS_IDE_PARTITION_TABLE_OFFSET 0x1be
+#define RTEMS_IDE_PARTITION_TABLE_SIZE (4 * 16)
+#define RTEMS_IDE_PARTITION_BOOTABLE_OFFSET 0
+#define RTEMS_IDE_PARTITION_SYS_TYPE_OFFSET 4
+#define RTEMS_IDE_PARTITION_START_OFFSET 8
+#define RTEMS_IDE_PARTITION_SIZE_OFFSET 12
+
+/*
+ * Conversion from and to little-endian byte order. (no-op on i386/i486)
+ */
+
+#if (CPU_BIG_ENDIAN == TRUE)
+# define LE_TO_CPU_U16(v) CPU_swap_u16(v)
+# define LE_TO_CPU_U32(v) CPU_swap_u32(v)
+# define CPU_TO_LE_U16(v) CPU_swap_u16(v)
+# define CPU_TO_LE_U32(v) CPU_swap_u32(v)
+#else
+# define LE_TO_CPU_U16(v) (v)
+# define LE_TO_CPU_U32(v) (v)
+# define CPU_TO_LE_U16(v) (v)
+# define CPU_TO_LE_U32(v) (v)
+#endif
+
+
+/*
+ * sector_data_t --
+ * corresponds to the sector on the device
+ */
+typedef struct rtems_sector_data_s
+{
+ uint32_t sector_num; /* sector number on the device */
+ uint8_t data[0]; /* raw sector data */
+} rtems_sector_data_t;
+
+
+/*
+ * Enum partition types
+ * see list at http://ata-atapi.com/hiwtab.htm
+ *
+ * @todo Should these have RTEMS before them.
+ */
+enum {
+ EMPTY_PARTITION = 0x00,
+ DOS_FAT12_PARTITION = 0x01,
+ DOS_FAT16_PARTITION = 0x04,
+ EXTENDED_PARTITION = 0x05,
+ DOS_P32MB_PARTITION = 0x06,
+ FAT32_PARTITION = 0x0B,
+ FAT32_LBA_PARTITION = 0x0C,
+ FAT16_LBA_PARTITION = 0x0E,
+ DM6_PARTITION = 0x54,
+ EZD_PARTITION = 0x55,
+ DM6_AUX1PARTITION = 0x51,
+ DM6_AUX3PARTITION = 0x53,
+ LINUX_SWAP = 0x82,
+ LINUX_NATIVE = 0x83,
+ LINUX_EXTENDED = 0x85
+};
+
+
+/* Forward declaration */
+struct rtems_disk_desc_s;
+
+/*
+ * part_desc_t --
+ * contains all neccessary information about partition
+ */
+typedef struct rtems_part_desc_s {
+ uint8_t bootable; /* is the partition active */
+ uint8_t sys_type; /* type of partition */
+ uint8_t log_id; /* logical number of partition */
+ uint32_t start; /* first partition sector, in absolute
+ * numeration */
+ uint32_t size; /* size in sectors */
+ uint32_t end; /* last partition sector, end = start + size - 1 */
+ struct rtems_disk_desc_s *disk_desc; /* descriptor of disk, partition
+ * contains in */
+ struct rtems_part_desc_s *ext_part; /* extended partition containing this
+ * one */
+
+ /* partitions, containing in this one */
+ struct rtems_part_desc_s *sub_part[RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER];
+} rtems_part_desc_t;
+
+
+
+typedef struct rtems_disk_desc_s {
+ dev_t dev; /* device number */
+
+ /* device name in /dev filesystem */
+ char dev_name[RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX];
+
+ uint32_t sector_size; /* size of sector */
+ uint32_t sector_bits; /* the base-2 logarithm of sector_size */
+ uint32_t lba_size; /* total amount of sectors in lba address mode */
+ int last_log_id; /* used for logical disks enumerating */
+
+ /* primary partition descriptors */
+ rtems_part_desc_t *partitions[RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER];
+} rtems_disk_desc_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * rtems_ide_part_table_free --
+ * frees disk descriptor structure
+ *
+ * PARAMETERS:
+ * disk_desc - disc descriptor structure to free
+ *
+ * RETURNS:
+ * N/A
+ */
+/**
+ * @deprecated Use the @ref rtems_bdpart "block device partition module" instead.
+ */
+void rtems_ide_part_table_free(
+ rtems_disk_desc_t *disk_desc
+) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
+
+
+/*
+ * rtems_ide_part_table_get --
+ * reads partition table structure from the device
+ * and creates disk description structure
+ *
+ * PARAMETERS:
+ * dev_name - path to physical device in /dev filesystem
+ * disk_desc - returned disc description structure
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else
+ */
+/**
+ * @deprecated Use the @ref rtems_bdpart "block device partition module" instead.
+ */
+rtems_status_code rtems_ide_part_table_get(
+ const char *dev_name,
+ rtems_disk_desc_t *disk_desc
+) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
+
+
+/*
+ * rtems_ide_part_table_initialize --
+ * initializes logical devices on the physical IDE drive
+ *
+ * PARAMETERS:
+ * dev_name - path to physical device in /dev filesystem
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else
+ */
+/**
+ * @deprecated Use the @ref rtems_bdpart "block device partition module" instead.
+ */
+rtems_status_code rtems_ide_part_table_initialize(
+ char *dev_name
+) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_IDE_PART_TABLE_H */
diff --git a/cpukit/libblock/include/rtems/media.h b/cpukit/libblock/include/rtems/media.h
new file mode 100644
index 0000000000..038357c16d
--- /dev/null
+++ b/cpukit/libblock/include/rtems/media.h
@@ -0,0 +1,521 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSMedia
+ *
+ * @brief Media API.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef RTEMS_MEDIA_H
+#define RTEMS_MEDIA_H
+
+#include <rtems.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup RTEMSMedia Media Manager
+ *
+ * @brief Removable media support.
+ *
+ * The media manager may be used to maintain the life cycle of a removable
+ * media. Currently only disk devices are supported. The initiator posts an
+ * event to the media manager and it will respond with appropriate default
+ * actions. For example a disk attach will lead to inspection of the partition
+ * table and mounted file systems. Clients can register listeners to react to
+ * events.
+ * @{
+ */
+
+#define RTEMS_MEDIA_MOUNT_BASE "/media"
+
+#define RTEMS_MEDIA_DELIMITER '-'
+
+/**
+ * Disk life cycle events:
+ * @dot
+ * digraph disk_events {
+ * "DISK ATTACH" -> "PARTITION INQUIRY";
+ * "DISK ATTACH" -> "MOUNT";
+ * "PARTITION INQUIRY" -> "PARTITION ATTACH";
+ * "PARTITION INQUIRY" -> "DISK DETACH";
+ * "PARTITION ATTACH" -> "MOUNT";
+ * "MOUNT" -> "UNMOUNT";
+ * "UNMOUNT" -> "PARTITION DETACH";
+ * "UNMOUNT" -> "DISK DETACH";
+ * "PARTITION DETACH" -> "DISK DETACH";
+ * }
+ * @enddot
+ */
+typedef enum {
+ RTEMS_MEDIA_EVENT_DISK_ATTACH,
+ RTEMS_MEDIA_EVENT_DISK_DETACH,
+ RTEMS_MEDIA_EVENT_MOUNT,
+ RTEMS_MEDIA_EVENT_UNMOUNT,
+ RTEMS_MEDIA_EVENT_PARTITION_INQUIRY,
+ RTEMS_MEDIA_EVENT_PARTITION_ATTACH,
+ RTEMS_MEDIA_EVENT_PARTITION_DETACH,
+ RTEMS_MEDIA_EVENT_ERROR
+} rtems_media_event;
+
+/**
+ * Normal state transition:
+ * @dot
+ * digraph state {
+ * INQUIRY -> READY [label="all listeners\nreturned successful"];
+ * INQUIRY -> ABORTED [label="otherwise"];
+ * READY -> SUCCESS [label="the worker\nreturned successful"];
+ * READY -> FAILED [label="otherwise"];
+ * }
+ * @enddot
+ */
+typedef enum {
+ RTEMS_MEDIA_STATE_INQUIRY,
+ RTEMS_MEDIA_STATE_READY,
+ RTEMS_MEDIA_STATE_ABORTED,
+ RTEMS_MEDIA_STATE_SUCCESS,
+ RTEMS_MEDIA_STATE_FAILED,
+ RTEMS_MEDIA_ERROR_DISK_UNKNOWN,
+ RTEMS_MEDIA_ERROR_DISK_EXISTS,
+ RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_UNKNOWN,
+ RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_EXISTS,
+ RTEMS_MEDIA_ERROR_PARTITION_UNKNOWN,
+ RTEMS_MEDIA_ERROR_PARTITION_ORPHAN,
+ RTEMS_MEDIA_ERROR_PARTITION_DETACH_WITH_MOUNT,
+ RTEMS_MEDIA_ERROR_PARTITION_WITH_UNKNOWN_DISK,
+ RTEMS_MEDIA_ERROR_MOUNT_POINT_UNKNOWN,
+ RTEMS_MEDIA_ERROR_MOUNT_POINT_EXISTS,
+ RTEMS_MEDIA_ERROR_MOUNT_POINT_ORPHAN
+} rtems_media_state;
+
+/**
+ * @brief Event listener.
+ *
+ * The listener will be called with the @a listener_arg passed to
+ * rtems_media_listener_add().
+ *
+ * Source and destination values for each event and state:
+ * <table>
+ * <tr><th>Event</th><th>State</th><th>Source</th><th>Destination</th></tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_DISK_ATTACH</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td><td>driver name</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td><td>driver name</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td><td>driver name</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td><td>driver name</td><td>disk path</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td><td>driver name</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_DISK_DETACH</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_PARTITION_INQUIRY</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_PARTITION_ATTACH</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td>
+ * <td>disk path</td><td>partition path</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_PARTITION_DETACH</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td><td>partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td><td>partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td><td>partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td><td>partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td><td>partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_MOUNT</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td>
+ * <td>disk or partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td>
+ * <td>disk or partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td>
+ * <td>disk or partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td>
+ * <td>disk or partition path</td><td>mount path</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td>
+ * <td>disk or partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5">RTEMS_MEDIA_EVENT_UNMOUNT</td>
+ * <td>RTEMS_MEDIA_STATE_INQUIRY</td><td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_READY</td><td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_ABORTED</td><td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_SUCCESS</td><td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_STATE_FAILED</td><td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="11">RTEMS_MEDIA_EVENT_ERROR</td>
+ * <td>RTEMS_MEDIA_ERROR_DISK_UNKNOWN</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_DISK_EXISTS</td><td>disk path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_UNKNOWN</td>
+ * <td>disk or partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_EXISTS</td>
+ * <td>disk or partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_PARTITION_UNKNOWN</td>
+ * <td>partition path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_PARTITION_ORPHAN</td>
+ * <td>partition path</td><td>disk path</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_PARTITION_DETACH_WITH_MOUNT</td>
+ * <td>partition path</td><td>mount path</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_PARTITION_WITH_UNKNOWN_DISK</td>
+ * <td>partition path</td><td>disk path</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_MOUNT_POINT_UNKNOWN</td>
+ * <td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_MOUNT_POINT_EXISTS</td>
+ * <td>mount path</td><td>NULL</td>
+ * </tr>
+ * <tr>
+ * <td>RTEMS_MEDIA_ERROR_MOUNT_POINT_ORPHAN</td>
+ * <td>mount path</td><td>disk path</td>
+ * </tr>
+ * </table>
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_IO_ERROR In the inquiry state this will abort the action.
+ */
+typedef rtems_status_code (*rtems_media_listener)(
+ rtems_media_event event,
+ rtems_media_state state,
+ const char *src,
+ const char *dest,
+ void *listener_arg
+);
+
+/**
+ * @brief Do the work corresponding to an event.
+ *
+ * The @a state will be
+ * - RTEMS_MEDIA_STATE_READY, or
+ * - RTEMS_MEDIA_STATE_ABORTED.
+ *
+ * It will be called with the @a src and @a worker_arg arguments passed to
+ * rtems_media_post_event().
+ *
+ * The destination shall be returned in @a dest in case of success. It shall
+ * be allocated with malloc().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_IO_ERROR Failure.
+ */
+typedef rtems_status_code (*rtems_media_worker)(
+ rtems_media_state state,
+ const char *src,
+ char **dest,
+ void *worker_arg
+);
+
+/**
+ * @name Base
+ *
+ * @{
+ */
+
+/**
+ * @brief Initializes the media manager.
+ *
+ * Calling this function more than once will have no effects. There is no
+ * protection against concurrent access.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NO_MEMORY Not enough resources.
+ */
+rtems_status_code rtems_media_initialize(void);
+
+/**
+ * @brief Adds the @a listener with argument @a listener_arg.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NO_MEMORY Not enough memory.
+ * @retval RTEMS_TOO_MANY Such a listener is already present.
+ */
+rtems_status_code rtems_media_listener_add(
+ rtems_media_listener listener,
+ void *listener_arg
+);
+
+/**
+ * @brief Removes the @a listener with argument @a listener_arg.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ID No such listener is present.
+ */
+rtems_status_code rtems_media_listener_remove(
+ rtems_media_listener listener,
+ void *listener_arg
+);
+
+/**
+ * @brief Posts the @a event with source @a src.
+ *
+ * The @a worker will be called with the @a worker_arg argument.
+ *
+ * The destination will be returned in @a dest in case of success. It will be
+ * allocated with malloc() and should be freed if not needed anymore.
+ *
+ * The work will be done by the calling thread. You can avoid this if you use
+ * the media server via rtems_media_server_post_event().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_UNSATISFIED One or more listeners aborted the action.
+ * @retval RTEMS_IO_ERROR The worker returned with an error status.
+ */
+rtems_status_code rtems_media_post_event(
+ rtems_media_event event,
+ const char *src,
+ char **dest,
+ rtems_media_worker worker,
+ void *worker_arg
+);
+
+/** @} */
+
+/**
+ * @name Server
+ *
+ * @{
+ */
+
+/**
+ * @brief Initializes the media manager and media server.
+ *
+ * It creates a server task with the @a priority, @a stack_size, @a modes, and
+ * @a attributes parameters.
+ *
+ * Calling this function more than once will have no effects. There is no
+ * protection against concurrent access.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NO_MEMORY Not enough resources.
+ */
+rtems_status_code rtems_media_server_initialize(
+ rtems_task_priority priority,
+ size_t stack_size,
+ rtems_mode modes,
+ rtems_attribute attributes
+);
+
+/**
+ * @brief Sends an event message to the media server.
+ *
+ * @see See rtems_media_post_event().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_NO_MEMORY Not enough resources to notify the media server.
+ * @retval RTEMS_NOT_CONFIGURED Media server is not initialized.
+ */
+rtems_status_code rtems_media_server_post_event(
+ rtems_media_event event,
+ const char *src,
+ rtems_media_worker worker,
+ void *worker_arg
+);
+
+/**
+ * @brief See rtems_media_server_post_event().
+ */
+static inline rtems_status_code rtems_media_server_disk_attach(
+ const char *driver_name,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ return rtems_media_server_post_event(
+ RTEMS_MEDIA_EVENT_DISK_ATTACH,
+ driver_name,
+ worker,
+ worker_arg
+ );
+}
+
+/**
+ * @brief See rtems_media_server_post_event().
+ */
+static inline rtems_status_code rtems_media_server_disk_detach(
+ const char *disk_path
+)
+{
+ return rtems_media_server_post_event(
+ RTEMS_MEDIA_EVENT_DISK_DETACH,
+ disk_path,
+ NULL,
+ NULL
+ );
+}
+
+/** @} */
+
+/**
+ * @name Path Construction
+ *
+ * @{
+ */
+
+/**
+ * @brief Creates a new path as "prefix/name-major".
+ *
+ * @return New string, or @c NULL if no memory is available.
+ */
+char *rtems_media_create_path(
+ const char *prefix,
+ const char *name,
+ rtems_device_major_number major
+);
+
+/**
+ * @brief Replaces the prefix of the @a path with @a new_prefix.
+ *
+ * The prefix is everything up to the last '/'.
+ *
+ * @return New string, or @c NULL if no memory is available.
+ */
+char *rtems_media_replace_prefix(const char *new_prefix, const char *path);
+
+/**
+ * @brief Appends the @a minor number to the @a path resulting in "path-minor".
+ *
+ * @return New string, or @c NULL if no memory is available.
+ */
+char *rtems_media_append_minor(
+ const char *path,
+ rtems_device_minor_number minor
+);
+
+/** @} */
+
+/**
+ * @name Support
+ *
+ * @{
+ */
+
+/**
+ * @brief Returns the device identifier for the device located at
+ * @a device_path in @a device_identifier.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ID No device at this path.
+ */
+rtems_status_code rtems_media_get_device_identifier(
+ const char *device_path,
+ dev_t *device_identifier
+);
+
+const char *rtems_media_event_description(rtems_media_event event);
+
+const char *rtems_media_state_description(rtems_media_state state);
+
+/** @} */
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RTEMS_MEDIA_H */
diff --git a/cpukit/libblock/include/rtems/nvdisk-sram.h b/cpukit/libblock/include/rtems/nvdisk-sram.h
new file mode 100644
index 0000000000..450cfd8602
--- /dev/null
+++ b/cpukit/libblock/include/rtems/nvdisk-sram.h
@@ -0,0 +1,25 @@
+/*
+ * $Id$
+ *
+ * RTEMS Project (http://www.rtems.org/)
+ *
+ * Copyright 2007 Chris Johns (chrisj@rtems.org)
+ */
+
+/**
+ * NV Disk Static RAM Device Driver.
+ *
+ * This driver maps an NV disk to static RAM. You can use this
+ */
+
+#if !defined (_RTEMS_NVDISK_SRAM_H_)
+#define _RTEMS_NVDISK_SRAM_H_
+
+#include <rtems/nvdisk.h>
+
+/**
+ * The handlers for the NV Disk SRAM driver.
+ */
+extern const rtems_nvdisk_driver_handlers rtems_nvdisk_sram_handlers;
+
+#endif
diff --git a/cpukit/libblock/include/rtems/nvdisk.h b/cpukit/libblock/include/rtems/nvdisk.h
new file mode 100644
index 0000000000..48d8ba0b16
--- /dev/null
+++ b/cpukit/libblock/include/rtems/nvdisk.h
@@ -0,0 +1,209 @@
+/*
+ * nvdisk.h -- Non-volatile disk block device implementation
+ *
+ * Copyright (C) 2007 Chris Johns
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/**
+ * The Non-volatile disk provides a simple directly mapped disk
+ * driver with checksums for each. It is designed to provied a
+ * disk that can survive a restart. Examples are EEPROM devices
+ * which have byte writeable locations, or a battery backed up
+ * RAM disk.
+ *
+ * The low level driver provides the physical access to the
+ * hardware.
+ */
+#if !defined (_RTEMS_NVDISK_H_)
+#define _RTEMS_NVDISK_H_
+
+#include <stdint.h>
+#include <sys/ioctl.h>
+
+#include <rtems.h>
+
+/**
+ * The base name of the nv disks.
+ */
+#define RTEMS_NVDISK_DEVICE_BASE_NAME "/dev/nvd"
+
+/**
+ * NV disk specific ioctl request types. To use open the
+ * device and issue the ioctl call.
+ *
+ * @code
+ * int fd = open ("/dev/nvdisk0", O_WRONLY, 0);
+ * if (fd < 0)
+ * {
+ * printf ("driver open failed: %s\n", strerror (errno));
+ * exit (1);
+ * }
+ * if (ioctl (fd, RTEMS_NVDISK_IOCTL_ERASE_DISK) < 0)
+ * {
+ * printf ("driver erase failed: %s\n", strerror (errno));
+ * exit (1);
+ * }
+ * close (fd);
+ * @endcode
+ */
+#define RTEMS_NVDISK_IOCTL_ERASE_DISK _IO('B', 128)
+#define RTEMS_NVDISK_IOCTL_MONITORING _IO('B', 129)
+#define RTEMS_NVDISK_IOCTL_INFO_LEVEL _IO('B', 130)
+#define RTEMS_NVDISK_IOCTL_PRINT_STATUS _IO('B', 131)
+
+/**
+ * NV Disk Monitoring Data allows a user to obtain
+ * the current status of the disk.
+ */
+typedef struct rtems_nvdisk_monitor_data
+{
+ uint32_t block_size;
+ uint32_t block_count;
+ uint32_t page_count;
+ uint32_t pages_available;
+ uint32_t pages_used;
+ uint32_t info_level;
+} rtems_nvdisk_monitor_data;
+
+/**
+ * Return the number of kilo-bytes.
+ */
+#define RTEMS_NVDISK_KBYTES(_k) ((_k) * 1024)
+
+/**
+ * NV Low Level driver handlers.
+
+ * Typically this structure is part of a table of handlers in the
+ * device which is referenced in the nvdisk configuration table.
+ * The reference is kept in the driver and used all the time to
+ * manage the nv device, therefore it must always exist.
+ */
+typedef struct rtems_nvdisk_driver_handlers
+{
+ /**
+ * Read data from the device into the buffer. Return an errno
+ * error number if the data cannot be read.
+ *
+ * @param device The device to read data from.
+ * @param flags Device specific flags for the driver.
+ * @param base The base address of the device.
+ * @param offset The offset in the segment to read.
+ * @param buffer The buffer to read the data into.
+ * @param size The amount of data to read.
+ * @retval 0 No error.
+ * @retval EIO The read did not complete.
+ */
+ int (*read) (uint32_t device, uint32_t flags, void* base,
+ uint32_t offset, void* buffer, size_t size);
+
+ /**
+ * Write data from the buffer to the device. Return an errno
+ * error number if the device cannot be written to.
+ *
+ * @param device The device to write data to.
+ * @param flags Device specific flags for the driver.
+ * @param base The base address of the device.
+ * @param offset The offset in the device to write to.
+ * @param buffer The buffer to write the data from.
+ * @param size The amount of data to write.
+ * @retval 0 No error.
+ * @retval EIO The write did not complete or verify.
+ */
+ int (*write) (uint32_t device, uint32_t flags, void* base,
+ uint32_t offset, const void* buffer, size_t size);
+
+ /**
+ * Verify data in the buffer to the data in the device. Return an
+ * errno error number if the device cannot be read or the data verified.
+ *
+ * @param device The device to verify the data with.
+ * @param flags Device specific flags for the driver.
+ * @param base The base address of the device.
+ * @param offset The offset in the device to verify.
+ * @param buffer The buffer to verify the data in the device with.
+ * @param size The amount of data to verify.
+ * @retval 0 No error.
+ * @retval EIO The data did not verify.
+ */
+ int (*verify) (uint32_t device, uint32_t flags, void* base,
+ uint32_t offset, const void* buffer, size_t size);
+
+} rtems_nvdisk_driver_handlers;
+
+/**
+ * NV Device Descriptor holds the description of a device that is
+ * part of the NV disk.
+ *
+ * Typically this structure is part of a table of the device which
+ * is referenced in the nvdisk configuration table.
+ * The reference is kept in the driver and used all the time to
+ * manage the nv device, therefore it must always exist.
+ */
+typedef struct rtems_nvdisk_device_desc
+{
+ uint32_t flags; /**< Private user flags. */
+ void* base; /**< Base address of the device. */
+ uint32_t size; /**< Size of the device. */
+ const rtems_nvdisk_driver_handlers* nv_ops; /**< Device handlers. */
+} rtems_nvdisk_device_desc;
+
+/**
+ * RTEMS Non-Volatile Disk configuration table used to initialise the
+ * driver.
+ */
+typedef struct rtems_nvdisk_config
+{
+ uint32_t block_size; /**< The block size. */
+ uint32_t device_count; /**< The number of devices. */
+ const rtems_nvdisk_device_desc* devices; /**< The device descriptions. */
+ uint32_t flags; /**< Set of flags to control
+ driver. */
+ uint32_t info_level; /**< Default info level. */
+} rtems_nvdisk_config;
+
+/*
+ * Driver flags.
+ */
+
+/**
+ * Check the pages during initialisation to see which pages are
+ * valid and which are not. This could slow down initialising the
+ * disk driver.
+ */
+#define RTEMS_NVDISK_CHECK_PAGES (1 << 0)
+
+/**
+ * Non-volatile disk device driver initialization. Place in a table as the
+ * initialisation entry and remainder of the entries are the RTEMS block
+ * device generic handlers.
+ *
+ * @param major NV disk major device number.
+ * @param minor Minor device number, not applicable.
+ * @param arg Initialization argument, not applicable.
+ * @return The rtems_device_driver is actually just
+ * rtems_status_code.
+ */
+rtems_device_driver
+rtems_nvdisk_initialize (rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void* arg);
+
+/**
+ * External reference to the configuration. Please supply.
+ * Support is present in confdefs.h for providing this variable.
+ */
+extern const rtems_nvdisk_config rtems_nvdisk_configuration[];
+
+/**
+ * External reference to the number of configurations. Please supply.
+ * Support is present in confdefs.h for providing this variable.
+ */
+extern uint32_t rtems_nvdisk_configuration_size;
+
+#endif
diff --git a/cpukit/libblock/include/rtems/ramdisk.h b/cpukit/libblock/include/rtems/ramdisk.h
new file mode 100644
index 0000000000..71efc9fda0
--- /dev/null
+++ b/cpukit/libblock/include/rtems/ramdisk.h
@@ -0,0 +1,243 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_ramdisk
+ *
+ * @brief RAM disk block device API.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#ifndef _RTEMS_RAMDISK_H
+#define _RTEMS_RAMDISK_H
+
+
+#include <rtems.h>
+#include <rtems/blkdev.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup rtems_ramdisk RAM Disk Device
+ *
+ * @ingroup rtems_blkdev
+ *
+ * @{
+ */
+
+/**
+ * @name Static Configuration
+ *
+ * @{
+ */
+
+/**
+ * @brief RAM disk configuration table entry.
+ */
+typedef struct rtems_ramdisk_config {
+ /**
+ * @brief RAM disk block size.
+ */
+ uint32_t block_size;
+
+ /**
+ * @brief Number of blocks on this RAM disk.
+ */
+ rtems_blkdev_bnum block_num;
+
+ /**
+ * @brief RAM disk location or @c NULL if RAM disk memory should be allocated
+ * dynamically.
+ */
+ void *location;
+} rtems_ramdisk_config;
+
+/**
+ * @brief External reference to the RAM disk configuration table describing
+ * each RAM disk in the system.
+ *
+ * The configuration table is provided by the application.
+ */
+extern rtems_ramdisk_config rtems_ramdisk_configuration [];
+
+/**
+ * @brief External reference the size of the RAM disk configuration table @ref
+ * rtems_ramdisk_configuration.
+ *
+ * The configuration table size is provided by the application.
+ */
+extern size_t rtems_ramdisk_configuration_size;
+
+/**
+ * @brief RAM disk driver initialization entry point.
+ */
+rtems_device_driver ramdisk_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * RAM disk driver table entry.
+ */
+#define RAMDISK_DRIVER_TABLE_ENTRY \
+ { \
+ .initialization_entry = ramdisk_initialize, \
+ RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \
+ }
+
+#define RAMDISK_DEVICE_BASE_NAME "/dev/rd"
+
+/** @} */
+
+/**
+ * @name Runtime Configuration
+ *
+ * @{
+ */
+
+/**
+ * @brief RAM disk descriptor.
+ */
+typedef struct ramdisk {
+ /**
+ * @brief RAM disk block size, the media size.
+ */
+ uint32_t block_size;
+
+ /**
+ * @brief Number of blocks on this RAM disk.
+ */
+ rtems_blkdev_bnum block_num;
+
+ /**
+ * @brief RAM disk memory area.
+ */
+ void *area;
+
+ /**
+ * @brief RAM disk is initialized.
+ */
+ bool initialized;
+
+ /**
+ * @brief Indicates if memory is allocated by malloc() for this RAM disk.
+ */
+ bool malloced;
+
+ /**
+ * @brief Trace enable.
+ */
+ bool trace;
+} ramdisk;
+
+extern const rtems_driver_address_table ramdisk_ops;
+
+int ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
+
+/**
+ * @brief Allocates and initializes a RAM disk descriptor.
+ *
+ * The block size will be @a block_size. The block count will be @a
+ * block_count. The disk storage area begins at @a area_begin. If @a
+ * area_begin is @c NULL, the memory will be allocated and zeroed. Sets the
+ * trace enable to @a trace.
+ *
+ * @return Pointer to allocated and initialized ramdisk structure, or @c NULL
+ * if no memory is available.
+ *
+ * @note
+ * Runtime configuration example:
+ * @code
+ * #include <rtems.h>
+ * #include <rtems/libio.h>
+ * #include <rtems/ramdisk.h>
+ *
+ * rtems_status_code create_ramdisk(
+ * const char *disk_name_path,
+ * uint32_t block_size,
+ * rtems_blkdev_bnum block_count
+ * )
+ * {
+ * rtems_status_code sc = RTEMS_SUCCESSFUL;
+ * rtems_device_major_number major = 0;
+ * ramdisk *rd = NULL;
+ * dev_t dev = 0;
+ *
+ * sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
+ * if (sc != RTEMS_SUCCESSFUL) {
+ * return RTEMS_UNSATISFIED;
+ * }
+ *
+ * rd = ramdisk_allocate(NULL, block_size, block_count, false);
+ * if (rd == NULL) {
+ * rtems_io_unregister_driver(major);
+ *
+ * return RTEMS_UNSATISFIED;
+ * }
+ *
+ * dev = rtems_filesystem_make_dev_t(major, 0);
+ *
+ * sc = rtems_disk_create_phys(
+ * dev,
+ * block_size,
+ * block_count,
+ * ramdisk_ioctl,
+ * rd,
+ * disk_name_path
+ * );
+ * if (sc != RTEMS_SUCCESSFUL) {
+ * ramdisk_free(rd);
+ * rtems_io_unregister_driver(major);
+ *
+ * return RTEMS_UNSATISFIED;
+ * }
+ *
+ * return RTEMS_SUCCESSFUL;
+ * }
+ * @endcode
+ */
+ramdisk *ramdisk_allocate(
+ void *area_begin,
+ uint32_t block_size,
+ rtems_blkdev_bnum block_count,
+ bool trace
+);
+
+void ramdisk_free(ramdisk *rd);
+
+/**
+ * @brief Allocates, initializes and registers a RAM disk.
+ *
+ * The block size will be @a block_size. The block count will be @a
+ * block_count. The disk storage will be allocated. Sets the trace enable to
+ * @a trace. Registers a device node with disk name path @a disk. The
+ * registered device number will be returned in @a dev.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_UNSATISFIED Something is wrong.
+ */
+rtems_status_code ramdisk_register(
+ uint32_t block_size,
+ rtems_blkdev_bnum block_count,
+ bool trace,
+ const char *disk,
+ dev_t *dev
+);
+
+/** @} */
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libblock/src/bdbuf.c b/cpukit/libblock/src/bdbuf.c
new file mode 100644
index 0000000000..841c03bdbe
--- /dev/null
+++ b/cpukit/libblock/src/bdbuf.c
@@ -0,0 +1,2989 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdbuf
+ *
+ * Block device buffer management.
+ */
+
+/*
+ * Disk I/O buffering
+ * Buffer managment
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Peterburg, Russia
+ * Author: Andrey G. Ivanov <Andrey.Ivanov@oktet.ru>
+ * Victor V. Vengerov <vvv@oktet.ru>
+ * Alexander Kukuta <kam@oktet.ru>
+ *
+ * Copyright (C) 2008,2009 Chris Johns <chrisj@rtems.org>
+ * Rewritten to remove score mutex access. Fixes many performance
+ * issues.
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp
+ */
+
+/**
+ * Set to 1 to enable debug tracing.
+ */
+#define RTEMS_BDBUF_TRACE 0
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <limits.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/malloc.h>
+
+#include "rtems/bdbuf.h"
+
+#define BDBUF_INVALID_DEV ((dev_t) -1)
+
+/*
+ * Simpler label for this file.
+ */
+#define bdbuf_config rtems_bdbuf_configuration
+
+/**
+ * A swapout transfer transaction data. This data is passed to a worked thread
+ * to handle the write phase of the transfer.
+ */
+typedef struct rtems_bdbuf_swapout_transfer
+{
+ rtems_chain_control bds; /**< The transfer list of BDs. */
+ dev_t dev; /**< The device the transfer is for. */
+ bool syncing; /**< The data is a sync'ing. */
+ rtems_blkdev_request* write_req; /**< The write request array. */
+ uint32_t bufs_per_bd; /**< Number of buffers per bd. */
+} rtems_bdbuf_swapout_transfer;
+
+/**
+ * Swapout worker thread. These are available to take processing from the
+ * main swapout thread and handle the I/O operation.
+ */
+typedef struct rtems_bdbuf_swapout_worker
+{
+ rtems_chain_node link; /**< The threads sit on a chain when
+ * idle. */
+ rtems_id id; /**< The id of the task so we can wake
+ * it. */
+ volatile bool enabled; /**< The worker is enabled. */
+ rtems_bdbuf_swapout_transfer transfer; /**< The transfer data for this
+ * thread. */
+} rtems_bdbuf_swapout_worker;
+
+/**
+ * Buffer waiters synchronization.
+ */
+typedef struct rtems_bdbuf_waiters {
+ volatile unsigned count;
+ rtems_id sema;
+} rtems_bdbuf_waiters;
+
+/**
+ * The BD buffer cache.
+ */
+typedef struct rtems_bdbuf_cache
+{
+ rtems_id swapout; /**< Swapout task ID */
+ volatile bool swapout_enabled; /**< Swapout is only running if
+ * enabled. Set to false to kill the
+ * swap out task. It deletes itself. */
+ rtems_chain_control swapout_workers; /**< The work threads for the swapout
+ * task. */
+
+ rtems_bdbuf_buffer* bds; /**< Pointer to table of buffer
+ * descriptors. */
+ void* buffers; /**< The buffer's memory. */
+ size_t buffer_min_count; /**< Number of minimum size buffers
+ * that fit the buffer memory. */
+ size_t max_bds_per_group; /**< The number of BDs of minimum
+ * buffer size that fit in a group. */
+ uint32_t flags; /**< Configuration flags. */
+
+ rtems_id lock; /**< The cache lock. It locks all
+ * cache data, BD and lists. */
+ rtems_id sync_lock; /**< Sync calls block writes. */
+ volatile bool sync_active; /**< True if a sync is active. */
+ volatile rtems_id sync_requester; /**< The sync requester. */
+ volatile dev_t sync_device; /**< The device to sync and
+ * BDBUF_INVALID_DEV not a device
+ * sync. */
+
+ rtems_bdbuf_buffer* tree; /**< Buffer descriptor lookup AVL tree
+ * root. There is only one. */
+ rtems_chain_control lru; /**< Least recently used list */
+ rtems_chain_control modified; /**< Modified buffers list */
+ rtems_chain_control sync; /**< Buffers to sync list */
+
+ rtems_bdbuf_waiters access_waiters; /**< Wait for a buffer in
+ * ACCESS_CACHED, ACCESS_MODIFIED or
+ * ACCESS_EMPTY
+ * state. */
+ rtems_bdbuf_waiters transfer_waiters; /**< Wait for a buffer in TRANSFER
+ * state. */
+ rtems_bdbuf_waiters buffer_waiters; /**< Wait for a buffer and no one is
+ * available. */
+
+ size_t group_count; /**< The number of groups. */
+ rtems_bdbuf_group* groups; /**< The groups. */
+
+ bool initialised; /**< Initialised state. */
+} rtems_bdbuf_cache;
+
+/**
+ * Fatal errors
+ */
+#define RTEMS_BLKDEV_FATAL_ERROR(n) \
+ (((uint32_t)'B' << 24) | ((uint32_t)(n) & (uint32_t)0x00FFFFFF))
+
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_11 RTEMS_BLKDEV_FATAL_ERROR(1)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_4 RTEMS_BLKDEV_FATAL_ERROR(2)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_5 RTEMS_BLKDEV_FATAL_ERROR(3)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_6 RTEMS_BLKDEV_FATAL_ERROR(4)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_7 RTEMS_BLKDEV_FATAL_ERROR(5)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_8 RTEMS_BLKDEV_FATAL_ERROR(6)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_9 RTEMS_BLKDEV_FATAL_ERROR(7)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_10 RTEMS_BLKDEV_FATAL_ERROR(8)
+#define RTEMS_BLKDEV_FATAL_BDBUF_TREE_RM RTEMS_BLKDEV_FATAL_ERROR(9)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT RTEMS_BLKDEV_FATAL_ERROR(10)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK RTEMS_BLKDEV_FATAL_ERROR(11)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(12)
+#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK RTEMS_BLKDEV_FATAL_ERROR(13)
+#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(14)
+#define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_DIS RTEMS_BLKDEV_FATAL_ERROR(15)
+#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2 RTEMS_BLKDEV_FATAL_ERROR(16)
+#define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_RST RTEMS_BLKDEV_FATAL_ERROR(17)
+#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_TO RTEMS_BLKDEV_FATAL_ERROR(18)
+#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE RTEMS_BLKDEV_FATAL_ERROR(19)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE RTEMS_BLKDEV_FATAL_ERROR(20)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM RTEMS_BLKDEV_FATAL_ERROR(21)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE RTEMS_BLKDEV_FATAL_ERROR(22)
+#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START RTEMS_BLKDEV_FATAL_ERROR(23)
+#define BLKDEV_FATAL_BDBUF_SWAPOUT_RE RTEMS_BLKDEV_FATAL_ERROR(24)
+#define BLKDEV_FATAL_BDBUF_SWAPOUT_TS RTEMS_BLKDEV_FATAL_ERROR(25)
+#define RTEMS_BLKDEV_FATAL_BDBUF_WAIT_EVNT RTEMS_BLKDEV_FATAL_ERROR(26)
+#define RTEMS_BLKDEV_FATAL_BDBUF_RECYCLE RTEMS_BLKDEV_FATAL_ERROR(27)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_0 RTEMS_BLKDEV_FATAL_ERROR(28)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_1 RTEMS_BLKDEV_FATAL_ERROR(29)
+#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_2 RTEMS_BLKDEV_FATAL_ERROR(30)
+#define RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL RTEMS_BLKDEV_FATAL_ERROR(31)
+
+/**
+ * The events used in this code. These should be system events rather than
+ * application events.
+ */
+#define RTEMS_BDBUF_TRANSFER_SYNC RTEMS_EVENT_1
+#define RTEMS_BDBUF_SWAPOUT_SYNC RTEMS_EVENT_2
+
+/**
+ * The swap out task size. Should be more than enough for most drivers with
+ * tracing turned on.
+ */
+#define SWAPOUT_TASK_STACK_SIZE (8 * 1024)
+
+/**
+ * Lock semaphore attributes. This is used for locking type mutexes.
+ *
+ * @warning Priority inheritance is on.
+ */
+#define RTEMS_BDBUF_CACHE_LOCK_ATTRIBS \
+ (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \
+ RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
+
+/**
+ * Waiter semaphore attributes.
+ *
+ * @warning Do not configure as inherit priority. If a driver is in the driver
+ * initialisation table this locked semaphore will have the IDLE task
+ * as the holder and a blocking task will raise the priority of the
+ * IDLE task which can cause unsual side effects.
+ */
+#define RTEMS_BDBUF_CACHE_WAITER_ATTRIBS \
+ (RTEMS_PRIORITY | RTEMS_SIMPLE_BINARY_SEMAPHORE | \
+ RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
+
+/**
+ * Waiter timeout. Set to non-zero to find some info on a waiter that is
+ * waiting too long.
+ */
+#define RTEMS_BDBUF_WAIT_TIMEOUT RTEMS_NO_TIMEOUT
+#if !defined (RTEMS_BDBUF_WAIT_TIMEOUT)
+#define RTEMS_BDBUF_WAIT_TIMEOUT \
+ (TOD_MICROSECONDS_TO_TICKS (20000000))
+#endif
+
+/*
+ * The swap out task.
+ */
+static rtems_task rtems_bdbuf_swapout_task(rtems_task_argument arg);
+
+/**
+ * The Buffer Descriptor cache.
+ */
+static rtems_bdbuf_cache bdbuf_cache;
+
+#if RTEMS_BDBUF_TRACE
+/**
+ * If true output the trace message.
+ */
+bool rtems_bdbuf_tracer;
+
+/**
+ * Return the number of items on the list.
+ *
+ * @param list The chain control.
+ * @return uint32_t The number of items on the list.
+ */
+uint32_t
+rtems_bdbuf_list_count (rtems_chain_control* list)
+{
+ rtems_chain_node* node = rtems_chain_first (list);
+ uint32_t count = 0;
+ while (!rtems_chain_is_tail (list, node))
+ {
+ count++;
+ node = rtems_chain_next (node);
+ }
+ return count;
+}
+
+/**
+ * Show the usage for the bdbuf cache.
+ */
+void
+rtems_bdbuf_show_usage (void)
+{
+ uint32_t group;
+ uint32_t total = 0;
+ uint32_t val;
+
+ for (group = 0; group < bdbuf_cache.group_count; group++)
+ total += bdbuf_cache.groups[group].users;
+ printf ("bdbuf:group users=%lu", total);
+ val = rtems_bdbuf_list_count (&bdbuf_cache.lru);
+ printf (", lru=%lu", val);
+ total = val;
+ val = rtems_bdbuf_list_count (&bdbuf_cache.modified);
+ printf (", mod=%lu", val);
+ total += val;
+ val = rtems_bdbuf_list_count (&bdbuf_cache.sync);
+ printf (", sync=%lu", val);
+ total += val;
+ printf (", total=%lu\n", total);
+}
+
+/**
+ * Show the users for a group of a bd.
+ *
+ * @param where A label to show the context of output.
+ * @param bd The bd to show the users of.
+ */
+void
+rtems_bdbuf_show_users (const char* where, rtems_bdbuf_buffer* bd)
+{
+ const char* states[] =
+ { "EM", "FR", "CH", "AC", "AM", "MD", "SY", "TR" };
+
+ printf ("bdbuf:users: %15s: [%" PRIu32 " (%s)] %td:%td = %" PRIu32 " %s\n",
+ where,
+ bd->block, states[bd->state],
+ bd->group - bdbuf_cache.groups,
+ bd - bdbuf_cache.bds,
+ bd->group->users,
+ bd->group->users > 8 ? "<<<<<<<" : "");
+}
+#else
+#define rtems_bdbuf_tracer (0)
+#define rtems_bdbuf_show_usage() ((void) 0)
+#define rtems_bdbuf_show_users(_w, _b) ((void) 0)
+#endif
+
+/**
+ * The default maximum height of 32 allows for AVL trees having between
+ * 5,704,880 and 4,294,967,295 nodes, depending on order of insertion. You may
+ * change this compile-time constant as you wish.
+ */
+#ifndef RTEMS_BDBUF_AVL_MAX_HEIGHT
+#define RTEMS_BDBUF_AVL_MAX_HEIGHT (32)
+#endif
+
+static void
+rtems_bdbuf_fatal (rtems_bdbuf_buf_state state, uint32_t error)
+{
+ rtems_fatal_error_occurred ((((uint32_t) state) << 16) | error);
+}
+
+/**
+ * Searches for the node with specified dev/block.
+ *
+ * @param root pointer to the root node of the AVL-Tree
+ * @param dev device search key
+ * @param block block search key
+ * @retval NULL node with the specified dev/block is not found
+ * @return pointer to the node with specified dev/block
+ */
+static rtems_bdbuf_buffer *
+rtems_bdbuf_avl_search (rtems_bdbuf_buffer** root,
+ dev_t dev,
+ rtems_blkdev_bnum block)
+{
+ rtems_bdbuf_buffer* p = *root;
+
+ while ((p != NULL) && ((p->dev != dev) || (p->block != block)))
+ {
+ if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
+ {
+ p = p->avl.right;
+ }
+ else
+ {
+ p = p->avl.left;
+ }
+ }
+
+ return p;
+}
+
+/**
+ * Inserts the specified node to the AVl-Tree.
+ *
+ * @param root pointer to the root node of the AVL-Tree
+ * @param node Pointer to the node to add.
+ * @retval 0 The node added successfully
+ * @retval -1 An error occured
+ */
+static int
+rtems_bdbuf_avl_insert(rtems_bdbuf_buffer** root,
+ rtems_bdbuf_buffer* node)
+{
+ dev_t dev = node->dev;
+ rtems_blkdev_bnum block = node->block;
+
+ rtems_bdbuf_buffer* p = *root;
+ rtems_bdbuf_buffer* q;
+ rtems_bdbuf_buffer* p1;
+ rtems_bdbuf_buffer* p2;
+ rtems_bdbuf_buffer* buf_stack[RTEMS_BDBUF_AVL_MAX_HEIGHT];
+ rtems_bdbuf_buffer** buf_prev = buf_stack;
+
+ bool modified = false;
+
+ if (p == NULL)
+ {
+ *root = node;
+ node->avl.left = NULL;
+ node->avl.right = NULL;
+ node->avl.bal = 0;
+ return 0;
+ }
+
+ while (p != NULL)
+ {
+ *buf_prev++ = p;
+
+ if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
+ {
+ p->avl.cache = 1;
+ q = p->avl.right;
+ if (q == NULL)
+ {
+ q = node;
+ p->avl.right = q = node;
+ break;
+ }
+ }
+ else if ((p->dev != dev) || (p->block != block))
+ {
+ p->avl.cache = -1;
+ q = p->avl.left;
+ if (q == NULL)
+ {
+ q = node;
+ p->avl.left = q;
+ break;
+ }
+ }
+ else
+ {
+ return -1;
+ }
+
+ p = q;
+ }
+
+ q->avl.left = q->avl.right = NULL;
+ q->avl.bal = 0;
+ modified = true;
+ buf_prev--;
+
+ while (modified)
+ {
+ if (p->avl.cache == -1)
+ {
+ switch (p->avl.bal)
+ {
+ case 1:
+ p->avl.bal = 0;
+ modified = false;
+ break;
+
+ case 0:
+ p->avl.bal = -1;
+ break;
+
+ case -1:
+ p1 = p->avl.left;
+ if (p1->avl.bal == -1) /* simple LL-turn */
+ {
+ p->avl.left = p1->avl.right;
+ p1->avl.right = p;
+ p->avl.bal = 0;
+ p = p1;
+ }
+ else /* double LR-turn */
+ {
+ p2 = p1->avl.right;
+ p1->avl.right = p2->avl.left;
+ p2->avl.left = p1;
+ p->avl.left = p2->avl.right;
+ p2->avl.right = p;
+ if (p2->avl.bal == -1) p->avl.bal = +1; else p->avl.bal = 0;
+ if (p2->avl.bal == +1) p1->avl.bal = -1; else p1->avl.bal = 0;
+ p = p2;
+ }
+ p->avl.bal = 0;
+ modified = false;
+ break;
+
+ default:
+ break;
+ }
+ }
+ else
+ {
+ switch (p->avl.bal)
+ {
+ case -1:
+ p->avl.bal = 0;
+ modified = false;
+ break;
+
+ case 0:
+ p->avl.bal = 1;
+ break;
+
+ case 1:
+ p1 = p->avl.right;
+ if (p1->avl.bal == 1) /* simple RR-turn */
+ {
+ p->avl.right = p1->avl.left;
+ p1->avl.left = p;
+ p->avl.bal = 0;
+ p = p1;
+ }
+ else /* double RL-turn */
+ {
+ p2 = p1->avl.left;
+ p1->avl.left = p2->avl.right;
+ p2->avl.right = p1;
+ p->avl.right = p2->avl.left;
+ p2->avl.left = p;
+ if (p2->avl.bal == +1) p->avl.bal = -1; else p->avl.bal = 0;
+ if (p2->avl.bal == -1) p1->avl.bal = +1; else p1->avl.bal = 0;
+ p = p2;
+ }
+ p->avl.bal = 0;
+ modified = false;
+ break;
+
+ default:
+ break;
+ }
+ }
+ q = p;
+ if (buf_prev > buf_stack)
+ {
+ p = *--buf_prev;
+
+ if (p->avl.cache == -1)
+ {
+ p->avl.left = q;
+ }
+ else
+ {
+ p->avl.right = q;
+ }
+ }
+ else
+ {
+ *root = p;
+ break;
+ }
+ };
+
+ return 0;
+}
+
+
+/**
+ * Removes the node from the tree.
+ *
+ * @param root Pointer to pointer to the root node
+ * @param node Pointer to the node to remove
+ * @retval 0 Item removed
+ * @retval -1 No such item found
+ */
+static int
+rtems_bdbuf_avl_remove(rtems_bdbuf_buffer** root,
+ const rtems_bdbuf_buffer* node)
+{
+ dev_t dev = node->dev;
+ rtems_blkdev_bnum block = node->block;
+
+ rtems_bdbuf_buffer* p = *root;
+ rtems_bdbuf_buffer* q;
+ rtems_bdbuf_buffer* r;
+ rtems_bdbuf_buffer* s;
+ rtems_bdbuf_buffer* p1;
+ rtems_bdbuf_buffer* p2;
+ rtems_bdbuf_buffer* buf_stack[RTEMS_BDBUF_AVL_MAX_HEIGHT];
+ rtems_bdbuf_buffer** buf_prev = buf_stack;
+
+ bool modified = false;
+
+ memset (buf_stack, 0, sizeof(buf_stack));
+
+ while (p != NULL)
+ {
+ *buf_prev++ = p;
+
+ if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
+ {
+ p->avl.cache = 1;
+ p = p->avl.right;
+ }
+ else if ((p->dev != dev) || (p->block != block))
+ {
+ p->avl.cache = -1;
+ p = p->avl.left;
+ }
+ else
+ {
+ /* node found */
+ break;
+ }
+ }
+
+ if (p == NULL)
+ {
+ /* there is no such node */
+ return -1;
+ }
+
+ q = p;
+
+ buf_prev--;
+ if (buf_prev > buf_stack)
+ {
+ p = *(buf_prev - 1);
+ }
+ else
+ {
+ p = NULL;
+ }
+
+ /* at this moment q - is a node to delete, p is q's parent */
+ if (q->avl.right == NULL)
+ {
+ r = q->avl.left;
+ if (r != NULL)
+ {
+ r->avl.bal = 0;
+ }
+ q = r;
+ }
+ else
+ {
+ rtems_bdbuf_buffer **t;
+
+ r = q->avl.right;
+
+ if (r->avl.left == NULL)
+ {
+ r->avl.left = q->avl.left;
+ r->avl.bal = q->avl.bal;
+ r->avl.cache = 1;
+ *buf_prev++ = q = r;
+ }
+ else
+ {
+ t = buf_prev++;
+ s = r;
+
+ while (s->avl.left != NULL)
+ {
+ *buf_prev++ = r = s;
+ s = r->avl.left;
+ r->avl.cache = -1;
+ }
+
+ s->avl.left = q->avl.left;
+ r->avl.left = s->avl.right;
+ s->avl.right = q->avl.right;
+ s->avl.bal = q->avl.bal;
+ s->avl.cache = 1;
+
+ *t = q = s;
+ }
+ }
+
+ if (p != NULL)
+ {
+ if (p->avl.cache == -1)
+ {
+ p->avl.left = q;
+ }
+ else
+ {
+ p->avl.right = q;
+ }
+ }
+ else
+ {
+ *root = q;
+ }
+
+ modified = true;
+
+ while (modified)
+ {
+ if (buf_prev > buf_stack)
+ {
+ p = *--buf_prev;
+ }
+ else
+ {
+ break;
+ }
+
+ if (p->avl.cache == -1)
+ {
+ /* rebalance left branch */
+ switch (p->avl.bal)
+ {
+ case -1:
+ p->avl.bal = 0;
+ break;
+ case 0:
+ p->avl.bal = 1;
+ modified = false;
+ break;
+
+ case +1:
+ p1 = p->avl.right;
+
+ if (p1->avl.bal >= 0) /* simple RR-turn */
+ {
+ p->avl.right = p1->avl.left;
+ p1->avl.left = p;
+
+ if (p1->avl.bal == 0)
+ {
+ p1->avl.bal = -1;
+ modified = false;
+ }
+ else
+ {
+ p->avl.bal = 0;
+ p1->avl.bal = 0;
+ }
+ p = p1;
+ }
+ else /* double RL-turn */
+ {
+ p2 = p1->avl.left;
+
+ p1->avl.left = p2->avl.right;
+ p2->avl.right = p1;
+ p->avl.right = p2->avl.left;
+ p2->avl.left = p;
+
+ if (p2->avl.bal == +1) p->avl.bal = -1; else p->avl.bal = 0;
+ if (p2->avl.bal == -1) p1->avl.bal = 1; else p1->avl.bal = 0;
+
+ p = p2;
+ p2->avl.bal = 0;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ else
+ {
+ /* rebalance right branch */
+ switch (p->avl.bal)
+ {
+ case +1:
+ p->avl.bal = 0;
+ break;
+
+ case 0:
+ p->avl.bal = -1;
+ modified = false;
+ break;
+
+ case -1:
+ p1 = p->avl.left;
+
+ if (p1->avl.bal <= 0) /* simple LL-turn */
+ {
+ p->avl.left = p1->avl.right;
+ p1->avl.right = p;
+ if (p1->avl.bal == 0)
+ {
+ p1->avl.bal = 1;
+ modified = false;
+ }
+ else
+ {
+ p->avl.bal = 0;
+ p1->avl.bal = 0;
+ }
+ p = p1;
+ }
+ else /* double LR-turn */
+ {
+ p2 = p1->avl.right;
+
+ p1->avl.right = p2->avl.left;
+ p2->avl.left = p1;
+ p->avl.left = p2->avl.right;
+ p2->avl.right = p;
+
+ if (p2->avl.bal == -1) p->avl.bal = 1; else p->avl.bal = 0;
+ if (p2->avl.bal == +1) p1->avl.bal = -1; else p1->avl.bal = 0;
+
+ p = p2;
+ p2->avl.bal = 0;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (buf_prev > buf_stack)
+ {
+ q = *(buf_prev - 1);
+
+ if (q->avl.cache == -1)
+ {
+ q->avl.left = p;
+ }
+ else
+ {
+ q->avl.right = p;
+ }
+ }
+ else
+ {
+ *root = p;
+ break;
+ }
+
+ }
+
+ return 0;
+}
+
+static void
+rtems_bdbuf_set_state (rtems_bdbuf_buffer *bd, rtems_bdbuf_buf_state state)
+{
+ bd->state = state;
+}
+
+/**
+ * Change the block number for the block size to the block number for the media
+ * block size. We have to use 64bit maths. There is no short cut here.
+ *
+ * @param block The logical block number in the block size terms.
+ * @param block_size The block size.
+ * @param media_block_size The block size of the media.
+ * @return rtems_blkdev_bnum The media block number.
+ */
+static rtems_blkdev_bnum
+rtems_bdbuf_media_block (rtems_blkdev_bnum block,
+ size_t block_size,
+ size_t media_block_size)
+{
+ return (rtems_blkdev_bnum)
+ ((((uint64_t) block) * block_size) / media_block_size);
+}
+
+/**
+ * Lock the mutex. A single task can nest calls.
+ *
+ * @param lock The mutex to lock.
+ * @param fatal_error_code The error code if the call fails.
+ */
+static void
+rtems_bdbuf_lock (rtems_id lock, uint32_t fatal_error_code)
+{
+ rtems_status_code sc = rtems_semaphore_obtain (lock,
+ RTEMS_WAIT,
+ RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (fatal_error_code);
+}
+
+/**
+ * Unlock the mutex.
+ *
+ * @param lock The mutex to unlock.
+ * @param fatal_error_code The error code if the call fails.
+ */
+static void
+rtems_bdbuf_unlock (rtems_id lock, uint32_t fatal_error_code)
+{
+ rtems_status_code sc = rtems_semaphore_release (lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (fatal_error_code);
+}
+
+/**
+ * Lock the cache. A single task can nest calls.
+ */
+static void
+rtems_bdbuf_lock_cache (void)
+{
+ rtems_bdbuf_lock (bdbuf_cache.lock, RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK);
+}
+
+/**
+ * Unlock the cache.
+ */
+static void
+rtems_bdbuf_unlock_cache (void)
+{
+ rtems_bdbuf_unlock (bdbuf_cache.lock, RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK);
+}
+
+/**
+ * Lock the cache's sync. A single task can nest calls.
+ */
+static void
+rtems_bdbuf_lock_sync (void)
+{
+ rtems_bdbuf_lock (bdbuf_cache.sync_lock, RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK);
+}
+
+/**
+ * Unlock the cache's sync lock. Any blocked writers are woken.
+ */
+static void
+rtems_bdbuf_unlock_sync (void)
+{
+ rtems_bdbuf_unlock (bdbuf_cache.sync_lock,
+ RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK);
+}
+
+static void
+rtems_bdbuf_group_obtain (rtems_bdbuf_buffer *bd)
+{
+ ++bd->group->users;
+}
+
+static void
+rtems_bdbuf_group_release (rtems_bdbuf_buffer *bd)
+{
+ --bd->group->users;
+}
+
+static rtems_mode
+rtems_bdbuf_disable_preemption (void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_mode prev_mode = 0;
+
+ sc = rtems_task_mode (RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_DIS);
+
+ return prev_mode;
+}
+
+static void
+rtems_bdbuf_restore_preemption (rtems_mode prev_mode)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_task_mode (prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_RST);
+}
+
+/**
+ * Wait until woken. Semaphores are used so a number of tasks can wait and can
+ * be woken at once. Task events would require we maintain a list of tasks to
+ * be woken and this would require storage and we do not know the number of
+ * tasks that could be waiting.
+ *
+ * While we have the cache locked we can try and claim the semaphore and
+ * therefore know when we release the lock to the cache we will block until the
+ * semaphore is released. This may even happen before we get to block.
+ *
+ * A counter is used to save the release call when no one is waiting.
+ *
+ * The function assumes the cache is locked on entry and it will be locked on
+ * exit.
+ */
+static void
+rtems_bdbuf_anonymous_wait (rtems_bdbuf_waiters *waiters)
+{
+ rtems_status_code sc;
+ rtems_mode prev_mode;
+
+ /*
+ * Indicate we are waiting.
+ */
+ ++waiters->count;
+
+ /*
+ * Disable preemption then unlock the cache and block. There is no POSIX
+ * condition variable in the core API so this is a work around.
+ *
+ * The issue is a task could preempt after the cache is unlocked because it is
+ * blocking or just hits that window, and before this task has blocked on the
+ * semaphore. If the preempting task flushes the queue this task will not see
+ * the flush and may block for ever or until another transaction flushes this
+ * semaphore.
+ */
+ prev_mode = rtems_bdbuf_disable_preemption ();
+
+ /*
+ * Unlock the cache, wait, and lock the cache when we return.
+ */
+ rtems_bdbuf_unlock_cache ();
+
+ sc = rtems_semaphore_obtain (waiters->sema, RTEMS_WAIT, RTEMS_BDBUF_WAIT_TIMEOUT);
+
+ if (sc == RTEMS_TIMEOUT)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_TO);
+
+ if (sc != RTEMS_UNSATISFIED)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2);
+
+ rtems_bdbuf_lock_cache ();
+
+ rtems_bdbuf_restore_preemption (prev_mode);
+
+ --waiters->count;
+}
+
+static void
+rtems_bdbuf_wait (rtems_bdbuf_buffer *bd, rtems_bdbuf_waiters *waiters)
+{
+ rtems_bdbuf_group_obtain (bd);
+ ++bd->waiters;
+ rtems_bdbuf_anonymous_wait (waiters);
+ --bd->waiters;
+ rtems_bdbuf_group_release (bd);
+}
+
+/**
+ * Wake a blocked resource. The resource has a counter that lets us know if
+ * there are any waiters.
+ */
+static void
+rtems_bdbuf_wake (const rtems_bdbuf_waiters *waiters)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (waiters->count > 0)
+ {
+ sc = rtems_semaphore_flush (waiters->sema);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE);
+ }
+}
+
+static void
+rtems_bdbuf_wake_swapper (void)
+{
+ rtems_status_code sc = rtems_event_send (bdbuf_cache.swapout,
+ RTEMS_BDBUF_SWAPOUT_SYNC);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE);
+}
+
+static bool
+rtems_bdbuf_has_buffer_waiters (void)
+{
+ return bdbuf_cache.buffer_waiters.count;
+}
+
+static void
+rtems_bdbuf_remove_from_tree (rtems_bdbuf_buffer *bd)
+{
+ if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_TREE_RM);
+}
+
+static void
+rtems_bdbuf_remove_from_tree_and_lru_list (rtems_bdbuf_buffer *bd)
+{
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_FREE:
+ break;
+ case RTEMS_BDBUF_STATE_CACHED:
+ rtems_bdbuf_remove_from_tree (bd);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_10);
+ }
+
+ rtems_chain_extract (&bd->link);
+}
+
+static void
+rtems_bdbuf_make_free_and_add_to_lru_list (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_FREE);
+ rtems_chain_prepend (&bdbuf_cache.lru, &bd->link);
+}
+
+static void
+rtems_bdbuf_make_empty (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_EMPTY);
+}
+
+static void
+rtems_bdbuf_make_cached_and_add_to_lru_list (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_CACHED);
+ rtems_chain_append (&bdbuf_cache.lru, &bd->link);
+}
+
+static void
+rtems_bdbuf_discard_buffer (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_make_empty (bd);
+
+ if (bd->waiters == 0)
+ {
+ rtems_bdbuf_remove_from_tree (bd);
+ rtems_bdbuf_make_free_and_add_to_lru_list (bd);
+ }
+}
+
+static void
+rtems_bdbuf_add_to_modified_list_after_access (rtems_bdbuf_buffer *bd)
+{
+ if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dev)
+ {
+ rtems_bdbuf_unlock_cache ();
+
+ /*
+ * Wait for the sync lock.
+ */
+ rtems_bdbuf_lock_sync ();
+
+ rtems_bdbuf_unlock_sync ();
+ rtems_bdbuf_lock_cache ();
+ }
+
+ /*
+ * Only the first modified release sets the timer and any further user
+ * accesses do not change the timer value which should move down. This
+ * assumes the user's hold of the buffer is much less than the time on the
+ * modified list. Resetting the timer on each access which could result in a
+ * buffer never getting to 0 and never being forced onto disk. This raises a
+ * difficult question. Is a snapshot of a block that is changing better than
+ * nothing being written? We have tended to think we should hold changes for
+ * only a specific period of time even if still changing and get onto disk
+ * and letting the file system try and recover this position if it can.
+ */
+ if (bd->state == RTEMS_BDBUF_STATE_ACCESS_CACHED
+ || bd->state == RTEMS_BDBUF_STATE_ACCESS_EMPTY)
+ bd->hold_timer = bdbuf_config.swap_block_hold;
+
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_MODIFIED);
+ rtems_chain_append (&bdbuf_cache.modified, &bd->link);
+
+ if (bd->waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.access_waiters);
+ else if (rtems_bdbuf_has_buffer_waiters ())
+ rtems_bdbuf_wake_swapper ();
+}
+
+static void
+rtems_bdbuf_add_to_lru_list_after_access (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_group_release (bd);
+ rtems_bdbuf_make_cached_and_add_to_lru_list (bd);
+
+ if (bd->waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.access_waiters);
+ else
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+}
+
+/**
+ * Compute the number of BDs per group for a given buffer size.
+ *
+ * @param size The buffer size. It can be any size and we scale up.
+ */
+static size_t
+rtems_bdbuf_bds_per_group (size_t size)
+{
+ size_t bufs_per_size;
+ size_t bds_per_size;
+
+ if (size > bdbuf_config.buffer_max)
+ return 0;
+
+ bufs_per_size = ((size - 1) / bdbuf_config.buffer_min) + 1;
+
+ for (bds_per_size = 1;
+ bds_per_size < bufs_per_size;
+ bds_per_size <<= 1)
+ ;
+
+ return bdbuf_cache.max_bds_per_group / bds_per_size;
+}
+
+static void
+rtems_bdbuf_discard_buffer_after_access (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_group_release (bd);
+ rtems_bdbuf_discard_buffer (bd);
+
+ if (bd->waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.access_waiters);
+ else
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+}
+
+/**
+ * Reallocate a group. The BDs currently allocated in the group are removed
+ * from the ALV tree and any lists then the new BD's are prepended to the ready
+ * list of the cache.
+ *
+ * @param group The group to reallocate.
+ * @param new_bds_per_group The new count of BDs per group.
+ * @return A buffer of this group.
+ */
+static rtems_bdbuf_buffer *
+rtems_bdbuf_group_realloc (rtems_bdbuf_group* group, size_t new_bds_per_group)
+{
+ rtems_bdbuf_buffer* bd;
+ size_t b;
+ size_t bufs_per_bd;
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:realloc: %tu: %zd -> %zd\n",
+ group - bdbuf_cache.groups, group->bds_per_group,
+ new_bds_per_group);
+
+ bufs_per_bd = bdbuf_cache.max_bds_per_group / group->bds_per_group;
+
+ for (b = 0, bd = group->bdbuf;
+ b < group->bds_per_group;
+ b++, bd += bufs_per_bd)
+ rtems_bdbuf_remove_from_tree_and_lru_list (bd);
+
+ group->bds_per_group = new_bds_per_group;
+ bufs_per_bd = bdbuf_cache.max_bds_per_group / new_bds_per_group;
+
+ for (b = 1, bd = group->bdbuf + bufs_per_bd;
+ b < group->bds_per_group;
+ b++, bd += bufs_per_bd)
+ rtems_bdbuf_make_free_and_add_to_lru_list (bd);
+
+ if (b > 1)
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+
+ return group->bdbuf;
+}
+
+static void
+rtems_bdbuf_setup_empty_buffer (rtems_bdbuf_buffer *bd,
+ dev_t dev,
+ rtems_blkdev_bnum block)
+{
+ bd->dev = dev;
+ bd->block = block;
+ bd->avl.left = NULL;
+ bd->avl.right = NULL;
+ bd->waiters = 0;
+
+ if (rtems_bdbuf_avl_insert (&bdbuf_cache.tree, bd) != 0)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_RECYCLE);
+
+ rtems_bdbuf_make_empty (bd);
+}
+
+static rtems_bdbuf_buffer *
+rtems_bdbuf_get_buffer_from_lru_list (dev_t dev,
+ rtems_blkdev_bnum block,
+ size_t bds_per_group)
+{
+ rtems_chain_node *node = rtems_chain_first (&bdbuf_cache.lru);
+
+ while (!rtems_chain_is_tail (&bdbuf_cache.lru, node))
+ {
+ rtems_bdbuf_buffer *bd = (rtems_bdbuf_buffer *) node;
+ rtems_bdbuf_buffer *empty_bd = NULL;
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:next-bd: %tu (%td:%" PRId32 ") %zd -> %zd\n",
+ bd - bdbuf_cache.bds,
+ bd->group - bdbuf_cache.groups, bd->group->users,
+ bd->group->bds_per_group, bds_per_group);
+
+ /*
+ * If nobody waits for this BD, we may recycle it.
+ */
+ if (bd->waiters == 0)
+ {
+ if (bd->group->bds_per_group == bds_per_group)
+ {
+ rtems_bdbuf_remove_from_tree_and_lru_list (bd);
+
+ empty_bd = bd;
+ }
+ else if (bd->group->users == 0)
+ empty_bd = rtems_bdbuf_group_realloc (bd->group, bds_per_group);
+ }
+
+ if (empty_bd != NULL)
+ {
+ rtems_bdbuf_setup_empty_buffer (empty_bd, dev, block);
+
+ return empty_bd;
+ }
+
+ node = rtems_chain_next (node);
+ }
+
+ return NULL;
+}
+
+/**
+ * Initialise the cache.
+ *
+ * @return rtems_status_code The initialisation status.
+ */
+rtems_status_code
+rtems_bdbuf_init (void)
+{
+ rtems_bdbuf_group* group;
+ rtems_bdbuf_buffer* bd;
+ uint8_t* buffer;
+ size_t b;
+ size_t cache_aligment;
+ rtems_status_code sc;
+ rtems_mode prev_mode;
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:init\n");
+
+ if (rtems_interrupt_is_in_progress())
+ return RTEMS_CALLED_FROM_ISR;
+
+ /*
+ * Check the configuration table values.
+ */
+ if ((bdbuf_config.buffer_max % bdbuf_config.buffer_min) != 0)
+ return RTEMS_INVALID_NUMBER;
+
+ /*
+ * We use a special variable to manage the initialisation incase we have
+ * completing threads doing this. You may get errors if the another thread
+ * makes a call and we have not finished initialisation.
+ */
+ prev_mode = rtems_bdbuf_disable_preemption ();
+ if (bdbuf_cache.initialised)
+ {
+ rtems_bdbuf_restore_preemption (prev_mode);
+ return RTEMS_RESOURCE_IN_USE;
+ }
+
+ memset(&bdbuf_cache, 0, sizeof(bdbuf_cache));
+ bdbuf_cache.initialised = true;
+ rtems_bdbuf_restore_preemption (prev_mode);
+
+ /*
+ * For unspecified cache alignments we use the CPU alignment.
+ */
+ cache_aligment = 32; /* FIXME rtems_cache_get_data_line_size() */
+ if (cache_aligment <= 0)
+ cache_aligment = CPU_ALIGNMENT;
+
+ bdbuf_cache.sync_device = BDBUF_INVALID_DEV;
+
+ rtems_chain_initialize_empty (&bdbuf_cache.swapout_workers);
+ rtems_chain_initialize_empty (&bdbuf_cache.lru);
+ rtems_chain_initialize_empty (&bdbuf_cache.modified);
+ rtems_chain_initialize_empty (&bdbuf_cache.sync);
+
+ /*
+ * Create the locks for the cache.
+ */
+ sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 'l'),
+ 1, RTEMS_BDBUF_CACHE_LOCK_ATTRIBS, 0,
+ &bdbuf_cache.lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ rtems_bdbuf_lock_cache ();
+
+ sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 's'),
+ 1, RTEMS_BDBUF_CACHE_LOCK_ATTRIBS, 0,
+ &bdbuf_cache.sync_lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 'a'),
+ 0, RTEMS_BDBUF_CACHE_WAITER_ATTRIBS, 0,
+ &bdbuf_cache.access_waiters.sema);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 't'),
+ 0, RTEMS_BDBUF_CACHE_WAITER_ATTRIBS, 0,
+ &bdbuf_cache.transfer_waiters.sema);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 'b'),
+ 0, RTEMS_BDBUF_CACHE_WAITER_ATTRIBS, 0,
+ &bdbuf_cache.buffer_waiters.sema);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ /*
+ * Compute the various number of elements in the cache.
+ */
+ bdbuf_cache.buffer_min_count =
+ bdbuf_config.size / bdbuf_config.buffer_min;
+ bdbuf_cache.max_bds_per_group =
+ bdbuf_config.buffer_max / bdbuf_config.buffer_min;
+ bdbuf_cache.group_count =
+ bdbuf_cache.buffer_min_count / bdbuf_cache.max_bds_per_group;
+
+ /*
+ * Allocate the memory for the buffer descriptors.
+ */
+ bdbuf_cache.bds = calloc (sizeof (rtems_bdbuf_buffer),
+ bdbuf_cache.buffer_min_count);
+ if (!bdbuf_cache.bds)
+ goto error;
+
+ /*
+ * Allocate the memory for the buffer descriptors.
+ */
+ bdbuf_cache.groups = calloc (sizeof (rtems_bdbuf_group),
+ bdbuf_cache.group_count);
+ if (!bdbuf_cache.groups)
+ goto error;
+
+ /*
+ * Allocate memory for buffer memory. The buffer memory will be cache
+ * aligned. It is possible to free the memory allocated by rtems_memalign()
+ * with free(). Return 0 if allocated.
+ *
+ * The memory allocate allows a
+ */
+ if (rtems_memalign ((void **) &bdbuf_cache.buffers,
+ cache_aligment,
+ bdbuf_cache.buffer_min_count * bdbuf_config.buffer_min) != 0)
+ goto error;
+
+ /*
+ * The cache is empty after opening so we need to add all the buffers to it
+ * and initialise the groups.
+ */
+ for (b = 0, group = bdbuf_cache.groups,
+ bd = bdbuf_cache.bds, buffer = bdbuf_cache.buffers;
+ b < bdbuf_cache.buffer_min_count;
+ b++, bd++, buffer += bdbuf_config.buffer_min)
+ {
+ bd->dev = BDBUF_INVALID_DEV;
+ bd->group = group;
+ bd->buffer = buffer;
+
+ rtems_chain_append (&bdbuf_cache.lru, &bd->link);
+
+ if ((b % bdbuf_cache.max_bds_per_group) ==
+ (bdbuf_cache.max_bds_per_group - 1))
+ group++;
+ }
+
+ for (b = 0,
+ group = bdbuf_cache.groups,
+ bd = bdbuf_cache.bds;
+ b < bdbuf_cache.group_count;
+ b++,
+ group++,
+ bd += bdbuf_cache.max_bds_per_group)
+ {
+ group->bds_per_group = bdbuf_cache.max_bds_per_group;
+ group->bdbuf = bd;
+ }
+
+ /*
+ * Create and start swapout task. This task will create and manage the worker
+ * threads.
+ */
+ bdbuf_cache.swapout_enabled = true;
+
+ sc = rtems_task_create (rtems_build_name('B', 'S', 'W', 'P'),
+ bdbuf_config.swapout_priority ?
+ bdbuf_config.swapout_priority :
+ RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT,
+ SWAPOUT_TASK_STACK_SIZE,
+ RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
+ RTEMS_LOCAL | RTEMS_NO_FLOATING_POINT,
+ &bdbuf_cache.swapout);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ sc = rtems_task_start (bdbuf_cache.swapout,
+ rtems_bdbuf_swapout_task,
+ (rtems_task_argument) &bdbuf_cache);
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error;
+
+ rtems_bdbuf_unlock_cache ();
+
+ return RTEMS_SUCCESSFUL;
+
+error:
+
+ if (bdbuf_cache.swapout != 0)
+ rtems_task_delete (bdbuf_cache.swapout);
+
+ free (bdbuf_cache.buffers);
+ free (bdbuf_cache.groups);
+ free (bdbuf_cache.bds);
+
+ rtems_semaphore_delete (bdbuf_cache.buffer_waiters.sema);
+ rtems_semaphore_delete (bdbuf_cache.access_waiters.sema);
+ rtems_semaphore_delete (bdbuf_cache.transfer_waiters.sema);
+ rtems_semaphore_delete (bdbuf_cache.sync_lock);
+
+ if (bdbuf_cache.lock != 0)
+ {
+ rtems_bdbuf_unlock_cache ();
+ rtems_semaphore_delete (bdbuf_cache.lock);
+ }
+
+ bdbuf_cache.initialised = false;
+
+ return RTEMS_UNSATISFIED;
+}
+
+static void
+rtems_bdbuf_wait_for_event (rtems_event_set event)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_event_set out = 0;
+
+ sc = rtems_event_receive (event,
+ RTEMS_EVENT_ALL | RTEMS_WAIT,
+ RTEMS_NO_TIMEOUT,
+ &out);
+
+ if (sc != RTEMS_SUCCESSFUL || out != event)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_WAIT_EVNT);
+}
+
+static void
+rtems_bdbuf_wait_for_access (rtems_bdbuf_buffer *bd)
+{
+ while (true)
+ {
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ rtems_bdbuf_group_release (bd);
+ /* Fall through */
+ case RTEMS_BDBUF_STATE_CACHED:
+ rtems_chain_extract (&bd->link);
+ /* Fall through */
+ case RTEMS_BDBUF_STATE_EMPTY:
+ return;
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ rtems_bdbuf_wait (bd, &bdbuf_cache.access_waiters);
+ break;
+ case RTEMS_BDBUF_STATE_SYNC:
+ case RTEMS_BDBUF_STATE_TRANSFER:
+ case RTEMS_BDBUF_STATE_TRANSFER_PURGED:
+ rtems_bdbuf_wait (bd, &bdbuf_cache.transfer_waiters);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_7);
+ }
+ }
+}
+
+static void
+rtems_bdbuf_request_sync_for_modified_buffer (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_SYNC);
+ rtems_chain_extract (&bd->link);
+ rtems_chain_append (&bdbuf_cache.sync, &bd->link);
+ rtems_bdbuf_wake_swapper ();
+}
+
+/**
+ * @brief Waits until the buffer is ready for recycling.
+ *
+ * @retval @c true Buffer is valid and may be recycled.
+ * @retval @c false Buffer is invalid and has to searched again.
+ */
+static bool
+rtems_bdbuf_wait_for_recycle (rtems_bdbuf_buffer *bd)
+{
+ while (true)
+ {
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_FREE:
+ return true;
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ rtems_bdbuf_request_sync_for_modified_buffer (bd);
+ break;
+ case RTEMS_BDBUF_STATE_CACHED:
+ case RTEMS_BDBUF_STATE_EMPTY:
+ if (bd->waiters == 0)
+ return true;
+ else
+ {
+ /*
+ * It is essential that we wait here without a special wait count and
+ * without the group in use. Otherwise we could trigger a wait ping
+ * pong with another recycle waiter. The state of the buffer is
+ * arbitrary afterwards.
+ */
+ rtems_bdbuf_anonymous_wait (&bdbuf_cache.buffer_waiters);
+ return false;
+ }
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ rtems_bdbuf_wait (bd, &bdbuf_cache.access_waiters);
+ break;
+ case RTEMS_BDBUF_STATE_SYNC:
+ case RTEMS_BDBUF_STATE_TRANSFER:
+ case RTEMS_BDBUF_STATE_TRANSFER_PURGED:
+ rtems_bdbuf_wait (bd, &bdbuf_cache.transfer_waiters);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_8);
+ }
+ }
+}
+
+static void
+rtems_bdbuf_wait_for_sync_done (rtems_bdbuf_buffer *bd)
+{
+ while (true)
+ {
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_CACHED:
+ case RTEMS_BDBUF_STATE_EMPTY:
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ return;
+ case RTEMS_BDBUF_STATE_SYNC:
+ case RTEMS_BDBUF_STATE_TRANSFER:
+ case RTEMS_BDBUF_STATE_TRANSFER_PURGED:
+ rtems_bdbuf_wait (bd, &bdbuf_cache.transfer_waiters);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_9);
+ }
+ }
+}
+
+static void
+rtems_bdbuf_wait_for_buffer (void)
+{
+ if (!rtems_chain_is_empty (&bdbuf_cache.modified))
+ rtems_bdbuf_wake_swapper ();
+
+ rtems_bdbuf_anonymous_wait (&bdbuf_cache.buffer_waiters);
+}
+
+static void
+rtems_bdbuf_sync_after_access (rtems_bdbuf_buffer *bd)
+{
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_SYNC);
+
+ rtems_chain_append (&bdbuf_cache.sync, &bd->link);
+
+ if (bd->waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.access_waiters);
+
+ rtems_bdbuf_wake_swapper ();
+ rtems_bdbuf_wait_for_sync_done (bd);
+
+ /*
+ * We may have created a cached or empty buffer which may be recycled.
+ */
+ if (bd->waiters == 0
+ && (bd->state == RTEMS_BDBUF_STATE_CACHED
+ || bd->state == RTEMS_BDBUF_STATE_EMPTY))
+ {
+ if (bd->state == RTEMS_BDBUF_STATE_EMPTY)
+ {
+ rtems_bdbuf_remove_from_tree (bd);
+ rtems_bdbuf_make_free_and_add_to_lru_list (bd);
+ }
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+ }
+}
+
+static rtems_bdbuf_buffer *
+rtems_bdbuf_get_buffer_for_read_ahead (dev_t dev,
+ rtems_blkdev_bnum block,
+ size_t bds_per_group)
+{
+ rtems_bdbuf_buffer *bd = NULL;
+
+ bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
+
+ if (bd == NULL)
+ {
+ bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
+
+ if (bd != NULL)
+ rtems_bdbuf_group_obtain (bd);
+ }
+ else
+ /*
+ * The buffer is in the cache. So it is already available or in use, and
+ * thus no need for a read ahead.
+ */
+ bd = NULL;
+
+ return bd;
+}
+
+static rtems_bdbuf_buffer *
+rtems_bdbuf_get_buffer_for_access (dev_t dev,
+ rtems_blkdev_bnum block,
+ size_t bds_per_group)
+{
+ rtems_bdbuf_buffer *bd = NULL;
+
+ do
+ {
+ bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
+
+ if (bd != NULL)
+ {
+ if (bd->group->bds_per_group != bds_per_group)
+ {
+ if (rtems_bdbuf_wait_for_recycle (bd))
+ {
+ rtems_bdbuf_remove_from_tree_and_lru_list (bd);
+ rtems_bdbuf_make_free_and_add_to_lru_list (bd);
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+ }
+ bd = NULL;
+ }
+ }
+ else
+ {
+ bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
+
+ if (bd == NULL)
+ rtems_bdbuf_wait_for_buffer ();
+ }
+ }
+ while (bd == NULL);
+
+ rtems_bdbuf_wait_for_access (bd);
+ rtems_bdbuf_group_obtain (bd);
+
+ return bd;
+}
+
+static rtems_status_code
+rtems_bdbuf_obtain_disk (dev_t dev,
+ rtems_blkdev_bnum block,
+ rtems_disk_device **dd_ptr,
+ rtems_blkdev_bnum *media_block_ptr,
+ size_t *bds_per_group_ptr)
+{
+ rtems_disk_device *dd = NULL;
+
+ if (!bdbuf_cache.initialised)
+ return RTEMS_NOT_CONFIGURED;
+
+ /*
+ * Do not hold the cache lock when obtaining the disk table.
+ */
+ dd = rtems_disk_obtain (dev);
+ if (dd == NULL)
+ return RTEMS_INVALID_ID;
+
+ *dd_ptr = dd;
+
+ if (media_block_ptr != NULL)
+ {
+ /*
+ * Compute the media block number. Drivers work with media block number not
+ * the block number a BD may have as this depends on the block size set by
+ * the user.
+ */
+ rtems_blkdev_bnum mb = rtems_bdbuf_media_block (block,
+ dd->block_size,
+ dd->media_block_size);
+ if (mb >= dd->size)
+ {
+ rtems_disk_release(dd);
+ return RTEMS_INVALID_NUMBER;
+ }
+
+ *media_block_ptr = mb + dd->start;
+ }
+
+ if (bds_per_group_ptr != NULL)
+ {
+ size_t bds_per_group = rtems_bdbuf_bds_per_group (dd->block_size);
+
+ if (bds_per_group == 0)
+ {
+ rtems_disk_release (dd);
+ return RTEMS_INVALID_NUMBER;
+ }
+
+ *bds_per_group_ptr = bds_per_group;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static void
+rtems_bdbuf_release_disk (rtems_disk_device *dd)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_disk_release (dd);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL);
+}
+
+rtems_status_code
+rtems_bdbuf_get (dev_t dev,
+ rtems_blkdev_bnum block,
+ rtems_bdbuf_buffer **bd_ptr)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *dd = NULL;
+ rtems_bdbuf_buffer *bd = NULL;
+ rtems_blkdev_bnum media_block = 0;
+ size_t bds_per_group = 0;
+
+ sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ rtems_bdbuf_lock_cache ();
+
+ /*
+ * Print the block index relative to the physical disk.
+ */
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
+ media_block, block, (unsigned) dev);
+
+ bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
+
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_CACHED:
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_CACHED);
+ break;
+ case RTEMS_BDBUF_STATE_EMPTY:
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_EMPTY);
+ break;
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ /*
+ * To get a modified buffer could be considered a bug in the caller
+ * because you should not be getting an already modified buffer but user
+ * may have modified a byte in a block then decided to seek the start and
+ * write the whole block and the file system will have no record of this
+ * so just gets the block to fill.
+ */
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_2);
+ break;
+ }
+
+ if (rtems_bdbuf_tracer)
+ {
+ rtems_bdbuf_show_users ("get", bd);
+ rtems_bdbuf_show_usage ();
+ }
+
+ rtems_bdbuf_unlock_cache ();
+
+ rtems_bdbuf_release_disk (dd);
+
+ *bd_ptr = bd;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/**
+ * Call back handler called by the low level driver when the transfer has
+ * completed. This function may be invoked from interrupt handler.
+ *
+ * @param arg Arbitrary argument specified in block device request
+ * structure (in this case - pointer to the appropriate
+ * block device request structure).
+ * @param status I/O completion status
+ */
+static void
+rtems_bdbuf_transfer_done (void* arg, rtems_status_code status)
+{
+ rtems_blkdev_request* req = (rtems_blkdev_request*) arg;
+
+ req->status = status;
+
+ rtems_event_send (req->io_task, RTEMS_BDBUF_TRANSFER_SYNC);
+}
+
+static void
+rtems_bdbuf_create_read_request (const rtems_disk_device *dd,
+ rtems_blkdev_bnum media_block,
+ size_t bds_per_group,
+ rtems_blkdev_request *req,
+ rtems_bdbuf_buffer **bd_ptr)
+{
+ rtems_bdbuf_buffer *bd = NULL;
+ rtems_blkdev_bnum media_block_end = dd->start + dd->size;
+ rtems_blkdev_bnum media_block_count = dd->block_size / dd->media_block_size;
+ dev_t dev = dd->dev;
+ uint32_t block_size = dd->block_size;
+ uint32_t transfer_index = 1;
+ uint32_t transfer_count = bdbuf_config.max_read_ahead_blocks + 1;
+
+ if (media_block_end - media_block < transfer_count)
+ transfer_count = media_block_end - media_block;
+
+ req->req = RTEMS_BLKDEV_REQ_READ;
+ req->req_done = rtems_bdbuf_transfer_done;
+ req->done_arg = req;
+ req->io_task = rtems_task_self ();
+ req->status = RTEMS_RESOURCE_IN_USE;
+ req->bufnum = 0;
+
+ bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
+
+ *bd_ptr = bd;
+
+ req->bufs [0].user = bd;
+ req->bufs [0].block = media_block;
+ req->bufs [0].length = block_size;
+ req->bufs [0].buffer = bd->buffer;
+
+ if (rtems_bdbuf_tracer)
+ rtems_bdbuf_show_users ("read", bd);
+
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_CACHED:
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ return;
+ case RTEMS_BDBUF_STATE_EMPTY:
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_TRANSFER);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_1);
+ break;
+ }
+
+ while (transfer_index < transfer_count)
+ {
+ media_block += media_block_count;
+
+ bd = rtems_bdbuf_get_buffer_for_read_ahead (dev, media_block,
+ bds_per_group);
+
+ if (bd == NULL)
+ break;
+
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_TRANSFER);
+
+ req->bufs [transfer_index].user = bd;
+ req->bufs [transfer_index].block = media_block;
+ req->bufs [transfer_index].length = block_size;
+ req->bufs [transfer_index].buffer = bd->buffer;
+
+ if (rtems_bdbuf_tracer)
+ rtems_bdbuf_show_users ("read-ahead", bd);
+
+ ++transfer_index;
+ }
+
+ req->bufnum = transfer_index;
+}
+
+static rtems_status_code
+rtems_bdbuf_execute_transfer_request (const rtems_disk_device *dd,
+ rtems_blkdev_request *req,
+ bool cache_locked)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int result = 0;
+ uint32_t transfer_index = 0;
+ bool wake_transfer_waiters = false;
+ bool wake_buffer_waiters = false;
+
+ if (cache_locked)
+ rtems_bdbuf_unlock_cache ();
+
+ result = dd->ioctl (dd->phys_dev, RTEMS_BLKIO_REQUEST, req);
+
+ if (result == 0)
+ {
+ rtems_bdbuf_wait_for_event (RTEMS_BDBUF_TRANSFER_SYNC);
+ sc = req->status;
+ }
+ else
+ sc = RTEMS_IO_ERROR;
+
+ rtems_bdbuf_lock_cache ();
+
+ for (transfer_index = 0; transfer_index < req->bufnum; ++transfer_index)
+ {
+ rtems_bdbuf_buffer *bd = req->bufs [transfer_index].user;
+ bool waiters = bd->waiters;
+
+ if (waiters)
+ wake_transfer_waiters = true;
+ else
+ wake_buffer_waiters = true;
+
+ rtems_bdbuf_group_release (bd);
+
+ if (sc == RTEMS_SUCCESSFUL && bd->state == RTEMS_BDBUF_STATE_TRANSFER)
+ rtems_bdbuf_make_cached_and_add_to_lru_list (bd);
+ else
+ rtems_bdbuf_discard_buffer (bd);
+
+ if (rtems_bdbuf_tracer)
+ rtems_bdbuf_show_users ("transfer", bd);
+ }
+
+ if (wake_transfer_waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.transfer_waiters);
+
+ if (wake_buffer_waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+
+ if (!cache_locked)
+ rtems_bdbuf_unlock_cache ();
+
+ if (sc == RTEMS_SUCCESSFUL || sc == RTEMS_UNSATISFIED)
+ return sc;
+ else
+ return RTEMS_IO_ERROR;
+}
+
+rtems_status_code
+rtems_bdbuf_read (dev_t dev,
+ rtems_blkdev_bnum block,
+ rtems_bdbuf_buffer **bd_ptr)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *dd = NULL;
+ rtems_blkdev_request *req = NULL;
+ rtems_bdbuf_buffer *bd = NULL;
+ rtems_blkdev_bnum media_block = 0;
+ size_t bds_per_group = 0;
+
+ sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ /*
+ * TODO: This type of request structure is wrong and should be removed.
+ */
+#define bdbuf_alloc(size) __builtin_alloca (size)
+
+ req = bdbuf_alloc (sizeof (rtems_blkdev_request) +
+ sizeof (rtems_blkdev_sg_buffer) *
+ (bdbuf_config.max_read_ahead_blocks + 1));
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
+ media_block + dd->start, block, (unsigned) dev);
+
+ rtems_bdbuf_lock_cache ();
+ rtems_bdbuf_create_read_request (dd, media_block, bds_per_group, req, &bd);
+
+ if (req->bufnum > 0)
+ {
+ sc = rtems_bdbuf_execute_transfer_request (dd, req, true);
+ if (sc == RTEMS_SUCCESSFUL)
+ {
+ rtems_chain_extract (&bd->link);
+ rtems_bdbuf_group_obtain (bd);
+ }
+ }
+
+ if (sc == RTEMS_SUCCESSFUL)
+ {
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_CACHED:
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_CACHED);
+ break;
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_4);
+ break;
+ }
+
+ if (rtems_bdbuf_tracer)
+ {
+ rtems_bdbuf_show_users ("read", bd);
+ rtems_bdbuf_show_usage ();
+ }
+
+ *bd_ptr = bd;
+ }
+ else
+ *bd_ptr = NULL;
+
+ rtems_bdbuf_unlock_cache ();
+ rtems_bdbuf_release_disk (dd);
+
+ return sc;
+}
+
+static rtems_status_code
+rtems_bdbuf_check_bd_and_lock_cache (rtems_bdbuf_buffer *bd, const char *kind)
+{
+ if (!bdbuf_cache.initialised)
+ return RTEMS_NOT_CONFIGURED;
+ if (bd == NULL)
+ return RTEMS_INVALID_ADDRESS;
+ if (rtems_bdbuf_tracer)
+ {
+ printf ("bdbuf:%s: %" PRIu32 "\n", kind, bd->block);
+ rtems_bdbuf_show_users (kind, bd);
+ }
+ rtems_bdbuf_lock_cache();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code
+rtems_bdbuf_release (rtems_bdbuf_buffer *bd)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_bdbuf_check_bd_and_lock_cache (bd, "release");
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ rtems_bdbuf_add_to_lru_list_after_access (bd);
+ break;
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ rtems_bdbuf_discard_buffer_after_access (bd);
+ break;
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ rtems_bdbuf_add_to_modified_list_after_access (bd);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_0);
+ break;
+ }
+
+ if (rtems_bdbuf_tracer)
+ rtems_bdbuf_show_usage ();
+
+ rtems_bdbuf_unlock_cache ();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code
+rtems_bdbuf_release_modified (rtems_bdbuf_buffer *bd)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_bdbuf_check_bd_and_lock_cache (bd, "release modified");
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ rtems_bdbuf_add_to_modified_list_after_access (bd);
+ break;
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ rtems_bdbuf_discard_buffer_after_access (bd);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_6);
+ break;
+ }
+
+ if (rtems_bdbuf_tracer)
+ rtems_bdbuf_show_usage ();
+
+ rtems_bdbuf_unlock_cache ();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code
+rtems_bdbuf_sync (rtems_bdbuf_buffer *bd)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_bdbuf_check_bd_and_lock_cache (bd, "sync");
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ switch (bd->state)
+ {
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ rtems_bdbuf_sync_after_access (bd);
+ break;
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ rtems_bdbuf_discard_buffer_after_access (bd);
+ break;
+ default:
+ rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_5);
+ break;
+ }
+
+ if (rtems_bdbuf_tracer)
+ rtems_bdbuf_show_usage ();
+
+ rtems_bdbuf_unlock_cache ();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code
+rtems_bdbuf_syncdev (dev_t dev)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *dd = NULL;
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:syncdev: %08x\n", (unsigned) dev);
+
+ sc = rtems_bdbuf_obtain_disk (dev, 0, &dd, NULL, NULL);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ /*
+ * Take the sync lock before locking the cache. Once we have the sync lock we
+ * can lock the cache. If another thread has the sync lock it will cause this
+ * thread to block until it owns the sync lock then it can own the cache. The
+ * sync lock can only be obtained with the cache unlocked.
+ */
+ rtems_bdbuf_lock_sync ();
+ rtems_bdbuf_lock_cache ();
+
+ /*
+ * Set the cache to have a sync active for a specific device and let the swap
+ * out task know the id of the requester to wake when done.
+ *
+ * The swap out task will negate the sync active flag when no more buffers
+ * for the device are held on the "modified for sync" queues.
+ */
+ bdbuf_cache.sync_active = true;
+ bdbuf_cache.sync_requester = rtems_task_self ();
+ bdbuf_cache.sync_device = dev;
+
+ rtems_bdbuf_wake_swapper ();
+ rtems_bdbuf_unlock_cache ();
+ rtems_bdbuf_wait_for_event (RTEMS_BDBUF_TRANSFER_SYNC);
+ rtems_bdbuf_unlock_sync ();
+ rtems_bdbuf_release_disk (dd);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static int
+rtems_bdbuf_null_disk_ioctl (rtems_disk_device *dd, uint32_t req, void *arg)
+{
+ return -1;
+}
+
+/**
+ * Swapout transfer to the driver. The driver will break this I/O into groups
+ * of consecutive write requests is multiple consecutive buffers are required
+ * by the driver. The cache is not locked.
+ *
+ * @param transfer The transfer transaction.
+ */
+static void
+rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
+{
+ rtems_chain_node *node;
+ static rtems_disk_device null_disk = {
+ .phys_dev = &null_disk,
+ .capabilities = 0,
+ .ioctl = rtems_bdbuf_null_disk_ioctl
+ };
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dev);
+
+ /*
+ * If there are buffers to transfer to the media transfer them.
+ */
+ if (!rtems_chain_is_empty (&transfer->bds))
+ {
+ /*
+ * The last block number used when the driver only supports
+ * continuous blocks in a single request.
+ */
+ uint32_t last_block = 0;
+
+ /*
+ * Number of buffers per bd. This is used to detect the next
+ * block.
+ */
+ uint32_t bufs_per_bd = 0;
+
+ /*
+ * Obtain the disk device. The cache's mutex has been released to avoid a
+ * dead lock.
+ */
+ rtems_disk_device *dd = rtems_disk_obtain (transfer->dev);
+
+ if (dd == NULL)
+ dd = &null_disk;
+
+ bufs_per_bd = dd->block_size / bdbuf_config.buffer_min;
+
+ /*
+ * Take as many buffers as configured and pass to the driver. Note, the
+ * API to the drivers has an array of buffers and if a chain was passed
+ * we could have just passed the list. If the driver API is updated it
+ * should be possible to make this change with little effect in this
+ * code. The array that is passed is broken in design and should be
+ * removed. Merging members of a struct into the first member is
+ * trouble waiting to happen.
+ */
+ transfer->write_req->status = RTEMS_RESOURCE_IN_USE;
+ transfer->write_req->bufnum = 0;
+
+ while ((node = rtems_chain_get(&transfer->bds)) != NULL)
+ {
+ rtems_bdbuf_buffer* bd = (rtems_bdbuf_buffer*) node;
+ bool write = false;
+
+ /*
+ * If the device only accepts sequential buffers and this is not the
+ * first buffer (the first is always sequential, and the buffer is not
+ * sequential then put the buffer back on the transfer chain and write
+ * the committed buffers.
+ */
+
+ if (rtems_bdbuf_tracer)
+ printf ("bdbuf:swapout write: bd:%" PRIu32 ", bufnum:%" PRIu32 " mode:%s\n",
+ bd->block, transfer->write_req->bufnum,
+ dd->phys_dev->capabilities &
+ RTEMS_BLKDEV_CAP_MULTISECTOR_CONT ? "MULIT" : "SCAT");
+
+ if ((dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_MULTISECTOR_CONT) &&
+ transfer->write_req->bufnum &&
+ (bd->block != (last_block + bufs_per_bd)))
+ {
+ rtems_chain_prepend (&transfer->bds, &bd->link);
+ write = true;
+ }
+ else
+ {
+ rtems_blkdev_sg_buffer* buf;
+ buf = &transfer->write_req->bufs[transfer->write_req->bufnum];
+ transfer->write_req->bufnum++;
+ buf->user = bd;
+ buf->block = bd->block;
+ buf->length = dd->block_size;
+ buf->buffer = bd->buffer;
+ last_block = bd->block;
+ }
+
+ /*
+ * Perform the transfer if there are no more buffers, or the transfer
+ * size has reached the configured max. value.
+ */
+
+ if (rtems_chain_is_empty (&transfer->bds) ||
+ (transfer->write_req->bufnum >= bdbuf_config.max_write_blocks))
+ write = true;
+
+ if (write)
+ {
+ rtems_bdbuf_execute_transfer_request (dd, transfer->write_req, false);
+
+ transfer->write_req->status = RTEMS_RESOURCE_IN_USE;
+ transfer->write_req->bufnum = 0;
+ }
+ }
+
+ if (dd != &null_disk)
+ {
+ /*
+ * If sync'ing and the deivce is capability of handling a sync IO control
+ * call perform the call.
+ */
+ if (transfer->syncing &&
+ (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
+ {
+ /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
+ /* How should the error be handled ? */
+ }
+
+ rtems_disk_release (dd);
+ }
+ }
+}
+
+/**
+ * Process the modified list of buffers. There is a sync or modified list that
+ * needs to be handled so we have a common function to do the work.
+ *
+ * @param dev The device to handle. If BDBUF_INVALID_DEV no device is selected
+ * so select the device of the first buffer to be written to disk.
+ * @param chain The modified chain to process.
+ * @param transfer The chain to append buffers to be written too.
+ * @param sync_active If true this is a sync operation so expire all timers.
+ * @param update_timers If true update the timers.
+ * @param timer_delta It update_timers is true update the timers by this
+ * amount.
+ */
+static void
+rtems_bdbuf_swapout_modified_processing (dev_t* dev,
+ rtems_chain_control* chain,
+ rtems_chain_control* transfer,
+ bool sync_active,
+ bool update_timers,
+ uint32_t timer_delta)
+{
+ if (!rtems_chain_is_empty (chain))
+ {
+ rtems_chain_node* node = rtems_chain_head (chain);
+ bool sync_all;
+
+ node = node->next;
+
+ /*
+ * A sync active with no valid dev means sync all.
+ */
+ if (sync_active && (*dev == BDBUF_INVALID_DEV))
+ sync_all = true;
+ else
+ sync_all = false;
+
+ while (!rtems_chain_is_tail (chain, node))
+ {
+ rtems_bdbuf_buffer* bd = (rtems_bdbuf_buffer*) node;
+
+ /*
+ * Check if the buffer's hold timer has reached 0. If a sync is active
+ * or someone waits for a buffer written force all the timers to 0.
+ *
+ * @note Lots of sync requests will skew this timer. It should be based
+ * on TOD to be accurate. Does it matter ?
+ */
+ if (sync_all || (sync_active && (*dev == bd->dev))
+ || rtems_bdbuf_has_buffer_waiters ())
+ bd->hold_timer = 0;
+
+ if (bd->hold_timer)
+ {
+ if (update_timers)
+ {
+ if (bd->hold_timer > timer_delta)
+ bd->hold_timer -= timer_delta;
+ else
+ bd->hold_timer = 0;
+ }
+
+ if (bd->hold_timer)
+ {
+ node = node->next;
+ continue;
+ }
+ }
+
+ /*
+ * This assumes we can set dev_t to BDBUF_INVALID_DEV which is just an
+ * assumption. Cannot use the transfer list being empty the sync dev
+ * calls sets the dev to use.
+ */
+ if (*dev == BDBUF_INVALID_DEV)
+ *dev = bd->dev;
+
+ if (bd->dev == *dev)
+ {
+ rtems_chain_node* next_node = node->next;
+ rtems_chain_node* tnode = rtems_chain_tail (transfer);
+
+ /*
+ * The blocks on the transfer list are sorted in block order. This
+ * means multi-block transfers for drivers that require consecutive
+ * blocks perform better with sorted blocks and for real disks it may
+ * help lower head movement.
+ */
+
+ rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_TRANSFER);
+
+ rtems_chain_extract (node);
+
+ tnode = tnode->previous;
+
+ while (node && !rtems_chain_is_head (transfer, tnode))
+ {
+ rtems_bdbuf_buffer* tbd = (rtems_bdbuf_buffer*) tnode;
+
+ if (bd->block > tbd->block)
+ {
+ rtems_chain_insert (tnode, node);
+ node = NULL;
+ }
+ else
+ tnode = tnode->previous;
+ }
+
+ if (node)
+ rtems_chain_prepend (transfer, node);
+
+ node = next_node;
+ }
+ else
+ {
+ node = node->next;
+ }
+ }
+ }
+}
+
+/**
+ * Process the cache's modified buffers. Check the sync list first then the
+ * modified list extracting the buffers suitable to be written to disk. We have
+ * a device at a time. The task level loop will repeat this operation while
+ * there are buffers to be written. If the transfer fails place the buffers
+ * back on the modified list and try again later. The cache is unlocked while
+ * the buffers are being written to disk.
+ *
+ * @param timer_delta It update_timers is true update the timers by this
+ * amount.
+ * @param update_timers If true update the timers.
+ * @param transfer The transfer transaction data.
+ *
+ * @retval true Buffers where written to disk so scan again.
+ * @retval false No buffers where written to disk.
+ */
+static bool
+rtems_bdbuf_swapout_processing (unsigned long timer_delta,
+ bool update_timers,
+ rtems_bdbuf_swapout_transfer* transfer)
+{
+ rtems_bdbuf_swapout_worker* worker;
+ bool transfered_buffers = false;
+
+ rtems_bdbuf_lock_cache ();
+
+ /*
+ * If a sync is active do not use a worker because the current code does not
+ * cleaning up after. We need to know the buffers have been written when
+ * syncing to release sync lock and currently worker threads do not return to
+ * here. We do not know the worker is the last in a sequence of sync writes
+ * until after we have it running so we do not know to tell it to release the
+ * lock. The simplest solution is to get the main swap out task perform all
+ * sync operations.
+ */
+ if (bdbuf_cache.sync_active)
+ worker = NULL;
+ else
+ {
+ worker = (rtems_bdbuf_swapout_worker*)
+ rtems_chain_get (&bdbuf_cache.swapout_workers);
+ if (worker)
+ transfer = &worker->transfer;
+ }
+
+ rtems_chain_initialize_empty (&transfer->bds);
+ transfer->dev = BDBUF_INVALID_DEV;
+ transfer->syncing = bdbuf_cache.sync_active;
+
+ /*
+ * When the sync is for a device limit the sync to that device. If the sync
+ * is for a buffer handle process the devices in the order on the sync
+ * list. This means the dev is BDBUF_INVALID_DEV.
+ */
+ if (bdbuf_cache.sync_active)
+ transfer->dev = bdbuf_cache.sync_device;
+
+ /*
+ * If we have any buffers in the sync queue move them to the modified
+ * list. The first sync buffer will select the device we use.
+ */
+ rtems_bdbuf_swapout_modified_processing (&transfer->dev,
+ &bdbuf_cache.sync,
+ &transfer->bds,
+ true, false,
+ timer_delta);
+
+ /*
+ * Process the cache's modified list.
+ */
+ rtems_bdbuf_swapout_modified_processing (&transfer->dev,
+ &bdbuf_cache.modified,
+ &transfer->bds,
+ bdbuf_cache.sync_active,
+ update_timers,
+ timer_delta);
+
+ /*
+ * We have all the buffers that have been modified for this device so the
+ * cache can be unlocked because the state of each buffer has been set to
+ * TRANSFER.
+ */
+ rtems_bdbuf_unlock_cache ();
+
+ /*
+ * If there are buffers to transfer to the media transfer them.
+ */
+ if (!rtems_chain_is_empty (&transfer->bds))
+ {
+ if (worker)
+ {
+ rtems_status_code sc = rtems_event_send (worker->id,
+ RTEMS_BDBUF_SWAPOUT_SYNC);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE);
+ }
+ else
+ {
+ rtems_bdbuf_swapout_write (transfer);
+ }
+
+ transfered_buffers = true;
+ }
+
+ if (bdbuf_cache.sync_active && !transfered_buffers)
+ {
+ rtems_id sync_requester;
+ rtems_bdbuf_lock_cache ();
+ sync_requester = bdbuf_cache.sync_requester;
+ bdbuf_cache.sync_active = false;
+ bdbuf_cache.sync_requester = 0;
+ rtems_bdbuf_unlock_cache ();
+ if (sync_requester)
+ rtems_event_send (sync_requester, RTEMS_BDBUF_TRANSFER_SYNC);
+ }
+
+ return transfered_buffers;
+}
+
+/**
+ * Allocate the write request and initialise it for good measure.
+ *
+ * @return rtems_blkdev_request* The write reference memory.
+ */
+static rtems_blkdev_request*
+rtems_bdbuf_swapout_writereq_alloc (void)
+{
+ /*
+ * @note chrisj The rtems_blkdev_request and the array at the end is a hack.
+ * I am disappointment at finding code like this in RTEMS. The request should
+ * have been a rtems_chain_control. Simple, fast and less storage as the node
+ * is already part of the buffer structure.
+ */
+ rtems_blkdev_request* write_req =
+ malloc (sizeof (rtems_blkdev_request) +
+ (bdbuf_config.max_write_blocks * sizeof (rtems_blkdev_sg_buffer)));
+
+ if (!write_req)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM);
+
+ write_req->req = RTEMS_BLKDEV_REQ_WRITE;
+ write_req->req_done = rtems_bdbuf_transfer_done;
+ write_req->done_arg = write_req;
+ write_req->io_task = rtems_task_self ();
+
+ return write_req;
+}
+
+/**
+ * The swapout worker thread body.
+ *
+ * @param arg A pointer to the worker thread's private data.
+ * @return rtems_task Not used.
+ */
+static rtems_task
+rtems_bdbuf_swapout_worker_task (rtems_task_argument arg)
+{
+ rtems_bdbuf_swapout_worker* worker = (rtems_bdbuf_swapout_worker*) arg;
+
+ while (worker->enabled)
+ {
+ rtems_bdbuf_wait_for_event (RTEMS_BDBUF_SWAPOUT_SYNC);
+
+ rtems_bdbuf_swapout_write (&worker->transfer);
+
+ rtems_bdbuf_lock_cache ();
+
+ rtems_chain_initialize_empty (&worker->transfer.bds);
+ worker->transfer.dev = BDBUF_INVALID_DEV;
+
+ rtems_chain_append (&bdbuf_cache.swapout_workers, &worker->link);
+
+ rtems_bdbuf_unlock_cache ();
+ }
+
+ free (worker->transfer.write_req);
+ free (worker);
+
+ rtems_task_delete (RTEMS_SELF);
+}
+
+/**
+ * Open the swapout worker threads.
+ */
+static void
+rtems_bdbuf_swapout_workers_open (void)
+{
+ rtems_status_code sc;
+ size_t w;
+
+ rtems_bdbuf_lock_cache ();
+
+ for (w = 0; w < bdbuf_config.swapout_workers; w++)
+ {
+ rtems_bdbuf_swapout_worker* worker;
+
+ worker = malloc (sizeof (rtems_bdbuf_swapout_worker));
+ if (!worker)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM);
+
+ rtems_chain_append (&bdbuf_cache.swapout_workers, &worker->link);
+ worker->enabled = true;
+ worker->transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
+
+ rtems_chain_initialize_empty (&worker->transfer.bds);
+ worker->transfer.dev = BDBUF_INVALID_DEV;
+
+ sc = rtems_task_create (rtems_build_name('B', 'D', 'o', 'a' + w),
+ (bdbuf_config.swapout_priority ?
+ bdbuf_config.swapout_priority :
+ RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT),
+ SWAPOUT_TASK_STACK_SIZE,
+ RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
+ RTEMS_LOCAL | RTEMS_NO_FLOATING_POINT,
+ &worker->id);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE);
+
+ sc = rtems_task_start (worker->id,
+ rtems_bdbuf_swapout_worker_task,
+ (rtems_task_argument) worker);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START);
+ }
+
+ rtems_bdbuf_unlock_cache ();
+}
+
+/**
+ * Close the swapout worker threads.
+ */
+static void
+rtems_bdbuf_swapout_workers_close (void)
+{
+ rtems_chain_node* node;
+
+ rtems_bdbuf_lock_cache ();
+
+ node = rtems_chain_first (&bdbuf_cache.swapout_workers);
+ while (!rtems_chain_is_tail (&bdbuf_cache.swapout_workers, node))
+ {
+ rtems_bdbuf_swapout_worker* worker = (rtems_bdbuf_swapout_worker*) node;
+ worker->enabled = false;
+ rtems_event_send (worker->id, RTEMS_BDBUF_SWAPOUT_SYNC);
+ node = rtems_chain_next (node);
+ }
+
+ rtems_bdbuf_unlock_cache ();
+}
+
+/**
+ * Body of task which takes care on flushing modified buffers to the disk.
+ *
+ * @param arg A pointer to the global cache data. Use the global variable and
+ * not this.
+ * @return rtems_task Not used.
+ */
+static rtems_task
+rtems_bdbuf_swapout_task (rtems_task_argument arg)
+{
+ rtems_bdbuf_swapout_transfer transfer;
+ uint32_t period_in_ticks;
+ const uint32_t period_in_msecs = bdbuf_config.swapout_period;;
+ uint32_t timer_delta;
+
+ transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
+ rtems_chain_initialize_empty (&transfer.bds);
+ transfer.dev = BDBUF_INVALID_DEV;
+ transfer.syncing = false;
+
+ /*
+ * Localise the period.
+ */
+ period_in_ticks = RTEMS_MICROSECONDS_TO_TICKS (period_in_msecs * 1000);
+
+ /*
+ * This is temporary. Needs to be changed to use the real time clock.
+ */
+ timer_delta = period_in_msecs;
+
+ /*
+ * Create the worker threads.
+ */
+ rtems_bdbuf_swapout_workers_open ();
+
+ while (bdbuf_cache.swapout_enabled)
+ {
+ rtems_event_set out;
+ rtems_status_code sc;
+
+ /*
+ * Only update the timers once in the processing cycle.
+ */
+ bool update_timers = true;
+
+ /*
+ * If we write buffers to any disk perform a check again. We only write a
+ * single device at a time and the cache may have more than one device's
+ * buffers modified waiting to be written.
+ */
+ bool transfered_buffers;
+
+ do
+ {
+ transfered_buffers = false;
+
+ /*
+ * Extact all the buffers we find for a specific device. The device is
+ * the first one we find on a modified list. Process the sync queue of
+ * buffers first.
+ */
+ if (rtems_bdbuf_swapout_processing (timer_delta,
+ update_timers,
+ &transfer))
+ {
+ transfered_buffers = true;
+ }
+
+ /*
+ * Only update the timers once.
+ */
+ update_timers = false;
+ }
+ while (transfered_buffers);
+
+ sc = rtems_event_receive (RTEMS_BDBUF_SWAPOUT_SYNC,
+ RTEMS_EVENT_ALL | RTEMS_WAIT,
+ period_in_ticks,
+ &out);
+
+ if ((sc != RTEMS_SUCCESSFUL) && (sc != RTEMS_TIMEOUT))
+ rtems_fatal_error_occurred (BLKDEV_FATAL_BDBUF_SWAPOUT_RE);
+ }
+
+ rtems_bdbuf_swapout_workers_close ();
+
+ free (transfer.write_req);
+
+ rtems_task_delete (RTEMS_SELF);
+}
+
+static void
+rtems_bdbuf_purge_list (rtems_chain_control *purge_list)
+{
+ bool wake_buffer_waiters = false;
+ rtems_chain_node *node = NULL;
+
+ while ((node = rtems_chain_get (purge_list)) != NULL)
+ {
+ rtems_bdbuf_buffer *bd = (rtems_bdbuf_buffer *) node;
+
+ if (bd->waiters == 0)
+ wake_buffer_waiters = true;
+
+ rtems_bdbuf_discard_buffer (bd);
+ }
+
+ if (wake_buffer_waiters)
+ rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
+}
+
+typedef bool (*rtems_bdbuf_purge_compare)(dev_t a, dev_t b);
+
+static void
+rtems_bdbuf_gather_for_purge (rtems_chain_control *purge_list,
+ rtems_bdbuf_purge_compare compare,
+ dev_t dev)
+{
+ rtems_bdbuf_buffer *stack [RTEMS_BDBUF_AVL_MAX_HEIGHT];
+ rtems_bdbuf_buffer **prev = stack;
+ rtems_bdbuf_buffer *cur = bdbuf_cache.tree;
+
+ *prev = NULL;
+
+ while (cur != NULL)
+ {
+ if ((*compare) (cur->dev, dev))
+ {
+ switch (cur->state)
+ {
+ case RTEMS_BDBUF_STATE_FREE:
+ case RTEMS_BDBUF_STATE_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_PURGED:
+ case RTEMS_BDBUF_STATE_TRANSFER_PURGED:
+ break;
+ case RTEMS_BDBUF_STATE_SYNC:
+ rtems_bdbuf_wake (&bdbuf_cache.transfer_waiters);
+ /* Fall through */
+ case RTEMS_BDBUF_STATE_MODIFIED:
+ rtems_bdbuf_group_release (cur);
+ /* Fall through */
+ case RTEMS_BDBUF_STATE_CACHED:
+ rtems_chain_extract (&cur->link);
+ rtems_chain_append (purge_list, &cur->link);
+ break;
+ case RTEMS_BDBUF_STATE_TRANSFER:
+ rtems_bdbuf_set_state (cur, RTEMS_BDBUF_STATE_TRANSFER_PURGED);
+ break;
+ case RTEMS_BDBUF_STATE_ACCESS_CACHED:
+ case RTEMS_BDBUF_STATE_ACCESS_EMPTY:
+ case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
+ rtems_bdbuf_set_state (cur, RTEMS_BDBUF_STATE_ACCESS_PURGED);
+ break;
+ default:
+ rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_STATE_11);
+ }
+ }
+
+ if (cur->avl.left != NULL)
+ {
+ /* Left */
+ ++prev;
+ *prev = cur;
+ cur = cur->avl.left;
+ }
+ else if (cur->avl.right != NULL)
+ {
+ /* Right */
+ ++prev;
+ *prev = cur;
+ cur = cur->avl.right;
+ }
+ else
+ {
+ while (*prev != NULL && cur == (*prev)->avl.right)
+ {
+ /* Up */
+ cur = *prev;
+ --prev;
+ }
+ if (*prev != NULL)
+ /* Right */
+ cur = (*prev)->avl.right;
+ else
+ /* Finished */
+ cur = NULL;
+ }
+ }
+}
+
+static void
+rtems_bdbuf_purge (rtems_bdbuf_purge_compare compare, dev_t dev)
+{
+ rtems_chain_control purge_list;
+
+ rtems_chain_initialize_empty (&purge_list);
+ rtems_bdbuf_lock_cache ();
+ rtems_bdbuf_gather_for_purge (&purge_list, compare, dev);
+ rtems_bdbuf_purge_list (&purge_list);
+ rtems_bdbuf_unlock_cache ();
+}
+
+static bool
+rtems_bdbuf_purge_compare_dev (dev_t a, dev_t b)
+{
+ return a == b;
+}
+
+void
+rtems_bdbuf_purge_dev (dev_t dev)
+{
+ rtems_bdbuf_purge (rtems_bdbuf_purge_compare_dev, dev);
+}
+
+static bool
+rtems_bdbuf_purge_compare_major (dev_t a, dev_t b)
+{
+ return rtems_filesystem_dev_major_t (a) == rtems_filesystem_dev_major_t (b);
+}
+
+void
+rtems_bdbuf_purge_major (rtems_device_major_number major)
+{
+ dev_t dev = rtems_filesystem_make_dev_t (major, 0);
+
+ rtems_bdbuf_purge (rtems_bdbuf_purge_compare_major, dev);
+}
diff --git a/cpukit/libblock/src/bdpart-create.c b/cpukit/libblock/src/bdpart-create.c
new file mode 100644
index 0000000000..dc93522c19
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-create.c
@@ -0,0 +1,160 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+rtems_status_code rtems_bdpart_create(
+ const char *disk_name,
+ const rtems_bdpart_format *format,
+ rtems_bdpart_partition *pt,
+ const unsigned *dist,
+ size_t count
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ bool dos_compatibility = format != NULL
+ && format->type == RTEMS_BDPART_FORMAT_MBR
+ && format->mbr.dos_compatibility;
+ rtems_blkdev_bnum disk_end = 0;
+ rtems_blkdev_bnum pos = 0;
+ rtems_blkdev_bnum dist_sum = 0;
+ rtems_blkdev_bnum record_space =
+ dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
+ rtems_blkdev_bnum overhead = 0;
+ rtems_blkdev_bnum free_space = 0;
+ dev_t disk = 0;
+ size_t i = 0;
+
+ /* Check if we have something to do */
+ if (count == 0) {
+ /* Nothing to do */
+ return RTEMS_SUCCESSFUL;
+ }
+
+ /* Check parameter */
+ if (format == NULL || pt == NULL || dist == NULL) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ /* Get disk data */
+ sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Get distribution sum and check for overflow */
+ for (i = 0; i < count; ++i) {
+ unsigned prev_sum = dist_sum;
+
+ dist_sum += dist [i];
+
+ if (dist_sum < prev_sum) {
+ return RTEMS_INVALID_NUMBER;
+ }
+
+ if (dist [i] == 0) {
+ return RTEMS_INVALID_NUMBER;
+ }
+ }
+
+ /* Check format */
+ if (format->type != RTEMS_BDPART_FORMAT_MBR) {
+ return RTEMS_NOT_IMPLEMENTED;
+ }
+
+ /* Align end of disk on cylinder boundary if necessary */
+ if (dos_compatibility) {
+ disk_end -= (disk_end % record_space);
+ }
+
+ /*
+ * We need at least space for the MBR and the compatibility space for the
+ * first primary partition.
+ */
+ overhead += record_space;
+
+ /*
+ * In case we need an extended partition and logical partitions we have to
+ * account for the space of each EBR.
+ */
+ if (count > 4) {
+ overhead += (count - 3) * record_space;
+ }
+
+ /*
+ * Account space to align every partition on cylinder boundaries if
+ * necessary.
+ */
+ if (dos_compatibility) {
+ overhead += (count - 1) * record_space;
+ }
+
+ /* Check disk space */
+ if ((overhead + count) > disk_end) {
+ return RTEMS_IO_ERROR;
+ }
+
+ /* Begin of first primary partition */
+ pos = record_space;
+
+ /* Space for partitions */
+ free_space = disk_end - overhead;
+
+ for (i = 0; i < count; ++i) {
+ rtems_bdpart_partition *p = pt + i;
+
+ /* Partition size */
+ rtems_blkdev_bnum s = free_space * dist [i];
+ if (s < free_space || s < dist [i]) {
+ /* TODO: Calculate without overflow */
+ return RTEMS_INVALID_NUMBER;
+ }
+ s /= dist_sum;
+
+ /* Ensure that the partition is not empty */
+ if (s == 0) {
+ s = 1;
+ }
+
+ /* Align partition upwards */
+ s += record_space - (s % record_space);
+
+ /* Partition begin and end */
+ p->begin = pos;
+ pos += s;
+ p->end = pos;
+
+ /* Reserve space for the EBR if necessary */
+ if (count > 4 && i > 2) {
+ p->begin += record_space;
+ }
+ }
+
+ /* Expand the last partition to the disk end */
+ pt [count - 1].end = disk_end;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/bdpart-dump.c b/cpukit/libblock/src/bdpart-dump.c
new file mode 100644
index 0000000000..abd85b6037
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-dump.c
@@ -0,0 +1,97 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+static void rtems_bdpart_type_to_string(
+ const uuid_t type,
+ char str [37]
+)
+{
+ uuid_unparse_lower( type, str);
+}
+
+void rtems_bdpart_dump( const rtems_bdpart_partition *pt, size_t count)
+{
+ size_t i = 0;
+
+ printf(
+ "-------------------------------------------------------------------------------\n"
+ " PARTITION TABLE\n"
+ "------------+------------+-----------------------------------------------------\n"
+ " BEGIN | END | TYPE\n"
+ "------------+------------+-----------------------------------------------------\n"
+ );
+
+ for (i = 0; i < count; ++i) {
+ const rtems_bdpart_partition *p = pt + i;
+ const char *type = NULL;
+ char type_buffer [52];
+ uint8_t type_mbr = 0;
+
+ if (rtems_bdpart_to_mbr_partition_type( p->type, &type_mbr)) {
+ switch (type_mbr) {
+ case RTEMS_BDPART_MBR_FAT_12:
+ type = "FAT 12";
+ break;
+ case RTEMS_BDPART_MBR_FAT_16:
+ type = "FAT 16";
+ break;
+ case RTEMS_BDPART_MBR_FAT_16_LBA:
+ type = "FAT 16 LBA";
+ break;
+ case RTEMS_BDPART_MBR_FAT_32:
+ type = "FAT 32";
+ break;
+ case RTEMS_BDPART_MBR_FAT_32_LBA:
+ type = "FAT 32 LBA";
+ break;
+ case RTEMS_BDPART_MBR_DATA:
+ type = "DATA";
+ break;
+ default:
+ snprintf( type_buffer, sizeof( type_buffer), "0x%02" PRIx8, type_mbr);
+ type = type_buffer;
+ break;
+ }
+ } else {
+ rtems_bdpart_type_to_string( p->type, type_buffer);
+ type = type_buffer;
+ }
+
+ printf(
+ " %10" PRIu32 " | %10" PRIu32 " |%52s\n",
+ p->begin,
+ p->end,
+ type
+ );
+ }
+
+ puts( "------------+------------+-----------------------------------------------------");
+}
diff --git a/cpukit/libblock/src/bdpart-mount.c b/cpukit/libblock/src/bdpart-mount.c
new file mode 100644
index 0000000000..aef15dfbaa
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-mount.c
@@ -0,0 +1,184 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+#include <rtems/libio.h>
+
+rtems_status_code rtems_bdpart_mount(
+ const char *disk_name,
+ const rtems_bdpart_partition *pt __attribute__((unused)),
+ size_t count,
+ const char *mount_base
+)
+{
+ rtems_status_code esc = RTEMS_SUCCESSFUL;
+ const char *disk_file_name = strrchr( disk_name, '/');
+ char *logical_disk_name = NULL;
+ char *logical_disk_marker = NULL;
+ char *mount_point = NULL;
+ char *mount_marker = NULL;
+ size_t disk_file_name_size = 0;
+ size_t disk_name_size = strlen( disk_name);
+ size_t mount_base_size = strlen( mount_base);
+ size_t i = 0;
+
+ /* Create logical disk name base */
+ logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
+ if (logical_disk_name == NULL) {
+ return RTEMS_NO_MEMORY;
+ }
+ strncpy( logical_disk_name, disk_name, disk_name_size);
+
+ /* Get disk file name */
+ if (disk_file_name != NULL) {
+ disk_file_name += 1;
+ disk_file_name_size = strlen( disk_file_name);
+ } else {
+ disk_file_name = disk_name;
+ disk_file_name_size = disk_name_size;
+ }
+
+ /* Create mount point base */
+ mount_point = malloc( mount_base_size + 1 + disk_file_name_size + RTEMS_BDPART_NUMBER_SIZE);
+ if (mount_point == NULL) {
+ esc = RTEMS_NO_MEMORY;
+ goto cleanup;
+ }
+ strncpy( mount_point, mount_base, mount_base_size);
+ mount_point [mount_base_size] = '/';
+ strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
+
+ /* Markers */
+ logical_disk_marker = logical_disk_name + disk_name_size;
+ mount_marker = mount_point + mount_base_size + 1 + disk_file_name_size;
+
+ /* Mount supported file systems for each partition */
+ for (i = 0; i < count; ++i) {
+ /* Create logical disk name */
+ int rv = snprintf( logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
+ if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
+ esc = RTEMS_INVALID_NAME;
+ goto cleanup;
+ }
+
+ /* Create mount point */
+ strncpy( mount_marker, logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE);
+ rv = rtems_mkdir( mount_point, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (rv != 0) {
+ esc = RTEMS_IO_ERROR;
+ goto cleanup;
+ }
+
+ /* Mount */
+ rv = mount(
+ logical_disk_name,
+ mount_point,
+ "msdos",
+ 0,
+ NULL
+ );
+ if (rv != 0) {
+ rmdir( mount_point);
+ }
+ }
+
+cleanup:
+
+ free( logical_disk_name);
+ free( mount_point);
+
+ return esc;
+}
+
+rtems_status_code rtems_bdpart_unmount(
+ const char *disk_name,
+ const rtems_bdpart_partition *pt __attribute__((unused)),
+ size_t count,
+ const char *mount_base
+)
+{
+ rtems_status_code esc = RTEMS_SUCCESSFUL;
+ const char *disk_file_name = strrchr( disk_name, '/');
+ char *mount_point = NULL;
+ char *mount_marker = NULL;
+ size_t disk_file_name_size = 0;
+ size_t disk_name_size = strlen( disk_name);
+ size_t mount_base_size = strlen( mount_base);
+ size_t i = 0;
+
+ /* Get disk file name */
+ if (disk_file_name != NULL) {
+ disk_file_name += 1;
+ disk_file_name_size = strlen( disk_file_name);
+ } else {
+ disk_file_name = disk_name;
+ disk_file_name_size = disk_name_size;
+ }
+
+ /* Create mount point base */
+ mount_point = malloc( mount_base_size + 1 + disk_file_name_size + RTEMS_BDPART_NUMBER_SIZE);
+ if (mount_point == NULL) {
+ esc = RTEMS_NO_MEMORY;
+ goto cleanup;
+ }
+ strncpy( mount_point, mount_base, mount_base_size);
+ mount_point [mount_base_size] = '/';
+ strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
+
+ /* Marker */
+ mount_marker = mount_point + mount_base_size + 1 + disk_file_name_size;
+
+ /* Mount supported file systems for each partition */
+ for (i = 0; i < count; ++i) {
+ /* Create mount point */
+ int rv = snprintf( mount_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
+ if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
+ esc = RTEMS_INVALID_NAME;
+ goto cleanup;
+ }
+
+ /* Unmount */
+ rv = unmount( mount_point);
+ if (rv == 0) {
+ /* Remove mount point */
+ rv = rmdir( mount_point);
+ if (rv != 0) {
+ esc = RTEMS_IO_ERROR;
+ goto cleanup;
+ }
+ }
+ }
+
+cleanup:
+
+ free( mount_point);
+
+ return esc;
+}
diff --git a/cpukit/libblock/src/bdpart-read.c b/cpukit/libblock/src/bdpart-read.c
new file mode 100644
index 0000000000..3560dbd3a3
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-read.c
@@ -0,0 +1,348 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/bdbuf.h>
+#include <rtems/bdpart.h>
+#include <rtems/endian.h>
+
+#define RTEMS_BDPART_MBR_PARTITION_TYPE( type) \
+ { \
+ (type), 0xa2U, 0x2eU, 0x38U, \
+ 0x38U, 0xb5U, 0xdeU, 0x11U, \
+ 0xbcU, 0x13U, 0x00U, 0x1dU, \
+ 0x09U, 0xb0U, 0x5fU, 0xa4U \
+ }
+
+static const uuid_t RTEMS_BDPART_MBR_MASTER_TYPE =
+ RTEMS_BDPART_MBR_PARTITION_TYPE( RTEMS_BDPART_MBR_EMPTY);
+
+void rtems_bdpart_to_partition_type( uint8_t mbr_type, uuid_t type)
+{
+ type [0] = mbr_type;
+ memcpy( type + 1, RTEMS_BDPART_MBR_MASTER_TYPE + 1, sizeof( uuid_t) - 1);
+}
+
+bool rtems_bdpart_to_mbr_partition_type(
+ const uuid_t type,
+ uint8_t *mbr_type
+)
+{
+ *mbr_type = rtems_bdpart_mbr_partition_type( type);
+
+ return memcmp(
+ type + 1,
+ RTEMS_BDPART_MBR_MASTER_TYPE + 1,
+ sizeof( uuid_t) - 1
+ ) == 0;
+}
+
+/*
+ * FIXME: This code should the deviceio interface and not the bdbug interface.
+ */
+rtems_status_code rtems_bdpart_get_disk_data(
+ const char *disk_name,
+ dev_t *disk,
+ rtems_blkdev_bnum *disk_end
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int rv = 0;
+ rtems_blkdev_bnum disk_begin = 0;
+ rtems_blkdev_bnum block_size = 0;
+ rtems_disk_device *dd = NULL;
+ struct stat st;
+
+ /* Get disk handle */
+ rv = stat( disk_name, &st);
+ if (rv != 0) {
+ return RTEMS_INVALID_NAME;
+ }
+ *disk = st.st_rdev;
+
+ /* Get disk begin, end and block size */
+ dd = rtems_disk_obtain( *disk);
+ if (dd == NULL) {
+ return RTEMS_INVALID_NAME;
+ }
+ disk_begin = dd->start;
+ *disk_end = dd->size;
+ block_size = dd->block_size;
+ sc = rtems_disk_release( dd);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Check block size */
+ if (block_size < RTEMS_BDPART_BLOCK_SIZE) {
+ return RTEMS_IO_ERROR;
+ }
+
+ /* Check that we have do not have a logical disk */
+ if (disk_begin != 0) {
+ return RTEMS_IO_ERROR;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static bool rtems_bdpart_is_valid_record( const uint8_t *data)
+{
+ return data [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_0]
+ == RTEMS_BDPART_MBR_SIGNATURE_0
+ && data [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_1]
+ == RTEMS_BDPART_MBR_SIGNATURE_1;
+}
+
+static rtems_blkdev_bnum rtems_bdpart_next_ebr( const uint8_t *data)
+{
+ rtems_blkdev_bnum begin =
+ rtems_uint32_from_little_endian( data + RTEMS_BDPART_MBR_OFFSET_BEGIN);
+ uint8_t type = data [RTEMS_BDPART_MBR_OFFSET_TYPE];
+
+ if (type == RTEMS_BDPART_MBR_EXTENDED) {
+ return begin;
+ } else {
+ return 0;
+ }
+}
+
+static rtems_status_code rtems_bdpart_read_mbr_partition(
+ const uint8_t *data,
+ rtems_bdpart_partition **p,
+ const rtems_bdpart_partition *p_end,
+ rtems_blkdev_bnum *ep_begin
+)
+{
+ rtems_blkdev_bnum begin =
+ rtems_uint32_from_little_endian( data + RTEMS_BDPART_MBR_OFFSET_BEGIN);
+ rtems_blkdev_bnum size =
+ rtems_uint32_from_little_endian( data + RTEMS_BDPART_MBR_OFFSET_SIZE);
+ rtems_blkdev_bnum end = begin + size;
+ uint8_t type = data [RTEMS_BDPART_MBR_OFFSET_TYPE];
+
+ if (type == RTEMS_BDPART_MBR_EMPTY) {
+ return RTEMS_SUCCESSFUL;
+ } else if (*p == p_end) {
+ return RTEMS_TOO_MANY;
+ } else if (begin >= end) {
+ return RTEMS_IO_ERROR;
+ } else if (type == RTEMS_BDPART_MBR_EXTENDED) {
+ if (ep_begin != NULL) {
+ *ep_begin = begin;
+ }
+ } else {
+ /* Increment partition index */
+ ++(*p);
+
+ /* Clear partition */
+ memset( *p, 0, sizeof( rtems_bdpart_partition));
+
+ /* Set values */
+ (*p)->begin = begin;
+ (*p)->end = end;
+ rtems_bdpart_to_partition_type( type, (*p)->type);
+ (*p)->flags = data [RTEMS_BDPART_MBR_OFFSET_FLAGS];
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static rtems_status_code rtems_bdpart_read_record(
+ dev_t disk,
+ rtems_blkdev_bnum index,
+ rtems_bdbuf_buffer **block
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ /* Release previous block if necessary */
+ if (*block != NULL) {
+ sc = rtems_bdbuf_release( *block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+ }
+
+ /* Read the record block */
+ sc = rtems_bdbuf_read( disk, index, block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* just in case block did not get filled in */
+ if ( *block == NULL ) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ /* Check MBR signature */
+ if (!rtems_bdpart_is_valid_record( (*block)->buffer)) {
+ return RTEMS_IO_ERROR;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_bdpart_read(
+ const char *disk_name,
+ rtems_bdpart_format *format,
+ rtems_bdpart_partition *pt,
+ size_t *count
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code esc = RTEMS_SUCCESSFUL;
+ rtems_bdbuf_buffer *block = NULL;
+ rtems_bdpart_partition *p = pt - 1;
+ const rtems_bdpart_partition *p_end = pt + (count != NULL ? *count : 0);
+ rtems_blkdev_bnum ep_begin = 0; /* Extended partition begin */
+ rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
+ rtems_blkdev_bnum disk_end = 0;
+ dev_t disk = 0;
+ size_t i = 0;
+ const uint8_t *data = NULL;
+
+ /* Check parameter */
+ if (format == NULL || pt == NULL || count == NULL) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ /* Set count to a save value */
+ *count = 0;
+
+ /* Get disk data */
+ sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Read MBR */
+ sc = rtems_bdpart_read_record( disk, 0, &block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+
+ /* Read the first partition entry */
+ data = block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0;
+ sc = rtems_bdpart_read_mbr_partition( data, &p, p_end, &ep_begin);
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+
+ /* Determine if we have a MBR or GPT format */
+ if (rtems_bdpart_mbr_partition_type( p->type) == RTEMS_BDPART_MBR_GPT) {
+ esc = RTEMS_NOT_IMPLEMENTED;
+ goto cleanup;
+ }
+
+ /* Set format */
+ format->type = RTEMS_BDPART_FORMAT_MBR;
+ format->mbr.disk_id = rtems_uint32_from_little_endian(
+ block->buffer + RTEMS_BDPART_MBR_OFFSET_DISK_ID
+ );
+ format->mbr.dos_compatibility = true;
+
+ /* Iterate through the rest of the primary partition table */
+ for (i = 1; i < 4; ++i) {
+ data += RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE;
+
+ sc = rtems_bdpart_read_mbr_partition( data, &p, p_end, &ep_begin);
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+ }
+
+ /* Iterate through the logical partitions within the extended partition */
+ ebr = ep_begin;
+ while (ebr != 0) {
+ rtems_blkdev_bnum tmp = 0;
+
+ /* Read EBR */
+ sc = rtems_bdpart_read_record( disk, ebr, &block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+
+ /* Read first partition entry */
+ sc = rtems_bdpart_read_mbr_partition(
+ block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0,
+ &p,
+ p_end,
+ NULL
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+
+ /* Adjust partition begin */
+ tmp = p->begin + ebr;
+ if (tmp > p->begin) {
+ p->begin = tmp;
+ } else {
+ esc = RTEMS_IO_ERROR;
+ goto cleanup;
+ }
+
+ /* Adjust partition end */
+ tmp = p->end + ebr;
+ if (tmp > p->end) {
+ p->end = tmp;
+ } else {
+ esc = RTEMS_IO_ERROR;
+ goto cleanup;
+ }
+
+ /* Read second partition entry for next EBR block */
+ ebr = rtems_bdpart_next_ebr(
+ block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_1
+ );
+ if (ebr != 0) {
+ /* Adjust partition EBR block index */
+ tmp = ebr + ep_begin;
+ if (tmp > ebr) {
+ ebr = tmp;
+ } else {
+ esc = RTEMS_IO_ERROR;
+ goto cleanup;
+ }
+ }
+ }
+
+ /* Return partition count */
+ *count = (size_t) (p - pt + 1);
+
+cleanup:
+
+ if (block != NULL) {
+ rtems_bdbuf_release( block);
+ }
+
+ return esc;
+}
diff --git a/cpukit/libblock/src/bdpart-register.c b/cpukit/libblock/src/bdpart-register.c
new file mode 100644
index 0000000000..172c8b4964
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-register.c
@@ -0,0 +1,163 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+rtems_status_code rtems_bdpart_register(
+ const char *disk_name,
+ const rtems_bdpart_partition *pt,
+ size_t count
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code esc = RTEMS_SUCCESSFUL;
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+ rtems_blkdev_bnum disk_end = 0;
+ dev_t disk = 0;
+ dev_t logical_disk = 0;
+ char *logical_disk_name = NULL;
+ char *logical_disk_marker = NULL;
+ size_t disk_name_size = strlen( disk_name);
+ size_t i = 0;
+
+ /* Get disk data */
+ sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Get the disk device identifier */
+ rtems_filesystem_split_dev_t( disk, major, minor);
+
+ /* Create logical disk name */
+ logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
+ if (logical_disk_name == NULL) {
+ return RTEMS_NO_MEMORY;
+ }
+ strncpy( logical_disk_name, disk_name, disk_name_size);
+ logical_disk_marker = logical_disk_name + disk_name_size;
+
+ /* Create a logical disk for each partition */
+ for (i = 0; i < count; ++i) {
+ const rtems_bdpart_partition *p = pt + i;
+ int rv = 0;
+
+ /* New minor number */
+ ++minor;
+
+ /* Create a new device identifier */
+ logical_disk = rtems_filesystem_make_dev_t( major, minor);
+
+ /* Set partition number for logical disk name */
+ rv = snprintf( logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
+ if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
+ esc = RTEMS_INVALID_NAME;
+ goto cleanup;
+ }
+
+ /* Create logical disk */
+ sc = rtems_disk_create_log(
+ logical_disk,
+ disk,
+ p->begin,
+ p->end - p->begin,
+ logical_disk_name
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+ }
+
+cleanup:
+
+ free( logical_disk_name);
+
+ return esc;
+}
+
+rtems_status_code rtems_bdpart_register_from_disk( const char *disk_name)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_bdpart_format format;
+ rtems_bdpart_partition pt [RTEMS_BDPART_PARTITION_NUMBER_HINT];
+ size_t count = RTEMS_BDPART_PARTITION_NUMBER_HINT;
+
+ /* Read partitions */
+ sc = rtems_bdpart_read( disk_name, &format, pt, &count);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Register partitions */
+ return rtems_bdpart_register( disk_name, pt, count);
+}
+
+rtems_status_code rtems_bdpart_unregister(
+ const char *disk_name,
+ const rtems_bdpart_partition *pt __attribute__((unused)),
+ size_t count
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+ rtems_blkdev_bnum disk_end = 0;
+ dev_t disk = 0;
+ dev_t logical_disk = 0;
+ size_t i = 0;
+
+ /* Get disk data */
+ sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Get the disk device identifier */
+ rtems_filesystem_split_dev_t( disk, major, minor);
+
+ /* Create a logical disk for each partition */
+ for (i = 0; i < count; ++i) {
+ /* New minor number */
+ ++minor;
+
+ /* Get the device identifier */
+ logical_disk = rtems_filesystem_make_dev_t( major, minor);
+
+ /* Delete logical disk */
+ sc = rtems_disk_delete( logical_disk);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/bdpart-sort.c b/cpukit/libblock/src/bdpart-sort.c
new file mode 100644
index 0000000000..1114b7a492
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-sort.c
@@ -0,0 +1,48 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+static int rtems_bdpart_partition_compare( const void *aa, const void *bb)
+{
+ const rtems_bdpart_partition *a = aa;
+ const rtems_bdpart_partition *b = bb;
+
+ if (a->begin < b->begin) {
+ return -1;
+ } else if (a->begin == b->begin) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+void rtems_bdpart_sort( rtems_bdpart_partition *pt, size_t count)
+{
+ qsort( pt, count, sizeof( *pt), rtems_bdpart_partition_compare);
+}
diff --git a/cpukit/libblock/src/bdpart-write.c b/cpukit/libblock/src/bdpart-write.c
new file mode 100644
index 0000000000..92e80a24ec
--- /dev/null
+++ b/cpukit/libblock/src/bdpart-write.c
@@ -0,0 +1,302 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/bdbuf.h>
+#include <rtems/bdpart.h>
+#include <rtems/endian.h>
+
+static void rtems_bdpart_write_mbr_partition(
+ uint8_t *data,
+ uint32_t begin,
+ uint32_t size,
+ uint8_t type,
+ uint8_t flags
+)
+{
+ rtems_uint32_to_little_endian( begin, data + RTEMS_BDPART_MBR_OFFSET_BEGIN);
+ rtems_uint32_to_little_endian( size, data + RTEMS_BDPART_MBR_OFFSET_SIZE);
+ data [RTEMS_BDPART_MBR_OFFSET_TYPE] = type;
+ data [RTEMS_BDPART_MBR_OFFSET_FLAGS] = flags;
+}
+
+static rtems_status_code rtems_bdpart_new_record(
+ dev_t disk,
+ rtems_blkdev_bnum index,
+ rtems_bdbuf_buffer **block
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ /* Synchronize previous block if necessary */
+ if (*block != NULL) {
+ sc = rtems_bdbuf_sync( *block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+ }
+
+ /* Read the new record block (this accounts for disk block sizes > 512) */
+ sc = rtems_bdbuf_read( disk, index, block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* just in case block did not get filled in */
+ if ( *block == NULL ) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ /* Clear record */
+ memset( (*block)->buffer, 0, RTEMS_BDPART_BLOCK_SIZE);
+
+ /* Write signature */
+ (*block)->buffer [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_0] =
+ RTEMS_BDPART_MBR_SIGNATURE_0;
+ (*block)->buffer [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_1] =
+ RTEMS_BDPART_MBR_SIGNATURE_1;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_bdpart_write(
+ const char *disk_name,
+ const rtems_bdpart_format *format,
+ const rtems_bdpart_partition *pt,
+ size_t count
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code esc = RTEMS_SUCCESSFUL;
+ bool dos_compatibility = format != NULL
+ && format->type == RTEMS_BDPART_FORMAT_MBR
+ && format->mbr.dos_compatibility;
+ rtems_bdbuf_buffer *block = NULL;
+ rtems_blkdev_bnum disk_end = 0;
+ rtems_blkdev_bnum record_space =
+ dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
+ dev_t disk = 0;
+ size_t ppc = 0; /* Primary partition count */
+ size_t i = 0;
+ uint8_t *data = NULL;
+
+ /* Check if we have something to do */
+ if (count == 0) {
+ /* Nothing to do */
+ return RTEMS_SUCCESSFUL;
+ }
+
+ /* Check parameter */
+ if (format == NULL || pt == NULL) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ /* Get disk data */
+ sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ /* Align end of disk on cylinder boundary if necessary */
+ if (dos_compatibility) {
+ disk_end -= (disk_end % record_space);
+ }
+
+ /* Check that we have a consistent partition table */
+ for (i = 0; i < count; ++i) {
+ const rtems_bdpart_partition *p = pt + i;
+
+ /* Check that begin and end are proper within the disk */
+ if (p->begin >= disk_end || p->end > disk_end) {
+ esc = RTEMS_INVALID_NUMBER;
+ goto cleanup;
+ }
+
+ /* Check that begin and end are valid */
+ if (p->begin >= p->end) {
+ esc = RTEMS_INVALID_NUMBER;
+ goto cleanup;
+ }
+
+ /* Check that partitions do not overlap */
+ if (i > 0 && pt [i - 1].end > p->begin) {
+ esc = RTEMS_INVALID_NUMBER;
+ goto cleanup;
+ }
+ }
+
+ /* Check format */
+ if (format->type != RTEMS_BDPART_FORMAT_MBR) {
+ esc = RTEMS_NOT_IMPLEMENTED;
+ goto cleanup;
+ }
+
+ /*
+ * Set primary partition count. If we have more than four partitions we need
+ * an extended partition which will contain the partitions of number four and
+ * above as logical partitions. If we have four or less partitions we can
+ * use the primary partition table.
+ */
+ ppc = count <= 4 ? count : 3;
+
+ /*
+ * Check that the first primary partition starts at head one and sector one
+ * under the virtual one head and 63 sectors geometry if necessary.
+ */
+ if (dos_compatibility && pt [0].begin != RTEMS_BDPART_MBR_CYLINDER_SIZE) {
+ esc = RTEMS_INVALID_NUMBER;
+ goto cleanup;
+ }
+
+ /*
+ * Check that we have enough space for the EBRs. The partitions with number
+ * four and above are logical partitions if we have more than four partitions
+ * in total. The logical partitions are contained in the extended partition.
+ * Each logical partition is described via one EBR preceding the partition.
+ * The space for the EBR and maybe some space which is needed for DOS
+ * compatibility resides between the partitions. So there have to be gaps of
+ * the appropriate size between the partitions.
+ */
+ for (i = ppc; i < count; ++i) {
+ if ((pt [i].begin - pt [i - 1].end) < record_space) {
+ esc = RTEMS_INVALID_NUMBER;
+ goto cleanup;
+ }
+ }
+
+ /* Check that we can convert the parition descriptions to the MBR format */
+ for (i = 0; i < count; ++i) {
+ uint8_t type = 0;
+
+ const rtems_bdpart_partition *p = pt + i;
+
+ /* Check type */
+ if (!rtems_bdpart_to_mbr_partition_type( p->type, &type)) {
+ esc = RTEMS_INVALID_ID;
+ goto cleanup;
+ }
+
+ /* Check flags */
+ if (p->flags > 0xffU) {
+ esc = RTEMS_INVALID_ID;
+ goto cleanup;
+ }
+
+ /* Check ID */
+ /* TODO */
+ }
+
+ /* New MBR */
+ sc = rtems_bdpart_new_record( disk, 0, &block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+
+ /* Write disk ID */
+ rtems_uint32_to_little_endian(
+ format->mbr.disk_id,
+ block->buffer + RTEMS_BDPART_MBR_OFFSET_DISK_ID
+ );
+
+ /* Write primary partition table */
+ data = block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0;
+ for (i = 0; i < ppc; ++i) {
+ const rtems_bdpart_partition *p = pt + i;
+
+ /* Write partition entry */
+ rtems_bdpart_write_mbr_partition(
+ data,
+ p->begin,
+ p->end - p->begin,
+ rtems_bdpart_mbr_partition_type( p->type),
+ (uint8_t) p->flags
+ );
+
+ data += RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE;
+ }
+
+ /* Write extended partition with logical partitions if necessary */
+ if (ppc != count) {
+ rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
+
+ /* Begin of extended partition */
+ rtems_blkdev_bnum ep_begin = pt [ppc].begin - record_space;
+
+ /* Write extended partition */
+ rtems_bdpart_write_mbr_partition(
+ data,
+ ep_begin,
+ disk_end - ep_begin,
+ RTEMS_BDPART_MBR_EXTENDED,
+ 0
+ );
+
+ /* Write logical partitions */
+ for (i = ppc; i < count; ++i) {
+ const rtems_bdpart_partition *p = pt + i;
+
+ /* Write second partition entry */
+ if (i > ppc) {
+ rtems_blkdev_bnum begin = p->begin - record_space;
+
+ rtems_bdpart_write_mbr_partition(
+ block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_1,
+ begin - ep_begin,
+ disk_end - begin,
+ RTEMS_BDPART_MBR_EXTENDED,
+ 0
+ );
+ }
+
+ /* New EBR */
+ ebr = p->begin - record_space;
+ sc = rtems_bdpart_new_record( disk, ebr, &block);
+ if (sc != RTEMS_SUCCESSFUL) {
+ esc = sc;
+ goto cleanup;
+ }
+
+ /* Write first partition entry */
+ rtems_bdpart_write_mbr_partition(
+ block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0,
+ record_space,
+ p->end - p->begin,
+ rtems_bdpart_mbr_partition_type( p->type),
+ (uint8_t) p->flags
+ );
+ }
+ }
+
+cleanup:
+
+ if (block != NULL) {
+ rtems_bdbuf_sync( block);
+ }
+
+ return esc;
+}
diff --git a/cpukit/libblock/src/blkdev-ops.c b/cpukit/libblock/src/blkdev-ops.c
new file mode 100644
index 0000000000..6cc0c3009e
--- /dev/null
+++ b/cpukit/libblock/src/blkdev-ops.c
@@ -0,0 +1,32 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_blkdev
+ *
+ * @brief Block device management.
+ */
+
+/*
+ * Copyright (c) 2011 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/blkdev.h>
+
+const rtems_driver_address_table rtems_blkdev_generic_ops = {
+ .initialization_entry = NULL,
+ .open_entry = rtems_blkdev_generic_open,
+ .close_entry = rtems_blkdev_generic_close,
+ .read_entry = rtems_blkdev_generic_read,
+ .write_entry = rtems_blkdev_generic_write,
+ .control_entry = rtems_blkdev_generic_ioctl
+};
diff --git a/cpukit/libblock/src/blkdev.c b/cpukit/libblock/src/blkdev.c
new file mode 100644
index 0000000000..10c14dfaf2
--- /dev/null
+++ b/cpukit/libblock/src/blkdev.c
@@ -0,0 +1,263 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_blkdev
+ *
+ * Block device management.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <sys/ioctl.h>
+
+#include "rtems/diskdevs.h"
+#include "rtems/bdbuf.h"
+
+/* rtems_blkdev_generic_read --
+ * Generic block device read primitive. Implemented using block device
+ * buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_read(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void * arg)
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ rtems_libio_rw_args_t *args = arg;
+ rtems_libio_t *iop = args->iop;
+ rtems_disk_device *dd = iop->data1;
+ uint32_t block_size = dd->block_size;
+ char *buf = args->buffer;
+ uint32_t count = args->count;
+ rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
+ uint32_t blkofs = (uint32_t) (args->offset % block_size);
+ dev_t dev = dd->dev;
+
+ args->bytes_moved = 0;
+
+ while (count > 0)
+ {
+ rtems_bdbuf_buffer *diskbuf;
+ uint32_t copy;
+
+ rc = rtems_bdbuf_read(dev, block, &diskbuf);
+ if (rc != RTEMS_SUCCESSFUL)
+ break;
+ copy = block_size - blkofs;
+ if (copy > count)
+ copy = count;
+ memcpy(buf, (char *)diskbuf->buffer + blkofs, copy);
+ rc = rtems_bdbuf_release(diskbuf);
+ args->bytes_moved += copy;
+ if (rc != RTEMS_SUCCESSFUL)
+ break;
+ count -= copy;
+ buf += copy;
+ blkofs = 0;
+ block++;
+ }
+
+ return rc;
+}
+
+/* rtems_blkdev_generic_write --
+ * Generic block device write primitive. Implemented using block device
+ * buffer management primitives.
+ */
+rtems_device_driver
+rtems_blkdev_generic_write(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void * arg)
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ rtems_libio_rw_args_t *args = arg;
+ rtems_libio_t *iop = args->iop;
+ rtems_disk_device *dd = iop->data1;
+ uint32_t block_size = dd->block_size;
+ char *buf = args->buffer;
+ uint32_t count = args->count;
+ rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
+ uint32_t blkofs = (uint32_t) (args->offset % block_size);
+ dev_t dev = dd->dev;
+
+ args->bytes_moved = 0;
+
+ while (count > 0)
+ {
+ rtems_bdbuf_buffer *diskbuf;
+ uint32_t copy;
+
+ if ((blkofs == 0) && (count >= block_size))
+ rc = rtems_bdbuf_get(dev, block, &diskbuf);
+ else
+ rc = rtems_bdbuf_read(dev, block, &diskbuf);
+ if (rc != RTEMS_SUCCESSFUL)
+ break;
+
+ copy = block_size - blkofs;
+ if (copy > count)
+ copy = count;
+ memcpy((char *)diskbuf->buffer + blkofs, buf, copy);
+ args->bytes_moved += copy;
+
+ rc = rtems_bdbuf_release_modified(diskbuf);
+ if (rc != RTEMS_SUCCESSFUL)
+ break;
+
+ count -= copy;
+ buf += copy;
+ blkofs = 0;
+ block++;
+ }
+
+ return rc;
+}
+
+/* blkdev_generic_open --
+ * Generic block device open primitive.
+ */
+rtems_device_driver
+rtems_blkdev_generic_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg)
+{
+ rtems_libio_open_close_args_t *oc = arg;
+ rtems_libio_t *iop = oc->iop;
+ dev_t dev = rtems_filesystem_make_dev_t(major, minor);
+ rtems_disk_device *dd = rtems_disk_obtain(dev);
+
+ iop->data1 = dd;
+
+ if (dd != NULL)
+ return RTEMS_SUCCESSFUL;
+ else
+ return RTEMS_UNSATISFIED;
+}
+
+
+/* blkdev_generic_close --
+ * Generic block device close primitive.
+ */
+rtems_device_driver
+rtems_blkdev_generic_close(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void * arg)
+{
+ rtems_libio_open_close_args_t *oc = arg;
+ rtems_libio_t *iop = oc->iop;
+ rtems_disk_device *dd = iop->data1;
+
+ rtems_disk_release(dd);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/* blkdev_generic_ioctl --
+ * Generic block device ioctl primitive.
+ */
+rtems_device_driver
+rtems_blkdev_generic_ioctl(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void * arg)
+{
+ rtems_libio_ioctl_args_t *args = arg;
+ rtems_libio_t *iop = args->iop;
+ rtems_disk_device *dd = iop->data1;
+ int rc;
+
+ switch (args->command)
+ {
+ case RTEMS_BLKIO_GETMEDIABLKSIZE:
+ *((uint32_t *) args->buffer) = dd->media_block_size;
+ args->ioctl_return = 0;
+ break;
+
+ case RTEMS_BLKIO_GETBLKSIZE:
+ *((uint32_t *) args->buffer) = dd->block_size;
+ args->ioctl_return = 0;
+ break;
+
+ case RTEMS_BLKIO_SETBLKSIZE:
+ dd->block_size = *((uint32_t *) args->buffer);
+ args->ioctl_return = 0;
+ break;
+
+ case RTEMS_BLKIO_GETSIZE:
+ *((rtems_blkdev_bnum *) args->buffer) = dd->size;
+ args->ioctl_return = 0;
+ break;
+
+ case RTEMS_BLKIO_SYNCDEV:
+ rc = rtems_bdbuf_syncdev(dd->dev);
+ args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
+ break;
+
+ case RTEMS_BLKIO_REQUEST:
+ /*
+ * It is not allowed to directly access the driver circumventing
+ * the cache.
+ */
+ args->ioctl_return = (uint32_t) -1;
+ break;
+
+ default:
+ args->ioctl_return = (uint32_t) dd->ioctl(dd->phys_dev,
+ args->command,
+ args->buffer);
+ break;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+int
+rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
+{
+ size_t *arg_size = argp;
+ int rc = 0;
+
+ switch (req)
+ {
+ case RTEMS_BLKIO_GETMEDIABLKSIZE:
+ *arg_size = dd->media_block_size;
+ break;
+
+ case RTEMS_BLKIO_GETBLKSIZE:
+ *arg_size = dd->block_size;
+ break;
+
+ case RTEMS_BLKIO_SETBLKSIZE:
+ dd->block_size = *arg_size;
+ break;
+
+ case RTEMS_BLKIO_GETSIZE:
+ *arg_size = dd->size;
+ break;
+
+ default:
+ errno = EINVAL;
+ rc = -1;
+ break;
+ }
+
+ return rc;
+}
diff --git a/cpukit/libblock/src/diskdevs.c b/cpukit/libblock/src/diskdevs.c
new file mode 100644
index 0000000000..08a6a9bf8c
--- /dev/null
+++ b/cpukit/libblock/src/diskdevs.c
@@ -0,0 +1,589 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_disk
+ *
+ * @brief Block device disk management implementation.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/diskdevs.h>
+#include <rtems/blkdev.h>
+#include <rtems/bdbuf.h>
+
+#define DISKTAB_INITIAL_SIZE 8
+
+/* Table of disk devices having the same major number */
+typedef struct rtems_disk_device_table {
+ rtems_disk_device **minor; /* minor-indexed disk device table */
+ rtems_device_minor_number size; /* Number of entries in the table */
+} rtems_disk_device_table;
+
+/* Pointer to [major].minor[minor] indexed array of disk devices */
+static rtems_disk_device_table *disktab;
+
+/* Number of allocated entries in disktab table */
+static rtems_device_major_number disktab_size;
+
+/* Mutual exclusion semaphore for disk devices table */
+static rtems_id diskdevs_mutex;
+
+/* diskdevs data structures protection flag.
+ * Normally, only table lookup operations performed. It is quite fast, so
+ * it is possible to done lookups when interrupts are disabled, avoiding
+ * obtaining the semaphore. This flags sets immediately after entering in
+ * mutex-protected section and cleared before leaving this section in
+ * "big" primitives like add/delete new device etc. Lookup function first
+ * disable interrupts and check this flag. If it is set, lookup function
+ * will be blocked on semaphore and lookup operation will be performed in
+ * semaphore-protected code. If it is not set (very-very frequent case),
+ * we can do lookup safely, enable interrupts and return result.
+ */
+static volatile bool diskdevs_protected;
+
+static rtems_status_code
+disk_lock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_semaphore_obtain(diskdevs_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc == RTEMS_SUCCESSFUL) {
+ diskdevs_protected = true;
+
+ return RTEMS_SUCCESSFUL;
+ } else {
+ return RTEMS_NOT_CONFIGURED;
+ }
+}
+
+static void
+disk_unlock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ diskdevs_protected = false;
+
+ sc = rtems_semaphore_release(diskdevs_mutex);
+ if (sc != RTEMS_SUCCESSFUL) {
+ /* FIXME: Error number */
+ rtems_fatal_error_occurred(0xdeadbeef);
+ }
+}
+
+static rtems_disk_device *
+get_disk_entry(dev_t dev, bool lookup_only)
+{
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+
+ rtems_filesystem_split_dev_t(dev, major, minor);
+
+ if (major < disktab_size && disktab != NULL) {
+ rtems_disk_device_table *dtab = disktab + major;
+
+ if (minor < dtab->size && dtab->minor != NULL) {
+ rtems_disk_device *dd = dtab->minor [minor];
+
+ if (dd != NULL && !lookup_only) {
+ if (!dd->deleted) {
+ ++dd->uses;
+ } else {
+ dd = NULL;
+ }
+ }
+
+ return dd;
+ }
+ }
+
+ return NULL;
+}
+
+static rtems_disk_device **
+create_disk_table_entry(dev_t dev)
+{
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+
+ rtems_filesystem_split_dev_t(dev, major, minor);
+
+ if (major >= disktab_size) {
+ rtems_disk_device_table *table = disktab;
+ rtems_device_major_number old_size = disktab_size;
+ rtems_device_major_number new_size = 2 * old_size;
+
+ if (major >= new_size) {
+ new_size = major + 1;
+ }
+
+ table = realloc(table, new_size * sizeof(*table));
+ if (table == NULL) {
+ return NULL;
+ }
+
+ memset(table + old_size, 0, (new_size - old_size) * sizeof(*table));
+ disktab = table;
+ disktab_size = new_size;
+ }
+
+ if (disktab [major].minor == NULL || minor >= disktab[major].size) {
+ rtems_disk_device **table = disktab [major].minor;
+ rtems_device_minor_number old_size = disktab [major].size;
+ rtems_device_minor_number new_size = 0;
+
+ if (old_size == 0) {
+ new_size = DISKTAB_INITIAL_SIZE;
+ } else {
+ new_size = 2 * old_size;
+ }
+ if (minor >= new_size) {
+ new_size = minor + 1;
+ }
+
+ table = realloc(table, new_size * sizeof(*table));
+ if (table == NULL) {
+ return NULL;
+ }
+
+ memset(table + old_size, 0, (new_size - old_size) * sizeof(*table));
+ disktab [major].minor = table;
+ disktab [major].size = new_size;
+ }
+
+ return disktab [major].minor + minor;
+}
+
+static rtems_status_code
+create_disk(dev_t dev, const char *name, rtems_disk_device **dd_ptr)
+{
+ rtems_disk_device **dd_entry = create_disk_table_entry(dev);
+ rtems_disk_device *dd = NULL;
+ char *alloc_name = NULL;
+
+ if (dd_entry == NULL) {
+ return RTEMS_NO_MEMORY;
+ }
+
+ if (*dd_entry != NULL) {
+ return RTEMS_RESOURCE_IN_USE;
+ }
+
+ dd = malloc(sizeof(*dd));
+ if (dd == NULL) {
+ return RTEMS_NO_MEMORY;
+ }
+
+ if (name != NULL) {
+ alloc_name = strdup(name);
+
+ if (alloc_name == NULL) {
+ free(dd);
+
+ return RTEMS_NO_MEMORY;
+ }
+ }
+
+ if (name != NULL) {
+ if (mknod(alloc_name, 0777 | S_IFBLK, dev) < 0) {
+ free(alloc_name);
+ free(dd);
+ return RTEMS_UNSATISFIED;
+ }
+ }
+
+ dd->dev = dev;
+ dd->name = alloc_name;
+ dd->uses = 0;
+ dd->deleted = false;
+
+ *dd_entry = dd;
+ *dd_ptr = dd;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_disk_create_phys(
+ dev_t dev,
+ uint32_t block_size,
+ rtems_blkdev_bnum block_count,
+ rtems_block_device_ioctl handler,
+ void *driver_data,
+ const char *name
+)
+{
+ rtems_disk_device *dd = NULL;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (handler == NULL) {
+ return RTEMS_INVALID_ADDRESS;
+ }
+
+ if (block_size == 0) {
+ return RTEMS_INVALID_NUMBER;
+ }
+
+ sc = disk_lock();
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ sc = create_disk(dev, name, &dd);
+ if (sc != RTEMS_SUCCESSFUL) {
+ disk_unlock();
+
+ return sc;
+ }
+
+ dd->phys_dev = dd;
+ dd->start = 0;
+ dd->size = block_count;
+ dd->block_size = dd->media_block_size = block_size;
+ dd->ioctl = handler;
+ dd->driver_data = driver_data;
+
+ if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) < 0) {
+ dd->capabilities = 0;
+ }
+
+ disk_unlock();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static bool
+is_physical_disk(const rtems_disk_device *dd)
+{
+ return dd->phys_dev == dd;
+}
+
+rtems_status_code rtems_disk_create_log(
+ dev_t dev,
+ dev_t phys,
+ rtems_blkdev_bnum begin_block,
+ rtems_blkdev_bnum block_count,
+ const char *name
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *physical_disk = NULL;
+ rtems_disk_device *dd = NULL;
+ rtems_blkdev_bnum end_block = begin_block + block_count;
+
+ sc = disk_lock();
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ physical_disk = get_disk_entry(phys, true);
+ if (physical_disk == NULL || !is_physical_disk(physical_disk)) {
+ disk_unlock();
+
+ return RTEMS_INVALID_ID;
+ }
+
+ if (
+ begin_block >= physical_disk->size
+ || end_block <= begin_block
+ || end_block > physical_disk->size
+ ) {
+ disk_unlock();
+
+ return RTEMS_INVALID_NUMBER;
+ }
+
+ sc = create_disk(dev, name, &dd);
+ if (sc != RTEMS_SUCCESSFUL) {
+ disk_unlock();
+
+ return sc;
+ }
+
+ dd->phys_dev = physical_disk;
+ dd->start = begin_block;
+ dd->size = block_count;
+ dd->block_size = dd->media_block_size = physical_disk->block_size;
+ dd->ioctl = physical_disk->ioctl;
+ dd->driver_data = physical_disk->driver_data;
+
+ ++physical_disk->uses;
+
+ disk_unlock();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static void
+free_disk_device(rtems_disk_device *dd)
+{
+ if (is_physical_disk(dd)) {
+ (*dd->ioctl)(dd, RTEMS_BLKIO_DELETED, NULL);
+ }
+ if (dd->name != NULL) {
+ unlink(dd->name);
+ free(dd->name);
+ }
+ free(dd);
+}
+
+static void
+rtems_disk_cleanup(rtems_disk_device *disk_to_remove)
+{
+ rtems_disk_device *const physical_disk = disk_to_remove->phys_dev;
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+
+ if (physical_disk->deleted) {
+ dev_t dev = physical_disk->dev;
+ unsigned deleted_count = 0;
+
+ for (major = 0; major < disktab_size; ++major) {
+ rtems_disk_device_table *dtab = disktab + major;
+
+ for (minor = 0; minor < dtab->size; ++minor) {
+ rtems_disk_device *dd = dtab->minor [minor];
+
+ if (dd != NULL && dd->phys_dev->dev == dev && dd != physical_disk) {
+ if (dd->uses == 0) {
+ ++deleted_count;
+ dtab->minor [minor] = NULL;
+ free_disk_device(dd);
+ } else {
+ dd->deleted = true;
+ }
+ }
+ }
+ }
+
+ physical_disk->uses -= deleted_count;
+ if (physical_disk->uses == 0) {
+ rtems_filesystem_split_dev_t(physical_disk->dev, major, minor);
+ disktab [major].minor [minor] = NULL;
+ free_disk_device(physical_disk);
+ }
+ } else {
+ if (disk_to_remove->uses == 0) {
+ --physical_disk->uses;
+ rtems_filesystem_split_dev_t(disk_to_remove->dev, major, minor);
+ disktab [major].minor [minor] = NULL;
+ free_disk_device(disk_to_remove);
+ }
+ }
+}
+
+rtems_status_code
+rtems_disk_delete(dev_t dev)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *dd = NULL;
+
+ sc = disk_lock();
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ dd = get_disk_entry(dev, true);
+ if (dd == NULL) {
+ disk_unlock();
+
+ return RTEMS_INVALID_ID;
+ }
+
+ dd->deleted = true;
+ rtems_disk_cleanup(dd);
+
+ disk_unlock();
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_disk_device *
+rtems_disk_obtain(dev_t dev)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device *dd = NULL;
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable(level);
+ if (!diskdevs_protected) {
+ /* Frequent and quickest case */
+ dd = get_disk_entry(dev, false);
+ rtems_interrupt_enable(level);
+ } else {
+ rtems_interrupt_enable(level);
+
+ sc = disk_lock();
+ if (sc == RTEMS_SUCCESSFUL) {
+ dd = get_disk_entry(dev, false);
+ disk_unlock();
+ }
+ }
+
+ return dd;
+}
+
+rtems_status_code
+rtems_disk_release(rtems_disk_device *dd)
+{
+ rtems_interrupt_level level;
+ dev_t dev = dd->dev;
+ unsigned uses = 0;
+ bool deleted = false;
+
+ rtems_interrupt_disable(level);
+ uses = --dd->uses;
+ deleted = dd->deleted;
+ rtems_interrupt_enable(level);
+
+ if (uses == 0 && deleted) {
+ rtems_disk_delete(dev);
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_disk_device *
+rtems_disk_next(dev_t dev)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_disk_device_table *dtab = NULL;
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+
+ if (dev != (dev_t) -1) {
+ rtems_filesystem_split_dev_t(dev, major, minor);
+
+ /* If minor wraps around */
+ if ((minor + 1) < minor) {
+ /* If major wraps around */
+ if ((major + 1) < major) {
+ return NULL;
+ }
+ ++major;
+ minor = 0;
+ } else {
+ ++minor;
+ }
+ }
+
+ sc = disk_lock();
+ if (sc != RTEMS_SUCCESSFUL) {
+ return NULL;
+ }
+
+ if (major >= disktab_size) {
+ disk_unlock();
+
+ return NULL;
+ }
+
+ dtab = disktab + major;
+ while (true) {
+ if (dtab->minor == NULL || minor >= dtab->size) {
+ minor = 0;
+ ++major;
+ if (major >= disktab_size) {
+ disk_unlock();
+
+ return NULL;
+ }
+ dtab = disktab + major;
+ } else if (dtab->minor [minor] == NULL) {
+ ++minor;
+ } else {
+ ++dtab->minor [minor]->uses;
+ disk_unlock();
+
+ return dtab->minor [minor];
+ }
+ }
+}
+
+rtems_status_code
+rtems_disk_io_initialize(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_device_major_number size = DISKTAB_INITIAL_SIZE;
+
+ if (disktab_size > 0) {
+ return RTEMS_SUCCESSFUL;
+ }
+
+ disktab = calloc(size, sizeof(rtems_disk_device_table));
+ if (disktab == NULL) {
+ return RTEMS_NO_MEMORY;
+ }
+
+ diskdevs_protected = false;
+ sc = rtems_semaphore_create(
+ rtems_build_name('D', 'D', 'E', 'V'),
+ 1,
+ RTEMS_FIFO | RTEMS_BINARY_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY
+ | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL,
+ 0,
+ &diskdevs_mutex
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ free(disktab);
+
+ return RTEMS_NO_MEMORY;
+ }
+
+ sc = rtems_bdbuf_init();
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_semaphore_delete(diskdevs_mutex);
+ free(disktab);
+
+ return RTEMS_UNSATISFIED;
+ }
+
+ disktab_size = size;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code
+rtems_disk_io_done(void)
+{
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+
+ for (major = 0; major < disktab_size; ++major) {
+ rtems_disk_device_table *dtab = disktab + major;
+
+ for (minor = 0; minor < dtab->size; ++minor) {
+ rtems_disk_device *dd = dtab->minor [minor];
+
+ if (dd != NULL) {
+ free_disk_device(dd);
+ }
+ }
+ free(dtab->minor);
+ }
+ free(disktab);
+
+ rtems_semaphore_delete(diskdevs_mutex);
+
+ diskdevs_mutex = RTEMS_ID_NONE;
+ disktab = NULL;
+ disktab_size = 0;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/flashdisk.c b/cpukit/libblock/src/flashdisk.c
new file mode 100644
index 0000000000..20a9eb46b9
--- /dev/null
+++ b/cpukit/libblock/src/flashdisk.c
@@ -0,0 +1,2603 @@
+/*
+ * flashdisk.c -- Flash disk block device implementation
+ *
+ * Copyright (C) 2007 Chris Johns
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * Flash disk driver for RTEMS provides support for block based
+ * file systems on flash devices. The driver is not a flash file
+ * system nor does it try to compete with flash file systems. It
+ * currently does not journal how-ever block sequence numbering
+ * could be added to allow recovery of a past positions if
+ * a power down occurred while being updated.
+ *
+ * This flash driver provides block device support for most flash
+ * devices. The driver has been tested on NOR type devices such
+ * as the AMLV160 or M28W160. Support for NAND type devices may
+ * require driver changes to allow speedy recover of the block
+ * mapping data and to also handle the current use of word programming.
+ * Currently the page descriptors are stored in the first few pages
+ * of each segment.
+ *
+ * The driver supports devices, segments and pages. You provide
+ * to the driver the device descriptions as a table of device
+ * descriptors. Each device descriptor contain a table of
+ * segment descriptions or segment descriptors. The driver uses
+ * this information to manage the devices.
+ *
+ * A device is made up of segments. These are also called
+ * sectors or blocks. It is the smallest erasable part of a device.
+ * A device can have differing size segments at different
+ * offsets in the device. The segment descriptors support repeating
+ * segments that are continous in the device. The driver breaks the
+ * segments up into pages. The first pages of a segment contain
+ * the page descriptors. A page descriptor hold the page flags,
+ * a CRC for the page of data and the block number the page
+ * holds. The block can appear in any order in the devices. A
+ * page is active if it hold a current block of data. If the
+ * used bit is set the page is counted as used. A page moves
+ * from erased to active to used then back to erased. If a block
+ * is written that is already in a page, the block is written to
+ * a new page the old page is flagged as used.
+ *
+ * At initialisation time each segment's page descriptors are
+ * read into memory and scanned to determine the active pages,
+ * the used pages and the bad pages. If a segment has any erased
+ * pages it is queue on the available queue. If the segment has
+ * no erased pages it is queue on the used queue.
+ *
+ * The available queue is sorted from the least number available
+ * to the most number of available pages. A segment that has just
+ * been erased will placed at the end of the queue. A segment that
+ * has only a few available pages will be used sooner and once
+ * there are no available pages it is queued on the used queue.
+ * The used queue hold segments that have no available pages and
+ * is sorted from the least number of active pages to the most
+ * number of active pages.
+ *
+ * The driver is required to compact segments. Compacting takes
+ * the segment with the most number of available pages from the
+ * available queue then takes segments with the least number of
+ * active pages from the used queue until it has enough pages
+ * to fill the empty segment. As the active pages are moved
+ * they flagged as used and once the segment has only used pages
+ * it is erased.
+ *
+ * A flash block driver like this never knows if a page is not
+ * being used by the file-system. A typical file system is not
+ * design with the idea of erasing a block on a disk once it is
+ * not being used. The file-system will normally use a flag
+ * or a location as a marker to say that part of the disk is
+ * no longer in use. This means a number of blocks could be
+ * held in active pages but are no in use by the file system.
+ * The file system may also read blocks that have never been
+ * written to disk. This complicates the driver and may make
+ * the wear, usage and erase patterns harsher than a flash
+ * file system. The driver may also suffer from problems if
+ * power is lost.
+ *
+ * @note
+ *
+ * The use of pages can vary. The rtems_fdisk_seg_*_page set
+ * routines use an absolute page number relative to the segment
+ * while all other page numbera are relative to the number of
+ * page descriptor pages a segment has. You need to add the
+ * number of page descriptor pages (pages_desc) to the page number
+ * when call the rtems_fdisk_seg_*_page functions.
+ *
+ * You must always show the page number as relative in any trace
+ * or error message as device-segment-page and if you have to
+ * the page number as absolute use device-segment~page. This
+ * can be seen in the page copy routine.
+ *
+ * The code is like this to avoid needing the pass the pages_desc
+ * value around. It is only used in selected places and so the
+ * extra parameter was avoided.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "rtems/blkdev.h"
+#include "rtems/diskdevs.h"
+#include "rtems/flashdisk.h"
+
+/**
+ * Control tracing. It can be compiled out of the code for small
+ * footprint targets. Leave in by default.
+ */
+#if !defined (RTEMS_FDISK_TRACE)
+#define RTEMS_FDISK_TRACE 1
+#endif
+
+/**
+ * The start of a segment has a segment control table. This hold the CRC and
+ * block number for the page.
+ *
+ * @todo A sequence number for the block could be added. This would
+ * mean a larger descriptor size. Need to make the sequence
+ * large like 20+ bits so a large file system would not have
+ * more blocks available than the sequence number.
+ */
+typedef struct rtems_fdisk_page_desc
+{
+ uint16_t crc; /**< The page's checksum. */
+ uint16_t flags; /**< The flags for the page. */
+ uint32_t block; /**< The block number. */
+} rtems_fdisk_page_desc;
+
+/**
+ * Flag the page as active.
+ */
+#define RTEMS_FDISK_PAGE_ACTIVE (1 << 0)
+
+/**
+ * Flag the page as used.
+ */
+#define RTEMS_FDISK_PAGE_USED (1 << 1)
+
+/**
+ * Flash Segment Control holds the pointer to the segment, number of
+ * pages, various page stats and the memory copy of the page descriptors.
+ */
+typedef struct rtems_fdisk_segment_ctl
+{
+ /**
+ * Segments with available pages are maintained as a linked list.
+ */
+ struct rtems_fdisk_segment_ctl* next;
+
+ /**
+ * The descriptor provided by the low-level driver.
+ */
+ const rtems_fdisk_segment_desc* descriptor;
+
+ /**
+ * The device this segment resides on.
+ */
+ uint32_t device;
+
+ /**
+ * The segment in the device. This must be within the
+ * segment descriptor.
+ */
+ uint32_t segment;
+
+ /**
+ * The in-memory ocpy of the page descriptors found at
+ * the start of the segment in the flash device.
+ */
+ rtems_fdisk_page_desc* page_descriptors;
+
+ /*
+ * Page stats.
+ *
+ * A bad page does not checksum or is not erased or has invalid flags.
+ */
+ uint32_t pages; /**< Total number of pages in the segment. */
+ uint32_t pages_desc; /**< Number of pages used for page descriptors. */
+ uint32_t pages_active; /**< Number of pages flagged as active. */
+ uint32_t pages_used; /**< Number of pages flagged as used. */
+ uint32_t pages_bad; /**< Number of pages detected as bad. */
+
+ uint32_t failed; /**< The segment has failed. */
+
+ uint32_t erased; /**< Counter to debugging. Wear support would
+ remove this. */
+} rtems_fdisk_segment_ctl;
+
+/**
+ * Segment control table queue.
+ */
+typedef struct rtems_fdisk_segment_ctl_queue
+{
+ rtems_fdisk_segment_ctl* head;
+ rtems_fdisk_segment_ctl* tail;
+ uint32_t count;
+} rtems_fdisk_segment_ctl_queue;
+
+/**
+ * Flash Device Control holds the segment controls
+ */
+typedef struct rtems_fdisk_device_ctl
+{
+ rtems_fdisk_segment_ctl* segments; /**< Segment controls. */
+ uint32_t segment_count; /**< Segment control count. */
+ const rtems_fdisk_device_desc* descriptor; /**< Device descriptor. */
+} rtems_fdisk_device_ctl;
+
+/**
+ * The Block control holds the segment and page with the data.
+ */
+typedef struct rtems_fdisk_block_ctl
+{
+ rtems_fdisk_segment_ctl* segment; /**< The segment with the block. */
+ uint32_t page; /**< The page in the segment. */
+} rtems_fdisk_block_ctl;
+
+/**
+ * The virtual block table holds the mapping for blocks as seen by the disk
+ * drivers to the device, segment and page numbers of the physical device.
+ */
+typedef struct rtems_flashdisk
+{
+ rtems_device_major_number major; /**< The driver's major number. */
+ rtems_device_minor_number minor; /**< The driver's minor number. */
+
+ uint32_t flags; /**< configuration flags. */
+
+ uint32_t compact_segs; /**< Max segs to compact at once. */
+ uint32_t avail_compact_segs; /**< The number of segments when
+ compaction occurs when writing. */
+
+ uint32_t block_size; /**< The block size for this disk. */
+ rtems_fdisk_block_ctl* blocks; /**< The block to segment-page
+ mappings. */
+ uint32_t block_count; /**< The number of avail. blocks. */
+ uint32_t unavail_blocks; /**< The number of unavail blocks. */
+
+ rtems_fdisk_device_ctl* devices; /**< The flash devices for this
+ disk. */
+ uint32_t device_count; /**< The number of flash devices. */
+
+ rtems_fdisk_segment_ctl_queue available; /**< The queue of segments with
+ available pages. */
+ rtems_fdisk_segment_ctl_queue used; /**< The list of segments with all
+ pages used. */
+ rtems_fdisk_segment_ctl_queue erase; /**< The list of segments to be
+ erased. */
+ rtems_fdisk_segment_ctl_queue failed; /**< The list of segments that failed
+ when being erased. */
+ rtems_id lock; /**< Mutex for threading protection.*/
+
+ uint8_t* copy_buffer; /**< Copy buf used during compacting */
+
+ uint32_t info_level; /**< The info trace level. */
+} rtems_flashdisk;
+
+/**
+ * The array of flash disks we support.
+ */
+static rtems_flashdisk* rtems_flashdisks;
+
+/**
+ * The number of flash disks we have.
+ */
+static uint32_t rtems_flashdisk_count;
+
+/**
+ * The CRC16 factor table. Created during initialisation.
+ */
+static uint16_t* rtems_fdisk_crc16_factor;
+
+/**
+ * Calculate the CRC16 checksum.
+ *
+ * @param _b The byte to checksum.
+ * @param _c The current checksum.
+ */
+#define rtems_fdisk_calc_crc16(_b, _c) \
+ rtems_fdisk_crc16_factor[((_b) ^ ((_c) & 0xff)) & 0xff] ^ (((_c) >> 8) & 0xff)
+
+/**
+ * Generate the CRC table.
+ *
+ * @param pattern The seed pattern for the table of factors.
+ * @relval RTEMS_SUCCESSFUL The table was generated.
+ * @retval RTEMS_NO_MEMORY The table could not be allocated from the heap.
+ */
+rtems_status_code
+rtems_fdisk_crc16_gen_factors (uint16_t pattern)
+{
+ uint32_t b;
+
+ rtems_fdisk_crc16_factor = malloc (sizeof (uint16_t) * 256);
+ if (!rtems_fdisk_crc16_factor)
+ return RTEMS_NO_MEMORY;
+
+ for (b = 0; b < 256; b++)
+ {
+ uint32_t i;
+ uint16_t v = b;
+ for (i = 8; i--;)
+ v = v & 1 ? (v >> 1) ^ pattern : v >> 1;
+ rtems_fdisk_crc16_factor[b] = v & 0xffff;
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+#if RTEMS_FDISK_TRACE
+/**
+ * Print a message to the flash disk output and flush it.
+ *
+ * @param fd The flashdisk control structure.
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_fdisk_printf (const rtems_flashdisk* fd, const char *format, ...)
+{
+ int ret = 0;
+ if (fd->info_level >= 3)
+ {
+ va_list args;
+ va_start (args, format);
+ fprintf (stdout, "fdisk:");
+ ret = vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ fflush (stdout);
+ va_end (args);
+ }
+ return ret;
+}
+
+/**
+ * Print a info message to the flash disk output and flush it.
+ *
+ * @param fd The flashdisk control structure.
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_fdisk_info (const rtems_flashdisk* fd, const char *format, ...)
+{
+ int ret = 0;
+ if (fd->info_level >= 2)
+ {
+ va_list args;
+ va_start (args, format);
+ fprintf (stdout, "fdisk:");
+ ret = vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ fflush (stdout);
+ va_end (args);
+ }
+ return ret;
+}
+
+/**
+ * Print a warning to the flash disk output and flush it.
+ *
+ * @param fd The flashdisk control structure.
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_fdisk_warning (const rtems_flashdisk* fd, const char *format, ...)
+{
+ int ret = 0;
+ if (fd->info_level >= 1)
+ {
+ va_list args;
+ va_start (args, format);
+ fprintf (stdout, "fdisk:warning:");
+ ret = vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ fflush (stdout);
+ va_end (args);
+ }
+ return ret;
+}
+#endif
+
+/**
+ * Print an error to the flash disk output and flush it.
+ *
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_fdisk_error (const char *format, ...)
+{
+ int ret;
+ va_list args;
+ va_start (args, format);
+ fprintf (stderr, "fdisk:error:");
+ ret = vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+ fflush (stderr);
+ va_end (args);
+ return ret;
+}
+
+/**
+ * Print an abort message, flush it then abort the program.
+ *
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ */
+static void
+rtems_fdisk_abort (const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+ fprintf (stderr, "fdisk:abort:");
+ vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+ fflush (stderr);
+ va_end (args);
+ exit (1);
+}
+
+/**
+ * Initialise the segment control queue.
+ */
+static void
+rtems_fdisk_segment_queue_init (rtems_fdisk_segment_ctl_queue* queue)
+{
+ queue->head = queue->tail = 0;
+ queue->count = 0;
+}
+
+/**
+ * Push to the head of the segment control queue.
+ */
+static void
+rtems_fdisk_segment_queue_push_head (rtems_fdisk_segment_ctl_queue* queue,
+ rtems_fdisk_segment_ctl* sc)
+{
+ if (sc)
+ {
+ sc->next = queue->head;
+ queue->head = sc;
+
+ if (queue->tail == 0)
+ queue->tail = sc;
+ queue->count++;
+ }
+}
+
+/**
+ * Pop the head of the segment control queue.
+ */
+static rtems_fdisk_segment_ctl*
+rtems_fdisk_segment_queue_pop_head (rtems_fdisk_segment_ctl_queue* queue)
+{
+ if (queue->head)
+ {
+ rtems_fdisk_segment_ctl* sc = queue->head;
+
+ queue->head = sc->next;
+ if (!queue->head)
+ queue->tail = 0;
+
+ queue->count--;
+
+ sc->next = 0;
+
+ return sc;
+ }
+
+ return 0;
+}
+
+/**
+ * Push to the tail of the segment control queue.
+ */
+static void
+rtems_fdisk_segment_queue_push_tail (rtems_fdisk_segment_ctl_queue* queue,
+ rtems_fdisk_segment_ctl* sc)
+{
+ if (sc)
+ {
+ sc->next = 0;
+
+ if (queue->head)
+ {
+ queue->tail->next = sc;
+ queue->tail = sc;
+ }
+ else
+ {
+ queue->head = queue->tail = sc;
+ }
+
+ queue->count++;
+ }
+}
+
+/**
+ * Remove from the segment control queue.
+ */
+static void
+rtems_fdisk_segment_queue_remove (rtems_fdisk_segment_ctl_queue* queue,
+ rtems_fdisk_segment_ctl* sc)
+{
+ rtems_fdisk_segment_ctl* prev = 0;
+ rtems_fdisk_segment_ctl* it = queue->head;
+
+ /*
+ * Do not change sc->next as sc could be on another queue.
+ */
+
+ while (it)
+ {
+ if (sc == it)
+ {
+ if (prev == 0)
+ {
+ queue->head = sc->next;
+ if (queue->head == 0)
+ queue->tail = 0;
+ }
+ else
+ {
+ prev->next = sc->next;
+ if (queue->tail == sc)
+ queue->tail = prev;
+ }
+ sc->next = 0;
+ queue->count--;
+ break;
+ }
+
+ prev = it;
+ it = it->next;
+ }
+}
+
+/**
+ * Insert into the segment control queue before the specific
+ * segment control item.
+ */
+static void
+rtems_fdisk_segment_queue_insert_before (rtems_fdisk_segment_ctl_queue* queue,
+ rtems_fdisk_segment_ctl* item,
+ rtems_fdisk_segment_ctl* sc)
+{
+ if (item)
+ {
+ rtems_fdisk_segment_ctl** prev = &queue->head;
+ rtems_fdisk_segment_ctl* it = queue->head;
+
+ while (it)
+ {
+ if (item == it)
+ {
+ sc->next = item;
+ *prev = sc;
+ queue->count++;
+ return;
+ }
+
+ prev = &it->next;
+ it = it->next;
+ }
+ }
+
+ rtems_fdisk_segment_queue_push_tail (queue, sc);
+}
+
+/**
+ * Count the number of elements on the list.
+ */
+static uint32_t
+rtems_fdisk_segment_queue_count (rtems_fdisk_segment_ctl_queue* queue)
+{
+ return queue->count;
+}
+
+/**
+ * Count the number of elements on the list.
+ */
+static uint32_t
+rtems_fdisk_segment_count_queue (rtems_fdisk_segment_ctl_queue* queue)
+{
+ rtems_fdisk_segment_ctl* sc = queue->head;
+ uint32_t count = 0;
+
+ while (sc)
+ {
+ count++;
+ sc = sc->next;
+ }
+
+ return count;
+}
+
+/**
+ * See if a segment control is present on this queue.
+ */
+static bool
+rtems_fdisk_segment_queue_present (rtems_fdisk_segment_ctl_queue* queue,
+ rtems_fdisk_segment_ctl* sc)
+{
+ rtems_fdisk_segment_ctl* it = queue->head;
+
+ while (it)
+ {
+ if (it == sc)
+ return true;
+ it = it->next;
+ }
+
+ return false;
+}
+
+/**
+ * Format a string with the queue status.
+ */
+static void
+rtems_fdisk_queue_status (rtems_flashdisk* fd,
+ rtems_fdisk_segment_ctl* sc,
+ char queues[5])
+{
+ queues[0] = rtems_fdisk_segment_queue_present (&fd->available, sc) ? 'A' : '-';
+ queues[1] = rtems_fdisk_segment_queue_present (&fd->used, sc) ? 'U' : '-';
+ queues[2] = rtems_fdisk_segment_queue_present (&fd->erase, sc) ? 'E' : '-';
+ queues[3] = rtems_fdisk_segment_queue_present (&fd->failed, sc) ? 'F' : '-';
+ queues[4] = '\0';
+}
+
+/**
+ * Check if the page descriptor is erased.
+ */
+static bool
+rtems_fdisk_page_desc_erased (const rtems_fdisk_page_desc* pd)
+{
+ return ((pd->crc == 0xffff) &&
+ (pd->flags == 0xffff) &&
+ (pd->block == 0xffffffff)) ? true : false;
+}
+
+/**
+ * Check if the flags are set. The flags are inverted as we can
+ * only set a flag by changing it from 1 to 0.
+ */
+static bool
+rtems_fdisk_page_desc_flags_set (rtems_fdisk_page_desc* pd, uint16_t flags)
+{
+ return (pd->flags & flags) == 0 ? true : false;
+}
+
+/**
+ * Check if the flags are clear. The flags are inverted as we can
+ * only set a flag by changing it from 1 to 0.
+ */
+static bool
+rtems_fdisk_page_desc_flags_clear (rtems_fdisk_page_desc* pd, uint16_t flags)
+{
+ return (pd->flags & flags) == flags ? true : false;
+}
+
+/**
+ * Set the flags. Setting means clear the bit to 0.
+ */
+static void
+rtems_fdisk_page_desc_set_flags (rtems_fdisk_page_desc* pd, uint16_t flags)
+{
+ pd->flags &= ~flags;
+}
+
+/**
+ * Get the segment descriptor for a device and segment. There are
+ * no range checks.
+ */
+static const rtems_fdisk_segment_desc*
+rtems_fdisk_seg_descriptor (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment)
+{
+ return fd->devices[device].segments[segment].descriptor;
+}
+
+/**
+ * Count the segments for a device.
+ */
+static uint32_t
+rtems_fdisk_count_segments (const rtems_fdisk_device_desc* dd)
+{
+ uint32_t count = 0;
+ uint32_t segment;
+ for (segment = 0; segment < dd->segment_count; segment++)
+ count += dd->segments[segment].count;
+ return count;
+}
+
+/**
+ * Calculate the pages in a segment give the segment size and the
+ * page size.
+ *
+ * @param sd The segment descriptor.
+ * @param page_size The page size in bytes.
+ */
+static uint32_t
+rtems_fdisk_pages_in_segment (const rtems_fdisk_segment_desc* sd,
+ uint32_t page_size)
+{
+ return sd->size / page_size;
+}
+
+/**
+ * Calculate the number of pages needed to hold the page descriptors.
+ * The calculation need to round up.
+ *
+ * The segment control contains the number of pages used as descriptors
+ * and should be used rather than this call where possible.
+ */
+static uint32_t
+rtems_fdisk_page_desc_pages (const rtems_fdisk_segment_desc* sd,
+ uint32_t page_size)
+{
+ uint32_t pages = rtems_fdisk_pages_in_segment (sd, page_size);
+ uint32_t bytes = pages * sizeof (rtems_fdisk_page_desc);
+ return ((bytes - 1) / page_size) + 1;
+}
+
+/**
+ * The number of available pages is the total pages less the
+ * active, used and bad pages.
+ */
+static uint32_t
+rtems_fdisk_seg_pages_available (const rtems_fdisk_segment_ctl* sc)
+{
+ return sc->pages - (sc->pages_active + sc->pages_used + sc->pages_bad);
+}
+/**
+ * Find the next available page in a segment.
+ */
+static uint32_t
+rtems_fdisk_seg_next_available_page (rtems_fdisk_segment_ctl* sc)
+{
+ rtems_fdisk_page_desc* pd = &sc->page_descriptors[0];
+ uint32_t page;
+
+ for (page = 0; page < sc->pages; page++, pd++)
+ if (rtems_fdisk_page_desc_erased (pd))
+ break;
+
+ return page;
+}
+
+/**
+ * Find the segment on the queue that has the most free pages.
+ */
+static rtems_fdisk_segment_ctl*
+rtems_fdisk_seg_most_available (const rtems_fdisk_segment_ctl_queue* queue)
+{
+ rtems_fdisk_segment_ctl* sc = queue->head;
+ rtems_fdisk_segment_ctl* biggest = queue->head;
+
+ while (sc)
+ {
+ if (rtems_fdisk_seg_pages_available (sc) >
+ rtems_fdisk_seg_pages_available (biggest))
+ biggest = sc;
+ sc = sc->next;
+ }
+
+ return biggest;
+}
+
+/**
+ * Is the segment all used ?
+ */
+#if 0
+static bool
+rtems_fdisk_seg_pages_all_used (const rtems_fdisk_segment_ctl* sc)
+{
+ return sc->pages == (sc->pages_used + sc->pages_bad) ? true : false;
+}
+#endif
+
+/**
+ * Calculate the blocks in a device. This is the number of
+ * pages less the pages hold page descriptors. This call be used
+ * early in the initialisation process and does not rely on
+ * the system being fully initialised.
+ *
+ * @param dd The device descriptor.
+ * @param page_size The page size in bytes.
+ */
+static uint32_t
+rtems_fdisk_blocks_in_device (const rtems_fdisk_device_desc* dd,
+ uint32_t page_size)
+{
+ uint32_t count = 0;
+ uint32_t s;
+ for (s = 0; s < dd->segment_count; s++)
+ {
+ const rtems_fdisk_segment_desc* sd = &dd->segments[s];
+ count +=
+ (rtems_fdisk_pages_in_segment (sd, page_size) -
+ rtems_fdisk_page_desc_pages (sd, page_size)) * sd->count;
+ }
+ return count;
+}
+
+/**
+ * Read a block of data from a segment.
+ */
+static int
+rtems_fdisk_seg_read (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ void* buffer,
+ uint32_t size)
+{
+ const rtems_fdisk_segment_desc* sd;
+ const rtems_fdisk_driver_handlers* ops;
+ sd = rtems_fdisk_seg_descriptor (fd, device, segment);
+ ops = fd->devices[device].descriptor->flash_ops;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " seg-read: %02d-%03d: o=%08x s=%d",
+ device, segment, offset, size);
+#endif
+ return ops->read (sd, device, segment, offset, buffer, size);
+}
+
+/**
+ * Write a block of data to a segment. It is assumed the
+ * location in the segment is erased and able to take the
+ * data.
+ */
+static int
+rtems_fdisk_seg_write (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ const void* buffer,
+ uint32_t size)
+{
+ const rtems_fdisk_segment_desc* sd;
+ const rtems_fdisk_driver_handlers* ops;
+ sd = rtems_fdisk_seg_descriptor (fd, device, segment);
+ ops = fd->devices[device].descriptor->flash_ops;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " seg-write: %02d-%03d: o=%08x s=%d",
+ device, segment, offset, size);
+#endif
+ return ops->write (sd, device, segment, offset, buffer, size);
+}
+
+/**
+ * Blank check the area of a segment.
+ */
+static int
+rtems_fdisk_seg_blank_check (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ uint32_t size)
+{
+ const rtems_fdisk_segment_desc* sd;
+ const rtems_fdisk_driver_handlers* ops;
+ sd = rtems_fdisk_seg_descriptor (fd, device, segment);
+ ops = fd->devices[device].descriptor->flash_ops;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " seg-blank: %02d-%03d: o=%08x s=%d",
+ device, segment, offset, size);
+#endif
+ return ops->blank (sd, device, segment, offset, size);
+}
+/**
+ * Verify the data with the data in a segment.
+ */
+static int
+rtems_fdisk_seg_verify (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t offset,
+ const void* buffer,
+ uint32_t size)
+{
+ const rtems_fdisk_segment_desc* sd;
+ const rtems_fdisk_driver_handlers* ops;
+ sd = rtems_fdisk_seg_descriptor (fd, device, segment);
+ ops = fd->devices[device].descriptor->flash_ops;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " seg-verify: %02d-%03d: o=%08x s=%d",
+ device, segment, offset, size);
+#endif
+ return ops->verify (sd, device, segment, offset, buffer, size);
+}
+
+/**
+ * Blank check a page of data in a segment.
+ */
+static int
+rtems_fdisk_seg_blank_check_page (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t page)
+{
+ return rtems_fdisk_seg_blank_check (fd, device, segment,
+ page * fd->block_size, fd->block_size);
+}
+
+/**
+ * Read a page of data from a segment.
+ */
+static int
+rtems_fdisk_seg_read_page (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t page,
+ void* buffer)
+{
+ return rtems_fdisk_seg_read (fd, device, segment,
+ page * fd->block_size, buffer, fd->block_size);
+}
+
+/**
+ * Write a page of data to a segment.
+ */
+static int
+rtems_fdisk_seg_write_page (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t page,
+ const void* buffer)
+{
+ if ((fd->flags & RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE))
+ {
+ int ret = rtems_fdisk_seg_blank_check_page (fd, device, segment, page);
+ if (ret)
+ return ret;
+ }
+ return rtems_fdisk_seg_write (fd, device, segment,
+ page * fd->block_size, buffer, fd->block_size);
+}
+
+/**
+ * Verify a page of data with the data in the segment.
+ */
+static int
+rtems_fdisk_seg_verify_page (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t page,
+ const void* buffer)
+{
+ return rtems_fdisk_seg_verify (fd, device, segment,
+ page * fd->block_size, buffer, fd->block_size);
+}
+
+/**
+ * Copy a page of data from one segment to another segment.
+ */
+static int
+rtems_fdisk_seg_copy_page (const rtems_flashdisk* fd,
+ uint32_t src_device,
+ uint32_t src_segment,
+ uint32_t src_page,
+ uint32_t dst_device,
+ uint32_t dst_segment,
+ uint32_t dst_page)
+{
+ int ret;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " seg-copy-page: %02d-%03d~%03d=>%02d-%03d~%03d",
+ src_device, src_segment, src_page,
+ dst_device, dst_segment, dst_page);
+#endif
+ ret = rtems_fdisk_seg_read_page (fd, src_device, src_segment, src_page,
+ fd->copy_buffer);
+ if (ret)
+ return ret;
+ return rtems_fdisk_seg_write_page (fd, dst_device, dst_segment, dst_page,
+ fd->copy_buffer);
+}
+
+/**
+ * Write the page descriptor to a segment. This code assumes the page
+ * descriptors are located at offset 0 in the segment.
+ */
+static int
+rtems_fdisk_seg_write_page_desc (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t page,
+ const rtems_fdisk_page_desc* page_desc)
+{
+ uint32_t offset = page * sizeof (rtems_fdisk_page_desc);
+ if ((fd->flags & RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE))
+ {
+ int ret = rtems_fdisk_seg_blank_check (fd, device, segment,
+ offset,
+ sizeof (rtems_fdisk_page_desc));
+ if (ret)
+ return ret;
+ }
+ return rtems_fdisk_seg_write (fd, device, segment, offset,
+ page_desc, sizeof (rtems_fdisk_page_desc));
+}
+
+/**
+ * Write the page descriptor flags to a segment. This code assumes the page
+ * descriptors are located at offset 0 in the segment.
+ */
+static int
+rtems_fdisk_seg_write_page_desc_flags (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment,
+ uint32_t page,
+ const rtems_fdisk_page_desc* page_desc)
+{
+ uint32_t offset = ((page * sizeof (rtems_fdisk_page_desc)) +
+ ((uint8_t*) &page_desc->flags) - ((uint8_t*) page_desc));
+ if ((fd->flags & RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE))
+ {
+ uint16_t flash_flags;
+ int ret;
+ ret = rtems_fdisk_seg_read (fd, device, segment, offset,
+ &flash_flags, sizeof (flash_flags));
+ if (ret)
+ return ret;
+ if ((flash_flags & page_desc->flags) != page_desc->flags)
+ {
+ rtems_fdisk_error (" seg-write-page-flags: %02d-%03d-%03d: " \
+ "flags not erased: 0x%04 -> 0x%04x",
+ device, segment, page, flash_flags, page_desc->flags);
+ return ret;
+ }
+ }
+ return rtems_fdisk_seg_write (fd, device, segment, offset,
+ &page_desc->flags, sizeof (page_desc->flags));
+}
+
+/**
+ * Erase a segment.
+ */
+static int
+rtems_fdisk_seg_erase (const rtems_flashdisk* fd,
+ uint32_t device,
+ uint32_t segment)
+{
+ const rtems_fdisk_segment_desc* sd;
+ const rtems_fdisk_driver_handlers* ops;
+ sd = rtems_fdisk_seg_descriptor (fd, device, segment);
+ ops = fd->devices[device].descriptor->flash_ops;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " seg-erase: %02d-%03d", device, segment);
+#endif
+ return ops->erase (sd, device, segment);
+}
+
+/**
+ * Erase a device.
+ */
+static int
+rtems_fdisk_device_erase (const rtems_flashdisk* fd, uint32_t device)
+{
+ const rtems_fdisk_driver_handlers* ops;
+ ops = fd->devices[device].descriptor->flash_ops;
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " device-erase: %02d", device);
+#endif
+ return ops->erase_device (fd->devices[device].descriptor, device);
+}
+
+/**
+ * Erase all flash.
+ */
+static int
+rtems_fdisk_erase_flash (const rtems_flashdisk* fd)
+{
+ uint32_t device;
+ for (device = 0; device < fd->device_count; device++)
+ {
+ int ret;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, " erase-flash:%02d", device);
+#endif
+
+ ret = rtems_fdisk_device_erase (fd, device);
+
+ if (ret != 0)
+ return ret;
+ }
+ return 0;
+}
+
+/**
+ * Calculate the checksum of a page in a segment.
+ */
+static uint16_t
+rtems_fdisk_page_checksum (const uint8_t* buffer, uint32_t page_size)
+{
+ uint16_t cs = 0xffff;
+ uint32_t i;
+
+ for (i = 0; i < page_size; i++, buffer++)
+ cs = rtems_fdisk_calc_crc16 (cs, *buffer);
+
+ return cs;
+}
+
+/**
+ * Erase the segment.
+ */
+static int
+rtems_fdisk_erase_segment (rtems_flashdisk* fd, rtems_fdisk_segment_ctl* sc)
+{
+ int ret = rtems_fdisk_seg_erase (fd, sc->device, sc->segment);
+ if (ret)
+ {
+ rtems_fdisk_error (" erase-segment:%02d-%03d: " \
+ "segment erase failed: %s (%d)",
+ sc->device, sc->segment, strerror (ret), ret);
+ sc->failed = true;
+ if (!rtems_fdisk_segment_queue_present (&fd->failed, sc))
+ rtems_fdisk_segment_queue_push_tail (&fd->failed, sc);
+ return ret;
+ }
+
+ sc->erased++;
+
+ memset (sc->page_descriptors, 0xff, sc->pages_desc * fd->block_size);
+
+ sc->pages_active = 0;
+ sc->pages_used = 0;
+ sc->pages_bad = 0;
+
+ sc->failed = false;
+
+ /*
+ * Push to the tail of the available queue. It is a very
+ * simple type of wear reduction. Every other available
+ * segment will now get a go.
+ */
+ rtems_fdisk_segment_queue_push_tail (&fd->available, sc);
+
+ return 0;
+}
+
+/**
+ * Erase used segment.
+ */
+static int
+rtems_fdisk_erase_used (rtems_flashdisk* fd)
+{
+ rtems_fdisk_segment_ctl* sc;
+ int latched_ret = 0;
+
+ while ((sc = rtems_fdisk_segment_queue_pop_head (&fd->erase)))
+ {
+ /*
+ * The segment will either end up on the available queue or
+ * the failed queue.
+ */
+ int ret = rtems_fdisk_erase_segment (fd, sc);
+ if (ret && !latched_ret)
+ latched_ret = ret;
+ }
+
+ return latched_ret;
+}
+
+/**
+ * Queue a segment. This is done after some of the stats for the segment
+ * have been changed and this may effect the order the segment pages have in
+ * the queue of available pages.
+ *
+ * @param fd The flash disk control table.
+ * @param sc The segment control table to be reallocated
+ */
+static void
+rtems_fdisk_queue_segment (rtems_flashdisk* fd, rtems_fdisk_segment_ctl* sc)
+{
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, " queue-seg:%02d-%03d: p=%d a=%d u=%d b=%d f=%s n=%s",
+ sc->device, sc->segment,
+ sc->pages, sc->pages_active, sc->pages_used, sc->pages_bad,
+ sc->failed ? "FAILED" : "no", sc->next ? "set" : "null");
+#endif
+
+ /*
+ * If the segment has failed then check the failed queue and append
+ * if not failed.
+ */
+ if (sc->failed)
+ {
+ if (!rtems_fdisk_segment_queue_present (&fd->failed, sc))
+ rtems_fdisk_segment_queue_push_tail (&fd->failed, sc);
+ return;
+ }
+
+ /*
+ * Remove the queue from the available or used queue.
+ */
+ rtems_fdisk_segment_queue_remove (&fd->available, sc);
+ rtems_fdisk_segment_queue_remove (&fd->used, sc);
+
+ /*
+ * Are all the pages in the segment used ?
+ * If they are and the driver has been configured to background
+ * erase place the segment on the used queue. If not configured
+ * to background erase perform the erase now.
+ *
+ */
+ if (rtems_fdisk_seg_pages_available (sc) == 0)
+ {
+ if (sc->pages_active)
+ {
+ /*
+ * Keep the used queue sorted by the most number of used
+ * pages. When we compact we want to move the pages into
+ * a new segment and cover more than one segment.
+ */
+ rtems_fdisk_segment_ctl* seg = fd->used.head;
+
+ while (seg)
+ {
+ if (sc->pages_used > seg->pages_used)
+ break;
+ seg = seg->next;
+ }
+
+ if (seg)
+ rtems_fdisk_segment_queue_insert_before (&fd->used, seg, sc);
+ else
+ rtems_fdisk_segment_queue_push_tail (&fd->used, sc);
+ }
+ else
+ {
+ if ((fd->flags & RTEMS_FDISK_BACKGROUND_ERASE))
+ rtems_fdisk_segment_queue_push_tail (&fd->erase, sc);
+ else
+ rtems_fdisk_erase_segment (fd, sc);
+ }
+ }
+ else
+ {
+ /*
+ * The segment has pages available so place back onto the
+ * available list. The list is sorted from the least number
+ * of available pages to the most. This approach means
+ * the pages of a partially filled segment will be filled
+ * before moving onto another emptier segment. This keeps
+ * empty segments longer aiding compaction.
+ *
+ * The down side is the wear effect as a single segment
+ * could be used more than segment. This will not be
+ * addressed until wear support is added.
+ *
+ * @note Wear support can be added by having counts for
+ * for the number of times a segment is erased. This
+ * available list is then sorted on the least number
+ * of available pages then empty segments are sorted
+ * on the least number of erases the segment has.
+ *
+ * The erase count can be stored in specially flaged
+ * pages and contain a counter (32bits?) and 32 bits
+ * for each segment. When a segment is erased a
+ * bit is cleared for that segment. When 32 erasers
+ * has occurred the page is re-written to the flash
+ * with all the counters updated with the number of
+ * bits cleared and all bits set back to 1.
+ */
+ rtems_fdisk_segment_ctl* seg = fd->available.head;
+
+ while (seg)
+ {
+ if (rtems_fdisk_seg_pages_available (sc) <
+ rtems_fdisk_seg_pages_available (seg))
+ break;
+ seg = seg->next;
+ }
+
+ if (seg)
+ rtems_fdisk_segment_queue_insert_before (&fd->available, seg, sc);
+ else
+ rtems_fdisk_segment_queue_push_tail (&fd->available, sc);
+ }
+}
+
+/**
+ * Compact the used segments to free what is available. Find the segment
+ * with the most avalable number of pages and see if we have
+ * used segments that will fit. The used queue is sorted on the least
+ * number of active pages.
+ */
+static int
+rtems_fdisk_compact (rtems_flashdisk* fd)
+{
+ uint32_t compacted_segs = 0;
+
+ while (fd->used.head)
+ {
+ rtems_fdisk_segment_ctl* dsc;
+ rtems_fdisk_segment_ctl* ssc;
+ uint32_t dst_pages;
+ uint32_t segments;
+ uint32_t pages;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " compacting");
+#endif
+
+ dsc = rtems_fdisk_seg_most_available (&fd->available);
+
+ if (dsc == 0)
+ {
+ rtems_fdisk_error ("compacting: no available segments to compact too");
+ return EIO;
+ }
+
+ ssc = fd->used.head;
+ dst_pages = rtems_fdisk_seg_pages_available (dsc);
+ segments = 0;
+ pages = 0;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " dsc:%02d-%03d: most available",
+ dsc->device, dsc->segment);
+#endif
+
+ /*
+ * Count the number of segments that have active pages that fit into
+ * the destination segment. Also limit the number of segments that
+ * we handle during one compaction. A lower number means less aggressive
+ * compaction or less delay when compacting but it may mean the disk
+ * will fill.
+ */
+
+ while (ssc &&
+ ((pages + ssc->pages_active) < dst_pages) &&
+ ((compacted_segs + segments) < fd->compact_segs))
+ {
+ pages += ssc->pages_active;
+ segments++;
+ ssc = ssc->next;
+ }
+
+ /*
+ * We need a source segment and have pages to copy and
+ * compacting one segment to another is silly. Compaction needs
+ * to free at least one more segment.
+ */
+
+ if (!ssc || (pages == 0) || ((compacted_segs + segments) == 1))
+ break;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, " ssc scan: %d-%d: p=%ld, seg=%ld",
+ ssc->device, ssc->segment,
+ pages, segments);
+#endif
+
+ rtems_fdisk_segment_queue_remove (&fd->available, dsc);
+
+ /*
+ * We now copy the pages to the new segment.
+ */
+
+ while (pages)
+ {
+ uint32_t spage;
+ int ret;
+
+ ssc = rtems_fdisk_segment_queue_pop_head (&fd->used);
+
+ if (ssc)
+ {
+ uint32_t used = 0;
+ uint32_t active = 0;
+ for (spage = 0; spage < ssc->pages; spage++)
+ {
+ rtems_fdisk_page_desc* spd = &ssc->page_descriptors[spage];
+
+ if (rtems_fdisk_page_desc_flags_set (spd, RTEMS_FDISK_PAGE_ACTIVE) &&
+ !rtems_fdisk_page_desc_flags_set (spd, RTEMS_FDISK_PAGE_USED))
+ {
+ rtems_fdisk_page_desc* dpd;
+ uint32_t dpage;
+
+ dpage = rtems_fdisk_seg_next_available_page (dsc);
+ dpd = &dsc->page_descriptors[dpage];
+
+ active++;
+
+ if (dpage >= dsc->pages)
+ {
+ rtems_fdisk_error ("compacting: %02d-%03d: " \
+ "no page desc available: %d",
+ dsc->device, dsc->segment,
+ rtems_fdisk_seg_pages_available (dsc));
+ dsc->failed = true;
+ rtems_fdisk_queue_segment (fd, dsc);
+ rtems_fdisk_segment_queue_push_head (&fd->used, ssc);
+ return EIO;
+ }
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "compacting: %02d-%03d-%03d=>%02d-%03d-%03d",
+ ssc->device, ssc->segment, spage,
+ dsc->device, dsc->segment, dpage);
+#endif
+ ret = rtems_fdisk_seg_copy_page (fd, ssc->device, ssc->segment,
+ spage + ssc->pages_desc,
+ dsc->device, dsc->segment,
+ dpage + dsc->pages_desc);
+ if (ret)
+ {
+ rtems_fdisk_error ("compacting: %02d-%03d-%03d=>" \
+ "%02d-%03d-%03d: " \
+ "copy page failed: %s (%d)",
+ ssc->device, ssc->segment, spage,
+ dsc->device, dsc->segment, dpage,
+ strerror (ret), ret);
+ dsc->failed = true;
+ rtems_fdisk_queue_segment (fd, dsc);
+ rtems_fdisk_segment_queue_push_head (&fd->used, ssc);
+ return ret;
+ }
+
+ *dpd = *spd;
+
+ ret = rtems_fdisk_seg_write_page_desc (fd,
+ dsc->device, dsc->segment,
+ dpage, dpd);
+
+ if (ret)
+ {
+ rtems_fdisk_error ("compacting: %02d-%03d-%03d=>" \
+ "%02d-%03d-%03d: copy pd failed: %s (%d)",
+ ssc->device, ssc->segment, spage,
+ dsc->device, dsc->segment, dpage,
+ strerror (ret), ret);
+ dsc->failed = true;
+ rtems_fdisk_queue_segment (fd, dsc);
+ rtems_fdisk_segment_queue_push_head (&fd->used, ssc);
+ return ret;
+ }
+
+ dsc->pages_active++;
+
+ /*
+ * No need to set the used bit on the source page as the
+ * segment will be erased. Power down could be a problem.
+ * We do the stats to make sure everything is as it should
+ * be.
+ */
+
+ ssc->pages_active--;
+ ssc->pages_used++;
+
+ fd->blocks[spd->block].segment = dsc;
+ fd->blocks[spd->block].page = dpage;
+
+ /*
+ * Place the segment on to the correct queue.
+ */
+ rtems_fdisk_queue_segment (fd, dsc);
+
+ pages--;
+ }
+ else
+ used++;
+ }
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_printf (fd, "ssc end: %d-%d: p=%ld, a=%ld, u=%ld",
+ ssc->device, ssc->segment,
+ pages, active, used);
+#endif
+ if (ssc->pages_active != 0)
+ {
+ rtems_fdisk_error ("compacting: ssc pages not 0: %d",
+ ssc->pages_active);
+ }
+
+ ret = rtems_fdisk_erase_segment (fd, ssc);
+
+ if (ret)
+ return ret;
+ }
+ }
+
+ compacted_segs += segments;
+ }
+
+ return 0;
+}
+
+/**
+ * Recover the block mappings from the devices.
+ */
+static int
+rtems_fdisk_recover_block_mappings (rtems_flashdisk* fd)
+{
+ uint32_t device;
+
+ /*
+ * Clear the queues.
+ */
+ rtems_fdisk_segment_queue_init (&fd->available);
+ rtems_fdisk_segment_queue_init (&fd->used);
+ rtems_fdisk_segment_queue_init (&fd->erase);
+ rtems_fdisk_segment_queue_init (&fd->failed);
+
+ /*
+ * Clear the lock mappings.
+ */
+ memset (fd->blocks, 0, fd->block_count * sizeof (rtems_fdisk_block_ctl));
+
+ /*
+ * Scan each segment or each device recovering the valid pages.
+ */
+ for (device = 0; device < fd->device_count; device++)
+ {
+ uint32_t segment;
+ for (segment = 0; segment < fd->devices[device].segment_count; segment++)
+ {
+ rtems_fdisk_segment_ctl* sc = &fd->devices[device].segments[segment];
+ const rtems_fdisk_segment_desc* sd = sc->descriptor;
+ rtems_fdisk_page_desc* pd;
+ uint32_t page;
+ int ret;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "recover-block-mappings:%02d-%03d", device, segment);
+#endif
+
+ sc->pages_desc = rtems_fdisk_page_desc_pages (sd, fd->block_size);
+ sc->pages =
+ rtems_fdisk_pages_in_segment (sd, fd->block_size) - sc->pages_desc;
+
+ sc->pages_active = 0;
+ sc->pages_used = 0;
+ sc->pages_bad = 0;
+
+ sc->failed = false;
+
+ if (!sc->page_descriptors)
+ sc->page_descriptors = malloc (sc->pages_desc * fd->block_size);
+
+ if (!sc->page_descriptors)
+ rtems_fdisk_abort ("no memory for page descriptors");
+
+ pd = sc->page_descriptors;
+
+ /*
+ * The page descriptors are always at the start of the segment. Read
+ * the descriptors off the device into the segment control page
+ * descriptors.
+ *
+ * @todo It may be better to ask the driver to get these value
+ * so NAND flash could be better supported.
+ */
+ ret = rtems_fdisk_seg_read (fd, device, segment, 0, (void*) pd,
+ sc->pages_desc * fd->block_size);
+
+ if (ret)
+ {
+ rtems_fdisk_error ("recover-block-mappings:%02d-%03d: " \
+ "read page desc failed: %s (%d)",
+ device, segment, strerror (ret), ret);
+ return ret;
+ }
+
+ /*
+ * Check each page in the segement for valid pages.
+ * Update the stats for the segment so we know how many pages
+ * are active and how many are used.
+ *
+ * If the page is active see if the block is with-in range and
+ * if the block is a duplicate.
+ */
+ for (page = 0; page < sc->pages; page++, pd++)
+ {
+ if (rtems_fdisk_page_desc_erased (pd))
+ {
+ /*
+ * Is the page erased ?
+ */
+ ret = rtems_fdisk_seg_blank_check_page (fd, device, segment,
+ page + sc->pages_desc);
+
+ if (ret)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_warning (fd, "page not blank: %d-%d-%d",
+ device, segment, page, pd->block);
+#endif
+ rtems_fdisk_page_desc_set_flags (pd, RTEMS_FDISK_PAGE_USED);
+
+ ret = rtems_fdisk_seg_write_page_desc (fd, device, segment,
+ page, pd);
+
+ if (ret)
+ {
+ rtems_fdisk_error ("forcing page to used failed: %d-%d-%d",
+ device, segment, page);
+ sc->failed = true;
+ }
+
+ sc->pages_used++;
+ }
+ }
+ else
+ {
+ if (rtems_fdisk_page_desc_flags_set (pd, RTEMS_FDISK_PAGE_USED))
+ {
+ sc->pages_used++;
+ }
+ else if (rtems_fdisk_page_desc_flags_set (pd, RTEMS_FDISK_PAGE_ACTIVE))
+ {
+ if (pd->block >= fd->block_count)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_warning (fd,
+ "invalid block number: %d-%d-%d: block: %d",
+ device, segment, page, pd->block);
+#endif
+ sc->pages_bad++;
+ }
+ else if (fd->blocks[pd->block].segment)
+ {
+ /**
+ * @todo
+ * This may need more work later. Maybe a counter is stored with
+ * each block so we can tell which is the later block when
+ * duplicates appear. A power down with a failed wirte could cause
+ * a duplicate.
+ */
+ const rtems_fdisk_segment_ctl* bsc = fd->blocks[pd->block].segment;
+ rtems_fdisk_error ("duplicate block: %d-%d-%d: " \
+ "duplicate: %d-%d-%d",
+ bsc->device, bsc->segment,
+ fd->blocks[pd->block].page,
+ device, segment, page);
+ sc->pages_bad++;
+ }
+ else
+ {
+ /**
+ * @todo
+ * Add start up crc checks here.
+ */
+ fd->blocks[pd->block].segment = sc;
+ fd->blocks[pd->block].page = page;
+
+ /*
+ * The page is active.
+ */
+ sc->pages_active++;
+ }
+ }
+ else
+ sc->pages_bad++;
+ }
+ }
+
+ /*
+ * Place the segment on to the correct queue.
+ */
+ rtems_fdisk_queue_segment (fd, sc);
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * Read a block. The block is checked to see if the page referenced
+ * is valid and the page has a valid crc.
+ *
+ * @param fd The rtems_flashdisk control table.
+ * @param block The block number to read.
+ * @param buffer The buffer to write the data into.
+ * @return 0 No error.
+ * @return EIO Invalid block size, block number, segment pointer, crc,
+ * page flags.
+ */
+static bool
+rtems_fdisk_read_block (rtems_flashdisk* fd,
+ uint32_t block,
+ uint8_t* buffer)
+{
+ rtems_fdisk_block_ctl* bc;
+ rtems_fdisk_segment_ctl* sc;
+ rtems_fdisk_page_desc* pd;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "read-block:%d", block);
+#endif
+
+ /*
+ * Broken out to allow info messages when testing.
+ */
+
+ if (block >= (fd->block_count - fd->unavail_blocks))
+ {
+ rtems_fdisk_error ("read-block: block out of range: %d", block);
+ return EIO;
+ }
+
+ bc = &fd->blocks[block];
+
+ if (!bc->segment)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "read-block: no segment mapping: %d", block);
+#endif
+ memset (buffer, fd->block_size, 0xff);
+ return 0;
+ }
+
+ sc = fd->blocks[block].segment;
+ pd = &sc->page_descriptors[bc->page];
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd,
+ " read:%d=>%02d-%03d-%03d: p=%d a=%d u=%d b=%d n=%s: " \
+ "f=%04x c=%04x b=%d",
+ block, sc->device, sc->segment, bc->page,
+ sc->pages, sc->pages_active, sc->pages_used, sc->pages_bad,
+ sc->next ? "set" : "null",
+ pd->flags, pd->crc, pd->block);
+#endif
+
+ if (rtems_fdisk_page_desc_flags_set (pd, RTEMS_FDISK_PAGE_ACTIVE))
+ {
+ if (rtems_fdisk_page_desc_flags_clear (pd, RTEMS_FDISK_PAGE_USED))
+ {
+ uint16_t cs;
+
+ /*
+ * We use the segment page offset not the page number used in the
+ * driver. This skips the page descriptors.
+ */
+ int ret = rtems_fdisk_seg_read_page (fd, sc->device, sc->segment,
+ bc->page + sc->pages_desc, buffer);
+
+ if (ret)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd,
+ "read-block:%02d-%03d-%03d: read page failed: %s (%d)",
+ sc->device, sc->segment, bc->page,
+ strerror (ret), ret);
+#endif
+ return ret;
+ }
+
+ cs = rtems_fdisk_page_checksum (buffer, fd->block_size);
+
+ if (cs == pd->crc)
+ return 0;
+
+ rtems_fdisk_error ("read-block: crc failure: %d: buffer:%04x page:%04x",
+ block, cs, pd->crc);
+ }
+ else
+ {
+ rtems_fdisk_error ("read-block: block points to used page: %d: %d-%d-%d",
+ block, sc->device, sc->segment, bc->page);
+ }
+ }
+ else
+ {
+ rtems_fdisk_error ("read-block: block page not active: %d: %d-%d-%d",
+ block, sc->device, sc->segment, bc->page);
+ }
+
+ return EIO;
+}
+
+/**
+ * Write a block. The block:
+ *
+ * # May never have existed in flash before this write.
+ * # Exists and needs to be moved to a new page.
+ *
+ * If the block does not exist in flash we need to get the next
+ * segment available to place the page into. The segments with
+ * available pages are held on the avaliable list sorted on least
+ * number of available pages as the primary key. Currently there
+ * is no secondary key. Empty segments are at the end of the list.
+ *
+ * If the block already exists we need to set the USED bit in the
+ * current page's flags. This is a single byte which changes a 1 to
+ * a 0 and can be done with a single 16 bit write. The driver for
+ * 8 bit devices should only attempt the write on the changed bit.
+ *
+ * @param fd The rtems_flashdisk control table.
+ * @param block The block number to read.
+ * @param block_size The size of the block. Must match what we have.
+ * @param buffer The buffer to write the data into.
+ * @return 0 No error.
+ * @return EIO Invalid block size, block number, segment pointer, crc,
+ * page flags.
+ */
+static int
+rtems_fdisk_write_block (rtems_flashdisk* fd,
+ uint32_t block,
+ const uint8_t* buffer)
+{
+ rtems_fdisk_block_ctl* bc;
+ rtems_fdisk_segment_ctl* sc;
+ rtems_fdisk_page_desc* pd;
+ uint32_t page;
+ int ret;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "write-block:%d", block);
+#endif
+
+ /*
+ * Broken out to allow info messages when testing.
+ */
+
+ if (block >= (fd->block_count - fd->unavail_blocks))
+ {
+ rtems_fdisk_error ("write-block: block out of range: %d", block);
+ return EIO;
+ }
+
+ bc = &fd->blocks[block];
+
+ /*
+ * Does the page exist in flash ?
+ */
+ if (bc->segment)
+ {
+ sc = bc->segment;
+ pd = &sc->page_descriptors[bc->page];
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, " write:%02d-%03d-%03d: flag used",
+ sc->device, sc->segment, bc->page);
+#endif
+
+ /*
+ * The page exists in flash so see if the page has been changed.
+ */
+ if (rtems_fdisk_seg_verify_page (fd, sc->device, sc->segment,
+ bc->page + sc->pages_desc, buffer) == 0)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "write-block:%d=>%02d-%03d-%03d: page verified",
+ block, sc->device, sc->segment, bc->page);
+#endif
+ return 0;
+ }
+
+ /*
+ * The page exists in flash so we need to set the used flag
+ * in the page descriptor. The descriptor is in memory with the
+ * segment control block. We can assume this memory copy
+ * matches the flash device.
+ */
+
+ rtems_fdisk_page_desc_set_flags (pd, RTEMS_FDISK_PAGE_USED);
+
+ ret = rtems_fdisk_seg_write_page_desc_flags (fd, sc->device, sc->segment,
+ bc->page, pd);
+
+ if (ret)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, " write:%02d-%03d-%03d: " \
+ "write used page desc failed: %s (%d)",
+ sc->device, sc->segment, bc->page,
+ strerror (ret), ret);
+#endif
+ sc->failed = true;
+ }
+ else
+ {
+ sc->pages_active--;
+ sc->pages_used++;
+ }
+
+ /*
+ * If possible reuse this segment. This will mean the segment
+ * needs to be removed from the available list and placed
+ * back if space is still available.
+ */
+ rtems_fdisk_queue_segment (fd, sc);
+
+ /*
+ * If no background compacting then compact in the forground.
+ * If we compact we ignore the error as there is little we
+ * can do from here. The write may will work.
+ */
+ if ((fd->flags & RTEMS_FDISK_BACKGROUND_COMPACT) == 0)
+ rtems_fdisk_compact (fd);
+ }
+
+ /*
+ * Is it time to compact the disk ?
+ *
+ * We override the background compaction configruation.
+ */
+ if (rtems_fdisk_segment_count_queue (&fd->available) <=
+ fd->avail_compact_segs)
+ rtems_fdisk_compact (fd);
+
+ /*
+ * Get the next avaliable segment.
+ */
+ sc = rtems_fdisk_segment_queue_pop_head (&fd->available);
+
+ /*
+ * Is the flash disk full ?
+ */
+ if (!sc)
+ {
+ /*
+ * If compacting is configured for the background do it now
+ * to see if we can get some space back.
+ */
+ if ((fd->flags & RTEMS_FDISK_BACKGROUND_COMPACT))
+ rtems_fdisk_compact (fd);
+
+ /*
+ * Try again for some free space.
+ */
+ sc = rtems_fdisk_segment_queue_pop_head (&fd->available);
+
+ if (!sc)
+ {
+ rtems_fdisk_error ("write-block: no available pages");
+ return ENOSPC;
+ }
+ }
+
+#if RTEMS_FDISK_TRACE
+ if (fd->info_level >= 3)
+ {
+ char queues[5];
+ rtems_fdisk_queue_status (fd, sc, queues);
+ rtems_fdisk_info (fd, " write:%d=>%02d-%03d: queue check: %s",
+ block, sc->device, sc->segment, queues);
+ }
+#endif
+
+ /*
+ * Find the next avaliable page in the segment.
+ */
+
+ pd = sc->page_descriptors;
+
+ for (page = 0; page < sc->pages; page++, pd++)
+ {
+ if (rtems_fdisk_page_desc_erased (pd))
+ {
+ pd->crc = rtems_fdisk_page_checksum (buffer, fd->block_size);
+ pd->block = block;
+
+ bc->segment = sc;
+ bc->page = page;
+
+ rtems_fdisk_page_desc_set_flags (pd, RTEMS_FDISK_PAGE_ACTIVE);
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, " write:%d=>%02d-%03d-%03d: write: " \
+ "p=%d a=%d u=%d b=%d n=%s: f=%04x c=%04x b=%d",
+ block, sc->device, sc->segment, page,
+ sc->pages, sc->pages_active, sc->pages_used,
+ sc->pages_bad, sc->next ? "set" : "null",
+ pd->flags, pd->crc, pd->block);
+#endif
+
+ /*
+ * We use the segment page offset not the page number used in the
+ * driver. This skips the page descriptors.
+ */
+ ret = rtems_fdisk_seg_write_page (fd, sc->device, sc->segment,
+ page + sc->pages_desc, buffer);
+ if (ret)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "write-block:%02d-%03d-%03d: write page failed: " \
+ "%s (%d)", sc->device, sc->segment, page,
+ strerror (ret), ret);
+#endif
+ sc->failed = true;
+ }
+ else
+ {
+ ret = rtems_fdisk_seg_write_page_desc (fd, sc->device, sc->segment,
+ page, pd);
+ if (ret)
+ {
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "write-block:%02d-%03d-%03d: " \
+ "write page desc failed: %s (%d)",
+ sc->device, sc->segment, bc->page,
+ strerror (ret), ret);
+#endif
+ sc->failed = true;
+ }
+ else
+ {
+ sc->pages_active++;
+ }
+ }
+
+ rtems_fdisk_queue_segment (fd, sc);
+ return ret;
+ }
+ }
+
+ rtems_fdisk_error ("write-block: no erased page descs in segment: %d-%d",
+ sc->device, sc->segment);
+
+ sc->failed = true;
+ rtems_fdisk_queue_segment (fd, sc);
+
+ return EIO;
+}
+
+/**
+ * Disk READ request handler. This primitive copies data from the
+ * flash disk to the supplied buffer and invoke the callout function
+ * to inform upper layer that reading is completed.
+ *
+ * @param req Pointer to the READ block device request info.
+ * @retval int The ioctl return value.
+ */
+static int
+rtems_fdisk_read (rtems_flashdisk* fd, rtems_blkdev_request* req)
+{
+ rtems_blkdev_sg_buffer* sg = req->bufs;
+ uint32_t buf;
+ int ret = 0;
+
+ for (buf = 0; (ret == 0) && (buf < req->bufnum); buf++, sg++)
+ {
+ uint8_t* data;
+ uint32_t fb;
+ uint32_t b;
+ fb = sg->length / fd->block_size;
+ data = sg->buffer;
+ for (b = 0; b < fb; b++, data += fd->block_size)
+ {
+ ret = rtems_fdisk_read_block (fd, sg->block + b, data);
+ if (ret)
+ break;
+ }
+ }
+
+ req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
+ req->req_done (req->done_arg, req->status);
+
+ return ret;
+}
+
+/**
+ * Flash disk WRITE request handler. This primitive copies data from
+ * supplied buffer to flash disk and invoke the callout function to inform
+ * upper layer that writing is completed.
+ *
+ * @param req Pointers to the WRITE block device request info.
+ * @retval int The ioctl return value.
+ */
+static int
+rtems_fdisk_write (rtems_flashdisk* fd, rtems_blkdev_request* req)
+{
+ rtems_blkdev_sg_buffer* sg = req->bufs;
+ uint32_t buf;
+ int ret = 0;
+
+ for (buf = 0; (ret == 0) && (buf < req->bufnum); buf++, sg++)
+ {
+ uint8_t* data;
+ uint32_t fb;
+ uint32_t b;
+ fb = sg->length / fd->block_size;
+ data = sg->buffer;
+ for (b = 0; b < fb; b++, data += fd->block_size)
+ {
+ ret = rtems_fdisk_write_block (fd, sg->block + b, data);
+ if (ret)
+ break;
+ }
+ }
+
+ req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
+ req->req_done (req->done_arg, req->status);
+
+ return 0;
+}
+
+/**
+ * Flash disk erase disk.
+ *
+ * @param fd The flashdisk data.
+ * @retval int The ioctl return value.
+ */
+static int
+rtems_fdisk_erase_disk (rtems_flashdisk* fd)
+{
+ uint32_t device;
+ int ret;
+
+#if RTEMS_FDISK_TRACE
+ rtems_fdisk_info (fd, "erase-disk");
+#endif
+
+ ret = rtems_fdisk_erase_flash (fd);
+
+ if (ret == 0)
+ {
+ for (device = 0; device < fd->device_count; device++)
+ {
+ if (!fd->devices[device].segments)
+ return ENOMEM;
+
+ ret = rtems_fdisk_recover_block_mappings (fd);
+ if (ret)
+ break;
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * Flash Disk Monitoring data is return in the monitoring data
+ * structure.
+ */
+static int
+rtems_fdisk_monitoring_data (rtems_flashdisk* fd,
+ rtems_fdisk_monitor_data* data)
+{
+ uint32_t i;
+ uint32_t j;
+
+ data->block_size = fd->block_size;
+ data->block_count = fd->block_count;
+ data->unavail_blocks = fd->unavail_blocks;
+ data->device_count = fd->device_count;
+
+ data->blocks_used = 0;
+ for (i = 0; i < fd->block_count; i++)
+ if (fd->blocks[i].segment)
+ data->blocks_used++;
+
+ data->segs_available = rtems_fdisk_segment_count_queue (&fd->available);
+ data->segs_used = rtems_fdisk_segment_count_queue (&fd->used);
+ data->segs_failed = rtems_fdisk_segment_count_queue (&fd->failed);
+
+ data->segment_count = 0;
+ data->page_count = 0;
+ data->pages_desc = 0;
+ data->pages_active = 0;
+ data->pages_used = 0;
+ data->pages_bad = 0;
+ data->seg_erases = 0;
+
+ for (i = 0; i < fd->device_count; i++)
+ {
+ data->segment_count += fd->devices[i].segment_count;
+
+ for (j = 0; j < fd->devices[i].segment_count; j++)
+ {
+ rtems_fdisk_segment_ctl* sc = &fd->devices[i].segments[j];
+
+ data->page_count += sc->pages;
+ data->pages_desc += sc->pages_desc;
+ data->pages_active += sc->pages_active;
+ data->pages_used += sc->pages_used;
+ data->pages_bad += sc->pages_bad;
+ data->seg_erases += sc->erased;
+ }
+ }
+
+ data->info_level = fd->info_level;
+ return 0;
+}
+
+/**
+ * Print to stdout the status of the driver. This is a debugging aid.
+ */
+static int
+rtems_fdisk_print_status (rtems_flashdisk* fd)
+{
+#if RTEMS_FDISK_TRACE
+ uint32_t current_info_level = fd->info_level;
+ uint32_t total;
+ uint32_t count;
+ uint32_t device;
+
+ fd->info_level = 3;
+
+ rtems_fdisk_printf (fd,
+ "Flash Disk Driver Status : %d.%d", fd->major, fd->minor);
+
+ rtems_fdisk_printf (fd, "Block count\t%d", fd->block_count);
+ rtems_fdisk_printf (fd, "Unavail blocks\t%d", fd->unavail_blocks);
+ count = rtems_fdisk_segment_count_queue (&fd->available);
+ total = count;
+ rtems_fdisk_printf (fd, "Available queue\t%ld (%ld)",
+ count, rtems_fdisk_segment_queue_count (&fd->available));
+ count = rtems_fdisk_segment_count_queue (&fd->used);
+ total += count;
+ rtems_fdisk_printf (fd, "Used queue\t%ld (%ld)",
+ count, rtems_fdisk_segment_queue_count (&fd->used));
+ count = rtems_fdisk_segment_count_queue (&fd->erase);
+ total += count;
+ rtems_fdisk_printf (fd, "Erase queue\t%ld (%ld)",
+ count, rtems_fdisk_segment_queue_count (&fd->erase));
+ count = rtems_fdisk_segment_count_queue (&fd->failed);
+ total += count;
+ rtems_fdisk_printf (fd, "Failed queue\t%ld (%ld)",
+ count, rtems_fdisk_segment_queue_count (&fd->failed));
+
+ count = 0;
+ for (device = 0; device < fd->device_count; device++)
+ count += fd->devices[device].segment_count;
+
+ rtems_fdisk_printf (fd, "Queue total\t%ld of %ld, %s", total, count,
+ total == count ? "ok" : "MISSING");
+
+ rtems_fdisk_printf (fd, "Device count\t%d", fd->device_count);
+
+ for (device = 0; device < fd->device_count; device++)
+ {
+ uint32_t block;
+ uint32_t seg;
+
+ rtems_fdisk_printf (fd, " Device\t\t%ld", device);
+ rtems_fdisk_printf (fd, " Segment count\t%ld",
+ fd->devices[device].segment_count);
+
+ for (seg = 0; seg < fd->devices[device].segment_count; seg++)
+ {
+ rtems_fdisk_segment_ctl* sc = &fd->devices[device].segments[seg];
+ uint32_t page;
+ uint32_t erased = 0;
+ uint32_t active = 0;
+ uint32_t used = 0;
+ bool is_active = false;
+ char queues[5];
+
+ rtems_fdisk_queue_status (fd, sc, queues);
+
+ for (page = 0; page < sc->pages; page++)
+ {
+ if (rtems_fdisk_page_desc_erased (&sc->page_descriptors[page]))
+ erased++;
+ else if (rtems_fdisk_page_desc_flags_set (&sc->page_descriptors[page],
+ RTEMS_FDISK_PAGE_ACTIVE))
+ {
+ if (rtems_fdisk_page_desc_flags_set (&sc->page_descriptors[page],
+ RTEMS_FDISK_PAGE_USED))
+ used++;
+ else
+ {
+ active++;
+ is_active = true;
+ }
+ }
+
+ for (block = 0; block < fd->block_count; block++)
+ {
+ if ((fd->blocks[block].segment == sc) &&
+ (fd->blocks[block].page == page) && !is_active)
+ rtems_fdisk_printf (fd,
+ " %ld\t not active when mapped by block %ld",
+ page, block);
+ }
+ }
+
+ count = 0;
+ for (block = 0; block < fd->block_count; block++)
+ {
+ if (fd->blocks[block].segment == sc)
+ count++;
+ }
+
+ rtems_fdisk_printf (fd, " %3ld %s p:%3ld a:%3ld/%3ld" \
+ " u:%3ld/%3ld e:%3ld/%3ld br:%ld",
+ seg, queues,
+ sc->pages, sc->pages_active, active,
+ sc->pages_used, used, erased,
+ sc->pages - (sc->pages_active +
+ sc->pages_used + sc->pages_bad),
+ count);
+ }
+ }
+
+ {
+ rtems_fdisk_segment_ctl* sc = fd->used.head;
+ int count = 0;
+ rtems_fdisk_printf (fd, "Used List:");
+ while (sc)
+ {
+ rtems_fdisk_printf (fd, " %3d %02d:%03d u:%3ld",
+ count, sc->device, sc->segment, sc->pages_used);
+ sc = sc->next;
+ count++;
+ }
+ }
+ fd->info_level = current_info_level;
+
+ return 0;
+#else
+ return ENOSYS;
+#endif
+}
+
+/**
+ * Flash disk IOCTL handler.
+ *
+ * @param dd Disk device.
+ * @param req IOCTL request code.
+ * @param argp IOCTL argument.
+ * @retval The IOCTL return value
+ */
+static int
+rtems_fdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
+{
+ dev_t dev = rtems_disk_get_device_identifier (dd);
+ rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
+ rtems_blkdev_request* r = argp;
+ rtems_status_code sc;
+
+ errno = 0;
+
+ sc = rtems_semaphore_obtain (rtems_flashdisks[minor].lock, RTEMS_WAIT, 0);
+ if (sc != RTEMS_SUCCESSFUL)
+ errno = EIO;
+ else
+ {
+ errno = 0;
+ switch (req)
+ {
+ case RTEMS_BLKIO_REQUEST:
+ if ((minor >= rtems_flashdisk_count) ||
+ (rtems_flashdisks[minor].device_count == 0))
+ {
+ errno = ENODEV;
+ }
+ else
+ {
+ switch (r->req)
+ {
+ case RTEMS_BLKDEV_REQ_READ:
+ errno = rtems_fdisk_read (&rtems_flashdisks[minor], r);
+ break;
+
+ case RTEMS_BLKDEV_REQ_WRITE:
+ errno = rtems_fdisk_write (&rtems_flashdisks[minor], r);
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+ }
+ break;
+
+ case RTEMS_FDISK_IOCTL_ERASE_DISK:
+ errno = rtems_fdisk_erase_disk (&rtems_flashdisks[minor]);
+ break;
+
+ case RTEMS_FDISK_IOCTL_COMPACT:
+ errno = rtems_fdisk_compact (&rtems_flashdisks[minor]);
+ break;
+
+ case RTEMS_FDISK_IOCTL_ERASE_USED:
+ errno = rtems_fdisk_erase_used (&rtems_flashdisks[minor]);
+ break;
+
+ case RTEMS_FDISK_IOCTL_MONITORING:
+ errno = rtems_fdisk_monitoring_data (&rtems_flashdisks[minor],
+ (rtems_fdisk_monitor_data*) argp);
+ break;
+
+ case RTEMS_FDISK_IOCTL_INFO_LEVEL:
+ rtems_flashdisks[minor].info_level = (uintptr_t) argp;
+ break;
+
+ case RTEMS_FDISK_IOCTL_PRINT_STATUS:
+ errno = rtems_fdisk_print_status (&rtems_flashdisks[minor]);
+ break;
+
+ default:
+ rtems_blkdev_ioctl (dd, req, argp);
+ break;
+ }
+
+ sc = rtems_semaphore_release (rtems_flashdisks[minor].lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ errno = EIO;
+ }
+
+ return errno == 0 ? 0 : -1;
+}
+
+/**
+ * Flash disk device driver initialization.
+ *
+ * @todo Memory clean up on error is really badly handled.
+ *
+ * @param major Flash disk major device number.
+ * @param minor Minor device number, not applicable.
+ * @param arg Initialization argument, not applicable.
+ */
+rtems_device_driver
+rtems_fdisk_initialize (rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void* arg __attribute__((unused)))
+{
+ const rtems_flashdisk_config* c = rtems_flashdisk_configuration;
+ rtems_flashdisk* fd;
+ rtems_status_code sc;
+
+ sc = rtems_disk_io_initialize ();
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ sc = rtems_fdisk_crc16_gen_factors (0x8408);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ rtems_flashdisks = calloc (rtems_flashdisk_configuration_size,
+ sizeof (rtems_flashdisk));
+
+ if (!rtems_flashdisks)
+ return RTEMS_NO_MEMORY;
+
+ for (minor = 0; minor < rtems_flashdisk_configuration_size; minor++, c++)
+ {
+ char name[] = RTEMS_FLASHDISK_DEVICE_BASE_NAME "a";
+ dev_t dev = rtems_filesystem_make_dev_t (major, minor);
+ uint32_t device;
+ uint32_t blocks = 0;
+ int ret;
+
+ fd = &rtems_flashdisks[minor];
+
+ name [sizeof(RTEMS_FLASHDISK_DEVICE_BASE_NAME)] += minor;
+
+ fd->major = major;
+ fd->minor = minor;
+ fd->flags = c->flags;
+ fd->compact_segs = c->compact_segs;
+ fd->avail_compact_segs = c->avail_compact_segs;
+ fd->block_size = c->block_size;
+ fd->unavail_blocks = c->unavail_blocks;
+ fd->info_level = c->info_level;
+
+ for (device = 0; device < c->device_count; device++)
+ blocks += rtems_fdisk_blocks_in_device (&c->devices[device],
+ c->block_size);
+
+ /*
+ * One copy buffer of a page size.
+ */
+ fd->copy_buffer = malloc (c->block_size);
+ if (!fd->copy_buffer)
+ return RTEMS_NO_MEMORY;
+
+ fd->blocks = calloc (blocks, sizeof (rtems_fdisk_block_ctl));
+ if (!fd->blocks)
+ return RTEMS_NO_MEMORY;
+
+ fd->block_count = blocks;
+
+ fd->devices = calloc (c->device_count, sizeof (rtems_fdisk_device_ctl));
+ if (!fd->devices)
+ return RTEMS_NO_MEMORY;
+
+ sc = rtems_semaphore_create (rtems_build_name ('F', 'D', 'S', 'K'), 1,
+ RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE |
+ RTEMS_INHERIT_PRIORITY, 0, &fd->lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_fdisk_error ("disk lock create failed");
+ free (fd->copy_buffer);
+ free (fd->blocks);
+ free (fd->devices);
+ return sc;
+ }
+
+ sc = rtems_disk_create_phys(dev, c->block_size,
+ blocks - fd->unavail_blocks,
+ rtems_fdisk_ioctl, NULL, name);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_semaphore_delete (fd->lock);
+ rtems_disk_delete (dev);
+ free (fd->copy_buffer);
+ free (fd->blocks);
+ free (fd->devices);
+ rtems_fdisk_error ("disk create phy failed");
+ return sc;
+ }
+
+ for (device = 0; device < c->device_count; device++)
+ {
+ rtems_fdisk_segment_ctl* sc;
+ uint32_t segment_count;
+ uint32_t segment;
+
+ segment_count = rtems_fdisk_count_segments (&c->devices[device]);
+
+ fd->devices[device].segments = calloc (segment_count,
+ sizeof (rtems_fdisk_segment_ctl));
+ if (!fd->devices[device].segments)
+ {
+ rtems_disk_delete (dev);
+ rtems_semaphore_delete (fd->lock);
+ free (fd->copy_buffer);
+ free (fd->blocks);
+ free (fd->devices);
+ return RTEMS_NO_MEMORY;
+ }
+
+ sc = fd->devices[device].segments;
+
+ for (segment = 0; segment < c->devices[device].segment_count; segment++)
+ {
+ const rtems_fdisk_segment_desc* sd;
+ uint32_t seg_segment;
+
+ sd = &c->devices[device].segments[segment];
+
+ for (seg_segment = 0; seg_segment < sd->count; seg_segment++, sc++)
+ {
+ sc->descriptor = sd;
+ sc->device = device;
+ sc->segment = seg_segment;
+ sc->erased = 0;
+ }
+ }
+
+ fd->devices[device].segment_count = segment_count;
+ fd->devices[device].descriptor = &c->devices[device];
+ }
+
+ fd->device_count = c->device_count;
+
+ ret = rtems_fdisk_recover_block_mappings (fd);
+ if (ret)
+ {
+ rtems_disk_delete (dev);
+ rtems_semaphore_delete (fd->lock);
+ free (fd->copy_buffer);
+ free (fd->blocks);
+ free (fd->devices);
+ rtems_fdisk_error ("recovery of disk failed: %s (%d)",
+ strerror (ret), ret);
+ return ret;
+ }
+
+ ret = rtems_fdisk_compact (fd);
+ if (ret)
+ {
+ rtems_disk_delete (dev);
+ rtems_semaphore_delete (fd->lock);
+ free (fd->copy_buffer);
+ free (fd->blocks);
+ free (fd->devices);
+ rtems_fdisk_error ("compacting of disk failed: %s (%d)",
+ strerror (ret), ret);
+ return ret;
+ }
+ }
+
+ rtems_flashdisk_count = rtems_flashdisk_configuration_size;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/ide_part_table.c b/cpukit/libblock/src/ide_part_table.c
new file mode 100644
index 0000000000..3543284dfc
--- /dev/null
+++ b/cpukit/libblock/src/ide_part_table.c
@@ -0,0 +1,594 @@
+/*****************************************************************************
+ *
+ * ide_part_table.c
+ *
+ * The implementation of library supporting "MS-DOS-style" partition table
+ *
+ *
+ * Copyright (C) 2002 OKTET Ltd., St.-Petersburg, Russia
+ *
+ * Author: Konstantin Abramenko <Konstantin.Abramenko@oktet.ru>
+ * Alexander Kukuta <Alexander.Kukuta@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ *****************************************************************************/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems/ide_part_table.h>
+
+/*
+ * get_sector --
+ * gets sector from the disk
+ *
+ * PARAMETERS:
+ * dev - device number
+ * sector_num - number of sector to read
+ * sector - returned pointer to pointer to allocated
+ * sector_data_t structure
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL, if success;
+ * RTEMS_NO_MEMORY, if canot allocate memory for sector data;
+ * other error codes returned by rtems_bdbuf_read().
+ *
+ * NOTES:
+ * get_sector() operates with device via bdbuf library,
+ * and does not support devices with sector size other than 512 bytes
+ */
+static rtems_status_code
+get_sector(dev_t dev, uint32_t sector_num, rtems_sector_data_t **sector)
+{
+ rtems_sector_data_t *s;
+ rtems_bdbuf_buffer *buf;
+ rtems_status_code rc;
+
+ if (sector == NULL)
+ {
+ return RTEMS_INTERNAL_ERROR;
+ }
+
+ s = (rtems_sector_data_t *) malloc(sizeof(rtems_sector_data_t) + RTEMS_IDE_SECTOR_SIZE);
+ if (s == NULL)
+ {
+ return RTEMS_NO_MEMORY;
+ }
+
+ rc = rtems_bdbuf_read(dev, sector_num, &buf);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ free(s);
+ return rc;
+ }
+
+ memcpy(s->data, buf->buffer, RTEMS_IDE_SECTOR_SIZE);
+ s->sector_num = sector_num;
+
+ *sector = s;
+
+ rtems_bdbuf_release(buf);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+
+/*
+ * msdos_signature_check --
+ * checks if the partition table sector has msdos signature
+ *
+ * PARAMETERS:
+ * sector - sector to check
+ *
+ * RETURNS:
+ * true if sector has msdos signature, false otherwise
+ */
+static bool
+msdos_signature_check (rtems_sector_data_t *sector)
+{
+ uint8_t *p = sector->data + RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_OFFSET;
+
+ return ((p[0] == RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA1) &&
+ (p[1] == RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA2));
+}
+
+
+/*
+ * is_extended --
+ * checks if the partition type is extended
+ *
+ * PARAMETERS:
+ * type - type of partition to check
+ *
+ * RETURNS:
+ * true if partition type is extended, false otherwise
+ */
+static bool
+is_extended(uint8_t type)
+{
+ return ((type == EXTENDED_PARTITION) || (type == LINUX_EXTENDED));
+}
+
+/*
+ * is_fat_partition --
+ * checks if the partition type is defined for FAT
+ *
+ * PARAMETERS:
+ * type - type of partition to check
+ *
+ * RETURNS:
+ * true if partition type is extended, false otherwise
+ */
+static bool
+is_fat_partition(uint8_t type)
+{
+ static const uint8_t fat_part_types[] = {
+ DOS_FAT12_PARTITION,DOS_FAT16_PARTITION,
+ DOS_P32MB_PARTITION,
+ FAT32_PARTITION ,FAT32_LBA_PARTITION,
+ FAT16_LBA_PARTITION
+ };
+
+ return (NULL != memchr(fat_part_types,type,sizeof(fat_part_types)));
+}
+
+
+/*
+ * data_to_part_desc --
+ * parses raw partition table sector data
+ * to partition description structure
+ *
+ * PARAMETERS:
+ * data - raw partition table sector data
+ * new_part_desc - pointer to returned partition description structure
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL, if success;
+ * RTEMS_NO_MEMOTY, if cannot allocate memory for part_desc_t strucure;
+ * RTEMS_INTERNAL_ERROR, if other error occurs.
+ */
+static rtems_status_code
+data_to_part_desc(uint8_t *data, rtems_part_desc_t **new_part_desc)
+{
+ rtems_part_desc_t *part_desc;
+ uint32_t temp;
+
+ if (new_part_desc == NULL)
+ {
+ return RTEMS_INTERNAL_ERROR;
+ }
+
+ *new_part_desc = NULL;
+
+ if ((part_desc = calloc(1, sizeof(rtems_part_desc_t))) == NULL)
+ {
+ return RTEMS_NO_MEMORY;
+ }
+
+ part_desc->bootable = *(data + RTEMS_IDE_PARTITION_BOOTABLE_OFFSET);
+ part_desc->sys_type = *(data + RTEMS_IDE_PARTITION_SYS_TYPE_OFFSET);
+
+ /* read the offset start position and partition size in sectors */
+
+ /* due to incorrect data alignment one have to align data first */
+ memcpy(&temp, data + RTEMS_IDE_PARTITION_START_OFFSET, sizeof(uint32_t));
+ part_desc->start = LE_TO_CPU_U32(temp);
+
+ memcpy(&temp, data + RTEMS_IDE_PARTITION_SIZE_OFFSET, sizeof(uint32_t));
+ part_desc->size = LE_TO_CPU_U32(temp);
+
+ /*
+ * use partitions that are
+ * - extended
+ * or
+ * - FAT type and non-zero
+ */
+ if (is_extended(part_desc->sys_type) ||
+ ((is_fat_partition(part_desc->sys_type)) && (part_desc->size != 0))) {
+ *new_part_desc = part_desc;
+ }
+ else {
+ /* empty partition */
+ free(part_desc);
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+
+/*
+ * read_extended_partition --
+ * recursively reads extended partition sector from the device
+ * and constructs the partition table tree
+ *
+ * PARAMETERS:
+ * start - start sector of primary extended partition, used for
+ * calculation of absolute partition sector address
+ * ext_part - description of extended partition to process
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success,
+ * RTEMS_NO_MEMOTY if cannot allocate memory for part_desc_t strucure,
+ * RTEMS_INTERNAL_ERROR if other error occurs.
+ */
+static rtems_status_code
+read_extended_partition(uint32_t start, rtems_part_desc_t *ext_part)
+{
+ int i;
+ dev_t dev;
+ rtems_sector_data_t *sector = NULL;
+ uint32_t here;
+ uint8_t *data;
+ rtems_part_desc_t *new_part_desc;
+ rtems_status_code rc;
+
+ if ((ext_part == NULL) || (ext_part->disk_desc == NULL))
+ {
+ return RTEMS_INTERNAL_ERROR;
+ }
+
+ dev = ext_part->disk_desc->dev;
+
+ /* get start sector of current extended partition */
+ here = ext_part->start;
+
+ /* get first extended partition sector */
+
+ rc = get_sector(dev, here, &sector);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ if (sector)
+ free(sector);
+ return rc;
+ }
+
+ if (!msdos_signature_check(sector))
+ {
+ free(sector);
+ return RTEMS_INTERNAL_ERROR;
+ }
+
+ /* read and process up to 4 logical partition descriptors */
+
+ data = sector->data + RTEMS_IDE_PARTITION_TABLE_OFFSET;
+
+ for (i = 0; i < RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER; i++)
+ {
+ /* if data_to_part_desc fails skip this partition
+ * and parse the next one
+ */
+ rc = data_to_part_desc(data, &new_part_desc);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ free(sector);
+ return rc;
+ }
+
+ if (new_part_desc == NULL)
+ {
+ data += RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE;
+ continue;
+ }
+
+ ext_part->sub_part[i] = new_part_desc;
+ new_part_desc->ext_part = ext_part;
+ new_part_desc->disk_desc = ext_part->disk_desc;
+
+ if (is_extended(new_part_desc->sys_type))
+ {
+ new_part_desc->log_id = EMPTY_PARTITION;
+ new_part_desc->start += start;
+ read_extended_partition(start, new_part_desc);
+ }
+ else
+ {
+ rtems_disk_desc_t *disk_desc = new_part_desc->disk_desc;
+ disk_desc->partitions[disk_desc->last_log_id] = new_part_desc;
+ new_part_desc->log_id = ++disk_desc->last_log_id;
+ new_part_desc->start += here;
+ new_part_desc->end = new_part_desc->start + new_part_desc->size - 1;
+ }
+ data += RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE;
+ }
+
+ free(sector);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+
+/*
+ * read_mbr --
+ * reads Master Boot Record (sector 0) of physical device and
+ * constructs disk description structure
+ *
+ * PARAMETERS:
+ * disk_desc - returned disc description structure
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success,
+ * RTEMS_INTERNAL_ERROR otherwise
+ */
+static rtems_status_code
+read_mbr(rtems_disk_desc_t *disk_desc)
+{
+ int part_num;
+ rtems_sector_data_t *sector = NULL;
+ rtems_part_desc_t *part_desc;
+ uint8_t *data;
+ rtems_status_code rc;
+ dev_t dev = disk_desc->dev;
+
+ /* get MBR sector */
+ rc = get_sector(dev, 0, &sector);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ if (sector)
+ free(sector);
+ return rc;
+ }
+
+ /* check if the partition table structure is MS-DOS style */
+ if (!msdos_signature_check(sector))
+ {
+ free(sector);
+ return RTEMS_INTERNAL_ERROR;
+ }
+
+ /* read and process 4 primary partition descriptors */
+
+ data = sector->data + RTEMS_IDE_PARTITION_TABLE_OFFSET;
+
+ for (part_num = 0;
+ part_num < RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER;
+ part_num++)
+ {
+ rc = data_to_part_desc(data, &part_desc);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ free(sector);
+ return rc;
+ }
+
+ if (part_desc != NULL)
+ {
+ part_desc->log_id = part_num + 1;
+ part_desc->disk_desc = disk_desc;
+ part_desc->end = part_desc->start + part_desc->size - 1;
+ disk_desc->partitions[part_num] = part_desc;
+ }
+ else
+ {
+ disk_desc->partitions[part_num] = NULL;
+ }
+
+ data += RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE;
+ }
+
+ free(sector);
+
+ disk_desc->last_log_id = RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER;
+
+ /* There cannot be more than one extended partition,
+ but we are to process each primary partition */
+ for (part_num = 0;
+ part_num < RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER;
+ part_num++)
+ {
+ part_desc = disk_desc->partitions[part_num];
+ if (part_desc != NULL && is_extended(part_desc->sys_type))
+ {
+ read_extended_partition(part_desc->start, part_desc);
+ }
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+
+/*
+ * partition free --
+ * frees partition description structure
+ *
+ * PARAMETERS:
+ * part_desc - returned disc description structure
+ *
+ * RETURNS:
+ * N/A
+ */
+static void
+partition_free(rtems_part_desc_t *part_desc)
+{
+ int part_num;
+
+ if (part_desc == NULL)
+ return;
+
+ if (is_extended(part_desc->sys_type))
+ {
+ for (part_num = 0;
+ part_num < RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER;
+ part_num++)
+ {
+ partition_free(part_desc->sub_part[part_num]);
+ }
+ }
+
+ free(part_desc);
+}
+
+
+/*
+ * partition_table_free - frees disk descriptor structure
+ *
+ * PARAMETERS:
+ * disk_desc - disc descriptor structure to free
+ *
+ * RETURNS:
+ * N/A
+ */
+static void
+partition_table_free(rtems_disk_desc_t *disk_desc)
+{
+ int part_num;
+
+ for (part_num = 0;
+ part_num < RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER;
+ part_num++)
+ {
+ partition_free(disk_desc->partitions[part_num]);
+ }
+
+ free(disk_desc);
+}
+
+
+/*
+ * partition_table_get - reads partition table structure from the device
+ * and creates disk description structure
+ *
+ * PARAMETERS:
+ * dev_name - path to physical device in /dev filesystem
+ * disk_desc - returned disc description structure
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success,
+ * RTEMS_INTERNAL_ERROR otherwise
+ */
+static rtems_status_code
+partition_table_get(const char *dev_name, rtems_disk_desc_t *disk_desc)
+{
+ struct stat dev_stat;
+ rtems_status_code rc;
+
+ rc = stat(dev_name, &dev_stat);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ return RTEMS_INTERNAL_ERROR;
+ }
+
+ strncpy (disk_desc->dev_name, dev_name, 15);
+ disk_desc->dev = dev_stat.st_rdev;
+ disk_desc->sector_size = (dev_stat.st_blksize) ? dev_stat.st_blksize :
+ RTEMS_IDE_SECTOR_SIZE;
+
+ rc = read_mbr(disk_desc);
+
+ return rc;
+}
+
+
+/*
+ * rtems_ide_part_table_free - frees disk descriptor structure
+ *
+ * PARAMETERS:
+ * disk_desc - disc descriptor structure to free
+ *
+ * RETURNS:
+ * N/A
+ */
+void
+rtems_ide_part_table_free(rtems_disk_desc_t *disk_desc)
+{
+ partition_table_free( disk_desc );
+}
+
+
+/*
+ * rtems_ide_part_table_get - reads partition table structure from the device
+ * and creates disk description structure
+ *
+ * PARAMETERS:
+ * dev_name - path to physical device in /dev filesystem
+ * disk_desc - returned disc description structure
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success,
+ * RTEMS_INTERNAL_ERROR otherwise
+ */
+rtems_status_code
+rtems_ide_part_table_get(const char *dev_name, rtems_disk_desc_t *disk_desc)
+{
+ return partition_table_get( dev_name, disk_desc );
+}
+
+
+/*
+ * rtems_ide_part_table_initialize - initializes logical devices
+ * on the physical IDE drive
+ *
+ * PARAMETERS:
+ * dev_name - path to physical device in /dev filesystem
+ *
+ * RETURNS:
+ * RTEMS_SUCCESSFUL if success,
+ * RTEMS_NO_MEMOTY if cannot have not enough memory,
+ * RTEMS_INTERNAL_ERROR if other error occurs.
+ */
+rtems_status_code
+rtems_ide_part_table_initialize(char *dev_name)
+{
+ int part_num;
+ dev_t dev;
+ rtems_disk_desc_t *disk_desc;
+ rtems_device_major_number major;
+ rtems_device_minor_number minor;
+ rtems_status_code rc;
+ rtems_part_desc_t *part_desc;
+
+ /* logical device name /dev/hdxyy */
+ char name[RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX];
+
+ disk_desc = (rtems_disk_desc_t *) calloc(1, sizeof(rtems_disk_desc_t));
+ if (disk_desc == NULL)
+ {
+ return RTEMS_NO_MEMORY;
+ }
+
+ /* get partition table */
+ rc = partition_table_get(dev_name, disk_desc);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ free(disk_desc);
+ return rc;
+ }
+
+ /* To avoid device numbers conflicts we have to use for logic disk the same
+ * device major number as ATA device has, and minor number that equals to
+ * sum of logic disk partition number and the minor number of physical disk
+ */
+
+ rtems_filesystem_split_dev_t (disk_desc->dev, major, minor);
+
+ /* create logical disks on the physical one */
+ for (part_num = 0; part_num < disk_desc->last_log_id; part_num++)
+ {
+ sprintf(name, "%s%d", dev_name, part_num + 1);
+ dev = rtems_filesystem_make_dev_t(major, ++minor);
+
+ part_desc = disk_desc->partitions[part_num];
+ if (part_desc == NULL)
+ {
+ continue;
+ }
+
+ rc = rtems_disk_create_log(dev, disk_desc->dev, part_desc->start,
+ part_desc->size, name);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ fprintf(stdout,"Cannot create device %s, error code %d\n", name, rc);
+ continue;
+ }
+ }
+
+ partition_table_free(disk_desc);
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/media-desc.c b/cpukit/libblock/src/media-desc.c
new file mode 100644
index 0000000000..005f0f7329
--- /dev/null
+++ b/cpukit/libblock/src/media-desc.c
@@ -0,0 +1,72 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSMedia
+ *
+ * @brief Media implementation.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/media.h>
+
+static const char *const rtems_media_event_desc_table [] = {
+ [RTEMS_MEDIA_EVENT_DISK_ATTACH] = "DISK ATTACH",
+ [RTEMS_MEDIA_EVENT_DISK_DETACH] = "DISK DETACH",
+ [RTEMS_MEDIA_EVENT_MOUNT] = "MOUNT",
+ [RTEMS_MEDIA_EVENT_UNMOUNT] = "UNMOUNT",
+ [RTEMS_MEDIA_EVENT_PARTITION_INQUIRY] = "PARTITION INQUIRY",
+ [RTEMS_MEDIA_EVENT_PARTITION_ATTACH] = "PARTITION ATTACH",
+ [RTEMS_MEDIA_EVENT_PARTITION_DETACH] = "PARTITION DETACH"
+};
+
+static const char *const rtems_media_state_desc_table [] = {
+ [RTEMS_MEDIA_STATE_INQUIRY] = "INQUIRY",
+ [RTEMS_MEDIA_STATE_ABORTED] = "ABORTED",
+ [RTEMS_MEDIA_STATE_READY] = "SUCCESS",
+ [RTEMS_MEDIA_STATE_FAILED] = "FAILED",
+ [RTEMS_MEDIA_STATE_SUCCESS] = "SUCCESS",
+ [RTEMS_MEDIA_ERROR_DISK_UNKNOWN] = "ERROR DISK UNKNOWN",
+ [RTEMS_MEDIA_ERROR_DISK_EXISTS] = "ERROR DISK EXISTS",
+ [RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_UNKNOWN] = "ERROR DISK OR PARTITION UNKNOWN",
+ [RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_EXISTS] = "ERROR DISK OR PARTITION EXISTS",
+ [RTEMS_MEDIA_ERROR_PARTITION_UNKNOWN] = "ERROR PARTITION UNKNOWN",
+ [RTEMS_MEDIA_ERROR_PARTITION_ORPHAN] = "ERROR PARTITION ORPHAN",
+ [RTEMS_MEDIA_ERROR_PARTITION_DETACH_WITH_MOUNT] = "ERROR PARTITION DETACH WITH MOUNT",
+ [RTEMS_MEDIA_ERROR_PARTITION_WITH_UNKNOWN_DISK] = "ERROR PARTITION WITH UNKNOWN DISK",
+ [RTEMS_MEDIA_ERROR_MOUNT_POINT_UNKNOWN] = "ERROR MOUNT POINT UNKNOWN",
+ [RTEMS_MEDIA_ERROR_MOUNT_POINT_EXISTS] = "ERROR MOUNT POINT EXISTS",
+ [RTEMS_MEDIA_ERROR_MOUNT_POINT_ORPHAN] = "ERROR MOUNT POINT ORPHAN"
+};
+
+#define TC(table) (sizeof(table) / sizeof(table [0]))
+
+const char *rtems_media_event_description(rtems_media_event event)
+{
+ if ((size_t) event < TC(rtems_media_event_desc_table)) {
+ return rtems_media_event_desc_table [event];
+ } else {
+ return "INVALID";
+ }
+}
+
+const char *rtems_media_state_description(rtems_media_state state)
+{
+ if ((size_t) state < TC(rtems_media_state_desc_table)) {
+ return rtems_media_state_desc_table [state];
+ } else {
+ return "INVALID";
+ }
+}
diff --git a/cpukit/libblock/src/media-dev-ident.c b/cpukit/libblock/src/media-dev-ident.c
new file mode 100644
index 0000000000..7c0f298424
--- /dev/null
+++ b/cpukit/libblock/src/media-dev-ident.c
@@ -0,0 +1,47 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSMedia
+ *
+ * @brief Media implementation.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <rtems.h>
+
+#include <rtems/media.h>
+
+rtems_status_code rtems_media_get_device_identifier(
+ const char *device_path,
+ dev_t *device_identifier
+)
+{
+ int rv = 0;
+ struct stat st;
+
+ rv = stat(device_path, &st);
+ if (rv != 0) {
+ return RTEMS_INVALID_ID;
+ }
+
+ *device_identifier = st.st_rdev;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/media-path.c b/cpukit/libblock/src/media-path.c
new file mode 100644
index 0000000000..1668145294
--- /dev/null
+++ b/cpukit/libblock/src/media-path.c
@@ -0,0 +1,86 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSMedia
+ *
+ * @brief Media implementation.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include <rtems/media.h>
+
+char *rtems_media_create_path(
+ const char *prefix,
+ const char *name,
+ rtems_device_major_number major
+)
+{
+ size_t const size = strlen(prefix) + 1 + strlen(name) + 1 + 10 + 1;
+ char *const s = malloc(size);
+
+ if (s != NULL) {
+#ifndef NDEBUG
+ int rv =
+#endif
+ snprintf(s, size, "%s/%s-%" PRIu32, prefix, name, major);
+ assert(rv < (int) size);
+ }
+
+ return s;
+}
+
+char *rtems_media_replace_prefix(const char *new_prefix, const char *path)
+{
+ const char *const name_try = strrchr(path, '/');
+ const char *const name = (name_try == NULL) ? path : name_try + 1;
+ size_t const new_prefix_len = strlen(new_prefix);
+ size_t const name_size = strlen(name) + 1;
+ size_t const size = new_prefix_len + 1 + name_size;
+ char *const s = malloc(size);
+
+ if (s != NULL) {
+ memcpy(s, new_prefix, new_prefix_len);
+ s [new_prefix_len] = '/';
+ memcpy(s + new_prefix_len + 1, name, name_size);
+ }
+
+ return s;
+}
+
+char *rtems_media_append_minor(
+ const char *path,
+ rtems_device_minor_number minor
+)
+{
+ size_t const size = strlen(path) + 1 + 10 + 1;
+ char *const s = malloc(size);
+
+ if (s != NULL) {
+#ifndef NDEBUG
+ int rv =
+#endif
+ snprintf(s, size, "%s-%" PRIu32, path, minor);
+ assert(rv < (int) size);
+ }
+
+ return s;
+}
diff --git a/cpukit/libblock/src/media-server.c b/cpukit/libblock/src/media-server.c
new file mode 100644
index 0000000000..66f46abee9
--- /dev/null
+++ b/cpukit/libblock/src/media-server.c
@@ -0,0 +1,152 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSMedia
+ *
+ * @brief Media implementation.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <rtems.h>
+#include <rtems/chain.h>
+#include <rtems/media.h>
+
+#define EVENT RTEMS_EVENT_13
+
+typedef struct {
+ rtems_chain_node node;
+ rtems_media_event event;
+ const char *src;
+ rtems_media_worker worker;
+ void *worker_arg;
+} message;
+
+static RTEMS_CHAIN_DEFINE_EMPTY(message_chain);
+
+static rtems_id server_id = RTEMS_ID_NONE;
+
+static void media_server(rtems_task_argument arg __attribute__((unused)))
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ while (true) {
+ message *msg = NULL;
+
+ sc = rtems_chain_get_with_wait(
+ &message_chain,
+ EVENT,
+ RTEMS_NO_TIMEOUT,
+ (rtems_chain_node **) &msg
+ );
+ assert(sc == RTEMS_SUCCESSFUL);
+ assert(msg != NULL);
+
+ rtems_media_post_event(
+ msg->event,
+ msg->src,
+ NULL,
+ msg->worker,
+ msg->worker_arg
+ );
+
+ free(msg);
+ }
+}
+
+rtems_status_code rtems_media_server_initialize(
+ rtems_task_priority priority,
+ size_t stack_size,
+ rtems_mode modes,
+ rtems_attribute attributes
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (server_id == RTEMS_ID_NONE) {
+ sc = rtems_media_initialize();
+ if (sc != RTEMS_SUCCESSFUL) {
+ goto error;
+ }
+
+ sc = rtems_task_create(
+ rtems_build_name('M', 'D', 'I', 'A'),
+ priority,
+ stack_size,
+ modes,
+ attributes,
+ &server_id
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ goto error;
+ }
+
+ sc = rtems_task_start(server_id, media_server, 0);
+ if (sc != RTEMS_SUCCESSFUL) {
+ goto error;
+ }
+ }
+
+ return RTEMS_SUCCESSFUL;
+
+error:
+
+ if (server_id != RTEMS_ID_NONE) {
+ rtems_task_delete(server_id);
+ }
+
+ return RTEMS_NO_MEMORY;
+}
+
+rtems_status_code rtems_media_server_post_event(
+ rtems_media_event event,
+ const char *src,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ size_t src_size = strlen(src) + 1;
+ message *msg = malloc(sizeof(*msg) + src_size);
+
+ if (msg != NULL) {
+ char *s = (char *) msg + sizeof(*msg);
+
+ memcpy(s, src, src_size);
+
+ msg->event = event;
+ msg->src = s;
+ msg->worker = worker;
+ msg->worker_arg = worker_arg;
+
+ sc = rtems_chain_append_with_notification(
+ &message_chain,
+ &msg->node,
+ server_id,
+ EVENT
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ sc = RTEMS_NOT_CONFIGURED;
+ }
+ } else {
+ sc = RTEMS_NO_MEMORY;
+ }
+
+ return sc;
+}
diff --git a/cpukit/libblock/src/media.c b/cpukit/libblock/src/media.c
new file mode 100644
index 0000000000..b4ddd6ad7c
--- /dev/null
+++ b/cpukit/libblock/src/media.c
@@ -0,0 +1,1012 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSMedia
+ *
+ * @brief Media implementation.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <string.h>
+#include <assert.h>
+
+#include <rtems.h>
+#include <rtems/bdbuf.h>
+#include <rtems/diskdevs.h>
+#include <rtems/bdpart.h>
+#include <rtems/libio.h>
+
+#include <rtems/media.h>
+
+typedef struct {
+ rtems_bdpart_partition *partitions;
+ size_t *count;
+} partition_table;
+
+typedef struct {
+ dev_t physical_disk;
+ dev_t logical_disk;
+ rtems_blkdev_bnum begin;
+ rtems_blkdev_bnum count;
+} partition;
+
+typedef struct media_item {
+ rtems_chain_node node;
+ struct media_item *parent;
+ char *disk_path;
+ char *mount_path;
+} media_item;
+
+typedef struct listener_item {
+ rtems_chain_node node;
+ rtems_media_listener listener;
+ void *listener_arg;
+} listener_item;
+
+static RTEMS_CHAIN_DEFINE_EMPTY(listener_item_chain);
+
+static RTEMS_CHAIN_DEFINE_EMPTY(media_item_chain);
+
+static rtems_id media_mutex = RTEMS_ID_NONE;
+
+static rtems_status_code lock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_semaphore_obtain(media_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL) {
+ sc = RTEMS_NOT_CONFIGURED;
+ }
+
+ return sc;
+}
+
+static void unlock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_semaphore_release(media_mutex);
+ assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static listener_item *find_listener(
+ rtems_media_listener listener,
+ void *listener_arg
+)
+{
+ rtems_chain_node *node = rtems_chain_first(&listener_item_chain);
+
+ while (!rtems_chain_is_tail(&listener_item_chain, node)) {
+ listener_item *item = (listener_item *) node;
+
+ if (item->listener == listener && item->listener_arg == listener_arg) {
+ return item;
+ }
+
+ node = rtems_chain_next(node);
+ }
+
+ return NULL;
+}
+
+rtems_status_code rtems_media_listener_add(
+ rtems_media_listener listener,
+ void *listener_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = lock();
+ if (sc == RTEMS_SUCCESSFUL) {
+ listener_item *item = find_listener(listener, listener_arg);
+
+ if (item == NULL) {
+ item = malloc(sizeof(*item));
+ if (item != NULL) {
+ item->listener = listener;
+ item->listener_arg = listener_arg;
+ rtems_chain_append_unprotected(&listener_item_chain, &item->node);
+ } else {
+ sc = RTEMS_NO_MEMORY;
+ }
+ } else {
+ sc = RTEMS_TOO_MANY;
+ }
+
+ unlock();
+ }
+
+ return sc;
+}
+
+rtems_status_code rtems_media_listener_remove(
+ rtems_media_listener listener,
+ void *listener_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = lock();
+ if (sc == RTEMS_SUCCESSFUL) {
+ listener_item *item = find_listener(listener, listener_arg);
+
+ if (item != NULL) {
+ rtems_chain_extract_unprotected(&item->node);
+ free(item);
+ } else {
+ sc = RTEMS_INVALID_ID;
+ }
+
+ unlock();
+ }
+
+ return sc;
+}
+
+static rtems_status_code notify(
+ rtems_media_event event,
+ rtems_media_state state,
+ const char *src,
+ const char *dest
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code rsc = RTEMS_SUCCESSFUL;
+ rtems_chain_node *node = rtems_chain_first(&listener_item_chain);
+
+ while (!rtems_chain_is_tail(&listener_item_chain, node)) {
+ listener_item *item = (listener_item *) node;
+
+ sc = (*item->listener)(event, state, src, dest, item->listener_arg);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = sc;
+ }
+
+ node = rtems_chain_next(node);
+ }
+
+ return rsc;
+}
+
+static void error(
+ rtems_media_state state,
+ const char *src,
+ const char *dest
+)
+{
+ notify(RTEMS_MEDIA_EVENT_ERROR, state, src, dest);
+}
+
+static media_item *get_media_item(
+ const char *disk_path,
+ const char *mount_path
+)
+{
+ rtems_chain_node *node = rtems_chain_first(&media_item_chain);
+
+ while (!rtems_chain_is_tail(&media_item_chain, node)) {
+ media_item *item = (media_item *) node;
+
+ if (
+ (disk_path == NULL || strcmp(disk_path, item->disk_path) == 0)
+ && (mount_path == NULL || strcmp(mount_path, item->mount_path) == 0)
+ ) {
+ return item;
+ }
+
+ node = rtems_chain_next(node);
+ }
+
+ return NULL;
+}
+
+static void free_item(media_item *item)
+{
+ rtems_chain_extract(&item->node);
+ free(item->mount_path);
+ free(item);
+}
+
+static void create_item(
+ media_item *parent,
+ const char *disk_path,
+ const char *mount_path
+)
+{
+ size_t disk_path_size = strlen(disk_path) + 1;
+ media_item *item = malloc(sizeof(*item) + disk_path_size);
+
+ if (item != NULL) {
+ if (mount_path != NULL) {
+ item->mount_path = strdup(mount_path);
+
+ if (item->mount_path == NULL) {
+ free(item);
+
+ return;
+ }
+ } else {
+ item->mount_path = NULL;
+ }
+
+ item->parent = parent;
+ item->disk_path = (char *) item + sizeof(*item);
+ memcpy(item->disk_path, disk_path, disk_path_size);
+ rtems_chain_append(&media_item_chain, &item->node);
+ }
+}
+
+static void remove_mount_point(const char *mount_path)
+{
+ media_item *item = get_media_item(NULL, mount_path);
+
+ if (item != NULL) {
+ free(item->mount_path);
+ item->mount_path = NULL;
+ } else {
+ error(RTEMS_MEDIA_ERROR_MOUNT_POINT_UNKNOWN, mount_path, NULL);
+ }
+}
+
+static void remove_partition(const char *partition_path)
+{
+ media_item *item = get_media_item(partition_path, NULL);
+
+ if (item != NULL) {
+ if (item->mount_path != NULL) {
+ error(
+ RTEMS_MEDIA_ERROR_PARTITION_DETACH_WITH_MOUNT,
+ partition_path,
+ item->mount_path
+ );
+ }
+ free_item(item);
+ } else {
+ error(RTEMS_MEDIA_ERROR_PARTITION_UNKNOWN, partition_path, NULL);
+ }
+}
+
+static void remove_disk(const char *disk_path)
+{
+ media_item *item = get_media_item(disk_path, NULL);
+
+ if (item != NULL) {
+ rtems_chain_node *node = rtems_chain_first(&media_item_chain);
+
+ while (!rtems_chain_is_tail(&media_item_chain, node)) {
+ media_item *child = (media_item *) node;
+
+ node = rtems_chain_next(node);
+
+ if (child->parent == item) {
+ if (child->mount_path != NULL) {
+ error(
+ RTEMS_MEDIA_ERROR_MOUNT_POINT_ORPHAN,
+ child->mount_path,
+ disk_path
+ );
+ }
+ error(RTEMS_MEDIA_ERROR_PARTITION_ORPHAN, child->disk_path, disk_path);
+ free_item(child);
+ }
+ }
+
+ free_item(item);
+ } else {
+ error(RTEMS_MEDIA_ERROR_DISK_UNKNOWN, disk_path, NULL);
+ }
+}
+
+static void add_disk(const char *disk_path)
+{
+ media_item *item = get_media_item(disk_path, NULL);
+
+ if (item != NULL) {
+ error(RTEMS_MEDIA_ERROR_DISK_EXISTS, disk_path, NULL);
+ remove_disk(disk_path);
+ }
+
+ create_item(NULL, disk_path, NULL);
+}
+
+static void add_partition(const char *disk_path, const char *partition_path)
+{
+ media_item *item = get_media_item(partition_path, NULL);
+ media_item *parent = get_media_item(disk_path, NULL);
+
+ if (item != NULL) {
+ error(RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_EXISTS, partition_path, NULL);
+ remove_disk(partition_path);
+ }
+
+ if (parent != NULL) {
+ create_item(parent, partition_path, NULL);
+ } else {
+ error(
+ RTEMS_MEDIA_ERROR_PARTITION_WITH_UNKNOWN_DISK,
+ partition_path,
+ disk_path
+ );
+ }
+}
+
+static void add_mount_point(const char *disk_path, const char *mount_path)
+{
+ media_item *item = get_media_item(disk_path, NULL);
+
+ if (item != NULL) {
+ if (item->mount_path != NULL) {
+ error(RTEMS_MEDIA_ERROR_MOUNT_POINT_EXISTS, item->mount_path, NULL);
+ free(item->mount_path);
+ }
+ item->mount_path = strdup(mount_path);
+ } else {
+ error(RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_UNKNOWN, disk_path, NULL);
+ }
+}
+
+static bool is_add_state(rtems_media_state state)
+{
+ return state == RTEMS_MEDIA_STATE_SUCCESS;
+}
+
+static bool is_remove_state(rtems_media_state state)
+{
+ return state == RTEMS_MEDIA_STATE_SUCCESS
+ || state == RTEMS_MEDIA_STATE_FAILED;
+}
+
+static rtems_status_code remember_event(
+ rtems_media_event event,
+ rtems_media_state state,
+ const char *src,
+ const char *dest
+)
+{
+ switch (event) {
+ case RTEMS_MEDIA_EVENT_DISK_ATTACH:
+ if (is_add_state(state)) {
+ add_disk(dest);
+ }
+ break;
+ case RTEMS_MEDIA_EVENT_PARTITION_ATTACH:
+ if (is_add_state(state)) {
+ add_partition(src, dest);
+ }
+ break;
+ case RTEMS_MEDIA_EVENT_MOUNT:
+ if (is_add_state(state)) {
+ add_mount_point(src, dest);
+ }
+ break;
+ case RTEMS_MEDIA_EVENT_UNMOUNT:
+ if (is_remove_state(state)) {
+ remove_mount_point(src);
+ }
+ break;
+ case RTEMS_MEDIA_EVENT_PARTITION_DETACH:
+ if (is_remove_state(state)) {
+ remove_partition(src);
+ }
+ break;
+ case RTEMS_MEDIA_EVENT_DISK_DETACH:
+ if (is_remove_state(state)) {
+ remove_disk(src);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static rtems_status_code process_event(
+ rtems_media_event event,
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_media_state state = RTEMS_MEDIA_STATE_FAILED;
+ char *dest = NULL;
+
+ sc = notify(event, RTEMS_MEDIA_STATE_INQUIRY, src, NULL);
+ if (sc == RTEMS_SUCCESSFUL) {
+ state = RTEMS_MEDIA_STATE_READY;
+ } else {
+ state = RTEMS_MEDIA_STATE_ABORTED;
+ }
+
+ sc = (*worker)(state, src, &dest, worker_arg);
+ if (state == RTEMS_MEDIA_STATE_READY) {
+ if (sc == RTEMS_SUCCESSFUL) {
+ state = RTEMS_MEDIA_STATE_SUCCESS;
+ } else {
+ state = RTEMS_MEDIA_STATE_FAILED;
+ }
+ }
+
+ notify(event, state, src, dest);
+ remember_event(event, state, src, dest);
+
+ if (state == RTEMS_MEDIA_STATE_SUCCESS) {
+ sc = RTEMS_SUCCESSFUL;
+ } else if (state == RTEMS_MEDIA_STATE_ABORTED) {
+ sc = RTEMS_UNSATISFIED;
+ } else {
+ sc = RTEMS_IO_ERROR;
+ }
+
+ if (dest_ptr != NULL && sc == RTEMS_SUCCESSFUL) {
+ *dest_ptr = dest;
+ } else {
+ free(dest);
+ }
+
+ return sc;
+}
+
+static rtems_status_code mount_worker(
+ rtems_media_state state,
+ const char *src,
+ char **dest,
+ void *worker_arg
+)
+{
+ int rv = 0;
+
+ if (state == RTEMS_MEDIA_STATE_READY) {
+ char *mount_path = NULL;
+
+ if (worker_arg == NULL) {
+ mount_path = rtems_media_replace_prefix(RTEMS_MEDIA_MOUNT_BASE, src);
+ } else {
+ mount_path = strdup(worker_arg);
+ }
+
+ if (mount_path == NULL) {
+ return RTEMS_IO_ERROR;
+ }
+
+ rv = rtems_mkdir(mount_path, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (rv != 0) {
+ free(mount_path);
+
+ return RTEMS_IO_ERROR;
+ }
+
+ rv = mount(
+ src,
+ mount_path,
+ RTEMS_FILESYSTEM_TYPE_DOSFS,
+ RTEMS_FILESYSTEM_READ_WRITE,
+ NULL
+ );
+ if (rv != 0) {
+ rmdir(mount_path);
+ free(mount_path);
+
+ return RTEMS_IO_ERROR;
+ }
+
+ *dest = mount_path;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static rtems_status_code do_mount(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ if (worker == NULL) {
+ worker = mount_worker;
+ }
+
+ return process_event(
+ RTEMS_MEDIA_EVENT_MOUNT,
+ src,
+ dest_ptr,
+ worker,
+ worker_arg
+ );
+}
+
+static rtems_status_code do_partition_attach(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ char *part_path = NULL;
+
+ if (worker != NULL) {
+ sc = process_event(
+ RTEMS_MEDIA_EVENT_PARTITION_ATTACH,
+ src,
+ &part_path,
+ worker,
+ worker_arg
+ );
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ sc = do_mount(part_path, NULL, NULL, NULL);
+ }
+ } else {
+ sc = RTEMS_INVALID_ADDRESS;
+ }
+
+ if (dest_ptr != NULL && sc == RTEMS_SUCCESSFUL) {
+ *dest_ptr = part_path;
+ } else {
+ free(part_path);
+ }
+
+ return sc;
+}
+
+static rtems_status_code partition_attach_worker(
+ rtems_media_state state,
+ const char *src,
+ char **dest,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (state == RTEMS_MEDIA_STATE_READY) {
+ partition *part = worker_arg;
+ rtems_device_minor_number minor =
+ rtems_filesystem_dev_minor_t(part->logical_disk);
+ char *part_path = rtems_media_append_minor(src, minor);
+
+ if (part_path == NULL) {
+ return RTEMS_IO_ERROR;
+ }
+
+ sc = rtems_disk_create_log(
+ part->logical_disk,
+ part->physical_disk,
+ part->begin,
+ part->count,
+ part_path
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ free(part_path);
+
+ return RTEMS_IO_ERROR;
+ }
+
+ *dest = part_path;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static rtems_status_code attach_and_mount_partitions(
+ const char *disk_path,
+ rtems_bdpart_partition *partitions,
+ size_t count
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_device_major_number major = 0;
+ rtems_device_minor_number minor = 0;
+ dev_t dev = 0;
+ size_t i = 0;
+
+ sc = rtems_media_get_device_identifier(disk_path, &dev);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return RTEMS_INVALID_ID;
+ }
+
+ major = rtems_filesystem_dev_major_t(dev);
+ minor = rtems_filesystem_dev_minor_t(dev) + 1;
+
+ for (i = 0; i < count; ++i, ++minor) {
+ partition part_desc = {
+ .physical_disk = dev,
+ .logical_disk = rtems_filesystem_make_dev_t(major, minor),
+ .begin = partitions [i].begin,
+ .count = partitions [i].end - partitions [i].begin
+ };
+ char *part_path = NULL;
+
+ sc = process_event(
+ RTEMS_MEDIA_EVENT_PARTITION_ATTACH,
+ disk_path,
+ &part_path,
+ partition_attach_worker,
+ &part_desc
+ );
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ sc = do_mount(part_path, NULL, NULL, NULL);
+ }
+
+ free(part_path);
+ }
+
+ return sc;
+}
+
+static rtems_status_code partition_inquiry_worker(
+ rtems_media_state state,
+ const char *src,
+ char **dest __attribute__((unused)),
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (state == RTEMS_MEDIA_STATE_READY) {
+ partition_table *pt = worker_arg;
+ rtems_bdpart_format format;
+
+ sc = rtems_bdpart_read(src, &format, pt->partitions, pt->count);
+ if (sc != RTEMS_SUCCESSFUL || *pt->count == 0) {
+ return RTEMS_IO_ERROR;
+ }
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static rtems_status_code do_partition_inquiry(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (worker == NULL) {
+ rtems_bdpart_partition partitions [RTEMS_BDPART_PARTITION_NUMBER_HINT];
+ size_t count = RTEMS_BDPART_PARTITION_NUMBER_HINT;
+ partition_table pt = {
+ .partitions = partitions,
+ .count = &count
+ };
+
+ sc = process_event(
+ RTEMS_MEDIA_EVENT_PARTITION_INQUIRY,
+ src,
+ dest_ptr,
+ partition_inquiry_worker,
+ &pt
+ );
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ sc = attach_and_mount_partitions(src, partitions, count);
+ }
+ } else {
+ sc = process_event(
+ RTEMS_MEDIA_EVENT_PARTITION_INQUIRY,
+ src,
+ dest_ptr,
+ worker,
+ worker_arg
+ );
+ }
+
+ return sc;
+}
+
+static rtems_status_code do_disk_attach(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code rsc = RTEMS_SUCCESSFUL;
+ char *disk_path = NULL;
+
+ if (worker != NULL) {
+ rsc = process_event(
+ RTEMS_MEDIA_EVENT_DISK_ATTACH,
+ src,
+ &disk_path,
+ worker,
+ worker_arg
+ );
+
+ if (rsc == RTEMS_SUCCESSFUL) {
+ sc = do_mount(disk_path, NULL, NULL, NULL);
+
+ if (sc != RTEMS_SUCCESSFUL) {
+ do_partition_inquiry(disk_path, NULL, NULL, NULL);
+ }
+ }
+ } else {
+ rsc = RTEMS_INVALID_ADDRESS;
+ }
+
+ if (dest_ptr != NULL && rsc == RTEMS_SUCCESSFUL) {
+ *dest_ptr = disk_path;
+ } else {
+ free(disk_path);
+ }
+
+ return rsc;
+}
+
+static rtems_status_code unmount_worker(
+ rtems_media_state state,
+ const char *src,
+ char **dest __attribute__((unused)),
+ void *worker_arg __attribute__((unused))
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (state == RTEMS_MEDIA_STATE_READY) {
+ int rv = unmount(src);
+
+ if (rv == 0) {
+ rv = rmdir(src);
+ if (rv != 0) {
+ sc = RTEMS_IO_ERROR;
+ }
+ } else {
+ sc = RTEMS_IO_ERROR;
+ }
+ }
+
+ return sc;
+}
+
+static rtems_status_code do_unmount(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ if (worker == NULL) {
+ worker = unmount_worker;
+ worker_arg = NULL;
+ }
+
+ return process_event(
+ RTEMS_MEDIA_EVENT_UNMOUNT,
+ src,
+ dest_ptr,
+ worker,
+ worker_arg
+ );
+}
+
+static rtems_status_code disk_detach_worker(
+ rtems_media_state state,
+ const char *src,
+ char **dest __attribute__((unused)),
+ void *worker_arg __attribute__((unused))
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code rsc = RTEMS_SUCCESSFUL;
+
+ if (state == RTEMS_MEDIA_STATE_READY) {
+ dev_t dev = 0;
+
+ sc = rtems_media_get_device_identifier(src, &dev);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return RTEMS_IO_ERROR;
+ }
+
+ sc = rtems_bdbuf_syncdev(dev);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+
+ sc = rtems_disk_delete(dev);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+
+ rtems_bdbuf_purge_dev(dev);
+
+ if (rtems_filesystem_dev_minor_t(dev) == 0) {
+ sc = rtems_io_unregister_driver(rtems_filesystem_dev_major_t(dev));
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+ }
+ }
+
+ return rsc;
+}
+
+static rtems_status_code detach_item(rtems_media_event event, media_item *item)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code rsc = RTEMS_SUCCESSFUL;
+
+ if (item->mount_path != NULL) {
+ sc = do_unmount(item->mount_path, NULL, NULL, NULL);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+ }
+
+ sc = process_event(event, item->disk_path, NULL, disk_detach_worker, NULL);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+
+ return rsc;
+}
+
+static rtems_status_code detach_parent_item(media_item *parent)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_status_code rsc = RTEMS_SUCCESSFUL;
+
+ rtems_chain_node *node = rtems_chain_first(&media_item_chain);
+
+ while (!rtems_chain_is_tail(&media_item_chain, node)) {
+ media_item *child = (media_item *) node;
+
+ node = rtems_chain_next(node);
+
+ if (child->parent == parent) {
+ sc = detach_item(RTEMS_MEDIA_EVENT_PARTITION_DETACH, child);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+ }
+ }
+
+ sc = detach_item(RTEMS_MEDIA_EVENT_DISK_DETACH, parent);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rsc = RTEMS_IO_ERROR;
+ }
+
+ return rsc;
+}
+
+static rtems_status_code do_disk_detach(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ if (worker == NULL) {
+ media_item *parent = get_media_item(src, NULL);
+
+ if (parent != NULL) {
+ return detach_parent_item(parent);
+ }
+
+ worker = disk_detach_worker;
+ worker_arg = NULL;
+ }
+
+ return process_event(
+ RTEMS_MEDIA_EVENT_DISK_DETACH,
+ src,
+ dest_ptr,
+ worker,
+ worker_arg
+ );
+}
+
+static rtems_status_code do_partition_detach(
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ if (worker == NULL) {
+ media_item *item = get_media_item(src, NULL);
+
+ if (item != NULL) {
+ return detach_item(RTEMS_MEDIA_EVENT_PARTITION_DETACH, item);
+ }
+
+ worker = disk_detach_worker;
+ worker_arg = NULL;
+ }
+
+ return process_event(
+ RTEMS_MEDIA_EVENT_PARTITION_DETACH,
+ src,
+ dest_ptr,
+ worker,
+ worker_arg
+ );
+}
+
+rtems_status_code rtems_media_post_event(
+ rtems_media_event event,
+ const char *src,
+ char **dest_ptr,
+ rtems_media_worker worker,
+ void *worker_arg
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = lock();
+ if (sc != RTEMS_SUCCESSFUL) {
+ return sc;
+ }
+
+ switch (event) {
+ case RTEMS_MEDIA_EVENT_DISK_ATTACH:
+ sc = do_disk_attach(src, dest_ptr, worker, worker_arg);
+ break;
+ case RTEMS_MEDIA_EVENT_DISK_DETACH:
+ sc = do_disk_detach(src, dest_ptr, worker, worker_arg);
+ break;
+ case RTEMS_MEDIA_EVENT_MOUNT:
+ sc = do_mount(src, dest_ptr, worker, worker_arg);
+ break;
+ case RTEMS_MEDIA_EVENT_UNMOUNT:
+ sc = do_unmount(src, dest_ptr, worker, worker_arg);
+ break;
+ case RTEMS_MEDIA_EVENT_PARTITION_INQUIRY:
+ sc = do_partition_inquiry(src, dest_ptr, worker, worker_arg);
+ break;
+ case RTEMS_MEDIA_EVENT_PARTITION_ATTACH:
+ sc = do_partition_attach(src, dest_ptr, worker, worker_arg);
+ break;
+ case RTEMS_MEDIA_EVENT_PARTITION_DETACH:
+ sc = do_partition_detach(src, dest_ptr, worker, worker_arg);
+ break;
+ default:
+ sc = RTEMS_INVALID_ID;
+ break;
+ }
+
+ unlock();
+
+ return sc;
+}
+
+rtems_status_code rtems_media_initialize(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (media_mutex == RTEMS_ID_NONE) {
+ sc = rtems_semaphore_create(
+ rtems_build_name('M', 'D', 'I', 'A'),
+ 1,
+ RTEMS_LOCAL | RTEMS_PRIORITY
+ | RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE,
+ 0,
+ &media_mutex
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ sc = RTEMS_NO_MEMORY;
+ }
+ }
+
+ return sc;
+}
diff --git a/cpukit/libblock/src/nvdisk-sram.c b/cpukit/libblock/src/nvdisk-sram.c
new file mode 100644
index 0000000000..b31f83cfed
--- /dev/null
+++ b/cpukit/libblock/src/nvdisk-sram.c
@@ -0,0 +1,68 @@
+/*
+ * $Id$
+ *
+ * RTEMS Project (http://www.rtems.org/)
+ *
+ * Copyright 2007 Chris Johns (chrisj@rtems.org)
+ */
+/**
+ * Provide SRAM support for the NV Disk.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <rtems.h>
+
+#include <rtems/nvdisk-sram.h>
+
+#ifndef NVDISK_SRAM_ERROR_TRACE
+#define NVDISK_SRAM_ERROR_TRACE (0)
+#endif
+
+static int
+rtems_nvdisk_sram_read (uint32_t device __attribute__((unused)),
+ uint32_t flags __attribute__((unused)),
+ void* base,
+ uint32_t offset,
+ void* buffer,
+ size_t size)
+{
+ memcpy (buffer, (base + offset), size);
+ return 0;
+}
+
+static int
+rtems_nvdisk_sram_write (uint32_t device __attribute__((unused)),
+ uint32_t flags __attribute__((unused)),
+ void* base,
+ uint32_t offset,
+ const void* buffer,
+ size_t size)
+{
+ memcpy ((base + offset), buffer, size);
+ return 0;
+}
+
+static int
+rtems_nvdisk_sram_verify (uint32_t device __attribute__((unused)),
+ uint32_t flags __attribute__((unused)),
+ void* base,
+ uint32_t offset,
+ const void* buffer,
+ size_t size)
+{
+ return memcmp ((base + offset), buffer, size) == 0 ? 0 : EIO;
+}
+
+
+const rtems_nvdisk_driver_handlers rtems_nvdisk_sram_handlers =
+{
+ read: rtems_nvdisk_sram_read,
+ write: rtems_nvdisk_sram_write,
+ verify: rtems_nvdisk_sram_verify
+};
diff --git a/cpukit/libblock/src/nvdisk.c b/cpukit/libblock/src/nvdisk.c
new file mode 100644
index 0000000000..26c0f40309
--- /dev/null
+++ b/cpukit/libblock/src/nvdisk.c
@@ -0,0 +1,845 @@
+/*
+ * nvdisk.c -- Non-volatile disk block device implementation
+ *
+ * Copyright (C) 2007 Chris Johns
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "rtems/blkdev.h"
+#include "rtems/diskdevs.h"
+#include "rtems/nvdisk.h"
+
+/**
+ * @note
+ *
+ * The use of pages can vary. The rtems_nvdisk_*_page set
+ * routines use an absolute page number relative to the segment
+ * while all other page numbera are relative to the number of
+ * page descriptor pages a segment has. You need to add the
+ * number of page descriptor pages (pages_desc) to the page number
+ * when call the rtems_nvdisk_*_page functions.
+ *
+ * You must always show the page number as relative in any trace
+ * or error message as device-page and if you have to
+ * the page number as absolute use device~page. This
+ * can be seen in the page copy routine.
+ *
+ * The code is like this to avoid needing the pass the pages_desc
+ * value around. It is only used in selected places and so the
+ * extra parameter was avoided.
+ */
+
+/**
+ * Control tracing. It can be compiled out of the code for small
+ * footprint targets. Leave in by default.
+ */
+#if !defined (RTEMS_NVDISK_TRACE)
+#define RTEMS_NVDISK_TRACE 0
+#endif
+
+/**
+ * NV Device Control holds the segment controls
+ */
+typedef struct rtems_nvdisk_device_ctl
+{
+ /**
+ * The device this segment resides on.
+ */
+ uint32_t device;
+
+ /**
+ * Total number of pages in the device.
+ */
+ uint32_t pages;
+
+ /**
+ * Number of pages used for page checksums.
+ */
+ uint32_t pages_desc;
+
+ /**
+ * First block number for this device.
+ */
+ uint32_t block_base;
+
+ /**
+ * Device descriptor.
+ */
+ const rtems_nvdisk_device_desc* descriptor;
+} rtems_nvdisk_device_ctl;
+
+/**
+ * The NV disk control structure for a single disk. There is one
+ * for each minor disk in the system.
+ */
+typedef struct rtems_mvdisk
+{
+ rtems_device_major_number major; /**< The driver's major number. */
+ rtems_device_minor_number minor; /**< The driver's minor number. */
+ uint32_t flags; /**< configuration flags. */
+ uint32_t block_size; /**< The block size for this disk. */
+ uint32_t block_count; /**< The number of available blocks. */
+ rtems_nvdisk_device_ctl* devices; /**< The NV devices for this disk. */
+ uint32_t device_count; /**< The number of NV devices. */
+ uint32_t cs_pages; /**< The num of pages of checksums. */
+ rtems_id lock; /**< Mutex for threading protection.*/
+ uint32_t info_level; /**< The info trace level. */
+} rtems_nvdisk;
+
+/**
+ * The array of NV disks we support.
+ */
+static rtems_nvdisk* rtems_nvdisks;
+
+/**
+ * The number of NV disks we have.
+ */
+static uint32_t rtems_nvdisk_count;
+
+/**
+ * The CRC16 factor table. Created during initialisation.
+ */
+static uint16_t* rtems_nvdisk_crc16_factor;
+
+/**
+ * Calculate the CRC16 checksum.
+ *
+ * @param _b The byte to checksum.
+ * @param _c The current checksum.
+ */
+#define rtems_nvdisk_calc_crc16(_b, _c) \
+ rtems_nvdisk_crc16_factor[((_b) ^ ((_c) & 0xff)) & 0xff] ^ (((_c) >> 8) & 0xff)
+
+/**
+ * Generate the CRC table.
+ *
+ * @param pattern The seed pattern for the table of factors.
+ * @relval RTEMS_SUCCESSFUL The table was generated.
+ * @retval RTEMS_NO_MEMORY The table could not be allocated from the heap.
+ */
+rtems_status_code
+rtems_nvdisk_crc16_gen_factors (uint16_t pattern)
+{
+ uint32_t b;
+
+ rtems_nvdisk_crc16_factor = malloc (sizeof (uint16_t) * 256);
+ if (!rtems_nvdisk_crc16_factor)
+ return RTEMS_NO_MEMORY;
+
+ for (b = 0; b < 256; b++)
+ {
+ uint32_t i;
+ uint16_t v = b;
+ for (i = 8; i--;)
+ v = v & 1 ? (v >> 1) ^ pattern : v >> 1;
+ rtems_nvdisk_crc16_factor[b] = v & 0xffff;
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+#if RTEMS_NVDISK_TRACE
+/**
+ * Print a message to the nvdisk output and flush it.
+ *
+ * @param nvd The nvdisk control structure.
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_nvdisk_printf (const rtems_nvdisk* nvd, const char *format, ...)
+{
+ int ret = 0;
+ if (nvd->info_level >= 3)
+ {
+ va_list args;
+ va_start (args, format);
+ fprintf (stdout, "nvdisk:");
+ ret = vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ fflush (stdout);
+ va_end (args);
+ }
+ return ret;
+}
+
+/**
+ * Print a info message to the nvdisk output and flush it.
+ *
+ * @param nvd The nvdisk control structure.
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_nvdisk_info (const rtems_nvdisk* nvd, const char *format, ...)
+{
+ int ret = 0;
+ if (nvd->info_level >= 2)
+ {
+ va_list args;
+ va_start (args, format);
+ fprintf (stdout, "nvdisk:");
+ ret = vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ fflush (stdout);
+ va_end (args);
+ }
+ return ret;
+}
+
+/**
+ * Print a warning to the nvdisk output and flush it.
+ *
+ * @param nvd The nvdisk control structure.
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_nvdisk_warning (const rtems_nvdisk* nvd, const char *format, ...)
+{
+ int ret = 0;
+ if (nvd->info_level >= 1)
+ {
+ va_list args;
+ va_start (args, format);
+ fprintf (stdout, "nvdisk:warning:");
+ ret = vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ fflush (stdout);
+ va_end (args);
+ }
+ return ret;
+}
+#endif
+
+/**
+ * Print an error to the nvdisk output and flush it.
+ *
+ * @param format The format string. See printf for details.
+ * @param ... The arguments for the format text.
+ * @return int The number of bytes written to the output.
+ */
+static int
+rtems_nvdisk_error (const char *format, ...)
+{
+ int ret;
+ va_list args;
+ va_start (args, format);
+ fprintf (stderr, "nvdisk:error:");
+ ret = vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+ fflush (stderr);
+ va_end (args);
+ return ret;
+}
+
+/**
+ * Get the descriptor for a device.
+ */
+static const rtems_nvdisk_device_desc*
+rtems_nvdisk_device_descriptor (const rtems_nvdisk* nvd, uint32_t device)
+{
+ return nvd->devices[device].descriptor;
+}
+
+/**
+ * Read a block of data from a device.
+ */
+static int
+rtems_nvdisk_device_read (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t offset,
+ void* buffer,
+ uint32_t size)
+{
+ const rtems_nvdisk_device_desc* dd;
+ const rtems_nvdisk_driver_handlers* ops;
+ dd = rtems_nvdisk_device_descriptor (nvd, device);
+ ops = nvd->devices[device].descriptor->nv_ops;
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_printf (nvd, " dev-read: %02d-%08x: s=%d",
+ device, offset, size);
+#endif
+ return ops->read (device, dd->flags, dd->base, offset, buffer, size);
+}
+
+/**
+ * Write a block of data to a device.
+ */
+static int
+rtems_nvdisk_device_write (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t offset,
+ const void* buffer,
+ uint32_t size)
+{
+ const rtems_nvdisk_device_desc* dd;
+ const rtems_nvdisk_driver_handlers* ops;
+ dd = rtems_nvdisk_device_descriptor (nvd, device);
+ ops = nvd->devices[device].descriptor->nv_ops;
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_printf (nvd, " dev-write: %02d-%08x: s=%d",
+ device, offset, size);
+#endif
+ return ops->write (device, dd->flags, dd->base, offset, buffer, size);
+}
+
+#if NOT_USED
+/**
+ * Verify the data with the data in a segment.
+ */
+static int
+rtems_nvdisk_device_verify (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t offset,
+ const void* buffer,
+ uint32_t size)
+{
+ const rtems_nvdisk_device_desc* dd;
+ const rtems_nvdisk_driver_handlers* ops;
+ dd = rtems_nvdisk_device_descriptor (nvd, device);
+ ops = nvd->devices[device].descriptor->nv_ops;
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_printf (nvd, " seg-verify: %02d-%08x: s=%d",
+ device, offset, size);
+#endif
+ return ops->verify (device, dd->flags, dd->base, offset, buffer, size);
+}
+#endif
+
+/**
+ * Read a page of data from the device.
+ */
+static int
+rtems_nvdisk_read_page (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t page,
+ void* buffer)
+{
+ return rtems_nvdisk_device_read (nvd, device,
+ page * nvd->block_size, buffer,
+ nvd->block_size);
+}
+
+/**
+ * Write a page of data to a device.
+ */
+static int
+rtems_nvdisk_write_page (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t page,
+ const void* buffer)
+{
+ return rtems_nvdisk_device_write (nvd, device,
+ page * nvd->block_size,
+ buffer, nvd->block_size);
+}
+
+/**
+ * Read the checksum from the device.
+ */
+static int
+rtems_nvdisk_read_checksum (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t page,
+ uint16_t* cs)
+{
+ return rtems_nvdisk_device_read (nvd, device,
+ page * sizeof (uint16_t),
+ cs, sizeof (uint16_t));
+}
+
+/**
+ * Write the checksum to the device.
+ */
+static int
+rtems_nvdisk_write_checksum (const rtems_nvdisk* nvd,
+ uint32_t device,
+ uint32_t page,
+ const uint16_t cs)
+{
+ return rtems_nvdisk_device_write (nvd, device,
+ page * sizeof (uint16_t),
+ &cs, sizeof (uint16_t));
+}
+
+/**
+ * Calculate the pages in a device give the device descriptor and the
+ * page size.
+ *
+ * @param dd The device descriptor.
+ * @param page_size The page size in bytes.
+ */
+static uint32_t
+rtems_nvdisk_pages_in_device (const rtems_nvdisk* nvd,
+ const rtems_nvdisk_device_desc* dd)
+{
+ return dd->size / nvd->block_size;
+}
+
+/**
+ * Calculate the number of pages needed to hold the page descriptors.
+ * The calculation need to round up.
+ */
+static uint32_t
+rtems_nvdisk_page_desc_pages (const rtems_nvdisk* nvd,
+ const rtems_nvdisk_device_desc* dd)
+{
+ uint32_t pages = rtems_nvdisk_pages_in_device (nvd, dd);
+ uint32_t bytes = pages * sizeof (uint16_t);
+ return ((bytes - 1) / nvd->block_size) + 1;
+}
+
+/**
+ * Calculate the checksum of a page.
+ */
+static uint16_t
+rtems_nvdisk_page_checksum (const uint8_t* buffer, uint32_t page_size)
+{
+ uint16_t cs = 0xffff;
+ uint32_t i;
+
+ for (i = 0; i < page_size; i++, buffer++)
+ cs = rtems_nvdisk_calc_crc16 (cs, *buffer);
+
+ return cs;
+}
+
+/**
+ * Map a block to a device.
+ */
+static rtems_nvdisk_device_ctl*
+rtems_nvdisk_get_device (rtems_nvdisk* nvd, uint32_t block)
+{
+ uint32_t device;
+
+ if (block >= nvd->block_count)
+ {
+ rtems_nvdisk_error ("read-block: bad block: %d", block);
+ return NULL;
+ }
+
+ for (device = 0; device < nvd->device_count; device++)
+ {
+ rtems_nvdisk_device_ctl* dc = &nvd->devices[device];
+ if ((block >= dc->block_base) &&
+ (block < (dc->block_base + dc->pages - dc->pages_desc)))
+ return dc;
+ }
+
+ rtems_nvdisk_error ("map-block:%d: no device/page map found", block);
+
+ return NULL;
+}
+
+/**
+ * Get the page for a block in a device.
+ */
+static uint32_t
+rtems_nvdisk_get_page (rtems_nvdisk_device_ctl* dc,
+ uint32_t block)
+{
+ return block - dc->block_base;
+}
+
+/**
+ * Read a block. The block is checked to see if the page referenced
+ * is valid and the page has a valid crc.
+ *
+ * @param nvd The rtems_nvdisk control table.
+ * @param block The block number to read.
+ * @param buffer The buffer to write the data into.
+ * @return 0 No error.
+ * @return EIO Invalid block number or crc.
+ */
+static int
+rtems_nvdisk_read_block (rtems_nvdisk* nvd, uint32_t block, uint8_t* buffer)
+{
+ rtems_nvdisk_device_ctl* dc;
+ uint32_t page;
+ uint16_t crc;
+ uint16_t cs;
+ int ret;
+
+ dc = rtems_nvdisk_get_device (nvd, block);
+
+ if (!dc)
+ return EIO;
+
+ page = rtems_nvdisk_get_page (dc, block);
+
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_info (nvd, " read-block:%d=>%02d-%03d, cs:%04x",
+ block, dc->device, page, crc);
+#endif
+
+ ret = rtems_nvdisk_read_checksum (nvd, dc->device, page, &crc);
+
+ if (ret)
+ return ret;
+
+ if (crc == 0xffff)
+ {
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_warning (nvd, "read-block: crc not set: %d", block);
+#endif
+ memset (buffer, 0, nvd->block_size);
+ return 0;
+ }
+
+ ret = rtems_nvdisk_read_page (nvd, dc->device, page + dc->pages_desc, buffer);
+
+ if (ret)
+ return ret;
+
+ cs = rtems_nvdisk_page_checksum (buffer, nvd->block_size);
+
+ if (cs != crc)
+ {
+ rtems_nvdisk_error ("read-block: crc failure: %d: buffer:%04x page:%04x",
+ block, cs, crc);
+ return EIO;
+ }
+
+ return 0;
+}
+
+/**
+ * Write a block.
+ *
+ * @param nvd The rtems_nvdisk control table.
+ * @param block The block number to read.
+ * @param block_size The size of the block. Must match what we have.
+ * @param buffer The buffer to write the data into.
+ * @return 0 No error.
+ * @return EIO Invalid block size, block number, segment pointer, crc,
+ * page flags.
+ */
+static int
+rtems_nvdisk_write_block (rtems_nvdisk* nvd,
+ uint32_t block,
+ const unsigned char* buffer)
+{
+ rtems_nvdisk_device_ctl* dc;
+ uint32_t page;
+ uint16_t cs;
+ int ret;
+
+ dc = rtems_nvdisk_get_device (nvd, block);
+
+ if (!dc)
+ return EIO;
+
+ page = rtems_nvdisk_get_page (dc, block);
+
+ cs = rtems_nvdisk_page_checksum (buffer, nvd->block_size);
+
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_info (nvd, " write-block:%d=>%02d-%03d", block, dc->device, page);
+#endif
+
+ ret = rtems_nvdisk_write_page (nvd, dc->device, page + dc->pages_desc, buffer);
+
+ if (ret)
+ return ret;
+
+ return rtems_nvdisk_write_checksum (nvd, dc->device, page, cs);
+}
+
+/**
+ * Disk READ request handler. This primitive copies data from the
+ * flash disk to the supplied buffer and invoke the callout function
+ * to inform upper layer that reading is completed.
+ *
+ * @param req Pointer to the READ block device request info.
+ * @retval int The ioctl return value.
+ */
+static int
+rtems_nvdisk_read (rtems_nvdisk* nvd, rtems_blkdev_request* req)
+{
+ rtems_blkdev_sg_buffer* sg = req->bufs;
+ uint32_t bufs;
+ int ret = 0;
+
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_info (nvd, "read: blocks=%d", req->bufnum);
+#endif
+
+ for (bufs = 0; (ret == 0) && (bufs < req->bufnum); bufs++, sg++)
+ {
+ uint8_t* data;
+ uint32_t nvb;
+ uint32_t b;
+ nvb = sg->length / nvd->block_size;
+ data = sg->buffer;
+ for (b = 0; b < nvb; b++, data += nvd->block_size)
+ {
+ ret = rtems_nvdisk_read_block (nvd, sg->block + b, data);
+ if (ret)
+ break;
+ }
+ }
+
+ req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
+ req->req_done (req->done_arg, req->status);
+
+ return ret;
+}
+
+/**
+ * Flash disk WRITE request handler. This primitive copies data from
+ * supplied buffer to NV disk and invoke the callout function to inform
+ * upper layer that writing is completed.
+ *
+ * @param req Pointers to the WRITE block device request info.
+ * @retval int The ioctl return value.
+ */
+static int
+rtems_nvdisk_write (rtems_nvdisk* nvd, rtems_blkdev_request* req)
+{
+ rtems_blkdev_sg_buffer* sg = req->bufs;
+ uint32_t bufs;
+ int ret = 0;
+
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_info (nvd, "write: blocks=%d", req->bufnum);
+#endif
+
+ for (bufs = 0; (ret == 0) && (bufs < req->bufnum); bufs++, sg++)
+ {
+ uint8_t* data;
+ uint32_t nvb;
+ uint32_t b;
+ nvb = sg->length / nvd->block_size;
+ data = sg->buffer;
+ for (b = 0; b < nvb; b++, data += nvd->block_size)
+ {
+ ret = rtems_nvdisk_write_block (nvd, sg->block + b, data);
+ if (ret)
+ break;
+ }
+ }
+
+ req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
+ req->req_done (req->done_arg, req->status);
+
+ return 0;
+}
+
+/**
+ * NV disk erase disk sets all the checksums for 0xffff.
+ *
+ * @param nvd The nvdisk data.
+ * @retval int The ioctl return value.
+ */
+static int
+rtems_nvdisk_erase_disk (rtems_nvdisk* nvd)
+{
+ uint32_t device;
+
+#if RTEMS_NVDISK_TRACE
+ rtems_nvdisk_info (nvd, "erase-disk");
+#endif
+
+ for (device = 0; device < nvd->device_count; device++)
+ {
+ rtems_nvdisk_device_ctl* dc = &nvd->devices[device];
+ uint32_t page;
+ for (page = 0; page < (dc->pages - dc->pages_desc); page++)
+ {
+ int ret = rtems_nvdisk_write_checksum (nvd, dc->device, page, 0xffff);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * NV disk IOCTL handler.
+ *
+ * @param dd Disk device.
+ * @param req IOCTL request code.
+ * @param argp IOCTL argument.
+ * @retval The IOCTL return value
+ */
+static int
+rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
+{
+ dev_t dev = rtems_disk_get_device_identifier (dd);
+ rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
+ rtems_blkdev_request* r = argp;
+ rtems_status_code sc;
+
+ if (minor >= rtems_nvdisk_count)
+ {
+ errno = ENODEV;
+ return -1;
+ }
+
+ if (rtems_nvdisks[minor].device_count == 0)
+ {
+ errno = ENODEV;
+ return -1;
+ }
+
+ errno = 0;
+
+ sc = rtems_semaphore_obtain (rtems_nvdisks[minor].lock, RTEMS_WAIT, 0);
+ if (sc != RTEMS_SUCCESSFUL)
+ errno = EIO;
+ else
+ {
+ errno = 0;
+ switch (req)
+ {
+ case RTEMS_BLKIO_REQUEST:
+ switch (r->req)
+ {
+ case RTEMS_BLKDEV_REQ_READ:
+ errno = rtems_nvdisk_read (&rtems_nvdisks[minor], r);
+ break;
+
+ case RTEMS_BLKDEV_REQ_WRITE:
+ errno = rtems_nvdisk_write (&rtems_nvdisks[minor], r);
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+ break;
+
+ case RTEMS_NVDISK_IOCTL_ERASE_DISK:
+ errno = rtems_nvdisk_erase_disk (&rtems_nvdisks[minor]);
+ break;
+
+ case RTEMS_NVDISK_IOCTL_INFO_LEVEL:
+ rtems_nvdisks[minor].info_level = (uintptr_t) argp;
+ break;
+
+ default:
+ rtems_blkdev_ioctl (dd, req, argp);
+ break;
+ }
+
+ sc = rtems_semaphore_release (rtems_nvdisks[minor].lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ errno = EIO;
+ }
+
+ return errno == 0 ? 0 : -1;
+}
+
+/**
+ * NV disk device driver initialization.
+ *
+ * @todo Memory clean up on error is really badly handled.
+ *
+ * @param major NV disk major device number.
+ * @param minor Minor device number, not applicable.
+ * @param arg Initialization argument, not applicable.
+ */
+rtems_device_driver
+rtems_nvdisk_initialize (rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void* arg __attribute__((unused)))
+{
+ const rtems_nvdisk_config* c = rtems_nvdisk_configuration;
+ rtems_nvdisk* nvd;
+ rtems_status_code sc;
+
+ sc = rtems_disk_io_initialize ();
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ sc = rtems_nvdisk_crc16_gen_factors (0x8408);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ rtems_nvdisks = calloc (rtems_nvdisk_configuration_size,
+ sizeof (rtems_nvdisk));
+
+ if (!rtems_nvdisks)
+ return RTEMS_NO_MEMORY;
+
+ for (minor = 0; minor < rtems_nvdisk_configuration_size; minor++, c++)
+ {
+ char name[] = RTEMS_NVDISK_DEVICE_BASE_NAME "a";
+ dev_t dev = rtems_filesystem_make_dev_t (major, minor);
+ uint32_t device;
+ uint32_t blocks = 0;
+
+ nvd = &rtems_nvdisks[minor];
+
+ name [sizeof(RTEMS_NVDISK_DEVICE_BASE_NAME)] += minor;
+
+ nvd->major = major;
+ nvd->minor = minor;
+ nvd->flags = c->flags;
+ nvd->block_size = c->block_size;
+ nvd->info_level = c->info_level;
+
+ nvd->devices = calloc (c->device_count, sizeof (rtems_nvdisk_device_ctl));
+ if (!nvd->devices)
+ return RTEMS_NO_MEMORY;
+
+ for (device = 0; device < c->device_count; device++)
+ {
+ rtems_nvdisk_device_ctl* dc = &nvd->devices[device];
+
+ dc->device = device;
+ dc->pages = rtems_nvdisk_pages_in_device (nvd, &c->devices[device]);
+ dc->pages_desc = rtems_nvdisk_page_desc_pages (nvd, &c->devices[device]);
+ dc->block_base = blocks;
+
+ blocks += dc->pages - dc->pages_desc;
+
+ dc->descriptor = &c->devices[device];
+ }
+
+ nvd->block_count = blocks;
+ nvd->device_count = c->device_count;
+
+ sc = rtems_disk_create_phys(dev, c->block_size, blocks,
+ rtems_nvdisk_ioctl, NULL, name);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_nvdisk_error ("disk create phy failed");
+ return sc;
+ }
+
+ sc = rtems_semaphore_create (rtems_build_name ('N', 'V', 'D', 'K'), 1,
+ RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE |
+ RTEMS_INHERIT_PRIORITY, 0, &nvd->lock);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_nvdisk_error ("disk lock create failed");
+ return sc;
+ }
+ }
+
+ rtems_nvdisk_count = rtems_nvdisk_configuration_size;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/ramdisk-config.c b/cpukit/libblock/src/ramdisk-config.c
new file mode 100644
index 0000000000..255240668b
--- /dev/null
+++ b/cpukit/libblock/src/ramdisk-config.c
@@ -0,0 +1,90 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_ramdisk
+ *
+ * @brief RAM disk block device implementation.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/ramdisk.h>
+
+rtems_device_driver
+ramdisk_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *arg __attribute__((unused)))
+{
+ rtems_device_minor_number i;
+ rtems_ramdisk_config *c = rtems_ramdisk_configuration;
+ struct ramdisk *r;
+ rtems_status_code rc;
+
+ rc = rtems_disk_io_initialize();
+ if (rc != RTEMS_SUCCESSFUL)
+ return rc;
+
+ /*
+ * Coverity Id 27 notes that this calloc() is a resource leak.
+ *
+ * This is allocating memory for a RAM disk which will persist for
+ * the life of the system. RTEMS has no "de-initialize" driver call
+ * so there is no corresponding free(r). Coverity is correct that
+ * it is never freed but this is not a problem.
+ */
+ r = calloc(rtems_ramdisk_configuration_size, sizeof(struct ramdisk));
+ r->trace = false;
+ for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++)
+ {
+ dev_t dev = rtems_filesystem_make_dev_t(major, i);
+ char name [] = RAMDISK_DEVICE_BASE_NAME "a";
+ name [sizeof(RAMDISK_DEVICE_BASE_NAME)] += i;
+ r->block_size = c->block_size;
+ r->block_num = c->block_num;
+ if (c->location == NULL)
+ {
+ r->malloced = true;
+ r->area = malloc(r->block_size * r->block_num);
+ if (r->area == NULL) /* No enough memory for this disk */
+ {
+ r->initialized = false;
+ continue;
+ }
+ else
+ {
+ r->initialized = true;
+ }
+ }
+ else
+ {
+ r->malloced = false;
+ r->initialized = true;
+ r->area = c->location;
+ }
+ rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
+ ramdisk_ioctl, r, name);
+ if (rc != RTEMS_SUCCESSFUL)
+ {
+ if (r->malloced)
+ {
+ free(r->area);
+ }
+ r->initialized = false;
+ }
+ }
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/ramdisk-driver.c b/cpukit/libblock/src/ramdisk-driver.c
new file mode 100644
index 0000000000..2bc8d27962
--- /dev/null
+++ b/cpukit/libblock/src/ramdisk-driver.c
@@ -0,0 +1,134 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_ramdisk
+ *
+ * @brief RAM disk block device implementation.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* FIXME: How to set this define? */
+#if !defined(RTEMS_RAMDISK_TRACE)
+ #define RTEMS_RAMDISK_TRACE 0
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#if RTEMS_RAMDISK_TRACE
+ #include <stdio.h>
+#endif
+
+#include <rtems.h>
+#include <rtems/ramdisk.h>
+
+#if RTEMS_RAMDISK_TRACE
+ static void
+ rtems_ramdisk_printf (const ramdisk *rd, const char *format, ...)
+ {
+ if (rd->trace)
+ {
+ va_list args;
+ va_start (args, format);
+ printf ("ramdisk:");
+ vprintf (format, args);
+ printf ("\n");
+ }
+ }
+#endif
+
+static int
+ramdisk_read(struct ramdisk *rd, rtems_blkdev_request *req)
+{
+ uint8_t *from = rd->area;
+ uint32_t i;
+ rtems_blkdev_sg_buffer *sg;
+
+#if RTEMS_RAMDISK_TRACE
+ rtems_ramdisk_printf (rd, "ramdisk read: start=%d, blocks=%d",
+ req->bufs[0].block, req->bufnum);
+#endif
+
+ for (i = 0, sg = req->bufs; i < req->bufnum; i++, sg++)
+ {
+#if RTEMS_RAMDISK_TRACE
+ rtems_ramdisk_printf (rd, "ramdisk read: buf=%d block=%d length=%d off=%d addr=%p",
+ i, sg->block, sg->length, sg->block * rd->block_size,
+ from + (sg->block * rd->block_size));
+#endif
+ memcpy(sg->buffer, from + (sg->block * rd->block_size), sg->length);
+ }
+ req->status = RTEMS_SUCCESSFUL;
+ req->req_done(req->done_arg, RTEMS_SUCCESSFUL);
+ return 0;
+}
+
+static int
+ramdisk_write(struct ramdisk *rd, rtems_blkdev_request *req)
+{
+ uint8_t *to = rd->area;
+ uint32_t i;
+ rtems_blkdev_sg_buffer *sg;
+
+#if RTEMS_RAMDISK_TRACE
+ rtems_ramdisk_printf (rd, "ramdisk write: start=%d, blocks=%d",
+ req->bufs[0].block, req->bufnum);
+#endif
+ for (i = 0, sg = req->bufs; i < req->bufnum; i++, sg++)
+ {
+#if RTEMS_RAMDISK_TRACE
+ rtems_ramdisk_printf (rd, "ramdisk write: buf=%d block=%d length=%d off=%d addr=%p",
+ i, sg->block, sg->length, sg->block * rd->block_size,
+ to + (sg->block * rd->block_size));
+#endif
+ memcpy(to + (sg->block * rd->block_size), sg->buffer, sg->length);
+ }
+ req->status = RTEMS_SUCCESSFUL;
+ req->req_done(req->done_arg, RTEMS_SUCCESSFUL);
+ return 0;
+}
+
+int
+ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
+{
+ switch (req)
+ {
+ case RTEMS_BLKIO_REQUEST:
+ {
+ rtems_blkdev_request *r = argp;
+ struct ramdisk *rd = rtems_disk_get_driver_data(dd);
+
+ switch (r->req)
+ {
+ case RTEMS_BLKDEV_REQ_READ:
+ return ramdisk_read(rd, r);
+
+ case RTEMS_BLKDEV_REQ_WRITE:
+ return ramdisk_write(rd, r);
+
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+ break;
+ }
+
+ default:
+ return rtems_blkdev_ioctl (dd, req, argp);
+ break;
+ }
+
+ errno = EINVAL;
+ return -1;
+}
diff --git a/cpukit/libblock/src/ramdisk-init.c b/cpukit/libblock/src/ramdisk-init.c
new file mode 100644
index 0000000000..fb8def0d83
--- /dev/null
+++ b/cpukit/libblock/src/ramdisk-init.c
@@ -0,0 +1,126 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_ramdisk
+ *
+ * @brief RAM disk block device implementation.
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/ramdisk.h>
+
+const rtems_driver_address_table ramdisk_ops = {
+ .initialization_entry = NULL,
+ RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES
+};
+
+ramdisk *ramdisk_allocate(
+ void *area_begin,
+ uint32_t block_size,
+ rtems_blkdev_bnum block_count,
+ bool trace
+)
+{
+ struct ramdisk *rd = malloc(sizeof(struct ramdisk));
+
+ if (rd == NULL) {
+ return NULL;
+ }
+
+ if (area_begin == NULL) {
+ area_begin = calloc(block_count, block_size);
+ if (area_begin == NULL) {
+ free(rd);
+
+ return NULL;
+ }
+ rd->malloced = true;
+ } else {
+ rd->malloced = false;
+ }
+ rd->block_size = block_size;
+ rd->block_num = block_count;
+ rd->area = area_begin;
+ rd->trace = trace;
+ rd->initialized = true;
+
+ return rd;
+}
+
+void ramdisk_free(ramdisk *rd)
+{
+ if (rd != NULL) {
+ if (rd->malloced) {
+ free(rd->area);
+ }
+ free(rd);
+ }
+}
+
+rtems_status_code ramdisk_register(
+ uint32_t block_size,
+ rtems_blkdev_bnum block_count,
+ bool trace,
+ const char *disk,
+ dev_t *dev_ptr
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_device_major_number major = 0;
+ ramdisk *rd = NULL;
+ dev_t dev = 0;
+
+ sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
+ if (sc != RTEMS_SUCCESSFUL) {
+ return RTEMS_UNSATISFIED;
+ }
+
+ rd = ramdisk_allocate(NULL, block_size, block_count, trace);
+ if (rd == NULL) {
+ rtems_io_unregister_driver(major);
+
+ return RTEMS_UNSATISFIED;
+ }
+
+ dev = rtems_filesystem_make_dev_t(major, 0);
+
+ sc = rtems_disk_create_phys(
+ dev,
+ block_size,
+ block_count,
+ ramdisk_ioctl,
+ rd,
+ disk
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ ramdisk_free(rd);
+ rtems_io_unregister_driver(major);
+
+ return RTEMS_UNSATISFIED;
+ }
+
+ *dev_ptr = dev;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libblock/src/show_bdbuf.c b/cpukit/libblock/src/show_bdbuf.c
new file mode 100644
index 0000000000..74ff9922aa
--- /dev/null
+++ b/cpukit/libblock/src/show_bdbuf.c
@@ -0,0 +1,909 @@
+/*===============================================================*\
+| Project: RTEMS bdbuf inspector |
++-----------------------------------------------------------------+
+| File: show_bdbuf.c
++-----------------------------------------------------------------+
+| Copyright (c) 2005 |
+| Embedded Brains GmbH |
+| Obere Lagerstr. 30 |
+| D-82178 Puchheim |
+| Germany |
+| rtems@embedded-brains.de |
++-----------------------------------------------------------------+
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| this file contains functions to enable the monitor |
+| to show bdbuf information |
+| |
+| XXX!!! ATTETION!!! XXX!!! |
+| |
+| This module inspects the bdbuf data structures, |
+| assuming they are static, but in fact they are used very |
+| dynamically. Therefore the results show MAY BE INCORRECT in |
+| some cases. And, to cure this a bit, this module may block |
+| preemption for a rather long time and therefore it may |
+| BREAK THE REALTIME BEHAVIOUR OF YOUR SYSTEM (when in use) |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 26.09.06 creation doe |
+|*****************************************************************|
+\*===============================================================*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/bdbuf.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <rtems/libio.h>
+#include <inttypes.h>
+
+typedef struct {
+ bool bdbuf_modified;
+ bool bdbuf_in_progress;
+ bool bdbuf_actual;
+ bool bdbuf_used;
+ bool bdbuf_all;
+ rtems_bdpool_id pool_id;
+} show_bdbuf_filter_t;
+
+typedef struct {
+ bool show_all;
+ bool show_node_chain;
+ bool show_dev;
+ bool show_blocknum;
+ bool show_error;
+ bool show_state;
+ bool show_use_count;
+ bool show_pool_id;
+ bool show_sema;
+} show_bdbuf_selector_t;
+
+typedef enum {bdbuf_chain_ident_none,
+ bdbuf_chain_ident_free,
+ bdbuf_chain_ident_lru,
+ bdbuf_chain_ident_mod} bdbuf_chain_identifier_t;
+
+typedef struct {
+ rtems_bdpool_id pool_id;
+ int index;
+ bdbuf_chain_identifier_t in_chain;
+ dev_t dev;
+ blkdev_bnum blknum;
+ rtems_status_code status;
+ int error;
+ bool modified;
+ bool in_progress;
+ bool actual;
+ int use_count;
+ const CORE_mutex_Control *sema;
+} show_bdbuf_bdbuf_info_t;
+
+typedef rtems_mode preemption_key_t;
+#define DISABLE_PREEMPTION(key) \
+ do { \
+ rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &(key)); \
+ } while (0)
+
+#define ENABLE_PREEMPTION(key) \
+ do { \
+ rtems_mode temp; \
+ rtems_task_mode((key), RTEMS_PREEMPT_MASK, &temp); \
+ } while (0)
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_follow_chain_node_to_head
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| follow a given chain to its head |
+| XXX: this is executed with preemption disabled |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const Chain_Node *the_node, /* input: node to track to its head */
+ Chain_Control **the_head /* storage for pointer to chain head */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ preemption_key_t preempt_key;
+ bool preempt_disabled = false;
+ /*
+ * disable preemption
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ DISABLE_PREEMPTION(preempt_key);
+ }
+ /*
+ * follow node to its head
+ * XXX: this is highly dependent on the chain implementation
+ * in score/src/chain.c and friends
+ */
+ while (the_node->previous != NULL) {
+ the_node = the_node->previous;
+ }
+ /*
+ * reenable preemption, if disabled
+ */
+ if (preempt_disabled) {
+ ENABLE_PREEMPTION(preempt_key);
+ }
+ /*
+ * XXX: this depends n the chain implementation in
+ * score/include/rtems/score/chain.h:
+ * Chain_Control is overlayed by two Cohain_Nodes
+ */
+ *the_head = (Chain_Control *)the_node;
+
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_determine_chain_of_bdbuf
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| find out, which chain this bdbuf is linked in |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const bdbuf_buffer *the_bdbuf, /* this is the bdbuf structure */
+ const bdbuf_pool *curr_pool, /* the pool this buffer belongs to */
+ bdbuf_chain_identifier_t *chn_ident /* result: identifier for chain */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ Chain_Control *the_chain_control;
+
+
+ *chn_ident = bdbuf_chain_ident_none;
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_follow_chain_node_to_head(&(the_bdbuf->link),
+ &(the_chain_control));
+ }
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (the_chain_control == &(curr_pool->free)) {
+ *chn_ident = bdbuf_chain_ident_free;
+ }
+ else if (the_chain_control == &(curr_pool->lru)) {
+ *chn_ident = bdbuf_chain_ident_lru;
+ }
+ else if (the_chain_control == &(rtems_bdbuf_ctx.mod)) {
+ *chn_ident = bdbuf_chain_ident_mod;
+ }
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_getargs
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| analyze cmd arguments |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int argc,
+ char **argv,
+ show_bdbuf_filter_t *filter,
+ show_bdbuf_selector_t *selector
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int arg_error = 0;
+ int i;
+ char *tmp_ptr;
+ int nm_argc = 0;
+ /*
+ * set filter and selector to default
+ */
+ memset(filter,0,sizeof(*filter));
+ filter->bdbuf_all = true;
+ memset(selector,0,sizeof(*selector));
+ selector->show_all = true;
+
+ /*
+ * scan arguments
+ */
+ for (i = 1;
+ (i < argc) && (arg_error == 0);
+ i++) {
+ if (argv[i][0] == '-') {
+ /*
+ * modifier arguments
+ */
+ switch(tolower(argv[i][1])) {
+ /*
+ * selection, which bdbufs to show
+ */
+ case 'm': /* only show bdbufs modified */
+ filter->bdbuf_modified = true ;
+ filter->bdbuf_all = false;
+ break;
+ case 'i': /* only show bdbufs in progress*/
+ filter->bdbuf_in_progress = true ;
+ filter->bdbuf_all = false;
+ break;
+ case 'v': /* only show bdbufs, which have valid data*/
+ filter->bdbuf_actual = true ;
+ filter->bdbuf_all = false;
+ break;
+ case 'u': /* only show bdbufs, which are in use */
+ filter->bdbuf_used = true ;
+ filter->bdbuf_all = false;
+ break;
+ case 'p': /* only show bdbufs, which belong to pool <n> */
+ filter->pool_id = strtol(argv[i]+2,&tmp_ptr,0);
+ if (tmp_ptr == argv[i]+2) { /* no conversion performed... */
+ arg_error = i;
+ }
+ filter->bdbuf_all = false;
+ break;
+ /*
+ * selection, what fields to show
+ */
+ case 'n': /* show bdbuf node_chain */
+ selector->show_node_chain = true ;
+ selector->show_all = false;
+ break;
+ case 'd': /* show device */
+ selector->show_dev = true ;
+ selector->show_all = false;
+ break;
+ case 'b': /* show blocknum */
+ selector->show_blocknum = true ;
+ selector->show_all = false;
+ break;
+ case 'e': /* show bdbuf error status */
+ selector->show_error = true ;
+ selector->show_all = false;
+ break;
+ case 's': /* show bdbuf state */
+ selector->show_state = true ;
+ selector->show_all = false;
+ break;
+ case 'c': /* show bdbuf use count */
+ selector->show_use_count = true ;
+ selector->show_all = false;
+ break;
+ case 'l': /* show bdbuf pool id */
+ selector->show_pool_id = true ;
+ selector->show_all = false;
+ break;
+ case 't': /* show bdbuf transfer sema */
+ selector->show_sema = true ;
+ break;
+ default:
+ arg_error = i;
+ break;
+ }
+ }
+ else {
+ /*
+ * non-modifier arguments
+ */
+ switch(++nm_argc) {
+ default: /* no further arguments defined */
+ arg_error = i;
+ break;
+ }
+ }
+ }
+ if (arg_error) {
+ printf("%s: unknown argument %s\n",argv[0],argv[arg_error]);
+ sc = RTEMS_NOT_DEFINED;
+ }
+ return sc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_get_bufpool
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| get buffer pool information |
+| XXX: this should be coupled closer to the bdbuf.c module |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ struct bdbuf_pool **pool_base_pptr,
+ int *pool_cnt_ptr
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+#if 0
+ rtems_status_code pool_rc = RTEMS_SUCCESSFUL;
+ struct bdbuf_pool *curr_pool,*pool_base, *pool_top;
+ int pool_cnt;
+ int pool_probe_size;
+ /*
+ * get first buffer pool
+ * XXX: this is highly dependent on how pools are defined
+ * and maintained in bdbuf.c
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ /*
+ * try all possible pool sizes, get highest/lowest pool address
+ */
+ pool_base = NULL;
+ pool_top = NULL;
+ curr_pool = NULL;
+ for (pool_probe_size = 1;
+ pool_probe_size < (INT_MAX>>1) && (pool_rc == RTEMS_SUCCESSFUL);
+ pool_probe_size <<= 1) {
+ pool_rc = rtems_bdbuf_find_pool(pool_probe_size,&curr_pool);
+ if (pool_rc == RTEMS_SUCCESSFUL) {
+ if (pool_base > curr_pool) {
+ pool_base = curr_pool;
+ }
+ if (pool_top < curr_pool) {
+ pool_top = curr_pool;
+ }
+ }
+ }
+ if (pool_base == NULL) {
+ rc = RTEMS_UNSATISFIED;
+ }
+ else {
+ pool_cnt = (pool_top - pool_base) + 1;
+ }
+ }
+ if (rc == RTEMS_SUCCESSFUL) {
+ *pool_base_pptr = pool_base;
+ *pool_cnt_ptr = pool_cnt;
+ }
+#else
+ if (rc == RTEMS_SUCCESSFUL) {
+ *pool_base_pptr = rtems_bdbuf_ctx.pool;
+ *pool_cnt_ptr = rtems_bdbuf_ctx.npools;
+ }
+#endif
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_pool_header
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| print buffer pool information |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int pool_idx,
+ bdbuf_pool *pool_ptr
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ if (rc == RTEMS_SUCCESSFUL) {
+ printf("------------------------------------------------------------------------------\n");
+ printf(" pool #%03d: blksize=%5u nblks=%5u buf_mem=0x%08" PRIxPTR " bdbuf_mem=0x%08" PRIxPTR "\n",
+ pool_idx,
+ pool_ptr->blksize,
+ pool_ptr->nblks,
+ (intptr_t) pool_ptr->mallocd_bufs,
+ (intptr_t) pool_ptr->bdbufs);
+ printf("------------------------------------------------------------------------------\n");
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_get_bdbuf_info
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| get buffer pool information |
+| XXX: this should be coupled closer to the bdbuf.c module |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const bdbuf_buffer *the_bdbuf, /* this is the bdbuf structure */
+ int bdbuf_idx, /* index of bdbuf */
+ const bdbuf_pool *curr_pool, /* the pool this buffer belongs to */
+ show_bdbuf_bdbuf_info_t *bdbuf_info /* struct to store info of bdbuf */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ /*
+ * determine the chain we are in
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_determine_chain_of_bdbuf(the_bdbuf,curr_pool,
+ &(bdbuf_info->in_chain));
+ if (rc != RTEMS_SUCCESSFUL) {
+ bdbuf_info->in_chain = bdbuf_chain_ident_none;
+ rc = RTEMS_SUCCESSFUL;
+ }
+ }
+
+ if (rc == RTEMS_SUCCESSFUL) {
+ bdbuf_info->index = bdbuf_idx;
+ bdbuf_info->dev = the_bdbuf->dev;
+ bdbuf_info->blknum = the_bdbuf->block;
+ bdbuf_info->status = the_bdbuf->status;
+ bdbuf_info->error = the_bdbuf->error;
+ bdbuf_info->modified = the_bdbuf->modified;
+ bdbuf_info->in_progress = the_bdbuf->in_progress;
+ bdbuf_info->actual = the_bdbuf->actual;
+ bdbuf_info->use_count = the_bdbuf->use_count;
+ bdbuf_info->sema = &(the_bdbuf->transfer_sema);
+ bdbuf_info->pool_id = the_bdbuf->pool;
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_match_filter
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| match bdbuf info with given filter |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const show_bdbuf_bdbuf_info_t *bdbuf_info, /* struct to store info of bdbuf */
+ const show_bdbuf_filter_t *filter,
+ bool *is_match
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ bool unmatch = false;
+
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (filter->bdbuf_all) {
+ unmatch = false;
+ }
+ else {
+ unmatch = ((filter->bdbuf_modified && !bdbuf_info->modified) ||
+ (filter->bdbuf_in_progress && !bdbuf_info->in_progress) ||
+ (filter->bdbuf_actual && !bdbuf_info->actual) ||
+ (filter->bdbuf_used && !(bdbuf_info->use_count > 0)));
+
+ }
+ *is_match = !unmatch;
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_print_wait_chain
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| list tasks waiting in "transfer_sema" chain |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ bdbuf_buffer *the_bdbuf /* this is the bdbuf structure */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ Chain_Control *the_chain_head;
+ const Chain_Node *the_chain_node;
+ int thread_cnt = 0;
+ const Thread_Control *the_thread;
+ Objects_Id thread_id;
+ Objects_Name thread_name;
+ uint32_t thread_name_nonstring;
+ /*
+ * get head of (fifo) wait chain
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ the_chain_head = &(the_bdbuf->transfer_sema.Wait_queue.Queues.Fifo);
+ the_chain_node = _Chain_First(the_chain_head);
+ }
+ /*
+ * walk through thread chain
+ */
+ while ((rc == RTEMS_SUCCESSFUL) &&
+ (the_chain_node != _Chain_Tail( the_chain_head ))) {
+ thread_cnt++;
+ the_thread = (const Thread_Control *)the_chain_node;
+
+ thread_id = the_thread->Object.id;
+ thread_name = the_thread->Object.name;
+ thread_name_nonstring = (uint32_t)thread_name.name_u32;
+ printf("%20s %3d (0x%08" PRIx32 ") %c%c%c%c\n",
+ ((thread_cnt == 1) ? "Threads waiting:" : ""),
+ thread_cnt,thread_id,
+ (char)((thread_name_nonstring >> 24) & 0xff),
+ (char)((thread_name_nonstring >> 16) & 0xff),
+ (char)((thread_name_nonstring >> 8) & 0xff),
+ (char)((thread_name_nonstring >> 0) & 0xff));
+
+ the_chain_node = the_chain_node->next;
+ }
+
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_print
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| print requested bdbuffer information |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const show_bdbuf_bdbuf_info_t *bdbuf_info, /* info of bdbuf */
+ show_bdbuf_selector_t * selector, /* selector, what to show */
+ bool print_header /* true: print header, not info */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ /*
+ * 6 chars: print index of buffer
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (print_header) {
+ printf("INDEX ");
+ }
+ else {
+ printf("%5u ",bdbuf_info->index);
+ }
+ }
+ /*
+ * 3 chars: print info about the pool id of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_use_count))) {
+ if (print_header) {
+ printf("PL ");
+ }
+ else {
+ printf("%2u ",bdbuf_info->pool_id);
+ }
+ }
+
+ /*
+ * 4 chars: print info about chain (lru/free/mod) of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_node_chain))) {
+ if (print_header) {
+ printf("CHN ");
+ }
+ else {
+ printf("%3s ",
+ ((bdbuf_info->in_chain == bdbuf_chain_ident_free) ? "FRE"
+ : (bdbuf_info->in_chain == bdbuf_chain_ident_lru) ? "LRU"
+ : (bdbuf_info->in_chain == bdbuf_chain_ident_mod) ? "MOD"
+ : "???"));
+ }
+ }
+
+ /*
+ * 7 chars: print info about device of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_dev))) {
+ if (print_header) {
+ printf("DEVICE ");
+ }
+ else {
+ printf("%3" PRIu32 "%2" PRIu32,
+ ((bdbuf_info->dev == -1)
+ ? 0 : rtems_filesystem_dev_major_t(bdbuf_info->dev)),
+ ((bdbuf_info->dev == -1)
+ ? 0 : rtems_filesystem_dev_minor_t(bdbuf_info->dev)));
+ }
+ }
+
+ /*
+ * 7 chars: print info about block number of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_blocknum))) {
+ if (print_header) {
+ printf("BLOCK ");
+ }
+ else {
+ printf("%6" PRIu32,bdbuf_info->blknum);
+ }
+ }
+
+ /*
+ * 4 chars: print info about use count of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_use_count))) {
+ if (print_header) {
+ printf("USE ");
+ }
+ else {
+ printf("%3u ",bdbuf_info->use_count);
+ }
+ }
+
+ /*
+ * 4 chars: print info about state of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_state))) {
+ if (print_header) {
+ printf("STA ");
+ }
+ else {
+ printf("%c%c%c ",
+ (bdbuf_info->modified ? 'M' : '.'),
+ (bdbuf_info->in_progress ? 'P' : '.'),
+ (bdbuf_info->actual ? 'A' : '.'));
+ }
+ }
+
+ /*
+ * 42 chars: print info about error of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_error))) {
+ if (print_header) {
+ printf("%20s:%-10s ","RTEMS STATUS","ERRNO");
+ }
+ else {
+ printf("%20s:%-10s ",
+ ((bdbuf_info->status == RTEMS_SUCCESSFUL)
+ ? "SUCCESSFUL" : rtems_status_text(bdbuf_info->status)),
+ ((bdbuf_info->status == RTEMS_SUCCESSFUL)
+ ? "" : strerror(bdbuf_info->error)));
+ }
+ }
+ /*
+ * FIXME: add info about waiting chain
+ */
+ printf("\n");
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void rtems_bdbuf_show_fnc
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| list all bdbufs with their content |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int argc,
+ char **argv,
+ rtems_monitor_command_arg_t* command_arg,
+ bool verbose
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ show_bdbuf_filter_t filter;
+ show_bdbuf_selector_t selector;
+ show_bdbuf_bdbuf_info_t bdbuf_info;
+
+ bdbuf_pool *curr_pool,*pool_base;
+ int pool_cnt,pool_idx;
+ int bdbuf_idx;
+ bool bdbuf_matches;
+ int matched_cnt,un_matched_cnt;
+
+ /*
+ * analyze command line options
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_getargs (argc,argv,
+ &filter,&selector);
+ }
+
+ /*
+ * get buffer pool information
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_get_bufpool(&pool_base,&pool_cnt);
+ if (rc != RTEMS_SUCCESSFUL) {
+ printf("%s: ERROR: no buffer pool found\n",argv[0]);
+ }
+ }
+ /*
+ * for all or selected buffer pool(s)
+ */
+ for (pool_idx = 0;
+ (rc == RTEMS_SUCCESSFUL) && (pool_idx < pool_cnt);
+ pool_idx++) {
+ if ((filter.pool_id < 0) ||
+ (filter.pool_id == pool_idx)) {
+ curr_pool = pool_base + pool_idx;
+ /*
+ * print pool header
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_pool_header(pool_idx,curr_pool);
+ }
+ if (rc == RTEMS_SUCCESSFUL) {
+ matched_cnt = 0;
+ un_matched_cnt = 0;
+ /*
+ * print header for bdbuf
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_show_bdbuf_print(NULL,&selector,
+ true);
+ }
+ /*
+ * for all bdbufs in this pool
+ */
+ for (bdbuf_idx = 0;
+ ((rc == RTEMS_SUCCESSFUL) &&
+ (bdbuf_idx < curr_pool->nblks));
+ bdbuf_idx++) {
+ /*
+ * get infos about bdbuf
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_show_bdbuf_get_bdbuf_info
+ (&(curr_pool->bdbufs[bdbuf_idx]),
+ bdbuf_idx,
+ curr_pool,
+ &bdbuf_info);
+ }
+ /*
+ * check, if bdbuf matches selection criteria
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_show_bdbuf_match_filter(&bdbuf_info,&filter,
+ &bdbuf_matches);
+ }
+ /*
+ * print info about bdbuf
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (bdbuf_matches) {
+ rc = rtems_show_bdbuf_print(&bdbuf_info,&selector,
+ false);
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ selector.show_sema) {
+ rc = rtems_show_bdbuf_print_wait_chain(&(curr_pool->bdbufs[bdbuf_idx]));
+ }
+ matched_cnt++;
+ }
+ else {
+ un_matched_cnt++;
+ }
+ }
+ }
+ /*
+ * print match statistics and footer
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ printf("%d bdbufs printed, %d bdbufs suppressed\n",
+ matched_cnt,un_matched_cnt);
+ }
+ }
+ }
+ }
+}
+
+static rtems_monitor_command_entry_t rtems_show_bdbuf_cmds[] = {
+ {
+ "bdbuf_show",
+ "usage: bdbuf_show\n",
+ 0,
+ rtems_bdbuf_show_fnc,
+ { 0 },
+ 0
+ }
+};
+
+#ifndef ARRAY_CNT
+#define ARRAY_CNT(arr) (sizeof((arr))/sizeof((arr)[0]))
+#endif
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_init
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| add command(s) to monitor |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ void /* none up to now */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int item;
+
+ for (item = 0;
+ (sc == RTEMS_SUCCESSFUL) && (item < ARRAY_CNT(rtems_show_bdbuf_cmds));
+ item++) {
+ if (0 == rtems_monitor_insert_cmd (&rtems_show_bdbuf_cmds[item])) {
+ sc = RTEMS_INVALID_NAME;
+ }
+ }
+ return sc;
+}
diff --git a/cpukit/libcsupport/.cvsignore b/cpukit/libcsupport/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libcsupport/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
new file mode 100644
index 0000000000..95eee5bd77
--- /dev/null
+++ b/cpukit/libcsupport/Makefile.am
@@ -0,0 +1,133 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+noinst_LIBRARIES = libcsupport.a
+libcsupport_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = include/console.h include/clockdrv.h \
+ include/rtems/framebuffer.h include/iosupp.h include/ringbuf.h \
+ include/rtc.h include/spurious.h include/timerdrv.h include/vmeintr.h
+
+## motorola
+
+include_rtems_motoroladir = $(includedir)/rtems/motorola
+
+include_rtems_motorola_HEADERS = include/motorola/mc68230.h \
+ include/motorola/mc68681.h
+
+## rtems
+include_rtems_HEADERS += include/rtems/assoc.h include/rtems/error.h \
+ include/rtems/libcsupport.h include/rtems/libio.h include/rtems/libio_.h \
+ include/rtems/malloc.h include/rtems/termiostypes.h \
+ include/rtems/gxx_wrappers.h
+
+## zilog
+
+include_rtems_zilogdir = $(includedir)/rtems/zilog
+
+include_rtems_zilog_HEADERS = include/zilog/z8036.h include/zilog/z8530.h \
+ include/zilog/z8536.h
+
+## General stuff
+ERROR_C_FILES = src/error.c src/__assert.c
+
+ASSOCIATION_C_FILES = src/assoclocalbyname.c \
+ src/assoclocalbyremotebitfield.c src/assoclocalbyremote.c \
+ src/assocnamebad.c src/assocnamebylocalbitfield.c \
+ src/assocnamebylocal.c src/assocnamebyremotebitfield.c \
+ src/assocnamebyremote.c src/assocptrbylocal.c src/assocptrbyname.c \
+ src/assocptrbyremote.c src/assocremotebylocalbitfield.c \
+ src/assocremotebylocal.c src/assocremotebyname.c
+
+BASE_FS_C_FILES = src/base_fs.c src/mount.c src/unmount.c src/libio.c \
+ src/mount-mgr.c src/mount-mktgt.c src/libio_init.c \
+ src/eval.c src/privateenv.c \
+ src/open_dev_console.c src/__usrenv.c src/rtems_mkdir.c
+
+if LIBNETWORKING
+BASE_FS_C_FILES += src/libio_sockets.c
+endif
+
+TERMIOS_C_FILES = src/cfgetispeed.c src/cfgetospeed.c src/cfsetispeed.c \
+ src/cfsetospeed.c src/tcgetattr.c src/tcsetattr.c src/tcdrain.c \
+ src/tcflow.c src/tcflush.c src/tcgetpgrp.c src/tcsendbreak.c \
+ src/tcsetpgrp.c src/termios.c src/termiosinitialize.c \
+ src/termios_baud2index.c src/termios_baud2num.c src/termios_num2baud.c \
+ src/termios_setinitialbaud.c src/termios_baudtable.c
+
+SYSTEM_CALL_C_FILES = src/open.c src/close.c src/read.c src/write.c \
+ src/write_r.c \
+ src/lseek.c src/ioctl.c src/mkdir.c src/mknod.c src/mkfifo.c src/rmdir.c \
+ src/chdir.c src/chmod.c src/fchdir.c src/fchmod.c src/fchown.c src/chown.c \
+ src/link.c src/unlink.c src/umask.c src/ftruncate.c src/utime.c src/fstat.c \
+ src/fcntl.c src/fpathconf.c src/getdents.c src/fsync.c src/fdatasync.c \
+ src/pipe.c src/dup.c src/dup2.c src/symlink.c src/readlink.c \
+ src/chroot.c src/sync.c src/_rename_r.c src/statvfs.c src/utimes.c src/lchown.c
+
+## Until sys/uio.h is moved to libcsupport, we have to have networking
+## enabled to compile these. Hopefully this is a temporary situation.
+if NEWLIB
+SYSTEM_CALL_C_FILES += src/readv.c src/writev.c
+endif
+
+DIRECTORY_SCAN_C_FILES =
+## Newlib SHOULD have provided this one
+DIRECTORY_SCAN_C_FILES += src/readdir_r.c
+## Comment out when using these from newlib's unix directory
+DIRECTORY_SCAN_C_FILES += src/getcwd.c
+
+ID_C_FILES = src/getegid.c src/geteuid.c src/getgid.c src/getgroups.c \
+ src/getlogin.c src/getpgrp.c src/getpid.c src/getppid.c src/getuid.c \
+ src/seteuid.c src/setgid.c src/setuid.c src/seteuid.c src/setpgid.c \
+ src/setsid.c
+
+MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \
+ src/realloc.c src/_calloc_r.c src/_malloc_r.c \
+ src/free.c src/freenode.c src/_free_r.c \
+ src/_realloc_r.c src/mallocfreespace.c \
+ src/mallocgetheapptr.c src/mallocsetheapptr.c \
+ src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
+ src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
+ src/malloc_statistics_helpers.c src/posix_memalign.c \
+ src/rtems_memalign.c src/malloc_deferred.c src/malloc_sbrk_helpers.c \
+ src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \
+ src/rtems_heap_extend.c
+
+PASSWORD_GROUP_C_FILES = src/getpwent.c
+
+TERMINAL_IDENTIFICATION_C_FILES = src/ctermid.c
+## 20 Nov 2008: Now using these from newlib's posix directory
+TERMINAL_IDENTIFICATION_C_FILES += src/isatty.c src/isatty_r.c
+## Comment out when using these from newlib's unix directory
+TERMINAL_IDENTIFICATION_C_FILES += src/ttyname.c
+
+LIBC_GLUE_C_FILES = src/__getpid.c src/__gettod.c src/__times.c \
+ src/truncate.c src/access.c src/stat.c src/lstat.c src/pathconf.c \
+ src/newlibc_reent.c src/newlibc_init.c src/newlibc_exit.c \
+ src/kill_noposix.c src/utsname.c
+
+BSD_LIBC_C_FILES = src/strlcpy.c src/strlcat.c src/issetugid.c
+
+libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \
+ src/printk_plugin.c src/putk.c src/vprintk.c \
+ src/sup_fs_is_separator.c src/sup_fs_get_start_loc.c \
+ src/sup_fs_get_sym_start_loc.c \
+ $(BSD_LIBC_C_FILES) $(BASE_FS_C_FILES) $(MALLOC_C_FILES) \
+ $(ERROR_C_FILES) $(ASSOCIATION_C_FILES)
+
+libcsupport_a_SOURCES += $(LIBC_GLUE_C_FILES) $(PASSWORD_GROUP_C_FILES) \
+ $(TERMINAL_IDENTIFICATION_C_FILES) $(SYSTEM_CALL_C_FILES) \
+ $(DIRECTORY_SCAN_C_FILES) $(ID_C_FILES) src/envlock.c \
+ $(TERMIOS_C_FILES) src/getpagesize.c src/getrusage.c
+
+libcsupport_a_SOURCES += src/flockfile.c src/funlockfile.c src/ftrylockfile.c
+
+EXTRA_DIST = src/TODO src/CASES src/README
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libcsupport/include/clockdrv.h b/cpukit/libcsupport/include/clockdrv.h
new file mode 100644
index 0000000000..d0eb55e9f6
--- /dev/null
+++ b/cpukit/libcsupport/include/clockdrv.h
@@ -0,0 +1,52 @@
+/**
+ * @file rtems/clockdrv.h
+ */
+
+/* clock.h
+ *
+ * This file describes the Clock Driver for all boards.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_CLOCKDRV_H
+#define _RTEMS_CLOCKDRV_H
+
+#include <rtems/io.h> /* rtems_device_driver */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* variables */
+
+extern volatile uint32_t Clock_driver_ticks;
+extern rtems_device_major_number rtems_clock_major;
+extern rtems_device_minor_number rtems_clock_minor;
+
+/* default clock driver entry */
+
+#define CLOCK_DRIVER_TABLE_ENTRY \
+ { Clock_initialize, NULL, NULL, NULL, NULL, NULL }
+
+rtems_device_driver Clock_initialize(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+void Clock_exit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/console.h b/cpukit/libcsupport/include/console.h
new file mode 100644
index 0000000000..0a2d258887
--- /dev/null
+++ b/cpukit/libcsupport/include/console.h
@@ -0,0 +1,162 @@
+/**
+ * @file rtems/console.h
+ */
+
+/* console.h
+ *
+ * This file describes the Console Device Driver for all boards.
+ * This driver provides support for the standard C Library.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_CONSOLE_H
+#define _RTEMS_CONSOLE_H
+
+#include <rtems/io.h> /* rtems_device_driver */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This macro defines the standard name for the console device
+ * that is available to applications.
+ */
+#define CONSOLE_DEVICE_NAME "/dev/console"
+
+/**
+ * This macro defines the standard device driver table entry for
+ * a console device driver.
+ */
+#define CONSOLE_DRIVER_TABLE_ENTRY \
+ { console_initialize, console_open, console_close, \
+ console_read, console_write, console_control }
+
+/**
+ * @brief Console Initialization Entry Point
+ *
+ * This method initializes the console device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver is successfully initialized.
+ */
+rtems_device_driver console_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Open Entry Point
+ *
+ * This method opens a specific device supported by the
+ * console device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver is successfully opened.
+ */
+rtems_device_driver console_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Close Entry Point
+ *
+ * This method closes a specific device supported by the
+ * console device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully closed.
+ */
+rtems_device_driver console_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Read Entry Point
+ *
+ * This method reads from a specific device supported by the
+ * console device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully read from.
+ */
+rtems_device_driver console_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console Write Entry Point
+ *
+ * This method writes to a specific device supported by the
+ * console device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully written.
+ */
+rtems_device_driver console_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Console IO Control Entry Point
+ *
+ * This method performs an IO Control operation on a
+ * specific device supported by the console device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver IO control operation is
+ * successfully performed.
+ */
+rtems_device_driver console_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/iosupp.h b/cpukit/libcsupport/include/iosupp.h
new file mode 100644
index 0000000000..cd2ff02e06
--- /dev/null
+++ b/cpukit/libcsupport/include/iosupp.h
@@ -0,0 +1,46 @@
+/**
+ * @file rtems/iosupp.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_IOSUPP_H
+#define _RTEMS_IOSUPP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* character constants */
+
+#define BS 0x08 /* backspace */
+#define LF 0x0a /* line feed */
+#define CR 0x0d /* carriage return */
+#define XON 0x11 /* control-Q */
+#define XOFF 0x13 /* control-S */
+
+/* structures */
+
+#ifdef IOSUPP_INIT
+#define IOSUPP_EXTERN
+#else
+#undef IOSUPP_EXTERN
+#define IOSUPP_EXTERN extern
+#endif
+
+/* functions */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/motorola/mc68230.h b/cpukit/libcsupport/include/motorola/mc68230.h
new file mode 100644
index 0000000000..d993a150fd
--- /dev/null
+++ b/cpukit/libcsupport/include/motorola/mc68230.h
@@ -0,0 +1,74 @@
+/**
+ * @file rtems/motorola/mc68230.h
+ */
+
+/*
+ * mc68230.h -- Low level support code for the Motorola 68230 Parallel
+ * Interface/Timer (PIT)
+ *
+ * Modified by Doug McBride, Colorado Space Grant College
+ *
+ * Format taken partly from RTEMS code and mostly from Motorola IDP user's
+ * manual. RTEMS copyright information below.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_MOTOROLA_MC68230_H
+#define _RTEMS_MOTOROLA_MC68230_H
+
+/* Some Motorola IDP User manual defines: */
+#define MC68230_PIT_ADDR 0x00c01003 /* base address of the PIT */
+#define MC68230_REGOFF 0x04 /* Difference between addresses */
+#define MC68230_VECT 64
+#define MC68230_H1VECT 0x00
+#define MC68230_H2VECT 0x01
+#define MC68230_H3VECT 0x02
+#define MC68230_H4VECT 0x03
+
+/*
+ * mc68230 register offsets
+ */
+#define MC68230_PGCR 0x00
+#define MC68230_PSRR 1*MC68230_REGOFF
+#define MC68230_PADDR 2*MC68230_REGOFF
+#define MC68230_PBDDR 3*MC68230_REGOFF
+#define MC68230_PCDDR 4*MC68230_REGOFF
+#define MC68230_PIVR 5*MC68230_REGOFF
+#define MC68230_PACR 6*MC68230_REGOFF
+#define MC68230_PBCR 7*MC68230_REGOFF
+#define MC68230_PADR 8*MC68230_REGOFF
+#define MC68230_PBDR 9*MC68230_REGOFF
+#define MC68230_PAAR 10*MC68230_REGOFF
+#define MC68230_PBAR 11*MC68230_REGOFF
+#define MC68230_PCDR 12*MC68230_REGOFF
+#define MC68230_PITSR 13*MC68230_REGOFF
+#define MC68230_TCR 16*MC68230_REGOFF
+#define MC68230_TIVR 17*MC68230_REGOFF
+#define MC68230_CPRH 19*MC68230_REGOFF
+#define MC68230_CPRM 20*MC68230_REGOFF
+#define MC68230_CPRL 21*MC68230_REGOFF
+#define MC68230_CNTRH 23*MC68230_REGOFF
+#define MC68230_CNTRM 24*MC68230_REGOFF
+#define MC68230_CNTRL 25*MC68230_REGOFF
+#define MC68230_TSR 26*MC68230_REGOFF
+
+/* Some RTEMS style defines: */
+#ifndef MC68230_VOL8
+#define MC68230_VOL8( ptr ) ((volatile uint8_t *)(ptr))
+#endif
+
+#define MC68230_WRITE( reg, data ) \
+ *(MC68230_VOL8(MC68230_PIT_ADDR+reg)) = (data)
+
+#define MC68230_READ( reg, data ) \
+ (data) = *(MC68230_VOL8(MC68230_PIT_ADDR+reg))
+
+#endif
diff --git a/cpukit/libcsupport/include/motorola/mc68681.h b/cpukit/libcsupport/include/motorola/mc68681.h
new file mode 100644
index 0000000000..7b2f566da3
--- /dev/null
+++ b/cpukit/libcsupport/include/motorola/mc68681.h
@@ -0,0 +1,309 @@
+/**
+ * @file rtems/motorola/mc68681.h
+ *
+ *
+ * mc68681-duart.h -- Low level support code for the Motorola mc68681
+ * DUART.
+ */
+
+/*
+ *
+ * Originally written by rob@cygnus.com (Rob Savoye) for the libgloss
+ * IDP support.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_MOTOROLA_MC68681_H
+#define _RTEMS_MOTOROLA_MC68681_H
+
+/*
+ * In the dark ages when this controller was designed, it was actually
+ * possible to access data on unaligned byte boundaries with no penalty.
+ * Now we find this chip in configurations in which the registers are
+ * at 16-bit, 32-bit, and 64-bit boundaries at the whim of the board
+ * designer. If the registers are not at byte addresses, then
+ * set this multiplier before including this file to correct the offsets.
+ */
+
+#ifndef MC68681_OFFSET_MULTIPLIER
+#define MC68681_OFFSET_MULTIPLIER 1
+#endif
+
+#define __MC68681_REG(_R) ((_R) * MC68681_OFFSET_MULTIPLIER)
+
+/*
+ * mc68681 register offsets Read/Write Addresses
+ */
+#define MC68681_MODE_REG_1A __MC68681_REG(0) /* MR1A-MR Prior to Read */
+#define MC68681_MODE_REG_2A __MC68681_REG(0) /* MR2A-MR After Read */
+
+#define MC68681_COUNT_MODE_CURRENT_MSB __MC68681_REG(6) /* CTU */
+#define MC68681_COUNTER_TIMER_UPPER_REG __MC68681_REG(6) /* CTU */
+#define MC68681_COUNT_MODE_CURRENT_LSB __MC68681_REG(7) /* CTL */
+#define MC68681_COUNTER_TIMER_LOWER_REG __MC68681_REG(7) /* CTL */
+#define MC68681_INTERRUPT_VECTOR_REG __MC68681_REG(12) /* IVR */
+
+#define MC68681_MODE_REG_1B __MC68681_REG(8) /* MR1B-MR Prior to Read */
+#define MC68681_MODE_REG_2B __MC68681_REG(8) /* MR2BA-MR After Read */
+
+/*
+ * mc68681 register offsets Read Only Addresses
+ */
+#define MC68681_STATUS_REG_A __MC68681_REG(1) /* SRA */
+#define MC68681_MASK_ISR_REG __MC68681_REG(2) /* MISR */
+#define MC68681_RECEIVE_BUFFER_A __MC68681_REG(3) /* RHRA */
+#define MC68681_INPUT_PORT_CHANGE_REG __MC68681_REG(4) /* IPCR */
+#define MC68681_INTERRUPT_STATUS_REG __MC68681_REG(5) /* ISR */
+#define MC68681_STATUS_REG_B __MC68681_REG(9) /* SRB */
+#define MC68681_RECEIVE_BUFFER_B __MC68681_REG(11) /* RHRB */
+#define MC68681_INPUT_PORT __MC68681_REG(13) /* IP */
+#define MC68681_START_COUNT_CMD __MC68681_REG(14) /* SCC */
+#define MC68681_STOP_COUNT_CMD __MC68681_REG(15) /* STC */
+
+/*
+ * mc68681 register offsets Write Only Addresses
+ */
+#define MC68681_CLOCK_SELECT_REG_A __MC68681_REG(1) /* CSRA */
+#define MC68681_COMMAND_REG_A __MC68681_REG(2) /* CRA */
+#define MC68681_TRANSMIT_BUFFER_A __MC68681_REG(3) /* THRA */
+#define MC68681_AUX_CTRL_REG __MC68681_REG(4) /* ACR */
+#define MC68681_INTERRUPT_MASK_REG __MC68681_REG(5) /* IMR */
+#define MC68681_CLOCK_SELECT_REG_B __MC68681_REG(9) /* CSRB */
+#define MC68681_COMMAND_REG_B __MC68681_REG(10) /* CRB */
+#define MC68681_TRANSMIT_BUFFER_B __MC68681_REG(11) /* THRB */
+#define MC68681_OUTPUT_PORT_CONFIG_REG __MC68681_REG(13) /* OPCR */
+#define MC68681_OUTPUT_PORT_SET_REG __MC68681_REG(14) /* SOPBC */
+#define MC68681_OUTPUT_PORT_RESET_BITS __MC68681_REG(15) /* COPBC */
+
+
+#ifndef MC6681_VOL
+#define MC6681_VOL( ptr ) ((volatile unsigned char *)(ptr))
+#endif
+
+#define MC68681_WRITE( _base, _reg, _data ) \
+ *((volatile unsigned char *)_base+_reg) = (_data)
+
+#define MC68681_READ( _base, _reg ) \
+ *(((volatile unsigned char *)_base+_reg))
+
+
+
+#define MC68681_CLEAR 0x00
+
+#define MC68681_PORT_A 0
+#define MC68681_PORT_B 1
+
+/*
+ * DUART Command Register Definitions:
+ *
+ * MC68681_COMMAND_REG_A,MC68681_COMMAND_REG_B
+ */
+#define MC68681_MODE_REG_ENABLE_RX 0x01
+#define MC68681_MODE_REG_DISABLE_RX 0x02
+#define MC68681_MODE_REG_ENABLE_TX 0x04
+#define MC68681_MODE_REG_DISABLE_TX 0x08
+#define MC68681_MODE_REG_RESET_MR_PTR 0x10
+#define MC68681_MODE_REG_RESET_RX 0x20
+#define MC68681_MODE_REG_RESET_TX 0x30
+#define MC68681_MODE_REG_RESET_ERROR 0x40
+#define MC68681_MODE_REG_RESET_BREAK 0x50
+#define MC68681_MODE_REG_START_BREAK 0x60
+#define MC68681_MODE_REG_STOP_BREAK 0x70
+#define MC68681_MODE_REG_SET_RX_BRG 0x80
+#define MC68681_MODE_REG_CLEAR_RX_BRG 0x90
+#define MC68681_MODE_REG_SET_TX_BRG 0xa0
+#define MC68681_MODE_REG_CLEAR_TX_BRG 0xb0
+#define MC68681_MODE_REG_SET_STANDBY 0xc0
+#define MC68681_MODE_REG_SET_ACTIVE 0xd0
+
+/*
+ * Mode Register Definitions
+ *
+ * MC68681_MODE_REG_1A
+ * MC68681_MODE_REG_1B
+ */
+#define MC68681_5BIT_CHARS 0x00
+#define MC68681_6BIT_CHARS 0x01
+#define MC68681_7BIT_CHARS 0x02
+#define MC68681_8BIT_CHARS 0x03
+
+#define MC68681_ODD_PARITY 0x00
+#define MC68681_EVEN_PARITY 0x04
+
+#define MC68681_WITH_PARITY 0x00
+#define MC68681_FORCE_PARITY 0x08
+#define MC68681_NO_PARITY 0x10
+#define MC68681_MULTI_DROP 0x18
+
+#define MC68681_ERR_MODE_CHAR 0x00
+#define MC68681_ERR_MODE_BLOCK 0x20
+
+#define MC68681_RX_INTR_RX_READY 0x00
+#define MC68681_RX_INTR_FFULL 0x40
+
+#define MC68681_NO_RX_RTS_CTL 0x00
+#define MC68681_RX_RTS_CTRL 0x80
+
+
+/*
+ * Mode Register Definitions
+ *
+ * MC68681_MODE_REG_2A
+ * MC68681_MODE_REG_2B
+ */
+#define MC68681_STOP_BIT_LENGTH__563 0x00
+#define MC68681_STOP_BIT_LENGTH__625 0x01
+#define MC68681_STOP_BIT_LENGTH__688 0x02
+#define MC68681_STOP_BIT_LENGTH__75 0x03
+#define MC68681_STOP_BIT_LENGTH__813 0x04
+#define MC68681_STOP_BIT_LENGTH__875 0x05
+#define MC68681_STOP_BIT_LENGTH__938 0x06
+#define MC68681_STOP_BIT_LENGTH_1 0x07
+#define MC68681_STOP_BIT_LENGTH_1_563 0x08
+#define MC68681_STOP_BIT_LENGTH_1_625 0x09
+#define MC68681_STOP_BIT_LENGTH_1_688 0x0a
+#define MC68681_STOP_BIT_LENGTH_1_75 0x0b
+#define MC68681_STOP_BIT_LENGTH_1_813 0x0c
+#define MC68681_STOP_BIT_LENGTH_1_875 0x0d
+#define MC68681_STOP_BIT_LENGTH_1_938 0x0e
+#define MC68681_STOP_BIT_LENGTH_2 0x0f
+
+#define MC68681_CTS_ENABLE_TX 0x10
+#define MC68681_TX_RTS_CTRL 0x20
+
+#define MC68681_CHANNEL_MODE_NORMAL 0x00
+#define MC68681_CHANNEL_MODE_ECHO 0x40
+#define MC68681_CHANNEL_MODE_LOCAL_LOOP 0x80
+#define MC68681_CHANNEL_MODE_REMOTE_LOOP 0xc0
+
+/*
+ * Status Register Definitions
+ *
+ * MC68681_STATUS_REG_A, MC68681_STATUS_REG_B
+ */
+#define MC68681_RX_READY 0x01
+#define MC68681_FFULL 0x02
+#define MC68681_TX_READY 0x04
+#define MC68681_TX_EMPTY 0x08
+#define MC68681_OVERRUN_ERROR 0x10
+#define MC68681_PARITY_ERROR 0x20
+#define MC68681_FRAMING_ERROR 0x40
+#define MC68681_RECEIVED_BREAK 0x80
+
+
+/*
+ * Interupt Status Register Definitions.
+ *
+ * MC68681_INTERRUPT_STATUS_REG
+ */
+
+
+/*
+ * Interupt Mask Register Definitions
+ *
+ * MC68681_INTERRUPT_MASK_REG
+ */
+#define MC68681_IR_TX_READY_A 0x01
+#define MC68681_IR_RX_READY_A 0x02
+#define MC68681_IR_BREAK_A 0x04
+#define MC68681_IR_COUNTER_READY 0x08
+#define MC68681_IR_TX_READY_B 0x10
+#define MC68681_IR_RX_READY_B 0x20
+#define MC68681_IR_BREAK_B 0x40
+#define MC68681_IR_INPUT_PORT_CHANGE 0x80
+
+/*
+ * Status Register Definitions.
+ *
+ * MC68681_STATUS_REG_A,MC68681_STATUS_REG_B
+ */
+#define MC68681_STATUS_RXRDY 0x01
+#define MC68681_STATUS_FFULL 0x02
+#define MC68681_STATUS_TXRDY 0x04
+#define MC68681_STATUS_TXEMT 0x08
+#define MC68681_STATUS_OVERRUN_ERROR 0x10
+#define MC68681_STATUS_PARITY_ERROR 0x20
+#define MC68681_STATUS_FRAMING_ERROR 0x40
+#define MC68681_STATUS_RECEIVED_BREAK 0x80
+
+/*
+ * Definitions for the Interrupt Vector Register:
+ *
+ * MC68681_INTERRUPT_VECTOR_REG
+ */
+#define MC68681_INTERRUPT_VECTOR_INIT 0x0f
+
+/*
+ * Definitions for the Auxiliary Control Register
+ *
+ * MC68681_AUX_CTRL_REG
+ */
+#define MC68681_AUX_BRG_SET1 0x00
+#define MC68681_AUX_BRG_SET2 0x80
+
+
+/*
+ * The following Baud rates assume the X1 clock pin is driven with a
+ * 3.6864 MHz signal. If a different frequency is used the DUART channel
+ * is running at the follwoing baud rate:
+ * ((Table Baud Rate)*frequency)/3.6864 MHz
+ */
+
+/*
+ * Definitions for the Clock Select Register:
+ *
+ * MC68681_CLOCK_SELECT_REG_A,MC68681_CLOCK_SELECT_REG_A
+ *
+ * Note: ACR[7] is the MSB of the Auxiliary Control register
+ * X is the extend bit.
+ * CRA - 0x08 Set Rx BRG Select Extend Bit (X=1)
+ * CRA - 0x09 Clear Rx BRG Select Extend Bit (X=0)
+ * CRB - 0x0a Set Tx BRG Select Extend Bit (X=1)
+ * CRB - 0x0b Clear Tx BRG Select Extend Bit (x=1)
+ */
+#define MC68681_BAUD_RATE_MASK_50 0x00 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_75 0x00 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_110 0x01
+#define MC68681_BAUD_RATE_MASK_134_5 0x02
+#define MC68681_BAUD_RATE_MASK_150 0x03 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_200 0x03 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_300 0x04 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_600 0x05 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_1050 0x07 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_1200 0x06 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_1800 0x0a /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_2400 0x08 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_3600 0x04 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_4800 0x09
+#define MC68681_BAUD_RATE_MASK_7200 0x0a /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_9600 0xbb
+
+#define MC68681_BAUD_RATE_MASK_14_4K 0x05 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_19_2K 0xcc /* ACR[7]=1,X=0 */
+ /* ARC[7]=0,X=1 */
+#define MC68681_BAUD_RATE_MASK_28_8K 0x06 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_38_4K 0xcc /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_57_6K 0x07 /* ACR[7]=0,X=0 */
+ /* ARC[7]=1,X=1 */
+#define MC68681_BAUD_RATE_MASK_115_5K 0x08
+#define MC68681_BAUD_RATE_MASK_TIMER 0xdd
+#define MC68681_BAUD_RATE_MASK_TIMER_16X 0xee
+#define MC68681_BAUD_RATE_MASK_TIMER_1X 0xff
+
+#endif
diff --git a/cpukit/libcsupport/include/ringbuf.h b/cpukit/libcsupport/include/ringbuf.h
new file mode 100644
index 0000000000..39941d857d
--- /dev/null
+++ b/cpukit/libcsupport/include/ringbuf.h
@@ -0,0 +1,55 @@
+/**
+ * @file rtems/ringbuf.h
+ *
+ * This file provides simple ring buffer functionality.
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _RTEMS_RINGBUF_H
+#define _RTEMS_RINGBUF_H
+
+#ifndef RINGBUF_QUEUE_LENGTH
+#define RINGBUF_QUEUE_LENGTH 128
+#endif
+
+typedef struct {
+ uint8_t buffer[RINGBUF_QUEUE_LENGTH];
+ volatile int head;
+ volatile int tail;
+} Ring_buffer_t;
+
+#define Ring_buffer_Initialize( _buffer ) \
+ do { \
+ (_buffer)->head = (_buffer)->tail = 0; \
+ } while ( 0 )
+
+#define Ring_buffer_Is_empty( _buffer ) \
+ ( (_buffer)->head == (_buffer)->tail )
+
+#define Ring_buffer_Is_full( _buffer ) \
+ ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH )
+
+#define Ring_buffer_Add_character( _buffer, _ch ) \
+ do { \
+ uint32_t isrlevel; \
+ \
+ rtems_interrupt_disable( isrlevel ); \
+ (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
+ (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
+ rtems_interrupt_enable( isrlevel ); \
+ } while ( 0 )
+
+#define Ring_buffer_Remove_character( _buffer, _ch ) \
+ do { \
+ uint32_t isrlevel; \
+ \
+ rtems_interrupt_disable( isrlevel ); \
+ (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
+ (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
+ rtems_interrupt_enable( isrlevel ); \
+ } while ( 0 )
+
+#endif
diff --git a/cpukit/libcsupport/include/rtc.h b/cpukit/libcsupport/include/rtc.h
new file mode 100644
index 0000000000..cc6f8c2b80
--- /dev/null
+++ b/cpukit/libcsupport/include/rtc.h
@@ -0,0 +1,116 @@
+/**
+ * @file
+ *
+ * Real-time clock driver interface.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTC_H
+#define _RTEMS_RTC_H
+
+#include <rtems.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup rtems_rtc Real-Time Clock Driver Interface
+ *
+ * This driver interface provides support to read and set the real-time clock
+ * and to initialize the time of day for the system.
+ *
+ * @{
+ */
+
+/**
+ * Device file name path.
+ */
+#define RTC_DEVICE_NAME "/dev/rtc"
+
+/**
+ * Device driver table entry.
+ */
+#define RTC_DRIVER_TABLE_ENTRY \
+ { rtc_initialize, rtc_open, rtc_close, \
+ rtc_read, rtc_write, rtc_control }
+
+/**
+ * Initializes the real-time clock device and sets the time of day for the
+ * system.
+ *
+ * If the real-time clock provides an invalid time of day value the system time
+ * of day must remain untouched.
+ */
+rtems_device_driver rtc_initialize(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Opens the real-time clock device.
+ */
+rtems_device_driver rtc_open(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Closes the real-time clock device.
+ */
+rtems_device_driver rtc_close(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Reads the real-time clock value.
+ *
+ * The value will be returned in a @ref rtems_time_of_day structure.
+ */
+rtems_device_driver rtc_read(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Sets the real-time clock value.
+ *
+ * The value will be set from a @ref rtems_time_of_day structure.
+ */
+rtems_device_driver rtc_write(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Controls the real-time clock.
+ */
+rtems_device_driver rtc_control(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/rtems/assoc.h b/cpukit/libcsupport/include/rtems/assoc.h
new file mode 100644
index 0000000000..5b72b8d086
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/assoc.h
@@ -0,0 +1,120 @@
+/**
+ * @file rtems/assoc.h
+ */
+
+/*
+ *
+ * Rtems associativity routines. Mainly used to convert a value from
+ * one space to another (eg: our errno's to host errno's and v.v)
+ *
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_ASSOC_H
+#define _RTEMS_RTEMS_ASSOC_H
+
+#include <stdint.h> /* uint32_t */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ const char *name;
+ uint32_t local_value;
+ uint32_t remote_value;
+} rtems_assoc_t;
+
+/*
+ * Flag/marker for optional default value in each table
+ */
+
+#define RTEMS_ASSOC_DEFAULT_NAME "(default)"
+
+const rtems_assoc_t *rtems_assoc_ptr_by_name(
+ const rtems_assoc_t *,
+ const char *
+);
+
+const rtems_assoc_t *rtems_assoc_ptr_by_remote(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+uint32_t rtems_assoc_remote_by_local(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+uint32_t rtems_assoc_local_by_remote(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+uint32_t rtems_assoc_remote_by_name(
+ const rtems_assoc_t *,
+ const char *
+);
+uint32_t rtems_assoc_local_by_name(
+ const rtems_assoc_t *,
+ const char *
+);
+
+const char *rtems_assoc_name_by_local(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+const char *rtems_assoc_name_by_remote(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+uint32_t rtems_assoc_remote_by_local_bitfield(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+char *rtems_assoc_name_by_local_bitfield(
+ const rtems_assoc_t *,
+ uint32_t ,
+ char *
+);
+
+char *rtems_assoc_name_by_remote_bitfield(
+ const rtems_assoc_t *,
+ uint32_t ,
+ char *
+);
+
+uint32_t rtems_assoc_local_by_remote_bitfield(
+ const rtems_assoc_t *,
+ uint32_t
+);
+
+const rtems_assoc_t *rtems_assoc_ptr_by_local(
+ const rtems_assoc_t *ap,
+ uint32_t local_value
+);
+
+#if defined(INSIDE_ASSOC)
+
+#define rtems_assoc_is_default(_ap) \
+ ((_ap)->name && !strcmp((_ap)->name, RTEMS_ASSOC_DEFAULT_NAME))
+
+/*
+ * what to return if a value is not found
+ * this is not reentrant, but it really shouldn't be invoked anyway
+ */
+
+const char *rtems_assoc_name_bad(
+ uint32_t bad_value
+);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! _RTEMS_RTEMS_ASSOC_H */
diff --git a/cpukit/libcsupport/include/rtems/error.h b/cpukit/libcsupport/include/rtems/error.h
new file mode 100644
index 0000000000..6c589e8e94
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/error.h
@@ -0,0 +1,60 @@
+/**
+ * @file rtems/error.h
+ */
+
+/*
+ * Defines and externs for rtems error reporting
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_ERROR_H
+#define _RTEMS_RTEMS_ERROR_H
+
+#include <rtems/rtems/status.h>
+#include <rtems/score/interr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef Internal_errors_t rtems_error_code_t;
+
+/*
+ * rtems_error() and rtems_panic() support
+ */
+
+#if 0
+/* not 16bit-int host clean */
+#define RTEMS_ERROR_ERRNO (1<<((sizeof(rtems_error_code_t) * CHAR_BIT) - 2)) /* hi bit; use 'errno' */
+#define RTEMS_ERROR_PANIC (RTEMS_ERROR_ERRNO / 2) /* err fatal; no return */
+#define RTEMS_ERROR_ABORT (RTEMS_ERROR_ERRNO / 4) /* err is fatal; panic */
+#else
+#define RTEMS_ERROR_ERRNO (0x40000000) /* hi bit; use 'errno' */
+#define RTEMS_ERROR_PANIC (0x20000000) /* err fatal; no return */
+#define RTEMS_ERROR_ABORT (0x10000000) /* err is fatal; panic */
+#endif
+
+#define RTEMS_ERROR_MASK \
+ (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | RTEMS_ERROR_PANIC) /* all */
+
+const char *rtems_status_text(rtems_status_code sc);
+int rtems_error(
+ rtems_error_code_t error_code,
+ const char *printf_format,
+ ...
+);
+void rtems_panic(
+ const char *printf_format,
+ ...
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+extern int rtems_panic_in_progress;
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/rtems/framebuffer.h b/cpukit/libcsupport/include/rtems/framebuffer.h
new file mode 100644
index 0000000000..a300716c58
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/framebuffer.h
@@ -0,0 +1,158 @@
+/**
+ * @file rtems/framebuffer.h
+ */
+
+/*
+ * This file describes the Frame Buffer Device Driver for all boards.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __RTEMS_FRAMEBUFFER_h__
+#define __RTEMS_FRAMEBUFFER_h__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This macro defines the standard name for the frame buffer device
+ * that is available to applications.
+ */
+#define FRAMEBUFFER_DEVICE_NAME "/dev/fb"
+
+/**
+ * This macro defines the standard device driver table entry for
+ * a frame buffer device driver.
+ */
+#define FRAME_BUFFER_DRIVER_TABLE_ENTRY \
+ { frame_buffer_initialize, frame_buffer_open, frame_buffer_close, \
+ frame_buffer_read, frame_buffer_write, frame_buffer_control }
+
+/**
+ * @brief Frame Buffer Initialization Entry Point
+ *
+ * This method initializes the frame buffer device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver is successfully initialized.
+ */
+rtems_device_driver frame_buffer_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Frame Buffer Open Entry Point
+ *
+ * This method opens a specific device supported by the
+ * frame buffer device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver is successfully opened.
+ */
+rtems_device_driver frame_buffer_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Frame Buffer Close Entry Point
+ *
+ * This method closes a specific device supported by the
+ * frame buffer device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully closed.
+ */
+rtems_device_driver frame_buffer_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Frame Buffer Read Entry Point
+ *
+ * This method reads from a specific device supported by the
+ * frame buffer device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully read from.
+ */
+rtems_device_driver frame_buffer_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Frame Buffer Write Entry Point
+ *
+ * This method writes to a specific device supported by the
+ * frame buffer device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device is successfully written.
+ */
+rtems_device_driver frame_buffer_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Frame Buffer IO Control Entry Point
+ *
+ * This method performs an IO Control operation on a
+ * specific device supported by the frame buffer device driver.
+ *
+ * @param[in] major is the device driver major number
+ * @param[in] minor is the device driver minor number
+ * @param[in] arg is the parameters to this call
+ *
+ * @return This method returns RTEMS_SUCCESSFUL when
+ * the device driver IO control operation is
+ * successfully performed.
+ */
+rtems_device_driver frame_buffer_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/rtems/gxx_wrappers.h b/cpukit/libcsupport/include/rtems/gxx_wrappers.h
new file mode 100755
index 0000000000..d4d4aae799
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/gxx_wrappers.h
@@ -0,0 +1,78 @@
+/*
+ * RTEMS threads compatibility routines for libgcc2.
+ *
+ * by: Rosimildo da Silva (rdasilva@connecttel.com)
+ *
+ * Used ideas from:
+ * W. Eric Norum
+ * Canadian Light Source
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@cls.usask.ca
+ *
+ * Eric sent some e-mail in the rtems-list as a start point for this
+ * module implementation.
+ *
+ * $Id$
+ */
+
+#ifndef __GCC_WRAPPERS_h
+#define __GCC_WRAPPERS_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * These typedefs should match with the ones defined in the file
+ * gcc/gthr-rtems.h in the gcc distribution.
+ * FIXME: T.S, 2007/01/31: -> gcc/gthr-rtems.h still declares
+ * void * __gthread_key_t;
+ */
+typedef struct __gthread_key_ {
+ void *val; /* this is switched with the task */
+ void (*dtor)(void*); /* this remains in place for all tasks */
+} __gthread_key, *__gthread_key_t;
+
+typedef int __gthread_once_t;
+typedef void *__gthread_mutex_t;
+typedef void *__gthread_recursive_mutex_t;
+
+int rtems_gxx_once(__gthread_once_t *once, void (*func) (void));
+
+int rtems_gxx_key_create (__gthread_key_t *key, void (*dtor) (void *));
+
+int rtems_gxx_key_dtor (__gthread_key_t key, void *ptr);
+
+int rtems_gxx_key_delete (__gthread_key_t key);
+
+void *rtems_gxx_getspecific(__gthread_key_t key);
+
+int rtems_gxx_setspecific(__gthread_key_t key, const void *ptr);
+
+/*
+ * MUTEX support
+ */
+void rtems_gxx_mutex_init (__gthread_mutex_t *mutex);
+
+int rtems_gxx_mutex_lock (__gthread_mutex_t *mutex);
+
+int rtems_gxx_mutex_destroy (__gthread_mutex_t *mutex);
+
+int rtems_gxx_mutex_trylock (__gthread_mutex_t *mutex);
+
+int rtems_gxx_mutex_unlock (__gthread_mutex_t *mutex);
+
+void rtems_gxx_recursive_mutex_init(__gthread_recursive_mutex_t *mutex);
+
+int rtems_gxx_recursive_mutex_lock(__gthread_recursive_mutex_t *mutex);
+
+int rtems_gxx_recursive_mutex_trylock(__gthread_recursive_mutex_t *mutex);
+
+int rtems_gxx_recursive_mutex_unlock(__gthread_recursive_mutex_t *mutex);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __GCC_WRAPPERS_h */
diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h
new file mode 100644
index 0000000000..9dfcf851fe
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/libcsupport.h
@@ -0,0 +1,81 @@
+/**
+ * @file rtems/libcsupport.h
+ */
+
+/* libcsupport.h
+ *
+ * This include file contains the information regarding the
+ * RTEMS specific support for the standard C library.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_LIBCSUPPORT_H
+#define _RTEMS_RTEMS_LIBCSUPPORT_H
+
+#include <sys/types.h>
+#include <stdint.h>
+
+#include <rtems/score/heap.h>
+#include <rtems/rtems/tasks.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void RTEMS_Malloc_Initialize(
+ void *heap_begin,
+ uintptr_t heap_size,
+ size_t sbrk_amount
+);
+
+extern void malloc_dump(void);
+extern void malloc_walk(size_t source, size_t printf_enabled);
+void malloc_set_heap_pointer(Heap_Control *new_heap);
+Heap_Control *malloc_get_heap_pointer( void );
+extern void libc_init(void);
+extern int host_errno(void);
+extern void fix_syscall_errno(void);
+extern size_t malloc_free_space(void);
+extern void open_dev_console(void);
+
+/*
+ * Prototypes required to install newlib reentrancy user extension
+ */
+bool newlib_create_hook(
+ rtems_tcb *current_task,
+ rtems_tcb *creating_task
+);
+
+#define __RTEMS_NEWLIB_BEGIN 0
+
+void newlib_delete_hook(
+ rtems_tcb *current_task,
+ rtems_tcb *deleted_task
+);
+
+#define RTEMS_NEWLIB_EXTENSION \
+{ \
+ newlib_create_hook, /* rtems_task_create */ \
+ 0, /* rtems_task_start */ \
+ 0, /* rtems_task_restart */ \
+ newlib_delete_hook, /* rtems_task_delete */ \
+ 0, /* task_switch */ \
+ __RTEMS_NEWLIB_BEGIN, /* task_begin */ \
+ 0, /* task_exitted */ \
+ 0 /* fatal */ \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
new file mode 100644
index 0000000000..73c52e31d7
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -0,0 +1,1685 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief Basic IO API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_LIBIO_H
+#define _RTEMS_RTEMS_LIBIO_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/statvfs.h>
+
+#include <unistd.h>
+#include <termios.h>
+
+#include <rtems.h>
+#include <rtems/fs.h>
+#include <rtems/chain.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup LibIO IO Library
+ *
+ * @brief Provides system call and file system interface definitions.
+ *
+ * General purpose communication channel for RTEMS to allow UNIX/POSIX
+ * system call behavior under RTEMS. Initially this supported only
+ * IO to devices but has since been enhanced to support networking
+ * and support for mounted file systems.
+ *
+ * @{
+ */
+
+/**
+ * A 64-bit file offset for internal use by RTEMS. Based on the Newlib
+ * type.
+ */
+typedef _off64_t rtems_off64_t;
+
+/**
+ * @brief File system node types.
+ */
+typedef enum {
+ RTEMS_FILESYSTEM_INVALID_NODE_TYPE,
+ RTEMS_FILESYSTEM_DIRECTORY,
+ RTEMS_FILESYSTEM_DEVICE,
+ RTEMS_FILESYSTEM_HARD_LINK,
+ RTEMS_FILESYSTEM_SYM_LINK,
+ RTEMS_FILESYSTEM_MEMORY_FILE
+} rtems_filesystem_node_types_t;
+
+/**
+ * @name File System Node Operations
+ *
+ * @{
+ */
+
+/**
+ * This type defines the interface to the open(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_open_t)(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+);
+
+/**
+ * This type defines the interface to the close(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_close_t)(
+ rtems_libio_t *iop
+);
+
+/**
+ * This type defines the interface to the read(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef ssize_t (*rtems_filesystem_read_t)(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+);
+
+/**
+ * This type defines the interface to the write(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef ssize_t (*rtems_filesystem_write_t)(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+);
+
+/**
+ * This type defines the interface to the ioctl(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_ioctl_t)(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+);
+
+/**
+ * This type defines the interface to the lseek(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef rtems_off64_t (*rtems_filesystem_lseek_t)(
+ rtems_libio_t *iop,
+ rtems_off64_t length,
+ int whence
+);
+
+/**
+ * This type defines the interface to the fstat(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_fstat_t)(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+);
+
+/**
+ * This type defines the interface to the fchmod(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_fchmod_t)(
+ rtems_filesystem_location_info_t *loc,
+ mode_t mode
+);
+
+/**
+ * This type defines the interface to the ftruncate(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_ftruncate_t)(
+ rtems_libio_t *iop,
+ rtems_off64_t length
+);
+
+/**
+ * This type defines the interface to the fpathconf(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_fpathconf_t)(
+ rtems_libio_t *iop,
+ int name
+);
+
+/**
+ * This type defines the interface to the fsync(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_fsync_t)(
+ rtems_libio_t *iop
+);
+
+/**
+ * This type defines the interface to the fdatasync(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_fdatasync_t)(
+ rtems_libio_t *iop
+);
+
+/**
+ * This type defines the interface to the fnctl(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_fcntl_t)(
+ int cmd,
+ rtems_libio_t *iop
+);
+
+typedef int (*rtems_filesystem_rmnod_t)(
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/** @} */
+
+/**
+ * @brief File system node operations table.
+ */
+struct _rtems_filesystem_file_handlers_r {
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the open(2) system call
+ *
+ * @note This method must have a filesystem specific implementation.
+ *
+ * @note There is no default implementation.
+ */
+ rtems_filesystem_open_t open_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the close(2) system call
+ *
+ * @note This method is REQUIRED by all file systems.
+ *
+ * @note There is no default implementation.
+ */
+ rtems_filesystem_close_t close_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the read(2) system call
+ *
+ * @note This method must have a filesystem specific implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_read_t read_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the write(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_write_t write_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the ioctl(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_ioctl_t ioctl_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the lseek(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_lseek_t lseek_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fstat(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fstat_t fstat_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fchmod(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fchmod_t fchmod_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the ftruncate(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_ftruncate_t ftruncate_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fpathconf(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fpathconf_t fpathconf_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fsync(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fsync_t fsync_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fdatasync(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fdatasync_t fdatasync_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fcntl(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fcntl_t fcntl_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the rmnod(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_rmnod_t rmnod_h;
+};
+
+extern const rtems_filesystem_file_handlers_r
+rtems_filesystem_handlers_default;
+
+/**
+ * This method defines the interface to the default open(2)
+ * system call support which is provided by a file system
+ * implementation.
+ */
+int rtems_filesystem_default_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+);
+
+/**
+ * This method defines the interface to the default close(2)
+ * system call support which is provided by a file system
+ * implementation.
+ */
+int rtems_filesystem_default_close(
+ rtems_libio_t *iop
+);
+
+
+/**
+ * This method defines the interface to the default read(2)
+ * system call support which is provided by a file system
+ * implementation.
+ */
+ssize_t rtems_filesystem_default_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+);
+
+/**
+ * This method defines the interface to the default write(2) system call
+ * support which is provided by a file system implementation.
+ */
+ssize_t rtems_filesystem_default_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+);
+
+/**
+ * This method defines the interface to the default ioctl(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+);
+
+/**
+ * This method defines the interface to the default lseek(2) system call
+ * support which is provided by a file system implementation.
+ */
+rtems_off64_t rtems_filesystem_default_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t length,
+ int whence
+);
+
+/**
+ * This method defines the interface to the default fstat(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_fstat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+);
+
+/**
+ * This method defines the interface to the default fchmod(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_fchmod(
+ rtems_filesystem_location_info_t *loc,
+ mode_t mode
+);
+
+/**
+ * This method defines the interface to the default ftruncate(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_ftruncate(
+ rtems_libio_t *iop,
+ rtems_off64_t length
+);
+
+/**
+ * This method defines the interface to the default fpathconf(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_fpathconf(
+ rtems_libio_t *iop,
+ int name
+);
+
+/**
+ * This method defines the interface to the default fsync(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_fsync(
+ rtems_libio_t *iop
+);
+
+/**
+ * This method defines the interface to the default fdatasync(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_fdatasync(
+ rtems_libio_t *iop
+);
+
+/**
+ * This method defines the interface to the default fnctl(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_fcntl(
+ int cmd,
+ rtems_libio_t *iop
+);
+
+/**
+ * This method defines the interface to the default rmnod(2) system call
+ * support which is provided by a file system implementation.
+ */
+int rtems_filesystem_default_rmnod(
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/**
+ * @name File System Operations
+ *
+ * @{
+ */
+
+/**
+ * This type defines the interface to the mknod(2) system call
+ * support which is provided by a file system implementation.
+ *
+ * @note This routine does not allocate any space and
+ * rtems_filesystem_freenode_t is not called by the generic
+ * after calling this routine. ie. node_access does not have
+ * to contain valid data when the routine returns.
+ */
+typedef int (*rtems_filesystem_mknod_t)(
+ const char *path, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+/**
+ * This type defines the interface that allows the
+ * file system implementation to parse a path and
+ * allocate any memory necessary for tracking purposes.
+ *
+ * @note rtems_filesystem_freenode_t must be called by
+ * the generic after calling this routine
+ */
+typedef int (*rtems_filesystem_evalpath_t)(
+ const char *pathname, /* IN */
+ size_t pathnamelen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+/**
+ * This type defines the interface that allows the
+ * file system implementation to parse a path with the
+ * intent of creating a new node and to
+ * allocate any memory necessary for tracking purposes.
+ *
+ * @note rtems_filesystem_freenode_t must be called by
+ * the generic after calling this routine
+ */
+typedef int (*rtems_filesystem_evalmake_t)(
+ const char *path, /* IN */
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ const char **name /* OUT */
+);
+
+/**
+ * This type defines the interface to the link(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_link_t)(
+ rtems_filesystem_location_info_t *to_loc, /* IN */
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *name /* IN */
+);
+
+/**
+ * This type defines the interface to the unlink(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_unlink_t)(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/**
+ * This type defines the interface to the chown(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_chown_t)(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ uid_t owner, /* IN */
+ gid_t group /* IN */
+);
+
+/**
+ * This type defines the interface to the freenod(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_freenode_t)(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/**
+ * This type defines the interface that allows the implemented
+ * filesystem ot mount another filesystem at the given location.
+ */
+typedef int (* rtems_filesystem_mount_t ) (
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+/**
+ * This type defines the interface that allows a file system
+ * implementation to do any necessary work that is needed when
+ * it is being mounted.
+ */
+typedef int (* rtems_filesystem_fsmount_me_t )(
+ rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */
+ const void *data /* IN */
+);
+
+/**
+ * This type defines the interface allow the filesystem to
+ * unmount a filesystem that was mounted at one of its node
+ * locations.
+ */
+typedef int (* rtems_filesystem_unmount_t ) (
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+/**
+ * This type defines the interface that allows a file system
+ * implementation to do any necessary work that is needed when
+ * it is being unmounted.
+ */
+typedef int (* rtems_filesystem_fsunmount_me_t ) (
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+/**
+ * This type defines the interface that will return the
+ * type of a filesystem implementations node.
+ */
+typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) (
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/**
+ * This type defines the interface to the time(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (* rtems_filesystem_utime_t)(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+);
+
+/**
+ * This type defines the interface to the link(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_evaluate_link_t)(
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ int flags /* IN */
+);
+
+/**
+ * This type defines the interface to the symlink(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_symlink_t)(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ const char *link_name, /* IN */
+ const char *node_name
+);
+
+/**
+ * This type defines the interface to the readlink(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef ssize_t (*rtems_filesystem_readlink_t)(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ char *buf, /* OUT */
+ size_t bufsize
+);
+
+/**
+ * This type defines the interface to the name(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_rename_t)(
+ rtems_filesystem_location_info_t *old_parent_loc, /* IN */
+ rtems_filesystem_location_info_t *old_loc, /* IN */
+ rtems_filesystem_location_info_t *new_parent_loc, /* IN */
+ const char *name /* IN */
+);
+
+/**
+ * This type defines the interface to the statvfs(2) system call
+ * support which is provided by a file system implementation.
+ */
+typedef int (*rtems_filesystem_statvfs_t)(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct statvfs *buf /* OUT */
+);
+
+/** @} */
+
+/**
+ * @brief File system operations table.
+ */
+struct _rtems_filesystem_operations_table {
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine that evaluates a character path and
+ * returns the node assocated with the last node in the path.
+ *
+ * @note This method must have a filesystem specific implementation.
+ *
+ * @note There is no default implementation.
+ */
+ rtems_filesystem_evalpath_t evalpath_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine that evaluates a character path and
+ * returns the node assocated with next to the last node in
+ * the path. The last node will be the new node to be created.
+ *
+ * @note This method must have a filesystem specific implementation.
+ *
+ * @note There is no default implementation.
+ */
+ rtems_filesystem_evalmake_t evalformake_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the link(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_link_t link_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the unlink(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_unlink_t unlink_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of a method that returns the node type of the given node.
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_node_type_t node_type_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the link(2) system call
+ *
+ * @note This method may use a mknod implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_mknod_t mknod_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the link(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_chown_t chown_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the freenod(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_freenode_t freenod_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the mount(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_mount_t mount_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fsmount(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fsmount_me_t fsmount_me_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the unmount(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_unmount_t unmount_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the fsunmount(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_fsunmount_me_t fsunmount_me_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the utime(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_utime_t utime_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the eval_link(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_evaluate_link_t eval_link_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the sumlink(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_symlink_t symlink_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the readlink(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_readlink_t readlink_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the rename(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_rename_t rename_h;
+
+ /**
+ * This field points to the file system specific implementation
+ * of the support routine for the statvfs(2) system call
+ *
+ * @note This method may use a default implementation.
+ *
+ * @note The default implementation returns -1 and sets
+ * errno to ENOTSUP.
+ */
+ rtems_filesystem_statvfs_t statvfs_h;
+};
+
+extern const rtems_filesystem_operations_table
+rtems_filesystem_operations_default;
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of path evaluation.
+ */
+int rtems_filesystem_default_evalpath(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of path evaluation for make.
+ */
+int rtems_filesystem_default_evalformake(
+ const char *path,
+ rtems_filesystem_location_info_t *pathloc,
+ const char **name
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a link command.
+ */
+int rtems_filesystem_default_link(
+ rtems_filesystem_location_info_t *to_loc, /* IN */
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *name /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a unlink command.
+ */
+int rtems_filesystem_default_unlink(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation to determine the node type.
+ */
+rtems_filesystem_node_types_t rtems_filesystem_default_node_type(
+ rtems_filesystem_location_info_t *pathloc
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation to create a new node.
+ */
+int rtems_filesystem_default_mknod(
+ const char *path, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a chown command.
+ */
+int rtems_filesystem_default_chown(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ uid_t owner, /* IN */
+ gid_t group /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a freenode command.
+ */
+int rtems_filesystem_default_freenode(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a mount command.
+ */
+int rtems_filesystem_default_mount (
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a fsmount command.
+ */
+int rtems_filesystem_default_fsmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */
+ const void *data /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a unmount command.
+ */
+int rtems_filesystem_default_unmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a fsunmount command.
+ */
+int rtems_filesystem_default_fsunmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a utime command.
+ */
+int rtems_filesystem_default_utime(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a link command.
+ */
+int rtems_filesystem_default_evaluate_link(
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ int flags /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a symlink command.
+ */
+int rtems_filesystem_default_symlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ const char *link_name, /* IN */
+ const char *node_name
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a readlink command.
+ */
+ssize_t rtems_filesystem_default_readlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ char *buf, /* OUT */
+ size_t bufsize
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a rename command.
+ */
+int rtems_filesystem_default_rename(
+ rtems_filesystem_location_info_t *old_parent_loc, /* IN */
+ rtems_filesystem_location_info_t *old_loc, /* IN */
+ rtems_filesystem_location_info_t *new_parent_loc, /* IN */
+ const char *name /* IN */
+);
+
+/**
+ * @brief Provides a defualt routine for filesystem
+ * implementation of a statvfs command.
+ */
+int rtems_filesystem_default_statvfs(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct statvfs *buf /* OUT */
+);
+
+/**
+ * @brief Gets the mount handler for the file system @a type.
+ *
+ * @return The file system mount handler associated with the @a type, or
+ * @c NULL if no such association exists.
+ */
+rtems_filesystem_fsmount_me_t
+rtems_filesystem_get_mount_handler(
+ const char *type
+);
+
+/**
+ * @brief Contain file system specific information which is required to support
+ * fpathconf().
+ */
+typedef struct {
+ int link_max; /* count */
+ int max_canon; /* max formatted input line size */
+ int max_input; /* max input line size */
+ int name_max; /* max name length */
+ int path_max; /* max path */
+ int pipe_buf; /* pipe buffer size */
+ int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */
+ int posix_chown_restrictions; /* can chown: 0=no, 1=yes */
+ int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */
+ int posix_prio_io; /* priority IO, 0=no, 1=yes */
+ int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */
+ int posix_vdisable; /* special char processing, 0=no, 1=yes */
+} rtems_filesystem_limits_and_options_t;
+
+/**
+ * @brief Default pathconf settings.
+ *
+ * Override in a filesystem.
+ */
+extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf;
+
+/**
+ * @brief An open file data structure.
+ *
+ * It will be indexed by 'fd'.
+ *
+ * @todo Should really have a separate per/file data structure that this points
+ * to (eg: size, offset, driver, pathname should be in that)
+ */
+struct rtems_libio_tt {
+ rtems_driver_name_t *driver;
+ rtems_off64_t size; /* size of file */
+ rtems_off64_t offset; /* current offset into file */
+ uint32_t flags;
+ rtems_filesystem_location_info_t pathinfo;
+ rtems_id sem;
+ uint32_t data0; /* private to "driver" */
+ void *data1; /* ... */
+};
+
+/**
+ * @brief Paramameter block for read/write.
+ *
+ * It must include 'offset' instead of using iop's offset since we can have
+ * multiple outstanding i/o's on a device.
+ */
+typedef struct {
+ rtems_libio_t *iop;
+ rtems_off64_t offset;
+ char *buffer;
+ uint32_t count;
+ uint32_t flags;
+ uint32_t bytes_moved;
+} rtems_libio_rw_args_t;
+
+/**
+ * @brief Parameter block for open/close.
+ */
+typedef struct {
+ rtems_libio_t *iop;
+ uint32_t flags;
+ uint32_t mode;
+} rtems_libio_open_close_args_t;
+
+/**
+ * @brief Parameter block for ioctl.
+ */
+typedef struct {
+ rtems_libio_t *iop;
+ uint32_t command;
+ void *buffer;
+ uint32_t ioctl_return;
+} rtems_libio_ioctl_args_t;
+
+/**
+ * @name Flag Values
+ *
+ * @{
+ */
+
+#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */
+#define LIBIO_FLAGS_READ 0x0002 /* reading */
+#define LIBIO_FLAGS_WRITE 0x0004 /* writing */
+#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */
+#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */
+#define LIBIO_FLAGS_CREATE 0x0400 /* create file */
+#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */
+#define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
+
+/** @} */
+
+void rtems_libio_init(void);
+
+/**
+ * @name External I/O Handlers
+ *
+ * @{
+ */
+
+typedef int (*rtems_libio_open_t)(
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+);
+
+typedef int (*rtems_libio_close_t)(
+ int fd
+);
+
+typedef ssize_t (*rtems_libio_read_t)(
+ int fd,
+ void *buffer,
+ size_t count
+);
+
+typedef ssize_t (*rtems_libio_write_t)(
+ int fd,
+ const void *buffer,
+ size_t count
+);
+
+typedef int (*rtems_libio_ioctl_t)(
+ int fd,
+ uint32_t command,
+ void *buffer
+);
+
+typedef rtems_off64_t (*rtems_libio_lseek_t)(
+ int fd,
+ rtems_off64_t offset,
+ int whence
+);
+
+/** @} */
+
+/**
+ * @name Permission Macros
+ *
+ * @{
+ */
+
+/*
+ * The following macros are used to build up the permissions sets
+ * used to check permissions. These are similar in style to the
+ * mode_t bits and should stay compatible with them.
+ */
+#define RTEMS_LIBIO_PERMS_READ S_IROTH
+#define RTEMS_LIBIO_PERMS_WRITE S_IWOTH
+#define RTEMS_LIBIO_PERMS_RDWR (S_IROTH|S_IWOTH)
+#define RTEMS_LIBIO_PERMS_EXEC S_IXOTH
+#define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC
+#define RTEMS_LIBIO_PERMS_RWX S_IRWXO
+
+/** @} */
+
+union __rtems_dev_t {
+ dev_t device;
+ struct {
+ rtems_device_major_number major;
+ rtems_device_minor_number minor;
+ } __overlay;
+};
+
+static inline dev_t rtems_filesystem_make_dev_t(
+ rtems_device_major_number _major,
+ rtems_device_minor_number _minor
+)
+{
+ union __rtems_dev_t temp;
+
+ temp.__overlay.major = _major;
+ temp.__overlay.minor = _minor;
+ return temp.device;
+}
+
+static inline rtems_device_major_number rtems_filesystem_dev_major_t(
+ dev_t device
+)
+{
+ union __rtems_dev_t temp;
+
+ temp.device = device;
+ return temp.__overlay.major;
+}
+
+
+static inline rtems_device_minor_number rtems_filesystem_dev_minor_t(
+ dev_t device
+)
+{
+ union __rtems_dev_t temp;
+
+ temp.device = device;
+ return temp.__overlay.minor;
+}
+
+#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
+ do { \
+ (_major) = rtems_filesystem_dev_major_t ( _dev ); \
+ (_minor) = rtems_filesystem_dev_minor_t( _dev ); \
+ } while(0)
+
+/*
+ * Verifies that the permission flag is valid.
+ */
+#define rtems_libio_is_valid_perms( _perm ) \
+ (((~RTEMS_LIBIO_PERMS_RWX) & _perm ) == 0)
+
+/*
+ * Prototypes for filesystem
+ */
+
+void rtems_filesystem_initialize( void );
+
+typedef void (*rtems_libio_init_functions_t)(void);
+extern rtems_libio_init_functions_t rtems_libio_init_helper;
+
+void open_dev_console(void);
+
+typedef void (*rtems_libio_supp_functions_t)(void);
+extern rtems_libio_supp_functions_t rtems_libio_supp_helper;
+
+typedef void (*rtems_fs_init_functions_t)(void);
+extern rtems_fs_init_functions_t rtems_fs_init_helper;
+
+/**
+ * @brief Creates a directory and all its parent directories according to
+ * @a path.
+ *
+ * The @a mode value selects the access permissions of the directory.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+extern int rtems_mkdir(const char *path, mode_t mode);
+
+/** @} */
+
+/**
+ * @defgroup FileSystemTypesAndMount File System Types and Mount
+ *
+ * @ingroup LibIO
+ *
+ * @brief File system types and mount.
+ *
+ * @{
+ */
+
+/**
+ * @name File System Types
+ *
+ * @{
+ */
+
+#define RTEMS_FILESYSTEM_TYPE_IMFS "imfs"
+#define RTEMS_FILESYSTEM_TYPE_MINIIMFS "mimfs"
+#define RTEMS_FILESYSTEM_TYPE_DEVFS "devfs"
+#define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs"
+#define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs"
+#define RTEMS_FILESYSTEM_TYPE_NFS "nfs"
+#define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs"
+#define RTEMS_FILESYSTEM_TYPE_RFS "rfs"
+
+/** @} */
+
+/**
+ * @brief Mount table entry.
+ */
+struct rtems_filesystem_mount_table_entry_tt {
+ rtems_chain_node Node;
+ rtems_filesystem_location_info_t mt_point_node;
+ rtems_filesystem_location_info_t mt_fs_root;
+ int options;
+ void *fs_info;
+
+ rtems_filesystem_limits_and_options_t pathconf_limits_and_options;
+
+ /*
+ * The target or mount point of the file system.
+ */
+ const char *target;
+
+ /*
+ * The type of filesystem or the name of the filesystem.
+ */
+ const char *type;
+
+ /*
+ * When someone adds a mounted filesystem on a real device,
+ * this will need to be used.
+ *
+ * The lower layers can manage how this is managed. Leave as a
+ * string.
+ */
+ char *dev;
+};
+
+/**
+ * @brief File system options.
+ */
+typedef enum {
+ RTEMS_FILESYSTEM_READ_ONLY,
+ RTEMS_FILESYSTEM_READ_WRITE,
+ RTEMS_FILESYSTEM_BAD_OPTIONS
+} rtems_filesystem_options_t;
+
+/**
+ * @brief File system table entry.
+ */
+typedef struct rtems_filesystem_table_t {
+ const char *type;
+ rtems_filesystem_fsmount_me_t mount_h;
+} rtems_filesystem_table_t;
+
+/**
+ * @brief Static table of file systems.
+ *
+ * Externally defined by confdefs.h or the user.
+ */
+extern const rtems_filesystem_table_t rtems_filesystem_table [];
+
+/**
+ * @brief Registers a file system @a type.
+ *
+ * The @a mount_h handler will be used to mount a file system of this @a type.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+int rtems_filesystem_register(
+ const char *type,
+ rtems_filesystem_fsmount_me_t mount_h
+);
+
+/**
+ * @brief Unregisters a file system @a type.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+int rtems_filesystem_unregister(
+ const char *type
+);
+
+/**
+ * @brief Unmounts the file system at @a mount_path.
+ *
+ * @todo Due to file system implementation shortcomings it is possible to
+ * unmount file systems in use. This likely leads to heap corruption. Unmount
+ * only file systems which are not in use by the application.
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+int unmount(
+ const char *mount_path
+);
+
+/**
+ * @brief Mounts a file system at @a target.
+ *
+ * The @a source may be a path to the corresponding device file, or @c NULL.
+ * The @a target path must lead to an existing directory, or @c NULL. In case
+ * @a target is @c NULL, the root file system will be mounted. The @a data
+ * parameter will be forwarded to the file system initialization handler. The
+ * file system type is selected by @a filesystemtype and may be one of
+ * - RTEMS_FILESYSTEM_TYPE_DEVFS,
+ * - RTEMS_FILESYSTEM_TYPE_DOSFS,
+ * - RTEMS_FILESYSTEM_TYPE_FTPFS,
+ * - RTEMS_FILESYSTEM_TYPE_IMFS,
+ * - RTEMS_FILESYSTEM_TYPE_MINIIMFS,
+ * - RTEMS_FILESYSTEM_TYPE_NFS,
+ * - RTEMS_FILESYSTEM_TYPE_RFS, or
+ * - RTEMS_FILESYSTEM_TYPE_TFTPFS.
+ *
+ * Only configured or registered file system types are available. You can add
+ * file system types to your application configuration with
+ * - CONFIGURE_FILESYSTEM_DEVFS,
+ * - CONFIGURE_FILESYSTEM_DOSFS,
+ * - CONFIGURE_FILESYSTEM_FTPFS,
+ * - CONFIGURE_FILESYSTEM_IMFS,
+ * - CONFIGURE_FILESYSTEM_MINIIMFS,
+ * - CONFIGURE_FILESYSTEM_NFS,
+ * - CONFIGURE_FILESYSTEM_RFS, and
+ * - CONFIGURE_FILESYSTEM_TFTPFS.
+ *
+ * @see rtems_filesystem_register() and mount_and_make_target_path().
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+int mount(
+ const char *source,
+ const char *target,
+ const char *filesystemtype,
+ rtems_filesystem_options_t options,
+ const void *data
+);
+
+/**
+ * @brief Mounts a file system and makes the @a target path.
+ *
+ * The @a target path will be created with rtems_mkdir() and must not be
+ * @c NULL.
+ *
+ * @see mount().
+ *
+ * @retval 0 Successful operation.
+ * @retval -1 An error occured. The @c errno indicates the error.
+ */
+int mount_and_make_target_path(
+ const char *source,
+ const char *target,
+ const char *filesystemtype,
+ rtems_filesystem_options_t options,
+ const void *data
+);
+
+/**
+ * @brief Per file system type routine.
+ *
+ * @see rtems_filesystem_iterate().
+ *
+ * @retval true Stop the iteration.
+ * @retval false Continue the iteration.
+ */
+typedef bool (*rtems_per_filesystem_routine)(
+ const rtems_filesystem_table_t *fs_entry,
+ void *arg
+);
+
+/**
+ * @brief Iterates over all file system types.
+ *
+ * For each file system type the @a routine will be called with the entry and
+ * the @a routine_arg parameter.
+ *
+ * Do not register or unregister file system types in @a routine.
+ *
+ * The iteration is protected by the IO library mutex.
+ *
+ * @retval true Iteration stopped due to @a routine return status.
+ * @retval false Iteration through all entries.
+ */
+bool rtems_filesystem_iterate(
+ rtems_per_filesystem_routine routine,
+ void *routine_arg
+);
+
+/**
+ * @brief Per file system mount routine.
+ *
+ * @see rtems_filesystem_mount_iterate().
+ *
+ * @retval true Stop the iteration.
+ * @retval false Continue the iteration.
+ */
+typedef bool (*rtems_per_filesystem_mount_routine)(
+ const rtems_filesystem_mount_table_entry_t *mt_entry,
+ void *arg
+);
+
+/**
+ * @brief Iterates over all file system mounts.
+ *
+ * For each file system mount the @a routine will be called with the entry and
+ * the @a routine_arg parameter.
+ *
+ * Do not mount or unmount file systems in @a routine.
+ *
+ * The iteration is protected by the IO library mutex.
+ *
+ * @retval true Iteration stopped due to @a routine return status.
+ * @retval false Iteration through all entries.
+ */
+bool
+rtems_filesystem_mount_iterate(
+ rtems_per_filesystem_mount_routine routine,
+ void *routine_arg
+);
+
+/**
+ * @brief Boot time mount table entry.
+ */
+typedef struct {
+ const char *type;
+ rtems_filesystem_options_t fsoptions;
+ const char *device;
+ const char *mount_point;
+} rtems_filesystem_mount_table_t;
+
+/**
+ * @brief Boot time mount table.
+ *
+ * @todo Only the first entry will be evaluated. Why do we need a table?
+ */
+extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
+
+/**
+ * @brief Boot time mount table entry count.
+ *
+ * @todo Only the first entry will be evaluated. Why do we need a table?
+ */
+extern const int rtems_filesystem_mount_table_size;
+
+/** @} */
+
+/**
+ * @defgroup Termios Termios
+ *
+ * @ingroup LibIO
+ *
+ * @brief Termios
+ *
+ * @{
+ */
+
+typedef struct rtems_termios_callbacks {
+ int (*firstOpen)(int major, int minor, void *arg);
+ int (*lastClose)(int major, int minor, void *arg);
+ int (*pollRead)(int minor);
+ ssize_t (*write)(int minor, const char *buf, size_t len);
+ int (*setAttributes)(int minor, const struct termios *t);
+ int (*stopRemoteTx)(int minor);
+ int (*startRemoteTx)(int minor);
+ int outputUsesInterrupts;
+} rtems_termios_callbacks;
+
+void rtems_termios_initialize (void);
+
+/*
+ * CCJ: Change before opening a tty. Newer code from Eric is coming
+ * so extra work to handle an open tty is not worth it. If the tty
+ * is open, close then open it again.
+ */
+rtems_status_code rtems_termios_bufsize (
+ int cbufsize, /* cooked buffer size */
+ int raw_input, /* raw input buffer size */
+ int raw_output /* raw output buffer size */
+);
+
+rtems_status_code rtems_termios_open (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg,
+ const rtems_termios_callbacks *callbacks
+);
+
+rtems_status_code rtems_termios_close(
+ void *arg
+);
+
+rtems_status_code rtems_termios_read(
+ void *arg
+);
+
+rtems_status_code rtems_termios_write(
+ void *arg
+);
+
+rtems_status_code rtems_termios_ioctl(
+ void *arg
+);
+
+int rtems_termios_enqueue_raw_characters(
+ void *ttyp,
+ char *buf,
+ int len
+);
+
+int rtems_termios_dequeue_characters(
+ void *ttyp,
+ int len
+);
+
+/** @} */
+
+/**
+ * @brief The pathconf setting for a file system.
+ */
+#define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options)
+
+/**
+ * @brief The type of file system. Its name.
+ */
+#define rtems_filesystem_type(_mte) ((_mte)->type)
+
+/**
+ * @brief The mount point of a file system.
+ */
+#define rtems_filesystem_mount_point(_mte) ((_mte)->target)
+
+/**
+ * @brief The device entry of a file system.
+ */
+#define rtems_filesystem_mount_device(_mte) ((_mte)->dev)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_LIBIO_H */
diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
new file mode 100644
index 0000000000..f5cb537210
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -0,0 +1,246 @@
+/**
+ * @file rtems/libio_.h
+ */
+
+/*
+ * Libio Internal Information
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_LIBIO__H
+#define _RTEMS_RTEMS_LIBIO__H
+
+#include <rtems.h>
+#include <rtems/libio.h> /* include before standard IO */
+
+#include <sys/types.h>
+
+#include <errno.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Semaphore to protect the io table
+ */
+
+#define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O')
+#define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n)
+
+extern rtems_id rtems_libio_semaphore;
+
+/*
+ * File descriptor Table Information
+ */
+
+extern uint32_t rtems_libio_number_iops;
+extern rtems_libio_t *rtems_libio_iops;
+extern rtems_libio_t *rtems_libio_last_iop;
+extern rtems_libio_t *rtems_libio_iop_freelist;
+
+/*
+ * rtems_libio_iop
+ *
+ * Macro to return the file descriptor pointer.
+ */
+
+#define rtems_libio_iop(_fd) \
+ ((((uint32_t)(_fd)) < rtems_libio_number_iops) ? \
+ &rtems_libio_iops[_fd] : 0)
+
+/*
+ * rtems_libio_iop_to_descriptor
+ *
+ * Macro to convert an internal file descriptor pointer (iop) into
+ * the integer file descriptor used by the "section 2" system calls.
+ */
+
+#define rtems_libio_iop_to_descriptor(_iop) \
+ ((!(_iop)) ? -1 : (_iop - rtems_libio_iops))
+
+/*
+ * rtems_libio_check_is_open
+ *
+ * Macro to check if a file descriptor is actually open.
+ */
+
+#define rtems_libio_check_is_open(_iop) \
+ do { \
+ if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
+ errno = EBADF; \
+ return -1; \
+ } \
+ } while (0)
+
+/*
+ * rtems_libio_check_fd
+ *
+ * Macro to check if a file descriptor number is valid.
+ */
+
+#define rtems_libio_check_fd(_fd) \
+ do { \
+ if ((uint32_t) (_fd) >= rtems_libio_number_iops) { \
+ errno = EBADF; \
+ return -1; \
+ } \
+ } while (0)
+
+/*
+ * rtems_libio_check_buffer
+ *
+ * Macro to check if a buffer pointer is valid.
+ */
+
+#define rtems_libio_check_buffer(_buffer) \
+ do { \
+ if ((_buffer) == 0) { \
+ errno = EINVAL; \
+ return -1; \
+ } \
+ } while (0)
+
+/*
+ * rtems_libio_check_count
+ *
+ * Macro to check if a count or length is valid.
+ */
+
+#define rtems_libio_check_count(_count) \
+ do { \
+ if ((_count) == 0) { \
+ return 0; \
+ } \
+ } while (0)
+
+/*
+ * rtems_libio_check_permissions
+ *
+ * Macro to check if a file descriptor is open for this operation.
+ */
+
+#define rtems_libio_check_permissions(_iop, _flag) \
+ do { \
+ if (((_iop)->flags & (_flag)) == 0) { \
+ rtems_set_errno_and_return_minus_one( EINVAL ); \
+ return -1; \
+ } \
+ } while (0)
+
+/*
+ * rtems_filesystem_freenode
+ *
+ * Macro to free a node.
+ */
+
+void rtems_filesystem_freenode( rtems_filesystem_location_info_t* node );
+
+/*
+ * External structures
+ */
+#include <rtems/userenv.h>
+
+extern rtems_user_env_t * rtems_current_user_env;
+extern rtems_user_env_t rtems_global_user_env;
+
+/*
+ * Instantiate a private copy of the per user information for the calling task.
+ */
+
+rtems_status_code rtems_libio_set_private_env(void);
+rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
+
+static inline void rtems_libio_lock( void )
+{
+ rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+}
+
+static inline void rtems_libio_unlock( void )
+{
+ rtems_semaphore_release( rtems_libio_semaphore );
+}
+
+/*
+ * File Descriptor Routine Prototypes
+ */
+
+rtems_libio_t *rtems_libio_allocate(void);
+
+uint32_t rtems_libio_fcntl_flags(
+ uint32_t fcntl_flags
+);
+
+uint32_t rtems_libio_to_fcntl_flags(
+ uint32_t flags
+);
+
+void rtems_libio_free(
+ rtems_libio_t *iop
+);
+
+int rtems_libio_is_open_files_in_fs(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+);
+
+int rtems_libio_is_file_open(
+ void *node_access
+);
+
+/*
+ * File System Routine Prototypes
+ */
+
+int rtems_filesystem_evaluate_relative_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc,
+ int follow_link
+);
+
+int rtems_filesystem_evaluate_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc,
+ int follow_link
+);
+
+int rtems_filesystem_dirname(
+ const char *pathname
+);
+
+int rtems_filesystem_prefix_separators(
+ const char *pathname,
+ int pathnamelen
+);
+
+void rtems_filesystem_initialize(void);
+
+int init_fs_mount_table(void);
+
+int rtems_filesystem_is_separator(char ch);
+
+void rtems_filesystem_get_start_loc(const char *path,
+ int *index,
+ rtems_filesystem_location_info_t *loc);
+
+void rtems_filesystem_get_sym_start_loc(const char *path,
+ int *index,
+ rtems_filesystem_location_info_t *loc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h
new file mode 100644
index 0000000000..af092982f7
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/malloc.h
@@ -0,0 +1,186 @@
+/**
+ * @file rtems/malloc.h
+ */
+
+/*
+ * RTEMS Malloc Extensions
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_MALLOC_H
+#define _RTEMS_MALLOC_H
+
+#include <rtems.h>
+#include <rtems/bspIo.h>
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Malloc Statistics Structure
+ */
+typedef struct {
+ uint32_t space_available; /* current size of malloc area */
+ uint32_t malloc_calls; /* # calls to malloc */
+ uint32_t memalign_calls; /* # calls to memalign */
+ uint32_t free_calls;
+ uint32_t realloc_calls;
+ uint32_t calloc_calls;
+ uint32_t max_depth; /* most ever malloc'd at 1 time */
+ uintmax_t lifetime_allocated;
+ uintmax_t lifetime_freed;
+} rtems_malloc_statistics_t;
+
+/*
+ * Malloc statistics plugin
+ */
+typedef struct {
+ void (*initialize)(void);
+ void (*at_malloc)(void *);
+ void (*at_free)(void *);
+} rtems_malloc_statistics_functions_t;
+
+extern rtems_malloc_statistics_functions_t
+ rtems_malloc_statistics_helpers_table;
+extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
+
+/*
+ * Malloc Heap Extension (sbrk) plugin
+ */
+typedef struct {
+ void *(*initialize)(void *, size_t);
+ void *(*extend)(size_t);
+} rtems_malloc_sbrk_functions_t;
+
+extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
+extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
+
+/*
+ * Malloc Plugin to Dirty Memory at Allocation Time
+ */
+typedef void (*rtems_malloc_dirtier_t)(void *, size_t);
+extern rtems_malloc_dirtier_t rtems_malloc_dirty_helper;
+
+/** @brief Dirty memory function
+ *
+ * This method fills the specified area with a non-zero pattern
+ * to aid in debugging programs which do not initialize their
+ * memory allocated from the heap.
+ */
+void rtems_malloc_dirty_memory(
+ void *start,
+ size_t size
+);
+
+/** @brief Print Malloc Statistic Usage Report
+ *
+ * This method fills in the called provided malloc statistics area.
+ *
+ * @return This method returns 0 if successful and -1 on error.
+ */
+int malloc_get_statistics(
+ rtems_malloc_statistics_t *stats
+);
+
+/** @brief Print Malloc Statistic Usage Report
+ *
+ * This method prints a malloc statistics report.
+ *
+ * @note It uses printk to print the report.
+ */
+void malloc_report_statistics(void);
+
+/** @brief Print Malloc Statistic Usage Report
+ *
+ * This method prints a malloc statistics report.
+ *
+ * @param[in] context is the context to pass to the print handler
+ * @param[in] print is the print handler
+ *
+ * @note It uses the CALLER's routine to print the report.
+ */
+void malloc_report_statistics_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+);
+
+/**
+ *
+ * This method is a help memalign implementation which does all
+ * error checking done by posix_memalign() EXCEPT it does NOT
+ * place numeric restrictions on the alignment value.
+ *
+ * @param[in] pointer points to the user pointer
+ * @param[in] alignment is the desired alignment
+ * @param[in] size is the allocation request size in bytes
+ *
+ * @return This methods returns zero on success and a POSIX errno
+ * value to indicate the failure condition. On success
+ * *pointer will contain the address of the allocated memory.
+ */
+int rtems_memalign(
+ void **pointer,
+ size_t alignment,
+ size_t size
+);
+
+/**
+ * @brief Allocates a memory area of size @a size bytes from the heap.
+ *
+ * If the alignment parameter @a alignment is not equal to zero, the allocated
+ * memory area will begin at an address aligned by this value.
+ *
+ * If the boundary parameter @a boundary is not equal to zero, the allocated
+ * memory area will fulfill a boundary constraint. The boundary value
+ * specifies the set of addresses which are aligned by the boundary value. The
+ * interior of the allocated memory area will not contain an element of this
+ * set. The begin or end address of the area may be a member of the set.
+ *
+ * A size value of zero will return a unique address which may be freed with
+ * free().
+ *
+ * The memory allocated by this function can be released with a call to free().
+ *
+ * @return A pointer to the begin of the allocated memory area, or @c NULL if
+ * no memory is available or the parameters are inconsistent.
+ */
+void *rtems_heap_allocate_aligned_with_boundary(
+ size_t size,
+ uintptr_t alignment,
+ uintptr_t boundary
+);
+
+/**
+ * @brief Extends the memory available for the heap using the memory area
+ * starting at @a area_begin of size @a area_size bytes.
+ *
+ * There are no alignment requirements. The memory area must be big enough to
+ * contain some maintainance blocks. It must not overlap parts of the current
+ * heap areas. Disconnected subordinate heap areas will lead to used blocks
+ * which cover the gaps. Extending with an inappropriate memory area will
+ * corrupt the heap.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ADDRESS Invalid memory area.
+ */
+rtems_status_code rtems_heap_extend(
+ void *area_begin,
+ uintptr_t area_size
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/rtems/termiostypes.h b/cpukit/libcsupport/include/rtems/termiostypes.h
new file mode 100644
index 0000000000..ebba9ca9f7
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/termiostypes.h
@@ -0,0 +1,210 @@
+/**
+ * @file rtems/termiostypes.h
+ */
+
+/*
+ * RTEMS termios device support internal data structures
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __TERMIOSTYPES_H
+#define __TERMIOSTYPES_H
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Wakeup callback data structure
+ */
+struct ttywakeup {
+ void (*sw_pfn)(struct termios *tty, void *arg);
+ void *sw_arg;
+};
+
+/*
+ * Variables associated with the character buffer
+ */
+struct rtems_termios_rawbuf {
+ char *theBuf;
+ volatile unsigned int Head;
+ volatile unsigned int Tail;
+ volatile unsigned int Size;
+ rtems_id Semaphore;
+};
+/*
+ * Variables associated with each termios instance.
+ * One structure for each hardware I/O device.
+ */
+struct rtems_termios_tty {
+ /*
+ * Linked-list of active TERMIOS devices
+ */
+ struct rtems_termios_tty *forw;
+ struct rtems_termios_tty *back;
+
+ /*
+ * How many times has this device been opened
+ */
+ int refcount;
+
+ /*
+ * This device
+ */
+ rtems_device_major_number major;
+ rtems_device_minor_number minor;
+
+ /*
+ * Mutual-exclusion semaphores
+ */
+ rtems_id isem;
+ rtems_id osem;
+
+ /*
+ * The canonical (cooked) character buffer
+ */
+ char *cbuf;
+ int ccount;
+ int cindex;
+
+ /*
+ * Keep track of cursor (printhead) position
+ */
+ int column;
+ int read_start_column;
+
+ /*
+ * The ioctl settings
+ */
+ struct termios termios;
+ rtems_interval vtimeTicks;
+
+ /*
+ * Raw input character buffer
+ */
+ struct rtems_termios_rawbuf rawInBuf;
+ uint32_t rawInBufSemaphoreOptions;
+ rtems_interval rawInBufSemaphoreTimeout;
+ rtems_interval rawInBufSemaphoreFirstTimeout;
+ unsigned int rawInBufDropped; /* Statistics */
+
+ /*
+ * Raw output character buffer
+ */
+ struct rtems_termios_rawbuf rawOutBuf;
+ int t_dqlen; /* count of characters dequeued from device */
+ enum {rob_idle, rob_busy, rob_wait } rawOutBufState;
+
+ /*
+ * Callbacks to device-specific routines
+ */
+ rtems_termios_callbacks device;
+ volatile unsigned int flow_ctrl;
+ unsigned int lowwater,highwater;
+
+ /*
+ * I/O task IDs (for task-driven drivers)
+ */
+ rtems_id rxTaskId;
+ rtems_id txTaskId;
+
+ /*
+ * line discipline related stuff
+ */
+ int t_line; /* id of line discipline */
+ void *t_sc; /* hook for discipline-specific data structure */
+
+ /*
+ * Wakeup callback variables
+ */
+ struct ttywakeup tty_snd;
+ struct ttywakeup tty_rcv;
+ int tty_rcvwakeup;
+};
+
+struct rtems_termios_linesw {
+ int (*l_open) (struct rtems_termios_tty *tp);
+ int (*l_close)(struct rtems_termios_tty *tp);
+ int (*l_read )(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
+ int (*l_write)(struct rtems_termios_tty *tp,rtems_libio_rw_args_t *args);
+ int (*l_rint )(int c,struct rtems_termios_tty *tp);
+ int (*l_start)(struct rtems_termios_tty *tp);
+ int (*l_ioctl)(struct rtems_termios_tty *tp,rtems_libio_ioctl_args_t *args);
+ int (*l_modem)(struct rtems_termios_tty *tp,int flags);
+};
+
+/*
+ * FIXME: this should move to libio.h!
+ * values for rtems_termios_callbacks.outputUsesInterrupts
+ */
+#define TERMIOS_POLLED 0
+#define TERMIOS_IRQ_DRIVEN 1
+#define TERMIOS_TASK_DRIVEN 2
+
+/*
+ * FIXME: this should move to termios.h!
+ */
+void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty);
+
+/*
+ * FIXME: this should move to termios.h!
+ * put a string to output ring buffer
+ */
+void rtems_termios_puts (
+ const void *buf,
+ int len,
+ struct rtems_termios_tty *tty
+);
+
+/*
+ * global hooks for line disciplines
+ */
+extern struct rtems_termios_linesw rtems_termios_linesw[];
+extern int rtems_termios_nlinesw;
+
+#define TTYDISC 0 /* termios tty line discipline */
+#define TABLDISC 3 /* tablet discipline */
+#define SLIPDISC 4 /* serial IP discipline */
+#define PPPDISC 5 /* PPP discipline */
+#define MAXLDISC 8
+
+/* baudrate xxx integer type */
+typedef int32_t rtems_termios_baud_t;
+
+/* convert xxx integer to equivalent Bxxx constant */
+int rtems_termios_number_to_baud(rtems_termios_baud_t baud);
+
+/* convert Bxxx constant to xxx integer */
+rtems_termios_baud_t rtems_termios_baud_to_number(int termios_baud);
+
+/* convert Bxxx constant to index */
+int rtems_termios_baud_to_index(rtems_termios_baud_t termios_baud);
+
+/*
+ * This method is used by a driver to tell termios its
+ * initial baud rate. This is especially important when
+ * the device driver does not set the baud to the default
+ * of B9600.
+ */
+int rtems_termios_set_initial_baud(
+ struct rtems_termios_tty *ttyp,
+ rtems_termios_baud_t baud
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TERMIOSTYPES_H */
diff --git a/cpukit/libcsupport/include/rtems/watchdogdrv.h b/cpukit/libcsupport/include/rtems/watchdogdrv.h
new file mode 100644
index 0000000000..309ebf7b81
--- /dev/null
+++ b/cpukit/libcsupport/include/rtems/watchdogdrv.h
@@ -0,0 +1,73 @@
+/**
+ * @file rtems/watchdogdrv.h
+ *
+ * This file describes the Watchdog Driver for all boards.
+ * A watchdog is a hardware device that will reset the board
+ * if not touched in a specific way at a regular interval.
+ * It is a simple, yet important, part of many embedded systems.
+ */
+
+/*
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_WATCHDOGDRV_H
+#define _RTEMS_WATCHDOGDRV_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This macro defines the watchdog device driver entry points.
+ */
+#define WATCHDOG_DRIVER_TABLE_ENTRY \
+ { Watchdog_initialize, NULL, NULL, NULL, NULL, Watchdog_control }
+
+/**
+ * @brief Watchdog Driver Initialization
+ *
+ * This method initializes the watchdog hardware device. The device
+ * should be initialized as DISABLED since BSP initialization may
+ * take longer than the timeout period for the watchdog.
+ *
+ * @param[in] major is the watchdog device major number
+ * @param[in] minor is the watchdog device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver Watchdog_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arguments
+);
+
+/**
+ * @brief Watchdog Driver IO Control
+ *
+ * This method implements the IO Control device driver entry
+ * point for the watchdog hardware device.
+ *
+ * @param[in] major is the watchdog device major number
+ * @param[in] minor is the watchdog device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver Watchdog_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arguments
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/spurious.h b/cpukit/libcsupport/include/spurious.h
new file mode 100644
index 0000000000..9aeffb53ce
--- /dev/null
+++ b/cpukit/libcsupport/include/spurious.h
@@ -0,0 +1,45 @@
+/**
+ * @file rtems/spurious.h
+ */
+
+/* spurious.h
+ *
+ * This file describes the Spurious Interrupt Driver for all boards.
+ *
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SPURIOUS_H
+#define _RTEMS_SPURIOUS_H
+
+#include <rtems/rtems/types.h> /* rtems_id */
+#include <rtems/io.h> /* rtems_device_driver */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SPURIOUS_DRIVER_TABLE_ENTRY \
+ { Spurious_Initialize, NULL, NULL, NULL, NULL, NULL }
+
+rtems_device_driver Spurious_Initialize(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *,
+ rtems_id,
+ uint32_t *
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/sys/filio.h b/cpukit/libcsupport/include/sys/filio.h
new file mode 100644
index 0000000000..5a8b7e4bbb
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/filio.h
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)filio.h 8.1 (Berkeley) 3/28/94
+ * $Id$
+ */
+
+#ifndef _SYS_FILIO_H_
+#define _SYS_FILIO_H_
+
+#include <sys/ioccom.h>
+
+/* RTEMS defines all of these in sys/ioccom.h */
+#if 0
+/* Generic file-descriptor ioctl's. */
+#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
+#define FIONCLEX _IO('f', 2) /* remove close on exec */
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#define FIOSETOWN _IOW('f', 124, int) /* set owner */
+#define FIOGETOWN _IOR('f', 123, int) /* get owner */
+#endif
+
+#endif /* !_SYS_FILIO_H_ */
diff --git a/cpukit/libcsupport/include/sys/ioccom.h b/cpukit/libcsupport/include/sys/ioccom.h
new file mode 100644
index 0000000000..1a7fd27ef7
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/ioccom.h
@@ -0,0 +1,104 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ioccom.h 8.2 (Berkeley) 3/28/94
+ * $FreeBSD: src/sys/sys/ioccom.h,v 1.15 2004/04/07 04:19:49 imp Exp $
+ */
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_IOCCOM_H_
+#define _SYS_IOCCOM_H_
+
+#include <sys/types.h>
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word. The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
+#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
+#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
+#define IOCGROUP(x) (((x) >> 8) & 0xff)
+
+#define IOCPARM_MAX PAGE_SIZE /* max size of ioctl, mult. of PAGE_SIZE */
+#define IOC_VOID 0x20000000 /* no parameters */
+#define IOC_OUT 0x40000000 /* copy out parameters */
+#define IOC_IN 0x80000000 /* copy in parameters */
+#define IOC_INOUT (IOC_IN|IOC_OUT)
+#define IOC_DIRMASK 0xe0000000 /* mask for IN/OUT/VOID */
+
+#define _IOC(inout,group,num,len) \
+ (u_int32_t) ((u_int32_t)inout | \
+ (u_int32_t) ((u_int32_t)((u_int32_t)len & IOCPARM_MASK) << 16) | \
+ (u_int32_t)((group) << 8) | \
+ (u_int32_t)(num))
+#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
+#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
+#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
+/* this should be _IORW, but stdio got there first */
+#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
+
+/*
+ * IOCTL values
+ */
+
+#define RTEMS_IO_GET_ATTRIBUTES 1
+#define RTEMS_IO_SET_ATTRIBUTES 2
+#define RTEMS_IO_TCDRAIN 3
+#define RTEMS_IO_RCVWAKEUP 4
+#define RTEMS_IO_SNDWAKEUP 5
+
+/* copied from libnetworking/sys/filio.h and commented out there */
+/* Generic file-descriptor ioctl's. */
+#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
+#define FIONCLEX _IO('f', 2) /* remove close on exec */
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#define FIOSETOWN _IOW('f', 124, int) /* set owner */
+#define FIOGETOWN _IOR('f', 123, int) /* get owner */
+
+#ifndef _KERNEL
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#ifndef __ioctl_command_defined
+typedef u_int32_t ioctl_command_t;
+#define __ioctl_command_defined
+#endif
+
+__BEGIN_DECLS
+int ioctl(int, ioctl_command_t, ...);
+__END_DECLS
+
+#endif /* !KERNEL */
+
+#endif /* !_SYS_IOCCOM_H_ */
diff --git a/cpukit/libcsupport/include/sys/ioctl.h b/cpukit/libcsupport/include/sys/ioctl.h
new file mode 100644
index 0000000000..3957396ead
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/ioctl.h
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ioctl.h 8.6 (Berkeley) 3/28/94
+ * $FreeBSD: src/sys/sys/ioctl.h,v 1.13 2004/06/11 11:16:26 phk Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_IOCTL_H_
+#define _SYS_IOCTL_H_
+
+#include <sys/ttycom.h>
+
+/*
+ * Pun for SunOS prior to 3.2. SunOS 3.2 and later support TIOCGWINSZ
+ * and TIOCSWINSZ (yes, even 3.2-3.5, the fact that it wasn't documented
+ * notwithstanding).
+ */
+struct ttysize {
+ unsigned short ts_lines;
+ unsigned short ts_cols;
+ unsigned short ts_xxx;
+ unsigned short ts_yyy;
+};
+#define TIOCGSIZE TIOCGWINSZ
+#define TIOCSSIZE TIOCSWINSZ
+
+#include <sys/ioccom.h>
+
+#include <sys/filio.h>
+#include <sys/sockio.h>
+
+#endif /* !_SYS_IOCTL_H_ */
diff --git a/cpukit/libcsupport/include/sys/sockio.h b/cpukit/libcsupport/include/sys/sockio.h
new file mode 100644
index 0000000000..15ade24729
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/sockio.h
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)sockio.h 8.1 (Berkeley) 3/28/94
+ * $FreeBSD: src/sys/sys/sockio.h,v 1.31 2006/07/09 06:04:00 sam Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_SOCKIO_H_
+#define _SYS_SOCKIO_H_
+
+#include <sys/ioccom.h>
+
+/* Socket ioctl's. */
+#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
+#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
+#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
+#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
+#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
+#define SIOCSPGRP _IOW('s', 8, int) /* set process group */
+#define SIOCGPGRP _IOR('s', 9, int) /* get process group */
+
+#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
+#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
+#define SIOCGETVIFCNT _IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt */
+#define SIOCGETSGCNT _IOWR('r', 16, struct sioc_sg_req) /* get s,g pkt cnt */
+
+#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
+#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */
+#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
+#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
+#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */
+#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
+#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
+#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
+#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */
+#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
+#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
+#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */
+#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
+#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */
+#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
+#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
+#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
+#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
+#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
+#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
+
+#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
+#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
+#define SIOCGIFMTU _IOWR('i', 51, struct ifreq) /* get IF mtu */
+#define SIOCSIFMTU _IOW('i', 52, struct ifreq) /* set IF mtu */
+#define SIOCGIFPHYS _IOWR('i', 53, struct ifreq) /* get IF wire */
+#define SIOCSIFPHYS _IOW('i', 54, struct ifreq) /* set IF wire */
+#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
+#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
+
+/*
+ * RTEMS additions for setting/getting `tap' function on incoming packets.
+ */
+#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
+#define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
+
+#endif /* !_SYS_SOCKIO_H_ */
diff --git a/cpukit/libcsupport/include/sys/statvfs.h b/cpukit/libcsupport/include/sys/statvfs.h
new file mode 100644
index 0000000000..1029eb3c6b
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/statvfs.h
@@ -0,0 +1,52 @@
+/*
+ * COPYRIGHT (c) 2009 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/*
+ * The statvfs as defined by the SUS:
+ * http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/statvfs.h.html
+ */
+
+#ifndef _SYS_STATVFS_H_
+#define _SYS_STATVFS_H_
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef uint64_t fsblkcnt_t;
+typedef uint32_t fsfilcnt_t;
+
+struct statvfs
+{
+ unsigned long f_bsize; /**< File system block size. */
+ unsigned long f_frsize; /**< Fundamental file system block size. */
+ fsblkcnt_t f_blocks; /**< Total number of blocks on file system in units
+ * of f_frsize. */
+ fsblkcnt_t f_bfree; /**< Total number of free blocks. */
+ fsblkcnt_t f_bavail; /**< Number of free blocks available to
+ * non-privileged process. */
+ fsfilcnt_t f_files; /**< Total number of file serial numbers. */
+ fsfilcnt_t f_ffree; /**< Total number of free file serial numbers. */
+ fsfilcnt_t f_favail; /**< Number of file serial numbers available to
+ * non-privileged process. */
+ unsigned long f_fsid; /**< File system ID. */
+ unsigned long f_flag; /**< Bit mask of f_flag values. */
+ unsigned long f_namemax; /**< Maximum filename length. */
+};
+
+extern int statvfs(const char *, struct statvfs *);
+extern int fstatvfs(int, struct statvfs *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/sys/termios.h b/cpukit/libcsupport/include/sys/termios.h
new file mode 100644
index 0000000000..f619c95709
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/termios.h
@@ -0,0 +1,198 @@
+/*
+ * POSIX termios implementation for RTEMS console device driver.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef TERMIOS_H
+#define TERMIOS_H
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+#define NCCS 19
+struct termios {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[NCCS]; /* control characters */
+};
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK 0000020
+#define ISTRIP 0000040
+#define INLCR 0000100
+#define IGNCR 0000200
+#define ICRNL 0000400
+#define IUCLC 0001000
+#define IXON 0002000
+#define IXANY 0004000
+#define IXOFF 0010000
+#define IMAXBEL 0020000
+
+/* c_oflag bits */
+#define OPOST 0000001
+#define OLCUC 0000002
+#define ONLCR 0000004
+#define OCRNL 0000010
+#define ONOCR 0000020
+#define ONLRET 0000040
+#define OFILL 0000100
+#define OFDEL 0000200
+#define NLDLY 0000400
+#define NL0 0000000
+#define NL1 0000400
+#define CRDLY 0003000
+#define CR0 0000000
+#define CR1 0001000
+#define CR2 0002000
+#define CR3 0003000
+#define TABDLY 0014000
+#define TAB0 0000000
+#define TAB1 0004000
+#define TAB2 0010000
+#define TAB3 0014000
+#define XTABS 0014000
+#define BSDLY 0020000
+#define BS0 0000000
+#define BS1 0020000
+#define VTDLY 0040000
+#define VT0 0000000
+#define VT1 0040000
+#define FFDLY 0100000
+#define FF0 0000000
+#define FF1 0100000
+
+/* c_cflag bit meaning */
+#define CBAUD 0010017
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+#define EXTA B19200
+#define EXTB B38400
+#define CSIZE 0000060
+#define CS5 0000000
+#define CS6 0000020
+#define CS7 0000040
+#define CS8 0000060
+#define CSTOPB 0000100
+#define CREAD 0000200
+#define PARENB 0000400
+#define PARODD 0001000
+#define HUPCL 0002000
+#define CLOCAL 0004000
+#define CBAUDEX 0010000
+#define B57600 0010001
+#define B115200 0010002
+#define B230400 0010003
+#define B460800 0010004
+#define CIBAUD 002003600000 /* input baud rate (not used) */
+#define CRTSCTS 020000000000 /* flow control */
+
+#define RTEMS_TERMIOS_NUMBER_BAUD_RATES 20
+
+/* c_lflag bits */
+#define ISIG 0000001
+#define ICANON 0000002
+#define XCASE 0000004
+#define ECHO 0000010
+#define ECHOE 0000020
+#define ECHOK 0000040
+#define ECHONL 0000100
+#define NOFLSH 0000200
+#define TOSTOP 0000400
+#define ECHOCTL 0001000
+#define ECHOPRT 0002000
+#define ECHOKE 0004000
+#define FLUSHO 0010000
+#define PENDIN 0040000
+#define IEXTEN 0100000
+
+/* tcflow() and TCXONC use these */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* tcflush() and TCFLSH use these */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* tcsetattr uses these */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
+
+int tcdrain(int);
+int tcflow(int, int);
+int tcflush(int, int);
+int tcgetattr(int, struct termios *);
+int tcsetattr(int, int, struct termios *);
+int tcdrain(int);
+pid_t tcgetprgrp(int);
+int tcsetprgrp(int, pid_t);
+int tcsendbreak(int, int);
+
+speed_t cfgetospeed(const struct termios *tp);
+int cfsetospeed(struct termios *tp, speed_t speed);
+speed_t cfgetispeed(const struct termios *tp);
+int cfsetispeed(struct termios *tp, speed_t speed);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TERMIOS_H */
diff --git a/cpukit/libcsupport/include/sys/ttycom.h b/cpukit/libcsupport/include/sys/ttycom.h
new file mode 100644
index 0000000000..f2e491bc50
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/ttycom.h
@@ -0,0 +1,141 @@
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ttycom.h 8.1 (Berkeley) 3/28/94
+ * $Id$
+ */
+
+#ifndef _SYS_TTYCOM_H_
+#define _SYS_TTYCOM_H_
+
+#include <sys/ioccom.h>
+
+/*
+ * Tty ioctl's except for those supported only for backwards compatibility
+ * with the old tty driver.
+ */
+
+/*
+ * Window/terminal size structure. This information is stored by the kernel
+ * in order to provide a consistent interface, but is not used by the kernel.
+ */
+struct winsize {
+ unsigned short ws_row; /* rows, in characters */
+ unsigned short ws_col; /* columns, in characters */
+ unsigned short ws_xpixel; /* horizontal size, pixels */
+ unsigned short ws_ypixel; /* vertical size, pixels */
+};
+
+#define TIOCMODG _IOR('t', 3, int) /* get modem control state */
+#define TIOCMODS _IOW('t', 4, int) /* set modem control state */
+#define TIOCM_LE 0001 /* line enable */
+#define TIOCM_DTR 0002 /* data terminal ready */
+#define TIOCM_RTS 0004 /* request to send */
+#define TIOCM_ST 0010 /* secondary transmit */
+#define TIOCM_SR 0020 /* secondary receive */
+#define TIOCM_CTS 0040 /* clear to send */
+#define TIOCM_CAR 0100 /* carrier detect */
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RNG 0200 /* ring */
+#define TIOCM_RI TIOCM_RNG
+#define TIOCM_DSR 0400 /* data set ready */
+ /* 8-10 compat */
+#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */
+#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */
+ /* 15 unused */
+#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */
+ /* 17-18 compat */
+#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */
+#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */
+#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */
+#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */
+#define TIOCGETD _IOR('t', 26, int) /* get line discipline */
+#define TIOCSETD _IOW('t', 27, int) /* set line discipline */
+ /* 127-124 compat */
+#define TIOCSBRK _IO('t', 123) /* set break bit */
+#define TIOCCBRK _IO('t', 122) /* clear break bit */
+#define TIOCSDTR _IO('t', 121) /* set data terminal ready */
+#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */
+#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */
+#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */
+ /* 117-116 compat */
+#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */
+#define TIOCSTI _IOW('t', 114, char) /* simulate terminal input */
+#define TIOCNOTTY _IO('t', 113) /* void tty association */
+#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */
+#define TIOCPKT_DATA 0x00 /* data packet */
+#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */
+#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */
+#define TIOCPKT_STOP 0x04 /* stop output */
+#define TIOCPKT_START 0x08 /* start output */
+#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */
+#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */
+#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */
+#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */
+#define TIOCSTART _IO('t', 110) /* start output, like ^Q */
+#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */
+#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */
+#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */
+#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */
+#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */
+#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */
+#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */
+#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */
+#define TIOCSTAT _IO('t', 101) /* simulate ^T status message */
+#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */
+#define TIOCCONS _IOW('t', 98, int) /* become virtual console */
+#define TIOCSCTTY _IO('t', 97) /* become controlling tty */
+#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */
+#define TIOCSIG _IO('t', 95) /* pty: generate signal */
+#define TIOCDRAIN _IO('t', 94) /* wait till output drained */
+#define TIOCMSDTRWAIT _IOW('t', 91, int) /* modem: set wait on close */
+#define TIOCMGDTRWAIT _IOR('t', 90, int) /* modem: get wait on close */
+#define TIOCTIMESTAMP _IOR('t', 89, struct timeval) /* enable/get timestamp
+ * of last input event */
+#define TIOCDCDTIMESTAMP _IOR('t', 88, struct timeval) /* enable/get timestamp
+ * of last DCd rise */
+#define TIOCSDRAINWAIT _IOW('t', 87, int) /* set ttywait timeout */
+#define TIOCGDRAINWAIT _IOR('t', 86, int) /* get ttywait timeout */
+#define TIOCDSIMICROCODE _IO('t', 85) /* download microcode to
+ * DSI Softmodem */
+
+#define TTYDISC 0 /* termios tty line discipline */
+#define TABLDISC 3 /* tablet discipline */
+#define SLIPDISC 4 /* serial IP discipline */
+#define PPPDISC 5 /* PPP discipline */
+
+#endif /* !_SYS_TTYCOM_H_ */
diff --git a/cpukit/libcsupport/include/sys/utsname.h b/cpukit/libcsupport/include/sys/utsname.h
new file mode 100644
index 0000000000..b1b2e6ef41
--- /dev/null
+++ b/cpukit/libcsupport/include/sys/utsname.h
@@ -0,0 +1,52 @@
+/* sys/utsname.h
+ *
+ * $Id$
+ */
+
+#ifndef __POSIX_SYS_UTSNAME_h
+#define __POSIX_SYS_UTSNAME_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * 4.4.1 Get System Name (Table 4-1), P1003.1b-1993, p. 90
+ *
+ * NOTE: The lengths of the strings in this structure are
+ * just long enough to reliably contain the RTEMS information.
+ * For example, the fields are not long enough to support
+ * Internet hostnames.
+ */
+
+#ifdef _KERNEL
+#define SYS_NMLN 32 /* uname(2) for the FreeBSD 1.1 ABI. */
+#endif
+
+#ifndef SYS_NMLN
+#define SYS_NMLN 32 /* User can override. */
+#endif
+
+struct utsname {
+ char sysname[SYS_NMLN]; /* Name of this implementation of the operating system */
+ char nodename[SYS_NMLN]; /* Name of this node within an implementation */
+ /* specified communication network */
+ char release[SYS_NMLN]; /* Current release level of this implementation */
+ char version[SYS_NMLN]; /* Current version level of this release */
+ char machine[SYS_NMLN]; /* Name of the hardware type on which the system */
+ /* is running */
+};
+
+/*
+ * 4.4.1 Get System Name, P1003.1b-1993, p. 90
+ */
+
+int uname(
+ struct utsname *name
+);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+/* end of include file */
diff --git a/cpukit/libcsupport/include/timerdrv.h b/cpukit/libcsupport/include/timerdrv.h
new file mode 100644
index 0000000000..872c6db217
--- /dev/null
+++ b/cpukit/libcsupport/include/timerdrv.h
@@ -0,0 +1,34 @@
+/**
+ * @file rtems/timerdrv.h
+ *
+ * This file describes the Timer Driver for all boards.
+ */
+
+/*
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_TIMERDRV_H
+#define _RTEMS_TIMERDRV_H
+
+#include <rtems/btimer.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Intentionally empty */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/vmeintr.h b/cpukit/libcsupport/include/vmeintr.h
new file mode 100644
index 0000000000..990592c83a
--- /dev/null
+++ b/cpukit/libcsupport/include/vmeintr.h
@@ -0,0 +1,59 @@
+/**
+ * @file rtems/vmeintr.h
+ *
+ * This file is the specification for the VMEbus interface library
+ * which should be provided by all BSPs for VMEbus Single Board
+ * Computers but currently only a few do so.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_VMEINTR_H
+#define _RTEMS_VMEINTR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This defines the mask which is used to determine which
+ * interrupt levels are affected by a call to this package.
+ * The LSB corresponds to VME interrupt 0 and the MSB
+ * to VME interrupt 7.
+ *
+ */
+
+typedef uint8_t VME_interrupt_Mask;
+
+/*
+ * VME_interrupt_Disable
+ *
+ */
+
+void VME_interrupt_Disable (
+ VME_interrupt_Mask mask /* IN */
+);
+
+/*
+ * VME_interrupt_Disable
+ *
+ */
+
+void VME_interrupt_Enable (
+ VME_interrupt_Mask mask /* IN */
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* end of include file */
diff --git a/cpukit/libcsupport/include/zilog/z8036.h b/cpukit/libcsupport/include/zilog/z8036.h
new file mode 100644
index 0000000000..707b6dd567
--- /dev/null
+++ b/cpukit/libcsupport/include/zilog/z8036.h
@@ -0,0 +1,106 @@
+/**
+ * @file rtems/zilog/z8036.h
+ */
+
+/*
+ * This include file defines information related to a Zilog Z8036
+ * Counter/Timer/IO Chip. It is a memory mapped part.
+ *
+ * NOTE: This file shares as much as possible with the include
+ * file for the Z8536 via z8x36.h.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ZILOG_Z8036_H
+#define _RTEMS_ZILOG_Z8036_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* macros */
+
+#define Z8036( ptr ) ((volatile struct z8036_map *)(ptr))
+
+#define Z8x36_STATE0 ( z8036 ) \
+ { /*char *garbage = *(Z8036(z8036))->???; */ }
+
+
+#define Z8x36_WRITE( z8036, reg, data ) \
+ (Z8036(z8036))->reg = (data)
+
+
+#define Z8x36_READ( z8036, reg, data ) \
+ (Z8036(z8036))->reg = (data)
+
+/* structures */
+
+struct z8036_map {
+/* MAIN CONTROL REGISTERS (0x00-0x07) */
+ uint8_t MASTER_INTR; /* Master Interrupt Ctl Reg */
+ uint8_t MASTER_CFG; /* Master Configuration Ctl Reg */
+ uint8_t PORTA_VECTOR; /* Port A - Interrupt Vector */
+ uint8_t PORTB_VECTOR; /* Port B - Interrupt Vector */
+ uint8_t CNT_TMR_VECTOR; /* Counter/Timer Interrupt Vector */
+ uint8_t PORTC_DATA_POLARITY; /* Port C - Data Path Polarity */
+ uint8_t PORTC_DIRECTION; /* Port C - Data Direction */
+ uint8_t PORTC_SPECIAL_IO_CTL; /* Port C - Special IO Control */
+/* MOST OFTEN ACCESSED REGISTERS (0x08 - 0x0f) */
+ uint8_t PORTA_CMD_STATUS; /* Port A - Command Status Reg */
+ uint8_t PORTB_CMD_STATUS; /* Port B - Command Status Reg */
+ uint8_t CT1_CMD_STATUS; /* Ctr/Timer 1 - Command Status Reg */
+ uint8_t CT2_CMD_STATUS; /* Ctr/Timer 2 - Command Status Reg */
+ uint8_t CT3_CMD_STATUS; /* Ctr/Timer 3 - Command Status Reg */
+ uint8_t PORTA_DATA; /* Port A - Data */
+ uint8_t PORTB_DATA; /* Port B - Data */
+ uint8_t PORTC_DATA; /* Port C - Data */
+/* COUNTER/TIMER RELATED REGISTERS (0x10-0x1f) */
+ uint8_t CT1_CUR_CNT_MSB; /* Ctr/Timer 1 - Current Count (MSB) */
+ uint8_t CT1_CUR_CNT_LSB; /* Ctr/Timer 1 - Current Count (LSB) */
+ uint8_t CT2_CUR_CNT_MSB; /* Ctr/Timer 2 - Current Count (MSB) */
+ uint8_t CT2_CUR_CNT_LSB; /* Ctr/Timer 2 - Current Count (LSB) */
+ uint8_t CT3_CUR_CNT_MSB; /* Ctr/Timer 3 - Current Count (MSB) */
+ uint8_t CT3_CUR_CNT_LSB; /* Ctr/Timer 3 - Current Count (LSB) */
+ uint8_t CT1_TIME_CONST_MSB; /* Ctr/Timer 1 - Time Constant (MSB) */
+ uint8_t CT1_TIME_CONST_LSB; /* Ctr/Timer 1 - Time Constant (LSB) */
+ uint8_t CT2_TIME_CONST_MSB; /* Ctr/Timer 2 - Time Constant (MSB) */
+ uint8_t CT2_TIME_CONST_LSB; /* Ctr/Timer 2 - Time Constant (LSB) */
+ uint8_t CT3_TIME_CONST_MSB; /* Ctr/Timer 3 - Time Constant (MSB) */
+ uint8_t CT3_TIME_CONST_LSB; /* Ctr/Timer 3 - Time Constant (LSB) */
+ uint8_t CT1_MODE_SPEC; /* Ctr/Timer 1 - Mode Specification */
+ uint8_t CT2_MODE_SPEC; /* Ctr/Timer 2 - Mode Specification */
+ uint8_t CT3_MODE_SPEC; /* Ctr/Timer 3 - Mode Specification */
+ uint8_t CURRENT_VECTOR; /* Current Vector */
+/* PORT A SPECIFICATION REGISTERS (0x20 -0x27) */
+ uint8_t PORTA_MODE; /* Port A - Mode Specification */
+ uint8_t PORTA_HANDSHAKE; /* Port A - Handshake Specification */
+ uint8_t PORTA_DATA_POLARITY; /* Port A - Data Path Polarity */
+ uint8_t PORTA_DIRECTION; /* Port A - Data Direction */
+ uint8_t PORTA_SPECIAL_IO_CTL; /* Port A - Special IO Control */
+ uint8_t PORTA_PATT_POLARITY; /* Port A - Pattern Polarity */
+ uint8_t PORTA_PATT_TRANS; /* Port A - Pattern Transition */
+ uint8_t PORTA_PATT_MASK; /* Port A - Pattern Mask */
+/* PORT B SPECIFICATION REGISTERS (0x28-0x2f) */
+ uint8_t PORTB_MODE; /* Port B - Mode Specification */
+ uint8_t PORTB_HANDSHAKE; /* Port B - Handshake Specification */
+ uint8_t PORTB_DATA_POLARITY; /* Port B - Data Path Polarity */
+ uint8_t PORTB_DIRECTION; /* Port B - Data Direction */
+ uint8_t PORTB_SPECIAL_IO_CTL; /* Port B - Special IO Control */
+ uint8_t PORTB_PATT_POLARITY; /* Port B - Pattern Polarity */
+ uint8_t PORTB_PATT_TRANS; /* Port B - Pattern Transition */
+ uint8_t PORTB_PATT_MASK; /* Port B - Pattern Mask */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/zilog/z8530.h b/cpukit/libcsupport/include/zilog/z8530.h
new file mode 100644
index 0000000000..13c63536c4
--- /dev/null
+++ b/cpukit/libcsupport/include/zilog/z8530.h
@@ -0,0 +1,97 @@
+/**
+ * @file rtems/zilog/z8530.h
+ */
+
+/*
+ * This include file defines information related to a Zilog Z8530
+ * SCC Chip. It is a IO mapped part.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ZILOG_Z8530_H
+#define _RTEMS_ZILOG_Z8530_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* macros */
+
+#define VOL8( ptr ) ((volatile uint8_t *)(ptr))
+
+#define Z8x30_STATE0 ( z8530 ) \
+ { char *garbage; \
+ (garbage) = *(VOL8(z8530)) \
+ }
+
+#define Z8x30_WRITE_CONTROL( z8530, reg, data ) \
+ *(VOL8(z8530)) = (reg); \
+ *(VOL8(z8530)) = (data)
+
+#define Z8x30_READ_CONTROL( z8530, reg, data ) \
+ *(VOL8(z8530)) = (reg); \
+ (data) = *(VOL8(z8530))
+
+#define Z8x30_WRITE_DATA( z8530, data ) \
+ *(VOL8(z8530)) = (data);
+
+#define Z8x30_READ_DATA( z8530, data ) \
+ (data) = *(VOL8(z8530));
+
+
+/* RR_0 Bit Definitions */
+
+#define RR_0_TX_BUFFER_EMPTY 0x04
+#define RR_0_RX_DATA_AVAILABLE 0x01
+
+/* read registers */
+
+#define RR_0 0x00
+#define RR_1 0x01
+#define RR_2 0x02
+#define RR_3 0x03
+#define RR_4 0x04
+#define RR_5 0x05
+#define RR_6 0x06
+#define RR_7 0x07
+#define RR_8 0x08
+#define RR_9 0x09
+#define RR_10 0x0A
+#define RR_11 0x0B
+#define RR_12 0x0C
+#define RR_13 0x0D
+#define RR_14 0x0E
+#define RR_15 0x0F
+
+/* write registers */
+
+#define WR_0 0x00
+#define WR_1 0x01
+#define WR_2 0x02
+#define WR_3 0x03
+#define WR_4 0x04
+#define WR_5 0x05
+#define WR_6 0x06
+#define WR_7 0x07
+#define WR_8 0x08
+#define WR_9 0x09
+#define WR_10 0x0A
+#define WR_11 0x0B
+#define WR_12 0x0C
+#define WR_13 0x0D
+#define WR_14 0x0E
+#define WR_15 0x0F
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/include/zilog/z8536.h b/cpukit/libcsupport/include/zilog/z8536.h
new file mode 100644
index 0000000000..b67bd4cf9c
--- /dev/null
+++ b/cpukit/libcsupport/include/zilog/z8536.h
@@ -0,0 +1,114 @@
+/**
+ * @file rtems/zilog/z8536.h
+ */
+
+/*
+ * This include file defines information related to a Zilog Z8536
+ * Counter/Timer/IO Chip. It is a IO mapped part.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ *
+ * NOTE: This file shares as much as possible with the include
+ * file for the Z8036 via z8x36.h.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ZILOG_Z8536_H
+#define _RTEMS_ZILOG_Z8536_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* macros */
+
+#define VOL8( ptr ) ((volatile uint8_t *)(ptr))
+
+#define Z8x36_STATE0 ( z8536 ) \
+ { char *garbage; \
+ (garbage) = *(VOL8(z8536+0xC)) \
+ }
+
+#define Z8x36_WRITE( z8536, reg, data ) \
+ *(VOL8(z8536+0xC)) = (reg); \
+ *(VOL8(z8536+0xC)) = (data)
+
+#define Z8x36_READ( z8536, reg, data ) \
+ *(VOL8(z8536+0xC)) = (reg); \
+ (data) = *(VOL8(z8536+0xC))
+
+/* structures */
+
+/* MAIN CONTROL REGISTERS (0x00-0x07) */
+#define MASTER_INTR 0x00 /* Master Interrupt Ctl Reg */
+#define MASTER_CFG 0x01 /* Master Configuration Ctl Reg */
+#define PORTA_VECTOR 0x02 /* Port A - Interrupt Vector */
+#define PORTB_VECTOR 0x03 /* Port B - Interrupt Vector */
+#define CNT_TMR_VECTOR 0x04 /* Counter/Timer Interrupt Vector */
+#define PORTC_DATA_POLARITY 0x05 /* Port C - Data Path Polarity */
+#define PORTC_DIRECTION 0x06 /* Port C - Data Direction */
+#define PORTC_SPECIAL_IO_CTL 0x07 /* Port C - Special IO Control */
+
+/* MOST OFTEN ACCESSED REGISTERS (0x08 - 0x0f) */
+#define PORTA_CMD_STATUS 0x08 /* Port A - Command Status Reg */
+#define PORTB_CMD_STATUS 0x09 /* Port B - Command Status Reg */
+#define CT1_CMD_STATUS 0x0a /* Ctr/Timer 1 - Command Status Reg */
+#define CT2_CMD_STATUS 0x0b /* Ctr/Timer 2 - Command Status Reg */
+#define CT3_CMD_STATUS 0x0c /* Ctr/Timer 3 - Command Status Reg */
+#define PORTA_DATA 0x0d /* Port A - Data */
+#define PORTB_DATA 0x0e /* Port B - Data */
+#define PORTC_DATA 0x0f /* Port C - Data */
+
+/* COUNTER/TIMER RELATED REGISTERS (0x10-0x1f) */
+#define CT1_CUR_CNT_MSB 0x10 /* Ctr/Timer 1 - Current Count (MSB) */
+#define CT1_CUR_CNT_LSB 0x11 /* Ctr/Timer 1 - Current Count (LSB) */
+#define CT2_CUR_CNT_MSB 0x12 /* Ctr/Timer 2 - Current Count (MSB) */
+#define CT2_CUR_CNT_LSB 0x13 /* Ctr/Timer 2 - Current Count (LSB) */
+#define CT3_CUR_CNT_MSB 0x14 /* Ctr/Timer 3 - Current Count (MSB) */
+#define CT3_CUR_CNT_LSB 0x15 /* Ctr/Timer 3 - Current Count (LSB) */
+#define CT1_TIME_CONST_MSB 0x16 /* Ctr/Timer 1 - Time Constant (MSB) */
+#define CT1_TIME_CONST_LSB 0x17 /* Ctr/Timer 1 - Time Constant (LSB) */
+#define CT2_TIME_CONST_MSB 0x18 /* Ctr/Timer 2 - Time Constant (MSB) */
+#define CT2_TIME_CONST_LSB 0x19 /* Ctr/Timer 2 - Time Constant (LSB) */
+#define CT3_TIME_CONST_MSB 0x1a /* Ctr/Timer 3 - Time Constant (MSB) */
+#define CT3_TIME_CONST_LSB 0x1b /* Ctr/Timer 3 - Time Constant (LSB) */
+#define CT1_MODE_SPEC 0x1c /* Ctr/Timer 1 - Mode Specification */
+#define CT2_MODE_SPEC 0x1d /* Ctr/Timer 2 - Mode Specification */
+#define CT3_MODE_SPEC 0x1e /* Ctr/Timer 3 - Mode Specification */
+#define CURRENT_VECTOR 0x1f /* Current Vector */
+
+/* PORT A SPECIFICATION REGISTERS (0x20 -0x27) */
+#define PORTA_MODE 0x20 /* Port A - Mode Specification */
+#define PORTA_HANDSHAKE 0x21 /* Port A - Handshake Specification */
+#define PORTA_DATA_POLARITY 0x22 /* Port A - Data Path Polarity */
+#define PORTA_DIRECTION 0x23 /* Port A - Data Direction */
+#define PORTA_SPECIAL_IO_CTL 0x24 /* Port A - Special IO Control */
+#define PORTA_PATT_POLARITY 0x25 /* Port A - Pattern Polarity */
+#define PORTA_PATT_TRANS 0x26 /* Port A - Pattern Transition */
+#define PORTA_PATT_MASK 0x27 /* Port A - Pattern Mask */
+
+/* PORT B SPECIFICATION REGISTERS (0x28-0x2f) */
+#define PORTB_MODE 0x28 /* Port B - Mode Specification */
+#define PORTB_HANDSHAKE 0x29 /* Port B - Handshake Specification */
+#define PORTB_DATA_POLARITY 0x2a /* Port B - Data Path Polarity */
+#define PORTB_DIRECTION 0x2b /* Port B - Data Direction */
+#define PORTB_SPECIAL_IO_CTL 0x2c /* Port B - Special IO Control */
+#define PORTB_PATT_POLARITY 0x2d /* Port B - Pattern Polarity */
+#define PORTB_PATT_TRANS 0x2e /* Port B - Pattern Transition */
+#define PORTB_PATT_MASK 0x2f /* Port B - Pattern Mask */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libcsupport/preinstall.am b/cpukit/libcsupport/preinstall.am
new file mode 100644
index 0000000000..f71362fe31
--- /dev/null
+++ b/cpukit/libcsupport/preinstall.am
@@ -0,0 +1,118 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/console.h: include/console.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/console.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/console.h
+
+$(PROJECT_INCLUDE)/rtems/clockdrv.h: include/clockdrv.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/clockdrv.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/clockdrv.h
+
+$(PROJECT_INCLUDE)/rtems/framebuffer.h: include/rtems/framebuffer.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/framebuffer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/framebuffer.h
+
+$(PROJECT_INCLUDE)/rtems/iosupp.h: include/iosupp.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/iosupp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/iosupp.h
+
+$(PROJECT_INCLUDE)/rtems/ringbuf.h: include/ringbuf.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ringbuf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ringbuf.h
+
+$(PROJECT_INCLUDE)/rtems/rtc.h: include/rtc.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtc.h
+
+$(PROJECT_INCLUDE)/rtems/spurious.h: include/spurious.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/spurious.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/spurious.h
+
+$(PROJECT_INCLUDE)/rtems/timerdrv.h: include/timerdrv.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/timerdrv.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/timerdrv.h
+
+$(PROJECT_INCLUDE)/rtems/vmeintr.h: include/vmeintr.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/vmeintr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/vmeintr.h
+
+$(PROJECT_INCLUDE)/rtems/motorola/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/motorola
+ @: > $(PROJECT_INCLUDE)/rtems/motorola/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/motorola/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/motorola/mc68230.h: include/motorola/mc68230.h $(PROJECT_INCLUDE)/rtems/motorola/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/motorola/mc68230.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/motorola/mc68230.h
+
+$(PROJECT_INCLUDE)/rtems/motorola/mc68681.h: include/motorola/mc68681.h $(PROJECT_INCLUDE)/rtems/motorola/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/motorola/mc68681.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/motorola/mc68681.h
+
+$(PROJECT_INCLUDE)/rtems/assoc.h: include/rtems/assoc.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/assoc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/assoc.h
+
+$(PROJECT_INCLUDE)/rtems/error.h: include/rtems/error.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/error.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/error.h
+
+$(PROJECT_INCLUDE)/rtems/libcsupport.h: include/rtems/libcsupport.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/libcsupport.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/libcsupport.h
+
+$(PROJECT_INCLUDE)/rtems/libio.h: include/rtems/libio.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/libio.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/libio.h
+
+$(PROJECT_INCLUDE)/rtems/libio_.h: include/rtems/libio_.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/libio_.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/libio_.h
+
+$(PROJECT_INCLUDE)/rtems/malloc.h: include/rtems/malloc.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/malloc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/malloc.h
+
+$(PROJECT_INCLUDE)/rtems/termiostypes.h: include/rtems/termiostypes.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/termiostypes.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/termiostypes.h
+
+$(PROJECT_INCLUDE)/rtems/gxx_wrappers.h: include/rtems/gxx_wrappers.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/gxx_wrappers.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/gxx_wrappers.h
+
+$(PROJECT_INCLUDE)/rtems/zilog/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/zilog
+ @: > $(PROJECT_INCLUDE)/rtems/zilog/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/zilog/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/zilog/z8036.h: include/zilog/z8036.h $(PROJECT_INCLUDE)/rtems/zilog/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/zilog/z8036.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/zilog/z8036.h
+
+$(PROJECT_INCLUDE)/rtems/zilog/z8530.h: include/zilog/z8530.h $(PROJECT_INCLUDE)/rtems/zilog/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/zilog/z8530.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/zilog/z8530.h
+
+$(PROJECT_INCLUDE)/rtems/zilog/z8536.h: include/zilog/z8536.h $(PROJECT_INCLUDE)/rtems/zilog/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/zilog/z8536.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/zilog/z8536.h
+
diff --git a/cpukit/libcsupport/src/CASES b/cpukit/libcsupport/src/CASES
new file mode 100644
index 0000000000..4578ae5009
--- /dev/null
+++ b/cpukit/libcsupport/src/CASES
@@ -0,0 +1,23 @@
+#
+# $Id$
+#
+
+This is a list of cases to consider when implementing a file system:
+
+
++ Given a tree of this form:
+
+ a ----- b
+ /
+ c
+
+ Where a and b are directories and c is a link to directory b. Consider
+ this sequence:
+
+ - rmdir a/b
+ - mknod c/b/x
+ - unlink c
+
+
+
+
diff --git a/cpukit/libcsupport/src/README b/cpukit/libcsupport/src/README
new file mode 100644
index 0000000000..ee7a90501e
--- /dev/null
+++ b/cpukit/libcsupport/src/README
@@ -0,0 +1,37 @@
+--
+-- $Id$
+--
+
+Overview of newlib support (newlib is from CYGNUS)
+ Each task can have its own libc state including:
+ open stdio files
+ strtok
+ multi precision arithmetic state
+ etc.
+
+ This is implemented by a reentrancy data structure for each task.
+
+ When a task is "started" (in RTEMS sense) the reentrancy structure
+ is allocated. Its address is stored in notepad[NOTEPAD_LAST].
+
+ When task is switched to, the value of global variable _impure_ptr
+ is changed to the value of the new tasks reentrancy structure.
+
+ When a task is deleted
+ atexit() processing (for that task) happens
+ task's stdio buffers are flushed
+
+ When exit(3) is called
+ calling task's atexit processing done
+ global libc state atexit processing done
+ (this will include any atexit routines installed by drivers)
+ executive is shutdown
+ causes a context switch back to bsp land
+
+
+NOTE:
+ libc extension are installed by bsp_libc_init()
+ iff we are using clock interrupts.
+ This hack is necessary to allow the tmtests to avoid
+ timing the extensions.
+
diff --git a/cpukit/libcsupport/src/TODO b/cpukit/libcsupport/src/TODO
new file mode 100644
index 0000000000..38cb012326
--- /dev/null
+++ b/cpukit/libcsupport/src/TODO
@@ -0,0 +1,14 @@
+#
+# $Id$
+#
+
++ newlib 1.8.0 has the wrong prototype for at least read() and write().
+
++ There should be a "eat it" stub for all system calls which are
+ available to make filling out an operations table easier.
+ See device_lseek() for an example of where this would be nice.
+
++ Fix strerror() so it prints all error numbers.
+
++ Check the node allocation coment in the fchdir call.
++ Add an interface somewhere for this call. \ No newline at end of file
diff --git a/cpukit/libcsupport/src/__assert.c b/cpukit/libcsupport/src/__assert.c
new file mode 100644
index 0000000000..0e90b604c6
--- /dev/null
+++ b/cpukit/libcsupport/src/__assert.c
@@ -0,0 +1,52 @@
+/* __assert - small RTEMS Specific Implementation
+ *
+ * COPYRIGHT (c) 2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bspIo.h>
+#include <rtems.h>
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE___ASSERT_FUNC)
+/*
+ * Newlib 1.16.0 added this method. Together these provide an
+ * RTEMS safe, low memory implementation.
+ */
+void __assert_func(
+ const char *file,
+ int line,
+ const char *func,
+ const char *failedexpr
+)
+{
+ printk("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
+ failedexpr,
+ file,
+ line,
+ (func) ? ", function: " : "",
+ (func) ? func : ""
+ );
+ rtems_fatal_error_occurred(0);
+}
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE___ASSERT)
+void __assert(
+ const char *file,
+ int line,
+ const char *failedexpr
+)
+{
+ __assert_func (file, line, NULL, failedexpr);
+}
+#endif
diff --git a/cpukit/libcsupport/src/__getpid.c b/cpukit/libcsupport/src/__getpid.c
new file mode 100644
index 0000000000..85a4c0b013
--- /dev/null
+++ b/cpukit/libcsupport/src/__getpid.c
@@ -0,0 +1,17 @@
+/*
+ * Some C Libraries reference this routine since they think getpid is
+ * a real system call.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+pid_t __getpid(void)
+{
+ return getpid();
+}
diff --git a/cpukit/libcsupport/src/__gettod.c b/cpukit/libcsupport/src/__gettod.c
new file mode 100644
index 0000000000..05db4ab9d0
--- /dev/null
+++ b/cpukit/libcsupport/src/__gettod.c
@@ -0,0 +1,86 @@
+/*
+ * gettimeofday() - SVR4 and BSD4.3 extension required by Newlib
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+
+#if defined(RTEMS_NEWLIB)
+#include <sys/time.h>
+#include <errno.h>
+#include <rtems.h>
+#include <rtems/seterr.h>
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_GETTIMEOFDAY)
+/*
+ * NOTE: The solaris gettimeofday does not have a second parameter.
+ */
+int gettimeofday(
+ struct timeval *tp,
+ void * __tz __attribute__((unused))
+)
+{
+ /* struct timezone* tzp = (struct timezone*) __tz; */
+ if ( !tp )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ /*
+ * POSIX does not seem to allow for not having a TOD so we just
+ * grab the time of day.
+ */
+ _TOD_Get_timeval( tp );
+
+ /*
+ * Timezone information ignored by the OS proper. Per email
+ * with Eric Norum, this is how GNU/Linux, Solaris, and MacOS X
+ * do it. This puts us in good company.
+ */
+
+ return 0;
+}
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETTIMEOFDAY_R)
+
+#include <sys/reent.h>
+
+/*
+ * "Reentrant" version
+ */
+int _gettimeofday_r(
+ struct _reent *ignored_reentrancy_stuff __attribute__((unused)),
+ struct timeval *tp,
+ struct timezone *tzp
+)
+{
+ return gettimeofday( tp, tzp );
+}
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETTIMEOFDAY)
+/*
+ * "System call" version
+ */
+
+int _gettimeofday(
+ struct timeval *tp,
+ struct timezone *tzp
+)
+{
+ return gettimeofday( tp, tzp );
+}
+#endif
+
+#endif /* defined(RTEMS_NEWLIB) */
diff --git a/cpukit/libcsupport/src/__times.c b/cpukit/libcsupport/src/__times.c
new file mode 100644
index 0000000000..2de529275e
--- /dev/null
+++ b/cpukit/libcsupport/src/__times.c
@@ -0,0 +1,114 @@
+/*
+ * times() - POSIX 1003.1b 4.5.2 - Get Process Times
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <sys/times.h>
+#include <time.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timestamp.h>
+#endif
+
+clock_t _times(
+ struct tms *ptms
+)
+{
+ rtems_interval ticks;
+
+ if ( !ptms )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ /*
+ * This call does not depend on TOD being initialized and can't fail.
+ */
+
+ ticks = rtems_clock_get_ticks_since_boot();
+
+ /*
+ * RTEMS technically has no notion of system versus user time
+ * since there is no separation of OS from application tasks.
+ * But we can at least make a distinction between the number
+ * of ticks since boot and the number of ticks executed by this
+ * this thread.
+ */
+
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ {
+ Timestamp_Control per_tick;
+ uint32_t ticks;
+ uint32_t fractional_ticks;
+
+ _Timestamp_Set(
+ &per_tick,
+ rtems_configuration_get_microseconds_per_tick() /
+ TOD_MICROSECONDS_PER_SECOND,
+ (rtems_configuration_get_nanoseconds_per_tick() %
+ TOD_NANOSECONDS_PER_SECOND)
+ );
+
+ _Timestamp_Divide(
+ &_Thread_Executing->cpu_time_used,
+ &per_tick,
+ &ticks,
+ &fractional_ticks
+ );
+ ptms->tms_utime = ticks;
+ }
+ #else
+ ptms->tms_utime = _Thread_Executing->cpu_time_used;
+ #endif
+ ptms->tms_stime = ticks;
+ ptms->tms_cutime = 0;
+ ptms->tms_cstime = 0;
+
+ return ticks;
+}
+
+/*
+ * times()
+ *
+ * times() system call wrapper for _times() above.
+ */
+
+clock_t times(
+ struct tms *ptms
+)
+{
+ return _times( ptms );
+}
+
+/*
+ * _times_r
+ *
+ * This is the Newlib dependent reentrant version of times().
+ */
+
+#if defined(RTEMS_NEWLIB)
+
+#include <reent.h>
+
+clock_t _times_r(
+ struct _reent *ptr __attribute__((unused)),
+ struct tms *ptms
+)
+{
+ return _times( ptms );
+}
+#endif
diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c
new file mode 100644
index 0000000000..0b3469fa1a
--- /dev/null
+++ b/cpukit/libcsupport/src/__usrenv.c
@@ -0,0 +1,27 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+
+/*
+ * Global information for POSIX Process Environment Support
+ */
+
+rtems_user_env_t rtems_global_user_env;
+rtems_user_env_t * rtems_current_user_env = &rtems_global_user_env;
+
+
diff --git a/cpukit/libcsupport/src/_calloc_r.c b/cpukit/libcsupport/src/_calloc_r.c
new file mode 100644
index 0000000000..1b515d2464
--- /dev/null
+++ b/cpukit/libcsupport/src/_calloc_r.c
@@ -0,0 +1,30 @@
+/*
+ * _calloc_r Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__CALLOC_R)
+#include <sys/reent.h>
+#include <stdlib.h>
+
+void *_calloc_r(
+ struct _reent *ignored __attribute__((unused)),
+ size_t elements,
+ size_t size
+)
+{
+ return calloc( elements, size );
+}
+#endif
diff --git a/cpukit/libcsupport/src/_free_r.c b/cpukit/libcsupport/src/_free_r.c
new file mode 100644
index 0000000000..9b3eb5c285
--- /dev/null
+++ b/cpukit/libcsupport/src/_free_r.c
@@ -0,0 +1,29 @@
+/*
+ * _free_r Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__FREE_R)
+#include <sys/reent.h>
+#include <stdlib.h>
+
+void _free_r(
+ struct _reent *ignored __attribute__((unused)),
+ void *ptr
+)
+{
+ free( ptr );
+}
+#endif
diff --git a/cpukit/libcsupport/src/_malloc_r.c b/cpukit/libcsupport/src/_malloc_r.c
new file mode 100644
index 0000000000..9a30097324
--- /dev/null
+++ b/cpukit/libcsupport/src/_malloc_r.c
@@ -0,0 +1,29 @@
+/*
+ * _malloc_r Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__MALLOC_R)
+#include <sys/reent.h>
+#include <stdlib.h>
+
+void *_malloc_r(
+ struct _reent *ignored __attribute__((unused)),
+ size_t size
+)
+{
+ return malloc( size );
+}
+#endif
diff --git a/cpukit/libcsupport/src/_realloc_r.c b/cpukit/libcsupport/src/_realloc_r.c
new file mode 100644
index 0000000000..78c9faf351
--- /dev/null
+++ b/cpukit/libcsupport/src/_realloc_r.c
@@ -0,0 +1,30 @@
+/*
+ * _realloc_r Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__REALLOC_R)
+#include <sys/reent.h>
+#include <stdlib.h>
+
+void *_realloc_r(
+ struct _reent *ignored __attribute__((unused)),
+ void *ptr,
+ size_t size
+)
+{
+ return realloc( ptr, size );
+}
+#endif
diff --git a/cpukit/libcsupport/src/_rename_r.c b/cpukit/libcsupport/src/_rename_r.c
new file mode 100644
index 0000000000..51010df28e
--- /dev/null
+++ b/cpukit/libcsupport/src/_rename_r.c
@@ -0,0 +1,113 @@
+/*
+ * _rename_r() - POSIX 1003.1b - 5.3.4 - Rename a file
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__RENAME_R)
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int _rename_r(
+ struct _reent *ptr __attribute__((unused)),
+ const char *old,
+ const char *new
+)
+{
+ int old_parent_pathlen;
+ rtems_filesystem_location_info_t old_loc;
+ rtems_filesystem_location_info_t old_parent_loc;
+ rtems_filesystem_location_info_t new_parent_loc;
+ int i;
+ int result;
+ const char *name;
+ bool free_old_parentloc = false;
+
+ /*
+ * Get the parent node of the old path to be renamed. Find the parent path.
+ */
+
+ old_parent_pathlen = rtems_filesystem_dirname ( old );
+
+ if ( old_parent_pathlen == 0 )
+ rtems_filesystem_get_start_loc( old, &i, &old_parent_loc );
+ else {
+ result = rtems_filesystem_evaluate_path( old, old_parent_pathlen,
+ RTEMS_LIBIO_PERMS_WRITE,
+ &old_parent_loc,
+ false );
+ if ( result != 0 )
+ return -1;
+
+ free_old_parentloc = true;
+ }
+
+ /*
+ * Start from the parent to find the node that should be under it.
+ */
+
+ old_loc = old_parent_loc;
+ name = old + old_parent_pathlen;
+ name += rtems_filesystem_prefix_separators( name, strlen( name ) );
+
+ result = rtems_filesystem_evaluate_relative_path( name , strlen( name ),
+ 0, &old_loc, false );
+ if ( result != 0 ) {
+ if ( free_old_parentloc )
+ rtems_filesystem_freenode( &old_parent_loc );
+ return -1;
+ }
+
+ /*
+ * Get the parent of the new node we are renaming to.
+ */
+
+ rtems_filesystem_get_start_loc( new, &i, &new_parent_loc );
+
+ result = (*new_parent_loc.ops->evalformake_h)( &new[i], &new_parent_loc, &name );
+ if ( result != 0 ) {
+ rtems_filesystem_freenode( &new_parent_loc );
+ if ( free_old_parentloc )
+ rtems_filesystem_freenode( &old_parent_loc );
+ rtems_filesystem_freenode( &old_loc );
+ return -1;
+ }
+
+ /*
+ * Check to see if the caller is trying to rename across file system
+ * boundaries.
+ */
+
+ if ( old_parent_loc.mt_entry != new_parent_loc.mt_entry ) {
+ rtems_filesystem_freenode( &new_parent_loc );
+ if ( free_old_parentloc )
+ rtems_filesystem_freenode( &old_parent_loc );
+ rtems_filesystem_freenode( &old_loc );
+ rtems_set_errno_and_return_minus_one( EXDEV );
+ }
+
+ result = (*new_parent_loc.ops->rename_h)( &old_parent_loc, &old_loc, &new_parent_loc, name );
+
+ rtems_filesystem_freenode( &new_parent_loc );
+ if ( free_old_parentloc )
+ rtems_filesystem_freenode( &old_parent_loc );
+ rtems_filesystem_freenode( &old_loc );
+
+ return result;
+}
+#endif
diff --git a/cpukit/libcsupport/src/access.c b/cpukit/libcsupport/src/access.c
new file mode 100644
index 0000000000..7365d6db7d
--- /dev/null
+++ b/cpukit/libcsupport/src/access.c
@@ -0,0 +1,48 @@
+/*
+ * access() - POSIX 1003.1b 5.6.3 - File Accessibility
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+int access(
+ const char *path,
+ int amode
+)
+{
+ struct stat statbuf;
+
+ if ( stat(path, &statbuf) )
+ return -1;
+
+ if ( amode & R_OK ) {
+ if (!( statbuf.st_mode & S_IREAD ))
+ return -1;
+ }
+
+ if ( amode & W_OK ) {
+ if ( !( statbuf.st_mode & S_IWRITE ) )
+ return -1;
+ }
+
+ if ( amode & X_OK ) {
+ if ( !( statbuf.st_mode & S_IEXEC ) )
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/assoclocalbyname.c b/cpukit/libcsupport/src/assoclocalbyname.c
new file mode 100644
index 0000000000..28856afc46
--- /dev/null
+++ b/cpukit/libcsupport/src/assoclocalbyname.c
@@ -0,0 +1,31 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+uint32_t rtems_assoc_local_by_name(
+ const rtems_assoc_t *ap,
+ const char *name
+)
+{
+ const rtems_assoc_t *nap;
+
+ nap = rtems_assoc_ptr_by_name(ap, name);
+ if (nap)
+ return nap->local_value;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/assoclocalbyremote.c b/cpukit/libcsupport/src/assoclocalbyremote.c
new file mode 100644
index 0000000000..545f31b6a8
--- /dev/null
+++ b/cpukit/libcsupport/src/assoclocalbyremote.c
@@ -0,0 +1,31 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+uint32_t rtems_assoc_local_by_remote(
+ const rtems_assoc_t *ap,
+ uint32_t remote_value
+)
+{
+ const rtems_assoc_t *nap;
+
+ nap = rtems_assoc_ptr_by_remote(ap, remote_value);
+ if (nap)
+ return nap->local_value;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/assoclocalbyremotebitfield.c b/cpukit/libcsupport/src/assoclocalbyremotebitfield.c
new file mode 100644
index 0000000000..177ca62b49
--- /dev/null
+++ b/cpukit/libcsupport/src/assoclocalbyremotebitfield.c
@@ -0,0 +1,34 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+
+uint32_t rtems_assoc_local_by_remote_bitfield(
+ const rtems_assoc_t *ap,
+ uint32_t remote_value
+)
+{
+ uint32_t b;
+ uint32_t local_value = 0;
+
+ for (b = 1; b; b <<= 1) {
+ if (b & remote_value)
+ local_value |= rtems_assoc_local_by_remote(ap, b);
+ }
+
+ return local_value;
+}
diff --git a/cpukit/libcsupport/src/assocnamebad.c b/cpukit/libcsupport/src/assocnamebad.c
new file mode 100644
index 0000000000..f61f4e844d
--- /dev/null
+++ b/cpukit/libcsupport/src/assocnamebad.c
@@ -0,0 +1,40 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <inttypes.h>
+#include <stdio.h> /* sprintf */
+
+/*
+ * what to return if a value is not found
+ * this is not reentrant, but it really shouldn't be invoked anyway
+ */
+
+const char *
+rtems_assoc_name_bad(
+#ifdef RTEMS_DEBUG
+ uint32_t bad_value
+#else
+ uint32_t bad_value __attribute((unused))
+#endif
+)
+{
+#ifdef RTEMS_DEBUG
+ static char bad_buffer[32];
+
+ sprintf(bad_buffer, "< %" PRId32 "[0x%" PRIx32 " ] >", bad_value, bad_value);
+#else
+ static char bad_buffer[40] = "<assocnamebad.c: : BAD NAME>";
+#endif
+ return bad_buffer;
+}
diff --git a/cpukit/libcsupport/src/assocnamebylocal.c b/cpukit/libcsupport/src/assocnamebylocal.c
new file mode 100644
index 0000000000..3ba0b8c083
--- /dev/null
+++ b/cpukit/libcsupport/src/assocnamebylocal.c
@@ -0,0 +1,31 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+const char *rtems_assoc_name_by_local(
+ const rtems_assoc_t *ap,
+ uint32_t local_value
+)
+{
+ const rtems_assoc_t *nap;
+
+ nap = rtems_assoc_ptr_by_local(ap, local_value);
+ if (nap)
+ return nap->name;
+
+ return rtems_assoc_name_bad(local_value);
+}
diff --git a/cpukit/libcsupport/src/assocnamebylocalbitfield.c b/cpukit/libcsupport/src/assocnamebylocalbitfield.c
new file mode 100644
index 0000000000..c9d1fa1256
--- /dev/null
+++ b/cpukit/libcsupport/src/assocnamebylocalbitfield.c
@@ -0,0 +1,38 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+char *rtems_assoc_name_by_local_bitfield(
+ const rtems_assoc_t *ap,
+ uint32_t value,
+ char *buffer
+)
+{
+ uint32_t b;
+
+ *buffer = 0;
+
+ for (b = 1; b; b <<= 1) {
+ if (b & value) {
+ if (*buffer)
+ strcat(buffer, " ");
+ strcat(buffer, rtems_assoc_name_by_local(ap, b));
+ }
+ }
+
+ return buffer;
+}
diff --git a/cpukit/libcsupport/src/assocnamebyremote.c b/cpukit/libcsupport/src/assocnamebyremote.c
new file mode 100644
index 0000000000..281022c7bf
--- /dev/null
+++ b/cpukit/libcsupport/src/assocnamebyremote.c
@@ -0,0 +1,33 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+
+const char *rtems_assoc_name_by_remote(
+ const rtems_assoc_t *ap,
+ uint32_t remote_value
+)
+{
+ const rtems_assoc_t *nap;
+ nap = rtems_assoc_ptr_by_remote(ap, remote_value);
+
+ if (nap)
+ return nap->name;
+
+ return rtems_assoc_name_bad(remote_value);
+}
+
diff --git a/cpukit/libcsupport/src/assocnamebyremotebitfield.c b/cpukit/libcsupport/src/assocnamebyremotebitfield.c
new file mode 100644
index 0000000000..1293393e1e
--- /dev/null
+++ b/cpukit/libcsupport/src/assocnamebyremotebitfield.c
@@ -0,0 +1,39 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+
+char *rtems_assoc_name_by_remote_bitfield(
+ const rtems_assoc_t *ap,
+ uint32_t value,
+ char *buffer
+)
+{
+ uint32_t b;
+
+ *buffer = 0;
+
+ for (b = 1; b; b <<= 1) {
+ if (b & value) {
+ if (*buffer)
+ strcat(buffer, " ");
+ strcat(buffer, rtems_assoc_name_by_remote(ap, b));
+ }
+ }
+
+ return buffer;
+}
diff --git a/cpukit/libcsupport/src/assocptrbylocal.c b/cpukit/libcsupport/src/assocptrbylocal.c
new file mode 100644
index 0000000000..cbf26b1bcb
--- /dev/null
+++ b/cpukit/libcsupport/src/assocptrbylocal.c
@@ -0,0 +1,34 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+const rtems_assoc_t *rtems_assoc_ptr_by_local(
+ const rtems_assoc_t *ap,
+ uint32_t local_value
+)
+{
+ const rtems_assoc_t *default_ap = 0;
+
+ if (rtems_assoc_is_default(ap))
+ default_ap = ap++;
+
+ for ( ; ap->name; ap++)
+ if (ap->local_value == local_value)
+ return ap;
+
+ return default_ap;
+}
diff --git a/cpukit/libcsupport/src/assocptrbyname.c b/cpukit/libcsupport/src/assocptrbyname.c
new file mode 100644
index 0000000000..457f57e434
--- /dev/null
+++ b/cpukit/libcsupport/src/assocptrbyname.c
@@ -0,0 +1,35 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+
+const rtems_assoc_t *rtems_assoc_ptr_by_name(
+ const rtems_assoc_t *ap,
+ const char *name
+)
+{
+ const rtems_assoc_t *default_ap = 0;
+
+ if (rtems_assoc_is_default(ap))
+ default_ap = ap++;
+
+ for ( ; ap->name; ap++)
+ if (strcmp(ap->name, name) == 0)
+ return ap;
+
+ return default_ap;
+}
diff --git a/cpukit/libcsupport/src/assocptrbyremote.c b/cpukit/libcsupport/src/assocptrbyremote.c
new file mode 100644
index 0000000000..4879c2d397
--- /dev/null
+++ b/cpukit/libcsupport/src/assocptrbyremote.c
@@ -0,0 +1,34 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+const rtems_assoc_t *rtems_assoc_ptr_by_remote(
+ const rtems_assoc_t *ap,
+ uint32_t remote_value
+)
+{
+ const rtems_assoc_t *default_ap = 0;
+
+ if (rtems_assoc_is_default(ap))
+ default_ap = ap++;
+
+ for ( ; ap->name; ap++)
+ if (ap->remote_value == remote_value)
+ return ap;
+
+ return default_ap;
+}
diff --git a/cpukit/libcsupport/src/assocremotebylocal.c b/cpukit/libcsupport/src/assocremotebylocal.c
new file mode 100644
index 0000000000..23bbcc74fa
--- /dev/null
+++ b/cpukit/libcsupport/src/assocremotebylocal.c
@@ -0,0 +1,31 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+uint32_t rtems_assoc_remote_by_local(
+ const rtems_assoc_t *ap,
+ uint32_t local_value
+)
+{
+ const rtems_assoc_t *nap;
+
+ nap = rtems_assoc_ptr_by_local(ap, local_value);
+ if (nap)
+ return nap->remote_value;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/assocremotebylocalbitfield.c b/cpukit/libcsupport/src/assocremotebylocalbitfield.c
new file mode 100644
index 0000000000..3d28345847
--- /dev/null
+++ b/cpukit/libcsupport/src/assocremotebylocalbitfield.c
@@ -0,0 +1,33 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+
+uint32_t rtems_assoc_remote_by_local_bitfield(
+ const rtems_assoc_t *ap,
+ uint32_t local_value
+)
+{
+ uint32_t b;
+ uint32_t remote_value = 0;
+
+ for (b = 1; b; b <<= 1)
+ if (b & local_value)
+ remote_value |= rtems_assoc_remote_by_local(ap, b);
+
+ return remote_value;
+}
diff --git a/cpukit/libcsupport/src/assocremotebyname.c b/cpukit/libcsupport/src/assocremotebyname.c
new file mode 100644
index 0000000000..923c8d28ba
--- /dev/null
+++ b/cpukit/libcsupport/src/assocremotebyname.c
@@ -0,0 +1,31 @@
+/*
+ * assoc.c
+ * rtems assoc routines
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define INSIDE_ASSOC
+
+#include <rtems.h>
+#include <rtems/assoc.h>
+
+#include <string.h> /* strcat, strcmp */
+
+uint32_t rtems_assoc_remote_by_name(
+ const rtems_assoc_t *ap,
+ const char *name
+)
+{
+ const rtems_assoc_t *nap;
+
+ nap = rtems_assoc_ptr_by_name(ap, name);
+ if (nap)
+ return nap->remote_value;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/base_fs.c b/cpukit/libcsupport/src/base_fs.c
new file mode 100644
index 0000000000..b5681eda63
--- /dev/null
+++ b/cpukit/libcsupport/src/base_fs.c
@@ -0,0 +1,114 @@
+/*
+ * Base file system initialization
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+
+/*
+ * Default mode for created files.
+ */
+
+
+/*
+ * rtems_filesystem_initialize
+ *
+ * Initialize the foundation of the file system. This is specified
+ * by the structure rtems_filesystem_mount_table. The usual
+ * configuration is a single instantiation of the IMFS or miniIMFS with
+ * a single "/dev" directory in it.
+ */
+
+void rtems_filesystem_initialize( void )
+{
+ int status;
+ const rtems_filesystem_mount_table_t *mt;
+ rtems_filesystem_location_info_t loc;
+
+ /*
+ * Set the default umask to "022".
+ */
+
+ rtems_filesystem_umask = 022;
+
+ /*
+ * mount the first filesystem.
+ */
+ if ( rtems_filesystem_mount_table_size == 0 )
+ rtems_fatal_error_occurred( 0xABCD0001 );
+
+ mt = &rtems_filesystem_mount_table[0];
+
+ status = mount( mt->device, mt->mount_point, mt->type, mt->fsoptions, NULL );
+ if ( status == -1 )
+ rtems_fatal_error_occurred( 0xABCD0002 );
+
+ rtems_filesystem_link_counts = 0;
+
+ /* setup the 'current' and 'root' directories
+ *
+ * NOTE: cloning the pathlocs is not strictly
+ * necessary. Since we implicitely let
+ * all threads that don't call
+ * libio_set_private_env() share the same
+ * (initial) 'root' and 'current' locs,
+ * we (also implicitely) assume that the
+ * root filesystem doesn't care about
+ * reference counts.
+ * I just inserted the code snippet below
+ * to remind everybody of the fact by
+ * making it more explicit...
+ * Ideally, every thread would have to
+ * call either share_private_env() or
+ * set_private_env() - but then: that's
+ * gonna hit performance.
+ *
+ * Till Straumann, 10/25/2002
+ */
+ /* Clone the root pathloc */
+ rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0);
+ rtems_filesystem_root = loc;
+ /* One more clone for the current node */
+ rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0);
+ rtems_filesystem_current = loc;
+
+ /* Note: the global_env's refcnt doesn't matter
+ * as the global env is never released
+ */
+
+
+ /*
+ * Traditionally RTEMS devices are under "/dev" so install this directory.
+ *
+ * If the mkdir() fails, we can't print anything so just fatal error.
+ *
+ * NOTE: UNIX root is 755 and owned by root/root (0/0). It is actually
+ * created that way by the IMFS.
+ */
+
+ status = mkdir( "/dev", 0777);
+ if ( status != 0 )
+ rtems_fatal_error_occurred( 0xABCD0003 );
+
+ /*
+ * You can't mount another filesystem properly until the mount point
+ * it will be mounted onto is created. Moreover, if it is going to
+ * use a device, then it is REALLY unfair to attempt this
+ * before device drivers are initialized. So we return via a base
+ * filesystem image and nothing auto-mounted at this point.
+ */
+}
diff --git a/cpukit/libcsupport/src/calloc.c b/cpukit/libcsupport/src/calloc.c
new file mode 100644
index 0000000000..859b4c2213
--- /dev/null
+++ b/cpukit/libcsupport/src/calloc.c
@@ -0,0 +1,41 @@
+/*
+ * calloc()
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC)
+#include "malloc_p.h"
+#include <stdlib.h>
+
+void *calloc(
+ size_t nelem,
+ size_t elsize
+)
+{
+ register char *cptr;
+ size_t length;
+
+ MSBUMP(calloc_calls, 1);
+
+ length = nelem * elsize;
+ cptr = malloc( length );
+ if ( cptr )
+ memset( cptr, '\0', length );
+
+ MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */
+
+ return cptr;
+}
+#endif
diff --git a/cpukit/libcsupport/src/cfgetispeed.c b/cpukit/libcsupport/src/cfgetispeed.c
new file mode 100644
index 0000000000..225c7311cc
--- /dev/null
+++ b/cpukit/libcsupport/src/cfgetispeed.c
@@ -0,0 +1,32 @@
+/*
+ * cfgetispeed() - POSIX 1003.1b 7.1.3 - Baud Rate Functions
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+
+speed_t cfgetispeed(
+ const struct termios *tp
+)
+{
+ return (tp->c_cflag / (CIBAUD / CBAUD)) & CBAUD;
+}
+#endif
diff --git a/cpukit/libcsupport/src/cfgetospeed.c b/cpukit/libcsupport/src/cfgetospeed.c
new file mode 100644
index 0000000000..e239e54758
--- /dev/null
+++ b/cpukit/libcsupport/src/cfgetospeed.c
@@ -0,0 +1,32 @@
+/*
+ * cfgetospeed() - POSIX 1003.1b 7.1.3 - Baud Rate Functions
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+
+speed_t cfgetospeed(
+ const struct termios *tp
+)
+{
+ return tp->c_cflag & CBAUD;
+}
+#endif
diff --git a/cpukit/libcsupport/src/cfsetispeed.c b/cpukit/libcsupport/src/cfsetispeed.c
new file mode 100644
index 0000000000..383762bee1
--- /dev/null
+++ b/cpukit/libcsupport/src/cfsetispeed.c
@@ -0,0 +1,40 @@
+/*
+ * cfsetispeed() - POSIX 1003.1b 7.1.3 - Baud Rate Functions
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int cfsetispeed(
+ struct termios *tp,
+ speed_t speed
+)
+{
+ if ( speed & ~CBAUD )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ tp->c_cflag = (tp->c_cflag & ~CIBAUD) | (speed * (CIBAUD / CBAUD));
+ return 0;
+}
+#endif
diff --git a/cpukit/libcsupport/src/cfsetospeed.c b/cpukit/libcsupport/src/cfsetospeed.c
new file mode 100644
index 0000000000..0badcbbdc7
--- /dev/null
+++ b/cpukit/libcsupport/src/cfsetospeed.c
@@ -0,0 +1,40 @@
+/*
+ * cfsetospeed() - POSIX 1003.1b 7.1.3 - Baud Rate Functions
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int cfsetospeed(
+ struct termios *tp,
+ speed_t speed
+)
+{
+ if ( speed & ~CBAUD )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ tp->c_cflag = (tp->c_cflag & ~CBAUD) | speed;
+ return 0;
+}
+#endif
diff --git a/cpukit/libcsupport/src/chdir.c b/cpukit/libcsupport/src/chdir.c
new file mode 100644
index 0000000000..c9d05f0bef
--- /dev/null
+++ b/cpukit/libcsupport/src/chdir.c
@@ -0,0 +1,57 @@
+/*
+ * chdir() - POSIX 1003.1b - 5.2.1 - Change Current Working Directory
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int chdir(
+ const char *pathname
+)
+{
+ rtems_filesystem_location_info_t loc;
+ int result;
+
+ if ( !pathname )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ /*
+ * Get the node where we wish to go.
+ */
+ result = rtems_filesystem_evaluate_path(
+ pathname, strlen( pathname ), RTEMS_LIBIO_PERMS_SEARCH, &loc, true );
+ if ( result != 0 )
+ return -1;
+
+ /*
+ * Verify you can change directory into this node.
+ */
+ if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
+ rtems_filesystem_freenode( &loc );
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+ }
+
+ rtems_filesystem_freenode( &rtems_filesystem_current );
+
+ rtems_filesystem_current = loc;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/chmod.c b/cpukit/libcsupport/src/chmod.c
new file mode 100644
index 0000000000..d1d9ae0f5f
--- /dev/null
+++ b/cpukit/libcsupport/src/chmod.c
@@ -0,0 +1,46 @@
+/*
+ * chmod() - POSIX 1003.1b 5.6.4 - Change File Modes
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int chmod(
+ const char *path,
+ mode_t mode
+)
+{
+ int status;
+ rtems_filesystem_location_info_t loc;
+ int result;
+
+ status = rtems_filesystem_evaluate_path( path, strlen( path ), 0, &loc, true );
+ if ( status != 0 )
+ return -1;
+
+ result = (*loc.handlers->fchmod_h)( &loc, mode );
+
+ rtems_filesystem_freenode( &loc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/chown.c b/cpukit/libcsupport/src/chown.c
new file mode 100644
index 0000000000..3cab985cad
--- /dev/null
+++ b/cpukit/libcsupport/src/chown.c
@@ -0,0 +1,54 @@
+/*
+ * chown() - POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int _chown_helper(
+ const char *path,
+ uid_t owner,
+ gid_t group,
+ int follow_link
+)
+{
+ rtems_filesystem_location_info_t loc;
+ int result;
+
+ if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x00, &loc, follow_link ) )
+ return -1;
+
+ result = (*loc.ops->chown_h)( &loc, owner, group );
+
+ rtems_filesystem_freenode( &loc );
+
+ return result;
+}
+
+int chown(
+ const char *path,
+ uid_t owner,
+ gid_t group
+)
+{
+ return _chown_helper( path, owner, group, true );
+}
diff --git a/cpukit/libcsupport/src/chroot.c b/cpukit/libcsupport/src/chroot.c
new file mode 100644
index 0000000000..ccda4d6d7a
--- /dev/null
+++ b/cpukit/libcsupport/src/chroot.c
@@ -0,0 +1,55 @@
+/*
+ * chroot() - Change Root Directory
+ * Author: fernando.ruiz@ctv.es
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int chroot(
+ const char *pathname
+)
+{
+ int result;
+ rtems_filesystem_location_info_t loc;
+
+ /* an automatic call to new private env the first time */
+ if (rtems_current_user_env == &rtems_global_user_env) {
+ rtems_libio_set_private_env(); /* try to set a new private env*/
+ if (rtems_current_user_env == &rtems_global_user_env) /* not ok */
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+ }
+
+ result = chdir(pathname);
+ if (result) {
+ rtems_set_errno_and_return_minus_one( errno );
+ }
+
+ /* clone the new root location */
+ if (rtems_filesystem_evaluate_path(".", 1, 0, &loc, 0)) {
+ /* our cwd has changed, though - but there is no easy way of return :-( */
+ rtems_set_errno_and_return_minus_one( errno );
+ }
+ rtems_filesystem_freenode(&rtems_filesystem_root);
+ rtems_filesystem_root = loc;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/close.c b/cpukit/libcsupport/src/close.c
new file mode 100644
index 0000000000..726bca11d9
--- /dev/null
+++ b/cpukit/libcsupport/src/close.c
@@ -0,0 +1,57 @@
+/*
+ * close() - POSIX 1003.1b 6.3.1 - Close a File
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+
+int close(
+ int fd
+)
+{
+ rtems_libio_t *iop;
+ rtems_status_code rc;
+
+ rtems_libio_check_fd(fd);
+ iop = rtems_libio_iop(fd);
+ rtems_libio_check_is_open(iop);
+
+ rc = RTEMS_SUCCESSFUL;
+ rc = (*iop->pathinfo.handlers->close_h)( iop );
+
+ rtems_filesystem_freenode( &iop->pathinfo );
+ rtems_libio_free( iop );
+
+ return rc;
+}
+
+/*
+ * _close_r
+ *
+ * This is the Newlib dependent reentrant version of close().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__CLOSE_R)
+
+#include <reent.h>
+
+int _close_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd
+)
+{
+ return close( fd );
+}
+#endif
diff --git a/cpukit/libcsupport/src/ctermid.c b/cpukit/libcsupport/src/ctermid.c
new file mode 100644
index 0000000000..37b2f9cfc0
--- /dev/null
+++ b/cpukit/libcsupport/src/ctermid.c
@@ -0,0 +1,42 @@
+/*
+ * ctermid() - POSIX 1003.1b 4.7.1 - Generate Terminal Pathname
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <stdio.h>
+#include <string.h>
+
+static char *ctermid_name = "/dev/console";
+
+char *ctermid(
+ char *s
+)
+{
+ if ( !s )
+ return ctermid_name;
+
+ /*
+ * We have no way of knowing the length of the user provided buffer.
+ * It may not be large enough but there is no way to know that. :(
+ * So this is a potential buffer owerrun that we can do nothing about.
+ */
+ strcpy( s, ctermid_name );
+ return s;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/dup.c b/cpukit/libcsupport/src/dup.c
new file mode 100644
index 0000000000..684d72d92f
--- /dev/null
+++ b/cpukit/libcsupport/src/dup.c
@@ -0,0 +1,26 @@
+/*
+ * dup() - POSIX 1003.1b 6.2.1 Duplicate an Open File Descriptor
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+
+int dup(
+ int fildes
+)
+{
+ return fcntl( fildes, F_DUPFD, 0 );
+}
diff --git a/cpukit/libcsupport/src/dup2.c b/cpukit/libcsupport/src/dup2.c
new file mode 100644
index 0000000000..15998f797c
--- /dev/null
+++ b/cpukit/libcsupport/src/dup2.c
@@ -0,0 +1,52 @@
+/*
+ * dup2() - POSIX 1003.1b 6.2.1 Duplicate an Open File Descriptor
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <rtems/libio_.h>
+
+int dup2(
+ int fildes,
+ int fildes2
+)
+{
+ int status;
+ struct stat buf;
+
+ /*
+ * If fildes is not valid, then fildes2 should not be closed.
+ */
+
+ status = fstat( fildes, &buf );
+ if ( status == -1 )
+ return -1;
+
+ /*
+ * If fildes2 is not valid, then we should not do anything either.
+ */
+
+ status = fstat( fildes2, &buf );
+ if ( status == -1 )
+ return -1;
+
+ /*
+ * This fcntl handles everything else.
+ */
+
+ return fcntl( fildes, F_DUPFD, fildes2 );
+}
diff --git a/cpukit/libcsupport/src/envlock.c b/cpukit/libcsupport/src/envlock.c
new file mode 100644
index 0000000000..9594e0abe3
--- /dev/null
+++ b/cpukit/libcsupport/src/envlock.c
@@ -0,0 +1,108 @@
+/*
+ * Author: Till Straumann <strauman@slac.stanford.edu>, 3/2002
+ *
+ * $Id$
+ */
+
+/* provide locking for the global environment 'environ' */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <sys/reent.h>
+
+#include <assert.h>
+
+/*
+ * NOTES:
+ * - although it looks like a classical multiple-readers / single writer (MRSW)
+ * locking problem, we still use a single lock for the following reasons:
+ * 1) newlib has no provision / hook for calling different locking routines
+ * from setenv/putenv and getenv, respectively.
+ * 2) MRSW involves calling several semaphore-primitives, even in the most
+ * likely case of a first-reader's access. This probably takes more CPU
+ * time than just waiting until another reader is done; environment
+ * access is fast.
+ * - the lock implementation must allow nesting (same thread may call
+ * lock-lock-unlock-unlock).
+ * - NEWLIB-1.8.2 has an ugly BUG: if environ is NULL, _findenv_r() bails
+ * out leaving the lock held :-(
+ *
+ * Used by the following functions:
+ * findenv_r(), setenv_r(), and unsetenv_r() which are called by
+ * getenv(), getenv_r(), setenv(), and unsetenv().
+ *
+ */
+
+#if defined(ENVLOCK_DEDIDCATED_MUTEX)
+static rtems_id envLock=0;
+
+static void
+__rtems_envlock_init(void)
+{
+ extern char **environ;
+ rtems_status_code rc;
+
+ if (envLock) /* already initialized */
+ return;
+
+ assert(environ && "MUST have non-NULL 'environ' due to newlib bug");
+
+ rc = rtems_semaphore_create(
+ rtems_build_name('E','N','V','S'),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
+ 0,
+ &envLock);
+ if (RTEMS_SUCCESSFUL!=rc)
+ rtems_fatal_error_occurred(rc);
+}
+
+void
+__env_lock(struct _reent *r)
+{
+ /* Do lazy init */
+ if (!envLock)
+ __rtems_envlock_init();
+ /*
+ * Must not use a semaphore before pre-tasking hook is called.
+ * - it will corrupt memory :-(
+ */
+
+ if (_Thread_Executing)
+ rtems_semaphore_obtain(envLock, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+}
+
+void
+__env_unlock(struct _reent *r)
+{
+ /*
+ * Must not use a semaphore before pre-tasking hook is called.
+ * - it will corrupt memory :-(
+ */
+ if (_Thread_Executing)
+ rtems_semaphore_release(envLock);
+}
+#else
+
+/*
+ * Reuse the libio mutex -- it is always initialized before we
+ * could possibly run.
+ */
+
+#include <rtems/libio_.h>
+
+void
+__env_lock(struct _reent *r __attribute__((unused)))
+{
+ rtems_libio_lock();
+}
+
+void
+__env_unlock(struct _reent *r __attribute__((unused)))
+{
+ rtems_libio_unlock();
+}
+#endif
diff --git a/cpukit/libcsupport/src/error.c b/cpukit/libcsupport/src/error.c
new file mode 100644
index 0000000000..074707c54c
--- /dev/null
+++ b/cpukit/libcsupport/src/error.c
@@ -0,0 +1,209 @@
+/*
+ * report errors and panics to RTEMS' stderr.
+ * Currently just used by RTEMS monitor.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * These routines provide general purpose error reporting.
+ * rtems_error reports an error to stderr and allows use of
+ * printf style formatting. A newline is appended to all messages.
+ *
+ * error_flag can be specified as any of the following:
+ *
+ * RTEMS_ERROR_ERRNO -- include errno text in output
+ * RTEMS_ERROR_PANIC -- halts local system after output
+ * RTEMS_ERROR_ABORT -- abort after output
+ *
+ * It can also include a rtems_status value which can be OR'd
+ * with the above flags. *
+ *
+ * EXAMPLE
+ * #include <rtems.h>
+ * #include <rtems/error.h>
+ * rtems_error(0, "stray interrupt %d", intr);
+ *
+ * EXAMPLE
+ * if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL)
+ * {
+ * rtems_error(status | RTEMS_ERROR_ABORT,
+ * "could not create task");
+ * }
+ *
+ * EXAMPLE
+ * if ((fd = open(pathname, O_RDNLY)) < 0)
+ * {
+ * rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname);
+ * goto failed;
+ * }
+ */
+
+/* This is always defined on RTEMS Scheduler Simulator and thus
+ * we get a redefined warning if this is not present.
+ */
+#ifndef __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+ #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#endif
+#include <rtems.h>
+
+#include <rtems/error.h>
+#include <rtems/assoc.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h> /* _exit() */
+
+int rtems_panic_in_progress;
+
+const rtems_assoc_t rtems_status_assoc[] = {
+ { "successful completion", RTEMS_SUCCESSFUL, 0 },
+ { "returned from a thread", RTEMS_TASK_EXITTED, 0 },
+ { "multiprocessing not configured", RTEMS_MP_NOT_CONFIGURED, 0 },
+ { "invalid object name", RTEMS_INVALID_NAME, 0 },
+ { "invalid object id", RTEMS_INVALID_ID, 0 },
+ { "too many", RTEMS_TOO_MANY, 0 },
+ { "timed out waiting", RTEMS_TIMEOUT, 0 },
+ { "object deleted while waiting", RTEMS_OBJECT_WAS_DELETED, 0 },
+ { "specified size was invalid", RTEMS_INVALID_SIZE, 0 },
+ { "address specified is invalid", RTEMS_INVALID_ADDRESS, 0 },
+ { "number was invalid", RTEMS_INVALID_NUMBER, 0 },
+ { "item has not been initialized", RTEMS_NOT_DEFINED, 0 },
+ { "resources still outstanding", RTEMS_RESOURCE_IN_USE, 0 },
+ { "request not satisfied", RTEMS_UNSATISFIED, 0 },
+ { "thread is in wrong state", RTEMS_INCORRECT_STATE, 0 },
+ { "thread already in state", RTEMS_ALREADY_SUSPENDED, 0 },
+ { "illegal on calling thread", RTEMS_ILLEGAL_ON_SELF, 0 },
+ { "illegal for remote object", RTEMS_ILLEGAL_ON_REMOTE_OBJECT, 0 },
+ { "called from wrong environment", RTEMS_CALLED_FROM_ISR, 0 },
+ { "invalid thread priority", RTEMS_INVALID_PRIORITY, 0 },
+ { "invalid date/time", RTEMS_INVALID_CLOCK, 0 },
+ { "invalid node id", RTEMS_INVALID_NODE, 0 },
+ { "directive not configured", RTEMS_NOT_CONFIGURED, 0 },
+ { "not owner of resource", RTEMS_NOT_OWNER_OF_RESOURCE , 0 },
+ { "directive not implemented", RTEMS_NOT_IMPLEMENTED, 0 },
+ { "RTEMS inconsistency detected", RTEMS_INTERNAL_ERROR, 0 },
+ { "could not get enough memory", RTEMS_NO_MEMORY, 0 },
+ { "driver IO error", RTEMS_IO_ERROR, 0 },
+ { "internal multiprocessing only", THREAD_STATUS_PROXY_BLOCKING, 0 },
+ { 0, 0, 0 },
+};
+
+
+const char *rtems_status_text(
+ rtems_status_code status
+)
+{
+ return rtems_assoc_name_by_local(rtems_status_assoc, status);
+}
+
+
+static int rtems_verror(
+ rtems_error_code_t error_flag,
+ const char *printf_format,
+ va_list arglist
+)
+{
+ int local_errno = 0;
+ int chars_written = 0;
+ rtems_status_code status;
+
+ if (error_flag & RTEMS_ERROR_PANIC) {
+ if (rtems_panic_in_progress++)
+ _Thread_Disable_dispatch(); /* disable task switches */
+
+ /* don't aggravate things */
+ if (rtems_panic_in_progress > 2)
+ return 0;
+ }
+
+ (void) fflush(stdout); /* in case stdout/stderr same */
+
+ status = error_flag & ~RTEMS_ERROR_MASK;
+ if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */
+ local_errno = errno;
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if (_System_state_Is_multiprocessing)
+ fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node);
+ #endif
+
+ chars_written += vfprintf(stderr, printf_format, arglist);
+
+ if (status)
+ chars_written +=
+ fprintf(stderr, " (status: %s)", rtems_status_text(status));
+
+ if (local_errno) {
+ if ((local_errno > 0) && *strerror(local_errno))
+ chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
+ else
+ chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
+ }
+
+ chars_written += fprintf(stderr, "\n");
+
+ (void) fflush(stderr);
+
+ return chars_written;
+}
+
+
+/*
+ * Report an error.
+ * error_flag is as above; printf_format is a normal
+ * printf(3) format string, with its concommitant arguments.
+ *
+ * Returns the number of characters written.
+ */
+
+int rtems_error(
+ rtems_error_code_t error_flag,
+ const char *printf_format,
+ ...
+)
+{
+ va_list arglist;
+ int chars_written;
+
+ va_start(arglist, printf_format);
+ chars_written = rtems_verror(error_flag, printf_format, arglist);
+ va_end(arglist);
+
+ if (error_flag & RTEMS_ERROR_PANIC) {
+ rtems_error(0, "fatal error, exiting");
+ _exit(errno);
+ }
+ if (error_flag & RTEMS_ERROR_ABORT) {
+ rtems_error(0, "fatal error, aborting");
+ abort();
+ }
+
+ return chars_written;
+}
+
+/*
+ * rtems_panic is shorthand for rtems_error(RTEMS_ERROR_PANIC, ...)
+ */
+
+void rtems_panic(
+ const char *printf_format,
+ ...
+)
+{
+ va_list arglist;
+
+ va_start(arglist, printf_format);
+ (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
+ va_end(arglist);
+
+ rtems_error(0, "fatal error, exiting");
+ _exit(errno);
+}
diff --git a/cpukit/libcsupport/src/eval.c b/cpukit/libcsupport/src/eval.c
new file mode 100644
index 0000000000..5a9118d3e1
--- /dev/null
+++ b/cpukit/libcsupport/src/eval.c
@@ -0,0 +1,151 @@
+/*
+ * rtems_filesystem_evaluate_path()
+ *
+ * Routine to seed the evaluate path routine.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_evaluate_relative_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc,
+ int follow_link
+)
+{
+ int result;
+ rtems_filesystem_node_types_t type;
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * Verify Input parameters that should never be bad unless someone
+ * is implementing a new filesystem and has bugs.
+ */
+ if ( !pathname )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ if ( !pathloc )
+ rtems_set_errno_and_return_minus_one( EIO );
+ #endif
+
+ result = (*pathloc->ops->evalpath_h)( pathname, pathnamelen, flags, pathloc );
+
+ /*
+ * Get the Node type and determine if you need to follow the link or
+ * not.
+ */
+
+ if ( (result == 0) && follow_link ) {
+
+ type = (*pathloc->ops->node_type_h)( pathloc );
+
+ if ( ( type == RTEMS_FILESYSTEM_HARD_LINK ) ||
+ ( type == RTEMS_FILESYSTEM_SYM_LINK ) ) {
+
+ /* what to do with the valid node pathloc points to
+ * if eval_link_h fails?
+ * Let the FS implementation deal with this case. It
+ * should probably free pathloc in either case:
+ * - if the link evaluation fails, it must free the
+ * original (valid) pathloc because we are going
+ * to return -1 and hence the FS generics won't
+ * cleanup pathloc.
+ * - if the link evaluation is successful, the updated
+ * pathloc will be passed up (and eventually released).
+ * Hence, the (valid) originial node that we submit to
+ * eval_link_h() should be released by the handler.
+ */
+
+ result = (*pathloc->ops->eval_link_h)( pathloc, flags );
+ }
+ }
+
+ return result;
+}
+
+int rtems_filesystem_evaluate_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc,
+ int follow_link
+)
+{
+ int i = 0;
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * Verify Input parameters that should never be bad unless someone
+ * is implementing a new filesystem and has bugs.
+ */
+ if ( !pathname )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ if ( !pathloc )
+ rtems_set_errno_and_return_minus_one( EIO );
+ #endif
+
+ /*
+ * Evaluate the path using the optable evalpath.
+ */
+
+ rtems_filesystem_get_start_loc( pathname, &i, pathloc );
+
+ /*
+ * We evaluation the path relative to the start location we get got.
+ */
+ return rtems_filesystem_evaluate_relative_path( &pathname[i],
+ pathnamelen - i,
+ flags,
+ pathloc,
+ follow_link );
+}
+
+int rtems_filesystem_dirname(
+ const char *pathname
+)
+{
+ int len = strlen( pathname );
+
+ while ( len ) {
+ len--;
+ if ( rtems_filesystem_is_separator( pathname[len] ) )
+ break;
+ }
+
+ return len;
+}
+
+int rtems_filesystem_prefix_separators(
+ const char *pathname,
+ int pathnamelen
+)
+{
+ /*
+ * Eat any separators at start of the path.
+ */
+ int stripped = 0;
+ while ( *pathname && pathnamelen && rtems_filesystem_is_separator( *pathname ) )
+ {
+ pathname++;
+ pathnamelen--;
+ stripped++;
+ }
+ return stripped;
+}
diff --git a/cpukit/libcsupport/src/fchdir.c b/cpukit/libcsupport/src/fchdir.c
new file mode 100644
index 0000000000..3c53d653e3
--- /dev/null
+++ b/cpukit/libcsupport/src/fchdir.c
@@ -0,0 +1,82 @@
+/*
+ * fchdir() - compatible with SVr4, 4.4BSD and X/OPEN - Change Directory
+ *
+ * COPYRIGHT (c) 1989-2000.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int fchdir(
+ int fd
+)
+{
+ rtems_libio_t *iop;
+ rtems_filesystem_location_info_t loc, saved;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ /*
+ * Now process the fchmod().
+ */
+
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
+
+ /*
+ * Verify you can change directory into this node.
+ */
+
+ if ( (*iop->pathinfo.ops->node_type_h)( &iop->pathinfo ) !=
+ RTEMS_FILESYSTEM_DIRECTORY ) {
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+ }
+
+
+ /*
+ * FIXME : I feel there should be another call to
+ * actually take into account the extra reference to
+ * this node which we are making here. I can
+ * see the freenode interface but do not see
+ * allocnode node interface. It maybe node_type.
+ *
+ * FIXED: T.Straumann: it is evaluate_path()
+ * but note the race condition. Threads who
+ * share their rtems_filesystem_current better
+ * be synchronized!
+ */
+
+ saved = rtems_filesystem_current;
+ rtems_filesystem_current = iop->pathinfo;
+
+ /* clone the current node */
+ if (rtems_filesystem_evaluate_path(".", 1, 0, &loc, 0)) {
+ /* cloning failed; restore original and bail out */
+ rtems_filesystem_current = saved;
+ return -1;
+ }
+ /* release the old one */
+ rtems_filesystem_freenode( &saved );
+
+ rtems_filesystem_current = loc;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/fchmod.c b/cpukit/libcsupport/src/fchmod.c
new file mode 100644
index 0000000000..867f40f1f8
--- /dev/null
+++ b/cpukit/libcsupport/src/fchmod.c
@@ -0,0 +1,45 @@
+/*
+ * fchmod() - POSIX 1003.1b 5.6.4 - Change File Modes
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int fchmod(
+ int fd,
+ mode_t mode
+)
+{
+ rtems_libio_t *iop;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ /*
+ * Now process the fchmod().
+ */
+
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ return (*iop->pathinfo.handlers->fchmod_h)( &iop->pathinfo, mode );
+}
diff --git a/cpukit/libcsupport/src/fchown.c b/cpukit/libcsupport/src/fchown.c
new file mode 100644
index 0000000000..13bb2b9da0
--- /dev/null
+++ b/cpukit/libcsupport/src/fchown.c
@@ -0,0 +1,42 @@
+/*
+ * fchown() - POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int fchown(
+ int fd,
+ uid_t owner,
+ gid_t group
+)
+{
+ rtems_libio_t *iop;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ return (*iop->pathinfo.ops->chown_h)( &iop->pathinfo, owner, group );
+}
diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c
new file mode 100644
index 0000000000..988a9414ee
--- /dev/null
+++ b/cpukit/libcsupport/src/fcntl.c
@@ -0,0 +1,184 @@
+/*
+ * fcntl() - POSIX 1003.1b 6.5.2 - File Control
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+static int vfcntl(
+ int fd,
+ int cmd,
+ va_list ap
+)
+{
+ rtems_libio_t *iop;
+ rtems_libio_t *diop;
+ int fd2;
+ int flags;
+ int mask;
+ int ret = 0;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ /*
+ * Now process the fcntl().
+ */
+
+ /*
+ * This switch should contain all the cases from POSIX.
+ */
+
+ switch ( cmd ) {
+ case F_DUPFD: /* dup */
+ fd2 = va_arg( ap, int );
+ if ( fd2 )
+ diop = rtems_libio_iop( fd2 );
+ else {
+ /* allocate a file control block */
+ diop = rtems_libio_allocate();
+ if ( diop == 0 ) {
+ ret = -1;
+ break;
+ }
+ }
+
+ diop->flags = iop->flags;
+ diop->pathinfo = iop->pathinfo;
+ ret = (int) (diop - rtems_libio_iops);
+ break;
+
+ case F_GETFD: /* get f_flags */
+ ret = ((iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC) != 0);
+ break;
+
+ case F_SETFD: /* set f_flags */
+ /*
+ * Interpret the third argument as the "close on exec()" flag.
+ * If this argument is 1, then the file descriptor is to be closed
+ * if a new process is exec()'ed. Since RTEMS does not support
+ * processes, then we can ignore this one except to make
+ * F_GETFD work.
+ */
+
+ if ( va_arg( ap, int ) )
+ iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
+ else
+ iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC;
+ break;
+
+ case F_GETFL: /* more flags (cloexec) */
+ ret = rtems_libio_to_fcntl_flags( iop->flags );
+ break;
+
+ case F_SETFL:
+ flags = rtems_libio_fcntl_flags( va_arg( ap, int ) );
+ mask = LIBIO_FLAGS_NO_DELAY | LIBIO_FLAGS_APPEND;
+
+ /*
+ * XXX If we are turning on append, should we seek to the end?
+ */
+
+ iop->flags = (iop->flags & ~mask) | (flags & mask);
+ break;
+
+ case F_GETLK:
+ errno = ENOTSUP;
+ ret = -1;
+ break;
+
+ case F_SETLK:
+ errno = ENOTSUP;
+ ret = -1;
+ break;
+
+ case F_SETLKW:
+ errno = ENOTSUP;
+ ret = -1;
+ break;
+
+ case F_SETOWN: /* for sockets. */
+ errno = ENOTSUP;
+ ret = -1;
+ break;
+
+ case F_GETOWN: /* for sockets. */
+ errno = ENOTSUP;
+ ret = -1;
+ break;
+
+ default:
+ errno = EINVAL;
+ ret = -1;
+ break;
+ }
+
+ /*
+ * If we got this far successfully, then we give the optional
+ * filesystem specific handler a chance to process this.
+ */
+
+ if (ret >= 0) {
+ int err = (*iop->pathinfo.handlers->fcntl_h)( cmd, iop );
+ if (err) {
+ errno = err;
+ ret = -1;
+ }
+ }
+ return ret;
+}
+
+int fcntl(
+ int fd,
+ int cmd,
+ ...
+)
+{
+ int ret;
+ va_list ap;
+ va_start( ap, cmd );
+ ret = vfcntl(fd,cmd,ap);
+ va_end(ap);
+ return ret;
+}
+
+
+/*
+ * _fcntl_r
+ *
+ * This is the Newlib dependent reentrant version of fcntl().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_FCNTL_R)
+
+#include <reent.h>
+
+int _fcntl_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd,
+ int cmd,
+ int arg
+)
+{
+ return fcntl( fd, cmd, arg );
+}
+#endif
diff --git a/cpukit/libcsupport/src/fdatasync.c b/cpukit/libcsupport/src/fdatasync.c
new file mode 100644
index 0000000000..de226af5c1
--- /dev/null
+++ b/cpukit/libcsupport/src/fdatasync.c
@@ -0,0 +1,39 @@
+/*
+ * fdatasync() - POSIX 1003.1b 6.6.2 - Synchronize the Data of a File
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int fdatasync(
+ int fd
+)
+{
+ rtems_libio_t *iop;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ /*
+ * Now process the fdatasync().
+ */
+
+ return (*iop->pathinfo.handlers->fdatasync_h)( iop );
+}
diff --git a/cpukit/libcsupport/src/flockfile.c b/cpukit/libcsupport/src/flockfile.c
new file mode 100644
index 0000000000..db83961af1
--- /dev/null
+++ b/cpukit/libcsupport/src/flockfile.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2009 by
+ * Ralf Corsépius, Ulm, Germany. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_FLOCKFILE) && defined(HAVE_DECL_FLOCKFILE)
+
+#include <stdio.h>
+
+/* This is a non-functional stub */
+void flockfile(FILE* file)
+{
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/fpathconf.c b/cpukit/libcsupport/src/fpathconf.c
new file mode 100644
index 0000000000..accaae1585
--- /dev/null
+++ b/cpukit/libcsupport/src/fpathconf.c
@@ -0,0 +1,87 @@
+/*
+ * fpathconf() - POSIX 1003.1b - 5.7.1 - Configurable Pathname Varables
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#include <unistd.h>
+#include <errno.h>
+
+long fpathconf(
+ int fd,
+ int name
+)
+{
+ long return_value;
+ rtems_libio_t *iop;
+ rtems_filesystem_limits_and_options_t *the_limits;
+
+ rtems_libio_check_fd(fd);
+ iop = rtems_libio_iop(fd);
+ rtems_libio_check_is_open(iop);
+ rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
+
+ /*
+ * Now process the information request.
+ */
+
+ the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options;
+
+ switch ( name ) {
+ case _PC_LINK_MAX:
+ return_value = the_limits->link_max;
+ break;
+ case _PC_MAX_CANON:
+ return_value = the_limits->max_canon;
+ break;
+ case _PC_MAX_INPUT:
+ return_value = the_limits->max_input;
+ break;
+ case _PC_NAME_MAX:
+ return_value = the_limits->name_max;
+ break;
+ case _PC_PATH_MAX:
+ return_value = the_limits->path_max;
+ break;
+ case _PC_PIPE_BUF:
+ return_value = the_limits->pipe_buf;
+ break;
+ case _PC_CHOWN_RESTRICTED:
+ return_value = the_limits->posix_chown_restrictions;
+ break;
+ case _PC_NO_TRUNC:
+ return_value = the_limits->posix_no_trunc;
+ break;
+ case _PC_VDISABLE:
+ return_value = the_limits->posix_vdisable;
+ break;
+ case _PC_ASYNC_IO:
+ return_value = the_limits->posix_async_io;
+ break;
+ case _PC_PRIO_IO:
+ return_value = the_limits->posix_prio_io;
+ break;
+ case _PC_SYNC_IO:
+ return_value = the_limits->posix_sync_io;
+ break;
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ break;
+ }
+
+ return return_value;
+}
diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c
new file mode 100644
index 0000000000..d3ee2937f9
--- /dev/null
+++ b/cpukit/libcsupport/src/free.c
@@ -0,0 +1,55 @@
+/*
+ * calloc()
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+#include <stdlib.h>
+
+void free(
+ void *ptr
+)
+{
+ MSBUMP(free_calls, 1);
+
+ if ( !ptr )
+ return;
+
+ /*
+ * Do not attempt to free memory if in a critical section or ISR.
+ */
+ if ( _System_state_Is_up(_System_state_Get()) &&
+ !malloc_is_system_state_OK() ) {
+ malloc_deferred_free(ptr);
+ return;
+ }
+
+ /*
+ * If configured, update the statistics
+ */
+ if ( rtems_malloc_statistics_helpers )
+ (*rtems_malloc_statistics_helpers->at_free)(ptr);
+
+ if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
+ printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
+ ptr,
+ RTEMS_Malloc_Heap->area_begin,
+ RTEMS_Malloc_Heap->area_end
+ );
+ }
+
+}
+#endif
diff --git a/cpukit/libcsupport/src/freenode.c b/cpukit/libcsupport/src/freenode.c
new file mode 100644
index 0000000000..21a9c1de91
--- /dev/null
+++ b/cpukit/libcsupport/src/freenode.c
@@ -0,0 +1,20 @@
+/*
+ * freenode()
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <stdlib.h>
+#include <rtems/libio_.h>
+
+void rtems_filesystem_freenode( rtems_filesystem_location_info_t *_node )
+{
+ _node->ops->freenod_h(_node );
+}
diff --git a/cpukit/libcsupport/src/fstat.c b/cpukit/libcsupport/src/fstat.c
new file mode 100644
index 0000000000..0718c28d0d
--- /dev/null
+++ b/cpukit/libcsupport/src/fstat.c
@@ -0,0 +1,72 @@
+/*
+ * fstat() - POSIX 1003.1b 5.6.2 - Get File Status
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int fstat(
+ int fd,
+ struct stat *sbuf
+)
+{
+ rtems_libio_t *iop;
+
+ /*
+ * Check to see if we were passed a valid pointer.
+ */
+ if ( !sbuf )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ /*
+ * Now process the stat() request.
+ */
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_fd( fd );
+ rtems_libio_check_is_open(iop);
+
+ /*
+ * Zero out the stat structure so the various support
+ * versions of stat don't have to.
+ */
+ memset( sbuf, 0, sizeof(struct stat) );
+
+ return (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, sbuf );
+}
+
+/*
+ * _fstat_r
+ *
+ * This is the Newlib dependent reentrant version of fstat().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_FSTAT_R)
+
+#include <reent.h>
+
+int _fstat_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd,
+ struct stat *buf
+)
+{
+ return fstat( fd, buf );
+}
+#endif
diff --git a/cpukit/libcsupport/src/fsync.c b/cpukit/libcsupport/src/fsync.c
new file mode 100644
index 0000000000..4d2fe2ae12
--- /dev/null
+++ b/cpukit/libcsupport/src/fsync.c
@@ -0,0 +1,39 @@
+/*
+ * fsync() - POSIX 1003.1b 6.6.1 - Synchronize the State of a File
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int fsync(
+ int fd
+)
+{
+ rtems_libio_t *iop;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ /*
+ * Now process the fsync().
+ */
+
+ return (*iop->pathinfo.handlers->fsync_h)( iop );
+}
diff --git a/cpukit/libcsupport/src/ftruncate.c b/cpukit/libcsupport/src/ftruncate.c
new file mode 100644
index 0000000000..64946d7bb6
--- /dev/null
+++ b/cpukit/libcsupport/src/ftruncate.c
@@ -0,0 +1,51 @@
+/*
+ * ftruncate() - Truncate a File to the Specified Length
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int ftruncate(
+ int fd,
+ off_t length
+)
+{
+ rtems_libio_t *iop;
+ rtems_filesystem_location_info_t loc;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ /*
+ * Now process the ftruncate() request.
+ */
+
+ /*
+ * Make sure we are not working on a directory
+ */
+
+ loc = iop->pathinfo;
+ if ( (*loc.ops->node_type_h)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( EISDIR );
+
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ return (*iop->pathinfo.handlers->ftruncate_h)( iop, length );
+}
diff --git a/cpukit/libcsupport/src/ftrylockfile.c b/cpukit/libcsupport/src/ftrylockfile.c
new file mode 100644
index 0000000000..924690e44f
--- /dev/null
+++ b/cpukit/libcsupport/src/ftrylockfile.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2009 by
+ * Ralf Corsépius, Ulm, Germany. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_FTRYLOCKFILE) && defined(HAVE_DECL_FTRYLOCKFILE)
+
+#include <stdio.h>
+#include <rtems/seterr.h>
+#include <errno.h>
+
+/* This is a non-functional stub */
+int ftrylockfile(FILE* file)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/funlockfile.c b/cpukit/libcsupport/src/funlockfile.c
new file mode 100644
index 0000000000..a9f1bf3a92
--- /dev/null
+++ b/cpukit/libcsupport/src/funlockfile.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2009 by
+ * Ralf Corsépius, Ulm, Germany. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_FUNLOCKFILE) && defined(HAVE_DECL_FUNLOCKFILE)
+
+#include <stdio.h>
+
+/* This is a non-functional stub */
+void funlockfile(FILE* file)
+{
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/getchark.c b/cpukit/libcsupport/src/getchark.c
new file mode 100644
index 0000000000..f501fc65f0
--- /dev/null
+++ b/cpukit/libcsupport/src/getchark.c
@@ -0,0 +1,25 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/bspIo.h>
+
+int getchark(void)
+{
+ if ( BSP_poll_char )
+ return (*BSP_poll_char)();
+
+ return -1;
+}
diff --git a/cpukit/libcsupport/src/getcwd.c b/cpukit/libcsupport/src/getcwd.c
new file mode 100644
index 0000000000..2f2be7fc72
--- /dev/null
+++ b/cpukit/libcsupport/src/getcwd.c
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 1989, 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copied from newlib 1.8.1. RTEMS can not build all of the contents
+ * of the UNIX directory but we need this routine.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_GETCWD
+
+/*
+ * Added these when moved to RTEMS
+ */
+
+#define _stat stat
+#define _opendir opendir
+#define _fstat fstat
+#define _readdir readdir
+#define _closedir closedir
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getcwd.c 5.11 (Berkeley) 2/24/91";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <reent.h>
+#include <_syslist.h>
+
+#define bcopy(a,b,c) memmove (b,a,c)
+
+#define ISDOT(dp) \
+ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
+ (dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
+
+#ifndef _REENT_ONLY
+
+char *
+getcwd (
+ char *pt,
+ size_t size)
+{
+ register struct dirent *dp;
+ register DIR *dir = 0;
+ register dev_t dev;
+ register ino_t ino;
+ register int first;
+ register char *bpt, *bup;
+ struct stat s;
+ dev_t root_dev;
+ ino_t root_ino;
+ size_t ptsize, upsize;
+ int save_errno;
+ char *ept, *eup, *up;
+
+ /*
+ * If no buffer specified by the user, allocate one as necessary.
+ * If a buffer is specified, the size has to be non-zero. The path
+ * is built from the end of the buffer backwards.
+ */
+
+ if (pt)
+ {
+ ptsize = 0;
+ if (!size)
+ {
+ errno = EINVAL;
+ return (char *) NULL;
+ }
+ ept = pt + size;
+ }
+ else
+ {
+ if (!(pt = (char *) malloc (ptsize = 1024 - 4)))
+ {
+ return (char *) NULL;
+ }
+ ept = pt + ptsize;
+ }
+ bpt = ept - 1;
+ *bpt = '\0';
+
+ /*
+ * Allocate bytes (1024 - malloc space) for the string of "../"'s.
+ * Should always be enough (it's 340 levels). If it's not, allocate
+ * as necessary. Special * case the first stat, it's ".", not "..".
+ */
+
+ if (!(up = (char *) malloc (upsize = 1024 - 4)))
+ {
+ goto err;
+ }
+ eup = up + MAXPATHLEN;
+ bup = up;
+ up[0] = '.';
+ up[1] = '\0';
+
+ /* Save root values, so know when to stop. */
+ if (stat ("/", &s))
+ goto err;
+ root_dev = s.st_dev;
+ root_ino = s.st_ino;
+
+ errno = 0; /* XXX readdir has no error return. */
+
+ for (first = 1;; first = 0)
+ {
+ /* Stat the current level. */
+ if (_stat (up, &s))
+ goto err;
+
+ /* Save current node values. */
+ ino = s.st_ino;
+ dev = s.st_dev;
+
+ /* Check for reaching root. */
+ if (root_dev == dev && root_ino == ino)
+ {
+ *--bpt = '/';
+ /*
+ * It's unclear that it's a requirement to copy the
+ * path to the beginning of the buffer, but it's always
+ * been that way and stuff would probably break.
+ */
+ (void) bcopy (bpt, pt, ept - bpt);
+ free (up);
+ return pt;
+ }
+
+ /*
+ * Build pointer to the parent directory, allocating memory
+ * as necessary. Max length is 3 for "../", the largest
+ * possible component name, plus a trailing NULL.
+ */
+
+ if (bup + 3 + MAXNAMLEN + 1 >= eup)
+ {
+ if (!(up = (char *) realloc (up, upsize *= 2)))
+ {
+ goto err;
+ }
+ bup = up;
+ eup = up + upsize;
+ }
+ *bup++ = '.';
+ *bup++ = '.';
+ *bup = '\0';
+
+ /* Open and stat parent directory. */
+ if (!(dir = _opendir (up)) || _fstat (__dirfd (dir), &s))
+ goto err;
+
+ /* Add trailing slash for next directory. */
+ *bup++ = '/';
+
+ /*
+ * If it's a mount point, have to stat each element because
+ * the inode number in the directory is for the entry in the
+ * parent directory, not the inode number of the mounted file.
+ */
+
+ save_errno = 0;
+ if (s.st_dev == dev)
+ {
+ for (;;)
+ {
+ if (!(dp = _readdir (dir)))
+ goto notfound;
+ if (dp->d_ino == ino)
+ break;
+ }
+ }
+ else
+ for (;;)
+ {
+ if (!(dp = _readdir (dir)))
+ goto notfound;
+ if (ISDOT (dp))
+ continue;
+ bcopy (dp->d_name, bup, strlen (dp->d_name) + 1);
+
+ /* Save the first error for later. */
+ if (stat (up, &s))
+ {
+ if (!save_errno)
+ save_errno = errno;
+ errno = 0;
+ continue;
+ }
+ if (s.st_dev == dev && s.st_ino == ino)
+ break;
+ }
+
+ /*
+ * Check for length of the current name, preceding slash,
+ * leading slash.
+ */
+
+ if (bpt - pt <= strlen (dp->d_name) + (first ? 1 : 2))
+ {
+ size_t len, off;
+
+ if (!ptsize)
+ {
+ errno = ERANGE;
+ goto err;
+ }
+ off = bpt - pt;
+ len = ept - bpt;
+ if (!(pt = (char *) realloc (pt, ptsize *= 2)))
+ {
+ goto err;
+ }
+ bpt = pt + off;
+ ept = pt + ptsize;
+ (void) bcopy (bpt, ept - len, len);
+ bpt = ept - len;
+ }
+ if (!first)
+ *--bpt = '/';
+ bpt -= strlen (dp->d_name);
+ bcopy (dp->d_name, bpt, strlen (dp->d_name));
+ (void) _closedir (dir);
+ dir = 0;
+
+ /* Truncate any file name. */
+ *bup = '\0';
+ }
+
+notfound:
+ /*
+ * If readdir set errno, use it, not any saved error; otherwise,
+ * didn't find the current directory in its parent directory, set
+ * errno to ENOENT.
+ */
+
+ if (!errno)
+ errno = save_errno ? save_errno : ENOENT;
+ /* FALLTHROUGH */
+
+err:
+ if(dir)
+ (void) _closedir (dir);
+ if (ptsize)
+ free (pt);
+ free (up);
+ return (char *) NULL;
+}
+
+#endif /* _REENT_ONLY */
+
+#endif
diff --git a/cpukit/libcsupport/src/getdents.c b/cpukit/libcsupport/src/getdents.c
new file mode 100644
index 0000000000..d0b787cd88
--- /dev/null
+++ b/cpukit/libcsupport/src/getdents.c
@@ -0,0 +1,55 @@
+/*
+ * getdents() - Get Directory Entries
+ *
+ * SVR4 and SVID extension required by Newlib readdir() family.
+ *
+ * This routine will dd_len / (sizeof dirent) directory entries relative to
+ * the current directory position index. These entries will be placed in
+ * character array pointed to by -dd_buf-
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int getdents(
+ int dd_fd,
+ char *dd_buf,
+ int dd_len
+)
+{
+ rtems_libio_t *iop;
+ rtems_filesystem_location_info_t loc;
+
+ /*
+ * Get the file control block structure associated with the file descriptor
+ */
+ iop = rtems_libio_iop( dd_fd );
+
+ /*
+ * Make sure we are working on a directory
+ */
+ loc = iop->pathinfo;
+ if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * Return the number of bytes that were actually transfered as a result
+ * of the read attempt.
+ */
+ return (*iop->pathinfo.handlers->read_h)( iop, dd_buf, dd_len );
+}
diff --git a/cpukit/libcsupport/src/getegid.c b/cpukit/libcsupport/src/getegid.c
new file mode 100644
index 0000000000..2d89348230
--- /dev/null
+++ b/cpukit/libcsupport/src/getegid.c
@@ -0,0 +1,24 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+#include <rtems/userenv.h>
+
+/*
+ * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs,
+ * P1003.1b-1993, p. 84
+ */
+
+gid_t getegid( void )
+{
+ return _POSIX_types_Egid;
+}
diff --git a/cpukit/libcsupport/src/geteuid.c b/cpukit/libcsupport/src/geteuid.c
new file mode 100644
index 0000000000..de35557c63
--- /dev/null
+++ b/cpukit/libcsupport/src/geteuid.c
@@ -0,0 +1,31 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+
+#include <rtems/userenv.h>
+
+/*
+ * MACRO in userenv.h
+uid_t _POSIX_types_Euid = 0;
+*/
+
+/*PAGE
+ *
+ * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs,
+ * P1003.1b-1993, p. 84
+ */
+
+uid_t geteuid( void )
+{
+ return _POSIX_types_Euid;
+}
diff --git a/cpukit/libcsupport/src/getgid.c b/cpukit/libcsupport/src/getgid.c
new file mode 100644
index 0000000000..7074e765e5
--- /dev/null
+++ b/cpukit/libcsupport/src/getgid.c
@@ -0,0 +1,18 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/userenv.h>
+
+/*
+ * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs,
+ * P1003.1b-1993, p. 84
+ */
+gid_t getgid( void )
+{
+ return _POSIX_types_Gid;
+}
diff --git a/cpukit/libcsupport/src/getgroups.c b/cpukit/libcsupport/src/getgroups.c
new file mode 100644
index 0000000000..128761c8b6
--- /dev/null
+++ b/cpukit/libcsupport/src/getgroups.c
@@ -0,0 +1,23 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+
+/*PAGE
+ *
+ * 4.2.3 Get Supplementary IDs, P1003.1b-1993, p. 86
+ */
+
+int getgroups(
+ int gidsetsize __attribute__((unused)),
+ gid_t grouplist[] __attribute__((unused))
+)
+{
+ return 0; /* no supplemental group ids */
+}
diff --git a/cpukit/libcsupport/src/getlogin.c b/cpukit/libcsupport/src/getlogin.c
new file mode 100644
index 0000000000..f98e7ca9e0
--- /dev/null
+++ b/cpukit/libcsupport/src/getlogin.c
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <limits.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+#include <rtems/userenv.h>
+
+#include <unistd.h>
+#include <pwd.h>
+
+/*
+ * 4.2.4 Get User Name, P1003.1b-1993, p. 87
+ *
+ * NOTE: P1003.1c/D10, p. 49 adds getlogin_r().
+ */
+char *getlogin( void )
+{
+ (void) getlogin_r( _POSIX_types_Getlogin_buffer, LOGIN_NAME_MAX );
+ return _POSIX_types_Getlogin_buffer;
+}
+
+/*
+ * 4.2.4 Get User Name, P1003.1b-1993, p. 87
+ *
+ * NOTE: P1003.1c/D10, p. 49 adds getlogin_r().
+ */
+int getlogin_r(
+ char *name,
+ size_t namesize
+)
+{
+ struct passwd *pw;
+ char *pname;
+
+ if ( !name )
+ return EFAULT;
+
+ if ( namesize < LOGIN_NAME_MAX )
+ return ERANGE;
+
+ /* Set the pointer to a default name */
+ pname = "";
+
+ pw = getpwuid(getuid());
+ if ( pw )
+ pname = pw->pw_name;
+
+ strncpy( name, pname, LOGIN_NAME_MAX );
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/getpagesize.c b/cpukit/libcsupport/src/getpagesize.c
new file mode 100644
index 0000000000..3ea44be1fa
--- /dev/null
+++ b/cpukit/libcsupport/src/getpagesize.c
@@ -0,0 +1,22 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <sys/param.h>
+
+/*
+ * Get System Page Size (from SVR4 and 4.2+ BSD)
+ *
+ * This is not a functional version but the SPARC backend for at least
+ * gcc 2.8.1 plus gnat 3.13p and gcc 3.0.1 require it to be there and
+ * return a reasonable value.
+ */
+int getpagesize(void)
+{
+ return PAGE_SIZE;
+}
diff --git a/cpukit/libcsupport/src/getpgrp.c b/cpukit/libcsupport/src/getpgrp.c
new file mode 100644
index 0000000000..0904d23883
--- /dev/null
+++ b/cpukit/libcsupport/src/getpgrp.c
@@ -0,0 +1,31 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <limits.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 4.3.1 Get Process Group IDs, P1003.1b-1993, p. 89
+ */
+
+pid_t getpgrp( void )
+{
+ /*
+ * This always succeeds and returns the process group id. For rtems,
+ * this will always be the local node;
+ */
+
+ return _Objects_Local_node;
+}
diff --git a/cpukit/libcsupport/src/getpid.c b/cpukit/libcsupport/src/getpid.c
new file mode 100644
index 0000000000..55cd2a6589
--- /dev/null
+++ b/cpukit/libcsupport/src/getpid.c
@@ -0,0 +1,41 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 4.1.1 Get Process and Parent Process IDs, P1003.1b-1993, p. 83
+ */
+
+pid_t getpid( void )
+{
+ return _Objects_Local_node;
+}
+
+/*
+ * _getpid_r
+ *
+ * This is the Newlib dependent reentrant version of getpid().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETPID_R)
+
+#include <reent.h>
+
+pid_t _getpid_r(
+ struct _reent *ptr __attribute__((unused))
+)
+{
+ return getpid();
+}
+#endif
diff --git a/cpukit/libcsupport/src/getppid.c b/cpukit/libcsupport/src/getppid.c
new file mode 100644
index 0000000000..b987f69447
--- /dev/null
+++ b/cpukit/libcsupport/src/getppid.c
@@ -0,0 +1,25 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+
+pid_t _POSIX_types_Ppid = 0;
+
+/*PAGE
+ *
+ * 4.1.1 Get Process and Parent Process IDs, P1003.1b-1993, p. 83
+ */
+
+pid_t getppid( void )
+{
+ return _POSIX_types_Ppid;
+}
diff --git a/cpukit/libcsupport/src/getpwent.c b/cpukit/libcsupport/src/getpwent.c
new file mode 100644
index 0000000000..210f4bedd5
--- /dev/null
+++ b/cpukit/libcsupport/src/getpwent.c
@@ -0,0 +1,438 @@
+/*
+ * POSIX 1003.1b - 9.2.2 - User Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+/*
+ * Static, thread-unsafe, buffers
+ */
+static FILE *passwd_fp;
+static char pwbuf[200];
+static struct passwd pwent;
+static FILE *group_fp;
+static char grbuf[200];
+static struct group grent;
+
+/*
+ * Initialize useable but dummy databases
+ */
+void init_etc_passwd_group(void)
+{
+ FILE *fp;
+ static char etc_passwd_initted = 0;
+
+ if (etc_passwd_initted)
+ return;
+ etc_passwd_initted = 1;
+ mkdir("/etc", 0777);
+
+ /*
+ * Initialize /etc/passwd
+ */
+ if ((fp = fopen("/etc/passwd", "r")) != NULL) {
+ fclose(fp);
+ }
+ else if ((fp = fopen("/etc/passwd", "w")) != NULL) {
+ fprintf(fp, "root:*:0:0:root::/:/bin/sh\n"
+ "rtems:*:1:1:RTEMS Application::/:/bin/sh\n"
+ "tty:!:2:2:tty owner::/:/bin/false\n" );
+ fclose(fp);
+ }
+
+ /*
+ * Initialize /etc/group
+ */
+ if ((fp = fopen("/etc/group", "r")) != NULL) {
+ fclose(fp);
+ }
+ else if ((fp = fopen("/etc/group", "w")) != NULL) {
+ fprintf( fp, "root:x:0:root\n"
+ "rtems:x:1:rtems\n"
+ "tty:x:2:tty\n" );
+ fclose(fp);
+ }
+}
+
+/*
+ * Extract a string value from the database
+ */
+static int
+scanString(FILE *fp, char **name, char **bufp, size_t *nleft, int nlFlag)
+{
+ int c;
+
+ *name = *bufp;
+ for (;;) {
+ c = getc(fp);
+ if (c == ':') {
+ if (nlFlag)
+ return 0;
+ break;
+ }
+ if (c == '\n') {
+ if (!nlFlag)
+ return 0;
+ break;
+ }
+ if (c == EOF)
+ return 0;
+ if (*nleft < 2)
+ return 0;
+ **bufp = c;
+ ++(*bufp);
+ --(*nleft);
+ }
+ **bufp = '\0';
+ ++(*bufp);
+ --(*nleft);
+ return 1;
+}
+
+/*
+ * Extract an integer value from the database
+ */
+static int
+scanInt(FILE *fp, int *val)
+{
+ int c;
+ unsigned int i = 0;
+ unsigned int limit = INT_MAX;
+ int sign = 0;
+ int d;
+
+ for (;;) {
+ c = getc(fp);
+ if (c == ':')
+ break;
+ if (sign == 0) {
+ if (c == '-') {
+ sign = -1;
+ limit++;
+ continue;
+ }
+ sign = 1;
+ }
+ if (!isdigit(c))
+ return 0;
+ d = c - '0';
+ if ((i > (limit / 10))
+ || ((i == (limit / 10)) && (d > (limit % 10))))
+ return 0;
+ i = i * 10 + d;
+ }
+ if (sign == 0)
+ return 0;
+ *val = i * sign;
+ return 1;
+}
+
+/*
+ * Extract a single password record from the database
+ */
+static int scanpw(
+ FILE *fp,
+ struct passwd *pwd,
+ char *buffer,
+ size_t bufsize
+)
+{
+ int pwuid, pwgid;
+
+ if (!scanString(fp, &pwd->pw_name, &buffer, &bufsize, 0)
+ || !scanString(fp, &pwd->pw_passwd, &buffer, &bufsize, 0)
+ || !scanInt(fp, &pwuid)
+ || !scanInt(fp, &pwgid)
+ || !scanString(fp, &pwd->pw_comment, &buffer, &bufsize, 0)
+ || !scanString(fp, &pwd->pw_gecos, &buffer, &bufsize, 0)
+ || !scanString(fp, &pwd->pw_dir, &buffer, &bufsize, 0)
+ || !scanString(fp, &pwd->pw_shell, &buffer, &bufsize, 1))
+ return 0;
+ pwd->pw_uid = pwuid;
+ pwd->pw_gid = pwgid;
+ return 1;
+}
+
+static int getpw_r(
+ const char *name,
+ int uid,
+ struct passwd *pwd,
+ char *buffer,
+ size_t bufsize,
+ struct passwd **result
+)
+{
+ FILE *fp;
+ int match;
+
+ init_etc_passwd_group();
+
+ if ((fp = fopen("/etc/passwd", "r")) == NULL)
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ for(;;) {
+ if (!scanpw(fp, pwd, buffer, bufsize))
+ goto error_einval;
+
+ if (name) {
+ match = (strcmp(pwd->pw_name, name) == 0);
+ } else {
+ match = (pwd->pw_uid == uid);
+ }
+
+ if (match) {
+ fclose(fp);
+ *result = pwd;
+ return 0;
+ }
+ }
+error_einval:
+ fclose(fp);
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
+
+int getpwnam_r(
+ const char *name,
+ struct passwd *pwd,
+ char *buffer,
+ size_t bufsize,
+ struct passwd **result
+)
+{
+ return getpw_r(name, 0, pwd, buffer, bufsize, result);
+}
+
+struct passwd *getpwnam(
+ const char *name
+)
+{
+ struct passwd *p;
+
+ if(getpwnam_r(name, &pwent, pwbuf, sizeof pwbuf, &p))
+ return NULL;
+ return p;
+}
+
+int getpwuid_r(
+ uid_t uid,
+ struct passwd *pwd,
+ char *buffer,
+ size_t bufsize,
+ struct passwd **result
+)
+{
+ return getpw_r(NULL, uid, pwd, buffer, bufsize, result);
+}
+
+struct passwd *getpwuid(
+ uid_t uid
+)
+{
+ struct passwd *p;
+
+ if(getpwuid_r(uid, &pwent, pwbuf, sizeof pwbuf, &p))
+ return NULL;
+ return p;
+}
+
+struct passwd *getpwent(void)
+{
+ if (passwd_fp == NULL)
+ return NULL;
+ if (!scanpw(passwd_fp, &pwent, pwbuf, sizeof pwbuf))
+ return NULL;
+ return &pwent;
+}
+
+void setpwent(void)
+{
+ init_etc_passwd_group();
+
+ if (passwd_fp != NULL)
+ fclose(passwd_fp);
+ passwd_fp = fopen("/etc/passwd", "r");
+}
+
+void endpwent(void)
+{
+ if (passwd_fp != NULL)
+ fclose(passwd_fp);
+}
+
+/*
+ * Extract a single group record from the database
+ */
+static int scangr(
+ FILE *fp,
+ struct group *grp,
+ char *buffer,
+ size_t bufsize
+)
+{
+ int grgid;
+ char *grmem, *cp;
+ int memcount;
+
+ if (!scanString(fp, &grp->gr_name, &buffer, &bufsize, 0)
+ || !scanString(fp, &grp->gr_passwd, &buffer, &bufsize, 0)
+ || !scanInt(fp, &grgid)
+ || !scanString(fp, &grmem, &buffer, &bufsize, 1))
+ return 0;
+ grp->gr_gid = grgid;
+
+ /*
+ * Determine number of members
+ */
+ for (cp = grmem, memcount = 1 ; *cp != 0 ; cp++) {
+ if(*cp == ',')
+ memcount++;
+ }
+
+ /*
+ * Hack to produce (hopefully) a suitably-aligned array of pointers
+ */
+ if (bufsize < (((memcount+1)*sizeof(char *)) + 15))
+ return 0;
+ grp->gr_mem = (char **)(((uintptr_t)buffer + 15) & ~15);
+
+ /*
+ * Fill in pointer array
+ */
+ grp->gr_mem[0] = grmem;
+ for (cp = grmem, memcount = 1 ; *cp != 0 ; cp++) {
+ if(*cp == ',') {
+ *cp = '\0';
+ grp->gr_mem[memcount++] = cp + 1;
+ }
+ }
+ grp->gr_mem[memcount] = NULL;
+ return 1;
+}
+
+static int getgr_r(
+ const char *name,
+ int gid,
+ struct group *grp,
+ char *buffer,
+ size_t bufsize,
+ struct group **result
+)
+{
+ FILE *fp;
+ int match;
+
+ init_etc_passwd_group();
+
+ if ((fp = fopen("/etc/group", "r")) == NULL)
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ for(;;) {
+ if (!scangr(fp, grp, buffer, bufsize))
+ goto error_einval;
+
+ if (name) {
+ match = (strcmp(grp->gr_name, name) == 0);
+ } else {
+ match = (grp->gr_gid == gid);
+ }
+
+ if (match) {
+ fclose(fp);
+ *result = grp;
+ return 0;
+ }
+ }
+error_einval:
+ fclose(fp);
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
+
+int getgrnam_r(
+ const char *name,
+ struct group *grp,
+ char *buffer,
+ size_t bufsize,
+ struct group **result
+)
+{
+ return getgr_r(name, 0, grp, buffer, bufsize, result);
+}
+
+struct group *getgrnam(
+ const char *name
+)
+{
+ struct group *p;
+
+ if(getgrnam_r(name, &grent, grbuf, sizeof grbuf, &p))
+ return NULL;
+ return p;
+}
+
+int getgrgid_r(
+ gid_t gid,
+ struct group *grp,
+ char *buffer,
+ size_t bufsize,
+ struct group **result
+)
+{
+ return getgr_r(NULL, gid, grp, buffer, bufsize, result);
+}
+
+struct group *getgrgid(
+ gid_t gid
+)
+{
+ struct group *p;
+
+ if(getgrgid_r(gid, &grent, grbuf, sizeof grbuf, &p))
+ return NULL;
+ return p;
+}
+
+struct group *getgrent(void)
+{
+ if (group_fp == NULL)
+ return NULL;
+ if (!scangr(group_fp, &grent, grbuf, sizeof grbuf))
+ return NULL;
+ return &grent;
+}
+
+void setgrent(void)
+{
+ init_etc_passwd_group();
+
+ if (group_fp != NULL)
+ fclose(group_fp);
+ group_fp = fopen("/etc/group", "r");
+}
+
+void endgrent(void)
+{
+ if (group_fp != NULL)
+ fclose(group_fp);
+}
diff --git a/cpukit/libcsupport/src/getrusage.c b/cpukit/libcsupport/src/getrusage.c
new file mode 100644
index 0000000000..df68376e50
--- /dev/null
+++ b/cpukit/libcsupport/src/getrusage.c
@@ -0,0 +1,54 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/resource.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/seterr.h>
+
+int getrusage(int who, struct rusage *usage)
+{
+ struct timespec uptime;
+ struct timeval rtime;
+
+ if ( !usage )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ /*
+ * RTEMS only has a single process so there are no children.
+ * The single process has been running since the system
+ * was booted and since there is no distinction between system
+ * and user time, we will just report the uptime.
+ */
+ if (who == RUSAGE_SELF) {
+ rtems_clock_get_uptime( &uptime );
+
+ rtime.tv_sec = uptime.tv_sec;
+ rtime.tv_usec = uptime.tv_nsec / 1000;
+
+ usage->ru_utime = rtime;
+ usage->ru_stime = rtime;
+
+ return 0;
+ }
+
+ if (who == RUSAGE_CHILDREN) {
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
+
diff --git a/cpukit/libcsupport/src/getuid.c b/cpukit/libcsupport/src/getuid.c
new file mode 100644
index 0000000000..d3a13192fa
--- /dev/null
+++ b/cpukit/libcsupport/src/getuid.c
@@ -0,0 +1,28 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/userenv.h>
+
+/*
+ * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs,
+ * P1003.1b-1993, p. 84
+ */
+uid_t getuid( void )
+{
+ return _POSIX_types_Uid;
+}
+
diff --git a/cpukit/libcsupport/src/gxx_wrappers.c b/cpukit/libcsupport/src/gxx_wrappers.c
new file mode 100644
index 0000000000..e3d300a9f2
--- /dev/null
+++ b/cpukit/libcsupport/src/gxx_wrappers.c
@@ -0,0 +1,295 @@
+/*
+ * RTEMS threads compatibility routines for libgcc2.
+ *
+ * by: Rosimildo da Silva (rdasilva@connecttel.com)
+ *
+ * Used ideas from:
+ * W. Eric Norum
+ * Canadian Light Source
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@cls.usask.ca
+ *
+ * Eric sent some e-mail in the rtems-list as a start point for this
+ * module implementation.
+ *
+ * $Id$
+ */
+
+/*
+ * This file is only used if using gcc
+ */
+#if defined(__GNUC__)
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/gxx_wrappers.h>
+
+#include <stdlib.h>
+
+#include <rtems.h>
+
+/* uncomment this if you need to debug this interface */
+/*#define DEBUG_GXX_WRAPPERS 1*/
+
+int rtems_gxx_once(__gthread_once_t *once, void (*func) (void))
+{
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: once=%x, func=%x\n", *once, func );
+ #endif
+
+ if ( *(volatile __gthread_once_t *)once == 0 ) {
+ rtems_mode saveMode;
+ __gthread_once_t o;
+
+ rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &saveMode);
+ if ( (o = *(volatile __gthread_once_t *)once) == 0 ) {
+ *(volatile __gthread_once_t *)once = 1;
+ }
+ rtems_task_mode(saveMode, RTEMS_PREEMPT_MASK, &saveMode);
+ if ( o == 0 )
+ (*func)();
+ }
+ return 0;
+}
+
+int rtems_gxx_key_create (__gthread_key_t *key, void (*dtor) (void *))
+{
+ rtems_status_code status;
+
+ /* Ok, this can be a bit tricky. We are going to return a "key" as a
+ * pointer to the buffer that will hold the value of the key itself.
+ * We have to to this, because the others functions on this interface
+ * deal with the value of the key, as used with the POSIX API.
+ */
+ /* Do not pull your hair, trust me this works. :-) */
+ __gthread_key_t new_key = (__gthread_key_t) malloc( sizeof( *new_key ) );
+ *key = new_key;
+ new_key->val = NULL;
+ new_key->dtor = dtor;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk(
+ "gxx_wrappers: create key=%x, dtor=%x, new_key=%x\n", key, dtor, new_key
+ );
+ #endif
+
+ /* register with RTEMS the buffer that will hold the key values */
+ status = rtems_task_variable_add( RTEMS_SELF, (void **)new_key, dtor );
+ if ( status == RTEMS_SUCCESSFUL )
+ return 0;
+
+ free( new_key );
+ return -1;
+}
+
+int rtems_gxx_key_dtor (__gthread_key_t key, void *ptr)
+{
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: dtor key=%x, ptr=%x\n", key, ptr );
+ #endif
+
+ key->val = 0;
+ return 0;
+}
+
+int rtems_gxx_key_delete (__gthread_key_t key)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: delete key=%x\n", key );
+ #endif
+
+ /* register with RTEMS the buffer that will hold the key values */
+ status = rtems_task_variable_delete( RTEMS_SELF, (void **)key );
+ if ( status == RTEMS_SUCCESSFUL ) {
+ /* Hmm - hopefully all tasks using this key have gone away... */
+ if ( key ) free( *(void **)key );
+ return 0;
+ }
+ key = NULL;
+ return 0;
+}
+
+void *rtems_gxx_getspecific(__gthread_key_t key)
+{
+ rtems_status_code status;
+ void *p= 0;
+
+ /* register with RTEMS the buffer that will hold the key values */
+ status = rtems_task_variable_get( RTEMS_SELF, (void **)key, &p );
+ if ( status == RTEMS_SUCCESSFUL ) {
+ /* We do not have to do this, but what the heck ! */
+ p= key->val;
+ } else {
+ /* fisrt time, always set to zero, it is unknown the value that the others
+ * threads are using at the moment of this call
+ */
+ status = rtems_task_variable_add( RTEMS_SELF, (void **)key, key->dtor );
+ if ( status != RTEMS_SUCCESSFUL ) {
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_GXX_KEY_ADD_FAILED
+ );
+ }
+ key->val = (void *)0;
+ }
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk(
+ "gxx_wrappers: getspecific key=%x, ptr=%x, id=%x\n",
+ key,
+ p,
+ rtems_task_self()
+ );
+ #endif
+ return p;
+}
+
+int rtems_gxx_setspecific(__gthread_key_t key, const void *ptr)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk(
+ "gxx_wrappers: setspecific key=%x, ptr=%x, id=%x\n",
+ key,
+ ptr,
+ rtems_task_self()
+ );
+ #endif
+
+ /* register with RTEMS the buffer that will hold the key values */
+ status = rtems_task_variable_add( RTEMS_SELF, (void **)key, key->dtor );
+ if ( status == RTEMS_SUCCESSFUL ) {
+ /* now let's set the proper value */
+ key->val = (void *)ptr;
+ return 0;
+ }
+ return -1;
+}
+
+
+/*
+ * MUTEX support
+ */
+void rtems_gxx_mutex_init (__gthread_mutex_t *mutex)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: mutex init =%X\n", *mutex );
+ #endif
+
+ status = rtems_semaphore_create(
+ rtems_build_name ('G', 'C', 'C', '2'),
+ 1,
+ RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|
+ RTEMS_INHERIT_PRIORITY|RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
+ 0,
+ (rtems_id *)mutex
+ );
+ if ( status != RTEMS_SUCCESSFUL ) {
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk(
+ "gxx_wrappers: mutex init failed %s (%d)\n",
+ rtems_status_text(status),
+ status
+ );
+ #endif
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED
+ );
+ }
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: mutex init complete =%X\n", *mutex );
+ #endif
+}
+
+int rtems_gxx_mutex_lock (__gthread_mutex_t *mutex)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: lock mutex=%X\n", *mutex );
+ #endif
+
+ status = rtems_semaphore_obtain(
+ *(rtems_id *)mutex,
+ RTEMS_WAIT,
+ RTEMS_NO_TIMEOUT
+ );
+ if ( status == RTEMS_SUCCESSFUL )
+ return 0;
+ return -1;
+}
+
+int rtems_gxx_mutex_destroy (__gthread_mutex_t *mutex)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: destroy mutex=%X\n", *mutex );
+ #endif
+
+ status = rtems_semaphore_delete(*(rtems_id *)mutex);
+ if ( status == RTEMS_SUCCESSFUL )
+ return 0;
+ return -1;
+}
+
+int rtems_gxx_mutex_trylock (__gthread_mutex_t *mutex)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: trylock mutex=%X\n", *mutex );
+ #endif
+
+ status = rtems_semaphore_obtain (*(rtems_id *)mutex, RTEMS_NO_WAIT, 0);
+ if ( status == RTEMS_SUCCESSFUL )
+ return 0;
+ return -1;
+}
+
+int rtems_gxx_mutex_unlock (__gthread_mutex_t *mutex)
+{
+ rtems_status_code status;
+
+ #ifdef DEBUG_GXX_WRAPPERS
+ printk( "gxx_wrappers: unlock mutex=%X\n", *mutex );
+ #endif
+
+ status = rtems_semaphore_release( *(rtems_id *)mutex );
+ if ( status == RTEMS_SUCCESSFUL )
+ return 0;
+ return -1;
+}
+
+void rtems_gxx_recursive_mutex_init(__gthread_recursive_mutex_t *mutex)
+{
+ rtems_gxx_mutex_init(mutex);
+}
+
+int rtems_gxx_recursive_mutex_lock(__gthread_recursive_mutex_t *mutex)
+{
+ return rtems_gxx_mutex_lock(mutex);
+}
+
+int rtems_gxx_recursive_mutex_trylock(__gthread_recursive_mutex_t *mutex)
+{
+ return rtems_gxx_mutex_trylock(mutex);
+}
+
+int rtems_gxx_recursive_mutex_unlock(__gthread_recursive_mutex_t *mutex)
+{
+ return rtems_gxx_mutex_unlock(mutex);
+}
+
+#endif /* __GNUC__ */
diff --git a/cpukit/libcsupport/src/ioctl.c b/cpukit/libcsupport/src/ioctl.c
new file mode 100644
index 0000000000..ae8a88bd77
--- /dev/null
+++ b/cpukit/libcsupport/src/ioctl.c
@@ -0,0 +1,54 @@
+/*
+ * ioctl() system call
+ *
+ * This routine is not defined in the POSIX 1003.1b standard but is
+ * commonly supported on most UNIX and POSIX systems.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#include <unistd.h>
+
+int ioctl(
+ int fd,
+ ioctl_command_t command,
+ ...
+)
+{
+ va_list ap;
+ rtems_status_code rc;
+ rtems_libio_t *iop;
+ void *buffer;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ va_start(ap, command);
+
+ buffer = va_arg(ap, void *);
+
+ /*
+ * Now process the ioctl().
+ */
+ rc = (*iop->pathinfo.handlers->ioctl_h)( iop, command, buffer );
+
+ va_end( ap );
+ return rc;
+}
diff --git a/cpukit/libcsupport/src/isatty.c b/cpukit/libcsupport/src/isatty.c
new file mode 100644
index 0000000000..b29ce7b53d
--- /dev/null
+++ b/cpukit/libcsupport/src/isatty.c
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_ISATTY
+
+#include <sys/stat.h>
+
+int isatty(
+ int fd
+)
+{
+ struct stat buf;
+
+ if (fstat (fd, &buf) < 0)
+ return 0;
+
+ if (S_ISCHR (buf.st_mode))
+ return 1;
+
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/isatty_r.c b/cpukit/libcsupport/src/isatty_r.c
new file mode 100644
index 0000000000..3e2e2baa14
--- /dev/null
+++ b/cpukit/libcsupport/src/isatty_r.c
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * _isatty_r
+ *
+ * This is the Newlib dependent reentrant version of isatty().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__ISATTY_R)
+
+#include <unistd.h>
+#include <reent.h>
+#include <sys/stat.h>
+
+int _isatty_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd
+)
+{
+ return isatty( fd );
+}
+#endif
diff --git a/cpukit/libcsupport/src/issetugid.c b/cpukit/libcsupport/src/issetugid.c
new file mode 100644
index 0000000000..84a2d9ce61
--- /dev/null
+++ b/cpukit/libcsupport/src/issetugid.c
@@ -0,0 +1,16 @@
+/*
+ * Dummy version of BSD routine
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_ISSETUGID)
+int issetugid (void)
+{
+ return 0;
+}
+#endif
diff --git a/cpukit/libcsupport/src/kill_noposix.c b/cpukit/libcsupport/src/kill_noposix.c
new file mode 100644
index 0000000000..8b7898b3f8
--- /dev/null
+++ b/cpukit/libcsupport/src/kill_noposix.c
@@ -0,0 +1,48 @@
+/*
+ * Marginal implementations of some POSIX API routines
+ * to be used when POSIX is disabled.
+ *
+ * + kill
+ * + _kill_r
+ * + __kill
+ * + sleep
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <unistd.h>
+
+/*
+ * These are directly supported (and completely correct) in the posix api.
+ */
+
+#if !defined(RTEMS_POSIX_API)
+int kill( pid_t pid, int sig )
+{
+ return 0;
+}
+
+#if defined(RTEMS_NEWLIB)
+#include <reent.h>
+
+int _kill_r( struct _reent *ptr, pid_t pid, int sig )
+{
+ return 0;
+}
+#endif
+
+int __kill( pid_t pid, int sig )
+{
+ return 0;
+}
+#endif
diff --git a/cpukit/libcsupport/src/lchown.c b/cpukit/libcsupport/src/lchown.c
new file mode 100644
index 0000000000..c244e08879
--- /dev/null
+++ b/cpukit/libcsupport/src/lchown.c
@@ -0,0 +1,31 @@
+/*
+ * lchown() - POSIX 1003.1b 5.6.5 - Change Owner and Group of a File
+ * But Do Not Follow a Symlink
+ *
+ * Written by: Vinu Rajashekhar <vinutheraj@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/stat.h>
+
+#include <rtems.h>
+
+int _chown_helper( const char *path, uid_t owner, gid_t group, int follow_link);
+
+int lchown(
+ const char *path,
+ uid_t owner,
+ gid_t group
+)
+{
+ return _chown_helper( path, owner, group, false );
+}
diff --git a/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c
new file mode 100644
index 0000000000..d080d01596
--- /dev/null
+++ b/cpukit/libcsupport/src/libio.c
@@ -0,0 +1,278 @@
+/*
+ * This file contains the support infrastructure used to manage the
+ * table of integer style file descriptors used by the low level
+ * POSIX system calls like open(), read, fstat(), etc.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <rtems/assoc.h>
+
+/* define this to alias O_NDELAY to O_NONBLOCK, i.e.,
+ * O_NDELAY is accepted on input but fcntl(F_GETFL) returns
+ * O_NONBLOCK. This is because rtems has no distinction
+ * between the two (but some systems have).
+ * Note that accepting this alias creates a problem:
+ * an application trying to clear the non-blocking flag
+ * using a
+ *
+ * fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NDELAY);
+ *
+ * does (silently) ignore the operation.
+ */
+#undef ACCEPT_O_NDELAY_ALIAS
+
+/*
+ * rtems_libio_fcntl_flags
+ *
+ * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand
+ */
+
+const rtems_assoc_t access_modes_assoc[] = {
+ { "READ", LIBIO_FLAGS_READ, O_RDONLY },
+ { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY },
+ { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR },
+ { 0, 0, 0 },
+};
+
+const rtems_assoc_t status_flags_assoc[] = {
+#ifdef ACCEPT_O_NDELAY_ALIAS
+ { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY },
+#endif
+ { "NONBLOCK", LIBIO_FLAGS_NO_DELAY, O_NONBLOCK },
+ { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND },
+ { "CREATE", LIBIO_FLAGS_CREATE, O_CREAT },
+ { 0, 0, 0 },
+};
+
+uint32_t rtems_libio_fcntl_flags(
+ uint32_t fcntl_flags
+)
+{
+ uint32_t flags = 0;
+ uint32_t access_modes;
+
+ /*
+ * Access mode is a small integer
+ */
+
+ access_modes = fcntl_flags & O_ACCMODE;
+ fcntl_flags &= ~O_ACCMODE;
+ flags = rtems_assoc_local_by_remote( access_modes_assoc, access_modes );
+
+ /*
+ * Everything else is single bits
+ */
+
+ flags |=
+ rtems_assoc_local_by_remote_bitfield(status_flags_assoc, fcntl_flags);
+ return flags;
+}
+
+/*
+ * rtems_libio_to_fcntl_flags
+ *
+ * Convert RTEMS internal flags to UNIX fnctl(2) flags
+ */
+
+uint32_t rtems_libio_to_fcntl_flags(
+ uint32_t flags
+)
+{
+ uint32_t fcntl_flags = 0;
+
+ if ( (flags & LIBIO_FLAGS_READ_WRITE) == LIBIO_FLAGS_READ_WRITE ) {
+ fcntl_flags |= O_RDWR;
+ } else if ( (flags & LIBIO_FLAGS_READ) == LIBIO_FLAGS_READ) {
+ fcntl_flags |= O_RDONLY;
+ } else if ( (flags & LIBIO_FLAGS_WRITE) == LIBIO_FLAGS_WRITE) {
+ fcntl_flags |= O_WRONLY;
+ }
+
+ if ( (flags & LIBIO_FLAGS_NO_DELAY) == LIBIO_FLAGS_NO_DELAY ) {
+ fcntl_flags |= O_NONBLOCK;
+ }
+
+ if ( (flags & LIBIO_FLAGS_APPEND) == LIBIO_FLAGS_APPEND ) {
+ fcntl_flags |= O_APPEND;
+ }
+
+ if ( (flags & LIBIO_FLAGS_CREATE) == LIBIO_FLAGS_CREATE ) {
+ fcntl_flags |= O_CREAT;
+ }
+
+ return fcntl_flags;
+}
+
+/*
+ * rtems_libio_allocate
+ *
+ * This routine searches the IOP Table for an unused entry. If it
+ * finds one, it returns it. Otherwise, it returns NULL.
+ */
+
+rtems_libio_t *rtems_libio_allocate( void )
+{
+ rtems_libio_t *iop, *next;
+ rtems_status_code rc;
+ rtems_id sema;
+
+ rtems_libio_lock();
+
+ if (rtems_libio_iop_freelist) {
+ rc = rtems_semaphore_create(
+ RTEMS_LIBIO_IOP_SEM(rtems_libio_iop_freelist - rtems_libio_iops),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ 0,
+ &sema
+ );
+ if (rc != RTEMS_SUCCESSFUL)
+ goto failed;
+ iop = rtems_libio_iop_freelist;
+ next = iop->data1;
+ (void) memset( iop, 0, sizeof(rtems_libio_t) );
+ iop->flags = LIBIO_FLAGS_OPEN;
+ iop->sem = sema;
+ rtems_libio_iop_freelist = next;
+ goto done;
+ }
+
+failed:
+ iop = 0;
+
+done:
+ rtems_libio_unlock();
+ return iop;
+}
+
+/*
+ * rtems_libio_free
+ *
+ * This routine frees the resources associated with an IOP (file descriptor)
+ * and clears the slot in the IOP Table.
+ */
+
+void rtems_libio_free(
+ rtems_libio_t *iop
+)
+{
+ rtems_libio_lock();
+
+ if (iop->sem)
+ rtems_semaphore_delete(iop->sem);
+
+ iop->flags &= ~LIBIO_FLAGS_OPEN;
+ iop->data1 = rtems_libio_iop_freelist;
+ rtems_libio_iop_freelist = iop;
+
+ rtems_libio_unlock();
+}
+
+/*
+ * rtems_libio_is_open_files_in_fs
+ *
+ * This routine scans the entire file descriptor table to determine if the
+ * are any active file descriptors that refer to the at least one node in the
+ * file system that we are trying to dismount.
+ *
+ * If there is at least one node in the file system referenced by the mount
+ * table entry a 1 is returned, otherwise a 0 is returned.
+ */
+
+int rtems_libio_is_open_files_in_fs(
+ rtems_filesystem_mount_table_entry_t * fs_mt_entry
+)
+{
+ rtems_libio_t *iop;
+ int result = 0;
+ uint32_t i;
+
+ rtems_libio_lock();
+
+ /*
+ * Look for any active file descriptor entry.
+ */
+
+ for (iop=rtems_libio_iops,i=0; i < rtems_libio_number_iops; iop++, i++){
+
+ if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) {
+
+ /*
+ * Check if this node is under the file system that we
+ * are trying to dismount.
+ */
+
+ if ( iop->pathinfo.mt_entry == fs_mt_entry ) {
+ result = 1;
+ break;
+ }
+ }
+ }
+
+ rtems_libio_unlock();
+
+ return result;
+}
+
+/*
+ * rtems_libio_is_file_open
+ *
+ * This routine scans the entire file descriptor table to determine if the
+ * given file refers to an active file descriptor.
+ *
+ * If the given file is open a 1 is returned, otherwise a 0 is returned.
+ */
+
+int rtems_libio_is_file_open(
+ void *node_access
+)
+{
+ rtems_libio_t *iop;
+ int result=0;
+ uint32_t i;
+
+ rtems_libio_lock();
+
+ /*
+ * Look for any active file descriptor entry.
+ */
+
+ for (iop=rtems_libio_iops,i=0; i < rtems_libio_number_iops; iop++, i++){
+ if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) {
+
+ /*
+ * Check if this node is under the file system that we
+ * are trying to dismount.
+ */
+
+ if ( iop->pathinfo.node_access == node_access ) {
+ result = 1;
+ break;
+ }
+ }
+ }
+
+ rtems_libio_unlock();
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/libio_init.c b/cpukit/libcsupport/src/libio_init.c
new file mode 100644
index 0000000000..a6b99870a5
--- /dev/null
+++ b/cpukit/libcsupport/src/libio_init.c
@@ -0,0 +1,89 @@
+/*
+ * This file contains the support infrastructure used to manage the
+ * table of integer style file descriptors used by the low level
+ * POSIX system calls like open(), read, fstat(), etc.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h> /* libio_.h pulls in rtems */
+#include <rtems.h>
+#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
+
+#include <stdio.h> /* O_RDONLY, et.al. */
+#include <fcntl.h> /* O_RDONLY, et.al. */
+#include <errno.h>
+
+#include <errno.h>
+#include <string.h> /* strcmp */
+#include <unistd.h>
+#include <stdlib.h> /* calloc() */
+
+#include <rtems/libio.h> /* libio.h not pulled in by rtems */
+
+/*
+ * File descriptor Table Information
+ */
+
+rtems_id rtems_libio_semaphore;
+rtems_libio_t *rtems_libio_iops;
+rtems_libio_t *rtems_libio_iop_freelist;
+
+/*
+ * rtems_libio_init
+ *
+ * Called by BSP startup code to initialize the libio subsystem.
+ */
+
+void rtems_libio_init( void )
+{
+ rtems_status_code rc;
+ uint32_t i;
+ rtems_libio_t *iop;
+
+ if (rtems_libio_number_iops > 0)
+ {
+ rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops,
+ sizeof(rtems_libio_t));
+ if (rtems_libio_iops == NULL)
+ rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
+
+ iop = rtems_libio_iop_freelist = rtems_libio_iops;
+ for (i = 0 ; (i + 1) < rtems_libio_number_iops ; i++, iop++)
+ iop->data1 = iop + 1;
+ iop->data1 = NULL;
+ }
+
+ /*
+ * Create the binary semaphore used to provide mutual exclusion
+ * on the IOP Table.
+ */
+
+ rc = rtems_semaphore_create(
+ RTEMS_LIBIO_SEM,
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &rtems_libio_semaphore
+ );
+ if ( rc != RTEMS_SUCCESSFUL )
+ rtems_fatal_error_occurred( rc );
+
+ /*
+ * Initialize the base file system infrastructure.
+ */
+
+ if (rtems_fs_init_helper)
+ (* rtems_fs_init_helper)();
+}
diff --git a/cpukit/libcsupport/src/libio_sockets.c b/cpukit/libcsupport/src/libio_sockets.c
new file mode 100644
index 0000000000..c67e19d78c
--- /dev/null
+++ b/cpukit/libcsupport/src/libio_sockets.c
@@ -0,0 +1,73 @@
+/*
+ * This file contains the support infrastructure used to manage the
+ * table of integer style file descriptors used by the socket calls.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+/*
+ * Convert an RTEMS file descriptor to a BSD socket pointer.
+ */
+
+struct socket *rtems_bsdnet_fdToSocket(
+ int fd
+)
+{
+ rtems_libio_t *iop;
+
+ /* same as rtems_libio_check_fd(_fd) but different return */
+ if ((uint32_t)fd >= rtems_libio_number_iops) {
+ errno = EBADF;
+ return NULL;
+ }
+ iop = &rtems_libio_iops[fd];
+
+ /* same as rtems_libio_check_is_open(iop) but different return */
+ if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) {
+ errno = EBADF;
+ return NULL;
+ }
+
+ if (iop->data1 == NULL)
+ errno = EBADF;
+ return iop->data1;
+}
+
+/*
+ * Create an RTEMS file descriptor for a socket
+ */
+
+int rtems_bsdnet_makeFdForSocket(
+ void *so,
+ const rtems_filesystem_file_handlers_r *h
+)
+{
+ rtems_libio_t *iop;
+ int fd;
+
+ iop = rtems_libio_allocate();
+ if (iop == 0)
+ rtems_set_errno_and_return_minus_one( ENFILE );
+
+ fd = iop - rtems_libio_iops;
+ iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
+ iop->data0 = fd;
+ iop->data1 = so;
+ iop->pathinfo.handlers = h;
+ iop->pathinfo.ops = &rtems_filesystem_operations_default;
+ return fd;
+}
diff --git a/cpukit/libcsupport/src/link.c b/cpukit/libcsupport/src/link.c
new file mode 100644
index 0000000000..11b6521dea
--- /dev/null
+++ b/cpukit/libcsupport/src/link.c
@@ -0,0 +1,94 @@
+/*
+ * link() - POSIX 1003.1b - 5.3.4 - Create a new link
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int link(
+ const char *existing,
+ const char *new
+)
+{
+ rtems_filesystem_location_info_t existing_loc;
+ rtems_filesystem_location_info_t parent_loc;
+ int i;
+ int result;
+ const char *name_start;
+
+ /*
+ * Get the node we are linking to.
+ */
+
+ result = rtems_filesystem_evaluate_path( existing, strlen( existing ),
+ 0, &existing_loc, true );
+ if ( result != 0 )
+ return -1;
+
+ /*
+ * Get the parent of the node we are creating.
+ */
+
+ rtems_filesystem_get_start_loc( new, &i, &parent_loc );
+
+ result = (*parent_loc.ops->evalformake_h)( &new[i], &parent_loc, &name_start );
+ if ( result != 0 ) {
+ rtems_filesystem_freenode( &existing_loc );
+ return -1;
+ }
+
+ /*
+ * Check to see if the caller is trying to link across file system
+ * boundaries.
+ */
+
+ if ( parent_loc.mt_entry != existing_loc.mt_entry ) {
+ rtems_filesystem_freenode( &existing_loc );
+ rtems_filesystem_freenode( &parent_loc );
+ rtems_set_errno_and_return_minus_one( EXDEV );
+ }
+
+ result = (*parent_loc.ops->link_h)( &existing_loc, &parent_loc, name_start );
+
+ rtems_filesystem_freenode( &existing_loc );
+ rtems_filesystem_freenode( &parent_loc );
+
+ return result;
+}
+
+/*
+ * _link_r
+ *
+ * This is the Newlib dependent reentrant version of link().
+ */
+
+#if defined(RTEMS_NEWLIB)
+
+#include <reent.h>
+
+int _link_r(
+ struct _reent *ptr __attribute__((unused)),
+ const char *existing,
+ const char *new
+)
+{
+ return link( existing, new );
+}
+#endif
diff --git a/cpukit/libcsupport/src/lseek.c b/cpukit/libcsupport/src/lseek.c
new file mode 100644
index 0000000000..3f37029807
--- /dev/null
+++ b/cpukit/libcsupport/src/lseek.c
@@ -0,0 +1,94 @@
+/*
+ * lseek() - POSIX 1003.1b 6.5.3 - Reposition Read/Write File Offset
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+off_t lseek(
+ int fd,
+ off_t offset,
+ int whence
+)
+{
+ rtems_libio_t *iop;
+ off_t old_offset;
+ off_t status;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open(iop);
+
+ /*
+ * Now process the lseek().
+ */
+
+ old_offset = iop->offset;
+ switch ( whence ) {
+ case SEEK_SET:
+ iop->offset = offset;
+ break;
+
+ case SEEK_CUR:
+ iop->offset += offset;
+ break;
+
+ case SEEK_END:
+ iop->offset = iop->size + offset;
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ /*
+ * At this time, handlers assume iop->offset has the desired
+ * new offset.
+ */
+
+ status = (*iop->pathinfo.handlers->lseek_h)( iop, offset, whence );
+ if ( status == (off_t) -1 )
+ iop->offset = old_offset;
+
+ /*
+ * So if the operation failed, we have to restore iop->offset.
+ */
+
+ return status;
+}
+
+/*
+ * _lseek_r
+ *
+ * This is the Newlib dependent reentrant version of lseek().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__LSEEK_R)
+
+#include <reent.h>
+
+off_t _lseek_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd,
+ off_t offset,
+ int whence
+)
+{
+ return lseek( fd, offset, whence );
+}
+#endif
diff --git a/cpukit/libcsupport/src/lstat.c b/cpukit/libcsupport/src/lstat.c
new file mode 100644
index 0000000000..f034f4aa76
--- /dev/null
+++ b/cpukit/libcsupport/src/lstat.c
@@ -0,0 +1,22 @@
+/*
+ * lstat() - BSD 4.3 and SVR4 - Get File Status
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _STAT_NAME lstat
+#define _STAT_R_NAME _lstat_r
+#define _STAT_FOLLOW_LINKS false
+
+#include "stat.c"
diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c
new file mode 100644
index 0000000000..6bb77a4630
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc.c
@@ -0,0 +1,83 @@
+/*
+ * RTEMS Malloc Family Implementation
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include <stdlib.h>
+#include <errno.h>
+
+#include "malloc_p.h"
+
+void *malloc(
+ size_t size
+)
+{
+ void *return_this;
+
+ MSBUMP(malloc_calls, 1);
+
+ /*
+ * If some free's have been deferred, then do them now.
+ */
+ malloc_deferred_frees_process();
+
+ /*
+ * Validate the parameters
+ */
+ if ( !size )
+ return (void *) 0;
+
+ /*
+ * Do not attempt to allocate memory if not in correct system state.
+ */
+ if ( _System_state_Is_up(_System_state_Get()) &&
+ !malloc_is_system_state_OK() )
+ return NULL;
+
+ /*
+ * Try to give a segment in the current heap if there is not
+ * enough space then try to grow the heap.
+ * If this fails then return a NULL pointer.
+ */
+
+ return_this = _Protected_heap_Allocate( RTEMS_Malloc_Heap, size );
+
+ if ( !return_this ) {
+ if (rtems_malloc_sbrk_helpers)
+ return_this = (*rtems_malloc_sbrk_helpers->extend)( size );
+ if ( !return_this ) {
+ errno = ENOMEM;
+ return (void *) 0;
+ }
+ }
+
+ /*
+ * If the user wants us to dirty the allocated memory, then do it.
+ */
+ if ( rtems_malloc_dirty_helper )
+ (*rtems_malloc_dirty_helper)( return_this, size );
+
+ /*
+ * If configured, update the statistics
+ */
+ if ( rtems_malloc_statistics_helpers )
+ (*rtems_malloc_statistics_helpers->at_malloc)(return_this);
+
+ return return_this;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c
new file mode 100644
index 0000000000..4289a899bc
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_deferred.c
@@ -0,0 +1,60 @@
+/*
+ * Process free requests deferred because they were from ISR
+ * or other critical section.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include <stdlib.h>
+#include <errno.h>
+
+#include "malloc_p.h"
+
+rtems_chain_control RTEMS_Malloc_GC_list;
+
+bool malloc_is_system_state_OK(void)
+{
+ if ( _Thread_Dispatch_disable_level > 0 )
+ return false;
+
+ if ( _ISR_Nest_level > 0 )
+ return false;
+
+ return true;
+}
+
+void malloc_deferred_frees_initialize(void)
+{
+ rtems_chain_initialize_empty(&RTEMS_Malloc_GC_list);
+}
+
+void malloc_deferred_frees_process(void)
+{
+ rtems_chain_node *to_be_freed;
+
+ /*
+ * If some free's have been deferred, then do them now.
+ */
+ while ((to_be_freed = rtems_chain_get(&RTEMS_Malloc_GC_list)) != NULL)
+ free(to_be_freed);
+}
+
+void malloc_deferred_free(
+ void *pointer
+)
+{
+ rtems_chain_append(&RTEMS_Malloc_GC_list, (rtems_chain_node *)pointer);
+}
+#endif
diff --git a/cpukit/libcsupport/src/malloc_dirtier.c b/cpukit/libcsupport/src/malloc_dirtier.c
new file mode 100644
index 0000000000..eb6ae7ccf3
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_dirtier.c
@@ -0,0 +1,30 @@
+/*
+ * RTEMS Malloc Family -- Dirty Memory from Malloc
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/malloc.h>
+#include "malloc_p.h"
+
+#include <errno.h>
+
+void rtems_malloc_dirty_memory(
+ void *start,
+ size_t size
+)
+{
+ (void) memset(start, 0xCF, size);
+}
diff --git a/cpukit/libcsupport/src/malloc_get_statistics.c b/cpukit/libcsupport/src/malloc_get_statistics.c
new file mode 100644
index 0000000000..c13a1555e8
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_get_statistics.c
@@ -0,0 +1,33 @@
+/*
+ * malloc_get_statistics Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+int malloc_get_statistics(
+ rtems_malloc_statistics_t *stats
+)
+{
+ if ( !stats )
+ return -1;
+ _RTEMS_Lock_allocator();
+ *stats = rtems_malloc_statistics;
+ _RTEMS_Unlock_allocator();
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/malloc_initialize.c b/cpukit/libcsupport/src/malloc_initialize.c
new file mode 100644
index 0000000000..e00a868e5a
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_initialize.c
@@ -0,0 +1,114 @@
+/**
+ * @file
+ *
+ * @brief Malloc initialization implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/malloc.h>
+#include <rtems/score/wkspace.h>
+#include "malloc_p.h"
+
+/* FIXME: Dummy function */
+#ifndef RTEMS_NEWLIB
+void RTEMS_Malloc_Initialize(
+ void *heap_begin,
+ uintptr_t heap_size,
+ size_t sbrk_amount
+)
+{
+}
+#else
+rtems_malloc_statistics_t rtems_malloc_statistics;
+extern bool rtems_unified_work_area;
+
+void RTEMS_Malloc_Initialize(
+ void *heap_begin,
+ uintptr_t heap_size,
+ size_t sbrk_amount
+)
+{
+ /*
+ * If configured, initialize the statistics support
+ */
+ if ( rtems_malloc_statistics_helpers != NULL ) {
+ (*rtems_malloc_statistics_helpers->initialize)();
+ }
+
+ /*
+ * Initialize the garbage collection list to start with nothing on it.
+ */
+ malloc_deferred_frees_initialize();
+
+ /*
+ * Initialize the optional sbrk support for extending the heap
+ */
+ if ( rtems_malloc_sbrk_helpers != NULL ) {
+ heap_begin = (*rtems_malloc_sbrk_helpers->initialize)(
+ heap_begin,
+ sbrk_amount
+ );
+ heap_size = (uintptr_t) sbrk_amount;
+ }
+
+ /*
+ * If this system is configured to use the same heap for
+ * the RTEMS Workspace and C Program Heap, then we need to
+ * be very very careful about destroying the initialization
+ * that has already been done.
+ */
+
+ /*
+ * If the BSP is not clearing out the workspace, then it is most likely
+ * not clearing out the initial memory for the heap. There is no
+ * standard supporting zeroing out the heap memory. But much code
+ * with UNIX history seems to assume that memory malloc'ed during
+ * initialization (before any free's) is zero'ed. This is true most
+ * of the time under UNIX because zero'ing memory when it is first
+ * given to a process eliminates the chance of a process seeing data
+ * left over from another process. This would be a security violation.
+ */
+
+ if (
+ !rtems_unified_work_area
+ && rtems_configuration_get_do_zero_of_workspace()
+ ) {
+ memset( heap_begin, 0, heap_size );
+ }
+
+ /*
+ * Unfortunately we cannot use assert if this fails because if this
+ * has failed we do not have a heap and if we do not have a heap
+ * STDIO cannot work because there will be no buffers.
+ */
+
+ if ( !rtems_unified_work_area ) {
+ uintptr_t status = _Protected_heap_Initialize(
+ RTEMS_Malloc_Heap,
+ heap_begin,
+ heap_size,
+ CPU_HEAP_ALIGNMENT
+ );
+ if ( status == 0 ) {
+ rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
+ }
+ }
+
+ MSBUMP( space_available, _Protected_heap_Get_size(RTEMS_Malloc_Heap) );
+}
+#endif
diff --git a/cpukit/libcsupport/src/malloc_p.h b/cpukit/libcsupport/src/malloc_p.h
new file mode 100644
index 0000000000..f93f0b9287
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_p.h
@@ -0,0 +1,45 @@
+/*
+ * RTEMS Malloc Family Internal Header
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+#include <rtems/score/protectedheap.h>
+#include <rtems/malloc.h>
+
+#ifdef RTEMS_NEWLIB
+#include <sys/reent.h>
+#endif
+
+#include <stdint.h>
+#include <rtems/chain.h>
+
+/*
+ * Basic management data
+ */
+extern Heap_Control *RTEMS_Malloc_Heap;
+
+/*
+ * Malloc Statistics Structure
+ */
+extern rtems_malloc_statistics_t rtems_malloc_statistics;
+
+#define MSBUMP(_f,_n) rtems_malloc_statistics._f += (_n)
+
+/*
+ * Process deferred free operations
+ */
+bool malloc_is_system_state_OK(void);
+void malloc_deferred_frees_initialize(void);
+void malloc_deferred_frees_process(void);
+void malloc_deferred_free(void *);
diff --git a/cpukit/libcsupport/src/malloc_report_statistics.c b/cpukit/libcsupport/src/malloc_report_statistics.c
new file mode 100644
index 0000000000..24f5505429
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_report_statistics.c
@@ -0,0 +1,26 @@
+/*
+ * malloc_report_statistics Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+void malloc_report_statistics(void)
+{
+ malloc_report_statistics_with_plugin( NULL, printk_plugin );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/malloc_report_statistics_plugin.c b/cpukit/libcsupport/src/malloc_report_statistics_plugin.c
new file mode 100644
index 0000000000..637587190a
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_report_statistics_plugin.c
@@ -0,0 +1,61 @@
+/*
+ * malloc_report_statistics with plugin Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+#include "inttypes.h"
+
+void malloc_report_statistics_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+)
+{
+ rtems_malloc_statistics_t *s;
+ uintmax_t allocated;
+
+ s = &rtems_malloc_statistics;
+
+ allocated = s->lifetime_allocated - s->lifetime_freed;
+
+ (*print)(
+ context,
+ "Malloc statistics\n"
+ " avail:%"PRIu32"k allocated:%"PRIu32"k (%"PRId32"%%) "
+ "max:%"PRIu32"k (%"PRIu32"%%)"
+ " lifetime:%"PRIu32"k freed:%"PRIu32"k\n",
+ s->space_available / 1024,
+ allocated / 1024,
+ /* avoid float! */
+ (allocated * 100) / s->space_available,
+ s->max_depth / 1024,
+ (s->max_depth * 100) / s->space_available,
+ (uint32_t) (s->lifetime_allocated / 1024),
+ (uint32_t) (s->lifetime_freed / 1024)
+ );
+ (*print)(
+ context,
+ " Call counts: malloc:%"PRIu32" memalign:%"PRIu32" free:%"PRIu32
+ " realloc:%"PRIu32" calloc:%"PRIu32"\n",
+ s->malloc_calls,
+ s->memalign_calls,
+ s->free_calls,
+ s->realloc_calls,
+ s->calloc_calls
+ );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/malloc_sbrk_helpers.c b/cpukit/libcsupport/src/malloc_sbrk_helpers.c
new file mode 100644
index 0000000000..e917fd36af
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_sbrk_helpers.c
@@ -0,0 +1,112 @@
+/*
+ * RTEMS Malloc -- SBRK Support Plugin
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h> /* sbrk */
+
+#include <rtems.h>
+#include <rtems/malloc.h>
+#include "malloc_p.h"
+
+#include <errno.h>
+
+size_t RTEMS_Malloc_Sbrk_amount;
+
+void *malloc_sbrk_initialize(
+ void *starting_address,
+ size_t length
+)
+{
+ uintptr_t old_address;
+ uintptr_t uaddress;
+
+ RTEMS_Malloc_Sbrk_amount = length;
+
+ /*
+ * If the starting address is 0 then we are to attempt to
+ * get length worth of memory using sbrk. Make sure we
+ * align the address that we get back.
+ */
+
+ if (!starting_address) {
+ uaddress = (uintptr_t)sbrk(length);
+
+ if (uaddress == (uintptr_t) -1) {
+ rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
+ /* DOES NOT RETURN!!! */
+ }
+
+ if (uaddress & (CPU_HEAP_ALIGNMENT-1)) {
+ old_address = uaddress;
+ uaddress = (uaddress + CPU_HEAP_ALIGNMENT) & ~(CPU_HEAP_ALIGNMENT-1);
+
+ /*
+ * adjust the length by whatever we aligned by
+ */
+ length -= uaddress - old_address;
+ }
+
+ starting_address = (void *)uaddress;
+ }
+ return starting_address;
+}
+
+void *malloc_sbrk_extend_and_allocate(
+ size_t size
+)
+{
+ uint32_t sbrk_amount;
+ void *starting_address;
+ uint32_t the_size;
+ void *return_this;
+
+ /*
+ * Round to the "requested sbrk amount" so hopefully we won't have
+ * to grow again for a while. This effectively does sbrk() calls
+ * in "page" amounts.
+ */
+
+ sbrk_amount = RTEMS_Malloc_Sbrk_amount;
+
+ if ( sbrk_amount == 0 )
+ return (void *) 0;
+
+ the_size = ((size + sbrk_amount) / sbrk_amount * sbrk_amount);
+
+ starting_address = (void *) sbrk(the_size);
+ if ( starting_address == (void*) -1 )
+ return (void *) 0;
+
+ if ( !_Protected_heap_Extend(
+ RTEMS_Malloc_Heap, starting_address, the_size) ) {
+ sbrk(-the_size);
+ errno = ENOMEM;
+ return (void *) 0;
+ }
+
+ MSBUMP(space_available, the_size);
+
+ return_this = _Protected_heap_Allocate( RTEMS_Malloc_Heap, size );
+ return return_this;
+}
+
+
+rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table = {
+ malloc_sbrk_initialize,
+ malloc_sbrk_extend_and_allocate
+};
+
+
diff --git a/cpukit/libcsupport/src/malloc_statistics_helpers.c b/cpukit/libcsupport/src/malloc_statistics_helpers.c
new file mode 100644
index 0000000000..fcd9a5cbde
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_statistics_helpers.c
@@ -0,0 +1,75 @@
+
+/*
+ * _calloc_r Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+#include <sys/reent.h>
+#include <stdlib.h>
+
+
+static void rtems_malloc_statistics_initialize( void )
+{
+ /*
+ * Zero all the statistics
+ */
+ (void) memset(&rtems_malloc_statistics, 0, sizeof(rtems_malloc_statistics));
+}
+
+static void rtems_malloc_statistics_at_malloc(
+ void *pointer
+)
+{
+ uintptr_t actual_size = 0;
+ uint32_t current_depth;
+ rtems_malloc_statistics_t *s = &rtems_malloc_statistics;
+
+ if ( !pointer )
+ return;
+
+ _Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &actual_size);
+
+ MSBUMP(lifetime_allocated, actual_size);
+
+ current_depth = (uint32_t) (s->lifetime_allocated - s->lifetime_freed);
+ if (current_depth > s->max_depth)
+ s->max_depth = current_depth;
+}
+
+/*
+ * If the pointer is not in the heap, then we won't be able to get its
+ * size and thus we skip updating the statistics.
+ */
+static void rtems_malloc_statistics_at_free(
+ void *pointer
+)
+{
+ uintptr_t size;
+
+ if (_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &size) ) {
+ MSBUMP(lifetime_freed, size);
+ }
+}
+
+rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = {
+ rtems_malloc_statistics_initialize,
+ rtems_malloc_statistics_at_malloc,
+ rtems_malloc_statistics_at_free,
+};
+
+#endif
diff --git a/cpukit/libcsupport/src/malloc_walk.c b/cpukit/libcsupport/src/malloc_walk.c
new file mode 100644
index 0000000000..6b6602b2ff
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_walk.c
@@ -0,0 +1,28 @@
+/*
+ * malloc_walk Implementation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+#include <stdlib.h>
+
+void malloc_walk(size_t source, size_t printf_enabled)
+{
+ _Protected_heap_Walk( RTEMS_Malloc_Heap, (int) source, printf_enabled );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/mallocfreespace.c b/cpukit/libcsupport/src/mallocfreespace.c
new file mode 100644
index 0000000000..cb0eb1f2ea
--- /dev/null
+++ b/cpukit/libcsupport/src/mallocfreespace.c
@@ -0,0 +1,42 @@
+/*
+ * RTEMS Malloc Get Free Information
+ *
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+#include <rtems/score/protectedheap.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+
+#include "malloc_p.h"
+
+/*
+ * Find amount of free heap remaining
+ */
+
+size_t malloc_free_space( void )
+{
+ Heap_Information info;
+
+ _Protected_heap_Get_free_information( RTEMS_Malloc_Heap, &info );
+ return (size_t) info.largest;
+}
diff --git a/cpukit/libcsupport/src/mallocgetheapptr.c b/cpukit/libcsupport/src/mallocgetheapptr.c
new file mode 100644
index 0000000000..b0df2f57fb
--- /dev/null
+++ b/cpukit/libcsupport/src/mallocgetheapptr.c
@@ -0,0 +1,26 @@
+/*
+ * RTEMS Malloc Get Heap Pointer -- Primarily for Debug
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+#include "malloc_p.h"
+
+Heap_Control *malloc_get_heap_pointer( void )
+{
+ return RTEMS_Malloc_Heap;
+}
diff --git a/cpukit/libcsupport/src/mallocinfo.c b/cpukit/libcsupport/src/mallocinfo.c
new file mode 100644
index 0000000000..d1c3266aeb
--- /dev/null
+++ b/cpukit/libcsupport/src/mallocinfo.c
@@ -0,0 +1,39 @@
+/*
+ * RTEMS Malloc Get Status Information
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+#include <rtems/score/protectedheap.h>
+
+extern Heap_Control *RTEMS_Malloc_Heap;
+
+/*
+ * Find amount of free heap remaining
+ */
+
+int malloc_info(
+ Heap_Information_block *the_info
+)
+{
+ if ( !the_info )
+ return -1;
+
+ _Protected_heap_Get_information( RTEMS_Malloc_Heap, the_info );
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/mallocsetheapptr.c b/cpukit/libcsupport/src/mallocsetheapptr.c
new file mode 100644
index 0000000000..e0d1471750
--- /dev/null
+++ b/cpukit/libcsupport/src/mallocsetheapptr.c
@@ -0,0 +1,28 @@
+/*
+ * RTEMS Malloc Set Heap Pointer -- Primarily for Debug
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+#include "malloc_p.h"
+
+void malloc_set_heap_pointer(
+ Heap_Control *new_heap
+)
+{
+ RTEMS_Malloc_Heap = new_heap;
+}
diff --git a/cpukit/libcsupport/src/mkdir.c b/cpukit/libcsupport/src/mkdir.c
new file mode 100644
index 0000000000..2fae8a733a
--- /dev/null
+++ b/cpukit/libcsupport/src/mkdir.c
@@ -0,0 +1,30 @@
+/*
+ * mkdir() - POSIX 1003.1b 5.4.1 - Make a Directory
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+int mkdir(
+ const char *pathname,
+ mode_t mode
+)
+{
+ return mknod( pathname, mode | S_IFDIR, 0LL);
+}
diff --git a/cpukit/libcsupport/src/mkfifo.c b/cpukit/libcsupport/src/mkfifo.c
new file mode 100644
index 0000000000..efe6207bf8
--- /dev/null
+++ b/cpukit/libcsupport/src/mkfifo.c
@@ -0,0 +1,28 @@
+/*
+ * mkfifo() - POSIX 1003.1b 5.4.1 - Make a FIFO Special File
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+int mkfifo(
+ const char *path,
+ mode_t mode
+)
+{
+ return mknod( path, mode | S_IFIFO, 0LL );
+}
diff --git a/cpukit/libcsupport/src/mknod.c b/cpukit/libcsupport/src/mknod.c
new file mode 100644
index 0000000000..29aff43c31
--- /dev/null
+++ b/cpukit/libcsupport/src/mknod.c
@@ -0,0 +1,73 @@
+/*
+ * mknod()
+ *
+ * This routine is not defined in the POSIX 1003.1b standard but is
+ * commonly supported on most UNIX and POSIX systems. It is the
+ * foundation for creating file system objects.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int mknod(
+ const char *pathname,
+ mode_t mode,
+ dev_t dev
+)
+{
+ rtems_filesystem_location_info_t temp_loc;
+ int i;
+ const char *name_start;
+ int result;
+
+ /*
+ * The file type is field within the mode. Check we have a sane mode set.
+ */
+ switch (mode & S_IFMT)
+ {
+ case S_IFDIR:
+ case S_IFCHR:
+ case S_IFBLK:
+ case S_IFREG:
+ case S_IFIFO:
+ break;
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ rtems_filesystem_get_start_loc( pathname, &i, &temp_loc );
+
+ result = (*temp_loc.ops->evalformake_h)(
+ &pathname[i],
+ &temp_loc,
+ &name_start
+ );
+ if ( result != 0 )
+ return -1;
+
+ result = (*temp_loc.ops->mknod_h)( name_start, mode, dev, &temp_loc );
+
+ rtems_filesystem_freenode( &temp_loc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/mount-mgr.c b/cpukit/libcsupport/src/mount-mgr.c
new file mode 100644
index 0000000000..c610ff6998
--- /dev/null
+++ b/cpukit/libcsupport/src/mount-mgr.c
@@ -0,0 +1,169 @@
+/*
+ * mount()
+ *
+ * Mange the mount table. You can iterate on mounts and file systems, as well
+ * as add and remove file systems not in the file system confiration table.
+ *
+ * COPYRIGHT (c) Chris Johns <chrisj@rtems.org> 2010.
+ *
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <rtems/chain.h>
+#include <rtems/seterr.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems/libio_.h>
+
+typedef struct {
+ rtems_chain_node node;
+ rtems_filesystem_table_t entry;
+} filesystem_node;
+
+static RTEMS_CHAIN_DEFINE_EMPTY(filesystem_chain);
+
+bool rtems_filesystem_iterate(
+ rtems_per_filesystem_routine routine,
+ void *routine_arg
+)
+{
+ const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table [0];
+ rtems_chain_node *node = NULL;
+ bool stop = false;
+
+ while ( table_entry->type && !stop ) {
+ stop = (*routine)( table_entry, routine_arg );
+ ++table_entry;
+ }
+
+ if ( !stop ) {
+ rtems_libio_lock();
+ for (
+ node = rtems_chain_first( &filesystem_chain );
+ !rtems_chain_is_tail( &filesystem_chain, node ) && !stop;
+ node = rtems_chain_next( node )
+ ) {
+ const filesystem_node *fsn = (filesystem_node *) node;
+
+ stop = (*routine)( &fsn->entry, routine_arg );
+ }
+ rtems_libio_unlock();
+ }
+
+ return stop;
+}
+
+typedef struct {
+ const char *type;
+ rtems_filesystem_fsmount_me_t mount_h;
+} find_arg;
+
+static bool find_handler(const rtems_filesystem_table_t *entry, void *arg)
+{
+ find_arg *fa = arg;
+
+ if ( strcmp( entry->type, fa->type ) != 0 ) {
+ return false;
+ } else {
+ fa->mount_h = entry->mount_h;
+
+ return true;
+ }
+}
+
+rtems_filesystem_fsmount_me_t
+rtems_filesystem_get_mount_handler(
+ const char *type
+)
+{
+ find_arg fa = {
+ .type = type,
+ .mount_h = NULL
+ };
+
+ if ( type != NULL ) {
+ rtems_filesystem_iterate( find_handler, &fa );
+ }
+
+ return fa.mount_h;
+}
+
+int
+rtems_filesystem_register(
+ const char *type,
+ rtems_filesystem_fsmount_me_t mount_h
+)
+{
+ size_t type_size = strlen(type) + 1;
+ size_t fsn_size = sizeof( filesystem_node ) + type_size;
+ filesystem_node *fsn = malloc( fsn_size );
+ char *type_storage = (char *) fsn + sizeof( *fsn );
+
+ if ( fsn == NULL )
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ memcpy(type_storage, type, type_size);
+ fsn->entry.type = type_storage;
+ fsn->entry.mount_h = mount_h;
+
+ rtems_libio_lock();
+ if ( rtems_filesystem_get_mount_handler( type ) == NULL ) {
+ rtems_chain_append( &filesystem_chain, &fsn->node );
+ } else {
+ rtems_libio_unlock();
+ free( fsn );
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+ rtems_libio_unlock();
+
+ return 0;
+}
+
+int
+rtems_filesystem_unregister(
+ const char *type
+)
+{
+ rtems_chain_node *node = NULL;
+
+ if ( type == NULL ) {
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ rtems_libio_lock();
+ for (
+ node = rtems_chain_first( &filesystem_chain );
+ !rtems_chain_is_tail( &filesystem_chain, node );
+ node = rtems_chain_next( node )
+ ) {
+ filesystem_node *fsn = (filesystem_node *) node;
+
+ if ( strcmp( fsn->entry.type, type ) == 0 ) {
+ rtems_chain_extract( node );
+ free( fsn );
+ rtems_libio_unlock();
+
+ return 0;
+ }
+ }
+ rtems_libio_unlock();
+
+ rtems_set_errno_and_return_minus_one( ENOENT );
+}
diff --git a/cpukit/libcsupport/src/mount-mktgt.c b/cpukit/libcsupport/src/mount-mktgt.c
new file mode 100644
index 0000000000..3b4d50aded
--- /dev/null
+++ b/cpukit/libcsupport/src/mount-mktgt.c
@@ -0,0 +1,56 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief mount_and_make_target_path() implementation.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/libio.h>
+
+int mount_and_make_target_path(
+ const char *source,
+ const char *target,
+ const char *filesystemtype,
+ rtems_filesystem_options_t options,
+ const void *data
+)
+{
+ int rv = -1;
+
+ if (target != NULL) {
+ rv = rtems_mkdir(target, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (rv == 0) {
+ rv = mount(
+ source,
+ target,
+ filesystemtype,
+ options,
+ data
+ );
+ }
+ } else {
+ errno = EINVAL;
+ }
+
+ return rv;
+}
diff --git a/cpukit/libcsupport/src/mount.c b/cpukit/libcsupport/src/mount.c
new file mode 100644
index 0000000000..00a07aab3a
--- /dev/null
+++ b/cpukit/libcsupport/src/mount.c
@@ -0,0 +1,282 @@
+/*
+ * mount()
+ *
+ * XXX
+ *
+ * XXX make sure no required ops are NULL
+ * XXX make sure no optional ops you are using are NULL
+ * XXX unmount should be required.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <rtems/chain.h>
+#include <rtems/seterr.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems/libio_.h>
+
+static RTEMS_CHAIN_DEFINE_EMPTY(mount_chain);
+
+/*
+ * Default pathconfs.
+ */
+const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf = {
+ 5, /* link_max: count */
+ 128, /* max_canon: max formatted input line size */
+ 7, /* max_input: max input line size */
+ 255, /* name_max: max name */
+ 255, /* path_max: max path */
+ 1024, /* pipe_buf: pipe buffer size */
+ 0, /* posix_async_io: async IO supported on fs, 0=no, 1=yes */
+ 0 , /* posix_chown_restrictions: can chown: 0=no, 1=yes */
+ 1, /* posix_no_trunc: error on filenames > max name, 0=no, 1=yes */
+ 0, /* posix_prio_io: priority IO, 0=no, 1=yes */
+ 0, /* posix_sync_io: file can be sync'ed, 0=no, 1=yes */
+ 0 /* posix_vdisable: special char processing, 0=no, 1=yes */
+};
+
+static bool is_node_fs_root(
+ const rtems_filesystem_mount_table_entry_t *mt_entry,
+ void *arg
+)
+{
+ return arg == mt_entry->mt_fs_root.node_access;
+}
+
+static rtems_filesystem_mount_table_entry_t *alloc_mount_table_entry(
+ const char *source_or_null,
+ const char *target_or_null,
+ const char *filesystemtype,
+ size_t *target_length_ptr
+)
+{
+ const char *target = target_or_null != NULL ? target_or_null : "/";
+ size_t filesystemtype_size = strlen( filesystemtype ) + 1;
+ size_t source_size = source_or_null != NULL ?
+ strlen( source_or_null ) + 1 : 0;
+ size_t target_size = strlen( target ) + 1;
+ size_t size = sizeof( rtems_filesystem_mount_table_entry_t )
+ + filesystemtype_size + source_size + target_size;
+ rtems_filesystem_mount_table_entry_t *mt_entry = calloc( 1, size );
+
+ if ( mt_entry != NULL ) {
+ char *str = (char *) mt_entry + sizeof( *mt_entry );
+
+ memcpy( str, filesystemtype, filesystemtype_size );
+ mt_entry->type = str;
+ str += filesystemtype_size;
+
+ memcpy( str, source_or_null, source_size );
+ mt_entry->dev = str;
+ str += source_size;
+
+ memcpy( str, target, target_size );
+ mt_entry->target = str;
+ }
+
+ *target_length_ptr = target_size - 1;
+
+ return mt_entry;
+}
+
+/*
+ * mount
+ *
+ * This routine will attempt to mount a new file system at the specified
+ * mount point. A series of tests will be run to determine if any of the
+ * following reasons exist to prevent the mount operation:
+ *
+ * 1) The file system type or options are not valid
+ * 2) No new file system root node is specified
+ * 3) The selected file system has already been mounted
+ * 4) The mount point exists with the proper permissions to allow mounting
+ * 5) The selected mount point already has a file system mounted to it
+ *
+ */
+
+int mount(
+ const char *source,
+ const char *target,
+ const char *filesystemtype,
+ rtems_filesystem_options_t options,
+ const void *data
+)
+{
+ rtems_filesystem_fsmount_me_t mount_h = NULL;
+ rtems_filesystem_location_info_t loc;
+ rtems_filesystem_mount_table_entry_t *mt_entry = NULL;
+ rtems_filesystem_location_info_t *loc_to_free = NULL;
+ bool has_target = target != NULL;
+ size_t target_length = 0;
+
+ /*
+ * Are the file system options valid?
+ */
+
+ if ( options != RTEMS_FILESYSTEM_READ_ONLY &&
+ options != RTEMS_FILESYSTEM_READ_WRITE )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * Get mount handler
+ */
+ mount_h = rtems_filesystem_get_mount_handler( filesystemtype );
+ if ( !mount_h )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * Allocate a mount table entry
+ */
+ mt_entry = alloc_mount_table_entry(
+ source,
+ target,
+ filesystemtype,
+ &target_length
+ );
+ if ( !mt_entry )
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ mt_entry->mt_fs_root.mt_entry = mt_entry;
+ mt_entry->options = options;
+ mt_entry->pathconf_limits_and_options = rtems_filesystem_default_pathconf;
+
+ /*
+ * The mount_point should be a directory with read/write/execute
+ * permissions in the existing tree.
+ */
+
+ if ( has_target ) {
+ if ( rtems_filesystem_evaluate_path(
+ target, target_length, RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 )
+ goto cleanup_and_bail;
+
+ loc_to_free = &loc;
+
+ /*
+ * Test to see if it is a directory
+ */
+
+ if ( loc.ops->node_type_h( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
+ errno = ENOTDIR;
+ goto cleanup_and_bail;
+ }
+
+ /*
+ * You can only mount one file system onto a single mount point.
+ */
+
+ if ( rtems_filesystem_mount_iterate( is_node_fs_root, loc.node_access ) ) {
+ errno = EBUSY;
+ goto cleanup_and_bail;
+ }
+
+ /*
+ * This must be a good mount point, so move the location information
+ * into the allocated mount entry. Note: the information that
+ * may have been allocated in loc should not be sent to freenode
+ * until the system is unmounted. It may be needed to correctly
+ * traverse the tree.
+ */
+
+ mt_entry->mt_point_node.node_access = loc.node_access;
+ mt_entry->mt_point_node.handlers = loc.handlers;
+ mt_entry->mt_point_node.ops = loc.ops;
+ mt_entry->mt_point_node.mt_entry = loc.mt_entry;
+
+ /*
+ * This link to the parent is only done when we are dealing with system
+ * below the base file system
+ */
+
+ if ( loc.ops->mount_h( mt_entry ) ) {
+ goto cleanup_and_bail;
+ }
+ } else {
+ /*
+ * Do we already have a base file system ?
+ */
+ if ( !rtems_chain_is_empty( &mount_chain ) ) {
+ errno = EINVAL;
+ goto cleanup_and_bail;
+ }
+
+ /*
+ * This is a mount of the base file system --> The
+ * mt_point_node.node_access will be left to null to indicate that this
+ * is the root of the entire file system.
+ */
+ }
+
+ if ( (*mount_h)( mt_entry, data ) ) {
+ /*
+ * Try to undo the mount operation
+ */
+ loc.ops->unmount_h( mt_entry );
+ goto cleanup_and_bail;
+ }
+
+ /*
+ * Add the mount table entry to the mount table chain
+ */
+ rtems_libio_lock();
+ rtems_chain_append( &mount_chain, &mt_entry->Node );
+ rtems_libio_unlock();
+
+ if ( !has_target )
+ rtems_filesystem_root = mt_entry->mt_fs_root;
+
+ return 0;
+
+cleanup_and_bail:
+
+ free( mt_entry );
+
+ if ( loc_to_free )
+ rtems_filesystem_freenode( loc_to_free );
+
+ return -1;
+}
+
+bool rtems_filesystem_mount_iterate(
+ rtems_per_filesystem_mount_routine routine,
+ void *routine_arg
+)
+{
+ rtems_chain_node *node = NULL;
+ bool stop = false;
+
+ rtems_libio_lock();
+ for (
+ node = rtems_chain_first( &mount_chain );
+ !rtems_chain_is_tail( &mount_chain, node ) && !stop;
+ node = rtems_chain_next( node )
+ ) {
+ const rtems_filesystem_mount_table_entry_t *mt_entry =
+ (rtems_filesystem_mount_table_entry_t *) node;
+
+ stop = (*routine)( mt_entry, routine_arg );
+ }
+ rtems_libio_unlock();
+
+ return stop;
+}
diff --git a/cpukit/libcsupport/src/newlibc_exit.c b/cpukit/libcsupport/src/newlibc_exit.c
new file mode 100644
index 0000000000..818ba884f4
--- /dev/null
+++ b/cpukit/libcsupport/src/newlibc_exit.c
@@ -0,0 +1,160 @@
+/*
+ * Implementation of hooks for the CYGNUS newlib libc
+ * These hooks set things up so that:
+ * + '_REENT' is switched at task switch time.
+ *
+ * COPYRIGHT (c) 1994 by Division Incorporated
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+
+#if defined(RTEMS_NEWLIB)
+#include <rtems/libcsupport.h>
+
+/* Since we compile with strict ANSI we need to undef it to get
+ * prototypes for extensions
+ */
+#undef __STRICT_ANSI__
+
+#include <stdlib.h> /* for free() */
+#include <string.h> /* for memset() */
+
+#include <sys/reent.h> /* for extern of _REENT (aka _impure_ptr) */
+#include <errno.h>
+
+#include <stdio.h>
+
+int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
+
+/* do we think we are reentrant? */
+extern int libc_reentrant;
+extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
+
+/*
+ * CYGNUS newlib routine that does atexit() processing and flushes
+ * stdio streams
+ * undocumented
+ */
+
+extern void _wrapup_reent(struct _reent *);
+extern void _reclaim_reent(struct _reent *);
+
+void libc_wrapup(void)
+{
+ /*
+ * In case RTEMS is already down, don't do this. It could be
+ * dangerous.
+ */
+
+ if (!_System_state_Is_up(_System_state_Get()))
+ return;
+
+ /*
+ * This was already done if the user called exit() directly .
+ _wrapup_reent(0);
+ */
+
+ if (_REENT != _global_impure_ptr) {
+ _wrapup_reent(_global_impure_ptr);
+#if 0
+ /* Don't reclaim this one, just in case we do printfs
+ * on the way out to ROM.
+ */
+ _reclaim_reent(&libc_global_reent);
+#endif
+ _REENT = _global_impure_ptr;
+ }
+
+ /*
+ * Try to drain output buffers.
+ *
+ * Should this be changed to do *all* file streams?
+ * _fwalk (_REENT, fclose);
+ */
+
+ fclose (stdin);
+ fclose (stdout);
+ fclose (stderr);
+}
+
+/*
+ * Function: _exit
+ * Created: 94/12/10
+ *
+ * Description:
+ * Called from exit() after it does atexit() processing and stdio fflush's
+ *
+ * called from bottom of exit() to really delete the task.
+ * If we are using reentrant libc, then let the delete extension
+ * do all the work, otherwise if a shutdown is in progress,
+ * then just do it.
+ *
+ * Parameters:
+ * exit status
+ *
+ * Returns:
+ * does not return
+ *
+ * Side Effects:
+ *
+ * Notes:
+ *
+ *
+ * Deficiencies/ToDo:
+ *
+ *
+ */
+
+#include <unistd.h>
+
+/* FIXME: These defines are a blatant hack */
+ #define EXIT_SYMBOL _exit
+
+ #if defined(__AVR__)
+ #undef __USE_INIT_FINI__
+ #endif
+ #if defined(__USE_INIT_FINI__)
+ #if defined(__m32r__)
+ #define FINI_SYMBOL __fini
+ #else
+ #define FINI_SYMBOL _fini
+ #endif
+
+ extern void FINI_SYMBOL( void );
+ #endif
+
+void EXIT_SYMBOL(int status)
+{
+ /*
+ * If the toolset uses init/fini sections, then we need to
+ * run the global destructors now.
+ */
+ #if defined(__USE_INIT_FINI__)
+ FINI_SYMBOL();
+ #endif
+
+ /*
+ * We need to do the exit processing on the global reentrancy structure.
+ * This has already been done on the per task reentrancy structure
+ * associated with this task.
+ */
+
+ libc_wrapup();
+ rtems_shutdown_executive(status);
+ for (;;) ; /* to avoid warnings */
+}
+
+
+#endif
diff --git a/cpukit/libcsupport/src/newlibc_init.c b/cpukit/libcsupport/src/newlibc_init.c
new file mode 100644
index 0000000000..4d2cef5405
--- /dev/null
+++ b/cpukit/libcsupport/src/newlibc_init.c
@@ -0,0 +1,41 @@
+/*
+ * Implementation of hooks for the CYGNUS newlib libc
+ * These hooks set things up so that:
+ * + '_REENT' is switched at task switch time.
+ *
+ * COPYRIGHT (c) 1994 by Division Incorporated
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB)
+
+/*
+ * Init libc for CYGNUS newlib
+ *
+ * Set up _REENT to use our global libc_global_reent.
+ * (newlib provides a global of its own, but we prefer our own name for it)
+ *
+ * If reentrancy is desired (which it should be), then
+ * we install the task extension hooks to maintain the
+ * newlib reentrancy global variable _REENT on task
+ * create, delete, switch, exit, etc.
+ *
+ */
+
+
+void
+libc_init(void)
+{
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/newlibc_reent.c b/cpukit/libcsupport/src/newlibc_reent.c
new file mode 100644
index 0000000000..1315dc35dc
--- /dev/null
+++ b/cpukit/libcsupport/src/newlibc_reent.c
@@ -0,0 +1,170 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+
+#if defined(RTEMS_NEWLIB)
+#include <rtems/libcsupport.h>
+
+/* Since we compile with strict ANSI we need to undef it to get
+ * prototypes for extensions
+ */
+#undef __STRICT_ANSI__
+
+#include <stdlib.h> /* for free() */
+#include <string.h> /* for memset() */
+
+#include <sys/reent.h> /* for extern of _REENT (aka _impure_ptr) */
+#include <errno.h>
+
+/*
+ * NOTE:
+ * There is some problem with doing this on the hpux version
+ * of the UNIX simulator (symptom is printf core dumps), so
+ * we just don't for now.
+ * Not sure if this is a problem with hpux, newlib, or something else.
+ */
+
+#include <stdio.h>
+
+int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
+
+extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
+/*
+ * reent struct allocation moved here from libc_start_hook() to avoid
+ * mutual exclusion problems when memory is allocated from the start hook.
+ *
+ * Memory is also now allocated from the workspace rather than the heap.
+ * -- ptorre 9/30/03
+ */
+bool newlib_create_hook(
+ rtems_tcb *current_task __attribute__((unused)),
+ rtems_tcb *creating_task
+)
+{
+ struct _reent *ptr;
+
+ if (_Thread_libc_reent == 0)
+ {
+ _REENT = _global_impure_ptr;
+
+ _Thread_Set_libc_reent (&_REENT);
+ }
+
+ /* NOTE: The RTEMS malloc is reentrant without a reent ptr since
+ * it is based on the Classic API Region Manager.
+ */
+
+ #define REENT_MALLOCED 0
+ #if REENT_MALLOCED
+ ptr = (struct _reent *) calloc(1, sizeof(struct _reent));
+ #else
+ /* It is OK to allocate from the workspace because these
+ * hooks run with thread dispatching disabled.
+ */
+ ptr = (struct _reent *) _Workspace_Allocate(sizeof(struct _reent));
+ #endif
+
+ if (ptr) {
+ _REENT_INIT_PTR((ptr)); /* GCC extension: structure constants */
+ creating_task->libc_reent = ptr;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
+ * Called for all user TASKS (system tasks are MPCI Receive Server and IDLE)
+ */
+
+#ifdef NEED_SETVBUF
+void newlib_begin_hook(rtems_tcb *current_task)
+{
+ setvbuf( stdout, NULL, _IOLBF, BUFSIZ );
+}
+#endif
+
+/*
+ * Called when a task is deleted.
+ * Must restore the new lib reentrancy state for the new current
+ * task.
+ *
+ */
+
+int newlib_free_buffers(
+ FILE *fp
+)
+{
+ switch ( fileno(fp) ) {
+ case 0:
+ case 1:
+ case 2:
+ if (fp->_flags & __SMBF) {
+ free( fp->_bf._base );
+ fp->_flags &= ~__SMBF;
+ fp->_bf._base = fp->_p = (unsigned char *) NULL;
+ }
+ break;
+ default:
+ fclose(fp);
+ }
+ return 0;
+}
+
+void newlib_delete_hook(
+ rtems_tcb *current_task,
+ rtems_tcb *deleted_task
+)
+{
+ struct _reent *ptr;
+
+ /*
+ * The reentrancy structure was allocated by newlib using malloc()
+ */
+
+ if (current_task == deleted_task) {
+ ptr = _REENT;
+ } else {
+ ptr = deleted_task->libc_reent;
+ }
+
+ if (ptr && ptr != _global_impure_ptr) {
+/*
+ _wrapup_reent(ptr);
+ _reclaim_reent(ptr);
+*/
+ /*
+ * Just in case there are some buffers lying around.
+ */
+ _fwalk(ptr, newlib_free_buffers);
+#if REENT_MALLOCED
+ free(ptr);
+#else
+ _Workspace_Free(ptr);
+#endif
+ }
+
+ deleted_task->libc_reent = NULL;
+
+ /*
+ * Require the switch back to another task to install its own
+ */
+
+ if ( current_task == deleted_task ) {
+ _REENT = 0;
+ }
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c
new file mode 100644
index 0000000000..a49ebfec0d
--- /dev/null
+++ b/cpukit/libcsupport/src/open.c
@@ -0,0 +1,215 @@
+/*
+ * open() - POSIX 1003.1 5.3.1 - Open a File
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+#include <fcntl.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#include <unistd.h>
+
+/*
+ * Returns file descriptor on success or -1 and errno set to one of the
+ * following:
+ *
+ * EACCESS - Seach permission is denied on a component of the path prefix,
+ * or the file exists and the permissions specified by the
+ * flags are denied, or the file does not exist and write
+ * permission is denied for the parent directory of the file
+ * to be created, or O_TRUNC is specified and write permission
+ * is denied.
+ * EEXIST - O_CREAT and O_EXCL are set and the named file exists.
+ * EINTR - The open( operation was interrupted by a signal.
+ * EINVAL - This implementation does not support synchronized IO for this
+ * file.
+ * EISDIR - The named file is a directory and the flags argument
+ * specified write or read/write access.
+ * EMFILE - Too many file descriptors are in used by this process.
+ * ENAMETOOLONG -
+ * The length of the path exceeds PATH_MAX or a pathname
+ * component is longer than NAME_MAX while POSIX_NO_TRUNC
+ * is in effect.
+ * ENFILE - Too many files are open in the system.
+ * ENOENT - O_CREAT is not set and and the anmed file does not exist,
+ * or O_CREAT is set and either the path prefix does not exist
+ * or the path argument points to an empty string.
+ * ENOSPC - The directory or file system that would contain the new file
+ * cannot be extended.
+ * ENOTDIR - A component of the path prefix is not a directory.
+ * ENXIO - O_NONBLOCK is set, the named file is a FIFO, O_WRONLY is
+ * set, and no process has the file open for reading.
+ * EROFS - The named file resides on a read-only file system and either
+ * O_WRONLY, O_RDWR, O_CREAT (if the file does not exist), or
+ * O_TRUNC is set in the flags argument.
+ */
+
+int open(
+ const char *pathname,
+ int flags,
+ ...
+)
+{
+ va_list ap;
+ int mode;
+ int rc;
+ rtems_libio_t *iop = 0;
+ int status;
+ rtems_filesystem_location_info_t loc;
+ rtems_filesystem_location_info_t *loc_to_free = NULL;
+ int eval_flags;
+
+ /*
+ * Set the Evaluation flags
+ */
+ eval_flags = 0;
+ status = flags + 1;
+ if ( ( status & _FREAD ) == _FREAD )
+ eval_flags |= RTEMS_LIBIO_PERMS_READ;
+ if ( ( status & _FWRITE ) == _FWRITE )
+ eval_flags |= RTEMS_LIBIO_PERMS_WRITE;
+
+ va_start(ap, flags);
+
+ mode = va_arg( ap, int );
+
+ /*
+ * NOTE: This comment is OBSOLETE. The proper way to do this now
+ * would be to support a magic mounted file system.
+ *
+ * Additional external I/O handlers would be supported by adding
+ * code to pick apart the pathname appropriately. The networking
+ * code does not require changes here since network file
+ * descriptors are obtained using socket(), not open().
+ */
+
+ /* allocate a file control block */
+ iop = rtems_libio_allocate();
+ if ( iop == 0 ) {
+ rc = ENFILE;
+ goto done;
+ }
+
+ /*
+ * See if the file exists.
+ */
+ status = rtems_filesystem_evaluate_path(
+ pathname, strlen( pathname ), eval_flags, &loc, true );
+
+ if ( status == -1 ) {
+ if ( errno != ENOENT ) {
+ rc = errno;
+ goto done;
+ }
+
+ /* If the file does not exist and we are not trying to create it--> error */
+ if ( !(flags & O_CREAT) ) {
+ rc = ENOENT;
+ goto done;
+ }
+
+ /* Create the node for the new regular file */
+ rc = mknod( pathname, S_IFREG | mode, 0LL );
+ if ( rc ) {
+ rc = errno;
+ goto done;
+ }
+
+ /*
+ * After we do the mknod(), we have to evaluate the path to get the
+ * "loc" structure needed to actually have the file itself open.
+ * So we created it, and then we need to have "look it up."
+ */
+ status = rtems_filesystem_evaluate_path(
+ pathname, strlen( pathname ), 0x0, &loc, true );
+ if ( status != 0 ) { /* The file did not exist */
+ rc = EACCES;
+ goto done;
+ }
+
+ } else if ((flags & (O_EXCL|O_CREAT)) == (O_EXCL|O_CREAT)) {
+ /* We were trying to create a file that already exists */
+ rc = EEXIST;
+ loc_to_free = &loc;
+ goto done;
+ }
+
+ loc_to_free = &loc;
+
+ /*
+ * Fill in the file control block based on the loc structure
+ * returned by successful path evaluation.
+ */
+ iop->flags |= rtems_libio_fcntl_flags( flags );
+ iop->pathinfo = loc;
+
+ rc = (*iop->pathinfo.handlers->open_h)( iop, pathname, flags, mode );
+ if ( rc ) {
+ rc = errno;
+ goto done;
+ }
+
+ /*
+ * Optionally truncate the file.
+ */
+ if ( (flags & O_TRUNC) == O_TRUNC ) {
+ rc = ftruncate( iop - rtems_libio_iops, 0 );
+ if ( rc ) {
+ if(errno) rc = errno;
+ close( iop - rtems_libio_iops );
+ /* those are released by close(): */
+ iop = 0;
+ loc_to_free = NULL;
+ }
+ }
+
+ /*
+ * Single exit and clean up path.
+ */
+done:
+ va_end(ap);
+
+ if ( rc ) {
+ if ( iop )
+ rtems_libio_free( iop );
+ if ( loc_to_free )
+ rtems_filesystem_freenode( loc_to_free );
+ rtems_set_errno_and_return_minus_one( rc );
+ }
+
+ return iop - rtems_libio_iops;
+}
+
+/*
+ * _open_r
+ *
+ * This is the Newlib dependent reentrant version of open().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__OPEN_R)
+
+#include <reent.h>
+
+int _open_r(
+ struct _reent *ptr __attribute__((unused)),
+ const char *buf,
+ int flags,
+ int mode
+)
+{
+ return open( buf, flags, mode );
+}
+#endif
diff --git a/cpukit/libcsupport/src/open_dev_console.c b/cpukit/libcsupport/src/open_dev_console.c
new file mode 100644
index 0000000000..ce01a9276e
--- /dev/null
+++ b/cpukit/libcsupport/src/open_dev_console.c
@@ -0,0 +1,51 @@
+/*
+ * open_dev_console - open /dev/console
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <fcntl.h>
+
+/*
+ * This is a replaceable stub which opens the console, if present.
+ */
+void open_dev_console(void)
+{
+ int stdin_fd;
+ int stdout_fd;
+ int stderr_fd;
+
+ /*
+ * Attempt to open /dev/console.
+ */
+ if ((stdin_fd = open("/dev/console", O_RDONLY, 0)) == -1) {
+ /*
+ * There may not be a console driver so this is OK.
+ */
+ return;
+ }
+
+ /*
+ * But if we find /dev/console once, we better find it twice more
+ * or something is REALLY wrong.
+ */
+ if ((stdout_fd = open("/dev/console", O_WRONLY, 0)) == -1)
+ rtems_fatal_error_occurred( 0x55544431 ); /* error STD1 */
+
+ if ((stderr_fd = open("/dev/console", O_WRONLY, 0)) == -1)
+ rtems_fatal_error_occurred( 0x55544432 ); /* error STD2 */
+}
+
diff --git a/cpukit/libcsupport/src/pathconf.c b/cpukit/libcsupport/src/pathconf.c
new file mode 100644
index 0000000000..d16f899e95
--- /dev/null
+++ b/cpukit/libcsupport/src/pathconf.c
@@ -0,0 +1,41 @@
+/*
+ * pathconf() - POSIX 1003.1b - 5.7.1 - Configurable Pathname Varables
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+long pathconf(
+ const char *path,
+ int name
+)
+{
+ int status;
+ int fd;
+
+ fd = open( path, O_RDONLY );
+ if ( fd == -1 )
+ return -1;
+
+ status = fpathconf( fd, name );
+
+ (void) close( fd );
+
+ return status;
+}
diff --git a/cpukit/libcsupport/src/pipe.c b/cpukit/libcsupport/src/pipe.c
new file mode 100644
index 0000000000..13b2eb5dc6
--- /dev/null
+++ b/cpukit/libcsupport/src/pipe.c
@@ -0,0 +1,32 @@
+/*
+ * pipe() - POSIX 1003.1b 6.1.1 Create an Inter-Process Channel
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <rtems/seterr.h>
+
+extern int pipe_create(int filsdes[2]);
+
+int pipe(
+ int filsdes[2]
+)
+{
+ if (filsdes == NULL)
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ return pipe_create(filsdes);
+}
diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c
new file mode 100644
index 0000000000..cde55f042b
--- /dev/null
+++ b/cpukit/libcsupport/src/posix_memalign.c
@@ -0,0 +1,44 @@
+/*
+ * posix_memalign()
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+#include <stdlib.h>
+#include <errno.h>
+
+int posix_memalign(
+ void **pointer,
+ size_t alignment,
+ size_t size
+)
+{
+ /*
+ * Update call statistics
+ */
+ MSBUMP(memalign_calls, 1);
+
+ if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *)))
+ return EINVAL;
+
+ /*
+ * rtems_memalign does all of the error checking work EXCEPT
+ * for adding restrictionso on the alignment.
+ */
+ return rtems_memalign( pointer, alignment, size );
+}
+#endif
diff --git a/cpukit/libcsupport/src/printk.c b/cpukit/libcsupport/src/printk.c
new file mode 100644
index 0000000000..3ac7c8616a
--- /dev/null
+++ b/cpukit/libcsupport/src/printk.c
@@ -0,0 +1,39 @@
+/*
+ * (C) Copyright 1997 -
+ * - NavIST Group - Real-Time Distributed Systems and Industrial Automation
+ *
+ * http://pandora.ist.utl.pt
+ *
+ * Instituto Superior Tecnico * Lisboa * PORTUGAL
+ *
+ * Disclaimer:
+ *
+ * This file is provided "AS IS" without warranty of any kind, either
+ * expressed or implied.
+ *
+ * This code is based on code by: Jose Rufino - IST
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <rtems/bspIo.h>
+
+/*
+ * printk
+ *
+ * Kernel printf function requiring minimal infrastructure.
+ */
+void printk(const char *fmt, ...)
+{
+ va_list ap; /* points to each unnamed argument in turn */
+
+ va_start(ap, fmt); /* make ap point to 1st unnamed arg */
+ vprintk(fmt, ap);
+ va_end(ap); /* clean up when done */
+}
diff --git a/cpukit/libcsupport/src/printk_plugin.c b/cpukit/libcsupport/src/printk_plugin.c
new file mode 100644
index 0000000000..60d93a96af
--- /dev/null
+++ b/cpukit/libcsupport/src/printk_plugin.c
@@ -0,0 +1,34 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+#include <rtems/bspIo.h>
+
+int printk_plugin(
+ void *ignored __attribute__((unused)),
+ const char *format,
+ ...
+)
+{
+ va_list arg_pointer;
+
+ va_start (arg_pointer, format);
+
+ vprintk( format, arg_pointer );
+
+ va_end(arg_pointer); /* clean up when done */
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c
new file mode 100644
index 0000000000..89137200b7
--- /dev/null
+++ b/cpukit/libcsupport/src/privateenv.c
@@ -0,0 +1,204 @@
+/*
+ * Instantiate a private user environment for the calling thread.
+ *
+ * Submitted by: fernando.ruiz@ctv.es (correo@fernando-ruiz.com)
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h> /* free */
+
+#include <rtems.h>
+#include <rtems/chain.h>
+#include <rtems/libio_.h>
+
+/* cleanup a user environment
+ * NOTE: this must be called with
+ * thread dispatching disabled!
+ */
+static void
+free_user_env(void *venv)
+{
+ rtems_user_env_t *env = (rtems_user_env_t*) venv ;
+
+ if (env != &rtems_global_user_env
+ #ifdef HAVE_USERENV_REFCNT
+ && --env->refcnt <= 0
+ #endif
+ ) {
+ rtems_filesystem_freenode( &env->current_directory);
+ rtems_filesystem_freenode( &env->root_directory);
+ free(env);
+ }
+}
+
+rtems_status_code rtems_libio_set_private_env(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_id task_id = rtems_task_self();
+ rtems_filesystem_location_info_t root_loc;
+ rtems_filesystem_location_info_t current_loc;
+ rtems_user_env_t *new_env = NULL;
+ int rv = 0;
+
+ rv = rtems_filesystem_evaluate_path("/", 1, 0, &root_loc, 0);
+ if (rv != 0)
+ goto error_0;
+
+ rv = rtems_filesystem_evaluate_path("/", 1, 0, &current_loc, 0);
+ if (rv != 0)
+ goto error_1;
+
+ /*
+ * Malloc is necessary whenever the current task does not
+ * have its own environment in place. This could be:
+ * a) it never had one
+ * OR
+ * b) it shared another task's environment
+ */
+
+ /*
+ * Bharath: I'm not sure if the check can be reduced to
+ * if( rtems_current_user_env->task_id != task_id ) {
+ */
+
+ if (
+ rtems_current_user_env == &rtems_global_user_env
+ || rtems_current_user_env->task_id != task_id
+ ) {
+ new_env = malloc(sizeof(rtems_user_env_t));
+ if (new_env == NULL)
+ goto error_2;
+
+ #ifdef HAVE_USERENV_REFCNT
+ new_env->refcnt = 1;
+ #endif
+
+ sc = rtems_task_variable_add(
+ RTEMS_SELF,
+ (void*)&rtems_current_user_env,
+ (void(*)(void *))free_user_env
+ );
+ if (sc != RTEMS_SUCCESSFUL)
+ goto error_3;
+
+ rtems_current_user_env = new_env;
+ }
+
+ /* Inherit the global values */
+ *rtems_current_user_env = rtems_global_user_env;
+
+ rtems_current_user_env->task_id = task_id;
+
+ /*
+ * Clone the pathlocs. In contrast to most other code we must _not_ free the
+ * original locs because what we are trying to do here is forking off clones.
+ * The reason is a pathloc can be allocated by the file system and needs to
+ * be freed when deleting the environment.
+ */
+ rtems_filesystem_root = root_loc;
+ rtems_filesystem_current = current_loc;
+
+ return RTEMS_SUCCESSFUL;
+
+error_3:
+ free(new_env);
+
+error_2:
+ rtems_filesystem_freenode(&current_loc);
+
+error_1:
+ rtems_filesystem_freenode(&root_loc);
+
+error_0:
+ return RTEMS_NO_MEMORY;
+}
+
+/*
+ * Share the same private environment between two tasks:
+ * Task_id (remote) and RTEMS_SELF(current).
+ */
+
+/* NOTE:
+ *
+ * THIS CODE HAS NO PROTECTION IMPLEMENTED
+ *
+ * Tasks who wish to share their environments must
+ *
+ * a) assert that no participants are concurrently
+ * executing
+ * libio_share_private_env() and/or libio_set_private_env()
+ *
+ * b) mutex access to rtems_filesystem_current, rtems_filesytem_root
+ * while changing any of those (chdir(), chroot()).
+ */
+
+rtems_status_code rtems_libio_share_private_env(rtems_id task_id)
+{
+ rtems_status_code sc;
+ rtems_user_env_t * shared_user_env;
+ rtems_id current_task_id;
+
+ /*
+ * get current task id
+ */
+ current_task_id = rtems_task_self();
+
+ /*
+ * If this was an attempt to share the task with self,
+ * if somebody wanted to do it... Lets tell them, its shared
+ */
+
+ if( task_id == current_task_id )
+ return RTEMS_SUCCESSFUL;
+ /*
+ * Try to get the requested user environment
+ */
+ sc = rtems_task_variable_get(
+ task_id,
+ (void*)&rtems_current_user_env,
+ (void*)&shared_user_env );
+
+ /*
+ * If it was not successful, return the error code
+ */
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ /*
+ * If we are here, we have the required environment to be
+ * shared with the current task
+ */
+
+ /*
+ * If we have a current environment in place, we need to
+ * free it, since we will be sharing the variable with the
+ * shared_user_env
+ */
+
+ if (rtems_current_user_env->task_id==current_task_id) {
+ rtems_user_env_t *tmp = rtems_current_user_env;
+ free_user_env( tmp );
+ }
+
+ /* the current_user_env is the same pointer that remote env */
+ rtems_current_user_env = shared_user_env;
+
+ /* increase the reference count */
+#ifdef HAVE_USERENV_REFCNT
+ rtems_current_user_env->refcnt++;
+#endif
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libcsupport/src/putk.c b/cpukit/libcsupport/src/putk.c
new file mode 100644
index 0000000000..d804cf05e8
--- /dev/null
+++ b/cpukit/libcsupport/src/putk.c
@@ -0,0 +1,30 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bspIo.h>
+
+/*
+ * putk
+ *
+ * Kernel putk (e.g. puts) function requiring minimal infrastrure.
+ */
+void putk(const char *s)
+{
+ const char *p;
+
+ for (p=s ; *p ; p++ )
+ BSP_output_char(*p);
+ BSP_output_char('\n');
+}
diff --git a/cpukit/libcsupport/src/read.c b/cpukit/libcsupport/src/read.c
new file mode 100644
index 0000000000..f4c3bdc322
--- /dev/null
+++ b/cpukit/libcsupport/src/read.c
@@ -0,0 +1,67 @@
+/*
+ * read() - POSIX 1003.1b 6.4.1 - Read From a File
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t read(
+ int fd,
+ void *buffer,
+ size_t count
+)
+{
+ ssize_t rc;
+ rtems_libio_t *iop;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open( iop );
+ rtems_libio_check_buffer( buffer );
+ rtems_libio_check_count( count );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
+
+ /*
+ * Now process the read().
+ */
+ rc = (*iop->pathinfo.handlers->read_h)( iop, buffer, count );
+
+ if ( rc > 0 )
+ iop->offset += rc;
+
+ return rc;
+}
+
+/*
+ * _read_r
+ *
+ * This is the Newlib dependent reentrant version of read().
+ */
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE__READ_R)
+
+#include <reent.h>
+
+ssize_t _read_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd,
+ void *buf,
+ size_t nbytes
+)
+{
+ return read( fd, buf, nbytes );
+}
+#endif
diff --git a/cpukit/libcsupport/src/readdir_r.c b/cpukit/libcsupport/src/readdir_r.c
new file mode 100644
index 0000000000..f1d53ae593
--- /dev/null
+++ b/cpukit/libcsupport/src/readdir_r.c
@@ -0,0 +1,30 @@
+/*
+ * readdir_r - reentrant version of readdir()
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_READDIR_R
+
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+
+/*
+ * The RTEMS version of readdir is already thread-safe.
+ */
+
+int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
+{
+ *result = readdir(dirp);
+ if (*result)
+ *entry = **result;
+ return *result ? 0 : errno;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/readlink.c b/cpukit/libcsupport/src/readlink.c
new file mode 100644
index 0000000000..1880ed667e
--- /dev/null
+++ b/cpukit/libcsupport/src/readlink.c
@@ -0,0 +1,48 @@
+/*
+ * readlink() - POSIX 1003.1b - X.X.X - XXX
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t readlink(
+ const char *pathname,
+ char *buf,
+ size_t bufsize
+)
+{
+ rtems_filesystem_location_info_t loc;
+ int result;
+
+ if (!buf)
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ result = rtems_filesystem_evaluate_path( pathname, strlen( pathname ),
+ 0, &loc, false );
+ if ( result != 0 )
+ return -1;
+
+ if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_SYM_LINK ){
+ rtems_filesystem_freenode( &loc );
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ result = (*loc.ops->readlink_h)( &loc, buf, bufsize );
+
+ rtems_filesystem_freenode( &loc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/readv.c b/cpukit/libcsupport/src/readv.c
new file mode 100644
index 0000000000..6b33760504
--- /dev/null
+++ b/cpukit/libcsupport/src/readv.c
@@ -0,0 +1,120 @@
+/*
+ * readv() - POSIX 1003.1 - Read a Vector
+ *
+ * OpenGroup URL:
+ *
+ * http://www.opengroup.org/onlinepubs/009695399/functions/readv.html
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t readv(
+ int fd,
+ const struct iovec *iov,
+ int iovcnt
+)
+{
+ ssize_t total;
+ int v;
+ int bytes;
+ rtems_libio_t *iop;
+ bool all_zeros;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open( iop );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
+
+ /*
+ * Argument validation on IO vector
+ */
+ if ( !iov )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( iovcnt <= 0 )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( iovcnt > IOV_MAX )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * OpenGroup says that you are supposed to return EINVAL if the
+ * sum of the iov_len values in the iov array would overflow a
+ * ssize_t.
+ *
+ * Also we would like to ensure that no IO is performed if there
+ * are obvious errors in the iovec. So this extra loop ensures
+ * that we do not do anything if there is an argument error.
+ */
+
+ all_zeros = true;
+ for ( total=0, v=0 ; v < iovcnt ; v++ ) {
+ ssize_t old;
+
+ /*
+ * iov[v].iov_len cannot be less than 0 because size_t is unsigned.
+ * So we only check for zero.
+ */
+ if ( iov[v].iov_base == 0 )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /* check for wrap */
+ old = total;
+ total += iov[v].iov_len;
+ if ( total < old )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( iov[v].iov_len )
+ all_zeros = false;
+ }
+
+ /*
+ * A readv with all zeros logically has no effect. Even though
+ * OpenGroup didn't address this case as they did with writev(),
+ * we will handle it the same way for symmetry.
+ */
+ if ( all_zeros == true ) {
+ return 0;
+ }
+
+ /*
+ * Now process the readv().
+ */
+ for ( total=0, v=0 ; v < iovcnt ; v++ ) {
+ bytes = (*iop->pathinfo.handlers->read_h)(
+ iop,
+ iov[v].iov_base,
+ iov[v].iov_len
+ );
+
+ if ( bytes < 0 )
+ return -1;
+
+ if ( bytes > 0 ) {
+ iop->offset += bytes;
+ total += bytes;
+ }
+
+ if (bytes != iov[ v ].iov_len)
+ break;
+ }
+
+ return total;
+}
diff --git a/cpukit/libcsupport/src/realloc.c b/cpukit/libcsupport/src/realloc.c
new file mode 100644
index 0000000000..3689f32e61
--- /dev/null
+++ b/cpukit/libcsupport/src/realloc.c
@@ -0,0 +1,88 @@
+/*
+ * calloc()
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+#include <stdlib.h>
+#include <errno.h>
+
+void *realloc(
+ void *ptr,
+ size_t size
+)
+{
+ uintptr_t old_size;
+ char *new_area;
+
+ MSBUMP(realloc_calls, 1);
+
+ /*
+ * Do not attempt to allocate memory if in a critical section or ISR.
+ */
+
+ if (_System_state_Is_up(_System_state_Get())) {
+ if (_Thread_Dispatch_disable_level > 0)
+ return (void *) 0;
+
+ if (_ISR_Nest_level > 0)
+ return (void *) 0;
+ }
+
+ /*
+ * Continue with realloc().
+ */
+ if ( !ptr )
+ return malloc( size );
+
+ if ( !size ) {
+ free( ptr );
+ return (void *) 0;
+ }
+
+ if ( !_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, ptr, &old_size) ) {
+ errno = EINVAL;
+ return (void *) 0;
+ }
+
+ /*
+ * Now resize it.
+ */
+ if ( _Protected_heap_Resize_block( RTEMS_Malloc_Heap, ptr, size ) ) {
+ return ptr;
+ }
+
+ /*
+ * There used to be a free on this error case but it is wrong to
+ * free the memory per OpenGroup Single UNIX Specification V2
+ * and the C Standard.
+ */
+
+ new_area = malloc( size );
+
+ MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */
+
+ if ( !new_area ) {
+ return (void *) 0;
+ }
+
+ memcpy( new_area, ptr, (size < old_size) ? size : old_size );
+ free( ptr );
+
+ return new_area;
+
+}
+#endif
diff --git a/cpukit/libcsupport/src/rmdir.c b/cpukit/libcsupport/src/rmdir.c
new file mode 100644
index 0000000000..d7d4edf675
--- /dev/null
+++ b/cpukit/libcsupport/src/rmdir.c
@@ -0,0 +1,95 @@
+/*
+ * rmdir() - POSIX 1003.1b - 5.2.2 - Remove a Directory
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rmdir(
+ const char *pathname
+)
+{
+ int parentpathlen;
+ const char *name;
+ rtems_filesystem_location_info_t parentloc;
+ rtems_filesystem_location_info_t loc;
+ int i;
+ int result;
+ bool free_parentloc = false;
+
+ /*
+ * Get the parent node of the node we wish to remove. Find the parent path.
+ */
+
+ parentpathlen = rtems_filesystem_dirname ( pathname );
+
+ if ( parentpathlen == 0 )
+ rtems_filesystem_get_start_loc( pathname, &i, &parentloc );
+ else {
+ result = rtems_filesystem_evaluate_path(pathname, parentpathlen,
+ RTEMS_LIBIO_PERMS_WRITE,
+ &parentloc,
+ false );
+ if ( result != 0 )
+ return -1;
+
+ free_parentloc = true;
+ }
+
+ /*
+ * Start from the parent to find the node that should be under it.
+ */
+
+ loc = parentloc;
+ name = pathname + parentpathlen;
+ name += rtems_filesystem_prefix_separators( name, strlen( name ) );
+
+ result = rtems_filesystem_evaluate_relative_path( name , strlen( name ),
+ 0, &loc, false );
+ if ( result != 0 ) {
+ if ( free_parentloc )
+ rtems_filesystem_freenode( &parentloc );
+ return -1;
+ }
+
+ /*
+ * Verify you can remove this node as a directory.
+ */
+ if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
+ rtems_filesystem_freenode( &loc );
+ if ( free_parentloc )
+ rtems_filesystem_freenode( &parentloc );
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+ }
+
+ /*
+ * Use the filesystems rmnod to remove the node.
+ */
+
+ result = (*loc.handlers->rmnod_h)( &parentloc, &loc );
+
+ rtems_filesystem_freenode( &loc );
+ if ( free_parentloc )
+ rtems_filesystem_freenode( &parentloc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/rtems_heap_extend.c b/cpukit/libcsupport/src/rtems_heap_extend.c
new file mode 100644
index 0000000000..5916852278
--- /dev/null
+++ b/cpukit/libcsupport/src/rtems_heap_extend.c
@@ -0,0 +1,45 @@
+/**
+ * @file
+ *
+ * @ingroup libcsupport
+ *
+ * @brief rtems_heap_extend() implementation.
+ */
+
+/*
+ * Copyright (c) 2011 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+rtems_status_code rtems_heap_extend(
+ void *area_begin,
+ uintptr_t area_size
+)
+{
+ bool ok = _Protected_heap_Extend(RTEMS_Malloc_Heap, area_begin, area_size);
+
+ if (ok) {
+ return RTEMS_SUCCESSFUL;
+ } else {
+ return RTEMS_INVALID_ADDRESS;
+ }
+}
+#endif /* RTEMS_NEWLIB */
diff --git a/cpukit/libcsupport/src/rtems_malloc.c b/cpukit/libcsupport/src/rtems_malloc.c
new file mode 100644
index 0000000000..fcd99438f0
--- /dev/null
+++ b/cpukit/libcsupport/src/rtems_malloc.c
@@ -0,0 +1,56 @@
+/**
+ * @file
+ *
+ * @ingroup libcsupport
+ *
+ * @brief rtems_malloc() implementation.
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+void *rtems_heap_allocate_aligned_with_boundary(
+ size_t size,
+ uintptr_t alignment,
+ uintptr_t boundary
+)
+{
+ if (
+ _System_state_Is_up( _System_state_Get() )
+ && !malloc_is_system_state_OK()
+ ) {
+ return NULL;
+ }
+
+ malloc_deferred_frees_process();
+
+ /* FIXME: Statistics, boundary checks */
+
+ return _Protected_heap_Allocate_aligned_with_boundary(
+ RTEMS_Malloc_Heap,
+ size,
+ alignment,
+ boundary
+ );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/rtems_memalign.c b/cpukit/libcsupport/src/rtems_memalign.c
new file mode 100644
index 0000000000..2d64cbbfd6
--- /dev/null
+++ b/cpukit/libcsupport/src/rtems_memalign.c
@@ -0,0 +1,72 @@
+/*
+ * rtems_memalign() - Raw aligned allocate from Protected Heap
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+#include <stdlib.h>
+#include <errno.h>
+
+int rtems_memalign(
+ void **pointer,
+ size_t alignment,
+ size_t size
+)
+{
+ void *return_this;
+
+ /*
+ * Parameter error checks
+ */
+ if ( !pointer )
+ return EINVAL;
+
+ *pointer = NULL;
+
+ /*
+ * Do not attempt to allocate memory if not in correct system state.
+ */
+ if ( _System_state_Is_up(_System_state_Get()) &&
+ !malloc_is_system_state_OK() )
+ return EINVAL;
+
+ /*
+ * If some free's have been deferred, then do them now.
+ */
+ malloc_deferred_frees_process();
+
+ /*
+ * Perform the aligned allocation requested
+ */
+ return_this = _Protected_heap_Allocate_aligned(
+ RTEMS_Malloc_Heap,
+ size,
+ alignment
+ );
+ if ( !return_this )
+ return ENOMEM;
+
+ /*
+ * If configured, update the more involved statistics
+ */
+ if ( rtems_malloc_statistics_helpers )
+ (*rtems_malloc_statistics_helpers->at_malloc)(pointer);
+
+ *pointer = return_this;
+ return 0;
+}
+#endif
diff --git a/cpukit/libcsupport/src/rtems_mkdir.c b/cpukit/libcsupport/src/rtems_mkdir.c
new file mode 100644
index 0000000000..86ef7e1b84
--- /dev/null
+++ b/cpukit/libcsupport/src/rtems_mkdir.c
@@ -0,0 +1,141 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief rtems_mkdir() implementation.
+ *
+ * The implementation is based on FreeBSD 'bin/mkdir/mkdir.c' revision 163213.
+ */
+
+/*-
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * Copyright (c) 1983, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rtems/libio.h>
+
+/*
+ * Returns 1 if a directory has been created,
+ * 2 if it already existed, and 0 on failure.
+ */
+static int
+build(char *path, mode_t omode)
+{
+ struct stat sb;
+ mode_t numask, oumask;
+ int first, last, retval;
+ char *p;
+
+ p = path;
+ oumask = 0;
+ retval = 1;
+ if (p[0] == '/') /* Skip leading '/'. */
+ ++p;
+ for (first = 1, last = 0; !last ; ++p) {
+ if (p[0] == '\0')
+ last = 1;
+ else if (p[0] != '/')
+ continue;
+ *p = '\0';
+ if (!last && p[1] == '\0')
+ last = 1;
+ if (first) {
+ /*
+ * POSIX 1003.2:
+ * For each dir operand that does not name an existing
+ * directory, effects equivalent to those caused by the
+ * following command shall occcur:
+ *
+ * mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
+ * mkdir [-m mode] dir
+ *
+ * We change the user's umask and then restore it,
+ * instead of doing chmod's.
+ */
+ oumask = umask(0);
+ numask = oumask & ~(S_IWUSR | S_IXUSR);
+ (void)umask(numask);
+ first = 0;
+ }
+ if (last)
+ (void)umask(oumask);
+ if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
+ if (errno == EEXIST || errno == EISDIR) {
+ if (stat(path, &sb) < 0) {
+ retval = 0;
+ break;
+ } else if (!S_ISDIR(sb.st_mode)) {
+ if (last)
+ errno = EEXIST;
+ else
+ errno = ENOTDIR;
+ retval = 0;
+ break;
+ }
+ if (last)
+ retval = 2;
+ } else {
+ retval = 0;
+ break;
+ }
+ }
+ if (!last)
+ *p = '/';
+ }
+ if (!first && !last)
+ (void)umask(oumask);
+ return (retval);
+}
+
+int
+rtems_mkdir(const char *path, mode_t mode)
+{
+ int success = 0;
+ char *dup_path = strdup(path);
+
+ if (dup_path != NULL) {
+ success = build(dup_path, mode);
+ free(dup_path);
+ }
+
+ return success != 0 ? 0 : -1;
+}
diff --git a/cpukit/libcsupport/src/setegid.c b/cpukit/libcsupport/src/setegid.c
new file mode 100644
index 0000000000..04b93fa070
--- /dev/null
+++ b/cpukit/libcsupport/src/setegid.c
@@ -0,0 +1,26 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+#include <rtems/userenv.h>
+
+/*
+ * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs,
+ * P1003.1b-1993, p. 84
+ */
+int setegid(
+ gid_t gid
+)
+{
+ _POSIX_types_Egid = gid;
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/seteuid.c b/cpukit/libcsupport/src/seteuid.c
new file mode 100644
index 0000000000..262641cde3
--- /dev/null
+++ b/cpukit/libcsupport/src/seteuid.c
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/userenv.h>
+
+int seteuid( uid_t euid )
+{
+ _POSIX_types_Euid = euid;
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/setgid.c b/cpukit/libcsupport/src/setgid.c
new file mode 100644
index 0000000000..908899cf72
--- /dev/null
+++ b/cpukit/libcsupport/src/setgid.c
@@ -0,0 +1,21 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/userenv.h>
+
+/*
+ *
+ * 4.2.2 Set User and Group IDs, P1003.1b-1993, p. 84
+ */
+int setgid(
+ gid_t gid
+)
+{
+ _POSIX_types_Gid = gid;
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/setpgid.c b/cpukit/libcsupport/src/setpgid.c
new file mode 100644
index 0000000000..ba8f7afc62
--- /dev/null
+++ b/cpukit/libcsupport/src/setpgid.c
@@ -0,0 +1,24 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 4.3.3 Set Process Group ID for Job Control, P1003.1b-1993, p. 89
+ */
+
+int setpgid(
+ pid_t pid __attribute__((unused)),
+ pid_t pgid __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/libcsupport/src/setsid.c b/cpukit/libcsupport/src/setsid.c
new file mode 100644
index 0000000000..cbebdb4952
--- /dev/null
+++ b/cpukit/libcsupport/src/setsid.c
@@ -0,0 +1,21 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 4.3.2 Create Session and Set Process Group ID, P1003.1b-1993, p. 88
+ */
+
+pid_t setsid( void )
+{
+ rtems_set_errno_and_return_minus_one( EPERM );
+}
diff --git a/cpukit/libcsupport/src/setuid.c b/cpukit/libcsupport/src/setuid.c
new file mode 100644
index 0000000000..0e4234ba09
--- /dev/null
+++ b/cpukit/libcsupport/src/setuid.c
@@ -0,0 +1,30 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/userenv.h>
+
+/*
+ *
+ * 4.2.2 Set User and Group IDs, P1003.1b-1993, p. 84
+ */
+int setuid(
+ uid_t uid
+)
+{
+ _POSIX_types_Uid = uid;
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/stat.c b/cpukit/libcsupport/src/stat.c
new file mode 100644
index 0000000000..9f06deaa52
--- /dev/null
+++ b/cpukit/libcsupport/src/stat.c
@@ -0,0 +1,97 @@
+/*
+ * stat() - POSIX 1003.1b 5.6.2 - Get File Status
+ *
+ * Reused from lstat().
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * lstat() and stat() share the same implementation with a minor
+ * difference on how links are evaluated.
+ */
+
+#ifndef _STAT_NAME
+#define _STAT_NAME stat
+#define _STAT_R_NAME _stat_r
+#define _STAT_FOLLOW_LINKS true
+#endif
+
+
+#include <rtems.h>
+
+#include <rtems/libio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int _STAT_NAME(
+ const char *path,
+ struct stat *buf
+)
+{
+ int status;
+ rtems_filesystem_location_info_t loc;
+
+ /*
+ * Check to see if we were passed a valid pointer.
+ */
+
+ if ( !buf )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ status = rtems_filesystem_evaluate_path( path, strlen( path ),
+ 0, &loc, _STAT_FOLLOW_LINKS );
+ if ( status != 0 )
+ return -1;
+
+ /*
+ * Zero out the stat structure so the various support
+ * versions of stat don't have to.
+ */
+
+ memset( buf, 0, sizeof(struct stat) );
+
+ status = (*loc.handlers->fstat_h)( &loc, buf );
+
+ rtems_filesystem_freenode( &loc );
+
+ return status;
+}
+
+/*
+ * _stat_r, _lstat_r
+ *
+ * This is the Newlib dependent reentrant version of stat() and lstat().
+ */
+
+#if defined(RTEMS_NEWLIB)
+
+#include <reent.h>
+
+int _STAT_R_NAME(
+ struct _reent *ptr __attribute__((unused)),
+ const char *path,
+ struct stat *buf
+)
+{
+ return _STAT_NAME( path, buf );
+}
+#endif
diff --git a/cpukit/libcsupport/src/statvfs.c b/cpukit/libcsupport/src/statvfs.c
new file mode 100644
index 0000000000..599aa7edc1
--- /dev/null
+++ b/cpukit/libcsupport/src/statvfs.c
@@ -0,0 +1,52 @@
+/*
+ * COPYRIGHT (c) 2009 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/*
+ * The statvfs as defined by the SUS:
+ * http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/statvfs.h.html
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#include <sys/statvfs.h>
+
+int
+statvfs (const char *path, struct statvfs *sb)
+{
+ rtems_filesystem_location_info_t loc;
+ rtems_filesystem_location_info_t *fs_mount_root;
+ rtems_filesystem_mount_table_entry_t *mt_entry;
+ int result;
+
+ /*
+ * Get
+ * The root node of the mounted filesytem.
+ * The node for the directory that the fileystem is mounted on.
+ * The mount entry that is being refered to.
+ */
+
+ if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x0, &loc, true ) )
+ return -1;
+
+ mt_entry = loc.mt_entry;
+ fs_mount_root = &mt_entry->mt_fs_root;
+
+ memset (sb, 0, sizeof (struct statvfs));
+
+ result = ( fs_mount_root->ops->statvfs_h )( fs_mount_root, sb );
+
+ rtems_filesystem_freenode( &loc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/strlcat.c b/cpukit/libcsupport/src/strlcat.c
new file mode 100644
index 0000000000..b617cb93e8
--- /dev/null
+++ b/cpukit/libcsupport/src/strlcat.c
@@ -0,0 +1,41 @@
+/*
+ * utils.c - various utility functions used in pppd.
+ *
+ * Copyright (c) 1999 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#ifndef HAVE_STRLCAT
+/*
+ * strlcat - like strcat/strncat, doesn't overflow destination buffer,
+ * always leaves destination null-terminated (for len > 0).
+ */
+size_t
+strlcat(
+ char *dest,
+ const char *src,
+ size_t len )
+{
+ size_t dlen = strlen(dest);
+
+ return dlen + strlcpy(dest + dlen, src, (len > dlen? len - dlen: 0));
+}
+#endif
diff --git a/cpukit/libcsupport/src/strlcpy.c b/cpukit/libcsupport/src/strlcpy.c
new file mode 100644
index 0000000000..2773e877cb
--- /dev/null
+++ b/cpukit/libcsupport/src/strlcpy.c
@@ -0,0 +1,49 @@
+/*
+ * utils.c - various utility functions used in pppd.
+ *
+ * Copyright (c) 1999 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#ifndef HAVE_STRLCPY
+/*
+ * strlcpy - like strcpy/strncpy, doesn't overflow destination buffer,
+ * always leaves destination null-terminated (for len > 0).
+ */
+size_t
+strlcpy(dest, src, len)
+ char *dest;
+ const char *src;
+ size_t len;
+{
+ size_t ret = strlen(src);
+
+ if (len != 0) {
+ if (ret < len)
+ strcpy(dest, src);
+ else {
+ strncpy(dest, src, len - 1);
+ dest[len-1] = 0;
+ }
+ }
+ return ret;
+}
+#endif
diff --git a/cpukit/libcsupport/src/sup_fs_get_start_loc.c b/cpukit/libcsupport/src/sup_fs_get_start_loc.c
new file mode 100644
index 0000000000..89f7efbb0d
--- /dev/null
+++ b/cpukit/libcsupport/src/sup_fs_get_start_loc.c
@@ -0,0 +1,48 @@
+ /**
+ * @file src/sup_fs_get_start_loc.c
+ */
+
+/*
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * rtems_filesystem_get_start_loc
+ *
+ * Function to determine if path is absolute or relative
+ *
+ * Parameters:
+ *
+ * path : IN - path to be checked
+ * index: OUT - 0, if relative, 1 if absolute
+ * loc : OUT - location info of root fs if absolute
+ * location info of current fs if relative
+ *
+ * Returns: void
+ */
+
+/* Includes */
+
+#include "rtems/libio_.h"
+
+void rtems_filesystem_get_start_loc(const char *path,
+ int *index,
+ rtems_filesystem_location_info_t *loc)
+{
+ if (rtems_filesystem_is_separator(path[0])) {
+ *loc = rtems_filesystem_root;
+ *index = 1;
+ }
+ else {
+ *loc = rtems_filesystem_current;
+ *index = 0;
+ }
+}
diff --git a/cpukit/libcsupport/src/sup_fs_get_sym_start_loc.c b/cpukit/libcsupport/src/sup_fs_get_sym_start_loc.c
new file mode 100644
index 0000000000..4bcc964a46
--- /dev/null
+++ b/cpukit/libcsupport/src/sup_fs_get_sym_start_loc.c
@@ -0,0 +1,47 @@
+ /**
+ * @file src/sup_fs_get_sym_start_loc.c
+ */
+
+/*
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * rtems_filesystem_get_sym_start_loc
+ *
+ * Function to determine if path is absolute or relative
+ *
+ * Parameters:
+ *
+ * path : IN - path to be checked
+ * index: OUT - 0, if relative, 1 if absolute
+ * loc : OUT - location info of root fs if absolute
+ * location info of current fs if relative
+ *
+ * Returns: void
+ */
+
+/* Includes */
+
+#include "rtems/libio_.h"
+
+void rtems_filesystem_get_sym_start_loc(const char *path,
+ int *index,
+ rtems_filesystem_location_info_t *loc)
+{
+ if (rtems_filesystem_is_separator(path[0])) {
+ *loc = rtems_filesystem_root;
+ *index = 1;
+ }
+ else {
+ *index = 0;
+ }
+}
diff --git a/cpukit/libcsupport/src/sup_fs_is_separator.c b/cpukit/libcsupport/src/sup_fs_is_separator.c
new file mode 100644
index 0000000000..affd606271
--- /dev/null
+++ b/cpukit/libcsupport/src/sup_fs_is_separator.c
@@ -0,0 +1,30 @@
+/**
+ * @file src/sup_fs_is_separator.c
+ */
+
+/*
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+/*
+ * rtems_filesystem_is_separator
+ *
+ * Function to determine if a character is a path name separator.
+ * This was originally a macro in libio_.h
+ *
+ * NOTE: This function handles MS-DOS and UNIX style names.
+ */
+
+int rtems_filesystem_is_separator(char ch)
+{
+ return ((ch == '/') || (ch == '\\') || (ch == '\0'));
+}
diff --git a/cpukit/libcsupport/src/symlink.c b/cpukit/libcsupport/src/symlink.c
new file mode 100644
index 0000000000..be29980911
--- /dev/null
+++ b/cpukit/libcsupport/src/symlink.c
@@ -0,0 +1,42 @@
+/*
+ * symlink() - POSIX 1003.1b - X.X.X - XXX
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int symlink(
+ const char *actualpath,
+ const char *sympath
+)
+{
+ rtems_filesystem_location_info_t loc;
+ int i;
+ const char *name_start;
+ int result;
+
+ rtems_filesystem_get_start_loc( sympath, &i, &loc );
+
+ result = (*loc.ops->evalformake_h)( &sympath[i], &loc, &name_start );
+ if ( result != 0 )
+ return -1;
+
+ result = (*loc.ops->symlink_h)( &loc, actualpath, name_start);
+
+ rtems_filesystem_freenode( &loc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/sync.c b/cpukit/libcsupport/src/sync.c
new file mode 100644
index 0000000000..e1deefc293
--- /dev/null
+++ b/cpukit/libcsupport/src/sync.c
@@ -0,0 +1,101 @@
+/*
+ * sync() - XXX ??? where is this defined
+ *
+ * This function operates by as follows:
+ * for all threads
+ * for all FILE *
+ * fsync()
+ * fdatasync()
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Since we compile with strict ANSI we need to undef it to get
+ * prototypes for extensions
+ */
+#undef __STRICT_ANSI__
+int fdatasync(int); /* still not always prototyped */
+
+
+#include <unistd.h>
+#include <stdio.h>
+
+#include <rtems.h>
+/*
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+*/
+
+/* XXX check standards -- Linux version appears to be void */
+void _fwalk(struct _reent *, void *);
+
+
+static void sync_wrapper(FILE *f)
+{
+ int fn = fileno(f);
+
+ /*
+ * We are explicitly NOT checking the return values as it does not
+ * matter if they succeed. We are just making a best faith attempt
+ * at both and trusting that we were passed a good FILE pointer.
+ */
+ fsync(fn);
+ fdatasync(fn);
+}
+
+/* iterate over all FILE *'s for this thread */
+static void sync_per_thread(Thread_Control *t)
+{
+ struct _reent *current_reent;
+ struct _reent *this_reent;
+
+ /*
+ * The sync_wrapper() function will operate on the current thread's
+ * reent structure so we will temporarily use that.
+ */
+ this_reent = t->libc_reent;
+ if ( this_reent ) {
+ current_reent = _Thread_Executing->libc_reent;
+ _Thread_Executing->libc_reent = this_reent;
+ _fwalk (t->libc_reent, sync_wrapper);
+ _Thread_Executing->libc_reent = current_reent;
+ }
+}
+
+/*
+ * _global_impure_ptr is not prototyped in any .h files.
+ * We have to extern it here.
+ */
+extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
+
+void sync(void)
+{
+
+ /*
+ * Walk the one used initially by RTEMS.
+ */
+ _fwalk(_global_impure_ptr, sync_wrapper);
+
+ /*
+ * XXX Do we walk the one used globally by newlib?
+ * XXX Do we need the RTEMS global one?
+ */
+
+ /*
+ * Now walk all the per-thread reentrancy structures.
+ */
+ rtems_iterate_over_all_threads(sync_per_thread);
+}
diff --git a/cpukit/libcsupport/src/tcdrain.c b/cpukit/libcsupport/src/tcdrain.c
new file mode 100644
index 0000000000..c2e9d5e2ee
--- /dev/null
+++ b/cpukit/libcsupport/src/tcdrain.c
@@ -0,0 +1,36 @@
+/*
+ * tcdrain() - POSIX 1003.1b 7.2.2 - Line Control Functions
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+/* #include <sys/ioctl.h> */
+
+#include <rtems/libio.h>
+
+int tcdrain(
+ int fd
+)
+{
+ return ioctl( fd, RTEMS_IO_TCDRAIN, 0 );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/tcflow.c b/cpukit/libcsupport/src/tcflow.c
new file mode 100644
index 0000000000..d4d3945f38
--- /dev/null
+++ b/cpukit/libcsupport/src/tcflow.c
@@ -0,0 +1,44 @@
+/*
+ * tcflow() - POSIX 1003.1b 7.2.2 - Line Control Functions
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB)
+#include <termios.h>
+#include <unistd.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int tcflow (
+ int fd __attribute__((unused)),
+ int action
+)
+{
+ switch (action) {
+ case TCOOFF:
+ case TCOON:
+ case TCIOFF:
+ case TCION:
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ /* fd is not validated */
+
+ /* When this is supported, implement it here */
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/tcflush.c b/cpukit/libcsupport/src/tcflush.c
new file mode 100644
index 0000000000..6546966384
--- /dev/null
+++ b/cpukit/libcsupport/src/tcflush.c
@@ -0,0 +1,50 @@
+/*
+ * tcflush() - POSIX 1003.1b 7.2.2 - Line Control Functions
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+/* #include <sys/ioctl.h> */
+
+#include <rtems/seterr.h>
+#include <rtems/libio.h>
+
+int tcflush (
+ int fd __attribute__((unused)),
+ int queue
+)
+{
+ switch (queue) {
+ case TCIFLUSH:
+ case TCOFLUSH:
+ case TCIOFLUSH:
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ /* fd is not validated */
+
+ /* When this is supported, implement it here */
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/tcgetattr.c b/cpukit/libcsupport/src/tcgetattr.c
new file mode 100644
index 0000000000..8d4eb0618b
--- /dev/null
+++ b/cpukit/libcsupport/src/tcgetattr.c
@@ -0,0 +1,36 @@
+/*
+ * tcgetattr() - POSIX 1003.1b 7.2.1 - Get and Set State
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+/* #include <sys/ioctl.h> */
+
+#include <rtems/libio.h>
+
+int tcgetattr(
+ int fd,
+ struct termios *tp
+)
+{
+ return ioctl( fd, RTEMS_IO_GET_ATTRIBUTES, tp );
+}
+#endif
diff --git a/cpukit/libcsupport/src/tcgetpgrp.c b/cpukit/libcsupport/src/tcgetpgrp.c
new file mode 100644
index 0000000000..8894e46eef
--- /dev/null
+++ b/cpukit/libcsupport/src/tcgetpgrp.c
@@ -0,0 +1,28 @@
+/*
+ * tcgetprgrp() - POSIX 1003.1b 7.2.3 - Get Foreground Process Group ID
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_NEWLIB) && !defined(HAVE_TCGETPGRP)
+
+#include <sys/types.h>
+#include <unistd.h>
+
+pid_t tcgetpgrp(int fd __attribute__((unused)))
+{
+ return getpid();
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/tcsendbreak.c b/cpukit/libcsupport/src/tcsendbreak.c
new file mode 100644
index 0000000000..300e7a8f85
--- /dev/null
+++ b/cpukit/libcsupport/src/tcsendbreak.c
@@ -0,0 +1,36 @@
+/*
+ * tcsendbreak() - POSIX 1003.1b 7.2.2 - Line Control Functions
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+/* #include <sys/ioctl.h> */
+
+#include <rtems/libio.h>
+
+int tcsendbreak (
+ int fd __attribute__((unused)),
+ int duration __attribute__((unused)) )
+{
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/tcsetattr.c b/cpukit/libcsupport/src/tcsetattr.c
new file mode 100644
index 0000000000..187c1df584
--- /dev/null
+++ b/cpukit/libcsupport/src/tcsetattr.c
@@ -0,0 +1,51 @@
+/*
+ * tcsetattr() - POSIX 1003.1b 7.2.1 - Get and Set State
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+/* #include <sys/ioctl.h> */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int tcsetattr(
+ int fd,
+ int opt,
+ struct termios *tp
+)
+{
+ switch (opt) {
+ default:
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+
+ case TCSADRAIN:
+ if (ioctl( fd, RTEMS_IO_TCDRAIN, NULL ) < 0)
+ return -1;
+ /*
+ * Fall through to....
+ */
+ case TCSANOW:
+ return ioctl( fd, RTEMS_IO_SET_ATTRIBUTES, tp );
+ }
+}
+#endif
diff --git a/cpukit/libcsupport/src/tcsetpgrp.c b/cpukit/libcsupport/src/tcsetpgrp.c
new file mode 100644
index 0000000000..f8e48025b6
--- /dev/null
+++ b/cpukit/libcsupport/src/tcsetpgrp.c
@@ -0,0 +1,36 @@
+/*
+ * tcsetprgrp() - POSIX 1003.1b 7.2.4 - Set Foreground Process Group ID
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#if defined(RTEMS_NEWLIB)
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <termios.h>
+/* #include <sys/ioctl.h> */
+
+#include <rtems/libio.h>
+
+int tcsetpgrp(
+ int fd __attribute__((unused)),
+ pid_t pid __attribute__((unused)) )
+{
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
new file mode 100644
index 0000000000..4085c5e4a2
--- /dev/null
+++ b/cpukit/libcsupport/src/termios.c
@@ -0,0 +1,1480 @@
+/*
+ * TERMIOS serial line support
+ *
+ * Author:
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ttycom.h>
+
+#include <rtems/termiostypes.h>
+
+/*
+ * The size of the cooked buffer
+ */
+#define CBUFSIZE (rtems_termios_cbufsize)
+
+/*
+ * The sizes of the raw message buffers.
+ * On most architectures it is quite a bit more
+ * efficient if these are powers of two.
+ */
+#define RAW_INPUT_BUFFER_SIZE (rtems_termios_raw_input_size)
+#define RAW_OUTPUT_BUFFER_SIZE (rtems_termios_raw_output_size)
+
+/* fields for "flow_ctrl" status */
+#define FL_IREQXOF 1 /* input queue requests stop of incoming data */
+#define FL_ISNTXOF 2 /* XOFF has been sent to other side of line */
+#define FL_IRTSOFF 4 /* RTS has been turned off for other side.. */
+
+#define FL_ORCVXOF 0x10 /* XOFF has been received */
+#define FL_OSTOP 0x20 /* output has been stopped due to XOFF */
+
+#define FL_MDRTS 0x100 /* input controlled with RTS/CTS handshake */
+#define FL_MDXON 0x200 /* input controlled with XON/XOFF protocol */
+#define FL_MDXOF 0x400 /* output controlled with XON/XOFF protocol */
+
+#define NODISC(n) \
+ { NULL, NULL, NULL, NULL, \
+ NULL, NULL, NULL, NULL }
+/*
+ * FIXME: change rtems_termios_linesw entries consistent
+ * with rtems_termios_linesw entry usage...
+ */
+struct rtems_termios_linesw rtems_termios_linesw[MAXLDISC] =
+{
+ NODISC(0), /* 0- termios-built-in */
+ NODISC(1), /* 1- defunct */
+ NODISC(2), /* 2- NTTYDISC */
+ NODISC(3), /* TABLDISC */
+ NODISC(4), /* SLIPDISC */
+ NODISC(5), /* PPPDISC */
+ NODISC(6), /* loadable */
+ NODISC(7), /* loadable */
+};
+
+int rtems_termios_nlinesw =
+ sizeof (rtems_termios_linesw) / sizeof (rtems_termios_linesw[0]);
+
+extern struct rtems_termios_tty *rtems_termios_ttyHead;
+extern struct rtems_termios_tty *rtems_termios_ttyTail;
+extern rtems_id rtems_termios_ttyMutex;
+
+static int rtems_termios_cbufsize = 256;
+static int rtems_termios_raw_input_size = 128;
+static int rtems_termios_raw_output_size = 64;
+
+static rtems_task rtems_termios_rxdaemon(rtems_task_argument argument);
+static rtems_task rtems_termios_txdaemon(rtems_task_argument argument);
+/*
+ * some constants for I/O daemon task creation
+ */
+#define TERMIOS_TXTASK_PRIO 10
+#define TERMIOS_RXTASK_PRIO 9
+#define TERMIOS_TXTASK_STACKSIZE 1024
+#define TERMIOS_RXTASK_STACKSIZE 1024
+/*
+ * some events to be sent to the I/O tasks
+ */
+#define TERMIOS_TX_START_EVENT RTEMS_EVENT_1
+#define TERMIOS_TX_TERMINATE_EVENT RTEMS_EVENT_0
+
+#define TERMIOS_RX_PROC_EVENT RTEMS_EVENT_1
+#define TERMIOS_RX_TERMINATE_EVENT RTEMS_EVENT_0
+
+/*
+ * Open a termios device
+ */
+rtems_status_code
+rtems_termios_open (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg,
+ const rtems_termios_callbacks *callbacks
+)
+{
+ rtems_status_code sc;
+ rtems_libio_open_close_args_t *args = arg;
+ struct rtems_termios_tty *tty;
+
+ /*
+ * See if the device has already been opened
+ */
+ sc = rtems_semaphore_obtain(
+ rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ for (tty = rtems_termios_ttyHead ; tty != NULL ; tty = tty->forw) {
+ if ((tty->major == major) && (tty->minor == minor))
+ break;
+ }
+
+ if (tty == NULL) {
+ static char c = 'a';
+
+ /*
+ * Create a new device
+ */
+ tty = calloc (1, sizeof (struct rtems_termios_tty));
+ if (tty == NULL) {
+ rtems_semaphore_release (rtems_termios_ttyMutex);
+ return RTEMS_NO_MEMORY;
+ }
+ /*
+ * allocate raw input buffer
+ */
+ tty->rawInBuf.Size = RAW_INPUT_BUFFER_SIZE;
+ tty->rawInBuf.theBuf = malloc (tty->rawInBuf.Size);
+ if (tty->rawInBuf.theBuf == NULL) {
+ free(tty);
+ rtems_semaphore_release (rtems_termios_ttyMutex);
+ return RTEMS_NO_MEMORY;
+ }
+ /*
+ * allocate raw output buffer
+ */
+ tty->rawOutBuf.Size = RAW_OUTPUT_BUFFER_SIZE;
+ tty->rawOutBuf.theBuf = malloc (tty->rawOutBuf.Size);
+ if (tty->rawOutBuf.theBuf == NULL) {
+ free((void *)(tty->rawInBuf.theBuf));
+ free(tty);
+ rtems_semaphore_release (rtems_termios_ttyMutex);
+ return RTEMS_NO_MEMORY;
+ }
+ /*
+ * allocate cooked buffer
+ */
+ tty->cbuf = malloc (CBUFSIZE);
+ if (tty->cbuf == NULL) {
+ free((void *)(tty->rawOutBuf.theBuf));
+ free((void *)(tty->rawInBuf.theBuf));
+ free(tty);
+ rtems_semaphore_release (rtems_termios_ttyMutex);
+ return RTEMS_NO_MEMORY;
+ }
+ /*
+ * Initialize wakeup callbacks
+ */
+ tty->tty_snd.sw_pfn = NULL;
+ tty->tty_snd.sw_arg = NULL;
+ tty->tty_rcv.sw_pfn = NULL;
+ tty->tty_rcv.sw_arg = NULL;
+ tty->tty_rcvwakeup = 0;
+
+ /*
+ * link tty
+ */
+ tty->forw = rtems_termios_ttyHead;
+ tty->back = NULL;
+ if (rtems_termios_ttyHead != NULL)
+ rtems_termios_ttyHead->back = tty;
+ rtems_termios_ttyHead = tty;
+ if (rtems_termios_ttyTail == NULL)
+ rtems_termios_ttyTail = tty;
+
+ tty->minor = minor;
+ tty->major = major;
+
+ /*
+ * Set up mutex semaphores
+ */
+ sc = rtems_semaphore_create (
+ rtems_build_name ('T', 'R', 'i', c),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &tty->isem);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ sc = rtems_semaphore_create (
+ rtems_build_name ('T', 'R', 'o', c),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &tty->osem);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ sc = rtems_semaphore_create (
+ rtems_build_name ('T', 'R', 'x', c),
+ 0,
+ RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO,
+ RTEMS_NO_PRIORITY,
+ &tty->rawOutBuf.Semaphore);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ tty->rawOutBufState = rob_idle;
+
+ /*
+ * Set callbacks
+ */
+ tty->device = *callbacks;
+
+ /*
+ * Create I/O tasks
+ */
+ if (tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN) {
+ sc = rtems_task_create (
+ rtems_build_name ('T', 'x', 'T', c),
+ TERMIOS_TXTASK_PRIO,
+ TERMIOS_TXTASK_STACKSIZE,
+ RTEMS_NO_PREEMPT | RTEMS_NO_TIMESLICE |
+ RTEMS_NO_ASR,
+ RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
+ &tty->txTaskId);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ sc = rtems_task_create (
+ rtems_build_name ('R', 'x', 'T', c),
+ TERMIOS_RXTASK_PRIO,
+ TERMIOS_RXTASK_STACKSIZE,
+ RTEMS_NO_PREEMPT | RTEMS_NO_TIMESLICE |
+ RTEMS_NO_ASR,
+ RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
+ &tty->rxTaskId);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+
+ }
+ if ((tty->device.pollRead == NULL) ||
+ (tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN)){
+ sc = rtems_semaphore_create (
+ rtems_build_name ('T', 'R', 'r', c),
+ 0,
+ RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &tty->rawInBuf.Semaphore);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ }
+
+ /*
+ * Set default parameters
+ */
+ tty->termios.c_iflag = BRKINT | ICRNL | IXON | IMAXBEL;
+ tty->termios.c_oflag = OPOST | ONLCR | XTABS;
+ tty->termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
+ tty->termios.c_lflag =
+ ISIG | ICANON | IEXTEN | ECHO | ECHOK | ECHOE | ECHOCTL;
+
+ tty->termios.c_cc[VINTR] = '\003';
+ tty->termios.c_cc[VQUIT] = '\034';
+ tty->termios.c_cc[VERASE] = '\177';
+ tty->termios.c_cc[VKILL] = '\025';
+ tty->termios.c_cc[VEOF] = '\004';
+ tty->termios.c_cc[VEOL] = '\000';
+ tty->termios.c_cc[VEOL2] = '\000';
+ tty->termios.c_cc[VSTART] = '\021';
+ tty->termios.c_cc[VSTOP] = '\023';
+ tty->termios.c_cc[VSUSP] = '\032';
+ tty->termios.c_cc[VREPRINT] = '\022';
+ tty->termios.c_cc[VDISCARD] = '\017';
+ tty->termios.c_cc[VWERASE] = '\027';
+ tty->termios.c_cc[VLNEXT] = '\026';
+
+ /* start with no flow control, clear flow control flags */
+ tty->flow_ctrl = 0;
+ /*
+ * set low/highwater mark for XON/XOFF support
+ */
+ tty->lowwater = tty->rawInBuf.Size * 1/2;
+ tty->highwater = tty->rawInBuf.Size * 3/4;
+ /*
+ * Bump name characer
+ */
+ if (c++ == 'z')
+ c = 'a';
+
+ }
+ args->iop->data1 = tty;
+ if (!tty->refcount++) {
+ if (tty->device.firstOpen)
+ (*tty->device.firstOpen)(major, minor, arg);
+
+ /*
+ * start I/O tasks, if needed
+ */
+ if (tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN) {
+ sc = rtems_task_start(
+ tty->rxTaskId, rtems_termios_rxdaemon, (rtems_task_argument)tty);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+
+ sc = rtems_task_start(
+ tty->txTaskId, rtems_termios_txdaemon, (rtems_task_argument)tty);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ }
+ }
+ rtems_semaphore_release (rtems_termios_ttyMutex);
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * Drain output queue
+ */
+static void
+drainOutput (struct rtems_termios_tty *tty)
+{
+ rtems_interrupt_level level;
+ rtems_status_code sc;
+
+ if (tty->device.outputUsesInterrupts != TERMIOS_POLLED) {
+ rtems_interrupt_disable (level);
+ while (tty->rawOutBuf.Tail != tty->rawOutBuf.Head) {
+ tty->rawOutBufState = rob_wait;
+ rtems_interrupt_enable (level);
+ sc = rtems_semaphore_obtain(
+ tty->rawOutBuf.Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ rtems_interrupt_disable (level);
+ }
+ rtems_interrupt_enable (level);
+ }
+}
+
+rtems_status_code
+rtems_termios_close (void *arg)
+{
+ rtems_libio_open_close_args_t *args = arg;
+ struct rtems_termios_tty *tty = args->iop->data1;
+ rtems_status_code sc;
+
+ sc = rtems_semaphore_obtain(
+ rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ if (--tty->refcount == 0) {
+ if (rtems_termios_linesw[tty->t_line].l_close != NULL) {
+ /*
+ * call discipline-specific close
+ */
+ sc = rtems_termios_linesw[tty->t_line].l_close(tty);
+ } else {
+ /*
+ * default: just flush output buffer
+ */
+ sc = rtems_semaphore_obtain(tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_fatal_error_occurred (sc);
+ }
+ drainOutput (tty);
+ rtems_semaphore_release (tty->osem);
+ }
+
+ if (tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN) {
+ /*
+ * send "terminate" to I/O tasks
+ */
+ sc = rtems_event_send( tty->rxTaskId, TERMIOS_RX_TERMINATE_EVENT );
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ sc = rtems_event_send( tty->txTaskId, TERMIOS_TX_TERMINATE_EVENT );
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ }
+ if (tty->device.lastClose)
+ (*tty->device.lastClose)(tty->major, tty->minor, arg);
+ if (tty->forw == NULL) {
+ rtems_termios_ttyTail = tty->back;
+ if ( rtems_termios_ttyTail != NULL ) {
+ rtems_termios_ttyTail->forw = NULL;
+ }
+ } else {
+ tty->forw->back = tty->back;
+ }
+
+ if (tty->back == NULL) {
+ rtems_termios_ttyHead = tty->forw;
+ if ( rtems_termios_ttyHead != NULL ) {
+ rtems_termios_ttyHead->back = NULL;
+ }
+ } else {
+ tty->back->forw = tty->forw;
+ }
+
+ rtems_semaphore_delete (tty->isem);
+ rtems_semaphore_delete (tty->osem);
+ rtems_semaphore_delete (tty->rawOutBuf.Semaphore);
+ if ((tty->device.pollRead == NULL) ||
+ (tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN))
+ rtems_semaphore_delete (tty->rawInBuf.Semaphore);
+ free (tty->rawInBuf.theBuf);
+ free (tty->rawOutBuf.theBuf);
+ free (tty->cbuf);
+ free (tty);
+ }
+ rtems_semaphore_release (rtems_termios_ttyMutex);
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_termios_bufsize (
+ int cbufsize,
+ int raw_input,
+ int raw_output
+)
+{
+ rtems_termios_cbufsize = cbufsize;
+ rtems_termios_raw_input_size = raw_input;
+ rtems_termios_raw_output_size = raw_output;
+ return RTEMS_SUCCESSFUL;
+}
+
+static void
+termios_set_flowctrl(struct rtems_termios_tty *tty)
+{
+ rtems_interrupt_level level;
+ /*
+ * check for flow control options to be switched off
+ */
+
+ /* check for outgoing XON/XOFF flow control switched off */
+ if (( tty->flow_ctrl & FL_MDXON) &&
+ !(tty->termios.c_iflag & IXON)) {
+ /* clear related flags in flow_ctrl */
+ tty->flow_ctrl &= ~(FL_MDXON | FL_ORCVXOF);
+
+ /* has output been stopped due to received XOFF? */
+ if (tty->flow_ctrl & FL_OSTOP) {
+ /* disable interrupts */
+ rtems_interrupt_disable(level);
+ tty->flow_ctrl &= ~FL_OSTOP;
+ /* check for chars in output buffer (or rob_state?) */
+ if (tty->rawOutBufState != rob_idle) {
+ /* if chars available, call write function... */
+ (*tty->device.write)(
+ tty->minor, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail],1);
+ }
+ /* reenable interrupts */
+ rtems_interrupt_enable(level);
+ }
+ }
+ /* check for incoming XON/XOFF flow control switched off */
+ if (( tty->flow_ctrl & FL_MDXOF) && !(tty->termios.c_iflag & IXOFF)) {
+ /* clear related flags in flow_ctrl */
+ tty->flow_ctrl &= ~(FL_MDXOF);
+ /* FIXME: what happens, if we had sent XOFF but not yet XON? */
+ tty->flow_ctrl &= ~(FL_ISNTXOF);
+ }
+
+ /* check for incoming RTS/CTS flow control switched off */
+ if (( tty->flow_ctrl & FL_MDRTS) && !(tty->termios.c_cflag & CRTSCTS)) {
+ /* clear related flags in flow_ctrl */
+ tty->flow_ctrl &= ~(FL_MDRTS);
+
+ /* restart remote Tx, if it was stopped */
+ if ((tty->flow_ctrl & FL_IRTSOFF) && (tty->device.startRemoteTx != NULL)) {
+ tty->device.startRemoteTx(tty->minor);
+ }
+ tty->flow_ctrl &= ~(FL_IRTSOFF);
+ }
+
+ /*
+ * check for flow control options to be switched on
+ */
+ /* check for incoming RTS/CTS flow control switched on */
+ if (tty->termios.c_cflag & CRTSCTS) {
+ tty->flow_ctrl |= FL_MDRTS;
+ }
+ /* check for incoming XON/XOF flow control switched on */
+ if (tty->termios.c_iflag & IXOFF) {
+ tty->flow_ctrl |= FL_MDXOF;
+ }
+ /* check for outgoing XON/XOF flow control switched on */
+ if (tty->termios.c_iflag & IXON) {
+ tty->flow_ctrl |= FL_MDXON;
+ }
+}
+
+rtems_status_code
+rtems_termios_ioctl (void *arg)
+{
+ rtems_libio_ioctl_args_t *args = arg;
+ struct rtems_termios_tty *tty = args->iop->data1;
+ struct ttywakeup *wakeup = (struct ttywakeup *)args->buffer;
+ rtems_status_code sc;
+
+ args->ioctl_return = 0;
+ sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL) {
+ args->ioctl_return = sc;
+ return sc;
+ }
+ switch (args->command) {
+ default:
+ if (rtems_termios_linesw[tty->t_line].l_ioctl != NULL) {
+ sc = rtems_termios_linesw[tty->t_line].l_ioctl(tty,args);
+ }
+ else {
+ sc = RTEMS_INVALID_NUMBER;
+ }
+ break;
+
+ case RTEMS_IO_GET_ATTRIBUTES:
+ *(struct termios *)args->buffer = tty->termios;
+ break;
+
+ case RTEMS_IO_SET_ATTRIBUTES:
+ tty->termios = *(struct termios *)args->buffer;
+
+ /* check for and process change in flow control options */
+ termios_set_flowctrl(tty);
+
+ if (tty->termios.c_lflag & ICANON) {
+ tty->rawInBufSemaphoreOptions = RTEMS_WAIT;
+ tty->rawInBufSemaphoreTimeout = RTEMS_NO_TIMEOUT;
+ tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT;
+ } else {
+ tty->vtimeTicks = tty->termios.c_cc[VTIME] *
+ rtems_clock_get_ticks_per_second() / 10;
+ if (tty->termios.c_cc[VTIME]) {
+ tty->rawInBufSemaphoreOptions = RTEMS_WAIT;
+ tty->rawInBufSemaphoreTimeout = tty->vtimeTicks;
+ if (tty->termios.c_cc[VMIN])
+ tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT;
+ else
+ tty->rawInBufSemaphoreFirstTimeout = tty->vtimeTicks;
+ } else {
+ if (tty->termios.c_cc[VMIN]) {
+ tty->rawInBufSemaphoreOptions = RTEMS_WAIT;
+ tty->rawInBufSemaphoreTimeout = RTEMS_NO_TIMEOUT;
+ tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT;
+ } else {
+ tty->rawInBufSemaphoreOptions = RTEMS_NO_WAIT;
+ }
+ }
+ }
+ if (tty->device.setAttributes)
+ (*tty->device.setAttributes)(tty->minor, &tty->termios);
+ break;
+
+ case RTEMS_IO_TCDRAIN:
+ drainOutput (tty);
+ break;
+
+ case RTEMS_IO_SNDWAKEUP:
+ tty->tty_snd = *wakeup;
+ break;
+
+ case RTEMS_IO_RCVWAKEUP:
+ tty->tty_rcv = *wakeup;
+ break;
+
+ /*
+ * FIXME: add various ioctl code handlers
+ */
+
+#if 1 /* FIXME */
+ case TIOCSETD:
+ /*
+ * close old line discipline
+ */
+ if (rtems_termios_linesw[tty->t_line].l_close != NULL) {
+ sc = rtems_termios_linesw[tty->t_line].l_close(tty);
+ }
+ tty->t_line=*(int*)(args->buffer);
+ tty->t_sc = NULL; /* ensure that no more valid data */
+ /*
+ * open new line discipline
+ */
+ if (rtems_termios_linesw[tty->t_line].l_open != NULL) {
+ sc = rtems_termios_linesw[tty->t_line].l_open(tty);
+ }
+ break;
+ case TIOCGETD:
+ *(int*)(args->buffer)=tty->t_line;
+ break;
+#endif
+ case FIONREAD: {
+ int rawnc = tty->rawInBuf.Tail - tty->rawInBuf.Head;
+ if ( rawnc < 0 )
+ rawnc += tty->rawInBuf.Size;
+ /* Half guess that this is the right operation */
+ *(int *)args->buffer = tty->ccount - tty->cindex + rawnc;
+ }
+ break;
+ }
+
+ rtems_semaphore_release (tty->osem);
+ args->ioctl_return = sc;
+ return sc;
+}
+
+/*
+ * Send characters to device-specific code
+ */
+void
+rtems_termios_puts (
+ const void *_buf, int len, struct rtems_termios_tty *tty)
+{
+ const unsigned char *buf = _buf;
+ unsigned int newHead;
+ rtems_interrupt_level level;
+ rtems_status_code sc;
+
+ if (tty->device.outputUsesInterrupts == TERMIOS_POLLED) {
+ (*tty->device.write)(tty->minor, (void *)buf, len);
+ return;
+ }
+ newHead = tty->rawOutBuf.Head;
+ while (len) {
+ /*
+ * Performance improvement could be made here.
+ * Copy multiple bytes to raw buffer:
+ * if (len > 1) && (space to buffer end, or tail > 1)
+ * ncopy = MIN (len, space to buffer end or tail)
+ * memcpy (raw buffer, buf, ncopy)
+ * buf += ncopy
+ * len -= ncopy
+ *
+ * To minimize latency, the memcpy should be done
+ * with interrupts enabled.
+ */
+ newHead = (newHead + 1) % tty->rawOutBuf.Size;
+ rtems_interrupt_disable (level);
+ while (newHead == tty->rawOutBuf.Tail) {
+ tty->rawOutBufState = rob_wait;
+ rtems_interrupt_enable (level);
+ sc = rtems_semaphore_obtain(
+ tty->rawOutBuf.Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ rtems_interrupt_disable (level);
+ }
+ tty->rawOutBuf.theBuf[tty->rawOutBuf.Head] = *buf++;
+ tty->rawOutBuf.Head = newHead;
+ if (tty->rawOutBufState == rob_idle) {
+ /* check, whether XOFF has been received */
+ if (!(tty->flow_ctrl & FL_ORCVXOF)) {
+ (*tty->device.write)(tty->minor,
+ (char *)&tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail],1);
+ } else {
+ /* remember that output has been stopped due to flow ctrl*/
+ tty->flow_ctrl |= FL_OSTOP;
+ }
+ tty->rawOutBufState = rob_busy;
+ }
+ rtems_interrupt_enable (level);
+ len--;
+ }
+}
+
+/*
+ * Handle output processing
+ */
+static void
+oproc (unsigned char c, struct rtems_termios_tty *tty)
+{
+ int i;
+
+ if (tty->termios.c_oflag & OPOST) {
+ switch (c) {
+ case '\n':
+ if (tty->termios.c_oflag & ONLRET)
+ tty->column = 0;
+ if (tty->termios.c_oflag & ONLCR) {
+ rtems_termios_puts ("\r", 1, tty);
+ tty->column = 0;
+ }
+ break;
+
+ case '\r':
+ if ((tty->termios.c_oflag & ONOCR) && (tty->column == 0))
+ return;
+ if (tty->termios.c_oflag & OCRNL) {
+ c = '\n';
+ if (tty->termios.c_oflag & ONLRET)
+ tty->column = 0;
+ break;
+ }
+ tty->column = 0;
+ break;
+
+ case '\t':
+ i = 8 - (tty->column & 7);
+ if ((tty->termios.c_oflag & TABDLY) == XTABS) {
+ tty->column += i;
+ rtems_termios_puts ( " ", i, tty);
+ return;
+ }
+ tty->column += i;
+ break;
+
+ case '\b':
+ if (tty->column > 0)
+ tty->column--;
+ break;
+
+ default:
+ if (tty->termios.c_oflag & OLCUC)
+ c = toupper(c);
+ if (!iscntrl(c))
+ tty->column++;
+ break;
+ }
+ }
+ rtems_termios_puts (&c, 1, tty);
+}
+
+rtems_status_code
+rtems_termios_write (void *arg)
+{
+ rtems_libio_rw_args_t *args = arg;
+ struct rtems_termios_tty *tty = args->iop->data1;
+ rtems_status_code sc;
+
+ sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+ if (rtems_termios_linesw[tty->t_line].l_write != NULL) {
+ sc = rtems_termios_linesw[tty->t_line].l_write(tty,args);
+ rtems_semaphore_release (tty->osem);
+ return sc;
+ }
+ if (tty->termios.c_oflag & OPOST) {
+ uint32_t count = args->count;
+ char *buffer = args->buffer;
+ while (count--)
+ oproc (*buffer++, tty);
+ args->bytes_moved = args->count;
+ } else {
+ rtems_termios_puts (args->buffer, args->count, tty);
+ args->bytes_moved = args->count;
+ }
+ rtems_semaphore_release (tty->osem);
+ return sc;
+}
+
+/*
+ * Echo a typed character
+ */
+static void
+echo (unsigned char c, struct rtems_termios_tty *tty)
+{
+ if ((tty->termios.c_lflag & ECHOCTL) &&
+ iscntrl(c) && (c != '\t') && (c != '\n')) {
+ char echobuf[2];
+
+ echobuf[0] = '^';
+ echobuf[1] = c ^ 0x40;
+ rtems_termios_puts (echobuf, 2, tty);
+ tty->column += 2;
+ } else {
+ oproc (c, tty);
+ }
+}
+
+/*
+ * Erase a character or line
+ * FIXME: Needs support for WERASE and ECHOPRT.
+ * FIXME: Some of the tests should check for IEXTEN, too.
+ */
+static void
+erase (struct rtems_termios_tty *tty, int lineFlag)
+{
+ if (tty->ccount == 0)
+ return;
+ if (lineFlag) {
+ if (!(tty->termios.c_lflag & ECHO)) {
+ tty->ccount = 0;
+ return;
+ }
+ if (!(tty->termios.c_lflag & ECHOE)) {
+ tty->ccount = 0;
+ echo (tty->termios.c_cc[VKILL], tty);
+ if (tty->termios.c_lflag & ECHOK)
+ echo ('\n', tty);
+ return;
+ }
+ }
+
+ while (tty->ccount) {
+ unsigned char c = tty->cbuf[--tty->ccount];
+
+ if (tty->termios.c_lflag & ECHO) {
+ if (!lineFlag && !(tty->termios.c_lflag & ECHOE)) {
+ echo (tty->termios.c_cc[VERASE], tty);
+ } else if (c == '\t') {
+ int col = tty->read_start_column;
+ int i = 0;
+
+ /*
+ * Find the character before the tab
+ */
+ while (i != tty->ccount) {
+ c = tty->cbuf[i++];
+ if (c == '\t') {
+ col = (col | 7) + 1;
+ } else if (iscntrl (c)) {
+ if (tty->termios.c_lflag & ECHOCTL)
+ col += 2;
+ } else {
+ col++;
+ }
+ }
+
+ /*
+ * Back up over the tab
+ */
+ while (tty->column > col) {
+ rtems_termios_puts ("\b", 1, tty);
+ tty->column--;
+ }
+ }
+ else {
+ if (iscntrl (c) && (tty->termios.c_lflag & ECHOCTL)) {
+ rtems_termios_puts ("\b \b", 3, tty);
+ if (tty->column)
+ tty->column--;
+ }
+ if (!iscntrl (c) || (tty->termios.c_lflag & ECHOCTL)) {
+ rtems_termios_puts ("\b \b", 3, tty);
+ if (tty->column)
+ tty->column--;
+ }
+ }
+ }
+ if (!lineFlag)
+ break;
+ }
+}
+
+/*
+ * Process a single input character
+ */
+static int
+iproc (unsigned char c, struct rtems_termios_tty *tty)
+{
+ if (tty->termios.c_iflag & ISTRIP)
+ c &= 0x7f;
+
+ if (tty->termios.c_iflag & IUCLC)
+ c = tolower (c);
+
+ if (c == '\r') {
+ if (tty->termios.c_iflag & IGNCR)
+ return 0;
+ if (tty->termios.c_iflag & ICRNL)
+ c = '\n';
+ } else if ((c == '\n') && (tty->termios.c_iflag & INLCR)) {
+ c = '\r';
+ }
+
+ if ((c != '\0') && (tty->termios.c_lflag & ICANON)) {
+ if (c == tty->termios.c_cc[VERASE]) {
+ erase (tty, 0);
+ return 0;
+ }
+ else if (c == tty->termios.c_cc[VKILL]) {
+ erase (tty, 1);
+ return 0;
+ }
+ else if (c == tty->termios.c_cc[VEOF]) {
+ return 1;
+ } else if (c == '\n') {
+ if (tty->termios.c_lflag & (ECHO | ECHONL))
+ echo (c, tty);
+ tty->cbuf[tty->ccount++] = c;
+ return 1;
+ } else if ((c == tty->termios.c_cc[VEOL]) ||
+ (c == tty->termios.c_cc[VEOL2])) {
+ if (tty->termios.c_lflag & ECHO)
+ echo (c, tty);
+ tty->cbuf[tty->ccount++] = c;
+ return 1;
+ }
+ }
+
+ /*
+ * FIXME: Should do IMAXBEL handling somehow
+ */
+ if (tty->ccount < (CBUFSIZE-1)) {
+ if (tty->termios.c_lflag & ECHO)
+ echo (c, tty);
+ tty->cbuf[tty->ccount++] = c;
+ }
+ return 0;
+}
+
+/*
+ * Process input character, with semaphore.
+ */
+static int
+siproc (unsigned char c, struct rtems_termios_tty *tty)
+{
+ int i;
+
+ /*
+ * Obtain output semaphore if character will be echoed
+ */
+ if (tty->termios.c_lflag & (ECHO|ECHOE|ECHOK|ECHONL|ECHOPRT|ECHOCTL|ECHOKE)) {
+ rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ i = iproc (c, tty);
+ rtems_semaphore_release (tty->osem);
+ }
+ else {
+ i = iproc (c, tty);
+ }
+ return i;
+}
+
+/*
+ * Fill the input buffer by polling the device
+ */
+static rtems_status_code
+fillBufferPoll (struct rtems_termios_tty *tty)
+{
+ int n;
+
+ if (tty->termios.c_lflag & ICANON) {
+ for (;;) {
+ n = (*tty->device.pollRead)(tty->minor);
+ if (n < 0) {
+ rtems_task_wake_after (1);
+ } else {
+ if (siproc (n, tty))
+ break;
+ }
+ }
+ } else {
+ rtems_interval then, now;
+
+ then = rtems_clock_get_ticks_since_boot();
+ for (;;) {
+ n = (*tty->device.pollRead)(tty->minor);
+ if (n < 0) {
+ if (tty->termios.c_cc[VMIN]) {
+ if (tty->termios.c_cc[VTIME] && tty->ccount) {
+ now = rtems_clock_get_ticks_since_boot();
+ if ((now - then) > tty->vtimeTicks) {
+ break;
+ }
+ }
+ } else {
+ if (!tty->termios.c_cc[VTIME])
+ break;
+ now = rtems_clock_get_ticks_since_boot();
+ if ((now - then) > tty->vtimeTicks) {
+ break;
+ }
+ }
+ rtems_task_wake_after (1);
+ } else {
+ siproc (n, tty);
+ if (tty->ccount >= tty->termios.c_cc[VMIN])
+ break;
+ if (tty->termios.c_cc[VMIN] && tty->termios.c_cc[VTIME])
+ then = rtems_clock_get_ticks_since_boot();
+ }
+ }
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * Fill the input buffer from the raw input queue
+ */
+static rtems_status_code
+fillBufferQueue (struct rtems_termios_tty *tty)
+{
+ rtems_interval timeout = tty->rawInBufSemaphoreFirstTimeout;
+ rtems_status_code sc;
+ int wait = (int)1;
+
+ while ( wait ) {
+ /*
+ * Process characters read from raw queue
+ */
+ while ((tty->rawInBuf.Head != tty->rawInBuf.Tail) &&
+ (tty->ccount < (CBUFSIZE-1))) {
+ unsigned char c;
+ unsigned int newHead;
+
+ newHead = (tty->rawInBuf.Head + 1) % tty->rawInBuf.Size;
+ c = tty->rawInBuf.theBuf[newHead];
+ tty->rawInBuf.Head = newHead;
+ if(((tty->rawInBuf.Tail-newHead+tty->rawInBuf.Size)
+ % tty->rawInBuf.Size)
+ < tty->lowwater) {
+ tty->flow_ctrl &= ~FL_IREQXOF;
+ /* if tx stopped and XON should be sent... */
+ if (((tty->flow_ctrl & (FL_MDXON | FL_ISNTXOF))
+ == (FL_MDXON | FL_ISNTXOF))
+ && ((tty->rawOutBufState == rob_idle)
+ || (tty->flow_ctrl & FL_OSTOP))) {
+ /* XON should be sent now... */
+ (*tty->device.write)(
+ tty->minor, (void *)&(tty->termios.c_cc[VSTART]), 1);
+ } else if (tty->flow_ctrl & FL_MDRTS) {
+ tty->flow_ctrl &= ~FL_IRTSOFF;
+ /* activate RTS line */
+ if (tty->device.startRemoteTx != NULL) {
+ tty->device.startRemoteTx(tty->minor);
+ }
+ }
+ }
+
+ /* continue processing new character */
+ if (tty->termios.c_lflag & ICANON) {
+ if (siproc (c, tty))
+ wait = 0;
+ } else {
+ siproc (c, tty);
+ if (tty->ccount >= tty->termios.c_cc[VMIN])
+ wait = 0;
+ }
+ timeout = tty->rawInBufSemaphoreTimeout;
+ }
+
+ /*
+ * Wait for characters
+ */
+ if ( wait ) {
+ sc = rtems_semaphore_obtain(
+ tty->rawInBuf.Semaphore, tty->rawInBufSemaphoreOptions, timeout);
+ if (sc != RTEMS_SUCCESSFUL)
+ break;
+ }
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code
+rtems_termios_read (void *arg)
+{
+ rtems_libio_rw_args_t *args = arg;
+ struct rtems_termios_tty *tty = args->iop->data1;
+ uint32_t count = args->count;
+ char *buffer = args->buffer;
+ rtems_status_code sc;
+
+ sc = rtems_semaphore_obtain (tty->isem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ if (rtems_termios_linesw[tty->t_line].l_read != NULL) {
+ sc = rtems_termios_linesw[tty->t_line].l_read(tty,args);
+ tty->tty_rcvwakeup = 0;
+ rtems_semaphore_release (tty->isem);
+ return sc;
+ }
+
+ if (tty->cindex == tty->ccount) {
+ tty->cindex = tty->ccount = 0;
+ tty->read_start_column = tty->column;
+ if (tty->device.pollRead != NULL &&
+ tty->device.outputUsesInterrupts == TERMIOS_POLLED)
+ sc = fillBufferPoll (tty);
+ else
+ sc = fillBufferQueue (tty);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ tty->cindex = tty->ccount = 0;
+ }
+ while (count && (tty->cindex < tty->ccount)) {
+ *buffer++ = tty->cbuf[tty->cindex++];
+ count--;
+ }
+ args->bytes_moved = args->count - count;
+ tty->tty_rcvwakeup = 0;
+ rtems_semaphore_release (tty->isem);
+ return sc;
+}
+
+/*
+ * signal receive interrupt to rx daemon
+ * NOTE: This routine runs in the context of the
+ * device receive interrupt handler.
+ */
+void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty)
+{
+ /*
+ * send event to rx daemon task
+ */
+ rtems_event_send(tty->rxTaskId,TERMIOS_RX_PROC_EVENT);
+}
+
+/*
+ * Place characters on raw queue.
+ * NOTE: This routine runs in the context of the
+ * device receive interrupt handler.
+ * Returns the number of characters dropped because of overflow.
+ */
+int
+rtems_termios_enqueue_raw_characters (void *ttyp, char *buf, int len)
+{
+ struct rtems_termios_tty *tty = ttyp;
+ unsigned int newTail;
+ char c;
+ int dropped = 0;
+ bool flow_rcv = false; /* true, if flow control char received */
+ rtems_interrupt_level level;
+
+ if (rtems_termios_linesw[tty->t_line].l_rint != NULL) {
+ while (len--) {
+ c = *buf++;
+ rtems_termios_linesw[tty->t_line].l_rint(c,tty);
+ }
+
+ /*
+ * check to see if rcv wakeup callback was set
+ */
+ if (( !tty->tty_rcvwakeup ) && ( tty->tty_rcv.sw_pfn != NULL )) {
+ (*tty->tty_rcv.sw_pfn)(&tty->termios, tty->tty_rcv.sw_arg);
+ tty->tty_rcvwakeup = 1;
+ }
+ return 0;
+ }
+
+ while (len--) {
+ c = *buf++;
+ /* FIXME: implement IXANY: any character restarts output */
+ /* if incoming XON/XOFF controls outgoing stream: */
+ if (tty->flow_ctrl & FL_MDXON) {
+ /* if received char is V_STOP and V_START (both are equal value) */
+ if (c == tty->termios.c_cc[VSTOP]) {
+ if (c == tty->termios.c_cc[VSTART]) {
+ /* received VSTOP and VSTART==VSTOP? */
+ /* then toggle "stop output" status */
+ tty->flow_ctrl = tty->flow_ctrl ^ FL_ORCVXOF;
+ }
+ else {
+ /* VSTOP received (other code than VSTART) */
+ /* stop output */
+ tty->flow_ctrl |= FL_ORCVXOF;
+ }
+ flow_rcv = true;
+ }
+ else if (c == tty->termios.c_cc[VSTART]) {
+ /* VSTART received */
+ /* restart output */
+ tty->flow_ctrl &= ~FL_ORCVXOF;
+ flow_rcv = true;
+ }
+ }
+ if (flow_rcv) {
+ /* restart output according to FL_ORCVXOF flag */
+ if ((tty->flow_ctrl & (FL_ORCVXOF | FL_OSTOP)) == FL_OSTOP) {
+ /* disable interrupts */
+ rtems_interrupt_disable(level);
+ tty->flow_ctrl &= ~FL_OSTOP;
+ /* check for chars in output buffer (or rob_state?) */
+ if (tty->rawOutBufState != rob_idle) {
+ /* if chars available, call write function... */
+ (*tty->device.write)(
+ tty->minor, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail], 1);
+ }
+ /* reenable interrupts */
+ rtems_interrupt_enable(level);
+ }
+ } else {
+ newTail = (tty->rawInBuf.Tail + 1) % tty->rawInBuf.Size;
+ /* if chars_in_buffer > highwater */
+ rtems_interrupt_disable(level);
+ if ((((newTail - tty->rawInBuf.Head + tty->rawInBuf.Size)
+ % tty->rawInBuf.Size) > tty->highwater) &&
+ !(tty->flow_ctrl & FL_IREQXOF)) {
+ /* incoming data stream should be stopped */
+ tty->flow_ctrl |= FL_IREQXOF;
+ if ((tty->flow_ctrl & (FL_MDXOF | FL_ISNTXOF))
+ == (FL_MDXOF ) ) {
+ if ((tty->flow_ctrl & FL_OSTOP) ||
+ (tty->rawOutBufState == rob_idle)) {
+ /* if tx is stopped due to XOFF or out of data */
+ /* call write function here */
+ tty->flow_ctrl |= FL_ISNTXOF;
+ (*tty->device.write)(tty->minor,
+ (void *)&(tty->termios.c_cc[VSTOP]), 1);
+ }
+ } else if ((tty->flow_ctrl & (FL_MDRTS | FL_IRTSOFF)) == (FL_MDRTS) ) {
+ tty->flow_ctrl |= FL_IRTSOFF;
+ /* deactivate RTS line */
+ if (tty->device.stopRemoteTx != NULL) {
+ tty->device.stopRemoteTx(tty->minor);
+ }
+ }
+ }
+
+ /* reenable interrupts */
+ rtems_interrupt_enable(level);
+
+ if (newTail == tty->rawInBuf.Head) {
+ dropped++;
+ } else {
+ tty->rawInBuf.theBuf[newTail] = c;
+ tty->rawInBuf.Tail = newTail;
+
+ /*
+ * check to see if rcv wakeup callback was set
+ */
+ if (( !tty->tty_rcvwakeup ) && ( tty->tty_rcv.sw_pfn != NULL )) {
+ (*tty->tty_rcv.sw_pfn)(&tty->termios, tty->tty_rcv.sw_arg);
+ tty->tty_rcvwakeup = 1;
+ }
+ }
+ }
+ }
+
+ tty->rawInBufDropped += dropped;
+ rtems_semaphore_release (tty->rawInBuf.Semaphore);
+ return dropped;
+}
+
+/*
+ * in task-driven mode, this function is called in Tx task context
+ * in interrupt-driven mode, this function is called in TxIRQ context
+ */
+int
+rtems_termios_refill_transmitter (struct rtems_termios_tty *tty)
+{
+ unsigned int newTail;
+ int nToSend;
+ rtems_interrupt_level level;
+ int len;
+
+ /* check for XOF/XON to send */
+ if ((tty->flow_ctrl & (FL_MDXOF | FL_IREQXOF | FL_ISNTXOF))
+ == (FL_MDXOF | FL_IREQXOF)) {
+ /* XOFF should be sent now... */
+ (*tty->device.write)(tty->minor, (void *)&(tty->termios.c_cc[VSTOP]), 1);
+
+ rtems_interrupt_disable(level);
+ tty->t_dqlen--;
+ tty->flow_ctrl |= FL_ISNTXOF;
+ rtems_interrupt_enable(level);
+
+ nToSend = 1;
+
+ } else if ((tty->flow_ctrl & (FL_IREQXOF | FL_ISNTXOF)) == FL_ISNTXOF) {
+ /* NOTE: send XON even, if no longer in XON/XOFF mode... */
+ /* XON should be sent now... */
+ /*
+ * FIXME: this .write call will generate another
+ * dequeue callback. This will advance the "Tail" in the data
+ * buffer, although the corresponding data is not yet out!
+ * Therefore the dequeue "length" should be reduced by 1
+ */
+ (*tty->device.write)(tty->minor, (void *)&(tty->termios.c_cc[VSTART]), 1);
+
+ rtems_interrupt_disable(level);
+ tty->t_dqlen--;
+ tty->flow_ctrl &= ~FL_ISNTXOF;
+ rtems_interrupt_enable(level);
+
+ nToSend = 1;
+ } else {
+ if ( tty->rawOutBuf.Head == tty->rawOutBuf.Tail ) {
+ /*
+ * buffer was empty
+ */
+ if (tty->rawOutBufState == rob_wait) {
+ /*
+ * this should never happen...
+ */
+ rtems_semaphore_release (tty->rawOutBuf.Semaphore);
+ }
+ return 0;
+ }
+
+ rtems_interrupt_disable(level);
+ len = tty->t_dqlen;
+ tty->t_dqlen = 0;
+ rtems_interrupt_enable(level);
+
+ newTail = (tty->rawOutBuf.Tail + len) % tty->rawOutBuf.Size;
+ tty->rawOutBuf.Tail = newTail;
+ if (tty->rawOutBufState == rob_wait) {
+ /*
+ * wake up any pending writer task
+ */
+ rtems_semaphore_release (tty->rawOutBuf.Semaphore);
+ }
+
+ if (newTail == tty->rawOutBuf.Head) {
+ /*
+ * Buffer has become empty
+ */
+ tty->rawOutBufState = rob_idle;
+ nToSend = 0;
+
+ /*
+ * check to see if snd wakeup callback was set
+ */
+ if ( tty->tty_snd.sw_pfn != NULL) {
+ (*tty->tty_snd.sw_pfn)(&tty->termios, tty->tty_snd.sw_arg);
+ }
+ }
+ /* check, whether output should stop due to received XOFF */
+ else if ((tty->flow_ctrl & (FL_MDXON | FL_ORCVXOF))
+ == (FL_MDXON | FL_ORCVXOF)) {
+ /* Buffer not empty, but output stops due to XOFF */
+ /* set flag, that output has been stopped */
+ rtems_interrupt_disable(level);
+ tty->flow_ctrl |= FL_OSTOP;
+ tty->rawOutBufState = rob_busy; /*apm*/
+ rtems_interrupt_enable(level);
+ nToSend = 0;
+ } else {
+ /*
+ * Buffer not empty, start tranmitter
+ */
+ if (newTail > tty->rawOutBuf.Head)
+ nToSend = tty->rawOutBuf.Size - newTail;
+ else
+ nToSend = tty->rawOutBuf.Head - newTail;
+ /* when flow control XON or XOF, don't send blocks of data */
+ /* to allow fast reaction on incoming flow ctrl and low latency*/
+ /* for outgoing flow control */
+ if (tty->flow_ctrl & (FL_MDXON | FL_MDXOF)) {
+ nToSend = 1;
+ }
+ tty->rawOutBufState = rob_busy; /*apm*/
+ (*tty->device.write)(
+ tty->minor, &tty->rawOutBuf.theBuf[newTail], nToSend);
+ }
+ tty->rawOutBuf.Tail = newTail; /*apm*/
+ }
+ return nToSend;
+}
+
+/*
+ * Characters have been transmitted
+ * NOTE: This routine runs in the context of the
+ * device transmit interrupt handler.
+ * The second argument is the number of characters transmitted so far.
+ * This value will always be 1 for devices which generate an interrupt
+ * for each transmitted character.
+ * It returns number of characters left to transmit
+ */
+int
+rtems_termios_dequeue_characters (void *ttyp, int len)
+{
+ struct rtems_termios_tty *tty = ttyp;
+ rtems_status_code sc;
+
+ /*
+ * sum up character count already sent
+ */
+ tty->t_dqlen += len;
+
+ if (tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN) {
+ /*
+ * send wake up to transmitter task
+ */
+ sc = rtems_event_send(tty->txTaskId, TERMIOS_TX_START_EVENT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ return 0; /* nothing to output in IRQ... */
+ }
+
+ if (tty->t_line == PPPDISC ) {
+ /*
+ * call any line discipline start function
+ */
+ if (rtems_termios_linesw[tty->t_line].l_start != NULL) {
+ rtems_termios_linesw[tty->t_line].l_start(tty);
+ }
+ return 0; /* nothing to output in IRQ... */
+ }
+
+ return rtems_termios_refill_transmitter(tty);
+}
+
+/*
+ * this task actually processes any transmit events
+ */
+static rtems_task rtems_termios_txdaemon(rtems_task_argument argument)
+{
+ struct rtems_termios_tty *tty = (struct rtems_termios_tty *)argument;
+ rtems_event_set the_event;
+
+ while (1) {
+ /*
+ * wait for rtems event
+ */
+ rtems_event_receive(
+ (TERMIOS_TX_START_EVENT | TERMIOS_TX_TERMINATE_EVENT),
+ RTEMS_EVENT_ANY | RTEMS_WAIT,
+ RTEMS_NO_TIMEOUT,
+ &the_event
+ );
+ if ((the_event & TERMIOS_TX_TERMINATE_EVENT) != 0) {
+ tty->txTaskId = 0;
+ rtems_task_delete(RTEMS_SELF);
+ }
+
+ /*
+ * call any line discipline start function
+ */
+ if (rtems_termios_linesw[tty->t_line].l_start != NULL) {
+ rtems_termios_linesw[tty->t_line].l_start(tty);
+ }
+
+ /*
+ * try to push further characters to device
+ */
+ rtems_termios_refill_transmitter(tty);
+ }
+}
+
+/*
+ * this task actually processes any receive events
+ */
+static rtems_task rtems_termios_rxdaemon(rtems_task_argument argument)
+{
+ struct rtems_termios_tty *tty = (struct rtems_termios_tty *)argument;
+ rtems_event_set the_event;
+ int c;
+ char c_buf;
+
+ while (1) {
+ /*
+ * wait for rtems event
+ */
+ rtems_event_receive(
+ (TERMIOS_RX_PROC_EVENT | TERMIOS_RX_TERMINATE_EVENT),
+ RTEMS_EVENT_ANY | RTEMS_WAIT,
+ RTEMS_NO_TIMEOUT,
+ &the_event
+ );
+ if ((the_event & TERMIOS_RX_TERMINATE_EVENT) != 0) {
+ tty->rxTaskId = 0;
+ rtems_task_delete(RTEMS_SELF);
+ }
+
+ /*
+ * do something
+ */
+ c = tty->device.pollRead(tty->minor);
+ if (c != EOF) {
+ /*
+ * pollRead did call enqueue on its own
+ */
+ c_buf = c;
+ rtems_termios_enqueue_raw_characters ( tty,&c_buf,1);
+ }
+ }
+}
diff --git a/cpukit/libcsupport/src/termios_baud2index.c b/cpukit/libcsupport/src/termios_baud2index.c
new file mode 100644
index 0000000000..8bd6b867b8
--- /dev/null
+++ b/cpukit/libcsupport/src/termios_baud2index.c
@@ -0,0 +1,50 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/termios.h>
+#include <rtems/termiostypes.h>
+
+int rtems_termios_baud_to_index(
+ rtems_termios_baud_t termios_baud
+)
+{
+ int baud_index;
+
+ switch (termios_baud) {
+ case B0: baud_index = 0; break;
+ case B50: baud_index = 1; break;
+ case B75: baud_index = 2; break;
+ case B110: baud_index = 3; break;
+ case B134: baud_index = 4; break;
+ case B150: baud_index = 5; break;
+ case B200: baud_index = 6; break;
+ case B300: baud_index = 7; break;
+ case B600: baud_index = 8; break;
+ case B1200: baud_index = 9; break;
+ case B1800: baud_index = 10; break;
+ case B2400: baud_index = 11; break;
+ case B4800: baud_index = 12; break;
+ case B9600: baud_index = 13; break;
+ case B19200: baud_index = 14; break;
+ case B38400: baud_index = 15; break;
+ case B57600: baud_index = 16; break;
+ case B115200: baud_index = 17; break;
+ case B230400: baud_index = 18; break;
+ case B460800: baud_index = 19; break;
+ default: baud_index = -1; break;
+ }
+
+ return baud_index;
+}
diff --git a/cpukit/libcsupport/src/termios_baud2num.c b/cpukit/libcsupport/src/termios_baud2num.c
new file mode 100644
index 0000000000..57b908ebee
--- /dev/null
+++ b/cpukit/libcsupport/src/termios_baud2num.c
@@ -0,0 +1,33 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/assoc.h>
+
+extern rtems_assoc_t termios_assoc_table[];
+
+int32_t rtems_termios_baud_to_number(
+ int termios_baud
+)
+{
+ int baud;
+
+ baud = rtems_assoc_local_by_remote( termios_assoc_table, termios_baud );
+ if ( baud == 0 && termios_baud != 0 )
+ return -1;
+
+ return baud;
+}
diff --git a/cpukit/libcsupport/src/termios_baudtable.c b/cpukit/libcsupport/src/termios_baudtable.c
new file mode 100644
index 0000000000..92d1c6b809
--- /dev/null
+++ b/cpukit/libcsupport/src/termios_baudtable.c
@@ -0,0 +1,42 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/assoc.h>
+
+rtems_assoc_t termios_assoc_table[] = {
+ { "B0", 0, B0 },
+ { "B50", 50, B50 },
+ { "B75", 75, B75 },
+ { "B110", 110, B110 },
+ { "B134", 134, B134 },
+ { "B150", 150, B150 },
+ { "B200", 200, B200 },
+ { "B300", 300, B300 },
+ { "B600", 600, B600 },
+ { "B1200", 1200, B1200 },
+ { "B1800", 1800, B1800 },
+ { "B2400", 2400, B2400 },
+ { "B4800", 4800, B4800 },
+ { "B9600", 9600, B9600 },
+ { "B19200", 19200, B19200 },
+ { "B38400", 38400, B38400 },
+ { "B57600", 57600, B57600 },
+ { "B115200", 115200, B115200 },
+ { "B230400", 230400, B230400 },
+ { "B460800", 460800, B460800 },
+ { NULL, 0, 0 }
+};
diff --git a/cpukit/libcsupport/src/termios_num2baud.c b/cpukit/libcsupport/src/termios_num2baud.c
new file mode 100644
index 0000000000..3725609135
--- /dev/null
+++ b/cpukit/libcsupport/src/termios_num2baud.c
@@ -0,0 +1,32 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/assoc.h>
+
+extern rtems_assoc_t termios_assoc_table[];
+
+int rtems_termios_number_to_baud(
+ int32_t baud
+)
+{
+ int termios_baud;
+
+ termios_baud = rtems_assoc_remote_by_local( termios_assoc_table, baud );
+ if ( termios_baud == 0 && baud != 0 )
+ return -1;
+ return termios_baud;
+}
diff --git a/cpukit/libcsupport/src/termios_setinitialbaud.c b/cpukit/libcsupport/src/termios_setinitialbaud.c
new file mode 100644
index 0000000000..282f5533de
--- /dev/null
+++ b/cpukit/libcsupport/src/termios_setinitialbaud.c
@@ -0,0 +1,33 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/termios.h>
+#include <rtems/termiostypes.h>
+
+int rtems_termios_set_initial_baud(
+ struct rtems_termios_tty *ttyp,
+ int32_t baud
+)
+{
+ int cflags_baud;
+
+ cflags_baud = rtems_termios_number_to_baud(baud);
+ if ( cflags_baud == -1 )
+ return -1;
+
+ ttyp->termios.c_cflag = (ttyp->termios.c_cflag & ~CBAUD) | cflags_baud;
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/termiosinitialize.c b/cpukit/libcsupport/src/termiosinitialize.c
new file mode 100644
index 0000000000..b6660fe342
--- /dev/null
+++ b/cpukit/libcsupport/src/termiosinitialize.c
@@ -0,0 +1,54 @@
+/*
+ * Termios initialization routine
+ *
+ * Author:
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+struct rtems_termios_tty *rtems_termios_ttyHead;
+struct rtems_termios_tty *rtems_termios_ttyTail;
+rtems_id rtems_termios_ttyMutex;
+
+void
+rtems_termios_initialize (void)
+{
+ rtems_status_code sc;
+
+ /*
+ * Create the mutex semaphore for the tty list
+ */
+ if (!rtems_termios_ttyMutex) {
+ sc = rtems_semaphore_create (
+ rtems_build_name ('T', 'R', 'm', 'i'),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &rtems_termios_ttyMutex);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred (sc);
+ }
+}
diff --git a/cpukit/libcsupport/src/truncate.c b/cpukit/libcsupport/src/truncate.c
new file mode 100644
index 0000000000..7a0a98b4bd
--- /dev/null
+++ b/cpukit/libcsupport/src/truncate.c
@@ -0,0 +1,43 @@
+/*
+ * truncate() - Truncate a File to the Specified Length
+ *
+ * This routine is not defined in the POSIX 1003.1b standard but is
+ * commonly supported on most UNIX and POSIX systems. It is provided
+ * for compatibility.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+int truncate(
+ const char *path,
+ off_t length
+)
+{
+ int status;
+ int fd;
+
+ fd = open( path, O_WRONLY );
+ if ( fd == -1 )
+ return -1;
+
+ status = ftruncate( fd, length );
+
+ (void) close( fd );
+
+ return status;
+}
diff --git a/cpukit/libcsupport/src/ttyname.c b/cpukit/libcsupport/src/ttyname.c
new file mode 100644
index 0000000000..ed0b5cbdc1
--- /dev/null
+++ b/cpukit/libcsupport/src/ttyname.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_TTYNAME
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <termios.h>
+#include <unistd.h>
+#include <string.h>
+#include <paths.h>
+#include <_syslist.h>
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+static char ttyname_buf[sizeof (_PATH_DEV) + MAXNAMLEN];
+
+/*
+ * ttyname_r() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name
+ */
+int ttyname_r(
+ int fd,
+ char *name,
+ size_t namesize
+)
+{
+ struct stat sb;
+ struct termios tty;
+ struct dirent *dirp;
+ DIR *dp;
+ struct stat dsb;
+ char *rval;
+
+ /* Must be a terminal. */
+ if (tcgetattr (fd, &tty) < 0)
+ rtems_set_errno_and_return_minus_one(EBADF);
+
+ /* Must be a character device. */
+ if (fstat (fd, &sb) || !S_ISCHR (sb.st_mode))
+ rtems_set_errno_and_return_minus_one(EBADF);
+
+ if ((dp = opendir (_PATH_DEV)) == NULL)
+ rtems_set_errno_and_return_minus_one(EBADF);
+
+ /* Place the base directory in the path. */
+ strncpy (name, _PATH_DEV, namesize);
+
+ for (rval = NULL; (dirp = readdir (dp)) != NULL ;)
+ {
+ if (dirp->d_ino != sb.st_ino)
+ continue;
+ strcpy (name + sizeof (_PATH_DEV) - 1, dirp->d_name);
+ if (stat (name, &dsb) || sb.st_dev != dsb.st_dev ||
+ sb.st_ino != dsb.st_ino)
+ continue;
+ rval = name;
+ break;
+ }
+ (void) closedir (dp);
+ return 0;
+}
+
+/*
+ * ttyname() - POSIX 1003.1b 4.7.2 - Determine Terminal Device Name
+ */
+
+char *ttyname(
+ int fd
+)
+{
+ if ( !ttyname_r( fd, ttyname_buf, sizeof(ttyname_buf) ) )
+ return ttyname_buf;
+ return NULL;
+}
+
+#endif
diff --git a/cpukit/libcsupport/src/umask.c b/cpukit/libcsupport/src/umask.c
new file mode 100644
index 0000000000..32bf79e2b9
--- /dev/null
+++ b/cpukit/libcsupport/src/umask.c
@@ -0,0 +1,33 @@
+/*
+ * umask() - POSIX 1003.1b 5.3.3 - Set File Creation Mask
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtems/libio_.h>
+
+mode_t umask(
+ mode_t cmask
+)
+{
+ mode_t old_mask;
+
+ old_mask = rtems_filesystem_umask;
+ rtems_filesystem_umask = cmask;
+
+ return old_mask;
+}
diff --git a/cpukit/libcsupport/src/unlink.c b/cpukit/libcsupport/src/unlink.c
new file mode 100644
index 0000000000..bb28959b6d
--- /dev/null
+++ b/cpukit/libcsupport/src/unlink.c
@@ -0,0 +1,103 @@
+/*
+ * unlink() - POSIX 1003.1b - 5.5.1 - Remove an existing link
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int unlink(
+ const char *path
+)
+{
+ int parentpathlen;
+ const char *name;
+ rtems_filesystem_location_info_t parentloc;
+ rtems_filesystem_location_info_t loc;
+ int i;
+ int result;
+ bool free_parentloc = false;
+
+ /*
+ * Get the node to be unlinked. Find the parent path first.
+ */
+
+ parentpathlen = rtems_filesystem_dirname ( path );
+
+ if ( parentpathlen == 0 )
+ rtems_filesystem_get_start_loc( path, &i, &parentloc );
+ else {
+ result = rtems_filesystem_evaluate_path( path, parentpathlen,
+ RTEMS_LIBIO_PERMS_WRITE,
+ &parentloc,
+ false );
+ if ( result != 0 )
+ return -1;
+
+ free_parentloc = true;
+ }
+
+ /*
+ * Start from the parent to find the node that should be under it.
+ */
+
+ loc = parentloc;
+ name = path + parentpathlen;
+ name += rtems_filesystem_prefix_separators( name, strlen( name ) );
+
+ result = rtems_filesystem_evaluate_relative_path( name , strlen( name ),
+ 0, &loc, false );
+ if ( result != 0 ) {
+ if ( free_parentloc )
+ rtems_filesystem_freenode( &parentloc );
+ return -1;
+ }
+
+ if ( (*loc.ops->node_type_h)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) {
+ rtems_filesystem_freenode( &loc );
+ if ( free_parentloc )
+ rtems_filesystem_freenode( &parentloc );
+ rtems_set_errno_and_return_minus_one( EISDIR );
+ }
+
+ result = (*loc.ops->unlink_h)( &parentloc, &loc );
+
+ rtems_filesystem_freenode( &loc );
+ if ( free_parentloc )
+ rtems_filesystem_freenode( &parentloc );
+
+ return result;
+}
+
+/*
+ * _unlink_r
+ *
+ * This is the Newlib dependent reentrant version of unlink().
+ */
+
+#if defined(RTEMS_NEWLIB)
+
+#include <reent.h>
+
+int _unlink_r(
+ struct _reent *ptr __attribute__((unused)),
+ const char *path
+)
+{
+ return unlink( path );
+}
+#endif
diff --git a/cpukit/libcsupport/src/unmount.c b/cpukit/libcsupport/src/unmount.c
new file mode 100644
index 0000000000..a2c67f7098
--- /dev/null
+++ b/cpukit/libcsupport/src/unmount.c
@@ -0,0 +1,162 @@
+/*
+ * unmount() - Unmount a File System
+ *
+ * This routine is not defined in the POSIX 1003.1b standard but
+ * in some form is supported on most UNIX and POSIX systems. This
+ * routine is necessary to mount instantiations of a file system
+ * into the file system name space.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include <rtems/chain.h>
+
+static bool is_fs_below_mount_point(
+ const rtems_filesystem_mount_table_entry_t *mt_entry,
+ void *arg
+)
+{
+ return arg == mt_entry->mt_point_node.mt_entry;
+}
+
+/*
+ * unmount
+ *
+ * This routine will attempt to unmount the file system that has been
+ * is mounted a path. If the operation is successful, 0 will
+ * be returned to the calling routine. Otherwise, 1 will be returned.
+ */
+
+int unmount(
+ const char *path
+)
+{
+ rtems_filesystem_location_info_t loc;
+ rtems_filesystem_location_info_t *fs_root_loc;
+ rtems_filesystem_location_info_t *fs_mount_loc;
+ rtems_filesystem_mount_table_entry_t *mt_entry;
+
+ /*
+ * Get
+ * The root node of the mounted filesytem.
+ * The node for the directory that the fileystem is mounted on.
+ * The mount entry that is being refered to.
+ */
+
+ if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x0, &loc, true ) )
+ return -1;
+
+ mt_entry = loc.mt_entry;
+ fs_mount_loc = &mt_entry->mt_point_node;
+ fs_root_loc = &mt_entry->mt_fs_root;
+
+ /*
+ * Verify this is the root node for the file system to be unmounted.
+ */
+
+ if ( fs_root_loc->node_access != loc.node_access ){
+ rtems_filesystem_freenode( &loc );
+ rtems_set_errno_and_return_minus_one( EACCES );
+ }
+
+ /*
+ * Free the loc node and just use the nodes from the mt_entry .
+ */
+
+ rtems_filesystem_freenode( &loc );
+
+ /*
+ * Verify the current node is not in this filesystem.
+ * XXX - Joel I have a question here wasn't code added
+ * that made the current node thread based instead
+ * of system based? I thought it was but it doesn't
+ * look like it in this version.
+ */
+
+ if ( rtems_filesystem_current.mt_entry == mt_entry )
+ rtems_set_errno_and_return_minus_one( EBUSY );
+
+ /*
+ * Verify there are no file systems below the path specified
+ */
+
+ if ( rtems_filesystem_mount_iterate( is_fs_below_mount_point,
+ fs_root_loc->mt_entry ) )
+ rtems_set_errno_and_return_minus_one( EBUSY );
+
+ /*
+ * Run the file descriptor table to determine if there are any file
+ * descriptors that are currently active and reference nodes in the
+ * file system that we are trying to unmount
+ */
+
+ if ( rtems_libio_is_open_files_in_fs( mt_entry ) == 1 )
+ rtems_set_errno_and_return_minus_one( EBUSY );
+
+ /*
+ * Allow the file system being unmounted on to do its cleanup.
+ * If it fails it will set the errno to the approprate value
+ * and the fileystem will not be modified.
+ */
+
+ if (( fs_mount_loc->ops->unmount_h )( mt_entry ) != 0 )
+ return -1;
+
+ /*
+ * Allow the mounted filesystem to unmark the use of the root node.
+ *
+ * Run the unmount function for the subordinate file system.
+ *
+ * If we fail to unmount the filesystem remount it on the base filesystems
+ * directory node.
+ *
+ * NOTE: Fatal error is called in a case which should never happen
+ * This was response was questionable but the best we could
+ * come up with.
+ */
+
+ if ((fs_root_loc->ops->fsunmount_me_h )( mt_entry ) != 0){
+ if (( fs_mount_loc->ops->mount_h )( mt_entry ) != 0 )
+ rtems_fatal_error_occurred( 0 );
+ return -1;
+ }
+
+ /*
+ * Extract the mount table entry from the chain
+ */
+
+ rtems_libio_lock();
+ rtems_chain_extract( &mt_entry->Node );
+ rtems_libio_unlock();
+
+ /*
+ * Free the memory node that was allocated in mount
+ * Free the memory associated with the extracted mount table entry.
+ */
+
+ rtems_filesystem_freenode( fs_mount_loc );
+ free( mt_entry );
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/utime.c b/cpukit/libcsupport/src/utime.c
new file mode 100644
index 0000000000..25bcb0761b
--- /dev/null
+++ b/cpukit/libcsupport/src/utime.c
@@ -0,0 +1,47 @@
+/*
+ * utime() - POSIX 1003.1b 5.5.6 - Set File Access and Modification Times
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <utime.h>
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int utime(
+ const char *path,
+ const struct utimbuf *times
+)
+{
+ rtems_filesystem_location_info_t temp_loc;
+ int result;
+ struct utimbuf now;
+
+ if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x00, &temp_loc, true ) )
+ return -1;
+
+ if ( times == NULL ) {
+ now.actime = now.modtime = time( NULL );
+ times = &now;
+ }
+
+ result = (*temp_loc.ops->utime_h)( &temp_loc, times->actime, times->modtime );
+
+ rtems_filesystem_freenode( &temp_loc );
+
+ return result;
+}
diff --git a/cpukit/libcsupport/src/utimes.c b/cpukit/libcsupport/src/utimes.c
new file mode 100644
index 0000000000..b2070a9431
--- /dev/null
+++ b/cpukit/libcsupport/src/utimes.c
@@ -0,0 +1,33 @@
+/*
+ * Written by: Vinu Rajashekhar <vinutheraj@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <utime.h>
+#include <sys/time.h>
+
+int utimes(
+ const char *path,
+ const struct timeval times[2]
+)
+{
+ struct utimbuf timeinsecs;
+
+ if ( times == NULL )
+ return utime( path, NULL );
+
+ timeinsecs.actime = (time_t) times[0].tv_sec;
+ timeinsecs.modtime = (time_t) times[1].tv_sec;
+
+ return utime( path, &timeinsecs );
+}
diff --git a/cpukit/libcsupport/src/utsname.c b/cpukit/libcsupport/src/utsname.c
new file mode 100644
index 0000000000..564a762942
--- /dev/null
+++ b/cpukit/libcsupport/src/utsname.c
@@ -0,0 +1,49 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include <inttypes.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 4.4.1 Get System Name, P1003.1b-1993, p. 90
+ */
+
+int uname(
+ struct utsname *name
+)
+{
+ /* XXX: Here is what Solaris returns...
+ sysname = SunOS
+ nodename = node_name
+ release = 5.3
+ version = Generic_101318-12
+ machine = sun4m
+ */
+
+ if ( !name )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ strncpy( name->sysname, "RTEMS", sizeof(name->sysname) );
+
+ snprintf( name->nodename, sizeof(name->nodename), "Node %" PRId16, _Objects_Local_node );
+
+ strncpy( name->release, RTEMS_VERSION, sizeof(name->release) );
+
+ strncpy( name->version, "", sizeof(name->version) );
+
+ snprintf( name->machine, sizeof(name->machine), "%s/%s", CPU_NAME, CPU_MODEL_NAME );
+
+ return 0;
+}
diff --git a/cpukit/libcsupport/src/vprintk.c b/cpukit/libcsupport/src/vprintk.c
new file mode 100644
index 0000000000..852b5e302f
--- /dev/null
+++ b/cpukit/libcsupport/src/vprintk.c
@@ -0,0 +1,191 @@
+/*
+ * (C) Copyright 1997 -
+ * - NavIST Group - Real-Time Distributed Systems and Industrial Automation
+ *
+ * http://pandora.ist.utl.pt
+ *
+ * Instituto Superior Tecnico * Lisboa * PORTUGAL
+ *
+ * Disclaimer:
+ *
+ * This file is provided "AS IS" without warranty of any kind, either
+ * expressed or implied.
+ *
+ * This code is based on code by: Jose Rufino - IST
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <rtems/bspIo.h>
+
+static void printNum(
+ long num,
+ unsigned base,
+ bool sign,
+ unsigned maxwidth,
+ char lead
+);
+
+/*
+ * vprintk
+ *
+ * A simplified version of printf intended for use when the
+ * console is not yet initialized or in ISR's.
+ *
+ * Arguments:
+ * as in printf: fmt - format string, ... - unnamed arguments.
+ */
+void vprintk(
+ const char *fmt,
+ va_list ap
+)
+{
+ for (; *fmt != '\0'; fmt++) {
+ unsigned base = 0;
+ unsigned width = 0;
+ bool lflag = false;
+ bool minus = false;
+ bool sign = false;
+ char lead = ' ';
+ char c;
+
+ if (*fmt != '%') {
+ BSP_output_char(*fmt);
+ continue;
+ }
+ fmt++;
+ if (*fmt == '0' ) {
+ lead = '0';
+ fmt++;
+ }
+ if (*fmt == '-' ) {
+ minus = true;
+ fmt++;
+ }
+ while (*fmt >= '0' && *fmt <= '9' ) {
+ width *= 10;
+ width += ((unsigned) *fmt - '0');
+ fmt++;
+ }
+
+ if ((c = *fmt) == 'l') {
+ lflag = true;
+ c = *++fmt;
+ }
+ if ( c == 'c' ) {
+ /* need a cast here since va_arg() only takes fully promoted types */
+ char chr = (char) va_arg(ap, int);
+ BSP_output_char(chr);
+ continue;
+ }
+ if ( c == 's' ) {
+ unsigned i, len;
+ char *s, *str;
+
+ str = va_arg(ap, char *);
+
+ if ( str == NULL ) {
+ str = "";
+ }
+
+ /* calculate length of string */
+ for ( len=0, s=str ; *s ; len++, s++ )
+ ;
+
+ /* leading spaces */
+ if ( !minus )
+ for ( i=len ; i<width ; i++ )
+ BSP_output_char(' ');
+
+ /* no width option */
+ if (width == 0) {
+ width = len;
+ }
+
+ /* output the string */
+ for ( i=0 ; i<width && *str ; str++ )
+ BSP_output_char(*str);
+
+ /* trailing spaces */
+ if ( minus )
+ for ( i=len ; i<width ; i++ )
+ BSP_output_char(' ');
+
+ continue;
+ }
+
+ /* must be a numeric format or something unsupported */
+ if ( c == 'o' || c == 'O' ) {
+ base = 8; sign = false;
+ } else if ( c == 'i' || c == 'I' ||
+ c == 'd' || c == 'D' ) {
+ base = 10; sign = true;
+ } else if ( c == 'u' || c == 'U' ) {
+ base = 10; sign = false;
+ } else if ( c == 'x' || c == 'X' ) {
+ base = 16; sign = false;
+ } else if ( c == 'p' ) {
+ base = 16; sign = false; lflag = true;
+ } else {
+ BSP_output_char(c);
+ continue;
+ }
+
+ printNum(
+ lflag ? va_arg(ap, long) : (long) va_arg(ap, int),
+ base,
+ sign,
+ width,
+ lead
+ );
+ }
+}
+
+/*
+ * printNum - print number in a given base.
+ * Arguments
+ * num - number to print
+ * base - base used to print the number.
+ */
+static void printNum(
+ long num,
+ unsigned base,
+ bool sign,
+ unsigned maxwidth,
+ char lead
+)
+{
+ unsigned long unsigned_num;
+ unsigned long n;
+ unsigned count;
+ char toPrint[20];
+
+ if ( sign && (num < 0) ) {
+ BSP_output_char('-');
+ unsigned_num = (unsigned long) -num;
+ if (maxwidth) maxwidth--;
+ } else {
+ unsigned_num = (unsigned long) num;
+ }
+
+ count = 0;
+ while ((n = unsigned_num / base) > 0) {
+ toPrint[count++] = (char) (unsigned_num - (n * base));
+ unsigned_num = n;
+ }
+ toPrint[count++] = (char) unsigned_num;
+
+ for (n=maxwidth ; n > count; n-- )
+ BSP_output_char(lead);
+
+ for (n = 0; n < count; n++) {
+ BSP_output_char("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]);
+ }
+}
diff --git a/cpukit/libcsupport/src/write.c b/cpukit/libcsupport/src/write.c
new file mode 100644
index 0000000000..b723f426b6
--- /dev/null
+++ b/cpukit/libcsupport/src/write.c
@@ -0,0 +1,53 @@
+/*
+ * write() - POSIX 1003.1b 6.4.2 - Write to a File
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+/*
+ * write
+ *
+ * This routine writes count bytes from from buffer pointed to by buffer
+ * to the file associated with the open file descriptor, fildes.
+ */
+
+ssize_t write(
+ int fd,
+ const void *buffer,
+ size_t count
+)
+{
+ ssize_t rc;
+ rtems_libio_t *iop;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open( iop );
+ rtems_libio_check_buffer( buffer );
+ rtems_libio_check_count( count );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ /*
+ * Now process the write() request.
+ */
+ rc = (*iop->pathinfo.handlers->write_h)( iop, buffer, count );
+
+ if ( rc > 0 )
+ iop->offset += rc;
+
+ return rc;
+}
diff --git a/cpukit/libcsupport/src/write_r.c b/cpukit/libcsupport/src/write_r.c
new file mode 100644
index 0000000000..ad142a7364
--- /dev/null
+++ b/cpukit/libcsupport/src/write_r.c
@@ -0,0 +1,40 @@
+/*
+ * write_r() - POSIX 1003.1b 6.4.2 - Write to a File
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+/*
+ * _write_r
+ *
+ * This is the Newlib dependent reentrant version of write().
+ */
+
+#if defined(RTEMS_NEWLIB)
+
+#include <reent.h>
+
+_ssize_t _write_r(
+ struct _reent *ptr __attribute__((unused)),
+ int fd,
+ const void *buf,
+ size_t nbytes
+)
+{
+ return write( fd, buf, nbytes );
+}
+#endif
diff --git a/cpukit/libcsupport/src/writev.c b/cpukit/libcsupport/src/writev.c
new file mode 100644
index 0000000000..380e325365
--- /dev/null
+++ b/cpukit/libcsupport/src/writev.c
@@ -0,0 +1,128 @@
+/*
+ * writev() - POSIX 1003.1 - Read a Vector
+ *
+ * OpenGroup URL:
+ *
+ * http://www.opengroup.org/onlinepubs/009695399/functions/writev.html
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t writev(
+ int fd,
+ const struct iovec *iov,
+ int iovcnt
+)
+{
+ ssize_t total;
+ int v;
+ int bytes;
+ rtems_libio_t *iop;
+ ssize_t old;
+ bool all_zeros;
+
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_is_open( iop );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
+ /*
+ * Argument validation on IO vector
+ */
+ if ( !iov )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( iovcnt <= 0 )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( iovcnt > IOV_MAX )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * OpenGroup says that you are supposed to return EINVAL if the
+ * sum of the iov_len values in the iov array would overflow a
+ * ssize_t.
+ *
+ * Also we would like to ensure that no IO is performed if there
+ * are obvious errors in the iovec. So this extra loop ensures
+ * that we do not do anything if there is an argument error.
+ *
+ * In addition,the OpenGroup specification says that if all the
+ * iov_len entries are zero, then the call has no effect. So
+ * this loop does that check as well and sets "all-zero" appropriately.
+ * The variable "all_zero" is used as an early exit point before
+ * entering the write loop.
+ */
+ all_zeros = true;
+ for ( old=0, total=0, v=0 ; v < iovcnt ; v++ ) {
+
+ /*
+ * iov[v].iov_len cannot be less than 0 because size_t is unsigned.
+ * So we only check for zero.
+ */
+ if ( iov[v].iov_base == 0 )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( iov[v].iov_len )
+ all_zeros = false;
+
+ /* check for wrap */
+ old = total;
+ total += iov[v].iov_len;
+ if ( total < old || total > SSIZE_MAX )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ /*
+ * A writev with all zeros is supposed to have no effect per OpenGroup.
+ */
+ if ( all_zeros == true ) {
+ return 0;
+ }
+
+ /*
+ * Now process the writev().
+ */
+ for ( total=0, v=0 ; v < iovcnt ; v++ ) {
+ /* all zero lengths has no effect */
+ if ( iov[v].iov_len == 0 )
+ continue;
+
+ bytes = (*iop->pathinfo.handlers->write_h)(
+ iop,
+ iov[v].iov_base,
+ iov[v].iov_len
+ );
+
+ if ( bytes < 0 )
+ return -1;
+
+ if ( bytes > 0 ) {
+ iop->offset += bytes;
+ total += bytes;
+ }
+
+ if (bytes != iov[ v ].iov_len)
+ break;
+ }
+
+ return total;
+}
+
diff --git a/cpukit/libfs/.cvsignore b/cpukit/libfs/.cvsignore
new file mode 100644
index 0000000000..b52c5e8c77
--- /dev/null
+++ b/cpukit/libfs/.cvsignore
@@ -0,0 +1,3 @@
+Makefile
+Makefile.in
+stamp-h*
diff --git a/cpukit/libfs/Makefile.am b/cpukit/libfs/Makefile.am
new file mode 100644
index 0000000000..e0122a513f
--- /dev/null
+++ b/cpukit/libfs/Makefile.am
@@ -0,0 +1,103 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+# Pick up nfsclient
+if LIBNETWORKING
+NFSCLIENT_SUBDIR= src/nfsclient
+endif
+SUBDIRS = $(NFSCLIENT_SUBDIR)
+DIST_SUBDIRS = $(SUBDIRS)
+
+EXTRA_DIST = README
+
+noinst_LIBRARIES = libdefaultfs.a
+libdefaultfs_a_SOURCES = \
+ src/defaults/default_fchmod.c src/defaults/default_freenode.c \
+ src/defaults/default_fsync.c src/defaults/default_link.c \
+ src/defaults/default_read.c src/defaults/default_rmnod.c \
+ src/defaults/default_unlink.c src/defaults/default_chown.c \
+ src/defaults/default_fcntl.c src/defaults/default_fsmount.c \
+ src/defaults/default_ftruncate.c src/defaults/default_lseek.c \
+ src/defaults/default_readlink.c src/defaults/default_statvfs.c \
+ src/defaults/default_utime.c src/defaults/default_evalpath.c \
+ src/defaults/default_fdatasync.c src/defaults/default_fstat.c \
+ src/defaults/default_ioctl.c src/defaults/default_mount.c \
+ src/defaults/default_rename.c src/defaults/default_symlink.c \
+ src/defaults/default_write.c src/defaults/default_fpathconf.c \
+ src/defaults/default_unmount.c src/defaults/default_evaluate_link.c \
+ src/defaults/default_open.c src/defaults/default_close.c \
+ src/defaults/default_fsunmount.c src/defaults/default_mknod.c \
+ src/defaults/default_node_type.c src/defaults/default_evalformake.c \
+ src/defaults/default_handlers.c src/defaults/default_ops.c
+
+noinst_LIBRARIES += libimfs.a
+libimfs_a_SOURCES =
+
+libimfs_a_SOURCES += src/imfs/deviceerrno.c src/imfs/deviceio.c \
+ src/imfs/fifoimfs_init.c src/imfs/imfs_chown.c src/imfs/imfs_config.c \
+ src/imfs/imfs_creat.c src/imfs/imfs_debug.c src/imfs/imfs_directory.c \
+ src/imfs/imfs_eval.c src/imfs/imfs_fchmod.c \
+ src/imfs/imfs_fdatasync.c src/imfs/imfs_fifo.c \
+ src/imfs/imfs_fsunmount.c src/imfs/imfs_getchild.c \
+ src/imfs/imfs_gtkn.c src/imfs/imfs_handlers_device.c \
+ src/imfs/imfs_handlers_directory.c src/imfs/imfs_handlers_link.c \
+ src/imfs/imfs_handlers_memfile.c src/imfs/imfs_init.c \
+ src/imfs/imfs_initsupp.c src/imfs/imfs_link.c src/imfs/imfs_load_tar.c \
+ src/imfs/imfs_mknod.c src/imfs/imfs_mount.c src/imfs/imfs_ntype.c \
+ src/imfs/imfs_readlink.c src/imfs/imfs_rename.c src/imfs/imfs_rmnod.c \
+ src/imfs/imfs_stat.c src/imfs/imfs_symlink.c src/imfs/imfs_unlink.c \
+ src/imfs/imfs_unmount.c src/imfs/imfs_utime.c src/imfs/ioman.c \
+ src/imfs/memfile.c src/imfs/miniimfs_init.c src/imfs/imfs.h
+
+# POSIX FIFO/pipe
+libimfs_a_SOURCES += src/pipe/fifo.c src/pipe/pipe.c src/pipe/pipe.h
+
+noinst_LIBRARIES += libdevfs.a
+libdevfs_a_SOURCES = src/devfs/devfs_init.c src/devfs/devfs_eval.c \
+ src/devfs/devfs_mknod.c src/devfs/devfs_show.c \
+ src/devfs/devfs_node_type.c src/devfs/devopen.c src/devfs/devread.c \
+ src/devfs/devwrite.c src/devfs/devclose.c src/devfs/devioctl.c \
+ src/devfs/devstat.c src/devfs/devfs.h
+
+# dosfs
+if LIBDOSFS
+noinst_LIBRARIES += libdosfs.a
+
+# libdosfs_FATFS_C_FILES
+libdosfs_a_SOURCES = src/dosfs/fat.c src/dosfs/fat.h \
+ src/dosfs/fat_fat_operations.c src/dosfs/fat_fat_operations.h \
+ src/dosfs/fat_file.c src/dosfs/fat_file.h
+
+# libdosfs_DOSFS_C_FILES
+libdosfs_a_SOURCES += src/dosfs/msdos_create.c src/dosfs/msdos_dir.c \
+ src/dosfs/msdos_eval.c src/dosfs/msdos_file.c src/dosfs/msdos_free.c \
+ src/dosfs/msdos_fsunmount.c src/dosfs/msdos_handlers_dir.c \
+ src/dosfs/msdos_handlers_file.c src/dosfs/msdos_init.c \
+ src/dosfs/msdos_initsupp.c src/dosfs/msdos_misc.c \
+ src/dosfs/msdos_mknod.c src/dosfs/msdos_node_type.c \
+ src/dosfs/msdos_conv.c src/dosfs/msdos.h src/dosfs/msdos_format.c \
+ src/dosfs/dosfs.h src/dosfs/msdos_rename.c
+endif
+
+# RFS
+noinst_LIBRARIES += librfs.a
+librfs_a_SOURCES = \
+ src/rfs/rtems-rfs-bitmaps.c src/rfs/rtems-rfs-block.c \
+ src/rfs/rtems-rfs-buffer-bdbuf.c src/rfs/rtems-rfs-buffer.c \
+ src/rfs/rtems-rfs-dir-hash.c src/rfs/rtems-rfs-file.c \
+ src/rfs/rtems-rfs-group.c src/rfs/rtems-rfs-inode.c \
+ src/rfs/rtems-rfs-rtems-dev.c src/rfs/rtems-rfs-rtems-utils.c \
+ src/rfs/rtems-rfs-rtems.c src/rfs/rtems-rfs-shell.c \
+ src/rfs/rtems-rfs-bitmaps-ut.c src/rfs/rtems-rfs-dir.c \
+ src/rfs/rtems-rfs-file-system.c src/rfs/rtems-rfs-format.c \
+ src/rfs/rtems-rfs-link.c src/rfs/rtems-rfs-mutex.c \
+ src/rfs/rtems-rfs-rtems-dir.c src/rfs/rtems-rfs-rtems-file.c \
+ src/rfs/rtems-rfs-trace.c
+
+# ---
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libfs/README b/cpukit/libfs/README
new file mode 100644
index 0000000000..dfd7682099
--- /dev/null
+++ b/cpukit/libfs/README
@@ -0,0 +1,29 @@
+#
+# $Id$
+#
+
+This directory contains for the "file system" library. All supported
+file systems live under this tree.
+
+Currently the supported file systems in this library are:
+
+- IMFS or In Memory File System
+
+ This is the only root file system on RTEMS at the moment. It supports
+ files, directories, device nodes and mount points. It can also be
+ configured to be the miniIMFS.
+
+- TFTP and FTP filesystem are part of the libnetworking library.
+
+- DEVFS or Device File system
+
+- DOSFS, a FAT 12/16/32 MSDOS compatible file system.
+
+- NFS Client, can mount NFS exported file systems.
+
+- PIPE, a pipe file system.
+
+- RFS, The RTEMS File System.
+
+--Chris Johns and Joel Sherrill
+ 17 Feb 2010
diff --git a/cpukit/libfs/preinstall.am b/cpukit/libfs/preinstall.am
new file mode 100644
index 0000000000..dba6cc4d81
--- /dev/null
+++ b/cpukit/libfs/preinstall.am
@@ -0,0 +1,7 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
diff --git a/cpukit/libfs/src/defaults/default_chown.c b/cpukit/libfs/src/defaults/default_chown.c
new file mode 100644
index 0000000000..82cb0b694f
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_chown.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_chown(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ uid_t owner, /* IN */
+ gid_t group /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_close.c b/cpukit/libfs/src/defaults/default_close.c
new file mode 100644
index 0000000000..bd7082184c
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_close.c
@@ -0,0 +1,19 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+
+int rtems_filesystem_default_close(
+ rtems_libio_t *iop
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/defaults/default_evalformake.c b/cpukit/libfs/src/defaults/default_evalformake.c
new file mode 100644
index 0000000000..891d961dc1
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_evalformake.c
@@ -0,0 +1,32 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief rtems_filesystem_default_evalformake() implementation.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/libio.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_evalformake(
+ const char *path,
+ rtems_filesystem_location_info_t *pathloc,
+ const char **name
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_evalpath.c b/cpukit/libfs/src/defaults/default_evalpath.c
new file mode 100644
index 0000000000..1e3f762cbe
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_evalpath.c
@@ -0,0 +1,25 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_evalpath(
+ const char *pathname, /* IN */
+ size_t pathnamelen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
+
diff --git a/cpukit/libfs/src/defaults/default_evaluate_link.c b/cpukit/libfs/src/defaults/default_evaluate_link.c
new file mode 100644
index 0000000000..a82c73729f
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_evaluate_link.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_evaluate_link(
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ int flags /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
+
diff --git a/cpukit/libfs/src/defaults/default_fchmod.c b/cpukit/libfs/src/defaults/default_fchmod.c
new file mode 100644
index 0000000000..cda32c82d5
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fchmod.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fchmod(
+ rtems_filesystem_location_info_t *loc,
+ mode_t mode
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_fcntl.c b/cpukit/libfs/src/defaults/default_fcntl.c
new file mode 100644
index 0000000000..d9d8602e40
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fcntl.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fcntl(
+ int cmd,
+ rtems_libio_t *iop
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/defaults/default_fdatasync.c b/cpukit/libfs/src/defaults/default_fdatasync.c
new file mode 100644
index 0000000000..90677df5c4
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fdatasync.c
@@ -0,0 +1,21 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fdatasync(
+ rtems_libio_t *iop
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_fpathconf.c b/cpukit/libfs/src/defaults/default_fpathconf.c
new file mode 100644
index 0000000000..f65d7d92fc
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fpathconf.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fpathconf(
+ rtems_libio_t *iop,
+ int name
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_freenode.c b/cpukit/libfs/src/defaults/default_freenode.c
new file mode 100644
index 0000000000..bb231d13f7
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_freenode.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_freenode(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ return 0;
+}
+
diff --git a/cpukit/libfs/src/defaults/default_fsmount.c b/cpukit/libfs/src/defaults/default_fsmount.c
new file mode 100644
index 0000000000..5a442c82b6
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fsmount.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fsmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */
+ const void *data /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_fstat.c b/cpukit/libfs/src/defaults/default_fstat.c
new file mode 100644
index 0000000000..6c8d501a21
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fstat.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fstat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_fsunmount.c b/cpukit/libfs/src/defaults/default_fsunmount.c
new file mode 100644
index 0000000000..e879f5c2f8
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fsunmount.c
@@ -0,0 +1,21 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fsunmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/defaults/default_fsync.c b/cpukit/libfs/src/defaults/default_fsync.c
new file mode 100644
index 0000000000..5cd352e9d4
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_fsync.c
@@ -0,0 +1,21 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_fsync(
+ rtems_libio_t *iop
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_ftruncate.c b/cpukit/libfs/src/defaults/default_ftruncate.c
new file mode 100644
index 0000000000..9214b77448
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_ftruncate.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_ftruncate(
+ rtems_libio_t *iop,
+ rtems_off64_t length
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_handlers.c b/cpukit/libfs/src/defaults/default_handlers.c
new file mode 100644
index 0000000000..5343875295
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_handlers.c
@@ -0,0 +1,39 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief rtems_filesystem_handlers_default definition.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/libio.h>
+
+const rtems_filesystem_file_handlers_r rtems_filesystem_handlers_default = {
+ .open_h = rtems_filesystem_default_open,
+ .close_h = rtems_filesystem_default_close,
+ .read_h = rtems_filesystem_default_read,
+ .write_h = rtems_filesystem_default_write,
+ .ioctl_h = rtems_filesystem_default_ioctl,
+ .lseek_h = rtems_filesystem_default_lseek,
+ .fstat_h = rtems_filesystem_default_fstat,
+ .fchmod_h = rtems_filesystem_default_fchmod,
+ .ftruncate_h = rtems_filesystem_default_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_filesystem_default_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_filesystem_default_rmnod
+};
diff --git a/cpukit/libfs/src/defaults/default_ioctl.c b/cpukit/libfs/src/defaults/default_ioctl.c
new file mode 100644
index 0000000000..06816c48d8
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_ioctl.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_link.c b/cpukit/libfs/src/defaults/default_link.c
new file mode 100644
index 0000000000..d9bc913b27
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_link.c
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_link(
+ rtems_filesystem_location_info_t *to_loc, /* IN */
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *name /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
+
diff --git a/cpukit/libfs/src/defaults/default_lseek.c b/cpukit/libfs/src/defaults/default_lseek.c
new file mode 100644
index 0000000000..21ae23ee93
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_lseek.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+rtems_off64_t rtems_filesystem_default_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t length,
+ int whence
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_mknod.c b/cpukit/libfs/src/defaults/default_mknod.c
new file mode 100644
index 0000000000..fcd03be4c2
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_mknod.c
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_mknod(
+ const char *path, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_mount.c b/cpukit/libfs/src/defaults/default_mount.c
new file mode 100644
index 0000000000..9063b554bc
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_mount.c
@@ -0,0 +1,21 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_mount (
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/defaults/default_node_type.c b/cpukit/libfs/src/defaults/default_node_type.c
new file mode 100644
index 0000000000..a118a04f72
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_node_type.c
@@ -0,0 +1,29 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief rtems_filesystem_default_node_type() implementation.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/libio.h>
+
+rtems_filesystem_node_types_t rtems_filesystem_default_node_type(
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ return RTEMS_FILESYSTEM_INVALID_NODE_TYPE;
+}
diff --git a/cpukit/libfs/src/defaults/default_open.c b/cpukit/libfs/src/defaults/default_open.c
new file mode 100644
index 0000000000..b119fbf5be
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_open.c
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_ops.c b/cpukit/libfs/src/defaults/default_ops.c
new file mode 100644
index 0000000000..575cf6b2d4
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_ops.c
@@ -0,0 +1,43 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ *
+ * @brief rtems_filesystem_operations_default definition.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/libio.h>
+
+const rtems_filesystem_operations_table rtems_filesystem_operations_default = {
+ .evalpath_h = rtems_filesystem_default_evalpath,
+ .evalformake_h = rtems_filesystem_default_evalformake,
+ .link_h = rtems_filesystem_default_link,
+ .unlink_h = rtems_filesystem_default_unlink,
+ .node_type_h = rtems_filesystem_default_node_type,
+ .mknod_h = rtems_filesystem_default_mknod,
+ .chown_h = rtems_filesystem_default_chown,
+ .freenod_h = rtems_filesystem_default_freenode,
+ .mount_h = rtems_filesystem_default_mount,
+ .fsmount_me_h = rtems_filesystem_default_fsmount,
+ .unmount_h = rtems_filesystem_default_unmount,
+ .fsunmount_me_h = rtems_filesystem_default_fsunmount,
+ .utime_h = rtems_filesystem_default_utime,
+ .eval_link_h = rtems_filesystem_default_evaluate_link,
+ .symlink_h = rtems_filesystem_default_symlink,
+ .readlink_h = rtems_filesystem_default_readlink,
+ .rename_h = rtems_filesystem_default_rename,
+ .statvfs_h = rtems_filesystem_default_statvfs
+};
diff --git a/cpukit/libfs/src/defaults/default_read.c b/cpukit/libfs/src/defaults/default_read.c
new file mode 100644
index 0000000000..2f6d7e9d72
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_read.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t rtems_filesystem_default_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_readlink.c b/cpukit/libfs/src/defaults/default_readlink.c
new file mode 100644
index 0000000000..1d07970999
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_readlink.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t rtems_filesystem_default_readlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ char *buf, /* OUT */
+ size_t bufsize
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_rename.c b/cpukit/libfs/src/defaults/default_rename.c
new file mode 100644
index 0000000000..93bf15f2e0
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_rename.c
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_rename(
+ rtems_filesystem_location_info_t *old_parent_loc, /* IN */
+ rtems_filesystem_location_info_t *old_loc, /* IN */
+ rtems_filesystem_location_info_t *new_parent_loc, /* IN */
+ const char *name /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_rmnod.c b/cpukit/libfs/src/defaults/default_rmnod.c
new file mode 100644
index 0000000000..776ee4b659
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_rmnod.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_rmnod(
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_statvfs.c b/cpukit/libfs/src/defaults/default_statvfs.c
new file mode 100644
index 0000000000..22d891815f
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_statvfs.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_statvfs(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct statvfs *buf /* OUT */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_symlink.c b/cpukit/libfs/src/defaults/default_symlink.c
new file mode 100644
index 0000000000..8985d76aef
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_symlink.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_symlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ const char *link_name, /* IN */
+ const char *node_name
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_unlink.c b/cpukit/libfs/src/defaults/default_unlink.c
new file mode 100644
index 0000000000..cf633c6ce1
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_unlink.c
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_unlink(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/defaults/default_unmount.c b/cpukit/libfs/src/defaults/default_unmount.c
new file mode 100644
index 0000000000..9fc53c060f
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_unmount.c
@@ -0,0 +1,21 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_unmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/defaults/default_utime.c b/cpukit/libfs/src/defaults/default_utime.c
new file mode 100644
index 0000000000..77a2f2e8d6
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_utime.c
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int rtems_filesystem_default_utime(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
+
diff --git a/cpukit/libfs/src/defaults/default_write.c b/cpukit/libfs/src/defaults/default_write.c
new file mode 100644
index 0000000000..97f057f08f
--- /dev/null
+++ b/cpukit/libfs/src/defaults/default_write.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t rtems_filesystem_default_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+}
diff --git a/cpukit/libfs/src/devfs/devclose.c b/cpukit/libfs/src/devfs/devclose.c
new file mode 100644
index 0000000000..773cade5c6
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devclose.c
@@ -0,0 +1,41 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/io.h>
+
+#include "devfs.h"
+
+int devFS_close(
+ rtems_libio_t *iop
+)
+{
+ rtems_libio_open_close_args_t args;
+ rtems_status_code status;
+ rtems_device_name_t *np;
+
+ np = (rtems_device_name_t *)iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.flags = 0;
+ args.mode = 0;
+
+ status = rtems_io_close(
+ np->major,
+ np->minor,
+ (void *) &args
+ );
+
+ return rtems_deviceio_errno(status);
+}
+
+
diff --git a/cpukit/libfs/src/devfs/devfs.h b/cpukit/libfs/src/devfs/devfs.h
new file mode 100644
index 0000000000..eafa069cb8
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devfs.h
@@ -0,0 +1,280 @@
+/**
+* @file libfs/devfs/devfs.h
+*
+* This include file contains all constants and structures associated
+* with the 'device-only' filesystem.
+*/
+
+#ifndef _RTEMS_DEVFS_H
+#define _RTEMS_DEVFS_H
+
+#include <rtems/libio_.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This structure define the type of device table
+ */
+
+typedef struct
+{
+ /** This member points to device name which is a null-terminated string */
+ char *device_name;
+ /** This member is the name length of a device */
+ uint32_t device_name_length;
+ /** major number of a device */
+ rtems_device_major_number major;
+ /** minor number of a device */
+ rtems_device_minor_number minor;
+ /** device creation mode, only device file can be created */
+ mode_t mode;
+
+} rtems_device_name_t;
+
+
+
+/**
+ * This routine associates RTEMS status code with errno
+ */
+
+extern int rtems_deviceio_errno(rtems_status_code code);
+
+
+/**
+ * The following defines the device table size. This values
+ * is configured during application configuration time by
+ * the user. The default value is set to 4.
+ */
+
+extern uint32_t rtems_device_table_size;
+
+/**
+ * This handler maps open operation to rtems_io_open.
+ * @param iop This is the RTEMS's internal representation of file.
+ * @param pathname a null-terminated string that starts with /dev.
+ * @param flag access flags
+ * @param mode access mode
+ * @retval the same as open
+ */
+
+extern int devFS_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+);
+
+
+/**
+ * This handler maps close operation to rtems_io_close.
+ * @param iop This is the RTEMS's internal representation of file
+ * @retval the same as close
+ */
+
+
+extern int devFS_close(
+ rtems_libio_t *iop
+);
+
+
+/**
+ * This handler maps read operation to rtems_io_read.
+ * @param iop This is the RTEMS's internal representation of file
+ * @param buffer memory location to store read data
+ * @param count how many bytes to read
+ * @retval On successful, this routine returns total bytes read. On error
+ * it returns -1 and errno is set to proper value.
+ */
+
+extern ssize_t devFS_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+);
+
+
+/**
+ * This handler maps write operation to rtems_io_write.
+ * @param iop This is the RTEMS's internal representation of file
+ * @param buffer data to be written
+ * @param count how many bytes to write
+ * @retval On successful, this routine returns total bytes written. On error
+ * it returns -1 and errno is set to proper value.
+ */
+
+extern ssize_t devFS_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+);
+
+
+/**
+ * This handler maps ioctl operation to rtems_io_ioctl.
+ * @param iop This is the RTEMS's internal representation of file
+ * @param command io control command
+ * @param buffer io control parameters
+ * @retval On successful, this routine returns total bytes written. On error
+ * it returns -1 and errno is set to proper value.
+ */
+
+extern int devFS_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+);
+
+
+
+
+/**
+ * This handler gets the device file information. This routine only set the following member of struct stat:
+ * st_dev : device number
+ * st_mode: device file creation mode, only two mode are accepted:
+ * S_IFCHR: character device file
+ * S_IFBLK: block device file
+ * @param loc contains filesystem access information
+ * @param buf buffer to hold the device file's information
+ * @retval On successful, this routine returns 0. On error
+ * it returns -1 and errno is set to proper value.
+ */
+
+extern int devFS_stat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+);
+
+
+
+/**
+ * This routine is invoked upon determination of a node type.
+ * Since this is a device-only filesystem, so there is only
+ * one node type in the system.
+ *
+ * @param pathloc contains filesytem access information, this
+ * parameter is ignored
+ * @retval always returns RTEMS_FILESYSTEM_DEVICE
+ */
+
+extern rtems_filesystem_node_types_t devFS_node_type(
+ rtems_filesystem_location_info_t *pathloc
+);
+
+
+
+/**
+ * This routine is invoked to determine if 'pathname' exists.
+ * This routine first check access flags, then it searches
+ * the device table to get the information.
+ *
+ * @param pathname device name to be searched
+ * @param flags access flags
+ * @param pathloc contains filesystem access information
+ * @retval upon success(pathname exists), this routines
+ * returns 0; if 'flag' is invalid, it returns -1 and errno
+ * is set to EIO; otherwise, it returns -1 and errno is set to ENOENT
+ */
+
+extern int devFS_evaluate_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc
+);
+
+
+/**
+ * This routine is given a path to evaluate and a valid start
+ * location. It is responsible for finding the parent node for
+ * a requested make command, setting pathloc information to
+ * identify the parent node, and setting the name pointer to
+ * the first character of the name of the new node. In device
+ * only filesystem, devices do not has a tree hierarchy, there
+ * are no parent-child relationship. So this routine is rather
+ * simple, it just set *name to path and returns
+ *
+ * @param path device path to be evaluated
+ * @param pathloc contains filesystem access information, this
+ * parameter is ignored
+ * @param name
+ * @retval always returns 0
+ */
+
+extern int devFS_evaluate_for_make(
+ const char *path,
+ rtems_filesystem_location_info_t *pathloc,
+ const char **name
+);
+
+
+
+/**
+ * This routine is invoked upon registration of a new device
+ * file. It is responsible for creating a item in the main
+ * device table. This routine searches the device table in
+ * sequential order, when found a empty slot, it fills the slot
+ * with proper values.
+ *
+ * @param path the device file name to be registered
+ * @param mode file mode, this parameter is ignored
+ * @param dev device major and minor number
+ * @param pathloc contains filesystem access information
+ * @retval upon success, this routine returns 0; if 'path'
+ * already exist, it returns -1 and errno is set to EEXIST;
+ * if device table is full, it returns -1 and errno is set
+ * to ENOMEM
+ */
+
+extern int devFS_mknod(
+ const char *path,
+ mode_t mode,
+ dev_t dev,
+ rtems_filesystem_location_info_t *pathloc
+);
+
+
+/**
+ * This routine is invoked upon rtems filesystem initialization.
+ * It is responsible for creating the main device table,
+ * initializing it to a known state, and set device file operation
+ * handlers. After this, the device-only filesytem is ready for use
+ *
+ * @param mt_entry The filesystem mount table entry.
+ * @param data Filesystem specific data.
+ * @retval upon success, this routine returns 0; otherwise it returns
+ * -1 and errno is set to proper value. The only error is when malloc
+ * failed, and errno is set to NOMEM.
+ */
+
+extern int devFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+);
+
+
+/**
+ * This routine retrieves all the device registered in system, and
+ * prints out their detail information. For example, on one system,
+ * devFS_show will print out following message:
+ *
+ * /dev/console 0 0
+ * /dev/clock 1 0
+ * /dev/tty0 0 0
+ * /flash 2 0
+ *
+ * This routine is intended for debugging, and can be used by shell
+ * program to provide user with the system information.
+ *
+ * @retval 0
+ */
+
+extern int devFS_Show(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/cpukit/libfs/src/devfs/devfs_eval.c b/cpukit/libfs/src/devfs/devfs_eval.c
new file mode 100644
index 0000000000..a3169fb3fa
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devfs_eval.c
@@ -0,0 +1,85 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/seterr.h>
+#include <fcntl.h>
+#include <assert.h>
+#include "devfs.h"
+
+/**
+ * The following defines the device-only filesystem operating
+ * handlers.
+ */
+
+extern rtems_filesystem_operations_table devFS_ops;
+
+/**
+ * The following defines the device-only filesystem operating
+ * handlers.
+ */
+
+extern rtems_filesystem_file_handlers_r devFS_file_handlers;
+
+int devFS_evaluate_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ int i;
+ rtems_device_name_t *device_name_table;
+
+ /* see if 'flags' is valid */
+ if ( !rtems_libio_is_valid_perms( flags ) )
+ rtems_set_errno_and_return_minus_one( EPERM );
+
+ /* get the device name table */
+ device_name_table = (rtems_device_name_t *)pathloc->node_access;
+ if (!device_name_table)
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ for (i = 0; i < rtems_device_table_size; i++) {
+ if (!device_name_table[i].device_name)
+ continue;
+
+ if (strncmp(pathname, device_name_table[i].device_name, pathnamelen) != 0)
+ continue;
+
+ if (device_name_table[i].device_name[pathnamelen] != '\0')
+ continue;
+
+ /* find the device, set proper values */
+ pathloc->node_access = (void *)&device_name_table[i];
+ pathloc->handlers = &devFS_file_handlers;
+ pathloc->ops = &devFS_ops;
+ pathloc->mt_entry = rtems_filesystem_root.mt_entry;
+ return 0;
+ }
+
+ /* no such file or directory */
+ rtems_set_errno_and_return_minus_one( ENOENT );
+}
+
+
+
+int devFS_evaluate_for_make(
+ const char *path,
+ rtems_filesystem_location_info_t *pathloc,
+ const char **name
+)
+{
+ /* we do nothing, just set name to path */
+ *name = path;
+ return 0;
+}
+
diff --git a/cpukit/libfs/src/devfs/devfs_init.c b/cpukit/libfs/src/devfs/devfs_init.c
new file mode 100644
index 0000000000..5f6521a045
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devfs_init.c
@@ -0,0 +1,92 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <rtems.h>
+#include <rtems/seterr.h>
+#include <rtems/score/wkspace.h>
+#include "devfs.h"
+
+rtems_filesystem_operations_table devFS_ops =
+{
+ devFS_evaluate_path,
+ devFS_evaluate_for_make,
+ rtems_filesystem_default_link,
+ rtems_filesystem_default_unlink,
+ devFS_node_type,
+ devFS_mknod,
+ rtems_filesystem_default_chown,
+ rtems_filesystem_default_freenode,
+ rtems_filesystem_default_mount,
+ devFS_initialize,
+ rtems_filesystem_default_unmount,
+ rtems_filesystem_default_fsunmount,
+ rtems_filesystem_default_utime,
+ rtems_filesystem_default_evaluate_link,
+ rtems_filesystem_default_symlink,
+ rtems_filesystem_default_readlink,
+ rtems_filesystem_default_rename,
+ rtems_filesystem_default_statvfs
+};
+
+
+rtems_filesystem_file_handlers_r devFS_file_handlers =
+{
+ devFS_open,
+ devFS_close,
+ devFS_read,
+ devFS_write,
+ devFS_ioctl,
+ rtems_filesystem_default_lseek,
+ devFS_stat,
+ rtems_filesystem_default_fchmod,
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ rtems_filesystem_default_rmnod
+};
+
+
+
+int devFS_initialize(
+ rtems_filesystem_mount_table_entry_t *temp_mt_entry,
+ const void *data
+)
+{
+ rtems_device_name_t *device_name_table;
+
+ /* allocate device only filesystem name table */
+ device_name_table = (rtems_device_name_t *)_Workspace_Allocate(
+ sizeof( rtems_device_name_t ) * ( rtems_device_table_size )
+ );
+
+ /* no memory for device filesystem */
+ if (!device_name_table)
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ memset(
+ device_name_table, 0,
+ sizeof( rtems_device_name_t ) * ( rtems_device_table_size )
+ );
+
+ /* set file handlers */
+ temp_mt_entry->mt_fs_root.handlers = &devFS_file_handlers;
+ temp_mt_entry->mt_fs_root.ops = &devFS_ops;
+
+ /* Set the node_access to device name table */
+ temp_mt_entry->mt_fs_root.node_access = (void *)device_name_table;
+
+ return 0;
+}
+
diff --git a/cpukit/libfs/src/devfs/devfs_mknod.c b/cpukit/libfs/src/devfs/devfs_mknod.c
new file mode 100644
index 0000000000..d8e5a30d5f
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devfs_mknod.c
@@ -0,0 +1,81 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/seterr.h>
+#include "devfs.h"
+
+int devFS_mknod(
+ const char *path,
+ mode_t mode,
+ dev_t dev,
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ int i;
+ int slot;
+ rtems_device_name_t *device_name_table;
+ rtems_device_major_number major;
+ rtems_device_minor_number minor;
+ ISR_Level level;
+
+ /*
+ * This is a special case. In rtems_filesystem_initialize,
+ * a special device '/dev' will be created. We check this
+ * condition and do not create the '/dev' and the 'path'
+ * actually passed in is 'dev', not '/dev'. Just return 0 to
+ * indicate we are OK.
+ */
+
+ if ((path[0] == 'd') && (path[1] == 'e') &&
+ (path[2] == 'v') && (path[3] == '\0'))
+ return 0;
+
+ /* must be a character device or a block device */
+ if (!S_ISBLK(mode) && !S_ISCHR(mode))
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ else
+ rtems_filesystem_split_dev_t(dev, major, minor);
+
+ /* Find an empty slot in device name table */
+ device_name_table = (rtems_device_name_t *)pathloc->node_access;
+ if (!device_name_table)
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ for (slot = -1, i = 0; i < rtems_device_table_size; i++){
+ if (device_name_table[i].device_name == NULL)
+ slot = i;
+ else
+ if (strcmp(path, device_name_table[i].device_name) == 0)
+ rtems_set_errno_and_return_minus_one( EEXIST );
+ }
+
+ if (slot == -1)
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ _ISR_Disable(level);
+ device_name_table[slot].device_name = (char *)path;
+ device_name_table[slot].device_name_length = strlen(path);
+ device_name_table[slot].major = major;
+ device_name_table[slot].minor = minor;
+ device_name_table[slot].mode = mode;
+ _ISR_Enable(level);
+
+ return 0;
+}
+
diff --git a/cpukit/libfs/src/devfs/devfs_node_type.c b/cpukit/libfs/src/devfs/devfs_node_type.c
new file mode 100644
index 0000000000..0bede52d2d
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devfs_node_type.c
@@ -0,0 +1,26 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "devfs.h"
+
+rtems_filesystem_node_types_t devFS_node_type(
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ /*
+ * There is only one type of node: device
+ */
+
+ return RTEMS_FILESYSTEM_DEVICE;
+}
+
+
diff --git a/cpukit/libfs/src/devfs/devfs_show.c b/cpukit/libfs/src/devfs/devfs_show.c
new file mode 100644
index 0000000000..e449caf49f
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devfs_show.c
@@ -0,0 +1,36 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/seterr.h>
+#include "devfs.h"
+
+int devFS_Show(void)
+{
+ int i;
+ rtems_filesystem_location_info_t *temp_loc;
+ rtems_device_name_t *device_name_table;
+
+ temp_loc = &rtems_filesystem_root;
+ device_name_table = (rtems_device_name_t *)temp_loc->node_access;
+ if (!device_name_table)
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ for (i = 0; i < rtems_device_table_size; i++){
+ if (device_name_table[i].device_name){
+ printk("/%s %d %d\n", device_name_table[i].device_name,
+ device_name_table[i].major, device_name_table[i].minor);
+ }
+ }
+ return 0;
+}
+
+
diff --git a/cpukit/libfs/src/devfs/devioctl.c b/cpukit/libfs/src/devfs/devioctl.c
new file mode 100644
index 0000000000..15965b8c0e
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devioctl.c
@@ -0,0 +1,45 @@
+#if HAVE_CONFIG_H
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/io.h>
+
+#include "devfs.h"
+
+int devFS_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+)
+{
+ rtems_libio_ioctl_args_t args;
+ rtems_status_code status;
+ rtems_device_name_t *np;
+
+ np = (rtems_device_name_t *)iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.command = command;
+ args.buffer = buffer;
+
+ status = rtems_io_control(
+ np->major,
+ np->minor,
+ (void *) &args
+ );
+
+ if ( status )
+ return rtems_deviceio_errno(status);
+
+ return args.ioctl_return;
+}
+
diff --git a/cpukit/libfs/src/devfs/devopen.c b/cpukit/libfs/src/devfs/devopen.c
new file mode 100644
index 0000000000..67be3678e1
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devopen.c
@@ -0,0 +1,42 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/io.h>
+
+#include "devfs.h"
+
+int devFS_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ rtems_libio_open_close_args_t args;
+ rtems_status_code status;
+ rtems_device_name_t *np;
+
+ np = (rtems_device_name_t *)iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.flags = iop->flags;
+ args.mode = mode;
+
+ status = rtems_io_open(
+ np->major,
+ np->minor,
+ (void *) &args
+ );
+
+ return rtems_deviceio_errno(status);
+}
diff --git a/cpukit/libfs/src/devfs/devread.c b/cpukit/libfs/src/devfs/devread.c
new file mode 100644
index 0000000000..10f74e81c9
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devread.c
@@ -0,0 +1,48 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/io.h>
+
+#include "devfs.h"
+
+ssize_t devFS_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ rtems_libio_rw_args_t args;
+ rtems_status_code status;
+ rtems_device_name_t *np;
+
+ np = (rtems_device_name_t *)iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.offset = iop->offset;
+ args.buffer = buffer;
+ args.count = count;
+ args.flags = iop->flags;
+ args.bytes_moved = 0;
+
+ status = rtems_io_read(
+ np->major,
+ np->minor,
+ (void *) &args
+ );
+
+ if ( status )
+ return rtems_deviceio_errno(status);
+
+ return (ssize_t) args.bytes_moved;
+}
+
diff --git a/cpukit/libfs/src/devfs/devstat.c b/cpukit/libfs/src/devfs/devstat.c
new file mode 100644
index 0000000000..db17595621
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devstat.c
@@ -0,0 +1,46 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/io.h>
+#include <rtems/seterr.h>
+#include <rtems/libio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "devfs.h"
+
+int devFS_stat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+)
+{
+ rtems_device_name_t *the_dev;
+
+ the_dev = (rtems_device_name_t *)loc->node_access;
+
+ /*
+ * stat() invokes devFS_evaluate_path() which checks that node_access
+ * is not NULL. So this should NEVER be NULL unless someone breaks
+ * other code in this filesystem.
+ */
+ #if defined(RTEMS_DEBUG)
+ if (!the_dev)
+ rtems_set_errno_and_return_minus_one( EFAULT );
+ #endif
+
+ buf->st_rdev = rtems_filesystem_make_dev_t( the_dev->major, the_dev->minor );
+ buf->st_mode = the_dev->mode;
+ return 0;
+}
+
+
diff --git a/cpukit/libfs/src/devfs/devwrite.c b/cpukit/libfs/src/devfs/devwrite.c
new file mode 100644
index 0000000000..5389c69bc5
--- /dev/null
+++ b/cpukit/libfs/src/devfs/devwrite.c
@@ -0,0 +1,48 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/io.h>
+
+#include "devfs.h"
+
+ssize_t devFS_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ rtems_libio_rw_args_t args;
+ rtems_status_code status;
+ rtems_device_name_t *np;
+
+ np = (rtems_device_name_t *)iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.offset = iop->offset;
+ args.buffer = (void *) buffer;
+ args.count = count;
+ args.flags = iop->flags;
+ args.bytes_moved = 0;
+
+ status = rtems_io_write(
+ np->major,
+ np->minor,
+ (void *) &args
+ );
+
+ if ( status )
+ return rtems_deviceio_errno(status);
+
+ return (ssize_t) args.bytes_moved;
+}
+
diff --git a/cpukit/libfs/src/dosfs/.cvsignore b/cpukit/libfs/src/dosfs/.cvsignore
new file mode 100644
index 0000000000..4b0640c9c5
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/.cvsignore
@@ -0,0 +1,4 @@
+config.h
+config.h.in
+stamp-h
+stamp-h.in
diff --git a/cpukit/libfs/src/dosfs/dosfs.h b/cpukit/libfs/src/dosfs/dosfs.h
new file mode 100644
index 0000000000..5b6cdec2bf
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/dosfs.h
@@ -0,0 +1,88 @@
+/**
+ * @file rtems/dosfs.h
+ *
+ * Application interface to MSDOS filesystem.
+ */
+
+/*
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#ifndef _RTEMS_DOSFS_H
+#define _RTEMS_DOSFS_H
+
+#include <rtems.h>
+#include <rtems/libio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int rtems_dosfs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data);
+
+#define MSDOS_FMT_FATANY 0
+#define MSDOS_FMT_FAT12 1
+#define MSDOS_FMT_FAT16 2
+#define MSDOS_FMT_FAT32 3
+
+#define MSDOS_FMT_INFO_LEVEL_NONE (0)
+#define MSDOS_FMT_INFO_LEVEL_INFO (1)
+#define MSDOS_FMT_INFO_LEVEL_DETAIL (2)
+#define MSDOS_FMT_INFO_LEVEL_DEBUG (3)
+
+/*
+ * data to be filled out for formatter: parameters for format call
+ * any parameter set to 0 or NULL will be automatically detected/computed
+ */
+typedef struct {
+ const char *OEMName; /* OEM Name string or NULL */
+ const char *VolLabel; /* Volume Label string or NULL */
+ uint32_t sectors_per_cluster; /* request value: sectors per cluster */
+ uint32_t fat_num; /* request value: number of FATs on disk */
+ uint32_t files_per_root_dir; /* request value: file entries in root */
+ uint8_t fattype; /* request value: MSDOS_FMT_FAT12/16/32 */
+ uint8_t media; /* media code. default: 0xF8 */
+ bool quick_format; /* true: do not clear out data sectors */
+ uint32_t cluster_align; /* requested value: cluster alignment */
+ /* make sector number of first sector */
+ /* of first cluster divisible by this */
+ /* value. This can optimize clusters */
+ /* to be located at start of track */
+ /* or start of flash block */
+ int info_level; /* The amount of info to output */
+} msdos_format_request_param_t;
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int msdos_format
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| format device with msdos filesystem |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const char *devname, /* device name */
+ const msdos_format_request_param_t *rqdata /* requested fmt parameters */
+ /* set to NULL for automatic */
+ /* determination */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libfs/src/dosfs/fat.c b/cpukit/libfs/src/dosfs/fat.c
new file mode 100644
index 0000000000..ba9ae23e86
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/fat.c
@@ -0,0 +1,863 @@
+/*
+ * fat.c
+ *
+ * Low-level operations on a volume with FAT filesystem
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+
+int
+fat_buf_access(fat_fs_info_t *fs_info, uint32_t blk, int op_type,
+ rtems_bdbuf_buffer **buf)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ uint8_t i;
+ bool sec_of_fat;
+
+
+ if (fs_info->c.state == FAT_CACHE_EMPTY)
+ {
+ if (op_type == FAT_OP_TYPE_READ)
+ sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf);
+ else
+ sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+ fs_info->c.blk_num = blk;
+ fs_info->c.modified = 0;
+ fs_info->c.state = FAT_CACHE_ACTUAL;
+ }
+
+ sec_of_fat = ((fs_info->c.blk_num >= fs_info->vol.fat_loc) &&
+ (fs_info->c.blk_num < fs_info->vol.rdir_loc));
+
+ if (fs_info->c.blk_num != blk)
+ {
+ if (fs_info->c.modified)
+ {
+ if (sec_of_fat && !fs_info->vol.mirror)
+ memcpy(fs_info->sec_buf, fs_info->c.buf->buffer,
+ fs_info->vol.bps);
+
+ sc = rtems_bdbuf_release_modified(fs_info->c.buf);
+ fs_info->c.state = FAT_CACHE_EMPTY;
+ fs_info->c.modified = 0;
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ if (sec_of_fat && !fs_info->vol.mirror)
+ {
+ rtems_bdbuf_buffer *b;
+
+ for (i = 1; i < fs_info->vol.fats; i++)
+ {
+ sc = rtems_bdbuf_get(fs_info->vol.dev,
+ fs_info->c.blk_num +
+ fs_info->vol.fat_length * i,
+ &b);
+ if ( sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ memcpy(b->buffer, fs_info->sec_buf, fs_info->vol.bps);
+ sc = rtems_bdbuf_release_modified(b);
+ if ( sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+ }
+ }
+ else
+ {
+ sc = rtems_bdbuf_release(fs_info->c.buf);
+ fs_info->c.state = FAT_CACHE_EMPTY;
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ }
+ if (op_type == FAT_OP_TYPE_READ)
+ sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf);
+ else
+ sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+ fs_info->c.blk_num = blk;
+ fs_info->c.state = FAT_CACHE_ACTUAL;
+ }
+ *buf = fs_info->c.buf;
+ return RC_OK;
+}
+
+int
+fat_buf_release(fat_fs_info_t *fs_info)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ uint8_t i;
+ bool sec_of_fat;
+
+ if (fs_info->c.state == FAT_CACHE_EMPTY)
+ return RC_OK;
+
+ sec_of_fat = ((fs_info->c.blk_num >= fs_info->vol.fat_loc) &&
+ (fs_info->c.blk_num < fs_info->vol.rdir_loc));
+
+ if (fs_info->c.modified)
+ {
+ if (sec_of_fat && !fs_info->vol.mirror)
+ memcpy(fs_info->sec_buf, fs_info->c.buf->buffer, fs_info->vol.bps);
+
+ sc = rtems_bdbuf_release_modified(fs_info->c.buf);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+ fs_info->c.modified = 0;
+
+ if (sec_of_fat && !fs_info->vol.mirror)
+ {
+ rtems_bdbuf_buffer *b;
+
+ for (i = 1; i < fs_info->vol.fats; i++)
+ {
+ sc = rtems_bdbuf_get(fs_info->vol.dev,
+ fs_info->c.blk_num +
+ fs_info->vol.fat_length * i,
+ &b);
+ if ( sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ memcpy(b->buffer, fs_info->sec_buf, fs_info->vol.bps);
+ sc = rtems_bdbuf_release_modified(b);
+ if ( sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+ }
+ }
+ else
+ {
+ sc = rtems_bdbuf_release(fs_info->c.buf);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+ }
+ fs_info->c.state = FAT_CACHE_EMPTY;
+ return RC_OK;
+}
+
+/* _fat_block_read --
+ * This function reads 'count' bytes from device filesystem is mounted on,
+ * starts at 'start+offset' position where 'start' computed in sectors
+ * and 'offset' is offset inside sector (reading may cross sectors
+ * boundary; in this case assumed we want to read sequential sector(s))
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * start - sector num to start read from
+ * offset - offset inside sector 'start'
+ * count - count of bytes to read
+ * buff - buffer provided by user
+ *
+ * RETURNS:
+ * bytes read on success, or -1 if error occured
+ * and errno set appropriately
+ */
+ssize_t
+_fat_block_read(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t count,
+ void *buff
+ )
+{
+ int rc = RC_OK;
+ register fat_fs_info_t *fs_info = mt_entry->fs_info;
+ ssize_t cmpltd = 0;
+ uint32_t blk = start;
+ uint32_t ofs = offset;
+ rtems_bdbuf_buffer *block = NULL;
+ uint32_t c = 0;
+
+ while (count > 0)
+ {
+ rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block);
+ if (rc != RC_OK)
+ return -1;
+
+ c = MIN(count, (fs_info->vol.bps - ofs));
+ memcpy((buff + cmpltd), (block->buffer + ofs), c);
+
+ count -= c;
+ cmpltd += c;
+ blk++;
+ ofs = 0;
+ }
+ return cmpltd;
+}
+
+/* _fat_block_write --
+ * This function write 'count' bytes to device filesystem is mounted on,
+ * starts at 'start+offset' position where 'start' computed in sectors
+ * and 'offset' is offset inside sector (writing may cross sectors
+ * boundary; in this case assumed we want to write sequential sector(s))
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * start - sector num to start read from
+ * offset - offset inside sector 'start'
+ * count - count of bytes to write
+ * buff - buffer provided by user
+ *
+ * RETURNS:
+ * bytes written on success, or -1 if error occured
+ * and errno set appropriately
+ */
+ssize_t
+_fat_block_write(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t count,
+ const void *buff)
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ ssize_t cmpltd = 0;
+ uint32_t blk = start;
+ uint32_t ofs = offset;
+ rtems_bdbuf_buffer *block = NULL;
+ uint32_t c = 0;
+
+ while(count > 0)
+ {
+ c = MIN(count, (fs_info->vol.bps - ofs));
+
+ if (c == fs_info->vol.bps)
+ rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block);
+ else
+ rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block);
+ if (rc != RC_OK)
+ return -1;
+
+ memcpy((block->buffer + ofs), (buff + cmpltd), c);
+
+ fat_buf_mark_modified(fs_info);
+
+ count -= c;
+ cmpltd +=c;
+ blk++;
+ ofs = 0;
+ }
+ return cmpltd;
+}
+
+/* _fat_block_release --
+ * This function works around the hack that hold a bdbuf and does
+ * not release it.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ *
+ * RETURNS:
+ * 0 on success, or -1 if error occured and errno set appropriately
+ */
+int
+_fat_block_release(
+ rtems_filesystem_mount_table_entry_t *mt_entry)
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ return fat_buf_release(fs_info);
+}
+
+/* fat_cluster_read --
+ * wrapper for reading a whole cluster at once
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * cln - number of cluster to read
+ * buff - buffer provided by user
+ *
+ * RETURNS:
+ * bytes read on success, or -1 if error occured
+ * and errno set appropriately
+ */
+ssize_t
+fat_cluster_read(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ void *buff
+ )
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t fsec = 0;
+
+ fsec = fat_cluster_num_to_sector_num(mt_entry, cln);
+
+ return _fat_block_read(mt_entry, fsec, 0,
+ fs_info->vol.spc << fs_info->vol.sec_log2, buff);
+}
+
+/* fat_cluster_write --
+ * wrapper for writting a whole cluster at once
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * cln - number of cluster to write
+ * buff - buffer provided by user
+ *
+ * RETURNS:
+ * bytes written on success, or -1 if error occured
+ * and errno set appropriately
+ */
+ssize_t
+fat_cluster_write(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ const void *buff
+ )
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t fsec = 0;
+
+ fsec = fat_cluster_num_to_sector_num(mt_entry, cln);
+
+ return _fat_block_write(mt_entry, fsec, 0,
+ fs_info->vol.spc << fs_info->vol.sec_log2, buff);
+}
+
+/* fat_init_volume_info --
+ * Get inforamtion about volume on which filesystem is mounted on
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ * and errno set appropriately
+ */
+int
+fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ register fat_vol_t *vol = &fs_info->vol;
+ uint32_t data_secs = 0;
+ char boot_rec[FAT_MAX_BPB_SIZE];
+ char fs_info_sector[FAT_USEFUL_INFO_SIZE];
+ ssize_t ret = 0;
+ struct stat stat_buf;
+ int i = 0;
+ rtems_bdbuf_buffer *block = NULL;
+
+ rc = stat(mt_entry->dev, &stat_buf);
+ if (rc == -1)
+ return rc;
+
+ /* Must be a block device. */
+ if (!S_ISBLK(stat_buf.st_mode))
+ rtems_set_errno_and_return_minus_one(ENOTTY);
+
+ /* check that device is registred as block device and lock it */
+ vol->dd = rtems_disk_obtain(stat_buf.st_rdev);
+ if (vol->dd == NULL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ vol->dev = stat_buf.st_rdev;
+
+ /* Read boot record */
+ /* FIXME: Asserts FAT_MAX_BPB_SIZE < bdbuf block size */
+ sc = rtems_bdbuf_read( vol->dev, 0, &block);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one( EIO);
+ }
+
+ memcpy( boot_rec, block->buffer, FAT_MAX_BPB_SIZE);
+
+ sc = rtems_bdbuf_release( block);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one( EIO );
+ }
+
+ /* Evaluate boot record */
+ vol->bps = FAT_GET_BR_BYTES_PER_SECTOR(boot_rec);
+
+ if ( (vol->bps != 512) &&
+ (vol->bps != 1024) &&
+ (vol->bps != 2048) &&
+ (vol->bps != 4096))
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ for (vol->sec_mul = 0, i = (vol->bps >> FAT_SECTOR512_BITS); (i & 1) == 0;
+ i >>= 1, vol->sec_mul++);
+ for (vol->sec_log2 = 0, i = vol->bps; (i & 1) == 0;
+ i >>= 1, vol->sec_log2++);
+
+ vol->spc = FAT_GET_BR_SECTORS_PER_CLUSTER(boot_rec);
+ /*
+ * "sectors per cluster" of zero is invalid
+ * (and would hang the following loop)
+ */
+ if (vol->spc == 0)
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one(EINVAL);
+ }
+
+ for (vol->spc_log2 = 0, i = vol->spc; (i & 1) == 0;
+ i >>= 1, vol->spc_log2++);
+
+ /*
+ * "bytes per cluster" value greater than 32K is invalid
+ */
+ if ((vol->bpc = vol->bps << vol->spc_log2) > MS_BYTES_PER_CLUSTER_LIMIT)
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one(EINVAL);
+ }
+
+ for (vol->bpc_log2 = 0, i = vol->bpc; (i & 1) == 0;
+ i >>= 1, vol->bpc_log2++);
+
+ vol->fats = FAT_GET_BR_FAT_NUM(boot_rec);
+ vol->fat_loc = FAT_GET_BR_RESERVED_SECTORS_NUM(boot_rec);
+
+ vol->rdir_entrs = FAT_GET_BR_FILES_PER_ROOT_DIR(boot_rec);
+
+ /* calculate the count of sectors occupied by the root directory */
+ vol->rdir_secs = ((vol->rdir_entrs * FAT_DIRENTRY_SIZE) + (vol->bps - 1)) /
+ vol->bps;
+
+ vol->rdir_size = vol->rdir_secs << vol->sec_log2;
+
+ if ( (FAT_GET_BR_SECTORS_PER_FAT(boot_rec)) != 0)
+ vol->fat_length = FAT_GET_BR_SECTORS_PER_FAT(boot_rec);
+ else
+ vol->fat_length = FAT_GET_BR_SECTORS_PER_FAT32(boot_rec);
+
+ vol->data_fsec = vol->fat_loc + vol->fats * vol->fat_length +
+ vol->rdir_secs;
+
+ /* for FAT12/16 root dir starts at(sector) */
+ vol->rdir_loc = vol->fat_loc + vol->fats * vol->fat_length;
+
+ if ( (FAT_GET_BR_TOTAL_SECTORS_NUM16(boot_rec)) != 0)
+ vol->tot_secs = FAT_GET_BR_TOTAL_SECTORS_NUM16(boot_rec);
+ else
+ vol->tot_secs = FAT_GET_BR_TOTAL_SECTORS_NUM32(boot_rec);
+
+ data_secs = vol->tot_secs - vol->data_fsec;
+
+ vol->data_cls = data_secs / vol->spc;
+
+ /* determine FAT type at least */
+ if ( vol->data_cls < FAT_FAT12_MAX_CLN)
+ {
+ vol->type = FAT_FAT12;
+ vol->mask = FAT_FAT12_MASK;
+ vol->eoc_val = FAT_FAT12_EOC;
+ }
+ else
+ {
+ if ( vol->data_cls < FAT_FAT16_MAX_CLN)
+ {
+ vol->type = FAT_FAT16;
+ vol->mask = FAT_FAT16_MASK;
+ vol->eoc_val = FAT_FAT16_EOC;
+ }
+ else
+ {
+ vol->type = FAT_FAT32;
+ vol->mask = FAT_FAT32_MASK;
+ vol->eoc_val = FAT_FAT32_EOC;
+ }
+ }
+
+ if (vol->type == FAT_FAT32)
+ {
+ vol->rdir_cl = FAT_GET_BR_FAT32_ROOT_CLUSTER(boot_rec);
+
+ vol->mirror = FAT_GET_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_MIRROR;
+ if (vol->mirror)
+ vol->afat = FAT_GET_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_FAT_NUM;
+ else
+ vol->afat = 0;
+
+ vol->info_sec = FAT_GET_BR_FAT32_FS_INFO_SECTOR(boot_rec);
+ if( vol->info_sec == 0 )
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+ else
+ {
+ ret = _fat_block_read(mt_entry, vol->info_sec , 0,
+ FAT_FSI_LEADSIG_SIZE, fs_info_sector);
+ if ( ret < 0 )
+ {
+ rtems_disk_release(vol->dd);
+ return -1;
+ }
+
+ if (FAT_GET_FSINFO_LEAD_SIGNATURE(fs_info_sector) !=
+ FAT_FSINFO_LEAD_SIGNATURE_VALUE)
+ {
+ _fat_block_release(mt_entry);
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+ else
+ {
+ ret = _fat_block_read(mt_entry, vol->info_sec , FAT_FSI_INFO,
+ FAT_USEFUL_INFO_SIZE, fs_info_sector);
+ if ( ret < 0 )
+ {
+ _fat_block_release(mt_entry);
+ rtems_disk_release(vol->dd);
+ return -1;
+ }
+
+ vol->free_cls = FAT_GET_FSINFO_FREE_CLUSTER_COUNT(fs_info_sector);
+ vol->next_cl = FAT_GET_FSINFO_NEXT_FREE_CLUSTER(fs_info_sector);
+ rc = fat_fat32_update_fsinfo_sector(mt_entry, 0xFFFFFFFF,
+ 0xFFFFFFFF);
+ if ( rc != RC_OK )
+ {
+ _fat_block_release(mt_entry);
+ rtems_disk_release(vol->dd);
+ return rc;
+ }
+ }
+ }
+ }
+ else
+ {
+ vol->rdir_cl = 0;
+ vol->mirror = 0;
+ vol->afat = 0;
+ vol->free_cls = 0xFFFFFFFF;
+ vol->next_cl = 0xFFFFFFFF;
+ }
+
+ _fat_block_release(mt_entry);
+
+ vol->afat_loc = vol->fat_loc + vol->fat_length * vol->afat;
+
+ /* set up collection of fat-files fd */
+ fs_info->vhash = calloc(FAT_HASH_SIZE, sizeof(rtems_chain_control));
+ if ( fs_info->vhash == NULL )
+ {
+ rtems_disk_release(vol->dd);
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ for (i = 0; i < FAT_HASH_SIZE; i++)
+ rtems_chain_initialize_empty(fs_info->vhash + i);
+
+ fs_info->rhash = calloc(FAT_HASH_SIZE, sizeof(rtems_chain_control));
+ if ( fs_info->rhash == NULL )
+ {
+ rtems_disk_release(vol->dd);
+ free(fs_info->vhash);
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+ for (i = 0; i < FAT_HASH_SIZE; i++)
+ rtems_chain_initialize_empty(fs_info->rhash + i);
+
+ fs_info->uino_pool_size = FAT_UINO_POOL_INIT_SIZE;
+ fs_info->uino_base = (vol->tot_secs << vol->sec_mul) << 4;
+ fs_info->index = 0;
+ fs_info->uino = (char *)calloc(fs_info->uino_pool_size, sizeof(char));
+ if ( fs_info->uino == NULL )
+ {
+ rtems_disk_release(vol->dd);
+ free(fs_info->vhash);
+ free(fs_info->rhash);
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+ fs_info->sec_buf = (uint8_t *)calloc(vol->bps, sizeof(uint8_t));
+ if (fs_info->sec_buf == NULL)
+ {
+ rtems_disk_release(vol->dd);
+ free(fs_info->vhash);
+ free(fs_info->rhash);
+ free(fs_info->uino);
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ return RC_OK;
+}
+
+/* fat_shutdown_drive --
+ * Free all allocated resources and synchronize all necessary data
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ * and errno set appropriately
+ */
+int
+fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ int i = 0;
+
+ if (fs_info->vol.type & FAT_FAT32)
+ {
+ rc = fat_fat32_update_fsinfo_sector(mt_entry, fs_info->vol.free_cls,
+ fs_info->vol.next_cl);
+ if ( rc != RC_OK )
+ rc = -1;
+ }
+
+ fat_buf_release(fs_info);
+
+ if (rtems_bdbuf_syncdev(fs_info->vol.dev) != RTEMS_SUCCESSFUL)
+ rc = -1;
+
+ for (i = 0; i < FAT_HASH_SIZE; i++)
+ {
+ rtems_chain_node *node = NULL;
+ rtems_chain_control *the_chain = fs_info->vhash + i;
+
+ while ( (node = rtems_chain_get(the_chain)) != NULL )
+ free(node);
+ }
+
+ for (i = 0; i < FAT_HASH_SIZE; i++)
+ {
+ rtems_chain_node *node = NULL;
+ rtems_chain_control *the_chain = fs_info->rhash + i;
+
+ while ( (node = rtems_chain_get(the_chain)) != NULL )
+ free(node);
+ }
+
+ free(fs_info->vhash);
+ free(fs_info->rhash);
+
+ free(fs_info->uino);
+ free(fs_info->sec_buf);
+ rtems_disk_release(fs_info->vol.dd);
+
+ if (rc)
+ errno = EIO;
+ return rc;
+}
+
+/* fat_init_clusters_chain --
+ * Zeroing contents of all clusters in the chain
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * start_cluster_num - num of first cluster in the chain
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ * and errno set appropriately
+ */
+int
+fat_init_clusters_chain(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t start_cln
+ )
+{
+ int rc = RC_OK;
+ ssize_t ret = 0;
+ register fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cur_cln = start_cln;
+ char *buf;
+
+ buf = calloc(fs_info->vol.bpc, sizeof(char));
+ if ( buf == NULL )
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
+ {
+ ret = fat_cluster_write(mt_entry, cur_cln, buf);
+ if ( ret == -1 )
+ {
+ free(buf);
+ return -1;
+ }
+
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
+ if ( rc != RC_OK )
+ {
+ free(buf);
+ return rc;
+ }
+
+ }
+ free(buf);
+ return rc;
+}
+
+#define FAT_UNIQ_INO_BASE 0x0FFFFF00
+
+#define FAT_UNIQ_INO_IS_BUSY(index, arr) \
+ (((arr)[((index)>>3)]>>((index) & (8-1))) & 0x01)
+
+#define FAT_SET_UNIQ_INO_BUSY(index, arr) \
+ ((arr)[((index)>>3)] |= (0x01<<((index) & (8-1))))
+
+#define FAT_SET_UNIQ_INO_FREE(index, arr) \
+ ((arr)[((index)>>3)] &= (~(0x01<<((index) & (8-1)))))
+
+/* fat_get_unique_ino --
+ * Allocate unique ino from unique ino pool
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ *
+ * RETURNS:
+ * unique inode number on success, or 0 if there is no free unique inode
+ * number in the pool
+ *
+ * ATTENTION:
+ * 0 means FAILED !!!
+ *
+ */
+uint32_t
+fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry)
+{
+ register fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t j = 0;
+ bool resrc_unsuff = false;
+
+ while (!resrc_unsuff)
+ {
+ for (j = 0; j < fs_info->uino_pool_size; j++)
+ {
+ if (!FAT_UNIQ_INO_IS_BUSY(fs_info->index, fs_info->uino))
+ {
+ FAT_SET_UNIQ_INO_BUSY(fs_info->index, fs_info->uino);
+ return (fs_info->uino_base + fs_info->index);
+ }
+ fs_info->index++;
+ if (fs_info->index >= fs_info->uino_pool_size)
+ fs_info->index = 0;
+ }
+
+ if ((fs_info->uino_pool_size << 1) < (0x0FFFFFFF - fs_info->uino_base))
+ {
+ fs_info->uino_pool_size <<= 1;
+ fs_info->uino = realloc(fs_info->uino, fs_info->uino_pool_size);
+ if (fs_info->uino != NULL)
+ fs_info->index = fs_info->uino_pool_size;
+ else
+ resrc_unsuff = true;
+ }
+ else
+ resrc_unsuff = true;
+ }
+ return 0;
+}
+
+/* fat_free_unique_ino --
+ * Return unique ino to unique ino pool
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * ino - inode number to free
+ *
+ * RETURNS:
+ * None
+ */
+void
+fat_free_unique_ino(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t ino
+ )
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+
+ FAT_SET_UNIQ_INO_FREE((ino - fs_info->uino_base), fs_info->uino);
+}
+
+/* fat_ino_is_unique --
+ * Test whether ino is from unique ino pool
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * ino - ino to be tested
+ *
+ * RETURNS:
+ * true if ino is allocated from unique ino pool, false otherwise
+ */
+inline bool
+fat_ino_is_unique(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t ino
+ )
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+
+ return (ino >= fs_info->uino_base);
+}
+
+/* fat_fat32_update_fsinfo_sector --
+ * Synchronize fsinfo sector for FAT32 volumes
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * free_count - count of free clusters
+ * next_free - the next free cluster num
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+fat_fat32_update_fsinfo_sector(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t free_count,
+ uint32_t next_free
+ )
+{
+ ssize_t ret1 = 0, ret2 = 0;
+ register fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t le_free_count = 0;
+ uint32_t le_next_free = 0;
+
+ le_free_count = CT_LE_L(free_count);
+ le_next_free = CT_LE_L(next_free);
+
+ ret1 = _fat_block_write(mt_entry,
+ fs_info->vol.info_sec,
+ FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET,
+ 4,
+ (char *)(&le_free_count));
+
+ ret2 = _fat_block_write(mt_entry,
+ fs_info->vol.info_sec,
+ FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET,
+ 4,
+ (char *)(&le_next_free));
+
+ if ( (ret1 < 0) || (ret2 < 0) )
+ return -1;
+
+ return RC_OK;
+}
diff --git a/cpukit/libfs/src/dosfs/fat.h b/cpukit/libfs/src/dosfs/fat.h
new file mode 100644
index 0000000000..8d62662c10
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/fat.h
@@ -0,0 +1,517 @@
+/*
+ * fat.h
+ *
+ * Constants/data structures/prototypes for low-level operations on a volume
+ * with FAT filesystem
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#ifndef __DOSFS_FAT_H__
+#define __DOSFS_FAT_H__
+
+#include <string.h>
+
+#include <rtems/seterr.h>
+
+#include <rtems/score/cpu.h>
+#include <errno.h>
+#include <rtems/bdbuf.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef RC_OK
+#define RC_OK 0
+#endif
+
+/*
+ * Remember that all FAT file system on disk data structure is
+ * "little endian"!
+ * (derived from linux)
+ */
+/*
+ * Conversion from and to little-endian byte order. (no-op on i386/i486)
+ *
+ * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
+ * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
+ */
+
+#if (CPU_BIG_ENDIAN == TRUE)
+# define CF_LE_W(v) CPU_swap_u16((uint16_t)(v))
+# define CF_LE_L(v) CPU_swap_u32((uint32_t)(v))
+# define CT_LE_W(v) CPU_swap_u16((uint16_t)(v))
+# define CT_LE_L(v) CPU_swap_u32((uint32_t)(v))
+#else
+# define CF_LE_W(v) (v)
+# define CF_LE_L(v) (v)
+# define CT_LE_W(v) (v)
+# define CT_LE_L(v) (v)
+#endif
+
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+
+#define FAT_HASH_SIZE 2
+#define FAT_HASH_MODULE FAT_HASH_SIZE
+
+
+#define FAT_SECTOR512_SIZE 512 /* sector size (bytes) */
+#define FAT_SECTOR512_BITS 9 /* log2(SECTOR_SIZE) */
+
+/* maximum + 1 number of clusters for FAT12 */
+#define FAT_FAT12_MAX_CLN 4085
+
+/* maximum + 1 number of clusters for FAT16 */
+#define FAT_FAT16_MAX_CLN 65525
+
+#define FAT_FAT12 0x01
+#define FAT_FAT16 0x02
+#define FAT_FAT32 0x04
+
+#define FAT_UNDEFINED_VALUE (uint32_t)0xFFFFFFFF
+
+#define FAT_FAT12_EOC 0x0FF8
+#define FAT_FAT16_EOC 0xFFF8
+#define FAT_FAT32_EOC (uint32_t)0x0FFFFFF8
+
+#define FAT_FAT12_FREE 0x0000
+#define FAT_FAT16_FREE 0x0000
+#define FAT_FAT32_FREE 0x00000000
+
+#define FAT_GENFAT_EOC (uint32_t)0xFFFFFFFF
+#define FAT_GENFAT_FREE (uint32_t)0x00000000
+
+#define FAT_FAT12_SHIFT 0x04
+
+#define FAT_FAT12_MASK 0x00000FFF
+#define FAT_FAT16_MASK 0x0000FFFF
+#define FAT_FAT32_MASK (uint32_t)0x0FFFFFFF
+
+#define FAT_MAX_BPB_SIZE 90
+#define FAT_TOTAL_MBR_SIZE 512
+
+/* size of useful information in FSInfo sector */
+#define FAT_USEFUL_INFO_SIZE 12
+
+#define FAT_GET_ADDR(x, ofs) ((uint8_t *)(x) + (ofs))
+
+#define FAT_GET_VAL8(x, ofs) (uint8_t)(*((uint8_t *)(x) + (ofs)))
+
+#define FAT_GET_VAL16(x, ofs) \
+ (uint16_t)( (*((uint8_t *)(x) + (ofs))) | \
+ ((*((uint8_t *)(x) + (ofs) + 1)) << 8) )
+
+#define FAT_GET_VAL32(x, ofs) \
+ (uint32_t)( (uint32_t)(*((uint8_t *)(x) + (ofs))) | \
+ ((uint32_t)(*((uint8_t *)(x) + (ofs) + 1)) << 8) | \
+ ((uint32_t)(*((uint8_t *)(x) + (ofs) + 2)) << 16) | \
+ ((uint32_t)(*((uint8_t *)(x) + (ofs) + 3)) << 24) )
+
+#define FAT_SET_VAL8(x, ofs,val) \
+ (*((uint8_t *)(x)+(ofs))=(uint8_t)(val))
+
+#define FAT_SET_VAL16(x, ofs,val) do { \
+ FAT_SET_VAL8((x),(ofs),(val)); \
+ FAT_SET_VAL8((x),(ofs)+1,(val)>>8);\
+ } while (0)
+
+#define FAT_SET_VAL32(x, ofs,val) do { \
+ uint32_t val1 = val; \
+ FAT_SET_VAL16((x),(ofs),(val1)&0xffff);\
+ FAT_SET_VAL16((x),(ofs)+2,(val1)>>16);\
+ } while (0)
+
+/* macros to access boot sector fields */
+#define FAT_GET_BR_JMPBOOT(x) FAT_GET_VAL8( x, 0)
+#define FAT_SET_BR_JMPBOOT(x,val) FAT_SET_VAL8( x, 0,val)
+
+#define FAT_GET_ADDR_BR_OEMNAME(x) FAT_GET_ADDR( x, 3)
+#define FAT_BR_OEMNAME_SIZE (8)
+
+#define FAT_GET_BR_BYTES_PER_SECTOR(x) FAT_GET_VAL16(x, 11)
+#define FAT_SET_BR_BYTES_PER_SECTOR(x,val) FAT_SET_VAL16(x, 11,val)
+
+#define FAT_GET_BR_SECTORS_PER_CLUSTER(x) FAT_GET_VAL8( x, 13)
+#define FAT_SET_BR_SECTORS_PER_CLUSTER(x,val)FAT_SET_VAL8( x, 13,val)
+
+#define FAT_GET_BR_RESERVED_SECTORS_NUM(x) FAT_GET_VAL16(x, 14)
+#define FAT_SET_BR_RESERVED_SECTORS_NUM(x,val) FAT_SET_VAL16(x, 14,val)
+
+#define FAT_GET_BR_FAT_NUM(x) FAT_GET_VAL8( x, 16)
+#define FAT_SET_BR_FAT_NUM(x,val) FAT_SET_VAL8( x, 16,val)
+
+#define FAT_GET_BR_FILES_PER_ROOT_DIR(x) FAT_GET_VAL16(x, 17)
+#define FAT_SET_BR_FILES_PER_ROOT_DIR(x,val) FAT_SET_VAL16(x, 17,val)
+
+#define FAT_GET_BR_TOTAL_SECTORS_NUM16(x) FAT_GET_VAL16(x, 19)
+#define FAT_SET_BR_TOTAL_SECTORS_NUM16(x,val)FAT_SET_VAL16(x, 19,val)
+
+#define FAT_GET_BR_MEDIA(x) FAT_GET_VAL8( x, 21)
+#define FAT_SET_BR_MEDIA(x,val) FAT_SET_VAL8( x, 21,val)
+
+#define FAT_GET_BR_SECTORS_PER_FAT(x) FAT_GET_VAL16(x, 22)
+#define FAT_SET_BR_SECTORS_PER_FAT(x,val) FAT_SET_VAL16(x, 22,val)
+
+#define FAT_GET_BR_SECTORS_PER_TRACK(x) FAT_GET_VAL16(x, 24)
+#define FAT_SET_BR_SECTORS_PER_TRACK(x,val) FAT_SET_VAL16(x, 24,val)
+
+#define FAT_GET_BR_NUMBER_OF_HEADS(x) FAT_GET_VAL16(x, 26)
+#define FAT_SET_BR_NUMBER_OF_HEADS(x,val) FAT_SET_VAL16(x, 26,val)
+
+#define FAT_GET_BR_HIDDEN_SECTORS(x) FAT_GET_VAL32(x, 28)
+#define FAT_SET_BR_HIDDEN_SECTORS(x,val) FAT_SET_VAL32(x, 28,val)
+
+#define FAT_GET_BR_TOTAL_SECTORS_NUM32(x) FAT_GET_VAL32(x, 32)
+#define FAT_SET_BR_TOTAL_SECTORS_NUM32(x,val) FAT_SET_VAL32(x, 32,val)
+ /* --- start of FAT12/16 specific fields */
+#define FAT_GET_BR_DRVNUM(x) FAT_GET_VAL8( x, 36)
+#define FAT_SET_BR_DRVNUM(x,val) FAT_SET_VAL8( x, 36,val)
+
+#define FAT_GET_BR_RSVD1(x) FAT_GET_VAL8( x, 37)
+#define FAT_SET_BR_RSVD1(x,val) FAT_SET_VAL8( x, 37,val)
+
+#define FAT_GET_BR_BOOTSIG(x) FAT_GET_VAL8( x, 38)
+#define FAT_SET_BR_BOOTSIG(x,val) FAT_SET_VAL8( x, 38,val)
+#define FAT_BR_BOOTSIG_VAL (0x29)
+
+#define FAT_GET_BR_VOLID(x) FAT_GET_VAL32(x, 39)
+#define FAT_SET_BR_VOLID(x,val) FAT_SET_VAL32(x, 39,val)
+
+#define FAT_GET_ADDR_BR_VOLLAB(x) FAT_GET_ADDR (x, 43)
+#define FAT_BR_VOLLAB_SIZE (11)
+
+#define FAT_GET_ADDR_BR_FILSYSTYPE(x) FAT_GET_ADDR (x, 54)
+#define FAT_BR_FILSYSTYPE_SIZE (8)
+ /* --- end of FAT12/16 specific fields */
+ /* --- start of FAT32 specific fields */
+#define FAT_GET_BR_SECTORS_PER_FAT32(x) FAT_GET_VAL32(x, 36)
+#define FAT_SET_BR_SECTORS_PER_FAT32(x,val) FAT_SET_VAL32(x, 36,val)
+
+#define FAT_GET_BR_EXT_FLAGS(x) FAT_GET_VAL16(x, 40)
+#define FAT_SET_BR_EXT_FLAGS(x,val) FAT_SET_VAL16(x, 40,val)
+
+#define FAT_GET_BR_FSVER(x) FAT_GET_VAL16(x, 42)
+#define FAT_SET_BR_FSVER(x,val) FAT_SET_VAL16(x, 42,val)
+
+#define FAT_GET_BR_FAT32_ROOT_CLUSTER(x) FAT_GET_VAL32(x, 44)
+#define FAT_SET_BR_FAT32_ROOT_CLUSTER(x,val) FAT_SET_VAL32(x, 44,val)
+
+#define FAT_GET_BR_FAT32_FS_INFO_SECTOR(x) FAT_GET_VAL16(x, 48)
+#define FAT_SET_BR_FAT32_FS_INFO_SECTOR(x,val) FAT_SET_VAL16(x, 48,val)
+
+#define FAT_GET_BR_FAT32_BK_BOOT_SECTOR(x) FAT_GET_VAL16(x, 50)
+#define FAT_SET_BR_FAT32_BK_BOOT_SECTOR(x,val) FAT_SET_VAL16(x, 50,val)
+
+#define FAT_GET_ADDR_BR_FAT32_RESERVED(x) FAT_GET_ADDR (x, 52)
+#define FAT_BR_FAT32_RESERVED_SIZE (12)
+
+#define FAT_GET_BR_FAT32_DRVNUM(x) FAT_GET_VAL8( x, 64)
+#define FAT_SET_BR_FAT32_DRVNUM(x,val) FAT_SET_VAL8( x, 64,val)
+
+#define FAT_GET_BR_FAT32_RSVD1(x) FAT_GET_VAL8( x, 65)
+#define FAT_SET_BR_FAT32_RSVD1(x,val) FAT_SET_VAL8( x, 65,val)
+
+#define FAT_GET_BR_FAT32_BOOTSIG(x) FAT_GET_VAL8( x, 66)
+#define FAT_SET_BR_FAT32_BOOTSIG(x,val) FAT_SET_VAL8( x, 66,val)
+#define FAT_BR_FAT32_BOOTSIG_VAL (0x29)
+
+#define FAT_GET_BR_FAT32_VOLID(x) FAT_GET_VAL32(x, 67)
+#define FAT_SET_BR_FAT32_VOLID(x,val) FAT_SET_VAL32(x, 67,val)
+
+#define FAT_GET_ADDR_BR_FAT32_VOLLAB(x) FAT_GET_ADDR (x, 71)
+#define FAT_BR_FAT32_VOLLAB_SIZE (11)
+
+#define FAT_GET_ADDR_BR_FAT32_FILSYSTYPE(x) FAT_GET_ADDR (x, 82)
+#define FAT_BR_FAT32_FILSYSTYPE_SIZE (8)
+ /* --- end of FAT32 specific fields */
+
+#define FAT_GET_BR_SIGNATURE(x) FAT_GET_VAL16(x,510)
+#define FAT_SET_BR_SIGNATURE(x,val) FAT_SET_VAL16(x,510,val)
+#define FAT_BR_SIGNATURE_VAL (0xAA55)
+
+ /*
+ * FAT32 FSINFO description
+ */
+#define FAT_GET_FSINFO_LEAD_SIGNATURE(x) FAT_GET_VAL32(x, 0)
+#define FAT_SET_FSINFO_LEAD_SIGNATURE(x,val) FAT_SET_VAL32(x, 0,val)
+#define FAT_FSINFO_LEAD_SIGNATURE_VALUE (0x41615252)
+
+#define FAT_GET_FSINFO_STRUC_SIGNATURE(x) FAT_GET_VAL32(x,484)
+#define FAT_SET_FSINFO_STRUC_SIGNATURE(x,val) FAT_SET_VAL32(x,484,val)
+#define FAT_FSINFO_STRUC_SIGNATURE_VALUE (0x61417272)
+
+#define FAT_GET_FSINFO_TRAIL_SIGNATURE(x) FAT_GET_VAL32(x,508)
+#define FAT_SET_FSINFO_TRAIL_SIGNATURE(x,val) FAT_SET_VAL32(x,508,val)
+#define FAT_FSINFO_TRAIL_SIGNATURE_VALUE (0xAA550000)
+/*
+ * I read FSInfo sector from offset 484 to access the information, so offsets
+ * of these fields a relative
+ */
+#define FAT_GET_FSINFO_FREE_CLUSTER_COUNT(x) FAT_GET_VAL32(x, 4)
+#define FAT_SET_FSINFO_FREE_CLUSTER_COUNT(x,val) FAT_SET_VAL32(x, 4,val)
+#define FAT_GET_FSINFO_NEXT_FREE_CLUSTER(x) FAT_GET_VAL32(x, 8)
+#define FAT_SET_FSINFO_NEXT_FREE_CLUSTER(x,val) FAT_SET_VAL32(x, 8,val)
+
+#define FAT_FSI_INFO 484
+#define FAT_FSINFO_STRUCT_OFFSET 488
+#define FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET (FAT_FSINFO_STRUCT_OFFSET+0)
+
+#define FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET (FAT_FSINFO_STRUCT_OFFSET+4)
+
+#define FAT_RSRVD_CLN 0x02
+
+#define FAT_FSI_LEADSIG_SIZE 0x04
+
+#define FAT_TOTAL_FSINFO_SIZE 512
+
+#define MS_BYTES_PER_CLUSTER_LIMIT 0x8000 /* 32K */
+
+#define FAT_BR_EXT_FLAGS_MIRROR 0x0080
+
+#define FAT_BR_EXT_FLAGS_FAT_NUM 0x000F
+
+#define FAT_BR_MEDIA_FIXED 0xf8
+
+#define FAT_DIRENTRY_SIZE 32
+
+#define FAT_DIRENTRIES_PER_SEC512 16
+
+/*
+ * Volume descriptor
+ * Description of the volume the FAT filesystem is located on - generally
+ * the fields of the structure correspond to Boot Sector and BPB Structure
+ * fields
+ */
+typedef struct fat_vol_s
+{
+ uint16_t bps; /* bytes per sector */
+ uint8_t sec_log2; /* log2 of bps */
+ uint8_t sec_mul; /* log2 of 512bts sectors number per sector */
+ uint8_t spc; /* sectors per cluster */
+ uint8_t spc_log2; /* log2 of spc */
+ uint16_t bpc; /* bytes per cluster */
+ uint8_t bpc_log2; /* log2 of bytes per cluster */
+ uint8_t fats; /* number of FATs */
+ uint8_t type; /* FAT type */
+ uint32_t mask;
+ uint32_t eoc_val;
+ uint16_t fat_loc; /* FAT start */
+ uint32_t fat_length; /* sectors per FAT */
+ uint32_t rdir_loc; /* root directory start */
+ uint16_t rdir_entrs; /* files per root directory */
+ uint32_t rdir_secs; /* sectors per root directory */
+ uint32_t rdir_size; /* root directory size in bytes */
+ uint32_t tot_secs; /* total count of sectors */
+ uint32_t data_fsec; /* first data sector */
+ uint32_t data_cls; /* count of data clusters */
+ uint32_t rdir_cl; /* first cluster of the root directory */
+ uint16_t info_sec; /* FSInfo Sector Structure location */
+ uint32_t free_cls; /* last known free clusters count */
+ uint32_t next_cl; /* next free cluster number */
+ uint8_t mirror; /* mirroring enabla/disable */
+ uint32_t afat_loc; /* active FAT location */
+ uint8_t afat; /* the number of active FAT */
+ dev_t dev; /* device ID */
+ rtems_disk_device *dd; /* disk device (see libblock) */
+ void *private_data; /* reserved */
+} fat_vol_t;
+
+
+typedef struct fat_cache_s
+{
+ uint32_t blk_num;
+ bool modified;
+ uint8_t state;
+ rtems_bdbuf_buffer *buf;
+} fat_cache_t;
+
+/*
+ * This structure identifies the instance of the filesystem on the FAT
+ * ("fat-file") level.
+ */
+typedef struct fat_fs_info_s
+{
+ fat_vol_t vol; /* volume descriptor */
+ rtems_chain_control *vhash; /* "vhash" of fat-file descriptors */
+ rtems_chain_control *rhash; /* "rhash" of fat-file descriptors */
+ char *uino; /* array of unique ino numbers */
+ uint32_t index;
+ uint32_t uino_pool_size; /* size */
+ uint32_t uino_base;
+ fat_cache_t c; /* cache */
+ uint8_t *sec_buf; /* just placeholder for anything */
+} fat_fs_info_t;
+
+/*
+ * FAT position is a the cluster and the offset into the
+ * cluster.
+ */
+typedef struct fat_pos_s
+{
+ uint32_t cln;
+ uint32_t ofs;
+} fat_pos_t;
+
+/*
+ * If the name we looking for is file we store not only first data cluster
+ * number, but and cluster number and offset for directory entry for this
+ * name. We also add the LFN start offset so we can delete it the whole
+ * file name. We can then use this to delete the file.
+ */
+typedef struct fat_dir_pos_s
+{
+ fat_pos_t sname;
+ fat_pos_t lname;
+} fat_dir_pos_t;
+
+/*
+ * Set the long name entries to this value for a short file name.
+ */
+#define FAT_FILE_SHORT_NAME (0xffffffff)
+
+#define FAT_FAT_OFFSET(fat_type, cln) \
+ ((fat_type) & FAT_FAT12 ? ((cln) + ((cln) >> 1)) : \
+ (fat_type) & FAT_FAT16 ? ((cln) << 1) : \
+ ((cln) << 2))
+
+#define FAT_CLUSTER_IS_ODD(n) ((n) & 0x0001)
+
+#define FAT12_SHIFT 0x4 /* half of a byte */
+
+/* initial size of array of unique ino */
+#define FAT_UINO_POOL_INIT_SIZE 0x100
+
+/* cache support */
+#define FAT_CACHE_EMPTY 0x0
+#define FAT_CACHE_ACTUAL 0x1
+
+#define FAT_OP_TYPE_READ 0x1
+#define FAT_OP_TYPE_GET 0x2
+
+static inline void
+fat_dir_pos_init(
+ fat_dir_pos_t *dir_pos
+ )
+{
+ dir_pos->sname.cln = 0;
+ dir_pos->sname.ofs = 0;
+ dir_pos->lname.cln = FAT_FILE_SHORT_NAME;
+ dir_pos->lname.ofs = FAT_FILE_SHORT_NAME;
+}
+
+static inline uint32_t
+fat_cluster_num_to_sector_num(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln
+ )
+{
+ register fat_fs_info_t *fs_info = mt_entry->fs_info;
+
+ if ( (cln == 0) && (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)) )
+ return fs_info->vol.rdir_loc;
+
+ return (((cln - FAT_RSRVD_CLN) << fs_info->vol.spc_log2) +
+ fs_info->vol.data_fsec);
+}
+
+static inline uint32_t
+fat_cluster_num_to_sector512_num(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln
+ )
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+
+ if (cln == 1)
+ return 1;
+
+ return (fat_cluster_num_to_sector_num(mt_entry, cln) <<
+ fs_info->vol.sec_mul);
+}
+
+static inline void
+fat_buf_mark_modified(fat_fs_info_t *fs_info)
+{
+ fs_info->c.modified = true;
+}
+
+int
+fat_buf_access(fat_fs_info_t *fs_info, uint32_t blk, int op_type,
+ rtems_bdbuf_buffer **buf);
+
+int
+fat_buf_release(fat_fs_info_t *fs_info);
+
+ssize_t
+_fat_block_read(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t count,
+ void *buff);
+
+ssize_t
+_fat_block_write(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t count,
+ const void *buff);
+
+int
+_fat_block_release(rtems_filesystem_mount_table_entry_t *mt_entry);
+
+ssize_t
+fat_cluster_read(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ void *buff);
+
+ssize_t
+fat_cluster_write(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ const void *buff);
+
+int
+fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry);
+
+int
+fat_init_clusters_chain(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t start_cln);
+
+uint32_t
+fat_cluster_num_to_sector_num(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln);
+
+int
+fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry);
+
+
+uint32_t
+fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry);
+
+bool
+fat_ino_is_unique(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t ino);
+
+void
+fat_free_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t ino);
+
+int
+fat_fat32_update_fsinfo_sector(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t free_count,
+ uint32_t next_free
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DOSFS_FAT_H__ */
diff --git a/cpukit/libfs/src/dosfs/fat_fat_operations.c b/cpukit/libfs/src/dosfs/fat_fat_operations.c
new file mode 100644
index 0000000000..c4f82805e8
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/fat_fat_operations.c
@@ -0,0 +1,436 @@
+/*
+ * fat_fat_operations.c
+ *
+ * General operations on File Allocation Table
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+
+/* fat_scan_fat_for_free_clusters --
+ * Allocate chain of free clusters from Files Allocation Table
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * chain - the number of the first allocated cluster (first cluster
+ * in the chain)
+ * count - count of clusters to allocate (chain length)
+ *
+ * RETURNS:
+ * RC_OK on success, or error code if error occured (errno set
+ * appropriately)
+ *
+ *
+ */
+int
+fat_scan_fat_for_free_clusters(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t *chain,
+ uint32_t count,
+ uint32_t *cls_added,
+ uint32_t *last_cl
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cl4find = 2;
+ uint32_t next_cln = 0;
+ uint32_t save_cln = 0;
+ uint32_t data_cls_val = fs_info->vol.data_cls + 2;
+ uint32_t i = 2;
+
+ *cls_added = 0;
+
+ if (count == 0)
+ return rc;
+
+ if (fs_info->vol.next_cl != FAT_UNDEFINED_VALUE)
+ cl4find = fs_info->vol.next_cl;
+
+ /*
+ * fs_info->vol.data_cls is exactly the count of data clusters
+ * starting at cluster 2, so the maximum valid cluster number is
+ * (fs_info->vol.data_cls + 1)
+ */
+ while (i < data_cls_val)
+ {
+ rc = fat_get_fat_cluster(mt_entry, cl4find, &next_cln);
+ if ( rc != RC_OK )
+ {
+ if (*cls_added != 0)
+ fat_free_fat_clusters_chain(mt_entry, (*chain));
+ return rc;
+ }
+
+ if (next_cln == FAT_GENFAT_FREE)
+ {
+ /*
+ * We are enforced to process allocation of the first free cluster
+ * by separate 'if' statement because otherwise undo function
+ * wouldn't work properly
+ */
+ if (*cls_added == 0)
+ {
+ *chain = cl4find;
+ rc = fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_EOC);
+ if ( rc != RC_OK )
+ {
+ /*
+ * this is the first cluster we tried to allocate so no
+ * cleanup activity needed
+ */
+ return rc;
+ }
+ }
+ else
+ {
+ /* set EOC value to new allocated cluster */
+ rc = fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_EOC);
+ if ( rc != RC_OK )
+ {
+ /* cleanup activity */
+ fat_free_fat_clusters_chain(mt_entry, (*chain));
+ return rc;
+ }
+
+ rc = fat_set_fat_cluster(mt_entry, save_cln, cl4find);
+ if ( rc != RC_OK )
+ {
+ /* cleanup activity */
+ fat_free_fat_clusters_chain(mt_entry, (*chain));
+ /* trying to save last allocated cluster for future use */
+ fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_FREE);
+ fat_buf_release(fs_info);
+ return rc;
+ }
+ }
+
+ save_cln = cl4find;
+ (*cls_added)++;
+
+ /* have we satisfied request ? */
+ if (*cls_added == count)
+ {
+ fs_info->vol.next_cl = save_cln;
+ if (fs_info->vol.free_cls != 0xFFFFFFFF)
+ fs_info->vol.free_cls -= (*cls_added);
+ *last_cl = save_cln;
+ fat_buf_release(fs_info);
+ return rc;
+ }
+ }
+ i++;
+ cl4find++;
+ if (cl4find >= data_cls_val)
+ cl4find = 2;
+ }
+
+ fs_info->vol.next_cl = save_cln;
+ if (fs_info->vol.free_cls != 0xFFFFFFFF)
+ fs_info->vol.free_cls -= (*cls_added);
+
+ *last_cl = save_cln;
+ fat_buf_release(fs_info);
+ return RC_OK;
+}
+
+/* fat_free_fat_clusters_chain --
+ * Free chain of clusters in Files Allocation Table.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * chain - number of the first cluster in the chain
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+fat_free_fat_clusters_chain(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t chain
+ )
+{
+ int rc = RC_OK, rc1 = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cur_cln = chain;
+ uint32_t next_cln = 0;
+ uint32_t freed_cls_cnt = 0;
+
+ while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
+ {
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &next_cln);
+ if ( rc != RC_OK )
+ {
+ if(fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)
+ fs_info->vol.free_cls += freed_cls_cnt;
+
+ fat_buf_release(fs_info);
+ return rc;
+ }
+
+ rc = fat_set_fat_cluster(mt_entry, cur_cln, FAT_GENFAT_FREE);
+ if ( rc != RC_OK )
+ rc1 = rc;
+
+ freed_cls_cnt++;
+ cur_cln = next_cln;
+ }
+
+ fs_info->vol.next_cl = chain;
+ if (fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)
+ fs_info->vol.free_cls += freed_cls_cnt;
+
+ fat_buf_release(fs_info);
+ if (rc1 != RC_OK)
+ return rc1;
+
+ return RC_OK;
+}
+
+/* fat_get_fat_cluster --
+ * Fetches the contents of the cluster (link to next cluster in the chain)
+ * from Files Allocation Table.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * cln - number of cluster to fetch the contents from
+ * ret_val - contents of the cluster 'cln' (link to next cluster in
+ * the chain)
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ * and errno set appropriately
+ */
+int
+fat_get_fat_cluster(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ uint32_t *ret_val
+ )
+{
+ int rc = RC_OK;
+ register fat_fs_info_t *fs_info = mt_entry->fs_info;
+ rtems_bdbuf_buffer *block0 = NULL;
+ uint32_t sec = 0;
+ uint32_t ofs = 0;
+
+ /* sanity check */
+ if ( (cln < 2) || (cln > (fs_info->vol.data_cls + 1)) )
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ sec = (FAT_FAT_OFFSET(fs_info->vol.type, cln) >> fs_info->vol.sec_log2) +
+ fs_info->vol.afat_loc;
+ ofs = FAT_FAT_OFFSET(fs_info->vol.type, cln) & (fs_info->vol.bps - 1);
+
+ rc = fat_buf_access(fs_info, sec, FAT_OP_TYPE_READ, &block0);
+ if (rc != RC_OK)
+ return rc;
+
+ switch ( fs_info->vol.type )
+ {
+ case FAT_FAT12:
+ /*
+ * we are enforced in complex computations for FAT12 to escape CPU
+ * align problems for some architectures
+ */
+ *ret_val = (*((uint8_t *)(block0->buffer + ofs)));
+ if ( ofs == (fs_info->vol.bps - 1) )
+ {
+ rc = fat_buf_access(fs_info, sec + 1, FAT_OP_TYPE_READ,
+ &block0);
+ if (rc != RC_OK)
+ return rc;
+
+ *ret_val |= (*((uint8_t *)(block0->buffer)))<<8;
+ }
+ else
+ {
+ *ret_val |= (*((uint8_t *)(block0->buffer + ofs + 1)))<<8;
+ }
+
+ if ( FAT_CLUSTER_IS_ODD(cln) )
+ *ret_val = (*ret_val) >> FAT12_SHIFT;
+ else
+ *ret_val = (*ret_val) & FAT_FAT12_MASK;
+ break;
+
+ case FAT_FAT16:
+ *ret_val = *((uint16_t *)(block0->buffer + ofs));
+ *ret_val = CF_LE_W(*ret_val);
+ break;
+
+ case FAT_FAT32:
+ *ret_val = *((uint32_t *)(block0->buffer + ofs));
+ *ret_val = CF_LE_L(*ret_val);
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one(EIO);
+ break;
+ }
+
+ return RC_OK;
+}
+
+/* fat_set_fat_cluster --
+ * Set the contents of the cluster (link to next cluster in the chain)
+ * from Files Allocation Table.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * cln - number of cluster to set contents to
+ * in_val - value to set
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ * and errno set appropriately
+ */
+int
+fat_set_fat_cluster(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ uint32_t in_val
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t sec = 0;
+ uint32_t ofs = 0;
+ uint16_t fat16_clv = 0;
+ uint32_t fat32_clv = 0;
+ rtems_bdbuf_buffer *block0 = NULL;
+
+ /* sanity check */
+ if ( (cln < 2) || (cln > (fs_info->vol.data_cls + 1)) )
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ sec = (FAT_FAT_OFFSET(fs_info->vol.type, cln) >> fs_info->vol.sec_log2) +
+ fs_info->vol.afat_loc;
+ ofs = FAT_FAT_OFFSET(fs_info->vol.type, cln) & (fs_info->vol.bps - 1);
+
+ rc = fat_buf_access(fs_info, sec, FAT_OP_TYPE_READ, &block0);
+ if (rc != RC_OK)
+ return rc;
+
+ switch ( fs_info->vol.type )
+ {
+ case FAT_FAT12:
+ if ( FAT_CLUSTER_IS_ODD(cln) )
+ {
+ fat16_clv = ((uint16_t )in_val) << FAT_FAT12_SHIFT;
+ *((uint8_t *)(block0->buffer + ofs)) =
+ (*((uint8_t *)(block0->buffer + ofs))) & 0x0F;
+
+ *((uint8_t *)(block0->buffer + ofs)) =
+ (*((uint8_t *)(block0->buffer + ofs))) |
+ (uint8_t )(fat16_clv & 0x00FF);
+
+ fat_buf_mark_modified(fs_info);
+
+ if ( ofs == (fs_info->vol.bps - 1) )
+ {
+ rc = fat_buf_access(fs_info, sec + 1, FAT_OP_TYPE_READ,
+ &block0);
+ if (rc != RC_OK)
+ return rc;
+
+ *((uint8_t *)(block0->buffer)) &= 0x00;
+
+ *((uint8_t *)(block0->buffer)) =
+ (*((uint8_t *)(block0->buffer))) |
+ (uint8_t )((fat16_clv & 0xFF00)>>8);
+
+ fat_buf_mark_modified(fs_info);
+ }
+ else
+ {
+ *((uint8_t *)(block0->buffer + ofs + 1)) &= 0x00;
+
+ *((uint8_t *)(block0->buffer + ofs + 1)) =
+ (*((uint8_t *)(block0->buffer + ofs + 1))) |
+ (uint8_t )((fat16_clv & 0xFF00)>>8);
+ }
+ }
+ else
+ {
+ fat16_clv = ((uint16_t )in_val) & FAT_FAT12_MASK;
+ *((uint8_t *)(block0->buffer + ofs)) &= 0x00;
+
+ *((uint8_t *)(block0->buffer + ofs)) =
+ (*((uint8_t *)(block0->buffer + ofs))) |
+ (uint8_t )(fat16_clv & 0x00FF);
+
+ fat_buf_mark_modified(fs_info);
+
+ if ( ofs == (fs_info->vol.bps - 1) )
+ {
+ rc = fat_buf_access(fs_info, sec + 1, FAT_OP_TYPE_READ,
+ &block0);
+ if (rc != RC_OK)
+ return rc;
+
+ *((uint8_t *)(block0->buffer)) =
+ (*((uint8_t *)(block0->buffer))) & 0xF0;
+
+ *((uint8_t *)(block0->buffer)) =
+ (*((uint8_t *)(block0->buffer))) |
+ (uint8_t )((fat16_clv & 0xFF00)>>8);
+
+ fat_buf_mark_modified(fs_info);
+ }
+ else
+ {
+ *((uint8_t *)(block0->buffer + ofs + 1)) =
+ (*((uint8_t *)(block0->buffer + ofs + 1))) & 0xF0;
+
+ *((uint8_t *)(block0->buffer + ofs+1)) =
+ (*((uint8_t *)(block0->buffer + ofs+1))) |
+ (uint8_t )((fat16_clv & 0xFF00)>>8);
+ }
+ }
+ break;
+
+ case FAT_FAT16:
+ *((uint16_t *)(block0->buffer + ofs)) =
+ (uint16_t )(CT_LE_W(in_val));
+ fat_buf_mark_modified(fs_info);
+ break;
+
+ case FAT_FAT32:
+ fat32_clv = CT_LE_L((in_val & FAT_FAT32_MASK));
+
+ *((uint32_t *)(block0->buffer + ofs)) =
+ (*((uint32_t *)(block0->buffer + ofs))) & (CT_LE_L(0xF0000000));
+
+ *((uint32_t *)(block0->buffer + ofs)) =
+ fat32_clv | (*((uint32_t *)(block0->buffer + ofs)));
+
+ fat_buf_mark_modified(fs_info);
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one(EIO);
+ break;
+
+ }
+
+ return RC_OK;
+}
diff --git a/cpukit/libfs/src/dosfs/fat_fat_operations.h b/cpukit/libfs/src/dosfs/fat_fat_operations.h
new file mode 100644
index 0000000000..d516057ad0
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/fat_fat_operations.h
@@ -0,0 +1,59 @@
+/*
+ * fat_fat_operations.h
+ *
+ * Constants/data structures/prototypes for operations on Files Allocation
+ * Table
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+#ifndef __DOSFS_FAT_FAT_OPERATIONS_H__
+#define __DOSFS_FAT_FAT_OPERATIONS_H__
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include <rtems/bdbuf.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "fat.h"
+
+int
+fat_get_fat_cluster(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ uint32_t *ret_val);
+
+int
+fat_set_fat_cluster(rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ uint32_t in_val);
+
+int
+fat_scan_fat_for_free_clusters(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t *chain,
+ uint32_t count,
+ uint32_t *cls_added,
+ uint32_t *last_cl
+);
+
+int
+fat_free_fat_clusters_chain(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t chain
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DOSFS_FAT_FAT_OPERATIONS_H__ */
diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c
new file mode 100644
index 0000000000..9a3ad6677e
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/fat_file.c
@@ -0,0 +1,993 @@
+/*
+ * fat_file.c
+ *
+ * General operations on "fat-file"
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * @(#) $Id$
+ *
+ */
+
+#define MSDOS_TRACE 1
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <time.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+static inline void
+_hash_insert(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
+ fat_file_fd_t *el);
+
+static inline void
+_hash_delete(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
+ fat_file_fd_t *el);
+
+static inline int
+_hash_search(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ rtems_chain_control *hash,
+ uint32_t key1,
+ uint32_t key2,
+ fat_file_fd_t **ret
+);
+
+static off_t
+fat_file_lseek(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t file_cln,
+ uint32_t *disk_cln
+);
+
+/* fat_file_open --
+ * Open fat-file. Two hash tables are accessed by key
+ * constructed from cluster num and offset of the node (i.e.
+ * files/directories are distinguished by location on the disk).
+ * First, hash table("vhash") consists of fat-file descriptors corresponded
+ * to "valid" files is accessed. Search is made by 2 fields equal to key
+ * constructed. If descriptor is found in the "vhash" - return it.
+ * Otherwise search is made in hash table("rhash") consits of fat-file
+ * descriptors corresponded to "removed-but-still-open" files with the
+ * same keys.
+ * If search failed, new fat-file descriptor is added to "vhash"
+ * with both key fields equal to constructed key. Otherwise new fat-file
+ * descriptor is added to "vhash" with first key field equal to key
+ * constructed and the second equal to an unique (unique among all values
+ * of second key fields) value.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * pos - cluster and offset of the node
+ * fat_fd - placeholder for returned fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK and pointer to opened descriptor on success, or -1 if error
+ * occured (errno set appropriately)
+ */
+int
+fat_file_open(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_dir_pos_t *dir_pos,
+ fat_file_fd_t **fat_fd
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ fat_file_fd_t *lfat_fd = NULL;
+ uint32_t key = 0;
+
+ /* construct key */
+ key = fat_construct_key(mt_entry, &dir_pos->sname);
+
+ /* access "valid" hash table */
+ rc = _hash_search(mt_entry, fs_info->vhash, key, 0, &lfat_fd);
+ if ( rc == RC_OK )
+ {
+ /* return pointer to fat_file_descriptor allocated before */
+ (*fat_fd) = lfat_fd;
+ lfat_fd->links_num++;
+ return rc;
+ }
+
+ /* access "removed-but-still-open" hash table */
+ rc = _hash_search(mt_entry, fs_info->rhash, key, key, &lfat_fd);
+
+ lfat_fd = (*fat_fd) = (fat_file_fd_t*)malloc(sizeof(fat_file_fd_t));
+ if ( lfat_fd == NULL )
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ memset(lfat_fd, 0, sizeof(fat_file_fd_t));
+
+ lfat_fd->links_num = 1;
+ lfat_fd->flags &= ~FAT_FILE_REMOVED;
+ lfat_fd->map.last_cln = FAT_UNDEFINED_VALUE;
+
+ lfat_fd->dir_pos = *dir_pos;
+
+ if ( rc != RC_OK )
+ lfat_fd->ino = key;
+ else
+ {
+ lfat_fd->ino = fat_get_unique_ino(mt_entry);
+
+ if ( lfat_fd->ino == 0 )
+ {
+ free((*fat_fd));
+ /*
+ * XXX: kernel resource is unsufficient, but not the memory,
+ * but there is no suitable errno :(
+ */
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+ }
+ _hash_insert(fs_info->vhash, key, lfat_fd->ino, lfat_fd);
+
+ /*
+ * other fields of fat-file descriptor will be initialized on upper
+ * level
+ */
+
+ return RC_OK;
+}
+
+
+/* fat_file_reopen --
+ * Increment by 1 number of links
+ *
+ * PARAMETERS:
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK
+ */
+int
+fat_file_reopen(fat_file_fd_t *fat_fd)
+{
+ fat_fd->links_num++;
+ return RC_OK;
+}
+
+/* fat_file_close --
+ * Close fat-file. If count of links to fat-file
+ * descriptor is greater than 1 (i.e. somebody esle holds pointer
+ * to this descriptor) just decrement it. Otherwise
+ * do the following. If this descriptor corresponded to removed fat-file
+ * then free clusters contained fat-file data, delete descriptor from
+ * "rhash" table and free memory allocated by descriptor. If descriptor
+ * correspondes to non-removed fat-file and 'ino' field has value from
+ * unique inode numbers pool then set count of links to descriptor to zero
+ * and leave it in hash, otherwise delete descriptor from "vhash" and free
+ * memory allocated by the descriptor
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK, or -1 if error occured (errno set appropriately)
+ */
+int
+fat_file_close(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t key = 0;
+
+ /*
+ * if links_num field of fat-file descriptor is greater than 1
+ * decrement the count of links and return
+ */
+ if (fat_fd->links_num > 1)
+ {
+ fat_fd->links_num--;
+ return rc;
+ }
+
+ key = fat_construct_key(mt_entry, &fat_fd->dir_pos.sname);
+
+ if (fat_fd->flags & FAT_FILE_REMOVED)
+ {
+ rc = fat_file_truncate(mt_entry, fat_fd, 0);
+ if ( rc != RC_OK )
+ return rc;
+
+ _hash_delete(fs_info->rhash, key, fat_fd->ino, fat_fd);
+
+ if ( fat_ino_is_unique(mt_entry, fat_fd->ino) )
+ fat_free_unique_ino(mt_entry, fat_fd->ino);
+
+ free(fat_fd);
+ }
+ else
+ {
+ if (fat_ino_is_unique(mt_entry, fat_fd->ino))
+ {
+ fat_fd->links_num = 0;
+ }
+ else
+ {
+ _hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd);
+ free(fat_fd);
+ }
+ }
+ /*
+ * flush any modified "cached" buffer back to disk
+ */
+ rc = fat_buf_release(fs_info);
+
+ return rc;
+}
+
+/* fat_file_read --
+ * Read 'count' bytes from 'start' position from fat-file. This
+ * interface hides the architecture of fat-file, represents it as
+ * linear file
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * start - offset in fat-file (in bytes) to read from
+ * count - count of bytes to read
+ * buf - buffer provided by user
+ *
+ * RETURNS:
+ * the number of bytes read on success, or -1 if error occured (errno
+ * set appropriately)
+ */
+ssize_t
+fat_file_read(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t start,
+ uint32_t count,
+ uint8_t *buf
+)
+{
+ int rc = RC_OK;
+ ssize_t ret = 0;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cmpltd = 0;
+ uint32_t cur_cln = 0;
+ uint32_t cl_start = 0;
+ uint32_t save_cln = 0;
+ uint32_t ofs = 0;
+ uint32_t save_ofs;
+ uint32_t sec = 0;
+ uint32_t byte = 0;
+ uint32_t c = 0;
+
+ /* it couldn't be removed - otherwise cache update will be broken */
+ if (count == 0)
+ return cmpltd;
+
+ /*
+ * >= because start is offset and computed from 0 and file_size
+ * computed from 1
+ */
+ if ( start >= fat_fd->fat_file_size )
+ return FAT_EOF;
+
+ if ((count > fat_fd->fat_file_size) ||
+ (start > fat_fd->fat_file_size - count))
+ count = fat_fd->fat_file_size - start;
+
+ if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
+ (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
+ {
+ sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->cln);
+ sec += (start >> fs_info->vol.sec_log2);
+ byte = start & (fs_info->vol.bps - 1);
+
+ ret = _fat_block_read(mt_entry, sec, byte, count, buf);
+ if ( ret < 0 )
+ return -1;
+
+ return ret;
+ }
+
+ cl_start = start >> fs_info->vol.bpc_log2;
+ save_ofs = ofs = start & (fs_info->vol.bpc - 1);
+
+ rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
+ if (rc != RC_OK)
+ return rc;
+
+ while (count > 0)
+ {
+ c = MIN(count, (fs_info->vol.bpc - ofs));
+
+ sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
+ sec += (ofs >> fs_info->vol.sec_log2);
+ byte = ofs & (fs_info->vol.bps - 1);
+
+ ret = _fat_block_read(mt_entry, sec, byte, c, buf + cmpltd);
+ if ( ret < 0 )
+ return -1;
+
+ count -= c;
+ cmpltd += c;
+ save_cln = cur_cln;
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
+ if ( rc != RC_OK )
+ return rc;
+
+ ofs = 0;
+ }
+
+ /* update cache */
+ /* XXX: check this - I'm not sure :( */
+ fat_fd->map.file_cln = cl_start +
+ ((save_ofs + cmpltd - 1) >> fs_info->vol.bpc_log2);
+ fat_fd->map.disk_cln = save_cln;
+
+ return cmpltd;
+}
+
+/* fat_file_write --
+ * Write 'count' bytes of data from user supplied buffer to fat-file
+ * starting at offset 'start'. This interface hides the architecture
+ * of fat-file, represents it as linear file
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * start - offset(in bytes) to write from
+ * count - count
+ * buf - buffer provided by user
+ *
+ * RETURNS:
+ * number of bytes actually written to the file on success, or -1 if
+ * error occured (errno set appropriately)
+ */
+ssize_t
+fat_file_write(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t start,
+ uint32_t count,
+ const uint8_t *buf
+ )
+{
+ int rc = 0;
+ ssize_t ret = 0;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cmpltd = 0;
+ uint32_t cur_cln = 0;
+ uint32_t save_cln = 0; /* FIXME: This might be incorrect, cf. below */
+ uint32_t cl_start = 0;
+ uint32_t ofs = 0;
+ uint32_t save_ofs;
+ uint32_t sec = 0;
+ uint32_t byte = 0;
+ uint32_t c = 0;
+
+ if ( count == 0 )
+ return cmpltd;
+
+ if ( start > fat_fd->fat_file_size )
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ if ((count > fat_fd->size_limit) ||
+ (start > fat_fd->size_limit - count))
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ rc = fat_file_extend(mt_entry, fat_fd, start + count, &c);
+ if (rc != RC_OK)
+ return rc;
+
+ /*
+ * check whether there was enough room on device to locate
+ * file of 'start + count' bytes
+ */
+ if (c != (start + count))
+ count = c - start;
+
+ if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
+ (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
+ {
+ sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->cln);
+ sec += (start >> fs_info->vol.sec_log2);
+ byte = start & (fs_info->vol.bps - 1);
+
+ ret = _fat_block_write(mt_entry, sec, byte, count, buf);
+ if ( ret < 0 )
+ return -1;
+
+ return ret;
+ }
+
+ cl_start = start >> fs_info->vol.bpc_log2;
+ save_ofs = ofs = start & (fs_info->vol.bpc - 1);
+
+ rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
+ if (rc != RC_OK)
+ return rc;
+
+ while (count > 0)
+ {
+ c = MIN(count, (fs_info->vol.bpc - ofs));
+
+ sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
+ sec += (ofs >> fs_info->vol.sec_log2);
+ byte = ofs & (fs_info->vol.bps - 1);
+
+ ret = _fat_block_write(mt_entry, sec, byte, c, buf + cmpltd);
+ if ( ret < 0 )
+ return -1;
+
+ count -= c;
+ cmpltd += c;
+ save_cln = cur_cln;
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
+ if ( rc != RC_OK )
+ return rc;
+
+ ofs = 0;
+ }
+
+ /* update cache */
+ /* XXX: check this - I'm not sure :( */
+ fat_fd->map.file_cln = cl_start +
+ ((save_ofs + cmpltd - 1) >> fs_info->vol.bpc_log2);
+ fat_fd->map.disk_cln = save_cln;
+
+ return cmpltd;
+}
+
+/* fat_file_extend --
+ * Extend fat-file. If new length less than current fat-file size -
+ * do nothing. Otherwise calculate necessary count of clusters to add,
+ * allocate it and add new clusters chain to the end of
+ * existing clusters chain.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * new_length - new length
+ * a_length - placeholder for result - actual new length of file
+ *
+ * RETURNS:
+ * RC_OK and new length of file on success, or -1 if error occured (errno
+ * set appropriately)
+ */
+int
+fat_file_extend(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t new_length,
+ uint32_t *a_length
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t chain = 0;
+ uint32_t bytes2add = 0;
+ uint32_t cls2add = 0;
+ uint32_t old_last_cl;
+ uint32_t last_cl = 0;
+ uint32_t bytes_remain = 0;
+ uint32_t cls_added;
+
+ *a_length = new_length;
+
+ if (new_length <= fat_fd->fat_file_size)
+ return RC_OK;
+
+ if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
+ (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
+ rtems_set_errno_and_return_minus_one( ENOSPC );
+
+ bytes_remain = (fs_info->vol.bpc -
+ (fat_fd->fat_file_size & (fs_info->vol.bpc - 1))) &
+ (fs_info->vol.bpc - 1);
+
+ bytes2add = new_length - fat_fd->fat_file_size;
+
+ if (bytes2add > bytes_remain)
+ bytes2add -= bytes_remain;
+ else
+ bytes2add = 0;
+
+ /*
+ * if in last cluster allocated for the file there is enough room to
+ * handle extention (hence we don't need to add even one cluster to the
+ * file ) - return
+ */
+ if (bytes2add == 0)
+ return RC_OK;
+
+ cls2add = ((bytes2add - 1) >> fs_info->vol.bpc_log2) + 1;
+
+ rc = fat_scan_fat_for_free_clusters(mt_entry, &chain, cls2add,
+ &cls_added, &last_cl);
+
+ /* this means that low level I/O error occured */
+ if (rc != RC_OK)
+ return rc;
+
+ /* this means that no space left on device */
+ if ((cls_added == 0) && (bytes_remain == 0))
+ rtems_set_errno_and_return_minus_one(ENOSPC);
+
+ /* check wether we satisfied request for 'cls2add' clusters */
+ if (cls2add != cls_added)
+ *a_length = new_length -
+ ((cls2add - cls_added - 1) << fs_info->vol.bpc_log2) -
+ (bytes2add & (fs_info->vol.bpc - 1));
+
+ /* add new chain to the end of existed */
+ if ( fat_fd->fat_file_size == 0 )
+ {
+ fat_fd->map.disk_cln = fat_fd->cln = chain;
+ fat_fd->map.file_cln = 0;
+ }
+ else
+ {
+ if (fat_fd->map.last_cln != FAT_UNDEFINED_VALUE)
+ {
+ old_last_cl = fat_fd->map.last_cln;
+ }
+ else
+ {
+ rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
+ (fat_fd->fat_file_size - 1), &old_last_cl);
+ if ( rc != RC_OK )
+ {
+ fat_free_fat_clusters_chain(mt_entry, chain);
+ return rc;
+ }
+ }
+
+ rc = fat_set_fat_cluster(mt_entry, old_last_cl, chain);
+ if ( rc != RC_OK )
+ {
+ fat_free_fat_clusters_chain(mt_entry, chain);
+ return rc;
+ }
+ fat_buf_release(fs_info);
+ }
+
+ /* update number of the last cluster of the file if it changed */
+ if (cls_added != 0)
+ {
+ fat_fd->map.last_cln = last_cl;
+ if (fat_fd->fat_file_type == FAT_DIRECTORY)
+ {
+ rc = fat_init_clusters_chain(mt_entry, chain);
+ if ( rc != RC_OK )
+ {
+ fat_free_fat_clusters_chain(mt_entry, chain);
+ return rc;
+ }
+ }
+ }
+
+ fat_fd->fat_file_size = new_length;
+
+ return RC_OK;
+}
+
+/* fat_file_truncate --
+ * Truncate fat-file. If new length greater than current fat-file size -
+ * do nothing. Otherwise find first cluster to free and free all clusters
+ * in the chain starting from this cluster.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * new_length - new length
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+fat_file_truncate(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t new_length
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cur_cln = 0;
+ uint32_t cl_start = 0;
+ uint32_t new_last_cln = FAT_UNDEFINED_VALUE;
+
+
+ if ( new_length >= fat_fd->fat_file_size )
+ return rc;
+
+ assert(fat_fd->fat_file_size);
+
+ cl_start = (new_length + fs_info->vol.bpc - 1) >> fs_info->vol.bpc_log2;
+
+ if ((cl_start << fs_info->vol.bpc_log2) >= fat_fd->fat_file_size)
+ return RC_OK;
+
+ if (cl_start != 0)
+ {
+ rc = fat_file_lseek(mt_entry, fat_fd, cl_start - 1, &new_last_cln);
+ if (rc != RC_OK)
+ return rc;
+
+ }
+
+ rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
+ if (rc != RC_OK)
+ return rc;
+
+ rc = fat_free_fat_clusters_chain(mt_entry, cur_cln);
+ if (rc != RC_OK)
+ return rc;
+
+ if (cl_start != 0)
+ {
+ rc = fat_set_fat_cluster(mt_entry, new_last_cln, FAT_GENFAT_EOC);
+ if ( rc != RC_OK )
+ return rc;
+ fat_fd->map.file_cln = cl_start - 1;
+ fat_fd->map.disk_cln = new_last_cln;
+ fat_fd->map.last_cln = new_last_cln;
+ }
+ return RC_OK;
+}
+
+/* fat_file_ioctl --
+ * F_CLU_NUM:
+ * make mapping between serial number of the cluster in fat-file and
+ * its real number on the volume
+ *
+ * PARAMETERS:
+ * fat_fd - fat-file descriptor
+ * mt_entry - mount table entry
+ * cmd - command
+ * ...
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured and errno set appropriately
+ */
+int
+fat_file_ioctl(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ int cmd,
+ ...)
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cur_cln = 0;
+ uint32_t cl_start = 0;
+ uint32_t pos = 0;
+ uint32_t *ret;
+ va_list ap;
+
+ va_start(ap, cmd);
+
+ switch (cmd)
+ {
+ case F_CLU_NUM:
+ pos = va_arg(ap, uint32_t );
+ ret = va_arg(ap, uint32_t *);
+
+ /* sanity check */
+ if ( pos >= fat_fd->fat_file_size ) {
+ va_end(ap);
+ rtems_set_errno_and_return_minus_one( EIO );
+ }
+
+ if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
+ (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
+ {
+ /* cluster 0 (zero) reserved for root dir */
+ *ret = 0;
+ rc = RC_OK;
+ break;
+ }
+
+ cl_start = pos >> fs_info->vol.bpc_log2;
+
+ rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
+ if ( rc != RC_OK )
+ break;
+
+ *ret = cur_cln;
+ break;
+
+ default:
+ errno = EINVAL;
+ rc = -1;
+ break;
+ }
+ va_end(ap);
+ return rc;
+}
+
+/* fat_file_mark_removed --
+ * Remove the fat-file descriptor from "valid" hash table, insert it
+ * into "removed-but-still-open" hash table and set up "removed" bit.
+ *
+ * PARAMETERS:
+ * fat_fd - fat-file descriptor
+ * mt_entry - mount table entry
+ *
+ * RETURNS:
+ * None
+ */
+void
+fat_file_mark_removed(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t key = 0;
+
+ key = fat_construct_key(mt_entry, &fat_fd->dir_pos.sname);
+
+ _hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd);
+
+ _hash_insert(fs_info->rhash, key, fat_fd->ino, fat_fd);
+
+ fat_fd->flags |= FAT_FILE_REMOVED;
+}
+
+/* fat_file_datasync --
+ * Synchronize fat-file - flush all buffered data to the media.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured and errno set appropriately
+ */
+int
+fat_file_datasync(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cur_cln = fat_fd->cln;
+ rtems_bdbuf_buffer *block = NULL;
+ uint32_t sec = 0;
+ uint32_t i = 0;
+
+ if (fat_fd->fat_file_size == 0)
+ return RC_OK;
+
+ /*
+ * we can use only one bdbuf :( and we also know that cache is useless
+ * for sync operation, so don't use it
+ */
+ rc = fat_buf_release(fs_info);
+ if (rc != RC_OK)
+ return rc;
+
+ /* for each cluster of the file ... */
+ while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
+ {
+ sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
+ /* for each sector in cluster ... */
+ for ( i = 0; i < fs_info->vol.spc; i++ )
+ {
+ /* ... sync it */
+ sc = rtems_bdbuf_read(fs_info->vol.dev, (sec + i), &block);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ sc = rtems_bdbuf_sync(block);
+ if ( sc != RTEMS_SUCCESSFUL )
+ rtems_set_errno_and_return_minus_one( EIO );
+ }
+
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
+ if ( rc != RC_OK )
+ return rc;
+ }
+ return rc;
+}
+
+/* fat_file_size --
+ * Calculate fat-file size - fat-file is nothing that clusters chain, so
+ * go through all clusters in the chain and count it. Only
+ * special case is root directory for FAT12/16 volumes.
+ * This function is used only for directories which are fat-files with
+ * non-zero length, hence 'fat_fd->cln' always contains valid data.
+ * Calculated size is stored in 'fat_file_size' field of fat-file
+ * descriptor.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+fat_file_size(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ int rc = RC_OK;
+ fat_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t cur_cln = fat_fd->cln;
+ uint32_t save_cln = 0;
+
+ /* Have we requested root dir size for FAT12/16? */
+ if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
+ (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
+ {
+ fat_fd->fat_file_size = fs_info->vol.rdir_size;
+ return rc;
+ }
+
+ fat_fd->fat_file_size = 0;
+
+ while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
+ {
+ save_cln = cur_cln;
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
+ if ( rc != RC_OK )
+ return rc;
+
+ fat_fd->fat_file_size += fs_info->vol.bpc;
+ }
+ fat_fd->map.last_cln = save_cln;
+ return rc;
+}
+
+/* hash support routines */
+
+/* _hash_insert --
+ * Insert elemnt into hash based on key 'key1'
+ *
+ * PARAMETERS:
+ * hash - hash element will be inserted into
+ * key1 - key on which insertion is based on
+ * key2 - not used during insertion
+ * el - element to insert
+ *
+ * RETURNS:
+ * None
+ */
+static inline void
+_hash_insert(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
+ fat_file_fd_t *el)
+{
+ rtems_chain_append((hash) + ((key1) % FAT_HASH_MODULE), &(el)->link);
+}
+
+
+/* _hash_delete --
+ * Remove element from hash
+ *
+ * PARAMETERS:
+ * hash - hash element will be removed from
+ * key1 - not used
+ * key2 - not used
+ * el - element to delete
+ *
+ * RETURNS:
+ * None
+ */
+static inline void
+_hash_delete(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
+ fat_file_fd_t *el)
+{
+ rtems_chain_extract(&(el)->link);
+}
+
+/* _hash_search --
+ * Search element in hash. If both keys match pointer to found element
+ * is returned
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * hash - hash element will be removed from
+ * key1 - search key
+ * key2 - search key
+ * ret - placeholder for result
+ *
+ * RETURNS:
+ * 0 and pointer to found element on success, -1 otherwise
+ */
+static inline int
+_hash_search(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ rtems_chain_control *hash,
+ uint32_t key1,
+ uint32_t key2,
+ fat_file_fd_t **ret
+ )
+{
+ uint32_t mod = (key1) % FAT_HASH_MODULE;
+ rtems_chain_node *the_node = rtems_chain_first(hash + mod);
+
+ for ( ; !rtems_chain_is_tail((hash) + mod, the_node) ; )
+ {
+ fat_file_fd_t *ffd = (fat_file_fd_t *)the_node;
+ uint32_t ck = fat_construct_key(mt_entry, &ffd->dir_pos.sname);
+
+ if ( (key1) == ck)
+ {
+ if ( ((key2) == 0) || ((key2) == ffd->ino) )
+ {
+ *ret = (void *)the_node;
+ return 0;
+ }
+ }
+ the_node = the_node->next;
+ }
+ return -1;
+}
+
+static off_t
+fat_file_lseek(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t file_cln,
+ uint32_t *disk_cln
+ )
+{
+ int rc = RC_OK;
+
+ if (file_cln == fat_fd->map.file_cln)
+ *disk_cln = fat_fd->map.disk_cln;
+ else
+ {
+ uint32_t cur_cln;
+ uint32_t count;
+ uint32_t i;
+
+ if (file_cln > fat_fd->map.file_cln)
+ {
+ cur_cln = fat_fd->map.disk_cln;
+ count = file_cln - fat_fd->map.file_cln;
+ }
+ else
+ {
+ cur_cln = fat_fd->cln;
+ count = file_cln;
+ }
+
+ /* skip over the clusters */
+ for (i = 0; i < count; i++)
+ {
+ rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
+ if ( rc != RC_OK )
+ return rc;
+ }
+
+ /* update cache */
+ fat_fd->map.file_cln = file_cln;
+ fat_fd->map.disk_cln = cur_cln;
+
+ *disk_cln = cur_cln;
+ }
+ return RC_OK;
+}
diff --git a/cpukit/libfs/src/dosfs/fat_file.h b/cpukit/libfs/src/dosfs/fat_file.h
new file mode 100644
index 0000000000..01ab73ef98
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/fat_file.h
@@ -0,0 +1,192 @@
+/*
+ * fat_file.h
+ *
+ * Constants/data structures/prototypes for operations on "fat-file"
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+#ifndef __DOSFS_FAT_FILE_H__
+#define __DOSFS_FAT_FILE_H__
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include <time.h>
+
+#include "fat.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* "fat-file" representation
+ *
+ * the idea is: fat-file is nothing but a cluster chain, any open fat-file is
+ * represented in system by fat-file descriptor and has well-known
+ * file interface:
+ *
+ * fat_file_open()
+ * fat_file_close()
+ * fat_file_read()
+ * fat_file_write()
+ *
+ * Such interface hides the architecture of fat-file and represents it like
+ * linear file
+ */
+
+typedef rtems_filesystem_node_types_t fat_file_type_t;
+
+#define FAT_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY
+#define FAT_FILE RTEMS_FILESYSTEM_MEMORY_FILE
+
+typedef struct fat_file_map_s
+{
+ uint32_t file_cln;
+ uint32_t disk_cln;
+ uint32_t last_cln;
+} fat_file_map_t;
+/*
+ * descriptor of a fat-file
+ *
+ * To each particular clusters chain
+ */
+typedef struct fat_file_fd_s
+{
+ rtems_chain_node link; /*
+ * fat-file descriptors organized into hash;
+ * collision lists are handled via link
+ * field
+ */
+ uint32_t links_num; /*
+ * the number of fat_file_open call on
+ * this fat-file
+ */
+ uint32_t ino; /* inode, file serial number :)))) */
+ fat_file_type_t fat_file_type;
+ uint32_t size_limit;
+ uint32_t fat_file_size; /* length */
+ uint32_t cln;
+ fat_dir_pos_t dir_pos;
+ uint8_t flags;
+ fat_file_map_t map;
+ time_t mtime;
+
+} fat_file_fd_t;
+
+#define FAT_FILE_REMOVED 0x01
+
+#define FAT_FILE_IS_REMOVED(p)\
+ (((p)->flags & FAT_FILE_REMOVED) ? 1 : 0)
+
+/* ioctl macros */
+#define F_CLU_NUM 0x01
+
+/*
+ * Each file and directory on a MSDOS volume is unique identified by it
+ * location, i.e. location of it 32 Bytes Directory Entry Structure. We can
+ * distinguish them by cluster number it locates on and offset inside this
+ * cluster. But root directory on any volumes (FAT12/16/32) has no 32 Bytes
+ * Directory Entry Structure corresponded to it. So we assume 32 Bytes
+ * Directory Entry Structure of root directory locates at cluster 1 (invalid
+ * cluaster number) and offset 0
+ */
+#define FAT_ROOTDIR_CLUSTER_NUM 0x01
+
+#define FAT_FD_OF_ROOT_DIR(fat_fd) \
+ ((fat_fd->dir_pos.sname.cln == FAT_ROOTDIR_CLUSTER_NUM) && \
+ (fat_fd->dir_pos.sname.ofs == 0))
+
+#define FAT_EOF 0x00
+
+/* fat_construct_key --
+ * Construct key for hash access: convert (cluster num, offset) to
+ * (sector512 num, new offset) and than construct key as
+ * key = (sector512 num) << 4 | (new offset)
+ *
+ * PARAMETERS:
+ * cl - cluster number
+ * ofs - offset inside cluster 'cl'
+ * mt_entry - mount table entry
+ *
+ * RETURNS:
+ * constructed key
+ */
+static inline uint32_t
+fat_construct_key(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_pos_t *pos)
+{
+ return ( ((fat_cluster_num_to_sector512_num(mt_entry, pos->cln) +
+ (pos->ofs >> FAT_SECTOR512_BITS)) << 4) +
+ ((pos->ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) );
+}
+
+/* Prototypes for "fat-file" operations */
+int
+fat_file_open(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_dir_pos_t *dir_pos,
+ fat_file_fd_t **fat_fd);
+
+int
+fat_file_reopen(fat_file_fd_t *fat_fd);
+
+int
+fat_file_close(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd);
+
+ssize_t
+fat_file_read(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t start,
+ uint32_t count,
+ uint8_t *buf);
+
+ssize_t
+fat_file_write(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t start,
+ uint32_t count,
+ const uint8_t *buf);
+
+int
+fat_file_extend(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t new_length,
+ uint32_t *a_length);
+
+int
+fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t new_length);
+
+int
+fat_file_datasync(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd);
+
+
+int
+fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ int cmd,
+ ...);
+
+int
+fat_file_size(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd);
+
+void
+fat_file_mark_removed(rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DOSFS_FAT_FILE_H__ */
diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h
new file mode 100644
index 0000000000..696dac37cf
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos.h
@@ -0,0 +1,467 @@
+/*
+ * msdos.h
+ *
+ * The MSDOS filesystem constants/data structures/prototypes
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+#ifndef __DOSFS_MSDOS_H__
+#define __DOSFS_MSDOS_H__
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_file.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MSDOS_NAME_NOT_FOUND_ERR 0x7D01
+
+/*
+ * This structure identifies the instance of the filesystem on the MSDOS
+ * level.
+ */
+typedef struct msdos_fs_info_s
+{
+ fat_fs_info_t fat; /*
+ * volume
+ * description
+ */
+ const rtems_filesystem_file_handlers_r *directory_handlers; /*
+ * a set of routines
+ * that handles the
+ * nodes of directory
+ * type
+ */
+ const rtems_filesystem_file_handlers_r *file_handlers; /*
+ * a set of routines
+ * that handles the
+ * nodes of file
+ * type
+ */
+ rtems_id vol_sema; /*
+ * semaphore
+ * associated with
+ * the volume
+ */
+ uint8_t *cl_buf; /*
+ * just placeholder
+ * for anything
+ */
+} msdos_fs_info_t;
+
+/* a set of routines that handle the nodes which are directories */
+extern const rtems_filesystem_file_handlers_r msdos_dir_handlers;
+
+/* a set of routines that handle the nodes which are files */
+extern const rtems_filesystem_file_handlers_r msdos_file_handlers;
+
+/* Volume semaphore timeout value. This value can be changed to a number
+ * of ticks to help debugging or if you need such a */
+#define MSDOS_VOLUME_SEMAPHORE_TIMEOUT RTEMS_NO_TIMEOUT
+
+/* Node types */
+#define MSDOS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY
+#define MSDOS_REGULAR_FILE RTEMS_FILESYSTEM_MEMORY_FILE
+#define MSDOS_HARD_LINK RTEMS_FILESYSTEM_HARD_LINK /* pseudo type */
+
+typedef rtems_filesystem_node_types_t msdos_node_type_t;
+
+/*
+ * Macros for fetching fields from 32 bytes long FAT Directory Entry
+ * Structure
+ */
+#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE 32 /* 32 bytes */
+
+#define MSDOS_DIR_NAME(x) (char *)((x) + 0)
+#define MSDOS_DIR_ENTRY_TYPE(x) (uint8_t *)((x) + 0)
+#define MSDOS_DIR_ATTR(x) (uint8_t *)((x) + 11)
+#define MSDOS_DIR_NT_RES(x) (uint8_t *)((x) + 12)
+#define MSDOS_DIR_LFN_CHECKSUM(x) (uint8_t *)((x) + 13)
+#define MSDOS_DIR_CRT_TIME_TENTH(x) (uint8_t *)((x) + 13)
+#define MSDOS_DIR_CRT_TIME(x) (uint16_t *)((x) + 14)
+#define MSDOS_DIR_CRT_DATE(x) (uint16_t *)((x) + 16)
+#define MSDOS_DIR_LAST_ACCESS_DATE(x) (uint16_t *)((x) + 18)
+#define MSDOS_DIR_FIRST_CLUSTER_HI(x) (uint16_t *)((x) + 20)
+#define MSDOS_DIR_WRITE_TIME(x) (uint16_t *)((x) + 22)
+#define MSDOS_DIR_WRITE_DATE(x) (uint16_t *)((x) + 24)
+#define MSDOS_DIR_FIRST_CLUSTER_LOW(x) (uint16_t *)((x) + 26)
+#define MSDOS_DIR_FILE_SIZE(x) (uint32_t *)((x) + 28)
+
+#define MSDOS_EXTRACT_CLUSTER_NUM(p) \
+ (uint32_t)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) | \
+ ((uint32_t)(CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) )
+
+/*
+ * Fields offset in 32 bytes long FAT Directory Entry
+ * Structure
+ */
+#define MSDOS_FILE_SIZE_OFFSET 28
+#define MSDOS_FILE_NAME_OFFSET 0
+#define MSDOS_FIRST_CLUSTER_HI_OFFSET 20
+#define MSDOS_FIRST_CLUSTER_LOW_OFFSET 26
+#define MSDOS_FILE_WDATE_OFFSET 24
+#define MSDOS_FILE_WTIME_OFFSET 22
+#define MSDOS_FILE_ADATE_OFFSET 18
+
+/*
+ * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry
+ * Structure
+ */
+#define MSDOS_ATTR_READ_ONLY 0x01
+#define MSDOS_ATTR_HIDDEN 0x02
+#define MSDOS_ATTR_SYSTEM 0x04
+#define MSDOS_ATTR_VOLUME_ID 0x08
+#define MSDOS_ATTR_DIRECTORY 0x10
+#define MSDOS_ATTR_ARCHIVE 0x20
+#define MSDOS_ATTR_LFN (MSDOS_ATTR_READ_ONLY | \
+ MSDOS_ATTR_HIDDEN | \
+ MSDOS_ATTR_SYSTEM | \
+ MSDOS_ATTR_VOLUME_ID)
+#define MSDOS_ATTR_LFN_MASK (MSDOS_ATTR_READ_ONLY | \
+ MSDOS_ATTR_HIDDEN | \
+ MSDOS_ATTR_SYSTEM | \
+ MSDOS_ATTR_VOLUME_ID | \
+ MSDOS_ATTR_DIRECTORY | \
+ MSDOS_ATTR_ARCHIVE)
+
+#define MSDOS_LAST_LONG_ENTRY 0x40
+#define MSDOS_LAST_LONG_ENTRY_MASK 0x3F
+
+#define MSDOS_DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
+#define MSDOS_DT_2SECONDS_SHIFT 0
+#define MSDOS_DT_MINUTES_MASK 0x7E0 /* minutes */
+#define MSDOS_DT_MINUTES_SHIFT 5
+#define MSDOS_DT_HOURS_MASK 0xF800 /* hours */
+#define MSDOS_DT_HOURS_SHIFT 11
+
+#define MSDOS_DD_DAY_MASK 0x1F /* day of month */
+#define MSDOS_DD_DAY_SHIFT 0
+#define MSDOS_DD_MONTH_MASK 0x1E0 /* month */
+#define MSDOS_DD_MONTH_SHIFT 5
+#define MSDOS_DD_YEAR_MASK 0xFE00 /* year - 1980 */
+#define MSDOS_DD_YEAR_SHIFT 9
+
+
+/*
+ * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry
+ * Structure
+ */
+#define MSDOS_THIS_DIR_ENTRY_EMPTY 0xE5
+#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY 0x00
+
+/*
+ * Number of characters per directory entry for a long filename.
+ */
+#define MSDOS_LFN_LEN_PER_ENTRY (13)
+
+/*
+ * Macros for names parsing and formatting
+ */
+#define msdos_is_separator(_ch) rtems_filesystem_is_separator(_ch)
+
+#define MSDOS_SHORT_BASE_LEN 8 /* 8 characters */
+#define MSDOS_SHORT_EXT_LEN 3 /* 3 characters */
+#define MSDOS_SHORT_NAME_LEN (MSDOS_SHORT_BASE_LEN+\
+ MSDOS_SHORT_EXT_LEN) /* 11 chars */
+#define MSDOS_NAME_MAX_LNF_LEN (255)
+#define MSDOS_NAME_MAX MSDOS_SHORT_NAME_LEN
+#define MSDOS_NAME_MAX_WITH_DOT (MSDOS_NAME_MAX + 1)
+#define MSDOS_NAME_MAX_LFN_WITH_DOT (260)
+
+
+extern const char *const MSDOS_DOT_NAME; /* ".", padded to MSDOS_NAME chars */
+extern const char *const MSDOS_DOTDOT_NAME; /* ".", padded to MSDOS_NAME chars */
+
+typedef enum msdos_name_types_e
+{
+ MSDOS_NAME_INVALID = 0, /* Unknown name type. Has invalid characters. */
+ MSDOS_NAME_SHORT, /* Name can be short. */
+ MSDOS_NAME_LONG /* Name is long; cannot be short. */
+} msdos_name_type_t;
+
+typedef enum msdos_token_types_e
+{
+ MSDOS_NO_MORE_PATH,
+ MSDOS_CURRENT_DIR,
+ MSDOS_UP_DIR,
+ MSDOS_NAME,
+ MSDOS_INVALID_TOKEN
+} msdos_token_types_t;
+
+/* Others macros */
+#define MSDOS_RES_NT_VALUE 0x00
+#define MSDOS_INIT_DIR_SIZE 0x00
+
+/* "dot" entry offset in a directory */
+#define MSDOS_DOT_DIR_ENTRY_OFFSET 0x00 /* first entry in directory */
+
+/* "dotdot" entry offset in a directory */
+#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET 0x20 /* second entry in directory */
+
+/* 'p' should be char* */
+#define DOT_NODE_P(p) ((char *)(p))
+#define DOTDOT_NODE_P(p) ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE))
+
+/* Size limits for files and directories */
+#define MSDOS_MAX_DIR_LENGHT 0x200000 /* 2,097,152 bytes */
+#define MSDOS_MAX_FILE_SIZE 0xFFFFFFFF /* 4 Gb */
+
+/*
+ * The number of 32 bytes long FAT Directory Entry
+ * Structures per 512 bytes sector
+ */
+#define MSDOS_DPS512_NUM 16
+
+/* Prototypes */
+int msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
+
+int msdos_eval_path(
+ const char *pathname, /* IN */
+ size_t pathnamelen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+int msdos_eval4make(
+ const char *path, /* IN */
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ const char **name /* OUT */
+);
+
+int msdos_unlink(rtems_filesystem_location_info_t *pathloc /* IN */);
+
+int msdos_free_node_info(rtems_filesystem_location_info_t *pathloc /* IN */);
+
+rtems_filesystem_node_types_t msdos_node_type(rtems_filesystem_location_info_t *pathloc);
+
+int msdos_mknod(
+ const char *path, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+int msdos_utime(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+);
+
+int msdos_rename(rtems_filesystem_location_info_t *old_parent_loc,
+ rtems_filesystem_location_info_t *old_loc,
+ rtems_filesystem_location_info_t *new_parent_loc,
+ const char *new_name);
+
+int msdos_initialize_support(
+ rtems_filesystem_mount_table_entry_t *temp_mt_entry,
+ const rtems_filesystem_operations_table *op_table,
+ const rtems_filesystem_file_handlers_r *file_handlers,
+ const rtems_filesystem_file_handlers_r *directory_handlers
+);
+
+int msdos_file_open(
+ rtems_libio_t *iop, /* IN */
+ const char *pathname, /* IN */
+ uint32_t flag, /* IN */
+ uint32_t mode /* IN */
+);
+
+int msdos_file_close(rtems_libio_t *iop /* IN */);
+
+ssize_t msdos_file_read(
+ rtems_libio_t *iop, /* IN */
+ void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+ssize_t msdos_file_write(
+ rtems_libio_t *iop, /* IN */
+ const void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+rtems_off64_t msdos_file_lseek(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t offset, /* IN */
+ int whence /* IN */
+);
+
+int msdos_file_stat(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct stat *buf /* OUT */
+);
+
+int
+msdos_file_ftruncate(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t length /* IN */
+);
+
+int msdos_file_sync(rtems_libio_t *iop);
+
+int msdos_file_datasync(rtems_libio_t *iop);
+
+int msdos_file_ioctl(
+ rtems_libio_t *iop, /* IN */
+ uint32_t command, /* IN */
+ void *buffer /* IN */
+);
+
+int
+msdos_dir_chmod(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ mode_t mode /* IN */
+);
+
+int msdos_file_rmnod(rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */);
+
+int msdos_dir_open(
+ rtems_libio_t *iop, /* IN */
+ const char *pathname, /* IN */
+ uint32_t flag, /* IN */
+ uint32_t mode /* IN */
+);
+
+int msdos_dir_close(rtems_libio_t *iop /* IN */);
+
+ssize_t msdos_dir_read(
+ rtems_libio_t *iop, /* IN */
+ void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+rtems_off64_t msdos_dir_lseek(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t offset, /* IN */
+ int whence /* IN */
+);
+
+int
+msdos_file_chmod(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ mode_t mode /* IN */
+);
+
+int msdos_dir_rmnod(rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */);
+
+int msdos_dir_sync(rtems_libio_t *iop);
+
+int msdos_dir_stat(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct stat *buf /* OUT */
+);
+
+int msdos_creat_node(rtems_filesystem_location_info_t *parent_loc,
+ msdos_node_type_t type,
+ const char *name,
+ int name_len,
+ mode_t mode,
+ const fat_file_fd_t *link_fd);
+
+/* Misc prototypes */
+msdos_token_types_t msdos_get_token(const char *path,
+ int pathlen,
+ const char **token,
+ int *token_len);
+
+int msdos_find_name(
+ rtems_filesystem_location_info_t *parent_loc,
+ const char *name,
+ int name_len
+);
+
+int msdos_get_name_node(
+ rtems_filesystem_location_info_t *parent_loc,
+ bool create_node,
+ const char *name,
+ int name_len,
+ msdos_name_type_t name_type,
+ fat_dir_pos_t *dir_pos,
+ char *name_dir_entry
+);
+
+int msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc);
+
+msdos_name_type_t msdos_long_to_short(const char *lfn, int lfn_len,
+ char* sfn, int sfn_len);
+
+int msdos_filename_unix2dos(const char *un, int unlen, char *dn);
+
+void msdos_date_unix2dos(
+ unsigned int tsp, uint16_t *ddp,
+ uint16_t *dtp);
+
+unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt);
+
+int msdos_set_first_cluster_num(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+);
+
+int msdos_set_file_size(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+);
+
+int msdos_set_first_char4file_name(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_dir_pos_t *dir_pos,
+ unsigned char first_char
+);
+
+int msdos_set_dir_wrt_time_and_date(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+);
+
+
+int msdos_dir_is_empty(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ bool *ret_val
+);
+
+int msdos_find_name_in_fat_file(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ bool create_node,
+ const char *name,
+ int name_len,
+ msdos_name_type_t name_type,
+ fat_dir_pos_t *dir_pos,
+ char *name_dir_entry
+);
+
+int msdos_find_node_by_cluster_num_in_fat_file(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t cl4find,
+ fat_dir_pos_t *dir_pos,
+ char *dir_entry
+);
+
+int msdos_get_dotdot_dir_info_cluster_num_and_offset(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ fat_dir_pos_t *dir_pos,
+ char *dir_entry
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DOSFS_MSDOS_H__ */
diff --git a/cpukit/libfs/src/dosfs/msdos_conv.c b/cpukit/libfs/src/dosfs/msdos_conv.c
new file mode 100644
index 0000000000..95b25814db
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_conv.c
@@ -0,0 +1,317 @@
+/*
+ * Adaptation of NetBSD code for RTEMS by Victor V. Vengerov <vvv@oktet.ru>
+ */
+/* $NetBSD: msdosfs_conv.c,v 1.10 1994/12/27 18:36:24 mycroft Exp $ */
+/*
+ * Written by Paul Popelka (paulp@uts.amdahl.com)
+ *
+ * You can do anything you want with this software, just don't say you wrote
+ * it, and don't remove this notice.
+ *
+ * This software is provided "as is".
+ *
+ * The author supplies this software to be publicly redistributed on the
+ * understanding that the author is not responsible for the correct
+ * functioning of this software in any circumstances and is not liable for
+ * any damages caused by this software.
+ *
+ * October 1992
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include "msdos.h"
+
+/* #define SECONDSPERDAY (24 * 60 * 60) */
+#define SECONDSPERDAY ((uint32_t) 86400)
+
+/*
+ * Days in each month in a regular year.
+ */
+static uint16_t regyear[] = {
+ 31, 28, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31
+};
+
+/*
+ * Days in each month in a leap year.
+ */
+static uint16_t leapyear[] = {
+ 31, 29, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31
+};
+
+/*
+ * Variables used to remember parts of the last time conversion. Maybe we
+ * can avoid a full conversion.
+ */
+static uint32_t lasttime;
+static uint32_t lastday;
+static uint16_t lastddate;
+static uint16_t lastdtime;
+
+/*
+ * Convert the unix version of time to dos's idea of time to be used in
+ * file timestamps. The passed in unix time is assumed to be in GMT.
+ */
+void
+msdos_date_unix2dos(unsigned int t, uint16_t *ddp,
+ uint16_t *dtp)
+{
+ uint32_t days;
+ uint32_t inc;
+ uint32_t year;
+ uint32_t month;
+ uint16_t *months;
+
+ /*
+ * If the time from the last conversion is the same as now, then
+ * skip the computations and use the saved result.
+ */
+ if (lasttime != t) {
+ lasttime = t;
+ lastdtime = (((t % 60) >> 1) << MSDOS_DT_2SECONDS_SHIFT)
+ + (((t / 60) % 60) << MSDOS_DT_MINUTES_SHIFT)
+ + (((t / 3600) % 24) << MSDOS_DT_HOURS_SHIFT);
+
+ /*
+ * If the number of days since 1970 is the same as the last
+ * time we did the computation then skip all this leap year
+ * and month stuff.
+ */
+ days = t / (SECONDSPERDAY);
+ if (days != lastday) {
+ lastday = days;
+ for (year = 1970;; year++) {
+ inc = year & 0x03 ? 365 : 366;
+ if (days < inc)
+ break;
+ days -= inc;
+ }
+ months = year & 0x03 ? regyear : leapyear;
+ for (month = 0; month < 12; month++) {
+ if (days < months[month])
+ break;
+ days -= months[month];
+ }
+ lastddate = ((days + 1) << MSDOS_DD_DAY_SHIFT)
+ + ((month + 1) << MSDOS_DD_MONTH_SHIFT);
+ /*
+ * Remember dos's idea of time is relative to 1980.
+ * unix's is relative to 1970. If somehow we get a
+ * time before 1980 then don't give totally crazy
+ * results.
+ */
+ if (year > 1980)
+ lastddate += (year - 1980) <<
+ MSDOS_DD_YEAR_SHIFT;
+ }
+ }
+ *dtp = lastdtime;
+ *ddp = lastddate;
+}
+
+/*
+ * The number of days between Jan 1, 1970 and Jan 1, 1980. In that
+ * interval there were 8 regular years and 2 leap years.
+ */
+/* #define DAYSTO1980 ((8 * 365) + (2 * 366)) */
+#define DAYSTO1980 ((uint32_t) 3652)
+
+static uint16_t lastdosdate;
+static uint32_t lastseconds;
+
+/*
+ * Convert from dos' idea of time to unix'. This will probably only be
+ * called from the stat(), and fstat() system calls and so probably need
+ * not be too efficient.
+ */
+unsigned int
+msdos_date_dos2unix(unsigned int dd, unsigned int dt)
+{
+ uint32_t seconds;
+ uint32_t m, month;
+ uint32_t y, year;
+ uint32_t days;
+ uint16_t *months;
+
+ seconds = 2 * ((dt & MSDOS_DT_2SECONDS_MASK) >> MSDOS_DT_2SECONDS_SHIFT)
+ + ((dt & MSDOS_DT_MINUTES_MASK) >> MSDOS_DT_MINUTES_SHIFT) * 60
+ + ((dt & MSDOS_DT_HOURS_MASK) >> MSDOS_DT_HOURS_SHIFT) * 3600;
+ /*
+ * If the year, month, and day from the last conversion are the
+ * same then use the saved value.
+ */
+ if (lastdosdate != dd) {
+ lastdosdate = dd;
+ days = 0;
+ year = (dd & MSDOS_DD_YEAR_MASK) >> MSDOS_DD_YEAR_SHIFT;
+ for (y = 0; y < year; y++)
+ days += y & 0x03 ? 365 : 366;
+ months = year & 0x03 ? regyear : leapyear;
+ /*
+ * Prevent going from 0 to 0xffffffff in the following
+ * loop.
+ */
+ month = (dd & MSDOS_DD_MONTH_MASK) >> MSDOS_DD_MONTH_SHIFT;
+ if (month == 0) {
+ month = 1;
+ }
+ for (m = 0; m < month - 1; m++)
+ days += months[m];
+ days += ((dd & MSDOS_DD_DAY_MASK) >> MSDOS_DD_DAY_SHIFT) - 1;
+ lastseconds = (days + DAYSTO1980) * SECONDSPERDAY;
+ }
+ return seconds + lastseconds;
+}
+
+static const uint8_t msdos_map[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 00-07 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 08-0f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 10-17 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 18-1f */
+ 0, '!', 0, '#', '$', '%', '&', '\'', /* 20-27 */
+ '(', ')', 0, '+', 0, '-', 0, 0, /* 28-2f */
+ '0', '1', '2', '3', '4', '5', '6', '7', /* 30-37 */
+ '8', '9', 0, 0, 0, 0, 0, 0, /* 38-3f */
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 40-47 */
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 48-4f */
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 50-57 */
+ 'X', 'Y', 'Z', 0, 0, 0, '^', '_', /* 58-5f */
+ '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 60-67 */
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 68-6f */
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 70-77 */
+ 'X', 'Y', 'Z', '{', 0, '}', '~', 0, /* 78-7f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 80-87 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 88-8f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 90-97 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 98-9f */
+ 0, 0xad, 0xbd, 0x9c, 0xcf, 0xbe, 0xdd, 0xf5, /* a0-a7 */
+ 0xf9, 0xb8, 0xa6, 0xae, 0xaa, 0xf0, 0xa9, 0xee, /* a8-af */
+ 0xf8, 0xf1, 0xfd, 0xfc, 0xef, 0xe6, 0xf4, 0xfa, /* b0-b7 */
+ 0xf7, 0xfb, 0xa7, 0xaf, 0xac, 0xab, 0xf3, 0xa8, /* b8-bf */
+ 0xb7, 0xb5, 0xb6, 0xc7, 0x8e, 0x8f, 0x92, 0x80, /* c0-c7 */
+ 0xd4, 0x90, 0xd2, 0xd3, 0xde, 0xd6, 0xd7, 0xd8, /* c8-cf */
+ 0xd1, 0xa5, 0xe3, 0xe0, 0xe2, 0xe5, 0x99, 0x9e, /* d0-d7 */
+ 0x9d, 0xeb, 0xe9, 0xea, 0x9a, 0xed, 0xe8, 0xe1, /* d8-df */
+ 0xb7, 0xb5, 0xb6, 0xc7, 0x8e, 0x8f, 0x92, 0x80, /* e0-e7 */
+ 0xd4, 0x90, 0xd2, 0xd3, 0xde, 0xd6, 0xd7, 0xd8, /* e8-ef */
+ 0xd1, 0xa5, 0xe3, 0xe0, 0xe2, 0xe5, 0x99, 0xf6, /* f0-f7 */
+ 0x9d, 0xeb, 0xe9, 0xea, 0x9a, 0xed, 0xe8, 0x98, /* f8-ff */
+#if OLD_TABLE
+/* 00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 08 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 10 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 18 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 20 */ 0x00, 0x21, 0x00, 0x23, 0x24, 0x25, 0x26, 0x27, /* !"#$%&' */
+/* 28 */ 0x28, 0x29, 0x00, 0x00, 0x00, 0x2D, 0x2E, 0x00, /* ()*+,-./ */
+/* 30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 01234567 */
+/* 38 */ 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 89:;<=>? */
+/* 40 */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* @ABCDEFG */
+/* 48 */ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, /* HIJKLMNO */
+/* 50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* PQRSTUVW */
+/* 58 */ 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x00, 0x5E, 0x5F, /* XYZ[\]^_ */
+/* 60 */ 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* `abcdefg */
+/* 68 */ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, /* hijklmno */
+/* 70 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* pqrstuvw */
+/* 78 */ 0x58, 0x59, 0x5A, 0x5B, 0x7C, 0x00, 0x7E, 0x00, /* xyz{|}~ */
+/* 80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 88 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 98 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* A0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* A8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* B0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* B8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* C0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* C8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* D0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* D8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* E0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* E8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* F0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* F8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+#endif
+};
+/*
+ * Convert a unix filename to a DOS filename. Return -1 if wrong name is
+ * supplied.
+ */
+int
+msdos_filename_unix2dos(const char *un, int unlen, char *dn)
+{
+ int i;
+ uint8_t c;
+
+ /*
+ * Fill the dos filename string with blanks. These are DOS's pad
+ * characters.
+ */
+ for (i = 0; i <= 10; i++)
+ dn[i] = ' ';
+
+ /*
+ * The filenames "." and ".." are handled specially, since they
+ * don't follow dos filename rules.
+ */
+ if (un[0] == '.' && unlen == 1) {
+ dn[0] = '.';
+ return 0;
+ }
+ if (un[0] == '.' && un[1] == '.' && unlen == 2) {
+ dn[0] = '.';
+ dn[1] = '.';
+ return 0;
+ }
+
+ /*
+ * Remove any dots from the start of a file name.
+ */
+ while (unlen && (*un == '.')) {
+ un++;
+ unlen--;
+ }
+
+ /*
+ * Copy the unix filename into the dos filename string upto the end
+ * of string, a '.', or 8 characters. Whichever happens first stops
+ * us. This forms the name portion of the dos filename. Fold to
+ * upper case.
+ */
+ for (i = 0; i <= 7 && unlen && (c = *un) && c != '.'; i++) {
+ if (msdos_map[c] == 0)
+ break;
+ dn[i] = msdos_map[c];
+ un++;
+ unlen--;
+ }
+
+ /*
+ * Strip any further characters up to a '.' or the end of the
+ * string.
+ */
+ while (unlen && (c = *un)) {
+ un++;
+ unlen--;
+ /* Make sure we've skipped over the dot before stopping. */
+ if (c == '.')
+ break;
+ }
+
+ /*
+ * Copy in the extension part of the name, if any. Force to upper
+ * case. Note that the extension is allowed to contain '.'s.
+ * Filenames in this form are probably inaccessable under dos.
+ */
+ for (i = 8; i <= 10 && unlen && (c = *un); i++) {
+ if (msdos_map[c] == 0)
+ break;
+ dn[i] = msdos_map[c];
+ un++;
+ unlen--;
+ }
+ return 0;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_create.c b/cpukit/libfs/src/dosfs/msdos_create.c
new file mode 100644
index 0000000000..ec5862a178
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_create.c
@@ -0,0 +1,267 @@
+/*
+ * Routine to create a new MSDOS filesystem node
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ *
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rtems/libio_.h>
+#include <time.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_creat_node --
+ * Create a new node. Determine if the name is a long name. If long we to
+ * scan the directory to create a short entry.
+ *
+ *
+
+
+
+ * If a new node is file, FAT 32 Bytes Directory
+ * Entry Structure is initialized, free space is found in parent
+ * directory and structure is written to the disk. In case of directory,
+ * all above steps present and also new cluster is allocated for a
+ * new directory and dot and dotdot nodes are created in alloceted cluster.
+ *
+ * PARAMETERS:
+ * parent_loc - parent (directory we are going to create node in)
+ * type - new node type (file or directory)
+ * name - new node name
+ * mode - mode
+ * link_info - fs_info of existing node for a pseudo "hard-link"
+ * (see msdos_file.c, msdos_link for documentation)
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately).
+ *
+ */
+int
+msdos_creat_node(rtems_filesystem_location_info_t *parent_loc,
+ msdos_node_type_t type,
+ const char *name,
+ int name_len,
+ mode_t mode,
+ const fat_file_fd_t *link_fd)
+{
+ int rc = RC_OK;
+ ssize_t ret = 0;
+ msdos_fs_info_t *fs_info = parent_loc->mt_entry->fs_info;
+ fat_file_fd_t *parent_fat_fd = parent_loc->node_access;
+ fat_file_fd_t *fat_fd = NULL;
+ time_t time_ret = 0;
+ uint16_t time_val = 0;
+ uint16_t date = 0;
+ fat_dir_pos_t dir_pos;
+ msdos_name_type_t name_type;
+ char short_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
+ char dot_dotdot[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2];
+ char link_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
+ uint32_t sec = 0;
+ uint32_t byte = 0;
+
+ fat_dir_pos_init(&dir_pos);
+
+ memset(short_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ memset(dot_dotdot, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2);
+
+ name_type = msdos_long_to_short (name, name_len,
+ MSDOS_DIR_NAME(short_node),
+ MSDOS_NAME_MAX);
+
+ /* fill reserved field */
+ *MSDOS_DIR_NT_RES(short_node) = MSDOS_RES_NT_VALUE;
+
+ /* set up last write date and time */
+ time_ret = time(NULL);
+ if ( time_ret == -1 )
+ return -1;
+
+ msdos_date_unix2dos(time_ret, &date, &time_val);
+ *MSDOS_DIR_CRT_TIME(short_node) = CT_LE_W(time_val);
+ *MSDOS_DIR_CRT_DATE(short_node) = CT_LE_W(date);
+ *MSDOS_DIR_WRITE_TIME(short_node) = CT_LE_W(time_val);
+ *MSDOS_DIR_WRITE_DATE(short_node) = CT_LE_W(date);
+ *MSDOS_DIR_LAST_ACCESS_DATE(short_node) = CT_LE_W(date);
+
+ /* initialize directory/file size */
+ *MSDOS_DIR_FILE_SIZE(short_node) = MSDOS_INIT_DIR_SIZE;
+
+ if (type == MSDOS_DIRECTORY) {
+ *MSDOS_DIR_ATTR(short_node) |= MSDOS_ATTR_DIRECTORY;
+ }
+ else if (type == MSDOS_HARD_LINK) {
+ /*
+ * when we establish a (temporary) hard link,
+ * we must copy some information from the original
+ * node to the newly created
+ */
+ /*
+ * read the original directory entry
+ */
+ sec = fat_cluster_num_to_sector_num(parent_loc->mt_entry,
+ link_fd->dir_pos.sname.cln);
+ sec += (link_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
+ byte = (link_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1));
+
+ ret = _fat_block_read(parent_loc->mt_entry,
+ sec, byte, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE,
+ link_node);
+ if (ret < 0) {
+ return -1;
+ }
+ /*
+ * copy various attributes
+ */
+ *MSDOS_DIR_ATTR(short_node) =*MSDOS_DIR_ATTR(link_node);
+ *MSDOS_DIR_CRT_TIME_TENTH(short_node)=*MSDOS_DIR_CRT_TIME_TENTH(link_node);
+ *MSDOS_DIR_CRT_TIME(short_node) =*MSDOS_DIR_CRT_TIME(link_node);
+ *MSDOS_DIR_CRT_DATE(short_node) =*MSDOS_DIR_CRT_DATE(link_node);
+
+ /*
+ * copy/set "file size", "first cluster"
+ */
+ *MSDOS_DIR_FILE_SIZE(short_node) =*MSDOS_DIR_FILE_SIZE(link_node);
+
+ *MSDOS_DIR_FIRST_CLUSTER_LOW(short_node) =
+ *MSDOS_DIR_FIRST_CLUSTER_LOW(link_node);
+ *MSDOS_DIR_FIRST_CLUSTER_HI(short_node) =
+ *MSDOS_DIR_FIRST_CLUSTER_HI(link_node);
+ /*
+ * set "archive bit" due to changes
+ */
+ *MSDOS_DIR_ATTR(short_node) |= MSDOS_ATTR_ARCHIVE;
+ }
+ else { /* regular file... */
+ *MSDOS_DIR_ATTR(short_node) |= MSDOS_ATTR_ARCHIVE;
+ }
+
+ /*
+ * find free space in the parent directory and write new initialized
+ * FAT 32 Bytes Directory Entry Structure to the disk
+ */
+ rc = msdos_get_name_node(parent_loc, true, name, name_len,
+ name_type, &dir_pos, short_node);
+ if ( rc != RC_OK )
+ return rc;
+
+ /*
+ * if we create a new file we are done, if directory there are more steps
+ * to do
+ */
+ if (type == MSDOS_DIRECTORY)
+ {
+ /* open new directory as fat-file */
+ rc = fat_file_open(parent_loc->mt_entry, &dir_pos, &fat_fd);
+ if (rc != RC_OK)
+ goto err;
+
+ /*
+ * we opened fat-file for node we just created, so initialize fat-file
+ * descritor
+ */
+ fat_fd->fat_file_size = 0;
+ fat_fd->fat_file_type = FAT_DIRECTORY;
+ fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
+
+ /*
+ * dot and dotdot entries are identical to new node except the
+ * names
+ */
+ memcpy(DOT_NODE_P(dot_dotdot), short_node,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ memcpy(DOTDOT_NODE_P(dot_dotdot), short_node,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ memcpy(MSDOS_DIR_NAME(DOT_NODE_P(dot_dotdot)), MSDOS_DOT_NAME,
+ MSDOS_NAME_MAX);
+ memcpy(MSDOS_DIR_NAME(DOTDOT_NODE_P(dot_dotdot)), MSDOS_DOTDOT_NAME,
+ MSDOS_NAME_MAX);
+
+ /* set up cluster num for dotdot entry */
+ /*
+ * here we can ommit FAT32 condition because for all FAT types dirs
+ * right under root dir should contain 0 in dotdot entry but for
+ * FAT12/16 parent_fat_fd->cluster_num always contains such value
+ */
+ if ((FAT_FD_OF_ROOT_DIR(parent_fat_fd)) &&
+ (fs_info->fat.vol.type & FAT_FAT32))
+ {
+ *MSDOS_DIR_FIRST_CLUSTER_LOW(DOTDOT_NODE_P(dot_dotdot)) = 0x0000;
+ *MSDOS_DIR_FIRST_CLUSTER_HI(DOTDOT_NODE_P(dot_dotdot)) = 0x0000;
+ }
+ else
+ {
+ *MSDOS_DIR_FIRST_CLUSTER_LOW(DOTDOT_NODE_P(dot_dotdot)) =
+ CT_LE_W((uint16_t )((parent_fat_fd->cln) & 0x0000FFFF));
+ *MSDOS_DIR_FIRST_CLUSTER_HI(DOTDOT_NODE_P(dot_dotdot)) =
+ CT_LE_W((uint16_t )(((parent_fat_fd->cln) & 0xFFFF0000)>>16));
+ }
+
+ /*
+ * write dot and dotdot entries to new fat-file: currently fat-file
+ * correspondes to a new node is zero length, so it will be extended
+ * by one cluster and entries will be written
+ */
+ ret = fat_file_write(parent_loc->mt_entry, fat_fd, 0,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2,
+ (uint8_t *)dot_dotdot);
+ if (ret < 0)
+ {
+ rc = -1;
+ goto error;
+ }
+
+ /* increment fat-file size by cluster size */
+ fat_fd->fat_file_size += fs_info->fat.vol.bpc;
+
+ /* set up cluster num for dot entry */
+ *MSDOS_DIR_FIRST_CLUSTER_LOW(DOT_NODE_P(dot_dotdot)) =
+ CT_LE_W((uint16_t )((fat_fd->cln) & 0x0000FFFF));
+ *MSDOS_DIR_FIRST_CLUSTER_HI(DOT_NODE_P(dot_dotdot)) =
+ CT_LE_W((uint16_t )(((fat_fd->cln) & 0xFFFF0000) >> 16));
+
+ /* rewrite dot entry */
+ ret = fat_file_write(parent_loc->mt_entry, fat_fd, 0,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE,
+ (uint8_t *)DOT_NODE_P(dot_dotdot));
+ if (ret < 0)
+ {
+ rc = -1;
+ goto error;
+ }
+
+ /* write first cluster num of a new directory to disk */
+ rc = msdos_set_first_cluster_num(parent_loc->mt_entry, fat_fd);
+ if (rc != RC_OK)
+ goto error;
+
+ fat_file_close(parent_loc->mt_entry, fat_fd);
+ }
+ return RC_OK;
+
+error:
+ fat_file_close(parent_loc->mt_entry, fat_fd);
+
+err:
+ /* mark the used 32bytes structure on the disk as free */
+ msdos_set_first_char4file_name(parent_loc->mt_entry, &dir_pos, 0xE5);
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c
new file mode 100644
index 0000000000..7e6bcf3db6
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_dir.c
@@ -0,0 +1,706 @@
+/*
+ * MSDOS directory handlers implementation
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <rtems/libio_.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <dirent.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_dir_open --
+ * Open fat-file which correspondes to the directory being opened and
+ * set offset field of file control block to zero.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * pathname - name
+ * flag - flags
+ * mode - mode
+ *
+ * RETURNS:
+ * RC_OK, if directory opened successfully, or -1 if error occured (errno
+ * set apropriately)
+ */
+int
+msdos_dir_open(rtems_libio_t *iop, const char *pathname, uint32_t flag,
+ uint32_t mode)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ rc = fat_file_reopen(fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ iop->offset = 0;
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_dir_close --
+ * Close fat-file which correspondes to the directory being closed
+ *
+ * PARAMETERS:
+ * iop - file control block
+ *
+ * RETURNS:
+ * RC_OK, if directory closed successfully, or -1 if error occured (errno
+ * set apropriately.
+ */
+int
+msdos_dir_close(rtems_libio_t *iop)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ rc = fat_file_close(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_format_dirent_with_dot --
+ * This routine convert a (short) MSDOS filename as present on disk
+ * (fixed 8+3 characters, filled with blanks, without separator dot)
+ * to a "normal" format, with between 0 and 8 name chars,
+ * a separating dot and up to 3 extension characters
+ * Rules to work:
+ * - copy any (0-8) "name" part characters that are non-blank
+ * - if an extension exists, append a dot
+ * - copy any (0-3) non-blank extension characters
+ * - append a '\0' (dont count it for the rturn code
+ *
+ * PARAMETERS:
+ * dst: pointer to destination char array (must be big enough)
+ * src: pointer to source characters
+ *
+ *
+ * RETURNS:
+ * the number of bytes (without trailing '\0'(written to destination
+ */
+static ssize_t
+msdos_format_dirent_with_dot(char *dst,const char *src)
+{
+ ssize_t len;
+ int i;
+ const char *src_tmp;
+
+ /*
+ * find last non-blank character of base name
+ */
+ for ((i = MSDOS_SHORT_BASE_LEN ,
+ src_tmp = src + MSDOS_SHORT_BASE_LEN-1);
+ ((i > 0) &&
+ (*src_tmp == ' '));
+ i--,src_tmp--)
+ {};
+ /*
+ * copy base name to destination
+ */
+ src_tmp = src;
+ len = i;
+ while (i-- > 0) {
+ *dst++ = tolower((unsigned char)(*src_tmp++));
+ }
+ /*
+ * find last non-blank character of extension
+ */
+ for ((i = MSDOS_SHORT_EXT_LEN ,
+ src_tmp = src + MSDOS_SHORT_BASE_LEN+MSDOS_SHORT_EXT_LEN-1);
+ ((i > 0) &&
+ (*src_tmp == ' '));
+ i--,src_tmp--)
+ {};
+ /*
+ * extension is not empty
+ */
+ if (i > 0) {
+ *dst++ = '.'; /* append dot */
+ len += i + 1; /* extension + dot */
+ src_tmp = src + MSDOS_SHORT_BASE_LEN;
+ while (i-- > 0) {
+ *dst++ = tolower((unsigned char)(*src_tmp++));
+ len++;
+ }
+ }
+ *dst = '\0'; /* terminate string */
+
+ return len;
+}
+
+/* msdos_dir_read --
+ * This routine will read the next directory entry based on the directory
+ * offset. The offset should be equal to -n- time the size of an
+ * individual dirent structure. If n is not an integer multiple of the
+ * sizeof a dirent structure, an integer division will be performed to
+ * determine directory entry that will be returned in the buffer. Count
+ * should reflect -m- times the sizeof dirent bytes to be placed in the
+ * buffer.
+ * If there are not -m- dirent elements from the current directory
+ * position to the end of the exisiting file, the remaining entries will
+ * be placed in the buffer and the returned value will be equal to
+ * -m actual- times the size of a directory entry.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * buffer - buffer provided by user
+ * count - count of bytes to read
+ *
+ * RETURNS:
+ * the number of bytes read on success, or -1 if error occured (errno
+ * set apropriately).
+ */
+ssize_t
+msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+ fat_file_fd_t *tmp_fat_fd = NULL;
+ struct dirent tmp_dirent;
+ uint32_t start = 0;
+ ssize_t ret = 0;
+ uint32_t cmpltd = 0;
+ uint32_t j = 0, i = 0;
+ uint32_t bts2rd = 0;
+ uint32_t cur_cln = 0;
+ uint32_t lfn_start = FAT_FILE_SHORT_NAME;
+ uint8_t lfn_checksum = 0;
+ int lfn_entries = 0;
+
+ /*
+ * cast start and count - protect against using sizes that are not exact
+ * multiples of the -dirent- size. These could result in unexpected
+ * results
+ */
+ start = iop->offset / sizeof(struct dirent);
+ count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
+
+ /*
+ * optimization: we know that root directory for FAT12/16 volumes is
+ * sequential set of sectors and any cluster is sequential set of sectors
+ * too, so read such set of sectors is quick operation for low-level IO
+ * layer.
+ */
+ bts2rd = (FAT_FD_OF_ROOT_DIR(fat_fd) &&
+ (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16))) ?
+ fat_fd->fat_file_size :
+ fs_info->fat.vol.bpc;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ while (count > 0)
+ {
+ /*
+ * fat-file is already opened by open call, so read it
+ * Always read directory fat-file from the beggining because of MSDOS
+ * directories feature :( - we should count elements currently
+ * present in the directory because there may be holes :)
+ */
+ ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, (j * bts2rd),
+ bts2rd, fs_info->cl_buf);
+ if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ rtems_set_errno_and_return_minus_one(EIO);
+ }
+
+ for (i = 0; i < ret; i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ {
+ char* entry = (char*) fs_info->cl_buf + i;
+
+ /*
+ * Is this directory from here on empty ?
+ */
+ if ((*MSDOS_DIR_ENTRY_TYPE(entry)) ==
+ MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return cmpltd;
+ }
+
+ /* Is the directory entry empty */
+ if ((*MSDOS_DIR_ENTRY_TYPE(entry)) == MSDOS_THIS_DIR_ENTRY_EMPTY)
+ continue;
+
+ /* Is the directory entry empty a volume label */
+ if (((*MSDOS_DIR_ATTR(entry)) & MSDOS_ATTR_VOLUME_ID) &&
+ ((*MSDOS_DIR_ATTR(entry) & MSDOS_ATTR_LFN_MASK) != MSDOS_ATTR_LFN))
+ continue;
+
+ /*
+ * Check the attribute to see if the entry is for a long file
+ * name.
+ */
+ if ((*MSDOS_DIR_ATTR(entry) & MSDOS_ATTR_LFN_MASK) ==
+ MSDOS_ATTR_LFN)
+ {
+ int o;
+ char* p;
+ int q;
+
+ /*
+ * Is this is the first entry of a LFN ?
+ */
+ if (lfn_start == FAT_FILE_SHORT_NAME)
+ {
+ /*
+ * The first entry must have the last long entry flag set.
+ */
+ if ((*MSDOS_DIR_ENTRY_TYPE(entry) &
+ MSDOS_LAST_LONG_ENTRY) == 0)
+ continue;
+
+ /*
+ * Remember the start location of the long file name.
+ */
+ lfn_start =
+ ((j * bts2rd) + i) / MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE;
+
+ /*
+ * Get the number of entries so we can count down and
+ * also the checksum of the short entry.
+ */
+ lfn_entries = (*MSDOS_DIR_ENTRY_TYPE(entry) &
+ MSDOS_LAST_LONG_ENTRY_MASK);
+ lfn_checksum = *MSDOS_DIR_LFN_CHECKSUM(entry);
+ memset (tmp_dirent.d_name, 0, sizeof(tmp_dirent.d_name));
+ }
+
+ /*
+ * If the entry number or the check sum do not match
+ * forget this series of long directory entries. These could
+ * be orphaned entries depending on the history of the
+ * disk.
+ */
+ if ((lfn_entries != (*MSDOS_DIR_ENTRY_TYPE(entry) &
+ MSDOS_LAST_LONG_ENTRY_MASK)) ||
+ (lfn_checksum != *MSDOS_DIR_LFN_CHECKSUM(entry)))
+ {
+ lfn_start = FAT_FILE_SHORT_NAME;
+ continue;
+ }
+
+ /*
+ * Extract the file name into the directory entry. The data is
+ * stored in UNICODE characters (16bit). No translation is
+ * currently supported.
+ *
+ * The DOS maximum length is 255 characters without the
+ * trailing nul character. We need to range check the length to
+ * fit in the directory entry name field.
+ */
+
+ lfn_entries--;
+ p = entry + 1;
+ o = lfn_entries * MSDOS_LFN_LEN_PER_ENTRY;
+
+ for (q = 0; q < MSDOS_LFN_LEN_PER_ENTRY; q++)
+ {
+ if (o >= (sizeof(tmp_dirent.d_name) - 1))
+ break;
+
+ tmp_dirent.d_name[o++] = *p;
+
+ if (*p == '\0')
+ break;
+
+ switch (q)
+ {
+ case 4:
+ p += 5;
+ break;
+ case 10:
+ p += 4;
+ break;
+ default:
+ p += 2;
+ break;
+ }
+ }
+ }
+ else
+ {
+ fat_dir_pos_t dir_pos;
+
+ /*
+ * Skip active entries until get the entry to start from.
+ */
+ if (start)
+ {
+ lfn_start = FAT_FILE_SHORT_NAME;
+ start--;
+ continue;
+ }
+
+ /*
+ * Move the entry to the return buffer
+ *
+ * unfortunately there is no method to extract ino except to
+ * open fat-file descriptor :( ... so, open it
+ */
+
+ /* get number of cluster we are working with */
+ rc = fat_file_ioctl(iop->pathinfo.mt_entry, fat_fd, F_CLU_NUM,
+ j * bts2rd, &cur_cln);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ fat_dir_pos_init(&dir_pos);
+ dir_pos.sname.cln = cur_cln;
+ dir_pos.sname.ofs = i;
+ rc = fat_file_open(iop->pathinfo.mt_entry, &dir_pos, &tmp_fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ /* fill in dirent structure */
+ /* XXX: from what and in what d_off should be computed ?! */
+ tmp_dirent.d_off = start + cmpltd;
+ tmp_dirent.d_reclen = sizeof(struct dirent);
+ tmp_dirent.d_ino = tmp_fat_fd->ino;
+
+ /*
+ * If a long file name check if the correct number of
+ * entries have been found and if the checksum is correct.
+ * If not return the short file name.
+ */
+ if (lfn_start != FAT_FILE_SHORT_NAME)
+ {
+ uint8_t cs = 0;
+ uint8_t* p = (uint8_t*) entry;
+ int i;
+
+ for (i = 0; i < 11; i++, p++)
+ cs = ((cs & 1) ? 0x80 : 0) + (cs >> 1) + *p;
+
+ if (lfn_entries || (lfn_checksum != cs))
+ lfn_start = FAT_FILE_SHORT_NAME;
+ }
+
+ if (lfn_start == FAT_FILE_SHORT_NAME)
+ {
+ /*
+ * convert dir entry from fixed 8+3 format (without dot)
+ * to 0..8 + 1dot + 0..3 format
+ */
+ tmp_dirent.d_namlen = msdos_format_dirent_with_dot(
+ tmp_dirent.d_name, entry); /* src text */
+ }
+ else
+ {
+ tmp_dirent.d_namlen = strlen(tmp_dirent.d_name);
+ }
+
+ memcpy(buffer + cmpltd, &tmp_dirent, sizeof(struct dirent));
+
+ iop->offset = iop->offset + sizeof(struct dirent);
+ cmpltd += (sizeof(struct dirent));
+ count -= (sizeof(struct dirent));
+
+ /* inode number extracted, close fat-file */
+ rc = fat_file_close(iop->pathinfo.mt_entry, tmp_fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+ }
+
+ if (count <= 0)
+ break;
+ }
+ j++;
+ }
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return cmpltd;
+}
+
+/* msdos_dir_write --
+ * no write for directory
+ */
+
+/* msdos_dir_lseek --
+ *
+ * This routine will behave in one of three ways based on the state of
+ * argument whence. Based on the state of its value the offset argument will
+ * be interpreted using one of the following methods:
+ *
+ * SEEK_SET - offset is the absolute byte offset from the start of the
+ * logical start of the dirent sequence that represents the
+ * directory
+ * SEEK_CUR - offset is used as the relative byte offset from the current
+ * directory position index held in the iop structure
+ * SEEK_END - N/A --> This will cause an assert.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * offset - offset
+ * whence - predefine directive
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno
+ * set apropriately).
+ */
+rtems_off64_t
+msdos_dir_lseek(rtems_libio_t *iop, rtems_off64_t offset, int whence)
+{
+ switch (whence)
+ {
+ case SEEK_SET:
+ case SEEK_CUR:
+ break;
+ /*
+ * Movement past the end of the directory via lseek is not a
+ * permitted operation
+ */
+ case SEEK_END:
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ break;
+ }
+ return RC_OK;
+}
+
+/* msdos_dir_stat --
+ *
+ * This routine will obtain the following information concerning the current
+ * directory:
+ * st_dev device id
+ * st_ino node serial number :)
+ * st_mode mode extracted from the node
+ * st_size total size in bytes
+ * st_blksize blocksize for filesystem I/O
+ * st_blocks number of blocks allocated
+ * stat_mtime time of last modification
+ *
+ * PARAMETERS:
+ * loc - this directory
+ * buf - stat buffer provided by user
+ *
+ * RETURNS:
+ * RC_OK and filled stat buffer on success, or -1 if error occured (errno
+ * set apropriately).
+ */
+int
+msdos_dir_stat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+ )
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = loc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = loc->node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ buf->st_dev = fs_info->fat.vol.dev;
+ buf->st_ino = fat_fd->ino;
+ buf->st_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
+ buf->st_rdev = 0ll;
+ buf->st_size = fat_fd->fat_file_size;
+ buf->st_blocks = fat_fd->fat_file_size >> FAT_SECTOR512_BITS;
+ buf->st_blksize = fs_info->fat.vol.bps;
+ buf->st_mtime = fat_fd->mtime;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_dir_truncate --
+ * No truncate for directory.
+ *
+ * PARAMETERS:
+ *
+ * RETURNS:
+ *
+ */
+
+/* msdos_dir_sync --
+ * The following routine does a syncronization on a MSDOS directory node.
+ * DIR_WrtTime, DIR_WrtDate and DIR_fileSize fields of 32 Bytes Directory
+ * Entry Structure should not be updated for directories, so only call
+ * to corresponding fat-file routine.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately).
+ */
+int
+msdos_dir_sync(rtems_libio_t *iop)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
+
+/* msdos_dir_chmod --
+ * Change the attributes of the directory. This currently does
+ * nothing and returns no error.
+ *
+ * PARAMETERS:
+ * pathloc - node description
+ * mode - the new mode
+ *
+ * RETURNS:
+ * RC_OK always
+ */
+int
+msdos_dir_chmod(rtems_filesystem_location_info_t *pathloc,
+ mode_t mode)
+{
+ return RC_OK;
+}
+
+/* msdos_dir_rmnod --
+ * Remove directory node.
+ *
+ * Check that this directory node is not opened as fat-file, is empty and
+ * not filesystem root node. If all this conditions met then delete.
+ *
+ * PARAMETERS:
+ * pathloc - node description
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately).
+ */
+int
+msdos_dir_rmnod(rtems_filesystem_location_info_t *parent_pathloc,
+ rtems_filesystem_location_info_t *pathloc)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = pathloc->node_access;
+ bool is_empty = false;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /*
+ * We deny attempts to delete open directory (if directory is current
+ * directory we assume it is open one)
+ */
+ if (fat_fd->links_num > 1)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ rtems_set_errno_and_return_minus_one(EBUSY);
+ }
+
+ /*
+ * You cannot remove a node that still has children
+ */
+ rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ if (!is_empty)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ rtems_set_errno_and_return_minus_one(ENOTEMPTY);
+ }
+
+ /*
+ * You cannot remove the file system root node.
+ */
+ if (pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ rtems_set_errno_and_return_minus_one(EBUSY);
+ }
+
+ /*
+ * You cannot remove a mountpoint.
+ * not used - mount() not implemenetd yet.
+ */
+
+ /* mark file removed */
+ rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos,
+ MSDOS_THIS_DIR_ENTRY_EMPTY);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ fat_file_mark_removed(pathloc->mt_entry, fat_fd);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_eval.c b/cpukit/libfs/src/dosfs/msdos_eval.c
new file mode 100644
index 0000000000..c128be8ff5
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_eval.c
@@ -0,0 +1,437 @@
+/*
+ * MSDOS evaluation routines
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_set_handlers --
+ * Set handlers for the node with specified type(i.e. handlers for file
+ * or directory).
+ *
+ * PARAMETERS:
+ * loc - node description
+ *
+ * RETURNS:
+ * None
+ */
+static void
+msdos_set_handlers(rtems_filesystem_location_info_t *loc)
+{
+ msdos_fs_info_t *fs_info = loc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = loc->node_access;
+
+ if (fat_fd->fat_file_type == FAT_DIRECTORY)
+ loc->handlers = fs_info->directory_handlers;
+ else
+ loc->handlers = fs_info->file_handlers;
+}
+
+/* msdos_eval_path --
+ *
+ * The following routine evaluate path for a node that wishes to be
+ * accessed. Structure 'pathloc' is returned with a pointer to the
+ * node to be accessed.
+ *
+ * PARAMETERS:
+ * pathname - path for evaluation
+ * flags - flags
+ * pathloc - node description (IN/OUT)
+ *
+ * RETURNS:
+ * RC_OK and filled pathloc on success, or -1 if error occured
+ * (errno set appropriately)
+ *
+ */
+int
+msdos_eval_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc
+ )
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = NULL;
+ rtems_filesystem_location_info_t newloc;
+ int i = 0;
+ int token_len = 0;
+ msdos_token_types_t type = MSDOS_CURRENT_DIR;
+ const char *token;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ if (!pathloc->node_access)
+ {
+ errno = ENOENT;
+ rc = -1;
+ goto err;
+ }
+
+ fat_fd = pathloc->node_access;
+
+ rc = fat_file_reopen(fat_fd);
+ if (rc != RC_OK)
+ goto err;
+
+ while ((type != MSDOS_NO_MORE_PATH) && (type != MSDOS_INVALID_TOKEN))
+ {
+ type = msdos_get_token(&pathname[i], pathnamelen, &token, &token_len);
+ pathnamelen -= token_len;
+ i += token_len;
+
+ fat_fd = pathloc->node_access;
+
+ switch (type)
+ {
+ case MSDOS_UP_DIR:
+ /*
+ * Only a directory can be decended into.
+ */
+ if (fat_fd->fat_file_type != FAT_DIRECTORY)
+ {
+ errno = ENOTSUP;
+ rc = -1;
+ goto error;
+ }
+
+ /*
+ * Am I at the root of this mounted filesystem?
+ */
+ if (pathloc->node_access ==
+ pathloc->mt_entry->mt_fs_root.node_access)
+ {
+ /*
+ * Am I at the root of all filesystems?
+ * XXX: MSDOS is not supposed to be base fs.
+ */
+ if (pathloc->node_access ==
+ rtems_filesystem_root.node_access)
+ {
+ break; /* Throw out the .. in this case */
+ }
+ else
+ {
+ newloc = pathloc->mt_entry->mt_point_node;
+ *pathloc = newloc;
+
+ rc = fat_file_close(pathloc->mt_entry, fat_fd);
+ if (rc != RC_OK)
+ goto err;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return (*pathloc->ops->evalpath_h)(&(pathname[i-token_len]),
+ pathnamelen + token_len,
+ flags, pathloc);
+ }
+ }
+ else
+ {
+ rc = msdos_find_name(pathloc, token, token_len);
+ if (rc != RC_OK)
+ {
+ if (rc == MSDOS_NAME_NOT_FOUND_ERR)
+ {
+ errno = ENOENT;
+ rc = -1;
+ }
+ goto error;
+ }
+ }
+ break;
+
+ case MSDOS_NAME:
+ /*
+ * Only a directory can be decended into.
+ */
+ if (fat_fd->fat_file_type != FAT_DIRECTORY)
+ {
+ errno = ENOTSUP;
+ rc = -1;
+ goto error;
+ }
+
+ /*
+ * Otherwise find the token name in the present location and
+ * set the node access to the point we have found.
+ */
+ rc = msdos_find_name(pathloc, token, token_len);
+ if (rc != RC_OK)
+ {
+ if (rc == MSDOS_NAME_NOT_FOUND_ERR)
+ {
+ errno = ENOENT;
+ rc = -1;
+ }
+ goto error;
+ }
+ break;
+
+ case MSDOS_NO_MORE_PATH:
+ case MSDOS_CURRENT_DIR:
+ break;
+
+ case MSDOS_INVALID_TOKEN:
+ errno = ENAMETOOLONG;
+ rc = -1;
+ goto error;
+ break;
+
+ }
+ }
+
+ /*
+ * Always return the root node.
+ *
+ * If we are at a node that is a mount point. Set loc to the
+ * new fs root node and let let the mounted filesystem set the handlers.
+ *
+ * NOTE: The behavior of stat() on a mount point appears to be
+ * questionable.
+ * NOTE: MSDOS filesystem currently doesn't support mount functionality ->
+ * action not implemented
+ */
+ fat_fd = pathloc->node_access;
+
+ msdos_set_handlers(pathloc);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+
+error:
+ fat_file_close(pathloc->mt_entry, fat_fd);
+
+err:
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
+
+/* msdos_eval4make --
+ * The following routine evaluate path for a new node to be created.
+ * 'pathloc' is returned with a pointer to the parent of the new node.
+ * 'name' is returned with a pointer to the first character in the
+ * new node name. The parent node is verified to be a directory.
+ *
+ * PARAMETERS:
+ * path - path for evaluation
+ * pathloc - IN/OUT (start point for evaluation/parent directory for
+ * creation)
+ * name - new node name
+ *
+ * RETURNS:
+ * RC_OK, filled pathloc for parent directory and name of new node on
+ * success, or -1 if error occured (errno set appropriately)
+ */
+int
+msdos_eval4make(
+ const char *path,
+ rtems_filesystem_location_info_t *pathloc,
+ const char **name
+ )
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = NULL;
+ rtems_filesystem_location_info_t newloc;
+ msdos_token_types_t type;
+ int i = 0;
+ int token_len;
+ const char *token;
+ bool done = false;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ if (!pathloc->node_access)
+ {
+ errno = ENOENT;
+ rc = -1;
+ goto err;
+ }
+
+ fat_fd = pathloc->node_access;
+
+ rc = fat_file_reopen(fat_fd);
+ if (rc != RC_OK)
+ goto err;
+
+ while (!done)
+ {
+ type = msdos_get_token(&path[i], strlen(&path[i]), &token, &token_len);
+ i += token_len;
+ fat_fd = pathloc->node_access;
+
+ switch (type)
+ {
+ case MSDOS_UP_DIR:
+ /*
+ * Only a directory can be decended into.
+ */
+ if (fat_fd->fat_file_type != FAT_DIRECTORY)
+ {
+ errno = ENOTDIR;
+ rc = -1;
+ goto error;
+ }
+
+ /*
+ * Am I at the root of this mounted filesystem?
+ */
+ if (pathloc->node_access ==
+ pathloc->mt_entry->mt_fs_root.node_access)
+ {
+ /*
+ * Am I at the root of all filesystems?
+ * XXX: MSDOS is not supposed to be base fs.
+ */
+ if (pathloc->node_access ==
+ rtems_filesystem_root.node_access)
+ {
+ break; /* Throw out the .. in this case */
+ }
+ else
+ {
+ newloc = pathloc->mt_entry->mt_point_node;
+ *pathloc = newloc;
+
+ rc = fat_file_close(pathloc->mt_entry, fat_fd);
+ if (rc != RC_OK)
+ goto err;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return (*pathloc->ops->evalformake_h)(&path[i-token_len],
+ pathloc, name);
+ }
+ }
+ else
+ {
+ rc = msdos_find_name(pathloc, token, token_len);
+ if (rc != RC_OK)
+ {
+ if (rc == MSDOS_NAME_NOT_FOUND_ERR)
+ {
+ errno = ENOENT;
+ rc = -1;
+ }
+ goto error;
+ }
+ }
+ break;
+
+ case MSDOS_NAME:
+ /*
+ * Only a directory can be decended into.
+ */
+ if (fat_fd->fat_file_type != FAT_DIRECTORY)
+ {
+ errno = ENOTDIR;
+ rc = -1;
+ goto error;
+ }
+
+ /*
+ * Otherwise find the token name in the present location and
+ * set the node access to the point we have found.
+ */
+ rc = msdos_find_name(pathloc, token, token_len);
+ if (rc)
+ {
+ if (rc != MSDOS_NAME_NOT_FOUND_ERR)
+ {
+ errno = ENOENT;
+ rc = -1;
+ goto error;
+ }
+ else
+ done = true;
+ }
+ break;
+
+ case MSDOS_NO_MORE_PATH:
+ errno = EEXIST;
+ rc = -1;
+ goto error;
+ break;
+
+ case MSDOS_CURRENT_DIR:
+ break;
+
+ case MSDOS_INVALID_TOKEN:
+ errno = ENAMETOOLONG;
+ rc = -1;
+ goto error;
+ break;
+
+ }
+ }
+
+ *name = &path[i - token_len];
+
+ /*
+ * We have evaluated the path as far as we can.
+ * Verify there is not any invalid stuff at the end of the name.
+ */
+ for( ; path[i] != '\0'; i++)
+ {
+ if (!msdos_is_separator(path[i]))
+ {
+ errno = ENOENT;
+ rc = -1;
+ goto error;
+ }
+ }
+
+ fat_fd = pathloc->node_access;
+
+ if (fat_fd->fat_file_type != FAT_DIRECTORY)
+ {
+ errno = ENOTDIR;
+ rc = -1;
+ goto error;
+ }
+
+ msdos_set_handlers(pathloc);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+
+error:
+ fat_file_close(pathloc->mt_entry, fat_fd);
+
+err:
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c
new file mode 100644
index 0000000000..0b05296df9
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_file.c
@@ -0,0 +1,503 @@
+/*
+ * MSDOS file handlers implementation
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_file_open --
+ * Open fat-file which correspondes to the file
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * pathname - name
+ * flag - flags
+ * mode - mode
+ *
+ * RETURNS:
+ * RC_OK, if file opened successfully, or -1 if error occured
+ * and errno set appropriately
+ */
+int
+msdos_file_open(rtems_libio_t *iop, const char *pathname, uint32_t flag,
+ uint32_t mode)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ rc = fat_file_reopen(fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ if (iop->flags & LIBIO_FLAGS_APPEND)
+ iop->offset = fat_fd->fat_file_size;
+
+ iop->size = fat_fd->fat_file_size;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_file_close --
+ * Close fat-file which correspondes to the file. If fat-file descriptor
+ * which correspondes to the file is not marked "removed", synchronize
+ * size, first cluster number, write time and date fields of the file.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ *
+ * RETURNS:
+ * RC_OK, if file closed successfully, or -1 if error occured (errno set
+ * appropriately)
+ */
+int
+msdos_file_close(rtems_libio_t *iop)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /*
+ * if fat-file descriptor is not marked as "removed", synchronize
+ * size, first cluster number, write time and date fields of the file
+ */
+ if (!FAT_FILE_IS_REMOVED(fat_fd))
+ {
+ rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+ }
+
+ rc = fat_file_close(iop->pathinfo.mt_entry, fat_fd);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
+
+/* msdos_file_read --
+ * This routine read from file pointed to by file control block into
+ * the specified data buffer provided by user
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * buffer - buffer provided by user
+ * count - the number of bytes to read
+ *
+ * RETURNS:
+ * the number of bytes read on success, or -1 if error occured (errno set
+ * appropriately)
+ */
+ssize_t
+msdos_file_read(rtems_libio_t *iop, void *buffer, size_t count)
+{
+ ssize_t ret = 0;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, iop->offset, count,
+ buffer);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return ret;
+}
+
+/* msdos_file_write --
+ * This routine writes the specified data buffer into the file pointed to
+ * by file control block.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * buffer - data to write
+ * count - count of bytes to write
+ *
+ * RETURNS:
+ * the number of bytes written on success, or -1 if error occured
+ * and errno set appropriately
+ */
+ssize_t
+msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
+{
+ ssize_t ret = 0;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ ret = fat_file_write(iop->pathinfo.mt_entry, fat_fd, iop->offset, count,
+ buffer);
+ if (ret < 0)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return -1;
+ }
+
+ /*
+ * update file size in both fat-file descriptor and file control block if
+ * file was extended
+ */
+ if (iop->offset + ret > fat_fd->fat_file_size)
+ fat_fd->fat_file_size = iop->offset + ret;
+
+ iop->size = fat_fd->fat_file_size;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return ret;
+}
+
+/* msdos_file_lseek --
+ * Process lseek call to the file: extend file if lseek is up to the end
+ * of the file.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * offset - new offset
+ * whence - predefine directive
+ *
+ * RETURNS:
+ * new offset on success, or -1 if error occured (errno set
+ * appropriately).
+ */
+rtems_off64_t
+msdos_file_lseek(rtems_libio_t *iop, rtems_off64_t offset, int whence)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+ uint32_t real_size = 0;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ rc = fat_file_extend(iop->pathinfo.mt_entry, fat_fd, iop->offset,
+ &real_size);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ if (real_size > fat_fd->fat_file_size)
+ fat_fd->fat_file_size = iop->offset = real_size;
+
+ iop->size = fat_fd->fat_file_size;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return iop->offset;
+}
+
+/* msdos_file_stat --
+ *
+ * PARAMETERS:
+ * loc - node description
+ * buf - stat buffer provided by user
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+msdos_file_stat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+ )
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = loc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = loc->node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ buf->st_dev = fs_info->fat.vol.dev;
+ buf->st_ino = fat_fd->ino;
+ buf->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
+ buf->st_rdev = 0ll;
+ buf->st_size = fat_fd->fat_file_size;
+ buf->st_blocks = fat_fd->fat_file_size >> FAT_SECTOR512_BITS;
+ buf->st_blksize = fs_info->fat.vol.bps;
+ buf->st_mtime = fat_fd->mtime;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_file_ftruncate --
+ * Truncate the file (if new length is greater then current do nothing).
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * length - new length
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately).
+ */
+int
+msdos_file_ftruncate(rtems_libio_t *iop, rtems_off64_t length)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+
+ if (length >= fat_fd->fat_file_size)
+ return RC_OK;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ rc = fat_file_truncate(iop->pathinfo.mt_entry, fat_fd, length);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ /*
+ * fat_file_truncate do nothing if new length >= fat-file size, so update
+ * file size only if length < fat-file size
+ */
+ if (length < fat_fd->fat_file_size)
+ iop->size = fat_fd->fat_file_size = length;
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_file_sync --
+ * Synchronize file - synchronize file data and if file is not removed
+ * synchronize file metadata.
+ *
+ * PARAMETERS:
+ * iop - file control block
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+msdos_file_sync(rtems_libio_t *iop)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /* synchronize file data */
+ rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ /*
+ * if fat-file descriptor is not marked "removed" - synchronize file
+ * metadata
+ */
+ if (!FAT_FILE_IS_REMOVED(fat_fd))
+ {
+ rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+ rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+ rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+ }
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+/* msdos_file_datasync --
+ * Synchronize file - synchronize only file data (metadata is letf intact).
+ *
+ * PARAMETERS:
+ * iop - file control block
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+msdos_file_datasync(rtems_libio_t *iop)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
+ msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /* synchronize file data */
+ rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
+
+
+/* msdos_file_ioctl --
+ *
+ *
+ * PARAMETERS:
+ * iop - file control block
+ * ...
+ *
+ * RETURNS:
+ *
+ */
+int
+msdos_file_ioctl(rtems_libio_t *iop,uint32_t command, void *buffer)
+{
+ int rc = RC_OK;
+
+ return rc;
+}
+
+/* msdos_file_chmod --
+ * Change the attributes of the file. This currently does
+ * nothing and returns no error.
+ *
+ * PARAMETERS:
+ * pathloc - node description
+ * mode - the new mode
+ *
+ * RETURNS:
+ * RC_OK always
+ */
+int
+msdos_file_chmod(rtems_filesystem_location_info_t *pathloc,
+ mode_t mode)
+{
+ return RC_OK;
+}
+
+/* msdos_file_rmnod --
+ * Remove node associated with a file - set up first name character to
+ * predefined value(and write it to the disk), and mark fat-file which
+ * correspondes to the file as "removed"
+ *
+ * PARAMETERS:
+ * pathloc - node description
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+msdos_file_rmnod(rtems_filesystem_location_info_t *parent_pathloc,
+ rtems_filesystem_location_info_t *pathloc)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = pathloc->node_access;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /* mark file removed */
+ rc = msdos_set_first_char4file_name(pathloc->mt_entry,
+ &fat_fd->dir_pos,
+ MSDOS_THIS_DIR_ENTRY_EMPTY);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ fat_file_mark_removed(pathloc->mt_entry, fat_fd);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return RC_OK;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_format.c b/cpukit/libfs/src/dosfs/msdos_format.c
new file mode 100644
index 0000000000..1394f811c4
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_format.c
@@ -0,0 +1,1127 @@
+/*===============================================================*\
+| Project: RTEMS msdos format functionality |
++-----------------------------------------------------------------+
+| File: msdos_format.c |
++-----------------------------------------------------------------+
+| Copyright (c) 2004 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file contains msdos_format function. This function |
+| formats a disk partition conforming to MS-DOS conventions |
+| |
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 29.10.04 creation doe |
+\*===============================================================*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "msdos.h"
+#include "dosfs.h"
+
+typedef struct {
+ uint32_t bytes_per_sector;
+ uint32_t totl_sector_cnt;
+ uint32_t rsvd_sector_cnt;
+
+ uint32_t sectors_per_cluster;
+ uint32_t sectors_per_fat;
+
+ uint32_t fat_start_sec;
+ uint32_t files_per_root_dir;
+ uint32_t root_dir_sectors;
+ uint32_t root_dir_start_sec;
+ uint32_t root_dir_fmt_sec_cnt;
+ uint32_t mbr_copy_sec; /* location of copy of mbr or 0 */
+ uint32_t fsinfo_sec; /* location of fsinfo sector or 0 */
+ uint8_t fat_num;
+ uint8_t media_code;
+ uint8_t fattype;
+ char OEMName[FAT_BR_OEMNAME_SIZE+1];
+ char VolLabel[FAT_BR_VOLLAB_SIZE+1];
+ bool VolLabel_present;
+ uint32_t vol_id;
+} msdos_format_param_t;
+
+/*
+ * Formatted output.
+ */
+static void
+msdos_format_printf (const msdos_format_request_param_t *rqdata,
+ int info_level,
+ const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+ if (rqdata != NULL && rqdata->info_level >= info_level)
+ {
+ vfprintf (stdout, format, args);
+ fflush (stdout);
+ }
+ va_end (args);
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_read_sec
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| function to read a sector |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int fd, /* file descriptor index */
+ uint32_t start_sector, /* sector number to write to */
+ uint32_t sector_size, /* size of sector */
+ char *buffer /* buffer with read data into */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ int ret_val = 0;
+
+ if (0 > lseek(fd,((off_t)start_sector)*sector_size,SEEK_SET)) {
+ ret_val = -1;
+ }
+ if (ret_val == 0) {
+ if (0 > read(fd,buffer,sector_size)) {
+ ret_val = -1;
+ }
+ }
+
+ return ret_val;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_write_sec
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| function to write to a sector |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int fd, /* file descriptor index */
+ uint32_t start_sector, /* sector number to write to */
+ uint32_t sector_size, /* size of sector */
+ const char *buffer /* buffer with write data */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ int ret_val = 0;
+
+ if (0 > lseek(fd,((off_t)start_sector)*sector_size,SEEK_SET)) {
+ ret_val = -1;
+ }
+ if (ret_val == 0) {
+ if (0 > write(fd,buffer,sector_size)) {
+ ret_val = -1;
+ }
+ }
+
+ return ret_val;
+}
+
+/*=========================================================================* \
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_fill_sectors
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| function to fill sectors with byte |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const msdos_format_request_param_t *rqdata,
+ int fd, /* file descriptor index */
+ uint32_t start_sector, /* sector number to fill to */
+ uint32_t sector_cnt, /* number of sectors to fill to */
+ uint32_t sector_size, /* size of sector */
+ const char fill_byte /* byte to fill into sectors */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ int ret_val = 0;
+ char *fill_buffer = NULL;
+ uint32_t total_sectors = sector_cnt;
+ int last_percent = -1;
+
+ /*
+ * allocate and fill buffer
+ */
+ if (ret_val == 0) {
+ fill_buffer = malloc(sector_size);
+ if (fill_buffer == NULL) {
+ errno = ENOMEM;
+ ret_val = -1;
+ }
+ else {
+ memset(fill_buffer,fill_byte,sector_size);
+ }
+ }
+
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "Filling : ");
+ /*
+ * write to consecutive sectors
+ */
+ while ((ret_val == 0) &&
+ (sector_cnt > 0)) {
+ int percent = (sector_cnt * 100) / total_sectors;
+ if (percent != last_percent) {
+ if ((percent & 1) == 0)
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL, ".");
+ last_percent = percent;
+ }
+ ret_val = msdos_format_write_sec(fd,start_sector,sector_size,fill_buffer);
+ start_sector++;
+ sector_cnt--;
+ }
+
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL, "\n");
+
+ if (ret_val)
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_INFO,
+ "filling error on sector: %d\n", start_sector);
+
+ /*
+ * cleanup
+ */
+ if (fill_buffer != NULL) {
+ free(fill_buffer);
+ fill_buffer = NULL;
+ }
+ return ret_val;
+}
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_gen_volid
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| function to generate a pseudo-random volume id |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ uint32_t *volid_ptr /* volume ID return pointer */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ int ret_val = 0;
+ int rc;
+ struct timeval time_value;
+
+ rc = rtems_clock_get_tod_timeval(&time_value);
+ if (rc == RTEMS_SUCCESSFUL) {
+ *volid_ptr = time_value.tv_sec + time_value.tv_sec;
+ }
+ else {
+ *volid_ptr = rand();
+ }
+
+ return ret_val;
+}
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_eval_sectors_per_cluster
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| function to check/adjust sectors_per_cluster to legal values |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int fattype, /* type code of FAT (FAT_FAT12 ...) */
+ uint32_t bytes_per_sector, /* byte count per sector (512) */
+ uint32_t fatdata_sec_cnt, /* sectors available for FAT and data */
+ uint8_t fat_num, /* number of fat copies */
+ uint32_t sectors_per_cluster, /* sectors per cluster (requested) */
+ uint32_t *sectors_per_cluster_adj, /* ret: sec per cluster (granted) */
+ uint32_t *sectors_per_fat_ptr /* ret: sectors needed for one FAT */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+
+ bool finished = false;
+ int ret_val = 0;
+ uint32_t fatdata_cluster_cnt;
+ uint32_t fat_capacity;
+ uint32_t sectors_per_fat;
+ uint32_t data_cluster_cnt;
+ /*
+ * ensure, that maximum cluster size (32KByte) is not exceeded
+ */
+ while (MS_BYTES_PER_CLUSTER_LIMIT / bytes_per_sector < sectors_per_cluster) {
+ sectors_per_cluster /= 2;
+ }
+
+ do {
+ /*
+ * compute number of data clusters for current data:
+ * - compute cluster count for data AND fat
+ * - compute storage size for FAT
+ * - subtract from total cluster count
+ */
+ fatdata_cluster_cnt = fatdata_sec_cnt/sectors_per_cluster;
+ if (fattype == FAT_FAT12) {
+ fat_capacity = fatdata_cluster_cnt * 3 / 2;
+ }
+ else if (fattype == FAT_FAT16) {
+ fat_capacity = fatdata_cluster_cnt * 2;
+ }
+ else { /* FAT32 */
+ fat_capacity = fatdata_cluster_cnt * 4;
+ }
+
+ sectors_per_fat = ((fat_capacity
+ + (bytes_per_sector - 1))
+ / bytes_per_sector);
+
+ data_cluster_cnt = (fatdata_cluster_cnt -
+ (((sectors_per_fat * fat_num)
+ + (sectors_per_cluster - 1))
+ / sectors_per_cluster));
+ /*
+ * data cluster count too big? then make sectors bigger
+ */
+ if (((fattype == FAT_FAT12) && (data_cluster_cnt > FAT_FAT12_MAX_CLN)) ||
+ ((fattype == FAT_FAT16) && (data_cluster_cnt > FAT_FAT16_MAX_CLN))) {
+ sectors_per_cluster *= 2;
+ }
+ else {
+ finished = true;
+ }
+ /*
+ * when maximum cluster size is exceeded, we have invalid data, abort...
+ */
+ if ((sectors_per_cluster * bytes_per_sector)
+ > MS_BYTES_PER_CLUSTER_LIMIT) {
+ ret_val = EINVAL;
+ finished = true;
+ }
+ } while (!finished);
+
+ if (ret_val != 0) {
+ rtems_set_errno_and_return_minus_one(ret_val);
+ }
+ else {
+ *sectors_per_cluster_adj = sectors_per_cluster;
+ *sectors_per_fat_ptr = sectors_per_fat;
+ return 0;
+ }
+}
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_determine_fmt_params
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| determine parameters for formatting |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const rtems_disk_device *dd, /* disk device structure */
+ const msdos_format_request_param_t *rqdata, /* requested fmt parameters */
+ msdos_format_param_t *fmt_params/* computed fmt parameters */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ int ret_val = 0;
+ uint32_t fatdata_sect_cnt;
+ uint32_t onebit;
+ uint32_t sectors_per_cluster_adj = 0;
+ uint64_t total_size = 0;
+
+ memset(fmt_params,0,sizeof(*fmt_params));
+ /*
+ * this one is fixed in this implementation.
+ * At least one thing we don't have to magically guess...
+ */
+ if (ret_val == 0) {
+ fmt_params->bytes_per_sector = dd->block_size;
+ fmt_params->totl_sector_cnt = dd->size;
+ total_size = dd->block_size * dd->size;
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "bytes per sector: %d\ntotal sectors: %d\ntotal size: %lu\n",
+ dd->block_size, dd->size, total_size);
+ }
+ /*
+ * determine number of FATs
+ */
+ if (ret_val == 0) {
+ if ((rqdata == NULL) ||
+ (rqdata->fat_num == 0)) {
+ fmt_params->fat_num = 2;
+ }
+ else if (rqdata->fat_num <= 6) {
+ fmt_params->fat_num = rqdata->fat_num;
+ }
+ else {
+ ret_val = EINVAL;
+ }
+ }
+
+ if (ret_val == 0)
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "number of fats: %d\n", fmt_params->fat_num);
+
+ /*
+ * Now we get sort of a loop when determining things:
+ * The FAT type (FAT12/16/32) is determined ONLY from the
+ * data cluster count:
+ * Disks with data cluster count < 4085 are FAT12.
+ * Disks with data cluster count < 65525 are FAT16.
+ * The rest is FAT32 (no FAT128 available yet :-)
+ *
+ * The number of data clusters is the
+ * total capacity
+ * minus reserved sectors
+ * minus root directory ares
+ * minus storage needed for the FAT (and its copy/copies).
+ *
+ * The last item once again depends on the FAT type and the cluster count.
+ *
+ * So here is what we do in this formatter:
+ * - If a FAT type is requested from the caller, we try to modify
+ * the cluster size, until the data cluster count is in range
+ * - If no FAT type is given, we estimate a useful FAT type from
+ * the disk capacity and then adapt the cluster size
+ */
+
+ /*
+ * determine characteristic values:
+ * - number of sectors
+ * - number of reserved sectors
+ * - number of used sectors
+ * - sectors per cluster
+ */
+ /*
+ * determine FAT type and sectors per cluster
+ * depends on
+ */
+ if (ret_val == 0) {
+ fmt_params->sectors_per_cluster = 1;
+ if ((rqdata != NULL) &&
+ (rqdata->fattype == MSDOS_FMT_FAT12)) {
+ fmt_params->fattype = FAT_FAT12;
+ }
+ else if ((rqdata != NULL) &&
+ (rqdata->fattype == MSDOS_FMT_FAT16)) {
+ fmt_params->fattype = FAT_FAT16;
+ }
+ else if ((rqdata != NULL) &&
+ (rqdata->fattype == MSDOS_FMT_FAT32)) {
+ fmt_params->fattype = FAT_FAT32;
+ }
+ else if ((rqdata != NULL) &&
+ (rqdata->fattype != MSDOS_FMT_FATANY)) {
+ ret_val = -1;
+ errno = EINVAL;
+ }
+ else {
+ /*
+ * limiting values for disk size, fat type, sectors per cluster
+ * NOTE: maximum sect_per_clust is arbitrarily choosen with values that
+ * are a compromise concerning capacity and efficency
+ */
+ if (fmt_params->totl_sector_cnt
+ < ((uint32_t)FAT_FAT12_MAX_CLN)*8) {
+ fmt_params->fattype = FAT_FAT12;
+ /* start trying with small clusters */
+ fmt_params->sectors_per_cluster = 2;
+ }
+ else if (fmt_params->totl_sector_cnt
+ < ((uint32_t)FAT_FAT16_MAX_CLN)*32) {
+ fmt_params->fattype = FAT_FAT16;
+ /* start trying with small clusters */
+ fmt_params->sectors_per_cluster = 2;
+ }
+ else {
+ #define ONE_GB (1024L * 1024L * 1024L)
+ uint32_t gigs = (total_size + ONE_GB) / ONE_GB;
+ int b;
+ fmt_params->fattype = FAT_FAT32;
+ /* scale with the size of disk... */
+ for (b = 31; b > 0; b--)
+ if ((gigs & (1 << b)) != 0)
+ break;
+ fmt_params->sectors_per_cluster = 1 << b;
+ }
+ }
+ /*
+ * try to use user requested cluster size
+ */
+ if ((rqdata != NULL) &&
+ (rqdata->sectors_per_cluster > 0)) {
+ fmt_params->sectors_per_cluster =
+ rqdata->sectors_per_cluster;
+ }
+ /*
+ * check sectors per cluster.
+ * must be power of 2
+ * must be smaller than or equal to 128
+ * sectors_per_cluster*bytes_per_sector must not be bigger than 32K
+ */
+ for (onebit = 128;onebit >= 1;onebit = onebit>>1) {
+ if (fmt_params->sectors_per_cluster >= onebit) {
+ fmt_params->sectors_per_cluster = onebit;
+ if (fmt_params->sectors_per_cluster
+ <= 32768L/fmt_params->bytes_per_sector) {
+ /* value is small enough so this value is ok */
+ onebit = 1;
+ }
+ }
+ }
+ }
+
+ if (ret_val == 0) {
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "sectors per cluster: %d\n", fmt_params->sectors_per_cluster);
+
+ if (fmt_params->fattype == FAT_FAT32) {
+ /* recommended: for FAT32, always set reserved sector count to 32 */
+ fmt_params->rsvd_sector_cnt = 32;
+ /* for FAT32, always set files per root directory 0 */
+ fmt_params->files_per_root_dir = 0;
+ /* location of copy of MBR */
+ fmt_params->mbr_copy_sec = 6;
+ /* location of fsinfo sector */
+ fmt_params->fsinfo_sec = 1;
+
+ }
+ else {
+ /* recommended: for FAT12/FAT16, always set reserved sector count to 1 */
+ fmt_params->rsvd_sector_cnt = 1;
+ /* recommended: for FAT16, set files per root directory to 512 */
+ /* for FAT12/FAT16, set files per root directory */
+ /* must fill up an even count of sectors */
+ if ((rqdata != NULL) &&
+ (rqdata->files_per_root_dir > 0)) {
+ fmt_params->files_per_root_dir = rqdata->files_per_root_dir;
+ }
+ else {
+ if (fmt_params->fattype == FAT_FAT16) {
+ fmt_params->files_per_root_dir = 512;
+ }
+ else {
+ fmt_params->files_per_root_dir = 64;
+ }
+ }
+ fmt_params->files_per_root_dir = (fmt_params->files_per_root_dir +
+ (2*fmt_params->bytes_per_sector/
+ FAT_DIRENTRY_SIZE-1));
+ fmt_params->files_per_root_dir -= (fmt_params->files_per_root_dir %
+ (2*fmt_params->bytes_per_sector
+ /FAT_DIRENTRY_SIZE));
+ }
+ fmt_params->root_dir_sectors =
+ (((fmt_params->files_per_root_dir * FAT_DIRENTRY_SIZE)
+ + fmt_params->bytes_per_sector - 1)
+ / fmt_params->bytes_per_sector);
+ }
+ if (ret_val == 0) {
+ fatdata_sect_cnt = (fmt_params->totl_sector_cnt -
+ fmt_params->rsvd_sector_cnt -
+ fmt_params->root_dir_sectors);
+
+ /*
+ * check values to get legal arrangement of FAT type and cluster count
+ */
+
+ ret_val = msdos_format_eval_sectors_per_cluster
+ (fmt_params->fattype,
+ fmt_params->bytes_per_sector,
+ fatdata_sect_cnt,
+ fmt_params->fat_num,
+ fmt_params->sectors_per_cluster,
+ &sectors_per_cluster_adj,
+ &(fmt_params->sectors_per_fat));
+ fmt_params->sectors_per_cluster = sectors_per_cluster_adj;
+ }
+
+ /*
+ * determine media code
+ */
+ if (ret_val == 0) {
+ if ((rqdata != NULL) &&
+ (rqdata->media != 0)) {
+ const char valid_media_codes[] =
+ {0xF0,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF};
+ if (NULL==memchr(valid_media_codes,
+ rqdata->media,
+ sizeof(valid_media_codes))) {
+ ret_val = -1;
+ errno = EINVAL;
+ }
+ else {
+ fmt_params->media_code = rqdata->media;
+ }
+ }
+ else {
+ fmt_params->media_code = FAT_BR_MEDIA_FIXED;
+ }
+ }
+ /*
+ * determine location and size of root directory
+ * for formatting
+ */
+ if (fmt_params->root_dir_sectors > 0) {
+ fmt_params->root_dir_start_sec =
+ fmt_params->rsvd_sector_cnt
+ + (fmt_params-> fat_num*fmt_params->sectors_per_fat);
+ fmt_params->root_dir_fmt_sec_cnt = fmt_params->root_dir_sectors;
+ }
+ else {
+ /*
+ * for FAT32: root directory is in cluster 2
+ */
+ fmt_params->root_dir_start_sec =
+ fmt_params->rsvd_sector_cnt
+ + (fmt_params-> fat_num*fmt_params->sectors_per_fat);
+ fmt_params->root_dir_fmt_sec_cnt = fmt_params->sectors_per_cluster;
+ }
+ /*
+ * determine usable OEMName
+ */
+ if (ret_val == 0) {
+ const char *from;
+ char *to = fmt_params->OEMName;
+ int cnt;
+ from = "RTEMS"; /* default: make "from" point to OS Name */
+ if ((rqdata != NULL) &&
+ (rqdata->OEMName != NULL)) {
+ from = rqdata->OEMName;
+ }
+ for (cnt = 0;
+ cnt < (sizeof(fmt_params->OEMName)-1);
+ cnt++) {
+ if (isprint((unsigned char)*from)) {
+ *to++ = *from++;
+ }
+ else {
+ /*
+ * non-printable character in given name, so keep stuck
+ * at that character and replace all following characters
+ * with a ' '
+ */
+ *to++=' ';
+ }
+ *to = '\0';
+ }
+ }
+
+ /*
+ * determine usable Volume Label
+ */
+ if (ret_val == 0) {
+ const char *from;
+ char *to = fmt_params->VolLabel;
+ int cnt;
+ from = ""; /* default: make "from" point to empty string */
+ if ((rqdata != NULL) &&
+ (rqdata->VolLabel != NULL)) {
+ from = rqdata->VolLabel;
+ fmt_params->VolLabel_present = true;
+ }
+ for (cnt = 0;
+ cnt < (sizeof(fmt_params->VolLabel)-1);
+ cnt++) {
+ if (isprint((unsigned char)*from)) {
+ *to++ = *from++;
+ }
+ else {
+ /*
+ * non-printable character in given name, so keep stuck
+ * at that character and replace all following characters
+ * with a ' '
+ */
+ *to++=' ';
+ }
+ *to = '\0';
+ }
+ }
+
+ /*
+ * determine usable Volume ID
+ */
+ if (ret_val == 0) {
+ msdos_format_gen_volid(&(fmt_params->vol_id));
+ }
+ /*
+ * Phuuu.... That's it.
+ */
+ if (ret_val != 0) {
+ rtems_set_errno_and_return_minus_one(ret_val);
+ }
+ else {
+ return 0;
+ }
+}
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_gen_mbr
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| create master boot record content from parameter set |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ char mbr[], /* sector buffer */
+ const msdos_format_param_t *fmt_params/* computed fmt parameters */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ uint32_t total_sectors_num16 = 0;
+ uint32_t total_sectors_num32 = 0;
+
+ /* store total sector count in either 16 or 32 bit field in mbr */
+ if (fmt_params->totl_sector_cnt < 0x10000) {
+ total_sectors_num16 = fmt_params->totl_sector_cnt;
+ }
+ else {
+ total_sectors_num32 = fmt_params->totl_sector_cnt;
+ }
+ /*
+ * finally we are there: let's fill in the values into the MBR
+ * but first clear the MRB leaving the partition table.
+ */
+#define RTEMS_IDE_PARTITION_TABLE_OFFSET 0x1be
+#define RTEMS_IDE_PARTITION_TABLE_SIZE (4 * 16)
+ memset(mbr,0,RTEMS_IDE_PARTITION_TABLE_OFFSET);
+ memset(mbr + RTEMS_IDE_PARTITION_TABLE_OFFSET + RTEMS_IDE_PARTITION_TABLE_SIZE,
+ 0,
+ FAT_TOTAL_MBR_SIZE - (RTEMS_IDE_PARTITION_TABLE_OFFSET + RTEMS_IDE_PARTITION_TABLE_SIZE));
+ /*
+ * FIXME: fill jmpBoot and Boot code...
+ * with 0xEB,....
+ */
+ /*
+ * fill OEMName
+ */
+ memcpy(FAT_GET_ADDR_BR_OEMNAME(mbr),
+ fmt_params->OEMName,
+ FAT_BR_OEMNAME_SIZE);
+ FAT_SET_BR_BYTES_PER_SECTOR(mbr , fmt_params->bytes_per_sector);
+ FAT_SET_BR_SECTORS_PER_CLUSTER(mbr , fmt_params->sectors_per_cluster);
+ FAT_SET_BR_RESERVED_SECTORS_NUM(mbr, fmt_params->rsvd_sector_cnt);
+
+ /* number of FATs on medium */
+ FAT_SET_BR_FAT_NUM(mbr , 2); /* standard/recommended value */
+ FAT_SET_BR_FILES_PER_ROOT_DIR(mbr , fmt_params->files_per_root_dir);
+ FAT_SET_BR_TOTAL_SECTORS_NUM16(mbr , total_sectors_num16);
+ FAT_SET_BR_MEDIA(mbr , fmt_params->media_code);
+
+ FAT_SET_BR_SECTORS_PER_TRACK(mbr , 255); /* only needed for INT13... */
+ FAT_SET_BR_NUMBER_OF_HEADS(mbr , 6); /* only needed for INT13... */
+ FAT_SET_BR_HIDDEN_SECTORS(mbr , 1); /* only needed for INT13... */
+
+ FAT_SET_BR_TOTAL_SECTORS_NUM32(mbr , total_sectors_num32);
+ if (fmt_params->fattype != FAT_FAT32) {
+ FAT_SET_BR_SECTORS_PER_FAT(mbr ,fmt_params->sectors_per_fat);
+ FAT_SET_BR_DRVNUM(mbr , 0); /* only needed for INT13... */
+ FAT_SET_BR_RSVD1(mbr , 0); /* fill with zero */
+ FAT_SET_BR_BOOTSIG(mbr , FAT_BR_BOOTSIG_VAL);
+ FAT_SET_BR_VOLID(mbr , fmt_params->vol_id); /* volume id */
+ memcpy(FAT_GET_ADDR_BR_VOLLAB(mbr),
+ fmt_params->VolLabel,
+ FAT_BR_VOLLAB_SIZE);
+ memcpy(FAT_GET_ADDR_BR_FILSYSTYPE(mbr),
+ (fmt_params->fattype == FAT_FAT12)
+ ? "FAT12 "
+ : "FAT16 ",
+ FAT_BR_FILSYSTYPE_SIZE);
+ }
+ else {
+ FAT_SET_BR_SECTORS_PER_FAT32(mbr ,fmt_params->sectors_per_fat);
+ FAT_SET_BR_EXT_FLAGS(mbr , 0);
+ FAT_SET_BR_FSVER(mbr , 0); /* FAT32 Version:0.0 */
+ FAT_SET_BR_FAT32_ROOT_CLUSTER(mbr , 2); /* put root dir to cluster 2 */
+ FAT_SET_BR_FAT32_FS_INFO_SECTOR(mbr, 1); /* Put fsinfo to rsrvd sec 1*/
+ FAT_SET_BR_FAT32_BK_BOOT_SECTOR(mbr, fmt_params->mbr_copy_sec ); /* Put MBR copy to rsrvd sec */
+ memset(FAT_GET_ADDR_BR_FAT32_RESERVED(mbr),0,FAT_BR_FAT32_RESERVED_SIZE);
+
+ FAT_SET_BR_FAT32_DRVNUM(mbr , 0); /* only needed for INT13... */
+ FAT_SET_BR_FAT32_RSVD1(mbr , 0); /* fill with zero */
+ FAT_SET_BR_FAT32_BOOTSIG(mbr ,FAT_BR_FAT32_BOOTSIG_VAL);
+ FAT_SET_BR_FAT32_VOLID(mbr , 0); /* not set */
+ memset(FAT_GET_ADDR_BR_FAT32_VOLLAB(mbr) ,0,FAT_BR_VOLLAB_SIZE);
+ memcpy(FAT_GET_ADDR_BR_FAT32_FILSYSTYPE(mbr),
+ "FAT32 ",
+ FAT_BR_FILSYSTYPE_SIZE);
+ }
+ /*
+ * add boot record signature
+ */
+ FAT_SET_BR_SIGNATURE(mbr, FAT_BR_SIGNATURE_VAL);
+
+ /*
+ * add jump to boot loader at start of sector
+ */
+ FAT_SET_VAL8(mbr,0,0xeb);
+ FAT_SET_VAL8(mbr,1,0x3c);
+ FAT_SET_VAL8(mbr,2,0x90);
+ /*
+ * FIXME: a nice little PC boot loader would be nice here.
+ * but where can I get one for free?
+ */
+ /*
+ * Phuuu.... That's it.
+ */
+ return 0;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+static int msdos_format_gen_fsinfo
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| create FAT32 fsinfo sector |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ char fsinfo[] /* sector buffer */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ /*
+ * clear fsinfo sector data
+ */
+ memset(fsinfo,0,FAT_TOTAL_FSINFO_SIZE);
+ /*
+ * write LEADSIG, STRUCTSIG, TRAILSIG
+ */
+ FAT_SET_FSINFO_LEAD_SIGNATURE (fsinfo,FAT_FSINFO_LEAD_SIGNATURE_VALUE );
+ FAT_SET_FSINFO_STRUC_SIGNATURE(fsinfo,FAT_FSINFO_STRUC_SIGNATURE_VALUE);
+ FAT_SET_FSINFO_TRAIL_SIGNATURE(fsinfo,FAT_FSINFO_TRAIL_SIGNATURE_VALUE);
+ /*
+ * write "empty" values for free cluster count and next cluster number
+ */
+ FAT_SET_FSINFO_FREE_CLUSTER_COUNT(fsinfo+FAT_FSI_INFO,
+ 0xffffffff);
+ FAT_SET_FSINFO_NEXT_FREE_CLUSTER (fsinfo+FAT_FSI_INFO,
+ 0xffffffff);
+ return 0;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int msdos_format
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| format device with msdos filesystem |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const char *devname, /* device name */
+ const msdos_format_request_param_t *rqdata /* requested fmt parameters */
+ /* set to NULL for automatic */
+ /* determination */
+ )
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0, if success, -1 and errno if failed |
+\*=========================================================================*/
+{
+ char tmp_sec[FAT_TOTAL_MBR_SIZE];
+ int rc;
+ rtems_disk_device *dd = NULL;
+ struct stat stat_buf;
+ int ret_val = 0;
+ int fd = -1;
+ int i;
+ msdos_format_param_t fmt_params;
+
+ /*
+ * open device for writing
+ */
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL, "open device\n");
+ fd = open(devname, O_RDWR);
+ if (fd == -1) {
+ ret_val= -1;
+ }
+
+ /*
+ * sanity check on device
+ */
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "stat check: %s\n", devname);
+ if (ret_val == 0) {
+ rc = fstat(fd, &stat_buf);
+ ret_val = rc;
+ }
+
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_INFO,
+ "formating: %s\n", devname);
+ /* rtems feature: no block devices, all are character devices */
+ if ((ret_val == 0) && (!S_ISBLK(stat_buf.st_mode))) {
+ errno = ENOTTY;
+ ret_val = -1;
+ }
+
+ /* check that device is registered as block device and lock it */
+ if (ret_val == 0) {
+ dd = rtems_disk_obtain(stat_buf.st_rdev);
+ if (dd == NULL) {
+ errno = ENOTTY;
+ ret_val = -1;
+ }
+ }
+
+ /*
+ * compute formatting parameters
+ */
+ if (ret_val == 0) {
+ ret_val = msdos_format_determine_fmt_params(dd,rqdata,&fmt_params);
+ }
+ /*
+ * if requested, write whole disk/partition with 0xe5
+ */
+ if ((ret_val == 0) &&
+ (rqdata != NULL) &&
+ !(rqdata->quick_format)) {
+ ret_val = msdos_format_fill_sectors
+ (rqdata,
+ fd,
+ 0, /* start sector */
+ fmt_params.totl_sector_cnt, /* sector count */
+ fmt_params.bytes_per_sector,
+ 0xe5);
+ }
+
+ /*
+ * create master boot record
+ */
+ if (ret_val == 0) {
+ /*
+ * Read the current MBR to obtain the partition table.
+ */
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "read MRB sector\n");
+ ret_val = msdos_format_read_sec(fd,
+ 0,
+ fmt_params.bytes_per_sector,
+ tmp_sec);
+ if (ret_val == 0) {
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "generate MRB sector\n");
+ ret_val = msdos_format_gen_mbr(tmp_sec,&fmt_params);
+ }
+
+ /*
+ * write master boot record to disk
+ * also write copy of MBR to disk
+ */
+ if (ret_val == 0) {
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "write MRB sector\n");
+ ret_val = msdos_format_write_sec(fd,
+ 0,
+ fmt_params.bytes_per_sector,
+ tmp_sec);
+ }
+ if ((ret_val == 0) &&
+ (fmt_params.mbr_copy_sec != 0)) {
+ /*
+ * write copy of MBR
+ */
+ msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
+ "write back up MRB sector\n");
+ ret_val = msdos_format_write_sec(fd,
+ fmt_params.mbr_copy_sec ,
+ fmt_params.bytes_per_sector,
+ tmp_sec);
+ }
+ }
+ /*
+ * for FAT32: initialize info sector on disk
+ */
+ if ((ret_val == 0) &&
+ (fmt_params.fsinfo_sec != 0)) {
+ ret_val = msdos_format_gen_fsinfo(tmp_sec);
+ }
+ /*
+ * write fsinfo sector
+ */
+ if ((ret_val == 0) &&
+ (fmt_params.fsinfo_sec != 0)) {
+ ret_val = msdos_format_write_sec(fd,
+ fmt_params.fsinfo_sec,
+ fmt_params.bytes_per_sector,
+ tmp_sec);
+ }
+ /*
+ * write FAT as all empty
+ * -> write all FAT sectors as zero
+ */
+ if (ret_val == 0) {
+ ret_val = msdos_format_fill_sectors
+ (rqdata,
+ fd,
+ fmt_params.rsvd_sector_cnt, /* start sector */
+ fmt_params.fat_num*fmt_params.sectors_per_fat,/* sector count */
+ fmt_params.bytes_per_sector,
+ 0x00);
+ }
+ /*
+ * clear/init root directory
+ * -> write all directory sectors as 0x00
+ */
+ if (ret_val == 0) {
+ ret_val = msdos_format_fill_sectors
+ (rqdata,
+ fd,
+ fmt_params.root_dir_start_sec, /* start sector */
+ fmt_params.root_dir_fmt_sec_cnt, /* sector count */
+ fmt_params.bytes_per_sector,
+ 0x00);
+ }
+ /*
+ * write volume label to first entry of directory
+ */
+ if ((ret_val == 0) && fmt_params.VolLabel_present) {
+ memset(tmp_sec,0,sizeof(tmp_sec));
+ memcpy(MSDOS_DIR_NAME(tmp_sec),fmt_params.VolLabel,MSDOS_SHORT_NAME_LEN);
+ *MSDOS_DIR_ATTR(tmp_sec) = MSDOS_ATTR_VOLUME_ID;
+ ret_val = msdos_format_write_sec
+ (fd,
+ fmt_params.root_dir_start_sec,
+ fmt_params.bytes_per_sector,
+ tmp_sec);
+ }
+ /*
+ * write FAT entry 0 as (0xffffff00|Media_type)EOC,
+ * write FAT entry 1 as EOC
+ * allocate directory in a FAT32 FS
+ */
+ if ((ret_val == 0) && fmt_params.VolLabel_present){
+ /*
+ * empty sector: all clusters are free/do not link further on
+ */
+ memset(tmp_sec,0,sizeof(tmp_sec));
+
+ switch(fmt_params.fattype) {
+ case FAT_FAT12:
+ /* LSBits of FAT entry 0: media_type */
+ FAT_SET_VAL8(tmp_sec,0,(fmt_params.media_code));
+ /* MSBits of FAT entry 0:0xf, LSBits of FAT entry 1: LSB of EOC */
+ FAT_SET_VAL8(tmp_sec,1,(0x0f | (FAT_FAT12_EOC << 4)));
+ /* MSBits of FAT entry 1: MSBits of EOC */
+ FAT_SET_VAL8(tmp_sec,2,(FAT_FAT12_EOC >> 4));
+ break;
+
+ case FAT_FAT16:
+ /* FAT entry 0: 0xff00|media_type */
+ FAT_SET_VAL8(tmp_sec,0,fmt_params.media_code);
+ FAT_SET_VAL8(tmp_sec,1,0xff);
+ /* FAT entry 1: EOC */
+ FAT_SET_VAL16(tmp_sec,2,FAT_FAT16_EOC);
+ break;
+
+ case FAT_FAT32:
+ /* FAT entry 0: 0xffffff00|media_type */
+ FAT_SET_VAL32(tmp_sec,0,0xffffff00|fmt_params.media_code);
+ /* FAT entry 1: EOC */
+ FAT_SET_VAL32(tmp_sec,4,FAT_FAT32_EOC);
+ break;
+
+ default:
+ ret_val = -1;
+ errno = EINVAL;
+ }
+ if (fmt_params.fattype == FAT_FAT32) {
+ /*
+ * only first valid cluster (cluster number 2) belongs
+ * to root directory, and is end of chain
+ * mark this in every copy of the FAT
+ */
+ FAT_SET_VAL32(tmp_sec,8,FAT_FAT32_EOC);
+ }
+ for (i = 0;
+ (i < fmt_params.fat_num) && (ret_val == 0);
+ i++) {
+ ret_val = msdos_format_write_sec
+ (fd,
+ fmt_params.rsvd_sector_cnt
+ + (i * fmt_params.sectors_per_fat),
+ fmt_params.bytes_per_sector,
+ tmp_sec);
+ }
+ }
+ /*
+ * cleanup:
+ * sync and unlock disk
+ * free any data structures (not needed now)
+ */
+ if (fd != -1) {
+ close(fd);
+ }
+ if (dd != NULL) {
+ rtems_disk_release(dd);
+ }
+ return ret_val;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_free.c b/cpukit/libfs/src/dosfs/msdos_free.c
new file mode 100644
index 0000000000..90fc586a10
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_free.c
@@ -0,0 +1,56 @@
+/*
+ * Free node handler implementation for the filesystem
+ * operations table.
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include <errno.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_free_node_info --
+ * Call fat-file close routine.
+ *
+ * PARAMETERS:
+ * pathloc - node description
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 code if error occured
+ *
+ */
+int
+msdos_free_node_info(rtems_filesystem_location_info_t *pathloc)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ rc = fat_file_close(pathloc->mt_entry, pathloc->node_access);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_fsunmount.c b/cpukit/libfs/src/dosfs/msdos_fsunmount.c
new file mode 100644
index 0000000000..310da9c8ff
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_fsunmount.c
@@ -0,0 +1,70 @@
+/*
+ * MSDOS shut down handler implementation
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_shut_down --
+ * Shut down MSDOS filesystem - free all allocated resources (don't
+ * return if deallocation of some resource failed - free as much as
+ * possible).
+ *
+ * PARAMETERS:
+ * temp_mt_entry - mount table entry
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately).
+ *
+ */
+int
+msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry)
+{
+ int rc = RC_OK;
+ msdos_fs_info_t *fs_info = temp_mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = temp_mt_entry->mt_fs_root.node_access;
+
+ /* close fat-file which correspondes to root directory */
+ if (fat_file_close(temp_mt_entry, fat_fd) != RC_OK)
+ {
+ /* no return - try to free as much as possible */
+ rc = -1;
+ }
+
+ if (fat_shutdown_drive(temp_mt_entry) != RC_OK)
+ {
+ /* no return - try to free as much as possible */
+ rc = -1;
+ }
+
+ rtems_semaphore_delete(fs_info->vol_sema);
+ free(fs_info->cl_buf);
+ free(temp_mt_entry->fs_info);
+
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_handlers_dir.c b/cpukit/libfs/src/dosfs/msdos_handlers_dir.c
new file mode 100644
index 0000000000..cc32af86d4
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_handlers_dir.c
@@ -0,0 +1,36 @@
+/*
+ * Directory Handlers Table for MSDOS filesystem
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio.h>
+#include "msdos.h"
+
+const rtems_filesystem_file_handlers_r msdos_dir_handlers = {
+ msdos_dir_open,
+ msdos_dir_close,
+ msdos_dir_read,
+ rtems_filesystem_default_write,
+ rtems_filesystem_default_ioctl,
+ msdos_dir_lseek,
+ msdos_dir_stat,
+ msdos_dir_chmod,
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ msdos_dir_sync,
+ msdos_dir_sync,
+ rtems_filesystem_default_fcntl,
+ msdos_dir_rmnod
+};
diff --git a/cpukit/libfs/src/dosfs/msdos_handlers_file.c b/cpukit/libfs/src/dosfs/msdos_handlers_file.c
new file mode 100644
index 0000000000..18d4fdd018
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_handlers_file.c
@@ -0,0 +1,36 @@
+/*
+ * File Operations Table for MSDOS filesystem
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio.h>
+#include "msdos.h"
+
+const rtems_filesystem_file_handlers_r msdos_file_handlers = {
+ msdos_file_open,
+ msdos_file_close,
+ msdos_file_read,
+ msdos_file_write,
+ msdos_file_ioctl,
+ msdos_file_lseek,
+ msdos_file_stat,
+ msdos_file_chmod,
+ msdos_file_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ msdos_file_sync,
+ msdos_file_datasync,
+ rtems_filesystem_default_fcntl,
+ msdos_file_rmnod
+};
diff --git a/cpukit/libfs/src/dosfs/msdos_init.c b/cpukit/libfs/src/dosfs/msdos_init.c
new file mode 100644
index 0000000000..217e0c1f3a
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_init.c
@@ -0,0 +1,64 @@
+/*
+ * Init routine for MSDOS
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include "dosfs.h"
+#include "msdos.h"
+
+const rtems_filesystem_operations_table msdos_ops = {
+ .evalpath_h = msdos_eval_path,
+ .evalformake_h = msdos_eval4make,
+ .link_h = rtems_filesystem_default_link,
+ .unlink_h = msdos_file_rmnod,
+ .node_type_h = msdos_node_type,
+ .mknod_h = msdos_mknod,
+ .chown_h = rtems_filesystem_default_chown,
+ .freenod_h = msdos_free_node_info,
+ .mount_h = rtems_filesystem_default_mount,
+ .fsmount_me_h = rtems_dosfs_initialize,
+ .unmount_h = rtems_filesystem_default_unmount,
+ .fsunmount_me_h = msdos_shut_down,
+ .utime_h = rtems_filesystem_default_utime,
+ .eval_link_h = rtems_filesystem_default_evaluate_link,
+ .symlink_h = rtems_filesystem_default_symlink,
+ .readlink_h = rtems_filesystem_default_readlink,
+ .rename_h = msdos_rename,
+ .statvfs_h = rtems_filesystem_default_statvfs
+};
+
+/* msdos_initialize --
+ * MSDOS filesystem initialization. Called when mounting an
+ * MSDOS filesystem.
+ *
+ * PARAMETERS:
+ * temp_mt_entry - mount table entry
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately).
+ *
+ */
+int rtems_dosfs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data)
+{
+ int rc;
+
+ rc = msdos_initialize_support(mt_entry,
+ &msdos_ops,
+ &msdos_file_handlers,
+ &msdos_dir_handlers);
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_initsupp.c b/cpukit/libfs/src/dosfs/msdos_initsupp.c
new file mode 100644
index 0000000000..fc10fda71a
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_initsupp.c
@@ -0,0 +1,149 @@
+/*
+ * MSDOS Initialization support routine implementation
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_initialize_support --
+ * MSDOS filesystem initialization
+ *
+ * PARAMETERS:
+ * temp_mt_entry - mount table entry
+ * op_table - filesystem operations table
+ * file_handlers - file operations table
+ * directory_handlers - directory operations table
+ *
+ * RETURNS:
+ * RC_OK and filled temp_mt_entry on success, or -1 if error occured
+ * (errno set apropriately)
+ *
+ */
+int
+msdos_initialize_support(
+ rtems_filesystem_mount_table_entry_t *temp_mt_entry,
+ const rtems_filesystem_operations_table *op_table,
+ const rtems_filesystem_file_handlers_r *file_handlers,
+ const rtems_filesystem_file_handlers_r *directory_handlers
+ )
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = NULL;
+ fat_file_fd_t *fat_fd = NULL;
+ fat_dir_pos_t root_pos;
+ uint32_t cl_buf_size;
+
+ fs_info = (msdos_fs_info_t *)calloc(1, sizeof(msdos_fs_info_t));
+ if (!fs_info)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+
+ temp_mt_entry->fs_info = fs_info;
+
+ rc = fat_init_volume_info(temp_mt_entry);
+ if (rc != RC_OK)
+ {
+ free(fs_info);
+ return rc;
+ }
+
+ fs_info->file_handlers = file_handlers;
+ fs_info->directory_handlers = directory_handlers;
+
+ /*
+ * open fat-file which correspondes to root directory
+ * (so inode number 0x00000010 is always used for root directory)
+ */
+ fat_dir_pos_init(&root_pos);
+ root_pos.sname.cln = FAT_ROOTDIR_CLUSTER_NUM;
+ rc = fat_file_open(temp_mt_entry, &root_pos, &fat_fd);
+ if (rc != RC_OK)
+ {
+ fat_shutdown_drive(temp_mt_entry);
+ free(fs_info);
+ return rc;
+ }
+
+ /* again: unfortunately "fat-file" is just almost fat file :( */
+ fat_fd->fat_file_type = FAT_DIRECTORY;
+ fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
+ fat_fd->cln = fs_info->fat.vol.rdir_cl;
+
+ fat_fd->map.file_cln = 0;
+ fat_fd->map.disk_cln = fat_fd->cln;
+
+ /* if we have FAT12/16 */
+ if ( fat_fd->cln == 0 )
+ {
+ fat_fd->fat_file_size = fs_info->fat.vol.rdir_size;
+ cl_buf_size = (fs_info->fat.vol.bpc > fs_info->fat.vol.rdir_size) ?
+ fs_info->fat.vol.bpc :
+ fs_info->fat.vol.rdir_size;
+ }
+ else
+ {
+ rc = fat_file_size(temp_mt_entry, fat_fd);
+ if ( rc != RC_OK )
+ {
+ fat_file_close(temp_mt_entry, fat_fd);
+ fat_shutdown_drive(temp_mt_entry);
+ free(fs_info);
+ return rc;
+ }
+ cl_buf_size = fs_info->fat.vol.bpc;
+ }
+
+ fs_info->cl_buf = (uint8_t *)calloc(cl_buf_size, sizeof(char));
+ if (fs_info->cl_buf == NULL)
+ {
+ fat_file_close(temp_mt_entry, fat_fd);
+ fat_shutdown_drive(temp_mt_entry);
+ free(fs_info);
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+
+ sc = rtems_semaphore_create(3,
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO,
+ 0,
+ &fs_info->vol_sema);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fat_file_close(temp_mt_entry, fat_fd);
+ fat_shutdown_drive(temp_mt_entry);
+ free(fs_info->cl_buf);
+ free(fs_info);
+ rtems_set_errno_and_return_minus_one( EIO );
+ }
+
+ temp_mt_entry->mt_fs_root.node_access = fat_fd;
+ temp_mt_entry->mt_fs_root.handlers = directory_handlers;
+ temp_mt_entry->mt_fs_root.ops = op_table;
+
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c
new file mode 100644
index 0000000000..d49b89048b
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_misc.c
@@ -0,0 +1,1731 @@
+/*
+ * Miscellaneous routines implementation for MSDOS filesystem
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#define MSDOS_TRACE 1
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+
+#include <stdio.h>
+
+/*
+ * External strings. Saves spave this way.
+ */
+const char *const MSDOS_DOT_NAME = ". ";
+const char *const MSDOS_DOTDOT_NAME = ".. ";
+
+/* msdos_is_valid_name_char --
+ * Routine to check the character in a file or directory name.
+ * The characters support in the short file name are letters,
+ * digits, or characters with code points values greater than
+ * 127 (not sure what this last is) plus the following special
+ * characters "$%'-_@~`!(){}^#&". The must be uppercase.
+ *
+ * The following 6 characters are allowed in a long names,
+ * " +,;=[]" including a space and lower case letters.
+ *
+ * PARAMETERS:
+ * ch - character to check.
+ *
+ * RETURNS:
+ * MSDOS_NAME_INVALID - Not valid in a long or short name.
+ * MSDOS_NAME_SHORT - Valid in a short name or long name.
+ * MSDOS_NAME_LONG - Valid in a long name only.
+ *
+ */
+static msdos_name_type_t
+msdos_is_valid_name_char(const char ch)
+{
+ if (strchr(" +,;=[]", ch) != NULL)
+ return MSDOS_NAME_LONG;
+
+ if ((ch == '.') || isalnum((unsigned char)ch) ||
+ (strchr("$%'-_@~`!(){}^#&", ch) != NULL))
+ return MSDOS_NAME_SHORT;
+
+ return MSDOS_NAME_INVALID;
+}
+
+/* msdos_short_hex_number --
+ * Routine to set the hex number in the SFN.
+ *
+ * PARAMETERS:
+ * name - name to change
+ * num - number to set
+ *
+ * RETURNS:
+ * nothing
+ *
+ */
+static void
+msdos_short_name_hex(char* sfn, int num)
+{
+ static const char* hex = "0123456789ABCDEF";
+ char* c = MSDOS_DIR_NAME(sfn);
+ int i;
+ for (i = 0; i < 2; i++, c++)
+ if ((*c == ' ') || (*c == '.'))
+ *c = '_';
+ for (i = 0; i < 4; i++, c++)
+ *c = hex[(num >> ((3 - i) * 4)) & 0xf];
+ *c++ = '~';
+ *c++ = '1';
+}
+
+/* msdos_name_type --
+ * Routine the type of file name.
+ *
+ * PARAMETERS:
+ * name - name to check
+ *
+ * RETURNS:
+ * true the name is long, else the name is short.
+ *
+ */
+#define MSDOS_NAME_TYPE_PRINT 0
+static msdos_name_type_t
+msdos_name_type(const char *name, int name_len)
+{
+ bool lowercase = false;
+ bool uppercase = false;
+ int dot_at = -1;
+ int count = 0;
+
+ while (*name && (count < name_len))
+ {
+ bool is_dot = *name == '.';
+ msdos_name_type_t type = msdos_is_valid_name_char(*name);
+
+#if MSDOS_NAME_TYPE_PRINT
+ printf ("MSDOS_NAME_TYPE: c:%02x type:%d\n", *name, type);
+#endif
+
+ if ((type == MSDOS_NAME_INVALID) || (type == MSDOS_NAME_LONG))
+ return type;
+
+ if (dot_at >= 0)
+ {
+ if (is_dot || ((count - dot_at) > 3))
+ {
+#if MSDOS_NAME_TYPE_PRINT
+ printf ("MSDOS_NAME_TYPE: LONG[1]: is_dot:%d, at:%d cnt\n",
+ is_dot, dot_at, count);
+#endif
+ return MSDOS_NAME_LONG;
+ }
+ }
+ else
+ {
+ if (count == 8 && !is_dot)
+ {
+#if MSDOS_NAME_TYPE_PRINT
+ printf ("MSDOS_NAME_TYPE: LONG[2]: is_dot:%d, at:%d cnt\n",
+ is_dot, dot_at, count);
+#endif
+ return MSDOS_NAME_LONG;
+ }
+ }
+
+ if (is_dot)
+ dot_at = count;
+ else if ((*name >= 'A') && (*name <= 'Z'))
+ uppercase = true;
+ else if ((*name >= 'a') && (*name <= 'z'))
+ lowercase = true;
+
+ count++;
+ name++;
+ }
+
+ if (lowercase && uppercase)
+ {
+#if MSDOS_NAME_TYPE_PRINT
+ printf ("MSDOS_NAME_TYPE: LONG[3]\n");
+#endif
+ return MSDOS_NAME_LONG;
+ }
+
+#if MSDOS_NAME_TYPE_PRINT
+ printf ("MSDOS_NAME_TYPE: SHORT[1]\n");
+#endif
+ return MSDOS_NAME_SHORT;
+}
+
+/* msdos_long_to_short --
+ * Routine to creates a short name from a long. Start the end of the
+ *
+ * PARAMETERS:
+ * name - name to check
+ *
+ * RETURNS:
+ * true the name is long, else the name is short.
+ *
+ */
+#define MSDOS_L2S_PRINT 0
+msdos_name_type_t
+msdos_long_to_short(const char *lfn, int lfn_len, char* sfn, int sfn_len)
+{
+ msdos_name_type_t type;
+ int i;
+
+ /*
+ * Fill with spaces. This is how a short directory entry is padded.
+ */
+ memset (sfn, ' ', sfn_len);
+
+ /*
+ * Handle '.' and '..' specially.
+ */
+ if ((lfn[0] == '.') && (lfn_len == 1))
+ {
+ sfn[0] = '.';
+#if MSDOS_L2S_PRINT
+ printf ("MSDOS_L2S: SHORT[1]: lfn:'%s' SFN:'%s'\n", lfn, sfn);
+#endif
+ return MSDOS_NAME_SHORT;
+ }
+
+ if ((lfn[0] == '.') && (lfn[1] == '.') && (lfn_len == 2))
+ {
+ sfn[0] = sfn[1] = '.';
+#if MSDOS_L2S_PRINT
+ printf ("MSDOS_L2S: SHORT[2]: lfn:'%s' SFN:'%s'\n", lfn, sfn);
+#endif
+ return MSDOS_NAME_SHORT;
+ }
+
+ /*
+ * Filenames with only blanks and dots are not allowed!
+ */
+ for (i = 0; i < lfn_len; i++)
+ if ((lfn[i] != ' ') && (lfn[i] != '.'))
+ break;
+
+ if (i == lfn_len)
+ {
+#if MSDOS_L2S_PRINT
+ printf ("MSDOS_L2S: INVALID[1]: lfn:'%s' SFN:'%s'\n", lfn, sfn);
+#endif
+ return MSDOS_NAME_INVALID;
+ }
+
+ /*
+ * Is this a short name ?
+ */
+
+ type = msdos_name_type (lfn, lfn_len);
+
+ if (type == MSDOS_NAME_INVALID)
+ {
+#if MSDOS_L2S_PRINT
+ printf ("MSDOS_L2S: INVALID[2]: lfn:'%s' SFN:'%s'\n", lfn, sfn);
+#endif
+ return MSDOS_NAME_INVALID;
+ }
+
+ msdos_filename_unix2dos (lfn, lfn_len, sfn);
+
+#if MSDOS_L2S_PRINT
+ printf ("MSDOS_L2S: TYPE:%d lfn:'%s' SFN:'%s'\n", type, lfn, sfn);
+#endif
+ return type;
+}
+
+/* msdos_get_token --
+ * Routine to get a token (name or separator) from the path.
+ *
+ * PARAMETERS:
+ * path - path to get token from
+ * ret_token - returned token
+ * token_len - length of returned token
+ *
+ * RETURNS:
+ * token type, token and token length
+ *
+ */
+msdos_token_types_t
+msdos_get_token(const char *path,
+ int pathlen,
+ const char **ret_token,
+ int *ret_token_len)
+{
+ msdos_token_types_t type = MSDOS_NAME;
+ int i = 0;
+
+ *ret_token = NULL;
+ *ret_token_len = 0;
+
+ if (pathlen == 0)
+ return MSDOS_NO_MORE_PATH;
+
+ /*
+ * Check for a separator.
+ */
+ while (!msdos_is_separator(path[i]) && (i < pathlen))
+ {
+ if ( !msdos_is_valid_name_char(path[i]) )
+ return MSDOS_INVALID_TOKEN;
+ ++i;
+ if ( i == MSDOS_NAME_MAX_LFN_WITH_DOT )
+ return MSDOS_INVALID_TOKEN;
+ }
+
+ *ret_token = path;
+
+ /*
+ * If it is just a separator then it is the current dir.
+ */
+ if ( i == 0 )
+ {
+ if ( (*path != '\0') && pathlen )
+ {
+ i++;
+ type = MSDOS_CURRENT_DIR;
+ }
+ else
+ type = MSDOS_NO_MORE_PATH;
+ }
+
+ /*
+ * Set the token and token_len to the token start and length.
+ */
+ *ret_token_len = i;
+
+ /*
+ * If we copied something that was not a seperator see if
+ * it was a special name.
+ */
+ if ( type == MSDOS_NAME )
+ {
+ if ((i == 2) && ((*ret_token)[0] == '.') && ((*ret_token)[1] == '.'))
+ {
+ type = MSDOS_UP_DIR;
+ return type;
+ }
+
+ if ((i == 1) && ((*ret_token)[0] == '.'))
+ {
+ type = MSDOS_CURRENT_DIR;
+ return type;
+ }
+ }
+
+ return type;
+}
+
+
+/* msdos_find_name --
+ * Find the node which correspondes to the name, open fat-file which
+ * correspondes to the found node and close fat-file which correspondes
+ * to the node we searched in.
+ *
+ * PARAMETERS:
+ * parent_loc - parent node description
+ * name - name to find
+ *
+ * RETURNS:
+ * RC_OK and updated 'parent_loc' on success, or -1 if error
+ * occured (errno set apropriately)
+ *
+ */
+int
+msdos_find_name(
+ rtems_filesystem_location_info_t *parent_loc,
+ const char *name,
+ int name_len
+ )
+{
+ int rc = RC_OK;
+ msdos_fs_info_t *fs_info = parent_loc->mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = NULL;
+ msdos_name_type_t name_type;
+ fat_dir_pos_t dir_pos;
+ unsigned short time_val = 0;
+ unsigned short date = 0;
+ char node_entry[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
+
+ memset(node_entry, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+
+ name_type = msdos_long_to_short (name,
+ name_len,
+ MSDOS_DIR_NAME(node_entry),
+ MSDOS_NAME_MAX);
+
+ /*
+ * find the node which correspondes to the name in the directory pointed by
+ * 'parent_loc'
+ */
+ rc = msdos_get_name_node(parent_loc, false, name, name_len, name_type,
+ &dir_pos, node_entry);
+ if (rc != RC_OK)
+ return rc;
+
+ if (((*MSDOS_DIR_ATTR(node_entry)) & MSDOS_ATTR_VOLUME_ID) ||
+ ((*MSDOS_DIR_ATTR(node_entry) & MSDOS_ATTR_LFN_MASK) == MSDOS_ATTR_LFN))
+ return MSDOS_NAME_NOT_FOUND_ERR;
+
+ /* open fat-file corresponded to the found node */
+ rc = fat_file_open(parent_loc->mt_entry, &dir_pos, &fat_fd);
+ if (rc != RC_OK)
+ return rc;
+
+ fat_fd->dir_pos = dir_pos;
+
+ /*
+ * I don't like this if, but: we should do it, or should write new file
+ * size and first cluster num to the disk after each write operation
+ * (even if one byte is written - that is TOO slow) because
+ * otherwise real values of these fields stored in fat-file descriptor
+ * may be accidentally rewritten with wrong values stored on the disk
+ */
+ if (fat_fd->links_num == 1)
+ {
+ fat_fd->cln = MSDOS_EXTRACT_CLUSTER_NUM(node_entry);
+
+ time_val = *MSDOS_DIR_WRITE_TIME(node_entry);
+ date = *MSDOS_DIR_WRITE_DATE(node_entry);
+
+ fat_fd->mtime = msdos_date_dos2unix(CF_LE_W(date), CF_LE_W(time_val));
+
+ if ((*MSDOS_DIR_ATTR(node_entry)) & MSDOS_ATTR_DIRECTORY)
+ {
+ fat_fd->fat_file_type = FAT_DIRECTORY;
+ fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
+
+ rc = fat_file_size(parent_loc->mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ fat_file_close(parent_loc->mt_entry, fat_fd);
+ return rc;
+ }
+ }
+ else
+ {
+ fat_fd->fat_file_size = CF_LE_L(*MSDOS_DIR_FILE_SIZE(node_entry));
+ fat_fd->fat_file_type = FAT_FILE;
+ fat_fd->size_limit = MSDOS_MAX_FILE_SIZE;
+ }
+
+ /* these data is not actual for zero-length fat-file */
+ fat_fd->map.file_cln = 0;
+ fat_fd->map.disk_cln = fat_fd->cln;
+
+ if ((fat_fd->fat_file_size != 0) &&
+ (fat_fd->fat_file_size <= fs_info->fat.vol.bpc))
+ {
+ fat_fd->map.last_cln = fat_fd->cln;
+ }
+ else
+ {
+ fat_fd->map.last_cln = FAT_UNDEFINED_VALUE;
+ }
+ }
+
+ /* close fat-file corresponded to the node we searched in */
+ rc = fat_file_close(parent_loc->mt_entry, parent_loc->node_access);
+ if (rc != RC_OK)
+ {
+ fat_file_close(parent_loc->mt_entry, fat_fd);
+ return rc;
+ }
+
+ /* update node_info_ptr field */
+ parent_loc->node_access = fat_fd;
+
+ return rc;
+}
+
+/* msdos_get_name_node --
+ * This routine is used in two ways: for a new node creation (a) or for
+ * search the node which correspondes to the name parameter (b).
+ * In case (a) 'name' should be set up to NULL and 'name_dir_entry' should
+ * point to initialized 32 bytes structure described a new node.
+ * In case (b) 'name' should contain a valid string.
+ *
+ * (a): reading fat-file which correspondes to directory we are going to
+ * create node in. If free slot is found write contents of
+ * 'name_dir_entry' into it. If reach end of fat-file and no free
+ * slot found, write 32 bytes to the end of fat-file.
+ *
+ * (b): reading fat-file which correspondes to directory and trying to
+ * find slot with the name field == 'name' parameter
+ *
+ *
+ * PARAMETERS:
+ * parent_loc - node description to create node in or to find name in
+ * name - NULL or name to find
+ * paux - identify a node location on the disk -
+ * cluster num and offset inside the cluster
+ * short_dir_entry - node to create/placeholder for found node (IN/OUT)
+ *
+ * RETURNS:
+ * RC_OK, filled aux_struct_ptr and name_dir_entry on success, or -1 if
+ * error occured (errno set apropriately)
+ *
+ */
+int
+msdos_get_name_node(
+ rtems_filesystem_location_info_t *parent_loc,
+ bool create_node,
+ const char *name,
+ int name_len,
+ msdos_name_type_t name_type,
+ fat_dir_pos_t *dir_pos,
+ char *name_dir_entry
+ )
+{
+ int rc = RC_OK;
+ fat_file_fd_t *fat_fd = parent_loc->node_access;
+ uint32_t dotdot_cln = 0;
+
+ /* find name in fat-file which corresponds to the directory */
+ rc = msdos_find_name_in_fat_file(parent_loc->mt_entry, fat_fd,
+ create_node, name, name_len, name_type,
+ dir_pos, name_dir_entry);
+ if ((rc != RC_OK) && (rc != MSDOS_NAME_NOT_FOUND_ERR))
+ return rc;
+
+ if (!create_node)
+ {
+ /* if we search for valid name and name not found -> return */
+ if (rc == MSDOS_NAME_NOT_FOUND_ERR)
+ return rc;
+
+ /*
+ * if we have deal with ".." - it is a special case :(((
+ *
+ * Really, we should return cluster num and offset not of ".." slot, but
+ * slot which correspondes to real directory name.
+ */
+ if (rc == RC_OK)
+ {
+ if (strncmp(name, "..", 2) == 0)
+ {
+ dotdot_cln = MSDOS_EXTRACT_CLUSTER_NUM((name_dir_entry));
+
+ /* are we right under root dir ? */
+ if (dotdot_cln == 0)
+ {
+ /*
+ * we can relax about first_char field - it never should be
+ * used for root dir
+ */
+ fat_dir_pos_init(dir_pos);
+ dir_pos->sname.cln = FAT_ROOTDIR_CLUSTER_NUM;
+ }
+ else
+ {
+ rc =
+ msdos_get_dotdot_dir_info_cluster_num_and_offset(parent_loc->mt_entry,
+ dotdot_cln,
+ dir_pos,
+ name_dir_entry);
+ if (rc != RC_OK)
+ return rc;
+ }
+ }
+ }
+ }
+ return rc;
+}
+
+/*
+ * msdos_get_dotdot_dir_info_cluster_num_and_offset
+ *
+ * Unfortunately, in general, we cann't work here in fat-file ideologic
+ * (open fat_file "..", get ".." and ".", open "..", find an entry ...)
+ * because if we open
+ * fat-file ".." it may happend that we have two different fat-file
+ * descriptors ( for real name of directory and ".." name ) for a single
+ * file ( cluster num of both pointers to the same cluster )
+ * But...we do it because we protected by semaphore
+ *
+ */
+
+/* msdos_get_dotdot_dir_info_cluster_num_and_offset --
+ * Get cluster num and offset not of ".." slot, but slot which correspondes
+ * to real directory name.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * cln - data cluster num extracted drom ".." slot
+ * paux - identify a node location on the disk -
+ * number of cluster and offset inside the cluster
+ * dir_entry - placeholder for found node
+ *
+ * RETURNS:
+ * RC_OK, filled 'paux' and 'dir_entry' on success, or -1 if error occured
+ * (errno set apropriately)
+ *
+ */
+int
+msdos_get_dotdot_dir_info_cluster_num_and_offset(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ uint32_t cln,
+ fat_dir_pos_t *dir_pos,
+ char *dir_entry
+ )
+{
+ int rc = RC_OK;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ fat_file_fd_t *fat_fd = NULL;
+ char dot_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
+ char dotdot_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE];
+ uint32_t cl4find = 0;
+
+ /*
+ * open fat-file corresponded to ".."
+ */
+ rc = fat_file_open(mt_entry, dir_pos, &fat_fd);
+ if (rc != RC_OK)
+ return rc;
+
+ fat_fd->cln = cln;
+ fat_fd->fat_file_type = FAT_DIRECTORY;
+ fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
+
+ fat_fd->map.file_cln = 0;
+ fat_fd->map.disk_cln = fat_fd->cln;
+
+ rc = fat_file_size(mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ fat_file_close(mt_entry, fat_fd);
+ return rc;
+ }
+
+ /* find "." node in opened directory */
+ memset(dot_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ msdos_long_to_short(".", 1, dot_node, MSDOS_SHORT_NAME_LEN);
+ rc = msdos_find_name_in_fat_file(mt_entry, fat_fd, false, ".", 1,
+ MSDOS_NAME_SHORT, dir_pos, dot_node);
+
+ if (rc != RC_OK)
+ {
+ fat_file_close(mt_entry, fat_fd);
+ return rc;
+ }
+
+ /* find ".." node in opened directory */
+ memset(dotdot_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ msdos_long_to_short("..", 2, dotdot_node, MSDOS_SHORT_NAME_LEN);
+ rc = msdos_find_name_in_fat_file(mt_entry, fat_fd, false, "..", 2,
+ MSDOS_NAME_SHORT, dir_pos,
+ dotdot_node);
+
+ if (rc != RC_OK)
+ {
+ fat_file_close(mt_entry, fat_fd);
+ return rc;
+ }
+
+ cl4find = MSDOS_EXTRACT_CLUSTER_NUM(dot_node);
+
+ /* close fat-file corresponded to ".." directory */
+ rc = fat_file_close(mt_entry, fat_fd);
+ if ( rc != RC_OK )
+ return rc;
+
+ if ( (MSDOS_EXTRACT_CLUSTER_NUM(dotdot_node)) == 0)
+ {
+ /*
+ * we handle root dir for all FAT types in the same way with the
+ * ordinary directories ( through fat_file_* calls )
+ */
+ fat_dir_pos_init(dir_pos);
+ dir_pos->sname.cln = FAT_ROOTDIR_CLUSTER_NUM;
+ }
+
+ /* open fat-file corresponded to second ".." */
+ rc = fat_file_open(mt_entry, dir_pos, &fat_fd);
+ if (rc != RC_OK)
+ return rc;
+
+ if ((MSDOS_EXTRACT_CLUSTER_NUM(dotdot_node)) == 0)
+ fat_fd->cln = fs_info->fat.vol.rdir_cl;
+ else
+ fat_fd->cln = MSDOS_EXTRACT_CLUSTER_NUM(dotdot_node);
+
+ fat_fd->fat_file_type = FAT_DIRECTORY;
+ fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
+
+ fat_fd->map.file_cln = 0;
+ fat_fd->map.disk_cln = fat_fd->cln;
+
+ rc = fat_file_size(mt_entry, fat_fd);
+ if (rc != RC_OK)
+ {
+ fat_file_close(mt_entry, fat_fd);
+ return rc;
+ }
+
+ /* in this directory find slot with specified cluster num */
+ rc = msdos_find_node_by_cluster_num_in_fat_file(mt_entry, fat_fd, cl4find,
+ dir_pos, dir_entry);
+ if (rc != RC_OK)
+ {
+ fat_file_close(mt_entry, fat_fd);
+ return rc;
+ }
+ rc = fat_file_close(mt_entry, fat_fd);
+ return rc;
+}
+
+
+/* msdos_set_dir_wrt_time_and_date --
+ * Write last write date and time for a file to the disk (to corresponded
+ * 32bytes node)
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately).
+ *
+ */
+int
+msdos_set_dir_wrt_time_and_date(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ ssize_t ret1 = 0, ret2 = 0, ret3 = 0;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint16_t time_val;
+ uint16_t date;
+ uint32_t sec = 0;
+ uint32_t byte = 0;
+
+ msdos_date_unix2dos(fat_fd->mtime, &date, &time_val);
+
+ /*
+ * calculate input for _fat_block_write: convert (cluster num, offset) to
+ * (sector num, new offset)
+ */
+ sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->dir_pos.sname.cln);
+ sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
+ /* byte points to start of 32bytes structure */
+ byte = fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1);
+
+ time_val = CT_LE_W(time_val);
+ ret1 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_WTIME_OFFSET,
+ 2, (char *)(&time_val));
+ date = CT_LE_W(date);
+ ret2 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_WDATE_OFFSET,
+ 2, (char *)(&date));
+ ret3 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_ADATE_OFFSET,
+ 2, (char *)(&date));
+
+ if ( (ret1 < 0) || (ret2 < 0) || (ret3 < 0) )
+ return -1;
+
+ return RC_OK;
+}
+
+/* msdos_set_first_cluster_num --
+ * Write number of first cluster of the file to the disk (to corresponded
+ * 32bytes slot)
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ *
+ */
+int
+msdos_set_first_cluster_num(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ ssize_t ret1 = 0, ret2 = 0;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t new_cln = fat_fd->cln;
+ uint16_t le_cl_low = 0;
+ uint16_t le_cl_hi = 0;
+ uint32_t sec = 0;
+ uint32_t byte = 0;
+
+ /*
+ * calculate input for _fat_block_write: convert (cluster num, offset) to
+ * (sector num, new offset)
+ */
+ sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->dir_pos.sname.cln);
+ sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
+ /* byte from points to start of 32bytes structure */
+ byte = fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1);
+
+ le_cl_low = CT_LE_W((uint16_t )(new_cln & 0x0000FFFF));
+ ret1 = _fat_block_write(mt_entry, sec,
+ byte + MSDOS_FIRST_CLUSTER_LOW_OFFSET, 2,
+ (char *)(&le_cl_low));
+ le_cl_hi = CT_LE_W((uint16_t )((new_cln & 0xFFFF0000) >> 16));
+ ret2 = _fat_block_write(mt_entry, sec,
+ byte + MSDOS_FIRST_CLUSTER_HI_OFFSET, 2,
+ (char *)(&le_cl_hi));
+ if ( (ret1 < 0) || (ret2 < 0) )
+ return -1;
+
+ return RC_OK;
+}
+
+
+/* msdos_set_file size --
+ * Write file size of the file to the disk (to corresponded 32bytes slot)
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately).
+ *
+ */
+int
+msdos_set_file_size(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd
+ )
+{
+ ssize_t ret = 0;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t le_new_length = 0;
+ uint32_t sec = 0;
+ uint32_t byte = 0;
+
+ sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->dir_pos.sname.cln);
+ sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
+ byte = (fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1));
+
+ le_new_length = CT_LE_L((fat_fd->fat_file_size));
+ ret = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_SIZE_OFFSET, 4,
+ (char *)(&le_new_length));
+ if ( ret < 0 )
+ return -1;
+
+ return RC_OK;
+}
+
+/*
+ * We should not check whether this routine is called for root dir - it
+ * never can happend
+ */
+
+/* msdos_set_first_char4file_name --
+ * Write first character of the name of the file to the disk (to
+ * corresponded 32bytes slot)
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * cl - number of cluster
+ * ofs - offset inside cluster
+ * fchar - character to set up
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set apropriately)
+ *
+ */
+int
+msdos_set_first_char4file_name(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_dir_pos_t *dir_pos,
+ unsigned char fchar
+ )
+{
+ ssize_t ret;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t dir_block_size;
+ fat_pos_t start = dir_pos->lname;
+ fat_pos_t end = dir_pos->sname;
+
+ if ((end.cln == fs_info->fat.vol.rdir_cl) &&
+ (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16)))
+ dir_block_size = fs_info->fat.vol.rdir_size;
+ else
+ dir_block_size = fs_info->fat.vol.bpc;
+
+ if (dir_pos->lname.cln == FAT_FILE_SHORT_NAME)
+ start = dir_pos->sname;
+
+ /*
+ * We handle the changes directly due the way the short file
+ * name code was written rather than use the fat_file_write
+ * interface.
+ */
+ while (true)
+ {
+ uint32_t sec = (fat_cluster_num_to_sector_num(mt_entry, start.cln) +
+ (start.ofs >> fs_info->fat.vol.sec_log2));
+ uint32_t byte = (start.ofs & (fs_info->fat.vol.bps - 1));;
+
+ ret = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_NAME_OFFSET, 1,
+ &fchar);
+ if (ret < 0)
+ return -1;
+
+ if ((start.cln == end.cln) && (start.ofs == end.ofs))
+ break;
+
+ start.ofs += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE;
+ if (start.ofs >= dir_block_size)
+ {
+ int rc;
+ if ((end.cln == fs_info->fat.vol.rdir_cl) &&
+ (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16)))
+ break;
+ rc = fat_get_fat_cluster(mt_entry, start.cln, &start.cln);
+ if ( rc != RC_OK )
+ return rc;
+ start.ofs = 0;
+ }
+ }
+
+ return RC_OK;
+}
+
+/* msdos_dir_is_empty --
+ * Check whether directory which correspondes to the fat-file descriptor is
+ * empty.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * ret_val - placeholder for result
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured
+ *
+ */
+int
+msdos_dir_is_empty(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ bool *ret_val
+ )
+{
+ ssize_t ret = 0;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t j = 0, i = 0;
+
+ /* dir is not empty */
+ *ret_val = false;
+
+ while ((ret = fat_file_read(mt_entry, fat_fd, j * fs_info->fat.vol.bps,
+ fs_info->fat.vol.bps,
+ fs_info->cl_buf)) != FAT_EOF)
+ {
+ if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ return -1;
+
+ assert(ret == fs_info->fat.vol.bps);
+
+ /* have to look at the DIR_NAME as "raw" 8-bit data */
+ for (i = 0;
+ i < fs_info->fat.vol.bps;
+ i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ {
+ char* entry = (char*) fs_info->cl_buf + i;
+
+ /*
+ * If the entry is empty, a long file name entry, or '.' or '..'
+ * then consider it as empty.
+ *
+ * Just ignore long file name entries. They must have a short entry to
+ * be valid.
+ */
+ if (((*MSDOS_DIR_ENTRY_TYPE(entry)) ==
+ MSDOS_THIS_DIR_ENTRY_EMPTY) ||
+ ((*MSDOS_DIR_ATTR(entry) & MSDOS_ATTR_LFN_MASK) ==
+ MSDOS_ATTR_LFN) ||
+ (strncmp(MSDOS_DIR_NAME((entry)), MSDOS_DOT_NAME,
+ MSDOS_SHORT_NAME_LEN) == 0) ||
+ (strncmp(MSDOS_DIR_NAME((entry)),
+ MSDOS_DOTDOT_NAME,
+ MSDOS_SHORT_NAME_LEN) == 0))
+ continue;
+
+ /*
+ * Nothing more to look at.
+ */
+ if ((*MSDOS_DIR_NAME(entry)) ==
+ MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY)
+ {
+ *ret_val = true;
+ return RC_OK;
+ }
+
+ /*
+ * Short file name entries mean not empty.
+ */
+ return RC_OK;
+ }
+ j++;
+ }
+ *ret_val = true;
+ return RC_OK;
+}
+
+/* msdos_create_name_in_fat_file --
+ * This routine creates an entry in the fat file for the file name
+ * provided by the user. The directory entry passed is the short
+ * file name and is added as it. If the file name is long a long
+ * file name set of entries is added.
+ *
+ * Scan the directory for the file and if not found add the new entry.
+ * When scanning remember the offset in the file where the directory
+ * entry can be added.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * name - NULL or name to find
+ * paux - identify a node location on the disk -
+ * number of cluster and offset inside the cluster
+ * name_dir_entry - node to create/placeholder for found node
+ *
+ * RETURNS:
+ * RC_OK on success, or error code if error occured (errno set
+ * appropriately)
+ *
+ */
+#define MSDOS_FIND_PRINT 0
+int msdos_find_name_in_fat_file(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ bool create_node,
+ const char *name,
+ int name_len,
+ msdos_name_type_t name_type,
+ fat_dir_pos_t *dir_pos,
+ char *name_dir_entry
+ )
+{
+ ssize_t ret = 0;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t dir_offset = 0;
+ uint32_t dir_entry = 0;
+ uint32_t bts2rd = 0;
+ fat_pos_t lfn_start;
+ bool lfn_matched = false;
+ uint8_t lfn_checksum = 0;
+ int lfn_entries;
+ int lfn_entry = 0;
+ uint32_t empty_space_offset = 0;
+ uint32_t empty_space_entry = 0;
+ uint32_t empty_space_count = 0;
+ bool empty_space_found = false;
+ uint32_t entries_per_block;
+ bool read_cluster = false;
+
+ assert(name_len > 0);
+
+ fat_dir_pos_init(dir_pos);
+
+ lfn_start.cln = lfn_start.ofs = FAT_FILE_SHORT_NAME;
+
+ /*
+ * Set the number of short entries needed to store the LFN. If the name
+ * is short still check for possible long entries with the short name.
+ *
+ * In PR1491 we need to have a LFN for a short file name entry. To
+ * test this make this test always fail, ie add "0 &&".
+ */
+ if (create_node && (name_type == MSDOS_NAME_SHORT))
+ lfn_entries = 0;
+ else
+ lfn_entries =
+ ((name_len - 1) + MSDOS_LFN_LEN_PER_ENTRY) / MSDOS_LFN_LEN_PER_ENTRY;
+
+ if (FAT_FD_OF_ROOT_DIR(fat_fd) &&
+ (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16)))
+ bts2rd = fat_fd->fat_file_size;
+ else
+ bts2rd = fs_info->fat.vol.bpc;
+
+ entries_per_block = bts2rd / MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE;
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[1] nt:%d, cn:%i ebp:%li bts2rd:%li lfne:%d nl:%i n:%s\n",
+ name_type, create_node, entries_per_block, bts2rd,
+ lfn_entries, name_len, name);
+#endif
+ /*
+ * Scan the directory seeing if the file is present. While
+ * doing this see if a suitable location can be found to
+ * create the entry if the name is not found.
+ */
+ while ((ret = fat_file_read(mt_entry, fat_fd, (dir_offset * bts2rd),
+ bts2rd, fs_info->cl_buf)) != FAT_EOF)
+ {
+ bool remainder_empty = false;
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[2] dir_offset:%li\n", dir_offset);
+#endif
+
+ if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ assert(ret == bts2rd);
+
+ /* have to look at the DIR_NAME as "raw" 8-bit data */
+ for (dir_entry = 0;
+ dir_entry < bts2rd;
+ dir_entry += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ {
+ char* entry = (char*) fs_info->cl_buf + dir_entry;
+
+ /*
+ * See if the entry is empty or the remainder of the directory is
+ * empty ? Localise to make the code read better.
+ */
+ bool entry_empty = (*MSDOS_DIR_ENTRY_TYPE(entry) ==
+ MSDOS_THIS_DIR_ENTRY_EMPTY);
+ remainder_empty = (*MSDOS_DIR_ENTRY_TYPE(entry) ==
+ MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY);
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[3] re:%i ee:%i do:%li de:%li(%ld)\n",
+ remainder_empty, entry_empty, dir_offset,
+ dir_entry, (dir_entry / MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE));
+#endif
+ /*
+ * Remember where the we are, ie the start, so we can come back
+ * to here and write the long file name if this is the start of
+ * a series of empty entries. If empty_space_count is 0 then
+ * we are currently not inside an empty series of entries. It
+ * is a count of empty entries.
+ */
+ if (empty_space_count == 0)
+ {
+ empty_space_entry = dir_entry;
+ empty_space_offset = dir_offset;
+ }
+
+ if (remainder_empty)
+ {
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[3.1] cn:%i esf:%i\n", create_node, empty_space_found);
+#endif
+ /*
+ * If just looking and there is no more entries in the
+ * directory - return name-not-found
+ */
+ if (!create_node)
+ return MSDOS_NAME_NOT_FOUND_ERR;
+
+ /*
+ * Lets go and write the directory entries. If we have not found
+ * any available space add the remaining number of entries to any that
+ * we may have already found that are just before this entry. If more
+ * are needed FAT_EOF is returned by the read and we extend the file.
+ */
+ if (!empty_space_found)
+ {
+ empty_space_count +=
+ entries_per_block - (dir_entry / MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ empty_space_found = true;
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[3.2] esf:%i esc%i\n", empty_space_found, empty_space_count);
+#endif
+ }
+ break;
+ }
+ else if (entry_empty)
+ {
+ if (create_node)
+ {
+ /*
+ * Remainder is not empty so is this entry empty ?
+ */
+ empty_space_count++;
+
+ if (empty_space_count == (lfn_entries + 1))
+ empty_space_found = true;
+ }
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[4.1] esc:%li esf:%i\n",
+ empty_space_count, empty_space_found);
+#endif
+ }
+ else
+ {
+ /*
+ * A valid entry so handle it.
+ *
+ * If empty space has not been found we need to start the
+ * count again.
+ */
+ if (create_node && !empty_space_found)
+ {
+ empty_space_entry = 0;
+ empty_space_count = 0;
+ }
+
+ /*
+ * Check the attribute to see if the entry is for a long
+ * file name.
+ */
+ if ((*MSDOS_DIR_ATTR(entry) & MSDOS_ATTR_LFN_MASK) ==
+ MSDOS_ATTR_LFN)
+ {
+ char* p;
+ int o;
+ int i;
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[4.2] lfn:%c entry:%i checksum:%i\n",
+ lfn_start.cln == FAT_FILE_SHORT_NAME ? 'f' : 't',
+ *MSDOS_DIR_ENTRY_TYPE(entry) & MSDOS_LAST_LONG_ENTRY_MASK,
+ *MSDOS_DIR_LFN_CHECKSUM(entry));
+#endif
+ /*
+ * If we are not already processing a LFN see if this is
+ * the first entry of a LFN ?
+ */
+ if (lfn_start.cln == FAT_FILE_SHORT_NAME)
+ {
+ lfn_matched = false;
+
+ /*
+ * The first entry must have the last long entry
+ * flag set.
+ */
+ if ((*MSDOS_DIR_ENTRY_TYPE(entry) &
+ MSDOS_LAST_LONG_ENTRY) == 0)
+ continue;
+
+ /*
+ * Does the number of entries in the LFN directory
+ * entry match the number we expect for this
+ * file name. Note we do not know the number of
+ * characters in the entry so this is check further
+ * on when the characters are checked.
+ */
+ if (lfn_entries != (*MSDOS_DIR_ENTRY_TYPE(entry) &
+ MSDOS_LAST_LONG_ENTRY_MASK))
+ continue;
+
+ /*
+ * Get the checksum of the short entry.
+ */
+ lfn_start.cln = dir_offset;
+ lfn_start.ofs = dir_entry;
+ lfn_entry = lfn_entries;
+ lfn_checksum = *MSDOS_DIR_LFN_CHECKSUM(entry);
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[4.3] lfn_checksum:%i\n",
+ *MSDOS_DIR_LFN_CHECKSUM(entry));
+#endif
+ }
+
+ /*
+ * If the entry number or the check sum do not match
+ * forget this series of long directory entries. These
+ * could be orphaned entries depending on the history
+ * of the disk.
+ */
+ if ((lfn_entry != (*MSDOS_DIR_ENTRY_TYPE(entry) &
+ MSDOS_LAST_LONG_ENTRY_MASK)) ||
+ (lfn_checksum != *MSDOS_DIR_LFN_CHECKSUM(entry)))
+ {
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[4.4] no match\n");
+#endif
+ lfn_start.cln = FAT_FILE_SHORT_NAME;
+ continue;
+ }
+
+ lfn_entry--;
+ o = lfn_entry * MSDOS_LFN_LEN_PER_ENTRY;
+ p = entry + 1;
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[5] lfne:%i\n", lfn_entry);
+#endif
+ for (i = 0; i < MSDOS_LFN_LEN_PER_ENTRY; i++)
+ {
+#if MSDOS_FIND_PRINT > 1
+ printf ("MSFS:[6] o:%i i:%i *p:%c(%02x) name[o + i]:%c(%02x)\n",
+ o, i, *p, *p, name[o + i], name[o + i]);
+#endif
+ if (*p == '\0')
+ {
+ /*
+ * If this is the first entry, ie the last part of the
+ * long file name and the length does not match then
+ * the file names do not match.
+ */
+ if (((lfn_entry + 1) == lfn_entries) &&
+ ((o + i) != name_len))
+ lfn_start.cln = FAT_FILE_SHORT_NAME;
+ break;
+ }
+
+ if (((o + i) >= name_len) || (*p != name[o + i]))
+ {
+ lfn_start.cln = FAT_FILE_SHORT_NAME;
+ break;
+ }
+
+ switch (i)
+ {
+ case 4:
+ p += 5;
+ break;
+ case 10:
+ p += 4;
+ break;
+ default:
+ p += 2;
+ break;
+ }
+ }
+
+ lfn_matched = ((lfn_entry == 0) &&
+ (lfn_start.cln != FAT_FILE_SHORT_NAME));
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[8.1] lfn_matched:%i\n", lfn_matched);
+#endif
+ }
+ else
+ {
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.1] SFN entry, lfn_matched:%i\n", lfn_matched);
+#endif
+ /*
+ * SFN entry found.
+ *
+ * If a LFN has been found and it matched check the
+ * entries have all been found and the checksum is
+ * correct. If this is the case return the short file
+ * name entry.
+ */
+ if (lfn_matched)
+ {
+ uint8_t cs = 0;
+ uint8_t* p = (uint8_t*) MSDOS_DIR_NAME(entry);
+ int i;
+
+ for (i = 0; i < MSDOS_SHORT_NAME_LEN; i++, p++)
+ cs = ((cs & 1) ? 0x80 : 0) + (cs >> 1) + *p;
+
+ if (lfn_entry || (lfn_checksum != cs))
+ lfn_matched = false;
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.2] checksum, lfn_matched:%i, lfn_entry:%i, lfn_checksum:%02x/%02x\n",
+ lfn_matched, lfn_entry, lfn_checksum, cs);
+#endif
+ }
+
+ /*
+ * If the long file names matched or the file name is
+ * short and they match then we have the entry. We will not
+ * match a long file name against a short file name because
+ * a long file name that generates a matching short file
+ * name is not a long file name.
+ */
+ if (lfn_matched ||
+ ((name_type == MSDOS_NAME_SHORT) &&
+ (lfn_start.cln == FAT_FILE_SHORT_NAME) &&
+ (memcmp(MSDOS_DIR_NAME(entry),
+ MSDOS_DIR_NAME(name_dir_entry),
+ MSDOS_SHORT_NAME_LEN) == 0)))
+ {
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.3] SNF found\n");
+#endif
+ /*
+ * We get the entry we looked for - fill the position
+ * structure and the 32 bytes of the short entry
+ */
+ int rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
+ dir_offset * bts2rd,
+ &dir_pos->sname.cln);
+ if (rc != RC_OK)
+ return rc;
+
+ dir_pos->sname.ofs = dir_entry;
+
+ if (lfn_start.cln != FAT_FILE_SHORT_NAME)
+ {
+ rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
+ lfn_start.cln * bts2rd,
+ &lfn_start.cln);
+ if (rc != RC_OK)
+ return rc;
+ }
+
+ dir_pos->lname.cln = lfn_start.cln;
+ dir_pos->lname.ofs = lfn_start.ofs;
+
+ memcpy(name_dir_entry, entry,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ return RC_OK;
+ }
+
+ lfn_start.cln = FAT_FILE_SHORT_NAME;
+ lfn_matched = false;
+ }
+ }
+ }
+
+ if (remainder_empty)
+ break;
+
+ dir_offset++;
+ }
+
+ /*
+ * If we are not to create the entry return a not found error.
+ */
+ if (!create_node)
+ return MSDOS_NAME_NOT_FOUND_ERR;
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[8.1] WRITE do:%ld esc:%ld eso:%ld ese:%ld\n",
+ dir_offset, empty_space_count, empty_space_offset, empty_space_entry);
+#endif
+
+ /*
+ * If a long file name calculate the checksum of the short file name
+ * data to place in each long file name entry. First set the short
+ * file name to the slot of the SFN entry. This will mean no clashes
+ * in this directory.
+ */
+ lfn_checksum = 0;
+ if (name_type == MSDOS_NAME_LONG)
+ {
+ int slot = (((empty_space_offset * bts2rd) + empty_space_entry) /
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) + lfn_entries + 1;
+ msdos_short_name_hex(MSDOS_DIR_NAME(name_dir_entry), slot);
+ }
+
+ if (lfn_entries)
+ {
+ uint8_t* p = (uint8_t*) MSDOS_DIR_NAME(name_dir_entry);
+ int i;
+ for (i = 0; i < 11; i++, p++)
+ lfn_checksum =
+ ((lfn_checksum & 1) ? 0x80 : 0) + (lfn_checksum >> 1) + *p;
+ }
+
+ /*
+ * If there is no space available then extend the file. The
+ * empty_space_count is a count of empty entries in the currently
+ * read cluster so if 0 there is no space. Note, dir_offset will
+ * be at the next cluster so we can just make empty_space_offset
+ * that value.
+ */
+ if (empty_space_count == 0)
+ {
+ read_cluster = true;
+ empty_space_offset = dir_offset;
+ empty_space_entry = 0;
+ }
+
+ /*
+ * Have we read past the empty block ? If so go back and read it again.
+ */
+ if (dir_offset != empty_space_offset)
+ read_cluster = true;
+
+ /*
+ * Handle the entry writes.
+ */
+ lfn_start.cln = lfn_start.ofs = FAT_FILE_SHORT_NAME;
+ lfn_entry = 0;
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9] read_cluster:%d eso:%ld ese:%ld\n",
+ read_cluster, empty_space_offset, empty_space_entry);
+#endif
+
+ /*
+ * The one more is the short entry.
+ */
+ while (lfn_entry < (lfn_entries + 1))
+ {
+ int length = 0;
+
+ if (read_cluster)
+ {
+ uint32_t new_length;
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.1] eso:%li\n", empty_space_offset);
+#endif
+ ret = fat_file_read(mt_entry, fat_fd,
+ (empty_space_offset * bts2rd), bts2rd,
+ fs_info->cl_buf);
+
+ if (ret != bts2rd)
+ {
+ if (ret != FAT_EOF)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.2] extending file:%li\n", empty_space_offset);
+#endif
+ ret = fat_file_extend (mt_entry, fat_fd, empty_space_offset * bts2rd,
+ &new_length);
+
+ if (ret != RC_OK)
+ return ret;
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.3] extended: %d <-> %d\n", new_length, empty_space_offset * bts2rd);
+#endif
+ if (new_length != (empty_space_offset * bts2rd))
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ memset(fs_info->cl_buf, 0, bts2rd);
+
+ ret = fat_file_write(mt_entry, fat_fd,
+ empty_space_offset * bts2rd,
+ bts2rd, fs_info->cl_buf);
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[9.4] clear write: %d\n", ret);
+#endif
+ if (ret == -1)
+ return ret;
+ else if (ret != bts2rd)
+ rtems_set_errno_and_return_minus_one(EIO);
+ }
+ }
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[10] eso:%li\n", empty_space_offset);
+#endif
+
+ for (dir_entry = empty_space_entry;
+ dir_entry < bts2rd;
+ dir_entry += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ {
+ char* entry = (char*) fs_info->cl_buf + dir_entry;
+ char* p;
+ const char* n;
+ int i;
+ char fill = 0;
+
+ length += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE;
+ lfn_entry++;
+
+#if MSDOS_FIND_PRINT
+ printf ("MSFS:[10] de:%li(%li) length:%i lfn_entry:%i\n",
+ dir_entry, (dir_entry / MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE),
+ length, lfn_entry);
+#endif
+ /*
+ * Time to write the short file name entry.
+ */
+ if (lfn_entry == (lfn_entries + 1))
+ {
+ /* get current cluster number */
+ int rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
+ empty_space_offset * bts2rd,
+ &dir_pos->sname.cln);
+ if (rc != RC_OK)
+ return rc;
+
+ dir_pos->sname.ofs = dir_entry;
+
+ if (lfn_start.cln != FAT_FILE_SHORT_NAME)
+ {
+ rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
+ lfn_start.cln * bts2rd,
+ &lfn_start.cln);
+ if (rc != RC_OK)
+ return rc;
+ }
+
+ dir_pos->lname.cln = lfn_start.cln;
+ dir_pos->lname.ofs = lfn_start.ofs;
+
+ /* write new node entry */
+ memcpy (entry, (uint8_t *) name_dir_entry,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ break;
+ }
+
+ /*
+ * This is a long file name and we need to write
+ * a long file name entry. See if this is the
+ * first entry written and if so remember the
+ * the location of the long file name.
+ */
+ if (lfn_start.cln == FAT_FILE_SHORT_NAME)
+ {
+ lfn_start.cln = empty_space_offset;
+ lfn_start.ofs = dir_entry;
+ }
+
+ /*
+ * Clear the entry before loading the data.
+ */
+ memset (entry, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+
+ *MSDOS_DIR_LFN_CHECKSUM(entry) = lfn_checksum;
+
+ p = entry + 1;
+ n = name + (lfn_entries - lfn_entry) * MSDOS_LFN_LEN_PER_ENTRY;
+
+ for (i = 0; i < MSDOS_LFN_LEN_PER_ENTRY; i++)
+ {
+ if (*n != 0)
+ {
+ *p = *n;
+ n++;
+ }
+ else
+ {
+ p [0] = fill;
+ p [1] = fill;
+ fill = 0xff;
+ }
+
+ switch (i)
+ {
+ case 4:
+ p += 5;
+ break;
+ case 10:
+ p += 4;
+ break;
+ default:
+ p += 2;
+ break;
+ }
+ }
+
+ *MSDOS_DIR_ENTRY_TYPE(entry) = (lfn_entries - lfn_entry) + 1;
+ if (lfn_entry == 1)
+ *MSDOS_DIR_ENTRY_TYPE(entry) |= MSDOS_LAST_LONG_ENTRY;
+ *MSDOS_DIR_ATTR(entry) |= MSDOS_ATTR_LFN;
+ }
+
+ ret = fat_file_write(mt_entry, fat_fd,
+ (empty_space_offset * bts2rd) + empty_space_entry,
+ length, fs_info->cl_buf + empty_space_entry);
+ if (ret == -1)
+ return ret;
+ else if (ret != length)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ empty_space_offset++;
+ empty_space_entry = 0;
+ read_cluster = true;
+ }
+
+ return 0;
+}
+
+/* msdos_find_node_by_cluster_num_in_fat_file --
+ * Find node with specified number of cluster in fat-file.
+ *
+ * Note, not updated in the LFN change because it is only used
+ * for . and .. entries and these are always short.
+ *
+ * PARAMETERS:
+ * mt_entry - mount table entry
+ * fat_fd - fat-file descriptor
+ * cl4find - number of cluster to find
+ * paux - identify a node location on the disk -
+ * cluster num and offset inside the cluster
+ * dir_entry - placeholder for found node
+ *
+ * RETURNS:
+ * RC_OK on success, or error code if error occured
+ *
+ */
+int msdos_find_node_by_cluster_num_in_fat_file(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ fat_file_fd_t *fat_fd,
+ uint32_t cl4find,
+ fat_dir_pos_t *dir_pos,
+ char *dir_entry
+ )
+{
+ int rc = RC_OK;
+ ssize_t ret = 0;
+ msdos_fs_info_t *fs_info = mt_entry->fs_info;
+ uint32_t bts2rd = 0;
+ uint32_t i = 0, j = 0;
+
+ if (FAT_FD_OF_ROOT_DIR(fat_fd) &&
+ (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16)))
+ bts2rd = fat_fd->fat_file_size;
+ else
+ bts2rd = fs_info->fat.vol.bpc;
+
+ while ((ret = fat_file_read(mt_entry, fat_fd, j * bts2rd, bts2rd,
+ fs_info->cl_buf)) != FAT_EOF)
+ {
+ if ( ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE )
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ assert(ret == bts2rd);
+
+ for (i = 0; i < bts2rd; i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
+ {
+ char* entry = (char*) fs_info->cl_buf + i;
+
+ /* if this and all rest entries are empty - return not-found */
+ if ((*MSDOS_DIR_ENTRY_TYPE(entry)) ==
+ MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY)
+ return MSDOS_NAME_NOT_FOUND_ERR;
+
+ /* if this entry is empty - skip it */
+ if ((*MSDOS_DIR_ENTRY_TYPE(entry)) ==
+ MSDOS_THIS_DIR_ENTRY_EMPTY)
+ continue;
+
+ /* if get a non-empty entry - compare clusters num */
+ if (MSDOS_EXTRACT_CLUSTER_NUM(entry) == cl4find)
+ {
+ /* on success fill aux structure and copy all 32 bytes */
+ rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM, j * bts2rd,
+ &dir_pos->sname.cln);
+ if (rc != RC_OK)
+ return rc;
+
+ dir_pos->sname.ofs = i;
+ dir_pos->lname.cln = FAT_FILE_SHORT_NAME;
+ dir_pos->lname.ofs = FAT_FILE_SHORT_NAME;
+
+ memcpy(dir_entry, entry,
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE);
+ return RC_OK;
+ }
+ }
+ j++;
+ }
+ return MSDOS_NAME_NOT_FOUND_ERR;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_mknod.c b/cpukit/libfs/src/dosfs/msdos_mknod.c
new file mode 100644
index 0000000000..ad4ad50d00
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_mknod.c
@@ -0,0 +1,84 @@
+/*
+ * Routine for node creation in MSDOS filesystem.
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <rtems.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_mknod --
+ * The following function checks spelling and formats name for a new node,
+ * determines type of the node to be created and creates it.
+ *
+ * PARAMETERS:
+ * name - file name to create
+ * mode - node type
+ * dev - dev
+ * pathloc - parent directory description
+ *
+ * RETURNS:
+ * RC_OK on succes, or -1 if error occured and set errno
+ *
+ */
+int msdos_mknod(
+ const char *name,
+ mode_t mode,
+ dev_t dev,
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
+ msdos_token_types_t type = 0;
+
+ /*
+ * Figure out what type of msdos node this is.
+ */
+ if (S_ISDIR(mode))
+ {
+ type = MSDOS_DIRECTORY;
+ }
+ else if (S_ISREG(mode))
+ {
+ type = MSDOS_REGULAR_FILE;
+ }
+ else
+ rtems_set_errno_and_return_minus_one(EINVAL);
+
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /* Create an MSDOS node */
+ rc = msdos_creat_node(pathloc, type, name, strlen(name), mode, NULL);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_node_type.c b/cpukit/libfs/src/dosfs/msdos_node_type.c
new file mode 100644
index 0000000000..877cf60492
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_node_type.c
@@ -0,0 +1,58 @@
+/*
+ * The following returns the type of node that the loc refers to.
+ *
+ * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <rtems.h>
+
+#include <rtems/libio_.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_node_type --
+ * Determine type of the node that the pathloc refers to.
+ *
+ * PARAMETERS:
+ * pathloc - node description
+ *
+ * RETURNS:
+ * node type
+ *
+ */
+rtems_filesystem_node_types_t
+msdos_node_type(rtems_filesystem_location_info_t *pathloc)
+{
+ fat_file_fd_t *fat_fd;
+
+ /*
+ * we don't need to obtain the volume semaphore here because node_type_h
+ * call always follows evalpath_h call(hence link increment occured) and
+ * hence node_access memory can't be freed during processing node_type_h
+ * call
+ */
+ fat_fd = pathloc->node_access;
+
+ return fat_fd->fat_file_type;
+}
diff --git a/cpukit/libfs/src/dosfs/msdos_rename.c b/cpukit/libfs/src/dosfs/msdos_rename.c
new file mode 100644
index 0000000000..1f5a6d9c6a
--- /dev/null
+++ b/cpukit/libfs/src/dosfs/msdos_rename.c
@@ -0,0 +1,92 @@
+/*
+ * Routine to rename a MSDOS filesystem node
+ *
+ * Copyright (C) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) $Id$
+ *
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rtems/libio_.h>
+#include <time.h>
+
+#include "fat.h"
+#include "fat_fat_operations.h"
+#include "fat_file.h"
+
+#include "msdos.h"
+
+/* msdos_rename --
+ * Rename the node by removing the exitsing directory entry and creating a
+ * new one.
+ *
+ * PARAMETERS:
+ * old_parent_loc - node description for the "old parent" node
+ * old_loc - node description for the "old" node
+ * new_parent_loc - node description for the "parent" node
+ * name - name of new node
+ *
+ * RETURNS:
+ * RC_OK on success, or -1 if error occured (errno set appropriately)
+ */
+int
+msdos_rename(rtems_filesystem_location_info_t *old_parent_loc,
+ rtems_filesystem_location_info_t *old_loc,
+ rtems_filesystem_location_info_t *new_parent_loc,
+ const char *new_name)
+{
+ int rc = RC_OK;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ msdos_fs_info_t *fs_info = new_parent_loc->mt_entry->fs_info;
+ fat_file_fd_t *old_fat_fd = old_loc->node_access;
+ const char *token;
+ int len;
+
+ /*
+ * check spelling and format new node name
+ */
+ if (MSDOS_NAME != msdos_get_token(new_name, strlen(new_name), &token, &len)) {
+ rtems_set_errno_and_return_minus_one(ENAMETOOLONG);
+ }
+ /*
+ * lock volume
+ */
+ sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
+ MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one(EIO);
+
+ /*
+ * create new directory entry as "hard link", copying relevant info from
+ * existing file
+ */
+ rc = msdos_creat_node(new_parent_loc,
+ MSDOS_HARD_LINK,new_name,len,S_IFREG,
+ old_fat_fd);
+ if (rc != RC_OK)
+ {
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+ }
+
+ /*
+ * mark file removed
+ */
+ rc = msdos_set_first_char4file_name(old_loc->mt_entry,
+ &old_fat_fd->dir_pos,
+ MSDOS_THIS_DIR_ENTRY_EMPTY);
+
+ rtems_semaphore_release(fs_info->vol_sema);
+ return rc;
+}
diff --git a/cpukit/libfs/src/imfs/.cvsignore b/cpukit/libfs/src/imfs/.cvsignore
new file mode 100644
index 0000000000..c62d89f265
--- /dev/null
+++ b/cpukit/libfs/src/imfs/.cvsignore
@@ -0,0 +1,5 @@
+config.h
+config.h.in
+stamp-h
+stamp-h.in
+stamp-h1.in
diff --git a/cpukit/libfs/src/imfs/deviceerrno.c b/cpukit/libfs/src/imfs/deviceerrno.c
new file mode 100644
index 0000000000..396df7619d
--- /dev/null
+++ b/cpukit/libfs/src/imfs/deviceerrno.c
@@ -0,0 +1,73 @@
+/*
+ * IMFS Device Node Handlers
+ *
+ * This file contains the set of handlers used to map operations on
+ * IMFS device nodes onto calls to the RTEMS Classic API IO Manager.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+
+static const int status_code_to_errno [RTEMS_STATUS_CODES_LAST + 1] = {
+ [RTEMS_SUCCESSFUL] = 0,
+ [RTEMS_TASK_EXITTED] = EIO,
+ [RTEMS_MP_NOT_CONFIGURED] = EIO,
+ [RTEMS_INVALID_NAME] = EINVAL,
+ [RTEMS_INVALID_ID] = EIO,
+ [RTEMS_TOO_MANY] = EIO,
+ [RTEMS_TIMEOUT] = ETIMEDOUT,
+ [RTEMS_OBJECT_WAS_DELETED] = EIO,
+ [RTEMS_INVALID_SIZE] = EIO,
+ [RTEMS_INVALID_ADDRESS] = EIO,
+ [RTEMS_INVALID_NUMBER] = EBADF,
+ [RTEMS_NOT_DEFINED] = EIO,
+ [RTEMS_RESOURCE_IN_USE] = EBUSY,
+ [RTEMS_UNSATISFIED] = ENODEV,
+ [RTEMS_INCORRECT_STATE] = EIO,
+ [RTEMS_ALREADY_SUSPENDED] = EIO,
+ [RTEMS_ILLEGAL_ON_SELF] = EIO,
+ [RTEMS_ILLEGAL_ON_REMOTE_OBJECT] = EIO,
+ [RTEMS_CALLED_FROM_ISR] = EIO,
+ [RTEMS_INVALID_PRIORITY] = EIO,
+ [RTEMS_INVALID_CLOCK] = EINVAL,
+ [RTEMS_INVALID_NODE] = EINVAL,
+ [RTEMS_NOT_CONFIGURED] = ENOSYS,
+ [RTEMS_NOT_OWNER_OF_RESOURCE] = EPERM,
+ [RTEMS_NOT_IMPLEMENTED] = ENOSYS,
+ [RTEMS_INTERNAL_ERROR] = EIO,
+ [RTEMS_NO_MEMORY] = ENOMEM,
+ [RTEMS_IO_ERROR] = EIO,
+ [RTEMS_PROXY_BLOCKING] = EIO
+};
+
+int rtems_deviceio_errno(rtems_status_code sc)
+{
+ if (sc == RTEMS_SUCCESSFUL) {
+ return 0;
+ } else {
+ int eno = EINVAL;
+
+ if ((unsigned) sc <= RTEMS_STATUS_CODES_LAST) {
+ eno = status_code_to_errno [sc];
+ }
+
+ errno = eno;
+
+ return -1;
+ }
+}
diff --git a/cpukit/libfs/src/imfs/deviceio.c b/cpukit/libfs/src/imfs/deviceio.c
new file mode 100644
index 0000000000..ff6cf2a01e
--- /dev/null
+++ b/cpukit/libfs/src/imfs/deviceio.c
@@ -0,0 +1,233 @@
+/*
+ * IMFS Device Node Handlers
+ *
+ * This file contains the set of handlers used to map operations on
+ * IMFS device nodes onto calls to the RTEMS Classic API IO Manager.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/devfs.h>
+
+#include "imfs.h"
+
+/*
+ * device_open
+ *
+ * This handler maps an open() operation onto rtems_io_open().
+ */
+
+int device_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ rtems_libio_open_close_args_t args;
+ rtems_status_code status;
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.flags = iop->flags;
+ args.mode = mode;
+
+ status = rtems_io_open(
+ the_jnode->info.device.major,
+ the_jnode->info.device.minor,
+ (void *) &args
+ );
+
+ return rtems_deviceio_errno( status );
+}
+
+/*
+ * device_close
+ *
+ * This handler maps a close() operation onto rtems_io_close().
+ */
+
+int device_close(
+ rtems_libio_t *iop
+)
+{
+ rtems_libio_open_close_args_t args;
+ rtems_status_code status;
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.flags = 0;
+ args.mode = 0;
+
+ status = rtems_io_close(
+ the_jnode->info.device.major,
+ the_jnode->info.device.minor,
+ (void *) &args
+ );
+
+ IMFS_check_node_remove( the_jnode );
+
+ return rtems_deviceio_errno( status );
+}
+
+/*
+ * device_read
+ *
+ * This handler maps a read() operation onto rtems_io_read().
+ */
+
+ssize_t device_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ rtems_libio_rw_args_t args;
+ rtems_status_code status;
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.offset = iop->offset;
+ args.buffer = buffer;
+ args.count = count;
+ args.flags = iop->flags;
+ args.bytes_moved = 0;
+
+ status = rtems_io_read(
+ the_jnode->info.device.major,
+ the_jnode->info.device.minor,
+ (void *) &args
+ );
+
+ if ( status )
+ return rtems_deviceio_errno(status);
+
+ return (ssize_t) args.bytes_moved;
+}
+
+/*
+ * device_write
+ *
+ * This handler maps a write() operation onto rtems_io_write().
+ */
+
+ssize_t device_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ rtems_libio_rw_args_t args;
+ rtems_status_code status;
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ args.iop = iop;
+ args.offset = iop->offset;
+ args.buffer = (void *) buffer;
+ args.count = count;
+ args.flags = iop->flags;
+ args.bytes_moved = 0;
+
+ status = rtems_io_write(
+ the_jnode->info.device.major,
+ the_jnode->info.device.minor,
+ (void *) &args
+ );
+
+ if ( status )
+ return rtems_deviceio_errno(status);
+
+ return (ssize_t) args.bytes_moved;
+}
+
+/*
+ * device_ioctl
+ *
+ * This handler maps an ioctl() operation onto rtems_io_ioctl().
+ */
+
+int device_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+)
+{
+ rtems_libio_ioctl_args_t args;
+ rtems_status_code status;
+ IMFS_jnode_t *the_jnode;
+
+ args.iop = iop;
+ args.command = command;
+ args.buffer = buffer;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ status = rtems_io_control(
+ the_jnode->info.device.major,
+ the_jnode->info.device.minor,
+ (void *) &args
+ );
+
+ if ( status )
+ return rtems_deviceio_errno(status);
+
+ return args.ioctl_return;
+}
+
+/*
+ * device_lseek
+ *
+ * This handler eats all lseek() operations and does not create
+ * an error. It assumes all devices can handle the seek. The
+ * writes fail.
+ */
+
+rtems_off64_t device_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t offset,
+ int whence
+)
+{
+ return offset;
+}
+
+/*
+ * device_stat
+ *
+ * The IMFS_stat() is used.
+ */
+
+/*
+ * device_rmnod
+ *
+ * The IMFS_rmnod() is used.
+ */
+
+int device_ftruncate(
+ rtems_libio_t *iop,
+ rtems_off64_t length
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/fifoimfs_init.c b/cpukit/libfs/src/imfs/fifoimfs_init.c
new file mode 100644
index 0000000000..13dc373eec
--- /dev/null
+++ b/cpukit/libfs/src/imfs/fifoimfs_init.c
@@ -0,0 +1,61 @@
+/**
+ * @file
+ *
+ * @ingroup LibFSIMFS
+ *
+ * @brief IMFS without fifo support initialization.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "imfs.h"
+
+const rtems_filesystem_operations_table fifoIMFS_ops = {
+ .evalpath_h = IMFS_eval_path,
+ .evalformake_h = IMFS_evaluate_for_make,
+ .link_h = IMFS_link,
+ .unlink_h = IMFS_unlink,
+ .node_type_h = IMFS_node_type,
+ .mknod_h = IMFS_mknod,
+ .chown_h = IMFS_chown,
+ .freenod_h = rtems_filesystem_default_freenode,
+ .mount_h = IMFS_mount,
+ .fsmount_me_h = fifoIMFS_initialize,
+ .unmount_h = IMFS_unmount,
+ .fsunmount_me_h = IMFS_fsunmount,
+ .utime_h = IMFS_utime,
+ .eval_link_h = IMFS_evaluate_link,
+ .symlink_h = IMFS_symlink,
+ .readlink_h = IMFS_readlink,
+ .rename_h = IMFS_rename,
+ .statvfs_h = rtems_filesystem_default_statvfs
+};
+
+int fifoIMFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+)
+{
+ return IMFS_initialize_support(
+ mt_entry,
+ &fifoIMFS_ops,
+ &IMFS_memfile_handlers,
+ &IMFS_directory_handlers,
+ &IMFS_fifo_handlers
+ );
+}
diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
new file mode 100644
index 0000000000..aec8febdc5
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -0,0 +1,574 @@
+/*
+ * Header file for the In-Memory File System
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_IMFS_H
+#define _RTEMS_IMFS_H
+
+#include <rtems.h>
+#include <rtems/chain.h>
+
+#include <sys/types.h>
+#include <limits.h>
+#include <rtems/libio.h>
+
+#include <rtems/pipe.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * File name macros
+ */
+
+#define IMFS_is_valid_name_char( _ch ) ( 1 )
+
+#define IMFS_is_separator( _ch ) \
+ rtems_filesystem_is_separator( _ch )
+
+/*
+ * Data types
+ */
+
+struct IMFS_jnode_tt;
+typedef struct IMFS_jnode_tt IMFS_jnode_t;
+
+typedef struct {
+ rtems_chain_control Entries;
+ rtems_filesystem_mount_table_entry_t *mt_fs;
+} IMFS_directory_t;
+
+typedef struct {
+ rtems_device_major_number major;
+ rtems_device_minor_number minor;
+} IMFS_device_t;
+
+typedef struct {
+ IMFS_jnode_t *link_node;
+} IMFS_link_t;
+
+typedef struct {
+ char *name;
+} IMFS_sym_link_t;
+
+typedef struct {
+ pipe_control_t *pipe;
+} IMFS_fifo_t;
+
+/*
+ * IMFS "memfile" information
+ *
+ * The data structure for the in-memory "memfiles" is based on classic UNIX.
+ *
+ * block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
+ * length which could be data or a table of pointers to blocks.
+ *
+ * Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
+ * impact on the maximum file size supported as well as the amount of
+ * memory wasted due to internal file fragmentation. The following
+ * is a list of maximum file sizes based on various settings
+ *
+ * max_filesize with blocks of 16 is 1,328
+ * max_filesize with blocks of 32 is 18,656
+ * max_filesize with blocks of 64 is 279,488
+ * max_filesize with blocks of 128 is 4,329,344
+ * max_filesize with blocks of 256 is 68,173,568
+ * max_filesize with blocks of 512 is 1,082,195,456
+ */
+
+#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128
+ extern int imfs_rq_memfile_bytes_per_block;
+ extern int imfs_memfile_bytes_per_block;
+
+#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
+#define IMFS_MEMFILE_BLOCK_SLOTS \
+ (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
+
+typedef uint8_t *block_p;
+typedef block_p *block_ptr;
+
+typedef struct {
+ rtems_off64_t size; /* size of file in bytes */
+ block_ptr indirect; /* array of 128 data blocks pointers */
+ block_ptr doubly_indirect; /* 128 indirect blocks */
+ block_ptr triply_indirect; /* 128 doubly indirect blocks */
+} IMFS_memfile_t;
+
+typedef struct {
+ rtems_off64_t size; /* size of file in bytes */
+ block_p direct; /* pointer to file image */
+} IMFS_linearfile_t;
+
+/*
+ * Important block numbers for "memfiles"
+ */
+
+#define FIRST_INDIRECT (0)
+#define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1)
+
+#define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1)
+#define LAST_DOUBLY_INDIRECT \
+ (LAST_INDIRECT + \
+ (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
+
+#define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1)
+#define LAST_TRIPLY_INDIRECT \
+ (LAST_DOUBLY_INDIRECT +\
+ (IMFS_MEMFILE_BLOCK_SLOTS * \
+ IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
+
+#define IMFS_MEMFILE_MAXIMUM_SIZE \
+ (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
+
+/*
+ * What types of IMFS file systems entities there can be.
+ */
+
+typedef enum {
+ IMFS_DIRECTORY = RTEMS_FILESYSTEM_DIRECTORY,
+ IMFS_DEVICE = RTEMS_FILESYSTEM_DEVICE,
+ IMFS_HARD_LINK = RTEMS_FILESYSTEM_HARD_LINK,
+ IMFS_SYM_LINK = RTEMS_FILESYSTEM_SYM_LINK,
+ IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE,
+ IMFS_LINEAR_FILE,
+ IMFS_FIFO
+} IMFS_jnode_types_t;
+
+typedef union {
+ IMFS_directory_t directory;
+ IMFS_device_t device;
+ IMFS_link_t hard_link;
+ IMFS_sym_link_t sym_link;
+ IMFS_memfile_t file;
+ IMFS_linearfile_t linearfile;
+ IMFS_fifo_t fifo;
+} IMFS_types_union;
+
+/*
+ * Major device number for the IMFS. This is not a real device number because
+ * the IMFS is just a file system and does not have a driver.
+ */
+#define IMFS_DEVICE_MAJOR_NUMBER (0xfffe)
+
+/*
+ * Maximum length of a "basename" of an IMFS file/node.
+ */
+
+#define IMFS_NAME_MAX 32
+
+/*
+ * The control structure for an IMFS jnode.
+ */
+
+struct IMFS_jnode_tt {
+ rtems_chain_node Node; /* for chaining them together */
+ IMFS_jnode_t *Parent; /* Parent node */
+ char name[IMFS_NAME_MAX+1]; /* "basename" */
+ mode_t st_mode; /* File mode */
+ nlink_t st_nlink; /* Link count */
+ ino_t st_ino; /* inode */
+
+ uid_t st_uid; /* User ID of owner */
+ gid_t st_gid; /* Group ID of owner */
+
+ time_t stat_atime; /* Time of last access */
+ time_t stat_mtime; /* Time of last modification */
+ time_t stat_ctime; /* Time of last status change */
+ IMFS_jnode_types_t type; /* Type of this entry */
+ IMFS_types_union info;
+};
+
+#define IMFS_update_atime( _jnode ) \
+ do { \
+ struct timeval tv; \
+ gettimeofday( &tv, 0 ); \
+ _jnode->stat_atime = (time_t) tv.tv_sec; \
+ } while (0)
+
+#define IMFS_update_mtime( _jnode ) \
+ do { \
+ struct timeval tv; \
+ gettimeofday( &tv, 0 ); \
+ _jnode->stat_mtime = (time_t) tv.tv_sec; \
+ } while (0)
+
+#define IMFS_update_ctime( _jnode ) \
+ do { \
+ struct timeval tv; \
+ gettimeofday( &tv, 0 ); \
+ _jnode->stat_ctime = (time_t) tv.tv_sec; \
+ } while (0)
+
+#define IMFS_mtime_ctime_update( _jnode ) \
+ do { \
+ struct timeval tv; \
+ gettimeofday( &tv, 0 ); \
+ _jnode->stat_mtime = (time_t) tv.tv_sec; \
+ _jnode->stat_ctime = (time_t) tv.tv_sec; \
+ } while (0)
+
+typedef struct {
+ int instance;
+ ino_t ino_count;
+ const rtems_filesystem_file_handlers_r *memfile_handlers;
+ const rtems_filesystem_file_handlers_r *directory_handlers;
+ const rtems_filesystem_file_handlers_r *fifo_handlers;
+} IMFS_fs_info_t;
+
+/*
+ * Type defination for tokens returned from IMFS_get_token
+ */
+
+typedef enum {
+ IMFS_NO_MORE_PATH,
+ IMFS_CURRENT_DIR,
+ IMFS_UP_DIR,
+ IMFS_NAME,
+ IMFS_INVALID_TOKEN
+} IMFS_token_types;
+
+/*
+ * Shared Data
+ */
+
+extern const rtems_filesystem_file_handlers_r IMFS_directory_handlers;
+extern const rtems_filesystem_file_handlers_r IMFS_device_handlers;
+extern const rtems_filesystem_file_handlers_r IMFS_link_handlers;
+extern const rtems_filesystem_file_handlers_r IMFS_memfile_handlers;
+extern const rtems_filesystem_file_handlers_r IMFS_fifo_handlers;
+extern const rtems_filesystem_operations_table IMFS_ops;
+extern const rtems_filesystem_operations_table fifoIMFS_ops;
+extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS;
+
+/*
+ * Routines
+ */
+
+extern int IMFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+);
+
+extern int fifoIMFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+);
+
+extern int miniIMFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+);
+
+extern int IMFS_initialize_support(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const rtems_filesystem_operations_table *op_table,
+ const rtems_filesystem_file_handlers_r *memfile_handlers,
+ const rtems_filesystem_file_handlers_r *directory_handlers,
+ const rtems_filesystem_file_handlers_r *fifo_handlers
+);
+
+extern int IMFS_fsunmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+);
+
+extern int rtems_tarfs_load(
+ char *mountpoint,
+ uint8_t *tar_image,
+ size_t tar_size
+);
+
+/*
+ * Returns the number of characters copied from path to token.
+ */
+extern IMFS_token_types IMFS_get_token(
+ const char *path,
+ int pathlen,
+ char *token,
+ int *token_len
+);
+
+extern void IMFS_dump( void );
+
+extern void IMFS_initialize_jnode(
+ IMFS_jnode_t *the_jnode,
+ IMFS_jnode_types_t type,
+ IMFS_jnode_t *the_parent,
+ char *name,
+ mode_t mode
+);
+
+extern IMFS_jnode_t *IMFS_find_match_in_dir(
+ IMFS_jnode_t *directory, /* IN */
+ char *name /* IN */
+);
+
+extern rtems_filesystem_node_types_t IMFS_node_type(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+extern int IMFS_stat(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct stat *buf /* OUT */
+);
+
+extern int IMFS_Set_handlers(
+ rtems_filesystem_location_info_t *loc
+);
+
+extern int IMFS_evaluate_link(
+ rtems_filesystem_location_info_t *node, /* IN/OUT */
+ int flags /* IN */
+);
+
+extern int IMFS_eval_path(
+ const char *pathname, /* IN */
+ size_t pathnamelen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+extern int IMFS_link(
+ rtems_filesystem_location_info_t *to_loc, /* IN */
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *token /* IN */
+);
+
+extern int IMFS_unlink(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+extern int IMFS_chown(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ uid_t owner, /* IN */
+ gid_t group /* IN */
+);
+
+extern int IMFS_mknod(
+ const char *path, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+);
+
+extern IMFS_jnode_t *IMFS_allocate_node(
+ IMFS_jnode_types_t type, /* IN */
+ const char *name, /* IN */
+ mode_t mode /* IN */
+);
+
+extern IMFS_jnode_t *IMFS_create_root_node(void);
+
+extern IMFS_jnode_t *IMFS_create_node(
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ IMFS_jnode_types_t type, /* IN */
+ const char *name, /* IN */
+ mode_t mode, /* IN */
+ const IMFS_types_union *info /* IN */
+);
+
+extern int IMFS_evaluate_for_make(
+ const char *path, /* IN */
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ const char **name /* OUT */
+);
+
+extern int IMFS_mount(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+extern int IMFS_unmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* IN */
+);
+
+extern int IMFS_memfile_remove(
+ IMFS_jnode_t *the_jnode /* IN/OUT */
+);
+
+extern int memfile_ftruncate(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t length /* IN */
+);
+
+extern int imfs_dir_open(
+ rtems_libio_t *iop, /* IN */
+ const char *pathname, /* IN */
+ uint32_t flag, /* IN */
+ uint32_t mode /* IN */
+);
+
+extern int imfs_dir_close(
+ rtems_libio_t *iop /* IN */
+);
+
+extern ssize_t imfs_dir_read(
+ rtems_libio_t *iop, /* IN */
+ void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+extern rtems_off64_t imfs_dir_lseek(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t offset, /* IN */
+ int whence /* IN */
+);
+
+extern int imfs_dir_fstat(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ struct stat *buf /* OUT */
+);
+
+extern int imfs_dir_rmnod(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+extern int memfile_open(
+ rtems_libio_t *iop, /* IN */
+ const char *pathname, /* IN */
+ uint32_t flag, /* IN */
+ uint32_t mode /* IN */
+);
+
+extern int memfile_close(
+ rtems_libio_t *iop /* IN */
+);
+
+extern ssize_t memfile_read(
+ rtems_libio_t *iop, /* IN */
+ void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+extern ssize_t memfile_write(
+ rtems_libio_t *iop, /* IN */
+ const void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+extern int memfile_ioctl(
+ rtems_libio_t *iop, /* IN */
+ uint32_t command, /* IN */
+ void *buffer /* IN */
+);
+
+extern rtems_off64_t memfile_lseek(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t offset, /* IN */
+ int whence /* IN */
+);
+
+extern int device_open(
+ rtems_libio_t *iop, /* IN */
+ const char *pathname, /* IN */
+ uint32_t flag, /* IN */
+ uint32_t mode /* IN */
+);
+
+extern int device_close(
+ rtems_libio_t *iop /* IN */
+);
+
+extern ssize_t device_read(
+ rtems_libio_t *iop, /* IN */
+ void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+extern ssize_t device_write(
+ rtems_libio_t *iop, /* IN */
+ const void *buffer, /* IN */
+ size_t count /* IN */
+);
+
+extern int device_ioctl(
+ rtems_libio_t *iop, /* IN */
+ uint32_t command, /* IN */
+ void *buffer /* IN */
+);
+
+extern rtems_off64_t device_lseek(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t offset, /* IN */
+ int whence /* IN */
+);
+
+extern int device_ftruncate(
+ rtems_libio_t *iop, /* IN */
+ rtems_off64_t length /* IN */
+);
+
+extern int IMFS_utime(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+);
+
+extern int IMFS_fchmod(
+ rtems_filesystem_location_info_t *loc,
+ mode_t mode
+);
+
+extern int IMFS_symlink(
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *link_name,
+ const char *node_name
+);
+
+extern ssize_t IMFS_readlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ char *buf, /* OUT */
+ size_t bufsize
+);
+
+extern int IMFS_rename(
+ rtems_filesystem_location_info_t *old_loc, /* IN */
+ rtems_filesystem_location_info_t *old_parent_loc, /* IN */
+ rtems_filesystem_location_info_t *new_parent_loc, /* IN */
+ const char *new_name /* IN */
+);
+
+extern int IMFS_fdatasync(
+ rtems_libio_t *iop
+);
+
+extern void IMFS_create_orphan(
+ IMFS_jnode_t *jnode
+);
+
+extern void IMFS_check_node_remove(
+ IMFS_jnode_t *jnode
+);
+
+extern int IMFS_rmnod(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+);
+
+/*
+ * Turn on IMFS assertions when RTEMS_DEBUG is defined.
+ */
+#ifdef RTEMS_DEBUG
+ #include <assert.h>
+
+ #define IMFS_assert(_x) assert(_x)
+#else
+ #define IMFS_assert(_x)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libfs/src/imfs/imfs_chown.c b/cpukit/libfs/src/imfs/imfs_chown.c
new file mode 100644
index 0000000000..7f0c7b5688
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_chown.c
@@ -0,0 +1,56 @@
+/*
+ * IMFS_chown
+ *
+ * This routine is the implementation of the chown() system
+ * call for the IMFS.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include "imfs.h"
+
+int IMFS_chown(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ uid_t owner, /* IN */
+ gid_t group /* IN */
+)
+{
+ IMFS_jnode_t *jnode;
+#if defined(RTEMS_POSIX_API)
+ uid_t st_uid;
+#endif
+
+ jnode = (IMFS_jnode_t *) pathloc->node_access;
+
+ /*
+ * Verify I am the owner of the node or the super user.
+ */
+
+#if defined(RTEMS_POSIX_API)
+ st_uid = geteuid();
+
+ if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) )
+ rtems_set_errno_and_return_minus_one( EPERM );
+#endif
+
+ jnode->st_uid = owner;
+ jnode->st_gid = group;
+
+ IMFS_update_ctime( jnode );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_config.c b/cpukit/libfs/src/imfs/imfs_config.c
new file mode 100644
index 0000000000..78f947e81f
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_config.c
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include "imfs.h"
+
+/* XXX this structure should use real constants */
+
+const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS = {
+ 5, /* link_max */
+ 6, /* max_canon */
+ 7, /* max_input */
+ IMFS_NAME_MAX, /* name_max */
+ 255, /* path_max */
+ 2, /* pipe_buf */
+ 1, /* posix_async_io */
+ 2, /* posix_chown_restrictions */
+ 3, /* posix_no_trunc */
+ 4, /* posix_prio_io */
+ 5, /* posix_sync_io */
+ 6 /* posix_vdisable */
+};
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c
new file mode 100644
index 0000000000..3b602d0c14
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_creat.c
@@ -0,0 +1,170 @@
+/*
+ * IMFS_create_node()
+ *
+ * Routine to create a new in memory file system node.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+
+/*
+ * Create an IMFS filesystem node of an arbitrary type that is NOT
+ * the root directory node.
+ */
+IMFS_jnode_t *IMFS_create_node(
+ rtems_filesystem_location_info_t *parent_loc,
+ IMFS_jnode_types_t type,
+ const char *name,
+ mode_t mode,
+ const IMFS_types_union *info
+)
+{
+ IMFS_jnode_t *node;
+ IMFS_jnode_t *parent;
+ IMFS_fs_info_t *fs_info;
+
+ /*
+ * MUST have a parent node to call this routine.
+ */
+ if ( parent_loc == NULL )
+ return NULL;
+
+ parent = parent_loc->node_access;
+ fs_info = parent_loc->mt_entry->fs_info;
+
+ /*
+ * Reject creation of FIFOs if support is disabled.
+ */
+ if ( type == IMFS_FIFO &&
+ fs_info->fifo_handlers == &rtems_filesystem_handlers_default )
+ return NULL;
+
+ /*
+ * Allocate filesystem node and fill in basic information
+ */
+ node = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
+ if ( !node )
+ return NULL;
+
+ /*
+ * Set the type specific information
+ */
+ if ( type == IMFS_DIRECTORY ) {
+ rtems_chain_initialize_empty(&node->info.directory.Entries);
+ } else if ( type == IMFS_HARD_LINK ) {
+ node->info.hard_link.link_node = info->hard_link.link_node;
+ } else if ( type == IMFS_SYM_LINK ) {
+ node->info.sym_link.name = info->sym_link.name;
+ } else if ( type == IMFS_DEVICE ) {
+ node->info.device.major = info->device.major;
+ node->info.device.minor = info->device.minor;
+ } else if ( type == IMFS_LINEAR_FILE ) {
+ node->info.linearfile.size = 0;
+ node->info.linearfile.direct = 0;
+ } else if ( type == IMFS_MEMORY_FILE ) {
+ node->info.file.size = 0;
+ node->info.file.indirect = 0;
+ node->info.file.doubly_indirect = 0;
+ node->info.file.triply_indirect = 0;
+ } else if ( type == IMFS_FIFO ) {
+ node->info.fifo.pipe = NULL;
+ } else {
+ IMFS_assert(0);
+ }
+
+ /*
+ * This node MUST have a parent, so put it in that directory list.
+ */
+ node->Parent = parent;
+ node->st_ino = ++fs_info->ino_count;
+
+ rtems_chain_append( &parent->info.directory.Entries, &node->Node );
+
+ return node;
+}
+
+/*
+ * Allocate filesystem node and fill in basic information
+ */
+IMFS_jnode_t *IMFS_allocate_node(
+ IMFS_jnode_types_t type,
+ const char *name,
+ mode_t mode
+)
+{
+ IMFS_jnode_t *node;
+ struct timeval tv;
+
+ /*
+ * Allocate an IMFS jnode
+ */
+ node = calloc( 1, sizeof( IMFS_jnode_t ) );
+ if ( !node )
+ return NULL;
+
+ /*
+ * Fill in the basic information
+ */
+ node->st_nlink = 1;
+ node->type = type;
+ strncpy( node->name, name, IMFS_NAME_MAX );
+
+ /*
+ * Fill in the mode and permission information for the jnode structure.
+ */
+ node->st_mode = mode;
+ #if defined(RTEMS_POSIX_API)
+ node->st_uid = geteuid();
+ node->st_gid = getegid();
+ #else
+ node->st_uid = 0;
+ node->st_gid = 0;
+ #endif
+
+ /*
+ * Now set all the times.
+ */
+ gettimeofday( &tv, 0 );
+
+ node->stat_atime = (time_t) tv.tv_sec;
+ node->stat_mtime = (time_t) tv.tv_sec;
+ node->stat_ctime = (time_t) tv.tv_sec;
+
+ return node;
+}
+
+IMFS_jnode_t *IMFS_create_root_node(void)
+{
+ IMFS_jnode_t *node;
+
+ /*
+ * Allocate filesystem node and fill in basic information
+ */
+ node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
+ if ( !node )
+ return NULL;
+
+ /*
+ * Set the type specific information
+ *
+ * NOTE: Root node is always a directory.
+ */
+ rtems_chain_initialize_empty(&node->info.directory.Entries);
+
+ return node;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_debug.c b/cpukit/libfs/src/imfs/imfs_debug.c
new file mode 100644
index 0000000000..0a4e3a9bba
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_debug.c
@@ -0,0 +1,159 @@
+/*
+ * IMFS debug support routines
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h> /* for close */
+#include <inttypes.h>
+
+#include <stdio.h>
+#include <sys/stat.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+
+/*
+ * IMFS_print_jnode
+ *
+ * This routine prints the contents of the specified jnode.
+ */
+void IMFS_print_jnode(
+ IMFS_jnode_t *the_jnode
+)
+{
+ IMFS_assert( the_jnode );
+
+ fprintf(stdout, "%s", the_jnode->name );
+ switch( the_jnode->type ) {
+ case IMFS_DIRECTORY:
+ fprintf(stdout, "/" );
+ break;
+
+ case IMFS_DEVICE:
+ fprintf(stdout, " (device %" PRId32 ", %" PRId32 ")",
+ the_jnode->info.device.major, the_jnode->info.device.minor );
+ break;
+
+ case IMFS_LINEAR_FILE:
+ fprintf(stdout, " (file %" PRId32 " %p)",
+ (uint32_t)the_jnode->info.linearfile.size,
+ the_jnode->info.linearfile.direct
+ );
+ break;
+
+ case IMFS_MEMORY_FILE:
+ /* Useful when debugging .. varies between targets */
+#if 0
+ fprintf(stdout, " (file %" PRId32 " %p %p %p)",
+ (uint32_t)the_jnode->info.file.size,
+ the_jnode->info.file.indirect,
+ the_jnode->info.file.doubly_indirect,
+ the_jnode->info.file.triply_indirect
+ );
+#else
+ fprintf(stdout, " (file %" PRId32 ")",
+ (uint32_t)the_jnode->info.file.size );
+#endif
+ break;
+
+ case IMFS_HARD_LINK:
+ fprintf(stdout, " links not printed\n" );
+ return;
+
+ case IMFS_SYM_LINK:
+ fprintf(stdout, " links not printed\n" );
+ return;
+
+ case IMFS_FIFO:
+ fprintf(stdout, " FIFO not printed\n" );
+ return;
+
+ default:
+ fprintf(stdout, " bad type %d\n", the_jnode->type );
+ return;
+ }
+ puts("");
+}
+
+/*
+ * IMFS_dump_directory
+ *
+ * This routine prints the contents of a directory in the IMFS. If a
+ * directory is encountered, then this routine will recurse to process
+ * the subdirectory.
+ */
+void IMFS_dump_directory(
+ IMFS_jnode_t *the_directory,
+ int level
+)
+{
+ rtems_chain_node *the_node;
+ rtems_chain_control *the_chain;
+ IMFS_jnode_t *the_jnode;
+ int i;
+
+ IMFS_assert( the_directory );
+ IMFS_assert( level >= 0 );
+ IMFS_assert( the_directory->type == IMFS_DIRECTORY );
+
+ the_chain = &the_directory->info.directory.Entries;
+
+ for ( the_node = rtems_chain_first( the_chain );
+ !rtems_chain_is_tail( the_chain, the_node );
+ the_node = the_node->next ) {
+
+ the_jnode = (IMFS_jnode_t *) the_node;
+
+ for ( i=0 ; i<=level ; i++ )
+ fprintf(stdout, "...." );
+ IMFS_print_jnode( the_jnode );
+ if ( the_jnode->type == IMFS_DIRECTORY )
+ IMFS_dump_directory( the_jnode, level + 1 );
+ }
+}
+
+/*
+ * IMFS_dump
+ *
+ * This routine dumps the entire IMFS that is mounted at the root
+ * directory.
+ *
+ * NOTE: Assuming the "/" directory is bad.
+ * Not checking that the starting directory is in an IMFS is bad.
+ */
+
+void IMFS_dump( void )
+{
+ fprintf(stdout, "*************** Dump of Entire IMFS ***************\n" );
+ fprintf(stdout, "/\n" );
+ IMFS_dump_directory( rtems_filesystem_root.node_access, 0 );
+ fprintf(stdout, "*************** End of Dump ***************\n" );
+}
+
+/*
+ * IMFS_memfile_maximum_size()
+ *
+ * This routine returns the size of the largest file which can be created
+ * using the IMFS memory file type.
+ *
+ */
+int IMFS_memfile_maximum_size( void )
+{
+ return IMFS_MEMFILE_MAXIMUM_SIZE;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_directory.c b/cpukit/libfs/src/imfs/imfs_directory.c
new file mode 100644
index 0000000000..46ff335e59
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_directory.c
@@ -0,0 +1,317 @@
+/*
+ * IMFS Directory Access Routines
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <rtems/chain.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <dirent.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+/*
+ * imfs_dir_open
+ *
+ * This rountine will verify that the node being opened as a directory is
+ * in fact a directory node. If it is then the offset into the directory
+ * will be set to 0 to position to the first directory entry.
+ */
+
+int imfs_dir_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ /* Is the node a directory ? */
+ the_jnode = (IMFS_jnode_t *) iop->pathinfo.node_access;
+
+ if ( the_jnode->type != IMFS_DIRECTORY )
+ return -1; /* It wasn't a directory --> return error */
+
+ iop->offset = 0;
+ return 0;
+}
+
+/*
+ * imfs_dir_read
+ *
+ * This routine will read the next directory entry based on the directory
+ * offset. The offset should be equal to -n- time the size of an individual
+ * dirent structure. If n is not an integer multiple of the sizeof a
+ * dirent structure, an integer division will be performed to determine
+ * directory entry that will be returned in the buffer. Count should reflect
+ * -m- times the sizeof dirent bytes to be placed in the buffer.
+ * If there are not -m- dirent elements from the current directory position
+ * to the end of the exisiting file, the remaining entries will be placed in
+ * the buffer and the returned value will be equal to -m actual- times the
+ * size of a directory entry.
+ */
+
+ssize_t imfs_dir_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ /*
+ * Read up to element iop->offset in the directory chain of the
+ * imfs_jnode_t struct for this file descriptor.
+ */
+ rtems_chain_node *the_node;
+ rtems_chain_control *the_chain;
+ IMFS_jnode_t *the_jnode;
+ int bytes_transferred;
+ int current_entry;
+ int first_entry;
+ int last_entry;
+ struct dirent tmp_dirent;
+
+ the_jnode = (IMFS_jnode_t *)iop->pathinfo.node_access;
+ the_chain = &the_jnode->info.directory.Entries;
+
+ if ( rtems_chain_is_empty( the_chain ) )
+ return 0;
+
+ /* Move to the first of the desired directory entries */
+ the_node = rtems_chain_first( the_chain );
+
+ bytes_transferred = 0;
+ first_entry = iop->offset;
+ /* protect against using sizes that are not exact multiples of the */
+ /* -dirent- size. These could result in unexpected results */
+ last_entry = first_entry + (count/sizeof(struct dirent)) * sizeof(struct dirent);
+
+ /* The directory was not empty so try to move to the desired entry in chain*/
+ for (
+ current_entry = 0;
+ current_entry < last_entry;
+ current_entry = current_entry + sizeof(struct dirent) ){
+
+ if ( rtems_chain_is_tail( the_chain, the_node ) ){
+ /* We hit the tail of the chain while trying to move to the first */
+ /* entry in the read */
+ return bytes_transferred; /* Indicate that there are no more */
+ /* entries to return */
+ }
+
+ if( current_entry >= first_entry ) {
+ /* Move the entry to the return buffer */
+ tmp_dirent.d_off = current_entry;
+ tmp_dirent.d_reclen = sizeof( struct dirent );
+ the_jnode = (IMFS_jnode_t *) the_node;
+ tmp_dirent.d_ino = the_jnode->st_ino;
+ tmp_dirent.d_namlen = strlen( the_jnode->name );
+ strcpy( tmp_dirent.d_name, the_jnode->name );
+ memcpy(
+ buffer + bytes_transferred,
+ (void *)&tmp_dirent,
+ sizeof( struct dirent )
+ );
+ iop->offset = iop->offset + sizeof(struct dirent);
+ bytes_transferred = bytes_transferred + sizeof( struct dirent );
+ }
+
+ the_node = the_node->next;
+ }
+
+ /* Success */
+ return bytes_transferred;
+}
+
+
+
+/*
+ * imfs_dir_close
+ *
+ * This routine will be called by the generic close routine to cleanup any
+ * resources that have been allocated for the management of the file
+ */
+
+int imfs_dir_close(
+ rtems_libio_t *iop
+)
+{
+ /*
+ * The generic close routine handles the deallocation of the file control
+ * and associated memory. At present the imfs_dir_close simply
+ * returns a successful completion status.
+ */
+
+ return 0;
+}
+
+
+
+/*
+ * imfs_dir_lseek
+ *
+ * This routine will behave in one of three ways based on the state of
+ * argument whence. Based on the state of its value the offset argument will
+ * be interpreted using one of the following methods:
+ *
+ * SEEK_SET - offset is the absolute byte offset from the start of the
+ * logical start of the dirent sequence that represents the
+ * directory
+ * SEEK_CUR - offset is used as the relative byte offset from the current
+ * directory position index held in the iop structure
+ * SEEK_END - N/A --> This will cause an EINVAL to be returned.
+ */
+
+rtems_off64_t imfs_dir_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t offset,
+ int whence
+)
+{
+ switch( whence ) {
+ case SEEK_SET: /* absolute move from the start of the file */
+ case SEEK_CUR: /* relative move */
+ iop->offset = (iop->offset/sizeof(struct dirent)) *
+ sizeof(struct dirent);
+ break;
+
+ case SEEK_END: /* Movement past the end of the directory via lseek */
+ /* is not a permitted operation */
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ break;
+ }
+
+ return 0;
+}
+
+
+
+/*
+ * imfs_dir_fstat
+ *
+ * This routine will obtain the following information concerning the current
+ * directory:
+ * st_dev 0ll
+ * st_ino 1
+ * st_mode mode extracted from the jnode
+ * st_nlink number of links to this node
+ * st_uid uid extracted from the jnode
+ * st_gid gid extracted from the jnode
+ * st_rdev 0ll
+ * st_size the number of bytes in the directory
+ * This is calculated by taking the number of entries
+ * in the directory and multiplying by the size of a
+ * dirent structure
+ * st_blksize 0
+ * st_blocks 0
+ * stat_atime time of last access
+ * stat_mtime time of last modification
+ * stat_ctime time of the last change
+ *
+ * This information will be returned to the calling function in a -stat- struct
+ *
+ */
+
+int imfs_dir_fstat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+)
+{
+ rtems_chain_node *the_node;
+ rtems_chain_control *the_chain;
+ IMFS_jnode_t *the_jnode;
+
+
+ the_jnode = (IMFS_jnode_t *) loc->node_access;
+
+ buf->st_dev = 0ll;
+ buf->st_ino = the_jnode->st_ino;
+ buf->st_mode = the_jnode->st_mode;
+ buf->st_nlink = the_jnode->st_nlink;
+ buf->st_uid = the_jnode->st_uid;
+ buf->st_gid = the_jnode->st_gid;
+ buf->st_rdev = 0ll;
+ buf->st_blksize = 0;
+ buf->st_blocks = 0;
+ buf->st_atime = the_jnode->stat_atime;
+ buf->st_mtime = the_jnode->stat_mtime;
+ buf->st_ctime = the_jnode->stat_ctime;
+
+ buf->st_size = 0;
+
+ the_chain = &the_jnode->info.directory.Entries;
+
+ /* Run through the chain and count the number of directory entries */
+ /* that are subordinate to this directory node */
+ for ( the_node = rtems_chain_first( the_chain );
+ !rtems_chain_is_tail( the_chain, the_node ) ;
+ the_node = the_node->next ) {
+
+ buf->st_size = buf->st_size + sizeof( struct dirent );
+ }
+
+ return 0;
+}
+
+/*
+ * IMFS_dir_rmnod
+ *
+ * This routine is available from the optable to remove a node
+ * from the IMFS file system.
+ */
+
+int imfs_dir_rmnod(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = (IMFS_jnode_t *) pathloc->node_access;
+
+ /*
+ * You cannot remove a node that still has children
+ */
+
+ if ( ! rtems_chain_is_empty( &the_jnode->info.directory.Entries ) )
+ rtems_set_errno_and_return_minus_one( ENOTEMPTY );
+
+ /*
+ * You cannot remove the file system root node.
+ */
+
+ if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access )
+ rtems_set_errno_and_return_minus_one( EBUSY );
+
+ /*
+ * You cannot remove a mountpoint.
+ */
+
+ if ( the_jnode->info.directory.mt_fs != NULL )
+ rtems_set_errno_and_return_minus_one( EBUSY );
+
+ IMFS_create_orphan( the_jnode );
+ IMFS_check_node_remove( the_jnode );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_eval.c b/cpukit/libfs/src/imfs/imfs_eval.c
new file mode 100644
index 0000000000..503c65179a
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_eval.c
@@ -0,0 +1,663 @@
+/*
+ * Evaluation IMFS Node Support Routines
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#define RTEMS_LIBIO_PERMS_RX (RTEMS_LIBIO_PERMS_SEARCH | RTEMS_LIBIO_PERMS_READ)
+#define RTEMS_LIBIO_PERMS_WX (RTEMS_LIBIO_PERMS_SEARCH | RTEMS_LIBIO_PERMS_WRITE)
+
+#define MAXSYMLINK 5
+
+int IMFS_Set_handlers(
+ rtems_filesystem_location_info_t *loc
+)
+{
+ IMFS_jnode_t *node = loc->node_access;
+ IMFS_fs_info_t *fs_info;
+
+ fs_info = loc->mt_entry->fs_info;
+ switch( node->type ) {
+ case IMFS_DIRECTORY:
+ loc->handlers = fs_info->directory_handlers;
+ break;
+ case IMFS_DEVICE:
+ loc->handlers = &IMFS_device_handlers;
+ break;
+ case IMFS_SYM_LINK:
+ case IMFS_HARD_LINK:
+ loc->handlers = &IMFS_link_handlers;
+ break;
+ case IMFS_LINEAR_FILE:
+ loc->handlers = fs_info->memfile_handlers;
+ break;
+ case IMFS_MEMORY_FILE:
+ loc->handlers = fs_info->memfile_handlers;
+ break;
+ case IMFS_FIFO:
+ loc->handlers = fs_info->fifo_handlers;
+ break;
+ }
+
+ return 0;
+}
+
+/*
+ * IMFS_evaluate_permission
+ *
+ * The following routine evaluates that we have permission
+ * to do flags on the node.
+ */
+int IMFS_evaluate_permission(
+ rtems_filesystem_location_info_t *node,
+ int flags
+)
+{
+ uid_t st_uid;
+ gid_t st_gid;
+ IMFS_jnode_t *jnode;
+ int flags_to_test;
+
+ if ( !rtems_libio_is_valid_perms( flags ) )
+ rtems_set_errno_and_return_minus_one( EPERM );
+
+ jnode = node->node_access;
+
+#if defined(RTEMS_POSIX_API)
+ st_uid = geteuid();
+ st_gid = getegid();
+#else
+ st_uid = jnode->st_uid;
+ st_gid = jnode->st_gid;
+#endif
+
+ /*
+ * Check if I am owner or a group member or someone else.
+ */
+
+ flags_to_test = flags;
+
+ if ( st_uid == jnode->st_uid )
+ flags_to_test <<= 6;
+ else if ( st_gid == jnode->st_gid )
+ flags_to_test <<= 3;
+ else {
+ /* must be other - do nothing */;
+ }
+
+ /*
+ * If all of the flags are set we have permission
+ * to do this.
+ */
+ if ( ( flags_to_test & jnode->st_mode) == flags_to_test )
+ return 1;
+
+ return 0;
+}
+
+/*
+ * IMFS_evaluate_hard_link
+ *
+ * The following routine evaluates a hardlink to the actual node.
+ */
+
+int IMFS_evaluate_hard_link(
+ rtems_filesystem_location_info_t *node, /* IN/OUT */
+ int flags /* IN */
+)
+{
+ IMFS_jnode_t *jnode = node->node_access;
+ int result = 0;
+
+ /*
+ * Check for things that should never happen.
+ */
+ IMFS_assert( jnode->type == IMFS_HARD_LINK );
+
+ /*
+ * Set the hard link value and the handlers.
+ */
+ node->node_access = jnode->info.hard_link.link_node;
+
+ IMFS_Set_handlers( node );
+
+ /*
+ * Verify we have the correct permissions for this node.
+ */
+
+ if ( !IMFS_evaluate_permission( node, flags ) )
+ rtems_set_errno_and_return_minus_one( EACCES );
+
+ return result;
+}
+
+
+/*
+ * IMFS_evaluate_sym_link
+ *
+ * The following routine evaluates a symbolic link to the actual node.
+ */
+
+int IMFS_evaluate_sym_link(
+ rtems_filesystem_location_info_t *node, /* IN/OUT */
+ int flags /* IN */
+)
+{
+ IMFS_jnode_t *jnode = node->node_access;
+ int result = 0;
+ int i;
+
+ /*
+ * Check for things that should never happen.
+ */
+ IMFS_assert( jnode->type == IMFS_SYM_LINK );
+ IMFS_assert( jnode->Parent );
+
+ /*
+ * Move the node_access to either the symbolic links parent or
+ * root depending on the symbolic links path.
+ */
+ node->node_access = jnode->Parent;
+
+ rtems_filesystem_get_sym_start_loc(
+ jnode->info.sym_link.name,
+ &i,
+ node
+ );
+
+ /*
+ * Use eval path to evaluate the path of the symbolic link.
+ */
+ result = IMFS_eval_path(
+ &jnode->info.sym_link.name[i],
+ strlen( &jnode->info.sym_link.name[i] ),
+ flags,
+ node
+ );
+
+ IMFS_Set_handlers( node );
+
+ /*
+ * Verify we have the correct permissions for this node.
+ */
+ if ( !IMFS_evaluate_permission( node, flags ) )
+ rtems_set_errno_and_return_minus_one( EACCES );
+
+ return result;
+}
+
+/*
+ * IMFS_evaluate_link
+ *
+ * The following routine returns the real node pointed to by a link.
+ */
+int IMFS_evaluate_link(
+ rtems_filesystem_location_info_t *node, /* IN/OUT */
+ int flags /* IN */
+)
+{
+ IMFS_jnode_t *jnode;
+ int result = 0;
+
+ do {
+ jnode = node->node_access;
+
+ /*
+ * Increment and check the link counter.
+ */
+
+ rtems_filesystem_link_counts ++;
+ if ( rtems_filesystem_link_counts > MAXSYMLINK ) {
+ rtems_filesystem_link_counts = 0;
+ rtems_set_errno_and_return_minus_one( ELOOP );
+ }
+
+ /*
+ * Follow the Link node.
+ */
+
+ if ( jnode->type == IMFS_HARD_LINK )
+ result = IMFS_evaluate_hard_link( node, flags );
+
+ else if (jnode->type == IMFS_SYM_LINK )
+ result = IMFS_evaluate_sym_link( node, flags );
+
+ } while ( ( result == 0 ) && ( ( jnode->type == IMFS_SYM_LINK ) ||
+ ( jnode->type == IMFS_HARD_LINK ) ) );
+
+ /*
+ * Clear link counter.
+ */
+
+ rtems_filesystem_link_counts = 0;
+
+ return result;
+}
+
+
+/*
+ * IMFS_evaluate_for_make
+ *
+ * The following routine evaluate path for a new node to be created.
+ * pathloc is returned with a pointer to the parent of the new node.
+ * name is returned with a pointer to the first character in the
+ * new node name. The parent node is verified to be a directory.
+ */
+
+int IMFS_evaluate_for_make(
+ const char *path, /* IN */
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ const char **name /* OUT */
+)
+{
+ int i = 0;
+ int len;
+ IMFS_token_types type;
+ char token[ IMFS_NAME_MAX + 1 ];
+ rtems_filesystem_location_info_t newloc;
+ IMFS_jnode_t *node;
+ bool done = false;
+ int pathlen;
+ int result;
+
+ /*
+ * This was filled in by the caller and is valid in the
+ * mount table.
+ */
+ node = pathloc->node_access;
+
+ /*
+ * Get the path length.
+ */
+ pathlen = strlen( path );
+ /*
+ * Evaluate all tokens until we are done or an error occurs.
+ */
+
+ while( !done ) {
+
+ type = IMFS_get_token( &path[i], pathlen, token, &len );
+ pathlen -= len;
+ i += len;
+
+ if ( !pathloc->node_access )
+ rtems_set_errno_and_return_minus_one( ENOENT );
+
+ /*
+ * I cannot move out of this directory without execute permission.
+ */
+
+ if ( type != IMFS_NO_MORE_PATH )
+ if ( node->type == IMFS_DIRECTORY )
+ if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) )
+ rtems_set_errno_and_return_minus_one( EACCES );
+
+ node = pathloc->node_access;
+
+ switch( type ) {
+
+ case IMFS_UP_DIR:
+ /*
+ * Am I at the root of all filesystems? (chroot'ed?)
+ */
+
+ if ( pathloc->node_access == rtems_filesystem_root.node_access )
+ break; /* Throw out the .. in this case */
+
+
+ /*
+ * Am I at the root of this mounted filesystem?
+ */
+
+ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access){
+
+ /*
+ * Am I at the root of all filesystems?
+ */
+
+ if ( pathloc->node_access == rtems_filesystem_root.node_access ) {
+ break;
+
+ } else {
+ newloc = pathloc->mt_entry->mt_point_node;
+ *pathloc = newloc;
+ return (*pathloc->ops->evalformake_h)( &path[i-len], pathloc, name );
+ }
+ } else {
+
+ if ( !node->Parent )
+ rtems_set_errno_and_return_minus_one( ENOENT );
+
+ node = node->Parent;
+ }
+
+ pathloc->node_access = node;
+ break;
+
+ case IMFS_NAME:
+
+ if ( node->type == IMFS_HARD_LINK ) {
+
+ result = IMFS_evaluate_link( pathloc, 0 );
+ if ( result == -1 )
+ return -1;
+
+ } else if ( node->type == IMFS_SYM_LINK ) {
+
+ result = IMFS_evaluate_link( pathloc, 0 );
+
+ if ( result == -1 )
+ return -1;
+ }
+
+ node = pathloc->node_access;
+ if ( !node )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * Only a directory can be decended into.
+ */
+
+ if ( node->type != IMFS_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * If we are at a node that is a mount point. Set loc to the
+ * new fs root node and let them finish evaluating the path.
+ */
+
+ if ( node->info.directory.mt_fs != NULL ) {
+ newloc = node->info.directory.mt_fs->mt_fs_root;
+ *pathloc = newloc;
+ return (*pathloc->ops->evalformake_h)( &path[i-len], pathloc, name );
+ }
+
+ /*
+ * Otherwise find the token name in the present location.
+ */
+
+ node = IMFS_find_match_in_dir( node, token );
+
+ /*
+ * If there is no node we have found the name of the node we
+ * wish to create.
+ */
+
+ if ( ! node )
+ done = true;
+ else
+ pathloc->node_access = node;
+
+ break;
+
+ case IMFS_NO_MORE_PATH:
+ rtems_set_errno_and_return_minus_one( EEXIST );
+ break;
+
+ case IMFS_INVALID_TOKEN:
+ rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
+ break;
+
+ case IMFS_CURRENT_DIR:
+ break;
+ }
+ }
+
+ *name = &path[ i - len ];
+
+ /*
+ * We have evaluated the path as far as we can.
+ * Verify there is not any invalid stuff at the end of the name.
+ */
+
+ for( ; path[i] != '\0'; i++) {
+ if ( !IMFS_is_separator( path[ i ] ) )
+ rtems_set_errno_and_return_minus_one( ENOENT );
+ }
+
+ /*
+ * Verify we can execute and write to this directory.
+ */
+
+ result = IMFS_Set_handlers( pathloc );
+
+ /*
+ * The returned node must be a directory
+ */
+ node = pathloc->node_access;
+ if ( node->type != IMFS_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * We must have Write and execute permission on the returned node.
+ */
+
+ if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_WX ) )
+ rtems_set_errno_and_return_minus_one( EACCES );
+
+ return result;
+}
+
+
+/*
+ * IMFS_eval_path
+ *
+ * The following routine evaluate path for a node that wishes to be
+ * accessed with mode. pathloc is returned with a pointer to the
+ * node to be accessed.
+ */
+
+int IMFS_eval_path(
+ const char *pathname, /* IN */
+ size_t pathnamelen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+ )
+{
+ int i = 0;
+ int len;
+ IMFS_token_types type = IMFS_CURRENT_DIR;
+ char token[ IMFS_NAME_MAX + 1 ];
+ rtems_filesystem_location_info_t newloc;
+ IMFS_jnode_t *node;
+ int result;
+
+ if ( !rtems_libio_is_valid_perms( flags ) ) {
+ rtems_set_errno_and_return_minus_one( EIO );
+ }
+
+ /*
+ * This was filled in by the caller and is valid in the
+ * mount table.
+ */
+
+ node = pathloc->node_access;
+
+ /*
+ * Evaluate all tokens until we are done or an error occurs.
+ */
+
+ while( (type != IMFS_NO_MORE_PATH) && (type != IMFS_INVALID_TOKEN) ) {
+
+ type = IMFS_get_token( &pathname[i], pathnamelen, token, &len );
+ pathnamelen -= len;
+ i += len;
+
+ if ( !pathloc->node_access )
+ rtems_set_errno_and_return_minus_one( ENOENT );
+
+ /*
+ * I cannot move out of this directory without execute permission.
+ */
+ if ( type != IMFS_NO_MORE_PATH )
+ if ( node->type == IMFS_DIRECTORY )
+ if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) )
+ rtems_set_errno_and_return_minus_one( EACCES );
+
+ node = pathloc->node_access;
+
+ switch( type ) {
+ case IMFS_UP_DIR:
+ /*
+ * Am I at the root of all filesystems? (chroot'ed?)
+ */
+
+ if ( pathloc->node_access == rtems_filesystem_root.node_access )
+ break; /* Throw out the .. in this case */
+
+ /*
+ * Am I at the root of this mounted filesystem?
+ */
+
+ if (pathloc->node_access ==
+ pathloc->mt_entry->mt_fs_root.node_access) {
+
+ /*
+ * Am I at the root of all filesystems?
+ */
+
+ if ( pathloc->node_access == rtems_filesystem_root.node_access ) {
+ break; /* Throw out the .. in this case */
+ } else {
+ newloc = pathloc->mt_entry->mt_point_node;
+ *pathloc = newloc;
+ return (*pathloc->ops->evalpath_h)(&(pathname[i-len]),
+ pathnamelen+len,
+ flags,pathloc);
+ }
+ } else {
+
+ if ( !node->Parent )
+ rtems_set_errno_and_return_minus_one( ENOENT );
+
+ node = node->Parent;
+ pathloc->node_access = node;
+
+ }
+
+ pathloc->node_access = node;
+ break;
+
+ case IMFS_NAME:
+ /*
+ * If we are at a link follow it.
+ */
+ if ( node->type == IMFS_HARD_LINK ) {
+ IMFS_evaluate_hard_link( pathloc, 0 );
+ node = pathloc->node_access;
+
+ /*
+ * It would be a design error if we evaluated the link and
+ * was broken.
+ */
+ IMFS_assert( node );
+
+ } else if ( node->type == IMFS_SYM_LINK ) {
+ result = IMFS_evaluate_sym_link( pathloc, 0 );
+
+ /*
+ * In contrast to a hard link, it is possible to have a broken
+ * symbolic link.
+ */
+ node = pathloc->node_access;
+ if ( result == -1 )
+ return -1;
+ }
+
+ /*
+ * Only a directory can be decended into.
+ */
+ if ( node->type != IMFS_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * If we are at a node that is a mount point. Set loc to the
+ * new fs root node and let them finish evaluating the path.
+ */
+ if ( node->info.directory.mt_fs != NULL ) {
+ newloc = node->info.directory.mt_fs->mt_fs_root;
+ *pathloc = newloc;
+ return (*pathloc->ops->evalpath_h)( &pathname[i-len],
+ pathnamelen+len,
+ flags, pathloc );
+ }
+
+ /*
+ * Otherwise find the token name in the present location.
+ */
+ node = IMFS_find_match_in_dir( node, token );
+ if ( !node )
+ rtems_set_errno_and_return_minus_one( ENOENT );
+
+ /*
+ * Set the node access to the point we have found.
+ */
+
+ pathloc->node_access = node;
+ break;
+
+ case IMFS_NO_MORE_PATH:
+ case IMFS_CURRENT_DIR:
+ break;
+
+ case IMFS_INVALID_TOKEN:
+ rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
+ break;
+
+ }
+ }
+
+ /*
+ * Always return the root node.
+ *
+ * If we are at a node that is a mount point. Set loc to the
+ * new fs root node and let let the mounted filesystem set the handlers.
+ *
+ * NOTE: The behavior of stat() on a mount point appears to be questionable.
+ */
+
+ if ( node->type == IMFS_DIRECTORY ) {
+ if ( node->info.directory.mt_fs != NULL ) {
+ newloc = node->info.directory.mt_fs->mt_fs_root;
+ *pathloc = newloc;
+ return (*pathloc->ops->evalpath_h)( &pathname[i-len],
+ pathnamelen+len,
+ flags, pathloc );
+ } else {
+ result = IMFS_Set_handlers( pathloc );
+ }
+ } else {
+ result = IMFS_Set_handlers( pathloc );
+ }
+
+ /*
+ * Verify we have the correct permissions for this node.
+ */
+
+ if ( !IMFS_evaluate_permission( pathloc, flags ) )
+ rtems_set_errno_and_return_minus_one( EACCES );
+
+ return result;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_fchmod.c b/cpukit/libfs/src/imfs/imfs_fchmod.c
new file mode 100644
index 0000000000..54a093de2f
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_fchmod.c
@@ -0,0 +1,56 @@
+/*
+ * IMFS file change mode routine.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include "imfs.h"
+
+int IMFS_fchmod(
+ rtems_filesystem_location_info_t *loc,
+ mode_t mode
+)
+{
+ IMFS_jnode_t *jnode;
+#if defined(RTEMS_POSIX_API)
+ uid_t st_uid;
+#endif
+
+ jnode = loc->node_access;
+
+ /*
+ * Verify I am the owner of the node or the super user.
+ */
+#if defined(RTEMS_POSIX_API)
+ st_uid = geteuid();
+
+ if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) )
+ rtems_set_errno_and_return_minus_one( EPERM );
+#endif
+
+ /*
+ * Change only the RWX permissions on the jnode to mode.
+ */
+
+ jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+ jnode->st_mode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+
+ IMFS_update_ctime( jnode );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_fdatasync.c b/cpukit/libfs/src/imfs/imfs_fdatasync.c
new file mode 100644
index 0000000000..6b107bfaf8
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_fdatasync.c
@@ -0,0 +1,29 @@
+/*
+ * IMFS_fdatasync
+ *
+ * The following routine does a sync on an IMFS node. The In Memory
+ * File System is always in sync, therefore this routine always returns
+ * pass.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "imfs.h"
+
+int IMFS_fdatasync(
+ rtems_libio_t *iop
+)
+{
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_fifo.c b/cpukit/libfs/src/imfs/imfs_fifo.c
new file mode 100644
index 0000000000..7cb3bbcd85
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_fifo.c
@@ -0,0 +1,148 @@
+/*
+ * imfs_fifo.c: FIFO support for IMFS
+ *
+ * Author: Wei Shen <cquark@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#include "imfs.h"
+
+#define JNODE2PIPE(_jnode) ( (_jnode)->info.fifo.pipe )
+
+#define LIBIO2PIPE(_iop) ( JNODE2PIPE((IMFS_jnode_t *)(_iop)->pathinfo.node_access) )
+
+/* Set errno and return -1 if error, else return _err */
+#define IMFS_FIFO_RETURN(_err) \
+do { \
+ if (_err < 0) \
+ rtems_set_errno_and_return_minus_one(-_err); \
+ return _err; \
+} while (0)
+
+int IMFS_fifo_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ IMFS_jnode_t *jnode = iop->pathinfo.node_access;
+
+ int err = fifo_open(&JNODE2PIPE(jnode), iop);
+ IMFS_FIFO_RETURN(err);
+}
+
+int IMFS_fifo_close(
+ rtems_libio_t *iop
+)
+{
+ int err = 0;
+ IMFS_jnode_t *jnode = iop->pathinfo.node_access;
+
+ pipe_release(&JNODE2PIPE(jnode), iop);
+
+ iop->flags &= ~LIBIO_FLAGS_OPEN;
+ IMFS_check_node_remove(jnode);
+
+ IMFS_FIFO_RETURN(err);
+}
+
+ssize_t IMFS_fifo_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ IMFS_jnode_t *jnode = iop->pathinfo.node_access;
+
+ int err = pipe_read(JNODE2PIPE(jnode), buffer, count, iop);
+ if (err > 0)
+ IMFS_update_atime(jnode);
+
+ IMFS_FIFO_RETURN(err);
+}
+
+ssize_t IMFS_fifo_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ IMFS_jnode_t *jnode = iop->pathinfo.node_access;
+
+ int err = pipe_write(JNODE2PIPE(jnode), buffer, count, iop);
+ if (err > 0) {
+ IMFS_mtime_ctime_update(jnode);
+ }
+
+ IMFS_FIFO_RETURN(err);
+}
+
+int IMFS_fifo_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+)
+{
+ int err;
+
+ if (command == FIONBIO) {
+ if (buffer == NULL)
+ err = -EFAULT;
+ else {
+ if (*(int *)buffer)
+ iop->flags |= LIBIO_FLAGS_NO_DELAY;
+ else
+ iop->flags &= ~LIBIO_FLAGS_NO_DELAY;
+ return 0;
+ }
+ }
+ else
+ err = pipe_ioctl(LIBIO2PIPE(iop), command, buffer, iop);
+
+ IMFS_FIFO_RETURN(err);
+}
+
+rtems_off64_t IMFS_fifo_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t offset,
+ int whence
+)
+{
+ off_t err = pipe_lseek(LIBIO2PIPE(iop), offset, whence, iop);
+ IMFS_FIFO_RETURN(err);
+}
+
+/*
+ * Handler table for IMFS FIFO nodes
+ */
+
+const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
+ IMFS_fifo_open,
+ IMFS_fifo_close,
+ IMFS_fifo_read,
+ IMFS_fifo_write,
+ IMFS_fifo_ioctl,
+ IMFS_fifo_lseek,
+ IMFS_stat,
+ IMFS_fchmod,
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ IMFS_rmnod,
+};
diff --git a/cpukit/libfs/src/imfs/imfs_fsunmount.c b/cpukit/libfs/src/imfs/imfs_fsunmount.c
new file mode 100644
index 0000000000..b65c20e60d
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_fsunmount.c
@@ -0,0 +1,94 @@
+/*
+ * IMFS Initialization
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h> /* for mkdir */
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+
+#if defined(IMFS_DEBUG)
+#include <stdio.h>
+#endif
+
+/*
+ * IMFS_fsunmount
+ */
+
+#define jnode_get_control( jnode ) \
+ (&jnode->info.directory.Entries)
+
+#define jnode_has_no_children( jnode ) \
+ rtems_chain_is_empty( jnode_get_control( jnode ) )
+
+#define jnode_has_children( jnode ) \
+ ( ! jnode_has_no_children( jnode ) )
+
+#define jnode_get_first_child( jnode ) \
+ ((IMFS_jnode_t *)( rtems_chain_head( jnode_get_control( jnode ) )->next))
+
+int IMFS_fsunmount(
+ rtems_filesystem_mount_table_entry_t *temp_mt_entry
+)
+{
+ IMFS_jnode_t *jnode;
+ IMFS_jnode_t *next;
+ rtems_filesystem_location_info_t loc;
+ int result = 0;
+
+ /*
+ * Traverse tree that starts at the mt_fs_root and deallocate memory
+ * associated memory space
+ */
+
+ jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access;
+ loc = temp_mt_entry->mt_fs_root;
+
+ /*
+ * Set this to null to indicate that it is being unmounted.
+ */
+
+ temp_mt_entry->mt_fs_root.node_access = NULL;
+
+ do {
+ next = jnode->Parent;
+ loc.node_access = (void *)jnode;
+ IMFS_Set_handlers( &loc );
+
+ if ( jnode->type != IMFS_DIRECTORY ) {
+ result = IMFS_unlink( NULL, &loc );
+ if (result != 0)
+ return -1;
+ jnode = next;
+ } else if ( jnode_has_no_children( jnode ) ) {
+ result = IMFS_unlink( NULL, &loc );
+ if (result != 0)
+ return -1;
+ jnode = next;
+ }
+ if ( jnode != NULL ) {
+ if ( jnode->type == IMFS_DIRECTORY ) {
+ if ( jnode_has_children( jnode ) )
+ jnode = jnode_get_first_child( jnode );
+ }
+ }
+ } while (jnode != NULL);
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_getchild.c b/cpukit/libfs/src/imfs/imfs_getchild.c
new file mode 100644
index 0000000000..1cfeb2a537
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_getchild.c
@@ -0,0 +1,66 @@
+/*
+ * IMFS_find_match_in_dir()
+ *
+ * This routine returns the child name in the given directory.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include "imfs.h"
+
+static const char dotname[2] = ".";
+static const char dotdotname[3] = "..";
+
+IMFS_jnode_t *IMFS_find_match_in_dir(
+ IMFS_jnode_t *directory,
+ char *name
+)
+{
+ rtems_chain_node *the_node;
+ rtems_chain_control *the_chain;
+ IMFS_jnode_t *the_jnode;
+
+ /*
+ * Check for fatal errors. A NULL directory show a problem in the
+ * the IMFS code.
+ */
+ IMFS_assert( directory );
+ IMFS_assert( name );
+
+ /*
+ * Check for "." and ".."
+ */
+
+ if ( !strcmp( name, dotname ) )
+ return directory;
+
+ if ( !strcmp( name, dotdotname ) )
+ return directory->Parent;
+
+ the_chain = &directory->info.directory.Entries;
+
+ for ( the_node = rtems_chain_first( the_chain );
+ !rtems_chain_is_tail( the_chain, the_node );
+ the_node = the_node->next ) {
+
+ the_jnode = (IMFS_jnode_t *) the_node;
+
+ if ( !strcmp( name, the_jnode->name ) )
+ return the_jnode;
+ }
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_gtkn.c b/cpukit/libfs/src/imfs/imfs_gtkn.c
new file mode 100644
index 0000000000..b15b2f1136
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_gtkn.c
@@ -0,0 +1,91 @@
+/*
+ * IMFS_get_token
+ *
+ * Routine to get a token (name or separator) from the path
+ * the length of the token is returned in token_len.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+
+IMFS_token_types IMFS_get_token(
+ const char *path,
+ int pathlen,
+ char *token,
+ int *token_len
+)
+{
+ register int i = 0;
+ IMFS_token_types type = IMFS_NAME;
+ register char c;
+
+ /*
+ * Copy a name into token. (Remember NULL is a token.)
+ */
+ c = path[i];
+ while ( (!IMFS_is_separator(c)) && (i < pathlen) && (i <= IMFS_NAME_MAX) ) {
+
+ token[i] = c;
+
+ if ( i == IMFS_NAME_MAX )
+ return IMFS_INVALID_TOKEN;
+
+ if ( !IMFS_is_valid_name_char(c) )
+ type = IMFS_INVALID_TOKEN;
+
+ c = path [++i];
+ }
+
+ /*
+ * Copy a seperator into token.
+ */
+
+ if ( i == 0 ) {
+ token[i] = c;
+
+ if ( (token[i] != '\0') && pathlen ) {
+ i++;
+ type = IMFS_CURRENT_DIR;
+ } else {
+ type = IMFS_NO_MORE_PATH;
+ }
+ } else if (token[ i-1 ] != '\0') {
+ token[i] = '\0';
+ }
+
+ /*
+ * Set token_len to the number of characters copied.
+ */
+
+ *token_len = i;
+
+ /*
+ * If we copied something that was not a seperator see if
+ * it was a special name.
+ */
+
+ if ( type == IMFS_NAME ) {
+ if ( strcmp( token, "..") == 0 )
+ type = IMFS_UP_DIR;
+ else if ( strcmp( token, "." ) == 0 )
+ type = IMFS_CURRENT_DIR;
+ }
+
+ return type;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_device.c b/cpukit/libfs/src/imfs/imfs_handlers_device.c
new file mode 100644
index 0000000000..025fb985cf
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_handlers_device.c
@@ -0,0 +1,41 @@
+/*
+ * Device Operations Table for the IMFS
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include "imfs.h"
+
+/*
+ * Handler table for IMFS device nodes
+ */
+
+const rtems_filesystem_file_handlers_r IMFS_device_handlers = {
+ device_open,
+ device_close,
+ device_read,
+ device_write,
+ device_ioctl,
+ device_lseek,
+ IMFS_stat,
+ IMFS_fchmod,
+ device_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ IMFS_rmnod
+};
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_directory.c b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
new file mode 100644
index 0000000000..d70957d018
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_handlers_directory.c
@@ -0,0 +1,41 @@
+/*
+ * Operations Table for Directories for the IMFS
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include "imfs.h"
+
+/*
+ * Set of operations handlers for operations on directories.
+ */
+
+const rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
+ imfs_dir_open,
+ imfs_dir_close,
+ imfs_dir_read,
+ rtems_filesystem_default_write,
+ rtems_filesystem_default_ioctl,
+ imfs_dir_lseek,
+ imfs_dir_fstat,
+ IMFS_fchmod,
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ IMFS_fdatasync,
+ rtems_filesystem_default_fcntl,
+ imfs_dir_rmnod
+};
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_link.c b/cpukit/libfs/src/imfs/imfs_handlers_link.c
new file mode 100644
index 0000000000..74f93e1a53
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_handlers_link.c
@@ -0,0 +1,41 @@
+/*
+ * Link Operations Table for the IMFS
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include "imfs.h"
+
+/*
+ * Handler table for IMFS device nodes
+ */
+
+const rtems_filesystem_file_handlers_r IMFS_link_handlers = {
+ rtems_filesystem_default_open,
+ rtems_filesystem_default_close,
+ rtems_filesystem_default_read,
+ rtems_filesystem_default_write,
+ rtems_filesystem_default_ioctl,
+ rtems_filesystem_default_lseek,
+ IMFS_stat, /* stat */
+ rtems_filesystem_default_fchmod,
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ IMFS_rmnod
+};
diff --git a/cpukit/libfs/src/imfs/imfs_handlers_memfile.c b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
new file mode 100644
index 0000000000..33003ecba9
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_handlers_memfile.c
@@ -0,0 +1,41 @@
+/*
+ * Memfile Operations Tables for the IMFS
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include "imfs.h"
+
+/*
+ * Set of operations handlers for operations on memfile entities.
+ */
+
+const rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
+ memfile_open,
+ memfile_close,
+ memfile_read,
+ memfile_write,
+ memfile_ioctl,
+ memfile_lseek,
+ IMFS_stat,
+ IMFS_fchmod,
+ memfile_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ IMFS_fdatasync, /* fsync */
+ IMFS_fdatasync,
+ rtems_filesystem_default_fcntl,
+ IMFS_rmnod
+};
diff --git a/cpukit/libfs/src/imfs/imfs_init.c b/cpukit/libfs/src/imfs/imfs_init.c
new file mode 100644
index 0000000000..c74d493b40
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_init.c
@@ -0,0 +1,61 @@
+/**
+ * @file
+ *
+ * @ingroup LibFSIMFS
+ *
+ * @brief IMFS initialization.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+
+#include "imfs.h"
+
+const rtems_filesystem_operations_table IMFS_ops = {
+ .evalpath_h = IMFS_eval_path,
+ .evalformake_h = IMFS_evaluate_for_make,
+ .link_h = IMFS_link,
+ .unlink_h = IMFS_unlink,
+ .node_type_h = IMFS_node_type,
+ .mknod_h = IMFS_mknod,
+ .chown_h = IMFS_chown,
+ .freenod_h = rtems_filesystem_default_freenode,
+ .mount_h = IMFS_mount,
+ .fsmount_me_h = IMFS_initialize,
+ .unmount_h = IMFS_unmount,
+ .fsunmount_me_h = IMFS_fsunmount,
+ .utime_h = IMFS_utime,
+ .eval_link_h = IMFS_evaluate_link,
+ .symlink_h = IMFS_symlink,
+ .readlink_h = IMFS_readlink,
+ .rename_h = IMFS_rename,
+ .statvfs_h = rtems_filesystem_default_statvfs
+};
+
+int IMFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+)
+{
+ return IMFS_initialize_support(
+ mt_entry,
+ &IMFS_ops,
+ &IMFS_memfile_handlers,
+ &IMFS_directory_handlers,
+ &rtems_filesystem_handlers_default /* for fifos */
+ );
+}
diff --git a/cpukit/libfs/src/imfs/imfs_initsupp.c b/cpukit/libfs/src/imfs/imfs_initsupp.c
new file mode 100644
index 0000000000..47e1d392e8
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_initsupp.c
@@ -0,0 +1,119 @@
+/*
+ * IMFS Initialization
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h> /* for mkdir */
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#if defined(IMFS_DEBUG)
+#include <stdio.h>
+#endif
+
+/*
+ * IMFS_determine_bytes_per_block
+ */
+int imfs_memfile_bytes_per_block = 0;
+
+static int IMFS_determine_bytes_per_block(
+ int *dest_bytes_per_block,
+ int requested_bytes_per_block,
+ int default_bytes_per_block
+)
+{
+ bool is_valid = false;
+ int bit_mask;
+
+ /*
+ * check, whether requested bytes per block is valid
+ */
+ for (bit_mask = 16; !is_valid && (bit_mask <= 512); bit_mask <<= 1) {
+ if (bit_mask == requested_bytes_per_block) {
+ is_valid = true;
+ break;
+ }
+ if(bit_mask > requested_bytes_per_block)
+ break;
+ }
+ *dest_bytes_per_block = ((is_valid)
+ ? requested_bytes_per_block
+ : default_bytes_per_block);
+ return 0;
+}
+
+
+/*
+ * IMFS_initialize
+ */
+int IMFS_initialize_support(
+ rtems_filesystem_mount_table_entry_t *temp_mt_entry,
+ const rtems_filesystem_operations_table *op_table,
+ const rtems_filesystem_file_handlers_r *memfile_handlers,
+ const rtems_filesystem_file_handlers_r *directory_handlers,
+ const rtems_filesystem_file_handlers_r *fifo_handlers
+)
+{
+ static int imfs_instance;
+ IMFS_fs_info_t *fs_info;
+ IMFS_jnode_t *jnode;
+
+ /*
+ * determine/check value for imfs_memfile_bytes_per_block
+ */
+ IMFS_determine_bytes_per_block(&imfs_memfile_bytes_per_block,
+ imfs_rq_memfile_bytes_per_block,
+ IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK);
+
+ /*
+ * Create the root node
+ *
+ * NOTE: UNIX root is 755 and owned by root/root (0/0).
+ */
+ temp_mt_entry->mt_fs_root.node_access = IMFS_create_root_node();
+ temp_mt_entry->mt_fs_root.handlers = directory_handlers;
+ temp_mt_entry->mt_fs_root.ops = op_table;
+ temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
+
+ /*
+ * Create custom file system data.
+ */
+ fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
+ if ( !fs_info ) {
+ free(temp_mt_entry->mt_fs_root.node_access);
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+ temp_mt_entry->fs_info = fs_info;
+
+ /*
+ * Set st_ino for the root to 1.
+ */
+
+ fs_info->instance = imfs_instance++;
+ fs_info->ino_count = 1;
+ fs_info->memfile_handlers = memfile_handlers;
+ fs_info->directory_handlers = directory_handlers;
+ fs_info->fifo_handlers = fifo_handlers;
+
+ jnode = temp_mt_entry->mt_fs_root.node_access;
+ jnode->st_ino = fs_info->ino_count;
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_link.c b/cpukit/libfs/src/imfs/imfs_link.c
new file mode 100644
index 0000000000..4c2136ba71
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_link.c
@@ -0,0 +1,78 @@
+/*
+ * IMFS_link
+ *
+ * The following rouine creates a new link node under parent with the
+ * name given in name. The link node is set to point to the node at
+ * to_loc.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_link(
+ rtems_filesystem_location_info_t *to_loc, /* IN */
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *token /* IN */
+)
+{
+ IMFS_types_union info;
+ IMFS_jnode_t *new_node;
+ char new_name[ IMFS_NAME_MAX + 1 ];
+ int i;
+
+ /*
+ * Verify this node can be linked to.
+ */
+ info.hard_link.link_node = to_loc->node_access;
+ if ( info.hard_link.link_node->st_nlink >= LINK_MAX )
+ rtems_set_errno_and_return_minus_one( EMLINK );
+
+ /*
+ * Remove any separators at the end of the string.
+ */
+ IMFS_get_token( token, strlen( token ), new_name, &i );
+
+ /*
+ * Create a new link node.
+ *
+ * NOTE: Coverity Id 19 reports this as a leak
+ * While technically not a leak, it indicated that IMFS_create_node
+ * was ONLY passed a NULL when we created the root node. We
+ * added a new IMFS_create_root_node() so this path no longer
+ * existed. The result was simpler code which should not have
+ * this path.
+ */
+ new_node = IMFS_create_node(
+ parent_loc,
+ IMFS_HARD_LINK,
+ new_name,
+ ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
+ &info
+ );
+
+ if ( !new_node )
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ /*
+ * Increment the link count of the node being pointed to.
+ */
+ info.hard_link.link_node->st_nlink++;
+ IMFS_update_ctime( info.hard_link.link_node );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c b/cpukit/libfs/src/imfs/imfs_load_tar.c
new file mode 100644
index 0000000000..3cb3c4e195
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
@@ -0,0 +1,186 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * This file implements the "mount" procedure for tar-based IMFS
+ * extensions. The TAR is not actually mounted under the IMFS.
+ * Directories from the TAR file are created as usual in the IMFS.
+ * File entries are created as IMFS_LINEAR_FILE nodes with their nods
+ * pointing to addresses in the TAR image.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <tar.h>
+
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <rtems/imfs.h>
+#include <rtems/untar.h>
+
+/*
+ * TAR file format:
+ *
+ * Offset Length Contents
+ * 0 100 bytes File name ('\0' terminated, 99 maxmum length)
+ * 100 8 bytes File mode (in octal ascii)
+ * 108 8 bytes User ID (in octal ascii)
+ * 116 8 bytes Group ID (in octal ascii)
+ * 124 12 bytes File size (s) (in octal ascii)
+ * 136 12 bytes Modify time (in octal ascii)
+ * 148 8 bytes Header checksum (in octal ascii)
+ * 156 1 bytes Link flag
+ * 157 100 bytes Linkname ('\0' terminated, 99 maxmum length)
+ * 257 8 bytes Magic PAX ("ustar\0" + 2 bytes padding)
+ * 257 8 bytes Magic GNU tar ("ustar \0")
+ * 265 32 bytes User name ('\0' terminated, 31 maxmum length)
+ * 297 32 bytes Group name ('\0' terminated, 31 maxmum length)
+ * 329 8 bytes Major device ID (in octal ascii)
+ * 337 8 bytes Minor device ID (in octal ascii)
+ * 345 167 bytes Padding
+ * 512 (s+p)bytes File contents (s+p) := (((s) + 511) & ~511),
+ * round up to 512 bytes
+ *
+ * Checksum:
+ * int i, sum;
+ * char* header = tar_header_pointer;
+ * sum = 0;
+ * for(i = 0; i < 512; i++)
+ * sum += 0xFF & header[i];
+ */
+
+#define MAX_NAME_FIELD_SIZE 99
+
+#define MIN(a,b) ((a)>(b)?(b):(a))
+
+/*
+ * rtems_tarfs_load
+ *
+ * Here we create the mountpoint directory and load the tarfs at
+ * that node. Once the IMFS has been mounted, we work through the
+ * tar image and perform as follows:
+ * - For directories, simply call mkdir(). The IMFS creates nodes as
+ * needed.
+ * - For files, we make our own calls to IMFS eval_for_make and
+ * create_node.
+ */
+int rtems_tarfs_load(
+ char *mountpoint,
+ uint8_t *tar_image,
+ size_t tar_size
+)
+{
+ rtems_filesystem_location_info_t root_loc;
+ rtems_filesystem_location_info_t loc;
+ const char *hdr_ptr;
+ char filename[100];
+ char full_filename[256];
+ int hdr_chksum;
+ unsigned char linkflag;
+ unsigned long file_size;
+ unsigned long file_mode;
+ int offset;
+ unsigned long nblocks;
+ IMFS_jnode_t *node;
+ int status;
+
+ status = rtems_filesystem_evaluate_path(
+ mountpoint,
+ strlen(mountpoint),
+ 0,
+ &root_loc,
+ 0
+ );
+ if (status != 0)
+ return -1;
+
+ if (root_loc.ops != &IMFS_ops && root_loc.ops != &fifoIMFS_ops)
+ return -1;
+
+ /*
+ * Create an IMFS node structure pointing to tar image memory.
+ */
+ offset = 0;
+ while (1) {
+ if (offset + 512 > tar_size)
+ break;
+
+ /*
+ * Read a header.
+ */
+ hdr_ptr = (char *) &tar_image[offset];
+ offset += 512;
+ if (strncmp(&hdr_ptr[257], "ustar", 5))
+ break;
+
+ strncpy(filename, hdr_ptr, MAX_NAME_FIELD_SIZE);
+ filename[MAX_NAME_FIELD_SIZE] = '\0';
+
+ linkflag = hdr_ptr[156];
+ file_mode = _rtems_octal2ulong(&hdr_ptr[100], 8);
+ file_size = _rtems_octal2ulong(&hdr_ptr[124], 12);
+ hdr_chksum = _rtems_octal2ulong(&hdr_ptr[148], 8);
+
+ if (_rtems_tar_header_checksum(hdr_ptr) != hdr_chksum)
+ break;
+
+ /*
+ * Generate an IMFS node depending on the file type.
+ * - For directories, just create directories as usual. IMFS
+ * will take care of the rest.
+ * - For files, create a file node with special tarfs properties.
+ */
+ if (linkflag == DIRTYPE) {
+ strcpy(full_filename, mountpoint);
+ if (full_filename[strlen(full_filename)-1] != '/')
+ strcat(full_filename, "/");
+ strcat(full_filename, filename);
+ mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
+ }
+ /*
+ * Create a LINEAR_FILE node
+ *
+ * NOTE: Coverity Id 20 reports this as a leak.
+ * While technically not a leak, it indicated that
+ * IMFS_create_node was ONLY passed a NULL when we created the
+ * root node. We added a new IMFS_create_root_node() so this
+ * path no longer existed. The result was simpler code which
+ * should not have this path.
+ */
+ else if (linkflag == REGTYPE) {
+ const char *name;
+
+ loc = root_loc;
+ if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) {
+ node = IMFS_create_node(
+ &loc,
+ IMFS_LINEAR_FILE, (char *)name,
+ (file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
+ NULL
+ );
+ node->info.linearfile.size = file_size;
+ node->info.linearfile.direct = &tar_image[offset];
+ }
+
+ nblocks = (((file_size) + 511) & ~511) / 512;
+ offset += 512 * nblocks;
+ }
+ }
+ return status;
+}
+
diff --git a/cpukit/libfs/src/imfs/imfs_mknod.c b/cpukit/libfs/src/imfs/imfs_mknod.c
new file mode 100644
index 0000000000..1a0175af0a
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_mknod.c
@@ -0,0 +1,76 @@
+/*
+ * IMFS_mknod
+ *
+ * Routine to create a node in the IMFS file system.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_mknod(
+ const char *token, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+)
+{
+ IMFS_token_types type = 0;
+ IMFS_jnode_t *new_node;
+ int result;
+ char new_name[ IMFS_NAME_MAX + 1 ];
+ IMFS_types_union info;
+
+ IMFS_get_token( token, strlen( token ), new_name, &result );
+
+ /*
+ * Figure out what type of IMFS node this is.
+ */
+ if ( S_ISDIR(mode) )
+ type = IMFS_DIRECTORY;
+ else if ( S_ISREG(mode) )
+ type = IMFS_MEMORY_FILE;
+ else if ( S_ISBLK(mode) || S_ISCHR(mode) ) {
+ type = IMFS_DEVICE;
+ rtems_filesystem_split_dev_t( dev, info.device.major, info.device.minor );
+ } else if (S_ISFIFO(mode))
+ type = IMFS_FIFO;
+ else
+ IMFS_assert( 0 );
+
+ /*
+ * Allocate and fill in an IMFS jnode
+ *
+ * NOTE: Coverity Id 21 reports this as a leak.
+ * While technically not a leak, it indicated that IMFS_create_node
+ * was ONLY passed a NULL when we created the root node. We
+ * added a new IMFS_create_root_node() so this path no longer
+ * existed. The result was simpler code which should not have
+ * this path.
+ */
+ new_node = IMFS_create_node( pathloc, type, new_name, mode, &info );
+ if ( !new_node )
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_mount.c b/cpukit/libfs/src/imfs/imfs_mount.c
new file mode 100644
index 0000000000..3ec16da3f7
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_mount.c
@@ -0,0 +1,53 @@
+/*
+ * IMFS_mount
+ *
+ * This routine will look at a mount table entry that we are going to
+ * add to the mount table. If the mount point rtems_filesystem
+ * location_info_t struct refers to a node that is a directory,
+ * the node will be marked as a mount point by setting its directory.mt_fs
+ * pointer to point to the mount table entry that we are about to add
+ * to the mount table chain.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_mount(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+)
+{
+ IMFS_jnode_t *node;
+
+ node = mt_entry->mt_point_node.node_access;
+
+ /*
+ * Is the node that we are mounting onto a directory node ?
+ */
+
+ if ( node->type != IMFS_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * Set mt_fs pointer to point to the mount table entry for
+ * the mounted file system.
+ */
+
+ node->info.directory.mt_fs = mt_entry;
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_ntype.c b/cpukit/libfs/src/imfs/imfs_ntype.c
new file mode 100644
index 0000000000..f80182b144
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_ntype.c
@@ -0,0 +1,32 @@
+/*
+ * IMFS_node_type
+ *
+ * The following verifies that returns the type of node that the
+ * loc refers to.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include "imfs.h"
+
+rtems_filesystem_node_types_t IMFS_node_type(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ IMFS_jnode_t *node;
+
+ node = pathloc->node_access;
+ return node->type;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_readlink.c b/cpukit/libfs/src/imfs/imfs_readlink.c
new file mode 100644
index 0000000000..b598fcf2c1
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_readlink.c
@@ -0,0 +1,43 @@
+/*
+ * IMFS_readlink
+ *
+ * The following rouine puts the symblic links destination name into
+ * buff.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+ssize_t IMFS_readlink(
+ rtems_filesystem_location_info_t *loc,
+ char *buf, /* OUT */
+ size_t bufsize
+)
+{
+ IMFS_jnode_t *node;
+ ssize_t i;
+
+ node = loc->node_access;
+
+ IMFS_assert( node->type == IMFS_SYM_LINK );
+
+ for( i=0; ((i<bufsize) && (node->info.sym_link.name[i] != '\0')); i++ )
+ buf[i] = node->info.sym_link.name[i];
+
+ return i;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_rename.c b/cpukit/libfs/src/imfs/imfs_rename.c
new file mode 100644
index 0000000000..f45aa5b694
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_rename.c
@@ -0,0 +1,54 @@
+/*
+ * IMFS_rename
+ *
+ * The following rouine creates a new link node under parent with the
+ * name given in name and removes the old.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_rename(
+ rtems_filesystem_location_info_t *old_parent_loc, /* IN */
+ rtems_filesystem_location_info_t *old_loc, /* IN */
+ rtems_filesystem_location_info_t *new_parent_loc, /* IN */
+ const char *new_name /* IN */
+)
+{
+ IMFS_jnode_t *the_jnode;
+ IMFS_jnode_t *new_parent;
+
+ the_jnode = old_loc->node_access;
+
+ strncpy( the_jnode->name, new_name, IMFS_NAME_MAX );
+
+ if ( the_jnode->Parent != NULL )
+ rtems_chain_extract( (rtems_chain_node *) the_jnode );
+
+ new_parent = new_parent_loc->node_access;
+ the_jnode->Parent = new_parent;
+
+ rtems_chain_append( &new_parent->info.directory.Entries, &the_jnode->Node );
+
+ /*
+ * Update the time.
+ */
+ IMFS_update_ctime( the_jnode );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c
new file mode 100644
index 0000000000..25c7cde084
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_rmnod.c
@@ -0,0 +1,77 @@
+/*
+ * IMFS Node Removal Handler
+ *
+ * This file contains the handler used to remove a node when a file type
+ * does not require special actions.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+
+#include "imfs.h"
+
+void IMFS_create_orphan( IMFS_jnode_t *jnode )
+{
+ if ( jnode->Parent != NULL ) {
+ rtems_chain_extract( &jnode->Node );
+ jnode->Parent = NULL;
+ }
+
+ --jnode->st_nlink;
+
+ IMFS_update_ctime( jnode );
+}
+
+void IMFS_check_node_remove( IMFS_jnode_t *jnode )
+{
+ if ( !rtems_libio_is_file_open( jnode ) && jnode->st_nlink < 1 ) {
+ if ( rtems_filesystem_current.node_access == jnode )
+ rtems_filesystem_current.node_access = NULL;
+
+ switch ( jnode->type ) {
+ case IMFS_MEMORY_FILE:
+ IMFS_memfile_remove( jnode );
+ break;
+ case IMFS_SYM_LINK:
+ free( jnode->info.sym_link.name );
+ break;
+ default:
+ break;
+ }
+
+ free( jnode );
+ }
+}
+
+/*
+ * IMFS_rmnod
+ */
+
+int IMFS_rmnod(
+ rtems_filesystem_location_info_t *parent_pathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ IMFS_jnode_t *jnode = (IMFS_jnode_t *) pathloc->node_access;
+
+ IMFS_create_orphan( jnode );
+ IMFS_check_node_remove( jnode );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_stat.c b/cpukit/libfs/src/imfs/imfs_stat.c
new file mode 100644
index 0000000000..29867faa7b
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_stat.c
@@ -0,0 +1,81 @@
+/*
+ * IMFS_stat
+ *
+ * This routine provides a stat for the IMFS file system.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_stat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+)
+{
+ IMFS_fs_info_t *fs_info;
+ IMFS_jnode_t *the_jnode;
+ IMFS_device_t *io;
+
+ the_jnode = loc->node_access;
+
+
+ switch ( the_jnode->type ) {
+
+ case IMFS_DEVICE:
+ io = &the_jnode->info.device;
+ buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor );
+ break;
+
+ case IMFS_LINEAR_FILE:
+ case IMFS_MEMORY_FILE:
+ buf->st_size = the_jnode->info.file.size;
+ break;
+
+ case IMFS_SYM_LINK:
+ buf->st_size = 0;
+ break;
+
+ case IMFS_FIFO:
+ buf->st_size = 0;
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one( ENOTSUP );
+ break;
+ }
+
+ /*
+ * The device number of the IMFS is the major number and the minor is the
+ * instance.
+ */
+ fs_info = loc->mt_entry->fs_info;
+ buf->st_dev =
+ rtems_filesystem_make_dev_t( IMFS_DEVICE_MAJOR_NUMBER, fs_info->instance );
+
+ buf->st_mode = the_jnode->st_mode;
+ buf->st_nlink = the_jnode->st_nlink;
+ buf->st_ino = the_jnode->st_ino;
+ buf->st_uid = the_jnode->st_uid;
+ buf->st_gid = the_jnode->st_gid;
+
+ buf->st_atime = the_jnode->stat_atime;
+ buf->st_mtime = the_jnode->stat_mtime;
+ buf->st_ctime = the_jnode->stat_ctime;
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_symlink.c b/cpukit/libfs/src/imfs/imfs_symlink.c
new file mode 100644
index 0000000000..7094f219fb
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_symlink.c
@@ -0,0 +1,77 @@
+/*
+ * IMFS_symlink
+ *
+ * The following rouine creates a new symbolic link node under parent
+ * with the name given in name. The node is set to point to the node at
+ * to_loc.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_symlink(
+ rtems_filesystem_location_info_t *parent_loc,
+ const char *link_name,
+ const char *node_name
+)
+{
+ IMFS_types_union info;
+ IMFS_jnode_t *new_node;
+ char new_name[ IMFS_NAME_MAX + 1 ];
+ int i;
+
+ /*
+ * Remove any separators at the end of the string.
+ */
+ IMFS_get_token( node_name, strlen( node_name ), new_name, &i );
+
+ /*
+ * Duplicate link name
+ */
+ info.sym_link.name = strdup(link_name);
+ if (info.sym_link.name == NULL) {
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+
+ /*
+ * Create a new link node.
+ *
+ * NOTE: Coverity CID 22 notes this as a resource leak.
+ * While technically not a leak, it indicated that IMFS_create_node
+ * was ONLY passed a NULL when we created the root node. We
+ * added a new IMFS_create_root_node() so this path no longer
+ * existed. The result was simpler code which should not have
+ * this path.
+ */
+ new_node = IMFS_create_node(
+ parent_loc,
+ IMFS_SYM_LINK,
+ new_name,
+ ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
+ &info
+ );
+
+ if (new_node == NULL) {
+ free(info.sym_link.name);
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_unlink.c b/cpukit/libfs/src/imfs/imfs_unlink.c
new file mode 100644
index 0000000000..0ec176ed03
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_unlink.c
@@ -0,0 +1,82 @@
+/*
+ * IMFS_unlink
+ *
+ * Routine to remove a link node from the tree.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_unlink(
+ rtems_filesystem_location_info_t *parentloc, /* IN */
+ rtems_filesystem_location_info_t *loc /* IN */
+)
+{
+ IMFS_jnode_t *node;
+ rtems_filesystem_location_info_t the_link;
+ int result = 0;
+
+ node = loc->node_access;
+
+ /*
+ * Decrement the link counter of node pointed to and free the
+ * space.
+ */
+
+ /*
+ * If this is the last last pointer to the node
+ * free the node.
+ */
+
+ if ( node->type == IMFS_HARD_LINK ) {
+
+ if ( !node->info.hard_link.link_node )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ the_link = *loc;
+ the_link.node_access = node->info.hard_link.link_node;
+ IMFS_Set_handlers( &the_link );
+
+ /*
+ * If removing the last hard link to a node, then we need
+ * to remove the node that is a link and the node itself.
+ */
+
+ if ( node->info.hard_link.link_node->st_nlink == 1)
+ {
+ result = (*the_link.handlers->rmnod_h)( parentloc, &the_link );
+ if ( result != 0 )
+ return -1;
+ }
+ else
+ {
+ node->info.hard_link.link_node->st_nlink --;
+ IMFS_update_ctime( node->info.hard_link.link_node );
+ }
+ }
+
+ /*
+ * Now actually free the node we were asked to free.
+ */
+
+ result = (*loc->handlers->rmnod_h)( parentloc, loc );
+
+ return result;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_unmount.c b/cpukit/libfs/src/imfs/imfs_unmount.c
new file mode 100644
index 0000000000..ee1482bfa5
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_unmount.c
@@ -0,0 +1,62 @@
+/*
+ * IMFS_unmount
+ *
+ * This routine will look at a mount table entry that we are going to
+ * add to the mount table. If the mount point
+ * rtems_filesystem_location_info_t struct refers to a node that is a
+ * directory that has a file system mounted on it, the node will be
+ * marked as a mount point by * setting its directory.mt_fs pointer
+ * to NULL. This indicates that a directory is no longer mounted on
+ * this node.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+int IMFS_unmount(
+ rtems_filesystem_mount_table_entry_t *mt_entry
+)
+{
+ IMFS_jnode_t *node;
+
+ node = mt_entry->mt_point_node.node_access;
+
+ /*
+ * Is the node that we are mounting onto a directory node ?
+ */
+
+ if ( node->type != IMFS_DIRECTORY )
+ rtems_set_errno_and_return_minus_one( ENOTDIR );
+
+ /*
+ * Did the node indicate that there was a directory mounted here?
+ */
+
+ if ( node->info.directory.mt_fs == NULL )
+ rtems_set_errno_and_return_minus_one( EINVAL ); /* XXX */
+
+ /*
+ * Set the mt_fs pointer to indicate that there is no longer
+ * a file system mounted to this point.
+ */
+
+ node->info.directory.mt_fs = NULL;
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/imfs_utime.c b/cpukit/libfs/src/imfs/imfs_utime.c
new file mode 100644
index 0000000000..2867e13ed6
--- /dev/null
+++ b/cpukit/libfs/src/imfs/imfs_utime.c
@@ -0,0 +1,42 @@
+/*
+ * IMFS_utime
+ *
+ * This routine is the implementation of the utime() system
+ * call for the IMFS.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <sys/time.h>
+
+#include <rtems/libio_.h>
+#include "imfs.h"
+
+int IMFS_utime(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = (IMFS_jnode_t *) pathloc->node_access;
+
+ the_jnode->stat_atime = actime;
+ the_jnode->stat_mtime = modtime;
+ the_jnode->stat_ctime = time( NULL );
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/imfs/ioman.c b/cpukit/libfs/src/imfs/ioman.c
new file mode 100644
index 0000000000..fa9918b266
--- /dev/null
+++ b/cpukit/libfs/src/imfs/ioman.c
@@ -0,0 +1,93 @@
+/*
+ * This file emulates the old Classic RTEMS IO manager directives
+ * which register and lookup names using the in-memory filesystem.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include "imfs.h"
+
+/*
+ * rtems_io_register_name
+ *
+ * This assumes that all registered devices are character devices.
+ */
+
+rtems_status_code rtems_io_register_name(
+ const char *device_name,
+ rtems_device_major_number major,
+ rtems_device_minor_number minor
+)
+{
+ int status;
+ dev_t dev;
+
+ dev = rtems_filesystem_make_dev_t( major, minor );
+ status = mknod( device_name, 0777 | S_IFCHR, dev );
+
+ /* this is the only error returned by the old version */
+ if ( status )
+ return RTEMS_TOO_MANY;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_io_lookup_name
+ *
+ * This version is reentrant.
+ *
+ * XXX - This is dependent upon IMFS and should not be.
+ * Suggest adding a filesystem routine to fill in the device_info.
+ */
+
+rtems_status_code rtems_io_lookup_name(
+ const char *name,
+ rtems_driver_name_t *device_info
+)
+{
+ IMFS_jnode_t *the_jnode;
+ rtems_filesystem_location_info_t loc;
+ int result;
+ rtems_filesystem_node_types_t node_type;
+
+ result = rtems_filesystem_evaluate_path(
+ name, strlen( name ), 0x00, &loc, true );
+ the_jnode = loc.node_access;
+
+ node_type = (*loc.ops->node_type_h)( &loc );
+
+ if ( (result != 0) || node_type != RTEMS_FILESYSTEM_DEVICE ) {
+ rtems_filesystem_freenode( &loc );
+ return RTEMS_UNSATISFIED;
+ }
+
+ device_info->device_name = (char *) name;
+ device_info->device_name_length = strlen( name );
+ device_info->major = the_jnode->info.device.major;
+ device_info->minor = the_jnode->info.device.minor;
+
+ rtems_filesystem_freenode( &loc );
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/memfile.c
new file mode 100644
index 0000000000..98616d1b36
--- /dev/null
+++ b/cpukit/libfs/src/imfs/memfile.c
@@ -0,0 +1,975 @@
+/*
+ * IMFS Device Node Handlers
+ *
+ * This file contains the set of handlers used to process operations on
+ * IMFS memory file nodes. The memory files are created in memory using
+ * malloc'ed memory. Thus any data stored in one of these files is lost
+ * at system shutdown unless special arrangements to copy the data to
+ * some type of non-volailte storage are made by the application.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include "imfs.h"
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+#define MEMFILE_STATIC
+
+/*
+ * Prototypes of private routines
+ */
+MEMFILE_STATIC int IMFS_memfile_extend(
+ IMFS_jnode_t *the_jnode,
+ off_t new_length
+);
+
+MEMFILE_STATIC int IMFS_memfile_addblock(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block
+);
+
+MEMFILE_STATIC int IMFS_memfile_remove_block(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block
+);
+
+MEMFILE_STATIC block_p *IMFS_memfile_get_block_pointer(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block,
+ int malloc_it
+);
+
+MEMFILE_STATIC ssize_t IMFS_memfile_read(
+ IMFS_jnode_t *the_jnode,
+ off_t start,
+ unsigned char *destination,
+ unsigned int length
+);
+
+ssize_t IMFS_memfile_write( /* cannot be static as used in imfs_fchmod.c */
+ IMFS_jnode_t *the_jnode,
+ off_t start,
+ const unsigned char *source,
+ unsigned int length
+);
+
+void *memfile_alloc_block(void);
+
+void memfile_free_block(
+ void *memory
+);
+
+/*
+ * memfile_open
+ *
+ * This routine processes the open() system call. Note that there is
+ * nothing special to be done at open() time.
+ */
+int memfile_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ /*
+ * Perform 'copy on write' for linear files
+ */
+ if ((iop->flags & (LIBIO_FLAGS_WRITE | LIBIO_FLAGS_APPEND))
+ && (the_jnode->type == IMFS_LINEAR_FILE)) {
+ uint32_t count = the_jnode->info.linearfile.size;
+ const unsigned char *buffer = the_jnode->info.linearfile.direct;
+
+ the_jnode->type = IMFS_MEMORY_FILE;
+ the_jnode->info.file.size = 0;
+ the_jnode->info.file.indirect = 0;
+ the_jnode->info.file.doubly_indirect = 0;
+ the_jnode->info.file.triply_indirect = 0;
+ if ((count != 0)
+ && (IMFS_memfile_write(the_jnode, 0, buffer, count) == -1))
+ return -1;
+ }
+ if (iop->flags & LIBIO_FLAGS_APPEND)
+ iop->offset = the_jnode->info.file.size;
+
+ iop->size = the_jnode->info.file.size;
+ return 0;
+}
+
+/*
+ * memfile_close
+ *
+ * This routine processes the close() system call. Note that there is
+ * nothing to flush or memory to free at this point.
+ */
+int memfile_close(
+ rtems_libio_t *iop
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ if (iop->flags & LIBIO_FLAGS_APPEND)
+ iop->offset = the_jnode->info.file.size;
+
+ IMFS_check_node_remove( the_jnode );
+
+ return 0;
+}
+
+/*
+ * memfile_read
+ *
+ * This routine processes the read() system call.
+ */
+ssize_t memfile_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ return IMFS_memfile_read( the_jnode, iop->offset, buffer, count );
+}
+
+/*
+ * memfile_write
+ *
+ * This routine processes the write() system call.
+ */
+ssize_t memfile_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ IMFS_jnode_t *the_jnode;
+ ssize_t status;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ status = IMFS_memfile_write( the_jnode, iop->offset, buffer, count );
+ iop->size = the_jnode->info.file.size;
+
+ return status;
+}
+
+/*
+ * memfile_ioctl
+ *
+ * This routine processes the ioctl() system call.
+ *
+ * NOTE: No ioctl()'s are supported for in-memory files.
+ */
+int memfile_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *buffer
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ return 0;
+}
+
+/*
+ * memfile_lseek
+ *
+ * This routine processes the lseek() system call.
+ */
+rtems_off64_t memfile_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t offset,
+ int whence
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ if (the_jnode->type == IMFS_LINEAR_FILE) {
+ if (iop->offset > the_jnode->info.linearfile.size)
+ iop->offset = the_jnode->info.linearfile.size;
+ }
+ else { /* Must be a block file (IMFS_MEMORY_FILE). */
+ if (IMFS_memfile_extend( the_jnode, iop->offset ))
+ rtems_set_errno_and_return_minus_one( ENOSPC );
+
+ iop->size = the_jnode->info.file.size;
+ }
+ return iop->offset;
+}
+
+/*
+ * memfile_stat
+ *
+ * This IMFS_stat() can be used.
+ */
+
+/*
+ * memfile_ftruncate
+ *
+ * This routine processes the ftruncate() system call.
+ */
+int memfile_ftruncate(
+ rtems_libio_t *iop,
+ rtems_off64_t length
+)
+{
+ IMFS_jnode_t *the_jnode;
+
+ the_jnode = iop->pathinfo.node_access;
+
+ /*
+ * POSIX 1003.1b does not specify what happens if you truncate a file
+ * and the new length is greater than the current size. We treat this
+ * as an extend operation.
+ */
+
+ if ( length > the_jnode->info.file.size )
+ return IMFS_memfile_extend( the_jnode, length );
+
+ /*
+ * The in-memory files do not currently reclaim memory until the file is
+ * deleted. So we leave the previously allocated blocks in place for
+ * future use and just set the length.
+ */
+ the_jnode->info.file.size = length;
+ iop->size = the_jnode->info.file.size;
+
+ IMFS_update_atime( the_jnode );
+
+ return 0;
+}
+
+/*
+ * IMFS_memfile_extend
+ *
+ * This routine insures that the in-memory file is of the length
+ * specified. If necessary, it will allocate memory blocks to
+ * extend the file.
+ */
+MEMFILE_STATIC int IMFS_memfile_extend(
+ IMFS_jnode_t *the_jnode,
+ off_t new_length
+)
+{
+ unsigned int block;
+ unsigned int new_blocks;
+ unsigned int old_blocks;
+
+ /*
+ * Perform internal consistency checks
+ */
+ IMFS_assert( the_jnode );
+ IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+
+ /*
+ * Verify new file size is supported
+ */
+ if ( new_length >= IMFS_MEMFILE_MAXIMUM_SIZE )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * Verify new file size is actually larger than current size
+ */
+ if ( new_length <= the_jnode->info.file.size )
+ return 0;
+
+ /*
+ * Calculate the number of range of blocks to allocate
+ */
+ new_blocks = new_length / IMFS_MEMFILE_BYTES_PER_BLOCK;
+ old_blocks = the_jnode->info.file.size / IMFS_MEMFILE_BYTES_PER_BLOCK;
+
+ /*
+ * Now allocate each of those blocks.
+ */
+ for ( block=old_blocks ; block<=new_blocks ; block++ ) {
+ if ( IMFS_memfile_addblock( the_jnode, block ) ) {
+ for ( ; block>=old_blocks ; block-- ) {
+ IMFS_memfile_remove_block( the_jnode, block );
+ }
+ rtems_set_errno_and_return_minus_one( ENOSPC );
+ }
+ }
+
+ /*
+ * Set the new length of the file.
+ */
+ the_jnode->info.file.size = new_length;
+ return 0;
+}
+
+/*
+ * IMFS_memfile_addblock
+ *
+ * This routine adds a single block to the specified in-memory file.
+ */
+MEMFILE_STATIC int IMFS_memfile_addblock(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block
+)
+{
+ block_p memory;
+ block_p *block_entry_ptr;
+
+ IMFS_assert( the_jnode );
+ IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+
+ /*
+ * Obtain the pointer for the specified block number
+ */
+ block_entry_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 1 );
+ if ( *block_entry_ptr )
+ return 0;
+
+ /*
+ * There is no memory for this block number so allocate it.
+ */
+ memory = memfile_alloc_block();
+ if ( !memory )
+ return 1;
+
+ *block_entry_ptr = memory;
+ return 0;
+}
+
+/*
+ * IMFS_memfile_remove_block
+ *
+ * This routine removes the specified block from the in-memory file.
+ *
+ * NOTE: This is a support routine and is called only to remove
+ * the last block or set of blocks in a file. Removing a
+ * block from the middle of a file would be exceptionally
+ * dangerous and the results unpredictable.
+ */
+MEMFILE_STATIC int IMFS_memfile_remove_block(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block
+)
+{
+ block_p *block_ptr;
+ block_p ptr;
+
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ IMFS_assert( block_ptr );
+
+ ptr = *block_ptr;
+ *block_ptr = 0;
+ memfile_free_block( ptr );
+
+ return 1;
+}
+
+/*
+ * memfile_free_blocks_in_table
+ *
+ * This is a support routine for IMFS_memfile_remove. It frees all the
+ * blocks in one of the indirection tables.
+ */
+void memfile_free_blocks_in_table(
+ block_p **block_table,
+ int entries
+)
+{
+ int i;
+ block_p *b;
+
+ /*
+ * Perform internal consistency checks
+ */
+ IMFS_assert( block_table );
+
+ /*
+ * Now go through all the slots in the table and free the memory.
+ */
+ b = *block_table;
+
+ for ( i=0 ; i<entries ; i++ ) {
+ if ( b[i] ) {
+ memfile_free_block( b[i] );
+ b[i] = 0;
+ }
+ }
+
+ /*
+ * Now that all the blocks in the block table are free, we can
+ * free the block table itself.
+ */
+ memfile_free_block( *block_table );
+ *block_table = 0;
+}
+
+/*
+ * IMFS_memfile_remove
+ *
+ * This routine frees all memory associated with an in memory file.
+ *
+ * NOTE: This is an exceptionally conservative implementation.
+ * It will check EVERY pointer which is non-NULL and insure
+ * any child non-NULL pointers are freed. Optimistically, all that
+ * is necessary is to scan until a NULL pointer is found. There
+ * should be no allocated data past that point.
+ *
+ * In experimentation on the powerpc simulator, it was noted
+ * that using blocks which held 128 slots versus 16 slots made
+ * a significant difference in the performance of this routine.
+ *
+ * Regardless until the IMFS implementation is proven, it
+ * is better to stick to simple, easy to understand algorithms.
+ */
+int IMFS_memfile_remove(
+ IMFS_jnode_t *the_jnode
+)
+{
+ IMFS_memfile_t *info;
+ int i;
+ int j;
+ unsigned int to_free;
+ block_p *p;
+
+ /*
+ * Perform internal consistency checks
+ */
+ IMFS_assert( the_jnode );
+ IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+
+ /*
+ * Eventually this could be set smarter at each call to
+ * memfile_free_blocks_in_table to greatly speed this up.
+ */
+ to_free = IMFS_MEMFILE_BLOCK_SLOTS;
+
+ /*
+ * Now start freeing blocks in this order:
+ * + indirect
+ * + doubly indirect
+ * + triply indirect
+ */
+ info = &the_jnode->info.file;
+
+ if ( info->indirect ) {
+ memfile_free_blocks_in_table( &info->indirect, to_free );
+ }
+
+ if ( info->doubly_indirect ) {
+ for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) {
+ if ( info->doubly_indirect[i] ) {
+ memfile_free_blocks_in_table(
+ (block_p **)&info->doubly_indirect[i], to_free );
+ }
+ }
+ memfile_free_blocks_in_table( &info->doubly_indirect, to_free );
+
+ }
+
+ if ( info->triply_indirect ) {
+ for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) {
+ p = (block_p *) info->triply_indirect[i];
+ if ( !p ) /* ensure we have a valid pointer */
+ break;
+ for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) {
+ if ( p[j] ) {
+ memfile_free_blocks_in_table( (block_p **)&p[j], to_free);
+ }
+ }
+ memfile_free_blocks_in_table(
+ (block_p **)&info->triply_indirect[i], to_free );
+ }
+ memfile_free_blocks_in_table(
+ (block_p **)&info->triply_indirect, to_free );
+ }
+
+ return 0;
+}
+
+/*
+ * IMFS_memfile_read
+ *
+ * This routine read from memory file pointed to by the_jnode into
+ * the specified data buffer specified by destination. The file
+ * is NOT extended. An offset greater than the length of the file
+ * is considered an error. Read from an offset for more bytes than
+ * are between the offset and the end of the file will result in
+ * reading the data between offset and the end of the file (truncated
+ * read).
+ */
+MEMFILE_STATIC ssize_t IMFS_memfile_read(
+ IMFS_jnode_t *the_jnode,
+ off_t start,
+ unsigned char *destination,
+ unsigned int length
+)
+{
+ block_p *block_ptr;
+ unsigned int block;
+ unsigned int my_length;
+ unsigned int to_copy = 0;
+ unsigned int last_byte;
+ unsigned int copied;
+ unsigned int start_offset;
+ unsigned char *dest;
+
+ dest = destination;
+
+ /*
+ * Perform internal consistency checks
+ */
+ IMFS_assert( the_jnode );
+ IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE ||
+ the_jnode->type != IMFS_LINEAR_FILE );
+ IMFS_assert( dest );
+
+ /*
+ * Linear files (as created from a tar file are easier to handle
+ * than block files).
+ */
+ my_length = length;
+
+ if (the_jnode->type == IMFS_LINEAR_FILE) {
+ unsigned char *file_ptr;
+
+ file_ptr = (unsigned char *)the_jnode->info.linearfile.direct;
+
+ if (my_length > (the_jnode->info.linearfile.size - start))
+ my_length = the_jnode->info.linearfile.size - start;
+
+ memcpy(dest, &file_ptr[start], my_length);
+
+ IMFS_update_atime( the_jnode );
+
+ return my_length;
+ }
+
+ /*
+ * If the last byte we are supposed to read is past the end of this
+ * in memory file, then shorten the length to read.
+ */
+ last_byte = start + length;
+ if ( last_byte > the_jnode->info.file.size )
+ my_length = the_jnode->info.file.size - start;
+
+ copied = 0;
+
+ /*
+ * Three phases to the read:
+ * + possibly the last part of one block
+ * + all of zero of more blocks
+ * + possibly the first part of one block
+ */
+
+ /*
+ * Phase 1: possibly the last part of one block
+ */
+ start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK;
+ block = start / IMFS_MEMFILE_BYTES_PER_BLOCK;
+ if ( start_offset ) {
+ to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK - start_offset;
+ if ( to_copy > my_length )
+ to_copy = my_length;
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ if ( !block_ptr )
+ return copied;
+ memcpy( dest, &(*block_ptr)[ start_offset ], to_copy );
+ dest += to_copy;
+ block++;
+ my_length -= to_copy;
+ copied += to_copy;
+ }
+
+ /*
+ * Phase 2: all of zero of more blocks
+ */
+ to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK;
+ while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) {
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ if ( !block_ptr )
+ return copied;
+ memcpy( dest, &(*block_ptr)[ 0 ], to_copy );
+ dest += to_copy;
+ block++;
+ my_length -= to_copy;
+ copied += to_copy;
+ }
+
+ /*
+ * Phase 3: possibly the first part of one block
+ */
+ IMFS_assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK );
+
+ if ( my_length ) {
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ if ( !block_ptr )
+ return copied;
+ memcpy( dest, &(*block_ptr)[ 0 ], my_length );
+ copied += my_length;
+ }
+
+ IMFS_update_atime( the_jnode );
+
+ return copied;
+}
+
+/*
+ * IMFS_memfile_write
+ *
+ * This routine writes the specified data buffer into the in memory
+ * file pointed to by the_jnode. The file is extended as needed.
+ */
+MEMFILE_STATIC ssize_t IMFS_memfile_write(
+ IMFS_jnode_t *the_jnode,
+ off_t start,
+ const unsigned char *source,
+ unsigned int length
+)
+{
+ block_p *block_ptr;
+ unsigned int block;
+ int status;
+ unsigned int my_length;
+ unsigned int to_copy = 0;
+ unsigned int last_byte;
+ unsigned int start_offset;
+ int copied;
+ const unsigned char *src;
+
+ src = source;
+
+ /*
+ * Perform internal consistency checks
+ */
+ IMFS_assert( source );
+ IMFS_assert( the_jnode );
+ IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+
+ my_length = length;
+ /*
+ * If the last byte we are supposed to write is past the end of this
+ * in memory file, then extend the length.
+ */
+
+ last_byte = start + my_length;
+ if ( last_byte > the_jnode->info.file.size ) {
+ status = IMFS_memfile_extend( the_jnode, last_byte );
+ if ( status )
+ rtems_set_errno_and_return_minus_one( ENOSPC );
+ }
+
+ copied = 0;
+
+ /*
+ * Three phases to the write:
+ * + possibly the last part of one block
+ * + all of zero of more blocks
+ * + possibly the first part of one block
+ */
+
+ /*
+ * Phase 1: possibly the last part of one block
+ */
+ start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK;
+ block = start / IMFS_MEMFILE_BYTES_PER_BLOCK;
+ if ( start_offset ) {
+ to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK - start_offset;
+ if ( to_copy > my_length )
+ to_copy = my_length;
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ if ( !block_ptr )
+ return copied;
+ #if 0
+ fprintf(
+ stderr,
+ "write %d at %d in %d: %*s\n",
+ to_copy,
+ start_offset,
+ block,
+ to_copy,
+ src
+ );
+ #endif
+ memcpy( &(*block_ptr)[ start_offset ], src, to_copy );
+ src += to_copy;
+ block++;
+ my_length -= to_copy;
+ copied += to_copy;
+ }
+
+ /*
+ * Phase 2: all of zero of more blocks
+ */
+
+ to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK;
+ while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) {
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ if ( !block_ptr )
+ return copied;
+ #if 0
+ fprintf(stdout, "write %d in %d: %*s\n", to_copy, block, to_copy, src );
+ #endif
+ memcpy( &(*block_ptr)[ 0 ], src, to_copy );
+ src += to_copy;
+ block++;
+ my_length -= to_copy;
+ copied += to_copy;
+ }
+
+ /*
+ * Phase 3: possibly the first part of one block
+ */
+ IMFS_assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK );
+
+ to_copy = my_length;
+ if ( my_length ) {
+ block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
+ if ( !block_ptr )
+ return copied;
+ #if 0
+ fprintf(stdout, "write %d in %d: %*s\n", to_copy, block, to_copy, src );
+ #endif
+ memcpy( &(*block_ptr)[ 0 ], src, my_length );
+ my_length = 0;
+ copied += to_copy;
+ }
+
+ IMFS_mtime_ctime_update( the_jnode );
+
+ return copied;
+}
+
+/*
+ * IMFS_memfile_get_block_pointer
+ *
+ * This routine looks up the block pointer associated with the given block
+ * number. If that block has not been allocated and "malloc_it" is
+ * TRUE, then the block is allocated. Otherwise, it is an error.
+ */
+#if 0
+block_p *IMFS_memfile_get_block_pointer_DEBUG(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block,
+ int malloc_it
+);
+
+block_p *IMFS_memfile_get_block_pointer(
+ IMFS_jnode_t *the_jnode,
+ unsigned int block,
+ int malloc_it
+)
+{
+ block_p *p;
+
+ p = IMFS_memfile_get_block_pointer_DEBUG( the_jnode, block, malloc_it );
+ fprintf(stdout, "(%d -> %p) ", block, p );
+ return p;
+}
+
+block_p *IMFS_memfile_get_block_pointer_DEBUG(
+#else
+block_p *IMFS_memfile_get_block_pointer(
+#endif
+ IMFS_jnode_t *the_jnode,
+ unsigned int block,
+ int malloc_it
+)
+{
+ unsigned int my_block;
+ IMFS_memfile_t *info;
+ unsigned int singly;
+ unsigned int doubly;
+ unsigned int triply;
+ block_p *p;
+ block_p *p1;
+ block_p *p2;
+
+ /*
+ * Perform internal consistency checks
+ */
+ IMFS_assert( the_jnode );
+ IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
+
+ info = &the_jnode->info.file;
+ my_block = block;
+
+ /*
+ * Is the block number in the simple indirect portion?
+ */
+ if ( my_block <= LAST_INDIRECT ) {
+ p = info->indirect;
+
+ if ( malloc_it ) {
+
+ if ( !p ) {
+ p = memfile_alloc_block();
+ if ( !p )
+ return 0;
+ info->indirect = p;
+ }
+ return &info->indirect[ my_block ];
+ }
+
+ if ( !p )
+ return 0;
+
+ return &info->indirect[ my_block ];
+ }
+
+ /*
+ * Is the block number in the doubly indirect portion?
+ */
+
+ if ( my_block <= LAST_DOUBLY_INDIRECT ) {
+ my_block -= FIRST_DOUBLY_INDIRECT;
+
+ singly = my_block % IMFS_MEMFILE_BLOCK_SLOTS;
+ doubly = my_block / IMFS_MEMFILE_BLOCK_SLOTS;
+
+ p = info->doubly_indirect;
+ if ( malloc_it ) {
+
+ if ( !p ) {
+ p = memfile_alloc_block();
+ if ( !p )
+ return 0;
+ info->doubly_indirect = p;
+ }
+
+ p1 = (block_p *)p[ doubly ];
+ if ( !p1 ) {
+ p1 = memfile_alloc_block();
+ if ( !p1 )
+ return 0;
+ p[ doubly ] = (block_p) p1;
+ }
+
+ return (block_p *)&p1[ singly ];
+ }
+
+ if ( !p )
+ return 0;
+
+ p = (block_p *)p[ doubly ];
+ if ( !p )
+ return 0;
+
+ return (block_p *)&p[ singly ];
+ }
+
+ /*
+ * Is the block number in the triply indirect portion?
+ */
+ if ( my_block <= LAST_TRIPLY_INDIRECT ) {
+ my_block -= FIRST_TRIPLY_INDIRECT;
+
+ singly = my_block % IMFS_MEMFILE_BLOCK_SLOTS;
+ doubly = my_block / IMFS_MEMFILE_BLOCK_SLOTS;
+ triply = doubly / IMFS_MEMFILE_BLOCK_SLOTS;
+ doubly %= IMFS_MEMFILE_BLOCK_SLOTS;
+
+ p = info->triply_indirect;
+
+ if ( malloc_it ) {
+ if ( !p ) {
+ p = memfile_alloc_block();
+ if ( !p )
+ return 0;
+ info->triply_indirect = p;
+ }
+
+ p1 = (block_p *) p[ triply ];
+ if ( !p1 ) {
+ p1 = memfile_alloc_block();
+ if ( !p1 )
+ return 0;
+ p[ triply ] = (block_p) p1;
+ }
+
+ p2 = (block_p *)p1[ doubly ];
+ if ( !p2 ) {
+ p2 = memfile_alloc_block();
+ if ( !p2 )
+ return 0;
+ p1[ doubly ] = (block_p) p2;
+ }
+ return (block_p *)&p2[ singly ];
+ }
+
+ if ( !p )
+ return 0;
+
+ p1 = (block_p *) p[ triply ];
+ if ( !p1 )
+ return 0;
+
+ p2 = (block_p *)p1[ doubly ];
+ if ( !p2 )
+ return 0;
+
+ return (block_p *)&p2[ singly ];
+ }
+
+ /*
+ * This means the requested block number is out of range.
+ */
+ return 0;
+}
+
+/*
+ * memfile_alloc_block
+ *
+ * Allocate a block for an in-memory file.
+ */
+int memfile_blocks_allocated = 0;
+
+void *memfile_alloc_block(void)
+{
+ void *memory;
+
+ memory = (void *)calloc(1, IMFS_MEMFILE_BYTES_PER_BLOCK);
+ if ( memory )
+ memfile_blocks_allocated++;
+
+ return memory;
+}
+
+/*
+ * memfile_free_block
+ *
+ * Free a block from an in-memory file.
+ */
+void memfile_free_block(
+ void *memory
+)
+{
+ free(memory);
+ memfile_blocks_allocated--;
+}
diff --git a/cpukit/libfs/src/imfs/miniimfs_init.c b/cpukit/libfs/src/imfs/miniimfs_init.c
new file mode 100644
index 0000000000..b43a5318e8
--- /dev/null
+++ b/cpukit/libfs/src/imfs/miniimfs_init.c
@@ -0,0 +1,61 @@
+/**
+ * @file
+ *
+ * @ingroup LibFSIMFS
+ *
+ * @brief Mini-IMFS initialization.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+
+#include "imfs.h"
+
+static const rtems_filesystem_operations_table miniIMFS_ops = {
+ .evalpath_h = IMFS_eval_path,
+ .evalformake_h = IMFS_evaluate_for_make,
+ .link_h = rtems_filesystem_default_link,
+ .unlink_h = rtems_filesystem_default_unlink,
+ .node_type_h = IMFS_node_type,
+ .mknod_h = IMFS_mknod,
+ .chown_h = rtems_filesystem_default_chown,
+ .freenod_h = rtems_filesystem_default_freenode,
+ .mount_h = IMFS_mount,
+ .fsmount_me_h = miniIMFS_initialize,
+ .unmount_h = rtems_filesystem_default_unmount,
+ .fsunmount_me_h = rtems_filesystem_default_unmount,
+ .utime_h = rtems_filesystem_default_utime,
+ .eval_link_h = rtems_filesystem_default_evaluate_link,
+ .symlink_h = rtems_filesystem_default_symlink,
+ .readlink_h = rtems_filesystem_default_readlink,
+ .rename_h = rtems_filesystem_default_rename,
+ .statvfs_h = rtems_filesystem_default_statvfs
+};
+
+int miniIMFS_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+)
+{
+ return IMFS_initialize_support(
+ mt_entry,
+ &miniIMFS_ops,
+ &rtems_filesystem_handlers_default, /* for memfiles */
+ &rtems_filesystem_handlers_default, /* for directories */
+ &rtems_filesystem_handlers_default /* for fifos */
+ );
+}
diff --git a/cpukit/libfs/src/nfsclient/.cvsignore b/cpukit/libfs/src/nfsclient/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libfs/src/nfsclient/ChangeLog.slac b/cpukit/libfs/src/nfsclient/ChangeLog.slac
new file mode 100644
index 0000000000..94dea06763
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/ChangeLog.slac
@@ -0,0 +1,112 @@
+Changes since RTEMS-NFS 1.4:
+LICENSE:
+ - changed license terms; RTEMS-NFS is now released under the more liberal
+ 'SLAC license'.
+NFS:
+ - silenced compiler warnings (follow handler declaration changes in libio.h
+ by using 'size_t' instead of 'uint32_t' etc.).
+
+Changes since RTEMS-NFS 1.3:
+RPCIOD:
+ - round timeout to next system clock tick and ensure it is at least
+ 1 tick.
+ - cap retransmission timeout to transaction lifetime.
+ - BUGFIX (reported by Steven Johnson, 12/5/06): we must change the XID
+ before sending a timed-out transaction back to the requestor to prevent
+ a late reply from being accepted.
+ - Made task priority run-time configurable (and read from rtems_bsdnet_config
+ by default).
+
+NFS:
+ - added nfsGetTimeout() and nfsSetTimeout() to retrieve and modify,
+ respectively the (global) timeout for NFS/MOUNT operations.
+ - Minor mod. to fix 'type-punned pointer' warning (can avoid pointer cast).
+ - Added global variable 'nfsStBlksize' (defaults to 8k) which is now
+ used to report the file system's 'preferred' blocksize (stat(2)/st_blksize).
+ The old behavior (server's fattr.st_blksize is passed through) can be
+ obtained by setting nfsStBlksize=0.
+ The new feature lets stdio use 8k buffers (only if newlib was built with
+ HAVE_BLKSIZE defined). This enhances NFS (buffered) read performance quite
+ a bit. Thanks to Steven Johnson <sjohnson@sakuraindustries.com> for helping
+ with this.
+ - Updated README (performance section).
+ - Added simple performance test: nfsTest.c
+
+Changes since RTEMS-NFS 1.3_pre2:
+ RPCIOD:
+ - fix a problem with NFS server clusters (reply comes from an IP address
+ different from the destination of the request) by relaxing paranoia checks.
+
+Changes since RTEMS-NFS 1.2:
+ NFS:
+ - replaced inet_aton -> inet_pton
+ - replaced unsigned32 -> uint32_t
+ - added _KERNEL definition for 4.7 compilation
+ - silenced compiler warnings (4.7)
+ - added -Wno-unused-variable in 'proto' -- rpcgen produces a lot of them.
+ - new locking scheme. The 'in-use' counters cannot be protected by a mutex
+ because files might be closed when a thread is deleted from a dispatch-disabled
+ section where mutexes must not be locked. The counters are now protected by
+ disabling interrupts.
+ The only critical race-condition I can see ATM is while the NFS is being
+ unmounted and the mount point is crossed by another thread. It should be the
+ generic FS code's responsibility to handle that (but AFAIK, it doesn't) --
+ it's out of our scope...
+ - ftruncate didn't work. The functionality is achieved by nfs_sattr()
+ setting the file size to 0. However, nfs_sattr() always tried to set
+ all attributes (re-applying the current values to fields we didn't
+ want to change) which failed (EPERM) if we were not the owner.
+ Now, we restrict modifications to the requested fields (in case of
+ ftruncate this is *only* the size), adhering to rfc1094 (which states
+ that unused fields shall be set to -1).
+ - lseek(SEEK_END) didn't work. The underlying RTEMS filesystem code
+ uses an internal file 'size' field to compute the offset whence SEEK_END.
+ Instead of painfully maintaining 'size' across all system calls, we
+ just tweak the offset for SEEK_END and leave 'size' unused.
+ - fix: O_APPEND wasn't honoured. Note that there is no NFS 'append' call -
+ the client simply uses the currently available idea of the file size
+ to set the write offset. This obviously is subject to race conditions
+ if multiple clients are writing the same file.
+ dirutils:
+ - replaced read/write calls by stdio; In case of copying to stdout, I
+ experienced occasional crashes when write(fileno(stdout),...) -- according
+ to the standard, mixing low-level i/o with stdio might produce undefined
+ results; there we go...
+
+Changes since RTEMS-NFS 1.1:
+ NFS:
+ - unlink() didnt work. The underlying RTEMS filesystem code evaluates
+ a '..' path on a non-directory node to find out the file's parent
+ directory. Workaround to this semantically inelegant RTEMS feature
+ was implemented.
+
+Changes since RTEMS-NFS 1.0.beta3:
+ NFS:
+ - fixed possible string overrun in nfsMount
+ - nfs_read_dir() must reset the 'eofreached' flag if it skipped
+ dirents present in the xdr but not fitting into the user buffer.
+ - nfsMountsShow() released the wrong lock!
+ RPCIO:
+ - cannot delete locked binary semaphore (authlock) -- must unlock
+ first (authlock was never deleted and hence effectively leaked)
+ - added ASSERT paranoia around mutex primitives
+ - Relaxed paranoia check / ASSERTion failure:
+ paranoia_free() is called more than once on an ext_buf - it must
+ undo calls to paranoia_refcnt() - hence the 0 == --refcnt check
+ is too strict.
+ - Added a DEBUG flag to introduce random packet losses for testing
+ retransmission.
+ xdr_mbuf:
+ - make sure we do a signed comparison
+
+Changes since rtemsNFS-1.0.beta2:
+ - moved 'tar' command to the 'config' area; use
+ predefined 'make-tar' in individual Makefiles
+ - use INSTALL_CHANGE for headers, not INSTALL_VARIANT (probably doesn't
+ matter, though)
+ - use LD not LD_FOR_TARGET (to get absolute path)
+ - fixed assertion failure print format
+ - print requestor id if send_event fails - had just experienced this :-(
+ - hint about fprintf using FP registers is probably PPC specific
+ - provided implementation for xdrmbuf_getlong_aligned(). i386-rtems
+ seems to use it.
diff --git a/cpukit/libfs/src/nfsclient/LICENSE b/cpukit/libfs/src/nfsclient/LICENSE
new file mode 100644
index 0000000000..4687f9a22f
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/LICENSE
@@ -0,0 +1,44 @@
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
diff --git a/cpukit/libfs/src/nfsclient/Makefile.am b/cpukit/libfs/src/nfsclient/Makefile.am
new file mode 100644
index 0000000000..98ba99286c
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/Makefile.am
@@ -0,0 +1,74 @@
+#
+# $Id$
+#
+
+include $(top_srcdir)/automake/compile.am
+
+#%dirutils.obj: %dirutils.o
+# $(LD) -r -o $@ $^
+project_lib_PROGRAMS = dirutils.rel
+dirutils_rel_SOURCES = src/dirutils.c
+dirutils_rel_CPPFLAGS = $(AM_CPPFLAGS)
+dirutils_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
+
+if LIBNETWORKING
+project_lib_LIBRARIES = libnfs.a
+
+# if you have CEXP set this variable to 'YES'
+# and some "help" info will be compiled in.
+libnfs_a_SOURCES = src/rpcio.c src/rpcio.h
+libnfs_a_SOURCES += src/nfs.c src/sock_mbuf.c src/xdr_mbuf.c
+libnfs_a_SOURCES += proto/mount_prot.h proto/nfs_prot.h
+
+# With CEXP
+# libnfs_a_SOURCES += dirutils.c rpcio.modini.c nfs.modini.c cexphelp.c
+
+include_HEADERS = src/librtemsNfs.h
+
+# PGMS=${ARCH}/nfs.obj ${ARCH}/rpcio.obj ${ARCH}/dirutils.obj
+
+libnfs_a_CPPFLAGS = $(AM_CPPFLAGS)
+libnfs_a_CPPFLAGS += -I$(srcdir)/proto
+libnfs_a_CPPFLAGS += -UHAVE_CEXP
+
+#%nfs.obj: %nfs.o %nfs.modini.o
+# $(LD) -r -o $@ $^ -L../proto/$(ARCH) -lnfsprot
+project_lib_PROGRAMS += nfs.rel
+nfs_rel_SOURCES = src/nfs.c proto/nfs_prot.h proto/mount_prot.h
+nfs_rel_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/proto
+nfs_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
+nfs_rel_LDADD = libnfs.a
+
+#%rpcio.obj: %rpcio.o %sock_mbuf.o %xdr_mbuf.o %rpcio.modini.o
+# $(LD) -r -o $@ $^
+project_lib_PROGRAMS += rpcio.rel
+rpcio_rel_SOURCES = src/rpcio.c src/sock_mbuf.c src/xdr_mbuf.c
+rpcio_rel_CPPFLAGS = $(AM_CPPFLAGS)
+rpcio_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
+
+libnfs_a_SOURCES += proto/nfs_prot_xdr.c proto/nfs_prot.h
+libnfs_a_SOURCES += proto/mount_prot_xdr.c proto/mount_prot.h
+
+libnfs_a_CPPFLAGS += -I$(srcdir)/proto
+libnfs_a_CPPFLAGS += -UHAVE_CEXP
+endif
+
+
+if RPCTOOLS
+$(srcdir)/proto/mount_prot.h: proto/mount_prot.x
+ (cd $(srcdir)/proto && $(RPCGEN) -h -C mount_prot.x > mount_prot.h)
+
+$(srcdir)/proto/mount_prot_xdr.c: proto/mount_prot.x proto/mount_prot.h
+ (cd $(srcdir)/proto && $(RPCGEN) -c -C mount_prot.x \
+ > mount_prot_xdr.c)
+
+$(srcdir)/proto/nfs_prot.h: proto/nfs_prot.x
+ (cd $(srcdir)/proto && $(RPCGEN) -h -C nfs_prot.x > nfs_prot.h)
+
+$(srcdir)/proto/nfs_prot_xdr.c: proto/nfs_prot.x proto/nfs_prot.h
+ (cd $(srcdir)/proto && $(RPCGEN) -c -C nfs_prot.x \
+ > nfs_prot_xdr.c)
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libfs/src/nfsclient/README b/cpukit/libfs/src/nfsclient/README
new file mode 100644
index 0000000000..944b830e2e
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/README
@@ -0,0 +1,548 @@
+RTEMS-NFS
+=========
+
+A NFS-V2 client implementation for the RTEMS real-time
+executive.
+
+Author: Till Straumann <strauman@slac.stanford.edu>, 2002
+
+Copyright 2002, Stanford University and
+ Till Straumann <strauman@slac.stanford.edu>
+
+Stanford Notice
+***************
+
+Acknowledgement of sponsorship
+* * * * * * * * * * * * * * * *
+This software was produced by the Stanford Linear Accelerator Center,
+Stanford University, under Contract DE-AC03-76SFO0515 with the Department
+of Energy.
+
+
+Contents
+--------
+I Overview
+ 1) Performance
+ 2) Reference Platform / Test Environment
+
+II Usage
+ 1) Initialization
+ 2) Mounting Remote Server Filesystems
+ 3) Unmounting
+ 4) Unloading
+ 5) Dumping Information / Statistics
+
+III Implementation Details
+ 1) RPCIOD
+ 2) NFS
+ 3) RTEMS Resources Used By NFS/RPCIOD
+ 4) Caveats & Bugs
+
+IV Licensing & Disclaimers
+
+I Overview
+-----------
+
+This package implements a simple non-caching NFS
+client for RTEMS. Most of the system calls are
+supported with the exception of 'mount', i.e. it
+is not possible to mount another FS on top of NFS
+(mostly because of the difficulty that arises when
+mount points are deleted on the server). It
+shouldn't be hard to do, though.
+
+Note: this client supports NFS vers. 2 / MOUNT vers. 1;
+ NFS Version 3 or higher are NOT supported.
+
+The package consists of two modules: RPCIOD and NFS
+itself.
+
+ - RPCIOD is a UDP/RPC multiplexor daemon. It takes
+ RPC requests from multiple local client threads,
+ funnels them through a single socket to multiple
+ servers and dispatches the replies back to the
+ (blocked) requestor threads.
+ RPCIOD does packet retransmission and handles
+ timeouts etc.
+ Note however, that it does NOT do any XDR
+ marshalling - it is up to the requestor threads
+ to do the XDR encoding/decoding. RPCIOD _is_ RPC
+ specific, though, because its message dispatching
+ is based on the RPC transaction ID.
+
+ - The NFS package maps RTEMS filesystem calls
+ to proper RPCs, it does the XDR work and
+ hands marshalled RPC requests to RPCIOD.
+ All of the calls are synchronous, i.e. they
+ block until they get a reply.
+
+1) Performance
+- - - - - - - -
+Performance sucks (due to the lack of
+readahead/delayed write and caching). On a fast
+(100Mb/s) ethernet, it takes about 20s to copy a
+10MB file from NFS to NFS. I found, however, that
+vxWorks' NFS client doesn't seem to be any
+faster...
+
+Since there is no buffer cache with read-ahead
+implemented, all NFS reads are synchronous RPC
+calls. Every read operation involves sending a
+request and waiting for the reply. As long as the
+overhead (sending request + processing it on the
+server) is significant compared to the time it
+takes to transferring the actual data, increasing
+the amount of data per request results in better
+throughput. The UDP packet size limit imposes a
+limit of 8k per RPC call, hence reading from NFS
+in chunks of 8k is better than chunks of 1k [but
+chunks >8k are not possible, i.e., simply not
+honoured: read(a_nfs_fd, buf, 20000) returns
+8192]. This is similar to the old linux days
+(mount with rsize=8k). You can let stdio take
+care of the buffering or use 8k buffers with
+explicit read(2) operations. Note that stdio
+honours the file-system's st_blksize field
+if newlib is compiled with HAVE_BLKSIZE defined.
+In this case, stdio uses 8k buffers for files
+on NFS transparently. The blocksize NFS
+reports can be tuned with a global variable
+setting (see nfs.c for details).
+
+Further increase of throughput can be achieved
+with read-ahead (issuing RPC calls in parallel
+[send out request for block n+1 while you are
+waiting for data of block n to arrive]). Since
+this is not handled by the file system itself, you
+would have to code this yourself e.g., using
+parallel threads to read from a single file from
+interleaved offsets.
+
+Another obvious improvement can be achieved if
+processing the data takes a significant amount of
+time. Then, having a pipeline of threads for
+reading data and processing them makes sense
+[thread b processes chunk n while thread a blocks
+in read(chunk n+1)].
+
+Some performance figures:
+Software: src/nfsTest.c:nfsReadTest() [data not
+ processed in any way].
+Hardware: MVME6100
+Network: 100baseT-FD
+Server: Linux-2.6/RHEL4-smp [dell precision 420]
+File: 10MB
+
+Results:
+Single threaded ('normal') NFS read, 1k buffers: 3.46s (2.89MB/s)
+Single threaded ('normal') NFS read, 8k buffers: 1.31s (7.63MB/s)
+Multi threaded; 2 readers, 8k buffers/xfers: 1.12s (8.9 MB/s)
+Multi threaded; 3 readers, 8k buffers/xfers: 1.04s (9.6 MB/s)
+
+2) Reference Platform
+- - - - - - - - - - -
+RTEMS-NFS was developed and tested on
+
+ o RTEMS-ss20020301 (local patches applied)
+ o PowerPC G3, G4 on Synergy SVGM series board
+ (custom 'SVGM' BSP, to be released soon)
+ o PowerPC 604 on MVME23xx
+ (powerpc/shared/motorola-powerpc BSP)
+ o Test Environment:
+ - RTEMS executable running CEXP
+ - rpciod/nfs dynamically loaded from TFTPfs
+ - EPICS application dynamically loaded from NFS;
+ the executing IOC accesses all of its files
+ on NFS.
+
+II Usage
+---------
+
+After linking into the system and proper initialization
+(rtems-NFS supports 'magic' module initialization when
+loaded into a running system with the CEXP loader),
+you are ready for mounting NFSes from a server
+(I avoid the term NFS filesystem because NFS already
+stands for 'Network File System').
+
+You should also read the
+
+ - "RTEMS Resources Used By NFS/RPCIOD"
+ - "CAVEATS & BUGS"
+
+below.
+
+1) Initialization
+- - - - - - - - -
+NFS consists of two modules who must be initialized:
+
+ a) the RPCIO daemon package; by calling
+
+ rpcUdpInit();
+
+ note that this step must be performed prior to
+ initializing NFS:
+
+ b) NFS is initialized by calling
+
+ nfsInit( smallPoolDepth, bigPoolDepth );
+
+ if you supply 0 (zero) values for the pool
+ depths, the compile-time default configuration
+ is used which should work fine.
+
+NOTE: when using CEXP to load these modules into a
+running system, initialization will be performed
+automagically.
+
+2) Mounting Remote Server Filesystems
+- - - - - - - - - - - - - - - - - - -
+
+There are two interfaces for mounting an NFS:
+
+ - The (non-POSIX) RTEMS 'mount()' call:
+
+ mount( &mount_table_entry_pointer,
+ &filesystem_operations_table_pointer,
+ options,
+ device,
+ mount_point )
+
+ Note that you must specify a 'mount_table_entry_pointer'
+ (use a dummy) - RTEMS' mount() doesn't grok a NULL for
+ the first argument.
+
+ o for the 'filesystem_operations_table_pointer', supply
+
+ &nfs_fs_ops
+
+ o options are constants (see RTEMS headers) for specifying
+ read-only / read-write mounts.
+
+ o the 'device' string specifies the remote filesystem
+ who is to be mounted. NFS expects a string conforming
+ to the following format (EBNF syntax):
+
+ [ <uid> '.' <gid> '@' ] <hostip> ':' <path>
+
+ The first optional part of the string allows you
+ to specify the credentials to be used for all
+ subsequent transactions with this server. If the
+ string is omitted, the EUID/EGID of the executing
+ thread (i.e. the thread performing the 'mount' -
+ NFS will still 'remember' these values and use them
+ for all future communication with this server).
+
+ The <hostip> part denotes the server IP address
+ in standard 'dot' notation. It is followed by
+ a colon and the (absolute) path on the server.
+ Note that no extra characters or whitespace must
+ be present in the string. Example 'device' strings
+ are:
+
+ "300.99@192.168.44.3:/remote/rtems/root"
+
+ "192.168.44.3:/remote/rtems/root"
+
+ o the 'mount_point' string identifies the local
+ directory (most probably on IMFS) where the NFS
+ is to be mounted. Note that the mount point must
+ already exist with proper permissions.
+
+ - Alternate 'mount' interface. NFS offers a more
+ convenient wrapper taking three string arguments:
+
+ nfsMount(uidgid_at_host, server_path, mount_point)
+
+ This interface does DNS lookup (see reentrancy note
+ below) and creates the mount point if necessary.
+
+ o the first argument specifies the server and
+ optionally the uid/gid to be used for authentication.
+ The semantics are exactly as described above:
+
+ [ <uid> '.' <gid> '@' ] <host>
+
+ The <host> part may be either a host _name_ or
+ an IP address in 'dot' notation. In the former
+ case, nfsMount() uses 'gethostbyname()' to do
+ a DNS lookup.
+
+ IMPORTANT NOTE: gethostbyname() is NOT reentrant/
+ thread-safe and 'nfsMount()' (if not provided with an
+ IP/dot address string) is hence subject to race conditions.
+
+ o the 'server_path' and 'mount_point' arguments
+ are described above.
+ NOTE: If the mount point does not exist yet,
+ nfsMount() tries to create it.
+
+ o if nfsMount() is called with a NULL 'uidgid_at_host'
+ argument, it lists all currently mounted NFS
+
+3) Unmounting
+- - - - - - -
+An NFS can be unmounted using RTEMS 'unmount()'
+call (yep, it is unmount() - not umount()):
+
+ unmount(mount_point)
+
+Note that you _must_ supply the mount point (string
+argument). It is _not_ possible to specify the
+'mountee' when unmounting. NFS implements no
+convenience wrapper for this (yet), essentially because
+(although this sounds unbelievable) it is non-trivial
+to lookup the path leading to an RTEMS filesystem
+directory node.
+
+4) Unloading
+- - - - - - -
+After unmounting all NFS from the system, the NFS
+and RPCIOD modules may be stopped and unloaded.
+Just call 'nfsCleanup()' and 'rpcUdpCleanup()'
+in this order. You should evaluate the return value
+of these routines which is non-zero if either
+of them refuses to yield (e.g. because there are
+still mounted filesystems).
+Again, when unloading is done by CEXP this is
+transparently handled.
+
+5) Dumping Information / Statistics
+- - - - - - - - - - - - - - - - - -
+
+Rudimentary RPCIOD statistics are printed
+to a file (stdout when NULL) by
+
+ int rpcUdpStats(FILE *f)
+
+A list of all currently mounted NFS can be
+printed to a file (stdout if NULL) using
+
+ int nfsMountsShow(FILE *f)
+
+For convenience, this routine is also called
+by nfsMount() when supplying NULL arguments.
+
+III Implementation Details
+--------------------------
+
+1) RPCIOD
+- - - - -
+
+RPCIOD was created to
+
+a) avoid non-reentrant librpc calls.
+b) support 'asynchronous' operation over a single
+ socket.
+
+RPCIOD is a daemon thread handling 'transaction objects'
+(XACTs) through an UDP socket. XACTs are marshalled RPC
+calls/replies associated with RPC servers and requestor
+threads.
+
+requestor thread: network:
+
+ XACT packet
+ | |
+ V V
+ | message queue | ( socket )
+ | | ^
+ ----------> <----- | |
+ RPCIOD |
+ / --------------
+ timeout/ (re) transmission
+
+
+A requestor thread drops a transaction into
+the message queue and goes to sleep. The XACT is
+picked up by rpciod who is listening for events from
+three sources:
+
+ o the request queue
+ o packet arrival at the socket
+ o timeouts
+
+RPCIOD sends the XACT to its destination server and
+enqueues the pending XACT into an ordered list of
+outstanding transactions.
+
+When a packet arrives, RPCIOD (based on the RPC transaction
+ID) looks up the matching XACT and wakes up the requestor
+who can then XDR-decode the RPC results found in the XACT
+object's buffer.
+
+When a timeout expires, RPCIOD examines the outstanding
+XACT that is responsible for the timeout. If its lifetime
+has not expired yet, RPCIOD resends the request. Otherwise,
+the XACT's error status is set and the requestor is woken up.
+
+RPCIOD dynamically adjusts the retransmission intervals
+based on the average round-trip time measured (on a per-server
+basis).
+
+Having the requestors event driven (rather than blocking
+e.g. on a semaphore) is geared to having many different
+requestors (one synchronization object per requestor would
+be needed otherwise).
+
+Requestors who want to do asynchronous IO need a different
+interface which will be added in the future.
+
+1.a) Reentrancy
+- - - - - - - -
+RPCIOD does no non-reentrant librpc calls.
+
+1.b) Efficiency
+- - - - - - - -
+We shouldn't bother about efficiency until pipelining (read-ahead/
+delayed write) and caching are implemented. The round-trip delay
+associated with every single RPC transaction clearly is a big
+performance killer.
+
+Nevertheless, I could not withstand the temptation to eliminate
+the extra copy step involved with socket IO:
+
+A user data object has to be XDR encoded into a buffer. The
+buffer given to the socket where it is copied into MBUFs.
+(The network chip driver might even do more copying).
+
+Likewise, on reception 'recvfrom' copies MBUFS into a user
+buffer which is XDR decoded into the final user data object.
+
+Eliminating the copying into (possibly multiple) MBUFS by
+'sendto()' is actually a piece of cake. RPCIOD uses the
+'sosend()' routine [properly wrapped] supplying a single
+MBUF header who directly points to the marshalled buffer
+:-)
+
+Getting rid of the extra copy on reception was (only a little)
+harder: I derived a 'XDR-mbuf' stream from SUN's xdr_mem which
+allows for XDR-decoding out of a MBUF chain who is obtained by
+soreceive().
+
+2) NFS
+- - - -
+The actual NFS implementation is straightforward and essentially
+'passive' (no threads created). Any RTEMS task executing a
+filesystem call dispatched to NFS (such as 'opendir()', 'lseek()'
+or 'unlink()') ends up XDR encoding arguments, dropping a
+XACT into RPCIOD's message queue and going to sleep.
+When woken up by RPCIOD, the XACT is decoded (using the XDR-mbuf
+stream mentioned above) and the properly cooked-up results are
+returned.
+
+3) RTEMS Resources Used By NFS/RPCIOD
+- - - - - - - - - - - - - - - - - - -
+
+The RPCIOD/NFS package uses the following resources. Some
+parameters are compile-time configurable - consult the
+source files for details.
+
+RPCIOD:
+ o 1 task
+ o 1 message queue
+ o 1 socket/filedescriptor
+ o 2 semaphores (a third one is temporarily created during
+ rpcUdpCleanup()).
+ o 1 RTEMS EVENT (by default RTEMS_EVENT_30).
+ IMPORTANT: this event is used by _every_ thread executing
+ NFS system calls and hence is RESERVED.
+ o 3 events only used by RPCIOD itself, i.e. these must not
+ be sent to RPCIOD by no other thread (except for the intended
+ use, of course). The events involved are 1,2,3.
+ o preemption disabled sections: NONE
+ o sections with interrupts disabled: NONE
+ o NO 'timers' are used (timer code would run in IRQ context)
+ o memory usage: n.a
+
+NFS:
+ o 2 message queues
+ o 2 semaphores
+ o 1 semaphore per mounted NFS
+ o 1 slot in driver entry table (for major number)
+ o preemption disabled sections: NONE
+ o sections with interrupts disabled: NONE
+ o 1 task + 1 semaphore temporarily created when
+ listing mounted filesystems (rtems_filesystem_resolve_location())
+
+4) CAVEATS & BUGS
+- - - - - - - - -
+Unfortunately, some bugs crawl around in the filesystem generics.
+(Some of them might already be fixed in versions later than
+rtems-ss-20020301).
+I recommend to use the patch distributed with RTEMS-NFS.
+
+ o RTEMS uses/used (Joel said it has been fixed already) a 'short'
+ ino_t which is not enough for NFS.
+ The driver detects this problem and enables a workaround. In rare
+ situations (mainly involving 'getcwd()' improper inode comparison
+ may result (due to the restricted size, stat() returns st_ino modulo
+ 2^16). In most cases, however, st_dev is compared along with st_ino
+ which will give correct results (different files may yield identical
+ st_ino but they will have different st_dev). However, there is
+ code (in getcwd(), for example) who assumes that files residing
+ in one directory must be hosted by the same device and hence omits
+ the st_dev comparison. In such a case, the workaround will fail.
+
+ NOTE: changing the size (sys/types.h) of ino_t from 'short' to 'long'
+ is strongly recommended. It is NOT included in the patch, however
+ as this is a major change requiring ALL of your sources to
+ be recompiled.
+
+ THE ino_t SIZE IS FIXED IN GCC-3.2/NEWLIB-1.10.0-2 DISTRIBUTED BY
+ OAR.
+
+ o You may work around most filesystem bugs by observing the following
+ rules:
+
+ * never use chroot() (fixed by the patch)
+ * never use getpwent(), getgrent() & friends - they are NOT THREAD
+ safe (fixed by the patch)
+ * NEVER use rtems_libio_share_private_env() - not even with the
+ patch applied. Just DONT - it is broken by design.
+ * All threads who have their own userenv (who have called
+ rtems_libio_set_private_env()) SHOULD 'chdir("/")' before
+ terminating. Otherwise, (i.e. if their cwd is on NFS), it will
+ be impossible to unmount the NFS involved.
+
+ o The patch slightly changes the semantics of 'getpwent()' and
+ 'getgrent()' & friends (to what is IMHO correct anyways - the patch is
+ also needed to fix another problem, however): with the patch applied,
+ the passwd and group files are always accessed from the 'current' user
+ environment, i.e. a thread who has changed its 'root' or 'uid' might
+ not be able to access these files anymore.
+
+ o NOTE: RTEMS 'mount()' / 'unmount()' are NOT THREAD SAFE.
+
+ o The NFS protocol has no 'append' or 'seek_end' primitive. The client
+ must query the current file size (this client uses cached info) and
+ change the local file pointer accordingly (in 'O_APPEND' mode).
+ Obviously, this involves a race condition and hence multiple clients
+ writing the same file may lead to corruption.
+
+IV Licensing & Disclaimers
+--------------------------
+
+NFS is distributed under the SLAC License - consult the
+separate 'LICENSE' file.
+
+Government disclaimer of liability
+- - - - - - - - - - - - - - - - -
+Neither the United States nor the United States Department of Energy,
+nor any of their employees, makes any warranty, express or implied,
+or assumes any legal liability or responsibility for the accuracy,
+completeness, or usefulness of any data, apparatus, product, or process
+disclosed, or represents that its use would not infringe privately
+owned rights.
+
+Stanford disclaimer of liability
+- - - - - - - - - - - - - - - - -
+Stanford University makes no representations or warranties, express or
+implied, nor assumes any liability for the use of this software.
+
+Maintenance of notice
+- - - - - - - - - - -
+In the interest of clarity regarding the origin and status of this
+software, Stanford University requests that any recipient of it maintain
+this notice affixed to any distribution by the recipient that contains a
+copy or derivative of this software.
diff --git a/cpukit/libfs/src/nfsclient/preinstall.am b/cpukit/libfs/src/nfsclient/preinstall.am
new file mode 100644
index 0000000000..c65f7f76dc
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/preinstall.am
@@ -0,0 +1,51 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_LIB)/dirutils.rel: dirutils.rel $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_PROGRAM) $< $(PROJECT_LIB)/dirutils.rel
+TMPINSTALL_FILES += $(PROJECT_LIB)/dirutils.rel
+
+if LIBNETWORKING
+$(PROJECT_LIB)/libnfs.a: libnfs.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libnfs.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libnfs.a
+
+$(PROJECT_INCLUDE)/librtemsNfs.h: src/librtemsNfs.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/librtemsNfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/librtemsNfs.h
+
+$(PROJECT_LIB)/nfs.rel: nfs.rel $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_PROGRAM) $< $(PROJECT_LIB)/nfs.rel
+TMPINSTALL_FILES += $(PROJECT_LIB)/nfs.rel
+
+$(PROJECT_LIB)/rpcio.rel: rpcio.rel $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_PROGRAM) $< $(PROJECT_LIB)/rpcio.rel
+TMPINSTALL_FILES += $(PROJECT_LIB)/rpcio.rel
+endif
diff --git a/cpukit/libfs/src/nfsclient/proto/mount_prot.h b/cpukit/libfs/src/nfsclient/proto/mount_prot.h
new file mode 100644
index 0000000000..1cde517aea
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/proto/mount_prot.h
@@ -0,0 +1,144 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#ifndef _MOUNT_PROT_H_RPCGEN
+#define _MOUNT_PROT_H_RPCGEN
+
+#include <rpc/rpc.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MNTPATHLEN 1024
+#define MNTNAMLEN 255
+#define FHSIZE 32
+
+typedef char fhandle[FHSIZE];
+
+struct fhstatus {
+ u_int fhs_status;
+ union {
+ fhandle fhs_fhandle;
+ } fhstatus_u;
+};
+typedef struct fhstatus fhstatus;
+
+typedef char *dirpath;
+
+typedef char *name;
+
+typedef struct mountbody *mountlist;
+
+struct mountbody {
+ name ml_hostname;
+ dirpath ml_directory;
+ mountlist ml_next;
+};
+typedef struct mountbody mountbody;
+
+typedef struct groupnode *groups;
+
+struct groupnode {
+ name gr_name;
+ groups gr_next;
+};
+typedef struct groupnode groupnode;
+
+typedef struct exportnode *exports;
+
+struct exportnode {
+ dirpath ex_dir;
+ groups ex_groups;
+ exports ex_next;
+};
+typedef struct exportnode exportnode;
+
+#define MOUNTPROG 100005
+#define MOUNTVERS 1
+
+#if defined(__STDC__) || defined(__cplusplus)
+#define MOUNTPROC_NULL 0
+extern void * mountproc_null_1(void *, CLIENT *);
+extern void * mountproc_null_1_svc(void *, struct svc_req *);
+#define MOUNTPROC_MNT 1
+extern fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
+extern fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
+#define MOUNTPROC_DUMP 2
+extern mountlist * mountproc_dump_1(void *, CLIENT *);
+extern mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
+#define MOUNTPROC_UMNT 3
+extern void * mountproc_umnt_1(dirpath *, CLIENT *);
+extern void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
+#define MOUNTPROC_UMNTALL 4
+extern void * mountproc_umntall_1(void *, CLIENT *);
+extern void * mountproc_umntall_1_svc(void *, struct svc_req *);
+#define MOUNTPROC_EXPORT 5
+extern exports * mountproc_export_1(void *, CLIENT *);
+extern exports * mountproc_export_1_svc(void *, struct svc_req *);
+#define MOUNTPROC_EXPORTALL 6
+extern exports * mountproc_exportall_1(void *, CLIENT *);
+extern exports * mountproc_exportall_1_svc(void *, struct svc_req *);
+extern int mountprog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
+
+#else /* K&R C */
+#define MOUNTPROC_NULL 0
+extern void * mountproc_null_1();
+extern void * mountproc_null_1_svc();
+#define MOUNTPROC_MNT 1
+extern fhstatus * mountproc_mnt_1();
+extern fhstatus * mountproc_mnt_1_svc();
+#define MOUNTPROC_DUMP 2
+extern mountlist * mountproc_dump_1();
+extern mountlist * mountproc_dump_1_svc();
+#define MOUNTPROC_UMNT 3
+extern void * mountproc_umnt_1();
+extern void * mountproc_umnt_1_svc();
+#define MOUNTPROC_UMNTALL 4
+extern void * mountproc_umntall_1();
+extern void * mountproc_umntall_1_svc();
+#define MOUNTPROC_EXPORT 5
+extern exports * mountproc_export_1();
+extern exports * mountproc_export_1_svc();
+#define MOUNTPROC_EXPORTALL 6
+extern exports * mountproc_exportall_1();
+extern exports * mountproc_exportall_1_svc();
+extern int mountprog_1_freeresult ();
+#endif /* K&R C */
+
+/* the xdr functions */
+
+#if defined(__STDC__) || defined(__cplusplus)
+extern bool_t xdr_fhandle (XDR *, fhandle);
+extern bool_t xdr_fhstatus (XDR *, fhstatus*);
+extern bool_t xdr_dirpath (XDR *, dirpath*);
+extern bool_t xdr_name (XDR *, name*);
+extern bool_t xdr_mountlist (XDR *, mountlist*);
+extern bool_t xdr_mountbody (XDR *, mountbody*);
+extern bool_t xdr_groups (XDR *, groups*);
+extern bool_t xdr_groupnode (XDR *, groupnode*);
+extern bool_t xdr_exports (XDR *, exports*);
+extern bool_t xdr_exportnode (XDR *, exportnode*);
+
+#else /* K&R C */
+extern bool_t xdr_fhandle ();
+extern bool_t xdr_fhstatus ();
+extern bool_t xdr_dirpath ();
+extern bool_t xdr_name ();
+extern bool_t xdr_mountlist ();
+extern bool_t xdr_mountbody ();
+extern bool_t xdr_groups ();
+extern bool_t xdr_groupnode ();
+extern bool_t xdr_exports ();
+extern bool_t xdr_exportnode ();
+
+#endif /* K&R C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_MOUNT_PROT_H_RPCGEN */
diff --git a/cpukit/libfs/src/nfsclient/proto/mount_prot.x b/cpukit/libfs/src/nfsclient/proto/mount_prot.x
new file mode 100644
index 0000000000..7e0d7f3ad6
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/proto/mount_prot.x
@@ -0,0 +1,161 @@
+/* @(#)mount.x 2.1 88/08/01 4.0 RPCSRC */
+/* @(#)mount.x 1.2 87/09/18 Copyr 1987 Sun Micro */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Protocol description for the mount program
+ */
+
+
+const MNTPATHLEN = 1024; /* maximum bytes in a pathname argument */
+const MNTNAMLEN = 255; /* maximum bytes in a name argument */
+const FHSIZE = 32; /* size in bytes of a file handle */
+
+/*
+ * The fhandle is the file handle that the server passes to the client.
+ * All file operations are done using the file handles to refer to a file
+ * or a directory. The file handle can contain whatever information the
+ * server needs to distinguish an individual file.
+ */
+typedef opaque fhandle[FHSIZE];
+
+/*
+ * If a status of zero is returned, the call completed successfully, and
+ * a file handle for the directory follows. A non-zero status indicates
+ * some sort of error. The status corresponds with UNIX error numbers.
+ */
+union fhstatus switch (unsigned fhs_status) {
+case 0:
+ fhandle fhs_fhandle;
+default:
+ void;
+};
+
+/*
+ * The type dirpath is the pathname of a directory
+ */
+typedef string dirpath<MNTPATHLEN>;
+
+/*
+ * The type name is used for arbitrary names (hostnames, groupnames)
+ */
+typedef string name<MNTNAMLEN>;
+
+/*
+ * A list of who has what mounted
+ */
+typedef struct mountbody *mountlist;
+struct mountbody {
+ name ml_hostname;
+ dirpath ml_directory;
+ mountlist ml_next;
+};
+
+/*
+ * A list of netgroups
+ */
+typedef struct groupnode *groups;
+struct groupnode {
+ name gr_name;
+ groups gr_next;
+};
+
+/*
+ * A list of what is exported and to whom
+ */
+typedef struct exportnode *exports;
+struct exportnode {
+ dirpath ex_dir;
+ groups ex_groups;
+ exports ex_next;
+};
+
+program MOUNTPROG {
+ /*
+ * Version one of the mount protocol communicates with version two
+ * of the NFS protocol. The only connecting point is the fhandle
+ * structure, which is the same for both protocols.
+ */
+ version MOUNTVERS {
+ /*
+ * Does no work. It is made available in all RPC services
+ * to allow server reponse testing and timing
+ */
+ void
+ MOUNTPROC_NULL(void) = 0;
+
+ /*
+ * If fhs_status is 0, then fhs_fhandle contains the
+ * file handle for the directory. This file handle may
+ * be used in the NFS protocol. This procedure also adds
+ * a new entry to the mount list for this client mounting
+ * the directory.
+ * Unix authentication required.
+ */
+ fhstatus
+ MOUNTPROC_MNT(dirpath) = 1;
+
+ /*
+ * Returns the list of remotely mounted filesystems. The
+ * mountlist contains one entry for each hostname and
+ * directory pair.
+ */
+ mountlist
+ MOUNTPROC_DUMP(void) = 2;
+
+ /*
+ * Removes the mount list entry for the directory
+ * Unix authentication required.
+ */
+ void
+ MOUNTPROC_UMNT(dirpath) = 3;
+
+ /*
+ * Removes all of the mount list entries for this client
+ * Unix authentication required.
+ */
+ void
+ MOUNTPROC_UMNTALL(void) = 4;
+
+ /*
+ * Returns a list of all the exported filesystems, and which
+ * machines are allowed to import it.
+ */
+ exports
+ MOUNTPROC_EXPORT(void) = 5;
+
+ /*
+ * Identical to MOUNTPROC_EXPORT above
+ */
+ exports
+ MOUNTPROC_EXPORTALL(void) = 6;
+ } = 1;
+} = 100005;
diff --git a/cpukit/libfs/src/nfsclient/proto/mount_prot_xdr.c b/cpukit/libfs/src/nfsclient/proto/mount_prot_xdr.c
new file mode 100644
index 0000000000..b439ef341f
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/proto/mount_prot_xdr.c
@@ -0,0 +1,104 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#include "mount_prot.h"
+
+bool_t
+xdr_fhandle (XDR *xdrs, fhandle objp)
+{
+ if (!xdr_opaque (xdrs, objp, FHSIZE))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_fhstatus (XDR *xdrs, fhstatus *objp)
+{
+ if (!xdr_u_int (xdrs, &objp->fhs_status))
+ return FALSE;
+ switch (objp->fhs_status) {
+ case 0:
+ if (!xdr_fhandle (xdrs, objp->fhstatus_u.fhs_fhandle))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool_t
+xdr_dirpath (XDR *xdrs, dirpath *objp)
+{
+ if (!xdr_string (xdrs, objp, MNTPATHLEN))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_name (XDR *xdrs, name *objp)
+{
+ if (!xdr_string (xdrs, objp, MNTNAMLEN))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_mountlist (XDR *xdrs, mountlist *objp)
+{
+ if (!xdr_pointer (xdrs, (char **)objp, sizeof (struct mountbody), (xdrproc_t) xdr_mountbody))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_mountbody (XDR *xdrs, mountbody *objp)
+{
+ if (!xdr_name (xdrs, &objp->ml_hostname))
+ return FALSE;
+ if (!xdr_dirpath (xdrs, &objp->ml_directory))
+ return FALSE;
+ if (!xdr_mountlist (xdrs, &objp->ml_next))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_groups (XDR *xdrs, groups *objp)
+{
+ if (!xdr_pointer (xdrs, (char **)objp, sizeof (struct groupnode), (xdrproc_t) xdr_groupnode))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_groupnode (XDR *xdrs, groupnode *objp)
+{
+ if (!xdr_name (xdrs, &objp->gr_name))
+ return FALSE;
+ if (!xdr_groups (xdrs, &objp->gr_next))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_exports (XDR *xdrs, exports *objp)
+{
+ if (!xdr_pointer (xdrs, (char **)objp, sizeof (struct exportnode), (xdrproc_t) xdr_exportnode))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_exportnode (XDR *xdrs, exportnode *objp)
+{
+ if (!xdr_dirpath (xdrs, &objp->ex_dir))
+ return FALSE;
+ if (!xdr_groups (xdrs, &objp->ex_groups))
+ return FALSE;
+ if (!xdr_exports (xdrs, &objp->ex_next))
+ return FALSE;
+ return TRUE;
+}
diff --git a/cpukit/libfs/src/nfsclient/proto/nfs_prot.h b/cpukit/libfs/src/nfsclient/proto/nfs_prot.h
new file mode 100644
index 0000000000..de812dbfcf
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/proto/nfs_prot.h
@@ -0,0 +1,453 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#ifndef _NFS_PROT_H_RPCGEN
+#define _NFS_PROT_H_RPCGEN
+
+#include <rpc/rpc.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NFS_PORT 2049
+#define NFS_MAXDATA 8192
+#define NFS_MAXPATHLEN 1024
+#define NFS_MAXNAMLEN 255
+#define NFS_FHSIZE 32
+#define NFS_COOKIESIZE 4
+#define NFS_FIFO_DEV -1
+#define NFSMODE_FMT 0170000
+#define NFSMODE_DIR 0040000
+#define NFSMODE_CHR 0020000
+#define NFSMODE_BLK 0060000
+#define NFSMODE_REG 0100000
+#define NFSMODE_LNK 0120000
+#define NFSMODE_SOCK 0140000
+#define NFSMODE_FIFO 0010000
+
+enum nfsstat {
+ NFS_OK = 0,
+ NFSERR_PERM = 1,
+ NFSERR_NOENT = 2,
+ NFSERR_IO = 5,
+ NFSERR_NXIO = 6,
+ NFSERR_ACCES = 13,
+ NFSERR_EXIST = 17,
+ NFSERR_NODEV = 19,
+ NFSERR_NOTDIR = 20,
+ NFSERR_ISDIR = 21,
+ NFSERR_FBIG = 27,
+ NFSERR_NOSPC = 28,
+ NFSERR_ROFS = 30,
+ NFSERR_NAMETOOLONG = 63,
+ NFSERR_NOTEMPTY = 66,
+ NFSERR_DQUOT = 69,
+ NFSERR_STALE = 70,
+ NFSERR_WFLUSH = 99,
+};
+typedef enum nfsstat nfsstat;
+
+enum ftype {
+ NFNON = 0,
+ NFREG = 1,
+ NFDIR = 2,
+ NFBLK = 3,
+ NFCHR = 4,
+ NFLNK = 5,
+ NFSOCK = 6,
+ NFBAD = 7,
+ NFFIFO = 8,
+};
+typedef enum ftype ftype;
+
+struct nfs_fh {
+ char data[NFS_FHSIZE];
+};
+typedef struct nfs_fh nfs_fh;
+
+struct nfstime {
+ u_int seconds;
+ u_int useconds;
+};
+typedef struct nfstime nfstime;
+
+struct fattr {
+ ftype type;
+ u_int mode;
+ u_int nlink;
+ u_int uid;
+ u_int gid;
+ u_int size;
+ u_int blocksize;
+ u_int rdev;
+ u_int blocks;
+ u_int fsid;
+ u_int fileid;
+ nfstime atime;
+ nfstime mtime;
+ nfstime ctime;
+};
+typedef struct fattr fattr;
+
+struct sattr {
+ u_int mode;
+ u_int uid;
+ u_int gid;
+ u_int size;
+ nfstime atime;
+ nfstime mtime;
+};
+typedef struct sattr sattr;
+
+typedef char *filename;
+
+typedef char *nfspath;
+
+struct attrstat {
+ nfsstat status;
+ union {
+ fattr attributes;
+ } attrstat_u;
+};
+typedef struct attrstat attrstat;
+
+struct sattrargs {
+ nfs_fh file;
+ sattr attributes;
+};
+typedef struct sattrargs sattrargs;
+
+struct diropargs {
+ nfs_fh dir;
+ filename name;
+};
+typedef struct diropargs diropargs;
+
+struct diropokres {
+ nfs_fh file;
+ fattr attributes;
+};
+typedef struct diropokres diropokres;
+
+struct diropres {
+ nfsstat status;
+ union {
+ diropokres diropres;
+ } diropres_u;
+};
+typedef struct diropres diropres;
+
+struct readlinkres {
+ nfsstat status;
+ union {
+ nfspath data;
+ } readlinkres_u;
+};
+typedef struct readlinkres readlinkres;
+
+struct readargs {
+ nfs_fh file;
+ u_int offset;
+ u_int count;
+ u_int totalcount;
+};
+typedef struct readargs readargs;
+
+struct readokres {
+ fattr attributes;
+ struct {
+ u_int data_len;
+ char *data_val;
+ } data;
+};
+typedef struct readokres readokres;
+
+struct readres {
+ nfsstat status;
+ union {
+ readokres reply;
+ } readres_u;
+};
+typedef struct readres readres;
+
+struct writeargs {
+ nfs_fh file;
+ u_int beginoffset;
+ u_int offset;
+ u_int totalcount;
+ struct {
+ u_int data_len;
+ char *data_val;
+ } data;
+};
+typedef struct writeargs writeargs;
+
+struct createargs {
+ diropargs where;
+ sattr attributes;
+};
+typedef struct createargs createargs;
+
+struct renameargs {
+ diropargs from;
+ diropargs to;
+};
+typedef struct renameargs renameargs;
+
+struct linkargs {
+ nfs_fh from;
+ diropargs to;
+};
+typedef struct linkargs linkargs;
+
+struct symlinkargs {
+ diropargs from;
+ nfspath to;
+ sattr attributes;
+};
+typedef struct symlinkargs symlinkargs;
+
+struct nfscookie {
+ char data[NFS_COOKIESIZE];
+};
+typedef struct nfscookie nfscookie;
+
+struct readdirargs {
+ nfs_fh dir;
+ nfscookie cookie;
+ u_int count;
+};
+typedef struct readdirargs readdirargs;
+
+struct entry {
+ u_int fileid;
+ filename name;
+ nfscookie cookie;
+ struct entry *nextentry;
+};
+typedef struct entry entry;
+
+struct dirlist {
+ entry *entries;
+ bool_t eof;
+};
+typedef struct dirlist dirlist;
+
+struct readdirres {
+ nfsstat status;
+ union {
+ dirlist reply;
+ } readdirres_u;
+};
+typedef struct readdirres readdirres;
+
+struct statfsokres {
+ u_int tsize;
+ u_int bsize;
+ u_int blocks;
+ u_int bfree;
+ u_int bavail;
+};
+typedef struct statfsokres statfsokres;
+
+struct statfsres {
+ nfsstat status;
+ union {
+ statfsokres reply;
+ } statfsres_u;
+};
+typedef struct statfsres statfsres;
+
+#define NFS_PROGRAM 100003
+#define NFS_VERSION 2
+
+#if defined(__STDC__) || defined(__cplusplus)
+#define NFSPROC_NULL 0
+extern void * nfsproc_null_2(void *, CLIENT *);
+extern void * nfsproc_null_2_svc(void *, struct svc_req *);
+#define NFSPROC_GETATTR 1
+extern attrstat * nfsproc_getattr_2(nfs_fh *, CLIENT *);
+extern attrstat * nfsproc_getattr_2_svc(nfs_fh *, struct svc_req *);
+#define NFSPROC_SETATTR 2
+extern attrstat * nfsproc_setattr_2(sattrargs *, CLIENT *);
+extern attrstat * nfsproc_setattr_2_svc(sattrargs *, struct svc_req *);
+#define NFSPROC_ROOT 3
+extern void * nfsproc_root_2(void *, CLIENT *);
+extern void * nfsproc_root_2_svc(void *, struct svc_req *);
+#define NFSPROC_LOOKUP 4
+extern diropres * nfsproc_lookup_2(diropargs *, CLIENT *);
+extern diropres * nfsproc_lookup_2_svc(diropargs *, struct svc_req *);
+#define NFSPROC_READLINK 5
+extern readlinkres * nfsproc_readlink_2(nfs_fh *, CLIENT *);
+extern readlinkres * nfsproc_readlink_2_svc(nfs_fh *, struct svc_req *);
+#define NFSPROC_READ 6
+extern readres * nfsproc_read_2(readargs *, CLIENT *);
+extern readres * nfsproc_read_2_svc(readargs *, struct svc_req *);
+#define NFSPROC_WRITECACHE 7
+extern void * nfsproc_writecache_2(void *, CLIENT *);
+extern void * nfsproc_writecache_2_svc(void *, struct svc_req *);
+#define NFSPROC_WRITE 8
+extern attrstat * nfsproc_write_2(writeargs *, CLIENT *);
+extern attrstat * nfsproc_write_2_svc(writeargs *, struct svc_req *);
+#define NFSPROC_CREATE 9
+extern diropres * nfsproc_create_2(createargs *, CLIENT *);
+extern diropres * nfsproc_create_2_svc(createargs *, struct svc_req *);
+#define NFSPROC_REMOVE 10
+extern nfsstat * nfsproc_remove_2(diropargs *, CLIENT *);
+extern nfsstat * nfsproc_remove_2_svc(diropargs *, struct svc_req *);
+#define NFSPROC_RENAME 11
+extern nfsstat * nfsproc_rename_2(renameargs *, CLIENT *);
+extern nfsstat * nfsproc_rename_2_svc(renameargs *, struct svc_req *);
+#define NFSPROC_LINK 12
+extern nfsstat * nfsproc_link_2(linkargs *, CLIENT *);
+extern nfsstat * nfsproc_link_2_svc(linkargs *, struct svc_req *);
+#define NFSPROC_SYMLINK 13
+extern nfsstat * nfsproc_symlink_2(symlinkargs *, CLIENT *);
+extern nfsstat * nfsproc_symlink_2_svc(symlinkargs *, struct svc_req *);
+#define NFSPROC_MKDIR 14
+extern diropres * nfsproc_mkdir_2(createargs *, CLIENT *);
+extern diropres * nfsproc_mkdir_2_svc(createargs *, struct svc_req *);
+#define NFSPROC_RMDIR 15
+extern nfsstat * nfsproc_rmdir_2(diropargs *, CLIENT *);
+extern nfsstat * nfsproc_rmdir_2_svc(diropargs *, struct svc_req *);
+#define NFSPROC_READDIR 16
+extern readdirres * nfsproc_readdir_2(readdirargs *, CLIENT *);
+extern readdirres * nfsproc_readdir_2_svc(readdirargs *, struct svc_req *);
+#define NFSPROC_STATFS 17
+extern statfsres * nfsproc_statfs_2(nfs_fh *, CLIENT *);
+extern statfsres * nfsproc_statfs_2_svc(nfs_fh *, struct svc_req *);
+extern int nfs_program_2_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
+
+#else /* K&R C */
+#define NFSPROC_NULL 0
+extern void * nfsproc_null_2();
+extern void * nfsproc_null_2_svc();
+#define NFSPROC_GETATTR 1
+extern attrstat * nfsproc_getattr_2();
+extern attrstat * nfsproc_getattr_2_svc();
+#define NFSPROC_SETATTR 2
+extern attrstat * nfsproc_setattr_2();
+extern attrstat * nfsproc_setattr_2_svc();
+#define NFSPROC_ROOT 3
+extern void * nfsproc_root_2();
+extern void * nfsproc_root_2_svc();
+#define NFSPROC_LOOKUP 4
+extern diropres * nfsproc_lookup_2();
+extern diropres * nfsproc_lookup_2_svc();
+#define NFSPROC_READLINK 5
+extern readlinkres * nfsproc_readlink_2();
+extern readlinkres * nfsproc_readlink_2_svc();
+#define NFSPROC_READ 6
+extern readres * nfsproc_read_2();
+extern readres * nfsproc_read_2_svc();
+#define NFSPROC_WRITECACHE 7
+extern void * nfsproc_writecache_2();
+extern void * nfsproc_writecache_2_svc();
+#define NFSPROC_WRITE 8
+extern attrstat * nfsproc_write_2();
+extern attrstat * nfsproc_write_2_svc();
+#define NFSPROC_CREATE 9
+extern diropres * nfsproc_create_2();
+extern diropres * nfsproc_create_2_svc();
+#define NFSPROC_REMOVE 10
+extern nfsstat * nfsproc_remove_2();
+extern nfsstat * nfsproc_remove_2_svc();
+#define NFSPROC_RENAME 11
+extern nfsstat * nfsproc_rename_2();
+extern nfsstat * nfsproc_rename_2_svc();
+#define NFSPROC_LINK 12
+extern nfsstat * nfsproc_link_2();
+extern nfsstat * nfsproc_link_2_svc();
+#define NFSPROC_SYMLINK 13
+extern nfsstat * nfsproc_symlink_2();
+extern nfsstat * nfsproc_symlink_2_svc();
+#define NFSPROC_MKDIR 14
+extern diropres * nfsproc_mkdir_2();
+extern diropres * nfsproc_mkdir_2_svc();
+#define NFSPROC_RMDIR 15
+extern nfsstat * nfsproc_rmdir_2();
+extern nfsstat * nfsproc_rmdir_2_svc();
+#define NFSPROC_READDIR 16
+extern readdirres * nfsproc_readdir_2();
+extern readdirres * nfsproc_readdir_2_svc();
+#define NFSPROC_STATFS 17
+extern statfsres * nfsproc_statfs_2();
+extern statfsres * nfsproc_statfs_2_svc();
+extern int nfs_program_2_freeresult ();
+#endif /* K&R C */
+
+/* the xdr functions */
+
+#if defined(__STDC__) || defined(__cplusplus)
+extern bool_t xdr_nfsstat (XDR *, nfsstat*);
+extern bool_t xdr_ftype (XDR *, ftype*);
+extern bool_t xdr_nfs_fh (XDR *, nfs_fh*);
+extern bool_t xdr_nfstime (XDR *, nfstime*);
+extern bool_t xdr_fattr (XDR *, fattr*);
+extern bool_t xdr_sattr (XDR *, sattr*);
+extern bool_t xdr_filename (XDR *, filename*);
+extern bool_t xdr_nfspath (XDR *, nfspath*);
+extern bool_t xdr_attrstat (XDR *, attrstat*);
+extern bool_t xdr_sattrargs (XDR *, sattrargs*);
+extern bool_t xdr_diropargs (XDR *, diropargs*);
+extern bool_t xdr_diropokres (XDR *, diropokres*);
+extern bool_t xdr_diropres (XDR *, diropres*);
+extern bool_t xdr_readlinkres (XDR *, readlinkres*);
+extern bool_t xdr_readargs (XDR *, readargs*);
+extern bool_t xdr_readokres (XDR *, readokres*);
+extern bool_t xdr_readres (XDR *, readres*);
+extern bool_t xdr_writeargs (XDR *, writeargs*);
+extern bool_t xdr_createargs (XDR *, createargs*);
+extern bool_t xdr_renameargs (XDR *, renameargs*);
+extern bool_t xdr_linkargs (XDR *, linkargs*);
+extern bool_t xdr_symlinkargs (XDR *, symlinkargs*);
+extern bool_t xdr_nfscookie (XDR *, nfscookie*);
+extern bool_t xdr_readdirargs (XDR *, readdirargs*);
+extern bool_t xdr_entry (XDR *, entry*);
+extern bool_t xdr_dirlist (XDR *, dirlist*);
+extern bool_t xdr_readdirres (XDR *, readdirres*);
+extern bool_t xdr_statfsokres (XDR *, statfsokres*);
+extern bool_t xdr_statfsres (XDR *, statfsres*);
+
+#else /* K&R C */
+extern bool_t xdr_nfsstat ();
+extern bool_t xdr_ftype ();
+extern bool_t xdr_nfs_fh ();
+extern bool_t xdr_nfstime ();
+extern bool_t xdr_fattr ();
+extern bool_t xdr_sattr ();
+extern bool_t xdr_filename ();
+extern bool_t xdr_nfspath ();
+extern bool_t xdr_attrstat ();
+extern bool_t xdr_sattrargs ();
+extern bool_t xdr_diropargs ();
+extern bool_t xdr_diropokres ();
+extern bool_t xdr_diropres ();
+extern bool_t xdr_readlinkres ();
+extern bool_t xdr_readargs ();
+extern bool_t xdr_readokres ();
+extern bool_t xdr_readres ();
+extern bool_t xdr_writeargs ();
+extern bool_t xdr_createargs ();
+extern bool_t xdr_renameargs ();
+extern bool_t xdr_linkargs ();
+extern bool_t xdr_symlinkargs ();
+extern bool_t xdr_nfscookie ();
+extern bool_t xdr_readdirargs ();
+extern bool_t xdr_entry ();
+extern bool_t xdr_dirlist ();
+extern bool_t xdr_readdirres ();
+extern bool_t xdr_statfsokres ();
+extern bool_t xdr_statfsres ();
+
+#endif /* K&R C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_NFS_PROT_H_RPCGEN */
diff --git a/cpukit/libfs/src/nfsclient/proto/nfs_prot.x b/cpukit/libfs/src/nfsclient/proto/nfs_prot.x
new file mode 100644
index 0000000000..a40d9a5f5f
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/proto/nfs_prot.x
@@ -0,0 +1,1268 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)nfs_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static char rcsid[] = "$Id$";
+%#endif /* not lint */
+#endif
+
+const NFS_PORT = 2049;
+const NFS_MAXDATA = 8192;
+const NFS_MAXPATHLEN = 1024;
+const NFS_MAXNAMLEN = 255;
+const NFS_FHSIZE = 32;
+const NFS_COOKIESIZE = 4;
+const NFS_FIFO_DEV = -1; /* size kludge for named pipes */
+
+/*
+ * File types
+ */
+const NFSMODE_FMT = 0170000; /* type of file */
+const NFSMODE_DIR = 0040000; /* directory */
+const NFSMODE_CHR = 0020000; /* character special */
+const NFSMODE_BLK = 0060000; /* block special */
+const NFSMODE_REG = 0100000; /* regular */
+const NFSMODE_LNK = 0120000; /* symbolic link */
+const NFSMODE_SOCK = 0140000; /* socket */
+const NFSMODE_FIFO = 0010000; /* fifo */
+
+/*
+ * Error status
+ */
+enum nfsstat {
+ NFS_OK= 0, /* no error */
+ NFSERR_PERM=1, /* Not owner */
+ NFSERR_NOENT=2, /* No such file or directory */
+ NFSERR_IO=5, /* I/O error */
+ NFSERR_NXIO=6, /* No such device or address */
+ NFSERR_ACCES=13, /* Permission denied */
+ NFSERR_EXIST=17, /* File exists */
+ NFSERR_NODEV=19, /* No such device */
+ NFSERR_NOTDIR=20, /* Not a directory*/
+ NFSERR_ISDIR=21, /* Is a directory */
+ NFSERR_FBIG=27, /* File too large */
+ NFSERR_NOSPC=28, /* No space left on device */
+ NFSERR_ROFS=30, /* Read-only file system */
+ NFSERR_NAMETOOLONG=63, /* File name too long */
+ NFSERR_NOTEMPTY=66, /* Directory not empty */
+ NFSERR_DQUOT=69, /* Disc quota exceeded */
+ NFSERR_STALE=70, /* Stale NFS file handle */
+ NFSERR_WFLUSH=99 /* write cache flushed */
+};
+
+/*
+ * File types
+ */
+enum ftype {
+ NFNON = 0, /* non-file */
+ NFREG = 1, /* regular file */
+ NFDIR = 2, /* directory */
+ NFBLK = 3, /* block special */
+ NFCHR = 4, /* character special */
+ NFLNK = 5, /* symbolic link */
+ NFSOCK = 6, /* unix domain sockets */
+ NFBAD = 7, /* unused */
+ NFFIFO = 8 /* named pipe */
+};
+
+/*
+ * File access handle
+ */
+struct nfs_fh {
+ opaque data[NFS_FHSIZE];
+};
+
+/*
+ * Timeval
+ */
+struct nfstime {
+ unsigned seconds;
+ unsigned useconds;
+};
+
+
+/*
+ * File attributes
+ */
+struct fattr {
+ ftype type; /* file type */
+ unsigned mode; /* protection mode bits */
+ unsigned nlink; /* # hard links */
+ unsigned uid; /* owner user id */
+ unsigned gid; /* owner group id */
+ unsigned size; /* file size in bytes */
+ unsigned blocksize; /* prefered block size */
+ unsigned rdev; /* special device # */
+ unsigned blocks; /* Kb of disk used by file */
+ unsigned fsid; /* device # */
+ unsigned fileid; /* inode # */
+ nfstime atime; /* time of last access */
+ nfstime mtime; /* time of last modification */
+ nfstime ctime; /* time of last change */
+};
+
+/*
+ * File attributes which can be set
+ */
+struct sattr {
+ unsigned mode; /* protection mode bits */
+ unsigned uid; /* owner user id */
+ unsigned gid; /* owner group id */
+ unsigned size; /* file size in bytes */
+ nfstime atime; /* time of last access */
+ nfstime mtime; /* time of last modification */
+};
+
+
+typedef string filename<NFS_MAXNAMLEN>;
+typedef string nfspath<NFS_MAXPATHLEN>;
+
+/*
+ * Reply status with file attributes
+ */
+union attrstat switch (nfsstat status) {
+case NFS_OK:
+ fattr attributes;
+default:
+ void;
+};
+
+struct sattrargs {
+ nfs_fh file;
+ sattr attributes;
+};
+
+/*
+ * Arguments for directory operations
+ */
+struct diropargs {
+ nfs_fh dir; /* directory file handle */
+ filename name; /* name (up to NFS_MAXNAMLEN bytes) */
+};
+
+struct diropokres {
+ nfs_fh file;
+ fattr attributes;
+};
+
+/*
+ * Results from directory operation
+ */
+union diropres switch (nfsstat status) {
+case NFS_OK:
+ diropokres diropres;
+default:
+ void;
+};
+
+union readlinkres switch (nfsstat status) {
+case NFS_OK:
+ nfspath data;
+default:
+ void;
+};
+
+/*
+ * Arguments to remote read
+ */
+struct readargs {
+ nfs_fh file; /* handle for file */
+ unsigned offset; /* byte offset in file */
+ unsigned count; /* immediate read count */
+ unsigned totalcount; /* total read count (from this offset)*/
+};
+
+/*
+ * Status OK portion of remote read reply
+ */
+struct readokres {
+ fattr attributes; /* attributes, need for pagin*/
+ opaque data<NFS_MAXDATA>;
+};
+
+union readres switch (nfsstat status) {
+case NFS_OK:
+ readokres reply;
+default:
+ void;
+};
+
+/*
+ * Arguments to remote write
+ */
+struct writeargs {
+ nfs_fh file; /* handle for file */
+ unsigned beginoffset; /* beginning byte offset in file */
+ unsigned offset; /* current byte offset in file */
+ unsigned totalcount; /* total write count (to this offset)*/
+ opaque data<NFS_MAXDATA>;
+};
+
+struct createargs {
+ diropargs where;
+ sattr attributes;
+};
+
+struct renameargs {
+ diropargs from;
+ diropargs to;
+};
+
+struct linkargs {
+ nfs_fh from;
+ diropargs to;
+};
+
+struct symlinkargs {
+ diropargs from;
+ nfspath to;
+ sattr attributes;
+};
+
+
+/* TS, 10/21/2002; converted cookie to struct */
+struct nfscookie {
+ opaque data[NFS_COOKIESIZE];
+};
+
+/*
+ * Arguments to readdir
+ */
+struct readdirargs {
+ nfs_fh dir; /* directory handle */
+ nfscookie cookie;
+ unsigned count; /* number of directory bytes to read */
+};
+
+struct entry {
+ unsigned fileid;
+ filename name;
+ nfscookie cookie;
+ entry *nextentry;
+};
+
+struct dirlist {
+ entry *entries;
+ bool eof;
+};
+
+union readdirres switch (nfsstat status) {
+case NFS_OK:
+ dirlist reply;
+default:
+ void;
+};
+
+struct statfsokres {
+ unsigned tsize; /* preferred transfer size in bytes */
+ unsigned bsize; /* fundamental file system block size */
+ unsigned blocks; /* total blocks in file system */
+ unsigned bfree; /* free blocks in fs */
+ unsigned bavail; /* free blocks avail to non-superuser */
+};
+
+union statfsres switch (nfsstat status) {
+case NFS_OK:
+ statfsokres reply;
+default:
+ void;
+};
+
+#ifdef WANT_NFS3
+
+/*
+ * NFSv3 constants and types
+ */
+const NFS3_FHSIZE = 64; /* maximum size in bytes of a file handle */
+const NFS3_COOKIEVERFSIZE = 8; /* size of a cookie verifier for READDIR */
+const NFS3_CREATEVERFSIZE = 8; /* size of the verifier used for CREATE */
+const NFS3_WRITEVERFSIZE = 8; /* size of the verifier used for WRITE */
+
+typedef unsigned hyper uint64;
+typedef hyper int64;
+typedef unsigned long uint32;
+typedef long int32;
+typedef string filename3<>;
+typedef string nfspath3<>;
+typedef uint64 fileid3;
+typedef uint64 cookie3;
+typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
+typedef opaque createverf3[NFS3_CREATEVERFSIZE];
+typedef opaque writeverf3[NFS3_WRITEVERFSIZE];
+typedef uint32 uid3;
+typedef uint32 gid3;
+typedef uint64 size3;
+typedef uint64 offset3;
+typedef uint32 mode3;
+typedef uint32 count3;
+
+/*
+ * Error status (v3)
+ */
+enum nfsstat3 {
+ NFS3_OK = 0,
+ NFS3ERR_PERM = 1,
+ NFS3ERR_NOENT = 2,
+ NFS3ERR_IO = 5,
+ NFS3ERR_NXIO = 6,
+ NFS3ERR_ACCES = 13,
+ NFS3ERR_EXIST = 17,
+ NFS3ERR_XDEV = 18,
+ NFS3ERR_NODEV = 19,
+ NFS3ERR_NOTDIR = 20,
+ NFS3ERR_ISDIR = 21,
+ NFS3ERR_INVAL = 22,
+ NFS3ERR_FBIG = 27,
+ NFS3ERR_NOSPC = 28,
+ NFS3ERR_ROFS = 30,
+ NFS3ERR_MLINK = 31,
+ NFS3ERR_NAMETOOLONG = 63,
+ NFS3ERR_NOTEMPTY = 66,
+ NFS3ERR_DQUOT = 69,
+ NFS3ERR_STALE = 70,
+ NFS3ERR_REMOTE = 71,
+ NFS3ERR_BADHANDLE = 10001,
+ NFS3ERR_NOT_SYNC = 10002,
+ NFS3ERR_BAD_COOKIE = 10003,
+ NFS3ERR_NOTSUPP = 10004,
+ NFS3ERR_TOOSMALL = 10005,
+ NFS3ERR_SERVERFAULT = 10006,
+ NFS3ERR_BADTYPE = 10007,
+ NFS3ERR_JUKEBOX = 10008
+};
+
+/*
+ * File types (v3)
+ */
+enum ftype3 {
+ NF3REG = 1, /* regular file */
+ NF3DIR = 2, /* directory */
+ NF3BLK = 3, /* block special */
+ NF3CHR = 4, /* character special */
+ NF3LNK = 5, /* symbolic link */
+ NF3SOCK = 6, /* unix domain sockets */
+ NF3FIFO = 7 /* named pipe */
+};
+
+struct specdata3 {
+ uint32 specdata1;
+ uint32 specdata2;
+};
+
+/*
+ * File access handle (v3)
+ */
+struct nfs_fh3 {
+ opaque data<NFS3_FHSIZE>;
+};
+
+/*
+ * Timeval (v3)
+ */
+struct nfstime3 {
+ uint32 seconds;
+ uint32 nseconds;
+};
+
+
+/*
+ * File attributes (v3)
+ */
+struct fattr3 {
+ ftype3 type; /* file type */
+ mode3 mode; /* protection mode bits */
+ uint32 nlink; /* # hard links */
+ uid3 uid; /* owner user id */
+ gid3 gid; /* owner group id */
+ size3 size; /* file size in bytes */
+ size3 used; /* prefered block size */
+ specdata3 rdev; /* special device # */
+ uint64 fsid; /* device # */
+ fileid3 fileid; /* inode # */
+ nfstime3 atime; /* time of last access */
+ nfstime3 mtime; /* time of last modification */
+ nfstime3 ctime; /* time of last change */
+};
+
+union post_op_attr switch (bool attributes_follow) {
+case TRUE:
+ fattr3 attributes;
+case FALSE:
+ void;
+};
+
+struct wcc_attr {
+ size3 size;
+ nfstime3 mtime;
+ nfstime3 ctime;
+};
+
+union pre_op_attr switch (bool attributes_follow) {
+case TRUE:
+ wcc_attr attributes;
+case FALSE:
+ void;
+};
+
+struct wcc_data {
+ pre_op_attr before;
+ post_op_attr after;
+};
+
+union post_op_fh3 switch (bool handle_follows) {
+case TRUE:
+ nfs_fh3 handle;
+case FALSE:
+ void;
+};
+
+/*
+ * File attributes which can be set (v3)
+ */
+enum time_how {
+ DONT_CHANGE = 0,
+ SET_TO_SERVER_TIME = 1,
+ SET_TO_CLIENT_TIME = 2
+};
+
+union set_mode3 switch (bool set_it) {
+case TRUE:
+ mode3 mode;
+default:
+ void;
+};
+
+union set_uid3 switch (bool set_it) {
+case TRUE:
+ uid3 uid;
+default:
+ void;
+};
+
+union set_gid3 switch (bool set_it) {
+case TRUE:
+ gid3 gid;
+default:
+ void;
+};
+
+union set_size3 switch (bool set_it) {
+case TRUE:
+ size3 size;
+default:
+ void;
+};
+
+union set_atime switch (time_how set_it) {
+case SET_TO_CLIENT_TIME:
+ nfstime3 atime;
+default:
+ void;
+};
+
+union set_mtime switch (time_how set_it) {
+case SET_TO_CLIENT_TIME:
+ nfstime3 mtime;
+default:
+ void;
+};
+
+struct sattr3 {
+ set_mode3 mode;
+ set_uid3 uid;
+ set_gid3 gid;
+ set_size3 size;
+ set_atime atime;
+ set_mtime mtime;
+};
+
+/*
+ * Arguments for directory operations (v3)
+ */
+struct diropargs3 {
+ nfs_fh3 dir; /* directory file handle */
+ filename3 name; /* name (up to NFS_MAXNAMLEN bytes) */
+};
+
+/*
+ * Arguments to getattr (v3).
+ */
+struct GETATTR3args {
+ nfs_fh3 object;
+};
+
+struct GETATTR3resok {
+ fattr3 obj_attributes;
+};
+
+union GETATTR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ GETATTR3resok resok;
+default:
+ void;
+};
+
+/*
+ * Arguments to setattr (v3).
+ */
+union sattrguard3 switch (bool check) {
+case TRUE:
+ nfstime3 obj_ctime;
+case FALSE:
+ void;
+};
+
+struct SETATTR3args {
+ nfs_fh3 object;
+ sattr3 new_attributes;
+ sattrguard3 guard;
+};
+
+struct SETATTR3resok {
+ wcc_data obj_wcc;
+};
+
+struct SETATTR3resfail {
+ wcc_data obj_wcc;
+};
+
+union SETATTR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ SETATTR3resok resok;
+default:
+ SETATTR3resfail resfail;
+};
+
+/*
+ * Arguments to lookup (v3).
+ */
+struct LOOKUP3args {
+ diropargs3 what;
+};
+
+struct LOOKUP3resok {
+ nfs_fh3 object;
+ post_op_attr obj_attributes;
+ post_op_attr dir_attributes;
+};
+
+struct LOOKUP3resfail {
+ post_op_attr dir_attributes;
+};
+
+union LOOKUP3res switch (nfsstat3 status) {
+case NFS3_OK:
+ LOOKUP3resok resok;
+default:
+ LOOKUP3resfail resfail;
+};
+
+/*
+ * Arguments to access (v3).
+ */
+const ACCESS3_READ = 0x0001;
+const ACCESS3_LOOKUP = 0x0002;
+const ACCESS3_MODIFY = 0x0004;
+const ACCESS3_EXTEND = 0x0008;
+const ACCESS3_DELETE = 0x0010;
+const ACCESS3_EXECUTE = 0x0020;
+
+struct ACCESS3args {
+ nfs_fh3 object;
+ uint32 access;
+};
+
+struct ACCESS3resok {
+ post_op_attr obj_attributes;
+ uint32 access;
+};
+
+struct ACCESS3resfail {
+ post_op_attr obj_attributes;
+};
+
+union ACCESS3res switch (nfsstat3 status) {
+case NFS3_OK:
+ ACCESS3resok resok;
+default:
+ ACCESS3resfail resfail;
+};
+
+/*
+ * Arguments to readlink (v3).
+ */
+struct READLINK3args {
+ nfs_fh3 symlink;
+};
+
+struct READLINK3resok {
+ post_op_attr symlink_attributes;
+ nfspath3 data;
+};
+
+struct READLINK3resfail {
+ post_op_attr symlink_attributes;
+};
+
+union READLINK3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READLINK3resok resok;
+default:
+ READLINK3resfail resfail;
+};
+
+/*
+ * Arguments to read (v3).
+ */
+struct READ3args {
+ nfs_fh3 file;
+ offset3 offset;
+ count3 count;
+};
+
+struct READ3resok {
+ post_op_attr file_attributes;
+ count3 count;
+ bool eof;
+ opaque data<>;
+};
+
+struct READ3resfail {
+ post_op_attr file_attributes;
+};
+
+/* XXX: solaris 2.6 uses ``nfsstat'' here */
+union READ3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READ3resok resok;
+default:
+ READ3resfail resfail;
+};
+
+/*
+ * Arguments to write (v3).
+ */
+enum stable_how {
+ UNSTABLE = 0,
+ DATA_SYNC = 1,
+ FILE_SYNC = 2
+};
+
+struct WRITE3args {
+ nfs_fh3 file;
+ offset3 offset;
+ count3 count;
+ stable_how stable;
+ opaque data<>;
+};
+
+struct WRITE3resok {
+ wcc_data file_wcc;
+ count3 count;
+ stable_how committed;
+ writeverf3 verf;
+};
+
+struct WRITE3resfail {
+ wcc_data file_wcc;
+};
+
+union WRITE3res switch (nfsstat3 status) {
+case NFS3_OK:
+ WRITE3resok resok;
+default:
+ WRITE3resfail resfail;
+};
+
+/*
+ * Arguments to create (v3).
+ */
+enum createmode3 {
+ UNCHECKED = 0,
+ GUARDED = 1,
+ EXCLUSIVE = 2
+};
+
+union createhow3 switch (createmode3 mode) {
+case UNCHECKED:
+case GUARDED:
+ sattr3 obj_attributes;
+case EXCLUSIVE:
+ createverf3 verf;
+};
+
+struct CREATE3args {
+ diropargs3 where;
+ createhow3 how;
+};
+
+struct CREATE3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct CREATE3resfail {
+ wcc_data dir_wcc;
+};
+
+union CREATE3res switch (nfsstat3 status) {
+case NFS3_OK:
+ CREATE3resok resok;
+default:
+ CREATE3resfail resfail;
+};
+
+/*
+ * Arguments to mkdir (v3).
+ */
+struct MKDIR3args {
+ diropargs3 where;
+ sattr3 attributes;
+};
+
+struct MKDIR3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct MKDIR3resfail {
+ wcc_data dir_wcc;
+};
+
+union MKDIR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ MKDIR3resok resok;
+default:
+ MKDIR3resfail resfail;
+};
+
+/*
+ * Arguments to symlink (v3).
+ */
+struct symlinkdata3 {
+ sattr3 symlink_attributes;
+ nfspath3 symlink_data;
+};
+
+struct SYMLINK3args {
+ diropargs3 where;
+ symlinkdata3 symlink;
+};
+
+struct SYMLINK3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct SYMLINK3resfail {
+ wcc_data dir_wcc;
+};
+
+union SYMLINK3res switch (nfsstat3 status) {
+case NFS3_OK:
+ SYMLINK3resok resok;
+default:
+ SYMLINK3resfail resfail;
+};
+
+/*
+ * Arguments to mknod (v3).
+ */
+struct devicedata3 {
+ sattr3 dev_attributes;
+ specdata3 spec;
+};
+
+union mknoddata3 switch (ftype3 type) {
+case NF3CHR:
+case NF3BLK:
+ devicedata3 device;
+case NF3SOCK:
+case NF3FIFO:
+ sattr3 pipe_attributes;
+default:
+ void;
+};
+
+struct MKNOD3args {
+ diropargs3 where;
+ mknoddata3 what;
+};
+
+struct MKNOD3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct MKNOD3resfail {
+ wcc_data dir_wcc;
+};
+
+union MKNOD3res switch (nfsstat3 status) {
+case NFS3_OK:
+ MKNOD3resok resok;
+default:
+ MKNOD3resfail resfail;
+};
+
+/*
+ * Arguments to remove (v3).
+ */
+struct REMOVE3args {
+ diropargs3 object;
+};
+
+struct REMOVE3resok {
+ wcc_data dir_wcc;
+};
+
+struct REMOVE3resfail {
+ wcc_data dir_wcc;
+};
+
+union REMOVE3res switch (nfsstat3 status) {
+case NFS3_OK:
+ REMOVE3resok resok;
+default:
+ REMOVE3resfail resfail;
+};
+
+/*
+ * Arguments to rmdir (v3).
+ */
+struct RMDIR3args {
+ diropargs3 object;
+};
+
+struct RMDIR3resok {
+ wcc_data dir_wcc;
+};
+
+struct RMDIR3resfail {
+ wcc_data dir_wcc;
+};
+
+union RMDIR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ RMDIR3resok resok;
+default:
+ RMDIR3resfail resfail;
+};
+
+/*
+ * Arguments to rename (v3).
+ */
+struct RENAME3args {
+ diropargs3 from;
+ diropargs3 to;
+};
+
+struct RENAME3resok {
+ wcc_data fromdir_wcc;
+ wcc_data todir_wcc;
+};
+
+struct RENAME3resfail {
+ wcc_data fromdir_wcc;
+ wcc_data todir_wcc;
+};
+
+union RENAME3res switch (nfsstat3 status) {
+case NFS3_OK:
+ RENAME3resok resok;
+default:
+ RENAME3resfail resfail;
+};
+
+/*
+ * Arguments to link (v3).
+ */
+struct LINK3args {
+ nfs_fh3 file;
+ diropargs3 link;
+};
+
+struct LINK3resok {
+ post_op_attr file_attributes;
+ wcc_data linkdir_wcc;
+};
+
+struct LINK3resfail {
+ post_op_attr file_attributes;
+ wcc_data linkdir_wcc;
+};
+
+union LINK3res switch (nfsstat3 status) {
+case NFS3_OK:
+ LINK3resok resok;
+default:
+ LINK3resfail resfail;
+};
+
+/*
+ * Arguments to readdir (v3).
+ */
+struct READDIR3args {
+ nfs_fh3 dir;
+ cookie3 cookie;
+ cookieverf3 cookieverf;
+ count3 count;
+};
+
+struct entry3 {
+ fileid3 fileid;
+ filename3 name;
+ cookie3 cookie;
+ entry3 *nextentry;
+};
+
+struct dirlist3 {
+ entry3 *entries;
+ bool eof;
+};
+
+struct READDIR3resok {
+ post_op_attr dir_attributes;
+ cookieverf3 cookieverf;
+ dirlist3 reply;
+};
+
+struct READDIR3resfail {
+ post_op_attr dir_attributes;
+};
+
+union READDIR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READDIR3resok resok;
+default:
+ READDIR3resfail resfail;
+};
+
+/*
+ * Arguments to readdirplus (v3).
+ */
+struct READDIRPLUS3args {
+ nfs_fh3 dir;
+ cookie3 cookie;
+ cookieverf3 cookieverf;
+ count3 dircount;
+ count3 maxcount;
+};
+
+struct entryplus3 {
+ fileid3 fileid;
+ filename3 name;
+ cookie3 cookie;
+ post_op_attr name_attributes;
+ post_op_fh3 name_handle;
+ entryplus3 *nextentry;
+};
+
+struct dirlistplus3 {
+ entryplus3 *entries;
+ bool eof;
+};
+
+struct READDIRPLUS3resok {
+ post_op_attr dir_attributes;
+ cookieverf3 cookieverf;
+ dirlistplus3 reply;
+};
+
+struct READDIRPLUS3resfail {
+ post_op_attr dir_attributes;
+};
+
+union READDIRPLUS3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READDIRPLUS3resok resok;
+default:
+ READDIRPLUS3resfail resfail;
+};
+
+/*
+ * Arguments to fsstat (v3).
+ */
+struct FSSTAT3args {
+ nfs_fh3 fsroot;
+};
+
+struct FSSTAT3resok {
+ post_op_attr obj_attributes;
+ size3 tbytes;
+ size3 fbytes;
+ size3 abytes;
+ size3 tfiles;
+ size3 ffiles;
+ size3 afiles;
+ uint32 invarsec;
+};
+
+struct FSSTAT3resfail {
+ post_op_attr obj_attributes;
+};
+
+union FSSTAT3res switch (nfsstat3 status) {
+case NFS3_OK:
+ FSSTAT3resok resok;
+default:
+ FSSTAT3resfail resfail;
+};
+
+/*
+ * Arguments to fsinfo (v3).
+ */
+const FSF3_LINK = 0x0001;
+const FSF3_SYMLINK = 0x0002;
+const FSF3_HOMOGENEOUS = 0x0008;
+const FSF3_CANSETTIME = 0x0010;
+
+struct FSINFO3args {
+ nfs_fh3 fsroot;
+};
+
+struct FSINFO3resok {
+ post_op_attr obj_attributes;
+ uint32 rtmax;
+ uint32 rtpref;
+ uint32 rtmult;
+ uint32 wtmax;
+ uint32 wtpref;
+ uint32 wtmult;
+ uint32 dtpref;
+ size3 maxfilesize;
+ nfstime3 time_delta;
+ uint32 properties;
+};
+
+struct FSINFO3resfail {
+ post_op_attr obj_attributes;
+};
+
+union FSINFO3res switch (nfsstat3 status) {
+case NFS3_OK:
+ FSINFO3resok resok;
+default:
+ FSINFO3resfail resfail;
+};
+
+/*
+ * Arguments to pathconf (v3).
+ */
+struct PATHCONF3args {
+ nfs_fh3 object;
+};
+
+struct PATHCONF3resok {
+ post_op_attr obj_attributes;
+ uint32 linkmax;
+ uint32 name_max;
+ bool no_trunc;
+ bool chown_restricted;
+ bool case_insensitive;
+ bool case_preserving;
+};
+
+struct PATHCONF3resfail {
+ post_op_attr obj_attributes;
+};
+
+union PATHCONF3res switch (nfsstat3 status) {
+case NFS3_OK:
+ PATHCONF3resok resok;
+default:
+ PATHCONF3resfail resfail;
+};
+
+/*
+ * Arguments to commit (v3).
+ */
+struct COMMIT3args {
+ nfs_fh3 file;
+ offset3 offset;
+ count3 count;
+};
+
+struct COMMIT3resok {
+ wcc_data file_wcc;
+ writeverf3 verf;
+};
+
+struct COMMIT3resfail {
+ wcc_data file_wcc;
+};
+
+union COMMIT3res switch (nfsstat3 status) {
+case NFS3_OK:
+ COMMIT3resok resok;
+default:
+ COMMIT3resfail resfail;
+};
+
+#endif /* WANT_NFS3 */
+
+/*
+ * Remote file service routines
+ */
+program NFS_PROGRAM {
+ version NFS_VERSION {
+ void
+ NFSPROC_NULL(void) = 0;
+
+ attrstat
+ NFSPROC_GETATTR(nfs_fh) = 1;
+
+ attrstat
+ NFSPROC_SETATTR(sattrargs) = 2;
+
+ void
+ NFSPROC_ROOT(void) = 3;
+
+ diropres
+ NFSPROC_LOOKUP(diropargs) = 4;
+
+ readlinkres
+ NFSPROC_READLINK(nfs_fh) = 5;
+
+ readres
+ NFSPROC_READ(readargs) = 6;
+
+ void
+ NFSPROC_WRITECACHE(void) = 7;
+
+ attrstat
+ NFSPROC_WRITE(writeargs) = 8;
+
+ diropres
+ NFSPROC_CREATE(createargs) = 9;
+
+ nfsstat
+ NFSPROC_REMOVE(diropargs) = 10;
+
+ nfsstat
+ NFSPROC_RENAME(renameargs) = 11;
+
+ nfsstat
+ NFSPROC_LINK(linkargs) = 12;
+
+ nfsstat
+ NFSPROC_SYMLINK(symlinkargs) = 13;
+
+ diropres
+ NFSPROC_MKDIR(createargs) = 14;
+
+ nfsstat
+ NFSPROC_RMDIR(diropargs) = 15;
+
+ readdirres
+ NFSPROC_READDIR(readdirargs) = 16;
+
+ statfsres
+ NFSPROC_STATFS(nfs_fh) = 17;
+ } = 2;
+} = 100003;
+#ifdef WANT_NFS3
+program NFS3_PROGRAM {
+ version NFS_V3 {
+ void
+ NFSPROC3_NULL(void) = 0;
+
+ GETATTR3res
+ NFSPROC3_GETATTR(GETATTR3args) = 1;
+
+ SETATTR3res
+ NFSPROC3_SETATTR(SETATTR3args) = 2;
+
+ LOOKUP3res
+ NFSPROC3_LOOKUP(LOOKUP3args) = 3;
+
+ ACCESS3res
+ NFSPROC3_ACCESS(ACCESS3args) = 4;
+
+ READLINK3res
+ NFSPROC3_READLINK(READLINK3args) = 5;
+
+ READ3res
+ NFSPROC3_READ(READ3args) = 6;
+
+ WRITE3res
+ NFSPROC3_WRITE(WRITE3args) = 7;
+
+ CREATE3res
+ NFSPROC3_CREATE(CREATE3args) = 8;
+
+ MKDIR3res
+ NFSPROC3_MKDIR(MKDIR3args) = 9;
+
+ SYMLINK3res
+ NFSPROC3_SYMLINK(SYMLINK3args) = 10;
+
+ MKNOD3res
+ NFSPROC3_MKNOD(MKNOD3args) = 11;
+
+ REMOVE3res
+ NFSPROC3_REMOVE(REMOVE3args) = 12;
+
+ RMDIR3res
+ NFSPROC3_RMDIR(RMDIR3args) = 13;
+
+ RENAME3res
+ NFSPROC3_RENAME(RENAME3args) = 14;
+
+ LINK3res
+ NFSPROC3_LINK(LINK3args) = 15;
+
+ READDIR3res
+ NFSPROC3_READDIR(READDIR3args) = 16;
+
+ READDIRPLUS3res
+ NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17;
+
+ FSSTAT3res
+ NFSPROC3_FSSTAT(FSSTAT3args) = 18;
+
+ FSINFO3res
+ NFSPROC3_FSINFO(FSINFO3args) = 19;
+
+ PATHCONF3res
+ NFSPROC3_PATHCONF(PATHCONF3args) = 20;
+
+ COMMIT3res
+ NFSPROC3_COMMIT(COMMIT3args) = 21;
+ } = 3;
+} = 100003;
+#endif
+
diff --git a/cpukit/libfs/src/nfsclient/proto/nfs_prot_xdr.c b/cpukit/libfs/src/nfsclient/proto/nfs_prot_xdr.c
new file mode 100644
index 0000000000..cde005e2b4
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/proto/nfs_prot_xdr.c
@@ -0,0 +1,621 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#include "nfs_prot.h"
+#ifndef lint
+/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/
+/*static char sccsid[] = "from: @(#)nfs_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
+ #if !defined(__rtems__)
+ static char rcsid[] = "$Id$";
+ #endif
+#endif /* not lint */
+
+bool_t
+xdr_nfsstat (XDR *xdrs, nfsstat *objp)
+{
+ if (!xdr_enum (xdrs, (enum_t *) objp))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_ftype (XDR *xdrs, ftype *objp)
+{
+ if (!xdr_enum (xdrs, (enum_t *) objp))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_nfs_fh (XDR *xdrs, nfs_fh *objp)
+{
+ if (!xdr_opaque (xdrs, objp->data, NFS_FHSIZE))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_nfstime (XDR *xdrs, nfstime *objp)
+{
+ if (!xdr_u_int (xdrs, &objp->seconds))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->useconds))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_fattr (XDR *xdrs, fattr *objp)
+{
+ register int32_t *buf;
+
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!xdr_ftype (xdrs, &objp->type))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 10 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->nlink))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocksize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->rdev))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->fsid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->fileid))
+ return FALSE;
+
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->mode);
+ IXDR_PUT_U_LONG(buf, objp->nlink);
+ IXDR_PUT_U_LONG(buf, objp->uid);
+ IXDR_PUT_U_LONG(buf, objp->gid);
+ IXDR_PUT_U_LONG(buf, objp->size);
+ IXDR_PUT_U_LONG(buf, objp->blocksize);
+ IXDR_PUT_U_LONG(buf, objp->rdev);
+ IXDR_PUT_U_LONG(buf, objp->blocks);
+ IXDR_PUT_U_LONG(buf, objp->fsid);
+ IXDR_PUT_U_LONG(buf, objp->fileid);
+ }
+ if (!xdr_nfstime (xdrs, &objp->atime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->mtime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->ctime))
+ return FALSE;
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ if (!xdr_ftype (xdrs, &objp->type))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 10 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->nlink))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocksize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->rdev))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->fsid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->fileid))
+ return FALSE;
+
+ } else {
+ objp->mode = IXDR_GET_U_LONG(buf);
+ objp->nlink = IXDR_GET_U_LONG(buf);
+ objp->uid = IXDR_GET_U_LONG(buf);
+ objp->gid = IXDR_GET_U_LONG(buf);
+ objp->size = IXDR_GET_U_LONG(buf);
+ objp->blocksize = IXDR_GET_U_LONG(buf);
+ objp->rdev = IXDR_GET_U_LONG(buf);
+ objp->blocks = IXDR_GET_U_LONG(buf);
+ objp->fsid = IXDR_GET_U_LONG(buf);
+ objp->fileid = IXDR_GET_U_LONG(buf);
+ }
+ if (!xdr_nfstime (xdrs, &objp->atime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->mtime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->ctime))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!xdr_ftype (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->nlink))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocksize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->rdev))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->fsid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->fileid))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->atime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->mtime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->ctime))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_sattr (XDR *xdrs, sattr *objp)
+{
+ register int32_t *buf;
+
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->mode);
+ IXDR_PUT_U_LONG(buf, objp->uid);
+ IXDR_PUT_U_LONG(buf, objp->gid);
+ IXDR_PUT_U_LONG(buf, objp->size);
+ }
+ if (!xdr_nfstime (xdrs, &objp->atime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->mtime))
+ return FALSE;
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+
+ } else {
+ objp->mode = IXDR_GET_U_LONG(buf);
+ objp->uid = IXDR_GET_U_LONG(buf);
+ objp->gid = IXDR_GET_U_LONG(buf);
+ objp->size = IXDR_GET_U_LONG(buf);
+ }
+ if (!xdr_nfstime (xdrs, &objp->atime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->mtime))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->atime))
+ return FALSE;
+ if (!xdr_nfstime (xdrs, &objp->mtime))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_filename (XDR *xdrs, filename *objp)
+{
+ if (!xdr_string (xdrs, objp, NFS_MAXNAMLEN))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_nfspath (XDR *xdrs, nfspath *objp)
+{
+ if (!xdr_string (xdrs, objp, NFS_MAXPATHLEN))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_attrstat (XDR *xdrs, attrstat *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_fattr (xdrs, &objp->attrstat_u.attributes))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool_t
+xdr_sattrargs (XDR *xdrs, sattrargs *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ if (!xdr_sattr (xdrs, &objp->attributes))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_diropargs (XDR *xdrs, diropargs *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->dir))
+ return FALSE;
+ if (!xdr_filename (xdrs, &objp->name))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_diropokres (XDR *xdrs, diropokres *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ if (!xdr_fattr (xdrs, &objp->attributes))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_diropres (XDR *xdrs, diropres *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_diropokres (xdrs, &objp->diropres_u.diropres))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool_t
+xdr_readlinkres (XDR *xdrs, readlinkres *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_nfspath (xdrs, &objp->readlinkres_u.data))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool_t
+xdr_readargs (XDR *xdrs, readargs *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->count))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->totalcount))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_readokres (XDR *xdrs, readokres *objp)
+{
+ if (!xdr_fattr (xdrs, &objp->attributes))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, NFS_MAXDATA))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_readres (XDR *xdrs, readres *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_readokres (xdrs, &objp->readres_u.reply))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool_t
+xdr_writeargs (XDR *xdrs, writeargs *objp)
+{
+ register int32_t *buf;
+
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->beginoffset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->totalcount))
+ return FALSE;
+
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->beginoffset);
+ IXDR_PUT_U_LONG(buf, objp->offset);
+ IXDR_PUT_U_LONG(buf, objp->totalcount);
+ }
+ if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, NFS_MAXDATA))
+ return FALSE;
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->beginoffset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->totalcount))
+ return FALSE;
+
+ } else {
+ objp->beginoffset = IXDR_GET_U_LONG(buf);
+ objp->offset = IXDR_GET_U_LONG(buf);
+ objp->totalcount = IXDR_GET_U_LONG(buf);
+ }
+ if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, NFS_MAXDATA))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->beginoffset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->totalcount))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->data.data_val, (u_int *) &objp->data.data_len, NFS_MAXDATA))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_createargs (XDR *xdrs, createargs *objp)
+{
+ if (!xdr_diropargs (xdrs, &objp->where))
+ return FALSE;
+ if (!xdr_sattr (xdrs, &objp->attributes))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_renameargs (XDR *xdrs, renameargs *objp)
+{
+ if (!xdr_diropargs (xdrs, &objp->from))
+ return FALSE;
+ if (!xdr_diropargs (xdrs, &objp->to))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_linkargs (XDR *xdrs, linkargs *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->from))
+ return FALSE;
+ if (!xdr_diropargs (xdrs, &objp->to))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_symlinkargs (XDR *xdrs, symlinkargs *objp)
+{
+ if (!xdr_diropargs (xdrs, &objp->from))
+ return FALSE;
+ if (!xdr_nfspath (xdrs, &objp->to))
+ return FALSE;
+ if (!xdr_sattr (xdrs, &objp->attributes))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_nfscookie (XDR *xdrs, nfscookie *objp)
+{
+ if (!xdr_opaque (xdrs, objp->data, NFS_COOKIESIZE))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_readdirargs (XDR *xdrs, readdirargs *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->dir))
+ return FALSE;
+ if (!xdr_nfscookie (xdrs, &objp->cookie))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->count))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_entry (XDR *xdrs, entry *objp)
+{
+ if (!xdr_u_int (xdrs, &objp->fileid))
+ return FALSE;
+ if (!xdr_filename (xdrs, &objp->name))
+ return FALSE;
+ if (!xdr_nfscookie (xdrs, &objp->cookie))
+ return FALSE;
+ if (!xdr_pointer (xdrs, (char **)&objp->nextentry, sizeof (entry), (xdrproc_t) xdr_entry))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_dirlist (XDR *xdrs, dirlist *objp)
+{
+ if (!xdr_pointer (xdrs, (char **)&objp->entries, sizeof (entry), (xdrproc_t) xdr_entry))
+ return FALSE;
+ if (!xdr_bool (xdrs, &objp->eof))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_readdirres (XDR *xdrs, readdirres *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_dirlist (xdrs, &objp->readdirres_u.reply))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool_t
+xdr_statfsokres (XDR *xdrs, statfsokres *objp)
+{
+ register int32_t *buf;
+
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ buf = XDR_INLINE (xdrs, 5 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->tsize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bsize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bfree))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bavail))
+ return FALSE;
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->tsize);
+ IXDR_PUT_U_LONG(buf, objp->bsize);
+ IXDR_PUT_U_LONG(buf, objp->blocks);
+ IXDR_PUT_U_LONG(buf, objp->bfree);
+ IXDR_PUT_U_LONG(buf, objp->bavail);
+ }
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ buf = XDR_INLINE (xdrs, 5 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->tsize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bsize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bfree))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bavail))
+ return FALSE;
+ } else {
+ objp->tsize = IXDR_GET_U_LONG(buf);
+ objp->bsize = IXDR_GET_U_LONG(buf);
+ objp->blocks = IXDR_GET_U_LONG(buf);
+ objp->bfree = IXDR_GET_U_LONG(buf);
+ objp->bavail = IXDR_GET_U_LONG(buf);
+ }
+ return TRUE;
+ }
+
+ if (!xdr_u_int (xdrs, &objp->tsize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bsize))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bfree))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->bavail))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_statfsres (XDR *xdrs, statfsres *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_statfsokres (xdrs, &objp->statfsres_u.reply))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
diff --git a/cpukit/libfs/src/nfsclient/rfc1094.txt b/cpukit/libfs/src/nfsclient/rfc1094.txt
new file mode 100644
index 0000000000..7ad0f737ef
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/rfc1094.txt
@@ -0,0 +1,1258 @@
+
+ RFC 1094 (RFC1094)
+
+Internet RFC/STD/FYI/BCP Archives
+
+
+ RFC 1094 - NFS: Network File System Protocol specification
+
+------------------------------------------------------------------------
+
+
+Network Working Group Sun Microsystems, Inc.
+Request for Comments: 1094 March 1989
+
+ NFS: Network File System Protocol Specification
+
+STATUS OF THIS MEMO
+
+ This RFC describes a protocol that Sun Microsystems, Inc., and others
+ are using. A new version of the protocol is under development, but
+ others may benefit from the descriptions of the current protocol, and
+ discussion of some of the design issues. Distribution of this memo
+ is unlimited.
+
+1. INTRODUCTION
+
+ The Sun Network Filesystem (NFS) protocol provides transparent remote
+ access to shared files across networks. The NFS protocol is designed
+ to be portable across different machines, operating systems, network
+ architectures, and transport protocols. This portability is achieved
+ through the use of Remote Procedure Call (RPC) primitives built on
+ top of an eXternal Data Representation (XDR). Implementations
+ already exist for a variety of machines, from personal computers to
+ supercomputers.
+
+ The supporting mount protocol allows the server to hand out remote
+ access privileges to a restricted set of clients. It performs the
+ operating system-specific functions that allow, for example, to
+ attach remote directory trees to some local file system.
+
+1.1. Remote Procedure Call
+
+ Sun's Remote Procedure Call specification provides a procedure-
+ oriented interface to remote services. Each server supplies a
+ "program" that is a set of procedures. NFS is one such program. The
+ combination of host address, program number, and procedure number
+ specifies one remote procedure. A goal of NFS was to not require any
+ specific level of reliability from its lower levels, so it could
+ potentially be used on many underlying transport protocols, or even
+ another remote procedure call implementation. For ease of
+ discussion, the rest of this document will assume NFS is implemented
+ on top of Sun RPC, described in RFC 1057 </rfcs/rfc1057.html>, "RPC: Remote Procedure
+ Call Protocol Specification".
+
+1.2. External Data Representation
+
+ The eXternal Data Representation (XDR) standard provides a common way
+ of representing a set of data types over a network. The NFS Protocol
+
+ Specification is written using the RPC data description language.
+ For more information, see RFC 1014 </rfcs/rfc1014.html>, "XDR: External Data
+ Representation Standard". Although automated RPC/XDR compilers exist
+ to generate server and client "stubs", NFS does not require their
+ use. Any software that provides equivalent functionality can be
+ used, and if the encoding is exactly the same it can interoperate
+ with other implementations of NFS.
+
+1.3. Stateless Servers
+
+ The NFS protocol was intended to be as stateless as possible. That
+ is, a server should not need to maintain any protocol state
+ information about any of its clients in order to function correctly.
+ Stateless servers have a distinct advantage over stateful servers in
+ the event of a failure. With stateless servers, a client need only
+ retry a request until the server responds; it does not even need to
+ know that the server has crashed, or the network temporarily went
+ down. The client of a stateful server, on the other hand, needs to
+ either detect a server failure and rebuild the server's state when it
+ comes back up, or cause client operations to fail.
+
+ This may not sound like an important issue, but it affects the
+ protocol in some unexpected ways. We feel that it may be worth a bit
+ of extra complexity in the protocol to be able to write very simple
+ servers that do not require fancy crash recovery. Note that even if
+ a so-called "reliable" transport protocol such as TCP is used, the
+ client must still be able to handle interruptions of service by re-
+ opening connections when they time out. Thus, a stateless protocol
+ may actually simplify the implementation.
+
+ On the other hand, NFS deals with objects such as files and
+ directories that inherently have state -- what good would a file be
+ if it did not keep its contents intact? The goal was to not
+ introduce any extra state in the protocol itself. Inherently
+ stateful operations such as file or record locking, and remote
+ execution, were implemented as separate services, not described in
+ this document.
+
+ The basic way to simplify recovery was to make operations as
+ "idempotent" as possible (so that they can potentially be repeated).
+ Some operations in this version of the protocol did not attain this
+ goal; luckily most of the operations (such as Read and Write) are
+ idempotent. Also, most server failures occur between operations, not
+ between the receipt of an operation and the response. Finally,
+ although actual server failures may be rare, in complex networks,
+ failures of any network, router, or bridge may be indistinguishable
+ from a server failure.
+
+2. NFS PROTOCOL DEFINITION
+
+ Servers change over time, and so can the protocol that they use. RPC
+ provides a version number with each RPC request. This RFC describes
+ version two of the NFS protocol. Even in the second version, there
+ are a few obsolete procedures and parameters, which will be removed
+ in later versions. An RFC for version three of the NFS protocol is
+ currently under preparation.
+
+2.1. File System Model
+
+ NFS assumes a file system that is hierarchical, with directories as
+ all but the bottom level of files. Each entry in a directory (file,
+ directory, device, etc.) has a string name. Different operating
+ systems may have restrictions on the depth of the tree or the names
+ used, as well as using different syntax to represent the "pathname",
+ which is the concatenation of all the "components" (directory and
+ file names) in the name. A "file system" is a tree on a single
+ server (usually a single disk or physical partition) with a specified
+ "root". Some operating systems provide a "mount" operation to make
+ all file systems appear as a single tree, while others maintain a
+ "forest" of file systems. Files are unstructured streams of
+ uninterpreted bytes. Version 3 of NFS uses slightly more general
+ file system model.
+
+ NFS looks up one component of a pathname at a time. It may not be
+ obvious why it does not just take the whole pathname, traipse down
+ the directories, and return a file handle when it is done. There are
+ several good reasons not to do this. First, pathnames need
+ separators between the directory components, and different operating
+ systems use different separators. We could define a Network Standard
+ Pathname Representation, but then every pathname would have to be
+ parsed and converted at each end. Other issues are discussed in
+ section 3, NFS Implementation Issues.
+
+ Although files and directories are similar objects in many ways,
+ different procedures are used to read directories and files. This
+ provides a network standard format for representing directories. The
+ same argument as above could have been used to justify a procedure
+ that returns only one directory entry per call. The problem is
+ efficiency. Directories can contain many entries, and a remote call
+ to return each would be just too slow.
+
+2.2. Server Procedures
+
+ The protocol definition is given as a set of procedures with
+ arguments and results defined using the RPC language (XDR language
+ extended with program, version, and procedure declarations). A brief
+
+ description of the function of each procedure should provide enough
+ information to allow implementation. Section 2.3 describes the basic
+ data types in more detail.
+
+ All of the procedures in the NFS protocol are assumed to be
+ synchronous. When a procedure returns to the client, the client can
+ assume that the operation has completed and any data associated with
+ the request is now on stable storage. For example, a client WRITE
+ request may cause the server to update data blocks, filesystem
+ information blocks (such as indirect blocks), and file attribute
+ information (size and modify times). When the WRITE returns to the
+ client, it can assume that the write is safe, even in case of a
+ server crash, and it can discard the data written. This is a very
+ important part of the statelessness of the server. If the server
+ waited to flush data from remote requests, the client would have to
+ save those requests so that it could resend them in case of a server
+ crash.
+
+ /*
+ * Remote file service routines
+ */
+ program NFS_PROGRAM {
+ version NFS_VERSION {
+ void
+ NFSPROC_NULL(void) = 0;
+
+ attrstat
+ NFSPROC_GETATTR(fhandle) = 1;
+
+ attrstat
+ NFSPROC_SETATTR(sattrargs) = 2;
+
+ void
+ NFSPROC_ROOT(void) = 3;
+
+ diropres
+ NFSPROC_LOOKUP(diropargs) = 4;
+
+ readlinkres
+ NFSPROC_READLINK(fhandle) = 5;
+
+ readres
+ NFSPROC_READ(readargs) = 6;
+
+ void
+ NFSPROC_WRITECACHE(void) = 7;
+
+ attrstat
+ NFSPROC_WRITE(writeargs) = 8;
+
+ diropres
+ NFSPROC_CREATE(createargs) = 9;
+
+ stat
+ NFSPROC_REMOVE(diropargs) = 10;
+
+ stat
+ NFSPROC_RENAME(renameargs) = 11;
+
+ stat
+ NFSPROC_LINK(linkargs) = 12;
+
+ stat
+ NFSPROC_SYMLINK(symlinkargs) = 13;
+
+ diropres
+ NFSPROC_MKDIR(createargs) = 14;
+
+ stat
+ NFSPROC_RMDIR(diropargs) = 15;
+
+ readdirres
+ NFSPROC_READDIR(readdirargs) = 16;
+
+ statfsres
+ NFSPROC_STATFS(fhandle) = 17;
+ } = 2;
+ } = 100003;
+
+2.2.1. Do Nothing
+
+ void
+ NFSPROC_NULL(void) = 0;
+
+ This procedure does no work. It is made available in all RPC
+ services to allow server response testing and timing.
+
+2.2.2. Get File Attributes
+
+ attrstat
+ NFSPROC_GETATTR (fhandle) = 1;
+
+ If the reply status is NFS_OK, then the reply attributes contains the
+ attributes for the file given by the input fhandle.
+
+2.2.3. Set File Attributes
+
+ struct sattrargs {
+ fhandle file;
+ sattr attributes;
+ };
+
+ attrstat
+ NFSPROC_SETATTR (sattrargs) = 2;
+
+ The "attributes" argument contains fields which are either -1 or are
+ the new value for the attributes of "file". If the reply status is
+ NFS_OK, then the reply attributes have the attributes of the file
+ after the "SETATTR" operation has completed.
+
+ Notes: The use of -1 to indicate an unused field in "attributes" is
+ changed in the next version of the protocol.
+
+2.2.4. Get Filesystem Root
+
+ void
+ NFSPROC_ROOT(void) = 3;
+
+ Obsolete. This procedure is no longer used because finding the root
+ file handle of a filesystem requires moving pathnames between client
+ and server. To do this right, we would have to define a network
+ standard representation of pathnames. Instead, the function of
+ looking up the root file handle is done by the MNTPROC_MNT procedure.
+ (See Appendix A, "Mount Protocol Definition", for details).
+
+2.2.5. Look Up File Name
+
+ diropres
+ NFSPROC_LOOKUP(diropargs) = 4;
+
+ If the reply "status" is NFS_OK, then the reply "file" and reply
+ "attributes" are the file handle and attributes for the file "name"
+ in the directory given by "dir" in the argument.
+
+2.2.6. Read From Symbolic Link
+
+ union readlinkres switch (stat status) {
+ case NFS_OK:
+ path data;
+ default:
+ void;
+ };
+
+ readlinkres
+ NFSPROC_READLINK(fhandle) = 5;
+
+ If "status" has the value NFS_OK, then the reply "data" is the data
+ in the symbolic link given by the file referred to by the fhandle
+ argument.
+
+ Notes: Since NFS always parses pathnames on the client, the pathname
+ in a symbolic link may mean something different (or be meaningless)
+ on a different client or on the server if a different pathname syntax
+ is used.
+
+2.2.7. Read From File
+
+ struct readargs {
+ fhandle file;
+ unsigned offset;
+ unsigned count;
+ unsigned totalcount;
+ };
+
+ union readres switch (stat status) {
+ case NFS_OK:
+ fattr attributes;
+ nfsdata data;
+ default:
+ void;
+ };
+
+ readres
+ NFSPROC_READ(readargs) = 6;
+
+ Returns up to "count" bytes of "data" from the file given by "file",
+ starting at "offset" bytes from the beginning of the file. The first
+ byte of the file is at offset zero. The file attributes after the
+ read takes place are returned in "attributes".
+
+ Notes: The argument "totalcount" is unused, and is removed in the
+ next protocol revision.
+
+2.2.8. Write to Cache
+
+ void
+ NFSPROC_WRITECACHE(void) = 7;
+
+ To be used in the next protocol revision.
+
+2.2.9. Write to File
+
+ struct writeargs {
+ fhandle file;
+ unsigned beginoffset;
+ unsigned offset;
+ unsigned totalcount;
+ nfsdata data;
+ };
+
+ attrstat
+ NFSPROC_WRITE(writeargs) = 8;
+
+ Writes "data" beginning "offset" bytes from the beginning of "file".
+ The first byte of the file is at offset zero. If the reply "status"
+ is NFS_OK, then the reply "attributes" contains the attributes of the
+ file after the write has completed. The write operation is atomic.
+ Data from this "WRITE" will not be mixed with data from another
+ client's "WRITE".
+
+ Notes: The arguments "beginoffset" and "totalcount" are ignored and
+ are removed in the next protocol revision.
+
+2.2.10. Create File
+
+ struct createargs {
+ diropargs where;
+ sattr attributes;
+ };
+
+ diropres
+ NFSPROC_CREATE(createargs) = 9;
+
+ The file "name" is created in the directory given by "dir". The
+ initial attributes of the new file are given by "attributes". A
+ reply "status" of NFS_OK indicates that the file was created, and
+ reply "file" and reply "attributes" are its file handle and
+ attributes. Any other reply "status" means that the operation failed
+ and no file was created.
+
+ Notes: This routine should pass an exclusive create flag, meaning
+ "create the file only if it is not already there".
+
+2.2.11. Remove File
+
+ stat
+ NFSPROC_REMOVE(diropargs) = 10;
+
+ The file "name" is removed from the directory given by "dir". A
+ reply of NFS_OK means the directory entry was removed.
+
+ Notes: possibly non-idempotent operation.
+
+2.2.12. Rename File
+
+ struct renameargs {
+ diropargs from;
+ diropargs to;
+ };
+
+ stat
+ NFSPROC_RENAME(renameargs) = 11;
+
+ The existing file "from.name" in the directory given by "from.dir" is
+ renamed to "to.name" in the directory given by "to.dir". If the
+ reply is NFS_OK, the file was renamed. The RENAME operation is
+ atomic on the server; it cannot be interrupted in the middle.
+
+ Notes: possibly non-idempotent operation.
+
+2.2.13. Create Link to File
+
+ Procedure 12, Version 2.
+
+ struct linkargs {
+ fhandle from;
+ diropargs to;
+ };
+
+ stat
+ NFSPROC_LINK(linkargs) = 12;
+
+ Creates the file "to.name" in the directory given by "to.dir", which
+ is a hard link to the existing file given by "from". If the return
+ value is NFS_OK, a link was created. Any other return value
+ indicates an error, and the link was not created.
+
+ A hard link should have the property that changes to either of the
+ linked files are reflected in both files. When a hard link is made
+ to a file, the attributes for the file should have a value for
+ "nlink" that is one greater than the value before the link.
+
+ Notes: possibly non-idempotent operation.
+
+2.2.14. Create Symbolic Link
+
+ struct symlinkargs {
+ diropargs from;
+ path to;
+ sattr attributes;
+ };
+
+ stat
+ NFSPROC_SYMLINK(symlinkargs) = 13;
+
+ Creates the file "from.name" with ftype NFLNK in the directory given
+ by "from.dir". The new file contains the pathname "to" and has
+ initial attributes given by "attributes". If the return value is
+ NFS_OK, a link was created. Any other return value indicates an
+ error, and the link was not created.
+
+ A symbolic link is a pointer to another file. The name given in "to"
+ is not interpreted by the server, only stored in the newly created
+ file. When the client references a file that is a symbolic link, the
+ contents of the symbolic link are normally transparently
+ reinterpreted as a pathname to substitute. A READLINK operation
+ returns the data to the client for interpretation.
+
+ Notes: On UNIX servers the attributes are never used, since symbolic
+ links always have mode 0777.
+
+2.2.15. Create Directory
+
+ diropres
+ NFSPROC_MKDIR (createargs) = 14;
+
+ The new directory "where.name" is created in the directory given by
+ "where.dir". The initial attributes of the new directory are given
+ by "attributes". A reply "status" of NFS_OK indicates that the new
+ directory was created, and reply "file" and reply "attributes" are
+ its file handle and attributes. Any other reply "status" means that
+ the operation failed and no directory was created.
+
+ Notes: possibly non-idempotent operation.
+
+2.2.16. Remove Directory
+
+ stat
+ NFSPROC_RMDIR(diropargs) = 15;
+
+ The existing empty directory "name" in the directory given by "dir"
+ is removed. If the reply is NFS_OK, the directory was removed.
+
+ Notes: possibly non-idempotent operation.
+
+2.2.17. Read From Directory
+
+ struct readdirargs {
+ fhandle dir;
+ nfscookie cookie;
+ unsigned count;
+ };
+
+ struct entry {
+ unsigned fileid;
+ filename name;
+ nfscookie cookie;
+ entry *nextentry;
+ };
+
+ union readdirres switch (stat status) {
+ case NFS_OK:
+ struct {
+ entry *entries;
+ bool eof;
+ } readdirok;
+ default:
+ void;
+ };
+
+ readdirres
+ NFSPROC_READDIR (readdirargs) = 16;
+
+ Returns a variable number of directory entries, with a total size of
+ up to "count" bytes, from the directory given by "dir". If the
+ returned value of "status" is NFS_OK, then it is followed by a
+ variable number of "entry"s. Each "entry" contains a "fileid" which
+ consists of a unique number to identify the file within a filesystem,
+ the "name" of the file, and a "cookie" which is an opaque pointer to
+ the next entry in the directory. The cookie is used in the next
+ READDIR call to get more entries starting at a given point in the
+ directory. The special cookie zero (all bits zero) can be used to
+ get the entries starting at the beginning of the directory. The
+ "fileid" field should be the same number as the "fileid" in the the
+ attributes of the file. (See section "2.3.5. fattr" under "Basic
+ Data Types".) The "eof" flag has a value of TRUE if there are no
+ more entries in the directory.
+
+2.2.18. Get Filesystem Attributes
+
+ union statfsres (stat status) {
+ case NFS_OK:
+ struct {
+ unsigned tsize;
+ unsigned bsize;
+ unsigned blocks;
+ unsigned bfree;
+ unsigned bavail;
+ } info;
+ default:
+ void;
+ };
+
+ statfsres
+ NFSPROC_STATFS(fhandle) = 17;
+
+ If the reply "status" is NFS_OK, then the reply "info" gives the
+ attributes for the filesystem that contains file referred to by the
+ input fhandle. The attribute fields contain the following values:
+
+ tsize The optimum transfer size of the server in bytes. This is
+ the number of bytes the server would like to have in the
+ data part of READ and WRITE requests.
+
+ bsize The block size in bytes of the filesystem.
+
+ blocks The total number of "bsize" blocks on the filesystem.
+
+ bfree The number of free "bsize" blocks on the filesystem.
+
+ bavail The number of "bsize" blocks available to non-privileged
+ users.
+
+ Notes: This call does not work well if a filesystem has variable
+ size blocks.
+
+2.3. Basic Data Types
+
+ The following XDR definitions are basic structures and types used in
+ other structures described further on.
+
+2.3.1. stat
+
+ enum stat {
+ NFS_OK = 0,
+ NFSERR_PERM=1,
+
+ NFSERR_NOENT=2,
+ NFSERR_IO=5,
+ NFSERR_NXIO=6,
+ NFSERR_ACCES=13,
+ NFSERR_EXIST=17,
+ NFSERR_NODEV=19,
+ NFSERR_NOTDIR=20,
+ NFSERR_ISDIR=21,
+ NFSERR_FBIG=27,
+ NFSERR_NOSPC=28,
+ NFSERR_ROFS=30,
+ NFSERR_NAMETOOLONG=63,
+ NFSERR_NOTEMPTY=66,
+ NFSERR_DQUOT=69,
+ NFSERR_STALE=70,
+ NFSERR_WFLUSH=99
+ };
+
+ The "stat" type is returned with every procedure's results. A value
+ of NFS_OK indicates that the call completed successfully and the
+ results are valid. The other values indicate some kind of error
+ occurred on the server side during the servicing of the procedure.
+ The error values are derived from UNIX error numbers.
+
+ NFSERR_PERM
+ Not owner. The caller does not have correct ownership to perform
+ the requested operation.
+
+ NFSERR_NOENT
+ No such file or directory. The file or directory specified does
+ not exist.
+
+ NFSERR_IO
+ Some sort of hard error occurred when the operation was in
+ progress. This could be a disk error, for example.
+
+ NFSERR_NXIO
+ No such device or address.
+
+ NFSERR_ACCES
+ Permission denied. The caller does not have the correct
+ permission to perform the requested operation.
+
+ NFSERR_EXIST
+ File exists. The file specified already exists.
+
+ NFSERR_NODEV
+ No such device.
+
+ NFSERR_NOTDIR
+ Not a directory. The caller specified a non-directory in a
+ directory operation.
+
+ NFSERR_ISDIR
+ Is a directory. The caller specified a directory in a non-
+ directory operation.
+
+ NFSERR_FBIG
+ File too large. The operation caused a file to grow beyond the
+ server's limit.
+
+ NFSERR_NOSPC
+ No space left on device. The operation caused the server's
+ filesystem to reach its limit.
+
+ NFSERR_ROFS
+ Read-only filesystem. Write attempted on a read-only filesystem.
+
+ NFSERR_NAMETOOLONG
+ File name too long. The file name in an operation was too long.
+
+ NFSERR_NOTEMPTY
+ Directory not empty. Attempted to remove a directory that was not
+ empty.
+
+ NFSERR_DQUOT
+ Disk quota exceeded. The client's disk quota on the server has
+ been exceeded.
+
+ NFSERR_STALE
+ The "fhandle" given in the arguments was invalid. That is, the
+ file referred to by that file handle no longer exists, or access
+ to it has been revoked.
+
+ NFSERR_WFLUSH
+ The server's write cache used in the "WRITECACHE" call got flushed
+ to disk.
+
+2.3.2. ftype
+
+ enum ftype {
+ NFNON = 0,
+ NFREG = 1,
+ NFDIR = 2,
+ NFBLK = 3,
+ NFCHR = 4,
+ NFLNK = 5
+ };
+
+ The enumeration "ftype" gives the type of a file. The type NFNON
+ indicates a non-file, NFREG is a regular file, NFDIR is a
+ directory, NFBLK is a block-special device, NFCHR is a character-
+ special device, and NFLNK is a symbolic link.
+
+2.3.3. fhandle
+
+ typedef opaque fhandle[FHSIZE];
+
+ The "fhandle" is the file handle passed between the server and the
+ client. All file operations are done using file handles to refer
+ to a file or directory. The file handle can contain whatever
+ information the server needs to distinguish an individual file.
+
+2.3.4. timeval
+
+ struct timeval {
+ unsigned int seconds;
+ unsigned int useconds;
+ };
+
+ The "timeval" structure is the number of seconds and microseconds
+ since midnight January 1, 1970, Greenwich Mean Time. It is used
+ to pass time and date information.
+
+2.3.5. fattr
+
+ struct fattr {
+ ftype type;
+ unsigned int mode;
+ unsigned int nlink;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned int size;
+ unsigned int blocksize;
+ unsigned int rdev;
+ unsigned int blocks;
+
+ unsigned int fsid;
+ unsigned int fileid;
+ timeval atime;
+ timeval mtime;
+ timeval ctime;
+ };
+
+ The "fattr" structure contains the attributes of a file; "type" is
+ the type of the file; "nlink" is the number of hard links to the
+ file (the number of different names for the same file); "uid" is
+ the user identification number of the owner of the file; "gid" is
+ the group identification number of the group of the file; "size"
+ is the size in bytes of the file; "blocksize" is the size in bytes
+ of a block of the file; "rdev" is the device number of the file if
+ it is type NFCHR or NFBLK; "blocks" is the number of blocks the
+ file takes up on disk; "fsid" is the file system identifier for
+ the filesystem containing the file; "fileid" is a number that
+ uniquely identifies the file within its filesystem; "atime" is the
+ time when the file was last accessed for either read or write;
+ "mtime" is the time when the file data was last modified
+ (written); and "ctime" is the time when the status of the file was
+ last changed. Writing to the file also changes "ctime" if the
+ size of the file changes.
+
+ "Mode" is the access mode encoded as a set of bits. Notice that
+ the file type is specified both in the mode bits and in the file
+ type. This is really a bug in the protocol and will be fixed in
+ future versions. The descriptions given below specify the bit
+ positions using octal numbers.
+
+ 0040000 This is a directory; "type" field should be NFDIR.
+ 0020000 This is a character special file; "type" field should
+ be NFCHR.
+ 0060000 This is a block special file; "type" field should be
+ NFBLK.
+ 0100000 This is a regular file; "type" field should be NFREG.
+ 0120000 This is a symbolic link file; "type" field should be
+ NFLNK.
+ 0140000 This is a named socket; "type" field should be NFNON.
+ 0004000 Set user id on execution.
+ 0002000 Set group id on execution.
+ 0001000 Save swapped text even after use.
+ 0000400 Read permission for owner.
+ 0000200 Write permission for owner.
+ 0000100 Execute and search permission for owner.
+ 0000040 Read permission for group.
+ 0000020 Write permission for group.
+ 0000010 Execute and search permission for group.
+
+ 0000004 Read permission for others.
+ 0000002 Write permission for others.
+ 0000001 Execute and search permission for others.
+
+ Notes: The bits are the same as the mode bits returned by the
+ stat(2) system call in UNIX. The file type is specified both in
+ the mode bits and in the file type. This is fixed in future
+ versions.
+
+ The "rdev" field in the attributes structure is an operating
+ system specific device specifier. It will be removed and
+ generalized in the next revision of the protocol.
+
+2.3.6. sattr
+
+ struct sattr {
+ unsigned int mode;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned int size;
+ timeval atime;
+ timeval mtime;
+ };
+
+ The "sattr" structure contains the file attributes which can be
+ set from the client. The fields are the same as for "fattr"
+ above. A "size" of zero means the file should be truncated. A
+ value of -1 indicates a field that should be ignored.
+
+2.3.7. filename
+
+ typedef string filename<MAXNAMLEN>;
+
+ The type "filename" is used for passing file names or pathname
+ components.
+
+2.3.8. path
+
+ typedef string path<MAXPATHLEN>;
+
+ The type "path" is a pathname. The server considers it as a
+ string with no internal structure, but to the client it is the
+ name of a node in a filesystem tree.
+
+2.3.9. attrstat
+
+ union attrstat switch (stat status) {
+ case NFS_OK:
+
+ fattr attributes;
+ default:
+ void;
+ };
+
+ The "attrstat" structure is a common procedure result. It
+ contains a "status" and, if the call succeeded, it also contains
+ the attributes of the file on which the operation was done.
+
+2.3.10. diropargs
+
+ struct diropargs {
+ fhandle dir;
+ filename name;
+ };
+
+ The "diropargs" structure is used in directory operations. The
+ "fhandle" "dir" is the directory in which to find the file "name".
+ A directory operation is one in which the directory is affected.
+
+2.3.11. diropres
+
+ union diropres switch (stat status) {
+ case NFS_OK:
+ struct {
+ fhandle file;
+ fattr attributes;
+ } diropok;
+ default:
+ void;
+ };
+
+ The results of a directory operation are returned in a "diropres"
+ structure. If the call succeeded, a new file handle "file" and
+ the "attributes" associated with that file are returned along with
+ the "status".
+
+3. NFS IMPLEMENTATION ISSUES
+
+ The NFS protocol was designed to allow different operating systems to
+ share files. However, since it was designed in a UNIX environment,
+ many operations have semantics similar to the operations of the UNIX
+ file system. This section discusses some of the implementation-
+ specific details and semantic issues.
+
+3.1. Server/Client Relationship
+
+ The NFS protocol is designed to allow servers to be as simple and
+
+ general as possible. Sometimes the simplicity of the server can be a
+ problem, if the client wants to implement complicated filesystem
+ semantics.
+
+ For example, some operating systems allow removal of open files. A
+ process can open a file and, while it is open, remove it from the
+ directory. The file can be read and written as long as the process
+ keeps it open, even though the file has no name in the filesystem.
+ It is impossible for a stateless server to implement these semantics.
+ The client can do some tricks such as renaming the file on remove,
+ and only removing it on close. We believe that the server provides
+ enough functionality to implement most file system semantics on the
+ client.
+
+ Every NFS client can also potentially be a server, and remote and
+ local mounted filesystems can be freely intermixed. This leads to
+ some interesting problems when a client travels down the directory
+ tree of a remote filesystem and reaches the mount point on the server
+ for another remote filesystem. Allowing the server to follow the
+ second remote mount would require loop detection, server lookup, and
+ user revalidation. Instead, we decided not to let clients cross a
+ server's mount point. When a client does a LOOKUP on a directory on
+ which the server has mounted a filesystem, the client sees the
+ underlying directory instead of the mounted directory.
+
+ For example, if a server has a file system called "/usr" and mounts
+ another file system on "/usr/src", if a client mounts "/usr", it
+ does NOT see the mounted version of "/usr/src". A client could do
+ remote mounts that match the server's mount points to maintain the
+ server's view. In this example, the client would also have to mount
+ "/usr/src" in addition to "/usr", even if they are from the same
+ server.
+
+3.2. Pathname Interpretation
+
+ There are a few complications to the rule that pathnames are always
+ parsed on the client. For example, symbolic links could have
+ different interpretations on different clients. Another common
+ problem for non-UNIX implementations is the special interpretation of
+ the pathname ".." to mean the parent of a given directory. The next
+ revision of the protocol uses an explicit flag to indicate the parent
+ instead.
+
+3.3. Permission Issues
+
+ The NFS protocol, strictly speaking, does not define the permission
+ checking used by servers. However, it is expected that a server will
+ do normal operating system permission checking using AUTH_UNIX style
+
+ authentication as the basis of its protection mechanism. The server
+ gets the client's effective "uid", effective "gid", and groups on
+ each call and uses them to check permission. There are various
+ problems with this method that can been resolved in interesting ways.
+
+ Using "uid" and "gid" implies that the client and server share the
+ same "uid" list. Every server and client pair must have the same
+ mapping from user to "uid" and from group to "gid". Since every
+ client can also be a server, this tends to imply that the whole
+ network shares the same "uid/gid" space. AUTH_DES (and the next
+ revision of the NFS protocol) uses string names instead of numbers,
+ but there are still complex problems to be solved.
+
+ Another problem arises due to the usually stateful open operation.
+ Most operating systems check permission at open time, and then check
+ that the file is open on each read and write request. With stateless
+ servers, the server has no idea that the file is open and must do
+ permission checking on each read and write call. On a local
+ filesystem, a user can open a file and then change the permissions so
+ that no one is allowed to touch it, but will still be able to write
+ to the file because it is open. On a remote filesystem, by contrast,
+ the write would fail. To get around this problem, the server's
+ permission checking algorithm should allow the owner of a file to
+ access it regardless of the permission setting.
+
+ A similar problem has to do with paging in from a file over the
+ network. The operating system usually checks for execute permission
+ before opening a file for demand paging, and then reads blocks from
+ the open file. The file may not have read permission, but after it
+ is opened it does not matter. An NFS server can not tell the
+ difference between a normal file read and a demand page-in read. To
+ make this work, the server allows reading of files if the "uid" given
+ in the call has either execute or read permission on the file.
+
+ In most operating systems, a particular user (on UNIX, the user ID
+ zero) has access to all files no matter what permission and ownership
+ they have. This "super-user" permission may not be allowed on the
+ server, since anyone who can become super-user on their workstation
+ could gain access to all remote files. The UNIX server by default
+ maps user id 0 to -2 before doing its access checking. This works
+ except for NFS root filesystems, where super-user access cannot be
+ avoided.
+
+3.4. RPC Information
+
+ Authentication
+ The NFS service uses AUTH_UNIX, AUTH_DES, or AUTH_SHORT style
+ authentication, except in the NULL procedure where AUTH_NONE is
+
+ also allowed.
+
+ Transport Protocols
+ NFS is supported normally on UDP.
+
+ Port Number
+ The NFS protocol currently uses the UDP port number 2049. This is
+ not an officially assigned port, so later versions of the protocol
+ use the "Portmapping" facility of RPC.
+
+3.5. Sizes of XDR Structures
+
+ These are the sizes, given in decimal bytes, of various XDR
+ structures used in the protocol:
+
+ /*
+ * The maximum number of bytes of data in a READ or WRITE
+ * request.
+ */
+ const MAXDATA = 8192;
+
+ /* The maximum number of bytes in a pathname argument. */
+ const MAXPATHLEN = 1024;
+
+ /* The maximum number of bytes in a file name argument. */
+ const MAXNAMLEN = 255;
+
+ /* The size in bytes of the opaque "cookie" passed by READDIR. */
+ const COOKIESIZE = 4;
+
+ /* The size in bytes of the opaque file handle. */
+ const FHSIZE = 32;
+
+3.6. Setting RPC Parameters
+
+ Various file system parameters and options should be set at mount
+ time. The mount protocol is described in the appendix below. For
+ example, "Soft" mounts as well as "Hard" mounts are usually both
+ provided. Soft mounted file systems return errors when RPC
+ operations fail (after a given number of optional retransmissions),
+ while hard mounted file systems continue to retransmit forever. The
+ maximum transfer sizes are implementation dependent. For efficient
+ operation over a local network, 8192 bytes of data are normally used.
+ This may result in lower-level fragmentation (such as at the IP
+ level). Since some network interfaces may not allow such packets,
+ for operation over slower-speed networks or hosts, or through
+ gateways, transfer sizes of 512 or 1024 bytes often provide better
+ results.
+
+ Clients and servers may need to keep caches of recent operations to
+ help avoid problems with non-idempotent operations. For example, if
+ the transport protocol drops the response for a Remove File
+ operation, upon retransmission the server may return an error code of
+ NFSERR_NOENT instead of NFS_OK. But if the server keeps around the
+ last operation requested and its result, it could return the proper
+ success code. Of course, the server could be crashed and rebooted
+ between retransmissions, but a small cache (even a single entry)
+ would solve most problems.
+
+ Appendix A. MOUNT PROTOCOL DEFINITION
+
+A.1. Introduction
+
+ The mount protocol is separate from, but related to, the NFS
+ protocol. It provides operating system specific services to get the
+ NFS off the ground -- looking up server path names, validating user
+ identity, and checking access permissions. Clients use the mount
+ protocol to get the first file handle, which allows them entry into a
+ remote filesystem.
+
+ The mount protocol is kept separate from the NFS protocol to make it
+ easy to plug in new access checking and validation methods without
+ changing the NFS server protocol.
+
+ Notice that the protocol definition implies stateful servers because
+ the server maintains a list of client's mount requests. The mount
+ list information is not critical for the correct functioning of
+ either the client or the server. It is intended for advisory use
+ only, for example, to warn possible clients when a server is going
+ down.
+
+ Version one of the mount protocol is used with version two of the NFS
+ protocol. The only information communicated between these two
+ protocols is the "fhandle" structure.
+
+A.2. RPC Information
+
+ Authentication
+ The mount service uses AUTH_UNIX and AUTH_NONE style
+ authentication only.
+
+ Transport Protocols
+ The mount service is supported on both UDP and TCP.
+
+ Port Number
+ Consult the server's portmapper, described in RFC 1057 </rfcs/rfc1057.html>, "RPC:
+ Remote Procedure Call Protocol Specification", to find the port
+ number on which the mount service is registered.
+
+A.3. Sizes of XDR Structures
+
+ These are the sizes, given in decimal bytes, of various XDR
+ structures used in the protocol:
+
+ /* The maximum number of bytes in a pathname argument. */
+ const MNTPATHLEN = 1024;
+
+ /* The maximum number of bytes in a name argument. */
+ const MNTNAMLEN = 255;
+
+ /* The size in bytes of the opaque file handle. */
+ const FHSIZE = 32;
+
+A.4. Basic Data Types
+
+ This section presents the data types used by the mount protocol. In
+ many cases they are similar to the types used in NFS.
+
+A.4.1. fhandle
+
+ typedef opaque fhandle[FHSIZE];
+
+ The type "fhandle" is the file handle that the server passes to the
+ client. All file operations are done using file handles to refer to
+ a file or directory. The file handle can contain whatever
+ information the server needs to distinguish an individual file.
+
+ This is the same as the "fhandle" XDR definition in version 2 of the
+ NFS protocol; see section "2.3.3. fhandle" under "Basic Data Types".
+
+A.4.2. fhstatus
+
+ union fhstatus switch (unsigned status) {
+ case 0:
+ fhandle directory;
+ default:
+ void;
+ }
+
+ The type "fhstatus" is a union. If a "status" of zero is returned,
+ the call completed successfully, and a file handle for the
+ "directory" follows. A non-zero status indicates some sort of error.
+ In this case, the status is a UNIX error number.
+
+A.4.3. dirpath
+
+ typedef string dirpath<MNTPATHLEN>;
+
+ The type "dirpath" is a server pathname of a directory.
+
+A.4.4. name
+
+ typedef string name<MNTNAMLEN>;
+
+ The type "name" is an arbitrary string used for various names.
+
+A.5. Server Procedures
+
+ The following sections define the RPC procedures supplied by a mount
+ server.
+
+ /*
+ * Protocol description for the mount program
+ */
+ program MOUNTPROG {
+ /*
+ * Version 1 of the mount protocol used with
+ * version 2 of the NFS protocol.
+ */
+ version MOUNTVERS {
+
+ void
+ MOUNTPROC_NULL(void) = 0;
+
+ fhstatus
+ MOUNTPROC_MNT(dirpath) = 1;
+
+ mountlist
+ MOUNTPROC_DUMP(void) = 2;
+
+ void
+ MOUNTPROC_UMNT(dirpath) = 3;
+
+ void
+ MOUNTPROC_UMNTALL(void) = 4;
+
+ exportlist
+ MOUNTPROC_EXPORT(void) = 5;
+ } = 1;
+ } = 100005;
+
+A.5.1. Do Nothing
+
+ void
+ MNTPROC_NULL(void) = 0;
+
+ This procedure does no work. It is made available in all RPC
+ services to allow server response testing and timing.
+
+A.5.2. Add Mount Entry
+
+ fhstatus
+ MNTPROC_MNT(dirpath) = 1;
+
+ If the reply "status" is 0, then the reply "directory" contains the
+ file handle for the directory "dirname". This file handle may be
+ used in the NFS protocol. This procedure also adds a new entry to
+ the mount list for this client mounting "dirname".
+
+A.5.3. Return Mount Entries
+
+ struct *mountlist {
+ name hostname;
+ dirpath directory;
+ mountlist nextentry;
+ };
+
+ mountlist
+ MNTPROC_DUMP(void) = 2;
+
+ Returns the list of remote mounted filesystems. The "mountlist"
+ contains one entry for each "hostname" and "directory" pair.
+
+A.5.4. Remove Mount Entry
+
+ void
+ MNTPROC_UMNT(dirpath) = 3;
+
+ Removes the mount list entry for the input "dirpath".
+
+A.5.5. Remove All Mount Entries
+
+ void
+ MNTPROC_UMNTALL(void) = 4;
+
+ Removes all of the mount list entries for this client.
+
+A.5.6. Return Export List
+
+ struct *groups {
+ name grname;
+ groups grnext;
+ };
+
+ struct *exportlist {
+ dirpath filesys;
+ groups groups;
+ exportlist next;
+ };
+
+ exportlist
+ MNTPROC_EXPORT(void) = 5;
+
+ Returns a variable number of export list entries. Each entry
+ contains a filesystem name and a list of groups that are allowed to
+ import it. The filesystem name is in "filesys", and the group name
+ is in the list "groups".
+
+ Notes: The exportlist should contain more information about the
+ status of the filesystem, such as a read-only flag.
+
+Author's Address:
+
+ Bill Nowicki
+ Sun Microsystems, Inc.
+ Mail Stop 1-40
+ 2550 Garcia Avenue
+ Mountain View, CA 94043
+
+ Phone: (415) 336-7278
+
+ Email: nowicki@SUN.COM <mailto:nowicki@SUN.COM>
+
+Comment on RFC 1094 </rfccomment.php?rfcnum=1094>
+
+
+
+Comments about this RFC:
+
+ * RFC 1094: I am preparing for doing a project in File System in
+ Network. can you specify... </qa/rfcc-377.html> by Ravik (12/4/2003)
+
+
+Previous: RFC 1093 - NSFNET routing architecture </rfcs/rfc1093.html>
+
+
+
+Next: RFC 1095 - Common Management Information Services and Protocol
+over TCP/IP (CMOT) </rfcs/rfc1095.html>
+
+
+
+------------------------------------------------------------------------
diff --git a/cpukit/libfs/src/nfsclient/src/cexphelp.c b/cpukit/libfs/src/nfsclient/src/cexphelp.c
new file mode 100644
index 0000000000..d0406ad33a
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/cexphelp.c
@@ -0,0 +1,20 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <librtemsNfs.h>
+#include <cexpHelp.h>
+CEXP_HELP_TAB_BEGIN(rtemsNfs)
+ HELP(
+"Mount a remote filesystem (NFS). The mount point (must not be a NFS dir)\n"
+"is created on the fly if not existing already.\n"
+"uid/gid to use may be specified:\n"
+" hostspec: [uid.gid@]hostname_or_ipaddr\n"
+ , int, nfsMount, (char *hostspec, char *exportdir, char *mntpoint)
+ ),
+ HELP(
+"Print all currently mounted NFS directories to open file handle.\n"
+"Pass f = 0 to print to stdout\n"
+ , int, nfsMountsShow, (FILE *f)
+ ),
+CEXP_HELP_TAB_END
diff --git a/cpukit/libfs/src/nfsclient/src/dirutils.c b/cpukit/libfs/src/nfsclient/src/dirutils.c
new file mode 100644
index 0000000000..99c65876f3
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/dirutils.c
@@ -0,0 +1,385 @@
+/* $Id$ */
+
+/* very crude and basic fs utilities for testing the NFS */
+
+/* Till Straumann, <strauman@slac.stanford.edu>, 10/2002 */
+
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef __vxworks
+#include <vxWorks.h>
+#endif
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h> /* PATH_MAX */
+
+#include <inttypes.h> /* PRI* */
+
+#if SIZEOF_MODE_T == 8
+#define PRIomode_t PRIo64
+#elif SIZEOF_MODE_T == 4
+#define PRIomode_t PRIo32
+#else
+#error "unsupport size of mode_t"
+#endif
+
+#if SIZEOF_OFF_T == 8
+#define PRIdoff_t PRIo64
+#elif SIZEOF_OFF_T == 4
+#define PRIdoff_t PRIo32
+#else
+#error "unsupported size of off_t"
+#endif
+
+#ifdef HAVE_CEXP
+#include <cexpHelp.h>
+#endif
+
+#ifndef __vxworks
+int
+pwd(void)
+{
+char buf[PATH_MAX];
+
+ if ( !getcwd(buf,PATH_MAX)) {
+ perror("getcwd");
+ return -1;
+ } else {
+ printf("%s\n",buf);
+ }
+ return 0;
+}
+
+static int
+ls_r(char *path, char *chpt, char *name, struct stat *buf)
+{
+char *t;
+ sprintf(chpt, "/%s", name);
+ if (lstat(path,buf)) {
+ fprintf(stderr,"stat(%s): %s\n", path, strerror(errno));
+ return -1;
+ }
+ switch ( buf->st_mode & S_IFMT ) {
+ case S_IFSOCK:
+ case S_IFIFO: t = "|"; break;
+
+ default:
+ case S_IFREG:
+ case S_IFBLK:
+ case S_IFCHR:
+ t = ""; break;
+ case S_IFDIR:
+ t = "/"; break;
+ case S_IFLNK:
+ t = "@"; break;
+ }
+
+ printf("%10li, %10" PRIdoff_t "b, %5i.%-5i 0%04" PRIomode_t " %s%s\n",
+ buf->st_ino,
+ buf->st_size,
+ buf->st_uid,
+ buf->st_gid,
+ buf->st_mode & ~S_IFMT,
+ name,
+ t);
+ *chpt = 0;
+ return 0;
+}
+
+int
+ls(char *dir, char *opts)
+{
+struct dirent *de;
+char path[PATH_MAX+1];
+char *chpt;
+DIR *dp = 0;
+int rval = -1;
+struct stat buf;
+
+ if ( !dir )
+ dir = ".";
+
+ strncpy(path, dir, PATH_MAX);
+ path[PATH_MAX] = 0;
+ chpt = path+strlen(path);
+
+ if ( !(dp=opendir(dir)) ) {
+ perror("opendir");
+ goto cleanup;
+ }
+
+ while ( (de = readdir(dp)) ) {
+ ls_r(path, chpt, de->d_name, &buf);
+ }
+
+ rval = 0;
+
+cleanup:
+ if (dp)
+ closedir(dp);
+ return rval;
+}
+#endif
+
+#if 0
+ fprintf(stderr, "usage: cp(""from"",[""to""[,""-f""]]\n");
+ fprintf(stderr, " ""to""==NULL -> stdout\n");
+ fprintf(stderr, " ""-f"" -> overwrite existing file\n");
+#endif
+
+int
+cp(char *from, char *to, char *opts)
+{
+struct stat st;
+int rval = -1;
+int fd = -1;
+FILE *fst = 0;
+FILE *tst = 0;
+int flags = O_CREAT | O_WRONLY | O_TRUNC | O_EXCL;
+
+ if (from) {
+
+ if ((fd=open(from,O_RDONLY,0)) < 0) {
+ fprintf(stderr,
+ "Opening %s for reading: %s\n",
+ from,
+ strerror(errno));
+ goto cleanup;
+ }
+
+ if (fstat(fd, &st)) {
+ fprintf(stderr,
+ "rstat(%s): %s\n",
+ from,
+ strerror(errno));
+ goto cleanup;
+ }
+
+
+ if (!S_ISREG(st.st_mode)) {
+ fprintf(stderr,"Refuse to copy a non-regular file\n");
+ errno = EINVAL;
+ goto cleanup;
+ }
+ /* Now create a stream -- I experienced occasional weirdness
+ * when circumventing the streams attached to fildno(stdin)
+ * by reading/writing to the underlying fd's directly ->
+ * for now we always go through buffered I/O...
+ */
+ if ( !(fst=fdopen(fd,"r")) ) {
+ fprintf(stderr,
+ "Opening input stream [fdopen()] failed: %s\n",
+ strerror(errno));
+ goto cleanup;
+ }
+ /* at this point, we have a stream and don't need 'fd' anymore */
+ fd = -1;
+
+ } else {
+ fst = stdin;
+ st.st_mode = 0644;
+ }
+
+ if (opts && strchr(opts,'f'))
+ flags &= ~ O_EXCL;
+
+ if (to) {
+ if ( (fd=open(to,flags,st.st_mode)) < 0 ) {
+ fprintf(stderr,
+ "Opening %s for writing: %s\n",
+ to,
+ strerror(errno));
+ goto cleanup;
+ }
+ if ( !(tst=fdopen(fd, "w")) ) {
+ fprintf(stderr,
+ "Opening output stream [fdopen()] failed: %s\n",
+ strerror(errno));
+ goto cleanup;
+ }
+ /* at this point we have a stream and don't need 'fd' anymore */
+ fd = -1;
+ } else {
+ tst = stdout;
+ }
+
+ /* clear old errors */
+ clearerr(fst);
+ clearerr(tst);
+
+ /* use macro versions on register vars; stdio is already buffered,
+ * there's nothing to be gained by reading/writing blocks into
+ * a secondary buffer...
+ */
+ {
+ register int ch;
+ register FILE *f = fst;
+ register FILE *t = tst;
+ while ( EOF != (ch = getc(f)) && EOF != putc(ch, t) )
+ /* nothing else */;
+ }
+
+ if ( ferror(fst) ) {
+ fprintf(stderr,"Read error: %s\n",strerror(errno));
+ goto cleanup;
+ }
+ if ( ferror(tst) ) {
+ fprintf(stderr,"Write error: %s\n",strerror(errno));
+ goto cleanup;
+ }
+
+ rval = 0;
+
+cleanup:
+
+ if ( fd >= 0 )
+ close(fd);
+
+ if ( fst ) {
+ if ( from )
+ fclose(fst);
+ else
+ clearerr(fst);
+ }
+ if ( tst ) {
+ if ( to )
+ fclose(tst);
+ else {
+ /* flush stdout */
+ fflush(tst);
+ clearerr(tst);
+ }
+ }
+
+ return rval;
+}
+
+int
+ln(char *to, char *name, char *opts)
+{
+ if (!to) {
+ fprintf(stderr,"ln: need 'to' argument\n");
+ return -1;
+ }
+ if (!name) {
+ if ( !(name = strrchr(to,'/')) ) {
+ fprintf(stderr,
+ "ln: 'unable to link %s to %s\n",
+ to,to);
+ return -1;
+ }
+ name++;
+ }
+ if (opts || strchr(opts,'s')) {
+ if (symlink(name,to)) {
+ fprintf(stderr,"symlink: %s\n",strerror(errno));
+ return -1;
+ }
+ } else {
+ if (link(name,to)) {
+ fprintf(stderr,"hardlink: %s\n",strerror(errno));
+ return -1;
+ }
+ }
+ return 0;
+}
+
+int
+rm(char *path)
+{
+ return unlink(path);
+}
+
+int
+cd(char *path)
+{
+ return chdir(path);
+}
+
+#ifdef HAVE_CEXP
+static CexpHelpTabRec _cexpHelpTabDirutils[] __attribute__((unused)) = {
+ HELP(
+"copy a file: cp(""from"",[""to""[,""-f""]])\n\
+ from = NULL <-- stdin\n\
+ to = NULL --> stdout\n\
+ option -f: overwrite existing file\n",
+ int,
+ cp, (char *from, char *to, char *options)
+ ),
+ HELP(
+"list a directory: ls([""dir""])\n",
+ int,
+ ls, (char *dir)
+ ),
+ HELP(
+"remove a file\n",
+ int,
+ rm, (char *path)
+ ),
+ HELP(
+"change the working directory\n",
+ int,
+ cd, (char *path)
+ ),
+ HELP(
+"create a link: ln(""to"",""name"",""[-s]""\n\
+ -s creates a symlink\n",
+ int,
+ ln, (char *to, char *name, char *options)
+ ),
+ HELP("",,0,)
+};
+#endif
diff --git a/cpukit/libfs/src/nfsclient/src/librtemsNfs.h b/cpukit/libfs/src/nfsclient/src/librtemsNfs.h
new file mode 100644
index 0000000000..fc17d1de7f
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/librtemsNfs.h
@@ -0,0 +1,180 @@
+#ifndef LIB_RTEMS_NFS_CLIENT_H
+#define LIB_RTEMS_NFS_CLIENT_H
+/* $Id$ */
+
+/* public interface to the NFS client library for RTEMS */
+
+/* Author: Till Straumann <strauman@slac.stanford.edu> 2002-2003 */
+
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* RPCIO driver interface.
+ * If you need RPCIO for other purposes than NFS
+ * you may want to include <rpcio.h>
+#include "rpcio.h"
+ */
+
+/* Priority of daemon; may be setup prior to calling rpcUdpInit();
+ * otherwise the network task priority from the rtems_bsdnet_config
+ * is used...
+ */
+extern rtems_task_priority rpciodPriority;
+
+/* Initialize the driver.
+ *
+ * Note, called in nfsfs initialise when mount is called.
+ *
+ * RETURNS: 0 on success, -1 on failure
+ */
+int
+rpcUdpInit(void);
+
+/* Cleanup/Stop
+ *
+ * RETURNS: 0 on success, nonzero if still in use
+ */
+int
+rpcUdpCleanup(void);
+
+/* NFS driver interface */
+
+/* Initialize the NFS driver.
+ *
+ * NOTE: The RPCIO driver must have been initialized prior to
+ * calling this.
+ *
+ * Note, called in nfsfs initialise when mount is called with defaults.
+ *
+ * ARGS: depth of the small and big
+ * transaction pools, i.e. how
+ * many transactions (buffers)
+ * should always be kept around.
+ *
+ * (If more transactions are needed,
+ * they are created and destroyed
+ * on the fly).
+ *
+ * Supply zero values to have the
+ * driver chose reasonable defaults.
+ */
+int
+nfsInit(int smallPoolDepth, int bigPoolDepth);
+
+/* Driver cleanup code
+ *
+ * RETURNS: 0 on success, nonzero if still in use
+ */
+int
+nfsCleanup(void);
+
+/* Dump a list of the currently mounted NFS to a file
+ * (stdout is used in case f==NULL)
+ */
+int
+nfsMountsShow(FILE *f);
+
+/*
+ * Filesystem mount table mount handler. Do not call, use the mount call.
+ */
+int
+rtems_nfs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data);
+
+/* A utility routine to find the path leading to a
+ * rtems_filesystem_location_info_t node.
+ *
+ * This should really be present in libcsupport...
+ *
+ * INPUT: 'loc' and a buffer 'buf' (length 'len') to hold the
+ * path.
+ * OUTPUT: path copied into 'buf'
+ *
+ * RETURNS: 0 on success, RTEMS error code on error.
+ */
+rtems_status_code
+rtems_filesystem_resolve_location(char *buf, int len, rtems_filesystem_location_info_t *loc);
+
+/* Set the timeout (initial default: 10s) for NFS and mount calls.
+ *
+ * RETURNS 0 on success, nonzero if the requested timeout is less than
+ * a clock tick or if the system clock rate cannot be determined.
+ */
+
+int
+nfsSetTimeout(uint32_t timeout_ms);
+
+/* Read current timeout (in milliseconds) */
+uint32_t
+nfsGetTimeout(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c
new file mode 100644
index 0000000000..b8a7ffdb57
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/nfs.c
@@ -0,0 +1,3354 @@
+/* $Id$ */
+
+/* NFS client implementation for RTEMS; hooks into the RTEMS filesystem */
+
+/* Author: Till Straumann <strauman@slac.stanford.edu> 2002 */
+
+/* Hacked on by others. */
+
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <nfs_prot.h>
+#include <mount_prot.h>
+
+#include "rpcio.h"
+
+/* Configurable parameters */
+
+/* Estimated average length of a filename (including terminating 0).
+ * This was calculated by doing
+ *
+ * find <some root> -print -exec basename '{}' \; > feil
+ * wc feil
+ *
+ * AVG_NAMLEN = (num_chars + num_lines)/num_lines
+ */
+#define CONFIG_AVG_NAMLEN 10
+
+#define CONFIG_NFS_SMALL_XACT_SIZE 800 /* size of RPC arguments for non-write ops */
+/* lifetime of NFS attributes in a NfsNode;
+ * the time is in seconds and the lifetime is
+ * infinite if the symbol is #undef
+ */
+#define CONFIG_ATTR_LIFETIME 10/*secs*/
+
+/*
+ * The 'st_blksize' (stat(2)) value this nfs
+ * client should report. If set to zero then the server's fattr data
+ * is passed throught which is not necessary optimal.
+ * Newlib's stdio uses 'st_blksize' (if built with HAVE_BLKSIZE defined)
+ * to size the default buffer.
+ * Due to the overhead of NFS it is probably better to use the maximum
+ * size of an NFS read request (8k) rather than the optimal block
+ * size on the server.
+ * This value can be overridden at run-time by setting the global
+ * variable 'nfsStBlksize'.
+ * Thanks to Steven Johnson <sjohnson@sakuraindustries.com> for helping
+ * working on this issue.
+ */
+#define DEFAULT_NFS_ST_BLKSIZE NFS_MAXDATA
+
+/* dont change this without changing the maximal write size */
+#define CONFIG_NFS_BIG_XACT_SIZE UDPMSGSIZE /* dont change this */
+
+/* The real values for these are specified further down */
+#define NFSCALL_TIMEOUT (&_nfscalltimeout)
+#define MNTCALL_TIMEOUT (&_nfscalltimeout)
+static struct timeval _nfscalltimeout = { 10, 0 }; /* {secs, us } */
+
+/* More or less fixed constants; in particular, NFS3 is not supported */
+#define DELIM '/'
+#define HOSTDELIM ':'
+#define UPDIR ".."
+#define UIDSEP '@'
+#define NFS_VERSION_2 NFS_VERSION
+
+/* we use a dynamically assigned major number */
+#define NFS_MAJOR (nfsGlob.nfs_major)
+
+
+/* NOTE: RTEMS (ss-20020301) uses a 'short st_ino' type :-( but the
+ * NFS fileid is 32 bit. [Later versions of RTEMS have fixed this;
+ * nfsInit() issues a warning if you run a version with 'short st_ino'.]
+ *
+ * As a workarount, we merge the upper 16bits of the fileid into the
+ * minor device no. Hence, it is still possible to uniquely identify
+ * a file by looking at its device number (major = nfs, minor = part
+ * of the fileid + our 'nfs-id' identifier).
+ *
+ * This has an impact on performance, as e.g. getcwd() stats() all
+ * directory entries when it believes it has crossed a mount point
+ * (a.st_dev != b.st_dev).
+ *
+ * OTOH, it also might cause node comparison failure! E.g. 'getcwd()'
+ * assumes that two nodes residing in the same directory must be located
+ * on the same device and hence compares 'st_ino' only.
+ * If two files in the same directory have the same inode number
+ * modulo 2^16, they will be considered equal (although their device
+ * number doesn't match - getcwd doesn't look at it).
+ *
+ * Other software might or might not be affected.
+ *
+ * The only clean solution to this problem is bumping up the size of
+ * 'ino_t' at least to 'long'.
+ * Note that this requires _all_ software (libraries etc.) to be
+ * recompiled.
+ */
+
+#define NFS_MAKE_DEV_T_INO_HACK(node) \
+ rtems_filesystem_make_dev_t( NFS_MAJOR, \
+ (((rtems_device_minor_number)((node)->nfs->id))<<16) | (((rtems_device_minor_number)SERP_ATTR((node)).fileid) >> 16) )
+
+/* use our 'nfs id' and the server's fsid for the minor device number
+ * this should be fairly unique
+ */
+#define NFS_MAKE_DEV_T(node) \
+ rtems_filesystem_make_dev_t( NFS_MAJOR, \
+ (((rtems_device_minor_number)((node)->nfs->id))<<16) | (SERP_ATTR((node)).fsid & (((rtems_device_minor_number)1<<16)-1)) )
+
+#define DIRENT_HEADER_SIZE ( sizeof(struct dirent) - \
+ sizeof( ((struct dirent *)0)->d_name ) )
+
+
+/* debugging flags */
+#define DEBUG_COUNT_NODES (1<<0)
+#define DEBUG_TRACK_NODES (1<<1)
+#define DEBUG_EVALPATH (1<<2)
+#define DEBUG_READDIR (1<<3)
+#define DEBUG_SYSCALLS (1<<4)
+
+/* #define DEBUG ( DEBUG_SYSCALLS | DEBUG_COUNT_NODES ) */
+
+#ifdef DEBUG
+#define STATIC
+#else
+#define STATIC static
+#endif
+
+#define MUTEX_ATTRIBUTES (RTEMS_LOCAL | \
+ RTEMS_PRIORITY | \
+ RTEMS_INHERIT_PRIORITY | \
+ RTEMS_BINARY_SEMAPHORE)
+
+#define LOCK(s) do { \
+ rtems_semaphore_obtain((s), \
+ RTEMS_WAIT, \
+ RTEMS_NO_TIMEOUT); \
+ } while (0)
+
+#define UNLOCK(s) do { rtems_semaphore_release((s)); \
+ } while (0)
+
+/*****************************************
+ Types with Associated XDR Routines
+ *****************************************/
+
+/* a string buffer with a maximal length.
+ * If the buffer pointer is NULL, it is updated
+ * with an appropriately allocated area.
+ */
+typedef struct strbuf {
+ char *buf;
+ u_int max;
+} strbuf;
+
+static bool_t
+xdr_strbuf(XDR *xdrs, strbuf *obj)
+{
+ return xdr_string(xdrs, &obj->buf, obj->max);
+}
+
+/* Read 'readlink' results into a 'strbuf'.
+ * This is convenient as it avoids
+ * one extra step of copying / lenght
+ * checking.
+ */
+typedef struct readlinkres_strbuf {
+ nfsstat status;
+ strbuf strbuf;
+} readlinkres_strbuf;
+
+static bool_t
+xdr_readlinkres_strbuf(XDR *xdrs, readlinkres_strbuf *objp)
+{
+ if ( !xdr_nfsstat(xdrs, &objp->status) )
+ return FALSE;
+
+ if ( NFS_OK == objp->status ) {
+ if ( !xdr_string(xdrs, &objp->strbuf.buf, objp->strbuf.max) )
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+/* DirInfoRec is used instead of dirresargs
+ * to convert recursion into iteration. The
+ * 'rpcgen'erated xdr_dirresargs ends up
+ * doing nested calls when unpacking the
+ * 'next' pointers.
+ */
+
+typedef struct DirInfoRec_ {
+ readdirargs readdirargs;
+ /* clone of the 'readdirres' fields;
+ * the cookie is put into the readdirargs above
+ */
+ nfsstat status;
+ char *buf, *ptr;
+ int len;
+ bool_t eofreached;
+} DirInfoRec, *DirInfo;
+
+/* this deals with one entry / record */
+static bool_t
+xdr_dir_info_entry(XDR *xdrs, DirInfo di)
+{
+union {
+ char nambuf[NFS_MAXNAMLEN+1];
+ nfscookie cookie;
+} dummy;
+struct dirent *pde = (struct dirent *)di->ptr;
+u_int fileid;
+char *name;
+register int nlen = 0,len,naligned = 0;
+nfscookie *pcookie;
+
+ len = di->len;
+
+ if ( !xdr_u_int(xdrs, &fileid) )
+ return FALSE;
+
+ /* we must pass the address of a char* */
+ name = (len > NFS_MAXNAMLEN) ? pde->d_name : dummy.nambuf;
+
+ if ( !xdr_filename(xdrs, &name) ) {
+ return FALSE;
+ }
+
+ if (len >= 0) {
+ nlen = strlen(name);
+ naligned = nlen + 1 /* string delimiter */ + 3 /* alignment */;
+ naligned &= ~3;
+ len -= naligned;
+ }
+
+ /* if the cookie goes into the DirInfo, we hope this doesn't fail
+ * - the caller ends up with an invalid readdirargs cookie otherwise...
+ */
+ pcookie = (len >= 0) ? &di->readdirargs.cookie : &dummy.cookie;
+ if ( !xdr_nfscookie(xdrs, pcookie) ) {
+ return FALSE;
+ }
+
+ di->len = len;
+ /* adjust the buffer pointer */
+ if (len >= 0) {
+ pde->d_ino = fileid;
+ pde->d_namlen = nlen;
+ pde->d_off = di->ptr - di->buf;
+ if (name == dummy.nambuf) {
+ memcpy(pde->d_name, dummy.nambuf, nlen + 1);
+ }
+ pde->d_reclen = DIRENT_HEADER_SIZE + naligned;
+ di->ptr += pde->d_reclen;
+ }
+
+ return TRUE;
+}
+
+/* this routine loops over all entries */
+static bool_t
+xdr_dir_info(XDR *xdrs, DirInfo di)
+{
+DirInfo dip;
+
+ if ( !xdr_nfsstat(xdrs, &di->status) )
+ return FALSE;
+
+ if ( NFS_OK != di->status )
+ return TRUE;
+
+ dip = di;
+
+ while (dip) {
+ /* reserve space for the dirent 'header' - we assume it's word aligned! */
+#ifdef DEBUG
+ assert( DIRENT_HEADER_SIZE % 4 == 0 );
+#endif
+ dip->len -= DIRENT_HEADER_SIZE;
+
+ /* we pass a 0 size - size is unused since
+ * we always pass a non-NULL pointer
+ */
+ if ( !xdr_pointer(xdrs, (void*)&dip, 0 /* size */, (xdrproc_t)xdr_dir_info_entry) )
+ return FALSE;
+ }
+
+ if ( ! xdr_bool(xdrs, &di->eofreached) )
+ return FALSE;
+
+ /* if everything fits into the XDR buffer but not the user's buffer,
+ * they must resume reading from where xdr_dir_info_entry() started
+ * skipping and 'eofreached' needs to be adjusted
+ */
+ if ( di->len < 0 && di->eofreached )
+ di->eofreached = FALSE;
+
+ return TRUE;
+}
+
+
+/* a type better suited for node operations
+ * than diropres.
+ * fattr and fhs are swapped so parts of this
+ * structure may be used as a diroparg which
+ * is practical when looking up paths.
+ */
+
+/* Macro for accessing serporid fields
+ */
+#define SERP_ARGS(node) ((node)->serporid.serporid_u.serporid.arg_u)
+#define SERP_ATTR(node) ((node)->serporid.serporid_u.serporid.attributes)
+#define SERP_FILE(node) ((node)->serporid.serporid_u.serporid.file)
+
+
+typedef struct serporidok {
+ fattr attributes;
+ nfs_fh file;
+ union {
+ struct {
+ filename name;
+ } diroparg;
+ struct {
+ sattr attributes;
+ } sattrarg;
+ struct {
+ uint32_t offset;
+ uint32_t count;
+ uint32_t totalcount;
+ } readarg;
+ struct {
+ uint32_t beginoffset;
+ uint32_t offset;
+ uint32_t totalcount;
+ struct {
+ uint32_t data_len;
+ char* data_val;
+ } data;
+ } writearg;
+ struct {
+ filename name;
+ sattr attributes;
+ } createarg;
+ struct {
+ filename name;
+ diropargs to;
+ } renamearg;
+ struct {
+ diropargs to;
+ } linkarg;
+ struct {
+ filename name;
+ nfspath to;
+ sattr attributes;
+ } symlinkarg;
+ struct {
+ nfscookie cookie;
+ uint32_t count;
+ } readdirarg;
+ } arg_u;
+} serporidok;
+
+typedef struct serporid {
+ nfsstat status;
+ union {
+ serporidok serporid;
+ } serporid_u;
+} serporid;
+
+/* an XDR routine to encode/decode the inverted diropres
+ * into an nfsnodestat;
+ *
+ * NOTE: this routine only acts on
+ * - 'serporid.status'
+ * - 'serporid.file'
+ * - 'serporid.attributes'
+ * and leaves the 'arg_u' alone.
+ *
+ * The idea is that a 'diropres' is read into 'serporid'
+ * which can then be used as an argument to subsequent
+ * NFS-RPCs (after filling in the node's arg_u).
+ */
+static bool_t
+xdr_serporidok(XDR *xdrs, serporidok *objp)
+{
+ if (!xdr_nfs_fh (xdrs, &objp->file))
+ return FALSE;
+ if (!xdr_fattr (xdrs, &objp->attributes))
+ return FALSE;
+ return TRUE;
+}
+
+static bool_t
+xdr_serporid(XDR *xdrs, serporid *objp)
+{
+ if (!xdr_nfsstat (xdrs, &objp->status))
+ return FALSE;
+ switch (objp->status) {
+ case NFS_OK:
+ if (!xdr_serporidok(xdrs, &objp->serporid_u.serporid))
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+/*****************************************
+ Data Structures and Types
+ *****************************************/
+
+/* 'time()' hack with less overhead; */
+
+/* assume reading a long word is atomic */
+#define READ_LONG_IS_ATOMIC
+
+typedef uint32_t TimeStamp;
+
+static inline TimeStamp
+nowSeconds(void)
+{
+ rtems_interval rval;
+ rtems_clock_get_seconds_since_epoch( &rval );
+ return rval;
+}
+
+
+/* Per mounted FS structure */
+typedef struct NfsRec_ {
+ /* the NFS server we're talking to.
+ */
+ RpcUdpServer server;
+ /* statistics; how many NfsNodes are
+ * currently alive.
+ */
+ volatile int nodesInUse;
+#if DEBUG & DEBUG_COUNT_NODES
+ /* statistics; how many 'NfsNode.str'
+ * strings are currently allocated.
+ */
+ volatile int stringsInUse;
+#endif
+ /* A small number who uniquely
+ * identifies a mounted NFS within
+ * this driver (i.e. this NfsRec).
+ * Each time a NFS is mounted, the
+ * global ID counter is incremented
+ * and its value is assigned to the
+ * newly created NfsRec.
+ */
+ u_short id;
+ /* Our RTEMS filesystem mt_entry
+ */
+ rtems_filesystem_mount_table_entry_t *mt_entry;
+ /* Next NfsRec on a linked list who
+ * is anchored at nfsGlob
+ */
+ struct NfsRec_ *next;
+ /* Who we pretend we are
+ */
+ u_long uid,gid;
+} NfsRec, *Nfs;
+
+typedef struct NfsNodeRec_ {
+ /* This holds this node's attributes
+ * (stats) and its nfs filehandle.
+ * It also contains room for nfs rpc
+ * arguments.
+ */
+ serporid serporid;
+ /* The arguments we used when doing
+ * the 'lookup' call for this node.
+ * We need this information (especially
+ * the directory FH) for performing
+ * certain operations on this
+ * node (in particular: for unlinking
+ * it from a parent directory)
+ */
+ diropargs args;
+ /* FS this node belongs to
+ */
+ Nfs nfs;
+ /* A buffer for the string the
+ * args.name points to.
+ * We need this because args.name might
+ * temporarily point to strings on the
+ * stack. Duplicates are allocated from
+ * the heap and attached to 'str' so
+ * they can be released as appropriate.
+ */
+ char *str;
+ /* A timestamp for the stats
+ */
+ TimeStamp age;
+} NfsNodeRec, *NfsNode;
+
+/*****************************************
+ Forward Declarations
+ *****************************************/
+
+static ssize_t nfs_readlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ char *buf, /* OUT */
+ size_t len
+);
+
+static int updateAttr(NfsNode node, int force);
+
+/* Mask bits when setting attributes.
+ * Only the 'arg' fields with their
+ * corresponding bit set in the mask
+ * will be used. The others are left
+ * unchanged.
+ * The 'TOUCH' bits instruct nfs_sattr()
+ * to update the respective time
+ * fields to the current time
+ */
+#define SATTR_MODE (1<<0)
+#define SATTR_UID (1<<1)
+#define SATTR_GID (1<<2)
+#define SATTR_SIZE (1<<3)
+#define SATTR_ATIME (1<<4)
+#define SATTR_TOUCHA (1<<5)
+#define SATTR_MTIME (1<<6)
+#define SATTR_TOUCHM (1<<7)
+#define SATTR_TOUCH (SATTR_TOUCHM | SATTR_TOUCHA)
+
+static int
+nfs_sattr(NfsNode node, sattr *arg, u_long mask);
+
+extern struct _rtems_filesystem_operations_table nfs_fs_ops;
+static struct _rtems_filesystem_file_handlers_r nfs_file_file_handlers;
+static struct _rtems_filesystem_file_handlers_r nfs_dir_file_handlers;
+static struct _rtems_filesystem_file_handlers_r nfs_link_file_handlers;
+static rtems_driver_address_table drvNfs;
+
+int
+nfsMountsShow(FILE*);
+
+rtems_status_code
+rtems_filesystem_resolve_location(char *buf, int len, rtems_filesystem_location_info_t *loc);
+
+
+/*****************************************
+ Inline Routines
+ *****************************************/
+
+
+/* * * * * * * * * * * * * * * * * *
+ Trivial Operations on a NfsNode
+ * * * * * * * * * * * * * * * * * */
+
+/* determine if a location 'l' is an NFS root node */
+static inline int
+locIsRoot(rtems_filesystem_location_info_t *l)
+{
+NfsNode me = (NfsNode) l->node_access;
+NfsNode r;
+ r = (NfsNode)l->mt_entry->mt_fs_root.node_access;
+ return SERP_ATTR(r).fileid == SERP_ATTR(me).fileid &&
+ SERP_ATTR(r).fsid == SERP_ATTR(me).fsid;
+}
+
+/* determine if a location 'l' is an NFS node */
+static inline int
+locIsNfs(rtems_filesystem_location_info_t *l)
+{
+ return l->ops == &nfs_fs_ops;
+}
+
+/* determine if two locations refer to the
+ * same entity. We know that 'nfsloc' is a
+ * location inside nfs. However, we needn't
+ * know anything about 'anyloc'.
+ */
+static inline int
+locAreEqual(
+ rtems_filesystem_location_info_t *nfsloc,
+ rtems_filesystem_location_info_t *anyloc
+)
+{
+NfsNode na = (NfsNode) nfsloc->node_access;
+NfsNode nb;
+
+ if (!locIsNfs(anyloc))
+ return 0;
+
+ nb = (NfsNode) anyloc->node_access;
+
+ if (na->nfs != nb->nfs)
+ return 0;
+
+ updateAttr(nb, 0);
+
+ return SERP_ATTR(na).fileid == SERP_ATTR(nb).fileid &&
+ SERP_ATTR(na).fsid == SERP_ATTR(nb).fsid;
+}
+
+
+
+/*****************************************
+ Global Variables
+ *****************************************/
+
+/* These are (except for MAXNAMLEN/MAXPATHLEN) copied from IMFS */
+
+static rtems_filesystem_limits_and_options_t
+nfs_limits_and_options = {
+ 5, /* link_max */
+ 6, /* max_canon */
+ 7, /* max_input */
+ NFS_MAXNAMLEN, /* name_max */
+ NFS_MAXPATHLEN, /* path_max */
+ 2, /* pipe_buf */
+ 1, /* posix_async_io */
+ 2, /* posix_chown_restrictions */
+ 3, /* posix_no_trunc */
+ 4, /* posix_prio_io */
+ 5, /* posix_sync_io */
+ 6 /* posix_vdisable */
+};
+
+/* size of an encoded 'entry' object */
+static int dirres_entry_size;
+
+/* Global stuff and statistics */
+static struct nfsstats {
+ /* A lock for protecting the
+ * linked ist of mounted NFS
+ * and the num_mounted_fs field
+ */
+ rtems_id llock;
+ /* A lock for protecting misc
+ * stuff within the driver.
+ * The lock must only be held
+ * for short periods of time.
+ */
+ rtems_id lock;
+ /* Our major number as assigned
+ * by RTEMS
+ */
+ rtems_device_major_number nfs_major;
+ /* The number of currently
+ * mounted NFS
+ */
+ int num_mounted_fs;
+ /* A list of the currently
+ * mounted NFS
+ */
+ struct NfsRec_ *mounted_fs;
+ /* A counter for allocating
+ * unique IDs to each mounted
+ * NFS.
+ * Assume we are not going to
+ * do more than 16k mounts
+ * during the system lifetime
+ */
+ u_short fs_ids;
+} nfsGlob = {0, 0, 0, 0, 0, 0};
+
+/*
+ * Global variable to tune the 'st_blksize' (stat(2)) value this nfs
+ * client should report.
+ * size on the server.
+ */
+#ifndef DEFAULT_NFS_ST_BLKSIZE
+#define DEFAULT_NFS_ST_BLKSIZE NFS_MAXDATA
+#endif
+int nfsStBlksize = DEFAULT_NFS_ST_BLKSIZE;
+
+/* Two pools of RPC transactions;
+ * One with small send buffers
+ * the other with a big one.
+ * The actual size of the small
+ * buffer is configurable (see top).
+ *
+ * Note: The RX buffers are always
+ * big
+ */
+static RpcUdpXactPool smallPool = 0;
+static RpcUdpXactPool bigPool = 0;
+
+
+/*****************************************
+ Implementation
+ *****************************************/
+
+/* Create a Nfs object. This is
+ * per-mounted NFS information.
+ *
+ * ARGS: The Nfs server handle.
+ *
+ * RETURNS: Nfs on success,
+ * NULL on failure with
+ * errno set
+ *
+ * NOTE: The submitted server
+ * object is 'owned' by
+ * this Nfs and will be
+ * destroyed by nfsDestroy()
+ */
+static Nfs
+nfsCreate(RpcUdpServer server)
+{
+Nfs rval = calloc(1,sizeof(*rval));
+
+ if (rval) {
+ rval->server = server;
+ LOCK(nfsGlob.llock);
+ rval->next = nfsGlob.mounted_fs;
+ nfsGlob.mounted_fs = rval;
+ UNLOCK(nfsGlob.llock);
+ } else {
+ errno = ENOMEM;
+ }
+ return rval;
+}
+
+/* Destroy an Nfs object and
+ * its associated server
+ */
+static void
+nfsDestroy(Nfs nfs)
+{
+register Nfs prev;
+ if (!nfs)
+ return;
+
+ LOCK(nfsGlob.llock);
+ if (nfs == nfsGlob.mounted_fs)
+ nfsGlob.mounted_fs = nfs->next;
+ else {
+ for (prev = nfsGlob.mounted_fs;
+ prev && prev->next != nfs;
+ prev = prev->next)
+ /* nothing else to do */;
+ assert( prev );
+ prev->next = nfs->next;
+ }
+ UNLOCK(nfsGlob.llock);
+
+ nfs->next = 0; /* paranoia */
+ rpcUdpServerDestroy(nfs->server);
+ free(nfs);
+}
+
+/*
+ * Create a Node. The node will
+ * be associated with a particular
+ * mounted NFS identified by 'nfs'
+ * Optionally, a NFS file handle
+ * may be copied into this node.
+ *
+ * ARGS: nfs of the NFS this node
+ * belongs to.
+ * NFS file handle identifying
+ * this node.
+ * RETURNS: node on success,
+ * NULL on failure with errno
+ * set.
+ *
+ * NOTE: The caller of this routine
+ * is responsible for copying
+ * a NFS file handle if she
+ * choses to pass a NULL fh.
+ *
+ * The driver code assumes the
+ * a node always has a valid
+ * NFS filehandle and file
+ * attributes (unless the latter
+ * are aged).
+ */
+static NfsNode
+nfsNodeCreate(Nfs nfs, fhandle *fh)
+{
+NfsNode rval = malloc(sizeof(*rval));
+unsigned long flags;
+
+#if DEBUG & DEBUG_TRACK_NODES
+ fprintf(stderr,"NFS: creating a node\n");
+#endif
+
+ if (rval) {
+ if (fh)
+ memcpy( &SERP_FILE(rval), fh, sizeof(*fh) );
+ rtems_interrupt_disable(flags);
+ nfs->nodesInUse++;
+ rtems_interrupt_enable(flags);
+ rval->nfs = nfs;
+ rval->str = 0;
+ } else {
+ errno = ENOMEM;
+ }
+
+ return rval;
+}
+
+/* destroy a node */
+static void
+nfsNodeDestroy(NfsNode node)
+{
+unsigned long flags;
+
+#if DEBUG & DEBUG_TRACK_NODES
+ fprintf(stderr,"NFS: destroying a node\n");
+#endif
+#if 0
+ if (!node)
+ return;
+ /* this probably does nothing... */
+ xdr_free(xdr_serporid, &node->serporid);
+#endif
+
+ rtems_interrupt_disable(flags);
+ node->nfs->nodesInUse--;
+#if DEBUG & DEBUG_COUNT_NODES
+ if (node->str)
+ node->nfs->stringsInUse--;
+#endif
+ rtems_interrupt_enable(flags);
+
+ if (node->str)
+ free(node->str);
+
+ free(node);
+}
+
+/* Clone a given node (AKA copy constructor),
+ * i.e. create an exact copy.
+ *
+ * ARGS: node to clone
+ * RETURNS: new node on success
+ * NULL on failure with errno set.
+ *
+ * NOTE: a string attached to 'str'
+ * is cloned as well. Outdated
+ * attributes (of the new copy
+ * only) will be refreshed
+ * (if unsuccessful, this could
+ * be a reason for failure to
+ * clone a node).
+ */
+static NfsNode
+nfsNodeClone(NfsNode node)
+{
+NfsNode rval = nfsNodeCreate(node->nfs, 0);
+
+ if (rval) {
+ *rval = *node;
+
+ /* must clone the string also */
+ if (node->str) {
+ rval->args.name = rval->str = strdup(node->str);
+ if (!rval->str) {
+ errno = ENOMEM;
+ nfsNodeDestroy(rval);
+ return 0;
+ }
+#if DEBUG & DEBUG_COUNT_NODES
+ { unsigned long flags;
+ rtems_interrupt_disable(flags);
+ node->nfs->stringsInUse++;
+ rtems_interrupt_enable(flags);
+ }
+#endif
+ }
+
+ /* possibly update the stats */
+ if (updateAttr(rval, 0 /* only if necessary */)) {
+ nfsNodeDestroy(rval);
+ return 0;
+ }
+ }
+ return rval;
+}
+
+/* Initialize the driver.
+ *
+ * ARGS: depth of the small and big
+ * transaction pools, i.e. how
+ * many transactions (buffers)
+ * should always be kept around.
+ *
+ * (If more transactions are needed,
+ * they are created and destroyed
+ * on the fly).
+ */
+void
+nfsInit(int smallPoolDepth, int bigPoolDepth)
+{
+static int initialised = 0;
+entry dummy;
+rtems_status_code status;
+
+ if (initialised)
+ return;
+
+ initialised = 1;
+
+ fprintf(stderr,
+ "RTEMS-NFS $Release$, " \
+ "Till Straumann, Stanford/SLAC/SSRL 2002, " \
+ "See LICENSE file for licensing info.\n");
+
+ /* Get a major number */
+
+ if (RTEMS_SUCCESSFUL != rtems_io_register_driver(0, &drvNfs, &nfsGlob.nfs_major)) {
+ fprintf(stderr,"Registering NFS driver failed - %s\n", strerror(errno));
+ return;
+ }
+
+ if (0==smallPoolDepth)
+ smallPoolDepth = 20;
+ if (0==bigPoolDepth)
+ bigPoolDepth = 10;
+
+ /* it's crucial to zero out the 'next' pointer
+ * because it terminates the xdr_entry recursion
+ *
+ * we also must make the filename some non-zero
+ * char pointer!
+ */
+
+ memset(&dummy, 0, sizeof(dummy));
+
+ dummy.nextentry = 0;
+ dummy.name = "somename"; /* guess average length of a filename */
+ dirres_entry_size = xdr_sizeof((xdrproc_t)xdr_entry, &dummy);
+
+ smallPool = rpcUdpXactPoolCreate(
+ NFS_PROGRAM,
+ NFS_VERSION_2,
+ CONFIG_NFS_SMALL_XACT_SIZE,
+ smallPoolDepth);
+ assert( smallPool );
+
+ bigPool = rpcUdpXactPoolCreate(
+ NFS_PROGRAM,
+ NFS_VERSION_2,
+ CONFIG_NFS_BIG_XACT_SIZE,
+ bigPoolDepth);
+ assert( bigPool );
+
+ status = rtems_semaphore_create(
+ rtems_build_name('N','F','S','l'),
+ 1,
+ MUTEX_ATTRIBUTES,
+ 0,
+ &nfsGlob.llock);
+ assert( status == RTEMS_SUCCESSFUL );
+ status = rtems_semaphore_create(
+ rtems_build_name('N','F','S','m'),
+ 1,
+ MUTEX_ATTRIBUTES,
+ 0,
+ &nfsGlob.lock);
+ assert( status == RTEMS_SUCCESSFUL );
+
+ if (sizeof(ino_t) < sizeof(u_int)) {
+ fprintf(stderr,
+ "WARNING: Using 'short st_ino' hits performance and may fail to access/find correct files\n");
+ fprintf(stderr,
+ "you should fix newlib's sys/stat.h - for now I'll enable a hack...\n");
+
+ }
+}
+
+/* Driver cleanup code
+ */
+int
+nfsCleanup(void)
+{
+rtems_id l;
+int refuse;
+
+ if (!nfsGlob.llock) {
+ /* registering the driver failed - let them still cleanup */
+ return 0;
+ }
+
+ LOCK(nfsGlob.llock);
+ if ( (refuse = nfsGlob.num_mounted_fs) ) {
+ fprintf(stderr,"Refuse to unload NFS; %i filesystems still mounted.\n",
+ refuse);
+ nfsMountsShow(stderr);
+ /* yes, printing is slow - but since you try to unload the driver,
+ * you assume nobody is using NFS, so what if they have to wait?
+ */
+ UNLOCK(nfsGlob.llock);
+ return -1;
+ }
+
+ rtems_semaphore_delete(nfsGlob.lock);
+ nfsGlob.lock = 0;
+
+ /* hold the lock while cleaning up... */
+
+ rpcUdpXactPoolDestroy(smallPool);
+ rpcUdpXactPoolDestroy(bigPool);
+ l = nfsGlob.llock;
+ rtems_io_unregister_driver(nfsGlob.nfs_major);
+
+ rtems_semaphore_delete(l);
+ nfsGlob.llock = 0;
+ return 0;
+}
+
+/* NFS RPC wrapper.
+ *
+ * ARGS: srvr the NFS server we want to call
+ * proc the NFSPROC_xx we want to invoke
+ * xargs xdr routine to wrap the arguments
+ * pargs pointer to the argument object
+ * xres xdr routine to unwrap the results
+ * pres pointer to the result object
+ *
+ * RETURNS: 0 on success, -1 on error with errno set.
+ *
+ * NOTE: the caller assumes that errno is set to
+ * a nonzero value if this routine returns
+ * an error (nonzero return value).
+ *
+ * This routine prints RPC error messages to
+ * stderr.
+ */
+STATIC int
+nfscall(
+ RpcUdpServer srvr,
+ int proc,
+ xdrproc_t xargs,
+ void * pargs,
+ xdrproc_t xres,
+ void * pres)
+{
+RpcUdpXact xact;
+enum clnt_stat stat;
+RpcUdpXactPool pool;
+int rval = -1;
+
+
+ switch (proc) {
+ case NFSPROC_SYMLINK:
+ case NFSPROC_WRITE:
+ pool = bigPool; break;
+ default: pool = smallPool; break;
+ }
+
+ xact = rpcUdpXactPoolGet(pool, XactGetCreate);
+
+ if ( !xact ) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ if ( RPC_SUCCESS != (stat=rpcUdpSend(
+ xact,
+ srvr,
+ NFSCALL_TIMEOUT,
+ proc,
+ xres,
+ pres,
+ xargs,
+ pargs,
+ 0)) ||
+ RPC_SUCCESS != (stat=rpcUdpRcv(xact)) ) {
+
+ fprintf(stderr,
+ "NFS (proc %i) - %s\n",
+ proc,
+ clnt_sperrno(stat));
+
+ switch (stat) {
+ /* TODO: this is probably not complete and/or fully accurate */
+ case RPC_CANTENCODEARGS : errno = EINVAL; break;
+ case RPC_AUTHERROR : errno = EPERM; break;
+
+ case RPC_CANTSEND :
+ case RPC_CANTRECV : /* hope they have errno set */
+ case RPC_SYSTEMERROR : break;
+
+ default : errno = EIO; break;
+ }
+ } else {
+ rval = 0;
+ }
+
+ /* release the transaction back into the pool */
+ rpcUdpXactPoolPut(xact);
+
+ if (rval && !errno)
+ errno = EIO;
+
+ return rval;
+}
+
+/* Check the 'age' of a node's stats
+ * and read the attributes from the server
+ * if necessary.
+ *
+ * ARGS: node node to update
+ * force enforce updating ignoring
+ * the timestamp/age
+ *
+ * RETURNS: 0 on success,
+ * -1 on failure with errno set
+ */
+
+static int
+updateAttr(NfsNode node, int force)
+{
+
+ if (force
+#ifdef CONFIG_ATTR_LIFETIME
+ || (nowSeconds() - node->age > CONFIG_ATTR_LIFETIME)
+#endif
+ ) {
+ if ( nfscall(node->nfs->server,
+ NFSPROC_GETATTR,
+ (xdrproc_t)xdr_nfs_fh, &SERP_FILE(node),
+ (xdrproc_t)xdr_attrstat, &node->serporid) )
+ return -1;
+
+ if ( NFS_OK != node->serporid.status ) {
+ errno = node->serporid.status;
+ return -1;
+ }
+
+ node->age = nowSeconds();
+ }
+
+ return 0;
+}
+
+/*
+ * IP address helper.
+ *
+ * initialize a sockaddr_in from a
+ * [<uid>'.'<gid>'@']<host>':'<path>" string and let
+ * pPath point to the <path> part; retrieve the optional
+ * uid/gids
+ *
+ * ARGS: see description above
+ *
+ * RETURNS: 0 on success,
+ * -1 on failure with errno set
+ */
+static int
+buildIpAddr(u_long *puid, u_long *pgid,
+ char **pHost, struct sockaddr_in *psa,
+ char **pPath)
+{
+struct hostent *h;
+char host[64];
+char *chpt = *pPath;
+char *path;
+int len;
+
+ if ( !chpt ) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* look for the optional uid/gid */
+ if ( (chpt = strchr(chpt, UIDSEP)) ) {
+ if ( 2 != sscanf(*pPath,"%li.%li",puid,pgid) ) {
+ errno = EINVAL;
+ return -1;
+ }
+ chpt++;
+ } else {
+ *puid = RPCIOD_DEFAULT_ID;
+ *pgid = RPCIOD_DEFAULT_ID;
+ chpt = *pPath;
+ }
+ if ( pHost )
+ *pHost = chpt;
+
+ /* split the device name which is in the form
+ *
+ * <host> ':' <path>
+ *
+ * into its components using a local buffer
+ */
+
+ if ( !(path = strchr(chpt, HOSTDELIM)) ||
+ (len = path - chpt) >= sizeof(host) - 1 ) {
+ errno = EINVAL;
+ return -1;
+ }
+ /* point to path beyond ':' */
+ path++;
+
+ strncpy(host, chpt, len);
+ host[len]=0;
+
+ /* BEGIN OF NON-THREAD SAFE REGION */
+
+ h = gethostbyname(host);
+
+ if ( !h ) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ memcpy(&psa->sin_addr, h->h_addr, sizeof (struct in_addr));
+
+ /* END OF NON-THREAD SAFE REGION */
+
+ psa->sin_family = AF_INET;
+ psa->sin_port = 0;
+ *pPath = path;
+ return 0;
+}
+
+/* wrapper similar to nfscall.
+ * However, since it is not used
+ * very often, the simpler and less
+ * efficient rpcUdpCallRp API is used.
+ *
+ * ARGS: see 'nfscall()' above
+ *
+ * RETURNS: RPC status
+ */
+static enum clnt_stat
+mntcall(
+ struct sockaddr_in *psrvr,
+ int proc,
+ xdrproc_t xargs,
+ void * pargs,
+ xdrproc_t xres,
+ void * pres,
+ u_long uid,
+ u_long gid)
+{
+#ifdef MOUNT_V1_PORT
+int retry;
+#endif
+enum clnt_stat stat = RPC_FAILED;
+
+#ifdef MOUNT_V1_PORT
+ /* if the portmapper fails, retry a fixed port */
+ for (retry = 1, psrvr->sin_port = 0, stat = RPC_FAILED;
+ retry >= 0 && stat;
+ stat && (psrvr->sin_port = htons(MOUNT_V1_PORT)), retry-- )
+#endif
+ stat = rpcUdpCallRp(
+ psrvr,
+ MOUNTPROG,
+ MOUNTVERS,
+ proc,
+ xargs,
+ pargs,
+ xres,
+ pres,
+ uid,
+ gid,
+ MNTCALL_TIMEOUT
+ );
+ return stat;
+}
+
+/*****************************************
+ RTEMS File System Operations for NFS
+ *****************************************/
+
+#if 0 /* for reference */
+
+struct rtems_filesystem_location_info_tt
+{
+ void *node_access;
+ rtems_filesystem_file_handlers_r *handlers;
+ rtems_filesystem_operations_table *ops;
+ rtems_filesystem_mount_table_entry_t *mt_entry;
+};
+
+#endif
+
+/*
+ * Evaluate a path letting 'pathloc' travel along.
+ *
+ * The important semantics of this operation are:
+ *
+ * If this routine returns -1, the caller assumes
+ * pathloc to be _invalid_ and hence it will not
+ * invoke rtems_filesystem_freenode() on it.
+ *
+ * OTOH, if evalpath returns 0,
+ * rtems_filesystem_freenode() will eventually be
+ * called which results in our freeing the associated
+ * NfsNode attached to node_access.
+ *
+ * Therefore, this routine will _always_ allocate
+ * a NfsNode and pass it out to *pathloc (provided
+ * that the evaluation succeeds).
+ *
+ * However, if the evaluation finds that it has to
+ * step across FS boundaries (mount point or a symlink
+ * pointing outside), the NfsNode is destroyed
+ * before passing control to the new FS' evalpath_h()
+ *
+ */
+
+union nfs_evalpath_arg {
+ int i;
+ const char **c;
+ };
+
+STATIC int nfs_do_evalpath(
+ const char *pathname, /* IN */
+ int pathnamelen, /* IN */
+ union nfs_evalpath_arg *arg,
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ int forMake
+)
+{
+char *del = 0, *part;
+int e = 0;
+NfsNode node = pathloc->node_access;
+char *p = malloc(MAXPATHLEN+1);
+Nfs nfs = (Nfs)pathloc->mt_entry->fs_info;
+RpcUdpServer server = nfs->server;
+unsigned long flags;
+#if DEBUG & DEBUG_COUNT_NODES
+unsigned long niu,siu;
+#endif
+
+ if ( !p ) {
+ e = ENOMEM;
+ goto cleanup;
+ }
+ memset(p, 0, MAXPATHLEN+1);
+ memcpy(p, pathname, pathnamelen);
+
+ LOCK(nfsGlob.lock);
+ node = nfsNodeClone(node);
+ UNLOCK(nfsGlob.lock);
+
+ /* from here on, the NFS is protected from being unmounted
+ * since the node refcount is > 1
+ */
+
+ /* clone the node */
+ if ( !node ) {
+ /* nodeClone sets errno */
+ pathloc->node_access = 0;
+ if ( ! (e = errno) ) {
+ /* if we have no node, e must not be zero! */
+ e = ENOMEM;
+ }
+ goto cleanup;
+ }
+
+ pathloc->node_access = node;
+
+ /* Special case: the RTEMS filesystem code
+ * may emit '..' on a regular file node to
+ * find the parent directory :-(.
+ * (eval.c: rtems_filesystem_evaluate_parent())
+ * Try to catch this case here:
+ */
+ if ( NFDIR != SERP_ATTR(node).type && '.'==*p && '.'==*(p+1) ) {
+ for ( part = p+2; '/'==*part; part++ )
+ /* skip trailing '/' */;
+ if ( !*part ) {
+ /* this is it; back out dir and let them look up the dir itself... */
+ memcpy( &SERP_FILE(node),
+ &node->args.dir,
+ sizeof(node->args.dir));
+ *(p+1)=0;
+ }
+ }
+
+ for (part=p; part && *part; part=del) {
+
+ if ( NFLNK == SERP_ATTR(node).type ) {
+ /* follow midpath link */
+ char *b = malloc(NFS_MAXPATHLEN+1);
+ int l;
+
+ if (!b) {
+ e = ENOMEM;
+ goto cleanup;
+ }
+ if (nfs_readlink(pathloc, b, NFS_MAXPATHLEN+1)) {
+ free(b);
+ e = errno;
+ goto cleanup;
+ }
+
+ /* prepend the link value to the rest of the path */
+ if ( (l=strlen(b)) + strlen(part) + 1 > NFS_MAXPATHLEN ) {
+ free(b);
+ e = EINVAL;
+ goto cleanup;
+ }
+ /* swap string buffers and reset delimiter */
+ b[l++] = DELIM;
+ strcpy(b+l,part);
+ part = b;
+ b = p;
+ p = del = part;
+
+ free(b);
+
+ /* back up the directory filehandle (only necessary
+ * if we don't back out to the root
+ */
+ if (! (DELIM == *part) ) {
+ memcpy( &SERP_FILE(node),
+ &node->args.dir,
+ sizeof(node->args.dir));
+
+ if (updateAttr(node, 1 /* force */)) {
+ e = errno;
+ goto cleanup;
+ }
+ }
+ }
+
+ /* find delimiter and eat /// sequences
+ * (only if we don't restart at the root)
+ */
+ if ( DELIM != *part && (del = strchr(part, DELIM))) {
+ do {
+ *del++=0;
+ } while (DELIM==*del);
+ }
+
+ /* refuse to backup over the root */
+ if ( 0==strcmp(part,UPDIR)
+ && locAreEqual(pathloc, &rtems_filesystem_root) ) {
+ part++;
+ }
+
+ /* cross mountpoint upwards */
+ if ( (0==strcmp(part,UPDIR) && locIsRoot(pathloc)) /* cross mountpoint up */
+ || DELIM == *part /* link starts at root */
+ ) {
+ int rval;
+
+#if DEBUG & DEBUG_EVALPATH
+ fprintf(stderr,
+ "Crossing mountpoint upwards\n");
+#endif
+
+ if (DELIM == *part) {
+ *pathloc = rtems_filesystem_root;
+ } else {
+ *pathloc = pathloc->mt_entry->mt_point_node;
+ /* re-append the rest of the path */
+ if (del)
+ while ( 0 == *--del )
+ *del = DELIM;
+ }
+
+ nfsNodeDestroy(node);
+
+#if DEBUG & DEBUG_EVALPATH
+ fprintf(stderr,
+ "Re-evaluating '%s'\n",
+ part);
+#endif
+
+ if (forMake)
+ rval = pathloc->ops->evalformake_h(part, pathloc, arg->c);
+ else
+ rval = pathloc->ops->evalpath_h(part, strlen(part), arg->i, pathloc);
+
+ free(p);
+ return rval;
+ }
+
+ /* lookup one element */
+ SERP_ARGS(node).diroparg.name = part;
+
+ /* remember args / directory fh */
+ memcpy( &node->args, &SERP_FILE(node), sizeof(node->args));
+
+ /* don't lookup the item we want to create */
+ if ( forMake && (!del || !*del) )
+ break;
+
+#if DEBUG & DEBUG_EVALPATH
+ fprintf(stderr,"Looking up '%s'\n",part);
+#endif
+
+ if ( nfscall(server,
+ NFSPROC_LOOKUP,
+ (xdrproc_t)xdr_diropargs, &SERP_FILE(node),
+ (xdrproc_t)xdr_serporid, &node->serporid) ||
+ NFS_OK != (errno=node->serporid.status) ) {
+ e = errno;
+ goto cleanup;
+ }
+ node->age = nowSeconds();
+
+#if DEBUG & DEBUG_EVALPATH
+ if (NFLNK == SERP_ATTR(node).type && del) {
+ fprintf(stderr,
+ "Following midpath link '%s'\n",
+ part);
+ }
+#endif
+
+ }
+
+ if (forMake) {
+ /* remember the name - do this _before_ copying
+ * the name to local storage; the caller expects a
+ * pointer into pathloc
+ */
+ assert( node->args.name );
+
+ *(const char**)arg = pathname + (node->args.name - p);
+
+#if 0
+ /* restore the directory node */
+
+ memcpy( &SERP_FILE(node),
+ &node->args.dir,
+ sizeof(node->args.dir));
+
+ if ( (nfscall(nfs->server,
+ NFSPROC_GETATTR,
+ (xdrproc_t)xdr_nfs_fh, &SERP_FILE(node),
+ (xdrproc_t)xdr_attrstat, &node->serporid) && !errno && (errno = EIO)) ||
+ (NFS_OK != (errno=node->serporid.status) ) ) {
+ goto cleanup;
+ }
+#endif
+ }
+
+ if (locIsRoot(pathloc)) {
+
+ /* stupid filesystem code has no 'op' for comparing nodes
+ * but just compares the 'node_access' pointers.
+ * Luckily, this is only done for comparing the root nodes.
+ * Hence, we never give them a copy of the root but always
+ * the root itself.
+ */
+ pathloc->node_access = pathloc->mt_entry->mt_fs_root.node_access;
+ /* increment the 'in use' counter since we return one more
+ * reference to the root node
+ */
+ rtems_interrupt_disable(flags);
+ nfs->nodesInUse++;
+ rtems_interrupt_enable(flags);
+ nfsNodeDestroy(node);
+
+
+ } else {
+ switch (SERP_ATTR(node).type) {
+ case NFDIR: pathloc->handlers = &nfs_dir_file_handlers; break;
+ case NFREG: pathloc->handlers = &nfs_file_file_handlers; break;
+ case NFLNK: pathloc->handlers = &nfs_link_file_handlers; break;
+ default: pathloc->handlers = &rtems_filesystem_handlers_default; break;
+ }
+ pathloc->node_access = node;
+
+ /* remember the name of this directory entry */
+
+ if (node->args.name) {
+ if (node->str) {
+#if DEBUG & DEBUG_COUNT_NODES
+ rtems_interrupt_disable(flags);
+ nfs->stringsInUse--;
+ rtems_interrupt_enable(flags);
+#endif
+ free(node->str);
+ }
+ node->args.name = node->str = strdup(node->args.name);
+ if (!node->str) {
+ e = ENOMEM;
+ goto cleanup;
+ }
+
+#if DEBUG & DEBUG_COUNT_NODES
+ rtems_interrupt_disable(flags);
+ nfs->stringsInUse++;
+ rtems_interrupt_enable(flags);
+#endif
+ }
+
+ }
+ node = 0;
+
+ e = 0;
+
+cleanup:
+ free(p);
+#if DEBUG & DEBUG_COUNT_NODES
+ /* cache counters; nfs may be unmounted by other thread after the last
+ * node is destroyed
+ */
+ niu = nfs->nodesInUse;
+ siu = nfs->stringsInUse;
+#endif
+ if (node) {
+ nfsNodeDestroy(node);
+ pathloc->node_access = 0;
+ }
+#if DEBUG & DEBUG_COUNT_NODES
+ fprintf(stderr,
+ "leaving evalpath, in use count is %i nodes, %i strings\n",
+ niu,siu);
+#endif
+ if (e) {
+#if DEBUG & DEBUG_EVALPATH
+ perror("Evalpath");
+#endif
+ rtems_set_errno_and_return_minus_one(e);
+ } else {
+ return 0;
+ }
+}
+
+/* MANDATORY; may set errno=ENOSYS and return -1 */
+static int nfs_evalformake(
+ const char *path, /* IN */
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ const char **pname /* OUT */
+)
+{
+ union nfs_evalpath_arg args;
+ args.c = pname;
+
+ return nfs_do_evalpath(path, strlen(path), &args, pathloc, 1 /*forMake*/);
+}
+
+static int nfs_evalpath(
+ const char *path, /* IN */
+ size_t pathlen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+)
+{
+ union nfs_evalpath_arg args;
+ args.i = flags;
+ return nfs_do_evalpath(path, pathlen, &args, pathloc, 0 /*not forMake*/);
+}
+
+
+/* create a hard link */
+
+static int nfs_link(
+ rtems_filesystem_location_info_t *to_loc, /* IN */
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ const char *name /* IN */
+)
+{
+NfsNode pNode;
+nfsstat status;
+NfsNode tNode = to_loc->node_access;
+
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,"Creating link '%s'\n",name);
+#endif
+
+ if ( !locIsNfs(parent_loc) ) {
+ errno = EXDEV;
+ return -1;
+ }
+
+ pNode = parent_loc->node_access;
+ if ( tNode->nfs != pNode->nfs ) {
+ errno = EXDEV;
+ return -1;
+ }
+ memcpy(&SERP_ARGS(tNode).linkarg.to.dir,
+ &SERP_FILE(pNode),
+ sizeof(SERP_FILE(pNode)));
+
+ SERP_ARGS(tNode).linkarg.to.name = (filename)name;
+
+ if ( nfscall(tNode->nfs->server,
+ NFSPROC_LINK,
+ (xdrproc_t)xdr_linkargs, &SERP_FILE(tNode),
+ (xdrproc_t)xdr_nfsstat, &status)
+ || (NFS_OK != (errno = status))
+ ) {
+#if DEBUG & DEBUG_SYSCALLS
+ perror("nfs_link");
+#endif
+ return -1;
+ }
+
+ return 0;
+
+}
+
+static int nfs_do_unlink(
+ rtems_filesystem_location_info_t *parent_loc,/* IN */
+ rtems_filesystem_location_info_t *loc, /* IN */
+ int proc
+)
+{
+nfsstat status;
+NfsNode node = loc->node_access;
+Nfs nfs = node->nfs;
+#if DEBUG & DEBUG_SYSCALLS
+char *name = NFSPROC_REMOVE == proc ?
+ "nfs_unlink" : "nfs_rmdir";
+#endif
+
+ /* The FS generics have determined that pathloc is _not_
+ * a directory. Hence we may assume that the parent
+ * is in our NFS.
+ */
+
+#if DEBUG & DEBUG_SYSCALLS
+ assert( node->args.name == node->str && node->str );
+
+ fprintf(stderr,"%s '%s'\n", name, node->args.name);
+#endif
+
+ if ( nfscall(nfs->server,
+ proc,
+ (xdrproc_t)xdr_diropargs, &node->args,
+ (xdrproc_t)xdr_nfsstat, &status)
+ || (NFS_OK != (errno = status))
+ ) {
+#if DEBUG & DEBUG_SYSCALLS
+ perror(name);
+#endif
+ return -1;
+ }
+
+ return 0;
+}
+
+static int nfs_unlink(
+ rtems_filesystem_location_info_t *parent_loc, /* IN */
+ rtems_filesystem_location_info_t *loc /* IN */
+)
+{
+ return nfs_do_unlink(parent_loc, loc, NFSPROC_REMOVE);
+}
+
+static int nfs_chown(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ uid_t owner, /* IN */
+ gid_t group /* IN */
+)
+{
+sattr arg;
+
+ arg.uid = owner;
+ arg.gid = group;
+
+ return nfs_sattr(pathloc->node_access, &arg, SATTR_UID | SATTR_GID);
+
+}
+
+/* Cleanup the FS private info attached to pathloc->node_access */
+static int nfs_freenode(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+Nfs nfs = ((NfsNode)pathloc->node_access)->nfs;
+
+#if DEBUG & DEBUG_COUNT_NODES
+ /* print counts at entry where they are > 0 so 'nfs' is safe from being destroyed
+ * and there's no race condition
+ */
+ fprintf(stderr,
+ "entering freenode, in use count is %i nodes, %i strings\n",
+ nfs->nodesInUse,
+ nfs->stringsInUse);
+#endif
+
+ /* never destroy the root node; it is released by the unmount
+ * code
+ */
+ if (locIsRoot(pathloc)) {
+ unsigned long flags;
+ /* just adjust the references to the root node but
+ * don't really release it
+ */
+ rtems_interrupt_disable(flags);
+ nfs->nodesInUse--;
+ rtems_interrupt_enable(flags);
+ } else {
+ nfsNodeDestroy(pathloc->node_access);
+ pathloc->node_access = 0;
+ }
+ return 0;
+}
+
+/* NOTE/TODO: mounting on top of NFS is not currently supported
+ *
+ * Challenge: stateless protocol. It would be possible to
+ * delete mount points on the server. We would need some sort
+ * of a 'garbage collector' looking for dead/unreachable
+ * mount points and unmounting them.
+ * Also, the path evaluation routine would have to check
+ * for crossing mount points. Crossing over from one NFS
+ * into another NFS could probably handled iteratively
+ * rather than by recursion.
+ */
+
+int rtems_nfs_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+)
+{
+char *host;
+struct sockaddr_in saddr;
+enum clnt_stat stat;
+fhstatus fhstat;
+u_long uid,gid;
+#ifdef NFS_V2_PORT
+int retry;
+#endif
+Nfs nfs = 0;
+NfsNode rootNode = 0;
+RpcUdpServer nfsServer = 0;
+int e = -1;
+char *path = mt_entry->dev;
+
+ if (rpcUdpInit () < 0) {
+ fprintf (stderr, "error: initialising RPC\n");
+ return -1;
+ }
+
+ nfsInit(0, 0);
+
+#if 0
+ printf("Trying to mount %s on %s\n",path,mntpoint);
+#endif
+
+ if ( buildIpAddr(&uid, &gid, &host, &saddr, &path) )
+ return -1;
+
+#ifdef NFS_V2_PORT
+ /* if the portmapper fails, retry a fixed port */
+ for (retry = 1, saddr.sin_port = 0, stat = RPC_FAILED;
+ retry >= 0 && stat;
+ stat && (saddr.sin_port = htons(NFS_V2_PORT)), retry-- )
+#endif
+ stat = rpcUdpServerCreate(
+ &saddr,
+ NFS_PROGRAM,
+ NFS_VERSION_2,
+ uid,
+ gid,
+ &nfsServer
+ );
+
+ if ( RPC_SUCCESS != stat ) {
+ fprintf(stderr,
+ "Unable to contact NFS server - invalid port? (%s)\n",
+ clnt_sperrno(stat));
+ e = EPROTONOSUPPORT;
+ goto cleanup;
+ }
+
+
+ /* first, try to ping the NFS server by
+ * calling the NULL proc.
+ */
+ if ( nfscall(nfsServer,
+ NFSPROC_NULL,
+ (xdrproc_t)xdr_void, 0,
+ (xdrproc_t)xdr_void, 0) ) {
+
+ fputs("NFS Ping ",stderr);
+ fwrite(host, 1, path-host-1, stderr);
+ fprintf(stderr," failed: %s\n", strerror(errno));
+
+ e = errno ? errno : EIO;
+ goto cleanup;
+ }
+
+ /* that seemed to work - we now try the
+ * actual mount
+ */
+
+ /* reuse server address but let the mntcall()
+ * search for the mountd's port
+ */
+ saddr.sin_port = 0;
+
+ stat = mntcall( &saddr,
+ MOUNTPROC_MNT,
+ (xdrproc_t)xdr_dirpath,
+ &path,
+ (xdrproc_t)xdr_fhstatus,
+ &fhstat,
+ uid,
+ gid );
+
+ if (stat) {
+ fprintf(stderr,"MOUNT -- %s\n",clnt_sperrno(stat));
+ if ( e<=0 )
+ e = EIO;
+ goto cleanup;
+ } else if (NFS_OK != (e=fhstat.fhs_status)) {
+ fprintf(stderr,"MOUNT: %s\n",strerror(e));
+ goto cleanup;
+ }
+
+ nfs = nfsCreate(nfsServer);
+ assert( nfs );
+ nfsServer = 0;
+
+ nfs->uid = uid;
+ nfs->gid = gid;
+
+ /* that seemed to work - we now create the root node
+ * and we also must obtain the root node attributes
+ */
+ rootNode = nfsNodeCreate(nfs, &fhstat.fhstatus_u.fhs_fhandle);
+ assert( rootNode );
+
+ if ( updateAttr(rootNode, 1 /* force */) ) {
+ e = errno;
+ goto cleanup;
+ }
+
+ /* looks good so far */
+
+ mt_entry->mt_fs_root.node_access = rootNode;
+
+ rootNode = 0;
+
+ mt_entry->mt_fs_root.ops = &nfs_fs_ops;
+ mt_entry->mt_fs_root.handlers = &nfs_dir_file_handlers;
+ mt_entry->pathconf_limits_and_options = nfs_limits_and_options;
+
+ LOCK(nfsGlob.llock);
+ nfsGlob.num_mounted_fs++;
+ /* allocate a new ID for this FS */
+ nfs->id = nfsGlob.fs_ids++;
+ UNLOCK(nfsGlob.llock);
+
+ mt_entry->fs_info = nfs;
+ nfs->mt_entry = mt_entry;
+ nfs = 0;
+
+ e = 0;
+
+cleanup:
+ if (nfs)
+ nfsDestroy(nfs);
+ if (nfsServer)
+ rpcUdpServerDestroy(nfsServer);
+ if (rootNode)
+ nfsNodeDestroy(rootNode);
+ if (e)
+ rtems_set_errno_and_return_minus_one(e);
+ else
+ return 0;
+}
+
+/* This op is called when they try to unmount THIS fs */
+STATIC int nfs_fsunmount_me(
+ rtems_filesystem_mount_table_entry_t *mt_entry /* in */
+)
+{
+enum clnt_stat stat;
+struct sockaddr_in saddr;
+char *path = mt_entry->dev;
+int nodesInUse;
+u_long uid,gid;
+int status;
+
+LOCK(nfsGlob.llock);
+ nodesInUse = ((Nfs)mt_entry->fs_info)->nodesInUse;
+
+ if (nodesInUse > 1 /* one ref to the root node used by us */) {
+ UNLOCK(nfsGlob.llock);
+ fprintf(stderr,
+ "Refuse to unmount; there are still %i nodes in use (1 used by us)\n",
+ nodesInUse);
+ rtems_set_errno_and_return_minus_one(EBUSY);
+ }
+
+ status = buildIpAddr(&uid, &gid, 0, &saddr, &path);
+ assert( !status );
+
+ stat = mntcall( &saddr,
+ MOUNTPROC_UMNT,
+ (xdrproc_t)xdr_dirpath, &path,
+ (xdrproc_t)xdr_void, 0,
+ uid,
+ gid
+ );
+
+ if (stat) {
+ UNLOCK(nfsGlob.llock);
+ fprintf(stderr,"NFS UMOUNT -- %s\n", clnt_sperrno(stat));
+ errno = EIO;
+ return -1;
+ }
+
+ nfsNodeDestroy(mt_entry->mt_fs_root.node_access);
+ mt_entry->mt_fs_root.node_access = 0;
+
+ nfsDestroy(mt_entry->fs_info);
+ mt_entry->fs_info = 0;
+
+ nfsGlob.num_mounted_fs--;
+UNLOCK(nfsGlob.llock);
+
+ return 0;
+}
+
+/* OPTIONAL; may be NULL - BUT: CAUTION; mount() doesn't check
+ * for this handler to be present - a fs bug
+ * //NOTE: (10/25/2002) patch submitted and probably applied
+ */
+static rtems_filesystem_node_types_t nfs_node_type(
+ rtems_filesystem_location_info_t *pathloc /* in */
+)
+{
+NfsNode node = pathloc->node_access;
+
+ if (updateAttr(node, 0 /* only if old */))
+ return -1;
+
+ switch( SERP_ATTR(node).type ) {
+ default:
+ /* rtems has no value for 'unknown';
+ */
+ case NFNON:
+ case NFSOCK:
+ case NFBAD:
+ case NFFIFO:
+ break;
+
+
+ case NFREG: return RTEMS_FILESYSTEM_MEMORY_FILE;
+ case NFDIR: return RTEMS_FILESYSTEM_DIRECTORY;
+
+ case NFBLK:
+ case NFCHR: return RTEMS_FILESYSTEM_DEVICE;
+
+ case NFLNK: return RTEMS_FILESYSTEM_SYM_LINK;
+ }
+ return -1;
+}
+
+static int nfs_mknod(
+ const char *path, /* IN */
+ mode_t mode, /* IN */
+ dev_t dev, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+)
+{
+
+struct timeval now;
+diropres res;
+NfsNode node = pathloc->node_access;
+mode_t type = S_IFMT & mode;
+
+ if (type != S_IFDIR && type != S_IFREG)
+ rtems_set_errno_and_return_minus_one(ENOTSUP);
+
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,"nfs_mknod: creating %s\n", path);
+#endif
+
+ rtems_clock_get_tod_timeval(&now);
+
+ SERP_ARGS(node).createarg.name = (filename)path;
+ SERP_ARGS(node).createarg.attributes.mode = mode;
+ /* TODO: either use our uid or use the Nfs credentials */
+ SERP_ARGS(node).createarg.attributes.uid = 0;
+ SERP_ARGS(node).createarg.attributes.gid = 0;
+ SERP_ARGS(node).createarg.attributes.size = 0;
+ SERP_ARGS(node).createarg.attributes.atime.seconds = now.tv_sec;
+ SERP_ARGS(node).createarg.attributes.atime.useconds = now.tv_usec;
+ SERP_ARGS(node).createarg.attributes.mtime.seconds = now.tv_sec;
+ SERP_ARGS(node).createarg.attributes.mtime.useconds = now.tv_usec;
+
+ if ( nfscall( node->nfs->server,
+ NFSPROC_CREATE,
+ (xdrproc_t)xdr_createargs, &SERP_FILE(node),
+ (xdrproc_t)xdr_diropres, &res)
+ || (NFS_OK != (errno = res.status)) ) {
+#if DEBUG & DEBUG_SYSCALLS
+ perror("nfs_mknod");
+#endif
+ return -1;
+ }
+
+ return 0;
+}
+
+static int nfs_utime(
+ rtems_filesystem_location_info_t *pathloc, /* IN */
+ time_t actime, /* IN */
+ time_t modtime /* IN */
+)
+{
+sattr arg;
+
+ /* TODO: add rtems EPOCH - UNIX EPOCH seconds */
+ arg.atime.seconds = actime;
+ arg.atime.useconds = 0;
+ arg.mtime.seconds = modtime;
+ arg.mtime.useconds = 0;
+
+ return nfs_sattr(pathloc->node_access, &arg, SATTR_ATIME | SATTR_MTIME);
+}
+
+static int nfs_symlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ const char *link_name, /* IN */
+ const char *node_name
+)
+{
+struct timeval now;
+nfsstat status;
+NfsNode node = loc->node_access;
+
+
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,"nfs_symlink: creating %s -> %s\n", link_name, node_name);
+#endif
+
+ rtems_clock_get_tod_timeval(&now);
+
+ SERP_ARGS(node).symlinkarg.name = (filename)link_name;
+ SERP_ARGS(node).symlinkarg.to = (nfspath) node_name;
+
+ SERP_ARGS(node).symlinkarg.attributes.mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
+ /* TODO */
+ SERP_ARGS(node).symlinkarg.attributes.uid = 0;
+ SERP_ARGS(node).symlinkarg.attributes.gid = 0;
+ SERP_ARGS(node).symlinkarg.attributes.size = 0;
+ SERP_ARGS(node).symlinkarg.attributes.atime.seconds = now.tv_sec;
+ SERP_ARGS(node).symlinkarg.attributes.atime.useconds = now.tv_usec;
+ SERP_ARGS(node).symlinkarg.attributes.mtime.seconds = now.tv_sec;
+ SERP_ARGS(node).symlinkarg.attributes.mtime.useconds = now.tv_usec;
+
+ if ( nfscall( node->nfs->server,
+ NFSPROC_SYMLINK,
+ (xdrproc_t)xdr_symlinkargs, &SERP_FILE(node),
+ (xdrproc_t)xdr_nfsstat, &status)
+ || (NFS_OK != (errno = status)) ) {
+#if DEBUG & DEBUG_SYSCALLS
+ perror("nfs_symlink");
+#endif
+ return -1;
+ }
+
+ return 0;
+}
+
+static int nfs_do_readlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ strbuf *psbuf /* IN/OUT */
+)
+{
+NfsNode node = loc->node_access;
+Nfs nfs = node->nfs;
+readlinkres_strbuf rr;
+int wasAlloced;
+int rval;
+
+ rr.strbuf = *psbuf;
+
+ wasAlloced = (0 == psbuf->buf);
+
+ if ( (rval = nfscall(nfs->server,
+ NFSPROC_READLINK,
+ (xdrproc_t)xdr_nfs_fh, &SERP_FILE(node),
+ (xdrproc_t)xdr_readlinkres_strbuf, &rr)) ) {
+ if (wasAlloced)
+ xdr_free( (xdrproc_t)xdr_strbuf, (caddr_t)&rr.strbuf );
+ }
+
+
+ if (NFS_OK != rr.status) {
+ if (wasAlloced)
+ xdr_free( (xdrproc_t)xdr_strbuf, (caddr_t)&rr.strbuf );
+ rtems_set_errno_and_return_minus_one(rr.status);
+ }
+
+ *psbuf = rr.strbuf;
+
+ return 0;
+}
+
+static ssize_t nfs_readlink(
+ rtems_filesystem_location_info_t *loc, /* IN */
+ char *buf, /* OUT */
+ size_t len
+)
+{
+strbuf sbuf;
+ sbuf.buf = buf;
+ sbuf.max = len;
+
+ return nfs_do_readlink(loc, &sbuf);
+}
+
+/* The semantics of this routine are:
+ *
+ * The caller submits a valid pathloc, i.e. it has
+ * an NfsNode attached to node_access.
+ * On return, pathloc points to the target node which
+ * may or may not be an NFS node.
+ * Hence, the original NFS node is released in either
+ * case:
+ * - link evaluation fails; pathloc points to no valid node
+ * - link evaluation success; pathloc points to a new valid
+ * node. If it's an NFS node, a new NfsNode will be attached
+ * to node_access...
+ */
+
+#define LINKVAL_BUFLEN (MAXPATHLEN+1)
+#define RVAL_ERR_BUT_DONT_FREENODE (-1)
+#define RVAL_ERR_AND_DO_FREENODE ( 1)
+#define RVAL_OK ( 0)
+
+static int nfs_eval_link(
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ int flags /* IN */
+)
+{
+rtems_filesystem_node_types_t type;
+char *buf = malloc(LINKVAL_BUFLEN);
+int rval = RVAL_ERR_AND_DO_FREENODE;
+
+ if (!buf) {
+ errno = ENOMEM;
+ goto cleanup;
+ }
+
+ /* in this loop, we must not use NFS specific ops as we might
+ * step out of our FS during the process...
+ * This algorithm should actually be performed by the
+ * generic's evaluate_path routine :-(
+ *
+ * Unfortunately, there is no way of finding the
+ * directory node who contains 'pathloc', however :-(
+ */
+ do {
+ /* assume the generics have verified 'pathloc' to be
+ * a link...
+ */
+ if ( !pathloc->ops->readlink_h ) {
+ errno = ENOTSUP;
+ goto cleanup;
+ }
+
+ if ( pathloc->ops->readlink_h(pathloc, buf, LINKVAL_BUFLEN) ) {
+ goto cleanup;
+ }
+
+#if DEBUG & DEBUG_EVALPATH
+ fprintf(stderr, "link value is '%s'\n", buf);
+#endif
+
+ /* is the link value an absolute path ? */
+ if ( DELIM != *buf ) {
+ /* NO; a relative path */
+
+ /* we must backup to the link's directory - we
+ * know only how to do that for NFS, however.
+ * In this special case, we can avoid recursion.
+ * Otherwise (i.e. if the link is on another FS),
+ * we must step into its eval_link_h().
+ */
+ if (locIsNfs(pathloc)) {
+ NfsNode node = pathloc->node_access;
+ int err;
+
+ memcpy( &SERP_FILE(node),
+ &node->args.dir,
+ sizeof(node->args.dir) );
+
+ if (updateAttr(node, 1 /* force */))
+ goto cleanup;
+
+ if (SERP_ATTR(node).type != NFDIR) {
+ errno = ENOTDIR;
+ goto cleanup;
+ }
+
+ pathloc->handlers = &nfs_dir_file_handlers;
+
+ err = nfs_evalpath(buf, strlen(buf), flags, pathloc);
+
+ /* according to its semantics,
+ * nfs_evalpath cloned the node attached
+ * to pathloc. Hence we have to
+ * release the old one (referring to
+ * the link; the new clone has been
+ * updated and refers to the link _value_).
+ */
+ nfsNodeDestroy(node);
+
+ if (err) {
+ /* nfs_evalpath has set errno;
+ * pathloc->node_access has no
+ * valid node attached in this case
+ */
+ rval = RVAL_ERR_BUT_DONT_FREENODE;
+ goto cleanup;
+ }
+
+ } else {
+ if ( ! pathloc->ops->eval_link_h ) {
+ errno = ENOTSUP;
+ goto cleanup;
+ }
+ if (!pathloc->ops->eval_link_h(pathloc, flags)) {
+ /* FS is responsible for freeing its pathloc->node_access
+ * if necessary
+ */
+ rval = RVAL_ERR_BUT_DONT_FREENODE;
+ goto cleanup;
+ }
+ }
+ } else {
+ /* link points to an absolute path '/xxx' */
+
+ /* release this node; filesystem_evaluate_path() will
+ * lookup a new one.
+ */
+ rtems_filesystem_freenode(pathloc);
+
+ if (rtems_filesystem_evaluate_path(buf, strlen(buf), flags, pathloc, 1)) {
+ /* If evalpath fails then there is no valid node
+ * attached to pathloc; hence we must not attempt
+ * to free the node
+ */
+ rval = RVAL_ERR_BUT_DONT_FREENODE;
+ goto cleanup;
+ }
+ }
+
+ if ( !pathloc->ops->node_type_h ) {
+ errno = ENOTSUP;
+ goto cleanup;
+ }
+
+ type = pathloc->ops->node_type_h(pathloc);
+
+
+ /* I dont know what to do about hard links */
+ } while ( RTEMS_FILESYSTEM_SYM_LINK == type );
+
+ rval = RVAL_OK;
+
+cleanup:
+
+ free(buf);
+
+ if (RVAL_ERR_AND_DO_FREENODE == rval) {
+ rtems_filesystem_freenode(pathloc);
+ return -1;
+ }
+
+ return rval;
+}
+
+
+struct _rtems_filesystem_operations_table nfs_fs_ops = {
+ nfs_evalpath, /* MANDATORY */
+ nfs_evalformake, /* MANDATORY; may set errno=ENOSYS and return -1 */
+ nfs_link, /* OPTIONAL; may be defaulted */
+ nfs_unlink, /* OPTIONAL; may be defaulted */
+ nfs_node_type, /* OPTIONAL; may be defaulted; BUG in mount - no test!! */
+ nfs_mknod, /* OPTIONAL; may be defaulted */
+ nfs_chown, /* OPTIONAL; may be defaulted */
+ nfs_freenode, /* OPTIONAL; may be defaulted; (release node_access) */
+ rtems_filesystem_default_mount,
+ rtems_nfs_initialize, /* OPTIONAL; may be defaulted -- not used anymore */
+ rtems_filesystem_default_unmount,
+ nfs_fsunmount_me, /* OPTIONAL; may be defaulted */
+ nfs_utime, /* OPTIONAL; may be defaulted */
+ nfs_eval_link, /* OPTIONAL; may be defaulted */
+ nfs_symlink, /* OPTIONAL; may be defaulted */
+ nfs_readlink, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_rename, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_statvfs /* OPTIONAL; may be defaulted */
+
+};
+
+/*****************************************
+ File Handlers
+
+ NOTE: the FS generics expect a FS'
+ evalpath_h() to switch the
+ pathloc->handlers according
+ to the pathloc/node's file
+ type.
+ We currently have 'file' and
+ 'directory' handlers and very
+ few 'symlink' handlers.
+
+ The handlers for each type are
+ implemented or #defined ZERO
+ in a 'nfs_file_xxx',
+ 'nfs_dir_xxx', 'nfs_link_xxx'
+ sequence below this point.
+
+ In some cases, a common handler,
+ can be used for all file types.
+ It is then simply called
+ 'nfs_xxx'.
+ *****************************************/
+
+/* stateless NFS protocol makes this trivial */
+static int nfs_file_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+ return 0;
+}
+
+/* reading directories is not stateless; we must
+ * remember the last 'read' position, i.e.
+ * the server 'cookie'. We do manage this information
+ * attached to the pathinfo.node_access_2.
+ */
+static int nfs_dir_open(
+ rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode
+)
+{
+NfsNode node = iop->pathinfo.node_access;
+DirInfo di;
+
+ /* create a readdirargs object and copy the file handle;
+ * attach to the pathinfo.node_access_2
+ */
+
+ di = (DirInfo) malloc(sizeof(*di));
+ iop->pathinfo.node_access_2 = di;
+
+ if ( !di ) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ memcpy( &di->readdirargs.dir,
+ &SERP_FILE(node),
+ sizeof(di->readdirargs.dir) );
+
+ /* rewind cookie */
+ memset( &di->readdirargs.cookie,
+ 0,
+ sizeof(di->readdirargs.cookie) );
+
+ di->eofreached = FALSE;
+
+ return 0;
+}
+
+static int nfs_file_close(
+ rtems_libio_t *iop
+)
+{
+ return 0;
+}
+
+static int nfs_dir_close(
+ rtems_libio_t *iop
+)
+{
+ free(iop->pathinfo.node_access_2);
+ iop->pathinfo.node_access_2 = 0;
+ return 0;
+}
+
+static ssize_t nfs_file_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+readres rr;
+NfsNode node = iop->pathinfo.node_access;
+Nfs nfs = node->nfs;
+
+ if (count > NFS_MAXDATA)
+ count = NFS_MAXDATA;
+
+ SERP_ARGS(node).readarg.offset = iop->offset;
+ SERP_ARGS(node).readarg.count = count;
+ SERP_ARGS(node).readarg.totalcount = UINT32_C(0xdeadbeef);
+
+ rr.readres_u.reply.data.data_val = buffer;
+
+ if ( nfscall( nfs->server,
+ NFSPROC_READ,
+ (xdrproc_t)xdr_readargs, &SERP_FILE(node),
+ (xdrproc_t)xdr_readres, &rr) ) {
+ return -1;
+ }
+
+
+ if (NFS_OK != rr.status) {
+ rtems_set_errno_and_return_minus_one(rr.status);
+ }
+
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,
+ "Read %i (asked for %i) bytes from offset %i to 0x%08x\n",
+ rr.readres_u.reply.data.data_len,
+ count,
+ iop->offset,
+ rr.readres_u.reply.data.data_val);
+#endif
+
+
+ return rr.readres_u.reply.data.data_len;
+}
+
+/* this is called by readdir() / getdents() */
+static ssize_t nfs_dir_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+DirInfo di = iop->pathinfo.node_access_2;
+RpcUdpServer server = ((Nfs)iop->pathinfo.mt_entry->fs_info)->server;
+
+ if ( di->eofreached )
+ return 0;
+
+ di->ptr = di->buf = buffer;
+
+ /* align + round down the buffer */
+ count &= ~ (DIRENT_HEADER_SIZE - 1);
+ di->len = count;
+
+#if 0
+ /* now estimate the number of entries we should ask for */
+ count /= DIRENT_HEADER_SIZE + CONFIG_AVG_NAMLEN;
+
+ /* estimate the encoded size that might take up */
+ count *= dirres_entry_size + CONFIG_AVG_NAMLEN;
+#else
+ /* integer arithmetics are better done the other way round */
+ count *= dirres_entry_size + CONFIG_AVG_NAMLEN;
+ count /= DIRENT_HEADER_SIZE + CONFIG_AVG_NAMLEN;
+#endif
+
+ if (count > NFS_MAXDATA)
+ count = NFS_MAXDATA;
+
+ di->readdirargs.count = count;
+
+#if DEBUG & DEBUG_READDIR
+ fprintf(stderr,
+ "Readdir: asking for %i XDR bytes, buffer is %i\n",
+ count, di->len);
+#endif
+
+ if ( nfscall(
+ server,
+ NFSPROC_READDIR,
+ (xdrproc_t)xdr_readdirargs, &di->readdirargs,
+ (xdrproc_t)xdr_dir_info, di) ) {
+ return -1;
+ }
+
+
+ if (NFS_OK != di->status) {
+ rtems_set_errno_and_return_minus_one(di->status);
+ }
+
+ return (char*)di->ptr - (char*)buffer;
+}
+
+static ssize_t nfs_file_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+NfsNode node = iop->pathinfo.node_access;
+Nfs nfs = node->nfs;
+int e;
+
+ if (count > NFS_MAXDATA)
+ count = NFS_MAXDATA;
+
+
+ SERP_ARGS(node).writearg.beginoffset = UINT32_C(0xdeadbeef);
+ if ( LIBIO_FLAGS_APPEND & iop->flags ) {
+ if ( updateAttr(node, 0) ) {
+ return -1;
+ }
+ SERP_ARGS(node).writearg.offset = SERP_ATTR(node).size;
+ } else {
+ SERP_ARGS(node).writearg.offset = iop->offset;
+ }
+ SERP_ARGS(node).writearg.totalcount = UINT32_C(0xdeadbeef);
+ SERP_ARGS(node).writearg.data.data_len = count;
+ SERP_ARGS(node).writearg.data.data_val = (void*)buffer;
+
+ /* write XDR buffer size will be chosen by nfscall based
+ * on the PROC specifier
+ */
+
+ if ( nfscall( nfs->server,
+ NFSPROC_WRITE,
+ (xdrproc_t)xdr_writeargs, &SERP_FILE(node),
+ (xdrproc_t)xdr_attrstat, &node->serporid) ) {
+ return -1;
+ }
+
+
+ if (NFS_OK != (e=node->serporid.status) ) {
+ /* try at least to recover the current attributes */
+ updateAttr(node, 1 /* force */);
+ rtems_set_errno_and_return_minus_one(e);
+ }
+
+ node->age = nowSeconds();
+
+ return count;
+}
+
+static rtems_off64_t nfs_file_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t length,
+ int whence
+)
+{
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,
+ "lseek to %i (length %i, whence %i)\n",
+ iop->offset,
+ length,
+ whence);
+#endif
+ if ( SEEK_END == whence ) {
+ /* rtems (4.6.2) libcsupport code 'lseek' uses iop->size to
+ * compute the offset. We don't want to track the file size
+ * by updating 'iop->size' constantly.
+ * Since lseek is the only place using iop->size, we work
+ * around this by tweaking the offset here...
+ */
+ NfsNode node = iop->pathinfo.node_access;
+ fattr *fa = &SERP_ATTR(node);
+
+ if (updateAttr(node, 0 /* only if old */)) {
+ return -1;
+ }
+ iop->offset = fa->size;
+ }
+
+ /* this is particularly easy :-) */
+ return iop->offset;
+}
+
+static rtems_off64_t nfs_dir_lseek(
+ rtems_libio_t *iop,
+ rtems_off64_t length,
+ int whence
+)
+{
+DirInfo di = iop->pathinfo.node_access_2;
+
+ /* we don't support anything other than
+ * rewinding
+ */
+ if (SEEK_SET != whence || 0 != length) {
+ errno = ENOTSUP;
+ return -1;
+ }
+
+ /* rewind cookie */
+ memset( &di->readdirargs.cookie,
+ 0,
+ sizeof(di->readdirargs.cookie) );
+
+ di->eofreached = FALSE;
+
+ return iop->offset;
+}
+
+#if 0 /* structure types for reference */
+struct fattr {
+ ftype type;
+ u_int mode;
+ u_int nlink;
+ u_int uid;
+ u_int gid;
+ u_int size;
+ u_int blocksize;
+ u_int rdev;
+ u_int blocks;
+ u_int fsid;
+ u_int fileid;
+ nfstime atime;
+ nfstime mtime;
+ nfstime ctime;
+};
+
+struct stat
+{
+ dev_t st_dev;
+ ino_t st_ino;
+ mode_t st_mode;
+ nlink_t st_nlink;
+ uid_t st_uid;
+ gid_t st_gid;
+ dev_t st_rdev;
+ rtems_off64_t st_size;
+ /* SysV/sco doesn't have the rest... But Solaris, eabi does. */
+#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
+ time_t st_atime;
+ time_t st_mtime;
+ time_t st_ctime;
+#else
+ time_t st_atime;
+ long st_spare1;
+ time_t st_mtime;
+ long st_spare2;
+ time_t st_ctime;
+ long st_spare3;
+ long st_blksize;
+ long st_blocks;
+ long st_spare4[2];
+#endif
+};
+#endif
+
+/* common for file/dir/link */
+static int nfs_fstat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *buf
+)
+{
+NfsNode node = loc->node_access;
+fattr *fa = &SERP_ATTR(node);
+
+ if (updateAttr(node, 0 /* only if old */)) {
+ return -1;
+ }
+
+/* done by caller
+ memset(buf, 0, sizeof(*buf));
+ */
+
+ /* translate */
+
+ /* one of the branches hopefully is optimized away */
+ if (sizeof(ino_t) < sizeof(u_int)) {
+ buf->st_dev = NFS_MAKE_DEV_T_INO_HACK((NfsNode)loc->node_access);
+ } else {
+ buf->st_dev = NFS_MAKE_DEV_T((NfsNode)loc->node_access);
+ }
+ buf->st_mode = fa->mode;
+ buf->st_nlink = fa->nlink;
+ buf->st_uid = fa->uid;
+ buf->st_gid = fa->gid;
+ buf->st_size = fa->size;
+ /* Set to "preferred size" of this NFS client implementation */
+ buf->st_blksize = nfsStBlksize ? nfsStBlksize : fa->blocksize;
+ buf->st_rdev = fa->rdev;
+ buf->st_blocks = fa->blocks;
+ buf->st_ino = fa->fileid;
+ buf->st_atime = fa->atime.seconds;
+ buf->st_mtime = fa->mtime.seconds;
+ buf->st_ctime = fa->ctime.seconds;
+
+#if 0 /* NFS should return the modes */
+ switch(fa->type) {
+ default:
+ case NFNON:
+ case NFBAD:
+ break;
+
+ case NFSOCK: buf->st_mode |= S_IFSOCK; break;
+ case NFFIFO: buf->st_mode |= S_IFIFO; break;
+ case NFREG : buf->st_mode |= S_IFREG; break;
+ case NFDIR : buf->st_mode |= S_IFDIR; break;
+ case NFBLK : buf->st_mode |= S_IFBLK; break;
+ case NFCHR : buf->st_mode |= S_IFCHR; break;
+ case NFLNK : buf->st_mode |= S_IFLNK; break;
+ }
+#endif
+
+ return 0;
+}
+
+/* a helper which does the real work for
+ * a couple of handlers (such as chmod,
+ * ftruncate or utime)
+ */
+static int
+nfs_sattr(NfsNode node, sattr *arg, u_long mask)
+{
+
+struct timeval now;
+nfstime nfsnow, t;
+int e;
+u_int mode;
+
+ if (updateAttr(node, 0 /* only if old */))
+ return -1;
+
+ rtems_clock_get_tod_timeval(&now);
+
+ /* TODO: add rtems EPOCH - UNIX EPOCH seconds */
+ nfsnow.seconds = now.tv_sec;
+ nfsnow.useconds = now.tv_usec;
+
+ /* merge permission bits into existing type bits */
+ mode = SERP_ATTR(node).mode;
+ if (mask & SATTR_MODE) {
+ mode &= S_IFMT;
+ mode |= arg->mode & ~S_IFMT;
+ } else {
+ mode = -1;
+ }
+ SERP_ARGS(node).sattrarg.attributes.mode = mode;
+
+ SERP_ARGS(node).sattrarg.attributes.uid =
+ (mask & SATTR_UID) ? arg->uid : -1;
+
+ SERP_ARGS(node).sattrarg.attributes.gid =
+ (mask & SATTR_GID) ? arg->gid : -1;
+
+ SERP_ARGS(node).sattrarg.attributes.size =
+ (mask & SATTR_SIZE) ? arg->size : -1;
+
+ if (mask & SATTR_ATIME)
+ t = arg->atime;
+ else if (mask & SATTR_TOUCHA)
+ t = nfsnow;
+ else
+ t.seconds = t.useconds = -1;
+ SERP_ARGS(node).sattrarg.attributes.atime = t;
+
+ if (mask & SATTR_ATIME)
+ t = arg->mtime;
+ else if (mask & SATTR_TOUCHA)
+ t = nfsnow;
+ else
+ t.seconds = t.useconds = -1;
+ SERP_ARGS(node).sattrarg.attributes.mtime = t;
+
+ node->serporid.status = NFS_OK;
+
+ if ( nfscall( node->nfs->server,
+ NFSPROC_SETATTR,
+ (xdrproc_t)xdr_sattrargs, &SERP_FILE(node),
+ (xdrproc_t)xdr_attrstat, &node->serporid) ) {
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,
+ "nfs_sattr (mask 0x%08x): %s",
+ mask,
+ strerror(errno));
+#endif
+ return -1;
+ }
+
+ if (NFS_OK != (e=node->serporid.status) ) {
+#if DEBUG & DEBUG_SYSCALLS
+ fprintf(stderr,"nfs_sattr: %s\n",strerror(e));
+#endif
+ /* try at least to recover the current attributes */
+ updateAttr(node, 1 /* force */);
+ rtems_set_errno_and_return_minus_one(e);
+ }
+
+ node->age = nowSeconds();
+
+ return 0;
+}
+
+
+/* common for file/dir/link */
+static int nfs_fchmod(
+ rtems_filesystem_location_info_t *loc,
+ mode_t mode
+)
+{
+sattr arg;
+
+ arg.mode = mode;
+ return nfs_sattr(loc->node_access, &arg, SATTR_MODE);
+
+}
+
+/* just set the size attribute to 'length'
+ * the server will take care of the rest :-)
+ */
+static int nfs_file_ftruncate(
+ rtems_libio_t *iop,
+ rtems_off64_t length
+)
+{
+sattr arg;
+
+ arg.size = length;
+ /* must not modify any other attribute; if we are not the owner
+ * of the file or directory but only have write access changing
+ * any attribute besides 'size' will fail...
+ */
+ return nfs_sattr(iop->pathinfo.node_access,
+ &arg,
+ SATTR_SIZE);
+}
+
+/* files and symlinks are removed
+ * by the common nfs_unlink() routine.
+ * NFS has a different NFSPROC_RMDIR
+ * call, though...
+ */
+static int nfs_dir_rmnod(
+ rtems_filesystem_location_info_t *parentpathloc, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ return nfs_do_unlink(parentpathloc, pathloc, NFSPROC_RMDIR);
+}
+
+/* the file handlers table */
+static
+struct _rtems_filesystem_file_handlers_r nfs_file_file_handlers = {
+ nfs_file_open, /* OPTIONAL; may be defaulted */
+ nfs_file_close, /* OPTIONAL; may be defaulted */
+ nfs_file_read, /* OPTIONAL; may be defaulted */
+ nfs_file_write, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_ioctl,
+ nfs_file_lseek, /* OPTIONAL; may be defaulted */
+ nfs_fstat, /* OPTIONAL; may be defaulted */
+ nfs_fchmod, /* OPTIONAL; may be defaulted */
+ nfs_file_ftruncate, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ nfs_unlink, /* OPTIONAL; may be defaulted */
+};
+
+/* the directory handlers table */
+static
+struct _rtems_filesystem_file_handlers_r nfs_dir_file_handlers = {
+ nfs_dir_open, /* OPTIONAL; may be defaulted */
+ nfs_dir_close, /* OPTIONAL; may be defaulted */
+ nfs_dir_read, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_write,
+ rtems_filesystem_default_ioctl,
+ nfs_dir_lseek, /* OPTIONAL; may be defaulted */
+ nfs_fstat, /* OPTIONAL; may be defaulted */
+ nfs_fchmod, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ nfs_dir_rmnod, /* OPTIONAL; may be defaulted */
+};
+
+/* the link handlers table */
+static
+struct _rtems_filesystem_file_handlers_r nfs_link_file_handlers = {
+ rtems_filesystem_default_open,
+ rtems_filesystem_default_close,
+ rtems_filesystem_default_read,
+ rtems_filesystem_default_write,
+ rtems_filesystem_default_ioctl,
+ rtems_filesystem_default_lseek,
+ nfs_fstat, /* OPTIONAL; may be defaulted */
+ nfs_fchmod, /* OPTIONAL; may be defaulted */
+ rtems_filesystem_default_ftruncate,
+ rtems_filesystem_default_fpathconf,
+ rtems_filesystem_default_fsync,
+ rtems_filesystem_default_fdatasync,
+ rtems_filesystem_default_fcntl,
+ nfs_unlink, /* OPTIONAL; may be defaulted */
+};
+
+/* we need a dummy driver entry table to get a
+ * major number from the system
+ */
+static
+rtems_device_driver nfs_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ /* we don't really use this routine because
+ * we cannot supply an argument (contrary
+ * to what the 'arg' parameter suggests - it
+ * is always set to 0 by the generics :-()
+ * and because we don't want the user to
+ * have to deal with the major number (which
+ * OTOH is something WE are interested in. The
+ * only reason for using this API was getting
+ * a major number, after all).
+ *
+ * Something must be present, however, to
+ * reserve a slot in the driver table.
+ */
+ return RTEMS_SUCCESSFUL;
+}
+
+static rtems_driver_address_table drvNfs = {
+ nfs_initialize,
+ 0, /* open */
+ 0, /* close */
+ 0, /* read */
+ 0, /* write */
+ 0 /* control */
+};
+
+/* Dump a list of the currently mounted NFS to a file */
+int
+nfsMountsShow(FILE *f)
+{
+char *mntpt = 0;
+Nfs nfs;
+
+ if (!f)
+ f = stdout;
+
+ if ( !(mntpt=malloc(MAXPATHLEN)) ) {
+ fprintf(stderr,"nfsMountsShow(): no memory\n");
+ return -1;
+ }
+
+ fprintf(f,"Currently Mounted NFS:\n");
+
+ LOCK(nfsGlob.llock);
+
+ for (nfs = nfsGlob.mounted_fs; nfs; nfs=nfs->next) {
+ fprintf(f,"%s on ", nfs->mt_entry->dev);
+ if (rtems_filesystem_resolve_location(mntpt, MAXPATHLEN, &nfs->mt_entry->mt_fs_root))
+ fprintf(f,"<UNABLE TO LOOKUP MOUNTPOINT>\n");
+ else
+ fprintf(f,"%s\n",mntpt);
+ }
+
+ UNLOCK(nfsGlob.llock);
+
+ free(mntpt);
+ return 0;
+}
+
+#if 0
+CCJ_REMOVE_MOUNT
+/* convenience wrapper
+ *
+ * NOTE: this routine calls NON-REENTRANT
+ * gethostbyname() if the host is
+ * not in 'dot' notation.
+ */
+int
+nfsMount(char *uidhost, char *path, char *mntpoint)
+{
+struct stat st;
+int devl;
+char *host;
+int rval = -1;
+char *dev = 0;
+
+ if (!uidhost || !path || !mntpoint) {
+ fprintf(stderr,"usage: nfsMount(""[uid.gid@]host"",""path"",""mountpoint"")\n");
+ nfsMountsShow(stderr);
+ return -1;
+ }
+
+ if ( !(dev = malloc((devl=strlen(uidhost) + 20 + strlen(path)+1))) ) {
+ fprintf(stderr,"nfsMount: out of memory\n");
+ return -1;
+ }
+
+ /* Try to create the mount point if nonexistent */
+ if (stat(mntpoint, &st)) {
+ if (ENOENT != errno) {
+ perror("nfsMount trying to create mount point - stat failed");
+ goto cleanup;
+ } else if (mkdir(mntpoint,0777)) {
+ perror("nfsMount trying to create mount point");
+ goto cleanup;
+ }
+ }
+
+ if ( !(host=strchr(uidhost,UIDSEP)) ) {
+ host = uidhost;
+ } else {
+ host++;
+ }
+
+ if (isdigit((unsigned char)*host)) {
+ /* avoid using gethostbyname */
+ sprintf(dev,"%s:%s",uidhost,path);
+ } else {
+ struct hostent *h;
+
+ /* copy the uid part (hostname will be
+ * overwritten)
+ */
+ strcpy(dev, uidhost);
+
+ /* NOTE NOTE NOTE: gethostbyname is NOT
+ * thread safe. This is UGLY
+ */
+
+/* BEGIN OF NON-THREAD SAFE REGION */
+
+ h = gethostbyname(host);
+
+ if ( !h ||
+ !inet_ntop( AF_INET,
+ (struct in_addr*)h->h_addr_list[0],
+ dev + (host - uidhost),
+ devl - (host - uidhost) )
+ ) {
+ fprintf(stderr,"nfsMount: host '%s' not found\n",host);
+ goto cleanup;
+ }
+
+/* END OF NON-THREAD SAFE REGION */
+
+ /* append ':<path>' */
+ strcat(dev,":");
+ strcat(dev,path);
+ }
+
+ printf("Trying to mount %s on %s\n",dev,mntpoint);
+
+ if (mount(dev,
+ mntpoint,
+ "nfs",
+ RTEMS_FILESYSTEM_READ_WRITE,
+ NULL)) {
+ perror("nfsMount - mount");
+ goto cleanup;
+ }
+
+ rval = 0;
+
+cleanup:
+ free(dev);
+ return rval;
+}
+#endif
+
+/* HERE COMES A REALLY UGLY HACK */
+
+/* This is stupid; it is _very_ hard to find the path
+ * leading to a rtems_filesystem_location_info_t node :-(
+ * The only easy way is making the location the current
+ * directory and issue a getcwd().
+ * However, since we don't want to tamper with the
+ * current directory, we must create a separate
+ * task to do the job for us - sigh.
+ */
+
+typedef struct ResolvePathArgRec_ {
+ rtems_filesystem_location_info_t *loc; /* IN: location to resolve */
+ char *buf; /* IN/OUT: buffer where to put the path */
+ int len; /* IN: buffer length */
+ rtems_id sync; /* IN: synchronization */
+ rtems_status_code status; /* OUT: result */
+} ResolvePathArgRec, *ResolvePathArg;
+
+static void
+resolve_path(rtems_task_argument arg)
+{
+ResolvePathArg rpa = (ResolvePathArg)arg;
+rtems_filesystem_location_info_t old;
+
+ /* IMPORTANT: let the helper task have its own libio environment (i.e. cwd) */
+ if (RTEMS_SUCCESSFUL == (rpa->status = rtems_libio_set_private_env())) {
+
+ old = rtems_filesystem_current;
+
+ rtems_filesystem_current = *(rpa->loc);
+
+ if ( !getcwd(rpa->buf, rpa->len) )
+ rpa->status = RTEMS_UNSATISFIED;
+
+ /* must restore the cwd because 'freenode' will be called on it */
+ rtems_filesystem_current = old;
+ }
+ rtems_semaphore_release(rpa->sync);
+ rtems_task_delete(RTEMS_SELF);
+}
+
+
+/* a utility routine to find the path leading to a
+ * rtems_filesystem_location_info_t node
+ *
+ * INPUT: 'loc' and a buffer 'buf' (length 'len') to hold the
+ * path.
+ * OUTPUT: path copied into 'buf'
+ *
+ * RETURNS: 0 on success, RTEMS error code on error.
+ */
+rtems_status_code
+rtems_filesystem_resolve_location(char *buf, int len, rtems_filesystem_location_info_t *loc)
+{
+ResolvePathArgRec arg;
+rtems_id tid = 0;
+rtems_task_priority pri;
+rtems_status_code status;
+
+ arg.loc = loc;
+ arg.buf = buf;
+ arg.len = len;
+ arg.sync = 0;
+
+ status = rtems_semaphore_create(
+ rtems_build_name('r','e','s','s'),
+ 0,
+ RTEMS_SIMPLE_BINARY_SEMAPHORE,
+ 0,
+ &arg.sync);
+
+ if (RTEMS_SUCCESSFUL != status)
+ goto cleanup;
+
+ rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &pri);
+
+ status = rtems_task_create(
+ rtems_build_name('r','e','s','s'),
+ pri,
+ RTEMS_MINIMUM_STACK_SIZE + 50000,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &tid);
+
+ if (RTEMS_SUCCESSFUL != status)
+ goto cleanup;
+
+ status = rtems_task_start(tid, resolve_path, (rtems_task_argument)&arg);
+
+ if (RTEMS_SUCCESSFUL != status) {
+ rtems_task_delete(tid);
+ goto cleanup;
+ }
+
+
+ /* synchronize with the helper task */
+ rtems_semaphore_obtain(arg.sync, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+
+ status = arg.status;
+
+cleanup:
+ if (arg.sync)
+ rtems_semaphore_delete(arg.sync);
+
+ return status;
+}
+
+int
+nfsSetTimeout(uint32_t timeout_ms)
+{
+rtems_interrupt_level k;
+uint32_t s,us;
+
+ if ( timeout_ms > 100000 ) {
+ /* out of range */
+ return -1;
+ }
+
+ s = timeout_ms/1000;
+ us = (timeout_ms % 1000) * 1000;
+
+ rtems_interrupt_disable(k);
+ _nfscalltimeout.tv_sec = s;
+ _nfscalltimeout.tv_usec = us;
+ rtems_interrupt_enable(k);
+
+ return 0;
+}
+
+uint32_t
+nfsGetTimeout( void )
+{
+rtems_interrupt_level k;
+uint32_t s,us;
+ rtems_interrupt_disable(k);
+ s = _nfscalltimeout.tv_sec;
+ us = _nfscalltimeout.tv_usec;
+ rtems_interrupt_enable(k);
+ return s*1000 + us/1000;
+}
diff --git a/cpukit/libfs/src/nfsclient/src/nfs.modini.c b/cpukit/libfs/src/nfsclient/src/nfs.modini.c
new file mode 100644
index 0000000000..22095cf53f
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/nfs.modini.c
@@ -0,0 +1,31 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "librtemsNfs.h"
+
+/* CEXP dynamic loader support */
+
+void
+_cexpModuleInitialize(void *mod)
+{
+#if defined(DEBUG)
+ /* print load address (in case we crash while initializing) */
+unsigned lr;
+ __asm__ __volatile__(
+ " bl thisis_loaded_at \n"
+ "thisis_loaded_at: \n"
+ " mflr %0 \n"
+ : "=r"(lr) ::"lr");
+ printf("thisis_loaded_at: 0x%08x\n",lr);
+#endif
+ nfsInit(0,0);
+}
+
+int
+_cexpModuleFinalize(void *mod)
+{
+ return nfsCleanup();
+}
+
+
diff --git a/cpukit/libfs/src/nfsclient/src/nfsTest.c b/cpukit/libfs/src/nfsclient/src/nfsTest.c
new file mode 100644
index 0000000000..a372a7511c
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/nfsTest.c
@@ -0,0 +1,381 @@
+/* $Id$ */
+
+/* Test program for evaluating NFS read throughput */
+
+/* Author: Till Straumann <strauman@slac.stanford.edu>, 2006 */
+
+/* This test code allows for evaluating NFS read performance
+ * under various scenarios:
+ * - synchronous reads with various buffer sizes (select
+ * 'num_readers' == 0, see below).
+ * - pseudo 'read-ahead' using multiple threads that issue
+ * NFS reads from the same file (but from different offsets)
+ * in parallel.
+ * Rationale: each NFS read request is synchronous, i.e., the
+ * caller sends a request to the server and waits for the
+ * reply to come back. Performance enhancement can be expected
+ * by requesting multiple blocks in parallel rather than
+ * sequentially.
+ *
+ * rtems_interval
+ * nfsTestRead(char *file_name, int chunk_size, int num_readers);
+ *
+ * 1) creates 'num_readers' threads, each opening 'file_name' for
+ * reading on a separate file descriptor.
+ * 2) creates message queues for communicating with reader threads
+ *
+ * 3) read file using nfsTestReadBigbuf() until EOF is reached
+ *
+ * 4) releases resources.
+ *
+ * RETURNS: Time elapsed during step 3 in ms. This is measured
+ * using the system clock so make sure the test file
+ * is big enough.
+ *
+ * nfsTestReadBigbuf() synchronously reads a block of
+ * 'num_readers * chunk_size' (which may be bigger than
+ * the UDP limit of 8k) using 'num_reader' threads to
+ * retrieve the various pieces of the big block in parallel.
+ * This speeds up things since several RPC calls can
+ * be in the works at once.
+ *
+ * NOTES:
+ * - if 'num_readers' == 0 this corresponds to an 'ordinary'
+ * NFS read. 'num_readers' == 1 schedules a single reader
+ * thread (== ordinary NFS read + message passing overhead).
+ * - no actual processing on the data is done; they are simply
+ * thrown away. A real, performance-critical application could
+ * pipeline 'reader' and 'cruncher' threads.
+ * - read is not completely asynchronous; synchronization is still
+ * performed at 'big block' boundaries (num_readers * chunk_size).
+ */
+
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/error.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+unsigned nfsTestReaderPri = 80;
+
+struct nfsTestReq_ {
+ unsigned offset; /* file offset */
+ int size; /* IN: block size to read (must be < 8192), OUT: bytes actually read */
+ void *buf; /* data buffer address */
+};
+
+/* Queue for sending requests to parallel reader tasks */
+rtems_id nfsTestRQ = 0;
+/* Queue to pickup replies from parallel reader tasks */
+rtems_id nfsTestAQ = 0;
+
+
+/* Reader task; opens its own file descriptor
+ * and works on requests:
+ * - obtain request from request queue.
+ * - lseek to the requested file offset
+ * - NFS read into buffer
+ * - queue reply.
+ *
+ * Note that this implementation is very simple
+ * - no full error checking.
+ * - file is opened/closed by thread
+ * it's main purpose is running quick tests.
+ */
+static rtems_task
+nfsTestReader(rtems_task_argument arg)
+{
+int fd = open((char*)arg,O_RDONLY);
+unsigned long s;
+struct nfsTestReq_ r;
+rtems_status_code sc;
+
+ if ( fd < 0 ) {
+ perror("nfsReader: opening file");
+ goto cleanup;
+ }
+ do {
+ s = sizeof(r);
+ sc = rtems_message_queue_receive(nfsTestRQ, &r, &s, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc, "(Error) reading from message queue");
+ goto cleanup;
+ }
+ if ( !r.buf ) {
+ /* They send a NULL buffer as a shutdown request */
+ break;
+ }
+#ifdef DEBUG
+ printf("Reader: reading offset %u, size %i to %p ... ",
+ r.offset, r.size, r.buf);
+#endif
+ /* seek to requested offset */
+ lseek(fd, r.offset, SEEK_SET);
+ r.size = read(fd, r.buf, r.size);
+#ifdef DEBUG
+ printf("got %i\n",r.size);
+#endif
+ rtems_message_queue_send(nfsTestAQ, &r, sizeof(r));
+ } while (1) ;
+
+cleanup:
+ if ( fd >= 0 )
+ close(fd);
+ rtems_task_delete(RTEMS_SELF);
+}
+
+
+/* helper to create and start a reader task */
+static rtems_id
+taskSpawn(char *filenm, int inst)
+{
+rtems_status_code sc;
+rtems_id tid;
+
+ sc = rtems_task_create(
+ rtems_build_name('n','t','t','0'+inst),
+ nfsTestReaderPri,
+ 1400,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &tid);
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc,"(Error) Creating nfs reader task %i",inst);
+ return 0;
+ }
+
+ sc = rtems_task_start(tid, nfsTestReader, (rtems_task_argument)filenm);
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc,"(Error) Staritng nfs reader task %i",inst);
+ rtems_task_delete(tid);
+ return 0;
+ }
+
+ return tid;
+}
+
+/*
+ * Read nrd*sz bytes into 'buf' from file offset 'off'
+ * using 'nrd' parallel reader tasks to do the job.
+ * This helper routine schedules 'nrd' requests to
+ * the reader tasks and waits for all requests to
+ * finish.
+ *
+ * RETURNS: number of bytes read or -1 (error).
+ *
+ * CAVEATS:
+ * - assumes read requests always return 'sz' bytes
+ * unless the end of file is reached.
+ * THIS ASSUMPTION SHOULD NOT BE MADE WHEN WRITING
+ * ANY 'REAL' CODE.
+ */
+static int
+nfsTestReadBigbuf(char *buf, int off, int sz, int nrd)
+{
+int i,rval=0;
+struct nfsTestReq_ r;
+ r.buf = buf;
+ r.size = sz;
+ r.offset = off;
+ /* send out parallel requests */
+ for (i=0; i<nrd; i++) {
+ rtems_message_queue_send(nfsTestRQ, &r, sizeof(r));
+ r.offset += sz;
+ r.buf += sz;
+ }
+ /* wait for answers */
+ for (i=0; i<nrd; i++) {
+ unsigned long s = sizeof(r);
+ rtems_message_queue_receive(nfsTestAQ, &r, &s, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if ( r.size < 0 ) {
+ fprintf(stderr,"A reader failed\n");
+ rval = -1;
+ } else {
+ /* FIXME sanity checks:
+ * - catch case where any-but-last read returns < sz
+ */
+ if ( rval >= 0 ) {
+ rval += r.size;
+ }
+ }
+ }
+ return rval;
+}
+
+/* Main test routine
+ *
+ * Read file 'fname' usint 'nrd' parallel reader tasks,
+ * each operating on chunks of 'sz' bytes.
+ *
+ * RETURNS: time elapsed in milliseconds. This is measured
+ * using the system clock. Hence, for the result
+ * to be meaningful, the file must be big enough.
+ *
+ */
+rtems_interval
+nfsTestRead(char *fnam, int sz, int nrd)
+{
+int i;
+unsigned off;
+rtems_interval now=-1, then, tickspsec;
+rtems_status_code sc;
+int fd=-1;
+char *buf=0;
+
+ if ( nrd < 0 )
+ nrd = 0;
+
+ if ( sz < 0 || sz > 8192 ) {
+ fprintf(stderr,"\n");
+ return -1;
+ }
+
+ nfsTestRQ = nfsTestAQ = 0;
+
+ /* Allocate buffer */
+ if ( ! (buf=malloc(sz*(nrd ? nrd : 1))) ) {
+ perror("allocating buffer");
+ goto cleanup;
+ }
+
+ /* Don't bother proceeding if we can't open the file for reading */
+ if ( (fd=open(fnam,O_RDONLY)) < 0 ) {
+ perror("opening file");
+ goto cleanup;
+ }
+ if ( nrd ) {
+ close(fd); fd = -1;
+ }
+
+ /* Create request queue */
+ if ( nrd ) {
+ sc = rtems_message_queue_create(
+ rtems_build_name('n','t','r','q'),
+ nrd,
+ sizeof(struct nfsTestReq_),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ & nfsTestRQ );
+
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc, "(Error) creating request queue");
+ nfsTestRQ = 0;
+ goto cleanup;
+ }
+
+ /* Spawn reader tasks */
+ for ( i=0; i<nrd; i++ ) {
+ if ( ! taskSpawn(fnam, i) )
+ goto cleanup;
+ }
+
+ /* Create reply queue */
+ sc = rtems_message_queue_create(
+ rtems_build_name('n','t','a','q'),
+ nrd,
+ sizeof(struct nfsTestReq_),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ & nfsTestAQ );
+
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc, "(Error) creating reply queue");
+ nfsTestAQ = 0;
+ goto cleanup;
+ }
+ }
+
+ /* Timed main loop */
+ then = rtems_clock_get_ticks_since_boot();
+
+ if ( nrd ) {
+ off = 0;
+ while ((i = nfsTestReadBigbuf(buf, off, sz, nrd)) > 0 ) {
+#ifdef DEBUG
+ printf("bigbuf got %i\n", i);
+#endif
+ off += i;
+ }
+ } else {
+ while ( (i = read(fd, buf, sz)) > 0 )
+ /* nothing else to do */;
+ if ( i < 0 ) {
+ perror("reading");
+ goto cleanup;
+ }
+ }
+
+ now = rtems_clock_get_ticks_since_boot();
+ now = (now-then)*1000;
+ ticksspec = rtems_clock_get_ticks_per_second();
+ now /= tickspsec; /* time in ms */
+
+cleanup:
+ if ( fd >= 0 )
+ close(fd);
+
+ if ( nfsTestRQ ) {
+ /* request tasks to shutdown by sending NULL buf request */
+ struct nfsTestReq_ r;
+ r.buf = 0;
+ for ( i=0; i<nrd; i++ ) {
+ rtems_message_queue_send( nfsTestRQ, &r, sizeof(r) );
+ }
+ /* cheat: instead of proper synchronization with shutdown we simply
+ * delay for a second...
+ */
+ rtems_task_wake_after( tickspsec );
+ rtems_message_queue_delete( nfsTestRQ );
+ }
+ if ( nfsTestAQ )
+ rtems_message_queue_delete( nfsTestAQ );
+ free(buf);
+ return now;
+}
diff --git a/cpukit/libfs/src/nfsclient/src/rpcio.c b/cpukit/libfs/src/nfsclient/src/rpcio.c
new file mode 100644
index 0000000000..3316cccb5f
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/rpcio.c
@@ -0,0 +1,1792 @@
+/* $Id$ */
+
+/* RPC multiplexor for a multitasking environment */
+
+/* Author: Till Straumann <strauman@slac.stanford.edu>, 2002 */
+
+/* This code funnels arbitrary task's UDP/RPC requests
+ * through one socket to arbitrary servers.
+ * The replies are gathered and dispatched to the
+ * requestors.
+ * One task handles all the sending and receiving
+ * work including retries.
+ * It is up to the requestor, however, to do
+ * the XDR encoding of the arguments / decoding
+ * of the results (except for the RPC header which
+ * is handled by the daemon).
+ */
+
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+#include <stdlib.h>
+#include <time.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "rpcio.h"
+
+/****************************************************************/
+/* CONFIGURABLE PARAMETERS */
+/****************************************************************/
+
+#define MBUF_RX /* If defined: use mbuf XDR stream for
+ * decoding directly out of mbufs
+ * Otherwise, the regular 'recvfrom()'
+ * interface will be used involving an
+ * extra buffer allocation + copy step.
+ */
+
+#define MBUF_TX /* If defined: avoid copying data when
+ * sending. Instead, use a wrapper to
+ * 'sosend()' which will point an MBUF
+ * directly to our buffer space.
+ * Note that the BSD stack does not copy
+ * data when fragmenting packets - it
+ * merely uses an mbuf chain pointing
+ * into different areas of the data.
+ *
+ * If undefined, the regular 'sendto()'
+ * interface is used.
+ */
+
+#undef REJECT_SERVERIP_MISMATCH
+ /* If defined, RPC replies must come from the server
+ * that was queried. Eric Norum has reported problems
+ * with clustered NFS servers. So we disable this
+ * reducing paranoia...
+ */
+
+/* daemon task parameters */
+#define RPCIOD_STACK 10000
+#define RPCIOD_PRIO 100 /* *fallback* priority */
+
+/* depth of the message queue for sending
+ * RPC requests to the daemon
+ */
+#define RPCIOD_QDEPTH 20
+
+/* Maximum retry limit for retransmission */
+#define RPCIOD_RETX_CAP_S 3 /* seconds */
+
+/* Default timeout for RPC calls */
+#define RPCIOD_DEFAULT_TIMEOUT (&_rpc_default_timeout)
+static struct timeval _rpc_default_timeout = { 10 /* secs */, 0 /* usecs */ };
+
+/* how many times should we try to resend a failed
+ * transaction with refreshed AUTHs
+ */
+#define RPCIOD_REFRESH 2
+
+/* Events we are using; the RPC_EVENT
+ * MUST NOT be used by any application
+ * thread doing RPC IO (e.g. NFS)
+ */
+#define RTEMS_RPC_EVENT RTEMS_EVENT_30 /* THE event used by RPCIO. Every task doing
+ * RPC IO will receive this - hence it is
+ * RESERVED
+ */
+#define RPCIOD_RX_EVENT RTEMS_EVENT_1 /* Events the RPCIOD is using/waiting for */
+#define RPCIOD_TX_EVENT RTEMS_EVENT_2
+#define RPCIOD_KILL_EVENT RTEMS_EVENT_3 /* send to the daemon to kill it */
+
+#define LD_XACT_HASH 8 /* ld of the size of the transaction hash table */
+
+
+/* Debugging Flags */
+
+/* NOTE: defining DEBUG 0 leaves some 'assert()' paranoia checks
+ * but produces no output
+ */
+
+#define DEBUG_TRACE_XACT (1<<0)
+#define DEBUG_EVENTS (1<<1)
+#define DEBUG_MALLOC (1<<2)
+#define DEBUG_TIMEOUT (1<<3)
+#define DEBUG_PACKLOSS (1<<4) /* This introduces random, artificial packet losses to test retransmission */
+
+#define DEBUG_PACKLOSS_FRACT (0xffffffff/10)
+
+/* USE PARENTHESIS WHEN 'or'ing MULTIPLE FLAGS: (DEBUG_XX | DEBUG_YY) */
+#define DEBUG (0)
+
+/****************************************************************/
+/* END OF CONFIGURABLE SECTION */
+/****************************************************************/
+
+/* prevent rollover of our timers by readjusting the epoch on the fly */
+#if (DEBUG) & DEBUG_TIMEOUT
+#define RPCIOD_EPOCH_SECS 10
+#else
+#define RPCIOD_EPOCH_SECS 10000
+#endif
+
+#ifdef DEBUG
+#define ASSERT(arg) assert(arg)
+#else
+#define ASSERT(arg) if (arg)
+#endif
+
+/****************************************************************/
+/* MACROS */
+/****************************************************************/
+
+
+#define XACT_HASHS (1<<(LD_XACT_HASH)) /* the hash table size derived from the ld */
+#define XACT_HASH_MSK ((XACT_HASHS)-1) /* mask to extract the hash index from a RPC-XID */
+
+
+#define MU_LOCK(mutex) do { \
+ assert( \
+ RTEMS_SUCCESSFUL == \
+ rtems_semaphore_obtain( \
+ (mutex), \
+ RTEMS_WAIT, \
+ RTEMS_NO_TIMEOUT \
+ ) ); \
+ } while(0)
+
+#define MU_UNLOCK(mutex) do { \
+ assert( \
+ RTEMS_SUCCESSFUL == \
+ rtems_semaphore_release( \
+ (mutex) \
+ ) ); \
+ } while(0)
+
+#define MU_CREAT(pmutex) do { \
+ assert( \
+ RTEMS_SUCCESSFUL == \
+ rtems_semaphore_create( \
+ rtems_build_name( \
+ 'R','P','C','l' \
+ ), \
+ 1, \
+ MUTEX_ATTRIBUTES, \
+ 0, \
+ (pmutex)) ); \
+ } while (0)
+
+
+#define MU_DESTROY(mutex) do { \
+ assert( \
+ RTEMS_SUCCESSFUL == \
+ rtems_semaphore_delete( \
+ mutex \
+ ) ); \
+ } while (0)
+
+#define MUTEX_ATTRIBUTES (RTEMS_LOCAL | \
+ RTEMS_PRIORITY | \
+ RTEMS_INHERIT_PRIORITY | \
+ RTEMS_BINARY_SEMAPHORE)
+
+#define FIRST_ATTEMPT 0x88888888 /* some time that is never reached */
+
+/****************************************************************/
+/* TYPE DEFINITIONS */
+/****************************************************************/
+
+typedef rtems_interval TimeoutT;
+
+/* 100000th implementation of a doubly linked list;
+ * since only one thread is looking at these,
+ * we need no locking
+ */
+typedef struct ListNodeRec_ {
+ struct ListNodeRec_ *next, *prev;
+} ListNodeRec, *ListNode;
+
+
+/* Structure representing an RPC server */
+typedef struct RpcUdpServerRec_ {
+ RpcUdpServer next; /* linked list of all servers; protected by hlock */
+ union {
+ struct sockaddr_in sin;
+ struct sockaddr sa;
+ } addr;
+ AUTH *auth;
+ rtems_id authlock; /* must MUTEX the auth object - it's not clear
+ * what is better:
+ * 1 having one (MUTEXed) auth per server
+ * who is shared among all transactions
+ * using that server
+ * 2 maintaining an AUTH per transaction
+ * (there are then other options: manage
+ * XACT pools on a per-server basis instead
+ * of associating a server with a XACT when
+ * sending)
+ * experience will show if the current (1)
+ * approach has to be changed.
+ */
+ TimeoutT retry_period; /* dynamically adjusted retry period
+ * (based on packet roundtrip time)
+ */
+ /* STATISTICS */
+ unsigned long retrans; /* how many retries were issued by this server */
+ unsigned long requests; /* how many requests have been sent */
+ unsigned long timeouts; /* how many requests have timed out */
+ unsigned long errors; /* how many errors have occurred (other than timeouts) */
+ char name[20]; /* server's address in IP 'dot' notation */
+} RpcUdpServerRec;
+
+typedef union RpcBufU_ {
+ uint32_t xid;
+ char buf[1];
+} RpcBufU, *RpcBuf;
+
+/* RX Buffer implementation; this is either
+ * an MBUF chain (MBUF_RX configuration)
+ * or a buffer allocated from the heap
+ * where recvfrom copies the (encoded) reply
+ * to. The XDR routines the copy/decode
+ * it into the user's data structures.
+ */
+#ifdef MBUF_RX
+typedef struct mbuf * RxBuf; /* an MBUF chain */
+static void bufFree(struct mbuf **m);
+#define XID(ibuf) (*(mtod((ibuf), u_long *)))
+extern void xdrmbuf_create(XDR *, struct mbuf *, enum xdr_op);
+#else
+typedef RpcBuf RxBuf;
+#define bufFree(b) do { MY_FREE(*(b)); *(b)=0; } while(0)
+#define XID(ibuf) ((ibuf)->xid)
+#endif
+
+/* A RPC 'transaction' consisting
+ * of server and requestor information,
+ * buffer space and an XDR object
+ * (for encoding arguments).
+ */
+typedef struct RpcUdpXactRec_ {
+ ListNodeRec node; /* so we can put XACTs on a list */
+ RpcUdpServer server; /* server this XACT goes to */
+ long lifetime; /* during the lifetime, retry attempts are made */
+ long tolive; /* lifetime timer */
+ struct rpc_err status; /* RPC reply error status */
+ long age; /* age info; needed to manage retransmission */
+ long trip; /* record round trip time in ticks */
+ rtems_id requestor; /* the task waiting for this XACT to complete */
+ RpcUdpXactPool pool; /* if this XACT belong to a pool, this is it */
+ XDR xdrs; /* argument encoder stream */
+ int xdrpos; /* stream position after the (permanent) header */
+ xdrproc_t xres; /* reply decoder proc - TODO needn't be here */
+ caddr_t pres; /* reply decoded obj - TODO needn't be here */
+#ifndef MBUF_RX
+ int ibufsize; /* size of the ibuf (bytes) */
+#endif
+#ifdef MBUF_TX
+ int refcnt; /* mbuf external storage reference count */
+#endif
+ int obufsize; /* size of the obuf (bytes) */
+ RxBuf ibuf; /* pointer to input buffer assigned by daemon */
+ RpcBufU obuf; /* output buffer (encoded args) APPENDED HERE */
+} RpcUdpXactRec;
+
+typedef struct RpcUdpXactPoolRec_ {
+ rtems_id box;
+ int prog;
+ int version;
+ int xactSize;
+} RpcUdpXactPoolRec;
+
+/* a global hash table where all 'living' transaction
+ * objects are registered.
+ * A number of bits in a transaction's XID maps 1:1 to
+ * an index in this table. Hence, the XACT matching
+ * an RPC/UDP reply packet can quickly be found
+ * The size of this table imposes a hard limit on the
+ * number of all created transactions in the system.
+ */
+static RpcUdpXact xactHashTbl[XACT_HASHS]={0};
+static u_long xidUpper [XACT_HASHS]={0};
+static unsigned xidHashSeed = 0 ;
+
+/* forward declarations */
+static RpcUdpXact
+sockRcv(void);
+
+static void
+rpcio_daemon(rtems_task_argument);
+
+#ifdef MBUF_TX
+ssize_t
+sendto_nocpy (
+ int s,
+ const void *buf, size_t buflen,
+ int flags,
+ const struct sockaddr *toaddr, int tolen,
+ void *closure,
+ void (*freeproc)(caddr_t, u_int),
+ void (*refproc)(caddr_t, u_int)
+);
+static void paranoia_free(caddr_t closure, u_int size);
+static void paranoia_ref (caddr_t closure, u_int size);
+#define SENDTO sendto_nocpy
+#else
+#define SENDTO sendto
+#endif
+
+static RpcUdpServer rpcUdpServers = 0; /* linked list of all servers; protected by llock */
+
+static int ourSock = -1; /* the socket we are using for communication */
+static rtems_id rpciod = 0; /* task id of the RPC daemon */
+static rtems_id msgQ = 0; /* message queue where the daemon picks up
+ * requests
+ */
+#ifndef NDEBUG
+static rtems_id llock = 0; /* MUTEX protecting the server list */
+static rtems_id hlock = 0; /* MUTEX protecting the hash table and the list of servers */
+#endif
+static rtems_id fini = 0; /* a synchronization semaphore we use during
+ * module cleanup / driver unloading
+ */
+static rtems_interval ticksPerSec; /* cached system clock rate (WHO IS ASSUMED NOT
+ * TO CHANGE)
+ */
+
+rtems_task_priority rpciodPriority = 0;
+
+#if (DEBUG) & DEBUG_MALLOC
+/* malloc wrappers for debugging */
+static int nibufs = 0;
+
+static inline void *MY_MALLOC(int s)
+{
+ if (s) {
+ void *rval;
+ MU_LOCK(hlock);
+ assert(nibufs++ < 2000);
+ MU_UNLOCK(hlock);
+ assert((rval = malloc(s)) != 0);
+ return rval;
+ }
+ return 0;
+}
+
+static inline void *MY_CALLOC(int n, int s)
+{
+ if (s) {
+ void *rval;
+ MU_LOCK(hlock);
+ assert(nibufs++ < 2000);
+ MU_UNLOCK(hlock);
+ assert((rval = calloc(n,s)) != 0);
+ return rval;
+ }
+ return 0;
+}
+
+
+static inline void MY_FREE(void *p)
+{
+ if (p) {
+ MU_LOCK(hlock);
+ nibufs--;
+ MU_UNLOCK(hlock);
+ free(p);
+ }
+}
+#else
+#define MY_MALLOC malloc
+#define MY_CALLOC calloc
+#define MY_FREE free
+#endif
+
+static inline bool_t
+locked_marshal(RpcUdpServer s, XDR *xdrs)
+{
+bool_t rval;
+ MU_LOCK(s->authlock);
+ rval = AUTH_MARSHALL(s->auth, xdrs);
+ MU_UNLOCK(s->authlock);
+ return rval;
+}
+
+/* Locked operations on a server's auth object */
+static inline bool_t
+locked_validate(RpcUdpServer s, struct opaque_auth *v)
+{
+bool_t rval;
+ MU_LOCK(s->authlock);
+ rval = AUTH_VALIDATE(s->auth, v);
+ MU_UNLOCK(s->authlock);
+ return rval;
+}
+
+static inline bool_t
+locked_refresh(RpcUdpServer s)
+{
+bool_t rval;
+ MU_LOCK(s->authlock);
+ rval = AUTH_REFRESH(s->auth);
+ MU_UNLOCK(s->authlock);
+ return rval;
+}
+
+/* Create a server object
+ *
+ */
+enum clnt_stat
+rpcUdpServerCreate(
+ struct sockaddr_in *paddr,
+ rpcprog_t prog,
+ rpcvers_t vers,
+ u_long uid,
+ u_long gid,
+ RpcUdpServer *psrv
+ )
+{
+RpcUdpServer rval;
+u_short port;
+char hname[MAX_MACHINE_NAME + 1];
+int theuid, thegid;
+int thegids[NGRPS];
+gid_t gids[NGROUPS];
+int len,i;
+AUTH *auth;
+enum clnt_stat pmap_err;
+struct pmap pmaparg;
+
+ if ( gethostname(hname, MAX_MACHINE_NAME) ) {
+ fprintf(stderr,
+ "RPCIO - error: I have no hostname ?? (%s)\n",
+ strerror(errno));
+ return RPC_UNKNOWNHOST;
+ }
+
+ if ( (len = getgroups(NGROUPS, gids) < 0 ) ) {
+ fprintf(stderr,
+ "RPCIO - error: I unable to get group ids (%s)\n",
+ strerror(errno));
+ return RPC_FAILED;
+ }
+
+ if ( len > NGRPS )
+ len = NGRPS;
+
+ for (i=0; i<len; i++)
+ thegids[i] = (int)gids[i];
+
+ theuid = (int) ((RPCIOD_DEFAULT_ID == uid) ? geteuid() : uid);
+ thegid = (int) ((RPCIOD_DEFAULT_ID == gid) ? getegid() : gid);
+
+ if ( !(auth = authunix_create(hname, theuid, thegid, len, thegids)) ) {
+ fprintf(stderr,
+ "RPCIO - error: unable to create RPC AUTH\n");
+ return RPC_FAILED;
+ }
+
+ /* if they specified no port try to ask the portmapper */
+ if (!paddr->sin_port) {
+
+ paddr->sin_port = htons(PMAPPORT);
+
+ pmaparg.pm_prog = prog;
+ pmaparg.pm_vers = vers;
+ pmaparg.pm_prot = IPPROTO_UDP;
+ pmaparg.pm_port = 0; /* not needed or used */
+
+
+ /* dont use non-reentrant pmap_getport ! */
+
+ pmap_err = rpcUdpCallRp(
+ paddr,
+ PMAPPROG,
+ PMAPVERS,
+ PMAPPROC_GETPORT,
+ xdr_pmap,
+ &pmaparg,
+ xdr_u_short,
+ &port,
+ uid,
+ gid,
+ 0);
+
+ if ( RPC_SUCCESS != pmap_err ) {
+ paddr->sin_port = 0;
+ return pmap_err;
+ }
+
+ paddr->sin_port = htons(port);
+ }
+
+ if (0==paddr->sin_port) {
+ return RPC_PROGNOTREGISTERED;
+ }
+
+ rval = (RpcUdpServer)MY_MALLOC(sizeof(*rval));
+ memset(rval, 0, sizeof(*rval));
+
+ if (!inet_ntop(AF_INET, &paddr->sin_addr, rval->name, sizeof(rval->name)))
+ sprintf(rval->name,"?.?.?.?");
+ rval->addr.sin = *paddr;
+
+ /* start with a long retransmission interval - it
+ * will be adapted dynamically
+ */
+ rval->retry_period = RPCIOD_RETX_CAP_S * ticksPerSec;
+
+ rval->auth = auth;
+
+ MU_CREAT( &rval->authlock );
+
+ /* link into list */
+ MU_LOCK( llock );
+ rval->next = rpcUdpServers;
+ rpcUdpServers = rval;
+ MU_UNLOCK( llock );
+
+ *psrv = rval;
+ return RPC_SUCCESS;
+}
+
+void
+rpcUdpServerDestroy(RpcUdpServer s)
+{
+RpcUdpServer prev;
+ if (!s)
+ return;
+ /* we should probably verify (but how?) that nobody
+ * (at least: no outstanding XACTs) is using this
+ * server;
+ */
+
+ /* remove from server list */
+ MU_LOCK(llock);
+ prev = rpcUdpServers;
+ if ( s == prev ) {
+ rpcUdpServers = s->next;
+ } else {
+ for ( ; prev ; prev = prev->next) {
+ if (prev->next == s) {
+ prev->next = s->next;
+ break;
+ }
+ }
+ }
+ MU_UNLOCK(llock);
+
+ /* MUST have found it */
+ assert(prev);
+
+ auth_destroy(s->auth);
+
+ MU_DESTROY(s->authlock);
+ MY_FREE(s);
+}
+
+int
+rpcUdpStats(FILE *f)
+{
+RpcUdpServer s;
+
+ if (!f) f = stdout;
+
+ fprintf(f,"RPCIOD statistics:\n");
+
+ MU_LOCK(llock);
+ for (s = rpcUdpServers; s; s=s->next) {
+ fprintf(f,"\nServer -- %s:\n", s->name);
+ fprintf(f," requests sent: %10ld, retransmitted: %10ld\n",
+ s->requests, s->retrans);
+ fprintf(f," timed out: %10ld, send errors: %10ld\n",
+ s->timeouts, s->errors);
+ fprintf(f," current retransmission interval: %dms\n",
+ (unsigned)(s->retry_period * 1000 / ticksPerSec) );
+ }
+ MU_UNLOCK(llock);
+
+ return 0;
+}
+
+RpcUdpXact
+rpcUdpXactCreate(
+ u_long program,
+ u_long version,
+ u_long size
+ )
+{
+RpcUdpXact rval=0;
+struct rpc_msg header;
+register int i,j;
+
+ if (!size)
+ size = UDPMSGSIZE;
+ /* word align */
+ size = (size + 3) & ~3;
+
+ rval = (RpcUdpXact)MY_CALLOC(1,sizeof(*rval) - sizeof(rval->obuf) + size);
+
+ if (rval) {
+
+ header.rm_xid = 0;
+ header.rm_direction = CALL;
+ header.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ header.rm_call.cb_prog = program;
+ header.rm_call.cb_vers = version;
+ xdrmem_create(&(rval->xdrs), rval->obuf.buf, size, XDR_ENCODE);
+
+ if (!xdr_callhdr(&(rval->xdrs), &header)) {
+ MY_FREE(rval);
+ return 0;
+ }
+ /* pick a free table slot and initialize the XID */
+ rval->obuf.xid = time(0) ^ (uintptr_t)rval;
+ MU_LOCK(hlock);
+ rval->obuf.xid = (xidHashSeed++ ^ ((uintptr_t)rval>>10)) & XACT_HASH_MSK;
+ i=j=(rval->obuf.xid & XACT_HASH_MSK);
+ if (msgQ) {
+ /* if there's no message queue, refuse to
+ * give them transactions; we might be in the process to
+ * go away...
+ */
+ do {
+ i=(i+1) & XACT_HASH_MSK; /* cheap modulo */
+ if (!xactHashTbl[i]) {
+#if (DEBUG) & DEBUG_TRACE_XACT
+ fprintf(stderr,"RPCIO: entering index %i, val %x\n",i,rval);
+#endif
+ xactHashTbl[i]=rval;
+ j=-1;
+ break;
+ }
+ } while (i!=j);
+ }
+ MU_UNLOCK(hlock);
+ if (i==j) {
+ XDR_DESTROY(&rval->xdrs);
+ MY_FREE(rval);
+ return 0;
+ }
+ rval->obuf.xid = xidUpper[i] | i;
+ rval->xdrpos = XDR_GETPOS(&(rval->xdrs));
+ rval->obufsize = size;
+ }
+ return rval;
+}
+
+void
+rpcUdpXactDestroy(RpcUdpXact xact)
+{
+int i = xact->obuf.xid & XACT_HASH_MSK;
+
+#if (DEBUG) & DEBUG_TRACE_XACT
+ fprintf(stderr,"RPCIO: removing index %i, val %x\n",i,xact);
+#endif
+
+ ASSERT( xactHashTbl[i]==xact );
+
+ MU_LOCK(hlock);
+ xactHashTbl[i]=0;
+ /* remember XID we used last time so we can avoid
+ * reusing the same one (incremented by rpcUdpSend routine)
+ */
+ xidUpper[i] = xact->obuf.xid & ~XACT_HASH_MSK;
+ MU_UNLOCK(hlock);
+
+ bufFree(&xact->ibuf);
+
+ XDR_DESTROY(&xact->xdrs);
+ MY_FREE(xact);
+}
+
+
+
+/* Send a transaction, i.e. enqueue it to the
+ * RPC daemon who will actually send it.
+ */
+enum clnt_stat
+rpcUdpSend(
+ RpcUdpXact xact,
+ RpcUdpServer srvr,
+ struct timeval *timeout,
+ u_long proc,
+ xdrproc_t xres, caddr_t pres,
+ xdrproc_t xargs, caddr_t pargs,
+ ...
+ )
+{
+register XDR *xdrs;
+unsigned long ms;
+va_list ap;
+
+ va_start(ap,pargs);
+
+ if (!timeout)
+ timeout = RPCIOD_DEFAULT_TIMEOUT;
+
+ ms = 1000 * timeout->tv_sec + timeout->tv_usec/1000;
+
+ /* round lifetime to closest # of ticks */
+ xact->lifetime = (ms * ticksPerSec + 500) / 1000;
+ if ( 0 == xact->lifetime )
+ xact->lifetime = 1;
+
+#if (DEBUG) & DEBUG_TIMEOUT
+ {
+ static int once=0;
+ if (!once++) {
+ fprintf(stderr,
+ "Initial lifetime: %i (ticks)\n",
+ xact->lifetime);
+ }
+ }
+#endif
+
+ xact->tolive = xact->lifetime;
+
+ xact->xres = xres;
+ xact->pres = pres;
+ xact->server = srvr;
+
+ xdrs = &xact->xdrs;
+ xdrs->x_op = XDR_ENCODE;
+ /* increment transaction ID */
+ xact->obuf.xid += XACT_HASHS;
+ XDR_SETPOS(xdrs, xact->xdrpos);
+ if ( !XDR_PUTLONG(xdrs,(long*)&proc) || !locked_marshal(srvr, xdrs) ||
+ !xargs(xdrs, pargs) ) {
+ va_end(ap);
+ return(xact->status.re_status=RPC_CANTENCODEARGS);
+ }
+ while ((xargs=va_arg(ap,xdrproc_t))) {
+ if (!xargs(xdrs, va_arg(ap,caddr_t)))
+ va_end(ap);
+ return(xact->status.re_status=RPC_CANTENCODEARGS);
+ }
+
+ va_end(ap);
+
+ rtems_task_ident(RTEMS_SELF, RTEMS_WHO_AM_I, &xact->requestor);
+ if ( rtems_message_queue_send( msgQ, &xact, sizeof(xact)) ) {
+ return RPC_CANTSEND;
+ }
+ /* wakeup the rpciod */
+ ASSERT( RTEMS_SUCCESSFUL==rtems_event_send(rpciod, RPCIOD_TX_EVENT) );
+
+ return RPC_SUCCESS;
+}
+
+/* Block for the RPC reply to an outstanding
+ * transaction.
+ * The caller is woken by the RPC daemon either
+ * upon reception of the reply or on timeout.
+ */
+enum clnt_stat
+rpcUdpRcv(RpcUdpXact xact)
+{
+int refresh;
+XDR reply_xdrs;
+struct rpc_msg reply_msg;
+rtems_status_code status;
+rtems_event_set gotEvents;
+
+ refresh = 0;
+
+ do {
+
+ /* block for the reply */
+ status = rtems_event_receive(
+ RTEMS_RPC_EVENT,
+ RTEMS_WAIT | RTEMS_EVENT_ANY,
+ RTEMS_NO_TIMEOUT,
+ &gotEvents);
+ ASSERT( status == RTEMS_SUCCESSFUL );
+
+ if (xact->status.re_status) {
+#ifdef MBUF_RX
+ /* add paranoia */
+ ASSERT( !xact->ibuf );
+#endif
+ return xact->status.re_status;
+ }
+
+#ifdef MBUF_RX
+ xdrmbuf_create(&reply_xdrs, xact->ibuf, XDR_DECODE);
+#else
+ xdrmem_create(&reply_xdrs, xact->ibuf->buf, xact->ibufsize, XDR_DECODE);
+#endif
+
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = xact->pres;
+ reply_msg.acpted_rply.ar_results.proc = xact->xres;
+
+ if (xdr_replymsg(&reply_xdrs, &reply_msg)) {
+ /* OK */
+ _seterr_reply(&reply_msg, &xact->status);
+ if (RPC_SUCCESS == xact->status.re_status) {
+ if ( !locked_validate(xact->server,
+ &reply_msg.acpted_rply.ar_verf) ) {
+ xact->status.re_status = RPC_AUTHERROR;
+ xact->status.re_why = AUTH_INVALIDRESP;
+ }
+ if (reply_msg.acpted_rply.ar_verf.oa_base) {
+ reply_xdrs.x_op = XDR_FREE;
+ xdr_opaque_auth(&reply_xdrs, &reply_msg.acpted_rply.ar_verf);
+ }
+ refresh = 0;
+ } else {
+ /* should we try to refresh our credentials ? */
+ if ( !refresh ) {
+ /* had never tried before */
+ refresh = RPCIOD_REFRESH;
+ }
+ }
+ } else {
+ reply_xdrs.x_op = XDR_FREE;
+ xdr_replymsg(&reply_xdrs, &reply_msg);
+ xact->status.re_status = RPC_CANTDECODERES;
+ }
+ XDR_DESTROY(&reply_xdrs);
+
+ bufFree(&xact->ibuf);
+
+#ifndef MBUF_RX
+ xact->ibufsize = 0;
+#endif
+
+ if (refresh && locked_refresh(xact->server)) {
+ rtems_task_ident(RTEMS_SELF, RTEMS_WHO_AM_I, &xact->requestor);
+ if ( rtems_message_queue_send(msgQ, &xact, sizeof(xact)) ) {
+ return RPC_CANTSEND;
+ }
+ /* wakeup the rpciod */
+ fprintf(stderr,"RPCIO INFO: refreshing my AUTH\n");
+ ASSERT( RTEMS_SUCCESSFUL==rtems_event_send(rpciod, RPCIOD_TX_EVENT) );
+ }
+
+ } while ( 0 && refresh-- > 0 );
+
+ return xact->status.re_status;
+}
+
+
+/* On RTEMS, I'm told to avoid select(); this seems to
+ * be more efficient
+ */
+static void
+rxWakeupCB(struct socket *sock, void *arg)
+{
+ rtems_id *rpciod = (rtems_id*) arg;
+ rtems_event_send(*rpciod, RPCIOD_RX_EVENT);
+}
+
+int
+rpcUdpInit(void)
+{
+int s;
+rtems_status_code status;
+int noblock = 1;
+struct sockwakeup wkup;
+
+ if (ourSock < 0) {
+ fprintf(stderr,"RTEMS-RPCIOD $Release$, " \
+ "Till Straumann, Stanford/SLAC/SSRL 2002, " \
+ "See LICENSE file for licensing info.\n");
+
+ ourSock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (ourSock>=0) {
+ bindresvport(ourSock,(struct sockaddr_in*)0);
+ s = ioctl(ourSock, FIONBIO, (char*)&noblock);
+ assert( s == 0 );
+ /* assume nobody tampers with the clock !! */
+ ticksPerSec = rtems_clock_get_ticks_per_second();
+ MU_CREAT( &hlock );
+ MU_CREAT( &llock );
+
+ if ( !rpciodPriority ) {
+ /* use configured networking priority */
+ if ( ! (rpciodPriority = rtems_bsdnet_config.network_task_priority) )
+ rpciodPriority = RPCIOD_PRIO; /* fallback value */
+ }
+
+ status = rtems_task_create(
+ rtems_build_name('R','P','C','d'),
+ rpciodPriority,
+ RPCIOD_STACK,
+ RTEMS_DEFAULT_MODES,
+ /* fprintf saves/restores FP registers on PPC :-( */
+ RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
+ &rpciod);
+ assert( status == RTEMS_SUCCESSFUL );
+
+ wkup.sw_pfn = rxWakeupCB;
+ wkup.sw_arg = &rpciod;
+ assert( 0==setsockopt(ourSock, SOL_SOCKET, SO_RCVWAKEUP, &wkup, sizeof(wkup)) );
+ status = rtems_message_queue_create(
+ rtems_build_name('R','P','C','q'),
+ RPCIOD_QDEPTH,
+ sizeof(RpcUdpXact),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &msgQ);
+ assert( status == RTEMS_SUCCESSFUL );
+ status = rtems_task_start( rpciod, rpcio_daemon, 0 );
+ assert( status == RTEMS_SUCCESSFUL );
+
+ } else {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+int
+rpcUdpCleanup(void)
+{
+ rtems_semaphore_create(
+ rtems_build_name('R','P','C','f'),
+ 0,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ 0,
+ &fini);
+ rtems_event_send(rpciod, RPCIOD_KILL_EVENT);
+ /* synchronize with daemon */
+ rtems_semaphore_obtain(fini, RTEMS_WAIT, 5*ticksPerSec);
+ /* if the message queue is still there, something went wrong */
+ if (!msgQ) {
+ rtems_task_delete(rpciod);
+ }
+ rtems_semaphore_delete(fini);
+ return (msgQ !=0);
+}
+
+/* Another API - simpler but less efficient.
+ * For each RPCall, a server and a Xact
+ * are created and destroyed on the fly.
+ *
+ * This should be used for infrequent calls
+ * (e.g. a NFS mount request).
+ *
+ * This is roughly compatible with the original
+ * clnt_call() etc. API - but it uses our
+ * daemon and is fully reentrant.
+ */
+enum clnt_stat
+rpcUdpClntCreate(
+ struct sockaddr_in *psaddr,
+ rpcprog_t prog,
+ rpcvers_t vers,
+ u_long uid,
+ u_long gid,
+ RpcUdpClnt *pclnt
+)
+{
+RpcUdpXact x;
+RpcUdpServer s;
+enum clnt_stat err;
+
+ if ( RPC_SUCCESS != (err=rpcUdpServerCreate(psaddr, prog, vers, uid, gid, &s)) )
+ return err;
+
+ if ( !(x=rpcUdpXactCreate(prog, vers, UDPMSGSIZE)) ) {
+ rpcUdpServerDestroy(s);
+ return RPC_FAILED;
+ }
+ /* TODO: could maintain a server cache */
+
+ x->server = s;
+
+ *pclnt = x;
+
+ return RPC_SUCCESS;
+}
+
+void
+rpcUdpClntDestroy(RpcUdpClnt xact)
+{
+ rpcUdpServerDestroy(xact->server);
+ rpcUdpXactDestroy(xact);
+}
+
+enum clnt_stat
+rpcUdpClntCall(
+ RpcUdpClnt xact,
+ u_long proc,
+ XdrProcT xargs,
+ CaddrT pargs,
+ XdrProcT xres,
+ CaddrT pres,
+ struct timeval *timeout
+ )
+{
+enum clnt_stat stat;
+
+ if ( (stat = rpcUdpSend(xact, xact->server, timeout, proc,
+ xres, pres,
+ xargs, pargs,
+ 0)) ) {
+ fprintf(stderr,"RPCIO Send failed: %i\n",stat);
+ return stat;
+ }
+ return rpcUdpRcv(xact);
+}
+
+/* a yet simpler interface */
+enum clnt_stat
+rpcUdpCallRp(
+ struct sockaddr_in *psrvr,
+ u_long prog,
+ u_long vers,
+ u_long proc,
+ XdrProcT xargs,
+ CaddrT pargs,
+ XdrProcT xres,
+ CaddrT pres,
+ u_long uid, /* RPCIO_DEFAULT_ID picks default */
+ u_long gid, /* RPCIO_DEFAULT_ID picks default */
+ struct timeval *timeout /* NULL picks default */
+)
+{
+RpcUdpClnt clp;
+enum clnt_stat stat;
+
+ stat = rpcUdpClntCreate(
+ psrvr,
+ prog,
+ vers,
+ uid,
+ gid,
+ &clp);
+
+ if ( RPC_SUCCESS != stat )
+ return stat;
+
+ stat = rpcUdpClntCall(
+ clp,
+ proc,
+ xargs, pargs,
+ xres, pres,
+ timeout);
+
+ rpcUdpClntDestroy(clp);
+
+ return stat;
+}
+
+/* linked list primitives */
+static void
+nodeXtract(ListNode n)
+{
+ if (n->prev)
+ n->prev->next = n->next;
+ if (n->next)
+ n->next->prev = n->prev;
+ n->next = n->prev = 0;
+}
+
+static void
+nodeAppend(ListNode l, ListNode n)
+{
+ if ( (n->next = l->next) )
+ n->next->prev = n;
+ l->next = n;
+ n->prev = l;
+
+}
+
+/* this code does the work */
+static void
+rpcio_daemon(rtems_task_argument arg)
+{
+rtems_status_code stat;
+RpcUdpXact xact;
+RpcUdpServer srv;
+rtems_interval next_retrans, then, unow;
+long now; /* need to do signed comparison with age! */
+rtems_event_set events;
+ListNode newList;
+size_t size;
+rtems_id q = 0;
+ListNodeRec listHead = {0, 0};
+unsigned long epoch = RPCIOD_EPOCH_SECS * ticksPerSec;
+unsigned long max_period = RPCIOD_RETX_CAP_S * ticksPerSec;
+rtems_status_code status;
+
+
+ then = rtems_clock_get_ticks_since_boot();
+
+ for (next_retrans = epoch;;) {
+
+ if ( RTEMS_SUCCESSFUL !=
+ (stat = rtems_event_receive(
+ RPCIOD_RX_EVENT | RPCIOD_TX_EVENT | RPCIOD_KILL_EVENT,
+ RTEMS_WAIT | RTEMS_EVENT_ANY,
+ next_retrans,
+ &events)) ) {
+ ASSERT( RTEMS_TIMEOUT == stat );
+ events = 0;
+ }
+
+ if (events & RPCIOD_KILL_EVENT) {
+ int i;
+
+#if (DEBUG) & DEBUG_EVENTS
+ fprintf(stderr,"RPCIO: got KILL event\n");
+#endif
+
+ MU_LOCK(hlock);
+ for (i=XACT_HASHS-1; i>=0; i--) {
+ if (xactHashTbl[i]) {
+ break;
+ }
+ }
+ if (i<0) {
+ /* prevent them from creating and enqueueing more messages */
+ q=msgQ;
+ /* messages queued after we executed this assignment will fail */
+ msgQ=0;
+ }
+ MU_UNLOCK(hlock);
+ if (i>=0) {
+ fprintf(stderr,"RPCIO There are still transactions circulating; I refuse to go away\n");
+ fprintf(stderr,"(1st in slot %i)\n",i);
+ rtems_semaphore_release(fini);
+ } else {
+ break;
+ }
+ }
+
+ unow = rtems_clock_get_ticks_since_boot();
+
+ /* measure everything relative to then to protect against
+ * rollover
+ */
+ now = unow - then;
+
+ /* NOTE: we don't lock the hash table while we are operating
+ * on transactions; the paradigm is that we 'own' a particular
+ * transaction (and hence it's hash table slot) from the
+ * time the xact was put into the message queue until we
+ * wake up the requestor.
+ */
+
+ if (RPCIOD_RX_EVENT & events) {
+
+#if (DEBUG) & DEBUG_EVENTS
+ fprintf(stderr,"RPCIO: got RX event\n");
+#endif
+
+ while ((xact=sockRcv())) {
+
+ /* extract from the retransmission list */
+ nodeXtract(&xact->node);
+
+ /* change the ID - there might already be
+ * a retransmission on the way. When it's
+ * reply arrives we must not find it's ID
+ * in the hashtable
+ */
+ xact->obuf.xid += XACT_HASHS;
+
+ xact->status.re_status = RPC_SUCCESS;
+
+ /* calculate roundtrip ticks */
+ xact->trip = now - xact->trip;
+
+ srv = xact->server;
+
+ /* adjust the server's retry period */
+ {
+ register TimeoutT rtry = srv->retry_period;
+ register TimeoutT trip = xact->trip;
+
+ ASSERT( trip >= 0 );
+
+ if ( 0==trip )
+ trip = 1;
+
+ /* retry_new = 0.75*retry_old + 0.25 * 8 * roundrip */
+ rtry = (3*rtry + (trip << 3)) >> 2;
+
+ if ( rtry > max_period )
+ rtry = max_period;
+
+ srv->retry_period = rtry;
+ }
+
+ /* wakeup requestor */
+ rtems_event_send(xact->requestor, RTEMS_RPC_EVENT);
+ }
+ }
+
+ if (RPCIOD_TX_EVENT & events) {
+
+#if (DEBUG) & DEBUG_EVENTS
+ fprintf(stderr,"RPCIO: got TX event\n");
+#endif
+
+ while (RTEMS_SUCCESSFUL == rtems_message_queue_receive(
+ msgQ,
+ &xact,
+ &size,
+ RTEMS_NO_WAIT,
+ RTEMS_NO_TIMEOUT)) {
+ /* put to the head of timeout q */
+ nodeAppend(&listHead, &xact->node);
+
+ xact->age = now;
+ xact->trip = FIRST_ATTEMPT;
+ }
+ }
+
+
+ /* work the timeout q */
+ newList = 0;
+ for ( xact=(RpcUdpXact)listHead.next;
+ xact && xact->age <= now;
+ xact=(RpcUdpXact)listHead.next ) {
+
+ /* extract from the list */
+ nodeXtract(&xact->node);
+
+ srv = xact->server;
+
+ if (xact->tolive < 0) {
+ /* this one timed out */
+ xact->status.re_errno = ETIMEDOUT;
+ xact->status.re_status = RPC_TIMEDOUT;
+
+ srv->timeouts++;
+
+ /* Change the ID - there might still be
+ * a reply on the way. When it arrives we
+ * must not find it's ID in the hash table
+ *
+ * Thanks to Steven Johnson for hunting this
+ * one down.
+ */
+ xact->obuf.xid += XACT_HASHS;
+
+#if (DEBUG) & DEBUG_TIMEOUT
+ fprintf(stderr,"RPCIO XACT timed out; waking up requestor\n");
+#endif
+ if ( rtems_event_send(xact->requestor, RTEMS_RPC_EVENT) ) {
+ rtems_panic("RPCIO PANIC file %s line: %i, requestor id was 0x%08x",
+ __FILE__,
+ __LINE__,
+ xact->requestor);
+ }
+
+ } else {
+ int len;
+
+ len = (int)XDR_GETPOS(&xact->xdrs);
+
+#ifdef MBUF_TX
+ xact->refcnt = 1; /* sendto itself */
+#endif
+ if ( len != SENDTO( ourSock,
+ xact->obuf.buf,
+ len,
+ 0,
+ &srv->addr.sa,
+ sizeof(srv->addr.sin)
+#ifdef MBUF_TX
+ , xact,
+ paranoia_free,
+ paranoia_ref
+#endif
+ ) ) {
+
+ xact->status.re_errno = errno;
+ xact->status.re_status = RPC_CANTSEND;
+ srv->errors++;
+
+ /* wakeup requestor */
+ fprintf(stderr,"RPCIO: SEND failure\n");
+ status = rtems_event_send(xact->requestor, RTEMS_RPC_EVENT);
+ assert( status == RTEMS_SUCCESSFUL );
+
+ } else {
+ /* send successful; calculate retransmission time
+ * and enqueue to temporary list
+ */
+ if (FIRST_ATTEMPT != xact->trip) {
+#if (DEBUG) & DEBUG_TIMEOUT
+ fprintf(stderr,
+ "timed out; tolive is %i (ticks), retry period is %i (ticks)\n",
+ xact->tolive,
+ srv->retry_period);
+#endif
+ /* this is a real retry; we backup
+ * the server's retry interval
+ */
+ if ( srv->retry_period < max_period ) {
+
+ /* If multiple transactions for this server
+ * fail (e.g. because it died) this will
+ * back-off very agressively (doubling
+ * the retransmission period for every
+ * timed out transaction up to the CAP limit)
+ * which is desirable - single packet failure
+ * is treated more gracefully by this algorithm.
+ */
+
+ srv->retry_period<<=1;
+#if (DEBUG) & DEBUG_TIMEOUT
+ fprintf(stderr,
+ "adjusted to; retry period %i\n",
+ srv->retry_period);
+#endif
+ } else {
+ /* never wait longer than RPCIOD_RETX_CAP_S seconds */
+ fprintf(stderr,
+ "RPCIO: server '%s' not responding - still trying\n",
+ srv->name);
+ }
+ if ( 0 == ++srv->retrans % 1000) {
+ fprintf(stderr,
+ "RPCIO - statistics: already %li retries to server %s\n",
+ srv->retrans,
+ srv->name);
+ }
+ } else {
+ srv->requests++;
+ }
+ xact->trip = now;
+ {
+ long capped_period = srv->retry_period;
+ if ( xact->lifetime < capped_period )
+ capped_period = xact->lifetime;
+ xact->age = now + capped_period;
+ xact->tolive -= capped_period;
+ }
+ /* enqueue to the list of newly sent transactions */
+ xact->node.next = newList;
+ newList = &xact->node;
+#if (DEBUG) & DEBUG_TIMEOUT
+ fprintf(stderr,
+ "XACT (0x%08x) age is 0x%x, now: 0x%x\n",
+ xact,
+ xact->age,
+ now);
+#endif
+ }
+ }
+ }
+
+ /* insert the newly sent transactions into the
+ * sorted retransmission list
+ */
+ for (; (xact = (RpcUdpXact)newList); ) {
+ register ListNode p,n;
+ newList = newList->next;
+ for ( p=&listHead; (n=p->next) && xact->age > ((RpcUdpXact)n)->age; p=n )
+ /* nothing else to do */;
+ nodeAppend(p, &xact->node);
+ }
+
+ if (now > epoch) {
+ /* every now and then, readjust the epoch */
+ register ListNode n;
+ then += now;
+ for (n=listHead.next; n; n=n->next) {
+ /* readjust outstanding time intervals subject to the
+ * condition that the 'absolute' time must remain
+ * the same. 'age' and 'trip' are measured with
+ * respect to 'then' - hence:
+ *
+ * abs_age == old_age + old_then == new_age + new_then
+ *
+ * ==> new_age = old_age + old_then - new_then == old_age - 'now'
+ */
+ ((RpcUdpXact)n)->age -= now;
+ ((RpcUdpXact)n)->trip -= now;
+#if (DEBUG) & DEBUG_TIMEOUT
+ fprintf(stderr,
+ "readjusted XACT (0x%08x); age is 0x%x, trip: 0x%x now: 0x%x\n",
+ (RpcUdpXact)n,
+ ((RpcUdpXact)n)->trip,
+ ((RpcUdpXact)n)->age,
+ now);
+#endif
+ }
+ now = 0;
+ }
+
+ next_retrans = listHead.next ?
+ ((RpcUdpXact)listHead.next)->age - now :
+ epoch; /* make sure we don't miss updating the epoch */
+#if (DEBUG) & DEBUG_TIMEOUT
+ fprintf(stderr,"RPCIO: next timeout is %x\n",next_retrans);
+#endif
+ }
+ /* close our socket; shut down the receiver */
+ close(ourSock);
+
+#if 0 /* if we get here, no transactions exist, hence there can be none
+ * in the queue whatsoever
+ */
+ /* flush the message queue */
+ while (RTEMS_SUCCESSFUL == rtems_message_queue_receive(
+ q,
+ &xact,
+ &size,
+ RTEMS_NO_WAIT,
+ RTEMS_NO_TIMEOUT)) {
+ /* TODO enque xact */
+ }
+
+ /* flush all outstanding transactions */
+
+ for (xact=((RpcUdpXact)listHead.next); xact; xact=((RpcUdpXact)xact->node.next)) {
+ xact->status.re_status = RPC_TIMEDOUT;
+ rtems_event_send(xact->requestor, RTEMS_RPC_EVENT);
+ }
+#endif
+
+ rtems_message_queue_delete(q);
+
+ MU_DESTROY(hlock);
+
+ fprintf(stderr,"RPC daemon exited...\n");
+
+ rtems_semaphore_release(fini);
+ rtems_task_suspend(RTEMS_SELF);
+}
+
+
+/* support for transaction 'pools'. A number of XACT objects
+ * is always kept around. The initial number is 0 but it
+ * is allowed to grow up to a maximum.
+ * If the need grows beyond the maximum, behavior depends:
+ * Users can either block until a transaction becomes available,
+ * they can create a new XACT on the fly or get an error
+ * if no free XACT is available from the pool.
+ */
+
+RpcUdpXactPool
+rpcUdpXactPoolCreate(
+ rpcprog_t prog, rpcvers_t version,
+ int xactsize, int poolsize)
+{
+RpcUdpXactPool rval = MY_MALLOC(sizeof(*rval));
+rtems_status_code status;
+
+ ASSERT( rval );
+ status = rtems_message_queue_create(
+ rtems_build_name('R','P','C','p'),
+ poolsize,
+ sizeof(RpcUdpXact),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &rval->box);
+ assert( status == RTEMS_SUCCESSFUL );
+
+ rval->prog = prog;
+ rval->version = version;
+ rval->xactSize = xactsize;
+ return rval;
+}
+
+void
+rpcUdpXactPoolDestroy(RpcUdpXactPool pool)
+{
+RpcUdpXact xact;
+
+ while ((xact = rpcUdpXactPoolGet(pool, XactGetFail))) {
+ rpcUdpXactDestroy(xact);
+ }
+ rtems_message_queue_delete(pool->box);
+ MY_FREE(pool);
+}
+
+RpcUdpXact
+rpcUdpXactPoolGet(RpcUdpXactPool pool, XactPoolGetMode mode)
+{
+RpcUdpXact xact = 0;
+size_t size;
+
+ if (RTEMS_SUCCESSFUL != rtems_message_queue_receive(
+ pool->box,
+ &xact,
+ &size,
+ XactGetWait == mode ?
+ RTEMS_WAIT : RTEMS_NO_WAIT,
+ RTEMS_NO_TIMEOUT)) {
+
+ /* nothing found in box; should we create a new one ? */
+
+ xact = (XactGetCreate == mode) ?
+ rpcUdpXactCreate(
+ pool->prog,
+ pool->version,
+ pool->xactSize) : 0 ;
+ if (xact)
+ xact->pool = pool;
+
+ }
+ return xact;
+}
+
+void
+rpcUdpXactPoolPut(RpcUdpXact xact)
+{
+RpcUdpXactPool pool;
+
+ pool = xact->pool;
+ ASSERT( pool );
+
+ if (RTEMS_SUCCESSFUL != rtems_message_queue_send(
+ pool->box,
+ &xact,
+ sizeof(xact)))
+ rpcUdpXactDestroy(xact);
+}
+
+#ifdef MBUF_RX
+
+/* WORKAROUND: include sys/mbuf.h (or other bsdnet headers) only
+ * _after_ using malloc()/free() & friends because
+ * the RTEMS/BSDNET headers redefine those :-(
+ */
+
+#define _KERNEL
+#include <sys/mbuf.h>
+
+ssize_t
+recv_mbuf_from(int s, struct mbuf **ppm, long len, struct sockaddr *fromaddr, int *fromlen);
+
+static void
+bufFree(struct mbuf **m)
+{
+ if (*m) {
+ rtems_bsdnet_semaphore_obtain();
+ m_freem(*m);
+ rtems_bsdnet_semaphore_release();
+ *m = 0;
+ }
+}
+#endif
+
+#ifdef MBUF_TX
+static void
+paranoia_free(caddr_t closure, u_int size)
+{
+#if (DEBUG)
+RpcUdpXact xact = (RpcUdpXact)closure;
+int len = (int)XDR_GETPOS(&xact->xdrs);
+
+ ASSERT( --xact->refcnt >= 0 && size == len );
+#endif
+}
+
+static void
+paranoia_ref (caddr_t closure, u_int size)
+{
+#if (DEBUG)
+RpcUdpXact xact = (RpcUdpXact)closure;
+int len = (int)XDR_GETPOS(&xact->xdrs);
+ ASSERT( size == len );
+ xact->refcnt++;
+#endif
+}
+#endif
+
+/* receive from a socket and find
+ * the transaction corresponding to the
+ * transaction ID received in the server
+ * reply.
+ *
+ * The semantics of the 'pibuf' pointer are
+ * as follows:
+ *
+ * MBUF_RX:
+ *
+ */
+
+#define RPCIOD_RXBUFSZ UDPMSGSIZE
+
+static RpcUdpXact
+sockRcv(void)
+{
+int len,i;
+uint32_t xid;
+union {
+ struct sockaddr_in sin;
+ struct sockaddr sa;
+} fromAddr;
+int fromLen = sizeof(fromAddr.sin);
+RxBuf ibuf = 0;
+RpcUdpXact xact = 0;
+
+ do {
+
+ /* rcv_mbuf() and recvfrom() differ in that the
+ * former allocates buffers and passes them back
+ * to us whereas the latter requires us to provide
+ * buffer space.
+ * Hence, in the first case whe have to make sure
+ * no old buffer is leaked - in the second case,
+ * we might well re-use an old buffer but must
+ * make sure we have one allocated
+ */
+#ifdef MBUF_RX
+ if (ibuf)
+ bufFree(&ibuf);
+
+ len = recv_mbuf_from(
+ ourSock,
+ &ibuf,
+ RPCIOD_RXBUFSZ,
+ &fromAddr.sa,
+ &fromLen);
+#else
+ if ( !ibuf )
+ ibuf = (RpcBuf)MY_MALLOC(RPCIOD_RXBUFSZ);
+ if ( !ibuf )
+ goto cleanup; /* no memory - drop this message */
+
+ len = recvfrom(ourSock,
+ ibuf->buf,
+ RPCIOD_RXBUFSZ,
+ 0,
+ &fromAddr.sa,
+ &fromLen);
+#endif
+
+ if (len <= 0) {
+ if (EAGAIN != errno)
+ fprintf(stderr,"RECV failed: %s\n",strerror(errno));
+ goto cleanup;
+ }
+
+#if (DEBUG) & DEBUG_PACKLOSS
+ if ( (unsigned)rand() < DEBUG_PACKLOSS_FRACT ) {
+ /* lose packets once in a while */
+ static int xxx = 0;
+ if ( ++xxx % 16 == 0 )
+ fprintf(stderr,"DEBUG: dropped %i packets, so far...\n",xxx);
+ if ( ibuf )
+ bufFree( &ibuf );
+ continue;
+ }
+#endif
+
+ i = (xid=XID(ibuf)) & XACT_HASH_MSK;
+
+ if ( !(xact=xactHashTbl[i]) ||
+ xact->obuf.xid != xid ||
+#ifdef REJECT_SERVERIP_MISMATCH
+ xact->server->addr.sin.sin_addr.s_addr != fromAddr.sin.sin_addr.s_addr ||
+#endif
+ xact->server->addr.sin.sin_port != fromAddr.sin.sin_port ) {
+
+ if (xact) {
+ if (
+#ifdef REJECT_SERVERIP_MISMATCH
+ xact->server->addr.sin.sin_addr.s_addr == fromAddr.sin.sin_addr.s_addr &&
+#endif
+ xact->server->addr.sin.sin_port == fromAddr.sin.sin_port &&
+ ( xact->obuf.xid == xid + XACT_HASHS ||
+ xact->obuf.xid == xid + 2*XACT_HASHS )
+ ) {
+#ifndef DEBUG /* don't complain if it's just a late arrival of a retry */
+ fprintf(stderr,"RPCIO - FYI sockRcv(): dropping late/redundant retry answer\n");
+#endif
+ } else {
+ fprintf(stderr,"RPCIO WARNING sockRcv(): transaction mismatch\n");
+ fprintf(stderr,"xact: xid 0x%08" PRIx32 " -- got 0x%08" PRIx32 "\n",
+ xact->obuf.xid, xid);
+ fprintf(stderr,"xact: addr 0x%08" PRIx32 " -- got 0x%08" PRIx32 "\n",
+ xact->server->addr.sin.sin_addr.s_addr,
+ fromAddr.sin.sin_addr.s_addr);
+ fprintf(stderr,"xact: port 0x%08x -- got 0x%08x\n",
+ xact->server->addr.sin.sin_port,
+ fromAddr.sin.sin_port);
+ }
+ } else {
+ fprintf(stderr,
+ "RPCIO WARNING sockRcv(): got xid 0x%08" PRIx32 " but its slot is empty\n",
+ xid);
+ }
+ /* forget about this one and try again */
+ xact = 0;
+ }
+
+ } while ( !xact );
+
+ xact->ibuf = ibuf;
+#ifndef MBUF_RX
+ xact->ibufsize = RPCIOD_RXBUFSZ;
+#endif
+
+ return xact;
+
+cleanup:
+
+ bufFree(&ibuf);
+
+ return 0;
+}
+
+
+#include <rtems/rtems_bsdnet_internal.h>
+/* double check the event configuration; should probably globally
+ * manage system events!!
+ * We do this at the end of the file for the same reason we had
+ * included mbuf.h only a couple of lines above - see comment up
+ * there...
+ */
+#if RTEMS_RPC_EVENT & SOSLEEP_EVENT & SBWAIT_EVENT & NETISR_EVENTS
+#error ILLEGAL EVENT CONFIGURATION
+#endif
diff --git a/cpukit/libfs/src/nfsclient/src/rpcio.h b/cpukit/libfs/src/nfsclient/src/rpcio.h
new file mode 100644
index 0000000000..0d65b76dc1
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/rpcio.h
@@ -0,0 +1,209 @@
+#ifndef RPCIO_H
+#define RPCIO_H
+/* $Id$ */
+
+/* A multihreaded RPC/UDP multiplexor */
+
+/* Author: Till Straumann, <strauman@slac.stanford.edu>, 2002 */
+
+/*
+ * Authorship
+ * ----------
+ * This software (NFS-2 client implementation for RTEMS) was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2002-2007,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * The NFS-2 client implementation for RTEMS was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#ifdef __rtems
+#include <rtems.h>
+#endif
+
+#include <rpc/rpc.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/param.h>
+#include <stdarg.h>
+
+typedef struct RpcUdpServerRec_ *RpcUdpServer;
+typedef struct RpcUdpXactRec_ *RpcUdpXact;
+
+typedef RpcUdpXact RpcUdpClnt;
+
+#define RPCIOD_DEFAULT_ID 0xdef10000
+
+int
+rpcUdpInit(void);
+
+enum clnt_stat
+rpcUdpServerCreate(
+ struct sockaddr_in *paddr,
+ rpcprog_t prog,
+ rpcvers_t vers,
+ u_long uid, /* RPCIO_DEFAULT_ID picks default */
+ u_long gid, /* RPCIO_DEFAULT_ID picks default */
+ RpcUdpServer *pclnt /* new server is returned here */
+ );
+
+
+void
+rpcUdpServerDestroy(RpcUdpServer s);
+
+/* Dump statistics to a file (stdout if NULL);
+ * returns 0 for convenience
+ */
+int
+rpcUdpStats(FILE *f);
+
+enum clnt_stat
+rpcUdpClntCreate(
+ struct sockaddr_in *psaddr,
+ rpcprog_t prog,
+ rpcvers_t vers,
+ u_long uid, /* RPCIO_DEFAULT_ID picks default */
+ u_long gid, /* RPCIO_DEFAULT_ID picks default */
+ RpcUdpClnt *pclnt /* new client is returned here */
+ );
+
+void
+RpcUdpClntDestroy(RpcUdpClnt clnt);
+
+/* mute compiler warnings */
+typedef void *XdrProcT;
+typedef void *CaddrT;
+
+enum clnt_stat
+rpcUdpClntCall(
+ RpcUdpClnt clnt,
+ u_long proc,
+ XdrProcT xargs,
+ CaddrT pargs,
+ XdrProcT xres,
+ CaddrT pres,
+ struct timeval *timeout /* optional timeout; maybe NULL to pick default */
+ );
+
+RpcUdpXact
+rpcUdpXactCreate(
+ u_long program,
+ u_long version,
+ u_long size
+ );
+
+void
+rpcUdpXactDestroy(
+ RpcUdpXact xact
+ );
+
+/* send a transaction */
+enum clnt_stat
+rpcUdpSend(
+ RpcUdpXact xact,
+ RpcUdpServer srvr,
+ struct timeval *timeout, /* maybe NULL to pick default */
+ u_long proc,
+ xdrproc_t xres,
+ caddr_t pres,
+ xdrproc_t xargs,
+ caddr_t pargs,
+ ... /* 0 terminated xdrproc/pobj additional argument list */
+ );
+
+/* wait for a transaction to complete */
+enum clnt_stat
+rpcUdpRcv(RpcUdpXact xact);
+
+/* a yet simpler interface */
+enum clnt_stat
+rpcUdpCallRp(
+ struct sockaddr_in *pserver_addr,
+ u_long prog,
+ u_long vers,
+ u_long proc,
+ XdrProcT xargs,
+ CaddrT pargs,
+ XdrProcT xres,
+ CaddrT pres,
+ u_long uid, /* RPCIO_DEFAULT_ID picks default */
+ u_long gid, /* RPCIO_DEFAULT_ID picks default */
+ struct timeval *timeout /* NULL picks default */
+);
+
+
+/* manage pools of transactions */
+
+/* A pool of transactions. The idea is not to malloc/free them
+ * all the time but keep a limited number around in a 'pool'.
+ * Users who need a XACT may get it from the pool and put it back
+ * when done.
+ * The pool is implemented by RTEMS message queues who manage
+ * the required task synchronization.
+ * A requestor has different options if the pool is empty:
+ * - it can wait (block) for a XACT to become available
+ * - it can get an error status
+ * - or it can malloc an extra XACT from the heap which
+ * will eventually be released.
+ */
+
+typedef struct RpcUdpXactPoolRec_ *RpcUdpXactPool;
+
+/* NOTE: the pool is empty initially, must get messages (in
+ * GetCreate mode
+ */
+RpcUdpXactPool
+rpcUdpXactPoolCreate(
+ rpcprog_t prog, rpcvers_t version,
+ int xactsize, int poolsize);
+
+void
+rpcUdpXactPoolDestroy(RpcUdpXactPool pool);
+
+typedef enum {
+ XactGetFail, /* call fails if no transaction available */
+ XactGetWait, /* call blocks until transaction available */
+ XactGetCreate /* a new transaction is allocated (and freed when put back to the pool */
+} XactPoolGetMode;
+
+RpcUdpXact
+rpcUdpXactPoolGet(RpcUdpXactPool pool, XactPoolGetMode mode);
+
+void
+rpcUdpXactPoolPut(RpcUdpXact xact);
+
+#endif
diff --git a/cpukit/libfs/src/nfsclient/src/rpcio.modini.c b/cpukit/libfs/src/nfsclient/src/rpcio.modini.c
new file mode 100644
index 0000000000..7aa802fe51
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/rpcio.modini.c
@@ -0,0 +1,19 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "librtemsNfs.h"
+/* CEXP module support (magic init) */
+void
+_cexpModuleInitialize(void *mod)
+{
+ rpcUdpInit();
+}
+
+int
+_cexpModuleFinalize(void *mod)
+{
+ return rpcUdpCleanup();
+}
+
+
diff --git a/cpukit/libfs/src/nfsclient/src/sock_mbuf.c b/cpukit/libfs/src/nfsclient/src/sock_mbuf.c
new file mode 100644
index 0000000000..3c589d9e81
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/sock_mbuf.c
@@ -0,0 +1,283 @@
+/*
+ * $Id$
+ *
+ * NOTE:
+ * This is derived from libnetworking/rtems/rtems_syscall.c
+ *
+ * RTEMS/libnetworking LICENSING restrictions may apply
+ *
+ * Author (modifications only):
+ * Copyright: 2002, Stanford University and
+ * Till Straumann, <strauman@slac.stanford.edu>
+ * Licensing: 'LICENSE.NET' file in the RTEMS top source directory
+ * for more information.
+ */
+
+/*
+The RTEMS TCP/IP stack is a port of the FreeBSD TCP/IP stack. The following
+copyright and licensing information applies to this code.
+
+This code is found under the c/src/libnetworking directory but does not
+constitute the entire contents of that subdirectory.
+
+=============================================================================
+
+Copyright (c) 1980, 1983, 1988, 1993
+ The Regents of the University of California. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. All advertising materials mentioning features or use of this software
+ must display the following acknowledgment:
+ This product includes software developed by the University of
+ California, Berkeley and its contributors.
+4. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-
+Portions Copyright (c) 1993 by Digital Equipment Corporation.
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies, and that
+the name of Digital Equipment Corporation not be used in advertising or
+publicity pertaining to distribution of the document or software without
+specific, written prior permission.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+=============================================================================
+*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/error.h>
+
+#define _KERNEL
+#define __BSD_VISIBLE 1
+#include <rtems/rtems_bsdnet.h>
+
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/fcntl.h>
+#include <sys/filio.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+struct socket *rtems_bsdnet_fdToSocket(int fd);
+
+/*
+ * Package system call argument into mbuf.
+ *
+ * (unfortunately, the original is not public)
+ */
+static int
+sockaddrtombuf (struct mbuf **mp, const struct sockaddr *buf, int buflen)
+{
+struct mbuf *m;
+struct sockaddr *sa;
+
+ if ((u_int)buflen > MLEN)
+ return (EINVAL);
+
+ rtems_bsdnet_semaphore_obtain();
+ m = m_get(M_WAIT, MT_SONAME);
+ rtems_bsdnet_semaphore_release();
+
+ if (m == NULL)
+ return (ENOBUFS);
+ m->m_len = buflen;
+ memcpy (mtod(m, caddr_t), buf, buflen);
+ *mp = m;
+ sa = mtod(m, struct sockaddr *);
+ sa->sa_len = buflen;
+
+ return 0;
+}
+
+static void
+dummyproc(caddr_t ext_buf, u_int ext_size)
+{
+}
+
+/*
+ * send data by simply allocating an MBUF packet
+ * header and pointing it to our data region.
+ *
+ * Optionally, the caller may supply 'reference'
+ * and 'free' procs. (The latter may call the
+ * user back once the networking stack has
+ * released the buffer).
+ *
+ * The callbacks are provided with the 'closure'
+ * pointer and the 'buflen' argument.
+ */
+ssize_t
+sendto_nocpy (
+ int s,
+ const void *buf, size_t buflen,
+ int flags,
+ const struct sockaddr *toaddr, int tolen,
+ void *closure,
+ void (*freeproc)(caddr_t, u_int),
+ void (*refproc)(caddr_t, u_int)
+)
+{
+ int error;
+ struct socket *so;
+ struct mbuf *to, *m;
+ int ret = -1;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+
+ error = sockaddrtombuf (&to, toaddr, tolen);
+ if (error) {
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+
+ MGETHDR(m, M_WAIT, MT_DATA);
+ m->m_pkthdr.len = 0;
+ m->m_pkthdr.rcvif = (struct ifnet *) 0;
+
+ m->m_flags |= M_EXT;
+ m->m_ext.ext_buf = closure ? closure : (void*)buf;
+ m->m_ext.ext_size = buflen;
+ /* we _must_ supply non-null procs; otherwise,
+ * the kernel code assumes it's a mbuf cluster
+ */
+ m->m_ext.ext_free = freeproc ? freeproc : dummyproc;
+ m->m_ext.ext_ref = refproc ? refproc : dummyproc;
+ m->m_pkthdr.len += buflen;
+ m->m_len = buflen;
+ m->m_data = (void*)buf;
+
+ error = sosend (so, to, NULL, m, NULL, flags);
+ if (error) {
+ if (/*auio.uio_resid != len &&*/ (error == EINTR || error == EWOULDBLOCK))
+ error = 0;
+ }
+ if (error)
+ errno = error;
+ else
+ ret = buflen;
+ if (to)
+ m_freem(to);
+ rtems_bsdnet_semaphore_release ();
+ return (ret);
+}
+
+
+/*
+ * receive data in an 'mbuf chain'.
+ * The chain must be released once the
+ * data has been extracted:
+ *
+ * rtems_bsdnet_semaphore_obtain();
+ * m_freem(chain);
+ * rtems_bsdnet_semaphore_release();
+ */
+ssize_t
+recv_mbuf_from(int s, struct mbuf **ppm, long len, struct sockaddr *fromaddr, int *fromlen)
+{
+ int ret = -1;
+ int error;
+ struct uio auio;
+ struct socket *so;
+ struct mbuf *from = NULL;
+
+ memset(&auio, 0, sizeof(auio));
+ *ppm = 0;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+/* auio.uio_iov = mp->msg_iov;
+ auio.uio_iovcnt = mp->msg_iovlen;
+ auio.uio_segflg = UIO_USERSPACE;
+ auio.uio_rw = UIO_READ;
+ auio.uio_offset = 0;
+*/
+ auio.uio_resid = len;
+ error = soreceive (so, &from, &auio, (struct mbuf **) ppm,
+ (struct mbuf **)NULL,
+ NULL);
+ if (error) {
+ if (auio.uio_resid != len && (error == EINTR || error == EWOULDBLOCK))
+ error = 0;
+ }
+ if (error) {
+ errno = error;
+ }
+ else {
+ ret = len - auio.uio_resid;
+ if (fromaddr) {
+ len = *fromlen;
+ if ((len <= 0) || (from == NULL)) {
+ len = 0;
+ }
+ else {
+ if (len > from->m_len)
+ len = from->m_len;
+ memcpy (fromaddr, mtod(from, caddr_t), len);
+ }
+ *fromlen = len;
+ }
+ }
+ if (from)
+ m_freem (from);
+ if (error && *ppm) {
+ m_freem(*ppm);
+ *ppm = 0;
+ }
+ rtems_bsdnet_semaphore_release ();
+ return (ret);
+}
diff --git a/cpukit/libfs/src/nfsclient/src/xdr_mbuf.c b/cpukit/libfs/src/nfsclient/src/xdr_mbuf.c
new file mode 100644
index 0000000000..4294d6dcd2
--- /dev/null
+++ b/cpukit/libfs/src/nfsclient/src/xdr_mbuf.c
@@ -0,0 +1,539 @@
+/* $Id$ */
+
+/* xdr_mbuf is derived from xdr_mem */
+
+/* Author (mbuf specifica): Till Straumann <strauman@slac.stanford.edu>, 10/2002 */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_mem.c,v 1.8 1999/08/28 00:02:56 peter Exp $";
+#endif
+
+/*
+ * xdr_mbuf, XDR implementation using mbuf buffers
+ *
+ * derived from:
+ *
+ * xdr_mem.h, XDR implementation using memory buffers.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * The MBUF stream is useful for BSDNET kernel (or RTEMS for that matter)
+ * use.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+
+#include <stdlib.h>
+
+#define TODO
+
+/* TODO remove: a hack because malloc is redefined */
+#ifdef TODO
+static inline void *
+my_malloc(size_t i)
+{
+ return malloc(i);
+}
+
+static inline void
+my_free(void *p)
+{
+ return free(p);
+}
+#endif
+
+#define DEBUG_ASSERT (1<<0)
+#define DEBUG_VERB (1<<1)
+
+#define DEBUG DEBUG_ASSERT
+
+#define _KERNEL
+#include <sys/mbuf.h>
+
+#include <assert.h>
+
+#if DEBUG & DEBUG_VERB || defined(TODO)
+#include <stdio.h>
+#endif
+
+static bool_t xdrmbuf_getlong_aligned(XDR *xdrs, long *lp);
+static bool_t xdrmbuf_putlong_aligned(XDR *xdrs, const long *lp);
+static bool_t xdrmbuf_getlong_unaligned(XDR *xdrs, long *lp);
+static bool_t xdrmbuf_putlong_unaligned(XDR *xdrs, const long *lp);
+static bool_t xdrmbuf_getbytes(XDR *xdrs, caddr_t addr, u_int len);
+static bool_t xdrmbuf_putbytes(XDR *xdrs, const char *addr, u_int len);
+static u_int xdrmbuf_getpos(XDR *xdrs); /* XXX w/64-bit pointers, u_int not enough! */
+static bool_t xdrmbuf_setpos(XDR *xdrs, u_int pos);
+static int32_t *xdrmbuf_inline_aligned(XDR *xdrs, u_int len);
+static int32_t *xdrmbuf_inline_unaligned(XDR *xdrs, u_int len);
+static void xdrmbuf_destroy(XDR *);
+
+static struct xdr_ops xdrmbuf_ops_aligned = {
+ xdrmbuf_getlong_aligned,
+ xdrmbuf_putlong_aligned,
+ xdrmbuf_getbytes,
+ xdrmbuf_putbytes,
+ xdrmbuf_getpos,
+ xdrmbuf_setpos,
+ xdrmbuf_inline_aligned,
+ xdrmbuf_destroy
+};
+
+static struct xdr_ops xdrmbuf_ops_unaligned = {
+ xdrmbuf_getlong_unaligned,
+ xdrmbuf_putlong_unaligned,
+ xdrmbuf_getbytes,
+ xdrmbuf_putbytes,
+ xdrmbuf_getpos,
+ xdrmbuf_setpos,
+ xdrmbuf_inline_unaligned,
+ xdrmbuf_destroy
+};
+
+typedef struct MBPrivateRec_ {
+ struct mbuf *mchain;
+ struct mbuf *mcurrent;
+ u_int pos; /* number of bytes contained in all MUBFS ahead
+ * of mcurrent
+ */
+} MBPrivateRec, *MBPrivate;
+
+/* NOTE: the stream position helper 'pos'
+ * must be managed by the caller!
+ */
+static inline void
+xdrmbuf_setup(XDR *xdrs, struct mbuf *m)
+{
+MBPrivate mbp = (MBPrivate)xdrs->x_base;
+
+ mbp->mcurrent = m;
+ xdrs->x_private = mtod(m,caddr_t);
+ xdrs->x_handy = m->m_len;
+ xdrs->x_ops = ((uintptr_t)xdrs->x_private & (sizeof(int32_t) - 1))
+ ? &xdrmbuf_ops_unaligned : &xdrmbuf_ops_aligned;
+}
+
+static struct mbuf *
+xdrmbuf_next(XDR *xdrs)
+{
+struct mbuf *rval;
+MBPrivate mbp = (MBPrivate)xdrs->x_base;
+
+ if (mbp->mcurrent) {
+ mbp->pos += mbp->mcurrent->m_len;
+ rval = mbp->mcurrent->m_next;
+ } else {
+ rval = 0;
+ }
+
+ if (rval) {
+ xdrmbuf_setup(xdrs, rval);
+ }
+#if DEBUG & DEBUG_VERB
+ else {
+ fprintf(stderr,"xdrmbuf: end of chain\n");
+ }
+#endif
+
+ return rval;
+}
+
+/*
+ * The procedure xdrmbuf_create initializes a stream descriptor for a
+ * memory buffer.
+ */
+void
+xdrmbuf_create(XDR *xdrs, struct mbuf *mbuf, enum xdr_op op)
+{
+MBPrivate mbp;
+
+ xdrs->x_op = op;
+ mbp = (MBPrivate)my_malloc(sizeof(*mbp));
+ assert( mbp );
+ xdrs->x_base = (caddr_t) mbp;
+
+ mbp->mchain = mbuf;
+ mbp->pos = 0;
+
+#if DEBUG & DEBUG_VERB
+ {
+ struct mbuf *mbf;
+ fprintf(stderr,"Dumping chain:\n");
+ for (mbf = mbuf; mbf; mbf=mbf->m_next) {
+ int ii;
+ fprintf(stderr,"MBUF------------");
+ for (ii=0; ii<mbf->m_len; ii++) {
+ fprintf(stderr,"%02x ",mtod(mbf,char*)[ii]);
+ if (ii%16==0)
+ fputc('\n',stderr);
+ }
+ fputc('\n',stderr);
+ }
+ }
+#endif
+
+ xdrmbuf_setup(xdrs, mbuf);
+}
+
+static void
+xdrmbuf_destroy(XDR *xdrs)
+{
+MBPrivate mbp = (MBPrivate)xdrs->x_base;
+#if 0 /* leave destroying the chain to the user */
+struct mbuf *m = mbp->mchain;
+
+ rtems_bsdnet_semaphore_obtain();
+ m_freem(m);
+ rtems_bsdnet_semaphore_release();
+#endif
+
+ my_free(mbp);
+}
+
+static bool_t
+xdrmbuf_getlong_aligned(register XDR *xdrs, register long *lp)
+{
+ while ( (signed int)(xdrs->x_handy -= sizeof(int32_t)) < 0) {
+ if ((xdrs->x_handy += sizeof(int32_t)) == 0) {
+ /* handy was 0 on entry; request a new buffer.
+ * Coded this way, so the most frequently executed
+ * path needs only one comparison...
+ */
+ if (!xdrmbuf_next(xdrs))
+ return FALSE;
+ } else {
+ /* uh-oh an aligned long spread over two MBUFS ??
+ * let the unaligned handler deal with this rare
+ * situation.
+ */
+ return xdrmbuf_getlong_unaligned(xdrs,lp);
+ }
+ }
+ *lp = ntohl(*(int32_t *)(xdrs->x_private));
+ xdrs->x_private += sizeof(int32_t);
+#if DEBUG & DEBUG_VERB
+ fprintf(stderr,"Got aligned long %x\n",*lp);
+#endif
+ return (TRUE);
+}
+
+static bool_t
+xdrmbuf_putlong_aligned(
+ XDR *xdrs,
+ const long *lp)
+{
+fprintf(stderr,"TODO: xdrmbuf_putlong_aligned() is unimplemented\n");
+ return FALSE;
+#if 0
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ *(int32_t *)xdrs->x_private = htonl(*lp);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+#endif
+}
+
+static bool_t
+xdrmbuf_getlong_unaligned(
+ XDR *xdrs,
+ long *lp)
+{
+union {
+ int32_t l;
+ char c[sizeof(int32_t)];
+} u;
+
+register int i,j;
+register char *cp,*sp;
+
+ i = xdrs->x_handy - sizeof(int32_t);
+
+ /* handle the most common case first */
+ if ( i >= 0 ) {
+
+ xdrs->x_handy = i;
+ sp = (char*)xdrs->x_private;
+ xdrs->x_private = sp + sizeof(int32_t);
+
+#ifdef CANDO_UNALIGNED
+ {
+ *lp = ntohl(*(int32_t *)sp);
+# if DEBUG & DEBUG_VERB
+ fprintf(stderr,"Got unaligned long %x (%i remaining)\n",*lp, xdrs->x_handy);
+# endif
+ return TRUE;
+ }
+#else /* machine can't do unaligned access */
+ {
+ u.c[0] = *sp;
+ u.c[1] = *++sp;
+ u.c[2] = *++sp;
+ u.c[3] = *++sp;
+
+ goto done;
+ }
+#endif /* CANDO_UNALIGNED */
+ }
+
+ /* here the messy 'crossing buffers' business starts */
+
+
+ j = sizeof(int32_t);
+
+ cp = u.c-1;
+
+ /* NOTE: on entry to this section, handy < j holds */
+ do {
+ sp = ((char*)xdrs->x_private)-1;
+
+ if ( (i=xdrs->x_handy) >= j ) {
+ /* more data in the buffer than we need:
+ * copy everything we need and goto 'done'
+ */
+ xdrs->x_handy = i-j;
+ do {
+ *++cp = *++sp;
+ } while (--j > 0);
+ xdrs->x_private = (caddr_t)++sp;
+
+ goto done;
+
+ } else {
+ /* not enough data - copy as much as possible
+ * then get retrieve the next MBUF and start
+ * over
+ */
+ j-=i;
+ while (i--)
+ *++cp = *++sp;
+ if (!xdrmbuf_next(xdrs))
+ return FALSE;
+#if DEBUG & DEBUG_VERB
+ fprintf(stderr,"getlong_unaligned: crossed mbuf boundary\n");
+#endif
+ }
+ } while (j > 0);
+
+done:
+
+ *lp = ntohl(u.l);
+
+#if DEBUG & DEBUG_VERB
+ fprintf(stderr,"Got unaligned long %x (%i remaining)\n",*lp, xdrs->x_handy);
+#endif
+ return (TRUE);
+}
+
+static bool_t
+xdrmbuf_putlong_unaligned(
+ XDR *xdrs,
+ const long *lp )
+{
+
+ fprintf(stderr,"TODO: xdrmbuf_putlong_unaligned() is unimplemented\n");
+ return FALSE;
+#if 0
+ {
+ int32_t l;
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ l = htonl(*lp);
+ memcpy(xdrs->x_private, &l, sizeof(int32_t));
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+ }
+#endif
+}
+
+static bool_t
+xdrmbuf_getbytes(
+ XDR *xdrs,
+ caddr_t addr,
+ u_int len)
+{
+#if DEBUG & DEBUG_VERB
+int olen=len,bufs=0;
+#endif
+
+#if DEBUG & DEBUG_VERB
+ fprintf(stderr,"wanting %i bytes (have %i)\n",olen,xdrs->x_handy);
+#endif
+
+ while (len>0) {
+ if (xdrs->x_handy >= len) {
+ memcpy(addr, xdrs->x_private, len);
+ xdrs->x_private += len;
+ xdrs->x_handy -= len;
+#if 0 /* save a couple of instructions */
+ len = 0;
+#else
+ goto done;
+#endif
+ } else {
+ if (xdrs->x_handy > 0) {
+ memcpy(addr, xdrs->x_private, xdrs->x_handy);
+ len -= xdrs->x_handy;
+ addr += xdrs->x_handy;
+ }
+ if (!xdrmbuf_next(xdrs))
+ return FALSE;
+#if DEBUG & DEBUG_VERB
+ bufs++;
+#endif
+ }
+ }
+done:
+#if DEBUG & DEBUG_VERB
+ fprintf(stderr,"Got %i bytes (out of %i mbufs)\n",olen,bufs);
+#endif
+ return (TRUE);
+}
+
+static bool_t
+xdrmbuf_putbytes(
+ XDR *xdrs,
+ const char *addr,
+ u_int len )
+{
+
+ fprintf(stderr,"TODO: xdrmbuf_putbytes() is unimplemented\n");
+ return FALSE;
+#if 0
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ memcpy(xdrs->x_private, addr, len);
+ xdrs->x_private += len;
+ return (TRUE);
+#endif
+}
+
+static u_int
+xdrmbuf_getpos(
+ XDR *xdrs)
+{
+#if 1
+MBPrivate mbp = (MBPrivate)xdrs->x_base;
+struct mbuf *m = mbp->mcurrent;
+u_int rval = mbp->pos;
+
+ if (m) {
+ rval += xdrs->x_private - mtod(m, void*);
+ }
+#else
+struct mbuf *m;
+u_int rval = 0;
+MBPrivate mbp = (MBPrivate)xdrs->x_base;
+
+ for ( m = mbp->mchain; m && m != mbp->mcurrent; m = m->m_next )
+ rval += m->m_len;
+ if (m) {
+ rval += (u_long)xdrs->x_private - mtod(m, u_long);
+ }
+
+#endif
+ return rval;
+}
+
+static bool_t
+xdrmbuf_setpos(
+ XDR *xdrs,
+ u_int pos)
+{
+struct mbuf *m;
+MBPrivate mbp = (MBPrivate)xdrs->x_base;
+
+ if (pos >= mbp->pos) {
+ pos -= mbp->pos;
+ m = mbp->mcurrent;
+ } else {
+ m = mbp->mchain;
+ mbp->pos = 0;
+ }
+
+ while ( m && pos >= m->m_len ) {
+ pos -= m->m_len;
+ mbp->pos += m->m_len;
+ m = m->m_next;
+ }
+
+ if (m) {
+ xdrmbuf_setup(xdrs, m);
+ xdrs->x_private += pos;
+ return TRUE;
+ }
+
+ return 0 == pos ? TRUE : FALSE;
+}
+
+static int32_t *
+xdrmbuf_inline_aligned(
+ XDR *xdrs,
+ u_int len)
+{
+int32_t *buf = 0;
+
+ if (xdrs->x_handy == 0 && !xdrmbuf_next(xdrs))
+ return 0;
+
+ if (xdrs->x_handy >= len) {
+ xdrs->x_handy -= len;
+ buf = (int32_t *) xdrs->x_private;
+ xdrs->x_private += len;
+#if DEBUG & DEBUG_VERB
+ fprintf(stderr,"Got %i aligned inline bytes at %x\n", len, buf);
+#endif
+ }
+#if DEBUG & DEBUG_VERB
+ else {
+ fprintf(stderr,"Skipped %i aligned inline bytes\n",len);
+ }
+#endif
+ return (buf);
+}
+
+static int32_t *
+xdrmbuf_inline_unaligned(
+ XDR *xdrs,
+ u_int len )
+{
+ return (0);
+}
diff --git a/cpukit/libfs/src/pipe/fifo.c b/cpukit/libfs/src/pipe/fifo.c
new file mode 100644
index 0000000000..9579954611
--- /dev/null
+++ b/cpukit/libfs/src/pipe/fifo.c
@@ -0,0 +1,585 @@
+/*
+ * fifo.c: POSIX FIFO/pipe for RTEMS
+ *
+ * Author: Wei Shen <cquark@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_POSIX_API
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
+#include "pipe.h"
+
+
+#define MIN(a, b) ((a) < (b)? (a): (b))
+
+#define LIBIO_ACCMODE(_iop) ((_iop)->flags & LIBIO_FLAGS_READ_WRITE)
+#define LIBIO_NODELAY(_iop) ((_iop)->flags & LIBIO_FLAGS_NO_DELAY)
+
+static rtems_id pipe_semaphore = RTEMS_ID_NONE;
+
+
+#define PIPE_EMPTY(_pipe) (_pipe->Length == 0)
+#define PIPE_FULL(_pipe) (_pipe->Length == _pipe->Size)
+#define PIPE_SPACE(_pipe) (_pipe->Size - _pipe->Length)
+#define PIPE_WSTART(_pipe) ((_pipe->Start + _pipe->Length) % _pipe->Size)
+
+#define PIPE_LOCK(_pipe) \
+ ( rtems_semaphore_obtain(_pipe->Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT) \
+ == RTEMS_SUCCESSFUL )
+
+#define PIPE_UNLOCK(_pipe) rtems_semaphore_release(_pipe->Semaphore)
+
+#define PIPE_READWAIT(_pipe) \
+ ( rtems_barrier_wait(_pipe->readBarrier, RTEMS_NO_TIMEOUT) \
+ == RTEMS_SUCCESSFUL)
+
+#define PIPE_WRITEWAIT(_pipe) \
+ ( rtems_barrier_wait(_pipe->writeBarrier, RTEMS_NO_TIMEOUT) \
+ == RTEMS_SUCCESSFUL)
+
+#define PIPE_WAKEUPREADERS(_pipe) \
+ do {uint32_t n; rtems_barrier_release(_pipe->readBarrier, &n); } while(0)
+
+#define PIPE_WAKEUPWRITERS(_pipe) \
+ do {uint32_t n; rtems_barrier_release(_pipe->writeBarrier, &n); } while(0)
+
+
+#ifdef RTEMS_POSIX_API
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+
+#include <rtems/rtems/barrier.h>
+#include <rtems/score/thread.h>
+
+/* Set barriers to be interruptible by signals. */
+static void pipe_interruptible(pipe_control_t *pipe)
+{
+ Objects_Locations location;
+
+ _Barrier_Get(pipe->readBarrier, &location)->Barrier.Wait_queue.state
+ |= STATES_INTERRUPTIBLE_BY_SIGNAL;
+ _Thread_Enable_dispatch();
+ _Barrier_Get(pipe->writeBarrier, &location)->Barrier.Wait_queue.state
+ |= STATES_INTERRUPTIBLE_BY_SIGNAL;
+ _Thread_Enable_dispatch();
+}
+#endif
+
+/*
+ * Alloc pipe control structure, buffer, and resources.
+ * Called with pipe_semaphore held.
+ */
+static int pipe_alloc(
+ pipe_control_t **pipep
+)
+{
+ static char c = 'a';
+ pipe_control_t *pipe;
+ int err = -ENOMEM;
+
+ pipe = malloc(sizeof(pipe_control_t));
+ if (pipe == NULL)
+ return err;
+ memset(pipe, 0, sizeof(pipe_control_t));
+
+ pipe->Size = PIPE_BUF;
+ pipe->Buffer = malloc(pipe->Size);
+ if (! pipe->Buffer)
+ goto err_buf;
+
+ err = -ENOMEM;
+
+ if (rtems_barrier_create(
+ rtems_build_name ('P', 'I', 'r', c),
+ RTEMS_BARRIER_MANUAL_RELEASE, 0,
+ &pipe->readBarrier) != RTEMS_SUCCESSFUL)
+ goto err_rbar;
+ if (rtems_barrier_create(
+ rtems_build_name ('P', 'I', 'w', c),
+ RTEMS_BARRIER_MANUAL_RELEASE, 0,
+ &pipe->writeBarrier) != RTEMS_SUCCESSFUL)
+ goto err_wbar;
+ if (rtems_semaphore_create(
+ rtems_build_name ('P', 'I', 's', c), 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO,
+ RTEMS_NO_PRIORITY, &pipe->Semaphore) != RTEMS_SUCCESSFUL)
+ goto err_sem;
+
+#ifdef RTEMS_POSIX_API
+ pipe_interruptible(pipe);
+#endif
+
+ *pipep = pipe;
+ if (c ++ == 'z')
+ c = 'a';
+ return 0;
+
+err_sem:
+ rtems_barrier_delete(pipe->writeBarrier);
+err_wbar:
+ rtems_barrier_delete(pipe->readBarrier);
+err_rbar:
+ free(pipe->Buffer);
+err_buf:
+ free(pipe);
+ return err;
+}
+
+/* Called with pipe_semaphore held. */
+static inline void pipe_free(
+ pipe_control_t *pipe
+)
+{
+ rtems_barrier_delete(pipe->readBarrier);
+ rtems_barrier_delete(pipe->writeBarrier);
+ rtems_semaphore_delete(pipe->Semaphore);
+ free(pipe->Buffer);
+ free(pipe);
+}
+
+static rtems_status_code pipe_lock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (pipe_semaphore == RTEMS_ID_NONE) {
+ rtems_libio_lock();
+
+ if (pipe_semaphore == RTEMS_ID_NONE) {
+ sc = rtems_semaphore_create(
+ rtems_build_name('P', 'I', 'P', 'E'),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &pipe_semaphore
+ );
+ }
+
+ rtems_libio_unlock();
+ }
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ sc = rtems_semaphore_obtain(pipe_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ }
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ return 0;
+ } else {
+ return -ENOMEM;
+ }
+}
+
+static void pipe_unlock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_semaphore_release(pipe_semaphore);
+ #ifdef RTEMS_DEBUG
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_fatal_error_occurred(0xdeadbeef);
+ }
+ #endif
+}
+
+/*
+ * If called with *pipep = NULL, pipe_new will call pipe_alloc to allocate a
+ * pipe control structure and set *pipep to its address.
+ * pipe is locked, when pipe_new returns with no error.
+ */
+static int pipe_new(
+ pipe_control_t **pipep
+)
+{
+ pipe_control_t *pipe;
+ int err = 0;
+
+ err = pipe_lock();
+ if (err)
+ return err;
+
+ pipe = *pipep;
+ if (pipe == NULL) {
+ err = pipe_alloc(&pipe);
+ if (err)
+ goto out;
+ }
+
+ if (! PIPE_LOCK(pipe))
+ err = -EINTR;
+
+ if (*pipep == NULL) {
+ if (err)
+ pipe_free(pipe);
+ else
+ *pipep = pipe;
+ }
+
+out:
+ pipe_unlock();
+ return err;
+}
+
+/*
+ * Interface to file system close.
+ *
+ * *pipep points to pipe control structure. When the last user releases pipe,
+ * it will be set to NULL.
+ */
+void pipe_release(
+ pipe_control_t **pipep,
+ rtems_libio_t *iop
+)
+{
+ pipe_control_t *pipe = *pipep;
+ uint32_t mode;
+
+ #if defined(RTEMS_DEBUG)
+ /* WARN pipe not freed and pipep not set to NULL! */
+ if (pipe_lock())
+ rtems_fatal_error_occurred(0xdeadbeef);
+
+ /* WARN pipe not released! */
+ if (!PIPE_LOCK(pipe))
+ rtems_fatal_error_occurred(0xdeadbeef);
+ #endif
+
+ mode = LIBIO_ACCMODE(iop);
+ if (mode & LIBIO_FLAGS_READ)
+ pipe->Readers --;
+ if (mode & LIBIO_FLAGS_WRITE)
+ pipe->Writers --;
+
+ PIPE_UNLOCK(pipe);
+
+ if (pipe->Readers == 0 && pipe->Writers == 0) {
+#if 0
+ /* To delete an anonymous pipe file when all users closed it */
+ if (pipe->Anonymous)
+ delfile = TRUE;
+#endif
+ pipe_free(pipe);
+ *pipep = NULL;
+ }
+ else if (pipe->Readers == 0 && mode != LIBIO_FLAGS_WRITE)
+ /* Notify waiting Writers that all their partners left */
+ PIPE_WAKEUPWRITERS(pipe);
+ else if (pipe->Writers == 0 && mode != LIBIO_FLAGS_READ)
+ PIPE_WAKEUPREADERS(pipe);
+
+ pipe_unlock();
+
+#if 0
+ if (! delfile)
+ return;
+ if (iop->pathinfo.ops->unlink_h == NULL)
+ return;
+
+ /* This is safe for IMFS, but how about other FSes? */
+ iop->flags &= ~LIBIO_FLAGS_OPEN;
+ if(iop->pathinfo.ops->unlink_h(&iop->pathinfo))
+ return;
+#endif
+
+}
+
+/*
+ * Interface to file system open.
+ *
+ * *pipep points to pipe control structure. If called with *pipep = NULL,
+ * fifo_open will try allocating and initializing a control structure. If the
+ * call succeeds, *pipep will be set to address of new control structure.
+ */
+int fifo_open(
+ pipe_control_t **pipep,
+ rtems_libio_t *iop
+)
+{
+ pipe_control_t *pipe;
+ unsigned int prevCounter;
+ int err;
+
+ err = pipe_new(pipep);
+ if (err)
+ return err;
+ pipe = *pipep;
+
+ switch (LIBIO_ACCMODE(iop)) {
+ case LIBIO_FLAGS_READ:
+ pipe->readerCounter ++;
+ if (pipe->Readers ++ == 0)
+ PIPE_WAKEUPWRITERS(pipe);
+
+ if (pipe->Writers == 0) {
+ /* Not an error */
+ if (LIBIO_NODELAY(iop))
+ break;
+
+ prevCounter = pipe->writerCounter;
+ err = -EINTR;
+ /* Wait until a writer opens the pipe */
+ do {
+ PIPE_UNLOCK(pipe);
+ if (! PIPE_READWAIT(pipe))
+ goto out_error;
+ if (! PIPE_LOCK(pipe))
+ goto out_error;
+ } while (prevCounter == pipe->writerCounter);
+ }
+ break;
+
+ case LIBIO_FLAGS_WRITE:
+ pipe->writerCounter ++;
+
+ if (pipe->Writers ++ == 0)
+ PIPE_WAKEUPREADERS(pipe);
+
+ if (pipe->Readers == 0 && LIBIO_NODELAY(iop)) {
+ PIPE_UNLOCK(pipe);
+ err = -ENXIO;
+ goto out_error;
+ }
+
+ if (pipe->Readers == 0) {
+ prevCounter = pipe->readerCounter;
+ err = -EINTR;
+ do {
+ PIPE_UNLOCK(pipe);
+ if (! PIPE_WRITEWAIT(pipe))
+ goto out_error;
+ if (! PIPE_LOCK(pipe))
+ goto out_error;
+ } while (prevCounter == pipe->readerCounter);
+ }
+ break;
+
+ case LIBIO_FLAGS_READ_WRITE:
+ pipe->readerCounter ++;
+ if (pipe->Readers ++ == 0)
+ PIPE_WAKEUPWRITERS(pipe);
+ pipe->writerCounter ++;
+ if (pipe->Writers ++ == 0)
+ PIPE_WAKEUPREADERS(pipe);
+ break;
+ }
+
+ PIPE_UNLOCK(pipe);
+ return 0;
+
+out_error:
+ pipe_release(pipep, iop);
+ return err;
+}
+
+/*
+ * Interface to file system read.
+ */
+ssize_t pipe_read(
+ pipe_control_t *pipe,
+ void *buffer,
+ size_t count,
+ rtems_libio_t *iop
+)
+{
+ int chunk, chunk1, read = 0, ret = 0;
+
+ if (! PIPE_LOCK(pipe))
+ return -EINTR;
+
+ while (read < count) {
+ while (PIPE_EMPTY(pipe)) {
+ /* Not an error */
+ if (pipe->Writers == 0)
+ goto out_locked;
+
+ if (LIBIO_NODELAY(iop)) {
+ ret = -EAGAIN;
+ goto out_locked;
+ }
+
+ /* Wait until pipe is no more empty or no writer exists */
+ pipe->waitingReaders ++;
+ PIPE_UNLOCK(pipe);
+ if (! PIPE_READWAIT(pipe))
+ ret = -EINTR;
+ if (! PIPE_LOCK(pipe)) {
+ /* WARN waitingReaders not restored! */
+ ret = -EINTR;
+ goto out_nolock;
+ }
+ pipe->waitingReaders --;
+ if (ret != 0)
+ goto out_locked;
+ }
+
+ /* Read chunk bytes */
+ chunk = MIN(count - read, pipe->Length);
+ chunk1 = pipe->Size - pipe->Start;
+ if (chunk > chunk1) {
+ memcpy(buffer + read, pipe->Buffer + pipe->Start, chunk1);
+ memcpy(buffer + read + chunk1, pipe->Buffer, chunk - chunk1);
+ }
+ else
+ memcpy(buffer + read, pipe->Buffer + pipe->Start, chunk);
+
+ pipe->Start += chunk;
+ pipe->Start %= pipe->Size;
+ pipe->Length -= chunk;
+ /* For buffering optimization */
+ if (PIPE_EMPTY(pipe))
+ pipe->Start = 0;
+
+ if (pipe->waitingWriters > 0)
+ PIPE_WAKEUPWRITERS(pipe);
+ read += chunk;
+ }
+
+out_locked:
+ PIPE_UNLOCK(pipe);
+
+out_nolock:
+ if (read > 0)
+ return read;
+ return ret;
+}
+
+/*
+ * Interface to file system write.
+ */
+ssize_t pipe_write(
+ pipe_control_t *pipe,
+ const void *buffer,
+ size_t count,
+ rtems_libio_t *iop
+)
+{
+ int chunk, chunk1, written = 0, ret = 0;
+
+ /* Write nothing */
+ if (count == 0)
+ return 0;
+
+ if (! PIPE_LOCK(pipe))
+ return -EINTR;
+
+ if (pipe->Readers == 0) {
+ ret = -EPIPE;
+ goto out_locked;
+ }
+
+ /* Write of PIPE_BUF bytes or less shall not be interleaved */
+ chunk = count <= pipe->Size ? count : 1;
+
+ while (written < count) {
+ while (PIPE_SPACE(pipe) < chunk) {
+ if (LIBIO_NODELAY(iop)) {
+ ret = -EAGAIN;
+ goto out_locked;
+ }
+
+ /* Wait until there is chunk bytes space or no reader exists */
+ pipe->waitingWriters ++;
+ PIPE_UNLOCK(pipe);
+ if (! PIPE_WRITEWAIT(pipe))
+ ret = -EINTR;
+ if (! PIPE_LOCK(pipe)) {
+ /* WARN waitingWriters not restored! */
+ ret = -EINTR;
+ goto out_nolock;
+ }
+ pipe->waitingWriters --;
+ if (ret != 0)
+ goto out_locked;
+
+ if (pipe->Readers == 0) {
+ ret = -EPIPE;
+ goto out_locked;
+ }
+ }
+
+ chunk = MIN(count - written, PIPE_SPACE(pipe));
+ chunk1 = pipe->Size - PIPE_WSTART(pipe);
+ if (chunk > chunk1) {
+ memcpy(pipe->Buffer + PIPE_WSTART(pipe), buffer + written, chunk1);
+ memcpy(pipe->Buffer, buffer + written + chunk1, chunk - chunk1);
+ }
+ else
+ memcpy(pipe->Buffer + PIPE_WSTART(pipe), buffer + written, chunk);
+
+ pipe->Length += chunk;
+ if (pipe->waitingReaders > 0)
+ PIPE_WAKEUPREADERS(pipe);
+ written += chunk;
+ /* Write of more than PIPE_BUF bytes can be interleaved */
+ chunk = 1;
+ }
+
+out_locked:
+ PIPE_UNLOCK(pipe);
+
+out_nolock:
+#ifdef RTEMS_POSIX_API
+ /* Signal SIGPIPE */
+ if (ret == -EPIPE)
+ kill(getpid(), SIGPIPE);
+#endif
+
+ if (written > 0)
+ return written;
+ return ret;
+}
+
+/*
+ * Interface to file system ioctl.
+ */
+int pipe_ioctl(
+ pipe_control_t *pipe,
+ uint32_t cmd,
+ void *buffer,
+ rtems_libio_t *iop
+)
+{
+ if (cmd == FIONREAD) {
+ if (buffer == NULL)
+ return -EFAULT;
+
+ if (! PIPE_LOCK(pipe))
+ return -EINTR;
+
+ /* Return length of pipe */
+ *(unsigned int *)buffer = pipe->Length;
+ PIPE_UNLOCK(pipe);
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+/*
+ * Interface to file system lseek.
+ */
+int pipe_lseek(
+ pipe_control_t *pipe,
+ off_t offset,
+ int whence,
+ rtems_libio_t *iop
+)
+{
+ /* Seek on pipe is not supported */
+ return -ESPIPE;
+}
diff --git a/cpukit/libfs/src/pipe/pipe.c b/cpukit/libfs/src/pipe/pipe.c
new file mode 100644
index 0000000000..63a294f5f8
--- /dev/null
+++ b/cpukit/libfs/src/pipe/pipe.c
@@ -0,0 +1,79 @@
+/*
+ * pipe.c: anonymous pipe
+ *
+ * Author: Wei Shen <cquark@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+
+/* Incremental number added to names of anonymous pipe files */
+/* FIXME: This approach is questionable */
+static uint16_t rtems_pipe_no = 0;
+
+/*
+ * Called by pipe() to create an anonymous pipe.
+ */
+int pipe_create(
+ int filsdes[2]
+)
+{
+ rtems_libio_t *iop;
+ int err = 0;
+
+ if (rtems_mkdir("/tmp", S_IRWXU | S_IRWXG | S_IRWXO) != 0)
+ return -1;
+
+ /* /tmp/.fifoXXXX */
+ char fifopath[15];
+ memcpy(fifopath, "/tmp/.fifo", 10);
+ sprintf(fifopath + 10, "%04x", rtems_pipe_no ++);
+
+ /* Try creating FIFO file until find an available file name */
+ while (mkfifo(fifopath, S_IRUSR|S_IWUSR) != 0) {
+ if (errno != EEXIST){
+ return -1;
+ }
+ /* Just try once... */
+ return -1;
+ /* sprintf(fifopath + 10, "%04x", rtems_pipe_no ++); */
+ }
+
+ /* Non-blocking open to avoid waiting for writers */
+ filsdes[0] = open(fifopath, O_RDONLY | O_NONBLOCK);
+ if (filsdes[0] < 0) {
+ err = errno;
+ /* Delete file at errors, or else if pipe is successfully created
+ the file node will be deleted after it is closed by all. */
+ unlink(fifopath);
+ }
+ else {
+ /* Reset open file to blocking mode */
+ iop = rtems_libio_iop(filsdes[0]);
+ iop->flags &= ~LIBIO_FLAGS_NO_DELAY;
+
+ filsdes[1] = open(fifopath, O_WRONLY);
+
+ if (filsdes[1] < 0) {
+ err = errno;
+ close(filsdes[0]);
+ }
+ unlink(fifopath);
+ }
+ if(err != 0)
+ rtems_set_errno_and_return_minus_one(err);
+ return 0;
+}
+
diff --git a/cpukit/libfs/src/pipe/pipe.h b/cpukit/libfs/src/pipe/pipe.h
new file mode 100644
index 0000000000..354cc9d130
--- /dev/null
+++ b/cpukit/libfs/src/pipe/pipe.h
@@ -0,0 +1,116 @@
+/*
+ * pipe.h: header of POSIX FIFO/pipe
+ *
+ * Author: Wei Shen <cquark@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_PIPE_H
+#define _RTEMS_PIPE_H
+
+#include <rtems/libio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Control block to manage each pipe */
+typedef struct pipe_control {
+ char *Buffer;
+ unsigned int Size;
+ unsigned int Start;
+ unsigned int Length;
+ unsigned int Readers;
+ unsigned int Writers;
+ unsigned int waitingReaders;
+ unsigned int waitingWriters;
+ unsigned int readerCounter; /* incremental counters */
+ unsigned int writerCounter; /* for differentiation of successive opens */
+ rtems_id Semaphore;
+ rtems_id readBarrier; /* wait queues */
+ rtems_id writeBarrier;
+#if 0
+ boolean Anonymous; /* anonymous pipe or FIFO */
+#endif
+} pipe_control_t;
+
+/*
+ * Called by pipe() to create an anonymous pipe.
+ */
+extern int pipe_create(
+ int filsdes[2]
+);
+
+/*
+ * Interface to file system close.
+ *
+ * *pipep points to pipe control structure. When the last user releases pipe,
+ * it will be set to NULL.
+ */
+extern void pipe_release(
+ pipe_control_t **pipep,
+ rtems_libio_t *iop
+);
+
+/*
+ * Interface to file system open.
+ *
+ * *pipep points to pipe control structure. If called with *pipep = NULL,
+ * fifo_open will try allocating and initializing a control structure. If the
+ * call succeeds, *pipep will be set to address of new control structure.
+ */
+extern int fifo_open(
+ pipe_control_t **pipep,
+ rtems_libio_t *iop
+);
+
+/*
+ * Interface to file system read.
+ */
+extern ssize_t pipe_read(
+ pipe_control_t *pipe,
+ void *buffer,
+ size_t count,
+ rtems_libio_t *iop
+);
+
+/*
+ * Interface to file system write.
+ */
+extern ssize_t pipe_write(
+ pipe_control_t *pipe,
+ const void *buffer,
+ size_t count,
+ rtems_libio_t *iop
+);
+
+/*
+ * Interface to file system ioctl.
+ */
+extern int pipe_ioctl(
+ pipe_control_t *pipe,
+ uint32_t cmd,
+ void *buffer,
+ rtems_libio_t *iop
+);
+
+/*
+ * Interface to file system lseek.
+ */
+extern int pipe_lseek(
+ pipe_control_t *pipe,
+ off_t offset,
+ int whence,
+ rtems_libio_t *iop
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-bitmaps-ut.c b/cpukit/libfs/src/rfs/rtems-rfs-bitmaps-ut.c
new file mode 100644
index 0000000000..1240940bc2
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-bitmaps-ut.c
@@ -0,0 +1,398 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Bitmap Unit Test..
+ *
+ * This is a unit test module for the bit map functions.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-bitmaps.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+
+#define rtems_rfs_exit_on_error(_rc, _r, _c, _b) \
+ if ((_rc > 0) || _r) { free (_b); rtems_rfs_bitmap_close (_c); return; }
+
+static bool
+rtems_rfs_bitmap_ut_test_range (rtems_rfs_bitmap_control* control,
+ int test,
+ bool set,
+ rtems_rfs_bitmap_bit bit,
+ size_t size)
+{
+ unsigned int count;
+ bool result;
+ for (count = 0; count < size; count++)
+ {
+ int rc = rtems_rfs_bitmap_map_test (control, bit + count, &result);
+ if (rc > 0)
+ {
+ printf (" %2d. Test bit %" PRId32 " in range (%" PRId32 ",%ld] is %s: ",
+ test, bit + count, bit, bit + size - 1, !set ? "set" : "clear");
+ printf ("FAIL (%s)\n", strerror (rc));
+ return false;
+ }
+ if (!set)
+ result = !result;
+ if (!result)
+ {
+ printf (" %2d. Test bit %" PRId32 " in range (%" PRId32 ",%ld] is %s: ",
+ test, bit + count, bit, bit + size - 1, !set ? "set" : "clear");
+ printf (" %s\n", !result ? "pass" : "FAIL");
+ return false;
+ }
+ }
+
+ printf (" %2d. Test bit range (%" PRId32 ",%ld] all %s: pass\n",
+ test, bit, bit + size - 1, set ? "set" : "clear");
+
+ return true;
+}
+
+static bool
+rtems_rfs_bitmap_ut_alloc_seq_test (rtems_rfs_bitmap_control* control,
+ int test,
+ rtems_rfs_bitmap_bit bit,
+ size_t size)
+{
+ bool state;
+ int i;
+ int rc;
+
+ printf (" %2d. Set all bits\n", test);
+ rc = rtems_rfs_bitmap_map_set_all (control);
+ if (rc > 0)
+ {
+ printf (" %2d. set all bits: FAIL (%s)\n", test, strerror (rc));
+ return false;
+ }
+
+ for (i = 0; i < size; i++)
+ rtems_rfs_bitmap_map_clear (control, bit + i);
+
+ printf (" %2d. Cleared bits (%" PRId32 ", %ld] (%zd)\n",
+ test, bit, bit + size - 1, size);
+
+ for (i = 0; i < rtems_rfs_bitmap_element_bits (); i++)
+ {
+ rc = rtems_rfs_bitmap_map_test (control, bit + i, &state);
+ if (rc > 0)
+ {
+ printf (" %2d. test bit: FAIL (%s)\n", test, strerror (rc));
+ return false;
+ }
+ if (state)
+ {
+ printf (" %2d. Cleared bit still set: bit = %" PRId32 "\n", test, bit + i);
+ return false;
+ }
+ }
+
+ for (i = 0, bit = 0; i < size; i++)
+ {
+ rtems_rfs_bitmap_bit seed = bit;
+ bool result;
+ int rc;
+ rc = rtems_rfs_bitmap_map_alloc (control, seed, &result, &bit);
+ if (rc > 0)
+ {
+ printf (" %2d. map all: FAIL (%s)\n", test, strerror (rc));
+ return false;
+ }
+ if (!result)
+ {
+ printf (" %2d. Find bit with seed = %" PRId32 ": %s: bit = %" PRId32 "\n",
+ test, seed, result ? "pass" : "FAIL", bit);
+ return false;
+ }
+ }
+
+ printf (" %2d. Alloc'ed all bits (%" PRId32 ", %ld] (%zd)\n",
+ test, bit, bit + size - 1, size);
+
+ return true;
+}
+
+static void
+rtems_rfs_bitmap_ut_test_bitmap (size_t size)
+{
+ rtems_rfs_file_system fs;
+ rtems_rfs_bitmap_control control;
+ rtems_rfs_buffer_handle handle;
+ rtems_rfs_buffer buffer;
+ rtems_rfs_bitmap_bit bit = 0;
+ rtems_rfs_bitmap_bit first_bit;
+ rtems_rfs_bitmap_bit last_bit;
+ bool result;
+ size_t bytes;
+ size_t clear;
+ int rc;
+
+ bytes = (rtems_rfs_bitmap_elements (size) *
+ sizeof (rtems_rfs_bitmap_element));
+
+ memset (&fs, 0, sizeof (fs));
+ memset (&buffer, 0, sizeof (buffer));
+
+ buffer.buffer = malloc (bytes);
+ buffer.block = 1;
+
+ if (!buffer.buffer)
+ {
+ printf (" Cannot allocate bitmap memory\n");
+ return;
+ }
+
+#if RTEMS_RFS_BITMAP_CLEAR_ZERO
+ memset (buffer.buffer, 0, bytes);
+#else
+ memset (buffer.buffer, 0xff, bytes);
+#endif
+
+ /*
+ * Do not close the handle so no writes need occur.
+ */
+ rc = rtems_rfs_buffer_handle_open (&fs, &handle);
+ if (rc > 0)
+ {
+ printf (" Cannot open the handle: %d: %s\n", rc, strerror (rc));
+ free (buffer.buffer);
+ return;
+ }
+
+ handle.buffer = &buffer;
+ handle.bnum = 1;
+
+ printf ("\nRFS Bitmap Test : size = %zd (%zd)\n",
+ size, rtems_rfs_bitmap_elements (size));
+ rc = rtems_rfs_bitmap_open (&control, &fs, &handle, size, 1);
+ if (rc > 0)
+ {
+ printf (" Cannot open the bitmap: %s\n", strerror (rc));
+ free (buffer.buffer);
+ return;
+ }
+
+ /*
+ * This is a new bitmap with no bits set. Try and find a bit with a few
+ * seeds.
+ */
+ rc = rtems_rfs_bitmap_map_alloc (&control, size * 2, &result, &bit);
+ printf (" 1. Find bit with seed > size: %s (%s)\n",
+ result ? "FAIL" : "pass", strerror (rc));
+ rtems_rfs_exit_on_error (rc, result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, size, &result, &bit);
+ printf (" 2. Find bit with seed = size: %s (%s)\n",
+ result ? "FAIL" : "pass", strerror (rc));
+ rtems_rfs_exit_on_error (rc, result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit);
+ result = result && (bit == 0);
+ printf (" 3. Find bit 0 with seed = 0: %s (%s): bit = %" PRId32 "\n",
+ result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, size - 1, &result, &bit);
+ result = result && (bit == (size - 1));
+ printf (" 4. Find bit (size - 1) with seed = (size - 1) (%zd): %s (%s): bit = %" PRId32 "\n",
+ size - 1, result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+
+ /*
+ * Test the bits allocated to make sure they are set.
+ */
+
+ rc = rtems_rfs_bitmap_map_test (&control, 0, &result);
+ printf (" 5. Test bit 0: %s (%s)\n",
+ result ? "pass" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_test (&control, size - 1, &result);
+ printf (" 6. Test bit (size - 1) (%zd): %s (%s)\n",
+ size - 1, result ? "pass" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ if (!rtems_rfs_bitmap_ut_test_range (&control, 7, false, 1, size - 2))
+ rtems_rfs_exit_on_error (0, !result, &control, buffer.buffer);
+
+ /*
+ * Set all bits then clear one and find it.
+ */
+ rc = rtems_rfs_bitmap_map_set_all (&control);
+ printf (" 8. Set all bits: %s (%s)\n",
+ rc == 0 ? "PASS" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+
+ bit = rand () % size;
+
+ rc = rtems_rfs_bitmap_map_clear (&control, bit);
+ printf (" 9. Clear bit %" PRId32 ": %s (%s)\n",
+ bit, rc == 0 ? "PASS" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+
+ last_bit = bit;
+ rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit);
+ result = result && (bit == last_bit);
+ printf (" 10. Find bit with seed = 0: %s (%s): bit = %" PRId32 "\n",
+ result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit);
+ result = !result || (bit != last_bit);
+ printf (" 11. Fail to find bit with seed = 0: %s (%s): bit = %" PRId32 "\n",
+ result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_clear (&control, 0);
+ printf (" 12. Clear bit 0: %s (%s)\n",
+ rc == 0 ? "pass" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, size - 1, &result, &bit);
+ result = result && (bit == 0);
+ printf (" 13. Find bit with seed = (size - 1): %s (%s): bit = %" PRId32 "\n",
+ result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_clear (&control, size - 1);
+ printf (" 14. Clear bit (size - 1) (%zd): %s (%s)\n",
+ size - 1, rc == 0 ? "pass" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, 0, &result, &bit);
+ result = result && (bit == (size - 1));
+ printf (" 15. Find bit with seed = 0: %s (%s): bit = %" PRId32 "\n",
+ result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_clear (&control, 0);
+ printf (" 16. Clear bit 0: %s (%s)\n",
+ rc == 0 ? "pass" : "FAIL", strerror (rc));
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, size / 2, &result, &bit);
+ result = result && (bit == 0);
+ printf (" 17. Find bit with seed = (size / 2) (%zd): %s (%s): bit = %" PRId32 "\n",
+ size / 2, result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_clear (&control, size - 1);
+ printf (" 18. Clear bit (size - 1) (%zd): %s, (%s)\n",
+ size - 1, rc == 0 ? "pass" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, size / 2, &result, &bit);
+ result = result && (bit == (size - 1));
+ printf (" 19. Find bit with seed = (size / 2) (%zd): %s (%s): bit = %" PRId32 "\n",
+ size / 2, result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_clear (&control, 0);
+ printf (" 20. Clear bit 0: %s (%s)\n",
+ rc == 0 ? "pass" : "FAIL", strerror (rc));
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, (size / 2) - 1, &result, &bit);
+ result = result && (bit == 0);
+ printf (" 21. Find bit with seed = ((size / 2) - 1) (%zd): %s (%s): bit = %" PRId32 "\n",
+ (size / 2) - 1, result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rc = rtems_rfs_bitmap_map_clear (&control, size - 1);
+ printf (" 22. Clear bit (size - 1) (%zd): %s (%s)\n",
+ size - 1, rc == 0 ? "pass" : "FAIL", strerror (rc));
+
+ rc = rtems_rfs_bitmap_map_alloc (&control, (size / 2) - 1, &result, &bit);
+ result = result && (bit == (size - 1));
+ printf (" 23. Find bit with seed = ((size / 2) - 1) (%zd): %s (%s): bit = %" PRId32 "\n",
+ (size / 2) - 1, result ? "pass" : "FAIL", strerror (rc), bit);
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ bit = rand () % (size / 2) + rtems_rfs_bitmap_element_bits ();
+ result = rtems_rfs_bitmap_ut_alloc_seq_test (&control, 23, bit,
+ rtems_rfs_bitmap_element_bits ());
+ rtems_rfs_exit_on_error (0, !result, &control, buffer.buffer);
+
+ bit = rand () % (size / 2) + rtems_rfs_bitmap_element_bits ();
+ result = rtems_rfs_bitmap_ut_alloc_seq_test (&control, 24, bit, 57);
+ rtems_rfs_exit_on_error (0, !result, &control, buffer.buffer);
+
+ /*
+ * Set all bits, clear a random numberone then create a search map and make
+ * sure the clear count is correct.
+ */
+ rc = rtems_rfs_bitmap_map_set_all (&control);
+ printf (" 25. Set all bits: %s (%s)\n",
+ rc == 0 ? "PASS" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+
+ first_bit = rand () % (size / 2) + rtems_rfs_bitmap_element_bits ();
+ last_bit = first_bit + rand () % (size / 2) + rtems_rfs_bitmap_element_bits ();
+
+ for (bit = first_bit; bit < last_bit; bit++)
+ {
+ rc = rtems_rfs_bitmap_map_clear (&control, bit);
+ if (rc > 0)
+ {
+ printf (" 26. Clear bit %" PRId32 ": %s (%s)\n",
+ bit, rc == 0 ? "PASS" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, false, &control, buffer.buffer);
+ }
+ }
+
+ printf (" 26. Clear bit (%" PRId32 ", %" PRId32 "]: %s (%s)\n",
+ first_bit, last_bit, rc == 0 ? "PASS" : "FAIL", strerror (rc));
+
+ clear = rtems_rfs_bitmap_map_free (&control);
+ result = clear == (last_bit - first_bit);
+ printf (" 27. Check free count is %zd: %" PRId32 ": %s (%s)\n",
+ clear, last_bit - first_bit,
+ result ? "pass" : "FAIL", strerror (rc));
+
+ rc = rtems_rfs_bitmap_create_search (&control);
+ result = clear == rtems_rfs_bitmap_map_free (&control);
+ printf (" 28. Create search check free count is %zd: %zd: %s (%s)\n",
+ clear, rtems_rfs_bitmap_map_free (&control),
+ result ? "pass" : "FAIL", strerror (rc));
+ rtems_rfs_exit_on_error (rc, !result, &control, buffer.buffer);
+
+ rtems_rfs_bitmap_close (&control);
+ free (buffer.buffer);
+}
+
+void
+rtems_rfs_bitmap_unit_test (void)
+{
+ printf ("RTEMS File System Bitmap Unit Test\n");
+ printf (" Bit set value : %d\n", RTEMS_RFS_BITMAP_BIT_SET);
+ printf (" Bit clear value : %d\n", RTEMS_RFS_BITMAP_BIT_CLEAR);
+ printf (" Num bit per element : %zd\n", rtems_rfs_bitmap_element_bits ());
+
+#if INT_MAX >= 0x23984237
+ srand (0x23984237);
+#else
+ srand (0x2398);
+#endif
+
+ rtems_rfs_bitmap_ut_test_bitmap (2048);
+ rtems_rfs_bitmap_ut_test_bitmap (420);
+}
+
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-bitmaps.c b/cpukit/libfs/src/rfs/rtems-rfs-bitmaps.c
new file mode 100644
index 0000000000..98715488f9
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-bitmaps.c
@@ -0,0 +1,646 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Bitmap Routines.
+ *
+ * These functions manage bit maps. A bit map consists of the map of bit
+ * allocated in a block and a search map where a bit represents 32 actual
+ * bits. The search map allows for a faster search for an available bit as 32
+ * search bits can checked in a test.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/**
+ * Set to 1 to enable warnings when developing.
+ */
+#define RTEMS_RFS_BITMAP_WARNINGS 0
+
+#if RTEMS_RFS_BITMAP_WARNINGS
+#include <stdio.h>
+#endif
+#include <stdlib.h>
+#include <rtems/rfs/rtems-rfs-bitmaps.h>
+
+/**
+ * Test a bit in an element. If set return true else return false.
+ *
+ * @param target The target to test the bit in.
+ * @param bit The bit to test.
+ * @retval true The bit is set.
+ * @retval false The bit is clear.
+ */
+static bool
+rtems_rfs_bitmap_test (rtems_rfs_bitmap_element target,
+ rtems_rfs_bitmap_bit bit)
+{
+ return RTEMS_RFS_BITMAP_TEST_BIT (target, bit);
+}
+
+/**
+ * Set the bits in the element. Bits not set in the bit argument are left
+ * unchanged.
+ *
+ * @param target The target element bits are set.
+ * @param bits The bits in the target to set. A 1 in the bits will set the
+ * same bit in the target.
+ */
+static rtems_rfs_bitmap_element
+rtems_rfs_bitmap_set (rtems_rfs_bitmap_element target,
+ rtems_rfs_bitmap_element bits)
+{
+ return RTEMS_RFS_BITMAP_SET_BITS (target, bits);
+}
+
+/**
+ * Clear the bits in the element. Bits not set in the bit argument are left
+ * unchanged.
+ *
+ * @param target The target element to clear the bits in.
+ * @param bits The bits in the target to clear. A 1 in the bits will clear the
+ * bit in the target.
+ */
+static rtems_rfs_bitmap_element
+rtems_rfs_bitmap_clear (rtems_rfs_bitmap_element target,
+ rtems_rfs_bitmap_element bits)
+{
+ return RTEMS_RFS_BITMAP_CLEAR_BITS (target, bits);
+}
+
+/**
+ * Merge the bits in 2 variables based on the mask. A set bit in the mask will
+ * merge the bits from bits1 and a clear bit will merge the bits from bits2.
+ * The mask is always defined as 1 being set and 0 being clear.
+ */
+static rtems_rfs_bitmap_element
+rtems_rfs_bitmap_merge (rtems_rfs_bitmap_element bits1,
+ rtems_rfs_bitmap_element bits2,
+ rtems_rfs_bitmap_element mask)
+{
+ /*
+ * Use the normal bit operators because we do not change the bits just merge
+ * the 2 separate parts.
+ */
+ bits1 &= mask;
+ bits2 &= RTEMS_RFS_BITMAP_INVERT_MASK (mask);
+ return bits1 | bits2;
+}
+
+/**
+ * Match the bits of 2 elements and return true if they match else return
+ * false.
+ *
+ * @param bits1 One set of bits to match.
+ * @param bits2 The second set of bits to match.
+ * @retval true The bits match.
+ * @retval false The bits do not match.
+ */
+static bool
+rtems_rfs_bitmap_match (rtems_rfs_bitmap_element bits1,
+ rtems_rfs_bitmap_element bits2)
+{
+ return bits1 ^ bits2 ? false : true;
+}
+
+#if RTEMS_NOT_USED_BUT_KEPT
+/**
+ * Match the bits of 2 elements within the mask and return true if they match
+ * else return false.
+ *
+ * @param mask The mask over which the match occurs. A 1 is a valid mask bit.
+ * @param bits1 One set of bits to match.
+ * @param bits2 The second set of bits to match.
+ * @retval true The bits match.
+ * @retval false The bits do not match.
+ */
+static bool
+rtems_rfs_bitmap_match_masked (rtems_rfs_bitmap_element mask,
+ rtems_rfs_bitmap_element bits1,
+ rtems_rfs_bitmap_element bits2)
+{
+ return (bits1 ^ bits2) & mask ? false : true;
+}
+#endif
+
+/**
+ * Return the map after loading from disk if not already loaded.
+ *
+ * @param control The bitmap control.
+ * @param rtems_rfs_bitmap_map* Pointer to the bitmap map data if no error.
+ * @return int The error number (errno). No error if 0.
+ */
+static int
+rtems_rfs_bitmap_load_map (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_map* map)
+{
+ int rc;
+
+ if (!control->buffer)
+ return ENXIO;
+
+ *map = NULL;
+
+ rc = rtems_rfs_buffer_handle_request (control->fs,
+ control->buffer,
+ control->block,
+ true);
+ if (rc)
+ return rc;
+
+ *map = rtems_rfs_buffer_data (control->buffer);
+ return 0;
+}
+
+rtems_rfs_bitmap_element
+rtems_rfs_bitmap_mask (unsigned int size)
+{
+ rtems_rfs_bitmap_element mask = RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK;
+ mask >>= (rtems_rfs_bitmap_element_bits () - size);
+ return mask;
+}
+
+rtems_rfs_bitmap_element
+rtems_rfs_bitmap_mask_section (unsigned int start, unsigned int end)
+{
+ rtems_rfs_bitmap_element mask = 0;
+ if (end > start)
+ mask = rtems_rfs_bitmap_mask (end - start) << start;
+ return mask;
+}
+
+int
+rtems_rfs_bitmap_map_set (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit bit)
+{
+ rtems_rfs_bitmap_map map;
+ rtems_rfs_bitmap_map search_map;
+ int index;
+ int offset;
+ int rc;
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+ if (bit >= control->size)
+ return EINVAL;
+ search_map = control->search_bits;
+ index = rtems_rfs_bitmap_map_index (bit);
+ offset = rtems_rfs_bitmap_map_offset (bit);
+ map[index] = rtems_rfs_bitmap_set (map[index], 1 << offset);
+ if (rtems_rfs_bitmap_match(map[index], RTEMS_RFS_BITMAP_ELEMENT_SET))
+ {
+ bit = index;
+ index = rtems_rfs_bitmap_map_index (bit);
+ offset = rtems_rfs_bitmap_map_offset (bit);
+ search_map[index] = rtems_rfs_bitmap_set (search_map[index], 1 << offset);
+ control->free--;
+ rtems_rfs_buffer_mark_dirty (control->buffer);
+ }
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_map_clear (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit bit)
+{
+ rtems_rfs_bitmap_map map;
+ rtems_rfs_bitmap_map search_map;
+ int index;
+ int offset;
+ int rc;
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+ if (bit >= control->size)
+ return EINVAL;
+ search_map = control->search_bits;
+ index = rtems_rfs_bitmap_map_index (bit);
+ offset = rtems_rfs_bitmap_map_offset (bit);
+ map[index] = rtems_rfs_bitmap_clear (map[index], 1 << offset);
+ bit = index;
+ index = rtems_rfs_bitmap_map_index (bit);
+ offset = rtems_rfs_bitmap_map_offset(bit);
+ search_map[index] = rtems_rfs_bitmap_clear (search_map[index], 1 << offset);
+ rtems_rfs_buffer_mark_dirty (control->buffer);
+ control->free++;
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_map_test (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit bit,
+ bool* state)
+{
+ rtems_rfs_bitmap_map map;
+ int index;
+ int rc;
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+ if (bit >= control->size)
+ return EINVAL;
+ index = rtems_rfs_bitmap_map_index (bit);
+ *state = rtems_rfs_bitmap_test (map[index], bit);
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_map_set_all (rtems_rfs_bitmap_control* control)
+{
+ rtems_rfs_bitmap_map map;
+ size_t elements;
+ int e;
+ int rc;
+
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+
+ elements = rtems_rfs_bitmap_elements (control->size);
+
+ control->free = 0;
+
+ for (e = 0; e < elements; e++)
+ map[e] = RTEMS_RFS_BITMAP_ELEMENT_SET;
+
+ elements = rtems_rfs_bitmap_elements (elements);
+
+ for (e = 0; e < elements; e++)
+ control->search_bits[e] = RTEMS_RFS_BITMAP_ELEMENT_SET;
+
+ rtems_rfs_buffer_mark_dirty (control->buffer);
+
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_map_clear_all (rtems_rfs_bitmap_control* control)
+{
+ rtems_rfs_bitmap_map map;
+ rtems_rfs_bitmap_bit last_search_bit;
+ size_t elements;
+ int e;
+ int rc;
+
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+
+ elements = rtems_rfs_bitmap_elements (control->size);
+
+ control->free = elements;
+
+ for (e = 0; e < elements; e++)
+ map[e] = RTEMS_RFS_BITMAP_ELEMENT_CLEAR;
+
+ /*
+ * Set the un-mapped bits in the last search element so the available logic
+ * works.
+ */
+ last_search_bit = rtems_rfs_bitmap_map_offset (elements);
+
+ if (last_search_bit == 0)
+ last_search_bit = rtems_rfs_bitmap_element_bits ();
+
+ elements = rtems_rfs_bitmap_elements (elements);
+
+ for (e = 0; e < (elements - 1); e++)
+ control->search_bits[e] = RTEMS_RFS_BITMAP_ELEMENT_CLEAR;
+
+ control->search_bits[elements - 1] =
+ rtems_rfs_bitmap_merge (RTEMS_RFS_BITMAP_ELEMENT_CLEAR,
+ RTEMS_RFS_BITMAP_ELEMENT_SET,
+ rtems_rfs_bitmap_mask (last_search_bit));
+
+ rtems_rfs_buffer_mark_dirty (control->buffer);
+
+ return 0;
+}
+
+static int
+rtems_rfs_search_map_for_clear_bit (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit* bit,
+ bool* found,
+ size_t window,
+ int direction)
+{
+ rtems_rfs_bitmap_map map;
+ rtems_rfs_bitmap_bit test_bit;
+ rtems_rfs_bitmap_bit end_bit;
+ rtems_rfs_bitmap_element* search_bits;
+ int search_index;
+ int search_offset;
+ rtems_rfs_bitmap_element* map_bits;
+ int map_index;
+ int map_offset;
+ int rc;
+
+ *found = false;
+
+ /*
+ * Load the bitmap.
+ */
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+
+ /*
+ * Calculate the bit we are testing plus the end point we search over.
+ */
+ test_bit = *bit;
+ end_bit = test_bit + (window * direction);
+
+ if (end_bit < 0)
+ end_bit = 0;
+ else if (end_bit >= control->size)
+ end_bit = control->size - 1;
+
+ map_index = rtems_rfs_bitmap_map_index (test_bit);
+ map_offset = rtems_rfs_bitmap_map_offset (test_bit);
+ search_index = rtems_rfs_bitmap_map_index (map_index);
+ search_offset = rtems_rfs_bitmap_map_offset (map_index);
+
+ search_bits = &control->search_bits[search_index];
+ map_bits = &map[map_index];
+
+ /*
+ * Check each bit from the search map offset for a clear bit.
+ */
+ do
+ {
+ /*
+ * If any bit is clear find that bit and then search the map element. If
+ * all bits are set there are no map bits so move to the next search
+ * element.
+ */
+ if (!rtems_rfs_bitmap_match (*search_bits, RTEMS_RFS_BITMAP_ELEMENT_SET))
+ {
+ while ((search_offset >= 0)
+ && (search_offset < rtems_rfs_bitmap_element_bits ()))
+ {
+ if (!rtems_rfs_bitmap_test (*search_bits, search_offset))
+ {
+ /*
+ * Find the clear bit in the map. Update the search map and map if
+ * found. We may find none are spare if searching up from the seed.
+ */
+ while ((map_offset >= 0)
+ && (map_offset < rtems_rfs_bitmap_element_bits ()))
+ {
+ if (!rtems_rfs_bitmap_test (*map_bits, map_offset))
+ {
+ *map_bits = rtems_rfs_bitmap_set (*map_bits, 1 << map_offset);
+ if (rtems_rfs_bitmap_match(*map_bits,
+ RTEMS_RFS_BITMAP_ELEMENT_SET))
+ *search_bits = rtems_rfs_bitmap_set (*search_bits,
+ 1 << search_offset);
+ control->free--;
+ *bit = test_bit;
+ *found = true;
+ rtems_rfs_buffer_mark_dirty (control->buffer);
+ return 0;
+ }
+
+ if (test_bit == end_bit)
+ break;
+
+ map_offset += direction;
+ test_bit += direction;
+ }
+ }
+
+ map_bits += direction;
+ map_index += direction;
+ map_offset = direction > 0 ? 0 : rtems_rfs_bitmap_element_bits () - 1;
+
+ test_bit = (map_index * rtems_rfs_bitmap_element_bits ()) + map_offset;
+
+ search_offset += direction;
+
+ if (((direction < 0) && (test_bit <= end_bit))
+ || ((direction > 0) && (test_bit >= end_bit)))
+ break;
+ }
+ }
+ else
+ {
+ /*
+ * Move to the next search element. We need to determine the number of
+ * bits in the search offset that are being skipped so the map bits
+ * pointer can be updated. If we are moving down and we have a search
+ * offset of 0 then the search map adjustment is to the top bit of the
+ * pervious search bit's value.
+ *
+ * Align test_bit either up or down depending on the direction to next 32
+ * bit boundary.
+ */
+ rtems_rfs_bitmap_bit bits_skipped;
+ test_bit &= ~((1 << RTEMS_RFS_ELEMENT_BITS_POWER_2) - 1);
+ if (direction > 0)
+ {
+ bits_skipped = rtems_rfs_bitmap_element_bits () - search_offset;
+ test_bit += bits_skipped * rtems_rfs_bitmap_element_bits ();
+ map_offset = 0;
+ }
+ else
+ {
+ bits_skipped = search_offset + 1;
+ /*
+ * Need to remove 1 for the rounding up. The above rounds down and
+ * adds 1. Remember the logic is for subtraction.
+ */
+ test_bit -= ((bits_skipped - 1) * rtems_rfs_bitmap_element_bits ()) + 1;
+ map_offset = rtems_rfs_bitmap_element_bits () - 1;
+ }
+ map_bits += direction * bits_skipped;
+ map_index += direction * bits_skipped;
+ }
+
+ search_bits += direction;
+ search_offset = direction > 0 ? 0 : rtems_rfs_bitmap_element_bits () - 1;
+ }
+ while (((direction < 0) && (test_bit >= end_bit))
+ || ((direction > 0) && (test_bit <= end_bit)));
+
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_map_alloc (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit seed,
+ bool* allocated,
+ rtems_rfs_bitmap_bit* bit)
+{
+ rtems_rfs_bitmap_bit upper_seed;
+ rtems_rfs_bitmap_bit lower_seed;
+ rtems_rfs_bitmap_bit window; /* may become a parameter */
+ int rc = 0;
+
+ /*
+ * By default we assume the allocation failed.
+ */
+ *allocated = false;
+
+ /*
+ * The window is the number of bits we search over in either direction each
+ * time.
+ */
+ window = RTEMS_RFS_BITMAP_SEARCH_WINDOW;
+
+ /*
+ * Start from the seed and move in either direction. Search in window amounts
+ * of bits from the original seed above then below. That is search from the
+ * seed up then from the seed down a window number of bits, then repeat the
+ * process from the window distance from the seed, again above then
+ * below. Keep moving out until all bits have been searched.
+ */
+ upper_seed = seed;
+ lower_seed = seed;
+
+ /*
+ * If the upper and lower seed values have reached the limits of the bitmap
+ * we have searched all of the map. The seed may not be aligned to a window
+ * boundary so we may need to search a partial window and this may also not
+ * be balanced for the upper or lower seeds. We move to the limits, search
+ * then return false if no clear bits are found.
+ */
+ while (((upper_seed >= 0) && (upper_seed < control->size))
+ || ((lower_seed >= 0) && (lower_seed < control->size)))
+ {
+ /*
+ * Search up first so bits allocated in succession are grouped together.
+ */
+ if (upper_seed < control->size)
+ {
+ *bit = upper_seed;
+ rc = rtems_rfs_search_map_for_clear_bit (control, bit, allocated,
+ window, 1);
+ if ((rc > 0) || *allocated)
+ break;
+ }
+
+ if (lower_seed >= 0)
+ {
+ *bit = lower_seed;
+ rc = rtems_rfs_search_map_for_clear_bit (control, bit, allocated,
+ window, -1);
+ if ((rc > 0) || *allocated)
+ break;
+ }
+
+ /*
+ * Do not bound the limits at the edges of the map. Do not update if an
+ * edge has been passed.
+ */
+ if (upper_seed < control->size)
+ upper_seed += window;
+ if (lower_seed >= 0)
+ lower_seed -= window;
+ }
+
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_create_search (rtems_rfs_bitmap_control* control)
+{
+ rtems_rfs_bitmap_map search_map;
+ rtems_rfs_bitmap_map map;
+ size_t size;
+ rtems_rfs_bitmap_bit bit;
+ int rc;
+
+ rc = rtems_rfs_bitmap_load_map (control, &map);
+ if (rc > 0)
+ return rc;
+
+ control->free = 0;
+ search_map = control->search_bits;
+ size = control->size;
+ bit = 0;
+
+ *search_map = RTEMS_RFS_BITMAP_ELEMENT_CLEAR;
+ while (size)
+ {
+ rtems_rfs_bitmap_element bits;
+ int available;
+ if (size < rtems_rfs_bitmap_element_bits ())
+ {
+ bits = rtems_rfs_bitmap_merge (*map,
+ RTEMS_RFS_BITMAP_ELEMENT_SET,
+ rtems_rfs_bitmap_mask_section (0, size));
+ available = size;
+ }
+ else
+ {
+ bits = *map;
+ available = rtems_rfs_bitmap_element_bits ();
+ }
+
+ if (rtems_rfs_bitmap_match (bits, RTEMS_RFS_BITMAP_ELEMENT_SET))
+ rtems_rfs_bitmap_set (*search_map, bit);
+ else
+ {
+ int b;
+ for (b = 0; b < available; b++)
+ if (!rtems_rfs_bitmap_test (bits, b))
+ control->free++;
+ }
+
+ size -= available;
+
+ if (bit == rtems_rfs_bitmap_element_bits ())
+ {
+ bit = 0;
+ search_map++;
+ *search_map = RTEMS_RFS_BITMAP_ELEMENT_CLEAR;
+ }
+ else
+ bit++;
+ map++;
+ }
+
+ return 0;
+}
+
+int
+rtems_rfs_bitmap_open (rtems_rfs_bitmap_control* control,
+ rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* buffer,
+ size_t size,
+ rtems_rfs_buffer_block block)
+{
+ size_t elements = rtems_rfs_bitmap_elements (size);
+
+ control->buffer = buffer;
+ control->fs = fs;
+ control->block = block;
+ control->size = size;
+
+ elements = rtems_rfs_bitmap_elements (elements);
+ control->search_bits = malloc (elements * sizeof (rtems_rfs_bitmap_element));
+
+ if (!control->search_bits)
+ return ENOMEM;
+
+ return rtems_rfs_bitmap_create_search (control);
+}
+
+int
+rtems_rfs_bitmap_close (rtems_rfs_bitmap_control* control)
+{
+ free (control->search_bits);
+ return 0;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-bitmaps.h b/cpukit/libfs/src/rfs/rtems-rfs-bitmaps.h
new file mode 100644
index 0000000000..50759b529d
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-bitmaps.h
@@ -0,0 +1,303 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Bitmap Routines.
+ *
+ * These functions manage bit maps. A bit map consists of the map of bit
+ * allocated in a block and a search map where a bit represents 32 actual
+ * bits. The search map allows for a faster search for an available bit as 32
+ * search bits can checked in a test.
+ */
+
+#if !defined (_RTEMS_RFS_BITMAPS_H_)
+#define _RTEMS_RFS_BITMAPS_H_
+
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-file-system-fwd.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+/**
+ * Define the way the bits are configured. We can have them configured as clear
+ * being 0 or clear being 1. This does not effect how masks are defined. A mask
+ * always has a 1 for set and 0 for clear.
+ */
+#define RTEMS_RFS_BITMAP_CLEAR_ZERO 0
+
+#if RTEMS_RFS_BITMAP_CLEAR_ZERO
+/*
+ * Bit set is a 1 and clear is 0.
+ */
+#define RTEMS_RFS_BITMAP_BIT_CLEAR 0
+#define RTEMS_RFS_BITMAP_BIT_SET 1
+#define RTEMS_RFS_BITMAP_ELEMENT_SET (RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK)
+#define RTEMS_RFS_BITMAP_ELEMENT_CLEAR (0)
+#define RTEMS_RFS_BITMAP_SET_BITS(_t, _b) ((_t) | (_b))
+#define RTEMS_RFS_BITMAP_CLEAR_BITS(_t, _b) ((_t) & ~(_b))
+#define RTEMS_RFS_BITMAP_TEST_BIT(_t, _b) (((_t) & (1 << (_b))) != 0 ? true : false)
+#else
+/*
+ * Bit set is a 0 and clear is 1.
+ */
+#define RTEMS_RFS_BITMAP_BIT_CLEAR 1
+#define RTEMS_RFS_BITMAP_BIT_SET 0
+#define RTEMS_RFS_BITMAP_ELEMENT_SET (0)
+#define RTEMS_RFS_BITMAP_ELEMENT_CLEAR (RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK)
+#define RTEMS_RFS_BITMAP_SET_BITS(_t, _b) ((_t) & ~(_b))
+#define RTEMS_RFS_BITMAP_CLEAR_BITS(_t, _b) ((_t) | (_b))
+#define RTEMS_RFS_BITMAP_TEST_BIT(_t, _b) (((_t) & (1 << (_b))) == 0 ? true : false)
+#endif
+
+/**
+ * Invert a mask. Masks are always 1 for set and 0 for clear.
+ */
+#define RTEMS_RFS_BITMAP_INVERT_MASK(_mask) (~(_mask))
+
+/**
+ * This is the full mask of the length of the element. A mask is always a 1 for
+ * set and 0 for clear. It is not effected by the state of
+ * RTEMS_RFS_BITMAP_CLEAR_ZERO.
+ */
+#define RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK (0xffffffffUL)
+
+/**
+ * The bitmap search window. Searches occur around a seed in either direction
+ * for half the window.
+ */
+#define RTEMS_RFS_BITMAP_SEARCH_WINDOW (rtems_rfs_bitmap_element_bits () * 64)
+
+/**
+ * A bit in a map.
+ */
+typedef int32_t rtems_rfs_bitmap_bit;
+
+/**
+ * The basic element of a bitmap. A bitmap is manipulated by elements.
+ */
+typedef uint32_t rtems_rfs_bitmap_element;
+
+/**
+ * The power of 2 number of bits in the element.
+ */
+#define RTEMS_RFS_ELEMENT_BITS_POWER_2 (5)
+
+/**
+ * A bitmap or map is an array of bitmap elements.
+ */
+typedef rtems_rfs_bitmap_element* rtems_rfs_bitmap_map;
+
+/**
+ * The bitmap control is a simple way to manage the various parts of a bitmap.
+ */
+typedef struct rtems_rfs_bitmap_control_s
+{
+ rtems_rfs_buffer_handle* buffer; //< Handle the to buffer with the bit
+ //map.
+ rtems_rfs_file_system* fs; //< The map's file system.
+ rtems_rfs_buffer_block block; //< The map's block number on disk.
+ size_t size; //< Number of bits in the map. Passed
+ //to create.
+ size_t free; //< Number of bits in the map that are
+ //free (clear).
+ rtems_rfs_bitmap_map search_bits; //< The search bit map memory.
+} rtems_rfs_bitmap_control;
+
+/**
+ * Return the number of bits for the number of bytes provided.
+ */
+#define rtems_rfs_bitmap_numof_bits(_bytes) (8 * (_bytes))
+
+/**
+ * Return the number of bits for the number of bytes provided. The search
+ * element and the element must have the same number of bits.
+ */
+#define rtems_rfs_bitmap_element_bits() \
+ rtems_rfs_bitmap_numof_bits (sizeof (rtems_rfs_bitmap_element))
+
+/**
+ * Return the number of bits a search element covers.
+ */
+#define rtems_rfs_bitmap_search_element_bits() \
+ (rtems_rfs_bitmap_element_bits() * rtems_rfs_bitmap_element_bits())
+
+/**
+ * Return the number of elements for a given number of bits.
+ */
+#define rtems_rfs_bitmap_elements(_bits) \
+ ((((_bits) - 1) / rtems_rfs_bitmap_element_bits()) + 1)
+
+/**
+ * Release the bitmap buffer back to the buffer pool or cache.
+ */
+#define rtems_rfs_bitmap_release_buffer(_fs, _bm) \
+ rtems_rfs_buffer_handle_release (_fs, (_bm)->buffer)
+
+/**
+ * Return the element index for a given bit. We use a macro to hide any
+ * implementation assuptions. Typically this would be calculated by dividing
+ * the bit index by the number of bits in an element. Given we have a power of
+ * 2 as the number of bits we can avoid the division by using a shift. A good
+ * compiler should figure this out but I would rather enforce this than rely on
+ * the specific backend of a compiler to do the right thing.
+ */
+#define rtems_rfs_bitmap_map_index(_b) \
+ ((_b) >> RTEMS_RFS_ELEMENT_BITS_POWER_2)
+
+/**
+ * Return the bit offset for a given bit in an element in a map. See @ref
+ * rtems_rfs_bitmap_map_index for a detailed reason why.
+ */
+#define rtems_rfs_bitmap_map_offset(_b) \
+ ((_b) & ((1 << RTEMS_RFS_ELEMENT_BITS_POWER_2) - 1))
+
+/**
+ * Return the size of the bitmap.
+ */
+#define rtems_rfs_bitmap_map_size(_c) ((_c)->size)
+
+/**
+ * Return the number of free bits in the bitmap.
+ */
+#define rtems_rfs_bitmap_map_free(_c) ((_c)->free)
+
+/**
+ * Return the buffer handle.
+ */
+#define rtems_rfs_bitmap_map_handle(_c) ((_c)->buffer)
+
+/**
+ * Return the bitmap map block.
+ */
+#define rtems_rfs_bitmap_map_block(_c) ((_c)->block)
+
+/**
+ * Create a bit mask with the specified number of bits up to an element's
+ * size. The mask is aligned to bit 0 of the element.
+ *
+ * @param size The number of bits in the mask.
+ * @return The mask of the argument size number of bits.
+ */
+rtems_rfs_bitmap_element rtems_rfs_bitmap_mask (unsigned int size);
+
+/**
+ * Create a bit mask section. A mask section is a mask that is not aligned to
+ * an end of the element.
+ *
+ * @param start The first bit of the mask numbered from 0.
+ * @param end The end bit of the mask numbered from 0.
+ * @return Mask section as defined by the start and end arguments.
+ */
+rtems_rfs_bitmap_element rtems_rfs_bitmap_mask_section (unsigned int start,
+ unsigned int end);
+
+/**
+ * Set a bit in a map and if all the bits are set, set the search map bit as
+ * well.
+ *
+ * @param control The control for the map.
+ * @param bit The bit in the map to set.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_map_set (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit bit);
+
+/**
+ * Clear a bit in a map and make sure the search map bit is clear so a search
+ * will find this bit available.
+ *
+ * @param control The control for the map.
+ * @param bit The bit in the map to clear.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_map_clear (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit bit);
+
+/**
+ * Test a bit in the map.
+ *
+ * @param control The bitmap control.
+ * @param bit The bit to test.
+ * @param state The state of the bit if no error is returned.
+ * @return int The error number (errno). No error if 0.
+ */
+int
+rtems_rfs_bitmap_map_test (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit bit,
+ bool* state);
+
+/**
+ * Set all bits in the bitmap and set the dirty bit.
+ *
+ * @param control The bitmap control.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_map_set_all (rtems_rfs_bitmap_control* control);
+
+/**
+ * Clear all bits in the bitmap and set the dirty bit.
+ *
+ * @param control The bitmap control.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_map_clear_all (rtems_rfs_bitmap_control* control);
+
+/**
+ * Find a free bit searching from the seed up and down until found. The search
+ * is performing by moving up from the seed for the window distance then to
+ * search down from the seed for the window distance. This is repeated out from
+ * the seed for each window until a free bit is found. The search is performed
+ * by checking the search map to see if the map has a free bit.
+ *
+ * @param control The map control.
+ * @param seed The bit to search out from.
+ * @param allocate A bit was allocated.
+ * @param bit Returns the bit found free if true is returned.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_map_alloc (rtems_rfs_bitmap_control* control,
+ rtems_rfs_bitmap_bit seed,
+ bool* allocate,
+ rtems_rfs_bitmap_bit* bit);
+
+/**
+ * Create a search bit map from the actual bit map.
+ *
+ * @param control The map control.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_create_search (rtems_rfs_bitmap_control* control);
+
+/**
+ * Open a bitmap control with a map and search map.
+ *
+ * @param control The map control.
+ * @param fs The file system data.
+ * @param buffer The buffer handle the map is stored in.
+ * @param size The number of bits in the map.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_open (rtems_rfs_bitmap_control* control,
+ rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* buffer,
+ size_t size,
+ rtems_rfs_buffer_block block);
+
+/**
+ * Close a bitmap.
+ *
+ * @param control The bit map control.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_bitmap_close (rtems_rfs_bitmap_control* control);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h b/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h
new file mode 100644
index 0000000000..b15f0ba113
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h
@@ -0,0 +1,239 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Block Position and Size Management.
+ *
+ * These functions manage the position in a block map as well as a size of data
+ * held in a block map. The position is the block count plus the offset into
+ * the last block where a block position of 0 and an offset of 0 is the start
+ * of a map. The size has a block count plus an offset, but the offset into the
+ * last block gives the actual size of the data in the map. This means a size
+ * will always have a block count greater than 0 when the file is not empty. A
+ * size offset of 0 and a non-zero block count means the length if aligned to
+ * the end of the block. For this reason there are 2 similar types so we know
+ * which set of rules are in use and the reason for this file.
+ */
+
+#if !defined (_RTEMS_RFS_BLOCK_POS_H_)
+#define _RTEMS_RFS_BLOCK_POS_H_
+
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+
+/**
+ * The block number is the same type as the inode block number. This makes sure
+ * the sizes of the types match.
+ */
+typedef rtems_rfs_inode_block rtems_rfs_block_no;
+
+/**
+ * The offset into a block.
+ */
+typedef uint32_t rtems_rfs_block_off;
+
+/**
+ * A block position is a block number times the block size plus the offset. The
+ * block field can be used hold a block number for the position as a look up
+ * cache.
+ */
+typedef struct rtems_rfs_block_pos_s
+{
+ /**
+ * The block index in the map. Range is from 0 to the maps block count minus
+ * 1.
+ */
+ rtems_rfs_block_no bno;
+
+ /**
+ * The offset into the block. Must be less than the block size.
+ */
+ rtems_rfs_block_off boff;
+
+ /**
+ * The block number that the bpos + boff map to. The 0 value is invalid and
+ * means no block number has been set.
+ */
+ rtems_rfs_block_no block;
+
+} rtems_rfs_block_pos;
+
+/**
+ * Copy a block position.
+ *
+ * @param _lhs The left hand side.
+ * @param _rhs The right hand side.
+ */
+#define rtems_rfs_block_copy_bpos(_lhs, _rhs) \
+ do { (_lhs)->bno = (_rhs)->bno; \
+ (_lhs)->boff = (_rhs)->boff; \
+ (_lhs)->block = (_rhs)->block; } while (0)
+
+/**
+ * Zero a block position.
+ *
+ * @param bpos A pointer to the block position.
+ */
+static inline void
+rtems_rfs_block_set_bpos_zero (rtems_rfs_block_pos* bpos)
+{
+ bpos->bno = 0;
+ bpos->boff = 0;
+ bpos->block = 0;
+}
+
+/**
+ * Given a position compute the block number and block offset.
+ *
+ * @param fs The file system data.
+ * @param pos The position as an absolute offset from the start.
+ * @param bpos Pointer to the block position to fill in.
+ */
+void rtems_rfs_block_get_bpos (rtems_rfs_file_system* fs,
+ rtems_rfs_pos pos,
+ rtems_rfs_block_pos* bpos);
+
+/**
+ * Given a block position compute the absolute offset.
+ *
+ * @param fs The file system data.
+ * @param bpos Pointer to the block position to fill in.
+ * @return rtems_rfs_pos The absolute offset.
+ */
+rtems_rfs_pos rtems_rfs_block_get_pos (rtems_rfs_file_system* fs,
+ rtems_rfs_block_pos* bpos);
+
+/**
+ * Add the relative position to the block position. The relative position is
+ * signed.
+ *
+ * @param fs The file system data.
+ * @param offset The relative offset add to the block position.
+ * @param bpos Pointer to the block position to fill in.
+ */
+static inline void
+rtems_rfs_block_add_pos (rtems_rfs_file_system* fs,
+ rtems_rfs_pos_rel offset,
+ rtems_rfs_block_pos* bpos)
+{
+ rtems_rfs_block_get_bpos (fs,
+ rtems_rfs_block_get_pos (fs, bpos) + offset,
+ bpos);
+ bpos->block = 0;
+}
+
+/**
+ * A block size is the number of blocks less one plus the offset where the
+ * offset must be less than the block size.
+ */
+typedef struct rtems_rfs_block_size_s
+{
+ /**
+ * The count of blocks in a map. A 0 means no blocks and a zero length and
+ * the offset should also be 0.
+ */
+ rtems_rfs_block_no count;
+
+ /**
+ * The offset into the block. An offset of 0 means block size, ie the first
+ * byte of the next block which is not allocated.
+ */
+ rtems_rfs_block_off offset;
+
+} rtems_rfs_block_size;
+
+/**
+ * Copy a block size.
+ *
+ * @param _lhs The left hand side.
+ * @param _rhs The right hand side.
+ */
+#define rtems_rfs_block_copy_size(_lhs, _rhs) \
+ do { (_lhs)->count = (_rhs)->count; \
+ (_lhs)->offset = (_rhs)->offset; } while (0)
+
+/**
+ * Last block ?
+ */
+#define rtems_rfs_block_pos_last_block(_p, _s) \
+ ((((_p)->bno == 0) && ((_s)->count == 0)) || ((_p)->bno == ((_s)->count - 1)))
+
+/**
+ * Last block ?
+ */
+#define rtems_rfs_block_pos_past_end(_p, _s) \
+ (((_p)->bno && ((_s)->count == 0)) || \
+ ((_p)->bno >= (_s)->count) || \
+ (((_p)->bno == ((_s)->count - 1)) && ((_p)->boff > (_s)->offset)))
+
+/**
+ * Is the block position past the end.
+ */
+#define rtems_rfs_block_pos_block_past_end(_p, _s) \
+ (((_p)->bno && ((_s)->count == 0)) || ((_p)->bno >= (_s)->count))
+
+/**
+ * Copy the size to the block position. Note the block position and the size
+ * have different block counts.
+ */
+#define rtems_rfs_block_size_get_bpos(_s, _b) \
+ do { (_b)->bno = (_s)->count; \
+ (_b)->boff = (_s)->offset; \
+ (_b)->block = 0; \
+ if ((_b)->boff) --(_b)->bno; } while (0)
+
+/**
+ * Do the sizes match ?
+ */
+#define rtems_rfs_block_size_equal(_lhs, _rhs) \
+ (((_lhs)->count == (_rhs)->count) && ((_lhs)->offset == (_rhs)->offset))
+
+/**
+ * Zero a block size.
+ *
+ * @param size A pointer to the block size.
+ */
+static inline void
+rtems_rfs_block_set_size_zero (rtems_rfs_block_size* size)
+{
+ size->count = 0;
+ size->offset = 0;
+}
+
+/**
+ * Set the size given a position.
+ *
+ * @param fs The file system data.
+ * @param pos The position as an absolute offset from the start.
+ * @param size Pointer to the block size to fill in.
+ */
+void rtems_rfs_block_get_block_size (rtems_rfs_file_system* fs,
+ rtems_rfs_pos pos,
+ rtems_rfs_block_size* size);
+
+/**
+ * Calculate the position given the number of blocks and the offset. If the
+ * block count is 0 the size is 0. If the block is greater than 0 and the
+ * offset is 0 the size is number of blocks multipled by the block size and if
+ * the offset is not 0 it is the offset into the last block. For example if
+ * blocks is 1 and offset is 0 the size is the block size. If the block count
+ * is 1 and size is 100 the size is 100.
+ *
+ * @param fs The file system data.
+ * @param size The size in blocks and offset.
+ * @return rtems_rfs_pos The size in bytes.
+ */
+rtems_rfs_pos rtems_rfs_block_get_size (rtems_rfs_file_system* fs,
+ rtems_rfs_block_size* size);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-block.c b/cpukit/libfs/src/rfs/rtems-rfs-block.c
new file mode 100644
index 0000000000..776c7f314d
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-block.c
@@ -0,0 +1,800 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Block Routines.
+ *
+ * These functions manage blocks in the RFS file system. A block is an area of
+ * the media and its size is set for a each specific media. The block size is
+ * set when the file system is set up and needs to be matched for it to be read
+ * correctly.
+ *
+ * Blocks are managed as groups. A block group or "group" is part of the total
+ * number of blocks being managed by the file system and exist to allow
+ * resources to localised. A file in a directory will be allocated blocks in
+ * the same group as the directory, and the blocks for the file will also be
+ * allocated in the same group.
+ *
+ * A group consist of a block bitmap, inodes and data blocks. The first block
+ * of the file system will hold the superblock. The block bitmap is a
+ * collection of blocks that hold a map of bits, one bit per block for each
+ * block in the group. When a file system is mounted the block bitmaps are read
+ * and a summary bit map is made. The summary bitmap has a single bit for 32
+ * bits in the bitmap and is set when all 32 bits it maps to are set. This
+ * speeds up the search for a free block by a factor of 32.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-block.h>
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-group.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+
+void
+rtems_rfs_block_get_bpos (rtems_rfs_file_system* fs,
+ rtems_rfs_pos pos,
+ rtems_rfs_block_pos* bpos)
+{
+ bpos->bno = pos / rtems_rfs_fs_block_size (fs);
+ bpos->boff = pos % rtems_rfs_fs_block_size (fs);
+}
+
+rtems_rfs_pos
+rtems_rfs_block_get_pos (rtems_rfs_file_system* fs,
+ rtems_rfs_block_pos* bpos)
+{
+ return (bpos->bno * rtems_rfs_fs_block_size (fs)) + bpos->boff;
+}
+
+void
+rtems_rfs_block_get_block_size (rtems_rfs_file_system* fs,
+ rtems_rfs_pos pos,
+ rtems_rfs_block_size* size)
+{
+ if (pos == 0)
+ rtems_rfs_block_set_size_zero (size);
+ else
+ {
+ size->count = pos / rtems_rfs_fs_block_size (fs) + 1;
+ size->offset = pos % rtems_rfs_fs_block_size (fs);
+ }
+}
+
+rtems_rfs_pos
+rtems_rfs_block_get_size (rtems_rfs_file_system* fs,
+ rtems_rfs_block_size* size)
+{
+ uint32_t offset;
+ uint64_t block_size;
+ if (size->count == 0)
+ return 0;
+ if (size->offset == 0)
+ offset = rtems_rfs_fs_block_size (fs);
+ else
+ offset = size->offset;
+ block_size = rtems_rfs_fs_block_size (fs);
+ return (((uint64_t) (size->count - 1)) * block_size) + offset;
+}
+
+int
+rtems_rfs_block_map_open (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* inode,
+ rtems_rfs_block_map* map)
+{
+ int b;
+ int rc;
+
+ /*
+ * Set the count to 0 so at least find fails, then open the handle and make
+ * sure the inode has been loaded into memory. If we did not load the inode
+ * do not unload it. The caller may assume it is still loaded when we return.
+ */
+
+ map->dirty = false;
+ map->inode = NULL;
+ rtems_rfs_block_set_size_zero (&map->size);
+ rtems_rfs_block_set_bpos_zero (&map->bpos);
+
+ rc = rtems_rfs_buffer_handle_open (fs, &map->singly_buffer);
+ if (rc > 0)
+ return rc;
+ rc = rtems_rfs_buffer_handle_open (fs, &map->doubly_buffer);
+ if (rc > 0)
+ return rc;
+
+ rc = rtems_rfs_inode_load (fs, inode);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &map->singly_buffer);
+ rtems_rfs_buffer_handle_close (fs, &map->doubly_buffer);
+ return rc;
+ }
+
+ /*
+ * Extract the block and block count data from the inode into the targets
+ * byte order.
+ */
+ map->inode = inode;
+ for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
+ map->blocks[b] = rtems_rfs_inode_get_block (inode, b);
+ map->size.count = rtems_rfs_inode_get_block_count (inode);
+ map->size.offset = rtems_rfs_inode_get_block_offset (inode);
+ map->last_map_block = rtems_rfs_inode_get_last_map_block (inode);
+ map->last_data_block = rtems_rfs_inode_get_last_data_block (inode);
+
+ rc = rtems_rfs_inode_unload (fs, inode, false);
+
+ return rc;
+}
+
+int
+rtems_rfs_block_map_close (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map)
+{
+ int rc = 0;
+ int brc;
+
+ if (map->dirty && map->inode)
+ {
+ brc = rtems_rfs_inode_load (fs, map->inode);
+ if (brc > 0)
+ rc = brc;
+
+ if (rc == 0)
+ {
+ int b;
+
+ for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
+ rtems_rfs_inode_set_block (map->inode, b, map->blocks[b]);
+ rtems_rfs_inode_set_block_count (map->inode, map->size.count);
+ rtems_rfs_inode_set_block_offset (map->inode, map->size.offset);
+ rtems_rfs_inode_set_last_map_block (map->inode, map->last_map_block);
+ rtems_rfs_inode_set_last_data_block (map->inode, map->last_data_block);
+
+ brc = rtems_rfs_inode_unload (fs, map->inode, true);
+ if (brc > 0)
+ rc = brc;
+
+ map->dirty = false;
+ }
+ }
+
+ map->inode = NULL;
+
+ brc = rtems_rfs_buffer_handle_close (fs, &map->singly_buffer);
+ if ((brc > 0) && (rc == 0))
+ rc = brc;
+ brc = rtems_rfs_buffer_handle_close (fs, &map->doubly_buffer);
+ if ((brc > 0) && (rc == 0))
+ rc = brc;
+ return rc;
+}
+
+/**
+ * Find a block indirectly held in a table of block numbers.
+ *
+ * @param fs The file system.
+ * @param buffer The handle to access the block data by.
+ * @param block The block number of the table of block numbers.
+ * @param offset The offset in the table of the block number to return. This is
+ * a block number offset not a byte offset into the table.
+ * @param result Pointer to the result of the search.
+ * @return int The error number (errno). No error if 0.
+ */
+static int
+rtems_rfs_block_find_indirect (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* buffer,
+ rtems_rfs_block_no block,
+ int offset,
+ rtems_rfs_block_no* result)
+{
+ int rc;
+
+ /*
+ * If the handle has a buffer and this request is a different block the current
+ * buffer is released.
+ */
+ rc = rtems_rfs_buffer_handle_request (fs, buffer, block, true);
+ if (rc > 0)
+ return rc;
+
+ *result = rtems_rfs_block_get_number (buffer, offset);
+ if ((*result + 1) == 0)
+ *result = 0;
+
+ if (*result >= rtems_rfs_fs_blocks (fs))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BLOCK_FIND))
+ printf ("rtems-rfs: block-find: invalid block in table:"
+ " block=%" PRId32 ", indirect=%" PRId32 "/%d\n", *result, block, offset);
+ *result = 0;
+ rc = EIO;
+ }
+
+ return 0;
+}
+
+int
+rtems_rfs_block_map_find (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_block_pos* bpos,
+ rtems_rfs_block_no* block)
+{
+ int rc = 0;
+
+ *block = 0;
+
+ /*
+ * Range checking here makes the remaining logic simpler.
+ */
+ if (rtems_rfs_block_pos_block_past_end (bpos, &map->size))
+ return ENXIO;
+
+ /*
+ * If the block position is the same and we have found the block just return it.
+ */
+ if ((bpos->bno == map->bpos.bno) && (map->bpos.block != 0))
+ {
+ *block = map->bpos.block;
+ }
+ else
+ {
+ /*
+ * Determine the type of access we need to perform. If the number of blocks
+ * is less than or equal to the number of slots in the inode the blocks are
+ * directly accessed.
+ */
+ if (map->size.count <= RTEMS_RFS_INODE_BLOCKS)
+ {
+ *block = map->blocks[bpos->bno];
+ }
+ else
+ {
+ /*
+ * The map is either singly or doubly indirect.
+ */
+ rtems_rfs_block_no direct;
+ rtems_rfs_block_no singly;
+
+ direct = bpos->bno % fs->blocks_per_block;
+ singly = bpos->bno / fs->blocks_per_block;
+
+ if (map->size.count <= fs->block_map_singly_blocks)
+ {
+ /*
+ * This is a single indirect table of blocks anchored off a slot in the
+ * inode.
+ */
+ rc = rtems_rfs_block_find_indirect (fs,
+ &map->singly_buffer,
+ map->blocks[singly],
+ direct, block);
+ }
+ else
+ {
+ /*
+ * The map is doubly indirect.
+ */
+ rtems_rfs_block_no doubly;
+
+ doubly = singly / fs->blocks_per_block;
+ singly %= fs->blocks_per_block;
+
+ if (map->size.count < fs->block_map_doubly_blocks)
+ {
+ rc = rtems_rfs_block_find_indirect (fs,
+ &map->doubly_buffer,
+ map->blocks[doubly],
+ singly, &singly);
+ if (rc == 0)
+ {
+ rc = rtems_rfs_block_find_indirect (fs,
+ &map->singly_buffer,
+ singly, direct, block);
+ }
+ }
+ else
+ {
+ /*
+ * This should never happen. Here so Joel can remove once his coverage
+ * testing gets to the file systems.
+ */
+ rc = ENXIO;
+ }
+ }
+ }
+ }
+
+ if (rc == 0)
+ {
+ rtems_rfs_block_copy_bpos (&map->bpos, bpos);
+ map->bpos.block = *block;
+ }
+
+ return rc;
+}
+
+int
+rtems_rfs_block_map_seek (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_pos_rel offset,
+ rtems_rfs_block_no* block)
+{
+ rtems_rfs_block_pos bpos;
+ rtems_rfs_block_copy_bpos (&bpos, &map->bpos);
+ rtems_rfs_block_add_pos (fs, offset, &bpos);
+ return rtems_rfs_block_map_find (fs, map, &bpos, block);
+}
+
+int
+rtems_rfs_block_map_next_block (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_block_no* block)
+{
+ rtems_rfs_block_pos bpos;
+ bpos.bno = map->bpos.bno + 1;
+ bpos.boff = 0;
+ bpos.block = 0;
+ return rtems_rfs_block_map_find (fs, map, &bpos, block);
+}
+
+/**
+ * Allocate an indirect block to a map.
+ *
+ * @param fs The file system data.
+ * @param map The map the allocation is for.
+ * @param buffer The buffer the indirect block is accessed by.
+ * @param block The block number of the indirect block allocated.
+ * @param upping True is upping the map to the next indirect level.
+ * @return int The error number (errno). No error if 0.
+ */
+static int
+rtems_rfs_block_map_indirect_alloc (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_buffer_handle* buffer,
+ rtems_rfs_block_no* block,
+ bool upping)
+{
+ rtems_rfs_bitmap_bit new_block;
+ int rc;
+ /*
+ * Save the new block locally because upping can have *block pointing to the
+ * slots which are cleared when upping.
+ */
+ rc = rtems_rfs_group_bitmap_alloc (fs, map->last_map_block, false, &new_block);
+ if (rc > 0)
+ return rc;
+ rc = rtems_rfs_buffer_handle_request (fs, buffer, new_block, false);
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, new_block);
+ return rc;
+ }
+ memset (rtems_rfs_buffer_data (buffer), 0xff, rtems_rfs_fs_block_size (fs));
+ if (upping)
+ {
+ int b;
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BLOCK_MAP_GROW))
+ printf ("rtems-rfs: block-map-grow: upping: block-count=%" PRId32 "\n",
+ map->size.count);
+ for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
+ rtems_rfs_block_set_number (buffer, b, map->blocks[b]);
+ memset (map->blocks, 0, sizeof (map->blocks));
+ }
+ rtems_rfs_buffer_mark_dirty (buffer);
+ *block = new_block;
+ map->last_map_block = new_block;
+ return 0;
+}
+
+int
+rtems_rfs_block_map_grow (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ size_t blocks,
+ rtems_rfs_block_no* new_block)
+{
+ int b;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BLOCK_MAP_GROW))
+ printf ("rtems-rfs: block-map-grow: entry: blocks=%zd count=%" PRIu32 "\n",
+ blocks, map->size.count);
+
+ if ((map->size.count + blocks) >= rtems_rfs_fs_max_block_map_blocks (fs))
+ return EFBIG;
+
+ /*
+ * Allocate a block at a time. The buffer handles hold the blocks so adding
+ * this way does not thrash the cache with lots of requests.
+ */
+ for (b = 0; b < blocks; b++)
+ {
+ rtems_rfs_bitmap_bit block;
+ int rc;
+
+ /*
+ * Allocate the block. If an indirect block is needed and cannot be
+ * allocated free this block.
+ */
+
+ rc = rtems_rfs_group_bitmap_alloc (fs, map->last_data_block,
+ false, &block);
+ if (rc > 0)
+ return rc;
+
+ if (map->size.count < RTEMS_RFS_INODE_BLOCKS)
+ map->blocks[map->size.count] = block;
+ else
+ {
+ /*
+ * Single indirect access is occuring. It could still be doubly indirect.
+ */
+ rtems_rfs_block_no direct;
+ rtems_rfs_block_no singly;
+
+ direct = map->size.count % fs->blocks_per_block;
+ singly = map->size.count / fs->blocks_per_block;
+
+ if (map->size.count < fs->block_map_singly_blocks)
+ {
+ /*
+ * Singly indirect tables are being used. Allocate a new block for a
+ * mapping table if direct is 0 or we are moving up (upping). If upping
+ * move the direct blocks into the table and if not this is the first
+ * entry of a new block.
+ */
+ if ((direct == 0) ||
+ ((singly == 0) && (direct == RTEMS_RFS_INODE_BLOCKS)))
+ {
+ /*
+ * Upping is when we move from direct to singly indirect.
+ */
+ bool upping;
+ upping = map->size.count == RTEMS_RFS_INODE_BLOCKS;
+ rc = rtems_rfs_block_map_indirect_alloc (fs, map,
+ &map->singly_buffer,
+ &map->blocks[singly],
+ upping);
+ }
+ else
+ {
+ rc = rtems_rfs_buffer_handle_request (fs, &map->singly_buffer,
+ map->blocks[singly], true);
+ }
+
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, block);
+ return rc;
+ }
+ }
+ else
+ {
+ /*
+ * Doubly indirect tables are being used.
+ */
+ rtems_rfs_block_no doubly;
+ rtems_rfs_block_no singly_block;
+
+ doubly = singly / fs->blocks_per_block;
+ singly %= fs->blocks_per_block;
+
+ /*
+ * Allocate a new block for a singly indirect table if direct is 0 as
+ * it is the first entry of a new block. We may also need to allocate a
+ * doubly indirect block as well. Both always occur when direct is 0
+ * and the doubly indirect block when singly is 0.
+ */
+ if (direct == 0)
+ {
+ rc = rtems_rfs_block_map_indirect_alloc (fs, map,
+ &map->singly_buffer,
+ &singly_block,
+ false);
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, block);
+ return rc;
+ }
+
+ /*
+ * Allocate a new block for a doubly indirect table if singly is 0 as
+ * it is the first entry of a new singly indirect block.
+ */
+ if ((singly == 0) ||
+ ((doubly == 0) && (singly == RTEMS_RFS_INODE_BLOCKS)))
+ {
+ bool upping;
+ upping = map->size.count == fs->block_map_singly_blocks;
+ rc = rtems_rfs_block_map_indirect_alloc (fs, map,
+ &map->doubly_buffer,
+ &map->blocks[doubly],
+ upping);
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, singly_block);
+ rtems_rfs_group_bitmap_free (fs, false, block);
+ return rc;
+ }
+ }
+ else
+ {
+ rc = rtems_rfs_buffer_handle_request (fs, &map->doubly_buffer,
+ map->blocks[doubly], true);
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, singly_block);
+ rtems_rfs_group_bitmap_free (fs, false, block);
+ return rc;
+ }
+ }
+
+ rtems_rfs_block_set_number (&map->doubly_buffer,
+ singly,
+ singly_block);
+ }
+ else
+ {
+ rc = rtems_rfs_buffer_handle_request (fs,
+ &map->doubly_buffer,
+ map->blocks[doubly],
+ true);
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, block);
+ return rc;
+ }
+
+ singly_block = rtems_rfs_block_get_number (&map->doubly_buffer,
+ singly);
+
+ rc = rtems_rfs_buffer_handle_request (fs, &map->singly_buffer,
+ singly_block, true);
+ if (rc > 0)
+ {
+ rtems_rfs_group_bitmap_free (fs, false, block);
+ return rc;
+ }
+ }
+ }
+
+ rtems_rfs_block_set_number (&map->singly_buffer, direct, block);
+ }
+
+ map->size.count++;
+ map->size.offset = 0;
+
+ if (b == 0)
+ *new_block = block;
+ map->last_data_block = block;
+ map->dirty = true;
+ }
+
+ return 0;
+}
+
+/**
+ * Shrink an indirect block.
+ *
+ * @param fs The file system data.
+ * @param map The map the allocation is for.
+ * @param buffer The buffer the indirect block is accessed by.
+ * @param indirect The index index in the inode's block table.
+ * @param index The index in the indirect table of the block.
+ * @return int The error number (errno). No error if 0.
+ */
+static int
+rtems_rfs_block_map_indirect_shrink (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_buffer_handle* buffer,
+ rtems_rfs_block_no indirect,
+ rtems_rfs_block_no index)
+{
+ int rc = 0;
+
+ /*
+ * If this is the first block in the indirect table (index == 0), ie the last
+ * block to be freed and the indirect block is now also free, or we have only
+ * one indirect table and we can fit the remaining blocks into the inode,
+ * then either move to the next indirect block or move the remaining blocks
+ * into the inode and free the indirect table's block.
+ */
+ if ((index == 0) ||
+ ((indirect == 0) && (index == RTEMS_RFS_INODE_BLOCKS)))
+ {
+ rtems_rfs_block_no block_to_free = map->blocks[indirect];
+
+ if ((indirect == 0) && (index == RTEMS_RFS_INODE_BLOCKS))
+ {
+ /*
+ * Move to direct inode access.
+ */
+ int b;
+ for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
+ map->blocks[b] = rtems_rfs_block_get_number (buffer, b);
+ }
+ else
+ {
+ /*
+ * One less singly indirect block in the inode.
+ */
+ map->blocks[indirect] = 0;
+ }
+
+ rc = rtems_rfs_group_bitmap_free (fs, false, block_to_free);
+ if (rc > 0)
+ return rc;
+
+ map->last_map_block = block_to_free;
+ }
+
+ return rc;
+}
+
+int
+rtems_rfs_block_map_shrink (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ size_t blocks)
+{
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BLOCK_MAP_SHRINK))
+ printf ("rtems-rfs: block-map-shrink: entry: blocks=%zd count=%" PRIu32 "\n",
+ blocks, map->size.count);
+
+ if (map->size.count == 0)
+ return 0;
+
+ if (blocks > map->size.count)
+ blocks = map->size.count;
+
+ while (blocks)
+ {
+ rtems_rfs_block_no block;
+ rtems_rfs_block_no block_to_free;
+ int rc;
+
+ block = map->size.count - 1;
+
+ if (block < RTEMS_RFS_INODE_BLOCKS)
+ {
+ /*
+ * We have less than RTEMS_RFS_INODE_BLOCKS so they are held in the
+ * inode.
+ */
+ block_to_free = map->blocks[block];
+ map->blocks[block] = 0;
+ }
+ else
+ {
+ /*
+ * Single indirect access is occuring. It could still be doubly indirect.
+ *
+ * The 'direct' variable is the offset in to the indirect table of
+ * blocks, and 'singly' is the inode block index of the singly indirect
+ * table of block numbers.
+ */
+ rtems_rfs_block_no direct;
+ rtems_rfs_block_no singly;
+
+ direct = block % fs->blocks_per_block;
+ singly = block / fs->blocks_per_block;
+
+ if (block < fs->block_map_singly_blocks)
+ {
+ /*
+ * Request the indirect block and then obtain the block number from the
+ * indirect block.
+ */
+ rc = rtems_rfs_buffer_handle_request (fs, &map->singly_buffer,
+ map->blocks[singly], true);
+ if (rc > 0)
+ return rc;
+
+ block_to_free = rtems_rfs_block_get_number (&map->singly_buffer,
+ direct);
+
+ rc = rtems_rfs_block_map_indirect_shrink (fs, map, &map->singly_buffer,
+ singly, direct);
+ if (rc)
+ return rc;
+ }
+ else if (block < fs->block_map_doubly_blocks)
+ {
+ /*
+ * Doubly indirect tables are being used. The 'doubly' variable is the
+ * index in to the inode's block table and points to a singly indirect
+ * table of block numbers. The 'doubly_singly' variable is the index
+ * into the doubly indirect table pointing to the singly indirect table
+ * of block numbers that form the map. This is used later to determine
+ * if the current doubly indirect table needs to be freed. The 'direct'
+ * value is still valid for doubly indirect tables.
+ */
+ rtems_rfs_block_no doubly;
+ rtems_rfs_block_no doubly_singly;
+
+ doubly = singly / fs->blocks_per_block;
+ doubly_singly = singly % fs->blocks_per_block;
+
+ rc = rtems_rfs_buffer_handle_request (fs, &map->doubly_buffer,
+ map->blocks[doubly], true);
+ if (rc > 0)
+ return rc;
+
+ singly = rtems_rfs_block_get_number (&map->doubly_buffer,
+ doubly_singly);
+
+ /*
+ * Read the singly indirect table and get the block number.
+ */
+ rc = rtems_rfs_buffer_handle_request (fs, &map->singly_buffer,
+ singly, true);
+ if (rc > 0)
+ return rc;
+
+ block_to_free = rtems_rfs_block_get_number (&map->singly_buffer,
+ direct);
+
+ if (direct == 0)
+ {
+ rc = rtems_rfs_group_bitmap_free (fs, false, singly);
+ if (rc > 0)
+ return rc;
+
+ map->last_map_block = singly;
+
+ rc = rtems_rfs_block_map_indirect_shrink (fs, map, &map->doubly_buffer,
+ doubly, doubly_singly);
+ if (rc)
+ return rc;
+ }
+ }
+ else
+ {
+ rc = EIO;
+ break;
+ }
+ }
+ rc = rtems_rfs_group_bitmap_free (fs, false, block_to_free);
+ if (rc > 0)
+ return rc;
+ map->size.count--;
+ map->size.offset = 0;
+ map->last_data_block = block_to_free;
+ map->dirty = true;
+ blocks--;
+ }
+
+ if (map->size.count == 0)
+ {
+ map->last_map_block = 0;
+ map->last_data_block = 0;
+ }
+
+ /*
+ * Keep the position inside the map.
+ */
+ if (rtems_rfs_block_pos_past_end (&map->bpos, &map->size))
+ rtems_rfs_block_size_get_bpos (&map->size, &map->bpos);
+
+ return 0;
+}
+
+int
+rtems_rfs_block_map_free_all (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map)
+{
+ return rtems_rfs_block_map_shrink (fs, map, map->size.count);
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-block.h b/cpukit/libfs/src/rfs/rtems-rfs-block.h
new file mode 100644
index 0000000000..e4e3f95830
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-block.h
@@ -0,0 +1,324 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Block Management.
+ *
+ * These functions manage the blocks used in the file system.
+ */
+
+#if !defined (_RTEMS_RFS_BLOCK_H_)
+#define _RTEMS_RFS_BLOCK_H_
+
+#include <rtems/rfs/rtems-rfs-block-pos.h>
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+
+/**
+ * Get a block number in the media format and return it in the host format.
+ *
+ * @param _h The buffer handle of the block.
+ * @param _b The block number index.
+ * @return uint32_t The block number.
+ */
+#define rtems_rfs_block_get_number(_h, _b) \
+ ((rtems_rfs_block_no) \
+ (rtems_rfs_read_u32 (rtems_rfs_buffer_data (_h) + \
+ ((_b) * sizeof (rtems_rfs_block_no)))))
+
+/**
+ * Set a block number in the media format given a number in the host format.
+ *
+ * @param _h The buffer handle of the block.
+ * @param _b The block number index, ie the number of block number not the
+ * buffer offset.
+ * @param _n The block number.
+ */
+#define rtems_rfs_block_set_number(_h, _b, _n) \
+ do { \
+ rtems_rfs_write_u32 (rtems_rfs_buffer_data (_h) + \
+ ((_b) * sizeof (rtems_rfs_block_no)), (_n)); \
+ rtems_rfs_buffer_mark_dirty (_h); \
+ } while (0)
+
+/**
+ * A block map manges the block lists that originate from an inode. The inode
+ * contains a number of block numbers. A block map takes those block numbers
+ * and manages them.
+ *
+ * The blocks cannot have all ones as a block number nor block 0. The block map
+ * is series of block numbers in a blocks. The size of the map determines the
+ * way the block numbers are stored. The map uses the following:
+ *
+ * @li @e Direct Access,
+ * @li @e Single Indirect Access, and
+ * @li @e Double Indirect Access.
+ *
+ * Direct access has the blocks numbers in the inode slots. The Single Indirect
+ * Access has block numbers in the inode slots that pointer to a table of block
+ * numbers that point to data blocks. The Double Indirect Access has block
+ * numbers in the inode that point to Single Indirect block tables.
+ *
+ * The inode can hold a number of Direct, Single Indirect, and Double Indirect
+ * block tables. The move from Direct to Single occurs then the block count in
+ * the map is above the number of slots in the inode. The move from Single to
+ * Double occurs when the map block count is greated than the block numbers per
+ * block multipled by the slots in the inode. The move from Single to Double
+ * occurs when the map block count is over the block numbers per block squared
+ * multipled by the number of slots in the inode.
+ *
+ * The block map can managed files of the follow size verses block size with 5
+ * inode slots:
+ *
+ * @li 41,943,040 bytes for a 512 byte block size,
+ * @li 335,544,320 bytes for a 1024 byte block size,
+ * @li 2,684,354,560 bytes for a 2048 byte block size, and
+ * @li 21,474,836,480 bytes for a 4096 byte block size.
+ */
+typedef struct rtems_rfs_block_map_s
+{
+ /**
+ * Is the map dirty ?
+ */
+ bool dirty;
+
+ /**
+ * The inode this map is attached to.
+ */
+ rtems_rfs_inode_handle* inode;
+
+ /**
+ * The size of the map.
+ */
+ rtems_rfs_block_size size;
+
+ /**
+ * The block map position. Used to navigate the map when seeking. The find
+ * call is to a position in the file/directory and is a block number plus
+ * offset. The block find only needs to locate a block and not worry about
+ * the offset while a seek can be less than a block size yet move across a
+ * block boundary. Therefore the position a block map has to maintain must
+ * include the offset so seeks work.
+ */
+ rtems_rfs_block_pos bpos;
+
+ /**
+ * The last map block allocated. This is used as the goal when allocating a
+ * new map block.
+ */
+ rtems_rfs_block_no last_map_block;
+
+ /**
+ * The last data block allocated. This is used as the goal when allocating a
+ * new data block.
+ */
+ rtems_rfs_block_no last_data_block;
+
+ /**
+ * The block map.
+ */
+ uint32_t blocks[RTEMS_RFS_INODE_BLOCKS];
+
+ /**
+ * Singly Buffer handle.
+ */
+ rtems_rfs_buffer_handle singly_buffer;
+
+ /**
+ * Doubly Buffer handle.
+ */
+ rtems_rfs_buffer_handle doubly_buffer;
+
+} rtems_rfs_block_map;
+
+/**
+ * Is the map dirty ?
+ */
+#define rtems_rfs_block_map_is_dirty(_m) ((_m)->dirty)
+
+/**
+ * Return the block count in the map.
+ */
+#define rtems_rfs_block_map_count(_m) ((_m)->size.count)
+
+/**
+ * Return the map's size element.
+ */
+#define rtems_rfs_block_map_size(_m) (&((_m)->size))
+
+/**
+ * Return the size offset for the map.
+ */
+#define rtems_rfs_block_map_size_offset(_m) ((_m)->size.offset)
+
+/**
+ * Are we at the last block in the map ?
+ */
+#define rtems_rfs_block_map_last(_m) \
+ rtems_rfs_block_pos_last_block (&(_m)->bpos, &(_m)->size)
+
+/**
+ * Is the position past the end of the block ?
+ */
+#define rtems_rfs_block_map_past_end(_m, _p) \
+ rtems_rfs_block_pos_past_end (_p, &(_m)->size)
+
+/**
+ * Return the current position in the map.
+ */
+#define rtems_rfs_block_map_pos(_f, _m) \
+ rtems_rfs_block_get_pos (_f, &(_m)->bpos)
+
+/**
+ * Return the map's current block number.
+ */
+#define rtems_rfs_block_map_block(_m) ((_m)->bpos.bno)
+
+/**
+ * Return the map's current block offset.
+ */
+#define rtems_rfs_block_map_block_offset(_m) ((_m)->bpos.boff)
+
+/**
+ * Set the size offset for the map. The map is tagged as dirty.
+ *
+ * @param map Pointer to the open map to set the offset in.
+ * @param offset The offset to set in the map's size.
+ */
+static inline void
+rtems_rfs_block_map_set_size_offset (rtems_rfs_block_map* map,
+ rtems_rfs_block_off offset)
+{
+ map->size.offset = offset;
+ map->dirty = true;
+}
+
+/**
+ * Set the map's size. The map is tagged as dirty.
+ *
+ * @param map Pointer to the open map to set the offset in.
+ * @param size The size to set in the map's size.
+ */
+static inline void
+rtems_rfs_block_map_set_size (rtems_rfs_block_map* map,
+ rtems_rfs_block_size* size)
+{
+ rtems_rfs_block_copy_size (&map->size, size);
+ map->dirty = true;
+}
+/**
+ * Open a block map. The block map data in the inode is copied into the
+ * map. The buffer handles are opened. The block position is set to the start
+ * so a seek of offset 0 will return the first block.
+ *
+ * @param fs The file system data.
+ * @param inode The inode the map belongs to.
+ * @param map The map that is opened.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_open (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* inode,
+ rtems_rfs_block_map* map);
+
+/**
+ * Close the map. The buffer handles are closed and any help buffers are
+ * released.
+ *
+ * @param fs The file system data.
+ * @param map The map that is opened.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_close (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map);
+
+/**
+ * Find a block number in the map from the position provided.
+ *
+ * @param fs The file system data.
+ * @param map The map to search.
+ * @param bpos The block position to find.
+ * @param block Pointer to place the block in when found.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_find (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_block_pos* bpos,
+ rtems_rfs_buffer_block* block);
+
+/**
+ * Seek around the map.
+ *
+ * @param fs The file system data.
+ * @param map The map to search.
+ * @param offset The distance to seek. It is signed.
+ * @param block Pointer to place the block in when found.
+ * @retval ENXIO Failed to seek because it is outside the block map.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_seek (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_pos_rel offset,
+ rtems_rfs_buffer_block* block);
+
+/**
+ * Seek to the next block.
+ *
+ * @param fs The file system data.
+ * @param map The map to search.
+ * @param block Pointer to place the block in when found.
+ * @retval ENXIO Failed to seek because it is outside the block map.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_next_block (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ rtems_rfs_buffer_block* block);
+
+/**
+ * Grow the block map by the specified number of blocks.
+ *
+ * @param fs The file system data.
+ * @param map Pointer to the open map to grow.
+ * @param blocks The number of blocks to grow the map by.
+ * @param new_block The first of the blocks allocated to the map.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_grow (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ size_t blocks,
+ rtems_rfs_block_no* new_block);
+
+/**
+ * Grow the block map by the specified number of blocks.
+ *
+ * @param fs The file system data.
+ * @param map Pointer to the open map to shrink.
+ * @param blocks The number of blocks to shrink the map by. If more than the
+ * number of blocks the map is emptied.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_shrink (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map,
+ size_t blocks);
+
+/**
+ * Free all blocks in the map.
+ *
+ * @param fs The file system data.
+ * @param map Pointer to the open map to free all blocks from.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_block_map_free_all (rtems_rfs_file_system* fs,
+ rtems_rfs_block_map* map);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c b/cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c
new file mode 100644
index 0000000000..536b136ed6
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c
@@ -0,0 +1,92 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Buffer Routines for the RTEMS libblock BD buffer cache.
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+#include <errno.h>
+
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+
+#if RTEMS_RFS_USE_LIBBLOCK
+
+/**
+ * Show errors.
+ */
+#define RTEMS_RFS_BUFFER_ERRORS 0
+
+int
+rtems_rfs_buffer_bdbuf_request (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_block block,
+ bool read,
+ rtems_rfs_buffer** buffer)
+{
+ rtems_status_code sc;
+ int rc = 0;
+
+ if (read)
+ sc = rtems_bdbuf_read (rtems_rfs_fs_device (fs), block, buffer);
+ else
+ sc = rtems_bdbuf_get (rtems_rfs_fs_device (fs), block, buffer);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+#if RTEMS_RFS_BUFFER_ERRORS
+ printf ("rtems-rfs: buffer-bdbuf-request: block=%lu: bdbuf-%s: %d: %s\n",
+ block, read ? "read" : "get", sc, rtems_status_text (sc));
+#endif
+ rc = EIO;
+ }
+
+ return rc;
+}
+
+int
+rtems_rfs_buffer_bdbuf_release (rtems_rfs_buffer* buffer,
+ bool modified)
+{
+ rtems_status_code sc;
+ int rc = 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_RELEASE))
+ printf ("rtems-rfs: bdbuf-release: block=%" PRIuPTR " bdbuf=%" PRIu32 " %s\n",
+ ((intptr_t) buffer->user),
+ buffer->block, modified ? "(modified)" : "");
+
+ if (modified)
+ sc = rtems_bdbuf_release_modified (buffer);
+ else
+ sc = rtems_bdbuf_release (buffer);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+#if RTEMS_RFS_BUFFER_ERRORS
+ printf ("rtems-rfs: buffer-release: bdbuf-%s: %s(%d)\n",
+ modified ? "modified" : "not-modified",
+ rtems_status_text (sc), sc);
+#endif
+ rc = EIO;
+ }
+
+ return rc;
+}
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer-devio.c b/cpukit/libfs/src/rfs/rtems-rfs-buffer-devio.c
new file mode 100644
index 0000000000..714c2bf300
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-buffer-devio.c
@@ -0,0 +1,61 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Buffer Routines.
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+
+#if !RTEMS_RFS_USE_LIBBLOCK
+
+/**
+ * Show errors.
+ */
+#define RTEMS_RFS_BUFFER_ERRORS 1
+
+int
+rtems_rfs_buffer_deviceio_request (rtems_rfs_buffer_handle* handle,
+ dev_t device,
+ rtems_rfs_buffer_block block,
+ bool read)
+{
+}
+
+int
+rtems_rfs_buffer_deviceio_release (rtems_rfs_buffer_handle* handle,
+ dev_t device)
+{
+}
+
+int
+rtems_rfs_buffer_deviceio_handle_open (rtems_rfs_buffer_handle* handle,
+ dev_t device)
+{
+}
+
+int
+rtems_rfs_buffer_device_handle_close (rtems_rfs_buffer_handle* handle,
+ dev_t device)
+{
+}
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer.c b/cpukit/libfs/src/rfs/rtems-rfs-buffer.c
new file mode 100644
index 0000000000..43fb586895
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-buffer.c
@@ -0,0 +1,484 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Buffer Routines.
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+#include <errno.h>
+
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+
+/**
+ * Scan the chain for a buffer that matches the block number.
+ *
+ * @param chain The chain to scan.
+ * @param count The number of items on the chain.
+ * @param block The block number to find.
+ * @return rtems_rfs_buffer* The buffer if found else NULL.
+ */
+static rtems_rfs_buffer*
+rtems_rfs_scan_chain (rtems_chain_control* chain,
+ uint32_t* count,
+ rtems_rfs_buffer_block block)
+{
+ rtems_rfs_buffer* buffer;
+ rtems_chain_node* node;
+
+ node = rtems_chain_last (chain);
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
+ printf ("rtems-rfs: buffer-scan: count=%" PRIu32 ", block=%" PRIu32 ": ", *count, block);
+
+ while (!rtems_chain_is_head (chain, node))
+ {
+ buffer = (rtems_rfs_buffer*) node;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
+ printf ("%" PRIuPTR " ", ((intptr_t) buffer->user));
+
+ if (((rtems_rfs_buffer_block) ((intptr_t)(buffer->user))) == block)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
+ printf (": found block=%" PRIuPTR "\n",
+ ((intptr_t)(buffer->user)));
+
+ (*count)--;
+ rtems_chain_extract (node);
+ rtems_chain_set_off_chain (node);
+ return buffer;
+ }
+ node = rtems_chain_previous (node);
+ }
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
+ printf (": not found\n");
+
+ return NULL;
+}
+
+int
+rtems_rfs_buffer_handle_request (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* handle,
+ rtems_rfs_buffer_block block,
+ bool read)
+{
+ int rc;
+
+ /*
+ * If the handle has a buffer release it. This allows a handle to be reused
+ * without needing to close then open it again.
+ */
+ if (rtems_rfs_buffer_handle_has_block (handle))
+ {
+ /*
+ * Treat block 0 as special to handle the loading of the super block.
+ */
+ if (block && (rtems_rfs_buffer_bnum (handle) == block))
+ return 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_REQUEST))
+ printf ("rtems-rfs: buffer-request: handle has buffer: %" PRIu32 "\n",
+ rtems_rfs_buffer_bnum (handle));
+
+ rc = rtems_rfs_buffer_handle_release (fs, handle);
+ if (rc > 0)
+ return rc;
+ handle->dirty = false;
+ handle->bnum = 0;
+ }
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_REQUEST))
+ printf ("rtems-rfs: buffer-request: block=%" PRIu32 "\n", block);
+
+ /*
+ * First check to see if the buffer has already been requested and is
+ * currently attached to a handle. If it is share the access. A buffer could
+ * be shared where different parts of the block have separate functions. An
+ * example is an inode block and the file system needs to handle 2 inodes in
+ * the same block at the same time.
+ */
+ if (fs->buffers_count)
+ {
+ /*
+ * Check the active buffer list for shared buffers.
+ */
+ handle->buffer = rtems_rfs_scan_chain (&fs->buffers,
+ &fs->buffers_count,
+ block);
+ if (rtems_rfs_buffer_handle_has_block (handle) &&
+ rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_REQUEST))
+ printf ("rtems-rfs: buffer-request: buffer shared: refs: %d\n",
+ rtems_rfs_buffer_refs (handle) + 1);
+ }
+
+ /*
+ * If the buffer has not been found check the local cache of released
+ * buffers. There are release and released modified lists to preserve the
+ * state.
+ */
+ if (!rtems_rfs_fs_no_local_cache (fs) &&
+ !rtems_rfs_buffer_handle_has_block (handle))
+ {
+ /*
+ * Check the local cache of released buffers.
+ */
+ if (fs->release_count)
+ handle->buffer = rtems_rfs_scan_chain (&fs->release,
+ &fs->release_count,
+ block);
+
+ if (!rtems_rfs_buffer_handle_has_block (handle) &&
+ fs->release_modified_count)
+ {
+ handle->buffer = rtems_rfs_scan_chain (&fs->release_modified,
+ &fs->release_modified_count,
+ block);
+ /*
+ * If we found a buffer retain the dirty buffer state.
+ */
+ if (rtems_rfs_buffer_handle_has_block (handle))
+ rtems_rfs_buffer_mark_dirty (handle);
+ }
+ }
+
+ /*
+ * If not located we request the buffer from the I/O layer.
+ */
+ if (!rtems_rfs_buffer_handle_has_block (handle))
+ {
+ rc = rtems_rfs_buffer_io_request (fs, block, read, &handle->buffer);
+
+ rtems_chain_set_off_chain (rtems_rfs_buffer_link(handle));
+
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_REQUEST))
+ printf ("rtems-rfs: buffer-request: block=%" PRIu32 ": bdbuf-%s: %d: %s\n",
+ block, read ? "read" : "get", rc, strerror (rc));
+ return rc;
+ }
+ }
+
+ /*
+ * Increase the reference count of the buffer.
+ */
+ rtems_rfs_buffer_refs_up (handle);
+ rtems_chain_append (&fs->buffers, rtems_rfs_buffer_link (handle));
+ fs->buffers_count++;
+
+ handle->buffer->user = (void*) ((intptr_t) block);
+ handle->bnum = block;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_REQUEST))
+ printf ("rtems-rfs: buffer-request: block=%" PRIu32 " bdbuf-%s=%" PRIu32 " refs=%d\n",
+ block, read ? "read" : "get", handle->buffer->block,
+ handle->buffer->references);
+
+ return 0;
+}
+
+int
+rtems_rfs_buffer_handle_release (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* handle)
+{
+ int rc = 0;
+
+ if (rtems_rfs_buffer_handle_has_block (handle))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_RELEASE))
+ printf ("rtems-rfs: buffer-release: block=%" PRIu32 " %s refs=%d %s\n",
+ rtems_rfs_buffer_bnum (handle),
+ rtems_rfs_buffer_dirty (handle) ? "(dirty)" : "",
+ rtems_rfs_buffer_refs (handle),
+ rtems_rfs_buffer_refs (handle) == 0 ? "BAD REF COUNT" : "");
+
+ if (rtems_rfs_buffer_refs (handle) > 0)
+ rtems_rfs_buffer_refs_down (handle);
+
+ if (rtems_rfs_buffer_refs (handle) == 0)
+ {
+ rtems_chain_extract (rtems_rfs_buffer_link (handle));
+ fs->buffers_count--;
+
+ if (rtems_rfs_fs_no_local_cache (fs))
+ {
+ handle->buffer->user = (void*) 0;
+ rc = rtems_rfs_buffer_io_release (handle->buffer,
+ rtems_rfs_buffer_dirty (handle));
+ }
+ else
+ {
+ /*
+ * If the total number of held buffers is higher than the configured
+ * value remove a buffer from the queue with the most buffers and
+ * release. The buffers are held on the queues with the newest at the
+ * head.
+ *
+ * This code stops a large series of transactions causing all the
+ * buffers in the cache being held in queues of this file system.
+ */
+ if ((fs->release_count +
+ fs->release_modified_count) >= fs->max_held_buffers)
+ {
+ rtems_rfs_buffer* buffer;
+ bool modified;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_RELEASE))
+ printf ("rtems-rfs: buffer-release: local cache overflow:"
+ " %" PRIu32 "\n", fs->release_count + fs->release_modified_count);
+
+ if (fs->release_count > fs->release_modified_count)
+ {
+ buffer = (rtems_rfs_buffer*) rtems_chain_get (&fs->release);
+ fs->release_count--;
+ modified = false;
+ }
+ else
+ {
+ buffer =
+ (rtems_rfs_buffer*) rtems_chain_get (&fs->release_modified);
+ fs->release_modified_count--;
+ modified = true;
+ }
+ buffer->user = (void*) 0;
+ rc = rtems_rfs_buffer_io_release (buffer, modified);
+ }
+
+ if (rtems_rfs_buffer_dirty (handle))
+ {
+ rtems_chain_append (&fs->release_modified,
+ rtems_rfs_buffer_link (handle));
+ fs->release_modified_count++;
+ }
+ else
+ {
+ rtems_chain_append (&fs->release, rtems_rfs_buffer_link (handle));
+ fs->release_count++;
+ }
+ }
+ }
+ handle->buffer = NULL;
+ }
+
+ return rc;
+}
+
+int
+rtems_rfs_buffer_open (const char* name, rtems_rfs_file_system* fs)
+{
+ struct stat st;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
+ printf ("rtems-rfs: buffer-open: opening: %s\n", name);
+
+ if (stat (name, &st) < 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
+ printf ("rtems-rfs: buffer-open: stat '%s' failed: %s\n",
+ name, strerror (errno));
+ return ENOENT;
+ }
+
+#if RTEMS_RFS_USE_LIBBLOCK
+ /*
+ * Is the device a block device ?
+ */
+ if (!S_ISBLK (st.st_mode))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
+ printf ("rtems-rfs: buffer-open: '%s' is not a block device\n", name);
+ return EIO;
+ }
+
+ /*
+ * Check that device is registred as a block device and lock it.
+ */
+ fs->disk = rtems_disk_obtain (st.st_rdev);
+ if (!fs->disk)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
+ printf ("rtems-rfs: buffer-open: cannot obtain the disk\n");
+ return EIO;
+ }
+#else
+ fs->device = open (name, O_RDWR);
+ if (fs->device < 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
+ printf ("rtems-rfs: buffer-open: cannot open file\n");
+ }
+ fs->media_size = st.st_size;
+ strcat (fs->name, name);
+#endif
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
+ printf ("rtems-rfs: buffer-open: blks=%" PRId32 ", blk-size=%" PRId32 "\n",
+ rtems_rfs_fs_media_blocks (fs),
+ rtems_rfs_fs_media_block_size (fs));
+
+ return 0;
+}
+
+int
+rtems_rfs_buffer_close (rtems_rfs_file_system* fs)
+{
+ int rc = 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CLOSE))
+ printf ("rtems-rfs: buffer-close: closing\n");
+
+ /*
+ * Change the block size to the media device size. It will release and sync
+ * all buffers.
+ */
+ rc = rtems_rfs_buffer_setblksize (fs, rtems_rfs_fs_media_block_size (fs));
+
+ if ((rc > 0) && rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CLOSE))
+ printf ("rtems-rfs: buffer-close: set media block size failed: %d: %s\n",
+ rc, strerror (rc));
+
+#if RTEMS_RFS_USE_LIBBLOCK
+ rtems_disk_release (fs->disk);
+#else
+ if (close (fs->device) < 0)
+ {
+ rc = errno;
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CLOSE))
+ printf ("rtems-rfs: buffer-close: file close failed: %d: %s\n",
+ rc, strerror (rc));
+ }
+#endif
+
+ return rc;
+}
+
+int
+rtems_rfs_buffer_sync (rtems_rfs_file_system* fs)
+{
+ int result = 0;
+#if RTEMS_RFS_USE_LIBBLOCK
+ rtems_status_code sc;
+#endif
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
+ printf ("rtems-rfs: buffer-sync: syncing\n");
+
+ /*
+ * @todo Split in the separate files for each type.
+ */
+#if RTEMS_RFS_USE_LIBBLOCK
+ sc = rtems_bdbuf_syncdev (rtems_rfs_fs_device (fs));
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
+ printf ("rtems-rfs: buffer-sync: device sync failed: %s\n",
+ rtems_status_text (sc));
+ result = EIO;
+ }
+ rtems_disk_release (fs->disk);
+#else
+ if (fsync (fs->device) < 0)
+ {
+ result = errno;
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CLOSE))
+ printf ("rtems-rfs: buffer-sync: file sync failed: %d: %s\n",
+ result, strerror (result));
+ }
+#endif
+ return result;
+}
+
+int
+rtems_rfs_buffer_setblksize (rtems_rfs_file_system* fs, size_t size)
+{
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SETBLKSIZE))
+ printf ("rtems-rfs: buffer-setblksize: block size: %zu\n", size);
+
+ rc = rtems_rfs_buffers_release (fs);
+ if ((rc > 0) && rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SETBLKSIZE))
+ printf ("rtems-rfs: buffer-setblksize: buffer release failed: %d: %s\n",
+ rc, strerror (rc));
+
+ rc = rtems_rfs_buffer_sync (fs);
+ if ((rc > 0) && rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SETBLKSIZE))
+ printf ("rtems-rfs: buffer-setblksize: device sync failed: %d: %s\n",
+ rc, strerror (rc));
+
+#if RTEMS_RFS_USE_LIBBLOCK
+ rc = fs->disk->ioctl (fs->disk, RTEMS_BLKIO_SETBLKSIZE, &size);
+ if (rc < 0)
+ rc = errno;
+#endif
+ return rc;
+}
+
+static int
+rtems_rfs_release_chain (rtems_chain_control* chain,
+ uint32_t* count,
+ bool modified)
+{
+ rtems_rfs_buffer* buffer;
+ int rrc = 0;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
+ printf ("rtems-rfs: release-chain: count=%" PRIu32 "\n", *count);
+
+ while (!rtems_chain_is_empty (chain))
+ {
+ buffer = (rtems_rfs_buffer*) rtems_chain_get (chain);
+ (*count)--;
+
+ buffer->user = (void*) 0;
+
+ rc = rtems_rfs_buffer_io_release (buffer, modified);
+ if ((rc > 0) && (rrc == 0))
+ rrc = rc;
+ }
+ return rrc;
+}
+
+int
+rtems_rfs_buffers_release (rtems_rfs_file_system* fs)
+{
+ int rrc = 0;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_RELEASE))
+ printf ("rtems-rfs: buffers-release: active:%" PRIu32 " "
+ "release:%" PRIu32 " release-modified:%" PRIu32 "\n",
+ fs->buffers_count, fs->release_count, fs->release_modified_count);
+
+ rc = rtems_rfs_release_chain (&fs->release,
+ &fs->release_count,
+ false);
+ if ((rc > 0) && (rrc == 0))
+ rrc = rc;
+ rc = rtems_rfs_release_chain (&fs->release_modified,
+ &fs->release_modified_count,
+ true);
+ if ((rc > 0) && (rrc == 0))
+ rrc = rc;
+
+ return rrc;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer.h b/cpukit/libfs/src/rfs/rtems-rfs-buffer.h
new file mode 100644
index 0000000000..e207f5c7d3
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-buffer.h
@@ -0,0 +1,265 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Buffer Management.
+ *
+ * These functions map blocks to the media interface layers.
+ */
+
+#if !defined (_RTEMS_RFS_BUFFER_H_)
+#define _RTEMS_RFS_BUFFER_H_
+
+#include <errno.h>
+
+#include <rtems/rfs/rtems-rfs-file-system-fwd.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+/**
+ * Define the method used to interface to the buffers. It can be libblock or
+ * device I/O. The libblock interface is to the RTEMS cache and block devices
+ * and device I/O accesses the media via a device file handle.
+ */
+#if defined (__rtems__)
+#define RTEMS_RFS_USE_LIBBLOCK 1
+#endif
+
+/**
+ * The RTEMS RFS I/O Layering.
+ */
+#if RTEMS_RFS_USE_LIBBLOCK
+#include <rtems/bdbuf.h>
+#include <rtems/error.h>
+
+typedef rtems_blkdev_bnum rtems_rfs_buffer_block;
+typedef rtems_bdbuf_buffer rtems_rfs_buffer;
+#define rtems_rfs_buffer_io_request rtems_rfs_buffer_bdbuf_request
+#define rtems_rfs_buffer_io_release rtems_rfs_buffer_bdbuf_release
+
+/**
+ * Request a buffer from the RTEMS libblock BD buffer cache.
+ */
+int rtems_rfs_buffer_bdbuf_request (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_block block,
+ bool read,
+ rtems_rfs_buffer** buffer);
+/**
+ * Release a buffer to the RTEMS libblock BD buffer cache.
+ */
+int rtems_rfs_buffer_bdbuf_release (rtems_rfs_buffer* handle,
+ bool modified);
+#else /* Device I/O */
+typedef uint32_t rtems_rfs_buffer_block;
+typedef struct _rtems_rfs_buffer
+{
+ rtems_chain_node link;
+ rtems_rfs_buffer_block user;
+ void* buffer;
+ size_t size;
+ uint32_t references;
+} rtems_rfs_buffer;
+#define rtems_rfs_buffer_io_request rtems_rfs_buffer_devceio_request
+#define rtems_rfs_buffer_io_release rtems_rfs_uffer_deviceio_release
+
+/**
+ * Request a buffer from the device I/O.
+ */
+int rtems_rfs_buffer_deviceio_request (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_block block,
+ bool read,
+ rtems_rfs_buffer* buffer);
+/**
+ * Release a buffer to the RTEMS libblock BD buffer cache.
+ */
+int rtems_rfs_buffer_deviceio_release (rtems_rfs_buffer* handle,
+ bool modified);
+#endif
+
+/**
+ * RFS Buffer handle.
+ */
+typedef struct rtems_rfs_buffer_handle_t
+{
+ /**
+ * Has the buffer been modifed?
+ */
+ bool dirty;
+
+ /**
+ * Block number. The lower layer block number may be absolute and we maybe
+ * relative to an offset in the disk so hold locally.
+ */
+ rtems_rfs_buffer_block bnum;
+
+ /**
+ * Reference the buffer descriptor.
+ */
+ rtems_rfs_buffer* buffer;
+
+} rtems_rfs_buffer_handle;
+
+/**
+ * The buffer linkage.
+ */
+#define rtems_rfs_buffer_link(_h) (&(_h)->buffer->link)
+
+/**
+ * Return the start of the data area of the buffer given a handle.
+ */
+#define rtems_rfs_buffer_data(_h) ((void*)((_h)->buffer->buffer))
+
+/**
+ * Return the size of the buffer given a handle.
+ */
+#define rtems_rfs_buffer_size(_h) ((_h)->buffer->size)
+
+/**
+ * Return the block number.
+ */
+#define rtems_rfs_buffer_bnum(_h) ((_h)->bnum)
+
+/**
+ * Return the buffer dirty status.
+ */
+#define rtems_rfs_buffer_dirty(_h) ((_h)->dirty)
+
+/**
+ * Does the handle have a valid block attached ?
+ */
+#define rtems_rfs_buffer_handle_has_block(_h) ((_h)->buffer ? true : false)
+
+/**
+ * Mark the buffer as dirty.
+ */
+#define rtems_rfs_buffer_mark_dirty(_h) ((_h)->dirty = true)
+
+/**
+ * Return the reference count.
+ */
+#define rtems_rfs_buffer_refs(_h) ((_h)->buffer->references)
+
+/**
+ * Increment the reference count.
+ */
+#define rtems_rfs_buffer_refs_up(_h) ((_h)->buffer->references += 1)
+
+/**
+ * Decrement the reference count.
+ */
+#define rtems_rfs_buffer_refs_down(_h) ((_h)->buffer->references -= 1)
+
+/**
+ * Request a buffer. The buffer can be filled with data from the media (read ==
+ * true) or you can request a buffer to fill with data.
+ *
+ * @param fs The file system data.
+ * @param handle The handle the requested buffer is attached to.
+ * @param block The block number.
+ * @param read Read the data from the disk.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffer_handle_request (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* handle,
+ rtems_rfs_buffer_block block,
+ bool read);
+
+/**
+ * Release a buffer. If the buffer is dirty the buffer is written to disk. The
+ * result does not indicate if the data was successfully written to the disk as
+ * this operation may be performed in asynchronously to this release.
+ *
+ * @param fs The file system data.
+ * @param handle The handle the requested buffer is attached to.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffer_handle_release (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* handle);
+
+/**
+ * Open a handle.
+ *
+ * @param fs The file system data.
+ * @param handle The buffer handle to open.
+ * @return int The error number (errno). No error if 0.
+ */
+static inline int
+rtems_rfs_buffer_handle_open (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* handle)
+{
+ handle->dirty = false;
+ handle->bnum = 0;
+ handle->buffer = NULL;
+ return 0;
+}
+
+/**
+ * Close a handle.
+ *
+ * @param fs The file system data.
+ * @param handle The buffer handle to close.
+ * @return int The error number (errno). No error if 0.
+ */
+static inline int
+rtems_rfs_buffer_handle_close (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_handle* handle)
+{
+ rtems_rfs_buffer_handle_release (fs, handle);
+ handle->dirty = false;
+ handle->bnum = 0;
+ handle->buffer = NULL;
+ return 0;
+}
+
+/**
+ * Open the buffer interface.
+ *
+ * @param name The device name to the media.
+ * @param fs Pointer to the file system data.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffer_open (const char* name, rtems_rfs_file_system* fs);
+
+/**
+ * Close the buffer interface.
+ *
+ * @param fs Pointer to the file system data.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffer_close (rtems_rfs_file_system* fs);
+
+/**
+ * Sync all buffers to the media.
+ *
+ * @param fs Pointer to the file system data.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffer_sync (rtems_rfs_file_system* fs);
+
+/**
+ * Set the block size of the device.
+ *
+ * @param fs Pointer to the file system data.
+ * @param size The new block size.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffer_setblksize (rtems_rfs_file_system* fs, size_t size);
+
+/**
+ * Release any chained buffers.
+ *
+ * @param fs The file system data.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_buffers_release (rtems_rfs_file_system* fs);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-data.h b/cpukit/libfs/src/rfs/rtems-rfs-data.h
new file mode 100644
index 0000000000..343c0a9854
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-data.h
@@ -0,0 +1,87 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Data.
+ *
+ * Access data in the correct byte order for the specific target we are running
+ * on.
+ *
+ * @todo Make direct access on matching byte ordered targets.
+ */
+
+#if !defined (_RTEMS_RFS_DATA_H_)
+#define _RTEMS_RFS_DATA_H_
+
+#include <stdint.h>
+
+/**
+ * Helper function to make sure we have a byte pointer.
+ */
+#define rtems_rfs_data_ptr(_d) ((uint8_t*)(_d))
+
+/**
+ * Helper function to get the data shifted in the correctly sized type.
+ */
+#define rtems_rfs_data_get(_d, _t, _o, _s) \
+ (((_t)(rtems_rfs_data_ptr (_d)[_o])) << (_s))
+
+/**
+ * RFS Read Unsigned 8bit Integer
+ */
+#define rtems_rfs_read_u8(_d) \
+ (*rtems_rfs_data_ptr (_d))
+
+/**
+ * RFS Read Unsigned 16bit Integer
+ */
+#define rtems_rfs_read_u16(_d) \
+ (rtems_rfs_data_get (_d, uint16_t, 0, 8) | \
+ rtems_rfs_data_get (_d, uint16_t, 1, 0))
+
+/**
+ * RFS Read Unsigned 32bit Integer
+ */
+#define rtems_rfs_read_u32(_d) \
+ (rtems_rfs_data_get (_d, uint32_t, 0, 24) | \
+ rtems_rfs_data_get (_d, uint32_t, 1, 16) | \
+ rtems_rfs_data_get (_d, uint32_t, 2, 8) | \
+ rtems_rfs_data_get (_d, uint32_t, 3, 0))
+
+/**
+ * RFS Write Unsigned 8bit Integer
+ */
+#define rtems_rfs_write_u8(_d, _v) \
+ (*rtems_rfs_data_ptr (_d) = (uint8_t)(_v))
+
+/**
+ * RFS Write Unsigned 16bit Integer
+ */
+#define rtems_rfs_write_u16(_d, _v) \
+ do { \
+ rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint16_t)(_v)) >> 8); \
+ rtems_rfs_data_ptr (_d)[1] = (uint8_t)((_v)); \
+ } while (0)
+
+/**
+ * RFS Write Unsigned 32bit Integer
+ */
+#define rtems_rfs_write_u32(_d, _v) \
+ do { \
+ rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint32_t)(_v)) >> 24); \
+ rtems_rfs_data_ptr (_d)[1] = (uint8_t)(((uint32_t)(_v)) >> 16); \
+ rtems_rfs_data_ptr (_d)[2] = (uint8_t)(((uint32_t)(_v)) >> 8); \
+ rtems_rfs_data_ptr (_d)[3] = (uint8_t)((uint32_t)(_v)); \
+ } while (0)
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-dir-hash.c b/cpukit/libfs/src/rfs/rtems-rfs-dir-hash.c
new file mode 100644
index 0000000000..0aaf405213
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-dir-hash.c
@@ -0,0 +1,341 @@
+/*
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Directory Hash function.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/rfs/rtems-rfs-dir-hash.h>
+
+#ifdef __rtems__
+# include <machine/endian.h> /* attempt to define endianness */
+#endif
+#ifdef linux
+# include <endian.h> /* attempt to define endianness */
+#endif
+
+/*
+ * My best guess at if you are big-endian or little-endian. This may
+ * need adjustment.
+ */
+#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
+ __BYTE_ORDER == __LITTLE_ENDIAN) || \
+ (defined(i386) || defined(__i386__) || defined(__i486__) || \
+ defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL))
+# define HASH_LITTLE_ENDIAN 1
+# define HASH_BIG_ENDIAN 0
+#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
+ __BYTE_ORDER == __BIG_ENDIAN) || \
+ (defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel))
+# define HASH_LITTLE_ENDIAN 0
+# define HASH_BIG_ENDIAN 1
+#else
+# define HASH_LITTLE_ENDIAN 0
+# define HASH_BIG_ENDIAN 0
+#endif
+
+#define hashsize(n) ((uint32_t)1<<(n))
+#define hashmask(n) (hashsize(n)-1)
+#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
+
+/*
+ -------------------------------------------------------------------------------
+ mix -- mix 3 32-bit values reversibly.
+
+ This is reversible, so any information in (a,b,c) before mix() is still in
+ (a,b,c) after mix().
+
+ If four pairs of (a,b,c) inputs are run through mix(), or through mix() in
+ reverse, there are at least 32 bits of the output that are sometimes the same
+ for one pair and different for another pair. This was tested for:
+
+ * pairs that differed by one bit, by two bits, in any combination of top bits
+ of (a,b,c), or in any combination of bottom bits of (a,b,c).
+
+ * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed the
+ output delta to a Gray code (a^(a>>1)) so a string of 1's (as is commonly
+ produced by subtraction) look like a single 1-bit difference.
+
+ * the base values were pseudorandom, all zero but one bit set, or all zero
+ plus a counter that starts at zero.
+
+ Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that satisfy this
+ are:
+
+ 4 6 8 16 19 4
+ 9 15 3 18 27 15
+ 14 9 3 7 17 3
+
+ Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing for "differ" defined
+ as + with a one-bit base and a two-bit delta. I used
+ http://burtleburtle.net/bob/hash/avalanche.html to choose the operations,
+ constants, and arrangements of the variables.
+
+ This does not achieve avalanche. There are input bits of (a,b,c) that fail
+ to affect some output bits of (a,b,c), especially of a. The most thoroughly
+ mixed value is c, but it doesn't really even achieve avalanche in c.
+
+ This allows some parallelism. Read-after-writes are good at doubling the
+ number of bits affected, so the goal of mixing pulls in the opposite
+ direction as the goal of parallelism. I did what I could. Rotates seem to
+ cost as much as shifts on every machine I could lay my hands on, and rotates
+ are much kinder to the top and bottom bits, so I used rotates.
+ -------------------------------------------------------------------------------
+*/
+#define mix(a,b,c) \
+ { \
+ a -= c; a ^= rot(c, 4); c += b; \
+ b -= a; b ^= rot(a, 6); a += c; \
+ c -= b; c ^= rot(b, 8); b += a; \
+ a -= c; a ^= rot(c,16); c += b; \
+ b -= a; b ^= rot(a,19); a += c; \
+ c -= b; c ^= rot(b, 4); b += a; \
+ }
+
+/*
+ -------------------------------------------------------------------------------
+ final -- final mixing of 3 32-bit values (a,b,c) into c
+
+ Pairs of (a,b,c) values differing in only a few bits will usually produce
+ values of c that look totally different. This was tested for
+
+ * pairs that differed by one bit, by two bits, in any combination of top bits
+ of (a,b,c), or in any combination of bottom bits of (a,b,c).
+
+ * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed the
+ output delta to a Gray code (a^(a>>1)) so a string of 1's (as is commonly
+ produced by subtraction) look like a single 1-bit difference. * the base
+ values were pseudorandom, all zero but one bit set, or all zero plus a
+ counter that starts at zero.
+
+ These constants passed:
+ 14 11 25 16 4 14 24
+ 12 14 25 16 4 14 24
+ and these came close:
+ 4 8 15 26 3 22 24
+ 10 8 15 26 3 22 24
+ 11 8 15 26 3 22 24
+ -------------------------------------------------------------------------------
+*/
+#define final(a,b,c) \
+ { \
+ c ^= b; c -= rot(b,14); \
+ a ^= c; a -= rot(c,11); \
+ b ^= a; b -= rot(a,25); \
+ c ^= b; c -= rot(b,16); \
+ a ^= c; a -= rot(c,4); \
+ b ^= a; b -= rot(a,14); \
+ c ^= b; c -= rot(b,24); \
+ }
+
+/**
+ * The follow is the documentation from Bob Jenkin's hash function:
+ *
+ * http://burtleburtle.net/bob/hash/doobs.html
+ *
+ * The function hashlittle() has been renamed.
+ *
+ * hashlittle() -- hash a variable-length key into a 32-bit value
+ *
+ * k : the key (the unaligned variable-length array of bytes)
+ * length : the length of the key, counting by bytes
+ * initval : can be any 4-byte value
+ *
+ * Returns a 32-bit value. Every bit of the key affects every bit of the
+ * return value. Two keys differing by one or two bits will have totally
+ * different hash values.
+ *
+ * The best hash table sizes are powers of 2. There is no need to do mod a
+ * prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask.
+ * For example, if you need only 10 bits, do h = (h & hashmask(10)); In which
+ * case, the hash table should have hashsize(10) elements.
+ *
+ * If you are hashing n strings (uint8_t **)k, do it like this: for (i=0, h=0;
+ * i<n; ++i) h = hashlittle( k[i], len[i], h);
+ *
+ * By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this
+ * code any way you wish, private, educational, or commercial. It's free.
+ *
+ * Use for hash table lookup, or anything where one collision in 2^^32 is
+ * acceptable. Do NOT use for cryptographic purposes.
+*/
+
+#define initval (20010928)
+uint32_t
+rtems_rfs_dir_hash (const void *key, size_t length)
+{
+ uint32_t a,b,c; /* internal state */
+ union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
+
+ /* Set up the internal state */
+ a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
+
+ u.ptr = key;
+ if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) {
+ const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */
+ /*const uint8_t *k8;*/
+
+ /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */
+ while (length > 12)
+ {
+ a += k[0];
+ b += k[1];
+ c += k[2];
+ mix(a,b,c);
+ length -= 12;
+ k += 3;
+ }
+
+ /*----------------------------- handle the last (probably partial) block */
+ /*
+ * "k[2]&0xffffff" actually reads beyond the end of the string, but
+ * then masks off the part it's not allowed to read. Because the
+ * string is aligned, the masked-off tail is in the same word as the
+ * rest of the string. Every machine with memory protection I've seen
+ * does it on word boundaries, so is OK with this. But VALGRIND will
+ * still catch it and complain. The masking trick does make the hash
+ * noticably faster for short strings (like English words).
+ */
+#ifndef VALGRIND
+
+ switch(length)
+ {
+ case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
+ case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
+ case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
+ case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
+ case 8 : b+=k[1]; a+=k[0]; break;
+ case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
+ case 6 : b+=k[1]&0xffff; a+=k[0]; break;
+ case 5 : b+=k[1]&0xff; a+=k[0]; break;
+ case 4 : a+=k[0]; break;
+ case 3 : a+=k[0]&0xffffff; break;
+ case 2 : a+=k[0]&0xffff; break;
+ case 1 : a+=k[0]&0xff; break;
+ case 0 : return c; /* zero length strings require no mixing */
+ }
+
+#else /* make valgrind happy */
+
+ k8 = (const uint8_t *)k;
+ switch(length)
+ {
+ case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
+ case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
+ case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
+ case 9 : c+=k8[8]; /* fall through */
+ case 8 : b+=k[1]; a+=k[0]; break;
+ case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
+ case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
+ case 5 : b+=k8[4]; /* fall through */
+ case 4 : a+=k[0]; break;
+ case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
+ case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
+ case 1 : a+=k8[0]; break;
+ case 0 : return c;
+ }
+
+#endif /* !valgrind */
+
+ } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
+ const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
+ const uint8_t *k8;
+
+ /*--------------- all but last block: aligned reads and different mixing */
+ while (length > 12)
+ {
+ a += k[0] + (((uint32_t)k[1])<<16);
+ b += k[2] + (((uint32_t)k[3])<<16);
+ c += k[4] + (((uint32_t)k[5])<<16);
+ mix(a,b,c);
+ length -= 12;
+ k += 6;
+ }
+
+ /*----------------------------- handle the last (probably partial) block */
+ k8 = (const uint8_t *)k;
+ switch(length)
+ {
+ case 12: c+=k[4]+(((uint32_t)k[5])<<16);
+ b+=k[2]+(((uint32_t)k[3])<<16);
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
+ case 10: c+=k[4];
+ b+=k[2]+(((uint32_t)k[3])<<16);
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 9 : c+=k8[8]; /* fall through */
+ case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
+ case 6 : b+=k[2];
+ a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 5 : b+=k8[4]; /* fall through */
+ case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
+ break;
+ case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
+ case 2 : a+=k[0];
+ break;
+ case 1 : a+=k8[0];
+ break;
+ case 0 : return c; /* zero length requires no mixing */
+ }
+
+ } else { /* need to read the key one byte at a time */
+ const uint8_t *k = (const uint8_t *)key;
+
+ /*--------------- all but the last block: affect some 32 bits of (a,b,c) */
+ while (length > 12)
+ {
+ a += k[0];
+ a += ((uint32_t)k[1])<<8;
+ a += ((uint32_t)k[2])<<16;
+ a += ((uint32_t)k[3])<<24;
+ b += k[4];
+ b += ((uint32_t)k[5])<<8;
+ b += ((uint32_t)k[6])<<16;
+ b += ((uint32_t)k[7])<<24;
+ c += k[8];
+ c += ((uint32_t)k[9])<<8;
+ c += ((uint32_t)k[10])<<16;
+ c += ((uint32_t)k[11])<<24;
+ mix(a,b,c);
+ length -= 12;
+ k += 12;
+ }
+
+ /*-------------------------------- last block: affect all 32 bits of (c) */
+ switch(length) /* all the case statements fall through */
+ {
+ case 12: c+=((uint32_t)k[11])<<24;
+ case 11: c+=((uint32_t)k[10])<<16;
+ case 10: c+=((uint32_t)k[9])<<8;
+ case 9 : c+=k[8];
+ case 8 : b+=((uint32_t)k[7])<<24;
+ case 7 : b+=((uint32_t)k[6])<<16;
+ case 6 : b+=((uint32_t)k[5])<<8;
+ case 5 : b+=k[4];
+ case 4 : a+=((uint32_t)k[3])<<24;
+ case 3 : a+=((uint32_t)k[2])<<16;
+ case 2 : a+=((uint32_t)k[1])<<8;
+ case 1 : a+=k[0];
+ break;
+ case 0 : return c;
+ }
+ }
+
+ final(a,b,c);
+ return c;
+}
+
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-dir-hash.h b/cpukit/libfs/src/rfs/rtems-rfs-dir-hash.h
new file mode 100644
index 0000000000..ca761dd0cc
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-dir-hash.h
@@ -0,0 +1,34 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Directory Hash provides a 32bit hash of a string. This is
+ * used to search a directory.
+ */
+
+#if !defined (_RTEMS_RFS_DIR_HASH_H_)
+#define _RTEMS_RFS_DIR_HAS_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+/**
+ * Compute a hash of the key over the length of string.
+ *
+ * @param key The key to calculate the hash of.
+ * @param length The length of the key in bytes.
+ * @return uint32_t The hash.
+ */
+uint32_t rtems_rfs_dir_hash (const void *key, size_t length);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-dir.c b/cpukit/libfs/src/rfs/rtems-rfs-dir.c
new file mode 100644
index 0000000000..1f2e5fd518
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-dir.c
@@ -0,0 +1,760 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Directory Routines.
+ *
+ * These functions manage blocks in the directory format. A directory entry is
+ * a variable length record in the block. The entry consists of a length, hash
+ * and the string. The length allows the next entry to be located and the hash
+ * allows a simple check to be performed wihtout a string compare. Directory
+ * entries do not span a block and removal of an entry results in the space in
+ * the block being compacted and the spare area being initialised to ones.
+ *
+ * The maximum length can be 1 or 2 bytes depending on the value in the
+ * superblock.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#if SIZEOF_OFF_T == 8
+#define PRIdoff_t PRIo64
+#elif SIZEOF_OFF_T == 4
+#define PRIdoff_t PRIo32
+#else
+#error "unsupported size of off_t"
+#endif
+
+#include <rtems/rfs/rtems-rfs-block.h>
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+#include <rtems/rfs/rtems-rfs-dir.h>
+#include <rtems/rfs/rtems-rfs-dir-hash.h>
+
+/**
+ * Validate the directory entry data.
+ */
+#define rtems_rfs_dir_entry_valid(_f, _l, _i) \
+ (((_l) <= RTEMS_RFS_DIR_ENTRY_SIZE) || ((_l) >= rtems_rfs_fs_max_name (_f)) \
+ || (_i < RTEMS_RFS_ROOT_INO) || (_i > rtems_rfs_fs_inodes (_f)))
+
+int
+rtems_rfs_dir_lookup_ino (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* inode,
+ const char* name,
+ int length,
+ rtems_rfs_ino* ino,
+ uint32_t* offset)
+{
+ rtems_rfs_block_map map;
+ rtems_rfs_buffer_handle entries;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ {
+ int c;
+ printf ("rtems-rfs: dir-lookup-ino: lookup ino: root=%" PRId32 ", path=",
+ inode->ino);
+ for (c = 0; c < length; c++)
+ printf ("%c", name[c]);
+ printf (", len=%d\n", length);
+ }
+
+ *ino = RTEMS_RFS_EMPTY_INO;
+ *offset = 0;
+
+ rc = rtems_rfs_block_map_open (fs, inode, &map);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: map open failed for ino %" PRIu32 ": %d: %s",
+ rtems_rfs_inode_ino (inode), rc, strerror (rc));
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &entries);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: handle open failed for ino %" PRIu32 ": %d: %s",
+ rtems_rfs_inode_ino (inode), rc, strerror (rc));
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+ else
+ {
+ rtems_rfs_block_no block;
+ uint32_t hash;
+
+ /*
+ * Calculate the hash of the look up string.
+ */
+ hash = rtems_rfs_dir_hash (name, length);
+
+ /*
+ * Locate the first block. The map points to the start after open so just
+ * seek 0. If an error the block will be 0.
+ */
+ rc = rtems_rfs_block_map_seek (fs, &map, 0, &block);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: block map find failed: %d: %s\n",
+ rc, strerror (rc));
+ if (rc == ENXIO)
+ rc = ENOENT;
+ rtems_rfs_buffer_handle_close (fs, &entries);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ while ((rc == 0) && block)
+ {
+ uint8_t* entry;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: block read, ino=%" PRIu32 " bno=%" PRId32 "\n",
+ rtems_rfs_inode_ino (inode), map.bpos.bno);
+
+ rc = rtems_rfs_buffer_handle_request (fs, &entries, block, true);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: block read, ino=%" PRIu32 " block=%" PRId32 ": %d: %s\n",
+ rtems_rfs_inode_ino (inode), block, rc, strerror (rc));
+ break;
+ }
+
+ /*
+ * Search the block to see if the name matches. A hash of 0xffff or 0x0
+ * means the entry is empty.
+ */
+
+ entry = rtems_rfs_buffer_data (&entries);
+
+ map.bpos.boff = 0;
+
+ while (map.bpos.boff < (rtems_rfs_fs_block_size (fs) - RTEMS_RFS_DIR_ENTRY_SIZE))
+ {
+ uint32_t ehash;
+ int elength;
+
+ ehash = rtems_rfs_dir_entry_hash (entry);
+ elength = rtems_rfs_dir_entry_length (entry);
+ *ino = rtems_rfs_dir_entry_ino (entry);
+
+ if (elength == RTEMS_RFS_DIR_ENTRY_EMPTY)
+ break;
+
+ if (rtems_rfs_dir_entry_valid (fs, elength, *ino))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: "
+ "bad length or ino for ino %" PRIu32 ": %u/%" PRId32 " @ %04" PRIx32 "\n",
+ rtems_rfs_inode_ino (inode), elength, *ino, map.bpos.boff);
+ rc = EIO;
+ break;
+ }
+
+ if (ehash == hash)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO_CHECK))
+ printf ("rtems-rfs: dir-lookup-ino: "
+ "checking entry for ino %" PRId32 ": bno=%04" PRIx32 "/off=%04" PRIx32
+ " length:%d ino:%" PRId32 "\n",
+ rtems_rfs_inode_ino (inode), map.bpos.bno, map.bpos.boff,
+ elength, rtems_rfs_dir_entry_ino (entry));
+
+ if (memcmp (entry + RTEMS_RFS_DIR_ENTRY_SIZE, name, length) == 0)
+ {
+ *offset = rtems_rfs_block_map_pos (fs, &map);
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO_FOUND))
+ printf ("rtems-rfs: dir-lookup-ino: "
+ "entry found in ino %" PRIu32 ", ino=%" PRIu32 " offset=%" PRIu32 "\n",
+ rtems_rfs_inode_ino (inode), *ino, *offset);
+
+ rtems_rfs_buffer_handle_close (fs, &entries);
+ rtems_rfs_block_map_close (fs, &map);
+ return 0;
+ }
+ }
+
+ map.bpos.boff += elength;
+ entry += elength;
+ }
+
+ if (rc == 0)
+ {
+ rc = rtems_rfs_block_map_next_block (fs, &map, &block);
+ if ((rc > 0) && (rc != ENXIO))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: "
+ "block map next block failed in ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (inode), rc, strerror (rc));
+ }
+ if (rc == ENXIO)
+ rc = ENOENT;
+ }
+ }
+
+ if ((rc == 0) && (block == 0))
+ {
+ rc = EIO;
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO))
+ printf ("rtems-rfs: dir-lookup-ino: block is 0 in ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (inode), rc, strerror (rc));
+ }
+ }
+
+ rtems_rfs_buffer_handle_close (fs, &entries);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+}
+
+int
+rtems_rfs_dir_add_entry (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir,
+ const char* name,
+ size_t length,
+ rtems_rfs_ino ino)
+{
+ rtems_rfs_block_map map;
+ rtems_rfs_block_pos bpos;
+ rtems_rfs_buffer_handle buffer;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_ADD_ENTRY))
+ {
+ int c;
+ printf ("rtems-rfs: dir-add-entry: dir=%" PRId32 ", name=",
+ rtems_rfs_inode_ino (dir));
+ for (c = 0; c < length; c++)
+ printf ("%c", name[c]);
+ printf (", len=%zd\n", length);
+ }
+
+ rc = rtems_rfs_block_map_open (fs, dir, &map);
+ if (rc > 0)
+ return rc;
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ /*
+ * Search the map from the beginning to find any empty space.
+ */
+ rtems_rfs_block_set_bpos_zero (&bpos);
+
+ while (true)
+ {
+ rtems_rfs_block_no block;
+ uint8_t* entry;
+ int offset;
+ bool read = true;
+
+ /*
+ * Locate the first block. If an error the block will be 0. If the map is
+ * empty which happens when creating a directory and adding the first entry
+ * the seek will return ENXIO. In this case we need to grow the directory.
+ */
+ rc = rtems_rfs_block_map_find (fs, &map, &bpos, &block);
+ if (rc > 0)
+ {
+ if (rc != ENXIO)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_ADD_ENTRY))
+ printf ("rtems-rfs: dir-add-entry: "
+ "block map find failed for ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (dir), rc, strerror (rc));
+ break;
+ }
+
+ /*
+ * We have reached the end of the directory so add a block.
+ */
+ rc = rtems_rfs_block_map_grow (fs, &map, 1, &block);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_ADD_ENTRY))
+ printf ("rtems-rfs: dir-add-entry: "
+ "block map grow failed for ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (dir), rc, strerror (rc));
+ break;
+ }
+
+ read = false;
+ }
+
+ bpos.bno++;
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, read);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_ADD_ENTRY))
+ printf ("rtems-rfs: dir-add-entry: "
+ "block buffer req failed for ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (dir), rc, strerror (rc));
+ break;
+ }
+
+ entry = rtems_rfs_buffer_data (&buffer);
+
+ if (!read)
+ memset (entry, 0xff, rtems_rfs_fs_block_size (fs));
+
+ offset = 0;
+
+ while (offset < (rtems_rfs_fs_block_size (fs) - RTEMS_RFS_DIR_ENTRY_SIZE))
+ {
+ rtems_rfs_ino eino;
+ int elength;
+
+ elength = rtems_rfs_dir_entry_length (entry);
+ eino = rtems_rfs_dir_entry_ino (entry);
+
+ if (elength == RTEMS_RFS_DIR_ENTRY_EMPTY)
+ {
+ if ((length + RTEMS_RFS_DIR_ENTRY_SIZE) <
+ (rtems_rfs_fs_block_size (fs) - offset))
+ {
+ uint32_t hash;
+ hash = rtems_rfs_dir_hash (name, length);
+ rtems_rfs_dir_set_entry_hash (entry, hash);
+ rtems_rfs_dir_set_entry_ino (entry, ino);
+ rtems_rfs_dir_set_entry_length (entry,
+ RTEMS_RFS_DIR_ENTRY_SIZE + length);
+ memcpy (entry + RTEMS_RFS_DIR_ENTRY_SIZE, name, length);
+ rtems_rfs_buffer_mark_dirty (&buffer);
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return 0;
+ }
+
+ break;
+ }
+
+ if (rtems_rfs_dir_entry_valid (fs, elength, eino))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_ADD_ENTRY))
+ printf ("rtems-rfs: dir-add-entry: "
+ "bad length or ino for ino %" PRIu32 ": %u/%" PRId32 " @ %04x\n",
+ rtems_rfs_inode_ino (dir), elength, eino, offset);
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return EIO;
+ }
+
+ entry += elength;
+ offset += elength;
+ }
+ }
+
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+}
+
+int
+rtems_rfs_dir_del_entry (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir,
+ rtems_rfs_ino ino,
+ uint32_t offset)
+{
+ rtems_rfs_block_map map;
+ rtems_rfs_block_no block;
+ rtems_rfs_buffer_handle buffer;
+ bool search;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_DEL_ENTRY))
+ printf ("rtems-rfs: dir-del-entry: dir=%" PRId32 ", entry=%" PRId32 " offset=%" PRIu32 "\n",
+ rtems_rfs_inode_ino (dir), ino, offset);
+
+ rc = rtems_rfs_block_map_open (fs, dir, &map);
+ if (rc > 0)
+ return rc;
+
+ rc = rtems_rfs_block_map_seek (fs, &map, offset, &block);
+ if (rc > 0)
+ {
+ if (rc == ENXIO)
+ rc = ENOENT;
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ /*
+ * Only search if the offset is 0 else we are at that position.
+ */
+ search = offset ? false : true;
+
+ while (rc == 0)
+ {
+ uint8_t* entry;
+ int eoffset;
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, true);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_DEL_ENTRY))
+ printf ("rtems-rfs: dir-del-entry: "
+ "block buffer req failed for ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (dir), rc, strerror (rc));
+ break;
+ }
+
+ /*
+ * If we are searching start at the beginning of the block. If not searching
+ * skip to the offset in the block.
+ */
+ if (search)
+ eoffset = 0;
+ else
+ eoffset = offset % rtems_rfs_fs_block_size (fs);
+
+ entry = rtems_rfs_buffer_data (&buffer) + eoffset;
+
+ while (eoffset < (rtems_rfs_fs_block_size (fs) - RTEMS_RFS_DIR_ENTRY_SIZE))
+ {
+ rtems_rfs_ino eino;
+ int elength;
+
+ elength = rtems_rfs_dir_entry_length (entry);
+ eino = rtems_rfs_dir_entry_ino (entry);
+
+ if (elength == RTEMS_RFS_DIR_ENTRY_EMPTY)
+ break;
+
+ if (rtems_rfs_dir_entry_valid (fs, elength, eino))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_DEL_ENTRY))
+ printf ("rtems-rfs: dir-del-entry: "
+ "bad length or ino for ino %" PRIu32 ": %u/%" PRId32
+ " @ %" PRIu32 ".%04x\n",
+ rtems_rfs_inode_ino (dir), elength, eino, block, eoffset);
+ rc = EIO;
+ break;
+ }
+
+ if (ino == rtems_rfs_dir_entry_ino (entry))
+ {
+ uint32_t remaining;
+ remaining = rtems_rfs_fs_block_size (fs) - (eoffset + elength);
+ memmove (entry, entry + elength, remaining);
+ memset (entry + remaining, 0xff, elength);
+
+ /*
+ * If the remainder of the block is empty and this is the start of the
+ * block and it is the last block in the map shrink the map.
+ *
+ * @note We could check again to see if the new end block in the map is
+ * also empty. This way we could clean up an empty directory.
+ */
+ elength = rtems_rfs_dir_entry_length (entry);
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_DEL_ENTRY))
+ printf ("rtems-rfs: dir-del-entry: "
+ "last block free for ino %" PRIu32 ": elength=%i block=%" PRIu32
+ " offset=%d last=%s\n",
+ ino, elength, block, eoffset,
+ rtems_rfs_block_map_last (&map) ? "yes" : "no");
+
+ if ((elength == RTEMS_RFS_DIR_ENTRY_EMPTY) &&
+ (eoffset == 0) && rtems_rfs_block_map_last (&map))
+ {
+ rc = rtems_rfs_block_map_shrink (fs, &map, 1);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_DEL_ENTRY))
+ printf ("rtems-rfs: dir-del-entry: "
+ "block map shrink failed for ino %" PRIu32 ": %d: %s\n",
+ rtems_rfs_inode_ino (dir), rc, strerror (rc));
+ }
+ }
+
+ rtems_rfs_buffer_mark_dirty (&buffer);
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return 0;
+ }
+
+ if (!search)
+ {
+ rc = EIO;
+ break;
+ }
+
+ entry += elength;
+ eoffset += elength;
+ }
+
+ if (rc == 0)
+ {
+ rc = rtems_rfs_block_map_next_block (fs, &map, &block);
+ if (rc == ENXIO)
+ rc = ENOENT;
+ }
+ }
+
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+}
+
+int
+rtems_rfs_dir_read (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir,
+ rtems_rfs_pos_rel offset,
+ struct dirent* dirent,
+ size_t* length)
+{
+ rtems_rfs_block_map map;
+ rtems_rfs_buffer_handle buffer;
+ rtems_rfs_block_no block;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_READ))
+ printf ("rtems-rfs: dir-read: dir=%" PRId32 " offset=%" PRId64 "\n",
+ rtems_rfs_inode_ino (dir), offset);
+
+ *length = 0;
+
+ rc = rtems_rfs_block_map_open (fs, dir, &map);
+ if (rc > 0)
+ return rc;
+
+ if (((rtems_rfs_fs_block_size (fs) -
+ (offset % rtems_rfs_fs_block_size (fs))) <= RTEMS_RFS_DIR_ENTRY_SIZE))
+ offset = (((offset / rtems_rfs_fs_block_size (fs)) + 1) *
+ rtems_rfs_fs_block_size (fs));
+
+ rc = rtems_rfs_block_map_seek (fs, &map, offset, &block);
+ if (rc > 0)
+ {
+ if (rc == ENXIO)
+ rc = ENOENT;
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ /*
+ * Look for an empty entry and if this is the last block that is the end of
+ * the directory.
+ */
+ while (rc == 0)
+ {
+ uint8_t* entry;
+ rtems_rfs_ino eino;
+ int elength;
+ int remaining;
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, true);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ entry = rtems_rfs_buffer_data (&buffer);
+ entry += map.bpos.boff;
+
+ elength = rtems_rfs_dir_entry_length (entry);
+ eino = rtems_rfs_dir_entry_ino (entry);
+
+ if (elength != RTEMS_RFS_DIR_ENTRY_EMPTY)
+ {
+ if (rtems_rfs_dir_entry_valid (fs, elength, eino))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_READ))
+ printf ("rtems-rfs: dir-read: "
+ "bad length or ino for ino %" PRIu32 ": %u/%" PRId32 " @ %04" PRIx32 "\n",
+ rtems_rfs_inode_ino (dir), elength, eino, map.bpos.boff);
+ rc = EIO;
+ break;
+ }
+
+ memset (dirent, 0, sizeof (struct dirent));
+ dirent->d_off = offset;
+ dirent->d_reclen = sizeof (struct dirent);
+
+ *length += elength;
+
+ remaining = rtems_rfs_fs_block_size (fs) - (map.bpos.boff + elength);
+
+ if (remaining <= RTEMS_RFS_DIR_ENTRY_SIZE)
+ *length += remaining;
+
+ elength -= RTEMS_RFS_DIR_ENTRY_SIZE;
+ if (elength > NAME_MAX)
+ elength = NAME_MAX;
+
+ memcpy (dirent->d_name, entry + RTEMS_RFS_DIR_ENTRY_SIZE, elength);
+
+ dirent->d_ino = rtems_rfs_dir_entry_ino (entry);
+ dirent->d_namlen = elength;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_READ))
+ printf ("rtems-rfs: dir-read: found off:%" PRIdoff_t " ino:%ld name=%s\n",
+ dirent->d_off, dirent->d_ino, dirent->d_name);
+ break;
+ }
+
+ *length += rtems_rfs_fs_block_size (fs) - map.bpos.boff;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_READ))
+ printf ("rtems-rfs: dir-read: next block: off:%" PRId64 " length:%zd\n",
+ offset, *length);
+
+ rc = rtems_rfs_block_map_next_block (fs, &map, &block);
+ if (rc == ENXIO)
+ rc = ENOENT;
+ }
+
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+}
+
+int
+rtems_rfs_dir_empty (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir)
+{
+ rtems_rfs_block_map map;
+ rtems_rfs_buffer_handle buffer;
+ rtems_rfs_block_no block;
+ bool empty;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_READ))
+ printf ("rtems-rfs: dir-empty: dir=%" PRId32 "\n", rtems_rfs_inode_ino (dir));
+
+ empty = true;
+
+ rc = rtems_rfs_block_map_open (fs, dir, &map);
+ if (rc > 0)
+ return rc;
+
+ rc = rtems_rfs_block_map_seek (fs, &map, 0, &block);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+ }
+
+ /*
+ * Look for an empty entry and if this is the last block that is the end of
+ * the directory.
+ */
+ while (empty)
+ {
+ uint8_t* entry;
+ int offset;
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, true);
+ if (rc > 0)
+ break;
+
+ entry = rtems_rfs_buffer_data (&buffer);
+ offset = 0;
+
+ while (offset < (rtems_rfs_fs_block_size (fs) - RTEMS_RFS_DIR_ENTRY_SIZE))
+ {
+ rtems_rfs_ino eino;
+ int elength;
+
+ elength = rtems_rfs_dir_entry_length (entry);
+ eino = rtems_rfs_dir_entry_ino (entry);
+
+ if (elength == RTEMS_RFS_DIR_ENTRY_EMPTY)
+ break;
+
+ if (rtems_rfs_dir_entry_valid (fs, elength, eino))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_EMPTY))
+ printf ("rtems-rfs: dir-empty: "
+ "bad length or ino for ino %" PRIu32 ": %u/%" PRIu32 " @ %04x\n",
+ rtems_rfs_inode_ino (dir), elength, eino, offset);
+ rc = EIO;
+ break;
+ }
+
+ /*
+ * Ignore the current (.) and parent (..) entries. Anything else means
+ * the directory is not empty.
+ */
+ if (((elength != (RTEMS_RFS_DIR_ENTRY_SIZE + 1)) ||
+ (entry[RTEMS_RFS_DIR_ENTRY_SIZE] != '.')) &&
+ ((elength != (RTEMS_RFS_DIR_ENTRY_SIZE + 2)) ||
+ (entry[RTEMS_RFS_DIR_ENTRY_SIZE] != '.') ||
+ (entry[RTEMS_RFS_DIR_ENTRY_SIZE + 1] != '.')))
+ {
+ empty = false;
+ break;
+ }
+
+ entry += elength;
+ offset += elength;
+ }
+
+ if (empty)
+ {
+ rc = rtems_rfs_block_map_next_block (fs, &map, &block);
+ if (rc > 0)
+ {
+ if (rc == ENXIO)
+ rc = 0;
+ break;
+ }
+ }
+ }
+
+ if ((rc == 0) && !empty)
+ rc = ENOTEMPTY;
+
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_block_map_close (fs, &map);
+ return rc;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-dir.h b/cpukit/libfs/src/rfs/rtems-rfs-dir.h
new file mode 100644
index 0000000000..1f452460db
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-dir.h
@@ -0,0 +1,206 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Directory Support
+ *
+ * This file provides the directory support functions.
+ */
+
+#if !defined (_RTEMS_RFS_DIR_H_)
+#define _RTEMS_RFS_DIR_H_
+
+#include <dirent.h>
+
+#include <rtems/libio_.h>
+
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+
+/**
+ * Test if the path provided is a current directory.
+ *
+ * @param _p Pointer to the path string.
+ * @return bool True if the path is a current directory.
+ */
+#define rtems_rfs_current_dir(_p) \
+ ((_p[0] == '.') && ((_p[1] == '\0') || rtems_filesystem_is_separator (_p[1])))
+
+/**
+ * Test if the path provided is a parent directory.
+ *
+ * @param _p Pointer to the path string.
+ * @return bool True if the path is a parent directory.
+ */
+#define rtems_rfs_parent_dir(_p) \
+ ((_p[0] == '.') && (_p[1] == '.') && \
+ ((_p[2] == '\0') || rtems_filesystem_is_separator (_p[2])))
+
+/**
+ * Define the offsets of the fields of a directory entry.
+ */
+#define RTEMS_RFS_DIR_ENTRY_INO (0) /**< The ino offset in a directory
+ * entry. */
+#define RTEMS_RFS_DIR_ENTRY_HASH (4) /**< The hash offset in a directory
+ * entry. The hash is 32bits. We need at
+ * least 16bits and given the length and
+ * ino field are 4 the extra 2 bytes is
+ * not a big overhead.*/
+#define RTEMS_RFS_DIR_ENTRY_LEN (8) /**< The length offset in a directory
+ * entry. */
+
+/**
+ * The length of the directory entry header.
+ */
+#define RTEMS_RFS_DIR_ENTRY_SIZE (4 + 4 + 2)
+
+/**
+ * The length when the remainder of the directory block is empty.
+ */
+#define RTEMS_RFS_DIR_ENTRY_EMPTY (0xffff)
+
+/**
+ * Return the hash of the entry.
+ *
+ * @param _e Pointer to the directory entry.
+ * @return uint32_t The hash.
+ */
+#define rtems_rfs_dir_entry_hash(_e) \
+ rtems_rfs_read_u32 (_e + RTEMS_RFS_DIR_ENTRY_HASH)
+
+/**
+ * Set the hash of the entry.
+ *
+ * @param _e Pointer to the directory entry.
+ * @param _h The hash.
+ */
+#define rtems_rfs_dir_set_entry_hash(_e, _h) \
+ rtems_rfs_write_u32 (_e + RTEMS_RFS_DIR_ENTRY_HASH, _h)
+
+/**
+ * Return the ino of the entry.
+ *
+ * @param _e Pointer to the directory entry.
+ * @return uint32_t The ino.
+ */
+#define rtems_rfs_dir_entry_ino(_e) \
+ rtems_rfs_read_u32 (_e + RTEMS_RFS_DIR_ENTRY_INO)
+
+/**
+ * Set the ino of the entry.
+ *
+ * @param _e Pointer to the directory entry.
+ * @param _i The ino.
+ */
+#define rtems_rfs_dir_set_entry_ino(_e, _i) \
+ rtems_rfs_write_u32 (_e + RTEMS_RFS_DIR_ENTRY_INO, _i)
+
+/**
+ * Return the length of the entry.
+ *
+ * @param _e Pointer to the directory entry.
+ * @return uint16_t The length.
+ */
+#define rtems_rfs_dir_entry_length(_e) \
+ rtems_rfs_read_u16 (_e + RTEMS_RFS_DIR_ENTRY_LEN)
+
+/**
+ * Set the length of the entry.
+ *
+ * @param _e Pointer to the directory entry.
+ * @param _l The length.
+ */
+#define rtems_rfs_dir_set_entry_length(_e, _l) \
+ rtems_rfs_write_u16 (_e + RTEMS_RFS_DIR_ENTRY_LEN, _l)
+
+/**
+ * Look up a directory entry in the directory pointed to by the inode. The look
+ * up is local to this directory. No need to decend.
+ *
+ * @param fs The file system.
+ * @param inode The inode of the directory to search.
+ * @param name The name to look up. The name may not be nul terminated.
+ * @param length The length of the name.
+ * @param ino The return inode number if there is no error.
+ * @param offset The offset in the directory for the entry.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_dir_lookup_ino (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* inode,
+ const char* name,
+ int length,
+ rtems_rfs_ino* ino,
+ uint32_t* offset);
+
+/**
+ * Add an entry to the directory returing the inode number allocated to the
+ * entry.
+ *
+ * @param fs The file system data.
+ * @param dir Pointer to the directory inode the entry is to be added too.
+ * @param name The name of the entry to be added.
+ * @param length The length of the name excluding a terminating 0.
+ * @param ino The ino of the entry.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_dir_add_entry (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir,
+ const char* name,
+ size_t length,
+ rtems_rfs_ino ino);
+
+/**
+ * Del an entry from the directory using an inode number as a key.
+ *
+ * @param fs The file system data.
+ * @param dir Pointer to the directory inode the entry is to be deleted from.
+ * @param ino The ino of the entry.
+ * @param offset The offset in the directory of the entry to delete. If 0
+ * search from the start for the ino.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_dir_del_entry (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir,
+ rtems_rfs_ino ino,
+ uint32_t offset);
+
+/**
+ * Read the directory entry from offset into the directory entry buffer and
+ * return the length of space this entry uses in the directory table.
+ *
+ * @param fs The file system data.
+ * @param dir The direct inode handler.
+ * @param offset The offset in the directory to read from.
+ * @param dirent Pointer to the dirent structure the entry is written into.
+ * @param length Set the length this entry takes in the directory.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_dir_read (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir,
+ rtems_rfs_pos_rel offset,
+ struct dirent* dirent,
+ size_t* length);
+
+/**
+ * Check if the directory is empty. The current and parent directory entries
+ * are ignored.
+ *
+ * @param fs The file system data
+ * @param dir The directory inode to check.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_dir_empty (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* dir);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file-system-fwd.h b/cpukit/libfs/src/rfs/rtems-rfs-file-system-fwd.h
new file mode 100644
index 0000000000..8c39944486
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-file-system-fwd.h
@@ -0,0 +1,27 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Data forward decl.
+ */
+
+#if !defined (_RTEMS_RFS_FILE_SYSTEM_FWD_H_)
+#define _RTEMS_RFS_FILE_SYSTEM_FWD_H_
+
+/**
+ * Forward reference to the file system data.
+ */
+struct _rtems_rfs_file_system;
+typedef struct _rtems_rfs_file_system rtems_rfs_file_system;
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file-system.c b/cpukit/libfs/src/rfs/rtems-rfs-file-system.c
new file mode 100644
index 0000000000..c972e13247
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-file-system.c
@@ -0,0 +1,320 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Open
+ *
+ * Open the file system by reading the superblock and then the group data.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+uint64_t
+rtems_rfs_fs_size (rtems_rfs_file_system* fs)
+{
+ uint64_t blocks = rtems_rfs_fs_blocks (fs);
+ uint64_t block_size = rtems_rfs_fs_block_size (fs);
+ return blocks * block_size;
+}
+
+uint64_t
+rtems_rfs_fs_media_size (rtems_rfs_file_system* fs)
+{
+ uint64_t media_blocks = (uint64_t) rtems_rfs_fs_media_blocks (fs);
+ uint64_t media_block_size = (uint64_t) rtems_rfs_fs_media_block_size (fs);
+ return media_blocks * media_block_size;
+}
+
+static int
+rtems_rfs_fs_read_superblock (rtems_rfs_file_system* fs)
+{
+ rtems_rfs_buffer_handle handle;
+ uint8_t* sb;
+ int group;
+ int rc;
+
+ rc = rtems_rfs_buffer_handle_open (fs, &handle);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: handle open failed: %d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_request (fs, &handle, 0, true);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: request failed%d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ sb = rtems_rfs_buffer_data (&handle);
+
+#define read_sb(_o) rtems_rfs_read_u32 (sb + (_o))
+
+ if (read_sb (RTEMS_RFS_SB_OFFSET_MAGIC) != RTEMS_RFS_SB_MAGIC)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: invalid superblock, bad magic\n");
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ return EIO;
+ }
+
+ fs->blocks = read_sb (RTEMS_RFS_SB_OFFSET_BLOCKS);
+ fs->block_size = read_sb (RTEMS_RFS_SB_OFFSET_BLOCK_SIZE);
+
+ if (rtems_rfs_fs_size(fs) > rtems_rfs_fs_media_size (fs))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: invalid superblock block/size count\n");
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ return EIO;
+ }
+
+ if ((read_sb (RTEMS_RFS_SB_OFFSET_VERSION) & RTEMS_RFS_VERSION_MASK) !=
+ (RTEMS_RFS_VERSION * RTEMS_RFS_VERSION_MASK))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: incompatible version: %08" PRIx32 " (%08" PRIx32 ")\n",
+ read_sb (RTEMS_RFS_SB_OFFSET_VERSION), RTEMS_RFS_VERSION_MASK);
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ return EIO;
+ }
+
+ if (read_sb (RTEMS_RFS_SB_OFFSET_INODE_SIZE) != RTEMS_RFS_INODE_SIZE)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: inode size mismatch: fs:%" PRId32 " target:%" PRId32 "\n",
+ read_sb (RTEMS_RFS_SB_OFFSET_VERSION), RTEMS_RFS_VERSION_MASK);
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ return EIO;
+ }
+
+ fs->bad_blocks = read_sb (RTEMS_RFS_SB_OFFSET_BAD_BLOCKS);
+ fs->max_name_length = read_sb (RTEMS_RFS_SB_OFFSET_MAX_NAME_LENGTH);
+ fs->group_count = read_sb (RTEMS_RFS_SB_OFFSET_GROUPS);
+ fs->group_blocks = read_sb (RTEMS_RFS_SB_OFFSET_GROUP_BLOCKS);
+ fs->group_inodes = read_sb (RTEMS_RFS_SB_OFFSET_GROUP_INODES);
+
+ fs->blocks_per_block =
+ rtems_rfs_fs_block_size (fs) / sizeof (rtems_rfs_inode_block);
+
+ fs->block_map_singly_blocks =
+ fs->blocks_per_block * RTEMS_RFS_INODE_BLOCKS;
+ fs->block_map_doubly_blocks =
+ fs->blocks_per_block * fs->blocks_per_block * RTEMS_RFS_INODE_BLOCKS;
+
+ fs->inodes = fs->group_count * fs->group_inodes;
+
+ fs->inodes_per_block = fs->block_size / RTEMS_RFS_INODE_SIZE;
+
+ if (fs->group_blocks >
+ rtems_rfs_bitmap_numof_bits (rtems_rfs_fs_block_size (fs)))
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: groups blocks larger than block bits\n");
+ return EIO;
+ }
+
+ rtems_rfs_buffer_handle_close (fs, &handle);
+
+ /*
+ * Change the block size to the value in the superblock.
+ */
+ rc = rtems_rfs_buffer_setblksize (fs, rtems_rfs_fs_block_size (fs));
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: invalid superblock block size%d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ fs->groups = calloc (fs->group_count, sizeof (rtems_rfs_group));
+
+ if (!fs->groups)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: no memory for group table\n");
+ return ENOMEM;
+ }
+
+ /*
+ * Perform each phase of group initialisation at the same time. This way we
+ * know how far the initialisation has gone if an error occurs and we need to
+ * close everything.
+ */
+ for (group = 0; group < fs->group_count; group++)
+ {
+ rc = rtems_rfs_group_open (fs,
+ rtems_rfs_fs_block (fs, group, 0),
+ fs->group_blocks,
+ fs->group_inodes,
+ &fs->groups[group]);
+ if (rc > 0)
+ {
+ int g;
+ for (g = 0; g < group; g++)
+ rtems_rfs_group_close (fs, &fs->groups[g]);
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: read-superblock: no memory for group table%d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
+int
+rtems_rfs_fs_open (const char* name,
+ void* user,
+ uint32_t flags,
+ rtems_rfs_file_system** fs)
+{
+ rtems_rfs_group* group;
+ size_t group_base;
+ rtems_rfs_inode_handle inode;
+ uint16_t mode;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: %s\n", name);
+
+ *fs = malloc (sizeof (rtems_rfs_file_system));
+ if (!*fs)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: no memory for file system data\n");
+ errno = ENOMEM;
+ return -1;
+ }
+
+ memset (*fs, 0, sizeof (rtems_rfs_file_system));
+
+ (*fs)->user = user;
+ rtems_chain_initialize_empty (&(*fs)->buffers);
+ rtems_chain_initialize_empty (&(*fs)->release);
+ rtems_chain_initialize_empty (&(*fs)->release_modified);
+ rtems_chain_initialize_empty (&(*fs)->file_shares);
+
+ (*fs)->max_held_buffers = RTEMS_RFS_FS_MAX_HELD_BUFFERS;
+ (*fs)->buffers_count = 0;
+ (*fs)->release_count = 0;
+ (*fs)->release_modified_count = 0;
+ (*fs)->flags = flags;
+
+ group = &(*fs)->groups[0];
+ group_base = 0;
+
+ /*
+ * Open the buffer interface.
+ */
+ rc = rtems_rfs_buffer_open (name, *fs);
+ if (rc > 0)
+ {
+ free (*fs);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: buffer open failed: %d: %s\n",
+ rc, strerror (rc));
+ errno = rc;
+ return -1;
+ }
+
+ rc = rtems_rfs_fs_read_superblock (*fs);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_close (*fs);
+ free (*fs);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: reading superblock: %d: %s\n",
+ rc, strerror (rc));
+ errno = rc;
+ return -1;
+ }
+
+ rc = rtems_rfs_inode_open (*fs, RTEMS_RFS_ROOT_INO, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_close (*fs);
+ free (*fs);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: reading root inode: %d: %s\n",
+ rc, strerror (rc));
+ errno = rc;
+ return -1;
+ }
+
+ if (((*fs)->flags & RTEMS_RFS_FS_FORCE_OPEN) == 0)
+ {
+ mode = rtems_rfs_inode_get_mode (&inode);
+
+ if ((mode == 0xffff) || !RTEMS_RFS_S_ISDIR (mode))
+ {
+ rtems_rfs_inode_close (*fs, &inode);
+ rtems_rfs_buffer_close (*fs);
+ free (*fs);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: invalid root inode mode\n");
+ errno = EIO;
+ return -1;
+ }
+ }
+
+ rc = rtems_rfs_inode_close (*fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_close (*fs);
+ free (*fs);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
+ printf ("rtems-rfs: open: closing root inode: %d: %s\n", rc, strerror (rc));
+ errno = rc;
+ return -1;
+ }
+
+ errno = 0;
+ return 0;
+}
+
+int
+rtems_rfs_fs_close (rtems_rfs_file_system* fs)
+{
+ int group;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_CLOSE))
+ printf ("rtems-rfs: close\n");
+
+ for (group = 0; group < fs->group_count; group++)
+ rtems_rfs_group_close (fs, &fs->groups[group]);
+
+ rtems_rfs_buffer_close (fs);
+
+ free (fs);
+ return 0;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file-system.h b/cpukit/libfs/src/rfs/rtems-rfs-file-system.h
new file mode 100644
index 0000000000..9ca0e4754f
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-file-system.h
@@ -0,0 +1,402 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Data
+ *
+ * This file defines the file system data.
+ */
+
+#if !defined (_RTEMS_RFS_FILE_SYSTEM_H_)
+#define _RTEMS_RFS_FILE_SYSTEM_H_
+
+#include <rtems/rfs/rtems-rfs-group.h>
+
+/**
+ * Superblock offsets and values.
+ */
+#define RTEMS_RFS_SB_OFFSET_MAGIC (0)
+#define RTEMS_RFS_SB_MAGIC (0x28092001)
+#define RTEMS_RFS_SB_OFFSET_VERSION (RTEMS_RFS_SB_OFFSET_MAGIC + 4)
+#define RTEMS_RFS_SB_OFFSET_BLOCK_SIZE (RTEMS_RFS_SB_OFFSET_VERSION + 4)
+#define RTEMS_RFS_SB_OFFSET_BLOCKS (RTEMS_RFS_SB_OFFSET_BLOCK_SIZE + 4)
+#define RTEMS_RFS_SB_OFFSET_BAD_BLOCKS (RTEMS_RFS_SB_OFFSET_BLOCKS + 4)
+#define RTEMS_RFS_SB_OFFSET_MAX_NAME_LENGTH (RTEMS_RFS_SB_OFFSET_BAD_BLOCKS + 4)
+#define RTEMS_RFS_SB_OFFSET_GROUPS (RTEMS_RFS_SB_OFFSET_MAX_NAME_LENGTH + 4)
+#define RTEMS_RFS_SB_OFFSET_GROUP_BLOCKS (RTEMS_RFS_SB_OFFSET_GROUPS + 4)
+#define RTEMS_RFS_SB_OFFSET_GROUP_INODES (RTEMS_RFS_SB_OFFSET_GROUP_BLOCKS + 4)
+#define RTEMS_RFS_SB_OFFSET_INODE_SIZE (RTEMS_RFS_SB_OFFSET_GROUP_INODES + 4)
+
+/**
+ * RFS Version Number.
+ */
+#define RTEMS_RFS_VERSION (0x00000000)
+
+/**
+ * RFS Version Number Mask. The mask determines which bits of the version
+ * number indicate compatility issues.
+ */
+#define RTEMS_RFS_VERSION_MASK INT32_C(0x00000000)
+
+/**
+ * The root inode number. Do not use 0 as this has special meaning in some Unix
+ * operating systems.
+ */
+#define RTEMS_RFS_ROOT_INO (1)
+
+/**
+ * Empty inode number.
+ */
+#define RTEMS_RFS_EMPTY_INO (0)
+
+/**
+ * The number of blocks in the inode. This number effects the size of the inode
+ * and that effects the overhead of the inode tables in a group.
+ */
+#define RTEMS_RFS_INODE_BLOCKS (5)
+
+/**
+ * The inode overhead is the percentage of space reserved for inodes. It is
+ * calculated as the percentage number of blocks in a group. The number of
+ * blocks in a group is the number of bits a block can hold.
+ */
+#define RTEMS_RFS_INODE_OVERHEAD_PERCENTAGE (1)
+
+/**
+ * Number of blocks in the superblock. Yes I know it is a superblock and not
+ * superblocks but if for any reason this needs to change it is handled.
+ */
+#define RTEMS_RFS_SUPERBLOCK_SIZE (1)
+
+/**
+ * The maximum number of buffers held by the file system at any one time.
+ */
+#define RTEMS_RFS_FS_MAX_HELD_BUFFERS (5)
+
+/**
+ * Absolute position. Make a 64bit value.
+ */
+typedef uint64_t rtems_rfs_pos;
+
+/**
+ * Relative position. Make a 64bit value.
+ */
+typedef int64_t rtems_rfs_pos_rel;
+
+/**
+ * Flags to control the file system.
+ */
+#define RTEMS_RFS_FS_BITMAPS_HOLD (1 << 0) /**< Do not release bitmaps
+ * when finished. Default is
+ * off so they are released. */
+#define RTEMS_RFS_FS_NO_LOCAL_CACHE (1 << 1) /**< Do not cache the buffers
+ * and release directly to the
+ * buffer support layer. The
+ * default is to hold buffers. */
+#define RTEMS_RFS_FS_FORCE_OPEN (1 << 2) /**< Force open and ignore any
+ * errors. */
+#define RTEMS_RFS_FS_READ_ONLY (1 << 3) /**< Make the mount
+ * read-only. Currently not
+ * supported. */
+/**
+ * RFS File System data.
+ */
+struct _rtems_rfs_file_system
+{
+ /**
+ * Flags to control the file system. Some can be controlled via the ioctl.
+ */
+ uint32_t flags;
+
+ /**
+ * The number of blocks in the disk. The size of the disk is the number of
+ * blocks by the block size. This should be within a block size of the size
+ * returned by the media driver.
+ */
+ size_t blocks;
+
+ /**
+ * The size of a block. This must be a multiple of the disk's media block
+ * size.
+ */
+ size_t block_size;
+
+#if RTEMS_RFS_USE_LIBBLOCK
+ /**
+ * The disk device. This is the data about the block device this file system
+ * is mounted on. We access the data held in this structure rather than
+ * making an extra copy in this structure.
+ */
+ rtems_disk_device* disk;
+#else
+ /**
+ * The device number which is a the file handle for device I/O.
+ */
+ dev_t device;
+
+ /**
+ * The number of blocks in the file system.
+ */
+ size_t size;
+#endif
+
+ /**
+ * Inode count.
+ */
+ uint32_t inodes;
+
+ /**
+ * Bad block blocks. This is a table of blocks that have been found to be
+ * bad.
+ */
+ uint32_t bad_blocks;
+
+ /**
+ * Maximum length of names supported by this file system.
+ */
+ uint32_t max_name_length;
+
+ /**
+ * A disk is broken down into a series of groups.
+ */
+ rtems_rfs_group* groups;
+
+ /**
+ * Number of groups.
+ */
+ int group_count;
+
+ /**
+ * Number of blocks in a group.
+ */
+ size_t group_blocks;
+
+ /**
+ * Number of inodes in a group.
+ */
+ size_t group_inodes;
+
+ /**
+ * Number of inodes in each block.
+ */
+ size_t inodes_per_block;
+
+ /**
+ * Number of block numbers in a block.
+ */
+ size_t blocks_per_block;
+
+ /**
+ * Block map single indirect count. This is the block number per block
+ * multiplied but the slots in the inode.
+ */
+ size_t block_map_singly_blocks;
+
+ /**
+ * Block map double indirect count. This is the block number per block
+ * squared and multiplied by the slots in the inode. It is the maximum
+ * number of blocks a map (file/directory) can have.
+ */
+ size_t block_map_doubly_blocks;
+
+ /**
+ * Number of buffers held before releasing back to the cache.
+ */
+ uint32_t max_held_buffers;
+
+ /**
+ * List of buffers attached to buffer handles. Allows sharing.
+ */
+ rtems_chain_control buffers;
+
+ /**
+ * Number of buffers held on the buffers list.
+ */
+ uint32_t buffers_count;
+
+ /**
+ * List of buffers that need to be released when the processing of a file
+ * system request has completed.
+ */
+ rtems_chain_control release;
+
+ /**
+ * Number of buffers held on the release list.
+ */
+ uint32_t release_count;
+
+ /**
+ * List of buffers that need to be released modified when the processing of a
+ * file system request has completed.
+ */
+ rtems_chain_control release_modified;
+
+ /**
+ * Number of buffers held on the release modified list.
+ */
+ uint32_t release_modified_count;
+
+ /**
+ * List of open shared file node data. The shared node data such as the inode
+ * and block map allows a single file to be open more than once.
+ */
+ rtems_chain_control file_shares;
+
+ /**
+ * Pointer to user data supplied when opening.
+ */
+ void* user;
+};
+
+/**
+ * Return the flags.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#define rtems_rfs_fs_flags(_f) ((_f)->flags)
+/**
+ * Should bitmap buffers be released when finished ?
+ *
+ * @param _fs Pointer to the file system.
+ */
+#define rtems_rfs_fs_release_bitmaps(_f) (!((_f)->flags & RTEMS_RFS_FS_BITMAPS_HOLD))
+
+/**
+ * Are the buffers locally cache or released back to the buffering layer ?
+ *
+ * @param _fs Pointer to the file system.
+ */
+#define rtems_rfs_fs_no_local_cache(_f) ((_f)->flags & RTEMS_RFS_FS_NO_LOCAL_CACHE)
+
+/**
+ * The disk device number.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#if RTEMS_RFS_USE_LIBBLOCK
+#define rtems_rfs_fs_device(_fs) ((_fs)->disk->dev)
+#else
+#define rtems_rfs_fs_device(_fs) ((_fs)->device)
+#endif
+
+/**
+ * The size of the disk in blocks.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#define rtems_rfs_fs_blocks(_fs) ((_fs)->blocks)
+
+/**
+ * The block size.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#define rtems_rfs_fs_block_size(_fs) ((_fs)->block_size)
+
+/**
+ * The number of inodes.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#define rtems_rfs_fs_inodes(_fs) ((_fs)->inodes)
+
+/**
+ * Calculate a block in the file system given the group and the block within
+ * the group.
+ *
+ * @param _fs Pointer to the file system.
+ * @param _grp The group.
+ * @param _blk The block within the group.
+ * @return The absolute block number.
+ */
+#define rtems_rfs_fs_block(_fs, _grp, _blk) \
+ ((((_fs)->group_blocks) * (_grp)) + (_blk) + 1)
+
+/**
+ * The media size of the disk in media size blocks.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#if RTEMS_RFS_USE_LIBBLOCK
+#define rtems_rfs_fs_media_blocks(_fs) ((_fs)->disk->size)
+#else
+#define rtems_rfs_fs_media_blocks(_fs) ((_fs)->media_size)
+#endif
+
+/**
+ * The media block size. This is the size of a block on disk. For a device I/O
+ * this value is 1.
+ *
+ * @param _fs Pointer to the file system.
+ */
+#if RTEMS_RFS_USE_LIBBLOCK
+#define rtems_rfs_fs_media_block_size(_fs) ((_fs)->disk->media_block_size)
+#else
+#define rtems_rfs_fs_media_block_size(_fs) (1)
+#endif
+
+/**
+ * The maximum length of a name supported by the file system.
+ */
+#define rtems_rfs_fs_max_name(_fs) ((_fs)->max_name_length)
+
+/**
+ * Return the maximum number of blocks in a block map.
+ *
+ * @return uint32_t The maximum number of blocks possible.
+ */
+#define rtems_rfs_fs_max_block_map_blocks(_fs) ((_fs)->block_map_doubly_blocks)
+
+/**
+ * Return the user pointer.
+ */
+#define rtems_rfs_fs_user(_fs) ((_fs)->user)
+
+/**
+ * Return the size of the disk in bytes.
+ *
+ * @param fs Pointer to the file system.
+ * @return uint64_t The size of the disk in bytes.
+ */
+uint64_t rtems_rfs_fs_size(rtems_rfs_file_system* fs);
+
+/**
+ * The size of the disk in bytes calculated from the media parameters..
+ *
+ * @param fs Pointer to the file system.
+ * @return uint64_t The size of the disk in bytes.
+ */
+uint64_t rtems_rfs_fs_media_size (rtems_rfs_file_system* fs);
+
+/**
+ * Open the file system given a file path.
+ *
+ * @param name The device to open.
+ * @param fs The file system data filled in by this call.
+ * @param user A pointer to user data.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_fs_open (const char* name,
+ void* user,
+ uint32_t flags,
+ rtems_rfs_file_system** fs);
+
+/**
+ * Close the file system.
+ *
+ * @param fs The file system data.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_fs_close (rtems_rfs_file_system* fs);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file.c b/cpukit/libfs/src/rfs/rtems-rfs-file.c
new file mode 100644
index 0000000000..777726a23a
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-file.c
@@ -0,0 +1,596 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems File Routines.
+ *
+ * These functions manage files.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-block-pos.h>
+#include <rtems/rfs/rtems-rfs-file.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+int
+rtems_rfs_file_open (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino,
+ uint32_t flags,
+ rtems_rfs_file_handle** file)
+{
+ rtems_rfs_file_handle* handle;
+ rtems_rfs_file_shared* shared;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_OPEN))
+ printf ("rtems-rfs: file-open: ino=%" PRId32 "\n", ino);
+
+ *file = NULL;
+
+ /*
+ * Allocate a new handle and initialise it. Do this before we deal with the
+ * shared node data so we do not have to be concerned with reference
+ * counting.
+ */
+ handle = malloc (sizeof (rtems_rfs_file_handle));
+ if (!handle)
+ return ENOMEM;
+
+ memset (handle, 0, sizeof (rtems_rfs_file_handle));
+
+ rc = rtems_rfs_buffer_handle_open (fs, &handle->buffer);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_OPEN))
+ printf ("rtems-rfs: file-open: buffer handle open failed: %d: %s\n",
+ rc, strerror (rc));
+ free (handle);
+ return rc;
+ }
+
+ /*
+ * Scan the file system data list of open files for this ino. If found up
+ * the reference count and return the pointer to the data.
+ */
+ shared = rtems_rfs_file_get_shared (fs, ino);
+ if (shared)
+ {
+ shared->references++;
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_OPEN))
+ printf ("rtems-rfs: file-open: ino=%" PRId32 " shared\n", ino);
+ }
+ else
+ {
+ /*
+ * None exists so create. Copy in the shared parts of the inode we hold in
+ * memory.
+ */
+ shared = malloc (sizeof (rtems_rfs_file_shared));
+ if (!shared)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle->buffer);
+ free (handle);
+ return ENOMEM;
+ }
+
+ memset (shared, 0, sizeof (rtems_rfs_file_shared));
+
+ rc = rtems_rfs_inode_open (fs, ino, &shared->inode, true);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_OPEN))
+ printf ("rtems-rfs: file-open: inode open failed: %d: %s\n",
+ rc, strerror (rc));
+ free (shared);
+ rtems_rfs_buffer_handle_close (fs, &handle->buffer);
+ free (handle);
+ return rc;
+ }
+
+ rc = rtems_rfs_block_map_open (fs, &shared->inode, &shared->map);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_OPEN))
+ printf ("rtems-rfs: file-open: block map open failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &shared->inode);
+ free (shared);
+ rtems_rfs_buffer_handle_close (fs, &handle->buffer);
+ free (handle);
+ return rc;
+ }
+
+ shared->references = 1;
+ shared->size.count = rtems_rfs_inode_get_block_count (&shared->inode);
+ shared->size.offset = rtems_rfs_inode_get_block_offset (&shared->inode);
+ shared->atime = rtems_rfs_inode_get_atime (&shared->inode);
+ shared->mtime = rtems_rfs_inode_get_mtime (&shared->inode);
+ shared->ctime = rtems_rfs_inode_get_ctime (&shared->inode);
+ shared->fs = fs;
+
+ rtems_chain_append (&fs->file_shares, &shared->link);
+
+ rtems_rfs_inode_unload (fs, &shared->inode, false);
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_OPEN))
+ printf ("rtems-rfs: file-open: ino=%" PRId32 " share created\n", ino);
+ }
+
+ handle->flags = flags;
+ handle->shared = shared;
+
+ *file = handle;
+
+ return 0;
+}
+
+int
+rtems_rfs_file_close (rtems_rfs_file_system* fs,
+ rtems_rfs_file_handle* handle)
+{
+ int rrc;
+ int rc;
+
+ rrc = 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE))
+ printf ("rtems-rfs: file-close: entry: ino=%" PRId32 "\n",
+ handle->shared->inode.ino);
+
+ if (handle->shared->references > 0)
+ handle->shared->references--;
+
+ if (handle->shared->references == 0)
+ {
+ if (!rtems_rfs_inode_is_loaded (&handle->shared->inode))
+ rrc = rtems_rfs_inode_load (fs, &handle->shared->inode);
+
+ if (rrc == 0)
+ {
+ /*
+ * @todo This could be clever and only update if different.
+ */
+ rtems_rfs_inode_set_atime (&handle->shared->inode,
+ handle->shared->atime);
+ rtems_rfs_inode_set_mtime (&handle->shared->inode,
+ handle->shared->mtime);
+ rtems_rfs_inode_set_ctime (&handle->shared->inode,
+ handle->shared->ctime);
+ if (!rtems_rfs_block_size_equal (&handle->shared->size,
+ &handle->shared->map.size))
+ rtems_rfs_block_map_set_size (&handle->shared->map,
+ &handle->shared->size);
+ }
+
+ rc = rtems_rfs_block_map_close (fs, &handle->shared->map);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE))
+ printf ("rtems-rfs: file-close: map close error: ino=%" PRId32 ": %d: %s\n",
+ handle->shared->inode.ino, rc, strerror (rc));
+ if (rrc == 0)
+ rrc = rc;
+ }
+
+ rc = rtems_rfs_inode_close (fs, &handle->shared->inode);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE))
+ printf ("rtems-rfs: file-close: inode close error: ino=%" PRId32 ": %d: %s\n",
+ handle->shared->inode.ino, rc, strerror (rc));
+ if (rrc == 0)
+ rrc = rc;
+ }
+
+ rtems_chain_extract (&handle->shared->link);
+ free (handle->shared);
+ }
+
+ rc = rtems_rfs_buffer_handle_close (fs, &handle->buffer);
+ if ((rrc == 0) && (rc > 0))
+ rrc = rc;
+
+ if (rrc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE))
+ printf ("rtems-rfs: file-close: result: %d: %s\n", rrc, strerror (rrc));
+ }
+
+ free (handle);
+
+ return rrc;
+}
+
+int
+rtems_rfs_file_io_start (rtems_rfs_file_handle* handle,
+ size_t* available,
+ bool read)
+{
+ size_t size;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-io: start: %s pos=%" PRIu32 ":%" PRIu32 "\n",
+ read ? "read" : "write", handle->bpos.bno, handle->bpos.boff);
+
+ if (!rtems_rfs_buffer_handle_has_block (&handle->buffer))
+ {
+ rtems_rfs_buffer_block block;
+ bool request_read;
+ int rc;
+
+ request_read = read;
+
+ rc = rtems_rfs_block_map_find (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_map (handle),
+ rtems_rfs_file_bpos (handle),
+ &block);
+ if (rc > 0)
+ {
+ /*
+ * Has the read reached the EOF ?
+ */
+ if (read && (rc == ENXIO))
+ {
+ *available = 0;
+ return 0;
+ }
+
+ if (rc != ENXIO)
+ return rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-io: start: grow\n");
+
+ rc = rtems_rfs_block_map_grow (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_map (handle),
+ 1, &block);
+ if (rc > 0)
+ return rc;
+
+ request_read = false;
+ }
+ else
+ {
+ /*
+ * If this is a write check if the write starts within a block or the
+ * amount of data is less than a block size. If it is read the block
+ * rather than getting a block to fill.
+ */
+ if (!read &&
+ (rtems_rfs_file_block_offset (handle) ||
+ (*available < rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle)))))
+ request_read = true;
+ }
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-io: start: block=%" PRIu32 " request-read=%s\n",
+ block, request_read ? "yes" : "no");
+
+ rc = rtems_rfs_buffer_handle_request (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_buffer (handle),
+ block, request_read);
+ if (rc > 0)
+ return rc;
+ }
+
+ if (read
+ && rtems_rfs_block_map_last (rtems_rfs_file_map (handle))
+ && rtems_rfs_block_map_size_offset (rtems_rfs_file_map (handle)))
+ size = rtems_rfs_block_map_size_offset (rtems_rfs_file_map (handle));
+ else
+ size = rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle));
+
+ *available = size - rtems_rfs_file_block_offset (handle);
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-io: start: available=%zu (%zu)\n",
+ *available, size);
+
+ return 0;
+}
+
+int
+rtems_rfs_file_io_end (rtems_rfs_file_handle* handle,
+ size_t size,
+ bool read)
+{
+ bool atime;
+ bool mtime;
+ bool length;
+ int rc = 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-io: end: %s size=%zu\n",
+ read ? "read" : "write", size);
+
+ if (rtems_rfs_buffer_handle_has_block (&handle->buffer))
+ {
+ if (!read)
+ rtems_rfs_buffer_mark_dirty (rtems_rfs_file_buffer (handle));
+ rc = rtems_rfs_buffer_handle_release (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_buffer (handle));
+ if (rc > 0)
+ {
+ printf (
+ "rtems-rfs: file-io: end: error on release: %s size=%zu: %d: %s\n",
+ read ? "read" : "write", size, rc, strerror (rc));
+
+ return rc;
+ }
+ }
+
+ /*
+ * Update the handle's position. Only a block size can be handled at a time
+ * so no special maths is needed. If the offset is bigger than the block size
+ * increase the block number and adjust the offset.
+ *
+ * If we are the last block and the position is past the current size update
+ * the size with the new length. The map holds the block count.
+ */
+ handle->bpos.boff += size;
+
+ if (handle->bpos.boff >=
+ rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle)))
+ {
+ handle->bpos.bno++;
+ handle->bpos.boff -= rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle));
+ }
+
+ length = false;
+ mtime = false;
+
+ if (!read &&
+ rtems_rfs_block_map_past_end (rtems_rfs_file_map (handle),
+ rtems_rfs_file_bpos (handle)))
+ {
+ rtems_rfs_block_map_set_size_offset (rtems_rfs_file_map (handle),
+ handle->bpos.boff);
+ length = true;
+ mtime = true;
+ }
+
+ atime = rtems_rfs_file_update_atime (handle);
+ mtime = rtems_rfs_file_update_mtime (handle) && mtime;
+ length = rtems_rfs_file_update_length (handle) && length;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-io: end: pos=%" PRIu32 ":%" PRIu32 " %c %c %c\n",
+ handle->bpos.bno, handle->bpos.boff,
+ atime ? 'A' : '-', mtime ? 'M' : '-', length ? 'L' : '-');
+
+ if (atime || mtime)
+ {
+ time_t now = time (NULL);
+ if (read && atime)
+ handle->shared->atime = now;
+ if (!read && mtime)
+ handle->shared->mtime = now;
+ }
+ if (length)
+ {
+ handle->shared->size.count =
+ rtems_rfs_block_map_count (rtems_rfs_file_map (handle));
+ handle->shared->size.offset =
+ rtems_rfs_block_map_size_offset (rtems_rfs_file_map (handle));
+ }
+
+ return rc;
+}
+
+int
+rtems_rfs_file_io_release (rtems_rfs_file_handle* handle)
+{
+ int rc = 0;
+ if (rtems_rfs_buffer_handle_has_block (&handle->buffer))
+ rc = rtems_rfs_buffer_handle_release (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_buffer (handle));
+ return rc;
+}
+
+int
+rtems_rfs_file_seek (rtems_rfs_file_handle* handle,
+ rtems_rfs_pos pos,
+ rtems_rfs_pos* new_pos)
+{
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-seek: new=%" PRIu64 "\n", pos);
+
+ /*
+ * This call only sets the position if it is in a valid part of the file. The
+ * user can request past the end of the file then write to extend the
+ * file. The lseek entry states:
+ *
+ * "Although lseek() may position the file offset beyond the end of the
+ * file, this function does not itself extend the size of the file."
+ *
+ * This means the file needs to set the file size to the pos only when a
+ * write occurs.
+ */
+ if (pos < rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
+ handle->shared))
+ rtems_rfs_file_set_bpos (handle, pos);
+
+ *new_pos = pos;
+ return 0;
+}
+
+int
+rtems_rfs_file_set_size (rtems_rfs_file_handle* handle,
+ rtems_rfs_pos new_size)
+{
+ rtems_rfs_block_map* map = rtems_rfs_file_map (handle);
+ rtems_rfs_pos size;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_IO))
+ printf ("rtems-rfs: file-set-size: size=%" PRIu64 "\n", new_size);
+
+ /*
+ * Short cut for the common truncate on open call.
+ */
+ if (new_size == 0)
+ {
+ rc = rtems_rfs_block_map_free_all (rtems_rfs_file_fs (handle), map);
+ if (rc > 0)
+ return rc;
+ }
+ else
+ {
+ size = rtems_rfs_file_size (handle);
+
+ /*
+ * If the file is same size do nothing else grow or shrink it ?
+ */
+ if (size != new_size)
+ {
+ if (size < new_size)
+ {
+ /*
+ * Grow. Fill with 0's.
+ */
+ rtems_rfs_pos count;
+ uint32_t length;
+ bool read_block;
+
+ count = new_size - size;
+ length = rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle));
+ read_block = false;
+
+ while (count)
+ {
+ rtems_rfs_buffer_block block;
+ rtems_rfs_block_pos bpos;
+ uint8_t* dst;
+
+ /*
+ * Get the block position for the current end of the file as seen by
+ * the map. If not found and the EOF grow the map then fill the block
+ * with 0.
+ */
+ rtems_rfs_block_size_get_bpos (rtems_rfs_block_map_size (map), &bpos);
+ rc = rtems_rfs_block_map_find (rtems_rfs_file_fs (handle),
+ map, &bpos, &block);
+ if (rc > 0)
+ {
+ /*
+ * Have we reached the EOF ?
+ */
+ if (rc != ENXIO)
+ return rc;
+
+ rc = rtems_rfs_block_map_grow (rtems_rfs_file_fs (handle),
+ map, 1, &block);
+ if (rc > 0)
+ return rc;
+ }
+
+ if (count < (length - bpos.boff))
+ {
+ length = count + bpos.boff;
+ read_block = true;
+ rtems_rfs_block_map_set_size_offset (map, length);
+ }
+ else
+ {
+ rtems_rfs_block_map_set_size_offset (map, 0);
+ }
+
+ /*
+ * Only read the block if the length is not the block size.
+ */
+ rc = rtems_rfs_buffer_handle_request (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_buffer (handle),
+ block, read_block);
+ if (rc > 0)
+ return rc;
+
+ dst = rtems_rfs_buffer_data (&handle->buffer);
+ memset (dst + bpos.boff, 0, length - bpos.boff);
+
+ rtems_rfs_buffer_mark_dirty (rtems_rfs_file_buffer (handle));
+
+ rc = rtems_rfs_buffer_handle_release (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_buffer (handle));
+ if (rc > 0)
+ return rc;
+
+ count -= length - bpos.boff;
+ }
+ }
+ else
+ {
+ /*
+ * Shrink
+ */
+ rtems_rfs_block_no blocks;
+ uint32_t offset;
+
+ blocks =
+ rtems_rfs_block_map_count (map) -
+ (((new_size - 1) /
+ rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle))) + 1);
+
+ offset =
+ new_size % rtems_rfs_fs_block_size (rtems_rfs_file_fs (handle));
+
+ if (blocks)
+ {
+ int rc;
+ rc = rtems_rfs_block_map_shrink (rtems_rfs_file_fs (handle),
+ rtems_rfs_file_map (handle),
+ blocks);
+ if (rc > 0)
+ return rc;
+ }
+
+ rtems_rfs_block_map_set_size_offset (map, offset);
+
+ if (rtems_rfs_block_pos_past_end (rtems_rfs_file_bpos (handle),
+ rtems_rfs_block_map_size (map)))
+ rtems_rfs_block_size_get_bpos (rtems_rfs_block_map_size (map),
+ rtems_rfs_file_bpos (handle));
+ }
+ }
+ }
+
+ handle->shared->size.count = rtems_rfs_block_map_count (map);
+ handle->shared->size.offset = rtems_rfs_block_map_size_offset (map);
+
+ if (rtems_rfs_file_update_mtime (handle))
+ handle->shared->mtime = time (NULL);
+
+ return 0;
+}
+
+rtems_rfs_file_shared*
+rtems_rfs_file_get_shared (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino)
+{
+ rtems_chain_node* node;
+ node = rtems_chain_first (&fs->file_shares);
+ while (!rtems_chain_is_tail (&fs->file_shares, node))
+ {
+ rtems_rfs_file_shared* shared;
+ shared = (rtems_rfs_file_shared*) node;
+ if (shared->inode.ino == ino)
+ return shared;
+ node = rtems_chain_next (node);
+ }
+ return NULL;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file.h b/cpukit/libfs/src/rfs/rtems-rfs-file.h
new file mode 100644
index 0000000000..54a2187df3
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-file.h
@@ -0,0 +1,393 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System File Support
+ *
+ * This file provides the support functions.
+ */
+
+#if !defined (_RTEMS_RFS_FILE_H_)
+#define _RTEMS_RFS_FILE_H_
+
+#include <rtems/libio_.h>
+
+#include <rtems/rfs/rtems-rfs-block.h>
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+
+/**
+ * File data that is shared by various file handles accessing the same file. We
+ * hold various inode values common to the file that can change frequently so
+ * the inode is not thrashed yet we meet the requirements of the POSIX
+ * standard. The stat call needs to check the shared file data.
+ */
+typedef struct _rtems_rfs_file_shared
+{
+ /**
+ * The shared parts are maintained as a list.
+ */
+ rtems_chain_node link;
+
+ /**
+ * Reference count the users of this data.
+ */
+ int references;
+
+ /**
+ * The inode for the file.
+ */
+ rtems_rfs_inode_handle inode;
+
+ /**
+ * The block map for the file. The handle holds the file's position not the
+ * map.
+ */
+ rtems_rfs_block_map map;
+
+ /**
+ * The size of the file as taken from the inode. The map's size and
+ * this size should be the same.
+ */
+ rtems_rfs_block_size size;
+
+ /**
+ * The access time. The last time the file was read.
+ */
+ rtems_rfs_time atime;
+
+ /**
+ * The modified time. The last time the file was written too.
+ */
+ rtems_rfs_time mtime;
+
+ /**
+ * The change time. The last time the inode was written too.
+ */
+ rtems_rfs_time ctime;
+
+ /**
+ * Hold a pointer to the file system data so users can take the handle and
+ * use it without the needing to hold the file system data pointer.
+ */
+ rtems_rfs_file_system* fs;
+
+} rtems_rfs_file_shared;
+
+/**
+ * Get the atime.
+ *
+ * @param shared The shared file data.
+ * @return rtems_rfs_time The atime.
+ */
+static inline rtems_rfs_time
+rtems_rfs_file_shared_get_atime (rtems_rfs_file_shared* shared)
+{
+ return shared->atime;
+}
+
+/**
+ * Get the mtime.
+ *
+ * @param shared The shared file data.
+ * @return rtems_rfs_time The mtime.
+ */
+static inline rtems_rfs_time
+rtems_rfs_file_shared_get_mtime (rtems_rfs_file_shared* shared)
+{
+ return shared->mtime;
+}
+
+/**
+ * Get the ctime.
+ *
+ * @param shared The shared file data.
+ * @return rtems_rfs_time The ctime.
+ */
+static inline rtems_rfs_time
+rtems_rfs_file_shared_get_ctime (rtems_rfs_file_shared* shared)
+{
+ return shared->ctime;
+}
+
+/**
+ * Get the block count.
+ *
+ * @param shared The shared file data.
+ * @return uint32_t The block count.
+ */
+static inline uint32_t
+rtems_rfs_file_shared_get_block_count (rtems_rfs_file_shared* shared)
+{
+ return shared->size.count;
+}
+
+/**
+ * Get the block offset.
+ *
+ * @param shared The shared file data.
+ * @return uint16_t The block offset.
+ */
+static inline uint16_t
+rtems_rfs_file_shared_get_block_offset (rtems_rfs_file_shared* shared)
+{
+ return shared->size.offset;
+}
+
+/**
+ * Calculate the size of data.
+ *
+ * @param fs The file system data.
+ * @oaram shared The shared file data.
+ * @return rtems_rfs_pos The data size in bytes.
+ */
+static inline rtems_rfs_pos
+rtems_rfs_file_shared_get_size (rtems_rfs_file_system* fs,
+ rtems_rfs_file_shared* shared)
+{
+ return rtems_rfs_block_get_size (fs, &shared->size);
+}
+
+/**
+ * File flags.
+ */
+#define RTEMS_RFS_FILE_NO_ATIME_UPDATE (1 << 0) /**< Do not update the atime
+ * field in the inode if
+ * set. */
+#define RTEMS_RFS_FILE_NO_MTIME_UPDATE (1 << 1) /**< Do not update the mtime
+ * field in the inode if
+ * set. */
+#define RTEMS_RFS_FILE_NO_LENGTH_UPDATE (1 << 2) /**< Do not update the position
+ * field in the inode if
+ * set. */
+
+/**
+ * File data used to managed an open file.
+ */
+typedef struct _rtems_rfs_file_handle
+{
+ /**
+ * Special flags that can be controlled by the fctrl call.
+ */
+ uint32_t flags;
+
+ /**
+ * The buffer of data at the file's position.
+ */
+ rtems_rfs_buffer_handle buffer;
+
+ /**
+ * The block position of this file handle.
+ */
+ rtems_rfs_block_pos bpos;
+
+ /**
+ * Pointer to the shared file data.
+ */
+ rtems_rfs_file_shared* shared;
+
+} rtems_rfs_file_handle;
+
+/**
+ * Access the data in the buffer.
+ */
+#define rtems_rfs_file_data(_f) \
+ (rtems_rfs_buffer_data (&(_f)->buffer) + (_f)->bpos.boff)
+
+/**
+ * Return the file system data pointer given a file handle.
+ */
+#define rtems_rfs_file_fs(_f) ((_f)->shared->fs)
+
+/**
+ * Return the file's inode handle pointer given a file handle.
+ */
+#define rtems_rfs_file_inode(_f) (&(_f)->shared->inode)
+
+/**
+ * Return the file's block map pointer given a file handle.
+ */
+#define rtems_rfs_file_map(_f) (&(_f)->shared->map)
+
+/**
+ * Return the file's block position pointer given a file handle.
+ */
+#define rtems_rfs_file_bpos(_f) (&(_f)->bpos)
+
+/**
+ * Return the file's block number given a file handle.
+ */
+#define rtems_rfs_file_block(_f) ((_f)->bpos.bno)
+
+/**
+ * Return the file's block offset given a file handle.
+ */
+#define rtems_rfs_file_block_offset(_f) ((_f)->bpos.boff)
+
+/**
+ * Set the file's block position given a file position (absolute).
+ */
+#define rtems_rfs_file_set_bpos(_f, _p) \
+ rtems_rfs_block_get_bpos (rtems_rfs_file_fs (_f), _p, (&(_f)->bpos))
+
+/**
+ * Return the file's buffer handle pointer given a file handle.
+ */
+#define rtems_rfs_file_buffer(_f) (&(_f)->buffer)
+
+/**
+ * Update the access time field of the inode when reading if flagged to do so.
+ */
+#define rtems_rfs_file_update_atime(_f) \
+ (((_f)->flags & RTEMS_RFS_FILE_NO_ATIME_UPDATE) == 0)
+
+/**
+ * Update the modified time field of the inode when writing if flagged to do so.
+ */
+#define rtems_rfs_file_update_mtime(_f) \
+ (((_f)->flags & RTEMS_RFS_FILE_NO_MTIME_UPDATE) == 0)
+
+/**
+ * Update the length field of the inode.
+ */
+#define rtems_rfs_file_update_length(_f) \
+ (((_f)->flags & RTEMS_RFS_FILE_NO_LENGTH_UPDATE) == 0)
+
+/**
+ * Return the shared size varable.
+ */
+#define rtems_rfs_file_get_size(_f) \
+ (&(_f)->shared->size)
+
+/**
+ * Return the size of file.
+ */
+#define rtems_rfs_file_size(_f) \
+ rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (_f), (_f)->shared)
+
+/**
+ * Return the file block count.
+ */
+#define rtems_rfs_file_size_count(_f) \
+ rtems_rfs_file_shared_get_block_count ((_f)->shared)
+
+/**
+ * Return the file block offset.
+ */
+#define rtems_rfs_file_size_offset(_f) \
+ rtems_rfs_file_shared_get_block_offset ((_f)->shared)
+
+/**
+ * Open a file handle.
+ *
+ * @param fs The file system.
+ * @param ino The inode number of the file to be opened.
+ * @param handle Return the handle pointer in this handle.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_open (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino,
+ uint32_t flags,
+ rtems_rfs_file_handle** handle);
+
+/**
+ * Close an open file handle.
+ *
+ * @param fs The file system.
+ * @param handle The open file handle.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_close (rtems_rfs_file_system* fs,
+ rtems_rfs_file_handle* handle);
+
+/**
+ * Start I/O on a block of a file. This call only requests the block from the
+ * media if reading and makes the buffer available to you the via the
+ * rtems_rfs_file_data interface after the call. The available amount data is
+ * taken from the current file position until the end of the block. The file
+ * position is not adujsted until the I/O ends. An I/O request cannot perform
+ * I/O past the end of a block so the call returns the amount of data
+ * available.
+ *
+ * @param handle The file handle.
+ * @param available The amount of data available for I/O.
+ * @param read The I/O operation is a read so the block is read from the media.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_io_start (rtems_rfs_file_handle* handle,
+ size_t* available,
+ bool read);
+
+/**
+ * End the I/O. Any buffers held in the file handle and returned to the
+ * cache. If inode updating is not disable and the I/O is a read the atime
+ * field is updated and if a write I/O the mtime is updated.
+ *
+ * If the file's position is updated by the size amount.
+ *
+ * @param handle The file handle.
+ * @param size The amount of data read or written.
+ * @param read The I/O was a read if true else it was a write.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_io_end (rtems_rfs_file_handle* handle,
+ size_t size,
+ bool read);
+
+/**
+ * Release the I/O resources without any changes. If data has changed in the
+ * buffer and the buffer was not already released as modified the data will be
+ * lost.
+ *
+ * @param handle The file handle.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_io_release (rtems_rfs_file_handle* handle);
+
+/**
+ * The file to the position returning the old position. The position is
+ * abolute.
+ *
+ * @param handle The file handle.
+ * @param pos The position to seek to.
+ * @param new_pos The actual position.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_seek (rtems_rfs_file_handle* handle,
+ rtems_rfs_pos pos,
+ rtems_rfs_pos* new_pos);
+
+/**
+ * Set the size of the file to the new size. This can extend the file to a new
+ * size.
+ *
+ * @param handle The file handle.
+ * @param size The new size of the file.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_file_set_size (rtems_rfs_file_handle* handle,
+ rtems_rfs_pos size);
+
+/**
+ * Return the shared file data for an ino.
+ *
+ * @param fs The file system data.
+ * @param ino The inode number to locate the data for.
+ * @return rtems_rfs_file_shared* The shared data or NULL is not located.
+ */
+rtems_rfs_file_shared* rtems_rfs_file_get_shared (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino);
+
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-format.c b/cpukit/libfs/src/rfs/rtems-rfs-format.c
new file mode 100644
index 0000000000..8199466bfb
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-format.c
@@ -0,0 +1,644 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Format
+ *
+ * Format the file system ready for use.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+#include <rtems/rtems-rfs-format.h>
+#include <rtems/rfs/rtems-rfs-dir.h>
+
+/**
+ * Return the number of gigabytes.
+ */
+#define GIGS(_g) (((uint64_t)(_g)) * 1024 * 1024)
+
+/**
+ * Return the number of bits that fit in the block size.
+ */
+static int
+rtems_rfs_bits_per_block (rtems_rfs_file_system* fs)
+{
+ return rtems_rfs_bitmap_numof_bits (rtems_rfs_fs_block_size (fs));
+}
+
+/**
+ * Return a rounded up integer quotient given a dividend and divisor. That is:
+ * "quotient = dividend / divisor"
+ */
+int
+rtems_rfs_rup_quotient (uint32_t dividend, uint32_t divisor)
+{
+ if (dividend == 0)
+ return 1;
+ return ((dividend - 1) / divisor) + 1;
+}
+
+/**
+ * Return the number of inodes as a percentage of the total number that can fit
+ * in a blocl.
+ */
+static int
+rtems_rfs_inodes_from_percent (rtems_rfs_file_system* fs,
+ int percentage)
+{
+ int blocks;
+ blocks = ((rtems_rfs_fs_blocks (fs) -
+ RTEMS_RFS_SUPERBLOCK_SIZE) * percentage) / 100;
+ blocks = rtems_rfs_rup_quotient (blocks, fs->group_count);
+ return blocks * (rtems_rfs_fs_block_size (fs) / RTEMS_RFS_INODE_SIZE);
+}
+
+/**
+ * Return the inode overhead given a number of inodes.
+ */
+static int
+rtems_rfs_inode_overhead (rtems_rfs_file_system* fs)
+{
+ int blocks;
+ int bits_per_block;
+ blocks = rtems_rfs_rup_quotient(fs->group_inodes * RTEMS_RFS_INODE_SIZE,
+ rtems_rfs_fs_block_size (fs));
+ bits_per_block = rtems_rfs_bits_per_block (fs);
+ /*
+ * There could be more bits than blocks, eg 512K disk with 512 blocks.
+ */
+ if (bits_per_block > (rtems_rfs_fs_blocks (fs) - RTEMS_RFS_SUPERBLOCK_SIZE))
+ bits_per_block = rtems_rfs_fs_blocks (fs) - RTEMS_RFS_SUPERBLOCK_SIZE;
+ return ((blocks + 1) * 100 * 10) / bits_per_block;
+}
+
+static bool
+rtems_rfs_check_config (rtems_rfs_file_system* fs,
+ const rtems_rfs_format_config* config)
+{
+ fs->block_size = config->block_size;
+ if (!fs->block_size)
+ {
+ uint64_t total_size = rtems_rfs_fs_media_size (fs);
+
+ if (total_size >= GIGS (1))
+ {
+ uint32_t gigs = (total_size + GIGS (1)) / GIGS (1);
+ int b;
+ for (b = 31; b > 0; b--)
+ if ((gigs & (1 << b)) != 0)
+ break;
+ fs->block_size = 1 << b;
+ }
+
+ if (fs->block_size < 512)
+ fs->block_size = 512;
+
+ if (fs->block_size > (4 * 1024))
+ fs->block_size = (4 * 1024);
+ }
+
+ if ((fs->block_size % rtems_rfs_fs_media_block_size (fs)) != 0)
+ {
+ printf ("block size (%zd) is not a multiple of media block size (%" PRId32 ")\n",
+ fs->block_size, rtems_rfs_fs_media_block_size (fs));
+ return false;
+ }
+
+ fs->group_blocks = config->group_blocks;
+ if (!fs->group_blocks)
+ {
+ /*
+ * The number of blocks per group is defined by the number of bits in a
+ * block.
+ */
+ fs->group_blocks = rtems_rfs_bitmap_numof_bits (fs->block_size);
+ }
+
+ if (fs->group_blocks > rtems_rfs_bitmap_numof_bits (fs->block_size))
+ {
+ printf ("group block count is higher than bits in block\n");
+ return false;
+ }
+
+ fs->blocks = rtems_rfs_fs_media_size (fs) / fs->block_size;
+
+ /*
+ * The bits per block sets the upper limit for the number of blocks in a
+ * group. The disk will be divided into groups which are the number of bits
+ * per block.
+ */
+ fs->group_count = rtems_rfs_rup_quotient (rtems_rfs_fs_blocks (fs),
+ rtems_rfs_bits_per_block (fs));
+
+ fs->group_inodes = config->group_inodes;
+ if (!fs->group_inodes)
+ {
+ int inode_overhead = RTEMS_RFS_INODE_OVERHEAD_PERCENTAGE;
+
+ /*
+ * The number of inodes per group is set as a percentage.
+ */
+ if (config->inode_overhead)
+ inode_overhead = config->inode_overhead;
+
+ fs->group_inodes = rtems_rfs_inodes_from_percent (fs, inode_overhead);
+ }
+
+ /*
+ * Round up to fill a block because the minimum allocation unit is a block.
+ */
+ fs->inodes_per_block = rtems_rfs_fs_block_size (fs) / RTEMS_RFS_INODE_SIZE;
+ fs->group_inodes =
+ rtems_rfs_rup_quotient (fs->group_inodes,
+ fs->inodes_per_block) * fs->inodes_per_block;
+
+ if (fs->group_inodes > rtems_rfs_bitmap_numof_bits (fs->block_size))
+ fs->group_inodes = rtems_rfs_bitmap_numof_bits (fs->block_size);
+
+ fs->max_name_length = config->max_name_length;
+ if (!fs->max_name_length)
+ {
+ fs->max_name_length = 512;
+ }
+
+ return true;
+}
+
+static bool
+rtems_rfs_write_group (rtems_rfs_file_system* fs,
+ int group,
+ bool initialise_inodes,
+ bool verbose)
+{
+ rtems_rfs_buffer_handle handle;
+ rtems_rfs_bitmap_control bitmap;
+ rtems_rfs_buffer_block group_base;
+ size_t group_size;
+ int blocks;
+ int b;
+ int rc;
+
+ group_base = rtems_rfs_fs_block (fs, group, 0);
+
+ if (group_base > rtems_rfs_fs_blocks (fs))
+ {
+ printf ("rtems-rfs: write-group: group %d base beyond disk limit\n",
+ group);
+ return false;
+ }
+
+ group_size = fs->group_blocks;
+
+ /*
+ * Be nice to strange sizes of disks. These are embedded systems after all
+ * and nice numbers do not always work out. Let the last block pick up the
+ * remainder of the blocks.
+ */
+ if ((group_base + group_size) > rtems_rfs_fs_blocks (fs))
+ group_size = rtems_rfs_fs_blocks (fs) - group_base;
+
+ if (verbose)
+ printf ("\rrtems-rfs: format: group %3d: base = %" PRId32 ", size = %zd",
+ group, group_base, group_size);
+
+ /*
+ * Open a handle and request an empty buffer.
+ */
+ rc = rtems_rfs_buffer_handle_open (fs, &handle);
+ if (rc > 0)
+ {
+ printf ("\nrtems-rfs: write-group: handle open failed: %d: %s\n",
+ rc, strerror (rc));
+ return false;
+ }
+
+ if (verbose)
+ printf (", blocks");
+
+ /*
+ * Open the block bitmap using the new buffer.
+ */
+ rc = rtems_rfs_bitmap_open (&bitmap, fs, &handle, group_size,
+ group_base + RTEMS_RFS_GROUP_BLOCK_BITMAP_BLOCK);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: open block bitmap failed: %d: %s\n",
+ group, rc, strerror (rc));
+ return false;
+ }
+
+ /*
+ * Force the whole buffer to a known state. The bit map may not occupy the
+ * whole block.
+ */
+ memset (rtems_rfs_buffer_data (&handle), 0xff, rtems_rfs_fs_block_size (fs));
+
+ /*
+ * Clear the bitmap.
+ */
+ rc = rtems_rfs_bitmap_map_clear_all (&bitmap);
+ if (rc > 0)
+ {
+ rtems_rfs_bitmap_close (&bitmap);
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: block bitmap clear all failed: %d: %s\n",
+ group, rc, strerror (rc));
+ return false;
+ }
+
+ /*
+ * Forced allocation of the block bitmap.
+ */
+ rtems_rfs_bitmap_map_set (&bitmap, RTEMS_RFS_GROUP_BLOCK_BITMAP_BLOCK);
+
+ /*
+ * Forced allocation of the inode bitmap.
+ */
+ rtems_rfs_bitmap_map_set (&bitmap, RTEMS_RFS_GROUP_INODE_BITMAP_BLOCK);
+
+ /*
+ * Determine the number of inodes blocks in the group.
+ */
+ blocks = rtems_rfs_rup_quotient (fs->group_inodes, fs->inodes_per_block);
+
+ /*
+ * Forced allocation of the inode blocks which follow the block bitmap.
+ */
+ for (b = 0; b < blocks; b++)
+ rtems_rfs_bitmap_map_set (&bitmap, b + RTEMS_RFS_GROUP_INODE_BLOCK);
+
+ /*
+ * Close the block bitmap.
+ */
+ rc = rtems_rfs_bitmap_close (&bitmap);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: close block bitmap failed: %d: %s\n",
+ group, rc, strerror (rc));
+ return false;
+ }
+
+ rtems_rfs_buffer_mark_dirty (&handle);
+
+ if (verbose)
+ printf (", inodes");
+
+ /*
+ * Open the inode bitmap using the old buffer. Should release any changes.
+ */
+ rc = rtems_rfs_bitmap_open (&bitmap, fs, &handle, group_size,
+ group_base + RTEMS_RFS_GROUP_INODE_BITMAP_BLOCK);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: open inode bitmap failed: %d: %s\n",
+ group, rc, strerror (rc));
+ return false;
+ }
+
+ /*
+ * Force the whole buffer to a known state. The bit map may not occupy the
+ * whole block.
+ */
+ memset (rtems_rfs_buffer_data (&handle), 0x00, rtems_rfs_fs_block_size (fs));
+
+ /*
+ * Clear the inode bitmap.
+ */
+ rc = rtems_rfs_bitmap_map_clear_all (&bitmap);
+ if (rc > 0)
+ {
+ rtems_rfs_bitmap_close (&bitmap);
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: inode bitmap" \
+ " clear all failed: %d: %s\n", group, rc, strerror (rc));
+ return false;
+ }
+
+ /*
+ * Close the inode bitmap.
+ */
+ rc = rtems_rfs_bitmap_close (&bitmap);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: close inode" \
+ " bitmap failed: %d: %s\n", group, rc, strerror (rc));
+ return false;
+ }
+
+ rtems_rfs_buffer_mark_dirty (&handle);
+
+ /*
+ * Initialise the inode tables if required to do so.
+ */
+ if (initialise_inodes)
+ {
+ for (b = 0; b < blocks; b++)
+ {
+ rc = rtems_rfs_buffer_handle_request (fs, &handle,
+ group_base + b + RTEMS_RFS_GROUP_INODE_BLOCK,
+ false);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("\nrtems-rfs: write-group: group %3d: block %" PRId32 " request failed: %d: %s\n",
+ group, group_base + b + RTEMS_RFS_GROUP_INODE_BLOCK,
+ rc, strerror (rc));
+ return false;
+ }
+
+ /*
+ * Force the whole buffer to a known state. The bit map may not occupy the
+ * whole block.
+ */
+ memset (rtems_rfs_buffer_data (&handle), 0xff, rtems_rfs_fs_block_size (fs));
+
+ rtems_rfs_buffer_mark_dirty (&handle);
+ }
+ }
+
+ rc = rtems_rfs_buffer_handle_close (fs, &handle);
+ if (rc > 0)
+ {
+ printf ("\nrtems-rfs: write-group: buffer handle close failed: %d: %s\n",
+ rc, strerror (rc));
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+rtems_rfs_write_superblock (rtems_rfs_file_system* fs)
+{
+ rtems_rfs_buffer_handle handle;
+ uint8_t* sb;
+ int rc;
+
+ rc = rtems_rfs_buffer_handle_open (fs, &handle);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: write-superblock: handle open failed: %d: %s\n",
+ rc, strerror (rc));
+ return false;
+ }
+
+ rc = rtems_rfs_buffer_handle_request (fs, &handle, 0, false);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("rtems-rfs: write-superblock: request failed: %d: %s\n",
+ rc, strerror (rc));
+ return false;
+ }
+
+ sb = rtems_rfs_buffer_data (&handle);
+
+#define write_sb(_o, _d) rtems_rfs_write_u32(sb + (_o), _d)
+
+ memset (sb, 0xff, rtems_rfs_fs_block_size (fs));
+
+ write_sb (RTEMS_RFS_SB_OFFSET_MAGIC, RTEMS_RFS_SB_MAGIC);
+ write_sb (RTEMS_RFS_SB_OFFSET_VERSION, RTEMS_RFS_VERSION);
+ write_sb (RTEMS_RFS_SB_OFFSET_BLOCKS, rtems_rfs_fs_blocks (fs));
+ write_sb (RTEMS_RFS_SB_OFFSET_BLOCK_SIZE, rtems_rfs_fs_block_size (fs));
+ write_sb (RTEMS_RFS_SB_OFFSET_BAD_BLOCKS, fs->bad_blocks);
+ write_sb (RTEMS_RFS_SB_OFFSET_MAX_NAME_LENGTH, fs->max_name_length);
+ write_sb (RTEMS_RFS_SB_OFFSET_GROUPS, fs->group_count);
+ write_sb (RTEMS_RFS_SB_OFFSET_GROUP_BLOCKS, fs->group_blocks);
+ write_sb (RTEMS_RFS_SB_OFFSET_GROUP_INODES, fs->group_inodes);
+ write_sb (RTEMS_RFS_SB_OFFSET_INODE_SIZE, RTEMS_RFS_INODE_SIZE);
+
+ rtems_rfs_buffer_mark_dirty (&handle);
+
+ rc = rtems_rfs_buffer_handle_release (fs, &handle);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &handle);
+ printf ("rtems-rfs: write-superblock: buffer release failed: %d: %s\n",
+ rc, strerror (rc));
+ return false;
+ }
+
+ rc = rtems_rfs_buffer_handle_close (fs, &handle);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: write-superblock: buffer handle close failed: %d: %s\n",
+ rc, strerror (rc));
+ return false;
+ }
+
+ return true;
+}
+
+static int
+rtems_rfs_write_root_dir (const char* name)
+{
+ rtems_rfs_file_system* fs;
+ rtems_rfs_inode_handle inode;
+ rtems_rfs_ino ino;
+ int rc;
+
+ /*
+ * External API so returns -1.
+ */
+ rc = rtems_rfs_fs_open (name, NULL, RTEMS_RFS_FS_FORCE_OPEN, &fs);
+ if (rc < 0)
+ {
+ printf ("rtems-rfs: format: file system open failed: %d: %s\n",
+ errno, strerror (errno));
+ return -1;
+ }
+
+ rc = rtems_rfs_inode_alloc (fs, RTEMS_RFS_ROOT_INO, &ino);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: format: inode allocation failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_fs_close (fs);
+ return rc;
+ }
+
+ if (ino != RTEMS_RFS_ROOT_INO)
+ {
+ printf ("rtems-rfs: format: allocated inode not root ino: %" PRId32 "\n", ino);
+ rtems_rfs_fs_close (fs);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: format: inode open failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_group_bitmap_free (fs, true, ino);
+ rtems_rfs_fs_close (fs);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_initialise (&inode, 0,
+ (RTEMS_RFS_S_IFDIR | RTEMS_RFS_S_IRWXU |
+ RTEMS_RFS_S_IXGRP | RTEMS_RFS_S_IXOTH),
+ 0, 0);
+ if (rc > 0)
+ printf ("rtems-rfs: format: inode initialise failed: %d: %s\n",
+ rc, strerror (rc));
+
+ rc = rtems_rfs_dir_add_entry (fs, &inode, ".", 1, ino);
+ if (rc > 0)
+ printf ("rtems-rfs: format: directory add failed: %d: %s\n",
+ rc, strerror (rc));
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ printf ("rtems-rfs: format: inode close failed: %d: %s\n",
+ rc, strerror (rc));
+
+ rc = rtems_rfs_fs_close (fs);
+ if (rc < 0)
+ printf ("rtems-rfs: format: file system close failed: %d: %s\n",
+ errno, strerror (errno));
+
+ return rc;
+}
+
+int
+rtems_rfs_format (const char* name, const rtems_rfs_format_config* config)
+{
+ rtems_rfs_file_system fs;
+ int group;
+ int rc;
+
+ if (config->verbose)
+ printf ("rtems-rfs: format: %s\n", name);
+
+ memset (&fs, 0, sizeof (rtems_rfs_file_system));
+
+ rtems_chain_initialize_empty (&fs.buffers);
+ rtems_chain_initialize_empty (&fs.release);
+ rtems_chain_initialize_empty (&fs.release_modified);
+ rtems_chain_initialize_empty (&fs.file_shares);
+
+ fs.max_held_buffers = RTEMS_RFS_FS_MAX_HELD_BUFFERS;
+
+ fs.release_count = 0;
+ fs.release_modified_count = 0;
+
+ fs.flags = RTEMS_RFS_FS_NO_LOCAL_CACHE;
+
+ /*
+ * Open the buffer interface.
+ */
+ rc = rtems_rfs_buffer_open (name, &fs);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: format: buffer open failed: %d: %s\n",
+ rc, strerror (rc));
+ return -1;
+ }
+
+ /*
+ * Check the media.
+ */
+ if (rtems_rfs_fs_media_block_size (&fs) == 0)
+ {
+ printf ("rtems-rfs: media block is invalid: %" PRIu32 "\n",
+ rtems_rfs_fs_media_block_size (&fs));
+ return -1;
+ }
+
+ /*
+ * Check the configuration data.
+ */
+ if (!rtems_rfs_check_config (&fs, config))
+ return -1;
+
+ if (config->verbose)
+ {
+ printf ("rtems-rfs: format: media size = %" PRIu64 "\n",
+ rtems_rfs_fs_media_size (&fs));
+ printf ("rtems-rfs: format: media blocks = %" PRIu32 "\n",
+ rtems_rfs_fs_media_blocks (&fs));
+ printf ("rtems-rfs: format: media block size = %" PRIu32 "\n",
+ rtems_rfs_fs_media_block_size (&fs));
+ printf ("rtems-rfs: format: size = %" PRIu64 "\n",
+ rtems_rfs_fs_size (&fs));
+ printf ("rtems-rfs: format: blocks = %zu\n",
+ rtems_rfs_fs_blocks (&fs));
+ printf ("rtems-rfs: format: block size = %zu\n",
+ rtems_rfs_fs_block_size (&fs));
+ printf ("rtems-rfs: format: bits per block = %u\n",
+ rtems_rfs_bits_per_block (&fs));
+ printf ("rtems-rfs: format: inode size = %zu\n", RTEMS_RFS_INODE_SIZE);
+ printf ("rtems-rfs: format: inodes = %zu (%d.%d%%)\n",
+ fs.group_inodes * fs.group_count,
+ rtems_rfs_inode_overhead (&fs) / 10,
+ rtems_rfs_inode_overhead (&fs) % 10);
+ printf ("rtems-rfs: format: groups = %u\n", fs.group_count);
+ printf ("rtems-rfs: format: group blocks = %zu\n", fs.group_blocks);
+ printf ("rtems-rfs: format: group inodes = %zu\n", fs.group_inodes);
+ }
+
+ rc = rtems_rfs_buffer_setblksize (&fs, rtems_rfs_fs_block_size (&fs));
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: format: setting block size failed: %d: %s\n",
+ rc, strerror (rc));
+ return -1;
+ }
+
+ if (!rtems_rfs_write_superblock (&fs))
+ {
+ printf ("rtems-rfs: format: superblock write failed\n");
+ return -1;
+ }
+
+ for (group = 0; group < fs.group_count; group++)
+ if (!rtems_rfs_write_group (&fs, group,
+ config->initialise_inodes, config->verbose))
+ return -1;
+
+ if (config->verbose)
+ printf ("\n");
+
+ rc = rtems_rfs_buffer_close (&fs);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: format: buffer close failed: %d: %s\n",
+ rc, strerror (rc));
+ return -1;
+ }
+
+ rc = rtems_rfs_write_root_dir (name);
+ if (rc > 0)
+ {
+ printf ("rtems-rfs: format: writing root dir failed: %d: %s\n",
+ rc, strerror (rc));
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-format.h b/cpukit/libfs/src/rfs/rtems-rfs-format.h
new file mode 100644
index 0000000000..48d65c9165
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-format.h
@@ -0,0 +1,90 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Format.
+ *
+ * This function lets you format a disk in the RFS format.
+ */
+
+#if !defined (_RTEMS_RFS_FORMAT_H_)
+#define _RTEMS_RFS_FORMAT_H_
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+/**
+ * RFS File System Configuration data used to format the file system. For
+ * default values leave the field set to 0.
+ */
+typedef struct _rtems_rfs_format_config
+{
+ /**
+ * The size of a block.
+ */
+ size_t block_size;
+
+ /**
+ * The number of blocks in a group.
+ */
+ size_t group_blocks;
+
+ /**
+ * The number of inodes in a group.
+ */
+ size_t group_inodes;
+
+ /**
+ * The percentage overhead allocated to inodes.
+ */
+ int inode_overhead;
+
+ /**
+ * The maximum length of a name.
+ */
+ size_t max_name_length;
+
+ /**
+ * Initialise the inode tables to all ones.
+ */
+ bool initialise_inodes;
+
+ /**
+ * Is the format verbose.
+ */
+ bool verbose;
+
+} rtems_rfs_format_config;
+
+/**
+ * RFS Format command.
+ *
+ * @param name The device name to format.
+ * @param config Pointer to a configuration table.
+ * @retval -1 Error. See errno.
+ * @retval 0 No error. Format successful.
+ */
+int rtems_rfs_format (const char* name, const rtems_rfs_format_config* config);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-group.c b/cpukit/libfs/src/rfs/rtems-rfs-group.c
new file mode 100644
index 0000000000..a6c2fce1ba
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-group.c
@@ -0,0 +1,361 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Group Routines.
+ *
+ * These functions open and close a group as well as manage bit allocations
+ * within a group.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-group.h>
+
+int
+rtems_rfs_group_open (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_block base,
+ size_t size,
+ size_t inodes,
+ rtems_rfs_group* group)
+{
+ int rc;
+
+ if (base >= rtems_rfs_fs_blocks (fs))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_OPEN))
+ printf ("rtems-rfs: group-open: base outside file system range: %d: %s\n",
+ EIO, strerror (EIO));
+ return EIO;
+ }
+
+ if ((base + size) >= rtems_rfs_fs_blocks (fs))
+ size = rtems_rfs_fs_blocks (fs) - base;
+
+ /*
+ * Limit the inodes to the same size as the blocks. This is what the
+ * format does and if this is not done the accounting of inodes does
+ * not work. If we are so pushed for inodes that this makes a difference
+ * the format configuration needs reviewing.
+ */
+ if (inodes > size)
+ inodes = size;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_OPEN))
+ printf ("rtems-rfs: group-open: base=%" PRId32 ", blocks=%zd inodes=%zd\n",
+ base, size, inodes);
+
+ group->base = base;
+ group->size = size;
+
+ rc = rtems_rfs_buffer_handle_open (fs, &group->block_bitmap_buffer);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_OPEN))
+ printf ("rtems-rfs: group-open: could not open block bitmap handle: %d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ rc = rtems_rfs_bitmap_open (&group->block_bitmap, fs,
+ &group->block_bitmap_buffer, size,
+ group->base + RTEMS_RFS_GROUP_BLOCK_BITMAP_BLOCK);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &group->block_bitmap_buffer);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_OPEN))
+ printf ("rtems-rfs: group-open: could not open block bitmap: %d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &group->inode_bitmap_buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_bitmap_close (&group->block_bitmap);
+ rtems_rfs_buffer_handle_close (fs, &group->block_bitmap_buffer);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_OPEN))
+ printf ("rtems-rfs: group-open: could not open inode bitmap handle: %d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ rc = rtems_rfs_bitmap_open (&group->inode_bitmap, fs,
+ &group->inode_bitmap_buffer, inodes,
+ group->base + RTEMS_RFS_GROUP_INODE_BITMAP_BLOCK);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &group->inode_bitmap_buffer);
+ rtems_rfs_bitmap_close (&group->block_bitmap);
+ rtems_rfs_buffer_handle_close (fs, &group->block_bitmap_buffer);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_OPEN))
+ printf ("rtems-rfs: group-open: could not open inode bitmap: %d: %s\n",
+ rc, strerror (rc));
+ return rc;
+ }
+
+ if (rtems_rfs_fs_release_bitmaps (fs))
+ {
+ rtems_rfs_bitmap_release_buffer (fs, &group->block_bitmap);
+ rtems_rfs_bitmap_release_buffer (fs, &group->inode_bitmap);
+ }
+
+ return 0;
+}
+
+int
+rtems_rfs_group_close (rtems_rfs_file_system* fs, rtems_rfs_group* group)
+{
+ int result = 0;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_CLOSE))
+ printf ("rtems-rfs: group-close: base=%" PRId32 "\n", group->base);
+
+ /*
+ * We need to close as much as possible and also return any error if one
+ * occurs but this may result in one even more important error being lost but
+ * we cannot OR the errors together so this is a reasonable compromise.
+ */
+ rc = rtems_rfs_bitmap_close (&group->inode_bitmap);
+ if (rc > 0)
+ result = rc;
+ rc = rtems_rfs_buffer_handle_close (fs, &group->inode_bitmap_buffer);
+ if (rc > 0)
+ result = rc;
+ rc = rtems_rfs_bitmap_close (&group->block_bitmap);
+ if (rc > 0)
+ result = rc;
+ rc = rtems_rfs_buffer_handle_close (fs, &group->block_bitmap_buffer);
+ if (rc > 0)
+ result = rc;
+
+ return result;
+}
+
+int
+rtems_rfs_group_bitmap_alloc (rtems_rfs_file_system* fs,
+ rtems_rfs_bitmap_bit goal,
+ bool inode,
+ rtems_rfs_bitmap_bit* result)
+{
+ int group_start;
+ size_t size;
+ rtems_rfs_bitmap_bit bit;
+ int offset;
+ bool updown;
+ int direction;
+
+ if (inode)
+ {
+ size = fs->group_inodes;
+ goal -= RTEMS_RFS_ROOT_INO;
+ }
+ else
+ size = fs->group_blocks;
+
+ group_start = goal / size;
+ bit = (rtems_rfs_bitmap_bit) (goal % size);
+ offset = 0;
+ updown = true;
+ direction = 1;
+
+ /*
+ * Try the goal group first and if that group fails try the groups either
+ * side until the whole file system has be tried.
+ */
+ while (true)
+ {
+ rtems_rfs_bitmap_control* bitmap;
+ int group;
+ bool allocated = false;
+ int rc;
+
+ /*
+ * We can start at any location and we move out from that point in each
+ * direction. The offset grows until we find a free bit or we hit an end.
+ */
+ group = group_start + (direction * offset);
+ if (offset)
+ bit = direction > 0 ? 0 : size - 1;
+
+ /*
+ * If we are still looking up and down and if the group is out of range we
+ * have reached one end. Stopping looking up and down and just move in the
+ * one direction one group at a time.
+ */
+ if ((group < 0) || (group >= fs->group_count))
+ {
+ if (!updown)
+ break;
+ direction = direction > 0 ? -1 : 1;
+ updown = false;
+ continue;
+ }
+
+ if (inode)
+ bitmap = &fs->groups[group].inode_bitmap;
+ else
+ bitmap = &fs->groups[group].block_bitmap;
+
+ rc = rtems_rfs_bitmap_map_alloc (bitmap, bit, &allocated, &bit);
+ if (rc > 0)
+ return rc;
+
+ if (rtems_rfs_fs_release_bitmaps (fs))
+ rtems_rfs_bitmap_release_buffer (fs, bitmap);
+
+ if (allocated)
+ {
+ if (inode)
+ *result = rtems_rfs_group_inode (fs, group, bit);
+ else
+ *result = rtems_rfs_group_block (&fs->groups[group], bit);
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_BITMAPS))
+ printf ("rtems-rfs: group-bitmap-alloc: %s allocated: %" PRId32 "\n",
+ inode ? "inode" : "block", *result);
+ return 0;
+ }
+
+ if (updown)
+ direction = direction > 0 ? -1 : 1;
+
+ offset++;
+ }
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_BITMAPS))
+ printf ("rtems-rfs: group-bitmap-alloc: no blocks available\n");
+
+ return ENOSPC;
+}
+
+int
+rtems_rfs_group_bitmap_free (rtems_rfs_file_system* fs,
+ bool inode,
+ rtems_rfs_bitmap_bit no)
+{
+ rtems_rfs_bitmap_control* bitmap;
+ unsigned int group;
+ rtems_rfs_bitmap_bit bit;
+ size_t size;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_BITMAPS))
+ printf ("rtems-rfs: group-bitmap-free: %s free: %" PRId32 "\n",
+ inode ? "inode" : "block", no);
+
+ if (inode)
+ {
+ no -= RTEMS_RFS_ROOT_INO;
+ size = fs->group_inodes;
+ }
+ else
+ {
+ no -= RTEMS_RFS_SUPERBLOCK_SIZE;
+ size = fs->group_blocks;
+ }
+
+ group = no / size;
+ bit = (rtems_rfs_bitmap_bit) (no % size);
+
+ if (inode)
+ bitmap = &fs->groups[group].inode_bitmap;
+ else
+ bitmap = &fs->groups[group].block_bitmap;
+
+ rc = rtems_rfs_bitmap_map_clear (bitmap, bit);
+
+ rtems_rfs_bitmap_release_buffer (fs, bitmap);
+
+ return rc;
+}
+
+int
+rtems_rfs_group_bitmap_test (rtems_rfs_file_system* fs,
+ bool inode,
+ rtems_rfs_bitmap_bit no,
+ bool* state)
+{
+ rtems_rfs_bitmap_control* bitmap;
+ unsigned int group;
+ rtems_rfs_bitmap_bit bit;
+ size_t size;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_GROUP_BITMAPS))
+ printf ("rtems-rfs: group-bitmap-test: %s test: %" PRId32 "\n",
+ inode ? "inode" : "block", no);
+
+ if (inode)
+ {
+ if ((no < RTEMS_RFS_ROOT_INO) || (no > rtems_rfs_fs_inodes (fs)))
+ return EINVAL;
+ no -= RTEMS_RFS_ROOT_INO;
+ size = fs->group_inodes;
+ }
+ else
+ {
+ if (no >= rtems_rfs_fs_blocks (fs))
+ return EINVAL;
+ size = fs->group_blocks;
+ }
+
+ group = no / size;
+ bit = (rtems_rfs_bitmap_bit) (no % size);
+
+ if (inode)
+ bitmap = &fs->groups[group].inode_bitmap;
+ else
+ bitmap = &fs->groups[group].block_bitmap;
+
+ rc = rtems_rfs_bitmap_map_test (bitmap, bit, state);
+
+ rtems_rfs_bitmap_release_buffer (fs, bitmap);
+
+ return rc;
+}
+
+int
+rtems_rfs_group_usage (rtems_rfs_file_system* fs,
+ size_t* blocks,
+ size_t* inodes)
+{
+ int g;
+
+ *blocks = 0;
+ *inodes = 0;
+
+ for (g = 0; g < fs->group_count; g++)
+ {
+ rtems_rfs_group* group = &fs->groups[g];
+ *blocks +=
+ rtems_rfs_bitmap_map_size(&group->block_bitmap) -
+ rtems_rfs_bitmap_map_free (&group->block_bitmap);
+ *inodes +=
+ rtems_rfs_bitmap_map_size (&group->inode_bitmap) -
+ rtems_rfs_bitmap_map_free (&group->inode_bitmap);
+ }
+
+ if (*blocks > rtems_rfs_fs_blocks (fs))
+ *blocks = rtems_rfs_fs_blocks (fs);
+ if (*inodes > rtems_rfs_fs_inodes (fs))
+ *inodes = rtems_rfs_fs_inodes (fs);
+
+ return 0;
+}
+
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-group.h b/cpukit/libfs/src/rfs/rtems-rfs-group.h
new file mode 100644
index 0000000000..1ec0107f89
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-group.h
@@ -0,0 +1,163 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Group Management.
+ *
+ * These functions manage the groups used in the file system.
+ */
+
+#if !defined (_RTEMS_RFS_GROUP_H_)
+#define _RTEMS_RFS_GROUP_H_
+
+#include <rtems/rfs/rtems-rfs-trace.h>
+#include <rtems/rfs/rtems-rfs-bitmaps.h>
+#include <rtems/rfs/rtems-rfs-buffer.h>
+
+/**
+ * Block allocations for a group on disk.
+ */
+#define RTEMS_RFS_GROUP_BLOCK_BITMAP_BLOCK (0)
+#define RTEMS_RFS_GROUP_INODE_BITMAP_BLOCK (1)
+#define RTEMS_RFS_GROUP_INODE_BLOCK (2)
+
+/**
+ * A group is a selection of blocks on the disk. Typically the number of blocks
+ * in a group is determined by the number of bits a block holds. This makes the
+ * bit allocator for blocks in the group simpler plus is allows a simple way to
+ * localise access to files and directories.
+ */
+typedef struct _rtems_rfs_group
+{
+ /**
+ * Base block number.
+ */
+ rtems_rfs_buffer_block base;
+
+ /**
+ * The number of blocks in the group. Groups may be different sizes.
+ */
+ size_t size;
+
+ /**
+ * The block bitmap control.
+ */
+ rtems_rfs_bitmap_control block_bitmap;
+
+ /**
+ * The handle to the block bitmap buffer.
+ */
+ rtems_rfs_buffer_handle block_bitmap_buffer;
+
+ /**
+ * The inode bitmap control.
+ */
+ rtems_rfs_bitmap_control inode_bitmap;
+
+ /**
+ * The handle to the inode bitmap buffer.
+ */
+ rtems_rfs_buffer_handle inode_bitmap_buffer;
+
+} rtems_rfs_group;
+
+/**
+ * Return the disk's block for a block in a group.
+ */
+#define rtems_rfs_group_block(_g, _b) (((_g)->base) + (_b))
+
+/**
+ * Return the file system inode for a inode in a group.
+ */
+#define rtems_rfs_group_inode(_f, _g, _i) \
+ (((_f)->group_inodes * (_g)) + (_i) + RTEMS_RFS_ROOT_INO)
+
+/**
+ * Open a group. Allocate all the resources including the bitmaps.
+ *
+ * @param fs The file system.
+ * @param base The base block number.
+ * @param size The number of blocks in the group.
+ * @param group Reference to the group to open.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_group_open (rtems_rfs_file_system* fs,
+ rtems_rfs_buffer_block base,
+ size_t size,
+ size_t inodes,
+ rtems_rfs_group* group);
+
+/**
+ * Close a group. Release all resources the group holds.
+ *
+ * @param fs The file system.
+ * @param group The group to close.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_group_close (rtems_rfs_file_system* fs,
+ rtems_rfs_group* group);
+
+/**
+ * Allocate an inode or block. The groups are searched to find the next
+ * available inode or block.
+ *
+ * @param fs The file system data.
+ * @param goal The goal to seed the bitmap search.
+ * @param inode If true allocate an inode else allocate a block.
+ * @param result The allocated bit in the bitmap.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_group_bitmap_alloc (rtems_rfs_file_system* fs,
+ rtems_rfs_bitmap_bit goal,
+ bool inode,
+ rtems_rfs_bitmap_bit* result);
+
+/**
+ * Free the group allocated bit.
+ *
+ * @param fs The file system data.
+ * @param inode If true the number to free is an inode else it is a block.
+ * @param block The inode or block number to free.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_group_bitmap_free (rtems_rfs_file_system* fs,
+ bool inode,
+ rtems_rfs_bitmap_bit no);
+
+/**
+ * Test the group allocated bit.
+ *
+ * @param fs The file system data.
+ * @param inode If true the number to free is an inode else it is a block.
+ * @param block The inode or block number to free.
+ * @param state Return the state of the bit.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_group_bitmap_test (rtems_rfs_file_system* fs,
+ bool inode,
+ rtems_rfs_bitmap_bit no,
+ bool* state);
+
+/**
+ * Determine the number of blocks and inodes used.
+ *
+ * @param fs The file system data.
+ * @param blocks The number of blocks used.
+ * @param inodes The number of inodes used.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_group_usage (rtems_rfs_file_system* fs,
+ size_t* blocks,
+ size_t* inodes);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-inode.c b/cpukit/libfs/src/rfs/rtems-rfs-inode.c
new file mode 100644
index 0000000000..ab3f4b7e65
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-inode.c
@@ -0,0 +1,402 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Inode Routines.
+ *
+ * These functions manage inodes in the RFS file system. An inode is part of a
+ * block that reside after the bitmaps in the group.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-block.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+#include <rtems/rfs/rtems-rfs-dir.h>
+
+int
+rtems_rfs_inode_alloc (rtems_rfs_file_system* fs,
+ rtems_rfs_bitmap_bit goal,
+ rtems_rfs_ino* ino)
+{
+ rtems_rfs_bitmap_bit bit;
+ int rc;
+ rc = rtems_rfs_group_bitmap_alloc (fs, goal, true, &bit);
+ *ino = bit;
+ return rc;
+}
+
+int
+rtems_rfs_inode_free (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino)
+{
+ rtems_rfs_bitmap_bit bit;
+ bit = ino;
+ return rtems_rfs_group_bitmap_free (fs, true, bit);
+}
+
+int
+rtems_rfs_inode_open (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino,
+ rtems_rfs_inode_handle* handle,
+ bool load)
+{
+ int group;
+ int gino;
+ int index;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_OPEN))
+ printf ("rtems-rfs: inode-open: ino: %" PRIu32 "\n", ino);
+
+ if (ino == RTEMS_RFS_EMPTY_INO)
+ return EINVAL;
+
+ if ((ino - RTEMS_RFS_ROOT_INO) > rtems_rfs_fs_inodes (fs))
+ return EINVAL;
+
+ handle->ino = ino;
+ handle->node = NULL;
+ handle->loads = 0;
+
+ gino = ino - RTEMS_RFS_ROOT_INO;
+ group = gino / fs->group_inodes;
+ gino = gino % fs->group_inodes;
+ index = (gino / fs->inodes_per_block) + RTEMS_RFS_GROUP_INODE_BLOCK;
+
+ handle->offset = gino % fs->inodes_per_block;
+ handle->block = rtems_rfs_group_block (&fs->groups[group], index);
+
+ rc = rtems_rfs_buffer_handle_open (fs, &handle->buffer);
+ if ((rc == 0) && load)
+ rc = rtems_rfs_inode_load (fs, handle);
+ return rc;
+}
+
+int
+rtems_rfs_inode_close (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle)
+{
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_CLOSE))
+ printf ("rtems-rfs: inode-close: ino: %" PRIu32 "\n", handle->ino);
+
+ rc = rtems_rfs_inode_unload (fs, handle, true);
+
+ if ((rc == 0) && (handle->loads > 0))
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_CLOSE))
+ printf ("rtems-rfs: inode-close: bad loads number: %d\n",
+ handle->loads);
+ rc = EIO;
+ }
+
+ handle->ino = 0;
+ return rc;
+}
+
+int
+rtems_rfs_inode_load (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle)
+{
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_LOAD))
+ printf ("rtems-rfs: inode-load: ino=%" PRIu32 " loads=%i loaded=%s\n",
+ handle->ino, handle->loads,
+ rtems_rfs_inode_is_loaded (handle) ? "yes" : "no");
+
+ /*
+ * An inode does not move so once loaded no need to do again.
+ */
+
+ if (!rtems_rfs_inode_is_loaded (handle))
+ {
+ int rc;
+
+ rc = rtems_rfs_buffer_handle_request (fs,&handle->buffer,
+ handle->block, true);
+ if (rc > 0)
+ return rc;
+
+ handle->node = rtems_rfs_buffer_data (&handle->buffer);
+ handle->node += handle->offset;
+ }
+
+ handle->loads++;
+
+ return 0;
+}
+
+int
+rtems_rfs_inode_unload (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle,
+ bool update_ctime)
+{
+ int rc = 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_UNLOAD))
+ printf ("rtems-rfs: inode-unload: ino=%" PRIu32 " loads=%i loaded=%s\n",
+ handle->ino, handle->loads,
+ rtems_rfs_inode_is_loaded (handle) ? "yes" : "no");
+
+ if (rtems_rfs_inode_is_loaded (handle))
+ {
+ if (handle->loads == 0)
+ return EIO;
+
+ handle->loads--;
+
+ if (handle->loads == 0)
+ {
+ /*
+ * If the buffer is dirty it will be release. Also set the ctime.
+ */
+ if (rtems_rfs_buffer_dirty (&handle->buffer) && update_ctime)
+ rtems_rfs_inode_set_ctime (handle, time (NULL));
+ rc = rtems_rfs_buffer_handle_release (fs, &handle->buffer);
+ handle->node = NULL;
+ }
+ }
+
+ return rc;
+}
+
+int
+rtems_rfs_inode_create (rtems_rfs_file_system* fs,
+ rtems_rfs_ino parent,
+ const char* name,
+ size_t length,
+ uint16_t mode,
+ uint16_t links,
+ uid_t uid,
+ gid_t gid,
+ rtems_rfs_ino* ino)
+{
+ rtems_rfs_inode_handle parent_inode;
+ rtems_rfs_inode_handle inode;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_CREATE))
+ {
+ const char* type = "unknown";
+ int c;
+ if (RTEMS_RFS_S_ISDIR (mode))
+ type = "dir";
+ else if (RTEMS_RFS_S_ISCHR (mode))
+ type = "char";
+ else if (RTEMS_RFS_S_ISBLK (mode))
+ type = "block";
+ else if (RTEMS_RFS_S_ISREG (mode))
+ type = "file";
+ else if (RTEMS_RFS_S_ISLNK (mode))
+ type = "link";
+ printf("rtems-rfs: inode-create: parent:%" PRIu32 " name:", parent);
+ for (c = 0; c < length; c++)
+ printf ("%c", name[c]);
+ printf (" type:%s mode:%04x (%03o)\n", type, mode, mode & ((1 << 10) - 1));
+ }
+
+ /*
+ * The file type is field within the mode. Check we have a sane mode set.
+ */
+ switch (mode & RTEMS_RFS_S_IFMT)
+ {
+ case RTEMS_RFS_S_IFDIR:
+ case RTEMS_RFS_S_IFCHR:
+ case RTEMS_RFS_S_IFBLK:
+ case RTEMS_RFS_S_IFREG:
+ case RTEMS_RFS_S_IFLNK:
+ break;
+ default:
+ return EINVAL;
+ }
+
+ rc = rtems_rfs_inode_alloc (fs, parent, ino);
+ if (rc > 0)
+ return rc;
+
+ rc = rtems_rfs_inode_open (fs, *ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_free (fs, *ino);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_initialise (&inode, links, mode, uid, gid);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_inode_free (fs, *ino);
+ return rc;
+ }
+
+ /*
+ * Only handle the specifics of a directory. Let caller handle the others.
+ *
+ * The inode delete will free the inode.
+ */
+ if (RTEMS_RFS_S_ISDIR (mode))
+ {
+ rc = rtems_rfs_dir_add_entry (fs, &inode, ".", 1, *ino);
+ if (rc == 0)
+ rc = rtems_rfs_dir_add_entry (fs, &inode, "..", 2, parent);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_delete (fs, &inode);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+ }
+
+ rc = rtems_rfs_inode_open (fs, parent, &parent_inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_delete (fs, &inode);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_dir_add_entry (fs, &parent_inode, name, length, *ino);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_delete (fs, &inode);
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_inode_close (fs, &parent_inode);
+ return rc;
+ }
+
+ /*
+ * If the node is a directory update the parent link count as the
+ * new directory has the '..' link that points to the parent.
+ */
+ if (RTEMS_RFS_S_ISDIR (mode))
+ rtems_rfs_inode_set_links (&parent_inode,
+ rtems_rfs_inode_get_links (&parent_inode) + 1);
+
+ rc = rtems_rfs_inode_close (fs, &parent_inode);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_delete (fs, &inode);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_free (fs, *ino);
+ return rc;
+ }
+
+ return 0;
+}
+
+int
+rtems_rfs_inode_delete (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle)
+{
+ int rc = 0;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_DELETE))
+ printf("rtems-rfs: inode-delete: ino:%" PRIu32 " loaded:%s\n",
+ rtems_rfs_inode_ino (handle),
+ rtems_rfs_inode_is_loaded (handle) ? "yes" : "no");
+
+ if (rtems_rfs_inode_is_loaded (handle))
+ {
+ rtems_rfs_block_map map;
+
+ /*
+ * Free the ino number.
+ */
+ rc = rtems_rfs_inode_free (fs, handle->ino);
+ if (rc > 0)
+ return rc;
+
+ /*
+ * Free the blocks the inode may have attached.
+ */
+ rc = rtems_rfs_block_map_open (fs, handle, &map);
+ if (rc == 0)
+ {
+ int rrc;
+ rrc = rtems_rfs_block_map_free_all (fs, &map);
+ rc = rtems_rfs_block_map_close (fs, &map);
+ if (rc > 0)
+ rrc = rc;
+ memset (handle->node, 0xff, RTEMS_RFS_INODE_SIZE);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+ /*
+ * Do the release here to avoid the ctime field being set on a
+ * close. Also if there loads is greater then one then other loads
+ * active. Forcing the loads count to 0.
+ */
+ rc = rtems_rfs_buffer_handle_release (fs, &handle->buffer);
+ handle->loads = 0;
+ handle->node = NULL;
+ }
+ }
+ return rc;
+}
+
+int
+rtems_rfs_inode_initialise (rtems_rfs_inode_handle* handle,
+ uint16_t links,
+ uint16_t mode,
+ uid_t uid,
+ gid_t gid)
+{
+ int b;
+ rtems_rfs_inode_set_links (handle, links);
+ rtems_rfs_inode_set_flags (handle, 0);
+ rtems_rfs_inode_set_mode (handle, mode);
+ rtems_rfs_inode_set_uid_gid (handle, uid, gid);
+ rtems_rfs_inode_set_block_offset (handle, 0);
+ rtems_rfs_inode_set_block_count (handle, 0);
+ for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
+ rtems_rfs_inode_set_block (handle, b, 0);
+ rtems_rfs_inode_set_last_map_block (handle, 0);
+ rtems_rfs_inode_set_last_data_block (handle, 0);
+ return rtems_rfs_inode_time_stamp_now (handle, true, true);
+}
+
+int
+rtems_rfs_inode_time_stamp_now (rtems_rfs_inode_handle* handle,
+ bool atime,
+ bool mtime)
+{
+ time_t now;
+ if (!rtems_rfs_inode_is_loaded (handle))
+ return ENXIO;
+ now = time (NULL);
+ if (atime)
+ rtems_rfs_inode_set_atime (handle, now);
+ if (mtime)
+ rtems_rfs_inode_set_mtime (handle, now);
+ return 0;
+}
+
+rtems_rfs_pos
+rtems_rfs_inode_get_size (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle)
+{
+ rtems_rfs_block_size size;
+ size.count = rtems_rfs_inode_get_block_count (handle);
+ size.offset = rtems_rfs_inode_get_block_offset (handle);
+ return rtems_rfs_block_get_size (fs, &size);
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-inode.h b/cpukit/libfs/src/rfs/rtems-rfs-inode.h
new file mode 100644
index 0000000000..5ac2868859
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-inode.h
@@ -0,0 +1,693 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Information Node.
+ *
+ * The information nodes hold the data about all nodes in the file system.
+ */
+
+#if !defined (_RTEMS_RFS_INODE_H_)
+#define _RTEMS_RFS_INODE_H_
+
+#include <sys/stat.h>
+
+#include <rtems/rfs/rtems-rfs-data.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+
+/**
+ * The RFS mode definitions. Currently map to the C library ones.
+ */
+#define RTEMS_RFS_S_ISUID S_ISUID /**< Set user id on execution */
+#define RTEMS_RFS_S_ISGID S_ISGID /**< Set group id on execution */
+#define RTEMS_RFS_S_ISVTX S_ISVTX /**< Save swapped text even after use */
+#define RTEMS_RFS_S_IREAD S_IREAD /**< Read permission, owner */
+#define RTEMS_RFS_S_IWRITE S_IWRITE /**< Write permission, owner */
+#define RTEMS_RFS_S_IEXEC S_IEXEC /**< Execute/search permission, owner */
+#define RTEMS_RFS_S_ENFMT S_ENFMT /**< Enforcement-mode locking */
+#define RTEMS_RFS_S_IFMT S_IFMT /**< Type of file */
+#define RTEMS_RFS_S_IFDIR S_IFDIR /**< Directory */
+#define RTEMS_RFS_S_IFCHR S_IFCHR /**< Character special */
+#define RTEMS_RFS_S_IFBLK S_IFBLK /**< Block special */
+#define RTEMS_RFS_S_IFREG S_IFREG /**< Regular */
+#define RTEMS_RFS_S_IFLNK S_IFLNK /**< Symbolic link */
+#define RTEMS_RFS_S_IFSOCK S_IFSOCK /**< Socket */
+#define RTEMS_RFS_S_IFIFO S_IFIFO /**< Fifo */
+#define RTEMS_RFS_S_IRWXU S_IRWXU
+#define RTEMS_RFS_S_IRUSR S_IRUSR /**< Read permission, owner */
+#define RTEMS_RFS_S_IWUSR S_IWUSR /**< Write permission, owner */
+#define RTEMS_RFS_S_IXUSR S_IXUSR /**< Execute/search permission, owner */
+#define RTEMS_RFS_S_IRWXG S_IRWXG
+#define RTEMS_RFS_S_IRGRP S_IRGRP /**< Read permission, group */
+#define RTEMS_RFS_S_IWGRP S_IWGRP /**< Write permission, grougroup */
+#define RTEMS_RFS_S_IXGRP S_IXGRP /**< Execute/search permission, group */
+#define RTEMS_RFS_S_IRWXO S_IRWXO
+#define RTEMS_RFS_S_IROTH S_IROTH /**< Read permission, other */
+#define RTEMS_RFS_S_IWOTH S_IWOTH /**< Write permission, other */
+#define RTEMS_RFS_S_IXOTH S_IXOTH /**< Execute/search permission, other */
+
+#define RTEMS_RFS_S_ISBLK(m) S_ISBLK(m)
+#define RTEMS_RFS_S_ISCHR(m) S_ISCHR(m)
+#define RTEMS_RFS_S_ISDIR(m) S_ISDIR(m)
+#define RTEMS_RFS_S_ISFIFO(m) S_ISFIFO(m)
+#define RTEMS_RFS_S_ISREG(m) S_ISREG(m)
+#define RTEMS_RFS_S_ISLNK(m) S_ISLNK(m)
+#define RTEMS_RFS_S_ISSOCK(m) S_ISSOCK(m)
+
+/**
+ * Permissions of a symlink.
+ */
+#define RTEMS_RFS_S_SYMLINK \
+ RTEMS_RFS_S_IFLNK | RTEMS_RFS_S_IRWXU | RTEMS_RFS_S_IRWXG | RTEMS_RFS_S_IRWXO
+
+/**
+ * The inode number or ino.
+ */
+typedef uint32_t rtems_rfs_ino;
+
+/**
+ * The time in the file system.
+ */
+typedef uint32_t rtems_rfs_time;
+
+/**
+ * The size of a block value on disk. This include the inodes and indirect
+ * tables.
+ */
+typedef uint32_t rtems_rfs_inode_block;
+
+/**
+ * The size of the data name field in the inode.
+ */
+#define RTEMS_RFS_INODE_DATA_NAME_SIZE \
+ (RTEMS_RFS_INODE_BLOCKS * sizeof (rtems_rfs_inode_block))
+
+/**
+ * The inode.
+ */
+typedef struct _rtems_rfs_inode
+{
+ /**
+ * The number of links to the inode.
+ */
+ uint16_t links;
+
+ /**
+ * The mode of the node.
+ */
+ uint16_t mode;
+
+ /**
+ * The owner of the node.
+ */
+ uint32_t owner;
+
+ /**
+ * Reserved.
+ */
+ uint16_t flags;
+
+ /**
+ * Amount of data held in the last block data.
+ */
+ uint16_t block_offset;
+
+ /**
+ * Number of blocks held by this file.
+ */
+ uint32_t block_count;
+
+ /**
+ * The access time. The last time the file was read.
+ */
+ rtems_rfs_time atime;
+
+ /**
+ * The modified time. The last time the file was written too.
+ */
+ rtems_rfs_time mtime;
+
+ /**
+ * The change time. The last time the inode was written too.
+ */
+ rtems_rfs_time ctime;
+
+ /**
+ * Blocks. These are the block numbers used by the node or table of
+ * nodes. The flags indicate the mode the blocks are being held in. In the
+ * direct table mode the blocks are entries in this table. In the indirect
+ * mode the blocks point to blocks that hold the block numbers. The data can
+ * also be a name if it fits. For example a symbolic link.
+ */
+ union
+ {
+ rtems_rfs_inode_block blocks[RTEMS_RFS_INODE_BLOCKS];
+ uint8_t name[RTEMS_RFS_INODE_DATA_NAME_SIZE];
+ } data;
+
+ /**
+ * The last block map block. Used as the goal when allocating a new block for
+ * use in the map.
+ */
+ rtems_rfs_inode_block last_map_block;
+
+ /**
+ * The last data block. Used as the goal when allocating a new block.
+ */
+ rtems_rfs_inode_block last_data_block;
+
+} rtems_rfs_inode;
+
+/**
+ * The size of an inode.
+ */
+#define RTEMS_RFS_INODE_SIZE (sizeof (rtems_rfs_inode))
+
+/**
+ * RFS Inode Handle.
+ */
+typedef struct _rtems_rfs_inode_handle
+{
+ /**
+ * Handles can be linked as a list for easy processing.
+ */
+ rtems_chain_node link;
+
+ /**
+ * The ino for this handle.
+ */
+ rtems_rfs_ino ino;
+
+ /**
+ * The pointer to the inode.
+ */
+ rtems_rfs_inode* node;
+
+ /**
+ * The buffer that contains this inode.
+ */
+ rtems_rfs_buffer_handle buffer;
+
+ /**
+ * The block number that holds the inode.
+ */
+ rtems_rfs_buffer_block block;
+
+ /**
+ * The offset into the block for the inode.
+ */
+ int offset;
+
+ /**
+ * Number of load requests.
+ */
+ int loads;
+
+} rtems_rfs_inode_handle;
+
+/**
+ * Is the inode loaded ?
+ */
+#define rtems_rfs_inode_is_loaded(_h) ((_h)->node)
+
+/**
+ * Get the inode ino for a handle.
+ */
+#define rtems_rfs_inode_ino(_h) ((_h)->ino)
+
+/**
+ * Get the link count.
+ *
+ * @param handle The inode handle.
+ * @return uint16_t The link count.
+ */
+static inline uint16_t
+rtems_rfs_inode_get_links (rtems_rfs_inode_handle* handle)
+{
+ uint16_t links;
+ links = rtems_rfs_read_u16 (&handle->node->links);
+ if (links == 0xffff)
+ links = 0;
+ return links;
+}
+
+/**
+ * Set the link count.
+ *
+ * @param handle The inode handle.
+ * @prarm links The links.
+ */
+static inline void
+rtems_rfs_inode_set_links (rtems_rfs_inode_handle* handle, uint16_t links)
+{
+ rtems_rfs_write_u16 (&handle->node->links, links);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the flags.
+ *
+ * @param handle The inode handle.
+ * @return uint16_t The flags.
+ */
+static inline uint16_t
+rtems_rfs_inode_get_flags (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u16 (&handle->node->flags);
+}
+
+/**
+ * Set the flags.
+ *
+ * @param handle The inode handle.
+ * @prarm flags The flags.
+ */
+static inline void
+rtems_rfs_inode_set_flags (rtems_rfs_inode_handle* handle, uint16_t flags)
+{
+ rtems_rfs_write_u16 (&handle->node->flags, flags);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the mode.
+ *
+ * @param handle The inode handle.
+ * @return uint16_t The mode.
+ */
+static inline uint16_t
+rtems_rfs_inode_get_mode (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u16 (&handle->node->mode);
+}
+
+/**
+ * Set the mode.
+ *
+ * @param handle The inode handle.
+ * @prarm mode The mode.
+ */
+static inline void
+rtems_rfs_inode_set_mode (rtems_rfs_inode_handle* handle, uint16_t mode)
+{
+ rtems_rfs_write_u16 (&handle->node->mode, mode);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the user id.
+ *
+ * @param handle The inode handle.
+ * @return uint16_t The user id (uid).
+ */
+static inline uint16_t
+rtems_rfs_inode_get_uid (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->owner) & 0xffff;
+}
+
+/**
+ * Get the group id.
+ *
+ * @param handle The inode handle.
+ * @return uint16_t The group id (gid).
+ */
+static inline uint16_t
+rtems_rfs_inode_get_gid (rtems_rfs_inode_handle* handle)
+{
+ return (rtems_rfs_read_u32 (&handle->node->owner) >> 16) & 0xffff;
+}
+
+/**
+ * Set the user id and group id.
+ *
+ * @param handle The inode handle.
+ * @param uid The user id (uid).
+ * @param gid The group id (gid).
+ */
+static inline void
+rtems_rfs_inode_set_uid_gid (rtems_rfs_inode_handle* handle,
+ uint16_t uid, uint16_t gid)
+{
+ rtems_rfs_write_u32 (&handle->node->owner, (((uint32_t) gid) << 16) | uid);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the block offset.
+ *
+ * @param handle The inode handle.
+ * @return uint32_t The block offset.
+ */
+static inline uint16_t
+rtems_rfs_inode_get_block_offset (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u16 (&handle->node->block_offset);
+}
+
+/**
+ * Set the block offset.
+ *
+ * @param handle The inode handle.
+ * @param block_count The block offset.
+ */
+static inline void
+rtems_rfs_inode_set_block_offset (rtems_rfs_inode_handle* handle,
+ uint16_t block_offset)
+{
+ rtems_rfs_write_u16 (&handle->node->block_offset, block_offset);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the block count.
+ *
+ * @param handle The inode handle.
+ * @return uint32_t The block count.
+ */
+static inline uint32_t
+rtems_rfs_inode_get_block_count (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->block_count);
+}
+
+/**
+ * Set the block count.
+ *
+ * @param handle The inode handle.
+ * @param block_count The block count.
+ */
+static inline void
+rtems_rfs_inode_set_block_count (rtems_rfs_inode_handle* handle, uint32_t block_count)
+{
+ rtems_rfs_write_u32 (&handle->node->block_count, block_count);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the atime.
+ *
+ * @param handle The inode handle.
+ * @return rtems_rfs_time The atime.
+ */
+static inline rtems_rfs_time
+rtems_rfs_inode_get_atime (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->atime);
+}
+
+/**
+ * Set the atime.
+ *
+ * @param handle The inode handle.
+ * @prarm atime The atime.
+ */
+static inline void
+rtems_rfs_inode_set_atime (rtems_rfs_inode_handle* handle,
+ rtems_rfs_time atime)
+{
+ rtems_rfs_write_u32 (&handle->node->atime, atime);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the mtime.
+ *
+ * @param handle The inode handle.
+ * @return rtems_rfs_time The mtime.
+ */
+static inline rtems_rfs_time
+rtems_rfs_inode_get_mtime (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->mtime);
+}
+
+/**
+ * Set the mtime.
+ *
+ * @param handle The inode handle.
+ * @prarm atime The mtime.
+ */
+static inline void
+rtems_rfs_inode_set_mtime (rtems_rfs_inode_handle* handle,
+ rtems_rfs_time mtime)
+{
+ rtems_rfs_write_u32 (&handle->node->mtime, mtime);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the ctime.
+ *
+ * @param handle The inode handle.
+ * @return rtems_rfs_time The ctime.
+ */
+static inline rtems_rfs_time
+rtems_rfs_inode_get_ctime (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->ctime);
+}
+
+/**
+ * Set the ctime.
+ *
+ * @param handle The inode handle.
+ * @prarm atime The ctime.
+ */
+static inline void
+rtems_rfs_inode_set_ctime (rtems_rfs_inode_handle* handle,
+ rtems_rfs_time ctime)
+{
+ rtems_rfs_write_u32 (&handle->node->ctime, ctime);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the block number.
+ *
+ * @param handle The inode handle.
+ * @param block The block number to return.
+ * @return uint32_t The block number.
+ */
+static inline uint32_t
+rtems_rfs_inode_get_block (rtems_rfs_inode_handle* handle, int block)
+{
+ return rtems_rfs_read_u32 (&handle->node->data.blocks[block]);
+}
+
+/**
+ * Set the block number for a given block index.
+ *
+ * @param handle The inode handle.
+ * @param block The block index.
+ * @param bno The block number.
+ */
+static inline void
+rtems_rfs_inode_set_block (rtems_rfs_inode_handle* handle, int block, uint32_t bno)
+{
+ rtems_rfs_write_u32 (&handle->node->data.blocks[block], bno);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the last map block from the inode.
+ *
+ * @param handle The inode handle.
+ * @return uint32_t The last map block number.
+ */
+static inline uint32_t
+rtems_rfs_inode_get_last_map_block (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->last_map_block);
+}
+
+/**
+ * Set the last map block.
+ *
+ * @param handle The inode handle.
+ * @param block_count The last map block number.
+ */
+static inline void
+rtems_rfs_inode_set_last_map_block (rtems_rfs_inode_handle* handle, uint32_t last_map_block)
+{
+ rtems_rfs_write_u32 (&handle->node->last_map_block, last_map_block);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Get the last data block from the inode.
+ *
+ * @param handle The inode handle.
+ * @return uint32_t The last data block number.
+ */
+static inline uint32_t
+rtems_rfs_inode_get_last_data_block (rtems_rfs_inode_handle* handle)
+{
+ return rtems_rfs_read_u32 (&handle->node->last_data_block);
+}
+
+/**
+ * Set the last data block.
+ *
+ * @param handle The inode handle.
+ * @param block_count The last data block number.
+ */
+static inline void
+rtems_rfs_inode_set_last_data_block (rtems_rfs_inode_handle* handle, uint32_t last_data_block)
+{
+ rtems_rfs_write_u32 (&handle->node->last_data_block, last_data_block);
+ rtems_rfs_buffer_mark_dirty (&handle->buffer);
+}
+
+/**
+ * Allocate an inode number and return it.
+ *
+ * @param fs The file system data.
+ * @param ino Return the ino.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_alloc (rtems_rfs_file_system* fs,
+ rtems_rfs_bitmap_bit goal,
+ rtems_rfs_ino* ino);
+
+/**
+ * Allocate an inode number and return it.
+ *
+ * @param fs The file system data.
+ * @param ino The ino too free.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_free (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino);
+
+/**
+ * Open the inode handle. This reads the inode into the buffer and sets the
+ * data pointer. All data is in media byte order and needs to be accessed via
+ * the supporting calls.
+ *
+ * @param fs The file system.
+ * @param ino The inode number.
+ * @param handle The handle to the inode we are opening.
+ * @param load If true load the inode into memory from the media.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_open (rtems_rfs_file_system* fs,
+ rtems_rfs_ino ino,
+ rtems_rfs_inode_handle* handle,
+ bool load);
+
+/**
+ * The close inode handle. All opened inodes need to be closed.
+ *
+ * @param fs The file system.
+ * @param handle The handle to close.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_close (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle);
+
+/**
+ * Load the inode into memory.
+ *
+ * @param fs The file system.
+ * @param handle The inode handle to load.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_load (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle);
+
+/**
+ * Unload the inode from memory.
+ *
+ * @param fs The file system.
+ * @param handle The inode handle to unload.
+ * @param update_ctime Update the ctime field of the inode.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_unload (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle,
+ bool update_ctime);
+
+/**
+ * Create an inode allocating, initialising and adding an entry to the parent
+ * directory.
+ *
+ * @param fs The file system data.
+ * @param parent The parent inode number to add the directory entry to.
+ * @param name The name of the directory entryinode to create.
+ *
+ */
+int rtems_rfs_inode_create (rtems_rfs_file_system* fs,
+ rtems_rfs_ino parent,
+ const char* name,
+ size_t length,
+ uint16_t mode,
+ uint16_t links,
+ uid_t uid,
+ gid_t gid,
+ rtems_rfs_ino* ino);
+
+/**
+ * Delete the inode eraseing it and release the buffer to commit the write. You
+ * need to load the inode again if you wish to use it again.
+ *
+ * @param fs The file system.
+ * @param handle The inode handle to erase.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_delete (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle);
+
+/**
+ * Initialise a new inode.
+ *
+ * @param handle The inode handle to initialise.
+ * @param links The number of links to the inode.
+ * @param mode The inode mode.
+ * @param uid The user id.
+ * @param gid The group id.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_inode_initialise (rtems_rfs_inode_handle* handle,
+ uint16_t links,
+ uint16_t mode,
+ uid_t uid,
+ gid_t gid);
+
+/**
+ * Time stamp the inode with the current time. The ctime field is hanlded
+ * automatically.
+ *
+ * @param handle The inode handle.
+ * @param atime Update the atime field.
+ * @param mtime UPdate the mtime field.
+ * @return int The error number (errno). No error if 0 and ENXIO if no inode
+ * loaded.
+ */
+int rtems_rfs_inode_time_stamp_now (rtems_rfs_inode_handle* handle,
+ bool atime,
+ bool mtime);
+
+/**
+ * Calculate the size of data attached to the inode.
+ *
+ * @param fs The file system data.
+ * @param handle The inode handle.
+ * @return rtems_rfs_pos The data size in bytes in the block map attched to the
+ * inode.
+ */
+rtems_rfs_pos rtems_rfs_inode_get_size (rtems_rfs_file_system* fs,
+ rtems_rfs_inode_handle* handle);
+
+#endif
+
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-link.c b/cpukit/libfs/src/rfs/rtems-rfs-link.c
new file mode 100644
index 0000000000..27a08153b9
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-link.c
@@ -0,0 +1,458 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Link Routines.
+ *
+ * These functions manage links. A link is the addition of a directory entry in
+ * a parent directory and incrementing the links count in the inode.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-block.h>
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+#include <rtems/rfs/rtems-rfs-dir.h>
+#include <rtems/rfs/rtems-rfs-dir-hash.h>
+#include <rtems/rfs/rtems-rfs-link.h>
+
+int
+rtems_rfs_link (rtems_rfs_file_system* fs,
+ const char* name,
+ int length,
+ rtems_rfs_ino parent,
+ rtems_rfs_ino target,
+ bool link_dir)
+{
+ rtems_rfs_inode_handle parent_inode;
+ rtems_rfs_inode_handle target_inode;
+ uint16_t links;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_LINK))
+ {
+ int c;
+ printf ("rtems-rfs: link: parent(%" PRIu32 ") -> ", parent);
+ for (c = 0; c < length; c++)
+ printf ("%c", name[c]);
+ printf ("(%" PRIu32 ")\n", target);
+ }
+
+ rc = rtems_rfs_inode_open (fs, target, &target_inode, true);
+ if (rc)
+ return rc;
+
+ /*
+ * If the target inode is a directory and we cannot link directories
+ * return a not supported error code.
+ */
+ if (!link_dir && S_ISDIR (rtems_rfs_inode_get_mode (&target_inode)))
+ {
+ rtems_rfs_inode_close (fs, &target_inode);
+ return ENOTSUP;
+ }
+
+ rc = rtems_rfs_inode_open (fs, parent, &parent_inode, true);
+ if (rc)
+ {
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_dir_add_entry (fs, &parent_inode, name, length, target);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &parent_inode);
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ links = rtems_rfs_inode_get_links (&target_inode) + 1;
+ rtems_rfs_inode_set_links (&target_inode, links);
+
+ rc = rtems_rfs_inode_time_stamp_now (&parent_inode, true, true);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &parent_inode);
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_close (fs, &parent_inode);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_close (fs, &target_inode);
+
+ return rc;
+}
+
+int
+rtems_rfs_unlink (rtems_rfs_file_system* fs,
+ rtems_rfs_ino parent,
+ rtems_rfs_ino target,
+ uint32_t doff,
+ rtems_rfs_unlink_dir dir_mode)
+{
+ rtems_rfs_inode_handle parent_inode;
+ rtems_rfs_inode_handle target_inode;
+ uint16_t links;
+ bool dir;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: unlink: parent(%" PRIu32 ") -X-> (%" PRIu32 ")\n", parent, target);
+
+ rc = rtems_rfs_inode_open (fs, target, &target_inode, true);
+ if (rc)
+ return rc;
+
+ /*
+ * If a directory process the unlink mode.
+ */
+
+ dir = RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&target_inode));
+ if (dir)
+ {
+ switch (dir_mode)
+ {
+ case rtems_rfs_unlink_dir_denied:
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: link is a directory\n");
+ rtems_rfs_inode_close (fs, &target_inode);
+ return EISDIR;
+
+ case rtems_rfs_unlink_dir_if_empty:
+ rc = rtems_rfs_dir_empty (fs, &target_inode);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: dir-empty: %d: %s\n", rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ rc = rtems_rfs_inode_open (fs, parent, &parent_inode, true);
+ if (rc)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: link: inode-open failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_dir_del_entry (fs, &parent_inode, target, doff);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: unlink: dir-del failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &parent_inode);
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ links = rtems_rfs_inode_get_links (&target_inode);
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: unlink: target:%" PRIu32 " links:%u\n", target, links);
+
+ if (links > 1)
+ {
+ links--;
+ rtems_rfs_inode_set_links (&target_inode, links);
+ }
+ else
+ {
+ /*
+ * Erasing the inode releases all blocks attached to it.
+ */
+ rc = rtems_rfs_inode_delete (fs, &target_inode);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: unlink: inode-del failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &parent_inode);
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ if (dir)
+ {
+ links = rtems_rfs_inode_get_links (&parent_inode);
+ if (links > 1)
+ links--;
+ rtems_rfs_inode_set_links (&parent_inode, links);
+ }
+ }
+
+ rc = rtems_rfs_inode_time_stamp_now (&parent_inode, true, true);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: link: inode-time-stamp failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &parent_inode);
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_close (fs, &parent_inode);
+ if (rc > 0)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: link: parent inode-close failed: %d: %s\n",
+ rc, strerror (rc));
+ rtems_rfs_inode_close (fs, &target_inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_inode_close (fs, &target_inode);
+
+ if ((rc > 0) && rtems_rfs_trace (RTEMS_RFS_TRACE_UNLINK))
+ printf ("rtems-rfs: link: target inode-close failed: %d: %s\n",
+ rc, strerror (rc));
+
+ return rc;
+}
+
+int
+rtems_rfs_symlink (rtems_rfs_file_system* fs,
+ const char* name,
+ int length,
+ const char* link,
+ int link_length,
+ uid_t uid,
+ gid_t gid,
+ rtems_rfs_ino parent)
+{
+ rtems_rfs_inode_handle inode;
+ rtems_rfs_ino ino;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_SYMLINK))
+ {
+ int c;
+ printf ("rtems-rfs: symlink: parent:%" PRIu32 " name:", parent);
+ for (c = 0; c < length; c++)
+ printf ("%c", name[c]);
+ printf (" link:");
+ for (c = 0; c < link_length; c++)
+ printf ("%c", link[c]);
+ }
+
+ if (link_length >= rtems_rfs_fs_block_size (fs))
+ return ENAMETOOLONG;
+
+ rc = rtems_rfs_inode_create (fs, parent, name, strlen (name),
+ RTEMS_RFS_S_SYMLINK,
+ 1, uid, gid, &ino);
+ if (rc > 0)
+ return rc;
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ return rc;
+
+ /*
+ * If the link length is less than the length of data union in the inode
+ * place the link into the data area else allocate a block and write the link
+ * to that.
+ */
+ if (link_length < RTEMS_RFS_INODE_DATA_NAME_SIZE)
+ {
+ memset (inode.node->data.name, 0, RTEMS_RFS_INODE_DATA_NAME_SIZE);
+ memcpy (inode.node->data.name, link, link_length);
+ rtems_rfs_inode_set_block_count (&inode, 0);
+ }
+ else
+ {
+ rtems_rfs_block_map map;
+ rtems_rfs_block_no block;
+ rtems_rfs_buffer_handle buffer;
+ uint8_t* data;
+
+ rc = rtems_rfs_block_map_open (fs, &inode, &map);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_block_map_grow (fs, &map, 1, &block);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, false);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ data = rtems_rfs_buffer_data (&buffer);
+
+ memset (data, 0xff, rtems_rfs_fs_block_size (fs));
+ memcpy (data, link, link_length);
+
+ rc = rtems_rfs_buffer_handle_close (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_block_map_close (fs, &map);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+ }
+
+ rtems_rfs_inode_set_block_offset (&inode, link_length);
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+
+ return rc;
+}
+
+int
+rtems_rfs_symlink_read (rtems_rfs_file_system* fs,
+ rtems_rfs_ino link,
+ char* path,
+ size_t size,
+ size_t* length)
+{
+ rtems_rfs_inode_handle inode;
+ int rc;
+
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_SYMLINK_READ))
+ printf ("rtems-rfs: symlink-read: link:%" PRIu32 "\n", link);
+
+ rc = rtems_rfs_inode_open (fs, link, &inode, true);
+ if (rc)
+ return rc;
+
+ if (!RTEMS_RFS_S_ISLNK (rtems_rfs_inode_get_mode (&inode)))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ return EINVAL;
+ }
+
+ *length = rtems_rfs_inode_get_block_offset (&inode);
+
+ if (size < *length)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ return EINVAL;
+ }
+
+ if (rtems_rfs_inode_get_block_count (&inode) == 0)
+ {
+ memcpy (path, inode.node->data.name, *length);
+ }
+ else
+ {
+ rtems_rfs_block_map map;
+ rtems_rfs_block_no block;
+ rtems_rfs_buffer_handle buffer;
+ char* data;
+
+ rc = rtems_rfs_block_map_open (fs, &inode, &map);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_block_map_seek (fs, &map, 0, &block);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, false);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ data = rtems_rfs_buffer_data (&buffer);
+ memcpy (path, data, *length);
+
+ rc = rtems_rfs_buffer_handle_close (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_block_map_close (fs, &map);
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+
+ rc = rtems_rfs_block_map_close (fs, &map);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ return rc;
+ }
+ }
+
+ path[*length] = '\0';
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+
+ return rc;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-link.h b/cpukit/libfs/src/rfs/rtems-rfs-link.h
new file mode 100644
index 0000000000..359360f0fd
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-link.h
@@ -0,0 +1,112 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Link Support
+ *
+ * This file provides the link support functions.
+ */
+
+#if !defined (_RTEMS_RFS_LINK_H_)
+#define _RTEMS_RFS_LINK_H_
+
+#include <dirent.h>
+
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+
+/**
+ * Directory unlink modes.
+ */
+typedef enum rtems_rfs_unlink_dir_e
+{
+ rtems_rfs_unlink_dir_denied, /**< Not allowed to unlink a directory. */
+ rtems_rfs_unlink_dir_if_empty, /**< Unlink if the directory is empty. */
+ rtems_rfs_unlink_dir_allowed /**< Unlinking of directories is allowed. */
+} rtems_rfs_unlink_dir;
+
+/**
+ * Create a link. Do not link directories unless renaming or you will create
+ * loops in the file system.
+ *
+ * @param fs The file system.
+ * @param name The name of the link.
+ * @param length The length of the name.
+ * @param parent The inode number of the parent directory.
+ * @param target The inode of the target.
+ * @param link_dir If true directories can be linked. Useful when renaming.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_link (rtems_rfs_file_system* fs,
+ const char* name,
+ int length,
+ rtems_rfs_ino parent,
+ rtems_rfs_ino target,
+ bool link_dir);
+
+/**
+ * Unlink the node from the parent directory. A directory offset for the target
+ * entry is required because links cause a number of inode numbers to appear in
+ * a single directory so scanning does not work.
+ *
+ * @param fs The file system.
+ * @param parent The inode number of the parent directory.
+ * @param target The inode of the target.
+ * @param doff Parent directory entry offset for the target entry.
+ * @param dir_mode Directory unlink mode.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_unlink (rtems_rfs_file_system* fs,
+ rtems_rfs_ino parent,
+ rtems_rfs_ino target,
+ uint32_t doff,
+ rtems_rfs_unlink_dir dir_mode);
+
+/**
+ * Symbolic link is an inode that has a path attached.
+ *
+ * @param fs The file system data.
+ * @param name The name of the node.
+ * @param length The length of the name of the node.
+ * @param link The link path attached to the symlink inode.
+ * @param link_length The length of the link path.
+ * @param parent The parent inode number.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_symlink (rtems_rfs_file_system* fs,
+ const char* name,
+ int length,
+ const char* link,
+ int link_length,
+ uid_t uid,
+ gid_t gid,
+ rtems_rfs_ino parent);
+
+/**
+ * Read a symbolic link into the provided buffer returning the link of link
+ * name.
+ *
+ * @param fs The file system data.
+ * @param link The link inode number to read.
+ * @param path The buffer to write the link path into.
+ * @param size The size of the buffer.
+ * @param length Set to the length of the link path.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_symlink_read (rtems_rfs_file_system* fs,
+ rtems_rfs_ino link,
+ char* path,
+ size_t size,
+ size_t* length);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-mutex.c b/cpukit/libfs/src/rfs/rtems-rfs-mutex.c
new file mode 100644
index 0000000000..90a865fb76
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-mutex.c
@@ -0,0 +1,72 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Mutex.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/rfs/rtems-rfs-mutex.h>
+
+#if __rtems__
+/**
+ * RTEMS_RFS Mutex Attributes
+ *
+ * @warning Do not configure as inherit priority. If a driver is in the driver
+ * initialisation table this locked semaphore will have the IDLE task
+ * as the holder and a blocking task will raise the priority of the
+ * IDLE task which can cause unsual side effects like not work.
+ */
+#define RTEMS_RFS_MUTEX_ATTRIBS \
+ (RTEMS_PRIORITY | RTEMS_SIMPLE_BINARY_SEMAPHORE | \
+ RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
+#endif
+
+int
+rtems_rfs_mutex_create (rtems_rfs_mutex* mutex)
+{
+#if __rtems__
+ rtems_status_code sc;
+ sc = rtems_semaphore_create (rtems_build_name ('R', 'F', 'S', 'm'),
+ 1, RTEMS_RFS_MUTEX_ATTRIBS, 0,
+ mutex);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
+ printf ("rtems-rfs: mutex: open failed: %s\n",
+ rtems_status_text (sc));
+ return EIO;
+ }
+#endif
+ return 0;
+}
+
+int
+rtems_rfs_mutex_destroy (rtems_rfs_mutex* mutex)
+{
+#if __rtems__
+ rtems_status_code sc;
+ sc = rtems_semaphore_delete (*mutex);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
+ printf ("rtems-rfs: mutex: close failed: %s\n",
+ rtems_status_text (sc));
+ return EIO;
+ }
+#endif
+ return 0;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-mutex.h b/cpukit/libfs/src/rfs/rtems-rfs-mutex.h
new file mode 100644
index 0000000000..12e7fee921
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-mutex.h
@@ -0,0 +1,108 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Mutex.
+ *
+ * It may be suprising we abstract this for the RTEMS file system but this code
+ * is designed to be run on host operating systems.
+ */
+
+#if !defined (_RTEMS_RFS_MUTEX_H_)
+#define _RTEMS_RFS_MUTEX_H_
+
+#include <errno.h>
+
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+#if __rtems__
+#include <rtems.h>
+#include <rtems/error.h>
+#endif
+
+/**
+ * RFS Mutex type.
+ */
+#if __rtems__
+typedef rtems_id rtems_rfs_mutex;
+#else
+typedef uint32_t rtems_rfs_mutex; /* place holder */
+#endif
+
+/**
+ * Create the mutex.
+ *
+ * @param mutex Reference to the mutex handle returned to the caller.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_mutex_create (rtems_rfs_mutex* mutex);
+
+/**
+ * Create the mutex.
+ *
+ * @param mutex Reference to the mutex handle returned to the caller.
+ * @return int The error number (errno). No error if 0.
+ */
+int rtems_rfs_mutex_destroy (rtems_rfs_mutex* mutex);
+
+/**
+ * Lock the mutex.
+ *
+ * @param mutex The mutex to lock.
+ * @retval true The mutex is locked.
+ * @retval false The mutex could not be locked.
+ */
+static inline int
+rtems_rfs_mutex_lock (rtems_rfs_mutex* mutex)
+{
+#if __rtems__
+ rtems_status_code sc = rtems_semaphore_obtain (*mutex, RTEMS_WAIT, 0);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+#if RTEMS_RFS_TRACE
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
+ printf ("rtems-rfs: mutex: obtain failed: %s\n",
+ rtems_status_text (sc));
+#endif
+ return EIO;
+ }
+#endif
+ return 0;
+}
+
+/**
+ * Unlock the mutex.
+ *
+ * @param mutex The mutex to unlock.
+ * @retval true The mutex is unlocked.
+ * @retval false The mutex could not be unlocked.
+ */
+static inline int
+rtems_rfs_mutex_unlock (rtems_rfs_mutex* mutex)
+{
+#if __rtems__
+ rtems_status_code sc = rtems_semaphore_release (*mutex);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+#if RTEMS_RFS_TRACE
+ if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
+ printf ("rtems-rfs: mutex: release failed: %s\n",
+ rtems_status_text (sc));
+#endif
+ return EIO;
+ }
+#endif
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c
new file mode 100644
index 0000000000..e2b3eb207f
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c
@@ -0,0 +1,271 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS RFS Device Interface.
+ *
+ * This file contains the set of handlers used to map operations on RFS device
+ * nodes onto calls to the RTEMS Classic API IO Manager.
+ *
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "rtems-rfs-rtems.h"
+
+/*
+ * Convert RTEMS status to a UNIX errno
+ */
+extern int rtems_deviceio_errno (rtems_status_code code);
+
+/**
+ * This handler maps an open() operation onto rtems_io_open().
+ *
+ * @param iop
+ * @param pathname
+ * @param flag
+ * @param mode
+ * @return int
+ */
+static int
+rtems_rfs_rtems_device_open ( rtems_libio_t *iop,
+ const char *pathname,
+ uint32_t flag,
+ uint32_t mode)
+{
+ rtems_libio_open_close_args_t args;
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_iop_ino (iop);
+ rtems_rfs_inode_handle inode;
+ int major;
+ int minor;
+ rtems_status_code status;
+ int rc;
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("device_open: opening inode", rc);
+ }
+
+ major = rtems_rfs_inode_get_block (&inode, 0);
+ minor = rtems_rfs_inode_get_block (&inode, 1);
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("device_open: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ iop->data0 = major;
+ iop->data1 = (void*)((intptr_t) minor);
+
+ args.iop = iop;
+ args.flags = iop->flags;
+ args.mode = mode;
+
+ status = rtems_io_open (major, minor, (void *) &args);
+
+ return rtems_deviceio_errno (status);
+}
+
+/**
+ * This handler maps a close() operation onto rtems_io_close().
+ *
+ * @param iop
+ * @return int
+ */
+
+static int
+rtems_rfs_rtems_device_close (rtems_libio_t* iop)
+{
+ rtems_libio_open_close_args_t args;
+ rtems_status_code status;
+ int major;
+ int minor;
+
+ major = (int) iop->data0;
+ minor = (intptr_t) iop->data1;
+
+ args.iop = iop;
+ args.flags = 0;
+ args.mode = 0;
+
+ status = rtems_io_close (major, minor, (void *) &args);
+
+ return rtems_deviceio_errno (status);
+}
+
+/**
+ * This handler maps a read() operation onto rtems_io_read().
+ *
+ * @param iop
+ * @param buffer
+ * @param count
+ * @return ssize_t
+ */
+
+static ssize_t
+rtems_rfs_rtems_device_read (rtems_libio_t* iop, void* buffer, size_t count)
+{
+ rtems_libio_rw_args_t args;
+ rtems_status_code status;
+ int major;
+ int minor;
+
+ major = (int) iop->data0;
+ minor = (intptr_t) iop->data1;
+
+ args.iop = iop;
+ args.offset = iop->offset;
+ args.buffer = buffer;
+ args.count = count;
+ args.flags = iop->flags;
+ args.bytes_moved = 0;
+
+ status = rtems_io_read (major, minor, (void *) &args);
+ if (status)
+ return rtems_deviceio_errno (status);
+
+ return (ssize_t) args.bytes_moved;
+}
+
+/*
+ * This handler maps a write() operation onto rtems_io_write().
+ *
+ * @param iop
+ * @param buffer
+ * @param count
+ * @return ssize_t
+ */
+
+static ssize_t
+rtems_rfs_rtems_device_write (rtems_libio_t* iop,
+ const void* buffer,
+ size_t count)
+{
+ rtems_libio_rw_args_t args;
+ rtems_status_code status;
+ int major;
+ int minor;
+
+ major = (int) iop->data0;
+ minor = (intptr_t) iop->data1;
+
+ args.iop = iop;
+ args.offset = iop->offset;
+ args.buffer = (void *) buffer;
+ args.count = count;
+ args.flags = iop->flags;
+ args.bytes_moved = 0;
+
+ status = rtems_io_write (major, minor, (void *) &args);
+ if (status)
+ return rtems_deviceio_errno (status);
+
+ return (ssize_t) args.bytes_moved;
+}
+
+/**
+ * This handler maps an ioctl() operation onto rtems_io_ioctl().
+ *
+ * @param iop
+ * @param command
+ * @param buffer
+ * @return int
+ */
+
+static int
+rtems_rfs_rtems_device_ioctl (rtems_libio_t* iop,
+ uint32_t command,
+ void* buffer)
+{
+ rtems_libio_ioctl_args_t args;
+ rtems_status_code status;
+ int major;
+ int minor;
+
+ major = (int) iop->data0;
+ minor = (intptr_t) iop->data1;
+
+ args.iop = iop;
+ args.command = command;
+ args.buffer = buffer;
+
+ status = rtems_io_control (major, minor, (void *) &args);
+ if (status)
+ return rtems_deviceio_errno (status);
+
+ return args.ioctl_return;
+}
+
+/**
+ * This handler eats all lseek() operations and does not create an error. It
+ * assumes all devices can handle the seek. The writes fail.
+ *
+ * @param iop
+ * @param offset
+ * @param whence
+ * @return rtems_off64_t
+ */
+
+static rtems_off64_t
+rtems_rfs_rtems_device_lseek (rtems_libio_t* iop,
+ rtems_off64_t offset,
+ int whence)
+{
+ return offset;
+}
+
+/**
+ * The consumes the truncate call. You cannot truncate device files.
+ *
+ * @param iop
+ * @param length
+ * @return int
+ */
+
+static int
+rtems_rfs_rtems_device_ftruncate (rtems_libio_t* iop, rtems_off64_t length)
+{
+ return 0;
+}
+
+/*
+ * Handler table for RFS device nodes
+ */
+
+const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers = {
+ .open_h = rtems_rfs_rtems_device_open,
+ .close_h = rtems_rfs_rtems_device_close,
+ .read_h = rtems_rfs_rtems_device_read,
+ .write_h = rtems_rfs_rtems_device_write,
+ .ioctl_h = rtems_rfs_rtems_device_ioctl,
+ .lseek_h = rtems_rfs_rtems_device_lseek,
+ .fstat_h = rtems_rfs_rtems_fstat,
+ .fchmod_h = rtems_rfs_rtems_fchmod,
+ .ftruncate_h = rtems_rfs_rtems_device_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_filesystem_default_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_rfs_rtems_rmnod
+};
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c
new file mode 100644
index 0000000000..bc3c4b85fa
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c
@@ -0,0 +1,245 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS RFS Directory Access Routines
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <rtems/rfs/rtems-rfs-dir.h>
+#include <rtems/rfs/rtems-rfs-link.h>
+#include "rtems-rfs-rtems.h"
+
+/**
+ * This rountine will verify that the node being opened as a directory is in
+ * fact a directory node. If it is then the offset into the directory will be
+ * set to 0 to position to the first directory entry.
+ *
+ * @param iop
+ * @param pathname
+ * @param flag
+ * @param mode
+ * @@return int
+ */
+static int
+rtems_rfs_rtems_dir_open (rtems_libio_t* iop,
+ const char* pathname,
+ uint32_t flag,
+ uint32_t mode)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_iop_ino (iop);
+ rtems_rfs_inode_handle inode;
+ int rc;
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("dir_open: opening inode", rc);
+ }
+
+ if (!RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&inode)))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("dir_open: not dir", ENOTDIR);
+ }
+
+ iop->offset = 0;
+
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return 0;
+}
+
+/**
+ * This routine will be called by the generic close routine to cleanup any
+ * resources that have been allocated for the management of the file
+ *
+ * @param iop
+ * @retval 0 Always no error.
+ */
+static int
+rtems_rfs_rtems_dir_close (rtems_libio_t* iop)
+{
+ /*
+ * The RFS does not hold any resources. Nothing to do.
+ */
+ return 0;
+}
+
+/**
+ * This routine will read the next directory entry based on the directory
+ * offset. The offset should be equal to -n- time the size of an individual
+ * dirent structure. If n is not an integer multiple of the sizeof a dirent
+ * structure, an integer division will be performed to determine directory
+ * entry that will be returned in the buffer. Count should reflect -m- times
+ * the sizeof dirent bytes to be placed in the buffer. If there are not -m-
+ * dirent elements from the current directory position to the end of the
+ * exisiting file, the remaining entries will be placed in the buffer and the
+ * returned value will be equal to -m actual- times the size of a directory
+ * entry.
+ */
+static ssize_t
+rtems_rfs_rtems_dir_read (rtems_libio_t* iop,
+ void* buffer,
+ size_t count)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_iop_ino (iop);
+ rtems_rfs_inode_handle inode;
+ struct dirent* dirent;
+ ssize_t bytes_transferred;
+ int d;
+ int rc;
+
+ count = count / sizeof (struct dirent);
+ dirent = buffer;
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("dir_read: read inode", rc);
+ }
+
+ bytes_transferred = 0;
+
+ for (d = 0; d < count; d++, dirent++)
+ {
+ size_t size;
+ rc = rtems_rfs_dir_read (fs, &inode, iop->offset, dirent, &size);
+ if (rc == ENOENT)
+ {
+ rc = 0;
+ break;
+ }
+ if (rc > 0)
+ {
+ bytes_transferred = rtems_rfs_rtems_error ("dir_read: dir read", rc);
+ break;
+ }
+ iop->offset += size;
+ bytes_transferred += sizeof (struct dirent);
+ }
+
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+
+ return bytes_transferred;
+}
+
+/**
+ * This routine will behave in one of three ways based on the state of argument
+ * whence. Based on the state of its value the offset argument will be
+ * interpreted using one of the following methods:
+ *
+ * SEEK_SET - offset is the absolute byte offset from the start of the
+ * logical start of the dirent sequence that represents the
+ * directory
+ * SEEK_CUR - offset is used as the relative byte offset from the current
+ * directory position index held in the iop structure
+ * SEEK_END - N/A --> This will cause an assert.
+ *
+ * @param iop
+ * @param offset
+ * @param whence
+ * return rtems_off64_t
+ */
+static rtems_off64_t
+rtems_rfs_rtems_dir_lseek (rtems_libio_t* iop,
+ rtems_off64_t offset,
+ int whence)
+{
+ switch (whence)
+ {
+ case SEEK_SET: /* absolute move from the start of the file */
+ case SEEK_CUR: /* relative move */
+ break;
+
+ case SEEK_END: /* Movement past the end of the directory via lseek */
+ /* is not a permitted operation */
+ default:
+ return rtems_rfs_rtems_error ("dir_lseek: bad whence", EINVAL);
+ break;
+ }
+ return 0;
+}
+
+static int
+rtems_rfs_rtems_dir_rmnod (rtems_filesystem_location_info_t* parent_pathloc,
+ rtems_filesystem_location_info_t* pathloc)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino parent = rtems_rfs_rtems_get_pathloc_ino (parent_pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ uint32_t doff = rtems_rfs_rtems_get_pathloc_doff (pathloc);
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_DIR_RMNOD))
+ printf ("rtems-rfs: dir-rmnod: parent:%" PRId32 " doff:%" PRIu32 ", ino:%" PRId32 "\n",
+ parent, doff, ino);
+
+ if (ino == RTEMS_RFS_ROOT_INO)
+ return rtems_rfs_rtems_error ("dir_rmnod: root inode", EBUSY);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_unlink (fs, parent, ino, doff, rtems_rfs_unlink_dir_if_empty);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("dir_rmnod: unlinking", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+ return 0;
+}
+
+/*
+ * Set of operations handlers for operations on directories.
+ */
+
+const rtems_filesystem_file_handlers_r rtems_rfs_rtems_dir_handlers = {
+ .open_h = rtems_rfs_rtems_dir_open,
+ .close_h = rtems_rfs_rtems_dir_close,
+ .read_h = rtems_rfs_rtems_dir_read,
+ .write_h = rtems_filesystem_default_write,
+ .ioctl_h = rtems_filesystem_default_ioctl,
+ .lseek_h = rtems_rfs_rtems_dir_lseek,
+ .fstat_h = rtems_rfs_rtems_fstat,
+ .fchmod_h = rtems_rfs_rtems_fchmod,
+ .ftruncate_h = rtems_filesystem_default_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_rfs_rtems_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_rfs_rtems_dir_rmnod
+};
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
new file mode 100644
index 0000000000..2f2df428dd
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
@@ -0,0 +1,354 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS RFS File Handlers
+ *
+ * This file contains the set of handlers used to process operations on
+ * RFS file nodes.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems/rfs/rtems-rfs-file.h>
+#include "rtems-rfs-rtems.h"
+
+/**
+ * This routine processes the open() system call. Note that there is nothing
+ * special to be done at open() time.
+ *
+ * @param iop
+ * @param pathname
+ * @param flag
+ * @param mode
+ * @return int
+ */
+
+static int
+rtems_rfs_rtems_file_open (rtems_libio_t* iop,
+ const char* pathname,
+ uint32_t flag,
+ uint32_t mode)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
+ rtems_rfs_ino ino;
+ rtems_rfs_file_handle* file;
+ uint32_t flags;
+ int rc;
+
+ flags = 0;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
+ printf("rtems-rfs: file-open: path:%s ino:%" PRId32 " flags:%04" PRIx32 " mode:%04" PRIx32 "\n",
+ pathname, ino, flags, mode);
+
+ rtems_rfs_rtems_lock (fs);
+
+ ino = rtems_rfs_rtems_get_iop_ino (iop);
+
+ rc = rtems_rfs_file_open (fs, ino, flags, &file);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("file-open: open", rc);
+ }
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
+ printf("rtems-rfs: file-open: handle:%p\n", file);
+
+ iop->size = rtems_rfs_file_size (file);
+ rtems_rfs_rtems_set_iop_file_handle (iop, file);
+
+ rtems_rfs_rtems_unlock (fs);
+ return 0;
+}
+
+/**
+ * This routine processes the close() system call. Note that there is nothing
+ * to flush at this point.
+ *
+ * @param iop
+ * @return int
+ */
+static int
+rtems_rfs_rtems_file_close (rtems_libio_t* iop)
+{
+ rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
+ rtems_rfs_file_system* fs = rtems_rfs_file_fs (file);
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_CLOSE))
+ printf("rtems-rfs: file-close: handle:%p\n", file);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_file_close (fs, file);
+ if (rc > 0)
+ rc = rtems_rfs_rtems_error ("file-close: file close", rc);
+
+ rtems_rfs_rtems_unlock (fs);
+ return rc;
+}
+
+/**
+ * This routine processes the read() system call.
+ *
+ * @param iop
+ * @param buffer
+ * @param count
+ * @return int
+ */
+static ssize_t
+rtems_rfs_rtems_file_read (rtems_libio_t* iop,
+ void* buffer,
+ size_t count)
+{
+ rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
+ rtems_rfs_pos pos;
+ uint8_t* data = buffer;
+ ssize_t read = 0;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_READ))
+ printf("rtems-rfs: file-read: handle:%p count:%zd\n", file, count);
+
+ rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
+
+ pos = iop->offset;
+
+ if (pos < rtems_rfs_file_size (file))
+ {
+ while (count)
+ {
+ size_t size;
+
+ rc = rtems_rfs_file_io_start (file, &size, true);
+ if (rc > 0)
+ {
+ read = rtems_rfs_rtems_error ("file-read: read: io-start", rc);
+ break;
+ }
+
+ if (size == 0)
+ break;
+
+ if (size > count)
+ size = count;
+
+ memcpy (data, rtems_rfs_file_data (file), size);
+
+ data += size;
+ count -= size;
+ read += size;
+
+ rc = rtems_rfs_file_io_end (file, size, true);
+ if (rc > 0)
+ {
+ read = rtems_rfs_rtems_error ("file-read: read: io-end", rc);
+ break;
+ }
+ }
+ }
+
+ rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
+
+ return read;
+}
+
+/**
+ * This routine processes the write() system call.
+ *
+ * @param iop
+ * @param buffer
+ * @param count
+ * @return ssize_t
+ */
+static ssize_t
+rtems_rfs_rtems_file_write (rtems_libio_t* iop,
+ const void* buffer,
+ size_t count)
+{
+ rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
+ rtems_rfs_pos pos;
+ const uint8_t* data = buffer;
+ ssize_t write = 0;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_WRITE))
+ printf("rtems-rfs: file-write: handle:%p count:%zd\n", file, count);
+
+ rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
+
+ pos = iop->offset;
+
+ /*
+ * If the iop position is past the physical end of the file we need to set
+ * the file size to the new length before writing. If the position equals the
+ * size of file we are still past the end of the file as positions number
+ * from 0. For a specific position we need a file that has a length of one
+ * more.
+ */
+
+ if (pos >= rtems_rfs_file_size (file))
+ {
+ rc = rtems_rfs_file_set_size (file, pos + 1);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
+ return rtems_rfs_rtems_error ("file-write: write extend", rc);
+ }
+ }
+
+ rtems_rfs_file_set_bpos (file, pos);
+
+ while (count)
+ {
+ size_t size = count;
+
+ rc = rtems_rfs_file_io_start (file, &size, false);
+ if (rc)
+ {
+ write = rtems_rfs_rtems_error ("file-write: write open", rc);
+ break;
+ }
+
+ if (size > count)
+ size = count;
+
+ memcpy (rtems_rfs_file_data (file), data, size);
+
+ data += size;
+ count -= size;
+ write += size;
+
+ rc = rtems_rfs_file_io_end (file, size, false);
+ if (rc)
+ {
+ write = rtems_rfs_rtems_error ("file-write: write close", rc);
+ break;
+ }
+ }
+
+ iop->size = rtems_rfs_file_size (file);
+
+ rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
+
+ return write;
+}
+
+/**
+ * This routine processes the ioctl() system call.
+ *
+ * @note No ioctl()'s are currently supported for RFS files.
+ *
+ * @param iop
+ * @param command
+ * @param buffer
+ */
+
+static int
+rtems_rfs_rtems_file_ioctl (rtems_libio_t* iop, uint32_t command, void* buffer)
+{
+ return 0;
+}
+
+/**
+ * This routine processes the lseek() system call.
+ *
+ * @param iop
+ * @param offset
+ * @param whence
+ * @return rtems_off64_t
+ */
+static rtems_off64_t
+rtems_rfs_rtems_file_lseek (rtems_libio_t* iop,
+ rtems_off64_t offset,
+ int whence)
+{
+ rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
+ rtems_rfs_pos pos;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK))
+ printf("rtems-rfs: file-lseek: handle:%p offset:%Ld\n", file, offset);
+
+ rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
+
+ pos = iop->offset;
+
+ rc = rtems_rfs_file_seek (file, pos, &pos);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
+ return rtems_rfs_rtems_error ("file_lseek: lseek", rc);
+ }
+
+ rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
+
+ return iop->offset;
+}
+
+/**
+ * This routine processes the ftruncate() system call.
+ *
+ * @param iop
+ * @param length
+ * @return int
+ */
+static int
+rtems_rfs_rtems_file_ftruncate (rtems_libio_t* iop,
+ rtems_off64_t length)
+{
+ rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_FTRUNC))
+ printf("rtems-rfs: file-ftrunc: handle:%p length:%Ld\n", file, length);
+
+ rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
+
+ rc = rtems_rfs_file_set_size (file, length);
+ if (rc)
+ rc = rtems_rfs_rtems_error ("file_ftruncate: set size", rc);
+
+ iop->size = rtems_rfs_file_size (file);
+
+ rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
+
+ return rc;
+}
+
+/*
+ * Set of operations handlers for operations on RFS files.
+ */
+
+const rtems_filesystem_file_handlers_r rtems_rfs_rtems_file_handlers = {
+ .open_h = rtems_rfs_rtems_file_open,
+ .close_h = rtems_rfs_rtems_file_close,
+ .read_h = rtems_rfs_rtems_file_read,
+ .write_h = rtems_rfs_rtems_file_write,
+ .ioctl_h = rtems_rfs_rtems_file_ioctl,
+ .lseek_h = rtems_rfs_rtems_file_lseek,
+ .fstat_h = rtems_rfs_rtems_fstat,
+ .fchmod_h = rtems_rfs_rtems_fchmod,
+ .ftruncate_h = rtems_rfs_rtems_file_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_rfs_rtems_fdatasync,
+ .fdatasync_h = rtems_rfs_rtems_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_rfs_rtems_rmnod
+};
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-utils.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-utils.c
new file mode 100644
index 0000000000..2c8ba591f2
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-utils.c
@@ -0,0 +1,244 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * Set of utility functions to support RTEMS RFS on RTEMS.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+
+#include "rtems-rfs-rtems.h"
+
+bool
+rtems_rfs_rtems_eval_perms (rtems_rfs_inode_handle* inode, int flags)
+{
+ uid_t st_uid;
+ gid_t st_gid;
+ uint16_t uid;
+ uint16_t gid;
+ uint16_t mode;
+ int flags_to_test;
+
+ uid = rtems_rfs_inode_get_uid (inode);
+ gid = rtems_rfs_inode_get_gid (inode);
+ mode = rtems_rfs_inode_get_mode (inode);
+
+#if defined (RTEMS_POSIX_API)
+ st_uid = geteuid ();
+ st_gid = getegid ();
+#else
+ st_uid = uid;
+ st_gid = gid;
+#endif
+
+ /*
+ * Check if I am owner or a group member or someone else.
+ */
+ flags_to_test = flags;
+
+ if ((st_uid == 0) || (st_uid == uid))
+ flags_to_test |= flags << 6;
+ if ((st_uid == 0) || (st_gid == gid))
+ flags_to_test |= flags << 3;
+ else
+ /* must be other - already set above */;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PERMS))
+ printf ("rtems-rfs: eval-perms: uid=%d gid=%d iuid=%d igid=%d " \
+ "flags=%o flags_to_test=%o mode=%o (%o)\n",
+ st_uid, st_gid, uid, gid,
+ flags, flags_to_test, mode & 0777,
+ flags_to_test & (mode & 0777));
+
+ /*
+ * If all of the flags are set we have permission
+ * to do this.
+ */
+ if ((flags_to_test & (mode & 0777)) != 0)
+ return true;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PERMS))
+ printf("rtems-rfs: eval-perms: perms failed\n");
+
+ return false;
+}
+
+/*
+ * The following sets the handlers based on the type of inode.
+ */
+
+bool
+rtems_rfs_rtems_set_handlers (rtems_filesystem_location_info_t* loc,
+ rtems_rfs_inode_handle* inode)
+{
+ uint16_t mode = rtems_rfs_inode_get_mode (inode);
+ loc->handlers = NULL;
+ if (RTEMS_RFS_S_ISDIR (mode))
+ loc->handlers = rtems_rfs_rtems_handlers (dir);
+ else if (RTEMS_RFS_S_ISCHR (mode) || RTEMS_RFS_S_ISBLK(mode))
+ loc->handlers = rtems_rfs_rtems_handlers (device);
+ else if (RTEMS_RFS_S_ISLNK (mode))
+ loc->handlers = rtems_rfs_rtems_handlers (link);
+ else if (RTEMS_RFS_S_ISREG (mode))
+ loc->handlers = rtems_rfs_rtems_handlers (file);
+ else
+ {
+ printf ("rtems-rfs: mode type unknown: %04x\n", mode);
+ return false;
+ }
+ return true;
+}
+
+uint16_t
+rtems_rfs_rtems_imode (mode_t mode)
+{
+ /*
+ * Mapping matches RTEMS so no need to change.
+ */
+ return mode;
+}
+
+mode_t
+rtems_rfs_rtems_mode (int imode)
+{
+ /*
+ * Mapping matches RTEMS so no need to change.
+ */
+ return imode;
+}
+
+/*
+ * Only provide if there is no macro version.
+ */
+#if !defined (rtems_rfs_rtems_error)
+int
+rtems_rfs_rtems_error (const char* mesg, int error)
+{
+ if (error)
+ printf ("rtems-rfs: %s: %d: %s\n", mesg, error, strerror (error));
+ errno = error;
+ return error == 0 ? 0 : -1;
+}
+#endif
+
+#if RTEMS_RFS_RTEMS_TRACE
+static uint32_t rtems_rfs_rtems_trace_mask;
+
+bool
+rtems_rfs_rtems_trace (uint32_t mask)
+{
+ bool result = false;
+ if (mask & rtems_rfs_rtems_trace_mask)
+ result = true;
+ return result;
+}
+
+void
+rtems_rfs_trace_rtems_set_mask (uint32_t mask)
+{
+ rtems_rfs_rtems_trace_mask |= mask;
+}
+
+void
+rtems_rfs_trace_rtems_clear_mask (uint32_t mask)
+{
+ rtems_rfs_rtems_trace_mask &= ~mask;
+}
+
+int
+rtems_rfs_rtems_trace_shell_command (int argc, char *argv[])
+{
+ const char* table[] =
+ {
+ "error-msgs",
+ "eval-path"
+ "eval-for-make",
+ "eval-perms",
+ "mknod",
+ "rmnod",
+ "link",
+ "unlink",
+ "chown",
+ "readlink",
+ "fchmod",
+ "stat",
+ "dir-rmnod",
+ "file-open",
+ "file-close",
+ "file-read",
+ "file-write",
+ "file-lseek",
+ "file-ftrunc"
+ };
+
+ bool set = true;
+ int arg;
+ int t;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][1])
+ {
+ case 'h':
+ printf ("usage: %s [-hl] [set/clear] [flags]\n", argv[0]);
+ return 0;
+ case 'l':
+ printf ("%s: valid flags to set or clear are:\n", argv[0]);
+ for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
+ printf (" %s\n", table[t]);
+ return 0;
+ default:
+ printf ("error: unknown option\n");
+ return 1;
+ }
+ }
+ else
+ {
+ uint32_t value = 0;
+ if (strcmp (argv[arg], "set") == 0)
+ set = true;
+ if (strcmp (argv[arg], "clear") == 0)
+ set = false;
+ else if (strcmp (argv[arg], "all") == 0)
+ value = RTEMS_RFS_RTEMS_DEBUG_ALL;
+ else
+ {
+ for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
+ {
+ if (strcmp (argv[arg], table[t]) == 0)
+ {
+ value = 1 << t;
+ break;
+ }
+ }
+ }
+
+ if (set)
+ rtems_rfs_rtems_trace_mask |= value;
+ else
+ rtems_rfs_rtems_trace_mask &= ~value;
+ }
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
new file mode 100644
index 0000000000..bf688f0f67
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
@@ -0,0 +1,1286 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System Interface for RTEMS.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+#include <stdlib.h>
+
+#if SIZEOF_MODE_T == 8
+#define PRIomode_t PRIo64
+#elif SIZEOF_MODE_T == 4
+#define PRIomode_t PRIo32
+#else
+#error "unsupport size of mode_t"
+#endif
+
+#include <rtems/rfs/rtems-rfs-file.h>
+#include <rtems/rfs/rtems-rfs-dir.h>
+#include <rtems/rfs/rtems-rfs-link.h>
+#include "rtems-rfs-rtems.h"
+
+/**
+ * The libio permissions for read/execute.
+ */
+#define RTEMS_LIBIO_PERMS_RX (RTEMS_LIBIO_PERMS_SEARCH | RTEMS_LIBIO_PERMS_READ)
+/**
+ * The libio permissions for write/execute.
+ */
+#define RTEMS_LIBIO_PERMS_WX (RTEMS_LIBIO_PERMS_SEARCH | RTEMS_LIBIO_PERMS_WRITE)
+
+/**
+ * Evaluate the path to a node that wishes to be accessed. The pathloc is
+ * returned with the ino to the node to be accessed.
+ *
+ * The routine starts from the root stripping away any leading path separators
+ * breaking the path up into the node names and checking an inode exists for
+ * that node name. Permissions are checked to insure access to the node is
+ * allowed. A path to a node must be accessable all the way even if the end
+ * result is directly accessable. As a user on Linux try "ls /root/../tmp" and
+ * you will see if fails.
+ *
+ * The whole process is complicated by crossmount paths where we head down into
+ * this file system only to return to the top and out to a another mounted file
+ * system. For example we are mounted on '/e' and the user enters "ls
+ * /e/a/b/../../dev". We need to head down then back up.
+ *
+ * @param path
+ * @param pathlen
+ * @param flags
+ * @param pathloc
+ */
+static int
+rtems_rfs_rtems_eval_path (const char* path,
+ size_t pathlen,
+ int flags,
+ rtems_filesystem_location_info_t* pathloc)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_inode_handle inode;
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ uint32_t doff = 0;
+ const char* node;
+ size_t node_len;
+ int stripped;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH))
+ printf ("rtems-rfs-rtems: eval-path: in: path:%s pathlen:%zi ino:%" PRId32 "\n",
+ path, pathlen, ino);
+
+ /*
+ * Eat any separators at the start of the path.
+ */
+ stripped = rtems_filesystem_prefix_separators (path, pathlen);
+ path += stripped;
+ pathlen -= stripped;
+
+ rtems_rfs_rtems_lock (fs);
+
+ while (true)
+ {
+ /*
+ * Open and load the inode.
+ */
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_path: opening inode", rc);
+ }
+
+ /*
+ * Is this the end of the pathname we where given ?
+ */
+ if ((*path == '\0') || (pathlen == 0))
+ break;
+
+ /*
+ * If a directory the execute bit must be set for us to enter.
+ */
+ if (RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&inode)) &&
+ !rtems_rfs_rtems_eval_perms (&inode, RTEMS_LIBIO_PERMS_SEARCH))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_path: eval perms", EACCES);
+ }
+
+ /*
+ * Extract the node name we will look for this time around.
+ */
+ node = path;
+ node_len = 0;
+ while (!rtems_filesystem_is_separator (*path) &&
+ (*path != '\0') && pathlen &&
+ ((node_len + 1) < rtems_rfs_fs_max_name (fs)))
+ {
+ path++;
+ pathlen--;
+ node_len++;
+ }
+
+ /*
+ * Eat any separators at start of the path.
+ */
+ stripped = rtems_filesystem_prefix_separators (path, pathlen);
+ path += stripped;
+ pathlen -= stripped;
+ node_len += stripped;
+
+ /*
+ * If the node is the current directory and there is more path to come move
+ * on it else we are at the inode we want.
+ */
+ if (rtems_rfs_current_dir (node))
+ {
+ if (*path)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ continue;
+ }
+ break;
+ }
+
+ /*
+ * If the node is a parent we must move up one directory. If the location
+ * is on another file system we have a crossmount so we call that file
+ * system to handle the remainder of the path.
+ */
+ if (rtems_rfs_parent_dir (node))
+ {
+ /*
+ * If we are at root inode of the file system we have a crossmount path.
+ */
+ if (ino == RTEMS_RFS_ROOT_INO)
+ {
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH))
+ printf("rtems-rfs-rtems: eval-path: crossmount: path:%s (%zd)\n",
+ path - node_len, pathlen + node_len);
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ *pathloc = pathloc->mt_entry->mt_point_node;
+ return (*pathloc->ops->evalpath_h)(path - node_len, pathlen + node_len,
+ flags, pathloc);
+ }
+
+ /*
+ * We need to find the parent of this node.
+ */
+ rc = rtems_rfs_dir_lookup_ino (fs, &inode, "..", 2, &ino, &doff);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_path: read parent inode", rc);
+ }
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH))
+ printf("rtems-rfs-rtems: eval-path: parent: ino:%" PRId32 "\n", ino);
+ }
+ else
+ {
+ /*
+ * Look up the node name in this directory. If found drop through, close
+ * the current inode and let the loop open the inode so the mode can be
+ * read and handlers set.
+ */
+ rc = rtems_rfs_dir_lookup_ino (fs, &inode,
+ node, node_len - stripped, &ino, &doff);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return ((errno = rc) == 0) ? 0 : -1;
+ }
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH))
+ printf("rtems-rfs-rtems: eval-path: down: path:%s ino:%" PRId32 "\n", node, ino);
+ }
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_path: closing node", rc);
+ }
+ }
+
+ rtems_rfs_rtems_set_pathloc_ino (pathloc, ino);
+ rtems_rfs_rtems_set_pathloc_doff (pathloc, doff);
+
+ rc = rtems_rfs_rtems_set_handlers (pathloc, &inode) ? 0 : EIO;
+
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH))
+ printf("rtems-rfs-rtems: eval-path: ino:%" PRId32 "\n", ino);
+
+ return rc;
+}
+
+/**
+ * The following routine evaluates a path for a new node to be created. The
+ * pathloc is returned with a pointer to the parent of the new node. The name
+ * is returned with a pointer to the first character in the new node name. The
+ * parent node is verified to be a directory.
+ *
+ * @param path
+ * @param pathloc
+ * @param name
+ * @return int
+ */
+static int
+rtems_rfs_rtems_eval_for_make (const char* path,
+ rtems_filesystem_location_info_t* pathloc,
+ const char** name)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_inode_handle inode;
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_ino node_ino;
+ uint32_t doff = 0;
+ const char* node;
+ int node_len;
+ int stripped;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE))
+ printf ("rtems-rfs-rtems: eval-for-make: path:%s ino:%" PRId32 "\n", path, ino);
+
+ *name = path + strlen (path);
+
+ while (*name != path)
+ {
+ (*name)--;
+ if (rtems_filesystem_is_separator (**name))
+ {
+ (*name)++;
+ break;
+ }
+ }
+
+ /*
+ * Eat any separators at start of the path.
+ */
+ stripped = rtems_filesystem_prefix_separators (path, strlen(path));
+ path += stripped;
+
+ rtems_rfs_rtems_lock (fs);
+
+ while (true)
+ {
+ /*
+ * Open and load the inode.
+ */
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: read ino", rc);
+ }
+
+ /*
+ * If a directory the execute bit must be set for us to enter.
+ */
+ if (RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&inode)) &&
+ !rtems_rfs_rtems_eval_perms (&inode, RTEMS_LIBIO_PERMS_SEARCH))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: eval perms", EACCES);
+ }
+
+ /*
+ * Is this the end of the pathname we where given ?
+ */
+ if (path == *name)
+ break;
+
+ /*
+ * Extract the node name we will look for this time around.
+ */
+ node = path;
+ node_len = 0;
+ while (!rtems_filesystem_is_separator(*path) &&
+ (*path != '\0') &&
+ (node_len < (rtems_rfs_fs_max_name (fs) - 1)))
+ {
+ node_len++;
+ path++;
+ }
+
+ /*
+ * Eat any separators at start of the new path.
+ */
+ stripped = rtems_filesystem_prefix_separators (path, strlen (path));
+ path += stripped;
+ node_len += stripped;
+
+ /*
+ * If the node is the current directory and there is more path to come move
+ * on it else we are at the inode we want.
+ */
+ if (rtems_rfs_current_dir (node))
+ {
+ if (*path)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ continue;
+ }
+ break;
+ }
+
+ /*
+ * If the node is a parent we must move up one directory. If the location
+ * is on another file system we have a crossmount so we call that file
+ * system to handle the remainder of the path.
+ */
+ if (rtems_rfs_parent_dir (path))
+ {
+ /*
+ * If we are at the root inode of the file system we have a crossmount
+ * path.
+ */
+ if (ino == RTEMS_RFS_ROOT_INO)
+ {
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE))
+ printf("rtems-rfs-rtems: eval-for-make: crossmount: path:%s\n",
+ path - node_len);
+
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ *pathloc = pathloc->mt_entry->mt_point_node;
+ return (*pathloc->ops->evalformake_h)(path - node_len, pathloc, name);
+ }
+
+ /*
+ * If not a directory give and up return. We cannot change dir from a
+ * regular file or device node.
+ */
+ if (!RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&inode)))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: not dir", ENOTSUP);
+ }
+
+ /*
+ * We need to find the parent of this node.
+ */
+ rc = rtems_rfs_dir_lookup_ino (fs, &inode, "..", 2, &ino, &doff);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: read parent inode", rc);
+ }
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE))
+ printf ("rtems-rfs-rtems: eval-for-make: parent: ino:%" PRId32 "\n", ino);
+ }
+ else
+ {
+ /*
+ * Read the inode so we know it exists and what type it is.
+ */
+ rc = rtems_rfs_dir_lookup_ino (fs, &inode,
+ node, node_len - stripped, &ino, &doff);
+ if (rc > 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: reading inode", rc);
+ }
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE))
+ printf("rtems-rfs-rtems: eval-for-make: down: path:%s ino:%" PRId32 "\n",
+ node, ino);
+ }
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: closing node", rc);
+ }
+ }
+
+ if (!RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&inode)))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: not dir", ENOTDIR);
+ }
+
+ if (!rtems_rfs_rtems_eval_perms (&inode, RTEMS_LIBIO_PERMS_WX))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: cannot write", EACCES);
+ }
+
+ /*
+ * Make sure the name does not already exists in the directory.
+ */
+ rc = rtems_rfs_dir_lookup_ino (fs, &inode, *name, strlen (*name),
+ &node_ino, &doff);
+ if (rc == 0)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: found name", EEXIST);
+ }
+
+ if (rc != ENOENT)
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("eval_for_make: look up", rc);
+ }
+
+ /*
+ * Set the parent ino in the path location.
+ */
+
+ rtems_rfs_rtems_set_pathloc_ino (pathloc, ino);
+ rtems_rfs_rtems_set_pathloc_doff (pathloc, doff);
+
+ rc = rtems_rfs_rtems_set_handlers (pathloc, &inode) ? 0 : EIO;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE))
+ printf("rtems-rfs-rtems: eval-for-make: parent ino:%" PRId32 " name:%s\n",
+ ino, *name);
+
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+
+ return rc;
+}
+
+/**
+ * The following rouine creates a new link node under parent with the name
+ * given in name. The link node is set to point to the node at to_loc.
+ *
+ * @param to_loc
+ * @param parent_loc
+ * @param name
+ * @return int
+ */
+static int
+rtems_rfs_rtems_link (rtems_filesystem_location_info_t* to_loc,
+ rtems_filesystem_location_info_t* parent_loc,
+ const char* name)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (to_loc);
+ rtems_rfs_ino target = rtems_rfs_rtems_get_pathloc_ino (to_loc);
+ rtems_rfs_ino parent = rtems_rfs_rtems_get_pathloc_ino (parent_loc);
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_LINK))
+ printf ("rtems-rfs-rtems: link: in: parent:%" PRId32 " target:%" PRId32 "\n",
+ parent, target);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_link (fs, name, strlen (name), parent, target, false);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("link: linking", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * Routine to remove a link node from the file system.
+ *
+ * @param parent_loc
+ * @param loc
+ * @return int
+ */
+
+static int
+rtems_rfs_rtems_unlink (rtems_filesystem_location_info_t* parent_loc,
+ rtems_filesystem_location_info_t* loc)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (parent_loc);
+ rtems_rfs_ino parent = rtems_rfs_rtems_get_pathloc_ino (parent_loc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (loc);
+ uint32_t doff = rtems_rfs_rtems_get_pathloc_doff (loc);
+ int rc;
+
+ rtems_rfs_rtems_lock (fs);
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_UNLINK))
+ printf("rtems-rfs-rtems: unlink: parent:%" PRId32 " doff:%" PRIu32 " ino:%" PRId32 "\n",
+ parent, doff, ino);
+
+ rc = rtems_rfs_unlink (fs, parent, ino, doff, rtems_rfs_unlink_dir_denied);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("unlink: unlink inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * The following verifies that and returns the type of node that the loc refers
+ * to.
+ *
+ * @param pathloc
+ * @return rtems_filesystem_node_types_t
+ */
+
+static rtems_filesystem_node_types_t
+rtems_rfs_rtems_node_type (rtems_filesystem_location_info_t* pathloc)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_filesystem_node_types_t type;
+ rtems_rfs_inode_handle inode;
+ uint16_t mode;
+ int rc;
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("node_type: opening inode", rc);
+ }
+
+ /*
+ * Do not return RTEMS_FILESYSTEM_HARD_LINK because this would result in an
+ * eval link which does not make sense in the case of the RFS file
+ * system. All directory entries are links to an inode. A link such as a HARD
+ * link is actually the normal path to a regular file, directory, device
+ * etc's inode. Links to inodes can be considered "the real" one, yet they
+ * are all links.
+ */
+ mode = rtems_rfs_inode_get_mode (&inode);
+ if (RTEMS_RFS_S_ISDIR (mode))
+ type = RTEMS_FILESYSTEM_DIRECTORY;
+ else if (RTEMS_RFS_S_ISLNK (mode))
+ type = RTEMS_FILESYSTEM_SYM_LINK;
+ else if (RTEMS_RFS_S_ISBLK (mode) || RTEMS_RFS_S_ISCHR (mode))
+ type = RTEMS_FILESYSTEM_DEVICE;
+ else
+ type = RTEMS_FILESYSTEM_MEMORY_FILE;
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("node_type: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return type;
+}
+
+/**
+ * This routine is the implementation of the chown() system call for the
+ * RFS.
+ *
+ * @param pathloc
+ * @param owner
+ * @param group
+ * return int
+ */
+
+static int
+rtems_rfs_rtems_chown (rtems_filesystem_location_info_t *pathloc,
+ uid_t owner,
+ gid_t group)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_inode_handle inode;
+#if defined (RTEMS_POSIX_API)
+ uid_t uid;
+#endif
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_CHOWN))
+ printf ("rtems-rfs-rtems: chown: in: ino:%" PRId32 " uid:%d gid:%d\n",
+ ino, owner, group);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("chown: opening inode", rc);
+ }
+
+ /*
+ * Verify I am the owner of the node or the super user.
+ */
+
+#if defined (RTEMS_POSIX_API)
+ uid = geteuid();
+
+ if ((uid != rtems_rfs_inode_get_uid (&inode)) && (uid != 0))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("chown: not able", EPERM);
+ }
+#endif
+
+ rtems_rfs_inode_set_uid_gid (&inode, owner, group);
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("chown: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * This routine is the implementation of the utime() system call for the
+ * RFS.
+ *
+ * @param pathloc
+ * @param atime
+ * @param mtime
+ * return int
+ */
+
+static int
+rtems_rfs_rtems_utime(rtems_filesystem_location_info_t* pathloc,
+ time_t atime,
+ time_t mtime)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_inode_handle inode;
+ int rc;
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("utime: read inode", rc);
+ }
+
+ rtems_rfs_inode_set_atime (&inode, atime);
+ rtems_rfs_inode_set_mtime (&inode, mtime);
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("utime: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * The following rouine creates a new symbolic link node under parent with the
+ * name given in name. The node is set to point to the node at to_loc.
+ *
+ * @param parent_loc
+ * @param link_name
+ * @param node_name
+ * return int
+ */
+
+static int
+rtems_rfs_rtems_symlink (rtems_filesystem_location_info_t* parent_loc,
+ const char* link_name,
+ const char* node_name)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (parent_loc);
+ rtems_rfs_ino parent = rtems_rfs_rtems_get_pathloc_ino (parent_loc);
+ uid_t uid;
+ gid_t gid;
+ int rc;
+
+#if defined(RTEMS_POSIX_API)
+ uid = geteuid ();
+ gid = getegid ();
+#else
+ uid = 0;
+ gid = 0;
+#endif
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_symlink (fs, node_name, strlen (node_name),
+ link_name, strlen (link_name),
+ uid, gid, parent);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("symlink: linking", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * The following rouine puts the symblic links destination name into buf.
+ *
+ * @param loc
+ * @param buf
+ * @param bufsize
+ * @return int
+ */
+
+static ssize_t
+rtems_rfs_rtems_readlink (rtems_filesystem_location_info_t* pathloc,
+ char* buf,
+ size_t bufsize)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ size_t length;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_READLINK))
+ printf ("rtems-rfs-rtems: readlink: in: ino:%" PRId32 "\n", ino);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_symlink_read (fs, ino, buf, bufsize, &length);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("readlink: reading link", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return (int) length;
+}
+
+int
+rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc,
+ mode_t mode)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_inode_handle inode;
+ uint16_t imode;
+#if defined (RTEMS_POSIX_API)
+ uid_t uid;
+#endif
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FCHMOD))
+ printf ("rtems-rfs-rtems: fchmod: in: ino:%" PRId32 " mode:%06" PRIomode_t "\n",
+ ino, mode);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("fchmod: opening inode", rc);
+ }
+
+ imode = rtems_rfs_inode_get_mode (&inode);
+
+ /*
+ * Verify I am the owner of the node or the super user.
+ */
+#if defined (RTEMS_POSIX_API)
+ uid = geteuid();
+
+ if ((uid != rtems_rfs_inode_get_uid (&inode)) && (uid != 0))
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("fchmod: checking uid", EPERM);
+ }
+#endif
+
+ imode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+ imode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+
+ rtems_rfs_inode_set_mode (&inode, imode);
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("fchmod: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+int
+rtems_rfs_rtems_fstat (rtems_filesystem_location_info_t* pathloc,
+ struct stat* buf)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_inode_handle inode;
+ rtems_rfs_file_shared* shared;
+ uint16_t mode;
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_STAT))
+ printf ("rtems-rfs-rtems: stat: in: ino:%" PRId32 "\n", ino);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("stat: opening inode", rc);
+ }
+
+ mode = rtems_rfs_inode_get_mode (&inode);
+
+ if (RTEMS_RFS_S_ISCHR (mode) || RTEMS_RFS_S_ISBLK (mode))
+ {
+ buf->st_rdev =
+ rtems_filesystem_make_dev_t (rtems_rfs_inode_get_block (&inode, 0),
+ rtems_rfs_inode_get_block (&inode, 1));
+ }
+
+ buf->st_dev = rtems_rfs_fs_device (fs);
+ buf->st_ino = rtems_rfs_inode_ino (&inode);
+ buf->st_mode = rtems_rfs_rtems_mode (mode);
+ buf->st_nlink = rtems_rfs_inode_get_links (&inode);
+ buf->st_uid = rtems_rfs_inode_get_uid (&inode);
+ buf->st_gid = rtems_rfs_inode_get_gid (&inode);
+
+ /*
+ * Need to check is the ino is an open file. If so we take the values from
+ * the open file rather than the inode.
+ */
+ shared = rtems_rfs_file_get_shared (fs, rtems_rfs_inode_ino (&inode));
+
+ if (shared)
+ {
+ buf->st_atime = rtems_rfs_file_shared_get_atime (shared);
+ buf->st_mtime = rtems_rfs_file_shared_get_mtime (shared);
+ buf->st_ctime = rtems_rfs_file_shared_get_ctime (shared);
+ buf->st_blocks = rtems_rfs_file_shared_get_block_count (shared);
+
+ if (S_ISLNK (buf->st_mode))
+ buf->st_size = rtems_rfs_file_shared_get_block_offset (shared);
+ else
+ buf->st_size = rtems_rfs_file_shared_get_size (fs, shared);
+ }
+ else
+ {
+ buf->st_atime = rtems_rfs_inode_get_atime (&inode);
+ buf->st_mtime = rtems_rfs_inode_get_mtime (&inode);
+ buf->st_ctime = rtems_rfs_inode_get_ctime (&inode);
+ buf->st_blocks = rtems_rfs_inode_get_block_count (&inode);
+
+ if (S_ISLNK (buf->st_mode))
+ buf->st_size = rtems_rfs_inode_get_block_offset (&inode);
+ else
+ buf->st_size = rtems_rfs_inode_get_size (fs, &inode);
+ }
+
+ buf->st_blksize = rtems_rfs_fs_block_size (fs);
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("stat: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+ return 0;
+}
+
+/**
+ * Routine to create a node in the RFS file system.
+ *
+ * @param name
+ * @param mode
+ * @param dev
+ * @param pathloc
+ * @return int
+ */
+
+static int
+rtems_rfs_rtems_mknod (const char *name,
+ mode_t mode,
+ dev_t dev,
+ rtems_filesystem_location_info_t *pathloc)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino parent = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ rtems_rfs_ino ino;
+ rtems_rfs_inode_handle inode;
+ uid_t uid;
+ gid_t gid;
+ int rc;
+
+#if defined(RTEMS_POSIX_API)
+ uid = geteuid ();
+ gid = getegid ();
+#else
+ uid = 0;
+ gid = 0;
+#endif
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_inode_create (fs, parent, name, strlen (name),
+ rtems_rfs_rtems_imode (mode),
+ 1, uid, gid, &ino);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("mknod: inode create", rc);
+ }
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("mknod: inode open", rc);
+ }
+
+ if (S_ISDIR(mode) || S_ISREG(mode))
+ {
+ }
+ else if (S_ISCHR (mode) || S_ISBLK (mode))
+ {
+ int major;
+ int minor;
+ rtems_filesystem_split_dev_t (dev, major, minor);
+ rtems_rfs_inode_set_block (&inode, 0, major);
+ rtems_rfs_inode_set_block (&inode, 1, minor);
+ }
+ else
+ {
+ rtems_rfs_inode_close (fs, &inode);
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("mknod: bad mode", EINVAL);
+ }
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("mknod: closing inode", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+ return 0;
+}
+
+/**
+ * Routine to remove a node from the RFS file system.
+ *
+ * @param parent_pathloc
+ * @param pathloc
+ * @return int
+ */
+int
+rtems_rfs_rtems_rmnod (rtems_filesystem_location_info_t* parent_pathloc,
+ rtems_filesystem_location_info_t* pathloc)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ rtems_rfs_ino parent = rtems_rfs_rtems_get_pathloc_ino (parent_pathloc);
+ rtems_rfs_ino ino = rtems_rfs_rtems_get_pathloc_ino (pathloc);
+ uint32_t doff = rtems_rfs_rtems_get_pathloc_doff (pathloc);
+ int rc;
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_RMNOD))
+ printf ("rtems-rfs: rmnod: parent:%" PRId32 " doff:%" PRIu32 ", ino:%" PRId32 "\n",
+ parent, doff, ino);
+
+ rtems_rfs_rtems_lock (fs);
+
+ rc = rtems_rfs_unlink (fs, parent, ino, doff, rtems_rfs_unlink_dir_denied);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("rmnod: unlinking", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+ return 0;
+}
+
+/**
+ * The following routine does a sync on an inode node. Currently it flushes
+ * everything related to this device.
+ *
+ * @param iop
+ * @return int
+ */
+int
+rtems_rfs_rtems_fdatasync (rtems_libio_t* iop)
+{
+ int rc;
+
+ rc = rtems_rfs_buffer_sync (rtems_rfs_rtems_pathloc_dev (&iop->pathinfo));
+ if (rc)
+ return rtems_rfs_rtems_error ("fdatasync: sync", rc);
+
+ return 0;
+}
+
+/**
+ * Rename the node.
+ *
+ * @param old_parent_loc The old name's parent location.
+ * @param old_loc The old name's location.
+ * @param new_parent_loc The new name's parent location.
+ * @param new_name The new name.
+ * @return int
+ */
+static int
+rtems_rfs_rtems_rename(rtems_filesystem_location_info_t* old_parent_loc,
+ rtems_filesystem_location_info_t* old_loc,
+ rtems_filesystem_location_info_t* new_parent_loc,
+ const char* new_name)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (old_loc);
+ rtems_rfs_ino old_parent;
+ rtems_rfs_ino new_parent;
+ rtems_rfs_ino ino;
+ uint32_t doff;
+ int rc;
+
+ old_parent = rtems_rfs_rtems_get_pathloc_ino (old_parent_loc);
+ new_parent = rtems_rfs_rtems_get_pathloc_ino (new_parent_loc);
+
+ ino = rtems_rfs_rtems_get_pathloc_ino (old_loc);
+ doff = rtems_rfs_rtems_get_pathloc_doff (old_loc);
+
+ if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_RENAME))
+ printf ("rtems-rfs: rename: ino:%" PRId32 " doff:%" PRIu32 ", new parent:%" PRId32 " new name:%s\n",
+ ino, doff, new_parent, new_name);
+
+ rtems_rfs_rtems_lock (fs);
+
+ /*
+ * Link to the inode before unlinking so the inode is not erased when
+ * unlinked.
+ */
+ rc = rtems_rfs_link (fs, new_name, strlen (new_name), new_parent, ino, true);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("rename: linking", rc);
+ }
+
+ /*
+ * Unlink all inodes even directories with the dir option as false because a
+ * directory may not be empty.
+ */
+ rc = rtems_rfs_unlink (fs, old_parent, ino, doff,
+ rtems_rfs_unlink_dir_allowed);
+ if (rc)
+ {
+ rtems_rfs_rtems_unlock (fs);
+ return rtems_rfs_rtems_error ("rename: unlinking", rc);
+ }
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * Return the file system stat data.
+ *
+ * @param pathloc
+ * @param sb
+ * @return int
+ */
+static int
+rtems_rfs_rtems_statvfs (rtems_filesystem_location_info_t* pathloc,
+ struct statvfs* sb)
+{
+ rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (pathloc);
+ size_t blocks;
+ size_t inodes;
+
+ rtems_rfs_group_usage (fs, &blocks, &inodes);
+
+ sb->f_bsize = rtems_rfs_fs_block_size (fs);
+ sb->f_frsize = rtems_rfs_fs_media_block_size (fs);
+ sb->f_blocks = rtems_rfs_fs_media_blocks (fs);
+ sb->f_bfree = rtems_rfs_fs_blocks (fs) - blocks;
+ sb->f_bavail = sb->f_bfree;
+ sb->f_files = rtems_rfs_fs_inodes (fs);
+ sb->f_ffree = rtems_rfs_fs_inodes (fs) - inodes;
+ sb->f_favail = sb->f_ffree;
+ sb->f_fsid = RTEMS_RFS_SB_MAGIC;
+ sb->f_flag = rtems_rfs_fs_flags (fs);
+ sb->f_namemax = rtems_rfs_fs_max_name (fs);
+
+ return 0;
+}
+
+/**
+ * Handler table for RFS link nodes
+ */
+const rtems_filesystem_file_handlers_r rtems_rfs_rtems_link_handlers =
+{
+ .open_h = rtems_filesystem_default_open,
+ .close_h = rtems_filesystem_default_close,
+ .read_h = rtems_filesystem_default_read,
+ .write_h = rtems_filesystem_default_write,
+ .ioctl_h = rtems_filesystem_default_ioctl,
+ .lseek_h = rtems_filesystem_default_lseek,
+ .fstat_h = rtems_rfs_rtems_fstat,
+ .fchmod_h = rtems_filesystem_default_fchmod,
+ .ftruncate_h = rtems_filesystem_default_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_filesystem_default_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_rfs_rtems_rmnod
+};
+
+/**
+ * Forward decl for the ops table.
+ */
+
+int rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data);
+int rtems_rfs_rtems_shutdown (rtems_filesystem_mount_table_entry_t *mt_entry);
+
+/**
+ * RFS file system operations table.
+ */
+const rtems_filesystem_operations_table rtems_rfs_ops =
+{
+ .evalpath_h = rtems_rfs_rtems_eval_path,
+ .evalformake_h = rtems_rfs_rtems_eval_for_make,
+ .link_h = rtems_rfs_rtems_link,
+ .unlink_h = rtems_rfs_rtems_unlink,
+ .node_type_h = rtems_rfs_rtems_node_type,
+ .mknod_h = rtems_rfs_rtems_mknod,
+ .chown_h = rtems_rfs_rtems_chown,
+ .freenod_h = rtems_filesystem_default_freenode,
+ .mount_h = rtems_filesystem_default_mount,
+ .fsmount_me_h = rtems_rfs_rtems_initialise,
+ .unmount_h = rtems_filesystem_default_unmount,
+ .fsunmount_me_h = rtems_rfs_rtems_shutdown,
+ .utime_h = rtems_rfs_rtems_utime,
+ .eval_link_h = rtems_filesystem_default_evaluate_link, /* never called cause we lie in the node type */
+ .symlink_h = rtems_rfs_rtems_symlink,
+ .readlink_h = rtems_rfs_rtems_readlink,
+ .rename_h = rtems_rfs_rtems_rename,
+ .statvfs_h = rtems_rfs_rtems_statvfs
+};
+
+/**
+ * Open the file system.
+ */
+
+int
+rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t* mt_entry,
+ const void* data)
+{
+ rtems_rfs_rtems_private* rtems;
+ rtems_rfs_file_system* fs;
+ int rc;
+
+ rtems = malloc (sizeof (rtems_rfs_rtems_private));
+ if (!rtems)
+ return rtems_rfs_rtems_error ("initialise: local data", ENOMEM);
+
+ memset (rtems, 0, sizeof (rtems_rfs_rtems_private));
+
+ rc = rtems_rfs_mutex_create (&rtems->access);
+ if (rc > 0)
+ {
+ free (rtems);
+ return rtems_rfs_rtems_error ("initialise: cannot create mutex", rc);
+ }
+
+ rc = rtems_rfs_mutex_lock (&rtems->access);
+ if (rc > 0)
+ {
+ rtems_rfs_mutex_destroy (&rtems->access);
+ free (rtems);
+ return rtems_rfs_rtems_error ("initialise: cannot lock access mutex", rc);
+ }
+
+ rc = rtems_rfs_fs_open (mt_entry->dev, rtems, 0, &fs);
+ if (rc)
+ {
+ free (rtems);
+ return rtems_rfs_rtems_error ("initialise: open", rc);
+ }
+
+ mt_entry->fs_info = fs;
+
+ mt_entry->mt_fs_root.node_access = (void*) RTEMS_RFS_ROOT_INO;
+ mt_entry->mt_fs_root.handlers = &rtems_rfs_rtems_dir_handlers;
+ mt_entry->mt_fs_root.ops = &rtems_rfs_ops;
+
+ rtems_rfs_rtems_unlock (fs);
+
+ return 0;
+}
+
+/**
+ * Shutdown the file system.
+ */
+int
+rtems_rfs_rtems_shutdown (rtems_filesystem_mount_table_entry_t* mt_entry)
+{
+ rtems_rfs_file_system* fs = mt_entry->fs_info;
+ rtems_rfs_rtems_private* rtems;
+ int rc;
+
+ rtems = rtems_rfs_fs_user (fs);
+
+ rc = rtems_rfs_fs_close(fs);
+
+ rtems_rfs_mutex_destroy (&rtems->access);
+ free (rtems);
+
+ return rtems_rfs_rtems_error ("shutdown: close", rc);
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.h b/cpukit/libfs/src/rfs/rtems-rfs-rtems.h
new file mode 100644
index 0000000000..19f51da31c
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems.h
@@ -0,0 +1,329 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System RTEMS Header file.
+ *
+ * This file is not to be installed. It binds the RFS file system to RTEMS.
+ */
+
+#if !defined(RTEMS_RFS_RTEMS_DEFINED)
+#define RTEMS_RFS_RTEMS_DEFINED
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <errno.h>
+
+/**
+ * RTEMS RFS RTEMS Error Enable. Set to 1 to printing of errors. Default is off.
+ */
+#define RTEMS_RFS_RTEMS_ERROR 0
+
+/**
+ * RTEMS RFS RTEMS Trace Enable. Set to 1 to printing of errors. Default is off.
+ */
+#define RTEMS_RFS_RTEMS_TRACE 0
+
+/**
+ * If we are not handling errors provide a define that removes the strings from
+ * the code.
+ */
+#if !RTEMS_RFS_RTEMS_ERROR
+#define rtems_rfs_rtems_error(_m, _e) \
+ (((errno = (_e)) == 0) ? 0 : -1)
+#else
+/**
+ * Take the result code and set errno with it and if non-zero return -1 else
+ * return 0.
+ *
+ * @param what The message to print is the error is not zero.
+ * @param error The error code.
+ * @retval -1 An error has occured.
+ * @retval 0 No error.
+ */
+int rtems_rfs_rtems_error (const char* mesg, int error);
+#endif
+
+/**
+ * Trace message defines the RTEMS bindings of the RTEMS RFS. This is a
+ * development tool where can edit the values below to control the various trace
+ * output.
+ */
+#define RTEMS_RFS_RTEMS_DEBUG_ALL (0xffffffff)
+#define RTEMS_RFS_RTEMS_DEBUG_ERROR_MSGS (1 << 0)
+#define RTEMS_RFS_RTEMS_DEBUG_EVAL_PATH (1 << 1)
+#define RTEMS_RFS_RTEMS_DEBUG_EVAL_FOR_MAKE (1 << 2)
+#define RTEMS_RFS_RTEMS_DEBUG_EVAL_PERMS (1 << 3)
+#define RTEMS_RFS_RTEMS_DEBUG_MKNOD (1 << 4)
+#define RTEMS_RFS_RTEMS_DEBUG_RMNOD (1 << 5)
+#define RTEMS_RFS_RTEMS_DEBUG_LINK (1 << 6)
+#define RTEMS_RFS_RTEMS_DEBUG_UNLINK (1 << 7)
+#define RTEMS_RFS_RTEMS_DEBUG_CHOWN (1 << 8)
+#define RTEMS_RFS_RTEMS_DEBUG_READLINK (1 << 9)
+#define RTEMS_RFS_RTEMS_DEBUG_FCHMOD (1 << 10)
+#define RTEMS_RFS_RTEMS_DEBUG_STAT (1 << 11)
+#define RTEMS_RFS_RTEMS_DEBUG_DIR_RMNOD (1 << 12)
+#define RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN (1 << 13)
+#define RTEMS_RFS_RTEMS_DEBUG_FILE_CLOSE (1 << 14)
+#define RTEMS_RFS_RTEMS_DEBUG_FILE_READ (1 << 15)
+#define RTEMS_RFS_RTEMS_DEBUG_FILE_WRITE (1 << 16)
+#define RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK (1 << 17)
+#define RTEMS_RFS_RTEMS_DEBUG_FILE_FTRUNC (1 << 18)
+
+/**
+ * Call to check if this part is bring traced. If RTEMS_RFS_RTEMS_TRACE is
+ * defined to 0 the code is dead code elminiated when built with -Os, -O2, or
+ * higher.
+ *
+ * @param mask The part of the API to trace.
+ * @retval true Tracing is active for the mask.
+ * @retval false Do not trace.
+ */
+#if RTEMS_RFS_RTEMS_TRACE
+bool rtems_rfs_rtems_trace (uint32_t mask);
+#else
+#define rtems_rfs_rtems_trace(_m) (0)
+#endif
+
+/**
+ * Set the mask.
+ *
+ * @param mask The mask bits to set.
+ * @return The previous mask.
+ */
+#if RTEMS_RFS_RTEMS_TRACE
+void rtems_rfs_rtems_trace_set_mask (uint32_t mask);
+#else
+#define rtems_rfs_rtems_trace_set_mask(_m)
+#endif
+
+/**
+ * Clear the mask.
+ *
+ * @param mask The mask bits to clear.
+ * @return The previous mask.
+ */
+#if RTEMS_RFS_RTEMS_TRACE
+void rtems_rfs_rtems_trace_clear_mask (uint32_t mask);
+#else
+#define rtems_rfs_rtems_trace_clear_mask(_m)
+#endif
+
+/**
+ * Add shell trace shell command.
+ */
+#if RTEMS_RFS_RTEMS_TRACE
+int rtems_rfs_rtems_trace_shell_command (int argc, char *argv[]);
+#endif
+
+#include <rtems/rfs/rtems-rfs-file-system.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+#include <rtems/rfs/rtems-rfs-mutex.h>
+#include <rtems/libio_.h>
+#include <rtems/fs.h>
+
+/**
+ * Private RFS RTEMS Port data.
+ */
+typedef struct rtems_rfs_rtems_private
+{
+ /**
+ * The access lock.
+ */
+ rtems_rfs_mutex access;
+} rtems_rfs_rtems_private;
+/**
+ * Return the file system structure given a path location.
+ *
+ * @param _loc Pointer to the path location.
+ * @return rtems_rfs_file_system*
+ */
+#define rtems_rfs_rtems_pathloc_dev(_loc) \
+ ((rtems_rfs_file_system*)((_loc)->mt_entry->fs_info))
+
+/**
+ * Set the inode number (ino) into the path location.
+ *
+ * @param _loc Pointer to the path location.
+ * @param _ino The ino to set in the path location.
+ */
+#define rtems_rfs_rtems_set_pathloc_ino(_loc, _ino) \
+ (_loc)->node_access = (void*)((intptr_t)(_ino))
+
+/**
+ * Get the inode number (ino) given a path location.
+ *
+ * @param _loc Pointer to the path location.
+ * @return rtems_rfs_ino The inode number in the path location.
+ */
+#define rtems_rfs_rtems_get_pathloc_ino(_loc) \
+ ((rtems_rfs_ino) (intptr_t)((_loc)->node_access))
+
+/**
+ * Set the directory offset (doff) into the path location.
+ *
+ * @param _loc Pointer to the path location.
+ * @param _doff The doff to set in the path location.
+ */
+#define rtems_rfs_rtems_set_pathloc_doff(_loc, _doff) \
+ (_loc)->node_access_2 = (void*)((intptr_t)(_doff))
+
+/**
+ * Get the directory offset (doff) given a path location.
+ *
+ * @param _loc Pointer to the path location.
+ * @return uin32_t The doff in the path location.
+ */
+#define rtems_rfs_rtems_get_pathloc_doff(_loc) \
+ ((uint32_t) (intptr_t)((_loc)->node_access_2))
+
+/**
+ * Get the ino from the I/O pointer.
+ *
+ * @param _iop The I/O pointer.
+ * @return ino
+ */
+#define rtems_rfs_rtems_get_iop_ino(_iop) \
+ ((intptr_t)(_iop)->pathinfo.node_access)
+
+/**
+ * Get the file handle from the I/O pointer.
+ *
+ * @param _iop The I/O pointer.
+ * @return filehandle The file handle
+ */
+#define rtems_rfs_rtems_get_iop_file_handle(_iop) \
+ ((rtems_rfs_file_handle*)(_iop)->pathinfo.node_access_2)
+
+/**
+ * Set the file handle in the I/O pointer.
+ *
+ * @param _iop The I/O pointer.
+ * @param _fh The file handle.
+ */
+#define rtems_rfs_rtems_set_iop_file_handle(_iop, _fh) \
+ (_iop)->pathinfo.node_access_2 = (_fh)
+
+/**
+ * Create the name of the handler's table given the type of handlers.
+ *
+ * @param _h The name of the handlers.
+ * @return label The name of the handler's table.
+ */
+#define rtems_rfs_rtems_handlers(_h) \
+ &rtems_rfs_rtems_ ## _h ## _handlers
+
+/**
+ * Evaluate the permissions of the inode's mode against the flags.
+ *
+ * @param inode The inode handler to check the mode, uid and gid.
+ * @param flags The flags to check permissions of.
+ * @retval true The permissions allow access to the inode.
+ * @retval false Access to the inode is not permitted.
+ */
+bool rtems_rfs_rtems_eval_perms (rtems_rfs_inode_handle* inode, int flags);
+
+/**
+ * Set the handlers in the path location based on the mode of the inode.
+ *
+ * @param loc Pointer to the path location to set the handlers in.
+ * @param inode The inode handle to check the mode of for the type of handlers.
+ * @retval true The handlers have been set.
+ * @retval false There are no handlers for the mode.
+ */
+bool rtems_rfs_rtems_set_handlers (rtems_filesystem_location_info_t* pathloc,
+ rtems_rfs_inode_handle* inode);
+
+/**
+ * Convert the system mode flags to inode mode flags.
+ *
+ * @param mode The system mode flags.
+ * @return uint16_t The inode mode flags.
+ */
+uint16_t rtems_rfs_rtems_imode (mode_t mode);
+
+/**
+ * Convert the inode mode flags to system mode flags.
+ *
+ * @param imode The inode mode flags
+ * @return mode_t The system mode flags.
+ */
+mode_t rtems_rfs_rtems_mode (int imode);
+
+/**
+ * Lock the RFS file system.
+ */
+static inline void
+ rtems_rfs_rtems_lock (rtems_rfs_file_system* fs)
+{
+ rtems_rfs_rtems_private* rtems = rtems_rfs_fs_user (fs);
+ rtems_rfs_mutex_lock (&rtems->access);
+}
+
+/**
+ * Unlock the RFS file system.
+ */
+static inline void
+ rtems_rfs_rtems_unlock (rtems_rfs_file_system* fs)
+{
+ rtems_rfs_rtems_private* rtems = rtems_rfs_fs_user (fs);
+ rtems_rfs_buffers_release (fs);
+ rtems_rfs_mutex_unlock (&rtems->access);
+}
+
+/**
+ * The handlers.
+ */
+extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_dir_handlers;
+extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers;
+extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_link_handlers;
+extern const rtems_filesystem_file_handlers_r rtems_rfs_rtems_file_handlers;
+
+/**
+ * The following routine does a stat on a node.
+ *
+ * @param iop
+ * @param buf
+ * @return int
+ */
+int rtems_rfs_rtems_fstat (rtems_filesystem_location_info_t* pathloc,
+ struct stat* buf);
+
+/**
+ * File change mode routine.
+ *
+ * @param iop
+ * @param mode
+ * @return int
+ */
+int rtems_rfs_rtems_fchmod (rtems_filesystem_location_info_t* pathloc,
+ mode_t mode);
+
+/**
+ * Routine to remove a node from the RFS file system.
+ *
+ * @param parent_pathloc
+ * @param pathloc
+ */
+int rtems_rfs_rtems_rmnod (rtems_filesystem_location_info_t* parent_pathloc,
+ rtems_filesystem_location_info_t* pathloc);
+
+/**
+ * The following routine does a sync on an inode node. Currently it flushes
+ * everything related to this device.
+ *
+ * @param iop
+ */
+int rtems_rfs_rtems_fdatasync (rtems_libio_t* iop);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-shell.c b/cpukit/libfs/src/rfs/rtems-rfs-shell.c
new file mode 100644
index 0000000000..63931752cf
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-shell.c
@@ -0,0 +1,753 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Shell Commands Support
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+#include <string.h>
+
+#include <rtems/rfs/rtems-rfs-block.h>
+#include <rtems/rfs/rtems-rfs-buffer.h>
+#include <rtems/rfs/rtems-rfs-group.h>
+#include <rtems/rfs/rtems-rfs-inode.h>
+#include <rtems/rfs/rtems-rfs-dir.h>
+#include <rtems/rtems-rfs-format.h>
+
+#include <sys/statvfs.h>
+
+#if __rtems__
+#include "rtems-rfs-rtems.h"
+#endif
+
+/**
+ * The type of the shell handlers we have.
+ */
+typedef int (*rtems_rfs_shell_handler) (rtems_rfs_file_system* fs, int argc, char *argv[]);
+
+/**
+ * Table of handlers we parse to invoke the command.
+ */
+typedef struct
+{
+ const char* name;
+ rtems_rfs_shell_handler handler;
+ const char* help;
+} rtems_rfs_shell_cmd;
+
+/**
+ * Lock the file system.
+ */
+static void
+rtems_rfs_shell_lock_rfs (rtems_rfs_file_system* fs)
+{
+#if __rtems__
+ rtems_rfs_rtems_lock (fs);
+#endif
+}
+
+/**
+ * Unlock the file system.
+ */
+static void
+rtems_rfs_shell_unlock_rfs (rtems_rfs_file_system* fs)
+{
+#if __rtems__
+ rtems_rfs_rtems_unlock (fs);
+#endif
+}
+
+/**
+ * Get the file system data from the specific path. Checks to make sure the path is
+ * pointing to a valid RFS file system.
+ */
+static int
+rtems_rfs_get_fs (const char* path, rtems_rfs_file_system** fs)
+{
+ struct statvfs sb;
+ int rc;
+
+ rc = statvfs (path, &sb);
+ if (rc < 0)
+ {
+ printf ("error: cannot statvfs path: %s: (%d) %s\n",
+ path, errno, strerror (errno));
+ return -1;
+ }
+
+ if (sb.f_fsid != RTEMS_RFS_SB_MAGIC)
+ {
+ printf ("error: path '%s' is not on an RFS file system\n", path);
+ return -1;
+ }
+
+#if __rtems__
+ /*
+ * Now find the path location on the file system. This will give the file
+ * system data.
+ */
+ {
+ rtems_filesystem_location_info_t pathloc;
+ rc = rtems_filesystem_evaluate_path (path, strlen (path), 0, &pathloc, true);
+ *fs = rtems_rfs_rtems_pathloc_dev (&pathloc);
+ rtems_filesystem_freenode (&pathloc);
+ }
+#endif
+
+ return rc;
+}
+
+static int
+rtems_rfs_shell_data (rtems_rfs_file_system* fs, int argc, char *argv[])
+{
+ size_t blocks;
+ size_t inodes;
+ int bpcent;
+ int ipcent;
+
+ printf ("RFS Filesystem Data\n");
+ printf (" flags: %08" PRIx32 "\n", fs->flags);
+#if 0
+ printf (" device: %08lx\n", rtems_rfs_fs_device (fs));
+#endif
+ printf (" blocks: %zu\n", rtems_rfs_fs_blocks (fs));
+ printf (" block size: %zu\n", rtems_rfs_fs_block_size (fs));
+ printf (" size: %" PRIu64 "\n", rtems_rfs_fs_size (fs));
+ printf (" media block size: %" PRIu32 "\n", rtems_rfs_fs_media_block_size (fs));
+ printf (" media size: %" PRIu64 "\n", rtems_rfs_fs_media_size (fs));
+ printf (" inodes: %" PRIu32 "\n", rtems_rfs_fs_inodes (fs));
+ printf (" bad blocks: %" PRIu32 "\n", fs->bad_blocks);
+ printf (" max. name length: %" PRIu32 "\n", rtems_rfs_fs_max_name (fs));
+ printf (" groups: %d\n", fs->group_count);
+ printf (" group blocks: %zd\n", fs->group_blocks);
+ printf (" group inodes: %zd\n", fs->group_inodes);
+ printf (" inodes per block: %zd\n", fs->inodes_per_block);
+ printf (" blocks per block: %zd\n", fs->blocks_per_block);
+ printf (" singly blocks: %zd\n", fs->block_map_singly_blocks);
+ printf (" doublly blocks: %zd\n", fs->block_map_doubly_blocks);
+ printf (" max. held buffers: %" PRId32 "\n", fs->max_held_buffers);
+
+ rtems_rfs_shell_lock_rfs (fs);
+
+ rtems_rfs_group_usage (fs, &blocks, &inodes);
+
+ rtems_rfs_shell_unlock_rfs (fs);
+
+ bpcent = (blocks * 1000) / rtems_rfs_fs_blocks (fs);
+ ipcent = (inodes * 1000) / rtems_rfs_fs_inodes (fs);
+
+ printf (" blocks used: %zd (%d.%d%%)\n",
+ blocks, bpcent / 10, bpcent % 10);
+ printf (" inodes used: %zd (%d.%d%%)\n",
+ inodes, ipcent / 10, ipcent % 10);
+
+ return 0;
+}
+
+static int
+rtems_rfs_shell_block (rtems_rfs_file_system* fs, int argc, char *argv[])
+{
+ rtems_rfs_buffer_handle buffer;
+ rtems_rfs_block_no block;
+ uint8_t* data;
+ bool state;
+ int b;
+ int rc;
+
+ if (argc <= 1)
+ {
+ printf ("error: no block number provided\n");
+ return 1;
+ }
+
+ block = strtoul (argv[1], 0, 0);
+
+ rtems_rfs_shell_lock_rfs (fs);
+
+ rc = rtems_rfs_group_bitmap_test (fs, false, block, &state);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: testing block state: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ printf (" %5" PRIu32 ": block %s\n", block, state ? "allocated" : "free");
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: opening buffer handle: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, true);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: requesting buffer handle: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ for (b = 0, data = rtems_rfs_buffer_data (&buffer);
+ b < rtems_rfs_fs_block_size (fs);
+ b++, data++)
+ {
+ int mod = b % 16;
+ if (mod == 0)
+ {
+ if (b)
+ printf ("\n");
+ printf ("%04x ", b);
+ }
+ if (mod == 8)
+ printf (" ");
+ printf ("%02x ", *data);
+ }
+
+ printf ("\n");
+
+ rc = rtems_rfs_buffer_handle_close (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: closing buffer handle: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ rtems_rfs_shell_unlock_rfs (fs);
+
+ return 0;
+}
+
+static int
+rtems_rfs_shell_inode (rtems_rfs_file_system* fs, int argc, char *argv[])
+{
+ rtems_rfs_ino start;
+ rtems_rfs_ino end;
+ rtems_rfs_ino total;
+ rtems_rfs_ino ino;
+ bool show_all;
+ bool error_check_only;
+ bool forced;
+ bool have_start;
+ bool have_end;
+ int arg;
+ int b;
+ int rc;
+
+ total = fs->group_inodes * fs->group_count;
+ start = RTEMS_RFS_ROOT_INO;
+ end = total - 1;
+ show_all = false;
+ error_check_only = false;
+ forced = false;
+ have_start = have_end = false;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][1])
+ {
+ case 'a':
+ show_all = true;
+ break;
+ case 'e':
+ error_check_only = true;
+ break;
+ case 'f':
+ forced = true;
+ break;
+ default:
+ printf ("warning: option ignored: %s\n", argv[arg]);
+ break;
+ }
+ }
+ else
+ {
+ if (have_end && have_start)
+ printf ("warning: option ignored: %s\n", argv[arg]);
+ else if (!have_start)
+ {
+ start = end = strtoul (argv[arg], 0, 0);
+ have_start = true;
+ }
+ else
+ {
+ end = strtoul (argv[arg], 0, 0);
+ have_end = true;
+ }
+ }
+ }
+
+ if ((start >= total) || (end >= total))
+ {
+ printf ("error: inode out of range (0->%" PRId32 ").\n", total - 1);
+ return 1;
+ }
+
+ rtems_rfs_shell_lock_rfs (fs);
+
+ for (ino = start; ino <= end; ino++)
+ {
+ rtems_rfs_inode_handle inode;
+ bool allocated;
+
+ rc = rtems_rfs_group_bitmap_test (fs, true, ino, &allocated);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: testing inode state: ino=%" PRIu32 ": (%d) %s\n",
+ ino, rc, strerror (rc));
+ return 1;
+ }
+
+ if (show_all || allocated)
+ {
+ uint16_t mode;
+ bool error;
+
+ rc = rtems_rfs_inode_open (fs, ino, &inode, true);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: opening inode handle: ino=%" PRIu32 ": (%d) %s\n",
+ ino, rc, strerror (rc));
+ return 1;
+ }
+
+ error = false;
+
+ mode = rtems_rfs_inode_get_mode (&inode);
+
+ if (error_check_only)
+ {
+ if (!RTEMS_RFS_S_ISDIR (mode) &&
+ !RTEMS_RFS_S_ISCHR (mode) &&
+ !RTEMS_RFS_S_ISBLK (mode) &&
+ !RTEMS_RFS_S_ISREG (mode) &&
+ !RTEMS_RFS_S_ISLNK (mode))
+ error = true;
+ else
+ {
+#if NEED_TO_HANDLE_DIFFERENT_TYPES
+ int b;
+ for (b = 0; b < RTEMS_RFS_INODE_BLOCKS; b++)
+ {
+ uint32_t block;
+ block = rtems_rfs_inode_get_block (&inode, b);
+ if ((block <= RTEMS_RFS_SUPERBLOCK_SIZE) ||
+ (block >= rtems_rfs_fs_blocks (fs)))
+ error = true;
+ }
+#endif
+ }
+ }
+
+ if (!error_check_only || error)
+ {
+ printf (" %5" PRIu32 ": pos=%06" PRIu32 ":%04zx %c ",
+ ino, rtems_rfs_buffer_bnum (&inode.buffer),
+ inode.offset * RTEMS_RFS_INODE_SIZE,
+ allocated ? 'A' : 'F');
+
+ if (!allocated && !forced)
+ printf (" --\n");
+ else
+ {
+ const char* type;
+ type = "UKN";
+ if (RTEMS_RFS_S_ISDIR (mode))
+ type = "DIR";
+ else if (RTEMS_RFS_S_ISCHR (mode))
+ type = "CHR";
+ else if (RTEMS_RFS_S_ISBLK (mode))
+ type = "BLK";
+ else if (RTEMS_RFS_S_ISREG (mode))
+ type = "REG";
+ else if (RTEMS_RFS_S_ISLNK (mode))
+ type = "LNK";
+ printf ("links=%03i mode=%04x (%s/%03o) bo=%04u bc=%04" PRIu32 " b=[",
+ rtems_rfs_inode_get_links (&inode),
+ mode, type, mode & ((1 << 10) - 1),
+ rtems_rfs_inode_get_block_offset (&inode),
+ rtems_rfs_inode_get_block_count (&inode));
+ for (b = 0; b < (RTEMS_RFS_INODE_BLOCKS - 1); b++)
+ printf ("%" PRIu32 " ", rtems_rfs_inode_get_block (&inode, b));
+ printf ("%" PRIu32 "]\n", rtems_rfs_inode_get_block (&inode, b));
+ }
+ }
+
+ rc = rtems_rfs_inode_close (fs, &inode);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: closing inode handle: ino=%" PRIu32 ": (%d) %s\n",
+ ino, rc, strerror (rc));
+ return 1;
+ }
+ }
+ }
+
+ rtems_rfs_shell_unlock_rfs (fs);
+
+ return 0;
+}
+
+static int
+rtems_rfs_shell_dir (rtems_rfs_file_system* fs, int argc, char *argv[])
+{
+ rtems_rfs_buffer_handle buffer;
+ rtems_rfs_block_no block;
+ uint8_t* data;
+ bool state;
+ int entry;
+ int b;
+ int rc;
+
+ if (argc <= 1)
+ {
+ printf ("error: no block number provided\n");
+ return 1;
+ }
+
+ block = strtoul (argv[1], 0, 0);
+
+ rtems_rfs_shell_lock_rfs (fs);
+
+ rc = rtems_rfs_group_bitmap_test (fs, false, block, &state);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: testing block state: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ printf (" %5" PRIu32 ": block %s\n", block, state ? "allocated" : "free");
+
+ rc = rtems_rfs_buffer_handle_open (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: opening buffer handle: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ rc = rtems_rfs_buffer_handle_request (fs, &buffer, block, true);
+ if (rc > 0)
+ {
+ rtems_rfs_buffer_handle_close (fs, &buffer);
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: requesting buffer handle: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ b = 0;
+ entry = 1;
+ data = rtems_rfs_buffer_data (&buffer);
+
+ while (b < (rtems_rfs_fs_block_size (fs) - RTEMS_RFS_DIR_ENTRY_SIZE - 1))
+ {
+ rtems_rfs_ino eino;
+ int elength;
+ int length;
+ int c;
+
+ eino = rtems_rfs_dir_entry_ino (data);
+ elength = rtems_rfs_dir_entry_length (data);
+
+ if (elength == RTEMS_RFS_DIR_ENTRY_EMPTY)
+ break;
+
+ if ((elength < RTEMS_RFS_DIR_ENTRY_SIZE) ||
+ (elength >= rtems_rfs_fs_max_name (fs)))
+ {
+ printf (" %5d: entry length appears corrupt: %d\n", entry, elength);
+ break;
+ }
+
+ if ((eino < RTEMS_RFS_ROOT_INO) || (eino >= rtems_rfs_fs_inodes (fs)))
+ {
+ printf (" %5d: entry ino appears corrupt: ino=%" PRId32 "\n", entry, eino);
+ break;
+ }
+
+ length = elength - RTEMS_RFS_DIR_ENTRY_SIZE;
+
+ printf (" %5d: %04x inode=%-6" PRIu32 " hash=%08" PRIx32 " name[%03u]=",
+ entry, b,
+ rtems_rfs_dir_entry_ino (data),
+ rtems_rfs_dir_entry_hash (data),
+ length);
+
+ if (length > 50)
+ length = 50;
+
+ for (c = 0; c < length; c++)
+ printf ("%c", data[RTEMS_RFS_DIR_ENTRY_SIZE + c]);
+ if (length < elength - RTEMS_RFS_DIR_ENTRY_SIZE)
+ printf ("...");
+ printf ("\n");
+
+ b += elength;
+ data += elength;
+ entry++;
+ }
+
+ rc = rtems_rfs_buffer_handle_close (fs, &buffer);
+ if (rc > 0)
+ {
+ rtems_rfs_shell_unlock_rfs (fs);
+ printf ("error: closing buffer handle: block=%" PRIu32 ": (%d) %s\n",
+ block, rc, strerror (rc));
+ return 1;
+ }
+
+ rtems_rfs_shell_unlock_rfs (fs);
+
+ return 0;
+}
+
+static int
+rtems_rfs_shell_group (rtems_rfs_file_system* fs, int argc, char *argv[])
+{
+ int start;
+ int end;
+ int g;
+
+ start = 0;
+ end = fs->group_count - 1;
+
+ switch (argc)
+ {
+ case 1:
+ break;
+ case 2:
+ start = end = strtoul (argv[1], 0, 0);
+ break;
+ case 3:
+ start = strtoul (argv[1], 0, 0);
+ end = strtoul (argv[2], 0, 0);
+ break;
+ default:
+ printf ("error: too many arguments.\n");
+ return 1;
+ }
+
+ if ((start < 0) || (end < 0) ||
+ (start >= fs->group_count) || (end >= fs->group_count))
+ {
+ printf ("error: group out of range (0->%d).\n", fs->group_count);
+ return 1;
+ }
+
+ rtems_rfs_shell_lock_rfs (fs);
+
+ for (g = start; g <= end; g++)
+ {
+ rtems_rfs_group* group = &fs->groups[g];
+ size_t blocks;
+ size_t inodes;
+ blocks = group->size - rtems_rfs_bitmap_map_free (&group->block_bitmap);
+ inodes = fs->group_inodes - rtems_rfs_bitmap_map_free (&group->inode_bitmap);
+ printf (" %4d: base=%-7" PRIu32 " size=%-6zu blocks=%-5zu (%3zu%%) inode=%-5zu (%3zu%%)\n",
+ g, group->base, group->size,
+ blocks, (blocks * 100) / group->size,
+ inodes, (inodes * 100) / fs->group_inodes);
+ }
+
+ rtems_rfs_shell_unlock_rfs (fs);
+
+ return 0;
+}
+
+
+void
+rtems_rfs_shell_usage (const char* arg)
+{
+ printf ("%s: RFS debugger\n", arg);
+ printf (" %s [-hl] <path> <command>\n", arg);
+ printf (" where:\n");
+ printf (" path: Path to the mounted RFS file system\n");
+ printf (" command: A debugger command. See -l for a list plus help.\n");
+ printf (" -h: This help\n");
+ printf (" -l: The debugger command list.\n");
+}
+
+int
+rtems_shell_debugrfs (int argc, char *argv[])
+{
+ const rtems_rfs_shell_cmd table[] =
+ {
+ { "block", rtems_rfs_shell_block,
+ "Display the contents of a block, block <bno>, block <bno>..<bno>" },
+ { "data", rtems_rfs_shell_data,
+ "Display file system data, data" },
+ { "dir", rtems_rfs_shell_dir,
+ "Display a block as a table for directory entrie, dir <bno>" },
+ { "group", rtems_rfs_shell_group,
+ "Display the group data of a file system, group, group <group>, group <start> <end>" },
+ { "inode", rtems_rfs_shell_inode,
+ "Display an inode, inode <ino>, inode> <ino>..<ino>" }
+ };
+
+ int arg;
+ int t;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] != '-')
+ break;
+
+ switch (argv[arg][1])
+ {
+ case 'h':
+ rtems_rfs_shell_usage (argv[0]);
+ return 0;
+ case 'l':
+ printf ("%s: commands are:\n", argv[0]);
+ for (t = 0; t < (sizeof (table) / sizeof (const rtems_rfs_shell_cmd)); t++)
+ printf (" %s\t\t%s\n", table[t].name, table[t].help);
+ return 0;
+ default:
+ printf ("error: unknown option: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+
+ if ((argc - arg) < 2)
+ printf ("error: you need at least a path and command, try %s -h\n", argv[0]);
+ else
+ {
+ rtems_rfs_file_system* fs;
+ if (rtems_rfs_get_fs (argv[arg], &fs) == 0)
+ {
+ for (t = 0; t < (sizeof (table) / sizeof (const rtems_rfs_shell_cmd)); t++)
+ if (strcmp (argv[arg + 1], table[t].name) == 0)
+ return table[t].handler (fs, argc - 2, argv + 2);
+ printf ("error: command not found: %s\n", argv[arg + 1]);
+ }
+ }
+
+ return 1;
+}
+
+int
+rtems_shell_rfs_format (int argc, char* argv[])
+{
+ rtems_rfs_format_config config;
+ const char* driver = NULL;
+ int arg;
+
+ memset (&config, 0, sizeof (rtems_rfs_format_config));
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][1])
+ {
+ case 'v':
+ config.verbose = true;
+ break;
+
+ case 's':
+ arg++;
+ if (arg >= argc)
+ {
+ printf ("error: block size needs an argument\n");
+ return 1;
+ }
+ config.block_size = strtoul (argv[arg], 0, 0);
+ break;
+
+ case 'b':
+ arg++;
+ if (arg >= argc)
+ {
+ printf ("error: group block count needs an argument\n");
+ return 1;
+ }
+ config.group_blocks = strtoul (argv[arg], 0, 0);
+ break;
+
+ case 'i':
+ arg++;
+ if (arg >= argc)
+ {
+ printf ("error: group inode count needs an argument\n");
+ return 1;
+ }
+ config.group_inodes = strtoul (argv[arg], 0, 0);
+ break;
+
+ case 'I':
+ config.initialise_inodes = true;
+ break;
+
+ case 'o':
+ arg++;
+ if (arg >= argc)
+ {
+ printf ("error: inode percentage overhead needs an argument\n");
+ return 1;
+ }
+ config.inode_overhead = strtoul (argv[arg], 0, 0);
+ break;
+
+ default:
+ printf ("error: invalid option: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ else
+ {
+ if (!driver)
+ driver = argv[arg];
+ else
+ {
+ printf ("error: only one driver name allowed: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+ if (!driver) {
+ printf ("error: no driver name provided\n");
+ return 1;
+ }
+
+ if (rtems_rfs_format (driver, &config) < 0)
+ {
+ printf ("error: format of %s failed: %s\n",
+ driver, strerror (errno));
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-shell.h b/cpukit/libfs/src/rfs/rtems-rfs-shell.h
new file mode 100644
index 0000000000..c07b7c3167
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-shell.h
@@ -0,0 +1,44 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Shell commands provide a CLI interface to support and
+ * development od the RFS file system.
+ */
+
+#if !defined (_RTEMS_RFS_SHELL_H_)
+#define _RTEMS_RFS_SHELL_H_
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+/**
+ * The shell command for the RFS debugger.
+ *
+ * @param argc The argument count.
+ * @param argv The argument variables.
+ * @return int The exit code for the command. A 0 is no error.
+ */
+int rtems_shell_debugrfs (int argc, char *argv[]);
+
+/**
+ * The shell command for formatting an RFS file system.
+ *
+ * @param argc The argument count.
+ * @param argv The argument variables.
+ * @return int The exit code for the command. A 0 is no error.
+ */
+int rtems_shell_rfs_format (int argc, char* argv[]);
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-trace.c b/cpukit/libfs/src/rfs/rtems-rfs-trace.c
new file mode 100644
index 0000000000..d96a63673b
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-trace.c
@@ -0,0 +1,159 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Trace Support
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <rtems/rfs/rtems-rfs-trace.h>
+
+#if RTEMS_RFS_TRACE
+static rtems_rfs_trace_mask rtems_rfs_trace_flags;
+
+bool
+rtems_rfs_trace (rtems_rfs_trace_mask mask)
+{
+ bool result = false;
+ if (mask & rtems_rfs_trace_flags)
+ result = true;
+ return result;
+}
+
+rtems_rfs_trace_mask
+rtems_rfs_trace_set_mask (rtems_rfs_trace_mask mask)
+{
+ rtems_rfs_trace_mask state = rtems_rfs_trace_flags;
+ rtems_rfs_trace_flags |= mask;
+ return state;
+}
+
+rtems_rfs_trace_mask
+rtems_rfs_trace_clear_mask (rtems_rfs_trace_mask mask)
+{
+ rtems_rfs_trace_mask state = rtems_rfs_trace_flags;
+ rtems_rfs_trace_flags &= ~mask;
+ return state;
+}
+
+int
+rtems_rfs_trace_shell_command (int argc, char *argv[])
+{
+ const char* table[] =
+ {
+ "open",
+ "close",
+ "mutex",
+ "buffer-open",
+ "buffer-close",
+ "buffer-sync",
+ "buffer-release",
+ "buffer-chains",
+ "buffer-handle-request",
+ "buffer-handle-release",
+ "buffer-setblksize",
+ "buffers-release",
+ "block-find",
+ "block-map-grow",
+ "block-map-shrink",
+ "group-open",
+ "group-close",
+ "group-bitmaps",
+ "inode-open",
+ "inode-close",
+ "inode-load",
+ "inode-unload",
+ "inode-create",
+ "inode-delete",
+ "link",
+ "unlink",
+ "dir-lookup-ino",
+ "dir-lookup-ino-check",
+ "dir-lookup-ino-found",
+ "dir-add-entry",
+ "dir-del-entry",
+ "dir-read",
+ "dir-empty",
+ "symlink",
+ "symlink-read",
+ "file-open",
+ "file-close",
+ "file-io"
+ };
+
+ rtems_rfs_trace_mask set_value = 0;
+ rtems_rfs_trace_mask clear_value = 0;
+ bool set = true;
+ int arg;
+ int t;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][1])
+ {
+ case 'h':
+ printf ("usage: %s [-hl] [set/clear] [flags]\n", argv[0]);
+ return 0;
+ case 'l':
+ printf ("%s: valid flags to set or clear are:\n", argv[0]);
+ for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
+ printf (" %s\n", table[t]);
+ return 0;
+ default:
+ printf ("error: unknown option\n");
+ return 1;
+ }
+ }
+ else
+ {
+ if (strcmp (argv[arg], "set") == 0)
+ set = true;
+ if (strcmp (argv[arg], "clear") == 0)
+ set = false;
+ else if (strcmp (argv[arg], "all") == 0)
+ {
+ if (set)
+ set_value = RTEMS_RFS_TRACE_ALL;
+ else
+ clear_value = RTEMS_RFS_TRACE_ALL;
+ }
+ else
+ {
+ for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
+ {
+ if (strcmp (argv[arg], table[t]) == 0)
+ {
+ if (set)
+ set_value = 1 << t;
+ else
+ clear_value = 1 << t;
+ break;
+ }
+ }
+ }
+
+ rtems_rfs_trace_flags |= set_value;
+ rtems_rfs_trace_flags &= ~clear_value;
+ }
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-trace.h b/cpukit/libfs/src/rfs/rtems-rfs-trace.h
new file mode 100644
index 0000000000..05d9258c7d
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs-trace.h
@@ -0,0 +1,129 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File Systems Trace manages the trace and debugging features of the
+ * RTEMS RFS file system. The design allows all tracing code and strings to be
+ * removed from the target code for small footprint systems.
+ */
+
+#if !defined (_RTEMS_RFS_TRACE_H_)
+#define _RTEMS_RFS_TRACE_H_
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+
+/**
+ * Is tracing enabled ?
+ */
+#if !defined (RTEMS_RFS_TRACE)
+#define RTEMS_RFS_TRACE 1
+#endif
+
+/**
+ * The type of the mask.
+ */
+typedef uint64_t rtems_rfs_trace_mask;
+
+/**
+ * List of tracing bits for the various parts of the file system.
+ */
+#define RTEMS_RFS_TRACE_ALL (0xffffffffffffffffULL)
+#define RTEMS_RFS_TRACE_OPEN (1ULL << 0)
+#define RTEMS_RFS_TRACE_CLOSE (1ULL << 1)
+#define RTEMS_RFS_TRACE_MUTEX (1ULL << 2)
+#define RTEMS_RFS_TRACE_BUFFER_OPEN (1ULL << 3)
+#define RTEMS_RFS_TRACE_BUFFER_CLOSE (1ULL << 4)
+#define RTEMS_RFS_TRACE_BUFFER_SYNC (1ULL << 5)
+#define RTEMS_RFS_TRACE_BUFFER_RELEASE (1ULL << 6)
+#define RTEMS_RFS_TRACE_BUFFER_CHAINS (1ULL << 7)
+#define RTEMS_RFS_TRACE_BUFFER_HANDLE_REQUEST (1ULL << 8)
+#define RTEMS_RFS_TRACE_BUFFER_HANDLE_RELEASE (1ULL << 9)
+#define RTEMS_RFS_TRACE_BUFFER_SETBLKSIZE (1ULL << 10)
+#define RTEMS_RFS_TRACE_BUFFERS_RELEASE (1ULL << 11)
+#define RTEMS_RFS_TRACE_BLOCK_FIND (1ULL << 12)
+#define RTEMS_RFS_TRACE_BLOCK_MAP_GROW (1ULL << 13)
+#define RTEMS_RFS_TRACE_BLOCK_MAP_SHRINK (1ULL << 14)
+#define RTEMS_RFS_TRACE_GROUP_OPEN (1ULL << 15)
+#define RTEMS_RFS_TRACE_GROUP_CLOSE (1ULL << 16)
+#define RTEMS_RFS_TRACE_GROUP_BITMAPS (1ULL << 17)
+#define RTEMS_RFS_TRACE_INODE_OPEN (1ULL << 18)
+#define RTEMS_RFS_TRACE_INODE_CLOSE (1ULL << 19)
+#define RTEMS_RFS_TRACE_INODE_LOAD (1ULL << 20)
+#define RTEMS_RFS_TRACE_INODE_UNLOAD (1ULL << 21)
+#define RTEMS_RFS_TRACE_INODE_CREATE (1ULL << 22)
+#define RTEMS_RFS_TRACE_INODE_DELETE (1ULL << 23)
+#define RTEMS_RFS_TRACE_LINK (1ULL << 24)
+#define RTEMS_RFS_TRACE_UNLINK (1ULL << 25)
+#define RTEMS_RFS_TRACE_DIR_LOOKUP_INO (1ULL << 26)
+#define RTEMS_RFS_TRACE_DIR_LOOKUP_INO_CHECK (1ULL << 27)
+#define RTEMS_RFS_TRACE_DIR_LOOKUP_INO_FOUND (1ULL << 28)
+#define RTEMS_RFS_TRACE_DIR_ADD_ENTRY (1ULL << 29)
+#define RTEMS_RFS_TRACE_DIR_DEL_ENTRY (1ULL << 30)
+#define RTEMS_RFS_TRACE_DIR_READ (1ULL << 31)
+#define RTEMS_RFS_TRACE_DIR_EMPTY (1ULL << 32)
+#define RTEMS_RFS_TRACE_SYMLINK (1ULL << 33)
+#define RTEMS_RFS_TRACE_SYMLINK_READ (1ULL << 34)
+#define RTEMS_RFS_TRACE_FILE_OPEN (1ULL << 35)
+#define RTEMS_RFS_TRACE_FILE_CLOSE (1ULL << 36)
+#define RTEMS_RFS_TRACE_FILE_IO (1ULL << 37)
+#define RTEMS_RFS_TRACE_FILE_SET (1ULL << 38)
+
+/**
+ * Call to check if this part is bring traced. If RTEMS_RFS_TRACE is defined to
+ * 0 the code is dead code elminiated when built with -Os, -O2, or higher.
+ *
+ * @param mask The part of the API to trace.
+ * @retval true Tracing is active for the mask.
+ * @retval false Do not trace.
+ */
+#if RTEMS_RFS_TRACE
+bool rtems_rfs_trace (rtems_rfs_trace_mask mask);
+#else
+#define rtems_rfs_trace(_m) (0)
+#endif
+
+/**
+ * Set the mask.
+ *
+ * @param mask The mask bits to set.
+ * @return The previous mask.
+ */
+#if RTEMS_RFS_TRACE
+rtems_rfs_trace_mask rtems_rfs_trace_set_mask (rtems_rfs_trace_mask mask);
+#else
+#define rtems_rfs_trace_set_mask(_m)
+#endif
+
+/**
+ * Clear the mask.
+ *
+ * @param mask The mask bits to clear.
+ * @return The previous mask.
+ */
+#if RTEMS_RFS_TRACE
+rtems_rfs_trace_mask rtems_rfs_trace_clear_mask (rtems_rfs_trace_mask mask);
+#else
+#define rtems_rfs_trace_clear_mask(_m)
+#endif
+
+/**
+ * Add shell trace shell command.
+ */
+#if RTEMS_RFS_TRACE
+int rtems_rfs_trace_shell_command (int argc, char *argv[]);
+#endif
+
+#endif
diff --git a/cpukit/libfs/src/rfs/rtems-rfs.h b/cpukit/libfs/src/rfs/rtems-rfs.h
new file mode 100644
index 0000000000..ca5a6f3051
--- /dev/null
+++ b/cpukit/libfs/src/rfs/rtems-rfs.h
@@ -0,0 +1,30 @@
+/*
+ * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/**
+ * @file
+ *
+ * @ingroup rtems-rfs
+ *
+ * RTEMS File System
+ *
+ */
+
+#if !defined(RTEMS_RFS_DEFINED)
+#define RTEMS_RFS_DEFINED
+
+#include <rtems.h>
+#include <rtems/fs.h>
+
+/**
+ * Initialise the RFS File system.
+ */
+int rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t *mt_entry);
+
+#endif
diff --git a/cpukit/libgnat/.cvsignore b/cpukit/libgnat/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libgnat/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libgnat/Makefile.am b/cpukit/libgnat/Makefile.am
new file mode 100644
index 0000000000..85414cb8cb
--- /dev/null
+++ b/cpukit/libgnat/Makefile.am
@@ -0,0 +1,17 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+EXTRA_DIST=
+
+if LIBGNAT
+AM_CPPFLAGS += -D__RTEMS_INSIDE__
+
+noinst_LIBRARIES = libgnat.a
+
+libgnat_a_SOURCES = ada_intrsupp.c adasupp.c
+endif
+
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libgnat/ada_intrsupp.c b/cpukit/libgnat/ada_intrsupp.c
new file mode 100644
index 0000000000..5f9c19281f
--- /dev/null
+++ b/cpukit/libgnat/ada_intrsupp.c
@@ -0,0 +1,146 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/bspIo.h>
+
+rtems_id __gnat_binary_semaphore_create(void)
+{
+ rtems_status_code status;
+ rtems_id semaphore;
+
+ status = rtems_semaphore_create(
+ rtems_build_name( 'A', 'I', 'S', 'R' ),
+ 0,
+ RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO,
+ 0,
+ &semaphore
+ );
+ if ( status != RTEMS_SUCCESSFUL )
+ printk( "__gnat_binary_semaphore_create failed %d\n", status );
+
+ #if defined(GNAT_DEBUG)
+ printk( "__gnat_binary_semaphore_create\n" );
+ #endif
+ return semaphore;
+}
+
+int __gnat_binary_semaphore_delete(
+ rtems_id semaphore
+)
+{
+ rtems_status_code status;
+
+ #if defined(GNAT_DEBUG)
+ printk( "__gnat_binary_semaphore_delete\n" );
+ #endif
+
+ status = rtems_semaphore_delete( semaphore );
+ if ( status != RTEMS_SUCCESSFUL )
+ printk( "__gnat_binary_semaphore_delete failed %d\n", status );
+
+ return 0;
+}
+
+int __gnat_binary_semaphore_obtain(
+ rtems_id semaphore
+)
+{
+ rtems_status_code status;
+
+ #if defined(GNAT_DEBUG)
+ printk( "__gnat_binary_semaphore_obtain\n" );
+ #endif
+
+ status = rtems_semaphore_obtain( semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+ if ( status != RTEMS_SUCCESSFUL )
+ printk( "__gnat_binary_semaphore_obtain failed %d\n", status );
+
+ return 0;
+}
+
+int __gnat_binary_semaphore_release(
+ rtems_id semaphore
+)
+{
+ rtems_status_code status;
+
+ #if defined(GNAT_DEBUG)
+ printk( "__gnat_binary_semaphore_release\n" );
+ #endif
+
+ status = rtems_semaphore_release( semaphore );
+ if ( status != RTEMS_SUCCESSFUL )
+ printk( "__gnat_binary_semaphore_release failed %d\n", status );
+
+ return 0;
+}
+
+int __gnat_binary_semaphore_flush(
+ rtems_id semaphore
+)
+{
+ rtems_status_code status;
+
+ printk( "__gnat_binary_semaphore_flush\n" );
+
+ status = rtems_semaphore_flush( semaphore );
+ if ( status != RTEMS_SUCCESSFUL )
+ printk( "__gnat_binary_semaphore_flush failed %d\n", status );
+
+ return 0;
+}
+
+typedef void (*ISRHandler)(void*);
+ void *set_vector( void *, rtems_vector_number, int );
+
+int __gnat_interrupt_connect(
+ int vector,
+ ISRHandler handler,
+ void *parameter
+)
+{
+ printk( "__gnat_interrupt_connect( %d, %p, %p )\n", vector, handler, parameter );
+ set_vector( handler, vector, 1 );
+ return 0;
+}
+
+int __gnat_interrupt_set(
+ int vector,
+ ISRHandler handler
+)
+{
+ printk( "__gnat_interrupt_set( %d, %p )\n", vector, handler );
+
+ set_vector( handler, vector, 1 );
+ return 0;
+}
+
+ISRHandler __gnat_interrupt_get(
+ int vector
+)
+{
+ printk( "__gnat_interrupt_get( %d )\n", vector );
+ return 0;
+}
+
+int __gnat_interrupt_number_to_vector(
+ int intNum
+)
+{
+ printk( "__gnat_interrupt_number_to_vector( %d )\n", intNum );
+ return intNum;
+}
+
diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c
new file mode 100644
index 0000000000..5af4730a65
--- /dev/null
+++ b/cpukit/libgnat/adasupp.c
@@ -0,0 +1,36 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/posix/pthread.h>
+
+/*
+ * _ada_pthread_minimum_stack_size
+ *
+ * This routine returns the minimum stack size so the GNAT RTS can
+ * allocate enough stack for Ada tasks.
+ */
+
+size_t _ada_pthread_minimum_stack_size( void )
+{
+ /*
+ * Eventually this may need to include a per cpu family calculation
+ * but for now, this will do.
+ */
+
+ return PTHREAD_MINIMUM_STACK_SIZE * 2;
+}
+
+uint32_t _ada_microseconds_per_tick(void)
+{
+ return rtems_configuration_get_microseconds_per_tick();
+}
diff --git a/cpukit/libi2c/.cvsignore b/cpukit/libi2c/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libi2c/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libi2c/Makefile.am b/cpukit/libi2c/Makefile.am
new file mode 100644
index 0000000000..c422529bc8
--- /dev/null
+++ b/cpukit/libi2c/Makefile.am
@@ -0,0 +1,11 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+noinst_LIBRARIES = libi2c.a
+
+libi2c_a_SOURCES = libi2c.c libi2c.h
+
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libi2c/README_libi2c b/cpukit/libi2c/README_libi2c
new file mode 100644
index 0000000000..f1a8fd017e
--- /dev/null
+++ b/cpukit/libi2c/README_libi2c
@@ -0,0 +1,367 @@
+#
+# $Id$
+#
+
+=====================
+Copyright and License
+=====================
+
+For Copyright and License of the source code, see the header in
+libi2c.c.
+
+=========
+Overview
+========
+
+This directory contains a general I2C/SPI API library. It offers a
+standard API to I2C or SPI based device drivers, abstracting the low
+level driver (dealing with the I2C/SPI controller hardware of the
+board) from the high-level drivers (dealing with devices connected to
+the I2C or SPI bus).
+
+In most cases throughout this document, i2c and spi devices are
+handled in a similar way. Therefore spi will not be explicitly named
+in every location.
+
+=========
+Features
+=========
+
+ + supports multiple i2c and/or spi busses
+
+ + supports multiple devices connected to each i2c/spi bus
+
+ + handles bus and device registration to the I/O manager
+
+=========
+Structure
+=========
+
+This library defines a layered API to i2c and spi devices. The
+layering is:
+
+ +----------------------------------------+
+ 6| Application |
+ +----------------------------------------+
+ 5| RTEMS I/O Manager |
+ +----------------------------------------+
+ 4|** libi2c OS adaption layer **|
+ +----------------------------------------+
+ 3| high level i2c device driver |
+ | (EEPROM, RTC, ...) |
+ | (e.g. in c/src/libchip/i2c) |
+ +----------------------------------------+
+ 2|** libi2c low level abstraction layer **|
+ +----------------------------------------+
+ 1| i2c controller driver |
+ | (in BSP) |
+ +----------------------------------------+
+
+This document will describe the following interfaces in separate
+sections:
+
+ + the interface between the RTEMS I/O Manager and the libi2c OS
+ interface (5<->4)
+
+ + the interface between the libi2c OS interface and the high level
+ i2c device driver (4<->3)
+
+ + the interface between the high level i2c device driver and the
+ libi2c low level abstraction layer (3<->2)
+
+ + the interface between the libi2c low level abstraction layer and
+ the i2c controller driver (2<->1)
+
+===================================
+Differences between i2c and spi bus
+===================================
+SPI and I2C has many similarities, but also some differences:
+
+- I2C uses inband addressing (the first bits sent select, which slave
+device is addressed) while SPI uses dedicated select lines to address
+a slave device
+
+- SPI supports combined full duplex read-write transactions while I2C
+either sends or receives data from a slave device
+
+- SPI supports a varity of per-slave options, which include:
+ - number of bits per character to transfer
+ - polarity and phase of clock wrt data
+ - clock frequency
+
+The libi2c API defines a superset of functions to handle both flavours
+of serial data transmission, but care should be taken not to use
+features dedicated to the wrong type of serial bus.
+
+
+======================
+Library Initialization
+======================
+Before any libi2c API is used, the library must be initialized. This
+is achived with a call to function
+
+ rtems_libi2c_initialize ().
+
+It creates a global mutex to lock internal data structures and
+registers the OS adaption layer to the RTEMS I/O manager.
+
+Any subsequent call to this function will be silently ignored.
+
+Typically the BSP startup code will perform this initialization.
+
+A proper place for initializing the i2c layer and populating it
+with busses and device drivers (see 'Bus Registration' and
+'Device/Driver Registration' below) is the 'predriver_hook'
+where most facilities (such as malloc, libio) are already
+available. Note, however, that 'stdio' is not yet functional
+at this point and all i2c bus and device drivers should carefully
+avoid using stdio so that other drivers which may build on top
+of i2c devices may be initialized properly (this may happen
+just after 'predriver_hook' when stdio is still not available).
+E.g., drivers listed in the configuration table are initialized
+during this step.
+
+Note that while 'libi2c' could be initialized from the rtems
+configuration table like other drivers there is no easy
+way of populating the i2c framework with bus- and device-
+drivers at this point (unless a special 'i2c' configuration
+table describing the bus layout is implemented in the future).
+
+For the time being, we must rely on the BSP (predriver_hook)
+to initialize the i2c system if it is used by other drivers
+(e.g., the RTC driver may have to use a i2c device).
+
+===================
+Bus Registration
+===================
+Each i2c and/or spi bus available must be registerd with a call to
+
+int rtems_libi2c_register_bus (char *name,
+ rtems_libi2c_bus_t * bus)
+
+It registers the bus to the libi2c internal data structures and
+creates a device node in the RTEMS filesystem with the given name. If
+no name is given (name==NULL), then the default name "/dev/i2c" is
+used instead.
+
+With the second calling parameter "rtems_libi2c_bus_t * bus" the
+caller passes in a set of function pointers, which define the entries
+into the i2c controller driver (defined in the BSP).
+
+This call returns an integer bus number, which can be used in
+subsequent calls to register devices attached to this bus (see below).
+
+Typically the BSP startup code will perform this registration for each
+bus available on the board.
+
+==========================
+Device/Driver Registration
+==========================
+Each device attached to an i2c or spi bus must be registered with a
+call to
+
+int
+rtems_libi2c_register_drv (char *name, rtems_libi2c_drv_t * drvtbl,
+ unsigned bus, unsigned i2caddr);
+
+With this call, libi2c is informed, that:
+
+- a device is attached to the given "bus" number (which in fact is the
+return value received from a previous rtems_libi2c_register_bus()
+call) with the address "i2caddr"
+
+- the device is managed by a driver, who's entry functions are listed
+ in "drvtbl"
+
+- the device should be registered with the given "name" in the device
+ tree of the filesystem.
+
+The call will create a proper minor device number, which has the bus
+number and i2c_address encoded. This minor number is the return value
+of the call and is also associated with the filesystem node created
+for this device.
+
+Note: If you have multiple devices of the same type, you must register
+each of them through a separate call (with the same "drvtbl", but
+different name/bus/i2caddr).
+
+====================================================================
+(5<->4) RTEMS I/O Manager and the libi2c OS adaption layer IF
+====================================================================
+
+The RTEMS I/O Manager regards the libi2c OS adaption layer as a normal
+RTEMS Device Driver with one unique major number and a set of minor
+numbers, one for each bus and one for each device attached to one of
+the busses.
+
+Therefore the libi2c OS adaption layer provides the standard calls:
+
+static rtems_driver_address_table libi2c_io_ops = {
+ initialization_entry: i2c_init,
+ open_entry: i2c_open,
+ close_entry: i2c_close,
+ read_entry: i2c_read,
+ write_entry: i2c_write,
+ control_entry: i2c_ioctl
+};
+
+These calls perform some parameter checking and then call the
+appropriate high level i2c device driver function, if available,
+according to the entries in the "drvtbl" passed in the
+rtems_libi2c_register_drv() call.
+
+There are two exceptions: when i2c_read or i2c_write is called with a
+minor number specifying a bus (and not a device attached to the bus),
+then the respective transfer is performed as a raw byte stream
+transfer to the bus.
+
+The main reason for the libi2c OS adaption layer is, that it
+dispatches the RTEMS I/O Manager calls to the proper device driver
+according to the minor number used.
+
+====================================================================
+libi2c OS adaption layer and the high level i2c device driver IF
+====================================================================
+
+Each high level i2c device driver provides a set of functions in the
+rtems_libi2c_drv_t data structure passed the libi2c when the device is
+registered (see "Device registration" above). These function directly match
+the RTEMS I/O Mangers calls "open", "close", "read", "write",
+"control", and they are passed the same arguments. Functions not
+needed may be ommited (and replaced by a NULL pointer in
+rtems_libi2c_drv_t).
+
+======================================================================
+high level i2c device driver and libi2c low level abstraction layer IF
+======================================================================
+libi2c provides a set of functions for the high level drivers. These
+functions are:
+
+rtems_libi2c_send_start();
+rtems_libi2c_send_stop();
+rtems_libi2c_send_addr();
+rtems_libi2c_read_bytes();
+rtems_libi2c_write_bytes();
+rtems_libi2c_start_read_bytes();
+rtems_libi2c_start_write_bytes();
+rtems_libi2c_ioctl();
+
+Please look into libi2c.h for the proper parameters and return codes.
+
+These functions perform the proper i2c operations when called.
+
+A typical access sequence for the I2C bus would be:
+
+rtems_libi2c_send_start();
+rtems_libi2c_send_addr();
+rtems_libi2c_write_bytes();
+rtems_libi2c_send_stop();
+
+Alternatively, the rtems_libi2c_write_bytes() call could be relpaced
+with a
+ rtems_libi2c_read_bytes()
+
+call or a sequence of multiple calls.
+
+Note: rtems_libi2c_send_start() locks the i2c/spi bus used, so no other
+device can use this i2c/spi bus, until rtems_libi2c_send_stop() function
+is called for the same device.
+
+Special provisions for SPI devices:
+===================================
+For SPI devices and their drivers, the libi2c interface is used
+slightly differently:
+
+rtems_libi2c_send_start() will lock access to the SPI bus, but has no
+effect on the hardware bus interface.
+
+rtems_libi2c_ioctl(...,RTEMS_LIBI2C_IOCTL_SET_TFRMODE,...) will set
+the transfer mode (bit rate, clock phase and polaritiy, bits per
+char...) according to the rtems_libi2c_tfr_mode_t structure passed in.
+
+rtems_libi2c_send_addr() will activate the proper select line to
+address a certain SPI device. The correspondance between an address
+and the select line pulled is BSP specific.
+
+rtems_libi2c_send_stop(); will deactivate the address line and unlock
+the bus.
+
+A typical access sequence for the SPI bus would be:
+
+rtems_libi2c_send_start();
+rtems_libi2c_ioctl(...,RTEMS_LIBI2C_IOCTL_SET_TFRMODE,...);
+rtems_libi2c_send_addr();
+rtems_libi2c_write_bytes();
+rtems_libi2c_send_stop();
+
+Alternatively, the rtems_libi2c_write_bytes() call could be relpaced
+with a
+ rtems_libi2c_read_bytes()
+or a
+ rtems_libi2c_ioctl(...,RTEMS_LIBI2C_IOCTL_READ_WRITE,...)
+call or a sequence of multiple calls.
+
+====================================================================
+libi2c low level abstraction layer and i2c controller driver IF
+====================================================================
+Each low level i2c/spi driver must provide a set of bus_ops functions
+as defined in the rtems_libi2c_bus_ops_t structure.
+
+typedef struct rtems_libi2c_bus_ops_
+{
+ /* Initialize the bus; might be called again to reset the bus driver */
+ rtems_status_code (*init) (rtems_libi2c_bus_t * bushdl);
+ /* Send start condition */
+ rtems_status_code (*send_start) (rtems_libi2c_bus_t * bushdl);
+ /* Send stop condition */
+ rtems_status_code (*send_stop) (rtems_libi2c_bus_t * bushdl);
+ /* initiate transfer from (rw!=0) or to a device */
+ rtems_status_code (*send_addr) (rtems_libi2c_bus_t * bushdl,
+ uint32_t addr, int rw);
+ /* read a number of bytes */
+ int (*read_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes,
+ int nbytes);
+ /* write a number of bytes */
+ int (*write_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes,
+ int nbytes);
+ /* ioctl misc functions */
+ int (*ioctl) (rtems_libi2c_bus_t * bushdl,
+ int cmd,
+ void *buffer;
+ );
+} rtems_libi2c_bus_ops_t;
+
+Each of these functions performs the corresponding function to the i2c
+bus.
+
+Special provisions for SPI devices:
+===================================
+For SPI busses, special behaviour is required:
+
+(*send_start) (rtems_libi2c_bus_t * bushdl)
+ normally is an empty function.
+
+ (*send_addr) (rtems_libi2c_bus_t * bushdl, uint32_t addr, int rw)
+ will activate the SPI select line matching to addr.
+
+(*send_stop) (rtems_libi2c_bus_t * bushdl)
+ will deactivate the SPI select line
+
+(*ioctl(...,RTEMS_LIBI2C_IOCTL_SET_TFRMODE,...)
+ will set the transfer mode (bit rate, clock phase and
+ polaritiy, bits per char...) according to the
+ rtems_libi2c_tfr_mode_t structure passed in.
+
+(*ioctl(...,RTEMS_LIBI2C_IOCTL_READ_WRITE,...)
+ will send and receive data at the same time.
+
+Note:
+
+- low-level I2C drivers normally are specific to the master
+device, but independent from the board hardware. So in many cases they
+can totally reside in libcpu or libchip.
+
+- low-level SPI drivers are mostly board independent, but the
+ addressing is board/BSP dependent. Therefore the (*send_start),
+ (*send_addr) and (*send_stop) functions are typically defined in the
+ BSP. The rest of the functions can reside in libcpu or libchip.
diff --git a/cpukit/libi2c/libi2c.c b/cpukit/libi2c/libi2c.c
new file mode 100644
index 0000000000..1f88968aab
--- /dev/null
+++ b/cpukit/libi2c/libi2c.c
@@ -0,0 +1,778 @@
+/* $Id$ */
+
+/* libi2c Implementation */
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2005,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+/*
+ * adaptations to also handle SPI devices
+ * by Thomas Doerfler, embedded brains GmbH, Puchheim, Germany
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdarg.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/bspIo.h>
+#include <rtems/libio.h>
+
+#include <rtems/libi2c.h>
+
+#define DRVNM "libi2c: "
+
+#define MAX_NO_BUSSES 8 /* Also limited by the macro building minor numbers */
+#define MAX_NO_DRIVERS 16 /* Number of high level drivers we support */
+
+#define MINOR2ADDR(minor) ((minor)&((1<<10)-1))
+#define MINOR2BUS(minor) (((minor)>>10)&7)
+#define MINOR2DRV(minor) ((minor)>>13)
+
+/* Check the 'minor' argument, i.e., verify that
+ * we have a driver connected
+ */
+#define DECL_CHECKED_BH(b, bh, m, s)\
+ unsigned b = MINOR2BUS(m); \
+ rtems_libi2c_bus_t *bh; \
+ if ( b >= MAX_NO_BUSSES || 0 == (bh=busses[b].bush) ) { \
+ return s RTEMS_INVALID_NUMBER; \
+ }
+
+#define DECL_CHECKED_DRV(d, b, m) \
+ unsigned d = MINOR2DRV(m); \
+ unsigned b = MINOR2BUS(m); \
+ if ( b >= MAX_NO_BUSSES || 0 == busses[b].bush \
+ || d > MAX_NO_DRIVERS || (d && 0 == drvs[d-1].drv )) {\
+ return RTEMS_INVALID_NUMBER; \
+ }
+
+#define DISPATCH(rval, entry, dflt) \
+ do { \
+ const rtems_driver_address_table *ops = drvs[--drv].drv->ops; \
+ rval = ops->entry ? ops->entry(major,minor,arg) : dflt; \
+ } while (0)
+
+
+rtems_device_major_number rtems_libi2c_major;
+
+static bool is_initialized = false;
+
+static struct i2cbus
+{
+ rtems_libi2c_bus_t *bush;
+ volatile rtems_id mutex; /* lock this across start -> stop */
+ volatile bool started;
+ char *name;
+} busses[MAX_NO_BUSSES] = { { NULL, RTEMS_ID_NONE, false, NULL } };
+
+static struct
+{
+ rtems_libi2c_drv_t *drv;
+} drvs[MAX_NO_DRIVERS] = { { NULL } };
+
+static rtems_id libmutex = RTEMS_ID_NONE;
+
+#define LOCK(m) assert(!rtems_semaphore_obtain((m), RTEMS_WAIT, RTEMS_NO_TIMEOUT))
+#define UNLOCK(m) rtems_semaphore_release((m))
+
+#define LIBLOCK() LOCK(libmutex)
+#define LIBUNLOCK() UNLOCK(libmutex)
+
+#define MUTEX_ATTS \
+ ( RTEMS_PRIORITY \
+ | RTEMS_BINARY_SEMAPHORE \
+ |RTEMS_INHERIT_PRIORITY \
+ |RTEMS_NO_PRIORITY_CEILING \
+ |RTEMS_LOCAL )
+
+/* During early stages of life, stdio is not available */
+
+static void
+safe_printf (const char *fmt, ...)
+{
+va_list ap;
+
+ va_start(ap, fmt);
+ if ( _System_state_Is_up( _System_state_Get() ) )
+ vfprintf( stderr, fmt, ap );
+ else
+ vprintk( fmt, ap );
+ va_end(ap);
+}
+
+static rtems_status_code
+mutexCreate (rtems_name nm, rtems_id *pm)
+{
+ rtems_status_code sc;
+
+ if (RTEMS_SUCCESSFUL !=
+ (sc = rtems_semaphore_create (nm, 1, MUTEX_ATTS, 0, pm))) {
+ if ( _System_state_Is_up( _System_state_Get() ) )
+ rtems_error (sc, DRVNM "Unable to create mutex\n");
+ else
+ printk (DRVNM "Unable to create mutex (status code %i)\n", sc);
+ }
+ return sc;
+}
+
+/* Lock a bus avoiding to have a mutex, which is mostly
+ * unused, hanging around all the time. We just create
+ * and delete it on the fly...
+ *
+ * ASSUMES: argument checked by caller
+ */
+
+static void
+lock_bus (int busno)
+{
+ struct i2cbus *bus = &busses[busno];
+
+ if (bus->mutex == RTEMS_ID_NONE) {
+ /*
+ * Nobody is holding the bus mutex - it's not there. Create it on the fly.
+ */
+ LIBLOCK ();
+ if (bus->mutex == RTEMS_ID_NONE) {
+ rtems_id m = RTEMS_ID_NONE;
+ rtems_status_code sc = mutexCreate (
+ rtems_build_name ('i', '2', 'c', '0' + busno),
+ &m
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ LIBUNLOCK ();
+ rtems_panic (DRVNM "Unable to create bus lock");
+ return;
+ }
+ bus->mutex = m;
+ }
+ LIBUNLOCK ();
+ }
+
+ /* Now lock this bus */
+ LOCK (bus->mutex);
+}
+
+static void
+unlock_bus (int busno)
+{
+ struct i2cbus *bus = &busses[busno];
+ UNLOCK (bus->mutex);
+}
+
+/* Note that 'arg' is always passed in as NULL */
+rtems_status_code
+rtems_i2c_init (rtems_device_major_number major, rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_status_code rval;
+ /* No busses or drivers can be registered at this point;
+ * avoid the macro aborting with an error
+ DECL_CHECKED_DRV (drv, busno, minor)
+ */
+
+ rval = mutexCreate (rtems_build_name ('l', 'I', '2', 'C'), &libmutex);
+
+ if ( RTEMS_SUCCESSFUL == rval ) {
+ is_initialized = true;
+ rtems_libi2c_major = major;
+ } else {
+ libmutex = RTEMS_ID_NONE;
+ }
+ return rval;
+}
+
+rtems_status_code
+rtems_i2c_open (rtems_device_major_number major, rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_status_code rval;
+ DECL_CHECKED_DRV (drv, busno, minor)
+
+ if (0 == drv) {
+ rval = RTEMS_SUCCESSFUL;
+ } else {
+ DISPATCH (rval, open_entry, RTEMS_SUCCESSFUL);
+ }
+ return rval;
+}
+
+rtems_status_code
+rtems_i2c_close (rtems_device_major_number major, rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_status_code rval;
+ DECL_CHECKED_DRV (drv, busno, minor)
+
+ if (0 == drv) {
+ rval = RTEMS_SUCCESSFUL;
+ } else {
+ DISPATCH (rval, close_entry, RTEMS_SUCCESSFUL);
+ }
+ return rval;
+}
+
+rtems_status_code
+rtems_i2c_read (rtems_device_major_number major, rtems_device_minor_number minor,
+ void *arg)
+{
+ int rval; /* int so we can check for negative value */
+ rtems_libio_rw_args_t *rwargs = arg;
+ DECL_CHECKED_DRV (drv, busno, minor)
+
+ if (0 == rwargs->count) {
+ rwargs->bytes_moved = 0;
+ return RTEMS_SUCCESSFUL;
+ }
+
+ if (0 == drv) {
+ rval =
+ rtems_libi2c_start_read_bytes (minor, (unsigned char *) rwargs->buffer,
+ rwargs->count);
+ if (rval >= 0) {
+ rwargs->bytes_moved = rval;
+ rtems_libi2c_send_stop (minor);
+ rval = RTEMS_SUCCESSFUL;
+ } else {
+ rval = -rval;
+ }
+ } else {
+ DISPATCH (rval, read_entry, RTEMS_NOT_IMPLEMENTED);
+ }
+ return rval;
+}
+
+rtems_status_code
+rtems_i2c_write (rtems_device_major_number major, rtems_device_minor_number minor,
+ void *arg)
+{
+ int rval; /* int so we can check for negative value */
+ rtems_libio_rw_args_t *rwargs = arg;
+ DECL_CHECKED_DRV (drv, busno, minor)
+
+ if (0 == rwargs->count) {
+ rwargs->bytes_moved = 0;
+ return RTEMS_SUCCESSFUL;
+ }
+
+ if (0 == drv) {
+ rval =
+ rtems_libi2c_start_write_bytes (minor, (unsigned char *) rwargs->buffer,
+ rwargs->count);
+ if (rval >= 0) {
+ rwargs->bytes_moved = rval;
+ rtems_libi2c_send_stop (minor);
+ rval = RTEMS_SUCCESSFUL;
+ } else {
+ rval = -rval;
+ }
+ } else {
+ DISPATCH (rval, write_entry, RTEMS_NOT_IMPLEMENTED);
+ }
+ return rval;
+}
+
+rtems_status_code
+rtems_i2c_ioctl (rtems_device_major_number major, rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_status_code rval;
+ DECL_CHECKED_DRV (drv, busno, minor)
+
+ if (0 == drv) {
+ rval = RTEMS_NOT_IMPLEMENTED;
+ } else {
+ DISPATCH (rval, control_entry, RTEMS_NOT_IMPLEMENTED);
+ }
+ return rval;
+}
+
+
+/* Our ops just dispatch to the registered drivers */
+const rtems_driver_address_table rtems_libi2c_io_ops = {
+ initialization_entry: rtems_i2c_init,
+ open_entry: rtems_i2c_open,
+ close_entry: rtems_i2c_close,
+ read_entry: rtems_i2c_read,
+ write_entry: rtems_i2c_write,
+ control_entry: rtems_i2c_ioctl,
+};
+
+int
+rtems_libi2c_initialize (void)
+{
+ rtems_status_code sc;
+
+ if (is_initialized) {
+ /*
+ * already called before? then skip this step
+ */
+ return 0;
+ }
+
+ /* rtems_io_register_driver does NOT currently check nor report back
+ * the return code of the 'init' operation, so we cannot
+ * rely on return code since it may seem OK even if the driver 'init;
+ * op failed.
+ * Let 'init' handle 'is_initialized'...
+ */
+ sc = rtems_io_register_driver (0, &rtems_libi2c_io_ops, &rtems_libi2c_major);
+ if (RTEMS_SUCCESSFUL != sc) {
+ safe_printf(
+ DRVNM "Claiming driver slot failed (rtems status code %i)\n",
+ sc);
+ if (libmutex != RTEMS_ID_NONE) {
+ rtems_semaphore_delete (libmutex);
+ }
+ libmutex = RTEMS_ID_NONE;
+ is_initialized = false;
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus)
+{
+ int i;
+ rtems_status_code err;
+ size_t length = (name ? strlen (name) + 1 : 20);
+ char *nmcpy = malloc(length);
+ char tmp, *chpt;
+ struct stat sbuf;
+
+ if (nmcpy == NULL) {
+ safe_printf ( DRVNM "No memory\n");
+ return -RTEMS_NO_MEMORY;
+ }
+
+ strncpy (nmcpy, name ? name : "/dev/i2c", length);
+
+ /* check */
+ if ('/' != *nmcpy) {
+ safe_printf ( DRVNM "Bad name: must be an absolute path starting with '/'\n");
+ free( nmcpy );
+ return -RTEMS_INVALID_NAME;
+ }
+ /* file must not exist */
+ if (!stat (nmcpy, &sbuf)) {
+ safe_printf ( DRVNM "Bad name: file exists already\n");
+ free( nmcpy );
+ return -RTEMS_INVALID_NAME;
+ }
+
+ /* we already verified that there is at least one '/' */
+ chpt = strrchr (nmcpy, '/') + 1;
+ tmp = *chpt;
+ *chpt = 0;
+ i = stat (nmcpy, &sbuf);
+ *chpt = tmp;
+ if (i) {
+ safe_printf ( DRVNM "Get %s status failed: %s\n",
+ nmcpy, strerror(errno));
+ free( nmcpy );
+ return -RTEMS_INVALID_NAME;
+ }
+ /* should be a directory since name terminates in '/' */
+
+
+ if (libmutex == RTEMS_ID_NONE) {
+ safe_printf ( DRVNM "Library not initialized\n");
+ free( nmcpy );
+ return -RTEMS_NOT_DEFINED;
+ }
+
+ if (bus == NULL || bus->size < sizeof (*bus)) {
+ safe_printf ( DRVNM "No bus-ops or size too small -- misconfiguration?\n");
+ free( nmcpy );
+ return -RTEMS_NOT_CONFIGURED;
+ }
+
+ LIBLOCK ();
+ for (i = 0; i < MAX_NO_BUSSES; i++) {
+ if (!busses[i].bush) {
+ /* found a free slot */
+ busses[i].bush = bus;
+ busses[i].mutex = RTEMS_ID_NONE;
+ busses[i].started = false;
+
+ if (!name)
+ sprintf (nmcpy + strlen (nmcpy), "%i", i);
+
+ if ((err = busses[i].bush->ops->init (busses[i].bush))) {
+ /* initialization failed */
+ i = -err;
+ } else {
+ busses[i].name = nmcpy;;
+ nmcpy = 0;
+ }
+
+ break;
+ }
+ }
+ LIBUNLOCK ();
+
+ if (i >= MAX_NO_BUSSES) {
+ i = -RTEMS_TOO_MANY;
+ }
+
+ free (nmcpy);
+
+ return i;
+}
+
+static int
+not_started (int busno)
+{
+ int rval;
+ lock_bus (busno);
+ rval = !busses[busno].started;
+ unlock_bus (busno);
+ return rval;
+}
+
+rtems_status_code
+rtems_libi2c_send_start (rtems_device_minor_number minor)
+{
+ int rval;
+ DECL_CHECKED_BH (busno, bush, minor, +)
+
+ lock_bus (busno);
+ rval = bush->ops->send_start (bush);
+
+ /* if this failed or is not the first start, unlock */
+ if (rval || busses[busno].started) {
+ /* HMM - what to do if the 1st start failed ?
+ * try to reset...
+ */
+ if (!busses[busno].started) {
+ /* just in case the bus driver fiddles with errno */
+ int errno_saved = errno;
+ bush->ops->init (bush);
+ errno = errno_saved;
+ } else if (rval) {
+ /* failed restart */
+ rtems_libi2c_send_stop (minor);
+ }
+ unlock_bus (busno);
+ } else {
+ /* successful 1st start; keep bus locked until stop is sent */
+ busses[busno].started = true;
+ }
+ return rval;
+}
+
+rtems_status_code
+rtems_libi2c_send_stop (rtems_device_minor_number minor)
+{
+ rtems_status_code rval;
+ DECL_CHECKED_BH (busno, bush, minor, +)
+
+ if (not_started (busno))
+ return RTEMS_NOT_OWNER_OF_RESOURCE;
+
+ rval = bush->ops->send_stop (bush);
+
+ busses[busno].started = false;
+
+ unlock_bus (busno);
+ return rval;
+}
+
+rtems_status_code
+rtems_libi2c_send_addr (rtems_device_minor_number minor, int rw)
+{
+ rtems_status_code sc;
+ DECL_CHECKED_BH (busno, bush, minor, +)
+
+ if (not_started (busno))
+ return RTEMS_NOT_OWNER_OF_RESOURCE;
+
+ sc = bush->ops->send_addr (bush, MINOR2ADDR (minor), rw);
+ if (RTEMS_SUCCESSFUL != sc)
+ rtems_libi2c_send_stop (minor);
+ return sc;
+}
+
+int
+rtems_libi2c_read_bytes (rtems_device_minor_number minor,
+ unsigned char *bytes,
+ int nbytes)
+{
+ int sc;
+ DECL_CHECKED_BH (busno, bush, minor, -)
+
+ if (not_started (busno))
+ return -RTEMS_NOT_OWNER_OF_RESOURCE;
+
+ sc = bush->ops->read_bytes (bush, bytes, nbytes);
+ if (sc < 0)
+ rtems_libi2c_send_stop (minor);
+ return sc;
+}
+
+int
+rtems_libi2c_write_bytes (rtems_device_minor_number minor,
+ const unsigned char *bytes,
+ int nbytes)
+{
+ int sc;
+ DECL_CHECKED_BH (busno, bush, minor, -)
+
+ if (not_started (busno))
+ return -RTEMS_NOT_OWNER_OF_RESOURCE;
+
+ sc = bush->ops->write_bytes (bush, (unsigned char *)bytes, nbytes);
+ if (sc < 0)
+ rtems_libi2c_send_stop (minor);
+ return sc;
+}
+
+int
+rtems_libi2c_ioctl (rtems_device_minor_number minor,
+ int cmd,
+ ...)
+{
+ va_list ap;
+ int sc = 0;
+ void *args;
+ bool is_started = false;
+ DECL_CHECKED_BH (busno, bush, minor, -)
+
+ va_start(ap, cmd);
+ args = va_arg(ap, void *);
+
+ switch(cmd) {
+ /*
+ * add ioctls defined for this level here:
+ */
+
+ case RTEMS_LIBI2C_IOCTL_GET_DRV_T:
+ /*
+ * query driver table entry
+ */
+ *(rtems_libi2c_drv_t **)args = (drvs[MINOR2DRV(minor)-1].drv);
+ break;
+
+ case RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE:
+ if (not_started (busno)) {
+ va_end(ap);
+ return -RTEMS_NOT_OWNER_OF_RESOURCE;
+ }
+
+ /*
+ * address device, then set transfer mode and perform read_write transfer
+ */
+ /*
+ * perform start/address
+ */
+ if (sc == 0) {
+ sc = rtems_libi2c_send_start (minor);
+ is_started = (sc == 0);
+ }
+ /*
+ * set tfr mode
+ */
+ if (sc == 0) {
+ sc = bush->ops->ioctl
+ (bush,
+ RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
+ &((rtems_libi2c_tfm_read_write_t *)args)->tfr_mode);
+ }
+ /*
+ * perform read_write
+ */
+ if (sc == 0) {
+ sc = bush->ops->ioctl
+ (bush,
+ RTEMS_LIBI2C_IOCTL_READ_WRITE,
+ &((rtems_libi2c_tfm_read_write_t *)args)->rd_wr);
+ }
+ if ((sc < 0) && (is_started)) {
+ rtems_libi2c_send_stop (minor);
+ }
+ break;
+ default:
+ sc = bush->ops->ioctl (bush, cmd, args);
+ break;
+ }
+ va_end(ap);
+ return sc;
+}
+
+static int
+do_s_rw (rtems_device_minor_number minor,
+ unsigned char *bytes,
+ int nbytes,
+ int rw)
+{
+ rtems_status_code sc;
+ rtems_libi2c_bus_t *bush;
+ int status;
+
+ if ((sc = rtems_libi2c_send_start (minor)))
+ return -sc;
+
+ /* at this point, we hold the bus and are sure the minor number is valid */
+ bush = busses[MINOR2BUS (minor)].bush;
+
+ if ((sc = bush->ops->send_addr (bush, MINOR2ADDR (minor), rw))) {
+ rtems_libi2c_send_stop (minor);
+ return -sc;
+ }
+
+ if (rw)
+ status = bush->ops->read_bytes (bush, bytes, nbytes);
+ else
+ status = bush->ops->write_bytes (bush, bytes, nbytes);
+
+ if (status < 0) {
+ rtems_libi2c_send_stop (minor);
+ }
+ return status;
+}
+
+int
+rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
+ unsigned char *bytes,
+ int nbytes)
+{
+ return do_s_rw (minor, bytes, nbytes, 1);
+}
+
+int
+rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
+ const unsigned char *bytes,
+ int nbytes)
+{
+ return do_s_rw (minor, (unsigned char *)bytes, nbytes, 0);
+}
+
+int
+rtems_libi2c_register_drv (const char *name, rtems_libi2c_drv_t * drvtbl,
+ unsigned busno, unsigned i2caddr)
+{
+ int i;
+ rtems_status_code err;
+ rtems_device_minor_number minor;
+
+ if (libmutex == RTEMS_ID_NONE) {
+ safe_printf ( DRVNM "Library not initialized\n");
+ return -RTEMS_NOT_DEFINED;
+ }
+
+ if (name && strchr (name, '/')) {
+ safe_printf ( DRVNM "Invalid name: '%s' -- must not contain '/'\n", name);
+ return -RTEMS_INVALID_NAME;
+ }
+
+ if (busno >= MAX_NO_BUSSES || !busses[busno].bush || i2caddr >= 1 << 10) {
+ errno = EINVAL;
+ return -RTEMS_INVALID_NUMBER;
+ }
+
+ if (drvtbl == NULL || drvtbl->size < sizeof (*drvtbl)) {
+ safe_printf ( DRVNM "No driver table or size too small -- misconfiguration?\n");
+ return -RTEMS_NOT_CONFIGURED;
+ }
+
+ /* allocate slot */
+ LIBLOCK ();
+ for (i = 0; i < MAX_NO_DRIVERS; i++) {
+ /* driver # 0 is special, it is the built-in raw driver */
+ if (!drvs[i].drv) {
+ char *str;
+ dev_t dev;
+ uint32_t mode;
+
+ /* found a free slot; encode slot + 1 ! */
+ minor = ((i + 1) << 13) | RTEMS_LIBI2C_MAKE_MINOR (busno, i2caddr);
+
+ if (name) {
+ size_t length = strlen (busses[busno].name) + strlen (name) + 2;
+ str = malloc (length);
+ snprintf (str, length, "%s.%s", busses[busno].name, name);
+
+ dev = rtems_filesystem_make_dev_t (rtems_libi2c_major, minor);
+
+ mode = 0111 | S_IFCHR;
+ if (drvtbl->ops->read_entry)
+ mode |= 0444;
+ if (drvtbl->ops->write_entry)
+ mode |= 0222;
+
+ /* note that 'umask' is applied to 'mode' */
+ if (mknod (str, mode, dev)) {
+ safe_printf( DRVNM
+ "Creating device node failed: %s; you can try to do it manually...\n",
+ strerror (errno));
+ }
+
+ free (str);
+ }
+
+ drvs[i].drv = drvtbl;
+
+ if (drvtbl->ops->initialization_entry)
+ err =
+ drvs[i].drv->ops->initialization_entry (rtems_libi2c_major, minor,
+ 0);
+ else
+ err = RTEMS_SUCCESSFUL;
+
+ LIBUNLOCK ();
+ return err ? -err : minor;
+ }
+ }
+ LIBUNLOCK ();
+ return -RTEMS_TOO_MANY;
+}
diff --git a/cpukit/libi2c/libi2c.h b/cpukit/libi2c/libi2c.h
new file mode 100644
index 0000000000..89edcb95d1
--- /dev/null
+++ b/cpukit/libi2c/libi2c.h
@@ -0,0 +1,510 @@
+/**
+ * @file
+ *
+ * @ingroup libi2c
+ *
+ * @brief I2C library.
+ */
+
+#ifndef _RTEMS_LIBI2C_H
+#define _RTEMS_LIBI2C_H
+/*$Id$*/
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2005,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#include <rtems.h>
+
+#include <rtems/io.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup libi2c I2C Library
+ *
+ * @brief I2C library.
+ *
+ * @{
+ */
+
+/* Simple I2C driver API */
+
+/* Initialize the libary - may fail if no semaphore or no driver slot is available */
+extern int rtems_libi2c_initialize (void);
+
+/* Alternatively to rtems_libi2c_initialize() the library can also be
+ * initialized by means of a traditional driver table entry containing
+ * the following entry points:
+ */
+extern rtems_status_code
+rtems_i2c_init (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+
+extern rtems_status_code
+rtems_i2c_open (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+
+extern rtems_status_code
+rtems_i2c_close (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+
+extern rtems_status_code
+rtems_i2c_read (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+
+extern rtems_status_code
+rtems_i2c_write (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+
+extern rtems_status_code
+rtems_i2c_ioctl (
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+
+extern const rtems_driver_address_table rtems_libi2c_io_ops;
+
+/* Unfortunately, if you want to add this driver to
+ * a RTEMS configuration table then you need all the
+ * members explicitly :-( (Device_driver_table should
+ * hold pointers to rtems_driver_address_tables rather
+ * than full structs).
+ *
+ * The difficulty is that adding this driver to the
+ * configuration table is not enough; you still need
+ * to populate the framework with low-level bus-driver(s)
+ * and high-level drivers and/or device-files...
+ *
+ * Currently the preferred way is having the BSP
+ * call 'rtems_libi2c_initialize' followed by
+ * 'rtems_libi2c_register_bus' and
+ * 'rtems_libi2c_register_drv' and/or
+ * 'mknod' (for 'raw' device nodes)
+ * from the 'pretasking_hook'.
+ */
+#define RTEMS_LIBI2C_DRIVER_TABLE_ENTRY \
+{ \
+ initialization_entry: rtems_i2c_init, \
+ open_entry: rtems_i2c_open, \
+ close_entry: rtems_i2c_close, \
+ read_entry: rtems_i2c_read, \
+ write_entry: rtems_i2c_write, \
+ control_entry: rtems_i2c_ioctl, \
+}
+
+/* Bus Driver API
+ *
+ * Bus drivers provide access to low-level i2c functions
+ * such as 'send start', 'send address', 'get bytes' etc.
+ */
+
+/* first field must be a pointer to ops; driver
+ * may add its own fields after this.
+ * the struct that is registered with the library
+ * is not copied; a pointer will we passed
+ * to the callback functions (ops).
+ */
+typedef struct rtems_libi2c_bus_t_
+{
+ const struct rtems_libi2c_bus_ops_ *ops;
+ int size; /* size of whole structure */
+} rtems_libi2c_bus_t;
+
+/* Access functions a low level driver must provide;
+ *
+ * All of these, except read_bytes and write_bytes
+ * return RTEMS_SUCCESSFUL on success and an error status
+ * otherwise. The read and write ops return the number
+ * of chars read/written or -(status code) on error.
+ */
+typedef struct rtems_libi2c_bus_ops_
+{
+ /* Initialize the bus; might be called again to reset the bus driver */
+ rtems_status_code (*init) (rtems_libi2c_bus_t * bushdl);
+ /* Send start condition */
+ rtems_status_code (*send_start) (rtems_libi2c_bus_t * bushdl);
+ /* Send stop condition */
+ rtems_status_code (*send_stop) (rtems_libi2c_bus_t * bushdl);
+ /* initiate transfer from (rw!=0) or to a device */
+ rtems_status_code (*send_addr) (rtems_libi2c_bus_t * bushdl,
+ uint32_t addr, int rw);
+ /* read a number of bytes */
+ int (*read_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes,
+ int nbytes);
+ /* write a number of bytes */
+ int (*write_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes,
+ int nbytes);
+ /* ioctl misc functions */
+ int (*ioctl) (rtems_libi2c_bus_t * bushdl,
+ int cmd,
+ void *buffer
+ );
+} rtems_libi2c_bus_ops_t;
+
+
+/*
+ * Register a lowlevel driver
+ *
+ * TODO: better description
+ *
+ * This allocates a major number identifying *this* driver
+ * (i.e., libi2c) and the minor number encodes a bus# and a i2c address.
+ *
+ * The name will be registered in the filesystem (parent
+ * directories must exist, also IMFS filesystem must exist see
+ * CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM). It may be NULL in which case
+ * the library will pick a default.
+ *
+ * RETURNS: bus # (>=0) or -1 on error (errno set).
+ */
+
+extern int rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus);
+
+extern rtems_device_major_number rtems_libi2c_major;
+
+#define RTEMS_LIBI2C_MAKE_MINOR(busno, i2caddr) \
+ ((((busno)&((1<<3)-1))<<10) | ((i2caddr)&((1<<10)-1)))
+
+/* After the library is initialized, a major number is available.
+ * As soon as a low-level bus driver is registered (above routine
+ * returns a 'busno'), a device node can be created in the filesystem
+ * with a major/minor number pair of
+ *
+ * rtems_libi2c_major / RTEMS_LIBI2C_MAKE_MINOR(busno, i2caddr)
+ *
+ * and a 'raw' hi-level driver is then attached to this device
+ * node.
+ * This 'raw' driver has very simple semantics:
+ *
+ * 'open' sends a start condition
+ * 'read'/'write' address the device identified by the i2c bus# and address
+ * encoded in the minor number and read or write, respectively
+ * a stream of bytes from or to the device. Every time the
+ * direction is changed, a 're-start' condition followed by
+ * an 'address' cycle is generated on the i2c bus.
+ * 'close' sends a stop condition.
+ *
+ * Hence, using the 'raw' driver, e.g., 100 bytes at offset 0x200 can be
+ * read from an EEPROM by the following pseudo-code:
+ *
+ * mknod("/dev/i2c-54", mode, MKDEV(rtems_libi2c_major, RTEMS_LIBI2C_MAKE_MINOR(0,0x54)))
+ *
+ * int fd;
+ * char off[2]={0x02,0x00};
+ *
+ * fd = open("/dev/i2c-54",O_RDWR);
+ * write(fd,off,2);
+ * read(fd,buf,100);
+ * close(fd);
+ *
+ */
+
+/* Higher Level Driver API
+ *
+ * Higher level drivers know how to deal with specific i2c
+ * devices (independent of the bus interface chip) and provide
+ * an abstraction, i.e., the usual read/write/ioctl access.
+ *
+ * Using the above example, such a high level driver could
+ * prevent the user from issuing potentially destructive write
+ * operations (the aforementioned EEPROM interprets any 3rd
+ * and following byte written to the device as data, i.e., the
+ * contents could easily be changed!).
+ * The correct 'read-pointer offset' programming could be
+ * implemented in 'open' and 'ioctl' of a high-level driver and
+ * the user would then only have to perform harmless read
+ * operations, e.g.,
+ *
+ * fd = open("/dev/i2c.eeprom",O_RDONLY) / * opens and sets EEPROM read pointer * /
+ * ioctl(fd, IOCTL_SEEK, 0x200) / * repositions the read pointer * /
+ * read(fd, buf, 100)
+ * close(fd)
+ *
+ */
+
+/* struct provided at driver registration. The driver may store
+ * private data behind the mandatory first fields but the size
+ * must be set to the size of the entire struct, e.g.,
+ *
+ * struct driver_pvt {
+ * rtems_libi2c_drv_t pub;
+ * struct { ... } pvt;
+ * } my_driver = {
+ * { ops: my_ops,
+ * size: sizeof(my_driver)
+ * },
+ * { ...};
+ * };
+ *
+ * A pointer to this struct is passed to the callback ops.
+ */
+
+typedef struct rtems_libi2c_drv_t_
+{
+ const rtems_driver_address_table *ops; /* the driver ops */
+ int size; /* size of whole structure (including appended private data) */
+} rtems_libi2c_drv_t;
+
+/*
+ * The high level driver must be registered with a particular
+ * bus number and i2c address.
+ *
+ * The registration procedure also creates a filesystem node,
+ * i.e., the returned minor number is not really needed.
+ *
+ * If the 'name' argument is NULL, no filesystem node is
+ * created (but this can be done 'manually' using rtems_libi2c_major
+ * and the return value of this routine).
+ *
+ * RETURNS minor number (FYI) or -1 on failure
+ */
+extern int
+rtems_libi2c_register_drv (const char *name, rtems_libi2c_drv_t * drvtbl,
+ unsigned bus, unsigned i2caddr);
+
+/* Operations available to high level drivers */
+
+/* NOTES: The bus a device is attached to is LOCKED from the first send_start
+ * until send_stop is executed!
+ *
+ * Bus tenure MUST NOT span multiple system calls - otherwise, a single
+ * thread could get into the protected sections (or would deadlock if the
+ * mutex was not nestable).
+ * E.g., consider what happens if 'open' sends a 'start' and 'close'
+ * sends a 'stop' (i.e., the bus mutex would be locked in 'open' and
+ * released in 'close'. A single thread could try to open two devices
+ * on the same bus and would either deadlock or nest into the bus mutex
+ * and potentially mess up the i2c messages.
+ *
+ * The correct way is to *always* relinquish the i2c bus (i.e., send 'stop'
+ * from any driver routine prior to returning control to the caller.
+ * Consult the implementation of the generic driver routines (open, close, ...)
+ * below or the examples in i2c-2b-eeprom.c and i2c-2b-ds1621.c
+ *
+ * Drivers just pass the minor number on to these routines...
+ */
+extern rtems_status_code rtems_libi2c_send_start (rtems_device_minor_number minor);
+
+extern rtems_status_code rtems_libi2c_send_stop (rtems_device_minor_number minor);
+
+extern rtems_status_code
+rtems_libi2c_send_addr (rtems_device_minor_number minor, int rw);
+
+/* the read/write routines return the number of bytes transferred
+ * or -(status_code) on error.
+ */
+extern int
+rtems_libi2c_read_bytes (rtems_device_minor_number minor,
+ unsigned char *bytes, int nbytes);
+
+extern int
+rtems_libi2c_write_bytes (rtems_device_minor_number minor,
+ const unsigned char *bytes, int nbytes);
+
+/* Send start, send address and read bytes */
+extern int
+rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
+ unsigned char *bytes,
+ int nbytes);
+
+/* Send start, send address and write bytes */
+extern int
+rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
+ const unsigned char *bytes,
+ int nbytes);
+
+
+/* call misc iocontrol function */
+extern int
+rtems_libi2c_ioctl (rtems_device_minor_number minor,
+ int cmd,
+ ...);
+/*
+ * NOTE: any low-level driver ioctl returning a negative
+ * result for release the bus (perform a STOP condition)
+ */
+/*******************************
+ * defined IOCTLs:
+ *******************************/
+#define RTEMS_LIBI2C_IOCTL_READ_WRITE 1
+/*
+ * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
+ * RTEMS_LIBI2C_IOCTL_READ_WRITE,
+ * rtems_libi2c_read_write_t *arg);
+ *
+ * This call performs a simultanous read/write transfer,
+ * which is possible (and sometimes needed) for SPI devices
+ *
+ * arg is a pointer to a rd_wr info data structure
+ *
+ * This call is only needed for SPI devices
+ */
+#define RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE 2
+/*
+ * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
+ * RTEMS_LIBI2C_IOCTL_START_READ_WRITE,
+ * unsigned char *rd_buffer,
+ * const unsigned char *wr_buffer,
+ * int byte_cnt,
+ * const rtems_libi2c_tfr_mode_t *tfr_mode_ptr);
+ *
+ * This call addresses a slave and then:
+ * - sets the proper transfer mode,
+ * - performs a simultanous read/write transfer,
+ * (which is possible and sometimes needed for SPI devices)
+ * NOTE: - if rd_buffer is NULL, receive data will be dropped
+ * - if wr_buffer is NULL, bytes with content 0 will transmitted
+ *
+ * rd_buffer is a pointer to a receive buffer (or NULL)
+ * wr_buffer is a pointer to the data to be sent (or NULL)
+ *
+ * This call is only needed for SPI devices
+ */
+
+#define RTEMS_LIBI2C_IOCTL_SET_TFRMODE 3
+/*
+ * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
+ * RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
+ * const rtems_libi2c_tfr_mode_t *tfr_mode_ptr);
+ *
+ * This call sets an SPI device to the transfer mode needed (baudrate etc.)
+ *
+ * tfr_mode is a pointer to a structure defining the SPI transfer mode needed
+ * (see below).
+ *
+ * This call is only needed for SPI devices
+ */
+
+#define RTEMS_LIBI2C_IOCTL_GET_DRV_T 4
+
+/*
+ * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
+ * RTEMS_LIBI2C_IOCTL_GET_DRV_T,
+ * const rtems_libi2c_drv_t *drv_t_ptr);
+ *
+ * This call allows the a high-level driver to query its driver table entry,
+ * including its private data appended to it during creation of the entry
+ *
+ */
+
+/**
+ * @brief IO control command for asynchronous read and write.
+ *
+ * @see rtems_libi2c_read_write_done_t and rtems_libi2c_read_write_async_t.
+ *
+ * @warning This is work in progress!
+ */
+#define RTEMS_LIBI2C_IOCTL_READ_WRITE_ASYNC 5
+
+/*
+ * argument data structures for IOCTLs defined above
+ */
+typedef struct {
+ unsigned char *rd_buf;
+ const unsigned char *wr_buf;
+ int byte_cnt;
+} rtems_libi2c_read_write_t;
+
+typedef struct {
+ uint32_t baudrate; /* maximum bits per second */
+ /* only valid for SPI drivers: */
+ uint8_t bits_per_char; /* how many bits per byte/word/longword? */
+ bool lsb_first; /* true: send LSB first */
+ bool clock_inv; /* true: inverted clock (high active) */
+ bool clock_phs; /* true: clock starts toggling at start of data tfr */
+ uint32_t idle_char; /* This character will be continuously transmitted in read only functions */
+} rtems_libi2c_tfr_mode_t;
+
+typedef struct {
+ rtems_libi2c_tfr_mode_t tfr_mode;
+ rtems_libi2c_read_write_t rd_wr;
+} rtems_libi2c_tfm_read_write_t;
+
+/**
+ * @brief Notification function type for asynchronous read and write.
+ *
+ * @see RTEMS_LIBI2C_IOCTL_READ_WRITE_ASYNC and
+ * rtems_libi2c_read_write_async_t.
+ *
+ * @warning This is work in progress!
+ */
+typedef void (*rtems_libi2c_read_write_done_t) \
+ ( int /* return value */, int /* nbytes */, void * /* arg */);
+
+/**
+ * @brief IO command data for asynchronous read and write.
+ *
+ * @see RTEMS_LIBI2C_IOCTL_READ_WRITE_ASYNC and
+ * rtems_libi2c_read_write_done_t.
+ *
+ * @warning This is work in progress!
+ */
+typedef struct {
+ unsigned char *rd_buf;
+ const unsigned char *wr_buf;
+ int byte_cnt;
+ rtems_libi2c_read_write_done_t done;
+ void *arg;
+} rtems_libi2c_read_write_async_t;
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libmd/.cvsignore b/cpukit/libmd/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libmd/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libmd/Makefile.am b/cpukit/libmd/Makefile.am
new file mode 100644
index 0000000000..57a09b06fc
--- /dev/null
+++ b/cpukit/libmd/Makefile.am
@@ -0,0 +1,15 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+if NEWLIB
+noinst_LIBRARIES = libmd.a
+libmd_a_SOURCES = md5.h md5.c
+libmd_a_SOURCES += md4.h md4.c
+libmd_a_CPPFLAGS = $(AM_CPPFLAGS)
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libmd/md4.c b/cpukit/libmd/md4.c
new file mode 100644
index 0000000000..acbadc5d27
--- /dev/null
+++ b/cpukit/libmd/md4.c
@@ -0,0 +1,301 @@
+/*
+** ********************************************************************
+** md4.c -- Implementation of MD4 Message Digest Algorithm **
+** Updated: 2/16/90 by Ronald L. Rivest **
+** (C) 1990 RSA Data Security, Inc. **
+** ********************************************************************
+*/
+
+/*
+** To use MD4:
+** -- Include md4.h in your program
+** -- Declare an MDstruct MD to hold the state of the digest
+** computation.
+** -- Initialize MD using MDbegin(&MD)
+** -- For each full block (64 bytes) X you wish to process, call
+** MD4Update(&MD,X,512)
+** (512 is the number of bits in a full block.)
+** -- For the last block (less than 64 bytes) you wish to process,
+** MD4Update(&MD,X,n)
+** where n is the number of bits in the partial block. A partial
+** block terminates the computation, so every MD computation
+** should terminate by processing a partial block, even if it
+** has n = 0.
+** -- The message digest is available in MD.buffer[0] ...
+** MD.buffer[3]. (Least-significant byte of each word
+** should be output first.)
+** -- You can print out the digest using MDprint(&MD)
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Implementation notes:
+** This implementation assumes that ints are 32-bit quantities.
+*/
+
+/* Compile-time includes
+*/
+#include <stdio.h>
+#include "md4.h"
+
+#include <inttypes.h>
+
+/* Compile-time declarations of MD4 "magic constants".
+*/
+#define I0 0x67452301L /* Initial values for MD buffer */
+#define I1 0xefcdab89L
+#define I2 0x98badcfeL
+#define I3 0x10325476L
+#define C2 013240474631L /* round 2 constant = sqrt(2) in octal */
+#define C3 015666365641L /* round 3 constant = sqrt(3) in octal */
+/* C2 and C3 are from Knuth, The Art of Programming, Volume 2
+** (Seminumerical Algorithms), Second Edition (1981), Addison-Wesley.
+** Table 2, page 660.
+*/
+
+#define fs1 3 /* round 1 shift amounts */
+#define fs2 7
+#define fs3 11
+#define fs4 19
+#define gs1 3 /* round 2 shift amounts */
+#define gs2 5
+#define gs3 9
+#define gs4 13
+#define hs1 3 /* round 3 shift amounts */
+#define hs2 9
+#define hs3 11
+#define hs4 15
+
+/* Compile-time macro declarations for MD4.
+** Note: The "rot" operator uses the variable "tmp".
+** It assumes tmp is declared as unsigned int, so that the >>
+** operator will shift in zeros rather than extending the sign bit.
+*/
+#define f(X,Y,Z) ((X&Y) | ((~X)&Z))
+#define g(X,Y,Z) ((X&Y) | (X&Z) | (Y&Z))
+#define h(X,Y,Z) (X^Y^Z)
+#define rot(X,S) (tmp=X,(tmp<<S) | (tmp>>(32-S)))
+#define ff(A,B,C,D,i,s) A = rot((A + f(B,C,D) + X[i]),s)
+#define gg(A,B,C,D,i,s) A = rot((A + g(B,C,D) + X[i] + C2),s)
+#define hh(A,B,C,D,i,s) A = rot((A + h(B,C,D) + X[i] + C3),s)
+
+/* MD4print(MDp)
+** Print message digest buffer MDp as 32 hexadecimal digits.
+** Order is from low-order byte of buffer[0] to high-order byte of
+** buffer[3].
+** Each byte is printed with high-order hexadecimal digit first.
+** This is a user-callable routine.
+*/
+void
+MD4Print(
+ MD4_CTX *MDp)
+{
+ int i,j;
+ for (i=0;i<4;i++)
+ for (j=0;j<32;j=j+8)
+ printf("%02" PRIx32,(MDp->buffer[i]>>j) & 0xFF);
+}
+
+/* MD4Init(MDp)
+** Initialize message digest buffer MDp.
+** This is a user-callable routine.
+*/
+void
+MD4Init(
+ MD4_CTX *MDp)
+{
+ int i;
+ MDp->buffer[0] = I0;
+ MDp->buffer[1] = I1;
+ MDp->buffer[2] = I2;
+ MDp->buffer[3] = I3;
+ for (i=0;i<8;i++) MDp->count[i] = 0;
+ MDp->done = 0;
+}
+
+/* MDblock(MDp,X)
+** Update message digest buffer MDp->buffer using 16-word data block X.
+** Assumes all 16 words of X are full of data.
+** Does not update MDp->count.
+** This routine is not user-callable.
+*/
+static void
+MDblock(
+ MD4_CTX *MDp,
+ unsigned char *Xb)
+{
+ register uint32_t tmp, A, B, C, D;
+ uint32_t X[16];
+ int i;
+
+ for (i = 0; i < 16; ++i) {
+ X[i] = Xb[0] + ((uint32_t)Xb[1] << 8) +
+ ((uint32_t)Xb[2] << 16) + ((uint32_t)Xb[3] << 24);
+ Xb += 4;
+ }
+
+ A = MDp->buffer[0];
+ B = MDp->buffer[1];
+ C = MDp->buffer[2];
+ D = MDp->buffer[3];
+ /* Update the message digest buffer */
+ ff(A , B , C , D , 0 , fs1); /* Round 1 */
+ ff(D , A , B , C , 1 , fs2);
+ ff(C , D , A , B , 2 , fs3);
+ ff(B , C , D , A , 3 , fs4);
+ ff(A , B , C , D , 4 , fs1);
+ ff(D , A , B , C , 5 , fs2);
+ ff(C , D , A , B , 6 , fs3);
+ ff(B , C , D , A , 7 , fs4);
+ ff(A , B , C , D , 8 , fs1);
+ ff(D , A , B , C , 9 , fs2);
+ ff(C , D , A , B , 10 , fs3);
+ ff(B , C , D , A , 11 , fs4);
+ ff(A , B , C , D , 12 , fs1);
+ ff(D , A , B , C , 13 , fs2);
+ ff(C , D , A , B , 14 , fs3);
+ ff(B , C , D , A , 15 , fs4);
+ gg(A , B , C , D , 0 , gs1); /* Round 2 */
+ gg(D , A , B , C , 4 , gs2);
+ gg(C , D , A , B , 8 , gs3);
+ gg(B , C , D , A , 12 , gs4);
+ gg(A , B , C , D , 1 , gs1);
+ gg(D , A , B , C , 5 , gs2);
+ gg(C , D , A , B , 9 , gs3);
+ gg(B , C , D , A , 13 , gs4);
+ gg(A , B , C , D , 2 , gs1);
+ gg(D , A , B , C , 6 , gs2);
+ gg(C , D , A , B , 10 , gs3);
+ gg(B , C , D , A , 14 , gs4);
+ gg(A , B , C , D , 3 , gs1);
+ gg(D , A , B , C , 7 , gs2);
+ gg(C , D , A , B , 11 , gs3);
+ gg(B , C , D , A , 15 , gs4);
+ hh(A , B , C , D , 0 , hs1); /* Round 3 */
+ hh(D , A , B , C , 8 , hs2);
+ hh(C , D , A , B , 4 , hs3);
+ hh(B , C , D , A , 12 , hs4);
+ hh(A , B , C , D , 2 , hs1);
+ hh(D , A , B , C , 10 , hs2);
+ hh(C , D , A , B , 6 , hs3);
+ hh(B , C , D , A , 14 , hs4);
+ hh(A , B , C , D , 1 , hs1);
+ hh(D , A , B , C , 9 , hs2);
+ hh(C , D , A , B , 5 , hs3);
+ hh(B , C , D , A , 13 , hs4);
+ hh(A , B , C , D , 3 , hs1);
+ hh(D , A , B , C , 11 , hs2);
+ hh(C , D , A , B , 7 , hs3);
+ hh(B , C , D , A , 15 , hs4);
+ MDp->buffer[0] += A;
+ MDp->buffer[1] += B;
+ MDp->buffer[2] += C;
+ MDp->buffer[3] += D;
+}
+
+/* MD4Update(MDp,X,count)
+** Input: X -- a pointer to an array of unsigned characters.
+** count -- the number of bits of X to use.
+** (if not a multiple of 8, uses high bits of last byte.)
+** Update MDp using the number of bits of X given by count.
+** This is the basic input routine for an MD4 user.
+** The routine completes the MD computation when count < 512, so
+** every MD computation should end with one call to MD4Update with a
+** count less than 512. A call with count 0 will be ignored if the
+** MD has already been terminated (done != 0), so an extra call with
+** count 0 can be given as a "courtesy close" to force termination
+** if desired.
+*/
+void
+MD4Update(
+ MD4_CTX *MDp,
+ unsigned char *X,
+ unsigned int count )
+{
+ unsigned int i, tmp, bit, byte, mask;
+ unsigned char XX[64];
+ unsigned char *p;
+
+ /* return with no error if this is a courtesy close with count
+ ** zero and MDp->done is true.
+ */
+ if (count == 0 && MDp->done) return;
+ /* check to see if MD is already done and report error */
+ if (MDp->done)
+ { printf("\nError: MD4Update MD already done."); return; }
+
+ /* Add count to MDp->count */
+ tmp = count;
+ p = MDp->count;
+ while (tmp)
+ { tmp += *p;
+ *p++ = tmp;
+ tmp = tmp >> 8;
+ }
+
+ /* Process data */
+ if (count == 512)
+ { /* Full block of data to handle */
+ MDblock(MDp,X);
+ }
+ else if (count > 512) /* Check for count too large */
+ {
+ printf("\nError: MD4Update called with illegal count value %d.",
+ count);
+ return;
+ }
+ else /* partial block -- must be last block so finish up */
+ {
+ /* Find out how many bytes and residual bits there are */
+ byte = count >> 3;
+ bit = count & 7;
+ /* Copy X into XX since we need to modify it */
+ for (i=0;i<=byte;i++) XX[i] = X[i];
+ for (i=byte+1;i<64;i++) XX[i] = 0;
+ /* Add padding '1' bit and low-order zeros in last byte */
+ mask = 1 << (7 - bit);
+ XX[byte] = (XX[byte] | mask) & ~( mask - 1);
+ /* If room for bit count, finish up with this block */
+ if (byte <= 55)
+ {
+ for (i=0;i<8;i++) XX[56+i] = MDp->count[i];
+ MDblock(MDp,XX);
+ }
+ else /* need to do two blocks to finish up */
+ {
+ MDblock(MDp,XX);
+ for (i=0;i<56;i++) XX[i] = 0;
+ for (i=0;i<8;i++) XX[56+i] = MDp->count[i];
+ MDblock(MDp,XX);
+ }
+ /* Set flag saying we're done with MD computation */
+ MDp->done = 1;
+ }
+}
+
+/*
+** Finish up MD4 computation and return message digest.
+*/
+void
+MD4Final(
+ unsigned char *buf,
+ MD4_CTX *MD)
+{
+ int i, j;
+ unsigned int w;
+
+ MD4Update(MD, NULL, 0);
+ for (i = 0; i < 4; ++i) {
+ w = MD->buffer[i];
+ for (j = 0; j < 4; ++j) {
+ *buf++ = w;
+ w >>= 8;
+ }
+ }
+}
+
+/*
+** End of md4.c
+****************************(cut)***********************************/
diff --git a/cpukit/libmd/md4.h b/cpukit/libmd/md4.h
new file mode 100644
index 0000000000..0245486af6
--- /dev/null
+++ b/cpukit/libmd/md4.h
@@ -0,0 +1,57 @@
+
+/*
+** ********************************************************************
+** md4.h -- Header file for implementation of **
+** MD4 Message Digest Algorithm **
+** Updated: 2/13/90 by Ronald L. Rivest **
+** (C) 1990 RSA Data Security, Inc. **
+** ********************************************************************
+*/
+
+#include <stdint.h>
+
+/* MDstruct is the data structure for a message digest computation.
+*/
+typedef struct {
+ uint32_t buffer[4]; /* Holds 4-word result of MD computation */
+ uint8_t count[8]; /* Number of bits processed so far */
+ uint32_t done; /* Nonzero means MD computation finished */
+} MD4_CTX;
+
+/* MD4Init(MD4_CTX *)
+** Initialize the MD4_CTX prepatory to doing a message digest
+** computation.
+*/
+extern void MD4Init(MD4_CTX *MD);
+
+/* MD4Update(MD,X,count)
+** Input: X -- a pointer to an array of unsigned characters.
+** count -- the number of bits of X to use (an unsigned int).
+** Updates MD using the first "count" bits of X.
+** The array pointed to by X is not modified.
+** If count is not a multiple of 8, MD4Update uses high bits of
+** last byte.
+** This is the basic input routine for a user.
+** The routine terminates the MD computation when count < 512, so
+** every MD computation should end with one call to MD4Update with a
+** count less than 512. Zero is OK for a count.
+*/
+extern void MD4Update(MD4_CTX *MD, unsigned char *X, unsigned int count);
+
+/* MD4Print(MD)
+** Prints message digest buffer MD as 32 hexadecimal digits.
+** Order is from low-order byte of buffer[0] to high-order byte
+** of buffer[3].
+** Each byte is printed with high-order hexadecimal digit first.
+*/
+extern void MD4Print(MD4_CTX *);
+
+/* MD4Final(buf, MD)
+** Returns message digest from MD and terminates the message
+** digest computation.
+*/
+extern void MD4Final(unsigned char *, MD4_CTX *);
+
+/*
+** End of md4.h
+****************************(cut)***********************************/
diff --git a/cpukit/libmd/md5.c b/cpukit/libmd/md5.c
new file mode 100644
index 0000000000..b4c20f3c72
--- /dev/null
+++ b/cpukit/libmd/md5.c
@@ -0,0 +1,312 @@
+
+
+/*
+ ***********************************************************************
+ ** md5.c -- the source code for MD5 routines **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
+ ** Created: 2/17/90 RLR **
+ ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
+ ** **
+ ** License to copy and use this software is granted provided that **
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message- **
+ ** Digest Algorithm" in all material mentioning or referencing this **
+ ** software or this function. **
+ ** **
+ ** License is also granted to make and use derivative works **
+ ** provided that such works are identified as "derived from the RSA **
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
+ ** material mentioning or referencing the derived work. **
+ ** **
+ ** RSA Data Security, Inc. makes no representations concerning **
+ ** either the merchantability of this software or the suitability **
+ ** of this software for any particular purpose. It is provided "as **
+ ** is" without express or implied warranty of any kind. **
+ ** **
+ ** These notices must be retained in any copies of any part of this **
+ ** documentation and/or software. **
+ ***********************************************************************
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h> /* memcpy */
+
+#include "md5.h"
+
+/*
+ ***********************************************************************
+ ** Message-digest routines: **
+ ** To form the message digest for a message M **
+ ** (1) Initialize a context buffer mdContext using MD5Init **
+ ** (2) Call MD5Update on mdContext and M **
+ ** (3) Call MD5Final on mdContext **
+ ** The message digest is now in mdContext->digest[0...15] **
+ ***********************************************************************
+ */
+
+/* forward declaration */
+static void Transform (UINT4 *buf, UINT4 *in);
+
+static unsigned char PADDING[64] = {
+ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/* F, G, H and I are basic MD5 functions */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
+/* Rotation is separate from addition to prevent recomputation */
+#define FF(a, b, c, d, x, s, ac) \
+ {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) \
+ {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) \
+ {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) \
+ {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+#ifdef __STDC__
+#define UL(x) x##U
+#else
+#define UL(x) x
+#endif
+
+/* The routine MD5Init initializes the message-digest context
+ mdContext. All fields are set to zero.
+ */
+void MD5Init (
+ MD5_CTX *mdContext )
+{
+ mdContext->i[0] = mdContext->i[1] = (UINT4)0;
+
+ /* Load magic initialization constants.
+ */
+ mdContext->buf[0] = (UINT4)0x67452301;
+ mdContext->buf[1] = (UINT4)0xefcdab89;
+ mdContext->buf[2] = (UINT4)0x98badcfe;
+ mdContext->buf[3] = (UINT4)0x10325476;
+}
+
+/* The routine MD5Update updates the message-digest context to
+ account for the presence of each of the characters inBuf[0..inLen-1]
+ in the message whose digest is being computed.
+ */
+void MD5Update (
+ MD5_CTX *mdContext,
+ const unsigned char *inBuf,
+ unsigned int inLen )
+{
+ UINT4 in[16];
+ int mdi;
+ unsigned int i, ii;
+
+ /* compute number of bytes mod 64 */
+ mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
+
+ /* update number of bits */
+ if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
+ mdContext->i[1]++;
+ mdContext->i[0] += ((UINT4)inLen << 3);
+ mdContext->i[1] += ((UINT4)inLen >> 29);
+
+ while (inLen--) {
+ /* add new character to buffer, increment mdi */
+ mdContext->in[mdi++] = *inBuf++;
+
+ /* transform if necessary */
+ if (mdi == 0x40) {
+ for (i = 0, ii = 0; i < 16; i++, ii += 4)
+ in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+ (((UINT4)mdContext->in[ii+2]) << 16) |
+ (((UINT4)mdContext->in[ii+1]) << 8) |
+ ((UINT4)mdContext->in[ii]);
+ Transform (mdContext->buf, in);
+ mdi = 0;
+ }
+ }
+}
+
+/* The routine MD5Final terminates the message-digest computation and
+ ends with the desired message digest in mdContext->digest[0...15].
+ */
+void MD5Final (
+ unsigned char hash[],
+ MD5_CTX *mdContext )
+{
+ UINT4 in[16];
+ int mdi;
+ unsigned int i, ii;
+ unsigned int padLen;
+
+ /* save number of bits */
+ in[14] = mdContext->i[0];
+ in[15] = mdContext->i[1];
+
+ /* compute number of bytes mod 64 */
+ mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
+
+ /* pad out to 56 mod 64 */
+ padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
+ MD5Update (mdContext, PADDING, padLen);
+
+ /* append length in bits and transform */
+ for (i = 0, ii = 0; i < 14; i++, ii += 4)
+ in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+ (((UINT4)mdContext->in[ii+2]) << 16) |
+ (((UINT4)mdContext->in[ii+1]) << 8) |
+ ((UINT4)mdContext->in[ii]);
+ Transform (mdContext->buf, in);
+
+ /* store buffer in digest */
+ for (i = 0, ii = 0; i < 4; i++, ii += 4) {
+ mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
+ mdContext->digest[ii+1] =
+ (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
+ mdContext->digest[ii+2] =
+ (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
+ mdContext->digest[ii+3] =
+ (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
+ }
+ memcpy(hash, mdContext->digest, 16);
+}
+
+/* Basic MD5 step. Transforms buf based on in.
+ */
+static void Transform (
+ UINT4 *buf,
+ UINT4 *in )
+{
+ UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
+
+ /* Round 1 */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+ FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
+ FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
+ FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
+ FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
+ FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
+ FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
+ FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
+ FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
+ FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
+ FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
+ FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
+ FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
+ FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
+ FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
+ FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
+ FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
+
+ /* Round 2 */
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+ GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
+ GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
+ GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
+ GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
+ GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
+ GG ( d, a, b, c, in[10], S22, UL( 38016083)); /* 22 */
+ GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
+ GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
+ GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
+ GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
+ GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
+ GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
+ GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
+ GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
+ GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
+ GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
+
+ /* Round 3 */
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+ HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
+ HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
+ HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
+ HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
+ HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
+ HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
+ HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
+ HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
+ HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
+ HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
+ HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
+ HH ( b, c, d, a, in[ 6], S34, UL( 76029189)); /* 44 */
+ HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
+ HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
+ HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
+ HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
+
+ /* Round 4 */
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+ II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
+ II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
+ II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
+ II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
+ II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
+ II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
+ II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
+ II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
+ II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
+ II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
+ II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
+ II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
+ II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
+ II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
+ II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
+ II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+
+/*
+ ***********************************************************************
+ ** End of md5.c **
+ ******************************** (cut) ********************************
+ */
diff --git a/cpukit/libmd/md5.h b/cpukit/libmd/md5.h
new file mode 100644
index 0000000000..543c539bc1
--- /dev/null
+++ b/cpukit/libmd/md5.h
@@ -0,0 +1,68 @@
+/*
+ ***********************************************************************
+ ** md5.h -- header file for implementation of MD5 **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
+ ** Created: 2/17/90 RLR **
+ ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
+ ** Revised (for MD5): RLR 4/27/91 **
+ ** -- G modified to have y&~z instead of y&z **
+ ** -- FF, GG, HH modified to add in last register done **
+ ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
+ ** -- distinct additive constant for each step **
+ ** -- round 4 added, working mod 7 **
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
+ ** **
+ ** License to copy and use this software is granted provided that **
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message- **
+ ** Digest Algorithm" in all material mentioning or referencing this **
+ ** software or this function. **
+ ** **
+ ** License is also granted to make and use derivative works **
+ ** provided that such works are identified as "derived from the RSA **
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
+ ** material mentioning or referencing the derived work. **
+ ** **
+ ** RSA Data Security, Inc. makes no representations concerning **
+ ** either the merchantability of this software or the suitability **
+ ** of this software for any particular purpose. It is provided "as **
+ ** is" without express or implied warranty of any kind. **
+ ** **
+ ** These notices must be retained in any copies of any part of this **
+ ** documentation and/or software. **
+ ***********************************************************************
+ */
+
+#ifndef __MD5_INCLUDE__
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* typedef a 32-bit type */
+typedef uint32_t UINT4;
+
+/* Data structure for MD5 (Message-Digest) computation */
+typedef struct {
+ UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
+ UINT4 buf[4]; /* scratch buffer */
+ unsigned char in[64]; /* input buffer */
+ unsigned char digest[16]; /* actual digest after MD5Final call */
+} MD5_CTX;
+
+void MD5Init (MD5_CTX *);
+void MD5Update (MD5_CTX *, const unsigned char *, unsigned int);
+void MD5Final (unsigned char [16], MD5_CTX *);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#define __MD5_INCLUDE__
+#endif /* __MD5_INCLUDE__ */
diff --git a/cpukit/libmd/preinstall.am b/cpukit/libmd/preinstall.am
new file mode 100644
index 0000000000..dba6cc4d81
--- /dev/null
+++ b/cpukit/libmd/preinstall.am
@@ -0,0 +1,7 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
diff --git a/cpukit/libmisc/.cvsignore b/cpukit/libmisc/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libmisc/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
new file mode 100644
index 0000000000..f288f14f2b
--- /dev/null
+++ b/cpukit/libmisc/Makefile.am
@@ -0,0 +1,161 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+EXTRA_DIST = README
+
+noinst_LIBRARIES =
+
+## bspcmdline
+noinst_LIBRARIES += libbspcmdline.a
+libbspcmdline_a_SOURCES = bspcmdline/bspcmdline_get.c \
+ bspcmdline/bspcmdline_getparam.c bspcmdline/bspcmdline_getparamraw.c \
+ bspcmdline/bspcmdline_getparamrhs.c
+
+## capture
+EXTRA_DIST += capture/README
+
+noinst_LIBRARIES += libcapture.a
+libcapture_a_SOURCES = capture/capture.c capture/capture-cli.c \
+ capture/capture.h capture/capture-cli.h
+
+## cpuuse
+EXTRA_DIST += cpuuse/README
+
+noinst_LIBRARIES += libcpuuse.a
+libcpuuse_a_SOURCES = cpuuse/cpuusagereport.c cpuuse/cpuusagereset.c \
+ cpuuse/cpuuse.h cpuuse/cpuusagedata.c
+
+## devnull
+noinst_LIBRARIES += libdevnull.a
+libdevnull_a_SOURCES = devnull/devnull.c devnull/devnull.h
+
+## dummy
+EXTRA_DIST += dummy/README
+
+noinst_LIBRARIES += libdummy.a
+libdummy_a_SOURCES = dummy/dummy.c dummy/dummy-networking.c
+
+## dumpbuf
+noinst_LIBRARIES += libdumpbuf.a
+libdumpbuf_a_SOURCES = dumpbuf/dumpbuf.c dumpbuf/dumpbuf.h
+
+## monitor
+noinst_LIBRARIES += libmonitor.a
+libmonitor_a_SOURCES = monitor/mon-command.c monitor/mon-symbols.c \
+ monitor/mon-prmisc.c monitor/mon-monitor.c monitor/mon-object.c \
+ monitor/mon-server.c monitor/mon-task.c monitor/mon-queue.c \
+ monitor/mon-driver.c monitor/mon-itask.c monitor/mon-extension.c \
+ monitor/mon-manager.c monitor/mon-config.c monitor/mon-part.c \
+ monitor/mon-region.c monitor/mon-sema.c monitor/mon-editor.c \
+ monitor/symbols.h monitor/monitor.h
+if LIBNETWORKING
+libmonitor_a_SOURCES += monitor/mon-network.c
+endif
+if HAS_MP
+libmonitor_a_SOURCES += monitor/mon-mpci.c
+endif
+
+EXTRA_DIST += monitor/README
+
+## fb
+noinst_LIBRARIES += libmw-fb.a
+libmw_fb_a_SOURCES = fb/mw_print.c fb/mw_uid.c fb/fb.h fb/mw_uid.h
+
+## mouse
+noinst_LIBRARIES += libmouse.a
+libmouse_a_SOURCES = mouse/mouse_parser.c mouse/serial_mouse.c
+EXTRA_DIST += mouse/README
+
+## shell
+if LIBSHELL
+noinst_LIBRARIES += libshell.a
+libshell_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/shell
+libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \
+ shell/main_alias.c shell/main_cat.c shell/main_cd.c shell/cmp-ls.c \
+ shell/main_chdir.c shell/main_chmod.c shell/main_chroot.c \
+ shell/main_cp.c shell/main_cpuuse.c shell/main_date.c shell/main_dir.c \
+ shell/main_echo.c shell/main_exit.c shell/main_halt.c shell/main_help.c \
+ shell/main_id.c shell/main_logoff.c shell/main_ln.c shell/main_ls.c \
+ shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \
+ shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \
+ shell/main_mmove.c shell/main_msdosfmt.c \
+ shell/main_mv.c shell/main_mwdump.c shell/main_perioduse.c \
+ shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \
+ shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \
+ shell/main_unmount.c shell/main_blksync.c shell/main_whoami.c \
+ shell/shell.c shell/shell_cmdset.c shell/shell_getchar.c \
+ shell/shell_getprompt.c shell/shellconfig.c \
+ shell/shellconfig.h shell/shell.h shell/shell_makeargs.c \
+ shell/filemode.c shell/pwcache.c shell/print-ls.c \
+ shell/write_file.c shell/utils-cp.c shell/utils-ls.c \
+ shell/err.c shell/errx.c shell/verr.c shell/vis.c \
+ shell/verrx.c shell/vwarn.c shell/vwarnx.c shell/warn.c shell/warnx.c \
+ shell/fts.c shell/print_heapinfo.c shell/main_wkspaceinfo.c \
+ shell/shell_script.c shell/login_prompt.c shell/login_check.c \
+ shell/fdisk.c shell/main_rtc.c \
+ shell/dd-args.c shell/main_dd.c shell/dd-conv.c shell/dd-conv_tab.c \
+ shell/dd-misc.c shell/dd-position.c \
+ shell/main_hexdump.c shell/hexdump-conv.c shell/hexdump-display.c \
+ shell/hexdump-odsyntax.c shell/hexdump-parse.c shell/hexsyntax.c \
+ shell/main_time.c shell/main_mknod.c \
+ shell/main_setenv.c shell/main_getenv.c shell/main_unsetenv.c \
+ shell/main_mkrfs.c shell/main_debugrfs.c
+
+if LIBNETWORKING
+libshell_a_SOURCES += \
+ shell/main_ifconfig.c shell/main_route.c shell/main_netstats.c
+endif
+endif
+
+EXTRA_DIST += shell/README
+
+## serdbg
+
+if LIBSERDBG
+noinst_LIBRARIES += libserdbg.a
+libserdbg_a_SOURCES = serdbg/serdbg.c serdbg/serdbgio.c \
+ serdbg/termios_printk.c serdbg/serdbgcnf.h serdbg/serdbg.h \
+ serdbg/termios_printk_cnf.h serdbg/termios_printk.h
+endif
+
+EXTRA_DIST += serdbg/README
+
+## stackchk
+noinst_LIBRARIES += libstackchk.a
+libstackchk_a_SOURCES = stackchk/check.c stackchk/internal.h \
+ stackchk/stackchk.h
+
+EXTRA_DIST += stackchk/README
+
+## libuntar
+noinst_LIBRARIES += libuntar.a
+libuntar_a_SOURCES = untar/untar.c untar/untar.h
+
+EXTRA_DIST += untar/README
+
+## stringto
+noinst_LIBRARIES += libstringto.a
+libstringto_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/stringto
+libstringto_a_SOURCES = stringto/stringtodouble.c stringto/stringtofloat.c \
+ stringto/stringtolongdouble.c \
+ stringto/stringtoint.c stringto/stringtolong.c stringto/stringtolonglong.c \
+ stringto/stringtopointer.c stringto/stringtounsignedint.c \
+ stringto/stringtounsignedchar.c stringto/stringtounsignedlong.c \
+ stringto/stringtounsignedlonglong.c
+
+## fsmount
+noinst_LIBRARIES += libfsmount.a
+libfsmount_a_SOURCES = fsmount/fsmount.c fsmount/fsmount.h
+
+## uuid
+noinst_LIBRARIES += libuuid.a
+libuuid_a_SOURCES = uuid/clear.c uuid/compare.c uuid/copy.c uuid/gen_uuid.c \
+ uuid/isnull.c uuid/pack.c uuid/parse.c uuid/unpack.c uuid/unparse.c \
+ uuid/uuid_time.c uuid/uuidd.h uuid/uuidP.h
+
+## ---
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libmisc/README b/cpukit/libmisc/README
new file mode 100644
index 0000000000..bbde4feeae
--- /dev/null
+++ b/cpukit/libmisc/README
@@ -0,0 +1,23 @@
+#
+# $Id$
+#
+
+This directory contains for the "miscellaneous" library. Currently
+this library contains a number of useful support libraries:
+
+ + Task Stack Overflow Checker
+ + Workspace Consistency Checker
+ + Task Execution Time Monitor
+ + Period Statistics Monitor
+ + Debug Monitor
+
+The following ideas have been mentioned for items which could go
+in this library, but this list is not all inclusive:
+
+ + there are no outstanding suggestions.
+
+The intent of this library is to provide a home for useful utility routines
+which are dependent upon RTEMS.
+
+--joel
+16 Sept 97
diff --git a/cpukit/libmisc/bspcmdline/bspcmdline.h b/cpukit/libmisc/bspcmdline/bspcmdline.h
new file mode 100644
index 0000000000..6d5f716aeb
--- /dev/null
+++ b/cpukit/libmisc/bspcmdline/bspcmdline.h
@@ -0,0 +1,128 @@
+/**
+ * @file rtems/bspcmdline.h
+ *
+ * This include file contains all prototypes and specifications
+ * related to the BSP Command Line String and associated helper
+ * routines. The helpers are useful for locating command line
+ * type arguments (e.g. --mode) and their associated right
+ * hand side (e.g. FAST in --mode=FAST).
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __BSP_COMMAND_LINE_h
+#define __BSP_COMMAND_LINE_h
+
+/**
+ * @defgroup BSPCommandLine BSP Command Line Helpers
+ *
+ * The BSP Command Line Handler provides a set of routines which assist
+ * in examining and decoding the Command Line String passed to the BSP
+ * at boot time.
+ */
+/**@{*/
+
+#include <stddef.h> /* for size_t */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @brief Obtain Pointer to BSP Boot Command String
+ *
+ * This method returns a pointer to the BSP Boot Command String. It
+ * is as likely to be NULL as point to a string as most BSPs do not
+ * have a start environment that provides a boot string.
+ *
+ * @return This method returns the pointer to the BSP Boot Command String.
+ */
+const char *rtems_bsp_cmdline_get(void);
+
+/**
+ * @brief Obtain COPY of the Entire Matching Argument
+ *
+ * This method searches for the argument @a name in the BSP Boot Command
+ * String and returns a copy of the entire string associated with it in
+ * @a value up to a string of @a length. This will include the argument
+ * and any right hand side portion of the string. For example, one might
+ * be returned --mode=FAST if
+ * searching for --mode.
+ *
+ * @param[in] name is the arugment to search for
+ * @param[in] value points to where the contents will
+ * be placed if located.
+ * @param[in] length is the maximum length to copy
+ *
+ * @return This method returns NULL if not found and
+ * @a value if found.
+ */
+const char *rtems_bsp_cmdline_get_param(
+ const char *name,
+ char *value,
+ size_t length
+);
+
+
+/**
+ * @brief Obtain COPY of the Right Hand Side of the Matching Argument
+ *
+ * This method searches for the argument @a name in
+ * the BSP Boot Command String and returns the right hand side
+ * associated with it in @a value up to a maximum string @a length.
+ * This will NOT include the argument but only any right hand side
+ * portion of the string. * For example, one might be returned FAST if
+ * searching for --mode.
+ *
+ * @param[in] name is the arugment to search for
+ * @param[in] value points to where the contents will
+ * be placed if located.
+ * @param[in] length is the maximum length to copy
+ *
+ * @return This method returns NULL if not found and
+ * @a value if found.
+ */
+const char *rtems_bsp_cmdline_get_param_rhs(
+ const char *name,
+ char *value,
+ size_t length
+);
+
+/**
+ * @brief Obtain Pointer to the Entire Matching Argument
+ *
+ * This method searches for the argument @a name in
+ * the BSP Boot Command String and returns a pointer to the
+ * entire string associated with it. This will include the
+ * argument and any right hand side portion of the string.
+ * For example, one might be returned --mode=FAST if
+ * searching for --mode.
+ *
+ * @param[in] name is the arugment to search for
+ *
+ * @return This method returns NULL if not found and a pointer
+ * into the BSP Boot Command String if found.
+ *
+ * @note The pointer will be to the original BSP Command
+ * Line string. Exercise caution when using this.
+ */
+const char *rtems_bsp_cmdline_get_param_raw(
+ const char *name
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+#endif
diff --git a/cpukit/libmisc/bspcmdline/bspcmdline_get.c b/cpukit/libmisc/bspcmdline/bspcmdline_get.c
new file mode 100644
index 0000000000..7e06aa47bd
--- /dev/null
+++ b/cpukit/libmisc/bspcmdline/bspcmdline_get.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bspcmdline.h>
+
+extern const char *bsp_boot_cmdline;
+
+const char *rtems_bsp_cmdline_get(void)
+{
+ return bsp_boot_cmdline;
+}
diff --git a/cpukit/libmisc/bspcmdline/bspcmdline_getparam.c b/cpukit/libmisc/bspcmdline/bspcmdline_getparam.c
new file mode 100644
index 0000000000..288128bf8d
--- /dev/null
+++ b/cpukit/libmisc/bspcmdline/bspcmdline_getparam.c
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bspcmdline.h>
+
+static void copy_string(
+ const char *start,
+ char *value,
+ size_t length
+)
+{
+ int i;
+ int quotes;
+ const char *p = start;
+
+ quotes=0;
+ for (i=0 ; *p && i<length-1; ) {
+ if ( *p == '\"' ) {
+ quotes++;
+ } else if ( ((quotes % 2) == 0) && *p == ' ' )
+ break;
+ value[i++] = *p++;
+ value[i] = '\0';
+ }
+
+}
+
+const char *rtems_bsp_cmdline_get_param(
+ const char *name,
+ char *value,
+ size_t length
+)
+{
+ const char *p;
+
+ if ( !name )
+ return NULL;
+
+ if ( !value )
+ return NULL;
+
+ if ( !length )
+ return NULL;
+
+ value[0] = '\0';
+
+ p = rtems_bsp_cmdline_get_param_raw( name );
+
+ if ( !p )
+ return NULL;
+
+ copy_string( p, value, length );
+
+ return value;
+}
diff --git a/cpukit/libmisc/bspcmdline/bspcmdline_getparamraw.c b/cpukit/libmisc/bspcmdline/bspcmdline_getparamraw.c
new file mode 100644
index 0000000000..18bda9143f
--- /dev/null
+++ b/cpukit/libmisc/bspcmdline/bspcmdline_getparamraw.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems/bspcmdline.h>
+
+extern const char *bsp_boot_cmdline;
+
+const char *rtems_bsp_cmdline_get_param_raw(
+ const char *name
+)
+{
+ const char *p;
+
+ if ( !name )
+ return NULL;
+
+ if ( !bsp_boot_cmdline )
+ return NULL;
+
+ p = strstr(bsp_boot_cmdline, name);
+ /* printf( "raw: %p (%s)\n", p, p ); */
+ return p;
+}
diff --git a/cpukit/libmisc/bspcmdline/bspcmdline_getparamrhs.c b/cpukit/libmisc/bspcmdline/bspcmdline_getparamrhs.c
new file mode 100644
index 0000000000..38269dc44a
--- /dev/null
+++ b/cpukit/libmisc/bspcmdline/bspcmdline_getparamrhs.c
@@ -0,0 +1,48 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems/bspcmdline.h>
+
+const char *rtems_bsp_cmdline_get_param_rhs(
+ const char *name,
+ char *value,
+ size_t length
+)
+{
+ const char *p;
+ const char *rhs;
+ char *d;
+
+ p = rtems_bsp_cmdline_get_param( name, value, length );
+ if ( !p )
+ return NULL;
+
+ rhs = &p[strlen(name)];
+ if ( *rhs != '=' )
+ return NULL;
+
+ rhs++;
+ if ( *rhs == '\"' )
+ rhs++;
+ for ( d=value ; *rhs ; )
+ *d++ = *rhs++;
+ if ( *(d-1) == '\"' )
+ d--;
+ *d = '\0';
+
+ return value;
+}
diff --git a/cpukit/libmisc/capture/README b/cpukit/libmisc/capture/README
new file mode 100644
index 0000000000..d12b5570d6
--- /dev/null
+++ b/cpukit/libmisc/capture/README
@@ -0,0 +1,255 @@
+#
+# $Id$
+#
+
+ RTEMS Performance Monitoring and Measurement Framework
+
+ Copyright 2002-2007 Chris Johns (chrisj@rtems.org)
+ 23 April 2002
+
+This directory contains the source code for the performance monitoring and
+measurement framework. It is more commonly know as the capture engine.
+
+The capture engine is in an early phase of development. Please review the Status
+section of this document for the current status.
+
+Performance.
+
+The capture engine is designed to not effect the system it is
+monitoring. Resources such as memory are used as well as a small performance
+hit in task creation, deletion and context switch. The overhead is small and
+will not be noticed unless the system is operating close to the performance
+limit of the target.
+
+Structure.
+
+The capture engine is implemented in a couple of layers. This lowest layer is
+the capture engine. Its interface is in the file 'capture.h'. Typically this
+interface is directly used unless you are implementing a target interface. The
+user interface is via a target interface.
+
+Command Line Interface (CLI).
+
+This is a target interface that provides a number of user commands via the
+RTEMS monitor. To use you need to provide the following in your
+application initialisation:
+
+ #include <rtems/monitor.h>
+ #include <rtems/capture-cli.h>
+
+ rtems_monitor_init (0);
+ rtems_capture_cli_init (0);
+
+Check the file capture-cli.h for documentation of the interface. The parameter
+is a pointer to your board support package's time stamp handler. The time stamp
+handler is yet to be tested so it is recommended this is left as 0, unless you
+wish to test this part of the engine.
+
+The commands are:
+
+ copen - Open the capture engine.
+ cclose - Close the capture engine.
+ cenable - Enable the capture engine.
+ cdisable - Disable the capture engine.
+ ctlist - List the tasks known to the capture engine.
+ ctload - Display the current load (sort of top).
+ cwlist - List the watch and trigger controls.
+ cwadd - Add a watch.
+ cwdel - Delete a watch.
+ cwctl - Enable or disable a watch.
+ cwglob - Enable or disable the global watch.
+ cwceil - Set the watch ceiling.
+ cwfloor - Set the watch floor.
+ ctrace - Dump the trace records.
+ ctrig - Define a trigger.
+
+Open
+
+ usage: copen [-i] size
+
+Open the capture engine. The size parameter is the size of the capture engine
+trace buffer. A single record hold a single event, for example a task create or
+a context in or out. The option '-i' will enable the capture engine after it is
+opened.
+
+Close
+
+ usage: cclose
+
+Close the capture engine and release all resources held by the capture engine.
+
+Enable
+
+ usage: cenable
+
+Enable the capture engine if it has been opened.
+
+Disable
+
+ usage: cdisable
+
+Disable the capture engine. The enable and disable commands provide a means of
+removing the overhead of the capture engine from the context switch. This may
+be needed when testing if it is felt the capture engines overhead is effecting
+the system.
+
+Task List
+
+ usage: ctlist
+
+List the tasks the capture engine knows about. This may contain tasks that have
+been deleted.
+
+Task Load
+
+ usage: ctload
+
+List the tasks in the order of load in a similar way top does on Unix. The
+command sends ANSI terminal codes. You press enter to stop the update. The
+update period is fixed at 5 seconds. The output looks like:
+
+ Press ENTER to exit.
+
+ PID NAME RPRI CPRI STATE %CPU %STK FLGS EXEC TIME
+04010001 IDLE 255 255 READY 96.012% 0% a-----g 1
+08010009 CPlt 1 1 READY 3.815% 15% a------ 0
+08010003 ntwk 20 20 Wevnt 0.072% 0% at----g 0
+08010004 CSr0 20 20 Wevnt 0.041% 0% at----g 0
+08010001 main 250 250 DELAY 0.041% 0% a-----g 0
+08010008 test 100 100 Wevnt 0.000% 20% at-T-+g 0
+08010007 test 100 100 Wevnt 0.000% 0% at-T-+g 0
+08010005 CSt0 20 20 Wevnt 0.000% 0% at----g 0
+08010006 RMON 1 1 Wsem 0.000% 0% a------ 0
+
+There are 7 flags and from left to right are:
+
+1) 'a' the task is active, and 'd' the task has been deleted.
+2) 't' the task has been traced.
+3) 'F' the task has a from (TO_ANY) trigger.
+4) 'T' the task has a to (FROM_ANY) trigger.
+5) 'E' the task has an edge (FROM_TO) trigger.
+6) '+' the task as a watch control attached, 'w' a watch is enabled.
+7) 'g' the task is part of a global trigger.
+
+The %STK is the percentage of stack used by a task. Currently only tasks
+created while the capture engine is enabled can be monitored.
+
+The RPRI is the real priority. This is the priority set for the task. The
+current priority is the executing priority that may reflect a level set as a
+result of priority inversion.
+
+Watch List
+
+ usage: cwlist
+
+This command lists the watch and trigger controls the capture engine has. A
+control is a structure used by the capture engine to determine if a task is
+watched or triggers capturing.
+
+Watch Add
+
+ usage: cwadd [task name] [id]
+
+Add a watch for a task. You can provide a name or id or both. A name will cause
+all tasks with that name to have the watch added. An id results in a watch
+being for a specific task.
+
+Using a name is useful when the task is not yet created.
+
+Watch Delete
+
+ usage: cwdel [task name] [id]
+
+Delete a watch that has been added.
+
+Watch Control
+
+ usage: cwctl [task name] [id] on/off
+
+Enable or disable a watch. The name and id parameters are the same as the watch
+add command.
+
+Global Watch
+
+ usage: cwglob on/off
+
+Enable or disable the global watch. A global watch is an easy way to enable
+watches for all tasks with real priorities between the watch ceiling and floor
+priorities.
+
+Watch Priority Ceiling
+
+ usage: cwceil priority
+
+Set the watch priority ceiling. All tasks with a priority less than the ceiling
+priority are not watched. This allow you to ignore high priority system and
+driver tasks.
+
+Watch Priority Floor
+
+ usage: cwfloor priority
+
+Set the watch priority floor. All tasks with a priority greater than the floor
+priority level are not watched. This allows you to remove tasks such as IDLE
+from being monitored.
+
+Trace
+
+ usage: ctrace [-c] [-r records]
+
+Dump the trace record. The option '-c' will output the records in comma
+separated variables (CSV). The '-r' option controls the number of records
+dumped. This can help stop the command looping for-ever.
+
+Trigger
+
+ usage: ctrig type [from name] [from id] [to name] [to id]
+
+Set a trigger. The types of triggers are :
+
+ from : trigger on a context switch from a task
+ to : trigger on a context switch to a task
+ edge : trigger on a context switch from a task to a task
+
+The from and to trigger types requires a task name or task id or both be
+provided. The edge requires a from name and/or id and a to name and/or id be
+provided.
+
+Flush
+
+ usage: cflush [-n]
+
+Flush the trace record. The option '-n' stops the capture engine be
+primed. This means an exising trigger state will not be cleared and tracing
+will continue.
+
+Status.
+
+The following is a list of outstanding issues or bugs.
+
+1) The capture engine does not scan the existing list of tasks in the kernel
+ when initialised. This means tasks that exist but are not active are not
+ seen. Not sure how to implement this one.
+
+2) The blocking read of trace records has not been completely implemented or
+ tested. This will wait until I complete the csv support for the cli for a
+ serial UI or the tcp server is implemented.
+
+3) Task control block clean up is not implemented. The control block should be
+ dumped to the trace buffer. This requires extended record formats. This can
+ be implemented using an event flag to indicate an extended record follows
+ the trace record. This would allow a task delete record to be directly
+ followed by the task information.
+
+4) Complete csv (comma separated variable) support for the CLI.
+
+5) Implement a tcp server interface.
+
+6) Complete the capture engine API documentation.
+
+7) Test the user supplied time stamp handler.
+
+8) Task name support is only for the rtems_name type. This means the only the
+ classic API tasks are currently supported. Partial support for the different
+ task names is provided how-ever this is not clean and does not support the
+ variable length task name such as found in the POSIX tasks.
diff --git a/cpukit/libmisc/capture/capture-cli.c b/cpukit/libmisc/capture/capture-cli.c
new file mode 100644
index 0000000000..98f76764f3
--- /dev/null
+++ b/cpukit/libmisc/capture/capture-cli.c
@@ -0,0 +1,1622 @@
+/*
+ ------------------------------------------------------------------------
+ $Id$
+ ------------------------------------------------------------------------
+
+ Copyright Objective Design Systems Pty Ltd, 2002
+ All rights reserved Objective Design Systems Pty Ltd, 2002
+ Chris Johns (ccj@acm.org)
+
+ COPYRIGHT (c) 1989-1998.
+ On-Line Applications Research Corporation (OAR).
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution.
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ ------------------------------------------------------------------------
+
+ RTEMS Performance Monitoring and Measurement Framework.
+
+ This is the Target Interface Command Line Interface. You need
+ start the RTEMS monitor.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/capture-cli.h>
+#include <rtems/monitor.h>
+
+#define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (20)
+
+/*
+ * The user capture timestamper.
+ */
+static rtems_capture_timestamp capture_timestamp;
+
+/*
+ * Common variable to sync the load monitor task.
+ */
+static volatile int cli_load_thread_active;
+
+/*
+ * rtems_capture_cli_open
+ *
+ * DESCRIPTION:
+ *
+ * This function opens the capture engine. We need the size of the
+ * capture buffer.
+ *
+ */
+
+static const char* open_usage = "usage: copen [-i] size\n";
+
+static void
+rtems_capture_cli_open (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ uint32_t size = 0;
+ bool enable = false;
+ rtems_status_code sc;
+ int arg;
+
+ if (argc <= 1)
+ {
+ fprintf (stdout, open_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ if (argv[arg][1] == 'i')
+ enable = true;
+ else
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ size = strtoul (argv[arg], 0, 0);
+
+ if (size < 100)
+ {
+ fprintf (stdout, "error: size must be greater than or equal to 100\n");
+ return;
+ }
+ }
+ }
+
+ sc = rtems_capture_open (size, capture_timestamp);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: open failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "capture engine opened.\n");
+
+ if (!enable)
+ return;
+
+ sc = rtems_capture_control (enable);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: open enable failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "capture engine enabled.\n");
+}
+
+/*
+ * rtems_capture_cli_close
+ *
+ * DESCRIPTION:
+ *
+ * This function closes the capture engine.
+ *
+ */
+
+static void
+rtems_capture_cli_close (int argc __attribute__((unused)),
+ char** argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+
+ sc = rtems_capture_close ();
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: close failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "capture engine closed.\n");
+}
+
+/*
+ * rtems_capture_cli_enable
+ *
+ * DESCRIPTION:
+ *
+ * This function enables the capture engine.
+ *
+ */
+
+static void
+rtems_capture_cli_enable (int argc __attribute__((unused)),
+ char** argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+
+ sc = rtems_capture_control (1);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: enable failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "capture engine enabled.\n");
+}
+
+/*
+ * rtems_capture_cli_disable
+ *
+ * DESCRIPTION:
+ *
+ * This function disables the capture engine.
+ *
+ */
+
+static void
+rtems_capture_cli_disable (int argc __attribute__((unused)),
+ char** argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+
+ sc = rtems_capture_control (0);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: disable failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "capture engine disabled.\n");
+}
+
+/*
+ * rtems_capture_cli_task_list
+ *
+ * DESCRIPTION:
+ *
+ * This function lists the tasks the capture engine knows about.
+ *
+ */
+
+static void
+rtems_capture_cli_task_list (int argc __attribute__((unused)),
+ char** argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
+ rtems_task_priority floor = rtems_capture_watch_get_floor ();
+ rtems_capture_task_t* task = rtems_capture_get_task_list ();
+ uint32_t ticks;
+ uint32_t tick_offset;
+ unsigned long long total_time;
+ int count = rtems_capture_task_count ();
+
+ if (capture_timestamp)
+ capture_timestamp (&ticks, &tick_offset);
+ else
+ {
+ ticks = _Watchdog_Ticks_since_boot;
+ tick_offset = 0;
+ }
+
+ fprintf (stdout, "total %i\n", count);
+
+ while (task)
+ {
+ rtems_task_priority priority;
+ int32_t stack_used;
+ int32_t time_used;
+
+ stack_used = rtems_capture_task_stack_usage (task);
+ if (stack_used)
+ stack_used = (stack_used * 100) / stack_used;
+
+ if (stack_used > 100)
+ stack_used = 100;
+
+ total_time = (ticks * rtems_capture_task_time (task)) + tick_offset;
+
+ time_used = (rtems_capture_task_time (task) * 100) / total_time;
+
+ if (time_used > 100)
+ time_used = 100;
+
+ priority = rtems_capture_task_real_priority (task);
+
+ fprintf (stdout, " ");
+ rtems_monitor_dump_id (rtems_capture_task_id (task));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_name (rtems_capture_task_name (task));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_priority (rtems_capture_task_start_priority (task));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_priority (rtems_capture_task_real_priority (task));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_state (rtems_capture_task_state (task));
+ fprintf (stdout, " %c%c",
+ rtems_capture_task_valid (task) ? 'a' : 'd',
+ rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-');
+
+ if ((floor > ceiling) && (ceiling > priority))
+ fprintf (stdout, "--");
+ else
+ {
+ uint32_t flags = rtems_capture_task_control_flags (task);
+ fprintf (stdout, "%c%c",
+ rtems_capture_task_control (task) ?
+ (flags & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
+ rtems_capture_watch_global_on () ? 'g' : '-');
+ }
+ fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% (%" PRIu32 ")\n",
+ stack_used, time_used, rtems_capture_task_ticks (task));
+
+ task = rtems_capture_next_task (task);
+ }
+}
+
+/*
+ * rtems_capture_cli_task_load_thread
+ *
+ * DESCRIPTION:
+ *
+ * This function displays the load of the tasks on an ANSI terminal.
+ *
+ */
+
+static void
+rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unused)))
+{
+ rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
+ rtems_task_priority floor = rtems_capture_watch_get_floor ();
+ int last_count = 0;
+
+ for (;;)
+ {
+ rtems_capture_task_t* tasks[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
+ unsigned long long load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
+ rtems_capture_task_t* task;
+ unsigned long long total_time;
+ int count = 0;
+ int i;
+ int j;
+
+ cli_load_thread_active = 1;
+
+ /*
+ * Iterate over the tasks and sort the highest load tasks
+ * into our local arrays. We only handle a limited number of
+ * tasks.
+ */
+
+ memset (tasks, 0, sizeof (tasks));
+ memset (load, 0, sizeof (load));
+
+ task = rtems_capture_get_task_list ();
+
+ total_time = 0;
+
+ while (task)
+ {
+ if (rtems_capture_task_valid (task))
+ {
+ unsigned long long l = rtems_capture_task_delta_time (task);
+
+ count++;
+
+ total_time += l;
+
+ for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)
+ {
+ if (tasks[i])
+ {
+ if ((l == 0) || (l < load[i]))
+ continue;
+
+ for (j = (RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - 1); j >= i; j--)
+ {
+ tasks[j + 1] = tasks[j];
+ load[j + 1] = load[j];
+ }
+ }
+
+ tasks[i] = task;
+ load[i] = l;
+ break;
+ }
+ }
+ task = rtems_capture_next_task (task);
+ }
+
+ fprintf (stdout, "\x1b[H\x1b[J Press ENTER to exit.\n\n");
+ fprintf (stdout,
+ " PID NAME RPRI CPRI STATE %%CPU %%STK FLGS EXEC TIME\n");
+
+ if (count > last_count)
+ j = count;
+ else
+ j = last_count;
+
+ for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)
+ {
+ rtems_task_priority priority;
+ int stack_used;
+ int task_load;
+ int k;
+
+ if (!tasks[i])
+ break;
+
+ j--;
+
+ stack_used = rtems_capture_task_stack_usage (tasks[i]);
+ if (stack_used)
+ stack_used = (stack_used * 100) / stack_used;
+
+ if (stack_used > 100)
+ stack_used = 100;
+
+ task_load = (int) ((load[i] * 100000) / total_time);
+
+ priority = rtems_capture_task_real_priority (tasks[i]);
+
+ fprintf (stdout, "\x1b[K");
+ rtems_monitor_dump_id (rtems_capture_task_id (tasks[i]));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_name (rtems_capture_task_name (tasks[i]));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_priority (priority);
+ fprintf (stdout, " ");
+ rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i]));
+ fprintf (stdout, " ");
+ k = rtems_monitor_dump_state (rtems_capture_task_state (tasks[i]));
+ fprintf (stdout, "%*c %3i.%03i%% ", 6 - k, ' ',
+ task_load / 1000, task_load % 1000);
+ fprintf (stdout, "%3i%% %c%c", stack_used,
+ rtems_capture_task_valid (tasks[i]) ? 'a' : 'd',
+ rtems_capture_task_flags (tasks[i]) & RTEMS_CAPTURE_TRACED ? 't' : '-');
+
+ if ((floor > ceiling) && (ceiling > priority))
+ fprintf (stdout, "--");
+ else
+ fprintf (stdout, "%c%c",
+ rtems_capture_task_control (tasks[i]) ?
+ (rtems_capture_task_control_flags (tasks[i]) &
+ RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
+ rtems_capture_watch_global_on () ? 'g' : '-');
+
+ fprintf (stdout, " %qi\n", rtems_capture_task_time (tasks[i]));
+ }
+
+ if (count < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS)
+ {
+ j = RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - count;
+ while (j > 0)
+ {
+ fprintf (stdout, "\x1b[K\n");
+ j--;
+ }
+ }
+
+ last_count = count;
+
+ cli_load_thread_active = 0;
+
+ rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (5000000));
+ }
+}
+
+/*
+ * rtems_capture_cli_task_load
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command.
+ *
+ */
+
+static void
+rtems_capture_cli_task_load (int argc __attribute__((unused)),
+ char** argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ rtems_task_priority priority;
+ rtems_name name;
+ rtems_id id;
+
+ sc = rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: cannot obtain the current priority: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ name = rtems_build_name('C', 'P', 'l', 't');
+
+ sc = rtems_task_create (name, priority, 4 * 1024,
+ RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
+ RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
+ &id);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: cannot create helper thread: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ sc = rtems_task_start (id, rtems_capture_cli_task_load_thread, 0);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: cannot start helper thread: %s\n",
+ rtems_status_text (sc));
+ rtems_task_delete (id);
+ return;
+ }
+
+ for (;;)
+ {
+ int c = getchar ();
+
+ if ((c == '\r') || (c == '\n'))
+ {
+ int loops = 20;
+
+ while (loops && cli_load_thread_active)
+ rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (100000));
+
+ rtems_task_delete (id);
+
+ fprintf (stdout, "load monitoring stopped.\n");
+
+ return;
+ }
+ }
+}
+
+/*
+ * rtems_capture_cli_watch_list
+ *
+ * DESCRIPTION:
+ *
+ * This function lists the controls in the capture engine.
+ *
+ */
+
+static void
+rtems_capture_cli_watch_list (int argc __attribute__((unused)),
+ char** argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_capture_control_t* control = rtems_capture_get_control_list ();
+ rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
+ rtems_task_priority floor = rtems_capture_watch_get_floor ();
+
+ fprintf (stdout, "watch priority ceiling is %" PRId32 "\n", ceiling);
+ fprintf (stdout, "watch priority floor is %" PRId32 "\n", floor);
+ fprintf (stdout, "global watch is %s\n",
+ rtems_capture_watch_global_on () ? "enabled" : "disabled");
+ fprintf (stdout, "total %" PRId32 "\n", rtems_capture_control_count ());
+
+ while (control)
+ {
+ uint32_t flags;
+ int f;
+ int fshowed;
+ int lf;
+
+ fprintf (stdout, " ");
+ rtems_monitor_dump_id (rtems_capture_control_id (control));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_name (rtems_capture_control_name (control));
+ flags = rtems_capture_control_flags (control);
+ fprintf (stdout, " %c%c ",
+ rtems_capture_watch_global_on () ? 'g' : '-',
+ flags & RTEMS_CAPTURE_WATCH ? 'w' : '-');
+ flags = rtems_capture_control_to_triggers (control);
+ fprintf (stdout, " T:%c%c%c%c%c%c%c",
+ flags & RTEMS_CAPTURE_SWITCH ? 'S' : '-',
+ flags & RTEMS_CAPTURE_CREATE ? 'C' : '-',
+ flags & RTEMS_CAPTURE_START ? 'S' : '-',
+ flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
+ flags & RTEMS_CAPTURE_DELETE ? 'D' : '-',
+ flags & RTEMS_CAPTURE_BEGIN ? 'B' : '-',
+ flags & RTEMS_CAPTURE_EXITTED ? 'E' : '-');
+ flags = rtems_capture_control_from_triggers (control);
+ fprintf (stdout, " F:%c%c%c%c%c",
+ flags & RTEMS_CAPTURE_SWITCH ? 'S' : '-',
+ flags & RTEMS_CAPTURE_CREATE ? 'C' : '-',
+ flags & RTEMS_CAPTURE_START ? 'S' : '-',
+ flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
+ flags & RTEMS_CAPTURE_DELETE ? 'D' : '-');
+
+ for (f = 0, fshowed = 0, lf = 1; f < RTEMS_CAPTURE_TRIGGER_TASKS; f++)
+ {
+ if (rtems_capture_control_by_valid (control, f))
+ {
+ if (lf && ((fshowed % 3) == 0))
+ {
+ fprintf (stdout, "\n");
+ lf = 0;
+ }
+
+ fprintf (stdout, " %2i:", f);
+ rtems_monitor_dump_name (rtems_capture_control_by_name (control, f));
+ fprintf (stdout, "/");
+ rtems_monitor_dump_id (rtems_capture_control_by_id (control, f));
+ flags = rtems_capture_control_by_triggers (control, f);
+ fprintf (stdout, ":%c%c%c%c%c",
+ flags & RTEMS_CAPTURE_SWITCH ? 'S' : '-',
+ flags & RTEMS_CAPTURE_CREATE ? 'C' : '-',
+ flags & RTEMS_CAPTURE_START ? 'S' : '-',
+ flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
+ flags & RTEMS_CAPTURE_DELETE ? 'D' : '-');
+ fshowed++;
+ lf = 1;
+ }
+ }
+
+ if (lf)
+ fprintf (stdout, "\n");
+
+ control = rtems_capture_next_control (control);
+ }
+}
+
+/*
+ * rtems_capture_cli_get_name_id
+ *
+ * DESCRIPTION:
+ *
+ * This function checks arguments for a name or an id.
+ *
+ */
+
+static bool
+rtems_capture_cli_get_name_id (char* arg,
+ bool* valid_name,
+ bool* valid_id,
+ rtems_name* name,
+ rtems_id* id)
+{
+ size_t l;
+ size_t i;
+
+ if (*valid_name && *valid_id)
+ {
+ fprintf (stdout, "error: too many arguments\n");
+ return 0;
+ }
+
+ /*
+ * See if the arg is all hex digits.
+ */
+
+ l = strlen (arg);
+
+ for (i = 0; i < l; i++)
+ if (!isxdigit ((unsigned char)arg[i]))
+ break;
+
+ if (i == l)
+ {
+ *id = strtoul (arg, 0, 16);
+ *valid_id = true;
+ }
+ else
+ {
+ /*
+ * This is a bit of hack but it should work on all platforms
+ * as it is what the score does with names.
+ *
+ * @warning The extra assigns play with the byte order so do not
+ * remove unless the score has been updated.
+ */
+ rtems_name rname;
+
+ rname = rtems_build_name(arg[0], arg[1], arg[2], arg[3]);
+ *name = rname;
+ *valid_name = true;
+ }
+
+ return 1;
+}
+
+/*
+ * rtems_capture_cli_watch_add
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that add a watch to the capture
+ * engine.
+ *
+ */
+
+static char const * watch_add_usage = "usage: cwadd [task name] [id]\n";
+
+static void
+rtems_capture_cli_watch_add (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ int arg;
+ rtems_name name = 0;
+ rtems_id id = 0;
+ bool valid_name = false;
+ bool valid_id = false;
+
+ if (argc <= 1)
+ {
+ fprintf (stdout, watch_add_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
+ &name, &id))
+ return;
+ }
+ }
+
+ if (!valid_name && !valid_id)
+ {
+ fprintf (stdout, "error: no valid name or task id located\n");
+ return;
+ }
+
+ sc = rtems_capture_watch_add (name, id);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout,
+ "error: watch add failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "watch added.\n");
+}
+
+/*
+ * rtems_capture_cli_watch_del
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that deletes a watch from the capture
+ * engine.
+ *
+ */
+
+static char const * watch_del_usage = "usage: cwdel [task name] [id]\n";
+
+static void
+rtems_capture_cli_watch_del (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ int arg;
+ rtems_name name = 0;
+ rtems_id id = 0;
+ bool valid_name = false;
+ bool valid_id = false;
+
+ if (argc <= 1)
+ {
+ fprintf (stdout, watch_del_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
+ &name, &id))
+ return;
+ }
+ }
+
+ if (!valid_name && !valid_id)
+ {
+ fprintf (stdout, "error: no valid name or task id located\n");
+ return;
+ }
+
+ sc = rtems_capture_watch_del (name, id);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: watch delete failed: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "watch delete.\n");
+}
+
+/*
+ * rtems_capture_cli_watch_control
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that controls a watch.
+ *
+ */
+
+static char const * watch_control_usage = "usage: cwctl [task name] [id] on/off\n";
+
+static void
+rtems_capture_cli_watch_control (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ int arg;
+ rtems_name name = 0;
+ rtems_id id = 0;
+ bool valid_name = false;
+ bool valid_id = false;
+ bool enable = false;
+
+ if (argc <= 2)
+ {
+ fprintf (stdout, watch_control_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ if (strcmp (argv[arg], "on") == 0)
+ enable = true;
+ else if (strcmp (argv[arg], "off") == 0)
+ enable = false;
+ else if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name,
+ &valid_id, &name, &id))
+ return;
+ }
+ }
+
+ if (!valid_name && !valid_id)
+ {
+ fprintf (stdout, "error: no valid name or task id located\n");
+ return;
+ }
+
+ sc = rtems_capture_watch_ctrl (name, id, enable);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: watch control failed: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "watch %s.\n", enable ? "enabled" : "disabled");
+}
+
+/*
+ * rtems_capture_cli_watch_global
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that sets a global watch.
+ *
+ */
+
+static char const * watch_global_usage = "usage: cwglob on/off\n";
+
+static void
+rtems_capture_cli_watch_global (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ int arg;
+ bool enable = false;
+
+ if (argc <= 1)
+ {
+ fprintf (stdout, watch_global_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ if (strcmp (argv[arg], "on") == 0)
+ enable = true;
+ else if (strcmp (argv[arg], "off") == 0)
+ enable = false;
+ }
+ }
+
+ sc = rtems_capture_watch_global (enable);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: global watch failed: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "global watch %s.\n", enable ? "enabled" : "disabled");
+}
+
+/*
+ * rtems_capture_cli_watch_ceiling
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that sets watch ceiling.
+ *
+ */
+
+static char const * watch_ceiling_usage = "usage: cwceil priority\n";
+
+static void
+rtems_capture_cli_watch_ceiling (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ int arg;
+ rtems_task_priority priority = 0;
+
+ if (argc <= 1)
+ {
+ fprintf (stdout, watch_ceiling_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ priority = strtoul (argv[arg], 0, 0);
+ }
+ }
+
+ sc = rtems_capture_watch_ceiling (priority);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: watch ceiling failed: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "watch ceiling is %" PRId32 ".\n", priority);
+}
+
+/*
+ * rtems_capture_cli_watch_floor
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that sets watch floor.
+ *
+ */
+
+static char const * watch_floor_usage = "usage: cwfloor priority\n";
+
+static void
+rtems_capture_cli_watch_floor (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ int arg;
+ rtems_task_priority priority = 0;
+
+ if (argc <= 1)
+ {
+ fprintf (stdout, watch_floor_usage);
+ return;
+ }
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ priority = strtoul (argv[arg], 0, 0);
+ }
+ }
+
+ sc = rtems_capture_watch_floor (priority);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: watch floor failed: %s\n",
+ rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "watch floor is %" PRId32 ".\n", priority);
+}
+
+/*
+ * rtems_capture_cli_trigger_worker
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that sets or clears a trigger.
+ *
+ */
+
+static char const *trigger_set_usage =
+ "usage: %s [-?] type [to name/id] [from] [from name/id]\n";
+
+static char const *trigger_set_types =
+ " You can say 'type TASK' or 'type TO from FROM'\n" \
+ " where TASK is the task the event is happening to\n" \
+ " or you can say the event TO this task FROM this task.\n" \
+ " No type defaults to 'switch'.\n" \
+ " switch : context switch TASK or FROM or FROM->TO\n" \
+ " create : create TASK, or create TO from FROM\n" \
+ " start : start TASK, or start TO from FROM\n" \
+ " restart : restart TASK, or restart TO from FROM\n" \
+ " delete : delete TASK or delete TO from FROM\n" \
+ " begin : begin TASK\n" \
+ " exitted : exitted TASK\n";
+
+/*
+ * Structure to handle the parsing of the trigger command line.
+ */
+typedef struct rtems_capture_cli_triggers_s
+{
+ char const * name;
+ rtems_capture_trigger_t type;
+ int to_only;
+} rtems_capture_cli_triggers_t;
+
+static rtems_capture_cli_triggers_t rtems_capture_cli_triggers[] =
+{
+ { "switch", rtems_capture_switch, 0 }, /* must be first */
+ { "create", rtems_capture_create, 0 },
+ { "start", rtems_capture_start, 0 },
+ { "restart", rtems_capture_restart, 0 },
+ { "delete", rtems_capture_delete, 0 },
+ { "begin", rtems_capture_begin, 1 },
+ { "exitted", rtems_capture_exitted, 1 }
+};
+
+typedef enum rtems_capture_cli_trig_state_e
+{
+ trig_type,
+ trig_to,
+ trig_from_from,
+ trig_from
+} rtems_capture_cli_trig_state_t;
+
+#define RTEMS_CAPTURE_CLI_TRIGGERS_NUM \
+ (sizeof (rtems_capture_cli_triggers) / sizeof (rtems_capture_cli_triggers_t))
+
+static void
+rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
+{
+ rtems_status_code sc;
+ int arg;
+ int trigger = 0; /* switch */
+ rtems_capture_trigger_mode_t trigger_mode = rtems_capture_from_any;
+ bool trigger_set = false;
+ bool is_from = false;
+ rtems_name name = 0;
+ rtems_id id = 0;
+ bool valid_name = false;
+ bool valid_id = false;
+ rtems_name from_name = 0;
+ rtems_id from_id = 0;
+ bool from_valid_name = false;
+ bool from_valid_id = false;
+ rtems_name to_name = 0;
+ rtems_id to_id = 0;
+ bool to_valid_name = false;
+ bool to_valid_id = false;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][1])
+ {
+ case '?':
+ fprintf (stdout, trigger_set_usage, set ? "ctset" : "ctclear");
+ fprintf (stdout, trigger_set_types);
+ return;
+ default:
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ break;
+ }
+ }
+ else
+ {
+ if (!trigger_set)
+ {
+ bool found = false;
+ int t;
+
+ for (t = 0; t < RTEMS_CAPTURE_CLI_TRIGGERS_NUM; t++)
+ if (strcmp (argv[arg], rtems_capture_cli_triggers[t].name) == 0)
+ {
+ trigger = t;
+ found = true;
+ break;
+ }
+
+ trigger_set = true;
+
+ /*
+ * If a trigger was not found assume the default and
+ * assume the parameter is a task name or id.
+ */
+ if (found)
+ continue;
+ }
+
+ if (strcmp (arg[argv], "from") == 0)
+ {
+ if (is_from)
+ fprintf (stdout, "warning: extra 'from' ignored\n");
+
+ is_from = 1;
+ continue;
+ }
+
+ if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
+ &name, &id))
+ return;
+
+ if (valid_name)
+ {
+ if (is_from)
+ {
+ if (!from_valid_name && !from_valid_id)
+ {
+ from_valid_name = true;
+ from_name = name;
+ }
+ else
+ fprintf (stdout, "warning: extra arguments ignored\n");
+ }
+ else if (!to_valid_name && !to_valid_id)
+ {
+ to_valid_name = true;
+ to_name = name;
+ }
+ else
+ fprintf (stdout, "warning: extra arguments ignored\n");
+ }
+
+ if (valid_id)
+ {
+ if (is_from)
+ {
+ if (!from_valid_name && !from_valid_id)
+ {
+ from_valid_id = true;
+ from_id = id;
+ }
+ else
+ fprintf (stdout, "warning: extra arguments ignored\n");
+ }
+ else if (!to_valid_name && !to_valid_id)
+ {
+ to_valid_id = true;
+ to_id = id;
+ }
+ else
+ fprintf (stdout, "warning: extra arguments ignored\n");
+ }
+ }
+ }
+
+ if (is_from && rtems_capture_cli_triggers[trigger].to_only)
+ {
+ fprintf (stdout, "error: a %s trigger can be a TO trigger\n",
+ rtems_capture_cli_triggers[trigger].name);
+ return;
+ }
+
+ if (!to_valid_name && !to_valid_id && !from_valid_name && !from_valid_id)
+ {
+ fprintf (stdout, trigger_set_usage);
+ return;
+ }
+
+ if (!is_from && !to_valid_name && !to_valid_id)
+ {
+ fprintf (stdout, "error: a %s trigger needs a TO name or id\n",
+ rtems_capture_cli_triggers[trigger].name);
+ return;
+ }
+
+ if (is_from && !from_valid_name && !from_valid_id)
+ {
+ fprintf (stdout, "error: a %s trigger needs a FROM name or id\n",
+ rtems_capture_cli_triggers[trigger].name);
+ return;
+ }
+
+ if ((from_valid_name || from_valid_id) && (to_valid_name || to_valid_id))
+ trigger_mode = rtems_capture_from_to;
+ else if (from_valid_name || from_valid_id)
+ trigger_mode = rtems_capture_to_any;
+ else if (to_valid_name || to_valid_id)
+ trigger_mode = rtems_capture_from_any;
+
+ if (set)
+ sc = rtems_capture_set_trigger (from_name, from_id, to_name, to_id,
+ trigger_mode,
+ rtems_capture_cli_triggers[trigger].type);
+ else
+ sc = rtems_capture_clear_trigger (from_name, from_id, to_name, to_id,
+ trigger_mode,
+ rtems_capture_cli_triggers[trigger].type);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: %sing the trigger failed: %s\n",
+ set ? "sett" : "clear", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "trigger %s.\n", set ? "set" : "cleared");
+}
+
+/*
+ * rtems_capture_cli_trigger_set
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that sets a trigger.
+ *
+ */
+
+static void
+rtems_capture_cli_trigger_set (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_capture_cli_trigger_worker (1, argc, argv);
+}
+
+/*
+ * rtems_capture_cli_trigger_clear
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that clears a trigger.
+ *
+ */
+
+static void
+rtems_capture_cli_trigger_clear (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_capture_cli_trigger_worker (0, argc, argv);
+}
+
+/*
+ * rtems_capture_cli_trace_records
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that dumps trace records.
+ *
+ */
+
+static void
+rtems_capture_cli_trace_records (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ bool csv = false;
+ static int dump_total = 22;
+ int total;
+ int count;
+ uint32_t read;
+ rtems_capture_record_t* rec;
+ int arg;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ if (argv[arg][1] == 'c')
+ csv = true;
+ else
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ else
+ {
+ size_t i;
+ size_t l;
+
+ l = strlen (argv[arg]);
+
+ for (i = 0; i < l; i++)
+ if (!isdigit ((unsigned char)argv[arg][i]))
+ {
+ fprintf (stdout, "error: not a number\n");
+ return;
+ }
+
+ dump_total = strtoul (argv[arg], 0, 0);
+ }
+ }
+
+ total = dump_total;
+
+ while (total)
+ {
+ sc = rtems_capture_read (0, 0, &read, &rec);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: trace read failed: %s\n", rtems_status_text (sc));
+ rtems_capture_flush (0);
+ return;
+ }
+
+ /*
+ * If we have no records then just exist. We still need to release
+ * the reader lock.
+ */
+
+ if (read == 0)
+ {
+ rtems_capture_release (read);
+ break;
+ }
+
+ count = total < read ? total : read;
+
+ while (count--)
+ {
+ if (csv)
+ fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32
+ ",%03" PRIu32 ",%04" PRIx32 ",%" PRId32 ",%" PRId32 "\n",
+ (uintptr_t) rec->task,
+ (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
+ (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
+ (rec->events >> RTEMS_CAPTURE_EVENT_START),
+ rec->ticks, rec->tick_offset);
+ else
+ {
+ unsigned long long t;
+ uint32_t event;
+ int e;
+
+ event = rec->events >> RTEMS_CAPTURE_EVENT_START;
+
+ t = rec->ticks;
+ t *= rtems_capture_tick_time ();
+ t += rec->tick_offset;
+
+ for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
+ {
+ if (event & 1)
+ {
+ fprintf (stdout, "%9li.%06li ", (unsigned long) (t / 1000000),
+ (unsigned long) (t % 1000000));
+ rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
+ fprintf (stdout, " ");
+ rtems_monitor_dump_name (rtems_capture_task_name (rec->task));
+ fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n",
+ (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
+ (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
+ rtems_capture_event_text (e));
+ }
+ event >>= 1;
+ }
+ }
+ rec++;
+ }
+
+ count = total < read ? total : read;
+
+ if (count < total)
+ total -= count;
+ else
+ total = 0;
+
+ rtems_capture_release (count);
+ }
+}
+
+/*
+ * rtems_capture_cli_flush
+ *
+ * DESCRIPTION:
+ *
+ * This function is a monitor command that flushes and primes the capture
+ * engine.
+ *
+ */
+
+static void
+rtems_capture_cli_flush (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ rtems_status_code sc;
+ bool prime = true;
+ int arg;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ if (argv[arg][1] == 'n')
+ prime = false;
+ else
+ fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
+ }
+ }
+
+ sc = rtems_capture_flush (prime);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ fprintf (stdout, "error: flush failed: %s\n", rtems_status_text (sc));
+ return;
+ }
+
+ fprintf (stdout, "trace buffer flushed and %s.\n",
+ prime ? "primed" : "not primed");
+}
+
+static rtems_monitor_command_entry_t rtems_capture_cli_cmds[] =
+{
+ {
+ "copen",
+ "usage: copen [-i] size\n",
+ 0,
+ rtems_capture_cli_open,
+ { 0 },
+ 0
+ },
+ {
+ "cclose",
+ "usage: cclose\n",
+ 0,
+ rtems_capture_cli_close,
+ { 0 },
+ 0
+ },
+ {
+ "cenable",
+ "usage: cenable\n",
+ 0,
+ rtems_capture_cli_enable,
+ { 0 },
+ 0
+ },
+ {
+ "cdisable",
+ "usage: cdisable\n",
+ 0,
+ rtems_capture_cli_disable,
+ { 0 },
+ 0
+ },
+ {
+ "ctlist",
+ "usage: ctlist \n",
+ 0,
+ rtems_capture_cli_task_list,
+ { 0 },
+ 0
+ },
+ {
+ "ctload",
+ "usage: ctload \n",
+ 0,
+ rtems_capture_cli_task_load,
+ { 0 },
+ 0
+ },
+ {
+ "cwlist",
+ "usage: cwlist\n",
+ 0,
+ rtems_capture_cli_watch_list,
+ { 0 },
+ 0
+ },
+ {
+ "cwadd",
+ "usage: cwadd [task name] [id]\n",
+ 0,
+ rtems_capture_cli_watch_add,
+ { 0 },
+ 0
+ },
+ {
+ "cwdel",
+ "usage: cwdel [task name] [id]\n",
+ 0,
+ rtems_capture_cli_watch_del,
+ { 0 },
+ 0
+ },
+ {
+ "cwctl",
+ "usage: cwctl [task name] [id] on/off\n",
+ 0,
+ rtems_capture_cli_watch_control,
+ { 0 },
+ 0
+ },
+ {
+ "cwglob",
+ "usage: cwglob on/off\n",
+ 0,
+ rtems_capture_cli_watch_global,
+ { 0 },
+ 0
+ },
+ {
+ "cwceil",
+ "usage: cwceil priority\n",
+ 0,
+ rtems_capture_cli_watch_ceiling,
+ { 0 },
+ 0
+ },
+ {
+ "cwfloor",
+ "usage: cwfloor priority\n",
+ 0,
+ rtems_capture_cli_watch_floor,
+ { 0 },
+ 0
+ },
+ {
+ "ctrace",
+ "usage: ctrace [-c] [-r records]\n",
+ 0,
+ rtems_capture_cli_trace_records,
+ { 0 },
+ 0
+ },
+ {
+ "ctset",
+ "usage: ctset -h\n",
+ 0,
+ rtems_capture_cli_trigger_set,
+ { 0 },
+ 0
+ },
+ {
+ "ctclear",
+ "usage: ctclear -?\n",
+ 0,
+ rtems_capture_cli_trigger_clear,
+ { 0 },
+ 0
+ },
+ {
+ "cflush",
+ "usage: cflush [-n]\n",
+ 0,
+ rtems_capture_cli_flush,
+ { 0 },
+ 0
+ }
+};
+
+/*
+ * rtems_capture_cli_init
+ *
+ * DESCRIPTION:
+ *
+ * This function initialises the command line interface to the capture
+ * engine.
+ *
+ */
+
+rtems_status_code
+rtems_capture_cli_init (rtems_capture_timestamp timestamp)
+{
+ size_t cmd;
+
+ capture_timestamp = timestamp;
+
+ for (cmd = 0;
+ cmd < sizeof (rtems_capture_cli_cmds) / sizeof (rtems_monitor_command_entry_t);
+ cmd++)
+ rtems_monitor_insert_cmd (&rtems_capture_cli_cmds[cmd]);
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/capture/capture-cli.h b/cpukit/libmisc/capture/capture-cli.h
new file mode 100644
index 0000000000..99c4e2252c
--- /dev/null
+++ b/cpukit/libmisc/capture/capture-cli.h
@@ -0,0 +1,56 @@
+/**
+ * @file rtems/capture-cli.h
+ */
+
+/*
+ ------------------------------------------------------------------------
+ $Id$
+ ------------------------------------------------------------------------
+
+ Copyright Objective Design Systems Pty Ltd, 2002
+ All rights reserved Objective Design Systems Pty Ltd, 2002
+ Chris Johns (ccj@acm.org)
+
+ COPYRIGHT (c) 1989-1998.
+ On-Line Applications Research Corporation (OAR).
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution.
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ ------------------------------------------------------------------------
+
+ RTEMS Performance Monitoring and Measurement Framework.
+
+ This is the Target Interface Command Line Interface. You need
+ start the RTEMS monitor.
+
+*/
+
+#ifndef __CAPTURE_CLI_H_
+#define __CAPTURE_CLI_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/capture.h>
+
+/**
+ * rtems_capture_cli_init
+ *
+ * DESCRIPTION:
+ *
+ * This function initialises the command line interface to the capture
+ * engine.
+ *
+ */
+rtems_status_code
+rtems_capture_cli_init (rtems_capture_timestamp timestamp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
new file mode 100644
index 0000000000..ac1acc01ac
--- /dev/null
+++ b/cpukit/libmisc/capture/capture.c
@@ -0,0 +1,1938 @@
+/*
+ ------------------------------------------------------------------------
+ $Id$
+ ------------------------------------------------------------------------
+
+ Copyright Objective Design Systems Pty Ltd, 2002
+ All rights reserved Objective Design Systems Pty Ltd, 2002
+ Chris Johns (ccj@acm.org)
+
+ COPYRIGHT (c) 1989-2009.
+ On-Line Applications Research Corporation (OAR).
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution.
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ ------------------------------------------------------------------------
+
+ RTEMS Performance Monitoring and Measurement Framework.
+
+ This is the Capture Engine component.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "capture.h"
+#include <rtems/score/states.inl>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/wkspace.inl>
+
+/*
+ * These events are always recorded and are not part of the
+ * watch filters.
+ *
+ * This feature has been disabled as it becomes confusing when
+ * setting up filters and some event leak.
+ */
+#if defined (RTEMS_CAPTURE_ENGINE_ALLOW_RELATED_EVENTS)
+#define RTEMS_CAPTURE_RECORD_EVENTS (RTEMS_CAPTURE_CREATED_BY_EVENT | \
+ RTEMS_CAPTURE_CREATED_EVENT | \
+ RTEMS_CAPTURE_STARTED_BY_EVENT | \
+ RTEMS_CAPTURE_STARTED_EVENT | \
+ RTEMS_CAPTURE_RESTARTED_BY_EVENT | \
+ RTEMS_CAPTURE_RESTARTED_EVENT | \
+ RTEMS_CAPTURE_DELETED_BY_EVENT | \
+ RTEMS_CAPTURE_DELETED_EVENT | \
+ RTEMS_CAPTURE_BEGIN_EVENT | \
+ RTEMS_CAPTURE_EXITTED_EVENT)
+#else
+#define RTEMS_CAPTURE_RECORD_EVENTS (0)
+#endif
+
+/*
+ * Global capture flags.
+ */
+#define RTEMS_CAPTURE_ON (1 << 0)
+#define RTEMS_CAPTURE_NO_MEMORY (1 << 1)
+#define RTEMS_CAPTURE_OVERFLOW (1 << 2)
+#define RTEMS_CAPTURE_TRIGGERED (1 << 3)
+#define RTEMS_CAPTURE_READER_ACTIVE (1 << 4)
+#define RTEMS_CAPTURE_READER_WAITING (1 << 5)
+#define RTEMS_CAPTURE_GLOBAL_WATCH (1 << 6)
+#define RTEMS_CAPTURE_ONLY_MONITOR (1 << 7)
+
+/*
+ * RTEMS Capture Data.
+ */
+static rtems_capture_record_t* capture_records;
+static uint32_t capture_size;
+static uint32_t capture_count;
+static rtems_capture_record_t* capture_in;
+static uint32_t capture_out;
+static uint32_t capture_flags;
+static rtems_capture_task_t* capture_tasks;
+static rtems_capture_control_t* capture_controls;
+static int capture_extension_index;
+static rtems_id capture_id;
+static rtems_capture_timestamp capture_timestamp;
+static rtems_task_priority capture_ceiling;
+static rtems_task_priority capture_floor;
+static uint32_t capture_tick_period;
+static rtems_id capture_reader;
+
+/*
+ * RTEMS Event text.
+ */
+static const char* capture_event_text[] =
+{
+ "CREATED_BY",
+ "CREATED",
+ "STARTED_BY",
+ "STARTED",
+ "RESTARTED_BY",
+ "RESTARTED",
+ "DELETED_BY",
+ "DELETED",
+ "BEGIN",
+ "EXITTED",
+ "SWITCHED_OUT",
+ "SWITCHED_IN",
+ "TIMESTAMP"
+};
+
+/*
+ * rtems_capture_get_time
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the current time. If a handler is provided
+ * by the user get the time from that.
+ */
+static inline void rtems_capture_get_time (uint32_t* ticks,
+ uint32_t* tick_offset)
+{
+ if (capture_timestamp)
+ capture_timestamp (ticks, tick_offset);
+ else
+ {
+ *ticks = _Watchdog_Ticks_since_boot;
+ *tick_offset = 0;
+ }
+}
+
+/*
+ * rtems_capture_match_names
+ *
+ * DESCRIPTION:
+ *
+ * This function compares rtems_names. It protects the
+ * capture engine from a change to the way names are supported
+ * in RTEMS.
+ *
+ */
+static inline bool
+rtems_capture_match_names (rtems_name lhs, rtems_name rhs)
+{
+ return lhs == rhs;
+}
+
+/*
+ * rtems_capture_match_id
+ *
+ * DESCRIPTION:
+ *
+ * This function compares rtems_ids. It protects the
+ * capture engine from a change to the way id are supported
+ * in RTEMS.
+ *
+ */
+static inline bool
+rtems_capture_match_ids (rtems_id lhs, rtems_id rhs)
+{
+ return lhs == rhs;
+}
+
+/*
+ * rtems_capture_match_name_id
+ *
+ * DESCRIPTION:
+ *
+ * This function matches a name and/or id.
+ */
+static inline bool
+rtems_capture_match_name_id (rtems_name lhs_name,
+ rtems_id lhs_id,
+ rtems_name rhs_name,
+ rtems_id rhs_id)
+{
+ /*
+ * The left hand side name or id could be 0 which means a wildcard.
+ */
+ if ((lhs_name == 0) && (lhs_id == rhs_id))
+ return 1;
+ else if ((lhs_id == 0) || (lhs_id == rhs_id))
+ {
+ if (rtems_capture_match_names (lhs_name, rhs_name))
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * rtems_capture_dup_name
+ *
+ * DESCRIPTION:
+ *
+ * This function duplicates an rtems_names. It protects the
+ * capture engine from a change to the way names are supported
+ * in RTEMS.
+ *
+ */
+static inline void
+rtems_capture_dup_name (rtems_name* dst, rtems_name src)
+{
+ *dst = src;
+}
+
+/*
+ * rtems_capture_by_in_to
+ *
+ * DESCRIPTION:
+ *
+ * This function sees if a BY control is in the BY names. The use
+ * of the valid_mask in this way assumes the number of trigger
+ * tasks is the number of bits in uint32_t.
+ *
+ */
+static inline bool
+rtems_capture_by_in_to (uint32_t events,
+ rtems_capture_task_t* by,
+ rtems_capture_control_t* to)
+{
+ uint32_t valid_mask = RTEMS_CAPTURE_CONTROL_FROM_MASK (0);
+ uint32_t valid_remainder = 0xffffffff;
+ int i;
+
+ for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
+ {
+ /*
+ * If there are no more valid BY entries then
+ * we are finished.
+ */
+ if ((valid_remainder & to->by_valid) == 0)
+ break;
+
+ /*
+ * Is the froby entry valid and does its name or id match.
+ */
+ if ((valid_mask & to->by_valid) &&
+ (to->by[i].trigger & events))
+ {
+ /*
+ * We have the BY task on the right hand side so we
+ * match with id's first then labels if the id's are
+ * not set.
+ */
+ if (rtems_capture_match_name_id (to->by[i].name, to->by[i].id,
+ by->name, by->id))
+ return 1;
+ }
+
+ valid_mask >>= 1;
+ valid_remainder >>= 1;
+ }
+
+ return 0;
+}
+
+/*
+ * rtems_capture_refcount_up
+ *
+ * DESCRIPTION:
+ *
+ * This function raises the reference count.
+ *
+ */
+static inline void
+rtems_capture_refcount_up (rtems_capture_task_t* task)
+{
+ task->refcount++;
+}
+
+/*
+ * rtems_capture_refcount_down
+ *
+ * DESCRIPTION:
+ *
+ * This function lowers the reference count and if the count
+ * reaches 0 the task control block is returned to the heap.
+ *
+ */
+static inline void
+rtems_capture_refcount_down (rtems_capture_task_t* task)
+{
+ if (task->refcount)
+ task->refcount--;
+}
+
+/*
+ * rtems_capture_init_stack_usage
+ *
+ * DESCRIPTION:
+ *
+ * This function setups a stack so its usage can be monitored.
+ */
+static inline void
+rtems_capture_init_stack_usage (rtems_capture_task_t* task)
+{
+ if (task->tcb)
+ {
+ uint32_t* s;
+ uint32_t i;
+
+ task->stack_size = task->tcb->Start.Initial_stack.size;
+ task->stack_clean = task->stack_size;
+
+ s = task->tcb->Start.Initial_stack.area;
+
+ for (i = 0; i < (task->stack_size - 128); i += 4)
+ *(s++) = 0xdeaddead;
+ }
+}
+
+/*
+ * rtems_capture_find_control
+ *
+ * DESCRIPTION:
+ *
+ * This function searches for a trigger given a name.
+ *
+ */
+static inline rtems_capture_control_t*
+rtems_capture_find_control (rtems_name name, rtems_id id)
+{
+ rtems_capture_control_t* control;
+
+ for (control = capture_controls; control != NULL; control = control->next)
+ if (rtems_capture_match_name_id (name, id, control->name, control->id))
+ break;
+ return control;
+}
+
+/*
+ * rtems_capture_create_control
+ *
+ * DESCRIPTION:
+ *
+ * This function creates a capture control for the capture engine.
+ *
+ */
+static inline rtems_capture_control_t*
+rtems_capture_create_control (rtems_name name, rtems_id id)
+{
+ rtems_interrupt_level level;
+ rtems_capture_control_t* control;
+ rtems_capture_task_t* task;
+
+ if ((name == 0) && (id == 0))
+ return NULL;
+
+ control = rtems_capture_find_control (name, id);
+
+ if (control == NULL)
+ {
+ control = _Workspace_Allocate (sizeof (rtems_capture_control_t));
+
+ if (control == NULL)
+ {
+ capture_flags |= RTEMS_CAPTURE_NO_MEMORY;
+ return NULL;
+ }
+
+ control->name = name;
+ control->id = id;
+ control->flags = 0;
+ control->to_triggers = 0;
+ control->from_triggers = 0;
+ control->by_valid = 0;
+
+ memset (control->by, 0, sizeof (control->by));
+
+ rtems_interrupt_disable (level);
+
+ control->next = capture_controls;
+ capture_controls = control;
+
+ /*
+ * We need to scan the task list as set the control to the
+ * tasks.
+ */
+ for (task = capture_tasks; task != NULL; task = task->forw)
+ if (rtems_capture_match_name_id (name, id, task->name, task->id))
+ task->control = control;
+
+ rtems_interrupt_enable (level);
+ }
+
+ return control;
+}
+
+/*
+ * rtems_capture_create_capture_task
+ *
+ * DESCRIPTION:
+ *
+ * This function create the task control.
+ *
+ */
+static inline rtems_capture_task_t*
+rtems_capture_create_capture_task (rtems_tcb* new_task)
+{
+ rtems_interrupt_level level;
+ rtems_capture_task_t* task;
+ rtems_capture_control_t* control;
+ rtems_name name;
+
+ task = _Workspace_Allocate (sizeof (rtems_capture_task_t));
+
+ if (task == NULL)
+ {
+ capture_flags |= RTEMS_CAPTURE_NO_MEMORY;
+ return NULL;
+ }
+
+ /*
+ * Check the type of name the object has.
+ */
+
+ rtems_object_get_classic_name( new_task->Object.id, &name );
+
+ rtems_capture_dup_name (&task->name, name);
+
+ task->id = new_task->Object.id;
+ task->flags = 0;
+ task->in = 0;
+ task->refcount = 0;
+ task->out = 0;
+ task->tcb = new_task;
+ task->ticks = 0;
+ task->tick_offset = 0;
+ task->ticks_in = 0;
+ task->tick_offset_in = 0;
+ task->control = 0;
+ task->last_ticks = 0;
+ task->last_tick_offset = 0;
+
+ task->tcb->extensions[capture_extension_index] = task;
+
+ task->start_priority = new_task->Start.initial_priority;
+ task->stack_size = new_task->Start.Initial_stack.size;
+ task->stack_clean = task->stack_size;
+
+ rtems_interrupt_disable (level);
+
+ task->forw = capture_tasks;
+ if (task->forw)
+ task->forw->back = task;
+ task->back = NULL;
+ capture_tasks = task;
+
+ rtems_interrupt_enable (level);
+
+ /*
+ * We need to scan the default control list to initialise
+ * this control.
+ */
+
+ for (control = capture_controls; control != NULL; control = control->next)
+ if (rtems_capture_match_name_id (control->name, control->id,
+ task->name, task->id))
+ task->control = control;
+
+ return task;
+}
+
+/*
+ * rtems_capture_destroy_capture_task
+ *
+ * DESCRIPTION:
+ *
+ * This function destroy the task structure if the reference count
+ * is 0 and the tcb has been cleared signalling the task has been
+ * deleted.
+ *
+ */
+static inline void
+rtems_capture_destroy_capture_task (rtems_capture_task_t* task)
+{
+ if (task)
+ {
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable (level);
+
+ if (task->tcb || task->refcount)
+ task = 0;
+
+ if (task)
+ {
+ if (task->forw)
+ task->forw->back = task->back;
+ if (task->back)
+ task->back->forw = task->forw;
+ else
+ capture_tasks = task->forw;
+ }
+
+ rtems_interrupt_enable (level);
+
+ _Workspace_Free (task);
+ }
+}
+
+/*
+ * rtems_capture_record
+ *
+ * DESCRIPTION:
+ *
+ * This function records a capture record into the capture buffer.
+ *
+ */
+static inline void
+rtems_capture_record (rtems_capture_task_t* task,
+ uint32_t events)
+{
+ /*
+ * Check the watch state if we have a task control, and
+ * the task's real priority is lower or equal to the ceiling.
+ */
+ if (task &&
+ ((capture_flags &
+ (RTEMS_CAPTURE_TRIGGERED | RTEMS_CAPTURE_ONLY_MONITOR)) ==
+ RTEMS_CAPTURE_TRIGGERED))
+ {
+ rtems_capture_control_t* control;
+
+ control = task->control;
+
+ /*
+ * Capure the record if we have an event that is always
+ * captured, or the task's real priority is greater than the
+ * watch ceiling, and the global watch or task watch is enabled.
+ */
+
+ if ((events & RTEMS_CAPTURE_RECORD_EVENTS) ||
+ ((task->tcb->real_priority >= capture_ceiling) &&
+ (task->tcb->real_priority <= capture_floor) &&
+ ((capture_flags & RTEMS_CAPTURE_GLOBAL_WATCH) ||
+ (control && (control->flags & RTEMS_CAPTURE_WATCH)))))
+ {
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable (level);
+
+ if (capture_count < capture_size)
+ {
+ capture_count++;
+ capture_in->task = task;
+ capture_in->events = (events |
+ (task->tcb->real_priority) |
+ (task->tcb->current_priority << 8));
+
+ if ((events & RTEMS_CAPTURE_RECORD_EVENTS) == 0)
+ task->flags |= RTEMS_CAPTURE_TRACED;
+
+ rtems_capture_get_time (&capture_in->ticks, &capture_in->tick_offset);
+
+ if (capture_in == &capture_records[capture_size - 1])
+ capture_in = capture_records;
+ else
+ capture_in++;
+
+ rtems_capture_refcount_up (task);
+ }
+ else
+ capture_flags |= RTEMS_CAPTURE_OVERFLOW;
+ rtems_interrupt_enable (level);
+ }
+ }
+}
+
+/*
+ * rtems_capture_trigger
+ *
+ * DESCRIPTION:
+ *
+ * See if we have triggered and if not see if this event is a
+ * cause of a trigger.
+ */
+bool
+rtems_capture_trigger (rtems_capture_task_t* ft,
+ rtems_capture_task_t* tt,
+ uint32_t events)
+{
+ /*
+ * If we have not triggered then see if this is a trigger condition.
+ */
+ if (!(capture_flags & RTEMS_CAPTURE_TRIGGERED))
+ {
+ rtems_capture_control_t* fc = NULL;
+ rtems_capture_control_t* tc = NULL;
+ uint32_t from_events = 0;
+ uint32_t to_events = 0;
+ uint32_t from_to_events = 0;
+
+ if (ft)
+ {
+ fc = ft->control;
+ if (fc)
+ from_events = fc->from_triggers & events;
+ }
+
+ if (tt)
+ {
+ tc = tt->control;
+ if (tc)
+ {
+ to_events = tc->to_triggers & events;
+ if (ft && tc->by_valid)
+ from_to_events = tc->by_triggers & events;
+ }
+ }
+
+ /*
+ * Check if we have any from or to events. These are the
+ * from any or to any type triggers. All from/to triggers are
+ * listed in the to's control with the from in the from list.
+ *
+ * The masking above means any flag set is a trigger.
+ */
+ if (from_events || to_events)
+ {
+ capture_flags |= RTEMS_CAPTURE_TRIGGERED;
+ return 1;
+ }
+
+ /*
+ * Check the from->to events.
+ */
+ if (from_to_events)
+ {
+ if (rtems_capture_by_in_to (events, ft, tc))
+ {
+ capture_flags |= RTEMS_CAPTURE_TRIGGERED;
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * rtems_capture_create_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a task is created.
+ *
+ */
+static bool
+rtems_capture_create_task (rtems_tcb* current_task,
+ rtems_tcb* new_task)
+{
+ rtems_capture_task_t* ct;
+ rtems_capture_task_t* nt;
+
+ ct = current_task->extensions[capture_extension_index];
+
+ /*
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+
+ if (ct == NULL)
+ ct = rtems_capture_create_capture_task (current_task);
+
+ /*
+ * Create the new task's capture control block.
+ */
+ nt = rtems_capture_create_capture_task (new_task);
+
+ if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))
+ {
+ rtems_capture_record (ct, RTEMS_CAPTURE_CREATED_BY_EVENT);
+ rtems_capture_record (nt, RTEMS_CAPTURE_CREATED_EVENT);
+ }
+
+ return 1 == 1;
+}
+
+/*
+ * rtems_capture_start_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a task is started.
+ *
+ */
+static void
+rtems_capture_start_task (rtems_tcb* current_task,
+ rtems_tcb* started_task)
+{
+ /*
+ * Get the capture task control block so we can trace this
+ * event.
+ */
+ rtems_capture_task_t* ct;
+ rtems_capture_task_t* st;
+
+ ct = current_task->extensions[capture_extension_index];
+ st = started_task->extensions[capture_extension_index];
+
+ /*
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+
+ if (ct == NULL)
+ ct = rtems_capture_create_capture_task (current_task);
+
+ if (st == NULL)
+ st = rtems_capture_create_capture_task (started_task);
+
+ if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))
+ {
+ rtems_capture_record (ct, RTEMS_CAPTURE_STARTED_BY_EVENT);
+ rtems_capture_record (st, RTEMS_CAPTURE_STARTED_EVENT);
+ }
+
+ rtems_capture_init_stack_usage (st);
+}
+
+/*
+ * rtems_capture_restart_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a task is restarted.
+ *
+ */
+static void
+rtems_capture_restart_task (rtems_tcb* current_task,
+ rtems_tcb* restarted_task)
+{
+ /*
+ * Get the capture task control block so we can trace this
+ * event.
+ */
+ rtems_capture_task_t* ct;
+ rtems_capture_task_t* rt;
+
+ ct = current_task->extensions[capture_extension_index];
+ rt = restarted_task->extensions[capture_extension_index];
+
+ /*
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+
+ if (ct == NULL)
+ ct = rtems_capture_create_capture_task (current_task);
+
+ if (rt == NULL)
+ rt = rtems_capture_create_capture_task (restarted_task);
+
+ if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))
+ {
+ rtems_capture_record (ct, RTEMS_CAPTURE_RESTARTED_BY_EVENT);
+ rtems_capture_record (rt, RTEMS_CAPTURE_RESTARTED_EVENT);
+ }
+
+ rtems_capture_task_stack_usage (rt);
+ rtems_capture_init_stack_usage (rt);
+}
+
+/*
+ * rtems_capture_delete_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a task is deleted.
+ *
+ */
+static void
+rtems_capture_delete_task (rtems_tcb* current_task,
+ rtems_tcb* deleted_task)
+{
+ /*
+ * Get the capture task control block so we can trace this
+ * event.
+ */
+ rtems_capture_task_t* ct;
+ rtems_capture_task_t* dt;
+
+ /*
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+
+ ct = current_task->extensions[capture_extension_index];
+ dt = deleted_task->extensions[capture_extension_index];
+
+ if (ct == NULL)
+ ct = rtems_capture_create_capture_task (current_task);
+
+ if (dt == NULL)
+ dt = rtems_capture_create_capture_task (deleted_task);
+
+ if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))
+ {
+ rtems_capture_record (ct, RTEMS_CAPTURE_DELETED_BY_EVENT);
+ rtems_capture_record (dt, RTEMS_CAPTURE_DELETED_EVENT);
+ }
+
+ rtems_capture_task_stack_usage (dt);
+
+ /*
+ * This task's tcb will be invalid. This signals the
+ * task has been deleted.
+ */
+ dt->tcb = 0;
+
+ rtems_capture_destroy_capture_task (dt);
+}
+
+/*
+ * rtems_capture_begin_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a task is begun.
+ *
+ */
+static void
+rtems_capture_begin_task (rtems_tcb* begin_task)
+{
+ /*
+ * Get the capture task control block so we can trace this
+ * event.
+ */
+ rtems_capture_task_t* bt;
+
+ bt = begin_task->extensions[capture_extension_index];
+
+ /*
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+
+ if (bt == NULL)
+ bt = rtems_capture_create_capture_task (begin_task);
+
+ if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))
+ rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);
+}
+
+/*
+ * rtems_capture_exitted_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a task is exitted. That is
+ * returned rather than was deleted.
+ *
+ */
+static void
+rtems_capture_exitted_task (rtems_tcb* exitted_task)
+{
+ /*
+ * Get the capture task control block so we can trace this
+ * event.
+ */
+ rtems_capture_task_t* et;
+
+ et = exitted_task->extensions[capture_extension_index];
+
+ /*
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+
+ if (et == NULL)
+ et = rtems_capture_create_capture_task (exitted_task);
+
+ if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))
+ rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
+
+ rtems_capture_task_stack_usage (et);
+}
+
+/*
+ * rtems_capture_switch_task
+ *
+ * DESCRIPTION:
+ *
+ * This function is called when a context is switched.
+ *
+ */
+static void
+rtems_capture_switch_task (rtems_tcb* current_task,
+ rtems_tcb* heir_task)
+{
+ /*
+ * Only perform context switch trace processing if tracing is
+ * enabled.
+ */
+ if (capture_flags & RTEMS_CAPTURE_ON)
+ {
+ uint32_t ticks;
+ uint32_t tick_offset;
+
+ /*
+ * Get the cpature task control block so we can update the
+ * reference and perform any watch or trigger functions.
+ * The task pointers may not be known as the task may have
+ * been created before the capture engine was open. Add them.
+ */
+ rtems_capture_task_t* ct;
+ rtems_capture_task_t* ht;
+
+
+ if (_States_Is_transient (current_task->current_state)
+ || _States_Is_dormant (current_task->current_state))
+ {
+ rtems_id ct_id = current_task->Object.id;
+
+ for (ct = capture_tasks; ct; ct = ct->forw)
+ if (ct->id == ct_id)
+ break;
+ }
+ else
+ {
+ ct = current_task->extensions[capture_extension_index];
+
+ if (ct == NULL)
+ ct = rtems_capture_create_capture_task (current_task);
+ }
+
+ ht = heir_task->extensions[capture_extension_index];
+
+ if (ht == NULL)
+ ht = rtems_capture_create_capture_task (heir_task);
+
+ /*
+ * Update the execution time. Assume the tick will not overflow
+ * for now. This may need to change.
+ */
+ rtems_capture_get_time (&ticks, &tick_offset);
+
+ /*
+ * We could end up with null pointers for both the current task
+ * and the heir task.
+ */
+
+ if (ht)
+ {
+ ht->in++;
+ ht->ticks_in = ticks;
+ ht->tick_offset_in = tick_offset;
+ }
+
+ if (ct)
+ {
+ ct->out++;
+ ct->ticks += ticks - ct->ticks_in;
+
+ if (capture_timestamp)
+ {
+ tick_offset += capture_tick_period - ct->tick_offset_in;
+
+ if (tick_offset < capture_tick_period)
+ ct->tick_offset = tick_offset;
+ else
+ {
+ ct->ticks++;
+ ct->tick_offset = tick_offset - capture_tick_period;
+ }
+ }
+ else
+ {
+ ct->tick_offset += 100;
+ }
+ }
+
+ if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))
+ {
+ rtems_capture_record (ct, RTEMS_CAPTURE_SWITCHED_OUT_EVENT);
+ rtems_capture_record (ht, RTEMS_CAPTURE_SWITCHED_IN_EVENT);
+ }
+ }
+}
+
+/*
+ * rtems_capture_open
+ *
+ * DESCRIPTION:
+ *
+ * This function initialises the realtime capture engine allocating the trace
+ * buffer. It is assumed we have a working heap at stage of initialisation.
+ *
+ */
+rtems_status_code
+rtems_capture_open (uint32_t size, rtems_capture_timestamp timestamp __attribute__((unused)))
+{
+ rtems_extensions_table capture_extensions;
+ rtems_name name;
+ rtems_status_code sc;
+
+ /*
+ * See if the capture engine is already open.
+ */
+
+ if (capture_records)
+ return RTEMS_RESOURCE_IN_USE;
+
+ capture_records = malloc (size * sizeof (rtems_capture_record_t));
+
+ if (capture_records == NULL)
+ return RTEMS_NO_MEMORY;
+
+ capture_size = size;
+ capture_count = 0;
+ capture_in = capture_records;
+ capture_out = 0;
+ capture_flags = 0;
+ capture_tasks = NULL;
+ capture_ceiling = 0;
+ capture_floor = 255;
+
+ /*
+ * Create the extension table. This is copied so we
+ * can create it as a local.
+ */
+ capture_extensions.thread_create = rtems_capture_create_task;
+ capture_extensions.thread_start = rtems_capture_start_task;
+ capture_extensions.thread_restart = rtems_capture_restart_task;
+ capture_extensions.thread_delete = rtems_capture_delete_task;
+ capture_extensions.thread_switch = rtems_capture_switch_task;
+ capture_extensions.thread_begin = rtems_capture_begin_task;
+ capture_extensions.thread_exitted = rtems_capture_exitted_task;
+ capture_extensions.fatal = NULL;
+
+ /*
+ * Get the tick period from the BSP Configuration Table.
+ */
+ capture_tick_period = Configuration.microseconds_per_tick;
+
+ /*
+ * Register the user extension handlers for the CAPture Engine.
+ */
+ name = rtems_build_name ('C', 'A', 'P', 'E');
+ sc = rtems_extension_create (name, &capture_extensions, &capture_id);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ capture_id = 0;
+ free (capture_records);
+ capture_records = NULL;
+ }
+ else
+ {
+ capture_extension_index = rtems_object_id_get_index (capture_id);;
+ }
+
+ /*
+ * Iterate over the list of existing tasks.
+ */
+
+ return sc;
+}
+
+/*
+ * rtems_capture_close
+ *
+ * DESCRIPTION:
+ *
+ * This function shutdowns the capture engine and release any claimed
+ * resources.
+ */
+rtems_status_code
+rtems_capture_close (void)
+{
+ rtems_interrupt_level level;
+ rtems_capture_task_t* task;
+ rtems_capture_control_t* control;
+ rtems_capture_record_t* records;
+ rtems_status_code sc;
+
+ rtems_interrupt_disable (level);
+
+ if (!capture_records)
+ {
+ rtems_interrupt_enable (level);
+ return RTEMS_SUCCESSFUL;
+ }
+
+ capture_flags &= ~(RTEMS_CAPTURE_ON | RTEMS_CAPTURE_ONLY_MONITOR);
+
+ records = capture_records;
+ capture_records = NULL;
+
+ rtems_interrupt_enable (level);
+
+ /*
+ * Delete the extension first. This means we are now able to
+ * release the resources we have without them being used.
+ */
+
+ sc = rtems_extension_delete (capture_id);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ task = capture_tasks;
+
+ while (task)
+ {
+ rtems_capture_task_t* delete = task;
+ task = task->forw;
+ _Workspace_Free (delete);
+ }
+
+ capture_tasks = NULL;
+
+ control = capture_controls;
+
+ while (control)
+ {
+ rtems_capture_control_t* delete = control;
+ control = control->next;
+ _Workspace_Free (delete);
+ }
+
+ capture_controls = NULL;
+
+ if (capture_records)
+ {
+ free (capture_records);
+ capture_records = NULL;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_control
+ *
+ * DESCRIPTION:
+ *
+ * This function allows control of tracing at a global level.
+ */
+rtems_status_code
+rtems_capture_control (bool enable)
+{
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable (level);
+
+ if (!capture_records)
+ {
+ rtems_interrupt_enable (level);
+ return RTEMS_UNSATISFIED;
+ }
+
+ if (enable)
+ capture_flags |= RTEMS_CAPTURE_ON;
+ else
+ capture_flags &= ~RTEMS_CAPTURE_ON;
+
+ rtems_interrupt_enable (level);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_monitor
+ *
+ * DESCRIPTION:
+ *
+ * This function enable the monitor mode. When in the monitor mode
+ * the tasks are monitored but no data is saved. This can be used
+ * to profile the load on a system.
+ */
+rtems_status_code
+rtems_capture_monitor (bool enable)
+{
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable (level);
+
+ if (!capture_records)
+ {
+ rtems_interrupt_enable (level);
+ return RTEMS_UNSATISFIED;
+ }
+
+ if (enable)
+ capture_flags |= RTEMS_CAPTURE_ONLY_MONITOR;
+ else
+ capture_flags &= ~RTEMS_CAPTURE_ONLY_MONITOR;
+
+ rtems_interrupt_enable (level);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_flush
+ *
+ * DESCRIPTION:
+ *
+ * This function flushes the capture buffer. The prime parameter allows the
+ * capture engine to also be primed again.
+ */
+rtems_status_code
+rtems_capture_flush (bool prime)
+{
+ rtems_interrupt_level level;
+ rtems_capture_task_t* task;
+
+ rtems_interrupt_disable (level);
+
+ for (task = capture_tasks; task != NULL; task = task->forw)
+ {
+ task->flags &= ~RTEMS_CAPTURE_TRACED;
+ task->refcount = 0;
+ }
+
+ if (prime)
+ capture_flags &= ~(RTEMS_CAPTURE_TRIGGERED | RTEMS_CAPTURE_OVERFLOW);
+ else
+ capture_flags &= ~RTEMS_CAPTURE_OVERFLOW;
+
+ capture_count = 0;
+ capture_in = capture_records;
+ capture_out = 0;
+
+ rtems_interrupt_enable (level);
+
+ task = capture_tasks;
+
+ while (task)
+ {
+ rtems_capture_task_t* check = task;
+ task = task->forw;
+ rtems_capture_destroy_capture_task (check);
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_watch_add
+ *
+ * DESCRIPTION:
+ *
+ * This function defines a watch for a specific task given a name. A watch
+ * causes it to be traced either in or out of context. The watch can be
+ * optionally enabled or disabled with the set routine. It is disabled by
+ * default.
+ */
+rtems_status_code
+rtems_capture_watch_add (rtems_name name, rtems_id id)
+{
+ rtems_capture_control_t* control;
+
+ if ((name == 0) && (id == 0))
+ return RTEMS_UNSATISFIED;
+
+ control = rtems_capture_find_control (name, id);
+
+ if (control && !id)
+ return RTEMS_TOO_MANY;
+
+ if (!control)
+ control = rtems_capture_create_control (name, id);
+
+ if (!control)
+ return RTEMS_NO_MEMORY;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_watch_del
+ *
+ * DESCRIPTION:
+ *
+ * This function removes a watch for a specific task given a name. The task
+ * description will still exist if referenced by a trace record in the trace
+ * buffer or a global watch is defined.
+ */
+rtems_status_code
+rtems_capture_watch_del (rtems_name name, rtems_id id)
+{
+ rtems_interrupt_level level;
+ rtems_capture_control_t* control;
+ rtems_capture_control_t** prev_control;
+ rtems_capture_task_t* task;
+ bool found = false;
+
+ /*
+ * Should this test be for wildcards ?
+ */
+
+ for (prev_control = &capture_controls, control = capture_controls;
+ control != NULL; )
+ {
+ if (rtems_capture_match_name_id (control->name, control->id, name, id))
+ {
+ rtems_interrupt_disable (level);
+
+ for (task = capture_tasks; task != NULL; task = task->forw)
+ if (task->control == control)
+ task->control = 0;
+
+ *prev_control = control->next;
+
+ rtems_interrupt_enable (level);
+
+ _Workspace_Free (control);
+
+ control = *prev_control;
+
+ found = true;
+ }
+ else
+ {
+ prev_control = &control->next;
+ control = control->next;
+ }
+ }
+
+ if (found)
+ return RTEMS_SUCCESSFUL;
+
+ return RTEMS_INVALID_NAME;
+}
+
+/*
+ * rtems_capture_watch_set
+ *
+ * DESCRIPTION:
+ *
+ * This function allows control of a watch. The watch can be enabled or
+ * disabled.
+ */
+rtems_status_code
+rtems_capture_watch_ctrl (rtems_name name, rtems_id id, bool enable)
+{
+ rtems_interrupt_level level;
+ rtems_capture_control_t* control;
+ bool found = false;
+
+ /*
+ * Find the control and then set the watch. It must exist before it can
+ * be controlled.
+ */
+ for (control = capture_controls; control != NULL; control = control->next)
+ {
+ if (rtems_capture_match_name_id (control->name, control->id, name, id))
+ {
+ rtems_interrupt_disable (level);
+
+ if (enable)
+ control->flags |= RTEMS_CAPTURE_WATCH;
+ else
+ control->flags &= ~RTEMS_CAPTURE_WATCH;
+
+ rtems_interrupt_enable (level);
+
+ found = true;
+ }
+ }
+
+ if (found)
+ return RTEMS_SUCCESSFUL;
+
+ return RTEMS_INVALID_NAME;
+}
+
+/*
+ * rtems_capture_watch_global
+ *
+ * DESCRIPTION:
+ *
+ * This function allows control of a global watch. The watch can be enabled or
+ * disabled. A global watch configures all tasks below the ceiling and above
+ * the floor to be traced.
+ */
+rtems_status_code
+rtems_capture_watch_global (bool enable)
+{
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable (level);
+
+ /*
+ * We need to keep specific and global watches separate so
+ * a global enable/disable does not lose a specific watch.
+ */
+ if (enable)
+ capture_flags |= RTEMS_CAPTURE_GLOBAL_WATCH;
+ else
+ capture_flags &= ~RTEMS_CAPTURE_GLOBAL_WATCH;
+
+ rtems_interrupt_enable (level);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_watch_global_on
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the global watch state.
+ */
+bool
+rtems_capture_watch_global_on (void)
+{
+ return capture_flags & RTEMS_CAPTURE_GLOBAL_WATCH ? 1 : 0;
+}
+
+/*
+ * rtems_capture_watch_ceiling
+ *
+ * DESCRIPTION:
+ *
+ * This function sets a watch ceiling. Tasks at or greating that the
+ * ceiling priority are not watched. This is a simple way to monitor
+ * an application and exclude system tasks running at a higher
+ * priority level.
+ */
+rtems_status_code
+rtems_capture_watch_ceiling (rtems_task_priority ceiling)
+{
+ capture_ceiling = ceiling;
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_watch_get_ceiling
+ *
+ * DESCRIPTION:
+ *
+ * This function gets the watch ceiling.
+ */
+rtems_task_priority
+rtems_capture_watch_get_ceiling (void)
+{
+ return capture_ceiling;
+}
+
+/*
+ * rtems_capture_watch_floor
+ *
+ * DESCRIPTION:
+ *
+ * This function sets a watch floor. Tasks at or less that the
+ * floor priority are not watched. This is a simple way to monitor
+ * an application and exclude system tasks running at a lower
+ * priority level.
+ */
+rtems_status_code
+rtems_capture_watch_floor (rtems_task_priority floor)
+{
+ capture_floor = floor;
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_watch_get_floor
+ *
+ * DESCRIPTION:
+ *
+ * This function gets the watch floor.
+ */
+rtems_task_priority
+rtems_capture_watch_get_floor (void)
+{
+ return capture_floor;
+}
+
+/*
+ * rtems_capture_map_trigger
+ *
+ * DESCRIPTION:
+ *
+ * Map the trigger to a bit mask.
+ *
+ */
+uint32_t
+rtems_capture_map_trigger (rtems_capture_trigger_t trigger)
+{
+ /*
+ * Transform the mode and trigger to a bit map.
+ */
+ switch (trigger)
+ {
+ case rtems_capture_switch:
+ return RTEMS_CAPTURE_SWITCH;
+ case rtems_capture_create:
+ return RTEMS_CAPTURE_CREATE;
+ case rtems_capture_start:
+ return RTEMS_CAPTURE_START;
+ case rtems_capture_restart:
+ return RTEMS_CAPTURE_RESTART;
+ case rtems_capture_delete:
+ return RTEMS_CAPTURE_DELETE;
+ case rtems_capture_begin:
+ return RTEMS_CAPTURE_BEGIN;
+ case rtems_capture_exitted:
+ return RTEMS_CAPTURE_EXITTED;
+ default:
+ break;
+ }
+ return 0;
+}
+
+/*
+ * rtems_capture_set_trigger
+ *
+ * DESCRIPTION:
+ *
+ * This function sets a trigger.
+ *
+ * This set trigger routine will create a capture control for the
+ * target task. The task list is searched and any existing tasks
+ * are linked to the new control.
+ *
+ * We can have a number of tasks that have the same name so we
+ * search using names. This means a number of tasks can be
+ * linked to single control.
+ */
+rtems_status_code
+rtems_capture_set_trigger (rtems_name from_name,
+ rtems_id from_id,
+ rtems_name to_name,
+ rtems_id to_id,
+ rtems_capture_trigger_mode_t mode,
+ rtems_capture_trigger_t trigger)
+{
+ rtems_capture_control_t* control;
+ uint32_t flags;
+
+ flags = rtems_capture_map_trigger (trigger);
+
+ /*
+ * The mode sets the opposite type of trigger. For example
+ * FROM ANY means trigger when the event happens TO this
+ * task. TO ANY means FROM this task.
+ */
+
+ if (mode == rtems_capture_to_any)
+ {
+ control = rtems_capture_create_control (from_name, from_id);
+ if (control == NULL)
+ return RTEMS_NO_MEMORY;
+ control->from_triggers |= flags & RTEMS_CAPTURE_FROM_TRIGS;
+ }
+ else
+ {
+ control = rtems_capture_create_control (to_name, to_id);
+ if (control == NULL)
+ return RTEMS_NO_MEMORY;
+ if (mode == rtems_capture_from_any)
+ control->to_triggers |= flags;
+ else
+ {
+ bool done = false;
+ int i;
+
+ control->by_triggers |= flags;
+
+ for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
+ {
+ if (rtems_capture_control_by_valid (control, i) &&
+ ((control->by[i].name == from_name) ||
+ (from_id && (control->by[i].id == from_id))))
+ {
+ control->by[i].trigger |= flags;
+ done = true;
+ break;
+ }
+ }
+
+ if (!done)
+ {
+ for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
+ {
+ if (!rtems_capture_control_by_valid (control, i))
+ {
+ control->by_valid |= RTEMS_CAPTURE_CONTROL_FROM_MASK (i);
+ control->by[i].name = from_name;
+ control->by[i].id = from_id;
+ control->by[i].trigger = flags;
+ done = true;
+ break;
+ }
+ }
+ }
+
+ if (!done)
+ return RTEMS_TOO_MANY;
+ }
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_clear_trigger
+ *
+ * DESCRIPTION:
+ *
+ * This function clear a trigger.
+ */
+rtems_status_code
+rtems_capture_clear_trigger (rtems_name from_name,
+ rtems_id from_id,
+ rtems_name to_name,
+ rtems_id to_id,
+ rtems_capture_trigger_mode_t mode,
+ rtems_capture_trigger_t trigger)
+{
+ rtems_capture_control_t* control;
+ uint32_t flags;
+
+ flags = rtems_capture_map_trigger (trigger);
+
+ if (mode == rtems_capture_to_any)
+ {
+ control = rtems_capture_find_control (from_name, from_id);
+ if (control == NULL)
+ {
+ if (from_id)
+ return RTEMS_INVALID_ID;
+ return RTEMS_INVALID_NAME;
+ }
+ control->from_triggers &= ~flags;
+ }
+ else
+ {
+ control = rtems_capture_find_control (to_name, to_id);
+ if (control == NULL)
+ {
+ if (to_id)
+ return RTEMS_INVALID_ID;
+ return RTEMS_INVALID_NAME;
+ }
+ if (mode == rtems_capture_from_any)
+ control->to_triggers &= ~flags;
+ else
+ {
+ bool done = false;
+ int i;
+
+ control->by_triggers &= ~flags;
+
+ for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
+ {
+ if (rtems_capture_control_by_valid (control, i) &&
+ ((control->by[i].name == from_name) ||
+ (control->by[i].id == from_id)))
+ {
+ control->by[i].trigger &= ~trigger;
+ if (control->by[i].trigger == 0)
+ control->by_valid &= ~RTEMS_CAPTURE_CONTROL_FROM_MASK (i);
+ done = true;
+ break;
+ }
+ }
+
+ if (!done)
+ {
+ if (from_id)
+ return RTEMS_INVALID_ID;
+ return RTEMS_INVALID_NAME;
+ }
+ }
+ }
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_read
+ *
+ * DESCRIPTION:
+ *
+ * This function reads a number of records from the capture buffer.
+ * The user can optionally block and wait until the buffer as a
+ * specific number of records available or a specific time has
+ * elasped.
+ *
+ * The function returns the number of record that is has that are
+ * in a continous block of memory. If the number of available records
+ * wrap then only those records are provided. This removes the need for
+ * caller to be concerned about buffer wrappings. If the number of
+ * requested records cannot be met due to the wrapping of the records
+ * less than the specified number will be returned.
+ *
+ * The user must release the records. This is achieved with a call to
+ * rtems_capture_release. Calls this function without a release will
+ * result in at least the same number of records being released.
+ *
+ * The 'threshold' parameter is the number of records that must be
+ * captured before returning. If a timeout period is specified (non-0)
+ * any captured records will be returned. These parameters stop
+ * thrashing occuring for a small number of records, yet allows
+ * a user configured latiency to be applied for single events.
+ *
+ * The 'timeout' parameter is in micro-seconds. A value of 0 will disable
+ * the timeout.
+ *
+ */
+rtems_status_code
+rtems_capture_read (uint32_t threshold,
+ uint32_t timeout,
+ uint32_t* read,
+ rtems_capture_record_t** recs)
+{
+ rtems_interrupt_level level;
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ uint32_t count;
+
+ *read = 0;
+ *recs = NULL;
+
+ rtems_interrupt_disable (level);
+
+ /*
+ * Only one reader is allowed.
+ */
+
+ if (capture_flags & RTEMS_CAPTURE_READER_ACTIVE)
+ {
+ rtems_interrupt_enable (level);
+ return RTEMS_RESOURCE_IN_USE;
+ }
+
+ capture_flags |= RTEMS_CAPTURE_READER_ACTIVE;
+ *read = count = capture_count;
+
+ rtems_interrupt_enable (level);
+
+ *recs = &capture_records[capture_out];
+
+ for (;;)
+ {
+ /*
+ * See if the count wraps the end of the record buffer.
+ */
+ if (count && ((capture_out + count) >= capture_size))
+ *read = capture_size - capture_out;
+
+ /*
+ * Do we have a threshold and the current count has not wrapped
+ * around the end of the capture record buffer ?
+ */
+ if ((*read == count) && threshold)
+ {
+ /*
+ * Do we have enough records ?
+ */
+ if (*read < threshold)
+ {
+ rtems_event_set event_out;
+
+ rtems_task_ident (RTEMS_SELF, RTEMS_LOCAL, &capture_reader);
+
+ rtems_interrupt_disable (level);
+
+ capture_flags |= RTEMS_CAPTURE_READER_WAITING;
+
+ rtems_interrupt_enable (level);
+
+ sc = rtems_event_receive (RTEMS_EVENT_0,
+ RTEMS_WAIT | RTEMS_EVENT_ANY,
+ RTEMS_MICROSECONDS_TO_TICKS (timeout),
+ &event_out);
+
+ /*
+ * Let the user handle all other sorts of errors. This may
+ * not be the best solution, but oh well, it will do for
+ * now.
+ */
+ if ((sc != RTEMS_SUCCESSFUL) && (sc != RTEMS_TIMEOUT))
+ break;
+
+ rtems_interrupt_disable (level);
+
+ *read = count = capture_count;
+
+ rtems_interrupt_enable (level);
+
+ continue;
+ }
+ }
+
+ /*
+ * Always out if we reach here. To loop use continue.
+ */
+ break;
+ }
+
+ return sc;
+}
+
+/*
+ * rtems_capture_release
+ *
+ * DESCRIPTION:
+ *
+ * This function releases the requested number of record slots back
+ * to the capture engine. The count must match the number read.
+ */
+rtems_status_code
+rtems_capture_release (uint32_t count)
+{
+ rtems_capture_record_t* rec;
+ uint32_t counted;
+
+ rtems_interrupt_level level;
+
+ rtems_interrupt_disable (level);
+
+ if (count > capture_count)
+ count = capture_count;
+
+ rtems_interrupt_enable (level);
+
+ counted = count;
+
+ rec = &capture_records[capture_out];
+
+ while (counted--)
+ {
+ rtems_capture_refcount_down (rec->task);
+ rtems_capture_destroy_capture_task (rec->task);
+ rec++;
+ }
+
+ rtems_interrupt_disable (level);
+
+ capture_count -= count;
+
+ capture_out = (capture_out + count) % capture_size;
+
+ capture_flags &= ~RTEMS_CAPTURE_READER_ACTIVE;
+
+ rtems_interrupt_enable (level);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * rtems_capture_tick_time
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the tick period in nano-seconds.
+ */
+uint32_t
+rtems_capture_tick_time (void)
+{
+ return capture_tick_period;
+}
+
+/*
+ * rtems_capture_event_text
+ *
+ * DESCRIPTION:
+ *
+ * This function returns a string for an event based on the bit in the
+ * event. The functions takes the bit offset as a number not the bit
+ * set in a bit map.
+ */
+const char*
+rtems_capture_event_text (int event)
+{
+ if ((event < RTEMS_CAPTURE_EVENT_START) || (event > RTEMS_CAPTURE_EVENT_END))
+ return "invalid event id";
+ return capture_event_text[event - RTEMS_CAPTURE_EVENT_START];
+}
+
+/*
+ * rtems_capture_get_task_list
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the head of the list of tasks that the
+ * capture engine has detected.
+ */
+rtems_capture_task_t*
+rtems_capture_get_task_list (void)
+{
+ return capture_tasks;
+}
+
+/*
+ * rtems_capture_task_stack_usage
+ *
+ * DESCRIPTION:
+ *
+ * This function updates the stack usage. The task control block
+ * is updated.
+ */
+uint32_t
+rtems_capture_task_stack_usage (rtems_capture_task_t* task)
+{
+ if (task->tcb)
+ {
+ uint32_t* st;
+ uint32_t* s;
+
+ /*
+ * @todo: Assumes all stacks move the same way.
+ */
+ st = task->tcb->Start.Initial_stack.area + task->stack_size;
+ s = task->tcb->Start.Initial_stack.area;
+
+ while (s < st)
+ {
+ if (*s != 0xdeaddead)
+ break;
+ s++;
+ }
+
+ task->stack_clean =
+ s - (uint32_t*) task->tcb->Start.Initial_stack.area;
+ }
+
+ return task->stack_clean;
+}
+
+/*
+ * rtems_capture_get_control_list
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the head of the list of control in the
+ * capture engine.
+ */
+rtems_capture_control_t*
+rtems_capture_get_control_list (void)
+{
+ return capture_controls;
+}
diff --git a/cpukit/libmisc/capture/capture.h b/cpukit/libmisc/capture/capture.h
new file mode 100644
index 0000000000..48ba5ebec4
--- /dev/null
+++ b/cpukit/libmisc/capture/capture.h
@@ -0,0 +1,1042 @@
+/**
+ * @file rtems/capture.h
+ */
+
+/*
+ ------------------------------------------------------------------------
+ $Id$
+ ------------------------------------------------------------------------
+
+ Copyright Objective Design Systems Pty Ltd, 2002
+ All rights reserved Objective Design Systems Pty Ltd, 2002
+ Chris Johns (ccj@acm.org)
+
+ COPYRIGHT (c) 1989-1998.
+ On-Line Applications Research Corporation (OAR).
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution.
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ ------------------------------------------------------------------------
+
+ RTEMS Performance Monitoring and Measurement Framework.
+ This is the Capture Engine component.
+
+*/
+
+#ifndef __CAPTURE_H_
+#define __CAPTURE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems.h>
+
+/**
+ * The number of tasks in a trigger group.
+ */
+#define RTEMS_CAPTURE_TRIGGER_TASKS (32)
+
+/**
+ * rtems_capture_from_t
+ *
+ * DESCRIPTION:
+ *
+ * A from capture is a task id and a mask for the type of
+ * from trigger we are interested in. The mask uses the same
+ * bit maps as the flags field in the control structure. There
+ * will only be a from type trigger if the flags in the control
+ * structure has the specific *_BY bit set.
+ */
+typedef struct rtems_capture_from_s
+{
+ rtems_name name;
+ rtems_id id;
+ uint32_t trigger;
+} rtems_capture_from_t;
+
+/**
+ * rtems_capture_control_t
+ *
+ * DESCRIPTION:
+ *
+ * RTEMS control holds the trigger and watch configuration for a group of
+ * tasks with the same name. The flags hold global control flags.
+ *
+ * The to_triggers fields holds triggers TO this task. The from_triggers holds
+ * triggers from this task. The by_triggers is an OR or triggers which are
+ * caused BY the task listed TO this task. The by_valid flag which entries
+ * in by are valid.
+ */
+typedef struct rtems_capture_control_s
+{
+ rtems_name name;
+ rtems_id id;
+ uint32_t flags;
+ uint32_t to_triggers;
+ uint32_t from_triggers;
+ uint32_t by_triggers;
+ uint32_t by_valid;
+ rtems_capture_from_t by[RTEMS_CAPTURE_TRIGGER_TASKS];
+ struct rtems_capture_control_s* next;
+} rtems_capture_control_t;
+
+/**
+ * The from_valid mask.
+ */
+#define RTEMS_CAPTURE_CONTROL_FROM_MASK(_s) \
+ (UINT32_C(1) << (RTEMS_CAPTURE_TRIGGER_TASKS - ((_s) + 1)))
+
+/**
+ * Control flags.
+ */
+#define RTEMS_CAPTURE_WATCH (1 << 0)
+
+/**
+ * Control triggers.
+ */
+#define RTEMS_CAPTURE_SWITCH (1 << 0)
+#define RTEMS_CAPTURE_CREATE (1 << 1)
+#define RTEMS_CAPTURE_START (1 << 2)
+#define RTEMS_CAPTURE_RESTART (1 << 3)
+#define RTEMS_CAPTURE_DELETE (1 << 4)
+#define RTEMS_CAPTURE_BEGIN (1 << 5)
+#define RTEMS_CAPTURE_EXITTED (1 << 6)
+
+#define RTEMS_CAPTURE_FROM_TRIGS (RTEMS_CAPTURE_SWITCH | \
+ RTEMS_CAPTURE_CREATE | \
+ RTEMS_CAPTURE_START | \
+ RTEMS_CAPTURE_RESTART | \
+ RTEMS_CAPTURE_DELETE)
+
+#define RTEMS_CAPTURE_TO_TRIGS (RTEMS_CAPTURE_SWITCH | \
+ RTEMS_CAPTURE_CREATE | \
+ RTEMS_CAPTURE_START | \
+ RTEMS_CAPTURE_RESTART | \
+ RTEMS_CAPTURE_DELETE | \
+ RTEMS_CAPTURE_BEGIN | \
+ RTEMS_CAPTURE_EXITTED)
+
+/**
+ * rtems_capture_task_t
+ *
+ * DESCRIPTION:
+ *
+ * RTEMS capture control provdes the information about a task, along
+ * with its trigger state. The control is referenced by each
+ * capture record. This is information neeed by the decoder. The
+ * capture record cannot assume the task will exist when the record is
+ * dumped via the target interface so task info needed for tracing is
+ * copied and held here. Once the references in the trace buffer
+ * have been removed and the task is deleted this structure is
+ * released back to the heap.
+ *
+ * The inline helper functions provide more details about the info
+ * contained in this structure.
+ *
+ * Note, the tracer code exploits the fact an rtems_name is a
+ * 32bit value.
+ */
+typedef struct rtems_capture_task_s
+{
+ rtems_name name;
+ rtems_id id;
+ uint32_t flags;
+ uint32_t refcount;
+ rtems_tcb* tcb;
+ uint32_t in;
+ uint32_t out;
+ rtems_task_priority start_priority;
+ uint32_t stack_size;
+ uint32_t stack_clean;
+ uint32_t ticks;
+ uint32_t tick_offset;
+ uint32_t ticks_in;
+ uint32_t tick_offset_in;
+ uint32_t last_ticks;
+ uint32_t last_tick_offset;
+ rtems_capture_control_t* control;
+ struct rtems_capture_task_s* forw;
+ struct rtems_capture_task_s* back;
+} rtems_capture_task_t;
+
+/**
+ * Task flags.
+ */
+#define RTEMS_CAPTURE_TRACED (1 << 0)
+
+/*
+ * rtems_capture_record_t
+ *
+ * DESCRIPTION:
+ *
+ * RTEMS capture record. This is a record that is written into
+ * the buffer. The events includes the priority of the task
+ * at the time of the context switch.
+ */
+typedef struct rtems_capture_record_s
+{
+ rtems_capture_task_t* task;
+ uint32_t events;
+ uint32_t ticks;
+ uint32_t tick_offset;
+} rtems_capture_record_t;
+
+/**
+ * The capture record event flags.
+ */
+#define RTEMS_CAPTURE_REAL_PRI_EVENT_MASK UINT32_C (0x000000ff)
+#define RTEMS_CAPTURE_CURR_PRI_EVENT_MASK UINT32_C (0x0000ff00)
+#define RTEMS_CAPTURE_REAL_PRIORITY_EVENT (0)
+#define RTEMS_CAPTURE_CURR_PRIORITY_EVENT (8)
+#define RTEMS_CAPTURE_EVENT_START (16)
+#define RTEMS_CAPTURE_CREATED_BY_EVENT UINT32_C (0x00010000)
+#define RTEMS_CAPTURE_CREATED_EVENT UINT32_C (0x00020000)
+#define RTEMS_CAPTURE_STARTED_BY_EVENT UINT32_C (0x00040000)
+#define RTEMS_CAPTURE_STARTED_EVENT UINT32_C (0x00080000)
+#define RTEMS_CAPTURE_RESTARTED_BY_EVENT UINT32_C (0x00100000)
+#define RTEMS_CAPTURE_RESTARTED_EVENT UINT32_C (0x00200000)
+#define RTEMS_CAPTURE_DELETED_BY_EVENT UINT32_C (0x00400000)
+#define RTEMS_CAPTURE_DELETED_EVENT UINT32_C (0x00800000)
+#define RTEMS_CAPTURE_BEGIN_EVENT UINT32_C (0x01000000)
+#define RTEMS_CAPTURE_EXITTED_EVENT UINT32_C (0x02000000)
+#define RTEMS_CAPTURE_SWITCHED_OUT_EVENT UINT32_C (0x04000000)
+#define RTEMS_CAPTURE_SWITCHED_IN_EVENT UINT32_C (0x08000000)
+#define RTEMS_CAPTURE_TIMESTAMP UINT32_C (0x10000000)
+#define RTEMS_CAPTURE_EVENT_END (28)
+
+/**
+ * rtems_capture_trigger_mode_t
+ *
+ * DESCRIPTION:
+ *
+ * The types of trigger modes that exist.
+ */
+typedef enum rtems_capture_trigger_mode_e
+{
+ rtems_capture_to_any,
+ rtems_capture_from_any,
+ rtems_capture_from_to
+} rtems_capture_trigger_mode_t;
+
+/**
+ * rtems_capture_trigger_t
+ *
+ * DESCRIPTION:
+ *
+ * The types of triggers that exist.
+ */
+typedef enum rtems_capture_trigger_e
+{
+ rtems_capture_switch,
+ rtems_capture_create,
+ rtems_capture_start,
+ rtems_capture_restart,
+ rtems_capture_delete,
+ rtems_capture_begin,
+ rtems_capture_exitted
+} rtems_capture_trigger_t;
+
+/**
+ * rtems_capture_timestamp
+ *
+ * DESCRIPTION:
+ *
+ * This defines the callout handler to obtain a time stamp. The
+ * value returned is time count since the last read.
+ *
+ */
+
+typedef void (*rtems_capture_timestamp)
+ (uint32_t* ticks, uint32_t* micro);
+
+/**
+ * rtems_capture_open
+ *
+ * DESCRIPTION:
+ *
+ * This function initialises the realtime trace manager allocating the
+ * capture buffer. It is assumed we have a working heap at stage of
+ * initialisation.
+ *
+ */
+rtems_status_code
+rtems_capture_open (uint32_t size,
+ rtems_capture_timestamp timestamp);
+
+/**
+ * rtems_capture_close
+ *
+ * DESCRIPTION:
+ *
+ * This function shutdowns the tracer and release any claimed
+ * resources.
+ */
+rtems_status_code
+rtems_capture_close (void);
+
+/**
+ * rtems_capture_control
+ *
+ * DESCRIPTION:
+ *
+ * This function allows control of tracing at a global level.
+ */
+rtems_status_code
+rtems_capture_control (bool enable);
+
+/**
+ * rtems_capture_monitor
+ *
+ * DESCRIPTION:
+ *
+ * This function enable the monitor mode. When in the monitor mode
+ * the tasks are monitored but no data is saved. This can be used
+ * to profile the load on a system.
+ */
+rtems_status_code
+rtems_capture_monitor (bool enable);
+
+/*
+ * rtems_capture_flush
+ *
+ * DESCRIPTION:
+ *
+ * This function flushes the trace buffer. The prime parameter allows the
+ * capture engine to also be primed again.
+ */
+rtems_status_code
+rtems_capture_flush (bool prime);
+
+/**
+ * rtems_capture_watch_add
+ *
+ * DESCRIPTION:
+ *
+ * This function defines a watch for a specific task given a name. A watch
+ * causes it to be traced either in or out of context. The watch can be
+ * optionally enabled or disabled with the set routine. It is disabled by
+ * default.
+ */
+rtems_status_code
+rtems_capture_watch_add (rtems_name name, rtems_id id);
+
+/**
+ * rtems_capture_watch_del
+ *
+ * DESCRIPTION:
+ *
+ * This function removes a watch for a specific task given a name. The task
+ * description will still exist if referenced by a trace record in the trace
+ * buffer or a global watch is defined.
+ */
+rtems_status_code
+rtems_capture_watch_del (rtems_name name, rtems_id id);
+
+/**
+ * rtems_capture_watch_set
+ *
+ * DESCRIPTION:
+ *
+ * This function allows control of a watch. The watch can be enabled or
+ * disabled.
+ */
+rtems_status_code
+rtems_capture_watch_ctrl (rtems_name name,
+ rtems_id id,
+ bool enable);
+
+/**
+ * rtems_capture_watch_global
+ *
+ * DESCRIPTION:
+ *
+ * This function allows control of a global watch. The watch can
+ * be enabled or disabled. A global watch configures all tasks below
+ * the ceiling and above the floor to be traced.
+ */
+rtems_status_code
+rtems_capture_watch_global (bool enable);
+
+/**
+ * rtems_capture_watch_global_on
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the global watch state.
+ */
+bool
+rtems_capture_watch_global_on (void);
+
+/**
+ * rtems_capture_watch_ceiling
+ *
+ * DESCRIPTION:
+ *
+ * This function sets a watch ceiling. Tasks at or greating that the
+ * ceiling priority are not watched. This is a simple way to monitor
+ * an application and exclude system tasks running at a higher
+ * priority level.
+ */
+rtems_status_code
+rtems_capture_watch_ceiling (rtems_task_priority ceiling);
+
+/**
+ * rtems_capture_watch_get_ceiling
+ *
+ * DESCRIPTION:
+ *
+ * This function gets the watch ceiling.
+ */
+rtems_task_priority
+rtems_capture_watch_get_ceiling (void);
+
+/**
+ * rtems_capture_watch_floor
+ *
+ * DESCRIPTION:
+ *
+ * This function sets a watch floor. Tasks at or less that the
+ * floor priority are not watched. This is a simple way to monitor
+ * an application and exclude system tasks running at a lower
+ * priority level.
+ */
+rtems_status_code
+rtems_capture_watch_floor (rtems_task_priority floor);
+
+/**
+ * rtems_capture_watch_get_floor
+ *
+ * DESCRIPTION:
+ *
+ * This function gets the watch floor.
+ */
+rtems_task_priority
+rtems_capture_watch_get_floor (void);
+
+/**
+ * rtems_capture_set_trigger
+ *
+ * DESCRIPTION:
+ *
+ * This function sets a trigger.
+ *
+ * This set trigger routine will create a trace control for the
+ * target task. The task list is searched and any existing tasks
+ * are linked to the new control.
+ *
+ * We can have a number of tasks that have the same name so we
+ * search using names. This means a number of tasks can be
+ * linked to single control.
+ */
+rtems_status_code
+rtems_capture_set_trigger (rtems_name from_name,
+ rtems_id from_id,
+ rtems_name to_name,
+ rtems_id to_id,
+ rtems_capture_trigger_mode_t mode,
+ rtems_capture_trigger_t trigger);
+
+/**
+ * rtems_capture_clear_trigger
+ *
+ * DESCRIPTION:
+ *
+ * This function clears a trigger.
+ *
+ * This clear trigger routine will not clear a watch.
+ */
+rtems_status_code
+rtems_capture_clear_trigger (rtems_name from_name,
+ rtems_id from_id,
+ rtems_name to_name,
+ rtems_id to_id,
+ rtems_capture_trigger_mode_t mode,
+ rtems_capture_trigger_t trigger);
+
+/**
+ * rtems_capture_read
+ *
+ * DESCRIPTION:
+ *
+ * This function reads a number of records from the capture buffer.
+ * The user can optionally block and wait until the buffer as a
+ * specific number of records available or a specific time has
+ * elasped.
+ *
+ * The function returns the number of record that is has that are
+ * in a continous block of memory. If the number of available records
+ * wrap then only those records are provided. This removes the need for
+ * caller to be concerned about buffer wrappings. If the number of
+ * requested records cannot be met due to the wrapping of the records
+ * less than the specified number will be returned.
+ *
+ * The user must release the records. This is achieved with a call to
+ * rtems_capture_release. Calls this function without a release will
+ * result in at least the same number of records being released.
+ *
+ * The 'threshold' parameter is the number of records that must be
+ * captured before returning. If a timeout period is specified (non-0)
+ * any captured records will be returned. These parameters stop
+ * thrashing occuring for a small number of records, yet allows
+ * a user configured latiency to be applied for single events.
+ *
+ * The 'timeout' parameter is in micro-seconds. A value of 0 will
+ * disable the timeout.
+ *
+ */
+rtems_status_code
+rtems_capture_read (uint32_t threshold,
+ uint32_t timeout,
+ uint32_t* read,
+ rtems_capture_record_t** recs);
+
+/**
+ * rtems_capture_release
+ *
+ * DESCRIPTION:
+ *
+ * This function releases the requested number of record slots back
+ * to the capture engine. The count must match the number read.
+ */
+rtems_status_code
+rtems_capture_release (uint32_t count);
+
+/**
+ * rtems_capture_tick_time
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the tick period in micro-seconds.
+ */
+uint32_t
+rtems_capture_tick_time (void);
+
+/*
+ * rtems_capture_tick_time
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the tick period in micro-seconds.
+ */
+uint32_t
+rtems_capture_tick_time (void);
+
+/**
+ * rtems_capture_event_text
+ *
+ * DESCRIPTION:
+ *
+ * This function returns a string for an event based on the bit in the
+ * event. The functions takes the bit offset as a number not the bit
+ * set in a bit map.
+ */
+const char*
+rtems_capture_event_text (int event);
+
+/**
+ * rtems_capture_get_task_list
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the head of the list of tasks that the
+ * capture engine has detected.
+ */
+rtems_capture_task_t*
+rtems_capture_get_task_list (void);
+
+/**
+ * rtems_capture_next_task
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the pointer to the next task in the list. The
+ * pointer NULL terminates the list.
+ */
+static inline rtems_capture_task_t*
+rtems_capture_next_task (rtems_capture_task_t* task)
+{
+ return task->forw;
+}
+
+/**
+ * rtems_capture_task_valid
+ *
+ * DESCRIPTION:
+ *
+ * This function returns true if the task control block points to
+ * a valid task.
+ */
+static inline bool
+rtems_capture_task_valid (rtems_capture_task_t* task)
+{
+ return task->tcb != NULL;
+}
+
+/**
+ * rtems_capture_task_id
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task id.
+ */
+static inline rtems_id
+rtems_capture_task_id (rtems_capture_task_t* task)
+{
+ return task->id;
+}
+
+/**
+ * rtems_capture_task_state
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task state.
+ */
+static inline States_Control
+rtems_capture_task_state (rtems_capture_task_t* task)
+{
+ if (rtems_capture_task_valid (task))
+ return task->tcb->current_state;
+ return 0;
+}
+
+/**
+ * rtems_capture_task_name
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task name.
+ */
+static inline rtems_name
+rtems_capture_task_name (rtems_capture_task_t* task)
+{
+ return task->name;
+}
+
+/**
+ * rtems_capture_task_flags
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task flags.
+ */
+static inline uint32_t
+rtems_capture_task_flags (rtems_capture_task_t* task)
+{
+ return task->flags;
+}
+
+/**
+ * rtems_capture_task_control
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task control if present.
+ */
+static inline rtems_capture_control_t*
+rtems_capture_task_control (rtems_capture_task_t* task)
+{
+ return task->control;
+}
+
+/**
+ * rtems_capture_task_control_flags
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task control flags if a control is present.
+ */
+static inline uint32_t
+rtems_capture_task_control_flags (rtems_capture_task_t* task)
+{
+ if (!task->control)
+ return 0;
+ return task->control->flags;
+}
+
+/**
+ * rtems_capture_task_switched_in
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the number of times the task has
+ * been switched into context.
+ */
+static inline uint32_t
+rtems_capture_task_switched_in (rtems_capture_task_t* task)
+{
+ return task->in;
+}
+
+/**
+ * rtems_capture_task_switched_out
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the number of times the task has
+ * been switched out of context.
+ */
+static inline uint32_t
+rtems_capture_task_switched_out (rtems_capture_task_t* task)
+{
+ return task->out;
+}
+
+/**
+ * rtems_capture_task_curr_priority
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the tasks start priority. The tracer needs this
+ * to track where the task's priority goes.
+ */
+static inline rtems_task_priority
+rtems_capture_task_start_priority (rtems_capture_task_t* task)
+{
+ return task->start_priority;
+}
+
+/**
+ * rtems_capture_task_real_priority
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the tasks real priority.
+ */
+static inline rtems_task_priority
+rtems_capture_task_real_priority (rtems_capture_task_t* task)
+{
+ if (rtems_capture_task_valid (task))
+ return task->tcb->real_priority;
+ return 0;
+}
+
+/**
+ * rtems_capture_task_curr_priority
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the tasks current priority.
+ */
+static inline rtems_task_priority
+rtems_capture_task_curr_priority (rtems_capture_task_t* task)
+{
+ if (rtems_capture_task_valid (task))
+ return task->tcb->current_priority;
+ return 0;
+}
+
+/**
+ * rtems_capture_task_stack_usage
+ *
+ * DESCRIPTION:
+ *
+ * This function updates the stack usage. The task control block
+ * is updated.
+ */
+uint32_t
+rtems_capture_task_stack_usage (rtems_capture_task_t* task);
+
+/**
+ * rtems_capture_task_stack_size
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task's stack size.
+ */
+static inline uint32_t
+rtems_capture_task_stack_size (rtems_capture_task_t* task)
+{
+ return task->stack_size;
+}
+
+/**
+ * rtems_capture_task_stack_used
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the amount of stack used.
+ */
+static inline uint32_t
+rtems_capture_task_stack_used (rtems_capture_task_t* task)
+{
+ return task->stack_size - task->stack_clean;
+}
+
+/**
+ * rtems_capture_task_ticks
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the current execution time as ticks.
+ */
+static inline uint32_t
+rtems_capture_task_ticks (rtems_capture_task_t* task)
+{
+ return task->ticks;
+}
+
+/**
+ * rtems_capture_task_tick_offset
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the current execution time tick offset.
+ */
+static inline uint32_t
+rtems_capture_task_tick_offset (rtems_capture_task_t* task)
+{
+ return task->tick_offset;
+}
+
+/**
+ * rtems_capture_task_time
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the current execution time.
+ */
+static inline unsigned long long
+rtems_capture_task_time (rtems_capture_task_t* task)
+{
+ unsigned long long t = task->ticks;
+ return (t * rtems_capture_tick_time ()) + task->tick_offset;;
+}
+
+/**
+ * rtems_capture_task_delta_time
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the execution time as a different between the
+ * last time the detla time was and now.
+ */
+static inline unsigned long long
+rtems_capture_task_delta_time (rtems_capture_task_t* task)
+{
+ unsigned long long t = task->ticks - task->last_ticks;
+ uint32_t o = task->tick_offset - task->last_tick_offset;
+
+ task->last_ticks = task->ticks;
+ task->last_tick_offset = task->tick_offset;
+
+ return (t * rtems_capture_tick_time ()) + o;
+}
+
+/**
+ * rtems_capture_task_count
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the number of tasks the capture
+ * engine knows about.
+ */
+static inline uint32_t
+rtems_capture_task_count (void)
+{
+ rtems_capture_task_t* task = rtems_capture_get_task_list ();
+ uint32_t count = 0;
+
+ while (task)
+ {
+ count++;
+ task = rtems_capture_next_task (task);
+ }
+
+ return count;
+}
+
+/**
+ * rtems_capture_get_control_list
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the head of the list of controls in the
+ * capture engine.
+ */
+rtems_capture_control_t*
+rtems_capture_get_control_list (void);
+
+/**
+ * rtems_capture_next_control
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the pointer to the next control in the list. The
+ * pointer NULL terminates the list.
+ */
+static inline rtems_capture_control_t*
+rtems_capture_next_control (rtems_capture_control_t* control)
+{
+ return control->next;
+}
+
+/**
+ * rtems_capture_control_id
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control id.
+ */
+static inline rtems_id
+rtems_capture_control_id (rtems_capture_control_t* control)
+{
+ return control->id;
+}
+
+/**
+ * rtems_capture_control_name
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control name.
+ */
+static inline rtems_name
+rtems_capture_control_name (rtems_capture_control_t* control)
+{
+ return control->name;
+}
+
+/**
+ * rtems_capture_control_flags
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control flags.
+ */
+static inline uint32_t
+rtems_capture_control_flags (rtems_capture_control_t* control)
+{
+ return control->flags;
+}
+
+/**
+ * rtems_capture_control_to_triggers
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task control to triggers.
+ */
+static inline uint32_t
+rtems_capture_control_to_triggers (rtems_capture_control_t* control)
+{
+ return control->to_triggers;
+}
+
+/**
+ * rtems_capture_control_from_triggers
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task control from triggers.
+ */
+static inline uint32_t
+rtems_capture_control_from_triggers (rtems_capture_control_t* control)
+{
+ return control->from_triggers;
+}
+
+/**
+ * rtems_capture_control_all_by_triggers
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the task control by triggers.
+ */
+static inline uint32_t
+rtems_capture_control_all_by_triggers (rtems_capture_control_t* control)
+{
+ return control->by_triggers;
+}
+
+/**
+ * rtems_capture_control_by_valid
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control valid BY flags.
+ */
+static inline int
+rtems_capture_control_by_valid (rtems_capture_control_t* control, int slot)
+{
+ return control->by_valid & RTEMS_CAPTURE_CONTROL_FROM_MASK (slot);
+}
+
+/**
+ * rtems_capture_control_by_name
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control BY task name.
+ */
+static inline rtems_name
+rtems_capture_control_by_name (rtems_capture_control_t* control, int by)
+{
+ if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
+ return control->by[by].name;
+ return control->by[0].name;
+}
+
+/**
+ * rtems_capture_control_by_id
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control BY task id.
+ */
+static inline rtems_id
+rtems_capture_control_by_id (rtems_capture_control_t* control, int by)
+{
+ if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
+ return control->by[by].id;
+ return control->by[0].id;
+}
+
+/**
+ * rtems_capture_control_by_triggers
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the control BY task triggers.
+ */
+static inline uint32_t
+rtems_capture_control_by_triggers (rtems_capture_control_t* control,
+ int by)
+{
+ if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
+ return control->by[by].trigger;
+ return control->by[0].trigger;
+}
+
+/**
+ * rtems_capture_control_count
+ *
+ * DESCRIPTION:
+ *
+ * This function returns the number of controls the capture
+ * engine has.
+ */
+static inline uint32_t
+rtems_capture_control_count (void)
+{
+ rtems_capture_control_t* control = rtems_capture_get_control_list ();
+ uint32_t count = 0;
+
+ while (control)
+ {
+ count++;
+ control = rtems_capture_next_control (control);
+ }
+
+ return count;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libmisc/cpuuse/README b/cpukit/libmisc/cpuuse/README
new file mode 100644
index 0000000000..ac674bb0b6
--- /dev/null
+++ b/cpukit/libmisc/cpuuse/README
@@ -0,0 +1,21 @@
+#
+# $Id$
+#
+
+This directory contains code to report and reset per-task CPU usage.
+If the BSP supports nanosecond timestamp granularity, this this information
+is very accurate. Otherwise, it is dependendent on the tick granularity.
+
+It provides two primary features:
+
+ + Generate a CPU Usage Report
+ + Reset CPU Usage Information
+
+NOTES:
+
+1. If configured for tick granularity, CPU usage is "docked" by a
+ clock tick at each context switch.
+2. If configured for nanosecond granularity, no work is done at each
+ clock tick. All bookkeeping is done as part of a context switch.
+
+
diff --git a/cpukit/libmisc/cpuuse/cpuusagedata.c b/cpukit/libmisc/cpuuse/cpuusagedata.c
new file mode 100644
index 0000000000..2d74b7eadf
--- /dev/null
+++ b/cpukit/libmisc/cpuuse/cpuusagedata.c
@@ -0,0 +1,28 @@
+/*
+ * CPU Usage Reporter - Shared Data
+ *
+ * COPYRIGHT (c) 1989-2009
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/cpuuse.h>
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timespec.h>
+#endif
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ struct timespec CPU_usage_Uptime_at_last_reset;
+#else
+ uint32_t CPU_usage_Ticks_at_last_reset;
+#endif
diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
new file mode 100644
index 0000000000..92445520b7
--- /dev/null
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -0,0 +1,205 @@
+/*
+ * CPU Usage Reporter
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include <rtems/cpuuse.h>
+#include <rtems/bspIo.h>
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timestamp.h>
+#endif
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
+#else
+ extern uint32_t CPU_usage_Ticks_at_last_reset;
+#endif
+
+/*PAGE
+ *
+ * rtems_cpu_usage_report
+ */
+
+void rtems_cpu_usage_report_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+)
+{
+ uint32_t i;
+ uint32_t api_index;
+ Thread_Control *the_thread;
+ Objects_Information *information;
+ char name[13];
+ uint32_t ival, fval;
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ Timestamp_Control uptime, total, ran, uptime_at_last_reset;
+ #else
+ uint32_t total_units = 0;
+ #endif
+
+ if ( !print )
+ return;
+
+ /*
+ * When not using nanosecond CPU usage resolution, we have to count
+ * the number of "ticks" we gave credit for to give the user a rough
+ * guideline as to what each number means proportionally.
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_Set_to_zero( &total );
+ uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
+ #else
+ for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
+ #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
+ if ( !_Objects_Information_table[ api_index ] )
+ continue;
+ #endif
+
+ information = _Objects_Information_table[ api_index ][ 1 ];
+ if ( information ) {
+ for ( i=1 ; i <= information->maximum ; i++ ) {
+ the_thread = (Thread_Control *)information->local_table[ i ];
+
+ if ( the_thread )
+ total_units += the_thread->cpu_time_used;
+ }
+ }
+ }
+ #endif
+
+ (*print)(
+ context,
+ "-------------------------------------------------------------------------------\n"
+ " CPU USAGE BY THREAD\n"
+ "------------+----------------------------------------+---------------+---------\n"
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ " ID | NAME | SECONDS | PERCENT\n"
+ #else
+ " ID | NAME | TICKS | PERCENT\n"
+ #endif
+ "------------+----------------------------------------+---------------+---------\n"
+ );
+
+ for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
+ #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
+ if ( !_Objects_Information_table[ api_index ] )
+ continue;
+ #endif
+
+ information = _Objects_Information_table[ api_index ][ 1 ];
+ if ( information ) {
+ for ( i=1 ; i <= information->maximum ; i++ ) {
+ the_thread = (Thread_Control *)information->local_table[ i ];
+
+ if ( !the_thread )
+ continue;
+
+ rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
+
+ (*print)(
+ context,
+ " 0x%08" PRIx32 " | %-38s |",
+ the_thread->Object.id,
+ name
+ );
+
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ /*
+ * If this is the currently executing thread, account for time
+ * since the last context switch.
+ */
+ ran = the_thread->cpu_time_used;
+ if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
+ Timestamp_Control used;
+ Timestamp_Control last = _Thread_Time_of_last_context_switch;
+ _TOD_Get_uptime( &uptime );
+ _Timestamp_Subtract( &last, &uptime, &used );
+ _Timestamp_Add_to( &ran, &used );
+ } else {
+ _TOD_Get_uptime( &uptime );
+ }
+ _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
+ _Timestamp_Divide( &ran, &total, &ival, &fval );
+
+ /*
+ * Print the information
+ */
+
+ (*print)( context,
+ "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
+ _Timestamp_Get_seconds( &ran ),
+ _Timestamp_Get_nanoseconds( &ran ) /
+ TOD_NANOSECONDS_PER_MICROSECOND,
+ ival, fval
+ );
+ #else
+ if (total_units) {
+ uint64_t ival_64;
+
+ ival_64 = the_thread->cpu_time_used;
+ ival_64 *= 100000;
+ ival = ival_64 / total_units;
+ } else {
+ ival = 0;
+ }
+
+ fval = ival % 1000;
+ ival /= 1000;
+ (*print)( context,
+ "%14" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
+ the_thread->cpu_time_used,
+ ival,
+ fval
+ );
+ #endif
+ }
+ }
+ }
+
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ (*print)(
+ context,
+ "------------+----------------------------------------+---------------+---------\n"
+ " TIME SINCE LAST CPU USAGE RESET IN SECONDS: %7" PRIu32 ".%06" PRIu32 "\n"
+ "-------------------------------------------------------------------------------\n",
+ _Timestamp_Get_seconds( &total ),
+ _Timestamp_Get_nanoseconds( &total ) / TOD_NANOSECONDS_PER_MICROSECOND
+ );
+ #else
+ (*print)(
+ context,
+ "------------+----------------------------------------+---------------+---------\n"
+ " TICKS SINCE LAST SYSTEM RESET: %14" PRIu32 "\n"
+ " TOTAL UNITS: %14" PRIu32 "\n"
+ "-------------------------------------------------------------------------------\n",
+ _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset,
+ total_units
+ );
+ #endif
+}
+
+void rtems_cpu_usage_report( void )
+{
+ rtems_cpu_usage_report_with_plugin( NULL, printk_plugin );
+}
diff --git a/cpukit/libmisc/cpuuse/cpuusagereset.c b/cpukit/libmisc/cpuuse/cpuusagereset.c
new file mode 100644
index 0000000000..0bf46903f1
--- /dev/null
+++ b/cpukit/libmisc/cpuuse/cpuusagereset.c
@@ -0,0 +1,60 @@
+/*
+ * CPU Usage Reporter
+ *
+ * COPYRIGHT (c) 1989-2009
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/score/timestamp.h>
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include <rtems/cpuuse.h>
+
+static void CPU_usage_Per_thread_handler(
+ Thread_Control *the_thread
+)
+{
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_Set_to_zero( &the_thread->cpu_time_used );
+ #else
+ the_thread->cpu_time_used = 0;
+ #endif
+}
+
+/*
+ * External data that is shared by cpu usage code but not declared in .h files.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
+#else
+ extern uint32_t CPU_usage_Ticks_at_last_reset;
+#endif
+
+/*
+ * rtems_cpu_usage_reset
+ */
+void rtems_cpu_usage_reset( void )
+{
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _TOD_Get_uptime( &CPU_usage_Uptime_at_last_reset );
+ _Thread_Time_of_last_context_switch = CPU_usage_Uptime_at_last_reset;
+ #else
+ CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
+ #endif
+
+ rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
+}
diff --git a/cpukit/libmisc/cpuuse/cpuuse.h b/cpukit/libmisc/cpuuse/cpuuse.h
new file mode 100644
index 0000000000..b38927e7c6
--- /dev/null
+++ b/cpukit/libmisc/cpuuse/cpuuse.h
@@ -0,0 +1,51 @@
+/* cpuuse.h
+ *
+ * This include file contains information necessary to utilize
+ * and install the cpu usage reporting mechanism.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __RTEMS_CPUUSE_h
+#define __RTEMS_CPUUSE_h
+
+#include <rtems/bspIo.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * rtems_cpu_usage_report_with_handler
+ */
+
+void rtems_cpu_usage_report_with_plugin(
+ void *context,
+ rtems_printk_plugin_t handler
+);
+
+/*
+ * rtems_cpu_usage_report
+ */
+
+void rtems_cpu_usage_report( void );
+
+/*
+ * rtems_cpu_usage_reset
+ */
+
+void rtems_cpu_usage_reset( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libmisc/devnull/devnull.c b/cpukit/libmisc/devnull/devnull.c
new file mode 100644
index 0000000000..4b22199814
--- /dev/null
+++ b/cpukit/libmisc/devnull/devnull.c
@@ -0,0 +1,184 @@
+/* /dev/null
+ *
+ * Derived from rtems' stub driver.
+ *
+ * Author: Ralf Corsepius (corsepiu@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1989-2000.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/devnull.h>
+#include <rtems/libio.h>
+
+/* null_initialize
+ *
+ * This routine is the null device driver init routine.
+ *
+ * Input parameters:
+ * major - device major number
+ * minor - device minor number
+ * pargp - pointer to parameter block
+ *
+ * Output parameters:
+ * rval - NULL_SUCCESSFUL
+ */
+
+uint32_t NULL_major;
+static char initialized;
+
+rtems_device_driver null_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *pargp __attribute__((unused))
+)
+{
+ rtems_device_driver status;
+
+ if ( !initialized ) {
+ initialized = 1;
+
+ status = rtems_io_register_name(
+ "/dev/null",
+ major,
+ (rtems_device_minor_number) 0
+ );
+
+ if (status != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred(status);
+
+ NULL_major = major;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/* null_open
+ *
+ * This routine is the null device driver open routine.
+ *
+ * Input parameters:
+ * major - device major number
+ * minor - device minor number
+ * pargb - pointer to open parameter block
+ *
+ * Output parameters:
+ * rval - NULL_SUCCESSFUL
+ */
+
+rtems_device_driver null_open(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *pargp __attribute__((unused))
+)
+{
+ return NULL_SUCCESSFUL;
+}
+
+
+/* null_close
+ *
+ * This routine is the null device driver close routine.
+ *
+ * Input parameters:
+ * major - device major number
+ * minor - device minor number
+ * pargb - pointer to close parameter block
+ *
+ * Output parameters:
+ * rval - NULL_SUCCESSFUL
+ */
+
+rtems_device_driver null_close(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *pargp __attribute__((unused))
+)
+{
+ return NULL_SUCCESSFUL;
+}
+
+
+/* null_read
+ *
+ * This routine is the null device driver read routine.
+ *
+ * Input parameters:
+ * major - device major number
+ * minor - device minor number
+ * pargp - pointer to read parameter block
+ *
+ * Output parameters:
+ * rval - NULL_SUCCESSFUL
+ */
+
+rtems_device_driver null_read(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *pargp __attribute__((unused))
+)
+{
+ return NULL_SUCCESSFUL;
+}
+
+
+/* null_write
+ *
+ * This routine is the null device driver write routine.
+ *
+ * Input parameters:
+ * major - device major number
+ * minor - device minor number
+ * pargp - pointer to write parameter block
+ *
+ * Output parameters:
+ * rval - NULL_SUCCESSFUL
+ */
+
+rtems_device_driver null_write(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *pargp
+)
+{
+ rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) pargp;
+
+ if ( rw_args )
+ rw_args->bytes_moved = rw_args->count;
+
+ return NULL_SUCCESSFUL;
+}
+
+
+/* null_control
+ *
+ * This routine is the null device driver control routine.
+ *
+ * Input parameters:
+ * major - device major number
+ * minor - device minor number
+ * pargp - pointer to cntrl parameter block
+ *
+ * Output parameters:
+ * rval - NULL_SUCCESSFUL
+ */
+
+rtems_device_driver null_control(
+ rtems_device_major_number major __attribute__((unused)),
+ rtems_device_minor_number minor __attribute__((unused)),
+ void *pargp __attribute__((unused))
+)
+{
+ return NULL_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/devnull/devnull.h b/cpukit/libmisc/devnull/devnull.h
new file mode 100644
index 0000000000..4fe90cde6c
--- /dev/null
+++ b/cpukit/libmisc/devnull/devnull.h
@@ -0,0 +1,73 @@
+/* devnull.h
+ *
+ * Null device driver, derived from rtems' stub driver.
+ *
+ * Author: Ralf Corsepius (corsepiu@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1989-2000.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_DEVNULL_H
+#define _RTEMS_DEVNULL_H
+
+#include <rtems/io.h> /* rtems_device_driver */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DEVNULL_DRIVER_TABLE_ENTRY \
+ { null_initialize, null_open, null_close, null_read, \
+ null_write, null_control }
+
+#define NULL_SUCCESSFUL RTEMS_SUCCESSFUL
+
+rtems_device_driver null_initialize(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+rtems_device_driver null_open(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+rtems_device_driver null_close(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+rtems_device_driver null_read(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+rtems_device_driver null_write(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+rtems_device_driver null_control(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libmisc/dummy/README b/cpukit/libmisc/dummy/README
new file mode 100644
index 0000000000..03bb30834d
--- /dev/null
+++ b/cpukit/libmisc/dummy/README
@@ -0,0 +1,23 @@
+dummy.rel
+=========
+
+A relocatible objects which contains a dummy configuration for RTEMS.
+
+Helps linking standard c-program code with RTEMS, which shall *not* be run
+on a target, such as configure script code fragments generated by autoconf's
+AC_TRY_LINK.
+
+Example:
+
+tar xzvf somepkg.tar.gz
+cd somepkg
+
+LDFLAGS=/usr/local/rtems/<cpu>-rtems/<bsp>/lib/dummy.rel \
+CC="<cpu>-rtems-gcc \
+-B/usr/local/rtems/<cpu>-rtems/<bsp>/lib/ -specs bsp_specs -qrtems" \
+CC_FOR_BUILD="gcc" \
+configure --host=<cpu>-rtems --build=i686-pc-linux-gnu
+make
+
+History:
+Starting dummy.c with a copy of rtems-19990528/c/src/tests/samples/minimum/init.c
diff --git a/cpukit/libmisc/dummy/dummy-networking.c b/cpukit/libmisc/dummy/dummy-networking.c
new file mode 100644
index 0000000000..77d708d516
--- /dev/null
+++ b/cpukit/libmisc/dummy/dummy-networking.c
@@ -0,0 +1,44 @@
+/*
+ * Dummy configuration file
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+/* Loopback Network Configuration */
+#if defined(RTEMS_NETWORKING)
+ #include <rtems/rtems_bsdnet.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+
+ struct rtems_bsdnet_config rtems_bsdnet_config = {
+ NULL, /* Network interface */
+ NULL, /* Use fixed network configuration */
+ 0, /* Default network task priority */
+ 0, /* Default mbuf capacity */
+ 0, /* Default mbuf cluster capacity */
+ "testSystem", /* Host name */
+ "nowhere.com", /* Domain name */
+ "127.0.0.1", /* Gateway */
+ "127.0.0.1", /* Log host */
+ {"127.0.0.1" }, /* Name server(s) */
+ {"127.0.0.1" }, /* NTP server(s) */
+ 1, /* sb_efficiency */
+ 0, /* udp_tx_buf_size */
+ 0, /* udp_rx_buf_size */
+ 0, /* tcp_tx_buf_size */
+ 0 /* tcp_rx_buf_size */
+ };
+#endif
diff --git a/cpukit/libmisc/dummy/dummy.c b/cpukit/libmisc/dummy/dummy.c
new file mode 100644
index 0000000000..b062c06091
--- /dev/null
+++ b/cpukit/libmisc/dummy/dummy.c
@@ -0,0 +1,38 @@
+/*
+ * Dummy configuration file
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+int main( int, char **, char **);
+
+/* configuration information */
+
+/* This is enough to get a basic main() up. */
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 10
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
+#define CONFIGURE_INIT_TASK_ENTRY_POINT (void *)main
+
+/* Include basic device drivers needed to call delays */
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+
diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.c b/cpukit/libmisc/dumpbuf/dumpbuf.c
new file mode 100644
index 0000000000..97274ecbaa
--- /dev/null
+++ b/cpukit/libmisc/dumpbuf/dumpbuf.c
@@ -0,0 +1,80 @@
+/*
+ * COPYRIGHT (c) 1997-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <rtems/dumpbuf.h>
+#include <rtems/bspIo.h>
+
+/*
+ * Put the body below rtems_print_buffer so it won't get inlined.
+ */
+
+static inline void Dump_Line(
+ const unsigned char *buffer,
+ int length
+);
+
+void rtems_print_buffer(
+ const unsigned char *buffer,
+ int length
+)
+{
+
+ int i, mod, max;
+
+ if ( !length ) return;
+
+ mod = length % 16;
+
+ max = length - mod;
+
+ for ( i=0 ; i<max ; i+=16 )
+ Dump_Line( &buffer[ i ], 16 );
+
+ if ( mod )
+ Dump_Line( &buffer[ max ], mod );
+}
+
+static inline void Dump_Line(
+ const unsigned char *buffer,
+ int length
+)
+{
+
+ int i;
+ char line_buffer[120];
+
+ line_buffer[0] = '\0';
+
+ for( i=0 ; i<length ; i++ )
+ sprintf( line_buffer, "%s%02x ", line_buffer, buffer[ i ] );
+
+ for( ; i<16 ; i++ )
+ strcat( line_buffer, " " );
+
+ strcat( line_buffer, "|" );
+ for( i=0 ; i<length ; i++ )
+ sprintf( line_buffer, "%s%c", line_buffer,
+ isprint( buffer[ i ] ) ? buffer[ i ] : '.' );
+
+ for( ; i<16 ; i++ )
+ strcat( line_buffer, " " );
+
+ strcat( line_buffer, "|\n" );
+
+ printk( line_buffer );
+}
diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.h b/cpukit/libmisc/dumpbuf/dumpbuf.h
new file mode 100644
index 0000000000..3502ace70a
--- /dev/null
+++ b/cpukit/libmisc/dumpbuf/dumpbuf.h
@@ -0,0 +1,39 @@
+/*
+ * COPYRIGHT (c) 1997-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __DUMP_BUFFER_h
+#define __DUMP_BUFFER_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Print Memory Buffer
+ *
+ * This method prints @a length bytes beginning at @a buffer in
+ * a nice format similar to what one would expect from a debugger
+ * or ROM monitor.
+ *
+ * @param[in] buffer is the address of the buffer
+ * @param[in] length is the length of the buffer
+ */
+void rtems_print_buffer(
+ const unsigned char *buffer,
+ int length
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libmisc/fb/fb.h b/cpukit/libmisc/fb/fb.h
new file mode 100644
index 0000000000..cf49d7bd91
--- /dev/null
+++ b/cpukit/libmisc/fb/fb.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2000 - Rosimildo da Silva
+ *
+ * MODULE DESCRIPTION:
+ * Micro FrameBuffer interface for Embedded Systems.
+ *
+ * $Id$
+ */
+
+#ifndef _MW_FB_H
+#define _MW_FB_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ioctls
+ 0x46 is 'F' */
+#define FBIOGET_VSCREENINFO 0x4600
+#define FBIOPUT_VSCREENINFO 0x4601
+#define FBIOGET_FSCREENINFO 0x4602
+#define FBIOGETCMAP 0x4604
+#define FBIOPUTCMAP 0x4605
+#define FB_EXEC_FUNCTION 0x4606
+#define FBIOSWAPBUFFERS 0x4607
+#define FBIOSETBUFFERMODE 0x4608
+
+#define FB_SINGLE_BUFFERED 0
+#define FB_TRIPLE_BUFFERED 1
+
+#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
+#define FB_TYPE_PLANES 1 /* Non interleaved planes */
+#define FB_TYPE_INTERLEAVED_PLANES 2 /* Interleaved planes */
+#define FB_TYPE_TEXT 3 /* Text/attributes */
+#define FB_TYPE_VGA_PLANES 4 /* EGA/VGA planes */
+#define FB_TYPE_VIRTUAL_BUFFER 5 /* Virtual Buffer */
+
+
+#define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White */
+#define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black */
+#define FB_VISUAL_TRUECOLOR 2 /* True color */
+#define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) */
+#define FB_VISUAL_DIRECTCOLOR 4 /* Direct color */
+#define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly */
+
+#define FB_ACCEL_NONE 0 /* no hardware accelerator */
+
+struct fb_bitfield {
+ uint32_t offset; /* beginning of bitfield */
+ uint32_t length; /* length of bitfield */
+ uint32_t msb_right; /* != 0 : Most significant bit is */
+ /* right */
+};
+
+struct fb_var_screeninfo {
+ uint32_t xres; /* visible resolution */
+ uint32_t yres;
+ uint32_t bits_per_pixel; /* guess what */
+ struct fb_bitfield red; /* bitfield in fb mem if true color, */
+ struct fb_bitfield green; /* else only length is significant */
+ struct fb_bitfield blue;
+ struct fb_bitfield transp; /* transparency */
+};
+
+struct fb_fix_screeninfo {
+ volatile char *smem_start; /* Start of frame buffer mem */
+ /* (physical address) */
+ uint32_t smem_len; /* Length of frame buffer mem */
+ uint32_t type; /* see FB_TYPE_* */
+ uint32_t visual; /* see FB_VISUAL_* */
+ uint32_t line_length; /* number of chars per line */
+};
+
+struct fb_cmap {
+ uint32_t start; /* First entry */
+ uint32_t len; /* Number of entries */
+ uint16_t *red; /* Red values */
+ uint16_t *green;
+ uint16_t *blue;
+ uint16_t *transp; /* transparency, can be NULL */
+};
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MW_FB_H */
diff --git a/cpukit/libmisc/fb/mw_print.c b/cpukit/libmisc/fb/mw_print.c
new file mode 100644
index 0000000000..4e8abf2bd8
--- /dev/null
+++ b/cpukit/libmisc/fb/mw_print.c
@@ -0,0 +1,92 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/mw_uid.h>
+#include <stdio.h>
+
+const char *uid_buttons(
+ unsigned short btns,
+ char *buffer,
+ size_t max
+)
+{
+ snprintf(
+ buffer,
+ max,
+ "LEFT=%s CENTER=%s RIGHT=%s",
+ ((btns & MV_BUTTON_LEFT) ? "down" : "up"),
+ ((btns & MV_BUTTON_CENTER) ? "down" : "up"),
+ ((btns & MV_BUTTON_RIGHT) ? "down" : "up")
+ );
+ return buffer;
+}
+
+void uid_print_message(
+ struct MW_UID_MESSAGE *uid
+)
+{
+ uid_print_message_with_plugin( NULL, printk_plugin, uid );
+}
+
+void uid_print_message_with_plugin(
+ void *context,
+ rtems_printk_plugin_t handler,
+ struct MW_UID_MESSAGE *uid
+)
+{
+ char buttons[80];
+
+ switch (uid->type) {
+ case MV_UID_INVALID:
+ (*handler)( context, "MV_UID_INVALID\n" );
+ break;
+ case MV_UID_REL_POS:
+ (*handler)(
+ context,
+ "MV_UID_REL_POS - %s x=%d y=%d z=%d\n",
+ uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)),
+ uid->m.pos.x, /* x location */
+ uid->m.pos.y, /* y location */
+ uid->m.pos.z /* z location, 0 for 2D */
+ );
+ break;
+ case MV_UID_ABS_POS:
+ (*handler)(
+ context,
+ "MV_UID_ABS_POS - %s x=%d y=%d z=%d\n",
+ uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)),
+ uid->m.pos.x, /* x location */
+ uid->m.pos.y, /* y location */
+ uid->m.pos.z /* z location, 0 for 2D */
+ );
+ break;
+ case MV_UID_KBD:
+ (*handler)( context,
+ "MV_UID_KBD - code=0x%04x modifiers=0x%02x mode=0x%02x\n",
+ uid->m.kbd.code, /* keycode or scancode */
+ uid->m.kbd.modifiers, /* key modifiers */
+ uid->m.kbd.mode /* current Kbd mode */
+ );
+ break;
+ case MV_UID_TIMER:
+ (*handler)( context, "MV_UID_TIMER\n" );
+ break;
+ default:
+ (*handler)( context, "Invalid device type\n" );
+ break;
+ }
+
+}
+
diff --git a/cpukit/libmisc/fb/mw_uid.c b/cpukit/libmisc/fb/mw_uid.c
new file mode 100644
index 0000000000..e3cf34f276
--- /dev/null
+++ b/cpukit/libmisc/fb/mw_uid.c
@@ -0,0 +1,150 @@
+/*
+ *
+ * Copyright (c) 2000 - Rosimildo da Silva
+ *
+ * MODULE DESCRIPTION:
+ * This module implements the input devices interface used by MicroWindows
+ * in an embedded system environment. It uses the RTEMS message queue as
+ * the repository for the messages posted by the devices registered.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <rtems.h>
+
+#include <rtems/mw_uid.h>
+#include <rtems/seterr.h>
+
+static rtems_id queue_id = 0;
+static int open_count = 0;
+
+/*
+#define MW_DEBUG_ON 1
+*/
+
+/* open a message queue with the kernel */
+int uid_open_queue(
+ const char *q_name,
+ int flags __attribute__((unused)),
+ size_t max_msgs
+)
+{
+ rtems_status_code status;
+
+ /*
+ * For the first device calling this function we would create the queue.
+ * It is assumed that this call is done at initialization, and no concerns
+ * regarding multi-threading is taken in consideration here.
+ */
+ if ( open_count ) {
+ open_count++;
+ return 0;
+ }
+
+ status = rtems_message_queue_create(
+ rtems_build_name( q_name[0], q_name[1], q_name[2], q_name[3] ),
+ max_msgs,
+ sizeof( struct MW_UID_MESSAGE ),
+ RTEMS_FIFO | RTEMS_LOCAL,
+ &queue_id
+ );
+ if ( status != RTEMS_SUCCESSFUL ) {
+ #ifdef MW_DEBUG_ON
+ printk( "UID_Queue: error creating queue: %d\n", status );
+ #endif
+ return -1;
+ }
+ #ifdef MW_DEBUG_ON
+ printk( "UID_Queue: id=%X\n", queue_id );
+ #endif
+ open_count++;
+ return 0;
+}
+
+
+/* close message queue */
+int uid_close_queue( void )
+{
+ if ( open_count == 1 ) {
+ rtems_message_queue_delete( queue_id );
+ queue_id = 0;
+ }
+ open_count--;
+ return 0;
+}
+
+/* reads for a message from the device */
+int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout )
+{
+ rtems_status_code status;
+ size_t size = 0;
+ unsigned long micro_secs = timeout*1000;
+ int wait = (timeout != 0);
+
+ status = rtems_message_queue_receive(
+ queue_id,
+ (void*)m,
+ &size,
+ wait ? RTEMS_WAIT : RTEMS_NO_WAIT,
+ RTEMS_MICROSECONDS_TO_TICKS(micro_secs)
+ );
+
+ if( status == RTEMS_SUCCESSFUL ) {
+ return size;
+ } else if( ( status == RTEMS_UNSATISFIED ) || ( status == RTEMS_TIMEOUT ) ) {
+ rtems_set_errno_and_return_minus_one( ETIMEDOUT );
+ }
+ /* Here we have one error condition */
+ #ifdef MW_DEBUG_ON
+ printk( "UID_Queue: error reading queue: %d\n", status );
+ #endif
+ return -1;
+}
+
+/*
+ * add a message to the queue of events. This method can be used to
+ * simulate hardware events, and it can be very handy during development
+ * a new interface.
+ */
+int uid_send_message( struct MW_UID_MESSAGE *m )
+{
+ rtems_status_code status;
+ status = rtems_message_queue_send(
+ queue_id, ( void * )m, sizeof( struct MW_UID_MESSAGE ) );
+ return (status == RTEMS_SUCCESSFUL) ? 0 : -1;
+}
+
+/*
+ * register the device to insert events to the message
+ * queue named as the value passed in q_name
+ */
+int uid_register_device( int fd, const char *q_name )
+{
+ return ioctl( fd, MW_UID_REGISTER_DEVICE, q_name );
+}
+
+/* tell this device to stop adding events to the queue */
+int uid_unregister_device( int fd )
+{
+ return ioctl( fd, MW_UID_UNREGISTER_DEVICE, NULL );
+}
+
+/* set the keyboard */
+int uid_set_kbd_mode( int fd, int mode, int *old_mode )
+{
+ if (ioctl( fd, MV_KDGKBMODE, old_mode) < 0) {
+ return -1;
+ }
+ if (ioctl(fd, MV_KDSKBMODE, mode ) < 0 ) {
+ return -1;
+ }
+ return 0;
+}
diff --git a/cpukit/libmisc/fb/mw_uid.h b/cpukit/libmisc/fb/mw_uid.h
new file mode 100644
index 0000000000..89f440acf4
--- /dev/null
+++ b/cpukit/libmisc/fb/mw_uid.h
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2000 - Rosimildo da Silva
+ *
+ * MODULE DESCRIPTION:
+ * This module defines the interface for input devices used by MicroWindows
+ * in an embedded system environment.
+ *
+ * $Id$
+ */
+
+#ifndef _MW_UID_H
+#define _MW_UID_H
+
+#include <sys/types.h>
+#include <rtems/bspIo.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* 0x41XX -- IOCTL functions for the Micro Input Devices commands */
+#define MW_UID_REGISTER_DEVICE 0x4100
+#define MW_UID_UNREGISTER_DEVICE 0x4101
+
+/* devices supported by MicroWindows */
+enum MW_INPUT_DEVICE_TYPE {
+ MV_UID_INVALID = 0,
+ MV_UID_REL_POS = 1, /* mouse */
+ MV_UID_ABS_POS = 2, /* touch-screen */
+ MV_UID_KBD = 3, /* keyboard */
+ MV_UID_TIMER = 4 /* timer -- not used */
+};
+
+/* matching MicroWindows */
+#define MV_BUTTON_RIGHT 0x01
+#define MV_BUTTON_CENTER 0x02
+#define MV_BUTTON_LEFT 0x04
+
+/* modifiers of the keyboard type devices */
+#define MV_KEY_MODIFIER_SHIFT_DOWN 0x10
+#define MV_KEY_MODIFIER_ALT_DOWN 0x20
+
+/* indication of the LEDS */
+#define MV_KEY_MODIFIER_CAPS_ON 0x04
+#define MV_KEY_MODIFIER_NUN_LOCK_ON 0x02
+#define MV_KEY_SCROLL_LOCK_ON 0x01
+
+/* keyboard modes -- default ASCII */
+#define MV_KEY_MODE_ASCII 0x01
+/*
+ * This mode one event is sent when a key is pressed,
+ * and another one is send when a key is released.
+ */
+#define MV_KEY_MODE_SCANCODE 0x00
+
+/* these defines match with the linux keyboard range
+ * for ioctls functions for the keyboard interface.
+ * 0x4BXX --- keyboard related functions
+ */
+#define MV_KDGKBMODE 0x4B44 /* gets current keyboard mode */
+#define MV_KDSKBMODE 0x4B45 /* sets current keyboard mode */
+
+/*
+ * Message generated by input devices controlled by MicroWindows.
+ */
+struct MW_UID_MESSAGE {
+ enum MW_INPUT_DEVICE_TYPE type; /* device type */
+ union {
+ /* fired when keyboard events are raised */
+ struct kbd_t {
+ unsigned short code; /* keycode or scancode */
+ unsigned char modifiers; /* key modifiers */
+ unsigned char mode; /* current Kbd mode */
+ } kbd;
+
+ /* fired when position events are raised, mouse, touch screen, etc */
+ struct pos_t {
+ unsigned short btns; /* indicates which buttons are pressed */
+ short x; /* x location */
+ short y; /* y location */
+ short z; /* z location, 0 for 2D */
+ } pos;
+
+ /* fired by a timer device periodically */
+ struct timer_t {
+ unsigned long frt; /* free running timer */
+ unsigned long seq; /* sequence number */
+ } tmr;
+ } m;
+};
+
+
+/*
+ * API for creating/closing/accessing the message queue used by the micro
+ * input device interface. All functions in this interface returns a
+ * zero ( 0 ) on success. One exception for that is the "read" routine
+ * that returns the number of bytes read. Negaive numbers indicate errors
+ *
+ * The implementation of the message queue for RTEMS uses a POSIX message
+ * queue interface. It should be very portable among systems with a POSIX
+ * support.
+ */
+
+/**
+ * This method creates the message queue that holds events from the
+ * input devices.
+ *
+ * @param[in] q_name is the name of the message queue
+ * @param[in] flags controls the behaviour of the queue
+ * @param[in] max_msgs specifies the maximum number of pending messages
+ *
+ * @note The message queue is from the Classic API.
+ *
+ * @return This method returns 0 on success and -1 on error.
+ */
+extern int uid_open_queue( const char *q_name, int flags, size_t max_msgs );
+
+/**
+ * This method closes the message queue and deletes it.
+ *
+ * @return This method returns 0 on success and -1 on error.
+ */
+extern int uid_close_queue( void );
+
+/**
+ * This method reads a message from the queue. It waits up to the specified
+ * timeout in miliseconds. A @a timeout of 0 is a poll.
+ *
+ * @param[in] m will be filled in with the received message
+ * @param[in] timeout is the maximum number of mulliseconds to wait
+ *
+ * @return This method returns 0 on success and -1 on error.
+ */
+extern int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout );
+
+/**
+ * This methods writes a message to the queue.
+ *
+ * @param[in] m is the message to send
+ *
+ * @return This method returns 0 on success and -1 on error.
+ */
+extern int uid_send_message( struct MW_UID_MESSAGE *m );
+
+/**
+ * This method registers the device associated with @a fd to
+ * to insert data to the queue
+ */
+extern int uid_register_device( int fd, const char *q_name );
+
+/* unregister device to stop adding messages to the queue */
+extern int uid_unregister_device( int fd );
+
+/* set the keyboard */
+extern int uid_set_kbd_mode( int fd, int mode, int *old_mode );
+
+/**
+ * This methods prints the specified UID message using printk
+ *
+ * @param[in] uid points to the message to print
+ */
+void uid_print_message(
+ struct MW_UID_MESSAGE *uid
+);
+
+/**
+ * This methods prints the specified UID message using your fprintf
+ * style method of choice.
+ *
+ * @param[in] context is a pointer to a data area which may be
+ * used by some print handlers
+ * @param[in] handler is the fprintf style method to invoke
+ * @param[in] uid points to the message to print
+ */
+void uid_print_message_with_plugin(
+ void *context,
+ rtems_printk_plugin_t handler,
+ struct MW_UID_MESSAGE *uid
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MW_UID_H */
diff --git a/cpukit/libmisc/fsmount/README b/cpukit/libmisc/fsmount/README
new file mode 100644
index 0000000000..88bfda62e7
--- /dev/null
+++ b/cpukit/libmisc/fsmount/README
@@ -0,0 +1,24 @@
+#
+#
+# fsmount information
+#
+# Author: Thomas Doerfler 02/07/2003
+#
+# README,v 1.1 1999/07/09 17:23:15 joel Exp
+#
+
+fsmount.c contains the function fsmount. It processes the
+fs table given as an parameter to create the listed mount points
+and mount the corresponding file systems to their mount points.
+See "c/src/tests/samples/fileio" for a sample on how to use this
+function.
+
+The field "report_reasons" specifies, what results of the mount point
+creation/mount operations should print to the console.
+
+The field "abort_reasons" specifies, what results of the mount point
+creation/mount operations should abort the function. Do not set the
+"abort_reasons" bit, unless you want to stop the processing of the
+fsmount table after the first successful mount.
+
+
diff --git a/cpukit/libmisc/fsmount/fsmount.c b/cpukit/libmisc/fsmount/fsmount.c
new file mode 100644
index 0000000000..1d82b94391
--- /dev/null
+++ b/cpukit/libmisc/fsmount/fsmount.c
@@ -0,0 +1,138 @@
+/**
+ * @file
+ *
+ * File system mount functions.
+ */
+
+/*===============================================================*\
+| Project: RTEMS fsmount |
++-----------------------------------------------------------------+
+| File: fsmount.c |
++-----------------------------------------------------------------+
+| Copyright (c) 2003 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file contains the fsmount functions. These functions |
+| are used to mount a list of filesystems (and create their mount |
+| points before) |
+| |
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 02.07.03 creation doe |
+\*===============================================================*/
+
+#ifndef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/fsmount.h>
+#include <rtems/libio.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int rtems_fsmount
+(
+/*-------------------------------------------------------------------------*\
+ | Purpose: |
+ | This function will create the mount points listed and mount the file |
+ | systems listed in the calling parameters |
+ +---------------------------------------------------------------------------+
+ | Input Parameters: |
+ \*-------------------------------------------------------------------------*/
+ const rtems_fstab_entry *fstab_ptr,
+ size_t fstab_count,
+ size_t *fail_idx
+ )
+/*-------------------------------------------------------------------------*\
+ | Return Value: |
+ | 0, if success, -1 and errno if failed |
+ \*=========================================================================*/
+{
+ int rc = 0;
+ int tmp_rc;
+ size_t fstab_idx = 0;
+ bool terminate = false;
+
+ /*
+ * scan through all fstab entries;
+ */
+ while (!terminate &&
+ (fstab_idx < fstab_count)) {
+ tmp_rc = 0;
+ /*
+ * create mount point
+ */
+ if (tmp_rc == 0) {
+ tmp_rc = rtems_mkdir(fstab_ptr->target, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (tmp_rc != 0) {
+ if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNTPNT_CRTERR)) {
+ fprintf(stdout,"fsmount: creation of mount point \"%s\" failed: %s\n",
+ fstab_ptr->target,
+ strerror(errno));
+ }
+ if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNTPNT_CRTERR)) {
+ terminate = true;
+ rc = tmp_rc;
+ }
+ }
+ }
+ /*
+ * mount device to given mount point
+ */
+ if (tmp_rc == 0) {
+ tmp_rc = mount(fstab_ptr->source,
+ fstab_ptr->target,
+ fstab_ptr->type,
+ fstab_ptr->options,
+ NULL);
+ if (tmp_rc != 0) {
+ if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_FAILED)) {
+ fprintf(stdout,"fsmount: mounting of \"%s\" to"
+ " \"%s\" failed: %s\n",
+ fstab_ptr->source,
+ fstab_ptr->target,
+ strerror(errno));
+ }
+ if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_FAILED)) {
+ terminate = true;
+ rc = tmp_rc;
+ }
+ }
+ else {
+ if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_OK)) {
+ fprintf(stdout,"fsmount: mounting of \"%s\" to"
+ " \"%s\" succeeded\n",
+ fstab_ptr->source,
+ fstab_ptr->target);
+ }
+ if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_OK)) {
+ terminate = true;
+ }
+ }
+ }
+ /*
+ * proceed to next entry
+ */
+ if (!terminate) {
+ fstab_ptr++;
+ fstab_idx++;
+ }
+ }
+ if (fail_idx != NULL) {
+ *fail_idx = fstab_idx;
+ }
+ return rc;
+}
diff --git a/cpukit/libmisc/fsmount/fsmount.h b/cpukit/libmisc/fsmount/fsmount.h
new file mode 100644
index 0000000000..94c8508358
--- /dev/null
+++ b/cpukit/libmisc/fsmount/fsmount.h
@@ -0,0 +1,209 @@
+/**
+ * @file
+ *
+ * File system mount functions.
+ */
+
+/*===============================================================*\
+| Project: RTEMS fsmount |
++-----------------------------------------------------------------+
+| File: fsmount.h |
++-----------------------------------------------------------------+
+| Copyright (c) 2003 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file contains the fsmount functions. These functions |
+| are used to mount a list of filesystems (and create their mount |
+| points before) |
+| |
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 02.07.03 creation doe |
+\*===============================================================*/
+
+#ifndef _FSMOUNT_H
+#define _FSMOUNT_H
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libcsupport.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup rtems_fstab File System Mount Support
+ *
+ * @{
+ */
+
+/**
+ * File system mount report and abort condition flags.
+ *
+ * The flags define, which conditions will cause a report during the mount
+ * process (via printf()) or abort the mount process.
+ *
+ * @see rtems_fstab_entry and rtems_fsmount().
+ */
+typedef enum {
+ /**
+ * No conditions.
+ */
+ RTEMS_FSTAB_NONE = 0U,
+
+ /**
+ * Complete mount process was successful.
+ */
+ RTEMS_FSTAB_OK = 0x1U,
+
+ /**
+ * Mount point creation failed.
+ */
+ RTEMS_FSTAB_ERROR_MOUNT_POINT = 0x2U,
+
+ /**
+ * File system mount failed.
+ */
+ RTEMS_FSTAB_ERROR_MOUNT = 0x4U,
+
+ /**
+ * Something failed.
+ */
+ RTEMS_FSTAB_ERROR = RTEMS_FSTAB_ERROR_MOUNT_POINT | RTEMS_FSTAB_ERROR_MOUNT,
+
+ /**
+ * Any condition.
+ */
+ RTEMS_FSTAB_ANY = RTEMS_FSTAB_OK | RTEMS_FSTAB_ERROR
+} rtems_fstab_conditions;
+
+/**
+ * File system table entry.
+ */
+typedef struct {
+ /**
+ * Source for the mount.
+ */
+ const char *source;
+
+ /**
+ * Target for the mount.
+ */
+ const char *target;
+
+ /**
+ * File system operations.
+ */
+ const char *type;
+
+ /**
+ * File system mount options.
+ */
+ rtems_filesystem_options_t options;
+
+ /**
+ * Report @ref rtems_fstab_conditions "condition flags".
+ */
+ uint16_t report_reasons;
+
+ /**
+ * Abort @ref rtems_fstab_conditions "condition flags".
+ */
+ uint16_t abort_reasons;
+} rtems_fstab_entry;
+
+/**
+ * Mounts the file systems listed in the file system mount table @a fstab of
+ * size @a size.
+ *
+ * Each file system will be mounted according to its table entry parameters.
+ * In case of an abort condition the corresponding table index will be reported
+ * in @a abort_index. The pointer @a abort_index may be @c NULL. The mount
+ * point paths will be created with rtems_mkdir() and need not exist
+ * beforehand.
+ *
+ * On success, zero is returned. On error, -1 is returned, and @c errno is set
+ * appropriately.
+ *
+ * @see rtems_bdpart_register_from_disk().
+ *
+ * The following example code tries to mount a FAT file system within a SD
+ * Card. Some cards do not have a partition table so at first it tries to find
+ * a file system inside the hole disk. If this is successful the mount process
+ * will be aborted because the @ref RTEMS_FSTAB_OK condition is true. If this
+ * did not work it tries to mount the file system inside the first partition.
+ * If this fails the mount process will not be aborted (this is already the
+ * last entry), but the last error status will be returned.
+ *
+ * @code
+ * #include <stdio.h>
+ * #include <string.h>
+ * #include <errno.h>
+ *
+ * #include <rtems.h>
+ * #include <rtems/bdpart.h>
+ * #include <rtems/error.h>
+ * #include <rtems/fsmount.h>
+ *
+ * static const rtems_fstab_entry fstab [] = {
+ * {
+ * .source = "/dev/sd-card-a",
+ * .target = "/mnt",
+ * .type = "dosfs",
+ * .options = RTEMS_FILESYSTEM_READ_WRITE,
+ * .report_reasons = RTEMS_FSTAB_ANY,
+ * .abort_reasons = RTEMS_FSTAB_OK
+ * }, {
+ * .source = "/dev/sd-card-a1",
+ * .target = "/mnt",
+ * .type = "dosfs",
+ * .options = RTEMS_FILESYSTEM_READ_WRITE,
+ * .report_reasons = RTEMS_FSTAB_ANY,
+ * .abort_reasons = RTEMS_FSTAB_NONE
+ * }
+ * };
+ *
+ * static void my_mount(void)
+ * {
+ * rtems_status_code sc = RTEMS_SUCCESSFUL;
+ * int rv = 0;
+ * size_t abort_index = 0;
+ *
+ * sc = rtems_bdpart_register_from_disk("/dev/sd-card-a");
+ * if (sc != RTEMS_SUCCESSFUL) {
+ * printf("read partition table failed: %s\n", rtems_status_text(sc));
+ * }
+ *
+ * rv = rtems_fsmount(fstab, sizeof(fstab) / sizeof(fstab [0]), &abort_index);
+ * if (rv != 0) {
+ * printf("mount failed: %s\n", strerror(errno));
+ * }
+ * printf("mount aborted at %zu\n", abort_index);
+ * }
+ * @endcode
+ */
+int rtems_fsmount( const rtems_fstab_entry *fstab, size_t size, size_t *abort_index);
+
+/** @} */
+
+typedef rtems_fstab_entry fstab_t;
+
+#define FSMOUNT_MNT_OK RTEMS_FSTAB_OK
+
+#define FSMOUNT_MNTPNT_CRTERR RTEMS_FSTAB_ERROR_MOUNT_POINT
+
+#define FSMOUNT_MNT_FAILED RTEMS_FSTAB_ERROR_MOUNT
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FSMOUNT_H */
diff --git a/cpukit/libmisc/monitor/README b/cpukit/libmisc/monitor/README
new file mode 100644
index 0000000000..d5a73da140
--- /dev/null
+++ b/cpukit/libmisc/monitor/README
@@ -0,0 +1,97 @@
+#
+# $Id$
+#
+
+monitor task
+
+The monitor task is an optional task that knows about RTEMS
+data structures and can print out information about them.
+It is a work-in-progress and needs many more commands, but
+is useful now.
+
+The monitor works best when it is the highest priority task,
+so all your other tasks should ideally be at some priority
+greater than 1.
+
+To use the monitor:
+-------------------
+
+ #include <rtems/monitor.h>
+
+ ...
+
+ rtems_monitor_init(0);
+
+ The parameter to rtems_monitor_init() tells the monitor whether
+ to suspend itself on startup. A value of 0 causes the monitor
+ to immediately enter command mode; a non-zero value causes the
+ monitor to suspend itself after creation and wait for explicit
+ wakeup.
+
+
+ rtems_monitor_wakeup();
+
+ wakes up a suspended monitor and causes it to reenter command mode.
+
+Monitor commands
+----------------
+
+ The monitor prompt is 'rtems> '.
+ Can abbreviate commands to "uniquity"
+ There is a 'help' command. Here is the output from various
+ help commands:
+
+ Commands (may be abbreviated)
+
+ help -- get this message or command specific help
+ task -- show task information
+ queue -- show message queue information
+ symbol -- show entries from symbol table
+ pause -- pause monitor for a specified number of ticks
+ fatal -- invoke a fatal RTEMS error
+
+ task [id [id ...] ]
+ display information about the specified tasks.
+ Default is to display information about all tasks on this node
+
+ queue [id [id ... ] ]
+ display information about the specified message queues
+ Default is to display information about all queues on this node
+
+ symbol [ symbolname [symbolname ... ] ]
+ display value associated with specified symbol.
+ Defaults to displaying all known symbols.
+
+ pause [ticks]
+ monitor goes to "sleep" for specified ticks (default is 1)
+ monitor will resume at end of period or if explicitly awakened
+
+ fatal [status]
+ Invoke 'rtems_fatal_error_occurred' with 'status'
+ (default is RTEMS_INTERNAL_ERROR)
+
+ continue
+ put the monitor to sleep waiting for an explicit wakeup from the
+ program running.
+
+
+Sample output from 'task' command
+---------------------------------
+
+ rtems> task
+ ID NAME PRIO STAT MODES EVENTS WAITID WAITARG NOTES
+ ------------------------------------------------------------------------
+ 00010001 UI1 2 READY P:T:nA NONE15: 0x40606348
+ 00010002 RMON 1 READY nP NONE15: 0x40604110
+
+ 'RMON' is the monitor itself, so we have 1 "user" task.
+ Its modes are P:T:nA which translate to:
+
+ preemptable
+ timesliced
+ no ASRS
+
+ It has no events.
+ It has a notepad value for notepad 15 which is 0x40606348
+ (this is the libc thread state)
+
diff --git a/cpukit/libmisc/monitor/mon-command.c b/cpukit/libmisc/monitor/mon-command.c
new file mode 100644
index 0000000000..b16c8f06c0
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-command.c
@@ -0,0 +1,244 @@
+/**
+ * @file
+ *
+ * @brief Command support routines for RTEMS monitor.
+ */
+
+/*
+ * $Id$
+ *
+ * 2001-01-30 KJO (vac4050@cae597.rsc.raytheon.com):
+ * Fixed rtems_monitor_command_lookup() to accept partial
+ * commands to uniqeness. Added support for setting
+ * the monitor prompt via an environment variable:
+ * RTEMS_MONITOR_PROMPT
+ *
+ * CCJ: 26-3-2000, adding command history and command line
+ * editing. This code is donated from My Right Boot and not
+ * covered by GPL, only the RTEMS license.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+static void
+rtems_monitor_show_help (
+ const rtems_monitor_command_entry_t *help_cmd,
+ int max_cmd_len
+)
+{
+#define MAX_HELP_LINE_LENGTH (75 - max_cmd_len - 2)
+
+ if (help_cmd && help_cmd->command)
+ {
+ const char *help = help_cmd->usage;
+ int help_len = strlen (help);
+ int spaces = max_cmd_len - strlen (help_cmd->command);
+ int show_this_line = 0;
+ int line_one = 1;
+ int c;
+
+ fprintf(stdout,"%s", help_cmd->command);
+
+ if (help_len == 0)
+ {
+ fprintf(stdout," - No help associated.\n");
+ return;
+ }
+
+ while (help_len)
+ {
+ fprintf(stdout,"%*c", spaces, ' ');
+
+ if (line_one)
+ fprintf(stdout," - ");
+
+ spaces = max_cmd_len + 2;
+ line_one = 0;
+
+ /*
+ * See if greater then the line length if so, work back
+ * from the end for a space, tab or lf or cr.
+ */
+
+ if (help_len > MAX_HELP_LINE_LENGTH)
+ {
+ for (show_this_line = MAX_HELP_LINE_LENGTH - 1;
+ show_this_line;
+ show_this_line--)
+ if ((help[show_this_line] == ' ') ||
+ (help[show_this_line] == '\n') ||
+ (help[show_this_line] == '\r'))
+ break;
+
+ /*
+ * If show_this_line is 0, it is a very long word !!
+ */
+
+ if (show_this_line == 0)
+ show_this_line = MAX_HELP_LINE_LENGTH - 1;
+ }
+ else
+ show_this_line = help_len;
+
+ for (c = 0; c < show_this_line; c++)
+ if ((help[c] == '\r') || (help[c] == '\n'))
+ show_this_line = c;
+ else
+ putchar (help[c]);
+
+ fprintf(stdout,"\n");
+
+ help += show_this_line;
+ help_len -= show_this_line;
+
+ /*
+ * Move past the line feeds or what ever else is being skipped.
+ */
+
+ while (help_len)
+ {
+ if ((*help != '\r') && (*help != '\n'))
+ break;
+
+ if (*help != ' ')
+ {
+ help++;
+ help_len--;
+ break;
+ }
+ help++;
+ help_len--;
+ }
+ }
+ }
+}
+
+void
+rtems_monitor_command_usage(
+ const rtems_monitor_command_entry_t *table,
+ const char *command_name
+)
+{
+ const rtems_monitor_command_entry_t *command = table;
+ int max_cmd_len = 0;
+
+ /* if first entry in table is a usage, then print it out */
+
+ if (command_name && (*command_name != '\0'))
+ {
+ command = rtems_monitor_command_lookup (command_name);
+
+ if (command)
+ rtems_monitor_show_help (command, strlen (command_name));
+ else
+ fprintf(stdout,"Unrecognised command; try just 'help'\n");
+ return;
+ }
+
+ /*
+ * Find the largest command size.
+ */
+
+ while (command)
+ {
+ int len = command->command ? strlen (command->command) : 0 ;
+
+ if (len > max_cmd_len)
+ max_cmd_len = len;
+
+ command = command->next;
+ }
+
+ max_cmd_len++;
+
+ command = table;
+
+ /*
+ * Now some nice formatting for the help.
+ */
+
+ while (command)
+ {
+ rtems_monitor_show_help (command, max_cmd_len);
+ command = command->next;
+ }
+}
+
+
+void rtems_monitor_help_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose __attribute__((unused))
+)
+{
+ int arg;
+ const rtems_monitor_command_entry_t *command =
+ command_arg->monitor_command_entry;
+
+ if (argc == 1)
+ rtems_monitor_command_usage(command, 0);
+ else
+ {
+ for (arg = 1; argv[arg]; arg++)
+ rtems_monitor_command_usage(command, argv[arg]);
+ }
+}
+
+typedef struct {
+ const char *name;
+ size_t length;
+ const rtems_monitor_command_entry_t *match;
+} rtems_monitor_command_lookup_entry;
+
+static bool rtems_monitor_command_lookup_routine(
+ const rtems_monitor_command_entry_t *e,
+ void *arg
+)
+{
+ rtems_monitor_command_lookup_entry *le =
+ (rtems_monitor_command_lookup_entry *) arg;
+
+ /* Check name */
+ if (strncmp(e->command, le->name, le->length) == 0) {
+ /* Check for ambiguity */
+ if (le->match == NULL) {
+ le->match = e;
+ } else {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/**
+ * @brief Looks for a command with the name @a name in the list of registered
+ * commands.
+ *
+ * The parameter @a name must not be NULL.
+ *
+ * Returns the corresponding command entry or NULL if no command is found.
+ */
+const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
+ const char *name
+)
+{
+ rtems_monitor_command_lookup_entry e = {
+ .name = name,
+ .length = strlen( name),
+ .match = NULL
+ };
+
+ rtems_monitor_command_iterate(rtems_monitor_command_lookup_routine, &e);
+
+ return e.match;
+}
diff --git a/cpukit/libmisc/monitor/mon-config.c b/cpukit/libmisc/monitor/mon-config.c
new file mode 100644
index 0000000000..b067db7e2f
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-config.c
@@ -0,0 +1,136 @@
+/*
+ * RTEMS Config display support
+ *
+ * TODO
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h> /* strtoul() */
+
+#define DATACOL 15
+#define CONTCOL DATACOL /* continued col */
+
+/*
+ * Fill in entire monitor config table
+ * for sending to a remote monitor or printing on the local system
+ */
+
+void
+rtems_monitor_config_canonical(
+ rtems_monitor_config_t *canonical_config,
+ void *config_void
+)
+{
+ rtems_configuration_table *c = (rtems_configuration_table *) config_void;
+ rtems_api_configuration_table *r = &Configuration_RTEMS_API;
+
+ canonical_config->work_space_start = c->work_space_start;
+ canonical_config->work_space_size = c->work_space_size;
+ canonical_config->maximum_tasks = r->maximum_tasks;
+ canonical_config->maximum_timers = r->maximum_timers;
+ canonical_config->maximum_semaphores = r->maximum_semaphores;
+ canonical_config->maximum_message_queues = r->maximum_message_queues;
+ canonical_config->maximum_partitions = r->maximum_partitions;
+ canonical_config->maximum_regions = r->maximum_regions;
+ canonical_config->maximum_ports = r->maximum_ports;
+ canonical_config->maximum_periods = r->maximum_periods;
+ canonical_config->maximum_extensions = c->maximum_extensions;
+ canonical_config->microseconds_per_tick = c->microseconds_per_tick;
+ canonical_config->ticks_per_timeslice = c->ticks_per_timeslice;
+ canonical_config->number_of_initialization_tasks = r->number_of_initialization_tasks;
+}
+
+/*
+ * This is easy, since there is only 1 (altho we could get them from
+ * other nodes...)
+ */
+
+void *
+rtems_monitor_config_next(
+ void *object_info __attribute__((unused)),
+ rtems_monitor_config_t *canonical_config __attribute__((unused)),
+ rtems_id *next_id
+)
+{
+ rtems_configuration_table *c = &Configuration;
+ int n = rtems_object_id_get_index(*next_id);
+
+ if (n >= 1)
+ goto failed;
+
+ _Thread_Disable_dispatch();
+
+ *next_id += 1;
+ return (void *) c;
+
+failed:
+ *next_id = RTEMS_OBJECT_ID_FINAL;
+ return 0;
+}
+
+
+void
+rtems_monitor_config_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ fprintf(stdout,"\
+INITIAL (startup) Configuration Info\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+ rtems_monitor_separator();
+}
+
+
+int
+rtems_monitor_config_dump(
+ rtems_monitor_config_t *monitor_config,
+ bool verbose __attribute__((unused))
+)
+{
+ int length = 0;
+
+ length = 0;
+ length += fprintf(stdout,"WORKSPACE");
+ length += rtems_monitor_pad(DATACOL, length);
+ length += fprintf(stdout,"start: %p; size: 0x%" PRIx32 "\n",
+ monitor_config->work_space_start,
+ monitor_config->work_space_size);
+
+ length = 0;
+ length += fprintf(stdout,"TIME");
+ length += rtems_monitor_pad(DATACOL, length);
+ length += fprintf(stdout,"usec/tick: %" PRId32 "; tick/timeslice: %" PRId32 "; tick/sec: %" PRId32 "\n",
+ monitor_config->microseconds_per_tick,
+ monitor_config->ticks_per_timeslice,
+ 1000000 / monitor_config->microseconds_per_tick);
+
+ length = 0;
+ length += fprintf(stdout,"MAXIMUMS");
+ length += rtems_monitor_pad(DATACOL, length);
+ length += fprintf(stdout,"tasks: %" PRId32 "; timers: %" PRId32 "; sems: %" PRId32 "; que's: %" PRId32 "; ext's: %" PRId32 "\n",
+ monitor_config->maximum_tasks,
+ monitor_config->maximum_timers,
+ monitor_config->maximum_semaphores,
+ monitor_config->maximum_message_queues,
+ monitor_config->maximum_extensions);
+ length = 0;
+ length += rtems_monitor_pad(CONTCOL, length);
+ length += fprintf(stdout,"partitions: %" PRId32 "; regions: %" PRId32 "; ports: %" PRId32 "; periods: %" PRId32 "\n",
+ monitor_config->maximum_partitions,
+ monitor_config->maximum_regions,
+ monitor_config->maximum_ports,
+ monitor_config->maximum_periods);
+ return length;
+}
diff --git a/cpukit/libmisc/monitor/mon-driver.c b/cpukit/libmisc/monitor/mon-driver.c
new file mode 100644
index 0000000000..c5c2c468b9
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-driver.c
@@ -0,0 +1,144 @@
+/*
+ * RTEMS monitor IO (device drivers) support
+ *
+ * There are 2 "driver" things the monitor knows about.
+ *
+ * 1. Regular RTEMS drivers.
+ * This is a table indexed by major device number and
+ * containing driver entry points only.
+ *
+ * 2. Driver name table.
+ * A separate table of names for drivers.
+ * The table converts driver names to a major number
+ * as index into the driver table and a minor number
+ * for an argument to driver.
+ *
+ * Drivers are displayed with 'driver' command.
+ * Names are displayed with 'name' command.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+#include <stdlib.h> /* strtoul() */
+#include <inttypes.h>
+
+#define DATACOL 15
+#define CONTCOL DATACOL /* continued col */
+
+
+void
+rtems_monitor_driver_canonical(
+ rtems_monitor_driver_t *canonical_driver,
+ void *driver_void
+)
+{
+ rtems_driver_address_table *d = (rtems_driver_address_table *) driver_void;
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_driver->initialization,
+ (void *) d->initialization_entry);
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_driver->open,
+ (void *) d->open_entry);
+ rtems_monitor_symbol_canonical_by_value(&canonical_driver->close,
+ (void *) d->close_entry);
+ rtems_monitor_symbol_canonical_by_value(&canonical_driver->read,
+ (void *) d->read_entry);
+ rtems_monitor_symbol_canonical_by_value(&canonical_driver->write,
+ (void *) d->write_entry);
+ rtems_monitor_symbol_canonical_by_value(&canonical_driver->control,
+ (void *) d->control_entry);
+}
+
+
+void *
+rtems_monitor_driver_next(
+ void *object_info __attribute__((unused)),
+ rtems_monitor_driver_t *canonical_driver,
+ rtems_id *next_id
+)
+{
+ rtems_configuration_table *c = &Configuration;
+ uint32_t n = rtems_object_id_get_index(*next_id);
+
+ if (n >= c->number_of_device_drivers)
+ goto failed;
+
+ _Thread_Disable_dispatch();
+
+ /*
+ * dummy up a fake id and name for this item
+ */
+
+ canonical_driver->id = n;
+ canonical_driver->name = rtems_build_name('-', '-', '-', '-');
+
+ *next_id += 1;
+ return (void *) (c->Device_driver_table + n);
+
+failed:
+ *next_id = RTEMS_OBJECT_ID_FINAL;
+ return 0;
+}
+
+
+void
+rtems_monitor_driver_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ fprintf(stdout,"\
+ Major Entry points\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+ rtems_monitor_separator();
+}
+
+void
+rtems_monitor_driver_dump(
+ rtems_monitor_driver_t *monitor_driver,
+ bool verbose
+)
+{
+ uint32_t length = 0;
+
+#if defined(RTEMS_USE_16_BIT_OBJECT)
+ length += fprintf(stdout," %" PRId16 "", monitor_driver->id);
+#else
+ length += fprintf(stdout," %" PRId32 "", monitor_driver->id);
+#endif
+ length += rtems_monitor_pad(13, length);
+ length += fprintf(stdout,"init: ");
+ length += rtems_monitor_symbol_dump(&monitor_driver->initialization, verbose);
+ length += fprintf(stdout,"; control: ");
+ length += rtems_monitor_symbol_dump(&monitor_driver->control, verbose);
+ length += fprintf(stdout,"\n");
+ length = 0;
+
+ length += rtems_monitor_pad(13, length);
+
+ length += fprintf(stdout,"open: ");
+ length += rtems_monitor_symbol_dump(&monitor_driver->open, verbose);
+ length += fprintf(stdout,"; close: ");
+ length += rtems_monitor_symbol_dump(&monitor_driver->close, verbose);
+ length += fprintf(stdout,"\n");
+ length = 0;
+
+ length += rtems_monitor_pad(13, length);
+
+ length += fprintf(stdout,"read: ");
+ length += rtems_monitor_symbol_dump(&monitor_driver->read, verbose);
+ length += fprintf(stdout,"; write: ");
+ length += rtems_monitor_symbol_dump(&monitor_driver->write, verbose);
+ length += fprintf(stdout,"\n");
+ length = 0;
+}
diff --git a/cpukit/libmisc/monitor/mon-editor.c b/cpukit/libmisc/monitor/mon-editor.c
new file mode 100644
index 0000000000..1104b50185
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-editor.c
@@ -0,0 +1,643 @@
+/**
+ * @file
+ *
+ * @brief Command line editor for RTEMS monitor.
+ */
+
+/*
+ * $Id$
+ *
+ * 2001-01-30 KJO (vac4050@cae597.rsc.raytheon.com):
+ * Fixed rtems_monitor_command_lookup() to accept partial
+ * commands to uniqeness. Added support for setting
+ * the monitor prompt via an environment variable:
+ * RTEMS_MONITOR_PROMPT
+ *
+ * CCJ: 26-3-2000, adding command history and command line
+ * editing. This code is donated from My Right Boot and not
+ * covered by GPL, only the RTEMS license.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <termios.h>
+#include <unistd.h>
+
+#ifndef MONITOR_PROMPT
+#define MONITOR_PROMPT "rtems" /* will have '> ' appended */
+#endif
+
+/*
+ * Some key labels to define special keys.
+ */
+
+#define KEYS_EXTENDED (0x8000)
+#define KEYS_NORMAL_MASK (0x00ff)
+#define KEYS_INS (0)
+#define KEYS_DEL (1)
+#define KEYS_UARROW (2)
+#define KEYS_DARROW (3)
+#define KEYS_LARROW (4)
+#define KEYS_RARROW (5)
+#define KEYS_HOME (6)
+#define KEYS_END (7)
+#define KEYS_F1 (8)
+#define KEYS_F2 (9)
+#define KEYS_F3 (10)
+#define KEYS_F4 (11)
+#define KEYS_F5 (12)
+#define KEYS_F6 (13)
+#define KEYS_F7 (14)
+#define KEYS_F8 (15)
+#define KEYS_F9 (16)
+#define KEYS_F10 (17)
+
+#define RTEMS_COMMAND_BUFFER_SIZE (75)
+
+static char monitor_prompt[32];
+static char buffer[RTEMS_COMMAND_BUFFER_SIZE];
+static int pos;
+static int logged_in;
+
+/*
+ * History data.
+ */
+
+#define RTEMS_COMMAND_HISTORIES (20)
+
+static char history_buffer[RTEMS_COMMAND_HISTORIES][RTEMS_COMMAND_BUFFER_SIZE];
+static int history_pos[RTEMS_COMMAND_HISTORIES];
+static int history;
+static int history_next;
+
+/*
+ * Translation tables. Not sure if this is the best way to
+ * handle this, how-ever I wish to avoid the overhead of
+ * including a more complete and standard environment such
+ * as ncurses.
+ */
+
+struct translation_table
+{
+ char expecting;
+ const struct translation_table *branch;
+ unsigned int key;
+};
+
+static const struct translation_table trans_two[] =
+{
+ { '~', 0, KEYS_INS },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_three[] =
+{
+ { '~', 0, KEYS_DEL },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab_csi[] =
+{
+ { '2', trans_two, 0 },
+ { '3', trans_three, 0 },
+ { 'A', 0, KEYS_UARROW },
+ { 'B', 0, KEYS_DARROW },
+ { 'D', 0, KEYS_LARROW },
+ { 'C', 0, KEYS_RARROW },
+ { 'F', 0, KEYS_END },
+ { 'H', 0, KEYS_HOME },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab_O[] =
+{
+ { '1', 0, KEYS_F1 },
+ { '2', 0, KEYS_F2 },
+ { '3', 0, KEYS_F3 },
+ { '4', 0, KEYS_F4 },
+ { '5', 0, KEYS_F5 },
+ { '6', 0, KEYS_F6 },
+ { '7', 0, KEYS_F7 },
+ { '8', 0, KEYS_F8 },
+ { '9', 0, KEYS_F9 },
+ { ':', 0, KEYS_F10 },
+ { 'P', 0, KEYS_F1 },
+ { 'Q', 0, KEYS_F2 },
+ { 'R', 0, KEYS_F3 },
+ { 'S', 0, KEYS_F4 },
+ { 'T', 0, KEYS_F5 },
+ { 'U', 0, KEYS_F6 },
+ { 'V', 0, KEYS_F7 },
+ { 'W', 0, KEYS_F8 },
+ { 'X', 0, KEYS_F9 },
+ { 'Y', 0, KEYS_F10 },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab[] =
+{
+ { '[', trans_tab_csi, 0 }, /* CSI command sequences */
+ { 'O', trans_tab_O, 0 }, /* O are the fuction keys */
+ { 0, 0, 0 }
+};
+
+/*
+ * Perform a basic translation for some ANSI/VT100 key codes.
+ * This code could do with a timeout on the ESC as it is
+ * now lost from the input stream. It is not* used by the
+ * line editor below so considiered not worth the effort.
+ */
+
+static unsigned int
+rtems_monitor_getchar (void)
+{
+ const struct translation_table *translation = 0;
+ for (;;)
+ {
+ char c = getchar ();
+ if (c == 27)
+ translation = trans_tab;
+ else
+ {
+ /*
+ * If no translation happing just pass through
+ * and return the key.
+ */
+ if (translation)
+ {
+ /*
+ * Scan the current table for the key, and if found
+ * see if this key is a fork. If so follow it and
+ * wait else return the extended key.
+ */
+ int index = 0;
+ int branched = 0;
+ while ((translation[index].expecting != '\0') ||
+ (translation[index].key != '\0'))
+ {
+ if (translation[index].expecting == c)
+ {
+ /*
+ * A branch is take if more keys are to come.
+ */
+ if (translation[index].branch == 0)
+ return KEYS_EXTENDED | translation[index].key;
+ else
+ {
+ translation = translation[index].branch;
+ branched = 1;
+ break;
+ }
+ }
+ index++;
+ }
+ /*
+ * Who knows what these keys are, just drop them.
+ */
+ if (!branched)
+ translation = 0;
+ }
+ else
+ return c;
+ }
+ }
+}
+
+/*
+ * The line editor with history.
+ */
+
+static int
+rtems_monitor_line_editor (
+ char *command
+)
+{
+ int repeating = 0;
+
+ memset (buffer, 0, RTEMS_COMMAND_BUFFER_SIZE);
+ history = history_next;
+ pos = 0;
+
+ if (!logged_in)
+ fprintf(stdout,"\nMonitor ready, press enter to login.\n\n");
+ else
+ fprintf(stdout,"%s $ ", monitor_prompt);
+
+ while (1)
+ {
+ unsigned int extended_key;
+ char c;
+
+ fflush (stdout);
+
+ extended_key = rtems_monitor_getchar ();
+ c = extended_key & KEYS_NORMAL_MASK;
+
+ /*
+ * Make the extended_key usable as a boolean.
+ */
+ extended_key &= ~KEYS_NORMAL_MASK;
+
+ if (!extended_key && !logged_in)
+ {
+ if (c == '\n')
+ {
+ logged_in = 1;
+ /*
+ * The prompt has changed from `>' to `$' to help know
+ * which version of the monitor code people are using.
+ */
+ fprintf(stdout,"%s $ ", monitor_prompt);
+ }
+ }
+ else
+ {
+ if (extended_key)
+ {
+ switch (c)
+ {
+ case KEYS_END:
+ fprintf(stdout,buffer + pos);
+ pos = (int) strlen (buffer);
+ break;
+
+ case KEYS_HOME:
+ fprintf(stdout,"\r%s $ ", monitor_prompt);
+ pos = 0;
+ break;
+
+ case KEYS_LARROW:
+ if (pos > 0)
+ {
+ pos--;
+ putchar ('\b');
+ }
+ break;
+
+ case KEYS_RARROW:
+ if ((pos < RTEMS_COMMAND_BUFFER_SIZE) && (buffer[pos] != '\0'))
+ {
+ putchar (buffer[pos]);
+ pos++;
+ }
+ break;
+
+ case KEYS_UARROW:
+ /*
+ * If we are moving up the histories then we need to save the working
+ * buffer.
+ */
+ if (history)
+ {
+ int end;
+ int bs;
+ if (history == history_next)
+ {
+ memcpy (history_buffer[history_next], buffer,
+ RTEMS_COMMAND_BUFFER_SIZE);
+ history_pos[history_next] = pos;
+ }
+ history--;
+ memcpy (buffer, history_buffer[history],
+ RTEMS_COMMAND_BUFFER_SIZE);
+ pos = history_pos[history];
+ fprintf(stdout,"\r%*c", RTEMS_COMMAND_BUFFER_SIZE, ' ');
+ fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
+ end = (int) strlen (buffer);
+ for (bs = 0; bs < (end - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+
+ case KEYS_DARROW:
+ if (history < history_next)
+ {
+ int end;
+ int bs;
+ history++;
+ memcpy (buffer, history_buffer[history],
+ RTEMS_COMMAND_BUFFER_SIZE);
+ pos = history_pos[history];
+ fprintf(stdout,"\r%*c", RTEMS_COMMAND_BUFFER_SIZE, ' ');
+ fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
+ end = (int) strlen (buffer);
+ for (bs = 0; bs < (end - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+
+ case KEYS_DEL:
+ if (buffer[pos] != '\0')
+ {
+ int end;
+ int bs;
+ strcpy (&buffer[pos], &buffer[pos + 1]);
+ fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
+ end = (int) strlen (buffer);
+ for (bs = 0; bs < (end - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+ }
+ }
+ else
+ {
+ switch (c)
+ {
+ case '\b':
+ case '\x7e':
+ case '\x7f':
+ if (pos > 0)
+ {
+ int bs;
+ pos--;
+ strcpy (buffer + pos, buffer + pos + 1);
+ fprintf(stdout,"\b%s \b", buffer + pos);
+ for (bs = 0; bs < ((int) strlen (buffer) - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+
+ case '\n':
+ /*
+ * Process the command.
+ */
+ fprintf(stdout,"\n");
+ repeating = 1;
+ /*
+ * Only process the history if we have a command and
+ *a history.
+ */
+ if (strlen (buffer))
+ {
+ if (history_next && (history == history_next))
+ {
+ /*
+ * Do not place the last command into the history
+ *if the same.
+ */
+ if (strcmp (history_buffer[history_next - 1], buffer))
+ repeating = 0;
+ }
+ else
+ repeating = 0;
+ }
+ if (!repeating)
+ {
+ memcpy (history_buffer[history_next], buffer,
+ RTEMS_COMMAND_BUFFER_SIZE);
+ history_pos[history_next] = pos;
+ if (history_next < (RTEMS_COMMAND_HISTORIES - 1))
+ history_next++;
+ else
+ {
+ memmove (history_buffer[0], history_buffer[1],
+ RTEMS_COMMAND_BUFFER_SIZE * (RTEMS_COMMAND_HISTORIES - 1));
+ memmove (&history_pos[0], &history_pos[1],
+ sizeof (history_pos[0]) * (RTEMS_COMMAND_HISTORIES - 1));
+ }
+ }
+ else
+ {
+#ifdef ENABLE_ENTER_REPEATS
+ if (history_next)
+ memcpy (buffer, history_buffer[history_next - 1],
+ RTEMS_COMMAND_BUFFER_SIZE);
+#endif
+ }
+ memmove (command, buffer, RTEMS_COMMAND_BUFFER_SIZE);
+ return repeating;
+ break;
+
+ default:
+ if ((pos < (RTEMS_COMMAND_BUFFER_SIZE - 1)) &&
+ (c >= ' ') && (c <= 'z'))
+ {
+ int end;
+ end = strlen (buffer);
+ if ((pos < end) && (end < RTEMS_COMMAND_BUFFER_SIZE))
+ {
+ int ch, bs;
+ for (ch = end; ch > pos; ch--)
+ buffer[ch] = buffer[ch - 1];
+ fprintf(stdout,buffer + pos);
+ for (bs = 0; bs < (end - pos + 1); bs++)
+ putchar ('\b');
+ }
+ buffer[pos++] = c;
+ if (pos > end)
+ buffer[pos] = '\0';
+ putchar (c);
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+
+/*
+ * make_argv(cp): token-count
+ * Break up the command line in 'cp' into global argv[] and argc (return
+ * value).
+ */
+
+int
+rtems_monitor_make_argv(
+ char *cp,
+ int *argc_p,
+ char **argv)
+{
+ int argc = 0;
+
+ while ((cp = strtok(cp, " \t\n\r")))
+ {
+ argv[argc++] = cp;
+ cp = (char *) NULL;
+ }
+ argv[argc] = (char *) NULL; /* end of argv */
+
+ return *argc_p = argc;
+}
+
+
+/*
+ * Read and break up a monitor command
+ *
+ * We have to loop on the gets call, since it will return NULL under UNIX
+ * RTEMS when we get a signal (eg: SIGALRM).
+ */
+
+int
+rtems_monitor_command_read(char *command,
+ int *argc,
+ char **argv)
+{
+ char *env_prompt;
+
+ env_prompt = getenv("RTEMS_MONITOR_PROMPT");
+
+ /*
+ * put node number in the prompt if we are multiprocessing
+ */
+#if defined(RTEMS_MULTIPROCESSING)
+ if (!rtems_configuration_get_user_multiprocessing_table ())
+ sprintf (monitor_prompt, "%s",
+ (env_prompt == NULL) ? MONITOR_PROMPT: env_prompt);
+ else /* .... */
+#endif
+ if (rtems_monitor_default_node != rtems_monitor_node)
+ sprintf (monitor_prompt, "%" PRId32 "-%s-%" PRId32 "", rtems_monitor_node,
+ (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt,
+ rtems_monitor_default_node);
+ else
+ sprintf (monitor_prompt, "%" PRId32 "-%s", rtems_monitor_node,
+ (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt);
+
+ rtems_monitor_line_editor (command);
+
+ return rtems_monitor_make_argv (command, argc, argv);
+}
+
+/*
+ * Main monitor command loop
+ */
+
+void
+rtems_monitor_task(
+ rtems_task_argument monitor_flags
+)
+{
+ rtems_tcb *debugee = 0;
+ rtems_context *rp;
+#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
+ rtems_context_fp *fp;
+#endif
+ char command_buffer[513];
+ int argc;
+ char *argv[64];
+ bool verbose = false;
+ struct termios term;
+
+ /*
+ * Make the stdin stream characte not line based.
+ */
+
+ if (tcgetattr (STDIN_FILENO, &term) < 0)
+ {
+ fprintf(stdout,"rtems-monitor: cannot get terminal attributes.\n");
+ }
+ else
+ {
+ /*
+ * No echo, no canonical processing.
+ */
+
+ term.c_lflag &= ~(ECHO | ICANON | IEXTEN);
+
+ /*
+ * No sigint on BREAK, CR-to-NL off, input parity off,
+ * don't strip 8th bit on input, output flow control off
+ */
+
+ term.c_lflag &= ~(INPCK | ISTRIP | IXON);
+ term.c_cc[VMIN] = 1;
+ term.c_cc[VTIME] = 0;
+
+ if (tcsetattr (STDIN_FILENO, TCSANOW, &term) < 0)
+ {
+ fprintf(stdout,"cannot set terminal attributes\n");
+ }
+ }
+
+ if (!(monitor_flags & RTEMS_MONITOR_NOSYMLOAD)) {
+ rtems_monitor_symbols_loadup();
+ }
+
+ if (monitor_flags & RTEMS_MONITOR_SUSPEND)
+ (void) rtems_monitor_suspend(RTEMS_NO_TIMEOUT);
+
+ for (;;)
+ {
+ const rtems_monitor_command_entry_t *command;
+
+ debugee = _Thread_Executing;
+ rp = &debugee->Registers;
+#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
+ fp = debugee->fp_context; /* possibly 0 */
+#endif
+
+ if (0 == rtems_monitor_command_read(command_buffer, &argc, argv))
+ continue;
+ if (argc < 1
+ || (command = rtems_monitor_command_lookup(argv [0])) == 0) {
+ /* no command */
+ fprintf(stdout,"Unrecognised command; try 'help'\n");
+ continue;
+ }
+
+ command->command_function(argc, argv, &command->command_arg, verbose);
+
+ fflush(stdout);
+ }
+}
+
+
+void
+rtems_monitor_kill(void)
+{
+ if (rtems_monitor_task_id)
+ rtems_task_delete(rtems_monitor_task_id);
+ rtems_monitor_task_id = 0;
+
+ rtems_monitor_server_kill();
+}
+
+void
+rtems_monitor_init(
+ uint32_t monitor_flags
+)
+{
+ rtems_status_code status;
+
+ rtems_monitor_kill();
+
+ status = rtems_task_create(RTEMS_MONITOR_NAME,
+ 1,
+ RTEMS_MINIMUM_STACK_SIZE * 2,
+ RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &rtems_monitor_task_id);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "could not create monitor task");
+ return;
+ }
+
+ rtems_monitor_node = rtems_object_id_get_node(rtems_monitor_task_id);
+ rtems_monitor_default_node = rtems_monitor_node;
+
+ rtems_monitor_server_init(monitor_flags);
+
+ if (!(monitor_flags & RTEMS_MONITOR_NOTASK)) {
+ /*
+ * Start the monitor task itself
+ */
+ status = rtems_task_start(
+ rtems_monitor_task_id, rtems_monitor_task, monitor_flags);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_error(status, "could not start monitor");
+ return;
+ }
+ }
+}
diff --git a/cpukit/libmisc/monitor/mon-extension.c b/cpukit/libmisc/monitor/mon-extension.c
new file mode 100644
index 0000000000..c6a9f72040
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-extension.c
@@ -0,0 +1,102 @@
+/*
+ * RTEMS Monitor extension support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+
+void
+rtems_monitor_extension_canonical(
+ rtems_monitor_extension_t *canonical_extension,
+ void *extension_void
+)
+{
+ Extension_Control *rtems_extension = (Extension_Control *) extension_void;
+ rtems_extensions_table *e = &rtems_extension->Extension.Callouts;
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_create,
+ (void *) e->thread_create);
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_start,
+ (void *) e->thread_start);
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_restart,
+ (void *) e->thread_restart);
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_delete,
+ (void *) e->thread_delete);
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_tswitch,
+ (void *) e->thread_switch);
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_begin,
+ (void *) e->thread_begin);
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_exitted,
+ (void *) e->thread_exitted);
+ rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_fatal,
+ (void *) e->fatal);
+}
+
+void
+rtems_monitor_extension_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ fprintf(stdout,"\
+ ID NAME\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+
+ rtems_monitor_separator();
+}
+
+
+/*
+ * Dump out the canonical form
+ */
+
+void
+rtems_monitor_extension_dump(
+ rtems_monitor_extension_t *monitor_extension,
+ bool verbose
+)
+{
+ uint32_t length = 0;
+
+ length += rtems_monitor_dump_id(monitor_extension->id);
+ length += rtems_monitor_pad(11, length);
+ length += rtems_monitor_dump_name(monitor_extension->id);
+
+ length += rtems_monitor_pad(18, length);
+ length += fprintf(stdout,"create: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_create, verbose);
+ length += fprintf(stdout,"; start: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_start, verbose);
+ length += fprintf(stdout,"; restart: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_restart, verbose);
+ length += fprintf(stdout,"\n");
+ length = 0;
+
+ length += rtems_monitor_pad(18, length);
+ length += fprintf(stdout,"delete: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_delete, verbose);
+ length += fprintf(stdout,"; switch: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_tswitch, verbose);
+ length += fprintf(stdout,"; begin: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_begin, verbose);
+ length += fprintf(stdout,"\n");
+ length = 0;
+
+ length += rtems_monitor_pad(18, length);
+ length += fprintf(stdout,"exitted: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_exitted, verbose);
+ length += fprintf(stdout,"; fatal: ");
+ length += rtems_monitor_symbol_dump(&monitor_extension->e_fatal, verbose);
+ length += fprintf(stdout,"\n");
+ length = 0;
+ fprintf(stdout,"\n");
+}
diff --git a/cpukit/libmisc/monitor/mon-itask.c b/cpukit/libmisc/monitor/mon-itask.c
new file mode 100644
index 0000000000..6dab51a768
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-itask.c
@@ -0,0 +1,121 @@
+/*
+ * RTEMS Monitor init task support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <inttypes.h>
+#include <stdio.h>
+
+/*
+ * As above, but just for init tasks
+ */
+void
+rtems_monitor_init_task_canonical(
+ rtems_monitor_init_task_t *canonical_itask,
+ void *itask_void
+)
+{
+ rtems_initialization_tasks_table *rtems_itask = itask_void;
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_itask->entry,
+ (void *) rtems_itask->entry_point);
+
+ canonical_itask->argument = rtems_itask->argument;
+ canonical_itask->stack_size = rtems_itask->stack_size;
+ canonical_itask->priority = rtems_itask->initial_priority;
+ canonical_itask->modes = rtems_itask->mode_set;
+ canonical_itask->attributes = rtems_itask->attribute_set;
+}
+
+void *
+rtems_monitor_init_task_next(
+ void *object_info __attribute__((unused)),
+ rtems_monitor_init_task_t *canonical_init_task,
+ rtems_id *next_id
+)
+{
+ rtems_initialization_tasks_table *itask;
+ uint32_t n = rtems_object_id_get_index(*next_id);
+
+ if (n >= Configuration_RTEMS_API.number_of_initialization_tasks)
+ goto failed;
+
+ _Thread_Disable_dispatch();
+
+ itask = Configuration_RTEMS_API.User_initialization_tasks_table + n;
+
+ /*
+ * dummy up a fake id and name for this item
+ */
+
+ canonical_init_task->id = n;
+ canonical_init_task->name = itask->name;
+
+ *next_id += 1;
+ return (void *) itask;
+
+failed:
+ *next_id = RTEMS_OBJECT_ID_FINAL;
+ return 0;
+}
+
+
+void
+rtems_monitor_init_task_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ fprintf(stdout,"\
+ # NAME ENTRY ARGUMENT PRIO MODES ATTRIBUTES STACK SIZE\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+ rtems_monitor_separator();
+}
+
+/*
+ */
+
+void
+rtems_monitor_init_task_dump(
+ rtems_monitor_init_task_t *monitor_itask,
+ bool verbose
+)
+{
+ int length = 0;
+
+ length += rtems_monitor_dump_decimal(monitor_itask->id);
+
+ length += rtems_monitor_pad(7, length);
+ length += rtems_monitor_dump_name(monitor_itask->id);
+
+ length += rtems_monitor_pad(14, length);
+ length += rtems_monitor_symbol_dump(&monitor_itask->entry, verbose);
+
+ length += rtems_monitor_pad(25, length);
+ length += fprintf(stdout,"%" PRId32 " [0x%" PRIx32 "]",
+ monitor_itask->argument, monitor_itask->argument);
+
+ length += rtems_monitor_pad(39, length);
+ length += rtems_monitor_dump_priority(monitor_itask->priority);
+
+ length += rtems_monitor_pad(46, length);
+ length += rtems_monitor_dump_modes(monitor_itask->modes);
+
+ length += rtems_monitor_pad(54, length);
+ length += rtems_monitor_dump_attributes(monitor_itask->attributes);
+
+ length += rtems_monitor_pad(66, length);
+ length += fprintf(stdout,"%" PRId32 " [0x%" PRIx32 "]",
+ monitor_itask->stack_size, monitor_itask->stack_size);
+
+ fprintf(stdout,"\n");
+}
diff --git a/cpukit/libmisc/monitor/mon-manager.c b/cpukit/libmisc/monitor/mon-manager.c
new file mode 100644
index 0000000000..9e71addfae
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-manager.c
@@ -0,0 +1,55 @@
+/*
+ * RTEMS Monitor "manager" support.
+ * Used to traverse object (chain) lists and print them out.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+
+/*
+ * "next" routine for all objects that are RTEMS manager objects
+ */
+
+void *
+rtems_monitor_manager_next(
+ void *table_void,
+ void *canonical,
+ rtems_id *next_id
+)
+{
+ Objects_Information *table = table_void;
+ rtems_monitor_generic_t *copy;
+ Objects_Control *object = 0;
+ Objects_Locations location;
+
+ /*
+ * When we are called, it must be local
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( ! _Objects_Is_local_id(*next_id) )
+ goto done;
+#endif
+
+ object = _Objects_Get_next(table, *next_id, &location, next_id);
+
+ if (object)
+ {
+ copy = (rtems_monitor_generic_t *) canonical;
+ copy->id = object->id;
+ copy->name = object->name.name_u32;
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+done:
+#endif
+ return object;
+}
diff --git a/cpukit/libmisc/monitor/mon-monitor.c b/cpukit/libmisc/monitor/mon-monitor.c
new file mode 100644
index 0000000000..88f3d49eb3
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-monitor.c
@@ -0,0 +1,529 @@
+/*
+ * RTEMS monitor main body
+ *
+ * TODO:
+ * add stuff to RTEMS api
+ * rtems_get_name(id)
+ * rtems_get_type(id)
+ * rtems_build_id(node, type, num)
+ * Add a command to dump out info about an arbitrary id when
+ * types are added to id's
+ * rtems> id idnum
+ * idnum: node n, object: whatever, id: whatever
+ * allow id's to be specified as n:t:id, where 'n:t' is optional
+ * should have a separate monitor FILE stream (ala the debugger)
+ * remote request/response stuff should be cleaned up
+ * maybe we can use real rpc??
+ * 'info' command to print out:
+ * interrupt stack location, direction and size
+ * floating point config stuff
+ * interrupt config stuff
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <rtems/monitor.h>
+
+/* set by trap handler */
+extern rtems_tcb *debugger_interrupted_task;
+extern rtems_context *debugger_interrupted_task_context;
+extern uint32_t debugger_trap;
+
+/*
+ * Various id's for the monitor
+ * They need to be public variables for access by other agencies
+ * such as debugger and remote servers'
+ */
+
+rtems_id rtems_monitor_task_id;
+
+uint32_t rtems_monitor_node; /* our node number */
+uint32_t rtems_monitor_default_node; /* current default for commands */
+
+/*
+ * The rtems symbol table
+ */
+
+rtems_symbol_table_t *rtems_monitor_symbols;
+
+/*
+ * The top-level commands
+ */
+
+static const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
+ { "config",
+ "Show the system configuration.",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_CONFIG },
+ &rtems_monitor_commands[1],
+ },
+ { "itask",
+ "List init tasks for the system",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_INIT_TASK },
+ &rtems_monitor_commands[2],
+ },
+ { "mpci",
+ "Show the MPCI system configuration, if configured.",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_MPCI },
+ &rtems_monitor_commands[3],
+ },
+ { "pause",
+ "Monitor goes to \"sleep\" for specified ticks (default is 1). "
+ "Monitor will resume at end of period or if explicitly awakened\n"
+ " pause [ticks]",
+ 0,
+ rtems_monitor_pause_cmd,
+ { 0 },
+ &rtems_monitor_commands[4],
+ },
+ { "continue",
+ "Put the monitor to sleep waiting for an explicit wakeup from the "
+ "program running.\n",
+ 0,
+ rtems_monitor_continue_cmd,
+ { 0 },
+ &rtems_monitor_commands[5],
+ },
+ { "go",
+ "Alias for 'continue'",
+ 0,
+ rtems_monitor_continue_cmd,
+ { 0 },
+ &rtems_monitor_commands[6],
+ },
+ { "symbol",
+ "Display value associated with specified symbol. "
+ "Defaults to displaying all known symbols.\n"
+ " symbol [ symbolname [symbolname ... ] ]",
+ 0,
+ rtems_monitor_symbol_cmd,
+ { .symbol_table = &rtems_monitor_symbols },
+ &rtems_monitor_commands[7],
+ },
+ { "extension",
+ "Display information about specified extensions. "
+ "Default is to display information about all extensions on this node.\n"
+ " extension [id [id ...] ]",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_EXTENSION },
+ &rtems_monitor_commands[8],
+ },
+ { "task",
+ "Display information about the specified tasks. "
+ "Default is to display information about all tasks on this node.\n"
+ " task [id [id ...] ]",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_TASK },
+ &rtems_monitor_commands[9],
+ },
+ { "queue",
+ "Display information about the specified message queues. "
+ "Default is to display information about all queues on this node.\n"
+ " queue [id [id ... ] ]",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_QUEUE },
+ &rtems_monitor_commands[10],
+ },
+ { "sema",
+ "sema [id [id ... ] ]\n"
+ " display information about the specified semaphores\n"
+ " Default is to display information about all semaphores on this node\n"
+ ,
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_SEMAPHORE },
+ &rtems_monitor_commands[11],
+ },
+ { "region",
+ "region [id [id ... ] ]\n"
+ " display information about the specified regions\n"
+ " Default is to display information about all regions on this node\n"
+ ,
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_REGION },
+ &rtems_monitor_commands[12],
+ },
+ { "part",
+ "part [id [id ... ] ]\n"
+ " display information about the specified partitions\n"
+ " Default is to display information about all partitions on this node\n"
+ ,
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_PARTITION },
+ &rtems_monitor_commands[13],
+ },
+ { "object",
+ "Display information about specified RTEMS objects. "
+ "Object id's must include 'type' information. "
+ "(which may normally be defaulted)\n"
+ " object [id [id ...] ]",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_INVALID },
+ &rtems_monitor_commands[14],
+ },
+ { "driver",
+ "Display the RTEMS device driver table.\n"
+ " driver [ major [ major ... ] ]",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_DRIVER },
+ &rtems_monitor_commands[15],
+ },
+ { "dname",
+ "Displays information about named drivers.\n",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_DNAME },
+ &rtems_monitor_commands[16],
+ },
+ { "exit",
+ "Invoke 'rtems_fatal_error_occurred' with 'status' "
+ "(default is RTEMS_SUCCESSFUL)\n"
+ " exit [status]",
+ 0,
+ rtems_monitor_fatal_cmd,
+ { .status_code = RTEMS_SUCCESSFUL },
+ &rtems_monitor_commands[17],
+ },
+ { "fatal",
+ "'exit' with fatal error; default error is RTEMS_TASK_EXITTED\n"
+ " fatal [status]",
+ 0,
+ rtems_monitor_fatal_cmd,
+ { .status_code = RTEMS_TASK_EXITTED }, /* exit value */
+ &rtems_monitor_commands[18],
+ },
+ { "quit",
+ "Alias for 'exit'\n",
+ 0,
+ rtems_monitor_fatal_cmd,
+ { .status_code = RTEMS_SUCCESSFUL }, /* exit value */
+ &rtems_monitor_commands[19],
+ },
+ { "reset",
+ "(SW)Resets the System.",
+ 0,
+ rtems_monitor_reset_cmd,
+ { 0 },
+ &rtems_monitor_commands[20],
+ },
+#if defined(RTEMS_MULTIPROCESSING)
+ { "node",
+ "Specify default node number for commands that take id's.\n"
+ " node [ node number ]",
+ 0,
+ rtems_monitor_node_cmd,
+ { 0 },
+ &rtems_monitor_commands[21],
+ },
+ #define RTEMS_MONITOR_POSIX_NEXT 22
+#else
+ #define RTEMS_MONITOR_POSIX_NEXT 21
+#endif
+#ifdef RTEMS_POSIX_API
+ { "pthread",
+ "Display information about the specified pthreads. "
+ "Default is to display information about all pthreads on this node.\n"
+ " pthread [id [id ...] ]",
+ 0,
+ rtems_monitor_object_cmd,
+ { RTEMS_MONITOR_OBJECT_PTHREAD },
+ &rtems_monitor_commands[RTEMS_MONITOR_POSIX_NEXT],
+ },
+ #define RTEMS_MONITOR_DEBUGGER_NEXT (RTEMS_MONITOR_POSIX_NEXT + 1)
+#else
+ #define RTEMS_MONITOR_DEBUGGER_NEXT RTEMS_MONITOR_POSIX_NEXT
+#endif
+#ifdef CPU_INVOKE_DEBUGGER
+ { "debugger",
+ "Enter the debugger, if possible. "
+ "A continue from the debugger will return to the monitor.\n",
+ 0,
+ rtems_monitor_debugger_cmd,
+ { 0 },
+ &rtems_monitor_commands[RTEMS_MONITOR_DEBUGGER_NEXT],
+ },
+#endif
+ { "help",
+ "Provide information about commands. "
+ "Default is show basic command summary.\n"
+ "help [ command [ command ] ]",
+ 0,
+ rtems_monitor_help_cmd,
+ { .monitor_command_entry = rtems_monitor_commands },
+ NULL
+ }
+};
+
+/*
+ * All registered commands.
+ */
+
+static const rtems_monitor_command_entry_t *rtems_monitor_registered_commands =
+ &rtems_monitor_commands [0];
+
+
+rtems_status_code
+rtems_monitor_suspend(rtems_interval timeout)
+{
+ rtems_event_set event_set;
+ rtems_status_code status;
+
+ status = rtems_event_receive(MONITOR_WAKEUP_EVENT,
+ RTEMS_DEFAULT_OPTIONS,
+ timeout,
+ &event_set);
+ return status;
+}
+
+void __attribute__((weak))
+rtems_monitor_reset_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t* command_arg,
+ bool verbose
+)
+{
+
+}
+
+void
+rtems_monitor_wakeup(void)
+{
+ rtems_status_code status;
+
+ status = rtems_event_send(rtems_monitor_task_id, MONITOR_WAKEUP_EVENT);
+}
+
+void rtems_monitor_debugger_cmd(
+ int argc __attribute__((unused)),
+ char **argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t *command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused))
+)
+{
+#ifdef CPU_INVOKE_DEBUGGER
+ CPU_INVOKE_DEBUGGER;
+#endif
+}
+
+void rtems_monitor_pause_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused))
+)
+{
+ if (argc == 1)
+ rtems_monitor_suspend(1);
+ else
+ rtems_monitor_suspend(strtoul(argv[1], 0, 0));
+}
+
+void rtems_monitor_fatal_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose __attribute__((unused))
+)
+{
+ if (argc == 1)
+ rtems_fatal_error_occurred(command_arg->status_code);
+ else
+ rtems_fatal_error_occurred(strtoul(argv[1], 0, 0));
+}
+
+void rtems_monitor_continue_cmd(
+ int argc __attribute__((unused)),
+ char **argv __attribute__((unused)),
+ const rtems_monitor_command_arg_t *command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused))
+)
+{
+ rtems_monitor_suspend(RTEMS_NO_TIMEOUT);
+}
+
+#if defined(RTEMS_MULTIPROCESSING)
+void rtems_monitor_node_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused))
+)
+{
+ uint32_t new_node = rtems_monitor_default_node;
+
+ switch (argc) {
+ case 1: /* no node, just set back to ours */
+ new_node = rtems_monitor_node;
+ break;
+
+ case 2:
+ new_node = strtoul(argv[1], 0, 0);
+ break;
+
+ default:
+ fprintf(stdout,"invalid syntax, try 'help node'\n");
+ break;
+ }
+
+ if ((new_node >= 1) &&
+ _Configuration_MP_table &&
+ (new_node <= _Configuration_MP_table->maximum_nodes))
+ rtems_monitor_default_node = new_node;
+}
+#endif
+
+
+/*
+ * Function: rtems_monitor_symbols_loadup
+ *
+ * Description:
+ * Create and load the monitor's symbol table.
+ * We are reading the output format of 'gnm' which looks like this:
+ *
+ * 400a7068 ? _Rate_monotonic_Information
+ * 400a708c ? _Thread_Dispatch_disable_level
+ * 400a7090 ? _Configuration_Table
+ *
+ * We ignore the type field.
+ *
+ * Side Effects:
+ * Creates and fills in 'rtems_monitor_symbols' table
+ *
+ * TODO
+ * there should be a BSP #define or something like that
+ * to do this; Assuming stdio is crazy.
+ * Someday this should know BFD
+ * Maybe we could get objcopy to just copy the symbol areas
+ * and copy that down.
+ *
+ */
+
+void
+rtems_monitor_symbols_loadup(void)
+{
+ FILE *fp;
+ char buffer[128];
+
+ if (rtems_monitor_symbols)
+ rtems_symbol_table_destroy(rtems_monitor_symbols);
+
+ rtems_monitor_symbols = rtems_symbol_table_create();
+ if (rtems_monitor_symbols == 0)
+ return;
+
+ fp = fopen("symbols", "r");
+
+ if (fp == 0)
+ return;
+
+ while (fgets(buffer, sizeof(buffer) - 1, fp))
+ {
+ char *symbol;
+ char *value;
+ char *ignored_type;
+
+ value = strtok(buffer, " \t\n");
+ ignored_type = strtok(0, " \t\n");
+ symbol = strtok(0, " \t\n");
+
+ if (symbol && ignored_type && value)
+ {
+ rtems_symbol_t *sp;
+ sp = rtems_symbol_create(rtems_monitor_symbols,
+ symbol,
+ (uint32_t) strtoul(value, 0, 16));
+ if (sp == 0)
+ {
+ fprintf(stdout,"could not define symbol '%s'\n", symbol);
+ goto done;
+ }
+ }
+ else
+ {
+ fprintf(stdout,"parsing error on '%s'\n", buffer);
+ goto done;
+ }
+ }
+
+done:
+ fclose(fp);
+ return;
+}
+
+/*
+ * User registered commands.
+ */
+
+int
+rtems_monitor_insert_cmd (
+ rtems_monitor_command_entry_t *command
+)
+{
+ const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
+
+ /* Reject empty commands */
+ if (command->command == NULL) {
+ return 0;
+ }
+
+ /* Reject command if already present */
+ while (e->next != NULL) {
+ if (e->command != NULL && strcmp(command->command, e->command) == 0) {
+ return 0;
+ }
+ e = e->next;
+ }
+
+ /* Prepend new command */
+ command->next = rtems_monitor_registered_commands;
+ rtems_monitor_registered_commands = command;
+
+ return 1;
+}
+
+/**
+ * @brief Iterates through all registerd commands.
+ *
+ * For each command the interation routine @a routine is called with the
+ * command entry and the user provided argument @a arg. It is guaranteed that
+ * the command name and function are not NULL.
+ */
+void rtems_monitor_command_iterate(
+ rtems_monitor_per_command_routine routine,
+ void *arg
+)
+{
+ const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
+
+ while (e != NULL) {
+ if (e->command != NULL && e->command_function != NULL) {
+ if (!routine(e, arg)) {
+ break;
+ }
+ }
+ e = e->next;
+ }
+}
diff --git a/cpukit/libmisc/monitor/mon-mpci.c b/cpukit/libmisc/monitor/mon-mpci.c
new file mode 100644
index 0000000000..ab77431241
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-mpci.c
@@ -0,0 +1,163 @@
+/*
+ * RTEMS MPCI Config display support
+ *
+ * TODO
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+#include <stdlib.h> /* strtoul() */
+#include <inttypes.h>
+
+#define DATACOL 15
+
+/*
+ * Fill in entire monitor config table
+ * for sending to a remote monitor or printing on the local system
+ */
+
+void
+rtems_monitor_mpci_canonical(
+ rtems_monitor_mpci_t *canonical_mpci,
+ void *config_void
+)
+{
+ rtems_configuration_table *c = &Configuration;
+ rtems_multiprocessing_table *m;
+ rtems_mpci_table *mt;
+
+ m = c->User_multiprocessing_table;
+ if (m == 0)
+ return;
+ mt = m->User_mpci_table;
+
+ canonical_mpci->node = m->node;
+ canonical_mpci->maximum_nodes = m->maximum_nodes;
+ canonical_mpci->maximum_global_objects = m->maximum_global_objects;
+ canonical_mpci->maximum_proxies = m->maximum_proxies;
+
+ canonical_mpci->default_timeout = mt->default_timeout;
+ canonical_mpci->maximum_packet_size = mt->maximum_packet_size;
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_mpci->initialization,
+ (void *) mt->initialization);
+
+ rtems_monitor_symbol_canonical_by_value(&canonical_mpci->get_packet,
+ (void *) mt->get_packet);
+ rtems_monitor_symbol_canonical_by_value(&canonical_mpci->return_packet,
+ (void *) mt->return_packet);
+ rtems_monitor_symbol_canonical_by_value(&canonical_mpci->send_packet,
+ (void *) mt->send_packet);
+ rtems_monitor_symbol_canonical_by_value(&canonical_mpci->receive_packet,
+ (void *) mt->receive_packet);
+}
+
+/*
+ * This is easy, since there is only 1 (altho we could get them from
+ * other nodes...)
+ */
+
+void *
+rtems_monitor_mpci_next(
+ void *object_info,
+ rtems_monitor_mpci_t *canonical_mpci,
+ rtems_id *next_id
+)
+{
+ rtems_configuration_table *c = &Configuration;
+ int n = rtems_object_id_get_index(*next_id);
+
+ if (n >= 1)
+ goto failed;
+
+ if ( ! c->User_multiprocessing_table)
+ goto failed;
+
+ _Thread_Disable_dispatch();
+
+ *next_id += 1;
+ return (void *) c;
+
+failed:
+ *next_id = RTEMS_OBJECT_ID_FINAL;
+ return 0;
+}
+
+
+void
+rtems_monitor_mpci_dump_header(
+ bool verbose
+)
+{
+ fprintf(stdout,"\
+ max max max default max\n\
+ node nodes globals proxies timeout pktsize\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+
+ rtems_monitor_separator();
+}
+
+
+void
+rtems_monitor_mpci_dump(
+ rtems_monitor_mpci_t *monitor_mpci,
+ bool verbose
+)
+{
+ uint32_t length = 0;
+
+ length += rtems_monitor_pad(2, length);
+ length += fprintf(stdout," %" PRId32 , monitor_mpci->node);
+ length += rtems_monitor_pad(11, length);
+ length += fprintf(stdout,"%" PRId32, monitor_mpci->maximum_nodes);
+
+ length += rtems_monitor_pad(18, length);
+ length += rtems_monitor_dump_decimal(monitor_mpci->maximum_global_objects);
+
+ length += rtems_monitor_pad(28, length);
+ length += rtems_monitor_dump_decimal(monitor_mpci->maximum_proxies);
+
+ length += rtems_monitor_pad(37, length);
+ length += rtems_monitor_dump_decimal(monitor_mpci->default_timeout);
+
+ length += rtems_monitor_pad(46, length);
+ length += rtems_monitor_dump_decimal((uint32_t) monitor_mpci->maximum_packet_size);
+
+ fprintf(stdout,"\n");
+ length = 0;
+ length += rtems_monitor_pad(DATACOL, length);
+
+ length += fprintf(stdout,"init: ");
+ length += rtems_monitor_symbol_dump(&monitor_mpci->initialization, verbose);
+
+ fprintf(stdout,"\n");
+ length = 0;
+ length += rtems_monitor_pad(DATACOL, length);
+
+ length += fprintf(stdout,"get: ");
+ length += rtems_monitor_symbol_dump(&monitor_mpci->get_packet, verbose);
+ length += fprintf(stdout,"; return: ");
+ length += rtems_monitor_symbol_dump(&monitor_mpci->return_packet, verbose);
+
+ fprintf(stdout,"\n");
+ length = 0;
+ length += rtems_monitor_pad(DATACOL, length);
+
+ length += fprintf(stdout,"send: ");
+ length += rtems_monitor_symbol_dump(&monitor_mpci->send_packet, verbose);
+ length += fprintf(stdout,"; receive: ");
+ length += rtems_monitor_symbol_dump(&monitor_mpci->receive_packet, verbose);
+
+ fprintf(stdout,"\n");
+ length = 0;
+}
diff --git a/cpukit/libmisc/monitor/mon-network.c b/cpukit/libmisc/monitor/mon-network.c
new file mode 100644
index 0000000000..52c0cd9852
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-network.c
@@ -0,0 +1,342 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include <rtems/rtems_bsdnet.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/sockio.h>
+#include <net/route.h>
+
+
+void mon_ifconfig(int argc, char *argv[],
+ uint32_t command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ struct sockaddr_in ipaddr;
+ struct sockaddr_in dstaddr;
+ struct sockaddr_in netmask;
+ struct sockaddr_in broadcast;
+ char *iface;
+ int f_ip = 0;
+ int f_ptp = 0;
+ int f_netmask = 0;
+ int f_up = 0;
+ int f_down = 0;
+ int f_bcast = 0;
+ int cur_idx;
+ int rc;
+ int flags;
+
+ memset(&ipaddr, 0, sizeof(ipaddr));
+ memset(&dstaddr, 0, sizeof(dstaddr));
+ memset(&netmask, 0, sizeof(netmask));
+ memset(&broadcast, 0, sizeof(broadcast));
+
+ ipaddr.sin_len = sizeof(ipaddr);
+ ipaddr.sin_family = AF_INET;
+
+ dstaddr.sin_len = sizeof(dstaddr);
+ dstaddr.sin_family = AF_INET;
+
+ netmask.sin_len = sizeof(netmask);
+ netmask.sin_family = AF_INET;
+
+ broadcast.sin_len = sizeof(broadcast);
+ broadcast.sin_family = AF_INET;
+
+ cur_idx = 0;
+ if (argc <= 1) {
+ /* display all interfaces */
+ iface = NULL;
+ cur_idx += 1;
+ } else {
+ iface = argv[1];
+ if (isdigit((unsigned char)*argv[2])) {
+ if (inet_pton(AF_INET, argv[2], &ipaddr.sin_addr) < 0) {
+ printf("bad ip address: %s\n", argv[2]);
+ return;
+ }
+ f_ip = 1;
+ cur_idx += 3;
+ } else {
+ cur_idx += 2;
+ }
+ }
+
+ if ((f_down !=0) && (f_ip != 0)) {
+ f_up = 1;
+ }
+
+ while(argc > cur_idx) {
+ if (strcmp(argv[cur_idx], "up") == 0) {
+ f_up = 1;
+ if (f_down != 0) {
+ printf("Can't make interface up and down\n");
+ }
+ } else if(strcmp(argv[cur_idx], "down") == 0) {
+ f_down = 1;
+ if (f_up != 0) {
+ printf("Can't make interface up and down\n");
+ }
+ } else if(strcmp(argv[cur_idx], "netmask") == 0) {
+ if ((cur_idx + 1) >= argc) {
+ printf("No netmask address\n");
+ return;
+ }
+ if (inet_pton(AF_INET, argv[cur_idx+1], &netmask.sin_addr) < 0) {
+ printf("bad netmask: %s\n", argv[cur_idx]);
+ return;
+ }
+ f_netmask = 1;
+ cur_idx += 1;
+ } else if(strcmp(argv[cur_idx], "broadcast") == 0) {
+ if ((cur_idx + 1) >= argc) {
+ printf("No broadcast address\n");
+ return;
+ }
+ if (inet_pton(AF_INET, argv[cur_idx+1], &broadcast.sin_addr) < 0) {
+ printf("bad broadcast: %s\n", argv[cur_idx]);
+ return;
+ }
+ f_bcast = 1;
+ cur_idx += 1;
+ } else if(strcmp(argv[cur_idx], "pointopoint") == 0) {
+ if ((cur_idx + 1) >= argc) {
+ printf("No pointopoint address\n");
+ return;
+ }
+ if (inet_pton(AF_INET, argv[cur_idx+1], &dstaddr.sin_addr) < 0) {
+ printf("bad pointopoint: %s\n", argv[cur_idx]);
+ return;
+ }
+
+ f_ptp = 1;
+ cur_idx += 1;
+ } else {
+ printf("Bad parameter: %s\n", argv[cur_idx]);
+ return;
+ }
+
+ cur_idx += 1;
+ }
+
+ printf("ifconfig ");
+ if (iface != NULL) {
+ printf("%s ", iface);
+ if (f_ip != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &ipaddr.sin_addr, str, 256);
+ printf("%s ", str);
+ }
+
+ if (f_netmask != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &netmask.sin_addr, str, 256);
+ printf("netmask %s ", str);
+ }
+
+ if (f_bcast != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &broadcast.sin_addr, str, 256);
+ printf("broadcast %s ", str);
+ }
+
+ if (f_ptp != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &dstaddr.sin_addr, str, 256);
+ printf("pointopoint %s ", str);
+ }
+
+ if (f_up != 0) {
+ printf("up\n");
+ } else if (f_down != 0) {
+ printf("down\n");
+ } else {
+ printf("\n");
+ }
+ }
+
+ if ((iface == NULL) || ((f_ip == 0) && (f_down == 0) && (f_up == 0))) {
+ rtems_bsdnet_show_if_stats();
+ return;
+ }
+
+ flags = 0;
+ if (f_netmask) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFNETMASK, &netmask);
+ if (rc < 0) {
+ printf("Could not set netmask: %s\n", strerror(errno));
+ return;
+ }
+ }
+
+ if (f_bcast) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFBRDADDR, &broadcast);
+ if (rc < 0) {
+ printf("Could not set broadcast: %s\n", strerror(errno));
+ return;
+ }
+ }
+
+ if (f_ptp) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFDSTADDR, &dstaddr);
+ if (rc < 0) {
+ printf("Could not set destination address: %s\n", strerror(errno));
+ return;
+ }
+ flags |= IFF_POINTOPOINT;
+ }
+
+ /* This must come _after_ setting the netmask, broadcast addresses */
+ if (f_ip) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFADDR, &ipaddr);
+ if (rc < 0) {
+ printf("Could not set IP address: %s\n", strerror(errno));
+ return;
+ }
+ }
+
+ if (f_up != 0) {
+ flags |= IFF_UP;
+ }
+
+ if (f_down != 0) {
+ printf("Warning: taking interfaces down is not supported\n");
+ }
+
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFFLAGS, &flags);
+ if (rc < 0) {
+ printf("Could not set interface flags: %s\n", strerror(errno));
+ return;
+ }
+}
+
+
+
+void mon_route(int argc, char *argv[],
+ uint32_t command_arg __attribute__((unused)),
+ bool verbose __attribute__((unused)))
+{
+ int cmd;
+ struct sockaddr_in dst;
+ struct sockaddr_in gw;
+ struct sockaddr_in netmask;
+ int f_host;
+ int f_gw = 0;
+ int cur_idx;
+ int flags;
+ int rc;
+
+ memset(&dst, 0, sizeof(dst));
+ memset(&gw, 0, sizeof(gw));
+ memset(&netmask, 0, sizeof(netmask));
+
+ dst.sin_len = sizeof(dst);
+ dst.sin_family = AF_INET;
+ dst.sin_addr.s_addr = inet_addr("0.0.0.0");
+
+ gw.sin_len = sizeof(gw);
+ gw.sin_family = AF_INET;
+ gw.sin_addr.s_addr = inet_addr("0.0.0.0");
+
+ netmask.sin_len = sizeof(netmask);
+ netmask.sin_family = AF_INET;
+ netmask.sin_addr.s_addr = inet_addr("255.255.255.0");
+
+ if (argc < 2) {
+ rtems_bsdnet_show_inet_routes();
+ return;
+ }
+
+ if (strcmp(argv[1], "add") == 0) {
+ cmd = RTM_ADD;
+ } else if (strcmp(argv[1], "del") == 0) {
+ cmd = RTM_DELETE;
+ } else {
+ printf("invalid command: %s\n", argv[1]);
+ printf("\tit should be 'add' or 'del'\n");
+ return;
+ }
+
+ if (argc < 3) {
+ printf("not enough arguments\n");
+ return;
+ }
+
+ if (strcmp(argv[2], "-host") == 0) {
+ f_host = 1;
+ } else if (strcmp(argv[2], "-net") == 0) {
+ f_host = 0;
+ } else {
+ printf("Invalid type: %s\n", argv[1]);
+ printf("\tit should be '-host' or '-net'\n");
+ return;
+ }
+
+ if (argc < 4) {
+ printf("not enough arguments\n");
+ return;
+ }
+
+ inet_pton(AF_INET, argv[3], &dst.sin_addr);
+
+ cur_idx = 4;
+ while(cur_idx < argc) {
+ if (strcmp(argv[cur_idx], "gw") == 0) {
+ if ((cur_idx +1) >= argc) {
+ printf("no gateway address\n");
+ return;
+ }
+ f_gw = 1;
+ inet_pton(AF_INET, argv[cur_idx + 1], &gw.sin_addr);
+ cur_idx += 1;
+ } else if(strcmp(argv[cur_idx], "netmask") == 0) {
+ if ((cur_idx +1) >= argc) {
+ printf("no netmask address\n");
+ return;
+ }
+ f_gw = 1;
+ inet_pton(AF_INET, argv[cur_idx + 1], &netmask.sin_addr);
+ cur_idx += 1;
+ } else {
+ printf("Unknown argument: %s\n", argv[cur_idx]);
+ return;
+ }
+ cur_idx += 1;
+ }
+
+ flags = RTF_STATIC;
+ if (f_gw != 0) {
+ flags |= RTF_GATEWAY;
+ }
+ if (f_host != 0) {
+ flags |= RTF_HOST;
+ }
+
+ rc = rtems_bsdnet_rtrequest(cmd,
+ (struct sockaddr*) &dst,
+ (struct sockaddr*) &gw,
+ (struct sockaddr*) &netmask, flags, NULL);
+ if (rc < 0) {
+ printf("Error adding route\n");
+ }
+}
diff --git a/cpukit/libmisc/monitor/mon-object.c b/cpukit/libmisc/monitor/mon-object.c
new file mode 100644
index 0000000000..96b2a85f8d
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-object.c
@@ -0,0 +1,423 @@
+/*
+ * RTEMS Monitor "object" support.
+ *
+ * Used to traverse object lists and print them out.
+ * An object can be an RTEMS object (chain based stuff) or
+ * a "misc" object such as a device driver.
+ *
+ * Each object has its own file in this directory (eg: extension.c)
+ * That file provides routines to convert a "native" structure
+ * to its canonical form, print a canonical structure, etc.
+ *
+ * TODO:
+ * should allow for non-numeric id's???
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <rtems/monitor.h>
+#if defined(RTEMS_POSIX_API)
+ #include <rtems/posix/pthread.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h> /* strtoul() */
+#include <string.h> /* memcpy() */
+
+#define NUMELEMS(arr) (sizeof(arr) / sizeof(arr[0]))
+
+/*
+ * add:
+ * next
+ */
+
+static const rtems_monitor_object_info_t rtems_monitor_object_info[] =
+{
+ { RTEMS_MONITOR_OBJECT_CONFIG,
+ (void *) 0,
+ sizeof(rtems_monitor_config_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_config_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_config_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_config_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_config_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_MPCI,
+ (void *) 0,
+#if defined(RTEMS_MULTIPROCESSING)
+ sizeof(rtems_monitor_mpci_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_mpci_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_mpci_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_mpci_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_mpci_dump,
+#else
+ 0,
+ (rtems_monitor_object_next_fn) 0,
+ (rtems_monitor_object_canonical_fn) 0,
+ (rtems_monitor_object_dump_header_fn) 0,
+ (rtems_monitor_object_dump_fn) 0,
+#endif
+ },
+ { RTEMS_MONITOR_OBJECT_INIT_TASK,
+ (void *) 0,
+ sizeof(rtems_monitor_init_task_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_init_task_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_init_task_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_init_task_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_init_task_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_TASK,
+ (void *) &_RTEMS_tasks_Information,
+ sizeof(rtems_monitor_task_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_task_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_task_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_QUEUE,
+ (void *) &_Message_queue_Information,
+ sizeof(rtems_monitor_queue_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_queue_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_queue_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_queue_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_SEMAPHORE,
+ (void *) &_Semaphore_Information,
+ sizeof(rtems_monitor_sema_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_sema_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_sema_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_sema_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_REGION,
+ (void *) &_Region_Information,
+ sizeof(rtems_monitor_region_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_region_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_region_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_region_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_PARTITION,
+ (void *) &_Partition_Information,
+ sizeof(rtems_monitor_part_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_part_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_part_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_part_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_EXTENSION,
+ (void *) &_Extension_Information,
+ sizeof(rtems_monitor_extension_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_extension_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_extension_dump,
+ },
+ { RTEMS_MONITOR_OBJECT_DRIVER,
+ (void *) 0,
+ sizeof(rtems_monitor_driver_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_driver_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_driver_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_driver_dump,
+ },
+#if defined(RTEMS_POSIX_API)
+ { RTEMS_MONITOR_OBJECT_PTHREAD,
+ (void *) &_POSIX_Threads_Information,
+ sizeof(rtems_monitor_task_t),
+ (rtems_monitor_object_next_fn) rtems_monitor_manager_next,
+ (rtems_monitor_object_canonical_fn) rtems_monitor_task_canonical,
+ (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header,
+ (rtems_monitor_object_dump_fn) rtems_monitor_task_dump,
+ },
+#endif
+};
+
+/*
+ * Allow id's to be specified without the node number or
+ * type for convenience.
+ */
+
+rtems_id
+rtems_monitor_id_fixup(
+ rtems_id id,
+ uint32_t default_node,
+ rtems_monitor_object_type_t type
+)
+{
+ uint32_t node;
+
+ node = rtems_object_id_get_node(id);
+ if (node == 0)
+ {
+ if (rtems_object_id_get_class(id) != OBJECTS_CLASSIC_NO_CLASS)
+ type = rtems_object_id_get_class(id);
+
+ id = rtems_build_id(
+ OBJECTS_CLASSIC_API,
+ type,
+ default_node,
+ rtems_object_id_get_index(id)
+ );
+ }
+ return id;
+}
+
+
+const rtems_monitor_object_info_t *
+rtems_monitor_object_lookup(
+ rtems_monitor_object_type_t type
+)
+{
+ const rtems_monitor_object_info_t *p;
+ for (p = &rtems_monitor_object_info[0];
+ p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)];
+ p++)
+ {
+ if (p->type == type)
+ return p;
+ }
+ return 0;
+}
+
+rtems_id
+rtems_monitor_object_canonical_next_remote(
+ rtems_monitor_object_type_t type,
+ rtems_id id,
+ void *canonical
+)
+{
+ rtems_id next_id;
+ rtems_status_code status;
+ rtems_monitor_server_request_t request;
+ rtems_monitor_server_response_t response;
+
+ /*
+ * Send request
+ */
+
+ request.command = RTEMS_MONITOR_SERVER_CANONICAL;
+ request.argument0 = (uint32_t) type;
+ request.argument1 = (uint32_t) id;
+
+ status = rtems_monitor_server_request(
+ rtems_object_id_get_node(id), &request, &response);
+ if (status != RTEMS_SUCCESSFUL)
+ goto failed;
+
+ /*
+ * process response
+ */
+
+ next_id = (rtems_id) response.result0;
+ if (next_id != RTEMS_OBJECT_ID_FINAL)
+ (void) memcpy(canonical, &response.payload, response.result1);
+
+ return next_id;
+
+failed:
+ return RTEMS_OBJECT_ID_FINAL;
+
+}
+
+
+rtems_id
+rtems_monitor_object_canonical_next(
+ const rtems_monitor_object_info_t *info,
+ rtems_id id,
+ void *canonical
+)
+{
+ rtems_id next_id;
+ void *raw_item;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( ! _Objects_Is_local_id(id) ) {
+ next_id = rtems_monitor_object_canonical_next_remote(
+ info->type,
+ id,
+ canonical
+ );
+ } else
+#endif
+ {
+ next_id = id;
+
+ raw_item = (void *) info->next(
+ info->object_information,
+ canonical,
+ &next_id
+ );
+
+ if (raw_item) {
+ info->canonical(canonical, raw_item);
+ _Thread_Enable_dispatch();
+ }
+ }
+ return next_id;
+}
+
+
+/*
+ * this is routine server invokes locally to get the type
+ */
+
+rtems_id
+rtems_monitor_object_canonical_get(
+ rtems_monitor_object_type_t type,
+ rtems_id id,
+ void *canonical,
+ size_t *size_p
+)
+{
+ const rtems_monitor_object_info_t *info;
+ rtems_id next_id;
+
+ *size_p = 0;
+
+ info = rtems_monitor_object_lookup(type);
+
+ if (info == 0)
+ return RTEMS_OBJECT_ID_FINAL;
+
+ next_id = rtems_monitor_object_canonical_next(info, id, canonical);
+ *size_p = info->size;
+
+ return next_id;
+}
+
+
+void
+rtems_monitor_object_dump_1(
+ const rtems_monitor_object_info_t *info,
+ rtems_id id,
+ bool verbose
+)
+{
+ rtems_id next_id;
+ rtems_monitor_union_t canonical;
+
+ if ((next_id = rtems_monitor_object_canonical_next(
+ info,
+ id,
+ &canonical)) != RTEMS_OBJECT_ID_FINAL)
+ {
+ /*
+ * If the one we actually got is the one we wanted, then
+ * print it out.
+ * For ones that have an id field, this works fine,
+ * for all others, always dump it out.
+ *
+ * HACK: the way we determine whether there is an id is a hack.
+ *
+ * by the way: the reason we try to not have an id, is that some
+ * of the canonical structures are almost too big for shared
+ * memory driver (eg: mpci)
+ */
+
+ if ((info->next != rtems_monitor_manager_next) ||
+ (id == canonical.generic.id))
+ info->dump(&canonical, verbose);
+ }
+}
+
+void
+rtems_monitor_object_dump_all(
+ const rtems_monitor_object_info_t *info,
+ bool verbose
+)
+{
+ rtems_id next_id;
+ rtems_monitor_union_t canonical;
+
+ next_id = RTEMS_OBJECT_ID_INITIAL(OBJECTS_CLASSIC_API, info->type, rtems_monitor_default_node);
+
+ while ((next_id = rtems_monitor_object_canonical_next(
+ info,
+ next_id,
+ &canonical)) != RTEMS_OBJECT_ID_FINAL)
+ {
+ info->dump(&canonical, verbose);
+ }
+}
+
+void
+rtems_monitor_object_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
+)
+{
+ int arg;
+ const rtems_monitor_object_info_t *info = 0;
+ rtems_monitor_object_type_t type;
+
+ /* what is the default type? */
+ type = command_arg->monitor_object;
+
+ if (argc == 1)
+ {
+ if (type == RTEMS_MONITOR_OBJECT_INVALID)
+ {
+ fprintf(stdout,"A type must be specified to \"dump all\"\n");
+ goto done;
+ }
+
+ info = rtems_monitor_object_lookup(type);
+ if (info == 0)
+ goto not_found;
+
+ if (info->dump_header)
+ info->dump_header(verbose);
+ rtems_monitor_object_dump_all(info, verbose);
+ }
+ else
+ {
+ uint32_t default_node = rtems_monitor_default_node;
+ rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID;
+ rtems_id id;
+
+ for (arg=1; argv[arg]; arg++)
+ {
+ id = (rtems_id) strtoul(argv[arg], 0, 16);
+ id = rtems_monitor_id_fixup(id, default_node, type);
+ type = (rtems_monitor_object_type_t) rtems_object_id_get_class(id);
+
+ /*
+ * Allow the item type to change in the middle
+ * of the command. If the type changes, then
+ * just dump out a new header and keep on going.
+ */
+ if (type != last_type)
+ {
+ info = rtems_monitor_object_lookup(type);
+ if (info == 0)
+ goto not_found;
+
+ if (info->dump_header)
+ info->dump_header(verbose);
+ }
+
+ if (info == 0)
+ {
+not_found: fprintf(stdout,"Invalid or unsupported type %d\n", type);
+ goto done;
+ }
+
+ rtems_monitor_object_dump_1(info, id, verbose);
+
+ default_node = rtems_object_id_get_node(id);
+
+ last_type = type;
+ }
+ }
+done:
+ return;
+}
diff --git a/cpukit/libmisc/monitor/mon-part.c b/cpukit/libmisc/monitor/mon-part.c
new file mode 100644
index 0000000000..72aff6921f
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-part.c
@@ -0,0 +1,72 @@
+/*
+ * RTEMS Monitor partition support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include "monitor.h"
+#include <rtems/rtems/attr.inl>
+#include <stdio.h>
+#include <string.h> /* memcpy() */
+
+void
+rtems_monitor_part_canonical(
+ rtems_monitor_part_t *canonical_part,
+ void *part_void
+)
+{
+ Partition_Control *rtems_part = (Partition_Control *) part_void;
+
+ canonical_part->attribute = rtems_part->attribute_set;
+ canonical_part->start_addr = rtems_part->starting_address;
+ canonical_part->length = rtems_part->length;
+ canonical_part->buf_size = rtems_part->buffer_size;
+ canonical_part->used_blocks = rtems_part->number_of_used_blocks;
+}
+
+
+void
+rtems_monitor_part_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ printf("\
+ ID NAME ATTR STARTADDR LENGTH BUF_SIZE USED_BLOCKS\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
+ 1 2 3 4 5 6 7 */
+
+ rtems_monitor_separator();
+}
+
+/*
+ */
+
+void
+rtems_monitor_part_dump(
+ rtems_monitor_part_t *monitor_part,
+ bool verbose __attribute__((unused))
+)
+{
+ int length = 0;
+
+ length += rtems_monitor_dump_id(monitor_part->id);
+ length += rtems_monitor_pad(11, length);
+ length += rtems_monitor_dump_name(monitor_part->id);
+ length += rtems_monitor_pad(18, length);
+ length += rtems_monitor_dump_attributes(monitor_part->attribute);
+ length += rtems_monitor_pad(30, length);
+ length += rtems_monitor_dump_addr(monitor_part->start_addr);
+ length += rtems_monitor_pad(40, length);
+ length += rtems_monitor_dump_hex(monitor_part->length);
+ length += rtems_monitor_pad(50, length);
+ length += rtems_monitor_dump_hex(monitor_part->buf_size);
+ length += rtems_monitor_pad(60, length);
+ length += rtems_monitor_dump_hex(monitor_part->used_blocks);
+ printf("\n");
+}
+
diff --git a/cpukit/libmisc/monitor/mon-prmisc.c b/cpukit/libmisc/monitor/mon-prmisc.c
new file mode 100644
index 0000000000..32ee6711b4
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-prmisc.c
@@ -0,0 +1,259 @@
+/*
+ * Print misc stuff for the monitor dump routines
+ * Each routine returns the number of characters it output.
+ *
+ * TODO:
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <rtems/assoc.h>
+
+#include <stdio.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+void
+rtems_monitor_separator(void)
+{
+ fprintf(stdout,"------------------------------------------------------------------------------\n");
+}
+
+uint32_t
+rtems_monitor_pad(
+ uint32_t destination_column,
+ uint32_t current_column
+)
+{
+ int pad_length;
+
+ if (destination_column <= current_column)
+ pad_length = 1;
+ else
+ pad_length = destination_column - current_column;
+
+ return fprintf(stdout,"%*s", pad_length, "");
+}
+
+int
+rtems_monitor_dump_decimal(uint32_t num)
+{
+ return fprintf(stdout,"%4" PRId32, num);
+}
+
+int
+rtems_monitor_dump_addr(void *addr)
+{
+ return fprintf(stdout,"0x%p", addr);
+}
+
+int
+rtems_monitor_dump_hex(uint32_t num)
+{
+ return fprintf(stdout,"0x%" PRIx32, num);
+}
+
+int
+rtems_monitor_dump_assoc_bitfield(
+ const rtems_assoc_t *ap,
+ const char *separator,
+ uint32_t value
+ )
+{
+ uint32_t b;
+ uint32_t length = 0;
+ const char *name;
+
+ for (b = 1; b; b <<= 1)
+ if (b & value)
+ {
+ if (length)
+ length += fprintf(stdout,"%s", separator);
+
+ name = rtems_assoc_name_by_local(ap, b);
+
+ if (name)
+ length += fprintf(stdout,"%s", name);
+ else
+ length += fprintf(stdout,"0x%" PRIx32, b);
+ }
+
+ return length;
+}
+
+int
+rtems_monitor_dump_id(rtems_id id)
+{
+#if defined(RTEMS_USE_16_BIT_OBJECT)
+ return fprintf(stdout,"%08" PRIx16, id);
+#else
+ return fprintf(stdout,"%08" PRIx32, id);
+#endif
+}
+
+int
+rtems_monitor_dump_name(rtems_id id)
+{
+ char name_buffer[18] = "????";
+
+ rtems_object_get_name( id, sizeof(name_buffer), name_buffer );
+
+ return fprintf( stdout, name_buffer );
+}
+
+int
+rtems_monitor_dump_priority(rtems_task_priority priority)
+{
+ return fprintf(stdout,"%3" PRId32, priority);
+}
+
+
+static const rtems_assoc_t rtems_monitor_state_assoc[] = {
+ { "DORM", STATES_DORMANT, 0 },
+ { "SUSP", STATES_SUSPENDED, 0 },
+ { "TRANS", STATES_TRANSIENT, 0 },
+ { "DELAY", STATES_DELAYING, 0 },
+ { "Wtime", STATES_WAITING_FOR_TIME, 0 },
+ { "Wbuf", STATES_WAITING_FOR_BUFFER, 0 },
+ { "Wseg", STATES_WAITING_FOR_SEGMENT, 0 },
+ { "Wmsg" , STATES_WAITING_FOR_MESSAGE, 0 },
+ { "Wevnt", STATES_WAITING_FOR_EVENT, 0 },
+ { "Wsem", STATES_WAITING_FOR_SEMAPHORE, 0 },
+ { "Wmutex", STATES_WAITING_FOR_MUTEX, 0 },
+ { "Wcvar", STATES_WAITING_FOR_CONDITION_VARIABLE, 0 },
+ { "Wjatx", STATES_WAITING_FOR_JOIN_AT_EXIT, 0 },
+ { "Wrpc", STATES_WAITING_FOR_RPC_REPLY, 0 },
+ { "WRATE", STATES_WAITING_FOR_PERIOD, 0 },
+ { "Wsig", STATES_WAITING_FOR_SIGNAL, 0 },
+ { "Wbar", STATES_WAITING_FOR_BARRIER, 0 },
+ { "Wrwlk", STATES_WAITING_FOR_RWLOCK, 0 },
+ { "Wisig", STATES_INTERRUPTIBLE_BY_SIGNAL, 0 },
+ { 0, 0, 0 },
+};
+
+int
+rtems_monitor_dump_state(States_Control state)
+{
+ int length = 0;
+
+ if (state == STATES_READY) /* assoc doesn't deal with this as it is 0 */
+ length += fprintf(stdout,"READY");
+
+ length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_state_assoc,
+ ":",
+ state);
+ return length;
+}
+
+static const rtems_assoc_t rtems_monitor_attribute_assoc[] = {
+ { "GL", RTEMS_GLOBAL, 0 },
+ { "PR", RTEMS_PRIORITY, 0 },
+ { "FL", RTEMS_FLOATING_POINT, 0 },
+ { "BI", RTEMS_BINARY_SEMAPHORE, 0 },
+ { "SB", RTEMS_SIMPLE_BINARY_SEMAPHORE, 0 },
+ { "IN", RTEMS_INHERIT_PRIORITY, 0 },
+ { "CE", RTEMS_PRIORITY_CEILING, 0 },
+ { "AR", RTEMS_BARRIER_AUTOMATIC_RELEASE, 0 },
+ { "ST", RTEMS_SYSTEM_TASK, 0 },
+ { 0, 0, 0 },
+};
+
+int
+rtems_monitor_dump_attributes(rtems_attribute attributes)
+{
+ int length = 0;
+
+ if (attributes == RTEMS_DEFAULT_ATTRIBUTES) /* value is 0 */
+ length += fprintf(stdout,"DEFAULT");
+
+ length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_attribute_assoc,
+ ":",
+ attributes);
+ return length;
+}
+
+static const rtems_assoc_t rtems_monitor_modes_assoc[] = {
+ { "nP", RTEMS_NO_PREEMPT, 0 },
+ { "T", RTEMS_TIMESLICE, 0 },
+ { "nA", RTEMS_NO_ASR, 0 },
+ { 0, 0, 0 },
+};
+
+int
+rtems_monitor_dump_modes(rtems_mode modes)
+{
+ uint32_t length = 0;
+
+ if (modes == RTEMS_DEFAULT_MODES) /* value is 0 */
+ length += fprintf(stdout,"P:T:nA");
+
+ length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_modes_assoc,
+ ":",
+ modes);
+ return length;
+}
+
+static const rtems_assoc_t rtems_monitor_events_assoc[] = {
+ { "0", RTEMS_EVENT_0, 0 },
+ { "1", RTEMS_EVENT_1, 0 },
+ { "2", RTEMS_EVENT_2, 0 },
+ { "3", RTEMS_EVENT_3, 0 },
+ { "4", RTEMS_EVENT_4, 0 },
+ { "5", RTEMS_EVENT_5, 0 },
+ { "6", RTEMS_EVENT_6, 0 },
+ { "7", RTEMS_EVENT_7, 0 },
+ { "8", RTEMS_EVENT_8, 0 },
+ { "9", RTEMS_EVENT_9, 0 },
+ { "10", RTEMS_EVENT_10, 0 },
+ { "11", RTEMS_EVENT_11, 0 },
+ { "12", RTEMS_EVENT_12, 0 },
+ { "13", RTEMS_EVENT_13, 0 },
+ { "14", RTEMS_EVENT_14, 0 },
+ { "15", RTEMS_EVENT_15, 0 },
+ { "16", RTEMS_EVENT_16, 0 },
+ { "17", RTEMS_EVENT_17, 0 },
+ { "18", RTEMS_EVENT_18, 0 },
+ { "19", RTEMS_EVENT_19, 0 },
+ { "20", RTEMS_EVENT_20, 0 },
+ { "21", RTEMS_EVENT_21, 0 },
+ { "22", RTEMS_EVENT_22, 0 },
+ { "23", RTEMS_EVENT_23, 0 },
+ { "24", RTEMS_EVENT_24, 0 },
+ { "25", RTEMS_EVENT_25, 0 },
+ { "26", RTEMS_EVENT_26, 0 },
+ { "27", RTEMS_EVENT_27, 0 },
+ { "28", RTEMS_EVENT_28, 0 },
+ { "29", RTEMS_EVENT_29, 0 },
+ { "30", RTEMS_EVENT_30, 0 },
+ { "31", RTEMS_EVENT_31, 0 },
+ { 0, 0, 0 },
+};
+
+int
+rtems_monitor_dump_events(rtems_event_set events)
+{
+ if (events == EVENT_SETS_NONE_PENDING) /* value is 0 */
+ return fprintf(stdout," NONE ");
+
+ return fprintf(stdout,"%08" PRIx32, events);
+}
+
+int
+rtems_monitor_dump_notepad(uint32_t *notepad)
+{
+ int length = 0;
+ int i;
+
+ for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
+ if (notepad[i])
+ length += fprintf(stdout,"%d: 0x%" PRIx32, i, notepad[i]);
+
+ return length;
+}
diff --git a/cpukit/libmisc/monitor/mon-queue.c b/cpukit/libmisc/monitor/mon-queue.c
new file mode 100644
index 0000000000..4237b01780
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-queue.c
@@ -0,0 +1,68 @@
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+
+void
+rtems_monitor_queue_canonical(
+ rtems_monitor_queue_t *canonical_queue,
+ void *queue_void
+)
+{
+ Message_queue_Control *rtems_queue = (Message_queue_Control *) queue_void;
+
+ canonical_queue->attributes = rtems_queue->attribute_set;
+ canonical_queue->maximum_message_size = rtems_queue->message_queue.maximum_message_size;
+ canonical_queue->maximum_pending_messages = rtems_queue->message_queue.maximum_pending_messages;
+ canonical_queue->number_of_pending_messages = rtems_queue->message_queue.number_of_pending_messages;
+}
+
+void
+rtems_monitor_queue_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ fprintf(stdout,"\
+ ID NAME ATTRIBUTES PEND MAXPEND MAXSIZE\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+ rtems_monitor_separator();
+}
+
+
+/*
+ * Dump out the "next" queue indicated by 'id'.
+ * Returns next one to check.
+ * Returns RTEMS_OBJECT_ID_FINAL when all done
+ */
+
+void
+rtems_monitor_queue_dump(
+ rtems_monitor_queue_t *monitor_queue,
+ bool verbose __attribute__((unused))
+)
+{
+ uint32_t length = 0;
+
+ length += rtems_monitor_dump_id(monitor_queue->id);
+ length += rtems_monitor_pad(11, length);
+ length += rtems_monitor_dump_name(monitor_queue->id);
+ length += rtems_monitor_pad(19, length);
+ length += rtems_monitor_dump_attributes(monitor_queue->attributes);
+ length += rtems_monitor_pad(31, length);
+ length += rtems_monitor_dump_decimal(monitor_queue->number_of_pending_messages);
+ length += rtems_monitor_pad(39, length);
+ length += rtems_monitor_dump_decimal(monitor_queue->maximum_pending_messages);
+ length += rtems_monitor_pad(48, length);
+ length += rtems_monitor_dump_decimal(monitor_queue->maximum_message_size);
+
+ fprintf(stdout,"\n");
+}
diff --git a/cpukit/libmisc/monitor/mon-region.c b/cpukit/libmisc/monitor/mon-region.c
new file mode 100644
index 0000000000..271cbf82f4
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-region.c
@@ -0,0 +1,73 @@
+/*
+ * RTEMS Monitor region support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include "monitor.h"
+#include <rtems/rtems/attr.inl>
+#include <stdio.h>
+#include <string.h> /* memcpy() */
+
+void
+rtems_monitor_region_canonical(
+ rtems_monitor_region_t *canonical_region,
+ void *region_void
+)
+{
+ Region_Control *rtems_region = (Region_Control *) region_void;
+
+ canonical_region->attribute = rtems_region->attribute_set;
+ canonical_region->start_addr = rtems_region->starting_address;
+ canonical_region->length = rtems_region->length;
+ canonical_region->page_size = rtems_region->page_size;
+ canonical_region->max_seg_size = rtems_region->maximum_segment_size;
+ canonical_region->used_blocks = rtems_region->number_of_used_blocks;
+}
+
+
+void
+rtems_monitor_region_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ printf("\
+ ID NAME ATTR STARTADDR LENGTH PAGE_SIZE USED_BLOCKS\n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
+ 1 2 3 4 5 6 7 */
+
+ rtems_monitor_separator();
+}
+
+/*
+ */
+
+void
+rtems_monitor_region_dump(
+ rtems_monitor_region_t *monitor_region,
+ bool verbose __attribute__((unused))
+)
+{
+ int length = 0;
+
+ length += rtems_monitor_dump_id(monitor_region->id);
+ length += rtems_monitor_pad(11, length);
+ length += rtems_monitor_dump_name(monitor_region->id);
+ length += rtems_monitor_pad(18, length);
+ length += rtems_monitor_dump_attributes(monitor_region->attribute);
+ length += rtems_monitor_pad(30, length);
+ length += rtems_monitor_dump_addr(monitor_region->start_addr);
+ length += rtems_monitor_pad(40, length);
+ length += rtems_monitor_dump_hex(monitor_region->length);
+ length += rtems_monitor_pad(50, length);
+ length += rtems_monitor_dump_hex(monitor_region->page_size);
+ length += rtems_monitor_pad(60, length);
+ length += rtems_monitor_dump_hex(monitor_region->used_blocks);
+ printf("\n");
+}
+
diff --git a/cpukit/libmisc/monitor/mon-sema.c b/cpukit/libmisc/monitor/mon-sema.c
new file mode 100644
index 0000000000..276601c04c
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-sema.c
@@ -0,0 +1,84 @@
+/*
+ * RTEMS Monitor semaphore support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include "monitor.h"
+#include <rtems/rtems/attr.inl>
+#include <stdio.h>
+#include <string.h> /* memcpy() */
+
+void
+rtems_monitor_sema_canonical(
+ rtems_monitor_sema_t *canonical_sema,
+ void *sema_void
+)
+{
+ Semaphore_Control *rtems_sema = (Semaphore_Control *) sema_void;
+
+ canonical_sema->attribute = rtems_sema->attribute_set;
+ canonical_sema->priority_ceiling =
+ rtems_sema->Core_control.mutex.Attributes.priority_ceiling;
+
+ canonical_sema->holder_id =
+ rtems_sema->Core_control.mutex.holder_id;
+
+ if (_Attributes_Is_counting_semaphore(canonical_sema->attribute)) {
+ /* we have a counting semaphore */
+ canonical_sema->cur_count =
+ rtems_sema->Core_control.semaphore.count;
+
+ canonical_sema->max_count =
+ rtems_sema->Core_control.semaphore.Attributes.maximum_count;
+ }
+ else {
+ /* we have a binary semaphore (mutex) */
+ canonical_sema->cur_count = rtems_sema->Core_control.mutex.lock;
+ canonical_sema->max_count = 1; /* mutex is either 0 or 1 */
+ }
+}
+
+
+void
+rtems_monitor_sema_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ printf("\
+ ID NAME ATTR PRICEIL CURR_CNT HOLDID \n");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
+ 1 2 3 4 5 6 7 */
+
+ rtems_monitor_separator();
+}
+
+/*
+ */
+
+void
+rtems_monitor_sema_dump(
+ rtems_monitor_sema_t *monitor_sema,
+ bool verbose __attribute__((unused))
+)
+{
+ int length = 0;
+
+ length += rtems_monitor_dump_id(monitor_sema->id);
+ length += rtems_monitor_pad(11, length);
+ length += rtems_monitor_dump_name(monitor_sema->id);
+ length += rtems_monitor_pad(18, length);
+ length += rtems_monitor_dump_attributes(monitor_sema->attribute);
+ length += rtems_monitor_pad(30, length);
+ length += rtems_monitor_dump_priority(monitor_sema->priority_ceiling);
+ length += rtems_monitor_pad(38, length);
+ length += rtems_monitor_dump_decimal(monitor_sema->cur_count);
+ length += rtems_monitor_pad(47, length);
+ length += rtems_monitor_dump_id(monitor_sema->holder_id);
+ printf("\n");
+}
diff --git a/cpukit/libmisc/monitor/mon-server.c b/cpukit/libmisc/monitor/mon-server.c
new file mode 100644
index 0000000000..03bc1932b2
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-server.c
@@ -0,0 +1,309 @@
+/*
+ * RTEMS monitor server (handles requests for info from RTEMS monitors
+ * running on other nodes)
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <rtems/monitor.h>
+
+/*
+ * Various id's for the server
+ */
+
+rtems_id rtems_monitor_server_task_id;
+rtems_id rtems_monitor_server_request_queue_id; /* our server */
+rtems_id *rtems_monitor_server_request_queue_ids; /* all servers */
+rtems_id rtems_monitor_server_response_queue_id; /* our server */
+
+
+/*
+ * Send a request to a server task
+ */
+
+rtems_status_code
+rtems_monitor_server_request(
+ uint32_t server_node,
+ rtems_monitor_server_request_t *request,
+ rtems_monitor_server_response_t *response
+)
+{
+ rtems_id server_id;
+ rtems_status_code status;
+ size_t size;
+
+ /*
+ * What is id of monitor on target node?
+ * Look it up if we don't know it yet.
+ */
+
+ server_id = rtems_monitor_server_request_queue_ids[server_node];
+ if (server_id == 0)
+ {
+ status = rtems_message_queue_ident(RTEMS_MONITOR_QUEUE_NAME,
+ server_node,
+ &server_id);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "ident of remote server failed");
+ goto done;
+ }
+
+ rtems_monitor_server_request_queue_ids[server_node] = server_id;
+ }
+
+ request->return_id = rtems_monitor_server_response_queue_id;
+
+ status = rtems_message_queue_send(server_id, request, sizeof(*request));
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "monitor server request send failed");
+ goto done;
+ }
+
+ /*
+ * Await response, if requested
+ */
+
+ if (response)
+ {
+ status = rtems_message_queue_receive(rtems_monitor_server_response_queue_id,
+ response,
+ &size,
+ RTEMS_WAIT,
+ 100);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "server did not respond");
+
+ /* maybe server task was restarted; look it up again next time */
+ rtems_monitor_server_request_queue_ids[server_node] = 0;
+
+ goto done;
+ }
+
+ if (response->command != RTEMS_MONITOR_SERVER_RESPONSE)
+ {
+ status = RTEMS_INCORRECT_STATE;
+ goto done;
+ }
+ }
+
+done:
+ return status;
+}
+
+
+
+/*
+ * monitor server task
+ */
+
+void
+rtems_monitor_server_task(
+ rtems_task_argument monitor_flags __attribute__((unused))
+)
+{
+ rtems_monitor_server_request_t request;
+ rtems_monitor_server_response_t response;
+ rtems_status_code status;
+ size_t size;
+
+ for (;;)
+ {
+ status = rtems_message_queue_receive(
+ rtems_monitor_server_request_queue_id,
+ &request,
+ &size,
+ RTEMS_WAIT,
+ (rtems_interval) 0);
+
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "monitor server msg queue receive error");
+ goto failed;
+ }
+
+ if (size != sizeof(request))
+ {
+ rtems_error(0, "monitor server bad size on receive");
+ goto failed;
+ }
+
+ switch (request.command)
+ {
+ case RTEMS_MONITOR_SERVER_CANONICAL:
+ {
+ rtems_monitor_object_type_t object_type;
+ rtems_id id;
+ rtems_id next_id;
+
+ object_type = (rtems_monitor_object_type_t) request.argument0;
+ id = (rtems_id) request.argument1;
+ next_id = rtems_monitor_object_canonical_get(object_type,
+ id,
+ &response.payload,
+ &size);
+
+ response.command = RTEMS_MONITOR_SERVER_RESPONSE;
+ response.result0 = next_id;
+ response.result1 = size;
+
+#define SERVER_OVERHEAD (RTEMS_offsetof(rtems_monitor_server_response_t, \
+ payload))
+
+ status = rtems_message_queue_send(request.return_id,
+ &response,
+ size + SERVER_OVERHEAD);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "response send failed");
+ goto failed;
+ }
+ break;
+ }
+
+ default:
+ {
+ rtems_error(0, "invalid command to monitor server: %d", request.command);
+ goto failed;
+ }
+ }
+ }
+
+failed:
+ rtems_task_delete(RTEMS_SELF);
+}
+
+
+/*
+ * Kill off any old server
+ * Not sure if this is useful, but it doesn't help
+ */
+
+void
+rtems_monitor_server_kill(void)
+{
+ if (rtems_monitor_server_task_id)
+ rtems_task_delete(rtems_monitor_server_task_id);
+ rtems_monitor_server_task_id = 0;
+
+ if (rtems_monitor_server_request_queue_id)
+ rtems_message_queue_delete(rtems_monitor_server_request_queue_id);
+ rtems_monitor_server_request_queue_ids = 0;
+
+ if (rtems_monitor_server_response_queue_id)
+ rtems_message_queue_delete(rtems_monitor_server_response_queue_id);
+ rtems_monitor_server_response_queue_id = 0;
+
+ if (rtems_monitor_server_request_queue_ids)
+ free(rtems_monitor_server_request_queue_ids);
+ rtems_monitor_server_request_queue_ids = 0;
+}
+
+
+void
+rtems_monitor_server_init(
+ uint32_t monitor_flags __attribute__((unused))
+)
+{
+ #if defined(RTEMS_MULTIPROCESSING)
+ rtems_status_code status;
+
+ if (_System_state_Is_multiprocessing &&
+ (_Configuration_MP_table->maximum_nodes > 1))
+ {
+ uint32_t maximum_nodes = _Configuration_MP_table->maximum_nodes;
+
+ /*
+ * create the msg que our server will listen
+ * Since we only get msgs from other RTEMS monitors, we just
+ * need reserve space for 1 msg from each node.
+ */
+
+ status = rtems_message_queue_create(
+ RTEMS_MONITOR_QUEUE_NAME,
+ maximum_nodes,
+ sizeof(rtems_monitor_server_request_t),
+ RTEMS_GLOBAL,
+ &rtems_monitor_server_request_queue_id);
+
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "could not create monitor server message queue");
+ goto done;
+ }
+
+ /*
+ * create the msg que our responses will come on
+ * Since monitor just does one thing at a time, we only need 1 item
+ * message queue.
+ */
+
+ status = rtems_message_queue_create(
+ RTEMS_MONITOR_RESPONSE_QUEUE_NAME,
+ 1, /* depth */
+ sizeof(rtems_monitor_server_response_t),
+ RTEMS_GLOBAL,
+ &rtems_monitor_server_response_queue_id);
+
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "could not create monitor response message queue");
+ goto done;
+ }
+
+ /* need an id for queue of each other server we might talk to */
+ /* indexed by node, so add 1 to maximum_nodes */
+ rtems_monitor_server_request_queue_ids =
+ (rtems_id *) malloc((maximum_nodes + 1) * sizeof(rtems_id));
+ (void) memset(rtems_monitor_server_request_queue_ids,
+ 0,
+ (maximum_nodes + 1) * sizeof(rtems_id));
+
+ rtems_monitor_server_request_queue_ids[rtems_monitor_node] =
+ rtems_monitor_server_request_queue_id;
+
+ /*
+ * create the server task
+ */
+ status = rtems_task_create(RTEMS_MONITOR_SERVER_NAME,
+ 1,
+ 0 /* default stack */,
+ RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &rtems_monitor_server_task_id);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "could not create monitor server task");
+ goto done;
+ }
+
+ /*
+ * Start the server task
+ */
+ status = rtems_task_start(rtems_monitor_server_task_id,
+ rtems_monitor_server_task,
+ monitor_flags);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "could not start monitor server");
+ goto done;
+ }
+ }
+
+done:
+ #endif
+ return;
+}
diff --git a/cpukit/libmisc/monitor/mon-symbols.c b/cpukit/libmisc/monitor/mon-symbols.c
new file mode 100644
index 0000000000..38a5716c6f
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-symbols.c
@@ -0,0 +1,490 @@
+/*
+ * File: symbols.c
+ *
+ * Description:
+ * Symbol table manager for the RTEMS monitor.
+ * These routines may be used by other system resources also.
+ *
+ *
+ * TODO:
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include <rtems/monitor.h>
+#include "symbols.h"
+
+
+rtems_symbol_table_t *
+rtems_symbol_table_create(void)
+{
+ rtems_symbol_table_t *table;
+
+ table = (rtems_symbol_table_t *) malloc(sizeof(rtems_symbol_table_t));
+ memset((void *) table, 0, sizeof(*table));
+
+ table->growth_factor = 30; /* 30 percent */
+
+ return table;
+}
+
+void
+rtems_symbol_table_destroy(rtems_symbol_table_t *table)
+{
+ rtems_symbol_string_block_t *p, *pnext;
+
+ if (table)
+ {
+ if (table->addresses)
+ (void) free(table->addresses);
+ table->addresses = 0;
+ p = table->string_buffer_head;
+ while (p)
+ {
+ pnext = p->next;
+ free(p);
+ p = pnext;
+ }
+ table->string_buffer_head = 0;
+ table->string_buffer_current = 0;
+
+ free(table);
+ }
+}
+
+rtems_symbol_t *
+rtems_symbol_create(
+ rtems_symbol_table_t *table,
+ const char *name,
+ uint32_t value
+ )
+{
+ size_t symbol_length;
+ size_t newsize;
+ rtems_symbol_t *sp;
+
+ symbol_length = strlen(name) + 1; /* include '\000' in length */
+
+ /* need to grow the table? */
+ if (table->next >= table->size)
+ {
+ if (table->size == 0)
+ newsize = 100;
+ else
+ newsize = table->size + (table->size / (100 / table->growth_factor));
+
+ table->addresses = (rtems_symbol_t *) realloc((void *) table->addresses, newsize * sizeof(rtems_symbol_t));
+ if (table->addresses == 0) /* blew it; lost orig */
+ goto failed;
+ table->size = newsize;
+ }
+
+ sp = &table->addresses[table->next];
+ sp->value = value;
+
+ /* Have to add it to string pool */
+ /* need to grow pool? */
+
+ if ((table->string_buffer_head == 0) ||
+ (table->strings_next + symbol_length) >= SYMBOL_STRING_BLOCK_SIZE)
+ {
+ rtems_symbol_string_block_t *p;
+
+ p = (rtems_symbol_string_block_t *) malloc(sizeof(rtems_symbol_string_block_t));
+ if (p == 0)
+ goto failed;
+ p->next = 0;
+ if (table->string_buffer_head == 0)
+ table->string_buffer_head = p;
+ else
+ table->string_buffer_current->next = p;
+ table->string_buffer_current = p;
+
+ table->strings_next = 0;
+ }
+
+ sp->name = table->string_buffer_current->buffer + table->strings_next;
+ (void) strcpy(sp->name, name);
+
+ table->strings_next += symbol_length;
+ table->sorted = 0;
+ table->next++;
+
+ return sp;
+
+/* XXX Not sure what to do here. We've possibly destroyed the initial
+ symbol table due to realloc failure */
+failed:
+ return 0;
+}
+
+/*
+ * Qsort entry point for compare by address
+ */
+
+static int
+rtems_symbol_compare(const void *e1,
+ const void *e2)
+{
+ rtems_symbol_t *s1, *s2;
+ s1 = (rtems_symbol_t *) e1;
+ s2 = (rtems_symbol_t *) e2;
+
+ if (s1->value < s2->value)
+ return -1;
+ if (s1->value > s2->value)
+ return 1;
+ return 0;
+}
+
+
+/*
+ * Sort the symbol table using qsort
+ */
+
+static void
+rtems_symbol_sort(rtems_symbol_table_t *table)
+{
+ qsort((void *) table->addresses, (size_t) table->next,
+ sizeof(rtems_symbol_t), rtems_symbol_compare);
+ table->sorted = 1;
+}
+
+
+/*
+ * Search the symbol table by address
+ * This code based on CYGNUS newlib bsearch, but changed
+ * to allow for finding closest symbol <= key
+ */
+
+rtems_symbol_t *
+rtems_symbol_value_lookup(
+ rtems_symbol_table_t *table,
+ uint32_t value
+ )
+{
+ rtems_symbol_t *sp;
+ rtems_symbol_t *base;
+ rtems_symbol_t *best = 0;
+ uint32_t distance;
+ uint32_t best_distance = ~0;
+ uint32_t elements;
+
+ if (table == 0)
+ table = rtems_monitor_symbols;
+
+ if ((table == 0) || (table->size == 0))
+ return 0;
+
+ if (table->sorted == 0)
+ rtems_symbol_sort(table);
+
+ base = table->addresses;
+ elements = table->next;
+
+ while (elements)
+ {
+ sp = base + (elements / 2);
+ if (value < sp->value)
+ elements /= 2;
+ else if (value > sp->value)
+ {
+ distance = value - sp->value;
+ if (distance < best_distance)
+ {
+ best_distance = distance;
+ best = sp;
+ }
+ base = sp + 1;
+ elements = (elements / 2) - (elements % 2 ? 0 : 1);
+ }
+ else
+ return sp;
+ }
+
+ if (value == base->value)
+ return base;
+
+ return best;
+}
+
+/*
+ * Search the symbol table for the exact matching address.
+ * If the symbol table has already been sorted, then
+ * call the regular symbol value lookup, however, it it
+ * has not yet been sorted, search it sequentially.
+ * This routine is primarily used for low level symbol
+ * lookups (eg. from exception handler and interrupt routines)
+ * where the penality of sorted is not wanted and where
+ * an exact match is needed such that symbol table order
+ * is not important.
+ */
+const rtems_symbol_t *
+rtems_symbol_value_lookup_exact(
+ rtems_symbol_table_t *table,
+ uint32_t value
+ )
+{
+ uint32_t s;
+ rtems_symbol_t *sp;
+
+ if (table == 0)
+ {
+ table = rtems_monitor_symbols;
+ if (table == 0)
+ return NULL;
+ }
+
+ if (table->sorted)
+ {
+ sp = rtems_symbol_value_lookup(table, value);
+ if ( rtems_symbol_value(sp) == value )
+ return sp;
+ else
+ return NULL; /* not an exact match */
+ }
+
+ for (s = 0, sp = table->addresses; s < table->next; s++, sp++)
+ {
+ if ( sp->value == value )
+ return sp;
+ }
+
+ return NULL;
+
+}
+
+
+/*
+ * Search the symbol table by string name (case independent)
+ */
+
+rtems_symbol_t *
+rtems_symbol_name_lookup(
+ rtems_symbol_table_t *table,
+ const char *name
+ )
+{
+ uint32_t s;
+ rtems_symbol_t *sp;
+
+ if (table == 0)
+ {
+ table = rtems_monitor_symbols;
+ if (table == 0)
+ return NULL;
+ }
+
+ for (s = 0, sp = table->addresses; s < table->next; s++, sp++)
+ {
+ if ( strcasecmp(sp->name, name) == 0 )
+ return sp;
+ }
+
+ return NULL;
+}
+
+void *
+rtems_monitor_symbol_next(
+ void *object_info,
+ rtems_monitor_symbol_t *canonical __attribute__((unused)),
+ rtems_id *next_id
+)
+{
+ rtems_symbol_table_t *table;
+ uint32_t n = rtems_object_id_get_index(*next_id);
+
+ table = *(rtems_symbol_table_t **) object_info;
+ if (table == 0)
+ goto failed;
+
+ if (n >= table->next)
+ goto failed;
+
+ /* NOTE: symbols do not have id and name fields */
+
+ if (table->sorted == 0)
+ rtems_symbol_sort(table);
+
+ _Thread_Disable_dispatch();
+
+ *next_id += 1;
+ return (void *) (table->addresses + n);
+
+failed:
+ *next_id = RTEMS_OBJECT_ID_FINAL;
+ return 0;
+}
+
+void
+rtems_monitor_symbol_canonical(
+ rtems_monitor_symbol_t *canonical_symbol,
+ rtems_symbol_t *sp
+)
+{
+ canonical_symbol->value = sp->value;
+ canonical_symbol->offset = 0;
+ strncpy(canonical_symbol->name, sp->name, sizeof(canonical_symbol->name)-1);
+}
+
+
+void
+rtems_monitor_symbol_canonical_by_name(
+ rtems_monitor_symbol_t *canonical_symbol,
+ const char *name
+)
+{
+ rtems_symbol_t *sp;
+
+ sp = rtems_symbol_name_lookup(0, name);
+
+ canonical_symbol->value = sp ? sp->value : 0;
+
+ strncpy(canonical_symbol->name, name, sizeof(canonical_symbol->name) - 1);
+ canonical_symbol->offset = 0;
+}
+
+void
+rtems_monitor_symbol_canonical_by_value(
+ rtems_monitor_symbol_t *canonical_symbol,
+ void *value_void_p
+)
+{
+ uintptr_t value = (uintptr_t) value_void_p;
+ rtems_symbol_t *sp;
+
+ sp = rtems_symbol_value_lookup(0, value);
+ if (sp)
+ {
+ canonical_symbol->value = sp->value;
+ canonical_symbol->offset = value - sp->value;
+ strncpy(canonical_symbol->name, sp->name, sizeof(canonical_symbol->name)-1);
+ }
+ else
+ {
+ canonical_symbol->value = value;
+ canonical_symbol->offset = 0;
+ canonical_symbol->name[0] = '\0';
+ }
+}
+
+
+uint32_t
+rtems_monitor_symbol_dump(
+ rtems_monitor_symbol_t *canonical_symbol,
+ bool verbose
+)
+{
+ uint32_t length = 0;
+
+ /*
+ * print the name if it exists AND if value is non-zero
+ * Ie: don't print some garbage symbol for address 0
+ */
+
+ if (canonical_symbol->name[0] && (canonical_symbol->value != 0))
+ {
+ if (canonical_symbol->offset == 0)
+ length += fprintf(stdout,"%.*s",
+ (int) sizeof(canonical_symbol->name),
+ canonical_symbol->name);
+ else
+ length += fprintf(stdout,"<%.*s+0x%" PRIx32 ">",
+ (int) sizeof(canonical_symbol->name),
+ canonical_symbol->name,
+ canonical_symbol->offset);
+ if (verbose)
+ length += fprintf(stdout,
+ " [0x%" PRIx32 "]", canonical_symbol->value);
+ }
+ else
+ length += fprintf(stdout,"[0x%" PRIx32 "]", canonical_symbol->value);
+
+ return length;
+}
+
+
+void
+rtems_monitor_symbol_dump_all(
+ rtems_symbol_table_t *table,
+ bool verbose __attribute__((unused))
+)
+{
+ uint32_t s;
+ rtems_symbol_t *sp;
+
+ if (table == 0)
+ {
+ table = rtems_monitor_symbols;
+ if (table == 0)
+ return;
+ }
+
+ if (table->sorted == 0)
+ rtems_symbol_sort(table);
+
+ for (s = 0, sp = table->addresses; s < table->next; s++, sp++)
+ {
+ rtems_monitor_symbol_t canonical_symbol;
+
+ rtems_monitor_symbol_canonical(&canonical_symbol, sp);
+ rtems_monitor_symbol_dump(&canonical_symbol, true);
+ fprintf(stdout,"\n");
+ }
+}
+
+
+/*
+ * 'symbol' command
+ */
+
+void rtems_monitor_symbol_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
+)
+{
+ int arg;
+ rtems_symbol_table_t *table;
+
+ table = *command_arg->symbol_table;
+ if (table == 0)
+ {
+ table = rtems_monitor_symbols;
+ if (table == 0)
+ return;
+ }
+
+ /*
+ * Use object command to dump out whole symbol table
+ */
+ if (argc == 1)
+ rtems_monitor_symbol_dump_all(table, verbose);
+ else
+ {
+ rtems_monitor_symbol_t canonical_symbol;
+
+ for (arg=1; argv[arg]; arg++)
+ {
+ rtems_monitor_symbol_canonical_by_name(&canonical_symbol, argv[arg]);
+ rtems_monitor_symbol_dump(&canonical_symbol, verbose);
+ fprintf(stdout,"\n");
+ }
+ }
+}
diff --git a/cpukit/libmisc/monitor/mon-task.c b/cpukit/libmisc/monitor/mon-task.c
new file mode 100644
index 0000000000..6007b3f879
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-task.c
@@ -0,0 +1,105 @@
+/*
+ * RTEMS Monitor task support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+#include <string.h> /* memcpy() */
+
+void
+rtems_monitor_task_canonical(
+ rtems_monitor_task_t *canonical_task,
+ void *thread_void
+)
+{
+ Thread_Control *rtems_thread = (Thread_Control *) thread_void;
+ RTEMS_API_Control *api;
+
+ api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ];
+
+ canonical_task->entry = rtems_thread->Start.entry_point;
+ canonical_task->argument = rtems_thread->Start.numeric_argument;
+ canonical_task->stack = rtems_thread->Start.Initial_stack.area;
+ canonical_task->stack_size = rtems_thread->Start.Initial_stack.size;
+ canonical_task->priority = rtems_thread->current_priority;
+ canonical_task->state = rtems_thread->current_state;
+ canonical_task->wait_id = rtems_thread->Wait.id;
+ canonical_task->events = api->pending_events;
+ /*
+ * FIXME: make this optionally cpu_time_executed
+ */
+#if 0
+ canonical_task->ticks = rtems_thread->cpu_time_executed;
+#else
+ canonical_task->ticks = 0;
+#endif
+
+/* XXX modes and attributes only exist in the RTEMS API .. */
+/* XXX not directly in the core thread.. they will have to be derived */
+/* XXX if they are important enough to include anymore. */
+ canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */
+ canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */;
+ (void) memcpy(canonical_task->notepad, api ->Notepads, sizeof(canonical_task->notepad));
+/* XXX more to fix */
+/*
+ (void) memcpy(&canonical_task->wait_args, &rtems_thread->Wait.Extra, sizeof(canonical_task->wait_args));
+*/
+}
+
+
+void
+rtems_monitor_task_dump_header(
+ bool verbose __attribute__((unused))
+)
+{
+ fprintf(stdout,"\
+ ID NAME PRI STATE MODES EVENTS WAITID WAITARG NOTES\n\
+");
+/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
+0 1 2 3 4 5 6 7 */
+
+ rtems_monitor_separator();
+}
+
+/*
+ */
+
+void
+rtems_monitor_task_dump(
+ rtems_monitor_task_t *monitor_task,
+ bool verbose __attribute__((unused))
+)
+{
+ int length = 0;
+
+ length += rtems_monitor_dump_id(monitor_task->id);
+ length += rtems_monitor_pad(11, length);
+ length += rtems_monitor_dump_name(monitor_task->id);
+ length += rtems_monitor_pad(26, length);
+ length += rtems_monitor_dump_priority(monitor_task->priority);
+ length += rtems_monitor_pad(29, length);
+ length += rtems_monitor_dump_state(monitor_task->state);
+ length += rtems_monitor_pad(37, length);
+ length += rtems_monitor_dump_modes(monitor_task->modes);
+ length += rtems_monitor_pad(45, length);
+ length += rtems_monitor_dump_events(monitor_task->events);
+ if (monitor_task->wait_id)
+ {
+ length += rtems_monitor_pad(54, length);
+ length += rtems_monitor_dump_id(monitor_task->wait_id);
+ length += rtems_monitor_pad(63, length);
+ length += rtems_monitor_dump_hex(monitor_task->wait_args);
+ }
+
+ length += rtems_monitor_pad(72, length);
+ length += rtems_monitor_dump_notepad(monitor_task->notepad);
+ fprintf(stdout,"\n");
+}
diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h
new file mode 100644
index 0000000000..84a360b976
--- /dev/null
+++ b/cpukit/libmisc/monitor/monitor.h
@@ -0,0 +1,531 @@
+/**
+ * @file rtems/monitor.h
+ *
+ * The RTEMS monitor task.
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef __MONITOR_H
+#define __MONITOR_H
+
+#include <rtems/error.h> /* rtems_error() */
+#include <rtems/config.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Forward decls from symbols.h */
+typedef struct _rtems_symbol_t rtems_symbol_t;
+typedef struct _rtems_symbol_table_t rtems_symbol_table_t;
+
+/*
+ * Monitor types are derived from rtems object classes
+ */
+
+typedef enum {
+ RTEMS_MONITOR_OBJECT_INVALID = OBJECTS_CLASSIC_NO_CLASS,
+ RTEMS_MONITOR_OBJECT_TASK = OBJECTS_RTEMS_TASKS,
+ RTEMS_MONITOR_OBJECT_EXTENSION = OBJECTS_RTEMS_EXTENSIONS,
+ RTEMS_MONITOR_OBJECT_QUEUE = OBJECTS_RTEMS_MESSAGE_QUEUES,
+ RTEMS_MONITOR_OBJECT_SEMAPHORE = OBJECTS_RTEMS_SEMAPHORES,
+ RTEMS_MONITOR_OBJECT_PARTITION = OBJECTS_RTEMS_PARTITIONS,
+ RTEMS_MONITOR_OBJECT_REGION = OBJECTS_RTEMS_REGIONS,
+ RTEMS_MONITOR_OBJECT_PORT = OBJECTS_RTEMS_PORTS,
+
+ /* following monitor objects are not known to RTEMS, but
+ * we like to have "types" for them anyway */
+
+ RTEMS_MONITOR_OBJECT_DRIVER = OBJECTS_RTEMS_CLASSES_LAST+1,
+ RTEMS_MONITOR_OBJECT_DNAME,
+ RTEMS_MONITOR_OBJECT_CONFIG,
+ RTEMS_MONITOR_OBJECT_INIT_TASK,
+ RTEMS_MONITOR_OBJECT_MPCI,
+ RTEMS_MONITOR_OBJECT_SYMBOL,
+ #if defined(RTEMS_POSIX_API)
+ RTEMS_MONITOR_OBJECT_PTHREAD,
+ #endif
+} rtems_monitor_object_type_t;
+
+/*
+ * rtems_monitor_init() flags
+ */
+
+#define RTEMS_MONITOR_SUSPEND 0x0001 /* suspend monitor on startup */
+#define RTEMS_MONITOR_GLOBAL 0x0002 /* monitor should be global */
+#define RTEMS_MONITOR_NOTASK 0x0004 /* do not start monitor task */
+#define RTEMS_MONITOR_NOSYMLOAD 0x0008 /* do not load symbols */
+#define RTEMS_MONITOR_WAITQUIT 0x0010 /* wait for monitor task to terminate */
+
+/*
+ * Public interfaces for RTEMS data structures monitor is aware of.
+ * These are only used by the monitor.
+ *
+ * NOTE:
+ * All the canonical objects that correspond to RTEMS managed "objects"
+ * must have an identical first portion with 'id' and 'name' fields.
+ *
+ * Others do not have that restriction, even tho we would like them to.
+ * This is because some of the canonical structures are almost too big
+ * for shared memory driver (eg: mpci) and we are nickel and diming it.
+ */
+
+/*
+ * Type of a pointer that may be a symbol
+ */
+
+#define MONITOR_SYMBOL_LEN 20
+typedef struct {
+ char name[MONITOR_SYMBOL_LEN];
+ uint32_t value;
+ uint32_t offset;
+} rtems_monitor_symbol_t;
+
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+} rtems_monitor_generic_t;
+
+/*
+ * Task
+ */
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+ Thread_Entry entry;
+ Thread_Entry_numeric_type argument;
+ void *stack;
+ uint32_t stack_size;
+ rtems_task_priority priority;
+ States_Control state;
+ rtems_event_set events;
+ rtems_mode modes;
+ rtems_attribute attributes;
+ uint32_t notepad[RTEMS_NUMBER_NOTEPADS];
+ rtems_id wait_id;
+ uint32_t wait_args;
+ uint32_t ticks;
+} rtems_monitor_task_t;
+
+/*
+ * Init task
+ */
+
+typedef struct {
+ rtems_id id; /* not really an id */
+ rtems_name name;
+ /* end of common portion */
+ rtems_monitor_symbol_t entry;
+ uint32_t argument;
+ uint32_t stack_size;
+ rtems_task_priority priority;
+ rtems_mode modes;
+ rtems_attribute attributes;
+} rtems_monitor_init_task_t;
+
+
+/*
+ * Message queue
+ */
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+ rtems_attribute attributes;
+ uint32_t number_of_pending_messages;
+ uint32_t maximum_pending_messages;
+ size_t maximum_message_size;
+} rtems_monitor_queue_t;
+
+/*
+ * Semaphore
+ */
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+ rtems_attribute attribute;
+ rtems_task_priority priority_ceiling;
+ uint32_t max_count;
+ uint32_t cur_count;
+ rtems_id holder_id;
+} rtems_monitor_sema_t;
+
+/*
+ * Extension
+ */
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+ rtems_monitor_symbol_t e_create;
+ rtems_monitor_symbol_t e_start;
+ rtems_monitor_symbol_t e_restart;
+ rtems_monitor_symbol_t e_delete;
+ rtems_monitor_symbol_t e_tswitch;
+ rtems_monitor_symbol_t e_begin;
+ rtems_monitor_symbol_t e_exitted;
+ rtems_monitor_symbol_t e_fatal;
+} rtems_monitor_extension_t;
+
+ /*
+ * Region
+ */
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+ rtems_attribute attribute;
+ void * start_addr;
+ uint32_t length;
+ uint32_t page_size;
+ uint32_t max_seg_size;
+ uint32_t used_blocks;
+} rtems_monitor_region_t;
+
+/*
+ * Partition
+ */
+typedef struct {
+ rtems_id id;
+ rtems_name name;
+ /* end of common portion */
+ rtems_attribute attribute;
+ void * start_addr;
+ uint32_t length;
+ uint32_t buf_size;
+ uint32_t used_blocks;
+} rtems_monitor_part_t;
+
+/*
+ * Device driver
+ */
+
+typedef struct {
+ rtems_id id; /* not really an id (should be tho) */
+ rtems_name name; /* ditto */
+ /* end of common portion */
+ rtems_monitor_symbol_t initialization; /* initialization procedure */
+ rtems_monitor_symbol_t open; /* open request procedure */
+ rtems_monitor_symbol_t close; /* close request procedure */
+ rtems_monitor_symbol_t read; /* read request procedure */
+ rtems_monitor_symbol_t write; /* write request procedure */
+ rtems_monitor_symbol_t control; /* special functions procedure */
+} rtems_monitor_driver_t;
+
+/*
+ * System config
+ */
+
+typedef struct {
+ void *work_space_start;
+ uint32_t work_space_size;
+ uint32_t maximum_tasks;
+ uint32_t maximum_timers;
+ uint32_t maximum_semaphores;
+ uint32_t maximum_message_queues;
+ uint32_t maximum_partitions;
+ uint32_t maximum_regions;
+ uint32_t maximum_ports;
+ uint32_t maximum_periods;
+ uint32_t maximum_extensions;
+ uint32_t microseconds_per_tick;
+ uint32_t ticks_per_timeslice;
+ uint32_t number_of_initialization_tasks;
+} rtems_monitor_config_t;
+
+/*
+ * MPCI config
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+typedef struct {
+ uint32_t node; /* local node number */
+ uint32_t maximum_nodes; /* maximum # nodes in system */
+ uint32_t maximum_global_objects; /* maximum # global objects */
+ uint32_t maximum_proxies; /* maximum # proxies */
+
+ uint32_t default_timeout; /* in ticks */
+ size_t maximum_packet_size;
+ rtems_monitor_symbol_t initialization;
+ rtems_monitor_symbol_t get_packet;
+ rtems_monitor_symbol_t return_packet;
+ rtems_monitor_symbol_t send_packet;
+ rtems_monitor_symbol_t receive_packet;
+} rtems_monitor_mpci_t;
+#endif
+
+/*
+ * The generic canonical information union
+ */
+
+typedef union {
+ rtems_monitor_generic_t generic;
+ rtems_monitor_task_t task;
+ rtems_monitor_queue_t queue;
+ rtems_monitor_sema_t sema;
+ rtems_monitor_extension_t extension;
+ rtems_monitor_driver_t driver;
+ rtems_monitor_config_t config;
+ rtems_monitor_region_t region;
+ rtems_monitor_part_t part;
+#if defined(RTEMS_MULTIPROCESSING)
+ rtems_monitor_mpci_t mpci;
+#endif
+ rtems_monitor_init_task_t itask;
+} rtems_monitor_union_t;
+
+/*
+ * Support for talking to other monitors
+ */
+
+/*
+ * Names of other monitors
+ */
+
+#define RTEMS_MONITOR_NAME (rtems_build_name('R', 'M', 'O', 'N'))
+#define RTEMS_MONITOR_SERVER_NAME (rtems_build_name('R', 'M', 'S', 'V'))
+#define RTEMS_MONITOR_QUEUE_NAME (rtems_build_name('R', 'M', 'S', 'Q'))
+#define RTEMS_MONITOR_RESPONSE_QUEUE_NAME (rtems_build_name('R', 'M', 'R', 'Q'))
+
+#define RTEMS_MONITOR_SERVER_RESPONSE 0x0001
+#define RTEMS_MONITOR_SERVER_CANONICAL 0x0002
+
+typedef struct
+{
+ uint32_t command;
+ rtems_id return_id;
+ uint32_t argument0;
+ uint32_t argument1;
+ uint32_t argument2;
+ uint32_t argument3;
+ uint32_t argument4;
+ uint32_t argument5;
+} rtems_monitor_server_request_t;
+
+typedef struct
+{
+ uint32_t command;
+ uint32_t result0;
+ uint32_t result1;
+ rtems_monitor_union_t payload;
+} rtems_monitor_server_response_t;
+
+extern rtems_id rtems_monitor_task_id;
+
+extern uint32_t rtems_monitor_node; /* our node number */
+extern uint32_t rtems_monitor_default_node; /* current default for commands */
+
+/*
+ * Monitor command function and table entry
+ */
+
+typedef struct rtems_monitor_command_entry_s rtems_monitor_command_entry_t;
+typedef union _rtems_monitor_command_arg_t rtems_monitor_command_arg_t;
+
+typedef void (*rtems_monitor_command_function_t)(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
+);
+
+union _rtems_monitor_command_arg_t {
+ rtems_monitor_object_type_t monitor_object;
+ rtems_status_code status_code;
+ rtems_symbol_table_t **symbol_table;
+ const rtems_monitor_command_entry_t *monitor_command_entry;
+};
+
+struct rtems_monitor_command_entry_s {
+ const char *command; /* command name */
+ const char *usage; /* usage string for the command */
+ uint32_t arguments_required; /* # of required args */
+ rtems_monitor_command_function_t command_function;
+ /* Some argument for the command */
+ rtems_monitor_command_arg_t command_arg;
+ const rtems_monitor_command_entry_t *next;
+};
+
+
+typedef void *(*rtems_monitor_object_next_fn)(void *, void *, rtems_id *);
+typedef void (*rtems_monitor_object_canonical_fn)(void *, void *);
+typedef void (*rtems_monitor_object_dump_header_fn)(bool);
+typedef void (*rtems_monitor_object_dump_fn)(void *, bool);
+
+typedef struct {
+ rtems_monitor_object_type_t type;
+ void *object_information;
+ int size; /* of canonical object */
+ rtems_monitor_object_next_fn next;
+ rtems_monitor_object_canonical_fn canonical;
+ rtems_monitor_object_dump_header_fn dump_header;
+ rtems_monitor_object_dump_fn dump;
+} rtems_monitor_object_info_t;
+
+typedef bool (*rtems_monitor_per_command_routine)(const rtems_monitor_command_entry_t *, void *);
+
+/* monitor.c */
+void rtems_monitor_pause_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_fatal_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_continue_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_debugger_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_reset_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_node_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_symbols_loadup(void);
+int rtems_monitor_insert_cmd(rtems_monitor_command_entry_t *);
+void rtems_monitor_wakeup(void);
+void rtems_monitor_command_iterate(rtems_monitor_per_command_routine routine, void *arg);
+rtems_status_code rtems_monitor_suspend(rtems_interval timeout);
+
+/* editor.c */
+void rtems_monitor_kill(void);
+void rtems_monitor_init(uint32_t);
+void rtems_monitor_task(rtems_task_argument);
+
+/* server.c */
+void rtems_monitor_server_kill(void);
+rtems_status_code rtems_monitor_server_request(uint32_t , rtems_monitor_server_request_t *, rtems_monitor_server_response_t *);
+void rtems_monitor_server_task(rtems_task_argument);
+void rtems_monitor_server_init(uint32_t );
+
+/* command.c */
+int rtems_monitor_make_argv(char *, int *, char **);
+int rtems_monitor_command_read(char *, int *, char **);
+void rtems_monitor_command_usage(const rtems_monitor_command_entry_t *, const char *);
+void rtems_monitor_help_cmd(int, char **, const rtems_monitor_command_arg_t *, bool);
+const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const char *name);
+
+/* prmisc.c */
+void rtems_monitor_separator(void);
+uint32_t rtems_monitor_pad(uint32_t dest_col, uint32_t curr_col);
+int rtems_monitor_dump_decimal(uint32_t num);
+int rtems_monitor_dump_hex(uint32_t num);
+int rtems_monitor_dump_addr(void *addr);
+int rtems_monitor_dump_id(rtems_id id);
+int rtems_monitor_dump_name(rtems_id id);
+int rtems_monitor_dump_priority(rtems_task_priority priority);
+int rtems_monitor_dump_state(States_Control state);
+int rtems_monitor_dump_modes(rtems_mode modes);
+int rtems_monitor_dump_attributes(rtems_attribute attributes);
+int rtems_monitor_dump_events(rtems_event_set events);
+int rtems_monitor_dump_notepad(uint32_t *notepad);
+
+/* object.c */
+rtems_id rtems_monitor_id_fixup(rtems_id, uint32_t , rtems_monitor_object_type_t);
+const rtems_monitor_object_info_t *rtems_monitor_object_lookup(rtems_monitor_object_type_t type);
+rtems_id rtems_monitor_object_canonical_get(rtems_monitor_object_type_t, rtems_id, void *, size_t *size_p);
+rtems_id rtems_monitor_object_canonical_next(const rtems_monitor_object_info_t *, rtems_id, void *);
+void *rtems_monitor_object_next(void *, void *, rtems_id, rtems_id *);
+rtems_id rtems_monitor_object_canonical(rtems_id, void *);
+void rtems_monitor_object_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+
+/* manager.c */
+void *rtems_monitor_manager_next(void *, void *, rtems_id *);
+
+/* config.c */
+void rtems_monitor_config_canonical(rtems_monitor_config_t *, void *);
+void *rtems_monitor_config_next(void *, rtems_monitor_config_t *, rtems_id *);
+void rtems_monitor_config_dump_header(bool);
+int rtems_monitor_config_dump(rtems_monitor_config_t *, bool verbose);
+
+/* mpci.c */
+#if defined(RTEMS_MULTIPROCESSING)
+void rtems_monitor_mpci_canonical(rtems_monitor_mpci_t *, void *);
+void *rtems_monitor_mpci_next(void *, rtems_monitor_mpci_t *, rtems_id *);
+void rtems_monitor_mpci_dump_header(bool);
+void rtems_monitor_mpci_dump(rtems_monitor_mpci_t *, bool verbose);
+#endif
+
+/* itask.c */
+void rtems_monitor_init_task_canonical(rtems_monitor_init_task_t *, void *);
+void *rtems_monitor_init_task_next(void *, rtems_monitor_init_task_t *, rtems_id *);
+void rtems_monitor_init_task_dump_header(bool);
+void rtems_monitor_init_task_dump(rtems_monitor_init_task_t *, bool verbose);
+
+/* extension.c */
+void rtems_monitor_extension_canonical(rtems_monitor_extension_t *, void *);
+void rtems_monitor_extension_dump_header(bool verbose);
+void rtems_monitor_extension_dump(rtems_monitor_extension_t *, bool);
+
+/* task.c */
+void rtems_monitor_task_canonical(rtems_monitor_task_t *, void *);
+void rtems_monitor_task_dump_header(bool verbose);
+void rtems_monitor_task_dump(rtems_monitor_task_t *, bool);
+
+/* sema.c */
+void rtems_monitor_sema_canonical(rtems_monitor_sema_t *, void *);
+void rtems_monitor_sema_dump_header(bool verbose);
+void rtems_monitor_sema_dump(rtems_monitor_sema_t *, bool);
+
+/* queue.c */
+void rtems_monitor_queue_canonical(rtems_monitor_queue_t *, void *);
+void rtems_monitor_queue_dump_header(bool verbose);
+void rtems_monitor_queue_dump(rtems_monitor_queue_t *, bool);
+
+/* region.c */
+void rtems_monitor_region_canonical(rtems_monitor_region_t *, void *);
+void rtems_monitor_region_dump_header(bool verbose);
+void rtems_monitor_region_dump(rtems_monitor_region_t *, bool);
+
+/* partition.c */
+void rtems_monitor_part_canonical(rtems_monitor_part_t *, void *);
+void rtems_monitor_part_dump_header(bool verbose);
+void rtems_monitor_part_dump(rtems_monitor_part_t *, bool);
+
+/* driver.c */
+void *rtems_monitor_driver_next(void *, rtems_monitor_driver_t *, rtems_id *);
+void rtems_monitor_driver_canonical(rtems_monitor_driver_t *, void *);
+void rtems_monitor_driver_dump_header(bool);
+void rtems_monitor_driver_dump(rtems_monitor_driver_t *, bool);
+
+/* symbols.c */
+rtems_symbol_table_t *rtems_symbol_table_create(void);
+void rtems_symbol_table_destroy(rtems_symbol_table_t *table);
+
+rtems_symbol_t *rtems_symbol_create(rtems_symbol_table_t *, const char *, uint32_t );
+rtems_symbol_t *rtems_symbol_value_lookup(rtems_symbol_table_t *, uint32_t );
+const rtems_symbol_t *rtems_symbol_value_lookup_exact(rtems_symbol_table_t *, uint32_t );
+rtems_symbol_t *rtems_symbol_name_lookup(rtems_symbol_table_t *, const char *);
+void *rtems_monitor_symbol_next(void *object_info, rtems_monitor_symbol_t *, rtems_id *);
+void rtems_monitor_symbol_canonical(rtems_monitor_symbol_t *, rtems_symbol_t *);
+void rtems_monitor_symbol_canonical_by_name(rtems_monitor_symbol_t *, const char *);
+void rtems_monitor_symbol_canonical_by_value(rtems_monitor_symbol_t *, void *);
+uint32_t rtems_monitor_symbol_dump(rtems_monitor_symbol_t *, bool);
+void rtems_monitor_symbol_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+
+#if defined(RTEMS_NETWORKING)
+void mon_ifconfig(
+ int argc,
+ char *argv[],
+ uint32_t command_arg,
+ bool verbose
+);
+void mon_route(
+ int argc,
+ char *argv[],
+ uint32_t command_arg,
+ bool verbose
+);
+#endif
+
+/* mon-object.c */
+const rtems_monitor_object_info_t *rtems_monitor_object_lookup(
+ rtems_monitor_object_type_t type
+);
+
+/* shared data */
+extern rtems_symbol_table_t *rtems_monitor_symbols;
+
+#define MONITOR_WAKEUP_EVENT RTEMS_EVENT_0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! __MONITOR_H */
diff --git a/cpukit/libmisc/monitor/symbols.h b/cpukit/libmisc/monitor/symbols.h
new file mode 100644
index 0000000000..6246379a94
--- /dev/null
+++ b/cpukit/libmisc/monitor/symbols.h
@@ -0,0 +1,64 @@
+/*
+ * RTEMS monitor symbol table functions
+ *
+ * Description:
+ * Entry points for symbol table routines.
+ *
+ *
+ *
+ * TODO:
+ *
+ * $Id$
+ */
+
+#ifndef _INCLUDE_SYMBOLS_H
+#define _INCLUDE_SYMBOLS_H
+
+#include <rtems/monitor.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _rtems_symbol_t {
+ uint32_t value;
+ char *name;
+} ;
+
+#define SYMBOL_STRING_BLOCK_SIZE 4080
+typedef struct rtems_symbol_string_block_s {
+ struct rtems_symbol_string_block_s *next;
+ char buffer[SYMBOL_STRING_BLOCK_SIZE];
+} rtems_symbol_string_block_t;
+
+struct _rtems_symbol_table_t {
+
+ uint32_t sorted; /* are symbols sorted right now? */
+ uint32_t growth_factor; /* % to grow by when needed */
+ uint32_t next; /* next symbol slot to use when adding */
+ uint32_t size; /* max # of symbols */
+
+ /*
+ * Symbol list -- sorted by address (when we do a lookup)
+ */
+
+ rtems_symbol_t *addresses; /* symbol array by address */
+
+ /*
+ * String pool, unsorted, a list of blocks of string data
+ */
+
+ rtems_symbol_string_block_t *string_buffer_head;
+ rtems_symbol_string_block_t *string_buffer_current;
+ uint32_t strings_next; /* next byte to use in this block */
+
+} ;
+
+#define rtems_symbol_name(sp) ((sp)->name)
+#define rtems_symbol_value(sp) ((sp)->value)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! _INCLUDE_SYMBOLS_H */
diff --git a/cpukit/libmisc/mouse/README b/cpukit/libmisc/mouse/README
new file mode 100644
index 0000000000..ab684a6d0b
--- /dev/null
+++ b/cpukit/libmisc/mouse/README
@@ -0,0 +1,214 @@
+#
+# $Id$
+#
+
+SOURCE: http://www.kryslix.com/nsfaq/Q.12.html
+
+Subject: What protocol do mice use?
+Date: 09/16/97
+Updated: 11/16/00 This document was adapated from a web page produced by
+Tomi Engdahl <then@delta.hut.fi>
+Microsoft serial mouse
+Description
+
+The Microsoft serial mouse is the most popular 2 button mouse. It is
+supported by all major operating systems. The maximum tracking rate for
+a Microsoft mouse is 40 reports/second * 127 counts per report, in other
+words, 5080 counts per second. The most common range for mice is is 100
+to 400 CPI (counts per inch) but can be up to 1000 CPI. A 100CPI mouse
+can discriminate motion up to 50.8 inches/second while a 400 CPI mouse
+can only discriminate motion up to 12.7 inches/second.
+Pinout
+
+9 pin 25 pin Line Comments
+shell 1 GND
+3 2 TD Serial data from host to mouse (only for power)
+2 3 RD Serial data from mouse to host
+7 4 RTS Positive voltage to mouse
+8 5 CTS
+6 6 DSR
+5 7 SGND
+4 20 DTR Positive voltage to mouse and reset/detection
+
+RTS = Request to Send CTS = Clear to Send
+DSR = Data Set Ready DTR = Data Terminal Ready
+GND = Protective Ground SGND = Signal Ground
+
+To function correctly, both the RTS and DTR lines must be
+positive. DTR/DSR and RTS/CTS must NOT be shorted. RTS may be toggled
+negative for at least 100ms to reset the mouse. (After a cold boot, the
+RTS line is usually negative. This provides an automatic toggle when
+RTS is brought positive). When DTR is toggled the mouse should send a
+single byte 0x45 (ASCII 'M').
+
+Serial data parameters:
+1200bps, 7 databits, 1 stop-bit
+
+Data packet format:
+
+Data is sent in 3 byte packets for each event (a button is pressed or
+released or the mouse moves):
+
+ D7 D6 D5 D4 D3 D2 D1 D0
+
+Byte 1 X 1 LB RB Y7 Y6 X7 X6
+Byte 2 X 0 X5 X4 X3 X2 X1 X0
+Byte 3 X 0 Y5 Y4 Y3 Y2 Y1 Y0
+
+LB is the state of the left button (1 means down)
+RB is the state of the right button (1 means down)
+X7-X0 movement in X direction since last packet (signed byte)
+Y7-Y0 movement in Y direction since last packet (signed byte)
+
+The high order bit of each byte (D7) is ignored. Bit D6 indicates the start of an event, which allows the software to synchronize with the mouse.
+
+Graphical representation of a packet
+
+ 1st byte 2nd byte 3rd byte
+ ================ =============== ================
+ - 1 ? ? Y Y X X - 0 X X X X X X - 0 Y Y Y Y Y Y
+ ================ =============== ================
+ | | \ / \ / \---------/ \---------/
+ | | | | | |
+ | | | \----\ | |
+ | | \--------|-------|--------\ |
+ | | / \ /---------\ / \ /---------\
+ | | ================ =================
+ | | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ Left Button --/ | ================ =================
+Right Button ----/ X increment Y increment
+
+3 Button Logitech extension
+
+Logitech extended the 2 button mouse protocol to support 3 button mice
+by adding a 4th byte when the middle button is pressed (and the first
+packet after it is released). If a 4th byte is encountered (i.e., an
+extra byte with D6 set to 0) then D5 of that byte (0x20) indicates the
+status of the middle mouse button.
+
+Mouse systems mouse
+
+Serial data parameters:
+
+1200bps, 8 databits, 1 stop-bit
+
+5 byte Mouse Systems packet
+
+ D7 D6 D5 D4 D3 D2 D1 D0
+
+Byte 1 1 0 0 0 0 LB CB RB
+Byte 2 X7 X6 X5 X4 X3 X2 X1 X0
+Byte 3 Y7 Y6 Y5 Y4 Y3 Y4 Y1 Y0
+Byte 4 X7' X6' X5' X4' X3' X2' X1' X0'
+Byte 5 Y7' Y6' Y5' Y4' Y3' Y4' Y1' Y0'
+
+LB is left button state (0=pressed, 1=released)
+CB is center button state (0=pressed, 1=released)
+RB is right button state (0=pressed, 1=released)
+X7-X0 movement in X direction since last packet in signed byte
+ format (-128..+127), positive direction right
+Y7-Y0 movement in Y direction since last packet in signed byte
+ format (-128..+127), positive direction up
+X7'-X0' movement in X direction since sending of X7-X0 packet in signed byte
+ format (-128..+127), positive direction right
+Y7'-Y0' movement in Y direction since sending of Y7-Y0 in signed byte
+ format (-128..+127), positive direction up
+
+The last two bytes in the packet (bytes 4 and 5) contain information
+about movement data changes which have occured after data bytes 2 and
+3 have been sent.
+
+PS/2 mouse
+
+The standard PS/2 mouse (such as the Logitech mouse) defaults to 160 CPI
+and can be switched to 40, 80, 160 or 320 CPI via software. The Microsoft
+mouse driver for Windows 3.x and Windows 95 defaults to 160 counts per
+inch. The maximum tracking rate for PS/2 mouse is 40 reports/second *
+255 counts per report, or 10200 counts per second. A 100 CPI mouse could
+discriminate motion up to 102 inches per second while a 400 CPI mouse
+could discriminate motion up to 25.2 inches per second.
+
+Connector pinout
+
+Pin Wire Name
+1 DATA
+2 Reserved
+3 Ground
+4 +5V Supply
+5 CLK
+6 Reserved
+Shield Chassis
+
+Packet Format
+
+ D7 D6 D5 D4 D3 D2 D1 D0
+Byte 1 XV XV YS XS 1 M R L
+Byte 2 X7 X6 X5 X4 X3 X2 X1 X0
+Byte 3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
+
+L Left button state (1 = pressed down)
+M Middle button state (1 = pressed down)
+R Right button state (1 = pressed down)
+X0-X7 Movement in X direction
+Y0-Y7 Movement in Y direction
+XS,YS Movement data sign bits (1 = negative)
+XV,YV Movement data overflow bits (1 = overflow has occured)
+
+Physical connector
+
+The PS/2 mouse connector has the following pinout when looking at the
+connector on the back of the computer:
+
+ 4 u 6
+ 1 . 2
+ 3 5
+
+1. GND
+2. +5V
+3. DATA
+4. CLOCK
+5. Not used
+6. Not used
+
+Bi-directional transmission is controlled by the CLK and DATA lines. Both
+are fed by an open collector device which lets either host or mouse force
+the line to "0". During non-transmission, CLK is at "1" and DATA can be at
+"0" or "1".
+
+The host can inhibit mouse transmission by forcing CLK to "0". If the
+host inhibits the mouse while it is transmitting, the byte must be
+retransmitted (if the inhibit state arrived before the 11th clock).
+
+Receiving data: Check 'clock'. If inactive, there is a bit on the 'data'
+line. Each transmission unit is one start bit, eight data bits, odd
+parity and one stop bit. Start bits are low, stop bits high. Each clock
+active or inactive period is 30 to 50 microseconds. Data transition to
+falling edge of clock is 5 to 25 microseconds.
+
+Sending: Check that both clock and data are high. Pull down data for
+start bit, and start clocking.
+
+NOTE: Logitech has made the extension to this protocol to allow three
+buttons (the M bit is always 0 on 2 button mice).
+
+References
+
+* Original PC mouse info page by Tomi Engdahl
+ http://www.hut.fi/~then/mytexts/mouse.html
+
+* PC Magazine May 28, 1991
+
+* Programmer's Reference to Genius Mouse
+ ftp://x2ftp.oulu.fi/pub/msdos/programming/docs/gmouse.doc
+
+* Logitech Pointing Device Hardware Information Product Support Document # 1410
+ ftp://ftp.logitech.com/pub/TechSupport/MOUSE/HELP/1410.txt
+
+* Mice: How do they work? by Richard Torrens
+ http://box.argonet.co.uk/users/4qd/meece.html
+
+* In Pursuit Of The Perfect Portable Pointer by Intelink Electronics
+from EDN Products Edition April 16, 1977 pages 43-45
+
+* Programming the Microsoft Mouse
+ http://www.geocities.com/SiliconValley/2151/mouse.html
diff --git a/cpukit/libmisc/mouse/mouse_parser.c b/cpukit/libmisc/mouse/mouse_parser.c
new file mode 100644
index 0000000000..9d78bbd979
--- /dev/null
+++ b/cpukit/libmisc/mouse/mouse_parser.c
@@ -0,0 +1,311 @@
+/*
+ * This code is derived from a UNIX Serial Port Mouse Driver with
+ * the following notice:
+ *
+ * ==================================================================
+ * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
+ * Portions Copyright (c) 1991 David I. Bell
+ * Permission is granted to use, distribute, or modify this source,
+ * provided that this copyright notice remains intact.
+ *
+ * UNIX Serial Port Mouse Driver
+ *
+ * This driver opens a serial port directly, and interprets serial data.
+ * Microsoft, PC, Logitech and PS/2 mice are supported. The PS/2 mouse
+ * is only supported if the OS runs the mouse byte codes through the
+ * serial port.
+ *
+ * Mouse Types Supported: pc ms, logi, ps2
+ * ==================================================================
+ *
+ * It has been modified to support the concept of being just a parser
+ * fed data from an arbitrary source. It is independent of either
+ * a PS/2 driver or a serial port.
+ *
+ * It was moved to cpukit/libmisc/mouse by Joel Sherrill.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h> /* strcmp */
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/mouse_parser.h>
+#include <rtems/mw_uid.h>
+
+/* states for the mouse */
+#define IDLE 0 /* start of byte sequence */
+#define XSET 1 /* setting x delta */
+#define YSET 2 /* setting y delta */
+#define XADD 3 /* adjusting x delta */
+#define YADD 4 /* adjusting y delta */
+
+/* values in the bytes returned by the mouse for the buttons*/
+#define PC_LEFT_BUTTON 4
+#define PC_MIDDLE_BUTTON 2
+#define PC_RIGHT_BUTTON 1
+
+#define MS_LEFT_BUTTON 2
+#define MS_RIGHT_BUTTON 1
+
+#define PS2_CTRL_BYTE 0x08
+#define PS2_LEFT_BUTTON 1
+#define PS2_RIGHT_BUTTON 2
+
+/* Bit fields in the bytes sent by the mouse.*/
+#define TOP_FIVE_BITS 0xf8
+#define BOTTOM_THREE_BITS 0x07
+#define TOP_BIT 0x80
+#define SIXTH_BIT 0x40
+#define BOTTOM_TWO_BITS 0x03
+#define THIRD_FOURTH_BITS 0x0c
+#define BOTTOM_SIX_BITS 0x3f
+
+/* local data */
+static int state; /* IDLE, XSET, ... */
+static BUTTON buttons; /* current mouse buttons pressed*/
+static BUTTON availbuttons; /* which buttons are available */
+static COORD xd; /* change in x */
+static COORD yd; /* change in y */
+
+static int left; /* because the button values change */
+static int middle; /* between mice, the buttons are */
+static int right; /* redefined */
+
+static int (*parse)( int ); /* parse routine */
+
+/* local routines*/
+static int ParsePC(int); /* routine to interpret PC mouse */
+static int ParseMS(int); /* routine to interpret MS mouse */
+static int ParsePS2(int); /* routine to interpret PS/2 mouse */
+
+/*
+ * Open up the mouse device.
+ * Returns the fd if successful, or negative if unsuccessful.
+ */
+int mouse_parser_initialize(const char *type)
+{
+ /* set button bits and parse procedure*/
+ if (!strcmp(type, "pc") || !strcmp(type, "logi")) {
+ /* pc or logitech mouse*/
+ left = PC_LEFT_BUTTON;
+ middle = PC_MIDDLE_BUTTON;
+ right = PC_RIGHT_BUTTON;
+ parse = ParsePC;
+ } else if (strcmp(type, "ms") == 0) {
+ /* microsoft mouse*/
+ left = MS_LEFT_BUTTON;
+ right = MS_RIGHT_BUTTON;
+ middle = 0;
+ parse = ParseMS;
+ } else if (strcmp(type, "ps2") == 0) {
+ /* PS/2 mouse*/
+ left = PS2_LEFT_BUTTON;
+ right = PS2_RIGHT_BUTTON;
+ middle = 0;
+ parse = ParsePS2;
+ } else
+ return -1;
+
+ printk("Device: /dev/mouse -- mouse type is: %s\n", type );
+
+ /* initialize data*/
+ availbuttons = left | middle | right;
+ state = IDLE;
+ buttons = 0;
+ xd = 0;
+ yd = 0;
+ return 0;
+}
+
+/*
+ * Attempt to read bytes from the mouse and interpret them.
+ * Returns -1 on error, 0 if either no bytes were read or not enough
+ * was read for a complete state, or 1 if the new state was read.
+ * When a new state is read, the current buttons and x and y deltas
+ * are returned. This routine does not block.
+ */
+int MOU_Data( int ch, COORD *dx, COORD *dy, COORD *dz, BUTTON *bptr)
+{
+ int b;
+
+ if ( !parse ) {
+ printk( "Mouse parser is not initialized!\n" );
+ return -1;
+ }
+
+ /*
+ * Loop over all the bytes read in the buffer, parsing them.
+ * When a complete state has been read, return the results,
+ * leaving further bytes in the buffer for later calls.
+ */
+ if ( (*parse)( ch ) ) {
+ *dx = xd;
+ *dy = yd;
+ *dz = 0;
+ b = 0;
+ if (buttons & left)
+ b |= LBUTTON;
+ if (buttons & right)
+ b |= RBUTTON;
+ if (buttons & middle)
+ b |= MBUTTON;
+ *bptr = b;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Input routine for PC mouse.
+ * Returns nonzero when a new mouse state has been completed.
+ */
+static int ParsePC(int byte)
+{
+ int sign; /* sign of movement */
+
+ switch (state) {
+ case IDLE:
+ if ((byte & TOP_FIVE_BITS) == TOP_BIT) {
+ buttons = ~byte & BOTTOM_THREE_BITS;
+ state = XSET;
+ }
+ break;
+
+ case XSET:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ xd = byte * sign;
+ state = YSET;
+ break;
+
+ case YSET:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ yd = -byte * sign;
+ state = XADD;
+ break;
+
+ case XADD:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ xd += byte * sign;
+ state = YADD;
+ break;
+
+ case YADD:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ yd -= byte * sign;
+ state = IDLE;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Input routine for Microsoft mouse.
+ * Returns nonzero when a new mouse state has been completed.
+ */
+static int ParseMS(int byte)
+{
+ switch (state) {
+ case IDLE:
+ if (byte & SIXTH_BIT) {
+ buttons = (byte >> 4) & BOTTOM_TWO_BITS;
+ yd = ((byte & THIRD_FOURTH_BITS) << 4);
+ xd = ((byte & BOTTOM_TWO_BITS) << 6);
+ state = XADD;
+ }
+ break;
+
+ case XADD:
+ xd |= (byte & BOTTOM_SIX_BITS);
+ state = YADD;
+ break;
+
+ case YADD:
+ yd |= (byte & BOTTOM_SIX_BITS);
+ state = IDLE;
+ if (xd > 127)
+ xd -= 256;
+ if (yd > 127)
+ yd -= 256;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Input routine for PS/2 mouse.
+ * Returns nonzero when a new mouse state has been completed.
+ */
+static int ParsePS2(int byte)
+{
+ switch (state) {
+ case IDLE:
+ if (byte & PS2_CTRL_BYTE) {
+ buttons = byte &
+ (PS2_LEFT_BUTTON|PS2_RIGHT_BUTTON);
+ state = XSET;
+ }
+ break;
+
+ case XSET:
+ if(byte > 127)
+ byte -= 256;
+ xd = byte;
+ state = YSET;
+ break;
+
+ case YSET:
+ if(byte > 127)
+ byte -= 256;
+ yd = -byte;
+ state = IDLE;
+ return 1;
+ }
+ return 0;
+}
+
+/* generic mouse parser */
+void mouse_parser_enqueue( unsigned char *buffer, size_t size )
+{
+ COORD dx;
+ COORD dy;
+ COORD dz;
+ BUTTON bptr;
+
+ while( size-- ) {
+ if ( MOU_Data( *buffer++, &dx, &dy, &dz, &bptr ) ) {
+ struct MW_UID_MESSAGE m;
+
+ m.type = MV_UID_REL_POS;
+ /* buttons definitons have been selected to match */
+ m.m.pos.btns = bptr;
+ m.m.pos.x = dx;
+ m.m.pos.y = dy;
+ m.m.pos.z = dz;
+ /* printk( "Mouse: msg: dx=%d, dy=%d, btn=%X\n", dx, dy, bptr ); */
+ uid_send_message( &m );
+ }
+ }
+}
+
diff --git a/cpukit/libmisc/mouse/mouse_parser.h b/cpukit/libmisc/mouse/mouse_parser.h
new file mode 100644
index 0000000000..59b6abb2f3
--- /dev/null
+++ b/cpukit/libmisc/mouse/mouse_parser.h
@@ -0,0 +1,108 @@
+/*
+ * This file is the header file for the Mouse Parser Engine which
+ * is derived from a UNIX Serial Port Mouse Driver with the following
+ * notice:
+ *
+ * ==================================================================
+ * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
+ * Portions Copyright (c) 1991 David I. Bell
+ * Permission is granted to use, distribute, or modify this source,
+ * provided that this copyright notice remains intact.
+ *
+ * UNIX Serial Port Mouse Driver
+ *
+ * This driver opens a serial port directly, and interprets serial data.
+ * Microsoft, PC, Logitech and PS/2 mice are supported. The PS/2 mouse
+ * is only supported if the OS runs the mouse byte codes through the
+ * serial port.
+ *
+ * Mouse Types Supported: pc ms, logi, ps2
+ * ==================================================================
+ *
+ * It has been modified to support the concept of being just a parser
+ * fed data from an arbitrary source. It is independent of either
+ * a PS/2 driver or a serial port.
+ *
+ * It was moved to cpukit/libmisc/mouse by Joel Sherrill.
+ *
+ * $Id$
+ */
+
+#ifndef __MOUSE_PARSER_h__
+#define __MOUSE_PARSER_h__
+
+#include <rtems/mw_uid.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is the mask for the right button.
+ *
+ * @note Use the same definitions as the user interface.
+ */
+#define RBUTTON MV_BUTTON_RIGHT
+
+/**
+ * This is the mask for the center button.
+ *
+ * @note Use the same definitions as the user interface.
+ */
+#define MBUTTON MV_BUTTON_CENTER
+
+/**
+ * This is the mask for the left button.
+ *
+ * @note Use the same definitions as the user interface.
+ */
+#define LBUTTON MV_BUTTON_LEFT
+
+/**
+ * This type is the device coordinates.
+ */
+typedef int COORD;
+
+/**
+ * This type is the mouse button mask.
+ */
+typedef unsigned int BUTTON;
+
+/**
+ * This type defines a pointer to the enqueue method. It is
+ * available since some device drivers keep pointers to the method
+ * to know when to enqueue or not.
+ */
+typedef void (*mouse_parser_enqueue_handler)(unsigned char *, size_t);
+
+/**
+ * @brief Initialize the Mouse Parser Engine
+ *
+ * This method initializes the Mouse Parser Engine for the mouse
+ * of @a type. The @a type should be one of the following strings:
+ * pc ms, logi, ps2.
+ *
+ * @a param[in] type indicates the type of mouse.
+ *
+ * @return This method returns 0 on success and -1 on error.
+ */
+int mouse_parser_initialize(const char *type);
+
+/**
+ * @brief Enqueue Input to the Mouse Parser Engine
+ *
+ * This method is used to pass mouse input to the Mouse Parser Engine.
+ *
+ * @a param[in] buffer is the data to enqueue
+ * @a param[in] size is the amount of data to enqueue
+ */
+void mouse_parser_enqueue(
+ unsigned char *buffer,
+ size_t size
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libmisc/mouse/serial_mouse.c b/cpukit/libmisc/mouse/serial_mouse.c
new file mode 100644
index 0000000000..c61401626d
--- /dev/null
+++ b/cpukit/libmisc/mouse/serial_mouse.c
@@ -0,0 +1,184 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <rtems/libio.h>
+#include <termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/mouse_parser.h>
+#include <rtems/serial_mouse.h>
+
+int serial_mouse_fd = -1;
+const char *serial_mouse_device;
+const char *serial_mouse_type;
+
+int serial_mouse_l_rint(int c, struct rtems_termios_tty *tp)
+{
+ unsigned char buf = c;
+
+ /* call mouse_parser( void *ptr, char *buffer, int size ) */
+ mouse_parser_enqueue( &buf, 1 );
+ return 0;
+}
+
+static struct rtems_termios_linesw serial_mouse_linesw = {
+ .l_open = NULL,
+ .l_close = NULL,
+ .l_read = NULL,
+ .l_write = NULL,
+ .l_rint = serial_mouse_l_rint,
+ .l_start = NULL,
+ .l_ioctl = NULL,
+ .l_modem = NULL
+};
+
+
+/*
+ * Serial Mouse - device driver INITIALIZE entry point.
+ */
+rtems_device_driver serial_mouse_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ bool status;
+
+ status = bsp_get_serial_mouse_device(
+ &serial_mouse_device,
+ &serial_mouse_type
+ );
+
+ (void) rtems_io_register_name( "/dev/mouse", major, 0 );
+
+ rtems_termios_linesw[ 6 ] = serial_mouse_linesw;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * serial_mouse - device driver OPEN entry point
+ */
+rtems_device_driver serial_mouse_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *args
+)
+{
+ struct termios termios_attr;
+ int status;
+ int disc = 6;
+
+ /* XXX open(2) the configured /dev/comX */
+ /* XXX save the file descriptor */
+ serial_mouse_fd = open( serial_mouse_device, O_RDONLY );
+ if ( serial_mouse_fd == -1 ) {
+ printk(
+ "Error opening serial_mouse device on %s\n",
+ serial_mouse_device
+ );
+ return RTEMS_IO_ERROR;
+ }
+
+ /* 1200-8-N-1, without hardware flow control */
+ /* BSP_uart_init( BSP_UART_PORT, 1200, CHR_8_BITS, 0, 0, 0 ); */
+ status = tcgetattr(serial_mouse_fd, &termios_attr );
+ if (status != 0) {
+ printk("Error getting mouse attributes\n");
+ return RTEMS_IO_ERROR;
+ }
+ termios_attr.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
+ termios_attr.c_iflag &= ~(IXON|IXANY|IXOFF);
+ /*
+ termios_attr.c_cc[VMIN] = itask_VMIN;
+ termios_attr.c_cc[VTIME] = itask_VTIME;
+ */
+ termios_attr.c_cflag |= B1200;
+ termios_attr.c_cflag |= CS8;
+ status = tcsetattr( serial_mouse_fd, TCSANOW, &termios_attr );
+ if (status != 0) {
+ printk("Error setting mouse attributes\n");
+ return RTEMS_IO_ERROR;
+ }
+
+ status = ioctl(serial_mouse_fd, TIOCSETD, &disc);
+ if (status != 0) {
+ printk("Error setting mouse attributes\n");
+ return RTEMS_IO_ERROR;
+ }
+
+ sleep(5);
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_device_driver serial_mouse_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ close( serial_mouse_fd );
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_device_driver serial_mouse_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+
+rtems_device_driver serial_mouse_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+
+rtems_device_driver serial_mouse_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t *)arg;
+
+ switch( args->command ) {
+
+ case MW_UID_REGISTER_DEVICE:
+ printk( "SerialMouse: reg=%s\n", args->buffer );
+ mouse_parser_initialize( serial_mouse_type );
+ break;
+
+ case MW_UID_UNREGISTER_DEVICE:
+ break;
+
+ default:
+ args->ioctl_return = ioctl(serial_mouse_fd, args->command, args->buffer );
+ if ( !args->ioctl_return )
+ return RTEMS_SUCCESSFUL;
+ return RTEMS_IO_ERROR;
+ }
+ args->ioctl_return = 0;
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/mouse/serial_mouse.h b/cpukit/libmisc/mouse/serial_mouse.h
new file mode 100644
index 0000000000..65e98089cb
--- /dev/null
+++ b/cpukit/libmisc/mouse/serial_mouse.h
@@ -0,0 +1,156 @@
+/**
+ * @file rtems/serial_mouse.h
+ *
+ * This file describes the Serial Mouse Driver for all boards.
+ * This driver assumes that the BSP or application will provide
+ * an implementation of the method bsp_get_serial_mouse_device()
+ * which tells the driver what serial port device to open() and
+ * what type of mouse is connected.
+ *
+ * This driver relies on the Mouse Parser Engine.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __SERIAL_MOUSE_h__
+#define __SERIAL_MOUSE_h__
+
+/* functions */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This macro defines the serial mouse device driver entry points.
+ */
+#define SERIAL_MOUSE_DRIVER_TABLE_ENTRY \
+ { serial_mouse_initialize, serial_mouse_open, serial_mouse_close, \
+ serial_mouse_read, serial_mouse_write, serial_mouse_control }
+
+/**
+ * @brief Serial Mouse Driver Initialization
+ *
+ * This method initializes the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Open
+ *
+ * This method implements the Open device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Close
+ *
+ * This method implements the Close device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Read
+ *
+ * This method implements the Read device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Write
+ *
+ * This method implements the Write device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver IO Control
+ *
+ * This method implements the IO Control device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Obtain Serial Mouse Configuration Information
+ *
+ * This method is implemented by the BSP or application and
+ * tells the driver what device to open() and what type of
+ * mouse is connected.
+ *
+ * @param[in] name will point to a string with the device name
+ * of the serial port with the mouse connected.
+ * @param[in] type will point to a string with the type of mouse connected.
+ *
+ * @return This method returns true on success and false on error.
+ */
+bool bsp_get_serial_mouse_device(
+ const char **name,
+ const char **type
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __tty_drv__ */
diff --git a/cpukit/libmisc/preinstall.am b/cpukit/libmisc/preinstall.am
new file mode 100644
index 0000000000..f6a7e763d2
--- /dev/null
+++ b/cpukit/libmisc/preinstall.am
@@ -0,0 +1,9 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+if LIBSHELL
+endif
diff --git a/cpukit/libmisc/serdbg/README b/cpukit/libmisc/serdbg/README
new file mode 100644
index 0000000000..338249c928
--- /dev/null
+++ b/cpukit/libmisc/serdbg/README
@@ -0,0 +1,138 @@
+#
+# $Id$
+#
+
+This directory contains three useful packages related to the termios I/O
+system:
+
+PACKAGE SERDBGIO
+================
+"serdbgio" provides the "serial gdb" standard I/O functions "getDebugChar"
+and "putDebugChar" for any device driver supporting polled termios mode.
+
+The initialization function "serdbg_open" opens the v.24 port intended
+for the serial debug connection, and sets the desired baud rate. The
+"getDebugChar" and "putDebugChar" functions then interact with the
+corresponding driver using the calls intended for polled termios
+operation.
+
+Specification for the debug device, baud rate and other parameters is
+done in a global structure of type "serdbg_conf_t". A configuration
+mechanism quite similar to the overall RTEMS configuration is available.
+
+PACKAGE SERDBG
+==============
+"serdbg" provides a means to optionally initialize and/or start a
+serial gdb session as soon as possible, this means as soon as all
+drivers have been initialized. The serial debug I/O functions can
+either be integrated as special routines of the BSP drivers, or using
+the package "serdbgio"
+
+PACKAGE TERMIOS_PRINTK
+======================
+"termios_printk" provides a standard output function suitable to use
+with "printk". It uses the same technique as serdbgio, hooking the
+interface between a polled device driver and the termios system.
+
+
+REQUIREMENTS
+============
+
+- These two packages can be used with any polled termios device
+driver.
+- For standard initialization, they need a modified "bsppost.c"
+to perform the initialization calls.
+
+USAGE
+=====
+
+For using these packages add the following to your "init" module or
+your "system.h" file (Note: most macro settings fall back to a
+default, if not set.):
+
+/*
+ * CONFIGURE_USE_SERDBG
+ * set this macro, if you want to connect gdb over a serial line
+ * when set, the debug stub will be connected after driver
+ * initialization in "bsppost.c"
+ */
+#define CONFIGURE_USE_SERDBG
+
+
+/*
+ * CONFIGURE_SERDBG_SKIP_INIT_BKPT
+ * set this macro, if you do not want the gdb interface to wait for a
+ * debugger connection directly after initialization
+ * If you set this macro, the gdb stub will only hook various
+ * exception vectors when called from "bsppost.c".
+ */
+/* #define CONFIGURE_SERDBG_SKIP_INIT_BKPT */
+
+/*
+ * CONFIGURE_SERDBG_USE_POLLED_TERMIOS
+ * set this macro, if you want "serdbgio" to provide the I/O
+ * functions for the serial gdb connection
+ */
+#define CONFIGURE_SERDBG_USE_POLLED_TERMIOS
+
+/*
+ * CONFIGURE_SERDBG_DEVNAME
+ * use this macro to specify the serial device to use
+ * for "serdbgio".
+ * Only used, when CONFIGURE_SERDBG_USE_POLLED_TERMIOS is set
+ */
+#define CONFIGURE_SERDBG_DEVNAME "/dev/tty03"
+
+/*
+ * CONFIGURE_SERDBG_BAUDRATE
+ * use this macro to specify the baud rate to use
+ * for "serdbgio".
+ * Only used, when CONFIGURE_SERDBG_USE_POLLED_TERMIOS is set
+ */
+#define CONFIGURE_SERDBG_BAUDRATE 57600
+
+/*
+ * CONFIGURE_SERDBG_CALLOUT
+ * use this macro to specify a routine that will called during I/O polling
+ * Only used, when CONFIGURE_SERDBG_USE_POLLED_TERMIOS is set
+ * This function of type "void pollfnc(void)" can be used for e.g.
+ * tickling a watchdog
+ */
+/* #define CONFIGURE_SERDBG_CALLOUT tickle_my_watchdog_fnc */
+
+#include <serdbgcnf.h>
+
+/*
+ * CONFIGURE_USE_TERMIOS_PRINTK
+ * set this macro, if you want printk output to be sent to a serial
+ * driver using the polled termios interface
+ * when set, the printk output function will be connected after driver
+ * initialization in "bsppost.c"
+ */
+#define CONFIGURE_USE_TERMIOS_PRINTK
+
+/*
+ * CONFIGURE_TERMIOS_PRINTK_DEVNAME
+ * use this macro to specify the serial device to use
+ * for printk output.
+ * Only used, when CONFIGURE_USE_TERMIOS_PRINTK is set
+ */
+#define CONFIGURE_TERMIOS_PRINTK_DEVNAME "/dev/console"
+
+/*
+ * CONFIGURE_TERMIOS_PRINTK_BAUDRATE
+ * use this macro to specify the baudrate to use
+ * for printk output.
+ * Only used, when CONFIGURE_USE_TERMIOS_PRINTK is set
+ */
+#define CONFIGURE_TERMIOS_PRINTK_BAUDRATE 9600
+
+/*
+ * CONFIGURE_TERMIOS_PRINTK_CALLOUT
+ * use this macro to specify a routine that will called during I/O polling
+ * This function of type "void pollfnc(void)" can be used for e.g.
+ * tickling a watchdog
+ */
+/* #define CONFIGURE_TERMIOS_PRINTK_CALLOUT tickle_my_watchdog_fnc */
+
+#include <termios_printk_cnf.h>
diff --git a/cpukit/libmisc/serdbg/serdbg.c b/cpukit/libmisc/serdbg/serdbg.c
new file mode 100644
index 0000000000..2f9abf6824
--- /dev/null
+++ b/cpukit/libmisc/serdbg/serdbg.c
@@ -0,0 +1,92 @@
+/*===============================================================*\
+| Project: RTEMS remote gdb over serial line |
++-----------------------------------------------------------------+
+| File: serdbg.c |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file contains intialization and utility functions to add |
+| a gdb remote debug stub to an RTEMS system |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 04.04.02 creation doe |
+\*===============================================================*/
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <rtems/serdbg.h>
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int serdbg_init_dbg
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| initialize remote gdb session over serial line |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ void
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ static bool is_initialized = false;
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ if (is_initialized) {
+ return RTEMS_SUCCESSFUL;
+ }
+ is_initialized = true;
+ /*
+ * try to open serial device
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ if ((serdbg_conf.open_io != NULL) &&
+ (0 > serdbg_conf.open_io(serdbg_conf.devname,serdbg_conf.baudrate))) {
+ fprintf(stderr,
+ "remote_gdb_init: cannot open device %s "
+ "for gdb connection:%s\n",serdbg_conf.devname,strerror(errno));
+ rc = RTEMS_IO_ERROR;
+ }
+ }
+ /*
+ * initialize gdb stub
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ set_debug_traps();
+ }
+ /*
+ * now activate gdb stub
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ !serdbg_conf.skip_init_bkpt) {
+ breakpoint();
+ }
+
+ /*
+ * return to original function
+ * this may be already unter gdb control
+ */
+ return rc;
+}
diff --git a/cpukit/libmisc/serdbg/serdbg.h b/cpukit/libmisc/serdbg/serdbg.h
new file mode 100644
index 0000000000..375b03b5d5
--- /dev/null
+++ b/cpukit/libmisc/serdbg/serdbg.h
@@ -0,0 +1,187 @@
+/*===============================================================*\
+| Project: RTEMS remote gdb over serial line |
++-----------------------------------------------------------------+
+| File: serdbg.h |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file declares intialization functions to add |
+| a gdb remote debug stub to an RTEMS system |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 04.04.02 creation doe |
+\*===============================================================*/
+/*
+ * $Id$
+ */
+#ifndef _SERDBG_H
+#define _SERDBG_H
+
+#include <rtems.h>
+#include <termios.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uint32_t baudrate; /* debug baud rate, e.g. 57600 */
+ void (*callout)(void); /* callout pointer during polling */
+ int (*open_io)(const char *dev_name, uint32_t baudrate); /* I/O open fnc */
+ const char *devname; /* debug device, e.g. "/dev/tty01" */
+ bool skip_init_bkpt; /* if TRUE, do not stop when initializing */
+} serdbg_conf_t;
+
+/*
+ * must be defined in init module...
+ */
+extern serdbg_conf_t serdbg_conf;
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void putDebugChar
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| send character to remote debugger |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ char c /* char to send */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int getDebugChar
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| get character from remote debugger |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ void /* <none> */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void serdbg_exceptionHandler
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| hook directly to an exception vector |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int vecnum, /* vector index to hook at */
+ void *vector /* address of handler function */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int serdbg_init
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| initialize remote gdb session over serial line |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ void
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+
+/*
+ * stuff from serdbgio.c
+ */
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int serdbg_open
+
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| try to open given serial debug port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ const char *dev_name, /* name of device to open */
+ uint32_t baudrate /* baud rate to use */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0 on success, -1 and errno otherwise |
+\*=========================================================================*/
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void putDebugChar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| send one character to serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ char c /* character to print */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int getDebugChar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| wait for one character from serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ void /* none */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| received character |
+\*=========================================================================*/
+
+/*
+ * Assumed to be provided by the BSP
+ */
+extern void set_debug_traps(void);
+extern void breakpoint(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SERDBG_H */
diff --git a/cpukit/libmisc/serdbg/serdbgcnf.h b/cpukit/libmisc/serdbg/serdbgcnf.h
new file mode 100644
index 0000000000..3820f61f8a
--- /dev/null
+++ b/cpukit/libmisc/serdbg/serdbgcnf.h
@@ -0,0 +1,89 @@
+/*===============================================================*\
+| Project: RTEMS configure remote gdb over serial line |
++-----------------------------------------------------------------+
+| File: serdbgcnf.h |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file declares intialization functions to add |
+| a gdb remote debug stub to an RTEMS system |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 13.05.02 creation doe |
+\*===============================================================*/
+/*
+ * $Id$
+ */
+#ifndef _SERDBGCNF_H
+#define _SERDBGCNF_H
+
+#include <rtems/serdbg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef CONFIGURE_INIT
+
+/*
+ * fallback for baud rate to use
+ */
+#ifndef CONFIGURE_SERDBG_BAUDRATE
+#define CONFIGURE_SERDBG_BAUDRATE 9600
+#endif
+
+/*
+ * fallback for device name to use
+ */
+#ifndef CONFIGURE_SERDBG_DEVNAME
+#define CONFIGURE_SERDBG_DEVNAME "/dev/tty01"
+#endif
+
+/*
+ * fill in serdbg_conf structure
+ */
+serdbg_conf_t serdbg_conf = {
+ CONFIGURE_SERDBG_BAUDRATE,
+
+#ifdef CONFIGURE_SERDBG_CALLOUT
+ CONFIGURE_SERDBG_CALLOUT,
+#else
+ NULL,
+#endif
+
+#ifdef CONFIGURE_SERDBG_USE_POLLED_TERMIOS
+ serdbg_open,
+#else
+ NULL,
+#endif
+
+ CONFIGURE_SERDBG_DEVNAME,
+
+#ifdef CONFIGURE_SERDBG_SKIP_INIT_BKPT
+ true,
+#else
+ false,
+#endif
+};
+
+int serdbg_init(void) {
+#ifdef CONFIGURE_USE_SERDBG
+ extern int serdbg_init_dbg(void);
+ return serdbg_init_dbg();
+#else
+ return 0;
+#endif
+}
+
+#endif /* CONFIGURE_INIT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SERDBGCNF_H */
diff --git a/cpukit/libmisc/serdbg/serdbgio.c b/cpukit/libmisc/serdbg/serdbgio.c
new file mode 100644
index 0000000000..6ab5b3c716
--- /dev/null
+++ b/cpukit/libmisc/serdbg/serdbgio.c
@@ -0,0 +1,256 @@
+/*===============================================================*\
+| File: serdbgio.c |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| Hebststr. 8, 82178 Puchheim, Germany |
+| <Thomas.Doerfler@imd-systems.de> |
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| http://www.rtems.com/license/LICENSE. |
+| all rights reserved |
++-----------------------------------------------------------------+
+| TERMIOS serial gdb interface support |
+| the functions in this file allow the standard gdb stubs like |
+| "m68k-stub.c" to access any serial interfaces that work with |
+| RTEMS termios in polled mode |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 10.05.02 creation doe |
+|*****************************************************************|
+|* $Id$
+ *
+|*****************************************************************|
+\*===============================================================*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <errno.h>
+#include <unistd.h> /* close */
+#include <stdio.h>
+#include <fcntl.h>
+#include <termios.h>
+
+#include <rtems/termiostypes.h>
+#include <rtems/serdbg.h>
+
+
+/*
+ * internal variables
+ */
+int serdbg_fd = -1;
+struct rtems_termios_tty *serdbg_tty;
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int serdbg_open
+
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| try to open given serial debug port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ const char *dev_name, /* name of device to open */
+ uint32_t baudrate /* baud rate to use */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0 on success, -1 and errno otherwise |
+\*=========================================================================*/
+{
+ bool err_occurred = false;
+ rtems_libio_t *iop = NULL;
+ struct termios act_termios;
+ tcflag_t baudcode = B0;
+
+#define FD_STORE_CNT 3
+ int fd_store[FD_STORE_CNT];
+ int fd_store_used = 0;
+
+ /*
+ * translate baudrate into baud code
+ */
+ switch(baudrate) {
+ case 50: baudcode = B50; break;
+ case 75: baudcode = B75; break;
+ case 110: baudcode = B110; break;
+ case 134: baudcode = B134; break;
+ case 150: baudcode = B150; break;
+ case 200: baudcode = B200; break;
+ case 300: baudcode = B300; break;
+ case 600: baudcode = B600; break;
+ case 1200: baudcode = B1200; break;
+ case 1800: baudcode = B1800; break;
+ case 2400: baudcode = B2400; break;
+ case 4800: baudcode = B4800; break;
+ case 9600: baudcode = B9600; break;
+ case 19200: baudcode = B19200; break;
+ case 38400: baudcode = B38400; break;
+ case 57600: baudcode = B57600; break;
+ case 115200: baudcode = B115200; break;
+ case 230400: baudcode = B230400; break;
+ case 460800: baudcode = B460800; break;
+ default : err_occurred = true; errno = EINVAL; break;
+ }
+
+ /*
+ * open device for serdbg operation
+ * skip any fds that are between 0..2, because they are
+ * reserved for stdin/out/err
+ */
+ if (!err_occurred &&
+ (dev_name != NULL) &&
+ (dev_name[0] != '\0')) {
+ do {
+ serdbg_fd = open(dev_name,O_RDWR);
+ if (serdbg_fd < 0) {
+ err_occurred = true;
+ }
+ else {
+ if (serdbg_fd < 3) {
+ if (fd_store_used >= FD_STORE_CNT) {
+ err_occurred = true;
+ }
+ else {
+ fd_store[fd_store_used++] = serdbg_fd;
+ }
+ }
+ }
+ } while (!err_occurred &&
+ (serdbg_fd < 3));
+ }
+ /*
+ * close any fds, that have been placed in fd_store
+ * so fd 0..2 are reusable again
+ */
+ while (--fd_store_used >= 0) {
+ close(fd_store[fd_store_used]);
+ }
+
+ /*
+ * capture tty structure
+ */
+ if (!err_occurred) {
+ iop = &rtems_libio_iops[serdbg_fd];
+ serdbg_tty = iop->data1;
+ }
+ /*
+ * set device baudrate
+ * (and transp mode, this is not really needed)
+ * ...
+ */
+ /*
+ * ... get fd settings
+ */
+ if (!err_occurred &&
+ (0 != tcgetattr(serdbg_fd,&act_termios))) {
+ err_occurred = true;
+ }
+ if (!err_occurred) {
+ act_termios.c_iflag
+ &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+ |INLCR|IGNCR|ICRNL|IXON);
+ act_termios.c_oflag
+ &= ~OPOST;
+
+ act_termios.c_lflag
+ &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+
+ cfsetospeed(&act_termios,baudcode);
+ cfsetispeed(&act_termios,baudcode);
+
+ if (0 != tcsetattr(serdbg_fd,TCSANOW,&act_termios)) {
+ err_occurred = true;
+ }
+ }
+ return (err_occurred
+ ? -1
+ : 0);
+}
+
+void putDebugChar(char c) __attribute__ ((__weak__));
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void putDebugChar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| send one character to serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ char c /* character to print */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+{
+ /*
+ * call serdbg polling callout, if available
+ */
+ if (serdbg_conf.callout != NULL) {
+ serdbg_conf.callout();
+ }
+ /*
+ * check, whether debug serial port is available
+ */
+ if ((serdbg_tty != NULL) &&
+ (serdbg_tty->device.write != NULL)) {
+ /*
+ * send character to debug serial port
+ */
+ serdbg_tty->device.write(serdbg_tty->minor,&c,1);
+ }
+}
+
+int getDebugChar(void) __attribute__ ((__weak__));
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int getDebugChar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| wait for one character from serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ void /* none */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| received character |
+\*=========================================================================*/
+{
+ int c = -1;
+ /*
+ * check, whether debug serial port is available
+ */
+ if ((serdbg_tty != NULL) &&
+ (serdbg_tty->device.pollRead != NULL)) {
+ do {
+ /*
+ * call serdbg polling callout, if available
+ */
+ if (serdbg_conf.callout != NULL) {
+ serdbg_conf.callout();
+ }
+ /*
+ * get character from debug serial port
+ */
+ c = serdbg_tty->device.pollRead(serdbg_tty->minor);
+ } while (c < 0);
+ }
+ return c;
+}
diff --git a/cpukit/libmisc/serdbg/termios_printk.c b/cpukit/libmisc/serdbg/termios_printk.c
new file mode 100644
index 0000000000..bcbfe482fa
--- /dev/null
+++ b/cpukit/libmisc/serdbg/termios_printk.c
@@ -0,0 +1,241 @@
+/*===============================================================*\
+| File: termios_printk.c |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| Hebststr. 8, 82178 Puchheim, Germany |
+| <Thomas.Doerfler@imd-systems.de> |
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| http://www.rtems.com/license/LICENSE. |
+| all rights reserved |
++-----------------------------------------------------------------+
+| TERMIOS printk support |
+| this module performs low-level printk output using |
+| a polled termios driver |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 13.05.02 creation doe |
+|*****************************************************************|
+|* $Id$
+ *
+|*****************************************************************|
+\*===============================================================*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <errno.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <termios.h>
+
+#include <rtems/termiostypes.h>
+#include <rtems/bspIo.h>
+#include <rtems/termios_printk.h>
+
+/*
+ * internal variables
+ */
+int termios_printk_fd = -1;
+struct rtems_termios_tty *termios_printk_tty;
+
+static void _termios_printk_null_char(
+ char c __attribute__((unused)))
+{
+ return;
+}
+
+BSP_output_char_function_type BSP_output_char = _termios_printk_null_char;
+BSP_polling_getchar_function_type BSP_poll_char;
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void termios_printk_outputchar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| send one character to serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ char c /* character to print */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+{
+ static const char cr = '\r';
+ /*
+ * check, whether printk serial port is available
+ */
+
+ if ((termios_printk_tty != NULL) &&
+ (termios_printk_tty->device.write != NULL)) {
+ /*
+ * call termios_printk polling callout, if available
+ */
+ if (termios_printk_conf.callout != NULL) {
+ termios_printk_conf.callout();
+ }
+ /*
+ * send character to debug serial port
+ */
+ if (c == '\n') {
+ termios_printk_tty->device.write(termios_printk_tty->minor,&cr,1);
+ }
+ termios_printk_tty->device.write(termios_printk_tty->minor,&c,1);
+ }
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int termios_printk_inputchar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| wait for one character from serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ void /* none */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| received character |
+\*=========================================================================*/
+{
+ int c = -1;
+ /*
+ * check, whether debug serial port is available
+ */
+ if ((termios_printk_tty != NULL) &&
+ (termios_printk_tty->device.pollRead != NULL)) {
+ do {
+ /*
+ * call termios_printk polling callout, if available
+ */
+ if (termios_printk_conf.callout != NULL) {
+ termios_printk_conf.callout();
+ }
+ /*
+ * get character from debug serial port
+ */
+ c = termios_printk_tty->device.pollRead(termios_printk_tty->minor);
+ } while (c < 0);
+ }
+ return c;
+}
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int termios_printk_open
+
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| try to open given serial debug port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ const char *dev_name, /* name of device to open */
+ uint32_t baudrate /* baud rate to use */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0 on success, -1 and errno otherwise |
+\*=========================================================================*/
+{
+ bool err_occurred = false;
+ rtems_libio_t *iop = NULL;
+ struct termios act_termios;
+ tcflag_t baudcode = B0;
+
+ if (termios_printk_fd >= 0) {
+ /*
+ * already initialized
+ */
+ return 0;
+ }
+ /*
+ * translate baudrate into baud code
+ */
+ switch(baudrate) {
+ case 50: baudcode = B50; break;
+ case 75: baudcode = B75; break;
+ case 110: baudcode = B110; break;
+ case 134: baudcode = B134; break;
+ case 150: baudcode = B150; break;
+ case 200: baudcode = B200; break;
+ case 300: baudcode = B300; break;
+ case 600: baudcode = B600; break;
+ case 1200: baudcode = B1200; break;
+ case 1800: baudcode = B1800; break;
+ case 2400: baudcode = B2400; break;
+ case 4800: baudcode = B4800; break;
+ case 9600: baudcode = B9600; break;
+ case 19200: baudcode = B19200; break;
+ case 38400: baudcode = B38400; break;
+ case 57600: baudcode = B57600; break;
+ case 115200: baudcode = B115200; break;
+ case 230400: baudcode = B230400; break;
+ case 460800: baudcode = B460800; break;
+ default : err_occurred = true; errno = EINVAL; break;
+ }
+ /*
+ * open device for serdbg operation
+ */
+ if (!err_occurred &&
+ (dev_name != NULL) &&
+ (dev_name[0] != '\0')) {
+ termios_printk_fd = open(dev_name,O_RDWR);
+ if (termios_printk_fd < 0) {
+ err_occurred = true;
+ }
+ }
+ /*
+ * capture tty structure
+ */
+ if (!err_occurred) {
+ iop = &rtems_libio_iops[termios_printk_fd];
+ termios_printk_tty = iop->data1;
+ }
+ /*
+ * set device baudrate
+ * (and transp mode, this is not really needed)
+ * ...
+ */
+ /*
+ * ... get fd settings
+ */
+ if (!err_occurred &&
+ (0 != tcgetattr(termios_printk_fd,&act_termios))) {
+ err_occurred = true;
+ }
+ if (!err_occurred) {
+
+ cfsetospeed(&act_termios,baudcode);
+ cfsetispeed(&act_termios,baudcode);
+
+ if (0 != tcsetattr(termios_printk_fd,TCSANOW,&act_termios)) {
+ err_occurred = true;
+ }
+ }
+ if (!err_occurred) {
+ BSP_output_char = termios_printk_outputchar;
+ BSP_poll_char = termios_printk_inputchar;
+ }
+ return (err_occurred
+ ? -1
+ : 0);
+}
diff --git a/cpukit/libmisc/serdbg/termios_printk.h b/cpukit/libmisc/serdbg/termios_printk.h
new file mode 100644
index 0000000000..4f484df62f
--- /dev/null
+++ b/cpukit/libmisc/serdbg/termios_printk.h
@@ -0,0 +1,104 @@
+/*===============================================================*\
+| Project: RTEMS remote gdb over serial line |
++-----------------------------------------------------------------+
+| File: termios_printk.h |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file declares intialization functions to add |
+| printk polled output via termios polled drivers |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 13.04.02 creation doe |
+\*===============================================================*/
+/*
+ * $Id$
+ */
+#ifndef _TERMIOS_PRINTK_H
+#define _TERMIOS_PRINTK_H
+
+#include <rtems.h>
+#include <termios.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uint32_t baudrate; /* debug baud rate, e.g. 57600 */
+ void (*callout)(void); /* callout pointer during polling */
+ const char *devname; /* debug device, e.g. "/dev/tty01" */
+} termios_printk_conf_t;
+
+/*
+ * must be defined in init module...
+ */
+extern termios_printk_conf_t termios_printk_conf;
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void termios_printk_outputchar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| send one character to serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ char c /* character to print */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| <none> |
+\*=========================================================================*/
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int termios_printk_inputchar
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| wait for one character from serial port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ void /* none */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| received character |
+\*=========================================================================*/
+
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+int termios_printk_open
+
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| try to open given serial debug port |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+(
+ const char *dev_name, /* name of device to open */
+ uint32_t baudrate /* baud rate to use */
+ );
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| 0 on success, -1 and errno otherwise |
+\*=========================================================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TERMIOS_PRINTK_H */
diff --git a/cpukit/libmisc/serdbg/termios_printk_cnf.h b/cpukit/libmisc/serdbg/termios_printk_cnf.h
new file mode 100644
index 0000000000..2e8a7ac043
--- /dev/null
+++ b/cpukit/libmisc/serdbg/termios_printk_cnf.h
@@ -0,0 +1,78 @@
+/*===============================================================*\
+| Project: RTEMS configure remote gdb over serial line |
++-----------------------------------------------------------------+
+| File: termios_printk_cnf.h |
++-----------------------------------------------------------------+
+| Copyright (c) 2002 IMD |
+| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
+| <Thomas.Doerfler@imd-systems.de> |
+| all rights reserved |
++-----------------------------------------------------------------+
+| this file declares intialization functions to add |
+| printk support via polled termios |
+| |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 13.05.02 creation doe |
+\*===============================================================*/
+/*
+ * $Id$
+ */
+#ifndef _TERMIOS_PRINTK_CNF_H
+#define _TERMIOS_PRINTK_CNF_H
+
+#include <rtems/termios_printk.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef CONFIGURE_INIT
+
+/*
+ * fallback for baud rate to use
+ */
+#ifndef CONFIGURE_TERMIOS_PRINTK_BAUDRATE
+#define CONFIGURE_TERMIOS_PRINTK_BAUDRATE 9600
+#endif
+
+/*
+ * fallback for device name to use
+ */
+#ifndef CONFIGURE_TERMIOS_PRINTK_DEVNAME
+#define CONFIGURE_TERMIOS_PRINTK_DEVNAME "/dev/console"
+#endif
+
+#ifdef CONFIGURE_USE_TERMIOS_PRINTK
+/*
+ * fill in termios_printk_conf structure
+ */
+termios_printk_conf_t termios_printk_conf = {
+ CONFIGURE_TERMIOS_PRINTK_BAUDRATE,
+
+#ifdef CONFIGURE_TERMIOS_PRINTK_CALLOUT
+ CONFIGURE_TERMIOS_PRINTK_CALLOUT,
+#else
+ NULL,
+#endif
+ CONFIGURE_TERMIOS_PRINTK_DEVNAME,
+};
+#endif
+
+int termios_printk_init(void) {
+#ifdef CONFIGURE_USE_TERMIOS_PRINTK
+ return termios_printk_open(termios_printk_conf.devname,
+ termios_printk_conf.baudrate);
+#else
+ return 0;
+#endif
+}
+
+#endif /* CONFIGURE_INIT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TERMIOS_PRINTK_CNF_H */
diff --git a/cpukit/libmisc/shell/README b/cpukit/libmisc/shell/README
new file mode 100644
index 0000000000..9798becc37
--- /dev/null
+++ b/cpukit/libmisc/shell/README
@@ -0,0 +1,27 @@
+#
+# $Id$
+#
+
+This directory contains a shell user extension
+primary features:
+
+ + create a user shell terminal task.
+
+This code has not been extensively tested. It is provided as a tool
+for RTEMS users to open more shell terminal.
+Suggestions and comments are appreciated.
+
+NOTES:
+
+1. printf() & getchar() works but you can't use
+ 0,1,2 like fildes. You need to use fileno(stdin),fileno(stdout),...
+
+2. You only need a termios dev to start a new session, add your new commands
+ and enjoy it.
+
+3. Telnetd daemon uses this (browse libnetworking/rtems_telnetd)
+ Enjoy it.
+
+FUTURE:
+
+1. Adding new commands in cmds.c to give file manegement to shell.
diff --git a/cpukit/libmisc/shell/cat_file.c b/cpukit/libmisc/shell/cat_file.c
new file mode 100644
index 0000000000..1a5efb4418
--- /dev/null
+++ b/cpukit/libmisc/shell/cat_file.c
@@ -0,0 +1,37 @@
+/*
+ * CAT Command Implementation
+ *
+ * Author:
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+int rtems_shell_cat_file(FILE * out,const char * name) {
+ FILE * fd;
+ int c;
+
+ if (out) {
+ fd = fopen(name,"r");
+ if (!fd) {
+ return -1;
+ }
+ while ((c=fgetc(fd))!=EOF)
+ fputc(c,out);
+ fclose(fd);
+ }
+ return 0;
+}
+
+
diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c
new file mode 100644
index 0000000000..e8d6c581df
--- /dev/null
+++ b/cpukit/libmisc/shell/cmds.c
@@ -0,0 +1,77 @@
+/*
+ * XXX -- Just monitor commands until those can be integrated better
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+/*-----------------------------------------------------------*
+ * with this you can call at all the rtems monitor commands.
+ * Not all work fine but you can show the rtems status and more.
+ *-----------------------------------------------------------*/
+int rtems_shell_main_monitor(int argc, char **argv) {
+ const rtems_monitor_command_entry_t *command = NULL;
+
+ if (argc < 1) {
+ return 1;
+ }
+
+ command = rtems_monitor_command_lookup(argv [0]);
+
+ if (command == NULL) {
+ return 1;
+ }
+
+ command->command_function(argc, argv, &command->command_arg, 0);
+
+ return 0;
+}
+
+static bool rtems_shell_register_command(const rtems_monitor_command_entry_t *e, void *arg __attribute__((unused)))
+{
+ /* Exclude EXIT (alias quit)*/
+ if (strcmp("exit", e->command) != 0) {
+ rtems_shell_cmd_t *shell_cmd =
+ (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
+
+ if (shell_cmd != NULL) {
+ shell_cmd->name = e->command;
+ shell_cmd->topic = "monitor";
+ shell_cmd->usage = e->usage;
+ shell_cmd->command = rtems_shell_main_monitor;
+ shell_cmd->alias = NULL;
+ shell_cmd->next = NULL;
+
+ if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
+ free(shell_cmd);
+ }
+ }
+ }
+
+ return true;
+}
+
+void rtems_shell_register_monitor_commands(void)
+{
+ rtems_monitor_command_iterate(rtems_shell_register_command, NULL);
+}
diff --git a/cpukit/libmisc/shell/cmp-ls.c b/cpukit/libmisc/shell/cmp-ls.c
new file mode 100644
index 0000000000..793e607fe1
--- /dev/null
+++ b/cpukit/libmisc/shell/cmp-ls.c
@@ -0,0 +1,204 @@
+/* $NetBSD: cmp.c,v 1.17 2003/08/07 09:05:14 agc Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Michael Fischbein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: cmp.c,v 1.17 2003/08/07 09:05:14 agc Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <fts.h>
+#include <string.h>
+
+#include "extern-ls.h"
+
+#if defined(__rtems__) || defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || \
+ defined(_XOPEN_SOURCE) || defined(__NetBSD__)
+#define ATIMENSEC_CMP(x, op, y) ((x)->st_atime op (y)->st_atime)
+#define CTIMENSEC_CMP(x, op, y) ((x)->st_ctime op (y)->st_ctime)
+#define MTIMENSEC_CMP(x, op, y) ((x)->st_mtime op (y)->st_mtime)
+#else
+#define ATIMENSEC_CMP(x, op, y) \
+ ((x)->st_atime.tv_nsec op (y)->st_atime.tv_nsec)
+#define CTIMENSEC_CMP(x, op, y) \
+ ((x)->st_ctime.tv_nsec op (y)->st_ctime.tv_nsec)
+#define MTIMENSEC_CMP(x, op, y) \
+ ((x)->st_mtime.tv_nsec op (y)->st_mtime.tv_nsec)
+#endif
+
+int
+namecmp(const FTSENT *a, const FTSENT *b)
+{
+
+ return (strcmp(a->fts_name, b->fts_name));
+}
+
+int
+revnamecmp(const FTSENT *a, const FTSENT *b)
+{
+
+ return (strcmp(b->fts_name, a->fts_name));
+}
+
+int
+modcmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_mtime > a->fts_statp->st_mtime)
+ return (1);
+ else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime)
+ return (-1);
+ else if (MTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
+ return (1);
+ else if (MTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
+ return (-1);
+ else
+ return (namecmp(a, b));
+}
+
+int
+revmodcmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_mtime > a->fts_statp->st_mtime)
+ return (-1);
+ else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime)
+ return (1);
+ else if (MTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
+ return (-1);
+ else if (MTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
+ return (1);
+ else
+ return (revnamecmp(a, b));
+}
+
+int
+acccmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_atime > a->fts_statp->st_atime)
+ return (1);
+ else if (b->fts_statp->st_atime < a->fts_statp->st_atime)
+ return (-1);
+ else if (ATIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
+ return (1);
+ else if (ATIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
+ return (-1);
+ else
+ return (namecmp(a, b));
+}
+
+int
+revacccmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_atime > a->fts_statp->st_atime)
+ return (-1);
+ else if (b->fts_statp->st_atime < a->fts_statp->st_atime)
+ return (1);
+ else if (ATIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
+ return (-1);
+ else if (ATIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
+ return (1);
+ else
+ return (revnamecmp(a, b));
+}
+
+int
+statcmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_ctime > a->fts_statp->st_ctime)
+ return (1);
+ else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime)
+ return (-1);
+ else if (CTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
+ return (1);
+ else if (CTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
+ return (-1);
+ else
+ return (namecmp(a, b));
+}
+
+int
+revstatcmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_ctime > a->fts_statp->st_ctime)
+ return (-1);
+ else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime)
+ return (1);
+ else if (CTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
+ return (-1);
+ else if (CTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
+ return (1);
+ else
+ return (revnamecmp(a, b));
+}
+
+int
+sizecmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_size > a->fts_statp->st_size)
+ return (1);
+ if (b->fts_statp->st_size < a->fts_statp->st_size)
+ return (-1);
+ else
+ return (namecmp(a, b));
+}
+
+int
+revsizecmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_size > a->fts_statp->st_size)
+ return (-1);
+ if (b->fts_statp->st_size < a->fts_statp->st_size)
+ return (1);
+ else
+ return (revnamecmp(a, b));
+}
diff --git a/cpukit/libmisc/shell/dd-args.c b/cpukit/libmisc/shell/dd-args.c
new file mode 100644
index 0000000000..a271287166
--- /dev/null
+++ b/cpukit/libmisc/shell/dd-args.c
@@ -0,0 +1,507 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
+#endif
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/dd/args.c,v 1.40 2004/08/15 19:10:05 rwatson Exp $");
+
+#include <sys/types.h>
+
+#include <err.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dd.h"
+#include "extern-dd.h"
+
+#define strtouq strtoul
+#define strtoq strtol
+
+static int c_arg(const void *, const void *);
+static int c_conv(const void *, const void *);
+static void f_bs(rtems_shell_dd_globals* globals, char *);
+static void f_cbs(rtems_shell_dd_globals* globals, char *);
+static void f_conv(rtems_shell_dd_globals* globals, char *);
+static void f_count(rtems_shell_dd_globals* globals, char *);
+static void f_files(rtems_shell_dd_globals* globals, char *);
+static void f_fillchar(rtems_shell_dd_globals* globals, char *);
+static void f_ibs(rtems_shell_dd_globals* globals, char *);
+static void f_if(rtems_shell_dd_globals* globals, char *);
+static void f_obs(rtems_shell_dd_globals* globals, char *);
+static void f_of(rtems_shell_dd_globals* globals, char *);
+static void f_seek(rtems_shell_dd_globals* globals, char *);
+static void f_skip(rtems_shell_dd_globals* globals, char *);
+static uintmax_t get_num(rtems_shell_dd_globals* globals, const char *);
+static off_t get_off_t(rtems_shell_dd_globals* globals, const char *);
+
+static const struct arg {
+ const char *name;
+ void (*f)(rtems_shell_dd_globals* globals, char *);
+ uint_least32_t set, noset;
+} args[] = {
+ { "bs", f_bs, C_BS, C_BS|C_IBS|C_OBS|C_OSYNC },
+ { "cbs", f_cbs, C_CBS, C_CBS },
+ { "conv", f_conv, 0, 0 },
+ { "count", f_count, C_COUNT, C_COUNT },
+ { "files", f_files, C_FILES, C_FILES },
+ { "fillchar", f_fillchar, C_FILL, C_FILL },
+ { "ibs", f_ibs, C_IBS, C_BS|C_IBS },
+ { "if", f_if, C_IF, C_IF },
+ { "iseek", f_skip, C_SKIP, C_SKIP },
+ { "obs", f_obs, C_OBS, C_BS|C_OBS },
+ { "of", f_of, C_OF, C_OF },
+ { "oseek", f_seek, C_SEEK, C_SEEK },
+ { "seek", f_seek, C_SEEK, C_SEEK },
+ { "skip", f_skip, C_SKIP, C_SKIP },
+};
+
+static char *oper;
+
+/*
+ * args -- parse JCL syntax of dd.
+ */
+void
+jcl(rtems_shell_dd_globals* globals, char **argv)
+{
+ struct arg *ap, tmp;
+ char *arg;
+
+ oper = NULL;
+
+ in.dbsz = out.dbsz = 512;
+
+ while ((oper = *++argv) != NULL) {
+// if ((oper = strdup(oper)) == NULL)
+// errx(exit_jump, 1, "unable to allocate space for the argument \"%s\"", *argv);
+ if ((arg = strchr(oper, '=')) == NULL)
+ errx(exit_jump, 1, "unknown operand %s", oper);
+ *arg++ = '\0';
+ if (!*arg)
+ errx(exit_jump, 1, "no value specified for %s", oper);
+ tmp.name = oper;
+ if (!(ap = (struct arg *)bsearch(&tmp, args,
+ sizeof(args)/sizeof(struct arg), sizeof(struct arg),
+ c_arg)))
+ errx(exit_jump, 1, "unknown operand %s", tmp.name);
+ if (ddflags & ap->noset)
+ errx(exit_jump, 1, "%s: illegal argument combination or already set",
+ tmp.name);
+ ddflags |= ap->set;
+ ap->f(globals, arg);
+ }
+
+ /* Final sanity checks. */
+
+ if (ddflags & C_BS) {
+ /*
+ * Bs is turned off by any conversion -- we assume the user
+ * just wanted to set both the input and output block sizes
+ * and didn't want the bs semantics, so we don't warn.
+ */
+ if (ddflags & (C_BLOCK | C_LCASE | C_SWAB | C_UCASE |
+ C_UNBLOCK))
+ ddflags &= ~C_BS;
+
+ /* Bs supersedes ibs and obs. */
+ if (ddflags & C_BS && ddflags & (C_IBS | C_OBS))
+ warnx("bs supersedes ibs and obs");
+ }
+
+ /*
+ * Ascii/ebcdic and cbs implies block/unblock.
+ * Block/unblock requires cbs and vice-versa.
+ */
+ if (ddflags & (C_BLOCK | C_UNBLOCK)) {
+ if (!(ddflags & C_CBS))
+ errx(exit_jump, 1, "record operations require cbs");
+ if (cbsz == 0)
+ errx(exit_jump, 1, "cbs cannot be zero");
+ cfunc = ddflags & C_BLOCK ? block : unblock;
+ } else if (ddflags & C_CBS) {
+ if (ddflags & (C_ASCII | C_EBCDIC)) {
+ if (ddflags & C_ASCII) {
+ ddflags |= C_UNBLOCK;
+ cfunc = unblock;
+ } else {
+ ddflags |= C_BLOCK;
+ cfunc = block;
+ }
+ } else
+ errx(exit_jump, 1, "cbs meaningless if not doing record operations");
+ } else
+ cfunc = def;
+
+ /*
+ * Bail out if the calculation of a file offset would overflow.
+ */
+ if (in.offset > OFF_MAX / (ssize_t)in.dbsz ||
+ out.offset > OFF_MAX / (ssize_t)out.dbsz)
+ errx(exit_jump, 1, "seek offsets cannot be larger than %jd",
+ (intmax_t)OFF_MAX);
+}
+
+static int
+c_arg(const void *a, const void *b)
+{
+
+ return (strcmp(((const struct arg *)a)->name,
+ ((const struct arg *)b)->name));
+}
+
+static void
+f_bs(rtems_shell_dd_globals* globals, char *arg)
+{
+ uintmax_t res;
+
+ res = get_num(globals, arg);
+ if (res < 1 || res > SSIZE_MAX)
+ errx(exit_jump, 1, "bs must be between 1 and %jd", (intmax_t)SSIZE_MAX);
+ in.dbsz = out.dbsz = (size_t)res;
+}
+
+static void
+f_cbs(rtems_shell_dd_globals* globals, char *arg)
+{
+ uintmax_t res;
+
+ res = get_num(globals, arg);
+ if (res < 1 || res > SSIZE_MAX)
+ errx(exit_jump, 1, "cbs must be between 1 and %jd", (intmax_t)SSIZE_MAX);
+ cbsz = (size_t)res;
+}
+
+static void
+f_count(rtems_shell_dd_globals* globals, char *arg)
+{
+ intmax_t res;
+
+ res = (intmax_t)get_num(globals, arg);
+ if (res < 0)
+ errx(exit_jump, 1, "count cannot be negative");
+ if (res == 0)
+ cpy_cnt = (uintmax_t)-1;
+ else
+ cpy_cnt = (uintmax_t)res;
+}
+
+static void
+f_files(rtems_shell_dd_globals* globals, char *arg)
+{
+
+ files_cnt = get_num(globals, arg);
+ if (files_cnt < 1)
+ errx(exit_jump, 1, "files must be between 1 and %jd", (uintmax_t)-1);
+}
+
+static void
+f_fillchar(rtems_shell_dd_globals* globals, char *arg)
+{
+
+ if (strlen(arg) != 1)
+ errx(exit_jump, 1, "need exactly one fill char");
+
+ fill_char = arg[0];
+}
+
+static void
+f_ibs(rtems_shell_dd_globals* globals, char *arg)
+{
+ uintmax_t res;
+
+ if (!(ddflags & C_BS)) {
+ res = get_num(globals, arg);
+ if (res < 1 || res > SSIZE_MAX)
+ errx(exit_jump, 1, "ibs must be between 1 and %jd",
+ (intmax_t)SSIZE_MAX);
+ in.dbsz = (size_t)res;
+ }
+}
+
+static void
+f_if(rtems_shell_dd_globals* globals, char *arg)
+{
+
+ in.name = strdup(arg);
+}
+
+static void
+f_obs(rtems_shell_dd_globals* globals, char *arg)
+{
+ uintmax_t res;
+
+ if (!(ddflags & C_BS)) {
+ res = get_num(globals, arg);
+ if (res < 1 || res > SSIZE_MAX)
+ errx(exit_jump, 1, "obs must be between 1 and %jd",
+ (intmax_t)SSIZE_MAX);
+ out.dbsz = (size_t)res;
+ }
+}
+
+static void
+f_of(rtems_shell_dd_globals* globals, char *arg)
+{
+
+ out.name = strdup(arg);
+}
+
+static void
+f_seek(rtems_shell_dd_globals* globals, char *arg)
+{
+
+ out.offset = get_off_t(globals, arg);
+}
+
+static void
+f_skip(rtems_shell_dd_globals* globals, char *arg)
+{
+
+ in.offset = get_off_t(globals, arg);
+}
+
+static const struct conv {
+ const char *name;
+ uint_least32_t set, noset;
+ const u_char *ctab_;
+} clist[] = {
+ { "ascii", C_ASCII, C_EBCDIC, e2a_POSIX },
+ { "block", C_BLOCK, C_UNBLOCK, NULL },
+ { "ebcdic", C_EBCDIC, C_ASCII, a2e_POSIX },
+ { "ibm", C_EBCDIC, C_ASCII, a2ibm_POSIX },
+ { "lcase", C_LCASE, C_UCASE, NULL },
+ { "noerror", C_NOERROR, 0, NULL },
+ { "notrunc", C_NOTRUNC, 0, NULL },
+ { "oldascii", C_ASCII, C_EBCDIC, e2a_32V },
+ { "oldebcdic", C_EBCDIC, C_ASCII, a2e_32V },
+ { "oldibm", C_EBCDIC, C_ASCII, a2ibm_32V },
+ { "osync", C_OSYNC, C_BS, NULL },
+ { "pareven", C_PAREVEN, C_PARODD|C_PARSET|C_PARNONE, NULL},
+ { "parnone", C_PARNONE, C_PARODD|C_PARSET|C_PAREVEN, NULL},
+ { "parodd", C_PARODD, C_PAREVEN|C_PARSET|C_PARNONE, NULL},
+ { "parset", C_PARSET, C_PARODD|C_PAREVEN|C_PARNONE, NULL},
+ { "sparse", C_SPARSE, 0, NULL },
+ { "swab", C_SWAB, 0, NULL },
+ { "sync", C_SYNC, 0, NULL },
+ { "ucase", C_UCASE, C_LCASE, NULL },
+ { "unblock", C_UNBLOCK, C_BLOCK, NULL },
+};
+
+static void
+f_conv(rtems_shell_dd_globals* globals, char *arg)
+{
+ struct conv *cp, tmp;
+
+ while (arg != NULL) {
+ tmp.name = strsep(&arg, ",");
+ cp = bsearch(&tmp, clist, sizeof(clist) / sizeof(struct conv),
+ sizeof(struct conv), c_conv);
+ if (cp == NULL)
+ errx(exit_jump, 1, "unknown conversion %s", tmp.name);
+ if (ddflags & cp->noset)
+ errx(exit_jump, 1, "%s: illegal conversion combination", tmp.name);
+ ddflags |= cp->set;
+ if (cp->ctab_)
+ ctab = cp->ctab_;
+ }
+}
+
+static int
+c_conv(const void *a, const void *b)
+{
+
+ return (strcmp(((const struct conv *)a)->name,
+ ((const struct conv *)b)->name));
+}
+
+/*
+ * Convert an expression of the following forms to a uintmax_t.
+ * 1) A positive decimal number.
+ * 2) A positive decimal number followed by a 'b' or 'B' (mult by 512).
+ * 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
+ * 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
+ * 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
+ * 5) A positive decimal number followed by a 'w' or 'W' (mult by sizeof int).
+ * 6) Two or more positive decimal numbers (with/without [BbKkMmGgWw])
+ * separated by 'x' or 'X' (also '*' for backwards compatibility),
+ * specifying the product of the indicated values.
+ */
+static uintmax_t
+get_num(rtems_shell_dd_globals* globals, const char *val)
+{
+ uintmax_t num, mult, prevnum;
+ char *expr;
+
+ errno = 0;
+ num = strtouq(val, &expr, 0);
+ if (errno != 0) /* Overflow or underflow. */
+ err(exit_jump, 1, "%s", oper);
+
+ if (expr == val) /* No valid digits. */
+ errx(exit_jump, 1, "%s: illegal numeric value", oper);
+
+ mult = 0;
+ switch (*expr) {
+ case 'B':
+ case 'b':
+ mult = UINT32_C(512);
+ break;
+ case 'K':
+ case 'k':
+ mult = UINT32_C(1) << 10;
+ break;
+ case 'M':
+ case 'm':
+ mult = UINT32_C(1) << 20;
+ break;
+ case 'G':
+ case 'g':
+ mult = UINT32_C(1) << 30;
+ break;
+ case 'W':
+ case 'w':
+ mult = sizeof(int);
+ break;
+ default:
+ ;
+ }
+
+ if (mult != 0) {
+ prevnum = num;
+ num *= mult;
+ /* Check for overflow. */
+ if (num / mult != prevnum)
+ goto erange;
+ expr++;
+ }
+
+ switch (*expr) {
+ case '\0':
+ break;
+ case '*': /* Backward compatible. */
+ case 'X':
+ case 'x':
+ mult = get_num(globals, expr + 1);
+ prevnum = num;
+ num *= mult;
+ if (num / mult == prevnum)
+ break;
+erange:
+ errx(exit_jump, 1, "%s: %s", oper, strerror(ERANGE));
+ default:
+ errx(exit_jump, 1, "%s: illegal numeric value", oper);
+ }
+ return (num);
+}
+
+/*
+ * Convert an expression of the following forms to an off_t. This is the
+ * same as get_num(), but it uses signed numbers.
+ *
+ * The major problem here is that an off_t may not necessarily be a intmax_t.
+ */
+static off_t
+get_off_t(rtems_shell_dd_globals* globals, const char *val)
+{
+ intmax_t num, mult, prevnum;
+ char *expr;
+
+ errno = 0;
+ num = strtoq(val, &expr, 0);
+ if (errno != 0) /* Overflow or underflow. */
+ err(exit_jump, 1, "%s", oper);
+
+ if (expr == val) /* No valid digits. */
+ errx(exit_jump, 1, "%s: illegal numeric value", oper);
+
+ mult = 0;
+ switch (*expr) {
+ case 'B':
+ case 'b':
+ mult = UINT32_C(512);
+ break;
+ case 'K':
+ case 'k':
+ mult = UINT32_C(1) << 10;
+ break;
+ case 'M':
+ case 'm':
+ mult = UINT32_C(1) << 20;
+ break;
+ case 'G':
+ case 'g':
+ mult = UINT32_C(1) << 30;
+ break;
+ case 'W':
+ case 'w':
+ mult = sizeof(int);
+ break;
+ }
+
+ if (mult != 0) {
+ prevnum = num;
+ num *= mult;
+ /* Check for overflow. */
+ if ((prevnum > 0) != (num > 0) || num / mult != prevnum)
+ goto erange;
+ expr++;
+ }
+
+ switch (*expr) {
+ case '\0':
+ break;
+ case '*': /* Backward compatible. */
+ case 'X':
+ case 'x':
+ mult = (intmax_t)get_off_t(globals, expr + 1);
+ prevnum = num;
+ num *= mult;
+ if ((prevnum > 0) == (num > 0) && num / mult == prevnum)
+ break;
+erange:
+ errx(exit_jump, 1, "%s: %s", oper, strerror(ERANGE));
+ default:
+ errx(exit_jump, 1, "%s: illegal numeric value", oper);
+ }
+ return (num);
+}
diff --git a/cpukit/libmisc/shell/dd-conv.c b/cpukit/libmisc/shell/dd-conv.c
new file mode 100644
index 0000000000..81dba4798b
--- /dev/null
+++ b/cpukit/libmisc/shell/dd-conv.c
@@ -0,0 +1,272 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
+#endif
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/dd/conv.c,v 1.19 2004/04/06 20:06:45 markm Exp $");
+
+#include <sys/param.h>
+
+#include <err.h>
+#include <inttypes.h>
+#include <string.h>
+
+#include "dd.h"
+#include "extern-dd.h"
+
+/*
+ * def --
+ * Copy input to output. Input is buffered until reaches obs, and then
+ * output until less than obs remains. Only a single buffer is used.
+ * Worst case buffer calculation is (ibs + obs - 1).
+ */
+void
+def(rtems_shell_dd_globals* globals)
+{
+ u_char *inp;
+ const u_char *t;
+ size_t cnt;
+
+ if ((t = ctab) != NULL)
+ for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
+ *inp = t[*inp];
+
+ /* Make the output buffer look right. */
+ out.dbp = in.dbp;
+ out.dbcnt = in.dbcnt;
+
+ if (in.dbcnt >= out.dbsz) {
+ /* If the output buffer is full, write it. */
+ dd_out(globals, 0);
+
+ /*
+ * Ddout copies the leftover output to the beginning of
+ * the buffer and resets the output buffer. Reset the
+ * input buffer to match it.
+ */
+ in.dbp = out.dbp;
+ in.dbcnt = out.dbcnt;
+ }
+}
+
+void
+def_close(rtems_shell_dd_globals* globals)
+{
+ /* Just update the count, everything is already in the buffer. */
+ if (in.dbcnt)
+ out.dbcnt = in.dbcnt;
+}
+
+/*
+ * Copy variable length newline terminated records with a max size cbsz
+ * bytes to output. Records less than cbs are padded with spaces.
+ *
+ * max in buffer: MAX(ibs, cbsz)
+ * max out buffer: obs + cbsz
+ */
+void
+block(rtems_shell_dd_globals* globals)
+{
+ u_char *inp, *outp;
+ const u_char *t;
+ size_t cnt, maxlen;
+ static int intrunc;
+ int ch;
+
+ /*
+ * Record truncation can cross block boundaries. If currently in a
+ * truncation state, keep tossing characters until reach a newline.
+ * Start at the beginning of the buffer, as the input buffer is always
+ * left empty.
+ */
+ if (intrunc) {
+ for (inp = in.db, cnt = in.dbrcnt; cnt && *inp++ != '\n'; --cnt)
+ ;
+ if (!cnt) {
+ in.dbcnt = 0;
+ in.dbp = in.db;
+ return;
+ }
+ intrunc = 0;
+ /* Adjust the input buffer numbers. */
+ in.dbcnt = cnt - 1;
+ in.dbp = inp + cnt - 1;
+ }
+
+ /*
+ * Copy records (max cbsz size chunks) into the output buffer. The
+ * translation is done as we copy into the output buffer.
+ */
+ ch = 0;
+ for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
+ maxlen = MIN(cbsz, in.dbcnt);
+ if ((t = ctab) != NULL)
+ for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
+ ++cnt)
+ *outp++ = t[ch];
+ else
+ for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
+ ++cnt)
+ *outp++ = ch;
+ /*
+ * Check for short record without a newline. Reassemble the
+ * input block.
+ */
+ if (ch != '\n' && in.dbcnt < cbsz) {
+ (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
+ break;
+ }
+
+ /* Adjust the input buffer numbers. */
+ in.dbcnt -= cnt;
+ if (ch == '\n')
+ --in.dbcnt;
+
+ /* Pad short records with spaces. */
+ if (cnt < cbsz)
+ (void)memset(outp, ctab ? ctab[' '] : ' ', cbsz - cnt);
+ else {
+ /*
+ * If the next character wouldn't have ended the
+ * block, it's a truncation.
+ */
+ if (!in.dbcnt || *inp != '\n')
+ ++st.trunc;
+
+ /* Toss characters to a newline. */
+ for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt)
+ ;
+ if (!in.dbcnt)
+ intrunc = 1;
+ else
+ --in.dbcnt;
+ }
+
+ /* Adjust output buffer numbers. */
+ out.dbp += cbsz;
+ if ((out.dbcnt += cbsz) >= out.dbsz)
+ dd_out(globals, 0);
+ outp = out.dbp;
+ }
+ in.dbp = in.db + in.dbcnt;
+}
+
+void
+block_close(rtems_shell_dd_globals* globals)
+{
+ /*
+ * Copy any remaining data into the output buffer and pad to a record.
+ * Don't worry about truncation or translation, the input buffer is
+ * always empty when truncating, and no characters have been added for
+ * translation. The bottom line is that anything left in the input
+ * buffer is a truncated record. Anything left in the output buffer
+ * just wasn't big enough.
+ */
+ if (in.dbcnt) {
+ ++st.trunc;
+ (void)memmove(out.dbp, in.dbp - in.dbcnt, in.dbcnt);
+ (void)memset(out.dbp + in.dbcnt, ctab ? ctab[' '] : ' ',
+ cbsz - in.dbcnt);
+ out.dbcnt += cbsz;
+ }
+}
+
+/*
+ * Convert fixed length (cbsz) records to variable length. Deletes any
+ * trailing blanks and appends a newline.
+ *
+ * max in buffer: MAX(ibs, cbsz) + cbsz
+ * max out buffer: obs + cbsz
+ */
+void
+unblock(rtems_shell_dd_globals* globals)
+{
+ u_char *inp;
+ const u_char *t;
+ size_t cnt;
+
+ /* Translation and case conversion. */
+ if ((t = ctab) != NULL)
+ for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
+ *inp = t[*inp];
+ /*
+ * Copy records (max cbsz size chunks) into the output buffer. The
+ * translation has to already be done or we might not recognize the
+ * spaces.
+ */
+ for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
+ for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
+ ;
+ if (t >= inp) {
+ cnt = t - inp + 1;
+ (void)memmove(out.dbp, inp, cnt);
+ out.dbp += cnt;
+ out.dbcnt += cnt;
+ }
+ *out.dbp++ = '\n';
+ if (++out.dbcnt >= out.dbsz)
+ dd_out(globals, 0);
+ }
+ if (in.dbcnt)
+ (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
+ in.dbp = in.db + in.dbcnt;
+}
+
+void
+unblock_close(rtems_shell_dd_globals* globals)
+{
+ u_char *t;
+ size_t cnt;
+
+ if (in.dbcnt) {
+ warnx("%s: short input record", in.name);
+ for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t)
+ ;
+ if (t >= in.db) {
+ cnt = t - in.db + 1;
+ (void)memmove(out.dbp, in.db, cnt);
+ out.dbp += cnt;
+ out.dbcnt += cnt;
+ }
+ ++out.dbcnt;
+ *out.dbp++ = '\n';
+ }
+}
diff --git a/cpukit/libmisc/shell/dd-conv_tab.c b/cpukit/libmisc/shell/dd-conv_tab.c
new file mode 100644
index 0000000000..782ed97be1
--- /dev/null
+++ b/cpukit/libmisc/shell/dd-conv_tab.c
@@ -0,0 +1,288 @@
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)conv_tab.c 8.1 (Berkeley) 5/31/93";
+#endif
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/dd/conv_tab.c,v 1.12 2004/04/06 20:06:45 markm Exp $");
+
+#include <sys/types.h>
+
+/*
+ * There are currently six tables:
+ *
+ * ebcdic -> ascii 32V conv=oldascii
+ * ascii -> ebcdic 32V conv=oldebcdic
+ * ascii -> ibm ebcdic 32V conv=oldibm
+ *
+ * ebcdic -> ascii POSIX/S5 conv=ascii
+ * ascii -> ebcdic POSIX/S5 conv=ebcdic
+ * ascii -> ibm ebcdic POSIX/S5 conv=ibm
+ *
+ * Other tables are built from these if multiple conversions are being
+ * done.
+ *
+ * Tables used for conversions to/from IBM and EBCDIC to support an extension
+ * to POSIX P1003.2/D11. The tables referencing POSIX contain data extracted
+ * from tables 4-3 and 4-4 in P1003.2/Draft 11. The historic tables were
+ * constructed by running against a file with all possible byte values.
+ *
+ * More information can be obtained in "Correspondences of 8-Bit and Hollerith
+ * Codes for Computer Environments-A USASI Tutorial", Communications of the
+ * ACM, Volume 11, Number 11, November 1968, pp. 783-789.
+ */
+
+u_char casetab[256];
+
+/* EBCDIC to ASCII -- 32V compatible. */
+const u_char e2a_32V[] = {
+ 0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, /* 0000 */
+ 0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017, /* 0010 */
+ 0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, /* 0020 */
+ 0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037, /* 0030 */
+ 0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, /* 0040 */
+ 0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007, /* 0050 */
+ 0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, /* 0060 */
+ 0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032, /* 0070 */
+ 0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, /* 0100 */
+ 0247, 0250, 0133, 0056, 0074, 0050, 0053, 0041, /* 0110 */
+ 0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, /* 0120 */
+ 0260, 0261, 0135, 0044, 0052, 0051, 0073, 0136, /* 0130 */
+ 0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, /* 0140 */
+ 0270, 0271, 0174, 0054, 0045, 0137, 0076, 0077, /* 0150 */
+ 0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, /* 0160 */
+ 0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042, /* 0170 */
+ 0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, /* 0200 */
+ 0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311, /* 0210 */
+ 0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, /* 0220 */
+ 0161, 0162, 0313, 0314, 0315, 0316, 0317, 0320, /* 0230 */
+ 0321, 0176, 0163, 0164, 0165, 0166, 0167, 0170, /* 0240 */
+ 0171, 0172, 0322, 0323, 0324, 0325, 0326, 0327, /* 0250 */
+ 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, /* 0260 */
+ 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, /* 0270 */
+ 0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, /* 0300 */
+ 0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355, /* 0310 */
+ 0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, /* 0320 */
+ 0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363, /* 0330 */
+ 0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, /* 0340 */
+ 0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371, /* 0350 */
+ 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, /* 0360 */
+ 0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
+};
+
+/* ASCII to EBCDIC -- 32V compatible. */
+const u_char a2e_32V[] = {
+ 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
+ 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
+ 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
+ 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
+ 0100, 0117, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
+ 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
+ 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
+ 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
+ 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
+ 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
+ 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
+ 0347, 0350, 0351, 0112, 0340, 0132, 0137, 0155, /* 0130 */
+ 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
+ 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
+ 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
+ 0247, 0250, 0251, 0300, 0152, 0320, 0241, 0007, /* 0170 */
+ 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
+ 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
+ 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
+ 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
+ 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
+ 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
+ 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
+ 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
+ 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
+ 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
+ 0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
+ 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
+ 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
+ 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
+ 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
+ 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
+};
+
+/* ASCII to IBM EBCDIC -- 32V compatible. */
+const u_char a2ibm_32V[] = {
+ 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
+ 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
+ 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
+ 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
+ 0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
+ 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
+ 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
+ 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
+ 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
+ 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
+ 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
+ 0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155, /* 0130 */
+ 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
+ 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
+ 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
+ 0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007, /* 0170 */
+ 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
+ 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
+ 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
+ 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
+ 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
+ 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
+ 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
+ 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
+ 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
+ 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
+ 0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
+ 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
+ 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
+ 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
+ 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
+ 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
+};
+
+/* EBCDIC to ASCII -- POSIX and System V compatible. */
+const u_char e2a_POSIX[] = {
+ 0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, /* 0000 */
+ 0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017, /* 0010 */
+ 0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, /* 0020 */
+ 0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037, /* 0030 */
+ 0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, /* 0040 */
+ 0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007, /* 0050 */
+ 0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, /* 0060 */
+ 0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032, /* 0070 */
+ 0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, /* 0100 */
+ 0247, 0250, 0325, 0056, 0074, 0050, 0053, 0174, /* 0110 */
+ 0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, /* 0120 */
+ 0260, 0261, 0041, 0044, 0052, 0051, 0073, 0176, /* 0130 */
+ 0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, /* 0140 */
+ 0270, 0271, 0313, 0054, 0045, 0137, 0076, 0077, /* 0150 */
+ 0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, /* 0160 */
+ 0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042, /* 0170 */
+ 0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, /* 0200 */
+ 0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311, /* 0210 */
+ 0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, /* 0220 */
+ 0161, 0162, 0136, 0314, 0315, 0316, 0317, 0320, /* 0230 */
+ 0321, 0345, 0163, 0164, 0165, 0166, 0167, 0170, /* 0240 */
+ 0171, 0172, 0322, 0323, 0324, 0133, 0326, 0327, /* 0250 */
+ 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, /* 0260 */
+ 0340, 0341, 0342, 0343, 0344, 0135, 0346, 0347, /* 0270 */
+ 0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, /* 0300 */
+ 0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355, /* 0310 */
+ 0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, /* 0320 */
+ 0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363, /* 0330 */
+ 0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, /* 0340 */
+ 0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371, /* 0350 */
+ 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, /* 0360 */
+ 0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
+};
+
+/* ASCII to EBCDIC -- POSIX and System V compatible. */
+const u_char a2e_POSIX[] = {
+ 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
+ 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
+ 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
+ 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
+ 0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
+ 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
+ 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
+ 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
+ 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
+ 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
+ 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
+ 0347, 0350, 0351, 0255, 0340, 0275, 0232, 0155, /* 0130 */
+ 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
+ 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
+ 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
+ 0247, 0250, 0251, 0300, 0117, 0320, 0137, 0007, /* 0170 */
+ 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
+ 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
+ 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
+ 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
+ 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
+ 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
+ 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
+ 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
+ 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
+ 0216, 0217, 0220, 0152, 0233, 0234, 0235, 0236, /* 0310 */
+ 0237, 0240, 0252, 0253, 0254, 0112, 0256, 0257, /* 0320 */
+ 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
+ 0270, 0271, 0272, 0273, 0274, 0241, 0276, 0277, /* 0340 */
+ 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
+ 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
+ 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
+};
+
+/* ASCII to IBM EBCDIC -- POSIX and System V compatible. */
+const u_char a2ibm_POSIX[] = {
+ 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
+ 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
+ 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
+ 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
+ 0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
+ 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
+ 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
+ 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
+ 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
+ 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
+ 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
+ 0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155, /* 0130 */
+ 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
+ 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
+ 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
+ 0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007, /* 0170 */
+ 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
+ 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
+ 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
+ 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
+ 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
+ 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
+ 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
+ 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
+ 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
+ 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
+ 0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
+ 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
+ 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
+ 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
+ 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
+ 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
+};
diff --git a/cpukit/libmisc/shell/dd-misc.c b/cpukit/libmisc/shell/dd-misc.c
new file mode 100644
index 0000000000..dc5cc0eb09
--- /dev/null
+++ b/cpukit/libmisc/shell/dd-misc.c
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
+#endif
+#endif /* not lint */
+#if 0
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/dd/misc.c,v 1.27 2004/04/06 20:06:46 markm Exp $");
+#endif
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "dd.h"
+#include "extern-dd.h"
+
+void
+summary(rtems_shell_dd_globals* globals)
+{
+ struct timeval tv;
+ double secs;
+ char buf[100];
+
+ (void)gettimeofday(&tv, (struct timezone *)NULL);
+ secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
+ if (secs < 1e-6)
+ secs = 1e-6;
+ /* Use snprintf(3) so that we don't reenter stdio(3). */
+ (void)snprintf(buf, sizeof(buf),
+ "%ju+%ju records in\n%ju+%ju records out\n",
+ st.in_full, st.in_part, st.out_full, st.out_part);
+ (void)write(STDERR_FILENO, buf, strlen(buf));
+ if (st.swab) {
+ (void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
+ st.swab, (st.swab == 1) ? "block" : "blocks");
+ (void)write(STDERR_FILENO, buf, strlen(buf));
+ }
+ if (st.trunc) {
+ (void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
+ st.trunc, (st.trunc == 1) ? "block" : "blocks");
+ (void)write(STDERR_FILENO, buf, strlen(buf));
+ }
+ (void)snprintf(buf, sizeof(buf),
+ "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
+ st.bytes, secs, st.bytes / secs);
+ (void)write(STDERR_FILENO, buf, strlen(buf));
+}
+
+/* ARGSUSED */
+void
+summaryx(rtems_shell_dd_globals* globals, int __unused)
+{
+ int save_errno = errno;
+
+ summary(globals);
+ errno = save_errno;
+}
+
+#if RTEMS_REMOVED
+/* ARGSUSED */
+void
+terminate(int sig)
+{
+
+ summary();
+ _exit(sig == 0 ? 0 : 1);
+}
+#endif
diff --git a/cpukit/libmisc/shell/dd-position.c b/cpukit/libmisc/shell/dd-position.c
new file mode 100644
index 0000000000..7586faddf8
--- /dev/null
+++ b/cpukit/libmisc/shell/dd-position.c
@@ -0,0 +1,193 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/dd/position.c,v 1.23 2004/04/06 20:06:46 markm Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/types.h>
+#if RTEMS_REMOVED
+#include <sys/mtio.h>
+#endif
+
+#include <err.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include "dd.h"
+#include "extern-dd.h"
+
+/*
+ * Position input/output data streams before starting the copy. Device type
+ * dependent. Seekable devices use lseek, and the rest position by reading.
+ * Seeking past the end of file can cause null blocks to be written to the
+ * output.
+ */
+void
+pos_in(rtems_shell_dd_globals* globals)
+{
+ off_t cnt;
+ int warned;
+ ssize_t nr;
+ size_t bcnt;
+
+ /* If known to be seekable, try to seek on it. */
+ if (in.flags & ISSEEK) {
+ errno = 0;
+ if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1 &&
+ errno != 0)
+ err(exit_jump, 1, "%s", in.name);
+ return;
+ }
+
+ /* Don't try to read a really weird amount (like negative). */
+ if (in.offset < 0)
+ errx(exit_jump, 1, "%s: illegal offset", "iseek/skip");
+
+ /*
+ * Read the data. If a pipe, read until satisfy the number of bytes
+ * being skipped. No differentiation for reading complete and partial
+ * blocks for other devices.
+ */
+ for (bcnt = in.dbsz, cnt = in.offset, warned = 0; cnt;) {
+ if ((nr = read(in.fd, in.db, bcnt)) > 0) {
+ if (in.flags & ISPIPE) {
+ if (!(bcnt -= nr)) {
+ bcnt = in.dbsz;
+ --cnt;
+ }
+ } else
+ --cnt;
+ continue;
+ }
+
+ if (nr == 0) {
+ if (files_cnt > 1) {
+ --files_cnt;
+ continue;
+ }
+ errx(exit_jump, 1, "skip reached end of input");
+ }
+
+ /*
+ * Input error -- either EOF with no more files, or I/O error.
+ * If noerror not set die. POSIX requires that the warning
+ * message be followed by an I/O display.
+ */
+ if (ddflags & C_NOERROR) {
+ if (!warned) {
+ warn("%s", in.name);
+ warned = 1;
+ summary(globals);
+ }
+ continue;
+ }
+ err(exit_jump, 1, "%s", in.name);
+ }
+}
+
+void
+pos_out(rtems_shell_dd_globals* globals)
+{
+#if RTEMS_REMOVED
+ struct mtop t_op;
+ off_t cnt;
+ ssize_t n;
+#endif
+
+ /*
+ * If not a tape, try seeking on the file. Seeking on a pipe is
+ * going to fail, but don't protect the user -- they shouldn't
+ * have specified the seek operand.
+ */
+ if (out.flags & (ISSEEK | ISPIPE)) {
+ errno = 0;
+ if (lseek(out.fd, out.offset * out.dbsz, SEEK_CUR) == -1 &&
+ errno != 0)
+ err(exit_jump, 1, "%s", out.name);
+ return;
+ }
+
+ /* Don't try to read a really weird amount (like negative). */
+ if (out.offset < 0)
+ errx(exit_jump, 1, "%s: illegal offset", "oseek/seek");
+
+#if RTEMS_REMOVED
+ /* If no read access, try using mtio. */
+ if (out.flags & NOREAD) {
+ t_op.mt_op = MTFSR;
+ t_op.mt_count = out.offset;
+
+ if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
+ err(1, "%s", out.name);
+ return;
+ }
+
+ /* Read it. */
+ for (cnt = 0; cnt < out.offset; ++cnt) {
+ if ((n = read(out.fd, out.db, out.dbsz)) > 0)
+ continue;
+
+ if (n == -1)
+ err(1, "%s", out.name);
+
+ /*
+ * If reach EOF, fill with NUL characters; first, back up over
+ * the EOF mark. Note, cnt has not yet been incremented, so
+ * the EOF read does not count as a seek'd block.
+ */
+ t_op.mt_op = MTBSR;
+ t_op.mt_count = 1;
+ if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
+ err(1, "%s", out.name);
+
+ while (cnt++ < out.offset) {
+ n = write(out.fd, out.db, out.dbsz);
+ if (n == -1)
+ err(1, "%s", out.name);
+ if ((size_t)n != out.dbsz)
+ errx(1, "%s: write failure", out.name);
+ }
+ break;
+ }
+#endif
+}
diff --git a/cpukit/libmisc/shell/dd.h b/cpukit/libmisc/shell/dd.h
new file mode 100644
index 0000000000..dc80765d48
--- /dev/null
+++ b/cpukit/libmisc/shell/dd.h
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)dd.h 8.3 (Berkeley) 4/2/94
+ * $FreeBSD: src/bin/dd/dd.h,v 1.22 2004/08/15 19:10:05 rwatson Exp $
+ */
+
+#ifndef _DD_H_
+#define _DD_H_
+
+#include <stddef.h>
+
+#define OFF_MAX LONG_MAX
+
+/* Input/output stream state. */
+typedef struct {
+ u_char *db; /* buffer address */
+ u_char *dbp; /* current buffer I/O address */
+ /* XXX ssize_t? */
+ size_t dbcnt; /* current buffer byte count */
+ size_t dbrcnt; /* last read byte count */
+ size_t dbsz; /* buffer size */
+
+#define ISCHR 0x01 /* character device (warn on short) */
+#define ISPIPE 0x02 /* pipe-like (see position.c) */
+#define ISTAPE 0x04 /* tape */
+#define ISSEEK 0x08 /* valid to seek on */
+#define NOREAD 0x10 /* not readable */
+#define ISTRUNC 0x20 /* valid to ftruncate() */
+ u_int flags;
+
+ const char *name; /* name */
+ int fd; /* file descriptor */
+ off_t offset; /* # of blocks to skip */
+} IO;
+
+typedef struct {
+ uintmax_t in_full; /* # of full input blocks */
+ uintmax_t in_part; /* # of partial input blocks */
+ uintmax_t out_full; /* # of full output blocks */
+ uintmax_t out_part; /* # of partial output blocks */
+ uintmax_t trunc; /* # of truncated records */
+ uintmax_t swab; /* # of odd-length swab blocks */
+ uintmax_t bytes; /* # of bytes written */
+ double start; /* start time of dd */
+} STAT;
+
+/* Flags (in ddflags). */
+#define C_ASCII 0x00001
+#define C_BLOCK 0x00002
+#define C_BS 0x00004
+#define C_CBS 0x00008
+#define C_COUNT 0x00010
+#define C_EBCDIC 0x00020
+#define C_FILES 0x00040
+#define C_IBS 0x00080
+#define C_IF 0x00100
+#define C_LCASE 0x00200
+#define C_NOERROR 0x00400
+#define C_NOTRUNC 0x00800
+#define C_OBS 0x01000
+#define C_OF 0x02000
+#define C_OSYNC 0x04000
+#define C_PAREVEN 0x08000
+#define C_PARNONE 0x100000
+#define C_PARODD 0x200000
+#define C_PARSET 0x400000
+#define C_SEEK 0x800000
+#define C_SKIP 0x1000000
+#define C_SPARSE 0x2000000
+#define C_SWAB 0x4000000
+#define C_SYNC 0x8000000
+#define C_UCASE 0x10000000
+#define C_UNBLOCK 0x20000000
+#define C_FILL 0x40000000
+
+#define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
+
+#endif
diff --git a/cpukit/libmisc/shell/err.c b/cpukit/libmisc/shell/err.c
new file mode 100644
index 0000000000..610ea598a2
--- /dev/null
+++ b/cpukit/libmisc/shell/err.c
@@ -0,0 +1,64 @@
+/* $NetBSD: err.c,v 1.25 2005/09/13 13:51:50 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: err.c,v 1.25 2005/09/13 13:51:50 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <stdarg.h>
+
+#ifdef __weak_alias
+__weak_alias(err, _err)
+#endif
+
+__dead void
+err(jmp_buf* exit_jmp, int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ verr(exit_jmp, eval, fmt, ap);
+ va_end(ap);
+}
diff --git a/cpukit/libmisc/shell/err.h b/cpukit/libmisc/shell/err.h
new file mode 100644
index 0000000000..f028d3b151
--- /dev/null
+++ b/cpukit/libmisc/shell/err.h
@@ -0,0 +1,84 @@
+/* $NetBSD: err.h,v 1.14 2005/02/03 04:39:32 perry Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)err.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ERR_H_
+#define _ERR_H_
+
+/*
+ * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two
+ * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
+ * of them here we may collide with the utility's includes. It's unreasonable
+ * for utilities to have to include one of them to include err.h, so we get
+ * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
+ */
+#include <machine/ansi.h>
+#include <sys/cdefs.h>
+
+#include <stdarg.h>
+#define _BSD_VA_LIST_ va_list
+
+#define __dead
+
+#define err rtems_shell_err
+#define verr rtems_shell_verr
+#define errx rtems_shell_errx
+#define verrx rtems_shell_verrx
+#define warn rtems_shell_warn
+#define vwarn rtems_shell_vwarn
+#define warnx rtems_shell_warnx
+#define vwarnx rtems_shell_vwarnx
+
+#include <setjmp.h>
+
+extern jmp_buf rtems_shell_bsd_exit_recover;
+
+__BEGIN_DECLS
+__dead void err(jmp_buf*, int, const char *, ...)
+ __attribute__((__noreturn__, __format__(__printf__, 3, 4)));
+__dead void verr(jmp_buf*, int, const char *, _BSD_VA_LIST_)
+ __attribute__((__noreturn__, __format__(__printf__, 3, 0)));
+__dead void errx(jmp_buf*, int, const char *, ...)
+ __attribute__((__noreturn__, __format__(__printf__, 3, 4)));
+__dead void verrx(jmp_buf*, int, const char *, _BSD_VA_LIST_)
+ __attribute__((__noreturn__, __format__(__printf__, 3, 0)));
+void warn(const char *, ...)
+ __attribute__((__format__(__printf__, 1, 2)));
+void vwarn(const char *, _BSD_VA_LIST_)
+ __attribute__((__format__(__printf__, 1, 0)));
+void warnx(const char *, ...)
+ __attribute__((__format__(__printf__, 1, 2)));
+void vwarnx(const char *, _BSD_VA_LIST_)
+ __attribute__((__format__(__printf__, 1, 0)));
+__END_DECLS
+
+#endif /* !_ERR_H_ */
diff --git a/cpukit/libmisc/shell/errx.c b/cpukit/libmisc/shell/errx.c
new file mode 100644
index 0000000000..04e15e128b
--- /dev/null
+++ b/cpukit/libmisc/shell/errx.c
@@ -0,0 +1,64 @@
+/* $NetBSD: errx.c,v 1.13 2005/09/13 13:51:50 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: errx.c,v 1.13 2005/09/13 13:51:50 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <stdarg.h>
+
+#ifdef __weak_alias
+__weak_alias(errx, _errx)
+#endif
+
+__dead void
+errx(jmp_buf* exit_jmp, int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ verrx(exit_jmp, eval, fmt, ap);
+ va_end(ap);
+}
diff --git a/cpukit/libmisc/shell/extern-cp.h b/cpukit/libmisc/shell/extern-cp.h
new file mode 100644
index 0000000000..093b30ff10
--- /dev/null
+++ b/cpukit/libmisc/shell/extern-cp.h
@@ -0,0 +1,91 @@
+/* $NetBSD: extern.h,v 1.12 2005/10/15 18:22:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)extern.h 8.2 (Berkeley) 4/1/94
+ */
+
+#ifndef _EXTERN_CP_H_
+#define _EXTERN_CP_H_
+
+#define PATH_T RTEMS_SHELL_CP_PATH_T
+
+typedef struct {
+ char *p_end; /* pointer to NULL at end of path */
+ char *target_end; /* pointer to end of target base */
+ char p_path[MAXPATHLEN + 1]; /* pointer to the start of a path */
+} PATH_T;
+
+#include <setjmp.h>
+
+typedef struct {
+ PATH_T to;
+ int info;
+ uid_t myuid;
+ int fflag, iflag, lflag, nflag, pflag, vflag;
+ mode_t myumask;
+ jmp_buf exit_jmp;
+} rtems_shell_cp_globals;
+
+#define to cp_globals->to
+#define info cp_globals->info
+#define myuid cp_globals->myuid
+#define fflag cp_globals->fflag
+#define iflag cp_globals->iflag
+#define lflag cp_globals->lflag
+#define nflag cp_globals->nflag
+#define pflag cp_globals->pflag
+#define vflag cp_globals->vflag
+#define myumask cp_globals->myumask
+#define exit_jump &(cp_globals->exit_jmp)
+
+#define copy_fifo rtems_shell_cp_copy_fifo
+#define copy_file rtems_shell_cp_copy_file
+#define copy_link rtems_shell_cp_copy_link
+#define copy_special rtems_shell_cp_copy_special
+#define set_utimes rtems_shell_cp_set_utimes
+#define setfile rtems_shell_cp_setfile
+#define usage rtems_shell_cp_usage
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int copy_fifo(rtems_shell_cp_globals* cp_globals, struct stat *, int);
+int copy_file(rtems_shell_cp_globals* cp_globals, FTSENT *, int);
+int copy_link(rtems_shell_cp_globals* cp_globals, FTSENT *, int);
+int copy_special(rtems_shell_cp_globals* cp_globals, struct stat *, int);
+int set_utimes(const char *, struct stat *);
+int setfile(rtems_shell_cp_globals* cp_globals, struct stat *, int);
+int preserve_dir_acls(struct stat *, char *, char *);
+int preserve_fd_acls(int, int);
+void usage(rtems_shell_cp_globals* cp_globals);
+
+__END_DECLS
+
+#endif /* !_EXTERN_H_ */
diff --git a/cpukit/libmisc/shell/extern-dd.h b/cpukit/libmisc/shell/extern-dd.h
new file mode 100644
index 0000000000..405d460ef3
--- /dev/null
+++ b/cpukit/libmisc/shell/extern-dd.h
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)extern.h 8.3 (Berkeley) 4/2/94
+ * $FreeBSD: src/bin/dd/extern.h,v 1.15 2004/08/15 19:10:05 rwatson Exp $
+ */
+
+#ifndef _EXTERN_DD_H_
+#define _EXTERN_DD_H_
+
+#include <setjmp.h>
+
+typedef struct rtems_shell_dd_globals_t {
+ IO in, out; /* input/output state */
+ STAT st; /* statistics */
+ void (*cfunc)(struct rtems_shell_dd_globals_t* globals); /* conversion function */
+ uintmax_t cpy_cnt; /* # of blocks to copy */
+ u_int ddflags; /* conversion options */
+ size_t cbsz; /* conversion block size */
+ uintmax_t files_cnt; /* # of files to copy */
+ const u_char *ctab; /* conversion table */
+ char fill_char; /* Character to fill with if defined */
+ u_char casetab[256];
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_dd_globals;
+
+#define in globals->in
+#define out globals->out
+#define st globals->st
+#define cfunc globals->cfunc
+#define cpy_cnt globals->cpy_cnt
+#define ddflags globals->ddflags
+#define cbsz globals->cbsz
+#define files_cnt globals->files_cnt
+#define casetab globals->casetab
+#define ctab globals->ctab
+#define fill_char globals->fill_char
+#define exit_jump &(globals->exit_jmp)
+
+#define block rtems_shell_dd_block
+#define block_close rtems_shell_dd_block_close
+#define dd_out rtems_shell_dd_dd_out
+#define def rtems_shell_dd_def
+#define def_close rtems_shell_dd_def_close
+#define jcl rtems_shell_dd_jcl
+#define pos_in rtems_shell_dd_pos_in
+#define pos_out rtems_shell_dd_pos_out
+#define summary rtems_shell_dd_summary
+#define summaryx rtems_shell_dd_summaryx
+#define terminate rtems_shell_dd_terminate
+#define unblock rtems_shell_dd_unblock
+#define unblock_close rtems_shell_dd_unblock_close
+
+void block(rtems_shell_dd_globals* );
+void block_close(rtems_shell_dd_globals* );
+void dd_out(rtems_shell_dd_globals* , int);
+void def(rtems_shell_dd_globals* globals);
+void def_close(rtems_shell_dd_globals* );
+void jcl(rtems_shell_dd_globals* , char **);
+void pos_in(rtems_shell_dd_globals* );
+void pos_out(rtems_shell_dd_globals* );
+void summary(rtems_shell_dd_globals* );
+void summaryx(rtems_shell_dd_globals* , int);
+void terminate(int);
+void unblock(rtems_shell_dd_globals* globals);
+void unblock_close(rtems_shell_dd_globals* globals);
+
+extern const u_char a2e_32V[256], a2e_POSIX[256];
+extern const u_char e2a_32V[256], e2a_POSIX[256];
+extern const u_char a2ibm_32V[256], a2ibm_POSIX[256];
+
+void rtems_shell_dd_exit(rtems_shell_dd_globals* globals, int code);
+
+#define exit(ec) rtems_shell_dd_exit(globals, ec)
+
+#endif /* !_EXTERN_H_ */
diff --git a/cpukit/libmisc/shell/extern-ls.h b/cpukit/libmisc/shell/extern-ls.h
new file mode 100644
index 0000000000..33f713b66e
--- /dev/null
+++ b/cpukit/libmisc/shell/extern-ls.h
@@ -0,0 +1,192 @@
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Michael Fischbein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)ls.h 8.1 (Berkeley) 5/31/93
+ * $FreeBSD: src/bin/ls/ls.h,v 1.23 2008/04/04 03:57:46 grog Exp $
+ */
+
+#ifndef _EXTERN_LS_H_
+#define _EXTERN_LS_H_
+
+#define NO_PRINT 1
+//#define COLORLS 1
+
+#include <sys/cdefs.h>
+#include <setjmp.h>
+
+#define major(d) rtems_filesystem_dev_major_t(d)
+#define minor(d) rtems_filesystem_dev_minor_t(d)
+
+const char *user_from_uid(uid_t uid, int nouser);
+
+typedef struct {
+ int blocksize;
+ int termwidth;
+ int sortkey;
+ int rval;
+ int output;
+ time_t now;
+
+ int f_accesstime;
+ int f_column;
+ int f_columnacross;
+ int f_flags;
+ int f_grouponly;
+ int f_humanize;
+ int f_inode;
+ int f_listdir;
+ int f_listdot;
+ int f_longform;
+ int f_nonprint;
+ int f_nosort;
+ int f_numericonly;
+ int f_octal;
+ int f_octal_escape;
+ int f_recursive;
+ int f_reversesort;
+ int f_sectime;
+ int f_singlecol;
+ int f_size;
+ int f_statustime;
+ int f_stream;
+ int f_type;
+ int f_typedir;
+ int f_whiteout;
+
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_ls_globals;
+
+#define blocksize globals->blocksize
+#define termwidth globals->termwidth
+#define sortkey globals->sortkey
+#define rval globals->rval
+#define output globals->output
+#define now globals->now
+
+#define f_accesstime globals->f_accesstime
+#define f_column globals->f_column
+#define f_columnacross globals->f_columnacross
+#define f_flags globals->f_flags
+#define f_grouponly globals->f_grouponly
+#define f_humanize globals->f_humanize
+#define f_inode globals->f_inode
+#define f_listdir globals->f_listdir
+#define f_listdot globals->f_listdot
+#define f_longform globals->f_longform
+#define f_nonprint globals->f_nonprint
+#define f_nosort globals->f_nosort
+#define f_numericonly globals->f_numericonly
+#define f_octal globals->f_octal
+#define f_octal_escape globals->f_octal_escape
+#define f_recursive globals->f_recursive
+#define f_reversesort globals->f_reversesort
+#define f_sectime globals->f_sectime
+#define f_singlecol globals->f_singlecol
+#define f_size globals->f_size
+#define f_statustime globals->f_statustime
+#define f_stream globals->f_stream
+#define f_type globals->f_type
+#define f_typedir globals->f_typedir
+#define f_whiteout globals->f_whiteout
+
+#define exit_jump &(globals->exit_jmp)
+
+void rtems_shell_ls_exit(rtems_shell_ls_globals* globals, int code);
+
+#define exit(ec) rtems_shell_ls_exit(globals, ec)
+
+
+typedef struct {
+ FTSENT *list;
+ u_int64_t btotal;
+ u_int64_t stotal;
+ int entries;
+ int maxlen;
+ int s_block;
+ int s_flags;
+ int s_group;
+ int s_inode;
+ int s_nlink;
+ int s_size;
+ int s_user;
+ int s_major;
+ int s_minor;
+} DISPLAY;
+
+typedef struct {
+ char *user;
+ char *group;
+ char *flags;
+ char data[1];
+} NAMES;
+
+#define acccmp rtems_shell_ls_acccmp
+#define revacccmp rtems_shell_ls_revacccmp
+#define modcmp rtems_shell_ls_modcmp
+#define revmodcmp rtems_shell_ls_revmodcmp
+#define namecmp rtems_shell_ls_namecmp
+#define revnamecmp rtems_shell_ls_revnamecmp
+#define statcmp rtems_shell_ls_statcmp
+#define revstatcmp rtems_shell_ls_revstatcmp
+#define sizecmp rtems_shell_ls_sizecmp
+#define revsizecmp rtems_shell_ls_revsizecmp
+#define printescaped rtems_shell_ls_printescaped
+#define printacol rtems_shell_ls_printacol
+#define printcol rtems_shell_ls_printcol
+#define printlong rtems_shell_ls_printlong
+#define printscol rtems_shell_ls_printscol
+#define printstream rtems_shell_ls_printstream
+#define usage rtems_shell_ls_usage
+
+int acccmp(const FTSENT *, const FTSENT *);
+int revacccmp(const FTSENT *, const FTSENT *);
+int modcmp(const FTSENT *, const FTSENT *);
+int revmodcmp(const FTSENT *, const FTSENT *);
+int namecmp(const FTSENT *, const FTSENT *);
+int revnamecmp(const FTSENT *, const FTSENT *);
+int statcmp(const FTSENT *, const FTSENT *);
+int revstatcmp(const FTSENT *, const FTSENT *);
+int sizecmp(const FTSENT *, const FTSENT *);
+int revsizecmp(const FTSENT *, const FTSENT *);
+
+int printescaped(rtems_shell_ls_globals* globals, const char *);
+void printacol(rtems_shell_ls_globals* globals, DISPLAY *);
+void printcol(rtems_shell_ls_globals* globals, DISPLAY *);
+void printlong(rtems_shell_ls_globals* globals, DISPLAY *);
+void printscol(rtems_shell_ls_globals* globals, DISPLAY *);
+void printstream(rtems_shell_ls_globals* globals, DISPLAY *);
+int safe_print(rtems_shell_ls_globals* globals, const char *);
+void usage(rtems_shell_ls_globals* globals);
+
+void strmode(mode_t mode, char *p);
+
+#endif /* !_EXTERN_H_ */
diff --git a/cpukit/libmisc/shell/fdisk.c b/cpukit/libmisc/shell/fdisk.c
new file mode 100644
index 0000000000..37a2e217dc
--- /dev/null
+++ b/cpukit/libmisc/shell/fdisk.c
@@ -0,0 +1,280 @@
+/**
+ * @file
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems/bdpart.h>
+#include <rtems/error.h>
+#include <rtems/shell.h>
+
+#define RTEMS_BDPART_SHELL_ERROR( fmt, ...) \
+ do { \
+ printf( "error: " fmt "\n", ##__VA_ARGS__); \
+ return -1; \
+ } while (0)
+
+#define RTEMS_BDPART_SHELL_ERROR_SC( sc, fmt, ...) \
+ if ((sc) != RTEMS_SUCCESSFUL) { \
+ printf( "error: " fmt ": %s\n", ##__VA_ARGS__, rtems_status_text( sc)); \
+ return -1; \
+ }
+
+typedef enum {
+ RTEMS_BDPART_SHELL_FS,
+ RTEMS_BDPART_SHELL_N,
+ RTEMS_BDPART_SHELL_MBR,
+ RTEMS_BDPART_SHELL_GPT
+} rtems_bdpart_shell_state;
+
+static const char rtems_bdpart_shell_usage [] =
+ "disk format and utility functions\n"
+ "\n"
+ "fdisk DISK_NAME\n"
+ "\tprints the partition table\n"
+ "\n"
+ "fdisk DISK_NAME [FS N1 [N2 ... ]] ... [write] [FORMAT]\n"
+ "\tcreates a new partition table\n"
+ "\n"
+ "fdisk DISK_NAME register\n"
+ "\tcreates a logical disk for each partition of the disk\n"
+ "\n"
+ "fdisk DISK_NAME unregister\n"
+ "\tdeletes the logical disks associated with the partitions of the disk\n"
+ "\n"
+ "fdisk DISK_NAME mount\n"
+ "\tmounts the file system of each partition of the disk\n"
+ "\n"
+ "fdisk DISK_NAME unmount\n"
+ "\tunmounts the file system of each partition of the disk\n"
+ "\n"
+ "option values:\n"
+ "\tDISK_NAME: absolute path to disk device like '/dev/hda'\n"
+ "\tN*: weights of positive integers\n"
+ "\tFS: 0x00 ... 0xff, fat12, fat16, fat32, data\n"
+ "\twrite: write the new partition table to the disk\n"
+ "\tFORMAT: mbr [[no]dos], gpt";
+
+static int rtems_bdpart_shell_main( int argc, char **argv)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_bdpart_format format;
+ rtems_bdpart_partition pt [RTEMS_BDPART_PARTITION_NUMBER_HINT];
+ unsigned dist [RTEMS_BDPART_PARTITION_NUMBER_HINT];
+ size_t count = RTEMS_BDPART_PARTITION_NUMBER_HINT;
+ const char *disk_name = NULL;
+ const char *mount_base = "/mnt";
+ bool do_create = false;
+ bool do_read = false;
+ bool do_write = false;
+ bool do_register = false;
+ bool do_unregister = false;
+ bool do_mount = false;
+ bool do_unmount = false;
+ bool do_dump = false;
+
+ if (argc < 2) {
+ puts( rtems_bdpart_shell_usage);
+ return -1;
+ }
+
+ disk_name = argv [1];
+
+ if (argc == 2) {
+ do_read = true;
+ do_dump = true;
+ } else if (argc == 3) {
+ /* Check option */
+ if (strcmp( argv [2], "register") == 0) {
+ do_read = true;
+ do_register = true;
+ } else if (strcmp( argv [2], "unregister") == 0) {
+ do_read = true;
+ do_unregister = true;
+ } else if (strcmp( argv [2], "mount") == 0) {
+ do_read = true;
+ do_mount = true;
+ } else if (strcmp( argv [2], "unmount") == 0) {
+ do_read = true;
+ do_unmount = true;
+ } else {
+ RTEMS_BDPART_SHELL_ERROR( "unexpected option: %s", argv [2]);
+ }
+ } else {
+ rtems_bdpart_shell_state state = RTEMS_BDPART_SHELL_FS;
+ uint8_t current_type = RTEMS_BDPART_MBR_FAT_32;
+ size_t i = 0;
+ int ai = 0;
+
+ /* Clear partition table */
+ memset( pt, 0, sizeof( pt));
+
+ /* Default format */
+ format.type = RTEMS_BDPART_FORMAT_MBR;
+ format.mbr.disk_id = 0;
+ format.mbr.dos_compatibility = true;
+
+ for (ai = 2; ai < argc; ++ai) {
+ char *s = argv [ai];
+ unsigned long v = 0;
+ char *end = NULL;
+
+ if (strlen( s) == 0) {
+ continue;
+ } else if (strcmp( s, "write") == 0) {
+ do_write = true;
+ continue;
+ } else if (strcmp( s, "mbr") == 0) {
+ state = RTEMS_BDPART_SHELL_MBR;
+ format.type = RTEMS_BDPART_FORMAT_MBR;
+ continue;
+ } else if (strcmp( s, "gpt") == 0) {
+ state = RTEMS_BDPART_SHELL_GPT;
+ format.type = RTEMS_BDPART_FORMAT_GPT;
+ continue;
+ }
+
+ switch (state) {
+ case RTEMS_BDPART_SHELL_FS:
+ v = strtoul( s, &end, 16);
+ if (*end == '\0') {
+ if (v <= 0xffU) {
+ current_type = (uint8_t) v;
+ } else {
+ RTEMS_BDPART_SHELL_ERROR( "type value out of range: %s", argv [ai]);
+ }
+ } else if (strcmp( s, "fat32") == 0) {
+ current_type = RTEMS_BDPART_MBR_FAT_32;
+ } else if (strcmp( s, "data") == 0) {
+ current_type = RTEMS_BDPART_MBR_DATA;
+ } else if (strcmp( s, "fat16") == 0) {
+ current_type = RTEMS_BDPART_MBR_FAT_16;
+ } else if (strcmp( s, "fat12") == 0) {
+ current_type = RTEMS_BDPART_MBR_FAT_12;
+ } else {
+ RTEMS_BDPART_SHELL_ERROR( "unexpected option: %s", argv [ai]);
+ }
+ state = RTEMS_BDPART_SHELL_N;
+ break;
+ case RTEMS_BDPART_SHELL_N:
+ v = strtoul( s, &end, 10);
+ if (*end == '\0') {
+ rtems_bdpart_to_partition_type( current_type, pt [i].type);
+ dist [i] = v;
+ if (i < count) {
+ ++i;
+ } else {
+ RTEMS_BDPART_SHELL_ERROR( "too many partitions");
+ }
+ } else {
+ --ai;
+ state = RTEMS_BDPART_SHELL_FS;
+ }
+ break;
+ case RTEMS_BDPART_SHELL_MBR:
+ if (strcmp( s, "dos") == 0) {
+ format.mbr.dos_compatibility = true;
+ } else if (strcmp( s, "nodos") == 0) {
+ format.mbr.dos_compatibility = false;
+ } else {
+ RTEMS_BDPART_SHELL_ERROR( "unexpected option: %s", argv [ai]);
+ }
+ break;
+ case RTEMS_BDPART_SHELL_GPT:
+ RTEMS_BDPART_SHELL_ERROR( "unexpected option: %s", argv [ai]);
+ default:
+ RTEMS_BDPART_SHELL_ERROR( "fdisk interal error");
+ }
+ }
+
+ /* Partition number */
+ count = i;
+
+ /* Actions */
+ do_create = true;
+ do_dump = true;
+ if (do_write) {
+ do_read = true;
+ }
+ }
+
+ if (do_create) {
+ /* Create partitions */
+ sc = rtems_bdpart_create( disk_name, &format, pt, dist, count);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot create partitions for '%s'", disk_name);
+ }
+
+ if (do_write) {
+ /* Write partitions */
+ sc = rtems_bdpart_write( disk_name, &format, pt, count);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot write partitions to '%s'", disk_name);
+ }
+
+ if (do_read) {
+ /* Read partitions */
+ count = RTEMS_BDPART_PARTITION_NUMBER_HINT;
+ sc = rtems_bdpart_read( disk_name, &format, pt, &count);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot read partitions from '%s'", disk_name);
+ }
+
+ if (do_register) {
+ /* Register partitions */
+ sc = rtems_bdpart_register( disk_name, pt, count);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot register partitions of '%s'", disk_name);
+ }
+
+ if (do_unregister) {
+ /* Unregister partitions */
+ sc = rtems_bdpart_unregister( disk_name, pt, count);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot unregister partitions of '%s'", disk_name);
+ }
+
+ if (do_mount) {
+ /* Mount partitions */
+ sc = rtems_bdpart_mount( disk_name, pt, count, mount_base);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot mount partitions of '%s' to '%s'", disk_name, mount_base);
+ }
+
+ if (do_unmount) {
+ /* Unmount partitions */
+ sc = rtems_bdpart_unmount( disk_name, pt, count, mount_base);
+ RTEMS_BDPART_SHELL_ERROR_SC( sc, "cannot unmount partitions of '%s'", disk_name);
+ }
+
+ if (do_dump) {
+ /* Dump partitions */
+ rtems_bdpart_dump( pt, count);
+ }
+
+ return 0;
+}
+
+struct rtems_shell_cmd_tt rtems_shell_FDISK_Command = {
+ .name = "fdisk",
+ .usage = rtems_bdpart_shell_usage,
+ .topic = "files",
+ .command = rtems_bdpart_shell_main,
+ .alias = NULL,
+ .next = NULL
+};
diff --git a/cpukit/libmisc/shell/filemode.c b/cpukit/libmisc/shell/filemode.c
new file mode 100644
index 0000000000..9a5d0440b4
--- /dev/null
+++ b/cpukit/libmisc/shell/filemode.c
@@ -0,0 +1,154 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/string/strmode.c,v 1.5 2007/01/09 00:28:12 imp Exp $");
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+void
+strmode(
+ mode_t mode,
+ char *p)
+{
+ /* print type */
+ switch (mode & S_IFMT) {
+ case S_IFDIR: /* directory */
+ *p++ = 'd';
+ break;
+ case S_IFCHR: /* character special */
+ *p++ = 'c';
+ break;
+ case S_IFBLK: /* block special */
+ *p++ = 'b';
+ break;
+ case S_IFREG: /* regular */
+ *p++ = '-';
+ break;
+ case S_IFLNK: /* symbolic link */
+ *p++ = 'l';
+ break;
+ case S_IFSOCK: /* socket */
+ *p++ = 's';
+ break;
+#ifdef S_IFIFO
+ case S_IFIFO: /* fifo */
+ *p++ = 'p';
+ break;
+#endif
+#ifdef S_IFWHT
+ case S_IFWHT: /* whiteout */
+ *p++ = 'w';
+ break;
+#endif
+ default: /* unknown */
+ *p++ = '?';
+ break;
+ }
+ /* usr */
+ if (mode & S_IRUSR)
+ *p++ = 'r';
+ else
+ *p++ = '-';
+ if (mode & S_IWUSR)
+ *p++ = 'w';
+ else
+ *p++ = '-';
+ switch (mode & (S_IXUSR | S_ISUID)) {
+ case 0:
+ *p++ = '-';
+ break;
+ case S_IXUSR:
+ *p++ = 'x';
+ break;
+ case S_ISUID:
+ *p++ = 'S';
+ break;
+ case S_IXUSR | S_ISUID:
+ *p++ = 's';
+ break;
+ }
+ /* group */
+ if (mode & S_IRGRP)
+ *p++ = 'r';
+ else
+ *p++ = '-';
+ if (mode & S_IWGRP)
+ *p++ = 'w';
+ else
+ *p++ = '-';
+ switch (mode & (S_IXGRP | S_ISGID)) {
+ case 0:
+ *p++ = '-';
+ break;
+ case S_IXGRP:
+ *p++ = 'x';
+ break;
+ case S_ISGID:
+ *p++ = 'S';
+ break;
+ case S_IXGRP | S_ISGID:
+ *p++ = 's';
+ break;
+ }
+ /* other */
+ if (mode & S_IROTH)
+ *p++ = 'r';
+ else
+ *p++ = '-';
+ if (mode & S_IWOTH)
+ *p++ = 'w';
+ else
+ *p++ = '-';
+ switch (mode & (S_IXOTH | S_ISVTX)) {
+ case 0:
+ *p++ = '-';
+ break;
+ case S_IXOTH:
+ *p++ = 'x';
+ break;
+ case S_ISVTX:
+ *p++ = 'T';
+ break;
+ case S_IXOTH | S_ISVTX:
+ *p++ = 't';
+ break;
+ }
+ *p++ = ' '; /* will be a '+' if ACL's implemented */
+ *p = '\0';
+}
diff --git a/cpukit/libmisc/shell/fts.c b/cpukit/libmisc/shell/fts.c
new file mode 100644
index 0000000000..2fd91b874c
--- /dev/null
+++ b/cpukit/libmisc/shell/fts.c
@@ -0,0 +1,1244 @@
+/* $NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
+#else
+__RCSID("$NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#ifndef __rtems__
+#include "namespace.h"
+#endif
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#define _DIAGASSERT(a)
+#undef FTS_WHITEOUT
+#define dirfd(dp) __dirfd(dp)
+
+#if ! HAVE_NBTOOL_CONFIG_H
+#define HAVE_STRUCT_DIRENT_D_NAMLEN
+#endif
+
+static FTSENT *fts_alloc(FTS *, const char *, size_t);
+static FTSENT *fts_build(FTS *, int);
+static void fts_free(FTSENT *);
+static void fts_lfree(FTSENT *);
+static void fts_load(FTS *, FTSENT *);
+static size_t fts_maxarglen(char * const *);
+static size_t fts_pow2(size_t);
+static int fts_palloc(FTS *, size_t);
+static void fts_padjust(FTS *, FTSENT *);
+static FTSENT *fts_sort(FTS *, FTSENT *, size_t);
+static unsigned short fts_stat(FTS *, FTSENT *, int);
+static int fts_safe_changedir(const FTS *, const FTSENT *, int,
+ const char *);
+
+#if defined(ALIGNBYTES) && defined(ALIGN)
+#define FTS_ALLOC_ALIGNED 1
+/* FIXME: Redefine because some versions of
+ * RTEMS newlib and the BSDs ship a broken ALIGN */
+#undef ALIGN
+#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
+#else
+#undef FTS_ALLOC_ALIGNED
+#endif
+
+#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
+
+#define CLR(opt) (sp->fts_options &= ~(opt))
+#define ISSET(opt) (sp->fts_options & (opt))
+#define SET(opt) (sp->fts_options |= (opt))
+
+#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path))
+#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
+
+/* fts_build flags */
+#define BCHILD 1 /* fts_children */
+#define BNAMES 2 /* fts_children, names only */
+#define BREAD 3 /* fts_read */
+
+#ifndef DTF_HIDEW
+#undef FTS_WHITEOUT
+#endif
+
+FTS *
+fts_open(char * const *argv, int options,
+ int (*compar)(const FTSENT **, const FTSENT **))
+{
+ FTS *sp;
+ FTSENT *p, *root;
+ size_t nitems;
+ FTSENT *parent, *tmp = NULL; /* pacify gcc */
+ size_t len;
+
+ _DIAGASSERT(argv != NULL);
+
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Allocate/initialize the stream */
+ if ((sp = malloc((unsigned int)sizeof(FTS))) == NULL)
+ return (NULL);
+ memset(sp, 0, sizeof(FTS));
+ sp->fts_compar = compar;
+ sp->fts_options = options;
+
+ /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
+ if (ISSET(FTS_LOGICAL))
+ SET(FTS_NOCHDIR);
+
+ /*
+ * Start out with 1K of path space, and enough, in any case,
+ * to hold the user's paths.
+ */
+ if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
+ goto mem1;
+
+ /* Allocate/initialize root's parent. */
+ if ((parent = fts_alloc(sp, "", 0)) == NULL)
+ goto mem2;
+ parent->fts_level = FTS_ROOTPARENTLEVEL;
+
+ /* Allocate/initialize root(s). */
+ for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
+ /* Don't allow zero-length paths. */
+ if ((len = strlen(*argv)) == 0) {
+ errno = ENOENT;
+ goto mem3;
+ }
+
+ if ((p = fts_alloc(sp, *argv, len)) == NULL)
+ goto mem3;
+ p->fts_level = FTS_ROOTLEVEL;
+ p->fts_parent = parent;
+ p->fts_accpath = p->fts_name;
+ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
+
+ /* Command-line "." and ".." are real directories. */
+ if (p->fts_info == FTS_DOT)
+ p->fts_info = FTS_D;
+
+ /*
+ * If comparison routine supplied, traverse in sorted
+ * order; otherwise traverse in the order specified.
+ */
+ if (compar) {
+ p->fts_link = root;
+ root = p;
+ } else {
+ p->fts_link = NULL;
+ if (root == NULL)
+ tmp = root = p;
+ else {
+ tmp->fts_link = p;
+ tmp = p;
+ }
+ }
+ }
+ if (compar && nitems > 1)
+ root = fts_sort(sp, root, nitems);
+
+ /*
+ * Allocate a dummy pointer and make fts_read think that we've just
+ * finished the node before the root(s); set p->fts_info to FTS_INIT
+ * so that everything about the "current" node is ignored.
+ */
+ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
+ goto mem3;
+ sp->fts_cur->fts_link = root;
+ sp->fts_cur->fts_info = FTS_INIT;
+
+ /*
+ * If using chdir(2), grab a file descriptor pointing to dot to insure
+ * that we can get back here; this could be avoided for some paths,
+ * but almost certainly not worth the effort. Slashes, symbolic links,
+ * and ".." are all fairly nasty problems. Note, if we can't get the
+ * descriptor we run anyway, just more slowly.
+ */
+ if (!ISSET(FTS_NOCHDIR)) {
+ if ((sp->fts_rfd = open(".", O_RDONLY, 0)) == -1)
+ SET(FTS_NOCHDIR);
+ else if (fcntl(sp->fts_rfd, F_SETFD, FD_CLOEXEC) == -1) {
+ close(sp->fts_rfd);
+ SET(FTS_NOCHDIR);
+ }
+ }
+
+ if (nitems == 0)
+ fts_free(parent);
+
+ return (sp);
+
+mem3: fts_lfree(root);
+ fts_free(parent);
+mem2: free(sp->fts_path);
+mem1: free(sp);
+ return (NULL);
+}
+
+static void
+fts_load(FTS *sp, FTSENT *p)
+{
+ size_t len;
+ char *cp;
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(p != NULL);
+
+ /*
+ * Load the stream structure for the next traversal. Since we don't
+ * actually enter the directory until after the preorder visit, set
+ * the fts_accpath field specially so the chdir gets done to the right
+ * place and the user can access the first node. From fts_open it's
+ * known that the path will fit.
+ */
+ len = p->fts_pathlen = p->fts_namelen;
+ memmove(sp->fts_path, p->fts_name, len + 1);
+ if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
+ len = strlen(++cp);
+ memmove(p->fts_name, cp, len + 1);
+ p->fts_namelen = len;
+ }
+ p->fts_accpath = p->fts_path = sp->fts_path;
+ sp->fts_dev = p->fts_dev;
+}
+
+int
+fts_close(FTS *sp)
+{
+ FTSENT *freep, *p;
+ int saved_errno = 0;
+
+ _DIAGASSERT(sp != NULL);
+
+ /*
+ * This still works if we haven't read anything -- the dummy structure
+ * points to the root list, so we step through to the end of the root
+ * list which has a valid parent pointer.
+ */
+ if (sp->fts_cur) {
+ if (sp->fts_cur->fts_flags & FTS_SYMFOLLOW)
+ (void)close(sp->fts_cur->fts_symfd);
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ freep = p;
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ fts_free(freep);
+ }
+ fts_free(p);
+ }
+
+ /* Free up child linked list, sort array, path buffer. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+ if (sp->fts_array)
+ free(sp->fts_array);
+ free(sp->fts_path);
+
+ /* Return to original directory, save errno if necessary. */
+ if (!ISSET(FTS_NOCHDIR)) {
+ if (fchdir(sp->fts_rfd) == -1)
+ saved_errno = errno;
+ (void)close(sp->fts_rfd);
+ }
+
+ /* Free up the stream pointer. */
+ free(sp);
+ if (saved_errno) {
+ errno = saved_errno;
+ return -1;
+ }
+
+ return 0;
+}
+
+#if !defined(__FTS_COMPAT_TAILINGSLASH)
+
+/*
+ * Special case of "/" at the end of the path so that slashes aren't
+ * appended which would cause paths to be written as "....//foo".
+ */
+#define NAPPEND(p) \
+ (p->fts_path[p->fts_pathlen - 1] == '/' \
+ ? p->fts_pathlen - 1 : p->fts_pathlen)
+
+#else /* !defined(__FTS_COMPAT_TAILINGSLASH) */
+
+/*
+ * compatibility with the old behaviour.
+ *
+ * Special case a root of "/" so that slashes aren't appended which would
+ * cause paths to be written as "//foo".
+ */
+
+#define NAPPEND(p) \
+ (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \
+ p->fts_path[0] == '/' ? 0 : p->fts_pathlen)
+
+#endif /* !defined(__FTS_COMPAT_TAILINGSLASH) */
+
+FTSENT *
+fts_read(FTS *sp)
+{
+ FTSENT *p, *tmp;
+ int instr;
+ char *t;
+ int saved_errno;
+
+ _DIAGASSERT(sp != NULL);
+
+ /* If finished or unrecoverable error, return NULL. */
+ if (sp->fts_cur == NULL || ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /* Save and zero out user instructions. */
+ instr = p->fts_instr;
+ p->fts_instr = FTS_NOINSTR;
+
+ /* Any type of file may be re-visited; re-stat and re-turn. */
+ if (instr == FTS_AGAIN) {
+ p->fts_info = fts_stat(sp, p, 0);
+ return (p);
+ }
+
+ /*
+ * Following a symlink -- SLNONE test allows application to see
+ * SLNONE and recover. If indirecting through a symlink, have
+ * keep a pointer to current location. If unable to get that
+ * pointer, follow fails.
+ */
+ if (instr == FTS_FOLLOW &&
+ (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
+ p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
+ if ((p->fts_symfd = open(".", O_RDONLY, 0)) == -1) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ close(p->fts_symfd);
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ }
+ return (p);
+ }
+
+ /* Directory in pre-order. */
+ if (p->fts_info == FTS_D) {
+ /* If skipped or crossed mount point, do post-order visit. */
+ if (instr == FTS_SKIP ||
+ (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
+ if (p->fts_flags & FTS_SYMFOLLOW)
+ (void)close(p->fts_symfd);
+ if (sp->fts_child) {
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+ p->fts_info = FTS_DP;
+ return (p);
+ }
+
+ /* Rebuild if only read the names and now traversing. */
+ if (sp->fts_child && ISSET(FTS_NAMEONLY)) {
+ CLR(FTS_NAMEONLY);
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+
+ /*
+ * Cd to the subdirectory.
+ *
+ * If have already read and now fail to chdir, whack the list
+ * to make the names come out right, and set the parent errno
+ * so the application will eventually get an error condition.
+ * Set the FTS_DONTCHDIR flag so that when we logically change
+ * directories back to the parent we don't do a chdir.
+ *
+ * If haven't read do so. If the read fails, fts_build sets
+ * FTS_STOP or the fts_info field of the node.
+ */
+ if (sp->fts_child) {
+ if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
+ p->fts_errno = errno;
+ p->fts_flags |= FTS_DONTCHDIR;
+ for (p = sp->fts_child; p; p = p->fts_link)
+ p->fts_accpath =
+ p->fts_parent->fts_accpath;
+ }
+ } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
+ if (ISSET(FTS_STOP))
+ return (NULL);
+ return (p);
+ }
+ p = sp->fts_child;
+ sp->fts_child = NULL;
+ goto name;
+ }
+
+ /* Move to the next node on this level. */
+next: tmp = p;
+ if ((p = p->fts_link) != NULL) {
+ fts_free(tmp);
+
+ /*
+ * If reached the top, return to the original directory, and
+ * load the paths for the next root.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ fts_load(sp, p);
+ return (sp->fts_cur = p);
+ }
+
+ /*
+ * User may have called fts_set on the node. If skipped,
+ * ignore. If followed, get a file descriptor so we can
+ * get back if necessary.
+ */
+ if (p->fts_instr == FTS_SKIP)
+ goto next;
+ if (p->fts_instr == FTS_FOLLOW) {
+ p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
+ if ((p->fts_symfd =
+ open(".", O_RDONLY, 0)) == -1) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ close(p->fts_symfd);
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ }
+ p->fts_instr = FTS_NOINSTR;
+ }
+
+name: t = sp->fts_path + NAPPEND(p->fts_parent);
+ *t++ = '/';
+ memmove(t, p->fts_name, (size_t)(p->fts_namelen + 1));
+ return (sp->fts_cur = p);
+ }
+
+ /* Move up to the parent node. */
+ p = tmp->fts_parent;
+ fts_free(tmp);
+
+ if (p->fts_level == FTS_ROOTPARENTLEVEL) {
+ /*
+ * Done; free everything up and set errno to 0 so the user
+ * can distinguish between error and EOF.
+ */
+ fts_free(p);
+ errno = 0;
+ return (sp->fts_cur = NULL);
+ }
+
+ /* Nul terminate the pathname. */
+ sp->fts_path[p->fts_pathlen] = '\0';
+
+ /*
+ * Return to the parent directory. If at a root node or came through
+ * a symlink, go back through the file descriptor. Otherwise, cd up
+ * one directory.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ } else if (p->fts_flags & FTS_SYMFOLLOW) {
+ if (FCHDIR(sp, p->fts_symfd)) {
+ saved_errno = errno;
+ (void)close(p->fts_symfd);
+ errno = saved_errno;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ (void)close(p->fts_symfd);
+ } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
+ fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
+ return (sp->fts_cur = p);
+}
+
+/*
+ * Fts_set takes the stream as an argument although it's not used in this
+ * implementation; it would be necessary if anyone wanted to add global
+ * semantics to fts using fts_set. An error return is allowed for similar
+ * reasons.
+ */
+/* ARGSUSED */
+int
+fts_set(FTS *sp, FTSENT *p, int instr)
+{
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(p != NULL);
+
+ if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
+ instr != FTS_NOINSTR && instr != FTS_SKIP) {
+ errno = EINVAL;
+ return (1);
+ }
+ p->fts_instr = instr;
+ return (0);
+}
+
+FTSENT *
+fts_children(FTS *sp, int instr)
+{
+ FTSENT *p;
+ int fd;
+
+ _DIAGASSERT(sp != NULL);
+
+ if (instr && instr != FTS_NAMEONLY) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /*
+ * Errno set to 0 so user can distinguish empty directory from
+ * an error.
+ */
+ errno = 0;
+
+ /* Fatal errors stop here. */
+ if (ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Return logical hierarchy of user's arguments. */
+ if (p->fts_info == FTS_INIT)
+ return (p->fts_link);
+
+ /*
+ * If not a directory being visited in pre-order, stop here. Could
+ * allow FTS_DNR, assuming the user has fixed the problem, but the
+ * same effect is available with FTS_AGAIN.
+ */
+ if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
+ return (NULL);
+
+ /* Free up any previous child list. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+
+ if (instr == FTS_NAMEONLY) {
+ SET(FTS_NAMEONLY);
+ instr = BNAMES;
+ } else
+ instr = BCHILD;
+
+ /*
+ * If using chdir on a relative path and called BEFORE fts_read does
+ * its chdir to the root of a traversal, we can lose -- we need to
+ * chdir into the subdirectory, and we don't know where the current
+ * directory is, so we can't get back so that the upcoming chdir by
+ * fts_read will work.
+ */
+ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
+ ISSET(FTS_NOCHDIR))
+ return (sp->fts_child = fts_build(sp, instr));
+
+ if ((fd = open(".", O_RDONLY, 0)) == -1)
+ return (sp->fts_child = NULL);
+ sp->fts_child = fts_build(sp, instr);
+ if (fchdir(fd)) {
+ (void)close(fd);
+ return (NULL);
+ }
+ (void)close(fd);
+ return (sp->fts_child);
+}
+
+/*
+ * This is the tricky part -- do not casually change *anything* in here. The
+ * idea is to build the linked list of entries that are used by fts_children
+ * and fts_read. There are lots of special cases.
+ *
+ * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is
+ * set and it's a physical walk (so that symbolic links can't be directories),
+ * we can do things quickly. First, if it's a 4.4BSD file system, the type
+ * of the file is in the directory entry. Otherwise, we assume that the number
+ * of subdirectories in a node is equal to the number of links to the parent.
+ * The former skips all stat calls. The latter skips stat calls in any leaf
+ * directories and for any files after the subdirectories in the directory have
+ * been found, cutting the stat calls by about 2/3.
+ */
+static FTSENT *
+fts_build(FTS *sp, int type)
+{
+ struct dirent *dp;
+ FTSENT *p, *head;
+ size_t nitems;
+ FTSENT *cur, *tail;
+ DIR *dirp;
+ void *oldaddr;
+ size_t dnamlen;
+ int cderrno, descend, level, nlinks, saved_errno, nostat, doadjust;
+ size_t len, maxlen;
+#ifdef FTS_WHITEOUT
+ int oflag;
+#endif
+ char *cp = NULL; /* pacify gcc */
+
+ _DIAGASSERT(sp != NULL);
+
+ /* Set current node pointer. */
+ cur = sp->fts_cur;
+
+ /*
+ * Open the directory for reading. If this fails, we're done.
+ * If being called from fts_read, set the fts_info field.
+ */
+#ifdef FTS_WHITEOUT
+ if (ISSET(FTS_WHITEOUT))
+ oflag = DTF_NODUP|DTF_REWIND;
+ else
+ oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
+#else
+#define __opendir2(path, flag) opendir(path)
+#endif
+ if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
+ if (type == BREAD) {
+ cur->fts_info = FTS_DNR;
+ cur->fts_errno = errno;
+ }
+ return (NULL);
+ }
+
+ /*
+ * Nlinks is the number of possible entries of type directory in the
+ * directory if we're cheating on stat calls, 0 if we're not doing
+ * any stat calls at all, -1 if we're doing stats on everything.
+ */
+ if (type == BNAMES) {
+ nlinks = 0;
+ nostat = 1;
+ } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
+ nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
+ nostat = 1;
+ } else {
+ nlinks = -1;
+ nostat = 0;
+ }
+
+#ifdef notdef
+ (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
+ (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
+ ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
+#endif
+ /*
+ * If we're going to need to stat anything or we want to descend
+ * and stay in the directory, chdir. If this fails we keep going,
+ * but set a flag so we don't chdir after the post-order visit.
+ * We won't be able to stat anything, but we can still return the
+ * names themselves. Note, that since fts_read won't be able to
+ * chdir into the directory, it will have to return different path
+ * names than before, i.e. "a/b" instead of "b". Since the node
+ * has already been visited in pre-order, have to wait until the
+ * post-order visit to return the error. There is a special case
+ * here, if there was nothing to stat then it's not an error to
+ * not be able to stat. This is all fairly nasty. If a program
+ * needed sorted entries or stat information, they had better be
+ * checking FTS_NS on the returned nodes.
+ */
+ cderrno = 0;
+ if (nlinks || type == BREAD) {
+ if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
+ if (nlinks && type == BREAD)
+ cur->fts_errno = errno;
+ cur->fts_flags |= FTS_DONTCHDIR;
+ descend = 0;
+ cderrno = errno;
+ } else
+ descend = 1;
+ } else
+ descend = 0;
+
+ /*
+ * Figure out the max file name length that can be stored in the
+ * current path -- the inner loop allocates more path as necessary.
+ * We really wouldn't have to do the maxlen calculations here, we
+ * could do them in fts_read before returning the path, but it's a
+ * lot easier here since the length is part of the dirent structure.
+ *
+ * If not changing directories set a pointer so that can just append
+ * each new name into the path.
+ */
+ len = NAPPEND(cur);
+ if (ISSET(FTS_NOCHDIR)) {
+ cp = sp->fts_path + len;
+ *cp++ = '/';
+ }
+ len++;
+ maxlen = sp->fts_pathlen - len;
+
+#if defined(__FTS_COMPAT_LEVEL)
+ if (cur->fts_level == SHRT_MAX) {
+ (void)closedir(dirp);
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+#endif
+
+ level = cur->fts_level + 1;
+
+ /* Read the directory, attaching each entry to the `link' pointer. */
+ doadjust = 0;
+ for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) {
+
+ if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
+ continue;
+
+#if defined(HAVE_STRUCT_DIRENT_D_NAMLEN)
+ dnamlen = dp->d_namlen;
+#else
+ dnamlen = strlen(dp->d_name);
+#endif
+ if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL)
+ goto mem1;
+ if (dnamlen >= maxlen) { /* include space for NUL */
+ oldaddr = sp->fts_path;
+ if (fts_palloc(sp, dnamlen + len + 1)) {
+ /*
+ * No more memory for path or structures. Save
+ * errno, free up the current structure and the
+ * structures already allocated.
+ */
+mem1: saved_errno = errno;
+ if (p)
+ fts_free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
+ errno = saved_errno;
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ /* Did realloc() change the pointer? */
+ if (oldaddr != sp->fts_path) {
+ doadjust = 1;
+ if (ISSET(FTS_NOCHDIR))
+ cp = sp->fts_path + len;
+ }
+ maxlen = sp->fts_pathlen - len;
+ }
+
+#if defined(__FTS_COMPAT_LENGTH)
+ if (len + dnamlen >= USHRT_MAX) {
+ /*
+ * In an FTSENT, fts_pathlen is an unsigned short
+ * so it is possible to wraparound here.
+ * If we do, free up the current structure and the
+ * structures already allocated, then error out
+ * with ENAMETOOLONG.
+ */
+ fts_free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+#endif
+ p->fts_level = level;
+ p->fts_pathlen = len + dnamlen;
+ p->fts_parent = sp->fts_cur;
+
+#ifdef FTS_WHITEOUT
+ if (dp->d_type == DT_WHT)
+ p->fts_flags |= FTS_ISW;
+#endif
+
+ if (cderrno) {
+ if (nlinks) {
+ p->fts_info = FTS_NS;
+ p->fts_errno = cderrno;
+ } /* else
+ p->fts_info = FTS_NSOK;
+ */
+ /* Coverity Scan Id 1 says above is dead code */
+ p->fts_accpath = cur->fts_accpath;
+ } else if (nlinks == 0
+#ifdef DT_DIR
+ || (nostat &&
+ dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
+#endif
+ ) {
+ p->fts_accpath =
+ ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
+ p->fts_info = FTS_NSOK;
+ } else {
+ /* Build a file name for fts_stat to stat. */
+ if (ISSET(FTS_NOCHDIR)) {
+ p->fts_accpath = p->fts_path;
+ memmove(cp, p->fts_name,
+ (size_t)(p->fts_namelen + 1));
+ } else
+ p->fts_accpath = p->fts_name;
+ /* Stat it. */
+ p->fts_info = fts_stat(sp, p, 0);
+
+ /* Decrement link count if applicable. */
+ if (nlinks > 0 && (p->fts_info == FTS_D ||
+ p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
+ --nlinks;
+ }
+
+ /* We walk in directory order so "ls -f" doesn't get upset. */
+ p->fts_link = NULL;
+ if (head == NULL)
+ head = tail = p;
+ else {
+ tail->fts_link = p;
+ tail = p;
+ }
+ ++nitems;
+ }
+ (void)closedir(dirp);
+
+ /*
+ * If had to realloc the path, adjust the addresses for the rest
+ * of the tree.
+ */
+ if (doadjust)
+ fts_padjust(sp, head);
+
+ /*
+ * If not changing directories, reset the path back to original
+ * state.
+ */
+ if (ISSET(FTS_NOCHDIR)) {
+ if (len == sp->fts_pathlen || nitems == 0)
+ --cp;
+ *cp = '\0';
+ }
+
+ /*
+ * If descended after called from fts_children or after called from
+ * fts_read and nothing found, get back. At the root level we use
+ * the saved fd; if one of fts_open()'s arguments is a relative path
+ * to an empty directory, we wind up here with no other way back. If
+ * can't get back, we're done.
+ */
+ if (descend && (type == BCHILD || !nitems) &&
+ (cur->fts_level == FTS_ROOTLEVEL ?
+ FCHDIR(sp, sp->fts_rfd) :
+ fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+
+ /* If didn't find anything, return NULL. */
+ if (!nitems) {
+ if (type == BREAD)
+ cur->fts_info = FTS_DP;
+ return (NULL);
+ }
+
+ /* Sort the entries. */
+ if (sp->fts_compar && nitems > 1)
+ head = fts_sort(sp, head, nitems);
+ return (head);
+}
+
+static unsigned short
+fts_stat(FTS *sp, FTSENT *p, int follow)
+{
+ FTSENT *t;
+ dev_t dev;
+ __fts_ino_t ino;
+ __fts_stat_t *sbp, sb;
+ int saved_errno;
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(p != NULL);
+
+ /* If user needs stat info, stat buffer already allocated. */
+ sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+
+#ifdef FTS_WHITEOUT
+ /* check for whiteout */
+ if (p->fts_flags & FTS_ISW) {
+ if (sbp != &sb) {
+ memset(sbp, '\0', sizeof (*sbp));
+ sbp->st_mode = S_IFWHT;
+ }
+ return (FTS_W);
+ }
+#endif
+
+ /*
+ * If doing a logical walk, or application requested FTS_FOLLOW, do
+ * a stat(2). If that fails, check for a non-existent symlink. If
+ * fail, set the errno from the stat call.
+ */
+ if (ISSET(FTS_LOGICAL) || follow) {
+ if (stat(p->fts_accpath, sbp)) {
+ saved_errno = errno;
+ if (!lstat(p->fts_accpath, sbp)) {
+ errno = 0;
+ return (FTS_SLNONE);
+ }
+ p->fts_errno = saved_errno;
+ goto err;
+ }
+ } else if (lstat(p->fts_accpath, sbp)) {
+ p->fts_errno = errno;
+err: memset(sbp, 0, sizeof(*sbp));
+ return (FTS_NS);
+ }
+
+ if (S_ISDIR(sbp->st_mode)) {
+ /*
+ * Set the device/inode. Used to find cycles and check for
+ * crossing mount points. Also remember the link count, used
+ * in fts_build to limit the number of stat calls. It is
+ * understood that these fields are only referenced if fts_info
+ * is set to FTS_D.
+ */
+ dev = p->fts_dev = sbp->st_dev;
+ ino = p->fts_ino = sbp->st_ino;
+ p->fts_nlink = sbp->st_nlink;
+
+ if (ISDOT(p->fts_name))
+ return (FTS_DOT);
+
+ /*
+ * Cycle detection is done by brute force when the directory
+ * is first encountered. If the tree gets deep enough or the
+ * number of symbolic links to directories is high enough,
+ * something faster might be worthwhile.
+ */
+ for (t = p->fts_parent;
+ t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+ if (ino == t->fts_ino && dev == t->fts_dev) {
+ p->fts_cycle = t;
+ return (FTS_DC);
+ }
+ return (FTS_D);
+ }
+ if (S_ISLNK(sbp->st_mode))
+ return (FTS_SL);
+ if (S_ISREG(sbp->st_mode))
+ return (FTS_F);
+ return (FTS_DEFAULT);
+}
+
+static FTSENT *
+fts_sort(FTS *sp, FTSENT *head, size_t nitems)
+{
+ FTSENT **ap, *p;
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(head != NULL);
+
+ /*
+ * Construct an array of pointers to the structures and call qsort(3).
+ * Reassemble the array in the order returned by qsort. If unable to
+ * sort for memory reasons, return the directory entries in their
+ * current order. Allocate enough space for the current needs plus
+ * 40 so don't realloc one entry at a time.
+ */
+ if (nitems > sp->fts_nitems) {
+ FTSENT **new;
+
+ new = realloc(sp->fts_array, sizeof(FTSENT *) * (nitems + 40));
+ if (new == 0)
+ return (head);
+ sp->fts_array = new;
+ sp->fts_nitems = nitems + 40;
+ }
+ for (ap = sp->fts_array, p = head; p; p = p->fts_link)
+ *ap++ = p;
+ qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *),
+ (int (*)(const void *, const void *))sp->fts_compar);
+ for (head = *(ap = sp->fts_array); --nitems; ++ap)
+ ap[0]->fts_link = ap[1];
+ ap[0]->fts_link = NULL;
+ return (head);
+}
+
+static FTSENT *
+fts_alloc(FTS *sp, const char *name, size_t namelen)
+{
+ FTSENT *p;
+#if defined(FTS_ALLOC_ALIGNED)
+ size_t len;
+#endif
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(name != NULL);
+
+#if defined(FTS_ALLOC_ALIGNED)
+ /*
+ * The file name is a variable length array and no stat structure is
+ * necessary if the user has set the nostat bit. Allocate the FTSENT
+ * structure, the file name and the stat structure in one chunk, but
+ * be careful that the stat structure is reasonably aligned. Since the
+ * fts_name field is declared to be of size 1, the fts_name pointer is
+ * namelen + 2 before the first possible address of the stat structure.
+ */
+ len = sizeof(FTSENT) + namelen;
+ if (!ISSET(FTS_NOSTAT))
+ len += sizeof(*(p->fts_statp)) + ALIGNBYTES;
+ if ((p = malloc(len)) == NULL)
+ return (NULL);
+
+ if (!ISSET(FTS_NOSTAT))
+ p->fts_statp = (__fts_stat_t *)ALIGN(p->fts_name + namelen + 2);
+#else
+ if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL)
+ return (NULL);
+
+ if (!ISSET(FTS_NOSTAT))
+ if ((p->fts_statp = malloc(sizeof(*(p->fts_statp)))) == NULL) {
+ free(p);
+ return (NULL);
+ }
+#endif
+
+ if (ISSET(FTS_NOSTAT))
+ p->fts_statp = NULL;
+
+ /* Copy the name plus the trailing NULL. */
+ memmove(p->fts_name, name, namelen + 1);
+
+ p->fts_namelen = namelen;
+ p->fts_path = sp->fts_path;
+ p->fts_errno = 0;
+ p->fts_flags = 0;
+ p->fts_instr = FTS_NOINSTR;
+ p->fts_number = 0;
+ p->fts_pointer = NULL;
+ return (p);
+}
+
+static void
+fts_free(FTSENT *p)
+{
+#if !defined(FTS_ALLOC_ALIGNED)
+ if (p->fts_statp)
+ free(p->fts_statp);
+#endif
+ free(p);
+}
+
+static void
+fts_lfree(FTSENT *head)
+{
+ FTSENT *p;
+
+ /* XXX: head may be NULL ? */
+
+ /* Free a linked list of structures. */
+ while ((p = head) != NULL) {
+ head = head->fts_link;
+ fts_free(p);
+ }
+}
+
+static size_t
+fts_pow2(size_t x)
+{
+
+ x--;
+ x |= x>>1;
+ x |= x>>2;
+ x |= x>>4;
+ x |= x>>8;
+#if (SIZEOF_SIZE_T * CHAR_BIT) > 16
+ x |= x>>16;
+#endif
+#if (SIZEOF_SIZE_T * CHAR_BIT) > 32
+ x |= x>>32;
+#endif
+#if (SIZEOF_SIZE_T * CHAR_BIT) > 64
+ x |= x>>64;
+#endif
+ x++;
+ return (x);
+}
+
+/*
+ * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
+ * Most systems will allow creation of paths much longer than MAXPATHLEN, even
+ * though the kernel won't resolve them. Round up the new size to a power of 2,
+ * so we don't realloc the path 2 bytes at a time.
+ */
+static int
+fts_palloc(FTS *sp, size_t size)
+{
+ char *new;
+
+ _DIAGASSERT(sp != NULL);
+
+#ifdef __FTS_COMPAT_LENGTH
+ /* Protect against fts_pathlen overflow. */
+ if (size > USHRT_MAX + 1) {
+ errno = ENAMETOOLONG;
+ return (1);
+ }
+#endif
+ size = fts_pow2(size);
+ new = realloc(sp->fts_path, size);
+ if (new == 0)
+ return (1);
+ sp->fts_path = new;
+ sp->fts_pathlen = size;
+ return (0);
+}
+
+/*
+ * When the path is realloc'd, have to fix all of the pointers in structures
+ * already returned.
+ */
+static void
+fts_padjust(FTS *sp, FTSENT *head)
+{
+ FTSENT *p;
+ char *addr;
+
+ _DIAGASSERT(sp != NULL);
+
+#define ADJUST(p) do { \
+ if ((p)->fts_accpath != (p)->fts_name) \
+ (p)->fts_accpath = \
+ addr + ((p)->fts_accpath - (p)->fts_path); \
+ (p)->fts_path = addr; \
+} while (/*CONSTCOND*/0)
+
+ addr = sp->fts_path;
+
+ /* Adjust the current set of children. */
+ for (p = sp->fts_child; p; p = p->fts_link)
+ ADJUST(p);
+
+ /* Adjust the rest of the tree, including the current level. */
+ for (p = head; p->fts_level >= FTS_ROOTLEVEL;) {
+ ADJUST(p);
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ }
+}
+
+static size_t
+fts_maxarglen(char * const *argv)
+{
+ size_t len, max;
+
+ _DIAGASSERT(argv != NULL);
+
+ for (max = 0; *argv; ++argv)
+ if ((len = strlen(*argv)) > max)
+ max = len;
+ return (max + 1);
+}
+
+/*
+ * Change to dir specified by fd or p->fts_accpath without getting
+ * tricked by someone changing the world out from underneath us.
+ * Assumes p->fts_dev and p->fts_ino are filled in.
+ */
+static int
+fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path)
+{
+ int oldfd = fd, ret = -1;
+ __fts_stat_t sb;
+
+ if (ISSET(FTS_NOCHDIR))
+ return 0;
+
+ if (oldfd < 0 && (fd = open(path, O_RDONLY)) == -1)
+ return -1;
+
+ if (fstat(fd, &sb) == -1)
+ goto bail;
+
+ if (sb.st_ino != p->fts_ino || sb.st_dev != p->fts_dev) {
+ errno = ENOENT;
+ goto bail;
+ }
+
+ ret = fchdir(fd);
+
+bail:
+ if (oldfd < 0) {
+ int save_errno = errno;
+ (void)close(fd);
+ errno = save_errno;
+ }
+ return ret;
+}
diff --git a/cpukit/libmisc/shell/fts.h b/cpukit/libmisc/shell/fts.h
new file mode 100644
index 0000000000..68e9d46c3e
--- /dev/null
+++ b/cpukit/libmisc/shell/fts.h
@@ -0,0 +1,146 @@
+/* $NetBSD: fts.h,v 1.14 2005/09/13 01:44:32 christos Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)fts.h 8.3 (Berkeley) 8/14/94
+ */
+
+#ifndef _FTS_H_
+#define _FTS_H_
+
+#ifndef __fts_stat_t
+#define __fts_stat_t struct stat
+#endif
+#ifndef __fts_nlink_t
+#define __fts_nlink_t nlink_t
+#endif
+#ifndef __fts_ino_t
+#define __fts_ino_t ino_t
+#endif
+
+typedef struct {
+ struct _ftsent *fts_cur; /* current node */
+ struct _ftsent *fts_child; /* linked list of children */
+ struct _ftsent **fts_array; /* sort array */
+ dev_t fts_dev; /* starting device # */
+ char *fts_path; /* path for this descent */
+ int fts_rfd; /* fd for root */
+ u_int fts_pathlen; /* sizeof(path) */
+ u_int fts_nitems; /* elements in the sort array */
+ int (*fts_compar) /* compare function */
+ (const struct _ftsent **, const struct _ftsent **);
+
+#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
+#define FTS_LOGICAL 0x002 /* logical walk */
+#define FTS_NOCHDIR 0x004 /* don't change directories */
+#define FTS_NOSTAT 0x008 /* don't get stat info */
+#define FTS_PHYSICAL 0x010 /* physical walk */
+#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
+#define FTS_XDEV 0x040 /* don't cross devices */
+#define FTS_WHITEOUT 0x080 /* return whiteout information */
+#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
+
+#define FTS_NAMEONLY 0x100 /* (private) child names only */
+#define FTS_STOP 0x200 /* (private) unrecoverable error */
+ int fts_options; /* fts_open options, global flags */
+} FTS;
+
+typedef struct _ftsent {
+ struct _ftsent *fts_cycle; /* cycle node */
+ struct _ftsent *fts_parent; /* parent directory */
+ struct _ftsent *fts_link; /* next file in directory */
+ long fts_number; /* local numeric value */
+ void *fts_pointer; /* local address value */
+ char *fts_accpath; /* access path */
+ char *fts_path; /* root path */
+ int fts_errno; /* errno for this node */
+ int fts_symfd; /* fd for symlink */
+ u_short fts_pathlen; /* strlen(fts_path) */
+ u_short fts_namelen; /* strlen(fts_name) */
+
+ __fts_ino_t fts_ino; /* inode */
+ dev_t fts_dev; /* device */
+ __fts_nlink_t fts_nlink; /* link count */
+
+#define FTS_ROOTPARENTLEVEL -1
+#define FTS_ROOTLEVEL 0
+ short fts_level; /* depth (-1 to N) */
+
+#define FTS_D 1 /* preorder directory */
+#define FTS_DC 2 /* directory that causes cycles */
+#define FTS_DEFAULT 3 /* none of the above */
+#define FTS_DNR 4 /* unreadable directory */
+#define FTS_DOT 5 /* dot or dot-dot */
+#define FTS_DP 6 /* postorder directory */
+#define FTS_ERR 7 /* error; errno is set */
+#define FTS_F 8 /* regular file */
+#define FTS_INIT 9 /* initialized only */
+#define FTS_NS 10 /* stat(2) failed */
+#define FTS_NSOK 11 /* no stat(2) requested */
+#define FTS_SL 12 /* symbolic link */
+#define FTS_SLNONE 13 /* symbolic link without target */
+#define FTS_W 14 /* whiteout object */
+ u_short fts_info; /* user flags for FTSENT structure */
+
+#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
+#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
+#define FTS_ISW 0x04 /* this is a whiteout object */
+ u_short fts_flags; /* private flags for FTSENT structure */
+
+#define FTS_AGAIN 1 /* read node again */
+#define FTS_FOLLOW 2 /* follow symbolic link */
+#define FTS_NOINSTR 3 /* no instructions */
+#define FTS_SKIP 4 /* discard node */
+ u_short fts_instr; /* fts_set() instructions */
+
+ __fts_stat_t *fts_statp; /* stat(2) information */
+ char fts_name[1]; /* file name */
+} FTSENT;
+
+#include <sys/cdefs.h>
+
+#define __RENAME(n)
+#define fts_children rtems_shell_fts_children
+#define fts_close rtems_shell_fts_close
+#define fts_open rtems_shell_fts_open
+#define fts_read rtems_shell_fts_read
+#define fts_set rtems_shell_fts_set
+
+__BEGIN_DECLS
+#ifndef __LIBC12_SOURCE__
+FTSENT *fts_children(FTS *, int) __RENAME(__fts_children30);
+int fts_close(FTS *) __RENAME(__fts_close30);
+FTS *fts_open(char * const *, int,
+ int (*)(const FTSENT **, const FTSENT **)) __RENAME(__fts_open30);
+FTSENT *fts_read(FTS *) __RENAME(__fts_read30);
+int fts_set(FTS *, FTSENT *, int) __RENAME(__fts_set30);
+#endif
+__END_DECLS
+
+#endif /* !_FTS_H_ */
diff --git a/cpukit/libmisc/shell/hexdump-conv.c b/cpukit/libmisc/shell/hexdump-conv.c
new file mode 100644
index 0000000000..44390baa32
--- /dev/null
+++ b/cpukit/libmisc/shell/hexdump-conv.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+static const char sccsid[] = "@(#)conv.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/hexdump/conv.c,v 1.9 2006/07/31 14:17:04 jkoshy Exp $");
+
+#include <sys/types.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+#include "hexdump.h"
+
+void
+conv_c(rtems_shell_hexdump_globals* globals, PR *pr, u_char *p, size_t bufsize)
+{
+ char buf[10];
+ char const *str;
+ wchar_t wc;
+ size_t clen, oclen;
+ int converr, pad, width;
+ char peekbuf[MB_LEN_MAX];
+
+ if (pr->mbleft > 0) {
+ str = "**";
+ pr->mbleft--;
+ goto strpr;
+ }
+
+ switch(*p) {
+ case '\0':
+ str = "\\0";
+ goto strpr;
+ /* case '\a': */
+ case '\007':
+ str = "\\a";
+ goto strpr;
+ case '\b':
+ str = "\\b";
+ goto strpr;
+ case '\f':
+ str = "\\f";
+ goto strpr;
+ case '\n':
+ str = "\\n";
+ goto strpr;
+ case '\r':
+ str = "\\r";
+ goto strpr;
+ case '\t':
+ str = "\\t";
+ goto strpr;
+ case '\v':
+ str = "\\v";
+ goto strpr;
+ default:
+ break;
+ }
+ /*
+ * Multibyte characters are disabled for hexdump(1) for backwards
+ * compatibility and consistency (none of its other output formats
+ * recognize them correctly).
+ */
+ converr = 0;
+ if (odmode && MB_CUR_MAX > 1) {
+ oclen = 0;
+retry:
+ clen = mbrtowc(&wc, (char*)p, bufsize, &pr->mbstate);
+ if (clen == 0)
+ clen = 1;
+ else if (clen == (size_t)-1 || (clen == (size_t)-2 &&
+ buf == peekbuf)) {
+ memset(&pr->mbstate, 0, sizeof(pr->mbstate));
+ wc = *p;
+ clen = 1;
+ converr = 1;
+ } else if (clen == (size_t)-2) {
+ /*
+ * Incomplete character; peek ahead and see if we
+ * can complete it.
+ */
+ oclen = bufsize;
+ bufsize = peek(globals, p = (u_char*)peekbuf, MB_CUR_MAX);
+ goto retry;
+ }
+ clen += oclen;
+ } else {
+ wc = *p;
+ clen = 1;
+ }
+ if (!converr && iswprint(wc)) {
+ if (!odmode) {
+ *pr->cchar = 'c';
+ (void)printf(pr->fmt, (int)wc);
+ } else {
+ *pr->cchar = 'C';
+ assert(strcmp(pr->fmt, "%3C") == 0);
+ width = wcwidth(wc);
+ assert(width >= 0);
+ pad = 3 - width;
+ if (pad < 0)
+ pad = 0;
+ (void)printf("%*s%lc", pad, "", wc);
+ pr->mbleft = clen - 1;
+ }
+ } else {
+ (void)sprintf(buf, "%03o", (int)*p);
+ str = buf;
+strpr: *pr->cchar = 's';
+ (void)printf(pr->fmt, str);
+ }
+}
+
+void
+conv_u(rtems_shell_hexdump_globals* globals, PR *pr, u_char *p)
+{
+ static char const * list[] = {
+ "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
+ "bs", "ht", "lf", "vt", "ff", "cr", "so", "si",
+ "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb",
+ "can", "em", "sub", "esc", "fs", "gs", "rs", "us",
+ };
+
+ /* od used nl, not lf */
+ if (*p <= 0x1f) {
+ *pr->cchar = 's';
+ if (odmode && *p == 0x0a)
+ (void)printf(pr->fmt, "nl");
+ else
+ (void)printf(pr->fmt, list[*p]);
+ } else if (*p == 0x7f) {
+ *pr->cchar = 's';
+ (void)printf(pr->fmt, "del");
+ } else if (odmode && *p == 0x20) { /* od replaced space with sp */
+ *pr->cchar = 's';
+ (void)printf(pr->fmt, " sp");
+ } else if (isprint(*p)) {
+ *pr->cchar = 'c';
+ (void)printf(pr->fmt, *p);
+ } else {
+ *pr->cchar = 'x';
+ (void)printf(pr->fmt, (int)*p);
+ }
+}
diff --git a/cpukit/libmisc/shell/hexdump-display.c b/cpukit/libmisc/shell/hexdump-display.c
new file mode 100644
index 0000000000..3e33fba143
--- /dev/null
+++ b/cpukit/libmisc/shell/hexdump-display.c
@@ -0,0 +1,431 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
+#endif
+#endif /* not lint */
+#if 0
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/hexdump/display.c,v 1.22 2004/08/04 02:47:32 tjr Exp $");
+#endif
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <stdint.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "hexdump.h"
+
+#define bcmp(s1,s2,sz) memcmp(s1,s2,sz)
+#define bcopy(s,d,sz) memcpy(d,s,sz)
+#define bzero(s,sz) memset(s,0,sz)
+#define index(s,c) strchr(s,c)
+
+#if RTEMS_REMOVED
+enum _vflag vflag = FIRST;
+
+static off_t address; /* address/offset in stream */
+static off_t eaddress; /* end address */
+#endif
+
+static void print(rtems_shell_hexdump_globals*, PR *, u_char *);
+
+void
+display(rtems_shell_hexdump_globals* globals)
+{
+ FS *fs;
+ FU *fu;
+ PR *pr;
+ int cnt;
+ u_char *bp;
+ off_t saveaddress;
+ u_char savech, *savebp;
+
+ savech = 0;
+ while ((bp = get(globals)))
+ for (fs = fshead, savebp = bp, saveaddress = address; fs;
+ fs = fs->nextfs, bp = savebp, address = saveaddress)
+ for (fu = fs->nextfu; fu; fu = fu->nextfu) {
+ if (fu->flags&F_IGNORE)
+ break;
+ for (cnt = fu->reps; cnt; --cnt)
+ for (pr = fu->nextpr; pr; address += pr->bcnt,
+ bp += pr->bcnt, pr = pr->nextpr) {
+ if (eaddress && address >= eaddress &&
+ !(pr->flags & (F_TEXT|F_BPAD)))
+ bpad(pr);
+ if (cnt == 1 && pr->nospace) {
+ savech = *pr->nospace;
+ *pr->nospace = '\0';
+ }
+ print(globals, pr, bp);
+ if (cnt == 1 && pr->nospace)
+ *pr->nospace = savech;
+ }
+ }
+ if (endfu) {
+ /*
+ * If eaddress not set, error or file size was multiple of
+ * blocksize, and no partial block ever found.
+ */
+ if (!eaddress) {
+ if (!address)
+ return;
+ eaddress = address;
+ }
+ for (pr = endfu->nextpr; pr; pr = pr->nextpr)
+ switch(pr->flags) {
+ case F_ADDRESS:
+ (void)printf(pr->fmt, (quad_t)eaddress);
+ break;
+ case F_TEXT:
+ (void)printf("%s", pr->fmt);
+ break;
+ }
+ }
+}
+
+static void
+print(rtems_shell_hexdump_globals* globals, PR *pr, u_char *bp)
+{
+ long double ldbl;
+ double f8;
+ float f4;
+ int16_t s2;
+ int8_t s8;
+ int32_t s4;
+ u_int16_t u2;
+ u_int32_t u4;
+ u_int64_t u8;
+
+ switch(pr->flags) {
+ case F_ADDRESS:
+ (void)printf(pr->fmt, (quad_t)address);
+ break;
+ case F_BPAD:
+ (void)printf(pr->fmt, "");
+ break;
+ case F_C:
+ conv_c(globals, pr, bp, eaddress ? eaddress - address :
+ blocksize - address % blocksize);
+ break;
+ case F_CHAR:
+ (void)printf(pr->fmt, *bp);
+ break;
+ case F_DBL:
+ switch(pr->bcnt) {
+ case 4:
+ bcopy(bp, &f4, sizeof(f4));
+ (void)printf(pr->fmt, f4);
+ break;
+ case 8:
+ bcopy(bp, &f8, sizeof(f8));
+ (void)printf(pr->fmt, f8);
+ break;
+ default:
+ if (pr->bcnt == sizeof(long double)) {
+ bcopy(bp, &ldbl, sizeof(ldbl));
+ (void)printf(pr->fmt, ldbl);
+ }
+ break;
+ }
+ break;
+ case F_INT:
+ switch(pr->bcnt) {
+ case 1:
+ (void)printf(pr->fmt, (quad_t)(signed char)*bp);
+ break;
+ case 2:
+ bcopy(bp, &s2, sizeof(s2));
+ (void)printf(pr->fmt, (quad_t)s2);
+ break;
+ case 4:
+ bcopy(bp, &s4, sizeof(s4));
+ (void)printf(pr->fmt, (quad_t)s4);
+ break;
+ case 8:
+ bcopy(bp, &s8, sizeof(s8));
+ (void)printf(pr->fmt, s8);
+ break;
+ }
+ break;
+ case F_P:
+ (void)printf(pr->fmt, isprint(*bp) ? *bp : '.');
+ break;
+ case F_STR:
+ (void)printf(pr->fmt, (char *)bp);
+ break;
+ case F_TEXT:
+ (void)printf("%s", pr->fmt);
+ break;
+ case F_U:
+ conv_u(globals, pr, bp);
+ break;
+ case F_UINT:
+ switch(pr->bcnt) {
+ case 1:
+ (void)printf(pr->fmt, (u_quad_t)*bp);
+ break;
+ case 2:
+ bcopy(bp, &u2, sizeof(u2));
+ (void)printf(pr->fmt, (u_quad_t)u2);
+ break;
+ case 4:
+ bcopy(bp, &u4, sizeof(u4));
+ (void)printf(pr->fmt, (u_quad_t)u4);
+ break;
+ case 8:
+ bcopy(bp, &u8, sizeof(u8));
+ (void)printf(pr->fmt, u8);
+ break;
+ }
+ break;
+ }
+}
+
+void
+bpad(PR *pr)
+{
+ static char const *spec = " -0+#";
+ char *p1, *p2;
+
+ /*
+ * Remove all conversion flags; '-' is the only one valid
+ * with %s, and it's not useful here.
+ */
+ pr->flags = F_BPAD;
+ pr->cchar[0] = 's';
+ pr->cchar[1] = '\0';
+ for (p1 = pr->fmt; *p1 != '%'; ++p1);
+ for (p2 = ++p1; *p1 && index(spec, *p1); ++p1);
+ while ((*p2++ = *p1++));
+}
+
+static char **_argv;
+
+u_char *
+get(rtems_shell_hexdump_globals* globals)
+{
+#if RTEMS_REMOVED
+ static int ateof = 1;
+ static u_char *curp, *savp;
+#endif
+ int n;
+ int need, nread;
+ int valid_save = 0;
+ u_char *tmpp;
+
+ if (!curp) {
+ if ((curp = calloc(1, blocksize)) == NULL)
+ err(exit_jump, 1, NULL);
+ if ((savp = calloc(1, blocksize)) == NULL)
+ err(exit_jump, 1, NULL);
+ } else {
+ tmpp = curp;
+ curp = savp;
+ savp = tmpp;
+ address += blocksize;
+ valid_save = 1;
+ }
+ for (need = blocksize, nread = 0;;) {
+ /*
+ * if read the right number of bytes, or at EOF for one file,
+ * and no other files are available, zero-pad the rest of the
+ * block and set the end flag.
+ */
+ if (!length || (ateof && !next(globals, (char **)NULL))) {
+ if (odmode && address < skip)
+ errx(exit_jump, 1, "cannot skip past end of input");
+ if (need == blocksize)
+ return((u_char *)NULL);
+ /*
+ * XXX bcmp() is not quite right in the presence
+ * of multibyte characters.
+ */
+ if (vflag != ALL &&
+ valid_save &&
+ bcmp(curp, savp, nread) == 0) {
+ if (vflag != DUP)
+ (void)printf("*\n");
+ return((u_char *)NULL);
+ }
+ bzero((char *)curp + nread, need);
+ eaddress = address + nread;
+ return(curp);
+ }
+ n = fread((char *)curp + nread, sizeof(u_char),
+ length == -1 ? need : MIN(length, need), hdstdin);
+ if (!n) {
+ if (ferror(hdstdin))
+ warn("%s", _argv[-1]);
+ ateof = 1;
+ continue;
+ }
+ ateof = 0;
+ if (length != -1)
+ length -= n;
+ if (!(need -= n)) {
+ /*
+ * XXX bcmp() is not quite right in the presence
+ * of multibyte characters.
+ */
+ if (vflag == ALL || vflag == FIRST ||
+ valid_save == 0 ||
+ bcmp(curp, savp, blocksize) != 0) {
+ if (vflag == DUP || vflag == FIRST)
+ vflag = WAIT;
+ return(curp);
+ }
+ if (vflag == WAIT)
+ (void)printf("*\n");
+ vflag = DUP;
+ address += blocksize;
+ need = blocksize;
+ nread = 0;
+ }
+ else
+ nread += n;
+ }
+}
+
+size_t
+peek(rtems_shell_hexdump_globals* globals, u_char *buf, size_t nbytes)
+{
+ size_t n, nread;
+ int c;
+
+ if (length != -1 && nbytes > (unsigned int)length)
+ nbytes = length;
+ nread = 0;
+ while (nread < nbytes && (c = getchar()) != EOF) {
+ *buf++ = c;
+ nread++;
+ }
+ n = nread;
+ while (n-- > 0) {
+ c = *--buf;
+ ungetc(c, hdstdin);
+ }
+ return (nread);
+}
+
+int
+next(rtems_shell_hexdump_globals* globals, char **argv)
+{
+#if RTEMS_REMOVED
+ static int done;
+#endif
+ int statok;
+
+ if (argv) {
+ _argv = argv;
+ return(1);
+ }
+ for (;;) {
+ if (*_argv) {
+ done = 1;
+ if (!hdstdin) {
+ hdstdin = malloc(sizeof(FILE));
+ if (!hdstdin)
+ {
+ errno = ENOMEM;
+ err(exit_jump, 1, "file name allocation");
+ }
+ memset (hdstdin, 0, sizeof(FILE));
+ }
+ if (!(hdstdin = freopen(*_argv, "r", hdstdin))) {
+ warn("%s", *_argv);
+ exitval = 1;
+ ++_argv;
+ continue;
+ }
+ statok = 1;
+ } else {
+ errno = ECANCELED;
+ err(exit_jump, 1, "no file (stdin no supported)");
+ if (done++)
+ return(0);
+ statok = 0;
+ }
+ if (skip)
+ doskip(globals, statok ? *_argv : "stdin", statok);
+ if (*_argv)
+ ++_argv;
+ if (!skip)
+ return(1);
+ }
+ /* NOTREACHED */
+}
+
+void
+doskip(rtems_shell_hexdump_globals* globals, const char *fname, int statok)
+{
+ int cnt;
+ struct stat sb;
+
+ if (statok) {
+ if (fstat(fileno(hdstdin), &sb))
+ err(exit_jump, 1, "%s", fname);
+ /* can seek block devices on RTEMS */
+ if (0 && S_ISREG(sb.st_mode) && skip >= sb.st_size) {
+ address += sb.st_size;
+ skip -= sb.st_size;
+ return;
+ }
+ if (1 || S_ISREG(sb.st_mode)) {
+ if (fseeko(hdstdin, skip, SEEK_SET))
+ err(exit_jump, 1, "%s", fname);
+ address += skip;
+ skip = 0;
+ } else {
+ for (cnt = 0; cnt < skip; ++cnt)
+ if (getchar() == EOF)
+ break;
+ address += cnt;
+ skip -= cnt;
+ }
+ }
+}
diff --git a/cpukit/libmisc/shell/hexdump-odsyntax.c b/cpukit/libmisc/shell/hexdump-odsyntax.c
new file mode 100644
index 0000000000..24e8d59e73
--- /dev/null
+++ b/cpukit/libmisc/shell/hexdump-odsyntax.c
@@ -0,0 +1,451 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/hexdump/odsyntax.c,v 1.17 2004/07/22 13:14:42 johan Exp $");
+#endif
+
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <float.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "hexdump.h"
+
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#define PADDING " "
+
+#if RTEMS_REMOVED
+int odmode;
+#endif
+
+static void odadd(rtems_shell_hexdump_globals*, const char *);
+static void odformat(rtems_shell_hexdump_globals*, const char *);
+static const char *odformatfp(rtems_shell_hexdump_globals*, char, const char *);
+static const char *odformatint(rtems_shell_hexdump_globals*, char, const char *);
+static void odoffset(rtems_shell_hexdump_globals*, int, char ***);
+static void odusage(rtems_shell_hexdump_globals*);
+
+void
+oldsyntax(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
+{
+ static char empty[] = "", padding[] = PADDING;
+ int ch;
+ char **argv, *end;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+ /* Add initial (default) address format. -A may change it later. */
+#define TYPE_OFFSET 7
+ add(globals, "\"%07.7_Ao\n\"");
+ add(globals, "\"%07.7_ao \"");
+
+ odmode = 1;
+ argv = *argvp;
+ while ((ch = getopt_r(argc, argv, "A:aBbcDdeFfHhIij:LlN:Oost:vXx", &getopt_reent)) != -1)
+ switch (ch) {
+ case 'A':
+ switch (*optarg) {
+ case 'd': case 'o': case 'x':
+ fshead->nextfu->fmt[TYPE_OFFSET] = *optarg;
+ fshead->nextfs->nextfu->fmt[TYPE_OFFSET] =
+ *optarg;
+ break;
+ case 'n':
+ fshead->nextfu->fmt = empty;
+ fshead->nextfs->nextfu->fmt = padding;
+ break;
+ default:
+ errx(exit_jump, 1, "%s: invalid address base", optarg);
+ }
+ break;
+ case 'a':
+ odformat(globals, "a");
+ break;
+ case 'B':
+ case 'o':
+ odformat(globals, "o2");
+ break;
+ case 'b':
+ odformat(globals, "o1");
+ break;
+ case 'c':
+ odformat(globals, "c");
+ break;
+ case 'd':
+ odformat(globals, "u2");
+ break;
+ case 'D':
+ odformat(globals, "u4");
+ break;
+ case 'e': /* undocumented in od */
+ case 'F':
+ odformat(globals, "fD");
+ break;
+ case 'f':
+ odformat(globals, "fF");
+ break;
+ case 'H':
+ case 'X':
+ odformat(globals, "x4");
+ break;
+ case 'h':
+ case 'x':
+ odformat(globals, "x2");
+ break;
+ case 'I':
+ case 'L':
+ case 'l':
+ odformat(globals, "dL");
+ break;
+ case 'i':
+ odformat(globals, "dI");
+ break;
+ case 'j':
+ errno = 0;
+ skip = strtoll(optarg, &end, 0);
+ if (*end == 'b')
+ skip *= 512;
+ else if (*end == 'k')
+ skip *= 1024;
+ else if (*end == 'm')
+ skip *= 1048576L;
+ if (errno != 0 || skip < 0 || strlen(end) > 1)
+ errx(exit_jump, 1, "%s: invalid skip amount", optarg);
+ break;
+ case 'N':
+ if ((length = atoi(optarg)) <= 0)
+ errx(exit_jump, 1, "%s: invalid length", optarg);
+ break;
+ case 'O':
+ odformat(globals, "o4");
+ break;
+ case 's':
+ odformat(globals, "d2");
+ break;
+ case 't':
+ odformat(globals, optarg);
+ break;
+ case 'v':
+ vflag = ALL;
+ break;
+ case '?':
+ default:
+ odusage(globals);
+ }
+
+ if (fshead->nextfs->nextfs == NULL)
+ odformat(globals, "oS");
+
+ argc -= getopt_reent.optind;
+ *argvp += getopt_reent.optind;
+
+ if (argc)
+ odoffset(globals, argc, argvp);
+}
+
+static void
+odusage(rtems_shell_hexdump_globals* globals)
+{
+
+ fprintf(stderr,
+"usage: od [-aBbcDdeFfHhIiLlOosvXx] [-A base] [-j skip] [-N length] [-t type]\n");
+ fprintf(stderr,
+" [[+]offset[.][Bb]] [file ...]\n");
+ exit(1);
+}
+
+static void
+odoffset(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
+{
+ char *p, *num, *end;
+ int base;
+
+ /*
+ * The offset syntax of od(1) was genuinely bizarre. First, if
+ * it started with a plus it had to be an offset. Otherwise, if
+ * there were at least two arguments, a number or lower-case 'x'
+ * followed by a number makes it an offset. By default it was
+ * octal; if it started with 'x' or '0x' it was hex. If it ended
+ * in a '.', it was decimal. If a 'b' or 'B' was appended, it
+ * multiplied the number by 512 or 1024 byte units. There was
+ * no way to assign a block count to a hex offset.
+ *
+ * We assume it's a file if the offset is bad.
+ */
+ p = argc == 1 ? (*argvp)[0] : (*argvp)[1];
+
+ if (*p != '+' && (argc < 2 ||
+ (!isdigit((unsigned char)p[0]) && (p[0] != 'x' || !isxdigit((unsigned char)p[1])))))
+ return;
+
+ base = 0;
+ /*
+ * skip over leading '+', 'x[0-9a-fA-f]' or '0x', and
+ * set base.
+ */
+ if (p[0] == '+')
+ ++p;
+ if (p[0] == 'x' && isxdigit((unsigned char)p[1])) {
+ ++p;
+ base = 16;
+ } else if (p[0] == '0' && p[1] == 'x') {
+ p += 2;
+ base = 16;
+ }
+
+ /* skip over the number */
+ if (base == 16)
+ for (num = p; isxdigit((unsigned char)*p); ++p);
+ else
+ for (num = p; isdigit((unsigned char)*p); ++p);
+
+ /* check for no number */
+ if (num == p)
+ return;
+
+ /* if terminates with a '.', base is decimal */
+ if (*p == '.') {
+ if (base)
+ return;
+ base = 10;
+ }
+
+ skip = strtoll(num, &end, base ? base : 8);
+
+ /* if end isn't the same as p, we got a non-octal digit */
+ if (end != p) {
+ skip = 0;
+ return;
+ }
+
+ if (*p) {
+ if (*p == 'B') {
+ skip *= 1024;
+ ++p;
+ } else if (*p == 'b') {
+ skip *= 512;
+ ++p;
+ }
+ }
+
+ if (*p) {
+ skip = 0;
+ return;
+ }
+
+ /*
+ * If the offset uses a non-octal base, the base of the offset
+ * is changed as well. This isn't pretty, but it's easy.
+ */
+ if (base == 16) {
+ fshead->nextfu->fmt[TYPE_OFFSET] = 'x';
+ fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x';
+ } else if (base == 10) {
+ fshead->nextfu->fmt[TYPE_OFFSET] = 'd';
+ fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'd';
+ }
+
+ /* Terminate file list. */
+ (*argvp)[1] = NULL;
+}
+
+static void
+odformat(rtems_shell_hexdump_globals* globals, const char *fmt)
+{
+ char fchar;
+
+ while (*fmt != '\0') {
+ switch ((fchar = *fmt++)) {
+ case 'a':
+ odadd(globals, "16/1 \"%3_u \" \"\\n\"");
+ break;
+ case 'c':
+ odadd(globals, "16/1 \"%3_c \" \"\\n\"");
+ break;
+ case 'o': case 'u': case 'd': case 'x':
+ fmt = odformatint(globals, fchar, fmt);
+ break;
+ case 'f':
+ fmt = odformatfp(globals, fchar, fmt);
+ break;
+ default:
+ errx(exit_jump, 1, "%c: unrecognised format character", fchar);
+ }
+ }
+}
+#define __unused
+
+static const char *
+odformatfp(rtems_shell_hexdump_globals* globals, char fchar __unused, const char *fmt)
+{
+ size_t isize;
+ int digits;
+ char *end, *hdfmt;
+
+ isize = sizeof(double);
+ switch (*fmt) {
+ case 'F':
+ isize = sizeof(float);
+ fmt++;
+ break;
+ case 'D':
+ isize = sizeof(double);
+ fmt++;
+ break;
+ case 'L':
+ isize = sizeof(long double);
+ fmt++;
+ break;
+ default:
+ if (isdigit((unsigned char)*fmt)) {
+ errno = 0;
+ isize = (size_t)strtoul(fmt, &end, 10);
+ if (errno != 0 || isize == 0)
+ errx(exit_jump, 1, "%s: invalid size", fmt);
+ fmt = (const char *)end;
+ }
+ }
+ if (isize == sizeof(float) ) {
+ digits = FLT_DIG;
+ } else if (isize == sizeof(double)) {
+ digits = DBL_DIG;
+ } else if (isize == sizeof(long double)) {
+ digits = LDBL_DIG;
+ } else {
+ errx(exit_jump, 1, "unsupported floating point size %zu",
+ isize);
+ }
+
+ asprintf(&hdfmt, "%lu/%lu \" %%%d.%de \" \"\\n\"",
+ 16UL / (u_long)isize, (u_long)isize, digits + 8, digits);
+ if (hdfmt == NULL)
+ err(exit_jump, 1, NULL);
+ odadd(globals, hdfmt);
+ free(hdfmt);
+
+ return (fmt);
+}
+
+static const char *
+odformatint(rtems_shell_hexdump_globals* globals, char fchar, const char *fmt)
+{
+ unsigned long long n;
+ size_t isize;
+ int digits;
+ char *end, *hdfmt;
+
+ isize = sizeof(int);
+ switch (*fmt) {
+ case 'C':
+ isize = sizeof(char);
+ fmt++;
+ break;
+ case 'I':
+ isize = sizeof(int);
+ fmt++;
+ break;
+ case 'L':
+ isize = sizeof(long);
+ fmt++;
+ break;
+ case 'S':
+ isize = sizeof(short);
+ fmt++;
+ break;
+ default:
+ if (isdigit((unsigned char)*fmt)) {
+ errno = 0;
+ isize = (size_t)strtoul(fmt, &end, 10);
+ if (errno != 0 || isize == 0)
+ errx(exit_jump, 1, "%s: invalid size", fmt);
+ if (isize != sizeof(char) && isize != sizeof(short) &&
+ isize != sizeof(int) && isize != sizeof(long))
+ errx(exit_jump, 1, "unsupported int size %lu",
+ (u_long)isize);
+ fmt = (const char *)end;
+ }
+ }
+
+ /*
+ * Calculate the maximum number of digits we need to
+ * fit the number. Overestimate for decimal with log
+ * base 8. We need one extra space for signed numbers
+ * to store the sign.
+ */
+ n = (1ULL << (8 * isize)) - 1;
+ digits = 0;
+ while (n != 0) {
+ digits++;
+ n >>= (fchar == 'x') ? 4 : 3;
+ }
+ if (fchar == 'd')
+ digits++;
+ asprintf(&hdfmt, "%lu/%lu \"%*s%%%s%d%c\" \"\\n\"",
+ 16UL / (u_long)isize, (u_long)isize, (int)(4 * isize - digits),
+ "", (fchar == 'd' || fchar == 'u') ? "" : "0", digits, fchar);
+ if (hdfmt == NULL)
+ err(exit_jump, 1, NULL);
+ odadd(globals, hdfmt);
+ free(hdfmt);
+
+ return (fmt);
+}
+
+static void
+odadd(rtems_shell_hexdump_globals* globals, const char *fmt)
+{
+ static int needpad;
+
+ if (needpad)
+ add(globals, "\""PADDING"\"");
+ add(globals, fmt);
+ needpad = 1;
+}
diff --git a/cpukit/libmisc/shell/hexdump-parse.c b/cpukit/libmisc/shell/hexdump-parse.c
new file mode 100644
index 0000000000..1c35ba4649
--- /dev/null
+++ b/cpukit/libmisc/shell/hexdump-parse.c
@@ -0,0 +1,531 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/hexdump/parse.c,v 1.14 2006/08/09 19:12:10 maxim Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/types.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#define index(s,c) strchr(s,c)
+
+#include "hexdump.h"
+
+#if RTEMS_REMOVED
+FU *endfu; /* format at end-of-data */
+#endif
+
+void
+addfile(rtems_shell_hexdump_globals* globals, char *name)
+{
+ unsigned char *p;
+ FILE *fp;
+ int ch;
+ char buf[2048 + 1];
+
+ if ((fp = fopen(name, "r")) == NULL)
+ err(exit_jump, 1, "%s", name);
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (!(p = (unsigned char*)index(buf, '\n'))) {
+ warnx("line too long");
+ while ((ch = getchar()) != '\n' && ch != EOF);
+ continue;
+ }
+ *p = '\0';
+ for (p = (unsigned char*) buf; *p && isspace(*p); ++p);
+ if (!*p || *p == '#')
+ continue;
+ add(globals, (char*)p);
+ }
+ (void)fclose(fp);
+}
+
+void
+add(rtems_shell_hexdump_globals* globals, const char *fmt)
+{
+ unsigned const char *p, *savep;
+ static FS **nextfs;
+ FS *tfs;
+ FU *tfu, **nextfu;
+
+ /* start new linked list of format units */
+ if ((tfs = calloc(1, sizeof(FS))) == NULL)
+ err(exit_jump, 1, NULL);
+ if (!fshead)
+ fshead = tfs;
+ else
+ *nextfs = tfs;
+ nextfs = &tfs->nextfs;
+ nextfu = &tfs->nextfu;
+
+ /* take the format string and break it up into format units */
+ for (p = (unsigned const char*)fmt;;) {
+ /* skip leading white space */
+ for (; isspace(*p); ++p);
+ if (!*p)
+ break;
+
+ /* allocate a new format unit and link it in */
+ if ((tfu = calloc(1, sizeof(FU))) == NULL)
+ err(exit_jump, 1, NULL);
+ *nextfu = tfu;
+ nextfu = &tfu->nextfu;
+ tfu->reps = 1;
+
+ /* if leading digit, repetition count */
+ if (isdigit(*p)) {
+ for (savep = p; isdigit(*p); ++p);
+ if (!isspace(*p) && *p != '/')
+ badfmt(globals, fmt);
+ /* may overwrite either white space or slash */
+ tfu->reps = atoi((char*)savep);
+ tfu->flags = F_SETREP;
+ /* skip trailing white space */
+ for (++p; isspace(*p); ++p);
+ }
+
+ /* skip slash and trailing white space */
+ if (*p == '/')
+ while (isspace(*++p));
+
+ /* byte count */
+ if (isdigit(*p)) {
+ for (savep = p; isdigit(*p); ++p);
+ if (!isspace(*p))
+ badfmt(globals, fmt);
+ tfu->bcnt = atoi((char*)savep);
+ /* skip trailing white space */
+ for (++p; isspace(*p); ++p);
+ }
+
+ /* format */
+ if (*p != '"')
+ badfmt(globals, fmt);
+ for (savep = ++p; *p != '"';)
+ if (*p++ == 0)
+ badfmt(globals, fmt);
+ if (!(tfu->fmt = malloc(p - savep + 1)))
+ err(exit_jump, 1, NULL);
+ (void) strncpy(tfu->fmt, (char*)savep, p - savep);
+ tfu->fmt[p - savep] = '\0';
+ escape(tfu->fmt);
+ p++;
+ }
+}
+
+static const char *spec = ".#-+ 0123456789";
+
+int
+size(rtems_shell_hexdump_globals* globals, FS *fs)
+{
+ FU *fu;
+ int bcnt, cursize;
+ unsigned char *fmt;
+ int prec;
+
+ /* figure out the data block size needed for each format unit */
+ for (cursize = 0, fu = fs->nextfu; fu; fu = fu->nextfu) {
+ if (fu->bcnt) {
+ cursize += fu->bcnt * fu->reps;
+ continue;
+ }
+ for (bcnt = prec = 0, fmt = (unsigned char*) fu->fmt; *fmt; ++fmt) {
+ if (*fmt != '%')
+ continue;
+ /*
+ * skip any special chars -- save precision in
+ * case it's a %s format.
+ */
+ while (index(spec + 1, *++fmt));
+ if (*fmt == '.' && isdigit(*++fmt)) {
+ prec = atoi((char*)fmt);
+ while (isdigit(*++fmt));
+ }
+ switch(*fmt) {
+ case 'c':
+ bcnt += 1;
+ break;
+ case 'd': case 'i': case 'o': case 'u':
+ case 'x': case 'X':
+ bcnt += 4;
+ break;
+ case 'e': case 'E': case 'f': case 'g': case 'G':
+ bcnt += 8;
+ break;
+ case 's':
+ bcnt += prec;
+ break;
+ case '_':
+ switch(*++fmt) {
+ case 'c': case 'p': case 'u':
+ bcnt += 1;
+ break;
+ }
+ }
+ }
+ cursize += bcnt * fu->reps;
+ }
+ return (cursize);
+}
+
+void
+rewrite(rtems_shell_hexdump_globals* globals, FS *fs)
+{
+ enum { NOTOKAY, USEBCNT, USEPREC } sokay;
+ PR *pr, **nextpr;
+ FU *fu;
+ unsigned char *p1, *p2, *fmtp;
+ char savech, cs[3];
+ int nconv, prec;
+ size_t len;
+
+ pr = NULL;
+ nextpr = NULL;
+ prec = 0;
+
+ for (fu = fs->nextfu; fu; fu = fu->nextfu) {
+ /*
+ * Break each format unit into print units; each conversion
+ * character gets its own.
+ */
+ for (nconv = 0, fmtp = (unsigned char*)fu->fmt; *fmtp; nextpr = &pr->nextpr) {
+ if ((pr = calloc(1, sizeof(PR))) == NULL)
+ err(exit_jump, 1, NULL);
+ if (!fu->nextpr)
+ fu->nextpr = pr;
+ else {
+ if (nextpr)
+ *nextpr = pr;
+ }
+
+ /* Skip preceding text and up to the next % sign. */
+ for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
+
+ /* Only text in the string. */
+ if (!*p1) {
+ pr->fmt = (char*)fmtp;
+ pr->flags = F_TEXT;
+ break;
+ }
+
+ /*
+ * Get precision for %s -- if have a byte count, don't
+ * need it.
+ */
+ if (fu->bcnt) {
+ sokay = USEBCNT;
+ /* Skip to conversion character. */
+ for (++p1; index(spec, *p1); ++p1);
+ } else {
+ /* Skip any special chars, field width. */
+ while (index(spec + 1, *++p1));
+ if (*p1 == '.' && isdigit(*++p1)) {
+ sokay = USEPREC;
+ prec = atoi((char*)p1);
+ while (isdigit(*++p1));
+ } else
+ sokay = NOTOKAY;
+ }
+
+ p2 = p1 + 1; /* Set end pointer. */
+ cs[0] = *p1; /* Set conversion string. */
+ cs[1] = '\0';
+
+ /*
+ * Figure out the byte count for each conversion;
+ * rewrite the format as necessary, set up blank-
+ * padding for end of data.
+ */
+ switch(cs[0]) {
+ case 'c':
+ pr->flags = F_CHAR;
+ switch(fu->bcnt) {
+ case 0: case 1:
+ pr->bcnt = 1;
+ break;
+ default:
+ p1[1] = '\0';
+ badcnt(globals, (char*)p1);
+ }
+ break;
+ case 'd': case 'i':
+ pr->flags = F_INT;
+ goto isint;
+ case 'o': case 'u': case 'x': case 'X':
+ pr->flags = F_UINT;
+isint: cs[2] = '\0';
+ cs[1] = cs[0];
+ cs[0] = 'q';
+ switch(fu->bcnt) {
+ case 0: case 4:
+ pr->bcnt = 4;
+ break;
+ case 1:
+ pr->bcnt = 1;
+ break;
+ case 2:
+ pr->bcnt = 2;
+ break;
+ default:
+ p1[1] = '\0';
+ badcnt(globals, (char*)p1);
+ }
+ break;
+ case 'e': case 'E': case 'f': case 'g': case 'G':
+ pr->flags = F_DBL;
+ switch(fu->bcnt) {
+ case 0: case 8:
+ pr->bcnt = 8;
+ break;
+ case 4:
+ pr->bcnt = 4;
+ break;
+ default:
+ if (fu->bcnt == sizeof(long double)) {
+ cs[2] = '\0';
+ cs[1] = cs[0];
+ cs[0] = 'L';
+ pr->bcnt = sizeof(long double);
+ } else {
+ p1[1] = '\0';
+ badcnt(globals, (char*)p1);
+ }
+ }
+ break;
+ case 's':
+ pr->flags = F_STR;
+ switch(sokay) {
+ case NOTOKAY:
+ badsfmt(globals);
+ case USEBCNT:
+ pr->bcnt = fu->bcnt;
+ break;
+ case USEPREC:
+ pr->bcnt = prec;
+ break;
+ }
+ break;
+ case '_':
+ ++p2;
+ switch(p1[1]) {
+ case 'A':
+ endfu = fu;
+ fu->flags |= F_IGNORE;
+ /* FALLTHROUGH */
+ case 'a':
+ pr->flags = F_ADDRESS;
+ ++p2;
+ switch(p1[2]) {
+ case 'd': case 'o': case'x':
+ cs[0] = 'q';
+ cs[1] = p1[2];
+ cs[2] = '\0';
+ break;
+ default:
+ p1[3] = '\0';
+ badconv(globals, (char*)p1);
+ }
+ break;
+ case 'c':
+ pr->flags = F_C;
+ /* cs[0] = 'c'; set in conv_c */
+ goto isint2;
+ case 'p':
+ pr->flags = F_P;
+ cs[0] = 'c';
+ goto isint2;
+ case 'u':
+ pr->flags = F_U;
+ /* cs[0] = 'c'; set in conv_u */
+isint2: switch(fu->bcnt) {
+ case 0: case 1:
+ pr->bcnt = 1;
+ break;
+ default:
+ p1[2] = '\0';
+ badcnt(globals, (char*)p1);
+ }
+ break;
+ default:
+ p1[2] = '\0';
+ badconv(globals, (char*)p1);
+ }
+ break;
+ default:
+ p1[1] = '\0';
+ badconv(globals, (char*)p1);
+ }
+
+ /*
+ * Copy to PR format string, set conversion character
+ * pointer, update original.
+ */
+ savech = *p2;
+ p1[0] = '\0';
+ len = strlen((char*)fmtp) + strlen(cs) + 1;
+ if ((pr->fmt = calloc(1, len)) == NULL)
+ err(exit_jump, 1, NULL);
+ snprintf(pr->fmt, len, "%s%s", fmtp, cs);
+ *p2 = savech;
+ pr->cchar = pr->fmt + (p1 - fmtp);
+ fmtp = p2;
+
+ /* Only one conversion character if byte count. */
+ if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)
+ errx(exit_jump, 1, "byte count with multiple conversion characters");
+ }
+ /*
+ * If format unit byte count not specified, figure it out
+ * so can adjust rep count later.
+ */
+ if (!fu->bcnt)
+ for (pr = fu->nextpr; pr; pr = pr->nextpr)
+ fu->bcnt += pr->bcnt;
+ }
+ if (pr) {
+ free(pr);
+ pr = NULL;
+ }
+ /*
+ * If the format string interprets any data at all, and it's
+ * not the same as the blocksize, and its last format unit
+ * interprets any data at all, and has no iteration count,
+ * repeat it as necessary.
+ *
+ * If, rep count is greater than 1, no trailing whitespace
+ * gets output from the last iteration of the format unit.
+ */
+ for (fu = fs->nextfu; fu; fu = fu->nextfu) {
+ if (!fu->nextfu && fs->bcnt < blocksize &&
+ !(fu->flags&F_SETREP) && fu->bcnt)
+ fu->reps += (blocksize - fs->bcnt) / fu->bcnt;
+ if (fu->reps > 1) {
+ for (pr = fu->nextpr;; pr = pr->nextpr)
+ if (!pr->nextpr)
+ break;
+ for (p1 = (unsigned char*)pr->fmt, p2 = NULL; *p1; ++p1)
+ p2 = isspace(*p1) ? p1 : NULL;
+ if (p2)
+ pr->nospace = (char*)p2;
+ }
+ }
+#ifdef DEBUG
+ for (fu = fs->nextfu; fu; fu = fu->nextfu) {
+ (void)printf("fmt:");
+ for (pr = fu->nextpr; pr; pr = pr->nextpr)
+ (void)printf(" {%s}", pr->fmt);
+ (void)printf("\n");
+ }
+#endif
+}
+
+void
+escape(char *p1)
+{
+ char *p2;
+
+ /* alphabetic escape sequences have to be done in place */
+ for (p2 = p1;; ++p1, ++p2) {
+ if (!*p1) {
+ *p2 = *p1;
+ break;
+ }
+ if (*p1 == '\\')
+ switch(*++p1) {
+ case 'a':
+ /* *p2 = '\a'; */
+ *p2 = '\007';
+ break;
+ case 'b':
+ *p2 = '\b';
+ break;
+ case 'f':
+ *p2 = '\f';
+ break;
+ case 'n':
+ *p2 = '\n';
+ break;
+ case 'r':
+ *p2 = '\r';
+ break;
+ case 't':
+ *p2 = '\t';
+ break;
+ case 'v':
+ *p2 = '\v';
+ break;
+ default:
+ *p2 = *p1;
+ break;
+ }
+ }
+}
+
+void
+badcnt(rtems_shell_hexdump_globals* globals, char *s)
+{
+ errx(exit_jump, 1, "%s: bad byte count", s);
+}
+
+void
+badsfmt(rtems_shell_hexdump_globals* globals)
+{
+ errx(exit_jump, 1, "%%s: requires a precision or a byte count");
+}
+
+void
+badfmt(rtems_shell_hexdump_globals* globals, const char *fmt)
+{
+ errx(exit_jump, 1, "\"%s\": bad format", fmt);
+}
+
+void
+badconv(rtems_shell_hexdump_globals* globals, char *ch)
+{
+ errx(exit_jump, 1, "%%%s: bad conversion character", ch);
+}
diff --git a/cpukit/libmisc/shell/hexdump.h b/cpukit/libmisc/shell/hexdump.h
new file mode 100644
index 0000000000..5b0e61b966
--- /dev/null
+++ b/cpukit/libmisc/shell/hexdump.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)hexdump.h 8.1 (Berkeley) 6/6/93
+ * $FreeBSD: src/usr.bin/hexdump/hexdump.h,v 1.9 2004/07/11 01:11:12 tjr Exp $
+ */
+
+#include <wchar.h>
+
+typedef struct _pr {
+ struct _pr *nextpr; /* next print unit */
+#define F_ADDRESS 0x001 /* print offset */
+#define F_BPAD 0x002 /* blank pad */
+#define F_C 0x004 /* %_c */
+#define F_CHAR 0x008 /* %c */
+#define F_DBL 0x010 /* %[EefGf] */
+#define F_INT 0x020 /* %[di] */
+#define F_P 0x040 /* %_p */
+#define F_STR 0x080 /* %s */
+#define F_U 0x100 /* %_u */
+#define F_UINT 0x200 /* %[ouXx] */
+#define F_TEXT 0x400 /* no conversions */
+ u_int flags; /* flag values */
+ int bcnt; /* byte count */
+ char *cchar; /* conversion character */
+ char *fmt; /* printf format */
+ char *nospace; /* no whitespace version */
+ int mbleft; /* bytes left of multibyte char. */
+ mbstate_t mbstate; /* conversion state */
+} PR;
+
+typedef struct _fu {
+ struct _fu *nextfu; /* next format unit */
+ struct _pr *nextpr; /* next print unit */
+#define F_IGNORE 0x01 /* %_A */
+#define F_SETREP 0x02 /* rep count set, not default */
+ u_int flags; /* flag values */
+ int reps; /* repetition count */
+ int bcnt; /* byte count */
+ char *fmt; /* format string */
+} FU;
+
+typedef struct _fs { /* format strings */
+ struct _fs *nextfs; /* linked list of format strings */
+ struct _fu *nextfu; /* linked list of format units */
+ int bcnt;
+} FS;
+
+#if 0
+extern FS *fshead; /* head of format strings list */
+extern FU *endfu; /* format at end-of-data */
+extern int blocksize; /* data block size */
+extern int exitval; /* final exit value */
+extern int odmode; /* are we acting as od(1)? */
+extern int length; /* amount of data to read */
+extern off_t skip; /* amount of data to skip at start */
+enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */
+extern enum _vflag vflag;
+#endif
+
+#include <setjmp.h>
+#include <stdio.h>
+
+enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */
+typedef struct rtems_shell_hexdump_globals_t {
+ FS *fshead; /* head of format strings list */
+ FU *endfu; /* format at end-of-data */
+ int blocksize; /* data block size */
+ int exitval; /* final exit value */
+ int odmode; /* are we acting as od(1)? */
+ int length; /* amount of data to read */
+ off_t skip; /* amount of data to skip at start */
+ enum _vflag vflag;
+
+ off_t address;
+ off_t eaddress;
+ int ateof;
+ u_char *curp;
+ u_char *savp;
+ int done;
+
+ FILE* hdstdin;
+
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_hexdump_globals;
+
+#define fshead globals->fshead
+#define endfu globals->endfu
+#define blocksize globals->blocksize
+#define exitval globals->exitval
+#define odmode globals->odmode
+#define length globals->length
+#define skip globals->skip
+#define vflag globals->vflag
+
+#define address globals->address
+#define eaddress globals->eaddress
+#define ateof globals->ateof
+#define curp globals->curp
+#define savp globals->savp
+#define done globals->done
+
+#define hdstdin globals->hdstdin
+
+#define exit_jump &(globals->exit_jmp)
+
+#define add rtems_shell_hexdump_add
+#define addfile rtems_shell_hexdump_addfile
+#define badcnt rtems_shell_hexdump_badcnt
+#define badconv rtems_shell_hexdump_badconv
+#define badfmt rtems_shell_hexdump_badfmt
+#define badsfmt rtems_shell_hexdump_badsfmt
+#define bpad rtems_shell_hexdump_bpad
+#define conv_c rtems_shell_hexdump_conv_c
+#define conv_u rtems_shell_hexdump_conv_u
+#define display rtems_shell_hexdump_display
+#define doskip rtems_shell_hexdump_doskip
+#define escape rtems_shell_hexdump_escape
+#define get rtems_shell_hexdump_get
+#define newsyntax rtems_shell_hexdump_newsyntax
+#define next rtems_shell_hexdump_next
+#define nomem rtems_shell_hexdump_nomem
+#define oldsyntax rtems_shell_hexdump_oldsyntax
+#define peek rtems_shell_hexdump_peek
+#define rewrite rtems_shell_hexdump_rewrite
+#define size rtems_shell_hexdump_size
+#define usage rtems_shell_hexdump_usage
+
+void add(rtems_shell_hexdump_globals*, const char *);
+void addfile(rtems_shell_hexdump_globals*, char *);
+void badcnt(rtems_shell_hexdump_globals*, char *);
+void badconv(rtems_shell_hexdump_globals*, char *);
+void badfmt(rtems_shell_hexdump_globals*, const char *);
+void badsfmt(rtems_shell_hexdump_globals*);
+void bpad(PR *);
+void conv_c(rtems_shell_hexdump_globals*, PR *, u_char *, size_t);
+void conv_u(rtems_shell_hexdump_globals*, PR *, u_char *);
+void display(rtems_shell_hexdump_globals*);
+void doskip(rtems_shell_hexdump_globals*, const char *, int);
+void escape(char *);
+u_char *get(rtems_shell_hexdump_globals*);
+void newsyntax(rtems_shell_hexdump_globals*, int, char ***);
+int next(rtems_shell_hexdump_globals*, char **);
+void nomem(void);
+void oldsyntax(rtems_shell_hexdump_globals*, int, char ***);
+size_t peek(rtems_shell_hexdump_globals*, u_char *, size_t);
+void rewrite(rtems_shell_hexdump_globals*, FS *);
+int size(rtems_shell_hexdump_globals*, FS *);
+void usage(rtems_shell_hexdump_globals*);
+
+#define exit(ec) rtems_shell_hexdump_exit(globals, ec)
+
+void rtems_shell_hexdump_exit(rtems_shell_hexdump_globals* globals, int code);
diff --git a/cpukit/libmisc/shell/hexsyntax.c b/cpukit/libmisc/shell/hexsyntax.c
new file mode 100644
index 0000000000..0f80738172
--- /dev/null
+++ b/cpukit/libmisc/shell/hexsyntax.c
@@ -0,0 +1,158 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/hexdump/hexsyntax.c,v 1.12 2002/09/04 23:29:01 dwmalone Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/types.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define rindex(s,c) strrchr(s,c)
+
+#include "hexdump.h"
+
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#if RTEMS_REMOVED
+off_t skip; /* bytes to skip */
+#endif
+
+void
+newsyntax(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
+{
+ int ch;
+ char *p, **argv;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+ argv = *argvp;
+ if ((p = rindex(argv[0], 'h')) != NULL &&
+ strcmp(p, "hd") == 0) {
+ /* "Canonical" format, implies -C. */
+ add(globals, "\"%08.8_Ax\n\"");
+ add(globals, "\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
+ add(globals, "\" |\" 16/1 \"%_p\" \"|\\n\"");
+ }
+ while ((ch = getopt_r(argc, argv, "bcCde:f:n:os:vx", &getopt_reent)) != -1)
+ switch (ch) {
+ case 'b':
+ add(globals, "\"%07.7_Ax\n\"");
+ add(globals, "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
+ break;
+ case 'c':
+ add(globals, "\"%07.7_Ax\n\"");
+ add(globals, "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
+ break;
+ case 'C':
+ add(globals, "\"%08.8_Ax\n\"");
+ add(globals, "\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
+ add(globals, "\" |\" 16/1 \"%_p\" \"|\\n\"");
+ break;
+ case 'd':
+ add(globals, "\"%07.7_Ax\n\"");
+ add(globals, "\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
+ break;
+ case 'e':
+ add(globals, getopt_reent.optarg);
+ break;
+ case 'f':
+ addfile(globals, getopt_reent.optarg);
+ break;
+ case 'n':
+ if ((length = atoi(getopt_reent.optarg)) < 0)
+ errx(exit_jump, 1, "%s: bad length value", getopt_reent.optarg);
+ break;
+ case 'o':
+ add(globals, "\"%07.7_Ax\n\"");
+ add(globals, "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
+ break;
+ case 's':
+ if ((skip = strtoll(getopt_reent.optarg, &p, 0)) < 0)
+ errx(exit_jump, 1, "%s: bad skip value", getopt_reent.optarg);
+ switch(*p) {
+ case 'b':
+ skip *= 512;
+ break;
+ case 'k':
+ skip *= 1024;
+ break;
+ case 'm':
+ skip *= 1048576;
+ break;
+ }
+ break;
+ case 'v':
+ vflag = ALL;
+ break;
+ case 'x':
+ add(globals, "\"%07.7_Ax\n\"");
+ add(globals, "\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
+ break;
+ case '?':
+ usage(globals);
+ }
+
+ if (!fshead) {
+ add(globals, "\"%07.7_Ax\n\"");
+ add(globals, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
+ }
+
+ *argvp += getopt_reent.optind;
+}
+
+void
+usage(rtems_shell_hexdump_globals* globals)
+{
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
+"usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]",
+" [-s skip] [file ...]",
+" hd [-bcdovx] [-e fmt] [-f fmt_file] [-n length]",
+" [-s skip] [file ...]");
+ exit(1);
+}
diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
new file mode 100644
index 0000000000..aadd346092
--- /dev/null
+++ b/cpukit/libmisc/shell/internal.h
@@ -0,0 +1,37 @@
+/*
+ * Shell Internal Information
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SHELL_INTERNAL_H
+#define _RTEMS_SHELL_INTERNAL_H
+
+struct rtems_shell_topic_tt;
+typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
+
+struct rtems_shell_topic_tt {
+ const char *topic;
+ rtems_shell_topic_t *next;
+};
+
+
+extern rtems_shell_cmd_t * rtems_shell_first_cmd;
+extern rtems_shell_topic_t * rtems_shell_first_topic;
+
+rtems_shell_topic_t * rtems_shell_lookup_topic(const char *topic);
+
+
+void rtems_shell_register_monitor_commands(void);
+void rtems_shell_initialize_command_set(void);
+
+void rtems_shell_print_heap_info(
+ const char *c,
+ Heap_Information *h
+);
+
+#endif
diff --git a/cpukit/libmisc/shell/login_check.c b/cpukit/libmisc/shell/login_check.c
new file mode 100644
index 0000000000..d744ee5954
--- /dev/null
+++ b/cpukit/libmisc/shell/login_check.c
@@ -0,0 +1,62 @@
+/**
+ * @file
+ *
+ * @brief Shell login check function.
+ */
+
+/*
+ * Copyright (c) 2009 embedded brains GmbH and others.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * Based on work from Chris Johns and Fernando Ruiz.
+ *
+ * Derived from file "cpukit/libmisc/shell/shell.c".
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <pwd.h>
+
+#include <rtems/shell.h>
+#include <rtems/userenv.h>
+
+bool rtems_shell_login_check(
+ const char *user,
+ const char *passphrase
+)
+{
+ struct passwd *pw = getpwnam( user);
+
+ /* Valid user? */
+ if (pw != NULL && strcmp( pw->pw_passwd, "!") != 0) {
+ setuid( pw->pw_uid);
+ setgid( pw->pw_gid);
+ rtems_current_user_env->euid = 0;
+ rtems_current_user_env->egid = 0;
+ chown( rtems_current_shell_env->devname, pw->pw_uid, 0);
+ rtems_current_user_env->euid = pw->pw_uid;
+ rtems_current_user_env->egid = pw->pw_gid;
+ if (strcmp( pw->pw_passwd, "*") == 0) {
+ /* TODO: /etc/shadow */
+ return true;
+ } else {
+ /* TODO: crypt() */
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/cpukit/libmisc/shell/login_prompt.c b/cpukit/libmisc/shell/login_prompt.c
new file mode 100644
index 0000000000..7e93078805
--- /dev/null
+++ b/cpukit/libmisc/shell/login_prompt.c
@@ -0,0 +1,209 @@
+/**
+ * @file
+ *
+ * @brief Shell login prompt functions.
+ */
+
+/*
+ * Authorship
+ * ----------
+ * Parts of this software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2003-2007
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * Parts of this software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ *
+ * Copyright (c) 2009 embedded brains GmbH and others.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * Based on work from Chris Johns, Fernando Ruiz and Till Straumann.
+ *
+ * Derived from files "cpukit/libmisc/shell/shell.c" and
+ * "cpukit/telnetd/check_passwd.c".
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include <rtems/shell.h>
+
+static int rtems_shell_discard( int c, FILE *stream)
+{
+ return c;
+}
+
+static bool rtems_shell_get_text(
+ FILE *in,
+ FILE *out,
+ char *line,
+ size_t size
+)
+{
+ int fd_in = fileno( in);
+ int (*put)( int, FILE *) =
+ out != NULL && isatty( fd_in)
+ ? fputc
+ : rtems_shell_discard;
+ size_t i = 0;
+
+ if (size < 1) {
+ return false;
+ }
+
+ tcdrain( fd_in);
+ if (out != NULL){
+ tcdrain( fileno(out) );
+ }
+
+ while (true) {
+ int c = fgetc(in);
+
+ switch (c) {
+ case EOF:
+ clearerr( in );
+ return false;
+ case '\n':
+ case '\r':
+ put('\n', out);
+ line [i] = '\0';
+ return true;
+ case 127:
+ case '\b':
+ if (i > 0) {
+ put('\b', out);
+ put(' ', out);
+ put('\b', out);
+ --i;
+ } else {
+ put('\a', out);
+ }
+ break;
+ default:
+ if (!iscntrl( c)) {
+ if (i < size - 1) {
+ line [i] = (char) c;
+ ++i;
+ put( c, out);
+ } else {
+ put('\a', out);
+ }
+ } else {
+ put('\a', out);
+ }
+ break;
+ }
+ }
+ return true;
+}
+
+bool rtems_shell_login_prompt(
+ FILE *in,
+ FILE *out,
+ const char *device,
+ rtems_shell_login_check_t check
+)
+{
+ int fd_in = fileno(in);
+ struct termios termios_previous;
+ bool restore_termios = false;
+ int i = 0;
+ bool result = false;
+
+ if (tcgetattr( fd_in, &termios_previous) == 0) {
+ struct termios termios_new = termios_previous;
+
+ /*
+ * Stay in canonical mode so we can tell EOF and dropped connections.
+ * But read one character at a time and do not echo it.
+ */
+ termios_new.c_lflag &= (unsigned char) ~ECHO;
+ termios_new.c_cc [VTIME] = 0;
+ termios_new.c_cc [VMIN] = 1;
+
+ restore_termios = tcsetattr( fd_in, TCSANOW, &termios_new) == 0;
+ }
+
+ for (i = 0; i < 3; ++i) {
+ char user [32];
+ char passphrase [128];
+
+ fprintf( out, "%s login: ", device );
+ fflush( out );
+ result = rtems_shell_get_text( in, out, user, sizeof(user) );
+ if ( !result )
+ break;
+
+ fflush( in);
+ fprintf( out, "Password: ");
+ fflush( out);
+ result = rtems_shell_get_text( in, NULL, passphrase, sizeof(passphrase) );
+ if ( !result )
+ break;
+ fputc( '\n', out);
+
+ result = check( user, passphrase );
+ if (result)
+ break;
+
+ fprintf( out, "Login incorrect\n\n");
+ sleep( 2);
+ }
+
+ if (restore_termios) {
+ /* What to do if restoring the flags fails? */
+ tcsetattr( fd_in, TCSANOW, &termios_previous);
+ }
+
+ return result;
+}
diff --git a/cpukit/libmisc/shell/main_alias.c b/cpukit/libmisc/shell/main_alias.c
new file mode 100644
index 0000000000..9f1b094eaa
--- /dev/null
+++ b/cpukit/libmisc/shell/main_alias.c
@@ -0,0 +1,45 @@
+/*
+ * ALIAS Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_rtems_main_alias(int argc, char **argv)
+{
+ if (argc<3) {
+ fprintf(stderr,"too few arguments\n");
+ return 1;
+ }
+
+ if (!rtems_shell_alias_cmd(argv[1],argv[2])) {
+ fprintf(stderr,"unable to make an alias(%s,%s)\n",argv[1],argv[2]);
+ }
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_ALIAS_Command = {
+ "alias", /* name */
+ "alias old new", /* usage */
+ "misc", /* topic */
+ rtems_shell_rtems_main_alias, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_blksync.c b/cpukit/libmisc/shell/main_blksync.c
new file mode 100644
index 0000000000..bf8369570e
--- /dev/null
+++ b/cpukit/libmisc/shell/main_blksync.c
@@ -0,0 +1,77 @@
+/*
+ * RM Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/bdbuf.h>
+#include <rtems/blkdev.h>
+#include "internal.h"
+
+int rtems_shell_main_blksync(
+ int argc,
+ char *argv[]
+)
+{
+ const char* driver = NULL;
+ int arg;
+ int fd;
+
+ for (arg = 1; arg < argc; arg++) {
+ if (argv[arg][0] == '-') {
+ fprintf( stderr, "%s: invalid option: %s\n", argv[0], argv[arg]);
+ return 1;
+ } else {
+ if (!driver)
+ driver = argv[arg];
+ else {
+ fprintf( stderr, "%s: only one driver name allowed: %s\n",
+ argv[0], argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+ fd = open (driver, O_WRONLY, 0);
+ if (fd < 0) {
+ fprintf( stderr, "%s: driver open failed: %s\n", argv[0], strerror (errno));
+ return 1;
+ }
+
+ if (ioctl (fd, RTEMS_BLKIO_SYNCDEV) < 0) {
+ fprintf( stderr, "%s: driver sync failed: %s\n", argv[0], strerror (errno));
+ return 1;
+ }
+
+ close (fd);
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_BLKSYNC_Command = {
+ "blksync", /* name */
+ "blksync driver # sync the block driver", /* usage */
+ "files", /* topic */
+ rtems_shell_main_blksync, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_cat.c b/cpukit/libmisc/shell/main_cat.c
new file mode 100644
index 0000000000..6efd7a09c8
--- /dev/null
+++ b/cpukit/libmisc/shell/main_cat.c
@@ -0,0 +1,60 @@
+/*
+ * CAT Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <termios.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stddef.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_cat(int argc, char *argv[])
+{
+ int n;
+ int sc;
+
+ for ( n=1; n < argc ; n++) {
+ sc = rtems_shell_cat_file(stdout, argv[n]);
+ if ( sc == -1 ) {
+ fprintf(stderr, "%s: %s: %s\n", argv[0], argv[n], strerror(errno));
+ return -1;
+ }
+ }
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_CAT_Command = {
+ "cat", /* name */
+ "cat n1 [n2 [n3...]] # show the ascii contents", /* usage */
+ "files", /* topic */
+ rtems_shell_main_cat , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_cd.c b/cpukit/libmisc/shell/main_cd.c
new file mode 100644
index 0000000000..e3ed35fa63
--- /dev/null
+++ b/cpukit/libmisc/shell/main_cd.c
@@ -0,0 +1,26 @@
+/*
+ * CD Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+rtems_shell_alias_t rtems_shell_CD_Alias = {
+ "chdir", /* command */
+ "cd" /* alias */
+};
diff --git a/cpukit/libmisc/shell/main_chdir.c b/cpukit/libmisc/shell/main_chdir.c
new file mode 100644
index 0000000000..2273f5c956
--- /dev/null
+++ b/cpukit/libmisc/shell/main_chdir.c
@@ -0,0 +1,54 @@
+/*
+ * CHDIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_chdir(
+ int argc,
+ char *argv[]
+)
+{
+ char *dir;
+
+ dir = "/";
+
+ if (argc > 1)
+ dir = argv[1];
+
+ if (chdir(dir)) {
+ fprintf(stderr, "chdir to '%s' failed:%s\n", dir,strerror(errno));
+ return errno;
+ }
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_CHDIR_Command = {
+ "chdir", /* name */
+ "chdir [dir] # change the current directory", /* usage */
+ "files", /* topic */
+ rtems_shell_main_chdir, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_chmod.c b/cpukit/libmisc/shell/main_chmod.c
new file mode 100644
index 0000000000..3c6ae68310
--- /dev/null
+++ b/cpukit/libmisc/shell/main_chmod.c
@@ -0,0 +1,70 @@
+/*
+ * CHMOD Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+int rtems_shell_main_chmod(
+ int argc,
+ char *argv[]
+)
+{
+ int n;
+ mode_t mode;
+ unsigned long tmp;
+
+ if (argc < 2) {
+ fprintf(stderr,"%s: too few arguments\n", argv[0]);
+ return -1;
+ }
+
+ /*
+ * Convert arguments into numbers
+ */
+ if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
+ printf( "Mode argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ mode = (mode_t) (tmp & 0777);
+
+ /*
+ * Now change the files modes
+ */
+ for (n=2 ; n < argc ; n++)
+ chmod(argv[n++], mode);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_CHMOD_Command = {
+ "chmod", /* name */
+ "chmod 0777 n1 n2... # change filemode", /* usage */
+ "files", /* topic */
+ rtems_shell_main_chmod, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_chroot.c b/cpukit/libmisc/shell/main_chroot.c
new file mode 100644
index 0000000000..ffdfb9ca3b
--- /dev/null
+++ b/cpukit/libmisc/shell/main_chroot.c
@@ -0,0 +1,53 @@
+/*
+ * CHROOT Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_chroot(
+ int argc,
+ char * argv[]
+)
+{
+ char *new_root = "/";
+
+ if (argc == 2)
+ new_root = argv[1];
+
+ if ( chroot(new_root) < 0 ) {
+ fprintf(stderr,"chroot %s (%s)\n", new_root, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_CHROOT_Command = {
+ "chroot", /* name */
+ "chroot [dir] # change the root directory", /* usage */
+ "files", /* topic */
+ rtems_shell_main_chroot, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_cp.c b/cpukit/libmisc/shell/main_cp.c
new file mode 100644
index 0000000000..5b56235abd
--- /dev/null
+++ b/cpukit/libmisc/shell/main_cp.c
@@ -0,0 +1,555 @@
+/* $NetBSD: cp.c,v 1.39 2005/10/24 12:59:07 kleink Exp $ */
+
+/*
+ * Copyright (c) 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * David Hitz of Auspex Systems Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#ifndef lint
+__COPYRIGHT(
+"@(#) Copyright (c) 1988, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
+#else
+__RCSID("$NetBSD: cp.c,v 1.39 2005/10/24 12:59:07 kleink Exp $");
+#endif
+#endif /* not lint */
+#endif
+/*
+ * Cp copies source files to target files.
+ *
+ * The global PATH_T structure "to" always contains the path to the
+ * current target file. Since fts(3) does not change directories,
+ * this path can be either absolute or dot-relative.
+ *
+ * The basic algorithm is to initialize "to" and use fts(3) to traverse
+ * the file hierarchy rooted in the argument list. A trivial case is the
+ * case of 'cp file1 file2'. The more interesting case is the case of
+ * 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
+ * path (relative to the root of the traversal) is appended to dir (stored
+ * in "to") to form the final target path.
+ */
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fts.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "extern-cp.h"
+
+#define S_ISTXT 0
+
+#define STRIP_TRAILING_SLASH(p) { \
+ while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
+ *--(p).p_end = 0; \
+}
+
+enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
+
+static int Rflag, rflag;
+
+static int main_cp(rtems_shell_cp_globals* cp_globals, int, char *[]);
+static int copy(rtems_shell_cp_globals* cp_globals, char *[], enum op, int);
+static int mastercmp(const FTSENT **, const FTSENT **);
+
+void
+rtems_shell_cp_exit (rtems_shell_cp_globals* cp_global, int code __attribute__((unused)))
+{
+ longjmp (cp_global->exit_jmp, 1);
+}
+
+int
+rtems_shell_main_cp(int argc, char *argv[])
+{
+ rtems_shell_cp_globals cp_globals;
+ memset (&cp_globals, 0, sizeof (cp_globals));
+ Rflag = rflag = 0;
+ if (setjmp (cp_globals.exit_jmp) == 0)
+ return main_cp (&cp_globals, argc, argv);
+ return 1;
+}
+
+int
+main_cp(rtems_shell_cp_globals* cp_globals, int argc, char *argv[])
+{
+ struct stat to_stat, tmp_stat;
+ enum op type;
+ int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
+ char *target;
+ struct getopt_data getopt_reent;
+
+ Hflag = Lflag = Pflag = 0;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+ while ((ch = getopt_r(argc, argv, "HLPRafilnprv", &getopt_reent)) != -1)
+ switch (ch) {
+ case 'H':
+ Hflag = 1;
+ Lflag = Pflag = 0;
+ break;
+ case 'L':
+ Lflag = 1;
+ Hflag = Pflag = 0;
+ break;
+ case 'P':
+ Pflag = 1;
+ Hflag = Lflag = 0;
+ break;
+ case 'R':
+ Rflag = 1;
+ break;
+ case 'a':
+ Pflag = 1;
+ pflag = 1;
+ Rflag = 1;
+ Hflag = Lflag = 0;
+ break;
+ case 'f':
+ fflag = 1;
+ iflag = nflag = 0;
+ break;
+ case 'i':
+ iflag = 1;
+ fflag = nflag = 0;
+ break;
+ case 'l':
+ lflag = 1;
+ break;
+ case 'n':
+ nflag = 1;
+ fflag = iflag = 0;
+ break;
+ case 'p':
+ pflag = 1;
+ break;
+ case 'r':
+ rflag = Lflag = 1;
+ Hflag = Pflag = 0;
+ break;
+ case 'v':
+ vflag = 1;
+ break;
+ default:
+ usage(cp_globals);
+ break;
+ }
+ argc -= getopt_reent.optind;
+ argv += getopt_reent.optind;
+
+ if (argc < 2)
+ usage(cp_globals);
+
+ fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
+ if (Rflag && rflag)
+ errx(exit_jump, 1, "the -R and -r options may not be specified together");
+ if (rflag)
+ Rflag = 1;
+ if (Rflag) {
+ if (Hflag)
+ fts_options |= FTS_COMFOLLOW;
+ if (Lflag) {
+ fts_options &= ~FTS_PHYSICAL;
+ fts_options |= FTS_LOGICAL;
+ }
+ } else {
+ fts_options &= ~FTS_PHYSICAL;
+ fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
+ }
+#if 0
+ (void)signal(SIGINFO, siginfo);
+#endif
+
+ /* Save the target base in "to". */
+ target = argv[--argc];
+ if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
+ errx(exit_jump, 1, "%s: name too long", target);
+ to.p_end = to.p_path + strlen(to.p_path);
+ if (to.p_path == to.p_end) {
+ *to.p_end++ = '.';
+ *to.p_end = 0;
+ }
+ have_trailing_slash = (to.p_end[-1] == '/');
+ if (have_trailing_slash)
+ STRIP_TRAILING_SLASH(to);
+ to.target_end = to.p_end;
+
+ /* Set end of argument list for fts(3). */
+ argv[argc] = NULL;
+
+ /*
+ * Cp has two distinct cases:
+ *
+ * cp [-R] source target
+ * cp [-R] source1 ... sourceN directory
+ *
+ * In both cases, source can be either a file or a directory.
+ *
+ * In (1), the target becomes a copy of the source. That is, if the
+ * source is a file, the target will be a file, and likewise for
+ * directories.
+ *
+ * In (2), the real target is not directory, but "directory/source".
+ */
+ r = stat(to.p_path, &to_stat);
+ if (r == -1 && errno != ENOENT)
+ err(exit_jump, 1, "%s", to.p_path);
+ if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
+ /*
+ * Case (1). Target is not a directory.
+ */
+ if (argc > 1)
+ errx(exit_jump, 1, "%s is not a directory", to.p_path);
+
+ /*
+ * Need to detect the case:
+ * cp -R dir foo
+ * Where dir is a directory and foo does not exist, where
+ * we want pathname concatenations turned on but not for
+ * the initial mkdir().
+ */
+ if (r == -1) {
+ if (Rflag && (Lflag || Hflag))
+ stat(*argv, &tmp_stat);
+ else
+ lstat(*argv, &tmp_stat);
+
+ if (S_ISDIR(tmp_stat.st_mode) && Rflag)
+ type = DIR_TO_DNE;
+ else
+ type = FILE_TO_FILE;
+ } else
+ type = FILE_TO_FILE;
+
+ if (have_trailing_slash && type == FILE_TO_FILE) {
+ if (r == -1)
+ errx(exit_jump, 1, "directory %s does not exist",
+ to.p_path);
+ else
+ errx(exit_jump, 1, "%s is not a directory", to.p_path);
+ }
+ } else
+ /*
+ * Case (2). Target is a directory.
+ */
+ type = FILE_TO_DIR;
+
+ return copy(cp_globals, argv, type, fts_options);
+}
+
+int
+copy(rtems_shell_cp_globals* cp_globals,
+ char *argv[], enum op type, int fts_options)
+{
+ struct stat to_stat;
+ FTS *ftsp;
+ FTSENT *curr;
+ int base = 0, dne, badcp, rval;
+ size_t nlen;
+ char *p, *target_mid;
+ mode_t mask, mode;
+
+ /*
+ * Keep an inverted copy of the umask, for use in correcting
+ * permissions on created directories when not using -p.
+ */
+ mask = ~umask(0777);
+ umask(~mask);
+
+ if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
+ err(exit_jump, 1, "fts_open");
+ for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) {
+ switch (curr->fts_info) {
+ case FTS_NS:
+ case FTS_DNR:
+ case FTS_ERR:
+ warnx("%s: %s",
+ curr->fts_path, strerror(curr->fts_errno));
+ badcp = rval = 1;
+ continue;
+ case FTS_DC: /* Warn, continue. */
+ warnx("%s: directory causes a cycle", curr->fts_path);
+ badcp = rval = 1;
+ continue;
+ default:
+ ;
+ }
+
+ /*
+ * If we are in case (2) or (3) above, we need to append the
+ * source name to the target name.
+ */
+ if (type != FILE_TO_FILE) {
+ /*
+ * Need to remember the roots of traversals to create
+ * correct pathnames. If there's a directory being
+ * copied to a non-existent directory, e.g.
+ * cp -R a/dir noexist
+ * the resulting path name should be noexist/foo, not
+ * noexist/dir/foo (where foo is a file in dir), which
+ * is the case where the target exists.
+ *
+ * Also, check for "..". This is for correct path
+ * concatenation for paths ending in "..", e.g.
+ * cp -R .. /tmp
+ * Paths ending in ".." are changed to ".". This is
+ * tricky, but seems the easiest way to fix the problem.
+ *
+ * XXX
+ * Since the first level MUST be FTS_ROOTLEVEL, base
+ * is always initialized.
+ */
+ if (curr->fts_level == FTS_ROOTLEVEL) {
+ if (type != DIR_TO_DNE) {
+ p = strrchr(curr->fts_path, '/');
+ base = (p == NULL) ? 0 :
+ (int)(p - curr->fts_path + 1);
+
+ if (!strcmp(&curr->fts_path[base],
+ ".."))
+ base += 1;
+ } else
+ base = curr->fts_pathlen;
+ }
+
+ p = &curr->fts_path[base];
+ nlen = curr->fts_pathlen - base;
+ target_mid = to.target_end;
+ if (*p != '/' && target_mid[-1] != '/')
+ *target_mid++ = '/';
+ *target_mid = 0;
+ if (target_mid - to.p_path + nlen >= PATH_MAX) {
+ warnx("%s%s: name too long (not copied)",
+ to.p_path, p);
+ badcp = rval = 1;
+ continue;
+ }
+ (void)strncat(target_mid, p, nlen);
+ to.p_end = target_mid + nlen;
+ *to.p_end = 0;
+ STRIP_TRAILING_SLASH(to);
+ }
+
+ if (curr->fts_info == FTS_DP) {
+ /*
+ * We are nearly finished with this directory. If we
+ * didn't actually copy it, or otherwise don't need to
+ * change its attributes, then we are done.
+ */
+ if (!curr->fts_number)
+ continue;
+ /*
+ * If -p is in effect, set all the attributes.
+ * Otherwise, set the correct permissions, limited
+ * by the umask. Optimise by avoiding a chmod()
+ * if possible (which is usually the case if we
+ * made the directory). Note that mkdir() does not
+ * honour setuid, setgid and sticky bits, but we
+ * normally want to preserve them on directories.
+ */
+ if (pflag) {
+ if (setfile(cp_globals, curr->fts_statp, -1))
+ rval = 1;
+ if (preserve_dir_acls(curr->fts_statp,
+ curr->fts_accpath, to.p_path) != 0)
+ rval = 1;
+ } else {
+ mode = curr->fts_statp->st_mode;
+ if ((mode & (S_ISUID | S_ISGID | S_ISTXT)) ||
+ ((mode | S_IRWXU) & mask) != (mode & mask))
+ if (chmod(to.p_path, mode & mask) != 0){
+ warn("chmod: %s", to.p_path);
+ rval = 1;
+ }
+ }
+ continue;
+ }
+
+ /* Not an error but need to remember it happened */
+ if (stat(to.p_path, &to_stat) == -1)
+ dne = 1;
+ else {
+ if (to_stat.st_dev == curr->fts_statp->st_dev &&
+ to_stat.st_ino == curr->fts_statp->st_ino) {
+ warnx("%s and %s are identical (not copied).",
+ to.p_path, curr->fts_path);
+ badcp = rval = 1;
+ if (S_ISDIR(curr->fts_statp->st_mode))
+ (void)fts_set(ftsp, curr, FTS_SKIP);
+ continue;
+ }
+ if (!S_ISDIR(curr->fts_statp->st_mode) &&
+ S_ISDIR(to_stat.st_mode)) {
+ warnx("cannot overwrite directory %s with "
+ "non-directory %s",
+ to.p_path, curr->fts_path);
+ badcp = rval = 1;
+ continue;
+ }
+ dne = 0;
+ }
+
+ switch (curr->fts_statp->st_mode & S_IFMT) {
+ case S_IFLNK:
+ /* Catch special case of a non-dangling symlink */
+ if ((fts_options & FTS_LOGICAL) ||
+ ((fts_options & FTS_COMFOLLOW) &&
+ curr->fts_level == 0)) {
+ if (copy_file(cp_globals, curr, dne))
+ badcp = rval = 1;
+ } else {
+ if (copy_link(cp_globals, curr, !dne))
+ badcp = rval = 1;
+ }
+ break;
+ case S_IFDIR:
+ if (!Rflag) {
+ warnx("%s is a directory (not copied).",
+ curr->fts_path);
+ (void)fts_set(ftsp, curr, FTS_SKIP);
+ badcp = rval = 1;
+ break;
+ }
+ /*
+ * If the directory doesn't exist, create the new
+ * one with the from file mode plus owner RWX bits,
+ * modified by the umask. Trade-off between being
+ * able to write the directory (if from directory is
+ * 555) and not causing a permissions race. If the
+ * umask blocks owner writes, we fail..
+ */
+ if (dne) {
+ if (mkdir(to.p_path,
+ curr->fts_statp->st_mode | S_IRWXU) < 0)
+ err(exit_jump, 1, "%s", to.p_path);
+ } else if (!S_ISDIR(to_stat.st_mode)) {
+ errno = ENOTDIR;
+ err(exit_jump, 1, "%s", to.p_path);
+ }
+ /*
+ * Arrange to correct directory attributes later
+ * (in the post-order phase) if this is a new
+ * directory, or if the -p flag is in effect.
+ */
+ curr->fts_number = pflag || dne;
+ break;
+ case S_IFBLK:
+ case S_IFCHR:
+ if (Rflag) {
+ if (copy_special(cp_globals, curr->fts_statp, !dne))
+ badcp = rval = 1;
+ } else {
+ if (copy_file(cp_globals, curr, dne))
+ badcp = rval = 1;
+ }
+ break;
+ case S_IFSOCK:
+ warnx("%s is a socket (not copied).",
+ curr->fts_path);
+ case S_IFIFO:
+ if (Rflag) {
+ if (copy_fifo(cp_globals, curr->fts_statp, !dne))
+ badcp = rval = 1;
+ } else {
+ if (copy_file(cp_globals, curr, dne))
+ badcp = rval = 1;
+ }
+ break;
+ default:
+ if (copy_file(cp_globals, curr, dne))
+ badcp = rval = 1;
+ break;
+ }
+ if (vflag && !badcp)
+ (void)printf("%s -> %s\n", curr->fts_path, to.p_path);
+ }
+ if (errno)
+ err(exit_jump, 1, "fts_read");
+ fts_close(ftsp);
+ return (rval);
+}
+
+/*
+ * mastercmp --
+ * The comparison function for the copy order. The order is to copy
+ * non-directory files before directory files. The reason for this
+ * is because files tend to be in the same cylinder group as their
+ * parent directory, whereas directories tend not to be. Copying the
+ * files first reduces seeking.
+ */
+int
+mastercmp(const FTSENT **a, const FTSENT **b)
+{
+ int a_info, b_info;
+
+ a_info = (*a)->fts_info;
+ if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR)
+ return (0);
+ b_info = (*b)->fts_info;
+ if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR)
+ return (0);
+ if (a_info == FTS_D)
+ return (-1);
+ if (b_info == FTS_D)
+ return (1);
+ return (0);
+}
+
+rtems_shell_cmd_t rtems_shell_CP_Command = {
+ "cp", /* name */
+ "cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target", /* usage */
+ "files", /* topic */
+ rtems_shell_main_cp, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
diff --git a/cpukit/libmisc/shell/main_cpuuse.c b/cpukit/libmisc/shell/main_cpuuse.c
new file mode 100644
index 0000000000..b2329934bd
--- /dev/null
+++ b/cpukit/libmisc/shell/main_cpuuse.c
@@ -0,0 +1,61 @@
+/*
+ * CPUUSE Command Implementation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/cpuuse.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_cpuuse(
+ int argc,
+ char *argv[]
+)
+{
+ /*
+ * When invoked with no arguments, print the report.
+ */
+ if ( argc == 1 ) {
+ rtems_cpu_usage_report_with_plugin(stdout, (rtems_printk_plugin_t)fprintf);
+ return 0;
+ }
+
+ /*
+ * When invoked with the single argument -r, reset the statistics.
+ */
+ if ( argc == 2 && !strcmp( argv[1], "-r" ) ) {
+ printf( "Resetting CPU Usage information\n" );
+ rtems_cpu_usage_reset();
+ return 0;
+ }
+
+ /*
+ * OK. The user did something wrong.
+ */
+ fprintf( stderr, "%s: [-r]\n", argv[0] );
+ return -1;
+}
+
+rtems_shell_cmd_t rtems_shell_CPUUSE_Command = {
+ "cpuuse", /* name */
+ "[-r] print or reset per thread cpu usage", /* usage */
+ "rtems", /* topic */
+ rtems_shell_main_cpuuse, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_date.c b/cpukit/libmisc/shell/main_date.c
new file mode 100644
index 0000000000..da6faa0e53
--- /dev/null
+++ b/cpukit/libmisc/shell/main_date.c
@@ -0,0 +1,80 @@
+/*
+ * DATE Shell Command Implmentation
+ *
+ * OAuthor: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * Significantly rewritten by Joel Sherrill <joel.sherrill@oarcorp.com>.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_date(
+ int argc,
+ char *argv[]
+)
+{
+ /*
+ * Print the current date and time in default format.
+ */
+ if ( argc == 1 ) {
+ time_t t;
+
+ time(&t);
+ printf("%s", ctime(&t));
+ return 0;
+ }
+
+ /*
+ * Set the current date and time
+ */
+ if ( argc == 3 ) {
+ char buf[128];
+ struct tm TOD;
+ struct timespec timesp;
+ char *result;
+
+ snprintf( buf, sizeof(buf), "%s %s", argv[1], argv[2] );
+ result = strptime(
+ buf,
+ "%Y-%m-%d %T",
+ &TOD
+ );
+ if ( result && !*result ) {
+ timesp.tv_sec = mktime( &TOD );
+ timesp.tv_nsec = 0;
+ clock_settime( CLOCK_REALTIME, &timesp );
+ return 0;
+ }
+ }
+
+ fprintf( stderr, "%s: Usage: [YYYY-MM-DD HH:MM:SS]\n", argv[0] );
+ return -1;
+}
+
+rtems_shell_cmd_t rtems_shell_DATE_Command = {
+ "date", /* name */
+ "date [YYYY-MM-DD HH:MM:SS]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_date, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_dd.c b/cpukit/libmisc/shell/main_dd.c
new file mode 100644
index 0000000000..930d382a97
--- /dev/null
+++ b/cpukit/libmisc/shell/main_dd.c
@@ -0,0 +1,565 @@
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#ifndef lint
+static char const copyright[] =
+"@(#) Copyright (c) 1991, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
+#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/dd/dd.c,v 1.43 2004/08/15 19:10:05 rwatson Exp $");
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#if RTEMS_REMOVED
+#include <sys/conf.h>
+#include <sys/disklabel.h>
+#endif
+#include <sys/filio.h>
+#include <sys/time.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "dd.h"
+#include "extern-dd.h"
+
+#define DD_DEFFILEMODE 0
+
+static void dd_close(rtems_shell_dd_globals* globals);
+static void dd_in(rtems_shell_dd_globals* globals);
+static void getfdtype(rtems_shell_dd_globals* globals, IO *);
+static void setup(rtems_shell_dd_globals* globals);
+
+#if RTEMS_REMOVED
+IO in, out; /* input/output state */
+STAT st; /* statistics */
+void (*cfunc)(void); /* conversion function */
+uintmax_t cpy_cnt; /* # of blocks to copy */
+static off_t pending = 0; /* pending seek if sparse */
+u_int ddflags = 0; /* conversion options */
+size_t cbsz; /* conversion block size */
+uintmax_t files_cnt = 1; /* # of files to copy */
+const u_char *ctab; /* conversion table */
+char fill_char; /* Character to fill with if defined */
+#endif
+
+static off_t pending = 0; /* pending seek if sparse */
+
+void
+rtems_shell_dd_exit (rtems_shell_dd_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+static int main_dd(rtems_shell_dd_globals* globals, int argc, char *argv[]);
+
+int
+rtems_shell_main_dd(int argc, char *argv[])
+{
+ rtems_shell_dd_globals dd_globals;
+ rtems_shell_dd_globals* globals = &dd_globals;
+ memset (globals, 0, sizeof (dd_globals));
+ pending = 0;
+ ddflags = 0;
+ files_cnt = 1;
+ dd_globals.exit_code = 1;
+ if (setjmp (dd_globals.exit_jmp) == 0)
+ dd_globals.exit_code = main_dd (globals, argc, argv);
+ if (in.fd)
+ close(in.fd);
+ if (out.fd)
+ close(out.fd);
+ if (in.name)
+ free((void*)in.name);
+ if (out.name)
+ free((void*)out.name);
+ if (in.db)
+ free(in.db);
+ if (out.db && (in.db != out.db))
+ free(out.db);
+ return dd_globals.exit_code;
+}
+
+int
+main_dd(rtems_shell_dd_globals* globals, int argc __unused, char *argv[])
+{
+ (void)setlocale(LC_CTYPE, "");
+ jcl(globals, argv);
+ setup(globals);
+
+#if RTEMS_REMOVED
+ (void)signal(SIGINFO, summaryx);
+ (void)signal(SIGINT, terminate);
+
+ atexit(summary);
+#endif
+
+ while (files_cnt--)
+ dd_in(globals);
+
+ dd_close(globals);
+ exit(0);
+ /* NOTREACHED */
+ return 0;
+}
+
+static int
+parity(u_char c)
+{
+ int i;
+
+ i = c ^ (c >> 1) ^ (c >> 2) ^ (c >> 3) ^
+ (c >> 4) ^ (c >> 5) ^ (c >> 6) ^ (c >> 7);
+ return (i & 1);
+}
+
+static void
+setup(rtems_shell_dd_globals* globals)
+{
+ u_int cnt;
+ struct timeval tv;
+
+ if (in.name == NULL) {
+ in.name = "stdin";
+ in.fd = STDIN_FILENO;
+ } else {
+ in.fd = open(in.name, O_RDONLY, 0);
+ if (in.fd == -1)
+ err(exit_jump, 1, "%s", in.name);
+ }
+
+ getfdtype(globals, &in);
+
+ if (files_cnt > 1 && !(in.flags & ISTAPE))
+ errx(exit_jump, 1, "files is not supported for non-tape devices");
+
+ if (out.name == NULL) {
+ /* No way to check for read access here. */
+ out.fd = STDOUT_FILENO;
+ out.name = "stdout";
+ } else {
+#define OFLAGS \
+ (O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC))
+ out.fd = open(out.name, O_RDWR | OFLAGS, DD_DEFFILEMODE);
+ /*
+ * May not have read access, so try again with write only.
+ * Without read we may have a problem if output also does
+ * not support seeks.
+ */
+ if (out.fd == -1) {
+ out.fd = open(out.name, O_WRONLY | OFLAGS, DD_DEFFILEMODE);
+ out.flags |= NOREAD;
+ }
+ if (out.fd == -1)
+ err(exit_jump, 1, "%s", out.name);
+ }
+
+ getfdtype(globals, &out);
+
+ /*
+ * Allocate space for the input and output buffers. If not doing
+ * record oriented I/O, only need a single buffer.
+ */
+ if (!(ddflags & (C_BLOCK | C_UNBLOCK))) {
+ if ((in.db = malloc(out.dbsz + in.dbsz - 1)) == NULL)
+ err(exit_jump, 1, "input buffer");
+ out.db = in.db;
+ } else if ((in.db = malloc(MAX(in.dbsz, cbsz) + cbsz)) == NULL ||
+ (out.db = malloc(out.dbsz + cbsz)) == NULL)
+ err(exit_jump, 1, "output buffer");
+ in.dbp = in.db;
+ out.dbp = out.db;
+
+ /* Position the input/output streams. */
+ if (in.offset)
+ pos_in(globals);
+ if (out.offset)
+ pos_out(globals);
+
+ /*
+ * Truncate the output file. If it fails on a type of output file
+ * that it should _not_ fail on, error out.
+ */
+ if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK) &&
+ out.flags & ISTRUNC)
+ if (ftruncate(out.fd, out.offset * out.dbsz) == -1)
+ err(exit_jump, 1, "truncating %s", out.name);
+
+ if (ddflags & (C_LCASE | C_UCASE | C_ASCII | C_EBCDIC | C_PARITY)) {
+ if (ctab != NULL) {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ casetab[cnt] = ctab[cnt];
+ } else {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ casetab[cnt] = cnt;
+ }
+ if ((ddflags & C_PARITY) && !(ddflags & C_ASCII)) {
+ /*
+ * If the input is not EBCDIC, and we do parity
+ * processing, strip input parity.
+ */
+ for (cnt = 200; cnt <= 0377; ++cnt)
+ casetab[cnt] = casetab[cnt & 0x7f];
+ }
+ if (ddflags & C_LCASE) {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ casetab[cnt] = tolower(casetab[cnt]);
+ } else if (ddflags & C_UCASE) {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ casetab[cnt] = toupper(casetab[cnt]);
+ }
+ if ((ddflags & C_PARITY)) {
+ /*
+ * This should strictly speaking be a no-op, but I
+ * wonder what funny LANG settings could get us.
+ */
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ casetab[cnt] = casetab[cnt] & 0x7f;
+ }
+ if ((ddflags & C_PARSET)) {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ casetab[cnt] = casetab[cnt] | 0x80;
+ }
+ if ((ddflags & C_PAREVEN)) {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ if (parity(casetab[cnt]))
+ casetab[cnt] = casetab[cnt] | 0x80;
+ }
+ if ((ddflags & C_PARODD)) {
+ for (cnt = 0; cnt <= 0377; ++cnt)
+ if (!parity(casetab[cnt]))
+ casetab[cnt] = casetab[cnt] | 0x80;
+ }
+
+ ctab = casetab;
+ }
+
+ (void)gettimeofday(&tv, (struct timezone *)NULL);
+ st.start = tv.tv_sec + tv.tv_usec * 1e-6;
+}
+
+static void
+getfdtype(rtems_shell_dd_globals* globals, IO *io)
+{
+ struct stat sb;
+#if RTEMS_REMOVED
+ int type;
+#endif
+
+ if (fstat(io->fd, &sb) == -1)
+ err(exit_jump, 1, "%s", io->name);
+ if (S_ISREG(sb.st_mode))
+ io->flags |= ISTRUNC;
+#if RTEMS_REMOVED
+ if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) {
+ if (ioctl(io->fd, FIODTYPE, &type) == -1) {
+ err(exit_jump, 1, "%s", io->name);
+ } else {
+ if (type & D_TAPE)
+ io->flags |= ISTAPE;
+ else if (type & (D_DISK | D_MEM))
+ io->flags |= ISSEEK;
+ if (S_ISCHR(sb.st_mode) && (type & D_TAPE) == 0)
+ io->flags |= ISCHR;
+ }
+ return;
+ }
+#else
+ io->flags |= ISSEEK;
+#endif
+ errno = 0;
+ if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
+ io->flags |= ISPIPE;
+ else
+ io->flags |= ISSEEK;
+}
+
+static void
+dd_in(rtems_shell_dd_globals* globals)
+{
+ ssize_t n;
+
+ for (;;) {
+ switch (cpy_cnt) {
+ case -1: /* count=0 was specified */
+ return;
+ case 0:
+ break;
+ default:
+ if (st.in_full + st.in_part >= (uintmax_t)cpy_cnt)
+ return;
+ break;
+ }
+
+ /*
+ * Zero the buffer first if sync; if doing block operations,
+ * use spaces.
+ */
+ if (ddflags & C_SYNC) {
+ if (ddflags & C_FILL)
+ memset(in.dbp, fill_char, in.dbsz);
+ else if (ddflags & (C_BLOCK | C_UNBLOCK))
+ memset(in.dbp, ' ', in.dbsz);
+ else
+ memset(in.dbp, 0, in.dbsz);
+ }
+
+ n = read(in.fd, in.dbp, in.dbsz);
+ if (n == 0) {
+ in.dbrcnt = 0;
+ return;
+ }
+
+ /* Read error. */
+ if (n == -1) {
+ /*
+ * If noerror not specified, die. POSIX requires that
+ * the warning message be followed by an I/O display.
+ */
+ if (!(ddflags & C_NOERROR))
+ err(exit_jump, 1, "%s", in.name);
+ warn("%s", in.name);
+ summary(globals);
+
+ /*
+ * If it's a seekable file descriptor, seek past the
+ * error. If your OS doesn't do the right thing for
+ * raw disks this section should be modified to re-read
+ * in sector size chunks.
+ */
+ if (in.flags & ISSEEK &&
+ lseek(in.fd, (off_t)in.dbsz, SEEK_CUR))
+ warn("%s", in.name);
+
+ /* If sync not specified, omit block and continue. */
+ if (!(ddflags & C_SYNC))
+ continue;
+
+ /* Read errors count as full blocks. */
+ in.dbcnt += in.dbrcnt = in.dbsz;
+ ++st.in_full;
+
+ /* Handle full input blocks. */
+ } else if ((size_t)n == in.dbsz) {
+ in.dbcnt += in.dbrcnt = n;
+ ++st.in_full;
+
+ /* Handle partial input blocks. */
+ } else {
+ /* If sync, use the entire block. */
+ if (ddflags & C_SYNC)
+ in.dbcnt += in.dbrcnt = in.dbsz;
+ else
+ in.dbcnt += in.dbrcnt = n;
+ ++st.in_part;
+ }
+
+ /*
+ * POSIX states that if bs is set and no other conversions
+ * than noerror, notrunc or sync are specified, the block
+ * is output without buffering as it is read.
+ */
+ if (ddflags & C_BS) {
+ out.dbcnt = in.dbcnt;
+ dd_out(globals, 1);
+ in.dbcnt = 0;
+ continue;
+ }
+
+ if (ddflags & C_SWAB) {
+ if ((n = in.dbrcnt) & 1) {
+ ++st.swab;
+ --n;
+ }
+ swab(in.dbp, in.dbp, (size_t)n);
+ }
+
+ in.dbp += in.dbrcnt;
+ (*cfunc)(globals);
+ }
+}
+
+/*
+ * Clean up any remaining I/O and flush output. If necessary, the output file
+ * is truncated.
+ */
+static void
+dd_close(rtems_shell_dd_globals* globals)
+{
+ if (cfunc == def)
+ def_close(globals);
+ else if (cfunc == block)
+ block_close(globals);
+ else if (cfunc == unblock)
+ unblock_close(globals);
+ if (ddflags & C_OSYNC && out.dbcnt && out.dbcnt < out.dbsz) {
+ if (ddflags & C_FILL)
+ memset(out.dbp, fill_char, out.dbsz - out.dbcnt);
+ else if (ddflags & (C_BLOCK | C_UNBLOCK))
+ memset(out.dbp, ' ', out.dbsz - out.dbcnt);
+ else
+ memset(out.dbp, 0, out.dbsz - out.dbcnt);
+ out.dbcnt = out.dbsz;
+ }
+ if (out.dbcnt || pending)
+ dd_out(globals, 1);
+}
+
+void
+dd_out(rtems_shell_dd_globals* globals, int force)
+{
+ u_char *outp;
+ size_t cnt, i, n;
+ ssize_t nw;
+ static int warned;
+ int sparse;
+
+ /*
+ * Write one or more blocks out. The common case is writing a full
+ * output block in a single write; increment the full block stats.
+ * Otherwise, we're into partial block writes. If a partial write,
+ * and it's a character device, just warn. If a tape device, quit.
+ *
+ * The partial writes represent two cases. 1: Where the input block
+ * was less than expected so the output block was less than expected.
+ * 2: Where the input block was the right size but we were forced to
+ * write the block in multiple chunks. The original versions of dd(1)
+ * never wrote a block in more than a single write, so the latter case
+ * never happened.
+ *
+ * One special case is if we're forced to do the write -- in that case
+ * we play games with the buffer size, and it's usually a partial write.
+ */
+ outp = out.db;
+ for (n = force ? out.dbcnt : out.dbsz;; n = out.dbsz) {
+ for (cnt = n;; cnt -= nw) {
+ sparse = 0;
+ if (ddflags & C_SPARSE) {
+ sparse = 1; /* Is buffer sparse? */
+ for (i = 0; i < cnt; i++)
+ if (outp[i] != 0) {
+ sparse = 0;
+ break;
+ }
+ }
+ if (sparse && !force) {
+ pending += cnt;
+ nw = cnt;
+ } else {
+ if (pending != 0) {
+ if (force)
+ pending--;
+ if (lseek(out.fd, pending, SEEK_CUR) ==
+ -1)
+ err(exit_jump, 2, "%s: seek error creating sparse file",
+ out.name);
+ if (force)
+ write(out.fd, outp, 1);
+ pending = 0;
+ }
+ if (cnt)
+ nw = write(out.fd, outp, cnt);
+ else
+ return;
+ }
+
+ if (nw <= 0) {
+ if (nw == 0)
+ errx(exit_jump, 1, "%s: end of device", out.name);
+ if (errno != EINTR)
+ err(exit_jump, 1, "%s", out.name);
+ nw = 0;
+ }
+ outp += nw;
+ st.bytes += nw;
+ if ((size_t)nw == n) {
+ if (n != out.dbsz)
+ ++st.out_part;
+ else
+ ++st.out_full;
+ break;
+ }
+ ++st.out_part;
+ if ((size_t)nw == cnt)
+ break;
+ if (out.flags & ISTAPE)
+ errx(exit_jump, 1, "%s: short write on tape device",
+ out.name);
+ if (out.flags & ISCHR && !warned) {
+ warned = 1;
+ warnx("%s: short write on character device",
+ out.name);
+ }
+ }
+ if ((out.dbcnt -= n) < out.dbsz)
+ break;
+ }
+
+ /* Reassemble the output block. */
+ if (out.dbcnt)
+ (void)memmove(out.db, out.dbp - out.dbcnt, out.dbcnt);
+ out.dbp = out.db + out.dbcnt;
+}
+
+rtems_shell_cmd_t rtems_shell_DD_Command = {
+ "dd", /* name */
+ "dd [OPERAND]...", /* usage */
+ "files", /* topic */
+ rtems_shell_main_dd, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_debugrfs.c b/cpukit/libmisc/shell/main_debugrfs.c
new file mode 100644
index 0000000000..5d4052d43a
--- /dev/null
+++ b/cpukit/libmisc/shell/main_debugrfs.c
@@ -0,0 +1,35 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include <rtems/shellconfig.h>
+#include <rtems/rtems-rfs-shell.h>
+#include <rtems/fsmount.h>
+#include "internal.h"
+
+#define OPTIONS "[-h]"
+
+rtems_shell_cmd_t rtems_shell_DEBUGRFS_Command = {
+ "debugrfs", /* name */
+ "debugrfs " OPTIONS, /* usage */
+ "files", /* topic */
+ rtems_shell_debugrfs, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_dir.c b/cpukit/libmisc/shell/main_dir.c
new file mode 100644
index 0000000000..473ab13f80
--- /dev/null
+++ b/cpukit/libmisc/shell/main_dir.c
@@ -0,0 +1,26 @@
+/*
+ * DIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+rtems_shell_alias_t rtems_shell_DIR_Alias = {
+ "ls", /* command */
+ "dir" /* alias */
+};
diff --git a/cpukit/libmisc/shell/main_echo.c b/cpukit/libmisc/shell/main_echo.c
new file mode 100644
index 0000000000..8f868a2f29
--- /dev/null
+++ b/cpukit/libmisc/shell/main_echo.c
@@ -0,0 +1,142 @@
+/* $NetBSD: echo.c,v 1.12 2005/02/06 04:43:43 perry Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Kenneth Almquist.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)echo.c 8.1 (Berkeley) 5/31/93
+ */
+
+/*
+ * Echo command.
+ *
+ * echo is steeped in tradition - several of them!
+ * netbsd has supported 'echo [-n | -e] args' in spite of -e not being
+ * documented anywhere.
+ * Posix requires that -n be supported, output from strings containing
+ * \ is implementation defined
+ * The Single Unix Spec requires that \ escapes be treated as if -e
+ * were set, but that -n not be treated as an option.
+ * (ksh supports 'echo [-eEn] args', but not -- so that it is actually
+ * impossible to actually output '-n')
+ *
+ * It is suggested that 'printf "%b" "string"' be used to get \ sequences
+ * expanded. printf is now a builtin of netbsd's sh and csh.
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+
+
+int rtems_shell_main_echo(
+ int argc,
+ char *argv[]
+)
+{
+ char **ap;
+ char *p;
+ char c;
+ int count;
+ int nflag = 0;
+ int eflag = 0;
+
+ ap = argv;
+ if (argc)
+ ap++;
+
+ if ((p = *ap) != NULL) {
+ if (!strcmp(p, "-n")) {
+ nflag = 1;
+ ap++;
+ } else if (!strcmp(p, "-e")) {
+ eflag = 1;
+ ap++;
+ }
+ }
+
+ while ((p = *ap++) != NULL) {
+ while ((c = *p++) != '\0') {
+ if (c == '\\' && eflag) {
+ switch (*p++) {
+ case 'a': c = '\a'; break; /* bell */
+ case 'b': c = '\b'; break;
+ case 'c': return 0; /* exit */
+ case 'e': c = 033; break; /* escape */
+ case 'f': c = '\f'; break;
+ case 'n': c = '\n'; break;
+ case 'r': c = '\r'; break;
+ case 't': c = '\t'; break;
+ case 'v': c = '\v'; break;
+ case '\\': break; /* c = '\\' */
+ case '0':
+ c = 0;
+ count = 3;
+ while (--count >= 0 && (unsigned)(*p - '0') < 8)
+ c = (c << 3) + (*p++ - '0');
+ break;
+ default:
+ /* Output the '/' and char following */
+ p--;
+ break;
+ }
+ }
+ putchar(c);
+ }
+ if (*ap)
+ putchar(' ');
+ }
+ if (! nflag)
+ putchar('\n');
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_ECHO_Command = {
+ "echo", /* name */
+ "echo [args]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_echo, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_exit.c b/cpukit/libmisc/shell/main_exit.c
new file mode 100644
index 0000000000..4d996cde10
--- /dev/null
+++ b/cpukit/libmisc/shell/main_exit.c
@@ -0,0 +1,26 @@
+/*
+ * exit Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+rtems_shell_alias_t rtems_shell_EXIT_Alias = {
+ "logoff", /* command */
+ "exit" /* alias */
+};
diff --git a/cpukit/libmisc/shell/main_getenv.c b/cpukit/libmisc/shell/main_getenv.c
new file mode 100644
index 0000000000..4e4789b632
--- /dev/null
+++ b/cpukit/libmisc/shell/main_getenv.c
@@ -0,0 +1,49 @@
+/*
+ * Get an environment vairable.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_getenv(int argc, char *argv[])
+{
+ char* string;
+
+ if (argc != 2)
+ {
+ printf ("error: only argument is the variable name\n");
+ return 1;
+ }
+
+ string = getenv (argv[1]);
+
+ if (!string)
+ {
+ printf ("error: %s not found\n", argv[1]);
+ return 1;
+ }
+
+ printf ("%s\n", string);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_GETENV_Command = {
+ "getenv", /* name */
+ "getenv [var]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_getenv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_halt.c b/cpukit/libmisc/shell/main_halt.c
new file mode 100644
index 0000000000..f6f9f7e4fd
--- /dev/null
+++ b/cpukit/libmisc/shell/main_halt.c
@@ -0,0 +1,40 @@
+/*
+ * Halt Command Implementation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_halt(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ exit(0);
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_HALT_Command = {
+ "halt", /* name */
+ "halt", /* usage */
+ "rtems", /* topic */
+ rtems_shell_main_halt, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_help.c b/cpukit/libmisc/shell/main_help.c
new file mode 100644
index 0000000000..512eb60bbc
--- /dev/null
+++ b/cpukit/libmisc/shell/main_help.c
@@ -0,0 +1,152 @@
+/*
+ *
+ * Shell Help Command
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/system.h>
+#include <rtems/shell.h>
+
+#include "internal.h"
+#include <string.h>
+
+/*
+ * show the help for one command.
+ */
+int rtems_shell_help_cmd(
+ rtems_shell_cmd_t *shell_cmd
+)
+{
+ const char * pc;
+ int col,line;
+
+ printf("%-12.12s - ",shell_cmd->name);
+ col = 14;
+ line = 1;
+ if (shell_cmd->alias) {
+ printf("is an <alias> for command '%s'",shell_cmd->alias->name);
+ } else if (shell_cmd->usage) {
+ pc = shell_cmd->usage;
+ while (*pc) {
+ switch(*pc) {
+ case '\r':
+ break;
+ case '\n':
+ putchar('\n');
+ col = 0;
+ break;
+ default:
+ putchar(*pc);
+ col++;
+ break;
+ }
+ pc++;
+ if (col>78) { /* What daring... 78?*/
+ if (*pc) {
+ putchar('\n');
+ col = 0;
+ }
+ }
+ if (!col && *pc) {
+ printf(" ");
+ col = 12;line++;
+ }
+ }
+ }
+ puts("");
+ return line;
+}
+
+/*
+ * show the help. The first command implemented.
+ * Can you see the header of routine? Known?
+ * The same with all the commands....
+ */
+int rtems_shell_help(
+ int argc,
+ char * argv[]
+)
+{
+ int col,line,arg;
+ rtems_shell_topic_t *topic;
+ rtems_shell_cmd_t * shell_cmd = rtems_shell_first_cmd;
+
+ if (argc<2) {
+ printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"
+ " TOPIC? The topics are\n");
+ topic = rtems_shell_first_topic;
+ col = 0;
+ while (topic) {
+ if (!col){
+ col = printf(" %s",topic->topic);
+ } else {
+ if ((col+strlen(topic->topic)+2)>78){
+ printf("\n");
+ col = printf(" %s",topic->topic);
+ } else {
+ col+= printf(", %s",topic->topic);
+ }
+ }
+ topic = topic->next;
+ }
+ printf("\n");
+ return 1;
+ }
+ line = 0;
+ for (arg = 1;arg<argc;arg++) {
+ if (line>16) {
+ printf("Press any key to continue...");getchar();
+ printf("\n");
+ line = 0;
+ }
+ topic = rtems_shell_lookup_topic(argv[arg]);
+ if (!topic){
+ if ((shell_cmd = rtems_shell_lookup_cmd(argv[arg])) == NULL) {
+ printf("help: topic or cmd '%s' not found. Try <help> alone for a list\n",
+ argv[arg]);
+ line++;
+ } else {
+ line+= rtems_shell_help_cmd(shell_cmd);
+ }
+ continue;
+ }
+ printf("help: list for the topic '%s'\n",argv[arg]);
+ line++;
+ while (shell_cmd) {
+ if (!strcmp(topic->topic,shell_cmd->topic))
+ line+= rtems_shell_help_cmd(shell_cmd);
+ if (line>16) {
+ printf("Press any key to continue...");
+ getchar();
+ printf("\n");
+ line = 0;
+ }
+ shell_cmd = shell_cmd->next;
+ }
+ }
+ puts("");
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_HELP_Command = {
+ "help", /* name */
+ "help [topic] # list of usage of commands", /* usage */
+ "help", /* topic */
+ rtems_shell_help, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_hexdump.c b/cpukit/libmisc/shell/main_hexdump.c
new file mode 100644
index 0000000000..8eb5a4e409
--- /dev/null
+++ b/cpukit/libmisc/shell/main_hexdump.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef lint
+static const char copyright[] =
+"@(#) Copyright (c) 1989, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/hexdump/hexdump.c,v 1.7 2002/09/04 23:29:01 dwmalone Exp $");
+#endif
+#endif /* not lint */
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+
+#include <sys/types.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define rindex(s,c) strrchr(s,c)
+
+#include "hexdump.h"
+
+#if RTEMS_REMOVED
+FS *fshead; /* head of format strings */
+int blocksize; /* data block size */
+int exitval; /* final exit value */
+int length = -1; /* max bytes to read */
+#endif
+
+void
+rtems_shell_hexdump_exit (rtems_shell_hexdump_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+static int main_hexdump(rtems_shell_hexdump_globals* globals, int argc, char *argv[]);
+
+int
+rtems_shell_main_hexdump(int argc, char *argv[])
+{
+ rtems_shell_hexdump_globals hexdump_globals;
+ rtems_shell_hexdump_globals* globals = &hexdump_globals;
+ memset (globals, 0, sizeof (hexdump_globals));
+ vflag = FIRST;
+ ateof = 1;
+ hexdump_globals.exit_code = 1;
+ if (setjmp (hexdump_globals.exit_jmp) == 0)
+ hexdump_globals.exit_code = main_hexdump (globals, argc, argv);
+ if (curp)
+ free (curp);
+ if (savp)
+ free (savp);
+ while (fshead)
+ {
+ FS* nextfs = fshead->nextfs;
+ while (fshead->nextfu)
+ {
+ FU* nextfu = fshead->nextfu->nextfu;
+ if (fshead->nextfu->fmt)
+ free(fshead->nextfu->fmt);
+ while (fshead->nextfu->nextpr)
+ {
+ PR* nextpr = fshead->nextfu->nextpr->nextpr;
+ if (((fshead->nextfu->nextpr->flags & F_TEXT) == 0) &&
+ fshead->nextfu->nextpr->fmt)
+ free(fshead->nextfu->nextpr->fmt);
+ free(fshead->nextfu->nextpr);
+ fshead->nextfu->nextpr = nextpr;
+ }
+ free(fshead->nextfu);
+ fshead->nextfu = nextfu;
+ }
+ free(fshead);
+ fshead = nextfs;
+ }
+ if (hdstdin)
+ {
+ fclose (hdstdin);
+ free (hdstdin);
+ }
+ return hexdump_globals.exit_code;
+}
+
+int
+main_hexdump(rtems_shell_hexdump_globals* globals, int argc, char *argv[])
+{
+ FS *tfs;
+ char *p;
+
+#if RTEMS_REMOVED
+ (void)setlocale(LC_ALL, "");
+#endif
+
+ if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
+ newsyntax(globals, argc, &argv);
+ else
+ oldsyntax(globals, argc, &argv);
+
+ /* figure out the data block size */
+ for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
+ tfs->bcnt = size(globals, tfs);
+ if (blocksize < tfs->bcnt)
+ blocksize = tfs->bcnt;
+ }
+ /* rewrite the rules, do syntax checking */
+ for (tfs = fshead; tfs; tfs = tfs->nextfs)
+ rewrite(globals, tfs);
+
+ (void)next(globals, argv);
+ display(globals);
+ exit(exitval);
+ return exitval;
+}
+
+rtems_shell_cmd_t rtems_shell_HEXDUMP_Command = {
+ "hexdump", /* name */
+ "hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]\n" /* usage */
+ " [-s skip] [file ...]",
+ "files", /* topic */
+ rtems_shell_main_hexdump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
diff --git a/cpukit/libmisc/shell/main_id.c b/cpukit/libmisc/shell/main_id.c
new file mode 100644
index 0000000000..8fa0914597
--- /dev/null
+++ b/cpukit/libmisc/shell/main_id.c
@@ -0,0 +1,67 @@
+/*
+ * ID Command Implementation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_id(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ struct passwd *pwd;
+ struct group *grp;
+
+ pwd = getpwuid(getuid());
+ grp = getgrgid(getgid());
+ printf(
+ "uid=%d(%s),gid=%d(%s),",
+ getuid(),
+ (pwd) ? pwd->pw_name : "",
+ getgid(),
+ (grp) ? grp->gr_name : ""
+ );
+ pwd = getpwuid(geteuid());
+ grp = getgrgid(getegid());
+ printf(
+ "euid=%d(%s),egid=%d(%s)\n",
+ geteuid(),
+ (pwd) ? pwd->pw_name : "",
+ getegid(),
+ (grp) ? grp->gr_name : ""
+ );
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_ID_Command = {
+ "id", /* name */
+ "show uid, gid, euid, and egid", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_id, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_ifconfig.c b/cpukit/libmisc/shell/main_ifconfig.c
new file mode 100644
index 0000000000..9f16207b10
--- /dev/null
+++ b/cpukit/libmisc/shell/main_ifconfig.c
@@ -0,0 +1,243 @@
+/*
+ * IFCONFIG Command Implmentation
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_ifconfig(
+ int argc,
+ char *argv[]
+)
+{
+ struct sockaddr_in ipaddr;
+ struct sockaddr_in dstaddr;
+ struct sockaddr_in netmask;
+ struct sockaddr_in broadcast;
+ char *iface;
+ int f_ip = 0;
+ int f_ptp = 0;
+ int f_netmask = 0;
+ int f_up = 0;
+ int f_down = 0;
+ int f_bcast = 0;
+ int cur_idx;
+ int rc;
+ int flags;
+
+ memset(&ipaddr, 0, sizeof(ipaddr));
+ memset(&dstaddr, 0, sizeof(dstaddr));
+ memset(&netmask, 0, sizeof(netmask));
+ memset(&broadcast, 0, sizeof(broadcast));
+
+ ipaddr.sin_len = sizeof(ipaddr);
+ ipaddr.sin_family = AF_INET;
+
+ dstaddr.sin_len = sizeof(dstaddr);
+ dstaddr.sin_family = AF_INET;
+
+ netmask.sin_len = sizeof(netmask);
+ netmask.sin_family = AF_INET;
+
+ broadcast.sin_len = sizeof(broadcast);
+ broadcast.sin_family = AF_INET;
+
+ cur_idx = 0;
+ if (argc <= 1) {
+ /* display all interfaces */
+ iface = NULL;
+ cur_idx += 1;
+ } else {
+ iface = argv[1];
+ if (isdigit((unsigned char)*argv[2])) {
+ if (inet_pton(AF_INET, argv[2], &ipaddr.sin_addr) < 0) {
+ printf("bad ip address: %s\n", argv[2]);
+ return 0;
+ }
+ f_ip = 1;
+ cur_idx += 3;
+ } else {
+ cur_idx += 2;
+ }
+ }
+
+ if ((f_down !=0) && (f_ip != 0)) {
+ f_up = 1;
+ }
+
+ while(argc > cur_idx) {
+ if (strcmp(argv[cur_idx], "up") == 0) {
+ f_up = 1;
+ if (f_down != 0) {
+ printf("Can't make interface up and down\n");
+ }
+ } else if(strcmp(argv[cur_idx], "down") == 0) {
+ f_down = 1;
+ if (f_up != 0) {
+ printf("Can't make interface up and down\n");
+ }
+ } else if(strcmp(argv[cur_idx], "netmask") == 0) {
+ if ((cur_idx + 1) >= argc) {
+ printf("No netmask address\n");
+ return -1;
+ }
+ if (inet_pton(AF_INET, argv[cur_idx+1], &netmask.sin_addr) < 0) {
+ printf("bad netmask: %s\n", argv[cur_idx]);
+ return -1;
+ }
+ f_netmask = 1;
+ cur_idx += 1;
+ } else if(strcmp(argv[cur_idx], "broadcast") == 0) {
+ if ((cur_idx + 1) >= argc) {
+ printf("No broadcast address\n");
+ return -1;
+ }
+ if (inet_pton(AF_INET, argv[cur_idx+1], &broadcast.sin_addr) < 0) {
+ printf("bad broadcast: %s\n", argv[cur_idx]);
+ return -1;
+ }
+ f_bcast = 1;
+ cur_idx += 1;
+ } else if(strcmp(argv[cur_idx], "pointopoint") == 0) {
+ if ((cur_idx + 1) >= argc) {
+ printf("No pointopoint address\n");
+ return -1;
+ }
+ if (inet_pton(AF_INET, argv[cur_idx+1], &dstaddr.sin_addr) < 0) {
+ printf("bad pointopoint: %s\n", argv[cur_idx]);
+ return -1;
+ }
+ f_ptp = 1;
+ cur_idx += 1;
+ } else {
+ printf("Bad parameter: %s\n", argv[cur_idx]);
+ return -1;
+ }
+ cur_idx += 1;
+ }
+
+ printf("ifconfig ");
+ if (iface != NULL) {
+ printf("%s ", iface);
+ if (f_ip != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &ipaddr.sin_addr, str, 256);
+ printf("%s ", str);
+ }
+
+ if (f_netmask != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &netmask.sin_addr, str, 256);
+ printf("netmask %s ", str);
+ }
+
+ if (f_bcast != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &broadcast.sin_addr, str, 256);
+ printf("broadcast %s ", str);
+ }
+
+ if (f_ptp != 0) {
+ char str[256];
+ inet_ntop(AF_INET, &dstaddr.sin_addr, str, 256);
+ printf("pointopoint %s ", str);
+ }
+
+ if (f_up != 0) {
+ printf("up\n");
+ } else if (f_down != 0) {
+ printf("down\n");
+ } else {
+ printf("\n");
+ }
+ }
+
+ if ((iface == NULL) || ((f_ip == 0) && (f_down == 0) && (f_up == 0))) {
+ rtems_bsdnet_show_if_stats();
+ return 0;
+ }
+
+ flags = 0;
+ if (f_netmask) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFNETMASK, &netmask);
+ if (rc < 0) {
+ printf("Could not set netmask: %s\n", strerror(errno));
+ return -1;
+ }
+ }
+
+ if (f_bcast) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFBRDADDR, &broadcast);
+ if (rc < 0) {
+ printf("Could not set broadcast: %s\n", strerror(errno));
+ return -1;
+ }
+ }
+
+ if (f_ptp) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFDSTADDR, &dstaddr);
+ if (rc < 0) {
+ printf("Could not set destination address: %s\n", strerror(errno));
+ return -1;
+ }
+ flags |= IFF_POINTOPOINT;
+ }
+
+ /* This must come _after_ setting the netmask, broadcast addresses */
+ if (f_ip) {
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFADDR, &ipaddr);
+ if (rc < 0) {
+ printf("Could not set IP address: %s\n", strerror(errno));
+ return -1;
+ }
+ }
+
+ if (f_up != 0) {
+ flags |= IFF_UP;
+ }
+
+ if (f_down != 0) {
+ printf("Warning: taking interfaces down is not supported\n");
+ }
+
+ rc = rtems_bsdnet_ifconfig(iface, SIOCSIFFLAGS, &flags);
+ if (rc < 0) {
+ printf("Could not set interface flags: %s\n", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_IFCONFIG_Command = {
+ "ifconfig", /* name */
+ "TBD", /* usage */
+ "network", /* topic */
+ rtems_shell_main_ifconfig, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_ln.c b/cpukit/libmisc/shell/main_ln.c
new file mode 100644
index 0000000000..aff1ffbf91
--- /dev/null
+++ b/cpukit/libmisc/shell/main_ln.c
@@ -0,0 +1,309 @@
+/* $NetBSD: ln.c,v 1.34 2008/07/20 00:52:40 lukem Exp $ */
+
+/*
+ * Copyright (c) 1987, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\
+ The Regents of the University of California. All rights reserved.");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94";
+#else
+__RCSID("$NetBSD: ln.c,v 1.34 2008/07/20 00:52:40 lukem Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <setjmp.h>
+
+typedef struct {
+ int fflag; /* Unlink existing files. */
+ int hflag; /* Check new name for symlink first. */
+ int iflag; /* Interactive mode. */
+ int sflag; /* Symbolic, not hard, link. */
+ int vflag; /* Verbose output */
+ char linkch;
+
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_ln_globals;
+
+#define fflag globals->fflag
+#define hflag globals->hflag
+#define iflag globals->iflag
+#define sflag globals->sflag
+#define vflag globals->vflag
+#define linkch globals->linkch
+
+#define exit_jump &(globals->exit_jmp)
+
+#define exit(ec) rtems_shell_ln_exit(globals, ec)
+
+static int main_ln(rtems_shell_ln_globals* , int, char *[]);
+
+static void
+rtems_shell_ln_exit (rtems_shell_ln_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+static int main_ln(rtems_shell_ln_globals* globals, int argc, char *argv[]);
+
+int
+rtems_shell_main_ln(int argc, char *argv[])
+{
+ rtems_shell_ln_globals ln_globals;
+ rtems_shell_ln_globals* globals = &ln_globals;
+ memset (globals, 0, sizeof (ln_globals));
+ ln_globals.exit_code = 1;
+ if (setjmp (ln_globals.exit_jmp) == 0)
+ return main_ln (globals, argc, argv);
+ return ln_globals.exit_code;
+}
+
+#if RTEMS_REMOVED
+int fflag; /* Unlink existing files. */
+int hflag; /* Check new name for symlink first. */
+int iflag; /* Interactive mode. */
+int sflag; /* Symbolic, not hard, link. */
+int vflag; /* Verbose output */
+
+ /* System link call. */
+int (*linkf)(const char *, const char *);
+char linkch;
+#endif
+
+int (*linkf)(const char *, const char *);
+
+static int linkit(rtems_shell_ln_globals* , const char *, const char *, int);
+static void usage(rtems_shell_ln_globals* );
+
+static int
+main_ln(rtems_shell_ln_globals* globals, int argc, char *argv[])
+{
+ struct stat sb;
+ int ch, exitval;
+ char *sourcedir;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+#if RTEMS_REMOVED
+ setprogname(argv[0]);
+ (void)setlocale(LC_ALL, "");
+#endif
+
+ while ((ch = getopt_r(argc, argv, "fhinsv", &getopt_reent)) != -1)
+ switch (ch) {
+ case 'f':
+ fflag = 1;
+ iflag = 0;
+ break;
+ case 'h':
+ case 'n':
+ hflag = 1;
+ break;
+ case 'i':
+ iflag = 1;
+ fflag = 0;
+ break;
+ case 's':
+ sflag = 1;
+ break;
+ case 'v':
+ vflag = 1;
+ break;
+ case '?':
+ default:
+ usage(globals);
+ /* NOTREACHED */
+ }
+
+ argv += getopt_reent.optind;
+ argc -= getopt_reent.optind;
+
+ if (sflag) {
+ linkf = symlink;
+ linkch = '-';
+ } else {
+ linkf = link;
+ linkch = '=';
+ }
+
+ switch(argc) {
+ case 0:
+ usage(globals);
+ /* NOTREACHED */
+ case 1: /* ln target */
+ exit(linkit(globals, argv[0], ".", 1));
+ /* NOTREACHED */
+ case 2: /* ln target source */
+ exit(linkit(globals, argv[0], argv[1], 0));
+ /* NOTREACHED */
+ }
+
+ /* ln target1 target2 directory */
+ sourcedir = argv[argc - 1];
+ if (hflag && lstat(sourcedir, &sb) == 0 && S_ISLNK(sb.st_mode)) {
+ /* we were asked not to follow symlinks, but found one at
+ the target--simulate "not a directory" error */
+ errno = ENOTDIR;
+ err(exit_jump, EXIT_FAILURE, "%s", sourcedir);
+ /* NOTREACHED */
+ }
+ if (stat(sourcedir, &sb)) {
+ err(exit_jump, EXIT_FAILURE, "%s", sourcedir);
+ /* NOTREACHED */
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ usage(globals);
+ /* NOTREACHED */
+ }
+ for (exitval = 0; *argv != sourcedir; ++argv)
+ exitval |= linkit(globals, *argv, sourcedir, 1);
+ exit(exitval);
+ /* NOTREACHED */
+ return 0;
+}
+
+int
+linkit(rtems_shell_ln_globals* globals, const char *source, const char *target, int isdir)
+{
+ struct stat sb;
+ const char *p;
+ char path[MAXPATHLEN];
+ int ch, exists, first;
+
+ if (!sflag) {
+ /* If target doesn't exist, quit now. */
+ if (stat(target, &sb)) {
+ warn("%s", target);
+ return (1);
+ }
+ }
+
+ /* If the source is a directory (and not a symlink if hflag),
+ append the target's name. */
+ if (isdir ||
+ (!lstat(source, &sb) && S_ISDIR(sb.st_mode)) ||
+ (!hflag && !stat(source, &sb) && S_ISDIR(sb.st_mode))) {
+ if ((p = strrchr(target, '/')) == NULL)
+ p = target;
+ else
+ ++p;
+ (void)snprintf(path, sizeof(path), "%s/%s", source, p);
+ source = path;
+ }
+
+ exists = !lstat(source, &sb);
+
+ /*
+ * If the file exists, then unlink it forcibly if -f was specified
+ * and interactively if -i was specified.
+ */
+ if (fflag && exists) {
+ if (unlink(source)) {
+ warn("%s", source);
+ return (1);
+ }
+ } else if (iflag && exists) {
+ fflush(stdout);
+ (void)fprintf(stderr, "replace %s? ", source);
+
+ first = ch = getchar();
+ while (ch != '\n' && ch != EOF)
+ ch = getchar();
+ if (first != 'y' && first != 'Y') {
+ (void)fprintf(stderr, "not replaced\n");
+ return (1);
+ }
+
+ if (unlink(source)) {
+ warn("%s", source);
+ return (1);
+ }
+ }
+
+ /* Attempt the link. */
+ if ((*linkf)(target, source)) {
+ warn("%s", source);
+ return (1);
+ }
+ if (vflag)
+ (void)printf("%s %c> %s\n", source, linkch, target);
+
+ return (0);
+}
+
+void
+usage(rtems_shell_ln_globals* globals)
+{
+#define getprogname() "ln"
+ (void)fprintf(stderr,
+ "usage:\t%s [-fhinsv] file1 file2\n\t%s [-fhinsv] file ... directory\n",
+ getprogname(), getprogname());
+ exit(1);
+ /* NOTREACHED */
+}
+
+rtems_shell_cmd_t rtems_shell_LN_Command = {
+ "ln", /* name */
+ "ln ln [-fhinsv] source_file [target_file]", /* usage */
+ "files", /* topic */
+ rtems_shell_main_ln, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_logoff.c b/cpukit/libmisc/shell/main_logoff.c
new file mode 100644
index 0000000000..7258724f04
--- /dev/null
+++ b/cpukit/libmisc/shell/main_logoff.c
@@ -0,0 +1,44 @@
+/*
+ * LOGOFF Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_logoff(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ printf("logoff from the system...");
+
+ rtems_current_shell_env->exit_shell = true;
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_LOGOFF_Command = {
+ "logoff", /* name */
+ "logoff from the system", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_logoff, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_ls.c b/cpukit/libmisc/shell/main_ls.c
new file mode 100644
index 0000000000..08072fb723
--- /dev/null
+++ b/cpukit/libmisc/shell/main_ls.c
@@ -0,0 +1,776 @@
+/* $NetBSD: ls.c,v 1.58 2005/10/26 02:24:22 jschauma Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Michael Fischbein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94";
+#else
+__RCSID("$NetBSD: ls.c,v 1.58 2005/10/26 02:24:22 jschauma Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <dirent.h>
+#include <err.h>
+#include <errno.h>
+#include <fts.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <termios.h>
+#include <pwd.h>
+#include <grp.h>
+
+#include "extern-ls.h"
+
+static void display(rtems_shell_ls_globals* globals, FTSENT *, FTSENT *);
+static int mastercmp_listdir(const FTSENT **, const FTSENT **);
+static int mastercmp_no_listdir(const FTSENT **, const FTSENT **);
+static void traverse(rtems_shell_ls_globals* globals, int, char **, int);
+
+static void (*printfcn)(rtems_shell_ls_globals* globals, DISPLAY *);
+static int (*sortfcn)(const FTSENT *, const FTSENT *);
+
+#define BY_NAME 0
+#define BY_SIZE 1
+#define BY_TIME 2
+
+#if RTEMS_REMOVED
+long blocksize; /* block size units */
+int termwidth = 80; /* default terminal width */
+int sortkey = BY_NAME;
+int rval = EXIT_SUCCESS; /* exit value - set if error encountered */
+
+/* flags */
+int f_accesstime; /* use time of last access */
+int f_column; /* columnated format */
+int f_columnacross; /* columnated format, sorted across */
+int f_flags; /* show flags associated with a file */
+int f_grouponly; /* long listing without owner */
+int f_humanize; /* humanize the size field */
+int f_inode; /* print inode */
+int f_listdir; /* list actual directory, not contents */
+int f_listdot; /* list files beginning with . */
+int f_longform; /* long listing format */
+int f_nonprint; /* show unprintables as ? */
+int f_nosort; /* don't sort output */
+int f_numericonly; /* don't convert uid/gid to name */
+int f_octal; /* print octal escapes for nongraphic characters */
+int f_octal_escape; /* like f_octal but use C escapes if possible */
+int f_recursive; /* ls subdirectories also */
+int f_reversesort; /* reverse whatever sort is used */
+int f_sectime; /* print the real time for all files */
+int f_singlecol; /* use single column output */
+int f_size; /* list size in short listing */
+int f_statustime; /* use time of last mode change */
+int f_stream; /* stream format */
+int f_type; /* add type character for non-regular files */
+int f_typedir; /* add type character for directories */
+int f_whiteout; /* show whiteout entries */
+#endif
+
+void
+rtems_shell_ls_exit (rtems_shell_ls_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+static int main_ls(rtems_shell_ls_globals* globals, int argc, char *argv[]);
+
+int
+rtems_shell_main_ls(int argc, char *argv[])
+{
+ rtems_shell_ls_globals ls_globals;
+ rtems_shell_ls_globals* globals = &ls_globals;
+ memset (globals, 0, sizeof (ls_globals));
+ termwidth = 80;
+ sortkey = BY_NAME;
+ rval = EXIT_SUCCESS;
+ ls_globals.exit_code = 1;
+ if (setjmp (ls_globals.exit_jmp) == 0)
+ return main_ls (globals, argc, argv);
+ return ls_globals.exit_code;
+}
+
+int
+main_ls(rtems_shell_ls_globals* globals, int argc, char *argv[])
+{
+ static char dot[] = ".", *dotav[] = { dot, NULL };
+ //struct winsize win;
+ int ch, fts_options;
+ int kflag = 0;
+ const char *p;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+#if RTEMS_REMOVED
+ setprogname(argv[0]);
+#endif
+ setlocale(LC_ALL, "");
+
+ /* Terminal defaults to -Cq, non-terminal defaults to -1. */
+ if (isatty(STDOUT_FILENO)) {
+#if RTEMS_REMOVED
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
+ win.ws_col > 0)
+ termwidth = win.ws_col;
+ f_column = f_nonprint = 1;
+#endif
+ } else
+ f_singlecol = 1;
+
+ /* Root is -A automatically. */
+ if (!getuid())
+ f_listdot = 1;
+
+ fts_options = FTS_PHYSICAL;
+ while ((ch = getopt_r(argc, argv,
+ "1ABCFLRSTWabcdfghiklmnopqrstuwx", &getopt_reent)) != -1) {
+ switch (ch) {
+ /*
+ * The -1, -C, -l, -m and -x options all override each other so
+ * shell aliasing works correctly.
+ */
+ case '1':
+ f_singlecol = 1;
+ f_column = f_columnacross = f_longform = f_stream = 0;
+ break;
+ case 'C':
+ f_column = 1;
+ f_columnacross = f_longform = f_singlecol = f_stream =
+ 0;
+ break;
+ case 'g':
+ if (f_grouponly != -1)
+ f_grouponly = 1;
+ f_longform = 1;
+ f_column = f_columnacross = f_singlecol = f_stream = 0;
+ break;
+ case 'l':
+ f_longform = 1;
+ f_column = f_columnacross = f_singlecol = f_stream = 0;
+ /* Never let -g take precedence over -l. */
+ f_grouponly = -1;
+ break;
+ case 'm':
+ f_stream = 1;
+ f_column = f_columnacross = f_longform = f_singlecol =
+ 0;
+ break;
+ case 'x':
+ f_columnacross = 1;
+ f_column = f_longform = f_singlecol = f_stream = 0;
+ break;
+ /* The -c and -u options override each other. */
+ case 'c':
+ f_statustime = 1;
+ f_accesstime = 0;
+ break;
+ case 'u':
+ f_accesstime = 1;
+ f_statustime = 0;
+ break;
+ case 'F':
+ f_type = 1;
+ break;
+ case 'L':
+ fts_options &= ~FTS_PHYSICAL;
+ fts_options |= FTS_LOGICAL;
+ break;
+ case 'R':
+ f_recursive = 1;
+ break;
+ case 'a':
+ fts_options |= FTS_SEEDOT;
+ /* FALLTHROUGH */
+ case 'A':
+ f_listdot = 1;
+ break;
+ /* The -B option turns off the -b, -q and -w options. */
+ case 'B':
+ f_nonprint = 0;
+ f_octal = 1;
+ f_octal_escape = 0;
+ break;
+ /* The -b option turns off the -B, -q and -w options. */
+ case 'b':
+ f_nonprint = 0;
+ f_octal = 0;
+ f_octal_escape = 1;
+ break;
+ /* The -d option turns off the -R option. */
+ case 'd':
+ f_listdir = 1;
+ f_recursive = 0;
+ break;
+ case 'f':
+ f_nosort = 1;
+ break;
+ case 'i':
+ f_inode = 1;
+ break;
+ case 'k':
+ blocksize = 1024;
+ kflag = 1;
+ break;
+ /* The -h option forces all sizes to be measured in bytes. */
+ case 'h':
+ f_humanize = 1;
+ break;
+ case 'n':
+ f_numericonly = 1;
+ break;
+ case 'o':
+ f_flags = 1;
+ break;
+ case 'p':
+ f_typedir = 1;
+ break;
+ /* The -q option turns off the -B, -b and -w options. */
+ case 'q':
+ f_nonprint = 1;
+ f_octal = 0;
+ f_octal_escape = 0;
+ break;
+ case 'r':
+ f_reversesort = 1;
+ break;
+ case 'S':
+ sortkey = BY_SIZE;
+ break;
+ case 's':
+ f_size = 1;
+ break;
+ case 'T':
+ f_sectime = 1;
+ break;
+ case 't':
+ sortkey = BY_TIME;
+ break;
+ case 'W':
+ f_whiteout = 1;
+ break;
+ /* The -w option turns off the -B, -b and -q options. */
+ case 'w':
+ f_nonprint = 0;
+ f_octal = 0;
+ f_octal_escape = 0;
+ break;
+ default:
+ case '?':
+ usage(globals);
+ }
+ }
+ argc -= getopt_reent.optind;
+ argv += getopt_reent.optind;
+
+ if (f_column || f_columnacross || f_stream) {
+ if ((p = getenv("COLUMNS")) != NULL)
+ termwidth = atoi(p);
+ }
+
+ /*
+ * If both -g and -l options, let -l take precedence.
+ */
+ if (f_grouponly == -1)
+ f_grouponly = 0;
+
+ /*
+ * If not -F, -i, -l, -p, -S, -s or -t options, don't require stat
+ * information.
+ */
+ if (!f_inode && !f_longform && !f_size && !f_type && !f_typedir &&
+ sortkey == BY_NAME)
+ fts_options |= FTS_NOSTAT;
+
+ /*
+ * If not -F, -d or -l options, follow any symbolic links listed on
+ * the command line.
+ */
+ if (!f_longform && !f_listdir && !f_type)
+ fts_options |= FTS_COMFOLLOW;
+
+ /*
+ * If -W, show whiteout entries
+ */
+#ifdef FTS_WHITEOUT
+ if (f_whiteout)
+ fts_options |= FTS_WHITEOUT;
+#endif
+
+ /* If -l or -s, figure out block size. */
+ if (f_inode || f_longform || f_size) {
+#if RTEMS_REMOVED
+ if (!kflag)
+ (void)getbsize(NULL, &blocksize);
+#else
+ /* Make equal to 1 so ls -l shows the actual blcok count */
+ blocksize = 512;
+#endif
+ blocksize /= 512;
+ }
+
+ /* Select a sort function. */
+ if (f_reversesort) {
+ switch (sortkey) {
+ case BY_NAME:
+ sortfcn = revnamecmp;
+ break;
+ case BY_SIZE:
+ sortfcn = revsizecmp;
+ break;
+ case BY_TIME:
+ if (f_accesstime)
+ sortfcn = revacccmp;
+ else if (f_statustime)
+ sortfcn = revstatcmp;
+ else /* Use modification time. */
+ sortfcn = revmodcmp;
+ break;
+ }
+ } else {
+ switch (sortkey) {
+ case BY_NAME:
+ sortfcn = namecmp;
+ break;
+ case BY_SIZE:
+ sortfcn = sizecmp;
+ break;
+ case BY_TIME:
+ if (f_accesstime)
+ sortfcn = acccmp;
+ else if (f_statustime)
+ sortfcn = statcmp;
+ else /* Use modification time. */
+ sortfcn = modcmp;
+ break;
+ }
+ }
+
+ /* Select a print function. */
+ if (f_singlecol)
+ printfcn = printscol;
+ else if (f_columnacross)
+ printfcn = printacol;
+ else if (f_longform)
+ printfcn = printlong;
+ else if (f_stream)
+ printfcn = printstream;
+ else
+ printfcn = printcol;
+
+ if (argc)
+ traverse(globals, argc, argv, fts_options);
+ else
+ traverse(globals, 1, dotav, fts_options);
+ exit(rval);
+ /* NOTREACHED */
+ return 0;
+}
+
+#if RTEMS_REMOVED
+static int output; /* If anything output. */
+#endif
+
+/*
+ * Traverse() walks the logical directory structure specified by the argv list
+ * in the order specified by the mastercmp() comparison function. During the
+ * traversal it passes linked lists of structures to display() which represent
+ * a superset (may be exact set) of the files to be displayed.
+ */
+static void
+traverse(rtems_shell_ls_globals* globals, int argc, char *argv[], int options)
+{
+ FTS *ftsp;
+ FTSENT *p, *chp;
+ int ch_options;
+
+ if ((ftsp =
+ fts_open(argv, options,
+ f_nosort ? NULL : f_listdir ?
+ mastercmp_listdir : mastercmp_no_listdir)) == NULL)
+ err(exit_jump, EXIT_FAILURE, NULL);
+
+ display(globals, NULL, fts_children(ftsp, 0));
+ if (f_listdir)
+ {
+ fts_close(ftsp);
+ return;
+ }
+
+ /*
+ * If not recursing down this tree and don't need stat info, just get
+ * the names.
+ */
+ ch_options = !f_recursive && options & FTS_NOSTAT ? FTS_NAMEONLY : 0;
+
+ while ((p = fts_read(ftsp)) != NULL)
+ switch (p->fts_info) {
+ case FTS_DC:
+ warnx("%s: directory causes a cycle", p->fts_name);
+ break;
+ case FTS_DNR:
+ case FTS_ERR:
+ warnx("%s: %s", p->fts_name, strerror(p->fts_errno));
+ rval = EXIT_FAILURE;
+ break;
+ case FTS_D:
+ if (p->fts_level != FTS_ROOTLEVEL &&
+ p->fts_name[0] == '.' && !f_listdot)
+ break;
+
+ /*
+ * If already output something, put out a newline as
+ * a separator. If multiple arguments, precede each
+ * directory with its name.
+ */
+ if (output)
+ (void)printf("\n%s:\n", p->fts_path);
+ else if (argc > 1) {
+ (void)printf("%s:\n", p->fts_path);
+ output = 1;
+ }
+
+ chp = fts_children(ftsp, ch_options);
+ display(globals, p, chp);
+
+ if (!f_recursive && chp != NULL)
+ (void)fts_set(ftsp, p, FTS_SKIP);
+ break;
+ }
+ fts_close(ftsp);
+ if (errno)
+ err(exit_jump, EXIT_FAILURE, "fts_read");
+}
+
+/*
+ * Display() takes a linked list of FTSENT structures and passes the list
+ * along with any other necessary information to the print function. P
+ * points to the parent directory of the display list.
+ */
+static void
+display(rtems_shell_ls_globals* globals, FTSENT *p, FTSENT *list)
+{
+ struct stat *sp;
+ DISPLAY d;
+ FTSENT *cur;
+ NAMES *np;
+ u_int64_t btotal, stotal, maxblock, maxsize;
+ int maxinode, maxnlink, maxmajor, maxminor;
+ int bcfile, entries, flen, glen, ulen, maxflags, maxgroup, maxlen;
+ int maxuser, needstats;
+ const char *user, *group;
+ char buf[21]; /* 64 bits == 20 digits, +1 for NUL */
+ char nuser[12], ngroup[12];
+ char *flags = NULL;
+
+#ifdef __GNUC__
+ /* This outrageous construct just to shut up a GCC warning. */
+ (void) &maxsize;
+#endif
+
+ /*
+ * If list is NULL there are two possibilities: that the parent
+ * directory p has no children, or that fts_children() returned an
+ * error. We ignore the error case since it will be replicated
+ * on the next call to fts_read() on the post-order visit to the
+ * directory p, and will be signalled in traverse().
+ */
+ if (list == NULL)
+ return;
+
+ needstats = f_inode || f_longform || f_size;
+ flen = 0;
+ maxinode = maxnlink = 0;
+ bcfile = 0;
+ maxuser = maxgroup = maxflags = maxlen = 0;
+ btotal = stotal = maxblock = maxsize = 0;
+ maxmajor = maxminor = 0;
+ for (cur = list, entries = 0; cur; cur = cur->fts_link) {
+ uint64_t size;
+ if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
+ warnx("%s: %s",
+ cur->fts_name, strerror(cur->fts_errno));
+ cur->fts_number = NO_PRINT;
+ rval = EXIT_FAILURE;
+ continue;
+ }
+
+ /*
+ * P is NULL if list is the argv list, to which different rules
+ * apply.
+ */
+ if (p == NULL) {
+ /* Directories will be displayed later. */
+ if (cur->fts_info == FTS_D && !f_listdir) {
+ cur->fts_number = NO_PRINT;
+ continue;
+ }
+ } else {
+ /* Only display dot file if -a/-A set. */
+ if (cur->fts_name[0] == '.' && !f_listdot) {
+ cur->fts_number = NO_PRINT;
+ continue;
+ }
+ }
+ if (cur->fts_namelen > maxlen)
+ maxlen = cur->fts_namelen;
+ if (needstats) {
+ sp = cur->fts_statp;
+ if (sp->st_size < 0)
+ size = sp->st_size * -1;
+ else
+ size = sp->st_size;
+ if (sp->st_blocks > maxblock)
+ maxblock = sp->st_blocks;
+ if (sp->st_ino > maxinode)
+ maxinode = sp->st_ino;
+ if (sp->st_nlink > maxnlink)
+ maxnlink = sp->st_nlink;
+ if (size > maxsize)
+ maxsize = size;
+ if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) {
+ bcfile = 1;
+ if (major(sp->st_rdev) > maxmajor)
+ maxmajor = major(sp->st_rdev);
+ if (minor(sp->st_rdev) > maxminor)
+ maxminor = minor(sp->st_rdev);
+ }
+
+ btotal += sp->st_blocks;
+ stotal += size;
+ if (f_longform) {
+ if (f_numericonly ||
+ (user = user_from_uid(sp->st_uid, 0)) ==
+ NULL) {
+ (void)snprintf(nuser, sizeof(nuser),
+ "%u", sp->st_uid);
+ user = nuser;
+ }
+ if (f_numericonly ||
+ (group = group_from_gid(sp->st_gid, 0)) ==
+ NULL) {
+ (void)snprintf(ngroup, sizeof(ngroup),
+ "%u", sp->st_gid);
+ group = ngroup;
+ }
+ if ((ulen = strlen(user)) > maxuser)
+ maxuser = ulen;
+ if ((glen = strlen(group)) > maxgroup)
+ maxgroup = glen;
+#if RTEMS_REMOVED
+ if (f_flags) {
+ flags =
+ flags_to_string(sp->st_flags, "-");
+ if ((flen = strlen(flags)) > maxflags)
+ maxflags = flen;
+ } else
+#endif
+ flen = 0;
+
+ if ((np = malloc(sizeof(NAMES) +
+ ulen + glen + flen + 3)) == NULL)
+ err(exit_jump, EXIT_FAILURE, NULL);
+
+ np->user = &np->data[0];
+ (void)strcpy(np->user, user);
+ np->group = &np->data[ulen + 1];
+ (void)strcpy(np->group, group);
+
+ if (f_flags && flags) {
+ np->flags = &np->data[ulen + glen + 2];
+ (void)strcpy(np->flags, flags);
+ }
+ cur->fts_pointer = np;
+ }
+ }
+ ++entries;
+ }
+
+ if (!entries)
+ return;
+
+ d.list = list;
+ d.entries = entries;
+ d.maxlen = maxlen;
+ if (needstats) {
+ d.btotal = btotal;
+ d.stotal = stotal;
+ if (f_humanize) {
+ d.s_block = 4; /* min buf length for humanize_number */
+ } else {
+ (void)snprintf(buf, sizeof(buf), "%llu",
+ (long long)howmany(maxblock, blocksize));
+ d.s_block = strlen(buf);
+ }
+ d.s_flags = maxflags;
+ d.s_group = maxgroup;
+ (void)snprintf(buf, sizeof(buf), "%u", maxinode);
+ d.s_inode = strlen(buf);
+ (void)snprintf(buf, sizeof(buf), "%u", maxnlink);
+ d.s_nlink = strlen(buf);
+ if (f_humanize) {
+ d.s_size = 4; /* min buf length for humanize_number */
+ } else {
+ (void)snprintf(buf, sizeof(buf), "%llu",
+ (long long)maxsize);
+ d.s_size = strlen(buf);
+ }
+ d.s_user = maxuser;
+ if (bcfile) {
+ (void)snprintf(buf, sizeof(buf), "%u", maxmajor);
+ d.s_major = strlen(buf);
+ (void)snprintf(buf, sizeof(buf), "%u", maxminor);
+ d.s_minor = strlen(buf);
+ if (d.s_major + d.s_minor + 2 > d.s_size)
+ d.s_size = d.s_major + d.s_minor + 2;
+ else if (d.s_size - d.s_minor - 2 > d.s_major)
+ d.s_major = d.s_size - d.s_minor - 2;
+ } else {
+ d.s_major = 0;
+ d.s_minor = 0;
+ }
+ }
+
+ printfcn(globals, &d);
+ output = 1;
+
+ if (f_longform)
+ for (cur = list; cur; cur = cur->fts_link)
+ free(cur->fts_pointer);
+}
+
+/*
+ * Ordering for mastercmp:
+ * If ordering the argv (fts_level = FTS_ROOTLEVEL) return non-directories
+ * as larger than directories. Within either group, use the sort function.
+ * All other levels use the sort function. Error entries remain unsorted.
+ */
+static int
+mastercmp_no_listdir(const FTSENT **a, const FTSENT **b)
+{
+ int a_info, b_info;
+ int l_f_listdir = 0;
+
+ a_info = (*a)->fts_info;
+ if (a_info == FTS_ERR)
+ return (0);
+ b_info = (*b)->fts_info;
+ if (b_info == FTS_ERR)
+ return (0);
+
+ if (a_info == FTS_NS || b_info == FTS_NS) {
+ if (b_info != FTS_NS)
+ return (1);
+ else if (a_info != FTS_NS)
+ return (-1);
+ else
+ return (namecmp(*a, *b));
+ }
+
+ if (a_info != b_info && !l_f_listdir &&
+ (*a)->fts_level == FTS_ROOTLEVEL) {
+ if (a_info == FTS_D)
+ return (1);
+ else if (b_info == FTS_D)
+ return (-1);
+ }
+ return (sortfcn(*a, *b));
+}
+
+static int
+mastercmp_listdir(const FTSENT **a, const FTSENT **b)
+{
+ int a_info, b_info;
+ int l_f_listdir = 1;
+
+ a_info = (*a)->fts_info;
+ if (a_info == FTS_ERR)
+ return (0);
+ b_info = (*b)->fts_info;
+ if (b_info == FTS_ERR)
+ return (0);
+
+ if (a_info == FTS_NS || b_info == FTS_NS) {
+ if (b_info != FTS_NS)
+ return (1);
+ else if (a_info != FTS_NS)
+ return (-1);
+ else
+ return (namecmp(*a, *b));
+ }
+
+ if (a_info != b_info && !l_f_listdir &&
+ (*a)->fts_level == FTS_ROOTLEVEL) {
+ if (a_info == FTS_D)
+ return (1);
+ else if (b_info == FTS_D)
+ return (-1);
+ }
+ return (sortfcn(*a, *b));
+}
+
+rtems_shell_cmd_t rtems_shell_LS_Command = {
+ "ls", /* name */
+ "ls [dir] # list files in the directory", /* usage */
+ "files", /* topic */
+ rtems_shell_main_ls, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mallocinfo.c b/cpukit/libmisc/shell/main_mallocinfo.c
new file mode 100644
index 0000000000..12423c7a73
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mallocinfo.c
@@ -0,0 +1,63 @@
+/*
+ * MALLOC_INFO Shell Command Implmentation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/malloc.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+extern int malloc_info( region_information_block * );
+extern void rtems_shell_print_unified_work_area_message(void);
+
+int rtems_shell_main_malloc_info(
+ int argc,
+ char *argv[]
+)
+{
+ if ( argc == 2 ) {
+ rtems_shell_print_unified_work_area_message();
+
+ if ( !strcmp( argv[1], "info" ) ) {
+ region_information_block info;
+
+ malloc_info( &info );
+ rtems_shell_print_heap_info( "free", &info.Free );
+ rtems_shell_print_heap_info( "used", &info.Used );
+ return 0;
+ } else if ( !strcmp( argv[1], "stats" ) ) {
+ malloc_report_statistics_with_plugin(
+ stdout,
+ (rtems_printk_plugin_t) fprintf
+ );
+ return 0;
+ }
+ }
+ fprintf( stderr, "%s: [info|stats]\n", argv[0] );
+ return -1;
+}
+
+rtems_shell_cmd_t rtems_shell_MALLOC_INFO_Command = {
+ "malloc", /* name */
+ "[info|stats]", /* usage */
+ "mem", /* topic */
+ rtems_shell_main_malloc_info, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
diff --git a/cpukit/libmisc/shell/main_mdump.c b/cpukit/libmisc/shell/main_mdump.c
new file mode 100644
index 0000000000..d196711363
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mdump.c
@@ -0,0 +1,96 @@
+/*
+ * MDUMP Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+int rtems_shell_main_mdump(
+ int argc,
+ char *argv[]
+)
+{
+ unsigned char n;
+ unsigned char m;
+ int max;
+ int res;
+ void *addr = NULL;
+ unsigned char *pb;
+
+ if (argc > 1) {
+ if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
+ printf( "Address argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+
+ }
+
+ if (argc > 2) {
+ if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
+ printf( "Length argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ if (max <= 0) {
+ max = 1; /* print 1 item if 0 or neg. */
+ res = 0;
+ } else {
+ max--;
+ res = max & 0xf;/* num bytes in last row */
+ max >>= 4; /* div by 16 */
+ max++; /* num of rows to print */
+ if (max > 20) { /* limit to 20 */
+ max = 20;
+ res = 0xf; /* 16 bytes print in last row */
+ }
+ }
+ } else {
+ max = 20;
+ res = 0xf;
+ }
+
+ pb = addr;
+ for (m=0; m<max; m++) {
+ printf("%10p ", pb);
+ for (n=0;n<=(m==(max-1)?res:0xf);n++)
+ printf("%02X%c",pb[n],n==7?'-':' ');
+ for (;n<=0xf;n++)
+ printf(" %c",n==7?'-':' ');
+ for (n=0;n<=(m==(max-1)?res:0xf);n++) {
+ printf("%c", isprint(pb[n]) ? pb[n] : '.');
+ }
+ printf("\n");
+ pb += 16;
+ }
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
+ "mdump", /* name */
+ "mdump [address [length]]", /* usage */
+ "mem", /* topic */
+ rtems_shell_main_mdump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
diff --git a/cpukit/libmisc/shell/main_medit.c b/cpukit/libmisc/shell/main_medit.c
new file mode 100644
index 0000000000..7905fbe689
--- /dev/null
+++ b/cpukit/libmisc/shell/main_medit.c
@@ -0,0 +1,79 @@
+/*
+ * MEDIT Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+extern int rtems_shell_main_mdump(int, char *);
+
+int rtems_shell_main_medit(
+ int argc,
+ char *argv[]
+)
+{
+ unsigned char *pb;
+ void *tmpp;
+ int n;
+ int i;
+
+ if ( argc < 3 ) {
+ fprintf(stderr,"%s: too few arguments\n", argv[0]);
+ return -1;
+ }
+
+ /*
+ * Convert arguments into numbers
+ */
+ if ( rtems_string_to_pointer(argv[1], &tmpp, NULL) ) {
+ printf( "Address argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ pb = tmpp;
+
+ /*
+ * Now edit the memory
+ */
+ n = 0;
+ for (i=2 ; i<=argc ; i++) {
+ unsigned char tmpc;
+
+ if ( rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) {
+ printf( "Value (%s) is not a number\n", argv[i] );
+ continue;
+ }
+
+ pb[n++] = tmpc;
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_MEDIT_Command = {
+ "medit", /* name */
+ "medit address value1 [value2 ...]", /* usage */
+ "mem", /* topic */
+ rtems_shell_main_medit, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mfill.c b/cpukit/libmisc/shell/main_mfill.c
new file mode 100644
index 0000000000..ecbaec4878
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mfill.c
@@ -0,0 +1,77 @@
+/*
+ * MFILL Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+int rtems_shell_main_mfill(
+ int argc,
+ char *argv[]
+)
+{
+ unsigned long tmp;
+ void *addr;
+ size_t size;
+ unsigned char value;
+
+ if ( argc != 4 ) {
+ fprintf(stderr,"%s: too few arguments\n", argv[0]);
+ return -1;
+ }
+
+ /*
+ * Convert arguments into numbers
+ */
+ if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
+ printf( "Address argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+
+ if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
+ printf( "Size argument (%s) is not a number\n", argv[2] );
+ return -1;
+ }
+ size = (size_t) tmp;
+
+ if ( rtems_string_to_unsigned_char(argv[3], &value, NULL, 0) ) {
+ printf( "Value argument (%s) is not a number\n", argv[3] );
+ return -1;
+ }
+
+ /*
+ * Now fill the memory.
+ */
+ memset(addr, size, value);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_MFILL_Command = {
+ "mfill", /* name */
+ "mfill address size value", /* usage */
+ "mem", /* topic */
+ rtems_shell_main_mfill, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mkdir.c b/cpukit/libmisc/shell/main_mkdir.c
new file mode 100644
index 0000000000..e191818923
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mkdir.c
@@ -0,0 +1,55 @@
+/*
+ * MKDIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_mkdir(
+ int argc,
+ char *argv[]
+)
+{
+ char *dir;
+ int n;
+
+ n = 1;
+ while (n<argc) {
+ dir = argv[n++];
+ if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
+ fprintf(stderr, "mkdir '%s' failed:%s\n", dir, strerror(errno));
+ }
+ }
+ return errno;
+}
+
+rtems_shell_cmd_t rtems_shell_MKDIR_Command = {
+ "mkdir", /* name */
+ "mkdir dir # make a directory", /* usage */
+ "files", /* topic */
+ rtems_shell_main_mkdir, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mknod.c b/cpukit/libmisc/shell/main_mknod.c
new file mode 100644
index 0000000000..e1ebb2a162
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mknod.c
@@ -0,0 +1,463 @@
+/* $NetBSD: mknod.c,v 1.39 2009/02/13 01:37:23 lukem Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#if 0
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1998\
+ The NetBSD Foundation, Inc. All rights reserved.");
+__RCSID("$NetBSD: mknod.c,v 1.39 2009/02/13 01:37:23 lukem Exp $");
+#endif /* not lint */
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#if !HAVE_NBTOOL_CONFIG_H && defined(KERN_DRIVERS)
+#include <sys/sysctl.h>
+#endif
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "mknod-pack_dev.h"
+
+#include <setjmp.h>
+
+typedef struct {
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_mknod_globals;
+
+#define exit_jump &(globals->exit_jmp)
+
+#define exit(ec) rtems_shell_mknod_exit(globals, ec)
+
+static int gid_name(const char *, gid_t *);
+static portdev_t callPack(rtems_shell_mknod_globals* globals,
+ pack_t *, int, u_long *);
+
+static int main_mknod(rtems_shell_mknod_globals*, int, char *[]);
+static void usage(rtems_shell_mknod_globals* );
+
+static void
+rtems_shell_mknod_exit (rtems_shell_mknod_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+#include "mknod-pack_dev.c"
+
+int
+rtems_shell_main_mknod(int argc, char *argv[])
+{
+ rtems_shell_mknod_globals mknod_globals;
+ rtems_shell_mknod_globals* globals = &mknod_globals;
+ memset (globals, 0, sizeof (mknod_globals));
+ mknod_globals.exit_code = 1;
+ if (setjmp (mknod_globals.exit_jmp) == 0)
+ return main_mknod (globals, argc, argv);
+ return mknod_globals.exit_code;
+}
+
+#define getprogname() "mknod"
+
+#ifdef KERN_DRIVERS
+#error invalid for RTEMS
+static struct kinfo_drivers *kern_drivers;
+static int num_drivers;
+
+static void get_device_info(void);
+static void print_device_info(char **);
+static int major_from_name(const char *, mode_t);
+#endif
+
+#define MAXARGS 3 /* 3 for bsdos, 2 for rest */
+
+int
+main_mknod(rtems_shell_mknod_globals* globals, int argc, char **argv)
+{
+ char *name, *p;
+ mode_t mode;
+ portdev_t dev;
+ pack_t *pack;
+ u_long numbers[MAXARGS];
+ int n, ch, fifo, hasformat;
+ int r_flag = 0; /* force: delete existing entry */
+#ifdef KERN_DRIVERS
+ int l_flag = 0; /* list device names and numbers */
+ int major;
+#endif
+#if RTEMS_REMOVED
+ void *modes = 0;
+#endif
+ uid_t uid = -1;
+ gid_t gid = -1;
+ int rval;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+ dev = 0;
+ fifo = hasformat = 0;
+ pack = pack_native;
+
+#ifdef KERN_DRIVERS
+ while ((ch = getopt(argc, argv, "lrRF:g:m:u:")) != -1) {
+#else
+ while ((ch = getopt_r(argc, argv, "rRF:g:m:u:", &getopt_reent)) != -1) {
+#endif
+ switch (ch) {
+
+#ifdef KERN_DRIVERS
+ case 'l':
+ l_flag = 1;
+ break;
+#endif
+
+ case 'r':
+ r_flag = 1;
+ break;
+
+ case 'R':
+ r_flag = 2;
+ break;
+
+ case 'F':
+ pack = pack_find(getopt_reent.optarg);
+ if (pack == NULL)
+ errx(exit_jump, 1, "invalid format: %s", getopt_reent.optarg);
+ hasformat++;
+ break;
+
+ case 'g':
+ if (getopt_reent.optarg[0] == '#') {
+ gid = strtol(getopt_reent.optarg + 1, &p, 10);
+ if (*p == 0)
+ break;
+ }
+ if (gid_name(getopt_reent.optarg, &gid) == 0)
+ break;
+ gid = strtol(getopt_reent.optarg, &p, 10);
+ if (*p == 0)
+ break;
+ errx(exit_jump, 1, "%s: invalid group name", getopt_reent.optarg);
+
+ case 'm':
+#if RTEMS_REMOVED
+ modes = setmode(getopt_reent.optarg);
+ if (modes == NULL)
+#endif
+ err(exit_jump, 1, "Cannot set file mode `%s'", getopt_reent.optarg);
+ break;
+
+ case 'u':
+ if (getopt_reent.optarg[0] == '#') {
+ uid = strtol(getopt_reent.optarg + 1, &p, 10);
+ if (*p == 0)
+ break;
+ }
+#if RTEMS_REMOVED
+ if (uid_from_user(getopt_reent.optarg, &uid) == 0)
+ break;
+#endif
+ uid = strtol(getopt_reent.optarg, &p, 10);
+ if (*p == 0)
+ break;
+ errx(exit_jump, 1, "%s: invalid user name", getopt_reent.optarg);
+
+ default:
+ case '?':
+ usage(globals);
+ }
+ }
+ argc -= getopt_reent.optind;
+ argv += getopt_reent.optind;
+
+#ifdef KERN_DRIVERS
+ if (l_flag) {
+ print_device_info(argv);
+ return 0;
+ }
+#endif
+
+ if (argc < 2 || argc > 10)
+ usage(globals);
+
+ name = *argv;
+ argc--;
+ argv++;
+
+ umask(mode = umask(0));
+ mode = (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) & ~mode;
+
+ if (argv[0][1] != '\0')
+ goto badtype;
+ switch (*argv[0]) {
+ case 'c':
+ mode |= S_IFCHR;
+ break;
+
+ case 'b':
+ mode |= S_IFBLK;
+ break;
+
+ case 'p':
+ if (hasformat)
+ errx(exit_jump, 1, "format is meaningless for fifos");
+ mode |= S_IFIFO;
+ fifo = 1;
+ break;
+
+ default:
+ badtype:
+ errx(exit_jump, 1, "node type must be 'b', 'c' or 'p'.");
+ }
+ argc--;
+ argv++;
+
+ if (fifo) {
+ if (argc != 0)
+ usage(globals);
+ } else {
+ if (argc < 1 || argc > MAXARGS)
+ usage(globals);
+ }
+
+ for (n = 0; n < argc; n++) {
+ errno = 0;
+ numbers[n] = strtoul(argv[n], &p, 0);
+ if (*p == 0 && errno == 0)
+ continue;
+#ifdef KERN_DRIVERS
+ if (n == 0) {
+ major = major_from_name(argv[0], mode);
+ if (major != -1) {
+ numbers[0] = major;
+ continue;
+ }
+ if (!isdigit(*(unsigned char *)argv[0]))
+ errx(1, "unknown driver: %s", argv[0]);
+ }
+#endif
+ errx(exit_jump, 1, "invalid number: %s", argv[n]);
+ }
+
+ switch (argc) {
+ case 0:
+ dev = 0;
+ break;
+
+ case 1:
+ dev = numbers[0];
+ break;
+
+ default:
+ dev = callPack(globals, pack, argc, numbers);
+ break;
+ }
+
+#if RTEMS_REMOVED
+ if (modes != NULL)
+ mode = getmode(modes, mode);
+#endif
+ umask(0);
+ rval = fifo ? mkfifo(name, mode) : mknod(name, mode, dev);
+ if (rval < 0 && errno == EEXIST && r_flag) {
+ struct stat sb;
+ if (lstat(name, &sb) != 0 || (!fifo && sb.st_rdev != dev))
+ sb.st_mode = 0;
+
+ if ((sb.st_mode & S_IFMT) == (mode & S_IFMT)) {
+ if (r_flag == 1)
+ /* Ignore permissions and user/group */
+ return 0;
+ if (sb.st_mode != mode)
+ rval = chmod(name, mode);
+ else
+ rval = 0;
+ } else {
+ unlink(name);
+ rval = fifo ? mkfifo(name, mode)
+ : mknod(name, mode, dev);
+ }
+ }
+ if (rval < 0)
+ err(exit_jump, 1, "%s", name);
+ if ((uid != (uid_t)-1 || gid != (uid_t)-1) && chown(name, uid, gid) == -1)
+ /* XXX Should we unlink the files here? */
+ warn("%s: uid/gid not changed", name);
+
+ return 0;
+}
+
+static void
+usage(rtems_shell_mknod_globals* globals)
+{
+ const char *progname = getprogname();
+
+ (void)fprintf(stderr,
+ "usage: %s [-rR] [-F format] [-m mode] [-u user] [-g group]\n",
+ progname);
+ (void)fprintf(stderr,
+#ifdef KERN_DRIVERS
+ " [ name [b | c] [major | driver] minor\n"
+#else
+ " [ name [b | c] major minor\n"
+#endif
+ " | name [b | c] major unit subunit\n"
+ " | name [b | c] number\n"
+ " | name p ]\n");
+#ifdef KERN_DRIVERS
+ (void)fprintf(stderr, " %s -l [driver] ...\n", progname);
+#endif
+ exit(1);
+}
+
+static int
+gid_name(const char *name, gid_t *gid)
+{
+ struct group *g;
+
+ g = getgrnam(name);
+ if (!g)
+ return -1;
+ *gid = g->gr_gid;
+ return 0;
+}
+
+static portdev_t
+callPack(rtems_shell_mknod_globals* globals, pack_t *f, int n, u_long *numbers)
+{
+ portdev_t d;
+ const char *error = NULL;
+
+ d = (*f)(n, numbers, &error);
+ if (error != NULL)
+ errx(exit_jump, 1, "%s", error);
+ return d;
+}
+
+#ifdef KERN_DRIVERS
+static void
+get_device_info(void)
+{
+ static int mib[2] = {CTL_KERN, KERN_DRIVERS};
+ size_t len;
+
+ if (sysctl(mib, 2, NULL, &len, NULL, 0) != 0)
+ err(1, "kern.drivers" );
+ kern_drivers = malloc(len);
+ if (kern_drivers == NULL)
+ err(1, "malloc");
+ if (sysctl(mib, 2, kern_drivers, &len, NULL, 0) != 0)
+ err(1, "kern.drivers" );
+
+ num_drivers = len / sizeof *kern_drivers;
+}
+
+static void
+print_device_info(char **names)
+{
+ int i;
+ struct kinfo_drivers *kd;
+
+ if (kern_drivers == NULL)
+ get_device_info();
+
+ do {
+ kd = kern_drivers;
+ for (i = 0; i < num_drivers; kd++, i++) {
+ if (*names && strcmp(*names, kd->d_name))
+ continue;
+ printf("%s", kd->d_name);
+ if (kd->d_cmajor != -1)
+ printf(" character major %d", kd->d_cmajor);
+ if (kd->d_bmajor != -1)
+ printf(" block major %d", kd->d_bmajor);
+ printf("\n");
+ }
+ } while (*names && *++names);
+}
+
+static int
+major_from_name(const char *name, mode_t mode)
+{
+ int i;
+ struct kinfo_drivers *kd;
+
+ if (kern_drivers == NULL)
+ get_device_info();
+
+ kd = kern_drivers;
+ for (i = 0; i < num_drivers; kd++, i++) {
+ if (strcmp(name, kd->d_name))
+ continue;
+ if (S_ISCHR(mode))
+ return kd->d_cmajor;
+ return kd->d_bmajor;
+ }
+ return -1;
+}
+#endif
+
+rtems_shell_cmd_t rtems_shell_MKNOD_Command = {
+ "mknod", /* name */
+ "mknod mknod [-rR] [-F fmt] [-m mode] name [c | b] minor", /* usage */
+ "files", /* topic */
+ rtems_shell_main_mknod, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mkrfs.c b/cpukit/libmisc/shell/main_mkrfs.c
new file mode 100644
index 0000000000..726b575b03
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mkrfs.c
@@ -0,0 +1,35 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include <rtems/shellconfig.h>
+#include <rtems/rtems-rfs-shell.h>
+#include <rtems/fsmount.h>
+#include "internal.h"
+
+#define OPTIONS "[-v] [-s blksz] [-b grpblk] [-i grpinode] [-I] [-o %inode]"
+
+rtems_shell_cmd_t rtems_shell_MKRFS_Command = {
+ "mkrfs", /* name */
+ "mkrfs " OPTIONS " dev", /* usage */
+ "files", /* topic */
+ rtems_shell_rfs_format, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mmove.c b/cpukit/libmisc/shell/main_mmove.c
new file mode 100644
index 0000000000..30c6629547
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mmove.c
@@ -0,0 +1,79 @@
+/*
+ * MMOVE Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+extern int rtems_shell_main_mdump(int, char *);
+
+int rtems_shell_main_mmove(
+ int argc,
+ char *argv[]
+)
+{
+ unsigned long tmp;
+ void *src;
+ void *dst;
+ size_t length;
+
+ if ( argc < 4 ) {
+ fprintf(stderr,"%s: too few arguments\n", argv[0]);
+ return -1;
+ }
+
+ /*
+ * Convert arguments into numbers
+ */
+ if ( rtems_string_to_pointer(argv[1], &dst, NULL) ) {
+ printf( "Destination argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+
+ if ( rtems_string_to_pointer(argv[2], &src, NULL) ) {
+ printf( "Source argument (%s) is not a number\n", argv[2] );
+ return -1;
+ }
+
+ if ( rtems_string_to_unsigned_long(argv[3], &tmp, NULL, 0) ) {
+ printf( "Length argument (%s) is not a number\n", argv[3] );
+ return -1;
+ }
+ length = (size_t) tmp;
+
+ /*
+ * Now copy the memory.
+ */
+ memcpy(dst, src, length);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_MMOVE_Command = {
+ "mmove", /* name */
+ "mmove dst src length", /* usage */
+ "mem", /* topic */
+ rtems_shell_main_mmove, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mount.c b/cpukit/libmisc/shell/main_mount.c
new file mode 100644
index 0000000000..b192a1668d
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mount.c
@@ -0,0 +1,133 @@
+/*
+ * Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include <rtems/libio.h>
+#include "internal.h"
+
+static bool print_filesystem(const rtems_filesystem_table_t *entry, void *arg)
+{
+ printf("%s ", entry->type);
+
+ return false;
+}
+
+int rtems_shell_main_mount(
+ int argc,
+ char *argv[]
+)
+{
+ rtems_filesystem_options_t options = RTEMS_FILESYSTEM_READ_WRITE;
+ char* type = NULL;
+ char* source = NULL;
+ char* target = NULL;
+ char* fsoptions = NULL;
+ int arg;
+
+ for (arg = 1; arg < argc; arg++) {
+ if (argv[arg][0] == '-') {
+ if (argv[arg][1] == 't') {
+ arg++;
+ if (arg == argc) {
+ fprintf(
+ stderr,
+ "%s: -t needs a type of file-system;; see -L.\n",
+ argv[0]
+ );
+ return 1;
+ }
+ type = argv[arg];
+ } else if (argv[arg][1] == 'r') {
+ options = RTEMS_FILESYSTEM_READ_ONLY;
+ } else if (argv[arg][1] == 'L') {
+ printf ("File systems: ");
+ rtems_filesystem_iterate(print_filesystem, NULL);
+ printf ("\n");
+ return 0;
+ } else if (argv[arg][1] == 'o') {
+ arg++;
+ if (arg == argc) {
+ fprintf(
+ stderr,
+ "%s: -o needs a list if filesystem options.\n",
+ argv[0]
+ );
+ return 1;
+ }
+ fsoptions = argv[arg];
+ } else {
+ fprintf (stderr, "unknown option: %s\n", argv[arg]);
+ return 1;
+ }
+ } else {
+ if (!source)
+ source = argv[arg];
+ else if (!target)
+ target = argv[arg];
+ else {
+ fprintf (
+ stderr, "mount: source and mount only require: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+ if (!type) {
+ fprintf (stderr, "mount: no file-system; see the -L option\n");
+ return 1;
+ }
+
+ if (!source) {
+ fprintf (stderr, "mount: no source\n");
+ return 1;
+ }
+
+ if (!target) {
+ fprintf (stderr, "mount: no mount point\n");
+ return 1;
+ }
+
+ /*
+ * Mount the disk.
+ */
+
+ if (mount (source, target, type, options, fsoptions) < 0) {
+ fprintf (stderr, "error: %s\n", strerror(errno));
+ return 1;
+ }
+
+ printf ("mounted %s -> %s\n", source, target);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_MOUNT_Command = {
+ "mount", /* name */
+ "mount [-t type] [-r] [-L] source target", /* usage */
+ "files", /* topic */
+ rtems_shell_main_mount, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mount_nfs.c b/cpukit/libmisc/shell/main_mount_nfs.c
new file mode 100644
index 0000000000..121d0ca6c2
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mount_nfs.c
@@ -0,0 +1,70 @@
+/*
+ * Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+#include <librtemsNfs.h>
+
+static int
+rtems_shell_nfs_mounter (
+ const char* device,
+ const char* mntpoint,
+ rtems_shell_filesystems_t* fs __attribute__((unused)),
+ rtems_filesystem_options_t options __attribute__((unused)))
+{
+ char* uidhost;
+ char* path;
+ int ret;
+
+ if (strchr (device, ':') == NULL) {
+ fprintf (stderr, "error: nfs mount device is [uid.gid@]host:path\n");
+ return -1;
+ }
+
+ if (rpcUdpInit () < 0) {
+ fprintf (stderr, "error: initialising RPC\n");
+ return -1;
+ }
+
+ nfsInit (0, 0);
+
+ uidhost = strdup (device);
+ path = strchr (uidhost, ':');
+ *path = '\0';
+ path++;
+
+ ret = nfsMount(uidhost, path, (char*) mntpoint);
+
+ free (uidhost);
+
+ return ret;
+}
+
+rtems_shell_filesystems_t rtems_shell_Mount_NFS = {
+ name: "nfs",
+ driver_needed: 1,
+ fs_ops: NULL,
+ mounter: rtems_shell_nfs_mounter
+};
diff --git a/cpukit/libmisc/shell/main_msdosfmt.c b/cpukit/libmisc/shell/main_msdosfmt.c
new file mode 100644
index 0000000000..c682e879eb
--- /dev/null
+++ b/cpukit/libmisc/shell/main_msdosfmt.c
@@ -0,0 +1,185 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include <rtems/shellconfig.h>
+#include <rtems/dosfs.h>
+#include <rtems/fsmount.h>
+#include "internal.h"
+
+int rtems_shell_main_msdos_format(
+ int argc,
+ char *argv[]
+)
+{
+ msdos_format_request_param_t rqdata = {
+ OEMName: "RTEMS",
+ VolLabel: "RTEMSDisk",
+ sectors_per_cluster: 0,
+ fat_num: 0,
+ files_per_root_dir: 0,
+ fattype: MSDOS_FMT_FATANY,
+ media: 0,
+ quick_format: TRUE,
+ cluster_align: 0,
+ info_level: 0
+ };
+
+ unsigned long tmp;
+ const char* driver = NULL;
+ int arg;
+
+ for (arg = 1; arg < argc; arg++) {
+ if (argv[arg][0] == '-') {
+ switch (argv[arg][1]) {
+ case 'V':
+ arg++;
+ if (arg == argc) {
+ fprintf (stderr, "error: no volume label.\n");
+ return 1;
+ }
+ rqdata.VolLabel = argv[arg];
+ break;
+
+ case 's':
+ arg++;
+ if (arg == argc) {
+ fprintf (stderr, "error: sectors per cluster count.\n");
+ return 1;
+ }
+
+ if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
+ printf(
+ "sector per cluster argument (%s) is not a number\n",
+ argv[arg]
+ );
+ return -1;
+ }
+
+ rqdata.sectors_per_cluster = (uint32_t) tmp;
+ break;
+
+ case 'r':
+ arg++;
+ if (arg == argc) {
+ fprintf (stderr, "error: no root directory size.\n");
+ return 1;
+ }
+
+ if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
+ printf(
+ "root directory size argument (%s) is not a number\n",
+ argv[arg]
+ );
+ return -1;
+ }
+
+ rqdata.files_per_root_dir = (uint32_t) tmp;
+ break;
+
+ case 't':
+ arg++;
+ if (arg == argc) {
+ fprintf (stderr, "error: no FAT type.\n");
+ return 1;
+ }
+
+ if (strcmp (argv[arg], "any") == 0)
+ rqdata.fattype = MSDOS_FMT_FATANY;
+ else if (strcmp (argv[arg], "12") == 0)
+ rqdata.fattype = MSDOS_FMT_FAT12;
+ else if (strcmp (argv[arg], "16") == 0)
+ rqdata.fattype = MSDOS_FMT_FAT16;
+ else if (strcmp (argv[arg], "32") == 0)
+ rqdata.fattype = MSDOS_FMT_FAT32;
+ else {
+ fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n");
+ return 1;
+ }
+ break;
+
+ case 'v':
+ rqdata.info_level++;
+ break;
+
+ default:
+ fprintf (stderr, "error: invalid option: %s\n", argv[arg]);
+ return 1;
+
+ }
+ } else {
+ if (!driver)
+ driver = argv[arg];
+ else {
+ fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+ if (!driver) {
+ fprintf (stderr, "error: no driver\n");
+ return 1;
+ }
+
+ printf ("msdos format: %s\n", driver);
+
+ if (rqdata.info_level)
+ {
+ printf (" %-20s: %s\n", "OEMName", "RTEMS");
+ printf (" %-20s: %s\n", "VolLabel", "RTEMSDisk");
+ printf (" %-20s: %" PRIu32 "\n", "sectors per cluster", rqdata.sectors_per_cluster);
+ printf (" %-20s: %" PRIu32 "\n", "fats", rqdata.fat_num);
+ printf (" %-20s: %" PRIu32 "\n", "files per root dir", rqdata.files_per_root_dir);
+ printf (" %-20s: %i\n", "fat type", rqdata.fattype);
+ printf (" %-20s: %d\n", "media", rqdata.media);
+ printf (" %-20s: %d\n", "quick_format", rqdata.quick_format);
+ printf (" %-20s: %" PRIu32 "\n", "cluster align", rqdata.cluster_align);
+ }
+
+ if (msdos_format (driver, &rqdata) < 0) {
+ fprintf (stderr, "error: format failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ printf ("msdos format successful\n");
+
+ return 0;
+}
+
+#define OPTIONS "[-v label] [-r size] [-t any/12/16/32]"
+
+rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = {
+ "mkdos", /* name */
+ "mkdos " OPTIONS " path # format disk", /* usage */
+ "files", /* topic */
+ rtems_shell_main_msdos_format, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
+rtems_shell_cmd_t rtems_shell_MSDOSFMT_Alias = {
+ "msdosfmt", /* name */
+ NULL, /* usage */
+ "files", /* topic */
+ NULL, /* command */
+ &rtems_shell_MSDOSFMT_Command, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mv.c b/cpukit/libmisc/shell/main_mv.c
new file mode 100644
index 0000000000..644900bc17
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mv.c
@@ -0,0 +1,491 @@
+/* $NetBSD: mv.c,v 1.41 2008/07/20 00:52:40 lukem Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ken Smith of The State University of New York at Buffalo.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
+ The Regents of the University of California. All rights reserved.");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
+#else
+__RCSID("$NetBSD: mv.c,v 1.41 2008/07/20 00:52:40 lukem Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <locale.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "pathnames-mv.h"
+
+/* RTEMS specific changes */
+typedef struct {
+ int fflg, iflg, vflg;
+ int stdin_ok;
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_mv_globals;
+
+int copy(char *, char *);
+int do_move(char *, char *);
+int fastcopy(char *, char *, struct stat *);
+void usage(void);
+int main(int, char *[]);
+
+#define fflg globals->fflg
+#define iflg globals->iflg
+#define vflg globals->vflg
+#define stdin_ok globals->stdin_ok
+#define exit_jump &(globals->exit_jmp)
+
+#include <setjmp.h>
+
+#define exit(ec) rtems_shell_mv_exit(globals, ec)
+
+void
+rtems_shell_mv_exit (rtems_shell_mv_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+void strmode(mode_t mode, char *p);
+const char *user_from_uid(uid_t uid, int nouser);
+char *group_from_gid(gid_t gid, int nogroup);
+
+static int main_mv(rtems_shell_mv_globals* globals, int argc, char *argv[]);
+
+int rtems_shell_main_cp(int argc, char *argv[]);
+int rtems_shell_main_rm(int argc, char *argv[]);
+
+int
+rtems_shell_main_mv(int argc, char *argv[])
+{
+ rtems_shell_mv_globals mv_globals;
+ memset (&mv_globals, 0, sizeof (mv_globals));
+ mv_globals.exit_code = 1;
+ if (setjmp (mv_globals.exit_jmp) == 0)
+ return main_mv (&mv_globals, argc, argv);
+ return mv_globals.exit_code;
+}
+
+#define do_move(a1, a2) do_move_mv(globals, a1, a2)
+#define fastcopy(a1, a2, a3) fastcopy_mv(globals, a1, a2, a3)
+#define copy(a1, a2) copy_mv(globals, a1, a2)
+#define usage() usage_mv(globals)
+
+static int do_move_mv(rtems_shell_mv_globals* globals, char *from, char *to);
+static int fastcopy_mv(rtems_shell_mv_globals* globals,
+ char *from, char *to, struct stat *sbp);
+static int copy_mv(rtems_shell_mv_globals* globals, char *from, char *to);
+static void usage_mv(rtems_shell_mv_globals* globals);
+
+/* RTEMS changes */
+
+int
+main_mv(rtems_shell_mv_globals* globals, int argc, char *argv[])
+{
+ int ch, len, rval;
+ char *p, *endp;
+ struct stat sb;
+ char path[MAXPATHLEN + 1];
+ size_t baselen;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+/* setprogname(argv[0]); */
+
+ (void)setlocale(LC_ALL, "");
+
+ while ((ch = getopt_r(argc, argv, "ifv", &getopt_reent)) != -1)
+ switch (ch) {
+ case 'i':
+ fflg = 0;
+ iflg = 1;
+ break;
+ case 'f':
+ iflg = 0;
+ fflg = 1;
+ break;
+ case 'v':
+ vflg = 1;
+ break;
+ default:
+ usage();
+ }
+ argc -= getopt_reent.optind;
+ argv += getopt_reent.optind;
+
+ if (argc < 2)
+ usage();
+
+ stdin_ok = isatty(STDIN_FILENO);
+
+ /*
+ * If the stat on the target fails or the target isn't a directory,
+ * try the move. More than 2 arguments is an error in this case.
+ */
+ if (stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) {
+ if (argc > 2)
+ usage();
+ exit(do_move(argv[0], argv[1]));
+ }
+
+ /* It's a directory, move each file into it. */
+ baselen = strlcpy(path, argv[argc - 1], sizeof(path));
+ if (baselen >= sizeof(path))
+ errx(exit_jump, 1, "%s: destination pathname too long", argv[argc - 1]);
+ endp = &path[baselen];
+ if (!baselen || *(endp - 1) != '/') {
+ *endp++ = '/';
+ ++baselen;
+ }
+ for (rval = 0; --argc; ++argv) {
+ p = *argv + strlen(*argv) - 1;
+ while (*p == '/' && p != *argv)
+ *p-- = '\0';
+ if ((p = strrchr(*argv, '/')) == NULL)
+ p = *argv;
+ else
+ ++p;
+
+ if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
+ warnx("%s: destination pathname too long", *argv);
+ rval = 1;
+ } else {
+ memmove(endp, p, len + 1);
+ if (do_move(*argv, path))
+ rval = 1;
+ }
+ }
+ return rval;
+}
+
+int
+do_move_mv(rtems_shell_mv_globals* globals, char *from, char *to)
+{
+ struct stat sb;
+ char modep[15];
+
+ /*
+ * (1) If the destination path exists, the -f option is not specified
+ * and either of the following conditions are true:
+ *
+ * (a) The permissions of the destination path do not permit
+ * writing and the standard input is a terminal.
+ * (b) The -i option is specified.
+ *
+ * the mv utility shall write a prompt to standard error and
+ * read a line from standard input. If the response is not
+ * affirmative, mv shall do nothing more with the current
+ * source file...
+ */
+ if (!fflg && !access(to, F_OK)) {
+ int ask = 1;
+ int ch;
+
+ if (iflg) {
+ if (access(from, F_OK)) {
+ warn("rename %s", from);
+ return (1);
+ }
+ (void)fprintf(stderr, "overwrite %s? ", to);
+ } else if (stdin_ok && access(to, W_OK) && !stat(to, &sb)) {
+ if (access(from, F_OK)) {
+ warn("rename %s", from);
+ return (1);
+ }
+ strmode(sb.st_mode, modep);
+ (void)fprintf(stderr, "override %s%s%s/%s for %s? ",
+ modep + 1, modep[9] == ' ' ? "" : " ",
+ user_from_uid(sb.st_uid, 0),
+ group_from_gid(sb.st_gid, 0), to);
+ } else
+ ask = 0;
+ if (ask) {
+ if ((ch = getchar()) != EOF && ch != '\n') {
+ int ch2;
+ while ((ch2 = getchar()) != EOF && ch2 != '\n')
+ continue;
+ }
+ if (ch != 'y' && ch != 'Y')
+ return (0);
+ }
+ }
+
+ /*
+ * (2) If rename() succeeds, mv shall do nothing more with the
+ * current source file. If it fails for any other reason than
+ * EXDEV, mv shall write a diagnostic message to the standard
+ * error and do nothing more with the current source file.
+ *
+ * (3) If the destination path exists, and it is a file of type
+ * directory and source_file is not a file of type directory,
+ * or it is a file not of type directory, and source file is
+ * a file of type directory, mv shall write a diagnostic
+ * message to standard error, and do nothing more with the
+ * current source file...
+ */
+ if (!rename(from, to)) {
+ if (vflg)
+ printf("%s -> %s\n", from, to);
+ return (0);
+ }
+
+ if (errno != EXDEV) {
+ warn("rename %s to %s", from, to);
+ return (1);
+ }
+
+ /*
+ * (4) If the destination path exists, mv shall attempt to remove it.
+ * If this fails for any reason, mv shall write a diagnostic
+ * message to the standard error and do nothing more with the
+ * current source file...
+ */
+ if (!lstat(to, &sb)) {
+ if ((S_ISDIR(sb.st_mode)) ? rmdir(to) : unlink(to)) {
+ warn("can't remove %s", to);
+ return (1);
+ }
+ }
+
+ /*
+ * (5) The file hierarchy rooted in source_file shall be duplicated
+ * as a file hierarchy rooted in the destination path...
+ */
+ if (lstat(from, &sb)) {
+ warn("%s", from);
+ return (1);
+ }
+
+ return (S_ISREG(sb.st_mode) ?
+ fastcopy(from, to, &sb) : copy(from, to));
+}
+
+int
+fastcopy_mv(rtems_shell_mv_globals* globals, char *from, char *to, struct stat *sbp)
+{
+ struct timeval tval[2];
+ uint32_t blen;
+ static char *bp;
+ int nread, from_fd, to_fd;
+
+ blen = 0;
+
+ if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
+ warn("%s", from);
+ return (1);
+ }
+ if ((to_fd =
+ open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
+ warn("%s", to);
+ (void)close(from_fd);
+ return (1);
+ }
+ if (!blen && !(bp = malloc(blen = sbp->st_blksize))) {
+ warn(NULL);
+ blen = 0;
+ (void)close(from_fd);
+ (void)close(to_fd);
+ return (1);
+ }
+ while ((nread = read(from_fd, bp, blen)) > 0)
+ if (write(to_fd, bp, nread) != nread) {
+ warn("%s", to);
+ goto err;
+ }
+ if (nread < 0) {
+ warn("%s", from);
+err: if (unlink(to))
+ warn("%s: remove", to);
+ (void)free(bp);
+ (void)close(from_fd);
+ (void)close(to_fd);
+ return (1);
+ }
+
+ (void)free(bp);
+ (void)close(from_fd);
+#ifdef xBSD4_4
+ TIMESPEC_TO_TIMEVAL(&tval[0], &sbp->st_atimespec);
+ TIMESPEC_TO_TIMEVAL(&tval[1], &sbp->st_mtimespec);
+#else
+ tval[0].tv_sec = sbp->st_atime;
+ tval[1].tv_sec = sbp->st_mtime;
+ tval[0].tv_usec = 0;
+ tval[1].tv_usec = 0;
+#endif
+#if 0
+#ifdef _SRV5
+ if (utimes(to, tval))
+#else
+ if (futimes(to_fd, tval))
+#endif
+ warn("%s: set times", to);
+#endif
+ if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
+ if (errno != EPERM)
+ warn("%s: set owner/group", to);
+ sbp->st_mode &= ~(S_ISUID | S_ISGID);
+ }
+ if (fchmod(to_fd, sbp->st_mode))
+ warn("%s: set mode", to);
+#if 0
+ if (fchflags(to_fd, sbp->st_flags) && (errno != EOPNOTSUPP))
+ warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
+#endif
+ if (close(to_fd)) {
+ warn("%s", to);
+ return (1);
+ }
+
+ if (unlink(from)) {
+ warn("%s: remove", from);
+ return (1);
+ }
+
+ if (vflg)
+ printf("%s -> %s\n", from, to);
+
+ return (0);
+}
+
+int
+copy_mv(rtems_shell_mv_globals* globals, char *from, char *to)
+{
+ char* cp_argv[5] = { "mv", vflg ? "-PRpv" : "-PRp", "--", from, to };
+ char* rm_argv[4] = { "mv", "-rf", "--", from };
+ int result;
+
+ result = rtems_shell_main_cp(5, cp_argv);
+ if (result) {
+ warnx("%s: did not terminate normally", _PATH_CP);
+ return (1);
+ }
+ result = rtems_shell_main_rm(4, rm_argv);
+ if (result) {
+ warnx("%s: did not terminate normally", _PATH_RM);
+ return (1);
+ }
+#if 0
+ pid_t pid;
+ int status;
+
+ if ((pid = vfork()) == 0) {
+ execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", "--", from, to, NULL);
+ warn("%s", _PATH_CP);
+ _exit(1);
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ warn("%s: waitpid", _PATH_CP);
+ return (1);
+ }
+ if (!WIFEXITED(status)) {
+ warnx("%s: did not terminate normally", _PATH_CP);
+ return (1);
+ }
+ if (WEXITSTATUS(status)) {
+ warnx("%s: terminated with %d (non-zero) status",
+ _PATH_CP, WEXITSTATUS(status));
+ return (1);
+ }
+ if (!(pid = vfork())) {
+ execl(_PATH_RM, "mv", "-rf", "--", from, NULL);
+ warn("%s", _PATH_RM);
+ _exit(1);
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ warn("%s: waitpid", _PATH_RM);
+ return (1);
+ }
+ if (!WIFEXITED(status)) {
+ warnx("%s: did not terminate normally", _PATH_RM);
+ return (1);
+ }
+ if (WEXITSTATUS(status)) {
+ warnx("%s: terminated with %d (non-zero) status",
+ _PATH_RM, WEXITSTATUS(status));
+ return (1);
+ }
+#endif
+ return (0);
+}
+
+void
+usage_mv(rtems_shell_mv_globals* globals)
+{
+ (void)fprintf(stderr, "usage: %s [-fiv] source target\n"
+ " %s [-fiv] source ... directory\n",
+ "mv", "mv");
+ exit(1);
+ /* NOTREACHED */
+}
+
+rtems_shell_cmd_t rtems_shell_MV_Command = {
+ "mv", /* name */
+ "[-fiv] source target ...", /* usage */
+ "files", /* topic */
+ rtems_shell_main_mv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_mwdump.c b/cpukit/libmisc/shell/main_mwdump.c
new file mode 100644
index 0000000000..f3e3cfc27b
--- /dev/null
+++ b/cpukit/libmisc/shell/main_mwdump.c
@@ -0,0 +1,95 @@
+/*
+ * MWDUMP Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+int rtems_shell_main_mwdump(
+ int argc,
+ char *argv[]
+)
+{
+ unsigned char n;
+ unsigned char m;
+ int max;
+ int res;
+ void *addr = 0;
+ unsigned char *pb;
+
+ if ( argc > 1 ) {
+ if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
+ printf( "Address argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ }
+
+ if ( argc > 2 ) {
+ if ( rtems_string_to_int(argv[2], &max, NULL, 0) ) {
+ printf( "Address argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+
+ if (max <= 0) {
+ max = 1; /* print 1 item if 0 or neg. */
+ res = 0;
+ } else {
+ max--;
+ res = max & 0xf;/* num bytes in last row */
+ max >>= 4; /* div by 16 */
+ max++; /* num of rows to print */
+ if (max > 20) { /* limit to 20 */
+ max = 20;
+ res = 0xf; /* 16 bytes print in last row */
+ }
+ }
+ } else {
+ max = 20;
+ res = 0xf;
+ }
+
+ pb = addr;
+ for (m=0;m<max;m++) {
+ printf("%10p ", pb);
+ for (n=0;n<=(m==(max-1)?res:0xf);n+=2)
+ printf("%04X%c",*((unsigned short*)(pb+n)),n==6?'-':' ');
+ for (;n<=0xf;n+=2)
+ printf(" %c", n==6?'-':' ');
+ for (n=0;n<=(m==(max-1)?res:0xf);n++) {
+ printf("%c", isprint(pb[n]) ? pb[n] : '.');
+ }
+ printf("\n");
+ pb += 16;
+ }
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_WDUMP_Command = {
+ "wdump", /* name */
+ "wdump [address [length]]", /* usage */
+ "mem", /* topic */
+ rtems_shell_main_mwdump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_netstats.c b/cpukit/libmisc/shell/main_netstats.c
new file mode 100644
index 0000000000..cc9b95a52c
--- /dev/null
+++ b/cpukit/libmisc/shell/main_netstats.c
@@ -0,0 +1,138 @@
+/*
+ * Network Statistics Shell Command Implmentation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+static void netstats_usage(void)
+{
+ printf(
+ "netstats [-vAimfpcut] where:\n"
+ " -A print All statistics\n"
+ " -i print Inet Routes\n"
+ " -m print MBUF Statistics\n"
+ " -f print IF Statistics\n"
+ " -p print IP Statistics\n"
+ " -c print ICMP Statistics\n"
+ " -u print UDP Statistics\n"
+ " -t print TCP Statistics\n"
+ );
+}
+
+int rtems_shell_main_netstats( /* command */
+ int argc,
+ char *argv[]
+)
+{
+ int option;
+ int doAll = 0;
+ int doInetRoutes = 0;
+ int doMBUFStats = 0;
+ int doIFStats = 0;
+ int doIPStats = 0;
+ int doICMPStats = 0;
+ int doUDPStats = 0;
+ int doTCPStats = 0;
+ int verbose = 0;
+ struct getopt_data getopt_reent;
+
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+ while ( (option = getopt_r( argc, argv, "Aimfpcutv", &getopt_reent)) != -1 ) {
+
+ switch ((char)option) {
+ case 'A': doAll = 1; break;
+ case 'i': doInetRoutes = 1; break;
+ case 'm': doMBUFStats = 1; break;
+ case 'f': doIFStats = 1; break;
+ case 'p': doIPStats = 1; break;
+ case 'c': doICMPStats = 1; break;
+ case 'u': doUDPStats = 1; break;
+ case 't': doTCPStats = 1; break;
+ case 'v': verbose = 1; break;
+ case '?':
+ default:
+ netstats_usage();
+ return -1;
+ }
+ }
+
+ if ( verbose ) {
+ printf(
+ "doAll=%d\n"
+ "doInetRoutes=%d\n"
+ "doMBUFStats=%d\n"
+ "doIFStats=%d\n"
+ "doIPStats=%d\n"
+ "doICMPStats=%d\n"
+ "doUDPStats=%d\n"
+ "doTCPStats=%d\n",
+ doAll,
+ doInetRoutes,
+ doMBUFStats,
+ doIFStats,
+ doIPStats,
+ doICMPStats,
+ doUDPStats,
+ doTCPStats
+ );
+ }
+
+ if ( doInetRoutes == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_inet_routes();
+ }
+
+ if ( doMBUFStats == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_mbuf_stats();
+ }
+
+ if ( doIFStats == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_if_stats();
+ }
+
+ if ( doIPStats == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_ip_stats();
+ }
+
+ if ( doICMPStats == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_icmp_stats();
+ }
+
+ if ( doUDPStats == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_udp_stats();
+ }
+
+ if ( doTCPStats == 1 || doAll == 1 ) {
+ rtems_bsdnet_show_tcp_stats();
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_NETSTATS_Command = {
+ "netstats", /* name */
+ "netstats [-Aimfpcutv]", /* usage */
+ "network", /* topic */
+ rtems_shell_main_netstats, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_perioduse.c b/cpukit/libmisc/shell/main_perioduse.c
new file mode 100644
index 0000000000..d0f123af1c
--- /dev/null
+++ b/cpukit/libmisc/shell/main_perioduse.c
@@ -0,0 +1,63 @@
+/*
+ * perioduse Command Implementation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_perioduse(
+ int argc,
+ char *argv[]
+)
+{
+ /*
+ * When invoked with no arguments, print the report.
+ */
+ if ( argc == 1 ) {
+ rtems_rate_monotonic_report_statistics_with_plugin(
+ stdout,
+ (rtems_printk_plugin_t)fprintf
+ );
+ return 0;
+ }
+
+ /*
+ * When invoked with the single argument -r, reset the statistics.
+ */
+ if ( argc == 2 && !strcmp( argv[1], "-r" ) ) {
+ printf( "Resetting Period Usage information\n" );
+ rtems_rate_monotonic_reset_all_statistics();
+ return 0;
+ }
+
+ /*
+ * OK. The user did something wrong.
+ */
+ fprintf( stderr, "%s: [-r]\n", argv[0] );
+ return -1;
+}
+
+rtems_shell_cmd_t rtems_shell_PERIODUSE_Command = {
+ "perioduse", /* name */
+ "[-r] print or reset per period usage", /* usage */
+ "rtems", /* topic */
+ rtems_shell_main_perioduse, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_pwd.c b/cpukit/libmisc/shell/main_pwd.c
new file mode 100644
index 0000000000..3a298f8242
--- /dev/null
+++ b/cpukit/libmisc/shell/main_pwd.c
@@ -0,0 +1,45 @@
+/*
+ * PWD Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_pwd(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ char dir[1024];
+
+ getcwd(dir,1024);
+ puts(dir);
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_PWD_Command = {
+ "pwd", /* name */
+ "pwd # print work directory", /* usage */
+ "files", /* topic */
+ rtems_shell_main_pwd, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_rm.c b/cpukit/libmisc/shell/main_rm.c
new file mode 100644
index 0000000000..465a0daf46
--- /dev/null
+++ b/cpukit/libmisc/shell/main_rm.c
@@ -0,0 +1,709 @@
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#ifndef lint
+static const char copyright[] =
+"@(#) Copyright (c) 1990, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94";
+#endif /* not lint */
+#endif
+#if 0
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.58 2006/10/31 02:22:36 delphij Exp $");
+#endif
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define rindex(s,c) strrchr(s,c)
+
+/* RTEMS specific changes */
+typedef struct {
+ int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
+ int rflag, Iflag;
+ uid_t uid;
+ int exit_code;
+ jmp_buf exit_jmp;
+} rtems_shell_rm_globals;
+
+#define dflag globals->dflag
+#define eval globals->eval
+#define fflag globals->fflag
+#define iflag globals->iflag
+#define Pflag globals->Pflag
+#define vflag globals->vflag
+#define Wflag globals->Wflag
+#define stdin_ok globals->stdin_ok
+#define rflag globals->rflag
+#define Iflag globals->Iflag
+#define xuid globals->uid
+#define exit_jump &(globals->exit_jmp)
+
+#include <setjmp.h>
+
+#define exit(ec) rtems_shell_rm_exit(globals, ec)
+void
+rtems_shell_rm_exit (rtems_shell_rm_globals* globals, int code)
+{
+ globals->exit_code = code;
+ longjmp (globals->exit_jmp, 1);
+}
+
+static int main_rm(rtems_shell_rm_globals* globals, int argc, char *argv[]);
+
+int
+rtems_shell_main_rm(int argc, char *argv[])
+{
+ rtems_shell_rm_globals rm_globals;
+ memset (&rm_globals, 0, sizeof (rm_globals));
+ rm_globals.exit_code = 1;
+ if (setjmp (rm_globals.exit_jmp) == 0)
+ return main_rm (&rm_globals, argc, argv);
+ return rm_globals.exit_code;
+}
+
+#define check(a1, a2, a3) check_rm(globals, a1, a2, a3)
+#define check2(a1) check2_rm(globals, a1)
+#define checkdot(a1) checkdot_rm(globals, a1)
+#define checkslash(a1) checkslash_rm(globals, a1)
+#define rm_file(a1) rm_file_rm(globals, a1)
+#define rm_overwrite(a1, a2) rm_overwrite_rm(globals, a1, a2)
+#define rm_tree(a1) rm_tree_rm(globals, a1)
+#define usage() usage_rm(globals)
+
+
+/* RTEMS changes */
+
+static int check_rm(rtems_shell_rm_globals* globals, char *, char *, struct stat *);
+static int check2_rm(rtems_shell_rm_globals* globals, char **);
+static void checkdot_rm(rtems_shell_rm_globals* globals, char **);
+static void checkslash_rm(rtems_shell_rm_globals* globals, char **);
+static void rm_file_rm(rtems_shell_rm_globals* globals, char **);
+static int rm_overwrite_rm(rtems_shell_rm_globals* globals, char *, struct stat *);
+static void rm_tree_rm(rtems_shell_rm_globals* globals, char **);
+static void usage_rm(rtems_shell_rm_globals* globals);
+
+/*
+ * rm --
+ * This rm is different from historic rm's, but is expected to match
+ * POSIX 1003.2 behavior. The most visible difference is that -f
+ * has two specific effects now, ignore non-existent files and force
+ * file removal.
+ */
+int
+main_rm(rtems_shell_rm_globals* globals, int argc, char *argv[])
+{
+ int ch;
+ char *p;
+
+ struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+ /*
+ * Test for the special case where the utility is called as
+ * "unlink", for which the functionality provided is greatly
+ * simplified.
+ */
+ if ((p = rindex(argv[0], '/')) == NULL)
+ p = argv[0];
+ else
+ ++p;
+ if (strcmp(p, "unlink") == 0) {
+ while (getopt_r(argc, argv, "", &getopt_reent) != -1)
+ usage();
+ argc -= getopt_reent.optind;
+ argv += getopt_reent.optind;
+ if (argc != 1)
+ usage();
+ rm_file(&argv[0]);
+ exit(eval);
+ }
+
+ Pflag = rflag = 0;
+ while ((ch = getopt_r(argc, argv, "dfiIPRrvW", &getopt_reent)) != -1)
+ switch(ch) {
+ case 'd':
+ dflag = 1;
+ break;
+ case 'f':
+ fflag = 1;
+ iflag = 0;
+ break;
+ case 'i':
+ fflag = 0;
+ iflag = 1;
+ break;
+ case 'I':
+ Iflag = 1;
+ break;
+ case 'P':
+ Pflag = 1;
+ break;
+ case 'R':
+ case 'r': /* Compatibility. */
+ rflag = 1;
+ break;
+ case 'v':
+ vflag = 1;
+ break;
+ case 'W':
+ Wflag = 1;
+ break;
+ default:
+ usage();
+ }
+ argc -= getopt_reent.optind;
+ argv += getopt_reent.optind;
+
+ if (argc < 1) {
+ if (fflag)
+ return (0);
+ usage();
+ }
+
+ checkdot(argv);
+ if (getenv("POSIXLY_CORRECT") == NULL)
+ checkslash(argv);
+ xuid = geteuid();
+
+ if (*argv) {
+ stdin_ok = isatty(STDIN_FILENO);
+
+ if (Iflag) {
+ if (check2(argv) == 0)
+ exit (1);
+ }
+ if (rflag)
+ rm_tree(argv);
+ else
+ rm_file(argv);
+ }
+
+ exit (eval);
+ return 0;
+}
+
+void
+rm_tree_rm(rtems_shell_rm_globals* globals, char **argv)
+{
+ FTS *fts;
+ FTSENT *p;
+ int needstat;
+ int flags;
+ int rval;
+
+ /*
+ * Remove a file hierarchy. If forcing removal (-f), or interactive
+ * (-i) or can't ask anyway (stdin_ok), don't stat the file.
+ */
+ needstat = !xuid || (!fflag && !iflag && stdin_ok);
+
+ /*
+ * If the -i option is specified, the user can skip on the pre-order
+ * visit. The fts_number field flags skipped directories.
+ */
+#define SKIPPED 1
+
+ flags = FTS_PHYSICAL;
+ if (!needstat)
+ flags |= FTS_NOSTAT;
+ if (Wflag)
+ flags |= FTS_WHITEOUT;
+ if (!(fts = fts_open(argv, flags, NULL))) {
+ if (fflag && errno == ENOENT)
+ return;
+ err(exit_jump, 1, "fts_open");
+ }
+ while ((p = fts_read(fts)) != NULL) {
+ switch (p->fts_info) {
+ case FTS_DNR:
+ if (!fflag || p->fts_errno != ENOENT) {
+ warnx("%s: %s",
+ p->fts_path, strerror(p->fts_errno));
+ eval = 1;
+ }
+ continue;
+ case FTS_ERR:
+ errx(exit_jump, 1, "%s: %s", p->fts_path, strerror(p->fts_errno));
+ case FTS_NS:
+ /*
+ * Assume that since fts_read() couldn't stat the
+ * file, it can't be unlinked.
+ */
+ if (!needstat)
+ break;
+ if (!fflag || p->fts_errno != ENOENT) {
+ warnx("%s: %s",
+ p->fts_path, strerror(p->fts_errno));
+ eval = 1;
+ }
+ continue;
+ case FTS_D:
+ /* Pre-order: give user chance to skip. */
+ if (!fflag && !check(p->fts_path, p->fts_accpath,
+ p->fts_statp)) {
+ (void)fts_set(fts, p, FTS_SKIP);
+ p->fts_number = SKIPPED;
+ }
+#if RTEMS_REMOVED
+ else if (!xuid &&
+ (p->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
+ !(p->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
+ chflags(p->fts_accpath,
+ p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)) < 0)
+ goto err;
+#endif
+ continue;
+ case FTS_DP:
+ /* Post-order: see if user skipped. */
+ if (p->fts_number == SKIPPED)
+ continue;
+ break;
+ default:
+ if (!fflag &&
+ !check(p->fts_path, p->fts_accpath, p->fts_statp))
+ continue;
+ }
+
+ rval = 0;
+#if RTEMS_REMOVED
+ if (!xuid &&
+ (p->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
+ !(p->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)))
+ rval = chflags(p->fts_accpath,
+ p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
+#endif
+ if (rval == 0) {
+ /*
+ * If we can't read or search the directory, may still be
+ * able to remove it. Don't print out the un{read,search}able
+ * message unless the remove fails.
+ */
+ switch (p->fts_info) {
+ case FTS_DP:
+ case FTS_DNR:
+ rval = rmdir(p->fts_accpath);
+ if (rval == 0 || (fflag && errno == ENOENT)) {
+ if (rval == 0 && vflag)
+ (void)printf("%s\n",
+ p->fts_path);
+ continue;
+ }
+ break;
+
+#if RTEMS_REMOVED
+ case FTS_W:
+ rval = undelete(p->fts_accpath);
+ if (rval == 0 && (fflag && errno == ENOENT)) {
+ if (vflag)
+ (void)printf("%s\n",
+ p->fts_path);
+ continue;
+ }
+ break;
+#endif
+
+ case FTS_NS:
+ /*
+ * Assume that since fts_read() couldn't stat
+ * the file, it can't be unlinked.
+ */
+ if (fflag)
+ continue;
+ /* FALLTHROUGH */
+ default:
+ if (Pflag)
+ if (!rm_overwrite(p->fts_accpath, NULL))
+ continue;
+ rval = unlink(p->fts_accpath);
+ if (rval == 0 || (fflag && errno == ENOENT)) {
+ if (rval == 0 && vflag)
+ (void)printf("%s\n",
+ p->fts_path);
+ continue;
+ }
+ }
+ }
+#if RTEMS_REMOVED
+err:
+#endif
+ warn("%s", p->fts_path);
+ eval = 1;
+ }
+ if (errno)
+ err(exit_jump, 1, "fts_read");
+ fts_close(fts);
+}
+
+#define S_ISWHT(m) (0)
+
+void
+rm_file_rm(rtems_shell_rm_globals* globals, char **argv)
+{
+ struct stat sb;
+ int rval;
+ char *f;
+
+ /*
+ * Remove a file. POSIX 1003.2 states that, by default, attempting
+ * to remove a directory is an error, so must always stat the file.
+ */
+ while ((f = *argv++) != NULL) {
+ /* Assume if can't stat the file, can't unlink it. */
+ if (lstat(f, &sb)) {
+#if RTEMS_REMOVED
+ if (Wflag) {
+ sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR;
+ } else {
+#endif
+ if (!fflag || errno != ENOENT) {
+ warn("%s", f);
+ eval = 1;
+ }
+ continue;
+#if RTEMS_REMOVED
+ }
+#endif
+ } else if (Wflag) {
+ warnx("%s: %s", f, strerror(EEXIST));
+ eval = 1;
+ continue;
+ }
+
+ if (S_ISDIR(sb.st_mode) && !dflag) {
+ warnx("%s: is a directory", f);
+ eval = 1;
+ continue;
+ }
+ if (!fflag && !S_ISWHT(sb.st_mode) && !check(f, f, &sb))
+ continue;
+ rval = 0;
+#if RTEMS_REMOVED
+ if (!xuid && !S_ISWHT(sb.st_mode) &&
+ (sb.st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
+ !(sb.st_flags & (SF_APPEND|SF_IMMUTABLE)))
+ rval = chflags(f, sb.st_flags & ~(UF_APPEND|UF_IMMUTABLE));
+#endif
+ if (rval == 0) {
+ if (S_ISWHT(sb.st_mode))
+#if RTEMS_REMOVED
+ rval = undelete(f);
+#endif
+ ;
+ else if (S_ISDIR(sb.st_mode))
+ rval = rmdir(f);
+ else {
+ if (Pflag)
+ if (!rm_overwrite(f, &sb))
+ continue;
+ rval = unlink(f);
+ }
+ }
+ if (rval && (!fflag || errno != ENOENT)) {
+ warn("%s", f);
+ eval = 1;
+ }
+ if (vflag && rval == 0)
+ (void)printf("%s\n", f);
+ }
+}
+
+/*
+ * rm_overwrite --
+ * Overwrite the file 3 times with varying bit patterns.
+ *
+ * XXX
+ * This is a cheap way to *really* delete files. Note that only regular
+ * files are deleted, directories (and therefore names) will remain.
+ * Also, this assumes a fixed-block file system (like FFS, or a V7 or a
+ * System V file system). In a logging file system, you'll have to have
+ * kernel support.
+ */
+int
+rm_overwrite_rm(rtems_shell_rm_globals* globals, char *file, struct stat *sbp)
+{
+ struct stat sb;
+#if RTEMS_REMOVED
+ struct statfs fsb;
+#endif
+ off_t len;
+ int bsize, fd, wlen;
+ char *buf = NULL;
+
+ fd = -1;
+ if (sbp == NULL) {
+ if (lstat(file, &sb))
+ goto err;
+ sbp = &sb;
+ }
+ if (!S_ISREG(sbp->st_mode))
+ return (1);
+ if (sbp->st_nlink > 1 && !fflag) {
+ warnx("%s (inode %lu): not overwritten due to multiple links",
+ file, sbp->st_ino);
+ return (0);
+ }
+ if ((fd = open(file, O_WRONLY, 0)) == -1)
+ goto err;
+#if RTEMS_REMOVED
+ if (fstatfs(fd, &fsb) == -1)
+ goto err;
+ bsize = MAX(fsb.f_iosize, 1024);
+#endif
+ bsize = 1024;
+ if ((buf = malloc(bsize)) == NULL)
+ err(exit_jump, 1, "%s: malloc", file);
+
+#define PASS(byte) { \
+ memset(buf, byte, bsize); \
+ for (len = sbp->st_size; len > 0; len -= wlen) { \
+ wlen = len < bsize ? len : bsize; \
+ if (write(fd, buf, wlen) != wlen) \
+ goto err; \
+ } \
+}
+ PASS(0xff);
+ if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
+ goto err;
+ PASS(0x00);
+ if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
+ goto err;
+ PASS(0xff);
+ if (!fsync(fd) && !close(fd)) {
+ free(buf);
+ return (1);
+ }
+
+err: eval = 1;
+ if (buf)
+ free(buf);
+ if (fd != -1)
+ close(fd);
+ warn("%s", file);
+ return (0);
+}
+
+void strmode(mode_t mode, char *p);
+char *fflagstostr(u_long flags);
+const char *user_from_uid(uid_t uid, int nouser);
+
+int
+check_rm(rtems_shell_rm_globals* globals, char *path, char *name, struct stat *sp)
+{
+ int ch, first;
+ char modep[15], *flagsp;
+
+ /* Check -i first. */
+ if (iflag)
+ (void)fprintf(stderr, "remove %s? ", path);
+ else {
+ /*
+ * If it's not a symbolic link and it's unwritable and we're
+ * talking to a terminal, ask. Symbolic links are excluded
+ * because their permissions are meaningless. Check stdin_ok
+ * first because we may not have stat'ed the file.
+ */
+#if RTEMS_REMOVED
+ if (!stdin_ok || S_ISLNK(sp->st_mode) ||
+ (!access(name, W_OK) &&
+ !(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
+ (!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !xuid)))
+#endif
+ if (!stdin_ok || S_ISLNK(sp->st_mode) ||
+ (!access(name, W_OK)))
+ return (1);
+ strmode(sp->st_mode, modep);
+#if RTEMS_REMOVED
+ if ((flagsp = fflagstostr(sp->st_flags)) == NULL)
+ err(exit_jump, 1, "fflagstostr");
+#else
+ flagsp = "no supported";
+#endif
+ if (Pflag)
+ errx(exit_jump, 1,
+ "%s: -P was specified, but file is not writable",
+ path);
+ (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ",
+ modep + 1, modep[9] == ' ' ? "" : " ",
+ user_from_uid(sp->st_uid, 0),
+ group_from_gid(sp->st_gid, 0),
+ *flagsp ? flagsp : "", *flagsp ? " " : "",
+ path);
+#if RTEMS_REMOVED
+ free(flagsp);
+#endif
+ }
+ (void)fflush(stderr);
+
+ first = ch = getchar();
+ while (ch != '\n' && ch != EOF)
+ ch = getchar();
+ return (first == 'y' || first == 'Y');
+}
+
+#define ISSLASH(a) ((a)[0] == '/' && (a)[1] == '\0')
+void
+checkslash_rm(rtems_shell_rm_globals* globals, char **argv)
+{
+ char **t, **u;
+ int complained;
+
+ complained = 0;
+ for (t = argv; *t;) {
+ if (ISSLASH(*t)) {
+ if (!complained++)
+ warnx("\"/\" may not be removed");
+ eval = 1;
+ for (u = t; u[0] != NULL; ++u)
+ u[0] = u[1];
+ } else {
+ ++t;
+ }
+ }
+}
+
+int
+check2_rm(rtems_shell_rm_globals* globals, char **argv)
+{
+ struct stat st;
+ int first;
+ int ch;
+ int fcount = 0;
+ int dcount = 0;
+ int i;
+ const char *dname = NULL;
+
+ for (i = 0; argv[i]; ++i) {
+ if (lstat(argv[i], &st) == 0) {
+ if (S_ISDIR(st.st_mode)) {
+ ++dcount;
+ dname = argv[i]; /* only used if 1 dir */
+ } else {
+ ++fcount;
+ }
+ }
+ }
+ first = 0;
+ while (first != 'n' && first != 'N' && first != 'y' && first != 'Y') {
+ if (dcount && rflag) {
+ fprintf(stderr, "recursively remove");
+ if (dcount == 1)
+ fprintf(stderr, " %s", dname);
+ else
+ fprintf(stderr, " %d dirs", dcount);
+ if (fcount == 1)
+ fprintf(stderr, " and 1 file");
+ else if (fcount > 1)
+ fprintf(stderr, " and %d files", fcount);
+ } else if (dcount + fcount > 3) {
+ fprintf(stderr, "remove %d files", dcount + fcount);
+ } else {
+ return(1);
+ }
+ fprintf(stderr, "? ");
+ fflush(stderr);
+
+ first = ch = getchar();
+ while (ch != '\n' && ch != EOF)
+ ch = getchar();
+ if (ch == EOF)
+ break;
+ }
+ return (first == 'y' || first == 'Y');
+}
+
+#define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2])))
+void
+checkdot_rm(rtems_shell_rm_globals* globals, char **argv)
+{
+ char *p, **save, **t;
+ int complained;
+
+ complained = 0;
+ for (t = argv; *t;) {
+ if ((p = strrchr(*t, '/')) != NULL)
+ ++p;
+ else
+ p = *t;
+ if (ISDOT(p)) {
+ if (!complained++)
+ warnx("\".\" and \"..\" may not be removed");
+ eval = 1;
+ for (save = t; (t[0] = t[1]) != NULL; ++t)
+ continue;
+ t = save;
+ } else
+ ++t;
+ }
+}
+
+void
+usage_rm(rtems_shell_rm_globals* globals)
+{
+
+ (void)fprintf(stderr, "%s\n%s\n",
+ "usage: rm [-f | -i] [-dIPRrvW] file ...",
+ " unlink file");
+ exit(1);
+}
+
+rtems_shell_cmd_t rtems_shell_RM_Command = {
+ "rm", /* name */
+ "[-f | -i] [-dIPRrvW] file ...", /* usage */
+ "files", /* topic */
+ rtems_shell_main_rm, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_rmdir.c b/cpukit/libmisc/shell/main_rmdir.c
new file mode 100644
index 0000000000..df94a7efbf
--- /dev/null
+++ b/cpukit/libmisc/shell/main_rmdir.c
@@ -0,0 +1,51 @@
+/*
+ * RMDIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_rmdir (int argc, char *argv[])
+{
+ char *dir;
+ int n;
+
+ n = 1;
+ while (n < argc) {
+ dir = argv[n++];
+ if (rmdir(dir)) {
+ fprintf(stderr,"%s: %s: %s\n", argv[0], dir, strerror(errno));
+ return -1;
+ }
+ }
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_RMDIR_Command = {
+ "rmdir", /* name */
+ "rmdir dir # remove directory", /* usage */
+ "files", /* topic */
+ rtems_shell_main_rmdir, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_route.c b/cpukit/libmisc/shell/main_route.c
new file mode 100644
index 0000000000..ea503b4ef2
--- /dev/null
+++ b/cpukit/libmisc/shell/main_route.c
@@ -0,0 +1,153 @@
+/*
+ * ROUTE Command Implmentation
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <net/route.h>
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_route(
+ int argc,
+ char *argv[]
+)
+{
+ int cmd;
+ struct sockaddr_in dst;
+ struct sockaddr_in gw;
+ struct sockaddr_in netmask;
+ int f_host;
+ int f_gw = 0;
+ int cur_idx;
+ int flags;
+ int rc;
+
+ memset(&dst, 0, sizeof(dst));
+ memset(&gw, 0, sizeof(gw));
+ memset(&netmask, 0, sizeof(netmask));
+
+ dst.sin_len = sizeof(dst);
+ dst.sin_family = AF_INET;
+ dst.sin_addr.s_addr = inet_addr("0.0.0.0");
+
+ gw.sin_len = sizeof(gw);
+ gw.sin_family = AF_INET;
+ gw.sin_addr.s_addr = inet_addr("0.0.0.0");
+
+ netmask.sin_len = sizeof(netmask);
+ netmask.sin_family = AF_INET;
+ netmask.sin_addr.s_addr = inet_addr("255.255.255.0");
+
+ if (argc < 2) {
+ rtems_bsdnet_show_inet_routes();
+ return 0;
+ }
+
+ if (strcmp(argv[1], "add") == 0) {
+ cmd = RTM_ADD;
+ } else if (strcmp(argv[1], "del") == 0) {
+ cmd = RTM_DELETE;
+ } else {
+ printf("invalid command: %s\n", argv[1]);
+ printf("\tit should be 'add' or 'del'\n");
+ return -1;
+ }
+
+ if (argc < 3) {
+ printf("not enough arguments\n");
+ return -1;
+ }
+
+ if (strcmp(argv[2], "-host") == 0) {
+ f_host = 1;
+ } else if (strcmp(argv[2], "-net") == 0) {
+ f_host = 0;
+ } else {
+ printf("Invalid type: %s\n", argv[1]);
+ printf("\tit should be '-host' or '-net'\n");
+ return -1;
+ }
+
+ if (argc < 4) {
+ printf("not enough arguments\n");
+ return -1;
+ }
+
+ inet_pton(AF_INET, argv[3], &dst.sin_addr);
+
+ cur_idx = 4;
+ while(cur_idx < argc) {
+ if (strcmp(argv[cur_idx], "gw") == 0) {
+ if ((cur_idx +1) >= argc) {
+ printf("no gateway address\n");
+ return -1;
+ }
+ f_gw = 1;
+ inet_pton(AF_INET, argv[cur_idx + 1], &gw.sin_addr);
+ cur_idx += 1;
+ } else if(strcmp(argv[cur_idx], "netmask") == 0) {
+ if ((cur_idx +1) >= argc) {
+ printf("no netmask address\n");
+ return -1;
+ }
+ f_gw = 1;
+ inet_pton(AF_INET, argv[cur_idx + 1], &netmask.sin_addr);
+ cur_idx += 1;
+ } else {
+ printf("Unknown argument\n");
+ return -1;
+ }
+ cur_idx += 1;
+ }
+
+ flags = RTF_STATIC;
+ if (f_gw != 0) {
+ flags |= RTF_GATEWAY;
+ }
+ if (f_host != 0) {
+ flags |= RTF_HOST;
+ }
+
+ rc = rtems_bsdnet_rtrequest(
+ cmd,
+ (struct sockaddr *)&dst,
+ (struct sockaddr *)&gw,
+ (struct sockaddr *)&netmask,
+ flags,
+ NULL
+ );
+ if (rc < 0) {
+ printf("Error adding route\n");
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_ROUTE_Command = {
+ "route", /* name */
+ "TBD", /* usage */
+ "network", /* topic */
+ rtems_shell_main_route, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_rtc.c b/cpukit/libmisc/shell/main_rtc.c
new file mode 100644
index 0000000000..139018eb13
--- /dev/null
+++ b/cpukit/libmisc/shell/main_rtc.c
@@ -0,0 +1,173 @@
+/**
+ * @file
+ *
+ * Real time clock shell command.
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <rtems.h>
+#include <rtems/rtc.h>
+#include <rtems/error.h>
+#include <rtems/shell.h>
+
+#define RTEMS_RTC_SHELL_ERROR( fmt, ...) \
+ do { \
+ printf( "error: " fmt "\n", ##__VA_ARGS__); \
+ return -1; \
+ } while (0)
+
+#define RTEMS_RTC_SHELL_ERROR_SC( sc, fmt, ...) \
+ if ((sc) != RTEMS_SUCCESSFUL) { \
+ printf( "error: " fmt ": %s\n", ##__VA_ARGS__, rtems_status_text( sc)); \
+ return -1; \
+ }
+
+static const char rtems_rtc_shell_usage [] =
+ "real time clock read and set\n"
+ "\n"
+ "rtc\n"
+ "\tprints the current time of day\n"
+ "\n"
+ "rtc YYYY-MM-DD [HH:MM:SS [TICKS]]\n"
+ "\tsets the time of day and real time clock";
+
+static int rtems_rtc_shell_main( int argc, char **argv)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_time_of_day tod = {
+ .year = 1988,
+ .month = 1,
+ .day = 1,
+ .hour = 0,
+ .minute = 0,
+ .second = 0,
+ .ticks = 0
+ };
+
+ if (argc == 1) {
+ sc = rtems_clock_get_tod( &tod);
+ RTEMS_RTC_SHELL_ERROR_SC( sc, "get time of day");
+
+ printf(
+ "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
+ " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32
+ " %02" PRIu32 "\n",
+ tod.year,
+ tod.month,
+ tod.day,
+ tod.hour,
+ tod.minute,
+ tod.second,
+ tod.ticks
+ );
+ } else if (argc > 1 && argc < 5) {
+ int rv = 0;
+ int fd = 0;
+ ssize_t n = 0;
+ uint32_t v [3];
+
+ if (argc > 1) {
+ rv = sscanf(
+ argv [1],
+ "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32,
+ v,
+ v + 1,
+ v + 2
+ );
+
+ if (rv == 3) {
+ tod.year = v [0];
+ tod.month = v [1];
+ tod.day = v [2];
+ } else {
+ RTEMS_RTC_SHELL_ERROR( "unexpected YYYY-MM-DD input: %s", argv [1]);
+ }
+ }
+
+ if (argc > 2) {
+ rv = sscanf(
+ argv [2],
+ "%04" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
+ v,
+ v + 1,
+ v + 2
+ );
+
+ if (rv == 3) {
+ tod.hour = v [0];
+ tod.minute = v [1];
+ tod.second = v [2];
+ } else {
+ RTEMS_RTC_SHELL_ERROR( "unexpected HH:MM:SS input: %s", argv [2]);
+ }
+ }
+
+ if (argc > 3) {
+ rv = sscanf( argv [3], "%5" PRIu32, v);
+
+ if (rv == 1) {
+ tod.ticks = v [0];
+ } else {
+ RTEMS_RTC_SHELL_ERROR( "unexpected TICKS input: %s", argv [3]);
+ }
+ }
+
+ sc = rtems_clock_set( &tod);
+ RTEMS_RTC_SHELL_ERROR_SC( sc, "set time of day");
+
+ fd = open( RTC_DEVICE_NAME, O_WRONLY);
+ if (fd < 0) {
+ perror( "error: open " RTC_DEVICE_NAME);
+ return -1;
+ }
+
+ n = write( fd, &tod, sizeof( tod));
+ if (n != (ssize_t) sizeof( tod)) {
+ perror( "error: write to " RTC_DEVICE_NAME);
+ close( fd);
+ return -1;
+ }
+
+ rv = close( fd);
+ if (rv != 0) {
+ perror( "error: close " RTC_DEVICE_NAME);
+ return -1;
+ }
+ } else {
+ puts( rtems_rtc_shell_usage);
+ return -1;
+ }
+
+ return 0;
+}
+
+struct rtems_shell_cmd_tt rtems_shell_RTC_Command = {
+ .name = "rtc",
+ .usage = rtems_rtc_shell_usage,
+ .topic = "misc",
+ .command = rtems_rtc_shell_main,
+ .alias = NULL,
+ .next = NULL
+};
diff --git a/cpukit/libmisc/shell/main_setenv.c b/cpukit/libmisc/shell/main_setenv.c
new file mode 100644
index 0000000000..5b7c92920f
--- /dev/null
+++ b/cpukit/libmisc/shell/main_setenv.c
@@ -0,0 +1,72 @@
+/*
+ * Set an environment vairable.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_setenv(int argc, char *argv[])
+{
+ char* env = NULL;
+ char* string = NULL;
+ int len = 0;
+ int arg;
+ char* p;
+
+ if (argc <= 2) {
+ printf("error: no variable or string\n");
+ return 1;
+ }
+
+ env = argv[1];
+
+ for (arg = 2; arg < argc; arg++)
+ len += strlen(argv[arg]);
+
+ len += argc - 2 - 1;
+
+ string = malloc(len + 1);
+
+ if (!string) {
+ printf("error: no memory\n");
+ return 1;
+ }
+
+ for (arg = 2, p = string; arg < argc; arg++) {
+ strcpy(p, argv[arg]);
+ p += strlen(argv[arg]);
+ if (arg < (argc - 1)) {
+ *p = ' ';
+ p++;
+ }
+ }
+
+ if (setenv(env, string, 1) < 0) {
+ printf( "error: %s\n", strerror(errno) );
+ free( string );
+ return 1;
+ }
+
+ free( string );
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_SETENV_Command = {
+ "setenv", /* name */
+ "setenv [var] [string]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_setenv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_sleep.c b/cpukit/libmisc/shell/main_sleep.c
new file mode 100644
index 0000000000..2dbb66a996
--- /dev/null
+++ b/cpukit/libmisc/shell/main_sleep.c
@@ -0,0 +1,74 @@
+/*
+ * Sleep Shell Command Implmentation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+int rtems_shell_main_sleep(
+ int argc,
+ char *argv[]
+)
+{
+ struct timespec delay;
+ unsigned long tmp;
+
+ if ((argc != 2) && (argc != 3)) {
+ fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] );
+ return -1;
+ }
+
+ /*
+ * Convert the seconds argument to a number
+ */
+ if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
+ printf( "Seconds argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ delay.tv_sec = (time_t) tmp;
+
+ /*
+ * If the user specified a nanoseconds argument, convert it
+ */
+ delay.tv_nsec = 0;
+ if (argc == 3) {
+ if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
+ printf( "Seconds argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ delay.tv_nsec = tmp;
+ }
+
+ /*
+ * Now sleep as requested.
+ */
+ nanosleep( &delay, NULL );
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_SLEEP_Command = {
+ "sleep", /* name */
+ "sleep seconds [nanoseconds]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_sleep, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_stackuse.c b/cpukit/libmisc/shell/main_stackuse.c
new file mode 100644
index 0000000000..4d1d944ceb
--- /dev/null
+++ b/cpukit/libmisc/shell/main_stackuse.c
@@ -0,0 +1,44 @@
+/*
+ * stackuse Command Implementation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/stackchk.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_stackuse(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ rtems_stack_checker_report_usage_with_plugin(
+ stdout,
+ (rtems_printk_plugin_t)fprintf
+ );
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_STACKUSE_Command = {
+ "stackuse", /* name */
+ "print per thread stack usage", /* usage */
+ "rtems", /* topic */
+ rtems_shell_main_stackuse, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_time.c b/cpukit/libmisc/shell/main_time.c
new file mode 100644
index 0000000000..7d6cf557ee
--- /dev/null
+++ b/cpukit/libmisc/shell/main_time.c
@@ -0,0 +1,84 @@
+/*
+ * Time Shell Command Implmentation
+ *
+ * Author: Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_time(
+ int argc,
+ char *argv[]
+)
+{
+ rtems_shell_cmd_t* shell_cmd;
+ int errorlevel = 0;
+ struct timespec start;
+ struct timespec end;
+ struct timespec period;
+ rtems_status_code sc;
+
+ argc--;
+
+ sc = rtems_clock_get_uptime(&start);
+ if (sc != RTEMS_SUCCESSFUL)
+ printf("error: cannot read time\n");
+
+ if (argc) {
+ shell_cmd = rtems_shell_lookup_cmd(argv[1]);
+ if ( argv[1] == NULL ) {
+ errorlevel = -1;
+ } else if ( shell_cmd == NULL ) {
+ errorlevel = rtems_shell_script_file(argc, &argv[1]);
+ } else {
+ errorlevel = shell_cmd->command(argc, &argv[1]);
+ }
+ }
+
+ sc = rtems_clock_get_uptime(&end);
+ if (sc != RTEMS_SUCCESSFUL)
+ printf("error: cannot read time\n");
+
+ period.tv_sec = end.tv_sec - start.tv_sec;
+ period.tv_nsec = end.tv_nsec - start.tv_nsec;
+ if (period.tv_nsec < 0)
+ {
+ --period.tv_sec;
+ period.tv_nsec += 1000000000UL;
+ }
+
+ printf("time: %li:%02li:%02li.%03li\n",
+ period.tv_sec / 3600,
+ period.tv_sec / 60, period.tv_sec % 60,
+ period.tv_nsec / 1000000);
+
+ return errorlevel;
+}
+
+rtems_shell_cmd_t rtems_shell_TIME_Command = {
+ "time", /* name */
+ "time command [arguments...]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_time, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_tty.c b/cpukit/libmisc/shell/main_tty.c
new file mode 100644
index 0000000000..f8313b55f8
--- /dev/null
+++ b/cpukit/libmisc/shell/main_tty.c
@@ -0,0 +1,44 @@
+/*
+ * TTY Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_tty(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ printf("%s\n", ttyname(fileno(stdin)));
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_TTY_Command = {
+ "tty", /* name */
+ "show ttyname", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_tty, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_umask.c b/cpukit/libmisc/shell/main_umask.c
new file mode 100644
index 0000000000..8bfbe7e443
--- /dev/null
+++ b/cpukit/libmisc/shell/main_umask.c
@@ -0,0 +1,62 @@
+/*
+ * UMASK Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+int rtems_shell_main_umask(
+ int argc,
+ char *argv[]
+)
+{
+ unsigned long tmp;
+ mode_t msk = umask(0);
+
+ if (argc == 2) {
+ if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
+ printf( "Mask argument (%s) is not a number\n", argv[1] );
+ return -1;
+ }
+ msk = (mode_t) tmp;
+
+ }
+ umask(msk);
+
+ msk = umask(0);
+ printf("0%o\n", (unsigned int) msk);
+ umask(msk);
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_UMASK_Command = {
+ "umask", /* name */
+ "umask [new_umask]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_umask, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_unmount.c b/cpukit/libmisc/shell/main_unmount.c
new file mode 100644
index 0000000000..ba101dc014
--- /dev/null
+++ b/cpukit/libmisc/shell/main_unmount.c
@@ -0,0 +1,74 @@
+/*
+ * Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include <rtems/fsmount.h>
+#include "internal.h"
+
+int rtems_shell_main_unmount(
+ int argc,
+ char *argv[]
+)
+{
+ char* mount_point = NULL;
+ int arg;
+
+ for (arg = 1; arg < argc; arg++) {
+ if (!mount_point)
+ mount_point = argv[arg];
+ else {
+ fprintf (stderr, "error: only one mount path require: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+
+ if (!mount_point) {
+ fprintf (stderr, "error: no mount point\n");
+ return 1;
+ }
+
+ /*
+ * Unmount the disk.
+ */
+
+ if (unmount (mount_point) < 0) {
+ fprintf (stderr, "error: unmount failed: %s: %s\n",
+ mount_point, strerror (errno));
+ return 1;
+ }
+
+ printf ("unmounted %s\n", mount_point);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_UNMOUNT_Command = {
+ "unmount", /* name */
+ "unmount path # unmount disk", /* usage */
+ "files", /* topic */
+ rtems_shell_main_unmount, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_unsetenv.c b/cpukit/libmisc/shell/main_unsetenv.c
new file mode 100644
index 0000000000..8805ba4341
--- /dev/null
+++ b/cpukit/libmisc/shell/main_unsetenv.c
@@ -0,0 +1,43 @@
+/*
+ * Unset an environment vairable.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_unsetenv(int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ printf ("error: only argument is the variable name\n");
+ return 1;
+ }
+
+ if (unsetenv (argv[1]) < 0)
+ {
+ printf ("error: %s\n", strerror (errno));
+ return 1;
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_UNSETENV_Command = {
+ "unsetenv", /* name */
+ "unsetenv [var]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_unsetenv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_whoami.c b/cpukit/libmisc/shell/main_whoami.c
new file mode 100644
index 0000000000..ce34ed95ca
--- /dev/null
+++ b/cpukit/libmisc/shell/main_whoami.c
@@ -0,0 +1,48 @@
+/*
+ * WHOAMI Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * Work: fernando.ruiz@ctv.es
+ * Home: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <pwd.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_whoami(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ struct passwd *pwd;
+
+ pwd = getpwuid(geteuid());
+ printf( "%s\n", (pwd) ? pwd->pw_name : "nobody");
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_WHOAMI_Command = {
+ "whoami", /* name */
+ "show current user", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_whoami, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_wkspaceinfo.c b/cpukit/libmisc/shell/main_wkspaceinfo.c
new file mode 100644
index 0000000000..fd7c531854
--- /dev/null
+++ b/cpukit/libmisc/shell/main_wkspaceinfo.c
@@ -0,0 +1,59 @@
+/*
+ * MALLOC_INFO Shell Command Implmentation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/malloc.h>
+#include <rtems/shell.h>
+#include <rtems/score/protectedheap.h>
+#include "internal.h"
+
+extern bool rtems_unified_work_area;
+
+void rtems_shell_print_unified_work_area_message(void)
+{
+ printf( "\nC Program Heap and RTEMS Workspace are %s.\n",
+ ((rtems_unified_work_area) ? "the same" : "separate")
+ );
+}
+
+int rtems_shell_main_wkspace_info(
+ int argc __attribute__((unused)),
+ char *argv[] __attribute__((unused))
+)
+{
+ Heap_Information_block info;
+
+ rtems_shell_print_unified_work_area_message();
+
+ _Protected_heap_Get_information( &_Workspace_Area, &info );
+ rtems_shell_print_heap_info( "free", &info.Free );
+ rtems_shell_print_heap_info( "used", &info.Used );
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_WKSPACE_INFO_Command = {
+ "wkspace", /* name */
+ "Report on RTEMS Executive Workspace", /* usage */
+ "rtems", /* topic */
+ rtems_shell_main_wkspace_info, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/mknod-pack_dev.c b/cpukit/libmisc/shell/mknod-pack_dev.c
new file mode 100644
index 0000000000..043019ad5a
--- /dev/null
+++ b/cpukit/libmisc/shell/mknod-pack_dev.c
@@ -0,0 +1,300 @@
+/* $NetBSD: pack_dev.c,v 1.10 2009/02/13 01:37:23 lukem Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#if 0
+#include <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: pack_dev.c,v 1.10 2009/02/13 01:37:23 lukem Exp $");
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "pack_dev.h"
+#endif
+
+static pack_t pack_netbsd;
+static pack_t pack_freebsd;
+static pack_t pack_8_8;
+static pack_t pack_12_20;
+static pack_t pack_14_18;
+static pack_t pack_8_24;
+static pack_t pack_bsdos;
+static int compare_format(const void *, const void *);
+
+static const char iMajorError[] = "invalid major number";
+static const char iMinorError[] = "invalid minor number";
+static const char tooManyFields[] = "too many fields for format";
+
+#define makedev(x,y) rtems_filesystem_make_dev_t(x,y)
+#define major(d) rtems_filesystem_dev_major_t(d)
+#define minor(d) rtems_filesystem_dev_minor_t(d)
+
+ /* exported */
+portdev_t
+pack_native(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev(numbers[0], numbers[1]);
+ if ((u_long)major(dev) != numbers[0])
+ *error = iMajorError;
+ else if ((u_long)minor(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+static portdev_t
+pack_netbsd(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_netbsd(numbers[0], numbers[1]);
+ if ((u_long)major_netbsd(dev) != numbers[0])
+ *error = iMajorError;
+ else if ((u_long)minor_netbsd(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_freebsd(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
+#define minor_freebsd(x) ((int32_t)(((x) & 0xffff00ff) >> 0))
+#define makedev_freebsd(x,y) ((portdev_t)((((x) << 8) & 0x0000ff00) | \
+ (((y) << 0) & 0xffff00ff)))
+
+static portdev_t
+pack_freebsd(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_freebsd(numbers[0], numbers[1]);
+ if ((u_long)major_freebsd(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)minor_freebsd(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_8_8(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
+#define minor_8_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
+#define makedev_8_8(x,y) ((portdev_t)((((x) << 8) & 0x0000ff00) | \
+ (((y) << 0) & 0x000000ff)))
+
+static portdev_t
+pack_8_8(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_8_8(numbers[0], numbers[1]);
+ if ((u_long)major_8_8(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)minor_8_8(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_12_20(x) ((int32_t)(((x) & 0xfff00000) >> 20))
+#define minor_12_20(x) ((int32_t)(((x) & 0x000fffff) >> 0))
+#define makedev_12_20(x,y) ((portdev_t)((((x) << 20) & 0xfff00000) | \
+ (((y) << 0) & 0x000fffff)))
+
+static portdev_t
+pack_12_20(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_12_20(numbers[0], numbers[1]);
+ if ((u_long)major_12_20(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)minor_12_20(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_14_18(x) ((int32_t)(((x) & 0xfffc0000) >> 18))
+#define minor_14_18(x) ((int32_t)(((x) & 0x0003ffff) >> 0))
+#define makedev_14_18(x,y) ((portdev_t)((((x) << 18) & 0xfffc0000) | \
+ (((y) << 0) & 0x0003ffff)))
+
+static portdev_t
+pack_14_18(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_14_18(numbers[0], numbers[1]);
+ if ((u_long)major_14_18(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)minor_14_18(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_8_24(x) ((int32_t)(((x) & 0xff000000) >> 24))
+#define minor_8_24(x) ((int32_t)(((x) & 0x00ffffff) >> 0))
+#define makedev_8_24(x,y) ((portdev_t)((((x) << 24) & 0xff000000) | \
+ (((y) << 0) & 0x00ffffff)))
+
+static portdev_t
+pack_8_24(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_8_24(numbers[0], numbers[1]);
+ if ((u_long)major_8_24(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)minor_8_24(dev) != numbers[1])
+ *error = iMinorError;
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+#define major_12_12_8(x) ((int32_t)(((x) & 0xfff00000) >> 20))
+#define unit_12_12_8(x) ((int32_t)(((x) & 0x000fff00) >> 8))
+#define subunit_12_12_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
+#define makedev_12_12_8(x,y,z) ((portdev_t)((((x) << 20) & 0xfff00000) | \
+ (((y) << 8) & 0x000fff00) | \
+ (((z) << 0) & 0x000000ff)))
+
+static portdev_t
+pack_bsdos(int n, u_long numbers[], const char **error)
+{
+ portdev_t dev = 0;
+
+ if (n == 2) {
+ dev = makedev_12_20(numbers[0], numbers[1]);
+ if ((u_long)major_12_20(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)minor_12_20(dev) != numbers[1])
+ *error = iMinorError;
+ } else if (n == 3) {
+ dev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);
+ if ((u_long)major_12_12_8(dev) != numbers[0])
+ *error = iMajorError;
+ if ((u_long)unit_12_12_8(dev) != numbers[1])
+ *error = "invalid unit number";
+ if ((u_long)subunit_12_12_8(dev) != numbers[2])
+ *error = "invalid subunit number";
+ } else
+ *error = tooManyFields;
+ return (dev);
+}
+
+
+ /* list of formats and pack functions */
+ /* this list must be sorted lexically */
+struct format {
+ const char *name;
+ pack_t *pack;
+} formats[] = {
+ {"386bsd", pack_8_8},
+ {"4bsd", pack_8_8},
+ {"bsdos", pack_bsdos},
+ {"freebsd", pack_freebsd},
+ {"hpux", pack_8_24},
+ {"isc", pack_8_8},
+ {"linux", pack_8_8},
+ {"native", pack_native},
+ {"netbsd", pack_netbsd},
+ {"osf1", pack_12_20},
+ {"sco", pack_8_8},
+ {"solaris", pack_14_18},
+ {"sunos", pack_8_8},
+ {"svr3", pack_8_8},
+ {"svr4", pack_14_18},
+ {"ultrix", pack_8_8},
+};
+
+static int
+compare_format(const void *key, const void *element)
+{
+ const char *name;
+ const struct format *format;
+
+ name = key;
+ format = element;
+
+ return (strcmp(name, format->name));
+}
+
+
+pack_t *
+pack_find(const char *name)
+{
+ struct format *format;
+
+ format = bsearch(name, formats,
+ sizeof(formats)/sizeof(formats[0]),
+ sizeof(formats[0]), compare_format);
+ if (format == 0)
+ return (NULL);
+ return (format->pack);
+}
diff --git a/cpukit/libmisc/shell/mknod-pack_dev.h b/cpukit/libmisc/shell/mknod-pack_dev.h
new file mode 100644
index 0000000000..5c6d78af8b
--- /dev/null
+++ b/cpukit/libmisc/shell/mknod-pack_dev.h
@@ -0,0 +1,52 @@
+/* $NetBSD: pack_dev.h,v 1.7 2008/04/28 20:23:09 martin Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PACK_DEV_H
+#define _PACK_DEV_H
+
+#ifdef __CYGWIN__
+typedef __dev32_t portdev_t;
+#else
+typedef dev_t portdev_t;
+#endif
+typedef portdev_t pack_t(int, u_long [], const char **);
+
+static pack_t *pack_find(const char *);
+static pack_t pack_native;
+
+#define major_netbsd(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
+#define minor_netbsd(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
+ (((x) & 0x000000ff) >> 0)))
+#define makedev_netbsd(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
+ (((y) << 12) & 0xfff00000) | \
+ (((y) << 0) & 0x000000ff)))
+
+#endif /* _PACK_DEV_H */
diff --git a/cpukit/libmisc/shell/pathnames-mv.h b/cpukit/libmisc/shell/pathnames-mv.h
new file mode 100644
index 0000000000..a38e4e9450
--- /dev/null
+++ b/cpukit/libmisc/shell/pathnames-mv.h
@@ -0,0 +1,40 @@
+/* $NetBSD: pathnames.h,v 1.8 2004/08/19 22:26:07 christos Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)pathnames.h 8.1 (Berkeley) 5/31/93
+ */
+
+#ifdef RESCUEDIR
+#define _PATH_RM RESCUEDIR "/rm"
+#define _PATH_CP RESCUEDIR "/cp"
+#else
+#define _PATH_RM "/bin/rm"
+#define _PATH_CP "/bin/cp"
+#endif
diff --git a/cpukit/libmisc/shell/print-ls.c b/cpukit/libmisc/shell/print-ls.c
new file mode 100644
index 0000000000..c19ce9009c
--- /dev/null
+++ b/cpukit/libmisc/shell/print-ls.c
@@ -0,0 +1,492 @@
+/* $NetBSD: print.c,v 1.40 2004/11/17 17:00:00 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Michael Fischbein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94";
+#else
+__RCSID("$NetBSD: print.c,v 1.40 2004/11/17 17:00:00 mycroft Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fts.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+//#include <tzfile.h>
+#include <unistd.h>
+//#include <util.h>
+
+#include "extern-ls.h"
+
+#define DAYSPERNYEAR ((time_t)365)
+#define SECSPERDAY ((time_t)60 * (time_t)60 * (time_t)24)
+
+
+#if RTEMS_REMOVED
+extern int termwidth;
+#endif
+
+static int printaname(rtems_shell_ls_globals* globals, FTSENT *, int, int);
+static void printlink(rtems_shell_ls_globals* globals, FTSENT *);
+static void printtime(rtems_shell_ls_globals* globals, time_t);
+static int printtype(u_int);
+
+#if RTEMS_REMOVED
+static time_t now;
+#endif
+
+#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
+
+void
+printscol(rtems_shell_ls_globals* globals, DISPLAY *dp)
+{
+ FTSENT *p;
+
+ for (p = dp->list; p; p = p->fts_link) {
+ if (IS_NOPRINT(p))
+ continue;
+ (void)printaname(globals, p, dp->s_inode, dp->s_block);
+ (void)putchar('\n');
+ }
+}
+
+void
+printlong(rtems_shell_ls_globals* globals, DISPLAY *dp)
+{
+ struct stat *sp;
+ FTSENT *p;
+ NAMES *np;
+ char buf[20]; //, szbuf[5];
+
+ now = time(NULL);
+
+ if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
+#if RTEMS_REMOVED
+ if (f_humanize) {
+ if ((humanize_number(szbuf, sizeof(szbuf), dp->stotal,
+ "", HN_AUTOSCALE,
+ (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(exit_jump, 1, "humanize_number");
+ (void)printf("total %s\n", szbuf);
+ } else {
+#endif
+ (void)printf("total %llu\n",
+ (long long)(howmany(dp->btotal, blocksize)));
+#if RTEMS_REMOVED
+ }
+#endif
+ }
+
+ for (p = dp->list; p; p = p->fts_link) {
+ if (IS_NOPRINT(p))
+ continue;
+ sp = p->fts_statp;
+ if (f_inode)
+ (void)printf("%*lu ", dp->s_inode, sp->st_ino);
+ if (f_size && !f_humanize) {
+ (void)printf("%*llu ", dp->s_block,
+ (long long)howmany(sp->st_blocks, blocksize));
+ }
+ (void)strmode(sp->st_mode, buf);
+ np = p->fts_pointer;
+ (void)printf("%s %*lu ", buf, dp->s_nlink,
+ (unsigned long)sp->st_nlink);
+ if (!f_grouponly)
+ (void)printf("%-*s ", dp->s_user, np->user);
+ (void)printf("%-*s ", dp->s_group, np->group);
+ if (f_flags)
+ (void)printf("%-*s ", dp->s_flags, np->flags);
+ if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
+ (void)printf("%*"PRIu32", %*"PRIu32" ",
+ dp->s_major, major(sp->st_rdev), dp->s_minor,
+ minor(sp->st_rdev));
+ else
+#if RTEMS_REMOVED
+ if (f_humanize) {
+ if ((humanize_number(szbuf, sizeof(szbuf),
+ sp->st_size, "", HN_AUTOSCALE,
+ (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ (void)printf("%*s ", dp->s_size, szbuf);
+ } else {
+#endif
+ {
+ unsigned long long size;
+ if (sp->st_size < 0)
+ size = sp->st_size * -1;
+ else
+ size = sp->st_size;
+ (void)printf("%*llu ", dp->s_size, size);
+ }
+ if (f_accesstime)
+ printtime(globals, sp->st_atime);
+ else if (f_statustime)
+ printtime(globals, sp->st_ctime);
+ else
+ printtime(globals, sp->st_mtime);
+ if (f_octal || f_octal_escape)
+ (void)safe_print(globals, p->fts_name);
+ else if (f_nonprint)
+ (void)printescaped(globals, p->fts_name);
+ else
+ (void)printf("%s", p->fts_name);
+
+ if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
+ (void)printtype(sp->st_mode);
+ if (S_ISLNK(sp->st_mode))
+ printlink(globals, p);
+ (void)putchar('\n');
+ }
+}
+
+void
+printcol(rtems_shell_ls_globals* globals, DISPLAY *dp)
+{
+ static FTSENT **array;
+ static int lastentries = -1;
+ FTSENT *p;
+ int base, chcnt, col, colwidth, num;
+ int numcols, numrows, row;
+ //char szbuf[5];
+
+ colwidth = dp->maxlen;
+ if (f_inode)
+ colwidth += dp->s_inode + 1;
+ if (f_size) {
+ if (f_humanize)
+ colwidth += dp->s_size + 1;
+ else
+ colwidth += dp->s_block + 1;
+ }
+ if (f_type || f_typedir)
+ colwidth += 1;
+
+ colwidth += 1;
+
+ if (termwidth < 2 * colwidth) {
+ printscol(globals, dp);
+ return;
+ }
+
+ /*
+ * Have to do random access in the linked list -- build a table
+ * of pointers.
+ */
+ if (dp->entries > lastentries) {
+ lastentries = dp->entries;
+ if ((array =
+ realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
+ warn(NULL);
+ printscol(globals, dp);
+ }
+ }
+ for (p = dp->list, num = 0; p; p = p->fts_link)
+ if (p->fts_number != NO_PRINT)
+ array[num++] = p;
+
+ numcols = termwidth / colwidth;
+ colwidth = termwidth / numcols; /* spread out if possible */
+ numrows = num / numcols;
+ if (num % numcols)
+ ++numrows;
+
+ if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
+#if RTEMS_REMOVED
+ if (f_humanize) {
+ if ((humanize_number(szbuf, sizeof(szbuf), dp->stotal,
+ "", HN_AUTOSCALE,
+ (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ (void)printf("total %s\n", szbuf);
+ } else {
+#endif
+ (void)printf("total %llu\n",
+ (long long)(howmany(dp->btotal, blocksize)));
+#if RTEMS_REMOVED
+ }
+#endif
+ }
+ for (row = 0; row < numrows; ++row) {
+ for (base = row, chcnt = col = 0; col < numcols; ++col) {
+ chcnt = printaname(globals, array[base], dp->s_inode,
+ f_humanize && 0 ? dp->s_size : dp->s_block);
+ if ((base += numrows) >= num)
+ break;
+ while (chcnt++ < colwidth)
+ (void)putchar(' ');
+ }
+ (void)putchar('\n');
+ }
+}
+
+void
+printacol(rtems_shell_ls_globals* globals, DISPLAY *dp)
+{
+ FTSENT *p;
+ int chcnt, col, colwidth;
+ int numcols;
+ //char szbuf[5];
+
+ colwidth = dp->maxlen;
+ if (f_inode)
+ colwidth += dp->s_inode + 1;
+ if (f_size) {
+ if (f_humanize)
+ colwidth += dp->s_size + 1;
+ else
+ colwidth += dp->s_block + 1;
+ }
+ if (f_type || f_typedir)
+ colwidth += 1;
+
+ colwidth += 1;
+
+ if (termwidth < 2 * colwidth) {
+ printscol(globals, dp);
+ return;
+ }
+
+ numcols = termwidth / colwidth;
+ colwidth = termwidth / numcols; /* spread out if possible */
+
+ if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
+#if RTEMS_REMOVED
+ if (f_humanize) {
+ if ((humanize_number(szbuf, sizeof(szbuf), dp->stotal,
+ "", HN_AUTOSCALE,
+ (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ (void)printf("total %s\n", szbuf);
+ } else {
+#endif
+ (void)printf("total %llu\n",
+ (long long)(howmany(dp->btotal, blocksize)));
+#if RTEMS_REMOVED
+ }
+#endif
+ }
+ chcnt = col = 0;
+ for (p = dp->list; p; p = p->fts_link) {
+ if (IS_NOPRINT(p))
+ continue;
+ if (col >= numcols) {
+ chcnt = col = 0;
+ (void)putchar('\n');
+ }
+ chcnt = printaname(globals, p, dp->s_inode,
+ f_humanize && 0 ? dp->s_size : dp->s_block);
+ while (chcnt++ < colwidth)
+ (void)putchar(' ');
+ col++;
+ }
+ (void)putchar('\n');
+}
+
+void
+printstream(rtems_shell_ls_globals* globals, DISPLAY *dp)
+{
+ FTSENT *p;
+ int col;
+ int extwidth;
+
+ extwidth = 0;
+ if (f_inode)
+ extwidth += dp->s_inode + 1;
+ if (f_size) {
+ if (f_humanize)
+ extwidth += dp->s_size + 1;
+ else
+ extwidth += dp->s_block + 1;
+ }
+ if (f_type)
+ extwidth += 1;
+
+ for (col = 0, p = dp->list; p != NULL; p = p->fts_link) {
+ if (IS_NOPRINT(p))
+ continue;
+ if (col > 0) {
+ (void)putchar(','), col++;
+ if (col + 1 + extwidth + p->fts_namelen >= termwidth)
+ (void)putchar('\n'), col = 0;
+ else
+ (void)putchar(' '), col++;
+ }
+ col += printaname(globals, p, dp->s_inode,
+ f_humanize && 0 ? dp->s_size : dp->s_block);
+ }
+ (void)putchar('\n');
+}
+
+/*
+ * print [inode] [size] name
+ * return # of characters printed, no trailing characters.
+ */
+static int
+printaname(rtems_shell_ls_globals* globals,
+ FTSENT *p, int inodefield, int sizefield)
+{
+ struct stat *sp;
+ int chcnt;
+ //char szbuf[5];
+
+ sp = p->fts_statp;
+ chcnt = 0;
+ if (f_inode)
+ chcnt += printf("%*lu ", inodefield, sp->st_ino);
+ if (f_size) {
+#if RTEMS_REMOVED
+ if (f_humanize) {
+ if ((humanize_number(szbuf, sizeof(szbuf), sp->st_size,
+ "", HN_AUTOSCALE,
+ (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ chcnt += printf("%*s ", sizefield, szbuf);
+ } else {
+#endif
+ chcnt += printf("%*llu ", sizefield,
+ (long long)howmany(sp->st_blocks, blocksize));
+#if RTEMS_REMOVED
+ }
+#endif
+ }
+ if (f_octal || f_octal_escape)
+ chcnt += safe_print(globals, p->fts_name);
+ else if (f_nonprint)
+ chcnt += printescaped(globals, p->fts_name);
+ else
+ chcnt += printf("%s", p->fts_name);
+ if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
+ chcnt += printtype(sp->st_mode);
+ return (chcnt);
+}
+
+static void
+printtime(rtems_shell_ls_globals* globals, time_t ftime)
+{
+ int i;
+ char *longstring;
+
+ longstring = ctime(&ftime);
+ for (i = 4; i < 11; ++i)
+ (void)putchar(longstring[i]);
+
+#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY)
+ if (f_sectime)
+ for (i = 11; i < 24; i++)
+ (void)putchar(longstring[i]);
+ else if (ftime + SIXMONTHS > now && ftime - SIXMONTHS < now)
+ for (i = 11; i < 16; ++i)
+ (void)putchar(longstring[i]);
+ else {
+ (void)putchar(' ');
+ for (i = 20; i < 24; ++i)
+ (void)putchar(longstring[i]);
+ }
+ (void)putchar(' ');
+}
+
+static int
+printtype(u_int mode)
+{
+ switch (mode & S_IFMT) {
+ case S_IFDIR:
+ (void)putchar('/');
+ return (1);
+ case S_IFIFO:
+ (void)putchar('|');
+ return (1);
+ case S_IFLNK:
+ (void)putchar('@');
+ return (1);
+ case S_IFSOCK:
+ (void)putchar('=');
+ return (1);
+#if RTEMS_REMOVED
+ case S_IFWHT:
+ (void)putchar('%');
+ return (1);
+#endif
+ }
+ if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
+ (void)putchar('*');
+ return (1);
+ }
+ return (0);
+}
+
+static void
+printlink(rtems_shell_ls_globals* globals, FTSENT *p)
+{
+ int lnklen;
+ char name[MAXPATHLEN + 1], path[MAXPATHLEN + 1];
+
+ if (p->fts_level == FTS_ROOTLEVEL)
+ (void)snprintf(name, sizeof(name), "%s", p->fts_name);
+ else
+ (void)snprintf(name, sizeof(name),
+ "%s/%s", p->fts_parent->fts_accpath, p->fts_name);
+ if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) {
+ (void)fprintf(stderr, "\nls: %s: %s\n", name, strerror(errno));
+ return;
+ }
+ path[lnklen] = '\0';
+ (void)printf(" -> ");
+ if (f_octal || f_octal_escape)
+ (void)safe_print(globals, path);
+ else if (f_nonprint)
+ (void)printescaped(globals, path);
+ else
+ (void)printf("%s", path);
+}
diff --git a/cpukit/libmisc/shell/print_heapinfo.c b/cpukit/libmisc/shell/print_heapinfo.c
new file mode 100644
index 0000000000..ad6db121d2
--- /dev/null
+++ b/cpukit/libmisc/shell/print_heapinfo.c
@@ -0,0 +1,37 @@
+/*
+ * Print Heap Information Structure
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+void rtems_shell_print_heap_info(
+ const char *c,
+ Heap_Information *h
+)
+{
+ printf(
+ "Number of %s blocks: %" PRId32 "\n"
+ "Largest %s block: %" PRId32 "\n"
+ "Total bytes %s: %" PRId32 "\n",
+ c, h->number,
+ c, h->largest,
+ c, h->total
+ );
+}
diff --git a/cpukit/libmisc/shell/pwcache.c b/cpukit/libmisc/shell/pwcache.c
new file mode 100644
index 0000000000..47b8e96fc6
--- /dev/null
+++ b/cpukit/libmisc/shell/pwcache.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)pwcache.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/gen/pwcache.c,v 1.11 2007/01/09 00:27:55 imp Exp $");
+
+#include <sys/types.h>
+
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <string.h>
+//#include <utmp.h>
+
+#define UT_NAMESIZE 64
+
+#define NCACHE 64 /* power of 2 */
+#define MASK (NCACHE - 1) /* bits to store with */
+
+const char *
+user_from_uid(uid_t uid, int nouser)
+{
+ static struct ncache {
+ uid_t uid;
+ int found;
+ char name[UT_NAMESIZE + 1];
+ } c_uid[NCACHE];
+ static int pwopen;
+ struct passwd *pw;
+ struct ncache *cp;
+
+ cp = c_uid + (uid & MASK);
+ if (cp->uid != uid || !*cp->name) {
+ if (pwopen == 0) {
+ //setpassent(1);
+ pwopen = 1;
+ }
+ pw = getpwuid(uid);
+ cp->uid = uid;
+ if (pw != NULL) {
+ cp->found = 1;
+ (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE);
+ cp->name[UT_NAMESIZE] = '\0';
+ } else {
+ cp->found = 0;
+ (void)snprintf(cp->name, UT_NAMESIZE, "%u", uid);
+ if (nouser)
+ return (NULL);
+ }
+ }
+ return ((nouser && !cp->found) ? NULL : cp->name);
+}
+
+char *
+group_from_gid(gid_t gid, int nogroup)
+{
+ static struct ncache {
+ gid_t gid;
+ int found;
+ char name[UT_NAMESIZE + 1];
+ } c_gid[NCACHE];
+ static int gropen;
+ struct group *gr;
+ struct ncache *cp;
+
+ cp = c_gid + (gid & MASK);
+ if (cp->gid != gid || !*cp->name) {
+ if (gropen == 0) {
+ //setgroupent(1);
+ gropen = 1;
+ }
+ gr = getgrgid(gid);
+ cp->gid = gid;
+ if (gr != NULL) {
+ cp->found = 1;
+ (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE);
+ cp->name[UT_NAMESIZE] = '\0';
+ } else {
+ cp->found = 0;
+ (void)snprintf(cp->name, UT_NAMESIZE, "%u", gid);
+ if (nogroup)
+ return (NULL);
+ }
+ }
+ return ((nogroup && !cp->found) ? NULL : cp->name);
+}
+
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
new file mode 100644
index 0000000000..bcc146731b
--- /dev/null
+++ b/cpukit/libmisc/shell/shell.c
@@ -0,0 +1,987 @@
+/*
+ *
+ * Instantatiate a new terminal shell.
+ *
+ * Author:
+ *
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/system.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include <rtems/console.h>
+#include "internal.h"
+
+#include <termios.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pwd.h>
+
+rtems_shell_env_t rtems_global_shell_env = {
+ .magic = rtems_build_name('S', 'E', 'N', 'V'),
+ .devname = CONSOLE_DEVICE_NAME,
+ .taskname = "SHGL",
+ .exit_shell = false,
+ .forever = true,
+ .errorlevel = -1,
+ .echo = false,
+ .cwd = "/",
+ .input = NULL,
+ .output = NULL,
+ .output_append = false,
+ .wake_on_end = RTEMS_ID_NONE,
+ .login_check = NULL
+};
+
+rtems_shell_env_t *rtems_current_shell_env = &rtems_global_shell_env;
+
+/*
+ * Initialize the shell user/process environment information
+ */
+rtems_shell_env_t *rtems_shell_init_env(
+ rtems_shell_env_t *shell_env_p
+)
+{
+ rtems_shell_env_t *shell_env;
+
+ shell_env = malloc(sizeof(rtems_shell_env_t));
+ if ( !shell_env )
+ return NULL;
+ if ( !shell_env_p ) {
+ *shell_env = rtems_global_shell_env;
+ } else {
+ *shell_env = *shell_env_p;
+ }
+ shell_env->taskname = NULL;
+
+ return shell_env;
+}
+
+/*
+ * Completely free a shell_env_t and all associated memory
+ */
+void rtems_shell_env_free(
+ void *ptr
+)
+{
+ rtems_shell_env_t *shell_env;
+ shell_env = (rtems_shell_env_t *) ptr;
+
+ if ( !ptr )
+ return;
+
+ if ( shell_env->input )
+ free((void *)shell_env->input);
+ if ( shell_env->output )
+ free((void *)shell_env->output);
+ free( ptr );
+}
+
+/*
+ * Get a line of user input with modest features
+ */
+int rtems_shell_line_editor(
+ char *cmds[],
+ int count,
+ int size,
+ const char *prompt,
+ FILE *in,
+ FILE *out
+)
+{
+ unsigned int extended_key;
+ int c;
+ int col;
+ int last_col;
+ int output;
+ char line[size];
+ char new_line[size];
+ int up;
+ int cmd = -1;
+ int inserting = 1;
+
+ output = (out && isatty(fileno(in)));
+
+ col = last_col = 0;
+
+ tcdrain(fileno(in));
+ if (out)
+ tcdrain(fileno(out));
+
+ if (output && prompt)
+ fprintf(out, "\r%s", prompt);
+
+ line[0] = 0;
+ new_line[0] = 0;
+
+ for (;;) {
+
+ if (output)
+ fflush(out);
+
+ extended_key = rtems_shell_getchar(in);
+
+ if (extended_key == EOF)
+ return -2;
+
+ c = extended_key & RTEMS_SHELL_KEYS_NORMAL_MASK;
+
+ /*
+ * Make the extended_key usable as a boolean.
+ */
+ extended_key &= ~RTEMS_SHELL_KEYS_NORMAL_MASK;
+
+ up = 0;
+
+ if (extended_key)
+ {
+ switch (c)
+ {
+ case RTEMS_SHELL_KEYS_END:
+ if (output)
+ fprintf(out, "%s", line + col);
+ col = (int) strlen (line);
+ break;
+
+ case RTEMS_SHELL_KEYS_HOME:
+ if (output) {
+ if (prompt)
+ fprintf(out,"\r%s", prompt);
+ }
+ col = 0;
+ break;
+
+ case RTEMS_SHELL_KEYS_LARROW:
+ if (col > 0)
+ {
+ col--;
+ if (output)
+ fputc('\b', out);
+ }
+ break;
+
+ case RTEMS_SHELL_KEYS_RARROW:
+ if ((col < size) && (line[col] != '\0'))
+ {
+ if (output)
+ fprintf(out, "%c", line[col]);
+ col++;
+ }
+ break;
+
+ case RTEMS_SHELL_KEYS_UARROW:
+ if ((cmd >= (count - 1)) || (strlen(cmds[cmd + 1]) == 0)) {
+ if (output)
+ fputc('\x7', out);
+ break;
+ }
+
+ up = 1;
+
+ /* drop through */
+ case RTEMS_SHELL_KEYS_DARROW:
+
+ {
+ int last_cmd = cmd;
+ int clen = strlen (line);
+
+ if (prompt)
+ clen += strlen(prompt);
+
+ if (up) {
+ cmd++;
+ } else {
+ if (cmd < 0) {
+ if (output)
+ fprintf(out, "\x7");
+ break;
+ }
+ else
+ cmd--;
+ }
+
+ if ((last_cmd < 0) || (strcmp(cmds[last_cmd], line) != 0))
+ memcpy (new_line, line, size);
+
+ if (cmd < 0)
+ memcpy (line, new_line, size);
+ else
+ memcpy (line, cmds[cmd], size);
+
+ col = strlen (line);
+
+ if (output) {
+ fprintf(out,"\r%*c", clen, ' ');
+ fprintf(out,"\r%s%s", prompt, line);
+ }
+ }
+ break;
+
+ case RTEMS_SHELL_KEYS_DEL:
+ if (line[col] != '\0')
+ {
+ int end;
+ int bs;
+ strcpy (&line[col], &line[col + 1]);
+ if (output) {
+ fprintf(out,"\r%s%s ", prompt, line);
+ end = (int) strlen (line);
+ for (bs = 0; bs < ((end - col) + 1); bs++)
+ fputc('\b', out);
+ }
+ }
+ break;
+
+ case RTEMS_SHELL_KEYS_INS:
+ inserting = inserting ? 0 : 1;
+ break;
+ }
+ }
+ else
+ {
+ switch (c)
+ {
+ case 1:/*Control-a*/
+ if (output) {
+ if (prompt)
+ fprintf(out,"\r%s", prompt);
+ }
+ col = 0;
+ break;
+
+ case 5:/*Control-e*/
+ if (output)
+ fprintf(out, "%s", line + col);
+ col = (int) strlen (line);
+ break;
+
+ case 11:/*Control-k*/
+ if (line[col]) {
+ if (output) {
+ int end = strlen(line);
+ int bs;
+ fprintf(out,"%*c", end - col, ' ');
+ for (bs = 0; bs < (end - col); bs++)
+ fputc('\b', out);
+ }
+ line[col] = '\0';
+ }
+ break;
+
+ case 0x04:/*Control-d*/
+ if (strlen(line))
+ break;
+ case EOF:
+ if (output)
+ fputc('\n', out);
+ return -2;
+
+ case '\f':
+ if (output) {
+ int end;
+ int bs;
+ fputc('\f',out);
+ fprintf(out,"\r%s%s", prompt, line);
+ end = (int) strlen (line);
+ for (bs = 0; bs < (end - col); bs++)
+ fputc('\b', out);
+ }
+ break;
+
+ case '\b':
+ case '\x7f':
+ if (col > 0)
+ {
+ int bs;
+ col--;
+ strcpy (line + col, line + col + 1);
+ if (output) {
+ fprintf(out,"\b%s \b", line + col);
+ for (bs = 0; bs < ((int) strlen (line) - col); bs++)
+ fputc('\b', out);
+ }
+ }
+ break;
+
+ case '\n':
+ case '\r':
+ {
+ /*
+ * Process the command.
+ */
+ if (output)
+ fprintf(out,"\n");
+
+ /*
+ * Only process the command if we have a command and it is not
+ * repeated in the history.
+ */
+ if (strlen(line) == 0) {
+ cmd = -1;
+ } else {
+ if ((cmd < 0) || (strcmp(line, cmds[cmd]) != 0)) {
+ if (count > 1)
+ memmove(cmds[1], cmds[0], (count - 1) * size);
+ memmove (cmds[0], line, size);
+ cmd = 0;
+ }
+ }
+ }
+ return cmd;
+
+ default:
+ if ((col < (size - 1)) && (c >= ' ') && (c <= '~')) {
+ int end = strlen (line);
+ if (inserting && (col < end) && (end < size)) {
+ int ch, bs;
+ for (ch = end + 1; ch > col; ch--)
+ line[ch] = line[ch - 1];
+ if (output) {
+ fprintf(out, "%s", line + col);
+ for (bs = 0; bs < (end - col + 1); bs++)
+ fputc('\b', out);
+ }
+ }
+ line[col++] = c;
+ if (col > end)
+ line[col] = '\0';
+ if (output)
+ fputc(c, out);
+ }
+ break;
+ }
+ }
+ }
+ return -2;
+}
+
+/* ----------------------------------------------- *
+ * - The shell TASK
+ * Poor but enough..
+ * TODO: Redirection. Tty Signals. ENVVARs. Shell language.
+ * ----------------------------------------------- */
+
+void rtems_shell_init_issue(void)
+{
+ static bool issue_inited=false;
+ struct stat buf;
+
+ if (issue_inited)
+ return;
+ issue_inited = true;
+
+ /* dummy call to init /etc dir */
+ getpwnam("root");
+
+ if (stat("/etc/issue",&buf)) {
+ rtems_shell_write_file("/etc/issue",
+ "\n"
+ "Welcome to @V\\n"
+ "Login into @S\\n");
+ }
+
+ if (stat("/etc/issue.net",&buf)) {
+ rtems_shell_write_file("/etc/issue.net",
+ "\n"
+ "Welcome to %v\n"
+ "running on %m\n");
+ }
+}
+
+static bool rtems_shell_login(FILE * in,FILE * out) {
+ FILE *fd;
+ int c;
+ time_t t;
+
+ rtems_shell_init_issue();
+ setuid(0);
+ setgid(0);
+ rtems_current_user_env->euid =
+ rtems_current_user_env->egid =0;
+
+ if (out) {
+ if ((rtems_current_shell_env->devname[5]!='p')||
+ (rtems_current_shell_env->devname[6]!='t')||
+ (rtems_current_shell_env->devname[7]!='y')) {
+ fd = fopen("/etc/issue","r");
+ if (fd) {
+ while ((c=fgetc(fd))!=EOF) {
+ if (c=='@') {
+ switch(c=fgetc(fd)) {
+ case 'L':
+ fprintf(out,"%s",rtems_current_shell_env->devname);
+ break;
+ case 'B':
+ fprintf(out,"0");
+ break;
+ case 'T':
+ case 'D':
+ time(&t);
+ fprintf(out,"%s",ctime(&t));
+ break;
+ case 'S':
+ fprintf(out,"RTEMS");
+ break;
+ case 'V':
+ fprintf(out,"%s\n%s",_RTEMS_version, _Copyright_Notice);
+ break;
+ case '@':
+ fprintf(out,"@");
+ break;
+ default :
+ fprintf(out,"@%c",c);
+ break;
+ }
+ } else if (c=='\\') {
+ switch(c=fgetc(fd)) {
+ case '\\': fprintf(out,"\\"); break;
+ case 'b': fprintf(out,"\b"); break;
+ case 'f': fprintf(out,"\f"); break;
+ case 'n': fprintf(out,"\n"); break;
+ case 'r': fprintf(out,"\r"); break;
+ case 's': fprintf(out," "); break;
+ case 't': fprintf(out,"\t"); break;
+ case '@': fprintf(out,"@"); break;
+ }
+ } else {
+ fputc(c,out);
+ }
+ }
+ fclose(fd);
+ }
+ } else {
+ fd = fopen("/etc/issue.net","r");
+ if (fd) {
+ while ((c=fgetc(fd))!=EOF) {
+ if (c=='%') {
+ switch(c=fgetc(fd)) {
+ case 't':
+ fprintf(out,"%s",rtems_current_shell_env->devname);
+ break;
+ case 'h':
+ fprintf(out,"0");
+ break;
+ case 'D':
+ fprintf(out," ");
+ break;
+ case 'd':
+ time(&t);
+ fprintf(out,"%s",ctime(&t));
+ break;
+ case 's':
+ fprintf(out,"RTEMS");
+ break;
+ case 'm':
+ fprintf(out,"(" CPU_NAME "/" CPU_MODEL_NAME ")");
+ break;
+ case 'r':
+ fprintf(out,_RTEMS_version);
+ break;
+ case 'v':
+ fprintf(out,"%s\n%s",_RTEMS_version,_Copyright_Notice);
+ break;
+ case '%':fprintf(out,"%%");
+ break;
+ default:
+ fprintf(out,"%%%c",c);
+ break;
+ }
+ } else {
+ fputc(c,out);
+ }
+ }
+ fclose(fd);
+ }
+ }
+ }
+
+ return rtems_shell_login_prompt(
+ in,
+ out,
+ rtems_current_shell_env->devname,
+ rtems_current_shell_env->login_check
+ );
+}
+
+#if defined(SHELL_DEBUG)
+void rtems_shell_print_env(
+ rtems_shell_env_t * shell_env
+)
+{
+ if ( !shell_env ) {
+ printk( "shell_env is NULL\n" );
+ return;
+ }
+ printk( "shell_env=%p\n"
+ "shell_env->magic=0x%08x\t"
+ "shell_env->devname=%s\n"
+ "shell_env->taskname=%s\t"
+ "shell_env->exit_shell=%d\t"
+ "shell_env->forever=%d\n",
+ shell_env->magic,
+ shell_env->devname,
+ ((shell_env->taskname) ? shell_env->taskname : "NOT SET"),
+ shell_env->exit_shell,
+ shell_env->forever
+ );
+}
+#endif
+
+rtems_task rtems_shell_task(rtems_task_argument task_argument)
+{
+ rtems_shell_env_t *shell_env = (rtems_shell_env_t*) task_argument;
+ rtems_id wake_on_end = shell_env->wake_on_end;
+ rtems_shell_main_loop( shell_env );
+ if (wake_on_end != RTEMS_INVALID_ID)
+ rtems_event_send (wake_on_end, RTEMS_EVENT_1);
+ rtems_task_delete( RTEMS_SELF );
+}
+
+#define RTEMS_SHELL_MAXIMUM_ARGUMENTS (128)
+#define RTEMS_SHELL_CMD_SIZE (128)
+#define RTEMS_SHELL_CMD_COUNT (32)
+#define RTEMS_SHELL_PROMPT_SIZE (128)
+
+bool rtems_shell_main_loop(
+ rtems_shell_env_t *shell_env_arg
+)
+{
+ rtems_shell_env_t *shell_env;
+ rtems_shell_cmd_t *shell_cmd;
+ rtems_status_code sc;
+ struct termios term;
+ struct termios previous_term;
+ char *prompt = NULL;
+ int cmd;
+ int cmd_count = 1; /* assume a script and so only 1 command line */
+ char *cmds[RTEMS_SHELL_CMD_COUNT];
+ char *cmd_argv;
+ int argc;
+ char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS];
+ bool result = true;
+ bool input_file = false;
+ int line = 0;
+ FILE *stdinToClose = NULL;
+ FILE *stdoutToClose = NULL;
+
+ rtems_shell_initialize_command_set();
+
+ shell_env =
+ rtems_current_shell_env = rtems_shell_init_env( shell_env_arg );
+
+ /*
+ * @todo chrisj
+ * Remove the use of task variables. Change to have a single
+ * allocation per shell and then set into a notepad register
+ * in the TCB. Provide a function to return the pointer.
+ * Task variables are a virus to embedded systems software.
+ */
+ sc = rtems_task_variable_add(
+ RTEMS_SELF,
+ (void*)&rtems_current_shell_env,
+ rtems_shell_env_free
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_error(sc,"rtems_task_variable_add(current_shell_env):");
+ return false;
+ }
+
+ setuid(0);
+ setgid(0);
+
+ rtems_current_user_env->euid = rtems_current_user_env->egid = 0;
+
+ fileno(stdout);
+
+ /* fprintf( stderr,
+ "-%s-%s-\n", shell_env->input, shell_env->output );
+ */
+
+ if (shell_env->output && strcmp(shell_env->output, "stdout") != 0) {
+ if (strcmp(shell_env->output, "stderr") == 0) {
+ stdout = stderr;
+ } else if (strcmp(shell_env->output, "/dev/null") == 0) {
+ fclose (stdout);
+ } else {
+ FILE *output = fopen(shell_env_arg->output,
+ shell_env_arg->output_append ? "a" : "w");
+ if (!output) {
+ fprintf(stderr, "shell: open output %s failed: %s\n",
+ shell_env_arg->output, strerror(errno));
+ return false;
+ }
+ stdout = output;
+ stdoutToClose = output;
+ }
+ }
+
+ if (shell_env->input && strcmp(shell_env_arg->input, "stdin") != 0) {
+ FILE *input = fopen(shell_env_arg->input, "r");
+ if (!input) {
+ fprintf(stderr, "shell: open input %s failed: %s\n",
+ shell_env_arg->input, strerror(errno));
+ return false;
+ }
+ stdin = input;
+ stdinToClose = input;
+ shell_env->forever = false;
+ input_file =true;
+ }
+ else {
+ /* make a raw terminal,Linux Manuals */
+ if (tcgetattr(fileno(stdin), &previous_term) >= 0) {
+ term = previous_term;
+ term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+ term.c_oflag &= ~OPOST;
+ term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
+ term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+ term.c_cflag |= CLOCAL | CREAD;
+ term.c_cc[VMIN] = 1;
+ term.c_cc[VTIME] = 0;
+ if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
+ fprintf(stderr,
+ "shell:cannot set terminal attributes(%s)\n",shell_env->devname);
+ }
+ }
+ cmd_count = RTEMS_SHELL_CMD_COUNT;
+ prompt = malloc(RTEMS_SHELL_PROMPT_SIZE);
+ if (!prompt)
+ fprintf(stderr,
+ "shell:cannot allocate prompt memory\n");
+ }
+
+ setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
+ setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
+
+ rtems_shell_initialize_command_set();
+
+ /*
+ * Allocate the command line buffers.
+ */
+ cmd_argv = malloc (RTEMS_SHELL_CMD_SIZE);
+ if (!cmd_argv) {
+ fprintf(stderr, "no memory for command line buffers\n" );
+ }
+
+ cmds[0] = calloc (cmd_count, RTEMS_SHELL_CMD_SIZE);
+ if (!cmds[0]) {
+ fprintf(stderr, "no memory for command line buffers\n" );
+ }
+
+ if (cmd_argv && cmds[0]) {
+
+ memset (cmds[0], 0, cmd_count * RTEMS_SHELL_CMD_SIZE);
+
+ for (cmd = 1; cmd < cmd_count; cmd++) {
+ cmds[cmd] = cmds[cmd - 1] + RTEMS_SHELL_CMD_SIZE;
+ }
+
+ do {
+ /* Set again root user and root filesystem, side effect of set_priv..*/
+ sc = rtems_libio_set_private_env();
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_error(sc,"rtems_libio_set_private_env():");
+ result = false;
+ break;
+ }
+
+ /*
+ * By using result here, we can fall to the bottom of the
+ * loop when the connection is dropped during login and
+ * keep on trucking.
+ */
+ if (shell_env->login_check != NULL) {
+ result = rtems_shell_login(stdin,stdout);
+ } else {
+ result = true;
+ }
+
+ if (result) {
+ const char *c;
+ memset (cmds[0], 0, cmd_count * RTEMS_SHELL_CMD_SIZE);
+ if (!input_file) {
+ rtems_shell_cat_file(stdout,"/etc/motd");
+ fprintf(stdout, "\n"
+ "RTEMS SHELL (Ver.1.0-FRC):%s. " \
+ __DATE__". 'help' to list commands.\n",
+ shell_env->devname);
+ }
+
+ if (input_file)
+ chdir(shell_env->cwd);
+ else
+ chdir("/"); /* XXX: chdir to getpwent homedir */
+
+ shell_env->exit_shell = false;
+
+ for (;;) {
+ int cmd;
+
+ /* Prompt section */
+ if (prompt) {
+ rtems_shell_get_prompt(shell_env, prompt,
+ RTEMS_SHELL_PROMPT_SIZE);
+ }
+
+ /* getcmd section */
+ cmd = rtems_shell_line_editor(cmds, cmd_count,
+ RTEMS_SHELL_CMD_SIZE, prompt,
+ stdin, stdout);
+
+ if (cmd == -1)
+ continue; /* empty line */
+
+ if (cmd == -2)
+ break; /*EOF*/
+
+ line++;
+
+ if (shell_env->echo)
+ fprintf(stdout, "%d: %s\n", line, cmds[cmd]);
+
+ /* evaluate cmd section */
+ c = cmds[cmd];
+ while (*c) {
+ if (!isblank((unsigned char)*c))
+ break;
+ c++;
+ }
+
+ if (*c == '\0') /* empty line */
+ continue;
+
+ if (*c == '#') { /* comment character */
+ cmds[cmd][0] = 0;
+ continue;
+ }
+
+ if (!strcmp(cmds[cmd],"bye") || !strcmp(cmds[cmd],"exit")) {
+ fprintf(stdout, "Shell exiting\n" );
+ break;
+ } else if (!strcmp(cmds[cmd],"shutdown")) { /* exit application */
+ fprintf(stdout, "System shutting down at user request\n" );
+ exit(0);
+ }
+
+ /* exec cmd section */
+ /* TODO:
+ * To avoid user crash catch the signals.
+ * Open a new stdio files with posibility of redirection *
+ * Run in a new shell task background. (unix &)
+ * Resuming. A little bash.
+ */
+ memcpy (cmd_argv, cmds[cmd], RTEMS_SHELL_CMD_SIZE);
+ if (!rtems_shell_make_args(cmd_argv, &argc, argv,
+ RTEMS_SHELL_MAXIMUM_ARGUMENTS)) {
+ shell_cmd = rtems_shell_lookup_cmd(argv[0]);
+ if ( argv[0] == NULL ) {
+ shell_env->errorlevel = -1;
+ } else if ( shell_cmd == NULL ) {
+ shell_env->errorlevel = rtems_shell_script_file(argc, argv);
+ } else {
+ shell_env->errorlevel = shell_cmd->command(argc, argv);
+ }
+ }
+
+ /* end exec cmd section */
+ if (shell_env->exit_shell)
+ break;
+ }
+
+ fflush( stdout );
+ fflush( stderr );
+ }
+ } while (result && shell_env->forever);
+
+ }
+
+ if (cmds[0])
+ free (cmds[0]);
+ if (cmd_argv)
+ free (cmd_argv);
+ if (prompt)
+ free (prompt);
+
+ if (stdinToClose) {
+ fclose( stdinToClose );
+ } else {
+ if (tcsetattr(fileno(stdin), TCSADRAIN, &previous_term) < 0) {
+ fprintf(
+ stderr,
+ "shell: cannot reset terminal attributes (%s)\n",
+ shell_env->devname
+ );
+ }
+ }
+ if ( stdoutToClose )
+ fclose( stdoutToClose );
+ return result;
+}
+
+/* ----------------------------------------------- */
+static rtems_status_code rtems_shell_run (
+ const char *task_name,
+ size_t task_stacksize,
+ rtems_task_priority task_priority,
+ const char *devname,
+ bool forever,
+ bool wait,
+ const char *input,
+ const char *output,
+ bool output_append,
+ rtems_id wake_on_end,
+ bool echo,
+ rtems_shell_login_check_t login_check
+)
+{
+ rtems_id task_id;
+ rtems_status_code sc;
+ rtems_shell_env_t *shell_env;
+ rtems_name name;
+
+ if ( task_name && strlen(task_name) >= 4)
+ name = rtems_build_name(
+ task_name[0], task_name[1], task_name[2], task_name[3]);
+ else
+ name = rtems_build_name( 'S', 'E', 'N', 'V' );
+
+ sc = rtems_task_create(
+ name,
+ task_priority,
+ task_stacksize,
+ RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
+ RTEMS_LOCAL | RTEMS_FLOATING_POINT,
+ &task_id
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_error(sc,"creating task %s in shell_init()",task_name);
+ return sc;
+ }
+
+ shell_env = rtems_shell_init_env( NULL );
+ if ( !shell_env ) {
+ rtems_error(RTEMS_NO_MEMORY,
+ "allocating shell_env %s in shell_init()",task_name);
+ return RTEMS_NO_MEMORY;
+ }
+ shell_env->devname = devname;
+ shell_env->taskname = task_name;
+ shell_env->exit_shell = false;
+ shell_env->forever = forever;
+ shell_env->echo = echo;
+ shell_env->input = strdup (input);
+ shell_env->output = strdup (output);
+ shell_env->output_append = output_append;
+ shell_env->wake_on_end = wake_on_end;
+ shell_env->login_check = login_check;
+
+ getcwd(shell_env->cwd, sizeof(shell_env->cwd));
+
+ sc = rtems_task_start(task_id, rtems_shell_task,
+ (rtems_task_argument) shell_env);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_error(sc,"starting task %s in shell_init()",task_name);
+ return sc;
+ }
+
+ if (wait) {
+ rtems_event_set out;
+ sc = rtems_event_receive (RTEMS_EVENT_1, RTEMS_WAIT, 0, &out);
+ }
+
+ return 0;
+}
+
+rtems_status_code rtems_shell_init(
+ const char *task_name,
+ size_t task_stacksize,
+ rtems_task_priority task_priority,
+ const char *devname,
+ bool forever,
+ bool wait,
+ rtems_shell_login_check_t login_check
+)
+{
+ rtems_id to_wake = RTEMS_ID_NONE;
+
+ if ( wait )
+ to_wake = rtems_task_self();
+
+ return rtems_shell_run(
+ task_name, /* task_name */
+ task_stacksize, /* task_stacksize */
+ task_priority, /* task_priority */
+ devname, /* devname */
+ forever, /* forever */
+ wait, /* wait */
+ "stdin", /* input */
+ "stdout", /* output */
+ false, /* output_append */
+ to_wake, /* wake_on_end */
+ false, /* echo */
+ login_check /* login check */
+ );
+}
+
+rtems_status_code rtems_shell_script (
+ const char *task_name,
+ size_t task_stacksize,
+ rtems_task_priority task_priority,
+ const char* input,
+ const char* output,
+ bool output_append,
+ bool wait,
+ bool echo
+)
+{
+ rtems_id current_task = RTEMS_INVALID_ID;
+ rtems_status_code sc;
+
+ if (wait) {
+ sc = rtems_task_ident (RTEMS_SELF, RTEMS_LOCAL, &current_task);
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+ }
+
+ sc = rtems_shell_run(
+ task_name, /* task_name */
+ task_stacksize, /* task_stacksize */
+ task_priority, /* task_priority */
+ NULL, /* devname */
+ 0, /* forever */
+ wait, /* wait */
+ input, /* input */
+ output, /* output */
+ output_append, /* output_append */
+ current_task, /* wake_on_end */
+ echo, /* echo */
+ NULL /* login check */
+ );
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ return sc;
+}
diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
new file mode 100644
index 0000000000..759bf71589
--- /dev/null
+++ b/cpukit/libmisc/shell/shell.h
@@ -0,0 +1,292 @@
+/**
+ * @file rtems/shell.h
+ *
+ * Instantatiate a new terminal shell.
+ */
+
+/*
+ * Author:
+ *
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * Thanks at:
+ * Chris Johns
+ *
+ * $Id$
+ */
+
+#ifndef __RTEMS_SHELL_H__
+#define __RTEMS_SHELL_H__
+
+#include <rtems.h>
+#include <stdio.h>
+#include <termios.h>
+#include <rtems/fs.h>
+#include <rtems/libio.h>
+#include <rtems/chain.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Some key labels to define special keys.
+ */
+
+#define RTEMS_SHELL_KEYS_EXTENDED (0x8000)
+#define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff)
+#define RTEMS_SHELL_KEYS_INS (0)
+#define RTEMS_SHELL_KEYS_DEL (1)
+#define RTEMS_SHELL_KEYS_UARROW (2)
+#define RTEMS_SHELL_KEYS_DARROW (3)
+#define RTEMS_SHELL_KEYS_LARROW (4)
+#define RTEMS_SHELL_KEYS_RARROW (5)
+#define RTEMS_SHELL_KEYS_HOME (6)
+#define RTEMS_SHELL_KEYS_END (7)
+#define RTEMS_SHELL_KEYS_F1 (8)
+#define RTEMS_SHELL_KEYS_F2 (9)
+#define RTEMS_SHELL_KEYS_F3 (10)
+#define RTEMS_SHELL_KEYS_F4 (11)
+#define RTEMS_SHELL_KEYS_F5 (12)
+#define RTEMS_SHELL_KEYS_F6 (13)
+#define RTEMS_SHELL_KEYS_F7 (14)
+#define RTEMS_SHELL_KEYS_F8 (15)
+#define RTEMS_SHELL_KEYS_F9 (16)
+#define RTEMS_SHELL_KEYS_F10 (17)
+
+typedef bool (*rtems_shell_login_check_t)(
+ const char * /* user */,
+ const char * /* passphrase */
+);
+
+bool rtems_shell_login_prompt(
+ FILE *in,
+ FILE *out,
+ const char *device,
+ rtems_shell_login_check_t check
+);
+
+bool rtems_shell_login_check(
+ const char *user,
+ const char *passphrase
+);
+
+typedef int (*rtems_shell_command_t)(int argc, char **argv);
+
+struct rtems_shell_cmd_tt;
+typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
+
+struct rtems_shell_cmd_tt {
+ const char *name;
+ const char *usage;
+ const char *topic;
+ rtems_shell_command_t command;
+ rtems_shell_cmd_t *alias;
+ rtems_shell_cmd_t *next;
+};
+
+typedef struct {
+ const char *name;
+ const char *alias;
+} rtems_shell_alias_t;
+
+/*
+ * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
+ * is extended, ie a special key.
+ */
+unsigned int rtems_shell_getchar(FILE *in);
+
+rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
+
+rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
+ rtems_shell_cmd_t *shell_cmd
+);
+
+rtems_shell_cmd_t * rtems_shell_add_cmd(
+ const char *cmd,
+ const char *topic,
+ const char *usage,
+ rtems_shell_command_t command
+);
+
+rtems_shell_cmd_t * rtems_shell_alias_cmd(
+ const char *cmd,
+ const char *alias
+);
+
+int rtems_shell_make_args(
+ char *commandLine,
+ int *argc_p,
+ char **argv_p,
+ int max_args
+);
+
+int rtems_shell_cat_file(
+ FILE *out,
+ const char *name
+);
+
+void rtems_shell_write_file(
+ const char *name,
+ const char *content
+);
+
+int rtems_shell_script_file(
+ int argc,
+ char **argv
+);
+
+/**
+ * Initialise the shell creating tasks to login and run the shell
+ * sessions.
+ *
+ * @param task_name Name of the shell task.
+ * @param task_stacksize The size of the stack. If 0 the default size is used.
+ * @param task_priority The priority the shell runs at.
+ * @param forever Repeat logins.
+ * @param wait Caller should block until shell exits.
+ * @param login_check User login check function, NULL disables login checks.
+ *
+ */
+rtems_status_code rtems_shell_init(
+ const char *task_name,
+ size_t task_stacksize,
+ rtems_task_priority task_priority,
+ const char *devname,
+ bool forever,
+ bool wait,
+ rtems_shell_login_check_t login_check
+);
+
+/**
+ * Run a shell script creating a shell tasks to execute the command under.
+ *
+ * @param task_name Name of the shell task.
+ * @param task_stacksize The size of the stack. If 0 the default size is used.
+ * @param task_priority The priority the shell runs at.
+ * @param input The file of commands. Can be 'stdin' to use stdin.
+ * @param output The output file to write commands to. Can be 'stdout',
+ * 'stderr' or '/dev/null'.
+ * @param output_append Append the output to the file or truncate the file.
+ * Create if it does not exist.
+ * @param wait Wait for the script to finish.
+ */
+rtems_status_code rtems_shell_script(
+ const char *task_name,
+ size_t task_stacksize, /* 0 default*/
+ rtems_task_priority task_priority,
+ const char *input,
+ const char *output,
+ bool output_append,
+ bool wait,
+ bool echo
+);
+
+/**
+ * Private environment associated with each shell instance.
+ */
+typedef struct {
+ /** 'S','E','N','V': Shell Environment */
+ rtems_name magic;
+ const char *devname;
+ const char *taskname;
+ bool exit_shell; /* logout */
+ bool forever; /* repeat login */
+ int errorlevel;
+ bool echo;
+ char cwd[256];
+ const char *input;
+ const char *output;
+ bool output_append;
+ rtems_id wake_on_end;
+ rtems_shell_login_check_t login_check;
+} rtems_shell_env_t;
+
+bool rtems_shell_main_loop(
+ rtems_shell_env_t *rtems_shell_env
+);
+
+extern rtems_shell_env_t rtems_global_shell_env;
+extern rtems_shell_env_t *rtems_current_shell_env;
+
+/*
+ * The types of file systems we can mount. We have them broken out
+ * out like this so they can be configured by shellconfig.h. The
+ * mount command needs special treatment due to some file systems
+ * being dependent on the network stack and some not. If we had
+ * all possible file systems being included it would force the
+ * networking stack into the applcation and this may not be
+ * required.
+ */
+struct rtems_shell_filesystems_tt;
+typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
+
+typedef int (*rtems_shell_filesystems_mounter_t)(
+ const char* driver,
+ const char* path,
+ rtems_shell_filesystems_t* fs,
+ rtems_filesystem_options_t options
+);
+
+struct rtems_shell_filesystems_tt {
+ rtems_chain_node link;
+ const char *name;
+ int driver_needed;
+ const rtems_filesystem_operations_table *fs_ops;
+ rtems_shell_filesystems_mounter_t mounter;
+};
+
+/**
+ * This method dynamically builds the command line prompt string
+ * and places it in @a prompt.
+ *
+ * @param[in] shell_env is the shell execution environment
+ * @param[in] prompt is a pointer to a string buffer area
+ * @param[in] size is length of the prompt buffer area
+ *
+ * @return This method fills in the memory pointed to by @a prompt.
+ *
+ * @note An application specific implementation can be provided
+ * by the user.
+ */
+void rtems_shell_get_prompt(
+ rtems_shell_env_t *shell_env,
+ char *prompt,
+ size_t size
+);
+
+/**
+ * Helper for the mount command.
+ *
+ * @param[in] driver The path to the driver.
+ * @param[in] path The path to mount on.
+ * @param[in] fs The file system definition.
+ * @param[in] options Special file system options.
+ */
+int rtems_shell_libc_mounter(
+ const char* driver,
+ const char* path,
+ rtems_shell_filesystems_t* fs,
+ rtems_filesystem_options_t options
+);
+
+/**
+ * Add a new file system mount configuration to the mount command.
+ *
+ * @param[in] fs The file system mount data.
+ */
+void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs);
+
+/**
+ * Delete file system mount configuration from the mount command.
+ *
+ * @param[in] fs The file system mount data to remove.
+ */
+void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c
new file mode 100644
index 0000000000..2abaed9242
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_cmdset.c
@@ -0,0 +1,234 @@
+/*
+ *
+ * Shell Command Set Management
+ *
+ * Author:
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+#include <termios.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include "internal.h"
+
+/*
+ * Common linked list of shell commands.
+ *
+ * Because the help report is very long, there is a topic for each command.
+ *
+ * Help list the topics
+ * help [topic] list the commands for the topic
+ * help [command] help for the command
+ *
+ */
+
+rtems_shell_cmd_t * rtems_shell_first_cmd;
+rtems_shell_topic_t * rtems_shell_first_topic;
+
+/*
+ * Find the topic from the set of topics registered.
+ */
+rtems_shell_topic_t * rtems_shell_lookup_topic(const char * topic) {
+ rtems_shell_topic_t * shell_topic;
+ shell_topic=rtems_shell_first_topic;
+
+ while (shell_topic) {
+ if (!strcmp(shell_topic->topic,topic))
+ return shell_topic;
+ shell_topic=shell_topic->next;
+ }
+ return (rtems_shell_topic_t *) NULL;
+}
+
+/*
+ * Add a new topic to the list of topics
+ */
+rtems_shell_topic_t * rtems_shell_add_topic(const char * topic) {
+ rtems_shell_topic_t * current,*aux;
+
+ if (!rtems_shell_first_topic) {
+ aux = malloc(sizeof(rtems_shell_topic_t));
+ aux->topic = topic;
+ aux->next = (rtems_shell_topic_t*)NULL;
+ return rtems_shell_first_topic = aux;
+ }
+ current=rtems_shell_first_topic;
+ if (!strcmp(topic,current->topic))
+ return current;
+
+ while (current->next) {
+ if (!strcmp(topic,current->next->topic))
+ return current->next;
+ current=current->next;
+ }
+ aux = malloc(sizeof(rtems_shell_topic_t));
+ aux->topic = topic;
+ aux->next = (rtems_shell_topic_t*)NULL;
+ current->next = aux;
+ return aux;
+}
+
+/*
+ * Find the command in the set
+ */
+rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char * cmd) {
+ rtems_shell_cmd_t * shell_cmd;
+ shell_cmd=rtems_shell_first_cmd;
+ while (shell_cmd) {
+ if (!strcmp(shell_cmd->name,cmd)) return shell_cmd;
+ shell_cmd=shell_cmd->next;
+ };
+ return (rtems_shell_cmd_t *) NULL;
+}
+
+/*
+ * Add a command structure to the set of known commands
+ */
+rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
+ rtems_shell_cmd_t *shell_cmd
+)
+{
+ rtems_shell_cmd_t *shell_pvt;
+
+ shell_pvt = rtems_shell_first_cmd;
+ while (shell_pvt) {
+ if (strcmp(shell_pvt->name, shell_cmd->name) == 0)
+ return NULL;
+ shell_pvt = shell_pvt->next;
+ }
+
+ if ( !rtems_shell_first_cmd ) {
+ rtems_shell_first_cmd = shell_cmd;
+ } else {
+ shell_pvt = rtems_shell_first_cmd;
+ while (shell_pvt->next)
+ shell_pvt = shell_pvt->next;
+ shell_pvt->next = shell_cmd;
+ }
+ rtems_shell_add_topic( shell_cmd->topic );
+ return shell_cmd;
+}
+
+/*
+ * Add a command as a set of arguments to the set and
+ * allocate the command structure on the fly.
+ */
+rtems_shell_cmd_t * rtems_shell_add_cmd(
+ const char *name,
+ const char *topic,
+ const char *usage,
+ rtems_shell_command_t command
+)
+{
+ rtems_shell_cmd_t *shell_cmd = NULL;
+ char *my_name = NULL;
+ char *my_topic = NULL;
+ char *my_usage = NULL;
+
+ /* Reject empty commands */
+ if (name == NULL || command == NULL) {
+ return NULL;
+ }
+
+ /* Allocate command stucture */
+ shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
+ if (shell_cmd == NULL) {
+ return NULL;
+ }
+
+ /* Allocate strings */
+ my_name = strdup(name);
+ my_topic = strdup(topic);
+ my_usage = strdup(usage);
+
+ /* Assign values */
+ shell_cmd->name = my_name;
+ shell_cmd->topic = my_topic;
+ shell_cmd->usage = my_usage;
+ shell_cmd->command = command;
+ shell_cmd->alias = NULL;
+ shell_cmd->next = NULL;
+
+ if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
+ /* Something is wrong, free allocated resources */
+ free(my_usage);
+ free(my_topic);
+ free(my_name);
+ free(shell_cmd);
+
+ return NULL;
+ }
+
+ return shell_cmd;
+}
+
+
+void rtems_shell_initialize_command_set(void)
+{
+ rtems_shell_cmd_t **c;
+ rtems_shell_alias_t **a;
+
+ for ( c = rtems_shell_Initial_commands ; *c ; c++ ) {
+ rtems_shell_add_cmd_struct( *c );
+ }
+
+ for ( a = rtems_shell_Initial_aliases ; *a ; a++ ) {
+ rtems_shell_alias_cmd( (*a)->name, (*a)->alias );
+ }
+
+ rtems_shell_register_monitor_commands();
+}
+
+/* ----------------------------------------------- *
+ * you can make an alias for every command.
+ * ----------------------------------------------- */
+rtems_shell_cmd_t *rtems_shell_alias_cmd(
+ const char *cmd,
+ const char *alias
+)
+{
+ rtems_shell_cmd_t *shell_cmd, *shell_aux;
+
+ shell_aux = (rtems_shell_cmd_t *) NULL;
+
+ if (alias) {
+ shell_aux = rtems_shell_lookup_cmd(alias);
+ if (shell_aux != NULL) {
+ return NULL;
+ }
+ shell_cmd = rtems_shell_lookup_cmd(cmd);
+ if (shell_cmd != NULL) {
+ shell_aux = rtems_shell_add_cmd(
+ alias,
+ shell_cmd->topic,
+ shell_cmd->usage,
+ shell_cmd->command
+ );
+ if (shell_aux)
+ shell_aux->alias = shell_cmd;
+ }
+ }
+ return shell_aux;
+}
diff --git a/cpukit/libmisc/shell/shell_getchar.c b/cpukit/libmisc/shell/shell_getchar.c
new file mode 100644
index 0000000000..b214a9511f
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_getchar.c
@@ -0,0 +1,176 @@
+/*
+ *
+ * Handle keys for the shell.
+ *
+ * Author:
+ *
+ * Chris Johns (chrisj@rtems.org)
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/system.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include "internal.h"
+
+/*
+ * Taken from the monitor code.
+ */
+
+/*
+ * Translation tables. Not sure if this is the best way to
+ * handle this, how-ever I wish to avoid the overhead of
+ * including a more complete and standard environment such
+ * as ncurses.
+ */
+
+struct translation_table
+{
+ char expecting;
+ const struct translation_table *branch;
+ unsigned int key;
+};
+
+static const struct translation_table trans_one[] =
+{
+ { '\x7e', 0, RTEMS_SHELL_KEYS_HOME },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_two[] =
+{
+ { '~', 0, RTEMS_SHELL_KEYS_INS },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_three[] =
+{
+ { '~', 0, RTEMS_SHELL_KEYS_DEL },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab_csi[] =
+{
+ { '1', trans_one, 0 },
+ { '2', trans_two, 0 },
+ { '3', trans_three, 0 },
+ { 'A', 0, RTEMS_SHELL_KEYS_UARROW },
+ { 'B', 0, RTEMS_SHELL_KEYS_DARROW },
+ { 'D', 0, RTEMS_SHELL_KEYS_LARROW },
+ { 'C', 0, RTEMS_SHELL_KEYS_RARROW },
+ { 'F', 0, RTEMS_SHELL_KEYS_END },
+ { 'H', 0, RTEMS_SHELL_KEYS_HOME },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab_O[] =
+{
+ { '1', 0, RTEMS_SHELL_KEYS_F1 },
+ { '2', 0, RTEMS_SHELL_KEYS_F2 },
+ { '3', 0, RTEMS_SHELL_KEYS_F3 },
+ { '4', 0, RTEMS_SHELL_KEYS_F4 },
+ { '5', 0, RTEMS_SHELL_KEYS_F5 },
+ { '6', 0, RTEMS_SHELL_KEYS_F6 },
+ { '7', 0, RTEMS_SHELL_KEYS_F7 },
+ { '8', 0, RTEMS_SHELL_KEYS_F8 },
+ { '9', 0, RTEMS_SHELL_KEYS_F9 },
+ { ':', 0, RTEMS_SHELL_KEYS_F10 },
+ { 'F', 0, RTEMS_SHELL_KEYS_END },
+ { 'P', 0, RTEMS_SHELL_KEYS_F1 },
+ { 'Q', 0, RTEMS_SHELL_KEYS_F2 },
+ { 'R', 0, RTEMS_SHELL_KEYS_F3 },
+ { 'S', 0, RTEMS_SHELL_KEYS_F4 },
+ { 'T', 0, RTEMS_SHELL_KEYS_F5 },
+ { 'U', 0, RTEMS_SHELL_KEYS_F6 },
+ { 'V', 0, RTEMS_SHELL_KEYS_F7 },
+ { 'W', 0, RTEMS_SHELL_KEYS_F8 },
+ { 'X', 0, RTEMS_SHELL_KEYS_F9 },
+ { 'Y', 0, RTEMS_SHELL_KEYS_F10 },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab[] =
+{
+ { '[', trans_tab_csi, 0 }, /* CSI command sequences */
+ { 'O', trans_tab_O, 0 }, /* O are the fuction keys */
+ { 0, 0, 0 }
+};
+
+/*
+ * Perform a basic tranlation for some ANSI/VT100 key codes.
+ * This code could do with a timeout on the ESC as it is
+ * now lost from the input stream. It is not* used by the
+ * line editor below so considiered not worth the effort.
+ */
+
+unsigned int
+rtems_shell_getchar (FILE *in)
+{
+ const struct translation_table *translation = 0;
+ for (;;)
+ {
+ int c = fgetc (in);
+ if (c == EOF)
+ return EOF;
+ if (c == 27)
+ translation = trans_tab;
+ else
+ {
+ /*
+ * If no translation happing just pass through
+ * and return the key.
+ */
+ if (translation)
+ {
+ /*
+ * Scan the current table for the key, and if found
+ * see if this key is a fork. If so follow it and
+ * wait else return the extended key.
+ */
+ int index = 0;
+ int branched = 0;
+ while ((translation[index].expecting != '\0') ||
+ (translation[index].key != '\0'))
+ {
+ if (translation[index].expecting == c)
+ {
+ /*
+ * A branch is take if more keys are to come.
+ */
+ if (translation[index].branch == 0)
+ return RTEMS_SHELL_KEYS_EXTENDED | translation[index].key;
+ else
+ {
+ translation = translation[index].branch;
+ branched = 1;
+ break;
+ }
+ }
+ index++;
+ }
+ /*
+ * Who knows what these keys are, just drop them.
+ */
+ if (!branched)
+ translation = 0;
+ }
+ else
+ return c;
+ }
+ }
+}
+
diff --git a/cpukit/libmisc/shell/shell_getprompt.c b/cpukit/libmisc/shell/shell_getprompt.c
new file mode 100644
index 0000000000..08c628b219
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_getprompt.c
@@ -0,0 +1,49 @@
+/*
+ * Dynamically build the shell prompt
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/system.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pwd.h>
+
+void rtems_shell_get_prompt(
+ rtems_shell_env_t *shell_env,
+ char *prompt,
+ size_t size
+)
+{
+ char curdir[256];
+
+ /* XXX: show_prompt user adjustable */
+ getcwd(curdir,sizeof(curdir));
+ snprintf(prompt, size - 1, "%s%s[%s] %c ",
+ ((shell_env->taskname) ? shell_env->taskname : ""),
+ ((shell_env->taskname) ? " " : ""),
+ curdir,
+ geteuid()?'$':'#');
+}
diff --git a/cpukit/libmisc/shell/shell_makeargs.c b/cpukit/libmisc/shell/shell_makeargs.c
new file mode 100644
index 0000000000..727ea829c9
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_makeargs.c
@@ -0,0 +1,68 @@
+/*
+ * Split string into argc/argv style argument list
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <ctype.h>
+
+int rtems_shell_make_args(
+ char *commandLine,
+ int *argc_p,
+ char **argv_p,
+ int max_args
+)
+{
+ int argc;
+ char *ch;
+ int status = 0;
+
+ argc = 0;
+ ch = commandLine;
+
+ while ( *ch ) {
+
+ while ( isspace((unsigned char)*ch) ) ch++;
+
+ if ( *ch == '\0' )
+ break;
+
+ if ( *ch == '"' ) {
+ argv_p[ argc ] = ++ch;
+ while ( ( *ch != '\0' ) && ( *ch != '"' ) ) ch++;
+ } else {
+ argv_p[ argc ] = ch;
+ while ( ( *ch != '\0' ) && ( !isspace((unsigned char)*ch) ) ) ch++;
+ }
+
+ argc++;
+
+ if ( *ch == '\0' )
+ break;
+
+ *ch++ = '\0';
+
+ if ( argc == (max_args-1) ) {
+ status = -1;
+ break;
+ }
+
+
+ }
+ argv_p[ argc ] = NULL;
+ *argc_p = argc;
+ return status;
+}
+
diff --git a/cpukit/libmisc/shell/shell_script.c b/cpukit/libmisc/shell/shell_script.c
new file mode 100644
index 0000000000..8854f4af35
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_script.c
@@ -0,0 +1,351 @@
+/*
+ * Shell Script Invocation
+ *
+ * Pseudo-code from Chris Johns, implemented and debugged
+ * by Joel Sherrill.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <unistd.h>
+#define __need_getopt_newlib
+#include <getopt.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/stringto.h>
+#include "internal.h"
+
+static void rtems_shell_joel_usage(void)
+{
+ printf(
+ "joel [args] where args may be:\n"
+ " -o FILE output file (default=stdout)\n"
+ " -p PRIORITY task priority\n"
+ " -s SIZE task stack size\n"
+ " -t NAME task name\n"
+ );
+}
+
+static int findOnPATH(
+ const char *userScriptName,
+ char *scriptFile,
+ size_t scriptFileLength
+)
+{
+ int sc;
+
+ /*
+ * If the user script name starts with a / assume it is a fully
+ * qualified path name and just use it.
+ */
+ if ( userScriptName[0] == '/' ) {
+ strncpy( scriptFile, userScriptName, PATH_MAX );
+ } else {
+ /*
+ * For now, the provided name is just turned into a fully
+ * qualified path name and used. There is no attempt to
+ * search along a path for it.
+ */
+
+ /* XXX should use strncat but what is the limit? */
+ getcwd( scriptFile, PATH_MAX );
+ strncat( scriptFile, "/", PATH_MAX );
+ strncat(
+ scriptFile,
+ ( (userScriptName[0] == '.' && userScriptName[1] == '/') ?
+ &userScriptName[2] : userScriptName),
+ PATH_MAX
+ );
+ }
+
+ sc = access( scriptFile, R_OK );
+ if ( sc ) {
+ return -1;
+ }
+
+ return 0;
+
+#if 0
+ /*
+ * Does the command (argv[0]) contain a path ?, i.e. starts with
+ * '.' or contains a '/'?
+ */
+ /* TODO: Add concept of PATH */
+ if (!contains_path) {
+ /* check PATH environment variable */
+ for (path_part = PATH; path_part; skip to ':')
+ {
+ }
+ if (not found)
+ return -1;
+ }
+#endif
+}
+
+int rtems_shell_main_joel(
+ int argc,
+ char **argv
+);
+
+int rtems_shell_main_joel(
+ int argc,
+ char **argv
+)
+{
+ unsigned long tmp;
+ int option;
+ int sc;
+ int verbose = 0;
+ char *taskName = "JOEL";
+ uint32_t stackSize = RTEMS_MINIMUM_STACK_SIZE * 10;
+ rtems_task_priority taskPriority = 20;
+ char *outputFile = "stdout";
+ rtems_status_code result;
+ char scriptFile[PATH_MAX];
+ struct getopt_data getopt_reent;
+
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+ while ( (option = getopt_r( argc, argv, "o:p:s:t:v", &getopt_reent)) != -1 ) {
+ switch ((char)option) {
+ case 'o':
+ outputFile = getopt_reent.optarg;
+ break;
+ case 'p': {
+ const char *s = getopt_reent.optarg;
+
+ if ( rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
+ printf( "Task Priority argument (%s) is not a number\n", s );
+ return -1;
+ }
+ taskPriority = (rtems_task_priority) tmp;
+ break;
+ }
+ case 's': {
+ const char *s = getopt_reent.optarg;
+
+ if ( rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
+ printf( "Stack size argument (%s) is not a number\n", s );
+ return -1;
+ }
+ stackSize = (uint32_t) tmp;
+ break;
+ }
+ case 't':
+ taskName = getopt_reent.optarg;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case '?':
+ default:
+ rtems_shell_joel_usage();
+ return -1;
+ }
+ }
+
+ if ( verbose ) {
+ fprintf( stderr,
+ "outputFile: %s\n"
+ "taskPriority: %" PRId32 "\n"
+ "stackSize: %" PRId32 "\n"
+ "taskName: %s\n",
+ outputFile,
+ taskPriority,
+ stackSize,
+ taskName
+ );
+ }
+
+ /*
+ * Verify there is a script name past the end of the arguments.
+ * Preincrement to skip program name.
+ */
+ if ( getopt_reent.optind >= argc ) {
+ fprintf( stderr, "Shell: No script to execute\n" );
+ return -1;
+ }
+
+ /*
+ * Find script on the path.
+ *
+ * NOTE: It is terrible that this is done twice but it
+ * seems to be the most expedient thing.
+ */
+ sc = findOnPATH( argv[getopt_reent.optind], scriptFile, PATH_MAX );
+ if ( sc ) {
+ fprintf( stderr, "%s: command not found\n", argv[0] );
+ return -1;
+ }
+
+ /* fprintf( stderr, "SCRIPT: -%s-\n", scriptFile ); */
+
+ /*
+ * I assume that argv[optind...] will have the arguments to
+ * the shell script. But that remains to be implemented.
+ */
+
+ /*
+ * Run the script
+ */
+ result = rtems_shell_script(
+ taskName, /* the name of the task */
+ stackSize, /* stack size */
+ taskPriority, /* task priority */
+ scriptFile, /* the script file */
+ outputFile, /* where to redirect the script */
+ 0, /* run once and exit */
+ 1, /* we will wait */
+ verbose /* do we echo */
+ );
+ if (result)
+ return -1;
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_JOEL_Command = {
+ "joel", /* name */
+ "joel [args] SCRIPT", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_joel, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
+/*
+ * This is a helper function which takes a command as arguments
+ * which has not been located as a built-in command and attempts
+ * to find something in the filesystem with the same name that
+ * appears to be a shell script.
+ */
+int rtems_shell_script_file(
+ int argc __attribute__((unused)),
+ char *argv[]
+)
+{
+ #define FIRST_LINE_LENGTH 128
+ #define SCRIPT_ARGV_LIMIT 32
+ char scriptFile[PATH_MAX];
+ char *scriptHead;
+ char scriptHeadBuffer[FIRST_LINE_LENGTH];
+ int sc;
+ FILE *script;
+ size_t length;
+ int scriptArgc;
+ char *scriptArgv[SCRIPT_ARGV_LIMIT];
+
+ /*
+ * Clear argv pointer array
+ */
+ for ( scriptArgc=0 ; scriptArgc<SCRIPT_ARGV_LIMIT ; scriptArgc++ )
+ scriptArgv[scriptArgc] = NULL;
+
+ /*
+ * Find argv[0] on the path
+ */
+ sc = findOnPATH( argv[0], scriptFile, PATH_MAX );
+ if ( sc ) {
+ fprintf( stderr, "%s: command not found\n", argv[0] );
+ return -1;
+ }
+
+ /*
+ * Open the file so we can see if it looks like a script.
+ */
+ script = fopen( scriptFile, "r" );
+ if ( !script ) {
+ fprintf( stderr, "%s: Unable to open %s\n", argv[0], scriptFile );
+ return -1;
+ }
+
+ /*
+ * Is the script OK to run?
+ * Verify the current user has permission to execute it.
+ *
+ * NOTE: May not work on all file systems
+ */
+ sc = access( scriptFile, X_OK );
+ if ( sc ) {
+ fprintf( stderr, "Unable to execute %s\n", scriptFile );
+ fclose( script );
+ return -1;
+ }
+
+ /*
+ * Try to read the first line from the potential script file
+ */
+ scriptHead = fgets(scriptHeadBuffer, FIRST_LINE_LENGTH, script);
+ if ( !scriptHead ) {
+ fprintf(
+ stderr, "%s: Unable to read first line of %s\n", argv[0], scriptFile );
+ fclose( script );
+ return -1;
+ }
+
+ fclose(script);
+
+ length = strnlen(scriptHead, FIRST_LINE_LENGTH);
+ scriptHead[length - 1] = '\0';
+
+ /* fprintf( stderr, "FIRST LINE: -%s-\n", scriptHead ); */
+
+ /*
+ * Verify the name of the "shell" is joel. This means
+ * the line starts with "#! joel".
+ */
+ if (strncmp("#! joel", scriptHead, 7) != 0) {
+ fprintf( stderr, "%s: Not a joel script %s\n", argv[0], scriptFile );
+ return -1;
+ }
+
+ /*
+ * Do not worry about search path further. We have found the
+ * script, it is executable, and we have successfully read the
+ * first line and found out it is a script.
+ */
+
+ /*
+ * Check for arguments in the first line of the script. This changes
+ * how the shell task is run.
+ */
+
+ sc = rtems_shell_make_args(
+ &scriptHead[3],
+ &scriptArgc,
+ scriptArgv,
+ SCRIPT_ARGV_LIMIT - 1
+ );
+ if ( sc ) {
+ fprintf(
+ stderr, "%s: Error parsing joel arguments %s\n", argv[0], scriptFile );
+ return -1;
+ }
+
+ scriptArgv[ scriptArgc++ ] = scriptFile;
+
+ /*
+ * TODO: How do we pass arguments from here to the script?
+ * At this point, it doesn't matter because we don't
+ * have any way for a shell script to access them.
+ */
+ return rtems_shell_main_joel( scriptArgc, scriptArgv );
+
+ return 0;
+}
diff --git a/cpukit/libmisc/shell/shellconfig.c b/cpukit/libmisc/shell/shellconfig.c
new file mode 100644
index 0000000000..0cb0de0b30
--- /dev/null
+++ b/cpukit/libmisc/shell/shellconfig.c
@@ -0,0 +1,21 @@
+/*
+ * RTEMS Shell Command Set -- DEFAULT Configuration
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define CONFIGURE_SHELL_COMMANDS_INIT
+#define CONFIGURE_SHELL_COMMANDS_ALL
+
+#include <rtems/shellconfig.h>
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
new file mode 100644
index 0000000000..cfc475095e
--- /dev/null
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -0,0 +1,438 @@
+/*
+ * RTEMS Shell Command Set Configuration
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SHELL_CONFIG_h
+#define _RTEMS_SHELL_CONFIG_h
+
+#include <rtems/shell.h>
+
+/*
+ * Externs for all command definition structures
+ */
+extern rtems_shell_cmd_t rtems_shell_HELP_Command;
+extern rtems_shell_cmd_t rtems_shell_ALIAS_Command;
+extern rtems_shell_cmd_t rtems_shell_TIME_Command;
+extern rtems_shell_cmd_t rtems_shell_LOGOFF_Command;
+extern rtems_shell_cmd_t rtems_shell_SETENV_Command;
+extern rtems_shell_cmd_t rtems_shell_GETENV_Command;
+extern rtems_shell_cmd_t rtems_shell_UNSETENV_Command;
+
+extern rtems_shell_cmd_t rtems_shell_MDUMP_Command;
+extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
+extern rtems_shell_cmd_t rtems_shell_MEDIT_Command;
+extern rtems_shell_cmd_t rtems_shell_MFILL_Command;
+extern rtems_shell_cmd_t rtems_shell_MMOVE_Command;
+
+extern rtems_shell_cmd_t rtems_shell_JOEL_Command;
+extern rtems_shell_cmd_t rtems_shell_DATE_Command;
+extern rtems_shell_cmd_t rtems_shell_ECHO_Command;
+extern rtems_shell_cmd_t rtems_shell_SLEEP_Command;
+extern rtems_shell_cmd_t rtems_shell_ID_Command;
+extern rtems_shell_cmd_t rtems_shell_TTY_Command;
+extern rtems_shell_cmd_t rtems_shell_WHOAMI_Command;
+
+extern rtems_shell_cmd_t rtems_shell_CP_Command;
+extern rtems_shell_cmd_t rtems_shell_PWD_Command;
+extern rtems_shell_cmd_t rtems_shell_LS_Command;
+extern rtems_shell_cmd_t rtems_shell_CHDIR_Command;
+extern rtems_shell_cmd_t rtems_shell_MKDIR_Command;
+extern rtems_shell_cmd_t rtems_shell_RMDIR_Command;
+extern rtems_shell_cmd_t rtems_shell_CHROOT_Command;
+extern rtems_shell_cmd_t rtems_shell_CHMOD_Command;
+extern rtems_shell_cmd_t rtems_shell_CAT_Command;
+extern rtems_shell_cmd_t rtems_shell_MKRFS_Command;
+extern rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command;
+extern rtems_shell_cmd_t rtems_shell_MSDOSFMT_Alias;
+extern rtems_shell_cmd_t rtems_shell_MV_Command;
+extern rtems_shell_cmd_t rtems_shell_RM_Command;
+extern rtems_shell_cmd_t rtems_shell_LN_Command;
+extern rtems_shell_cmd_t rtems_shell_MKNOD_Command;
+extern rtems_shell_cmd_t rtems_shell_UMASK_Command;
+extern rtems_shell_cmd_t rtems_shell_MOUNT_Command;
+extern rtems_shell_cmd_t rtems_shell_UNMOUNT_Command;
+extern rtems_shell_cmd_t rtems_shell_BLKSYNC_Command;
+extern rtems_shell_cmd_t rtems_shell_FDISK_Command;
+extern rtems_shell_cmd_t rtems_shell_DD_Command;
+extern rtems_shell_cmd_t rtems_shell_HEXDUMP_Command;
+extern rtems_shell_cmd_t rtems_shell_DEBUGRFS_Command;
+
+extern rtems_shell_cmd_t rtems_shell_RTC_Command;
+
+extern rtems_shell_cmd_t rtems_shell_HALT_Command;
+extern rtems_shell_cmd_t rtems_shell_CPUUSE_Command;
+extern rtems_shell_cmd_t rtems_shell_STACKUSE_Command;
+extern rtems_shell_cmd_t rtems_shell_PERIODUSE_Command;
+extern rtems_shell_cmd_t rtems_shell_WKSPACE_INFO_Command;
+extern rtems_shell_cmd_t rtems_shell_MALLOC_INFO_Command;
+#if RTEMS_NETWORKING
+ extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command;
+ extern rtems_shell_cmd_t rtems_shell_ROUTE_Command;
+ extern rtems_shell_cmd_t rtems_shell_NETSTATS_Command;
+#endif
+
+extern rtems_shell_cmd_t *rtems_shell_Initial_commands[];
+
+/*
+ * Extern for alias commands
+ */
+extern rtems_shell_alias_t rtems_shell_DIR_Alias;
+extern rtems_shell_alias_t rtems_shell_CD_Alias;
+extern rtems_shell_alias_t rtems_shell_EXIT_Alias;
+
+extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
+
+/*
+ * If we are configured to alias a command, then make sure the underlying
+ * command is configured.
+ */
+
+#if !defined(CONFIGURE_SHELL_COMMANDS_ALL)
+ #if defined(CONFIGURE_SHELL_COMMANDS_DIR) && \
+ !defined(CONFIGURE_SHELL_COMMANDS_LS)
+ #define CONFIGURE_SHELL_COMMAND_LS
+ #endif
+
+ #if defined(CONFIGURE_SHELL_COMMANDS_CD) && \
+ !defined(CONFIGURE_SHELL_COMMANDS_CHDIR)
+ #define CONFIGURE_SHELL_COMMAND_CHDIR
+ #endif
+
+ #if defined(CONFIGURE_SHELL_COMMANDS_EXIT) && \
+ !defined(CONFIGURE_SHELL_COMMANDS_LOGOFF)
+ #define CONFIGURE_SHELL_COMMAND_LOGOFF
+ #endif
+#endif
+
+#if defined(CONFIGURE_SHELL_COMMANDS_INIT)
+ rtems_shell_alias_t *rtems_shell_Initial_aliases[] = {
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_DIR)) || \
+ defined(CONFIGURE_SHELL_COMMAND_DIR)
+ &rtems_shell_DIR_Alias,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CD)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CD)
+ &rtems_shell_CD_Alias,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_EXIT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_EXIT)
+ &rtems_shell_EXIT_Alias,
+ #endif
+
+ /*
+ * User defined shell aliases
+ */
+ #if defined(CONFIGURE_SHELL_USER_ALIASES)
+ CONFIGURE_SHELL_USER_ALIASES,
+ #endif
+ NULL
+ };
+
+ rtems_shell_cmd_t *rtems_shell_Initial_commands[] = {
+ /*
+ * General comamnds that should be present
+ */
+ &rtems_shell_HELP_Command,
+ &rtems_shell_ALIAS_Command,
+ &rtems_shell_TIME_Command,
+
+ /*
+ * Common commands that can be optional
+ */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_JOEL)) || \
+ defined(CONFIGURE_SHELL_COMMAND_JOEL)
+ &rtems_shell_JOEL_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_DATE)) || \
+ defined(CONFIGURE_SHELL_COMMAND_DATE)
+ &rtems_shell_DATE_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_ECHO)) || \
+ defined(CONFIGURE_SHELL_COMMAND_ECHO)
+ &rtems_shell_ECHO_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_SLEEP)) || \
+ defined(CONFIGURE_SHELL_COMMAND_SLEEP)
+ &rtems_shell_SLEEP_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_ID)) || \
+ defined(CONFIGURE_SHELL_COMMAND_ID)
+ &rtems_shell_ID_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_TTY)) || \
+ defined(CONFIGURE_SHELL_COMMAND_TTY)
+ &rtems_shell_TTY_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_WHOAMI)) || \
+ defined(CONFIGURE_SHELL_COMMAND_WHOAMI)
+ &rtems_shell_WHOAMI_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_LOGOFF)) || \
+ defined(CONFIGURE_SHELL_COMMAND_LOGOFF)
+ &rtems_shell_LOGOFF_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_SETENV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_SETENV)
+ &rtems_shell_SETENV_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_GETENV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_GETENV)
+ &rtems_shell_GETENV_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CRLENV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_UNSETENV)
+ &rtems_shell_UNSETENV_Command,
+ #endif
+
+ /*
+ * Memory printing/modification family commands
+ */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MDUMP)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MDUMP)
+ &rtems_shell_MDUMP_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_WDUMP)) || \
+ defined(CONFIGURE_SHELL_COMMAND_WDUMP)
+ &rtems_shell_WDUMP_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MEDIT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MEDIT)
+ &rtems_shell_MEDIT_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MFILL)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MFILL)
+ &rtems_shell_MFILL_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MMOVE)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MMOVE)
+ &rtems_shell_MMOVE_Command,
+ #endif
+
+ /*
+ * File and directory commands
+ */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CP)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CP)
+ &rtems_shell_CP_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_PWD)) || \
+ defined(CONFIGURE_SHELL_COMMAND_PWD)
+ &rtems_shell_PWD_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_LS)) || \
+ defined(CONFIGURE_SHELL_COMMAND_LS)
+ &rtems_shell_LS_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CHDIR)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CHDIR)
+ &rtems_shell_CHDIR_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MKDIR)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MKDIR)
+ &rtems_shell_MKDIR_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_RMDIR)) || \
+ defined(CONFIGURE_SHELL_COMMAND_RMDIR)
+ &rtems_shell_RMDIR_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CHROOT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CHROOT)
+ &rtems_shell_CHROOT_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CHMOD)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CHMOD)
+ &rtems_shell_CHMOD_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CAT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CAT)
+ &rtems_shell_CAT_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MKRFS)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MKRFS)
+ &rtems_shell_MKRFS_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MSDOSFMT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MSDOSFMT)
+ &rtems_shell_MSDOSFMT_Command,
+ &rtems_shell_MSDOSFMT_Alias,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MV)
+ &rtems_shell_MV_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_RM)) || \
+ defined(CONFIGURE_SHELL_COMMAND_RM)
+ &rtems_shell_RM_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_LN)) || \
+ defined(CONFIGURE_SHELL_COMMAND_LN)
+ &rtems_shell_LN_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MKNOD)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MKNOD)
+ &rtems_shell_MKNOD_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_UMASK)) || \
+ defined(CONFIGURE_SHELL_COMMAND_UMASK)
+ &rtems_shell_UMASK_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MOUNT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MOUNT)
+ &rtems_shell_MOUNT_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_UNMOUNT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_UNMOUNT)
+ &rtems_shell_UNMOUNT_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_BLKSYNC)) || \
+ defined(CONFIGURE_SHELL_COMMAND_BLKSYNC)
+ &rtems_shell_BLKSYNC_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_FDISK)) || \
+ defined(CONFIGURE_SHELL_COMMAND_FDISK)
+ &rtems_shell_FDISK_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_DD)) || \
+ defined(CONFIGURE_SHELL_COMMAND_DD)
+ &rtems_shell_DD_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_HEXDUMP)) || \
+ defined(CONFIGURE_SHELL_COMMAND_HEXDUMP)
+ &rtems_shell_HEXDUMP_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_DEBUGRFS)) || \
+ defined(CONFIGURE_SHELL_COMMAND_DEBUGRFS)
+ &rtems_shell_DEBUGRFS_Command,
+ #endif
+
+ /*
+ * RTEMS Related commands
+ */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_HALT)) || \
+ defined(CONFIGURE_SHELL_COMMAND_HALT)
+ &rtems_shell_HALT_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CPUUSE)) || \
+ defined(CONFIGURE_SHELL_COMMAND_CPUUSE)
+ &rtems_shell_CPUUSE_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_STACKUSE)) || \
+ defined(CONFIGURE_SHELL_COMMAND_STACKUSE)
+ &rtems_shell_STACKUSE_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_PERIODUSE)) || \
+ defined(CONFIGURE_SHELL_COMMAND_PERIODUSE)
+ &rtems_shell_PERIODUSE_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_WKSPACE_INFO)) || \
+ defined(CONFIGURE_SHELL_COMMAND_WKSPACE_INFO)
+ &rtems_shell_WKSPACE_INFO_Command,
+ #endif
+
+ /*
+ * Malloc family commands
+ */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_MALLOC_INFO)) || \
+ defined(CONFIGURE_SHELL_COMMAND_MALLOC_INFO)
+ &rtems_shell_MALLOC_INFO_Command,
+ #endif
+
+ /*
+ * Network related commands
+ */
+ #if RTEMS_NETWORKING
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_IFCONFIG)) || \
+ defined(CONFIGURE_SHELL_COMMAND_IFCONFIG)
+ &rtems_shell_IFCONFIG_Command,
+ #endif
+
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_ROUTE)) || \
+ defined(CONFIGURE_SHELL_COMMAND_ROUTE)
+ &rtems_shell_ROUTE_Command,
+ #endif
+
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_NETSTATS)) || \
+ defined(CONFIGURE_SHELL_COMMAND_NETSTATS)
+ &rtems_shell_NETSTATS_Command,
+ #endif
+ #endif
+
+ /* Miscanellous shell commands */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) \
+ && !defined(CONFIGURE_SHELL_NO_COMMAND_RTC)) \
+ || defined(CONFIGURE_SHELL_COMMAND_RTC)
+ &rtems_shell_RTC_Command,
+ #endif
+
+ /*
+ * User defined shell commands
+ */
+ #if defined(CONFIGURE_SHELL_USER_COMMANDS)
+ CONFIGURE_SHELL_USER_COMMANDS,
+ #endif
+ NULL
+ };
+
+#endif
+
+#endif
diff --git a/cpukit/libmisc/shell/utils-cp.c b/cpukit/libmisc/shell/utils-cp.c
new file mode 100644
index 0000000000..7b7c7fc771
--- /dev/null
+++ b/cpukit/libmisc/shell/utils-cp.c
@@ -0,0 +1,496 @@
+/* $NetBSD: utils.c,v 1.29 2005/10/15 18:22:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if 0
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
+#else
+__RCSID("$NetBSD: utils.c,v 1.29 2005/10/15 18:22:18 christos Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#if 0
+#include <sys/mman.h>
+#endif
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <utime.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "extern-cp.h"
+
+#define lchmod chmod
+#define lchown chown
+
+#define cp_pct(x, y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
+
+int
+set_utimes(const char *file, struct stat *fs)
+{
+ struct utimbuf tv;
+
+ tv.actime = fs->st_atime;
+ tv.modtime = fs->st_mtime;
+
+ if (utime(file, &tv)) {
+ warn("lutimes: %s", file);
+ return (1);
+ }
+ return (0);
+}
+
+int
+copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *entp, int dne)
+{
+#define MAX_READ max_read
+ int max_read;
+ char* buf;
+ struct stat *fs;
+ ssize_t wcount;
+ size_t wresid;
+ off_t wtotal;
+ int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
+ char *bufp;
+#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
+ char *p;
+#endif
+
+ fs = entp->fts_statp;
+
+ max_read = fs->st_blksize;
+ if (max_read < (8 * 1024))
+ max_read = 8 * 1024;
+ buf = malloc (max_read);
+ if (!buf)
+ {
+ warn("no memory");
+ return (1);
+ }
+
+ if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
+ warn("%s", entp->fts_path);
+ (void)free(buf);
+ return (1);
+ }
+
+ /*
+ * If the file exists and we're interactive, verify with the user.
+ * If the file DNE, set the mode to be the from file, minus setuid
+ * bits, modified by the umask; arguably wrong, but it makes copying
+ * executables work right and it's been that way forever. (The
+ * other choice is 666 or'ed with the execute bits on the from file
+ * modified by the umask.)
+ */
+ if (!dne) {
+#define YESNO "(y/n [n]) "
+ if (nflag) {
+ if (vflag)
+ printf("%s not overwritten\n", to.p_path);
+ (void)close(from_fd);
+ (void)free(buf);
+ return (0);
+ } else if (iflag) {
+ (void)fprintf(stderr, "overwrite %s? %s",
+ to.p_path, YESNO);
+ checkch = ch = getchar();
+ while (ch != '\n' && ch != EOF)
+ ch = getchar();
+ if (checkch != 'y' && checkch != 'Y') {
+ (void)close(from_fd);
+ (void)free(buf);
+ (void)fprintf(stderr, "not overwritten\n");
+ return (1);
+ }
+ }
+
+ if (fflag) {
+ /* remove existing destination file name,
+ * create a new file */
+ (void)unlink(to.p_path);
+ if (!lflag)
+ to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
+ fs->st_mode & ~(S_ISUID | S_ISGID));
+ } else {
+ if (!lflag)
+ /* overwrite existing destination file name */
+ to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
+ }
+ } else {
+ if (!lflag)
+ to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
+ fs->st_mode & ~(S_ISUID | S_ISGID));
+ }
+
+ if (to_fd == -1) {
+ warn("%s", to.p_path);
+ (void)close(from_fd);
+ (void)free(buf);
+ return (1);
+ }
+
+ rval = 0;
+
+ if (!lflag) {
+ /*
+ * Mmap and write if less than 8M (the limit is so we don't totally
+ * trash memory on big files. This is really a minor hack, but it
+ * wins some CPU back.
+ */
+#ifdef CCJ_REMOVED_VM_AND_BUFFER_CACHE_SYNCHRONIZED
+ if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
+ fs->st_size <= 8 * 1048576) {
+ if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
+ MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) {
+ warn("%s", entp->fts_path);
+ rval = 1;
+ } else {
+ wtotal = 0;
+ for (bufp = p, wresid = fs->st_size; ;
+ bufp += wcount, wresid -= (size_t)wcount) {
+ wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
+ wtotal += wcount;
+ if (info) {
+ info = 0;
+ (void)fprintf(stderr,
+ "%s -> %s %3d%%\n",
+ entp->fts_path, to.p_path,
+ cp_pct(wtotal, fs->st_size));
+ }
+ if (wcount >= (ssize_t)wresid)
+ break;
+ }
+ if (wcount != (ssize_t)wresid) {
+ warn("%s", to.p_path);
+ rval = 1;
+ }
+ /* Some systems don't unmap on close(2). */
+ if (munmap(p, fs->st_size) < 0) {
+ warn("%s", entp->fts_path);
+ rval = 1;
+ }
+ }
+ } else
+#endif
+ {
+ wtotal = 0;
+ while ((rcount = read(from_fd, buf, MAX_READ)) > 0) {
+ for (bufp = buf, wresid = rcount; ;
+ bufp += wcount, wresid -= wcount) {
+ wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
+ wtotal += wcount;
+ if (info) {
+ info = 0;
+ (void)fprintf(stderr,
+ "%s -> %s %3d%%\n",
+ entp->fts_path, to.p_path,
+ cp_pct(wtotal, fs->st_size));
+ }
+ if (wcount >= (ssize_t)wresid)
+ break;
+ }
+ if (wcount != (ssize_t)wresid) {
+ warn("%s", to.p_path);
+ rval = 1;
+ break;
+ }
+ }
+ if (rcount < 0) {
+ warn("%s", entp->fts_path);
+ rval = 1;
+ }
+ }
+ } else {
+ if (link(entp->fts_path, to.p_path)) {
+ warn("%s", to.p_path);
+ rval = 1;
+ }
+ }
+ (void)close(from_fd);
+
+ /*
+ * Don't remove the target even after an error. The target might
+ * not be a regular file, or its attributes might be important,
+ * or its contents might be irreplaceable. It would only be safe
+ * to remove it if we created it and its length is 0.
+ */
+
+ if (!lflag) {
+ if (pflag && setfile(cp_globals, fs, to_fd))
+ rval = 1;
+ if (pflag && preserve_fd_acls(from_fd, to_fd) != 0)
+ rval = 1;
+ (void)close(from_fd);
+ if (close(to_fd)) {
+ warn("%s", to.p_path);
+ rval = 1;
+ }
+ }
+ (void)free(buf);
+ return (rval);
+}
+
+int
+copy_link(rtems_shell_cp_globals* cp_globals, FTSENT *p, int exists)
+{
+ ssize_t len;
+ char llink[PATH_MAX];
+
+ if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) {
+ warn("readlink: %s", p->fts_path);
+ return (1);
+ }
+ llink[len] = '\0';
+ if (exists && unlink(to.p_path)) {
+ warn("unlink: %s", to.p_path);
+ return (1);
+ }
+ if (symlink(llink, to.p_path)) {
+ warn("symlink: %s", llink);
+ return (1);
+ }
+ return (pflag ? setfile(cp_globals, p->fts_statp, -1) : 0);
+}
+
+int
+copy_fifo(rtems_shell_cp_globals* cp_globals, struct stat *from_stat, int exists)
+{
+ if (exists && unlink(to.p_path)) {
+ warn("unlink: %s", to.p_path);
+ return (1);
+ }
+ if (mkfifo(to.p_path, from_stat->st_mode)) {
+ warn("mkfifo: %s", to.p_path);
+ return (1);
+ }
+ return (pflag ? setfile(cp_globals, from_stat, -1) : 0);
+}
+
+int
+copy_special(rtems_shell_cp_globals* cp_globals, struct stat *from_stat, int exists)
+{
+ if (exists && unlink(to.p_path)) {
+ warn("unlink: %s", to.p_path);
+ return (1);
+ }
+ if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
+ warn("mknod: %s", to.p_path);
+ return (1);
+ }
+ return (pflag ? setfile(cp_globals, from_stat, -1) : 0);
+}
+
+#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
+ (tv)->tv_sec = *(ts); \
+ (tv)->tv_usec = 0; \
+}
+
+#define st_atimespec st_atime
+#define st_mtimespec st_mtime
+#define lutimes utimes
+
+int
+setfile(rtems_shell_cp_globals* cp_globals, struct stat *fs, int fd)
+{
+ static struct timeval tv[2];
+ struct stat ts;
+ int rval, gotstat, islink, fdval;
+
+ rval = 0;
+ fdval = fd != -1;
+ islink = !fdval && S_ISLNK(fs->st_mode);
+ fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
+ S_IRWXU | S_IRWXG | S_IRWXO;
+
+ TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
+ TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
+#if 0
+ if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
+ warn("%sutimes: %s", islink ? "l" : "", to.p_path);
+ rval = 1;
+ }
+#endif
+ if (fdval ? fstat(fd, &ts) :
+ (islink ? lstat(to.p_path, &ts) : stat(to.p_path, &ts)))
+ gotstat = 0;
+ else {
+ gotstat = 1;
+ ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX |
+ S_IRWXU | S_IRWXG | S_IRWXO;
+ }
+ /*
+ * Changing the ownership probably won't succeed, unless we're root
+ * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
+ * the mode; current BSD behavior is to remove all setuid bits on
+ * chown. If chown fails, lose setuid/setgid bits.
+ */
+ if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid)
+ if (fdval ? fchown(fd, fs->st_uid, fs->st_gid) :
+ (islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) :
+ chown(to.p_path, fs->st_uid, fs->st_gid))) {
+ if (errno != EPERM) {
+ warn("chown: %s", to.p_path);
+ rval = 1;
+ }
+ fs->st_mode &= ~(S_ISUID | S_ISGID);
+ }
+
+ if (!gotstat || fs->st_mode != ts.st_mode)
+ if (fdval ? fchmod(fd, fs->st_mode) :
+ (islink ? lchmod(to.p_path, fs->st_mode) :
+ chmod(to.p_path, fs->st_mode))) {
+ warn("chmod: %s", to.p_path);
+ rval = 1;
+ }
+
+#if 0
+ if (!gotstat || fs->st_flags != ts.st_flags)
+ if (fdval ?
+ fchflags(fd, fs->st_flags) :
+ (islink ? (errno = ENOSYS) :
+ chflags(to.p_path, fs->st_flags))) {
+ warn("chflags: %s", to.p_path);
+ rval = 1;
+ }
+#endif
+
+ return (rval);
+}
+
+int
+preserve_fd_acls(int source_fd __attribute__((unused)), int dest_fd __attribute__((unused)))
+{
+#if 0
+ struct acl *aclp;
+ acl_t acl;
+
+ if (fpathconf(source_fd, _PC_ACL_EXTENDED) != 1 ||
+ fpathconf(dest_fd, _PC_ACL_EXTENDED) != 1)
+ return (0);
+ acl = acl_get_fd(source_fd);
+ if (acl == NULL) {
+ warn("failed to get acl entries while setting %s", to.p_path);
+ return (1);
+ }
+ aclp = &acl->ats_acl;
+ if (aclp->acl_cnt == 3)
+ return (0);
+ if (acl_set_fd(dest_fd, acl) < 0) {
+ warn("failed to set acl entries for %s", to.p_path);
+ return (1);
+ }
+#endif
+ return (0);
+}
+
+int
+preserve_dir_acls(struct stat *fs __attribute__((unused)), char *source_dir __attribute__((unused)), char *dest_dir __attribute__((unused)))
+{
+#if 0
+ acl_t (*aclgetf)(const char *, acl_type_t);
+ int (*aclsetf)(const char *, acl_type_t, acl_t);
+ struct acl *aclp;
+ acl_t acl;
+
+ if (pathconf(source_dir, _PC_ACL_EXTENDED) != 1 ||
+ pathconf(dest_dir, _PC_ACL_EXTENDED) != 1)
+ return (0);
+ /*
+ * If the file is a link we will not follow it
+ */
+ if (S_ISLNK(fs->st_mode)) {
+ aclgetf = acl_get_link_np;
+ aclsetf = acl_set_link_np;
+ } else {
+ aclgetf = acl_get_file;
+ aclsetf = acl_set_file;
+ }
+ /*
+ * Even if there is no ACL_TYPE_DEFAULT entry here, a zero
+ * size ACL will be returned. So it is not safe to simply
+ * check the pointer to see if the default ACL is present.
+ */
+ acl = aclgetf(source_dir, ACL_TYPE_DEFAULT);
+ if (acl == NULL) {
+ warn("failed to get default acl entries on %s",
+ source_dir);
+ return (1);
+ }
+ aclp = &acl->ats_acl;
+ if (aclp->acl_cnt != 0 && aclsetf(dest_dir,
+ ACL_TYPE_DEFAULT, acl) < 0) {
+ warn("failed to set default acl entries on %s",
+ dest_dir);
+ return (1);
+ }
+ acl = aclgetf(source_dir, ACL_TYPE_ACCESS);
+ if (acl == NULL) {
+ warn("failed to get acl entries on %s", source_dir);
+ return (1);
+ }
+ aclp = &acl->ats_acl;
+ if (aclsetf(dest_dir, ACL_TYPE_ACCESS, acl) < 0) {
+ warn("failed to set acl entries on %s", dest_dir);
+ return (1);
+ }
+#endif
+ return (0);
+}
+
+void
+usage(rtems_shell_cp_globals* cp_globals)
+{
+ (void)fprintf(stderr, "%s\n%s\n",
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file",
+" cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... "
+"target_directory");
+ longjmp (cp_globals->exit_jmp, 1);
+}
diff --git a/cpukit/libmisc/shell/utils-ls.c b/cpukit/libmisc/shell/utils-ls.c
new file mode 100644
index 0000000000..7ff0d1b4bd
--- /dev/null
+++ b/cpukit/libmisc/shell/utils-ls.c
@@ -0,0 +1,117 @@
+/* $NetBSD: util.c,v 1.28 2005/06/17 14:36:16 hira Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Michael Fischbein.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)util.c 8.5 (Berkeley) 4/28/95";
+#else
+__RCSID("$NetBSD: util.c,v 1.28 2005/06/17 14:36:16 hira Exp $");
+#endif
+#endif /* not lint */
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <fts.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <vis.h>
+
+#include "extern-ls.h"
+
+#define SIZE_T_MAX 255
+
+int
+safe_print(rtems_shell_ls_globals* globals, const char *src)
+{
+ size_t len;
+ char *name;
+ int flags;
+
+ flags = VIS_NL | VIS_OCTAL;
+ if (f_octal_escape)
+ flags |= VIS_CSTYLE;
+
+ len = strlen(src);
+ if (len != 0 && SIZE_T_MAX/len <= 4) {
+ errx(exit_jump, EXIT_FAILURE, "%s: name too long", src);
+ /* NOTREACHED */
+ }
+
+ name = (char *)malloc(4*len+1);
+ if (name != NULL) {
+ len = strvis(name, src, flags);
+ printf("%s", name);
+ free(name);
+ return len;
+ } else
+ errx(exit_jump, EXIT_FAILURE, "out of memory!");
+ /* NOTREACHED */
+}
+
+int
+printescaped(rtems_shell_ls_globals* globals __attribute__((unused)), const char *src)
+{
+ unsigned char c;
+ int n;
+
+ for (n = 0; (c = *src) != '\0'; ++src, ++n)
+ if (isprint(c))
+ (void)putchar(c);
+ else
+ (void)putchar('?');
+ return n;
+}
+
+void
+usage(rtems_shell_ls_globals* globals)
+{
+
+ (void)fprintf(stderr,
+ "usage: %s [-AaBbCcdFfghikLlmnopqRrSsTtuWwx1] [file ...]\n",
+ "ls");
+ exit(EXIT_FAILURE);
+ /* NOTREACHED */
+}
diff --git a/cpukit/libmisc/shell/verr.c b/cpukit/libmisc/shell/verr.c
new file mode 100644
index 0000000000..301e229a1c
--- /dev/null
+++ b/cpukit/libmisc/shell/verr.c
@@ -0,0 +1,75 @@
+/* $NetBSD: verr.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: verr.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(verr, _verr)
+#endif
+
+__dead void
+verr(jmp_buf* exit_jmp, int eval __attribute__((unused)), const char *fmt, _BSD_VA_LIST_ ap)
+{
+ int sverrno;
+
+ sverrno = errno;
+#if 0
+ (void)fprintf(stderr, "%s: ", getprogname());
+#endif
+ if (fmt != NULL) {
+ (void)vfprintf(stdout, fmt, ap);
+ (void)fprintf(stdout, ": ");
+ }
+ (void)fprintf(stdout, "%s\n", strerror(sverrno));
+ longjmp (*exit_jmp, 1);
+}
diff --git a/cpukit/libmisc/shell/verrx.c b/cpukit/libmisc/shell/verrx.c
new file mode 100644
index 0000000000..30355dd31c
--- /dev/null
+++ b/cpukit/libmisc/shell/verrx.c
@@ -0,0 +1,68 @@
+/* $NetBSD: verrx.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: verrx.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __weak_alias
+__weak_alias(verrx, _verrx)
+#endif
+
+__dead void
+verrx(jmp_buf* exit_jmp, int eval __attribute__((unused)), const char *fmt, _BSD_VA_LIST_ ap)
+{
+#if 0
+ (void)fprintf(stderr, "%s: ", getprogname());
+#endif
+ if (fmt != NULL)
+ (void)vfprintf(stdout, fmt, ap);
+ (void)fprintf(stdout, "\n");
+ longjmp (*exit_jmp, 1);
+}
diff --git a/cpukit/libmisc/shell/vis.c b/cpukit/libmisc/shell/vis.c
new file mode 100644
index 0000000000..6316555279
--- /dev/null
+++ b/cpukit/libmisc/shell/vis.c
@@ -0,0 +1,387 @@
+/* $NetBSD: vis.c,v 1.33 2005/05/28 13:11:14 lukem Exp $ */
+
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 1999, 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _DIAGASSERT(a)
+
+#if 0
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: vis.c,v 1.33 2005/05/28 13:11:14 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+#endif
+
+#include <sys/types.h>
+
+#include <vis.h>
+#include <stdlib.h>
+
+#if !HAVE_VIS || !HAVE_SVIS
+#include <ctype.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+
+#undef BELL
+#define BELL '\a'
+
+#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+#define iswhite(c) (c == ' ' || c == '\t' || c == '\n')
+#define issafe(c) (c == '\b' || c == BELL || c == '\r')
+#define xtoa(c) "0123456789abcdef"[c]
+
+#define MAXEXTRAS 5
+
+
+#define MAKEEXTRALIST(flag, extra, orig) \
+do { \
+ const char *o = orig; \
+ char *e; \
+ while (*o++) \
+ continue; \
+ extra = malloc((size_t)((o - orig) + MAXEXTRAS)); \
+ if (!extra) break; \
+ for (o = orig, e = extra; (*e++ = *o++) != '\0';) \
+ continue; \
+ e--; \
+ if (flag & VIS_SP) *e++ = ' '; \
+ if (flag & VIS_TAB) *e++ = '\t'; \
+ if (flag & VIS_NL) *e++ = '\n'; \
+ if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \
+ *e = '\0'; \
+} while (/*CONSTCOND*/0)
+
+
+/*
+ * This is HVIS, the macro of vis used to HTTP style (RFC 1808)
+ */
+#define HVIS(dst, c, flag, nextc, extra) \
+do \
+ if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \
+ *dst++ = '%'; \
+ *dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \
+ *dst++ = xtoa((unsigned int)c & 0xf); \
+ } else { \
+ SVIS(dst, c, flag, nextc, extra); \
+ } \
+while (/*CONSTCOND*/0)
+
+/*
+ * This is SVIS, the central macro of vis.
+ * dst: Pointer to the destination buffer
+ * c: Character to encode
+ * flag: Flag word
+ * nextc: The character following 'c'
+ * extra: Pointer to the list of extra characters to be
+ * backslash-protected.
+ */
+#define SVIS(dst, c, flag, nextc, extra) \
+do { \
+ int isextra; \
+ isextra = strchr(extra, c) != NULL; \
+ if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \
+ ((flag & VIS_SAFE) && issafe(c)))) { \
+ *dst++ = c; \
+ break; \
+ } \
+ if (flag & VIS_CSTYLE) { \
+ switch (c) { \
+ case '\n': \
+ *dst++ = '\\'; *dst++ = 'n'; \
+ continue; \
+ case '\r': \
+ *dst++ = '\\'; *dst++ = 'r'; \
+ continue; \
+ case '\b': \
+ *dst++ = '\\'; *dst++ = 'b'; \
+ continue; \
+ case BELL: \
+ *dst++ = '\\'; *dst++ = 'a'; \
+ continue; \
+ case '\v': \
+ *dst++ = '\\'; *dst++ = 'v'; \
+ continue; \
+ case '\t': \
+ *dst++ = '\\'; *dst++ = 't'; \
+ continue; \
+ case '\f': \
+ *dst++ = '\\'; *dst++ = 'f'; \
+ continue; \
+ case ' ': \
+ *dst++ = '\\'; *dst++ = 's'; \
+ continue; \
+ case '\0': \
+ *dst++ = '\\'; *dst++ = '0'; \
+ if (isoctal(nextc)) { \
+ *dst++ = '0'; \
+ *dst++ = '0'; \
+ } \
+ continue; \
+ default: \
+ if (isgraph(c)) { \
+ *dst++ = '\\'; *dst++ = c; \
+ continue; \
+ } \
+ } \
+ } \
+ if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \
+ *dst++ = '\\'; \
+ *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; \
+ *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; \
+ *dst++ = (c & 07) + '0'; \
+ } else { \
+ if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \
+ if (c & 0200) { \
+ c &= 0177; *dst++ = 'M'; \
+ } \
+ if (iscntrl(c)) { \
+ *dst++ = '^'; \
+ if (c == 0177) \
+ *dst++ = '?'; \
+ else \
+ *dst++ = c + '@'; \
+ } else { \
+ *dst++ = '-'; *dst++ = c; \
+ } \
+ } \
+} while (/*CONSTCOND*/0)
+
+
+/*
+ * svis - visually encode characters, also encoding the characters
+ * pointed to by `extra'
+ */
+char *
+svis(char *dst, int c, int flag, int nextc, const char *extra)
+{
+ char *nextra = NULL;
+
+ _DIAGASSERT(dst != NULL);
+ _DIAGASSERT(extra != NULL);
+ MAKEEXTRALIST(flag, nextra, extra);
+ if (!nextra) {
+ *dst = '\0'; /* can't create nextra, return "" */
+ return dst;
+ }
+ if (flag & VIS_HTTPSTYLE)
+ HVIS(dst, c, flag, nextc, nextra);
+ else
+ SVIS(dst, c, flag, nextc, nextra);
+ free(nextra);
+ *dst = '\0';
+ return dst;
+}
+
+
+/*
+ * strsvis, strsvisx - visually encode characters from src into dst
+ *
+ * Extra is a pointer to a \0-terminated list of characters to
+ * be encoded, too. These functions are useful e. g. to
+ * encode strings in such a way so that they are not interpreted
+ * by a shell.
+ *
+ * Dst must be 4 times the size of src to account for possible
+ * expansion. The length of dst, not including the trailing NULL,
+ * is returned.
+ *
+ * Strsvisx encodes exactly len bytes from src into dst.
+ * This is useful for encoding a block of data.
+ */
+int
+strsvis(char *dst, const char *csrc, int flag, const char *extra)
+{
+ int c;
+ char *start;
+ char *nextra = NULL;
+ const unsigned char *src = (const unsigned char *)csrc;
+
+ _DIAGASSERT(dst != NULL);
+ _DIAGASSERT(src != NULL);
+ _DIAGASSERT(extra != NULL);
+ MAKEEXTRALIST(flag, nextra, extra);
+ if (!nextra) {
+ *dst = '\0'; /* can't create nextra, return "" */
+ return 0;
+ }
+ if (flag & VIS_HTTPSTYLE) {
+ for (start = dst; (c = *src++) != '\0'; /* empty */)
+ HVIS(dst, c, flag, *src, nextra);
+ } else {
+ for (start = dst; (c = *src++) != '\0'; /* empty */)
+ SVIS(dst, c, flag, *src, nextra);
+ }
+ free(nextra);
+ *dst = '\0';
+ return (dst - start);
+}
+
+
+int
+strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra)
+{
+ unsigned char c;
+ char *start;
+ char *nextra = NULL;
+ const unsigned char *src = (const unsigned char *)csrc;
+
+ _DIAGASSERT(dst != NULL);
+ _DIAGASSERT(src != NULL);
+ _DIAGASSERT(extra != NULL);
+ MAKEEXTRALIST(flag, nextra, extra);
+ if (! nextra) {
+ *dst = '\0'; /* can't create nextra, return "" */
+ return 0;
+ }
+
+ if (flag & VIS_HTTPSTYLE) {
+ for (start = dst; len > 0; len--) {
+ c = *src++;
+ HVIS(dst, c, flag, len ? *src : '\0', nextra);
+ }
+ } else {
+ for (start = dst; len > 0; len--) {
+ c = *src++;
+ SVIS(dst, c, flag, len ? *src : '\0', nextra);
+ }
+ }
+ free(nextra);
+ *dst = '\0';
+ return (dst - start);
+}
+#endif
+
+#if !HAVE_VIS
+/*
+ * vis - visually encode characters
+ */
+char *
+vis(char *dst, int c, int flag, int nextc)
+{
+ char *extra = NULL;
+ unsigned char uc = (unsigned char)c;
+
+ _DIAGASSERT(dst != NULL);
+
+ MAKEEXTRALIST(flag, extra, "");
+ if (! extra) {
+ *dst = '\0'; /* can't create extra, return "" */
+ return dst;
+ }
+ if (flag & VIS_HTTPSTYLE)
+ HVIS(dst, uc, flag, nextc, extra);
+ else
+ SVIS(dst, uc, flag, nextc, extra);
+ free(extra);
+ *dst = '\0';
+ return dst;
+}
+
+
+/*
+ * strvis, strvisx - visually encode characters from src into dst
+ *
+ * Dst must be 4 times the size of src to account for possible
+ * expansion. The length of dst, not including the trailing NULL,
+ * is returned.
+ *
+ * Strvisx encodes exactly len bytes from src into dst.
+ * This is useful for encoding a block of data.
+ */
+int
+strvis(char *dst, const char *src, int flag)
+{
+ char *extra = NULL;
+ int rv;
+
+ MAKEEXTRALIST(flag, extra, "");
+ if (!extra) {
+ *dst = '\0'; /* can't create extra, return "" */
+ return 0;
+ }
+ rv = strsvis(dst, src, flag, extra);
+ free(extra);
+ return rv;
+}
+
+
+int
+strvisx(char *dst, const char *src, size_t len, int flag)
+{
+ char *extra = NULL;
+ int rv;
+
+ MAKEEXTRALIST(flag, extra, "");
+ if (!extra) {
+ *dst = '\0'; /* can't create extra, return "" */
+ return 0;
+ }
+ rv = strsvisx(dst, src, len, flag, extra);
+ free(extra);
+ return rv;
+}
+#endif
diff --git a/cpukit/libmisc/shell/vis.h b/cpukit/libmisc/shell/vis.h
new file mode 100644
index 0000000000..fb0aa6dc2a
--- /dev/null
+++ b/cpukit/libmisc/shell/vis.h
@@ -0,0 +1,91 @@
+/* $NetBSD: vis.h,v 1.16 2005/09/13 01:44:32 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)vis.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _VIS_H_
+#define _VIS_H_
+
+#include <sys/types.h>
+
+/*
+ * to select alternate encoding format
+ */
+#define VIS_OCTAL 0x01 /* use octal \ddd format */
+#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */
+
+/*
+ * to alter set of characters encoded (default is to encode all
+ * non-graphic except space, tab, and newline).
+ */
+#define VIS_SP 0x04 /* also encode space */
+#define VIS_TAB 0x08 /* also encode tab */
+#define VIS_NL 0x10 /* also encode newline */
+#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
+#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
+
+/*
+ * other
+ */
+#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
+#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
+
+/*
+ * unvis return codes
+ */
+#define UNVIS_VALID 1 /* character valid */
+#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
+#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
+#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
+#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
+
+/*
+ * unvis flags
+ */
+#define UNVIS_END 1 /* no more characters */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+char *vis(char *, int, int, int);
+char *svis(char *, int, int, int, const char *);
+int strvis(char *, const char *, int);
+int strsvis(char *, const char *, int, const char *);
+int strvisx(char *, const char *, size_t, int);
+int strsvisx(char *, const char *, size_t, int, const char *);
+int strunvis(char *, const char *);
+int strunvisx(char *, const char *, int);
+#ifndef __LIBC12_SOURCE__
+//int unvis(char *, int, int *, int) __RENAME(__unvis13);
+#endif
+__END_DECLS
+
+#endif /* !_VIS_H_ */
diff --git a/cpukit/libmisc/shell/vwarn.c b/cpukit/libmisc/shell/vwarn.c
new file mode 100644
index 0000000000..df214c5db9
--- /dev/null
+++ b/cpukit/libmisc/shell/vwarn.c
@@ -0,0 +1,74 @@
+/* $NetBSD: vwarn.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vwarn.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(vwarn, _vwarn)
+#endif
+
+void
+vwarn(const char *fmt, _BSD_VA_LIST_ ap)
+{
+ int sverrno;
+
+ sverrno = errno;
+#if 0
+ (void)fprintf(stderr, "%s: ", getprogname());
+#endif
+ if (fmt != NULL) {
+ (void)vfprintf(stdout, fmt, ap);
+ (void)fprintf(stdout, ": ");
+ }
+ (void)fprintf(stdout, "%s\n", strerror(sverrno));
+}
diff --git a/cpukit/libmisc/shell/vwarnx.c b/cpukit/libmisc/shell/vwarnx.c
new file mode 100644
index 0000000000..34737a17f1
--- /dev/null
+++ b/cpukit/libmisc/shell/vwarnx.c
@@ -0,0 +1,67 @@
+/* $NetBSD: vwarnx.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vwarnx.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __weak_alias
+__weak_alias(vwarnx, _vwarnx)
+#endif
+
+void
+vwarnx(const char *fmt, _BSD_VA_LIST_ ap)
+{
+#if 0
+ (void)fprintf(stderr, "%s: ", getprogname());
+#endif
+ if (fmt != NULL)
+ (void)vfprintf(stdout, fmt, ap);
+ (void)fprintf(stdout, "\n");
+}
diff --git a/cpukit/libmisc/shell/warn.c b/cpukit/libmisc/shell/warn.c
new file mode 100644
index 0000000000..f32edfb630
--- /dev/null
+++ b/cpukit/libmisc/shell/warn.c
@@ -0,0 +1,64 @@
+/* $NetBSD: warn.c,v 1.13 2005/09/13 13:51:50 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: warn.c,v 1.13 2005/09/13 13:51:50 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <stdarg.h>
+
+#ifdef __weak_alias
+__weak_alias(warn, _warn)
+#endif
+
+void
+warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarn(fmt, ap);
+ va_end(ap);
+}
diff --git a/cpukit/libmisc/shell/warnx.c b/cpukit/libmisc/shell/warnx.c
new file mode 100644
index 0000000000..efcbd8b0f1
--- /dev/null
+++ b/cpukit/libmisc/shell/warnx.c
@@ -0,0 +1,64 @@
+/* $NetBSD: warnx.c,v 1.13 2005/09/13 13:51:50 christos Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: warnx.c,v 1.13 2005/09/13 13:51:50 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <err.h>
+#include <stdarg.h>
+
+#ifdef __weak_alias
+__weak_alias(warnx, _warnx)
+#endif
+
+void
+warnx(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarnx(fmt, ap);
+ va_end(ap);
+}
diff --git a/cpukit/libmisc/shell/write_file.c b/cpukit/libmisc/shell/write_file.c
new file mode 100644
index 0000000000..f9e72f4645
--- /dev/null
+++ b/cpukit/libmisc/shell/write_file.c
@@ -0,0 +1,43 @@
+/*
+ *
+ * Write buffer to a file
+ *
+ * Author:
+ *
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+void rtems_shell_write_file(
+ const char *name,
+ const char *content
+)
+{
+ FILE * fd;
+
+ fd = fopen(name,"w");
+ if ( !fd ) {
+ fprintf( stderr, "Unable to write %s\n", name );
+ }
+
+ if (fd) {
+ fwrite(content,1,strlen(content),fd);
+ fclose(fd);
+ }
+}
+
+
diff --git a/cpukit/libmisc/stackchk/README b/cpukit/libmisc/stackchk/README
new file mode 100644
index 0000000000..5421a77434
--- /dev/null
+++ b/cpukit/libmisc/stackchk/README
@@ -0,0 +1,53 @@
+#
+# $Id$
+#
+
+Introduction
+============
+
+This directory contains a stack bounds checker. It provides two
+primary features:
+
+ + check for stack overflow at each context switch
+ + provides an educated guess at each task's stack usage
+
+Enabling
+========
+
+Add the stack checker extension to the initial user extension set.
+If using confdefs.h to build your configuration table, this is
+as simple as adding -DSTACK_CHECK_ON to the gcc command line which
+compiles the file defining the configuration table. In the RTEMS
+test suites and samples, this is always init.c
+
+Background
+==========
+
+The stack overflow check at context switch works by looking for
+a 16 byte pattern at the logical end of the stack to be corrupted.
+The "guesser" assumes that the entire stack was prefilled with a known
+pattern and assumes that the pattern is still in place if the memory
+has not been used as a stack.
+
+Both of these can be fooled by pushing large holes onto the stack
+and not writing to them... or (much more unlikely) writing the
+magic patterns into memory.
+
+This code has not been extensively tested. It is provided as a tool
+for RTEMS users to catch the most common mistake in multitasking
+systems ... too little stack space. Suggestions and comments are appreciated.
+
+NOTES:
+
+1. Stack usage information is questionable on CPUs which push
+ large holes on stack.
+
+2. The stack checker has a tendency to generate a fault when
+ trying to print the helpful diagnostic message. If it comes
+ out, congratulations. If not, then the variable Stack_check_Blown_task
+ contains a pointer to the TCB of the offending task. This
+ is usually enough to go on.
+
+FUTURE:
+
+1. Determine how/if gcc will generate stack probe calls and support that.
diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c
new file mode 100644
index 0000000000..d2c0b1001b
--- /dev/null
+++ b/cpukit/libmisc/stackchk/check.c
@@ -0,0 +1,515 @@
+/*
+ * Stack Overflow Check User Extension Set
+ *
+ * NOTE: This extension set automatically determines at
+ * initialization time whether the stack for this
+ * CPU grows up or down and installs the correct
+ * extension routines for that direction.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <inttypes.h>
+
+/*
+ * The stack dump information may be printed by a "fatal" extension.
+ * Fatal extensions only get called via rtems_fatal_error_occurred()
+ * and not when rtems_shutdown_executive() is called.
+ * When that happens, this #define should be deleted and all the code
+ * it marks.
+ */
+#define DONT_USE_FATAL_EXTENSION
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <rtems/bspIo.h>
+#include <rtems/stackchk.h>
+#include "internal.h"
+
+/*
+ * Variable to indicate when the stack checker has been initialized.
+ */
+static int Stack_check_Initialized = 0;
+
+/*
+ * The "magic pattern" used to mark the end of the stack.
+ */
+Stack_check_Control Stack_check_Pattern;
+
+/*
+ * Helper function to report if the actual stack pointer is in range.
+ *
+ * NOTE: This uses a GCC specific method.
+ */
+static inline bool Stack_check_Frame_pointer_in_range(
+ Stack_Control *the_stack
+)
+{
+ #if defined(__GNUC__)
+ void *sp = __builtin_frame_address(0);
+
+ if ( sp < the_stack->area ) {
+ return false;
+ }
+ if ( sp > (the_stack->area + the_stack->size) ) {
+ return false;
+ }
+ #else
+ #error "How do I check stack bounds on a non-GNU compiler?"
+ #endif
+ return true;
+}
+
+/*
+ * Where the pattern goes in the stack area is dependent upon
+ * whether the stack grow to the high or low area of the memory.
+ */
+#if (CPU_STACK_GROWS_UP == TRUE)
+ #define Stack_check_Get_pattern( _the_stack ) \
+ ((char *)(_the_stack)->area + \
+ (_the_stack)->size - sizeof( Stack_check_Control ) )
+
+ #define Stack_check_Calculate_used( _low, _size, _high_water ) \
+ ((char *)(_high_water) - (char *)(_low))
+
+ #define Stack_check_usable_stack_start(_the_stack) \
+ ((_the_stack)->area)
+
+#else
+ /*
+ * We need this magic offset because during a task delete the task stack will
+ * be freed before we enter the task switch extension which checks the stack.
+ * The task stack free operation will write the next and previous pointers
+ * for the free list into this area.
+ */
+ #define Stack_check_Get_pattern( _the_stack ) \
+ ((char *)(_the_stack)->area + sizeof(Heap_Block) - HEAP_BLOCK_HEADER_SIZE)
+
+ #define Stack_check_Calculate_used( _low, _size, _high_water) \
+ ( ((char *)(_low) + (_size)) - (char *)(_high_water) )
+
+ #define Stack_check_usable_stack_start(_the_stack) \
+ ((char *)(_the_stack)->area + sizeof(Stack_check_Control))
+
+#endif
+
+/*
+ * Obtain a properly typed pointer to the area to check.
+ */
+#define Stack_check_Get_pattern_area( _the_stack ) \
+ (Stack_check_Control *) Stack_check_Get_pattern( _the_stack )
+
+/*
+ * The assumption is that if the pattern gets overwritten, the task
+ * is too close. This defines the usable stack memory.
+ */
+#define Stack_check_usable_stack_size(_the_stack) \
+ ((_the_stack)->size - sizeof(Stack_check_Control))
+
+#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
+ /*
+ * Did RTEMS allocate the interrupt stack? If so, put it in
+ * Stack_Control format.
+ */
+ Stack_Control Stack_check_Interrupt_stack;
+#endif
+
+/*
+ * Fill an entire stack area with BYTE_PATTERN. This will be used
+ * to check for amount of actual stack used.
+ */
+#define Stack_check_Dope_stack(_stack) \
+ memset((_stack)->area, BYTE_PATTERN, (_stack)->size)
+
+/*
+ * Stack_check_Initialize
+ */
+void Stack_check_Initialize( void )
+{
+ int i;
+ uint32_t *p;
+ static uint32_t pattern[ 4 ] = {
+ 0xFEEDF00D, 0x0BAD0D06, /* FEED FOOD to BAD DOG */
+ 0xDEADF00D, 0x600D0D06 /* DEAD FOOD but GOOD DOG */
+ };
+
+ if ( Stack_check_Initialized )
+ return;
+
+ /*
+ * Dope the pattern and fill areas
+ */
+ p = Stack_check_Pattern.pattern;
+ for ( i = 0; i < PATTERN_SIZE_WORDS; i++ ) {
+ p[i] = pattern[ i%4 ];
+ }
+
+ /*
+ * If appropriate, setup the interrupt stack for high water testing
+ * also.
+ */
+ #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
+ if (_CPU_Interrupt_stack_low && _CPU_Interrupt_stack_high) {
+ Stack_check_Interrupt_stack.area = _CPU_Interrupt_stack_low;
+ Stack_check_Interrupt_stack.size = (char *) _CPU_Interrupt_stack_high -
+ (char *) _CPU_Interrupt_stack_low;
+ Stack_check_Dope_stack(&Stack_check_Interrupt_stack);
+ }
+ #endif
+
+ Stack_check_Initialized = 1;
+}
+
+/*
+ * rtems_stack_checker_create_extension
+ */
+bool rtems_stack_checker_create_extension(
+ Thread_Control *running __attribute__((unused)),
+ Thread_Control *the_thread
+)
+{
+ Stack_check_Initialize();
+
+ if (the_thread)
+ Stack_check_Dope_stack(&the_thread->Start.Initial_stack);
+
+ return true;
+}
+
+/*
+ * rtems_stack_checker_Begin_extension
+ */
+void rtems_stack_checker_begin_extension(
+ Thread_Control *the_thread
+)
+{
+ Stack_check_Control *the_pattern;
+
+ if ( the_thread->Object.id == 0 ) /* skip system tasks */
+ return;
+
+ the_pattern = Stack_check_Get_pattern_area(&the_thread->Start.Initial_stack);
+
+ *the_pattern = Stack_check_Pattern;
+}
+
+/*
+ * Stack_check_report_blown_task
+ *
+ * Report a blown stack. Needs to be a separate routine
+ * so that interrupt handlers can use this too.
+ *
+ * NOTE: The system is in a questionable state... we may not get
+ * the following message out.
+ */
+void Stack_check_report_blown_task(
+ Thread_Control *running,
+ bool pattern_ok
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+void Stack_check_report_blown_task(Thread_Control *running, bool pattern_ok)
+{
+ Stack_Control *stack = &running->Start.Initial_stack;
+ void *pattern_area = Stack_check_Get_pattern(stack);
+ char name[32];
+
+ printk("BLOWN STACK!!!\n");
+ printk("task control block: 0x%08" PRIxPTR "\n", running);
+ printk("task ID: 0x%08lx\n", (unsigned long) running->Object.id);
+ printk(
+ "task name: 0x%08" PRIx32 "\n",
+ running->Object.name.name_u32
+ );
+ printk(
+ "task name string: %s\n",
+ rtems_object_get_name(running->Object.id, sizeof(name), name)
+ );
+ printk(
+ "task stack area (%lu Bytes): 0x%08" PRIxPTR " .. 0x%08" PRIxPTR "\n",
+ (unsigned long) stack->size,
+ stack->area,
+ ((char *) stack->area + stack->size)
+ );
+ if (!pattern_ok) {
+ printk(
+ "damaged pattern area (%lu Bytes): 0x%08" PRIxPTR " .. 0x%08" PRIxPTR "\n",
+ (unsigned long) PATTERN_SIZE_BYTES,
+ pattern_area,
+ (pattern_area + PATTERN_SIZE_BYTES)
+ );
+ }
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if (rtems_configuration_get_user_multiprocessing_table()) {
+ printk(
+ "node: 0x%08" PRIxPTR "\n",
+ rtems_configuration_get_user_multiprocessing_table()->node
+ );
+ }
+ #endif
+
+ rtems_fatal_error_occurred(0x81);
+}
+
+/*
+ * rtems_stack_checker_switch_extension
+ */
+void rtems_stack_checker_switch_extension(
+ Thread_Control *running __attribute__((unused)),
+ Thread_Control *heir __attribute__((unused))
+)
+{
+ Stack_Control *the_stack = &running->Start.Initial_stack;
+ void *pattern;
+ bool sp_ok;
+ bool pattern_ok = true;
+
+ pattern = Stack_check_Get_pattern_area(the_stack);
+
+ /*
+ * Check for an out of bounds stack pointer or an overwrite
+ */
+ sp_ok = Stack_check_Frame_pointer_in_range( the_stack );
+
+ pattern_ok = (!memcmp( pattern,
+ (void *) Stack_check_Pattern.pattern, PATTERN_SIZE_BYTES));
+
+ if ( !sp_ok || !pattern_ok ) {
+ Stack_check_report_blown_task( running, pattern_ok );
+ }
+}
+
+/*
+ * Check if blown
+ */
+bool rtems_stack_checker_is_blown( void )
+{
+ Stack_Control *the_stack = &_Thread_Executing->Start.Initial_stack;
+ bool sp_ok;
+ bool pattern_ok = true;
+
+ /*
+ * Check for an out of bounds stack pointer
+ */
+
+ sp_ok = Stack_check_Frame_pointer_in_range( the_stack );
+
+ /*
+ * The stack checker must be initialized before the pattern is there
+ * to check.
+ */
+ if ( Stack_check_Initialized ) {
+ pattern_ok = (!memcmp(
+ Stack_check_Get_pattern(the_stack),
+ (void *) Stack_check_Pattern.pattern,
+ PATTERN_SIZE_BYTES
+ ));
+ }
+
+
+ /*
+ * Let's report as much as we can.
+ */
+ if ( !sp_ok || !pattern_ok ) {
+ Stack_check_report_blown_task( _Thread_Executing, pattern_ok );
+ /* DOES NOT RETURN */
+ }
+
+ /*
+ * The Stack Pointer and the Pattern Area are OK so return false.
+ */
+ return false;
+}
+
+/*
+ * Stack_check_find_high_water_mark
+ */
+static inline void *Stack_check_find_high_water_mark(
+ const void *s,
+ size_t n
+)
+{
+ const uint32_t *base, *ebase;
+ uint32_t length;
+
+ base = s;
+ length = n/4;
+
+ #if ( CPU_STACK_GROWS_UP == TRUE )
+ /*
+ * start at higher memory and find first word that does not
+ * match pattern
+ */
+
+ base += length - 1;
+ for (ebase = s; base > ebase; base--)
+ if (*base != U32_PATTERN)
+ return (void *) base;
+ #else
+ /*
+ * start at lower memory and find first word that does not
+ * match pattern
+ */
+
+ base += PATTERN_SIZE_WORDS;
+ for (ebase = base + length; base < ebase; base++)
+ if (*base != U32_PATTERN)
+ return (void *) base;
+ #endif
+
+ return (void *)0;
+}
+
+/*
+ * Stack_check_Dump_threads_usage
+ *
+ * Try to print out how much stack was actually used by the task.
+ */
+static void *print_context;
+static rtems_printk_plugin_t print_handler;
+
+void Stack_check_Dump_threads_usage(
+ Thread_Control *the_thread
+)
+{
+ uint32_t size, used;
+ void *low;
+ void *high_water_mark;
+ void *current;
+ Stack_Control *stack;
+ char name[5];
+
+ /*
+ * The pointer passed in for the_thread is guaranteed to be non-NULL from
+ * rtems_iterate_over_all_threads() so no need to check it here.
+ */
+
+ /*
+ * Obtain interrupt stack information
+ */
+ #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
+ if (the_thread == (Thread_Control *) -1) {
+ if (!Stack_check_Interrupt_stack.area)
+ return;
+ stack = &Stack_check_Interrupt_stack;
+ the_thread = 0;
+ current = 0;
+ } else
+ #endif
+ {
+ stack = &the_thread->Start.Initial_stack;
+ current = (void *)_CPU_Context_Get_SP( &the_thread->Registers );
+ }
+
+ low = Stack_check_usable_stack_start(stack);
+ size = Stack_check_usable_stack_size(stack);
+
+ high_water_mark = Stack_check_find_high_water_mark(low, size);
+
+ if ( high_water_mark )
+ used = Stack_check_Calculate_used( low, size, high_water_mark );
+ else
+ used = 0;
+
+
+ #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
+ if ( the_thread )
+ #endif
+ {
+ (*print_handler)(
+ print_context,
+ "0x%08" PRIx32 " %4s",
+ the_thread->Object.id,
+ rtems_object_get_name( the_thread->Object.id, sizeof(name), name )
+ );
+ }
+ #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
+ else {
+ (*print_handler)( print_context, "0x%08" PRIx32 " INTR", ~0 );
+ }
+ #endif
+
+ (*print_handler)(
+ print_context,
+ " %010p - %010p %010p %8" PRId32 " ",
+ stack->area,
+ stack->area + stack->size - 1,
+ current,
+ size
+ );
+
+ if (Stack_check_Initialized == 0) {
+ (*print_handler)( print_context, "Unavailable\n" );
+ } else {
+ (*print_handler)( print_context, "%8" PRId32 "\n", used );
+ }
+
+
+}
+
+/*
+ * rtems_stack_checker_fatal_extension
+ */
+#ifndef DONT_USE_FATAL_EXTENSION
+ void rtems_stack_checker_fatal_extension(
+ Internal_errors_Source source,
+ bool is_internal,
+ uint32_t status
+ )
+ {
+ if (status == 0)
+ rtems_stack_checker_report_usage();
+ }
+#endif
+
+/*PAGE
+ *
+ * rtems_stack_checker_report_usage
+ */
+
+void rtems_stack_checker_report_usage_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+)
+{
+ if ( !print )
+ return;
+
+ print_context = context;
+ print_handler = print;
+
+ (*print)( context, "Stack usage by thread\n");
+ (*print)( context,
+" ID NAME LOW HIGH CURRENT AVAILABLE USED\n"
+ );
+
+ /* iterate over all threads and dump the usage */
+ rtems_iterate_over_all_threads( Stack_check_Dump_threads_usage );
+
+ #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
+ /* dump interrupt stack info if any */
+ Stack_check_Dump_threads_usage((Thread_Control *) -1);
+ #endif
+
+ print_context = NULL;
+ print_handler = NULL;
+}
+
+void rtems_stack_checker_report_usage( void )
+{
+ rtems_stack_checker_report_usage_with_plugin( NULL, printk_plugin );
+}
diff --git a/cpukit/libmisc/stackchk/internal.h b/cpukit/libmisc/stackchk/internal.h
new file mode 100644
index 0000000000..a16a61e30e
--- /dev/null
+++ b/cpukit/libmisc/stackchk/internal.h
@@ -0,0 +1,95 @@
+/* internal.h
+ *
+ * This include file contains internal information
+ * for the RTEMS stack checker.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __INTERNAL_STACK_CHECK_h
+#define __INTERNAL_STACK_CHECK_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This structure is used to fill in and compare the "end of stack"
+ * marker pattern.
+ * pattern area must be a multiple of 4 words.
+ */
+
+#ifdef CPU_STACK_CHECK_SIZE
+#define PATTERN_SIZE_WORDS (((CPU_STACK_CHECK_SIZE / 4) + 3) & ~0x3)
+#else
+#define PATTERN_SIZE_WORDS (4)
+#endif
+
+#define PATTERN_SIZE_BYTES (PATTERN_SIZE_WORDS * sizeof(uint32_t))
+
+typedef struct {
+ uint32_t pattern[ PATTERN_SIZE_WORDS ];
+} Stack_check_Control;
+
+/*
+ * The pattern used to fill the entire stack.
+ */
+
+#define BYTE_PATTERN 0xA5
+#define U32_PATTERN 0xA5A5A5A5
+
+/*
+ * rtems_stack_checker_create_extension
+ */
+
+bool rtems_stack_checker_create_extension(
+ Thread_Control *running,
+ Thread_Control *the_thread
+);
+
+/*
+ * rtems_stack_checker_begin_extension
+ */
+
+void rtems_stack_checker_begin_extension(
+ Thread_Control *the_thread
+);
+
+/*
+ * rtems_stack_checker_switch_extension
+ */
+
+void rtems_stack_checker_switch_extension(
+ Thread_Control *running,
+ Thread_Control *heir
+);
+
+/*
+ * rtems_stack_checker_fatal_extension
+ */
+
+void rtems_stack_checker_fatal_extension(
+ Internal_errors_Source source,
+ bool is_internal,
+ uint32_t status
+);
+
+/*
+ * rtems_stack_checker_report_usage
+ */
+
+void rtems_stack_checker_report_usage( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libmisc/stackchk/stackchk.h b/cpukit/libmisc/stackchk/stackchk.h
new file mode 100644
index 0000000000..02bbac3a45
--- /dev/null
+++ b/cpukit/libmisc/stackchk/stackchk.h
@@ -0,0 +1,135 @@
+/** @file rtems/stackchk.h
+ *
+ * This include file contains information necessary to utilize
+ * and install the stack checker mechanism.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_STACKCHK_H
+#define _RTEMS_STACKCHK_H
+
+#include <stdbool.h> /* bool */
+
+#include <rtems/score/percpu.h> /* Thread_Control */
+#include <rtems/bspIo.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief Has Current Task Blown Its Stack
+ *
+ * This method is used to determine if the current stack pointer
+ * of the currently executing task is within bounds.
+ *
+ * @return This method returns true if the currently executing task
+ * has blown its stack.
+ *
+ */
+bool rtems_stack_checker_is_blown( void );
+
+/** @brief Print Stack Usage Report
+ *
+ * This method prints a stack usage report for the curently executing
+ * task.
+ *
+ * @note It uses printk to print the report.
+ */
+void rtems_stack_checker_report_usage( void );
+
+/** @brief Print Stack Usage Report
+ *
+ * This method prints a stack usage report for the curently executing
+ * task.
+ *
+ * @param[in] context is the context to pass to the print handler
+ * @param[in] print is the print handler
+ *
+ * @note It uses the caller's routine to print the report.
+ */
+void rtems_stack_checker_report_usage_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+);
+
+/*************************************************************
+ *************************************************************
+ ** Prototyped only so the user extension can be installed **
+ *************************************************************
+ *************************************************************/
+
+/** @brief Stack Checker Task Create Extension
+ *
+ * This method is the task create extension for the stack checker.
+ *
+ * @param[in] running points to the currently executing task
+ * @param[in] the_thread points to the newly created task
+ *
+ * @note If this this the first task created, the stack checker
+ * will automatically intialize itself.
+ */
+bool rtems_stack_checker_create_extension(
+ Thread_Control *running,
+ Thread_Control *the_thread
+);
+
+/** @brief Stack Checker Task Begin Extension
+ *
+ * This method is the task begin extension for the stack checker.
+ *
+ * @param[in] the_thread points to task starting to execute
+ *
+ * @note This is called from the internal method _Thread_Handler.
+ */
+void rtems_stack_checker_begin_extension(
+ Thread_Control *the_thread
+);
+
+/** @brief Stack Checker Task Context Switch Extension
+ *
+ * This method is the task context switch extension for the stack checker.
+ *
+ * @param[in] running points to the currently executing task which
+ * is being context switched out
+ * @param[in] running points to the heir task which we are switching to
+ *
+ * @note This is called from the internal method _Thread_Dispatch.
+ */
+void rtems_stack_checker_switch_extension(
+ Thread_Control *running,
+ Thread_Control *heir
+);
+
+/** @brief Stack Checker Extension Set Definition
+ *
+ * This macro defines the user extension handler set for the stack
+ * checker. This macro is normally only used by confdefs.h.
+ */
+#define RTEMS_STACK_CHECKER_EXTENSION \
+{ \
+ rtems_stack_checker_create_extension, /* rtems_task_create */ \
+ 0, /* rtems_task_start */ \
+ 0, /* rtems_task_restart */ \
+ 0, /* rtems_task_delete */ \
+ rtems_stack_checker_switch_extension, /* task_switch */ \
+ rtems_stack_checker_begin_extension, /* task_begin */ \
+ 0, /* task_exitted */ \
+ 0 /* rtems_stack_checker_fatal_extension */, /* fatal */ \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libmisc/stringto/stringto.h b/cpukit/libmisc/stringto/stringto.h
new file mode 100644
index 0000000000..dfb1617bc9
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringto.h
@@ -0,0 +1,246 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_STRINGTO_H
+#define _RTEMS_STRINGTO_H
+
+#include <rtems.h>
+
+/**
+ * @brief Convert String to Pointer (with validation)
+ *
+ * This method converts a string to a pointer (void *) with
+ * basic numeric validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_pointer(
+ const char *s,
+ void **n,
+ char **endptr
+);
+
+/**
+ * @brief Convert String to Unsigned Character (with validation)
+ *
+ * This method converts a string to an unsigned character with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_unsigned_char(
+ const char *s,
+ unsigned char *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Int (with validation)
+ *
+ * This method converts a string to an int with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_int(
+ const char *s,
+ int *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Unsigned Int (with validation)
+ *
+ * This method converts a string to an unsigned int with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_unsigned_int(
+ const char *s,
+ unsigned int *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Long (with validation)
+ *
+ * This method converts a string to a long with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_long(
+ const char *s,
+ long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Unsigned Long (with validation)
+ *
+ * This method converts a string to an unsigned long with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_unsigned_long(
+ const char *s,
+ unsigned long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Long Long (with validation)
+ *
+ * This method converts a string to a long long with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_long_long(
+ const char *s,
+ long long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Unsigned Long Long (with validation)
+ *
+ * This method converts a string to an unsigned character with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_unsigned_long_long(
+ const char *s,
+ unsigned long long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Float (with validation)
+ *
+ * This method converts a string to a float with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_float(
+ const char *s,
+ float *n,
+ char **endptr
+);
+
+/**
+ * @brief Convert String to Double (with validation)
+ *
+ * This method converts a string to a double with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_double(
+ const char *s,
+ double *n,
+ char **endptr
+);
+
+/**
+ * @brief Convert String to long double (with validation)
+ *
+ * This method converts a string to a long double with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ *
+ * @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ * and *n is filled in. Otherwise, the status indicates the
+ * source of the error.
+ */
+rtems_status_code rtems_string_to_long_double(
+ const char *s,
+ long double *n,
+ char **endptr
+);
+
+#endif
diff --git a/cpukit/libmisc/stringto/stringtodouble.c b/cpukit/libmisc/stringto/stringtodouble.c
new file mode 100644
index 0000000000..ec50a1332b
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtodouble.c
@@ -0,0 +1,58 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtod (double)
+ */
+
+rtems_status_code rtems_string_to_double (
+ const char *s,
+ double *n,
+ char **endptr
+)
+{
+ double result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtod( s, &end );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == HUGE_VAL ) || ( result == -HUGE_VAL )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtofloat.c b/cpukit/libmisc/stringto/stringtofloat.c
new file mode 100644
index 0000000000..05ebe33566
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtofloat.c
@@ -0,0 +1,58 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtof (float)
+ */
+
+rtems_status_code rtems_string_to_float (
+ const char *s,
+ float *n,
+ char **endptr
+)
+{
+ float result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtof( s, &end );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == HUGE_VALF ) || ( result == -HUGE_VALF )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtoint.c b/cpukit/libmisc/stringto/stringtoint.c
new file mode 100644
index 0000000000..8e3663b496
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtoint.c
@@ -0,0 +1,73 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtol (int)
+ */
+
+rtems_status_code rtems_string_to_int (
+ const char *s,
+ int *n,
+ char **endptr,
+ int base
+)
+{
+ long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtol( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
+ return RTEMS_INVALID_NUMBER;
+
+#if (INT_MAX < LONG_MAX)
+ if ( result > INT_MAX ) {
+ errno = ERANGE;
+ return RTEMS_INVALID_NUMBER;
+ }
+#endif
+
+#if (INT_MIN < LONG_MIN)
+ if ( result < INT_MIN ) {
+ errno = ERANGE;
+ return RTEMS_INVALID_NUMBER;
+ }
+#endif
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtolong.c b/cpukit/libmisc/stringto/stringtolong.c
new file mode 100644
index 0000000000..e77b8822b8
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtolong.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtol (long)
+ */
+
+rtems_status_code rtems_string_to_long (
+ const char *s,
+ long *n,
+ char **endptr,
+ int base
+)
+{
+ long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtol( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtolongdouble.c b/cpukit/libmisc/stringto/stringtolongdouble.c
new file mode 100644
index 0000000000..776f5e183b
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtolongdouble.c
@@ -0,0 +1,58 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtod (double)
+ */
+
+rtems_status_code rtems_string_to_long_double (
+ const char *s,
+ long double *n,
+ char **endptr
+)
+{
+ long double result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtold( s, &end );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == HUGE_VALL ) || ( result == -HUGE_VALL )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtolonglong.c b/cpukit/libmisc/stringto/stringtolonglong.c
new file mode 100644
index 0000000000..d291262477
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtolonglong.c
@@ -0,0 +1,68 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/* c99 has LLONG_MAX instead of LONG_LONG_MAX */
+#ifndef LONG_LONG_MAX
+#define LONG_LONG_MAX LLONG_MAX
+#endif
+/* c99 has LLONG_MIN instead of LONG_LONG_MIN */
+#ifndef LONG_LONG_MIN
+#define LONG_LONG_MIN LLONG_MIN
+#endif
+
+/*
+ * Instantiate an error checking wrapper for strtoll (long long)
+ */
+
+rtems_status_code rtems_string_to_long_long (
+ const char *s,
+ long long *n,
+ char **endptr,
+ int base
+)
+{
+ long long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtoll( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == LONG_LONG_MAX ) || ( result == LONG_LONG_MIN )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtopointer.c b/cpukit/libmisc/stringto/stringtopointer.c
new file mode 100644
index 0000000000..3a99baa3b5
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtopointer.c
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <stdint.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtoul/strtoull (void *)
+ */
+
+#if (UINTPTR_MAX == ULONG_MAX)
+#define STRTOFUNC(a,b,c) rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
+#elif (UINTPTR_MAX == ULONG_LONG_MAX)
+#define STRTOFUNC(a,b,c) rtems_string_to_unsigned_long_long(a, (unsigned long long*) b, c, 0)
+#elif (UINTPTR_MAX == UINT_MAX)
+#define STRTOFUNC(a,b,c) rtems_string_to_unsigned_int(a, (unsigned int*) b, c, 0)
+#else
+/* Fallback to unsigned long */
+#define STRTOFUNC(a,b,c) rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
+#endif
+
+rtems_status_code rtems_string_to_pointer (
+ const char *s,
+ void **n,
+ char **endptr
+)
+{
+ return STRTOFUNC( s, n, endptr );
+}
diff --git a/cpukit/libmisc/stringto/stringtounsignedchar.c b/cpukit/libmisc/stringto/stringtounsignedchar.c
new file mode 100644
index 0000000000..5223b03fb7
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtounsignedchar.c
@@ -0,0 +1,66 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtoul (unsigned char)
+ */
+
+rtems_status_code rtems_string_to_unsigned_char (
+ const char *s,
+ unsigned char *n,
+ char **endptr,
+ int base
+)
+{
+ unsigned long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtoul( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == ULONG_MAX )))
+ return RTEMS_INVALID_NUMBER;
+
+#if (UCHAR_MAX < ULONG_MAX)
+ if ( result > UCHAR_MAX ) {
+ errno = ERANGE;
+ return RTEMS_INVALID_NUMBER;
+ }
+#endif
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtounsignedint.c b/cpukit/libmisc/stringto/stringtounsignedint.c
new file mode 100644
index 0000000000..9821beff87
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtounsignedint.c
@@ -0,0 +1,66 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtoul (unsigned int)
+ */
+
+rtems_status_code rtems_string_to_unsigned_int (
+ const char *s,
+ unsigned int *n,
+ char **endptr,
+ int base
+)
+{
+ unsigned long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtoul( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == ULONG_MAX )))
+ return RTEMS_INVALID_NUMBER;
+
+#if (UINT_MAX < ULONG_MAX)
+ if ( result > UINT_MAX ) {
+ errno = ERANGE;
+ return RTEMS_INVALID_NUMBER;
+ }
+#endif
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtounsignedlong.c b/cpukit/libmisc/stringto/stringtounsignedlong.c
new file mode 100644
index 0000000000..11c374c486
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtounsignedlong.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/*
+ * Instantiate an error checking wrapper for strtoul (unsigned long)
+ */
+
+rtems_status_code rtems_string_to_unsigned_long (
+ const char *s,
+ unsigned long *n,
+ char **endptr,
+ int base
+)
+{
+ unsigned long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtoul( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == ULONG_MAX )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/stringto/stringtounsignedlonglong.c b/cpukit/libmisc/stringto/stringtounsignedlonglong.c
new file mode 100644
index 0000000000..61c6e2e063
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringtounsignedlonglong.c
@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011 Ralf Corsépius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/* c99 has ULLONG_MAX instead of ULONG_LONG_MAX */
+#ifndef ULONG_LONG_MAX
+#define ULONG_LONG_MAX ULLONG_MAX
+#endif
+
+/*
+ * Instantiate an error checking wrapper for strtoull (unsigned long long)
+ */
+
+rtems_status_code rtems_string_to_unsigned_long_long (
+ const char *s,
+ unsigned long long *n,
+ char **endptr,
+ int base
+)
+{
+ unsigned long long result;
+ char *end;
+
+ if ( !n )
+ return RTEMS_INVALID_ADDRESS;
+
+ errno = 0;
+ *n = 0;
+
+ result = strtoull( s, &end, base );
+
+ if ( endptr )
+ *endptr = end;
+
+ if ( end == s )
+ return RTEMS_NOT_DEFINED;
+
+ if ( ( errno == ERANGE ) &&
+ (( result == 0 ) || ( result == ULONG_LONG_MAX )))
+ return RTEMS_INVALID_NUMBER;
+
+ *n = result;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/untar/README b/cpukit/libmisc/untar/README
new file mode 100644
index 0000000000..24c9e7fa62
--- /dev/null
+++ b/cpukit/libmisc/untar/README
@@ -0,0 +1,26 @@
+#
+#
+# untar information
+#
+# Author: Jake Janovetz 7.6.1999
+#
+# $Id$
+#
+
+untar.c contains two procedures for extracting files from a UNIX
+tar file:
+
+ int Untar_FromMemory(unsigned char *tar_buf, unsigned long size);
+ int Untar_FromFile(char *tar_name);
+
+Untar_FromMemory(...) takes its input from a chunk of allocated memory.
+This is particularly useful when the tar is stored in Flash memory or
+comes from the FTP daemon by way of a hook.
+
+Untar_FromFile(...) is identical except the source is from an existing
+file. The fully qualified filename is passed through char *tar_name.
+
+
+
+BUGS: Please email janovetz@uiuc.edu
+-----
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
new file mode 100644
index 0000000000..2c5c8e9cf3
--- /dev/null
+++ b/cpukit/libmisc/untar/untar.c
@@ -0,0 +1,384 @@
+/* FIXME:
+ * 1. Symbolic links are not created.
+ * 2. Untar_FromMemory uses FILE *fp.
+ * 3. How to determine end of archive?
+ *
+ * Written by: Jake Janovetz <janovetz@tempest.ece.uiuc.edu>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <rtems/untar.h>
+#include <rtems/bspIo.h>
+
+
+/**************************************************************************
+ * TAR file format:
+ *
+ * Offset Length Contents
+ * 0 100 bytes File name ('\0' terminated, 99 maxmum length)
+ * 100 8 bytes File mode (in octal ascii)
+ * 108 8 bytes User ID (in octal ascii)
+ * 116 8 bytes Group ID (in octal ascii)
+ * 124 12 bytes File size (s) (in octal ascii)
+ * 136 12 bytes Modify time (in octal ascii)
+ * 148 8 bytes Header checksum (in octal ascii)
+ * 156 1 bytes Link flag
+ * 157 100 bytes Linkname ('\0' terminated, 99 maxmum length)
+ * 257 8 bytes Magic PAX ("ustar\0" + 2 bytes padding)
+ * 257 8 bytes Magic GNU tar ("ustar \0")
+ * 265 32 bytes User name ('\0' terminated, 31 maxmum length)
+ * 297 32 bytes Group name ('\0' terminated, 31 maxmum length)
+ * 329 8 bytes Major device ID (in octal ascii)
+ * 337 8 bytes Minor device ID (in octal ascii)
+ * 345 155 bytes Prefix
+ * 512 (s+p)bytes File contents (s+p) := (((s) + 511) & ~511),
+ * round up to 512 bytes
+ *
+ * Checksum:
+ * int i, sum;
+ * char* header = tar_header_pointer;
+ * sum = 0;
+ * for(i = 0; i < 512; i++)
+ * sum += 0xFF & header[i];
+ *************************************************************************/
+
+#define MAX_NAME_FIELD_SIZE 99
+
+#define MIN(a,b) ((a)>(b)?(b):(a))
+
+
+/**************************************************************************
+ * This converts octal ASCII number representations into an
+ * unsigned long. Only support 32-bit numbers for now.
+ *************************************************************************/
+unsigned long
+_rtems_octal2ulong(
+ const char *octascii,
+ size_t len
+)
+{
+ size_t i;
+ unsigned long num;
+
+ num = 0;
+ for (i=0; i < len; i++)
+ {
+ if ((octascii[i] < '0') || (octascii[i] > '9'))
+ {
+ continue;
+ }
+ num = num * 8 + ((unsigned long)(octascii[i] - '0'));
+ }
+ return(num);
+}
+
+
+/**************************************************************************
+ * Function: Untar_FromMemory *
+ **************************************************************************
+ * Description: *
+ * *
+ * This is a simple subroutine used to rip links, directories, and *
+ * files out of a block of memory. *
+ * *
+ * *
+ * Inputs: *
+ * *
+ * void * tar_buf - Pointer to TAR buffer. *
+ * size_t size - Length of TAR buffer. *
+ * *
+ * *
+ * Output: *
+ * *
+ * int - UNTAR_SUCCESSFUL (0) on successful completion. *
+ * UNTAR_INVALID_CHECKSUM for an invalid header checksum. *
+ * UNTAR_INVALID_HEADER for an invalid header. *
+ * *
+ **************************************************************************/
+int
+Untar_FromMemory(
+ void *tar_buf,
+ size_t size
+)
+{
+ FILE *fp;
+ const char *tar_ptr = (const char *)tar_buf;
+ const char *bufr;
+ size_t n;
+ char fname[100];
+ char linkname[100];
+ int sum;
+ int hdr_chksum;
+ int retval;
+ unsigned long ptr;
+ unsigned long i;
+ unsigned long nblocks;
+ unsigned long file_size;
+ unsigned char linkflag;
+
+
+ ptr = 0;
+ while (1)
+ {
+ if (ptr + 512 > size)
+ {
+ retval = UNTAR_SUCCESSFUL;
+ break;
+ }
+
+ /* Read the header */
+ bufr = &tar_ptr[ptr];
+ ptr += 512;
+ if (strncmp(&bufr[257], "ustar", 5))
+ {
+ retval = UNTAR_SUCCESSFUL;
+ break;
+ }
+
+ strncpy(fname, bufr, MAX_NAME_FIELD_SIZE);
+ fname[MAX_NAME_FIELD_SIZE] = '\0';
+
+ linkflag = bufr[156];
+ file_size = _rtems_octal2ulong(&bufr[124], 12);
+
+ /******************************************************************
+ * Compute the TAR checksum and check with the value in
+ * the archive. The checksum is computed over the entire
+ * header, but the checksum field is substituted with blanks.
+ ******************************************************************/
+ hdr_chksum = _rtems_octal2ulong(&bufr[148], 8);
+ sum = _rtems_tar_header_checksum(bufr);
+
+ if (sum != hdr_chksum)
+ {
+ retval = UNTAR_INVALID_CHECKSUM;
+ break;
+ }
+
+
+ /******************************************************************
+ * We've decoded the header, now figure out what it contains and
+ * do something with it.
+ *****************************************************************/
+ if (linkflag == SYMTYPE)
+ {
+ strncpy(linkname, &bufr[157], MAX_NAME_FIELD_SIZE);
+ linkname[MAX_NAME_FIELD_SIZE] = '\0';
+ symlink(linkname, fname);
+ }
+ else if (linkflag == REGTYPE)
+ {
+ nblocks = (((file_size) + 511) & ~511) / 512;
+ if ((fp = fopen(fname, "w")) == NULL)
+ {
+ printk("Untar: failed to create file %s\n", fname);
+ ptr += 512 * nblocks;
+ }
+ else
+ {
+ unsigned long sizeToGo = file_size;
+ size_t len;
+
+ /***************************************************************
+ * Read out the data. There are nblocks of data where nblocks
+ * is the file_size rounded to the nearest 512-byte boundary.
+ **************************************************************/
+ for (i=0; i<nblocks; i++)
+ {
+ len = ((sizeToGo < 512L)?(sizeToGo):(512L));
+ n = fwrite(&tar_ptr[ptr], 1, len, fp);
+ if (n != len)
+ {
+ printk("untar: Error during write\n");
+ break;
+ }
+ ptr += 512;
+ sizeToGo -= n;
+ }
+ fclose(fp);
+ }
+ }
+ else if (linkflag == DIRTYPE)
+ {
+ mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
+ }
+ }
+
+ return(retval);
+}
+
+
+/**************************************************************************
+ * Function: Untar_FromFile *
+ **************************************************************************
+ * Description: *
+ * *
+ * This is a simple subroutine used to rip links, directories, and *
+ * files out of a TAR file. *
+ * *
+ * *
+ * Inputs: *
+ * *
+ * const char *tar_name - TAR filename. *
+ * *
+ * *
+ * Output: *
+ * *
+ * int - UNTAR_SUCCESSFUL (0) on successful completion. *
+ * UNTAR_INVALID_CHECKSUM for an invalid header checksum. *
+ * UNTAR_INVALID_HEADER for an invalid header. *
+ * *
+ **************************************************************************
+ * Change History: *
+ * 12/30/1998 - Creation (JWJ) *
+ *************************************************************************/
+int
+Untar_FromFile(
+ const char *tar_name
+)
+{
+ int fd;
+ char *bufr;
+ ssize_t n;
+ char fname[100];
+ char linkname[100];
+ int sum;
+ int hdr_chksum;
+ int retval;
+ unsigned long i;
+ unsigned long nblocks;
+ unsigned long size;
+ unsigned char linkflag;
+
+ retval = UNTAR_SUCCESSFUL;
+
+ if ((fd = open(tar_name, O_RDONLY)) < 0) {
+ return UNTAR_FAIL;
+ }
+
+ bufr = (char *)malloc(512);
+ if (bufr == NULL) {
+ return(UNTAR_FAIL);
+ }
+
+ while (1)
+ {
+ /* Read the header */
+ /* If the header read fails, we just consider it the end
+ of the tarfile. */
+ if ((n = read(fd, bufr, 512)) != 512)
+ {
+ break;
+ }
+
+ if (strncmp(&bufr[257], "ustar", 5))
+ {
+ break;
+ }
+
+ strncpy(fname, bufr, MAX_NAME_FIELD_SIZE);
+ fname[MAX_NAME_FIELD_SIZE] = '\0';
+
+ linkflag = bufr[156];
+ size = _rtems_octal2ulong(&bufr[124], 12);
+
+ /******************************************************************
+ * Compute the TAR checksum and check with the value in
+ * the archive. The checksum is computed over the entire
+ * header, but the checksum field is substituted with blanks.
+ ******************************************************************/
+ hdr_chksum = _rtems_octal2ulong(&bufr[148], 8);
+ sum = _rtems_tar_header_checksum(bufr);
+
+ if (sum != hdr_chksum)
+ {
+ retval = UNTAR_INVALID_CHECKSUM;
+ break;
+ }
+
+ /******************************************************************
+ * We've decoded the header, now figure out what it contains and
+ * do something with it.
+ *****************************************************************/
+ if (linkflag == SYMTYPE)
+ {
+ strncpy(linkname, &bufr[157], MAX_NAME_FIELD_SIZE);
+ linkname[MAX_NAME_FIELD_SIZE] = '\0';
+ symlink(linkname,fname);
+ }
+ else if (linkflag == REGTYPE)
+ {
+ int out_fd;
+
+ /******************************************************************
+ * Read out the data. There are nblocks of data where nblocks
+ * is the size rounded to the nearest 512-byte boundary.
+ *****************************************************************/
+ nblocks = (((size) + 511) & ~511) / 512;
+
+ if ((out_fd = creat(fname, 0644)) == -1)
+ {
+ for (i=0; i<nblocks; i++)
+ {
+ n = read(fd, bufr, 512);
+ }
+ }
+ else
+ {
+ for (i=0; i<nblocks; i++)
+ {
+ n = read(fd, bufr, 512);
+ n = MIN(n, size - i*512);
+ write(out_fd, bufr, n);
+ }
+ close(out_fd);
+ }
+ }
+ else if (linkflag == DIRTYPE)
+ {
+ mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
+ }
+ }
+ free(bufr);
+ close(fd);
+
+ return(retval);
+}
+
+/************************************************************************
+ * Compute the TAR checksum and check with the value in
+ * the archive. The checksum is computed over the entire
+ * header, but the checksum field is substituted with blanks.
+ ************************************************************************/
+int
+_rtems_tar_header_checksum(
+ const char *bufr
+)
+{
+ int i, sum;
+
+ sum = 0;
+ for (i=0; i<512; i++)
+ {
+ if ((i >= 148) && (i < 156))
+ sum += 0xff & ' ';
+ else
+ sum += 0xff & bufr[i];
+ }
+ return(sum);
+}
diff --git a/cpukit/libmisc/untar/untar.h b/cpukit/libmisc/untar/untar.h
new file mode 100644
index 0000000000..264753f2f7
--- /dev/null
+++ b/cpukit/libmisc/untar/untar.h
@@ -0,0 +1,49 @@
+/*
+ * Written by: Jake Janovetz <janovetz@tempest.ece.uiuc.edu>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_UNTAR_H
+#define _RTEMS_UNTAR_H
+
+#include <stddef.h>
+#include <tar.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define UNTAR_SUCCESSFUL 0
+#define UNTAR_FAIL 1
+#define UNTAR_INVALID_CHECKSUM 2
+#define UNTAR_INVALID_HEADER 3
+
+
+int Untar_FromMemory(void *tar_buf, size_t size);
+int Untar_FromFile(const char *tar_name);
+
+/**************************************************************************
+ * This converts octal ASCII number representations into an
+ * unsigned long. Only support 32-bit numbers for now.
+ *************************************************************************/
+extern unsigned long
+_rtems_octal2ulong(const char *octascii, size_t len);
+
+/************************************************************************
+ * Compute the TAR checksum and check with the value in
+ * the archive. The checksum is computed over the entire
+ * header, but the checksum field is substituted with blanks.
+ ************************************************************************/
+extern int
+_rtems_tar_header_checksum(const char *bufr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_UNTAR_H */
diff --git a/cpukit/libmisc/uuid/COPYING b/cpukit/libmisc/uuid/COPYING
new file mode 100644
index 0000000000..2f17068367
--- /dev/null
+++ b/cpukit/libmisc/uuid/COPYING
@@ -0,0 +1,25 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, and the entire permission notice in its entirety,
+ including the disclaimer of warranties.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
diff --git a/cpukit/libmisc/uuid/README b/cpukit/libmisc/uuid/README
new file mode 100644
index 0000000000..6b5c9eee97
--- /dev/null
+++ b/cpukit/libmisc/uuid/README
@@ -0,0 +1,14 @@
+uuid - DCE compatible Universally Unique Identifier library
+
+The UUID library is used to generate unique identifiers for objects that may be
+accessible beyond the local system. This library generates UUIDs compatible
+with those created by the Open Software Foundation (OSF) Distributed Computing
+Environment (DCE) utility uuidgen.
+
+The UUIDs generated by this library can be reasonably expected to be unique
+within a system, and unique across all systems. They could be used, for
+instance, to generate unique HTTP cookies across multiple web servers without
+communication between the servers, and without fear of a name clash.
+
+This code is from the E2fsprogs project: http://e2fsprogs.sourceforge.net.
+The package was e2fsprogs-libs-1.41.5.tar.gz.
diff --git a/cpukit/libmisc/uuid/clear.c b/cpukit/libmisc/uuid/clear.c
new file mode 100644
index 0000000000..5a1d188f6e
--- /dev/null
+++ b/cpukit/libmisc/uuid/clear.c
@@ -0,0 +1,47 @@
+/*
+ * clear.c -- Clear a UUID
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include "uuidP.h"
+
+void uuid_clear(uuid_t uu)
+{
+ memset(uu, 0, 16);
+}
+
diff --git a/cpukit/libmisc/uuid/compare.c b/cpukit/libmisc/uuid/compare.c
new file mode 100644
index 0000000000..888121f0ff
--- /dev/null
+++ b/cpukit/libmisc/uuid/compare.c
@@ -0,0 +1,59 @@
+/*
+ * compare.c --- compare whether or not two UUID's are the same
+ *
+ * Returns 0 if the two UUID's are different, and 1 if they are the same.
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include "uuidP.h"
+
+#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);
+
+int uuid_compare(const uuid_t uu1, const uuid_t uu2)
+{
+ struct uuid uuid1, uuid2;
+
+ uuid_unpack(uu1, &uuid1);
+ uuid_unpack(uu2, &uuid2);
+
+ UUCMP(uuid1.time_low, uuid2.time_low);
+ UUCMP(uuid1.time_mid, uuid2.time_mid);
+ UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
+ UUCMP(uuid1.clock_seq, uuid2.clock_seq);
+ return memcmp(uuid1.node, uuid2.node, 6);
+}
+
diff --git a/cpukit/libmisc/uuid/copy.c b/cpukit/libmisc/uuid/copy.c
new file mode 100644
index 0000000000..abf09d6fb3
--- /dev/null
+++ b/cpukit/libmisc/uuid/copy.c
@@ -0,0 +1,49 @@
+/*
+ * copy.c --- copy UUIDs
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "uuidP.h"
+
+void uuid_copy(uuid_t dst, const uuid_t src)
+{
+ unsigned char *cp1;
+ const unsigned char *cp2;
+ int i;
+
+ for (i=0, cp1 = dst, cp2 = src; i < 16; i++)
+ *cp1++ = *cp2++;
+}
diff --git a/cpukit/libmisc/uuid/gen_uuid.c b/cpukit/libmisc/uuid/gen_uuid.c
new file mode 100644
index 0000000000..7993ee5332
--- /dev/null
+++ b/cpukit/libmisc/uuid/gen_uuid.c
@@ -0,0 +1,670 @@
+/*
+ * gen_uuid.c --- generate a DCE-compatible uuid
+ *
+ * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Force inclusion of SVID stuff since we need it if we're compiling in
+ * gcc-wall wall mode
+ */
+#define _SVID_SOURCE
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#define UUID MYUUID
+#endif
+#include <stdio.h>
+#include <limits.h> /* for CHAR_BIT */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <sys/wait.h>
+#include <sys/stat.h>
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NET_IF_DL_H
+#include <net/if_dl.h>
+#endif
+#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
+#include "uuidP.h"
+#include "uuidd.h"
+
+#ifdef HAVE_SRANDOM
+#define srand(x) srandom(x)
+#define rand() random()
+#endif
+
+#ifdef TLS
+#define THREAD_LOCAL static TLS
+#else
+#define THREAD_LOCAL static
+#endif
+
+#if defined(__linux__) && defined(__NR_gettid) && defined(HAVE_JRAND48)
+#define DO_JRAND_MIX
+THREAD_LOCAL unsigned short jrand_seed[3];
+#endif
+
+#ifdef _WIN32
+static void gettimeofday (struct timeval *tv, void *dummy)
+{
+ FILETIME ftime;
+ uint64_t n;
+
+ GetSystemTimeAsFileTime (&ftime);
+ n = (((uint64_t) ftime.dwHighDateTime << 32)
+ + (uint64_t) ftime.dwLowDateTime);
+ if (n) {
+ n /= 10;
+ n -= ((369 * 365 + 89) * (uint64_t) 86400) * 1000000;
+ }
+
+ tv->tv_sec = n / 1000000;
+ tv->tv_usec = n % 1000000;
+}
+
+static int getuid (void)
+{
+ return 1;
+}
+#endif
+
+static int get_random_fd(void)
+{
+ struct timeval tv;
+ static int fd = -2;
+ int i;
+
+ if (fd == -2) {
+ gettimeofday(&tv, 0);
+#ifndef _WIN32
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1)
+ fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
+ if (fd >= 0) {
+ i = fcntl(fd, F_GETFD);
+ if (i >= 0)
+ fcntl(fd, F_SETFD, i | FD_CLOEXEC);
+ }
+#endif
+ srand((getpid() << ((sizeof(pid_t)*CHAR_BIT)>>1)) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
+#ifdef DO_JRAND_MIX
+ jrand_seed[0] = getpid() ^ (tv.tv_sec & 0xFFFF);
+ jrand_seed[1] = getppid() ^ (tv.tv_usec & 0xFFFF);
+ jrand_seed[2] = (tv.tv_sec ^ tv.tv_usec) >> 16;
+#endif
+ }
+ /* Crank the random number generator a few times */
+ gettimeofday(&tv, 0);
+ for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
+ rand();
+ return fd;
+}
+
+
+/*
+ * Generate a series of random bytes. Use /dev/urandom if possible,
+ * and if not, use srandom/random.
+ */
+static void get_random_bytes(void *buf, int nbytes)
+{
+ int i, n = nbytes, fd = get_random_fd();
+ int lose_counter = 0;
+ unsigned char *cp = (unsigned char *) buf;
+#ifdef DO_JRAND_MIX
+ unsigned short tmp_seed[3];
+#endif
+
+ if (fd >= 0) {
+ while (n > 0) {
+ i = read(fd, cp, n);
+ if (i <= 0) {
+ if (lose_counter++ > 16)
+ break;
+ continue;
+ }
+ n -= i;
+ cp += i;
+ lose_counter = 0;
+ }
+ }
+
+ /*
+ * We do this all the time, but this is the only source of
+ * randomness if /dev/random/urandom is out to lunch.
+ */
+ for (cp = buf, i = 0; i < nbytes; i++)
+ *cp++ ^= (rand() >> 7) & 0xFF;
+#ifdef DO_JRAND_MIX
+ memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed));
+ jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid);
+ for (cp = buf, i = 0; i < nbytes; i++)
+ *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF;
+ memcpy(jrand_seed, tmp_seed,
+ sizeof(jrand_seed)-sizeof(unsigned short));
+#endif
+
+ return;
+}
+
+/*
+ * Get the ethernet hardware address, if we can find it...
+ *
+ * XXX for a windows version, probably should use GetAdaptersInfo:
+ * http://www.codeguru.com/cpp/i-n/network/networkinformation/article.php/c5451
+ * commenting out get_node_id just to get gen_uuid to compile under windows
+ * is not the right way to go!
+ */
+static int get_node_id(unsigned char *node_id)
+{
+#ifdef HAVE_NET_IF_H
+ int sd;
+ struct ifreq ifr, *ifrp;
+ struct ifconf ifc;
+ char buf[1024];
+ int n, i;
+ unsigned char *a;
+#ifdef HAVE_NET_IF_DL_H
+ struct sockaddr_dl *sdlp;
+#endif
+
+/*
+ * BSD 4.4 defines the size of an ifreq to be
+ * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
+ * However, under earlier systems, sa_len isn't present, so the size is
+ * just sizeof(struct ifreq)
+ */
+#ifdef HAVE_SA_LEN
+#ifndef max
+#define max(a,b) ((a) > (b) ? (a) : (b))
+#endif
+#define ifreq_size(i) max(sizeof(struct ifreq),\
+ sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
+#else
+#define ifreq_size(i) sizeof(struct ifreq)
+#endif /* HAVE_SA_LEN*/
+
+ sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
+ if (sd < 0) {
+ return -1;
+ }
+ memset(buf, 0, sizeof(buf));
+ ifc.ifc_len = sizeof(buf);
+ ifc.ifc_buf = buf;
+ if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
+ close(sd);
+ return -1;
+ }
+ n = ifc.ifc_len;
+ for (i = 0; i < n; i+= ifreq_size(*ifrp) ) {
+ ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
+ strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
+#ifdef SIOCGIFHWADDR
+ if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
+ continue;
+ a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
+#else
+#ifdef SIOCGENADDR
+ if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
+ continue;
+ a = (unsigned char *) ifr.ifr_enaddr;
+#else
+#ifdef HAVE_NET_IF_DL_H
+ sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr;
+ if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen != 6))
+ continue;
+ a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen];
+#else
+ /*
+ * XXX we don't have a way of getting the hardware
+ * address
+ */
+ close(sd);
+ return 0;
+#endif /* HAVE_NET_IF_DL_H */
+#endif /* SIOCGENADDR */
+#endif /* SIOCGIFHWADDR */
+ if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
+ continue;
+ if (node_id) {
+ memcpy(node_id, a, 6);
+ close(sd);
+ return 1;
+ }
+ }
+ close(sd);
+#endif
+ return 0;
+}
+
+/* Assume that the gettimeofday() has microsecond granularity */
+#define MAX_ADJUSTMENT 10
+
+static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
+ uint16_t *ret_clock_seq, int *num)
+{
+ THREAD_LOCAL int adjustment = 0;
+ THREAD_LOCAL struct timeval last = {0, 0};
+ THREAD_LOCAL int state_fd = -2;
+ THREAD_LOCAL FILE *state_f;
+ THREAD_LOCAL uint16_t clock_seq;
+ struct timeval tv;
+ struct flock fl;
+ uint64_t clock_reg;
+ mode_t save_umask;
+ int len;
+
+ if (state_fd == -2) {
+ save_umask = umask(0);
+ state_fd = open("/var/lib/libuuid/clock.txt",
+ O_RDWR|O_CREAT, 0660);
+ (void) umask(save_umask);
+ state_f = fdopen(state_fd, "r+");
+ if (!state_f) {
+ close(state_fd);
+ state_fd = -1;
+ }
+ }
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+ fl.l_pid = 0;
+ if (state_fd >= 0) {
+ rewind(state_f);
+ while (fcntl(state_fd, F_SETLKW, &fl) < 0) {
+ if ((errno == EAGAIN) || (errno == EINTR))
+ continue;
+ fclose(state_f);
+ close(state_fd);
+ state_fd = -1;
+ break;
+ }
+ }
+ if (state_fd >= 0) {
+ unsigned int cl;
+ unsigned long tv1, tv2;
+ int a;
+
+ if (fscanf(state_f, "clock: %04x tv: %lu %lu adj: %d\n",
+ &cl, &tv1, &tv2, &a) == 4) {
+ clock_seq = cl & 0x3FFF;
+ last.tv_sec = tv1;
+ last.tv_usec = tv2;
+ adjustment = a;
+ }
+ }
+
+ if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
+ get_random_bytes(&clock_seq, sizeof(clock_seq));
+ clock_seq &= 0x3FFF;
+ gettimeofday(&last, 0);
+ last.tv_sec--;
+ }
+
+try_again:
+ gettimeofday(&tv, 0);
+ if ((tv.tv_sec < last.tv_sec) ||
+ ((tv.tv_sec == last.tv_sec) &&
+ (tv.tv_usec < last.tv_usec))) {
+ clock_seq = (clock_seq+1) & 0x3FFF;
+ adjustment = 0;
+ last = tv;
+ } else if ((tv.tv_sec == last.tv_sec) &&
+ (tv.tv_usec == last.tv_usec)) {
+ if (adjustment >= MAX_ADJUSTMENT)
+ goto try_again;
+ adjustment++;
+ } else {
+ adjustment = 0;
+ last = tv;
+ }
+
+ clock_reg = tv.tv_usec*10 + adjustment;
+ clock_reg += ((uint64_t) tv.tv_sec)*10000000;
+ clock_reg += (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
+
+ if (num && (*num > 1)) {
+ adjustment += *num - 1;
+ last.tv_usec += adjustment / 10;
+ adjustment = adjustment % 10;
+ last.tv_sec += last.tv_usec / 1000000;
+ last.tv_usec = last.tv_usec % 1000000;
+ }
+
+ if (state_fd > 0) {
+ rewind(state_f);
+ len = fprintf(state_f,
+ "clock: %04x tv: %016lu %08lu adj: %08d\n",
+ clock_seq, last.tv_sec, last.tv_usec, adjustment);
+ fflush(state_f);
+ if (ftruncate(state_fd, len) < 0) {
+ fprintf(state_f, " \n");
+ fflush(state_f);
+ }
+ rewind(state_f);
+ fl.l_type = F_UNLCK;
+ fcntl(state_fd, F_SETLK, &fl);
+ }
+
+ *clock_high = clock_reg >> 32;
+ *clock_low = clock_reg;
+ *ret_clock_seq = clock_seq;
+ return 0;
+}
+
+/* unused */
+#if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
+static ssize_t read_all(int fd, char *buf, size_t count)
+{
+ ssize_t ret;
+ ssize_t c = 0;
+
+ memset(buf, 0, count);
+ while (count > 0) {
+ ret = read(fd, buf, count);
+ if (ret < 0) {
+ if ((errno == EAGAIN) || (errno == EINTR))
+ continue;
+ return -1;
+ }
+ count -= ret;
+ buf += ret;
+ c += ret;
+ }
+ return c;
+}
+#endif
+
+#if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
+
+/*
+ * Close all file descriptors
+ */
+static void close_all_fds(void)
+{
+ int i, max;
+
+#if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
+ max = sysconf(_SC_OPEN_MAX);
+#elif defined(HAVE_GETDTABLESIZE)
+ max = getdtablesize();
+#elif defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
+ struct rlimit rl;
+
+ getrlimit(RLIMIT_NOFILE, &rl);
+ max = rl.rlim_cur;
+#else
+ max = OPEN_MAX;
+#endif
+
+ for (i=0; i < max; i++)
+ close(i);
+}
+
+#endif
+
+
+/*
+ * Try using the uuidd daemon to generate the UUID
+ *
+ * Returns 0 on success, non-zero on failure.
+ */
+static int get_uuid_via_daemon(int op, uuid_t out, int *num)
+{
+#if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
+ char op_buf[64];
+ int op_len;
+ int s;
+ ssize_t ret;
+ int32_t reply_len = 0, expected = 16;
+ struct sockaddr_un srv_addr;
+ pid_t pid;
+ static const char *uuidd_path = UUIDD_PATH;
+ static int access_ret = -2;
+ static int start_attempts = 0;
+
+ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ return -1;
+
+ srv_addr.sun_family = AF_UNIX;
+ strcpy(srv_addr.sun_path, UUIDD_SOCKET_PATH);
+
+ if (connect(s, (const struct sockaddr *) &srv_addr,
+ sizeof(struct sockaddr_un)) < 0) {
+ if (access_ret == -2)
+ access_ret = access(uuidd_path, X_OK);
+ if (access_ret == 0 && start_attempts++ < 5) {
+ if ((pid = fork()) == 0) {
+ close_all_fds();
+ execl(uuidd_path, "uuidd", "-qT", "300",
+ (char *) NULL);
+ exit(1);
+ }
+ (void) waitpid(pid, 0, 0);
+ if (connect(s, (const struct sockaddr *) &srv_addr,
+ sizeof(struct sockaddr_un)) < 0)
+ goto fail;
+ } else
+ goto fail;
+ }
+ op_buf[0] = op;
+ op_len = 1;
+ if (op == UUIDD_OP_BULK_TIME_UUID) {
+ memcpy(op_buf+1, num, sizeof(*num));
+ op_len += sizeof(*num);
+ expected += sizeof(*num);
+ }
+
+ ret = write(s, op_buf, op_len);
+ if (ret < 1)
+ goto fail;
+
+ ret = read_all(s, (char *) &reply_len, sizeof(reply_len));
+ if (ret < 0)
+ goto fail;
+
+ if (reply_len != expected)
+ goto fail;
+
+ ret = read_all(s, op_buf, reply_len);
+
+ if (op == UUIDD_OP_BULK_TIME_UUID)
+ memcpy(op_buf+16, num, sizeof(int));
+
+ memcpy(out, op_buf, 16);
+
+ close(s);
+ return ((ret == expected) ? 0 : -1);
+
+fail:
+ close(s);
+#endif
+ return -1;
+}
+
+void uuid__generate_time(uuid_t out, int *num)
+{
+ static unsigned char node_id[6];
+ static int has_init = 0;
+ struct uuid uu;
+ uint32_t clock_mid;
+
+ if (!has_init) {
+ if (get_node_id(node_id) <= 0) {
+ get_random_bytes(node_id, 6);
+ /*
+ * Set multicast bit, to prevent conflicts
+ * with IEEE 802 addresses obtained from
+ * network cards
+ */
+ node_id[0] |= 0x01;
+ }
+ has_init = 1;
+ }
+ get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num);
+ uu.clock_seq |= 0x8000;
+ uu.time_mid = (uint16_t) clock_mid;
+ uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000;
+ memcpy(uu.node, node_id, 6);
+ uuid_pack(&uu, out);
+}
+
+void uuid_generate_time(uuid_t out)
+{
+#ifdef TLS
+ THREAD_LOCAL int num = 0;
+ THREAD_LOCAL struct uuid uu;
+ THREAD_LOCAL time_t last_time = 0;
+ time_t now;
+
+ if (num > 0) {
+ now = time(0);
+ if (now > last_time+1)
+ num = 0;
+ }
+ if (num <= 0) {
+ num = 1000;
+ if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
+ out, &num) == 0) {
+ last_time = time(0);
+ uuid_unpack(out, &uu);
+ num--;
+ return;
+ }
+ num = 0;
+ }
+ if (num > 0) {
+ uu.time_low++;
+ if (uu.time_low == 0) {
+ uu.time_mid++;
+ if (uu.time_mid == 0)
+ uu.time_hi_and_version++;
+ }
+ num--;
+ uuid_pack(&uu, out);
+ return;
+ }
+#else
+ if (get_uuid_via_daemon(UUIDD_OP_TIME_UUID, out, 0) == 0)
+ return;
+#endif
+
+ uuid__generate_time(out, 0);
+}
+
+
+void uuid__generate_random(uuid_t out, int *num)
+{
+ uuid_t buf;
+ struct uuid uu;
+ int i, n;
+
+ if (!num || !*num)
+ n = 1;
+ else
+ n = *num;
+
+ for (i = 0; i < n; i++) {
+ get_random_bytes(buf, sizeof(buf));
+ uuid_unpack(buf, &uu);
+
+ uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
+ uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF)
+ | 0x4000;
+ uuid_pack(&uu, out);
+ out += sizeof(uuid_t);
+ }
+}
+
+void uuid_generate_random(uuid_t out)
+{
+ int num = 1;
+ /* No real reason to use the daemon for random uuid's -- yet */
+
+ uuid__generate_random(out, &num);
+}
+
+
+/*
+ * This is the generic front-end to uuid_generate_random and
+ * uuid_generate_time. It uses uuid_generate_random only if
+ * /dev/urandom is available, since otherwise we won't have
+ * high-quality randomness.
+ */
+void uuid_generate(uuid_t out)
+{
+ if (get_random_fd() >= 0)
+ uuid_generate_random(out);
+ else
+ uuid_generate_time(out);
+}
diff --git a/cpukit/libmisc/uuid/isnull.c b/cpukit/libmisc/uuid/isnull.c
new file mode 100644
index 0000000000..11bd765d98
--- /dev/null
+++ b/cpukit/libmisc/uuid/isnull.c
@@ -0,0 +1,52 @@
+/*
+ * isnull.c --- Check whether or not the UUID is null
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "uuidP.h"
+
+/* Returns 1 if the uuid is the NULL uuid */
+int uuid_is_null(const uuid_t uu)
+{
+ const unsigned char *cp;
+ int i;
+
+ for (i=0, cp = uu; i < 16; i++)
+ if (*cp++)
+ return 0;
+ return 1;
+}
+
diff --git a/cpukit/libmisc/uuid/pack.c b/cpukit/libmisc/uuid/pack.c
new file mode 100644
index 0000000000..d4c9955374
--- /dev/null
+++ b/cpukit/libmisc/uuid/pack.c
@@ -0,0 +1,73 @@
+/*
+ * Internal routine for packing UUID's
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include "uuidP.h"
+
+void uuid_pack(const struct uuid *uu, uuid_t ptr)
+{
+ uint32_t tmp;
+ unsigned char *out = ptr;
+
+ tmp = uu->time_low;
+ out[3] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[2] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[1] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[0] = (unsigned char) tmp;
+
+ tmp = uu->time_mid;
+ out[5] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[4] = (unsigned char) tmp;
+
+ tmp = uu->time_hi_and_version;
+ out[7] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[6] = (unsigned char) tmp;
+
+ tmp = uu->clock_seq;
+ out[9] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[8] = (unsigned char) tmp;
+
+ memcpy(out+10, uu->node, 6);
+}
+
diff --git a/cpukit/libmisc/uuid/parse.c b/cpukit/libmisc/uuid/parse.c
new file mode 100644
index 0000000000..d995df1db0
--- /dev/null
+++ b/cpukit/libmisc/uuid/parse.c
@@ -0,0 +1,83 @@
+/*
+ * parse.c --- UUID parsing
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "uuidP.h"
+
+int uuid_parse(const char *in, uuid_t uu)
+{
+ struct uuid uuid;
+ int i;
+ const char *cp;
+ char buf[3];
+
+ if (strlen(in) != 36)
+ return -1;
+ for (i=0, cp = in; i <= 36; i++,cp++) {
+ if ((i == 8) || (i == 13) || (i == 18) ||
+ (i == 23)) {
+ if (*cp == '-')
+ continue;
+ else
+ return -1;
+ }
+ if (i== 36)
+ if (*cp == 0)
+ continue;
+ if (!isxdigit((unsigned char)*cp))
+ return -1;
+ }
+ uuid.time_low = strtoul(in, NULL, 16);
+ uuid.time_mid = strtoul(in+9, NULL, 16);
+ uuid.time_hi_and_version = strtoul(in+14, NULL, 16);
+ uuid.clock_seq = strtoul(in+19, NULL, 16);
+ cp = in+24;
+ buf[2] = 0;
+ for (i=0; i < 6; i++) {
+ buf[0] = *cp++;
+ buf[1] = *cp++;
+ uuid.node[i] = strtoul(buf, NULL, 16);
+ }
+
+ uuid_pack(&uuid, uu);
+ return 0;
+}
diff --git a/cpukit/libmisc/uuid/unpack.c b/cpukit/libmisc/uuid/unpack.c
new file mode 100644
index 0000000000..4520633b7e
--- /dev/null
+++ b/cpukit/libmisc/uuid/unpack.c
@@ -0,0 +1,67 @@
+/*
+ * Internal routine for unpacking UUID
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include "uuidP.h"
+
+void uuid_unpack(const uuid_t in, struct uuid *uu)
+{
+ const uint8_t *ptr = in;
+ uint32_t tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_low = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_mid = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_hi_and_version = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->clock_seq = tmp;
+
+ memcpy(uu->node, ptr, 6);
+}
+
diff --git a/cpukit/libmisc/uuid/unparse.c b/cpukit/libmisc/uuid/unparse.c
new file mode 100644
index 0000000000..25cf07dc78
--- /dev/null
+++ b/cpukit/libmisc/uuid/unparse.c
@@ -0,0 +1,80 @@
+/*
+ * unparse.c -- convert a UUID to string
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include "uuidP.h"
+
+static const char *fmt_lower =
+ "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
+
+static const char *fmt_upper =
+ "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X";
+
+#ifdef UUID_UNPARSE_DEFAULT_UPPER
+#define FMT_DEFAULT fmt_upper
+#else
+#define FMT_DEFAULT fmt_lower
+#endif
+
+static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt)
+{
+ struct uuid uuid;
+
+ uuid_unpack(uu, &uuid);
+ sprintf(out, fmt,
+ uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
+ uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
+ uuid.node[0], uuid.node[1], uuid.node[2],
+ uuid.node[3], uuid.node[4], uuid.node[5]);
+}
+
+void uuid_unparse_lower(const uuid_t uu, char *out)
+{
+ uuid_unparse_x(uu, out, fmt_lower);
+}
+
+void uuid_unparse_upper(const uuid_t uu, char *out)
+{
+ uuid_unparse_x(uu, out, fmt_upper);
+}
+
+void uuid_unparse(const uuid_t uu, char *out)
+{
+ uuid_unparse_x(uu, out, FMT_DEFAULT);
+}
diff --git a/cpukit/libmisc/uuid/uuid.h b/cpukit/libmisc/uuid/uuid.h
new file mode 100644
index 0000000000..ca846da0f0
--- /dev/null
+++ b/cpukit/libmisc/uuid/uuid.h
@@ -0,0 +1,103 @@
+/*
+ * Public include file for the UUID library
+ *
+ * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifndef _UUID_UUID_H
+#define _UUID_UUID_H
+
+#include <sys/types.h>
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+#include <time.h>
+
+typedef unsigned char uuid_t[16];
+
+/* UUID Variant definitions */
+#define UUID_VARIANT_NCS 0
+#define UUID_VARIANT_DCE 1
+#define UUID_VARIANT_MICROSOFT 2
+#define UUID_VARIANT_OTHER 3
+
+/* UUID Type definitions */
+#define UUID_TYPE_DCE_TIME 1
+#define UUID_TYPE_DCE_RANDOM 4
+
+/* Allow UUID constants to be defined */
+#ifdef __GNUC__
+#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
+ static const uuid_t name __attribute__ ((unused)) = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
+#else
+#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
+ static const uuid_t name = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* clear.c */
+void uuid_clear(uuid_t uu);
+
+/* compare.c */
+int uuid_compare(const uuid_t uu1, const uuid_t uu2);
+
+/* copy.c */
+void uuid_copy(uuid_t dst, const uuid_t src);
+
+/* gen_uuid.c */
+void uuid_generate(uuid_t out);
+void uuid_generate_random(uuid_t out);
+void uuid_generate_time(uuid_t out);
+
+/* isnull.c */
+int uuid_is_null(const uuid_t uu);
+
+/* parse.c */
+int uuid_parse(const char *in, uuid_t uu);
+
+/* unparse.c */
+void uuid_unparse(const uuid_t uu, char *out);
+void uuid_unparse_lower(const uuid_t uu, char *out);
+void uuid_unparse_upper(const uuid_t uu, char *out);
+
+/* uuid_time.c */
+time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
+int uuid_type(const uuid_t uu);
+int uuid_variant(const uuid_t uu);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UUID_UUID_H */
diff --git a/cpukit/libmisc/uuid/uuidP.h b/cpukit/libmisc/uuid/uuidP.h
new file mode 100644
index 0000000000..d0e24c6942
--- /dev/null
+++ b/cpukit/libmisc/uuid/uuidP.h
@@ -0,0 +1,63 @@
+/*
+ * uuid.h -- private header file for uuids
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else
+#include <uuid/uuid_types.h>
+#endif
+#include <sys/types.h>
+
+#include "uuid.h"
+
+/*
+ * Offset between 15-Oct-1582 and 1-Jan-70
+ */
+#define TIME_OFFSET_HIGH 0x01B21DD2
+#define TIME_OFFSET_LOW 0x13814000
+
+struct uuid {
+ uint32_t time_low;
+ uint16_t time_mid;
+ uint16_t time_hi_and_version;
+ uint16_t clock_seq;
+ uint8_t node[6];
+};
+
+
+/*
+ * prototypes
+ */
+void uuid_pack(const struct uuid *uu, uuid_t ptr);
+void uuid_unpack(const uuid_t in, struct uuid *uu);
diff --git a/cpukit/libmisc/uuid/uuid_time.c b/cpukit/libmisc/uuid/uuid_time.c
new file mode 100644
index 0000000000..f9325968df
--- /dev/null
+++ b/cpukit/libmisc/uuid/uuid_time.c
@@ -0,0 +1,175 @@
+/*
+ * uuid_time.c --- Interpret the time field from a uuid. This program
+ * violates the UUID abstraction barrier by reaching into the guts
+ * of a UUID and interpreting it.
+ *
+ * Copyright (C) 1998, 1999 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#define UUID MYUUID
+#endif
+
+#include <stdio.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdlib.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <time.h>
+
+#include "uuidP.h"
+
+time_t uuid_time(const uuid_t uu, struct timeval *ret_tv)
+{
+ struct timeval tv;
+ struct uuid uuid;
+ uint32_t high;
+ uint64_t clock_reg;
+
+ uuid_unpack(uu, &uuid);
+
+ high = uuid.time_mid | ((uint32_t)(uuid.time_hi_and_version & 0xFFF) << 16);
+ clock_reg = uuid.time_low | ((uint64_t) high << 32);
+
+ clock_reg -= (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
+ tv.tv_sec = clock_reg / 10000000;
+ tv.tv_usec = (clock_reg % 10000000) / 10;
+
+ if (ret_tv)
+ *ret_tv = tv;
+
+ return tv.tv_sec;
+}
+
+int uuid_type(const uuid_t uu)
+{
+ struct uuid uuid;
+
+ uuid_unpack(uu, &uuid);
+ return ((uuid.time_hi_and_version >> 12) & 0xF);
+}
+
+int uuid_variant(const uuid_t uu)
+{
+ struct uuid uuid;
+ int var;
+
+ uuid_unpack(uu, &uuid);
+ var = uuid.clock_seq;
+
+ if ((var & 0x8000) == 0)
+ return UUID_VARIANT_NCS;
+ if ((var & 0x4000) == 0)
+ return UUID_VARIANT_DCE;
+ if ((var & 0x2000) == 0)
+ return UUID_VARIANT_MICROSOFT;
+ return UUID_VARIANT_OTHER;
+}
+
+#ifdef DEBUG
+static const char *variant_string(int variant)
+{
+ switch (variant) {
+ case UUID_VARIANT_NCS:
+ return "NCS";
+ case UUID_VARIANT_DCE:
+ return "DCE";
+ case UUID_VARIANT_MICROSOFT:
+ return "Microsoft";
+ default:
+ return "Other";
+ }
+}
+
+
+int
+main(int argc, char **argv)
+{
+ uuid_t buf;
+ time_t time_reg;
+ struct timeval tv;
+ int type, variant;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s uuid\n", argv[0]);
+ exit(1);
+ }
+ if (uuid_parse(argv[1], buf)) {
+ fprintf(stderr, "Invalid UUID: %s\n", argv[1]);
+ exit(1);
+ }
+ variant = uuid_variant(buf);
+ type = uuid_type(buf);
+ time_reg = uuid_time(buf, &tv);
+
+ printf("UUID variant is %d (%s)\n", variant, variant_string(variant));
+ if (variant != UUID_VARIANT_DCE) {
+ printf("Warning: This program only knows how to interpret "
+ "DCE UUIDs.\n\tThe rest of the output is likely "
+ "to be incorrect!!\n");
+ }
+ printf("UUID type is %d", type);
+ switch (type) {
+ case 1:
+ printf(" (time based)\n");
+ break;
+ case 2:
+ printf(" (DCE)\n");
+ break;
+ case 3:
+ printf(" (name-based)\n");
+ break;
+ case 4:
+ printf(" (random)\n");
+ break;
+ default:
+ printf("\n");
+ }
+ if (type != 1) {
+ printf("Warning: not a time-based UUID, so UUID time "
+ "decoding will likely not work!\n");
+ }
+ printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
+ ctime(&time_reg));
+
+ return 0;
+}
+#endif
diff --git a/cpukit/libmisc/uuid/uuidd.h b/cpukit/libmisc/uuid/uuidd.h
new file mode 100644
index 0000000000..528acdc9d0
--- /dev/null
+++ b/cpukit/libmisc/uuid/uuidd.h
@@ -0,0 +1,53 @@
+/*
+ * Definitions used by the uuidd daemon
+ *
+ * Copyright (C) 2007 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifndef _UUID_UUIDD_H
+#define _UUID_UUIDD_H
+
+#define UUIDD_SOCKET_PATH "/var/lib/libuuid/request"
+#define UUIDD_PIDFILE_PATH "/var/lib/libuuid/uuidd.pid"
+#define UUIDD_PATH "/usr/sbin/uuidd"
+
+#define UUIDD_OP_GETPID 0
+#define UUIDD_OP_GET_MAXOP 1
+#define UUIDD_OP_TIME_UUID 2
+#define UUIDD_OP_RANDOM_UUID 3
+#define UUIDD_OP_BULK_TIME_UUID 4
+#define UUIDD_OP_BULK_RANDOM_UUID 5
+#define UUIDD_MAX_OP UUIDD_OP_BULK_RANDOM_UUID
+
+extern void uuid__generate_time(uuid_t out, int *num);
+extern void uuid__generate_random(uuid_t out, int *num);
+
+#endif /* _UUID_UUID_H */
diff --git a/cpukit/libnetworking/.cvsignore b/cpukit/libnetworking/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/libnetworking/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/libnetworking/Makefile.am b/cpukit/libnetworking/Makefile.am
new file mode 100644
index 0000000000..54f144f459
--- /dev/null
+++ b/cpukit/libnetworking/Makefile.am
@@ -0,0 +1,209 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+AM_CPPFLAGS += -I$(srcdir)
+
+EXTRA_DIST = README
+
+# poll is not supported
+UNUSED_FILES = poll.h
+# Original FreeBSD file
+UNUSED_FILES += sys/poll.h
+
+
+if LIBNETWORKING
+# Add -DFORWARD_PROTOCOL to enable UDP forwarding -- requires missing net/pf.h
+libnetworking_CPPFLAGS = -DINET -DNFS \
+ -DDIAGNOSTIC -DBOOTP_COMPAT -D_KERNEL -D__BSD_VISIBLE
+
+noinst_LIBRARIES = libnetworking.a
+libnetworking_a_CPPFLAGS = $(AM_CPPFLAGS) $(libnetworking_CPPFLAGS)
+
+## poll.h is not in the list because RTEMS does not have poll()
+## and installing poll.h confuses autoconf.
+include_HEADERS = netdb.h
+include_HEADERS += resolv.h syslog.h
+
+libnetworking_a_SOURCES = opt_atalk.h opt_bdg.h opt_compat.h opt_inet6.h \
+ opt_inet.h opt_ipfw.h opt_ipx.h opt_mac.h opt_mrouting.h opt_netgraph.h \
+ opt_tcpdebug.h opt_ipsec.h loop.h
+libnetworking_a_SOURCES += opt_ppp.h
+libnetworking_a_SOURCES += bpfilter.h
+
+# arpa
+
+include_arpadir = $(includedir)/arpa
+
+include_arpa_HEADERS = arpa/ftp.h arpa/inet.h arpa/nameser.h \
+ arpa/nameser_compat.h
+
+## kern
+
+libnetworking_a_SOURCES += kern/kern_mib.c kern/kern_subr.c \
+ kern/kern_sysctl.c kern/uipc_domain.c kern/uipc_mbuf.c \
+ kern/uipc_socket.c kern/uipc_socket2.c
+
+## machine
+
+include_machinedir = $(includedir)/machine
+
+include_machine_HEADERS = machine/cpu.h machine/cpufunc.h \
+ machine/in_cksum.h machine/vmparam.h
+
+libnetworking_a_SOURCES += machine/limits.h
+
+## net
+
+include_netdir = $(includedir)/net
+
+include_net_HEADERS = net/bpf.h net/ethernet.h net/if.h net/if_arp.h \
+ net/if_dl.h net/if_llc.h net/if_ppp.h net/if_types.h net/if_var.h \
+ net/netisr.h net/ppp_defs.h net/radix.h net/raw_cb.h \
+ net/route.h net/if_pppvar.h net/slcompress.h
+include_net_HEADERS += net/if_media.h
+include_net_HEADERS += net/ppp_comp.h
+
+libnetworking_a_SOURCES += net/if.c net/if_ethersubr.c net/if_loop.c \
+ net/radix.c net/route.c net/rtsock.c net/raw_cb.c net/raw_usrreq.c \
+ net/if_ppp.c net/ppp_tty.c net/slcompress.c
+
+## netinet
+
+include_netinetdir = $(includedir)/netinet
+
+include_netinet_HEADERS = netinet/icmp_var.h netinet/if_ether.h \
+ netinet/igmp.h netinet/igmp_var.h netinet/in.h netinet/in_pcb.h \
+ netinet/in_systm.h netinet/in_var.h netinet/ip.h netinet/ip_fw.h \
+ netinet/ip_icmp.h netinet/ip_mroute.h netinet/ip_var.h netinet/tcp.h \
+ netinet/tcp_debug.h netinet/tcp_fsm.h netinet/tcp_seq.h \
+ netinet/tcp_timer.h netinet/tcp_var.h netinet/tcpip.h netinet/udp.h \
+ netinet/udp_var.h
+
+libnetworking_a_SOURCES += netinet/if_ether.c netinet/igmp.c netinet/in.c \
+ netinet/in_cksum.c netinet/in_pcb.c netinet/in_proto.c netinet/in_rmx.c \
+ netinet/ip_divert.c netinet/ip_fw.c netinet/ip_icmp.c netinet/ip_input.c \
+ netinet/ip_mroute.c netinet/ip_output.c netinet/raw_ip.c \
+ netinet/tcp_debug.c netinet/tcp_input.c netinet/tcp_output.c \
+ netinet/tcp_subr.c netinet/tcp_timer.c netinet/tcp_usrreq.c \
+ netinet/udp_usrreq.c netinet/in_cksum_arm.h netinet/in_cksum_i386.h \
+ netinet/in_cksum_m68k.h netinet/in_cksum_powerpc.h
+
+## nfs
+
+include_nfsdir = $(includedir)/nfs
+
+include_nfs_HEADERS = nfs/nfsproto.h
+include_nfs_HEADERS += nfs/rpcv2.h
+include_nfs_HEADERS += nfs/xdr_subs.h
+
+libnetworking_a_SOURCES += nfs/bootp_subr.c
+
+## nfsclient
+include_nfsclientdir = $(includedir)/nfsclient
+
+include_nfsclient_HEADERS = nfsclient/nfsargs.h nfsclient/nfsdiskless.h
+
+## rtems
+
+include_rtemsdir = $(includedir)/rtems
+
+include_rtems_HEADERS = rtems/rtems_bsdnet.h rtems/rtems_bsdnet_internal.h \
+ rtems/dhcp.h rtems/rtems_dhcp_failsafe.h rtems/tftp.h rtems/ftpfs.h \
+ rtems/mkrootfs.h
+include_rtems_HEADERS += rtems/rtems_mii_ioctl.h
+
+libnetworking_a_SOURCES += rtems/sghostname.c \
+ rtems/rtems_glue.c rtems/rtems_malloc_mbuf.c rtems/rtems_syscall.c \
+ rtems/rtems_bootp.c rtems/rtems_dhcp.c rtems/rtems_dhcp_failsafe.c \
+ rtems/rtems_showmbuf.c rtems/rtems_showroute.c rtems/rtems_showifstat.c \
+ rtems/rtems_showipstat.c rtems/rtems_showicmpstat.c \
+ rtems/rtems_showtcpstat.c rtems/rtems_showudpstat.c rtems/rtems_select.c \
+ rtems/mkrootfs.c rtems/rtems_bsdnet_malloc_starvation.c \
+ rtems/rtems_mii_ioctl.c rtems/rtems_mii_ioctl_kern.c \
+ rtems/rtems_socketpair.c
+
+## sys
+
+include_sysdir = $(includedir)/sys
+
+include_sys_HEADERS = sys/callout.h sys/conf.h sys/domain.h \
+ sys/kernel.h sys/libkern.h sys/linker_set.h sys/malloc.h sys/mbuf.h \
+ sys/mount.h sys/proc.h sys/protosw.h sys/reboot.h \
+ sys/resourcevar.h sys/select.h sys/signalvar.h sys/socket.h \
+ sys/socketvar.h sys/sysctl.h sys/syslog.h sys/systm.h sys/ttydefaults.h \
+ sys/ucred.h sys/un.h
+
+# vm
+
+include_vmdir = $(includedir)/vm
+
+include_vm_HEADERS = vm/vm.h vm/vm_extern.h vm/vm_kern.h vm/vm_param.h
+
+# dev
+include_dev_miidir = $(includedir)/dev/mii
+include_dev_mii_HEADERS = dev/mii/mii.h
+
+## libc
+
+libc_CPPFLAGS = -DNOPOLL -DNOSELECT -D__BSD_VISIBLE -D_THREAD_SAFE
+
+noinst_LIBRARIES += libc.a
+libc_a_CPPFLAGS = $(AM_CPPFLAGS) $(libc_CPPFLAGS)
+
+include_HEADERS += ifaddrs.h
+
+libc_a_SOURCES = libc/base64.c \
+ libc/gethostbydns.c libc/gethostbyht.c libc/gethostbynis.c \
+ libc/gethostnamadr.c libc/getnetbydns.c libc/getnetbyht.c \
+ libc/getnetbynis.c libc/getnetnamadr.c libc/getproto.c \
+ libc/getprotoent.c libc/getprotoname.c libc/getservbyname.c \
+ libc/getservbyport.c libc/getservent.c libc/herror.c libc/inet_addr.c \
+ libc/inet_lnaof.c libc/inet_makeaddr.c libc/inet_netof.c \
+ libc/inet_network.c libc/inet_ntoa.c libc/inet_ntop.c libc/inet_pton.c \
+ libc/linkaddr.c libc/map_v4v6.c libc/nsap_addr.c libc/ns_name.c \
+ libc/ns_netint.c libc/ns_parse.c libc/ns_print.c libc/ns_ttl.c \
+ libc/res_comp.c libc/res_data.c libc/res_debug.c libc/res_init.c \
+ libc/res_mkquery.c libc/res_mkupdate.c libc/res_query.c libc/res_send.c \
+ libc/res_stubs.c libc/res_update.c libc/strsep.c libc/rcmd.c
+libc_a_SOURCES += libc/res_config.h
+libc_a_SOURCES += libc/send.c
+libc_a_SOURCES += libc/recv.c
+libc_a_SOURCES += libc/getifaddrs.c
+libc_a_SOURCES += libc/if_indextoname.c
+libc_a_SOURCES += libc/if_nameindex.c
+endif
+
+UNUSED_FILES += libc/ether_addr.c libc/gethostname.c libc/inet_neta.c \
+ libc/inet_net_ntop.c libc/inet_net_pton.c libc/ns_addr.c \
+ libc/ns_ntoa.c
+
+libc_mans = libc/byteorder.3 libc/ethers.3 \
+ libc/gethostbyname.3 libc/getnetent.3 libc/getprotoent.3 \
+ libc/getservent.3 libc/inet.3 libc/linkaddr.3 libc/ns.3 \
+ libc/rcmd.3 libc/resolver.3
+EXTRA_DIST += $(libc_mans)
+
+if LIBNETWORKING
+man_MANS = $(libc_MANS)
+
+## lib
+
+EXTRA_DIST += lib/README
+
+lib_CPPFLAGS = -DNOPOLL -DNOSELECT
+
+noinst_LIBRARIES += lib.a
+lib_a_CPPFLAGS = $(AM_CPPFLAGS) $(lib_CPPFLAGS) -D__BSD_VISIBLE
+
+lib_a_SOURCES = lib/getprotoby.c lib/rtems_bsdnet_ntp.c lib/ftpfs.c \
+ lib/syslog.c lib/tftpDriver.c
+endif
+
+EXTRA_DIST += $(UNUSED_FILES)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libnetworking/README b/cpukit/libnetworking/README
new file mode 100644
index 0000000000..ed76f94183
--- /dev/null
+++ b/cpukit/libnetworking/README
@@ -0,0 +1,72 @@
+#
+# $Id$
+#
+
+This is a snapshot of my attempt to fit the FreeBSD networking code into
+RTEMS. Things seem to be working!
+
+Things that need to be done:
+ 1) More documentation!
+ 2) Figure out what's still not working :-)
+ 3) Rationalize the include files. Right now I have a special
+ hack in the Makefile to ensure that I pick up the FreeBSD versions
+ of the include files that are duplicated between RTEMS
+ and FreeBSD.
+ The network device driver source should move to the BSP source tree.
+ 4) Have a look at all the FIXME comments.
+ 5) Go through and make sure that all the source files are
+ free of undesired copyright restrictions.
+
+Initial Changes
+===============
+
+19-AUG-1998 snapshot
+ - Pulled BOOTP initialization out of rtems_glue. Applications which
+ don't used BOOTP are now about 5k smaller.
+ - Loopback interface is not installed by default, rather it is
+ attached like any other interface. Saves about 0.5 kbytes.
+ - Add rtems_bsdnet_show_if_stats();
+ - Moved test programs from below freebsd directory.
+
+18-AUG-1998 snapshot
+ - Removed some include files that were already part of RTEMS.
+ - Cleaned up machine/types.h to prepare for inclusion in RTEMS source.
+ - Added syslog library routines -- much simpler than KA9Q version.
+ Sockets can be shared among tasks (as long as the send is
+ protected by a mutex) so there's no need for a Syslog Daemon.
+
+16-AUG-1998 snapshot
+ - Table-driven configuration (networkconfig.h).
+ - Cleaned up rtems_bsdnet.h.
+ - BOOTP now retries properly -- Note to Joel:
+ The dichotomy between RTEMS and UNIX error codes is
+ a real pain!
+
+14-AUG-1998 snapshot
+ - Added dummy getprotobyname() and getprotobynum() functions.
+ - Added socket ioctl.
+ - Added application-level entry to manipulate routing tables.
+ - Added non-BOOTP network initialization.
+
+13-AUG-1998 snapshot
+ - Changed some BOOTP addresses from sockaddr_in to inaddr;
+ - Get DNS information from BOOTP reply.
+ - Got DNS lookups working.
+ Bloatware comes to RTEMS -- invoking gethostbyname() drags in
+ and extra 40 kbytes of code!
+ - Added hostname lookup program.
+
+12-AUG-1998 snapshot
+ - Added startup delay to network initialization.
+ - More statistic-printing routines.
+ - Added TFTP driver and test program
+ - Modified TFTP test program to use networkconfig.h.
+ - Removed unused include files.
+ - Added from ftp://ftp.ca.FreeBSD.ORG/pub/FreeBSD/FreeBSD-current/src/lib/libc/net.
+
+11-AUG-1998 snapshot.
+ - Added getpeername()
+ - Added M68k versions of IP checksum code
+ - Added TCP timing program to snapshot.
+
+02-AUG-1998 snapshot.
diff --git a/cpukit/libnetworking/arpa/ftp.h b/cpukit/libnetworking/arpa/ftp.h
new file mode 100644
index 0000000000..584d290bc9
--- /dev/null
+++ b/cpukit/libnetworking/arpa/ftp.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 1983, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ftp.h 8.1 (Berkeley) 6/2/93
+ *
+ * $Id$
+ */
+
+#ifndef _ARPA_FTP_H_
+#define _ARPA_FTP_H_
+
+/* Definitions for FTP; see RFC-765. */
+
+/*
+ * Reply codes.
+ */
+#define PRELIM 1 /* positive preliminary */
+#define COMPLETE 2 /* positive completion */
+#define CONTINUE 3 /* positive intermediate */
+#define TRANSIENT 4 /* transient negative completion */
+#define ERROR 5 /* permanent negative completion */
+
+/*
+ * Type codes
+ */
+#define TYPE_A 1 /* ASCII */
+#define TYPE_E 2 /* EBCDIC */
+#define TYPE_I 3 /* image */
+#define TYPE_L 4 /* local byte size */
+
+#ifdef FTP_NAMES
+char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" };
+#endif
+
+/*
+ * Form codes
+ */
+#define FORM_N 1 /* non-print */
+#define FORM_T 2 /* telnet format effectors */
+#define FORM_C 3 /* carriage control (ASA) */
+#ifdef FTP_NAMES
+char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" };
+#endif
+
+/*
+ * Structure codes
+ */
+#define STRU_F 1 /* file (no record structure) */
+#define STRU_R 2 /* record structure */
+#define STRU_P 3 /* page structure */
+#ifdef FTP_NAMES
+char *strunames[] = {"0", "File", "Record", "Page" };
+#endif
+
+/*
+ * Mode types
+ */
+#define MODE_S 1 /* stream */
+#define MODE_B 2 /* block */
+#define MODE_C 3 /* compressed */
+#ifdef FTP_NAMES
+char *modenames[] = {"0", "Stream", "Block", "Compressed" };
+#endif
+
+/*
+ * Record Tokens
+ */
+#define REC_ESC '\377' /* Record-mode Escape */
+#define REC_EOR '\001' /* Record-mode End-of-Record */
+#define REC_EOF '\002' /* Record-mode End-of-File */
+
+/*
+ * Block Header
+ */
+#define BLK_EOR 0x80 /* Block is End-of-Record */
+#define BLK_EOF 0x40 /* Block is End-of-File */
+#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */
+#define BLK_RESTART 0x10 /* Block is Restart Marker */
+
+#define BLK_BYTECOUNT 2 /* Bytes in this block */
+
+#endif /* !_FTP_H_ */
diff --git a/cpukit/libnetworking/arpa/inet.h b/cpukit/libnetworking/arpa/inet.h
new file mode 100644
index 0000000000..a1c409dc85
--- /dev/null
+++ b/cpukit/libnetworking/arpa/inet.h
@@ -0,0 +1,146 @@
+/*
+ * ++Copyright++ 1983, 1993
+ * -
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*%
+ * @(#)inet.h 8.1 (Berkeley) 6/2/93
+ * $Id$
+ * $FreeBSD: src/include/arpa/inet.h,v 1.33 2010/07/06 03:48:46 maxim Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _ARPA_INET_H_
+#define _ARPA_INET_H_
+
+/* External definitions for functions in inet(3). */
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <rtems/bsdnet/_types.h>
+
+/* Required for byteorder(3) functions. */
+#include <rtems/endian.h>
+
+#define INET_ADDRSTRLEN 16
+#define INET6_ADDRSTRLEN 46
+
+#ifndef _IN_ADDR_T_DECLARED
+typedef uint32_t in_addr_t;
+#define _IN_ADDR_T_DECLARED
+#endif
+
+#ifndef _IN_PORT_T_DECLARED
+typedef uint16_t in_port_t;
+#define _IN_PORT_T_DECLARED
+#endif
+
+/*
+ * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by
+ * POSIX.1-2001.
+ */
+#ifndef _SOCKLEN_T_DECLARED
+typedef __socklen_t socklen_t;
+#define _SOCKLEN_T_DECLARED
+#endif
+
+#ifndef _STRUCT_IN_ADDR_DECLARED
+struct in_addr {
+ in_addr_t s_addr;
+};
+#define _STRUCT_IN_ADDR_DECLARED
+#endif
+
+#if !defined(__rtems__) /* RTEMS -- Why rename these? */
+/* XXX all new diversions!! argh!! */
+#if __BSD_VISIBLE
+#define inet_addr __inet_addr
+#define inet_aton __inet_aton
+#define inet_lnaof __inet_lnaof
+#define inet_makeaddr __inet_makeaddr
+#define inet_neta __inet_neta
+#define inet_netof __inet_netof
+#define inet_network __inet_network
+#define inet_net_ntop __inet_net_ntop
+#define inet_net_pton __inet_net_pton
+#define inet_cidr_ntop __inet_cidr_ntop
+#define inet_cidr_pton __inet_cidr_pton
+#define inet_ntoa __inet_ntoa
+#define inet_ntoa_r __inet_ntoa_r
+#define inet_pton __inet_pton
+#define inet_ntop __inet_ntop
+#define inet_nsap_addr __inet_nsap_addr
+#define inet_nsap_ntoa __inet_nsap_ntoa
+#endif /* __BSD_VISIBLE */
+#endif /* __rtems__ */
+
+__BEGIN_DECLS
+in_addr_t inet_addr(const char *);
+char *inet_ntoa(struct in_addr);
+const char *inet_ntop(int, const void * __restrict, char * __restrict,
+ socklen_t);
+int inet_pton(int, const char * __restrict, void * __restrict);
+
+#if __BSD_VISIBLE
+int inet_aton(const char *, struct in_addr *);
+in_addr_t inet_lnaof(struct in_addr);
+struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
+char * inet_neta(in_addr_t, char *, size_t);
+in_addr_t inet_netof(struct in_addr);
+in_addr_t inet_network(const char *);
+char *inet_net_ntop(int, const void *, int, char *, size_t);
+int inet_net_pton(int, const char *, void *, size_t);
+unsigned inet_nsap_addr(const char *, unsigned char *, int);
+char *inet_nsap_ntoa(int, const unsigned char *, char *);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+
+#endif /* !_ARPA_INET_H_ */
diff --git a/cpukit/libnetworking/arpa/nameser.h b/cpukit/libnetworking/arpa/nameser.h
new file mode 100644
index 0000000000..0ba6c30a1e
--- /dev/null
+++ b/cpukit/libnetworking/arpa/nameser.h
@@ -0,0 +1,453 @@
+/*
+ * Copyright (c) 1983, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * From: Id: nameser.h,v 8.16 1998/02/06 00:35:58 halley Exp
+ * $FreeBSD: src/include/arpa/nameser.h,v 1.16 2002/03/23 17:24:55 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _ARPA_NAMESER_H_
+#define _ARPA_NAMESER_H_
+
+#define BIND_4_COMPAT
+
+#include <sys/types.h>
+#include <rtems/bsd/sys/cdefs.h>
+
+/*
+ * revision information. this is the release date in YYYYMMDD format.
+ * it can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__NAMESER > 19931104)". do not
+ * compare for equality; rather, use it to determine whether your libnameser.a
+ * is new enough to contain a certain feature.
+ */
+
+/* XXXRTH I made this bigger than __BIND in 4.9.5 T6B */
+#define __NAMESER 19961001 /* New interface version stamp. */
+
+/*
+ * Define constants based on RFC 883, RFC 1034, RFC 1035
+ */
+#define NS_PACKETSZ 512 /* maximum packet size */
+#define NS_MAXDNAME 1025 /* maximum domain name */
+#define NS_MAXCDNAME 255 /* maximum compressed domain name */
+#define NS_MAXLABEL 63 /* maximum length of domain label */
+#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */
+#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */
+#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
+#define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */
+#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */
+#define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */
+#define NS_INADDRSZ 4 /* IPv4 T_A */
+#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */
+#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */
+#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */
+
+/*
+ * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
+ * in synch with it.
+ */
+typedef enum __ns_sect {
+ ns_s_qd = 0, /* Query: Question. */
+ ns_s_zn = 0, /* Update: Zone. */
+ ns_s_an = 1, /* Query: Answer. */
+ ns_s_pr = 1, /* Update: Prerequisites. */
+ ns_s_ns = 2, /* Query: Name servers. */
+ ns_s_ud = 2, /* Update: Update. */
+ ns_s_ar = 3, /* Query|Update: Additional records. */
+ ns_s_max = 4
+} ns_sect;
+
+/*
+ * This is a message handle. It is caller allocated and has no dynamic data.
+ * This structure is intended to be opaque to all but ns_parse.c, thus the
+ * leading _'s on the member names. Use the accessor functions, not the _'s.
+ */
+typedef struct __ns_msg {
+ const u_char *_msg, *_eom;
+ u_int16_t _id, _flags, _counts[ns_s_max];
+ const u_char *_sections[ns_s_max];
+ ns_sect _sect;
+ int _rrnum;
+ const u_char *_ptr;
+} ns_msg;
+
+/* Private data structure - do not use from outside library. */
+struct _ns_flagdata { int mask, shift; };
+extern struct _ns_flagdata _ns_flagdata[];
+
+/* Accessor macros - this is part of the public interface. */
+#define ns_msg_getflag(handle, flag) ( \
+ ((handle)._flags & _ns_flagdata[flag].mask) \
+ >> _ns_flagdata[flag].shift \
+ )
+#define ns_msg_id(handle) ((handle)._id + 0)
+#define ns_msg_base(handle) ((handle)._msg + 0)
+#define ns_msg_end(handle) ((handle)._eom + 0)
+#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
+#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
+
+/*
+ * This is a parsed record. It is caller allocated and has no dynamic data.
+ */
+typedef struct __ns_rr {
+ char name[NS_MAXDNAME]; /* XXX need to malloc */
+ u_int16_t type;
+ u_int16_t rr_class;
+ u_int32_t ttl;
+ u_int16_t rdlength;
+ const u_char *rdata;
+} ns_rr;
+
+/* Accessor macros - this is part of the public interface. */
+#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
+#define ns_rr_type(rr) ((rr).type + 0)
+#define ns_rr_class(rr) ((rr).rr_class + 0)
+#define ns_rr_ttl(rr) ((rr).ttl + 0)
+#define ns_rr_rdlen(rr) ((rr).rdlength + 0)
+#define ns_rr_rdata(rr) ((rr).rdata + 0)
+
+/*
+ * These don't have to be in the same order as in the packet flags word,
+ * and they can even overlap in some cases, but they will need to be kept
+ * in synch with ns_parse.c:ns_flagdata[].
+ */
+typedef enum __ns_flag {
+ ns_f_qr, /* Question/Response. */
+ ns_f_opcode, /* Operation code. */
+ ns_f_aa, /* Authoritative Answer. */
+ ns_f_tc, /* Truncation occurred. */
+ ns_f_rd, /* Recursion Desired. */
+ ns_f_ra, /* Recursion Available. */
+ ns_f_z, /* MBZ. */
+ ns_f_ad, /* Authentic Data (DNSSEC). */
+ ns_f_cd, /* Checking Disabled (DNSSEC). */
+ ns_f_rcode, /* Response code. */
+ ns_f_max
+} ns_flag;
+
+/*
+ * Currently defined opcodes.
+ */
+typedef enum __ns_opcode {
+ ns_o_query = 0, /* Standard query. */
+ ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */
+ ns_o_status = 2, /* Name server status query (unsupported). */
+ /* Opcode 3 is undefined/reserved. */
+ ns_o_notify = 4, /* Zone change notification. */
+ ns_o_update = 5, /* Zone update message. */
+ ns_o_max = 6
+} ns_opcode;
+
+/*
+ * Currently defined response codes.
+ */
+typedef enum __ns_rcode {
+ ns_r_noerror = 0, /* No error occurred. */
+ ns_r_formerr = 1, /* Format error. */
+ ns_r_servfail = 2, /* Server failure. */
+ ns_r_nxdomain = 3, /* Name error. */
+ ns_r_notimpl = 4, /* Unimplemented. */
+ ns_r_refused = 5, /* Operation refused. */
+ /* these are for BIND_UPDATE */
+ ns_r_yxdomain = 6, /* Name exists */
+ ns_r_yxrrset = 7, /* RRset exists */
+ ns_r_nxrrset = 8, /* RRset does not exist */
+ ns_r_notauth = 9, /* Not authoritative for zone */
+ ns_r_notzone = 10, /* Zone of record different from zone section */
+ ns_r_max = 11
+} ns_rcode;
+
+/* BIND_UPDATE */
+typedef enum __ns_update_operation {
+ ns_uop_delete = 0,
+ ns_uop_add = 1,
+ ns_uop_max = 2
+} ns_update_operation;
+
+/*
+ * This RR-like structure is particular to UPDATE.
+ */
+struct ns_updrec {
+ struct ns_updrec *r_prev; /* prev record */
+ struct ns_updrec *r_next; /* next record */
+ u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */
+ char * r_dname; /* owner of the RR */
+ u_int16_t r_class; /* class number */
+ u_int16_t r_type; /* type number */
+ u_int32_t r_ttl; /* time to live */
+ u_char * r_data; /* rdata fields as text string */
+ u_int16_t r_size; /* size of r_data field */
+ int r_opcode; /* type of operation */
+ /* following fields for private use by the resolver/server routines */
+ struct ns_updrec *r_grpnext; /* next record when grouped */
+ struct databuf *r_dp; /* databuf to process */
+ struct databuf *r_deldp; /* databuf's deleted/overwritten */
+ u_int16_t r_zone; /* zone number on server */
+};
+typedef struct ns_updrec ns_updrec;
+
+/*
+ * Currently defined type values for resources and queries.
+ */
+typedef enum __ns_type {
+ ns_t_a = 1, /* Host address. */
+ ns_t_ns = 2, /* Authoritative server. */
+ ns_t_md = 3, /* Mail destination. */
+ ns_t_mf = 4, /* Mail forwarder. */
+ ns_t_cname = 5, /* Canonical name. */
+ ns_t_soa = 6, /* Start of authority zone. */
+ ns_t_mb = 7, /* Mailbox domain name. */
+ ns_t_mg = 8, /* Mail group member. */
+ ns_t_mr = 9, /* Mail rename name. */
+ ns_t_null = 10, /* Null resource record. */
+ ns_t_wks = 11, /* Well known service. */
+ ns_t_ptr = 12, /* Domain name pointer. */
+ ns_t_hinfo = 13, /* Host information. */
+ ns_t_minfo = 14, /* Mailbox information. */
+ ns_t_mx = 15, /* Mail routing information. */
+ ns_t_txt = 16, /* Text strings. */
+ ns_t_rp = 17, /* Responsible person. */
+ ns_t_afsdb = 18, /* AFS cell database. */
+ ns_t_x25 = 19, /* X_25 calling address. */
+ ns_t_isdn = 20, /* ISDN calling address. */
+ ns_t_rt = 21, /* Router. */
+ ns_t_nsap = 22, /* NSAP address. */
+ ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
+ ns_t_sig = 24, /* Security signature. */
+ ns_t_key = 25, /* Security key. */
+ ns_t_px = 26, /* X.400 mail mapping. */
+ ns_t_gpos = 27, /* Geographical position (withdrawn). */
+ ns_t_aaaa = 28, /* Ip6 Address. */
+ ns_t_loc = 29, /* Location Information. */
+ ns_t_nxt = 30, /* Next domain (security). */
+ ns_t_eid = 31, /* Endpoint identifier. */
+ ns_t_nimloc = 32, /* Nimrod Locator. */
+ ns_t_srv = 33, /* Server Selection. */
+ ns_t_atma = 34, /* ATM Address */
+ ns_t_naptr = 35, /* Naming Authority PoinTeR */
+ ns_t_opt = 41, /* OPT pseudo-RR, RFC2761 */
+ /* Query type values which do not appear in resource records. */
+ ns_t_ixfr = 251, /* Incremental zone transfer. */
+ ns_t_axfr = 252, /* Transfer zone of authority. */
+ ns_t_mailb = 253, /* Transfer mailbox records. */
+ ns_t_maila = 254, /* Transfer mail agent records. */
+ ns_t_any = 255, /* Wildcard match. */
+ ns_t_max = 65536
+} ns_type;
+
+/*
+ * Values for class field
+ */
+typedef enum __ns_class {
+ ns_c_in = 1, /* Internet. */
+ /* Class 2 unallocated/unsupported. */
+ ns_c_chaos = 3, /* MIT Chaos-net. */
+ ns_c_hs = 4, /* MIT Hesiod. */
+ /* Query class values which do not appear in resource records */
+ ns_c_none = 254, /* for prereq. sections in update requests */
+ ns_c_any = 255, /* Wildcard match. */
+ ns_c_max = 65536
+} ns_class;
+
+/*
+ * Flags field of the KEY RR rdata
+ */
+#define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */
+#define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
+#define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
+#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
+#define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */
+#define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */
+#define NS_KEY_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
+#define NS_KEY_RESERVED3 0x1000 /* reserved - must be zero */
+#define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */
+#define NS_KEY_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
+#define NS_KEY_ENTITY 0x0200 /* key is assoc. with entity eg host */
+#define NS_KEY_ZONEKEY 0x0100 /* key is zone key */
+#define NS_KEY_IPSEC 0x0080 /* key is for IPSEC (host or user)*/
+#define NS_KEY_EMAIL 0x0040 /* key is for email (MIME security) */
+#define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */
+#define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */
+#define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */
+
+#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED3 | \
+ NS_KEY_RESERVED4 | \
+ NS_KEY_RESERVED10 | \
+ NS_KEY_RESERVED11 )
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define NS_ALG_MD5RSA 1 /* MD5 with RSA */
+#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */
+#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */
+
+/* Signatures */
+#define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */
+#define NS_MD5RSA_MAX_BITS 2552
+ /* Total of binary mod and exp */
+#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)
+ /* Max length of text sig block */
+#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4)
+
+/* Offsets into SIG record rdata to find various values */
+#define NS_SIG_TYPE 0 /* Type flags */
+#define NS_SIG_ALG 2 /* Algorithm */
+#define NS_SIG_LABELS 3 /* How many labels in name */
+#define NS_SIG_OTTL 4 /* Original TTL */
+#define NS_SIG_EXPIR 8 /* Expiration time */
+#define NS_SIG_SIGNED 12 /* Signature time */
+#define NS_SIG_FOOT 16 /* Key footprint */
+#define NS_SIG_SIGNER 18 /* Domain name of who signed it */
+
+/* How RR types are represented as bit-flags in NXT records */
+#define NS_NXT_BITS 8
+#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS)))
+#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
+#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS)))
+
+
+/*
+ * Inline versions of get/put short/long. Pointer is advanced.
+ */
+#define NS_GET16(s, cp) { \
+ register u_char *t_cp = (u_char *)(cp); \
+ (s) = ((u_int16_t)t_cp[0] << 8) \
+ | ((u_int16_t)t_cp[1]) \
+ ; \
+ (cp) += NS_INT16SZ; \
+}
+
+#define NS_GET32(l, cp) { \
+ register u_char *t_cp = (u_char *)(cp); \
+ (l) = ((u_int32_t)t_cp[0] << 24) \
+ | ((u_int32_t)t_cp[1] << 16) \
+ | ((u_int32_t)t_cp[2] << 8) \
+ | ((u_int32_t)t_cp[3]) \
+ ; \
+ (cp) += NS_INT32SZ; \
+}
+
+#define NS_PUT16(s, cp) { \
+ register u_int16_t t_s = (u_int16_t)(s); \
+ register u_char *t_cp = (u_char *)(cp); \
+ *t_cp++ = t_s >> 8; \
+ *t_cp = t_s; \
+ (cp) += NS_INT16SZ; \
+}
+
+#define NS_PUT32(l, cp) { \
+ register u_int32_t t_l = (u_int32_t)(l); \
+ register u_char *t_cp = (u_char *)(cp); \
+ *t_cp++ = t_l >> 24; \
+ *t_cp++ = t_l >> 16; \
+ *t_cp++ = t_l >> 8; \
+ *t_cp = t_l; \
+ (cp) += NS_INT32SZ; \
+}
+
+/*
+ * ANSI C identifier hiding.
+ */
+#define ns_get16 __ns_get16
+#define ns_get32 __ns_get32
+#define ns_put16 __ns_put16
+#define ns_put32 __ns_put32
+#define ns_initparse __ns_initparse
+#define ns_parserr __ns_parserr
+#define ns_sprintrr __ns_sprintrr
+#define ns_sprintrrf __ns_sprintrrf
+#define ns_format_ttl __ns_format_ttl
+#define ns_parse_ttl __ns_parse_ttl
+#define ns_name_ntop __ns_name_ntop
+#define ns_name_pton __ns_name_pton
+#define ns_name_unpack __ns_name_unpack
+#define ns_name_pack __ns_name_pack
+#define ns_name_compress __ns_name_compress
+#define ns_name_uncompress __ns_name_uncompress
+
+__BEGIN_DECLS
+u_int ns_get16(const u_char *);
+u_long ns_get32(const u_char *);
+void ns_put16(u_int, u_char *);
+void ns_put32(u_long, u_char *);
+int ns_initparse(const u_char *, int, ns_msg *);
+int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
+int ns_sprintrr(const ns_msg *, const ns_rr *,
+ const char *, const char *, char *, size_t);
+int ns_sprintrrf(const u_char *, size_t, const char *,
+ ns_class, ns_type, u_long, const u_char *,
+ size_t, const char *, const char *,
+ char *, size_t);
+int ns_format_ttl(u_long, char *, size_t);
+int ns_parse_ttl(const char *, u_long *);
+int ns_name_ntop(const u_char *, char *, size_t);
+int ns_name_pton(const char *, u_char *, size_t);
+int ns_name_unpack(const u_char *, const u_char *,
+ const u_char *, u_char *, size_t);
+int ns_name_pack(const u_char *, u_char *, int,
+ const u_char **, const u_char **);
+int ns_name_uncompress(const u_char *, const u_char *,
+ const u_char *, char *, size_t);
+int ns_name_compress(const char *, u_char *, size_t,
+ const u_char **, const u_char **);
+int ns_name_skip(const u_char **, const u_char *);
+__END_DECLS
+
+#ifdef BIND_4_COMPAT
+#include <arpa/nameser_compat.h>
+#endif
+
+#endif /* !_ARPA_NAMESER_H_ */
diff --git a/cpukit/libnetworking/arpa/nameser_compat.h b/cpukit/libnetworking/arpa/nameser_compat.h
new file mode 100644
index 0000000000..9c1916ec55
--- /dev/null
+++ b/cpukit/libnetworking/arpa/nameser_compat.h
@@ -0,0 +1,194 @@
+/* Copyright (c) 1983, 1989
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * from nameser.h 8.1 (Berkeley) 6/2/93
+ * From: Id: nameser_compat.h,v 8.9 1998/03/20 23:25:10 halley Exp
+ * $Id$
+ */
+
+#ifndef _ARPA_NAMESER_COMPAT_
+#define _ARPA_NAMESER_COMPAT_
+
+#define __BIND 19950621 /* (DEAD) interface version stamp. */
+
+#include <rtems/endian.h>
+
+#if !defined(BYTE_ORDER) || \
+ (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
+ BYTE_ORDER != PDP_ENDIAN)
+ /* you must determine what the correct bit order is for
+ * your compiler - the next line is an intentional error
+ * which will force your compiles to bomb until you fix
+ * the above macros.
+ */
+ error "Undefined or invalid BYTE_ORDER";
+#endif
+
+/*
+ * Structure for query header. The order of the fields is machine- and
+ * compiler-dependent, depending on the byte/bit order and the layout
+ * of bit fields. We use bit fields only in int variables, as this
+ * is all ANSI requires. This requires a somewhat confusing rearrangement.
+ */
+
+typedef struct {
+ unsigned id :16; /* query identification number */
+#if BYTE_ORDER == BIG_ENDIAN
+ /* fields in third byte */
+ unsigned qr: 1; /* response flag */
+ unsigned opcode: 4; /* purpose of message */
+ unsigned aa: 1; /* authoritive answer */
+ unsigned tc: 1; /* truncated message */
+ unsigned rd: 1; /* recursion desired */
+ /* fields in fourth byte */
+ unsigned ra: 1; /* recursion available */
+ unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
+ unsigned ad: 1; /* authentic data from named */
+ unsigned cd: 1; /* checking disabled by resolver */
+ unsigned rcode :4; /* response code */
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
+ /* fields in third byte */
+ unsigned rd :1; /* recursion desired */
+ unsigned tc :1; /* truncated message */
+ unsigned aa :1; /* authoritive answer */
+ unsigned opcode :4; /* purpose of message */
+ unsigned qr :1; /* response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /* response code */
+ unsigned cd: 1; /* checking disabled by resolver */
+ unsigned ad: 1; /* authentic data from named */
+ unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /* recursion available */
+#endif
+ /* remaining bytes */
+ unsigned qdcount :16; /* number of question entries */
+ unsigned ancount :16; /* number of answer entries */
+ unsigned nscount :16; /* number of authority entries */
+ unsigned arcount :16; /* number of resource entries */
+} HEADER;
+
+#define PACKETSZ NS_PACKETSZ
+#define MAXDNAME NS_MAXDNAME
+#define MAXCDNAME NS_MAXCDNAME
+#define MAXLABEL NS_MAXLABEL
+#define HFIXEDSZ NS_HFIXEDSZ
+#define QFIXEDSZ NS_QFIXEDSZ
+#define RRFIXEDSZ NS_RRFIXEDSZ
+#define INT32SZ NS_INT32SZ
+#define INT16SZ NS_INT16SZ
+#define INADDRSZ NS_INADDRSZ
+#define IN6ADDRSZ NS_IN6ADDRSZ
+#define INDIR_MASK NS_CMPRSFLGS
+#define NAMESERVER_PORT NS_DEFAULTPORT
+
+#define S_ZONE ns_s_zn
+#define S_PREREQ ns_s_pr
+#define S_UPDATE ns_s_ud
+#define S_ADDT ns_s_ar
+
+#define QUERY ns_o_query
+#define IQUERY ns_o_iquery
+#define STATUS ns_o_status
+#define NS_NOTIFY_OP ns_o_notify
+#define NS_UPDATE_OP ns_o_update
+
+#define NOERROR ns_r_noerror
+#define FORMERR ns_r_formerr
+#define SERVFAIL ns_r_servfail
+#define NXDOMAIN ns_r_nxdomain
+#define NOTIMP ns_r_notimpl
+#define REFUSED ns_r_refused
+#define YXDOMAIN ns_r_yxdomain
+#define YXRRSET ns_r_yxrrset
+#define NXRRSET ns_r_nxrrset
+#define NOTAUTH ns_r_notauth
+#define NOTZONE ns_r_notzone
+
+#define DELETE ns_uop_delete
+#define ADD ns_uop_add
+
+#define T_A ns_t_a
+#define T_NS ns_t_ns
+#define T_MD ns_t_md
+#define T_MF ns_t_mf
+#define T_CNAME ns_t_cname
+#define T_SOA ns_t_soa
+#define T_MB ns_t_mb
+#define T_MG ns_t_mg
+#define T_MR ns_t_mr
+#define T_NULL ns_t_null
+#define T_WKS ns_t_wks
+#define T_PTR ns_t_ptr
+#define T_HINFO ns_t_hinfo
+#define T_MINFO ns_t_minfo
+#define T_MX ns_t_mx
+#define T_TXT ns_t_txt
+#define T_RP ns_t_rp
+#define T_AFSDB ns_t_afsdb
+#define T_X25 ns_t_x25
+#define T_ISDN ns_t_isdn
+#define T_RT ns_t_rt
+#define T_NSAP ns_t_nsap
+#define T_NSAP_PTR ns_t_nsap_ptr
+#define T_SIG ns_t_sig
+#define T_KEY ns_t_key
+#define T_PX ns_t_px
+#define T_GPOS ns_t_gpos
+#define T_AAAA ns_t_aaaa
+#define T_LOC ns_t_loc
+#define T_NXT ns_t_nxt
+#define T_EID ns_t_eid
+#define T_NIMLOC ns_t_nimloc
+#define T_SRV ns_t_srv
+#define T_ATMA ns_t_atma
+#define T_NAPTR ns_t_naptr
+#define T_IXFR ns_t_ixfr
+#define T_AXFR ns_t_axfr
+#define T_MAILB ns_t_mailb
+#define T_MAILA ns_t_maila
+#define T_ANY ns_t_any
+
+#define C_IN ns_c_in
+#define C_CHAOS ns_c_chaos
+#define C_HS ns_c_hs
+/* BIND_UPDATE */
+#define C_NONE ns_c_none
+#define C_ANY ns_c_any
+
+#define GETSHORT NS_GET16
+#define GETLONG NS_GET32
+#define PUTSHORT NS_PUT16
+#define PUTLONG NS_PUT32
+
+#endif /* _ARPA_NAMESER_COMPAT_ */
diff --git a/cpukit/libnetworking/bpfilter.h b/cpukit/libnetworking/bpfilter.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/bpfilter.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/dev/mii/mii.h b/cpukit/libnetworking/dev/mii/mii.h
new file mode 100644
index 0000000000..14e45b0462
--- /dev/null
+++ b/cpukit/libnetworking/dev/mii/mii.h
@@ -0,0 +1,206 @@
+/* $NetBSD: mii.h,v 1.9 2001/05/31 03:07:14 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
+ *
+ * Modification to match BSD/OS 3.0 MII interface by Jason R. Thorpe,
+ * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Manuel Bouyer.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: /repoman/r/ncvs/src/sys/dev/mii/mii.h,v 1.4 2002/04/29 11:57:28 phk Exp $
+ */
+
+#ifndef _DEV_MII_MII_H_
+#define _DEV_MII_MII_H_
+
+/*
+ * Registers common to all PHYs.
+ */
+
+#define MII_NPHY 32 /* max # of PHYs per MII */
+
+/*
+ * MII commands, used if a device must drive the MII lines
+ * manually.
+ */
+#define MII_COMMAND_START 0x01
+#define MII_COMMAND_READ 0x02
+#define MII_COMMAND_WRITE 0x01
+#define MII_COMMAND_ACK 0x02
+
+#define MII_BMCR 0x00 /* Basic mode control register (rw) */
+#define BMCR_RESET 0x8000 /* reset */
+#define BMCR_LOOP 0x4000 /* loopback */
+#define BMCR_SPEED0 0x2000 /* speed selection (LSB) */
+#define BMCR_AUTOEN 0x1000 /* autonegotiation enable */
+#define BMCR_PDOWN 0x0800 /* power down */
+#define BMCR_ISO 0x0400 /* isolate */
+#define BMCR_STARTNEG 0x0200 /* restart autonegotiation */
+#define BMCR_FDX 0x0100 /* Set duplex mode */
+#define BMCR_CTEST 0x0080 /* collision test */
+#define BMCR_SPEED1 0x0040 /* speed selection (MSB) */
+
+#define BMCR_S10 0x0000 /* 10 Mb/s */
+#define BMCR_S100 BMCR_SPEED0 /* 100 Mb/s */
+#define BMCR_S1000 BMCR_SPEED1 /* 1000 Mb/s */
+
+#define BMCR_SPEED(x) ((x) & (BMCR_SPEED0|BMCR_SPEED1))
+
+#define MII_BMSR 0x01 /* Basic mode status register (ro) */
+#define BMSR_100T4 0x8000 /* 100 base T4 capable */
+#define BMSR_100TXFDX 0x4000 /* 100 base Tx full duplex capable */
+#define BMSR_100TXHDX 0x2000 /* 100 base Tx half duplex capable */
+#define BMSR_10TFDX 0x1000 /* 10 base T full duplex capable */
+#define BMSR_10THDX 0x0800 /* 10 base T half duplex capable */
+#define BMSR_100T2FDX 0x0400 /* 100 base T2 full duplex capable */
+#define BMSR_100T2HDX 0x0200 /* 100 base T2 half duplex capable */
+#define BMSR_EXTSTAT 0x0100 /* Extended status in register 15 */
+#define BMSR_MFPS 0x0040 /* MII Frame Preamble Suppression */
+#define BMSR_ACOMP 0x0020 /* Autonegotiation complete */
+#define BMSR_RFAULT 0x0010 /* Link partner fault */
+#define BMSR_ANEG 0x0008 /* Autonegotiation capable */
+#define BMSR_LINK 0x0004 /* Link status */
+#define BMSR_JABBER 0x0002 /* Jabber detected */
+#define BMSR_EXTCAP 0x0001 /* Extended capability */
+
+/*
+ * Note that the EXTSTAT bit indicates that there is extended status
+ * info available in register 15, but 802.3 section 22.2.4.3 also
+ * states that that all 1000 Mb/s capable PHYs will set this bit to 1.
+ */
+#if 0
+#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX|BMSR_10TFDX| \
+ BMSR_10THDX|BMSR_ANEG)
+
+#else
+/* NetBSD uses: */
+#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \
+ BMSR_10TFDX|BMSR_10THDX|BMSR_100T2FDX|BMSR_100T2HDX)
+#endif
+
+/*
+ * Convert BMSR media capabilities to ANAR bits for autonegotiation.
+ * Note the shift chopps off the BMSR_ANEG bit.
+ */
+#define BMSR_MEDIA_TO_ANAR(x) (((x) & BMSR_MEDIAMASK) >> 6)
+
+#define MII_PHYIDR1 0x02 /* ID register 1 (ro) */
+
+#define MII_PHYIDR2 0x03 /* ID register 2 (ro) */
+#define IDR2_OUILSB 0xfc00 /* OUI LSB */
+#define IDR2_MODEL 0x03f0 /* vendor model */
+#define IDR2_REV 0x000f /* vendor revision */
+
+#define MII_OUI(id1, id2) (((id1) << 6) | ((id2) >> 10))
+#define MII_MODEL(id2) (((id2) & IDR2_MODEL) >> 4)
+#define MII_REV(id2) ((id2) & IDR2_REV)
+
+#define MII_ANAR 0x04 /* Autonegotiation advertisement (rw) */
+ /* section 28.2.4.1 and 37.2.6.1 */
+#define ANAR_NP 0x8000 /* Next page (ro) */
+#define ANAR_ACK 0x4000 /* link partner abilities acknowledged (ro) */
+#define ANAR_RF 0x2000 /* remote fault (ro) */
+#define ANAR_FC 0x0400 /* local device supports PAUSE */
+#define ANAR_T4 0x0200 /* local device supports 100bT4 */
+#define ANAR_TX_FD 0x0100 /* local device supports 100bTx FD */
+#define ANAR_TX 0x0080 /* local device supports 100bTx */
+#define ANAR_10_FD 0x0040 /* local device supports 10bT FD */
+#define ANAR_10 0x0020 /* local device supports 10bT */
+#define ANAR_CSMA 0x0001 /* protocol selector CSMA/CD */
+
+#define ANAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */
+#define ANAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */
+#define ANAR_X_PAUSE_NONE (0 << 7)
+#define ANAR_X_PAUSE_SYM (1 << 7)
+#define ANAR_X_PAUSE_ASYM (2 << 7)
+#define ANAR_X_PAUSE_TOWARDS (3 << 7)
+
+#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */
+ /* section 28.2.4.1 and 37.2.6.1 */
+#define ANLPAR_NP 0x8000 /* Next page (ro) */
+#define ANLPAR_ACK 0x4000 /* link partner accepted ACK (ro) */
+#define ANLPAR_RF 0x2000 /* remote fault (ro) */
+#define ANLPAR_FC 0x0400 /* link partner supports PAUSE */
+#define ANLPAR_T4 0x0200 /* link partner supports 100bT4 */
+#define ANLPAR_TX_FD 0x0100 /* link partner supports 100bTx FD */
+#define ANLPAR_TX 0x0080 /* link partner supports 100bTx */
+#define ANLPAR_10_FD 0x0040 /* link partner supports 10bT FD */
+#define ANLPAR_10 0x0020 /* link partner supports 10bT */
+#define ANLPAR_CSMA 0x0001 /* protocol selector CSMA/CD */
+
+#define ANLPAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */
+#define ANLPAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */
+#define ANLPAR_X_PAUSE_MASK (3 << 7)
+#define ANLPAR_X_PAUSE_NONE (0 << 7)
+#define ANLPAR_X_PAUSE_SYM (1 << 7)
+#define ANLPAR_X_PAUSE_ASYM (2 << 7)
+#define ANLPAR_X_PAUSE_TOWARDS (3 << 7)
+
+#define MII_ANER 0x06 /* Autonegotiation expansion (ro) */
+ /* section 28.2.4.1 and 37.2.6.1 */
+#define ANER_MLF 0x0010 /* multiple link detection fault */
+#define ANER_LPNP 0x0008 /* link parter next page-able */
+#define ANER_NP 0x0004 /* next page-able */
+#define ANER_PAGE_RX 0x0002 /* Page received */
+#define ANER_LPAN 0x0001 /* link parter autoneg-able */
+
+#define MII_ANNP 0x07 /* Autonegotiation next page */
+ /* section 28.2.4.1 and 37.2.6.1 */
+
+#define MII_ANLPRNP 0x08 /* Autonegotiation link partner rx next page */
+ /* section 32.5.1 and 37.2.6.1 */
+
+ /* This is also the 1000baseT control register */
+#define MII_100T2CR 0x09 /* 100base-T2 control register */
+#define GTCR_TEST_MASK 0xe000 /* see 802.3ab ss. 40.6.1.1.2 */
+#define GTCR_MAN_MS 0x1000 /* enable manual master/slave control */
+#define GTCR_ADV_MS 0x0800 /* 1 = adv. master, 0 = adv. slave */
+#define GTCR_PORT_TYPE 0x0400 /* 1 = DCE, 0 = DTE (NIC) */
+#define GTCR_ADV_1000TFDX 0x0200 /* adv. 1000baseT FDX */
+#define GTCR_ADV_1000THDX 0x0100 /* adv. 1000baseT HDX */
+
+ /* This is also the 1000baseT status register */
+#define MII_100T2SR 0x0a /* 100base-T2 status register */
+#define GTSR_MAN_MS_FLT 0x8000 /* master/slave config fault */
+#define GTSR_MS_RES 0x4000 /* result: 1 = master, 0 = slave */
+#define GTSR_LRS 0x2000 /* local rx status, 1 = ok */
+#define GTSR_RRS 0x1000 /* remove rx status, 1 = ok */
+#define GTSR_LP_1000TFDX 0x0800 /* link partner 1000baseT FDX capable */
+#define GTSR_LP_1000THDX 0x0400 /* link partner 1000baseT HDX capable */
+#define GTSR_LP_ASM_DIR 0x0200 /* link partner asym. pause dir. capable */
+#define GTSR_IDLE_ERR 0x00ff /* IDLE error count */
+
+#define MII_EXTSR 0x0f /* Extended status register */
+#define EXTSR_1000XFDX 0x8000 /* 1000X full-duplex capable */
+#define EXTSR_1000XHDX 0x4000 /* 1000X half-duplex capable */
+#define EXTSR_1000TFDX 0x2000 /* 1000T full-duplex capable */
+#define EXTSR_1000THDX 0x1000 /* 1000T half-duplex capable */
+
+#define EXTSR_MEDIAMASK (EXTSR_1000XFDX|EXTSR_1000XHDX| \
+ EXTSR_1000TFDX|EXTSR_1000THDX)
+
+#endif /* _DEV_MII_MII_H_ */
diff --git a/cpukit/libnetworking/ifaddrs.h b/cpukit/libnetworking/ifaddrs.h
new file mode 100644
index 0000000000..874591bb93
--- /dev/null
+++ b/cpukit/libnetworking/ifaddrs.h
@@ -0,0 +1,56 @@
+/* $FreeBSD: src/include/ifaddrs.h,v 1.3 2003/11/14 18:53:22 bms Exp $ */
+
+/*
+ * Copyright (c) 1995, 1999
+ * Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
+ */
+
+#ifndef _IFADDRS_H_
+#define _IFADDRS_H_
+
+struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
+ u_int ifa_flags;
+ struct sockaddr *ifa_addr;
+ struct sockaddr *ifa_netmask;
+ struct sockaddr *ifa_dstaddr;
+ void *ifa_data;
+};
+
+/*
+ * This may have been defined in <net/if.h>. Note that if <net/if.h> is
+ * to be included it must be included before this header file.
+ */
+#ifndef ifa_broadaddr
+#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
+#endif
+
+#include <rtems/bsd/sys/cdefs.h>
+
+__BEGIN_DECLS
+extern int getifaddrs(struct ifaddrs **);
+extern void freeifaddrs(struct ifaddrs *);
+__END_DECLS
+
+#endif
diff --git a/cpukit/libnetworking/kern/kern_mib.c b/cpukit/libnetworking/kern/kern_mib.c
new file mode 100644
index 0000000000..6471208786
--- /dev/null
+++ b/cpukit/libnetworking/kern/kern_mib.c
@@ -0,0 +1,385 @@
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Karels at Berkeley Software Design, Inc.
+ *
+ * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
+ * project, to make these variables more userfriendly.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
+ * $FreeBSD: src/sys/kern/kern_mib.c,v 1.74 2005/02/28 21:42:56 wes Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef __rtems__
+#include "opt_posix.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#ifndef __rtems__
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/jail.h>
+#include <sys/smp.h>
+#endif
+#include <sys/unistd.h>
+
+#ifdef __rtems__
+char machine[] = "SET ME";
+char osrelease[] = RTEMS_VERSION;
+char ostype[] = "RTEMS";
+#endif
+
+SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
+ "Sysctl internal magic");
+SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0,
+ "High kernel, proc, limits &c");
+#ifndef __rtems__
+SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0,
+ "Virtual memory");
+SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW, 0,
+ "File system");
+#endif
+SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW, 0,
+ "Network, (see socket.h)");
+#ifndef __rtems__
+SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW, 0,
+ "Debugging");
+SYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW, 0,
+ "Sizeof various things");
+SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW, 0,
+ "hardware");
+SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
+ "machine dependent");
+SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW, 0,
+ "user-level");
+SYSCTL_NODE(, CTL_P1003_1B, p1003_1b, CTLFLAG_RW, 0,
+ "p1003_1b, (see p1003_1b.h)");
+
+SYSCTL_NODE(, OID_AUTO, compat, CTLFLAG_RW, 0,
+ "Compatibility code");
+SYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0,
+ "Security");
+#ifdef REGRESSION
+SYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0,
+ "Regression test MIB");
+#endif
+
+SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD,
+ kern_ident, 0, "Kernel identifier");
+#endif /* __rtems__ */
+
+SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD,
+ osrelease, 0, "Operating system release");
+
+SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD,
+ 0, BSD, "Operating system revision");
+
+#ifndef __rtems__
+SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
+ version, 0, "Kernel version");
+#endif
+
+SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD,
+ ostype, 0, "Operating system type");
+
+#ifndef __rtems__
+extern int osreldate;
+SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD,
+ &osreldate, 0, "Operating system release date");
+
+SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD,
+ &maxproc, 0, "Maximum number of processes");
+
+SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
+ &maxprocperuid, 0, "Maximum processes allowed per userid");
+
+SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RD,
+ &maxusers, 0, "Hint for kernel tuning");
+
+SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD,
+ 0, ARG_MAX, "Maximum bytes of argument to execve(2)");
+
+SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD,
+ 0, _POSIX_VERSION, "Version of POSIX attempting to comply to");
+
+SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD,
+ 0, NGROUPS_MAX, "Maximum number of groups a user can belong to");
+
+SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD,
+ 0, 1, "Whether job control is available");
+
+#ifdef _POSIX_SAVED_IDS
+SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
+ 0, 1, "Whether saved set-group/user ID is available");
+#else
+SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
+ 0, 0, "Whether saved set-group/user ID is available");
+#endif
+
+char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */
+
+SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
+ kernelname, sizeof kernelname, "Name of kernel file booted");
+
+#ifdef SMP
+SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
+ &mp_ncpus, 0, "Number of active CPUs");
+#else
+SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
+ 0, 1, "Number of active CPUs");
+#endif
+
+SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD,
+ 0, BYTE_ORDER, "System byte order");
+
+SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD,
+ 0, PAGE_SIZE, "System memory page size");
+
+static int
+sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
+{
+ u_long val;
+
+ val = ctob(physmem);
+ return (sysctl_handle_long(oidp, &val, 0, req));
+}
+
+SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
+ 0, 0, sysctl_hw_physmem, "LU", "");
+
+static int
+sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
+{
+ u_long val;
+
+ val = ctob(physmem - cnt.v_wire_count);
+ return (sysctl_handle_long(oidp, &val, 0, req));
+}
+
+SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
+ 0, 0, sysctl_hw_usermem, "LU", "");
+
+SYSCTL_ULONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
+
+static char machine_arch[] = MACHINE_ARCH;
+SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
+ machine_arch, 0, "System architecture");
+
+char hostname[MAXHOSTNAMELEN];
+
+static int
+sysctl_hostname(SYSCTL_HANDLER_ARGS)
+{
+ struct prison *pr;
+ char tmphostname[MAXHOSTNAMELEN];
+ int error;
+
+ pr = req->td->td_ucred->cr_prison;
+ if (pr != NULL) {
+ if (!jail_set_hostname_allowed && req->newptr)
+ return (EPERM);
+ /*
+ * Process is in jail, so make a local copy of jail
+ * hostname to get/set so we don't have to hold the jail
+ * mutex during the sysctl copyin/copyout activities.
+ */
+ mtx_lock(&pr->pr_mtx);
+ bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
+ mtx_unlock(&pr->pr_mtx);
+
+ error = sysctl_handle_string(oidp, tmphostname,
+ sizeof pr->pr_host, req);
+
+ if (req->newptr != NULL && error == 0) {
+ /*
+ * Copy the locally set hostname to the jail, if
+ * appropriate.
+ */
+ mtx_lock(&pr->pr_mtx);
+ bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
+ mtx_unlock(&pr->pr_mtx);
+ }
+ } else
+ error = sysctl_handle_string(oidp,
+ hostname, sizeof hostname, req);
+ return (error);
+}
+
+SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
+ CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON,
+ 0, 0, sysctl_hostname, "A", "Hostname");
+
+static int regression_securelevel_nonmonotonic = 0;
+
+#ifdef REGRESSION
+SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
+ &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
+#endif
+
+int securelevel = -1;
+struct mtx securelevel_mtx;
+
+MTX_SYSINIT(securelevel_lock, &securelevel_mtx, "securelevel mutex lock",
+ MTX_DEF);
+
+static int
+sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
+{
+ struct prison *pr;
+ int error, level;
+
+ pr = req->td->td_ucred->cr_prison;
+
+ /*
+ * If the process is in jail, return the maximum of the global and
+ * local levels; otherwise, return the global level.
+ */
+ if (pr != NULL) {
+ mtx_lock(&pr->pr_mtx);
+ level = imax(securelevel, pr->pr_securelevel);
+ mtx_unlock(&pr->pr_mtx);
+ } else
+ level = securelevel;
+ error = sysctl_handle_int(oidp, &level, 0, req);
+ if (error || !req->newptr)
+ return (error);
+ /*
+ * Permit update only if the new securelevel exceeds the
+ * global level, and local level if any.
+ */
+ if (pr != NULL) {
+ mtx_lock(&pr->pr_mtx);
+ if (!regression_securelevel_nonmonotonic &&
+ (level < imax(securelevel, pr->pr_securelevel))) {
+ mtx_unlock(&pr->pr_mtx);
+ return (EPERM);
+ }
+ pr->pr_securelevel = level;
+ mtx_unlock(&pr->pr_mtx);
+ } else {
+ mtx_lock(&securelevel_mtx);
+ if (!regression_securelevel_nonmonotonic &&
+ (level < securelevel)) {
+ mtx_unlock(&securelevel_mtx);
+ return (EPERM);
+ }
+ securelevel = level;
+ mtx_unlock(&securelevel_mtx);
+ }
+ return (error);
+}
+
+SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
+ CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
+ "I", "Current secure level");
+
+char domainname[MAXHOSTNAMELEN];
+SYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
+ &domainname, sizeof(domainname), "Name of the current YP/NIS domain");
+
+u_long hostid;
+SYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
+
+/*
+ * This is really cheating. These actually live in the libc, something
+ * which I'm not quite sure is a good idea anyway, but in order for
+ * getnext and friends to actually work, we define dummies here.
+ */
+SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
+ "", 0, "PATH that finds all the standard utilities");
+SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
+ 0, 0, "Max ibase/obase values in bc(1)");
+SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
+ 0, 0, "Max array size in bc(1)");
+SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
+ 0, 0, "Max scale value in bc(1)");
+SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
+ 0, 0, "Max string length in bc(1)");
+SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
+ 0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
+SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
+SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
+ 0, 0, "Max length (bytes) of a text-processing utility's input line");
+SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
+ 0, 0, "Maximum number of repeats of a regexp permitted");
+SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
+ 0, 0,
+ "The version of POSIX 1003.2 with which the system attempts to comply");
+SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
+ 0, 0, "Whether C development supports the C bindings option");
+SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
+ 0, 0, "Whether system supports the C development utilities option");
+SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
+ 0, 0, "");
+SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
+ 0, 0, "Whether system supports FORTRAN development utilities");
+SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
+ 0, 0, "Whether system supports FORTRAN runtime utilities");
+SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
+ 0, 0, "Whether system supports creation of locales");
+SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
+ 0, 0, "Whether system supports software development utilities");
+SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
+ 0, 0, "Whether system supports the user portability utilities");
+SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
+ 0, 0, "Min Maximum number of streams a process may have open at one time");
+SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
+ 0, 0, "Min Maximum number of types supported for timezone names");
+
+#include <sys/vnode.h>
+SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
+ 0, sizeof(struct vnode), "sizeof(struct vnode)");
+
+SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
+ 0, sizeof(struct proc), "sizeof(struct proc)");
+
+#include <sys/conf.h>
+SYSCTL_INT(_debug_sizeof, OID_AUTO, cdev, CTLFLAG_RD,
+ 0, sizeof(struct cdev), "sizeof(struct cdev)");
+
+#include <sys/bio.h>
+#include <sys/buf.h>
+SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
+ 0, sizeof(struct bio), "sizeof(struct bio)");
+SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
+ 0, sizeof(struct buf), "sizeof(struct buf)");
+
+#include <sys/user.h>
+SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
+ 0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
+
+#endif /* __rtems__ */
diff --git a/cpukit/libnetworking/kern/kern_subr.c b/cpukit/libnetworking/kern/kern_subr.c
new file mode 100644
index 0000000000..3823f607a1
--- /dev/null
+++ b/cpukit/libnetworking/kern/kern_subr.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 1982, 1986, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)kern_subr.c 8.3 (Berkeley) 1/21/94
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
+
+int
+uiomove(void *cp, int n, struct uio *uio)
+{
+ register struct iovec *iov;
+ u_int cnt;
+ int error;
+
+#ifdef DIAGNOSTIC
+ if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
+ panic("uiomove: mode");
+#endif
+ while (n > 0 && uio->uio_resid) {
+ iov = uio->uio_iov;
+ cnt = iov->iov_len;
+ if (cnt == 0) {
+ uio->uio_iov++;
+ uio->uio_iovcnt--;
+ continue;
+ }
+ if (cnt > n)
+ cnt = n;
+
+ switch (uio->uio_segflg) {
+
+ case UIO_USERSPACE:
+ if (uio->uio_rw == UIO_READ)
+ error = copyout(cp, iov->iov_base, cnt);
+ else
+ error = copyin(iov->iov_base, cp, cnt);
+ if (error)
+ return (error);
+ break;
+
+ case UIO_SYSSPACE:
+ if (uio->uio_rw == UIO_READ)
+ bcopy((caddr_t)cp, iov->iov_base, cnt);
+ else
+ bcopy(iov->iov_base, (caddr_t)cp, cnt);
+ break;
+ case UIO_NOCOPY:
+ break;
+ }
+ iov->iov_base += cnt;
+ iov->iov_len -= cnt;
+ uio->uio_resid -= cnt;
+ uio->uio_offset += cnt;
+ cp += cnt;
+ n -= cnt;
+ }
+ return (0);
+}
+
+/*
+ * General routine to allocate a hash table.
+ */
+void *
+hashinit(elements, type, hashmask)
+ int elements, type;
+ u_long *hashmask;
+{
+ long hashsize;
+ LIST_HEAD(generic, generic) *hashtbl;
+ int i;
+
+ if (elements <= 0)
+ panic("hashinit: bad elements");
+ for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
+ continue;
+ hashsize >>= 1;
+ hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, M_WAITOK);
+ for (i = 0; i < hashsize; i++)
+ LIST_INIT(&hashtbl[i]);
+ *hashmask = hashsize - 1;
+ return (hashtbl);
+}
+
+#define NPRIMES 27
+static int primes[] = { 1, 13, 31, 61, 127, 251, 509, 761, 1021, 1531, 2039,
+ 2557, 3067, 3583, 4093, 4603, 5119, 5623, 6143, 6653,
+ 7159, 7673, 8191, 12281, 16381, 24571, 32749 };
+
+/*
+ * General routine to allocate a prime number sized hash table.
+ */
+void *
+phashinit(elements, type, nentries)
+ int elements, type;
+ u_long *nentries;
+{
+ long hashsize;
+ LIST_HEAD(generic, generic) *hashtbl;
+ int i;
+
+ if (elements <= 0)
+ panic("phashinit: bad elements");
+ for (i = 1, hashsize = primes[1]; hashsize <= elements;) {
+ i++;
+ if (i == NPRIMES)
+ break;
+ hashsize = primes[i];
+ }
+ hashsize = primes[i - 1];
+ hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, M_WAITOK);
+ for (i = 0; i < hashsize; i++)
+ LIST_INIT(&hashtbl[i]);
+ *nentries = hashsize;
+ return (hashtbl);
+}
diff --git a/cpukit/libnetworking/kern/kern_sysctl.c b/cpukit/libnetworking/kern/kern_sysctl.c
new file mode 100644
index 0000000000..993c20f5d2
--- /dev/null
+++ b/cpukit/libnetworking/kern/kern_sysctl.c
@@ -0,0 +1,1541 @@
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Karels at Berkeley Software Design, Inc.
+ *
+ * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
+ * project, to make these variables more userfriendly.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
+ * $FreeBSD: src/sys/kern/kern_sysctl.c,v 1.135 2002/10/27 07:12:34 rwatson Exp $
+ */
+
+#include "opt_compat.h"
+#include "opt_mac.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#ifndef __rtems__
+#include <sys/mac.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/sx.h>
+#include <sys/sysproto.h>
+#else
+#include <sys/queue.h>
+
+#include <stdio.h> /* for snprintf() */
+size_t strlcpy(char *, const char *, size_t);
+#endif
+#include <vm/vm.h>
+#include <vm/vm_extern.h>
+
+#ifndef __rtems__
+static MALLOC_DEFINE(M_SYSCTL, "sysctl", "sysctl internal magic");
+static MALLOC_DEFINE(M_SYSCTLOID, "sysctloid", "sysctl dynamic oids");
+static MALLOC_DEFINE(M_SYSCTLTMP, "sysctltmp", "sysctl temp output buffer");
+#else
+/*
+ * Currently these mean nothing on RTEMS.
+ */
+#define M_SYSCTLOID 1
+#define M_SYSCTLTMP 2
+#define M_ZERO 0
+
+#define mtx_lock(l)
+#define mtx_unlock(l)
+
+#endif
+
+#ifndef __rtems__
+/*
+ * Locking - this locks the sysctl tree in memory.
+ */
+static struct sx sysctllock;
+#endif
+
+#ifdef __rtems__
+#define SYSCTL_LOCK()
+#define SYSCTL_UNLOCK()
+#define SYSCTL_INIT()
+#else
+#define SYSCTL_LOCK() sx_xlock(&sysctllock)
+#define SYSCTL_UNLOCK() sx_xunlock(&sysctllock)
+#define SYSCTL_INIT() sx_init(&sysctllock, "sysctl lock")
+#endif
+
+static int sysctl_root(SYSCTL_HANDLER_ARGS);
+
+struct sysctl_oid_list sysctl__children; /* root list */
+
+static struct sysctl_oid *
+sysctl_find_oidname(const char *name, struct sysctl_oid_list *list)
+{
+ struct sysctl_oid *oidp;
+
+ SLIST_FOREACH(oidp, list, oid_link) {
+ if (strcmp(oidp->oid_name, name) == 0) {
+ return (oidp);
+ }
+ }
+ return (NULL);
+}
+
+/*
+ * Initialization of the MIB tree.
+ *
+ * Order by number in each list.
+ */
+
+void
+sysctl_register_oid(struct sysctl_oid *oidp)
+{
+ struct sysctl_oid_list *parent = oidp->oid_parent;
+ struct sysctl_oid *p;
+ struct sysctl_oid *q;
+
+ /*
+ * First check if another oid with the same name already
+ * exists in the parent's list.
+ */
+ p = sysctl_find_oidname(oidp->oid_name, parent);
+ if (p != NULL) {
+ if ((p->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
+ p->oid_refcnt++;
+ return;
+ } else {
+ printf("can't re-use a leaf (%s)!\n", p->oid_name);
+ return;
+ }
+ }
+ /*
+ * If this oid has a number OID_AUTO, give it a number which
+ * is greater than any current oid.
+ * NOTE: DO NOT change the starting value here, change it in
+ * <sys/sysctl.h>, and make sure it is at least 256 to
+ * accomodate e.g. net.inet.raw as a static sysctl node.
+ */
+ if (oidp->oid_number == OID_AUTO) {
+ static int32_t newoid = CTL_AUTO_START;
+
+ oidp->oid_number = newoid++;
+ if (newoid == 0x7fffffff)
+ panic("out of oids");
+ }
+#if 0
+ else if (oidp->oid_number >= CTL_AUTO_START) {
+ /* do not panic; this happens when unregistering sysctl sets */
+ printf("static sysctl oid too high: %d", oidp->oid_number);
+ }
+#endif
+
+ /*
+ * Insert the oid into the parent's list in order.
+ */
+ q = NULL;
+ SLIST_FOREACH(p, parent, oid_link) {
+ if (oidp->oid_number < p->oid_number)
+ break;
+ q = p;
+ }
+ if (q)
+ SLIST_INSERT_AFTER(q, oidp, oid_link);
+ else
+ SLIST_INSERT_HEAD(parent, oidp, oid_link);
+}
+
+void
+sysctl_unregister_oid(struct sysctl_oid *oidp)
+{
+ SLIST_REMOVE(oidp->oid_parent, oidp, sysctl_oid, oid_link);
+}
+
+/* Initialize a new context to keep track of dynamically added sysctls. */
+int
+sysctl_ctx_init(struct sysctl_ctx_list *c)
+{
+
+ if (c == NULL) {
+ return (EINVAL);
+ }
+ TAILQ_INIT(c);
+ return (0);
+}
+
+/* Free the context, and destroy all dynamic oids registered in this context */
+int
+sysctl_ctx_free(struct sysctl_ctx_list *clist)
+{
+ struct sysctl_ctx_entry *e, *e1;
+ int error;
+
+ error = 0;
+ /*
+ * First perform a "dry run" to check if it's ok to remove oids.
+ * XXX FIXME
+ * XXX This algorithm is a hack. But I don't know any
+ * XXX better solution for now...
+ */
+ TAILQ_FOREACH(e, clist, link) {
+ error = sysctl_remove_oid(e->entry, 0, 0);
+ if (error)
+ break;
+ }
+ /*
+ * Restore deregistered entries, either from the end,
+ * or from the place where error occured.
+ * e contains the entry that was not unregistered
+ */
+ if (error)
+ e1 = TAILQ_PREV(e, sysctl_ctx_list, link);
+ else
+ e1 = TAILQ_LAST(clist, sysctl_ctx_list);
+ while (e1 != NULL) {
+ sysctl_register_oid(e1->entry);
+ e1 = TAILQ_PREV(e1, sysctl_ctx_list, link);
+ }
+ if (error)
+ return(EBUSY);
+ /* Now really delete the entries */
+ e = TAILQ_FIRST(clist);
+ while (e != NULL) {
+ e1 = TAILQ_NEXT(e, link);
+ error = sysctl_remove_oid(e->entry, 1, 0);
+ if (error)
+ panic("sysctl_remove_oid: corrupt tree, entry: %s",
+ e->entry->oid_name);
+ free(e, M_SYSCTLOID);
+ e = e1;
+ }
+ return (error);
+}
+
+/* Add an entry to the context */
+struct sysctl_ctx_entry *
+sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
+{
+ struct sysctl_ctx_entry *e;
+
+ if (clist == NULL || oidp == NULL)
+ return(NULL);
+ e = malloc(sizeof(struct sysctl_ctx_entry), M_SYSCTLOID, M_WAITOK);
+ e->entry = oidp;
+ TAILQ_INSERT_HEAD(clist, e, link);
+ return (e);
+}
+
+/* Find an entry in the context */
+struct sysctl_ctx_entry *
+sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
+{
+ struct sysctl_ctx_entry *e;
+
+ if (clist == NULL || oidp == NULL)
+ return(NULL);
+ TAILQ_FOREACH(e, clist, link) {
+ if(e->entry == oidp)
+ return(e);
+ }
+ return (e);
+}
+
+/*
+ * Delete an entry from the context.
+ * NOTE: this function doesn't free oidp! You have to remove it
+ * with sysctl_remove_oid().
+ */
+int
+sysctl_ctx_entry_del(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
+{
+ struct sysctl_ctx_entry *e;
+
+ if (clist == NULL || oidp == NULL)
+ return (EINVAL);
+ e = sysctl_ctx_entry_find(clist, oidp);
+ if (e != NULL) {
+ TAILQ_REMOVE(clist, e, link);
+ free(e, M_SYSCTLOID);
+ return (0);
+ } else
+ return (ENOENT);
+}
+
+/*
+ * Remove dynamically created sysctl trees.
+ * oidp - top of the tree to be removed
+ * del - if 0 - just deregister, otherwise free up entries as well
+ * recurse - if != 0 traverse the subtree to be deleted
+ */
+int
+sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse)
+{
+ struct sysctl_oid *p;
+ int error;
+
+ if (oidp == NULL)
+ return(EINVAL);
+ if ((oidp->oid_kind & CTLFLAG_DYN) == 0) {
+ printf("can't remove non-dynamic nodes!\n");
+ return (EINVAL);
+ }
+ /*
+ * WARNING: normal method to do this should be through
+ * sysctl_ctx_free(). Use recursing as the last resort
+ * method to purge your sysctl tree of leftovers...
+ * However, if some other code still references these nodes,
+ * it will panic.
+ */
+ if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
+ if (oidp->oid_refcnt == 1) {
+ SLIST_FOREACH(p, SYSCTL_CHILDREN(oidp), oid_link) {
+ if (!recurse)
+ return (ENOTEMPTY);
+ error = sysctl_remove_oid(p, del, recurse);
+ if (error)
+ return (error);
+ }
+ if (del)
+ free(SYSCTL_CHILDREN(oidp), M_SYSCTLOID);
+ }
+ }
+ if (oidp->oid_refcnt > 1 ) {
+ oidp->oid_refcnt--;
+ } else {
+ if (oidp->oid_refcnt == 0) {
+ printf("Warning: bad oid_refcnt=%u (%s)!\n",
+ oidp->oid_refcnt, oidp->oid_name);
+ return (EINVAL);
+ }
+ sysctl_unregister_oid(oidp);
+ if (del) {
+ if (oidp->descr)
+ free((void *)(uintptr_t)(const void *)oidp->descr, M_SYSCTLOID);
+ free((void *)(uintptr_t)(const void *)oidp->oid_name,
+ M_SYSCTLOID);
+ free(oidp, M_SYSCTLOID);
+ }
+ }
+ return (0);
+}
+
+/*
+ * Create new sysctls at run time.
+ * clist may point to a valid context initialized with sysctl_ctx_init().
+ */
+struct sysctl_oid *
+sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent,
+ int number, const char *name, int kind, void *arg1, int arg2,
+ int (*handler)(SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr)
+{
+ struct sysctl_oid *oidp;
+ ssize_t len;
+ char *newname;
+
+ /* You have to hook up somewhere.. */
+ if (parent == NULL)
+ return(NULL);
+ /* Check if the node already exists, otherwise create it */
+ oidp = sysctl_find_oidname(name, parent);
+ if (oidp != NULL) {
+ if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
+ oidp->oid_refcnt++;
+ /* Update the context */
+ if (clist != NULL)
+ sysctl_ctx_entry_add(clist, oidp);
+ return (oidp);
+ } else {
+ printf("can't re-use a leaf (%s)!\n", name);
+ return (NULL);
+ }
+ }
+ oidp = malloc(sizeof(struct sysctl_oid), M_SYSCTLOID, M_WAITOK|M_ZERO);
+ oidp->oid_parent = parent;
+ SLIST_NEXT(oidp, oid_link) = NULL;
+ oidp->oid_number = number;
+ oidp->oid_refcnt = 1;
+ len = strlen(name);
+ newname = malloc(len + 1, M_SYSCTLOID, M_WAITOK);
+ bcopy(name, newname, len + 1);
+ newname[len] = '\0';
+ oidp->oid_name = newname;
+ oidp->oid_handler = handler;
+ oidp->oid_kind = CTLFLAG_DYN | kind;
+ if ((kind & CTLTYPE) == CTLTYPE_NODE) {
+ /* Allocate space for children */
+ SYSCTL_CHILDREN_SET(oidp, malloc(sizeof(struct sysctl_oid_list),
+ M_SYSCTLOID, M_WAITOK));
+ SLIST_INIT(SYSCTL_CHILDREN(oidp));
+ } else {
+ oidp->oid_arg1 = arg1;
+ oidp->oid_arg2 = arg2;
+ }
+ oidp->oid_fmt = fmt;
+ if (descr) {
+ int len = strlen(descr) + 1;
+ oidp->descr = malloc(len, M_SYSCTLOID, M_WAITOK);
+ if (oidp->descr)
+ strcpy((char *)(uintptr_t)(const void *)oidp->descr, descr);
+ }
+ /* Update the context, if used */
+ if (clist != NULL)
+ sysctl_ctx_entry_add(clist, oidp);
+ /* Register this oid */
+ sysctl_register_oid(oidp);
+ return (oidp);
+}
+
+/*
+ * Register the kernel's oids on startup.
+ */
+SET_DECLARE(sysctl_set, struct sysctl_oid);
+
+#if defined(__rtems__)
+void
+#else
+static void
+#endif
+sysctl_register_all(void *arg)
+{
+ struct sysctl_oid **oidp;
+
+ SYSCTL_INIT();
+ SET_FOREACH(oidp, sysctl_set)
+ sysctl_register_oid(*oidp);
+}
+SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_all, 0);
+
+/*
+ * "Staff-functions"
+ *
+ * These functions implement a presently undocumented interface
+ * used by the sysctl program to walk the tree, and get the type
+ * so it can print the value.
+ * This interface is under work and consideration, and should probably
+ * be killed with a big axe by the first person who can find the time.
+ * (be aware though, that the proper interface isn't as obvious as it
+ * may seem, there are various conflicting requirements.
+ *
+ * {0,0} printf the entire MIB-tree.
+ * {0,1,...} return the name of the "..." OID.
+ * {0,2,...} return the next OID.
+ * {0,3} return the OID of the name in "new"
+ * {0,4,...} return the kind & format info for the "..." OID.
+ * {0,5,...} return the description the "..." OID.
+ */
+
+static void
+sysctl_sysctl_debug_dump_node(struct sysctl_oid_list *l, int i)
+{
+ int k;
+ struct sysctl_oid *oidp;
+
+ SLIST_FOREACH(oidp, l, oid_link) {
+
+ for (k=0; k<i; k++)
+ printf(" ");
+
+ printf("%d %s ", oidp->oid_number, oidp->oid_name);
+
+ printf("%c%c",
+ oidp->oid_kind & CTLFLAG_RD ? 'R':' ',
+ oidp->oid_kind & CTLFLAG_WR ? 'W':' ');
+
+ if (oidp->oid_handler)
+ printf(" *Handler");
+
+ switch (oidp->oid_kind & CTLTYPE) {
+ case CTLTYPE_NODE:
+ printf(" Node\n");
+ if (!oidp->oid_handler) {
+ sysctl_sysctl_debug_dump_node(
+ oidp->oid_arg1, i+2);
+ }
+ break;
+ case CTLTYPE_INT: printf(" Int\n"); break;
+ case CTLTYPE_STRING: printf(" String\n"); break;
+ case CTLTYPE_QUAD: printf(" Quad\n"); break;
+ case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
+ default: printf("\n");
+ }
+
+ }
+}
+
+static int
+sysctl_sysctl_debug(SYSCTL_HANDLER_ARGS)
+{
+#ifndef __rtems__
+ int error;
+
+ error = suser(req->td);
+ if (error)
+ return error;
+#endif
+ sysctl_sysctl_debug_dump_node(&sysctl__children, 0);
+ return ENOENT;
+}
+
+SYSCTL_PROC(_sysctl, 0, debug, CTLTYPE_STRING|CTLFLAG_RD,
+ 0, 0, sysctl_sysctl_debug, "-", "");
+
+static int
+sysctl_sysctl_name(SYSCTL_HANDLER_ARGS)
+{
+ int *name = (int *) arg1;
+ u_int namelen = arg2;
+ int error = 0;
+ struct sysctl_oid *oid;
+ struct sysctl_oid_list *lsp = &sysctl__children, *lsp2;
+ char buf[10];
+
+ while (namelen) {
+ if (!lsp) {
+ snprintf(buf,sizeof(buf),"%d",*name);
+ if (req->oldidx)
+ error = SYSCTL_OUT(req, ".", 1);
+ if (!error)
+ error = SYSCTL_OUT(req, buf, strlen(buf));
+ if (error)
+ return (error);
+ namelen--;
+ name++;
+ continue;
+ }
+ lsp2 = 0;
+ SLIST_FOREACH(oid, lsp, oid_link) {
+ if (oid->oid_number != *name)
+ continue;
+
+ if (req->oldidx)
+ error = SYSCTL_OUT(req, ".", 1);
+ if (!error)
+ error = SYSCTL_OUT(req, oid->oid_name,
+ strlen(oid->oid_name));
+ if (error)
+ return (error);
+
+ namelen--;
+ name++;
+
+ if ((oid->oid_kind & CTLTYPE) != CTLTYPE_NODE)
+ break;
+
+ if (oid->oid_handler)
+ break;
+
+ lsp2 = (struct sysctl_oid_list *)oid->oid_arg1;
+ break;
+ }
+ lsp = lsp2;
+ }
+ return (SYSCTL_OUT(req, "", 1));
+}
+
+SYSCTL_NODE(_sysctl, 1, name, CTLFLAG_RD, sysctl_sysctl_name, "");
+
+static int
+sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen,
+ int *next, int *len, int level, struct sysctl_oid **oidpp)
+{
+ struct sysctl_oid *oidp;
+
+ *len = level;
+ SLIST_FOREACH(oidp, lsp, oid_link) {
+ *next = oidp->oid_number;
+ *oidpp = oidp;
+
+ if (oidp->oid_kind & CTLFLAG_SKIP)
+ continue;
+
+ if (!namelen) {
+ if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
+ return 0;
+ if (oidp->oid_handler)
+ /* We really should call the handler here...*/
+ return 0;
+ lsp = (struct sysctl_oid_list *)oidp->oid_arg1;
+ if (!sysctl_sysctl_next_ls(lsp, 0, 0, next+1,
+ len, level+1, oidpp))
+ return 0;
+ goto emptynode;
+ }
+
+ if (oidp->oid_number < *name)
+ continue;
+
+ if (oidp->oid_number > *name) {
+ if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
+ return 0;
+ if (oidp->oid_handler)
+ return 0;
+ lsp = (struct sysctl_oid_list *)oidp->oid_arg1;
+ if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1,
+ next+1, len, level+1, oidpp))
+ return (0);
+ goto next;
+ }
+ if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
+ continue;
+
+ if (oidp->oid_handler)
+ continue;
+
+ lsp = (struct sysctl_oid_list *)oidp->oid_arg1;
+ if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1,
+ len, level+1, oidpp))
+ return (0);
+ next:
+ namelen = 1;
+ emptynode:
+ *len = level;
+ }
+ return 1;
+}
+
+static int
+sysctl_sysctl_next(SYSCTL_HANDLER_ARGS)
+{
+ int *name = (int *) arg1;
+ u_int namelen = arg2;
+ int i, j, error;
+ struct sysctl_oid *oid;
+ struct sysctl_oid_list *lsp = &sysctl__children;
+ int newoid[CTL_MAXNAME];
+
+ i = sysctl_sysctl_next_ls(lsp, name, namelen, newoid, &j, 1, &oid);
+ if (i)
+ return ENOENT;
+ error = SYSCTL_OUT(req, newoid, j * sizeof (int));
+ return (error);
+}
+
+SYSCTL_NODE(_sysctl, 2, next, CTLFLAG_RD, sysctl_sysctl_next, "");
+
+static int
+name2oid (char *name, int *oid, int *len, struct sysctl_oid **oidpp)
+{
+ int i;
+ struct sysctl_oid *oidp;
+ struct sysctl_oid_list *lsp = &sysctl__children;
+ char *p;
+
+ if (!*name)
+ return ENOENT;
+
+ p = name + strlen(name) - 1 ;
+ if (*p == '.')
+ *p = '\0';
+
+ *len = 0;
+
+ for (p = name; *p && *p != '.'; p++)
+ ;
+ i = *p;
+ if (i == '.')
+ *p = '\0';
+
+ oidp = SLIST_FIRST(lsp);
+
+ while (oidp && *len < CTL_MAXNAME) {
+ if (strcmp(name, oidp->oid_name)) {
+ oidp = SLIST_NEXT(oidp, oid_link);
+ continue;
+ }
+ *oid++ = oidp->oid_number;
+ (*len)++;
+
+ if (!i) {
+ if (oidpp)
+ *oidpp = oidp;
+ return (0);
+ }
+
+ if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
+ break;
+
+ if (oidp->oid_handler)
+ break;
+
+ lsp = (struct sysctl_oid_list *)oidp->oid_arg1;
+ oidp = SLIST_FIRST(lsp);
+ name = p+1;
+ for (p = name; *p && *p != '.'; p++)
+ ;
+ i = *p;
+ if (i == '.')
+ *p = '\0';
+ }
+ return ENOENT;
+}
+
+static int
+sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS)
+{
+ char *p;
+ int error, oid[CTL_MAXNAME], len=0;
+ struct sysctl_oid *op = 0;
+
+ if (!req->newlen)
+ return ENOENT;
+ if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */
+ return (ENAMETOOLONG);
+
+ p = malloc(req->newlen+1, M_SYSCTL, M_WAITOK);
+
+ error = SYSCTL_IN(req, p, req->newlen);
+ if (error) {
+ free(p, M_SYSCTL);
+ return (error);
+ }
+
+ p [req->newlen] = '\0';
+
+ error = name2oid(p, oid, &len, &op);
+
+ free(p, M_SYSCTL);
+
+ if (error)
+ return (error);
+
+ error = SYSCTL_OUT(req, oid, len * sizeof *oid);
+ return (error);
+}
+
+SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW|CTLFLAG_ANYBODY, 0, 0,
+ sysctl_sysctl_name2oid, "I", "");
+
+static int
+sysctl_sysctl_oidfmt(SYSCTL_HANDLER_ARGS)
+{
+ struct sysctl_oid *oid;
+ int error;
+
+ error = sysctl_find_oid(arg1, arg2, &oid, NULL, req);
+ if (error)
+ return (error);
+
+ if (!oid->oid_fmt)
+ return (ENOENT);
+ error = SYSCTL_OUT(req, &oid->oid_kind, sizeof(oid->oid_kind));
+ if (error)
+ return (error);
+ error = SYSCTL_OUT(req, oid->oid_fmt, strlen(oid->oid_fmt) + 1);
+ return (error);
+}
+
+
+SYSCTL_NODE(_sysctl, 4, oidfmt, CTLFLAG_RD, sysctl_sysctl_oidfmt, "");
+
+static int
+sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS)
+{
+ struct sysctl_oid *oid;
+ int error;
+
+ error = sysctl_find_oid(arg1, arg2, &oid, NULL, req);
+ if (error)
+ return (error);
+
+ if (!oid->descr)
+ return (ENOENT);
+ error = SYSCTL_OUT(req, oid->descr, strlen(oid->descr) + 1);
+ return (error);
+}
+
+SYSCTL_NODE(_sysctl, 5, oiddescr, CTLFLAG_RD, sysctl_sysctl_oiddescr, "");
+
+/*
+ * Default "handler" functions.
+ */
+
+/*
+ * Handle an int, signed or unsigned.
+ * Two cases:
+ * a variable: point arg1 at it.
+ * a constant: pass it in arg2.
+ */
+
+int
+sysctl_handle_int(SYSCTL_HANDLER_ARGS)
+{
+ int tmpout, error = 0;
+
+ /*
+ * Attempt to get a coherent snapshot by making a copy of the data.
+ */
+ if (arg1)
+ tmpout = *(int *)arg1;
+ else
+ tmpout = arg2;
+ error = SYSCTL_OUT(req, &tmpout, sizeof(int));
+
+ if (error || !req->newptr)
+ return (error);
+
+ if (!arg1)
+ error = EPERM;
+ else
+ error = SYSCTL_IN(req, arg1, sizeof(int));
+ return (error);
+}
+
+/*
+ * Handle a long, signed or unsigned. arg1 points to it.
+ */
+
+int
+sysctl_handle_long(SYSCTL_HANDLER_ARGS)
+{
+ int error = 0;
+ long tmpout;
+
+ /*
+ * Attempt to get a coherent snapshot by making a copy of the data.
+ */
+ if (!arg1)
+ return (EINVAL);
+ tmpout = *(long *)arg1;
+ error = SYSCTL_OUT(req, &tmpout, sizeof(long));
+
+ if (error || !req->newptr)
+ return (error);
+
+ error = SYSCTL_IN(req, arg1, sizeof(long));
+ return (error);
+}
+
+/*
+ * Handle our generic '\0' terminated 'C' string.
+ * Two cases:
+ * a variable string: point arg1 at it, arg2 is max length.
+ * a constant string: point arg1 at it, arg2 is zero.
+ */
+
+int
+sysctl_handle_string(SYSCTL_HANDLER_ARGS)
+{
+ int error=0;
+ char *tmparg;
+ size_t outlen;
+
+ /*
+ * Attempt to get a coherent snapshot by copying to a
+ * temporary kernel buffer.
+ */
+retry:
+ outlen = strlen((char *)arg1)+1;
+ tmparg = malloc(outlen, M_SYSCTLTMP, M_WAITOK);
+
+ if (strlcpy(tmparg, (char *)arg1, outlen) >= outlen) {
+ free(tmparg, M_SYSCTLTMP);
+ goto retry;
+ }
+
+ error = SYSCTL_OUT(req, tmparg, outlen);
+ free(tmparg, M_SYSCTLTMP);
+
+ if (error || !req->newptr)
+ return (error);
+
+ if ((req->newlen - req->newidx) >= arg2) {
+ error = EINVAL;
+ } else {
+ arg2 = (req->newlen - req->newidx);
+ error = SYSCTL_IN(req, arg1, arg2);
+ ((char *)arg1)[arg2] = '\0';
+ }
+
+ return (error);
+}
+
+/*
+ * Handle any kind of opaque data.
+ * arg1 points to it, arg2 is the size.
+ */
+
+int
+sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)
+{
+ int error;
+ void *tmparg;
+
+ /*
+ * Attempt to get a coherent snapshot, either by wiring the
+ * user space buffer or copying to a temporary kernel buffer
+ * depending on the size of the data.
+ */
+ if (arg2 > PAGE_SIZE) {
+ sysctl_wire_old_buffer(req, arg2);
+ error = SYSCTL_OUT(req, arg1, arg2);
+ } else {
+ tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
+ bcopy(arg1, tmparg, arg2);
+ error = SYSCTL_OUT(req, tmparg, arg2);
+ free(tmparg, M_SYSCTLTMP);
+ }
+
+ if (error || !req->newptr)
+ return (error);
+
+ error = SYSCTL_IN(req, arg1, arg2);
+
+ return (error);
+}
+
+/*
+ * Transfer functions to/from kernel space.
+ * XXX: rather untested at this point
+ */
+static int
+sysctl_old_kernel(struct sysctl_req *req, const void *p, size_t l)
+{
+ size_t i = 0;
+
+ if (req->oldptr) {
+ i = l;
+ if (req->oldlen <= req->oldidx)
+ i = 0;
+ else
+ if (i > req->oldlen - req->oldidx)
+ i = req->oldlen - req->oldidx;
+ if (i > 0)
+ bcopy(p, (char *)req->oldptr + req->oldidx, i);
+ }
+ req->oldidx += l;
+ if (req->oldptr && i != l)
+ return (ENOMEM);
+ return (0);
+}
+
+static int
+sysctl_new_kernel(struct sysctl_req *req, void *p, size_t l)
+{
+ if (!req->newptr)
+ return 0;
+ if (req->newlen - req->newidx < l)
+ return (EINVAL);
+ bcopy((char *)req->newptr + req->newidx, p, l);
+ req->newidx += l;
+ return (0);
+}
+
+int
+kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
+ size_t *oldlenp, void *new, size_t newlen, size_t *retval)
+{
+ int error = 0;
+ struct sysctl_req req;
+
+ bzero(&req, sizeof req);
+
+ req.td = td;
+
+ if (oldlenp) {
+ req.oldlen = *oldlenp;
+ }
+
+ if (old) {
+ req.oldptr= old;
+ }
+
+ if (new != NULL) {
+ req.newlen = newlen;
+ req.newptr = new;
+ }
+
+ req.oldfunc = sysctl_old_kernel;
+ req.newfunc = sysctl_new_kernel;
+ req.lock = REQ_LOCKED;
+
+ SYSCTL_LOCK();
+
+ error = sysctl_root(0, name, namelen, &req);
+
+ if (req.lock == REQ_WIRED)
+#ifdef __rtems__
+ printf ("kern_sysctl: vsunlock needs to be called!\n");
+#else
+ vsunlock(req.oldptr, req.oldlen);
+#endif
+
+ SYSCTL_UNLOCK();
+
+ if (error && error != ENOMEM)
+ return (error);
+
+ if (retval) {
+ if (req.oldptr && req.oldidx > req.oldlen)
+ *retval = req.oldlen;
+ else
+ *retval = req.oldidx;
+ }
+ return (error);
+}
+
+int
+kernel_sysctlbyname(struct thread *td, char *name, void *old, size_t *oldlenp,
+ void *new, size_t newlen, size_t *retval)
+{
+ int oid[CTL_MAXNAME];
+ size_t oidlen, plen;
+ int error;
+
+ plen = 0; /* RTEMS - to avoid warnings */
+
+ oid[0] = 0; /* sysctl internal magic */
+ oid[1] = 3; /* name2oid */
+ oidlen = sizeof(oid);
+
+ error = kernel_sysctl(td, oid, 2, oid, &oidlen,
+ (void *)name, strlen(name), &plen);
+ if (error)
+ return (error);
+
+ error = kernel_sysctl(td, oid, plen / sizeof(int), old, oldlenp,
+ new, newlen, retval);
+ return (error);
+}
+
+/*
+ * Transfer function to/from user space.
+ */
+static int
+sysctl_old_user(struct sysctl_req *req, const void *p, size_t l)
+{
+ int error = 0;
+ size_t i = 0;
+
+#ifndef __rtems__
+ if (req->lock == 1 && req->oldptr)
+ WITNESS_SLEEP(1, NULL);
+#endif
+ if (req->oldptr) {
+ i = l;
+ if (req->oldlen <= req->oldidx)
+ i = 0;
+ else
+ if (i > req->oldlen - req->oldidx)
+ i = req->oldlen - req->oldidx;
+ if (i > 0)
+ error = copyout(p, (char *)req->oldptr + req->oldidx,
+ i);
+ }
+ req->oldidx += l;
+ if (error)
+ return (error);
+ if (req->oldptr && i < l)
+ return (ENOMEM);
+ return (0);
+}
+
+static int
+sysctl_new_user(struct sysctl_req *req, void *p, size_t l)
+{
+ int error;
+
+ if (!req->newptr)
+ return 0;
+ if (req->newlen - req->newidx < l)
+ return (EINVAL);
+ error = copyin((char *)req->newptr + req->newidx, p, l);
+ req->newidx += l;
+ return (error);
+}
+
+/*
+ * Wire the user space destination buffer. If set to a value greater than
+ * zero, the len parameter limits the maximum amount of wired memory.
+ *
+ * XXX - The len parameter is currently ignored due to the lack of
+ * a place to save it in the sysctl_req structure so that the matching
+ * amount of memory can be unwired in the sysctl exit code.
+ */
+int
+sysctl_wire_old_buffer(struct sysctl_req *req, size_t len)
+{
+ if (req->lock == REQ_LOCKED && req->oldptr &&
+ req->oldfunc == sysctl_old_user) {
+#ifndef __rtems__
+ vslock(req->oldptr, req->oldlen);
+#endif
+ req->lock = REQ_WIRED;
+ }
+ return (0);
+}
+
+int
+sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
+ int *nindx, struct sysctl_req *req)
+{
+ struct sysctl_oid *oid;
+ int indx;
+
+ oid = SLIST_FIRST(&sysctl__children);
+ indx = 0;
+ while (oid && indx < CTL_MAXNAME) {
+ if (oid->oid_number == name[indx]) {
+ indx++;
+ if (oid->oid_kind & CTLFLAG_NOLOCK)
+ req->lock = REQ_UNLOCKED;
+ if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
+ if (oid->oid_handler != NULL ||
+ indx == namelen) {
+ *noid = oid;
+ if (nindx != NULL)
+ *nindx = indx;
+ return (0);
+ }
+ oid = SLIST_FIRST(
+ (struct sysctl_oid_list *)oid->oid_arg1);
+ } else if (indx == namelen) {
+ *noid = oid;
+ if (nindx != NULL)
+ *nindx = indx;
+ return (0);
+ } else {
+ return (ENOTDIR);
+ }
+ } else {
+ oid = SLIST_NEXT(oid, oid_link);
+ }
+ }
+ return (ENOENT);
+}
+
+/*
+ * Traverse our tree, and find the right node, execute whatever it points
+ * to, and return the resulting error code.
+ */
+
+static int
+sysctl_root(SYSCTL_HANDLER_ARGS)
+{
+ struct sysctl_oid *oid;
+ int error, indx;
+
+ error = sysctl_find_oid(arg1, arg2, &oid, &indx, req);
+ if (error)
+ return (error);
+
+ if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
+ /*
+ * You can't call a sysctl when it's a node, but has
+ * no handler. Inform the user that it's a node.
+ * The indx may or may not be the same as namelen.
+ */
+ if (oid->oid_handler == NULL)
+ return (EISDIR);
+ }
+
+ /* Is this sysctl writable? */
+ if (req->newptr && !(oid->oid_kind & CTLFLAG_WR))
+ return (EPERM);
+
+#ifndef __rtems__
+ KASSERT(req->td != NULL, ("sysctl_root(): req->td == NULL"));
+
+ /* Is this sysctl sensitive to securelevels? */
+ if (req->newptr && (oid->oid_kind & CTLFLAG_SECURE)) {
+ error = securelevel_gt(req->td->td_ucred, 0);
+ if (error)
+ return (error);
+ }
+
+ /* Is this sysctl writable by only privileged users? */
+ if (req->newptr && !(oid->oid_kind & CTLFLAG_ANYBODY)) {
+ int flags;
+
+ if (oid->oid_kind & CTLFLAG_PRISON)
+ flags = PRISON_ROOT;
+ else
+ flags = 0;
+ error = suser_cred(req->td->td_ucred, flags);
+ if (error)
+ return (error);
+ }
+#endif
+
+ if (!oid->oid_handler)
+ return EINVAL;
+
+ if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE)
+ error = oid->oid_handler(oid, (int *)arg1 + indx, arg2 - indx,
+ req);
+ else
+ error = oid->oid_handler(oid, oid->oid_arg1, oid->oid_arg2,
+ req);
+ return (error);
+}
+
+#ifndef _SYS_SYSPROTO_H_
+struct sysctl_args {
+ int *name;
+ u_int namelen;
+ void *old;
+ size_t *oldlenp;
+ void *new;
+ size_t newlen;
+};
+#endif
+
+/*
+ * MPSAFE
+ */
+int
+__sysctl(struct thread *td, struct sysctl_args *uap)
+{
+ int error, name[CTL_MAXNAME];
+ size_t j;
+
+ if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
+ return (EINVAL);
+
+ error = copyin(uap->name, &name, uap->namelen * sizeof(int));
+ if (error)
+ return (error);
+
+ mtx_lock(&Giant);
+
+ error = userland_sysctl(td, name, uap->namelen,
+ uap->old, uap->oldlenp, 0,
+ uap->new, uap->newlen, &j);
+ if (error && error != ENOMEM)
+ goto done2;
+ if (uap->oldlenp) {
+ int i = copyout(&j, uap->oldlenp, sizeof(j));
+ if (i)
+ error = i;
+ }
+done2:
+ mtx_unlock(&Giant);
+ return (error);
+}
+
+/*
+ * This is used from various compatibility syscalls too. That's why name
+ * must be in kernel space.
+ */
+int
+userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
+ size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval)
+{
+ int error = 0;
+ struct sysctl_req req, req2;
+
+ bzero(&req, sizeof req);
+
+ req.td = td;
+
+ if (oldlenp) {
+ if (inkernel) {
+ req.oldlen = *oldlenp;
+ } else {
+ error = copyin(oldlenp, &req.oldlen, sizeof(*oldlenp));
+ if (error)
+ return (error);
+ }
+ }
+
+ if (old) {
+#ifndef __rtems__
+ if (!useracc(old, req.oldlen, VM_PROT_WRITE))
+ return (EFAULT);
+#endif
+ req.oldptr= old;
+ }
+
+ if (new != NULL) {
+#ifndef __rtems__
+ if (!useracc(new, req.newlen, VM_PROT_READ))
+ return (EFAULT);
+#endif
+ req.newlen = newlen;
+ req.newptr = new;
+ }
+
+ req.oldfunc = sysctl_old_user;
+ req.newfunc = sysctl_new_user;
+ req.lock = REQ_LOCKED;
+
+ SYSCTL_LOCK();
+
+#ifdef MAC
+ error = mac_check_system_sysctl(td->td_ucred, name, namelen, old,
+ oldlenp, inkernel, new, newlen);
+ if (error) {
+ SYSCTL_UNLOCK();
+ return (error);
+ }
+#endif
+
+ do {
+ req2 = req;
+ error = sysctl_root(0, name, namelen, &req2);
+ } while (error == EAGAIN);
+
+ req = req2;
+#ifndef __rtems__
+ if (req.lock == REQ_WIRED)
+ vsunlock(req.oldptr, req.oldlen);
+#endif
+
+ SYSCTL_UNLOCK();
+
+ if (error && error != ENOMEM)
+ return (error);
+
+ if (retval) {
+ if (req.oldptr && req.oldidx > req.oldlen)
+ *retval = req.oldlen;
+ else
+ *retval = req.oldidx;
+ }
+ return (error);
+}
+
+#ifdef COMPAT_43
+#include <sys/socket.h>
+#include <vm/vm_param.h>
+
+#define KINFO_PROC (0<<8)
+#define KINFO_RT (1<<8)
+#define KINFO_VNODE (2<<8)
+#define KINFO_FILE (3<<8)
+#define KINFO_METER (4<<8)
+#define KINFO_LOADAVG (5<<8)
+#define KINFO_CLOCKRATE (6<<8)
+
+/* Non-standard BSDI extension - only present on their 4.3 net-2 releases */
+#define KINFO_BSDI_SYSINFO (101<<8)
+
+/*
+ * XXX this is bloat, but I hope it's better here than on the potentially
+ * limited kernel stack... -Peter
+ */
+
+static struct {
+ int bsdi_machine; /* "i386" on BSD/386 */
+/* ^^^ this is an offset to the string, relative to the struct start */
+ char *pad0;
+ long pad1;
+ long pad2;
+ long pad3;
+ u_long pad4;
+ u_long pad5;
+ u_long pad6;
+
+ int bsdi_ostype; /* "BSD/386" on BSD/386 */
+ int bsdi_osrelease; /* "1.1" on BSD/386 */
+ long pad7;
+ long pad8;
+ char *pad9;
+
+ long pad10;
+ long pad11;
+ int pad12;
+ long pad13;
+ quad_t pad14;
+ long pad15;
+
+ struct timeval pad16;
+ /* we dont set this, because BSDI's uname used gethostname() instead */
+ int bsdi_hostname; /* hostname on BSD/386 */
+
+ /* the actual string data is appended here */
+
+} bsdi_si;
+/*
+ * this data is appended to the end of the bsdi_si structure during copyout.
+ * The "char *" offsets are relative to the base of the bsdi_si struct.
+ * This contains "FreeBSD\02.0-BUILT-nnnnnn\0i386\0", and these strings
+ * should not exceed the length of the buffer here... (or else!! :-)
+ */
+static char bsdi_strings[80]; /* It had better be less than this! */
+
+#ifndef _SYS_SYSPROTO_H_
+struct getkerninfo_args {
+ int op;
+ char *where;
+ size_t *size;
+ int arg;
+};
+#endif
+
+/*
+ * MPSAFE
+ */
+int
+ogetkerninfo(struct thread *td, struct getkerninfo_args *uap)
+{
+ int error, name[6];
+ size_t size;
+ u_int needed = 0;
+
+ mtx_lock(&Giant);
+
+ switch (uap->op & 0xff00) {
+
+ case KINFO_RT:
+ name[0] = CTL_NET;
+ name[1] = PF_ROUTE;
+ name[2] = 0;
+ name[3] = (uap->op & 0xff0000) >> 16;
+ name[4] = uap->op & 0xff;
+ name[5] = uap->arg;
+ error = userland_sysctl(td, name, 6, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_VNODE:
+ name[0] = CTL_KERN;
+ name[1] = KERN_VNODE;
+ error = userland_sysctl(td, name, 2, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_PROC:
+ name[0] = CTL_KERN;
+ name[1] = KERN_PROC;
+ name[2] = uap->op & 0xff;
+ name[3] = uap->arg;
+ error = userland_sysctl(td, name, 4, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_FILE:
+ name[0] = CTL_KERN;
+ name[1] = KERN_FILE;
+ error = userland_sysctl(td, name, 2, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_METER:
+ name[0] = CTL_VM;
+ name[1] = VM_TOTAL;
+ error = userland_sysctl(td, name, 2, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_LOADAVG:
+ name[0] = CTL_VM;
+ name[1] = VM_LOADAVG;
+ error = userland_sysctl(td, name, 2, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_CLOCKRATE:
+ name[0] = CTL_KERN;
+ name[1] = KERN_CLOCKRATE;
+ error = userland_sysctl(td, name, 2, uap->where, uap->size,
+ 0, 0, 0, &size);
+ break;
+
+ case KINFO_BSDI_SYSINFO: {
+ /*
+ * this is pretty crude, but it's just enough for uname()
+ * from BSDI's 1.x libc to work.
+ *
+ * *size gives the size of the buffer before the call, and
+ * the amount of data copied after a successful call.
+ * If successful, the return value is the amount of data
+ * available, which can be larger than *size.
+ *
+ * BSDI's 2.x product apparently fails with ENOMEM if *size
+ * is too small.
+ */
+
+ u_int left;
+ char *s;
+
+ bzero((char *)&bsdi_si, sizeof(bsdi_si));
+ bzero(bsdi_strings, sizeof(bsdi_strings));
+
+ s = bsdi_strings;
+
+ bsdi_si.bsdi_ostype = (s - bsdi_strings) + sizeof(bsdi_si);
+ strcpy(s, ostype);
+ s += strlen(s) + 1;
+
+ bsdi_si.bsdi_osrelease = (s - bsdi_strings) + sizeof(bsdi_si);
+ strcpy(s, osrelease);
+ s += strlen(s) + 1;
+
+ bsdi_si.bsdi_machine = (s - bsdi_strings) + sizeof(bsdi_si);
+ strcpy(s, machine);
+ s += strlen(s) + 1;
+
+ needed = sizeof(bsdi_si) + (s - bsdi_strings);
+
+ if ((uap->where == NULL) || (uap->size == NULL)) {
+ /* process is asking how much buffer to supply.. */
+ size = needed;
+ error = 0;
+ break;
+ }
+
+ if ((error = copyin(uap->size, &size, sizeof(size))) != 0)
+ break;
+
+ /* if too much buffer supplied, trim it down */
+ if (size > needed)
+ size = needed;
+
+ /* how much of the buffer is remaining */
+ left = size;
+
+ if ((error = copyout((char *)&bsdi_si, uap->where, left)) != 0)
+ break;
+
+ /* is there any point in continuing? */
+ if (left > sizeof(bsdi_si)) {
+ left -= sizeof(bsdi_si);
+ error = copyout(&bsdi_strings,
+ uap->where + sizeof(bsdi_si), left);
+ }
+ break;
+ }
+
+ default:
+ error = EOPNOTSUPP;
+ break;
+ }
+ if (error == 0) {
+ td->td_retval[0] = needed ? needed : size;
+ if (uap->size) {
+ error = copyout(&size, uap->size, sizeof(size));
+ }
+ }
+ mtx_unlock(&Giant);
+ return (error);
+}
+#endif /* COMPAT_43 */
diff --git a/cpukit/libnetworking/kern/uipc_domain.c b/cpukit/libnetworking/kern/uipc_domain.c
new file mode 100644
index 0000000000..241fe4cc86
--- /dev/null
+++ b/cpukit/libnetworking/kern/uipc_domain.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/domain.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+
+/*
+ * System initialization
+ *
+ * Note: domain initialization wants to take place on a per domain basis
+ * as a result of traversing a linker set. Most likely, each domain
+ * want to call a registration function rather than being handled here
+ * in domaininit(). Probably this will look like:
+ *
+ * SYSINIT(unique, SI_SUB_PROTO_DOMAI, SI_ORDER_ANY, domain_add, xxx)
+ *
+ * Where 'xxx' is replaced by the address of a parameter struct to be
+ * passed to the doamin_add() function.
+ */
+
+#if !defined(__rtems__)
+static int x_save_spl; /* used by kludge*/
+static void kludge_splimp(void *);
+static void kludge_splx(void *);
+ void domaininit(void *);
+SYSINIT(splimp, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, kludge_splimp, &x_save_spl)
+SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
+SYSINIT(splx, SI_SUB_PROTO_END, SI_ORDER_FIRST, kludge_splx, &x_save_spl)
+#endif
+
+static void pffasttimo(void *);
+static void pfslowtimo(void *);
+
+struct domain *domains;
+
+#define ADDDOMAIN(x) { \
+ __CONCAT(x,domain.dom_next) = domains; \
+ domains = &__CONCAT(x,domain); \
+}
+
+/* ARGSUSED*/
+void
+domaininit(void *dummy)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+
+/* - not in our sources
+#ifdef ISDN
+ ADDDOMAIN(isdn);
+#endif
+*/
+
+ for (dp = domains; dp; dp = dp->dom_next) {
+ if (dp->dom_init)
+ (*dp->dom_init)();
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){
+#ifdef PRU_OLDSTYLE
+ /* See comments in uipc_socket2.c. */
+ if (pr->pr_usrreqs == 0 && pr->pr_ousrreq)
+ pr->pr_usrreqs = &pru_oldstyle;
+#endif
+ if (pr->pr_init)
+ (*pr->pr_init)();
+ }
+ }
+
+ if (max_linkhdr < 16) /* XXX */
+ max_linkhdr = 16;
+ max_hdr = max_linkhdr + max_protohdr;
+ max_datalen = MHLEN - max_hdr;
+ timeout(pffasttimo, (void *)0, 1);
+ timeout(pfslowtimo, (void *)0, 1);
+}
+
+
+#if !defined(__rtems__)
+/*
+ * The following two operations are kludge code. Most likely, they should
+ * be done as a "domainpreinit()" for the first function and then rolled
+ * in as the last act of "domaininit()" for the second.
+ *
+ * In point of fact, it is questionable why other initialization prior
+ * to this does not also take place at splimp by default.
+ */
+static void
+kludge_splimp(void *udata)
+{
+ int *savesplp = udata;
+
+ *savesplp = splimp();
+}
+
+static void
+kludge_splx(void *udata)
+{
+ int *savesplp = udata;
+
+ splx( *savesplp);
+}
+#endif /* !defined(__rtems__) */
+
+struct protosw *
+pffindtype(int family, int type)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+
+ for (dp = domains; dp; dp = dp->dom_next)
+ if (dp->dom_family == family)
+ goto found;
+ return (0);
+found:
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+ if (pr->pr_type && pr->pr_type == type)
+ return (pr);
+ return (0);
+}
+
+struct protosw *
+pffindproto(int family, int protocol, int type)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+ struct protosw *maybe = 0;
+
+ if (family == 0)
+ return (0);
+ for (dp = domains; dp; dp = dp->dom_next)
+ if (dp->dom_family == family)
+ goto found;
+ return (0);
+found:
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+ if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
+ return (pr);
+
+ if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
+ pr->pr_protocol == 0 && maybe == (struct protosw *)0)
+ maybe = pr;
+ }
+ return (maybe);
+}
+
+void
+pfctlinput(int cmd, struct sockaddr *sa)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+
+ for (dp = domains; dp; dp = dp->dom_next)
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+ if (pr->pr_ctlinput)
+ (*pr->pr_ctlinput)(cmd, sa, (void *)0);
+}
+
+static void
+pfslowtimo(void *arg)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+
+ for (dp = domains; dp; dp = dp->dom_next)
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+ if (pr->pr_slowtimo)
+ (*pr->pr_slowtimo)();
+ timeout(pfslowtimo, (void *)0, hz/2);
+}
+
+static void
+pffasttimo(void *arg)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+
+ for (dp = domains; dp; dp = dp->dom_next)
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+ if (pr->pr_fasttimo)
+ (*pr->pr_fasttimo)();
+ timeout(pffasttimo, (void *)0, hz/5);
+}
diff --git a/cpukit/libnetworking/kern/uipc_mbuf.c b/cpukit/libnetworking/kern/uipc_mbuf.c
new file mode 100644
index 0000000000..390f9b6899
--- /dev/null
+++ b/cpukit/libnetworking/kern/uipc_mbuf.c
@@ -0,0 +1,741 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#define MBTYPES
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/syslog.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/vm_kern.h>
+#include <vm/vm_extern.h>
+
+#if !defined(__rtems__)
+static void mbinit (void *) __attribute__ ((unused));
+SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbinit, NULL)
+#endif
+
+struct mbuf *mbutl;
+char *mclrefcnt;
+struct mbstat mbstat;
+struct mbuf *mmbfree;
+union mcluster *mclfree;
+int max_linkhdr;
+int max_protohdr;
+int max_hdr;
+int max_datalen;
+
+/* "number of clusters of pages" */
+#define NCL_INIT 1
+
+#define NMB_INIT 16
+
+/*
+ * When MGET failes, ask protocols to free space when short of memory,
+ * then re-attempt to allocate an mbuf.
+ */
+struct mbuf *
+m_retry(int i, int t)
+{
+ register struct mbuf *m;
+
+ m_reclaim();
+#define m_retry(i, t) (struct mbuf *)0
+ MGET(m, i, t);
+#undef m_retry
+ if (m != NULL)
+ mbstat.m_wait++;
+ else
+ mbstat.m_drops++;
+ return (m);
+}
+
+/*
+ * As above; retry an MGETHDR.
+ */
+struct mbuf *
+m_retryhdr(int i, int t)
+{
+ register struct mbuf *m;
+
+ m_reclaim();
+#define m_retryhdr(i, t) (struct mbuf *)0
+ MGETHDR(m, i, t);
+#undef m_retryhdr
+ if (m != NULL)
+ mbstat.m_wait++;
+ else
+ mbstat.m_drops++;
+ return (m);
+}
+
+void
+m_reclaim(void)
+{
+ register struct domain *dp;
+ register struct protosw *pr;
+ int s = splimp();
+
+ for (dp = domains; dp; dp = dp->dom_next)
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+ if (pr->pr_drain)
+ (*pr->pr_drain)();
+ splx(s);
+ mbstat.m_drain++;
+}
+
+/*
+ * Space allocation routines.
+ * These are also available as macros
+ * for critical paths.
+ */
+struct mbuf *
+m_get(int nowait, int type)
+{
+ register struct mbuf *m;
+
+ MGET(m, nowait, type);
+ return (m);
+}
+
+struct mbuf *
+m_gethdr(int nowait, int type)
+{
+ register struct mbuf *m;
+
+ MGETHDR(m, nowait, type);
+ return (m);
+}
+
+struct mbuf *
+m_getclr(int nowait, int type)
+{
+ register struct mbuf *m;
+
+ MGET(m, nowait, type);
+ if (m == 0)
+ return (0);
+ bzero(mtod(m, caddr_t), MLEN);
+ return (m);
+}
+
+struct mbuf *
+m_free(struct mbuf *m)
+{
+ struct mbuf *n;
+
+ MFREE(m, n);
+ return (n);
+}
+
+void
+m_freem(struct mbuf *mb)
+{
+ struct mbuf *n;
+
+ if (mb == NULL)
+ return;
+ do {
+ MFREE(mb, n);
+ mb = n;
+ } while (mb);
+}
+
+/*
+ * Mbuffer utility routines.
+ */
+
+/*
+ * Lesser-used path for M_PREPEND:
+ * allocate new mbuf to prepend to chain,
+ * copy junk along.
+ */
+struct mbuf *
+m_prepend(struct mbuf *m, int len, int how)
+{
+ struct mbuf *mn;
+
+ MGET(mn, how, m->m_type);
+ if (mn == (struct mbuf *)NULL) {
+ m_freem(m);
+ return ((struct mbuf *)NULL);
+ }
+ if (m->m_flags & M_PKTHDR) {
+ M_COPY_PKTHDR(mn, m);
+ m->m_flags &= ~M_PKTHDR;
+ }
+ mn->m_next = m;
+ m = mn;
+ if (len < MHLEN)
+ MH_ALIGN(m, len);
+ m->m_len = len;
+ return (m);
+}
+
+/*
+ * Make a copy of an mbuf chain starting "off0" bytes from the beginning,
+ * continuing for "len" bytes. If len is M_COPYALL, copy to end of mbuf.
+ * The wait parameter is a choice of M_WAIT/M_DONTWAIT from caller.
+ */
+static int MCFail;
+
+struct mbuf *
+m_copym(struct mbuf *m, int off0, uint32_t len, int wait)
+{
+ struct mbuf *n, **np;
+ int off = off0;
+ struct mbuf *top;
+ int copyhdr = 0;
+
+ if (off < 0 || len < 0)
+ panic("m_copym");
+ if (off == 0 && m->m_flags & M_PKTHDR)
+ copyhdr = 1;
+ while (off > 0) {
+ if (m == NULL)
+ panic("m_copym");
+ if (off < m->m_len)
+ break;
+ off -= m->m_len;
+ m = m->m_next;
+ }
+ np = &top;
+ top = 0;
+ while (len > 0) {
+ if (m == NULL) {
+ if (len != M_COPYALL)
+ panic("m_copym");
+ break;
+ }
+ MGET(n, wait, m->m_type);
+ *np = n;
+ if (n == NULL)
+ goto nospace;
+ if (copyhdr) {
+ M_COPY_PKTHDR(n, m);
+ if (len == M_COPYALL)
+ n->m_pkthdr.len -= off0;
+ else
+ n->m_pkthdr.len = len;
+ copyhdr = 0;
+ }
+ n->m_len = min(len, m->m_len - off);
+ if (m->m_flags & M_EXT) {
+ n->m_data = m->m_data + off;
+ if(!m->m_ext.ext_ref)
+ mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
+ else
+ (*(m->m_ext.ext_ref))(m->m_ext.ext_buf,
+ m->m_ext.ext_size);
+ n->m_ext = m->m_ext;
+ n->m_flags |= M_EXT;
+ } else
+ bcopy(mtod(m, caddr_t)+off, mtod(n, caddr_t),
+ (unsigned)n->m_len);
+ if (len != M_COPYALL)
+ len -= n->m_len;
+ off = 0;
+ m = m->m_next;
+ np = &n->m_next;
+ }
+ if (top == NULL)
+ MCFail++;
+ return (top);
+nospace:
+ m_freem(top);
+ MCFail++;
+ return (NULL);
+}
+
+/*
+ * Copy an entire packet, including header (which must be present).
+ * An optimization of the common case `m_copym(m, 0, M_COPYALL, how)'.
+ */
+struct mbuf *
+m_copypacket(struct mbuf *m, int how)
+{
+ struct mbuf *top, *n, *o;
+
+ MGET(n, how, m->m_type);
+ top = n;
+ if (!n)
+ goto nospace;
+
+ M_COPY_PKTHDR(n, m);
+ n->m_len = m->m_len;
+ if (m->m_flags & M_EXT) {
+ n->m_data = m->m_data;
+ mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
+ n->m_ext = m->m_ext;
+ n->m_flags |= M_EXT;
+ } else {
+ bcopy(mtod(m, char *), mtod(n, char *), n->m_len);
+ }
+
+ m = m->m_next;
+ while (m) {
+ MGET(o, how, m->m_type);
+ if (!o)
+ goto nospace;
+
+ n->m_next = o;
+ n = n->m_next;
+
+ n->m_len = m->m_len;
+ if (m->m_flags & M_EXT) {
+ n->m_data = m->m_data;
+ mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
+ n->m_ext = m->m_ext;
+ n->m_flags |= M_EXT;
+ } else {
+ bcopy(mtod(m, char *), mtod(n, char *), n->m_len);
+ }
+
+ m = m->m_next;
+ }
+ return top;
+nospace:
+ m_freem(top);
+ MCFail++;
+ return 0;
+}
+
+/*
+ * Copy data from an mbuf chain starting "off" bytes from the beginning,
+ * continuing for "len" bytes, into the indicated buffer. Return -1 if requested
+ * size is bigger than available
+ */
+int
+m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
+{
+ u_int count;
+
+ if (off < 0 || len < 0)
+ panic("m_copydata");
+ while (off > 0) {
+ if (m == 0) {
+ /*printf("m_copydata: offset > mbuf length (");
+ while(m0) {
+ printf("[%d] ",m0->m_len);
+ m0 = m0->m_next;
+ }
+ printf(")\n");*/
+ return -1;
+ }
+ if (off < m->m_len)
+ break;
+ off -= m->m_len;
+ m = m->m_next;
+ }
+ while (len > 0) {
+ if (m == 0) {
+ /*printf("m_copydata: length > mbuf length (");
+ while(m0) {
+ printf("[%d] ",m0->m_len);
+ m0 = m0->m_next;
+ }
+ printf(")\n");*/
+
+ return -1;
+ }
+ count = min(m->m_len - off, len);
+ bcopy(mtod(m, caddr_t) + off, cp, count);
+ len -= count;
+ cp += count;
+ off = 0;
+ m = m->m_next;
+ }
+ return 0;
+}
+
+/*
+ * Concatenate mbuf chain n to m.
+ * Both chains must be of the same type (e.g. MT_DATA).
+ * Any m_pkthdr is not updated.
+ */
+void
+m_cat(struct mbuf *m, struct mbuf *n)
+{
+ while (m->m_next)
+ m = m->m_next;
+ while (n) {
+ if (m->m_flags & M_EXT ||
+ m->m_data + m->m_len + n->m_len >= &m->m_dat[MLEN]) {
+ /* just join the two chains */
+ m->m_next = n;
+ return;
+ }
+ /* splat the data from one into the other */
+ bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len,
+ (u_int)n->m_len);
+ m->m_len += n->m_len;
+ n = m_free(n);
+ }
+}
+
+void
+m_adj(struct mbuf *mp, int req_len)
+{
+ int len = req_len;
+ struct mbuf *m;
+ int count;
+
+ if ((m = mp) == NULL)
+ return;
+ if (len >= 0) {
+ /*
+ * Trim from head.
+ */
+ while (m != NULL && len > 0) {
+ if (m->m_len <= len) {
+ len -= m->m_len;
+ m->m_len = 0;
+ m = m->m_next;
+ } else {
+ m->m_len -= len;
+ m->m_data += len;
+ len = 0;
+ }
+ }
+ m = mp;
+ if (mp->m_flags & M_PKTHDR)
+ m->m_pkthdr.len -= (req_len - len);
+ } else {
+ /*
+ * Trim from tail. Scan the mbuf chain,
+ * calculating its length and finding the last mbuf.
+ * If the adjustment only affects this mbuf, then just
+ * adjust and return. Otherwise, rescan and truncate
+ * after the remaining size.
+ */
+ len = -len;
+ count = 0;
+ for (;;) {
+ count += m->m_len;
+ if (m->m_next == (struct mbuf *)0)
+ break;
+ m = m->m_next;
+ }
+ if (m->m_len >= len) {
+ m->m_len -= len;
+ if (mp->m_flags & M_PKTHDR)
+ mp->m_pkthdr.len -= len;
+ return;
+ }
+ count -= len;
+ if (count < 0)
+ count = 0;
+ /*
+ * Correct length for chain is "count".
+ * Find the mbuf with last data, adjust its length,
+ * and toss data from remaining mbufs on chain.
+ */
+ m = mp;
+ if (m->m_flags & M_PKTHDR)
+ m->m_pkthdr.len = count;
+ for (; m; m = m->m_next) {
+ if (m->m_len >= count) {
+ m->m_len = count;
+ break;
+ }
+ count -= m->m_len;
+ }
+ while (m->m_next)
+ (m = m->m_next) ->m_len = 0;
+ }
+}
+
+/*
+ * Rearange an mbuf chain so that len bytes are contiguous
+ * and in the data area of an mbuf (so that mtod and dtom
+ * will work for a structure of size len). Returns the resulting
+ * mbuf chain on success, frees it and returns null on failure.
+ * If there is room, it will add up to max_protohdr-len extra bytes to the
+ * contiguous region in an attempt to avoid being called next time.
+ */
+static int MPFail;
+
+struct mbuf *
+m_pullup(struct mbuf *n, int len)
+{
+ struct mbuf *m;
+ int count;
+ int space;
+
+ /*
+ * If first mbuf has no cluster, and has room for len bytes
+ * without shifting current data, pullup into it,
+ * otherwise allocate a new mbuf to prepend to the chain.
+ */
+ if ((n->m_flags & M_EXT) == 0 &&
+ n->m_data + len < &n->m_dat[MLEN] && n->m_next) {
+ if (n->m_len >= len)
+ return (n);
+ m = n;
+ n = n->m_next;
+ len -= m->m_len;
+ } else {
+ if (len > MHLEN)
+ goto bad;
+ MGET(m, M_DONTWAIT, n->m_type);
+ if (m == NULL)
+ goto bad;
+ m->m_len = 0;
+ if (n->m_flags & M_PKTHDR) {
+ M_COPY_PKTHDR(m, n);
+ n->m_flags &= ~M_PKTHDR;
+ }
+ }
+ space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
+ do {
+ count = min(min(max(len, max_protohdr), space), n->m_len);
+ bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len,
+ (unsigned)count);
+ len -= count;
+ m->m_len += count;
+ n->m_len -= count;
+ space -= count;
+ if (n->m_len)
+ n->m_data += count;
+ else
+ n = m_free(n);
+ } while (len > 0 && n);
+ if (len > 0) {
+ (void) m_free(m);
+ goto bad;
+ }
+ m->m_next = n;
+ return (m);
+ bad:
+ m_freem(n);
+ MPFail++;
+ return (NULL);
+}
+
+/*
+ * Partition an mbuf chain in two pieces, returning the tail --
+ * all but the first len0 bytes. In case of failure, it returns NULL and
+ * attempts to restore the chain to its original state.
+ */
+struct mbuf *
+m_split(struct mbuf *m0, int len0, int wait)
+{
+ struct mbuf *m, *n;
+ u_int len = len0, remain;
+
+ for (m = m0; m && len > m->m_len; m = m->m_next)
+ len -= m->m_len;
+ if (m == NULL)
+ return (NULL);
+ remain = m->m_len - len;
+ if (m0->m_flags & M_PKTHDR) {
+ MGETHDR(n, wait, m0->m_type);
+ if (n == NULL)
+ return (NULL);
+ n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif;
+ n->m_pkthdr.len = m0->m_pkthdr.len - len0;
+ m0->m_pkthdr.len = len0;
+ if (m->m_flags & M_EXT)
+ goto extpacket;
+ if (remain > MHLEN) {
+ /* m can't be the lead packet */
+ MH_ALIGN(n, 0);
+ n->m_next = m_split(m, len, wait);
+ if (n->m_next == 0) {
+ (void) m_free(n);
+ return (0);
+ } else
+ return (n);
+ } else
+ MH_ALIGN(n, remain);
+ } else if (remain == 0) {
+ n = m->m_next;
+ m->m_next = NULL;
+ return (n);
+ } else {
+ MGET(n, wait, m->m_type);
+ if (n == 0)
+ return (0);
+ M_ALIGN(n, remain);
+ }
+extpacket:
+ if (m->m_flags & M_EXT) {
+ n->m_flags |= M_EXT;
+ n->m_ext = m->m_ext;
+ if(!m->m_ext.ext_ref)
+ mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
+ else
+ (*(m->m_ext.ext_ref))(m->m_ext.ext_buf,
+ m->m_ext.ext_size);
+ m->m_ext.ext_size = 0; /* For Accounting XXXXXX danger */
+ n->m_data = m->m_data + len;
+ } else {
+ bcopy(mtod(m, caddr_t) + len, mtod(n, caddr_t), remain);
+ }
+ n->m_len = remain;
+ m->m_len = len;
+ n->m_next = m->m_next;
+ m->m_next = NULL;
+ return (n);
+}
+/*
+ * Routine to copy from device local memory into mbufs.
+ */
+struct mbuf *
+m_devget(char *buf, int totlen, int off0, struct ifnet *ifp,
+ void (*copy)(char *from, caddr_t to, u_int len))
+{
+ struct mbuf *m;
+ struct mbuf *top = NULL, **mp = &top;
+ int len;
+ int off = off0;
+ char *cp;
+ char *epkt;
+
+ cp = buf;
+ epkt = cp + totlen;
+ if (off) {
+ cp += off + 2 * sizeof(u_short);
+ totlen -= 2 * sizeof(u_short);
+ }
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == 0)
+ return (0);
+ m->m_pkthdr.rcvif = ifp;
+ m->m_pkthdr.len = totlen;
+ m->m_len = MHLEN;
+
+ while (totlen > 0) {
+ if (top) {
+ MGET(m, M_DONTWAIT, MT_DATA);
+ if (m == 0) {
+ m_freem(top);
+ return (0);
+ }
+ m->m_len = MLEN;
+ }
+ len = min(totlen, epkt - cp);
+ if (len >= MINCLSIZE) {
+ MCLGET(m, M_DONTWAIT);
+ if (m->m_flags & M_EXT)
+ m->m_len = len = min(len, MCLBYTES);
+ else
+ len = m->m_len;
+ } else {
+ /*
+ * Place initial small packet/header at end of mbuf.
+ */
+ if (len < m->m_len) {
+ if (top == 0 && len + max_linkhdr <= m->m_len)
+ m->m_data += max_linkhdr;
+ m->m_len = len;
+ } else
+ len = m->m_len;
+ }
+ if (copy)
+ copy(cp, mtod(m, caddr_t), (u_int)len);
+ else
+ bcopy(cp, mtod(m, caddr_t), (u_int)len);
+ cp += len;
+ *mp = m;
+ mp = &m->m_next;
+ totlen -= len;
+ if (cp == epkt)
+ cp = buf;
+ }
+ return (top);
+}
+
+/*
+ * Copy data from a buffer back into the indicated mbuf chain,
+ * starting "off" bytes from the beginning, extending the mbuf
+ * chain if necessary.
+ */
+int
+m_copyback(struct mbuf *m0, int off, int len, caddr_t cp)
+{
+ int mlen;
+ struct mbuf *m = m0, *n;
+ int totlen = 0;
+
+ if (m0 == NULL)
+ return 0;
+ while (off > (mlen = m->m_len)) {
+ off -= mlen;
+ totlen += mlen;
+ if (m->m_next == NULL) {
+ n = m_getclr(M_DONTWAIT, m->m_type);
+ if (n == NULL) {
+ /*panic("m_copyback() : malformed chain\n");*/
+ return -1;
+ }
+ n->m_len = min(MLEN, len + off);
+ m->m_next = n;
+ }
+ m = m->m_next;
+ }
+ while (len > 0) {
+ mlen = min (m->m_len - off, len);
+ bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen);
+ cp += mlen;
+ len -= mlen;
+ mlen += off;
+ off = 0;
+ totlen += mlen;
+ if (len == 0) {
+ /* m->m_len = mlen; */
+ break;
+ }
+ if (m->m_next == NULL) {
+ n = m_get(M_DONTWAIT, m->m_type);
+ if (n == 0) {
+ /*panic("m_copyback() : malformed chain 2\n");*/
+ return -1;
+ };
+ n->m_len = min(MLEN, len);
+ m->m_next = n;
+ }
+ /* m->m_len = mlen; */
+ m = m->m_next;
+ }
+/*out:*/
+ if (((m = m0)->m_flags & M_PKTHDR) && (m->m_pkthdr.len < totlen))
+ m->m_pkthdr.len = totlen;
+ return 0;
+}
diff --git a/cpukit/libnetworking/kern/uipc_socket.c b/cpukit/libnetworking/kern/uipc_socket.c
new file mode 100644
index 0000000000..47fe7194fd
--- /dev/null
+++ b/cpukit/libnetworking/kern/uipc_socket.c
@@ -0,0 +1,1104 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/file.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/domain.h>
+#include <sys/kernel.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/resourcevar.h>
+#include <sys/signalvar.h>
+#include <sys/sysctl.h>
+#include <limits.h>
+
+static int somaxconn = SOMAXCONN;
+SYSCTL_INT(_kern, KIPC_SOMAXCONN, somaxconn, CTLFLAG_RW, &somaxconn, 0, "");
+
+/*
+ * Socket operation routines.
+ * These routines are called by the routines in
+ * sys_socket.c or from a system process, and
+ * implement the semantics of socket operations by
+ * switching out to the protocol specific routines.
+ */
+/*ARGSUSED*/
+int
+socreate(int dom, struct socket **aso, int type, int proto,
+ struct proc *p)
+{
+ register struct protosw *prp;
+ register struct socket *so;
+ register int error;
+
+ if (proto)
+ prp = pffindproto(dom, proto, type);
+ else
+ prp = pffindtype(dom, type);
+ if (prp == 0 || prp->pr_usrreqs == 0)
+ return (EPROTONOSUPPORT);
+ if (prp->pr_type != type)
+ return (EPROTOTYPE);
+ MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT);
+ bzero((caddr_t)so, sizeof(*so));
+ TAILQ_INIT(&so->so_incomp);
+ TAILQ_INIT(&so->so_comp);
+ so->so_type = type;
+ so->so_state = SS_PRIV;
+ so->so_uid = 0;
+ so->so_proto = prp;
+ error = (*prp->pr_usrreqs->pru_attach)(so, proto);
+ if (error) {
+ so->so_state |= SS_NOFDREF;
+ sofree(so);
+ return (error);
+ }
+ *aso = so;
+ return (0);
+}
+
+int
+sobind(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error;
+
+ error = (*so->so_proto->pr_usrreqs->pru_bind)(so, nam);
+ splx(s);
+ return (error);
+}
+
+int
+solisten(struct socket *so, int backlog)
+{
+ int s = splnet(), error;
+
+ error = (*so->so_proto->pr_usrreqs->pru_listen)(so);
+ if (error) {
+ splx(s);
+ return (error);
+ }
+ if (so->so_comp.tqh_first == NULL)
+ so->so_options |= SO_ACCEPTCONN;
+ if (backlog < 0 || backlog > somaxconn)
+ backlog = somaxconn;
+ so->so_qlimit = backlog;
+ splx(s);
+ return (0);
+}
+
+void
+sofree(struct socket *so)
+{
+ struct socket *head = so->so_head;
+
+ if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0)
+ return;
+ if (head != NULL) {
+ if (so->so_state & SS_INCOMP) {
+ TAILQ_REMOVE(&head->so_incomp, so, so_list);
+ head->so_incqlen--;
+ } else if (so->so_state & SS_COMP) {
+ TAILQ_REMOVE(&head->so_comp, so, so_list);
+ } else {
+ panic("sofree: not queued");
+ }
+ head->so_qlen--;
+ so->so_state &= ~(SS_INCOMP|SS_COMP);
+ so->so_head = NULL;
+ }
+ sbrelease(&so->so_snd);
+ sorflush(so);
+ FREE(so, M_SOCKET);
+}
+
+/*
+ * Close a socket on last file table reference removal.
+ * Initiate disconnect if connected.
+ * Free socket when disconnect complete.
+ */
+int
+soclose(struct socket *so)
+{
+ int s = splnet(); /* conservative */
+ int error = 0;
+
+ if (so->so_options & SO_ACCEPTCONN) {
+ struct socket *sp, *sonext;
+
+ for (sp = so->so_incomp.tqh_first; sp != NULL; sp = sonext) {
+ sonext = sp->so_list.tqe_next;
+ (void) soabort(sp);
+ }
+ for (sp = so->so_comp.tqh_first; sp != NULL; sp = sonext) {
+ sonext = sp->so_list.tqe_next;
+ (void) soabort(sp);
+ }
+ }
+ if (so->so_pcb == 0)
+ goto discard;
+ if (so->so_state & SS_ISCONNECTED) {
+ if ((so->so_state & SS_ISDISCONNECTING) == 0) {
+ error = sodisconnect(so);
+ if (error)
+ goto drop;
+ }
+ if (so->so_options & SO_LINGER) {
+ if ((so->so_state & SS_ISDISCONNECTING) &&
+ (so->so_state & SS_NBIO))
+ goto drop;
+ while (so->so_state & SS_ISCONNECTED) {
+ soconnsleep (so);
+ }
+ }
+ }
+drop:
+ if (so->so_pcb) {
+ int error2 = (*so->so_proto->pr_usrreqs->pru_detach)(so);
+ if (error == 0)
+ error = error2;
+ }
+discard:
+ if (so->so_state & SS_NOFDREF)
+ panic("soclose: NOFDREF");
+ so->so_state |= SS_NOFDREF;
+ sofree(so);
+ splx(s);
+ return (error);
+}
+
+/*
+ * Must be called at splnet...
+ */
+int
+soabort(struct socket *so)
+{
+
+ return (*so->so_proto->pr_usrreqs->pru_abort)(so);
+}
+
+int
+soaccept(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error;
+
+ if ((so->so_state & SS_NOFDREF) == 0)
+ panic("soaccept: !NOFDREF");
+ so->so_state &= ~SS_NOFDREF;
+ error = (*so->so_proto->pr_usrreqs->pru_accept)(so, nam);
+ splx(s);
+ return (error);
+}
+
+int
+soconnect(struct socket *so, struct mbuf *nam)
+{
+ int s;
+ int error;
+
+ if (so->so_options & SO_ACCEPTCONN)
+ return (EOPNOTSUPP);
+ s = splnet();
+ /*
+ * If protocol is connection-based, can only connect once.
+ * Otherwise, if connected, try to disconnect first.
+ * This allows user to disconnect by connecting to, e.g.,
+ * a null address.
+ */
+ if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
+ ((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
+ (error = sodisconnect(so))))
+ error = EISCONN;
+ else
+ error = (*so->so_proto->pr_usrreqs->pru_connect)(so, nam);
+ splx(s);
+ return (error);
+}
+
+int
+soconnect2(struct socket *so1,struct socket *so2)
+{
+ int s = splnet();
+ int error;
+
+ error = (*so1->so_proto->pr_usrreqs->pru_connect2)(so1, so2);
+ splx(s);
+ return (error);
+}
+
+int
+sodisconnect(struct socket *so)
+{
+ int s = splnet();
+ int error;
+
+ if ((so->so_state & SS_ISCONNECTED) == 0) {
+ error = ENOTCONN;
+ goto bad;
+ }
+ if (so->so_state & SS_ISDISCONNECTING) {
+ error = EALREADY;
+ goto bad;
+ }
+ error = (*so->so_proto->pr_usrreqs->pru_disconnect)(so);
+bad:
+ splx(s);
+ return (error);
+}
+
+#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
+/*
+ * Send on a socket.
+ * If send must go all at once and message is larger than
+ * send buffering, then hard error.
+ * Lock against other senders.
+ * If must go all at once and not enough room now, then
+ * inform user that this would block and do nothing.
+ * Otherwise, if nonblocking, send as much as possible.
+ * The data to be sent is described by "uio" if nonzero,
+ * otherwise by the mbuf chain "top" (which must be null
+ * if uio is not). Data provided in mbuf chain must be small
+ * enough to send all at once.
+ *
+ * Returns nonzero on error, timeout or signal; callers
+ * must check for short counts if EINTR/ERESTART are returned.
+ * Data and control buffers are freed on return.
+ */
+int
+sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
+ struct mbuf *top, struct mbuf *control, int flags)
+{
+ struct mbuf **mp;
+ register struct mbuf *m;
+ register long space, len, resid;
+ int clen = 0, error, s, dontroute, mlen;
+ int atomic = sosendallatonce(so) || top;
+
+ if (uio)
+ resid = uio->uio_resid;
+ else
+ resid = top->m_pkthdr.len;
+ /*
+ * In theory resid should be unsigned.
+ * However, space must be signed, as it might be less than 0
+ * if we over-committed, and we must use a signed comparison
+ * of space and resid. On the other hand, a negative resid
+ * causes us to loop sending 0-length segments to the protocol.
+ *
+ * Also check to make sure that MSG_EOR isn't used on SOCK_STREAM
+ * type sockets since that's an error.
+ */
+ if ((resid < 0) || (so->so_type == SOCK_STREAM && (flags & MSG_EOR))) {
+ error = EINVAL;
+ goto out;
+ }
+
+ dontroute =
+ (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
+ (so->so_proto->pr_flags & PR_ATOMIC);
+ if (control)
+ clen = control->m_len;
+#define snderr(errno) { error = errno; splx(s); goto release; }
+
+restart:
+ error = sblock(&so->so_snd, SBLOCKWAIT(flags));
+ if (error)
+ goto out;
+ do {
+ s = splnet();
+ if (so->so_state & SS_CANTSENDMORE)
+ snderr(EPIPE);
+ if (so->so_error) {
+ error = so->so_error;
+ so->so_error = 0;
+ splx(s);
+ goto release;
+ }
+ if ((so->so_state & SS_ISCONNECTED) == 0) {
+ /*
+ * `sendto' and `sendmsg' is allowed on a connection-
+ * based socket if it supports implied connect.
+ * Return ENOTCONN if not connected and no address is
+ * supplied.
+ */
+ if ((so->so_proto->pr_flags & PR_CONNREQUIRED) &&
+ (so->so_proto->pr_flags & PR_IMPLOPCL) == 0) {
+ if ((so->so_state & SS_ISCONFIRMING) == 0 &&
+ !(resid == 0 && clen != 0))
+ snderr(ENOTCONN);
+ } else if (addr == 0)
+ snderr(so->so_proto->pr_flags & PR_CONNREQUIRED ?
+ ENOTCONN : EDESTADDRREQ);
+ }
+ space = sbspace(&so->so_snd);
+ if (flags & MSG_OOB)
+ space += 1024;
+ if ((atomic && resid > so->so_snd.sb_hiwat) ||
+ clen > so->so_snd.sb_hiwat)
+ snderr(EMSGSIZE);
+ if (space < resid + clen && uio &&
+ (atomic || space < so->so_snd.sb_lowat || space < clen)) {
+ if (so->so_state & SS_NBIO)
+ snderr(EWOULDBLOCK);
+ sbunlock(&so->so_snd);
+ error = sbwait(&so->so_snd);
+ splx(s);
+ if (error)
+ goto out;
+ goto restart;
+ }
+ splx(s);
+ mp = &top;
+ space -= clen;
+ do {
+ if (uio == NULL) {
+ /*
+ * Data is prepackaged in "top".
+ */
+ resid = 0;
+ if (flags & MSG_EOR)
+ top->m_flags |= M_EOR;
+ } else do {
+ if (top == 0) {
+ MGETHDR(m, M_WAIT, MT_DATA);
+ mlen = MHLEN;
+ m->m_pkthdr.len = 0;
+ m->m_pkthdr.rcvif = (struct ifnet *)0;
+ } else {
+ MGET(m, M_WAIT, MT_DATA);
+ mlen = MLEN;
+ }
+ if (resid >= MINCLSIZE) {
+ MCLGET(m, M_WAIT);
+ if ((m->m_flags & M_EXT) == 0)
+ goto nopages;
+ mlen = MCLBYTES;
+ len = min(min(mlen, resid), space);
+ } else {
+nopages:
+ len = min(min(mlen, resid), space);
+ /*
+ * For datagram protocols, leave room
+ * for protocol headers in first mbuf.
+ */
+ if (atomic && top == 0 && len < mlen)
+ MH_ALIGN(m, len);
+ }
+ space -= len;
+ error = uiomove(mtod(m, caddr_t), (int)len, uio);
+ resid = uio->uio_resid;
+ m->m_len = len;
+ *mp = m;
+ top->m_pkthdr.len += len;
+ if (error)
+ goto release;
+ mp = &m->m_next;
+ if (resid <= 0) {
+ if (flags & MSG_EOR)
+ top->m_flags |= M_EOR;
+ break;
+ }
+ } while (space > 0 && atomic);
+ if (dontroute)
+ so->so_options |= SO_DONTROUTE;
+ s = splnet(); /* XXX */
+ error = (*so->so_proto->pr_usrreqs->pru_send)(so,
+ (flags & MSG_OOB) ? PRUS_OOB :
+ /*
+ * If the user set MSG_EOF, the protocol
+ * understands this flag and nothing left to
+ * send then use PRU_SEND_EOF instead of PRU_SEND.
+ */
+ ((flags & MSG_EOF) &&
+ (so->so_proto->pr_flags & PR_IMPLOPCL) &&
+ (resid <= 0)) ?
+ PRUS_EOF : 0,
+ top, addr, control);
+ splx(s);
+ if (dontroute)
+ so->so_options &= ~SO_DONTROUTE;
+ clen = 0;
+ control = 0;
+ top = 0;
+ mp = &top;
+ if (error)
+ goto release;
+ } while (resid && space > 0);
+ } while (resid);
+
+release:
+ sbunlock(&so->so_snd);
+out:
+ if (top)
+ m_freem(top);
+ if (control)
+ m_freem(control);
+ return (error);
+}
+
+/*
+ * Implement receive operations on a socket.
+ * We depend on the way that records are added to the sockbuf
+ * by sbappend*. In particular, each record (mbufs linked through m_next)
+ * must begin with an address if the protocol so specifies,
+ * followed by an optional mbuf or mbufs containing ancillary data,
+ * and then zero or more mbufs of data.
+ * In order to avoid blocking network interrupts for the entire time here,
+ * we splx() while doing the actual copy to user space.
+ * Although the sockbuf is locked, new data may still be appended,
+ * and thus we must maintain consistency of the sockbuf during that time.
+ *
+ * The caller may receive the data as a single mbuf chain by supplying
+ * an mbuf **mp0 for use in returning the chain. The uio is then used
+ * only for the count in uio_resid.
+ */
+int
+soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
+ struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
+{
+ register struct mbuf *m, **mp;
+ register int flags, len, error, s, offset;
+ struct protosw *pr = so->so_proto;
+ struct mbuf *nextrecord;
+ int moff, type = 0;
+ int orig_resid = uio->uio_resid;
+
+ mp = mp0;
+ if (paddr)
+ *paddr = 0;
+ if (controlp)
+ *controlp = 0;
+ if (flagsp)
+ flags = *flagsp &~ MSG_EOR;
+ else
+ flags = 0;
+ if (flags & MSG_OOB) {
+ m = m_get(M_WAIT, MT_DATA);
+ error = (*pr->pr_usrreqs->pru_rcvoob)(so, m, flags & MSG_PEEK);
+ if (error)
+ goto bad;
+ do {
+ error = uiomove(mtod(m, caddr_t),
+ (int) min(uio->uio_resid, m->m_len), uio);
+ m = m_free(m);
+ } while (uio->uio_resid && error == 0 && m);
+bad:
+ if (m)
+ m_freem(m);
+ return (error);
+ }
+ if (mp)
+ *mp = (struct mbuf *)0;
+ if (so->so_state & SS_ISCONFIRMING && uio->uio_resid)
+ (*pr->pr_usrreqs->pru_rcvd)(so, 0);
+
+restart:
+ error = sblock(&so->so_rcv, SBLOCKWAIT(flags));
+ if (error)
+ return (error);
+ s = splnet();
+
+ m = so->so_rcv.sb_mb;
+ /*
+ * If we have less data than requested, block awaiting more
+ * (subject to any timeout) if:
+ * 1. the current count is less than the low water mark, or
+ * 2. MSG_WAITALL is set, and it is possible to do the entire
+ * receive operation at once if we block (resid <= hiwat).
+ * 3. MSG_DONTWAIT is not set
+ * If MSG_WAITALL is set but resid is larger than the receive buffer,
+ * we have to do the receive in sections, and thus risk returning
+ * a short count if a timeout or signal occurs after we start.
+ */
+ if (m == 0 || (((flags & MSG_DONTWAIT) == 0 &&
+ so->so_rcv.sb_cc < uio->uio_resid) &&
+ (so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||
+ ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&
+ m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) {
+#ifdef DIAGNOSTIC
+ if (m == 0 && so->so_rcv.sb_cc)
+ panic("receive 1");
+#endif
+ if (so->so_error) {
+ if (m)
+ goto dontblock;
+ error = so->so_error;
+ if ((flags & MSG_PEEK) == 0)
+ so->so_error = 0;
+ goto release;
+ }
+ if (so->so_state & SS_CANTRCVMORE) {
+ if (m)
+ goto dontblock;
+ else
+ goto release;
+ }
+ for (; m; m = m->m_next)
+ if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) {
+ m = so->so_rcv.sb_mb;
+ goto dontblock;
+ }
+ if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) == 0 &&
+ (so->so_proto->pr_flags & PR_CONNREQUIRED)) {
+ error = ENOTCONN;
+ goto release;
+ }
+ if (uio->uio_resid == 0)
+ goto release;
+ if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {
+ error = EWOULDBLOCK;
+ goto release;
+ }
+ sbunlock(&so->so_rcv);
+ error = sbwait(&so->so_rcv);
+ splx(s);
+ if (error)
+ return (error);
+ goto restart;
+ }
+dontblock:
+ nextrecord = m->m_nextpkt;
+ if (pr->pr_flags & PR_ADDR) {
+#ifdef DIAGNOSTIC
+ if (m->m_type != MT_SONAME)
+ panic("receive 1a");
+#endif
+ orig_resid = 0;
+ if (flags & MSG_PEEK) {
+ if (paddr)
+ *paddr = m_copy(m, 0, m->m_len);
+ m = m->m_next;
+ } else {
+ sbfree(&so->so_rcv, m);
+ if (paddr) {
+ *paddr = m;
+ so->so_rcv.sb_mb = m->m_next;
+ m->m_next = 0;
+ m = so->so_rcv.sb_mb;
+ } else {
+ MFREE(m, so->so_rcv.sb_mb);
+ m = so->so_rcv.sb_mb;
+ }
+ }
+ }
+ while (m && m->m_type == MT_CONTROL && error == 0) {
+ if (flags & MSG_PEEK) {
+ if (controlp)
+ *controlp = m_copy(m, 0, m->m_len);
+ m = m->m_next;
+ } else {
+ sbfree(&so->so_rcv, m);
+ if (controlp) {
+ if (pr->pr_domain->dom_externalize &&
+ mtod(m, struct cmsghdr *)->cmsg_type ==
+ SCM_RIGHTS)
+ error = (*pr->pr_domain->dom_externalize)(m);
+ *controlp = m;
+ so->so_rcv.sb_mb = m->m_next;
+ m->m_next = 0;
+ m = so->so_rcv.sb_mb;
+ } else {
+ MFREE(m, so->so_rcv.sb_mb);
+ m = so->so_rcv.sb_mb;
+ }
+ }
+ if (controlp) {
+ orig_resid = 0;
+ controlp = &(*controlp)->m_next;
+ }
+ }
+ if (m) {
+ if ((flags & MSG_PEEK) == 0)
+ m->m_nextpkt = nextrecord;
+ type = m->m_type;
+ if (type == MT_OOBDATA)
+ flags |= MSG_OOB;
+ }
+ moff = 0;
+ offset = 0;
+ while (m && uio->uio_resid > 0 && error == 0) {
+ if (m->m_type == MT_OOBDATA) {
+ if (type != MT_OOBDATA)
+ break;
+ } else if (type == MT_OOBDATA)
+ break;
+#ifdef DIAGNOSTIC
+ else if (m->m_type != MT_DATA && m->m_type != MT_HEADER)
+ panic("receive 3");
+#endif
+ so->so_state &= ~SS_RCVATMARK;
+ len = uio->uio_resid;
+ if (so->so_oobmark && len > so->so_oobmark - offset)
+ len = so->so_oobmark - offset;
+ if (len > m->m_len - moff)
+ len = m->m_len - moff;
+ /*
+ * If mp is set, just pass back the mbufs.
+ * Otherwise copy them out via the uio, then free.
+ * Sockbuf must be consistent here (points to current mbuf,
+ * it points to next record) when we drop priority;
+ * we must note any additions to the sockbuf when we
+ * block interrupts again.
+ */
+ if (mp == 0) {
+ splx(s);
+ error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio);
+ s = splnet();
+ if (error)
+ goto release;
+ } else
+ uio->uio_resid -= len;
+ if (len == m->m_len - moff) {
+ if (m->m_flags & M_EOR)
+ flags |= MSG_EOR;
+ if (flags & MSG_PEEK) {
+ m = m->m_next;
+ moff = 0;
+ } else {
+ nextrecord = m->m_nextpkt;
+ sbfree(&so->so_rcv, m);
+ if (mp) {
+ *mp = m;
+ mp = &m->m_next;
+ so->so_rcv.sb_mb = m = m->m_next;
+ *mp = (struct mbuf *)0;
+ } else {
+ MFREE(m, so->so_rcv.sb_mb);
+ m = so->so_rcv.sb_mb;
+ }
+ if (m)
+ m->m_nextpkt = nextrecord;
+ }
+ } else {
+ if (flags & MSG_PEEK)
+ moff += len;
+ else {
+ if (mp)
+ *mp = m_copym(m, 0, len, M_WAIT);
+ m->m_data += len;
+ m->m_len -= len;
+ so->so_rcv.sb_cc -= len;
+ }
+ }
+ if (so->so_oobmark) {
+ if ((flags & MSG_PEEK) == 0) {
+ so->so_oobmark -= len;
+ if (so->so_oobmark == 0) {
+ so->so_state |= SS_RCVATMARK;
+ break;
+ }
+ } else {
+ offset += len;
+ if (offset == so->so_oobmark)
+ break;
+ }
+ }
+ if (flags & MSG_EOR)
+ break;
+ /*
+ * If the MSG_WAITALL flag is set (for non-atomic socket),
+ * we must not quit until "uio->uio_resid == 0" or an error
+ * termination. If a signal/timeout occurs, return
+ * with a short count but without error.
+ * Keep sockbuf locked against other readers.
+ */
+ while (flags & MSG_WAITALL && m == 0 && uio->uio_resid > 0 &&
+ !sosendallatonce(so) && !nextrecord) {
+ if (so->so_error || so->so_state & SS_CANTRCVMORE)
+ break;
+ error = sbwait(&so->so_rcv);
+ if (error) {
+ sbunlock(&so->so_rcv);
+ splx(s);
+ return (0);
+ }
+ m = so->so_rcv.sb_mb;
+ if (m)
+ nextrecord = m->m_nextpkt;
+ }
+ }
+
+ if (m && pr->pr_flags & PR_ATOMIC) {
+ flags |= MSG_TRUNC;
+ if ((flags & MSG_PEEK) == 0)
+ (void) sbdroprecord(&so->so_rcv);
+ }
+ if ((flags & MSG_PEEK) == 0) {
+ if (m == 0)
+ so->so_rcv.sb_mb = nextrecord;
+ if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
+ (*pr->pr_usrreqs->pru_rcvd)(so, flags);
+ }
+ if (orig_resid == uio->uio_resid && orig_resid &&
+ (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
+ sbunlock(&so->so_rcv);
+ splx(s);
+ goto restart;
+ }
+
+ if (flagsp)
+ *flagsp |= flags;
+release:
+ sbunlock(&so->so_rcv);
+ splx(s);
+ return (error);
+}
+
+int
+soshutdown(struct socket *so, int how )
+{
+ register struct protosw *pr = so->so_proto;
+
+ how++;
+ if (how & FREAD)
+ sorflush(so);
+ if (how & FWRITE)
+ return ((*pr->pr_usrreqs->pru_shutdown)(so));
+ return (0);
+}
+
+void
+sorflush(struct socket *so)
+{
+ register struct sockbuf *sb = &so->so_rcv;
+ register struct protosw *pr = so->so_proto;
+ register int s;
+ struct sockbuf asb;
+
+ sb->sb_flags |= SB_NOINTR;
+ (void) sblock(sb, M_WAITOK);
+ s = splimp();
+ socantrcvmore(so);
+ sbunlock(sb);
+ asb = *sb;
+ bzero((caddr_t)sb, sizeof (*sb));
+ splx(s);
+ if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
+ (*pr->pr_domain->dom_dispose)(asb.sb_mb);
+ sbrelease(&asb);
+}
+
+int
+sosetopt(struct socket *so, int level, int optname, struct mbuf *m0)
+{
+ int error = 0;
+ register struct mbuf *m = m0;
+
+ if (level != SOL_SOCKET) {
+ if (so->so_proto && so->so_proto->pr_ctloutput)
+ return ((*so->so_proto->pr_ctloutput)
+ (PRCO_SETOPT, so, level, optname, &m0));
+ error = ENOPROTOOPT;
+ } else {
+ switch (optname) {
+
+ case SO_LINGER:
+ if (m == NULL || m->m_len != sizeof (struct linger)) {
+ error = EINVAL;
+ goto bad;
+ }
+ so->so_linger = mtod(m, struct linger *)->l_linger;
+ /* fall thru... */
+
+ case SO_DEBUG:
+ case SO_KEEPALIVE:
+ case SO_DONTROUTE:
+ case SO_USELOOPBACK:
+ case SO_BROADCAST:
+ case SO_REUSEADDR:
+ case SO_REUSEPORT:
+ case SO_OOBINLINE:
+ case SO_TIMESTAMP:
+ if (m == NULL || m->m_len < sizeof (int)) {
+ error = EINVAL;
+ goto bad;
+ }
+ if (*mtod(m, int *))
+ so->so_options |= optname;
+ else
+ so->so_options &= ~optname;
+ break;
+
+ case SO_SNDBUF:
+ case SO_RCVBUF:
+ case SO_SNDLOWAT:
+ case SO_RCVLOWAT:
+ {
+ int optval;
+
+ if (m == NULL || m->m_len < sizeof (int)) {
+ error = EINVAL;
+ goto bad;
+ }
+
+ /*
+ * Values < 1 make no sense for any of these
+ * options, so disallow them.
+ */
+ optval = *mtod(m, int *);
+ if (optval < 1) {
+ error = EINVAL;
+ goto bad;
+ }
+
+ switch (optname) {
+
+ case SO_SNDBUF:
+ case SO_RCVBUF:
+ if (sbreserve(optname == SO_SNDBUF ?
+ &so->so_snd : &so->so_rcv,
+ (u_long) optval) == 0) {
+ error = ENOBUFS;
+ goto bad;
+ }
+ break;
+
+ /*
+ * Make sure the low-water is never greater than
+ * the high-water.
+ */
+ case SO_SNDLOWAT:
+ so->so_snd.sb_lowat =
+ (optval > so->so_snd.sb_hiwat) ?
+ so->so_snd.sb_hiwat : optval;
+ break;
+ case SO_RCVLOWAT:
+ so->so_rcv.sb_lowat =
+ (optval > so->so_rcv.sb_hiwat) ?
+ so->so_rcv.sb_hiwat : optval;
+ break;
+ }
+ break;
+ }
+
+ case SO_SNDTIMEO:
+ case SO_RCVTIMEO:
+ {
+ struct timeval *tv;
+ unsigned long val;
+
+ if (m == NULL || m->m_len < sizeof (*tv)) {
+ error = EINVAL;
+ goto bad;
+ }
+ tv = mtod(m, struct timeval *);
+ if (tv->tv_sec >= (ULONG_MAX - hz) / hz) {
+ error = EDOM;
+ goto bad;
+ }
+
+ val = tv->tv_sec * hz + tv->tv_usec / tick;
+ if ((val == 0) && (tv->tv_sec || tv->tv_usec))
+ val = 1;
+
+ switch (optname) {
+
+ case SO_SNDTIMEO:
+ so->so_snd.sb_timeo = val;
+ break;
+ case SO_RCVTIMEO:
+ so->so_rcv.sb_timeo = val;
+ break;
+ }
+ break;
+ }
+
+ case SO_PRIVSTATE:
+ /* we don't care what the parameter is... */
+ so->so_state &= ~SS_PRIV;
+ break;
+
+ case SO_SNDWAKEUP:
+ case SO_RCVWAKEUP:
+ {
+ /* RTEMS addition. */
+ struct sockwakeup *sw;
+ struct sockbuf *sb;
+
+ if (m == NULL
+ || m->m_len != sizeof (struct sockwakeup)) {
+ error = EINVAL;
+ goto bad;
+ }
+ sw = mtod(m, struct sockwakeup *);
+ sb = (optname == SO_SNDWAKEUP
+ ? &so->so_snd
+ : &so->so_rcv);
+ sb->sb_wakeup = sw->sw_pfn;
+ sb->sb_wakeuparg = sw->sw_arg;
+ if (sw->sw_pfn)
+ sb->sb_flags |= SB_ASYNC;
+ else
+ sb->sb_flags &=~ SB_ASYNC;
+ break;
+ }
+
+ default:
+ error = ENOPROTOOPT;
+ break;
+ }
+ if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
+ (void) ((*so->so_proto->pr_ctloutput)
+ (PRCO_SETOPT, so, level, optname, &m0));
+ m = NULL; /* freed by protocol */
+ }
+ }
+bad:
+ if (m)
+ (void) m_free(m);
+ return (error);
+}
+
+int
+sogetopt(struct socket *so, int level, int optname, struct mbuf **mp)
+{
+ register struct mbuf *m;
+
+ if (level != SOL_SOCKET) {
+ if (so->so_proto && so->so_proto->pr_ctloutput) {
+ return ((*so->so_proto->pr_ctloutput)
+ (PRCO_GETOPT, so, level, optname, mp));
+ } else
+ return (ENOPROTOOPT);
+ } else {
+ m = m_get(M_WAIT, MT_SOOPTS);
+ m->m_len = sizeof (int);
+
+ switch (optname) {
+
+ case SO_LINGER:
+ m->m_len = sizeof (struct linger);
+ mtod(m, struct linger *)->l_onoff =
+ so->so_options & SO_LINGER;
+ mtod(m, struct linger *)->l_linger = so->so_linger;
+ break;
+
+ case SO_USELOOPBACK:
+ case SO_DONTROUTE:
+ case SO_DEBUG:
+ case SO_KEEPALIVE:
+ case SO_REUSEADDR:
+ case SO_REUSEPORT:
+ case SO_BROADCAST:
+ case SO_OOBINLINE:
+ case SO_TIMESTAMP:
+ *mtod(m, int *) = so->so_options & optname;
+ break;
+
+ case SO_PRIVSTATE:
+ *mtod(m, int *) = so->so_state & SS_PRIV;
+ break;
+
+ case SO_TYPE:
+ *mtod(m, int *) = so->so_type;
+ break;
+
+ case SO_ERROR:
+ *mtod(m, int *) = so->so_error;
+ so->so_error = 0;
+ break;
+
+ case SO_SNDBUF:
+ *mtod(m, int *) = so->so_snd.sb_hiwat;
+ break;
+
+ case SO_RCVBUF:
+ *mtod(m, int *) = so->so_rcv.sb_hiwat;
+ break;
+
+ case SO_SNDLOWAT:
+ *mtod(m, int *) = so->so_snd.sb_lowat;
+ break;
+
+ case SO_RCVLOWAT:
+ *mtod(m, int *) = so->so_rcv.sb_lowat;
+ break;
+
+ case SO_SNDTIMEO:
+ case SO_RCVTIMEO:
+ {
+ unsigned long val = (optname == SO_SNDTIMEO ?
+ so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
+
+ m->m_len = sizeof(struct timeval);
+ mtod(m, struct timeval *)->tv_sec = val / hz;
+ mtod(m, struct timeval *)->tv_usec =
+ (val % hz) * tick;
+ break;
+ }
+
+ case SO_SNDWAKEUP:
+ case SO_RCVWAKEUP:
+ {
+ struct sockbuf *sb;
+ struct sockwakeup *sw;
+
+ /* RTEMS additions. */
+ sb = (optname == SO_SNDWAKEUP
+ ? &so->so_snd
+ : &so->so_rcv);
+ m->m_len = sizeof (struct sockwakeup);
+ sw = mtod(m, struct sockwakeup *);
+ sw->sw_pfn = sb->sb_wakeup;
+ sw->sw_arg = sb->sb_wakeuparg;
+ break;
+ }
+
+ default:
+ (void)m_free(m);
+ return (ENOPROTOOPT);
+ }
+ *mp = m;
+ return (0);
+ }
+}
+
+void
+sohasoutofband(struct socket *so)
+{
+#if 0 /* FIXME: For now we just ignore out of band data */
+ struct proc *p;
+
+ if (so->so_pgid < 0)
+ gsignal(-so->so_pgid, SIGURG);
+ else if (so->so_pgid > 0 && (p = pfind(so->so_pgid)) != 0)
+ psignal(p, SIGURG);
+ selwakeup(&so->so_rcv.sb_sel);
+#endif
+}
diff --git a/cpukit/libnetworking/kern/uipc_socket2.c b/cpukit/libnetworking/kern/uipc_socket2.c
new file mode 100644
index 0000000000..fa5487fd84
--- /dev/null
+++ b/cpukit/libnetworking/kern/uipc_socket2.c
@@ -0,0 +1,940 @@
+/*
+ * This file has undergone several changes to reflect the
+ * differences between the RTEMS and FreeBSD kernels.
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/file.h>
+#include <sys/queue.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/signalvar.h>
+#include <sys/sysctl.h>
+
+/*
+ * Primitive routines for operating on sockets and socket buffers
+ */
+
+u_long sb_max = SB_MAX; /* XXX should be static */
+SYSCTL_INT(_kern, KIPC_MAXSOCKBUF, maxsockbuf, CTLFLAG_RW, &sb_max, 0, "");
+
+static u_long sb_efficiency = 8; /* parameter for sbreserve() */
+SYSCTL_INT(_kern, OID_AUTO, sockbuf_waste_factor, CTLFLAG_RW, &sb_efficiency,
+ 0, "");
+
+#if defined(__rtems__)
+ void rtems_set_sb_efficiency(
+ u_long efficiency
+ )
+ {
+ sb_efficiency = (efficiency == 0) ? 2 : efficiency;
+ }
+#endif
+
+/*
+ * Procedures to manipulate state flags of socket
+ * and do appropriate wakeups. Normal sequence from the
+ * active (originating) side is that soisconnecting() is
+ * called during processing of connect() call,
+ * resulting in an eventual call to soisconnected() if/when the
+ * connection is established. When the connection is torn down
+ * soisdisconnecting() is called during processing of disconnect() call,
+ * and soisdisconnected() is called when the connection to the peer
+ * is totally severed. The semantics of these routines are such that
+ * connectionless protocols can call soisconnected() and soisdisconnected()
+ * only, bypassing the in-progress calls when setting up a ``connection''
+ * takes no time.
+ *
+ * From the passive side, a socket is created with
+ * two queues of sockets: so_q0 for connections in progress
+ * and so_q for connections already made and awaiting user acceptance.
+ * As a protocol is preparing incoming connections, it creates a socket
+ * structure queued on so_q0 by calling sonewconn(). When the connection
+ * is established, soisconnected() is called, and transfers the
+ * socket structure to so_q, making it available to accept().
+ *
+ * If a socket is closed with sockets on either
+ * so_q0 or so_q, these sockets are dropped.
+ *
+ * If higher level protocols are implemented in
+ * the kernel, the wakeups done here will sometimes
+ * cause software-interrupt process scheduling.
+ */
+
+void
+soisconnecting(struct socket *so)
+{
+
+ so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING);
+ so->so_state |= SS_ISCONNECTING;
+}
+
+void
+soisconnected(struct socket *so)
+{
+ register struct socket *head = so->so_head;
+
+ so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
+ so->so_state |= SS_ISCONNECTED;
+ if (head && (so->so_state & SS_INCOMP)) {
+ TAILQ_REMOVE(&head->so_incomp, so, so_list);
+ head->so_incqlen--;
+ so->so_state &= ~SS_INCOMP;
+ TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
+ so->so_state |= SS_COMP;
+ sorwakeup(head);
+ soconnwakeup(head);
+ } else {
+ soconnwakeup(so);
+ sorwakeup(so);
+ sowwakeup(so);
+ }
+}
+
+void
+soisdisconnecting(struct socket *so)
+{
+
+ so->so_state &= ~SS_ISCONNECTING;
+ so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
+ soconnwakeup(so);
+ sowwakeup(so);
+ sorwakeup(so);
+}
+
+void
+soisdisconnected(struct socket *so)
+{
+
+ so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
+ so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE);
+ soconnwakeup(so);
+ sowwakeup(so);
+ sorwakeup(so);
+}
+
+/*
+ * Return a random connection that hasn't been serviced yet and
+ * is eligible for discard. There is a one in qlen chance that
+ * we will return a null, saying that there are no dropable
+ * requests. In this case, the protocol specific code should drop
+ * the new request. This insures fairness.
+ *
+ * This may be used in conjunction with protocol specific queue
+ * congestion routines.
+ */
+struct socket *
+sodropablereq(struct socket *head)
+{
+ register struct socket *so;
+ uint32_t i, j, qlen, m;
+
+ static int rnd;
+ static long old_mono_secs;
+ static unsigned int cur_cnt, old_cnt;
+
+ if ((i = (m = rtems_bsdnet_seconds_since_boot()) - old_mono_secs) != 0) {
+ old_mono_secs = m;
+ old_cnt = cur_cnt / i;
+ cur_cnt = 0;
+ }
+
+ so = TAILQ_FIRST(&head->so_incomp);
+ if (!so)
+ return (so);
+
+ qlen = head->so_incqlen;
+ if (++cur_cnt > qlen || old_cnt > qlen) {
+ rnd = (314159 * rnd + 66329) & 0xffff;
+ j = ((qlen + 1) * rnd) >> 16;
+
+ while (j-- && so)
+ so = TAILQ_NEXT(so, so_list);
+ }
+
+ return (so);
+}
+
+/*
+ * When an attempt at a new connection is noted on a socket
+ * which accepts connections, sonewconn is called. If the
+ * connection is possible (subject to space constraints, etc.)
+ * then we allocate a new structure, propoerly linked into the
+ * data structure of the original socket, and return this.
+ * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED.
+ *
+ * Currently, sonewconn() is defined as sonewconn1() in socketvar.h
+ * to catch calls that are missing the (new) second parameter.
+ */
+struct socket *
+sonewconn1(struct socket *head, int connstatus)
+{
+ register struct socket *so;
+
+ if (head->so_qlen > 3 * head->so_qlimit / 2)
+ return ((struct socket *)0);
+ MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT);
+ if (so == NULL)
+ return ((struct socket *)0);
+ bzero((caddr_t)so, sizeof(*so));
+ so->so_head = head;
+ so->so_type = head->so_type;
+ so->so_options = head->so_options &~ SO_ACCEPTCONN;
+ so->so_linger = head->so_linger;
+ so->so_state = head->so_state | SS_NOFDREF;
+ so->so_proto = head->so_proto;
+ so->so_timeo = head->so_timeo;
+ so->so_pgid = head->so_pgid;
+ so->so_uid = head->so_uid;
+ (void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat);
+ if (connstatus) {
+ TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
+ so->so_state |= SS_COMP;
+ } else {
+ TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
+ so->so_state |= SS_INCOMP;
+ head->so_incqlen++;
+ }
+ head->so_qlen++;
+ if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0)) {
+ if (so->so_state & SS_COMP) {
+ TAILQ_REMOVE(&head->so_comp, so, so_list);
+ } else {
+ TAILQ_REMOVE(&head->so_incomp, so, so_list);
+ head->so_incqlen--;
+ }
+ head->so_qlen--;
+ (void) free((caddr_t)so, M_SOCKET);
+ return ((struct socket *)0);
+ }
+ if (connstatus) {
+ sorwakeup(head);
+ soconnwakeup(head);
+ so->so_state |= connstatus;
+ }
+ return (so);
+}
+
+/*
+ * Socantsendmore indicates that no more data will be sent on the
+ * socket; it would normally be applied to a socket when the user
+ * informs the system that no more data is to be sent, by the protocol
+ * code (in case PRU_SHUTDOWN). Socantrcvmore indicates that no more data
+ * will be received, and will normally be applied to the socket by a
+ * protocol when it detects that the peer will send no more data.
+ * Data queued for reading in the socket may yet be read.
+ */
+
+void
+socantsendmore(struct socket *so)
+{
+
+ so->so_state |= SS_CANTSENDMORE;
+ sowwakeup(so);
+}
+
+void
+socantrcvmore(struct socket *so)
+{
+
+ so->so_state |= SS_CANTRCVMORE;
+ sorwakeup(so);
+}
+
+/*
+ * Socket buffer (struct sockbuf) utility routines.
+ *
+ * Each socket contains two socket buffers: one for sending data and
+ * one for receiving data. Each buffer contains a queue of mbufs,
+ * information about the number of mbufs and amount of data in the
+ * queue, and other fields allowing select() statements and notification
+ * on data availability to be implemented.
+ *
+ * Data stored in a socket buffer is maintained as a list of records.
+ * Each record is a list of mbufs chained together with the m_next
+ * field. Records are chained together with the m_nextpkt field. The upper
+ * level routine soreceive() expects the following conventions to be
+ * observed when placing information in the receive buffer:
+ *
+ * 1. If the protocol requires each message be preceded by the sender's
+ * name, then a record containing that name must be present before
+ * any associated data (mbuf's must be of type MT_SONAME).
+ * 2. If the protocol supports the exchange of ``access rights'' (really
+ * just additional data associated with the message), and there are
+ * ``rights'' to be received, then a record containing this data
+ * should be present (mbuf's must be of type MT_RIGHTS).
+ * 3. If a name or rights record exists, then it must be followed by
+ * a data record, perhaps of zero length.
+ *
+ * Before using a new socket structure it is first necessary to reserve
+ * buffer space to the socket, by calling sbreserve(). This should commit
+ * some of the available buffer space in the system buffer pool for the
+ * socket (currently, it does nothing but enforce limits). The space
+ * should be released by calling sbrelease() when the socket is destroyed.
+ */
+
+int
+soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
+{
+
+ if (sbreserve(&so->so_snd, sndcc) == 0)
+ goto bad;
+ if (sbreserve(&so->so_rcv, rcvcc) == 0)
+ goto bad2;
+ if (so->so_rcv.sb_lowat == 0)
+ so->so_rcv.sb_lowat = 1;
+ if (so->so_snd.sb_lowat == 0)
+ so->so_snd.sb_lowat = MCLBYTES;
+ if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
+ so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
+ return (0);
+bad2:
+ sbrelease(&so->so_snd);
+bad:
+ return (ENOBUFS);
+}
+
+/*
+ * Allot mbufs to a sockbuf.
+ * Attempt to scale mbmax so that mbcnt doesn't become limiting
+ * if buffering efficiency is near the normal case.
+ */
+int
+sbreserve(struct sockbuf *sb, u_long cc)
+{
+
+ if (cc > sb_max * MCLBYTES / (MSIZE + MCLBYTES))
+ return (0);
+ sb->sb_hiwat = cc;
+ sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
+ if (sb->sb_lowat > sb->sb_hiwat)
+ sb->sb_lowat = sb->sb_hiwat;
+ return (1);
+}
+
+/*
+ * Free mbufs held by a socket, and reserved mbuf space.
+ */
+void
+sbrelease(struct sockbuf *sb)
+{
+
+ sbflush(sb);
+ sb->sb_hiwat = sb->sb_mbmax = 0;
+}
+
+/*
+ * Routines to add and remove
+ * data from an mbuf queue.
+ *
+ * The routines sbappend() or sbappendrecord() are normally called to
+ * append new mbufs to a socket buffer, after checking that adequate
+ * space is available, comparing the function sbspace() with the amount
+ * of data to be added. sbappendrecord() differs from sbappend() in
+ * that data supplied is treated as the beginning of a new record.
+ * To place a sender's address, optional access rights, and data in a
+ * socket receive buffer, sbappendaddr() should be used. To place
+ * access rights and data in a socket receive buffer, sbappendrights()
+ * should be used. In either case, the new data begins a new record.
+ * Note that unlike sbappend() and sbappendrecord(), these routines check
+ * for the caller that there will be enough space to store the data.
+ * Each fails if there is not enough space, or if it cannot find mbufs
+ * to store additional information in.
+ *
+ * Reliable protocols may use the socket send buffer to hold data
+ * awaiting acknowledgement. Data is normally copied from a socket
+ * send buffer in a protocol with m_copy for output to a peer,
+ * and then removing the data from the socket buffer with sbdrop()
+ * or sbdroprecord() when the data is acknowledged by the peer.
+ */
+
+/*
+ * Append mbuf chain m to the last record in the
+ * socket buffer sb. The additional space associated
+ * the mbuf chain is recorded in sb. Empty mbufs are
+ * discarded and mbufs are compacted where possible.
+ */
+void
+sbappend(struct sockbuf *sb, struct mbuf *m)
+{
+ register struct mbuf *n;
+
+ if (m == 0)
+ return;
+ n = sb->sb_mb;
+ if (n) {
+ while (n->m_nextpkt)
+ n = n->m_nextpkt;
+ do {
+ if (n->m_flags & M_EOR) {
+ sbappendrecord(sb, m); /* XXXXXX!!!! */
+ return;
+ }
+ } while (n->m_next && (n = n->m_next));
+ }
+ sbcompress(sb, m, n);
+}
+
+#ifdef SOCKBUF_DEBUG
+void
+sbcheck(struct sockbuf *sb)
+{
+ register struct mbuf *m;
+ register int len = 0, mbcnt = 0;
+
+ for (m = sb->sb_mb; m; m = m->m_next) {
+ len += m->m_len;
+ mbcnt += MSIZE;
+ if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
+ mbcnt += m->m_ext.ext_size;
+ if (m->m_nextpkt)
+ panic("sbcheck nextpkt");
+ }
+ if (len != sb->sb_cc || mbcnt != sb->sb_mbcnt) {
+ printf("cc %d != %d || mbcnt %d != %d\n", len, sb->sb_cc,
+ mbcnt, sb->sb_mbcnt);
+ panic("sbcheck");
+ }
+}
+#endif
+
+/*
+ * As above, except the mbuf chain
+ * begins a new record.
+ */
+void
+sbappendrecord(struct sockbuf *sb, struct mbuf *m0)
+{
+ register struct mbuf *m;
+
+ if (m0 == 0)
+ return;
+ m = sb->sb_mb;
+ if (m)
+ while (m->m_nextpkt)
+ m = m->m_nextpkt;
+ /*
+ * Put the first mbuf on the queue.
+ * Note this permits zero length records.
+ */
+ sballoc(sb, m0);
+ if (m)
+ m->m_nextpkt = m0;
+ else
+ sb->sb_mb = m0;
+ m = m0->m_next;
+ m0->m_next = 0;
+ if (m && (m0->m_flags & M_EOR)) {
+ m0->m_flags &= ~M_EOR;
+ m->m_flags |= M_EOR;
+ }
+ sbcompress(sb, m, m0);
+}
+
+/*
+ * As above except that OOB data
+ * is inserted at the beginning of the sockbuf,
+ * but after any other OOB data.
+ */
+void
+sbinsertoob(struct sockbuf *sb, struct mbuf *m0)
+{
+ register struct mbuf *m;
+ register struct mbuf **mp;
+
+ if (m0 == 0)
+ return;
+ for (mp = &sb->sb_mb; *mp ; mp = &((*mp)->m_nextpkt)) {
+ m = *mp;
+ again:
+ switch (m->m_type) {
+
+ case MT_OOBDATA:
+ continue; /* WANT next train */
+
+ case MT_CONTROL:
+ m = m->m_next;
+ if (m)
+ goto again; /* inspect THIS train further */
+ }
+ break;
+ }
+ /*
+ * Put the first mbuf on the queue.
+ * Note this permits zero length records.
+ */
+ sballoc(sb, m0);
+ m0->m_nextpkt = *mp;
+ *mp = m0;
+ m = m0->m_next;
+ m0->m_next = 0;
+ if (m && (m0->m_flags & M_EOR)) {
+ m0->m_flags &= ~M_EOR;
+ m->m_flags |= M_EOR;
+ }
+ sbcompress(sb, m, m0);
+}
+
+/*
+ * Append address and data, and optionally, control (ancillary) data
+ * to the receive queue of a socket. If present,
+ * m0 must include a packet header with total length.
+ * Returns 0 if no space in sockbuf or insufficient mbufs.
+ */
+int
+sbappendaddr(struct sockbuf *sb, struct sockaddr *asa,
+ struct mbuf *m0, struct mbuf *control)
+{
+ register struct mbuf *m, *n;
+ int space = asa->sa_len;
+
+if (m0 && (m0->m_flags & M_PKTHDR) == 0)
+panic("sbappendaddr");
+ if (m0)
+ space += m0->m_pkthdr.len;
+ for (n = control; n; n = n->m_next) {
+ space += n->m_len;
+ if (n->m_next == 0) /* keep pointer to last control buf */
+ break;
+ }
+ if (space > sbspace(sb))
+ return (0);
+ if (asa->sa_len > MLEN)
+ return (0);
+ MGET(m, M_DONTWAIT, MT_SONAME);
+ if (m == 0)
+ return (0);
+ m->m_len = asa->sa_len;
+ bcopy((caddr_t)asa, mtod(m, caddr_t), asa->sa_len);
+ if (n)
+ n->m_next = m0; /* concatenate data to control */
+ else
+ control = m0;
+ m->m_next = control;
+ for (n = m; n; n = n->m_next)
+ sballoc(sb, n);
+ n = sb->sb_mb;
+ if (n) {
+ while (n->m_nextpkt)
+ n = n->m_nextpkt;
+ n->m_nextpkt = m;
+ } else
+ sb->sb_mb = m;
+ return (1);
+}
+
+int
+sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
+ struct mbuf *control)
+{
+ register struct mbuf *m, *n;
+ int space = 0;
+
+ if (control == 0)
+ panic("sbappendcontrol");
+ for (m = control; ; m = m->m_next) {
+ space += m->m_len;
+ if (m->m_next == 0)
+ break;
+ }
+ n = m; /* save pointer to last control buffer */
+ for (m = m0; m; m = m->m_next)
+ space += m->m_len;
+ if (space > sbspace(sb))
+ return (0);
+ n->m_next = m0; /* concatenate data to control */
+ for (m = control; m; m = m->m_next)
+ sballoc(sb, m);
+ n = sb->sb_mb;
+ if (n) {
+ while (n->m_nextpkt)
+ n = n->m_nextpkt;
+ n->m_nextpkt = control;
+ } else
+ sb->sb_mb = control;
+ return (1);
+}
+
+/*
+ * Compress mbuf chain m into the socket
+ * buffer sb following mbuf n. If n
+ * is null, the buffer is presumed empty.
+ */
+void
+sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n)
+{
+ register int eor = 0;
+ register struct mbuf *o;
+
+ while (m) {
+ eor |= m->m_flags & M_EOR;
+ if (m->m_len == 0 &&
+ (eor == 0 ||
+ (((o = m->m_next) || (o = n)) &&
+ o->m_type == m->m_type))) {
+ m = m_free(m);
+ continue;
+ }
+ if (n && (n->m_flags & (M_EXT | M_EOR)) == 0 &&
+ (n->m_data + n->m_len + m->m_len) < &n->m_dat[MLEN] &&
+ n->m_type == m->m_type) {
+ bcopy(mtod(m, caddr_t), mtod(n, caddr_t) + n->m_len,
+ (unsigned)m->m_len);
+ n->m_len += m->m_len;
+ sb->sb_cc += m->m_len;
+ m = m_free(m);
+ continue;
+ }
+ if (n)
+ n->m_next = m;
+ else
+ sb->sb_mb = m;
+ sballoc(sb, m);
+ n = m;
+ m->m_flags &= ~M_EOR;
+ m = m->m_next;
+ n->m_next = 0;
+ }
+ if (eor) {
+ if (n)
+ n->m_flags |= eor;
+ else
+ printf("semi-panic: sbcompress\n");
+ }
+}
+
+/*
+ * Free all mbufs in a sockbuf.
+ * Check that all resources are reclaimed.
+ */
+void
+sbflush(struct sockbuf *sb)
+{
+
+ if (sb->sb_flags & SB_LOCK)
+ panic("sbflush");
+ while (sb->sb_mbcnt)
+ sbdrop(sb, (int)sb->sb_cc);
+ if (sb->sb_cc || sb->sb_mb)
+ panic("sbflush 2");
+}
+
+/*
+ * Drop data from (the front of) a sockbuf.
+ */
+void
+sbdrop(struct sockbuf *sb, int len)
+{
+ register struct mbuf *m, *mn;
+ struct mbuf *next;
+
+ next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
+ while (len > 0) {
+ if (m == 0) {
+ if (next == 0)
+ panic("sbdrop");
+ m = next;
+ next = m->m_nextpkt;
+ continue;
+ }
+ if (m->m_len > len) {
+ m->m_len -= len;
+ m->m_data += len;
+ sb->sb_cc -= len;
+ break;
+ }
+ len -= m->m_len;
+ sbfree(sb, m);
+ MFREE(m, mn);
+ m = mn;
+ }
+ while (m && m->m_len == 0) {
+ sbfree(sb, m);
+ MFREE(m, mn);
+ m = mn;
+ }
+ if (m) {
+ sb->sb_mb = m;
+ m->m_nextpkt = next;
+ } else
+ sb->sb_mb = next;
+}
+
+/*
+ * Drop a record off the front of a sockbuf
+ * and move the next record to the front.
+ */
+void
+sbdroprecord(struct sockbuf *sb)
+{
+ register struct mbuf *m, *mn;
+
+ m = sb->sb_mb;
+ if (m) {
+ sb->sb_mb = m->m_nextpkt;
+ do {
+ sbfree(sb, m);
+ MFREE(m, mn);
+ m = mn;
+ } while (m);
+ }
+}
+
+/*
+ * Create a "control" mbuf containing the specified data
+ * with the specified type for presentation on a socket buffer.
+ */
+struct mbuf *
+sbcreatecontrol(caddr_t p, int size, int type, int level)
+{
+ register struct cmsghdr *cp;
+ struct mbuf *m;
+
+ if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
+ return ((struct mbuf *) NULL);
+ cp = mtod(m, struct cmsghdr *);
+ /* XXX check size? */
+ (void)memcpy(CMSG_DATA(cp), p, size);
+ size += sizeof(*cp);
+ m->m_len = size;
+ cp->cmsg_len = size;
+ cp->cmsg_level = level;
+ cp->cmsg_type = type;
+ return (m);
+}
+
+#ifdef PRU_OLDSTYLE
+/*
+ * The following routines mediate between the old-style `pr_usrreq'
+ * protocol implementations and the new-style `struct pr_usrreqs'
+ * calling convention.
+ */
+
+/* syntactic sugar */
+#define nomb (struct mbuf *)0
+
+static int
+old_abort(struct socket *so)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_ABORT, nomb, nomb, nomb);
+}
+
+static int
+old_accept(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_ACCEPT, nomb, nam, nomb);
+}
+
+static int
+old_attach(struct socket *so, intptr_t proto)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_ATTACH, nomb,
+ (struct mbuf *)proto, /* XXX */
+ nomb);
+}
+
+static int
+old_bind(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_BIND, nomb, nam, nomb);
+}
+
+static int
+old_connect(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_CONNECT, nomb, nam, nomb);
+}
+
+static int
+old_connect2(struct socket *so1, struct socket *so2)
+{
+ return so1->so_proto->pr_ousrreq(so1, PRU_CONNECT2, nomb,
+ (struct mbuf *)so2, nomb);
+}
+
+static int
+old_control(struct socket *so, intptr_t cmd, caddr_t data, struct ifnet *ifp)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_CONTROL, (struct mbuf *)cmd,
+ (struct mbuf *)data,
+ (struct mbuf *)ifp);
+}
+
+static int
+old_detach(struct socket *so)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_DETACH, nomb, nomb, nomb);
+}
+
+static int
+old_disconnect(struct socket *so)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_DISCONNECT, nomb, nomb, nomb);
+}
+
+static int
+old_listen(struct socket *so)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_LISTEN, nomb, nomb, nomb);
+}
+
+static int
+old_peeraddr(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_PEERADDR, nomb, nam, nomb);
+}
+
+static int
+old_rcvd(struct socket *so, intptr_t flags)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_RCVD, nomb,
+ (struct mbuf *)flags, /* XXX */
+ nomb);
+}
+
+static int
+old_rcvoob(struct socket *so, struct mbuf *m, intptr_t flags)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_RCVOOB, m,
+ (struct mbuf *)flags, /* XXX */
+ nomb);
+}
+
+static int
+old_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *addr,
+ struct mbuf *control)
+{
+ int req;
+
+ if (flags & PRUS_OOB) {
+ req = PRU_SENDOOB;
+ } else if(flags & PRUS_EOF) {
+ req = PRU_SEND_EOF;
+ } else {
+ req = PRU_SEND;
+ }
+ return so->so_proto->pr_ousrreq(so, req, m, addr, control);
+}
+
+static int
+old_sense(struct socket *so, struct stat *sb)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_SENSE, (struct mbuf *)sb,
+ nomb, nomb);
+}
+
+static int
+old_shutdown(struct socket *so)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_SHUTDOWN, nomb, nomb, nomb);
+}
+
+static int
+old_sockaddr(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_ousrreq(so, PRU_SOCKADDR, nomb, nam, nomb);
+}
+
+struct pr_usrreqs pru_oldstyle = {
+ old_abort, old_accept, old_attach, old_bind, old_connect,
+ old_connect2, old_control, old_detach, old_disconnect,
+ old_listen, old_peeraddr, old_rcvd, old_rcvoob, old_send,
+ old_sense, old_shutdown, old_sockaddr
+};
+
+#endif /* PRU_OLDSTYLE */
+
+/*
+ * Some routines that return EOPNOTSUPP for entry points that are not
+ * supported by a protocol. Fill in as needed.
+ */
+int
+pru_accept_notsupp(struct socket *so, struct mbuf *nam)
+{
+ return EOPNOTSUPP;
+}
+
+int
+pru_connect2_notsupp(struct socket *so1, struct socket *so2)
+{
+ return EOPNOTSUPP;
+}
+
+int
+pru_control_notsupp(struct socket *so, int cmd, caddr_t data,
+ struct ifnet *ifp)
+{
+ return EOPNOTSUPP;
+}
+
+int
+pru_listen_notsupp(struct socket *so)
+{
+ return EOPNOTSUPP;
+}
+
+int
+pru_rcvd_notsupp(struct socket *so, int flags)
+{
+ return EOPNOTSUPP;
+}
+
+int
+pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags)
+{
+ return EOPNOTSUPP;
+}
+
+/*
+ * This isn't really a ``null'' operation, but it's the default one
+ * and doesn't do anything destructive.
+ */
+int
+pru_sense_null(struct socket *so, struct stat *sb)
+{
+ sb->st_blksize = so->so_snd.sb_hiwat;
+ return 0;
+}
diff --git a/cpukit/libnetworking/lib/README b/cpukit/libnetworking/lib/README
new file mode 100644
index 0000000000..998bd5e708
--- /dev/null
+++ b/cpukit/libnetworking/lib/README
@@ -0,0 +1,5 @@
+#
+# $Id$
+#
+
+Sources from application-level (as opposed to kernel-level) libraries.
diff --git a/cpukit/libnetworking/lib/ftpfs.c b/cpukit/libnetworking/lib/ftpfs.c
new file mode 100644
index 0000000000..0f2183409c
--- /dev/null
+++ b/cpukit/libnetworking/lib/ftpfs.c
@@ -0,0 +1,1345 @@
+/**
+ * @file
+ *
+ * File Transfer Protocol file system (FTP client).
+ */
+
+/*
+ * Copyright (c) 2009, 2010, 2011
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * (c) Copyright 2002
+ * Thomas Doerfler
+ * IMD Ingenieurbuero fuer Microcomputertechnik
+ * Herbststr. 8
+ * 82178 Puchheim, Germany
+ * <Thomas.Doerfler@imd-systems.de>
+ *
+ * Modified by Sebastian Huber <sebastian.huber@embedded-brains.de>.
+ *
+ * This code has been created after closly inspecting "tftpdriver.c" from Eric
+ * Norum.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <netdb.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <rtems.h>
+#include <rtems/ftpfs.h>
+#include <rtems/imfs.h>
+#include <rtems/libio.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/seterr.h>
+
+#ifdef DEBUG
+ #define DEBUG_PRINTF(...) printf(__VA_ARGS__)
+#else
+ #define DEBUG_PRINTF(...)
+#endif
+
+/**
+ * Connection entry for each open file stream.
+ */
+typedef struct {
+ /**
+ * Control connection socket.
+ */
+ int ctrl_socket;
+
+ /**
+ * Data transfer socket.
+ */
+ int data_socket;
+
+ /**
+ * End of file flag.
+ */
+ bool eof;
+} rtems_ftpfs_entry;
+
+/**
+ * Mount entry for each file system instance.
+ */
+typedef struct {
+ /**
+ * Verbose mode enabled or disabled.
+ */
+ bool verbose;
+
+ /**
+ * Timeout value
+ */
+ struct timeval timeout;
+} rtems_ftpfs_mount_entry;
+
+static const rtems_filesystem_operations_table rtems_ftpfs_ops;
+
+static const rtems_filesystem_file_handlers_r rtems_ftpfs_handlers;
+
+static const rtems_filesystem_file_handlers_r rtems_ftpfs_root_handlers;
+
+static bool rtems_ftpfs_use_timeout(const struct timeval *to)
+{
+ return to->tv_sec != 0 || to->tv_usec != 0;
+}
+
+static int rtems_ftpfs_set_connection_timeout(
+ int socket,
+ const struct timeval *to
+)
+{
+ if (rtems_ftpfs_use_timeout(to)) {
+ int rv = 0;
+
+ rv = setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, to, sizeof(*to));
+ if (rv != 0) {
+ return EIO;
+ }
+
+ rv = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, to, sizeof(*to));
+ if (rv != 0) {
+ return EIO;
+ }
+ }
+
+ return 0;
+}
+
+static rtems_status_code rtems_ftpfs_do_ioctl(
+ const char *mount_point,
+ ioctl_command_t req,
+ ...
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int rv = 0;
+ int fd = 0;
+ va_list ap;
+
+ if (mount_point == NULL) {
+ mount_point = RTEMS_FTPFS_MOUNT_POINT_DEFAULT;
+ }
+
+ fd = open(mount_point, O_RDWR);
+ if (fd < 0) {
+ return RTEMS_INVALID_NAME;
+ }
+
+ va_start(ap, req);
+ rv = ioctl(fd, req, va_arg(ap, void *));
+ va_end(ap);
+ if (rv != 0) {
+ sc = RTEMS_INVALID_NUMBER;
+ }
+
+ rv = close(fd);
+ if (rv != 0 && sc == RTEMS_SUCCESSFUL) {
+ sc = RTEMS_IO_ERROR;
+ }
+
+ return sc;
+}
+
+rtems_status_code rtems_ftpfs_get_verbose(const char *mount_point, bool *verbose)
+{
+ return rtems_ftpfs_do_ioctl(
+ mount_point,
+ RTEMS_FTPFS_IOCTL_GET_VERBOSE,
+ verbose
+ );
+}
+
+rtems_status_code rtems_ftpfs_set_verbose(const char *mount_point, bool verbose)
+{
+ return rtems_ftpfs_do_ioctl(
+ mount_point,
+ RTEMS_FTPFS_IOCTL_SET_VERBOSE,
+ &verbose
+ );
+}
+
+rtems_status_code rtems_ftpfs_get_timeout(
+ const char *mount_point,
+ struct timeval *timeout
+)
+{
+ return rtems_ftpfs_do_ioctl(
+ mount_point,
+ RTEMS_FTPFS_IOCTL_GET_TIMEOUT,
+ timeout
+ );
+}
+
+rtems_status_code rtems_ftpfs_set_timeout(
+ const char *mount_point,
+ const struct timeval *timeout
+)
+{
+ return rtems_ftpfs_do_ioctl(
+ mount_point,
+ RTEMS_FTPFS_IOCTL_SET_TIMEOUT,
+ timeout
+ );
+}
+
+typedef void (*rtems_ftpfs_reply_parser)(
+ const char * /* reply fragment */,
+ size_t /* reply fragment length */,
+ void * /* parser argument */
+);
+
+typedef enum {
+ RTEMS_FTPFS_REPLY_START,
+ RTEMS_FTPFS_REPLY_SINGLE_LINE,
+ RTEMS_FTPFS_REPLY_SINGLE_LINE_DONE,
+ RTEMS_FTPFS_REPLY_MULTI_LINE,
+ RTEMS_FTPFS_REPLY_NEW_LINE,
+ RTEMS_FTPFS_REPLY_NEW_LINE_START
+} rtems_ftpfs_reply_state;
+
+typedef enum {
+ RTEMS_FTPFS_REPLY_ERROR = 0,
+ RTEMS_FTPFS_REPLY_1 = '1',
+ RTEMS_FTPFS_REPLY_2 = '2',
+ RTEMS_FTPFS_REPLY_3 = '3',
+ RTEMS_FTPFS_REPLY_4 = '4',
+ RTEMS_FTPFS_REPLY_5 = '5'
+} rtems_ftpfs_reply;
+
+#define RTEMS_FTPFS_REPLY_SIZE 3
+
+static rtems_ftpfs_reply rtems_ftpfs_get_reply(
+ int socket,
+ rtems_ftpfs_reply_parser parser,
+ void *parser_arg,
+ bool verbose
+)
+{
+ rtems_ftpfs_reply_state state = RTEMS_FTPFS_REPLY_START;
+ unsigned char reply_first [RTEMS_FTPFS_REPLY_SIZE] = { 'a', 'a', 'a' };
+ unsigned char reply_last [RTEMS_FTPFS_REPLY_SIZE] = { 'b', 'b', 'b' };
+ size_t reply_first_index = 0;
+ size_t reply_last_index = 0;
+ char buf [128];
+
+ while (true) {
+ /* Receive reply fragment from socket */
+ ssize_t i = 0;
+ ssize_t rv = recv(socket, buf, sizeof(buf), 0);
+
+ if (rv <= 0) {
+ return RTEMS_FTPFS_REPLY_ERROR;
+ }
+
+ /* Be verbose if necessary */
+ if (verbose) {
+ write(STDERR_FILENO, buf, (size_t) rv);
+ }
+
+ /* Invoke parser if necessary */
+ if (parser != NULL) {
+ parser(buf, (size_t) rv, parser_arg);
+ }
+
+ /* Parse reply fragment */
+ for (i = 0; i < rv; ++i) {
+ char c = buf [i];
+
+ switch (state) {
+ case RTEMS_FTPFS_REPLY_START:
+ if (reply_first_index < RTEMS_FTPFS_REPLY_SIZE) {
+ reply_first [reply_first_index] = c;
+ ++reply_first_index;
+ } else if (c == '-') {
+ state = RTEMS_FTPFS_REPLY_MULTI_LINE;
+ } else {
+ state = RTEMS_FTPFS_REPLY_SINGLE_LINE;
+ }
+ break;
+ case RTEMS_FTPFS_REPLY_SINGLE_LINE:
+ if (c == '\n') {
+ state = RTEMS_FTPFS_REPLY_SINGLE_LINE_DONE;
+ }
+ break;
+ case RTEMS_FTPFS_REPLY_MULTI_LINE:
+ if (c == '\n') {
+ state = RTEMS_FTPFS_REPLY_NEW_LINE_START;
+ reply_last_index = 0;
+ }
+ break;
+ case RTEMS_FTPFS_REPLY_NEW_LINE:
+ case RTEMS_FTPFS_REPLY_NEW_LINE_START:
+ if (reply_last_index < RTEMS_FTPFS_REPLY_SIZE) {
+ state = RTEMS_FTPFS_REPLY_NEW_LINE;
+ reply_last [reply_last_index] = c;
+ ++reply_last_index;
+ } else {
+ state = RTEMS_FTPFS_REPLY_MULTI_LINE;
+ }
+ break;
+ default:
+ return RTEMS_FTPFS_REPLY_ERROR;
+ }
+ }
+
+ /* Check reply */
+ if (state == RTEMS_FTPFS_REPLY_SINGLE_LINE_DONE) {
+ if (
+ isdigit(reply_first [0])
+ && isdigit(reply_first [1])
+ && isdigit(reply_first [2])
+ ) {
+ break;
+ } else {
+ return RTEMS_FTPFS_REPLY_ERROR;
+ }
+ } else if (state == RTEMS_FTPFS_REPLY_NEW_LINE_START) {
+ bool ok = true;
+
+ for (i = 0; i < RTEMS_FTPFS_REPLY_SIZE; ++i) {
+ ok = ok
+ && reply_first [i] == reply_last [i]
+ && isdigit(reply_first [i]);
+ }
+
+ if (ok) {
+ break;
+ }
+ }
+ }
+
+ return reply_first [0];
+}
+
+static rtems_ftpfs_reply rtems_ftpfs_send_command_with_parser(
+ int socket,
+ const char *cmd,
+ const char *arg,
+ rtems_ftpfs_reply_parser parser,
+ void *parser_arg,
+ bool verbose
+)
+{
+ rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
+ size_t cmd_len = strlen(cmd);
+ size_t arg_len = arg != NULL ? strlen(arg) : 0;
+ size_t len = cmd_len + arg_len + 2;
+ char *buf = malloc(len);
+
+ if (buf != NULL) {
+ ssize_t n = 0;
+ char *buf_arg = buf + cmd_len;
+ char *buf_eol = buf_arg + arg_len;
+
+ memcpy(buf, cmd, cmd_len);
+ memcpy(buf_arg, arg, arg_len);
+ buf_eol [0] = '\r';
+ buf_eol [1] = '\n';
+
+ /* Send */
+ n = send(socket, buf, len, 0);
+ if (n == (ssize_t) len) {
+ if (verbose) {
+ write(STDERR_FILENO, buf, len);
+ }
+
+ /* Reply */
+ reply = rtems_ftpfs_get_reply(socket, parser, parser_arg, verbose);
+ }
+
+ free(buf);
+ }
+
+ return reply;
+}
+
+static rtems_ftpfs_reply rtems_ftpfs_send_command(
+ int socket,
+ const char *cmd,
+ const char *arg,
+ bool verbose
+)
+{
+ return rtems_ftpfs_send_command_with_parser(
+ socket,
+ cmd,
+ arg,
+ NULL,
+ NULL,
+ verbose
+ );
+}
+
+typedef enum {
+ STATE_USER_NAME,
+ STATE_START_PASSWORD,
+ STATE_START_HOST_NAME,
+ STATE_START_HOST_NAME_OR_PATH,
+ STATE_START_PATH,
+ STATE_PASSWORD,
+ STATE_HOST_NAME,
+ STATE_DONE,
+ STATE_INVALID
+} split_state;
+
+static bool rtems_ftpfs_split_names (
+ char *s,
+ const char **user,
+ const char **password,
+ const char **hostname,
+ const char **path
+)
+{
+ split_state state = STATE_USER_NAME;
+ size_t len = strlen(s);
+ size_t i = 0;
+
+ *user = s;
+ *password = NULL;
+ *hostname = NULL;
+ *path = NULL;
+
+ for (i = 0; i < len; ++i) {
+ char c = s [i];
+
+ switch (state) {
+ case STATE_USER_NAME:
+ if (c == ':') {
+ state = STATE_START_PASSWORD;
+ s [i] = '\0';
+ } else if (c == '@') {
+ state = STATE_START_HOST_NAME;
+ s [i] = '\0';
+ } else if (c == '/') {
+ state = STATE_START_HOST_NAME_OR_PATH;
+ s [i] = '\0';
+ }
+ break;
+ case STATE_START_PASSWORD:
+ state = STATE_PASSWORD;
+ *password = &s [i];
+ --i;
+ break;
+ case STATE_START_HOST_NAME:
+ state = STATE_HOST_NAME;
+ *hostname = &s [i];
+ --i;
+ break;
+ case STATE_START_HOST_NAME_OR_PATH:
+ if (c == '@') {
+ state = STATE_START_HOST_NAME;
+ } else {
+ state = STATE_DONE;
+ *path = &s [i];
+ goto done;
+ }
+ break;
+ case STATE_START_PATH:
+ state = STATE_DONE;
+ *path = &s [i];
+ goto done;
+ case STATE_PASSWORD:
+ if (c == '@') {
+ state = STATE_START_HOST_NAME;
+ s [i] = '\0';
+ } else if (c == '/') {
+ state = STATE_START_HOST_NAME_OR_PATH;
+ s [i] = '\0';
+ }
+ break;
+ case STATE_HOST_NAME:
+ if (c == '/') {
+ state = STATE_START_PATH;
+ s [i] = '\0';
+ }
+ break;
+ default:
+ state = STATE_INVALID;
+ goto done;
+ }
+ }
+
+done:
+
+ /* This is a special case with no username and password */
+ if (*hostname == NULL) {
+ *hostname = &s [0];
+ *user = "anonymous";
+ *password = *user;
+ }
+
+ /* If we have no password use the user name */
+ if (*password == NULL) {
+ *password = *user;
+ }
+
+ return state == STATE_DONE;
+}
+
+static socklen_t rtems_ftpfs_create_address(
+ struct sockaddr_in *sa,
+ unsigned long address,
+ unsigned short port
+)
+{
+ memset(sa, sizeof(*sa), 0);
+
+ sa->sin_family = AF_INET;
+ sa->sin_addr.s_addr = address;
+ sa->sin_port = port;
+ sa->sin_len = sizeof(*sa);
+
+ return sizeof(*sa);
+}
+
+static int rtems_ftpfs_terminate(rtems_libio_t *iop, bool error)
+{
+ int eno = 0;
+ int rv = 0;
+ rtems_ftpfs_entry *e = iop->data1;
+ rtems_ftpfs_mount_entry *me = iop->pathinfo.mt_entry->fs_info;
+ bool verbose = me->verbose;
+ rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
+
+ if (e != NULL) {
+ /* Close data connection if necessary */
+ if (e->data_socket >= 0) {
+ rv = close(e->data_socket);
+ if (rv != 0) {
+ eno = EIO;
+ }
+
+ /* For write connections we have to obtain the transfer reply */
+ if (
+ e->ctrl_socket >= 0
+ && (iop->flags & LIBIO_FLAGS_WRITE) != 0
+ && !error
+ ) {
+ reply = rtems_ftpfs_get_reply(e->ctrl_socket, NULL, NULL, verbose);
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ eno = EIO;
+ }
+ }
+ }
+
+ /* Close control connection if necessary */
+ if (e->ctrl_socket >= 0) {
+ reply = rtems_ftpfs_send_command(
+ e->ctrl_socket,
+ "QUIT",
+ NULL,
+ verbose
+ );
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ eno = EIO;
+ }
+
+ rv = close(e->ctrl_socket);
+ if (rv != 0) {
+ eno = EIO;
+ }
+ }
+
+ /* Free connection entry */
+ free(e);
+ }
+
+ /* Invalidate IO entry */
+ iop->data1 = NULL;
+
+ return eno;
+}
+
+static int rtems_ftpfs_open_ctrl_connection(
+ rtems_ftpfs_entry *e,
+ const char *user,
+ const char *password,
+ const char *hostname,
+ uint32_t *client_address,
+ bool verbose,
+ const struct timeval *timeout
+)
+{
+ int rv = 0;
+ int eno = 0;
+ rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
+ struct in_addr address = { .s_addr = 0 };
+ struct sockaddr_in sa;
+ socklen_t size = 0;
+
+ /* Create the socket for the control connection */
+ e->ctrl_socket = socket(AF_INET, SOCK_STREAM, 0);
+ if (e->ctrl_socket < 0) {
+ return ENOMEM;
+ }
+
+ /* Set up the server address from the hostname */
+ if (inet_aton(hostname, &address) == 0) {
+ /* Try to get the address by name */
+ struct hostent *he = gethostbyname(hostname);
+
+ if (he != NULL) {
+ memcpy(&address, he->h_addr, sizeof(address));
+ } else {
+ return ENOENT;
+ }
+ }
+ rtems_ftpfs_create_address(&sa, address.s_addr, htons(RTEMS_FTPFS_CTRL_PORT));
+ DEBUG_PRINTF("server = %s\n", inet_ntoa(sa.sin_addr));
+
+ /* Open control connection */
+ rv = connect(
+ e->ctrl_socket,
+ (struct sockaddr *) &sa,
+ sizeof(sa)
+ );
+ if (rv != 0) {
+ return ENOENT;
+ }
+
+ /* Set control connection timeout */
+ eno = rtems_ftpfs_set_connection_timeout(e->ctrl_socket, timeout);
+ if (eno != 0) {
+ return eno;
+ }
+
+ /* Get client address */
+ size = rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
+ rv = getsockname(
+ e->ctrl_socket,
+ (struct sockaddr *) &sa,
+ &size
+ );
+ if (rv != 0) {
+ return ENOMEM;
+ }
+ *client_address = ntohl(sa.sin_addr.s_addr);
+ DEBUG_PRINTF("client = %s\n", inet_ntoa(sa.sin_addr));
+
+ /* Now we should get a welcome message from the server */
+ reply = rtems_ftpfs_get_reply(e->ctrl_socket, NULL, NULL, verbose);
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ return ENOENT;
+ }
+
+ /* Send USER command */
+ reply = rtems_ftpfs_send_command(e->ctrl_socket, "USER ", user, verbose);
+ if (reply == RTEMS_FTPFS_REPLY_3) {
+ /* Send PASS command */
+ reply = rtems_ftpfs_send_command(
+ e->ctrl_socket,
+ "PASS ",
+ password,
+ verbose
+ );
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ return EACCES;
+ }
+
+ /* TODO: Some server may require an account */
+ } else if (reply != RTEMS_FTPFS_REPLY_2) {
+ return EACCES;
+ }
+
+ /* Send TYPE command to set binary mode for all data transfers */
+ reply = rtems_ftpfs_send_command(e->ctrl_socket, "TYPE I", NULL, verbose);
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int rtems_ftpfs_open_data_connection_active(
+ rtems_ftpfs_entry *e,
+ uint32_t client_address,
+ const char *file_command,
+ const char *filename,
+ bool verbose,
+ const struct timeval *timeout
+)
+{
+ int rv = 0;
+ int eno = 0;
+ rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
+ struct sockaddr_in sa;
+ socklen_t size = 0;
+ int port_socket = -1;
+ char port_command [] = "PORT 000,000,000,000,000,000";
+ uint16_t data_port = 0;
+
+ /* Create port socket to establish a data data connection */
+ port_socket = socket(AF_INET, SOCK_STREAM, 0);
+ if (port_socket < 0) {
+ eno = ENOMEM;
+ goto cleanup;
+ }
+
+ /* Bind port socket */
+ rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
+ rv = bind(
+ port_socket,
+ (struct sockaddr *) &sa,
+ sizeof(sa)
+ );
+ if (rv != 0) {
+ eno = EBUSY;
+ goto cleanup;
+ }
+
+ /* Get port number for data socket */
+ size = rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
+ rv = getsockname(
+ port_socket,
+ (struct sockaddr *) &sa,
+ &size
+ );
+ if (rv != 0) {
+ eno = ENOMEM;
+ goto cleanup;
+ }
+ data_port = ntohs(sa.sin_port);
+
+ /* Send PORT command to set data connection port for server */
+ snprintf(
+ port_command,
+ sizeof(port_command),
+ "PORT %lu,%lu,%lu,%lu,%lu,%lu",
+ (client_address >> 24) & 0xffUL,
+ (client_address >> 16) & 0xffUL,
+ (client_address >> 8) & 0xffUL,
+ (client_address >> 0) & 0xffUL,
+ (data_port >> 8) & 0xffUL,
+ (data_port >> 0) & 0xffUL
+ );
+ reply = rtems_ftpfs_send_command(
+ e->ctrl_socket,
+ port_command,
+ NULL,
+ verbose
+ );
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ eno = ENOTSUP;
+ goto cleanup;
+ }
+
+ /* Listen on port socket for incoming data connections */
+ rv = listen(port_socket, 1);
+ if (rv != 0) {
+ eno = EBUSY;
+ goto cleanup;
+ }
+
+ /* Send RETR or STOR command with filename */
+ reply = rtems_ftpfs_send_command(
+ e->ctrl_socket,
+ file_command,
+ filename,
+ verbose
+ );
+ if (reply != RTEMS_FTPFS_REPLY_1) {
+ eno = EIO;
+ goto cleanup;
+ }
+
+ /* Wait for connect on data connection if necessary */
+ if (rtems_ftpfs_use_timeout(timeout)) {
+ struct timeval to = *timeout;
+ fd_set fds;
+
+ FD_ZERO(&fds);
+ FD_SET(port_socket, &fds);
+
+ rv = select(port_socket + 1, &fds, NULL, NULL, &to);
+ if (rv <= 0) {
+ eno = EIO;
+ goto cleanup;
+ }
+ }
+
+ /* Accept data connection */
+ size = sizeof(sa);
+ e->data_socket = accept(
+ port_socket,
+ (struct sockaddr *) &sa,
+ &size
+ );
+ if (e->data_socket < 0) {
+ eno = EIO;
+ goto cleanup;
+ }
+
+cleanup:
+
+ /* Close port socket if necessary */
+ if (port_socket >= 0) {
+ rv = close(port_socket);
+ if (rv != 0) {
+ eno = EIO;
+ }
+ }
+
+ return eno;
+}
+
+typedef enum {
+ RTEMS_FTPFS_PASV_START = 0,
+ RTEMS_FTPFS_PASV_JUNK,
+ RTEMS_FTPFS_PASV_DATA,
+ RTEMS_FTPFS_PASV_DONE
+} rtems_ftpfs_pasv_state;
+
+typedef struct {
+ rtems_ftpfs_pasv_state state;
+ uint8_t data [6];
+ size_t index;
+} rtems_ftpfs_pasv_entry;
+
+static void rtems_ftpfs_pasv_parser(
+ const char* buf,
+ size_t len,
+ void *arg
+)
+{
+ rtems_ftpfs_pasv_entry *e = arg;
+ size_t i = 0;
+
+ for (i = 0; i < len; ++i) {
+ int c = buf [i];
+
+ switch (e->state) {
+ case RTEMS_FTPFS_PASV_START:
+ if (!isdigit(c)) {
+ e->state = RTEMS_FTPFS_PASV_JUNK;
+ e->index = 0;
+ }
+ break;
+ case RTEMS_FTPFS_PASV_JUNK:
+ if (isdigit(c)) {
+ e->state = RTEMS_FTPFS_PASV_DATA;
+ e->data [e->index] = (uint8_t) (c - '0');
+ }
+ break;
+ case RTEMS_FTPFS_PASV_DATA:
+ if (isdigit(c)) {
+ e->data [e->index] = (uint8_t) (e->data [e->index] * 10 + c - '0');
+ } else if (c == ',') {
+ ++e->index;
+ if (e->index < sizeof(e->data)) {
+ e->data [e->index] = 0;
+ } else {
+ e->state = RTEMS_FTPFS_PASV_DONE;
+ }
+ } else {
+ e->state = RTEMS_FTPFS_PASV_DONE;
+ }
+ break;
+ default:
+ return;
+ }
+ }
+}
+
+static int rtems_ftpfs_open_data_connection_passive(
+ rtems_ftpfs_entry *e,
+ uint32_t client_address,
+ const char *file_command,
+ const char *filename,
+ bool verbose,
+ const struct timeval *timeout
+)
+{
+ int rv = 0;
+ rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
+ struct sockaddr_in sa;
+ uint32_t data_address = 0;
+ uint16_t data_port = 0;
+
+ rtems_ftpfs_pasv_entry pe = {
+ .state = RTEMS_FTPFS_PASV_START
+ };
+
+ /* Send PASV command */
+ reply = rtems_ftpfs_send_command_with_parser(
+ e->ctrl_socket,
+ "PASV",
+ NULL,
+ rtems_ftpfs_pasv_parser,
+ &pe,
+ verbose
+ );
+ if (reply != RTEMS_FTPFS_REPLY_2) {
+ return ENOTSUP;
+ }
+ data_address = ((uint32_t)(pe.data [0]) << 24) + ((uint32_t)(pe.data [1]) << 16)
+ + ((uint32_t)(pe.data [2]) << 8) + ((uint32_t)(pe.data [3]));
+ data_port = (uint16_t) ((pe.data [4] << 8) + pe.data [5]);
+ rtems_ftpfs_create_address(&sa, htonl(data_address), htons(data_port));
+ DEBUG_PRINTF(
+ "server data = %s:%u\n",
+ inet_ntoa(sa.sin_addr),
+ (unsigned) ntohs(sa.sin_port)
+ );
+
+ /* Create data socket */
+ e->data_socket = socket(AF_INET, SOCK_STREAM, 0);
+ if (e->data_socket < 0) {
+ return ENOMEM;
+ }
+
+ /* Open data connection */
+ rv = connect(
+ e->data_socket,
+ (struct sockaddr *) &sa,
+ sizeof(sa)
+ );
+ if (rv != 0) {
+ return EIO;
+ }
+
+ /* Send RETR or STOR command with filename */
+ reply = rtems_ftpfs_send_command(
+ e->ctrl_socket,
+ file_command,
+ filename,
+ verbose
+ );
+ if (reply != RTEMS_FTPFS_REPLY_1) {
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int rtems_ftpfs_open(
+ rtems_libio_t *iop,
+ const char *path,
+ uint32_t flags,
+ uint32_t mode
+)
+{
+ int eno = 0;
+ bool ok = false;
+ rtems_ftpfs_entry *e = NULL;
+ rtems_ftpfs_mount_entry *me = iop->pathinfo.mt_entry->fs_info;
+ bool verbose = me->verbose;
+ const struct timeval *timeout = &me->timeout;
+ const char *user = NULL;
+ const char *password = NULL;
+ const char *hostname = NULL;
+ const char *filename = NULL;
+ const char *file_command = (iop->flags & LIBIO_FLAGS_WRITE) != 0
+ ? "STOR "
+ : "RETR ";
+ uint32_t client_address = 0;
+ char *location = iop->pathinfo.node_access;
+
+ /* Invalidate data handle */
+ iop->data1 = NULL;
+
+ /* Check location, it was allocated during path evaluation */
+ if (location == NULL) {
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+
+ /* Split location into parts */
+ ok = rtems_ftpfs_split_names(
+ location,
+ &user,
+ &password,
+ &hostname,
+ &filename
+ );
+ if (!ok) {
+ if (strlen(location) == 0) {
+ /*
+ * This is an access to the root node that will be used for file system
+ * option settings.
+ */
+ iop->pathinfo.handlers = &rtems_ftpfs_root_handlers;
+
+ return 0;
+ } else {
+ rtems_set_errno_and_return_minus_one(ENOENT);
+ }
+ }
+ DEBUG_PRINTF(
+ "user = '%s', password = '%s', filename = '%s'\n",
+ user,
+ password,
+ filename
+ );
+
+ /* Check for either read-only or write-only flags */
+ if (
+ (iop->flags & LIBIO_FLAGS_WRITE) != 0
+ && (iop->flags & LIBIO_FLAGS_READ) != 0
+ ) {
+ rtems_set_errno_and_return_minus_one(ENOTSUP);
+ }
+
+ /* Allocate connection entry */
+ e = malloc(sizeof(*e));
+ if (e == NULL) {
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+
+ /* Initialize connection entry */
+ e->ctrl_socket = -1;
+ e->data_socket = -1;
+ e->eof = false;
+
+ /* Save connection state */
+ iop->data1 = e;
+
+ /* Open control connection */
+ eno = rtems_ftpfs_open_ctrl_connection(
+ e,
+ user,
+ password,
+ hostname,
+ &client_address,
+ verbose,
+ timeout
+ );
+ if (eno != 0) {
+ goto cleanup;
+ }
+
+ /* Open passive data connection */
+ eno = rtems_ftpfs_open_data_connection_passive(
+ e,
+ client_address,
+ file_command,
+ filename,
+ verbose,
+ timeout
+ );
+ if (eno == ENOTSUP) {
+ /* Open active data connection */
+ eno = rtems_ftpfs_open_data_connection_active(
+ e,
+ client_address,
+ file_command,
+ filename,
+ verbose,
+ timeout
+ );
+ }
+ if (eno != 0) {
+ goto cleanup;
+ }
+
+ /* Set data connection timeout */
+ eno = rtems_ftpfs_set_connection_timeout(e->data_socket, timeout);
+
+cleanup:
+
+ if (eno == 0) {
+ return 0;
+ } else {
+ /* Free all resources if an error occured */
+ rtems_ftpfs_terminate(iop, true);
+
+ rtems_set_errno_and_return_minus_one(eno);
+ }
+}
+
+static ssize_t rtems_ftpfs_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ rtems_ftpfs_entry *e = iop->data1;
+ rtems_ftpfs_mount_entry *me = iop->pathinfo.mt_entry->fs_info;
+ bool verbose = me->verbose;
+ char *in = buffer;
+ size_t todo = count;
+
+ if (e->eof) {
+ return 0;
+ }
+
+ while (todo > 0) {
+ ssize_t rv = recv(e->data_socket, in, todo, 0);
+
+ if (rv <= 0) {
+ if (rv == 0) {
+ rtems_ftpfs_reply reply =
+ rtems_ftpfs_get_reply(e->ctrl_socket, NULL, NULL, verbose);
+
+ if (reply == RTEMS_FTPFS_REPLY_2) {
+ e->eof = true;
+ break;
+ }
+ }
+
+ rtems_set_errno_and_return_minus_one(EIO);
+ }
+
+ in += rv;
+ todo -= (size_t) rv;
+ }
+
+ return (ssize_t) (count - todo);
+}
+
+static ssize_t rtems_ftpfs_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ rtems_ftpfs_entry *e = iop->data1;
+ const char *out = buffer;
+ size_t todo = count;
+
+ while (todo > 0) {
+ ssize_t rv = send(e->data_socket, out, todo, 0);
+
+ if (rv <= 0) {
+ if (rv == 0) {
+ break;
+ } else {
+ rtems_set_errno_and_return_minus_one(EIO);
+ }
+ }
+
+ out += rv;
+ todo -= (size_t) rv;
+ }
+
+ return (ssize_t) (count - todo);
+}
+
+static int rtems_ftpfs_close(rtems_libio_t *iop)
+{
+ int eno = rtems_ftpfs_terminate(iop, false);
+
+ if (eno == 0) {
+ return 0;
+ } else {
+ rtems_set_errno_and_return_minus_one(eno);
+ }
+}
+
+/* Dummy version to let fopen(*,"w") work properly */
+static int rtems_ftpfs_ftruncate(rtems_libio_t *iop, rtems_off64_t count)
+{
+ return 0;
+}
+
+static int rtems_ftpfs_eval_path(
+ const char *pathname,
+ size_t pathnamelen,
+ int flags,
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ /*
+ * The caller of this routine has striped off the mount prefix from the path.
+ * We need to store this path here or otherwise we would have to do this job
+ * again. The path is used in rtems_ftpfs_open() via iop->pathinfo.node_access.
+ */
+ char *pathname_dup = malloc(pathnamelen + 1);
+
+ if (pathname_dup != NULL) {
+ memcpy(pathname_dup, pathname, pathnamelen);
+ pathname_dup [pathnamelen] = '\0';
+ }
+
+ pathloc->node_access = pathname_dup;
+
+ return 0;
+}
+
+static int rtems_ftpfs_free_node(rtems_filesystem_location_info_t *pathloc)
+{
+ free(pathloc->node_access);
+
+ return 0;
+}
+
+static rtems_filesystem_node_types_t rtems_ftpfs_node_type(
+ rtems_filesystem_location_info_t *pathloc
+)
+{
+ return RTEMS_FILESYSTEM_MEMORY_FILE;
+}
+
+int rtems_ftpfs_initialize(
+ rtems_filesystem_mount_table_entry_t *e,
+ const void *d
+)
+{
+ rtems_ftpfs_mount_entry *me = malloc(sizeof(rtems_ftpfs_mount_entry));
+
+ /* Mount entry for FTP file system instance */
+ e->fs_info = me;
+ if (e->fs_info == NULL) {
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ }
+ me->verbose = false;
+ me->timeout.tv_sec = 0;
+ me->timeout.tv_usec = 0;
+
+ /* Set handler and oparations table */
+ e->mt_fs_root.handlers = &rtems_ftpfs_handlers;
+ e->mt_fs_root.ops = &rtems_ftpfs_ops;
+
+ /* We maintain no real file system nodes, so there is no real root */
+ e->mt_fs_root.node_access = NULL;
+
+ /* Just use the limits from IMFS */
+ e->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
+
+ return 0;
+}
+
+static int rtems_ftpfs_unmount_me(
+ rtems_filesystem_mount_table_entry_t *e
+)
+{
+ free(e->fs_info);
+
+ return 0;
+}
+
+static int rtems_ftpfs_ioctl(
+ rtems_libio_t *iop,
+ uint32_t command,
+ void *arg
+)
+{
+ rtems_ftpfs_mount_entry *me = iop->pathinfo.mt_entry->fs_info;
+ bool *verbose = arg;
+ struct timeval *timeout = arg;
+
+ if (arg == NULL) {
+ rtems_set_errno_and_return_minus_one(EINVAL);
+ }
+
+ switch (command) {
+ case RTEMS_FTPFS_IOCTL_GET_VERBOSE:
+ *verbose = me->verbose;
+ break;
+ case RTEMS_FTPFS_IOCTL_SET_VERBOSE:
+ me->verbose = *verbose;
+ break;
+ case RTEMS_FTPFS_IOCTL_GET_TIMEOUT:
+ *timeout = me->timeout;
+ break;
+ case RTEMS_FTPFS_IOCTL_SET_TIMEOUT:
+ me->timeout = *timeout;
+ break;
+ default:
+ rtems_set_errno_and_return_minus_one(EINVAL);
+ }
+
+ return 0;
+}
+
+/*
+ * The stat() support is intended only for the cp shell command. Each request
+ * will return that we have a regular file with read, write and execute
+ * permissions for every one. The node index uses a global counter to support
+ * a remote to remote copy. This is not a very sophisticated method.
+ */
+static int rtems_ftpfs_fstat(
+ rtems_filesystem_location_info_t *loc,
+ struct stat *st
+)
+{
+ static unsigned ino = 0;
+
+ memset(st, 0, sizeof(*st));
+
+ /* FIXME */
+ st->st_ino = ++ino;
+ st->st_dev = rtems_filesystem_make_dev_t(0xcc494cd6U, 0x1d970b4dU);
+
+ st->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
+
+ return 0;
+}
+
+static const rtems_filesystem_operations_table rtems_ftpfs_ops = {
+ .evalpath_h = rtems_ftpfs_eval_path,
+ .evalformake_h = rtems_filesystem_default_evalformake,
+ .link_h = rtems_filesystem_default_link,
+ .unlink_h = rtems_filesystem_default_unlink,
+ .node_type_h = rtems_ftpfs_node_type,
+ .mknod_h = rtems_filesystem_default_mknod,
+ .chown_h = rtems_filesystem_default_chown,
+ .freenod_h = rtems_ftpfs_free_node,
+ .mount_h = rtems_filesystem_default_mount,
+ .fsmount_me_h = rtems_ftpfs_initialize,
+ .unmount_h = rtems_filesystem_default_unmount,
+ .fsunmount_me_h = rtems_ftpfs_unmount_me,
+ .utime_h = rtems_filesystem_default_utime,
+ .eval_link_h = rtems_filesystem_default_evaluate_link,
+ .symlink_h = rtems_filesystem_default_symlink,
+ .readlink_h = rtems_filesystem_default_readlink
+};
+
+static const rtems_filesystem_file_handlers_r rtems_ftpfs_handlers = {
+ .open_h = rtems_ftpfs_open,
+ .close_h = rtems_ftpfs_close,
+ .read_h = rtems_ftpfs_read,
+ .write_h = rtems_ftpfs_write,
+ .ioctl_h = rtems_filesystem_default_ioctl,
+ .lseek_h = rtems_filesystem_default_lseek,
+ .fstat_h = rtems_ftpfs_fstat,
+ .fchmod_h = rtems_filesystem_default_fchmod,
+ .ftruncate_h = rtems_ftpfs_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_filesystem_default_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_filesystem_default_rmnod
+};
+
+static const rtems_filesystem_file_handlers_r rtems_ftpfs_root_handlers = {
+ .open_h = rtems_filesystem_default_open,
+ .close_h = rtems_filesystem_default_close,
+ .read_h = rtems_filesystem_default_read,
+ .write_h = rtems_filesystem_default_write,
+ .ioctl_h = rtems_ftpfs_ioctl,
+ .lseek_h = rtems_filesystem_default_lseek,
+ .fstat_h = rtems_filesystem_default_fstat,
+ .fchmod_h = rtems_filesystem_default_fchmod,
+ .ftruncate_h = rtems_filesystem_default_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_filesystem_default_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_filesystem_default_rmnod
+};
diff --git a/cpukit/libnetworking/lib/getprotoby.c b/cpukit/libnetworking/lib/getprotoby.c
new file mode 100644
index 0000000000..7cbbe32f1d
--- /dev/null
+++ b/cpukit/libnetworking/lib/getprotoby.c
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdb.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+static const struct protoent prototab[] = {
+ { "ip", NULL, IPPROTO_IP },
+ { "icmp", NULL, IPPROTO_ICMP },
+ { "tcp", NULL, IPPROTO_TCP },
+ { "udp", NULL, IPPROTO_UDP },
+ };
+
+/*
+ * Dummy version of BSD getprotobyname()
+ */
+struct protoent *
+getprotobyname_static (const char *name)
+{
+ int i;
+
+ for (i = 0 ; i < (sizeof prototab / sizeof prototab[0]) ; i++) {
+ if (strcmp (name, prototab[i].p_name) == 0)
+ return (struct protoent *) &prototab[i];
+ }
+ return NULL;
+}
+
+/*
+ * Dummy version of BSD getprotobynumber()
+ */
+struct protoent *
+getprotobynumber_static (int proto)
+{
+ int i;
+
+ for (i = 0 ; i < (sizeof prototab / sizeof prototab[0]) ; i++) {
+ if (proto == prototab[i].p_proto)
+ return (struct protoent *) &prototab[i];
+ }
+ return NULL;
+}
diff --git a/cpukit/libnetworking/lib/rtems_bsdnet_ntp.c b/cpukit/libnetworking/lib/rtems_bsdnet_ntp.c
new file mode 100644
index 0000000000..17de20ba8f
--- /dev/null
+++ b/cpukit/libnetworking/lib/rtems_bsdnet_ntp.c
@@ -0,0 +1,218 @@
+/*
+ * Synchronize with an NTP server
+ *
+ * This program may be distributed and used for any purpose.
+ * I ask only that you:
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
+ *
+ * W. Eric Norum
+ * Canadian Light Source
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@cls.usask.ca
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h> /* close */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <limits.h>
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/error.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <rtems/bsdnet/servers.h>
+
+/*
+ * RTEMS base: 1988, January 1
+ * UNIX base: 1970, January 1
+ * NTP base: 1900, January 1
+ */
+#define UNIX_BASE_TO_NTP_BASE (uint32_t)(((70UL*365UL)+17UL) * (24UL*60UL*60UL))
+
+struct ntpPacket {
+ struct ntpPacketSmall ntp;
+ char authenticator[96];
+};
+
+static int
+processPacket (struct ntpPacketSmall *p, int state, void *unused)
+{
+ time_t tbuf;
+ struct tm *lt;
+ rtems_time_of_day rt;
+ rtems_interval ticks_per_second;
+
+ if ( state )
+ return 0;
+
+ ticks_per_second = rtems_clock_get_ticks_per_second();
+ tbuf = ntohl (p->transmit_timestamp.integer) - UNIX_BASE_TO_NTP_BASE - rtems_bsdnet_timeoffset;
+ lt = gmtime (&tbuf);
+ rt.year = lt->tm_year + 1900;
+ rt.month = lt->tm_mon + 1;
+ rt.day = lt->tm_mday;
+ rt.hour = lt->tm_hour;
+ rt.minute = lt->tm_min;
+ rt.second = lt->tm_sec;
+ rt.ticks = ntohl (p->transmit_timestamp.fraction) / (ULONG_MAX / ticks_per_second);
+ if (rt.ticks >= ticks_per_second)
+ rt.ticks = ticks_per_second - 1;
+ rtems_clock_set (&rt);
+ return 0;
+}
+
+static int
+getServerTimespec(struct ntpPacketSmall *p, int state, void *usr_data)
+{
+struct timespec *ts = usr_data;
+unsigned long long tmp;
+
+ if ( 0 == state ) {
+ ts->tv_sec = ntohl( p->transmit_timestamp.integer );
+ ts->tv_sec -= rtems_bsdnet_timeoffset + UNIX_BASE_TO_NTP_BASE;
+
+ tmp = 1000000000 * (unsigned long long)ntohl(p->transmit_timestamp.fraction);
+
+ ts->tv_nsec = (unsigned long) (tmp>>32);
+ }
+ return 0;
+}
+
+int rtems_bsdnet_ntp_retry_count = 5;
+int rtems_bsdnet_ntp_timeout_secs = 5;
+int rtems_bsdnet_ntp_bcast_timeout_secs = 80;
+
+static int
+tryServer (int i, int s, rtems_bsdnet_ntp_callback_t callback, void *usr_data)
+{
+ int l = 0;
+ struct timeval tv;
+ socklen_t farlen;
+ struct sockaddr_in farAddr;
+ struct ntpPacketSmall packet;
+
+ if (i < 0)
+ tv.tv_sec = rtems_bsdnet_ntp_bcast_timeout_secs;
+ else
+ tv.tv_sec = rtems_bsdnet_ntp_timeout_secs;
+ tv.tv_usec = 0;
+ if (setsockopt (s, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv) < 0) {
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Can't set socket receive timeout: %s\n", strerror (errno));
+ close (s);
+ return -1;
+ }
+ if (i >= 0) {
+ memset (&farAddr, 0, sizeof farAddr);
+ farAddr.sin_family = AF_INET;
+ farAddr.sin_port = htons (123);
+ farAddr.sin_addr = rtems_bsdnet_ntpserver[i];
+ memset (&packet, 0, sizeof packet);
+ packet.li_vn_mode = (3 << 3) | 3; /* NTP version 3, client */
+ if ( callback( &packet, 1, usr_data ) )
+ return -1;
+ l = sendto (s, &packet, sizeof packet, 0, (struct sockaddr *)&farAddr, sizeof farAddr);
+ if (l != sizeof packet) {
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Can't send: %s\n", strerror (errno));
+ return -1;
+ }
+ } else {
+ if ( callback( &packet, -1, usr_data ) )
+ return -1;
+ }
+ farlen = sizeof farAddr;
+ i = recvfrom (s, &packet, sizeof packet, 0, (struct sockaddr *)&farAddr, &farlen);
+ if (i == 0)
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Unexpected EOF");
+ if (i < 0) {
+ if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
+ return -1;
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Can't receive: %s\n", strerror (errno));
+ }
+
+ if ( i >= sizeof packet &&
+ ((packet.li_vn_mode & (0x7 << 3)) == (3 << 3)) &&
+ ((packet.transmit_timestamp.integer != 0) || (packet.transmit_timestamp.fraction != 0)) &&
+ 0 == callback( &packet, 0 , usr_data) )
+ return 0;
+
+ return -1;
+}
+
+int rtems_bsdnet_get_ntp(int sock, rtems_bsdnet_ntp_callback_t callback, void *usr_data)
+{
+int s = -1;
+int i;
+int retry;
+struct sockaddr_in myAddr;
+int reuseFlag;
+int ret;
+
+ if ( !callback )
+ callback = getServerTimespec;
+
+ if ( sock < 0 ) {
+ s = socket (AF_INET, SOCK_DGRAM, 0);
+ if (s < 0) {
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Can't create socket: %s\n", strerror (errno));
+ return -1;
+ }
+ reuseFlag = 1;
+ if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)&reuseFlag, sizeof reuseFlag) < 0) {
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Can't set socket reuse: %s\n", strerror (errno));
+ close (s);
+ return -1;
+ }
+ memset (&myAddr, 0, sizeof myAddr);
+ myAddr.sin_family = AF_INET;
+ myAddr.sin_port = htons (0);
+ myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
+ if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0) {
+ fprintf (stderr, "rtems_bsdnet_get_ntp() Can't bind socket: %s\n", strerror (errno));
+ close (s);
+ return -1;
+ }
+ sock = s;
+ }
+ ret = -1;
+ for (retry = 0 ; (ret == -1) && (retry < rtems_bsdnet_ntp_retry_count) ; retry++) {
+ /*
+ * If there's no server we just have to wait
+ * and hope that there's an NTP broadcast
+ * server out there somewhere.
+ */
+ if (rtems_bsdnet_ntpserver_count < 0) {
+ ret = tryServer (-1, sock, callback, usr_data);
+ }
+ else {
+ for (i = 0 ; (ret == -1) && (i < rtems_bsdnet_ntpserver_count) ; i++) {
+ ret = tryServer (i, sock, callback, usr_data);
+ }
+ }
+ }
+ if ( s >= 0 )
+ close (s);
+ return ret;
+}
+
+int
+rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority)
+{
+ if (interval != 0) {
+ fprintf (stderr, "Daemon-mode note yet supported.\n");
+ errno = EINVAL;
+ return -1;
+ }
+ return rtems_bsdnet_get_ntp( -1, processPacket, 0);
+}
diff --git a/cpukit/libnetworking/lib/syslog.c b/cpukit/libnetworking/lib/syslog.c
new file mode 100644
index 0000000000..309d2d78f8
--- /dev/null
+++ b/cpukit/libnetworking/lib/syslog.c
@@ -0,0 +1,194 @@
+/*
+ * RTEMS version of syslog and associated routines
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <syslog.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <string.h>
+
+#include <unistd.h>
+
+static int LogStatus = LOG_CONS;
+static const char *LogTag = "syslog";
+static int LogFacility = LOG_USER;
+static int LogMask = 0xff;
+
+static int LogFd = -1;
+static rtems_id LogSemaphore;
+extern struct in_addr rtems_bsdnet_log_host_address;
+
+#define SYSLOG_PORT 514
+
+void
+syslog (int pri, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ vsyslog (pri, fmt, ap);
+ va_end (ap);
+}
+
+/*
+ * FIXME: Should cbuf be static? It could be if we put the mutex
+ * around the entire body of this routine. Then we wouldn't
+ * have to worry about blowing stacks with a local variable
+ * that large. Could make cbuf bigger, too.
+ */
+void
+vsyslog (int pri, const char *fmt, va_list ap)
+{
+ int cnt;
+ char *cp;
+ char *msgp, cbuf[200];
+ int sent;
+
+ if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
+ syslog (LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID,
+ "syslog: unknown facility/priority: %#x", pri);
+ pri &= LOG_PRIMASK|LOG_FACMASK;
+ }
+
+ if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
+ return;
+
+ if ((pri & LOG_FACMASK) == 0)
+ pri |= LogFacility;
+
+ cnt = sprintf (cbuf, "<%d>", pri);
+ cp = msgp = cbuf + cnt;
+ if (LogTag) {
+ const char *lp = LogTag;
+ while ((*cp = *lp++) != '\0')
+ cp++;
+ }
+ if (LogStatus & LOG_PID) {
+ rtems_id tid;
+ rtems_task_ident (RTEMS_SELF, 0, &tid);
+ cnt = sprintf (cp, "[%#lx]", (unsigned long)tid);
+ cp += cnt;
+ }
+ if (LogTag) {
+ *cp++ = ':';
+ *cp++ = ' ';
+ }
+ cnt = vsprintf (cp, fmt, ap);
+ cnt += cp - cbuf;
+ if (cbuf[cnt-1] == '\n')
+ cbuf[--cnt] = '\0';
+
+ if (LogStatus & LOG_PERROR)
+ printf ("%s\n", cbuf);
+
+ /*
+ * Grab the mutex
+ */
+ sent = 0;
+ if ((rtems_bsdnet_log_host_address.s_addr != INADDR_ANY)
+ && (LogFd >= 0)
+ && (rtems_semaphore_obtain (LogSemaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT) == RTEMS_SUCCESSFUL)) {
+ /*
+ * Set the destination address/port
+ */
+ struct sockaddr_in farAddress;
+ farAddress.sin_family = AF_INET;
+ farAddress.sin_port = htons (SYSLOG_PORT);
+ farAddress.sin_addr = rtems_bsdnet_log_host_address;
+ memset (farAddress.sin_zero, '\0', sizeof farAddress.sin_zero);
+
+ /*
+ * Send the message
+ */
+ if (sendto (LogFd, cbuf, cnt, 0, (struct sockaddr *)&farAddress, sizeof farAddress) >= 0)
+ sent = 1;
+ rtems_semaphore_release (LogSemaphore);
+ }
+ if (!sent && (LogStatus & LOG_CONS) && !(LogStatus & LOG_PERROR))
+ printf ("%s\n", msgp);
+}
+
+void
+openlog (const char *ident, int logstat, int logfac)
+{
+ rtems_status_code sc;
+ struct sockaddr_in myAddress;
+
+ if (ident != NULL)
+ LogTag = ident;
+ LogStatus = logstat;
+ if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0)
+ LogFacility = logfac;
+
+ /*
+ * Create the socket
+ */
+ if ((LogFd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
+ printf ("Can't create syslog socket: %d\n", errno);
+ return;
+ }
+
+ /*
+ * Bind socket to name
+ */
+ myAddress.sin_family = AF_INET;
+ myAddress.sin_addr.s_addr = INADDR_ANY;
+ myAddress.sin_port = 0;
+ memset (myAddress.sin_zero, '\0', sizeof myAddress.sin_zero);
+ if (bind (LogFd, (struct sockaddr *)&myAddress, sizeof (myAddress)) < 0) {
+ close (LogFd);
+ LogFd = -1;
+ printf ("Can't bind syslog socket: %d\n", errno);
+ return;
+ }
+
+ /*
+ * Create the mutex
+ */
+ sc = rtems_semaphore_create (rtems_build_name('s', 'L', 'o', 'g'),
+ 1,
+ RTEMS_PRIORITY |
+ RTEMS_BINARY_SEMAPHORE |
+ RTEMS_INHERIT_PRIORITY |
+ RTEMS_NO_PRIORITY_CEILING |
+ RTEMS_LOCAL,
+ 0,
+ &LogSemaphore);
+ if (sc != RTEMS_SUCCESSFUL) {
+ printf ("Can't create syslog semaphore: %d\n", sc);
+ close (LogFd);
+ LogFd = -1;
+ }
+}
+
+void
+closelog(void)
+{
+ if (LogFd >= 0) {
+ close (LogFd);
+ LogFd = -1;
+ rtems_semaphore_delete (LogSemaphore);
+ }
+}
+
+int
+setlogmask (int pmask)
+{
+ int omask;
+
+ omask = LogMask;
+ if (pmask != 0)
+ LogMask = pmask;
+ return (omask);
+}
diff --git a/cpukit/libnetworking/lib/tftpDriver.c b/cpukit/libnetworking/lib/tftpDriver.c
new file mode 100644
index 0000000000..4122c3d96f
--- /dev/null
+++ b/cpukit/libnetworking/lib/tftpDriver.c
@@ -0,0 +1,1119 @@
+/*
+ * Trivial File Transfer Protocol (RFC 1350)
+ *
+ * Transfer file to/from remote host
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ *
+ * $Id$
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <malloc.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/libio_.h>
+#include <rtems/seterr.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#ifdef RTEMS_TFTP_DRIVER_DEBUG
+int rtems_tftp_driver_debug = 1;
+#endif
+
+/*
+ * Range of UDP ports to try
+ */
+#define UDP_PORT_BASE 3180
+
+/*
+ * Default limits
+ */
+#define PACKET_FIRST_TIMEOUT_MILLISECONDS 400L
+#define PACKET_TIMEOUT_MILLISECONDS 6000L
+#define OPEN_RETRY_LIMIT 10
+#define IO_RETRY_LIMIT 10
+
+/*
+ * TFTP opcodes
+ */
+#define TFTP_OPCODE_RRQ 1
+#define TFTP_OPCODE_WRQ 2
+#define TFTP_OPCODE_DATA 3
+#define TFTP_OPCODE_ACK 4
+#define TFTP_OPCODE_ERROR 5
+
+/*
+ * Largest data transfer
+ */
+#define TFTP_BUFSIZE 512
+
+/*
+ * Packets transferred between machines
+ */
+union tftpPacket {
+ /*
+ * RRQ/WRQ packet
+ */
+ struct tftpRWRQ {
+ uint16_t opcode;
+ char filename_mode[TFTP_BUFSIZE];
+ } tftpRWRQ;
+
+ /*
+ * DATA packet
+ */
+ struct tftpDATA {
+ uint16_t opcode;
+ uint16_t blocknum;
+ uint8_t data[TFTP_BUFSIZE];
+ } tftpDATA;
+
+ /*
+ * ACK packet
+ */
+ struct tftpACK {
+ uint16_t opcode;
+ uint16_t blocknum;
+ } tftpACK;
+
+ /*
+ * ERROR packet
+ */
+ struct tftpERROR {
+ uint16_t opcode;
+ uint16_t errorCode;
+ char errorMessage[TFTP_BUFSIZE];
+ } tftpERROR;
+};
+
+/*
+ * State of each TFTP stream
+ */
+struct tftpStream {
+ /*
+ * Buffer for storing most recently-received packet
+ */
+ union tftpPacket pkbuf;
+
+ /*
+ * Last block number transferred
+ */
+ uint16_t blocknum;
+
+ /*
+ * Data transfer socket
+ */
+ int socket;
+ struct sockaddr_in myAddress;
+ struct sockaddr_in farAddress;
+
+ /*
+ * Indices into buffer
+ */
+ int nleft;
+ int nused;
+
+ /*
+ * Flags
+ */
+ int firstReply;
+ int eof;
+ int writing;
+};
+
+/*
+ * Flags for filesystem info.
+ */
+#define TFTPFS_VERBOSE (1 << 0)
+
+/*
+ * Root node_access value
+ * By using the address of the file system
+ * we ensure a unique value for this identifier.
+ */
+#define ROOT_NODE_ACCESS(_fs) (_fs)
+
+/*
+ * TFTP File system info.
+ */
+typedef struct tftpfs_info_s {
+ uint32_t flags;
+ rtems_id tftp_mutex;
+ int nStreams;
+ struct tftpStream ** volatile tftpStreams;
+} tftpfs_info_t;
+
+#define tftpfs_info_mount_table(_mt) ((tftpfs_info_t*) ((_mt)->fs_info))
+#define tftpfs_info_pathloc(_pl) ((tftpfs_info_t*) ((_pl)->mt_entry->fs_info))
+#define tftpfs_info_iop(_iop) (tftpfs_info_pathloc (&((_iop)->pathinfo)))
+
+/*
+ * Number of streams open at the same time
+ */
+
+typedef const char *tftp_node;
+static const rtems_filesystem_operations_table rtems_tftp_ops;
+static const rtems_filesystem_file_handlers_r rtems_tftp_handlers;
+
+int rtems_tftpfs_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+)
+{
+ tftpfs_info_t *fs;
+ rtems_status_code sc;
+
+ mt_entry->mt_fs_root.handlers = &rtems_tftp_handlers;
+ mt_entry->mt_fs_root.ops = &rtems_tftp_ops;
+
+ /*
+ * We have no tftp filesystem specific data to maintain. This
+ * filesystem may only be mounted ONCE.
+ *
+ * And we maintain no real filesystem nodes, so there is no real root.
+ */
+
+ fs = malloc (sizeof (tftpfs_info_t));
+ if (!fs)
+ rtems_set_errno_and_return_minus_one (ENOMEM);
+
+ fs->flags = 0;
+ fs->nStreams = 0;
+ fs->tftpStreams = 0;
+
+ mt_entry->fs_info = fs;
+ mt_entry->mt_fs_root.node_access = ROOT_NODE_ACCESS (fs);
+ mt_entry->mt_fs_root.node_access_2 = NULL;
+
+ /*
+ * Now allocate a semaphore for mutual exclusion.
+ *
+ * NOTE: This could be in an fsinfo for this filesystem type.
+ */
+
+ sc = rtems_semaphore_create (
+ rtems_build_name('T', 'F', 'T', 'P'),
+ 1,
+ RTEMS_FIFO |
+ RTEMS_BINARY_SEMAPHORE |
+ RTEMS_NO_INHERIT_PRIORITY |
+ RTEMS_NO_PRIORITY_CEILING |
+ RTEMS_LOCAL,
+ 0,
+ &fs->tftp_mutex
+ );
+
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_set_errno_and_return_minus_one (ENOMEM);
+
+ if (data) {
+ char* config = (char*) data;
+ char* token;
+ char* saveptr;
+ token = strtok_r (config, " ", &saveptr);
+ while (token) {
+ if (strcmp (token, "verbose") == 0)
+ fs->flags |= TFTPFS_VERBOSE;
+ token = strtok_r (NULL, " ", &saveptr);
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Release a stream and clear the pointer to it
+ */
+static void
+releaseStream (tftpfs_info_t *fs, int s)
+{
+ if (fs->tftpStreams[s] && (fs->tftpStreams[s]->socket >= 0))
+ close (fs->tftpStreams[s]->socket);
+ rtems_semaphore_obtain (fs->tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ free (fs->tftpStreams[s]);
+ fs->tftpStreams[s] = NULL;
+ rtems_semaphore_release (fs->tftp_mutex);
+}
+
+static int
+rtems_tftpfs_shutdown (rtems_filesystem_mount_table_entry_t* mt_entry)
+{
+ tftpfs_info_t *fs = tftpfs_info_mount_table (mt_entry);
+ int s;
+ for (s = 0; s < fs->nStreams; s++)
+ releaseStream (fs, s);
+ rtems_semaphore_delete (fs->tftp_mutex);
+ free (fs);
+ return 0;
+}
+
+/*
+ * Map error message
+ */
+static int
+tftpErrno (struct tftpStream *tp)
+{
+ unsigned int tftpError;
+ static const int errorMap[] = {
+ EINVAL,
+ ENOENT,
+ EPERM,
+ ENOSPC,
+ EINVAL,
+ ENXIO,
+ EEXIST,
+ ESRCH,
+ };
+
+ tftpError = ntohs (tp->pkbuf.tftpERROR.errorCode);
+ if (tftpError < (sizeof errorMap / sizeof errorMap[0]))
+ return errorMap[tftpError];
+ else
+ return 1000 + tftpError;
+}
+
+/*
+ * Send a message to make the other end shut up
+ */
+static void
+sendStifle (struct tftpStream *tp, struct sockaddr_in *to)
+{
+ int len;
+ struct {
+ uint16_t opcode;
+ uint16_t errorCode;
+ char errorMessage[12];
+ } msg;
+
+ /*
+ * Create the error packet (Unknown transfer ID).
+ */
+ msg.opcode = htons (TFTP_OPCODE_ERROR);
+ msg.errorCode = htons (5);
+ len = sizeof msg.opcode + sizeof msg.errorCode + 1;
+ len += sprintf (msg.errorMessage, "GO AWAY");
+
+ /*
+ * Send it
+ */
+ sendto (tp->socket, (char *)&msg, len, 0, (struct sockaddr *)to, sizeof *to);
+}
+
+/*
+ * Wait for a data packet
+ */
+static int
+getPacket (struct tftpStream *tp, int retryCount)
+{
+ int len;
+ struct timeval tv;
+
+ if (retryCount == 0) {
+ tv.tv_sec = PACKET_FIRST_TIMEOUT_MILLISECONDS / 1000L;
+ tv.tv_usec = (PACKET_FIRST_TIMEOUT_MILLISECONDS % 1000L) * 1000L;
+ }
+ else {
+ tv.tv_sec = PACKET_TIMEOUT_MILLISECONDS / 1000L;
+ tv.tv_usec = (PACKET_TIMEOUT_MILLISECONDS % 1000L) * 1000L;
+ }
+ setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
+ for (;;) {
+ union {
+ struct sockaddr s;
+ struct sockaddr_in i;
+ } from;
+ socklen_t fromlen = sizeof from;
+ len = recvfrom (tp->socket, &tp->pkbuf,
+ sizeof tp->pkbuf, 0,
+ &from.s, &fromlen);
+ if (len < 0)
+ break;
+ if (from.i.sin_addr.s_addr == tp->farAddress.sin_addr.s_addr) {
+ if (tp->firstReply) {
+ tp->firstReply = 0;
+ tp->farAddress.sin_port = from.i.sin_port;
+ }
+ if (tp->farAddress.sin_port == from.i.sin_port)
+ break;
+ }
+
+ /*
+ * Packet is from someone with whom we are
+ * not interested. Tell them to go away.
+ */
+ sendStifle (tp, &from.i);
+ }
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
+#ifdef RTEMS_TFTP_DRIVER_DEBUG
+ if (rtems_tftp_driver_debug) {
+ if (len >= (int) sizeof tp->pkbuf.tftpACK) {
+ int opcode = ntohs (tp->pkbuf.tftpDATA.opcode);
+ switch (opcode) {
+ default:
+ printf ("TFTP: OPCODE %d\n", opcode);
+ break;
+
+ case TFTP_OPCODE_DATA:
+ printf ("TFTP: RECV %d\n", ntohs (tp->pkbuf.tftpDATA.blocknum));
+ break;
+
+ case TFTP_OPCODE_ACK:
+ printf ("TFTP: GOT ACK %d\n", ntohs (tp->pkbuf.tftpACK.blocknum));
+ break;
+ }
+ }
+ else {
+ printf ("TFTP: %d-byte packet\n", len);
+ }
+ }
+#endif
+ return len;
+}
+
+/*
+ * Send an acknowledgement
+ */
+static int
+sendAck (struct tftpStream *tp)
+{
+#ifdef RTEMS_TFTP_DRIVER_DEBUG
+ if (rtems_tftp_driver_debug)
+ printf ("TFTP: ACK %d\n", tp->blocknum);
+#endif
+
+ /*
+ * Create the acknowledgement
+ */
+ tp->pkbuf.tftpACK.opcode = htons (TFTP_OPCODE_ACK);
+ tp->pkbuf.tftpACK.blocknum = htons (tp->blocknum);
+
+ /*
+ * Send it
+ */
+ if (sendto (tp->socket, (char *)&tp->pkbuf, sizeof tp->pkbuf.tftpACK, 0,
+ (struct sockaddr *)&tp->farAddress,
+ sizeof tp->farAddress) < 0)
+ return errno;
+ return 0;
+}
+
+static int rtems_tftp_evaluate_for_make(
+ const char *path __attribute__((unused)), /* IN */
+ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */
+ const char **name __attribute__((unused)) /* OUT */
+)
+{
+ pathloc->node_access = NULL;
+ pathloc->node_access_2 = NULL;
+ rtems_set_errno_and_return_minus_one (EIO);
+}
+
+/*
+ * Convert a path to canonical form
+ */
+static void
+fixPath (char *path)
+{
+ char *inp, *outp, *base;
+
+ outp = inp = path;
+ base = NULL;
+ for (;;) {
+ if (inp[0] == '.') {
+ if (inp[1] == '\0')
+ break;
+ if (inp[1] == '/') {
+ inp += 2;
+ continue;
+ }
+ if (inp[1] == '.') {
+ if (inp[2] == '\0') {
+ if ((base != NULL) && (outp > base)) {
+ outp--;
+ while ((outp > base) && (outp[-1] != '/'))
+ outp--;
+ }
+ break;
+ }
+ if (inp[2] == '/') {
+ inp += 3;
+ if (base == NULL)
+ continue;
+ if (outp > base) {
+ outp--;
+ while ((outp > base) && (outp[-1] != '/'))
+ outp--;
+ }
+ continue;
+ }
+ }
+ }
+ if (base == NULL)
+ base = inp;
+ while (inp[0] != '/') {
+ if ((*outp++ = *inp++) == '\0')
+ return;
+ }
+ *outp++ = '/';
+ while (inp[0] == '/')
+ inp++;
+ }
+ *outp = '\0';
+ return;
+}
+
+static int rtems_tftp_eval_path(
+ const char *pathname, /* IN */
+ size_t pathnamelen, /* IN */
+ int flags, /* IN */
+ rtems_filesystem_location_info_t *pathloc /* IN/OUT */
+)
+{
+ tftpfs_info_t *fs;
+ char *cp;
+
+ /*
+ * Get the file system info.
+ */
+ fs = tftpfs_info_pathloc (pathloc);
+
+ pathloc->handlers = &rtems_tftp_handlers;
+
+ /*
+ * Hack to provide the illusion of directories inside the TFTP file system.
+ * Paths ending in a / are assumed to be directories.
+ */
+ if (pathname[strlen(pathname)-1] == '/') {
+ int nal = 0;
+ if (pathloc->node_access != ROOT_NODE_ACCESS (fs))
+ nal = strlen(pathloc->node_access);
+ cp = malloc(nal + pathnamelen + 1);
+ if (cp == NULL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ if (nal)
+ memcpy (cp, pathloc->node_access, nal);
+ memcpy(cp + nal, pathname, pathnamelen);
+ cp[nal + pathnamelen] = '\0';
+ fixPath (cp);
+ pathloc->node_access = cp;
+ }
+ else {
+ if (pathnamelen) {
+ /*
+ * Reject it if it's not read-only or write-only.
+ */
+ flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE;
+ if ((flags != RTEMS_LIBIO_PERMS_READ) \
+ && (flags != RTEMS_LIBIO_PERMS_WRITE))
+ rtems_set_errno_and_return_minus_one(EINVAL);
+
+ cp = malloc(pathnamelen + 1);
+ if (cp == NULL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ memcpy(cp, pathname, pathnamelen);
+ cp[pathnamelen] = '\0';
+ fixPath (cp);
+ pathloc->node_access_2 = cp;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * The routine which does most of the work for the IMFS open handler
+ */
+static int rtems_tftp_open_worker(
+ rtems_libio_t *iop,
+ char *full_path_name,
+ uint32_t flags,
+ uint32_t mode __attribute__((unused))
+)
+{
+ tftpfs_info_t *fs;
+ struct tftpStream *tp;
+ int retryCount;
+ struct in_addr farAddress;
+ int s;
+ int len;
+ char *cp1;
+ char *cp2;
+ char *remoteFilename;
+ rtems_interval now;
+ rtems_status_code sc;
+ char *hostname;
+
+ /*
+ * Get the file system info.
+ */
+ fs = tftpfs_info_iop (iop);
+
+ /*
+ * Extract the host name component
+ */
+ hostname = full_path_name;
+ cp1 = strchr (full_path_name, ':');
+ if (!cp1)
+ hostname = "BOOTP_HOST";
+ else {
+ *cp1 = '\0';
+ ++cp1;
+ }
+
+ /*
+ * Convert hostname to Internet address
+ */
+ if (strcmp (hostname, "BOOTP_HOST") == 0)
+ farAddress = rtems_bsdnet_bootp_server_address;
+ else if (inet_aton (hostname, &farAddress) == 0) {
+ struct hostent *he = gethostbyname(hostname);
+ if (he == NULL)
+ return ENOENT;
+ memcpy (&farAddress, he->h_addr, sizeof (farAddress));
+ } else {
+ return ENOENT;
+ }
+
+ /*
+ * Extract file pathname component
+ */
+ if (strcmp (cp1, "BOOTP_FILE") == 0) {
+ cp1 = rtems_bsdnet_bootp_boot_file_name;
+ }
+ if (*cp1 == '\0')
+ return ENOENT;
+ remoteFilename = cp1;
+ if (strlen (remoteFilename) > (TFTP_BUFSIZE - 10))
+ return ENOENT;
+
+ /*
+ * Find a free stream
+ */
+ sc = rtems_semaphore_obtain (fs->tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ return EBUSY;
+ for (s = 0 ; s < fs->nStreams ; s++) {
+ if (fs->tftpStreams[s] == NULL)
+ break;
+ }
+ if (s == fs->nStreams) {
+ /*
+ * Reallocate stream pointers
+ * Guard against the case where realloc() returns NULL.
+ */
+ struct tftpStream **np;
+
+ np = realloc (fs->tftpStreams, ++fs->nStreams * sizeof *fs->tftpStreams);
+ if (np == NULL) {
+ rtems_semaphore_release (fs->tftp_mutex);
+ return ENOMEM;
+ }
+ fs->tftpStreams = np;
+ }
+ tp = fs->tftpStreams[s] = malloc (sizeof (struct tftpStream));
+ rtems_semaphore_release (fs->tftp_mutex);
+ if (tp == NULL)
+ return ENOMEM;
+ iop->data0 = s;
+ iop->data1 = tp;
+
+ /*
+ * Create the socket
+ */
+ if ((tp->socket = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
+ releaseStream (fs, s);
+ return ENOMEM;
+ }
+
+ /*
+ * Bind the socket to a local address
+ */
+ retryCount = 0;
+ now = rtems_clock_get_ticks_since_boot();
+ for (;;) {
+ int try = (now + retryCount) % 10;
+
+ tp->myAddress.sin_family = AF_INET;
+ tp->myAddress.sin_port = htons (UDP_PORT_BASE + fs->nStreams * try + s);
+ tp->myAddress.sin_addr.s_addr = htonl (INADDR_ANY);
+ if (bind (tp->socket, (struct sockaddr *)&tp->myAddress, sizeof tp->myAddress) >= 0)
+ break;
+ if (++retryCount == 10) {
+ releaseStream (fs, s);
+ return EBUSY;
+ }
+ }
+
+ /*
+ * Set the UDP destination to the TFTP server
+ * port on the remote machine.
+ */
+ tp->farAddress.sin_family = AF_INET;
+ tp->farAddress.sin_addr = farAddress;
+ tp->farAddress.sin_port = htons (69);
+
+ /*
+ * Start the transfer
+ */
+ tp->firstReply = 1;
+ retryCount = 0;
+ for (;;) {
+ /*
+ * Create the request
+ */
+ if ((flags & O_ACCMODE) == O_RDONLY) {
+ tp->writing = 0;
+ tp->pkbuf.tftpRWRQ.opcode = htons (TFTP_OPCODE_RRQ);
+ }
+ else {
+ tp->writing = 1;
+ tp->pkbuf.tftpRWRQ.opcode = htons (TFTP_OPCODE_WRQ);
+ }
+ cp1 = (char *) tp->pkbuf.tftpRWRQ.filename_mode;
+ cp2 = (char *) remoteFilename;
+ while ((*cp1++ = *cp2++) != '\0')
+ continue;
+ cp2 = "octet";
+ while ((*cp1++ = *cp2++) != '\0')
+ continue;
+ len = cp1 - (char *)&tp->pkbuf.tftpRWRQ;
+
+ /*
+ * Send the request
+ */
+ if (sendto (tp->socket, (char *)&tp->pkbuf, len, 0,
+ (struct sockaddr *)&tp->farAddress,
+ sizeof tp->farAddress) < 0) {
+ releaseStream (fs, s);
+ return EIO;
+ }
+
+ /*
+ * Get reply
+ */
+ len = getPacket (tp, retryCount);
+ if (len >= (int) sizeof tp->pkbuf.tftpACK) {
+ int opcode = ntohs (tp->pkbuf.tftpDATA.opcode);
+ if (!tp->writing
+ && (opcode == TFTP_OPCODE_DATA)
+ && (ntohs (tp->pkbuf.tftpDATA.blocknum) == 1)) {
+ tp->nused = 0;
+ tp->blocknum = 1;
+ tp->nleft = len - 2 * sizeof (uint16_t );
+ tp->eof = (tp->nleft < TFTP_BUFSIZE);
+ if (sendAck (tp) != 0) {
+ releaseStream (fs, s);
+ return EIO;
+ }
+ break;
+ }
+ if (tp->writing
+ && (opcode == TFTP_OPCODE_ACK)
+ && (ntohs (tp->pkbuf.tftpACK.blocknum) == 0)) {
+ tp->nused = 0;
+ tp->blocknum = 1;
+ break;
+ }
+ if (opcode == TFTP_OPCODE_ERROR) {
+ int e = tftpErrno (tp);
+ releaseStream (fs, s);
+ return e;
+ }
+ }
+
+ /*
+ * Keep trying
+ */
+ if (++retryCount >= OPEN_RETRY_LIMIT) {
+ releaseStream (fs, s);
+ return EIO;
+ }
+ }
+ return 0;
+}
+
+/*
+ * The IMFS open handler
+ */
+static int rtems_tftp_open(
+ rtems_libio_t *iop,
+ const char *new_name,
+ uint32_t flags,
+ uint32_t mode
+)
+{
+ tftpfs_info_t *fs;
+ const char *device;
+ char *full_path_name;
+ char *na;
+ char *na2;
+ int dlen;
+ int nalen;
+ int na2len;
+ int sep1;
+ int err;
+
+ /*
+ * Get the file system info.
+ */
+ fs = tftpfs_info_iop (iop);
+
+ /*
+ * Tack the prefix directory if one exists from the device name.
+ */
+ device =
+ rtems_filesystem_mount_device (rtems_filesystem_location_mount (&iop->pathinfo));
+ dlen = strlen (device);
+ if (dlen == 0)
+ rtems_set_errno_and_return_minus_one (ENOENT);
+
+ if (iop->pathinfo.node_access_2 == NULL)
+ rtems_set_errno_and_return_minus_one (ENOENT);
+
+ if (iop->pathinfo.node_access != ROOT_NODE_ACCESS (fs)) {
+ na = iop->pathinfo.node_access;
+ nalen = strlen (na);
+ }
+ else {
+ na = NULL;
+ nalen = 0;
+ }
+
+ na2 = iop->pathinfo.node_access_2;
+
+ na2len = strlen (na2);
+
+ if (nalen) {
+ sep1 = 1;
+ if (na[nalen] == '/') {
+ sep1 = 0;
+ if (na2[0] == '/')
+ ++na2;
+ }
+ else {
+ if (na2[0] == '/')
+ sep1 = 0;
+ else
+ sep1 = 1;
+ }
+ }
+ else
+ sep1 = 0;
+
+ full_path_name = malloc (dlen + nalen + sep1 + na2len + 1);
+ if (full_path_name == NULL)
+ rtems_set_errno_and_return_minus_one(ENOMEM);
+ strcpy (full_path_name, device);
+ if (nalen)
+ strcat (full_path_name, na);
+ if (sep1)
+ strcat (full_path_name, "/");
+ strcat (full_path_name, na2);
+ fixPath (full_path_name);
+
+ if (fs->flags & TFTPFS_VERBOSE)
+ printf ("TFTPFS: %s %s %s -> %s\n", device, na, na2, full_path_name);
+
+ err = rtems_tftp_open_worker (iop, full_path_name, flags, mode);
+ free (full_path_name);
+ rtems_set_errno_and_return_minus_one(err);
+}
+
+/*
+ * Read from a TFTP stream
+ */
+static ssize_t rtems_tftp_read(
+ rtems_libio_t *iop,
+ void *buffer,
+ size_t count
+)
+{
+ char *bp;
+ struct tftpStream *tp = iop->data1;
+ int retryCount;
+ int nwant;
+
+ if (!tp)
+ rtems_set_errno_and_return_minus_one( EIO );
+
+ /*
+ * Read till user request is satisfied or EOF is reached
+ */
+ bp = buffer;
+ nwant = count;
+ while (nwant) {
+ if (tp->nleft) {
+ int ncopy;
+ if (nwant < tp->nleft)
+ ncopy = nwant;
+ else
+ ncopy = tp->nleft;
+ memcpy (bp, &tp->pkbuf.tftpDATA.data[tp->nused], ncopy);
+ tp->nused += ncopy;
+ tp->nleft -= ncopy;
+ bp += ncopy;
+ nwant -= ncopy;
+ if (nwant == 0)
+ break;
+ }
+ if (tp->eof)
+ break;
+
+ /*
+ * Wait for the next packet
+ */
+ retryCount = 0;
+ for (;;) {
+ int len = getPacket (tp, retryCount);
+ if (len >= (int)sizeof tp->pkbuf.tftpACK) {
+ int opcode = ntohs (tp->pkbuf.tftpDATA.opcode);
+ uint16_t nextBlock = tp->blocknum + 1;
+ if ((opcode == TFTP_OPCODE_DATA)
+ && (ntohs (tp->pkbuf.tftpDATA.blocknum) == nextBlock)) {
+ tp->nused = 0;
+ tp->nleft = len - 2 * sizeof (uint16_t);
+ tp->eof = (tp->nleft < TFTP_BUFSIZE);
+ tp->blocknum++;
+ if (sendAck (tp) != 0)
+ rtems_set_errno_and_return_minus_one (EIO);
+ break;
+ }
+ if (opcode == TFTP_OPCODE_ERROR)
+ rtems_set_errno_and_return_minus_one (tftpErrno (tp));
+ }
+
+ /*
+ * Keep trying?
+ */
+ if (++retryCount == IO_RETRY_LIMIT)
+ rtems_set_errno_and_return_minus_one (EIO);
+ if (sendAck (tp) != 0)
+ rtems_set_errno_and_return_minus_one (EIO);
+ }
+ }
+ return count - nwant;
+}
+
+/*
+ * Flush a write buffer and wait for acknowledgement
+ */
+static int rtems_tftp_flush (struct tftpStream *tp)
+{
+ int wlen, rlen;
+ int retryCount = 0;
+
+ wlen = tp->nused + 2 * sizeof (uint16_t );
+ for (;;) {
+ tp->pkbuf.tftpDATA.opcode = htons (TFTP_OPCODE_DATA);
+ tp->pkbuf.tftpDATA.blocknum = htons (tp->blocknum);
+#ifdef RTEMS_TFTP_DRIVER_DEBUG
+ if (rtems_tftp_driver_debug)
+ printf ("TFTP: SEND %d (%d)\n", tp->blocknum, tp->nused);
+#endif
+ if (sendto (tp->socket, (char *)&tp->pkbuf, wlen, 0,
+ (struct sockaddr *)&tp->farAddress,
+ sizeof tp->farAddress) < 0)
+ return EIO;
+ rlen = getPacket (tp, retryCount);
+ /*
+ * Our last packet won't necessarily be acknowledged!
+ */
+ if ((rlen < 0) && (tp->nused < sizeof tp->pkbuf.tftpDATA.data))
+ return 0;
+ if (rlen >= (int)sizeof tp->pkbuf.tftpACK) {
+ int opcode = ntohs (tp->pkbuf.tftpACK.opcode);
+ if ((opcode == TFTP_OPCODE_ACK)
+ && (ntohs (tp->pkbuf.tftpACK.blocknum) == tp->blocknum)) {
+ tp->nused = 0;
+ tp->blocknum++;
+ return 0;
+ }
+ if (opcode == TFTP_OPCODE_ERROR)
+ return tftpErrno (tp);
+ }
+
+ /*
+ * Keep trying?
+ */
+ if (++retryCount == IO_RETRY_LIMIT)
+ return EIO;
+ }
+}
+
+/*
+ * Close a TFTP stream
+ */
+static int rtems_tftp_close(
+ rtems_libio_t *iop
+)
+{
+ tftpfs_info_t *fs;
+ struct tftpStream *tp = iop->data1;
+ int e = 0;
+
+ /*
+ * Get the file system info.
+ */
+ fs = tftpfs_info_iop (iop);
+
+ if (!tp)
+ rtems_set_errno_and_return_minus_one (EIO);
+
+ if (tp->writing)
+ e = rtems_tftp_flush (tp);
+ if (!tp->eof && !tp->firstReply) {
+ /*
+ * Tell the other end to stop
+ */
+ rtems_interval ticksPerSecond;
+ sendStifle (tp, &tp->farAddress);
+ ticksPerSecond = rtems_clock_get_ticks_per_second();
+ rtems_task_wake_after (1 + ticksPerSecond / 10);
+ }
+ releaseStream (fs, iop->data0);
+ rtems_set_errno_and_return_minus_one (e);
+}
+
+static ssize_t rtems_tftp_write(
+ rtems_libio_t *iop,
+ const void *buffer,
+ size_t count
+)
+{
+ const char *bp;
+ struct tftpStream *tp = iop->data1;
+ int nleft, nfree, ncopy;
+
+ /*
+ * Bail out if an error has occurred
+ */
+ if (!tp->writing)
+ rtems_set_errno_and_return_minus_one (EIO);
+
+ /*
+ * Write till user request is satisfied
+ * Notice that the buffer is flushed as soon as it is filled rather
+ * than waiting for the next write or a close. This ensures that
+ * the flush in close writes a less than full buffer so the far
+ * end can detect the end-of-file condition.
+ */
+ bp = buffer;
+ nleft = count;
+ while (nleft) {
+ nfree = sizeof tp->pkbuf.tftpDATA.data - tp->nused;
+ if (nleft < nfree)
+ ncopy = nleft;
+ else
+ ncopy = nfree;
+ memcpy (&tp->pkbuf.tftpDATA.data[tp->nused], bp, ncopy);
+ tp->nused += ncopy;
+ nleft -= ncopy;
+ bp += ncopy;
+ if (tp->nused == sizeof tp->pkbuf.tftpDATA.data) {
+ int e = rtems_tftp_flush (tp);
+ if (e) {
+ tp->writing = 0;
+ rtems_set_errno_and_return_minus_one (e);
+ }
+ }
+ }
+ return count;
+}
+
+/*
+ * Dummy version to let fopen(xxxx,"w") work properly.
+ */
+static int rtems_tftp_ftruncate(
+ rtems_libio_t *iop __attribute__((unused)),
+ rtems_off64_t count __attribute__((unused))
+)
+{
+ return 0;
+}
+
+static rtems_filesystem_node_types_t rtems_tftp_node_type(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ tftpfs_info_t *fs = tftpfs_info_pathloc (pathloc);
+ if ((pathloc->node_access == NULL)
+ || (pathloc->node_access_2 != NULL)
+ || (pathloc->node_access == ROOT_NODE_ACCESS (fs)))
+ return RTEMS_FILESYSTEM_MEMORY_FILE;
+ return RTEMS_FILESYSTEM_DIRECTORY;
+}
+
+static int rtems_tftp_free_node_info(
+ rtems_filesystem_location_info_t *pathloc /* IN */
+)
+{
+ tftpfs_info_t *fs = tftpfs_info_pathloc (pathloc);
+ if (pathloc->node_access && \
+ (pathloc->node_access != ROOT_NODE_ACCESS (fs))) {
+ free (pathloc->node_access);
+ pathloc->node_access = NULL;
+ }
+ if (pathloc->node_access_2) {
+ free (pathloc->node_access_2);
+ pathloc->node_access_2 = NULL;
+ }
+ return 0;
+}
+
+
+static const rtems_filesystem_operations_table rtems_tftp_ops = {
+ .evalpath_h = rtems_tftp_eval_path,
+ .evalformake_h = rtems_tftp_evaluate_for_make,
+ .link_h = rtems_filesystem_default_link,
+ .unlink_h = rtems_filesystem_default_unlink,
+ .node_type_h = rtems_tftp_node_type,
+ .mknod_h = rtems_filesystem_default_mknod,
+ .chown_h = rtems_filesystem_default_chown,
+ .freenod_h = rtems_tftp_free_node_info,
+ .mount_h = rtems_filesystem_default_mount,
+ .fsmount_me_h = rtems_tftpfs_initialize,
+ .unmount_h = rtems_filesystem_default_unmount,
+ .fsunmount_me_h = rtems_tftpfs_shutdown,
+ .utime_h = rtems_filesystem_default_utime,
+ .eval_link_h = rtems_filesystem_default_evaluate_link,
+ .symlink_h = rtems_filesystem_default_symlink,
+ .readlink_h = rtems_filesystem_default_readlink
+};
+
+static const rtems_filesystem_file_handlers_r rtems_tftp_handlers = {
+ .open_h = rtems_tftp_open,
+ .close_h = rtems_tftp_close,
+ .read_h = rtems_tftp_read,
+ .write_h = rtems_tftp_write,
+ .ioctl_h = rtems_filesystem_default_ioctl,
+ .lseek_h = rtems_filesystem_default_lseek,
+ .fstat_h = rtems_filesystem_default_fstat,
+ .fchmod_h = rtems_filesystem_default_fchmod,
+ .ftruncate_h = rtems_tftp_ftruncate,
+ .fpathconf_h = rtems_filesystem_default_fpathconf,
+ .fsync_h = rtems_filesystem_default_fsync,
+ .fdatasync_h = rtems_filesystem_default_fdatasync,
+ .fcntl_h = rtems_filesystem_default_fcntl,
+ .rmnod_h = rtems_filesystem_default_rmnod
+};
diff --git a/cpukit/libnetworking/libc/base64.c b/cpukit/libnetworking/libc/base64.c
new file mode 100644
index 0000000000..070cc52231
--- /dev/null
+++ b/cpukit/libnetworking/libc/base64.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define Assert(Cond) if (!(Cond)) abort()
+
+static const char Base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Pad64 = '=';
+
+/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
+ The following encoding technique is taken from RFC 1521 by Borenstein
+ and Freed. It is reproduced here in a slightly edited form for
+ convenience.
+
+ A 65-character subset of US-ASCII is used, enabling 6 bits to be
+ represented per printable character. (The extra 65th character, "=",
+ is used to signify a special processing function.)
+
+ The encoding process represents 24-bit groups of input bits as output
+ strings of 4 encoded characters. Proceeding from left to right, a
+ 24-bit input group is formed by concatenating 3 8-bit input groups.
+ These 24 bits are then treated as 4 concatenated 6-bit groups, each
+ of which is translated into a single digit in the base64 alphabet.
+
+ Each 6-bit group is used as an index into an array of 64 printable
+ characters. The character referenced by the index is placed in the
+ output string.
+
+ Table 1: The Base64 Alphabet
+
+ Value Encoding Value Encoding Value Encoding Value Encoding
+ 0 A 17 R 34 i 51 z
+ 1 B 18 S 35 j 52 0
+ 2 C 19 T 36 k 53 1
+ 3 D 20 U 37 l 54 2
+ 4 E 21 V 38 m 55 3
+ 5 F 22 W 39 n 56 4
+ 6 G 23 X 40 o 57 5
+ 7 H 24 Y 41 p 58 6
+ 8 I 25 Z 42 q 59 7
+ 9 J 26 a 43 r 60 8
+ 10 K 27 b 44 s 61 9
+ 11 L 28 c 45 t 62 +
+ 12 M 29 d 46 u 63 /
+ 13 N 30 e 47 v
+ 14 O 31 f 48 w (pad) =
+ 15 P 32 g 49 x
+ 16 Q 33 h 50 y
+
+ Special processing is performed if fewer than 24 bits are available
+ at the end of the data being encoded. A full encoding quantum is
+ always completed at the end of a quantity. When fewer than 24 input
+ bits are available in an input group, zero bits are added (on the
+ right) to form an integral number of 6-bit groups. Padding at the
+ end of the data is performed using the '=' character.
+
+ Since all base64 input is an integral number of octets, only the
+ -------------------------------------------------
+ following cases can arise:
+
+ (1) the final quantum of encoding input is an integral
+ multiple of 24 bits; here, the final unit of encoded
+ output will be an integral multiple of 4 characters
+ with no "=" padding,
+ (2) the final quantum of encoding input is exactly 8 bits;
+ here, the final unit of encoded output will be two
+ characters followed by two "=" padding characters, or
+ (3) the final quantum of encoding input is exactly 16 bits;
+ here, the final unit of encoded output will be three
+ characters followed by one "=" padding character.
+ */
+
+int
+b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
+ size_t datalength = 0;
+ u_char input[3];
+ u_char output[4];
+ size_t i;
+
+ while (2 < srclength) {
+ input[0] = *src++;
+ input[1] = *src++;
+ input[2] = *src++;
+ srclength -= 3;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ output[3] = input[2] & 0x3f;
+ Assert(output[0] < 64);
+ Assert(output[1] < 64);
+ Assert(output[2] < 64);
+ Assert(output[3] < 64);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Base64[output[3]];
+ }
+
+ /* Now we worry about padding. */
+ if (0 != srclength) {
+ /* Get what's left. */
+ input[0] = input[1] = input[2] = '\0';
+ for (i = 0; i < srclength; i++)
+ input[i] = *src++;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ Assert(output[0] < 64);
+ Assert(output[1] < 64);
+ Assert(output[2] < 64);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ if (srclength == 1)
+ target[datalength++] = Pad64;
+ else
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Pad64;
+ }
+ if (datalength >= targsize)
+ return (-1);
+ target[datalength] = '\0'; /* Returned value doesn't count \0. */
+ return (datalength);
+}
+
+/* skips all whitespace anywhere.
+ converts characters, four at a time, starting at (or after)
+ src from base - 64 numbers into three 8 bit bytes in the target area.
+ it returns the number of data bytes stored at the target, or -1 on error.
+ */
+
+int
+b64_pton(
+ char const *src,
+ u_char *target,
+ size_t targsize)
+{
+ int tarindex, state, ch;
+ char *pos;
+
+ state = 0;
+ tarindex = 0;
+
+ while ((ch = *src++) != '\0') {
+ if (isspace(ch)) /* Skip whitespace anywhere. */
+ continue;
+
+ if (ch == Pad64)
+ break;
+
+ pos = strchr(Base64, ch);
+ if (pos == 0) /* A non-base64 character. */
+ return (-1);
+
+ switch (state) {
+ case 0:
+ if (target) {
+ if ((size_t)tarindex >= targsize)
+ return (-1);
+ target[tarindex] = (pos - Base64) << 2;
+ }
+ state = 1;
+ break;
+ case 1:
+ if (target) {
+ if ((size_t)tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 4;
+ target[tarindex+1] = ((pos - Base64) & 0x0f)
+ << 4 ;
+ }
+ tarindex++;
+ state = 2;
+ break;
+ case 2:
+ if (target) {
+ if ((size_t)tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 2;
+ target[tarindex+1] = ((pos - Base64) & 0x03)
+ << 6;
+ }
+ tarindex++;
+ state = 3;
+ break;
+ case 3:
+ if (target) {
+ if ((size_t)tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64);
+ }
+ tarindex++;
+ state = 0;
+ break;
+ default:
+ abort();
+ }
+ }
+
+ /*
+ * We are done decoding Base-64 chars. Let's see if we ended
+ * on a byte boundary, and/or with erroneous trailing characters.
+ */
+
+ if (ch == Pad64) { /* We got a pad char. */
+ ch = *src++; /* Skip it, get next. */
+ switch (state) {
+ case 0: /* Invalid = in first position */
+ case 1: /* Invalid = in second position */
+ return (-1);
+
+ case 2: /* Valid, means one byte of info */
+ /* Skip any number of spaces. */
+ for ((void)NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ break;
+ /* Make sure there is another trailing = sign. */
+ if (ch != Pad64)
+ return (-1);
+ ch = *src++; /* Skip the = */
+ /* Fall through to "single trailing =" case. */
+ /* FALLTHROUGH */
+
+ case 3: /* Valid, means two bytes of info */
+ /*
+ * We know this char is an =. Is there anything but
+ * whitespace after it?
+ */
+ for ((void)NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ return (-1);
+
+ /*
+ * Now make sure for cases 2 and 3 that the "extra"
+ * bits that slopped past the last full byte were
+ * zeros. If we don't check them, they become a
+ * subliminal channel.
+ */
+ if (target && target[tarindex] != 0)
+ return (-1);
+ }
+ } else {
+ /*
+ * We ended by seeing the end of the string. Make sure we
+ * have no partial bytes lying around.
+ */
+ if (state != 0)
+ return (-1);
+ }
+
+ return (tarindex);
+}
diff --git a/cpukit/libnetworking/libc/byteorder.3 b/cpukit/libnetworking/libc/byteorder.3
new file mode 100644
index 0000000000..81bf604867
--- /dev/null
+++ b/cpukit/libnetworking/libc/byteorder.3
@@ -0,0 +1,77 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd June 4, 1993
+.Dt BYTEORDER 3
+.Os BSD 4.2
+.Sh NAME
+.Nm htonl ,
+.Nm htons ,
+.Nm ntohl ,
+.Nm ntohs
+.Nd convert values between host and network byte order
+.Sh SYNOPSIS
+.Fd #include <sys/param.h>
+.Ft u_long
+.Fn htonl "u_long hostlong"
+.Ft u_short
+.Fn htons "u_short hostshort"
+.Ft u_long
+.Fn ntohl "u_long netlong"
+.Ft u_short
+.Fn ntohs "u_short netshort"
+.Sh DESCRIPTION
+These routines convert 16 and 32 bit quantities between network
+byte order and host byte order.
+On machines which have a byte order which is the same as the network
+order, routines are defined as null macros.
+.Pp
+These routines are most often used in conjunction with Internet
+addresses and ports as returned by
+.Xr gethostbyname 3
+and
+.Xr getservent 3 .
+.Sh SEE ALSO
+.Xr gethostbyname 3 ,
+.Xr getservent 3
+.Sh HISTORY
+The
+.Nm byteorder
+functions appeared in
+.Bx 4.2 .
+.Sh BUGS
+On the
+.Tn VAX
+bytes are handled backwards from most everyone else in
+the world. This is not expected to be fixed in the near future.
diff --git a/cpukit/libnetworking/libc/ether_addr.c b/cpukit/libnetworking/libc/ether_addr.c
new file mode 100644
index 0000000000..3cd0bb258e
--- /dev/null
+++ b/cpukit/libnetworking/libc/ether_addr.c
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 1995
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * ethernet address conversion and lookup routines
+ *
+ * Written by Bill Paul <wpaul@ctr.columbia.edu>
+ * Center for Telecommunications Research
+ * Columbia University, New York City
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <paths.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <net/ethernet.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#ifndef _PATH_ETHERS
+#define _PATH_ETHERS "/etc/ethers"
+#endif
+
+/*
+ * Parse a string of text containing an ethernet address and hostname
+ * and separate it into its component parts.
+ */
+int ether_line(l, e, hostname)
+ char *l;
+ struct ether_addr *e;
+ char *hostname;
+{
+ int i, o[6];
+
+ i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2],
+ &o[3], &o[4], &o[5],
+ hostname);
+ if (i != 7)
+ return (i);
+
+ for (i=0; i<6; i++)
+ e->octet[i] = o[i];
+ return (0);
+}
+
+/*
+ * Convert an ASCII representation of an ethernet address to
+ * binary form.
+ */
+struct ether_addr *ether_aton(a)
+ char *a;
+{
+ int i;
+ static struct ether_addr o;
+ unsigned int o0, o1, o2, o3, o4, o5;
+
+ i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5);
+
+ if (i != 6)
+ return (NULL);
+
+ o.octet[0]=o0;
+ o.octet[1]=o1;
+ o.octet[2]=o2;
+ o.octet[3]=o3;
+ o.octet[4]=o4;
+ o.octet[5]=o5;
+
+ return ((struct ether_addr *)&o);
+}
+
+/*
+ * Convert a binary representation of an ethernet address to
+ * an ASCII string.
+ */
+char *ether_ntoa(n)
+ struct ether_addr *n;
+{
+ int i;
+ static char a[18];
+
+ i = sprintf(a,"%x:%x:%x:%x:%x:%x",n->octet[0],n->octet[1],n->octet[2],
+ n->octet[3],n->octet[4],n->octet[5]);
+ if (i < 11)
+ return (NULL);
+ return ((char *)&a);
+}
+
+/*
+ * Map an ethernet address to a hostname. Use either /etc/ethers or
+ * NIS/YP.
+ */
+
+int ether_ntohost(hostname, e)
+ char *hostname;
+ struct ether_addr *e;
+{
+ FILE *fp;
+ char buf[BUFSIZ + 2];
+ struct ether_addr local_ether;
+ char local_host[MAXHOSTNAMELEN];
+#ifdef YP
+ char *result;
+ int resultlen;
+ char *ether_a;
+ char *yp_domain;
+#endif
+ if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
+ return (1);
+
+ while (fgets(buf,BUFSIZ,fp)) {
+ if (buf[0] == '#')
+ continue;
+#ifdef YP
+ if (buf[0] == '+') {
+ if (yp_get_default_domain(&yp_domain))
+ continue;
+ ether_a = ether_ntoa(e);
+ if (yp_match(yp_domain, "ethers.byaddr", ether_a,
+ strlen(ether_a), &result, &resultlen)) {
+ continue;
+ }
+ strncpy(buf, result, resultlen);
+ buf[resultlen] = '\0';
+ free(result);
+ }
+#endif
+ if (!ether_line(buf, &local_ether, local_host)) {
+ if (!bcmp((char *)&local_ether.octet[0],
+ (char *)&e->octet[0], 6)) {
+ /* We have a match */
+ strcpy(hostname, local_host);
+ fclose(fp);
+ return(0);
+ }
+ }
+ }
+ fclose(fp);
+ return (1);
+}
+
+/*
+ * Map a hostname to an ethernet address using /etc/ethers or
+ * NIS/YP.
+ */
+int ether_hostton(hostname, e)
+ char *hostname;
+ struct ether_addr *e;
+{
+ FILE *fp;
+ char buf[BUFSIZ + 2];
+ struct ether_addr local_ether;
+ char local_host[MAXHOSTNAMELEN];
+#ifdef YP
+ char *result;
+ int resultlen;
+ char *yp_domain;
+#endif
+ if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
+ return (1);
+
+ while (fgets(buf,BUFSIZ,fp)) {
+ if (buf[0] == '#')
+ continue;
+#ifdef YP
+ if (buf[0] == '+') {
+ if (yp_get_default_domain(&yp_domain))
+ continue;
+ if (yp_match(yp_domain, "ethers.byname", hostname,
+ strlen(hostname), &result, &resultlen)) {
+ continue;
+ }
+ strncpy(buf, result, resultlen);
+ buf[resultlen] = '\0';
+ free(result);
+ }
+#endif
+ if (!ether_line(buf, &local_ether, local_host)) {
+ if (!strcmp(hostname, local_host)) {
+ /* We have a match */
+ bcopy((char *)&local_ether.octet[0],
+ (char *)&e->octet[0], 6);
+ fclose(fp);
+ return(0);
+ }
+ }
+ }
+ fclose(fp);
+ return (1);
+}
diff --git a/cpukit/libnetworking/libc/ethers.3 b/cpukit/libnetworking/libc/ethers.3
new file mode 100644
index 0000000000..afea48320a
--- /dev/null
+++ b/cpukit/libnetworking/libc/ethers.3
@@ -0,0 +1,193 @@
+.\" Copyright (c) 1995
+.\" Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Bill Paul.
+.\" 4. Neither the name of the author nor the names of any co-contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $Id$
+.\"
+.Dd April 12, 1995
+.Dt ETHERS 3
+.Os FreeBSD 2.1
+.Sh NAME
+.Nm ethers ,
+.Nm ether_line ,
+.Nm ether_aton ,
+.Nm ether_ntoa ,
+.Nm ether_ntohost ,
+.Nm ether_hostton
+.Nd Ethernet address conversion and lookup routines
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
+.Fd #include <net/ethernet.h>
+.Ft int
+.Fn ether_line "char *l" "struct ether_addr *e" "char *hostname"
+.Ft struct ether_addr *
+.Fn ether_aton "char *a"
+.Ft char *
+.Fn ether_ntoa "struct ether_addr *n"
+.Ft int
+.Fn ether_ntohost "char *hostname" "struct ether_addr *e"
+.Ft int
+.Fn ether_hostton "char *hostname" "struct ether_addr *e"
+.Sh DESCRIPTION
+These functions operate on ethernet addresses using an
+.Ar ether_addr
+structure, which is defined in the header file
+.Aq Pa netinet/if_ether.h :
+.Bd -literal -offset indent
+/*
+ * The number of bytes in an ethernet (MAC) address.
+ */
+#define ETHER_ADDR_LEN 6
+
+/*
+ * Structure of a 48-bit Ethernet address.
+ */
+struct ether_addr {
+ u_char octet[ETHER_ADDR_LEN];
+};
+.Ed
+.Pp
+The function
+.Fn ether_line
+scans
+.Ar l ,
+an
+.Tn ASCII
+string in
+.Xr ethers 5
+format and sets
+.Ar e
+to the ethernet address specified in the string and
+.Ar h
+to the hostname. This function is used to parse lines from
+.Pa /etc/ethers
+into their component parts.
+.Pp
+The
+.Fn ether_aton
+function converts an
+.Tn ASCII
+representation of an ethernet address into an
+.Ar ether_addr
+structure. Likewise,
+.Fn ether_ntoa
+converts an ethernet address specified as an
+.Ar ether_addr
+structure into an
+.Tn ASCII
+string.
+.Pp
+The
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions map ethernet addresses to their corresponding hostnames
+as specified in the
+.Pa /etc/ethers
+database.
+.Fn ether_ntohost
+converts from ethernet address to hostname, and
+.Fn ether_hostton
+converts from hostname to ethernet address.
+.Sh RETURN VALUES
+.Fn ether_line
+returns zero on success and non-zero if it was unable to parse
+any part of the supplied line
+.Ar l .
+It returns the extracted ethernet address in the supplied
+.Ar ether_addr
+structure
+.Ar e
+and the hostname in the supplied string
+.Ar h .
+.Pp
+On success,
+.Fn ether_ntoa
+returns a pointer to a string containing an
+.Tn ASCII
+representation of an ethernet address. If it is unable to convert
+the supplied
+.Ar ether_addr
+structure, it returns a
+.Dv NULL
+pointer. Likewise,
+.Fn ether_aton
+returns a pointer to an
+.Ar ether_addr
+structure on success and a
+.Dv NULL
+pointer on failure.
+.Pp
+The
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions both return zero on success or non-zero if they were
+unable to find a match in the
+.Pa /etc/ethers
+database.
+.Sh NOTES
+The user must insure that the hostname strings passed to the
+the
+.Fn ether_line ,
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions are large enough to contain the returned hostnames.
+.Sh NIS INTERACTION
+If the
+.Pa /etc/ethers
+contains a line with a single + in it, the
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions will attempt to consult the NIS
+.Pa ethers.byname
+and
+.Pa ethers.byaddr
+maps in addition to the data in the
+.Pa /etc/ethers
+file.
+.Sh SEE ALSO
+.Xr yp 4 ,
+.Xr ethers 5
+.Sh BUGS
+.Pp
+The
+.Fn ether_aton
+and
+.Fn ether_ntoa
+functions returns values that are stored in static memory areas
+which may be overwritten the next time they are called.
+.Sh HISTORY
+This particular implementation of the
+.Nm ethers
+library functions were written for and first appeared in
+.Fx 2.1 .
diff --git a/cpukit/libnetworking/libc/gethostbydns.c b/cpukit/libnetworking/libc/gethostbydns.c
new file mode 100644
index 0000000000..38a0cdc6d6
--- /dev/null
+++ b/cpukit/libnetworking/libc/gethostbydns.c
@@ -0,0 +1,775 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <syslog.h>
+
+#include "res_config.h"
+
+void abort(void); /* to avoid warning */
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+static const char AskedForGot[] =
+ "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
+
+static char *h_addr_ptrs[MAXADDRS + 1];
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[8*1024];
+static u_char host_addr[16]; /* IPv4 or IPv6 */
+
+#ifdef RESOLVSORT
+static void addrsort(char **, int);
+#endif
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+ int32_t al;
+ char ac;
+} align;
+
+extern int h_errno;
+int _dns_ttl_;
+
+#ifdef DEBUG
+static void
+debugprintf(
+ char *msg,
+ int num)
+{
+ if (_res.options & RES_DEBUG) {
+ int save = errno;
+
+ printf(msg, num);
+ errno = save;
+ }
+}
+#else
+#define debugprintf(msg, num) /*nada*/
+#endif
+
+#define BOUNDED_INCR(x) \
+ do { \
+ cp += x; \
+ if (cp > eom) { \
+ h_errno = NO_RECOVERY; \
+ return (NULL); \
+ } \
+ } while (0)
+
+#define BOUNDS_CHECK(ptr, count) \
+ do { \
+ if ((ptr) + (count) > eom) { \
+ h_errno = NO_RECOVERY; \
+ return (NULL); \
+ } \
+ } while (0)
+
+static struct hostent *
+gethostanswer(
+ const querybuf *answer,
+ int anslen,
+ const char *qname,
+ int qtype)
+{
+ const HEADER *hp;
+ const u_char *cp;
+ int n;
+ const u_char *eom, *erdata;
+ char *bp, **ap, **hap;
+ int type, class, buflen, ancount, qdcount;
+ int haveanswer, had_error;
+ int toobig = 0;
+ char tbuf[MAXDNAME];
+ const char *tname;
+ int (*name_ok)(const char *);
+
+ tname = qname;
+ host.h_name = NULL;
+ eom = answer->buf + anslen;
+ switch (qtype) {
+ case T_A:
+ case T_AAAA:
+ name_ok = res_hnok;
+ break;
+ case T_PTR:
+ name_ok = res_dnok;
+ break;
+ default:
+ h_errno = NO_RECOVERY;
+ return (NULL); /* XXX should be abort(); */
+ }
+ /*
+ * find first satisfactory answer
+ */
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount);
+ qdcount = ntohs(hp->qdcount);
+ bp = hostbuf;
+ buflen = sizeof hostbuf;
+ cp = answer->buf;
+ BOUNDED_INCR(HFIXEDSZ);
+ if (qdcount != 1) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !(*name_ok)(bp)) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ BOUNDED_INCR(n + QFIXEDSZ);
+ if (qtype == T_A || qtype == T_AAAA) {
+ /* res_send() has already verified that the query name is the
+ * same as the one we sent; this just gets the expanded name
+ * (i.e., with the succeeding search-domain tacked on).
+ */
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ /* The qname can be abbreviated, but h_name is now absolute. */
+ qname = host.h_name;
+ }
+ ap = host_aliases;
+ *ap = NULL;
+ host.h_aliases = host_aliases;
+ hap = h_addr_ptrs;
+ *hap = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ haveanswer = 0;
+ had_error = 0;
+ _dns_ttl_ = -1;
+ while (ancount-- > 0 && cp < eom && !had_error) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !(*name_ok)(bp)) {
+ had_error++;
+ continue;
+ }
+ cp += n; /* name */
+ BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
+ type = _getshort(cp);
+ cp += INT16SZ; /* type */
+ class = _getshort(cp);
+ cp += INT16SZ; /* class */
+ if (qtype == T_A && type == T_A)
+ _dns_ttl_ = _getlong(cp);
+ cp += INT32SZ; /* TTL */
+ n = _getshort(cp);
+ cp += INT16SZ; /* len */
+ BOUNDS_CHECK(cp, n);
+ erdata = cp + n;
+ if (class != C_IN) {
+ /* XXX - debug? syslog? */
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
+ if (ap >= &host_aliases[MAXALIASES-1])
+ continue;
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if ((n < 0) || !(*name_ok)(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ /* Store alias. */
+ *ap++ = bp;
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ bp += n;
+ buflen -= n;
+ /* Get canonical name. */
+ n = strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
+ if (qtype == T_PTR && type == T_CNAME) {
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if (n < 0 || !res_dnok(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ /* Get canonical name. */
+ n = strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ tname = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
+ if (type != qtype) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
+ qname, p_class(C_IN), p_type(qtype),
+ p_type(type));
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ switch (type) {
+ case T_PTR:
+ if (strcasecmp(tname, bp) != 0) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ AskedForGot, qname, bp);
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_hnok(bp)) {
+ had_error++;
+ break;
+ }
+#if MULTI_PTRS_ARE_ALIASES
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ if (!haveanswer)
+ host.h_name = bp;
+ else if (ap < &host_aliases[MAXALIASES-1])
+ *ap++ = bp;
+ else
+ n = -1;
+ if (n != -1) {
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ break;
+ }
+ bp += n;
+ buflen -= n;
+ }
+ break;
+#else
+ host.h_name = bp;
+ if (_res.options & RES_USE_INET6) {
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ break;
+ }
+ bp += n;
+ buflen -= n;
+ _map_v4v6_hostent(&host, &bp, &buflen);
+ }
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+#endif
+ case T_A:
+ case T_AAAA:
+ if (strcasecmp(host.h_name, bp) != 0) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ AskedForGot, host.h_name, bp);
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if (n != host.h_length) {
+ cp += n;
+ continue;
+ }
+ if (!haveanswer) {
+ register int nn;
+
+ host.h_name = bp;
+ nn = strlen(bp) + 1; /* for the \0 */
+ bp += nn;
+ buflen -= nn;
+ }
+
+ bp += sizeof(align) - ((uintptr_t)bp % sizeof(align));
+
+ if (bp + n >= &hostbuf[sizeof hostbuf]) {
+ debugprintf("size (%d) too big\n", n);
+ had_error++;
+ continue;
+ }
+ if (hap >= &h_addr_ptrs[MAXADDRS-1]) {
+ if (!toobig++)
+ debugprintf("Too many addresses (%d)\n",
+ MAXADDRS);
+ cp += n;
+ continue;
+ }
+ memcpy(*hap++ = bp, cp, n);
+ bp += n;
+ buflen -= n;
+ cp += n;
+ if (cp != erdata) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ break;
+ default:
+ debugprintf("Impossible condition (type=%d)\n", type);
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ /* BIND has abort() here, too risky on bad data */
+ }
+ if (!had_error)
+ haveanswer++;
+ }
+ if (haveanswer) {
+ *ap = NULL;
+ *hap = NULL;
+# if defined(RESOLVSORT)
+ /*
+ * Note: we sort even if host can take only one address
+ * in its return structures - should give it the "best"
+ * address in that case, not some random one
+ */
+ if (_res.nsort && haveanswer > 1 && qtype == T_A)
+ addrsort(h_addr_ptrs, haveanswer);
+# endif /*RESOLVSORT*/
+ if (!host.h_name) {
+ n = strlen(qname) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN)
+ goto no_recovery;
+ strcpy(bp, qname);
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ }
+ if (_res.options & RES_USE_INET6)
+ _map_v4v6_hostent(&host, &bp, &buflen);
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ no_recovery:
+ h_errno = NO_RECOVERY;
+ return (NULL);
+}
+
+struct hostent *
+__dns_getanswer(const char *answer, int anslen, const char *qname, int qtype)
+{
+ switch(qtype) {
+ case T_AAAA:
+ host.h_addrtype = AF_INET6;
+ host.h_length = IN6ADDRSZ;
+ break;
+ case T_A:
+ default:
+ host.h_addrtype = AF_INET;
+ host.h_length = INADDRSZ;
+ break;
+ }
+
+ return(gethostanswer((const querybuf *)answer, anslen, qname, qtype));
+}
+
+struct hostent *
+_gethostbydnsname(
+ const char *name,
+ int af)
+{
+ querybuf buf;
+ register const char *cp;
+ char *bp;
+ int n, size, type, len;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+
+ switch (af) {
+ case AF_INET:
+ size = INADDRSZ;
+ type = T_A;
+ break;
+ case AF_INET6:
+ size = IN6ADDRSZ;
+ type = T_AAAA;
+ break;
+ default:
+ h_errno = NETDB_INTERNAL;
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+
+ host.h_addrtype = af;
+ host.h_length = size;
+
+ /*
+ * if there aren't any dots, it could be a user-level alias.
+ * this is also done in res_query() since we are not the only
+ * function that looks up host names.
+ */
+ if (!strchr(name, '.') && (cp = __hostalias(name)))
+ name = cp;
+
+ /*
+ * disallow names consisting only of digits/dots, unless
+ * they end in a dot.
+ */
+ if (isdigit((unsigned char)name[0]))
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-numeric, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (inet_pton(af, name, host_addr) <= 0) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ bp = hostbuf + MAXDNAME;
+ len = sizeof hostbuf - MAXDNAME;
+ host.h_name = hostbuf;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ if (_res.options & RES_USE_INET6)
+ _map_v4v6_hostent(&host, &bp, &len);
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ if (!isdigit((unsigned char)*cp) && *cp != '.')
+ break;
+ }
+ if ((isxdigit((unsigned char)name[0]) && strchr(name, ':') != NULL) ||
+ name[0] == ':')
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-IPv6-legal, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (inet_pton(af, name, host_addr) <= 0) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ bp = hostbuf + MAXDNAME;
+ len = sizeof hostbuf - MAXDNAME;
+ host.h_name = hostbuf;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ if (!isxdigit((unsigned char)*cp) && *cp != ':' && *cp != '.')
+ break;
+ }
+
+ if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
+ debugprintf("res_search failed (%d)\n", n);
+ return (NULL);
+ }
+ return (gethostanswer(&buf, n, name, type));
+}
+
+struct hostent *
+_gethostbydnsaddr(
+ const char *addr, /* XXX should have been def'd as u_char! */
+ int len,
+ int af)
+{
+ const u_char *uaddr = (const u_char *)addr;
+ static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
+ static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
+ int n, size;
+ querybuf buf;
+ register struct hostent *hp;
+ char qbuf[MAXDNAME+1], *qp;
+#ifdef SUNSECURITY
+ register struct hostent *rhp;
+ char **haddr;
+ u_long old_options;
+ char hname2[MAXDNAME+1];
+#endif /*SUNSECURITY*/
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ if (af == AF_INET6 && len == IN6ADDRSZ &&
+ (!bcmp(uaddr, mapped, sizeof mapped) ||
+ !bcmp(uaddr, tunnelled, sizeof tunnelled))) {
+ /* Unmap. */
+ addr += sizeof mapped;
+ uaddr += sizeof mapped;
+ af = AF_INET;
+ len = INADDRSZ;
+ }
+ switch (af) {
+ case AF_INET:
+ size = INADDRSZ;
+ break;
+ case AF_INET6:
+ size = IN6ADDRSZ;
+ break;
+ default:
+ errno = EAFNOSUPPORT;
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ if (size != len) {
+ errno = EINVAL;
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ switch (af) {
+ case AF_INET:
+ (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+ (uaddr[3] & 0xff),
+ (uaddr[2] & 0xff),
+ (uaddr[1] & 0xff),
+ (uaddr[0] & 0xff));
+ break;
+ case AF_INET6:
+ qp = qbuf;
+ for (n = IN6ADDRSZ - 1; n >= 0; n--) {
+ qp += SPRINTF((qp, "%x.%x.",
+ uaddr[n] & 0xf,
+ (uaddr[n] >> 4) & 0xf));
+ }
+ strcpy(qp, "ip6.int");
+ break;
+ default:
+ abort();
+ }
+ n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
+ if (n < 0) {
+ debugprintf("res_query failed (%d)\n", n);
+ return (NULL);
+ }
+ if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR)))
+ return (NULL); /* h_errno was set by gethostanswer() */
+#ifdef SUNSECURITY
+ if (af == AF_INET) {
+ /*
+ * turn off search as the name should be absolute,
+ * 'localhost' should be matched by defnames
+ */
+ strncpy(hname2, hp->h_name, MAXDNAME);
+ hname2[MAXDNAME] = '\0';
+ old_options = _res.options;
+ _res.options &= ~RES_DNSRCH;
+ _res.options |= RES_DEFNAMES;
+ if (!(rhp = gethostbyname(hname2))) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostbyaddr: No A record for %s (verifying [%s])",
+ hname2, inet_ntoa(*((struct in_addr *)addr)));
+ _res.options = old_options;
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ _res.options = old_options;
+ for (haddr = rhp->h_addr_list; *haddr; haddr++)
+ if (!memcmp(*haddr, addr, INADDRSZ))
+ break;
+ if (!*haddr) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostbyaddr: A record of %s != PTR record [%s]",
+ hname2, inet_ntoa(*((struct in_addr *)addr)));
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ }
+#endif /*SUNSECURITY*/
+ hp->h_addrtype = af;
+ hp->h_length = len;
+ memcpy(host_addr, addr, len);
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ if (af == AF_INET && (_res.options & RES_USE_INET6)) {
+ _map_v4v6_address((char*)host_addr, (char*)host_addr);
+ hp->h_addrtype = AF_INET6;
+ hp->h_length = IN6ADDRSZ;
+ }
+ h_errno = NETDB_SUCCESS;
+ return (hp);
+}
+
+#ifdef RESOLVSORT
+static void
+addrsort(
+ char **ap,
+ int num)
+{
+ int i, j;
+ char **p;
+ short aval[MAXADDRS];
+ int needsort = 0;
+
+ p = ap;
+ for (i = 0; i < num; i++, p++) {
+ for (j = 0 ; (unsigned)j < _res.nsort; j++)
+ if (_res.sort_list[j].addr.s_addr ==
+ (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
+ break;
+ aval[i] = j;
+ if (needsort == 0 && i > 0 && j < aval[i-1])
+ needsort = i;
+ }
+ if (!needsort)
+ return;
+
+ while (needsort < num) {
+ for (j = needsort - 1; j >= 0; j--) {
+ if (aval[j] > aval[j+1]) {
+ char *hp;
+
+ i = aval[j];
+ aval[j] = aval[j+1];
+ aval[j+1] = i;
+
+ hp = ap[j];
+ ap[j] = ap[j+1];
+ ap[j+1] = hp;
+
+ } else
+ break;
+ }
+ needsort++;
+ }
+}
+#endif
+
+void
+_sethostdnsent(int stayopen)
+{
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+ if (stayopen)
+ _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+_endhostdnsent(void)
+{
+ _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+ res_close();
+}
diff --git a/cpukit/libnetworking/libc/gethostbyht.c b/cpukit/libnetworking/libc/gethostbyht.c
new file mode 100644
index 0000000000..4228b1c8c8
--- /dev/null
+++ b/cpukit/libnetworking/libc/gethostbyht.c
@@ -0,0 +1,318 @@
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h> /* realloc, malloc, free */
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <arpa/nameser.h> /* XXX */
+#include <resolv.h> /* XXX */
+#include <sys/fcntl.h>
+
+#define MAXALIASES 35
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[BUFSIZ+1];
+static FILE *hostf = NULL;
+static u_char host_addr[16]; /* IPv4 or IPv6 */
+static char *h_addr_ptrs[2];
+static int stayopen = 0;
+
+#ifdef _THREAD_SAFE
+static char* hostmap = NULL;
+static unsigned int hostlen = 0;
+static char *cur;
+#endif
+
+void
+_sethosthtent(int f)
+{
+ if (!hostf)
+ hostf = fopen(_PATH_HOSTS, "r" );
+ else
+ rewind(hostf);
+ stayopen = f;
+}
+
+void
+_endhosthtent(void)
+{
+ if (hostf && !stayopen) {
+ (void) fclose(hostf);
+ hostf = NULL;
+ }
+}
+
+struct hostent *
+gethostent(void)
+{
+ char *p;
+ register char *cp, **q;
+ int af, len;
+
+ if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ again:
+ if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ if (*p == '#')
+ goto again;
+ if (!(cp = strpbrk(p, "#\n")))
+ goto again;
+ *cp = '\0';
+ if (!(cp = strpbrk(p, " \t")))
+ goto again;
+ *cp++ = '\0';
+ if (inet_pton(AF_INET6, p, host_addr) > 0) {
+ af = AF_INET6;
+ len = IN6ADDRSZ;
+ } else if (inet_pton(AF_INET, p, host_addr) > 0) {
+ if (_res.options & RES_USE_INET6) {
+ _map_v4v6_address((char*)host_addr, (char*)host_addr);
+ af = AF_INET6;
+ len = IN6ADDRSZ;
+ } else {
+ af = AF_INET;
+ len = INADDRSZ;
+ }
+ } else {
+ goto again;
+ }
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ host.h_length = len;
+ host.h_addrtype = af;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ host.h_name = cp;
+ q = host.h_aliases = host_aliases;
+ if ((cp = strpbrk(cp, " \t")) != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ if ((cp = strpbrk(cp, " \t")) != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+}
+
+struct hostent *
+_gethostbyhtname(
+ const char *name,
+ int af)
+{
+ register struct hostent *p;
+ register char **cp;
+
+ sethostent(0);
+ while ((p = gethostent()) != NULL) {
+ if (p->h_addrtype != af)
+ continue;
+ if (strcasecmp(p->h_name, name) == 0)
+ break;
+ for (cp = p->h_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ endhostent();
+ return (p);
+}
+
+struct hostent *
+_gethostbyhtaddr(
+ const char *addr,
+ int len,
+ int af)
+{
+ register struct hostent *p;
+
+ sethostent(0);
+ while ((p = gethostent()) != NULL)
+ if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
+ break;
+ endhostent();
+ return (p);
+}
+
+
+#ifdef _THREAD_SAFE
+struct hostent* gethostent_r(char* buf, int len)
+{
+ char *dest;
+ struct hostent* pe=(struct hostent*)buf;
+ char* last;
+ char* max=buf+len;
+ int aliasidx;
+ int curlen;
+
+
+ if (hostf<0) return 0;
+ fseek(hostf,0,SEEK_END);
+ curlen=ftell(hostf);
+ fseek(hostf,0,SEEK_SET);
+
+ if (curlen > hostlen) {
+ if (hostmap) {
+ hostmap = realloc(hostmap,curlen);
+ }
+ else {
+ hostmap = malloc(curlen);
+ }
+ }
+ hostlen = curlen;
+
+ if (hostmap) {
+ if (fread(hostmap,hostlen,1,hostf) != hostlen) {
+ hostmap=0; goto error;
+ }
+ cur=hostmap;
+ }
+ last=hostmap+hostlen;
+again:
+ if ((size_t)len<sizeof(struct hostent)+11*sizeof(char*)) goto nospace;
+ dest=buf+sizeof(struct hostent);
+ pe->h_name=0;
+ pe->h_aliases=(char**)dest; pe->h_aliases[0]=0; dest+=10*sizeof(char*);
+ pe->h_addr_list=(char**)dest; dest+=2*sizeof(char**);
+ if (cur>=last) return 0;
+ if (*cur=='#' || *cur=='\n') goto parseerror;
+ /* first, the ip number */
+ pe->h_name=cur;
+ while (cur<last && !isspace((unsigned char)*cur)) cur++;
+ if (cur>=last) return 0;
+ if (*cur=='\n') goto parseerror;
+ {
+ char save=*cur;
+ *cur=0;
+ pe->h_addr_list[0]=dest;
+ pe->h_addr_list[1]=0;
+ if (max-dest<16) goto nospace;
+ if (inet_pton(AF_INET6,pe->h_name,dest)>0) {
+ pe->h_addrtype=AF_INET6;
+ pe->h_length=16;
+ dest+=16;
+ } else if (inet_pton(AF_INET,pe->h_name,dest)>0) {
+ pe->h_addrtype=AF_INET;
+ pe->h_length=4;
+ dest+=4;
+ } else {
+ *cur=save;
+ goto parseerror;
+ }
+ *cur=save;
+ }
+ ++cur;
+ /* now the aliases */
+ for (aliasidx=0;aliasidx<9;++aliasidx) {
+ while (cur<last && isblank((unsigned char)*cur)) ++cur;
+ pe->h_aliases[aliasidx]=cur;
+ while (cur<last && !isspace((unsigned char)*cur)) ++cur;
+ {
+ char *from=pe->h_aliases[aliasidx];
+ int len=cur-from;
+ if (max-dest<len+2) goto nospace;
+ pe->h_aliases[aliasidx]=dest;
+ memmove(dest,from,(size_t)(cur-from));
+ dest+=len;
+ *dest=0; ++dest;
+ }
+ if (*cur=='\n') { ++cur; ++aliasidx; break; }
+ if (cur>=last || !isblank((unsigned char)*cur)) break;
+ cur++;
+ }
+ pe->h_aliases[aliasidx]=0;
+ pe->h_name=pe->h_aliases[0];
+ pe->h_aliases++;
+ return pe;
+parseerror:
+ while (cur<last && *cur!='\n') cur++;
+ cur++;
+ goto again;
+nospace:
+ errno=ERANGE;
+ goto __error;
+error:
+ errno=ENOMEM;
+__error:
+ if (hostmap!=NULL) free(hostmap);
+ hostmap=NULL;
+ return 0;
+}
+#endif
diff --git a/cpukit/libnetworking/libc/gethostbyname.3 b/cpukit/libnetworking/libc/gethostbyname.3
new file mode 100644
index 0000000000..e21dc79f1d
--- /dev/null
+++ b/cpukit/libnetworking/libc/gethostbyname.3
@@ -0,0 +1,305 @@
+.\" Copyright (c) 1983, 1987, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
+.\" $Id$
+.\"
+.Dd May 25, 1995
+.Dt GETHOSTBYNAME 3
+.Os BSD 4.2
+.Sh NAME
+.Nm gethostbyname ,
+.Nm gethostbyname2 ,
+.Nm gethostbyaddr ,
+.Nm gethostent ,
+.Nm sethostent ,
+.Nm endhostent ,
+.Nm herror ,
+.Nm hstrerror
+.Nd get network host entry
+.Sh SYNOPSIS
+.Fd #include <netdb.h>
+.Vt extern int h_errno;
+.Ft struct hostent *
+.Fn gethostbyname "const char *name"
+.Ft struct hostent *
+.Fn gethostbyname2 "const char *name" "int af"
+.Ft struct hostent *
+.Fn gethostbyaddr "const char *addr" "int len" "int type"
+.Ft struct hostent *
+.Fn gethostent void
+.Ft void
+.Fn sethostent "int stayopen"
+.Ft void
+.Fn endhostent void
+.Ft void
+.Fn herror "const char *string"
+.Ft const char *
+.Fn hstrerror "int err"
+.Sh DESCRIPTION
+The
+.Fn gethostbyname ,
+.Fn gethostbyname2
+and
+.Fn gethostbyaddr
+functions
+each return a pointer to an object with the
+following structure describing an internet host
+referenced by name or by address, respectively.
+This structure contains either the information obtained from the name server,
+.Xr named 8 ,
+or broken-out fields from a line in
+.Pa /etc/hosts .
+If the local name server is not running these routines do a lookup in
+.Pa /etc/hosts .
+.Bd -literal
+struct hostent {
+ char *h_name; /* official name of host */
+ char **h_aliases; /* alias list */
+ int h_addrtype; /* host address type */
+ int h_length; /* length of address */
+ char **h_addr_list; /* list of addresses from name server */
+};
+#define h_addr h_addr_list[0] /* address, for backward compatibility */
+.Ed
+.Pp
+The members of this structure are:
+.Bl -tag -width h_addr_list
+.It Fa h_name
+Official name of the host.
+.It Fa h_aliases
+A NULL-terminated array of alternate names for the host.
+.It Fa h_addrtype
+The type of address being returned; usually
+.Dv AF_INET .
+.It Fa h_length
+The length, in bytes, of the address.
+.It Fa h_addr_list
+A NULL-terminated array of network addresses for the host.
+Host addresses are returned in network byte order.
+.It Fa h_addr
+The first address in
+.Fa h_addr_list ;
+this is for backward compatibility.
+.El
+.Pp
+When using the nameserver,
+.Fn gethostbyname
+and
+.Fn gethostbyname
+will search for the named host in the current domain and its parents
+unless the name ends in a dot.
+If the name contains no dot, and if the environment variable
+.Dq Ev HOSTALIASES
+contains the name of an alias file, the alias file will first be searched
+for an alias matching the input name.
+See
+.Xr hostname 7
+for the domain search procedure and the alias file format.
+.Pp
+The
+.Fn gethostbyname2
+function is an evolution of
+.Fn gethostbyname
+which is intended to allow lookups in address families other than
+.Dv AF_INET ,
+for example
+.Dv AF_INET6 .
+Currently the
+.Fa af
+argument must be specified as
+.Dv AF_INET
+else the function will return
+.Dv NULL
+after having set
+.Va h_errno
+to
+.Dv NETDB_INTERNAL
+.Pp
+The
+.Fn sethostent
+function
+may be used to request the use of a connected
+.Tn TCP
+socket for queries.
+If the
+.Fa stayopen
+flag is non-zero,
+this sets the option to send all queries to the name server using
+.Tn TCP
+and to retain the connection after each call to
+.Fn gethostbyname ,
+.Fn gethostbyname2
+or
+.Fn gethostbyaddr .
+Otherwise, queries are performed using
+.Tn UDP
+datagrams.
+.Pp
+The
+.Fn endhostent
+function
+closes the
+.Tn TCP
+connection.
+.Pp
+The
+.Fn herror
+function writes a message to the diagnostic output consisting of the
+string parameter
+.Fa s ,
+the constant string ": ", and a message corresponding to the value of
+.Va h_errno .
+.Pp
+The
+.Fn hstrerror
+function returns a string which is the message text corresponding to the
+value of the
+.Fa err
+parameter.
+.Sh FILES
+.Bl -tag -width /etc/resolv.conf -compact
+.It Pa /etc/hosts
+.It Pa /etc/host.conf
+.It Pa /etc/resolv.conf
+.El
+.Sh DIAGNOSTICS
+Error return status from
+.Fn gethostbyname ,
+.Fn gethostbyname2
+and
+.Fn gethostbyaddr
+is indicated by return of a null pointer.
+The external integer
+.Va h_errno
+may then be checked to see whether this is a temporary failure
+or an invalid or unknown host.
+The routine
+.Fn herror
+can be used to print an error message describing the failure.
+If its argument
+.Fa string
+is
+.Pf non Dv -NULL ,
+it is printed, followed by a colon and a space.
+The error message is printed with a trailing newline.
+.Pp
+The variable
+.Va h_errno
+can have the following values:
+.Bl -tag -width HOST_NOT_FOUND
+.It Dv HOST_NOT_FOUND
+No such host is known.
+.It Dv TRY_AGAIN
+This is usually a temporary error
+and means that the local server did not receive
+a response from an authoritative server.
+A retry at some later time may succeed.
+.It Dv NO_RECOVERY
+Some unexpected server failure was encountered.
+This is a non-recoverable error.
+.It Dv NO_DATA
+The requested name is valid but does not have an IP address;
+this is not a temporary error.
+This means that the name is known to the name server but there is no address
+associated with this name.
+Another type of request to the name server using this domain name
+will result in an answer;
+for example, a mail-forwarder may be registered for this domain.
+.El
+.Sh SEE ALSO
+.Xr resolver 3 ,
+.Xr hosts 5 ,
+.Xr hostname 7 ,
+.Xr named 8
+.Sh CAVEAT
+The
+.Fn gethostent
+function
+is defined, and
+.Fn sethostent
+and
+.Fn endhostent
+are redefined,
+when
+.Xr libc 3
+is built to use only the routines to lookup in
+.Pa /etc/hosts
+and not the name server.
+.Pp
+The
+.Fn gethostent
+function
+reads the next line of
+.Pa /etc/hosts ,
+opening the file if necessary.
+.Pp
+The
+.Fn sethostent
+function
+opens and/or rewinds the file
+.Pa /etc/hosts .
+If the
+.Fa stayopen
+argument is non-zero,
+the file will not be closed after each call to
+.Fn gethostbyname ,
+.Fn gethostbyname2
+or
+.Fn gethostbyaddr .
+.Pp
+The
+.Fn endhostent
+function
+closes the file.
+.Sh HISTORY
+The
+.Fn herror
+function appeared in
+.Bx 4.3 .
+The
+.Fn endhostent ,
+.Fn gethostbyaddr ,
+.Fn gethostbyname ,
+.Fn gethostent ,
+and
+.Fn sethostent
+functions appeared in
+.Bx 4.2 .
+The
+.Fn gethostbyname2
+function first appeared in bind-4.9.4.
+.Sh BUGS
+These functions use static data storage;
+if the data is needed for future use, it should be
+copied before any subsequent calls overwrite it.
+Only the Internet
+address format is currently understood.
diff --git a/cpukit/libnetworking/libc/gethostbynis.c b/cpukit/libnetworking/libc/gethostbynis.c
new file mode 100644
index 0000000000..1ae2e4980b
--- /dev/null
+++ b/cpukit/libnetworking/libc/gethostbynis.c
@@ -0,0 +1,141 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+#ifdef YP
+static char *host_aliases[MAXALIASES];
+static char hostaddr[MAXADDRS];
+static char *host_addrs[2];
+#endif /* YP */
+
+static struct hostent *
+_gethostbynis(
+ const char *name,
+ char *map,
+ int af)
+{
+#ifdef YP
+ register char *cp, **q;
+ char *result;
+ int resultlen;
+ static struct hostent h;
+ static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD + 2];
+
+ switch(af) {
+ case AF_INET:
+ break;
+ default:
+ case AF_INET6:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ if (domain == (char *)NULL)
+ if (yp_get_default_domain (&domain))
+ return ((struct hostent *)NULL);
+
+ if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+ return ((struct hostent *)NULL);
+
+ /* avoid potential memory leak */
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ ypbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&ypbuf;
+
+ if ((cp = index(result, '\n')))
+ *cp = '\0';
+
+ cp = strpbrk(result, " \t");
+ *cp++ = '\0';
+ h.h_addr_list = host_addrs;
+ h.h_addr = hostaddr;
+ *((u_long *)h.h_addr) = inet_addr(result);
+ h.h_length = sizeof(u_long);
+ h.h_addrtype = AF_INET;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ h.h_name = cp;
+ q = h.h_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&h);
+#else
+ return (NULL);
+#endif /* YP */
+}
+
+struct hostent *
+_gethostbynisname(
+ const char *name,
+ int af)
+{
+ return _gethostbynis(name, "hosts.byname", af);
+}
+
+struct hostent *
+_gethostbynisaddr(
+ const char *addr,
+ int len,
+ int af)
+{
+ return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
+}
diff --git a/cpukit/libnetworking/libc/gethostnamadr.c b/cpukit/libnetworking/libc/gethostnamadr.c
new file mode 100644
index 0000000000..8d7dd0db62
--- /dev/null
+++ b/cpukit/libnetworking/libc/gethostnamadr.c
@@ -0,0 +1,429 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <arpa/nameser.h> /* XXX hack for _res */
+#include <resolv.h> /* XXX hack for _res */
+
+#define _PATH_HOSTCONF "/etc/host.conf"
+
+enum service_type {
+ SERVICE_NONE = 0,
+ SERVICE_BIND,
+ SERVICE_HOSTS,
+ SERVICE_NIS };
+#define SERVICE_MAX SERVICE_NIS
+
+static struct {
+ const char *name;
+ enum service_type type;
+} service_names[] = {
+ { "hosts", SERVICE_HOSTS },
+ { "/etc/hosts", SERVICE_HOSTS },
+ { "hosttable", SERVICE_HOSTS },
+ { "htable", SERVICE_HOSTS },
+ { "bind", SERVICE_BIND },
+ { "dns", SERVICE_BIND },
+ { "domain", SERVICE_BIND },
+ { "yp", SERVICE_NIS },
+ { "yellowpages", SERVICE_NIS },
+ { "nis", SERVICE_NIS },
+ { 0, SERVICE_NONE }
+};
+
+static enum service_type service_order[SERVICE_MAX + 1];
+static int service_done = 0;
+
+static enum service_type
+get_service_name(const char *name) {
+ int i;
+ for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
+ if(!strcasecmp(name, service_names[i].name)) {
+ return service_names[i].type;
+ }
+ }
+ return SERVICE_NONE;
+}
+
+static void
+init_services(void)
+{
+ char *cp, *p, buf[BUFSIZ];
+ register int cc = 0;
+ FILE *fd;
+
+ if ((fd = (FILE *)fopen(_PATH_HOSTCONF, "r")) == NULL) {
+ /* make some assumptions */
+ service_order[0] = SERVICE_BIND;
+ service_order[1] = SERVICE_HOSTS;
+ service_order[2] = SERVICE_NONE;
+ } else {
+ while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
+ if(buf[0] == '#')
+ continue;
+
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
+ do {
+ if (isalpha((unsigned char)cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
+ }
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
+ }
+ service_order[cc] = SERVICE_NONE;
+ fclose(fd);
+ }
+ service_done = 1;
+}
+
+struct hostent *
+gethostbyname(const char *name)
+{
+ struct hostent *hp;
+
+ if (_res.options & RES_USE_INET6) { /* XXX */
+ hp = gethostbyname2(name, AF_INET6); /* XXX */
+ if (hp) /* XXX */
+ return (hp); /* XXX */
+ } /* XXX */
+ return (gethostbyname2(name, AF_INET));
+}
+
+struct hostent *
+gethostbyname2(const char *name, int type)
+{
+ struct hostent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return NULL;
+ case SERVICE_HOSTS:
+ hp = _gethostbyhtname(name, type);
+ break;
+ case SERVICE_BIND:
+ hp = _gethostbydnsname(name, type);
+ break;
+ case SERVICE_NIS:
+ hp = _gethostbynisname(name, type);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+int gethostbyaddr_r(const void *addr, socklen_t len, int type,
+ struct hostent *ret, char *buf, size_t buflen,
+ struct hostent **result, int *h_errnop)
+{
+ #warning "implement a proper gethostbyaddr_r"
+
+ *result = gethostbyaddr( addr, len, type );
+ if ( *result )
+ return 0;
+ return -1;
+}
+
+struct hostent *
+gethostbyaddr(const void *addr, socklen_t len, int type)
+{
+ struct hostent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return 0;
+ case SERVICE_HOSTS:
+ hp = _gethostbyhtaddr(addr, len, type);
+ break;
+ case SERVICE_BIND:
+ hp = _gethostbydnsaddr(addr, len, type);
+ break;
+ case SERVICE_NIS:
+ hp = _gethostbynisaddr(addr, len, type);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+void
+sethostent(int stayopen)
+{
+ _sethosthtent(stayopen);
+ _sethostdnsent(stayopen);
+}
+
+void
+endhostent(void)
+{
+ _endhosthtent();
+ _endhostdnsent();
+}
+
+#ifdef _THREAD_SAFE
+
+/* return length of decoded data or -1 */
+static int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
+ unsigned int maxlen,unsigned char* behindpacket) {
+ unsigned char *tmp;
+ unsigned char *max=dest+maxlen;
+ unsigned char *after=packet+offset;
+ int ok=0;
+ for (tmp=after; maxlen>0&&*tmp; ) {
+ if (tmp>=behindpacket) return -1;
+ if ((*tmp>>6)==3) { /* goofy DNS decompression */
+ unsigned int ofs=((unsigned int)(*tmp&0x3f)<<8)|*(tmp+1);
+ if (ofs>=(unsigned int)offset) return -1; /* RFC1035: "pointer to a _prior_ occurrance" */
+ if (after<tmp+2) after=tmp+2;
+ tmp=packet+ofs;
+ ok=0;
+ } else {
+ unsigned int duh;
+ if (dest+*tmp+1>max) return -1;
+ if (tmp+*tmp+1>=behindpacket) return -1;
+ for (duh=*tmp; duh>0; --duh)
+ *dest++=*++tmp;
+ *dest++='.'; ok=1;
+ ++tmp;
+ if (tmp>after) { after=tmp; if (!*tmp) ++after; }
+ }
+ }
+ if (ok) --dest;
+ *dest=0;
+ return after-packet;
+}
+
+static int __dns_gethostbyx_r(
+ const char* name,
+ struct hostent* result,
+ char *buf, size_t buflen,
+ struct hostent **RESULT,
+ int *h_errnop,
+ int lookfor)
+{
+
+ int names,ips;
+ unsigned char *cur;
+ unsigned char *max;
+ unsigned char inpkg[1500];
+ char* tmp;
+ int size;
+
+ if (lookfor==1) {
+ result->h_addrtype=AF_INET;
+ result->h_length=4;
+ } else {
+ result->h_addrtype=AF_INET6;
+ result->h_length=16;
+ }
+ result->h_aliases=(char**)(buf+8*sizeof(char*));
+ result->h_addr_list=(char**)buf;
+ result->h_aliases[0]=0;
+
+ cur=(unsigned char*)buf+16*sizeof(char*);
+ max=(unsigned char*)buf+buflen;
+ names=ips=0;
+
+ if ((size=res_query(name,C_IN,lookfor,inpkg,512))<0) {
+invalidpacket:
+ *h_errnop=HOST_NOT_FOUND;
+ return -1;
+ }
+ {
+ tmp=(char*)inpkg+12;
+ {
+ char Name[257];
+ unsigned short q=((unsigned short)inpkg[4]<<8)+inpkg[5];
+ while (q>0) {
+ if (tmp>(char*)inpkg+size) goto invalidpacket;
+ while (*tmp) { tmp+=*tmp+1; if (tmp>(char*)inpkg+size) goto invalidpacket; }
+ tmp+=5;
+ --q;
+ }
+ if (tmp>(char*)inpkg+size) goto invalidpacket;
+ q=((unsigned short)inpkg[6]<<8)+inpkg[7];
+ if (q<1) goto nodata;
+ while (q>0) {
+ int decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),(unsigned char*)Name,256,inpkg+size);
+ if (decofs<0) break;
+ tmp=(char*)inpkg+decofs;
+ --q;
+ if (tmp[0]!=0 || tmp[1]!=lookfor || /* TYPE != A */
+ tmp[2]!=0 || tmp[3]!=1) { /* CLASS != IN */
+ if (tmp[1]==5) { /* CNAME */
+ tmp+=10;
+ decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),(unsigned char*)Name,256,inpkg+size);
+ if (decofs<0) break;
+ tmp=(char*)inpkg+decofs;
+ } else
+ break;
+ continue;
+ }
+ tmp+=10; /* skip type, class, TTL and length */
+ {
+ int slen;
+ if (lookfor==1 || lookfor==28) /* A or AAAA*/ {
+ slen=strlen(Name);
+ if (cur+slen+8+(lookfor==28?12:0)>=max) { *h_errnop=NO_RECOVERY; return -1; }
+ } else if (lookfor==12) /* PTR */ {
+ decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),(unsigned char*)Name,256,inpkg+size);
+ if (decofs<0) break;
+ tmp=(char*)inpkg+decofs;
+ slen=strlen(Name);
+ } else
+ slen=strlen(Name);
+ strcpy((char*)cur,Name);
+ if (names==0)
+ result->h_name=(char*)cur;
+ else
+ result->h_aliases[names-1]=(char*)cur;
+ result->h_aliases[names]=0;
+ if (names<8) ++names;
+/* cur+=slen+1; */
+ cur+=(slen|3)+1;
+ result->h_addr_list[ips++] = (char*)cur;
+ if (lookfor==1) /* A */ {
+ *(int*)cur=*(int*)tmp;
+ cur+=4;
+ result->h_addr_list[ips]=0;
+ } else if (lookfor==28) /* AAAA */ {
+ {
+ int k;
+ for (k=0; k<16; ++k) cur[k]=tmp[k];
+ }
+ cur+=16;
+ result->h_addr_list[ips]=0;
+ }
+ }
+/* puts(Name); */
+ }
+ }
+ }
+ if (!names) {
+nodata:
+ *h_errnop=NO_DATA;
+ return -1;
+ }
+ *h_errnop=0;
+ *RESULT=result;
+ return 0;
+}
+
+
+
+
+int gethostbyname_r(const char* name,
+ struct hostent* result,
+ char *buf,
+ int buflen,
+ struct hostent **RESULT,
+ int *h_errnop)
+{
+
+ size_t L=strlen(name);
+ result->h_name=buf;
+ if (buflen<L) { *h_errnop=ERANGE; return 1; }
+ strcpy(buf,name);
+
+ result->h_addr_list=(char**)(buf+strlen(name)+1);
+ result->h_addr_list+=sizeof(char*)-((uintptr_t)(result->h_addr_list)&(sizeof(char*)-1));
+ result->h_addr_list[0]=(char*)&result->h_addr_list[2];
+ if (inet_pton(AF_INET,name,result->h_addr_list[0])) {
+ result->h_addrtype=AF_INET;
+ result->h_length=4;
+commonip:
+ result->h_aliases=result->h_addr_list+2*sizeof(char**);
+ result->h_aliases[0]=0;
+ result->h_addr_list[1]=0;
+ *RESULT=result;
+ *h_errnop=0;
+ return 0;
+ } else if (inet_pton(AF_INET6,name,result->h_addr_list[0])) {
+ result->h_addrtype=AF_INET6;
+ result->h_length=16;
+ goto commonip;
+ }
+
+
+ {
+ struct hostent* r;
+ sethostent(0);
+ while ((r=gethostent_r(buf,buflen))) {
+ int i;
+ if (r->h_addrtype==AF_INET && !strcasecmp(r->h_name,name)) { /* found it! */
+found:
+ memmove(result,r,sizeof(struct hostent));
+ *RESULT=result;
+ *h_errnop=0;
+ endhostent();
+ return 0;
+ }
+ for (i=0; i<16; ++i) {
+ if (r->h_aliases[i]) {
+ if (!strcasecmp(r->h_aliases[i],name)) goto found;
+ } else break;
+ }
+ }
+ endhostent();
+ }
+
+ return __dns_gethostbyx_r(name,result,buf+L,buflen-L,RESULT,h_errnop,1);
+}
+
+#endif
+
diff --git a/cpukit/libnetworking/libc/gethostname.c b/cpukit/libnetworking/libc/gethostname.c
new file mode 100644
index 0000000000..39efa2c0fc
--- /dev/null
+++ b/cpukit/libnetworking/libc/gethostname.c
@@ -0,0 +1,28 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Solaris doesn't include the gethostname call by default.
+ */
+#include <sys/utsname.h>
+#include <sys/systeminfo.h>
+
+#include <netdb.h>
+
+/*
+ * PUBLIC: #ifndef HAVE_GETHOSTNAME
+ * PUBLIC: int gethostname __P((char *, int));
+ * PUBLIC: #endif
+ */
+int
+gethostname(host, len)
+ char *host;
+ int len;
+{
+ return (sysinfo(SI_HOSTNAME, host, len) == -1 ? -1 : 0);
+}
diff --git a/cpukit/libnetworking/libc/getifaddrs.c b/cpukit/libnetworking/libc/getifaddrs.c
new file mode 100644
index 0000000000..9d5a535000
--- /dev/null
+++ b/cpukit/libnetworking/libc/getifaddrs.c
@@ -0,0 +1,419 @@
+/* $KAME: getifaddrs.c,v 1.9 2001/08/20 02:31:20 itojun Exp $ */
+
+/*
+ * Copyright (c) 1995, 1999
+ * Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp
+ */
+/*
+ * NOTE: SIOCGIFCONF case is not LP64 friendly. it also does not perform
+ * try-and-error for region size.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#ifdef NET_RT_IFLIST
+#include <sys/param.h>
+#include <net/route.h>
+#include <sys/sysctl.h>
+#include <net/if_dl.h>
+#endif
+
+#include <errno.h>
+#include <ifaddrs.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !defined(AF_LINK)
+#define SA_LEN(sa) sizeof(struct sockaddr)
+#endif
+
+#if !defined(SA_LEN)
+#define SA_LEN(sa) (sa)->sa_len
+#endif
+
+#define SALIGN (sizeof(long) - 1)
+#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1))
+
+#ifndef ALIGNBYTES
+/*
+ * On systems with a routing socket, ALIGNBYTES should match the value
+ * that the kernel uses when building the messages.
+ */
+#define ALIGNBYTES XXX
+#endif
+#ifndef ALIGN
+#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+#endif
+
+#if _BSDI_VERSION >= 199701
+#define HAVE_IFM_DATA
+#endif
+
+#if _BSDI_VERSION >= 199802
+/* ifam_data is very specific to recent versions of bsdi */
+#define HAVE_IFAM_DATA
+#endif
+
+#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
+#define HAVE_IFM_DATA
+#endif
+
+#define MAX_SYSCTL_TRY 5
+
+int
+getifaddrs(struct ifaddrs **pif)
+{
+ int icnt = 1;
+ int dcnt = 0;
+ int ncnt = 0;
+#ifdef NET_RT_IFLIST
+ int ntry = 0;
+ int mib[6];
+ size_t needed;
+ char *buf;
+ char *next;
+ struct ifaddrs *cif = 0;
+ char *p, *p0;
+ struct rt_msghdr *rtm;
+ struct if_msghdr *ifm;
+ struct ifa_msghdr *ifam;
+ struct sockaddr_dl *dl;
+ struct sockaddr *sa;
+ struct ifaddrs *ifa, *ift;
+ u_short idx = 0;
+#else /* NET_RT_IFLIST */
+ char buf[1024];
+ int m, sock;
+ struct ifconf ifc;
+ struct ifreq *ifr;
+ struct ifreq *lifr;
+#endif /* NET_RT_IFLIST */
+ int i;
+ size_t len, alen;
+ char *data;
+ char *names;
+
+#ifdef NET_RT_IFLIST
+ mib[0] = CTL_NET;
+ mib[1] = PF_ROUTE;
+ mib[2] = 0; /* protocol */
+ mib[3] = 0; /* wildcard address family */
+ mib[4] = NET_RT_IFLIST;
+ mib[5] = 0; /* no flags */
+ do {
+ /*
+ * We'll try to get addresses several times in case that
+ * the number of addresses is unexpectedly increased during
+ * the two sysctl calls. This should rarely happen, but we'll
+ * try to do our best for applications that assume success of
+ * this library (which should usually be the case).
+ * Portability note: since FreeBSD does not add margin of
+ * memory at the first sysctl, the possibility of failure on
+ * the second sysctl call is a bit higher.
+ */
+
+ if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ return (-1);
+ if ((buf = malloc(needed)) == NULL)
+ return (-1);
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
+ if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
+ free(buf);
+ return (-1);
+ }
+ free(buf);
+ buf = NULL;
+ }
+ } while (buf == NULL);
+
+ for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)(void *)next;
+ if (rtm->rtm_version != RTM_VERSION)
+ continue;
+ switch (rtm->rtm_type) {
+ case RTM_IFINFO:
+ ifm = (struct if_msghdr *)(void *)rtm;
+ if (ifm->ifm_addrs & RTA_IFP) {
+ idx = ifm->ifm_index;
+ ++icnt;
+ dl = (struct sockaddr_dl *)(void *)(ifm + 1);
+ dcnt += SA_RLEN((struct sockaddr *)(void*)dl) +
+ ALIGNBYTES;
+#ifdef HAVE_IFM_DATA
+ dcnt += sizeof(ifm->ifm_data);
+#endif /* HAVE_IFM_DATA */
+ ncnt += dl->sdl_nlen + 1;
+ } else
+ idx = 0;
+ break;
+
+ case RTM_NEWADDR:
+ ifam = (struct ifa_msghdr *)(void *)rtm;
+ if (idx && ifam->ifam_index != idx)
+ abort(); /* this cannot happen */
+
+#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD)
+ if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
+ break;
+ p = (char *)(void *)(ifam + 1);
+ ++icnt;
+#ifdef HAVE_IFAM_DATA
+ dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES;
+#endif /* HAVE_IFAM_DATA */
+ /* Scan to look for length of address */
+ alen = 0;
+ for (p0 = p, i = 0; i < RTAX_MAX; i++) {
+ if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
+ == 0)
+ continue;
+ sa = (struct sockaddr *)(void *)p;
+ len = SA_RLEN(sa);
+ if (i == RTAX_IFA) {
+ alen = len;
+ break;
+ }
+ p += len;
+ }
+ for (p = p0, i = 0; i < RTAX_MAX; i++) {
+ if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
+ == 0)
+ continue;
+ sa = (struct sockaddr *)(void *)p;
+ len = SA_RLEN(sa);
+ if (i == RTAX_NETMASK && SA_LEN(sa) == 0)
+ dcnt += alen;
+ else
+ dcnt += len;
+ p += len;
+ }
+ break;
+ }
+ }
+#else /* NET_RT_IFLIST */
+ ifc.ifc_buf = buf;
+ ifc.ifc_len = sizeof(buf);
+
+ if ((sock = _socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ return (-1);
+ i = _ioctl(sock, SIOCGIFCONF, (char *)&ifc);
+ _close(sock);
+ if (i < 0)
+ return (-1);
+
+ ifr = ifc.ifc_req;
+ lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
+
+ while (ifr < lifr) {
+ struct sockaddr *sa;
+
+ sa = &ifr->ifr_addr;
+ ++icnt;
+ dcnt += SA_RLEN(sa);
+ ncnt += sizeof(ifr->ifr_name) + 1;
+
+ if (SA_LEN(sa) < sizeof(*sa))
+ ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa));
+ else
+ ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
+ }
+#endif /* NET_RT_IFLIST */
+
+ if (icnt + dcnt + ncnt == 1) {
+ *pif = NULL;
+ free(buf);
+ return (0);
+ }
+ data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt);
+ if (data == NULL) {
+ free(buf);
+ return(-1);
+ }
+
+ ifa = (struct ifaddrs *)(void *)data;
+ data += sizeof(struct ifaddrs) * icnt;
+ names = data + dcnt;
+
+ memset(ifa, 0, sizeof(struct ifaddrs) * icnt);
+ ift = ifa;
+
+#ifdef NET_RT_IFLIST
+ idx = 0;
+ for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)(void *)next;
+ if (rtm->rtm_version != RTM_VERSION)
+ continue;
+ switch (rtm->rtm_type) {
+ case RTM_IFINFO:
+ ifm = (struct if_msghdr *)(void *)rtm;
+ if (ifm->ifm_addrs & RTA_IFP) {
+ idx = ifm->ifm_index;
+ dl = (struct sockaddr_dl *)(void *)(ifm + 1);
+
+ cif = ift;
+ ift->ifa_name = names;
+ ift->ifa_flags = (int)ifm->ifm_flags;
+ memcpy(names, dl->sdl_data,
+ (size_t)dl->sdl_nlen);
+ names[dl->sdl_nlen] = 0;
+ names += dl->sdl_nlen + 1;
+
+ ift->ifa_addr = (struct sockaddr *)(void *)data;
+ memcpy(data, dl,
+ (size_t)SA_LEN((struct sockaddr *)
+ (void *)dl));
+ data += SA_RLEN((struct sockaddr *)(void *)dl);
+
+#ifdef HAVE_IFM_DATA
+ /* ifm_data needs to be aligned */
+ ift->ifa_data = data = (void *)ALIGN(data);
+ memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data));
+ data += sizeof(ifm->ifm_data);
+#else /* HAVE_IFM_DATA */
+ ift->ifa_data = NULL;
+#endif /* HAVE_IFM_DATA */
+
+ ift = (ift->ifa_next = ift + 1);
+ } else
+ idx = 0;
+ break;
+
+ case RTM_NEWADDR:
+ ifam = (struct ifa_msghdr *)(void *)rtm;
+ if (idx && ifam->ifam_index != idx)
+ abort(); /* this cannot happen */
+
+ if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
+ break;
+ ift->ifa_name = cif->ifa_name;
+ ift->ifa_flags = cif->ifa_flags;
+ ift->ifa_data = NULL;
+ p = (char *)(void *)(ifam + 1);
+ /* Scan to look for length of address */
+ alen = 0;
+ for (p0 = p, i = 0; i < RTAX_MAX; i++) {
+ if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
+ == 0)
+ continue;
+ sa = (struct sockaddr *)(void *)p;
+ len = SA_RLEN(sa);
+ if (i == RTAX_IFA) {
+ alen = len;
+ break;
+ }
+ p += len;
+ }
+ for (p = p0, i = 0; i < RTAX_MAX; i++) {
+ if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
+ == 0)
+ continue;
+ sa = (struct sockaddr *)(void *)p;
+ len = SA_RLEN(sa);
+ switch (i) {
+ case RTAX_IFA:
+ ift->ifa_addr =
+ (struct sockaddr *)(void *)data;
+ memcpy(data, p, len);
+ data += len;
+ break;
+
+ case RTAX_NETMASK:
+ ift->ifa_netmask =
+ (struct sockaddr *)(void *)data;
+ if (SA_LEN(sa) == 0) {
+ memset(data, 0, alen);
+ data += alen;
+ break;
+ }
+ memcpy(data, p, len);
+ data += len;
+ break;
+
+ case RTAX_BRD:
+ ift->ifa_broadaddr =
+ (struct sockaddr *)(void *)data;
+ memcpy(data, p, len);
+ data += len;
+ break;
+ }
+ p += len;
+ }
+
+#ifdef HAVE_IFAM_DATA
+ /* ifam_data needs to be aligned */
+ ift->ifa_data = data = (void *)ALIGN(data);
+ memcpy(data, &ifam->ifam_data, sizeof(ifam->ifam_data));
+ data += sizeof(ifam->ifam_data);
+#endif /* HAVE_IFAM_DATA */
+
+ ift = (ift->ifa_next = ift + 1);
+ break;
+ }
+ }
+
+ free(buf);
+#else /* NET_RT_IFLIST */
+ ifr = ifc.ifc_req;
+ lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
+
+ while (ifr < lifr) {
+ struct sockaddr *sa;
+
+ ift->ifa_name = names;
+ names[sizeof(ifr->ifr_name)] = 0;
+ strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name));
+ while (*names++)
+ ;
+
+ ift->ifa_addr = (struct sockaddr *)data;
+ sa = &ifr->ifr_addr;
+ memcpy(data, sa, SA_LEN(sa));
+ data += SA_RLEN(sa);
+
+ ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
+ ift = (ift->ifa_next = ift + 1);
+ }
+#endif /* NET_RT_IFLIST */
+ if (--ift >= ifa) {
+ ift->ifa_next = NULL;
+ *pif = ifa;
+ } else {
+ *pif = NULL;
+ free(ifa);
+ }
+ return (0);
+}
+
+void
+freeifaddrs(struct ifaddrs *ifp)
+{
+
+ free(ifp);
+}
diff --git a/cpukit/libnetworking/libc/getnetbydns.c b/cpukit/libnetworking/libc/getnetbydns.c
new file mode 100644
index 0000000000..33ff993c15
--- /dev/null
+++ b/cpukit/libnetworking/libc/getnetbydns.c
@@ -0,0 +1,312 @@
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <syslog.h>
+
+#include "res_config.h"
+
+extern int h_errno;
+
+#define BYADDR 0
+#define BYNAME 1
+#define MAXALIASES 35
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+ long al;
+ char ac;
+} align;
+
+static struct netent *
+getnetanswer(
+ querybuf *answer,
+ int anslen,
+ int net_i)
+{
+
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *eom;
+ int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
+ char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN];
+ char *in, *st, *pauxt, *bp, **ap;
+ char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
+static struct netent net_entry;
+static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
+
+ /*
+ * find first satisfactory answer
+ *
+ * answer --> +------------+ ( MESSAGE )
+ * | Header |
+ * +------------+
+ * | Question | the question for the name server
+ * +------------+
+ * | Answer | RRs answering the question
+ * +------------+
+ * | Authority | RRs pointing toward an authority
+ * | Additional | RRs holding additional information
+ * +------------+
+ */
+ eom = answer->buf + anslen;
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount); /* #/records in the answer section */
+ qdcount = ntohs(hp->qdcount); /* #/entries in the question section */
+ bp = netbuf;
+ buflen = sizeof(netbuf);
+ cp = answer->buf + HFIXEDSZ;
+ if (!qdcount) {
+ if (hp->aa)
+ h_errno = HOST_NOT_FOUND;
+ else
+ h_errno = TRY_AGAIN;
+ return (NULL);
+ }
+ while (qdcount-- > 0)
+ cp += __dn_skipname(cp, eom) + QFIXEDSZ;
+ ap = net_aliases;
+ *ap = NULL;
+ net_entry.n_aliases = net_aliases;
+ haveanswer = 0;
+ while (--ancount >= 0 && cp < eom) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_dnok(bp))
+ break;
+ cp += n;
+ ans[0] = '\0';
+ (void)strncpy(&ans[0], bp, sizeof(ans) - 1);
+ ans[sizeof(ans) - 1] = '\0';
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ cp += INT32SZ; /* TTL */
+ GETSHORT(n, cp);
+ if (class == C_IN && type == T_PTR) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_hnok(bp)) {
+ cp += n;
+ return (NULL);
+ }
+ cp += n;
+ *ap++ = bp;
+ bp += strlen(bp) + 1;
+ net_entry.n_addrtype =
+ (class == C_IN) ? AF_INET : AF_UNSPEC;
+ haveanswer++;
+ }
+ }
+ if (haveanswer) {
+ *ap = NULL;
+ switch (net_i) {
+ case BYADDR:
+ net_entry.n_name = *net_entry.n_aliases;
+ net_entry.n_net = 0L;
+ break;
+ case BYNAME:
+ in = *net_entry.n_aliases;
+ net_entry.n_name = &ans[0];
+ aux2[0] = '\0';
+ for (i = 0; i < 4; i++) {
+ for (st = in, nchar = 0;
+ *st != '.';
+ st++, nchar++)
+ ;
+ if (nchar != 1 || *in != '0' || flag) {
+ flag = 1;
+ (void)strncpy(paux1,
+ (i==0) ? in : in-1,
+ (i==0) ?nchar : nchar+1);
+ paux1[(i==0) ? nchar : nchar+1] = '\0';
+ pauxt = paux2;
+ paux2 = strcat(paux1, paux2);
+ paux1 = pauxt;
+ }
+ in = ++st;
+ }
+ net_entry.n_net = inet_network(paux2);
+ break;
+ }
+ net_entry.n_aliases++;
+ return (&net_entry);
+ }
+ h_errno = TRY_AGAIN;
+ return (NULL);
+}
+
+struct netent *
+_getnetbydnsaddr(
+ register unsigned long net,
+ register int net_type )
+{
+ unsigned int netbr[4];
+ int nn, anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+ unsigned long net2;
+ struct netent *net_entry;
+
+ if (net_type != AF_INET)
+ return (NULL);
+
+ for (nn = 4, net2 = net; net2; net2 >>= 8)
+ netbr[--nn] = net2 & 0xff;
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
+ break;
+ case 1: /* Class C */
+ sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1], netbr[0]);
+ break;
+ }
+ anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+ if (anslen < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("res_query failed\n");
+#endif
+ return (NULL);
+ }
+ net_entry = getnetanswer(&buf, anslen, BYADDR);
+ if (net_entry) {
+ unsigned u_net = net; /* maybe net should be unsigned ? */
+
+ /* Strip trailing zeros */
+ while ((u_net & 0xff) == 0 && u_net != 0)
+ u_net >>= 8;
+ net_entry->n_net = u_net;
+ return (net_entry);
+ }
+ return (NULL);
+}
+
+struct netent *
+_getnetbydnsname(
+ register const char *net )
+{
+ int anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ strncpy(qbuf, net, sizeof(qbuf) - 1);
+ qbuf[sizeof(qbuf) - 1] = '\0';
+ anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+ if (anslen < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("res_query failed\n");
+#endif
+ return (NULL);
+ }
+ return getnetanswer(&buf, anslen, BYNAME);
+}
+
+void
+_setnetdnsent(
+ int stayopen)
+{
+ if (stayopen)
+ _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+_endnetdnsent(void)
+{
+ _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+ res_close();
+}
diff --git a/cpukit/libnetworking/libc/getnetbyht.c b/cpukit/libnetworking/libc/getnetbyht.c
new file mode 100644
index 0000000000..dbe2d68709
--- /dev/null
+++ b/cpukit/libnetworking/libc/getnetbyht.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * from getnetent.c 1.1 (Coimbra) 93/06/02
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#define MAXALIASES 35
+
+static FILE *netf;
+static char line[BUFSIZ+1];
+static struct netent net;
+static char *net_aliases[MAXALIASES];
+static int _net_stayopen;
+
+void
+_setnethtent(int f)
+{
+
+ if (netf == NULL)
+ netf = fopen(_PATH_NETWORKS, "r" );
+ else
+ rewind(netf);
+ _net_stayopen |= f;
+}
+
+void
+_endnethtent(void)
+{
+
+ if (netf) {
+ fclose(netf);
+ netf = NULL;
+ }
+ _net_stayopen = 0;
+}
+
+struct netent *
+getnetent(void)
+{
+ char *p;
+ register char *cp, **q;
+
+ if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
+ return (NULL);
+again:
+ p = fgets(line, sizeof line, netf);
+ if (p == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ net.n_name = p;
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ p = strpbrk(cp, " \t");
+ if (p != NULL)
+ *p++ = '\0';
+ net.n_net = inet_network(cp);
+ net.n_addrtype = AF_INET;
+ q = net.n_aliases = net_aliases;
+ if (p != NULL)
+ cp = p;
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &net_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&net);
+}
+
+struct netent *
+_getnetbyhtname(const char *name)
+{
+ register struct netent *p;
+ register char **cp;
+
+ setnetent(_net_stayopen);
+ while ( (p = getnetent()) ) {
+ if (strcasecmp(p->n_name, name) == 0)
+ break;
+ for (cp = p->n_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ if (!_net_stayopen)
+ endnetent();
+ return (p);
+}
+
+struct netent *
+_getnetbyhtaddr(
+ unsigned long net,
+ int type)
+{
+ register struct netent *p;
+
+ setnetent(_net_stayopen);
+ while ( (p = getnetent()) )
+ if (p->n_addrtype == type && p->n_net == net)
+ break;
+ if (!_net_stayopen)
+ endnetent();
+ return (p);
+}
diff --git a/cpukit/libnetworking/libc/getnetbynis.c b/cpukit/libnetworking/libc/getnetbynis.c
new file mode 100644
index 0000000000..3849a679df
--- /dev/null
+++ b/cpukit/libnetworking/libc/getnetbynis.c
@@ -0,0 +1,176 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <arpa/nameser.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+#ifdef YP
+static char *host_aliases[MAXALIASES];
+#endif /* YP */
+
+static struct netent *
+_getnetbynis(
+ const char *name,
+ char *map,
+ int af)
+{
+#ifdef YP
+ register char *cp, **q;
+ static char *result;
+ int resultlen;
+ static struct netent h;
+ static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD + 2];
+
+ switch(af) {
+ case AF_INET:
+ break;
+ default:
+ case AF_INET6:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ if (domain == (char *)NULL)
+ if (yp_get_default_domain (&domain))
+ return (NULL);
+
+ if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+ return (NULL);
+
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ ypbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&ypbuf;
+
+ if ((cp = index(result, '\n')))
+ *cp = '\0';
+
+ cp = strpbrk(result, " \t");
+ *cp++ = '\0';
+ h.n_name = result;
+
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+
+ h.n_net = inet_network(cp);
+ h.n_addrtype = AF_INET;
+
+ q = h.n_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&h);
+#else
+ return (NULL);
+#endif
+}
+
+struct netent *
+_getnetbynisname(
+ const char *name)
+{
+ return _getnetbynis(name, "networks.byname", AF_INET);
+}
+
+struct netent *
+_getnetbynisaddr(
+ unsigned long addr,
+ int af)
+{
+ char *str, *cp;
+ unsigned long net2;
+ int nn;
+ unsigned int netbr[4];
+ char buf[MAXDNAME];
+
+ if (af != AF_INET) {
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+
+ for (nn = 4, net2 = addr; net2; net2 >>= 8) {
+ netbr[--nn] = net2 & 0xff;
+ }
+
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(buf, "%u", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(buf, "%u.%u", netbr[2], netbr[3]);
+ break;
+ case 1: /* Class C */
+ sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
+ netbr[2], netbr[3]);
+ break;
+ }
+
+ str = (char *)&buf;
+ cp = str + (strlen(str) - 2);
+
+ while(!strcmp(cp, ".0")) {
+ *cp = '\0';
+ cp = str + (strlen(str) - 2);
+ }
+
+ return _getnetbynis(str, "networks.byaddr", af);
+}
diff --git a/cpukit/libnetworking/libc/getnetent.3 b/cpukit/libnetworking/libc/getnetent.3
new file mode 100644
index 0000000000..aec93b5876
--- /dev/null
+++ b/cpukit/libnetworking/libc/getnetent.3
@@ -0,0 +1,159 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd June 4, 1993
+.Dt GETNETENT 3
+.Os BSD 4.2
+.Sh NAME
+.Nm getnetent ,
+.Nm getnetbyaddr ,
+.Nm getnetbyname ,
+.Nm setnetent ,
+.Nm endnetent
+.Nd get network entry
+.Sh SYNOPSIS
+.Fd #include <netdb.h>
+.Ft struct netent *
+.Fn getnetent void
+.Ft struct netent *
+.Fn getnetbyname "const char *name"
+.Ft struct netent *
+.Fn getnetbyaddr "unsigned long net" "int type"
+.Ft void
+.Fn setnetent "int stayopen"
+.Ft void
+.Fn endnetent void
+.Sh DESCRIPTION
+The
+.Fn getnetent ,
+.Fn getnetbyname ,
+and
+.Fn getnetbyaddr
+functions
+each return a pointer to an object with the
+following structure
+containing the broken-out
+fields of a line in the network data base,
+.Pa /etc/networks .
+.Bd -literal -offset indent
+struct netent {
+ char *n_name; /* official name of net */
+ char **n_aliases; /* alias list */
+ int n_addrtype; /* net number type */
+ unsigned long n_net; /* net number */
+};
+.Ed
+.Pp
+The members of this structure are:
+.Bl -tag -width n_addrtype
+.It Fa n_name
+The official name of the network.
+.It Fa n_aliases
+A zero terminated list of alternate names for the network.
+.It Fa n_addrtype
+The type of the network number returned; currently only AF_INET.
+.It Fa n_net
+The network number. Network numbers are returned in machine byte
+order.
+.El
+.Pp
+The
+.Fn getnetent
+function
+reads the next line of the file, opening the file if necessary.
+.Pp
+The
+.Fn setnetent
+function
+opens and rewinds the file. If the
+.Fa stayopen
+flag is non-zero,
+the net data base will not be closed after each call to
+.Fn getnetbyname
+or
+.Fn getnetbyaddr .
+.Pp
+The
+.Fn endnetent
+function
+closes the file.
+.Pp
+The
+.Fn getnetbyname
+function
+and
+.Fn getnetbyaddr
+sequentially search from the beginning
+of the file until a matching
+net name or
+net address and type is found,
+or until
+.Dv EOF
+is encountered. The
+.Fa type
+must be
+.Dv AF_INET .
+Network numbers are supplied in host order.
+.Sh FILES
+.Bl -tag -width /etc/networks -compact
+.It Pa /etc/networks
+.El
+.Sh DIAGNOSTICS
+Null pointer
+(0) returned on
+.Dv EOF
+or error.
+.Sh SEE ALSO
+.Xr networks 5
+.Pp
+.%T RFC 1101
+.Sh HISTORY
+The
+.Fn getnetent ,
+.Fn getnetbyaddr ,
+.Fn getnetbyname ,
+.Fn setnetent ,
+and
+.Fn endnetent
+functions appeared in
+.Bx 4.2 .
+.Sh BUGS
+The data space used by
+these functions is static; if future use requires the data, it should be
+copied before any subsequent calls to these functions overwrite it.
+Only Internet network
+numbers are currently understood.
+Expecting network numbers to fit
+in no more than 32 bits is probably
+naive.
diff --git a/cpukit/libnetworking/libc/getnetnamadr.c b/cpukit/libnetworking/libc/getnetnamadr.c
new file mode 100644
index 0000000000..eb98477096
--- /dev/null
+++ b/cpukit/libnetworking/libc/getnetnamadr.c
@@ -0,0 +1,190 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h> /* for strcasecmp */
+#endif
+
+#ifndef _PATH_NETCONF
+#define _PATH_NETCONF "/etc/host.conf"
+#endif
+
+enum service_type {
+ SERVICE_NONE = 0,
+ SERVICE_BIND,
+ SERVICE_TABLE,
+ SERVICE_NIS };
+#define SERVICE_MAX SERVICE_NIS
+
+static struct {
+ const char *name;
+ enum service_type type;
+} service_names[] = {
+ { "hosts", SERVICE_TABLE },
+ { "/etc/hosts", SERVICE_TABLE },
+ { "hosttable", SERVICE_TABLE },
+ { "htable", SERVICE_TABLE },
+ { "bind", SERVICE_BIND },
+ { "dns", SERVICE_BIND },
+ { "domain", SERVICE_BIND },
+ { "yp", SERVICE_NIS },
+ { "yellowpages", SERVICE_NIS },
+ { "nis", SERVICE_NIS },
+ { 0, SERVICE_NONE }
+};
+
+static enum service_type service_order[SERVICE_MAX + 1];
+static int service_done = 0;
+
+static enum service_type
+get_service_name(const char *name) {
+ int i;
+ for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
+ if(!strcasecmp(name, service_names[i].name)) {
+ return service_names[i].type;
+ }
+ }
+ return SERVICE_NONE;
+}
+
+static void
+init_services(void)
+{
+ char *cp, *p, buf[BUFSIZ];
+ register int cc = 0;
+ FILE *fd;
+
+ if ((fd = (FILE *)fopen(_PATH_NETCONF, "r")) == NULL) {
+ /* make some assumptions */
+ service_order[0] = SERVICE_TABLE;
+ service_order[1] = SERVICE_NONE;
+ } else {
+ while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
+ if(buf[0] == '#')
+ continue;
+
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
+ do {
+ if (isalpha((unsigned char)cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
+ }
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
+ }
+ service_order[cc] = SERVICE_NONE;
+ fclose(fd);
+ }
+ service_done = 1;
+}
+
+struct netent *
+getnetbyname(const char *name)
+{
+ struct netent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return NULL;
+ case SERVICE_TABLE:
+ hp = _getnetbyhtname(name);
+ break;
+ case SERVICE_BIND:
+ hp = _getnetbydnsname(name);
+ break;
+ case SERVICE_NIS:
+ hp = _getnetbynisname(name);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+struct netent *
+getnetbyaddr(uint32_t addr, int af)
+{
+ struct netent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return 0;
+ case SERVICE_TABLE:
+ hp = _getnetbyhtaddr(addr, af);
+ break;
+ case SERVICE_BIND:
+ hp = _getnetbydnsaddr(addr, af);
+ break;
+ case SERVICE_NIS:
+ hp = _getnetbynisaddr(addr, af);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+void
+setnetent(int stayopen)
+{
+ _setnethtent(stayopen);
+ _setnetdnsent(stayopen);
+}
+
+void
+endnetent(void)
+{
+ _endnethtent();
+ _endnetdnsent();
+}
diff --git a/cpukit/libnetworking/libc/getproto.c b/cpukit/libnetworking/libc/getproto.c
new file mode 100644
index 0000000000..c394d31b76
--- /dev/null
+++ b/cpukit/libnetworking/libc/getproto.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdb.h>
+
+extern int _proto_stayopen;
+
+extern struct protoent * getprotobynumber_static(int);
+
+struct protoent *
+getprotobynumber(
+ int proto )
+{
+ register struct protoent *p;
+
+ setprotoent(_proto_stayopen);
+ while ( (p = getprotoent()) )
+ if (p->p_proto == proto)
+ break;
+ if (!_proto_stayopen)
+ endprotoent();
+
+ if ( !p )
+ p = getprotobynumber_static(proto);
+ return (p);
+}
diff --git a/cpukit/libnetworking/libc/getprotoent.3 b/cpukit/libnetworking/libc/getprotoent.3
new file mode 100644
index 0000000000..784461d7e3
--- /dev/null
+++ b/cpukit/libnetworking/libc/getprotoent.3
@@ -0,0 +1,147 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd June 4, 1993
+.Dt GETPROTOENT 3
+.Os BSD 4.2
+.Sh NAME
+.Nm getprotoent ,
+.Nm getprotobynumber ,
+.Nm getprotobyname ,
+.Nm setprotoent ,
+.Nm endprotoent
+.Nd get protocol entry
+.Sh SYNOPSIS
+.Fd #include <netdb.h>
+.Ft struct protoent *
+.Fn getprotoent void
+.Ft struct protoent *
+.Fn getprotobyname "const char *name"
+.Ft struct protoent *
+.Fn getprotobynumber "int proto"
+.Ft void
+.Fn setprotoent "int stayopen"
+.Ft void
+.Fn endprotoent void
+.Sh DESCRIPTION
+The
+.Fn getprotoent ,
+.Fn getprotobyname ,
+and
+.Fn getprotobynumber
+functions
+each return a pointer to an object with the
+following structure
+containing the broken-out
+fields of a line in the network protocol data base,
+.Pa /etc/protocols .
+.Bd -literal -offset indent
+.Pp
+struct protoent {
+ char *p_name; /* official name of protocol */
+ char **p_aliases; /* alias list */
+ int p_proto; /* protocol number */
+};
+.Ed
+.Pp
+The members of this structure are:
+.Bl -tag -width p_aliases
+.It Fa p_name
+The official name of the protocol.
+.It Fa p_aliases
+A zero terminated list of alternate names for the protocol.
+.It Fa p_proto
+The protocol number.
+.El
+.Pp
+The
+.Fn getprotoent
+function
+reads the next line of the file, opening the file if necessary.
+.Pp
+The
+.Fn setprotoent
+function
+opens and rewinds the file. If the
+.Fa stayopen
+flag is non-zero,
+the net data base will not be closed after each call to
+.Fn getprotobyname
+or
+.Fn getprotobynumber .
+.Pp
+The
+.Fn endprotoent
+function
+closes the file.
+.Pp
+The
+.Fn getprotobyname
+function
+and
+.Fn getprotobynumber
+sequentially search from the beginning
+of the file until a matching
+protocol name or
+protocol number is found,
+or until
+.Dv EOF
+is encountered.
+.Sh RETURN VALUES
+Null pointer
+(0) returned on
+.Dv EOF
+or error.
+.Sh FILES
+.Bl -tag -width /etc/protocols -compact
+.It Pa /etc/protocols
+.El
+.Sh SEE ALSO
+.Xr protocols 5
+.Sh HISTORY
+The
+.Fn getprotoent ,
+.Fn getprotobynumber ,
+.Fn getprotobyname ,
+.Fn setprotoent ,
+and
+.Fn endprotoent
+functions appeared in
+.Bx 4.2 .
+.Sh BUGS
+These functions use a static data space;
+if the data is needed for future use, it should be
+copied before any subsequent calls overwrite it.
+Only the Internet
+protocols are currently understood.
diff --git a/cpukit/libnetworking/libc/getprotoent.c b/cpukit/libnetworking/libc/getprotoent.c
new file mode 100644
index 0000000000..a100075ea9
--- /dev/null
+++ b/cpukit/libnetworking/libc/getprotoent.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MAXALIASES 35
+
+static FILE *protof = NULL;
+static char line[BUFSIZ+1];
+static struct protoent proto;
+static char *proto_aliases[MAXALIASES];
+int _proto_stayopen;
+
+void
+setprotoent(
+ int f)
+{
+ if (protof == NULL)
+ protof = fopen(_PATH_PROTOCOLS, "r" );
+ else
+ rewind(protof);
+ _proto_stayopen |= f;
+}
+
+void
+endprotoent(void)
+{
+ if (protof) {
+ fclose(protof);
+ protof = NULL;
+ }
+ _proto_stayopen = 0;
+}
+
+struct protoent *
+getprotoent(void)
+{
+ char *p;
+ register char *cp, **q;
+
+ if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
+ return (NULL);
+again:
+ if ((p = fgets(line, BUFSIZ, protof)) == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ proto.p_name = p;
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ p = strpbrk(cp, " \t");
+ if (p != NULL)
+ *p++ = '\0';
+ proto.p_proto = atoi(cp);
+ q = proto.p_aliases = proto_aliases;
+ if (p != NULL) {
+ cp = p;
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &proto_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ }
+ *q = NULL;
+ return (&proto);
+}
diff --git a/cpukit/libnetworking/libc/getprotoname.c b/cpukit/libnetworking/libc/getprotoname.c
new file mode 100644
index 0000000000..3f2278e542
--- /dev/null
+++ b/cpukit/libnetworking/libc/getprotoname.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdb.h>
+#include <string.h>
+
+extern int _proto_stayopen;
+
+extern struct protoent *getprotobyname_static(const char *);
+
+struct protoent *
+getprotobyname(
+ const char *name)
+{
+ register struct protoent *p;
+ register char **cp;
+
+ setprotoent(_proto_stayopen);
+ while ( (p = getprotoent()) ) {
+ if (strcmp(p->p_name, name) == 0)
+ break;
+ for (cp = p->p_aliases; *cp != 0; cp++)
+ if (strcmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ if (!_proto_stayopen)
+ endprotoent();
+
+ if ( !p )
+ p = getprotobyname_static(name);
+ return (p);
+}
diff --git a/cpukit/libnetworking/libc/getservbyname.c b/cpukit/libnetworking/libc/getservbyname.c
new file mode 100644
index 0000000000..37f80f8e15
--- /dev/null
+++ b/cpukit/libnetworking/libc/getservbyname.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdb.h>
+#include <string.h>
+
+extern int _serv_stayopen;
+
+int getservbyname_r(
+ const char *name,
+ const char *proto,
+ struct servent *result_buf,
+ char *buf,
+ size_t buflen,
+ struct servent **result
+)
+{
+ #warning "implement a proper getservbyport_r"
+
+ *result = getservbyname(name, proto);
+ if ( *result )
+ return 0;
+
+ return -1;
+}
+
+
+struct servent *
+getservbyname(
+ const char *name,
+ const char *proto )
+{
+ register struct servent *p;
+ register char **cp;
+
+#ifdef YP
+ extern char *___getservbyname_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyname_yp = (char *)name;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
+ setservent(_serv_stayopen);
+ while ( (p = getservent()) ) {
+ if (strcmp(name, p->s_name) == 0)
+ goto gotname;
+ for (cp = p->s_aliases; *cp; cp++)
+ if (strcmp(name, *cp) == 0)
+ goto gotname;
+ continue;
+gotname:
+ if (proto == 0 || strcmp(p->s_proto, proto) == 0)
+ break;
+ }
+ if (!_serv_stayopen)
+ endservent();
+
+#ifdef YP
+ ___getservbyname_yp = NULL;
+ ___getservbyproto_yp = NULL;
+#endif
+
+ return (p);
+}
diff --git a/cpukit/libnetworking/libc/getservbyport.c b/cpukit/libnetworking/libc/getservbyport.c
new file mode 100644
index 0000000000..cd76c2de4d
--- /dev/null
+++ b/cpukit/libnetworking/libc/getservbyport.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdb.h>
+#include <string.h>
+
+extern int _serv_stayopen;
+
+int getservbyport_r(
+ int port,
+ const char *proto,
+ struct servent *result_buf,
+ char *buf,
+ size_t buflen,
+ struct servent **result
+)
+{
+ #warning "implement a proper getservbyport_r"
+
+ *result = getservbyport(port, proto);
+ if ( *result )
+ return 0;
+
+ return -1;
+}
+
+struct servent *
+getservbyport(
+ int port,
+ const char *proto)
+{
+ register struct servent *p;
+
+#ifdef YP
+ extern int ___getservbyport_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyport_yp = port;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
+ setservent(_serv_stayopen);
+ while ( (p = getservent()) ) {
+ if (p->s_port != port)
+ continue;
+ if (proto == 0 || strcmp(p->s_proto, proto) == 0)
+ break;
+ }
+ if (!_serv_stayopen)
+ endservent();
+
+#ifdef YP
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+#endif
+
+ return (p);
+}
diff --git a/cpukit/libnetworking/libc/getservent.3 b/cpukit/libnetworking/libc/getservent.3
new file mode 100644
index 0000000000..79c18a3beb
--- /dev/null
+++ b/cpukit/libnetworking/libc/getservent.3
@@ -0,0 +1,156 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94
+.\" $Id$
+.\"
+.Dd July 9, 1995
+.Dt GETSERVENT 3
+.Os BSD 4.2
+.Sh NAME
+.Nm getservent ,
+.Nm getservbyport ,
+.Nm getservbyname ,
+.Nm setservent ,
+.Nm endservent
+.Nd get service entry
+.Sh SYNOPSIS
+.Fd #include <netdb.h>
+.Ft struct servent *
+.Fn getservent
+.Ft struct servent *
+.Fn getservbyname "const char *name" "const char *proto"
+.Ft struct servent *
+.Fn getservbyport "int port" "const char *proto"
+.Ft void
+.Fn setservent "int stayopen"
+.Ft void
+.Fn endservent void
+.Sh DESCRIPTION
+The
+.Fn getservent ,
+.Fn getservbyname ,
+and
+.Fn getservbyport
+functions
+each return a pointer to an object with the
+following structure
+containing the broken-out
+fields of a line in the network services data base,
+.Pa /etc/services .
+.Bd -literal -offset indent
+struct servent {
+ char *s_name; /* official name of service */
+ char **s_aliases; /* alias list */
+ int s_port; /* port service resides at */
+ char *s_proto; /* protocol to use */
+};
+.Ed
+.Pp
+The members of this structure are:
+.Bl -tag -width s_aliases
+.It Fa s_name
+The official name of the service.
+.It Fa s_aliases
+A zero terminated list of alternate names for the service.
+.It Fa s_port
+The port number at which the service resides.
+Port numbers are returned in network byte order.
+.It Fa s_proto
+The name of the protocol to use when contacting the
+service.
+.El
+.Pp
+The
+.Fn getservent
+function
+reads the next line of the file, opening the file if necessary.
+.Pp
+The
+.Fn setservent
+function
+opens and rewinds the file. If the
+.Fa stayopen
+flag is non-zero,
+the net data base will not be closed after each call to
+.Fn getservbyname
+or
+.Fn getservbyport .
+.Pp
+The
+.Fn endservent
+function
+closes the file.
+.Pp
+The
+.Fn getservbyname
+and
+.Fn getservbyport
+functions
+sequentially search from the beginning
+of the file until a matching
+protocol name or
+port number is found,
+or until
+.Dv EOF
+is encountered.
+If a protocol name is also supplied (non-
+.Dv NULL ) ,
+searches must also match the protocol.
+.ne 1i
+.Sh FILES
+.Bl -tag -width /etc/services -compact
+.It Pa /etc/services
+.El
+.Sh DIAGNOSTICS
+Null pointer
+(0) returned on
+.Dv EOF
+or error.
+.Sh SEE ALSO
+.Xr getprotoent 3 ,
+.Xr services 5
+.Sh HISTORY
+The
+.Fn getservent ,
+.Fn getservbyport ,
+.Fn getservbyname ,
+.Fn setservent ,
+and
+.Fn endservent
+functions appeared in
+.Bx 4.2 .
+.Sh BUGS
+These functions use static data storage;
+if the data is needed for future use, it should be
+copied before any subsequent calls overwrite it.
+Expecting port numbers to fit in a 32 bit
+quantity is probably naive.
diff --git a/cpukit/libnetworking/libc/getservent.c b/cpukit/libnetworking/libc/getservent.c
new file mode 100644
index 0000000000..6ebe7e2761
--- /dev/null
+++ b/cpukit/libnetworking/libc/getservent.c
@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+static int serv_stepping_yp = 0;
+extern int _yp_check __P(( char ** ));
+#endif
+
+
+#define MAXALIASES 35
+
+static FILE *servf = NULL;
+static char line[BUFSIZ+1];
+static struct servent serv;
+static char *serv_aliases[MAXALIASES];
+int _serv_stayopen;
+
+#ifdef YP
+char *___getservbyname_yp = NULL;
+char *___getservbyproto_yp = NULL;
+int ___getservbyport_yp = 0;
+static char *yp_domain = NULL;
+
+static int
+_getservbyport_yp(line)
+ char *line;
+{
+ char *result;
+ int resultlen;
+ char buf[YPMAXRECORD + 2];
+ int rv;
+
+ snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp),
+ ___getservbyproto_yp);
+
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ /*
+ * We have to be a little flexible here. Ideally you're supposed
+ * to have both a services.byname and a services.byport map, but
+ * some systems have only services.byname. FreeBSD cheats a little
+ * by putting the services.byport information in the same map as
+ * services.byname so that either case will work. We allow for both
+ * possibilities here: if there is no services.byport map, we try
+ * services.byname instead.
+ */
+ if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf),
+ &result, &resultlen))) {
+ if (rv == YPERR_MAP) {
+ if (yp_match(yp_domain, "services.byname", buf,
+ strlen(buf), &result, &resultlen))
+ return(0);
+ } else
+ return(0);
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+ return(1);
+}
+
+static int
+_getservbyname_yp(line)
+ char *line;
+{
+ char *result;
+ int resultlen;
+ char buf[YPMAXRECORD + 2];
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp,
+ ___getservbyproto_yp);
+
+ ___getservbyname_yp = 0;
+ ___getservbyproto_yp = NULL;
+
+ if (yp_match(yp_domain, "services.byname", buf, strlen(buf),
+ &result, &resultlen)) {
+ return(0);
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+ return(1);
+}
+
+static int
+_getservent_yp(line)
+ char *line;
+{
+ static char *key = NULL;
+ static int keylen;
+ char *lastkey, *result;
+ int resultlen;
+ int rv;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ if (!serv_stepping_yp) {
+ if (key)
+ free(key);
+ if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
+ &result, &resultlen))) {
+ serv_stepping_yp = 0;
+ return(0);
+ }
+ serv_stepping_yp = 1;
+ } else {
+ lastkey = key;
+ rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
+ &keylen, &result, &resultlen);
+ free(lastkey);
+ if (rv) {
+ serv_stepping_yp = 0;
+ return (0);
+ }
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+
+ return(1);
+}
+#endif
+
+void
+setservent(
+ int f)
+{
+ if (servf == NULL)
+ servf = fopen(_PATH_SERVICES, "r" );
+ else
+ rewind(servf);
+ _serv_stayopen |= f;
+}
+
+void
+endservent(void)
+{
+ if (servf) {
+ fclose(servf);
+ servf = NULL;
+ }
+ _serv_stayopen = 0;
+}
+
+struct servent *
+getservent(void)
+{
+ char *p;
+ register char *cp, **q;
+
+#ifdef YP
+ if (serv_stepping_yp && _getservent_yp(line)) {
+ p = (char *)&line;
+ goto unpack;
+ }
+tryagain:
+#endif
+ if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
+ return (NULL);
+again:
+ if ((p = fgets(line, BUFSIZ, servf)) == NULL)
+ return (NULL);
+#ifdef YP
+ if (*p == '+' && _yp_check(NULL)) {
+ if (___getservbyname_yp != NULL) {
+ if (!_getservbyname_yp(line))
+ goto tryagain;
+ }
+ else if (___getservbyport_yp != 0) {
+ if (!_getservbyport_yp(line))
+ goto tryagain;
+ }
+ else if (!_getservent_yp(line))
+ goto tryagain;
+ }
+unpack:
+#endif
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ serv.s_name = p;
+ p = strpbrk(p, " \t");
+ if (p == NULL)
+ goto again;
+ *p++ = '\0';
+ while (*p == ' ' || *p == '\t')
+ p++;
+ cp = strpbrk(p, ",/");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ serv.s_port = htons((u_short)atoi(p));
+ serv.s_proto = cp;
+ q = serv.s_aliases = serv_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &serv_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&serv);
+}
diff --git a/cpukit/libnetworking/libc/herror.c b/cpukit/libnetworking/libc/herror.c
new file mode 100644
index 0000000000..e7d6ba48cb
--- /dev/null
+++ b/cpukit/libnetworking/libc/herror.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+
+const char *h_errlist[] = {
+ "Resolver Error 0 (no error)",
+ "Unknown host", /* 1 HOST_NOT_FOUND */
+ "Host name lookup failure", /* 2 TRY_AGAIN */
+ "Unknown server error", /* 3 NO_RECOVERY */
+ "No address associated with name", /* 4 NO_ADDRESS */
+};
+int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
+
+int h_errno;
+
+#define HERROR_USE_WRITEV
+
+/*
+ * herror --
+ * print the error indicated by the h_errno value.
+ */
+void
+herror(const char *s)
+{
+#if defined(HERROR_USE_WRITEV)
+ struct iovec iov[4];
+ register struct iovec *v = iov;
+
+ if (s && *s) {
+ v->iov_base = (char *)s;
+ v->iov_len = strlen(s);
+ v++;
+ v->iov_base = ": ";
+ v->iov_len = 2;
+ v++;
+ }
+ v->iov_base = (char *)hstrerror(h_errno);
+ v->iov_len = strlen(v->iov_base);
+ v++;
+ v->iov_base = "\n";
+ v->iov_len = 1;
+ writev(STDERR_FILENO, iov, (v - iov) + 1);
+#else
+ /*
+ * no writev implementation available
+ */
+ if (s && *s) {
+ write (2, s, strlen (s));
+ write (2, ": ", 2);
+ }
+ s = (char *)hstrerror(h_errno);
+ write (2, s, strlen (s));
+ write (2, "\n", 1);
+#endif
+}
+
+const char *
+hstrerror(int err)
+{
+ if (err < 0)
+ return ("Resolver internal error");
+ else if (err < h_nerr)
+ return (h_errlist[err]);
+ return ("Unknown resolver error");
+}
diff --git a/cpukit/libnetworking/libc/if_indextoname.c b/cpukit/libnetworking/libc/if_indextoname.c
new file mode 100644
index 0000000000..8b2279e75c
--- /dev/null
+++ b/cpukit/libnetworking/libc/if_indextoname.c
@@ -0,0 +1,91 @@
+/* $KAME: if_indextoname.c,v 1.7 2000/11/08 03:09:30 itojun Exp $ */
+
+/*-
+ * Copyright (c) 1997, 2000
+ * Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * BSDI Id: if_indextoname.c,v 2.3 2000/04/17 22:38:05 dab Exp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if_dl.h>
+#include <net/if.h>
+#include <ifaddrs.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+/*
+ * From RFC 2533:
+ *
+ * The second function maps an interface index into its corresponding
+ * name.
+ *
+ * #include <net/if.h>
+ *
+ * char *if_indextoname(unsigned int ifindex, char *ifname);
+ *
+ * The ifname argument must point to a buffer of at least IF_NAMESIZE
+ * bytes into which the interface name corresponding to the specified
+ * index is returned. (IF_NAMESIZE is also defined in <net/if.h> and
+ * its value includes a terminating null byte at the end of the
+ * interface name.) This pointer is also the return value of the
+ * function. If there is no interface corresponding to the specified
+ * index, NULL is returned, and errno is set to ENXIO, if there was a
+ * system error (such as running out of memory), if_indextoname returns
+ * NULL and errno would be set to the proper value (e.g., ENOMEM).
+ */
+
+char *
+if_indextoname(unsigned int ifindex, char *ifname)
+{
+ struct ifaddrs *ifaddrs, *ifa;
+ int error = 0;
+
+ if (getifaddrs(&ifaddrs) < 0)
+ return(NULL); /* getifaddrs properly set errno */
+
+ for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr &&
+ ifa->ifa_addr->sa_family == AF_LINK &&
+ ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index)
+ break;
+ }
+
+ if (ifa == NULL) {
+ error = ENXIO;
+ ifname = NULL;
+ }
+ else
+ strncpy(ifname, ifa->ifa_name, IFNAMSIZ);
+
+ freeifaddrs(ifaddrs);
+
+ errno = error;
+ return(ifname);
+}
diff --git a/cpukit/libnetworking/libc/if_nameindex.c b/cpukit/libnetworking/libc/if_nameindex.c
new file mode 100644
index 0000000000..f4e54a6733
--- /dev/null
+++ b/cpukit/libnetworking/libc/if_nameindex.c
@@ -0,0 +1,150 @@
+/* $KAME: if_nameindex.c,v 1.8 2000/11/24 08:20:01 itojun Exp $ */
+
+/*-
+ * Copyright (c) 1997, 2000
+ * Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * BSDI Id: if_nameindex.c,v 2.3 2000/04/17 22:38:05 dab Exp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if_dl.h>
+#include <net/if.h>
+#include <ifaddrs.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * From RFC 2553:
+ *
+ * 4.3 Return All Interface Names and Indexes
+ *
+ * The if_nameindex structure holds the information about a single
+ * interface and is defined as a result of including the <net/if.h>
+ * header.
+ *
+ * struct if_nameindex {
+ * unsigned int if_index;
+ * char *if_name;
+ * };
+ *
+ * The final function returns an array of if_nameindex structures, one
+ * structure per interface.
+ *
+ * struct if_nameindex *if_nameindex(void);
+ *
+ * The end of the array of structures is indicated by a structure with
+ * an if_index of 0 and an if_name of NULL. The function returns a NULL
+ * pointer upon an error, and would set errno to the appropriate value.
+ *
+ * The memory used for this array of structures along with the interface
+ * names pointed to by the if_name members is obtained dynamically.
+ * This memory is freed by the next function.
+ *
+ * 4.4. Free Memory
+ *
+ * The following function frees the dynamic memory that was allocated by
+ * if_nameindex().
+ *
+ * #include <net/if.h>
+ *
+ * void if_freenameindex(struct if_nameindex *ptr);
+ *
+ * The argument to this function must be a pointer that was returned by
+ * if_nameindex().
+ */
+
+struct if_nameindex *
+if_nameindex(void)
+{
+ struct ifaddrs *ifaddrs, *ifa;
+ unsigned int ni;
+ int nbytes;
+ struct if_nameindex *ifni, *ifni2;
+ char *cp;
+
+ if (getifaddrs(&ifaddrs) < 0)
+ return(NULL);
+
+ /*
+ * First, find out how many interfaces there are, and how
+ * much space we need for the string names.
+ */
+ ni = 0;
+ nbytes = 0;
+ for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr &&
+ ifa->ifa_addr->sa_family == AF_LINK) {
+ nbytes += strlen(ifa->ifa_name) + 1;
+ ni++;
+ }
+ }
+
+ /*
+ * Next, allocate a chunk of memory, use the first part
+ * for the array of structures, and the last part for
+ * the strings.
+ */
+ cp = malloc((ni + 1) * sizeof(struct if_nameindex) + nbytes);
+ ifni = (struct if_nameindex *)cp;
+ if (ifni == NULL)
+ goto out;
+ cp += (ni + 1) * sizeof(struct if_nameindex);
+
+ /*
+ * Now just loop through the list of interfaces again,
+ * filling in the if_nameindex array and making copies
+ * of all the strings.
+ */
+ ifni2 = ifni;
+ for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr &&
+ ifa->ifa_addr->sa_family == AF_LINK) {
+ ifni2->if_index =
+ ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index;
+ ifni2->if_name = cp;
+ strcpy(cp, ifa->ifa_name);
+ ifni2++;
+ cp += strlen(cp) + 1;
+ }
+ }
+ /*
+ * Finally, don't forget to terminate the array.
+ */
+ ifni2->if_index = 0;
+ ifni2->if_name = NULL;
+out:
+ freeifaddrs(ifaddrs);
+ return(ifni);
+}
+
+void
+if_freenameindex(struct if_nameindex *ptr)
+{
+ free(ptr);
+}
diff --git a/cpukit/libnetworking/libc/inet.3 b/cpukit/libnetworking/libc/inet.3
new file mode 100644
index 0000000000..1052f538f2
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet.3
@@ -0,0 +1,210 @@
+.\" Copyright (c) 1983, 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd June 17, 1996
+.Dt INET 3
+.Os BSD 4.2
+.Sh NAME
+.Nm inet_aton ,
+.Nm inet_addr ,
+.Nm inet_network ,
+.Nm inet_ntoa ,
+.Nm inet_makeaddr ,
+.Nm inet_lnaof ,
+.Nm inet_netof
+.Nd Internet address manipulation routines
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
+.Fd #include <netinet/in.h>
+.Fd #include <arpa/inet.h>
+.Ft int
+.Fn inet_aton "const char *cp" "struct in_addr *pin"
+.Ft unsigned long
+.Fn inet_addr "const char *cp"
+.Ft unsigned long
+.Fn inet_network "const char *cp"
+.Ft char *
+.Fn inet_ntoa "struct in_addr in"
+.Ft struct in_addr
+.Fn inet_makeaddr "unsigned long net" "unsigned long lna"
+.Ft unsigned long
+.Fn inet_lnaof "struct in_addr in"
+.Ft unsigned long
+.Fn inet_netof "struct in_addr in"
+.Sh DESCRIPTION
+The routines
+.Fn inet_aton ,
+.Fn inet_addr
+and
+.Fn inet_network
+interpret character strings representing
+numbers expressed in the Internet standard
+.Ql \&.
+notation.
+The
+.Fn inet_aton
+routine interprets the specified character string as an Internet address,
+placing the address into the structure provided.
+It returns 1 if the string was successfully interpreted,
+or 0 if the string is invalid.
+The
+.Fn inet_addr
+and
+.Fn inet_network
+functions return numbers suitable for use
+as Internet addresses and Internet network
+numbers, respectively.
+The routine
+.Fn inet_ntoa
+takes an Internet address and returns an
+.Tn ASCII
+string representing the address in
+.Ql \&.
+notation. The routine
+.Fn inet_makeaddr
+takes an Internet network number and a local
+network address and constructs an Internet address
+from it. The routines
+.Fn inet_netof
+and
+.Fn inet_lnaof
+break apart Internet host addresses, returning
+the network number and local network address part,
+respectively.
+.Pp
+All Internet addresses are returned in network
+order (bytes ordered from left to right).
+All network numbers and local address parts are
+returned as machine format integer values.
+.Sh INTERNET ADDRESSES
+Values specified using the
+.Ql \&.
+notation take one
+of the following forms:
+.Bd -literal -offset indent
+a.b.c.d
+a.b.c
+a.b
+a
+.Ed
+.Pp
+When four parts are specified, each is interpreted
+as a byte of data and assigned, from left to right,
+to the four bytes of an Internet address. Note
+that when an Internet address is viewed as a 32-bit
+integer quantity on the
+.Tn VAX
+the bytes referred to
+above appear as
+.Dq Li d.c.b.a .
+That is,
+.Tn VAX
+bytes are
+ordered from right to left.
+.Pp
+When a three part address is specified, the last
+part is interpreted as a 16-bit quantity and placed
+in the right-most two bytes of the network address.
+This makes the three part address format convenient
+for specifying Class B network addresses as
+.Dq Li 128.net.host .
+.Pp
+When a two part address is supplied, the last part
+is interpreted as a 24-bit quantity and placed in
+the right most three bytes of the network address.
+This makes the two part address format convenient
+for specifying Class A network addresses as
+.Dq Li net.host .
+.Pp
+When only one part is given, the value is stored
+directly in the network address without any byte
+rearrangement.
+.Pp
+All numbers supplied as
+.Dq parts
+in a
+.Ql \&.
+notation
+may be decimal, octal, or hexadecimal, as specified
+in the C language (i.e., a leading 0x or 0X implies
+hexadecimal; otherwise, a leading 0 implies octal;
+otherwise, the number is interpreted as decimal).
+.Pp
+The
+.Fn inet_aton
+and
+.Fn inet_ntoa
+functions are semi-deprecated in favor of the
+.Xr addr2ascii 3
+family. However, since those functions are not yet widely implemented,
+portable programs cannot rely on their presence and will continue
+to use the
+.Xr inet 3
+functions for some time.
+.Sh DIAGNOSTICS
+The constant
+.Dv INADDR_NONE
+is returned by
+.Fn inet_addr
+and
+.Fn inet_network
+for malformed requests.
+.Sh SEE ALSO
+.Xr addr2ascii 3 ,
+.Xr gethostbyname 3 ,
+.Xr getnetent 3 ,
+.Xr hosts 5 ,
+.Xr networks 5
+.Sh HISTORY
+These
+functions appeared in
+.Bx 4.2 .
+.Sh BUGS
+The value
+.Dv INADDR_NONE
+(0xffffffff) is a valid broadcast address, but
+.Fn inet_addr
+cannot return that value without indicating failure.
+The newer
+.Fn inet_aton
+function does not share this problem.
+The problem of host byte ordering versus network byte ordering is
+confusing.
+The string returned by
+.Fn inet_ntoa
+resides in a static memory area.
+.Pp
+Inet_addr should return a
+.Fa struct in_addr .
diff --git a/cpukit/libnetworking/libc/inet_addr.c b/cpukit/libnetworking/libc/inet_addr.c
new file mode 100644
index 0000000000..9820e25ce2
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_addr.c
@@ -0,0 +1,179 @@
+/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
+ * Copyright (c) 1983, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+
+/*
+ * ASCII internet address interpretation routine.
+ * The value returned is in network order.
+ */
+in_addr_t
+inet_addr(
+ const char *cp)
+{
+ struct in_addr val;
+
+ if (inet_aton(cp, &val))
+ return (val.s_addr);
+ return (INADDR_NONE);
+}
+
+/*
+ * Check whether "cp" is a valid ASCII representation
+ * of an Internet address and convert to a binary address.
+ * Returns 1 if the address is valid, 0 if not.
+ * This replaces inet_addr, the return value from which
+ * cannot distinguish between failure and a local broadcast address.
+ */
+int
+inet_aton(
+ const char *cp,
+ struct in_addr *addr)
+{
+ in_addr_t val;
+ register int base, n;
+ register char c;
+ uint32_t parts[4];
+ register uint32_t *pp = parts;
+
+ c = *cp;
+ for (;;) {
+ /*
+ * Collect number up to ``.''.
+ * Values are specified as for C:
+ * 0x=hex, 0=octal, isdigit=decimal.
+ */
+ if (!isdigit((unsigned char)c))
+ return (0);
+ val = 0; base = 10;
+ if (c == '0') {
+ c = *++cp;
+ if (c == 'x' || c == 'X')
+ base = 16, c = *++cp;
+ else
+ base = 8;
+ }
+ for (;;) {
+ if (isascii((unsigned char)c) && isdigit((unsigned char)c)) {
+ val = (val * base) + (c - '0');
+ c = *++cp;
+ } else if (base == 16 && isascii((unsigned char)c) && isxdigit((unsigned char)c)) {
+ val = (val << 4) |
+ (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
+ c = *++cp;
+ } else
+ break;
+ }
+ if (c == '.') {
+ /*
+ * Internet format:
+ * a.b.c.d
+ * a.b.c (with c treated as 16 bits)
+ * a.b (with b treated as 24 bits)
+ */
+ if (pp >= parts + 3)
+ return (0);
+ *pp++ = val;
+ c = *++cp;
+ } else
+ break;
+ }
+ /*
+ * Check for trailing characters.
+ */
+ if (c != '\0' && (!isascii((unsigned char)c) || !isspace((unsigned char)c)))
+ return (0);
+ /*
+ * Concoct the address according to
+ * the number of parts specified.
+ */
+ n = pp - parts + 1;
+ switch (n) {
+
+ case 0:
+ return (0); /* initial nondigit */
+
+ case 1: /* a -- 32 bits */
+ break;
+
+ case 2: /* a.b -- 8.24 bits */
+ if (val > 0xffffff)
+ return (0);
+ val |= parts[0] << 24;
+ break;
+
+ case 3: /* a.b.c -- 8.8.16 bits */
+ if (val > 0xffff)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16);
+ break;
+
+ case 4: /* a.b.c.d -- 8.8.8.8 bits */
+ if (val > 0xff)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+ break;
+ }
+ if (addr != NULL)
+ addr->s_addr = htonl(val);
+ return (1);
+}
diff --git a/cpukit/libnetworking/libc/inet_lnaof.c b/cpukit/libnetworking/libc/inet_lnaof.c
new file mode 100644
index 0000000000..b97cf72439
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_lnaof.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Return the local network address portion of an
+ * internet address; handles class a/b/c network
+ * number formats.
+ */
+in_addr_t
+inet_lnaof(
+ struct in_addr in)
+{
+ register u_long i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return ((i)&IN_CLASSA_HOST);
+ else if (IN_CLASSB(i))
+ return ((i)&IN_CLASSB_HOST);
+ else
+ return ((i)&IN_CLASSC_HOST);
+}
diff --git a/cpukit/libnetworking/libc/inet_makeaddr.c b/cpukit/libnetworking/libc/inet_makeaddr.c
new file mode 100644
index 0000000000..183d20a3c0
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_makeaddr.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Formulate an Internet address from network + host. Used in
+ * building addresses stored in the ifnet structure.
+ */
+struct in_addr
+inet_makeaddr(
+ in_addr_t net,
+ in_addr_t host )
+{
+ u_long addr;
+
+ if (net < 128)
+ addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
+ else if (net < 65536)
+ addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
+ else if (net < 16777216L)
+ addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
+ else
+ addr = net | host;
+ addr = htonl(addr);
+ return (*(struct in_addr *)&addr);
+}
diff --git a/cpukit/libnetworking/libc/inet_net_ntop.c b/cpukit/libnetworking/libc/inet_net_ntop.c
new file mode 100644
index 0000000000..f756f0a209
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_net_ntop.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static char * inet_net_ntop_ipv4(const u_char *src, int bits,
+ char *dst, size_t size);
+
+/*
+ * char *
+ * inet_net_ntop(af, src, bits, dst, size)
+ * convert network number from network to presentation format.
+ * generates CIDR style result always.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+char *
+inet_net_ntop(af, src, bits, dst, size)
+ int af;
+ const void *src;
+ int bits;
+ char *dst;
+ size_t size;
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_ntop_ipv4(src, bits, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+}
+
+/*
+ * static char *
+ * inet_net_ntop_ipv4(src, bits, dst, size)
+ * convert IPv4 network number from network to presentation format.
+ * generates CIDR style result always.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ * network byte order assumed. this means 192.5.5.240/28 has
+ * 0x11110000 in its fourth octet.
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+static char *
+inet_net_ntop_ipv4(src, bits, dst, size)
+ const u_char *src;
+ int bits;
+ char *dst;
+ size_t size;
+{
+ char *odst = dst;
+ char *t;
+ u_int m;
+ int b;
+
+ if (bits < 0 || bits > 32) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ if (bits == 0) {
+ if (size < sizeof "0")
+ goto emsgsize;
+ *dst++ = '0';
+ *dst = '\0';
+ }
+
+ /* Format whole octets. */
+ for (b = bits / 8; b > 0; b--) {
+ if (size < sizeof "255.")
+ goto emsgsize;
+ t = dst;
+ dst += SPRINTF((dst, "%u", *src++));
+ if (b > 1) {
+ *dst++ = '.';
+ *dst = '\0';
+ }
+ size -= (size_t)(dst - t);
+ }
+
+ /* Format partial octet. */
+ b = bits % 8;
+ if (b > 0) {
+ if (size < sizeof ".255")
+ goto emsgsize;
+ t = dst;
+ if (dst != odst)
+ *dst++ = '.';
+ m = ((1 << b) - 1) << (8 - b);
+ dst += SPRINTF((dst, "%u", *src & m));
+ size -= (size_t)(dst - t);
+ }
+
+ /* Format CIDR /width. */
+ if (size < sizeof "/32")
+ goto emsgsize;
+ dst += SPRINTF((dst, "/%u", bits));
+ return (odst);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (NULL);
+}
diff --git a/cpukit/libnetworking/libc/inet_net_pton.c b/cpukit/libnetworking/libc/inet_net_pton.c
new file mode 100644
index 0000000000..3df64168f3
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_net_pton.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static int inet_net_pton_ipv4 __P((const char *src, u_char *dst,
+ size_t size));
+
+/*
+ * static int
+ * inet_net_pton(af, src, dst, size)
+ * convert network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not a valid network specification.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+int
+inet_net_pton(af, src, dst, size)
+ int af;
+ const char *src;
+ void *dst;
+ size_t size;
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_pton_ipv4(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+}
+
+/*
+ * static int
+ * inet_net_pton_ipv4(src, dst, size)
+ * convert IPv4 network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not an IPv4 network specification.
+ * note:
+ * network byte order assumed. this means 192.5.5.240/28 has
+ * 0x11110000 in its fourth octet.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+static int
+inet_net_pton_ipv4(src, dst, size)
+ const char *src;
+ u_char *dst;
+ size_t size;
+{
+ static const char
+ xdigits[] = "0123456789abcdef",
+ digits[] = "0123456789";
+ int n, ch, tmp, dirty, bits;
+ const u_char *odst = dst;
+
+ ch = *src++;
+ if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
+ && isascii(src[1]) && isxdigit(src[1])) {
+ /* Hexadecimal: Eat nybble string. */
+ if (size <= 0)
+ goto emsgsize;
+ *dst = 0, dirty = 0;
+ src++; /* skip x or X. */
+ while ((ch = *src++) != '\0' &&
+ isascii(ch) && isxdigit(ch)) {
+ if (isupper(ch))
+ ch = tolower(ch);
+ n = strchr(xdigits, ch) - xdigits;
+ assert(n >= 0 && n <= 15);
+ *dst |= n;
+ if (!dirty++)
+ *dst <<= 4;
+ else if (size-- > 0)
+ *++dst = 0, dirty = 0;
+ else
+ goto emsgsize;
+ }
+ if (dirty)
+ size--;
+ } else if (isascii(ch) && isdigit(ch)) {
+ /* Decimal: eat dotted digit string. */
+ for (;;) {
+ tmp = 0;
+ do {
+ n = strchr(digits, ch) - digits;
+ assert(n >= 0 && n <= 9);
+ tmp *= 10;
+ tmp += n;
+ if (tmp > 255)
+ goto enoent;
+ } while ((ch = *src++) != '\0' &&
+ isascii(ch) && isdigit(ch));
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = (u_char) tmp;
+ if (ch == '\0' || ch == '/')
+ break;
+ if (ch != '.')
+ goto enoent;
+ ch = *src++;
+ if (!isascii(ch) || !isdigit(ch))
+ goto enoent;
+ }
+ } else
+ goto enoent;
+
+ bits = -1;
+ if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
+ /* CIDR width specifier. Nothing can follow it. */
+ ch = *src++; /* Skip over the /. */
+ bits = 0;
+ do {
+ n = strchr(digits, ch) - digits;
+ assert(n >= 0 && n <= 9);
+ bits *= 10;
+ bits += n;
+ } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
+ if (ch != '\0')
+ goto enoent;
+ if (bits > 32)
+ goto emsgsize;
+ }
+
+ /* Firey death and destruction unless we prefetched EOS. */
+ if (ch != '\0')
+ goto enoent;
+
+ /* If nothing was written to the destination, we found no address. */
+ if (dst == odst)
+ goto enoent;
+ /* If no CIDR spec was given, infer width from net class. */
+ if (bits == -1) {
+ if (*odst >= 240) /* Class E */
+ bits = 32;
+ else if (*odst >= 224) /* Class D */
+ bits = 4;
+ else if (*odst >= 192) /* Class C */
+ bits = 24;
+ else if (*odst >= 128) /* Class B */
+ bits = 16;
+ else /* Class A */
+ bits = 8;
+ /* If imputed mask is narrower than specified octets, widen. */
+ if (bits >= 8 && bits < ((dst - odst) * 8))
+ bits = (dst - odst) * 8;
+ }
+ /* Extend network to cover the actual mask. */
+ while (bits > ((dst - odst) * 8)) {
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = '\0';
+ }
+ return (bits);
+
+ enoent:
+ errno = ENOENT;
+ return (-1);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
diff --git a/cpukit/libnetworking/libc/inet_neta.c b/cpukit/libnetworking/libc/inet_neta.c
new file mode 100644
index 0000000000..39f2404616
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_neta.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+/*
+ * char *
+ * inet_neta(src, dst, size)
+ * format a u_long network number into presentation format.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ * format of ``src'' is as for inet_network().
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+char *
+inet_neta(src, dst, size)
+ u_long src;
+ char *dst;
+ size_t size;
+{
+ char *odst = dst;
+ char *tp;
+
+ while (src & 0xffffffff) {
+ u_char b = (src & 0xff000000) >> 24;
+
+ src <<= 8;
+ if (b) {
+ if (size < sizeof "255.")
+ goto emsgsize;
+ tp = dst;
+ dst += SPRINTF((dst, "%u", b));
+ if (src != 0L) {
+ *dst++ = '.';
+ *dst = '\0';
+ }
+ size -= (size_t)(dst - tp);
+ }
+ }
+ if (dst == odst) {
+ if (size < sizeof "0.0.0.0")
+ goto emsgsize;
+ strcpy(dst, "0.0.0.0");
+ }
+ return (odst);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (NULL);
+}
diff --git a/cpukit/libnetworking/libc/inet_netof.c b/cpukit/libnetworking/libc/inet_netof.c
new file mode 100644
index 0000000000..e71f96f7f2
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_netof.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Return the network number from an internet
+ * address; handles class a/b/c network #'s.
+ */
+in_addr_t
+inet_netof(
+ struct in_addr in)
+{
+ register u_long i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ else if (IN_CLASSB(i))
+ return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ else
+ return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+}
diff --git a/cpukit/libnetworking/libc/inet_network.c b/cpukit/libnetworking/libc/inet_network.c
new file mode 100644
index 0000000000..ffeaa900a1
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_network.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+
+/*
+ * Internet network address interpretation routine.
+ * The library routines call this routine to interpret
+ * network numbers.
+ */
+in_addr_t
+inet_network(
+ const char *cp)
+{
+ register u_long val, base, n, i;
+ register char c;
+ u_long parts[4], *pp = parts;
+
+again:
+ val = 0; base = 10;
+ if (*cp == '0')
+ base = 8, cp++;
+ if (*cp == 'x' || *cp == 'X')
+ base = 16, cp++;
+ while ((c = *cp) != 0) {
+ if (isdigit((unsigned char)c)) {
+ val = (val * base) + (c - '0');
+ cp++;
+ continue;
+ }
+ if (base == 16 && isxdigit((unsigned char)c)) {
+ val = (val << 4) + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
+ cp++;
+ continue;
+ }
+ break;
+ }
+ if (*cp == '.') {
+ if (pp >= parts + 3)
+ return (INADDR_NONE);
+ *pp++ = val, cp++;
+ goto again;
+ }
+ if (*cp && !isspace((unsigned char)*cp))
+ return (INADDR_NONE);
+ *pp++ = val;
+ n = pp - parts;
+ for (val = 0, i = 0; i < n; i++) {
+ val <<= 8;
+ val |= parts[i] & 0xff;
+ }
+ return (val);
+}
diff --git a/cpukit/libnetworking/libc/inet_ntoa.c b/cpukit/libnetworking/libc/inet_ntoa.c
new file mode 100644
index 0000000000..cea3843776
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_ntoa.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <sys/libkern.h> /* for strcpy */
+
+/*
+ * Convert network-format internet address
+ * to base 256 d.d.d.d representation.
+ */
+char *
+inet_ntoa(
+ struct in_addr in)
+{
+ static char ret[18];
+
+ strcpy(ret, "[inet_ntoa error]");
+ (void) inet_ntop(AF_INET, &in, ret, sizeof ret);
+ return (ret);
+}
diff --git a/cpukit/libnetworking/libc/inet_ntop.c b/cpukit/libnetworking/libc/inet_ntop.c
new file mode 100644
index 0000000000..2e28dbbcd0
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_ntop.c
@@ -0,0 +1,193 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size);
+static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
+
+/* char *
+ * inet_ntop(af, src, dst, size)
+ * convert a network format address to presentation format.
+ * return:
+ * pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ * Paul Vixie, 1996.
+ */
+const char *
+inet_ntop(
+ int af,
+ const void *src,
+ char *dst,
+ socklen_t size)
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_ntop4(src, dst, size));
+ case AF_INET6:
+ return (inet_ntop6(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+ /* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ * format an IPv4 address, more or less like inet_ntoa()
+ * return:
+ * `dst' (as a const)
+ * notes:
+ * (1) uses no statics
+ * (2) takes a u_char* not an in_addr as input
+ * author:
+ * Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop4(
+ const u_char *src,
+ char *dst,
+ socklen_t size)
+{
+ static const char fmt[] = "%u.%u.%u.%u";
+ char tmp[sizeof "255.255.255.255"];
+
+ if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
+ errno = ENOSPC;
+ return (NULL);
+ }
+ strcpy(dst, tmp);
+ return (dst);
+}
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ * convert IPv6 binary address into presentation (printable) format
+ * author:
+ * Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop6(
+ const u_char *src,
+ char *dst,
+ socklen_t size)
+{
+ /*
+ * Note that int32_t and int16_t need only be "at least" large enough
+ * to contain a value of the specified size. On some systems, like
+ * Crays, there is no such thing as an integer variable with 16 bits.
+ * Keep this in mind if you think this function should have been coded
+ * to use pointer overlays. All the world's not a VAX.
+ */
+ char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+ struct { int base, len; } best, cur;
+ u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
+ int i;
+
+ /*
+ * Preprocess:
+ * Copy the input (bytewise) array into a wordwise array.
+ * Find the longest run of 0x00's in src[] for :: shorthanding.
+ */
+ memset(words, '\0', sizeof words);
+ for (i = 0; i < NS_IN6ADDRSZ; i++)
+ words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
+ best.base = -1;
+ best.len = 0;
+ cur.base = -1;
+ cur.len = 0;
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
+ if (words[i] == 0) {
+ if (cur.base == -1)
+ cur.base = i, cur.len = 1;
+ else
+ cur.len++;
+ } else {
+ if (cur.base != -1) {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ cur.base = -1;
+ }
+ }
+ }
+ if (cur.base != -1) {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ }
+ if (best.base != -1 && best.len < 2)
+ best.base = -1;
+
+ /*
+ * Format the result.
+ */
+ tp = tmp;
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
+ /* Are we inside the best run of 0x00's? */
+ if (best.base != -1 && i >= best.base &&
+ i < (best.base + best.len)) {
+ if (i == best.base)
+ *tp++ = ':';
+ continue;
+ }
+ /* Are we following an initial run of 0x00s or any real hex? */
+ if (i != 0)
+ *tp++ = ':';
+ /* Is this address an encapsulated IPv4? */
+ if (i == 6 && best.base == 0 &&
+ (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
+ if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
+ return (NULL);
+ tp += strlen(tp);
+ break;
+ }
+ tp += SPRINTF((tp, "%x", words[i]));
+ }
+ /* Was it a trailing run of 0x00's? */
+ if (best.base != -1 && (best.base + best.len) ==
+ (NS_IN6ADDRSZ / NS_INT16SZ))
+ *tp++ = ':';
+ *tp++ = '\0';
+
+ /*
+ * Check for overflow, copy, and we're done.
+ */
+ if ((size_t)(tp - tmp) > size) {
+ errno = ENOSPC;
+ return (NULL);
+ }
+ strcpy(dst, tmp);
+ return (dst);
+}
diff --git a/cpukit/libnetworking/libc/inet_pton.c b/cpukit/libnetworking/libc/inet_pton.c
new file mode 100644
index 0000000000..963c071353
--- /dev/null
+++ b/cpukit/libnetworking/libc/inet_pton.c
@@ -0,0 +1,214 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int inet_pton4(const char *src, u_char *dst);
+static int inet_pton6(const char *src, u_char *dst);
+
+/* int
+ * inet_pton(af, src, dst)
+ * convert from presentation format (which usually means ASCII printable)
+ * to network format (which is usually some kind of binary format).
+ * return:
+ * 1 if the address was valid for the specified address family
+ * 0 if the address wasn't valid (`dst' is untouched in this case)
+ * -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ * Paul Vixie, 1996.
+ */
+int
+inet_pton(
+ int af,
+ const char *src,
+ void *dst)
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4(src, dst));
+ case AF_INET6:
+ return (inet_pton6(src, dst));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+ /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ * like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ * 1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ * does not touch `dst' unless it's returning 1.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton4(
+ const char *src,
+ u_char *dst)
+{
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ u_char tmp[NS_INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ *(tp = tmp) = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr(digits, ch)) != NULL) {
+ u_int new = *tp * 10 + (pch - digits);
+
+ if (new > 255)
+ return (0);
+ *tp = new;
+ if (! saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+
+ memcpy(dst, tmp, NS_INADDRSZ);
+ return (1);
+}
+
+/* int
+ * inet_pton6(src, dst)
+ * convert presentation level address to network order binary form.
+ * return:
+ * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ * (1) does not touch `dst' unless it's returning 1.
+ * (2) :: in a full address is silently ignored.
+ * credit:
+ * inspired by Mark Andrews.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton6(
+ const char *src,
+ u_char *dst)
+{
+ static const char xdigits_l[] = "0123456789abcdef",
+ xdigits_u[] = "0123456789ABCDEF";
+ u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ u_int val;
+
+ memset((tp = tmp), '\0', NS_IN6ADDRSZ);
+ endp = tp + NS_IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':')
+ if (*++src != ':')
+ return (0);
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ pch = strchr((xdigits = xdigits_u), ch);
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff)
+ return (0);
+ saw_xdigit = 1;
+ continue;
+ }
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp)
+ return (0);
+ colonp = tp;
+ continue;
+ }
+ if (tp + NS_INT16SZ > endp)
+ return (0);
+ *tp++ = (u_char) (val >> 8) & 0xff;
+ *tp++ = (u_char) val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+ if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
+ inet_pton4(curtok, tp) > 0) {
+ tp += NS_INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+ return (0);
+ }
+ if (saw_xdigit) {
+ if (tp + NS_INT16SZ > endp)
+ return (0);
+ *tp++ = (u_char) (val >> 8) & 0xff;
+ *tp++ = (u_char) val & 0xff;
+ }
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = tp - colonp;
+ int i;
+
+ for (i = 1; i <= n; i++) {
+ endp[- i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+ tp = endp;
+ }
+ if (tp != endp)
+ return (0);
+ memcpy(dst, tmp, NS_IN6ADDRSZ);
+ return (1);
+}
diff --git a/cpukit/libnetworking/libc/linkaddr.3 b/cpukit/libnetworking/libc/linkaddr.3
new file mode 100644
index 0000000000..6999add0e8
--- /dev/null
+++ b/cpukit/libnetworking/libc/linkaddr.3
@@ -0,0 +1,138 @@
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley at BSDI.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" From: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93
+.\" $Id$
+.\"
+.Dd June 17, 1996
+.Dt LINK_ADDR 3
+.Os BSD 4.4
+.Sh NAME
+.Nm link_addr ,
+.Nm link_ntoa
+.Nd elementary address specification routines for link level access
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
+.Fd #include <net/if_dl.h>
+.Ft void
+.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl"
+.Ft char *
+.Fn link_ntoa "const struct sockaddr_dl *sdl"
+.Sh DESCRIPTION
+The routine
+.Fn link_addr
+interprets character strings representing
+link-level addresses, returning binary information suitable
+for use in system calls.
+The routine
+.Fn link_ntoa
+takes
+a link-level
+address and returns an
+.Tn ASCII
+string representing some of the information present,
+including the link level address itself, and the interface name
+or number, if present.
+This facility is experimental and is
+still subject to change.
+.Pp
+For
+.Fn link_addr ,
+the string
+.Fa addr
+may contain
+an optional network interface identifier of the form
+.Dq "name unit-number" ,
+suitable for the first argument to
+.Xr ifconfig 8 ,
+followed in all cases by a colon and
+an interface address in the form of
+groups of hexadecimal digits
+separated by periods.
+Each group represents a byte of address;
+address bytes are filled left to right from
+low order bytes through high order bytes.
+.Pp
+.\" A regular expression may make this format clearer:
+.\" .Bd -literal -offset indent
+.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)*
+.\" .Ed
+.\" .Pp
+Thus
+.Li le0:8.0.9.13.d.30
+represents an ethernet address
+to be transmitted on the first Lance ethernet interface.
+.Pp
+The direct use of these functions is deprecated in favor of the
+.Xr addr2ascii 3
+interface; however, portable programs cannot rely on the latter as it is
+not yet widely implemented.
+.Sh RETURN VALUES
+.Fn link_ntoa
+always returns a null terminated string.
+.Fn link_addr
+has no return value.
+(See
+.Sx BUGS . )
+.Sh SEE ALSO
+.Xr addr2ascii 3
+.\" .Xr iso 4
+.Sh HISTORY
+The
+.Fn link_addr
+and
+.Fn link_ntoa
+functions appeared in
+.Bx 4.3 Reno .
+.Sh BUGS
+The returned values for link_ntoa
+reside in a static memory area.
+.Pp
+The function
+.Fn link_addr
+should diagnose improperly formed input, and there should be an unambiguous
+way to recognize this.
+.Pp
+If the
+.Va sdl_len
+field of the link socket address
+.Fa sdl
+is 0,
+.Fn link_ntoa
+will not insert a colon before the interface address bytes.
+If this translated address is given to
+.Fn link_addr
+without inserting an initial colon,
+the latter will not interpret it correctly.
diff --git a/cpukit/libnetworking/libc/linkaddr.c b/cpukit/libnetworking/libc/linkaddr.c
new file mode 100644
index 0000000000..b7962c55b7
--- /dev/null
+++ b/cpukit/libnetworking/libc/linkaddr.c
@@ -0,0 +1,164 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if_dl.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+/* States*/
+#define NAMING 0
+#define GOTONE 1
+#define GOTTWO 2
+#define RESET 3
+/* Inputs */
+#define DIGIT (4*0)
+#define END (4*1)
+#define DELIM (4*2)
+#define LETTER (4*3)
+
+void
+link_addr(
+ const char *addr,
+ struct sockaddr_dl *sdl)
+{
+ char *cp = sdl->sdl_data;
+ char *cplim = sdl->sdl_len + (char *)sdl;
+ int byte = 0, state = NAMING,
+ new=0; /* new=0 to avoid warning */
+
+ bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
+ sdl->sdl_family = AF_LINK;
+ do {
+ state &= ~LETTER;
+ if ((*addr >= '0') && (*addr <= '9')) {
+ new = *addr - '0';
+ } else if ((*addr >= 'a') && (*addr <= 'f')) {
+ new = *addr - 'a' + 10;
+ } else if ((*addr >= 'A') && (*addr <= 'F')) {
+ new = *addr - 'A' + 10;
+ } else if (*addr == 0) {
+ state |= END;
+ } else if (state == NAMING &&
+ (((*addr >= 'A') && (*addr <= 'Z')) ||
+ ((*addr >= 'a') && (*addr <= 'z'))))
+ state |= LETTER;
+ else
+ state |= DELIM;
+ addr++;
+ switch (state /* | INPUT */) {
+ case NAMING | DIGIT:
+ case NAMING | LETTER:
+ *cp++ = addr[-1];
+ continue;
+ case NAMING | DELIM:
+ state = RESET;
+ sdl->sdl_nlen = cp - sdl->sdl_data;
+ continue;
+ case GOTTWO | DIGIT:
+ *cp++ = byte;
+ /* FALLTHROUGH */
+ case RESET | DIGIT:
+ state = GOTONE;
+ byte = new;
+ continue;
+ case GOTONE | DIGIT:
+ state = GOTTWO;
+ byte = new + (byte << 4);
+ continue;
+ default: /* | DELIM */
+ state = RESET;
+ *cp++ = byte;
+ byte = 0;
+ continue;
+ case GOTONE | END:
+ case GOTTWO | END:
+ *cp++ = byte;
+ /* FALLTHROUGH */
+ case RESET | END:
+ break;
+ }
+ break;
+ } while (cp < cplim);
+ sdl->sdl_alen = cp - LLADDR(sdl);
+ new = cp - (char *)sdl;
+ if (new > sizeof(*sdl))
+ sdl->sdl_len = new;
+ return;
+}
+
+static char hexlist[] = "0123456789abcdef";
+
+char *
+link_ntoa(
+ const struct sockaddr_dl *sdl)
+{
+ static char obuf[64];
+ char *out = obuf;
+ int i;
+ u_char *in = (u_char *)LLADDR(sdl);
+ u_char *inlim = in + sdl->sdl_alen;
+ int firsttime = 1;
+
+ if (sdl->sdl_nlen) {
+ memcpy(obuf, sdl->sdl_data, sdl->sdl_nlen);
+ out += sdl->sdl_nlen;
+ if (sdl->sdl_alen)
+ *out++ = ':';
+ }
+ while (in < inlim) {
+ if (firsttime)
+ firsttime = 0;
+ else
+ *out++ = '.';
+ i = *in++;
+ if (i > 0xf) {
+ out[1] = hexlist[i & 0xf];
+ i >>= 4;
+ out[0] = hexlist[i];
+ out += 2;
+ } else
+ *out++ = hexlist[i];
+ }
+ *out = 0;
+ return (obuf);
+}
diff --git a/cpukit/libnetworking/libc/map_v4v6.c b/cpukit/libnetworking/libc/map_v4v6.c
new file mode 100644
index 0000000000..0b13285756
--- /dev/null
+++ b/cpukit/libnetworking/libc/map_v4v6.c
@@ -0,0 +1,125 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <syslog.h>
+
+typedef union {
+ int32_t al;
+ char ac;
+} align;
+
+void
+_map_v4v6_address(const char *src, char *dst)
+{
+ u_char *p = (u_char *)dst;
+ char tmp[INADDRSZ];
+ int i;
+
+ /* Stash a temporary copy so our caller can update in place. */
+ memcpy(tmp, src, INADDRSZ);
+ /* Mark this ipv6 addr as a mapped ipv4. */
+ for (i = 0; i < 10; i++)
+ *p++ = 0x00;
+ *p++ = 0xff;
+ *p++ = 0xff;
+ /* Retrieve the saved copy and we're done. */
+ memcpy((void*)p, tmp, INADDRSZ);
+}
+
+void
+_map_v4v6_hostent(
+ struct hostent *hp,
+ char **bpp,
+ int *lenp)
+{
+ char **ap;
+
+ if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
+ return;
+ hp->h_addrtype = AF_INET6;
+ hp->h_length = IN6ADDRSZ;
+ for (ap = hp->h_addr_list; *ap; ap++) {
+ int i = sizeof(align) - ((uintptr_t)*bpp % sizeof(align));
+
+ if (*lenp < (i + IN6ADDRSZ)) {
+ /* Out of memory. Truncate address list here. XXX */
+ *ap = NULL;
+ return;
+ }
+ *bpp += i;
+ *lenp -= i;
+ _map_v4v6_address(*ap, *bpp);
+ *ap = *bpp;
+ *bpp += IN6ADDRSZ;
+ *lenp -= IN6ADDRSZ;
+ }
+}
diff --git a/cpukit/libnetworking/libc/ns.3 b/cpukit/libnetworking/libc/ns.3
new file mode 100644
index 0000000000..e621ad2d90
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns.3
@@ -0,0 +1,131 @@
+.\" Copyright (c) 1986, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)ns.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd June 4, 1993
+.Dt NS 3
+.Os BSD 4.3
+.Sh NAME
+.Nm ns_addr ,
+.Nm ns_ntoa
+.Nd Xerox
+.Tn NS Ns (tm)
+address conversion routines
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <netns/ns.h>
+.Ft struct ns_addr
+.Fn ns_addr "char *cp"
+.Ft char *
+.Fn ns_ntoa "struct ns_addr ns"
+.Sh DESCRIPTION
+The routine
+.Fn ns_addr
+interprets character strings representing
+.Tn XNS
+addresses, returning binary information suitable
+for use in system calls.
+The routine
+.Fn ns_ntoa
+takes
+.Tn XNS
+addresses and returns
+.Tn ASCII
+strings representing the address in a
+notation in common use in the Xerox Development Environment:
+.Bd -filled -offset indent
+<network number>.<host number>.<port number>
+.Ed
+.Pp
+Trailing zero fields are suppressed, and each number is printed in hexadecimal,
+in a format suitable for input to
+.Fn ns_addr .
+Any fields lacking super-decimal digits will have a
+trailing
+.Ql H
+appended.
+.Pp
+Unfortunately, no universal standard exists for representing
+.Tn XNS
+addresses.
+An effort has been made to insure that
+.Fn ns_addr
+be compatible with most formats in common use.
+It will first separate an address into 1 to 3 fields using a single delimiter
+chosen from
+period
+.Ql \&. ,
+colon
+.Ql \&:
+or pound-sign
+.Ql \&# .
+Each field is then examined for byte separators (colon or period).
+If there are byte separators, each subfield separated is taken to be
+a small hexadecimal number, and the entirety is taken as a network-byte-ordered
+quantity to be zero extended in the high-network-order bytes.
+Next, the field is inspected for hyphens, in which case
+the field is assumed to be a number in decimal notation
+with hyphens separating the millenia.
+Next, the field is assumed to be a number:
+It is interpreted
+as hexadecimal if there is a leading
+.Ql 0x
+(as in C),
+a trailing
+.Ql H
+(as in Mesa), or there are any super-decimal digits present.
+It is interpreted as octal is there is a leading
+.Ql 0
+and there are no super-octal digits.
+Otherwise, it is converted as a decimal number.
+.Sh RETURN VALUES
+None. (See
+.Sx BUGS . )
+.Sh SEE ALSO
+.Xr hosts 5 ,
+.Xr networks 5
+.Sh HISTORY
+The
+.Fn ns_addr
+and
+.Fn ns_toa
+functions appeared in
+.Bx 4.3 .
+.Sh BUGS
+The string returned by
+.Fn ns_ntoa
+resides in a static memory area.
+The function
+.Fn ns_addr
+should diagnose improperly formed input, and there should be an unambiguous
+way to recognize this.
diff --git a/cpukit/libnetworking/libc/ns_addr.c b/cpukit/libnetworking/libc/ns_addr.c
new file mode 100644
index 0000000000..5f17267297
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_addr.c
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * J.Q. Johnson.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <netns/ns.h>
+#include <stdio.h>
+#include <string.h>
+
+static struct ns_addr addr, zero_addr;
+
+static void Field(), cvtbase();
+
+struct ns_addr
+ns_addr(name)
+ const char *name;
+{
+ char separator;
+ char *hostname, *socketname, *cp;
+ char buf[50];
+
+ (void)strncpy(buf, name, sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+
+ /*
+ * First, figure out what he intends as a field separtor.
+ * Despite the way this routine is written, the prefered
+ * form 2-272.AA001234H.01777, i.e. XDE standard.
+ * Great efforts are made to insure backward compatability.
+ */
+ if ((hostname = strchr(buf, '#')) != NULL)
+ separator = '#';
+ else {
+ hostname = strchr(buf, '.');
+ if ((cp = strchr(buf, ':')) &&
+ ((hostname && cp < hostname) || (hostname == 0))) {
+ hostname = cp;
+ separator = ':';
+ } else
+ separator = '.';
+ }
+ if (hostname)
+ *hostname++ = 0;
+
+ addr = zero_addr;
+ Field(buf, addr.x_net.c_net, 4);
+ if (hostname == 0)
+ return (addr); /* No separator means net only */
+
+ socketname = strchr(hostname, separator);
+ if (socketname) {
+ *socketname++ = 0;
+ Field(socketname, (u_char *)&addr.x_port, 2);
+ }
+
+ Field(hostname, addr.x_host.c_host, 6);
+
+ return (addr);
+}
+
+static void
+Field(buf, out, len)
+ char *buf;
+ u_char *out;
+ int len;
+{
+ register char *bp = buf;
+ int i, ibase, base16 = 0, base10 = 0, clen = 0;
+ int hb[6], *hp;
+ char *fmt;
+
+ /*
+ * first try 2-273#2-852-151-014#socket
+ */
+ if ((*buf != '-') &&
+ (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d",
+ &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) {
+ cvtbase(1000L, 256, hb, i, out, len);
+ return;
+ }
+ /*
+ * try form 8E1#0.0.AA.0.5E.E6#socket
+ */
+ if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x",
+ &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
+ cvtbase(256L, 256, hb, i, out, len);
+ return;
+ }
+ /*
+ * try form 8E1#0:0:AA:0:5E:E6#socket
+ */
+ if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x",
+ &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
+ cvtbase(256L, 256, hb, i, out, len);
+ return;
+ }
+ /*
+ * This is REALLY stretching it but there was a
+ * comma notation separting shorts -- definitely non standard
+ */
+ if (1 < (i = sscanf(buf,"%x,%x,%x",
+ &hb[0], &hb[1], &hb[2]))) {
+ hb[0] = htons(hb[0]); hb[1] = htons(hb[1]);
+ hb[2] = htons(hb[2]);
+ cvtbase(65536L, 256, hb, i, out, len);
+ return;
+ }
+
+ /* Need to decide if base 10, 16 or 8 */
+ while (*bp) switch (*bp++) {
+
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '-':
+ break;
+
+ case '8': case '9':
+ base10 = 1;
+ break;
+
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ base16 = 1;
+ break;
+
+ case 'x': case 'X':
+ *--bp = '0';
+ base16 = 1;
+ break;
+
+ case 'h': case 'H':
+ base16 = 1;
+ /* fall into */
+
+ default:
+ *--bp = 0; /* Ends Loop */
+ }
+ if (base16) {
+ fmt = "%3x";
+ ibase = 4096;
+ } else if (base10 == 0 && *buf == '0') {
+ fmt = "%3o";
+ ibase = 512;
+ } else {
+ fmt = "%3d";
+ ibase = 1000;
+ }
+
+ for (bp = buf; *bp++; ) clen++;
+ if (clen == 0) clen++;
+ if (clen > 18) clen = 18;
+ i = ((clen - 1) / 3) + 1;
+ bp = clen + buf - 3;
+ hp = hb + i - 1;
+
+ while (hp > hb) {
+ (void)sscanf(bp, fmt, hp);
+ bp[0] = 0;
+ hp--;
+ bp -= 3;
+ }
+ (void)sscanf(buf, fmt, hp);
+ cvtbase((long)ibase, 256, hb, i, out, len);
+}
+
+static void
+cvtbase(oldbase,newbase,input,inlen,result,reslen)
+ long oldbase;
+ int newbase;
+ int input[];
+ int inlen;
+ unsigned char result[];
+ int reslen;
+{
+ int d, e;
+ long sum;
+
+ e = 1;
+ while (e > 0 && reslen > 0) {
+ d = 0; e = 0; sum = 0;
+ /* long division: input=input/newbase */
+ while (d < inlen) {
+ sum = sum*oldbase + (long) input[d];
+ e += (sum > 0);
+ input[d++] = sum / newbase;
+ sum %= newbase;
+ }
+ result[--reslen] = sum; /* accumulate remainder */
+ }
+ for (d=0; d < reslen; d++)
+ result[d] = 0;
+}
diff --git a/cpukit/libnetworking/libc/ns_name.c b/cpukit/libnetworking/libc/ns_name.c
new file mode 100644
index 0000000000..2823f4e43d
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_name.c
@@ -0,0 +1,593 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+
+/* Data. */
+
+static char digits[] = "0123456789";
+
+/* Forward. */
+
+static int special(int);
+static int printable(int);
+static int dn_find(const u_char *, const u_char *,
+ const u_char * const *,
+ const u_char * const *);
+
+/* Public. */
+
+/*
+ * ns_name_ntop(src, dst, dstsiz)
+ * Convert an encoded domain name to printable ascii as per RFC1035.
+ * return:
+ * Number of bytes written to buffer, or -1 (with errno set)
+ * notes:
+ * The root is returned as "."
+ * All other domains are returned in non absolute form
+ */
+int
+ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
+ const u_char *cp;
+ char *dn, *eom;
+ u_char c;
+ u_int n;
+
+ cp = src;
+ dn = dst;
+ eom = dst + dstsiz;
+
+ while ((n = *cp++) != 0) {
+ if ((n & NS_CMPRSFLGS) != 0) {
+ /* Some kind of compression pointer. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (dn != dst) {
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '.';
+ }
+ if (dn + n >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ for ((void)NULL; n > 0; n--) {
+ c = *cp++;
+ if (special(c)) {
+ if (dn + 1 >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '\\';
+ *dn++ = (char)c;
+ } else if (!printable(c)) {
+ if (dn + 3 >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '\\';
+ *dn++ = digits[c / 100];
+ *dn++ = digits[(c % 100) / 10];
+ *dn++ = digits[c % 10];
+ } else {
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = (char)c;
+ }
+ }
+ }
+ if (dn == dst) {
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '.';
+ }
+ if (dn >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dn++ = '\0';
+ return (dn - dst);
+}
+
+/*
+ * ns_name_pton(src, dst, dstsiz)
+ * Convert a ascii string into an encoded domain name as per RFC1035.
+ * return:
+ * -1 if it fails
+ * 1 if string was fully qualified
+ * 0 is string was not fully qualified
+ * notes:
+ * Enforces label and domain length limits.
+ */
+
+int
+ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
+ u_char *label, *bp, *eom;
+ int c, n, escaped;
+ char *cp;
+
+ escaped = 0;
+ bp = dst;
+ eom = dst + dstsiz;
+ label = bp++;
+
+ while ((c = *src++) != 0) {
+ if (escaped) {
+ if ((cp = strchr(digits, c)) != NULL) {
+ n = (cp - digits) * 100;
+ if ((c = *src++) == 0 ||
+ (cp = strchr(digits, c)) == NULL) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ n += (cp - digits) * 10;
+ if ((c = *src++) == 0 ||
+ (cp = strchr(digits, c)) == NULL) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ n += (cp - digits);
+ if (n > 255) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ c = n;
+ }
+ escaped = 0;
+ } else if (c == '\\') {
+ escaped = 1;
+ continue;
+ } else if (c == '.') {
+ c = (bp - label - 1);
+ if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (label >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *label = c;
+ /* Fully qualified ? */
+ if (*src == '\0') {
+ if (c != 0) {
+ if (bp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *bp++ = '\0';
+ }
+ if ((bp - dst) > MAXCDNAME) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ return (1);
+ }
+ if (c == 0) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ label = bp++;
+ continue;
+ }
+ if (bp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *bp++ = (u_char)c;
+ }
+ c = (bp - label - 1);
+ if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (label >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *label = c;
+ if (c != 0) {
+ if (bp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *bp++ = 0;
+ }
+ if ((bp - dst) > MAXCDNAME) { /* src too big */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * ns_name_unpack(msg, eom, src, dst, dstsiz)
+ * Unpack a domain name from a message, source may be compressed.
+ * return:
+ * -1 if it fails, or consumed octets if it succeeds.
+ */
+int
+ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
+ u_char *dst, size_t dstsiz)
+{
+ const u_char *srcp, *dstlim;
+ u_char *dstp;
+ int n, len, checked;
+
+ len = -1;
+ checked = 0;
+ dstp = dst;
+ srcp = src;
+ dstlim = dst + dstsiz;
+ if (srcp < msg || srcp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ /* Fetch next label in domain name. */
+ while ((n = *srcp++) != 0) {
+ /* Check for indirection. */
+ switch (n & NS_CMPRSFLGS) {
+ case 0:
+ /* Limit checks. */
+ if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ checked += n + 1;
+ *dstp++ = n;
+ memcpy(dstp, srcp, n);
+ dstp += n;
+ srcp += n;
+ break;
+
+ case NS_CMPRSFLGS:
+ if (srcp >= eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (len < 0)
+ len = srcp - src + 1;
+ srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
+ if (srcp < msg || srcp >= eom) { /* Out of range. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ checked += 2;
+ /*
+ * Check for loops in the compressed name;
+ * if we've looked at the whole message,
+ * there must be a loop.
+ */
+ if (checked >= eom - msg) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ break;
+
+ default:
+ errno = EMSGSIZE;
+ return (-1); /* flag error */
+ }
+ }
+ *dstp = '\0';
+ if (len < 0)
+ len = srcp - src;
+ return (len);
+}
+
+/*
+ * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
+ * Pack domain name 'domain' into 'comp_dn'.
+ * return:
+ * Size of the compressed name, or -1.
+ * notes:
+ * 'dnptrs' is an array of pointers to previous compressed names.
+ * dnptrs[0] is a pointer to the beginning of the message. The array
+ * ends with NULL.
+ * 'lastdnptr' is a pointer to the end of the array pointed to
+ * by 'dnptrs'.
+ * Side effects:
+ * The list of pointers in dnptrs is updated for labels inserted into
+ * the message as we compress the name. If 'dnptr' is NULL, we don't
+ * try to compress names. If 'lastdnptr' is NULL, we don't update the
+ * list.
+ */
+int
+ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
+ const u_char **dnptrs, const u_char **lastdnptr)
+{
+ u_char *dstp;
+ const u_char **cpp, **lpp, *eob, *msg;
+ const u_char *srcp;
+ int n, l;
+
+ srcp = src;
+ dstp = dst;
+ eob = dstp + dstsiz;
+ lpp = cpp = NULL;
+ if (dnptrs != NULL) {
+ if ((msg = *dnptrs++) != NULL) {
+ for (cpp = dnptrs; *cpp != NULL; cpp++)
+ (void)NULL;
+ lpp = cpp; /* end of list to search */
+ }
+ } else
+ msg = NULL;
+
+ /* make sure the domain we are about to add is legal */
+ l = 0;
+ do {
+ n = *srcp;
+ if ((n & NS_CMPRSFLGS) != 0) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ l += n + 1;
+ if (l > MAXCDNAME) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ srcp += n + 1;
+ } while (n != 0);
+
+ srcp = src;
+ do {
+ /* Look to see if we can use pointers. */
+ n = *srcp;
+ if (n != 0 && msg != NULL) {
+ l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
+ (const u_char * const *)lpp);
+ if (l >= 0) {
+ if (dstp + 1 >= eob) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *dstp++ = (l >> 8) | NS_CMPRSFLGS;
+ *dstp++ = l % 256;
+ return (dstp - dst);
+ }
+ /* Not found, save it. */
+ if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
+ (dstp - msg) < 0x4000) {
+ *cpp++ = dstp;
+ *cpp = NULL;
+ }
+ }
+ /* copy label to buffer */
+ if (n & NS_CMPRSFLGS) { /* Should not happen. */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ if (dstp + 1 + n >= eob) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ memcpy(dstp, srcp, n + 1);
+ srcp += n + 1;
+ dstp += n + 1;
+ } while (n != 0);
+
+ if (dstp > eob) {
+ if (msg != NULL)
+ *lpp = NULL;
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ return (dstp - dst);
+}
+
+/*
+ * ns_name_uncompress(msg, eom, src, dst, dstsiz)
+ * Expand compressed domain name to presentation format.
+ * return:
+ * Number of bytes read out of `src', or -1 (with errno set).
+ * note:
+ * Root domain returns as "." not "".
+ */
+int
+ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
+ char *dst, size_t dstsiz)
+{
+ u_char tmp[NS_MAXCDNAME];
+ int n;
+
+ if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
+ return (-1);
+ if (ns_name_ntop(tmp, dst, dstsiz) == -1)
+ return (-1);
+ return (n);
+}
+
+/*
+ * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
+ * Compress a domain name into wire format, using compression pointers.
+ * return:
+ * Number of bytes consumed in `dst' or -1 (with errno set).
+ * notes:
+ * 'dnptrs' is an array of pointers to previous compressed names.
+ * dnptrs[0] is a pointer to the beginning of the message.
+ * The list ends with NULL. 'lastdnptr' is a pointer to the end of the
+ * array pointed to by 'dnptrs'. Side effect is to update the list of
+ * pointers for labels inserted into the message as we compress the name.
+ * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
+ * is NULL, we don't update the list.
+ */
+int
+ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
+ const u_char **dnptrs, const u_char **lastdnptr)
+{
+ u_char tmp[NS_MAXCDNAME];
+
+ if (ns_name_pton(src, tmp, sizeof tmp) == -1)
+ return (-1);
+ return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
+}
+
+/*
+ * ns_name_skip(ptrptr, eom)
+ * Advance *ptrptr to skip over the compressed name it points at.
+ * return:
+ * 0 on success, -1 (with errno set) on failure.
+ */
+int
+ns_name_skip(const u_char **ptrptr, const u_char *eom) {
+ const u_char *cp;
+ u_int n;
+
+ cp = *ptrptr;
+ while (cp < eom && (n = *cp++) != 0) {
+ /* Check for indirection. */
+ switch (n & NS_CMPRSFLGS) {
+ case 0: /* normal case, n == len */
+ cp += n;
+ continue;
+ case NS_CMPRSFLGS: /* indirection */
+ cp++;
+ break;
+ default: /* illegal type */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ break;
+ }
+ if (cp > eom) {
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ *ptrptr = cp;
+ return (0);
+}
+
+/* Private. */
+
+/*
+ * special(ch)
+ * Thinking in noninternationalized USASCII (per the DNS spec),
+ * is this characted special ("in need of quoting") ?
+ * return:
+ * boolean.
+ */
+static int
+special(int ch) {
+ switch (ch) {
+ case 0x22: /* '"' */
+ case 0x2E: /* '.' */
+ case 0x3B: /* ';' */
+ case 0x5C: /* '\\' */
+ /* Special modifiers in zone files. */
+ case 0x40: /* '@' */
+ case 0x24: /* '$' */
+ return (1);
+ default:
+ return (0);
+ }
+}
+
+/*
+ * printable(ch)
+ * Thinking in noninternationalized USASCII (per the DNS spec),
+ * is this character visible and not a space when printed ?
+ * return:
+ * boolean.
+ */
+static int
+printable(int ch) {
+ return (ch > 0x20 && ch < 0x7f);
+}
+
+/*
+ * Thinking in noninternationalized USASCII (per the DNS spec),
+ * convert this character to lower case if it's upper case.
+ */
+static int
+mklower(int ch) {
+ if (ch >= 0x41 && ch <= 0x5A)
+ return (ch + 0x20);
+ return (ch);
+}
+
+/*
+ * dn_find(domain, msg, dnptrs, lastdnptr)
+ * Search for the counted-label name in an array of compressed names.
+ * return:
+ * offset from msg if found, or -1.
+ * notes:
+ * dnptrs is the pointer to the first name on the list,
+ * not the pointer to the start of the message.
+ */
+static int
+dn_find(const u_char *domain, const u_char *msg,
+ const u_char * const *dnptrs,
+ const u_char * const *lastdnptr)
+{
+ const u_char *dn, *cp, *sp;
+ const u_char * const *cpp;
+ u_int n;
+
+ for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
+ dn = domain;
+ sp = cp = *cpp;
+ while ((n = *cp++) != 0) {
+ /*
+ * check for indirection
+ */
+ switch (n & NS_CMPRSFLGS) {
+ case 0: /* normal case, n == len */
+ if (n != *dn++)
+ goto next;
+ for ((void)NULL; n > 0; n--)
+ if (mklower(*dn++) != mklower(*cp++))
+ goto next;
+ /* Is next root for both ? */
+ if (*dn == '\0' && *cp == '\0')
+ return (sp - msg);
+ if (*dn)
+ continue;
+ goto next;
+
+ case NS_CMPRSFLGS: /* indirection */
+ cp = msg + (((n & 0x3f) << 8) | *cp);
+ break;
+
+ default: /* illegal type */
+ errno = EMSGSIZE;
+ return (-1);
+ }
+ }
+ next: ;
+ }
+ errno = ENOENT;
+ return (-1);
+}
diff --git a/cpukit/libnetworking/libc/ns_netint.c b/cpukit/libnetworking/libc/ns_netint.c
new file mode 100644
index 0000000000..e620faf95c
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_netint.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/* Import. */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+u_int
+ns_get16(const u_char *src) {
+ u_int dst;
+
+ NS_GET16(dst, src);
+ return (dst);
+}
+
+u_long
+ns_get32(const u_char *src) {
+ u_long dst;
+
+ NS_GET32(dst, src);
+ return (dst);
+}
+
+void
+ns_put16(u_int src, u_char *dst) {
+ NS_PUT16(src, dst);
+}
+
+void
+ns_put32(u_long src, u_char *dst) {
+ NS_PUT32(src, dst);
+}
diff --git a/cpukit/libnetworking/libc/ns_ntoa.c b/cpukit/libnetworking/libc/ns_ntoa.c
new file mode 100644
index 0000000000..9934e2947a
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_ntoa.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <netns/ns.h>
+#include <stdio.h>
+
+char *
+ns_ntoa(addr)
+ struct ns_addr addr;
+{
+ static char obuf[40];
+ union { union ns_net net_e; u_long long_e; } net;
+ u_short port = htons(addr.x_port);
+ register char *cp;
+ char *cp2;
+ register u_char *up = addr.x_host.c_host;
+ u_char *uplim = up + 6;
+ static char *spectHex();
+
+ net.net_e = addr.x_net;
+ sprintf(obuf, "%lx", (u_long)ntohl(net.long_e));
+ cp = spectHex(obuf);
+ cp2 = cp + 1;
+ while (*up==0 && up < uplim) up++;
+ if (up == uplim) {
+ if (port) {
+ sprintf(cp, ".0");
+ cp += 2;
+ }
+ } else {
+ sprintf(cp, ".%x", *up++);
+ while (up < uplim) {
+ while (*cp) cp++;
+ sprintf(cp, "%02x", *up++);
+ }
+ cp = spectHex(cp2);
+ }
+ if (port) {
+ sprintf(cp, ".%x", port);
+ spectHex(cp + 1);
+ }
+ return (obuf);
+}
+
+static char *
+spectHex(p0)
+ char *p0;
+{
+ int ok = 0;
+ int nonzero = 0;
+ register char *p = p0;
+ for (; *p; p++) switch (*p) {
+
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ *p += ('A' - 'a');
+ /* fall into . . . */
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ ok = 1;
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ nonzero = 1;
+ }
+ if (nonzero && !ok) { *p++ = 'H'; *p = 0; }
+ return (p);
+}
diff --git a/cpukit/libnetworking/libc/ns_parse.c b/cpukit/libnetworking/libc/ns_parse.c
new file mode 100644
index 0000000000..e4e087d26b
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_parse.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+
+/* These need to be in the same order as the nres.h:ns_flag enum. */
+struct _ns_flagdata _ns_flagdata[16] = {
+ { 0x8000, 15 }, /* qr. */
+ { 0x7800, 11 }, /* opcode. */
+ { 0x0400, 10 }, /* aa. */
+ { 0x0200, 9 }, /* tc. */
+ { 0x0100, 8 }, /* rd. */
+ { 0x0080, 7 }, /* ra. */
+ { 0x0040, 6 }, /* z. */
+ { 0x0020, 5 }, /* ad. */
+ { 0x0010, 4 }, /* cd. */
+ { 0x000f, 0 }, /* rcode. */
+ { 0x0000, 0 }, /* expansion (1/6). */
+ { 0x0000, 0 }, /* expansion (2/6). */
+ { 0x0000, 0 }, /* expansion (3/6). */
+ { 0x0000, 0 }, /* expansion (4/6). */
+ { 0x0000, 0 }, /* expansion (5/6). */
+ { 0x0000, 0 }, /* expansion (6/6). */
+};
+
+static int
+skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
+ const u_char *optr = ptr;
+
+ for ((void)NULL; count > 0; count--) {
+ int b, rdlength;
+
+ b = dn_skipname(ptr, eom);
+ if (b < 0)
+ goto emsgsize;
+ ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
+ if (section != ns_s_qd) {
+ if (ptr + NS_INT32SZ > eom)
+ goto emsgsize;
+ ptr += NS_INT32SZ/*TTL*/;
+ if (ptr + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(rdlength, ptr);
+ ptr += rdlength/*RData*/;
+ }
+ }
+ if (ptr > eom)
+ goto emsgsize;
+ return (ptr - optr);
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
+
+int
+ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
+ const u_char *eom = msg + msglen;
+ int i;
+
+ memset(handle, 0x5e, sizeof *handle);
+ handle->_msg = msg;
+ handle->_eom = eom;
+ if (msg + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(handle->_id, msg);
+ if (msg + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(handle->_flags, msg);
+ for (i = 0; i < ns_s_max; i++) {
+ if (msg + NS_INT16SZ > eom)
+ goto emsgsize;
+ NS_GET16(handle->_counts[i], msg);
+ }
+ for (i = 0; i < ns_s_max; i++)
+ if (handle->_counts[i] == 0)
+ handle->_sections[i] = NULL;
+ else {
+ int b = skiprr(msg, eom, (ns_sect)i,
+ handle->_counts[i]);
+
+ if (b < 0)
+ return (-1);
+ handle->_sections[i] = msg;
+ msg += b;
+ }
+ if (msg != eom)
+ goto emsgsize;
+ handle->_sect = ns_s_max;
+ handle->_rrnum = -1;
+ handle->_ptr = NULL;
+ return (0);
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
+
+int
+ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
+ int b;
+
+ /* Make section right. */
+ if (section < 0 || section >= ns_s_max)
+ goto enodev;
+ if ((int)section != (int)handle->_sect) {
+ handle->_sect = section;
+ handle->_rrnum = 0;
+ handle->_ptr = handle->_sections[(int)section];
+ }
+
+ /* Make rrnum right. */
+ if (rrnum == -1)
+ rrnum = handle->_rrnum;
+ if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
+ goto enodev;
+ if (rrnum < handle->_rrnum) {
+ handle->_rrnum = 0;
+ handle->_ptr = handle->_sections[(int)section];
+ }
+
+ b = skiprr(handle->_msg, handle->_eom, section,
+ rrnum - handle->_rrnum);
+ if (b < 0)
+ return (-1);
+ handle->_ptr += b;
+ handle->_rrnum = rrnum;
+
+ /* Do the parse. */
+ b = dn_expand(handle->_msg, handle->_eom,
+ handle->_ptr, rr->name, NS_MAXDNAME);
+ if (b < 0)
+ return (-1);
+ handle->_ptr += b;
+ if (handle->_ptr + NS_INT16SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET16(rr->type, handle->_ptr);
+ if (handle->_ptr + NS_INT16SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET16(rr->rr_class, handle->_ptr);
+ if (section == ns_s_qd) {
+ rr->ttl = 0;
+ rr->rdlength = 0;
+ rr->rdata = NULL;
+ } else {
+ if (handle->_ptr + NS_INT32SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET32(rr->ttl, handle->_ptr);
+ if (handle->_ptr + NS_INT16SZ > handle->_eom)
+ goto emsgsize;
+ NS_GET16(rr->rdlength, handle->_ptr);
+ if (handle->_ptr + rr->rdlength > handle->_eom)
+ goto emsgsize;
+ rr->rdata = handle->_ptr;
+ handle->_ptr += rr->rdlength;
+ }
+ handle->_rrnum++;
+
+ /* All done. */
+ return (0);
+ enodev:
+ errno = ENODEV;
+ return (-1);
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
diff --git a/cpukit/libnetworking/libc/ns_print.c b/cpukit/libnetworking/libc/ns_print.c
new file mode 100644
index 0000000000..d8133c97d9
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_print.c
@@ -0,0 +1,746 @@
+/*
+ * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/* Import. */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <resolv.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <ctype.h>
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+/* Forward. */
+
+static size_t prune_origin(const char *name, const char *origin);
+static int charstr(const u_char *rdata, const u_char *edata,
+ char **buf, size_t *buflen);
+static int addname(const u_char *msg, size_t msglen,
+ const u_char **p, const char *origin,
+ char **buf, size_t *buflen);
+static void addlen(size_t len, char **buf, size_t *buflen);
+static int addstr(const char *src, size_t len,
+ char **buf, size_t *buflen);
+static int addtab(size_t len, size_t target, int spaced,
+ char **buf, size_t *buflen);
+
+/* Macros. */
+
+#define T(x) \
+ do { \
+ if ((x) < 0) \
+ return (-1); \
+ } while (0)
+
+/* Public. */
+
+/*
+ * int
+ * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen)
+ * Convert an RR to presentation format.
+ * return:
+ * Number of characters written to buf, or -1 (check errno).
+ */
+int
+ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
+ const char *name_ctx, const char *origin,
+ char *buf, size_t buflen)
+{
+ int n;
+
+ n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
+ ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
+ ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
+ name_ctx, origin, buf, buflen);
+ return (n);
+}
+
+/*
+ * int
+ * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen,
+ * name_ctx, origin, buf, buflen)
+ * Convert the fields of an RR into presentation format.
+ * return:
+ * Number of characters written to buf, or -1 (check errno).
+ */
+int
+ns_sprintrrf(const u_char *msg, size_t msglen,
+ const char *name, ns_class class, ns_type type,
+ u_long ttl, const u_char *rdata, size_t rdlen,
+ const char *name_ctx, const char *origin,
+ char *buf, size_t buflen)
+{
+ const char *obuf = buf;
+ const u_char *edata = rdata + rdlen;
+ int spaced = 0;
+
+ const char *comment;
+ char tmp[100];
+ int len, x;
+
+ /*
+ * Owner.
+ */
+ if (name_ctx != NULL && strcasecmp(name_ctx, name) == 0) {
+ T(addstr("\t\t\t", 3, &buf, &buflen));
+ } else {
+ len = prune_origin(name, origin);
+ if (len == 0) {
+ T(addstr("@\t\t\t", 4, &buf, &buflen));
+ } else {
+ T(addstr(name, len, &buf, &buflen));
+ /* Origin not used and no trailing dot? */
+ if ((!origin || !origin[0] || name[len] == '\0') &&
+ name[len - 1] != '.') {
+ T(addstr(".", 1, &buf, &buflen));
+ len++;
+ }
+ T(spaced = addtab(len, 24, spaced, &buf, &buflen));
+ }
+ }
+
+ /*
+ * TTL, Class, Type.
+ */
+ T(x = ns_format_ttl(ttl, buf, buflen));
+ addlen(x, &buf, &buflen);
+ len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
+ T(addstr(tmp, len, &buf, &buflen));
+ T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));
+
+ /*
+ * RData.
+ */
+ switch (type) {
+ case ns_t_a:
+ if (rdlen != NS_INADDRSZ)
+ goto formerr;
+ (void) inet_ntop(AF_INET, rdata, buf, buflen);
+ addlen(strlen(buf), &buf, &buflen);
+ break;
+
+ case ns_t_cname:
+ case ns_t_mb:
+ case ns_t_mg:
+ case ns_t_mr:
+ case ns_t_ns:
+ case ns_t_ptr:
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ break;
+
+ case ns_t_hinfo:
+ case ns_t_isdn:
+ /* First word. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Second word. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ break;
+
+ case ns_t_soa: {
+ u_long t;
+
+ /* Server name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Administrator name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" (\n", 3, &buf, &buflen));
+ spaced = 0;
+
+ if ((edata - rdata) != 5*NS_INT32SZ)
+ goto formerr;
+
+ /* Serial number. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ len = SPRINTF((tmp, "%lu", t));
+ T(addstr(tmp, len, &buf, &buflen));
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; serial\n", 9, &buf, &buflen));
+ spaced = 0;
+
+ /* Refresh interval. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; refresh\n", 10, &buf, &buflen));
+ spaced = 0;
+
+ /* Retry interval. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; retry\n", 8, &buf, &buflen));
+ spaced = 0;
+
+ /* Expiry. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; expiry\n", 9, &buf, &buflen));
+ spaced = 0;
+
+ /* Minimum TTL. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
+ T(len = ns_format_ttl(t, buf, buflen));
+ addlen(len, &buf, &buflen);
+ T(addstr(" )", 2, &buf, &buflen));
+ T(spaced = addtab(len, 16, spaced, &buf, &buflen));
+ T(addstr("; minimum\n", 10, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_mx:
+ case ns_t_afsdb:
+ case ns_t_rt: {
+ u_int t;
+
+ if (rdlen < NS_INT16SZ)
+ goto formerr;
+
+ /* Priority. */
+ t = ns_get16(rdata);
+ rdata += NS_INT16SZ;
+ len = SPRINTF((tmp, "%u ", t));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Target. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_px: {
+ u_int t;
+
+ if (rdlen < NS_INT16SZ)
+ goto formerr;
+
+ /* Priority. */
+ t = ns_get16(rdata);
+ rdata += NS_INT16SZ;
+ len = SPRINTF((tmp, "%u ", t));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Name1. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Name2. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_x25:
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ break;
+
+ case ns_t_txt:
+ while (rdata < edata) {
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ if (rdata < edata)
+ T(addstr(" ", 1, &buf, &buflen));
+ }
+ break;
+
+ case ns_t_nsap: {
+ char t[255*3];
+
+ (void) inet_nsap_ntoa(rdlen, rdata, t);
+ T(addstr(t, strlen(t), &buf, &buflen));
+ break;
+ }
+
+ case ns_t_aaaa:
+ if (rdlen != NS_IN6ADDRSZ)
+ goto formerr;
+ (void) inet_ntop(AF_INET6, rdata, buf, buflen);
+ addlen(strlen(buf), &buf, &buflen);
+ break;
+
+ case ns_t_loc: {
+ char t[255];
+
+ /* XXX protocol format checking? */
+ (void) loc_ntoa(rdata, t);
+ T(addstr(t, strlen(t), &buf, &buflen));
+ break;
+ }
+
+ case ns_t_naptr: {
+ u_int order, preference;
+ char t[50];
+
+ if (rdlen < 2*NS_INT16SZ)
+ goto formerr;
+
+ /* Order, Precedence. */
+ order = ns_get16(rdata); rdata += NS_INT16SZ;
+ preference = ns_get16(rdata); rdata += NS_INT16SZ;
+ len = SPRINTF((t, "%u %u ", order, preference));
+ T(addstr(t, len, &buf, &buflen));
+
+ /* Flags. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Service. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Regexp. */
+ T(len = charstr(rdata, edata, &buf, &buflen));
+ if (len < 0)
+ return (-1);
+ if (len == 0)
+ goto formerr;
+ rdata += len;
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Server. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ break;
+ }
+
+ case ns_t_srv: {
+ u_int priority, weight, port;
+ char t[50];
+
+ if (rdlen < NS_INT16SZ*3)
+ goto formerr;
+
+ /* Priority, Weight, Port. */
+ priority = ns_get16(rdata); rdata += NS_INT16SZ;
+ weight = ns_get16(rdata); rdata += NS_INT16SZ;
+ port = ns_get16(rdata); rdata += NS_INT16SZ;
+ len = SPRINTF((t, "%u %u %u ", priority, weight, port));
+ T(addstr(t, len, &buf, &buflen));
+
+ /* Server. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ break;
+ }
+
+ case ns_t_minfo:
+ case ns_t_rp:
+ /* Name1. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+ T(addstr(" ", 1, &buf, &buflen));
+
+ /* Name2. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ break;
+
+ case ns_t_wks: {
+ int n, lcnt;
+
+ if (rdlen < NS_INT32SZ + 1)
+ goto formerr;
+
+ /* Address. */
+ (void) inet_ntop(AF_INET, rdata, buf, buflen);
+ addlen(strlen(buf), &buf, &buflen);
+ rdata += NS_INADDRSZ;
+
+ /* Protocol. */
+ len = SPRINTF((tmp, " %u ( ", *rdata));
+ T(addstr(tmp, len, &buf, &buflen));
+ rdata += NS_INT8SZ;
+
+ /* Bit map. */
+ n = 0;
+ lcnt = 0;
+ while (rdata < edata) {
+ u_int c = *rdata++;
+ do {
+ if (c & 0200) {
+ if (lcnt == 0) {
+ T(addstr("\n\t\t\t\t", 5,
+ &buf, &buflen));
+ lcnt = 10;
+ spaced = 0;
+ }
+ len = SPRINTF((tmp, "%d ", n));
+ T(addstr(tmp, len, &buf, &buflen));
+ lcnt--;
+ }
+ c <<= 1;
+ } while (++n & 07);
+ }
+ T(addstr(")", 1, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_key: {
+ char base64_key[NS_MD5RSA_MAX_BASE64];
+ u_int keyflags, protocol, algorithm;
+ const char *leader;
+ int n;
+
+ if (rdlen < NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
+ goto formerr;
+
+ /* Key flags, Protocol, Algorithm. */
+ keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
+ protocol = *rdata++;
+ algorithm = *rdata++;
+ len = SPRINTF((tmp, "0x%04x %u %u",
+ keyflags, protocol, algorithm));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Public key data. */
+ len = b64_ntop(rdata, edata - rdata,
+ base64_key, sizeof base64_key);
+ if (len < 0)
+ goto formerr;
+ if (len > 15) {
+ T(addstr(" (", 2, &buf, &buflen));
+ leader = "\n\t\t";
+ spaced = 0;
+ } else
+ leader = " ";
+ for (n = 0; n < len; n += 48) {
+ T(addstr(leader, strlen(leader), &buf, &buflen));
+ T(addstr(base64_key + n, MIN(len - n, 48),
+ &buf, &buflen));
+ }
+ if (len > 15)
+ T(addstr(" )", 2, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_sig: {
+ char base64_key[NS_MD5RSA_MAX_BASE64];
+ u_int type, algorithm, labels, footprint;
+ const char *leader;
+ u_long t;
+ int n;
+
+ if (rdlen < 22)
+ goto formerr;
+
+ /* Type covered, Algorithm, Label count, Original TTL. */
+ type = ns_get16(rdata); rdata += NS_INT16SZ;
+ algorithm = *rdata++;
+ labels = *rdata++;
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ len = SPRINTF((tmp, " %s %d %lu ",
+ p_type(type), algorithm, t));
+ T(addstr(tmp, len, &buf, &buflen));
+ if (labels != (u_int)dn_count_labels(name))
+ goto formerr;
+
+ /* Signature expiry. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Time signed. */
+ t = ns_get32(rdata); rdata += NS_INT32SZ;
+ len = SPRINTF((tmp, "%s ", p_secstodate(t)));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Signature Footprint. */
+ footprint = ns_get16(rdata); rdata += NS_INT16SZ;
+ len = SPRINTF((tmp, "%u ", footprint));
+ T(addstr(tmp, len, &buf, &buflen));
+
+ /* Signer's name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ /* Signature. */
+ len = b64_ntop(rdata, edata - rdata,
+ base64_key, sizeof base64_key);
+ if (len > 15) {
+ T(addstr(" (", 2, &buf, &buflen));
+ leader = "\n\t\t";
+ spaced = 0;
+ } else
+ leader = " ";
+ if (len < 0)
+ goto formerr;
+ for (n = 0; n < len; n += 48) {
+ T(addstr(leader, strlen(leader), &buf, &buflen));
+ T(addstr(base64_key + n, MIN(len - n, 48),
+ &buf, &buflen));
+ }
+ if (len > 15)
+ T(addstr(" )", 2, &buf, &buflen));
+
+ break;
+ }
+
+ case ns_t_nxt: {
+ int n, c;
+
+ /* Next domain name. */
+ T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
+
+ /* Type bit map. */
+ n = edata - rdata;
+ for (c = 0; c < n*8; c++)
+ if (NS_NXT_BIT_ISSET(c, rdata)) {
+ len = SPRINTF((tmp, " %s", p_type(c)));
+ T(addstr(tmp, len, &buf, &buflen));
+ }
+ break;
+ }
+
+ default:
+ comment = "unknown RR type";
+ goto hexify;
+ }
+ return (buf - obuf);
+ formerr:
+ comment = "RR format error";
+ hexify: {
+ int n, m;
+ char *p;
+
+ len = SPRINTF((tmp, "\\#(\t\t; %s", comment));
+ T(addstr(tmp, len, &buf, &buflen));
+ while (rdata < edata) {
+ p = tmp;
+ p += SPRINTF((p, "\n\t"));
+ spaced = 0;
+ n = MIN(16, edata - rdata);
+ for (m = 0; m < n; m++)
+ p += SPRINTF((p, "%02x ", rdata[m]));
+ T(addstr(tmp, p - tmp, &buf, &buflen));
+ if (n < 16) {
+ T(addstr(")", 1, &buf, &buflen));
+ T(addtab(p - tmp + 1, 48, spaced, &buf, &buflen));
+ }
+ p = tmp;
+ p += SPRINTF((p, "; "));
+ for (m = 0; m < n; m++)
+ *p++ = (isascii(rdata[m]) && isprint(rdata[m]))
+ ? rdata[m]
+ : '.';
+ T(addstr(tmp, p - tmp, &buf, &buflen));
+ rdata += n;
+ }
+ return (buf - obuf);
+ }
+}
+
+/* Private. */
+
+/*
+ * size_t
+ * prune_origin(name, origin)
+ * Find out if the name is at or under the current origin.
+ * return:
+ * Number of characters in name before start of origin,
+ * or length of name if origin does not match.
+ * notes:
+ * This function should share code with samedomain().
+ */
+static size_t
+prune_origin(const char *name, const char *origin) {
+ const char *oname = name;
+
+ while (*name != '\0') {
+ if (origin != NULL && strcasecmp(name, origin) == 0)
+ return (name - oname - (name > oname));
+ while (*name != '\0') {
+ if (*name == '\\') {
+ name++;
+ /* XXX need to handle \nnn form. */
+ if (*name == '\0')
+ break;
+ } else if (*name == '.') {
+ name++;
+ break;
+ }
+ name++;
+ }
+ }
+ return (name - oname);
+}
+
+/*
+ * int
+ * charstr(rdata, edata, buf, buflen)
+ * Format a <character-string> into the presentation buffer.
+ * return:
+ * Number of rdata octets consumed
+ * 0 for protocol format error
+ * -1 for output buffer error
+ * side effects:
+ * buffer is advanced on success.
+ */
+static int
+charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
+ const u_char *odata = rdata;
+ size_t save_buflen = *buflen;
+ char *save_buf = *buf;
+
+ if (addstr("\"", 1, buf, buflen) < 0)
+ goto enospc;
+ if (rdata < edata) {
+ int n = *rdata;
+
+ if (rdata + 1 + n <= edata) {
+ rdata++;
+ while (n-- > 0) {
+ if (strchr("\n\"\\", *rdata) != NULL)
+ if (addstr("\\", 1, buf, buflen) < 0)
+ goto enospc;
+ if (addstr((const char *)rdata, 1,
+ buf, buflen) < 0)
+ goto enospc;
+ rdata++;
+ }
+ }
+ }
+ if (addstr("\"", 1, buf, buflen) < 0)
+ goto enospc;
+ return (rdata - odata);
+ enospc:
+ errno = ENOSPC;
+ *buf = save_buf;
+ *buflen = save_buflen;
+ return (-1);
+}
+
+static int
+addname(const u_char *msg, size_t msglen,
+ const u_char **pp, const char *origin,
+ char **buf, size_t *buflen)
+{
+ size_t newlen, save_buflen = *buflen;
+ char *save_buf = *buf;
+ int n;
+
+ n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen);
+ if (n < 0)
+ goto enospc; /* Guess. */
+ newlen = prune_origin(*buf, origin);
+ if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') &&
+ (newlen == 0 || (*buf)[newlen - 1] != '.')) {
+ /* No trailing dot. */
+ if (newlen + 2 > *buflen)
+ goto enospc; /* No room for ".\0". */
+ (*buf)[newlen++] = '.';
+ (*buf)[newlen] = '\0';
+ }
+ if (newlen == 0) {
+ /* Use "@" instead of name. */
+ if (newlen + 2 > *buflen)
+ goto enospc; /* No room for "@\0". */
+ (*buf)[newlen++] = '@';
+ (*buf)[newlen] = '\0';
+ }
+ *pp += n;
+ addlen(newlen, buf, buflen);
+ **buf = '\0';
+ return (newlen);
+ enospc:
+ errno = ENOSPC;
+ *buf = save_buf;
+ *buflen = save_buflen;
+ return (-1);
+}
+
+static void
+addlen(size_t len, char **buf, size_t *buflen) {
+ assert(len <= *buflen);
+ *buf += len;
+ *buflen -= len;
+}
+
+static int
+addstr(const char *src, size_t len, char **buf, size_t *buflen) {
+ if (len > *buflen) {
+ errno = ENOSPC;
+ return (-1);
+ }
+ memcpy(*buf, src, len);
+ addlen(len, buf, buflen);
+ **buf = '\0';
+ return (0);
+}
+
+static int
+addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
+ size_t save_buflen = *buflen;
+ char *save_buf = *buf;
+ int t;
+
+ if (spaced || len >= target - 1) {
+ T(addstr(" ", 2, buf, buflen));
+ spaced = 1;
+ } else {
+ for (t = (target - len - 1) / 8; t >= 0; t--)
+ if (addstr("\t", 1, buf, buflen) < 0) {
+ *buflen = save_buflen;
+ *buf = save_buf;
+ return (-1);
+ }
+ spaced = 0;
+ }
+ return (spaced);
+}
diff --git a/cpukit/libnetworking/libc/ns_ttl.c b/cpukit/libnetworking/libc/ns_ttl.c
new file mode 100644
index 0000000000..f88890bfa9
--- /dev/null
+++ b/cpukit/libnetworking/libc/ns_ttl.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/* Import. */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+/* Forward. */
+
+static int fmt1(int t, char s, char **buf, size_t *buflen);
+
+/* Macros. */
+
+#define T(x) if ((x) < 0) return (-1); else (void)NULL
+
+/* Public. */
+
+int
+ns_format_ttl(u_long src, char *dst, size_t dstlen) {
+ char *odst = dst;
+ int secs, mins, hours, days, weeks, x;
+ char *p;
+
+ secs = src % 60; src /= 60;
+ mins = src % 60; src /= 60;
+ hours = src % 24; src /= 24;
+ days = src % 7; src /= 7;
+ weeks = src; src = 0;
+
+ x = 0;
+ if (weeks) {
+ T(fmt1(weeks, 'W', &dst, &dstlen));
+ x++;
+ }
+ if (days) {
+ T(fmt1(days, 'D', &dst, &dstlen));
+ x++;
+ }
+ if (hours) {
+ T(fmt1(hours, 'H', &dst, &dstlen));
+ x++;
+ }
+ if (mins) {
+ T(fmt1(mins, 'M', &dst, &dstlen));
+ x++;
+ }
+ if (secs || !(weeks || days || hours || mins)) {
+ T(fmt1(secs, 'S', &dst, &dstlen));
+ x++;
+ }
+
+ if (x > 1) {
+ int ch;
+
+ for (p = odst; (ch = *p) != '\0'; p++)
+ if (isascii(ch) && isupper(ch))
+ *p = tolower(ch);
+ }
+
+ return (dst - odst);
+}
+
+int
+ns_parse_ttl(const char *src, u_long *dst) {
+ u_long ttl, tmp;
+ int ch, digits, dirty;
+
+ ttl = 0;
+ tmp = 0;
+ digits = 0;
+ dirty = 0;
+ while ((ch = *src++) != '\0') {
+ if (!isascii(ch) || !isprint(ch))
+ goto einval;
+ if (isdigit(ch)) {
+ tmp *= 10;
+ tmp += (ch - '0');
+ digits++;
+ continue;
+ }
+ if (digits == 0)
+ goto einval;
+ if (islower(ch))
+ ch = toupper(ch);
+ switch (ch) {
+ case 'W': tmp *= 7;
+ case 'D': tmp *= 24;
+ case 'H': tmp *= 60;
+ case 'M': tmp *= 60;
+ case 'S': break;
+ default: goto einval;
+ }
+ ttl += tmp;
+ tmp = 0;
+ digits = 0;
+ dirty = 1;
+ }
+ if (digits > 0) {
+ if (dirty)
+ goto einval;
+ else
+ ttl += tmp;
+ }
+ *dst = ttl;
+ return (0);
+
+ einval:
+ errno = EINVAL;
+ return (-1);
+}
+
+/* Private. */
+
+static int
+fmt1(int t, char s, char **buf, size_t *buflen) {
+ char tmp[50];
+ size_t len;
+
+ len = SPRINTF((tmp, "%d%c", t, s));
+ if (len + 1 > *buflen)
+ return (-1);
+ strcpy(*buf, tmp);
+ *buf += len;
+ *buflen -= len;
+ return (0);
+}
diff --git a/cpukit/libnetworking/libc/nsap_addr.c b/cpukit/libnetworking/libc/nsap_addr.c
new file mode 100644
index 0000000000..d8effa2e70
--- /dev/null
+++ b/cpukit/libnetworking/libc/nsap_addr.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 1996, 1998 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+
+static char
+xtob(
+ int c)
+{
+ return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
+}
+
+u_int
+inet_nsap_addr(
+ const char *ascii,
+ u_char *binary,
+ int maxlen)
+{
+ u_char c, nib;
+ u_int len = 0;
+
+ while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
+ if (c == '.' || c == '+' || c == '/')
+ continue;
+ if (!isascii(c))
+ return (0);
+ if (islower(c))
+ c = toupper(c);
+ if (isxdigit(c)) {
+ nib = xtob(c);
+ c = *ascii++;
+ if (c != '\0') {
+ c = toupper(c);
+ if (isxdigit(c)) {
+ *binary++ = (nib << 4) | xtob(c);
+ len++;
+ } else
+ return (0);
+ }
+ else
+ return (0);
+ }
+ else
+ return (0);
+ }
+ return (len);
+}
+
+char *
+inet_nsap_ntoa(
+ int binlen,
+ const u_char *binary,
+ char *ascii)
+{
+ register int nib;
+ int i;
+ static char tmpbuf[255*3];
+ char *start;
+
+ if (ascii)
+ start = ascii;
+ else {
+ ascii = tmpbuf;
+ start = tmpbuf;
+ }
+
+ if (binlen > 255)
+ binlen = 255;
+
+ for (i = 0; i < binlen; i++) {
+ nib = *binary >> 4;
+ *ascii++ = nib + (nib < 10 ? '0' : '7');
+ nib = *binary++ & 0x0f;
+ *ascii++ = nib + (nib < 10 ? '0' : '7');
+ if (((i % 2) == 0 && (i + 1) < binlen))
+ *ascii++ = '.';
+ }
+ *ascii = '\0';
+ return (start);
+}
diff --git a/cpukit/libnetworking/libc/rcmd.3 b/cpukit/libnetworking/libc/rcmd.3
new file mode 100644
index 0000000000..e25057fa4e
--- /dev/null
+++ b/cpukit/libnetworking/libc/rcmd.3
@@ -0,0 +1,204 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd February 15, 1996
+.Dt RCMD 3
+.Os BSD 4.2
+.Sh NAME
+.Nm rcmd ,
+.Nm rresvport ,
+.Nm iruserok ,
+.Nm ruserok
+.Nd routines for returning a stream to a remote command
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
+.Ft int
+.Fn rresvport "int *port"
+.Ft int
+.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser"
+.Ft int
+.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
+.Sh DESCRIPTION
+The
+.Fn rcmd
+function
+is used by the super-user to execute a command on
+a remote machine using an authentication scheme based
+on reserved port numbers.
+The
+.Fn rresvport
+function
+returns a descriptor to a socket
+with an address in the privileged port space.
+The
+.Fn ruserok
+function
+is used by servers
+to authenticate clients requesting service with
+.Fn rcmd .
+All three functions are present in the same file and are used
+by the
+.Xr rshd 8
+server (among others).
+.Pp
+The
+.Fn rcmd
+function
+looks up the host
+.Fa *ahost
+using
+.Xr gethostbyname 3 ,
+returning \-1 if the host does not exist.
+Otherwise
+.Fa *ahost
+is set to the standard name of the host
+and a connection is established to a server
+residing at the well-known Internet port
+.Fa inport .
+.Pp
+If the connection succeeds,
+a socket in the Internet domain of type
+.Dv SOCK_STREAM
+is returned to the caller, and given to the remote
+command as
+.Em stdin
+and
+.Em stdout .
+If
+.Fa fd2p
+is non-zero, then an auxiliary channel to a control
+process will be set up, and a descriptor for it will be placed
+in
+.Fa *fd2p .
+The control process will return diagnostic
+output from the command (unit 2) on this channel, and will also
+accept bytes on this channel as being
+.Tn UNIX
+signal numbers, to be
+forwarded to the process group of the command.
+If
+.Fa fd2p
+is 0, then the
+.Em stderr
+(unit 2 of the remote
+command) will be made the same as the
+.Em stdout
+and no
+provision is made for sending arbitrary signals to the remote process,
+although you may be able to get its attention by using out-of-band data.
+.Pp
+The protocol is described in detail in
+.Xr rshd 8 .
+.Pp
+The
+.Fn rresvport
+function is used to obtain a socket with a privileged
+address bound to it. This socket is suitable for use
+by
+.Fn rcmd
+and several other functions. Privileged Internet ports are those
+in the range 0 to 1023. Only the super-user
+is allowed to bind an address of this sort to a socket.
+.Pp
+The
+.Fn iruserok
+and
+.Fn ruserok
+functions take a remote host's IP address or name, as returned by the
+.Xr gethostbyname 3
+routines, two user names and a flag indicating whether the local user's
+name is that of the super-user.
+Then, if the user is
+.Em NOT
+the super-user, it checks the
+.Pa /etc/hosts.equiv
+file.
+If that lookup is not done, or is unsuccessful, the
+.Pa .rhosts
+in the local user's home directory is checked to see if the request for
+service is allowed.
+.Pp
+If this file does not exist, is not a regular file, is owned by anyone
+other than the user or the super-user, or is writable by anyone other
+than the owner, the check automatically fails.
+Zero is returned if the machine name is listed in the
+.Dq Pa hosts.equiv
+file, or the host and remote user name are found in the
+.Dq Pa .rhosts
+file; otherwise
+.Fn iruserok
+and
+.Fn ruserok
+return \-1.
+If the local domain (as obtained from
+.Xr gethostname 3 )
+is the same as the remote domain, only the machine name need be specified.
+.Pp
+The
+.Fn iruserok
+function is strongly preferred for security reasons.
+It requires trusting the local DNS at most, while the
+.Fn ruserok
+function requires trusting the entire DNS, which can be spoofed.
+.Sh DIAGNOSTICS
+The
+.Fn rcmd
+function
+returns a valid socket descriptor on success.
+It returns \-1 on error and prints a diagnostic message on the standard error.
+.Pp
+The
+.Fn rresvport
+function
+returns a valid, bound socket descriptor on success.
+It returns \-1 on error with the global value
+.Va errno
+set according to the reason for failure.
+The error code
+.Dv EAGAIN
+is overloaded to mean ``All network ports in use.''
+.Sh SEE ALSO
+.Xr rlogin 1 ,
+.Xr rsh 1 ,
+.Xr intro 2 ,
+.Xr rexec 3 ,
+.Xr rexecd 8 ,
+.Xr rlogind 8 ,
+.Xr rshd 8
+.Sh HISTORY
+These
+functions appeared in
+.Bx 4.2 .
diff --git a/cpukit/libnetworking/libc/rcmd.c b/cpukit/libnetworking/libc/rcmd.c
new file mode 100644
index 0000000000..d0fb281e1f
--- /dev/null
+++ b/cpukit/libnetworking/libc/rcmd.c
@@ -0,0 +1,547 @@
+/*
+ * Copyright (c) 1983, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <signal.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/select.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#ifndef __rtems__
+extern int innetgr( const char *, const char *, const char *, const char * );
+#endif
+
+#define max(a, b) ((a > b) ? a : b)
+
+#ifdef __rtems__
+int rresvport(int *alport);
+#define bzero(a,s) memset((a),0,(s))
+#define bcmp memcmp
+#define bcopy(s,d,i) memcpy(d,s,i)
+#else /* __rtems__ */
+
+int __ivaliduser(FILE *, u_int32_t, const char *, const char *);
+static int __icheckhost(const struct sockaddr *, socklen_t, const char *);
+
+#endif
+
+int
+rcmd(
+ char **ahost,
+ u_short rport,
+ const char *locuser,
+ const char *remuser,
+ const char *cmd,
+ int *fd2p )
+{
+ struct hostent *hp;
+ struct sockaddr_in sin, from;
+ fd_set reads;
+#ifndef __rtems__
+ long oldmask;
+#endif
+ pid_t pid;
+ int s, lport, timo;
+ char c;
+
+ pid = getpid();
+ hp = gethostbyname(*ahost);
+ if (hp == NULL) {
+ herror(*ahost);
+ return (-1);
+ }
+ *ahost = hp->h_name;
+#ifndef __rtems__
+ oldmask = sigblock(sigmask(SIGURG));
+#endif
+ for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
+ s = rresvport(&lport);
+ if (s < 0) {
+ if (errno == EAGAIN)
+ (void)fprintf(stderr,
+ "rcmd: socket: All ports in use\n");
+ else
+ (void)fprintf(stderr, "rcmd: socket: %s\n",
+ strerror(errno));
+#ifndef __rtems__
+ sigsetmask(oldmask);
+#endif
+ return (-1);
+ }
+ fcntl(s, F_SETOWN, pid);
+ bzero(&sin, sizeof sin);
+ sin.sin_len = sizeof(struct sockaddr_in);
+ sin.sin_family = hp->h_addrtype;
+ sin.sin_port = rport;
+ bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr));
+ if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
+ break;
+ (void)close(s);
+ if (errno == EADDRINUSE) {
+ lport--;
+ continue;
+ }
+ if (errno == ECONNREFUSED && timo <= 16) {
+ (void)sleep(timo);
+ timo *= 2;
+ continue;
+ }
+ if (hp->h_addr_list[1] != NULL) {
+ int oerrno = errno;
+
+ (void)fprintf(stderr, "connect to address %s: ",
+ inet_ntoa(sin.sin_addr));
+ errno = oerrno;
+ perror(0);
+ hp->h_addr_list++;
+ bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr));
+ (void)fprintf(stderr, "Trying %s...\n",
+ inet_ntoa(sin.sin_addr));
+ continue;
+ }
+ (void)fprintf(stderr, "%s: %s\n", hp->h_name, strerror(errno));
+#ifndef __rtems__
+ sigsetmask(oldmask);
+#endif
+ return (-1);
+ }
+ lport--;
+ if (fd2p == 0) {
+ write(s, "", 1);
+ lport = 0;
+ } else {
+ char num[8];
+ int s2 = rresvport(&lport), s3;
+ socklen_t len = sizeof(from);
+ int nfds;
+
+ if (s2 < 0)
+ goto bad;
+ listen(s2, 1);
+ (void)snprintf(num, sizeof(num), "%d", lport);
+ if (write(s, num, strlen(num)+1) != strlen(num)+1) {
+ (void)fprintf(stderr,
+ "rcmd: write (setting up stderr): %s\n",
+ strerror(errno));
+ (void)close(s2);
+ goto bad;
+ }
+ nfds = max(s, s2)+1;
+ if(nfds > FD_SETSIZE) {
+ fprintf(stderr, "rcmd: too many files\n");
+ (void)close(s2);
+ goto bad;
+ }
+again:
+ FD_ZERO(&reads);
+ FD_SET(s, &reads);
+ FD_SET(s2, &reads);
+ errno = 0;
+ if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){
+ if (errno != 0)
+ (void)fprintf(stderr,
+ "rcmd: select (setting up stderr): %s\n",
+ strerror(errno));
+ else
+ (void)fprintf(stderr,
+ "select: protocol failure in circuit setup\n");
+ (void)close(s2);
+ goto bad;
+ }
+ s3 = accept(s2, (struct sockaddr *)&from, &len);
+ /*
+ * XXX careful for ftp bounce attacks. If discovered, shut them
+ * down and check for the real auxiliary channel to connect.
+ */
+ if (from.sin_family == AF_INET && from.sin_port == htons(20)) {
+ close(s3);
+ goto again;
+ }
+ (void)close(s2);
+ if (s3 < 0) {
+ (void)fprintf(stderr,
+ "rcmd: accept: %s\n", strerror(errno));
+ lport = 0;
+ goto bad;
+ }
+ *fd2p = s3;
+ from.sin_port = ntohs((u_short)from.sin_port);
+ if (from.sin_family != AF_INET ||
+ from.sin_port >= IPPORT_RESERVED ||
+ from.sin_port < IPPORT_RESERVED / 2) {
+ (void)fprintf(stderr,
+ "socket: protocol failure in circuit setup.\n");
+ goto bad2;
+ }
+ }
+ (void)write(s, locuser, strlen(locuser)+1);
+ (void)write(s, remuser, strlen(remuser)+1);
+ (void)write(s, cmd, strlen(cmd)+1);
+ if (read(s, &c, 1) != 1) {
+ (void)fprintf(stderr,
+ "rcmd: %s: %s\n", *ahost, strerror(errno));
+ goto bad2;
+ }
+ if (c != 0) {
+ while (read(s, &c, 1) == 1) {
+ (void)write(STDERR_FILENO, &c, 1);
+ if (c == '\n')
+ break;
+ }
+ goto bad2;
+ }
+#ifndef __rtems__
+ sigsetmask(oldmask);
+#endif
+ return (s);
+bad2:
+ if (lport)
+ (void)close(*fd2p);
+bad:
+ (void)close(s);
+#ifndef __rtems__
+ sigsetmask(oldmask);
+#endif
+ return (-1);
+}
+
+int
+rresvport(int *alport )
+{
+ struct sockaddr_in sin;
+ int s;
+
+ bzero(&sin, sizeof sin);
+ sin.sin_len = sizeof(struct sockaddr_in);
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = INADDR_ANY;
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return (-1);
+#if 0 /* compat_exact_traditional_rresvport_semantics */
+ sin.sin_port = htons((u_short)*alport);
+ if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
+ return (s);
+ if (errno != EADDRINUSE) {
+ (void)close(s);
+ return (-1);
+ }
+#endif
+ sin.sin_port = 0;
+ if (bindresvport(s, &sin) == -1) {
+ (void)close(s);
+ return (-1);
+ }
+ *alport = (int)ntohs(sin.sin_port);
+ return (s);
+}
+
+#ifndef __rtems__
+int __check_rhosts_file = 1;
+char *__rcmd_errstr;
+
+int
+ruserok(rhost, superuser, ruser, luser)
+ const char *rhost, *ruser, *luser;
+ int superuser;
+{
+ struct hostent *hp;
+ u_long addr;
+ char **ap;
+
+ if ((hp = gethostbyname(rhost)) == NULL)
+ return (-1);
+ for (ap = hp->h_addr_list; *ap; ++ap) {
+ bcopy(*ap, &addr, sizeof(addr));
+ if (iruserok(addr, superuser, ruser, luser) == 0)
+ return (0);
+ }
+ return (-1);
+}
+
+/*
+ * New .rhosts strategy: We are passed an ip address. We spin through
+ * hosts.equiv and .rhosts looking for a match. When the .rhosts only
+ * has ip addresses, we don't have to trust a nameserver. When it
+ * contains hostnames, we spin through the list of addresses the nameserver
+ * gives us and look for a match.
+ *
+ * Returns 0 if ok, -1 if not ok.
+ */
+int
+iruserok(raddr, superuser, ruser, luser)
+ u_long raddr;
+ int superuser;
+ const char *ruser, *luser;
+{
+ register char *cp;
+ struct stat sbuf;
+ struct passwd *pwd;
+ FILE *hostf;
+ uid_t uid;
+ int first;
+ char pbuf[MAXPATHLEN];
+
+ first = 1;
+ hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r");
+again:
+ if (hostf) {
+ if (__ivaliduser(hostf, raddr, luser, ruser) == 0) {
+ (void)fclose(hostf);
+ return (0);
+ }
+ (void)fclose(hostf);
+ }
+ if (first == 1 && (__check_rhosts_file || superuser)) {
+ first = 0;
+ if ((pwd = getpwnam(luser)) == NULL)
+ return (-1);
+ (void)strcpy(pbuf, pwd->pw_dir);
+ (void)strcat(pbuf, "/.rhosts");
+
+ /*
+ * Change effective uid while opening .rhosts. If root and
+ * reading an NFS mounted file system, can't read files that
+ * are protected read/write owner only.
+ */
+ uid = geteuid();
+ (void)seteuid(pwd->pw_uid);
+ hostf = fopen(pbuf, "r");
+ (void)seteuid(uid);
+
+ if (hostf == NULL)
+ return (-1);
+ /*
+ * If not a regular file, or is owned by someone other than
+ * user or root or if writeable by anyone but the owner, quit.
+ */
+ cp = NULL;
+ if (lstat(pbuf, &sbuf) < 0)
+ cp = ".rhosts lstat failed";
+ else if (!S_ISREG(sbuf.st_mode))
+ cp = ".rhosts not regular file";
+ else if (fstat(fileno(hostf), &sbuf) < 0)
+ cp = ".rhosts fstat failed";
+ else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid)
+ cp = "bad .rhosts owner";
+ else if (sbuf.st_mode & (S_IWGRP|S_IWOTH))
+ cp = ".rhosts writeable by other than owner";
+ /* If there were any problems, quit. */
+ if (cp) {
+ __rcmd_errstr = cp;
+ (void)fclose(hostf);
+ return (-1);
+ }
+ goto again;
+ }
+ return (-1);
+}
+
+/*
+ * XXX
+ * Don't make static, used by lpd(8).
+ *
+ * Returns 0 if ok, -1 if not ok.
+ */
+int
+__ivaliduser(hostf, raddr, luser, ruser)
+ FILE *hostf;
+ u_long raddr;
+ const char *luser, *ruser;
+{
+ register char *user, *p;
+ int ch;
+ char buf[MAXHOSTNAMELEN + 128]; /* host + login */
+ char hname[MAXHOSTNAMELEN];
+ struct hostent *hp;
+ /* Presumed guilty until proven innocent. */
+ int userok = 0, hostok = 0;
+#ifdef YP
+ char *ypdomain;
+
+ if (yp_get_default_domain(&ypdomain))
+ ypdomain = NULL;
+#else
+#define ypdomain NULL
+#endif
+ /* We need to get the damn hostname back for netgroup matching. */
+ if ((hp = gethostbyaddr((char *)&raddr, sizeof(u_long),
+ AF_INET)) == NULL)
+ return (-1);
+ strncpy(hname, hp->h_name, sizeof(hname));
+ hname[sizeof(hname) - 1] = '\0';
+
+ while (fgets(buf, sizeof(buf), hostf)) {
+ p = buf;
+ /* Skip lines that are too long. */
+ if (strchr(p, '\n') == NULL) {
+ while ((ch = getc(hostf)) != '\n' && ch != EOF);
+ continue;
+ }
+ if (*p == '\n' || *p == '#') {
+ /* comment... */
+ continue;
+ }
+ while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') {
+ *p = isupper(*p) ? tolower(*p) : *p;
+ p++;
+ }
+ if (*p == ' ' || *p == '\t') {
+ *p++ = '\0';
+ while (*p == ' ' || *p == '\t')
+ p++;
+ user = p;
+ while (*p != '\n' && *p != ' ' &&
+ *p != '\t' && *p != '\0')
+ p++;
+ } else
+ user = p;
+ *p = '\0';
+ /*
+ * Do +/- and +@/-@ checking. This looks really nasty,
+ * but it matches SunOS's behavior so far as I can tell.
+ */
+ switch(buf[0]) {
+ case '+':
+ if (!buf[1]) { /* '+' matches all hosts */
+ hostok = 1;
+ break;
+ }
+ if (buf[1] == '@') /* match a host by netgroup */
+ hostok = innetgr((char *)&buf[2],
+ (char *)&hname, NULL, ypdomain);
+ else /* match a host by addr */
+ hostok = __icheckhost(raddr,(char *)&buf[1]);
+ break;
+ case '-': /* reject '-' hosts and all their users */
+ if (buf[1] == '@') {
+ if (innetgr((char *)&buf[2],
+ (char *)&hname, NULL, ypdomain))
+ return(-1);
+ } else {
+ if (__icheckhost(raddr,(char *)&buf[1]))
+ return(-1);
+ }
+ break;
+ default: /* if no '+' or '-', do a simple match */
+ hostok = __icheckhost(raddr, buf);
+ break;
+ }
+ switch(*user) {
+ case '+':
+ if (!*(user+1)) { /* '+' matches all users */
+ userok = 1;
+ break;
+ }
+ if (*(user+1) == '@') /* match a user by netgroup */
+ userok = innetgr(user+2, NULL, ruser, ypdomain);
+ else /* match a user by direct specification */
+ userok = !(strcmp(ruser, user+1));
+ break;
+ case '-': /* if we matched a hostname, */
+ if (hostok) { /* check for user field rejections */
+ if (!*(user+1))
+ return(-1);
+ if (*(user+1) == '@') {
+ if (innetgr(user+2, NULL,
+ ruser, ypdomain))
+ return(-1);
+ } else {
+ if (!strcmp(ruser, user+1))
+ return(-1);
+ }
+ }
+ break;
+ default: /* no rejections: try to match the user */
+ if (hostok)
+ userok = !(strcmp(ruser,*user ? user : luser));
+ break;
+ }
+ if (hostok && userok)
+ return(0);
+ }
+ return (-1);
+}
+
+/*
+ * Returns "true" if match, 0 if no match.
+ */
+static int
+__icheckhost(raddr, lhost)
+ u_long raddr;
+ register char *lhost;
+{
+ register struct hostent *hp;
+ register u_long laddr;
+ register char **pp;
+
+ /* Try for raw ip address first. */
+ if (isdigit(*lhost) && (long)(laddr = inet_addr(lhost)) != -1)
+ return (raddr == laddr);
+
+ /* Better be a hostname. */
+ if ((hp = gethostbyname(lhost)) == NULL)
+ return (0);
+
+ /* Spin through ip addresses. */
+ for (pp = hp->h_addr_list; *pp; ++pp)
+ if (!bcmp(&raddr, *pp, sizeof(u_long)))
+ return (1);
+
+ /* No match. */
+ return (0);
+}
+#endif
diff --git a/cpukit/libnetworking/libc/recv.c b/cpukit/libnetworking/libc/recv.c
new file mode 100644
index 0000000000..d36bfadcb4
--- /dev/null
+++ b/cpukit/libnetworking/libc/recv.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stddef.h>
+
+ssize_t
+recv(
+ int s,
+ void *buf,
+ size_t len,
+ int flags )
+{
+ return (recvfrom(s, buf, len, flags, NULL, 0));
+}
diff --git a/cpukit/libnetworking/libc/res_comp.c b/cpukit/libnetworking/libc/res_comp.c
new file mode 100644
index 0000000000..7240e56081
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_comp.c
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BIND_4_COMPAT
+
+/*
+ * Expand compressed domain name 'comp_dn' to full domain name.
+ * 'msg' is a pointer to the begining of the message,
+ * 'eomorig' points to the first location after the message,
+ * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
+ * Return size of compressed name or -1 if there was an error.
+ */
+int
+dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
+ char *dst, int dstsiz)
+{
+ int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
+
+ if (n > 0 && dst[0] == '.')
+ dst[0] = '\0';
+ return (n);
+}
+
+/*
+ * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
+ * Return the size of the compressed name or -1.
+ * 'length' is the size of the array pointed to by 'comp_dn'.
+ */
+int
+dn_comp(const char *src, u_char *dst, int dstsiz,
+ u_char **dnptrs, u_char **lastdnptr)
+{
+ return (ns_name_compress(src, dst, (size_t)dstsiz,
+ (const u_char **)dnptrs,
+ (const u_char **)lastdnptr));
+}
+
+/*
+ * Skip over a compressed domain name. Return the size or -1.
+ */
+int
+dn_skipname(const u_char *ptr, const u_char *eom) {
+ const u_char *saveptr = ptr;
+
+ if (ns_name_skip(&ptr, eom) == -1)
+ return (-1);
+ return (ptr - saveptr);
+}
+
+/*
+ * Verify that a domain name uses an acceptable character set.
+ */
+
+/*
+ * Note the conspicuous absence of ctype macros in these definitions. On
+ * non-ASCII hosts, we can't depend on string literals or ctype macros to
+ * tell us anything about network-format data. The rest of the BIND system
+ * is not careful about this, but for some reason, we're doing it right here.
+ */
+#define PERIOD 0x2e
+#define hyphenchar(c) ((c) == 0x2d)
+#define bslashchar(c) ((c) == 0x5c)
+#define periodchar(c) ((c) == PERIOD)
+#define asterchar(c) ((c) == 0x2a)
+#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
+ || ((c) >= 0x61 && (c) <= 0x7a))
+#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+
+#define borderchar(c) (alphachar(c) || digitchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
+
+int
+res_hnok(const char *dn)
+{
+ int ppch = '\0', pch = PERIOD, ch = *dn++;
+
+ while (ch != '\0') {
+ int nch = *dn++;
+
+ if (periodchar(ch)) {
+ (void)NULL;
+ } else if (periodchar(pch)) {
+ if (!borderchar(ch))
+ return (0);
+ } else if (periodchar(nch) || nch == '\0') {
+ if (!borderchar(ch))
+ return (0);
+ } else {
+ if (!middlechar(ch))
+ return (0);
+ }
+ ppch = pch, pch = ch, ch = nch;
+ }
+ return (1);
+}
+
+/*
+ * hostname-like (A, MX, WKS) owners can have "*" as their first label
+ * but must otherwise be as a host name.
+ */
+int
+res_ownok(const char *dn)
+{
+ if (asterchar(dn[0])) {
+ if (periodchar(dn[1]))
+ return (res_hnok(dn+2));
+ if (dn[1] == '\0')
+ return (1);
+ }
+ return (res_hnok(dn));
+}
+
+/*
+ * SOA RNAMEs and RP RNAMEs can have any printable character in their first
+ * label, but the rest of the name has to look like a host name.
+ */
+int
+res_mailok(const char *dn)
+{
+ int ch, escaped = 0;
+
+ /* "." is a valid missing representation */
+ if (*dn == '\0')
+ return (1);
+
+ /* otherwise <label>.<hostname> */
+ while ((ch = *dn++) != '\0') {
+ if (!domainchar(ch))
+ return (0);
+ if (!escaped && periodchar(ch))
+ break;
+ if (escaped)
+ escaped = 0;
+ else if (bslashchar(ch))
+ escaped = 1;
+ }
+ if (periodchar(ch))
+ return (res_hnok(dn));
+ return (0);
+}
+
+/*
+ * This function is quite liberal, since RFC 1034's character sets are only
+ * recommendations.
+ */
+int
+res_dnok(const char *dn)
+{
+ int ch;
+
+ while ((ch = *dn++) != '\0')
+ if (!domainchar(ch))
+ return (0);
+ return (1);
+}
+
+#ifdef BIND_4_COMPAT
+/*
+ * This module must export the following externally-visible symbols:
+ * ___putlong
+ * ___putshort
+ * __getlong
+ * __getshort
+ * Note that one _ comes from C and the others come from us.
+ */
+void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
+void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
+u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
+u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
+#endif /*BIND_4_COMPAT*/
diff --git a/cpukit/libnetworking/libc/res_config.h b/cpukit/libnetworking/libc/res_config.h
new file mode 100644
index 0000000000..fbd1d694f7
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_config.h
@@ -0,0 +1,20 @@
+/*
+ * $Id$
+ */
+
+#define DEBUG 1 /* enable debugging code (needed for dig) */
+#define RESOLVSORT /* allow sorting of addresses in gethostbyname */
+#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/
+#undef USELOOPBACK /* res_init() bind to localhost */
+#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */
+#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */
+#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */
+#define BIND_UPDATE 1 /* update support */
+
+#if defined(__rtems__)
+u_int16_t _getshort(const u_char *src);
+u_int32_t _getlong(const u_char *src);
+int gethostname (char *name, size_t namelen);
+int sethostname (char *name, size_t namelen);
+int issetugid (void);
+#endif
diff --git a/cpukit/libnetworking/libc/res_data.c b/cpukit/libnetworking/libc/res_data.c
new file mode 100644
index 0000000000..241d049c7a
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_data.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 1995,1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "res_config.h"
+
+const char *_res_opcodes[] = {
+ "QUERY",
+ "IQUERY",
+ "CQUERYM",
+ "CQUERYU", /* experimental */
+ "NOTIFY", /* experimental */
+ "UPDATE",
+ "6",
+ "7",
+ "8",
+ "9",
+ "10",
+ "11",
+ "12",
+ "13",
+ "ZONEINIT",
+ "ZONEREF",
+};
+
+const char *_res_resultcodes[] = {
+ "NOERROR",
+ "FORMERR",
+ "SERVFAIL",
+ "NXDOMAIN",
+ "NOTIMP",
+ "REFUSED",
+ "YXDOMAIN",
+ "YXRRSET",
+ "NXRRSET",
+ "NOTAUTH",
+ "ZONEERR",
+ "11",
+ "12",
+ "13",
+ "14",
+ "NOCHANGE",
+};
+
+#ifdef BIND_UPDATE
+const char *_res_sectioncodes[] = {
+ "ZONE",
+ "PREREQUISITES",
+ "UPDATE",
+ "ADDITIONAL",
+};
+#endif
diff --git a/cpukit/libnetworking/libc/res_debug.c b/cpukit/libnetworking/libc/res_debug.c
new file mode 100644
index 0000000000..e6e7cbfa04
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_debug.c
@@ -0,0 +1,971 @@
+/*
+ * Copyright (c) 1985
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <math.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <time.h>
+
+#define SPRINTF(x) sprintf x
+
+extern const char *_res_opcodes[];
+extern const char *_res_resultcodes[];
+extern const char *_res_sectioncodes[];
+
+/*
+ * Print the current options.
+ */
+void
+fp_resstat(struct __res_state *statp, FILE *file) {
+ u_long mask;
+
+ fprintf(file, ";; res options:");
+ if (!statp)
+ statp = &_res;
+ for (mask = 1; mask != 0; mask <<= 1)
+ if (statp->options & mask)
+ fprintf(file, " %s", p_option(mask));
+ putc('\n', file);
+}
+
+static void
+do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
+ int n, sflag, rrnum;
+ char buf[2048]; /* XXX need to malloc */
+ ns_opcode opcode;
+ ns_rr rr;
+
+ /*
+ * Print answer records.
+ */
+ sflag = (_res.pfcode & pflag);
+ if (_res.pfcode && !sflag)
+ return;
+
+ opcode = ns_msg_getflag(*handle, ns_f_opcode);
+ rrnum = 0;
+ for (;;) {
+ if (ns_parserr(handle, section, rrnum, &rr)) {
+ if (errno != ENODEV)
+ fprintf(file, ";; ns_parserr: %s\n",
+ strerror(errno));
+ else if (rrnum > 0 && sflag != 0 &&
+ (_res.pfcode & RES_PRF_HEAD1))
+ putc('\n', file);
+ return;
+ }
+ if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
+ fprintf(file, ";; %s SECTION:\n",
+ p_section(section, opcode));
+ if (section == ns_s_qd)
+ fprintf(file, ";;\t%s, type = %s, class = %s\n",
+ ns_rr_name(rr),
+ p_type(ns_rr_type(rr)),
+ p_class(ns_rr_class(rr)));
+ else {
+ n = ns_sprintrr(handle, &rr, NULL, NULL,
+ buf, sizeof buf);
+ if (n < 0) {
+ fprintf(file, ";; ns_sprintrr: %s\n",
+ strerror(errno));
+ return;
+ }
+ fputs(buf, file);
+ fputc('\n', file);
+ }
+ rrnum++;
+ }
+}
+
+void
+p_query(const u_char *msg) {
+ fp_query(msg, stdout);
+}
+
+void
+fp_query(const u_char *msg, FILE *file) {
+ fp_nquery(msg, PACKETSZ, file);
+}
+
+/*
+ * Print the contents of a query.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+fp_nquery(const u_char *msg, int len, FILE *file) {
+ ns_msg handle;
+ int qdcount, ancount, nscount, arcount;
+ u_int opcode, rcode, id;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+
+ if (ns_initparse(msg, len, &handle) < 0) {
+ fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
+ return;
+ }
+ opcode = ns_msg_getflag(handle, ns_f_opcode);
+ rcode = ns_msg_getflag(handle, ns_f_rcode);
+ id = ns_msg_id(handle);
+ qdcount = ns_msg_count(handle, ns_s_qd);
+ ancount = ns_msg_count(handle, ns_s_an);
+ nscount = ns_msg_count(handle, ns_s_ns);
+ arcount = ns_msg_count(handle, ns_s_ar);
+
+ /*
+ * Print header fields.
+ */
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
+ fprintf(file,
+ ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
+ _res_opcodes[opcode], _res_resultcodes[rcode], id);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
+ putc(';', file);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
+ fprintf(file, "; flags:");
+ if (ns_msg_getflag(handle, ns_f_qr))
+ fprintf(file, " qr");
+ if (ns_msg_getflag(handle, ns_f_aa))
+ fprintf(file, " aa");
+ if (ns_msg_getflag(handle, ns_f_tc))
+ fprintf(file, " tc");
+ if (ns_msg_getflag(handle, ns_f_rd))
+ fprintf(file, " rd");
+ if (ns_msg_getflag(handle, ns_f_ra))
+ fprintf(file, " ra");
+ if (ns_msg_getflag(handle, ns_f_z))
+ fprintf(file, " ??");
+ if (ns_msg_getflag(handle, ns_f_ad))
+ fprintf(file, " ad");
+ if (ns_msg_getflag(handle, ns_f_cd))
+ fprintf(file, " cd");
+ }
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
+ fprintf(file, "; %s: %d",
+ p_section(ns_s_qd, opcode), qdcount);
+ fprintf(file, ", %s: %d",
+ p_section(ns_s_an, opcode), ancount);
+ fprintf(file, ", %s: %d",
+ p_section(ns_s_ns, opcode), nscount);
+ fprintf(file, ", %s: %d",
+ p_section(ns_s_ar, opcode), arcount);
+ }
+ if ((!_res.pfcode) || (_res.pfcode &
+ (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
+ putc('\n',file);
+ }
+ /*
+ * Print the various sections.
+ */
+ do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
+ do_section(&handle, ns_s_an, RES_PRF_ANS, file);
+ do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
+ do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
+ if (qdcount == 0 && ancount == 0 &&
+ nscount == 0 && arcount == 0)
+ putc('\n', file);
+}
+
+const u_char *
+p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
+ char name[MAXDNAME];
+ int n;
+
+ if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
+ return (NULL);
+ if (name[0] == '\0')
+ putc('.', file);
+ else
+ fputs(name, file);
+ return (cp + n);
+}
+
+const u_char *
+p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
+ return (p_cdnname(cp, msg, PACKETSZ, file));
+}
+
+/* Return a fully-qualified domain name from a compressed name (with
+ length supplied). */
+
+const u_char *
+p_fqnname(
+ const u_char *cp,
+ const u_char *msg,
+ int msglen,
+ char *name,
+ int namelen)
+{
+ int n, newlen;
+
+ if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
+ return (NULL);
+ newlen = strlen(name);
+ if (newlen == 0 || name[newlen - 1] != '.') {
+ if (newlen + 1 >= namelen) /* Lack space for final dot */
+ return (NULL);
+ else
+ strcpy(name + newlen, ".");
+ }
+ return (cp + n);
+}
+
+/* XXX: the rest of these functions need to become length-limited, too. */
+
+const u_char *
+p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
+ char name[MAXDNAME];
+ const u_char *n;
+
+ n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
+ if (n == NULL)
+ return (NULL);
+ fputs(name, file);
+ return (n);
+}
+
+/*
+ * Names of RR classes and qclasses. Classes and qclasses are the same, except
+ * that C_ANY is a qclass but not a class. (You can ask for records of class
+ * C_ANY, but you can't have any records of that class in the database.)
+ */
+const struct res_sym __p_class_syms[] = {
+ {C_IN, "IN", NULL},
+ {C_CHAOS, "CHAOS", NULL},
+ {C_HS, "HS", NULL},
+ {C_HS, "HESIOD", NULL},
+ {C_ANY, "ANY", NULL},
+ {C_NONE, "NONE", NULL},
+ {C_IN, (char *)0, NULL}
+};
+
+/*
+ * Names of message sections.
+ */
+const struct res_sym __p_default_section_syms[] = {
+ {ns_s_qd, "QUERY", NULL},
+ {ns_s_an, "ANSWER", NULL},
+ {ns_s_ns, "AUTHORITY", NULL},
+ {ns_s_ar, "ADDITIONAL", NULL},
+ {0, (char *)0, NULL}
+};
+
+const struct res_sym __p_update_section_syms[] = {
+ {S_ZONE, "ZONE", NULL},
+ {S_PREREQ, "PREREQUISITE", NULL},
+ {S_UPDATE, "UPDATE", NULL},
+ {S_ADDT, "ADDITIONAL", NULL},
+ {0, (char *)0, NULL}
+};
+
+/*
+ * Names of RR types and qtypes. Types and qtypes are the same, except
+ * that T_ANY is a qtype but not a type. (You can ask for records of type
+ * T_ANY, but you can't have any records of that type in the database.)
+ */
+const struct res_sym __p_type_syms[] = {
+ {T_A, "A", "address"},
+ {T_NS, "NS", "name server"},
+ {T_MD, "MD", "mail destination (deprecated)"},
+ {T_MF, "MF", "mail forwarder (deprecated)"},
+ {T_CNAME, "CNAME", "canonical name"},
+ {T_SOA, "SOA", "start of authority"},
+ {T_MB, "MB", "mailbox"},
+ {T_MG, "MG", "mail group member"},
+ {T_MR, "MR", "mail rename"},
+ {T_NULL, "NULL", "null"},
+ {T_WKS, "WKS", "well-known service (deprecated)"},
+ {T_PTR, "PTR", "domain name pointer"},
+ {T_HINFO, "HINFO", "host information"},
+ {T_MINFO, "MINFO", "mailbox information"},
+ {T_MX, "MX", "mail exchanger"},
+ {T_TXT, "TXT", "text"},
+ {T_RP, "RP", "responsible person"},
+ {T_AFSDB, "AFSDB", "DCE or AFS server"},
+ {T_X25, "X25", "X25 address"},
+ {T_ISDN, "ISDN", "ISDN address"},
+ {T_RT, "RT", "router"},
+ {T_NSAP, "NSAP", "nsap address"},
+ {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
+ {T_SIG, "SIG", "signature"},
+ {T_KEY, "KEY", "key"},
+ {T_PX, "PX", "mapping information"},
+ {T_GPOS, "GPOS", "geographical position (withdrawn)"},
+ {T_AAAA, "AAAA", "IPv6 address"},
+ {T_LOC, "LOC", "location"},
+ {T_NXT, "NXT", "next valid name (unimplemented)"},
+ {T_EID, "EID", "endpoint identifier (unimplemented)"},
+ {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
+ {T_SRV, "SRV", "server selection"},
+ {T_ATMA, "ATMA", "ATM address (unimplemented)"},
+ {T_IXFR, "IXFR", "incremental zone transfer"},
+ {T_AXFR, "AXFR", "zone transfer"},
+ {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
+ {T_MAILA, "MAILA", "mail agent (deprecated)"},
+ {T_NAPTR, "NAPTR", "URN Naming Authority"},
+ {T_ANY, "ANY", "\"any\""},
+ {0, NULL, NULL}
+};
+
+int
+sym_ston(const struct res_sym *syms, const char *name, int *success) {
+ for ((void)NULL; syms->name != 0; syms++) {
+ if (strcasecmp (name, syms->name) == 0) {
+ if (success)
+ *success = 1;
+ return (syms->number);
+ }
+ }
+ if (success)
+ *success = 0;
+ return (syms->number); /* The default value. */
+}
+
+const char *
+sym_ntos(const struct res_sym *syms, int number, int *success) {
+ static char unname[20];
+
+ for ((void)NULL; syms->name != 0; syms++) {
+ if (number == syms->number) {
+ if (success)
+ *success = 1;
+ return (syms->name);
+ }
+ }
+
+ sprintf(unname, "%d", number);
+ if (success)
+ *success = 0;
+ return (unname);
+}
+
+const char *
+sym_ntop(const struct res_sym *syms, int number, int *success) {
+ static char unname[20];
+
+ for ((void)NULL; syms->name != 0; syms++) {
+ if (number == syms->number) {
+ if (success)
+ *success = 1;
+ return (syms->humanname);
+ }
+ }
+ sprintf(unname, "%d", number);
+ if (success)
+ *success = 0;
+ return (unname);
+}
+
+/*
+ * Return a string for the type.
+ */
+const char *
+p_type(int type) {
+ return (sym_ntos(__p_type_syms, type, (int *)0));
+}
+
+/*
+ * Return a string for the type.
+ */
+const char *
+p_section(int section, int opcode) {
+ const struct res_sym *symbols;
+
+ switch (opcode) {
+ case ns_o_update:
+ symbols = __p_update_section_syms;
+ break;
+ default:
+ symbols = __p_default_section_syms;
+ break;
+ }
+ return (sym_ntos(symbols, section, (int *)0));
+}
+
+/*
+ * Return a mnemonic for class.
+ */
+const char *
+p_class(int class) {
+ return (sym_ntos(__p_class_syms, class, (int *)0));
+}
+
+/*
+ * Return a mnemonic for an option
+ */
+const char *
+p_option(u_long option) {
+ static char nbuf[40];
+
+ switch (option) {
+ case RES_INIT: return "init";
+ case RES_DEBUG: return "debug";
+ case RES_AAONLY: return "aaonly(unimpl)";
+ case RES_USEVC: return "usevc";
+ case RES_PRIMARY: return "primry(unimpl)";
+ case RES_IGNTC: return "igntc";
+ case RES_RECURSE: return "recurs";
+ case RES_DEFNAMES: return "defnam";
+ case RES_STAYOPEN: return "styopn";
+ case RES_DNSRCH: return "dnsrch";
+ case RES_INSECURE1: return "insecure1";
+ case RES_INSECURE2: return "insecure2";
+ default: sprintf(nbuf, "?0x%lx?", (u_long)option);
+ return (nbuf);
+ }
+}
+
+/*
+ * Return a mnemonic for a time to live.
+ */
+const char *
+p_time(u_int32_t value) {
+ static char nbuf[40];
+
+ if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
+ sprintf(nbuf, "%" PRIu32, (uint32_t) value);
+ return (nbuf);
+}
+
+
+/*
+ * routines to convert between on-the-wire RR format and zone file format.
+ * Does not contain conversion to/from decimal degrees; divide or multiply
+ * by 60*60*1000 for that.
+ */
+
+static uint32_t poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
+ 1000000,10000000,100000000,1000000000};
+
+/* takes an XeY precision/size value, returns a string representation. */
+static const char *
+precsize_ntoa(
+ u_int8_t prec)
+{
+ static char retbuf[sizeof "90000000.00"];
+ unsigned long val;
+ uint32_t mantissa, exponent;
+
+ mantissa = (int)((prec >> 4) & 0x0f) % 10;
+ exponent = (int)((prec >> 0) & 0x0f) % 10;
+
+ val = mantissa * poweroften[exponent];
+
+ (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
+ return (retbuf);
+}
+
+/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
+static u_int8_t
+precsize_aton(
+ const char **strptr)
+{
+ unsigned int mval = 0, cmval = 0;
+ u_int8_t retval = 0;
+ const char *cp;
+ int exponent;
+ int mantissa;
+
+ cp = *strptr;
+
+ while (isdigit((unsigned char)*cp))
+ mval = mval * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* centimeters */
+ cp++;
+ if (isdigit((unsigned char)*cp)) {
+ cmval = (*cp++ - '0') * 10;
+ if (isdigit((unsigned char)*cp)) {
+ cmval += (*cp++ - '0');
+ }
+ }
+ }
+ cmval = (mval * 100) + cmval;
+
+ for (exponent = 0; exponent < 9; exponent++)
+ if (cmval < poweroften[exponent+1])
+ break;
+
+ mantissa = cmval / poweroften[exponent];
+ if (mantissa > 9)
+ mantissa = 9;
+
+ retval = (mantissa << 4) | exponent;
+
+ *strptr = cp;
+
+ return (retval);
+}
+
+/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
+static u_int32_t
+latlon2ul(
+ char **latlonstrptr,
+ int *which )
+{
+ char *cp;
+ u_int32_t retval;
+ int deg = 0, min = 0, secs = 0, secsfrac = 0;
+
+ cp = *latlonstrptr;
+
+ while (isdigit((unsigned char)*cp))
+ deg = deg * 10 + (*cp++ - '0');
+
+ while (isspace((unsigned char)*cp))
+ cp++;
+
+ if (!(isdigit((unsigned char)*cp)))
+ goto fndhemi;
+
+ while (isdigit((unsigned char)*cp))
+ min = min * 10 + (*cp++ - '0');
+
+ while (isspace((unsigned char)*cp))
+ cp++;
+
+ if (!(isdigit((unsigned char)*cp)))
+ goto fndhemi;
+
+ while (isdigit((unsigned char)*cp))
+ secs = secs * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* decimal seconds */
+ cp++;
+ if (isdigit((unsigned char)*cp)) {
+ secsfrac = (*cp++ - '0') * 100;
+ if (isdigit((unsigned char)*cp)) {
+ secsfrac += (*cp++ - '0') * 10;
+ if (isdigit((unsigned char)*cp)) {
+ secsfrac += (*cp++ - '0');
+ }
+ }
+ }
+ }
+
+ while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
+ cp++;
+
+ while (isspace((unsigned char)*cp))
+ cp++;
+
+ fndhemi:
+ switch (*cp) {
+ case 'N': case 'n':
+ case 'E': case 'e':
+ retval = ((u_int32_t)1<<31)
+ + (((((deg * 60) + min) * 60) + secs) * 1000)
+ + secsfrac;
+ break;
+ case 'S': case 's':
+ case 'W': case 'w':
+ retval = ((u_int32_t)1<<31)
+ - (((((deg * 60) + min) * 60) + secs) * 1000)
+ - secsfrac;
+ break;
+ default:
+ retval = 0; /* invalid value -- indicates error */
+ break;
+ }
+
+ switch (*cp) {
+ case 'N': case 'n':
+ case 'S': case 's':
+ *which = 1; /* latitude */
+ break;
+ case 'E': case 'e':
+ case 'W': case 'w':
+ *which = 2; /* longitude */
+ break;
+ default:
+ *which = 0; /* error */
+ break;
+ }
+
+ cp++; /* skip the hemisphere */
+
+ while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
+ cp++;
+
+ while (isspace((unsigned char)*cp)) /* move to next field */
+ cp++;
+
+ *latlonstrptr = cp;
+
+ return (retval);
+}
+
+/* converts a zone file representation in a string to an RDATA on-the-wire
+ * representation. */
+int
+loc_aton(
+ const char *ascii,
+ u_char *binary)
+{
+ const char *cp, *maxcp;
+ u_char *bcp;
+
+ u_int32_t latit = 0, longit = 0, alt = 0;
+ u_int32_t lltemp1 = 0, lltemp2 = 0;
+ int altmeters = 0, altfrac = 0, altsign = 1;
+ u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
+ u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
+ u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
+ int which1 = 0, which2 = 0;
+
+ cp = ascii;
+ maxcp = cp + strlen(ascii);
+
+ lltemp1 = latlon2ul((char **)&cp, &which1);
+
+ lltemp2 = latlon2ul((char **)&cp, &which2);
+
+ switch (which1 + which2) {
+ case 3: /* 1 + 2, the only valid combination */
+ if ((which1 == 1) && (which2 == 2)) { /* normal case */
+ latit = lltemp1;
+ longit = lltemp2;
+ } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
+ longit = lltemp1;
+ latit = lltemp2;
+ } else { /* some kind of brokenness */
+ return (0);
+ }
+ break;
+ default: /* we didn't get one of each */
+ return (0);
+ }
+
+ /* altitude */
+ if (*cp == '-') {
+ altsign = -1;
+ cp++;
+ }
+
+ if (*cp == '+')
+ cp++;
+
+ while (isdigit((unsigned char)*cp))
+ altmeters = altmeters * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* decimal meters */
+ cp++;
+ if (isdigit((unsigned char)*cp)) {
+ altfrac = (*cp++ - '0') * 10;
+ if (isdigit((unsigned char)*cp)) {
+ altfrac += (*cp++ - '0');
+ }
+ }
+ }
+
+ alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
+
+ while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace((unsigned char)*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ siz = precsize_aton(&cp);
+
+ while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace((unsigned char)*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ hp = precsize_aton(&cp);
+
+ while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace((unsigned char)*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ vp = precsize_aton(&cp);
+
+ defaults:
+
+ bcp = binary;
+ *bcp++ = (u_int8_t) 0; /* version byte */
+ *bcp++ = siz;
+ *bcp++ = hp;
+ *bcp++ = vp;
+ PUTLONG(latit,bcp);
+ PUTLONG(longit,bcp);
+ PUTLONG(alt,bcp);
+
+ return (16); /* size of RR in octets */
+}
+
+/* takes an on-the-wire LOC RR and formats it in a human readable format. */
+const char *
+loc_ntoa(
+ const u_char *binary,
+ char *ascii )
+{
+ static char *error = "?";
+ const u_char *cp = binary;
+
+ int latdeg, latmin, latsec, latsecfrac;
+ int longdeg, longmin, longsec, longsecfrac;
+ char northsouth, eastwest;
+ int altmeters, altfrac, altsign;
+
+ const u_int32_t referencealt = 100000 * 100;
+
+ int32_t latval, longval, altval;
+ u_int32_t templ;
+ u_int8_t sizeval, hpval, vpval, versionval;
+
+ char *sizestr, *hpstr, *vpstr;
+
+ versionval = *cp++;
+
+ if (versionval) {
+ (void) sprintf(ascii, "; error: unknown LOC RR version");
+ return (ascii);
+ }
+
+ sizeval = *cp++;
+
+ hpval = *cp++;
+ vpval = *cp++;
+
+ GETLONG(templ, cp);
+ latval = (templ - ((u_int32_t)1<<31));
+
+ GETLONG(templ, cp);
+ longval = (templ - ((u_int32_t)1<<31));
+
+ GETLONG(templ, cp);
+ if (templ < referencealt) { /* below WGS 84 spheroid */
+ altval = referencealt - templ;
+ altsign = -1;
+ } else {
+ altval = templ - referencealt;
+ altsign = 1;
+ }
+
+ if (latval < 0) {
+ northsouth = 'S';
+ latval = -latval;
+ } else
+ northsouth = 'N';
+
+ latsecfrac = latval % 1000;
+ latval = latval / 1000;
+ latsec = latval % 60;
+ latval = latval / 60;
+ latmin = latval % 60;
+ latval = latval / 60;
+ latdeg = latval;
+
+ if (longval < 0) {
+ eastwest = 'W';
+ longval = -longval;
+ } else
+ eastwest = 'E';
+
+ longsecfrac = longval % 1000;
+ longval = longval / 1000;
+ longsec = longval % 60;
+ longval = longval / 60;
+ longmin = longval % 60;
+ longval = longval / 60;
+ longdeg = longval;
+
+ altfrac = altval % 100;
+ altmeters = (altval / 100) * altsign;
+
+ if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
+ sizestr = error;
+ if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
+ hpstr = error;
+ if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
+ vpstr = error;
+
+ sprintf(ascii,
+ "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
+ latdeg, latmin, latsec, latsecfrac, northsouth,
+ longdeg, longmin, longsec, longsecfrac, eastwest,
+ altmeters, altfrac, sizestr, hpstr, vpstr);
+
+ if (sizestr != error)
+ free(sizestr);
+ if (hpstr != error)
+ free(hpstr);
+ if (vpstr != error)
+ free(vpstr);
+
+ return (ascii);
+}
+
+
+/* Return the number of DNS hierarchy levels in the name. */
+int
+dn_count_labels(const char *name) {
+ int i, len, count;
+
+ len = strlen(name);
+ for (i = 0, count = 0; i < len; i++) {
+ /* XXX need to check for \. or use named's nlabels(). */
+ if (name[i] == '.')
+ count++;
+ }
+
+ /* don't count initial wildcard */
+ if (name[0] == '*')
+ if (count)
+ count--;
+
+ /* don't count the null label for root. */
+ /* if terminating '.' not found, must adjust */
+ /* count to include last label */
+ if (len > 0 && name[len-1] != '.')
+ count++;
+ return (count);
+}
+
+
+/*
+ * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
+ * SIG records are required to be printed like this, by the Secure DNS RFC.
+ */
+char *
+p_secstodate (u_long secs) {
+ static char output[15]; /* YYYYMMDDHHMMSS and null */
+ time_t clock = secs;
+ struct tm *time;
+
+ time = gmtime(&clock);
+ time->tm_year += 1900;
+ time->tm_mon += 1;
+ sprintf(output, "%04d%02d%02d%02d%02d%02d",
+ time->tm_year, time->tm_mon, time->tm_mday,
+ time->tm_hour, time->tm_min, time->tm_sec);
+ return (output);
+}
diff --git a/cpukit/libnetworking/libc/res_init.c b/cpukit/libnetworking/libc/res_init.c
new file mode 100644
index 0000000000..9af80e3727
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_init.c
@@ -0,0 +1,501 @@
+/*
+ * Copyright (c) 1985, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "res_config.h"
+
+/*
+ * RTEMS -- set up name servers from global variable
+ */
+#include <rtems/rtems_bsdnet_internal.h>
+#include <rtems/bsdnet/servers.h>
+
+static void res_setoptions(char *, char *);
+
+#ifdef RESOLVSORT
+static const char sort_mask[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
+static u_int32_t net_mask(struct in_addr);
+#endif
+
+#if !defined(isascii) /* XXX - could be a function */
+# define isascii(c) (!(c & 0200))
+#endif
+
+/*
+ * Resolver state default settings.
+ */
+
+struct __res_state _res
+# if defined(__BIND_RES_TEXT)
+ = { RES_TIMEOUT, } /* Motorola, et al. */
+# endif
+ ;
+
+
+/*
+ * Set up default settings. If the configuration file exist, the values
+ * there will have precedence. Otherwise, the server address is set to
+ * INADDR_ANY and the default domain name comes from the gethostname().
+ *
+ * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
+ * rather than INADDR_ANY ("0.0.0.0") as the default name server address
+ * since it was noted that INADDR_ANY actually meant ``the first interface
+ * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
+ * it had to be "up" in order for you to reach your own name server. It
+ * was later decided that since the recommended practice is to always
+ * install local static routes through 127.0.0.1 for all your network
+ * interfaces, that we could solve this problem without a code change.
+ *
+ * The configuration file should always be used, since it is the only way
+ * to specify a default domain. If you are running a server on your local
+ * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
+ * in the configuration file.
+ *
+ * Return 0 if completes successfully, -1 on error
+ */
+int
+res_init(void)
+{
+ FILE *fp;
+ char *cp, **pp;
+ int n;
+ char buf[MAXDNAME];
+ int nserv = 0; /* number of nameserver records read from file */
+ int haveenv = 0;
+ int havesearch = 0;
+#ifdef RESOLVSORT
+ int nsort = 0;
+ char *net;
+#endif
+#ifndef RFC1535
+ int dots;
+#endif
+
+ /*
+ * These three fields used to be statically initialized. This made
+ * it hard to use this code in a shared library. It is necessary,
+ * now that we're doing dynamic initialization here, that we preserve
+ * the old semantics: if an application modifies one of these three
+ * fields of _res before res_init() is called, res_init() will not
+ * alter them. Of course, if an application is setting them to
+ * _zero_ before calling res_init(), hoping to override what used
+ * to be the static default, we can't detect it and unexpected results
+ * will follow. Zero for any of these fields would make no sense,
+ * so one can safely assume that the applications were already getting
+ * unexpected results.
+ *
+ * _res.options is tricky since some apps were known to diddle the bits
+ * before res_init() was first called. We can't replicate that semantic
+ * with dynamic initialization (they may have turned bits off that are
+ * set in RES_DEFAULT). Our solution is to declare such applications
+ * "broken". They could fool us by setting RES_INIT but none do (yet).
+ */
+ if (!_res.retrans)
+ _res.retrans = RES_TIMEOUT;
+ if (!_res.retry)
+ _res.retry = 4;
+ if (!(_res.options & RES_INIT))
+ _res.options = RES_DEFAULT;
+
+ /*
+ * This one used to initialize implicitly to zero, so unless the app
+ * has set it to something in particular, we can randomize it now.
+ */
+ if (!_res.id)
+ _res.id = res_randomid();
+
+#ifdef USELOOPBACK
+ _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
+#else
+ _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
+#endif
+ _res.nsaddr.sin_family = AF_INET;
+ _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
+ _res.nscount = 1;
+ _res.ndots = 1;
+ _res.pfcode = 0;
+
+ /*
+ * RTEMS -- Set up name servers
+ */
+ {
+ int n = 0;
+ while ((n < rtems_bsdnet_nameserver_count) && (nserv < MAXNS)) {
+ _res.nsaddr_list[nserv].sin_addr = rtems_bsdnet_nameserver[n];
+ _res.nsaddr_list[nserv].sin_family = AF_INET;
+ _res.nsaddr_list[nserv].sin_port = htons(NAMESERVER_PORT);
+ nserv++;
+ n++;
+ }
+ if (rtems_bsdnet_domain_name)
+ (void)strncpy(_res.defdname, rtems_bsdnet_domain_name, sizeof(_res.defdname) - 1);
+ }
+
+ /* Allow user to override the local domain definition */
+ if ((cp = getenv("LOCALDOMAIN")) != NULL) {
+ (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ haveenv++;
+
+ /*
+ * Set search list to be blank-separated strings
+ * from rest of env value. Permits users of LOCALDOMAIN
+ * to still have a search list, and anyone to set the
+ * one that they want to use as an individual (even more
+ * important now that the rfc1535 stuff restricts searches)
+ */
+ cp = _res.defdname;
+ pp = _res.dnsrch;
+ *pp++ = cp;
+ for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ if (*cp == '\n') /* silly backwards compat */
+ break;
+ else if (*cp == ' ' || *cp == '\t') {
+ *cp = 0;
+ n = 1;
+ } else if (n) {
+ *pp++ = cp;
+ n = 0;
+ havesearch = 1;
+ }
+ }
+ /* null terminate last domain if there are excess */
+ while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
+ cp++;
+ *cp = '\0';
+ *pp++ = 0;
+ }
+
+#define MATCH(line, name) \
+ (!strncmp(line, name, sizeof(name) - 1) && \
+ (line[sizeof(name) - 1] == ' ' || \
+ line[sizeof(name) - 1] == '\t'))
+
+ if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+ /* read the config file */
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ /* skip comments */
+ if (*buf == ';' || *buf == '#')
+ continue;
+ /* read default domain name */
+ if (MATCH(buf, "domain")) {
+ if (haveenv) /* skip if have from environ */
+ continue;
+ cp = buf + sizeof("domain") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp == '\0') || (*cp == '\n'))
+ continue;
+ strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
+ *cp = '\0';
+ havesearch = 0;
+ continue;
+ }
+ /* set search list */
+ if (MATCH(buf, "search")) {
+ if (haveenv) /* skip if have from environ */
+ continue;
+ cp = buf + sizeof("search") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp == '\0') || (*cp == '\n'))
+ continue;
+ strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ if ((cp = strchr(_res.defdname, '\n')) != NULL)
+ *cp = '\0';
+ /*
+ * Set search list to be blank-separated strings
+ * on rest of line.
+ */
+ cp = _res.defdname;
+ pp = _res.dnsrch;
+ *pp++ = cp;
+ for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ if (*cp == ' ' || *cp == '\t') {
+ *cp = 0;
+ n = 1;
+ } else if (n) {
+ *pp++ = cp;
+ n = 0;
+ }
+ }
+ /* null terminate last domain if there are excess */
+ while (*cp != '\0' && *cp != ' ' && *cp != '\t')
+ cp++;
+ *cp = '\0';
+ *pp++ = 0;
+ havesearch = 1;
+ continue;
+ }
+ /* read nameservers to query */
+ if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+ struct in_addr a;
+
+ cp = buf + sizeof("nameserver") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
+ _res.nsaddr_list[nserv].sin_addr = a;
+ _res.nsaddr_list[nserv].sin_family = AF_INET;
+ _res.nsaddr_list[nserv].sin_port =
+ htons(NAMESERVER_PORT);
+ nserv++;
+ }
+ continue;
+ }
+#ifdef RESOLVSORT
+ if (MATCH(buf, "sortlist")) {
+ struct in_addr a;
+
+ cp = buf + sizeof("sortlist") - 1;
+ while (nsort < MAXRESOLVSORT) {
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if (*cp == '\0' || *cp == '\n' || *cp == ';')
+ break;
+ net = cp;
+ while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
+ isascii((unsigned char)*cp) && !isspace((unsigned char)*cp))
+ cp++;
+ n = *cp;
+ *cp = 0;
+ if (inet_aton(net, &a)) {
+ _res.sort_list[nsort].addr = a;
+ if (ISSORTMASK(n)) {
+ *cp++ = n;
+ net = cp;
+ while (*cp && *cp != ';' &&
+ isascii((unsigned char)*cp) && !isspace((unsigned char)*cp))
+ cp++;
+ n = *cp;
+ *cp = 0;
+ if (inet_aton(net, &a)) {
+ _res.sort_list[nsort].mask = a.s_addr;
+ } else {
+ _res.sort_list[nsort].mask =
+ net_mask(_res.sort_list[nsort].addr);
+ }
+ } else {
+ _res.sort_list[nsort].mask =
+ net_mask(_res.sort_list[nsort].addr);
+ }
+ nsort++;
+ }
+ *cp = n;
+ }
+ continue;
+ }
+#endif
+ if (MATCH(buf, "options")) {
+ res_setoptions(buf + sizeof("options") - 1, "conf");
+ continue;
+ }
+ }
+ if (nserv > 1)
+ _res.nscount = nserv;
+#ifdef RESOLVSORT
+ _res.nsort = nsort;
+#endif
+ (void) fclose(fp);
+ }
+ if (_res.defdname[0] == 0 &&
+ gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
+ (cp = strchr(buf, '.')) != NULL)
+ strcpy(_res.defdname, cp + 1);
+
+ /* find components of local domain that might be searched */
+ if (havesearch == 0) {
+ pp = _res.dnsrch;
+ *pp++ = _res.defdname;
+ *pp = NULL;
+
+#ifndef RFC1535
+ dots = 0;
+ for (cp = _res.defdname; *cp; cp++)
+ dots += (*cp == '.');
+
+ cp = _res.defdname;
+ while (pp < _res.dnsrch + MAXDFLSRCH) {
+ if (dots < LOCALDOMAINPARTS)
+ break;
+ cp = strchr(cp, '.') + 1; /* we know there is one */
+ *pp++ = cp;
+ dots--;
+ }
+ *pp = NULL;
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG) {
+ printf(";; res_init()... default dnsrch list:\n");
+ for (pp = _res.dnsrch; *pp; pp++)
+ printf(";;\t%s\n", *pp);
+ printf(";;\t..END..\n");
+ }
+#endif
+#endif /* !RFC1535 */
+ }
+
+ if ((cp = getenv("RES_OPTIONS")) != NULL)
+ res_setoptions(cp, "env");
+ _res.options |= RES_INIT;
+ return (0);
+}
+
+static void
+res_setoptions(
+ char *options,
+ char *source)
+{
+ char *cp = options;
+ int i;
+
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_setoptions(\"%s\", \"%s\")...\n",
+ options, source);
+#endif
+ while (*cp) {
+ /* skip leading and inner runs of spaces */
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ /* search for and process individual options */
+ if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
+ i = atoi(cp + sizeof("ndots:") - 1);
+ if (i <= RES_MAXNDOTS)
+ _res.ndots = i;
+ else
+ _res.ndots = RES_MAXNDOTS;
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";;\tndots=%d\n", _res.ndots);
+#endif
+ } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
+#ifdef DEBUG
+ if (!(_res.options & RES_DEBUG)) {
+ printf(";; res_setoptions(\"%s\", \"%s\")..\n",
+ options, source);
+ _res.options |= RES_DEBUG;
+ }
+ printf(";;\tdebug\n");
+#endif
+ } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
+ _res.options |= RES_USE_INET6;
+ } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) {
+ _res.options |= RES_NOTLDQUERY;
+ } else {
+ /* XXX - print a warning here? */
+ }
+ /* skip to next run of spaces */
+ while (*cp && *cp != ' ' && *cp != '\t')
+ cp++;
+ }
+}
+
+#ifdef RESOLVSORT
+/* XXX - should really support CIDR which means explicit masks always. */
+static u_int32_t
+net_mask( /* XXX - should really use system's version of this */
+ struct in_addr in)
+{
+ u_int32_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (htonl(IN_CLASSA_NET));
+ else if (IN_CLASSB(i))
+ return (htonl(IN_CLASSB_NET));
+ return (htonl(IN_CLASSC_NET));
+}
+#endif
+
+u_int
+res_randomid(void)
+{
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
+}
diff --git a/cpukit/libnetworking/libc/res_mkquery.c b/cpukit/libnetworking/libc/res_mkquery.c
new file mode 100644
index 0000000000..832e2df740
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_mkquery.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "res_config.h"
+
+/*
+ * Form all types of queries.
+ * Returns the size of the result or -1.
+ */
+int
+res_mkquery(
+ int op, /* opcode of query */
+ const char *dname, /* domain name */
+ int class, int type, /* class and type of query */
+ const u_char *data, /* resource record data */
+ int datalen, /* length of data */
+ const u_char *newrr_in, /* new rr for modify or append */
+ u_char *buf, /* buffer to put query */
+ int buflen) /* size of buffer */
+{
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *dnptrs[20], **dpp, **lastdnptr;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_mkquery(%d, %s, %d, %d)\n",
+ op, dname, class, type);
+#endif
+ /*
+ * Initialize header fields.
+ */
+ if ((buf == NULL) || (buflen < HFIXEDSZ))
+ return (-1);
+ memset(buf, 0, HFIXEDSZ);
+ hp = (HEADER *) buf;
+ hp->id = htons(++_res.id);
+ hp->opcode = op;
+ hp->rd = (_res.options & RES_RECURSE) != 0;
+ hp->rcode = NOERROR;
+ cp = buf + HFIXEDSZ;
+ buflen -= HFIXEDSZ;
+ dpp = dnptrs;
+ *dpp++ = buf;
+ *dpp++ = NULL;
+ lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+ /*
+ * perform opcode specific processing
+ */
+ switch (op) {
+ case QUERY: /*FALLTHROUGH*/
+ case NS_NOTIFY_OP:
+ if ((buflen -= QFIXEDSZ) < 0)
+ return (-1);
+ if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+ return (-1);
+ cp += n;
+ buflen -= n;
+ __putshort(type, cp);
+ cp += INT16SZ;
+ __putshort(class, cp);
+ cp += INT16SZ;
+ hp->qdcount = htons(1);
+ if (op == QUERY || data == NULL)
+ break;
+ /*
+ * Make an additional record for completion domain.
+ */
+ buflen -= RRFIXEDSZ;
+ n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ buflen -= n;
+ __putshort(T_NULL, cp);
+ cp += INT16SZ;
+ __putshort(class, cp);
+ cp += INT16SZ;
+ __putlong(0, cp);
+ cp += INT32SZ;
+ __putshort(0, cp);
+ cp += INT16SZ;
+ hp->arcount = htons(1);
+ break;
+
+ case IQUERY:
+ /*
+ * Initialize answer section
+ */
+ if (buflen < 1 + RRFIXEDSZ + datalen)
+ return (-1);
+ *cp++ = '\0'; /* no domain name */
+ __putshort(type, cp);
+ cp += INT16SZ;
+ __putshort(class, cp);
+ cp += INT16SZ;
+ __putlong(0, cp);
+ cp += INT32SZ;
+ __putshort(datalen, cp);
+ cp += INT16SZ;
+ if (datalen) {
+ memcpy(cp, data, datalen);
+ cp += datalen;
+ }
+ hp->ancount = htons(1);
+ break;
+
+ default:
+ return (-1);
+ }
+ return (cp - buf);
+}
diff --git a/cpukit/libnetworking/libc/res_mkupdate.c b/cpukit/libnetworking/libc/res_mkupdate.c
new file mode 100644
index 0000000000..74eb5b18c4
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_mkupdate.c
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Based on the Dynamic DNS reference implementation by Viraj Bais
+ * <viraj_bais@ccm.fm.intel.com>
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "res_config.h"
+
+static int getnum_str(u_char **, u_char *);
+static int getword_str(char *, int, u_char **, u_char *);
+
+#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
+
+/*
+ * Form update packets.
+ * Returns the size of the resulting packet if no error
+ * On error,
+ * returns -1 if error in reading a word/number in rdata
+ * portion for update packets
+ * -2 if length of buffer passed is insufficient
+ * -3 if zone section is not the first section in
+ * the linked list, or section order has a problem
+ * -4 on a number overflow
+ * -5 unknown operation or no records
+ */
+int
+res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
+ ns_updrec *rrecp_start = rrecp_in;
+ HEADER *hp;
+ u_char *cp, *sp1, *sp2, *startp, *endp;
+ int n, i, soanum, multiline;
+ ns_updrec *rrecp;
+ struct in_addr ina;
+ char buf2[MAXDNAME];
+ int section, numrrs = 0, counts[ns_s_max];
+ u_int16_t rtype, rclass;
+ u_int32_t n1, rttl;
+ u_char *dnptrs[20], **dpp, **lastdnptr;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+
+ /*
+ * Initialize header fields.
+ */
+ if ((buf == NULL) || (buflen < HFIXEDSZ))
+ return (-1);
+ memset(buf, 0, HFIXEDSZ);
+ hp = (HEADER *) buf;
+ hp->id = htons(++_res.id);
+ hp->opcode = ns_o_update;
+ hp->rcode = NOERROR;
+ sp1 = buf + 2*INT16SZ; /* save pointer to zocount */
+ cp = buf + HFIXEDSZ;
+ buflen -= HFIXEDSZ;
+ dpp = dnptrs;
+ *dpp++ = buf;
+ *dpp++ = NULL;
+ lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+
+ if (rrecp_start == NULL)
+ return (-5);
+ else if (rrecp_start->r_section != S_ZONE)
+ return (-3);
+
+ memset(counts, 0, sizeof counts);
+ for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {
+ numrrs++;
+ section = rrecp->r_section;
+ if (section < 0 || section >= ns_s_max)
+ return (-1);
+ counts[section]++;
+ for (i = section + 1; i < ns_s_max; i++)
+ if (counts[i])
+ return (-3);
+ rtype = rrecp->r_type;
+ rclass = rrecp->r_class;
+ rttl = rrecp->r_ttl;
+ /* overload class and type */
+ if (section == S_PREREQ) {
+ rttl = 0;
+ switch (rrecp->r_opcode) {
+ case YXDOMAIN:
+ rclass = C_ANY;
+ rtype = T_ANY;
+ rrecp->r_size = 0;
+ break;
+ case NXDOMAIN:
+ rclass = C_NONE;
+ rtype = T_ANY;
+ rrecp->r_size = 0;
+ break;
+ case NXRRSET:
+ rclass = C_NONE;
+ rrecp->r_size = 0;
+ break;
+ case YXRRSET:
+ if (rrecp->r_size == 0)
+ rclass = C_ANY;
+ break;
+ default:
+ fprintf(stderr,
+ "res_mkupdate: incorrect opcode: %d\n",
+ rrecp->r_opcode);
+ fflush(stderr);
+ return (-1);
+ }
+ } else if (section == S_UPDATE) {
+ switch (rrecp->r_opcode) {
+ case DELETE:
+ rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;
+ break;
+ case ADD:
+ break;
+ default:
+ fprintf(stderr,
+ "res_mkupdate: incorrect opcode: %d\n",
+ rrecp->r_opcode);
+ fflush(stderr);
+ return (-1);
+ }
+ }
+
+ /*
+ * XXX appending default domain to owner name is omitted,
+ * fqdn must be provided
+ */
+ if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,
+ lastdnptr)) < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n + 2*INT16SZ);
+ PUTSHORT(rtype, cp);
+ PUTSHORT(rclass, cp);
+ if (section == S_ZONE) {
+ if (numrrs != 1 || rrecp->r_type != T_SOA)
+ return (-3);
+ continue;
+ }
+ ShrinkBuffer(INT32SZ + INT16SZ);
+ PUTLONG(rttl, cp);
+ sp2 = cp; /* save pointer to length byte */
+ cp += INT16SZ;
+ if (rrecp->r_size == 0) {
+ if (section == S_UPDATE && rclass != C_ANY)
+ return (-1);
+ else {
+ PUTSHORT(0, sp2);
+ continue;
+ }
+ }
+ startp = rrecp->r_data;
+ endp = startp + rrecp->r_size - 1;
+ /* XXX this should be done centrally. */
+ switch (rrecp->r_type) {
+ case T_A:
+ if (!getword_str(buf2, sizeof buf2, &startp, endp))
+ return (-1);
+ if (!inet_aton(buf2, &ina))
+ return (-1);
+ n1 = ntohl(ina.s_addr);
+ ShrinkBuffer(INT32SZ);
+ PUTLONG(n1, cp);
+ break;
+ case T_CNAME:
+ case T_MB:
+ case T_MG:
+ case T_MR:
+ case T_NS:
+ case T_PTR:
+ if (!getword_str(buf2, sizeof buf2, &startp, endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ break;
+ case T_MINFO:
+ case T_SOA:
+ case T_RP:
+ for (i = 0; i < 2; i++) {
+ if (!getword_str(buf2, sizeof buf2, &startp,
+ endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen,
+ dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ }
+ if (rrecp->r_type == T_SOA) {
+ ShrinkBuffer(5 * INT32SZ);
+ while (isspace(*startp) || !*startp)
+ startp++;
+ if (*startp == '(') {
+ multiline = 1;
+ startp++;
+ } else
+ multiline = 0;
+ /* serial, refresh, retry, expire, minimum */
+ for (i = 0; i < 5; i++) {
+ soanum = getnum_str(&startp, endp);
+ if (soanum < 0)
+ return (-1);
+ PUTLONG(soanum, cp);
+ }
+ if (multiline) {
+ while (isspace(*startp) || !*startp)
+ startp++;
+ if (*startp != ')')
+ return (-1);
+ }
+ }
+ break;
+ case T_MX:
+ case T_AFSDB:
+ case T_RT:
+ n = getnum_str(&startp, endp);
+ if (n < 0)
+ return (-1);
+ PUTSHORT(n, cp);
+ ShrinkBuffer(INT16SZ);
+ if (!getword_str(buf2, sizeof buf2, &startp, endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ break;
+ case T_PX:
+ n = getnum_str(&startp, endp);
+ if (n < 0)
+ return (-1);
+ PUTSHORT(n, cp);
+ ShrinkBuffer(INT16SZ);
+ for (i = 0; i < 2; i++) {
+ if (!getword_str(buf2, sizeof buf2, &startp,
+ endp))
+ return (-1);
+ n = dn_comp(buf2, cp, buflen, dnptrs,
+ lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ShrinkBuffer(n);
+ }
+ break;
+ case T_WKS:
+ case T_HINFO:
+ case T_TXT:
+ case T_X25:
+ case T_ISDN:
+ case T_NSAP:
+ case T_LOC:
+ /* XXX - more fine tuning needed here */
+ ShrinkBuffer(rrecp->r_size);
+ memcpy(cp, rrecp->r_data, rrecp->r_size);
+ cp += rrecp->r_size;
+ break;
+ default:
+ return (-1);
+ } /*switch*/
+ n = (u_int16_t)((cp - sp2) - INT16SZ);
+ PUTSHORT(n, sp2);
+ } /*for*/
+
+ hp->qdcount = htons(counts[0]);
+ hp->ancount = htons(counts[1]);
+ hp->nscount = htons(counts[2]);
+ hp->arcount = htons(counts[3]);
+ return (cp - buf);
+}
+
+/*
+ * Get a whitespace delimited word from a string (not file)
+ * into buf. modify the start pointer to point after the
+ * word in the string.
+ */
+static int
+getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
+ char *cp;
+ int c;
+
+ for (cp = buf; *startpp <= endp; ) {
+ c = **startpp;
+ if (isspace(c) || c == '\0') {
+ if (cp != buf) /* trailing whitespace */
+ break;
+ else { /* leading whitespace */
+ (*startpp)++;
+ continue;
+ }
+ }
+ (*startpp)++;
+ if (cp >= buf+size-1)
+ break;
+ *cp++ = (u_char)c;
+ }
+ *cp = '\0';
+ return (cp != buf);
+}
+
+/*
+ * Get a whitespace delimited number from a string (not file) into buf
+ * update the start pointer to point after the number in the string.
+ */
+static int
+getnum_str(u_char **startpp, u_char *endp) {
+ int c, n;
+ int seendigit = 0;
+ int m = 0;
+
+ for (n = 0; *startpp <= endp; ) {
+ c = **startpp;
+ if (isspace(c) || c == '\0') {
+ if (seendigit) /* trailing whitespace */
+ break;
+ else { /* leading whitespace */
+ (*startpp)++;
+ continue;
+ }
+ }
+ if (c == ';') {
+ while ((*startpp <= endp) &&
+ ((c = **startpp) != '\n'))
+ (*startpp)++;
+ if (seendigit)
+ break;
+ continue;
+ }
+ if (!isdigit(c)) {
+ if (c == ')' && seendigit) {
+ (*startpp)--;
+ break;
+ }
+ return (-1);
+ }
+ (*startpp)++;
+ n = n * 10 + (c - '0');
+ seendigit = 1;
+ }
+ return (n + m);
+}
+
+/*
+ * Allocate a resource record buffer & save rr info.
+ */
+ns_updrec *
+res_mkupdrec(int section, const char *dname,
+ u_int class, u_int type, u_long ttl) {
+ ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
+
+ if (!rrecp || !(rrecp->r_dname = strdup(dname)))
+ return (NULL);
+ rrecp->r_class = class;
+ rrecp->r_type = type;
+ rrecp->r_ttl = ttl;
+ rrecp->r_section = section;
+ return (rrecp);
+}
+
+/*
+ * Free a resource record buffer created by res_mkupdrec.
+ */
+void
+res_freeupdrec(ns_updrec *rrecp) {
+ /* Note: freeing r_dp is the caller's responsibility. */
+ if (rrecp->r_dname != NULL)
+ free(rrecp->r_dname);
+ free(rrecp);
+}
diff --git a/cpukit/libnetworking/libc/res_query.c b/cpukit/libnetworking/libc/res_query.c
new file mode 100644
index 0000000000..b742c30315
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_query.c
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include "res_config.h"
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in h_errno.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+int
+res_query(
+ const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer buffer */
+{
+ u_char buf[MAXPACKET];
+ HEADER *hp = (HEADER *) answer;
+ int n;
+
+ hp->rcode = NOERROR; /* default */
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query(%s, %d, %d)\n", name, class, type);
+#endif
+
+ n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
+ buf, sizeof(buf));
+ if (n <= 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query: mkquery failed\n");
+#endif
+ h_errno = NO_RECOVERY;
+ return (n);
+ }
+ n = res_send(buf, n, answer, anslen);
+ if (n < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query: send error\n");
+#endif
+ h_errno = TRY_AGAIN;
+ return (n);
+ }
+
+ if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; rcode = %d, ancount=%d\n", hp->rcode,
+ ntohs(hp->ancount));
+#endif
+ switch (hp->rcode) {
+ case NXDOMAIN:
+ h_errno = HOST_NOT_FOUND;
+ break;
+ case SERVFAIL:
+ h_errno = TRY_AGAIN;
+ break;
+ case NOERROR:
+ h_errno = NO_DATA;
+ break;
+ case FORMERR:
+ case NOTIMP:
+ case REFUSED:
+ default:
+ h_errno = NO_RECOVERY;
+ break;
+ }
+ return (-1);
+ }
+ return (n);
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * If enabled, implement search rules until answer or unrecoverable failure
+ * is detected. Error code, if any, is left in h_errno.
+ */
+int
+res_search(
+ const char *name, /* domain name */
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer */
+{
+ const char *cp, * const *domain;
+ HEADER *hp = (HEADER *) answer;
+ u_int dots;
+ int trailing_dot, ret, saved_herrno;
+ int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+ errno = 0;
+ h_errno = HOST_NOT_FOUND; /* default, if we never query */
+ dots = 0;
+ for (cp = name; *cp; cp++)
+ dots += (*cp == '.');
+ trailing_dot = 0;
+ if (cp > name && *--cp == '.')
+ trailing_dot++;
+
+ /* If there aren't any dots, it could be a user-level alias */
+ if (!dots && (cp = hostalias(name)) != NULL)
+ return (res_query(cp, class, type, answer, anslen));
+
+ /*
+ * If there are dots in the name already, let's just give it a try
+ * 'as is'. The threshold can be set with the "ndots" option.
+ */
+ saved_herrno = -1;
+ if (dots >= _res.ndots) {
+ ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (ret > 0)
+ return (ret);
+ saved_herrno = h_errno;
+ tried_as_is++;
+ }
+
+ /*
+ * We do at least one level of search if
+ * - there is no dot and RES_DEFNAME is set, or
+ * - there is at least one dot, there is no trailing dot,
+ * and RES_DNSRCH is set.
+ */
+ if ((!dots && (_res.options & RES_DEFNAMES)) ||
+ (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
+ int done = 0;
+
+ for (domain = (const char * const *)_res.dnsrch;
+ *domain && !done;
+ domain++) {
+
+ ret = res_querydomain(name, *domain, class, type,
+ answer, anslen);
+ if (ret > 0)
+ return (ret);
+
+ /*
+ * If no server present, give up.
+ * If name isn't found in this domain,
+ * keep trying higher domains in the search list
+ * (if that's enabled).
+ * On a NO_DATA error, keep trying, otherwise
+ * a wildcard entry of another type could keep us
+ * from finding this entry higher in the domain.
+ * If we get some other error (negative answer or
+ * server failure), then stop searching up,
+ * but try the input name below in case it's
+ * fully-qualified.
+ */
+ if (errno == ECONNREFUSED) {
+ h_errno = TRY_AGAIN;
+ return (-1);
+ }
+
+ switch (h_errno) {
+ case NO_DATA:
+ got_nodata++;
+ /* FALLTHROUGH */
+ case HOST_NOT_FOUND:
+ /* keep trying */
+ break;
+ case TRY_AGAIN:
+ if (hp->rcode == SERVFAIL) {
+ /* try next search element, if any */
+ got_servfail++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ /* anything else implies that we're done */
+ done++;
+ }
+
+ /* if we got here for some reason other than DNSRCH,
+ * we only wanted one iteration of the loop, so stop.
+ */
+ if (!(_res.options & RES_DNSRCH))
+ done++;
+ }
+ }
+
+ /*
+ * If we have not already tried the name "as is", do that now.
+ * note that we do this regardless of how many dots were in the
+ * name or whether it ends with a dot unless NOTLDQUERY is set.
+ */
+ if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) {
+ ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (ret > 0)
+ return (ret);
+ }
+
+ /* if we got here, we didn't satisfy the search.
+ * if we did an initial full query, return that query's h_errno
+ * (note that we wouldn't be here if that query had succeeded).
+ * else if we ever got a nodata, send that back as the reason.
+ * else send back meaningless h_errno, that being the one from
+ * the last DNSRCH we did.
+ */
+ if (saved_herrno != -1)
+ h_errno = saved_herrno;
+ else if (got_nodata)
+ h_errno = NO_DATA;
+ else if (got_servfail)
+ h_errno = TRY_AGAIN;
+ return (-1);
+}
+
+/*
+ * Perform a call on res_query on the concatenation of name and domain,
+ * removing a trailing dot from name if domain is NULL.
+ */
+int
+res_querydomain(
+ const char *name, const char *domain,
+ int class, int type, /* class and type of query */
+ u_char *answer, /* buffer to put answer */
+ int anslen) /* size of answer */
+{
+ char nbuf[MAXDNAME];
+ const char *longname = nbuf;
+ int n, d;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_querydomain(%s, %s, %d, %d)\n",
+ name, domain?domain:"<Nil>", class, type);
+#endif
+ if (domain == NULL) {
+ /*
+ * Check for trailing '.';
+ * copy without '.' if present.
+ */
+ n = strlen(name);
+ if (n >= MAXDNAME) {
+ h_errno = NO_RECOVERY;
+ return (-1);
+ }
+ n--;
+ if (n >= 0 && name[n] == '.') {
+ strncpy(nbuf, name, n);
+ nbuf[n] = '\0';
+ } else
+ longname = name;
+ } else {
+ n = strlen(name);
+ d = strlen(domain);
+ if (n + d + 1 >= MAXDNAME) {
+ h_errno = NO_RECOVERY;
+ return (-1);
+ }
+ sprintf(nbuf, "%s.%s", name, domain);
+ }
+ return (res_query(longname, class, type, answer, anslen));
+}
+
+const char *
+hostalias(const char *name)
+{
+ register char *cp1, *cp2;
+ FILE *fp;
+ char *file;
+ char buf[BUFSIZ];
+ static char abuf[MAXDNAME];
+
+ if (_res.options & RES_NOALIASES)
+ return (NULL);
+ if (issetugid())
+ return (NULL);
+ file = getenv("HOSTALIASES");
+ if (file == NULL || (fp = fopen(file, "r")) == NULL)
+ return (NULL);
+ setbuf(fp, NULL);
+ buf[sizeof(buf) - 1] = '\0';
+ while (fgets(buf, sizeof(buf), fp)) {
+ for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1)
+ ;
+ if (!*cp1)
+ break;
+ *cp1 = '\0';
+ if (!strcasecmp(buf, name)) {
+ while (isspace((unsigned char)*++cp1))
+ ;
+ if (!*cp1)
+ break;
+ for (cp2 = cp1 + 1; *cp2 && !isspace((unsigned char)*cp2); ++cp2)
+ ;
+ abuf[sizeof(abuf) - 1] = *cp2 = '\0';
+ strncpy(abuf, cp1, sizeof(abuf) - 1);
+ fclose(fp);
+ return (abuf);
+ }
+ }
+ fclose(fp);
+ return (NULL);
+}
diff --git a/cpukit/libnetworking/libc/res_send.c b/cpukit/libnetworking/libc/res_send.c
new file mode 100644
index 0000000000..b1dc337b41
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_send.c
@@ -0,0 +1,936 @@
+/*
+ * Copyright (c) 1985, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Send query to name server and wait for reply.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <unistd.h>
+#if !defined(__rtems__)
+#include <poll.h>
+#endif
+
+/* RTEMS now has writev */
+#define USE_WRITEV
+
+#include "res_config.h"
+
+#if !defined(__rtems__)
+
+#ifdef NOPOLL /* libc_r doesn't wrap poll yet() */
+static int use_poll = 0;
+#else
+static int use_poll = 1; /* adapt to poll() syscall availability */
+ /* 0 = not present, 1 = try it, 2 = exists */
+#endif
+#endif
+
+static int s = -1; /* socket used for communications */
+static int connected = 0; /* is the socket connected */
+static int vc = 0; /* is the socket a virtual circuit? */
+static res_send_qhook Qhook = NULL;
+static res_send_rhook Rhook = NULL;
+
+
+#define CAN_RECONNECT 1
+
+#ifndef DEBUG
+# define Dprint(cond, args) /*empty*/
+# define DprintQ(cond, args, query, size) /*empty*/
+# define Aerror(file, string, error, address) /*empty*/
+# define Perror(file, string, error) /*empty*/
+#else
+# define Dprint(cond, args) if (cond) {fprintf args;} else {}
+# define DprintQ(cond, args, query, size) if (cond) {\
+ fprintf args;\
+ __fp_nquery(query, size, stdout);\
+ } else {}
+ static void
+ Aerror(
+ FILE *file,
+ char *string,
+ int error,
+ struct sockaddr_in address)
+ {
+ int save = errno;
+
+ if (_res.options & RES_DEBUG) {
+ fprintf(file, "res_send: %s ([%s].%u): %s\n",
+ string,
+ inet_ntoa(address.sin_addr),
+ ntohs(address.sin_port),
+ strerror(error));
+ }
+ errno = save;
+ }
+ static void
+ Perror(
+ FILE *file,
+ char *string,
+ int error)
+ {
+ int save = errno;
+
+ if (_res.options & RES_DEBUG) {
+ fprintf(file, "res_send: %s: %s\n",
+ string, strerror(error));
+ }
+ errno = save;
+ }
+#endif
+
+void
+res_send_setqhook(
+ res_send_qhook hook)
+{
+
+ Qhook = hook;
+}
+
+void
+res_send_setrhook(
+ res_send_rhook hook)
+{
+
+ Rhook = hook;
+}
+
+/* int
+ * res_isourserver(ina)
+ * looks up "ina" in _res.ns_addr_list[]
+ * returns:
+ * 0 : not found
+ * >0 : found
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_isourserver(
+ const struct sockaddr_in *inp)
+{
+ struct sockaddr_in ina;
+ int ns, ret;
+
+ ina = *inp;
+ ret = 0;
+ for (ns = 0; ns < _res.nscount; ns++) {
+ const struct sockaddr_in *srv = &_res.nsaddr_list[ns];
+
+ if (srv->sin_family == ina.sin_family &&
+ srv->sin_port == ina.sin_port &&
+ (srv->sin_addr.s_addr == INADDR_ANY ||
+ srv->sin_addr.s_addr == ina.sin_addr.s_addr)) {
+ ret++;
+ break;
+ }
+ }
+ return (ret);
+}
+
+/* int
+ * res_nameinquery(name, type, class, buf, eom)
+ * look for (name,type,class) in the query section of packet (buf,eom)
+ * requires:
+ * buf + HFIXEDSZ <= eom
+ * returns:
+ * -1 : format error
+ * 0 : not found
+ * >0 : found
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_nameinquery(
+ const char *name,
+ int type, int class,
+ const u_char *buf, const u_char *eom)
+{
+ const u_char *cp = buf + HFIXEDSZ;
+ int qdcount = ntohs(((HEADER*)buf)->qdcount);
+
+ while (qdcount-- > 0) {
+ char tname[MAXDNAME+1];
+ int n, ttype, tclass;
+
+ n = dn_expand(buf, eom, cp, tname, sizeof tname);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ if (cp + 2 * INT16SZ > eom)
+ return (-1);
+ ttype = ns_get16(cp); cp += INT16SZ;
+ tclass = ns_get16(cp); cp += INT16SZ;
+ if (ttype == type &&
+ tclass == class &&
+ strcasecmp(tname, name) == 0)
+ return (1);
+ }
+ return (0);
+}
+
+/* int
+ * res_queriesmatch(buf1, eom1, buf2, eom2)
+ * is there a 1:1 mapping of (name,type,class)
+ * in (buf1,eom1) and (buf2,eom2)?
+ * returns:
+ * -1 : format error
+ * 0 : not a 1:1 mapping
+ * >0 : is a 1:1 mapping
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_queriesmatch(
+ const u_char *buf1, const u_char *eom1,
+ const u_char *buf2, const u_char *eom2)
+{
+ const u_char *cp = buf1 + HFIXEDSZ;
+ int qdcount = ntohs(((HEADER*)buf1)->qdcount);
+
+ if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
+ return (-1);
+
+ /*
+ * Only header section present in replies to
+ * dynamic update packets.
+ */
+ if ( (((HEADER *)buf1)->opcode == ns_o_update) &&
+ (((HEADER *)buf2)->opcode == ns_o_update) )
+ return (1);
+
+ if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
+ return (0);
+ while (qdcount-- > 0) {
+ char tname[MAXDNAME+1];
+ int n, ttype, tclass;
+
+ n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ if (cp + 2 * INT16SZ > eom1)
+ return (-1);
+ ttype = ns_get16(cp); cp += INT16SZ;
+ tclass = ns_get16(cp); cp += INT16SZ;
+ if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
+ return (0);
+ }
+ return (1);
+}
+
+int
+res_send(
+ const u_char *buf,
+ int buflen,
+ u_char *ans,
+ int anssiz)
+{
+ HEADER *hp = (HEADER *) buf;
+ HEADER *anhp = (HEADER *) ans;
+ int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns, n;
+ u_int badns; /* XXX NSMAX can't exceed #/bits in this variable */
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ /* errno should have been set by res_init() in this case. */
+ return (-1);
+ }
+ if (anssiz < HFIXEDSZ) {
+ errno = EINVAL;
+ return (-1);
+ }
+ DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
+ (stdout, ";; res_send()\n"), buf, buflen);
+ v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
+ gotsomewhere = 0;
+ connreset = 0;
+ terrno = ETIMEDOUT;
+ badns = 0;
+
+ /*
+ * Send request, RETRY times, or until successful
+ */
+ for (try = 0; try < _res.retry; try++) {
+ for (ns = 0; ns < _res.nscount; ns++) {
+ struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
+ same_ns:
+ if (badns & (1 << ns)) {
+ res_close();
+ goto next_ns;
+ }
+
+ if (Qhook) {
+ int done = 0, loops = 0;
+
+ do {
+ res_sendhookact act;
+
+ act = (*Qhook)(&nsap, &buf, &buflen,
+ ans, anssiz, &resplen);
+ switch (act) {
+ case res_goahead:
+ done = 1;
+ break;
+ case res_nextns:
+ res_close();
+ goto next_ns;
+ case res_done:
+ return (resplen);
+ case res_modified:
+ /* give the hook another try */
+ if (++loops < 42) /*doug adams*/
+ break;
+ /*FALLTHROUGH*/
+ case res_error:
+ /*FALLTHROUGH*/
+ default:
+ return (-1);
+ }
+ } while (!done);
+ }
+
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; Querying server (# %d) address = %s\n",
+ ns + 1, inet_ntoa(nsap->sin_addr)));
+
+ if (v_circuit) {
+ int truncated;
+#if defined(USE_WRITEV)
+ struct iovec iov[2];
+#endif
+ u_short len;
+ u_char *cp;
+
+ /*
+ * Use virtual circuit;
+ * at most one attempt per server.
+ */
+ try = _res.retry;
+ truncated = 0;
+ if (s < 0 || !vc || hp->opcode == ns_o_update) {
+ if (s >= 0)
+ res_close();
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+ terrno = errno;
+ Perror(stderr, "socket(vc)", errno);
+ return (-1);
+ }
+ errno = 0;
+ if (connect(s, (struct sockaddr *)nsap,
+ sizeof *nsap) < 0) {
+ terrno = errno;
+ Aerror(stderr, "connect/vc",
+ errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ vc = 1;
+ }
+ /*
+ * Send length & message
+ */
+ putshort((u_short)buflen, (u_char*)&len);
+#if defined(USE_WRITEV)
+ iov[0].iov_base = (caddr_t)&len;
+ iov[0].iov_len = INT16SZ;
+ iov[1].iov_base = (caddr_t)buf;
+ iov[1].iov_len = buflen;
+ if (writev(s, iov, 2) != (INT16SZ + buflen)) {
+#else
+ /*
+ * RTEMS doesn't have writev (yet)
+ */
+ if ((write (s, &len, INT16SZ) != INT16SZ)
+ || (write (s, buf, buflen) != buflen)) {
+#endif
+ terrno = errno;
+ Perror(stderr, "write failed", errno);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ /*
+ * Receive length & response
+ */
+read_len:
+ cp = ans;
+ len = INT16SZ;
+ while ((n = read(s, (char *)cp, (int)len)) > 0) {
+ cp += n;
+ if ((len -= n) <= 0)
+ break;
+ }
+ if (n <= 0) {
+ terrno = errno;
+ Perror(stderr, "read failed", errno);
+ res_close();
+ /*
+ * A long running process might get its TCP
+ * connection reset if the remote server was
+ * restarted. Requery the server instead of
+ * trying a new one. When there is only one
+ * server, this means that a query might work
+ * instead of failing. We only allow one reset
+ * per query to prevent looping.
+ */
+ if (terrno == ECONNRESET && !connreset) {
+ connreset = 1;
+ res_close();
+ goto same_ns;
+ }
+ res_close();
+ goto next_ns;
+ }
+ resplen = ns_get16(ans);
+ if (resplen > anssiz) {
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; response truncated\n")
+ );
+ truncated = 1;
+ len = anssiz;
+ } else
+ len = resplen;
+ if (len < HFIXEDSZ) {
+ /*
+ * Undersized message.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; undersized: %d\n", len));
+ terrno = EMSGSIZE;
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ cp = ans;
+ while (len != 0 &&
+ (n = read(s, (char *)cp, (int)len)) > 0) {
+ cp += n;
+ len -= n;
+ }
+ if (n <= 0) {
+ terrno = errno;
+ Perror(stderr, "read(vc)", errno);
+ res_close();
+ goto next_ns;
+ }
+ if (truncated) {
+ /*
+ * Flush rest of answer
+ * so connection stays in synch.
+ */
+ anhp->tc = 1;
+ len = resplen - anssiz;
+ while (len != 0) {
+ char junk[PACKETSZ];
+
+ n = (len > sizeof(junk)
+ ? sizeof(junk)
+ : len);
+ if ((n = read(s, junk, n)) > 0)
+ len -= n;
+ else
+ break;
+ }
+ }
+ /*
+ * The calling applicating has bailed out of
+ * a previous call and failed to arrange to have
+ * the circuit closed or the server has got
+ * itself confused. Anyway drop the packet and
+ * wait for the correct one.
+ */
+ if (hp->id != anhp->id) {
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer (unexpected):\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto read_len;
+ }
+ } else {
+ /*
+ * Use datagrams.
+ */
+#ifndef NOPOLL
+ struct pollfd pfd;
+ int msec;
+#endif
+ struct timeval timeout;
+#ifndef NOSELECT
+ fd_set dsmask, *dsmaskp;
+ int dsmasklen;
+#endif
+ struct sockaddr_in from;
+ socklen_t fromlen;
+
+ if ((s < 0) || vc) {
+ if (vc)
+ res_close();
+ s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0) {
+#ifndef CAN_RECONNECT
+ bad_dg_sock:
+#endif
+ terrno = errno;
+ Perror(stderr, "socket(dg)", errno);
+ return (-1);
+ }
+ connected = 0;
+ }
+#ifndef CANNOT_CONNECT_DGRAM
+ /*
+ * On a 4.3BSD+ machine (client and server,
+ * actually), sending to a nameserver datagram
+ * port with no nameserver will cause an
+ * ICMP port unreachable message to be returned.
+ * If our datagram socket is "connected" to the
+ * server, we get an ECONNREFUSED error on the next
+ * socket operation, and select returns if the
+ * error message is received. We can thus detect
+ * the absence of a nameserver without timing out.
+ * If we have sent queries to at least two servers,
+ * however, we don't want to remain connected,
+ * as we wish to receive answers from the first
+ * server to respond.
+ */
+ if (_res.nscount == 1 || (try == 0 && ns == 0)) {
+ /*
+ * Connect only if we are sure we won't
+ * receive a response from another server.
+ */
+ if (!connected) {
+ if (connect(s, (struct sockaddr *)nsap,
+ sizeof *nsap
+ ) < 0) {
+ Aerror(stderr,
+ "connect(dg)",
+ errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ connected = 1;
+ }
+ if (send(s, (char*)buf, buflen, 0) != buflen) {
+ Perror(stderr, "send", errno);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ } else {
+ /*
+ * Disconnect if we want to listen
+ * for responses from more than one server.
+ */
+ if (connected) {
+#ifdef CAN_RECONNECT
+ struct sockaddr_in no_addr;
+
+ no_addr.sin_family = AF_INET;
+ no_addr.sin_addr.s_addr = INADDR_ANY;
+ no_addr.sin_port = 0;
+ (void) connect(s,
+ (struct sockaddr *)
+ &no_addr,
+ sizeof no_addr);
+#else
+ int s1 = socket(PF_INET, SOCK_DGRAM,0);
+ if (s1 < 0)
+ goto bad_dg_sock;
+ (void) dup2(s1, s);
+ (void) close(s1);
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; new DG socket\n"))
+#endif /* CAN_RECONNECT */
+ connected = 0;
+ errno = 0;
+ }
+#endif /* !CANNOT_CONNECT_DGRAM */
+ if (sendto(s, (char*)buf, buflen, 0,
+ (struct sockaddr *)nsap,
+ sizeof *nsap)
+ != buflen) {
+ Aerror(stderr, "sendto", errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+#ifndef CANNOT_CONNECT_DGRAM
+ }
+#endif /* !CANNOT_CONNECT_DGRAM */
+
+ /*
+ * Wait for reply
+ */
+#ifndef NOPOLL
+ othersyscall:
+ if (use_poll) {
+ msec = (_res.retrans << try) * 1000;
+ if (try > 0)
+ msec /= _res.nscount;
+ if (msec <= 0)
+ msec = 1000;
+ } else {
+#endif
+ timeout.tv_sec = (_res.retrans << try);
+ if (try > 0)
+ timeout.tv_sec /= _res.nscount;
+ if ((long) timeout.tv_sec <= 0)
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+#ifndef NOPOLL
+ }
+#endif
+ wait:
+ if (s < 0) {
+ Perror(stderr, "s out-of-bounds", EMFILE);
+ res_close();
+ goto next_ns;
+ }
+#ifndef NOPOLL
+ if (use_poll) {
+ struct sigaction sa, osa;
+ int sigsys_installed = 0;
+
+ pfd.fd = s;
+ pfd.events = POLLIN;
+ if (use_poll == 1) {
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = SIG_IGN;
+ if (sigaction(SIGSYS, &sa, &osa) >= 0)
+ sigsys_installed = 1;
+ }
+ n = poll(&pfd, 1, msec);
+ if (sigsys_installed == 1) {
+ int oerrno = errno;
+ sigaction(SIGSYS, &osa, NULL);
+ errno = oerrno;
+ }
+ /* XXX why does nosys() return EINVAL? */
+ if (n < 0 && (errno == ENOSYS ||
+ errno == EINVAL)) {
+ use_poll = 0;
+ goto othersyscall;
+ } else if (use_poll == 1)
+ use_poll = 2;
+ if (n < 0) {
+ if (errno == EINTR)
+ goto wait;
+ Perror(stderr, "poll", errno);
+ res_close();
+ goto next_ns;
+ }
+ } else {
+#endif
+#ifndef NOSELECT
+ dsmasklen = howmany(s + 1, NFDBITS) *
+ sizeof(fd_mask);
+ if (dsmasklen > sizeof(fd_set)) {
+ dsmaskp = (fd_set *)malloc(dsmasklen);
+ if (dsmaskp == NULL) {
+ res_close();
+ goto next_ns;
+ }
+ } else
+ dsmaskp = &dsmask;
+ /* only zero what we need */
+ bzero((char *)dsmaskp, dsmasklen);
+ FD_SET(s, dsmaskp);
+ n = select(s + 1, dsmaskp, (fd_set *)NULL,
+ (fd_set *)NULL, &timeout);
+ if (dsmaskp != &dsmask)
+ free(dsmaskp);
+ if (n < 0) {
+ if (errno == EINTR)
+ goto wait;
+ Perror(stderr, "select", errno);
+ res_close();
+ goto next_ns;
+ }
+#endif
+#ifndef NOPOLL
+ }
+#endif
+
+#ifdef NOSELECT
+ setsockopt (s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout);
+#else
+ if (n == 0) {
+ /*
+ * timeout
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; timeout\n"));
+ gotsomewhere = 1;
+ res_close();
+ goto next_ns;
+ }
+#endif
+ errno = 0;
+ fromlen = sizeof(struct sockaddr_in);
+ resplen = recvfrom(s, (char*)ans, anssiz, 0,
+ (struct sockaddr *)&from, &fromlen);
+ if (resplen <= 0) {
+#ifdef NOSELECT
+ if (errno == ETIMEDOUT) {
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; timeout\n"));
+ gotsomewhere = 1;
+ res_close();
+ goto next_ns;
+ }
+#endif
+ Perror(stderr, "recvfrom", errno);
+ res_close();
+ goto next_ns;
+ }
+ gotsomewhere = 1;
+ if (resplen < HFIXEDSZ) {
+ /*
+ * Undersized message.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; undersized: %d\n",
+ resplen));
+ terrno = EMSGSIZE;
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ if (hp->id != anhp->id) {
+ /*
+ * response from old query, ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+#ifdef CHECK_SRVR_ADDR
+ if (!(_res.options & RES_INSECURE1) &&
+ !res_isourserver(&from)) {
+ /*
+ * response from wrong server? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; not our server:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+#endif
+ if (!(_res.options & RES_INSECURE2) &&
+ !res_queriesmatch(buf, buf + buflen,
+ ans, ans + anssiz)) {
+ /*
+ * response contains wrong query? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; wrong query name:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+ if (anhp->rcode == SERVFAIL ||
+ anhp->rcode == NOTIMP ||
+ anhp->rcode == REFUSED) {
+ DprintQ(_res.options & RES_DEBUG,
+ (stdout, "server rejected query:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ badns |= (1 << ns);
+ res_close();
+ /* don't retry if called from dig */
+ if (!_res.pfcode)
+ goto next_ns;
+ }
+ if (!(_res.options & RES_IGNTC) && anhp->tc) {
+ /*
+ * get rest of answer;
+ * use TCP with same server.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; truncated answer\n"));
+ v_circuit = 1;
+ res_close();
+ goto same_ns;
+ }
+ } /*if vc/dg*/
+ Dprint((_res.options & RES_DEBUG) ||
+ ((_res.pfcode & RES_PRF_REPLY) &&
+ (_res.pfcode & RES_PRF_HEAD1)),
+ (stdout, ";; got answer:\n"));
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, "%s", ""),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ /*
+ * If using virtual circuits, we assume that the first server
+ * is preferred over the rest (i.e. it is on the local
+ * machine) and only keep that one open.
+ * If we have temporarily opened a virtual circuit,
+ * or if we haven't been asked to keep a socket open,
+ * close the socket.
+ */
+ if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
+ !(_res.options & RES_STAYOPEN)) {
+ res_close();
+ }
+ if (Rhook) {
+ int done = 0, loops = 0;
+
+ do {
+ res_sendhookact act;
+
+ act = (*Rhook)(nsap, buf, buflen,
+ ans, anssiz, &resplen);
+ switch (act) {
+ case res_goahead:
+ case res_done:
+ done = 1;
+ break;
+ case res_nextns:
+ res_close();
+ goto next_ns;
+ case res_modified:
+ /* give the hook another try */
+ if (++loops < 42) /*doug adams*/
+ break;
+ /*FALLTHROUGH*/
+ case res_error:
+ /*FALLTHROUGH*/
+ default:
+ return (-1);
+ }
+ } while (!done);
+
+ }
+ return (resplen);
+ next_ns: ;
+ } /*foreach ns*/
+ } /*foreach retry*/
+ res_close();
+ if (!v_circuit) {
+ if (!gotsomewhere)
+ errno = ECONNREFUSED; /* no nameservers found */
+ else
+ errno = ETIMEDOUT; /* no answer obtained */
+ } else
+ errno = terrno;
+ return (-1);
+}
+
+/*
+ * This routine is for closing the socket if a virtual circuit is used and
+ * the program wants to close it. This provides support for endhostent()
+ * which expects to close the socket.
+ *
+ * This routine is not expected to be user visible.
+ */
+void
+res_close(void)
+{
+ if (s >= 0) {
+ (void) close(s);
+ s = -1;
+ connected = 0;
+ vc = 0;
+ }
+}
diff --git a/cpukit/libnetworking/libc/res_stubs.c b/cpukit/libnetworking/libc/res_stubs.c
new file mode 100644
index 0000000000..5bb415a94c
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_stubs.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 1996 Peter Wemm <peter@freebsd.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+/*
+ * This file is for FreeBSD-3.0 that has a bind-4.9.5-P1 derived
+ * resolver in the libc. It provides aliases for functions that
+ * have moved since 4.9.4-P1.
+ *
+ * I'll save everybody the trouble and say it now: *THIS IS A HACK*!
+ *
+ * Yes, many of these are private functions to the resolver, but some are
+ * needed as there is no other way to provide the functionality and they've
+ * turned up all over the place. :-(
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <rtems/bsd/sys/cdefs.h>
+
+__weak_reference(__inet_addr, inet_addr);
+__weak_reference(__inet_aton, inet_aton);
+__weak_reference(__inet_lnaof, inet_lnaof);
+__weak_reference(__inet_makeaddr, inet_makeaddr);
+__weak_reference(__inet_neta, inet_neta);
+__weak_reference(__inet_netof, inet_netof);
+__weak_reference(__inet_network, inet_network);
+__weak_reference(__inet_net_ntop, inet_net_ntop);
+__weak_reference(__inet_net_pton, inet_net_pton);
+__weak_reference(__inet_ntoa, inet_ntoa);
+__weak_reference(__inet_pton, inet_pton);
+__weak_reference(__inet_ntop, inet_ntop);
+__weak_reference(__inet_nsap_addr, inet_nsap_addr);
+__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa);
+
+__weak_reference(__sym_ston, sym_ston);
+__weak_reference(__sym_ntos, sym_ntos);
+__weak_reference(__sym_ntop, sym_ntop);
+__weak_reference(__fp_resstat, fp_resstat);
+__weak_reference(__p_query, p_query);
+__weak_reference(__p_fqnname, p_fqnname);
+__weak_reference(__p_secstodate, p_secstodate);
+__weak_reference(__dn_count_labels, dn_count_labels);
+__weak_reference(__dn_comp, dn_comp);
+__weak_reference(__res_close, _res_close);
+__weak_reference(__dn_expand, dn_expand);
+__weak_reference(__res_init, res_init);
+__weak_reference(__res_query, res_query);
+__weak_reference(__res_search, res_search);
+__weak_reference(__res_querydomain, res_querydomain);
+__weak_reference(__res_mkquery, res_mkquery);
+__weak_reference(__res_send, res_send);
diff --git a/cpukit/libnetworking/libc/res_update.c b/cpukit/libnetworking/libc/res_update.c
new file mode 100644
index 0000000000..85c55694fe
--- /dev/null
+++ b/cpukit/libnetworking/libc/res_update.c
@@ -0,0 +1,519 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Based on the Dynamic DNS reference implementation by Viraj Bais
+ * <viraj_bais@ccm.fm.intel.com>
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+/*
+ * Separate a linked list of records into groups so that all records
+ * in a group will belong to a single zone on the nameserver.
+ * Create a dynamic update packet for each zone and send it to the
+ * nameservers for that zone, and await answer.
+ * Abort if error occurs in updating any zone.
+ * Return the number of zones updated on success, < 0 on error.
+ *
+ * On error, caller must deal with the unsynchronized zones
+ * eg. an A record might have been successfully added to the forward
+ * zone but the corresponding PTR record would be missing if error
+ * was encountered while updating the reverse zone.
+ */
+
+#define NSMAX 16
+
+struct ns1 {
+ char nsname[MAXDNAME];
+ struct in_addr nsaddr1;
+};
+
+struct zonegrp {
+ char z_origin[MAXDNAME];
+ int16_t z_class;
+ char z_soardata[MAXDNAME + 5 * INT32SZ];
+ struct ns1 z_ns[NSMAX];
+ int z_nscount;
+ ns_updrec * z_rr;
+ struct zonegrp *z_next;
+};
+
+
+int
+res_update(ns_updrec *rrecp_in) {
+ ns_updrec *rrecp, *tmprrecp;
+ u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ];
+ char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME],
+ mailaddr[MAXDNAME];
+ u_char soardata[2*MAXCDNAME+5*INT32SZ];
+ char *dname, *svdname, *cp1, *target;
+ u_char *cp, *eom;
+ HEADER *hp = (HEADER *) answer;
+ struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL;
+ int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize,
+ newgroup, done, myzone, seen_before, numzones = 0;
+ u_int16_t dlen, class, qclass, type, qtype;
+ u_int32_t ttl;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+
+ for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) {
+ dname = rrecp->r_dname;
+ n = strlen(dname);
+ if (dname[n-1] == '.')
+ dname[n-1] = '\0';
+ qtype = T_SOA;
+ qclass = rrecp->r_class;
+ done = 0;
+ seen_before = 0;
+
+ while (!done && dname) {
+ if (qtype == T_SOA) {
+ for (tmpzptr = zgrp_start;
+ tmpzptr && !seen_before;
+ tmpzptr = tmpzptr->z_next) {
+ if (strcasecmp(dname,
+ tmpzptr->z_origin) == 0 &&
+ tmpzptr->z_class == qclass)
+ seen_before++;
+ for (tmprrecp = tmpzptr->z_rr;
+ tmprrecp && !seen_before;
+ tmprrecp = tmprrecp->r_grpnext)
+ if (strcasecmp(dname, tmprrecp->r_dname) == 0
+ && tmprrecp->r_class == qclass) {
+ seen_before++;
+ break;
+ }
+ if (seen_before) {
+ /*
+ * Append to the end of
+ * current group.
+ */
+ for (tmprrecp = tmpzptr->z_rr;
+ tmprrecp->r_grpnext;
+ tmprrecp = tmprrecp->r_grpnext)
+ (void)NULL;
+ tmprrecp->r_grpnext = rrecp;
+ rrecp->r_grpnext = NULL;
+ done = 1;
+ break;
+ }
+ }
+ } else if (qtype == T_A) {
+ for (tmpzptr = zgrp_start;
+ tmpzptr && !done;
+ tmpzptr = tmpzptr->z_next)
+ for (i = 0; i < tmpzptr->z_nscount; i++)
+ if (tmpzptr->z_class == qclass &&
+ strcasecmp(tmpzptr->z_ns[i].nsname,
+ dname) == 0 &&
+ tmpzptr->z_ns[i].nsaddr1.s_addr != 0) {
+ zptr->z_ns[k].nsaddr1.s_addr =
+ tmpzptr->z_ns[i].nsaddr1.s_addr;
+ done = 1;
+ break;
+ }
+ }
+ if (done)
+ break;
+ n = res_mkquery(QUERY, dname, qclass, qtype, NULL,
+ 0, NULL, buf, sizeof buf);
+ if (n <= 0) {
+ fprintf(stderr, "res_update: mkquery failed\n");
+ return (n);
+ }
+ n = res_send(buf, n, answer, sizeof answer);
+ if (n < 0) {
+ fprintf(stderr, "res_update: send error for %s\n",
+ rrecp->r_dname);
+ return (n);
+ }
+ if (n < HFIXEDSZ)
+ return (-1);
+ ancount = ntohs(hp->ancount);
+ nscount = ntohs(hp->nscount);
+ arcount = ntohs(hp->arcount);
+ rcode = hp->rcode;
+ cp = answer + HFIXEDSZ;
+ eom = answer + n;
+ /* skip the question section */
+ n = dn_skipname(cp, eom);
+ if (n < 0 || cp + n + 2 * INT16SZ > eom)
+ return (-1);
+ cp += n + 2 * INT16SZ;
+
+ if (qtype == T_SOA) {
+ if (ancount == 0 && nscount == 0 && arcount == 0) {
+ /*
+ * if (rcode == NOERROR) then the dname exists but
+ * has no soa record associated with it.
+ * if (rcode == NXDOMAIN) then the dname does not
+ * exist and the server is replying out of NCACHE.
+ * in either case, proceed with the next try
+ */
+ dname = strchr(dname, '.');
+ if (dname != NULL)
+ dname++;
+ continue;
+ } else if ((rcode == NOERROR || rcode == NXDOMAIN) &&
+ ancount == 0 &&
+ nscount == 1 && arcount == 0) {
+ /*
+ * name/data does not exist, soa record supplied in the
+ * authority section
+ */
+ /* authority section must contain the soa record */
+ if ((n = dn_expand(answer, eom, cp, zname,
+ sizeof zname)) < 0)
+ return (n);
+ cp += n;
+ if (cp + 2 * INT16SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ if (type != T_SOA || class != qclass) {
+ fprintf(stderr, "unknown answer\n");
+ return (-1);
+ }
+ myzone = 0;
+ svdname = dname;
+ while (dname)
+ if (strcasecmp(dname, zname) == 0) {
+ myzone = 1;
+ break;
+ } else if ((dname = strchr(dname, '.')) != NULL)
+ dname++;
+ if (!myzone) {
+ dname = strchr(svdname, '.');
+ if (dname != NULL)
+ dname++;
+ continue;
+ }
+ nscount = 0;
+ /* fallthrough */
+ } else if (rcode == NOERROR && ancount == 1) {
+ /*
+ * found the zone name
+ * new servers will supply NS records for the zone
+ * in authority section and A records for those
+ * nameservers in the additional section
+ * older servers have to be explicitly queried for
+ * NS records for the zone
+ */
+ /* answer section must contain the soa record */
+ if ((n = dn_expand(answer, eom, cp, zname,
+ sizeof zname)) < 0)
+ return (n);
+ else
+ cp += n;
+ if (cp + 2 * INT16SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ if (type == T_CNAME) {
+ dname = strchr(dname, '.');
+ if (dname != NULL)
+ dname++;
+ continue;
+ }
+ if (strcasecmp(dname, zname) != 0 ||
+ type != T_SOA ||
+ class != rrecp->r_class) {
+ fprintf(stderr, "unknown answer\n");
+ return (-1);
+ }
+ /* FALLTHROUGH */
+ } else {
+ fprintf(stderr,
+ "unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
+ ancount, nscount, arcount, hp->rcode);
+ return (-1);
+ }
+ if (cp + INT32SZ + INT16SZ > eom)
+ return (-1);
+ /* continue processing the soa record */
+ GETLONG(ttl, cp);
+ GETSHORT(dlen, cp);
+ if (cp + dlen > eom)
+ return (-1);
+ newgroup = 1;
+ zptr = zgrp_start;
+ prevzptr = NULL;
+ while (zptr) {
+ if (strcasecmp(zname, zptr->z_origin) == 0 &&
+ type == T_SOA && class == qclass) {
+ newgroup = 0;
+ break;
+ }
+ prevzptr = zptr;
+ zptr = zptr->z_next;
+ }
+ if (!newgroup) {
+ for (tmprrecp = zptr->z_rr;
+ tmprrecp->r_grpnext;
+ tmprrecp = tmprrecp->r_grpnext)
+ ;
+ tmprrecp->r_grpnext = rrecp;
+ rrecp->r_grpnext = NULL;
+ done = 1;
+ cp += dlen;
+ break;
+ } else {
+ if ((n = dn_expand(answer, eom, cp, primary,
+ sizeof primary)) < 0)
+ return (n);
+ cp += n;
+ /*
+ * We don't have to bounds check here because the
+ * next use of 'cp' is in dn_expand().
+ */
+ cp1 = (char *)soardata;
+ strcpy(cp1, primary);
+ cp1 += strlen(cp1) + 1;
+ if ((n = dn_expand(answer, eom, cp, mailaddr,
+ sizeof mailaddr)) < 0)
+ return (n);
+ cp += n;
+ strcpy(cp1, mailaddr);
+ cp1 += strlen(cp1) + 1;
+ if (cp + 5*INT32SZ > eom)
+ return (-1);
+ memcpy(cp1, cp, 5*INT32SZ);
+ cp += 5*INT32SZ;
+ cp1 += 5*INT32SZ;
+ rdatasize = (u_char *)cp1 - soardata;
+ zptr = calloc(1, sizeof(struct zonegrp));
+ if (zptr == NULL)
+ return (-1);
+ if (zgrp_start == NULL)
+ zgrp_start = zptr;
+ else
+ prevzptr->z_next = zptr;
+ zptr->z_rr = rrecp;
+ rrecp->r_grpnext = NULL;
+ strcpy(zptr->z_origin, zname);
+ zptr->z_class = class;
+ memcpy(zptr->z_soardata, soardata, rdatasize);
+ /* fallthrough to process NS and A records */
+ }
+ } else if (qtype == T_NS) {
+ if (rcode == NOERROR && ancount > 0) {
+ strcpy(zname, dname);
+ for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
+ if (strcasecmp(zname, zptr->z_origin) == 0)
+ break;
+ }
+ if (zptr == NULL)
+ /* should not happen */
+ return (-1);
+ if (nscount > 0) {
+ /*
+ * answer and authority sections contain
+ * the same information, skip answer section
+ */
+ for (j = 0; j < ancount; j++) {
+ n = dn_skipname(cp, eom);
+ if (n < 0)
+ return (-1);
+ n += 2*INT16SZ + INT32SZ;
+ if (cp + n + INT16SZ > eom)
+ return (-1);
+ cp += n;
+ GETSHORT(dlen, cp);
+ cp += dlen;
+ }
+ } else
+ nscount = ancount;
+ /* fallthrough to process NS and A records */
+ } else {
+ fprintf(stderr, "cannot determine nameservers for %s:\
+ans=%d, auth=%d, add=%d, rcode=%d\n",
+ dname, ancount, nscount, arcount, hp->rcode);
+ return (-1);
+ }
+ } else if (qtype == T_A) {
+ if (rcode == NOERROR && ancount > 0) {
+ arcount = ancount;
+ ancount = nscount = 0;
+ /* fallthrough to process A records */
+ } else {
+ fprintf(stderr, "cannot determine address for %s:\
+ans=%d, auth=%d, add=%d, rcode=%d\n",
+ dname, ancount, nscount, arcount, hp->rcode);
+ return (-1);
+ }
+ }
+ /* process NS records for the zone */
+ j = 0;
+ for (i = 0; i < nscount; i++) {
+ if ((n = dn_expand(answer, eom, cp, name,
+ sizeof name)) < 0)
+ return (n);
+ cp += n;
+ if (cp + 3 * INT16SZ + INT32SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ GETLONG(ttl, cp);
+ GETSHORT(dlen, cp);
+ if (cp + dlen > eom)
+ return (-1);
+ if (strcasecmp(name, zname) == 0 &&
+ type == T_NS && class == qclass) {
+ if ((n = dn_expand(answer, eom, cp,
+ name, sizeof name)) < 0)
+ return (n);
+ target = zptr->z_ns[j++].nsname;
+ strcpy(target, name);
+ }
+ cp += dlen;
+ }
+ if (zptr->z_nscount == 0)
+ zptr->z_nscount = j;
+ /* get addresses for the nameservers */
+ for (i = 0; i < arcount; i++) {
+ if ((n = dn_expand(answer, eom, cp, name,
+ sizeof name)) < 0)
+ return (n);
+ cp += n;
+ if (cp + 3 * INT16SZ + INT32SZ > eom)
+ return (-1);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ GETLONG(ttl, cp);
+ GETSHORT(dlen, cp);
+ if (cp + dlen > eom)
+ return (-1);
+ if (type == T_A && dlen == INT32SZ && class == qclass) {
+ for (j = 0; j < zptr->z_nscount; j++)
+ if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) {
+ memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp,
+ INT32SZ);
+ break;
+ }
+ }
+ cp += dlen;
+ }
+ if (zptr->z_nscount == 0) {
+ dname = zname;
+ qtype = T_NS;
+ continue;
+ }
+ done = 1;
+ for (k = 0; k < zptr->z_nscount; k++)
+ if (zptr->z_ns[k].nsaddr1.s_addr == 0) {
+ done = 0;
+ dname = zptr->z_ns[k].nsname;
+ qtype = T_A;
+ }
+
+ } /* while */
+ }
+
+ _res.options |= RES_DEBUG;
+ for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
+
+ /* append zone section */
+ rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
+ zptr->z_class, ns_t_soa, 0);
+ if (rrecp == NULL) {
+ fprintf(stderr, "saverrec error\n");
+ fflush(stderr);
+ return (-1);
+ }
+ rrecp->r_grpnext = zptr->z_rr;
+ zptr->z_rr = rrecp;
+
+ n = res_mkupdate(zptr->z_rr, packet, sizeof packet);
+ if (n < 0) {
+ fprintf(stderr, "res_mkupdate error\n");
+ fflush(stderr);
+ return (-1);
+ } else
+ fprintf(stdout, "res_mkupdate: packet size = %d\n", n);
+
+ /*
+ * Override the list of NS records from res_init() with
+ * the authoritative nameservers for the zone being updated.
+ * Sort primary to be the first in the list of nameservers.
+ */
+ for (i = 0; i < zptr->z_nscount; i++) {
+ if (strcasecmp(zptr->z_ns[i].nsname,
+ zptr->z_soardata) == 0) {
+ struct in_addr tmpaddr;
+
+ if (i != 0) {
+ strcpy(zptr->z_ns[i].nsname,
+ zptr->z_ns[0].nsname);
+ strcpy(zptr->z_ns[0].nsname,
+ zptr->z_soardata);
+ tmpaddr = zptr->z_ns[i].nsaddr1;
+ zptr->z_ns[i].nsaddr1 =
+ zptr->z_ns[0].nsaddr1;
+ zptr->z_ns[0].nsaddr1 = tmpaddr;
+ }
+ break;
+ }
+ }
+ for (i = 0; i < MAXNS; i++) {
+ _res.nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1;
+ _res.nsaddr_list[i].sin_family = AF_INET;
+ _res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
+ }
+ _res.nscount = (zptr->z_nscount < MAXNS) ?
+ zptr->z_nscount : MAXNS;
+ n = res_send(packet, n, answer, sizeof(answer));
+ if (n < 0) {
+ fprintf(stderr, "res_send: send error, n=%d\n", n);
+ break;
+ } else
+ numzones++;
+ }
+
+ /* free malloc'ed memory */
+ while(zgrp_start) {
+ zptr = zgrp_start;
+ zgrp_start = zgrp_start->z_next;
+ res_freeupdrec(zptr->z_rr); /* Zone section we allocated. */
+ free((char *)zptr);
+ }
+
+ return (numzones);
+}
diff --git a/cpukit/libnetworking/libc/resolver.3 b/cpukit/libnetworking/libc/resolver.3
new file mode 100644
index 0000000000..8c6f18334f
--- /dev/null
+++ b/cpukit/libnetworking/libc/resolver.3
@@ -0,0 +1,352 @@
+.\" Copyright (c) 1985, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)resolver.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd June 4, 1993
+.Dt RESOLVER 3
+.Os BSD 4.3
+.Sh NAME
+.Nm res_query ,
+.Nm res_search ,
+.Nm res_mkquery ,
+.Nm res_send ,
+.Nm res_init ,
+.Nm dn_comp ,
+.Nm dn_expand
+.Nd resolver routines
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <netinet/in.h>
+.Fd #include <arpa/nameser.h>
+.Fd #include <resolv.h>
+.Ft int
+.Fo res_query
+.Fa "const char *dname"
+.Fa "int class"
+.Fa "int type"
+.Fa "u_char *answer"
+.Fa "int anslen"
+.Fc
+.Ft int
+.Fo res_search
+.Fa "const char *dname"
+.Fa "int class"
+.Fa "int type"
+.Fa "u_char *answer"
+.Fa "int anslen"
+.Fc
+.Ft int
+.Fo res_mkquery
+.Fa "int op"
+.Fa "const char *dname"
+.Fa "int class"
+.Fa "int type"
+.Fa "const u_char *data"
+.Fa "int datalen"
+.Fa "const u_char *newrr_in"
+.Fa "u_char *buf"
+.Fa "int buflen"
+.Fc
+.Ft int
+.Fo res_send
+.Fa "const u_char *msg"
+.Fa "int msglen"
+.Fa "u_char *answer"
+.Fa "int anslen"
+.Fc
+.Ft int
+.Fn res_init
+.Fo dn_comp
+.Fa "const char *exp_dn"
+.Fa "u_char *comp_dn"
+.Fa "int length"
+.Fa "u_char **dnptrs"
+.Fa "u_char **lastdnptr"
+.Fc
+.Ft int
+.Fo dn_expand
+.Fa "const u_char *msg"
+.Fa "const u_char *eomorig"
+.Fa "const u_char *comp_dn"
+.Fa "char *exp_dn"
+.Fa "int length"
+.Fc
+.Sh DESCRIPTION
+These routines are used for making, sending and interpreting
+query and reply messages with Internet domain name servers.
+.Pp
+Global configuration and state information that is used by the
+resolver routines is kept in the structure
+.Em _res .
+Most of the values have reasonable defaults and can be ignored.
+Options
+stored in
+.Em _res.options
+are defined in
+.Pa resolv.h
+and are as follows.
+Options are stored as a simple bit mask containing the bitwise ``or''
+of the options enabled.
+.Bl -tag -width RES_DEFNAMES
+.It Dv RES_INIT
+True if the initial name server address and default domain name are
+initialized (i.e.,
+.Fn res_init
+has been called).
+.It Dv RES_DEBUG
+Print debugging messages.
+.It Dv RES_AAONLY
+Accept authoritative answers only.
+With this option,
+.Fn res_send
+should continue until it finds an authoritative answer or finds an error.
+Currently this is not implemented.
+.It Dv RES_USEVC
+Use
+.Tn TCP
+connections for queries instead of
+.Tn UDP
+datagrams.
+.It Dv RES_STAYOPEN
+Used with
+.Dv RES_USEVC
+to keep the
+.Tn TCP
+connection open between
+queries.
+This is useful only in programs that regularly do many queries.
+.Tn UDP
+should be the normal mode used.
+.It Dv RES_IGNTC
+Unused currently (ignore truncation errors, i.e., don't retry with
+.Tn TCP ) .
+.It Dv RES_RECURSE
+Set the recursion-desired bit in queries.
+This is the default.
+.Pf ( Fn res_send
+does not do iterative queries and expects the name server
+to handle recursion.)
+.It Dv RES_DEFNAMES
+If set,
+.Fn res_search
+will append the default domain name to single-component names
+(those that do not contain a dot).
+This option is enabled by default.
+.It Dv RES_DNSRCH
+If this option is set,
+.Fn res_search
+will search for host names in the current domain and in parent domains; see
+.Xr hostname 7 .
+This is used by the standard host lookup routine
+.Xr gethostbyname 3 .
+This option is enabled by default.
+.It Dv RES_NOALIASES
+This option turns off the user level aliasing feature controlled by the
+.Dq Ev HOSTALIASES
+environment variable. Network daemons should set this option.
+.El
+.Pp
+The
+.Fn res_init
+routine
+reads the configuration file (if any; see
+.Xr resolver 5 )
+to get the default domain name,
+search list and
+the Internet address of the local name server(s).
+If no server is configured, the host running
+the resolver is tried.
+The current domain name is defined by the hostname
+if not specified in the configuration file;
+it can be overridden by the environment variable
+.Ev LOCALDOMAIN .
+This environment variable may contain several blank-separated
+tokens if you wish to override the
+.Em "search list"
+on a per-process basis. This is similar to the
+.Em search
+command in the configuration file.
+Another environment variable (
+.Dq Ev RES_OPTIONS
+can be set to
+override certain internal resolver options which are otherwise
+set by changing fields in the
+.Em _res
+structure or are inherited from the configuration file's
+.Em options
+command. The syntax of the
+.Dq Ev RES_OPTIONS
+environment variable is explained in
+.Xr resolver 5 .
+Initialization normally occurs on the first call
+to one of the following routines.
+.Pp
+The
+.Fn res_query
+function provides an interface to the server query mechanism.
+It constructs a query, sends it to the local server,
+awaits a response, and makes preliminary checks on the reply.
+The query requests information of the specified
+.Fa type
+and
+.Fa class
+for the specified fully-qualified domain name
+.Fa dname .
+The reply message is left in the
+.Fa answer
+buffer with length
+.Fa anslen
+supplied by the caller.
+.Pp
+The
+.Fn res_search
+routine makes a query and awaits a response like
+.Fn res_query ,
+but in addition, it implements the default and search rules
+controlled by the
+.Dv RES_DEFNAMES
+and
+.Dv RES_DNSRCH
+options.
+It returns the first successful reply.
+.Pp
+The remaining routines are lower-level routines used by
+.Fn res_query .
+The
+.Fn res_mkquery
+function
+constructs a standard query message and places it in
+.Fa buf .
+It returns the size of the query, or \-1 if the query is
+larger than
+.Fa buflen .
+The query type
+.Fa op
+is usually
+.Dv QUERY ,
+but can be any of the query types defined in
+.Aq Pa arpa/nameser.h .
+The domain name for the query is given by
+.Fa dname .
+.Fa Newrr
+is currently unused but is intended for making update messages.
+.Pp
+The
+.Fn res_send
+routine
+sends a pre-formatted query and returns an answer.
+It will call
+.Fn res_init
+if
+.Dv RES_INIT
+is not set, send the query to the local name server, and
+handle timeouts and retries.
+The length of the reply message is returned, or
+\-1 if there were errors.
+.Pp
+The
+.Fn dn_comp
+function
+compresses the domain name
+.Fa exp_dn
+and stores it in
+.Fa comp_dn .
+The size of the compressed name is returned or \-1 if there were errors.
+The size of the array pointed to by
+.Fa comp_dn
+is given by
+.Fa length .
+The compression uses
+an array of pointers
+.Fa dnptrs
+to previously-compressed names in the current message.
+The first pointer points to
+to the beginning of the message and the list ends with
+.Dv NULL .
+The limit to the array is specified by
+.Fa lastdnptr .
+A side effect of
+.Fn dn_comp
+is to update the list of pointers for
+labels inserted into the message
+as the name is compressed.
+If
+.Em dnptr
+is
+.Dv NULL, names are not compressed.
+If
+.Fa lastdnptr
+is
+.Dv NULL ,
+the list of labels is not updated.
+.Pp
+The
+.Fn dn_expand
+entry
+expands the compressed domain name
+.Fa comp_dn
+to a full domain name
+The compressed name is contained in a query or reply message;
+.Fa msg
+is a pointer to the beginning of the message.
+The uncompressed name is placed in the buffer indicated by
+.Fa exp_dn
+which is of size
+.Fa length .
+The size of compressed name is returned or \-1 if there was an error.
+.Sh FILES
+.Bl -tag -width Pa
+/etc/resolv.conf
+The configuration file
+see
+.Xr resolver 5 .
+.El
+.Sh SEE ALSO
+.Xr gethostbyname 3 ,
+.Xr resolver 5 ,
+.Xr hostname 7 ,
+.Xr named 8
+.Pp
+.%T RFC1032 ,
+.%T RFC1033 ,
+.%T RFC1034 ,
+.%T RFC1035 ,
+.%T RFC974
+.Rs
+.%T "Name Server Operations Guide for BIND"
+.Re
+.Sh HISTORY
+The
+.Nm
+function appeared in
+.Bx 4.3 .
diff --git a/cpukit/libnetworking/libc/send.c b/cpukit/libnetworking/libc/send.c
new file mode 100644
index 0000000000..cb112da515
--- /dev/null
+++ b/cpukit/libnetworking/libc/send.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stddef.h>
+
+ssize_t
+send(
+ int s,
+ const void *msg,
+ size_t len,
+ int flags )
+{
+ return (sendto(s, msg, len, flags, NULL, 0));
+}
diff --git a/cpukit/libnetworking/libc/strsep.c b/cpukit/libnetworking/libc/strsep.c
new file mode 100644
index 0000000000..3ac9f12533
--- /dev/null
+++ b/cpukit/libnetworking/libc/strsep.c
@@ -0,0 +1,88 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if !HAVE_STRSEP
+
+#include <string.h>
+#include <stdio.h>
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ *
+ * PUBLIC: #ifndef HAVE_STRSEP
+ * PUBLIC: char *strsep __P((char **, const char *));
+ * PUBLIC: #endif
+ */
+char *
+strsep(stringp, delim)
+ register char **stringp;
+ register const char *delim;
+{
+ register char *s;
+ register const char *spanp;
+ register int c, sc;
+ char *tok;
+
+ if ((s = *stringp) == NULL)
+ return (NULL);
+ for (tok = s;;) {
+ c = *s++;
+ spanp = delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = 0;
+ *stringp = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+ /* NOTREACHED */
+}
+#endif
diff --git a/cpukit/libnetworking/loop.h b/cpukit/libnetworking/loop.h
new file mode 100644
index 0000000000..4fd6b8e1ba
--- /dev/null
+++ b/cpukit/libnetworking/loop.h
@@ -0,0 +1,20 @@
+/*
+ * $Id$
+ */
+
+#ifndef _RTEMS_BSDNET_LOOP_H
+#define _RTEMS_BSDNET_LOOP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NLOOP 1
+
+void rtems_bsdnet_initialize_loop(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_BSDNET_LOOP_H */
diff --git a/cpukit/libnetworking/machine/cpu.h b/cpukit/libnetworking/machine/cpu.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/machine/cpu.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/machine/cpufunc.h b/cpukit/libnetworking/machine/cpufunc.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/machine/cpufunc.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/machine/in_cksum.h b/cpukit/libnetworking/machine/in_cksum.h
new file mode 100644
index 0000000000..5329fba869
--- /dev/null
+++ b/cpukit/libnetworking/machine/in_cksum.h
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from tahoe: in_cksum.c 1.2 86/01/05
+ * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91
+ * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp
+ * $Id$
+ */
+
+#ifndef _MACHINE_IN_CKSUM_H_
+#define _MACHINE_IN_CKSUM_H_ 1
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <netinet/ip.h> /* struct ip */
+
+/*
+ * It it useful to have an Internet checksum routine which is inlineable
+ * and optimized specifically for the task of computing IP header checksums
+ * in the normal case (where there are no options and the header length is
+ * therefore always exactly five 32-bit words.
+ */
+
+/*
+ * Optimized version for the i386 family
+ */
+
+#if (defined(__GNUC__) && defined(__i386__))
+
+static __inline u_int
+in_cksum_hdr(const struct ip *ip)
+{
+ register u_int sum = ((const uint32_t*)ip)[0];
+ register u_int tmp;
+
+ __asm__ __volatile__(
+ " addl %2, %0 \n"
+ " adcl %3, %0 \n"
+ " adcl %4, %0 \n"
+ " adcl %5, %0 \n"
+ " adcl $0, %0 \n"
+ " movl %0, %1 \n"
+ " roll $16, %0 \n"
+ " addl %1, %0 \n"
+ :"+&r"(sum),"=&r"(tmp)
+ :"g"(((const uint32_t*)ip)[1]),
+ "g"(((const uint32_t*)ip)[2]),
+ "g"(((const uint32_t*)ip)[3]),
+ "g"(((const uint32_t*)ip)[4]),
+ "m"(*ip)
+ :"cc"
+ );
+
+ return (~sum) >>16;
+}
+
+static __inline void
+in_cksum_update(struct ip *ip)
+{
+ int __tmpsum;
+ __tmpsum = (int)ntohs(ip->ip_sum) + 256;
+ ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));
+}
+
+/*
+ * Optimized version for the MC68xxx and Coldfire families
+ */
+
+#elif (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)))
+
+static __inline__ u_int
+in_cksum_hdr(const struct ip *ip)
+{
+ register u_int *ap = (u_int *)ip;
+ register u_int sum = *ap++;
+ register u_int tmp;
+
+ __asm__ __volatile__("addl %2@+,%0\n\t"
+ "movel %2@+,%1\n\t"
+ "addxl %1,%0\n\t"
+ "movel %2@+,%1\n\t"
+ "addxl %1,%0\n\t"
+ "movel %2@,%1\n\t"
+ "addxl %1,%0\n\t"
+ "moveq #0,%1\n\t"
+ "addxl %1,%0\n" :
+ "=d" (sum), "=d" (tmp), "=a" (ap) :
+ "0" (sum), "2" (ap), "m"(*ip));
+ sum = (sum & 0xffff) + (sum >> 16);
+ if (sum > 0xffff)
+ sum -= 0xffff;
+ return ~sum & 0xffff;
+}
+
+/*
+ * Optimized version for the PowerPC family
+ */
+
+#elif (defined(__GNUC__) && (defined(__PPC__) || defined(__ppc__)))
+
+static __inline u_int
+in_cksum_hdr(const struct ip *ip)
+{
+register u_int sum, tmp;
+ __asm__ __volatile__(
+ " lwz %0, 0(%2) \n"
+ " lwz %1, 4(%2) \n"
+ " addc %0, %0, %1 \n" /* generate carry (XER[CA]) */
+ " lwz %1, 8(%2) \n"
+ " adde %0, %0, %1 \n" /* add + generate */
+ " lwz %1, 12(%2) \n"
+ " adde %0, %0, %1 \n"
+ " lwz %1, 16(%2) \n"
+ " adde %0, %0, %1 \n"
+ " addze %0, %0 \n" /* mop up XER[CA] */
+ " rotlwi %1, %0,16 \n" /* word-swapped copy in %1 */
+ " add %0, %0, %1 \n" /* see comment below */
+ " not %0, %0 \n"
+ " srwi %0, %0, 16 \n"
+ :"=&r"(sum),"=&r"(tmp):"b"(ip), "m"(*ip):"xer"
+ );
+ /* Note: if 'add' generates a carry out of the lower 16 bits
+ * then this is automatically added to the upper 16 bits
+ * where the correct result is found. (Stolen from linux.)
+ * %0 : upper-word lower-word
+ * + %1 : lower-word upper-word
+ * = word-sum word-sum
+ * ^+inter-word-carry
+ */
+ return sum;
+}
+
+static __inline void
+in_cksum_update(struct ip *ip)
+{
+ int __tmpsum;
+ __tmpsum = (int)ntohs(ip->ip_sum) + 256;
+ ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));
+}
+
+/*
+ * SPARC Version
+ */
+
+#elif (defined(__GNUC__) && defined(sparc))
+
+static __inline u_int
+in_cksum_hdr(const struct ip *ip)
+{
+ register u_int sum = 0;
+ register u_int tmp_o2;
+ register u_int tmp_o3;
+
+ __asm__ __volatile__ (" \
+ ld [%0], %1 ; \
+ ld [%0+4], %2 ; \
+ ld [%0+8], %3 ; \
+ addcc %1, %2, %1 ; \
+ ld [%0+12], %2 ; \
+ addxcc %1, %3, %1 ; \
+ ld [%0+16], %3 ; \
+ addxcc %1, %2, %1 ; \
+ addxcc %1, %3, %1 ; \
+ set 0x0ffff, %3 ; \
+ srl %1, 16, %2 ; \
+ and %1, %3, %1 ; \
+ addx %1, %2, %1 ; \
+ srl %1, 16, %2 ; \
+ add %1, %2, %1 ; \
+ not %1 ; \
+ and %1, %3, %1 ; \
+ " : "=r" (ip), "=r" (sum), "=r" (tmp_o2), "=r" (tmp_o3)
+ : "0" (ip), "1" (sum), "m"(*ip)
+ );
+ return sum;
+}
+
+#define in_cksum_update(ip) \
+ do { \
+ int __tmpsum; \
+ __tmpsum = (int)ntohs(ip->ip_sum) + 256; \
+ ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \
+ } while(0)
+/*
+ * Here is the generic, portable, inefficient algorithm.
+ */
+
+#else
+u_int in_cksum_hdr(const struct ip *);
+#define in_cksum_update(ip) \
+ do { \
+ int __tmpsum; \
+ __tmpsum = (int)ntohs(ip->ip_sum) + 256; \
+ ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \
+ } while(0)
+
+#endif
+
+#endif /* _MACHINE_IN_CKSUM_H_ */
diff --git a/cpukit/libnetworking/machine/limits.h b/cpukit/libnetworking/machine/limits.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/machine/limits.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/machine/vmparam.h b/cpukit/libnetworking/machine/vmparam.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/machine/vmparam.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/memory.h b/cpukit/libnetworking/memory.h
new file mode 100644
index 0000000000..7ef4cda388
--- /dev/null
+++ b/cpukit/libnetworking/memory.h
@@ -0,0 +1,5 @@
+/*
+ * Dummy include file for FreeBSD routines
+ */
+
+#include <string.h>
diff --git a/cpukit/libnetworking/net/bpf.h b/cpukit/libnetworking/net/bpf.h
new file mode 100644
index 0000000000..df21575640
--- /dev/null
+++ b/cpukit/libnetworking/net/bpf.h
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 1990, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from the Stanford/CMU enet packet filter,
+ * (net/enet.c) distributed as part of 4.3BSD, and code contributed
+ * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
+ * Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)bpf.h 8.1 (Berkeley) 6/10/93
+ * @(#)bpf.h 1.34 (LBL) 6/16/96
+ *
+ * $Id$
+ */
+
+#ifndef _NET_BPF_H_
+#define _NET_BPF_H_
+
+/* BSD style release date */
+#define BPF_RELEASE 199606
+
+typedef int32_t bpf_int32;
+typedef u_int32_t bpf_u_int32;
+
+/*
+ * Alignment macros. BPF_WORDALIGN rounds up to the next
+ * even multiple of BPF_ALIGNMENT.
+ */
+#define BPF_ALIGNMENT sizeof(bpf_int32)
+#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
+
+#define BPF_MAXINSNS 512
+#define BPF_MAXBUFSIZE 0x8000
+#define BPF_MINBUFSIZE 32
+
+/*
+ * Structure for BIOCSETF.
+ */
+struct bpf_program {
+ u_int bf_len;
+ struct bpf_insn *bf_insns;
+};
+
+/*
+ * Struct returned by BIOCGSTATS.
+ */
+struct bpf_stat {
+ u_int bs_recv; /* number of packets received */
+ u_int bs_drop; /* number of packets dropped */
+};
+
+/*
+ * Struct return by BIOCVERSION. This represents the version number of
+ * the filter language described by the instruction encodings below.
+ * bpf understands a program iff kernel_major == filter_major &&
+ * kernel_minor >= filter_minor, that is, if the value returned by the
+ * running kernel has the same major number and a minor number equal
+ * equal to or less than the filter being downloaded. Otherwise, the
+ * results are undefined, meaning an error may be returned or packets
+ * may be accepted haphazardly.
+ * It has nothing to do with the source code version.
+ */
+struct bpf_version {
+ u_short bv_major;
+ u_short bv_minor;
+};
+/* Current version number of filter architecture. */
+#define BPF_MAJOR_VERSION 1
+#define BPF_MINOR_VERSION 1
+
+#define BIOCGBLEN _IOR('B',102, u_int)
+#define BIOCSBLEN _IOWR('B',102, u_int)
+#define BIOCSETF _IOW('B',103, struct bpf_program)
+#define BIOCFLUSH _IO('B',104)
+#define BIOCPROMISC _IO('B',105)
+#define BIOCGDLT _IOR('B',106, u_int)
+#define BIOCGETIF _IOR('B',107, struct ifreq)
+#define BIOCSETIF _IOW('B',108, struct ifreq)
+#define BIOCSRTIMEOUT _IOW('B',109, struct timeval)
+#define BIOCGRTIMEOUT _IOR('B',110, struct timeval)
+#define BIOCGSTATS _IOR('B',111, struct bpf_stat)
+#define BIOCIMMEDIATE _IOW('B',112, u_int)
+#define BIOCVERSION _IOR('B',113, struct bpf_version)
+#define BIOCGRSIG _IOR('B',114, u_int)
+#define BIOCSRSIG _IOW('B',115, u_int)
+
+/*
+ * Structure prepended to each packet.
+ */
+struct bpf_hdr {
+ struct timeval bh_tstamp; /* time stamp */
+ bpf_u_int32 bh_caplen; /* length of captured portion */
+ bpf_u_int32 bh_datalen; /* original length of packet */
+ u_short bh_hdrlen; /* length of bpf header (this struct
+ plus alignment padding) */
+};
+/*
+ * Because the structure above is not a multiple of 4 bytes, some compilers
+ * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
+ * Only the kernel needs to know about it; applications use bh_hdrlen.
+ */
+#ifdef _KERNEL
+#define SIZEOF_BPF_HDR 18
+#endif
+
+/*
+ * Data-link level type codes.
+ */
+#define DLT_NULL 0 /* no link-layer encapsulation */
+#define DLT_EN10MB 1 /* Ethernet (10Mb) */
+#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
+#define DLT_AX25 3 /* Amateur Radio AX.25 */
+#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
+#define DLT_CHAOS 5 /* Chaos */
+#define DLT_IEEE802 6 /* IEEE 802 Networks */
+#define DLT_ARCNET 7 /* ARCNET */
+#define DLT_SLIP 8 /* Serial Line IP */
+#define DLT_PPP 9 /* Point-to-point Protocol */
+#define DLT_FDDI 10 /* FDDI */
+#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
+
+/*
+ * The instruction encodings.
+ */
+/* instruction classes */
+#define BPF_CLASS(code) ((code) & 0x07)
+#define BPF_LD 0x00
+#define BPF_LDX 0x01
+#define BPF_ST 0x02
+#define BPF_STX 0x03
+#define BPF_ALU 0x04
+#define BPF_JMP 0x05
+#define BPF_RET 0x06
+#define BPF_MISC 0x07
+
+/* ld/ldx fields */
+#define BPF_SIZE(code) ((code) & 0x18)
+#define BPF_W 0x00
+#define BPF_H 0x08
+#define BPF_B 0x10
+#define BPF_MODE(code) ((code) & 0xe0)
+#define BPF_IMM 0x00
+#define BPF_ABS 0x20
+#define BPF_IND 0x40
+#define BPF_MEM 0x60
+#define BPF_LEN 0x80
+#define BPF_MSH 0xa0
+
+/* alu/jmp fields */
+#define BPF_OP(code) ((code) & 0xf0)
+#define BPF_ADD 0x00
+#define BPF_SUB 0x10
+#define BPF_MUL 0x20
+#define BPF_DIV 0x30
+#define BPF_OR 0x40
+#define BPF_AND 0x50
+#define BPF_LSH 0x60
+#define BPF_RSH 0x70
+#define BPF_NEG 0x80
+#define BPF_JA 0x00
+#define BPF_JEQ 0x10
+#define BPF_JGT 0x20
+#define BPF_JGE 0x30
+#define BPF_JSET 0x40
+#define BPF_SRC(code) ((code) & 0x08)
+#define BPF_K 0x00
+#define BPF_X 0x08
+
+/* ret - BPF_K and BPF_X also apply */
+#define BPF_RVAL(code) ((code) & 0x18)
+#define BPF_A 0x10
+
+/* misc */
+#define BPF_MISCOP(code) ((code) & 0xf8)
+#define BPF_TAX 0x00
+#define BPF_TXA 0x80
+
+/*
+ * The instruction data structure.
+ */
+struct bpf_insn {
+ u_short code;
+ u_char jt;
+ u_char jf;
+ bpf_u_int32 k;
+};
+
+/*
+ * Macros for insn array initializers.
+ */
+#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
+#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
+
+#ifdef _KERNEL
+int bpf_validate(struct bpf_insn *, int);
+void bpf_tap(struct ifnet *, u_char *, u_int);
+void bpf_mtap(struct ifnet *, struct mbuf *);
+void bpfattach(struct ifnet *, u_int, u_int);
+void bpfilterattach(int);
+u_int bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int);
+#endif
+
+/*
+ * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
+ */
+#define BPF_MEMWORDS 16
+
+#endif /* _NET_BPF_H_ */
diff --git a/cpukit/libnetworking/net/ethernet.h b/cpukit/libnetworking/net/ethernet.h
new file mode 100644
index 0000000000..3051af077a
--- /dev/null
+++ b/cpukit/libnetworking/net/ethernet.h
@@ -0,0 +1,387 @@
+/*
+ * Fundamental constants relating to ethernet.
+ *
+ * $FreeBSD: src/sys/net/ethernet.h,v 1.24 2004/10/05 19:28:52 sam Exp $
+ *
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_ETHERNET_H_
+#define _NET_ETHERNET_H_
+
+/*
+ * Some basic Ethernet constants.
+ */
+#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
+#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
+#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */
+#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
+#define ETHER_MIN_LEN 64 /* minimum frame len, including CRC */
+#define ETHER_MAX_LEN 1518 /* maximum frame len, including CRC */
+#define ETHER_MAX_LEN_JUMBO 9018 /* max jumbo frame len, including CRC */
+
+#define ETHER_VLAN_ENCAP_LEN 4 /* len of 802.1Q VLAN encapsulation */
+/*
+ * Mbuf adjust factor to force 32-bit alignment of IP header.
+ * Drivers should do m_adj(m, ETHER_ALIGN) when setting up a
+ * receive so the upper layers get the IP header properly aligned
+ * past the 14-byte Ethernet header.
+ */
+#define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */
+
+/*
+ * Compute the maximum frame size based on ethertype (i.e. possible
+ * encapsulation) and whether or not an FCS is present.
+ */
+#define ETHER_MAX_FRAME(ifp, etype, hasfcs) \
+ ((ifp)->if_mtu + ETHER_HDR_LEN + \
+ ((hasfcs) ? ETHER_CRC_LEN : 0) + \
+ (((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0))
+
+/*
+ * Ethernet-specific mbuf flags.
+ */
+#define M_HASFCS M_PROTO5 /* FCS included at end of frame */
+
+/*
+ * Ethernet CRC32 polynomials (big- and little-endian verions).
+ */
+#define ETHER_CRC_POLY_LE 0xedb88320
+#define ETHER_CRC_POLY_BE 0x04c11db6
+
+/*
+ * A macro to validate a length with
+ */
+#define ETHER_IS_VALID_LEN(foo) \
+ ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
+
+/*
+ * Structure of a 10Mb/s Ethernet header.
+ */
+struct ether_header {
+ u_char ether_dhost[ETHER_ADDR_LEN];
+ u_char ether_shost[ETHER_ADDR_LEN];
+ u_short ether_type;
+};
+
+/*
+ * Structure of a 48-bit Ethernet address.
+ */
+struct ether_addr {
+ u_char octet[ETHER_ADDR_LEN];
+};
+
+#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
+
+/*
+ * NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields.
+ * However, there are some conflicts.
+ */
+
+#define ETHERTYPE_8023 0x0004 /* IEEE 802.3 packet */
+ /* 0x0101 .. 0x1FF Experimental */
+#define ETHERTYPE_PUP 0x0200 /* Xerox PUP protocol - see 0A00 */
+#define ETHERTYPE_PUPAT 0x0200 /* PUP Address Translation - see 0A01 */
+#define ETHERTYPE_SPRITE 0x0500 /* ??? */
+ /* 0x0400 Nixdorf */
+#define ETHERTYPE_NS 0x0600 /* XNS */
+#define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */
+#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */
+#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */
+#define ETHERTYPE_IP 0x0800 /* IP protocol */
+#define ETHERTYPE_X75 0x0801 /* X.75 Internet */
+#define ETHERTYPE_NBS 0x0802 /* NBS Internet */
+#define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */
+#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */
+#define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */
+#define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */
+#define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */
+#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */
+ /* 0x081C Symbolics Private */
+ /* 0x0888 - 0x088A Xyplex */
+#define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */
+#define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */
+#define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */
+#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */
+#define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */
+#define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */
+
+/* 0x1000 - 0x100F Berkeley Trailer */
+/*
+ * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
+ * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
+ * by an ETHER type (as given above) and then the (variable-length) header.
+ */
+#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
+#define ETHERTYPE_NTRAILER 16
+
+#define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */
+#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */
+#define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */
+#define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */
+
+ /* The following 3C0x types
+ are unregistered: */
+#define ETHERTYPE_NBPVCD 0x3C00 /* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */
+#define ETHERTYPE_NBPSCD 0x3C01 /* 3Com NBP System control datagram not registered */
+#define ETHERTYPE_NBPCREQ 0x3C02 /* 3Com NBP Connect request (virtual cct) not registered */
+#define ETHERTYPE_NBPCRSP 0x3C03 /* 3Com NBP Connect repsonse not registered */
+#define ETHERTYPE_NBPCC 0x3C04 /* 3Com NBP Connect complete not registered */
+#define ETHERTYPE_NBPCLREQ 0x3C05 /* 3Com NBP Close request (virtual cct) not registered */
+#define ETHERTYPE_NBPCLRSP 0x3C06 /* 3Com NBP Close response not registered */
+#define ETHERTYPE_NBPDG 0x3C07 /* 3Com NBP Datagram (like XNS IDP) not registered */
+#define ETHERTYPE_NBPDGB 0x3C08 /* 3Com NBP Datagram broadcast not registered */
+#define ETHERTYPE_NBPCLAIM 0x3C09 /* 3Com NBP Claim NetBIOS name not registered */
+#define ETHERTYPE_NBPDLTE 0x3C0A /* 3Com NBP Delete Netbios name not registered */
+#define ETHERTYPE_NBPRAS 0x3C0B /* 3Com NBP Remote adaptor status request not registered */
+#define ETHERTYPE_NBPRAR 0x3C0C /* 3Com NBP Remote adaptor response not registered */
+#define ETHERTYPE_NBPRST 0x3C0D /* 3Com NBP Reset not registered */
+
+#define ETHERTYPE_PCS 0x4242 /* PCS Basic Block Protocol */
+#define ETHERTYPE_IMLBLDIAG 0x424C /* Information Modes Little Big LAN diagnostic */
+#define ETHERTYPE_DIDDLE 0x4321 /* THD - Diddle */
+#define ETHERTYPE_IMLBL 0x4C42 /* Information Modes Little Big LAN */
+#define ETHERTYPE_SIMNET 0x5208 /* BBN Simnet Private */
+#define ETHERTYPE_DECEXPER 0x6000 /* DEC Unassigned, experimental */
+#define ETHERTYPE_MOPDL 0x6001 /* DEC MOP dump/load */
+#define ETHERTYPE_MOPRC 0x6002 /* DEC MOP remote console */
+#define ETHERTYPE_DECnet 0x6003 /* DEC DECNET Phase IV route */
+#define ETHERTYPE_DN ETHERTYPE_DECnet /* libpcap, tcpdump */
+#define ETHERTYPE_LAT 0x6004 /* DEC LAT */
+#define ETHERTYPE_DECDIAG 0x6005 /* DEC diagnostic protocol (at interface initialization?) */
+#define ETHERTYPE_DECCUST 0x6006 /* DEC customer protocol */
+#define ETHERTYPE_SCA 0x6007 /* DEC LAVC, SCA */
+#define ETHERTYPE_AMBER 0x6008 /* DEC AMBER */
+#define ETHERTYPE_DECMUMPS 0x6009 /* DEC MUMPS */
+ /* 0x6010 - 0x6014 3Com Corporation */
+#define ETHERTYPE_TRANSETHER 0x6558 /* Trans Ether Bridging (RFC1701)*/
+#define ETHERTYPE_RAWFR 0x6559 /* Raw Frame Relay (RFC1701) */
+#define ETHERTYPE_UBDL 0x7000 /* Ungermann-Bass download */
+#define ETHERTYPE_UBNIU 0x7001 /* Ungermann-Bass NIUs */
+#define ETHERTYPE_UBDIAGLOOP 0x7002 /* Ungermann-Bass diagnostic/loopback */
+#define ETHERTYPE_UBNMC 0x7003 /* Ungermann-Bass ??? (NMC to/from UB Bridge) */
+#define ETHERTYPE_UBBST 0x7005 /* Ungermann-Bass Bridge Spanning Tree */
+#define ETHERTYPE_OS9 0x7007 /* OS/9 Microware */
+#define ETHERTYPE_OS9NET 0x7009 /* OS/9 Net? */
+ /* 0x7020 - 0x7029 LRT (England) (now Sintrom) */
+#define ETHERTYPE_RACAL 0x7030 /* Racal-Interlan */
+#define ETHERTYPE_PRIMENTS 0x7031 /* Prime NTS (Network Terminal Service) */
+#define ETHERTYPE_CABLETRON 0x7034 /* Cabletron */
+#define ETHERTYPE_CRONUSVLN 0x8003 /* Cronus VLN */
+#define ETHERTYPE_CRONUS 0x8004 /* Cronus Direct */
+#define ETHERTYPE_HP 0x8005 /* HP Probe */
+#define ETHERTYPE_NESTAR 0x8006 /* Nestar */
+#define ETHERTYPE_ATTSTANFORD 0x8008 /* AT&T/Stanford (local use) */
+#define ETHERTYPE_EXCELAN 0x8010 /* Excelan */
+#define ETHERTYPE_SG_DIAG 0x8013 /* SGI diagnostic type */
+#define ETHERTYPE_SG_NETGAMES 0x8014 /* SGI network games */
+#define ETHERTYPE_SG_RESV 0x8015 /* SGI reserved type */
+#define ETHERTYPE_SG_BOUNCE 0x8016 /* SGI bounce server */
+#define ETHERTYPE_APOLLODOMAIN 0x8019 /* Apollo DOMAIN */
+#define ETHERTYPE_TYMSHARE 0x802E /* Tymeshare */
+#define ETHERTYPE_TIGAN 0x802F /* Tigan, Inc. */
+#define ETHERTYPE_REVARP 0x8035 /* Reverse addr resolution protocol */
+#define ETHERTYPE_AEONIC 0x8036 /* Aeonic Systems */
+#define ETHERTYPE_IPXNEW 0x8037 /* IPX (Novell Netware?) */
+#define ETHERTYPE_LANBRIDGE 0x8038 /* DEC LANBridge */
+#define ETHERTYPE_DSMD 0x8039 /* DEC DSM/DDP */
+#define ETHERTYPE_ARGONAUT 0x803A /* DEC Argonaut Console */
+#define ETHERTYPE_VAXELN 0x803B /* DEC VAXELN */
+#define ETHERTYPE_DECDNS 0x803C /* DEC DNS Naming Service */
+#define ETHERTYPE_ENCRYPT 0x803D /* DEC Ethernet Encryption */
+#define ETHERTYPE_DECDTS 0x803E /* DEC Distributed Time Service */
+#define ETHERTYPE_DECLTM 0x803F /* DEC LAN Traffic Monitor */
+#define ETHERTYPE_DECNETBIOS 0x8040 /* DEC PATHWORKS DECnet NETBIOS Emulation */
+#define ETHERTYPE_DECLAST 0x8041 /* DEC Local Area System Transport */
+ /* 0x8042 DEC Unassigned */
+#define ETHERTYPE_PLANNING 0x8044 /* Planning Research Corp. */
+ /* 0x8046 - 0x8047 AT&T */
+#define ETHERTYPE_DECAM 0x8048 /* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */
+#define ETHERTYPE_EXPERDATA 0x8049 /* ExperData */
+#define ETHERTYPE_VEXP 0x805B /* Stanford V Kernel exp. */
+#define ETHERTYPE_VPROD 0x805C /* Stanford V Kernel prod. */
+#define ETHERTYPE_ES 0x805D /* Evans & Sutherland */
+#define ETHERTYPE_LITTLE 0x8060 /* Little Machines */
+#define ETHERTYPE_COUNTERPOINT 0x8062 /* Counterpoint Computers */
+ /* 0x8065 - 0x8066 Univ. of Mass @ Amherst */
+#define ETHERTYPE_VEECO 0x8067 /* Veeco Integrated Auto. */
+#define ETHERTYPE_GENDYN 0x8068 /* General Dynamics */
+#define ETHERTYPE_ATT 0x8069 /* AT&T */
+#define ETHERTYPE_AUTOPHON 0x806A /* Autophon */
+#define ETHERTYPE_COMDESIGN 0x806C /* ComDesign */
+#define ETHERTYPE_COMPUGRAPHIC 0x806D /* Compugraphic Corporation */
+ /* 0x806E - 0x8077 Landmark Graphics Corp. */
+#define ETHERTYPE_MATRA 0x807A /* Matra */
+#define ETHERTYPE_DDE 0x807B /* Dansk Data Elektronik */
+#define ETHERTYPE_MERIT 0x807C /* Merit Internodal (or Univ of Michigan?) */
+ /* 0x807D - 0x807F Vitalink Communications */
+#define ETHERTYPE_VLTLMAN 0x8080 /* Vitalink TransLAN III Management */
+ /* 0x8081 - 0x8083 Counterpoint Computers */
+ /* 0x8088 - 0x808A Xyplex */
+#define ETHERTYPE_ATALK 0x809B /* AppleTalk */
+#define ETHERTYPE_AT ETHERTYPE_ATALK /* old NetBSD */
+#define ETHERTYPE_APPLETALK ETHERTYPE_ATALK /* HP-UX */
+ /* 0x809C - 0x809E Datability */
+#define ETHERTYPE_SPIDER 0x809F /* Spider Systems Ltd. */
+ /* 0x80A3 Nixdorf */
+ /* 0x80A4 - 0x80B3 Siemens Gammasonics Inc. */
+ /* 0x80C0 - 0x80C3 DCA (Digital Comm. Assoc.) Data Exchange Cluster */
+ /* 0x80C4 - 0x80C5 Banyan Systems */
+#define ETHERTYPE_PACER 0x80C6 /* Pacer Software */
+#define ETHERTYPE_APPLITEK 0x80C7 /* Applitek Corporation */
+ /* 0x80C8 - 0x80CC Intergraph Corporation */
+ /* 0x80CD - 0x80CE Harris Corporation */
+ /* 0x80CF - 0x80D2 Taylor Instrument */
+ /* 0x80D3 - 0x80D4 Rosemount Corporation */
+#define ETHERTYPE_SNA 0x80D5 /* IBM SNA Services over Ethernet */
+#define ETHERTYPE_VARIAN 0x80DD /* Varian Associates */
+ /* 0x80DE - 0x80DF TRFS (Integrated Solutions Transparent Remote File System) */
+ /* 0x80E0 - 0x80E3 Allen-Bradley */
+ /* 0x80E4 - 0x80F0 Datability */
+#define ETHERTYPE_RETIX 0x80F2 /* Retix */
+#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */
+ /* 0x80F4 - 0x80F5 Kinetics */
+#define ETHERTYPE_APOLLO 0x80F7 /* Apollo Computer */
+#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging (XXX conflicts) */
+ /* 0x80FF - 0x8101 Wellfleet Communications (XXX conflicts) */
+#define ETHERTYPE_BOFL 0x8102 /* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */
+#define ETHERTYPE_WELLFLEET 0x8103 /* Wellfleet Communications */
+ /* 0x8107 - 0x8109 Symbolics Private */
+#define ETHERTYPE_TALARIS 0x812B /* Talaris */
+#define ETHERTYPE_WATERLOO 0x8130 /* Waterloo Microsystems Inc. (XXX which?) */
+#define ETHERTYPE_HAYES 0x8130 /* Hayes Microcomputers (XXX which?) */
+#define ETHERTYPE_VGLAB 0x8131 /* VG Laboratory Systems */
+ /* 0x8132 - 0x8137 Bridge Communications */
+#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */
+#define ETHERTYPE_NOVELL 0x8138 /* Novell, Inc. */
+ /* 0x8139 - 0x813D KTI */
+#define ETHERTYPE_MUMPS 0x813F /* M/MUMPS data sharing */
+#define ETHERTYPE_AMOEBA 0x8145 /* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */
+#define ETHERTYPE_FLIP 0x8146 /* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */
+#define ETHERTYPE_VURESERVED 0x8147 /* Vrije Universiteit (NL) [reserved] */
+#define ETHERTYPE_LOGICRAFT 0x8148 /* Logicraft */
+#define ETHERTYPE_NCD 0x8149 /* Network Computing Devices */
+#define ETHERTYPE_ALPHA 0x814A /* Alpha Micro */
+#define ETHERTYPE_SNMP 0x814C /* SNMP over Ethernet (see RFC1089) */
+ /* 0x814D - 0x814E BIIN */
+#define ETHERTYPE_TEC 0x814F /* Technically Elite Concepts */
+#define ETHERTYPE_RATIONAL 0x8150 /* Rational Corp */
+ /* 0x8151 - 0x8153 Qualcomm */
+ /* 0x815C - 0x815E Computer Protocol Pty Ltd */
+ /* 0x8164 - 0x8166 Charles River Data Systems */
+#define ETHERTYPE_XTP 0x817D /* Protocol Engines XTP */
+#define ETHERTYPE_SGITW 0x817E /* SGI/Time Warner prop. */
+#define ETHERTYPE_HIPPI_FP 0x8180 /* HIPPI-FP encapsulation */
+#define ETHERTYPE_STP 0x8181 /* Scheduled Transfer STP, HIPPI-ST */
+ /* 0x8182 - 0x8183 Reserved for HIPPI-6400 */
+ /* 0x8184 - 0x818C SGI prop. */
+#define ETHERTYPE_MOTOROLA 0x818D /* Motorola */
+#define ETHERTYPE_NETBEUI 0x8191 /* PowerLAN NetBIOS/NetBEUI (PC) */
+ /* 0x819A - 0x81A3 RAD Network Devices */
+ /* 0x81B7 - 0x81B9 Xyplex */
+ /* 0x81CC - 0x81D5 Apricot Computers */
+ /* 0x81D6 - 0x81DD Artisoft Lantastic */
+ /* 0x81E6 - 0x81EF Polygon */
+ /* 0x81F0 - 0x81F2 Comsat Labs */
+ /* 0x81F3 - 0x81F5 SAIC */
+ /* 0x81F6 - 0x81F8 VG Analytical */
+ /* 0x8203 - 0x8205 QNX Software Systems Ltd. */
+ /* 0x8221 - 0x8222 Ascom Banking Systems */
+ /* 0x823E - 0x8240 Advanced Encryption Systems */
+ /* 0x8263 - 0x826A Charles River Data Systems */
+ /* 0x827F - 0x8282 Athena Programming */
+ /* 0x829A - 0x829B Inst Ind Info Tech */
+ /* 0x829C - 0x82AB Taurus Controls */
+ /* 0x82AC - 0x8693 Walker Richer & Quinn */
+#define ETHERTYPE_ACCTON 0x8390 /* Accton Technologies (unregistered) */
+#define ETHERTYPE_TALARISMC 0x852B /* Talaris multicast */
+#define ETHERTYPE_KALPANA 0x8582 /* Kalpana */
+ /* 0x8694 - 0x869D Idea Courier */
+ /* 0x869E - 0x86A1 Computer Network Tech */
+ /* 0x86A3 - 0x86AC Gateway Communications */
+#define ETHERTYPE_SECTRA 0x86DB /* SECTRA */
+#define ETHERTYPE_IPV6 0x86DD /* IP protocol version 6 */
+#define ETHERTYPE_DELTACON 0x86DE /* Delta Controls */
+#define ETHERTYPE_ATOMIC 0x86DF /* ATOMIC */
+ /* 0x86E0 - 0x86EF Landis & Gyr Powers */
+ /* 0x8700 - 0x8710 Motorola */
+#define ETHERTYPE_RDP 0x8739 /* Control Technology Inc. RDP Without IP */
+#define ETHERTYPE_MICP 0x873A /* Control Technology Inc. Mcast Industrial Ctrl Proto. */
+ /* 0x873B - 0x873C Control Technology Inc. Proprietary */
+#define ETHERTYPE_TCPCOMP 0x876B /* TCP/IP Compression (RFC1701) */
+#define ETHERTYPE_IPAS 0x876C /* IP Autonomous Systems (RFC1701) */
+#define ETHERTYPE_SECUREDATA 0x876D /* Secure Data (RFC1701) */
+#define ETHERTYPE_FLOWCONTROL 0x8808 /* 802.3x flow control packet */
+#define ETHERTYPE_PPP 0x880B /* PPP (obsolete by PPPOE) */
+#define ETHERTYPE_HITACHI 0x8820 /* Hitachi Cable (Optoelectronic Systems Laboratory) */
+#define ETHERTYPE_MPLS 0x8847 /* MPLS Unicast */
+#define ETHERTYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */
+#define ETHERTYPE_AXIS 0x8856 /* Axis Communications AB proprietary bootstrap/config */
+#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
+#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
+#define ETHERTYPE_LANPROBE 0x8888 /* HP LanProbe test? */
+#define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */
+#define ETHERTYPE_LOOPBACK 0x9000 /* Loopback: used to test interfaces */
+#define ETHERTYPE_LBACK ETHERTYPE_LOOPBACK /* DEC MOP loopback */
+#define ETHERTYPE_XNSSM 0x9001 /* 3Com (Formerly Bridge Communications), XNS Systems Management */
+#define ETHERTYPE_TCPSM 0x9002 /* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */
+#define ETHERTYPE_BCLOOP 0x9003 /* 3Com (Formerly Bridge Communications), loopback detection */
+#define ETHERTYPE_DEBNI 0xAAAA /* DECNET? Used by VAX 6220 DEBNI */
+#define ETHERTYPE_SONIX 0xFAF5 /* Sonix Arpeggio */
+#define ETHERTYPE_VITAL 0xFF00 /* BBN VITAL-LanBridge cache wakeups */
+ /* 0xFF00 - 0xFFOF ISC Bunker Ramo */
+
+#define ETHERTYPE_MAX 0xFFFF /* Maximum valid ethernet type, reserved */
+
+/*
+ * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
+ * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
+ * by an ETHER type (as given above) and then the (variable-length) header.
+ */
+#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
+#define ETHERTYPE_NTRAILER 16
+
+#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
+#define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
+#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
+
+#ifdef _KERNEL
+
+struct ifnet;
+struct mbuf;
+struct rtentry;
+struct sockaddr;
+
+extern uint32_t ether_crc32_le(const uint8_t *, size_t);
+extern uint32_t ether_crc32_be(const uint8_t *, size_t);
+extern void ether_demux(struct ifnet *, struct mbuf *);
+extern void ether_ifattach(struct ifnet *);
+extern void ether_ifdetach(struct ifnet *);
+extern int ether_ioctl(struct ifnet *, ioctl_command_t, caddr_t);
+extern void ether_input (struct ifnet *, struct ether_header *, struct mbuf *);
+extern int ether_output(struct ifnet *,
+ struct mbuf *, struct sockaddr *, struct rtentry *);
+extern int ether_output_frame(struct ifnet *, struct mbuf *);
+extern char *ether_sprintf(const u_int8_t *);
+
+#else /* _KERNEL */
+
+#include <rtems/bsd/sys/cdefs.h>
+
+/*
+ * Ethernet address conversion/parsing routines.
+ */
+__BEGIN_DECLS
+struct ether_addr *ether_aton(const char *);
+int ether_hostton(const char *, struct ether_addr *);
+int ether_line(const char *, struct ether_addr *, char *);
+char *ether_ntoa(const struct ether_addr *);
+int ether_ntohost(char *, const struct ether_addr *);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_NET_ETHERNET_H_ */
diff --git a/cpukit/libnetworking/net/if.c b/cpukit/libnetworking/net/if.c
new file mode 100644
index 0000000000..063a26b542
--- /dev/null
+++ b/cpukit/libnetworking/net/if.c
@@ -0,0 +1,784 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if.c 8.5 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/net/if.c,v 1.226 2005/04/15 01:51:26 cperciva Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/mbuf.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <sys/kernel.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <sys/syslog.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <net/if_var.h>
+#include <net/radix.h>
+
+/*
+ * System initialization
+ */
+
+static int ifconf(u_long, caddr_t);
+ void ifinit(void *);
+static void if_qflush(struct ifqueue *);
+static void if_slowtimo(void *);
+static void link_rtrequest(int, struct rtentry *, struct sockaddr *);
+
+SYSINIT(interfaces, SI_SUB_PROTO_IF, SI_ORDER_FIRST, ifinit, NULL)
+
+
+int ifqmaxlen = IFQ_MAXLEN;
+struct ifnet *ifnet;
+
+/*
+ * Network interface utility routines.
+ *
+ * Routines with ifa_ifwith* names take sockaddr *'s as
+ * parameters.
+ *
+ * This routine assumes that it will be called at splimp() or higher.
+ */
+/* ARGSUSED*/
+void
+ifinit(void *dummy)
+{
+ struct ifnet *ifp;
+
+ for (ifp = ifnet; ifp; ifp = ifp->if_next)
+ if (ifp->if_snd.ifq_maxlen == 0)
+ ifp->if_snd.ifq_maxlen = ifqmaxlen;
+ if_slowtimo(0);
+}
+
+int if_index = 0;
+struct ifaddr **ifnet_addrs;
+
+
+/*
+ * Attach an interface to the
+ * list of "active" interfaces.
+ */
+void
+if_attach(struct ifnet *ifp)
+{
+ unsigned socksize, ifasize;
+ int namelen, masklen;
+ char workbuf[64];
+ struct ifnet **p = &ifnet;
+ struct sockaddr_dl *sdl;
+ struct ifaddr *ifa;
+ static int if_indexlim = 8;
+
+
+ while (*p)
+ p = &((*p)->if_next);
+ *p = ifp;
+ ifp->if_index = ++if_index;
+ microtime(&ifp->if_lastchange);
+ if (ifnet_addrs == 0 || if_index >= if_indexlim) {
+ unsigned n = (if_indexlim <<= 1) * sizeof(ifa);
+ struct ifaddr **q = (struct ifaddr **)
+ malloc(n, M_IFADDR, M_WAITOK);
+ bzero((caddr_t)q, n);
+ if (ifnet_addrs) {
+ bcopy((caddr_t)ifnet_addrs, (caddr_t)q, n/2);
+ free((caddr_t)ifnet_addrs, M_IFADDR);
+ }
+ ifnet_addrs = q;
+ }
+ /*
+ * create a Link Level name for this device
+ */
+ namelen = sprintf(workbuf, "%s%d", ifp->if_name, ifp->if_unit);
+#define _offsetof(t, m) ((uintptr_t)((void*)&((t *)0)->m))
+ masklen = _offsetof(struct sockaddr_dl, sdl_data[0]) + namelen;
+ socksize = masklen + ifp->if_addrlen;
+#define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
+ socksize = ROUNDUP(socksize);
+ if (socksize < sizeof(*sdl))
+ socksize = sizeof(*sdl);
+ ifasize = sizeof(*ifa) + 2 * socksize;
+ ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK);
+ if (ifa) {
+ bzero((caddr_t)ifa, ifasize);
+ sdl = (struct sockaddr_dl *)(ifa + 1);
+ sdl->sdl_len = socksize;
+ sdl->sdl_family = AF_LINK;
+ bcopy(workbuf, sdl->sdl_data, namelen);
+ sdl->sdl_nlen = namelen;
+ sdl->sdl_index = ifp->if_index;
+ sdl->sdl_type = ifp->if_type;
+ ifnet_addrs[if_index - 1] = ifa;
+ ifa->ifa_ifp = ifp;
+ ifa->ifa_next = ifp->if_addrlist;
+ ifa->ifa_rtrequest = link_rtrequest;
+ ifp->if_addrlist = ifa;
+ ifa->ifa_addr = (struct sockaddr *)sdl;
+
+ sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
+ ifa->ifa_netmask = (struct sockaddr *)sdl;
+ sdl->sdl_len = masklen;
+ while (namelen != 0)
+ sdl->sdl_data[--namelen] = 0xff;
+ }
+}
+/*
+ * Locate an interface based on a complete address.
+ */
+/*ARGSUSED*/
+struct ifaddr *
+ifa_ifwithaddr(struct sockaddr *addr)
+{
+ struct ifnet *ifp;
+ struct ifaddr *ifa;
+
+#define equal(a1, a2) \
+ (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0)
+ for (ifp = ifnet; ifp; ifp = ifp->if_next)
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr->sa_family != addr->sa_family)
+ continue;
+ if (equal(addr, ifa->ifa_addr))
+ return (ifa);
+ if ((ifp->if_flags & IFF_BROADCAST) && ifa->ifa_broadaddr &&
+ equal(ifa->ifa_broadaddr, addr))
+ return (ifa);
+ }
+ return ((struct ifaddr *)0);
+}
+/*
+ * Locate the point to point interface with a given destination address.
+ */
+/*ARGSUSED*/
+struct ifaddr *
+ifa_ifwithdstaddr(struct sockaddr *addr)
+{
+ struct ifnet *ifp;
+ struct ifaddr *ifa;
+
+ for (ifp = ifnet; ifp; ifp = ifp->if_next)
+ if (ifp->if_flags & IFF_POINTOPOINT)
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr->sa_family != addr->sa_family)
+ continue;
+ if (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr))
+ return (ifa);
+ }
+ return ((struct ifaddr *)0);
+}
+
+/*
+ * Find an interface on a specific network. If many, choice
+ * is most specific found.
+ */
+struct ifaddr *
+ifa_ifwithnet(struct sockaddr *addr)
+{
+ struct ifnet *ifp;
+ struct ifaddr *ifa;
+ struct ifaddr *ifa_maybe = (struct ifaddr *) 0;
+ u_int af = addr->sa_family;
+ char *addr_data = addr->sa_data, *cplim;
+
+ if (af == AF_LINK) {
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
+ if (sdl->sdl_index && sdl->sdl_index <= if_index)
+ return (ifnet_addrs[sdl->sdl_index - 1]);
+ }
+ for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+ char *cp, *cp2, *cp3;
+
+ if (ifa->ifa_addr->sa_family != af)
+ next: continue;
+ if (ifp->if_flags & IFF_POINTOPOINT) {
+ if (ifa->ifa_dstaddr != 0
+ && equal(addr, ifa->ifa_dstaddr))
+ return (ifa);
+ } else {
+ /*
+ * if we have a special address handler,
+ * then use it instead of the generic one.
+ */
+ if (ifa->ifa_claim_addr) {
+ if ((*ifa->ifa_claim_addr)(ifa, addr)) {
+ return (ifa);
+ } else {
+ continue;
+ }
+ }
+
+ /*
+ * Scan all the bits in the ifa's address.
+ * If a bit dissagrees with what we are
+ * looking for, mask it with the netmask
+ * to see if it really matters.
+ * (A byte at a time)
+ */
+ if (ifa->ifa_netmask == 0)
+ continue;
+ cp = addr_data;
+ cp2 = ifa->ifa_addr->sa_data;
+ cp3 = ifa->ifa_netmask->sa_data;
+ cplim = ifa->ifa_netmask->sa_len
+ + (char *)ifa->ifa_netmask;
+ while (cp3 < cplim)
+ if ((*cp++ ^ *cp2++) & *cp3++)
+ goto next; /* next address! */
+ /*
+ * If the netmask of what we just found
+ * is more specific than what we had before
+ * (if we had one) then remember the new one
+ * before continuing to search
+ * for an even better one.
+ */
+ if (ifa_maybe == 0 ||
+ rn_refines((caddr_t)ifa->ifa_netmask,
+ (caddr_t)ifa_maybe->ifa_netmask))
+ ifa_maybe = ifa;
+ }
+ }
+ }
+ return (ifa_maybe);
+}
+
+/*
+ * Find an interface address specific to an interface best matching
+ * a given address.
+ */
+struct ifaddr *
+ifaof_ifpforaddr(struct sockaddr *addr, struct ifnet *ifp)
+{
+ struct ifaddr *ifa;
+ char *cp, *cp2, *cp3;
+ char *cplim;
+ struct ifaddr *ifa_maybe = 0;
+ u_int af = addr->sa_family;
+
+ if (af >= AF_MAX)
+ return (0);
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr->sa_family != af)
+ continue;
+ if (ifa_maybe == 0)
+ ifa_maybe = ifa;
+ if (ifa->ifa_netmask == 0) {
+ if (equal(addr, ifa->ifa_addr) ||
+ (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr)))
+ return (ifa);
+ continue;
+ }
+ if (ifp->if_flags & IFF_POINTOPOINT) {
+ if (equal(addr, ifa->ifa_dstaddr))
+ return (ifa);
+ } else {
+ cp = addr->sa_data;
+ cp2 = ifa->ifa_addr->sa_data;
+ cp3 = ifa->ifa_netmask->sa_data;
+ cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
+ for (; cp3 < cplim; cp3++)
+ if ((*cp++ ^ *cp2++) & *cp3)
+ break;
+ if (cp3 == cplim)
+ return (ifa);
+ }
+ }
+ return (ifa_maybe);
+}
+
+#include <net/route.h>
+
+/*
+ * Default action when installing a route with a Link Level gateway.
+ * Lookup an appropriate real ifa to point to.
+ * This should be moved to /sys/net/link.c eventually.
+ */
+static void
+link_rtrequest(int cmd, struct rtentry *rt, struct sockaddr *sa)
+{
+ struct ifaddr *ifa;
+ struct sockaddr *dst;
+ struct ifnet *ifp;
+
+ if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == 0) ||
+ ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0))
+ return;
+ ifa = ifaof_ifpforaddr(dst, ifp);
+ if (ifa) {
+ IFAFREE(rt->rt_ifa);
+ rt->rt_ifa = ifa;
+ ifa->ifa_refcnt++;
+ if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest)
+ ifa->ifa_rtrequest(cmd, rt, sa);
+ }
+}
+
+/*
+ * Mark an interface down and notify protocols of
+ * the transition.
+ * NOTE: must be called at splnet or eqivalent.
+ */
+void
+if_down(struct ifnet *ifp)
+{
+ struct ifaddr *ifa;
+
+ ifp->if_flags &= ~IFF_UP;
+ microtime(&ifp->if_lastchange);
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+ pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
+ if_qflush(&ifp->if_snd);
+ rt_ifmsg(ifp);
+}
+
+/*
+ * Mark an interface up and notify protocols of
+ * the transition.
+ * NOTE: must be called at splnet or eqivalent.
+ */
+void
+if_up(struct ifnet *ifp)
+{
+
+ ifp->if_flags |= IFF_UP;
+ microtime(&ifp->if_lastchange);
+#ifdef notyet
+ struct ifaddr *ifa;
+ /* this has no effect on IP, and will kill all iso connections XXX */
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+ pfctlinput(PRC_IFUP, ifa->ifa_addr);
+#endif
+ rt_ifmsg(ifp);
+}
+
+/*
+ * Flush an interface queue.
+ */
+static void
+if_qflush(struct ifqueue *ifq)
+{
+ struct mbuf *m, *n;
+
+ n = ifq->ifq_head;
+ while ((m = n) != 0) {
+ n = m->m_act;
+ m_freem(m);
+ }
+ ifq->ifq_head = 0;
+ ifq->ifq_tail = 0;
+ ifq->ifq_len = 0;
+}
+
+/*
+ * Handle interface watchdog timer routines. Called
+ * from softclock, we decrement timers (if set) and
+ * call the appropriate interface routine on expiration.
+ */
+static void
+if_slowtimo(void *arg)
+{
+ struct ifnet *ifp;
+ int s = splimp();
+
+ for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+ if (ifp->if_timer == 0 || --ifp->if_timer)
+ continue;
+ if (ifp->if_watchdog)
+ (*ifp->if_watchdog)(ifp);
+ }
+ splx(s);
+ timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ);
+}
+
+/*
+ * Map interface name to
+ * interface structure pointer.
+ */
+struct ifnet *
+ifunit(char *name)
+{
+ char *cp;
+ struct ifnet *ifp;
+ int unit;
+ unsigned len;
+ char *ep, c;
+
+ for (cp = name; cp < name + IFNAMSIZ && *cp; cp++)
+ if (*cp >= '0' && *cp <= '9')
+ break;
+ if (*cp == '\0' || cp == name + IFNAMSIZ)
+ return ((struct ifnet *)0);
+ /*
+ * Save first char of unit, and pointer to it,
+ * so we can put a null there to avoid matching
+ * initial substrings of interface names.
+ */
+ len = cp - name + 1;
+ c = *cp;
+ ep = cp;
+ for (unit = 0; *cp >= '0' && *cp <= '9'; )
+ unit = unit * 10 + *cp++ - '0';
+ if (*cp != '\0')
+ return 0; /* no trailing garbage allowed */
+ *ep = 0;
+ for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+ if (bcmp(ifp->if_name, name, len))
+ continue;
+ if (unit == ifp->if_unit)
+ break;
+ }
+ *ep = c;
+ return (ifp);
+}
+
+/*
+ * Interface ioctls.
+ */
+int
+ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
+{
+ struct ifnet *ifp;
+ struct ifreq *ifr;
+ int error;
+
+ switch (cmd) {
+
+ case SIOCGIFCONF:
+ case OSIOCGIFCONF:
+ return (ifconf(cmd, data));
+ }
+ ifr = (struct ifreq *)data;
+ ifp = ifunit(ifr->ifr_name);
+ if (ifp == 0)
+ return (ENXIO);
+ switch (cmd) {
+
+ case SIOCGIFFLAGS:
+ ifr->ifr_flags = ifp->if_flags;
+ break;
+
+ case SIOCGIFMETRIC:
+ ifr->ifr_metric = ifp->if_metric;
+ break;
+
+ case SIOCGIFMTU:
+ ifr->ifr_mtu = ifp->if_mtu;
+ break;
+
+ case SIOCGIFPHYS:
+ ifr->ifr_phys = ifp->if_physical;
+ break;
+
+ case SIOCSIFFLAGS:
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return (error);
+ if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
+ int s = splimp();
+ if_down(ifp);
+ splx(s);
+ }
+ if (ifr->ifr_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) {
+ int s = splimp();
+ if_up(ifp);
+ splx(s);
+ }
+ ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
+ (ifr->ifr_flags &~ IFF_CANTCHANGE);
+ if (ifp->if_ioctl)
+ (void) (*ifp->if_ioctl)(ifp, cmd, data);
+ microtime(&ifp->if_lastchange);
+ break;
+
+ case SIOCSIFMETRIC:
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return (error);
+ ifp->if_metric = ifr->ifr_metric;
+ microtime(&ifp->if_lastchange);
+ break;
+
+ case SIOCSIFPHYS:
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return error;
+ if (!ifp->if_ioctl)
+ return EOPNOTSUPP;
+ error = (*ifp->if_ioctl)(ifp, cmd, data);
+ if (error == 0)
+ microtime(&ifp->if_lastchange);
+ return(error);
+
+ case SIOCSIFMTU:
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return (error);
+ if (ifp->if_ioctl == NULL)
+ return (EOPNOTSUPP);
+ /*
+ * 72 was chosen below because it is the size of a TCP/IP
+ * header (40) + the minimum mss (32).
+ */
+ if (ifr->ifr_mtu < 72 || ifr->ifr_mtu > 65535L)
+ return (EINVAL);
+ error = (*ifp->if_ioctl)(ifp, cmd, data);
+ if (error == 0)
+ microtime(&ifp->if_lastchange);
+ return(error);
+
+ case SIOCADDMULTI:
+ case SIOCDELMULTI:
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return (error);
+ if (ifp->if_ioctl == NULL)
+ return (EOPNOTSUPP);
+ error = (*ifp->if_ioctl)(ifp, cmd, data);
+ if (error == 0 )
+ microtime(&ifp->if_lastchange);
+ return(error);
+
+ case SIOCSIFMEDIA:
+ error = suser(p->p_ucred, &p->p_acflag);
+ if (error)
+ return (error);
+ if (ifp->if_ioctl == NULL)
+ return (EOPNOTSUPP);
+ error = (*ifp->if_ioctl)(ifp, cmd, data);
+ if (error == 0)
+ microtime(&ifp->if_lastchange);
+ return error;
+
+ case SIOCGIFMEDIA:
+ if (ifp->if_ioctl == NULL)
+ return (EOPNOTSUPP);
+ return ((*ifp->if_ioctl)(ifp, cmd, data));
+
+ default:
+ if (so->so_proto == 0)
+ return (EOPNOTSUPP);
+#ifndef COMPAT_43
+ return ((*so->so_proto->pr_usrreqs->pru_control)(so, cmd,
+ data,
+ ifp));
+#else
+ {
+ int ocmd = cmd;
+
+ switch (cmd) {
+
+ case SIOCSIFDSTADDR:
+ case SIOCSIFADDR:
+ case SIOCSIFBRDADDR:
+ case SIOCSIFNETMASK:
+#if BYTE_ORDER != BIG_ENDIAN
+ if (ifr->ifr_addr.sa_family == 0 &&
+ ifr->ifr_addr.sa_len < 16) {
+ ifr->ifr_addr.sa_family = ifr->ifr_addr.sa_len;
+ ifr->ifr_addr.sa_len = 16;
+ }
+#else
+ if (ifr->ifr_addr.sa_len == 0)
+ ifr->ifr_addr.sa_len = 16;
+#endif
+ break;
+
+ case OSIOCGIFADDR:
+ cmd = SIOCGIFADDR;
+ break;
+
+ case OSIOCGIFDSTADDR:
+ cmd = SIOCGIFDSTADDR;
+ break;
+
+ case OSIOCGIFBRDADDR:
+ cmd = SIOCGIFBRDADDR;
+ break;
+
+ case OSIOCGIFNETMASK:
+ cmd = SIOCGIFNETMASK;
+ }
+ error = ((*so->so_proto->pr_usrreqs->pru_control)(so,
+ cmd,
+ data,
+ ifp));
+ switch (ocmd) {
+
+ case OSIOCGIFADDR:
+ case OSIOCGIFDSTADDR:
+ case OSIOCGIFBRDADDR:
+ case OSIOCGIFNETMASK:
+ *(u_short *)&ifr->ifr_addr = ifr->ifr_addr.sa_family;
+ }
+ return (error);
+
+ }
+#endif
+
+ /*
+ * RTEMS additions for setting/getting `tap' function
+ */
+ case SIOCSIFTAP:
+ ifp->if_tap = ifr->ifr_tap;
+ return 0;
+
+ case SIOCGIFTAP:
+ ifr->ifr_tap = ifp->if_tap;
+ return 0;
+ }
+ return (0);
+}
+
+/*
+ * Set/clear promiscuous mode on interface ifp based on the truth value
+ * of pswitch. The calls are reference counted so that only the first
+ * "on" request actually has an effect, as does the final "off" request.
+ * Results are undefined if the "off" and "on" requests are not matched.
+ */
+int
+ifpromisc(struct ifnet *ifp, int pswitch)
+{
+ struct ifreq ifr;
+
+ if (pswitch) {
+ /*
+ * If the device is not configured up, we cannot put it in
+ * promiscuous mode.
+ */
+ if ((ifp->if_flags & IFF_UP) == 0)
+ return (ENETDOWN);
+ if (ifp->if_pcount++ != 0)
+ return (0);
+ ifp->if_flags |= IFF_PROMISC;
+ log(LOG_INFO, "%s%d: promiscuous mode enabled\n",
+ ifp->if_name, ifp->if_unit);
+ } else {
+ if (--ifp->if_pcount > 0)
+ return (0);
+ ifp->if_flags &= ~IFF_PROMISC;
+ }
+ ifr.ifr_flags = ifp->if_flags;
+ return ((*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr));
+}
+
+/*
+ * Return interface configuration
+ * of system. List may be used
+ * in later ioctl's (above) to get
+ * other information.
+ */
+/*ARGSUSED*/
+static int
+ifconf(u_long cmd, caddr_t data)
+{
+ struct ifconf *ifc = (struct ifconf *)data;
+ struct ifnet *ifp = ifnet;
+ struct ifaddr *ifa;
+ struct ifreq ifr, *ifrp;
+ int space = ifc->ifc_len, error = 0;
+
+ ifrp = ifc->ifc_req;
+ for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) {
+ char workbuf[64];
+ int ifnlen;
+
+ ifnlen = sprintf(workbuf, "%s%d", ifp->if_name, ifp->if_unit);
+ if(ifnlen + 1 > sizeof ifr.ifr_name) {
+ error = ENAMETOOLONG;
+ } else {
+ strcpy(ifr.ifr_name, workbuf);
+ }
+
+ if ((ifa = ifp->if_addrlist) == 0) {
+ bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
+ error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
+ sizeof (ifr));
+ if (error)
+ break;
+ space -= sizeof (ifr), ifrp++;
+ } else
+ for ( ; space > sizeof (ifr) && ifa; ifa = ifa->ifa_next) {
+ struct sockaddr *sa = ifa->ifa_addr;
+#ifdef COMPAT_43
+ if (cmd == OSIOCGIFCONF) {
+ struct osockaddr *osa =
+ (struct osockaddr *)&ifr.ifr_addr;
+ ifr.ifr_addr = *sa;
+ osa->sa_family = sa->sa_family;
+ error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
+ sizeof (ifr));
+ ifrp++;
+ } else
+#endif
+ if (sa->sa_len <= sizeof(*sa)) {
+ ifr.ifr_addr = *sa;
+ error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
+ sizeof (ifr));
+ ifrp++;
+ } else {
+ space -= sa->sa_len - sizeof(*sa);
+ if (space < sizeof (ifr))
+ break;
+ error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
+ sizeof (ifr.ifr_name));
+ if (error == 0)
+ error = copyout((caddr_t)sa,
+ (caddr_t)&ifrp->ifr_addr, sa->sa_len);
+ ifrp = (struct ifreq *)
+ (sa->sa_len + (caddr_t)&ifrp->ifr_addr);
+ }
+ if (error)
+ break;
+ space -= sizeof (ifr);
+ }
+ }
+ ifc->ifc_len -= space;
+ return (error);
+}
+
+SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers");
+SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management");
diff --git a/cpukit/libnetworking/net/if.h b/cpukit/libnetworking/net/if.h
new file mode 100644
index 0000000000..7a0b9f15ce
--- /dev/null
+++ b/cpukit/libnetworking/net/if.h
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if.h,v 1.95 2005/02/25 19:46:41 brooks Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_IF_H_
+#define _NET_IF_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#if defined(__rtems__)
+/*
+ * FIXME - HACK: BSD defines __BSD_VISIBLE in sys/cdefs.h
+ * RTEMS sys/cdefs.h doesn't, so we enforce it here.
+ */
+#ifndef __BSD_VISIBLE
+#define __BSD_VISIBLE 1
+#endif
+#include <inttypes.h>
+#endif
+
+#ifdef _KERNEL
+#include <sys/queue.h>
+#endif
+
+#if __BSD_VISIBLE
+/*
+ * <net/if.h> does not depend on <sys/time.h> on most other systems. This
+ * helps userland compatibility. (struct timeval ifi_lastchange)
+ */
+#ifndef _KERNEL
+#include <sys/time.h>
+#endif
+
+struct ifnet;
+struct ether_header;
+#endif
+
+/*
+ * Length of interface external name, including terminating '\0'.
+ * Note: this is the same size as a generic device's external name.
+ */
+#define IF_NAMESIZE 16
+#if __BSD_VISIBLE
+#define IFNAMSIZ IF_NAMESIZE
+#define IF_MAXUNIT 0x7fff /* historical value */
+#endif
+#if __BSD_VISIBLE
+
+/*
+ * Structure used to query names of interface cloners.
+ */
+
+struct if_clonereq {
+ int ifcr_total; /* total cloners (out) */
+ int ifcr_count; /* room for this many in user buffer */
+ char *ifcr_buffer; /* buffer for cloner names */
+};
+
+/*
+ * Structure describing information about an interface
+ * which may be of interest to management entities.
+ */
+struct if_data {
+ /* generic interface information */
+ u_char ifi_type; /* ethernet, tokenring, etc */
+ u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
+ u_char ifi_addrlen; /* media address length */
+ u_char ifi_hdrlen; /* media header length */
+ u_char ifi_recvquota; /* polling quota for receive intrs */
+ u_char ifi_xmitquota; /* polling quota for xmit intrs */
+ u_long ifi_mtu; /* maximum transmission unit */
+ u_long ifi_metric; /* routing metric (external only) */
+ u_long ifi_baudrate; /* linespeed */
+ /* volatile statistics */
+ u_long ifi_ipackets; /* packets received on interface */
+ u_long ifi_ierrors; /* input errors on interface */
+ u_long ifi_opackets; /* packets sent on interface */
+ u_long ifi_oerrors; /* output errors on interface */
+ u_long ifi_collisions; /* collisions on csma interfaces */
+ u_long ifi_ibytes; /* total number of octets received */
+ u_long ifi_obytes; /* total number of octets sent */
+ u_long ifi_imcasts; /* packets received via multicast */
+ u_long ifi_omcasts; /* packets sent via multicast */
+ u_long ifi_iqdrops; /* dropped on input, this interface */
+ u_long ifi_noproto; /* destined for unsupported protocol */
+ u_long ifi_recvtiming; /* usec spent receiving when timing */
+ u_long ifi_xmittiming; /* usec spent xmitting when timing */
+ struct timeval ifi_lastchange; /* time of last administrative change */
+};
+
+#define IFF_UP 0x1 /* interface is up */
+#define IFF_BROADCAST 0x2 /* broadcast address valid */
+#define IFF_DEBUG 0x4 /* turn on debugging */
+#define IFF_LOOPBACK 0x8 /* is a loopback net */
+#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
+#define IFF_SMART 0x20 /* interface manages own routes */
+#define IFF_RUNNING 0x40 /* resources allocated */
+#define IFF_NOARP 0x80 /* no address resolution protocol */
+#define IFF_PROMISC 0x100 /* receive all packets */
+#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
+#define IFF_OACTIVE 0x400 /* tx hardware queue is full */
+#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
+#define IFF_LINK0 0x1000 /* per link layer defined bit */
+#define IFF_LINK1 0x2000 /* per link layer defined bit */
+#define IFF_LINK2 0x4000 /* per link layer defined bit */
+#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
+#define IFF_MULTICAST 0x8000 /* supports multicast */
+#define IFF_POLLING 0x10000 /* Interface is in polling mode. */
+#define IFF_PPROMISC 0x20000 /* user-requested promisc mode */
+#define IFF_MONITOR 0x40000 /* user-requested monitor mode */
+#define IFF_STATICARP 0x80000 /* static ARP */
+#define IFF_NEEDSGIANT 0x100000 /* hold Giant over if_start calls */
+
+/* flags set internally only: */
+#define IFF_CANTCHANGE \
+ (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
+ IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC|\
+ IFF_POLLING)
+
+/*
+ * Values for if_link_state.
+ */
+#define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
+#define LINK_STATE_DOWN 1 /* link is down */
+#define LINK_STATE_UP 2 /* link is up */
+
+/*
+ * Some convenience macros used for setting ifi_baudrate.
+ * XXX 1000 vs. 1024? --thorpej@netbsd.org
+ */
+#define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */
+#define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */
+#define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */
+
+#define IFQ_MAXLEN 50
+#define IFNET_SLOWHZ 1 /* granularity is 1 second */
+
+/*
+ * Message format for use in obtaining information about interfaces
+ * from getkerninfo and the routing socket
+ */
+struct if_msghdr {
+ u_short ifm_msglen; /* to skip over non-understood messages */
+ u_char ifm_version; /* future binary compatibility */
+ u_char ifm_type; /* message type */
+ int ifm_addrs; /* like rtm_addrs */
+ int ifm_flags; /* value of if_flags */
+ u_short ifm_index; /* index for associated ifp */
+ struct if_data ifm_data;/* statistics and other data about if */
+};
+
+/*
+ * Message format for use in obtaining information about interface addresses
+ * from getkerninfo and the routing socket
+ */
+struct ifa_msghdr {
+ u_short ifam_msglen; /* to skip over non-understood messages */
+ u_char ifam_version; /* future binary compatibility */
+ u_char ifam_type; /* message type */
+ int ifam_addrs; /* like rtm_addrs */
+ int ifam_flags; /* value of ifa_flags */
+ u_short ifam_index; /* index for associated ifp */
+ int ifam_metric; /* value of ifa_metric */
+};
+
+/* forward declaration */
+struct mbuf;
+
+/*
+ * Interface request structure used for socket
+ * ioctl's. All interface ioctl's must have parameter
+ * definitions which begin with ifr_name. The
+ * remainder may be interface specific.
+ */
+struct ifreq {
+ char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ union {
+ struct sockaddr ifru_addr;
+ struct sockaddr ifru_dstaddr;
+ struct sockaddr ifru_broadaddr;
+ short ifru_flags[2];
+ int32_t ifru_metric;
+ int32_t ifru_mtu;
+ int ifru_phys;
+ int ifru_media;
+ caddr_t ifru_data;
+ int (*ifru_tap)(struct ifnet *, struct ether_header *, struct mbuf *);
+ } ifr_ifru;
+#define ifr_addr ifr_ifru.ifru_addr /* address */
+#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
+#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
+#define ifr_flags ifr_ifru.ifru_flags[0] /* flags (low 16 bits) */
+#define ifr_flagshigh ifr_ifru.ifru_flags[1] /* flags (high 16 bits) */
+#define ifr_metric ifr_ifru.ifru_metric /* metric */
+#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
+#define ifr_phys ifr_ifru.ifru_phys /* physical wire */
+#define ifr_media ifr_ifru.ifru_media /* physical media */
+#define ifr_data ifr_ifru.ifru_data /* for use by interface */
+#define ifr_tap ifr_ifru.ifru_tap /* tap function */
+};
+
+struct ifaliasreq {
+ char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ struct sockaddr ifra_addr;
+ struct sockaddr ifra_broadaddr;
+ struct sockaddr ifra_mask;
+};
+
+struct ifmediareq {
+ char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ int ifm_current; /* current media options */
+ int ifm_mask; /* don't care mask */
+ int ifm_status; /* media status */
+ int ifm_active; /* active options */
+ int ifm_count; /* # entries in ifm_ulist array */
+ int *ifm_ulist; /* media words */
+};
+
+/*
+ * Structure used to retrieve aux status data from interfaces.
+ * Kernel suppliers to this interface should respect the formatting
+ * needed by ifconfig(8): each line starts with a TAB and ends with
+ * a newline. The canonical example to copy and paste is in if_tun.c.
+ */
+
+#define IFSTATMAX 800 /* 10 lines of text */
+struct ifstat {
+ char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ char ascii[IFSTATMAX + 1];
+};
+
+/*
+ * Structure used in SIOCGIFCONF request.
+ * Used to retrieve interface configuration
+ * for machine (useful for programs which
+ * must know all networks accessible).
+ */
+struct ifconf {
+ int ifc_len; /* size of associated buffer */
+ union {
+ caddr_t ifcu_buf;
+ struct ifreq *ifcu_req;
+ } ifc_ifcu;
+#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
+#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
+};
+#endif /* __BSD_VISIBLE */
+
+#ifndef _KERNEL
+struct if_nameindex {
+ unsigned int if_index; /* 1, 2, ... */
+ char *if_name; /* null terminated name: "le0", ... */
+};
+
+__BEGIN_DECLS
+void if_freenameindex(struct if_nameindex *);
+char *if_indextoname(unsigned int, char *);
+struct if_nameindex *if_nameindex(void);
+__END_DECLS
+#endif
+
+#ifdef _KERNEL
+
+/* XXX - this should go away soon. */
+#include <net/if_var.h>
+
+void ifafree(struct ifaddr *);
+
+int looutput(struct ifnet *,
+ struct mbuf *, struct sockaddr *, struct rtentry *);
+#endif
+
+#endif /* !_NET_IF_H_ */
diff --git a/cpukit/libnetworking/net/if_arp.h b/cpukit/libnetworking/net/if_arp.h
new file mode 100644
index 0000000000..f64da8b693
--- /dev/null
+++ b/cpukit/libnetworking/net/if_arp.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_arp.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if_arp.h,v 1.21 2005/01/07 01:45:34 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_IF_ARP_H_
+#define _NET_IF_ARP_H_
+
+#include <sys/socket.h> /* struct sockaddr */
+
+/*
+ * Address Resolution Protocol.
+ *
+ * See RFC 826 for protocol description. ARP packets are variable
+ * in size; the arphdr structure defines the fixed-length portion.
+ * Protocol type values are the same as those for 10 Mb/s Ethernet.
+ * It is followed by the variable-sized fields ar_sha, arp_spa,
+ * arp_tha and arp_tpa in that order, according to the lengths
+ * specified. Field names used correspond to RFC 826.
+ */
+struct arphdr {
+ u_short ar_hrd; /* format of hardware address */
+#define ARPHRD_ETHER 1 /* ethernet hardware format */
+#define ARPHRD_IEEE802 6 /* token-ring hardware format */
+#define ARPHRD_ARCNET 7 /* arcnet hardware format */
+#define ARPHRD_FRELAY 15 /* frame relay hardware format */
+#define ARPHRD_IEEE1394 24 /* firewire hardware format */
+ u_short ar_pro; /* format of protocol address */
+ u_char ar_hln; /* length of hardware address */
+ u_char ar_pln; /* length of protocol address */
+ u_short ar_op; /* one of: */
+#define ARPOP_REQUEST 1 /* request to resolve address */
+#define ARPOP_REPLY 2 /* response to previous request */
+#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */
+#define ARPOP_REVREPLY 4 /* response giving protocol address */
+#define ARPOP_INVREQUEST 8 /* request to identify peer */
+#define ARPOP_INVREPLY 9 /* response identifying peer */
+/*
+ * The remaining fields are variable in size,
+ * according to the sizes above.
+ */
+#ifdef COMMENT_ONLY
+ u_char ar_sha[]; /* sender hardware address */
+ u_char ar_spa[]; /* sender protocol address */
+ u_char ar_tha[]; /* target hardware address */
+ u_char ar_tpa[]; /* target protocol address */
+#endif
+};
+
+#define ar_sha(ap) (((caddr_t)((ap)+1)) + 0)
+#define ar_spa(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln)
+#define ar_tha(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln + (ap)->ar_pln)
+#define ar_tpa(ap) (((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
+
+#define arphdr_len2(ar_hln, ar_pln) \
+ (sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
+#define arphdr_len(ap) (arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
+
+/*
+ * ARP ioctl request
+ */
+struct arpreq {
+ struct sockaddr arp_pa; /* protocol address */
+ struct sockaddr arp_ha; /* hardware address */
+ int arp_flags; /* flags */
+};
+/* arp_flags and at_flags field values */
+#define ATF_INUSE 0x01 /* entry in use */
+#define ATF_COM 0x02 /* completed entry (enaddr valid) */
+#define ATF_PERM 0x04 /* permanent entry */
+#define ATF_PUBL 0x08 /* publish entry (respond for other host) */
+#define ATF_USETRAILERS 0x10 /* has requested trailers */
+
+#ifdef _KERNEL
+/*
+ * Structure shared between the ethernet driver modules and
+ * the address resolution code. For example, each ec_softc or il_softc
+ * begins with this structure.
+ * The code is written so that each *_softc _must_ begin with a
+ * struct arpcom, which in turn _must_ begin with a struct ifnet.
+ */
+struct arpcom {
+ /*
+ * The ifnet struct _must_ be at the head of this structure.
+ */
+ struct ifnet ac_if; /* network-visible interface */
+ u_char ac_enaddr[6]; /* ethernet hardware address */
+#if defined(__rtems__)
+/* Cruft from ancient BSD - should be removed once RTEMS is updated */
+ struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
+ int ac_multicnt; /* length of ac_multiaddrs list */
+#else
+ int now_unused; /* XXX was length of ac_multiaddrs list */
+ void *ac_netgraph; /* ng_ether(4) netgraph node info */
+#endif
+};
+#define IFP2AC(ifp) ((struct arpcom *)(ifp))
+
+#endif
+
+#endif /* !_NET_IF_ARP_H_ */
diff --git a/cpukit/libnetworking/net/if_dl.h b/cpukit/libnetworking/net/if_dl.h
new file mode 100644
index 0000000000..757f1f13f0
--- /dev/null
+++ b/cpukit/libnetworking/net/if_dl.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_dl.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if_dl.h,v 1.14 2005/01/07 01:45:34 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_IF_DL_H_
+#define _NET_IF_DL_H_
+
+/*
+ * A Link-Level Sockaddr may specify the interface in one of two
+ * ways: either by means of a system-provided index number (computed
+ * anew and possibly differently on every reboot), or by a human-readable
+ * string such as "il0" (for managerial convenience).
+ *
+ * Census taking actions, such as something akin to SIOCGCONF would return
+ * both the index and the human name.
+ *
+ * High volume transactions (such as giving a link-level ``from'' address
+ * in a recvfrom or recvmsg call) may be likely only to provide the indexed
+ * form, (which requires fewer copy operations and less space).
+ *
+ * The form and interpretation of the link-level address is purely a matter
+ * of convention between the device driver and its consumers; however, it is
+ * expected that all drivers for an interface of a given if_type will agree.
+ */
+
+/*
+ * Structure of a Link-Level sockaddr:
+ */
+struct sockaddr_dl {
+ u_char sdl_len; /* Total length of sockaddr */
+ u_char sdl_family; /* AF_LINK */
+ u_short sdl_index; /* if != 0, system given index for interface */
+ u_char sdl_type; /* interface type */
+ u_char sdl_nlen; /* interface name length, no trailing 0 reqd. */
+ u_char sdl_alen; /* link level address length */
+ u_char sdl_slen; /* link layer selector length */
+ char sdl_data[46]; /* minimum work area, can be larger;
+ contains both if name and ll address */
+};
+
+#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
+
+#ifndef _KERNEL
+
+#include <rtems/bsd/sys/cdefs.h>
+
+__BEGIN_DECLS
+void link_addr(const char *, struct sockaddr_dl *);
+char *link_ntoa(const struct sockaddr_dl *);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif
diff --git a/cpukit/libnetworking/net/if_ethersubr.c b/cpukit/libnetworking/net/if_ethersubr.c
new file mode 100644
index 0000000000..b60684fa6e
--- /dev/null
+++ b/cpukit/libnetworking/net/if_ethersubr.c
@@ -0,0 +1,899 @@
+/*
+ * Copyright (c) 1982, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.189 2005/03/06 22:59:40 sobomax Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_atalk.h"
+#include "opt_inet.h"
+#include "opt_inet6.h"
+#include "opt_ipx.h"
+#include "opt_bdg.h"
+#include "opt_mac.h"
+#include "opt_netgraph.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <sys/syslog.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/netisr.h>
+#include <net/route.h>
+#include <net/if_llc.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <net/ethernet.h>
+
+#if defined(INET) || defined(INET6)
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/if_ether.h>
+#include <netinet/ip_fw.h>
+#ifndef __rtems__
+#include <netinet/ip_dummynet.h>
+#endif
+#endif
+#ifdef INET6
+#include <netinet6/nd6.h>
+#endif
+
+#ifdef DEV_CARP
+#include <netinet/ip_carp.h>
+#endif
+
+#ifdef IPX
+#include <netipx/ipx.h>
+#include <netipx/ipx_if.h>
+#endif
+
+#ifdef NETATALK
+#include <netatalk/at.h>
+#include <netatalk/at_var.h>
+#include <netatalk/at_extern.h>
+
+#define llc_snap_org_code llc_un.type_snap.org_code
+#define llc_snap_ether_type llc_un.type_snap.ether_type
+
+extern u_char at_org_code[3];
+extern u_char aarp_org_code[3];
+#endif /* NETATALK */
+
+u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+#define senderr(e) do { error = (e); goto bad;} while (0)
+
+/*
+ * Ethernet output routine.
+ * Encapsulate a packet of type family for the local net.
+ * Use trailer local net encapsulation if enough data in first
+ * packet leaves a multiple of 512 bytes of data in remainder.
+ * Assumes that ifp is actually pointer to arpcom structure.
+ */
+int
+ether_output(struct ifnet *ifp, struct mbuf *m,
+ struct sockaddr *dst, struct rtentry *rt0)
+{
+ short type;
+ int s, error = 0;
+ u_char edst[6];
+ register struct rtentry *rt;
+ struct mbuf *mcopy = (struct mbuf *)0;
+ register struct ether_header *eh;
+ int off, len = m->m_pkthdr.len;
+ struct arpcom *ac = (struct arpcom *)ifp;
+#ifdef NETATALK
+ struct at_ifaddr *aa;
+#endif /* NETATALK */
+ int hlen; /* link layer header length */
+
+ if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+ senderr(ENETDOWN);
+ rt = rt0;
+ if (rt) {
+ if ((rt->rt_flags & RTF_UP) == 0) {
+ rt0 = rt = rtalloc1(dst, 1, 0UL);
+ if (rt0)
+ rt->rt_refcnt--;
+ else
+ senderr(EHOSTUNREACH);
+ }
+ if (rt->rt_flags & RTF_GATEWAY) {
+ if (rt->rt_gwroute == 0)
+ goto lookup;
+ if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
+ rtfree(rt); rt = rt0;
+ lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1,
+ 0UL);
+ if ((rt = rt->rt_gwroute) == 0)
+ senderr(EHOSTUNREACH);
+ }
+ }
+ if (rt->rt_flags & RTF_REJECT)
+ if (rt->rt_rmx.rmx_expire == 0 ||
+ rtems_bsdnet_seconds_since_boot() < rt->rt_rmx.rmx_expire)
+ senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
+ }
+ hlen = ETHER_HDR_LEN;
+ switch (dst->sa_family) {
+
+#ifdef INET
+ case AF_INET:
+ if (!arpresolve(ac, rt, m, dst, edst, rt0))
+ return (0); /* if not yet resolved */
+ /* If broadcasting on a simplex interface, loopback a copy */
+ if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
+ mcopy = m_copy(m, 0, (int)M_COPYALL);
+ off = m->m_pkthdr.len - m->m_len;
+ type = htons(ETHERTYPE_IP);
+ break;
+#endif
+#ifdef IPX
+ case AF_IPX:
+ {
+ struct ifaddr *ia;
+
+ type = htons(ETHERTYPE_IPX);
+ bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
+ (caddr_t)edst, sizeof (edst));
+ for (ia = ifp->if_addrlist; ia != NULL; ia = ia->ifa_next)
+ if(ia->ifa_addr->sa_family == AF_IPX &&
+ !bcmp((caddr_t)edst,
+ (caddr_t)&((struct ipx_ifaddr *)ia)->ia_addr.sipx_addr.x_host,
+ sizeof(edst)))
+ return (looutput(ifp, m, dst, rt));
+ /* If broadcasting on a simplex interface, loopback a copy */
+ if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
+ mcopy = m_copy(m, 0, (int)M_COPYALL);
+ break;
+ }
+#endif
+#ifdef NETATALK
+ case AF_APPLETALK:
+ {
+ struct sockaddr_at *sat = (struct sockaddr_at *)dst;
+
+ /*
+ * super hack..
+ * Most of this loopback code should move into the appletalk
+ * code, but it's here for now.. remember to move it! [JRE]
+ * This may not get the same interface we started with
+ * fix asap. XXX
+ */
+ aa = at_ifawithnet( sat );
+ if (aa == NULL) {
+ goto bad;
+ }
+ if( aa->aa_ifa.ifa_ifp != ifp ) {
+ (*aa->aa_ifa.ifa_ifp->if_output)(aa->aa_ifa.ifa_ifp,
+ m,dst,rt);
+ }
+ if (((sat->sat_addr.s_net == ATADDR_ANYNET)
+ && (sat->sat_addr.s_node == ATADDR_ANYNODE))
+ || ((sat->sat_addr.s_net == aa->aa_addr.sat_addr.s_net )
+ && (sat->sat_addr.s_node == aa->aa_addr.sat_addr.s_node))) {
+ (void) looutput(ifp, m, dst, rt);
+ return(0);
+ }
+
+ if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) {
+#ifdef NETATALKDEBUG
+ extern char *prsockaddr(struct sockaddr *);
+ printf("aarpresolv: failed for %s\n", prsockaddr(dst));
+#endif /* NETATALKDEBUG */
+ return (0);
+ }
+
+ /*
+ * If broadcasting on a simplex interface, loopback a copy
+ */
+ if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
+ mcopy = m_copy(m, 0, (int)M_COPYALL);
+ }
+ /*
+ * In the phase 2 case, we need to prepend an mbuf for the llc header.
+ * Since we must preserve the value of m, which is passed to us by
+ * value, we m_copy() the first mbuf, and use it for our llc header.
+ */
+ if ( aa->aa_flags & AFA_PHASE2 ) {
+ struct llc llc;
+
+ M_PREPEND(m, sizeof(struct llc), M_WAIT);
+ len += sizeof(struct llc);
+ llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
+ llc.llc_control = LLC_UI;
+ bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code));
+ llc.llc_snap_ether_type = htons( ETHERTYPE_AT );
+ bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
+ type = htons(m->m_pkthdr.len);
+ } else {
+ type = htons(ETHERTYPE_AT);
+ }
+ break;
+#endif /* NETATALK */
+
+ case AF_UNSPEC:
+ eh = (struct ether_header *)dst->sa_data;
+ (void)memcpy(edst, eh->ether_dhost, sizeof (edst));
+ type = eh->ether_type;
+ break;
+
+ default:
+ printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
+ dst->sa_family);
+ senderr(EAFNOSUPPORT);
+ }
+
+
+ if (mcopy)
+ (void) looutput(ifp, mcopy, dst, rt);
+ /*
+ * Add local net header. If no space in first mbuf,
+ * allocate another.
+ */
+ M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
+ if (m == NULL)
+ senderr(ENOBUFS);
+ eh = mtod(m, struct ether_header *);
+ (void)memcpy(&eh->ether_type, &type,
+ sizeof(eh->ether_type));
+ (void)memcpy(eh->ether_dhost, edst, sizeof (edst));
+ (void)memcpy(eh->ether_shost, ac->ac_enaddr,
+ sizeof(eh->ether_shost));
+ s = splimp();
+ /*
+ * Queue message on interface, and start output if interface
+ * not yet active.
+ */
+ if (IF_QFULL(&ifp->if_snd)) {
+ IF_DROP(&ifp->if_snd);
+ splx(s);
+ senderr(ENOBUFS);
+ }
+ IF_ENQUEUE(&ifp->if_snd, m);
+ if ((ifp->if_flags & IFF_OACTIVE) == 0)
+ (*ifp->if_start)(ifp);
+ splx(s);
+ ifp->if_obytes += len + sizeof (struct ether_header);
+ if (m->m_flags & M_MCAST)
+ ifp->if_omcasts++;
+ return (error);
+
+bad:
+ if (m)
+ m_freem(m);
+ return (error);
+}
+
+/*
+ * Process a received Ethernet packet;
+ * the packet is in the mbuf chain m without
+ * the ether header, which is provided separately.
+ */
+void
+ether_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m)
+{
+ register struct ifqueue *inq;
+ u_short ether_type;
+ int s;
+#if defined(NETATALK)
+ struct llc *l;
+#endif
+
+ if ((ifp->if_flags & IFF_UP) == 0) {
+ m_freem(m);
+ return;
+ }
+ ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh);
+ if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
+ sizeof(etherbroadcastaddr)) == 0)
+ m->m_flags |= M_BCAST;
+ else if (eh->ether_dhost[0] & 1)
+ m->m_flags |= M_MCAST;
+ if (m->m_flags & (M_BCAST|M_MCAST))
+ ifp->if_imcasts++;
+
+ /*
+ * RTEMS addition -- allow application to `tap into'
+ * the incoming packet stream.
+ */
+ if (ifp->if_tap && (*ifp->if_tap)(ifp, eh, m)) {
+ m_freem(m);
+ return;
+ }
+
+ ether_type = ntohs(eh->ether_type);
+
+ switch (ether_type) {
+#ifdef INET
+ case ETHERTYPE_IP:
+ schednetisr(NETISR_IP);
+ inq = &ipintrq;
+ break;
+
+ case ETHERTYPE_ARP:
+ schednetisr(NETISR_ARP);
+ inq = &arpintrq;
+ break;
+#endif
+#ifdef IPX
+ case ETHERTYPE_IPX:
+ schednetisr(NETISR_IPX);
+ inq = &ipxintrq;
+ break;
+#endif
+#ifdef NETATALK
+ case ETHERTYPE_AT:
+ schednetisr(NETISR_ATALK);
+ inq = &atintrq1;
+ break;
+ case ETHERTYPE_AARP:
+ /* probably this should be done with a NETISR as well */
+ aarpinput((struct arpcom *)ifp, m); /* XXX */
+ return;
+#endif /* NETATALK */
+ default:
+#if defined (ISO) || defined (LLC) || defined(NETATALK)
+ if (ether_type > ETHERMTU)
+ goto dropanyway;
+ l = mtod(m, struct llc *);
+ switch (l->llc_dsap) {
+#ifdef NETATALK
+ case LLC_SNAP_LSAP:
+ switch (l->llc_control) {
+ case LLC_UI:
+ if (l->llc_ssap != LLC_SNAP_LSAP)
+ goto dropanyway;
+
+ if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code,
+ sizeof(at_org_code)) == 0 &&
+ ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) {
+ inq = &atintrq2;
+ m_adj( m, sizeof( struct llc ));
+ schednetisr(NETISR_ATALK);
+ break;
+ }
+
+ if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code,
+ sizeof(aarp_org_code)) == 0 &&
+ ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) {
+ m_adj( m, sizeof( struct llc ));
+ aarpinput((struct arpcom *)ifp, m); /* XXX */
+ return;
+ }
+
+ default:
+ goto dropanyway;
+ }
+ break;
+#endif /* NETATALK */
+#ifdef ISO
+ case LLC_ISO_LSAP:
+ switch (l->llc_control) {
+ case LLC_UI:
+ /* LLC_UI_P forbidden in class 1 service */
+ if ((l->llc_dsap == LLC_ISO_LSAP) &&
+ (l->llc_ssap == LLC_ISO_LSAP)) {
+ /* LSAP for ISO */
+ if (m->m_pkthdr.len > ether_type)
+ m_adj(m, ether_type - m->m_pkthdr.len);
+ m->m_data += 3; /* XXX */
+ m->m_len -= 3; /* XXX */
+ m->m_pkthdr.len -= 3; /* XXX */
+ M_PREPEND(m, sizeof *eh, M_DONTWAIT);
+ if (m == 0)
+ return;
+ *mtod(m, struct ether_header *) = *eh;
+ IFDEBUG(D_ETHER)
+ printf("clnp packet");
+ ENDDEBUG
+ schednetisr(NETISR_ISO);
+ inq = &clnlintrq;
+ break;
+ }
+ goto dropanyway;
+
+ case LLC_XID:
+ case LLC_XID_P:
+ if(m->m_len < 6)
+ goto dropanyway;
+ l->llc_window = 0;
+ l->llc_fid = 9;
+ l->llc_class = 1;
+ l->llc_dsap = l->llc_ssap = 0;
+ /* Fall through to */
+ case LLC_TEST:
+ case LLC_TEST_P:
+ {
+ struct sockaddr sa;
+ register struct ether_header *eh2;
+ int i;
+ u_char c = l->llc_dsap;
+
+ l->llc_dsap = l->llc_ssap;
+ l->llc_ssap = c;
+ if (m->m_flags & (M_BCAST | M_MCAST))
+ bcopy((caddr_t)ac->ac_enaddr,
+ (caddr_t)eh->ether_dhost, 6);
+ sa.sa_family = AF_UNSPEC;
+ sa.sa_len = sizeof(sa);
+ eh2 = (struct ether_header *)sa.sa_data;
+ for (i = 0; i < 6; i++) {
+ eh2->ether_shost[i] = c = eh->ether_dhost[i];
+ eh2->ether_dhost[i] =
+ eh->ether_dhost[i] = eh->ether_shost[i];
+ eh->ether_shost[i] = c;
+ }
+ ifp->if_output(ifp, m, &sa, NULL);
+ return;
+ }
+ default:
+ m_freem(m);
+ return;
+ }
+ break;
+#endif /* ISO */
+#ifdef LLC
+ case LLC_X25_LSAP:
+ {
+ if (m->m_pkthdr.len > ether_type)
+ m_adj(m, ether_type - m->m_pkthdr.len);
+ M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
+ if (m == 0)
+ return;
+ if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP,
+ eh->ether_dhost, LLC_X25_LSAP, 6,
+ mtod(m, struct sdl_hdr *)))
+ panic("ETHER cons addr failure");
+ mtod(m, struct sdl_hdr *)->sdlhdr_len = ether_type;
+#ifdef LLC_DEBUG
+ printf("llc packet\n");
+#endif /* LLC_DEBUG */
+ schednetisr(NETISR_CCITT);
+ inq = &llcintrq;
+ break;
+ }
+#endif /* LLC */
+ dropanyway:
+ default:
+ m_freem(m);
+ return;
+ }
+#else /* ISO || LLC || NETATALK */
+ m_freem(m);
+ return;
+#endif /* ISO || LLC || NETATALK */
+ }
+
+ s = splimp();
+ if (IF_QFULL(inq)) {
+ IF_DROP(inq);
+ m_freem(m);
+ } else
+ IF_ENQUEUE(inq, m);
+ splx(s);
+}
+
+/*
+ * Convert Ethernet address to printable (loggable) representation.
+ * The static buffer isn't a really huge problem since this code
+ * is protected by the RTEMS network mutex.
+ */
+char *
+ether_sprintf(const u_char *ap)
+{
+ static char buf[32];
+ char *b = buf;
+ int i;
+
+ for (i = 0; i < ETHER_ADDR_LEN; i++, b+=3)
+ sprintf(b, "%02x:", *ap++);
+ *--b = '\0';
+ return buf;
+}
+
+/*
+ * Perform common duties while attaching to interface list
+ */
+void
+ether_ifattach(struct ifnet *ifp)
+{
+ struct ifaddr *ifa;
+ struct sockaddr_dl *sdl;
+
+ ifp->if_type = IFT_ETHER;
+ ifp->if_addrlen = ETHER_ADDR_LEN;
+ ifp->if_hdrlen = ETHER_HDR_LEN;
+ ifp->if_mtu = ETHERMTU;
+ if (ifp->if_baudrate == 0)
+ ifp->if_baudrate = 10000000;
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+ if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
+ sdl->sdl_family == AF_LINK) {
+ sdl->sdl_type = IFT_ETHER;
+ sdl->sdl_alen = ifp->if_addrlen;
+ bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
+ LLADDR(sdl), ifp->if_addrlen);
+ break;
+ }
+}
+
+#if defined(__rtems__)
+u_char ether_ipmulticast_min[6] =
+ { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
+u_char ether_ipmulticast_max[6] =
+ { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff };
+#else
+static u_char ether_ipmulticast_min[6] =
+ { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
+static u_char ether_ipmulticast_max[6] =
+ { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff };
+#endif
+
+/*
+ * Add an Ethernet multicast address or range of addresses to the list for a
+ * given interface.
+ */
+int
+ether_addmulti(struct ifreq *ifr, struct arpcom *ac)
+{
+ register struct ether_multi *enm;
+ struct sockaddr_in *sin;
+ u_char addrlo[6];
+ u_char addrhi[6];
+ int set_allmulti = 0;
+ int s = splimp();
+
+ switch (ifr->ifr_addr.sa_family) {
+
+ case AF_UNSPEC:
+ bcopy(ifr->ifr_addr.sa_data, addrlo, 6);
+ bcopy(addrlo, addrhi, 6);
+ break;
+
+#ifdef INET
+ case AF_INET:
+ sin = (struct sockaddr_in *)&(ifr->ifr_addr);
+ if (sin->sin_addr.s_addr == INADDR_ANY) {
+ /*
+ * An IP address of INADDR_ANY means listen to all
+ * of the Ethernet multicast addresses used for IP.
+ * (This is for the sake of IP multicast routers.)
+ */
+ bcopy(ether_ipmulticast_min, addrlo, 6);
+ bcopy(ether_ipmulticast_max, addrhi, 6);
+ set_allmulti = 1;
+ }
+ else {
+ ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo);
+ bcopy(addrlo, addrhi, 6);
+ }
+ break;
+#endif
+
+ default:
+ splx(s);
+ return (EAFNOSUPPORT);
+ }
+
+ /*
+ * Verify that we have valid Ethernet multicast addresses.
+ */
+ if ((addrlo[0] & 0x01) != 1 || (addrhi[0] & 0x01) != 1) {
+ splx(s);
+ return (EINVAL);
+ }
+ /*
+ * See if the address range is already in the list.
+ */
+ ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm);
+ if (enm != NULL) {
+ /*
+ * Found it; just increment the reference count.
+ */
+ ++enm->enm_refcount;
+ splx(s);
+ return (0);
+ }
+ /*
+ * New address or range; malloc a new multicast record
+ * and link it into the interface's multicast list.
+ */
+ enm = (struct ether_multi *)malloc(sizeof(*enm), M_IFMADDR, M_NOWAIT);
+ if (enm == NULL) {
+ splx(s);
+ return (ENOBUFS);
+ }
+ bcopy(addrlo, enm->enm_addrlo, 6);
+ bcopy(addrhi, enm->enm_addrhi, 6);
+ enm->enm_ac = ac;
+ enm->enm_refcount = 1;
+ enm->enm_next = ac->ac_multiaddrs;
+ ac->ac_multiaddrs = enm;
+ ac->ac_multicnt++;
+ splx(s);
+ if (set_allmulti)
+ ac->ac_if.if_flags |= IFF_ALLMULTI;
+
+ /*
+ * Return ENETRESET to inform the driver that the list has changed
+ * and its reception filter should be adjusted accordingly.
+ */
+ return (ENETRESET);
+}
+
+/*
+ * Delete a multicast address record.
+ */
+int
+ether_delmulti(struct ifreq *ifr, struct arpcom *ac)
+{
+ register struct ether_multi *enm;
+ register struct ether_multi **p;
+ struct sockaddr_in *sin;
+ u_char addrlo[6];
+ u_char addrhi[6];
+ int unset_allmulti = 0;
+ int s = splimp();
+
+ switch (ifr->ifr_addr.sa_family) {
+
+ case AF_UNSPEC:
+ bcopy(ifr->ifr_addr.sa_data, addrlo, 6);
+ bcopy(addrlo, addrhi, 6);
+ break;
+
+#ifdef INET
+ case AF_INET:
+ sin = (struct sockaddr_in *)&(ifr->ifr_addr);
+ if (sin->sin_addr.s_addr == INADDR_ANY) {
+ /*
+ * An IP address of INADDR_ANY means stop listening
+ * to the range of Ethernet multicast addresses used
+ * for IP.
+ */
+ bcopy(ether_ipmulticast_min, addrlo, 6);
+ bcopy(ether_ipmulticast_max, addrhi, 6);
+ unset_allmulti = 1;
+ }
+ else {
+ ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo);
+ bcopy(addrlo, addrhi, 6);
+ }
+ break;
+#endif
+
+ default:
+ splx(s);
+ return (EAFNOSUPPORT);
+ }
+
+ /*
+ * Look up the address in our list.
+ */
+ ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm);
+ if (enm == NULL) {
+ splx(s);
+ return (ENXIO);
+ }
+ if (--enm->enm_refcount != 0) {
+ /*
+ * Still some claims to this record.
+ */
+ splx(s);
+ return (0);
+ }
+ /*
+ * No remaining claims to this record; unlink and free it.
+ */
+ for (p = &enm->enm_ac->ac_multiaddrs;
+ *p != enm;
+ p = &(*p)->enm_next)
+ continue;
+ *p = (*p)->enm_next;
+ free(enm, M_IFMADDR);
+ ac->ac_multicnt--;
+ splx(s);
+ if (unset_allmulti)
+ ac->ac_if.if_flags &= ~IFF_ALLMULTI;
+
+ /*
+ * Return ENETRESET to inform the driver that the list has changed
+ * and its reception filter should be adjusted accordingly.
+ */
+ return (ENETRESET);
+}
+
+SYSCTL_DECL(_net_link);
+SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet");
+
+#if 0
+/*
+ * This is for reference. We have a table-driven version
+ * of the little-endian crc32 generator, which is faster
+ * than the double-loop.
+ */
+uint32_t
+ether_crc32_le(const uint8_t *buf, size_t len)
+{
+ size_t i;
+ uint32_t crc;
+ int bit;
+ uint8_t data;
+
+ crc = 0xffffffff; /* initial value */
+
+ for (i = 0; i < len; i++) {
+ for (data = *buf++, bit = 0; bit < 8; bit++, data >>= 1)
+ carry = (crc ^ data) & 1;
+ crc >>= 1;
+ if (carry)
+ crc = (crc ^ ETHER_CRC_POLY_LE);
+ }
+
+ return (crc);
+}
+#else
+uint32_t
+ether_crc32_le(const uint8_t *buf, size_t len)
+{
+ static const uint32_t crctab[] = {
+ 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
+ 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
+ 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
+ 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
+ };
+ size_t i;
+ uint32_t crc;
+
+ crc = 0xffffffff; /* initial value */
+
+ for (i = 0; i < len; i++) {
+ crc ^= buf[i];
+ crc = (crc >> 4) ^ crctab[crc & 0xf];
+ crc = (crc >> 4) ^ crctab[crc & 0xf];
+ }
+
+ return (crc);
+}
+#endif
+
+uint32_t
+ether_crc32_be(const uint8_t *buf, size_t len)
+{
+ size_t i;
+ uint32_t crc, carry;
+ int bit;
+ uint8_t data;
+
+ crc = 0xffffffff; /* initial value */
+
+ for (i = 0; i < len; i++) {
+ for (data = *buf++, bit = 0; bit < 8; bit++, data >>= 1) {
+ carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
+ crc <<= 1;
+ if (carry)
+ crc = (crc ^ ETHER_CRC_POLY_BE) | carry;
+ }
+ }
+
+ return (crc);
+}
+
+int
+ether_ioctl(struct ifnet *ifp, ioctl_command_t command, caddr_t data)
+{
+ struct ifaddr *ifa = (struct ifaddr *) data;
+ struct ifreq *ifr = (struct ifreq *) data;
+ int error = 0;
+
+ switch (command) {
+ case SIOCSIFADDR:
+ ifp->if_flags |= IFF_UP;
+
+ switch (ifa->ifa_addr->sa_family) {
+#ifdef INET
+ case AF_INET:
+ ifp->if_init(ifp->if_softc); /* before arpwhohas */
+ arp_ifinit((struct arpcom *)ifp, ifa);
+ break;
+#endif
+#ifdef IPX
+ /*
+ * XXX - This code is probably wrong
+ */
+ case AF_IPX:
+ {
+ struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
+ struct arpcom *ac = (struct arpcom *) (ifp->if_softc);
+
+ if (ipx_nullhost(*ina))
+ ina->x_host =
+ *(union ipx_host *)
+ ac->ac_enaddr;
+ else {
+ bcopy((caddr_t) ina->x_host.c_host,
+ (caddr_t) ac->ac_enaddr,
+ sizeof(ac->ac_enaddr));
+ }
+
+ /*
+ * Set new address
+ */
+ ifp->if_init(ifp->if_softc);
+ break;
+ }
+#endif
+ default:
+ ifp->if_init(ifp->if_softc);
+ break;
+ }
+ break;
+
+ case SIOCGIFADDR:
+ {
+ struct sockaddr *sa;
+
+ sa = (struct sockaddr *) & ifr->ifr_data;
+ bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr,
+ (caddr_t) sa->sa_data, ETHER_ADDR_LEN);
+ }
+ break;
+
+ case SIOCSIFMTU:
+ /*
+ * Set the interface MTU.
+ */
+ if (ifr->ifr_mtu > ETHERMTU) {
+ error = EINVAL;
+ } else {
+ ifp->if_mtu = ifr->ifr_mtu;
+ }
+ break;
+ default:
+ error = EINVAL; /* XXX netbsd has ENOTTY??? */
+ break;
+ }
+ return (error);
+}
diff --git a/cpukit/libnetworking/net/if_llc.h b/cpukit/libnetworking/net/if_llc.h
new file mode 100644
index 0000000000..fb38dd51e1
--- /dev/null
+++ b/cpukit/libnetworking/net/if_llc.h
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_llc.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if_llc.h,v 1.13 2006/12/01 17:50:11 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_IF_LLC_H_
+#define _NET_IF_LLC_H_
+
+#ifndef __packed
+#if defined(__GNUC__)
+#define __packed __attribute__((packed))
+#else
+#define __packed
+#endif
+#endif
+
+/*
+ * IEEE 802.2 Link Level Control headers, for use in conjunction with
+ * 802.{3,4,5} media access control methods.
+ *
+ * Headers here do not use bit fields due to shortcomings in many
+ * compilers.
+ */
+
+struct llc {
+ u_int8_t llc_dsap;
+ u_int8_t llc_ssap;
+ union {
+ struct {
+ u_int8_t control;
+ u_int8_t format_id;
+ u_int8_t class;
+ u_int8_t window_x2;
+ } __packed type_u;
+ struct {
+ u_int8_t num_snd_x2;
+ u_int8_t num_rcv_x2;
+ } __packed type_i;
+ struct {
+ u_int8_t control;
+ u_int8_t num_rcv_x2;
+ } __packed type_s;
+ struct {
+ u_int8_t control;
+ /*
+ * We cannot put the following fields in a structure because
+ * the structure rounding might cause padding.
+ */
+ u_int8_t frmr_rej_pdu0;
+ u_int8_t frmr_rej_pdu1;
+ u_int8_t frmr_control;
+ u_int8_t frmr_control_ext;
+ u_int8_t frmr_cause;
+ } __packed type_frmr;
+ struct {
+ u_int8_t control;
+ u_int8_t org_code[3];
+ u_int16_t ether_type;
+ } __packed type_snap;
+ struct {
+ u_int8_t control;
+ u_int8_t control_ext;
+ } __packed type_raw;
+ } __packed llc_un;
+} __packed;
+
+struct frmrinfo {
+ u_int8_t frmr_rej_pdu0;
+ u_int8_t frmr_rej_pdu1;
+ u_int8_t frmr_control;
+ u_int8_t frmr_control_ext;
+ u_int8_t frmr_cause;
+} __packed;
+
+#define llc_control llc_un.type_u.control
+#define llc_control_ext llc_un.type_raw.control_ext
+#define llc_fid llc_un.type_u.format_id
+#define llc_class llc_un.type_u.class
+#define llc_window llc_un.type_u.window_x2
+#define llc_frmrinfo llc_un.type_frmr.frmr_rej_pdu0
+#define llc_frmr_pdu0 llc_un.type_frmr.frmr_rej_pdu0
+#define llc_frmr_pdu1 llc_un.type_frmr.frmr_rej_pdu1
+#define llc_frmr_control llc_un.type_frmr.frmr_control
+#define llc_frmr_control_ext llc_un.type_frmr.frmr_control_ext
+#define llc_frmr_cause llc_un.type_frmr.frmr_cause
+#define llc_snap llc_un.type_snap
+
+/*
+ * Don't use sizeof(struct llc_un) for LLC header sizes
+ */
+#define LLC_ISFRAMELEN 4
+#define LLC_UFRAMELEN 3
+#define LLC_FRMRLEN 7
+#define LLC_SNAPFRAMELEN 8
+
+/*
+ * Unnumbered LLC format commands
+ */
+#define LLC_UI 0x3
+#define LLC_UI_P 0x13
+#define LLC_DISC 0x43
+#define LLC_DISC_P 0x53
+#define LLC_UA 0x63
+#define LLC_UA_P 0x73
+#define LLC_TEST 0xe3
+#define LLC_TEST_P 0xf3
+#define LLC_FRMR 0x87
+#define LLC_FRMR_P 0x97
+#define LLC_DM 0x0f
+#define LLC_DM_P 0x1f
+#define LLC_XID 0xaf
+#define LLC_XID_P 0xbf
+#define LLC_SABME 0x6f
+#define LLC_SABME_P 0x7f
+
+/*
+ * Supervisory LLC commands
+ */
+#define LLC_RR 0x01
+#define LLC_RNR 0x05
+#define LLC_REJ 0x09
+
+/*
+ * Info format - dummy only
+ */
+#define LLC_INFO 0x00
+
+/*
+ * ISO PDTR 10178 contains among others
+ */
+#define LLC_X25_LSAP 0x7e
+#define LLC_SNAP_LSAP 0xaa
+#define LLC_ISO_LSAP 0xfe
+
+#endif /* _NET_IF_LLC_H_ */
diff --git a/cpukit/libnetworking/net/if_loop.c b/cpukit/libnetworking/net/if_loop.c
new file mode 100644
index 0000000000..ed8b309991
--- /dev/null
+++ b/cpukit/libnetworking/net/if_loop.c
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_loop.c 8.2 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/net/if_loop.c,v 1.104 2005/02/24 01:34:01 sam Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Loopback interface driver for protocol testing and timing.
+ */
+#include "loop.h"
+#if NLOOP > 0
+
+#include "opt_atalk.h"
+#include "opt_inet.h"
+#include "opt_inet6.h"
+#include "opt_ipx.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/netisr.h>
+#include <net/route.h>
+#include <net/bpf.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#endif
+
+#ifdef IPX
+#include <netipx/ipx.h>
+#include <netipx/ipx_if.h>
+#endif
+
+#ifdef INET6
+#ifndef INET
+#include <netinet/in.h>
+#endif
+#include <netinet6/in6_var.h>
+#include <netinet/ip6.h>
+#endif
+
+#ifdef NETATALK
+#include <netatalk/at.h>
+#include <netatalk/at_var.h>
+#endif
+
+static int loioctl(struct ifnet *, ioctl_command_t, caddr_t);
+static void lortrequest(int, struct rtentry *, struct sockaddr *);
+
+#ifdef TINY_LOMTU
+#define LOMTU (1024+512)
+#elif defined(LARGE_LOMTU)
+#define LOMTU 131072
+#else
+#define LOMTU 16384
+#endif
+
+struct ifnet loif[NLOOP];
+
+void
+rtems_bsdnet_initialize_loop(void)
+{
+ register struct ifnet *ifp;
+ register int i = 0;
+
+ for (ifp = loif; i < NLOOP; ifp++) {
+ ifp->if_name = "lo";
+ ifp->if_next = NULL;
+ ifp->if_unit = i++;
+ ifp->if_mtu = LOMTU;
+ ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST;
+ ifp->if_ioctl = loioctl;
+ ifp->if_output = looutput;
+ ifp->if_type = IFT_LOOP;
+ ifp->if_hdrlen = 0;
+ ifp->if_addrlen = 0;
+ ifp->if_snd.ifq_maxlen = ifqmaxlen;
+ if_attach(ifp);
+#if NBPFILTER > 0
+ bpfattach(ifp, DLT_NULL, sizeof(u_int));
+#endif
+ }
+}
+
+int
+looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
+ struct rtentry *rt)
+{
+ int s, isr;
+ register struct ifqueue *ifq = 0;
+
+ if ((m->m_flags & M_PKTHDR) == 0)
+ panic("looutput no HDR");
+#if NBPFILTER > 0
+ /* BPF write needs to be handled specially */
+ if (dst->sa_family == AF_UNSPEC) {
+ dst->sa_family = *(mtod(m, int *));
+ m->m_len -= sizeof(int);
+ m->m_pkthdr.len -= sizeof(int);
+ m->m_data += sizeof(int);
+ }
+
+ /* Let BPF see incoming packet */
+ if (ifp->if_bpf) {
+ /*
+ * We need to prepend the address family as
+ * a four byte field. Cons up a dummy header
+ * to pacify bpf. This is safe because bpf
+ * will only read from the mbuf (i.e., it won't
+ * try to free it or keep a pointer a to it).
+ */
+ struct mbuf m0;
+ u_int af = dst->sa_family;
+
+ m0.m_next = m;
+ m0.m_len = 4;
+ m0.m_data = (char *)&af;
+
+ bpf_mtap(ifp, &m0);
+ }
+#endif
+ m->m_pkthdr.rcvif = ifp;
+
+ if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
+ m_freem(m);
+ return (rt->rt_flags & RTF_BLACKHOLE ? 0 :
+ rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH);
+ }
+ ifp->if_opackets++;
+ ifp->if_obytes += m->m_pkthdr.len;
+ switch (dst->sa_family) {
+
+#ifdef INET
+ case AF_INET:
+ ifq = &ipintrq;
+ isr = NETISR_IP;
+ break;
+#endif
+#ifdef IPX
+ case AF_IPX:
+ ifq = &ipxintrq;
+ isr = NETISR_IPX;
+ break;
+#endif
+#ifdef NETATALK
+ case AF_APPLETALK:
+ ifq = &atintrq2;
+ isr = NETISR_ATALK;
+ break;
+#endif /* NETATALK */
+ default:
+ printf("lo%d: can't handle af%d\n", ifp->if_unit,
+ dst->sa_family);
+ m_freem(m);
+ return (EAFNOSUPPORT);
+ }
+ s = splimp();
+ if (IF_QFULL(ifq)) {
+ IF_DROP(ifq);
+ m_freem(m);
+ splx(s);
+ return (ENOBUFS);
+ }
+ IF_ENQUEUE(ifq, m);
+ schednetisr(isr);
+ ifp->if_ipackets++;
+ ifp->if_ibytes += m->m_pkthdr.len;
+ splx(s);
+ return (0);
+}
+
+static void
+lortrequest(int cmd, struct rtentry *rt, struct sockaddr *sa)
+{
+ if (rt) {
+ rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */
+ /*
+ * For optimal performance, the send and receive buffers
+ * should be at least twice the MTU plus a little more for
+ * overhead.
+ */
+ rt->rt_rmx.rmx_recvpipe =
+ rt->rt_rmx.rmx_sendpipe = 3L * (long)LOMTU;
+ }
+}
+
+/*
+ * Process an ioctl request.
+ */
+static int
+loioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data)
+{
+ register struct ifaddr *ifa;
+ register struct ifreq *ifr = (struct ifreq *)data;
+ register int error = 0;
+
+ switch (cmd) {
+
+ case SIOCSIFADDR:
+ ifp->if_flags |= IFF_UP | IFF_RUNNING;
+ ifa = (struct ifaddr *)data;
+ ifa->ifa_rtrequest = lortrequest;
+ /*
+ * Everything else is done at a higher level.
+ */
+ break;
+
+ case SIOCADDMULTI:
+ case SIOCDELMULTI:
+ if (ifr == 0) {
+ error = EAFNOSUPPORT; /* XXX */
+ break;
+ }
+ switch (ifr->ifr_addr.sa_family) {
+
+#ifdef INET
+ case AF_INET:
+ break;
+#endif
+#ifdef INET6
+ case AF_INET6:
+ break;
+#endif
+
+ default:
+ error = EAFNOSUPPORT;
+ break;
+ }
+ break;
+
+ case SIOCSIFMTU:
+ ifp->if_mtu = ifr->ifr_mtu;
+ break;
+
+ case SIOCSIFFLAGS:
+ break;
+
+ default:
+ error = EINVAL;
+ }
+ return (error);
+}
+#endif /* NLOOP > 0 */
diff --git a/cpukit/libnetworking/net/if_media.h b/cpukit/libnetworking/net/if_media.h
new file mode 100644
index 0000000000..9a2b179061
--- /dev/null
+++ b/cpukit/libnetworking/net/if_media.h
@@ -0,0 +1,531 @@
+/* $NetBSD: if_media.h,v 1.3 1997/03/26 01:19:27 thorpej Exp $ */
+/* $FreeBSD: src/sys/net/if_media.h,v 1.26 2004/01/26 11:52:32 harti Exp $ */
+
+/*
+ * Copyright (c) 1997
+ * Jonathan Stone and Jason R. Thorpe. All rights reserved.
+ *
+ * This software is derived from information provided by Matt Thomas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Jonathan Stone
+ * and Jason R. Thorpe for the NetBSD Project.
+ * 4. The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _NET_IF_MEDIA_H_
+#define _NET_IF_MEDIA_H_
+
+/*
+ * Prototypes and definitions for BSD/OS-compatible network interface
+ * media selection.
+ *
+ * Where it is safe to do so, this code strays slightly from the BSD/OS
+ * design. Software which uses the API (device drivers, basically)
+ * shouldn't notice any difference.
+ *
+ * Many thanks to Matt Thomas for providing the information necessary
+ * to implement this interface.
+ */
+
+#ifdef _KERNEL
+
+#include <sys/queue.h>
+
+/*
+ * Driver callbacks for media status and change requests.
+ */
+typedef int (*ifm_change_cb_t)(struct ifnet *ifp);
+typedef void (*ifm_stat_cb_t)(struct ifnet *ifp, struct ifmediareq *req);
+
+/*
+ * In-kernel representation of a single supported media type.
+ */
+struct ifmedia_entry {
+ LIST_ENTRY(ifmedia_entry) ifm_list;
+ int ifm_media; /* description of this media attachment */
+ int ifm_data; /* for driver-specific use */
+ void *ifm_aux; /* for driver-specific use */
+};
+
+/*
+ * One of these goes into a network interface's softc structure.
+ * It is used to keep general media state.
+ */
+struct ifmedia {
+ int ifm_mask; /* mask of changes we don't care about */
+ int ifm_media; /* current user-set media word */
+ struct ifmedia_entry *ifm_cur; /* currently selected media */
+ LIST_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
+ ifm_change_cb_t ifm_change; /* media change driver callback */
+ ifm_stat_cb_t ifm_status; /* media status driver callback */
+};
+
+/* Initialize an interface's struct if_media field. */
+void ifmedia_init(struct ifmedia *ifm, int dontcare_mask,
+ ifm_change_cb_t change_callback, ifm_stat_cb_t status_callback);
+
+/* Remove all mediums from a struct ifmedia. */
+void ifmedia_removeall( struct ifmedia *ifm);
+
+/* Add one supported medium to a struct ifmedia. */
+void ifmedia_add(struct ifmedia *ifm, int mword, int data, void *aux);
+
+/* Add an array (of ifmedia_entry) media to a struct ifmedia. */
+void ifmedia_list_add(struct ifmedia *mp, struct ifmedia_entry *lp,
+ int count);
+
+/* Set default media type on initialization. */
+void ifmedia_set(struct ifmedia *ifm, int mword);
+
+/* Common ioctl function for getting/setting media, called by driver. */
+int ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr,
+ struct ifmedia *ifm, u_long cmd);
+
+#endif /*_KERNEL */
+
+/*
+ * if_media Options word:
+ * Bits Use
+ * ---- -------
+ * 0-4 Media variant
+ * 5-7 Media type
+ * 8-15 Type specific options
+ * 16-18 Mode (for multi-mode devices)
+ * 19 RFU
+ * 20-27 Shared (global) options
+ * 28-31 Instance
+ */
+
+/*
+ * Ethernet
+ */
+#define IFM_ETHER 0x00000020
+#define IFM_10_T 3 /* 10BaseT - RJ45 */
+#define IFM_10_2 4 /* 10Base2 - Thinnet */
+#define IFM_10_5 5 /* 10Base5 - AUI */
+#define IFM_100_TX 6 /* 100BaseTX - RJ45 */
+#define IFM_100_FX 7 /* 100BaseFX - Fiber */
+#define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */
+#define IFM_100_VG 9 /* 100VG-AnyLAN */
+#define IFM_100_T2 10 /* 100BaseT2 */
+#define IFM_1000_SX 11 /* 1000BaseSX - multi-mode fiber */
+#define IFM_10_STP 12 /* 10BaseT over shielded TP */
+#define IFM_10_FL 13 /* 10BaseFL - Fiber */
+#define IFM_1000_LX 14 /* 1000baseLX - single-mode fiber */
+#define IFM_1000_CX 15 /* 1000baseCX - 150ohm STP */
+#define IFM_1000_T 16 /* 1000baseT - 4 pair cat 5 */
+#define IFM_HPNA_1 17 /* HomePNA 1.0 (1Mb/s) */
+/* note 31 is the max! */
+
+#define IFM_ETH_MASTER 0x00000100 /* master mode (1000baseT) */
+
+/*
+ * Token ring
+ */
+#define IFM_TOKEN 0x00000040
+#define IFM_TOK_STP4 3 /* Shielded twisted pair 4m - DB9 */
+#define IFM_TOK_STP16 4 /* Shielded twisted pair 16m - DB9 */
+#define IFM_TOK_UTP4 5 /* Unshielded twisted pair 4m - RJ45 */
+#define IFM_TOK_UTP16 6 /* Unshielded twisted pair 16m - RJ45 */
+#define IFM_TOK_STP100 7 /* Shielded twisted pair 100m - DB9 */
+#define IFM_TOK_UTP100 8 /* Unshielded twisted pair 100m - RJ45 */
+#define IFM_TOK_ETR 0x00000200 /* Early token release */
+#define IFM_TOK_SRCRT 0x00000400 /* Enable source routing features */
+#define IFM_TOK_ALLR 0x00000800 /* All routes / Single route bcast */
+#define IFM_TOK_DTR 0x00002000 /* Dedicated token ring */
+#define IFM_TOK_CLASSIC 0x00004000 /* Classic token ring */
+#define IFM_TOK_AUTO 0x00008000 /* Automatic Dedicate/Classic token ring */
+
+/*
+ * FDDI
+ */
+#define IFM_FDDI 0x00000060
+#define IFM_FDDI_SMF 3 /* Single-mode fiber */
+#define IFM_FDDI_MMF 4 /* Multi-mode fiber */
+#define IFM_FDDI_UTP 5 /* CDDI / UTP */
+#define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */
+
+/*
+ * IEEE 802.11 Wireless
+ */
+#define IFM_IEEE80211 0x00000080
+/* NB: 0,1,2 are auto, manual, none defined below */
+#define IFM_IEEE80211_FH1 3 /* Frequency Hopping 1Mbps */
+#define IFM_IEEE80211_FH2 4 /* Frequency Hopping 2Mbps */
+#define IFM_IEEE80211_DS1 5 /* Direct Sequence 1Mbps */
+#define IFM_IEEE80211_DS2 6 /* Direct Sequence 2Mbps */
+#define IFM_IEEE80211_DS5 7 /* Direct Sequence 5.5Mbps */
+#define IFM_IEEE80211_DS11 8 /* Direct Sequence 11Mbps */
+#define IFM_IEEE80211_DS22 9 /* Direct Sequence 22Mbps */
+#define IFM_IEEE80211_OFDM6 10 /* OFDM 6Mbps */
+#define IFM_IEEE80211_OFDM9 11 /* OFDM 9Mbps */
+#define IFM_IEEE80211_OFDM12 12 /* OFDM 12Mbps */
+#define IFM_IEEE80211_OFDM18 13 /* OFDM 18Mbps */
+#define IFM_IEEE80211_OFDM24 14 /* OFDM 24Mbps */
+#define IFM_IEEE80211_OFDM36 15 /* OFDM 36Mbps */
+#define IFM_IEEE80211_OFDM48 16 /* OFDM 48Mbps */
+#define IFM_IEEE80211_OFDM54 17 /* OFDM 54Mbps */
+#define IFM_IEEE80211_OFDM72 18 /* OFDM 72Mbps */
+
+#define IFM_IEEE80211_ADHOC 0x00000100 /* Operate in Adhoc mode */
+#define IFM_IEEE80211_HOSTAP 0x00000200 /* Operate in Host AP mode */
+#define IFM_IEEE80211_IBSS 0x00000400 /* Operate in IBSS mode */
+#define IFM_IEEE80211_IBSSMASTER 0x00000800 /* Operate as an IBSS master */
+#define IFM_IEEE80211_TURBO 0x00001000 /* Operate in turbo mode */
+#define IFM_IEEE80211_MONITOR 0x00002000 /* Operate in monitor mode */
+
+/* operating mode for multi-mode devices */
+#define IFM_IEEE80211_11A 0x00010000 /* 5Ghz, OFDM mode */
+#define IFM_IEEE80211_11B 0x00020000 /* Direct Sequence mode */
+#define IFM_IEEE80211_11G 0x00030000 /* 2Ghz, CCK mode */
+#define IFM_IEEE80211_FH 0x00040000 /* 2Ghz, GFSK mode */
+
+/*
+ * ATM
+ */
+#define IFM_ATM 0x000000a0
+#define IFM_ATM_UNKNOWN 3
+#define IFM_ATM_UTP_25 4
+#define IFM_ATM_TAXI_100 5
+#define IFM_ATM_TAXI_140 6
+#define IFM_ATM_MM_155 7
+#define IFM_ATM_SM_155 8
+#define IFM_ATM_UTP_155 9
+#define IFM_ATM_MM_622 10
+#define IFM_ATM_SM_622 11
+#define IFM_ATM_VIRTUAL 12
+#define IFM_ATM_SDH 0x00000100 /* SDH instead of SONET */
+#define IFM_ATM_NOSCRAMB 0x00000200 /* no scrambling */
+#define IFM_ATM_UNASSIGNED 0x00000400 /* unassigned cells */
+
+/*
+ * Shared media sub-types
+ */
+#define IFM_AUTO 0 /* Autoselect best media */
+#define IFM_MANUAL 1 /* Jumper/dipswitch selects media */
+#define IFM_NONE 2 /* Deselect all media */
+
+/*
+ * Shared options
+ */
+#define IFM_FDX 0x00100000 /* Force full duplex */
+#define IFM_HDX 0x00200000 /* Force half duplex */
+#define IFM_FLAG0 0x01000000 /* Driver defined flag */
+#define IFM_FLAG1 0x02000000 /* Driver defined flag */
+#define IFM_FLAG2 0x04000000 /* Driver defined flag */
+#define IFM_LOOP 0x08000000 /* Put hardware in loopback */
+
+/*
+ * Masks
+ */
+#define IFM_NMASK 0x000000e0 /* Network type */
+#define IFM_TMASK 0x0000001f /* Media sub-type */
+#define IFM_IMASK 0xf0000000 /* Instance */
+#define IFM_ISHIFT 28 /* Instance shift */
+#define IFM_OMASK 0x0000ff00 /* Type specific options */
+#define IFM_MMASK 0x00070000 /* Mode */
+#define IFM_MSHIFT 16 /* Mode shift */
+#define IFM_GMASK 0x0ff00000 /* Global options */
+
+/*
+ * Status bits
+ */
+/*
+ * FIXME: This is a hack to get the libbsdport interface drivers working. See
+ * also rtems_mii_ioctl.h.
+ */
+#define IFM_AVALID IFM_FLAG0 /* Active bit valid */
+#define IFM_ACTIVE IFM_FLAG0 /* Interface attached to working net */
+
+/*
+ * Macros to extract various bits of information from the media word.
+ */
+#define IFM_TYPE(x) ((x) & IFM_NMASK)
+#define IFM_SUBTYPE(x) ((x) & IFM_TMASK)
+#define IFM_TYPE_OPTIONS(x) ((x) & IFM_OMASK)
+#define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT)
+#define IFM_OPTIONS(x) ((x) & (IFM_OMASK|IFM_GMASK))
+#define IFM_MODE(x) ((x) & IFM_MMASK)
+
+#define IFM_INST_MAX IFM_INST(IFM_IMASK)
+
+/*
+ * Macro to create a media word.
+ */
+#define IFM_MAKEWORD(type, subtype, options, instance) \
+ ((type) | (subtype) | (options) | ((uint32_t)(instance) << IFM_ISHIFT))
+#define IFM_MAKEMODE(mode) \
+ (((mode) << IFM_MSHIFT) & IFM_MMASK)
+
+/*
+ * NetBSD extension not defined in the BSDI API. This is used in various
+ * places to get the canonical description for a given type/subtype.
+ *
+ * NOTE: all but the top-level type descriptions must contain NO whitespace!
+ * Otherwise, parsing these in ifconfig(8) would be a nightmare.
+ */
+struct ifmedia_description {
+ int ifmt_word; /* word value; may be masked */
+ const char *ifmt_string; /* description */
+};
+
+#define IFM_TYPE_DESCRIPTIONS { \
+ { IFM_ETHER, "Ethernet" }, \
+ { IFM_TOKEN, "Token ring" }, \
+ { IFM_FDDI, "FDDI" }, \
+ { IFM_IEEE80211, "IEEE 802.11 Wireless Ethernet" }, \
+ { IFM_ATM, "ATM" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_ETHERNET_DESCRIPTIONS { \
+ { IFM_10_T, "10baseT/UTP" }, \
+ { IFM_10_2, "10base2/BNC" }, \
+ { IFM_10_5, "10base5/AUI" }, \
+ { IFM_100_TX, "100baseTX" }, \
+ { IFM_100_FX, "100baseFX" }, \
+ { IFM_100_T4, "100baseT4" }, \
+ { IFM_100_VG, "100baseVG" }, \
+ { IFM_100_T2, "100baseT2" }, \
+ { IFM_10_STP, "10baseSTP" }, \
+ { IFM_10_FL, "10baseFL" }, \
+ { IFM_1000_SX, "1000baseSX" }, \
+ { IFM_1000_LX, "1000baseLX" }, \
+ { IFM_1000_CX, "1000baseCX" }, \
+ { IFM_1000_T, "1000baseTX" }, \
+ { IFM_1000_T, "1000baseT" }, \
+ { IFM_HPNA_1, "homePNA" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_ETHERNET_ALIASES { \
+ { IFM_10_T, "UTP" }, \
+ { IFM_10_T, "10UTP" }, \
+ { IFM_10_2, "BNC" }, \
+ { IFM_10_2, "10BNC" }, \
+ { IFM_10_5, "AUI" }, \
+ { IFM_10_5, "10AUI" }, \
+ { IFM_100_TX, "100TX" }, \
+ { IFM_100_T4, "100T4" }, \
+ { IFM_100_VG, "100VG" }, \
+ { IFM_100_T2, "100T2" }, \
+ { IFM_10_STP, "10STP" }, \
+ { IFM_10_FL, "10FL" }, \
+ { IFM_1000_SX, "1000SX" }, \
+ { IFM_1000_LX, "1000LX" }, \
+ { IFM_1000_CX, "1000CX" }, \
+ { IFM_1000_T, "1000TX" }, \
+ { IFM_1000_T, "1000T" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS { \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_TOKENRING_DESCRIPTIONS { \
+ { IFM_TOK_STP4, "DB9/4Mbit" }, \
+ { IFM_TOK_STP16, "DB9/16Mbit" }, \
+ { IFM_TOK_UTP4, "UTP/4Mbit" }, \
+ { IFM_TOK_UTP16, "UTP/16Mbit" }, \
+ { IFM_TOK_STP100, "STP/100Mbit" }, \
+ { IFM_TOK_UTP100, "UTP/100Mbit" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_TOKENRING_ALIASES { \
+ { IFM_TOK_STP4, "4STP" }, \
+ { IFM_TOK_STP16, "16STP" }, \
+ { IFM_TOK_UTP4, "4UTP" }, \
+ { IFM_TOK_UTP16, "16UTP" }, \
+ { IFM_TOK_STP100, "100STP" }, \
+ { IFM_TOK_UTP100, "100UTP" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS { \
+ { IFM_TOK_ETR, "EarlyTokenRelease" }, \
+ { IFM_TOK_SRCRT, "SourceRouting" }, \
+ { IFM_TOK_ALLR, "AllRoutes" }, \
+ { IFM_TOK_DTR, "Dedicated" }, \
+ { IFM_TOK_CLASSIC,"Classic" }, \
+ { IFM_TOK_AUTO, " " }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_FDDI_DESCRIPTIONS { \
+ { IFM_FDDI_SMF, "Single-mode" }, \
+ { IFM_FDDI_MMF, "Multi-mode" }, \
+ { IFM_FDDI_UTP, "UTP" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_FDDI_ALIASES { \
+ { IFM_FDDI_SMF, "SMF" }, \
+ { IFM_FDDI_MMF, "MMF" }, \
+ { IFM_FDDI_UTP, "CDDI" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS { \
+ { IFM_FDDI_DA, "Dual-attach" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_IEEE80211_DESCRIPTIONS { \
+ { IFM_IEEE80211_FH1, "FH/1Mbps" }, \
+ { IFM_IEEE80211_FH2, "FH/2Mbps" }, \
+ { IFM_IEEE80211_DS1, "DS/1Mbps" }, \
+ { IFM_IEEE80211_DS2, "DS/2Mbps" }, \
+ { IFM_IEEE80211_DS5, "DS/5.5Mbps" }, \
+ { IFM_IEEE80211_DS11, "DS/11Mbps" }, \
+ { IFM_IEEE80211_DS22, "DS/22Mbps" }, \
+ { IFM_IEEE80211_OFDM6, "OFDM/6Mbps" }, \
+ { IFM_IEEE80211_OFDM9, "OFDM/9Mbps" }, \
+ { IFM_IEEE80211_OFDM12, "OFDM/12Mbps" }, \
+ { IFM_IEEE80211_OFDM18, "OFDM/18Mbps" }, \
+ { IFM_IEEE80211_OFDM24, "OFDM/24Mbps" }, \
+ { IFM_IEEE80211_OFDM36, "OFDM/36Mbps" }, \
+ { IFM_IEEE80211_OFDM48, "OFDM/48Mbps" }, \
+ { IFM_IEEE80211_OFDM54, "OFDM/54Mbps" }, \
+ { IFM_IEEE80211_OFDM72, "OFDM/72Mbps" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_IEEE80211_ALIASES { \
+ { IFM_IEEE80211_FH1, "FH1" }, \
+ { IFM_IEEE80211_FH2, "FH2" }, \
+ { IFM_IEEE80211_FH1, "FrequencyHopping/1Mbps" }, \
+ { IFM_IEEE80211_FH2, "FrequencyHopping/2Mbps" }, \
+ { IFM_IEEE80211_DS1, "DS1" }, \
+ { IFM_IEEE80211_DS2, "DS2" }, \
+ { IFM_IEEE80211_DS5, "DS5.5" }, \
+ { IFM_IEEE80211_DS11, "DS11" }, \
+ { IFM_IEEE80211_DS22, "DS22" }, \
+ { IFM_IEEE80211_DS1, "DirectSequence/1Mbps" }, \
+ { IFM_IEEE80211_DS2, "DirectSequence/2Mbps" }, \
+ { IFM_IEEE80211_DS5, "DirectSequence/5.5Mbps" }, \
+ { IFM_IEEE80211_DS11, "DirectSequence/11Mbps" }, \
+ { IFM_IEEE80211_DS22, "DirectSequence/22Mbps" }, \
+ { IFM_IEEE80211_OFDM6, "OFDM6" }, \
+ { IFM_IEEE80211_OFDM9, "OFDM9" }, \
+ { IFM_IEEE80211_OFDM12, "OFDM12" }, \
+ { IFM_IEEE80211_OFDM18, "OFDM18" }, \
+ { IFM_IEEE80211_OFDM24, "OFDM24" }, \
+ { IFM_IEEE80211_OFDM36, "OFDM36" }, \
+ { IFM_IEEE80211_OFDM48, "OFDM48" }, \
+ { IFM_IEEE80211_OFDM54, "OFDM54" }, \
+ { IFM_IEEE80211_OFDM72, "OFDM72" }, \
+ { IFM_IEEE80211_DS1, "CCK1" }, \
+ { IFM_IEEE80211_DS2, "CCK2" }, \
+ { IFM_IEEE80211_DS5, "CCK5.5" }, \
+ { IFM_IEEE80211_DS11, "CCK11" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS { \
+ { IFM_IEEE80211_ADHOC, "adhoc" }, \
+ { IFM_IEEE80211_HOSTAP, "hostap" }, \
+ { IFM_IEEE80211_IBSS, "ibss" }, \
+ { IFM_IEEE80211_IBSSMASTER, "ibss-master" }, \
+ { IFM_IEEE80211_TURBO, "turbo" }, \
+ { IFM_IEEE80211_MONITOR, "monitor" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS { \
+ { IFM_AUTO, "autoselect" }, \
+ { IFM_IEEE80211_11A, "11a" }, \
+ { IFM_IEEE80211_11B, "11b" }, \
+ { IFM_IEEE80211_11G, "11g" }, \
+ { IFM_IEEE80211_FH, "fh" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_IEEE80211_MODE_ALIASES { \
+ { IFM_AUTO, "auto" }, \
+ { 0, NULL }, \
+}
+
+# define IFM_SUBTYPE_ATM_DESCRIPTIONS { \
+ { IFM_ATM_UNKNOWN, "Unknown" }, \
+ { IFM_ATM_UTP_25, "UTP/25.6MBit" }, \
+ { IFM_ATM_TAXI_100, "Taxi/100MBit" }, \
+ { IFM_ATM_TAXI_140, "Taxi/140MBit" }, \
+ { IFM_ATM_MM_155, "Multi-mode/155MBit" }, \
+ { IFM_ATM_SM_155, "Single-mode/155MBit" }, \
+ { IFM_ATM_UTP_155, "UTP/155MBit" }, \
+ { IFM_ATM_MM_622, "Multi-mode/622MBit" }, \
+ { IFM_ATM_SM_622, "Single-mode/622MBit" }, \
+ { IFM_ATM_VIRTUAL, "Virtual" }, \
+ { 0, NULL }, \
+}
+
+# define IFM_SUBTYPE_ATM_ALIASES { \
+ { IFM_ATM_UNKNOWN, "UNKNOWN" }, \
+ { IFM_ATM_UTP_25, "UTP-25" }, \
+ { IFM_ATM_TAXI_100, "TAXI-100" }, \
+ { IFM_ATM_TAXI_140, "TAXI-140" }, \
+ { IFM_ATM_MM_155, "MM-155" }, \
+ { IFM_ATM_SM_155, "SM-155" }, \
+ { IFM_ATM_UTP_155, "UTP-155" }, \
+ { IFM_ATM_MM_622, "MM-622" }, \
+ { IFM_ATM_SM_622, "SM-622" }, \
+ { IFM_ATM_VIRTUAL, "VIRTUAL" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS { \
+ { IFM_ATM_SDH, "SDH" }, \
+ { IFM_ATM_NOSCRAMB, "Noscramb" }, \
+ { IFM_ATM_UNASSIGNED, "Unassigned" }, \
+ { 0, NULL }, \
+}
+
+
+#define IFM_SUBTYPE_SHARED_DESCRIPTIONS { \
+ { IFM_AUTO, "autoselect" }, \
+ { IFM_MANUAL, "manual" }, \
+ { IFM_NONE, "none" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SUBTYPE_SHARED_ALIASES { \
+ { IFM_AUTO, "auto" }, \
+ { 0, NULL }, \
+}
+
+#define IFM_SHARED_OPTION_DESCRIPTIONS { \
+ { IFM_FDX, "full-duplex" }, \
+ { IFM_HDX, "half-duplex" }, \
+ { IFM_FLAG0, "flag0" }, \
+ { IFM_FLAG1, "flag1" }, \
+ { IFM_FLAG2, "flag2" }, \
+ { IFM_LOOP, "hw-loopback" }, \
+ { 0, NULL }, \
+}
+
+#endif /* _NET_IF_MEDIA_H_ */
diff --git a/cpukit/libnetworking/net/if_ppp.c b/cpukit/libnetworking/net/if_ppp.c
new file mode 100644
index 0000000000..8f5f27aea8
--- /dev/null
+++ b/cpukit/libnetworking/net/if_ppp.c
@@ -0,0 +1,1751 @@
+/*
+ * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
+ */
+
+/*-
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Drew D. Perkins
+ * Carnegie Mellon University
+ * 4910 Forbes Ave.
+ * Pittsburgh, PA 15213
+ * (412) 268-8576
+ * ddp@andrew.cmu.edu
+ *
+ * Based on:
+ * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89
+ *
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Serial Line interface
+ *
+ * Rick Adams
+ * Center for Seismic Studies
+ * 1300 N 17th Street, Suite 1450
+ * Arlington, Virginia 22209
+ * (703)276-7900
+ * rick@seismo.ARPA
+ * seismo!rick
+ *
+ * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
+ * Converted to 4.3BSD Beta by Chris Torek.
+ * Other changes made at Berkeley, based in part on code by Kirk Smith.
+ *
+ * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
+ * Added VJ tcp header compression; more unified ioctls
+ *
+ * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
+ * Cleaned up a lot of the mbuf-related code to fix bugs that
+ * caused system crashes and packet corruption. Changed pppstart
+ * so that it doesn't just give up with a collision if the whole
+ * packet doesn't fit in the output ring buffer.
+ *
+ * Added priority queueing for interactive IP packets, following
+ * the model of if_sl.c, plus hooks for bpf.
+ * Paul Mackerras (paulus@cs.anu.edu.au).
+ */
+
+/* $FreeBSD: src/sys/net/if_ppp.c,v 1.109 2005/10/12 19:52:16 thompsa Exp $ */
+/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
+/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_inet.h"
+#include "opt_ipx.h"
+#include "opt_mac.h"
+#include "opt_ppp.h"
+
+#if NPPP > 0
+
+#include <termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/kernel.h>
+#include <sys/time.h>
+#include <sys/malloc.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/netisr.h>
+#include <net/route.h>
+#ifdef PPP_FILTER
+#include <net/bpf.h>
+#endif
+
+#if INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#endif
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+
+#ifdef VJC
+#include <net/slcompress.h>
+#endif
+
+#include <net/ppp_defs.h>
+#include <net/if_ppp.h>
+#include <net/if_pppvar.h>
+#include <machine/cpu.h>
+
+#define splsoftnet splnet
+
+#ifdef PPP_COMPRESS
+#define PACKETPTR struct mbuf *
+#include <net/ppp-comp.h>
+#endif
+
+static struct ppp_softc ppp_softc[NPPP];
+
+static int pppsioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data);
+static void ppp_requeue(struct ppp_softc *);
+#ifdef PPP_COMPRESS
+static void ppp_ccp(struct ppp_softc *, struct mbuf *m, int rcvd);
+static void ppp_ccp_closed(struct ppp_softc *);
+#endif
+static struct mbuf *ppp_inproc(struct ppp_softc *, struct mbuf *);
+static void pppdumpm(struct mbuf *m0);
+
+/*
+ * Some useful mbuf macros not in mbuf.h.
+ */
+#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
+
+#define M_DATASTART(m) \
+ (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
+ (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
+
+#define M_DATASIZE(m) \
+ (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
+ (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
+
+/*
+ * We steal two bits in the mbuf m_flags, to mark high-priority packets
+ * for output, and received packets following lost/corrupted packets.
+ */
+#define M_HIGHPRI 0x2000 /* output packet for sc_fastq */
+#define M_ERRMARK 0x4000 /* steal a bit in mbuf m_flags */
+
+
+#ifdef PPP_COMPRESS
+/*
+ * List of compressors we know about.
+ * We leave some space so maybe we can modload compressors.
+ */
+
+extern struct compressor ppp_bsd_compress;
+extern struct compressor ppp_deflate, ppp_deflate_draft;
+
+struct compressor *ppp_compressors[8] = {
+#if DO_BSD_COMPRESS
+ &ppp_bsd_compress,
+#endif
+#if DO_DEFLATE
+ &ppp_deflate,
+ &ppp_deflate_draft,
+#endif
+ NULL
+};
+#endif /* PPP_COMPRESS */
+
+extern struct ifqueue ipintrq;
+static struct timeval ppp_time;
+
+#ifndef __rtems__
+TEXT_SET(pseudo_set, ppp_rxdaemon);
+#endif
+
+static rtems_task ppp_rxdaemon(rtems_task_argument arg)
+{
+ rtems_event_set events;
+ rtems_interrupt_level level;
+ struct ppp_softc *sc = (struct ppp_softc *)arg;
+ struct mbuf *mp = (struct mbuf *)0;
+ struct mbuf *m;
+
+ /* enter processing loop */
+ while ( 1 ) {
+ /* wait for event */
+ rtems_event_receive(RX_PACKET|RX_MBUF|RX_EMPTY,RTEMS_WAIT|RTEMS_EVENT_ANY,RTEMS_NO_TIMEOUT,&events);
+ if ( events & RX_EMPTY ) {
+ printf("RX: QUEUE is EMPTY\n");
+ events &= ~RX_EMPTY;
+ }
+
+ if ( events ) {
+ /* get the network semaphore */
+ rtems_bsdnet_semaphore_obtain();
+
+ /* check to see if new packet was received */
+ if ( events & RX_PACKET ) {
+ /* get received packet mbuf chain */
+ rtems_interrupt_disable(level);
+ IF_DEQUEUE(&sc->sc_rawq, m);
+ rtems_interrupt_enable(level);
+
+ /* ensure packet was retrieved */
+ if ( m != (struct mbuf *)0 ) {
+ /* process the received packet */
+ mp = ppp_inproc(sc, m);
+ }
+ }
+
+ /* allocate a new mbuf to replace one */
+ if ( mp == NULL ) {
+ pppallocmbuf(sc, &mp);
+ }
+
+ /* place mbuf on freeq */
+ rtems_interrupt_disable(level);
+ IF_ENQUEUE(&sc->sc_freeq, mp);
+ rtems_interrupt_enable(level);
+ mp = (struct mbuf *)0;
+
+ /* release the network semaphore */
+ rtems_bsdnet_semaphore_release();
+
+ /* check to see if queue is empty */
+ if ( sc->sc_rawq.ifq_head ) {
+ /* queue is not empty - post another event */
+ rtems_event_send(sc->sc_rxtask, RX_PACKET);
+ }
+ }
+ }
+}
+
+static rtems_task ppp_txdaemon(rtems_task_argument arg)
+{
+ rtems_event_set events;
+ int iprocess = (int )0;
+ struct ppp_softc *sc = (struct ppp_softc *)arg;
+ struct mbuf *mp;
+ struct mbuf *mf;
+ struct mbuf *m;
+ struct rtems_termios_tty *tp;
+
+ int frag;
+
+ /* enter processing loop */
+ while ( 1 ) {
+ /* wait for event */
+ rtems_event_receive(TX_PACKET|TX_TRANSMIT,RTEMS_WAIT|RTEMS_EVENT_ANY,RTEMS_NO_TIMEOUT,&events);
+ if ( events & TX_TRANSMIT ) {
+ /* received event from interrupt handler - free current mbuf */
+ rtems_bsdnet_semaphore_obtain();
+
+ m_freem(sc->sc_outm);
+
+ rtems_bsdnet_semaphore_release();
+
+ /* chain is done - clear the values */
+ sc->sc_outm = (struct mbuf *)0;
+ sc->sc_outmc = (struct mbuf *)0;
+
+ /* now set flag to fake receive of TX_PACKET event */
+ /* this will check to see if we have any pending packets */
+ events |= TX_PACKET;
+ }
+
+ /* received event from pppasyncstart */
+ if ( events & TX_PACKET ) {
+ /* ensure we are not busy */
+ if ( sc->sc_outm == (struct mbuf *)0 ) {
+ /* try dequeuing a packet */
+ sc->sc_outm = ppp_dequeue(sc);
+ if ( sc->sc_outm == NULL ) {
+ /* clear output flags */
+ sc->sc_outflag = 0;
+ sc->sc_if.if_flags &= ~IFF_OACTIVE;
+ }
+ else {
+ /* set flag to start process */
+ iprocess = 1;
+ sc->sc_outflag = SC_TX_BUSY;
+ sc->sc_if.if_flags |= IFF_OACTIVE;
+ }
+ }
+ }
+
+ /* check to see if there is any processing required */
+ if ( iprocess ) {
+ /* clear process flag */
+ iprocess = (int)0;
+ frag=0;
+
+ /* initialize output values */
+ sc->sc_outfcs = PPP_INITFCS;
+ sc->sc_outbuf = (u_char *)0;
+ sc->sc_outlen = (short )0;
+ sc->sc_outoff = (short )0;
+ sc->sc_outfcslen = (short )0;
+
+/* printf("Start Transmit Packet..\n"); */
+
+ /* loop over all mbufs in chain */
+ mf = NULL;
+ mp = NULL;
+ m = sc->sc_outm;
+
+ sc->sc_outmc = m;
+ sc->sc_outlen = m->m_len;
+ sc->sc_outbuf = mtod(m, u_char *);
+
+ while (( m != (struct mbuf *)0 ) && ( m->m_len > 0 )) {
+ frag++;
+
+ /* update the FCS value and then check next packet length */
+ if(m->m_len){
+ sc->sc_outfcs = pppfcs(sc->sc_outfcs, mtod(m, u_char *), m->m_len);
+ }
+
+ if(( m->m_next != NULL ) && ( m->m_next->m_len == 0 )) {
+ if(mf){
+ printf(" if_ppp.c : MBUF Error !!!!\n");
+ }
+ else{
+ mf = m->m_next;
+ m->m_next = NULL;
+ }
+ }
+
+#ifdef LALL_X
+ /* check next packet to see if it is empty */
+ while (( m->m_next != NULL ) && ( m->m_next->m_len == 0 )) {
+ /* next mbuf is zero length */
+ /* add empty mbuf to free chain */
+ if ( mp == NULL ) {
+ /* item is head of free list */
+ mf = m->m_next;
+ mp = mf;
+ }
+ else {
+ /* add item to end of the free list */
+ mp->m_next = m->m_next;
+ mp = m->m_next;
+ }
+
+ /* remove empty item from process chain */
+ m->m_next = m->m_next->m_next;
+ mp->m_next = NULL;
+ }
+#endif
+ /* move to next packet */
+ m = m->m_next;
+ }
+
+ /* ensure there is data to be sent out */
+ tp = (struct rtems_termios_tty *)sc->sc_devp;
+ if (( tp != NULL ) && ( sc->sc_outmc != (struct mbuf *)0 )) {
+ /* place FCS value into buffer */
+ sc->sc_outfcsbuf[sc->sc_outfcslen++] = ~sc->sc_outfcs & 0xff;
+ sc->sc_outfcsbuf[sc->sc_outfcslen++] = (~sc->sc_outfcs >> 8) & 0xff;
+ microtime(&sc->sc_if.if_lastchange);
+
+ /* write out frame byte to start the transmission */
+ sc->sc_outchar = (u_char)PPP_FLAG;
+ (*tp->device.write)(tp->minor, (char *)&sc->sc_outchar, 1);
+ }
+
+ /* check to see if we need to free some empty mbufs */
+ if ( mf != (struct mbuf *)0 ) {
+ /* free empty mbufs */
+ rtems_bsdnet_semaphore_obtain();
+ m_freem(mf);
+ rtems_bsdnet_semaphore_release();
+ }
+ }
+ }
+}
+
+static void ppp_init(struct ppp_softc *sc)
+{
+ rtems_status_code status;
+ uint32_t priority = 100;
+
+ /* determine priority value */
+ if ( rtems_bsdnet_config.network_task_priority ) {
+ priority = rtems_bsdnet_config.network_task_priority;
+ }
+
+ /* check to see if we need to start up daemons */
+ if ( sc->sc_rxtask == 0 ) {
+ /* start rx daemon task */
+ status = rtems_task_create(rtems_build_name('R','x','P','0'+sc->sc_if.if_unit), priority, 2048,
+ RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
+ &sc->sc_rxtask);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_fatal_error_occurred(status);
+ }
+ else {
+ status = rtems_task_start(sc->sc_rxtask, ppp_rxdaemon, (rtems_task_argument)sc);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_fatal_error_occurred(status);
+ }
+ }
+
+ /* start tx daemon task */
+ status = rtems_task_create(rtems_build_name('T','x','P','0'+sc->sc_if.if_unit), priority, 2048,
+ RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
+ &sc->sc_txtask);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_fatal_error_occurred(status);
+ }
+ else {
+ status = rtems_task_start(sc->sc_txtask, ppp_txdaemon, (rtems_task_argument)sc);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_fatal_error_occurred(status);
+ }
+ }
+ }
+
+ /* mark driver running and output inactive */
+ /* ilya: IFF_RUNNING flag will be marked after the IPCP goes up */
+/* sc->sc_if.if_flags |= IFF_RUNNING; */
+}
+
+/*
+ * Called from boot code to establish ppp interfaces.
+ */
+int rtems_ppp_driver_attach(struct rtems_bsdnet_ifconfig *config, int attaching)
+{
+/* int i = (int)0; */
+ struct ppp_softc *sc;
+ char *name;
+ int number;
+
+
+ number = rtems_bsdnet_parse_driver_name (config, &name);
+
+ if (!attaching || (number >= NPPP))
+ return 0;
+
+ sc = &ppp_softc[number];
+
+ if (sc->sc_if.if_name != NULL)
+ return 0; /* interface is already attached */
+
+/* for (sc = ppp_softc; i < NPPP; sc++) { */
+ sc->sc_if.if_name = name /*"ppp"*/;
+ sc->sc_if.if_unit = number /*i++*/;
+ sc->sc_if.if_mtu = PPP_MTU;
+ sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
+ sc->sc_if.if_type = IFT_PPP;
+ sc->sc_if.if_hdrlen = PPP_HDRLEN;
+ sc->sc_if.if_ioctl = pppsioctl;
+ sc->sc_if.if_output = pppoutput;
+ sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
+ sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
+ sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
+ sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
+ sc->sc_freeq.ifq_maxlen = NUM_MBUFQ;
+
+ /* initialize and attach */
+ ppp_init(sc);
+ if_attach(&sc->sc_if);
+#if NBPFILTER > 0
+ bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
+#endif
+/* } */
+
+ return ( 1 );
+}
+
+/*
+ * Allocate a ppp interface unit and initialize it.
+ */
+struct ppp_softc *
+pppalloc(pid_t pid)
+{
+ int nppp, i;
+ struct ppp_softc *sc;
+
+ for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
+ if (sc->sc_xfer == pid) {
+ sc->sc_xfer = 0;
+ return sc;
+ }
+ for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
+ if (sc->sc_devp == NULL)
+ break;
+ if (nppp >= NPPP)
+ return NULL;
+
+ sc->sc_flags = 0;
+ sc->sc_mru = PPP_MRU;
+ sc->sc_relinq = NULL;
+ bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats));
+#ifdef VJC
+ MALLOC(sc->sc_comp, struct vjcompress *, sizeof(struct vjcompress),
+ M_DEVBUF, M_NOWAIT);
+ if (sc->sc_comp)
+ sl_compress_init(sc->sc_comp, -1);
+#endif
+#ifdef PPP_COMPRESS
+ sc->sc_xc_state = NULL;
+ sc->sc_rc_state = NULL;
+#endif /* PPP_COMPRESS */
+ for (i = 0; i < NUM_NP; ++i)
+ sc->sc_npmode[i] = NPMODE_ERROR;
+ sc->sc_npqueue = NULL;
+ sc->sc_npqtail = &sc->sc_npqueue;
+ microtime(&ppp_time);
+ sc->sc_last_sent = sc->sc_last_recv = ppp_time.tv_sec;
+
+ return sc;
+}
+
+/*
+ * Deallocate a ppp unit. Must be called at splsoftnet or higher.
+ */
+void
+pppdealloc(struct ppp_softc *sc)
+{
+ struct mbuf *m;
+ rtems_interrupt_level level;
+
+ if_down(&sc->sc_if);
+ sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
+ sc->sc_devp = NULL;
+ sc->sc_xfer = 0;
+
+ rtems_interrupt_disable(level);
+ if ( sc->sc_m != NULL ) {
+ m_freem(sc->sc_m);
+ sc->sc_m = (struct mbuf *)0;
+ }
+ if ( sc->sc_outm != NULL ) {
+ m_freem(sc->sc_outm);
+ sc->sc_outm = (struct mbuf *)0;
+ sc->sc_outmc = (struct mbuf *)0;
+ sc->sc_outflag = 0;
+ }
+ do {
+ IF_DEQUEUE(&sc->sc_freeq, m);
+ if (m != NULL) {
+ m_freem(m);
+ }
+ } while ( m != NULL );
+ do {
+ IF_DEQUEUE(&sc->sc_rawq, m);
+ if (m != NULL) {
+ m_freem(m);
+ }
+ } while ( m != NULL );
+ rtems_interrupt_enable(level);
+
+ for (;;) {
+ IF_DEQUEUE(&sc->sc_inq, m);
+ if (m == NULL)
+ break;
+ m_freem(m);
+ }
+ for (;;) {
+ IF_DEQUEUE(&sc->sc_fastq, m);
+ if (m == NULL)
+ break;
+ m_freem(m);
+ }
+ while ((m = sc->sc_npqueue) != NULL) {
+ sc->sc_npqueue = m->m_nextpkt;
+ m_freem(m);
+ }
+#ifdef PPP_COMPRESS
+ ppp_ccp_closed(sc);
+ sc->sc_xc_state = NULL;
+ sc->sc_rc_state = NULL;
+#endif /* PPP_COMPRESS */
+#ifdef PPP_FILTER
+ if (sc->sc_pass_filt.bf_insns != 0) {
+ FREE(sc->sc_pass_filt.bf_insns, M_DEVBUF);
+ sc->sc_pass_filt.bf_insns = 0;
+ sc->sc_pass_filt.bf_len = 0;
+ }
+ if (sc->sc_active_filt.bf_insns != 0) {
+ FREE(sc->sc_active_filt.bf_insns, M_DEVBUF);
+ sc->sc_active_filt.bf_insns = 0;
+ sc->sc_active_filt.bf_len = 0;
+ }
+#endif /* PPP_FILTER */
+#ifdef VJC
+ if (sc->sc_comp != 0) {
+ FREE(sc->sc_comp, M_DEVBUF);
+ sc->sc_comp = 0;
+ }
+#endif
+}
+
+/*
+ * Ioctl routine for generic ppp devices.
+ */
+int
+pppioctl(struct ppp_softc *sc, ioctl_command_t cmd, caddr_t data,
+ int flag, struct proc *p)
+{
+ int s, flags, mru, npx, taskid;
+ struct npioctl *npi;
+ time_t t;
+#ifdef PPP_FILTER
+ int error;
+ struct bpf_program *bp, *nbp;
+ struct bpf_insn *newcode, *oldcode;
+ int newcodelen;
+#endif /* PPP_FILTER */
+#ifdef PPP_COMPRESS
+ int nb;
+ struct ppp_option_data *odp;
+ struct compressor **cp;
+ u_char ccp_option[CCP_MAX_OPTION_LENGTH];
+#endif
+
+ switch (cmd) {
+ case FIONREAD:
+ *(int *)data = sc->sc_inq.ifq_len;
+ break;
+
+ case PPPIOCSTASK:
+ taskid = *(int *)data;
+ sc->sc_pppdtask = taskid;
+ break;
+
+ case PPPIOCGUNIT:
+ *(int *)data = sc->sc_if.if_unit;
+ break;
+
+ case PPPIOCGFLAGS:
+ *(u_int *)data = sc->sc_flags;
+ break;
+
+ case PPPIOCSFLAGS:
+ flags = *(int *)data & SC_MASK;
+ s = splsoftnet();
+#ifdef PPP_COMPRESS
+ if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
+ ppp_ccp_closed(sc);
+#endif
+ s = splimp();
+ sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags;
+ splx(s);
+ break;
+
+ case PPPIOCSMRU:
+ mru = *(int *)data;
+ if ( mru >= MCLBYTES ) {
+ /* error - currently only handle 1 culster sized MRU */
+ /* if we want to handle up to PPP_MAXMRU then we */
+ /* need to reallocate all mbufs on the freeq */
+ /* this can only be done with iterrupts disabled */
+ return ( -1 );
+ }
+ else if ( mru >= PPP_MRU ) {
+ /* update the size */
+ sc->sc_mru = mru;
+ }
+ break;
+
+ case PPPIOCGMRU:
+ *(int *)data = sc->sc_mru;
+ break;
+
+#ifdef VJC
+ case PPPIOCSMAXCID:
+ if (sc->sc_comp) {
+ s = splsoftnet();
+ sl_compress_init(sc->sc_comp, *(int *)data);
+ splx(s);
+ }
+ break;
+#endif
+
+ case PPPIOCXFERUNIT:
+ sc->sc_xfer = 0; /* Always root p->p_pid;*/
+ break;
+
+#ifdef PPP_COMPRESS
+ case PPPIOCSCOMPRESS:
+ odp = (struct ppp_option_data *) data;
+ nb = odp->length;
+ if (nb > sizeof(ccp_option))
+ nb = sizeof(ccp_option);
+ if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
+ return (error);
+ if (ccp_option[1] < 2) /* preliminary check on the length byte */
+ return (EINVAL);
+ for (cp = ppp_compressors; *cp != NULL; ++cp)
+ if ((*cp)->compress_proto == ccp_option[0]) {
+ /*
+ * Found a handler for the protocol - try to allocate
+ * a compressor or decompressor.
+ */
+ error = 0;
+ if (odp->transmit) {
+ s = splsoftnet();
+ if (sc->sc_xc_state != NULL)
+ (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
+ sc->sc_xcomp = *cp;
+ sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb);
+ if (sc->sc_xc_state == NULL) {
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: comp_alloc failed\n",
+ sc->sc_if.if_unit);
+ error = ENOBUFS;
+ }
+ splimp();
+ sc->sc_flags &= ~SC_COMP_RUN;
+ splx(s);
+ } else {
+ s = splsoftnet();
+ if (sc->sc_rc_state != NULL)
+ (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
+ sc->sc_rcomp = *cp;
+ sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb);
+ if (sc->sc_rc_state == NULL) {
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: decomp_alloc failed\n",
+ sc->sc_if.if_unit);
+ error = ENOBUFS;
+ }
+ splimp();
+ sc->sc_flags &= ~SC_DECOMP_RUN;
+ splx(s);
+ }
+ return (error);
+ }
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: no compressor for [%x %x %x], %x\n",
+ sc->sc_if.if_unit, ccp_option[0], ccp_option[1],
+ ccp_option[2], nb);
+ return (EINVAL); /* no handler found */
+#endif /* PPP_COMPRESS */
+
+ case PPPIOCGNPMODE:
+ case PPPIOCSNPMODE:
+ npi = (struct npioctl *) data;
+ switch (npi->protocol) {
+ case PPP_IP:
+ npx = NP_IP;
+ break;
+ default:
+ return EINVAL;
+ }
+ if (cmd == PPPIOCGNPMODE) {
+ npi->mode = sc->sc_npmode[npx];
+ } else {
+ if (npi->mode != sc->sc_npmode[npx]) {
+ s = splsoftnet();
+ sc->sc_npmode[npx] = npi->mode;
+ if (npi->mode != NPMODE_QUEUE) {
+ ppp_requeue(sc);
+ (*sc->sc_start)(sc);
+ }
+ splx(s);
+ }
+ }
+ break;
+
+ case PPPIOCGIDLE:
+ s = splsoftnet();
+ microtime(&ppp_time);
+ t = ppp_time.tv_sec;
+ ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
+ ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
+ splx(s);
+ break;
+
+#ifdef PPP_FILTER
+ case PPPIOCSPASS:
+ case PPPIOCSACTIVE:
+ nbp = (struct bpf_program *) data;
+ if ((unsigned) nbp->bf_len > BPF_MAXINSNS)
+ return EINVAL;
+ newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
+ if (newcodelen != 0) {
+ MALLOC(newcode, struct bpf_insn *, newcodelen, M_DEVBUF, M_WAITOK);
+ if (newcode == 0) {
+ return EINVAL; /* or sumpin */
+ }
+ if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
+ newcodelen)) != 0) {
+ FREE(newcode, M_DEVBUF);
+ return error;
+ }
+ if (!bpf_validate(newcode, nbp->bf_len)) {
+ FREE(newcode, M_DEVBUF);
+ return EINVAL;
+ }
+ } else
+ newcode = 0;
+ bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt;
+ oldcode = bp->bf_insns;
+ s = splimp();
+ bp->bf_len = nbp->bf_len;
+ bp->bf_insns = newcode;
+ splx(s);
+ if (oldcode != 0)
+ FREE(oldcode, M_DEVBUF);
+ break;
+#endif
+
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * Process an ioctl request to the ppp network interface.
+ */
+static int
+pppsioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data)
+{
+ /*struct proc *p = curproc;*/ /* XXX */
+ register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
+ register struct ifaddr *ifa = (struct ifaddr *)data;
+ register struct ifreq *ifr = (struct ifreq *)data;
+ struct ppp_stats *psp;
+#ifdef PPP_COMPRESS
+ struct ppp_comp_stats *pcp;
+#endif
+ int s = splimp(), error = 0;
+
+ switch (cmd) {
+ case SIOCSIFFLAGS:
+ if ((ifp->if_flags & IFF_RUNNING) == 0)
+ ifp->if_flags &= ~IFF_UP;
+ break;
+
+ case SIOCSIFADDR:
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ error = EAFNOSUPPORT;
+ break;
+
+ case SIOCSIFDSTADDR:
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ error = EAFNOSUPPORT;
+ break;
+
+ case SIOCSIFMTU:
+ sc->sc_if.if_mtu = ifr->ifr_mtu;
+ break;
+
+ case SIOCGIFMTU:
+ ifr->ifr_mtu = sc->sc_if.if_mtu;
+ break;
+
+ case SIOCADDMULTI:
+ case SIOCDELMULTI:
+ if (ifr == 0) {
+ error = EAFNOSUPPORT;
+ break;
+ }
+ switch(ifr->ifr_addr.sa_family) {
+#ifdef INET
+ case AF_INET:
+ break;
+#endif
+ default:
+ error = EAFNOSUPPORT;
+ break;
+ }
+ break;
+
+ case SIO_RTEMS_SHOW_STATS:
+ printf(" MRU:%-8u", sc->sc_mru);
+ printf(" Bytes received:%-8u", sc->sc_stats.ppp_ibytes);
+ printf(" Packets received:%-8u", sc->sc_stats.ppp_ipackets);
+ printf(" Receive errors:%-8u\n", sc->sc_stats.ppp_ierrors);
+ printf(" Bytes sent:%-8u", sc->sc_stats.ppp_obytes);
+ printf(" Packets sent:%-8u", sc->sc_stats.ppp_opackets);
+ printf(" Transmit errors:%-8u\n", sc->sc_stats.ppp_oerrors);
+ break;
+
+ case SIOCGPPPSTATS:
+ psp = &((struct ifpppstatsreq *) data)->stats;
+ bzero(psp, sizeof(*psp));
+ psp->p = sc->sc_stats;
+#if defined(VJC) && !defined(SL_NO_STATS)
+ if (sc->sc_comp) {
+ psp->vj.vjs_packets = sc->sc_comp->sls_packets;
+ psp->vj.vjs_compressed = sc->sc_comp->sls_compressed;
+ psp->vj.vjs_searches = sc->sc_comp->sls_searches;
+ psp->vj.vjs_misses = sc->sc_comp->sls_misses;
+ psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin;
+ psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin;
+ psp->vj.vjs_errorin = sc->sc_comp->sls_errorin;
+ psp->vj.vjs_tossed = sc->sc_comp->sls_tossed;
+ }
+#endif /* VJC */
+ break;
+
+#ifdef PPP_COMPRESS
+ case SIOCGPPPCSTATS:
+ pcp = &((struct ifpppcstatsreq *) data)->stats;
+ bzero(pcp, sizeof(*pcp));
+ if (sc->sc_xc_state != NULL)
+ (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c);
+ if (sc->sc_rc_state != NULL)
+ (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d);
+ break;
+#endif /* PPP_COMPRESS */
+
+ default:
+ error = EINVAL;
+ }
+ splx(s);
+ return (error);
+}
+
+/*
+ * Queue a packet. Start transmission if not active.
+ * Packet is placed in Information field of PPP frame.
+ */
+int
+pppoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
+ struct rtentry *rtp)
+{
+ register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
+ int protocol, address, control;
+ u_char *cp;
+ int s, error;
+ struct ip *ip;
+ struct ifqueue *ifq;
+ enum NPmode mode;
+ int len;
+ struct mbuf *m;
+
+ if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
+ || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) {
+ error = ENETDOWN; /* sort of */
+ goto bad;
+ }
+
+ /*
+ * Compute PPP header.
+ */
+ m0->m_flags &= ~M_HIGHPRI;
+ switch (dst->sa_family) {
+#ifdef INET
+ case AF_INET:
+ address = PPP_ALLSTATIONS;
+ control = PPP_UI;
+ protocol = PPP_IP;
+ mode = sc->sc_npmode[NP_IP];
+
+ /*
+ * If this packet has the "low delay" bit set in the IP header,
+ * put it on the fastq instead.
+ */
+ ip = mtod(m0, struct ip *);
+ if (ip->ip_tos & IPTOS_LOWDELAY)
+ m0->m_flags |= M_HIGHPRI;
+ break;
+#endif
+ case AF_UNSPEC:
+ address = PPP_ADDRESS(dst->sa_data);
+ control = PPP_CONTROL(dst->sa_data);
+ protocol = PPP_PROTOCOL(dst->sa_data);
+ mode = NPMODE_PASS;
+ break;
+ default:
+ printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family);
+ error = EAFNOSUPPORT;
+ goto bad;
+ }
+
+ /*
+ * Drop this packet, or return an error, if necessary.
+ */
+ if (mode == NPMODE_ERROR) {
+ error = ENETDOWN;
+ goto bad;
+ }
+ if (mode == NPMODE_DROP) {
+ error = 0;
+ goto bad;
+ }
+
+ /*
+ * Add PPP header. If no space in first mbuf, allocate another.
+ * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.)
+ */
+ if (M_LEADINGSPACE(m0) < PPP_HDRLEN) {
+ m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT);
+ if (m0 == 0) {
+ error = ENOBUFS;
+ goto bad;
+ }
+ m0->m_len = 0;
+ } else
+ m0->m_data -= PPP_HDRLEN;
+
+ cp = mtod(m0, u_char *);
+ *cp++ = address;
+ *cp++ = control;
+ *cp++ = protocol >> 8;
+ *cp++ = protocol & 0xff;
+ m0->m_len += PPP_HDRLEN;
+
+ len = 0;
+ for (m = m0; m != 0; m = m->m_next)
+ len += m->m_len;
+
+ if (sc->sc_flags & SC_LOG_OUTPKT) {
+ printf("ppp%d output: ", ifp->if_unit);
+ pppdumpm(m0);
+ }
+
+ if ((protocol & 0x8000) == 0) {
+#ifdef PPP_FILTER
+ /*
+ * Apply the pass and active filters to the packet,
+ * but only if it is a data packet.
+ */
+ *mtod(m0, u_char *) = 1; /* indicates outbound */
+ if (sc->sc_pass_filt.bf_insns != 0
+ && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0,
+ len, 0) == 0) {
+ error = 0; /* drop this packet */
+ goto bad;
+ }
+
+ /*
+ * Update the time we sent the most recent packet.
+ */
+ if (sc->sc_active_filt.bf_insns == 0
+ || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0))
+ sc->sc_last_sent = time.tv_sec;
+
+ *mtod(m0, u_char *) = address;
+#else
+ /*
+ * Update the time we sent the most recent data packet.
+ */
+ microtime(&ppp_time);
+ sc->sc_last_sent = ppp_time.tv_sec;
+#endif /* PPP_FILTER */
+ }
+
+#if NBPFILTER > 0
+ /*
+ * See if bpf wants to look at the packet.
+ */
+ if (sc->sc_bpf)
+ bpf_mtap(sc->sc_bpf, m0);
+#endif
+
+ /*
+ * Put the packet on the appropriate queue.
+ */
+ s = splsoftnet();
+ if (mode == NPMODE_QUEUE) {
+ /* XXX we should limit the number of packets on this queue */
+ *sc->sc_npqtail = m0;
+ m0->m_nextpkt = NULL;
+ sc->sc_npqtail = &m0->m_nextpkt;
+ } else {
+ ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
+ if (IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) {
+ IF_DROP(ifq);
+ splx(s);
+ sc->sc_if.if_oerrors++;
+ sc->sc_stats.ppp_oerrors++;
+ error = ENOBUFS;
+ goto bad;
+ }
+ IF_ENQUEUE(ifq, m0);
+ (*sc->sc_start)(sc);
+ }
+ ifp->if_lastchange = ppp_time;
+ ifp->if_opackets++;
+ ifp->if_obytes += len;
+
+ splx(s);
+ return (0);
+
+bad:
+ m_freem(m0);
+ return (error);
+}
+
+/*
+ * After a change in the NPmode for some NP, move packets from the
+ * npqueue to the send queue or the fast queue as appropriate.
+ * Should be called at spl[soft]net.
+ */
+static void
+ppp_requeue(struct ppp_softc *sc)
+{
+ struct mbuf *m, **mpp;
+ struct ifqueue *ifq;
+ enum NPmode mode;
+
+ for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) {
+ switch (PPP_PROTOCOL(mtod(m, u_char *))) {
+ case PPP_IP:
+ mode = sc->sc_npmode[NP_IP];
+ break;
+ default:
+ mode = NPMODE_PASS;
+ }
+
+ switch (mode) {
+ case NPMODE_PASS:
+ /*
+ * This packet can now go on one of the queues to be sent.
+ */
+ *mpp = m->m_nextpkt;
+ m->m_nextpkt = NULL;
+ ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd;
+ if (IF_QFULL(ifq)) {
+ IF_DROP(ifq);
+ sc->sc_if.if_oerrors++;
+ sc->sc_stats.ppp_oerrors++;
+ } else
+ IF_ENQUEUE(ifq, m);
+ break;
+
+ case NPMODE_DROP:
+ case NPMODE_ERROR:
+ *mpp = m->m_nextpkt;
+ m_freem(m);
+ break;
+
+ case NPMODE_QUEUE:
+ mpp = &m->m_nextpkt;
+ break;
+ }
+ }
+ sc->sc_npqtail = mpp;
+}
+
+/*
+ * Get a packet to send. This procedure is intended to be called at
+ * splsoftnet, since it may involve time-consuming operations such as
+ * applying VJ compression, packet compression, address/control and/or
+ * protocol field compression to the packet.
+ */
+struct mbuf *
+ppp_dequeue(struct ppp_softc *sc)
+{
+#ifdef PPP_COMPRESS
+ struct mbuf *mp;
+#endif
+ struct mbuf *m;
+ u_char *cp;
+ int address, control, protocol;
+
+ /*
+ * Grab a packet to send: first try the fast queue, then the
+ * normal queue.
+ */
+ rtems_bsdnet_semaphore_obtain();
+ IF_DEQUEUE(&sc->sc_fastq, m);
+ if (m == NULL)
+ IF_DEQUEUE(&sc->sc_if.if_snd, m);
+ rtems_bsdnet_semaphore_release();
+
+ if (m == NULL)
+ return NULL;
+
+ ++sc->sc_stats.ppp_opackets;
+
+ /*
+ * Extract the ppp header of the new packet.
+ * The ppp header will be in one mbuf.
+ */
+ cp = mtod(m, u_char *);
+ address = PPP_ADDRESS(cp);
+ control = PPP_CONTROL(cp);
+ protocol = PPP_PROTOCOL(cp);
+
+ switch (protocol) {
+ case PPP_IP:
+#ifdef VJC
+ /*
+ * If the packet is a TCP/IP packet, see if we can compress it.
+ */
+ if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) {
+ struct ip *ip;
+ int type;
+
+ mp = m;
+ ip = (struct ip *) (cp + PPP_HDRLEN);
+ if (mp->m_len <= PPP_HDRLEN) {
+ mp = mp->m_next;
+ if (mp == NULL)
+ break;
+ ip = mtod(mp, struct ip *);
+ }
+ /* this code assumes the IP/TCP header is in one non-shared mbuf */
+ if (ip->ip_p == IPPROTO_TCP) {
+ type = sl_compress_tcp(mp, ip, sc->sc_comp,
+ !(sc->sc_flags & SC_NO_TCP_CCID));
+ switch (type) {
+ case TYPE_UNCOMPRESSED_TCP:
+ protocol = PPP_VJC_UNCOMP;
+ break;
+ case TYPE_COMPRESSED_TCP:
+ protocol = PPP_VJC_COMP;
+ cp = mtod(m, u_char *);
+ cp[0] = address; /* header has moved */
+ cp[1] = control;
+ cp[2] = 0;
+ break;
+ }
+ cp[3] = protocol; /* update protocol in PPP header */
+ }
+ }
+#endif /* VJC */
+ break;
+
+#ifdef PPP_COMPRESS
+ case PPP_CCP:
+ ppp_ccp(sc, m, 0);
+ break;
+#endif /* PPP_COMPRESS */
+ }
+
+#ifdef PPP_COMPRESS
+ if (protocol != PPP_LCP && protocol != PPP_CCP
+ && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
+ struct mbuf *mcomp = NULL;
+ int slen, clen;
+
+ slen = 0;
+ for (mp = m; mp != NULL; mp = mp->m_next)
+ slen += mp->m_len;
+ clen = (*sc->sc_xcomp->compress)
+ (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN);
+ if (mcomp != NULL) {
+ if (sc->sc_flags & SC_CCP_UP) {
+ /* Send the compressed packet instead of the original. */
+ m_freem(m);
+ m = mcomp;
+ cp = mtod(m, u_char *);
+ protocol = cp[3];
+ } else {
+ /* Can't transmit compressed packets until CCP is up. */
+ m_freem(mcomp);
+ }
+ }
+ }
+#endif /* PPP_COMPRESS */
+
+ /*
+ * Compress the address/control and protocol, if possible.
+ */
+ if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS &&
+ control == PPP_UI && protocol != PPP_ALLSTATIONS &&
+ protocol != PPP_LCP) {
+ /* can compress address/control */
+ m->m_data += 2;
+ m->m_len -= 2;
+ }
+ if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
+ /* can compress protocol */
+ if (mtod(m, u_char *) == cp) {
+ cp[2] = cp[1]; /* move address/control up */
+ cp[1] = cp[0];
+ }
+ ++m->m_data;
+ --m->m_len;
+ }
+
+ return m;
+}
+
+#ifdef PPP_COMPRESS
+/*
+ * Handle a CCP packet. `rcvd' is 1 if the packet was received,
+ * 0 if it is about to be transmitted.
+ */
+static void
+ppp_ccp(struct ppp_softc *sc, struct mbuf *m, int rcvd)
+{
+ u_char *dp, *ep;
+ struct mbuf *mp;
+ int slen, s;
+
+ /*
+ * Get a pointer to the data after the PPP header.
+ */
+ if (m->m_len <= PPP_HDRLEN) {
+ mp = m->m_next;
+ if (mp == NULL)
+ return;
+ dp = (mp != NULL)? mtod(mp, u_char *): NULL;
+ } else {
+ mp = m;
+ dp = mtod(mp, u_char *) + PPP_HDRLEN;
+ }
+
+ ep = mtod(mp, u_char *) + mp->m_len;
+ if (dp + CCP_HDRLEN > ep)
+ return;
+ slen = CCP_LENGTH(dp);
+ if (dp + slen > ep) {
+ if (sc->sc_flags & SC_DEBUG)
+ printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
+ dp, slen, mtod(mp, u_char *), mp->m_len);
+ return;
+ }
+
+ switch (CCP_CODE(dp)) {
+ case CCP_CONFREQ:
+ case CCP_TERMREQ:
+ case CCP_TERMACK:
+ /* CCP must be going down - disable compression */
+ if (sc->sc_flags & SC_CCP_UP) {
+ s = splimp();
+ sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
+ splx(s);
+ }
+ break;
+
+ case CCP_CONFACK:
+ if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP)
+ && slen >= CCP_HDRLEN + CCP_OPT_MINLEN
+ && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) {
+ if (!rcvd) {
+ /* we're agreeing to send compressed packets. */
+ if (sc->sc_xc_state != NULL
+ && (*sc->sc_xcomp->comp_init)
+ (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
+ sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) {
+ s = splimp();
+ sc->sc_flags |= SC_COMP_RUN;
+ splx(s);
+ }
+ } else {
+ /* peer is agreeing to send compressed packets. */
+ if (sc->sc_rc_state != NULL
+ && (*sc->sc_rcomp->decomp_init)
+ (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
+ sc->sc_if.if_unit, 0, sc->sc_mru,
+ sc->sc_flags & SC_DEBUG)) {
+ s = splimp();
+ sc->sc_flags |= SC_DECOMP_RUN;
+ sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
+ splx(s);
+ }
+ }
+ }
+ break;
+
+ case CCP_RESETACK:
+ if (sc->sc_flags & SC_CCP_UP) {
+ if (!rcvd) {
+ if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN))
+ (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state);
+ } else {
+ if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
+ (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state);
+ s = splimp();
+ sc->sc_flags &= ~SC_DC_ERROR;
+ splx(s);
+ }
+ }
+ }
+ break;
+ }
+}
+
+/*
+ * CCP is down; free (de)compressor state if necessary.
+ */
+static void
+ppp_ccp_closed(struct ppp_softc *sc)
+{
+ if (sc->sc_xc_state) {
+ (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
+ sc->sc_xc_state = NULL;
+ }
+ if (sc->sc_rc_state) {
+ (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
+ sc->sc_rc_state = NULL;
+ }
+}
+#endif /* PPP_COMPRESS */
+
+/*
+ * Process a received PPP packet, doing decompression as necessary.
+ * Should be called at splsoftnet.
+ */
+#define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
+ TYPE_UNCOMPRESSED_TCP)
+
+static struct mbuf *
+ppp_inproc(struct ppp_softc *sc, struct mbuf *m)
+{
+ struct mbuf *mf = (struct mbuf *)0;
+ struct ifnet *ifp = &sc->sc_if;
+ struct ifqueue *inq;
+ int s, ilen, proto, rv;
+ u_char *cp, adrs, ctrl;
+ struct mbuf *mp;
+#ifdef PPP_COMPRESS
+ struct mbuf *dmp = NULL;
+#endif
+#ifdef VJC
+ u_char *iphdr;
+ u_int hlen;
+ int xlen;
+#endif
+
+ sc->sc_stats.ppp_ipackets++;
+
+ if (sc->sc_flags & SC_LOG_INPKT) {
+ ilen = 0;
+ for (mp = m; mp != NULL; mp = mp->m_next)
+ ilen += mp->m_len;
+ printf("ppp%d: got %d bytes\n", ifp->if_unit, ilen);
+ pppdumpm(m);
+ }
+
+ cp = mtod(m, u_char *);
+ adrs = PPP_ADDRESS(cp);
+ ctrl = PPP_CONTROL(cp);
+ proto = PPP_PROTOCOL(cp);
+
+ if (m->m_flags & M_ERRMARK) {
+ m->m_flags &= ~M_ERRMARK;
+ s = splimp();
+ sc->sc_flags |= SC_VJ_RESET;
+ splx(s);
+ }
+
+#ifdef PPP_COMPRESS
+ /*
+ * Decompress this packet if necessary, update the receiver's
+ * dictionary, or take appropriate action on a CCP packet.
+ */
+ if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
+ && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
+ /* decompress this packet */
+ rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
+ if (rv == DECOMP_OK) {
+ m_freem(m);
+ if (dmp == NULL) {
+ /* no error, but no decompressed packet produced */
+ return mf;
+ }
+ m = dmp;
+ cp = mtod(m, u_char *);
+ proto = PPP_PROTOCOL(cp);
+
+ } else {
+ /*
+ * An error has occurred in decompression.
+ * Pass the compressed packet up to pppd, which may take
+ * CCP down or issue a Reset-Req.
+ */
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: decompress failed %d\n", ifp->if_unit, rv);
+ s = splimp();
+ sc->sc_flags |= SC_VJ_RESET;
+ if (rv == DECOMP_ERROR)
+ sc->sc_flags |= SC_DC_ERROR;
+ else
+ sc->sc_flags |= SC_DC_FERROR;
+ splx(s);
+ }
+
+ } else {
+ if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
+ (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
+ }
+ if (proto == PPP_CCP) {
+ ppp_ccp(sc, m, 1);
+ }
+ }
+#endif
+
+ ilen = 0;
+ for (mp = m; mp != NULL; mp = mp->m_next)
+ ilen += mp->m_len;
+
+#ifdef VJC
+ if (sc->sc_flags & SC_VJ_RESET) {
+ /*
+ * If we've missed a packet, we must toss subsequent compressed
+ * packets which don't have an explicit connection ID.
+ */
+ if (sc->sc_comp)
+ sl_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp);
+ s = splimp();
+ sc->sc_flags &= ~SC_VJ_RESET;
+ splx(s);
+ }
+
+ /*
+ * See if we have a VJ-compressed packet to uncompress.
+ */
+ if (proto == PPP_VJC_COMP) {
+ if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
+ goto bad;
+
+ xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
+ ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
+ sc->sc_comp, &iphdr, &hlen);
+
+ if (xlen <= 0) {
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: VJ uncompress failed on type comp\n",
+ ifp->if_unit);
+ goto bad;
+ }
+
+ /* Copy the PPP and IP headers into a new mbuf. */
+ MGETHDR(mp, M_DONTWAIT, MT_DATA);
+ if (mp == NULL)
+ goto bad;
+ mp->m_len = 0;
+ mp->m_next = NULL;
+ if (hlen + PPP_HDRLEN > MHLEN) {
+ MCLGET(mp, M_DONTWAIT);
+ if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) {
+ m_freem(mp);
+ goto bad; /* lose if big headers and no clusters */
+ }
+ }
+#ifdef MAC
+ mac_create_mbuf_from_mbuf(m, mp);
+#endif
+ cp = mtod(mp, u_char *);
+ cp[0] = adrs;
+ cp[1] = ctrl;
+ cp[2] = 0;
+ cp[3] = PPP_IP;
+ proto = PPP_IP;
+ bcopy(iphdr, cp + PPP_HDRLEN, hlen);
+ mp->m_len = hlen + PPP_HDRLEN;
+
+ /*
+ * Trim the PPP and VJ headers off the old mbuf
+ * and stick the new and old mbufs together.
+ */
+ m->m_data += PPP_HDRLEN + xlen;
+ m->m_len -= PPP_HDRLEN + xlen;
+ if (m->m_len <= M_TRAILINGSPACE(mp)) {
+ bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
+ mp->m_len += m->m_len;
+ MFREE(m, mp->m_next);
+ } else
+ mp->m_next = m;
+ m = mp;
+ ilen += hlen - xlen;
+
+ } else if (proto == PPP_VJC_UNCOMP) {
+ if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
+ goto bad;
+
+ xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
+ ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
+ sc->sc_comp, &iphdr, &hlen);
+
+ if (xlen < 0) {
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: VJ uncompress failed on type uncomp\n",
+ ifp->if_unit);
+ goto bad;
+ }
+
+ proto = PPP_IP;
+ cp[3] = PPP_IP;
+ }
+#endif /* VJC */
+
+ /*
+ * If the packet will fit in a header mbuf, don't waste a
+ * whole cluster on it.
+ */
+ if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
+ MGETHDR(mp, M_DONTWAIT, MT_DATA);
+ if (mp != NULL) {
+ m_copydata(m, 0, ilen, mtod(mp, caddr_t));
+ /* instead of freeing - return cluster mbuf so it can be reused */
+ /* m_freem(m); */
+ mf = m;
+ m = mp;
+ m->m_len = ilen;
+ }
+ }
+ m->m_pkthdr.len = ilen;
+ m->m_pkthdr.rcvif = ifp;
+
+ if ((proto & 0x8000) == 0) {
+#ifdef PPP_FILTER
+ /*
+ * See whether we want to pass this packet, and
+ * if it counts as link activity.
+ */
+ adrs = *mtod(m, u_char *); /* save address field */
+ *mtod(m, u_char *) = 0; /* indicate inbound */
+ if (sc->sc_pass_filt.bf_insns != 0
+ && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m,
+ ilen, 0) == 0) {
+ /* drop this packet */
+ m_freem(m);
+ return mf;
+ }
+ if (sc->sc_active_filt.bf_insns == 0
+ || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0))
+ sc->sc_last_recv = time.tv_sec;
+
+ *mtod(m, u_char *) = adrs;
+#else
+ /*
+ * Record the time that we received this packet.
+ */
+ microtime(&ppp_time);
+ sc->sc_last_recv = ppp_time.tv_sec;
+#endif /* PPP_FILTER */
+ }
+
+#if NBPFILTER > 0
+ /* See if bpf wants to look at the packet. */
+ if (sc->sc_bpf)
+ bpf_mtap(sc->sc_bpf, m);
+#endif
+
+ rv = 0;
+ switch (proto) {
+#ifdef INET
+ case PPP_IP:
+ /*
+ * IP packet - take off the ppp header and pass it up to IP.
+ */
+ if ((ifp->if_flags & IFF_UP) == 0
+ || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
+ /* interface is down - drop the packet. */
+ m_freem(m);
+ return mf;
+ }
+ m->m_pkthdr.len -= PPP_HDRLEN;
+ m->m_data += PPP_HDRLEN;
+ m->m_len -= PPP_HDRLEN;
+ schednetisr(NETISR_IP);
+ inq = &ipintrq;
+ break;
+#endif
+
+ default:
+ /*
+ * Some other protocol - place on input queue for read().
+ */
+ inq = &sc->sc_inq;
+ rv = 1;
+ break;
+ }
+
+ /*
+ * Put the packet on the appropriate input queue.
+ */
+ s = splimp();
+ if (IF_QFULL(inq)) {
+ IF_DROP(inq);
+ splx(s);
+ if (sc->sc_flags & SC_DEBUG)
+ printf("ppp%d: input queue full\n", ifp->if_unit);
+ ifp->if_iqdrops++;
+ goto bad;
+ }
+ IF_ENQUEUE(inq, m);
+ splx(s);
+
+ ifp->if_ipackets++;
+ ifp->if_ibytes += ilen;
+ microtime(&ppp_time);
+ ifp->if_lastchange = ppp_time;
+
+ if (rv) {
+ (*sc->sc_ctlp)(sc);
+ }
+
+ return mf;
+
+ bad:
+ m_freem(m);
+ sc->sc_if.if_ierrors++;
+ sc->sc_stats.ppp_ierrors++;
+ return mf;
+}
+
+#define MAX_DUMP_BYTES 128
+
+static void
+pppdumpm(struct mbuf *m0)
+{
+ char buf[3*MAX_DUMP_BYTES+4];
+ char *bp = buf;
+ struct mbuf *m;
+ static char digits[] = "0123456789abcdef";
+
+ for (m = m0; m; m = m->m_next) {
+ int l = m->m_len;
+ u_char *rptr = (u_char *)m->m_data;
+
+ while (l--) {
+ if (bp > buf + sizeof(buf) - 4)
+ goto done;
+ *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */
+ *bp++ = digits[*rptr++ & 0xf];
+ }
+
+ if (m->m_next) {
+ if (bp > buf + sizeof(buf) - 3)
+ goto done;
+ *bp++ = '|';
+ } else
+ *bp++ = ' ';
+ }
+done:
+ if (m)
+ *bp++ = '>';
+ *bp = 0;
+ printf("%s\n", buf);
+}
+
+#endif /* NPPP > 0 */
diff --git a/cpukit/libnetworking/net/if_ppp.h b/cpukit/libnetworking/net/if_ppp.h
new file mode 100644
index 0000000000..820f722070
--- /dev/null
+++ b/cpukit/libnetworking/net/if_ppp.h
@@ -0,0 +1,141 @@
+/*
+ * if_ppp.h - Point-to-Point Protocol definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $FreeBSD: src/sys/net/if_ppp.h,v 1.15 2005/01/07 01:45:34 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _IF_PPP_H_
+#define _IF_PPP_H_
+
+/*
+ * Packet sizes
+ */
+#define PPP_MTU 1500 /* Default MTU (size of Info field) */
+#define PPP_MAXMRU 65000 /* Largest MRU we allow */
+#define PPP_MAXMTU 16384 /* Largest MTU we allow */
+
+/*
+ * Bit definitions for flags.
+ */
+#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */
+#define SC_COMP_AC 0x00000002 /* header compression (output) */
+#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */
+#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */
+#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */
+#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */
+#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */
+#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */
+#define SC_DEBUG 0x00010000 /* enable debug messages */
+#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */
+#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
+#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
+#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
+#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
+#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
+#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
+#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
+#define SC_SYNC 0x00200000 /* use synchronous HDLC framing */
+#define SC_MASK 0x0fff00ff /* bits that user can change */
+
+/*
+ * State bits in sc_flags, not changeable by user.
+ */
+#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
+#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
+#define SC_COMP_RUN 0x00001000 /* compressor has been initiated */
+#define SC_DECOMP_RUN 0x00002000 /* decompressor has been initiated */
+#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */
+#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */
+#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */
+#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */
+#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
+#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
+
+/*
+ * Ioctl definitions.
+ */
+
+struct npioctl {
+ int protocol; /* PPP procotol, e.g. PPP_IP */
+ enum NPmode mode;
+};
+
+/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
+struct ppp_option_data {
+ u_char *ptr;
+ u_int length;
+ int transmit;
+};
+
+struct ifpppstatsreq {
+ char ifr_name[IFNAMSIZ];
+ struct ppp_stats stats;
+};
+
+struct ifpppcstatsreq {
+ char ifr_name[IFNAMSIZ];
+ struct ppp_comp_stats stats;
+};
+
+/*
+ * Ioctl definitions.
+ */
+
+#define PPPIOCSTASK _IOW('t', 91, int) /* set pppd task id */
+#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */
+#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */
+#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */
+#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */
+#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */
+#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */
+#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */
+#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */
+#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */
+#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */
+#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
+#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
+#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */
+#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
+#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */
+#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */
+#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */
+#ifdef PPP_FILTER
+#define PPPIOCSPASS _IOW('t', 71, struct bpf_program) /* set pass filter */
+#define PPPIOCSACTIVE _IOW('t', 70, struct bpf_program) /* set active filt */
+#endif /* PPP_FILTER */
+
+/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */
+#define PPPIOCGMTU _IOR('t', 73, int) /* get interface MTU */
+#define PPPIOCSMTU _IOW('t', 72, int) /* set interface MTU */
+
+/*
+ * These two are interface ioctls so that pppstats can do them on
+ * a socket without having to open the serial device.
+ */
+#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
+#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
+
+#if !defined(ifr_mtu)
+#define ifr_mtu ifr_ifru.ifru_metric
+#endif
+
+#endif /* _IF_PPP_H_ */
diff --git a/cpukit/libnetworking/net/if_pppvar.h b/cpukit/libnetworking/net/if_pppvar.h
new file mode 100644
index 0000000000..4bb6a086b0
--- /dev/null
+++ b/cpukit/libnetworking/net/if_pppvar.h
@@ -0,0 +1,158 @@
+/*
+ * if_pppvar.h - private structures and declarations for PPP.
+ *
+ * Copyright (c) 1994 The Australian National University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation is hereby granted, provided that the above copyright
+ * notice appears in all copies. This software is provided without any
+ * warranty, express or implied. The Australian National University
+ * makes no representations about the suitability of this software for
+ * any purpose.
+ *
+ * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
+ * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+ * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
+ * OR MODIFICATIONS.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $FreeBSD: src/sys/net/if_pppvar.h,v 1.26 2006/12/05 18:54:21 ume Exp $
+ */
+
+#ifndef _NET_IF_PPPVAR_H_
+#define _NET_IF_PPPVAR_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * $Id$
+ */
+
+/*
+ * Supported network protocols. These values are used for
+ * indexing sc_npmode.
+ */
+#define NP_IP 0 /* Internet Protocol */
+#define NUM_NP 1 /* Number of NPs. */
+#define NUM_MBUFQ 64
+
+
+/*
+ * Structure describing each ppp unit.
+ */
+struct ppp_softc {
+ struct ifnet sc_if; /* network-visible interface */
+ u_int sc_flags; /* control/status bits; see if_ppp.h */
+ void *sc_devp; /* pointer to device-dep structure */
+ void (*sc_start)(struct ppp_softc *); /* start output proc */
+ void (*sc_ctlp)(struct ppp_softc *); /* rcvd control pkt */
+ void (*sc_relinq)(struct ppp_softc *); /* relinquish ifunit */
+ short sc_mru; /* max receive unit */
+ pid_t sc_xfer; /* used in transferring unit */
+ struct ifqueue sc_rawq; /* received packets */
+ struct ifqueue sc_inq; /* queue of input packets for daemon */
+ struct ifqueue sc_fastq; /* interactive output packet q */
+ struct mbuf *sc_npqueue; /* output packets not to be sent yet */
+ struct mbuf **sc_npqtail; /* ptr to last next ptr in npqueue */
+ struct pppstat sc_stats; /* count of bytes/pkts sent/rcvd */
+ caddr_t sc_bpf; /* hook for BPF */
+ enum NPmode sc_npmode[NUM_NP]; /* what to do with each NP */
+ struct compressor *sc_xcomp; /* transmit compressor */
+ void *sc_xc_state; /* transmit compressor state */
+ struct compressor *sc_rcomp; /* receive decompressor */
+ void *sc_rc_state; /* receive decompressor state */
+ time_t sc_last_sent; /* time (secs) last NP pkt sent */
+ time_t sc_last_recv; /* time (secs) last NP pkt rcvd */
+#ifdef PPP_FILTER
+ struct bpf_program sc_pass_filt; /* filter for packets to pass */
+ struct bpf_program sc_active_filt; /* filter for "non-idle" packets */
+#endif /* PPP_FILTER */
+#ifdef VJC
+ struct vjcompress *sc_comp; /* vjc control buffer */
+#endif
+
+ /* Device-dependent part for async lines. */
+ ext_accm sc_asyncmap; /* async control character map */
+ u_long sc_rasyncmap; /* receive async control char map */
+ struct mbuf *sc_outm; /* mbuf chain currently being output */
+ struct mbuf *sc_outmc; /* mbuf currently being output */
+ struct mbuf *sc_m; /* pointer to input mbuf chain */
+ struct mbuf *sc_mc; /* pointer to current input mbuf */
+ char *sc_mp; /* ptr to next char in input mbuf */
+ short sc_ilen; /* length of input packet so far */
+ u_short sc_fcs; /* FCS so far (input) */
+ u_short sc_outfcs; /* FCS so far for output packet */
+ u_char sc_rawin[16]; /* chars as received */
+ int sc_rawin_count; /* # in sc_rawin */
+
+ struct ifqueue sc_freeq; /* free packets */
+ short sc_outoff; /* output packet byte offset */
+ short sc_outflag; /* output status flag */
+ short sc_outlen; /* length of output packet */
+ short sc_outfcslen; /* length of output fcs data */
+ u_char sc_outfcsbuf[8]; /* output packet fcs buffer */
+ u_char *sc_outbuf; /* pointer to output data */
+ u_char sc_outchar;
+
+ rtems_id sc_rxtask;
+ rtems_id sc_txtask;
+ rtems_id sc_pppdtask;
+};
+
+struct ppp_softc *pppalloc(pid_t pid);
+void pppdealloc(struct ppp_softc *sc);
+int pppoutput(struct ifnet *, struct mbuf *,
+ struct sockaddr *, struct rtentry *);
+int pppioctl(struct ppp_softc *sc, ioctl_command_t cmd, caddr_t data,
+ int flag, struct proc *p);
+struct mbuf *ppp_dequeue(struct ppp_softc *sc);
+u_short pppfcs(u_short fcs, u_char *cp, int len);
+void pppallocmbuf(struct ppp_softc *sc, struct mbuf **mp);
+
+
+/* define event values */
+#define RX_PACKET RTEMS_EVENT_1
+#define RX_MBUF RTEMS_EVENT_2
+#define RX_EMPTY RTEMS_EVENT_3
+#define TX_PACKET RTEMS_EVENT_1
+#define TX_TRANSMIT RTEMS_EVENT_2
+#define PPPD_EVENT RTEMS_EVENT_31
+
+/* define out flag values */
+#define SC_TX_BUSY 0x0001
+#define SC_TX_FCS 0x0002
+#define SC_TX_ESCAPE 0x0004
+#define SC_TX_LASTCHAR 0x0008
+#define SC_TX_PENDING 0x0010
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NET_IF_PPPVAR_H_ */
+
diff --git a/cpukit/libnetworking/net/if_types.h b/cpukit/libnetworking/net/if_types.h
new file mode 100644
index 0000000000..478c419761
--- /dev/null
+++ b/cpukit/libnetworking/net/if_types.h
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_types.h 8.3 (Berkeley) 4/28/95
+ * $FreeBSD: src/sys/net/if_types.h,v 1.18 2005/02/22 13:04:03 glebius Exp $
+ * $NetBSD: if_types.h,v 1.16 2000/04/19 06:30:53 itojun Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_IF_TYPES_H_
+#define _NET_IF_TYPES_H_
+
+/*
+ * Interface types for benefit of parsing media address headers.
+ * This list is derived from the SNMP list of ifTypes, originally
+ * documented in RFC1573, now maintained as:
+ *
+ * ftp.isi.edu/in-notes/iana/assignments/smi-numbers
+ */
+
+#define IFT_OTHER 0x1 /* none of the following */
+#define IFT_1822 0x2 /* old-style arpanet imp */
+#define IFT_HDH1822 0x3 /* HDH arpanet imp */
+#define IFT_X25DDN 0x4 /* x25 to imp */
+#define IFT_X25 0x5 /* PDN X25 interface (RFC877) */
+#define IFT_ETHER 0x6 /* Ethernet CSMA/CD */
+#define IFT_ISO88023 0x7 /* CMSA/CD */
+#define IFT_ISO88024 0x8 /* Token Bus */
+#define IFT_ISO88025 0x9 /* Token Ring */
+#define IFT_ISO88026 0xa /* MAN */
+#define IFT_STARLAN 0xb
+#define IFT_P10 0xc /* Proteon 10MBit ring */
+#define IFT_P80 0xd /* Proteon 80MBit ring */
+#define IFT_HY 0xe /* Hyperchannel */
+#define IFT_FDDI 0xf
+#define IFT_LAPB 0x10
+#define IFT_SDLC 0x11
+#define IFT_T1 0x12
+#define IFT_CEPT 0x13 /* E1 - european T1 */
+#define IFT_ISDNBASIC 0x14
+#define IFT_ISDNPRIMARY 0x15
+#define IFT_PTPSERIAL 0x16 /* Proprietary PTP serial */
+#define IFT_PPP 0x17 /* RFC 1331 */
+#define IFT_LOOP 0x18 /* loopback */
+#define IFT_EON 0x19 /* ISO over IP */
+#define IFT_XETHER 0x1a /* obsolete 3MB experimental ethernet */
+#define IFT_NSIP 0x1b /* XNS over IP */
+#define IFT_SLIP 0x1c /* IP over generic TTY */
+#define IFT_ULTRA 0x1d /* Ultra Technologies */
+#define IFT_DS3 0x1e /* Generic T3 */
+#define IFT_SIP 0x1f /* SMDS */
+#define IFT_FRELAY 0x20 /* Frame Relay DTE only */
+#define IFT_RS232 0x21
+#define IFT_PARA 0x22 /* parallel-port */
+#define IFT_ARCNET 0x23
+#define IFT_ARCNETPLUS 0x24
+#define IFT_ATM 0x25 /* ATM cells */
+#define IFT_MIOX25 0x26
+#define IFT_SONET 0x27 /* SONET or SDH */
+#define IFT_X25PLE 0x28
+#define IFT_ISO88022LLC 0x29
+#define IFT_LOCALTALK 0x2a
+#define IFT_SMDSDXI 0x2b
+#define IFT_FRELAYDCE 0x2c /* Frame Relay DCE */
+#define IFT_V35 0x2d
+#define IFT_HSSI 0x2e
+#define IFT_HIPPI 0x2f
+#define IFT_MODEM 0x30 /* Generic Modem */
+#define IFT_AAL5 0x31 /* AAL5 over ATM */
+#define IFT_SONETPATH 0x32
+#define IFT_SONETVT 0x33
+#define IFT_SMDSICIP 0x34 /* SMDS InterCarrier Interface */
+#define IFT_PROPVIRTUAL 0x35 /* Proprietary Virtual/internal */
+#define IFT_PROPMUX 0x36 /* Proprietary Multiplexing */
+#define IFT_IEEE80212 0x37 /* 100BaseVG */
+#define IFT_FIBRECHANNEL 0x38 /* Fibre Channel */
+#define IFT_HIPPIINTERFACE 0x39 /* HIPPI interfaces */
+#define IFT_FRAMERELAYINTERCONNECT 0x3a /* Obsolete, use either 0x20 or 0x2c */
+#define IFT_AFLANE8023 0x3b /* ATM Emulated LAN for 802.3 */
+#define IFT_AFLANE8025 0x3c /* ATM Emulated LAN for 802.5 */
+#define IFT_CCTEMUL 0x3d /* ATM Emulated circuit */
+#define IFT_FASTETHER 0x3e /* Fast Ethernet (100BaseT) */
+#define IFT_ISDN 0x3f /* ISDN and X.25 */
+#define IFT_V11 0x40 /* CCITT V.11/X.21 */
+#define IFT_V36 0x41 /* CCITT V.36 */
+#define IFT_G703AT64K 0x42 /* CCITT G703 at 64Kbps */
+#define IFT_G703AT2MB 0x43 /* Obsolete see DS1-MIB */
+#define IFT_QLLC 0x44 /* SNA QLLC */
+#define IFT_FASTETHERFX 0x45 /* Fast Ethernet (100BaseFX) */
+#define IFT_CHANNEL 0x46 /* channel */
+#define IFT_IEEE80211 0x47 /* radio spread spectrum */
+#define IFT_IBM370PARCHAN 0x48 /* IBM System 360/370 OEMI Channel */
+#define IFT_ESCON 0x49 /* IBM Enterprise Systems Connection */
+#define IFT_DLSW 0x4a /* Data Link Switching */
+#define IFT_ISDNS 0x4b /* ISDN S/T interface */
+#define IFT_ISDNU 0x4c /* ISDN U interface */
+#define IFT_LAPD 0x4d /* Link Access Protocol D */
+#define IFT_IPSWITCH 0x4e /* IP Switching Objects */
+#define IFT_RSRB 0x4f /* Remote Source Route Bridging */
+#define IFT_ATMLOGICAL 0x50 /* ATM Logical Port */
+#define IFT_DS0 0x51 /* Digital Signal Level 0 */
+#define IFT_DS0BUNDLE 0x52 /* group of ds0s on the same ds1 */
+#define IFT_BSC 0x53 /* Bisynchronous Protocol */
+#define IFT_ASYNC 0x54 /* Asynchronous Protocol */
+#define IFT_CNR 0x55 /* Combat Net Radio */
+#define IFT_ISO88025DTR 0x56 /* ISO 802.5r DTR */
+#define IFT_EPLRS 0x57 /* Ext Pos Loc Report Sys */
+#define IFT_ARAP 0x58 /* Appletalk Remote Access Protocol */
+#define IFT_PROPCNLS 0x59 /* Proprietary Connectionless Protocol*/
+#define IFT_HOSTPAD 0x5a /* CCITT-ITU X.29 PAD Protocol */
+#define IFT_TERMPAD 0x5b /* CCITT-ITU X.3 PAD Facility */
+#define IFT_FRAMERELAYMPI 0x5c /* Multiproto Interconnect over FR */
+#define IFT_X213 0x5d /* CCITT-ITU X213 */
+#define IFT_ADSL 0x5e /* Asymmetric Digital Subscriber Loop */
+#define IFT_RADSL 0x5f /* Rate-Adapt. Digital Subscriber Loop*/
+#define IFT_SDSL 0x60 /* Symmetric Digital Subscriber Loop */
+#define IFT_VDSL 0x61 /* Very H-Speed Digital Subscrib. Loop*/
+#define IFT_ISO88025CRFPINT 0x62 /* ISO 802.5 CRFP */
+#define IFT_MYRINET 0x63 /* Myricom Myrinet */
+#define IFT_VOICEEM 0x64 /* voice recEive and transMit */
+#define IFT_VOICEFXO 0x65 /* voice Foreign Exchange Office */
+#define IFT_VOICEFXS 0x66 /* voice Foreign Exchange Station */
+#define IFT_VOICEENCAP 0x67 /* voice encapsulation */
+#define IFT_VOICEOVERIP 0x68 /* voice over IP encapsulation */
+#define IFT_ATMDXI 0x69 /* ATM DXI */
+#define IFT_ATMFUNI 0x6a /* ATM FUNI */
+#define IFT_ATMIMA 0x6b /* ATM IMA */
+#define IFT_PPPMULTILINKBUNDLE 0x6c /* PPP Multilink Bundle */
+#define IFT_IPOVERCDLC 0x6d /* IBM ipOverCdlc */
+#define IFT_IPOVERCLAW 0x6e /* IBM Common Link Access to Workstn */
+#define IFT_STACKTOSTACK 0x6f /* IBM stackToStack */
+#define IFT_VIRTUALIPADDRESS 0x70 /* IBM VIPA */
+#define IFT_MPC 0x71 /* IBM multi-protocol channel support */
+#define IFT_IPOVERATM 0x72 /* IBM ipOverAtm */
+#define IFT_ISO88025FIBER 0x73 /* ISO 802.5j Fiber Token Ring */
+#define IFT_TDLC 0x74 /* IBM twinaxial data link control */
+#define IFT_GIGABITETHERNET 0x75 /* Gigabit Ethernet */
+#define IFT_HDLC 0x76 /* HDLC */
+#define IFT_LAPF 0x77 /* LAP F */
+#define IFT_V37 0x78 /* V.37 */
+#define IFT_X25MLP 0x79 /* Multi-Link Protocol */
+#define IFT_X25HUNTGROUP 0x7a /* X25 Hunt Group */
+#define IFT_TRANSPHDLC 0x7b /* Transp HDLC */
+#define IFT_INTERLEAVE 0x7c /* Interleave channel */
+#define IFT_FAST 0x7d /* Fast channel */
+#define IFT_IP 0x7e /* IP (for APPN HPR in IP networks) */
+#define IFT_DOCSCABLEMACLAYER 0x7f /* CATV Mac Layer */
+#define IFT_DOCSCABLEDOWNSTREAM 0x80 /* CATV Downstream interface */
+#define IFT_DOCSCABLEUPSTREAM 0x81 /* CATV Upstream interface */
+#define IFT_A12MPPSWITCH 0x82 /* Avalon Parallel Processor */
+#define IFT_TUNNEL 0x83 /* Encapsulation interface */
+#define IFT_COFFEE 0x84 /* coffee pot */
+#define IFT_CES 0x85 /* Circiut Emulation Service */
+#define IFT_ATMSUBINTERFACE 0x86 /* (x) ATM Sub Interface */
+#define IFT_L2VLAN 0x87 /* Layer 2 Virtual LAN using 802.1Q */
+#define IFT_L3IPVLAN 0x88 /* Layer 3 Virtual LAN - IP Protocol */
+#define IFT_L3IPXVLAN 0x89 /* Layer 3 Virtual LAN - IPX Prot. */
+#define IFT_DIGITALPOWERLINE 0x8a /* IP over Power Lines */
+#define IFT_MEDIAMAILOVERIP 0x8b /* (xxx) Multimedia Mail over IP */
+#define IFT_DTM 0x8c /* Dynamic synchronous Transfer Mode */
+#define IFT_DCN 0x8d /* Data Communications Network */
+#define IFT_IPFORWARD 0x8e /* IP Forwarding Interface */
+#define IFT_MSDSL 0x8f /* Multi-rate Symmetric DSL */
+#define IFT_IEEE1394 0x90 /* IEEE1394 High Performance SerialBus*/
+#define IFT_IFGSN 0x91 /* HIPPI-6400 */
+#define IFT_DVBRCCMACLAYER 0x92 /* DVB-RCC MAC Layer */
+#define IFT_DVBRCCDOWNSTREAM 0x93 /* DVB-RCC Downstream Channel */
+#define IFT_DVBRCCUPSTREAM 0x94 /* DVB-RCC Upstream Channel */
+#define IFT_ATMVIRTUAL 0x95 /* ATM Virtual Interface */
+#define IFT_MPLSTUNNEL 0x96 /* MPLS Tunnel Virtual Interface */
+#define IFT_SRP 0x97 /* Spatial Reuse Protocol */
+#define IFT_VOICEOVERATM 0x98 /* Voice over ATM */
+#define IFT_VOICEOVERFRAMERELAY 0x99 /* Voice Over Frame Relay */
+#define IFT_IDSL 0x9a /* Digital Subscriber Loop over ISDN */
+#define IFT_COMPOSITELINK 0x9b /* Avici Composite Link Interface */
+#define IFT_SS7SIGLINK 0x9c /* SS7 Signaling Link */
+#define IFT_PROPWIRELESSP2P 0x9d /* Prop. P2P wireless interface */
+#define IFT_FRFORWARD 0x9e /* Frame forward Interface */
+#define IFT_RFC1483 0x9f /* Multiprotocol over ATM AAL5 */
+#define IFT_USB 0xa0 /* USB Interface */
+#define IFT_IEEE8023ADLAG 0xa1 /* IEEE 802.3ad Link Aggregate*/
+#define IFT_BGPPOLICYACCOUNTING 0xa2 /* BGP Policy Accounting */
+#define IFT_FRF16MFRBUNDLE 0xa3 /* FRF.16 Multilik Frame Relay*/
+#define IFT_H323GATEKEEPER 0xa4 /* H323 Gatekeeper */
+#define IFT_H323PROXY 0xa5 /* H323 Voice and Video Proxy */
+#define IFT_MPLS 0xa6 /* MPLS */
+#define IFT_MFSIGLINK 0xa7 /* Multi-frequency signaling link */
+#define IFT_HDSL2 0xa8 /* High Bit-Rate DSL, 2nd gen. */
+#define IFT_SHDSL 0xa9 /* Multirate HDSL2 */
+#define IFT_DS1FDL 0xaa /* Facility Data Link (4Kbps) on a DS1*/
+#define IFT_POS 0xab /* Packet over SONET/SDH Interface */
+#define IFT_DVBASILN 0xac /* DVB-ASI Input */
+#define IFT_DVBASIOUT 0xad /* DVB-ASI Output */
+#define IFT_PLC 0xae /* Power Line Communications */
+#define IFT_NFAS 0xaf /* Non-Facility Associated Signaling */
+#define IFT_TR008 0xb0 /* TROO8 */
+#define IFT_GR303RDT 0xb1 /* Remote Digital Terminal */
+#define IFT_GR303IDT 0xb2 /* Integrated Digital Terminal */
+#define IFT_ISUP 0xb3 /* ISUP */
+#define IFT_PROPDOCSWIRELESSMACLAYER 0xb4 /* prop/Wireless MAC Layer */
+#define IFT_PROPDOCSWIRELESSDOWNSTREAM 0xb5 /* prop/Wireless Downstream */
+#define IFT_PROPDOCSWIRELESSUPSTREAM 0xb6 /* prop/Wireless Upstream */
+#define IFT_HIPERLAN2 0xb7 /* HIPERLAN Type 2 Radio Interface */
+#define IFT_PROPBWAP2MP 0xb8 /* PropBroadbandWirelessAccess P2MP*/
+#define IFT_SONETOVERHEADCHANNEL 0xb9 /* SONET Overhead Channel */
+#define IFT_DIGITALWRAPPEROVERHEADCHANNEL 0xba /* Digital Wrapper Overhead */
+#define IFT_AAL2 0xbb /* ATM adaptation layer 2 */
+#define IFT_RADIOMAC 0xbc /* MAC layer over radio links */
+#define IFT_ATMRADIO 0xbd /* ATM over radio links */
+#define IFT_IMT 0xbe /* Inter-Machine Trunks */
+#define IFT_MVL 0xbf /* Multiple Virtual Lines DSL */
+#define IFT_REACHDSL 0xc0 /* Long Reach DSL */
+#define IFT_FRDLCIENDPT 0xc1 /* Frame Relay DLCI End Point */
+#define IFT_ATMVCIENDPT 0xc2 /* ATM VCI End Point */
+#define IFT_OPTICALCHANNEL 0xc3 /* Optical Channel */
+#define IFT_OPTICALTRANSPORT 0xc4 /* Optical Transport */
+
+#define IFT_STF 0xd7 /* 6to4 interface */
+
+/* not based on IANA assignments */
+#define IFT_GIF 0xf0
+#define IFT_PVC 0xf1
+#define IFT_FAITH 0xf2
+#define IFT_PFLOG 0xf6
+#define IFT_PFSYNC 0xf7
+#define IFT_CARP 0xf8 /* Common Address Redundancy Protocol */
+#endif /* !_NET_IF_TYPES_H_ */
diff --git a/cpukit/libnetworking/net/if_var.h b/cpukit/libnetworking/net/if_var.h
new file mode 100644
index 0000000000..7aa0ddbf43
--- /dev/null
+++ b/cpukit/libnetworking/net/if_var.h
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * From: @(#)if.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if_var.h,v 1.107 2006/06/19 22:20:44 mlaier Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_IF_VAR_H_
+#define _NET_IF_VAR_H_
+
+/*
+ * Structures defining a network interface, providing a packet
+ * transport mechanism (ala level 0 of the PUP protocols).
+ *
+ * Each interface accepts output datagrams of a specified maximum
+ * length, and provides higher level routines with input datagrams
+ * received from its medium.
+ *
+ * Output occurs when the routine if_output is called, with three parameters:
+ * (*ifp->if_output)(ifp, m, dst, rt)
+ * Here m is the mbuf chain to be sent and dst is the destination address.
+ * The output routine encapsulates the supplied datagram if necessary,
+ * and then transmits it on its medium.
+ *
+ * On input, each interface unwraps the data received by it, and either
+ * places it on the input queue of an internetwork datagram routine
+ * and posts the associated software interrupt, or passes the datagram to a raw
+ * packet input routine.
+ *
+ * Routines exist for locating interfaces by their addresses
+ * or for locating an interface on a certain network, as well as more general
+ * routing and gateway routines maintaining information used to locate
+ * interfaces. These routines live in the files if.c and route.c
+ */
+
+/*
+ * Forward structure declarations for function prototypes [sic].
+ */
+struct mbuf;
+#ifndef __rtems__
+struct thread;
+#endif
+struct rtentry;
+struct rt_addrinfo;
+struct socket;
+struct ether_header;
+#ifndef __rtems__
+struct carp_if;
+#endif
+
+#include <sys/queue.h> /* get TAILQ macros */
+
+/*
+ * Structure defining a queue for a network interface.
+ */
+struct ifqueue {
+ struct mbuf *ifq_head;
+ struct mbuf *ifq_tail;
+ int ifq_len;
+ int ifq_maxlen;
+ int ifq_drops;
+};
+
+/*
+ * Structure defining a network interface.
+ *
+ * (Would like to call this struct ``if'', but C isn't PL/1.)
+ */
+struct ifnet {
+ void *if_softc; /* pointer to driver state */
+ char *if_name; /* name, e.g. ``en'' or ``lo'' */
+ struct ifnet *if_next; /* all struct ifnets are chained */
+ struct ifaddr *if_addrlist; /* linked list of addresses per if */
+ int if_pcount; /* number of promiscuous listeners */
+ struct bpf_if *if_bpf; /* packet filter structure */
+ u_short if_index; /* numeric abbreviation for this if */
+ short if_unit; /* sub-unit for lower level driver */
+ short if_timer; /* time 'til if_watchdog called */
+ int if_flags; /* up/down, broadcast, etc. */
+ void *if_linkmib; /* link-type-specific MIB data */
+ size_t if_linkmiblen; /* length of above data */
+ struct if_data if_data;
+/* procedure handles */
+ int (*if_output) /* output routine (enqueue) */
+ (struct ifnet *, struct mbuf *, struct sockaddr *,
+ struct rtentry *);
+ void (*if_start) /* initiate output routine */
+ (struct ifnet *);
+ int (*if_ioctl) /* ioctl routine */
+ (struct ifnet *, ioctl_command_t, caddr_t);
+ void (*if_watchdog) /* timer routine */
+ (struct ifnet *);
+ int (*if_poll_recv) /* polled receive routine */
+ (struct ifnet *, int *);
+ int (*if_poll_xmit) /* polled transmit routine */
+ (struct ifnet *, int *);
+ void (*if_poll_intren) /* polled interrupt reenable routine */
+ (struct ifnet *);
+ void (*if_poll_slowinput) /* input routine for slow devices */
+ (struct ifnet *, struct mbuf *);
+ void (*if_init) /* Init routine */
+ (void *);
+ int (*if_tap) /* Packet filter routine */
+ (struct ifnet *, struct ether_header *, struct mbuf *);
+ struct ifqueue if_snd; /* output queue */
+ struct ifqueue *if_poll_slowq; /* input queue for slow devices */
+};
+
+typedef void if_init_f_t(void *);
+
+/*
+ * XXX These aliases are terribly dangerous because they could apply
+ * to anything.
+ */
+#define if_mtu if_data.ifi_mtu
+#define if_type if_data.ifi_type
+#define if_physical if_data.ifi_physical
+#define if_addrlen if_data.ifi_addrlen
+#define if_hdrlen if_data.ifi_hdrlen
+#define if_metric if_data.ifi_metric
+#define if_baudrate if_data.ifi_baudrate
+#define if_ipackets if_data.ifi_ipackets
+#define if_ierrors if_data.ifi_ierrors
+#define if_opackets if_data.ifi_opackets
+#define if_oerrors if_data.ifi_oerrors
+#define if_collisions if_data.ifi_collisions
+#define if_ibytes if_data.ifi_ibytes
+#define if_obytes if_data.ifi_obytes
+#define if_imcasts if_data.ifi_imcasts
+#define if_omcasts if_data.ifi_omcasts
+#define if_iqdrops if_data.ifi_iqdrops
+#define if_noproto if_data.ifi_noproto
+#define if_lastchange if_data.ifi_lastchange
+#define if_recvquota if_data.ifi_recvquota
+#define if_xmitquota if_data.ifi_xmitquota
+#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)NULL)
+
+/*
+ * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
+ * are queues of messages stored on ifqueue structures
+ * (defined above). Entries are added to and deleted from these structures
+ * by these macros, which should be called with ipl raised to splimp().
+ */
+#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
+#define IF_DROP(ifq) ((ifq)->ifq_drops++)
+
+#define IF_ENQUEUE(ifq, m) do { \
+ (m)->m_nextpkt = NULL; \
+ if ((ifq)->ifq_tail == NULL) \
+ (ifq)->ifq_head = m; \
+ else \
+ (ifq)->ifq_tail->m_nextpkt = m; \
+ (ifq)->ifq_tail = m; \
+ (ifq)->ifq_len++; \
+} while (0)
+
+#define IF_PREPEND(ifq, m) do { \
+ (m)->m_nextpkt = (ifq)->ifq_head; \
+ if ((ifq)->ifq_tail == NULL) \
+ (ifq)->ifq_tail = (m); \
+ (ifq)->ifq_head = (m); \
+ (ifq)->ifq_len++; \
+} while (0)
+
+#define IF_DEQUEUE(ifq, m) do { \
+ (m) = (ifq)->ifq_head; \
+ if (m) { \
+ if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
+ (ifq)->ifq_tail = NULL; \
+ (m)->m_nextpkt = NULL; \
+ (ifq)->ifq_len--; \
+ } \
+} while (0)
+
+/*
+ * The ifaddr structure contains information about one address
+ * of an interface. They are maintained by the different address families,
+ * are allocated and attached when an address is set, and are linked
+ * together so all addresses for an interface can be located.
+ */
+struct ifaddr {
+ struct sockaddr *ifa_addr; /* address of interface */
+ struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
+#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
+ struct sockaddr *ifa_netmask; /* used to determine subnet */
+ struct ifnet *ifa_ifp; /* back-pointer to interface */
+ struct ifaddr *ifa_next; /* next address for interface */
+ void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
+ (int, struct rtentry *, struct sockaddr *);
+ u_short ifa_flags; /* mostly rt_flags for cloning */
+ u_int ifa_refcnt; /* references to this structure */
+ int ifa_metric; /* cost of going out this interface */
+ int (*ifa_claim_addr) /* check if an addr goes to this if */
+ (struct ifaddr *, struct sockaddr *);
+
+};
+#define IFA_ROUTE RTF_UP /* route installed */
+
+#ifdef _KERNEL
+#define IFAFREE(ifa) \
+ if ((ifa)->ifa_refcnt <= 0) \
+ ifafree(ifa); \
+ else \
+ (ifa)->ifa_refcnt--;
+
+extern struct ifnet *ifnet;
+extern int ifqmaxlen;
+extern struct ifnet loif[];
+extern int if_index;
+extern struct ifaddr **ifnet_addrs;
+
+void if_attach(struct ifnet *);
+void if_down(struct ifnet *);
+void if_up(struct ifnet *);
+/*void ifinit(void);*/ /* declared in systm.h for main() */
+int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
+int ifpromisc(struct ifnet *, int);
+
+struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
+struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
+struct ifaddr *ifa_ifwithnet(struct sockaddr *);
+struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *);
+struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
+
+#endif /* _KERNEL */
+
+#endif /* !_NET_IF_VAR_H_ */
diff --git a/cpukit/libnetworking/net/netisr.h b/cpukit/libnetworking/net/netisr.h
new file mode 100644
index 0000000000..2dc99a3cc2
--- /dev/null
+++ b/cpukit/libnetworking/net/netisr.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 1980, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)netisr.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/netisr.h,v 1.33 2005/01/07 01:45:35 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_NETISR_H_
+#define _NET_NETISR_H_
+
+/*
+ * The networking code runs off software interrupts.
+ *
+ * You can switch into the network by doing splnet() and return by splx().
+ * The software interrupt level for the network is higher than the software
+ * level for the clock (so you can enter the network in routines called
+ * at timeout time).
+ */
+
+/*
+ * Each ``pup-level-1'' input queue has a bit in a ``netisr'' status
+ * word which is used to de-multiplex a single software
+ * interrupt used for scheduling the network code to calls
+ * on the lowest level routine of each protocol.
+ */
+#define NETISR_RAW 0 /* same as AF_UNSPEC */
+#define NETISR_IP 2 /* same as AF_INET */
+#define NETISR_IMP 3 /* same as AF_IMPLINK */
+#define NETISR_ISO 7 /* same as AF_ISO */
+#define NETISR_CCITT 10 /* same as AF_CCITT */
+#define NETISR_ATALK 16 /* same as AF_APPLETALK */
+#define NETISR_ARP 18 /* same as AF_LINK */
+#define NETISR_IPX 23 /* same as AF_IPX */
+#define NETISR_USB 25 /* USB soft interrupt */
+#define NETISR_PPP 26 /* PPP soft interrupt */
+
+#ifndef LOCORE
+#ifdef _KERNEL
+
+#define NETISR_SET(num, isr) /* FIXME: dummy, should be removed */
+
+extern volatile unsigned int netisr; /* scheduling bits for network */
+#define schednetisr(anisr) rtems_bsdnet_schednetisr(anisr)
+
+#endif
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/net/ppp_comp.h b/cpukit/libnetworking/net/ppp_comp.h
new file mode 100644
index 0000000000..5f37560e7a
--- /dev/null
+++ b/cpukit/libnetworking/net/ppp_comp.h
@@ -0,0 +1,168 @@
+/*
+ * ppp-comp.h - Definitions for doing PPP packet compression.
+ */
+/*
+ * Copyright (c) 1994 The Australian National University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation is hereby granted, provided that the above copyright
+ * notice appears in all copies. This software is provided without any
+ * warranty, express or implied. The Australian National University
+ * makes no representations about the suitability of this software for
+ * any purpose.
+ *
+ * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
+ * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+ * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
+ * OR MODIFICATIONS.
+ * $FreeBSD: src/sys/net/ppp_comp.h,v 1.12 2005/01/07 01:45:35 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_PPP_COMP_H
+#define _NET_PPP_COMP_H
+
+/*
+ * The following symbols control whether we include code for
+ * various compression methods.
+ */
+#ifndef DO_BSD_COMPRESS
+#define DO_BSD_COMPRESS 0 /* by default, include BSD-Compress */
+#endif
+#ifndef DO_DEFLATE
+#define DO_DEFLATE 0 /* by default, include Deflate */
+#endif
+#define DO_PREDICTOR_1 0
+#define DO_PREDICTOR_2 0
+
+/*
+ * Structure giving methods for compression/decompression.
+ */
+#ifdef PACKETPTR
+struct compressor {
+ int compress_proto; /* CCP compression protocol number */
+
+ /* Allocate space for a compressor (transmit side) */
+ void *(*comp_alloc)(u_char *options, int opt_len);
+ /* Free space used by a compressor */
+ void (*comp_free)(void *state);
+ /* Initialize a compressor */
+ int (*comp_init)(void *state, u_char *options, int opt_len,
+ int unit, int hdrlen, int debug);
+ /* Reset a compressor */
+ void (*comp_reset)(void *state);
+ /* Compress a packet */
+ int (*compress)(void *state, PACKETPTR *mret, PACKETPTR mp,
+ int orig_len, int max_len);
+ /* Return compression statistics */
+ void (*comp_stat)(void *state, struct compstat *stats);
+
+ /* Allocate space for a decompressor (receive side) */
+ void *(*decomp_alloc)(u_char *options, int opt_len);
+ /* Free space used by a decompressor */
+ void (*decomp_free)(void *state);
+ /* Initialize a decompressor */
+ int (*decomp_init)(void *state, u_char *options, int opt_len,
+ int unit, int hdrlen, int mru, int debug);
+ /* Reset a decompressor */
+ void (*decomp_reset)(void *state);
+ /* Decompress a packet. */
+ int (*decompress)(void *state, PACKETPTR mp, PACKETPTR *dmpp);
+ /* Update state for an incompressible packet received */
+ void (*incomp)(void *state, PACKETPTR mp);
+ /* Return decompression statistics */
+ void (*decomp_stat)(void *state, struct compstat *stats);
+};
+#endif /* PACKETPTR */
+
+/*
+ * Return values for decompress routine.
+ * We need to make these distinctions so that we can disable certain
+ * useful functionality, namely sending a CCP reset-request as a result
+ * of an error detected after decompression. This is to avoid infringing
+ * a patent held by Motorola.
+ * Don't you just lurve software patents.
+ */
+#define DECOMP_OK 0 /* everything went OK */
+#define DECOMP_ERROR 1 /* error detected before decomp. */
+#define DECOMP_FATALERROR 2 /* error detected after decomp. */
+
+/*
+ * CCP codes.
+ */
+#define CCP_CONFREQ 1
+#define CCP_CONFACK 2
+#define CCP_TERMREQ 5
+#define CCP_TERMACK 6
+#define CCP_RESETREQ 14
+#define CCP_RESETACK 15
+
+/*
+ * Max # bytes for a CCP option
+ */
+#define CCP_MAX_OPTION_LENGTH 32
+
+/*
+ * Parts of a CCP packet.
+ */
+#define CCP_CODE(dp) ((dp)[0])
+#define CCP_ID(dp) ((dp)[1])
+#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
+#define CCP_HDRLEN 4
+
+#define CCP_OPT_CODE(dp) ((dp)[0])
+#define CCP_OPT_LENGTH(dp) ((dp)[1])
+#define CCP_OPT_MINLEN 2
+
+/*
+ * Definitions for BSD-Compress.
+ */
+#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
+#define CILEN_BSD_COMPRESS 3 /* length of config. option */
+
+/* Macros for handling the 3rd byte of the BSD-Compress config option. */
+#define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
+#define BSD_VERSION(x) ((x) >> 5) /* version of option format */
+#define BSD_CURRENT_VERSION 1 /* current version number */
+#define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
+
+#define BSD_MIN_BITS 9 /* smallest code size supported */
+#define BSD_MAX_BITS 15 /* largest code size supported */
+
+/*
+ * Definitions for Deflate.
+ */
+#define CI_DEFLATE 26 /* config option for Deflate */
+#define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
+#define CILEN_DEFLATE 4 /* length of its config option */
+
+#define DEFLATE_MIN_SIZE 8
+#define DEFLATE_MAX_SIZE 15
+#define DEFLATE_METHOD_VAL 8
+#define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
+#define DEFLATE_METHOD(x) ((x) & 0x0F)
+#define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
+ + DEFLATE_METHOD_VAL)
+#define DEFLATE_CHK_SEQUENCE 0
+
+/*
+ * Definitions for other, as yet unsupported, compression methods.
+ */
+#define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
+#define CILEN_PREDICTOR_1 2 /* length of its config option */
+#define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
+#define CILEN_PREDICTOR_2 2 /* length of its config option */
+
+#endif /* _NET_PPP_COMP_H */
diff --git a/cpukit/libnetworking/net/ppp_defs.h b/cpukit/libnetworking/net/ppp_defs.h
new file mode 100644
index 0000000000..5df4fc7995
--- /dev/null
+++ b/cpukit/libnetworking/net/ppp_defs.h
@@ -0,0 +1,162 @@
+/*
+ * ppp_defs.h - PPP definitions.
+ *
+ * Copyright (c) 1994 The Australian National University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation is hereby granted, provided that the above copyright
+ * notice appears in all copies. This software is provided without any
+ * warranty, express or implied. The Australian National University
+ * makes no representations about the suitability of this software for
+ * any purpose.
+ *
+ * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
+ * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+ * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
+ * OR MODIFICATIONS.
+ *
+ * $FreeBSD: src/sys/net/ppp_defs.h,v 1.8 2005/01/07 01:45:35 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _PPP_DEFS_H_
+#define _PPP_DEFS_H_
+
+#include <stdint.h>
+
+/*
+ * The basic PPP frame.
+ */
+#define PPP_HDRLEN 4 /* octets for standard ppp header */
+#define PPP_FCSLEN 2 /* octets for FCS */
+#define PPP_MRU 1500 /* default MRU = max length of info field */
+
+#define PPP_ADDRESS(p) (((u_char *)(p))[0])
+#define PPP_CONTROL(p) (((u_char *)(p))[1])
+#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
+
+/*
+ * Significant octet values.
+ */
+#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
+#define PPP_UI 0x03 /* Unnumbered Information */
+#define PPP_FLAG 0x7e /* Flag Sequence */
+#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
+#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
+
+/*
+ * Protocol field values.
+ */
+#define PPP_IP 0x21 /* Internet Protocol */
+#define PPP_AT 0x29 /* AppleTalk Protocol */
+#define PPP_IPX 0x2b /* IPX protocol */
+#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
+#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
+#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
+#define PPP_COMP 0xfd /* compressed packet */
+#define PPP_IPCP 0x8021 /* IP Control Protocol */
+#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
+#define PPP_IPXCP 0x802b /* IPX Control Protocol */
+#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
+#define PPP_CCP 0x80fd /* Compression Control Protocol */
+#define PPP_LCP 0xc021 /* Link Control Protocol */
+#define PPP_PAP 0xc023 /* Password Authentication Protocol */
+#define PPP_LQR 0xc025 /* Link Quality Report protocol */
+#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
+#define PPP_CBCP 0xc029 /* Callback Control Protocol */
+
+/*
+ * Values for FCS calculations.
+ */
+#define PPP_INITFCS 0xffff /* Initial FCS value */
+#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
+#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
+
+/*
+ * Extended asyncmap - allows any character to be escaped.
+ */
+typedef uint32_t ext_accm[8];
+
+/*
+ * What to do with network protocol (NP) packets.
+ */
+enum NPmode {
+ NPMODE_PASS, /* pass the packet through */
+ NPMODE_DROP, /* silently drop the packet */
+ NPMODE_ERROR, /* return an error */
+ NPMODE_QUEUE /* save it up for later. */
+};
+
+/*
+ * Statistics.
+ */
+struct pppstat {
+ unsigned int ppp_ibytes; /* bytes received */
+ unsigned int ppp_ipackets; /* packets received */
+ unsigned int ppp_ierrors; /* receive errors */
+ unsigned int ppp_obytes; /* bytes sent */
+ unsigned int ppp_opackets; /* packets sent */
+ unsigned int ppp_oerrors; /* transmit errors */
+};
+
+struct vjstat {
+ unsigned int vjs_packets; /* outbound packets */
+ unsigned int vjs_compressed; /* outbound compressed packets */
+ unsigned int vjs_searches; /* searches for connection state */
+ unsigned int vjs_misses; /* times couldn't find conn. state */
+ unsigned int vjs_uncompressedin; /* inbound uncompressed packets */
+ unsigned int vjs_compressedin; /* inbound compressed packets */
+ unsigned int vjs_errorin; /* inbound unknown type packets */
+ unsigned int vjs_tossed; /* inbound packets tossed because of error */
+};
+
+struct ppp_stats {
+ struct pppstat p; /* basic PPP statistics */
+ struct vjstat vj; /* VJ header compression statistics */
+};
+
+struct compstat {
+ unsigned int unc_bytes; /* total uncompressed bytes */
+ unsigned int unc_packets; /* total uncompressed packets */
+ unsigned int comp_bytes; /* compressed bytes */
+ unsigned int comp_packets; /* compressed packets */
+ unsigned int inc_bytes; /* incompressible bytes */
+ unsigned int inc_packets; /* incompressible packets */
+ unsigned int ratio; /* recent compression ratio << 8 */
+};
+
+struct ppp_comp_stats {
+ struct compstat c; /* packet compression statistics */
+ struct compstat d; /* packet decompression statistics */
+};
+
+/*
+ * The following structure records the time in seconds since
+ * the last NP packet was sent or received.
+ */
+struct ppp_idle {
+ time_t xmit_idle; /* time since last NP packet sent */
+ time_t recv_idle; /* time since last NP packet received */
+};
+
+#ifndef __P
+#ifdef __STDC__
+#define __P(x) x
+#else
+#define __P(x) ()
+#endif
+#endif
+
+#endif /* _PPP_DEFS_H_ */
diff --git a/cpukit/libnetworking/net/ppp_tty.c b/cpukit/libnetworking/net/ppp_tty.c
new file mode 100644
index 0000000000..1d91266b4d
--- /dev/null
+++ b/cpukit/libnetworking/net/ppp_tty.c
@@ -0,0 +1,952 @@
+/*
+ * ppp_tty.c - Point-to-Point Protocol (PPP) driver for asynchronous
+ * tty devices.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Drew D. Perkins
+ * Carnegie Mellon University
+ * 4910 Forbes Ave.
+ * Pittsburgh, PA 15213
+ * (412) 268-8576
+ * ddp@andrew.cmu.edu
+ *
+ * Based on:
+ * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89
+ *
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Serial Line interface
+ *
+ * Rick Adams
+ * Center for Seismic Studies
+ * 1300 N 17th Street, Suite 1450
+ * Arlington, Virginia 22209
+ * (703)276-7900
+ * rick@seismo.ARPA
+ * seismo!rick
+ *
+ * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
+ * Converted to 4.3BSD Beta by Chris Torek.
+ * Other changes made at Berkeley, based in part on code by Kirk Smith.
+ *
+ * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
+ * Added VJ tcp header compression; more unified ioctls
+ *
+ * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
+ * Cleaned up a lot of the mbuf-related code to fix bugs that
+ * caused system crashes and packet corruption. Changed pppstart
+ * so that it doesn't just give up with a "collision" if the whole
+ * packet doesn't fit in the output ring buffer.
+ *
+ * Added priority queueing for interactive IP packets, following
+ * the model of if_sl.c, plus hooks for bpf.
+ * Paul Mackerras (paulus@cs.anu.edu.au).
+ */
+
+/* $FreeBSD: src/sys/net/ppp_tty.c,v 1.69 2005/10/16 20:44:18 phk Exp $ */
+/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
+/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_ppp.h" /* XXX for ppp_defs.h */
+
+#if NPPP > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/kernel.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+
+#ifdef VJC
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <net/slcompress.h>
+#endif
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <sys/ttycom.h>
+#include <termios.h>
+#include <rtems/termiostypes.h>
+
+#ifdef PPP_FILTER
+#include <net/bpf.h>
+#endif
+#include <net/ppp_defs.h>
+#include <net/if_ppp.h>
+#include <net/if_pppvar.h>
+
+
+void pppasyncattach(void);
+int pppopen(struct rtems_termios_tty *tty);
+int pppclose(struct rtems_termios_tty *tty);
+int pppread(struct rtems_termios_tty *tty, rtems_libio_rw_args_t *rw_args);
+int pppwrite(struct rtems_termios_tty *tty, rtems_libio_rw_args_t *rw_args);
+int ppptioctl(struct rtems_termios_tty *tty, rtems_libio_ioctl_args_t *args);
+int pppinput(int c, struct rtems_termios_tty *tty);
+int pppstart(struct rtems_termios_tty *tp);
+u_short pppfcs(u_short fcs, u_char *cp, int len);
+void pppallocmbuf(struct ppp_softc *sc, struct mbuf **mp);
+
+static void pppasyncstart(struct ppp_softc *);
+static void pppasyncctlp(struct ppp_softc *);
+static void pppasyncrelinq(struct ppp_softc *);
+/*static void ppp_timeout __P((void *)); */
+/*static void pppdumpb __P((u_char *b, int l)); */
+/*static void ppplogchar __P((struct ppp_softc *, int)); */
+
+/*
+ * Some useful mbuf macros not in mbuf.h.
+ */
+#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
+
+#define M_DATASTART(m) \
+ (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
+ (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
+
+#define M_DATASIZE(m) \
+ (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
+ (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
+
+/*
+ * We steal two bits in the mbuf m_flags, to mark high-priority packets
+ * for output, and received packets following lost/corrupted packets.
+ */
+#define M_HIGHPRI 0x2000 /* output packet for sc_fastq */
+#define M_ERRMARK 0x4000 /* steal a bit in mbuf m_flags */
+
+/*
+ * Does c need to be escaped?
+ */
+#define ESCAPE_P(c) (sc->sc_asyncmap[(c) >> 5] & (1 << ((c) & 0x1F)))
+
+/*
+ * Procedures for using an async tty interface for PPP.
+ */
+
+/* This is a FreeBSD-2.0 kernel. */
+#define CCOUNT(rb) (((rb).Size+(rb).Head-(rb).Tail) % (rb).Size)
+#define FCOUNT(rb) ((rb).Size-CCOUNT(rb)-1)
+#define PPP_LOWAT 100 /* Process more output when < LOWAT on queue */
+#define PPP_HIWAT 400 /* Don't start a new packet if HIWAT on que */
+
+/*
+ * Define the PPP line discipline.
+ */
+
+static struct rtems_termios_linesw pppdisc = {
+ pppopen, pppclose, pppread, pppwrite,
+ pppinput, pppstart, ppptioctl, NULL
+};
+
+void
+pppasyncattach(void)
+{
+ rtems_termios_linesw[PPPDISC] = pppdisc;
+}
+
+TEXT_SET(pseudo_set, pppasyncattach);
+
+/*
+ * Line specific open routine for async tty devices.
+ * Attach the given tty to the first available ppp unit.
+ * Called from device open routine or ttioctl.
+ */
+/* ARGSUSED */
+int
+pppopen(struct rtems_termios_tty *tty)
+{
+ int i;
+ register struct ppp_softc *sc;
+ struct mbuf *m = (struct mbuf *)0;
+
+ if (tty->t_line == PPPDISC) {
+ sc = (struct ppp_softc *)tty->t_sc;
+ if (sc != NULL && sc->sc_devp == (void *)tty) {
+ return (0);
+ }
+ }
+
+ if ((sc = pppalloc(1)) == NULL) {
+ return ENXIO;
+ }
+
+ if (sc->sc_relinq)
+ (*sc->sc_relinq)(sc); /* get previous owner to relinquish the unit */
+
+ sc->sc_ilen = 0;
+ sc->sc_m = NULL;
+ bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
+ sc->sc_asyncmap[0] = 0xffffffff;
+ sc->sc_asyncmap[3] = 0x60000000;
+ sc->sc_rasyncmap = 0;
+ sc->sc_devp = tty;
+ sc->sc_start = pppasyncstart;
+ sc->sc_ctlp = pppasyncctlp;
+ sc->sc_relinq = pppasyncrelinq;
+ sc->sc_outm = NULL;
+ sc->sc_outmc = NULL;
+
+ /* preallocate mbufs for free queue */
+ rtems_bsdnet_semaphore_obtain();
+ for (i=0; i<NUM_MBUFQ; i++) {
+ pppallocmbuf(sc, &m);
+ if ( i == 0 ) {
+ /* use first mbuf for rx iterrupt handling */
+ sc->sc_m = m;
+ }
+ else {
+ /* enqueue mbuf for later use */
+ IF_ENQUEUE(&sc->sc_freeq, m);
+ }
+ m = (struct mbuf *)0;
+ }
+ rtems_bsdnet_semaphore_release();
+
+ /* initialize values */
+ sc->sc_if.if_flags |= IFF_RUNNING;
+ sc->sc_if.if_baudrate =
+ rtems_termios_baud_to_number(tty->termios.c_cflag & CBAUD);
+
+ tty->t_sc = (void *)sc;
+
+ return ( RTEMS_SUCCESSFUL );
+}
+
+/*
+ * Line specific close routine, called from device close routine
+ * and from ttioctl.
+ * Detach the tty from the ppp unit.
+ * Mimics part of ttyclose().
+ */
+int
+pppclose(struct rtems_termios_tty *tty)
+{
+ register struct ppp_softc *sc;
+
+ tty->t_line = 0;
+ sc = (struct ppp_softc *)tty->t_sc;
+ if (sc != NULL) {
+ tty->t_sc = NULL;
+ if (tty == (struct rtems_termios_tty *)sc->sc_devp) {
+ rtems_bsdnet_semaphore_obtain();
+ pppasyncrelinq(sc);
+ pppdealloc(sc);
+ rtems_bsdnet_semaphore_release();
+ }
+ }
+ return ( RTEMS_SUCCESSFUL );
+}
+
+/*
+ * Relinquish the interface unit to another device.
+ */
+static void
+pppasyncrelinq(struct ppp_softc *sc)
+{
+#ifdef XXX_XXX
+ if (sc->sc_outm) {
+ m_freem(sc->sc_outm);
+ sc->sc_outm = NULL;
+ }
+ if (sc->sc_m) {
+ m_freem(sc->sc_m);
+ sc->sc_m = NULL;
+ }
+ if (sc->sc_flags & SC_TIMEOUT) {
+ untimeout(ppp_timeout, (void *) sc);
+ sc->sc_flags &= ~SC_TIMEOUT;
+ }
+#endif
+}
+
+/*
+ * Line specific (tty) read routine.
+ */
+int
+pppread(struct rtems_termios_tty *tty, rtems_libio_rw_args_t *rw_args)
+{
+ rtems_status_code status = RTEMS_UNSATISFIED;
+ int count = 0;
+ int maximum = rw_args->count;
+ char *buffer = rw_args->buffer;
+ register struct ppp_softc *sc = (struct ppp_softc *)tty->t_sc;
+ struct mbuf *m;
+ struct mbuf *m0;
+ u_char *p;
+
+ if (sc == NULL)
+ return 0;
+
+ /*
+ * Loop waiting for input, checking that nothing disasterous
+ * happens in the meantime.
+ */
+ if (tty != (struct rtems_termios_tty *)sc->sc_devp || tty->t_line != PPPDISC) {
+ return ( status );
+ }
+ if (sc->sc_inq.ifq_head == NULL) {
+ return ( status );
+ }
+
+ /* Get the packet from the input queue */
+ rtems_bsdnet_semaphore_obtain();
+ IF_DEQUEUE(&sc->sc_inq, m0);
+
+ /* loop over mbuf chain */
+ m = m0;
+ while (( m != NULL ) && ( m->m_len > 0 ) && ( count+m->m_len < maximum )) {
+ /* copy data into buffer */
+ p = mtod(m, u_char *);
+ memcpy(buffer, p, m->m_len);
+ memset(p, 0, m->m_len);
+ count += m->m_len;
+ buffer += m->m_len;
+
+ /* increment loop index */
+ m = m->m_next;
+ }
+
+ /* free mbuf chain */
+ m_freem(m0);
+ rtems_bsdnet_semaphore_release();
+
+ /* update return values */
+ rw_args->bytes_moved = count;
+ if ( count >= 0 ) {
+ status = RTEMS_SUCCESSFUL;
+ }
+
+ /* check to see if queue is empty */
+ if (sc->sc_inq.ifq_head != NULL) {
+ /* queue is not empty - post another event to ourself */
+ rtems_event_send(sc->sc_pppdtask, PPPD_EVENT);
+ }
+
+ return ( status );
+}
+
+/*
+ * Line specific (tty) write routine.
+ */
+int
+pppwrite(struct rtems_termios_tty *tty, rtems_libio_rw_args_t *rw_args)
+{
+ struct sockaddr dst;
+ int n;
+ int len;
+ int maximum = rw_args->count;
+ char *out_buffer = rw_args->buffer;
+ register struct ppp_softc *sc = (struct ppp_softc *)tty->t_sc;
+ struct mbuf *m;
+ struct mbuf *m0;
+ struct mbuf **mp;
+
+ rtems_bsdnet_semaphore_obtain();
+ for (mp = &m0; maximum; mp = &m->m_next) {
+ MGET(m, M_WAIT, MT_DATA);
+ if ((*mp = m) == NULL) {
+ m_freem(m0);
+ return (ENOBUFS);
+ }
+ m->m_len = 0;
+ if (maximum >= MCLBYTES / 2) {
+ MCLGET(m, M_DONTWAIT);
+ }
+ len = M_TRAILINGSPACE(m);
+ if (len > maximum) {
+ memcpy(mtod(m, u_char *),out_buffer,maximum);
+ m->m_len = maximum;
+ maximum = 0;
+ }
+ else {
+ memcpy(mtod(m, u_char *),out_buffer,len);
+ m->m_len = len;
+ maximum -= len;
+ out_buffer += len;
+ }
+ }
+
+ dst.sa_family = AF_UNSPEC;
+ bcopy(mtod(m0, u_char *), dst.sa_data, PPP_HDRLEN);
+ m0->m_data += PPP_HDRLEN;
+ m0->m_len -= PPP_HDRLEN;
+
+ n = pppoutput(&sc->sc_if, m0, &dst, (struct rtentry *)0);
+ rtems_bsdnet_semaphore_release();
+
+ return ( n );
+}
+
+/*
+ * Line specific (tty) ioctl routine.
+ * This discipline requires that tty device drivers call
+ * the line specific l_ioctl routine from their ioctl routines.
+ */
+/* ARGSUSED */
+int
+ppptioctl(struct rtems_termios_tty *tty, rtems_libio_ioctl_args_t *args)
+{
+/* int i; */
+ int error = RTEMS_SUCCESSFUL;
+ ioctl_command_t cmd = args->command;
+ caddr_t data = args->buffer;
+ struct ppp_softc *sc = tty->t_sc;
+
+ switch (cmd) {
+ case RTEMS_IO_GET_ATTRIBUTES:
+ case RTEMS_IO_SET_ATTRIBUTES:
+ case RTEMS_IO_TCDRAIN:
+ case RTEMS_IO_SNDWAKEUP:
+ case RTEMS_IO_RCVWAKEUP:
+ case TIOCGETD:
+ case TIOCSETD:
+ error = rtems_termios_ioctl(args);
+ break;
+
+ case PPPIOCSASYNCMAP:
+ sc->sc_asyncmap[0] = *(u_int *)data;
+ break;
+
+ case PPPIOCGASYNCMAP:
+ *(u_int *)data = sc->sc_asyncmap[0];
+ break;
+
+ case PPPIOCSRASYNCMAP:
+ sc->sc_rasyncmap = *(u_int *)data;
+ break;
+
+ case PPPIOCGRASYNCMAP:
+ *(u_int *)data = sc->sc_rasyncmap;
+ break;
+
+ case PPPIOCSXASYNCMAP:
+ bcopy(data, sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
+ sc->sc_asyncmap[1] = 0; /* mustn't escape 0x20 - 0x3f */
+ sc->sc_asyncmap[2] &= ~0x40000000; /* mustn't escape 0x5e */
+ sc->sc_asyncmap[3] |= 0x60000000; /* must escape 0x7d, 0x7e */
+ break;
+
+ case PPPIOCGXASYNCMAP:
+ bcopy(sc->sc_asyncmap, data, sizeof(sc->sc_asyncmap));
+ break;
+
+ default:
+ rtems_bsdnet_semaphore_obtain();
+ error = pppioctl(sc, cmd, data, 0, NULL);
+ rtems_bsdnet_semaphore_release();
+ }
+ return error;
+}
+
+/*
+ * FCS lookup table as calculated by genfcstab.
+ */
+static u_short fcstab[256] = {
+ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
+ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
+ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
+ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
+ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
+ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
+ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
+ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
+ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
+ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
+ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
+ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
+ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
+ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
+ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
+ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
+ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
+ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
+ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
+ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
+ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
+ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
+ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
+ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
+ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
+ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
+ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
+ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
+ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
+ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
+ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
+ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
+};
+
+/*
+ * Calculate a new FCS given the current FCS and the new data.
+ */
+u_short
+pppfcs(u_short fcs, u_char *cp, int len)
+{
+ while (len--)
+ fcs = PPP_FCS(fcs, *cp++);
+ return (fcs);
+}
+
+/*
+ * This gets called at splsoftnet from if_ppp.c at various times
+ * when there is data ready to be sent.
+ */
+void pppasyncstart(struct ppp_softc *sc)
+{
+ /* check to see if output is not active */
+ if ( sc->sc_outflag == 0 ) {
+ /* mark active and post tx event to daemon */
+ sc->sc_outflag |= SC_TX_PENDING;
+ rtems_event_send(sc->sc_txtask, TX_PACKET);
+ }
+}
+
+/*
+ * This gets called when a received packet is placed on
+ * the inq, at splsoftnet.
+ */
+static void
+pppasyncctlp(
+ struct ppp_softc *sc)
+{
+ /* check to see if task id was set */
+ if ( sc->sc_pppdtask != 0 ) {
+ /* post event to daemon */
+ rtems_event_send(sc->sc_pppdtask, PPPD_EVENT);
+ }
+}
+
+/*
+ * Start output on async tty interface. If the transmit queue
+ * has drained sufficiently, arrange for pppasyncstart to be
+ * called later at splsoftnet.
+ * Called at spltty or higher.
+ */
+int
+pppstart(struct rtems_termios_tty *tp)
+{
+ u_char *sendBegin;
+ u_long ioffset = (u_long )0;
+ struct mbuf *m = (struct mbuf *)0;
+ struct ppp_softc *sc = tp->t_sc;
+
+ /* ensure input is valid and we are busy */
+ if (( sc != NULL ) && ( sc->sc_outflag & SC_TX_BUSY )) {
+ /* check to see if we need to get the next buffer */
+
+ /* Ready with PPP_FLAG Character ? */
+ if(sc->sc_outflag & SC_TX_LASTCHAR){
+ sc->sc_outflag &= ~(SC_TX_BUSY | SC_TX_FCS | SC_TX_LASTCHAR);
+ rtems_event_send(sc->sc_txtask, TX_TRANSMIT); /* Ready for the next Packet */
+ return(0);
+ }
+
+ if ( sc->sc_outoff >= sc->sc_outlen ) {
+ /* loop to get next non-zero length buffer */
+ if ( sc->sc_outmc != NULL ) {
+ m = sc->sc_outmc->m_next;
+ }
+
+ /* check for next mbuf in chain */
+ if ( m != NULL ) {
+ /* update values to use this mbuf */
+ sc->sc_outmc = m;
+ sc->sc_outbuf = mtod(m, u_char *);
+ sc->sc_outlen = m->m_len;
+ sc->sc_outoff = (short)0;
+ }
+ else if ( (sc->sc_outflag & SC_TX_FCS) == 0 ) {
+ /* setup to use FCS buffer */
+ sc->sc_outflag |= SC_TX_FCS;
+ sc->sc_outbuf = sc->sc_outfcsbuf;
+ sc->sc_outlen = sc->sc_outfcslen;
+ sc->sc_outoff = (short)0;
+ }
+ else {
+ /* done with this packet */
+ sc->sc_outflag |= SC_TX_LASTCHAR;
+ sc->sc_outflag &=~(SC_TX_FCS);
+ sc->sc_outchar = (u_char)PPP_FLAG;
+ (*tp->device.write)(tp->minor, (char *)&sc->sc_outchar, 1);
+ return(0);
+ }
+ }
+
+ /* check to see if there is some data to write out */
+ if ( sc->sc_outoff < sc->sc_outlen ) {
+ /* check to see if character needs to be escaped */
+ sc->sc_outchar = sc->sc_outbuf[sc->sc_outoff];
+ if ( ESCAPE_P(sc->sc_outchar) ) {
+ if ( sc->sc_outflag & SC_TX_ESCAPE ) {
+ /* last sent character was the escape character */
+ sc->sc_outchar = sc->sc_outchar ^ PPP_TRANS;
+
+ /* clear the escape flag and increment the offset */
+ sc->sc_outflag &= ~SC_TX_ESCAPE;
+ ioffset++;
+ }
+ else {
+ /* need to send the escape character */
+ sc->sc_outchar = PPP_ESCAPE;
+
+ /* set the escape flag */
+ sc->sc_outflag |= SC_TX_ESCAPE;
+ }
+ sendBegin = &sc->sc_outchar;
+ }
+ else {
+ /* escape not needed - increment the offset as much as possible */
+ while ((!ESCAPE_P(sc->sc_outchar)) && ((sc->sc_outoff + ioffset) < sc->sc_outlen)) {
+ ioffset++;
+ sc->sc_outchar = sc->sc_outbuf[sc->sc_outoff + ioffset];
+ }
+ sendBegin = &sc->sc_outbuf[sc->sc_outoff];
+ }
+
+ /* write out the character(s) and update the stats */
+ (*tp->device.write)(tp->minor, (char *)sendBegin, (ioffset > 0) ? ioffset : 1);
+ sc->sc_stats.ppp_obytes += (ioffset > 0) ? ioffset : 1;
+ sc->sc_outoff += ioffset;
+ }
+ }
+
+ return ( 0 );
+}
+
+#ifdef XXX_XXX
+/*
+ * Timeout routine - try to start some more output.
+ */
+static void
+ppp_timeout(void *x)
+{
+ struct rtems_termios_tty *tty = (struct rtems_termios_tty *)x;
+ struct ppp_softc *sc = tty->t_sc;
+/* struct rtems_termios_tty *tp = (struct rtems_termios_tty *)sc->sc_devp; */
+
+ sc->sc_flags &= ~SC_TIMEOUT;
+/* pppstart(tp); */
+}
+#endif
+
+/*
+ * Allocate enough mbuf to handle current MRU.
+ */
+#ifdef XXX_XXX
+static void
+pppgetm(struct ppp_softc *sc)
+{
+ struct mbuf *m, **mp;
+ int len;
+
+ mp = &sc->sc_m;
+ for (len = sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN; len > 0; ){
+ if ((m = *mp) == NULL) {
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == NULL)
+ break;
+ *mp = m;
+ MCLGET(m, M_DONTWAIT);
+ }
+ len -= M_DATASIZE(m);
+ mp = &m->m_next;
+ }
+}
+#endif
+
+void
+pppallocmbuf(struct ppp_softc *sc, struct mbuf **mp)
+{
+ int ilen;
+ struct mbuf *m;
+
+ /* loop over length value */
+ ilen = sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN;
+ while ( ilen > 0 ) {
+ /* see if this is end of the chain */
+ m = *mp;
+ if ( m == NULL ) {
+ /* get mbuf header */
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if ( m == NULL ) {
+ /* error - set condition to break out */
+ printf("pppallocmbuf: MGETHDR failed\n");
+ break;
+ }
+ MCLGET(m, M_DONTWAIT);
+ m->m_next = NULL;
+ *mp = m;
+ }
+
+ /* update loop variables */
+ mp = &m->m_next;
+ ilen -= M_DATASIZE(m);
+ }
+}
+
+/*
+ * tty interface receiver interrupt.
+ */
+static uint32_t paritytab[8] = {
+ 0x96696996L, 0x69969669L, 0x69969669L, 0x96696996L,
+ 0x69969669L, 0x96696996L, 0x96696996L, 0x69969669L
+};
+
+int
+pppinput(int c, struct rtems_termios_tty *tp)
+{
+ register struct ppp_softc *sc = tp->t_sc;
+ struct mbuf *m;
+ int ilen;
+
+ if (sc == NULL || tp != (struct rtems_termios_tty *)sc->sc_devp)
+ return 0;
+ if (sc->sc_m == NULL) {
+ rtems_event_send(sc->sc_rxtask, RX_EMPTY);
+ IF_DEQUEUE(&sc->sc_freeq, sc->sc_m);
+ if ( sc->sc_m == NULL ) {
+ return 0;
+ }
+ }
+
+ ++sc->sc_stats.ppp_ibytes;
+
+ c &= 0xff;
+ if (c & 0x80)
+ sc->sc_flags |= SC_RCV_B7_1;
+ else
+ sc->sc_flags |= SC_RCV_B7_0;
+ if (paritytab[c >> 5] & (1 << (c & 0x1F)))
+ sc->sc_flags |= SC_RCV_ODDP;
+ else
+ sc->sc_flags |= SC_RCV_EVNP;
+
+ if (c == PPP_FLAG) {
+ ilen = sc->sc_ilen;
+ sc->sc_ilen = 0;
+
+ /*
+ * If SC_ESCAPED is set, then we've seen the packet
+ * abort sequence "}~".
+ */
+ if (sc->sc_flags & (SC_FLUSH | SC_ESCAPED)
+ || (ilen > 0 && sc->sc_fcs != PPP_GOODFCS)) {
+ sc->sc_flags |= SC_PKTLOST; /* note the dropped packet */
+ if ((sc->sc_flags & (SC_FLUSH | SC_ESCAPED)) == 0){
+ /* bad fcs error */
+ sc->sc_if.if_ierrors++;
+ sc->sc_stats.ppp_ierrors++;
+ } else
+ sc->sc_flags &= ~(SC_FLUSH | SC_ESCAPED);
+ return 0;
+ }
+
+ if (ilen < PPP_HDRLEN + PPP_FCSLEN) {
+ if (ilen) {
+ /* too short error */
+ sc->sc_if.if_ierrors++;
+ sc->sc_stats.ppp_ierrors++;
+ sc->sc_flags |= SC_PKTLOST;
+ }
+ return 0;
+ }
+
+ /* Remove FCS trailer. Somewhat painful... */
+ ilen -= 2;
+ if (--sc->sc_mc->m_len == 0) {
+ for (m = sc->sc_m; m->m_next != sc->sc_mc; m = m->m_next);
+ sc->sc_mc = m;
+ }
+ sc->sc_mc->m_len--;
+
+ /* excise this mbuf chain - place on raw queue */
+ m = sc->sc_m;
+ if ( sc->sc_flags & SC_PKTLOST ) {
+ m->m_flags |= M_ERRMARK;
+ sc->sc_flags &= ~SC_PKTLOST;
+ }
+ IF_ENQUEUE(&sc->sc_rawq, m);
+
+ /* setup next mbuf chain */
+ IF_DEQUEUE(&sc->sc_freeq, sc->sc_m);
+
+ /* send rx packet event */
+ rtems_event_send(sc->sc_rxtask, RX_PACKET);
+ return 0;
+ }
+
+ if (c < 0x20 && (sc->sc_rasyncmap & (1 << c)))
+ return 0;
+
+ if (sc->sc_flags & SC_ESCAPED) {
+ sc->sc_flags &= ~SC_ESCAPED;
+ c ^= PPP_TRANS;
+ } else if (c == PPP_ESCAPE) {
+ sc->sc_flags |= SC_ESCAPED;
+ return 0;
+ }
+
+ /*
+ * Initialize buffer on first octet received.
+ * First octet could be address or protocol (when compressing
+ * address/control).
+ * Second octet is control.
+ * Third octet is first or second (when compressing protocol)
+ * octet of protocol.
+ * Fourth octet is second octet of protocol.
+ */
+ if (sc->sc_ilen == 0) {
+ m = sc->sc_m;
+ m->m_len = 0;
+ m->m_data = M_DATASTART(sc->sc_m);
+ sc->sc_mc = m;
+ sc->sc_mp = mtod(m, char *);
+ sc->sc_fcs = PPP_INITFCS;
+ if (c != PPP_ALLSTATIONS) {
+ if (sc->sc_flags & SC_REJ_COMP_AC) {
+ /* garbage received error */
+ goto flush;
+ }
+ *sc->sc_mp++ = PPP_ALLSTATIONS;
+ *sc->sc_mp++ = PPP_UI;
+ sc->sc_ilen += 2;
+ m->m_len += 2;
+ }
+ }
+ if (sc->sc_ilen == 1 && c != PPP_UI) {
+ /* missing UI error */
+ goto flush;
+ }
+ if (sc->sc_ilen == 2 && (c & 1) == 1) {
+ /* a compressed protocol */
+ *sc->sc_mp++ = 0;
+ sc->sc_ilen++;
+ sc->sc_mc->m_len++;
+ }
+ if (sc->sc_ilen == 3 && (c & 1) == 0) {
+ /* bad protocol error */
+ goto flush;
+ }
+
+ /* packet beyond configured mru? */
+ if (++sc->sc_ilen > sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN) {
+ /* packet too big error */
+ goto flush;
+ }
+
+ /* is this mbuf full? */
+ m = sc->sc_mc;
+ if (M_TRAILINGSPACE(m) <= 0) {
+ if (m->m_next == NULL) {
+ /* get next available mbuf for the chain */
+ IF_DEQUEUE(&sc->sc_freeq, m->m_next);
+ if (m->m_next == NULL) {
+ /* too few mbufs */
+ goto flush;
+ }
+ else {
+ /* send rx mbuf event */
+ rtems_event_send(sc->sc_rxtask, RX_MBUF);
+ }
+ }
+ sc->sc_mc = m = m->m_next;
+ m->m_len = 0;
+ m->m_next = 0;
+ m->m_data = M_DATASTART(m);
+ sc->sc_mp = mtod(m, char *);
+ }
+
+ ++m->m_len;
+ *sc->sc_mp++ = c;
+ sc->sc_fcs = PPP_FCS(sc->sc_fcs, c);
+ return 0;
+
+ flush:
+ if (!(sc->sc_flags & SC_FLUSH)) {
+ sc->sc_if.if_ierrors++;
+ sc->sc_stats.ppp_ierrors++;
+ sc->sc_flags |= SC_FLUSH;
+ }
+ return 0;
+}
+
+#ifdef XXX_XXX
+#define MAX_DUMP_BYTES 128
+
+static void
+ppplogchar(struct ppp_softc *sc, int c)
+{
+ if (c >= 0)
+ sc->sc_rawin[sc->sc_rawin_count++] = c;
+ if (sc->sc_rawin_count >= sizeof(sc->sc_rawin)
+ || (c < 0 && sc->sc_rawin_count > 0)) {
+ printf("ppp%d input: ", sc->sc_if.if_unit);
+ pppdumpb(sc->sc_rawin, sc->sc_rawin_count);
+ sc->sc_rawin_count = 0;
+ }
+}
+
+static void
+pppdumpb(u_char *b, int l)
+{
+ char buf[3*MAX_DUMP_BYTES+4];
+ char *bp = buf;
+ static char digits[] = "0123456789abcdef";
+
+ while (l--) {
+ if (bp >= buf + sizeof(buf) - 3) {
+ *bp++ = '>';
+ break;
+ }
+ *bp++ = digits[*b >> 4]; /* convert byte to ascii hex */
+ *bp++ = digits[*b++ & 0xf];
+ *bp++ = ' ';
+ }
+
+ *bp = 0;
+ printf("%s\n", buf);
+}
+#endif
+
+#endif /* NPPP > 0 */
diff --git a/cpukit/libnetworking/net/radix.c b/cpukit/libnetworking/net/radix.c
new file mode 100644
index 0000000000..d1a9e90832
--- /dev/null
+++ b/cpukit/libnetworking/net/radix.c
@@ -0,0 +1,1043 @@
+/*
+ * Copyright (c) 1988, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)radix.c 8.5 (Berkeley) 5/19/95
+ * $FreeBSD: src/sys/net/radix.c,v 1.36 2004/04/21 15:27:36 luigi Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Routines to build and maintain radix trees for routing lookups.
+ */
+#ifndef _RADIX_H_
+#include <sys/param.h>
+#ifdef _KERNEL
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#define M_DONTWAIT M_NOWAIT
+#include <sys/domain.h>
+#else
+#include <stdlib.h>
+#endif
+#include <sys/syslog.h>
+#include <net/radix.h>
+#endif
+
+static int rn_walktree_from(struct radix_node_head *h, void *a, void *m,
+ walktree_f_t *f, void *w);
+static int rn_walktree(struct radix_node_head *, walktree_f_t *, void *);
+static struct radix_node
+ *rn_insert(void *, struct radix_node_head *, int *,
+ struct radix_node [2]),
+ *rn_newpair(void *, int, struct radix_node[2]),
+ *rn_search(void *, struct radix_node *),
+ *rn_search_m(void *, struct radix_node *, void *);
+
+static int max_keylen;
+static struct radix_mask *rn_mkfreelist;
+static struct radix_node_head *mask_rnhead;
+static char *addmask_key;
+static char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1};
+static char *rn_zeros, *rn_ones;
+
+#define rn_masktop (mask_rnhead->rnh_treetop)
+#undef Bcmp
+#define Bcmp(a, b, l) \
+ (l == 0 ? 0 : bcmp((caddr_t)(a), (caddr_t)(b), (u_long)l))
+
+static int rn_lexobetter(void *m_arg, void *n_arg);
+static struct radix_mask *
+ rn_new_radix_mask(struct radix_node *tt,
+ struct radix_mask *next);
+static int rn_satisfies_leaf(char *trial, struct radix_node *leaf,
+ int skip);
+
+/*
+ * The data structure for the keys is a radix tree with one way
+ * branching removed. The index rn_bit at an internal node n represents a bit
+ * position to be tested. The tree is arranged so that all descendants
+ * of a node n have keys whose bits all agree up to position rn_bit - 1.
+ * (We say the index of n is rn_bit.)
+ *
+ * There is at least one descendant which has a one bit at position rn_bit,
+ * and at least one with a zero there.
+ *
+ * A route is determined by a pair of key and mask. We require that the
+ * bit-wise logical and of the key and mask to be the key.
+ * We define the index of a route to associated with the mask to be
+ * the first bit number in the mask where 0 occurs (with bit number 0
+ * representing the highest order bit).
+ *
+ * We say a mask is normal if every bit is 0, past the index of the mask.
+ * If a node n has a descendant (k, m) with index(m) == index(n) == rn_bit,
+ * and m is a normal mask, then the route applies to every descendant of n.
+ * If the index(m) < rn_bit, this implies the trailing last few bits of k
+ * before bit b are all 0, (and hence consequently true of every descendant
+ * of n), so the route applies to all descendants of the node as well.
+ *
+ * Similar logic shows that a non-normal mask m such that
+ * index(m) <= index(n) could potentially apply to many children of n.
+ * Thus, for each non-host route, we attach its mask to a list at an internal
+ * node as high in the tree as we can go.
+ *
+ * The present version of the code makes use of normal routes in short-
+ * circuiting an explict mask and compare operation when testing whether
+ * a key satisfies a normal route, and also in remembering the unique leaf
+ * that governs a subtree.
+ */
+
+static struct radix_node *
+rn_search(void *v_arg, struct radix_node *head)
+{
+ register struct radix_node *x;
+ register caddr_t v;
+
+ for (x = head, v = v_arg; x->rn_bit >= 0;) {
+ if (x->rn_bmask & v[x->rn_offset])
+ x = x->rn_right;
+ else
+ x = x->rn_left;
+ }
+ return (x);
+}
+
+static struct radix_node *
+rn_search_m(void *v_arg, struct radix_node *head, void *m_arg)
+{
+ register struct radix_node *x;
+ register caddr_t v = v_arg, m = m_arg;
+
+ for (x = head; x->rn_bit >= 0;) {
+ if ((x->rn_bmask & m[x->rn_offset]) &&
+ (x->rn_bmask & v[x->rn_offset]))
+ x = x->rn_right;
+ else
+ x = x->rn_left;
+ }
+ return x;
+}
+
+int
+rn_refines(void *m_arg, void *n_arg)
+{
+ register caddr_t m = m_arg, n = n_arg;
+ register caddr_t lim, lim2 = lim = n + *(u_char *)n;
+ int longer = (*(u_char *)n++) - (int)(*(u_char *)m++);
+ int masks_are_equal = 1;
+
+ if (longer > 0)
+ lim -= longer;
+ while (n < lim) {
+ if (*n & ~(*m))
+ return 0;
+ if (*n++ != *m++)
+ masks_are_equal = 0;
+ }
+ while (n < lim2)
+ if (*n++)
+ return 0;
+ if (masks_are_equal && (longer < 0))
+ for (lim2 = m - longer; m < lim2; )
+ if (*m++)
+ return 1;
+ return (!masks_are_equal);
+}
+
+struct radix_node *
+rn_lookup(void *v_arg, void *m_arg, struct radix_node_head *head)
+{
+ register struct radix_node *x;
+ caddr_t netmask = 0;
+
+ if (m_arg) {
+ x = rn_addmask(m_arg, 1, head->rnh_treetop->rn_offset);
+ if (x == 0)
+ return (0);
+ netmask = x->rn_key;
+ }
+ x = rn_match(v_arg, head);
+ if (x && netmask) {
+ while (x && x->rn_mask != netmask)
+ x = x->rn_dupedkey;
+ }
+ return x;
+}
+
+static int
+rn_satisfies_leaf(char *trial, struct radix_node *leaf, int skip)
+{
+ register char *cp = trial, *cp2 = leaf->rn_key, *cp3 = leaf->rn_mask;
+ char *cplim;
+ int length = min(*(u_char *)cp, *(u_char *)cp2);
+
+ if (cp3 == 0)
+ cp3 = rn_ones;
+ else
+ length = min(length, *(u_char *)cp3);
+ cplim = cp + length; cp3 += skip; cp2 += skip;
+ for (cp += skip; cp < cplim; cp++, cp2++, cp3++)
+ if ((*cp ^ *cp2) & *cp3)
+ return 0;
+ return 1;
+}
+
+struct radix_node *
+rn_match(void *v_arg, struct radix_node_head *head)
+{
+ caddr_t v = v_arg;
+ register struct radix_node *t = head->rnh_treetop, *x;
+ register caddr_t cp = v, cp2;
+ caddr_t cplim;
+ struct radix_node *saved_t, *top = t;
+ int off = t->rn_offset, vlen = *(u_char *)cp, matched_off;
+ register int test, b, rn_bit;
+
+ /*
+ * Open code rn_search(v, top) to avoid overhead of extra
+ * subroutine call.
+ */
+ for (; t->rn_bit >= 0; ) {
+ if (t->rn_bmask & cp[t->rn_offset])
+ t = t->rn_right;
+ else
+ t = t->rn_left;
+ }
+ /*
+ * See if we match exactly as a host destination
+ * or at least learn how many bits match, for normal mask finesse.
+ *
+ * It doesn't hurt us to limit how many bytes to check
+ * to the length of the mask, since if it matches we had a genuine
+ * match and the leaf we have is the most specific one anyway;
+ * if it didn't match with a shorter length it would fail
+ * with a long one. This wins big for class B&C netmasks which
+ * are probably the most common case...
+ */
+ if (t->rn_mask)
+ vlen = *(u_char *)t->rn_mask;
+ cp += off; cp2 = t->rn_key + off; cplim = v + vlen;
+ for (; cp < cplim; cp++, cp2++)
+ if (*cp != *cp2)
+ goto on1;
+ /*
+ * This extra grot is in case we are explicitly asked
+ * to look up the default. Ugh!
+ *
+ * Never return the root node itself, it seems to cause a
+ * lot of confusion.
+ */
+ if (t->rn_flags & RNF_ROOT)
+ t = t->rn_dupedkey;
+ return t;
+on1:
+ test = (*cp ^ *cp2) & 0xff; /* find first bit that differs */
+ for (b = 7; (test >>= 1) > 0;)
+ b--;
+ matched_off = cp - v;
+ b += matched_off << 3;
+ rn_bit = -1 - b;
+ /*
+ * If there is a host route in a duped-key chain, it will be first.
+ */
+ if ((saved_t = t)->rn_mask == 0)
+ t = t->rn_dupedkey;
+ for (; t; t = t->rn_dupedkey)
+ /*
+ * Even if we don't match exactly as a host,
+ * we may match if the leaf we wound up at is
+ * a route to a net.
+ */
+ if (t->rn_flags & RNF_NORMAL) {
+ if (rn_bit <= t->rn_bit)
+ return t;
+ } else if (rn_satisfies_leaf(v, t, matched_off))
+ return t;
+ t = saved_t;
+ /* start searching up the tree */
+ do {
+ register struct radix_mask *m;
+ t = t->rn_parent;
+ m = t->rn_mklist;
+ if (m) {
+ /*
+ * If non-contiguous masks ever become important
+ * we can restore the masking and open coding of
+ * the search and satisfaction test and put the
+ * calculation of "off" back before the "do".
+ */
+ do {
+ if (m->rm_flags & RNF_NORMAL) {
+ if (rn_bit <= m->rm_bit)
+ return (m->rm_leaf);
+ } else {
+ off = min(t->rn_offset, matched_off);
+ x = rn_search_m(v, t, m->rm_mask);
+ while (x && x->rn_mask != m->rm_mask)
+ x = x->rn_dupedkey;
+ if (x && rn_satisfies_leaf(v, x, off))
+ return x;
+ }
+ m = m->rm_mklist;
+ } while (m);
+ }
+ } while (t != top);
+ return 0;
+}
+
+#ifdef RN_DEBUG
+int rn_nodenum;
+struct radix_node *rn_clist;
+int rn_saveinfo;
+int rn_debug = 1;
+#endif
+
+static struct radix_node *
+rn_newpair(void *v, int b, struct radix_node nodes[2])
+{
+ register struct radix_node *tt = nodes, *t = tt + 1;
+ t->rn_bit = b;
+ t->rn_bmask = 0x80 >> (b & 7);
+ t->rn_left = tt;
+ t->rn_offset = b >> 3;
+ tt->rn_bit = -1;
+ tt->rn_key = (caddr_t)v;
+ tt->rn_parent = t;
+ tt->rn_flags = t->rn_flags = RNF_ACTIVE;
+#ifdef RN_DEBUG
+ tt->rn_info = rn_nodenum++; t->rn_info = rn_nodenum++;
+ tt->rn_twin = t;
+ tt->rn_ybro = rn_clist;
+ rn_clist = tt;
+#endif
+ return t;
+}
+
+static struct radix_node *
+rn_insert(void *v_arg, struct radix_node_head *head, int *dupentry,
+ struct radix_node nodes[2])
+{
+ caddr_t v = v_arg;
+ struct radix_node *top = head->rnh_treetop;
+ int head_off = top->rn_offset, vlen = (int)*((u_char *)v);
+ register struct radix_node *t = rn_search(v_arg, top);
+ register caddr_t cp = v + head_off;
+ register int b;
+ struct radix_node *tt;
+ /*
+ * Find first bit at which v and t->rn_key differ
+ */
+ {
+ register caddr_t cp2 = t->rn_key + head_off;
+ register int cmp_res;
+ caddr_t cplim = v + vlen;
+
+ while (cp < cplim)
+ if (*cp2++ != *cp++)
+ goto on1;
+ *dupentry = 1;
+ return t;
+on1:
+ *dupentry = 0;
+ cmp_res = (cp[-1] ^ cp2[-1]) & 0xff;
+ for (b = (cp - v) << 3; cmp_res; b--)
+ cmp_res >>= 1;
+ }
+ {
+ register struct radix_node *p, *x = top;
+ cp = v;
+ do {
+ p = x;
+ if (cp[x->rn_offset] & x->rn_bmask)
+ x = x->rn_right;
+ else
+ x = x->rn_left;
+ } while (b > (unsigned) x->rn_bit);
+ /* x->rn_bit < b && x->rn_bit >= 0 */
+#ifdef RN_DEBUG
+ if (rn_debug)
+ log(LOG_DEBUG, "rn_insert: Going In:\n"), traverse(p);
+#endif
+ t = rn_newpair(v_arg, b, nodes);
+ tt = t->rn_left;
+ if ((cp[p->rn_offset] & p->rn_bmask) == 0)
+ p->rn_left = t;
+ else
+ p->rn_right = t;
+ x->rn_parent = t;
+ t->rn_parent = p; /* frees x, p as temp vars below */
+ if ((cp[t->rn_offset] & t->rn_bmask) == 0) {
+ t->rn_right = x;
+ } else {
+ t->rn_right = tt;
+ t->rn_left = x;
+ }
+#ifdef RN_DEBUG
+ if (rn_debug)
+ log(LOG_DEBUG, "rn_insert: Coming Out:\n"), traverse(p);
+#endif
+ }
+ return (tt);
+}
+
+struct radix_node *
+rn_addmask(void *n_arg, int search, int skip)
+{
+ caddr_t netmask = (caddr_t)n_arg;
+ register struct radix_node *x;
+ register caddr_t cp, cplim;
+ register int b = 0, mlen, j;
+ int maskduplicated, m0, isnormal;
+ struct radix_node *saved_x;
+ static int last_zeroed = 0;
+
+ if ((mlen = *(u_char *)netmask) > max_keylen)
+ mlen = max_keylen;
+ if (skip == 0)
+ skip = 1;
+ if (mlen <= skip)
+ return (mask_rnhead->rnh_nodes);
+ if (skip > 1)
+ Bcopy(rn_ones + 1, addmask_key + 1, skip - 1);
+ if ((m0 = mlen) > skip)
+ Bcopy(netmask + skip, addmask_key + skip, mlen - skip);
+ /*
+ * Trim trailing zeroes.
+ */
+ for (cp = addmask_key + mlen; (cp > addmask_key) && cp[-1] == 0;)
+ cp--;
+ mlen = cp - addmask_key;
+ if (mlen <= skip) {
+ if (m0 >= last_zeroed)
+ last_zeroed = mlen;
+ return (mask_rnhead->rnh_nodes);
+ }
+ if (m0 < last_zeroed)
+ Bzero(addmask_key + m0, last_zeroed - m0);
+ *addmask_key = last_zeroed = mlen;
+ x = rn_search(addmask_key, rn_masktop);
+ if (Bcmp(addmask_key, x->rn_key, mlen) != 0)
+ x = 0;
+ if (x || search)
+ return (x);
+ R_Malloc(x, struct radix_node *, max_keylen + 2 * sizeof (*x));
+ if ((saved_x = x) == 0)
+ return (0);
+ Bzero(x, max_keylen + 2 * sizeof (*x));
+ netmask = cp = (caddr_t)(x + 2);
+ Bcopy(addmask_key, cp, mlen);
+ x = rn_insert(cp, mask_rnhead, &maskduplicated, x);
+ if (maskduplicated) {
+ log(LOG_ERR, "rn_addmask: mask impossibly already in tree");
+ Free(saved_x);
+ return (x);
+ }
+ /*
+ * Calculate index of mask, and check for normalcy.
+ */
+ cplim = netmask + mlen; isnormal = 1;
+ for (cp = netmask + skip; (cp < cplim) && *(u_char *)cp == 0xff;)
+ cp++;
+ if (cp != cplim) {
+ for (j = 0x80; (j & *cp) != 0; j >>= 1)
+ b++;
+ if (*cp != normal_chars[b] || cp != (cplim - 1))
+ isnormal = 0;
+ }
+ b += (cp - netmask) << 3;
+ x->rn_bit = -1 - b;
+ if (isnormal)
+ x->rn_flags |= RNF_NORMAL;
+ return (x);
+}
+
+static int /* XXX: arbitrary ordering for non-contiguous masks */
+rn_lexobetter(void *m_arg, void *n_arg)
+{
+ register u_char *mp = m_arg, *np = n_arg, *lim;
+
+ if (*mp > *np)
+ return 1; /* not really, but need to check longer one first */
+ if (*mp == *np)
+ for (lim = mp + *mp; mp < lim;)
+ if (*mp++ > *np++)
+ return 1;
+ return 0;
+}
+
+static struct radix_mask *
+rn_new_radix_mask(struct radix_node *tt, struct radix_mask *next)
+{
+ register struct radix_mask *m;
+
+ MKGet(m);
+ if (m == 0) {
+ log(LOG_ERR, "Mask for route not entered\n");
+ return (0);
+ }
+ Bzero(m, sizeof *m);
+ m->rm_bit = tt->rn_bit;
+ m->rm_flags = tt->rn_flags;
+ if (tt->rn_flags & RNF_NORMAL)
+ m->rm_leaf = tt;
+ else
+ m->rm_mask = tt->rn_mask;
+ m->rm_mklist = next;
+ tt->rn_mklist = m;
+ return m;
+}
+
+struct radix_node *
+rn_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
+ struct radix_node treenodes[2])
+{
+ caddr_t v = (caddr_t)v_arg, netmask = (caddr_t)n_arg;
+ register struct radix_node *t, *x = 0, *tt;
+ struct radix_node *saved_tt, *top = head->rnh_treetop;
+ short b = 0, b_leaf = 0;
+ int keyduplicated;
+ caddr_t mmask;
+ struct radix_mask *m, **mp;
+
+ /*
+ * In dealing with non-contiguous masks, there may be
+ * many different routes which have the same mask.
+ * We will find it useful to have a unique pointer to
+ * the mask to speed avoiding duplicate references at
+ * nodes and possibly save time in calculating indices.
+ */
+ if (netmask) {
+ if ((x = rn_addmask(netmask, 0, top->rn_offset)) == 0)
+ return (0);
+ b_leaf = x->rn_bit;
+ b = -1 - x->rn_bit;
+ netmask = x->rn_key;
+ }
+ /*
+ * Deal with duplicated keys: attach node to previous instance
+ */
+ saved_tt = tt = rn_insert(v, head, &keyduplicated, treenodes);
+ if (keyduplicated) {
+ for (t = tt; tt; t = tt, tt = tt->rn_dupedkey) {
+ if (tt->rn_mask == netmask)
+ return (0);
+ if (netmask == 0 ||
+ (tt->rn_mask &&
+ ((b_leaf < tt->rn_bit) /* index(netmask) > node */
+ || rn_refines(netmask, tt->rn_mask)
+ || rn_lexobetter(netmask, tt->rn_mask))))
+ break;
+ }
+ /*
+ * If the mask is not duplicated, we wouldn't
+ * find it among possible duplicate key entries
+ * anyway, so the above test doesn't hurt.
+ *
+ * We sort the masks for a duplicated key the same way as
+ * in a masklist -- most specific to least specific.
+ * This may require the unfortunate nuisance of relocating
+ * the head of the list.
+ *
+ * We also reverse, or doubly link the list through the
+ * parent pointer.
+ */
+ if (tt == saved_tt) {
+ struct radix_node *xx = x;
+ /* link in at head of list */
+ (tt = treenodes)->rn_dupedkey = t;
+ tt->rn_flags = t->rn_flags;
+ tt->rn_parent = x = t->rn_parent;
+ t->rn_parent = tt; /* parent */
+ if (x->rn_left == t)
+ x->rn_left = tt;
+ else
+ x->rn_right = tt;
+ saved_tt = tt; x = xx;
+ } else {
+ (tt = treenodes)->rn_dupedkey = t->rn_dupedkey;
+ t->rn_dupedkey = tt;
+ tt->rn_parent = t; /* parent */
+ if (tt->rn_dupedkey) /* parent */
+ tt->rn_dupedkey->rn_parent = tt; /* parent */
+ }
+#ifdef RN_DEBUG
+ t=tt+1; tt->rn_info = rn_nodenum++; t->rn_info = rn_nodenum++;
+ tt->rn_twin = t; tt->rn_ybro = rn_clist; rn_clist = tt;
+#endif
+ tt->rn_key = (caddr_t) v;
+ tt->rn_bit = -1;
+ tt->rn_flags = RNF_ACTIVE;
+ }
+ /*
+ * Put mask in tree.
+ */
+ if (netmask) {
+ tt->rn_mask = netmask;
+ tt->rn_bit = x->rn_bit;
+ tt->rn_flags |= x->rn_flags & RNF_NORMAL;
+ }
+ t = saved_tt->rn_parent;
+ if (keyduplicated)
+ goto on2;
+ b_leaf = -1 - t->rn_bit;
+ if (t->rn_right == saved_tt)
+ x = t->rn_left;
+ else
+ x = t->rn_right;
+ /* Promote general routes from below */
+ if (x->rn_bit < 0) {
+ for (mp = &t->rn_mklist; x; x = x->rn_dupedkey)
+ if (x->rn_mask && (x->rn_bit >= b_leaf) && x->rn_mklist == 0) {
+ *mp = m = rn_new_radix_mask(x, 0);
+ if (m)
+ mp = &m->rm_mklist;
+ }
+ } else if (x->rn_mklist) {
+ /*
+ * Skip over masks whose index is > that of new node
+ */
+ for (mp = &x->rn_mklist; (m = *mp); mp = &m->rm_mklist)
+ if (m->rm_bit >= b_leaf)
+ break;
+ t->rn_mklist = m; *mp = 0;
+ }
+on2:
+ /* Add new route to highest possible ancestor's list */
+ if ((netmask == 0) || (b > t->rn_bit ))
+ return tt; /* can't lift at all */
+ b_leaf = tt->rn_bit;
+ do {
+ x = t;
+ t = t->rn_parent;
+ } while (b <= t->rn_bit && x != top);
+ /*
+ * Search through routes associated with node to
+ * insert new route according to index.
+ * Need same criteria as when sorting dupedkeys to avoid
+ * double loop on deletion.
+ */
+ for (mp = &x->rn_mklist; (m = *mp); mp = &m->rm_mklist) {
+ if (m->rm_bit < b_leaf)
+ continue;
+ if (m->rm_bit > b_leaf)
+ break;
+ if (m->rm_flags & RNF_NORMAL) {
+ mmask = m->rm_leaf->rn_mask;
+ if (tt->rn_flags & RNF_NORMAL) {
+ log(LOG_ERR,
+ "Non-unique normal route, mask not entered\n");
+ return tt;
+ }
+ } else
+ mmask = m->rm_mask;
+ if (mmask == netmask) {
+ m->rm_refs++;
+ tt->rn_mklist = m;
+ return tt;
+ }
+ if (rn_refines(netmask, mmask)
+ || rn_lexobetter(netmask, mmask))
+ break;
+ }
+ *mp = rn_new_radix_mask(tt, *mp);
+ return tt;
+}
+
+struct radix_node *
+rn_delete(void *v_arg, void *netmask_arg, struct radix_node_head *head)
+{
+ register struct radix_node *t, *p, *x, *tt;
+ struct radix_mask *m, *saved_m, **mp;
+ struct radix_node *dupedkey, *saved_tt, *top;
+ caddr_t v, netmask;
+ int b, head_off, vlen;
+
+ v = v_arg;
+ netmask = netmask_arg;
+ x = head->rnh_treetop;
+ tt = rn_search(v, x);
+ head_off = x->rn_offset;
+ vlen = *(u_char *)v;
+ saved_tt = tt;
+ top = x;
+ if (tt == 0 ||
+ Bcmp(v + head_off, tt->rn_key + head_off, vlen - head_off))
+ return (0);
+ /*
+ * Delete our route from mask lists.
+ */
+ if (netmask) {
+ if ((x = rn_addmask(netmask, 1, head_off)) == 0)
+ return (0);
+ netmask = x->rn_key;
+ while (tt->rn_mask != netmask)
+ if ((tt = tt->rn_dupedkey) == 0)
+ return (0);
+ }
+ if (tt->rn_mask == 0 || (saved_m = m = tt->rn_mklist) == 0)
+ goto on1;
+ if (tt->rn_flags & RNF_NORMAL) {
+ if (m->rm_leaf != tt || m->rm_refs > 0) {
+ log(LOG_ERR, "rn_delete: inconsistent annotation\n");
+ return 0; /* dangling ref could cause disaster */
+ }
+ } else {
+ if (m->rm_mask != tt->rn_mask) {
+ log(LOG_ERR, "rn_delete: inconsistent annotation\n");
+ goto on1;
+ }
+ if (--m->rm_refs >= 0)
+ goto on1;
+ }
+ b = -1 - tt->rn_bit;
+ t = saved_tt->rn_parent;
+ if (b > t->rn_bit)
+ goto on1; /* Wasn't lifted at all */
+ do {
+ x = t;
+ t = t->rn_parent;
+ } while (b <= t->rn_bit && x != top);
+ for (mp = &x->rn_mklist; (m = *mp); mp = &m->rm_mklist)
+ if (m == saved_m) {
+ *mp = m->rm_mklist;
+ MKFree(m);
+ break;
+ }
+ if (m == 0) {
+ log(LOG_ERR, "rn_delete: couldn't find our annotation\n");
+ if (tt->rn_flags & RNF_NORMAL)
+ return (0); /* Dangling ref to us */
+ }
+on1:
+ /*
+ * Eliminate us from tree
+ */
+ if (tt->rn_flags & RNF_ROOT)
+ return (0);
+#ifdef RN_DEBUG
+ /* Get us out of the creation list */
+ for (t = rn_clist; t && t->rn_ybro != tt; t = t->rn_ybro) {}
+ if (t) t->rn_ybro = tt->rn_ybro;
+#endif
+ t = tt->rn_parent;
+ dupedkey = saved_tt->rn_dupedkey;
+ if (dupedkey) {
+ /*
+ * Here, tt is the deletion target and
+ * saved_tt is the head of the dupekey chain.
+ */
+ if (tt == saved_tt) {
+ /* remove from head of chain */
+ x = dupedkey; x->rn_parent = t;
+ if (t->rn_left == tt)
+ t->rn_left = x;
+ else
+ t->rn_right = x;
+ } else {
+ /* find node in front of tt on the chain */
+ for (x = p = saved_tt; p && p->rn_dupedkey != tt;)
+ p = p->rn_dupedkey;
+ if (p) {
+ p->rn_dupedkey = tt->rn_dupedkey;
+ if (tt->rn_dupedkey) /* parent */
+ tt->rn_dupedkey->rn_parent = p;
+ /* parent */
+ } else log(LOG_ERR, "rn_delete: couldn't find us\n");
+ }
+ t = tt + 1;
+ if (t->rn_flags & RNF_ACTIVE) {
+#ifndef RN_DEBUG
+ *++x = *t;
+ p = t->rn_parent;
+#else
+ b = t->rn_info;
+ *++x = *t;
+ t->rn_info = b;
+ p = t->rn_parent;
+#endif
+ if (p->rn_left == t)
+ p->rn_left = x;
+ else
+ p->rn_right = x;
+ x->rn_left->rn_parent = x;
+ x->rn_right->rn_parent = x;
+ }
+ goto out;
+ }
+ if (t->rn_left == tt)
+ x = t->rn_right;
+ else
+ x = t->rn_left;
+ p = t->rn_parent;
+ if (p->rn_right == t)
+ p->rn_right = x;
+ else
+ p->rn_left = x;
+ x->rn_parent = p;
+ /*
+ * Demote routes attached to us.
+ */
+ if (t->rn_mklist) {
+ if (x->rn_bit >= 0) {
+ for (mp = &x->rn_mklist; (m = *mp);)
+ mp = &m->rm_mklist;
+ *mp = t->rn_mklist;
+ } else {
+ /* If there are any key,mask pairs in a sibling
+ duped-key chain, some subset will appear sorted
+ in the same order attached to our mklist */
+ for (m = t->rn_mklist; m && x; x = x->rn_dupedkey)
+ if (m == x->rn_mklist) {
+ struct radix_mask *mm = m->rm_mklist;
+ x->rn_mklist = 0;
+ if (--(m->rm_refs) < 0)
+ MKFree(m);
+ m = mm;
+ }
+ if (m)
+ log(LOG_ERR,
+ "rn_delete: Orphaned Mask %p at %p\n",
+ (void *)m, (void *)x);
+ }
+ }
+ /*
+ * We may be holding an active internal node in the tree.
+ */
+ x = tt + 1;
+ if (t != x) {
+#ifndef RN_DEBUG
+ *t = *x;
+#else
+ b = t->rn_info;
+ *t = *x;
+ t->rn_info = b;
+#endif
+ t->rn_left->rn_parent = t;
+ t->rn_right->rn_parent = t;
+ p = x->rn_parent;
+ if (p->rn_left == x)
+ p->rn_left = t;
+ else
+ p->rn_right = t;
+ }
+out:
+ tt->rn_flags &= ~RNF_ACTIVE;
+ tt[1].rn_flags &= ~RNF_ACTIVE;
+ return (tt);
+}
+
+/*
+ * This is the same as rn_walktree() except for the parameters and the
+ * exit.
+ */
+static int
+rn_walktree_from(struct radix_node_head *h, void *a, void *m,
+ walktree_f_t *f, void *w)
+{
+ int error;
+ struct radix_node *base, *next;
+ u_char *xa = (u_char *)a;
+ u_char *xm = (u_char *)m;
+ register struct radix_node *rn, *last = 0 /* shut up gcc */;
+ int stopping = 0;
+ int lastb;
+
+ /*
+ * rn_search_m is sort-of-open-coded here.
+ */
+ /* printf("about to search\n"); */
+ for (rn = h->rnh_treetop; rn->rn_bit >= 0; ) {
+ last = rn;
+ /* printf("rn_bit %d, rn_bmask %x, xm[rn_offset] %x\n",
+ rn->rn_bit, rn->rn_bmask, xm[rn->rn_offset]); */
+ if (!(rn->rn_bmask & xm[rn->rn_offset])) {
+ break;
+ }
+ if (rn->rn_bmask & xa[rn->rn_offset]) {
+ rn = rn->rn_right;
+ } else {
+ rn = rn->rn_left;
+ }
+ }
+ /* printf("done searching\n"); */
+
+ /*
+ * Two cases: either we stepped off the end of our mask,
+ * in which case last == rn, or we reached a leaf, in which
+ * case we want to start from the last node we looked at.
+ * Either way, last is the node we want to start from.
+ */
+ rn = last;
+ lastb = rn->rn_bit;
+
+ /* printf("rn %p, lastb %d\n", rn, lastb);*/
+
+ /*
+ * This gets complicated because we may delete the node
+ * while applying the function f to it, so we need to calculate
+ * the successor node in advance.
+ */
+ while (rn->rn_bit >= 0)
+ rn = rn->rn_left;
+
+ while (!stopping) {
+ /* printf("node %p (%d)\n", rn, rn->rn_bit); */
+ base = rn;
+ /* If at right child go back up, otherwise, go right */
+ while (rn->rn_parent->rn_right == rn
+ && !(rn->rn_flags & RNF_ROOT)) {
+ rn = rn->rn_parent;
+
+ /* if went up beyond last, stop */
+ if (rn->rn_bit < lastb) {
+ stopping = 1;
+ /* printf("up too far\n"); */
+ }
+ }
+
+ /* Find the next *leaf* since next node might vanish, too */
+ for (rn = rn->rn_parent->rn_right; rn->rn_bit >= 0;)
+ rn = rn->rn_left;
+ next = rn;
+ /* Process leaves */
+ while ((rn = base) != 0) {
+ base = rn->rn_dupedkey;
+ /* printf("leaf %p\n", rn); */
+ if (!(rn->rn_flags & RNF_ROOT)
+ && (error = (*f)(rn, w)))
+ return (error);
+ }
+ rn = next;
+
+ if (rn->rn_flags & RNF_ROOT) {
+ /* printf("root, stopping"); */
+ stopping = 1;
+ }
+
+ }
+ return 0;
+}
+
+static int
+rn_walktree(struct radix_node_head *h, walktree_f_t *f, void *w)
+{
+ int error;
+ struct radix_node *base, *next;
+ register struct radix_node *rn = h->rnh_treetop;
+ /*
+ * This gets complicated because we may delete the node
+ * while applying the function f to it, so we need to calculate
+ * the successor node in advance.
+ */
+ /* First time through node, go left */
+ while (rn->rn_bit >= 0)
+ rn = rn->rn_left;
+ for (;;) {
+ base = rn;
+ /* If at right child go back up, otherwise, go right */
+ while (rn->rn_parent->rn_right == rn
+ && (rn->rn_flags & RNF_ROOT) == 0)
+ rn = rn->rn_parent;
+ /* Find the next *leaf* since next node might vanish, too */
+ for (rn = rn->rn_parent->rn_right; rn->rn_bit >= 0;)
+ rn = rn->rn_left;
+ next = rn;
+ /* Process leaves */
+ while ((rn = base)) {
+ base = rn->rn_dupedkey;
+ if (!(rn->rn_flags & RNF_ROOT)
+ && (error = (*f)(rn, w)))
+ return (error);
+ }
+ rn = next;
+ if (rn->rn_flags & RNF_ROOT)
+ return (0);
+ }
+ /* NOTREACHED */
+}
+
+int
+rn_inithead(void **head, int off)
+{
+ register struct radix_node_head *rnh;
+ register struct radix_node *t, *tt, *ttt;
+ if (*head)
+ return (1);
+ R_Malloc(rnh, struct radix_node_head *, sizeof (*rnh));
+ if (rnh == 0)
+ return (0);
+ Bzero(rnh, sizeof (*rnh));
+ *head = rnh;
+ t = rn_newpair(rn_zeros, off, rnh->rnh_nodes);
+ ttt = rnh->rnh_nodes + 2;
+ t->rn_right = ttt;
+ t->rn_parent = t;
+ tt = t->rn_left;
+ tt->rn_flags = t->rn_flags = RNF_ROOT | RNF_ACTIVE;
+ tt->rn_bit = -1 - off;
+ *ttt = *tt;
+ ttt->rn_key = rn_ones;
+ rnh->rnh_addaddr = rn_addroute;
+ rnh->rnh_deladdr = rn_delete;
+ rnh->rnh_matchaddr = rn_match;
+ rnh->rnh_lookup = rn_lookup;
+ rnh->rnh_walktree = rn_walktree;
+ rnh->rnh_walktree_from = rn_walktree_from;
+ rnh->rnh_treetop = t;
+ return (1);
+}
+
+void
+rn_init(void)
+{
+ char *cp, *cplim;
+#ifdef _KERNEL
+ struct domain *dom;
+
+ for (dom = domains; dom; dom = dom->dom_next)
+ if (dom->dom_maxrtkey > max_keylen)
+ max_keylen = dom->dom_maxrtkey;
+#endif
+ if (max_keylen == 0) {
+ log(LOG_ERR,
+ "rn_init: radix functions require max_keylen be set\n");
+ return;
+ }
+ R_Malloc(rn_zeros, char *, 3 * max_keylen);
+ if (rn_zeros == NULL)
+ panic("rn_init");
+ Bzero(rn_zeros, 3 * max_keylen);
+ rn_ones = cp = rn_zeros + max_keylen;
+ addmask_key = cplim = rn_ones + max_keylen;
+ while (cp < cplim)
+ *cp++ = -1;
+ if (rn_inithead((void **)(void*)&mask_rnhead, 0) == 0)
+ panic("rn_init 2");
+}
diff --git a/cpukit/libnetworking/net/radix.h b/cpukit/libnetworking/net/radix.h
new file mode 100644
index 0000000000..cf132a4ab9
--- /dev/null
+++ b/cpukit/libnetworking/net/radix.h
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 1988, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)radix.h 8.2 (Berkeley) 10/31/94
+ * $FreeBSD: src/sys/net/radix.h,v 1.25 2004/04/18 11:48:35 luigi Exp $
+ */
+
+#ifndef _RADIX_H_
+#define _RADIX_H_
+
+/*
+ * Radix search tree node layout.
+ */
+
+struct radix_node {
+ struct radix_mask *rn_mklist; /* list of masks contained in subtree */
+ struct radix_node *rn_parent; /* parent */
+ short rn_bit; /* bit offset; -1-index(netmask) */
+ char rn_bmask; /* node: mask for bit test*/
+ u_char rn_flags; /* enumerated next */
+#define RNF_NORMAL 1 /* leaf contains normal route */
+#define RNF_ROOT 2 /* leaf is root leaf for tree */
+#define RNF_ACTIVE 4 /* This node is alive (for rtfree) */
+ union {
+ struct { /* leaf only data: */
+ caddr_t rn_Key; /* object of search */
+ caddr_t rn_Mask; /* netmask, if present */
+ struct radix_node *rn_Dupedkey;
+ } rn_leaf;
+ struct { /* node only data: */
+ int rn_Off; /* where to start compare */
+ struct radix_node *rn_L;/* progeny */
+ struct radix_node *rn_R;/* progeny */
+ } rn_node;
+ } rn_u;
+#ifdef RN_DEBUG
+ int rn_info;
+ struct radix_node *rn_twin;
+ struct radix_node *rn_ybro;
+#endif
+};
+
+#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
+#define rn_key rn_u.rn_leaf.rn_Key
+#define rn_mask rn_u.rn_leaf.rn_Mask
+#define rn_offset rn_u.rn_node.rn_Off
+#define rn_left rn_u.rn_node.rn_L
+#define rn_right rn_u.rn_node.rn_R
+
+/*
+ * Annotations to tree concerning potential routes applying to subtrees.
+ */
+
+struct radix_mask {
+ short rm_bit; /* bit offset; -1-index(netmask) */
+ char rm_unused; /* cf. rn_bmask */
+ u_char rm_flags; /* cf. rn_flags */
+ struct radix_mask *rm_mklist; /* more masks to try */
+ union {
+ caddr_t rmu_mask; /* the mask */
+ struct radix_node *rmu_leaf; /* for normal routes */
+ } rm_rmu;
+ int rm_refs; /* # of references to this struct */
+};
+
+#define rm_mask rm_rmu.rmu_mask
+#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
+
+#define MKGet(m) {\
+ if (rn_mkfreelist) {\
+ m = rn_mkfreelist; \
+ rn_mkfreelist = (m)->rm_mklist; \
+ } else \
+ R_Malloc(m, struct radix_mask *, sizeof (*(m))); }\
+
+#define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);}
+
+typedef int walktree_f_t(struct radix_node *, void *);
+
+struct radix_node_head {
+ struct radix_node *rnh_treetop;
+ int rnh_addrsize; /* permit, but not require fixed keys */
+ int rnh_pktsize; /* permit, but not require fixed keys */
+ struct radix_node *(*rnh_addaddr) /* add based on sockaddr */
+ (void *v, void *mask,
+ struct radix_node_head *head, struct radix_node nodes[]);
+ struct radix_node *(*rnh_addpkt) /* add based on packet hdr */
+ (void *v, void *mask,
+ struct radix_node_head *head, struct radix_node nodes[]);
+ struct radix_node *(*rnh_deladdr) /* remove based on sockaddr */
+ (void *v, void *mask, struct radix_node_head *head);
+ struct radix_node *(*rnh_delpkt) /* remove based on packet hdr */
+ (void *v, void *mask, struct radix_node_head *head);
+ struct radix_node *(*rnh_matchaddr) /* locate based on sockaddr */
+ (void *v, struct radix_node_head *head);
+ struct radix_node *(*rnh_lookup) /* locate based on sockaddr */
+ (void *v, void *mask, struct radix_node_head *head);
+ struct radix_node *(*rnh_matchpkt) /* locate based on packet hdr */
+ (void *v, struct radix_node_head *head);
+ int (*rnh_walktree) /* traverse tree */
+ (struct radix_node_head *head, walktree_f_t *f, void *w);
+ int (*rnh_walktree_from) /* traverse tree below a */
+ (struct radix_node_head *head, void *a, void *m,
+ walktree_f_t *f, void *w);
+ void (*rnh_close) /* do something when the last ref drops */
+ (struct radix_node *rn, struct radix_node_head *head);
+ struct radix_node rnh_nodes[3]; /* empty tree for common case */
+};
+
+#ifndef _KERNEL
+#define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n))
+#define Bcopy(a, b, n) bcopy(((char *)(a)), ((char *)(b)), (unsigned)(n))
+#define Bzero(p, n) bzero((char *)(p), (int)(n));
+#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
+#define R_Zalloc(p, t, n) (p = (t) calloc(1,(unsigned int)(n)))
+#define Free(p) free((char *)p);
+#else
+#define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
+#define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
+#define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n));
+#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_DONTWAIT))
+#define Free(p) free((caddr_t)p, M_RTABLE);
+#endif /*_KERNEL*/
+
+void rn_init(void);
+int rn_inithead(void **, int);
+int rn_refines(void *, void *);
+struct radix_node
+ *rn_addmask(void *, int, int),
+ *rn_addroute (void *, void *, struct radix_node_head *,
+ struct radix_node [2]),
+ *rn_delete(void *, void *, struct radix_node_head *),
+ *rn_lookup (void *v_arg, void *m_arg,
+ struct radix_node_head *head),
+ *rn_match(void *, struct radix_node_head *);
+
+#endif /* _RADIX_H_ */
diff --git a/cpukit/libnetworking/net/raw_cb.c b/cpukit/libnetworking/net/raw_cb.c
new file mode 100644
index 0000000000..e3b8b3c4d8
--- /dev/null
+++ b/cpukit/libnetworking/net/raw_cb.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)raw_cb.c 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/raw_cb.c,v 1.34 2006/06/02 08:27:15 rwatson Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <errno.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <net/raw_cb.h>
+#include <netinet/in.h>
+
+#ifdef __rtems__
+#define mtx_lock(x) /* UNUSED */
+#define mtx_unlock(x) /* UNUSED */
+#define KASSERT(x,y) /* UNUSED */
+#endif
+
+/*
+ * Routines to manage the raw protocol control blocks.
+ *
+ * TODO:
+ * hash lookups by protocol family/protocol + address family
+ * take care of unique address problems per AF?
+ * redo address binding to allow wildcards
+ */
+
+struct rawcb_list_head rawcb_list;
+static u_long raw_sendspace = RAWSNDQ;
+static u_long raw_recvspace = RAWRCVQ;
+
+/*
+ * Allocate a control block and a nominal amount
+ * of buffer space for the socket.
+ */
+int
+raw_attach(struct socket *so, int proto)
+{
+ register struct rawcb *rp = sotorawcb(so);
+ int error;
+
+ /*
+ * It is assumed that raw_attach is called
+ * after space has been allocated for the
+ * rawcb.
+ */
+ if (rp == 0)
+ return (ENOBUFS);
+ error = soreserve(so, raw_sendspace, raw_recvspace);
+ if (error)
+ return (error);
+ rp->rcb_socket = so;
+ rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
+ rp->rcb_proto.sp_protocol = proto;
+ mtx_lock(&rawcb_mtx);
+ LIST_INSERT_HEAD(&rawcb_list, rp, list);
+ mtx_unlock(&rawcb_mtx);
+ return (0);
+}
+
+/*
+ * Detach the raw connection block and discard
+ * socket resources.
+ */
+void
+raw_detach(struct rawcb *rp)
+{
+ struct socket *so = rp->rcb_socket;
+
+ KASSERT(so->so_pcb == rp, ("raw_detach: so_pcb != rp"));
+
+ so->so_pcb = NULL;
+ mtx_lock(&rawcb_mtx);
+ LIST_REMOVE(rp, list);
+ mtx_unlock(&rawcb_mtx);
+#ifdef notdef
+ if (rp->rcb_laddr)
+ m_freem(dtom(rp->rcb_laddr));
+ rp->rcb_laddr = 0;
+#endif
+ free((caddr_t)(rp), M_PCB);
+}
+
+/*
+ * Disconnect raw socket.
+ */
+void
+raw_disconnect(struct rawcb *rp)
+{
+
+#ifdef notdef
+ if (rp->rcb_faddr)
+ m_freem(dtom(rp->rcb_faddr));
+ rp->rcb_faddr = 0;
+#endif
+}
+
+#ifdef notdef
+int
+raw_bind(struct socket *so, struct mbuf *nam)
+{
+ struct sockaddr *addr = mtod(nam, struct sockaddr *);
+ register struct rawcb *rp;
+
+ if (ifnet == 0)
+ return (EADDRNOTAVAIL);
+ rp = sotorawcb(so);
+ nam = m_copym(nam, 0, M_COPYALL, M_TRYWAIT);
+ rp->rcb_laddr = mtod(nam, struct sockaddr *);
+ return (0);
+}
+#endif
diff --git a/cpukit/libnetworking/net/raw_cb.h b/cpukit/libnetworking/net/raw_cb.h
new file mode 100644
index 0000000000..02881e32b2
--- /dev/null
+++ b/cpukit/libnetworking/net/raw_cb.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)raw_cb.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/raw_cb.h,v 1.19 2005/01/07 01:45:35 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_RAW_CB_H_
+#define _NET_RAW_CB_H_
+
+#include <sys/queue.h>
+
+/*
+ * Raw protocol interface control block. Used
+ * to tie a socket to the generic raw interface.
+ */
+struct rawcb {
+ LIST_ENTRY(rawcb) list;
+ struct socket *rcb_socket; /* back pointer to socket */
+ struct sockaddr *rcb_faddr; /* destination address */
+ struct sockaddr *rcb_laddr; /* socket's address */
+ struct sockproto rcb_proto; /* protocol family, protocol */
+};
+
+#define sotorawcb(so) ((struct rawcb *)(so)->so_pcb)
+
+/*
+ * Nominal space allocated to a raw socket.
+ */
+#define RAWSNDQ 8192
+#define RAWRCVQ 8192
+
+#ifdef _KERNEL
+extern LIST_HEAD(rawcb_list_head, rawcb) rawcb_list;
+
+int raw_attach(struct socket *, int);
+void raw_ctlinput(int, struct sockaddr *, void *);
+void raw_detach(struct rawcb *);
+void raw_disconnect(struct rawcb *);
+void raw_init(void);
+void raw_input(struct mbuf *,
+ struct sockproto *, struct sockaddr *, struct sockaddr *);
+int raw_usrreq(struct socket *,
+ int, struct mbuf *, struct mbuf *, struct mbuf *);
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/net/raw_usrreq.c b/cpukit/libnetworking/net/raw_usrreq.c
new file mode 100644
index 0000000000..0b73cffa7a
--- /dev/null
+++ b/cpukit/libnetworking/net/raw_usrreq.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)raw_usrreq.c 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/raw_usrreq.c,v 1.44 2006/11/06 13:42:02 rwatson Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <errno.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <net/netisr.h>
+#include <net/raw_cb.h>
+
+/*
+ * Initialize raw connection block q.
+ */
+void
+raw_init(void)
+{
+
+ LIST_INIT(&rawcb_list);
+}
+
+
+/*
+ * Raw protocol input routine. Find the socket
+ * associated with the packet(s) and move them over. If
+ * nothing exists for this packet, drop it.
+ */
+/*
+ * Raw protocol interface.
+ */
+void
+raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src,
+ struct sockaddr *dst)
+{
+ register struct rawcb *rp;
+ register struct mbuf *m = m0;
+ struct socket *last;
+
+ last = 0;
+ LIST_FOREACH(rp, &rawcb_list, list) {
+ if (rp->rcb_proto.sp_family != proto->sp_family)
+ continue;
+ if (rp->rcb_proto.sp_protocol &&
+ rp->rcb_proto.sp_protocol != proto->sp_protocol)
+ continue;
+ /*
+ * We assume the lower level routines have
+ * placed the address in a canonical format
+ * suitable for a structure comparison.
+ *
+ * Note that if the lengths are not the same
+ * the comparison will fail at the first byte.
+ */
+#define equal(a1, a2) \
+ (bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
+ if (rp->rcb_laddr && !equal(rp->rcb_laddr, dst))
+ continue;
+ if (rp->rcb_faddr && !equal(rp->rcb_faddr, src))
+ continue;
+ if (last) {
+ struct mbuf *n;
+ n = m_copy(m, 0, (int)M_COPYALL);
+ if (n) {
+ if (sbappendaddr(&last->so_rcv, src,
+ n, (struct mbuf *)0) == 0)
+ /* should notify about lost packet */
+ m_freem(n);
+ else {
+ sorwakeup(last);
+ }
+ }
+ }
+ last = rp->rcb_socket;
+ }
+ if (last) {
+ if (sbappendaddr(&last->so_rcv, src,
+ m, (struct mbuf *)0) == 0)
+ m_freem(m);
+ else {
+ sorwakeup(last);
+ }
+ } else
+ m_freem(m);
+}
+
+void
+raw_ctlinput(int cmd, struct sockaddr *arg, void *dummy)
+{
+
+ if (cmd < 0 || cmd > PRC_NCMDS)
+ return;
+ /* INCOMPLETE */
+}
+
+int
+raw_usrreq( struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
+ struct mbuf *control)
+{
+ register struct rawcb *rp = sotorawcb(so);
+ register int error = 0;
+ int len;
+
+ if (req == PRU_CONTROL)
+ return (EOPNOTSUPP);
+ if (control && control->m_len) {
+ error = EOPNOTSUPP;
+ goto release;
+ }
+ if (rp == 0) {
+ error = EINVAL;
+ goto release;
+ }
+ switch (req) {
+
+ /*
+ * Allocate a raw control block and fill in the
+ * necessary info to allow packets to be routed to
+ * the appropriate raw interface routine.
+ */
+ case PRU_ATTACH:
+ if ((so->so_state & SS_PRIV) == 0) {
+ error = EACCES;
+ break;
+ }
+ error = raw_attach(so, (intptr_t)nam);
+ break;
+
+ /*
+ * Destroy state just before socket deallocation.
+ * Flush data or not depending on the options.
+ */
+ case PRU_DETACH:
+ if (rp == 0) {
+ error = ENOTCONN;
+ break;
+ }
+ raw_detach(rp);
+ break;
+
+ /*
+ * If a socket isn't bound to a single address,
+ * the raw input routine will hand it anything
+ * within that protocol family (assuming there's
+ * nothing else around it should go to).
+ */
+ case PRU_CONNECT:
+ error = EINVAL;
+#if 0
+ if (rp->rcb_faddr) {
+ error = EISCONN;
+ break;
+ }
+ nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
+ rp->rcb_faddr = mtod(nam, struct sockaddr *);
+ soisconnected(so);
+#endif
+ break;
+
+ case PRU_BIND:
+ error = EINVAL;
+#if 0
+ if (rp->rcb_laddr) {
+ error = EINVAL; /* XXX */
+ break;
+ }
+ error = raw_bind(so, nam);
+#endif
+ break;
+
+ case PRU_CONNECT2:
+ error = EOPNOTSUPP;
+ goto release;
+
+ case PRU_DISCONNECT:
+ if (rp->rcb_faddr == 0) {
+ error = ENOTCONN;
+ break;
+ }
+ raw_disconnect(rp);
+ soisdisconnected(so);
+ break;
+
+ /*
+ * Mark the connection as being incapable of further input.
+ */
+ case PRU_SHUTDOWN:
+ socantsendmore(so);
+ break;
+
+ /*
+ * Ship a packet out. The appropriate raw output
+ * routine handles any massaging necessary.
+ */
+ case PRU_SEND:
+ if (nam) {
+ if (rp->rcb_faddr) {
+ error = EISCONN;
+ break;
+ }
+ rp->rcb_faddr = mtod(nam, struct sockaddr *);
+ } else if (rp->rcb_faddr == 0) {
+ error = ENOTCONN;
+ break;
+ }
+ error = (*so->so_proto->pr_output)(m, so);
+ m = NULL;
+ if (nam)
+ rp->rcb_faddr = 0;
+ break;
+
+ case PRU_ABORT:
+ raw_disconnect(rp);
+ sofree(so);
+ soisdisconnected(so);
+ break;
+
+ case PRU_SENSE:
+ /*
+ * stat: don't bother with a blocksize.
+ */
+ return (0);
+
+ /*
+ * Not supported.
+ */
+ case PRU_RCVOOB:
+ case PRU_RCVD:
+ return(EOPNOTSUPP);
+
+ case PRU_LISTEN:
+ case PRU_ACCEPT:
+ case PRU_SENDOOB:
+ error = EOPNOTSUPP;
+ break;
+
+ case PRU_SOCKADDR:
+ if (rp->rcb_laddr == 0) {
+ error = EINVAL;
+ break;
+ }
+ len = rp->rcb_laddr->sa_len;
+ bcopy((caddr_t)rp->rcb_laddr, mtod(nam, caddr_t), (unsigned)len);
+ nam->m_len = len;
+ break;
+
+ case PRU_PEERADDR:
+ if (rp->rcb_faddr == 0) {
+ error = ENOTCONN;
+ break;
+ }
+ len = rp->rcb_faddr->sa_len;
+ bcopy((caddr_t)rp->rcb_faddr, mtod(nam, caddr_t), (unsigned)len);
+ nam->m_len = len;
+ break;
+
+ default:
+ panic("raw_usrreq");
+ }
+release:
+ if (m != NULL)
+ m_freem(m);
+ return (error);
+}
diff --git a/cpukit/libnetworking/net/route.c b/cpukit/libnetworking/net/route.c
new file mode 100644
index 0000000000..52ec7354bc
--- /dev/null
+++ b/cpukit/libnetworking/net/route.c
@@ -0,0 +1,947 @@
+/*
+ * Copyright (c) 1980, 1986, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)route.c 8.2 (Berkeley) 11/15/93
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_mrouting.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <net/raw_cb.h>
+
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_mroute.h>
+
+#define SA(p) ((struct sockaddr *)(p))
+
+struct route_cb route_cb;
+static struct rtstat rtstat;
+struct radix_node_head *rt_tables[AF_MAX+1];
+
+static int rttrash; /* routes not in table but not freed */
+
+static void rt_maskedcopy(struct sockaddr *,
+ struct sockaddr *, struct sockaddr *);
+static void rtable_init(struct radix_node_head **);
+
+/* compare two sockaddr structures */
+#define sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0)
+
+static void
+rtable_init(struct radix_node_head **table)
+{
+ struct domain *dom;
+ for (dom = domains; dom; dom = dom->dom_next)
+ if (dom->dom_rtattach)
+ dom->dom_rtattach((void *)&table[dom->dom_family],
+ dom->dom_rtoffset);
+}
+
+void
+route_init(void)
+{
+ rn_init(); /* initialize all zeroes, all ones, mask table */
+ rtable_init(rt_tables);
+}
+
+/*
+ * Packet routing routines.
+ */
+void
+rtalloc(struct route *ro)
+{
+ if (ro->ro_rt && ro->ro_rt->rt_ifp && (ro->ro_rt->rt_flags & RTF_UP))
+ return; /* XXX */
+ ro->ro_rt = rtalloc1(&ro->ro_dst, 1, 0UL);
+}
+
+void
+rtalloc_ign(struct route *ro, u_long ignore)
+{
+ if (ro->ro_rt && ro->ro_rt->rt_ifp && (ro->ro_rt->rt_flags & RTF_UP))
+ return; /* XXX */
+ ro->ro_rt = rtalloc1(&ro->ro_dst, 1, ignore);
+}
+
+/*
+ * Look up the route that matches the address given
+ * Or, at least try.. Create a cloned route if needed.
+ */
+struct rtentry *
+rtalloc1(struct sockaddr *dst, int report, u_long ignflags)
+{
+ struct radix_node_head *rnh = rt_tables[dst->sa_family];
+ struct rtentry *rt;
+ struct radix_node *rn;
+ struct rtentry *newrt;
+ struct rt_addrinfo info;
+ u_long nflags;
+ int s = splnet();
+ int err = 0, msgtype = RTM_MISS;
+
+ newrt = NULL;
+ /*
+ * Look up the address in the table for that Address Family
+ */
+ if (rnh && (rn = rnh->rnh_matchaddr((caddr_t)dst, rnh)) &&
+ ((rn->rn_flags & RNF_ROOT) == 0)) {
+ /*
+ * If we find it and it's not the root node, then
+ * get a refernce on the rtentry associated.
+ */
+ newrt = rt = (struct rtentry *)rn;
+ nflags = rt->rt_flags & ~ignflags;
+ if (report && (nflags & (RTF_CLONING | RTF_PRCLONING))) {
+ /*
+ * We are apparently adding (report = 0 in delete).
+ * If it requires that it be cloned, do so.
+ * (This implies it wasn't a HOST route.)
+ */
+ err = rtrequest(RTM_RESOLVE, dst, SA(0),
+ SA(0), 0, &newrt);
+ if (err) {
+ /*
+ * If the cloning didn't succeed, maybe
+ * what we have will do. Return that.
+ */
+ newrt = rt;
+ rt->rt_refcnt++;
+ goto miss;
+ }
+ if ((rt = newrt) && (rt->rt_flags & RTF_XRESOLVE)) {
+ /*
+ * If the new route specifies it be
+ * externally resolved, then go do that.
+ */
+ msgtype = RTM_RESOLVE;
+ goto miss;
+ }
+ } else
+ rt->rt_refcnt++;
+ } else {
+ /*
+ * Either we hit the root or couldn't find any match,
+ * Which basically means
+ * "caint get there frm here"
+ */
+ rtstat.rts_unreach++;
+ miss: if (report) {
+ /*
+ * If required, report the failure to the supervising
+ * Authorities.
+ * For a delete, this is not an error. (report == 0)
+ */
+ bzero(&info, sizeof(info));
+ info.rti_info[RTAX_DST] = dst;
+ rt_missmsg(msgtype, &info, 0, err);
+ }
+ }
+ splx(s);
+ return (newrt);
+}
+
+/*
+ * Remove a reference count from an rtentry.
+ * If the count gets low enough, take it out of the routing table
+ */
+void
+rtfree(struct rtentry *rt)
+{
+ register struct radix_node_head *rnh =
+ rt_tables[rt_key(rt)->sa_family];
+ register struct ifaddr *ifa;
+
+ if (rt == 0 || rnh == 0)
+ panic("rtfree");
+ rt->rt_refcnt--;
+ if(rnh->rnh_close && rt->rt_refcnt == 0) {
+ rnh->rnh_close((struct radix_node *)rt, rnh);
+ }
+ if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_UP) == 0) {
+ if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT))
+ panic ("rtfree 2");
+ rttrash--;
+ if (rt->rt_refcnt < 0) {
+ printf("rtfree: %p not freed (neg refs)\n", rt);
+ return;
+ }
+ ifa = rt->rt_ifa;
+ IFAFREE(ifa);
+ if (rt->rt_parent) {
+ RTFREE(rt->rt_parent);
+ }
+ Free(rt_key(rt));
+ Free(rt);
+ }
+}
+
+void
+ifafree(struct ifaddr *ifa)
+{
+ if (ifa == NULL)
+ panic("ifafree");
+ if (ifa->ifa_refcnt == 0)
+ free(ifa, M_IFADDR);
+ else
+ ifa->ifa_refcnt--;
+}
+
+/*
+ * Force a routing table entry to the specified
+ * destination to go through the given gateway.
+ * Normally called as a result of a routing redirect
+ * message from the network layer.
+ *
+ * N.B.: must be called at splnet
+ *
+ */
+void
+rtredirect(struct sockaddr *dst, struct sockaddr *gateway,
+ struct sockaddr *netmask, int flags, struct sockaddr *src,
+ struct rtentry **rtp)
+{
+ struct rtentry *rt;
+ int error = 0;
+ short *stat = NULL;
+ struct rt_addrinfo info;
+ struct ifaddr *ifa;
+
+ /* verify the gateway is directly reachable */
+ if ((ifa = ifa_ifwithnet(gateway)) == NULL) {
+ error = ENETUNREACH;
+ goto out;
+ }
+ rt = rtalloc1(dst, 0, 0UL);
+ /*
+ * If the redirect isn't from our current router for this dst,
+ * it's either old or wrong. If it redirects us to ourselves,
+ * we have a routing loop, perhaps as a result of an interface
+ * going down recently.
+ */
+#define equal(a1, a2) (bcmp((caddr_t)(a1), (caddr_t)(a2), (a1)->sa_len) == 0)
+ if (!(flags & RTF_DONE) && rt &&
+ (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
+ error = EINVAL;
+ else if (ifa_ifwithaddr(gateway))
+ error = EHOSTUNREACH;
+ if (error)
+ goto done;
+ /*
+ * Create a new entry if we just got back a wildcard entry
+ * or the the lookup failed. This is necessary for hosts
+ * which use routing redirects generated by smart gateways
+ * to dynamically build the routing tables.
+ */
+ if ((rt == 0) || (rt_mask(rt) && rt_mask(rt)->sa_len < 2))
+ goto create;
+ /*
+ * Don't listen to the redirect if it's
+ * for a route to an interface.
+ */
+ if (rt->rt_flags & RTF_GATEWAY) {
+ if (((rt->rt_flags & RTF_HOST) == 0) && (flags & RTF_HOST)) {
+ /*
+ * Changing from route to net => route to host.
+ * Create new route, rather than smashing route to net.
+ */
+ create:
+ flags |= RTF_GATEWAY | RTF_DYNAMIC;
+ error = rtrequest((int)RTM_ADD, dst, gateway,
+ netmask, flags,
+ (struct rtentry **)0);
+ stat = &rtstat.rts_dynamic;
+ } else {
+ /*
+ * Smash the current notion of the gateway to
+ * this destination. Should check about netmask!!!
+ */
+ rt->rt_flags |= RTF_MODIFIED;
+ flags |= RTF_MODIFIED;
+ stat = &rtstat.rts_newgateway;
+ rt_setgate(rt, rt_key(rt), gateway);
+ }
+ } else
+ error = EHOSTUNREACH;
+done:
+ if (rt) {
+ if (rtp && !error)
+ *rtp = rt;
+ else
+ rtfree(rt);
+ }
+out:
+ if (error)
+ rtstat.rts_badredirect++;
+ else if (stat != NULL)
+ (*stat)++;
+ bzero(&info, sizeof(info));
+ info.rti_info[RTAX_DST] = dst;
+ info.rti_info[RTAX_GATEWAY] = gateway;
+ info.rti_info[RTAX_NETMASK] = netmask;
+ info.rti_info[RTAX_AUTHOR] = src;
+ rt_missmsg(RTM_REDIRECT, &info, flags, error);
+}
+
+/*
+* Routing table ioctl interface.
+*/
+int
+rtioctl(int req, caddr_t data, struct proc *p)
+{
+#ifdef INET
+ /* Multicast goop, grrr... */
+#ifdef MROUTING
+ return mrt_ioctl(req, data);
+#else
+ return mrt_ioctl(req, data, p);
+#endif
+#else /* INET */
+ return ENXIO;
+#endif /* INET */
+}
+
+struct ifaddr *
+ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway)
+{
+ register struct ifaddr *ifa;
+ if ((flags & RTF_GATEWAY) == 0) {
+ /*
+ * If we are adding a route to an interface,
+ * and the interface is a pt to pt link
+ * we should search for the destination
+ * as our clue to the interface. Otherwise
+ * we can use the local address.
+ */
+ ifa = NULL;
+ if (flags & RTF_HOST) {
+ ifa = ifa_ifwithdstaddr(dst);
+ }
+ if (ifa == NULL)
+ ifa = ifa_ifwithaddr(gateway);
+ } else {
+ /*
+ * If we are adding a route to a remote net
+ * or host, the gateway may still be on the
+ * other end of a pt to pt link.
+ */
+ ifa = ifa_ifwithdstaddr(gateway);
+ }
+ if (ifa == 0)
+ ifa = ifa_ifwithnet(gateway);
+ if (ifa == 0) {
+ struct rtentry *rt = rtalloc1(dst, 0, 0UL);
+ if (rt == 0)
+ return (0);
+ rt->rt_refcnt--;
+ if ((ifa = rt->rt_ifa) == 0)
+ return (0);
+ }
+ if (ifa->ifa_addr->sa_family != dst->sa_family) {
+ struct ifaddr *oifa = ifa;
+ ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp);
+ if (ifa == 0)
+ ifa = oifa;
+ }
+ return (ifa);
+}
+
+#define ROUNDUP(a) (a>0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+
+static int rt_fixdelete(struct radix_node *, void *);
+static int rt_fixchange(struct radix_node *, void *);
+
+struct rtfc_arg {
+ struct rtentry *rt0;
+ struct radix_node_head *rnh;
+};
+
+/*
+ * Do appropriate manipulations of a routing tree given
+ * all the bits of info needed
+ */
+int
+rtrequest(int req, struct sockaddr *dst, struct sockaddr *gateway,
+ struct sockaddr *netmask, int flags, struct rtentry **ret_nrt)
+{
+ int s = splnet(); int error = 0;
+ register struct rtentry *rt;
+ register struct radix_node *rn;
+ register struct radix_node_head *rnh;
+ struct ifaddr *ifa;
+ struct sockaddr *ndst;
+#define senderr(x) { error = x ; goto bad; }
+
+ /*
+ * Find the correct routing tree to use for this Address Family
+ */
+ if ((rnh = rt_tables[dst->sa_family]) == 0)
+ senderr(ESRCH);
+ /*
+ * If we are adding a host route then we don't want to put
+ * a netmask in the tree
+ */
+ if (flags & RTF_HOST)
+ netmask = 0;
+ switch (req) {
+ case RTM_DELETE:
+ /*
+ * Remove the item from the tree and return it.
+ * Complain if it is not there and do no more processing.
+ */
+ if ((rn = rnh->rnh_deladdr(dst, netmask, rnh)) == 0)
+ senderr(ESRCH);
+ if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT))
+ panic ("rtrequest delete");
+ rt = (struct rtentry *)rn;
+
+ /*
+ * Now search what's left of the subtree for any cloned
+ * routes which might have been formed from this node.
+ */
+ if ((rt->rt_flags & RTF_PRCLONING) && netmask) {
+ rnh->rnh_walktree_from(rnh, dst, netmask,
+ rt_fixdelete, rt);
+ }
+
+ /*
+ * Remove any external references we may have.
+ * This might result in another rtentry being freed if
+ * we held it's last reference.
+ */
+ if (rt->rt_gwroute) {
+ rt = rt->rt_gwroute;
+ RTFREE(rt);
+ (rt = (struct rtentry *)rn)->rt_gwroute = 0;
+ }
+
+ /*
+ * NB: RTF_UP must be set during the search above,
+ * because we might delete the last ref, causing
+ * rt to get freed prematurely.
+ */
+ rt->rt_flags &= ~RTF_UP;
+
+ /*
+ * If there is llinfo or similar associated with the
+ * route, give the interface a chance to deal with it..
+ */
+ if ((ifa = rt->rt_ifa) && ifa->ifa_rtrequest)
+ ifa->ifa_rtrequest(RTM_DELETE, rt, SA(0));
+ rttrash++;
+ /*
+ * If the caller wants it, then it can have it, but it's up to it
+ * to free the rtentry as we won't be doing it.
+ */
+ if (ret_nrt)
+ *ret_nrt = rt;
+ else if (rt->rt_refcnt <= 0) {
+ rt->rt_refcnt++; /* make a 1->0 transition */
+ rtfree(rt);
+ }
+ break;
+
+ case RTM_RESOLVE:
+ if (ret_nrt == 0 || (rt = *ret_nrt) == 0)
+ senderr(EINVAL);
+ ifa = rt->rt_ifa;
+ flags = rt->rt_flags &
+ ~(RTF_CLONING | RTF_PRCLONING | RTF_STATIC);
+ flags |= RTF_WASCLONED;
+ gateway = rt->rt_gateway;
+ if ((netmask = rt->rt_genmask) == 0)
+ flags |= RTF_HOST;
+ goto makeroute;
+
+ case RTM_ADD:
+ if ((flags & RTF_GATEWAY) && !gateway)
+ panic("rtrequest: GATEWAY but no gateway");
+
+ if ((ifa = ifa_ifwithroute(flags, dst, gateway)) == 0)
+ senderr(ENETUNREACH);
+
+ makeroute:
+ R_Malloc(rt, struct rtentry *, sizeof(*rt));
+ if (rt == 0)
+ senderr(ENOBUFS);
+ Bzero(rt, sizeof(*rt));
+ rt->rt_flags = RTF_UP | flags;
+ if ((error = rt_setgate(rt, dst, gateway))) {
+ Free(rt);
+ senderr(error);
+ }
+ ndst = rt_key(rt);
+ if (netmask) {
+ rt_maskedcopy(dst, ndst, netmask);
+ } else
+ Bcopy(dst, ndst, dst->sa_len);
+
+ /*
+ * This moved from below so that rnh->rnh_addaddr() can
+ * examine the ifa and ifp if it so desires.
+ */
+ ifa->ifa_refcnt++;
+ rt->rt_ifa = ifa;
+ rt->rt_ifp = ifa->ifa_ifp;
+
+ rn = rnh->rnh_addaddr((caddr_t)ndst, (caddr_t)netmask,
+ rnh, rt->rt_nodes);
+ if (rn == 0) {
+ struct rtentry *rt2;
+ /*
+ * Uh-oh, we already have one of these in the tree.
+ * We do a special hack: if the route that's already
+ * there was generated by the protocol-cloning
+ * mechanism, then we just blow it away and retry
+ * the insertion of the new one.
+ */
+ rt2 = rtalloc1(dst, 0, RTF_PRCLONING);
+ if (rt2 && rt2->rt_parent) {
+ rtrequest(RTM_DELETE,
+ (struct sockaddr *)rt_key(rt2),
+ rt2->rt_gateway,
+ rt_mask(rt2), rt2->rt_flags, 0);
+ RTFREE(rt2);
+ rn = rnh->rnh_addaddr((caddr_t)ndst,
+ (caddr_t)netmask,
+ rnh, rt->rt_nodes);
+ } else if (rt2) {
+ RTFREE(rt2);
+ }
+ }
+
+ if (rn == 0) {
+ if (rt->rt_gwroute)
+ rtfree(rt->rt_gwroute);
+ if (rt->rt_ifa) {
+ IFAFREE(rt->rt_ifa);
+ }
+ Free(rt_key(rt));
+ Free(rt);
+ senderr(EEXIST);
+ }
+ rt->rt_parent = 0;
+
+ if (req == RTM_RESOLVE) {
+ rt->rt_rmx = (*ret_nrt)->rt_rmx; /* copy metrics */
+ if ((*ret_nrt)->rt_flags & RTF_PRCLONING) {
+ rt->rt_parent = (*ret_nrt);
+ (*ret_nrt)->rt_refcnt++;
+ }
+ }
+ if (ifa->ifa_rtrequest)
+ ifa->ifa_rtrequest(req, rt, SA(ret_nrt ? *ret_nrt : 0));
+ /*
+ * We repeat the same procedure from rt_setgate() here because
+ * it doesn't fire when we call it there because the node
+ * hasn't been added to the tree yet.
+ */
+ if (!(rt->rt_flags & RTF_HOST) && rt_mask(rt) != 0) {
+ struct rtfc_arg arg;
+ arg.rnh = rnh;
+ arg.rt0 = rt;
+ rnh->rnh_walktree_from(rnh, rt_key(rt), rt_mask(rt),
+ rt_fixchange, &arg);
+ }
+
+ if (ret_nrt) {
+ *ret_nrt = rt;
+ rt->rt_refcnt++;
+ }
+ break;
+ }
+bad:
+ splx(s);
+ return (error);
+}
+
+/*
+ * Called from rtrequest(RTM_DELETE, ...) to fix up the route's ``family''
+ * (i.e., the routes related to it by the operation of cloning). This
+ * routine is iterated over all potential former-child-routes by way of
+ * rnh->rnh_walktree_from() above, and those that actually are children of
+ * the late parent (passed in as VP here) are themselves deleted.
+ */
+static int
+rt_fixdelete(struct radix_node *rn, void *vp)
+{
+ struct rtentry *rt = (struct rtentry *)rn;
+ struct rtentry *rt0 = vp;
+
+ if (rt->rt_parent == rt0 && !(rt->rt_flags & RTF_PINNED)) {
+ return rtrequest(RTM_DELETE, rt_key(rt),
+ (struct sockaddr *)0, rt_mask(rt),
+ rt->rt_flags, (struct rtentry **)0);
+ }
+ return 0;
+}
+
+/*
+ * This routine is called from rt_setgate() to do the analogous thing for
+ * adds and changes. There is the added complication in this case of a
+ * middle insert; i.e., insertion of a new network route between an older
+ * network route and (cloned) host routes. For this reason, a simple check
+ * of rt->rt_parent is insufficient; each candidate route must be tested
+ * against the (mask, value) of the new route (passed as before in vp)
+ * to see if the new route matches it. Unfortunately, this has the obnoxious
+ * property of also triggering for insertion /above/ a pre-existing network
+ * route and clones. Sigh. This may be fixed some day.
+ *
+ * XXX - it may be possible to do fixdelete() for changes and reserve this
+ * routine just for adds. I'm not sure why I thought it was necessary to do
+ * changes this way.
+ */
+#ifdef DEBUG
+int rtfcdebug = 0;
+#endif
+
+static int
+rt_fixchange(struct radix_node *rn, void *vp)
+{
+ struct rtentry *rt = (struct rtentry *)rn;
+ struct rtfc_arg *ap = vp;
+ struct rtentry *rt0 = ap->rt0;
+ struct radix_node_head *rnh = ap->rnh;
+ u_char *xk1, *xm1, *xk2;
+ int i, len;
+
+#ifdef DEBUG
+ if (rtfcdebug)
+ printf("rt_fixchange: rt %p, rt0 %p\n", rt, rt0);
+#endif
+
+ if (!rt->rt_parent || (rt->rt_flags & RTF_PINNED)) {
+#ifdef DEBUG
+ if(rtfcdebug) printf("no parent or pinned\n");
+#endif
+ return 0;
+ }
+
+ if (rt->rt_parent == rt0) {
+#ifdef DEBUG
+ if(rtfcdebug) printf("parent match\n");
+#endif
+ return rtrequest(RTM_DELETE, rt_key(rt),
+ (struct sockaddr *)0, rt_mask(rt),
+ rt->rt_flags, (struct rtentry **)0);
+ }
+
+ /*
+ * There probably is a function somewhere which does this...
+ * if not, there should be.
+ */
+ len = imin(((struct sockaddr *)rt_key(rt0))->sa_len,
+ ((struct sockaddr *)rt_key(rt))->sa_len);
+
+ xk1 = (u_char *)rt_key(rt0);
+ xm1 = (u_char *)rt_mask(rt0);
+ xk2 = (u_char *)rt_key(rt);
+
+ for (i = rnh->rnh_treetop->rn_offset; i < len; i++) {
+ if ((xk2[i] & xm1[i]) != xk1[i]) {
+#ifdef DEBUG
+ if(rtfcdebug) printf("no match\n");
+#endif
+ return 0;
+ }
+ }
+
+ /*
+ * OK, this node is a clone, and matches the node currently being
+ * changed/added under the node's mask. So, get rid of it.
+ */
+#ifdef DEBUG
+ if(rtfcdebug) printf("deleting\n");
+#endif
+ return rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
+ rt_mask(rt), rt->rt_flags, (struct rtentry **)0);
+}
+
+int
+rt_setgate(struct rtentry *rt0, struct sockaddr *dst, struct sockaddr *gate)
+{
+ caddr_t new, old;
+ int dlen = ROUNDUP(dst->sa_len), glen = ROUNDUP(gate->sa_len);
+ register struct rtentry *rt = rt0;
+ struct radix_node_head *rnh = rt_tables[dst->sa_family];
+
+ /*
+ * A host route with the destination equal to the gateway
+ * will interfere with keeping LLINFO in the routing
+ * table, so disallow it.
+ */
+ if (((rt0->rt_flags & (RTF_HOST|RTF_GATEWAY|RTF_LLINFO)) ==
+ (RTF_HOST|RTF_GATEWAY)) &&
+ (dst->sa_len == gate->sa_len) &&
+ (bcmp(dst, gate, dst->sa_len) == 0)) {
+ /*
+ * The route might already exist if this is an RTM_CHANGE
+ * or a routing redirect, so try to delete it.
+ */
+ if (rt_key(rt0))
+ rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt0),
+ rt0->rt_gateway, rt_mask(rt0), rt0->rt_flags, 0);
+ return EADDRNOTAVAIL;
+ }
+
+ if (rt->rt_gateway == 0 || glen > ROUNDUP(rt->rt_gateway->sa_len)) {
+ old = (caddr_t)rt_key(rt);
+ R_Malloc(new, caddr_t, dlen + glen);
+ if (new == 0)
+ return ENOBUFS;
+ rt->rt_nodes->rn_key = new;
+ } else {
+ new = rt->rt_nodes->rn_key;
+ old = 0;
+ }
+ Bcopy(gate, (rt->rt_gateway = (struct sockaddr *)(new + dlen)), glen);
+ if (old) {
+ Bcopy(dst, new, dlen);
+ Free(old);
+ }
+ if (rt->rt_gwroute) {
+ rt = rt->rt_gwroute; RTFREE(rt);
+ rt = rt0; rt->rt_gwroute = 0;
+ }
+ /*
+ * Cloning loop avoidance:
+ * In the presence of protocol-cloning and bad configuration,
+ * it is possible to get stuck in bottomless mutual recursion
+ * (rtrequest rt_setgate rtalloc1). We avoid this by not allowing
+ * protocol-cloning to operate for gateways (which is probably the
+ * correct choice anyway), and avoid the resulting reference loops
+ * by disallowing any route to run through itself as a gateway.
+ * This is obviuosly mandatory when we get rt->rt_output().
+ */
+ if (rt->rt_flags & RTF_GATEWAY) {
+ rt->rt_gwroute = rtalloc1(gate, 1, RTF_PRCLONING);
+ if (rt->rt_gwroute == rt) {
+ RTFREE(rt->rt_gwroute);
+ rt->rt_gwroute = 0;
+ return EDQUOT; /* failure */
+ }
+ }
+
+ /*
+ * This isn't going to do anything useful for host routes, so
+ * don't bother. Also make sure we have a reasonable mask
+ * (we don't yet have one during adds).
+ */
+ if (!(rt->rt_flags & RTF_HOST) && rt_mask(rt) != 0) {
+ struct rtfc_arg arg;
+ arg.rnh = rnh;
+ arg.rt0 = rt;
+ rnh->rnh_walktree_from(rnh, rt_key(rt), rt_mask(rt),
+ rt_fixchange, &arg);
+ }
+
+ return 0;
+}
+
+static void
+rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst,
+ struct sockaddr *netmask)
+{
+ register u_char *cp1 = (u_char *)src;
+ register u_char *cp2 = (u_char *)dst;
+ register u_char *cp3 = (u_char *)netmask;
+ u_char *cplim = cp2 + *cp3;
+ u_char *cplim2 = cp2 + *cp1;
+
+ *cp2++ = *cp1++; *cp2++ = *cp1++; /* copies sa_len & sa_family */
+ cp3 += 2;
+ if (cplim > cplim2)
+ cplim = cplim2;
+ while (cp2 < cplim)
+ *cp2++ = *cp1++ & *cp3++;
+ if (cp2 < cplim2)
+ bzero(cp2, (unsigned)(cplim2 - cp2));
+}
+
+/*
+ * Set up a routing table entry, normally
+ * for an interface.
+ */
+int
+rtinit(struct ifaddr *ifa, int cmd, int flags)
+{
+ register struct rtentry *rt;
+ register struct sockaddr *dst;
+ register struct sockaddr *deldst;
+ struct mbuf *m = 0;
+ struct rtentry *nrt = 0;
+ int error;
+
+ dst = flags & RTF_HOST ? ifa->ifa_dstaddr : ifa->ifa_addr;
+ /*
+ * If it's a delete, check that if it exists, it's on the correct
+ * interface or we might scrub a route to another ifa which would
+ * be confusing at best and possibly worse.
+ */
+ if (cmd == RTM_DELETE) {
+ /*
+ * It's a delete, so it should already exist..
+ * If it's a net, mask off the host bits
+ * (Assuming we have a mask)
+ */
+ if ((flags & RTF_HOST) == 0 && ifa->ifa_netmask) {
+ m = m_get(M_WAIT, MT_SONAME);
+ deldst = mtod(m, struct sockaddr *);
+ rt_maskedcopy(dst, deldst, ifa->ifa_netmask);
+ dst = deldst;
+ }
+ /*
+ * Get an rtentry that is in the routing tree and
+ * contains the correct info. (if this fails we can't get there).
+ * We set "report" to FALSE so that if it doesn't exist,
+ * it doesn't report an error or clone a route, etc. etc.
+ */
+ rt = rtalloc1(dst, 0, 0UL);
+ if (rt) {
+ /*
+ * Ok so we found the rtentry. it has an extra reference
+ * for us at this stage. we won't need that so
+ * lop that off now.
+ */
+ rt->rt_refcnt--;
+ if (rt->rt_ifa != ifa) {
+ /*
+ * If the interface in the rtentry doesn't match
+ * the interface we are using, then we don't
+ * want to delete it, so return an error.
+ * This seems to be the only point of
+ * this whole RTM_DELETE clause.
+ */
+ if (m)
+ (void) m_free(m);
+ return (flags & RTF_HOST ? EHOSTUNREACH
+ : ENETUNREACH);
+ }
+ }
+ /* XXX */
+#if 0
+ else {
+ /*
+ * One would think that as we are deleting, and we know
+ * it doesn't exist, we could just return at this point
+ * with an "ELSE" clause, but apparently not..
+ */
+ return (flags & RTF_HOST ? EHOSTUNREACH
+ : ENETUNREACH);
+ }
+#endif
+ }
+ /*
+ * Do the actual request
+ */
+ error = rtrequest(cmd, dst, ifa->ifa_addr, ifa->ifa_netmask,
+ flags | ifa->ifa_flags, &nrt);
+ if (m)
+ (void) m_free(m);
+ /*
+ * If we are deleting, and we found an entry, then
+ * it's been removed from the tree.. now throw it away.
+ */
+ if (cmd == RTM_DELETE && error == 0 && (rt = nrt)) {
+ /*
+ * notify any listenning routing agents of the change
+ */
+ rt_newaddrmsg(cmd, ifa, error, nrt);
+ if (rt->rt_refcnt <= 0) {
+ rt->rt_refcnt++; /* need a 1->0 transition to free */
+ rtfree(rt);
+ }
+ }
+
+ /*
+ * We are adding, and we have a returned routing entry.
+ * We need to sanity check the result.
+ */
+ if (cmd == RTM_ADD && error == 0 && (rt = nrt)) {
+ /*
+ * We just wanted to add it.. we don't actually need a reference
+ */
+ rt->rt_refcnt--;
+ /*
+ * If it came back with an unexpected interface, then it must
+ * have already existed or something. (XXX)
+ */
+ if (rt->rt_ifa != ifa) {
+ printf("rtinit: wrong ifa (%p) was (%p)\n", ifa,
+ rt->rt_ifa);
+ /*
+ * Ask that the route we got back be removed
+ * from the routing tables as we are trying
+ * to supersede it.
+ */
+ if (rt->rt_ifa->ifa_rtrequest)
+ rt->rt_ifa->ifa_rtrequest(RTM_DELETE, rt, SA(0));
+ /*
+ * Remove the referenve to the it's ifaddr.
+ */
+ IFAFREE(rt->rt_ifa);
+ /*
+ * And substitute in references to the ifaddr
+ * we are adding.
+ */
+ rt->rt_ifa = ifa;
+ rt->rt_ifp = ifa->ifa_ifp;
+ ifa->ifa_refcnt++;
+ /*
+ * Now add it to the routing table
+ * XXX could we have just left it?
+ * as it might have been in the right place..
+ */
+ if (ifa->ifa_rtrequest)
+ ifa->ifa_rtrequest(RTM_ADD, rt, SA(0));
+ }
+ /*
+ * notify any listenning routing agents of the change
+ */
+ rt_newaddrmsg(cmd, ifa, error, nrt);
+ }
+ return (error);
+}
diff --git a/cpukit/libnetworking/net/route.h b/cpukit/libnetworking/net/route.h
new file mode 100644
index 0000000000..6549937d05
--- /dev/null
+++ b/cpukit/libnetworking/net/route.h
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 1980, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)route.h 8.4 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/net/route.h,v 1.65 2006/03/15 19:39:09 andre Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NET_ROUTE_H_
+#define _NET_ROUTE_H_
+
+#include <sys/socket.h> /* struct sockaddr */
+/*
+ * Kernel resident routing tables.
+ *
+ * The routing tables are initialized when interface addresses
+ * are set by making entries for all directly connected interfaces.
+ */
+
+/*
+ * A route consists of a destination address and a reference
+ * to a routing entry. These are often held by protocols
+ * in their control blocks, e.g. inpcb.
+ */
+struct route {
+ struct rtentry *ro_rt;
+ struct sockaddr ro_dst;
+};
+
+/*
+ * These numbers are used by reliable protocols for determining
+ * retransmission behavior and are included in the routing structure.
+ */
+struct rt_metrics_lite {
+ u_long rmx_mtu; /* MTU for this path */
+ u_long rmx_expire; /* lifetime for route, e.g. redirect */
+ u_long rmx_pksent; /* packets sent using this route */
+};
+
+struct rt_metrics {
+ u_long rmx_locks; /* Kernel must leave these values alone */
+ u_long rmx_mtu; /* MTU for this path */
+ u_long rmx_hopcount; /* max hops expected */
+ u_long rmx_expire; /* lifetime for route, e.g. redirect */
+ u_long rmx_recvpipe; /* inbound delay-bandwidth product */
+ u_long rmx_sendpipe; /* outbound delay-bandwidth product */
+ u_long rmx_ssthresh; /* outbound gateway buffer limit */
+ u_long rmx_rtt; /* estimated round trip time */
+ u_long rmx_rttvar; /* estimated rtt variance */
+ u_long rmx_pksent; /* packets sent using this route */
+ u_long rmx_filler[4]; /* will be used for T/TCP later */
+};
+
+/*
+ * rmx_rtt and rmx_rttvar are stored as microseconds;
+ * RTTTOPRHZ(rtt) converts to a value suitable for use
+ * by a protocol slowtimo counter.
+ */
+#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
+#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
+
+/*
+ * XXX kernel function pointer `rt_output' is visible to applications.
+ */
+struct mbuf;
+
+/*
+ * We distinguish between routes to hosts and routes to networks,
+ * preferring the former if available. For each route we infer
+ * the interface to use from the gateway address supplied when
+ * the route was entered. Routes that forward packets through
+ * gateways are marked so that the output routines know to address the
+ * gateway rather than the ultimate destination.
+ */
+#ifndef RNF_NORMAL
+#include <net/radix.h>
+#endif
+struct rtentry {
+ struct radix_node rt_nodes[2]; /* tree glue, and other values */
+#define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key))
+#define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask))
+ struct sockaddr *rt_gateway; /* value */
+ u_long rt_flags; /* up/down?, host/net */
+ struct ifnet *rt_ifp; /* the answer: interface to use */
+ struct ifaddr *rt_ifa; /* the answer: interface address to use */
+ struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */
+ long rt_refcnt; /* # held references */
+ struct sockaddr *rt_genmask; /* for generation of cloned routes */
+ caddr_t rt_llinfo; /* pointer to link level info cache */
+ struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
+ struct rtentry *rt_parent; /* cloning parent of this route */
+};
+
+/*
+ * Following structure necessary for 4.3 compatibility;
+ * We should eventually move it to a compat file.
+ */
+struct ortentry {
+ u_long rt_hash; /* to speed lookups */
+ struct sockaddr rt_dst; /* key */
+ struct sockaddr rt_gateway; /* value */
+ short rt_flags; /* up/down?, host/net */
+ short rt_refcnt; /* # held references */
+ u_long rt_use; /* raw # packets forwarded */
+ struct ifnet *rt_ifp; /* the answer: interface to use */
+};
+
+#define rt_use rt_rmx.rmx_pksent
+
+#define RTF_UP 0x1 /* route usable */
+#define RTF_GATEWAY 0x2 /* destination is a gateway */
+#define RTF_HOST 0x4 /* host entry (net otherwise) */
+#define RTF_REJECT 0x8 /* host or net unreachable */
+#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
+#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
+#define RTF_DONE 0x40 /* message confirmed */
+/* 0x80 unused, was RTF_DELCLONE */
+#define RTF_CLONING 0x100 /* generate new routes on use */
+#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
+#define RTF_LLINFO 0x400 /* generated by link layer (e.g. ARP) */
+#define RTF_STATIC 0x800 /* manually added */
+#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
+#define RTF_PROTO2 0x4000 /* protocol specific routing flag */
+#define RTF_PROTO1 0x8000 /* protocol specific routing flag */
+
+#define RTF_PRCLONING 0x10000 /* protocol requires cloning */
+#define RTF_WASCLONED 0x20000 /* route generated through cloning */
+#define RTF_PROTO3 0x40000 /* protocol specific routing flag */
+/* 0x80000 unused */
+#define RTF_PINNED 0x100000 /* future use */
+#define RTF_LOCAL 0x200000 /* route represents a local address */
+#define RTF_BROADCAST 0x400000 /* route represents a bcast address */
+#define RTF_MULTICAST 0x800000 /* route represents a mcast address */
+ /* 0x1000000 and up unassigned */
+
+/*
+ * Routing statistics.
+ */
+struct rtstat {
+ short rts_badredirect; /* bogus redirect calls */
+ short rts_dynamic; /* routes created by redirects */
+ short rts_newgateway; /* routes modified by redirects */
+ short rts_unreach; /* lookups which failed */
+ short rts_wildcard; /* lookups satisfied by a wildcard */
+};
+/*
+ * Structures for routing messages.
+ */
+struct rt_msghdr {
+ u_short rtm_msglen; /* to skip over non-understood messages */
+ u_char rtm_version; /* future binary compatibility */
+ u_char rtm_type; /* message type */
+ u_short rtm_index; /* index for associated ifp */
+ int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
+ int rtm_addrs; /* bitmask identifying sockaddrs in msg */
+ pid_t rtm_pid; /* identify sender */
+ int rtm_seq; /* for sender to identify action */
+ int rtm_errno; /* why failed */
+ int rtm_use; /* from rtentry */
+ u_long rtm_inits; /* which metrics we are initializing */
+ struct rt_metrics rtm_rmx; /* metrics themselves */
+};
+
+#define RTM_VERSION 5 /* Up the ante and ignore older versions */
+
+/*
+ * Message types.
+ */
+#define RTM_ADD 0x1 /* Add Route */
+#define RTM_DELETE 0x2 /* Delete Route */
+#define RTM_CHANGE 0x3 /* Change Metrics or flags */
+#define RTM_GET 0x4 /* Report Metrics */
+#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
+#define RTM_REDIRECT 0x6 /* Told to use different route */
+#define RTM_MISS 0x7 /* Lookup failed on this address */
+#define RTM_LOCK 0x8 /* fix specified metrics */
+#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
+#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
+#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
+#define RTM_NEWADDR 0xc /* address being added to iface */
+#define RTM_DELADDR 0xd /* address being removed from iface */
+#define RTM_IFINFO 0xe /* iface going up/down etc. */
+#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
+#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
+#define RTM_IFANNOUNCE 0x11 /* iface arrival/departure */
+#define RTM_IEEE80211 0x12 /* IEEE80211 wireless event */
+
+/*
+ * Bitmask values for rtm_inits and rmx_locks.
+ */
+#define RTV_MTU 0x1 /* init or lock _mtu */
+#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
+#define RTV_EXPIRE 0x4 /* init or lock _expire */
+#define RTV_RPIPE 0x8 /* init or lock _recvpipe */
+#define RTV_SPIPE 0x10 /* init or lock _sendpipe */
+#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
+#define RTV_RTT 0x40 /* init or lock _rtt */
+#define RTV_RTTVAR 0x80 /* init or lock _rttvar */
+
+/*
+ * Bitmask values for rtm_addrs.
+ */
+#define RTA_DST 0x1 /* destination sockaddr present */
+#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
+#define RTA_NETMASK 0x4 /* netmask sockaddr present */
+#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
+#define RTA_IFP 0x10 /* interface name sockaddr present */
+#define RTA_IFA 0x20 /* interface addr sockaddr present */
+#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
+#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
+
+/*
+ * Index offsets for sockaddr array for alternate internal encoding.
+ */
+#define RTAX_DST 0 /* destination sockaddr present */
+#define RTAX_GATEWAY 1 /* gateway sockaddr present */
+#define RTAX_NETMASK 2 /* netmask sockaddr present */
+#define RTAX_GENMASK 3 /* cloning mask sockaddr present */
+#define RTAX_IFP 4 /* interface name sockaddr present */
+#define RTAX_IFA 5 /* interface addr sockaddr present */
+#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
+#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
+#define RTAX_MAX 8 /* size of array to allocate */
+
+struct rt_addrinfo {
+ int rti_addrs;
+ struct sockaddr *rti_info[RTAX_MAX];
+};
+
+struct route_cb {
+ int ip_count;
+ int ipx_count;
+ int ns_count;
+ int iso_count;
+ int any_count;
+};
+
+#ifdef _KERNEL
+#define RTFREE(rt) \
+ do { \
+ if ((rt)->rt_refcnt <= 1) \
+ rtfree(rt); \
+ else \
+ (rt)->rt_refcnt--; \
+ } while (0)
+
+extern struct route_cb route_cb;
+extern struct radix_node_head *rt_tables[AF_MAX+1];
+
+void route_init(void);
+void rt_ifmsg(struct ifnet *);
+void rt_missmsg(int, struct rt_addrinfo *, int, int);
+void rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *);
+int rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *);
+void rtalloc_ign(struct route *, unsigned long);
+void rtalloc(struct route *ro); /* XXX deprecated, use rtalloc_ign(ro, 0) */
+struct rtentry *
+ rtalloc1(struct sockaddr *, int, unsigned long);
+void rtfree(struct rtentry *);
+int rtinit(struct ifaddr *, int, int);
+int rtioctl(int, caddr_t, struct proc *);
+void rtredirect(struct sockaddr *, struct sockaddr *,
+ struct sockaddr *, int, struct sockaddr *, struct rtentry **);
+int rtrequest(int, struct sockaddr *,
+ struct sockaddr *, struct sockaddr *, int, struct rtentry **);
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/net/rtsock.c b/cpukit/libnetworking/net/rtsock.c
new file mode 100644
index 0000000000..fb791f658b
--- /dev/null
+++ b/cpukit/libnetworking/net/rtsock.c
@@ -0,0 +1,801 @@
+/*
+ * Copyright (c) 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)rtsock.c 8.7 (Berkeley) 10/12/95
+ * $FreeBSD: src/sys/net/rtsock.c,v 1.122 2005/03/26 21:49:43 sam Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <net/raw_cb.h>
+
+static struct sockaddr route_dst = { 2, PF_ROUTE, { 0 } };
+static struct sockaddr route_src = { 2, PF_ROUTE, { 0 } };
+static struct sockaddr sa_zero = { sizeof(sa_zero), AF_INET, { 0 } };
+static struct sockproto route_proto = { PF_ROUTE, 0 };
+
+struct walkarg {
+ int w_tmemsize;
+ int w_op, w_arg;
+ caddr_t w_tmem;
+ struct sysctl_req *w_req;
+};
+
+static struct mbuf *rt_msg1(int type, struct rt_addrinfo *rtinfo);
+static int rt_msg2(int type, struct rt_addrinfo *rtinfo,
+ caddr_t cp, struct walkarg *w);
+static int rt_xaddrs(caddr_t cp, caddr_t cplim,
+ struct rt_addrinfo *rtinfo);
+static int sysctl_dumpentry(struct radix_node *rn, void *vw);
+static int sysctl_iflist(int af, struct walkarg *w);
+static int route_output(struct mbuf *m, struct socket *so);
+static int route_usrreq(struct socket *,
+ int, struct mbuf *, struct mbuf *, struct mbuf *);
+static void rt_setmetrics(u_long which, const struct rt_metrics *in,
+ struct rt_metrics *out);
+
+/*ARGSUSED*/
+static int
+route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
+ struct mbuf *control)
+{
+ int error = 0;
+ struct rawcb *rp = sotorawcb(so);
+ int s;
+
+ if (req == PRU_ATTACH) {
+ MALLOC(rp, struct rawcb *, sizeof(*rp), M_PCB, M_WAITOK);
+ so->so_pcb = (caddr_t)rp;
+ if (so->so_pcb)
+ bzero(so->so_pcb, sizeof(*rp));
+ }
+ if (req == PRU_DETACH && rp) {
+ int af = rp->rcb_proto.sp_protocol;
+ if (af == AF_INET)
+ route_cb.ip_count--;
+ else if (af == AF_IPX)
+ route_cb.ipx_count--;
+ else if (af == AF_ISO)
+ route_cb.iso_count--;
+ route_cb.any_count--;
+ }
+ s = splnet();
+ error = raw_usrreq(so, req, m, nam, control);
+ rp = sotorawcb(so);
+ if (req == PRU_ATTACH && rp) {
+ int af = rp->rcb_proto.sp_protocol;
+ if (error) {
+ free((caddr_t)rp, M_PCB);
+ splx(s);
+ return (error);
+ }
+ if (af == AF_INET)
+ route_cb.ip_count++;
+ else if (af == AF_IPX)
+ route_cb.ipx_count++;
+ else if (af == AF_ISO)
+ route_cb.iso_count++;
+ rp->rcb_faddr = &route_src;
+ route_cb.any_count++;
+ soisconnected(so);
+ so->so_options |= SO_USELOOPBACK;
+ }
+ splx(s);
+ return (error);
+}
+
+/*ARGSUSED*/
+static int
+route_output(struct mbuf *m, struct socket *so)
+{
+#define sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0)
+ struct rt_msghdr *rtm = NULL;
+ struct rtentry *rt = NULL;
+ struct rtentry *saved_nrt = 0;
+ struct radix_node_head *rnh;
+ struct rt_addrinfo info;
+ int len, error = 0;
+ struct ifnet *ifp = NULL;
+ struct ifaddr *ifa = NULL;
+
+#define senderr(e) { error = e; goto flush;}
+ if (m == NULL || ((m->m_len < sizeof(long)) &&
+ (m = m_pullup(m, sizeof(long))) == NULL))
+ return (ENOBUFS);
+ if ((m->m_flags & M_PKTHDR) == 0)
+ panic("route_output");
+ len = m->m_pkthdr.len;
+ if (len < sizeof(*rtm) ||
+ len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
+ info.rti_info[RTAX_DST] = NULL;
+ senderr(EINVAL);
+ }
+ R_Malloc(rtm, struct rt_msghdr *, len);
+ if (rtm == NULL) {
+ info.rti_info[RTAX_DST] = NULL;
+ senderr(ENOBUFS);
+ }
+ m_copydata(m, 0, len, (caddr_t)rtm);
+ if (rtm->rtm_version != RTM_VERSION) {
+ info.rti_info[RTAX_DST] = NULL;
+ senderr(EPROTONOSUPPORT);
+ }
+ info.rti_addrs = rtm->rtm_addrs;
+ if (rt_xaddrs((caddr_t)(rtm + 1), len + (caddr_t)rtm, &info)) {
+ info.rti_info[RTAX_DST] = NULL;
+ senderr(EINVAL);
+ }
+ if (info.rti_info[RTAX_DST] == NULL ||
+ info.rti_info[RTAX_DST]->sa_family >= AF_MAX ||
+ (info.rti_info[RTAX_GATEWAY] != NULL &&
+ info.rti_info[RTAX_GATEWAY]->sa_family >= AF_MAX))
+ senderr(EINVAL);
+ if (info.rti_info[RTAX_GENMASK]) {
+ struct radix_node *t;
+ t = rn_addmask((caddr_t) info.rti_info[RTAX_GENMASK], 0, 1);
+ if (t != NULL &&
+ Bcmp(info.rti_info[RTAX_GENMASK], t->rn_key, *(u_char *)info.rti_info[RTAX_GENMASK]) == 0)
+ info.rti_info[RTAX_GENMASK] =
+ (struct sockaddr *)t->rn_key;
+ else
+ senderr(ENOBUFS);
+ }
+ switch (rtm->rtm_type) {
+
+ case RTM_ADD:
+ if (info.rti_info[RTAX_GATEWAY] == NULL)
+ senderr(EINVAL);
+ error = rtrequest(RTM_ADD, info.rti_info[RTAX_DST], info.rti_info[RTAX_GATEWAY], info.rti_info[RTAX_NETMASK],
+ rtm->rtm_flags, &saved_nrt);
+ if (error == 0 && saved_nrt) {
+ rt_setmetrics(rtm->rtm_inits,
+ &rtm->rtm_rmx, &saved_nrt->rt_rmx);
+ saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
+ saved_nrt->rt_rmx.rmx_locks |=
+ (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
+ saved_nrt->rt_refcnt--;
+ saved_nrt->rt_genmask = info.rti_info[RTAX_GENMASK];
+ }
+ break;
+
+ case RTM_DELETE:
+ error = rtrequest(RTM_DELETE, info.rti_info[RTAX_DST], info.rti_info[RTAX_GATEWAY], info.rti_info[RTAX_NETMASK],
+ rtm->rtm_flags, &saved_nrt);
+ if (error == 0) {
+ if ((rt = saved_nrt))
+ rt->rt_refcnt++;
+ goto report;
+ }
+ break;
+
+ case RTM_GET:
+ case RTM_CHANGE:
+ case RTM_LOCK:
+ rnh = rt_tables[info.rti_info[RTAX_DST]->sa_family];
+ if (rnh == NULL) {
+ senderr(EAFNOSUPPORT);
+ } else if ((rt = (struct rtentry *)
+ rnh->rnh_lookup(info.rti_info[RTAX_DST], info.rti_info[RTAX_NETMASK], rnh)))
+ rt->rt_refcnt++;
+ else
+ senderr(ESRCH);
+ switch(rtm->rtm_type) {
+
+ case RTM_GET:
+ report:
+ info.rti_info[RTAX_DST] = rt_key(rt);
+ info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
+ info.rti_info[RTAX_NETMASK] = rt_mask(rt);
+ info.rti_info[RTAX_GENMASK] = rt->rt_genmask;
+ if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) {
+ ifp = rt->rt_ifp;
+ if (ifp) {
+ info.rti_info[RTAX_IFP] = ifp->if_addrlist->ifa_addr;
+ info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
+ rtm->rtm_index = ifp->if_index;
+ } else {
+ info.rti_info[RTAX_IFP] = NULL;
+ info.rti_info[RTAX_IFA] = NULL;
+ }
+ }
+ len = rt_msg2(rtm->rtm_type, &info, NULL, NULL);
+ if (len > rtm->rtm_msglen) {
+ struct rt_msghdr *new_rtm;
+ R_Malloc(new_rtm, struct rt_msghdr *, len);
+ if (new_rtm == NULL) {
+ senderr(ENOBUFS);
+ }
+ Bcopy(rtm, new_rtm, rtm->rtm_msglen);
+ Free(rtm); rtm = new_rtm;
+ }
+ (void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, NULL);
+ rtm->rtm_flags = rt->rt_flags;
+ rtm->rtm_rmx = rt->rt_rmx;
+ rtm->rtm_addrs = info.rti_addrs;
+ break;
+
+ case RTM_CHANGE:
+ if (info.rti_info[RTAX_GATEWAY] && (error = rt_setgate(rt, rt_key(rt), info.rti_info[RTAX_GATEWAY])))
+ senderr(error);
+
+ /*
+ * If they tried to change things but didn't specify
+ * the required gateway, then just use the old one.
+ * This can happen if the user tries to change the
+ * flags on the default route without changing the
+ * default gateway. Changing flags still doesn't work.
+ */
+ if ((rt->rt_flags & RTF_GATEWAY) && !info.rti_info[RTAX_GATEWAY])
+ info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
+
+ /* new gateway could require new ifaddr, ifp;
+ flags may also be different; ifp may be specified
+ by ll sockaddr when protocol address is ambiguous */
+ if (info.rti_info[RTAX_IFP] && (ifa = ifa_ifwithnet(info.rti_info[RTAX_IFP])) &&
+ (ifp = ifa->ifa_ifp) && (info.rti_info[RTAX_IFA] || info.rti_info[RTAX_GATEWAY]))
+ ifa = ifaof_ifpforaddr(info.rti_info[RTAX_IFA] ? info.rti_info[RTAX_IFA] : info.rti_info[RTAX_GATEWAY],
+ ifp);
+ else if ((info.rti_info[RTAX_IFA] && (ifa = ifa_ifwithaddr(info.rti_info[RTAX_IFA]))) ||
+ (info.rti_info[RTAX_GATEWAY] && (ifa = ifa_ifwithroute(rt->rt_flags,
+ rt_key(rt), info.rti_info[RTAX_GATEWAY]))))
+ ifp = ifa->ifa_ifp;
+ if (ifa) {
+ struct ifaddr *oifa = rt->rt_ifa;
+ if (oifa != ifa) {
+ if (oifa && oifa->ifa_rtrequest)
+ oifa->ifa_rtrequest(RTM_DELETE,
+ rt, info.rti_info[RTAX_GATEWAY]);
+ IFAFREE(rt->rt_ifa);
+ rt->rt_ifa = ifa;
+ ifa->ifa_refcnt++;
+ rt->rt_ifp = ifp;
+ }
+ }
+ rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
+ &rt->rt_rmx);
+ if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
+ rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, info.rti_info[RTAX_GATEWAY]);
+ if (info.rti_info[RTAX_GENMASK])
+ rt->rt_genmask = info.rti_info[RTAX_GENMASK];
+ /* FALLTHROUGH */
+ case RTM_LOCK:
+ rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
+ rt->rt_rmx.rmx_locks |=
+ (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
+ break;
+ }
+ break;
+
+ default:
+ senderr(EOPNOTSUPP);
+ }
+
+flush:
+ if (rtm) {
+ if (error)
+ rtm->rtm_errno = error;
+ else
+ rtm->rtm_flags |= RTF_DONE;
+ }
+ if (rt) /* XXX can this be true? */
+ rtfree(rt);
+ {
+ struct rawcb *rp = NULL;
+ /*
+ * Check to see if we don't want our own messages.
+ */
+ if ((so->so_options & SO_USELOOPBACK) == 0) {
+ if (route_cb.any_count <= 1) {
+ if (rtm)
+ Free(rtm);
+ m_freem(m);
+ return (error);
+ }
+ /* There is another listener, so construct message */
+ rp = sotorawcb(so);
+ }
+ if (rtm) {
+ m_copyback(m, 0, rtm->rtm_msglen, (caddr_t)rtm);
+ Free(rtm);
+ }
+ if (rp)
+ rp->rcb_proto.sp_family = 0; /* Avoid us */
+ if (info.rti_info[RTAX_DST])
+ route_proto.sp_protocol = info.rti_info[RTAX_DST]->sa_family;
+ raw_input(m, &route_proto, &route_src, &route_dst);
+ if (rp)
+ rp->rcb_proto.sp_family = PF_ROUTE;
+ }
+ return (error);
+#undef sa_equal
+}
+
+static void
+rt_setmetrics(u_long which, const struct rt_metrics *in,
+ struct rt_metrics *out)
+{
+#define metric(f, e) if (which & (f)) out->e = in->e;
+ metric(RTV_RPIPE, rmx_recvpipe);
+ metric(RTV_SPIPE, rmx_sendpipe);
+ metric(RTV_SSTHRESH, rmx_ssthresh);
+ metric(RTV_RTT, rmx_rtt);
+ metric(RTV_RTTVAR, rmx_rttvar);
+ metric(RTV_HOPCOUNT, rmx_hopcount);
+ metric(RTV_MTU, rmx_mtu);
+ metric(RTV_EXPIRE, rmx_expire);
+#undef metric
+}
+
+#define ROUNDUP(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
+
+
+/*
+ * Extract the addresses of the passed sockaddrs.
+ * Do a little sanity checking so as to avoid bad memory references.
+ * This data is derived straight from userland.
+ */
+static int
+rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
+{
+ struct sockaddr *sa;
+ int i;
+
+ bzero(rtinfo->rti_info, sizeof(rtinfo->rti_info));
+ for (i = 0; i < RTAX_MAX && cp < cplim; i++) {
+ if ((rtinfo->rti_addrs & (1 << i)) == 0)
+ continue;
+ sa = (struct sockaddr *)cp;
+ /*
+ * It won't fit.
+ */
+ if (cp + sa->sa_len > cplim)
+ return (EINVAL);
+ /*
+ * there are no more.. quit now
+ * If there are more bits, they are in error.
+ * I've seen this. route(1) can evidently generate these.
+ * This causes kernel to core dump.
+ * for compatibility, If we see this, point to a safe address.
+ */
+ if (sa->sa_len == 0) {
+ rtinfo->rti_info[i] = &sa_zero;
+ return (0); /* should be EINVAL but for compat */
+ }
+ /* accept it */
+ rtinfo->rti_info[i] = sa;
+ ADVANCE(cp, sa);
+ }
+ return (0);
+}
+
+static struct mbuf *
+rt_msg1(int type, struct rt_addrinfo *rtinfo)
+{
+ struct rt_msghdr *rtm;
+ struct mbuf *m;
+ int i;
+ struct sockaddr *sa;
+ int len, dlen;
+
+ m = m_gethdr(M_DONTWAIT, MT_DATA);
+ if (m == 0)
+ return (m);
+ switch (type) {
+
+ case RTM_DELADDR:
+ case RTM_NEWADDR:
+ len = sizeof(struct ifa_msghdr);
+ break;
+
+ case RTM_IFINFO:
+ len = sizeof(struct if_msghdr);
+ break;
+
+ default:
+ len = sizeof(struct rt_msghdr);
+ }
+ if (len > MHLEN)
+ panic("rt_msg1");
+ m->m_pkthdr.len = m->m_len = len;
+ m->m_pkthdr.rcvif = NULL;
+ rtm = mtod(m, struct rt_msghdr *);
+ bzero((caddr_t)rtm, len);
+ for (i = 0; i < RTAX_MAX; i++) {
+ if ((sa = rtinfo->rti_info[i]) == NULL)
+ continue;
+ rtinfo->rti_addrs |= (1 << i);
+ dlen = ROUNDUP(sa->sa_len);
+ m_copyback(m, len, dlen, (caddr_t)sa);
+ len += dlen;
+ }
+ if (m->m_pkthdr.len != len) {
+ m_freem(m);
+ return (NULL);
+ }
+ rtm->rtm_msglen = len;
+ rtm->rtm_version = RTM_VERSION;
+ rtm->rtm_type = type;
+ return (m);
+}
+
+static int
+rt_msg2(int type, struct rt_addrinfo *rtinfo, caddr_t cp, struct walkarg *w)
+{
+ int i;
+ int len, dlen, second_time = 0;
+ caddr_t cp0;
+
+ rtinfo->rti_addrs = 0;
+again:
+ switch (type) {
+
+ case RTM_DELADDR:
+ case RTM_NEWADDR:
+ len = sizeof(struct ifa_msghdr);
+ break;
+
+ case RTM_IFINFO:
+ len = sizeof(struct if_msghdr);
+ break;
+
+ default:
+ len = sizeof(struct rt_msghdr);
+ }
+ cp0 = cp;
+ if (cp0)
+ cp += len;
+ for (i = 0; i < RTAX_MAX; i++) {
+ struct sockaddr *sa;
+
+ if ((sa = rtinfo->rti_info[i]) == NULL)
+ continue;
+ rtinfo->rti_addrs |= (1 << i);
+ dlen = ROUNDUP(sa->sa_len);
+ if (cp) {
+ bcopy((caddr_t)sa, cp, (unsigned)dlen);
+ cp += dlen;
+ }
+ len += dlen;
+ }
+ if (cp == NULL && w != NULL && !second_time) {
+ struct walkarg *rw = w;
+
+ if (rw->w_req) {
+ if (rw->w_tmemsize < len) {
+ if (rw->w_tmem)
+ free(rw->w_tmem, M_RTABLE);
+ rw->w_tmem = (caddr_t)
+ malloc(len, M_RTABLE, M_NOWAIT);
+ if (rw->w_tmem)
+ rw->w_tmemsize = len;
+ }
+ if (rw->w_tmem) {
+ cp = rw->w_tmem;
+ second_time = 1;
+ goto again;
+ }
+ }
+ }
+ if (cp) {
+ struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
+
+ rtm->rtm_version = RTM_VERSION;
+ rtm->rtm_type = type;
+ rtm->rtm_msglen = len;
+ }
+ return (len);
+}
+
+/*
+ * This routine is called to generate a message from the routing
+ * socket indicating that a redirect has occured, a routing lookup
+ * has failed, or that a protocol has detected timeouts to a particular
+ * destination.
+ */
+void
+rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
+{
+ struct rt_msghdr *rtm;
+ struct mbuf *m;
+ struct sockaddr *sa = rtinfo->rti_info[RTAX_DST];
+
+ if (route_cb.any_count == 0)
+ return;
+ m = rt_msg1(type, rtinfo);
+ if (m == NULL)
+ return;
+ rtm = mtod(m, struct rt_msghdr *);
+ rtm->rtm_flags = RTF_DONE | flags;
+ rtm->rtm_errno = error;
+ rtm->rtm_addrs = rtinfo->rti_addrs;
+ route_proto.sp_protocol = sa ? sa->sa_family : 0;
+ raw_input(m, &route_proto, &route_src, &route_dst);
+}
+
+/*
+ * This routine is called to generate a message from the routing
+ * socket indicating that the status of a network interface has changed.
+ */
+void
+rt_ifmsg(struct ifnet *ifp)
+{
+ struct if_msghdr *ifm;
+ struct mbuf *m;
+ struct rt_addrinfo info;
+
+ if (route_cb.any_count == 0)
+ return;
+ bzero((caddr_t)&info, sizeof(info));
+ m = rt_msg1(RTM_IFINFO, &info);
+ if (m == NULL)
+ return;
+ ifm = mtod(m, struct if_msghdr *);
+ ifm->ifm_index = ifp->if_index;
+ ifm->ifm_flags = ifp->if_flags;
+ ifm->ifm_data = ifp->if_data;
+ ifm->ifm_addrs = 0;
+ route_proto.sp_protocol = 0;
+ raw_input(m, &route_proto, &route_src, &route_dst);
+}
+
+/*
+ * This is called to generate messages from the routing socket
+ * indicating a network interface has had addresses associated with it.
+ * if we ever reverse the logic and replace messages TO the routing
+ * socket indicate a request to configure interfaces, then it will
+ * be unnecessary as the routing socket will automatically generate
+ * copies of it.
+ */
+void
+rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
+{
+ struct rt_addrinfo info;
+ struct sockaddr *sa = NULL;
+ int pass;
+ struct mbuf *m = NULL;
+ struct ifnet *ifp = ifa->ifa_ifp;
+
+ if (route_cb.any_count == 0)
+ return;
+ for (pass = 1; pass < 3; pass++) {
+ bzero((caddr_t)&info, sizeof(info));
+ if ((cmd == RTM_ADD && pass == 1) ||
+ (cmd == RTM_DELETE && pass == 2)) {
+ struct ifa_msghdr *ifam;
+ int ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR;
+
+ info.rti_info[RTAX_IFA] = sa = ifa->ifa_addr;
+ info.rti_info[RTAX_IFP] = ifp->if_addrlist->ifa_addr;
+ info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
+ info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
+ if ((m = rt_msg1(ncmd, &info)) == NULL)
+ continue;
+ ifam = mtod(m, struct ifa_msghdr *);
+ ifam->ifam_index = ifp->if_index;
+ ifam->ifam_metric = ifa->ifa_metric;
+ ifam->ifam_flags = ifa->ifa_flags;
+ ifam->ifam_addrs = info.rti_addrs;
+ }
+ if ((cmd == RTM_ADD && pass == 2) ||
+ (cmd == RTM_DELETE && pass == 1)) {
+ struct rt_msghdr *rtm;
+
+ if (rt == NULL)
+ continue;
+ info.rti_info[RTAX_NETMASK] = rt_mask(rt);
+ info.rti_info[RTAX_DST] = sa = rt_key(rt);
+ info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
+ if ((m = rt_msg1(cmd, &info)) == NULL)
+ continue;
+ rtm = mtod(m, struct rt_msghdr *);
+ rtm->rtm_index = ifp->if_index;
+ rtm->rtm_flags |= rt->rt_flags;
+ rtm->rtm_errno = error;
+ rtm->rtm_addrs = info.rti_addrs;
+ }
+ route_proto.sp_protocol = sa ? sa->sa_family : 0;
+ raw_input(m, &route_proto, &route_src, &route_dst);
+ }
+}
+
+
+/*
+ * This is used in dumping the kernel table via sysctl().
+ */
+int
+sysctl_dumpentry(struct radix_node *rn, void *vw)
+{
+ struct walkarg *w = vw;
+ struct rtentry *rt = (struct rtentry *)rn;
+ int error = 0, size;
+ struct rt_addrinfo info;
+
+ if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
+ return 0;
+ bzero((caddr_t)&info, sizeof(info));
+ info.rti_info[RTAX_DST] = rt_key(rt);
+ info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
+ info.rti_info[RTAX_NETMASK] = rt_mask(rt);
+ info.rti_info[RTAX_GENMASK] = rt->rt_genmask;
+ size = rt_msg2(RTM_GET, &info, NULL, w);
+ if (w->w_req && w->w_tmem) {
+ struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
+
+ rtm->rtm_flags = rt->rt_flags;
+ rtm->rtm_use = rt->rt_use;
+ rtm->rtm_rmx = rt->rt_rmx;
+ rtm->rtm_index = rt->rt_ifp->if_index;
+ rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
+ rtm->rtm_addrs = info.rti_addrs;
+ error = SYSCTL_OUT(w->w_req, (caddr_t)rtm, size);
+ return (error);
+ }
+ return (error);
+}
+
+int
+sysctl_iflist(int af, struct walkarg *w)
+{
+ struct ifnet *ifp;
+ struct ifaddr *ifa;
+ struct rt_addrinfo info;
+ int len, error = 0;
+
+ bzero((caddr_t)&info, sizeof(info));
+ for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+ if (w->w_arg && w->w_arg != ifp->if_index)
+ continue;
+ ifa = ifp->if_addrlist;
+ info.rti_info[RTAX_IFP] = ifa->ifa_addr;
+ len = rt_msg2(RTM_IFINFO, &info, (caddr_t)0, w);
+ info.rti_info[RTAX_IFP] = 0;
+ if (w->w_req && w->w_tmem) {
+ struct if_msghdr *ifm;
+
+ ifm = (struct if_msghdr *)w->w_tmem;
+ ifm->ifm_index = ifp->if_index;
+ ifm->ifm_flags = ifp->if_flags;
+ ifm->ifm_data = ifp->if_data;
+ ifm->ifm_addrs = info.rti_addrs;
+ error = SYSCTL_OUT(w->w_req,(caddr_t)ifm, len);
+ if (error)
+ return (error);
+ }
+ while ((ifa = ifa->ifa_next) != 0) {
+ if (af && af != ifa->ifa_addr->sa_family)
+ continue;
+ info.rti_info[RTAX_IFA] = ifa->ifa_addr;
+ info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
+ info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
+ len = rt_msg2(RTM_NEWADDR, &info, NULL, w);
+ if (w->w_req && w->w_tmem) {
+ struct ifa_msghdr *ifam;
+
+ ifam = (struct ifa_msghdr *)w->w_tmem;
+ ifam->ifam_index = ifa->ifa_ifp->if_index;
+ ifam->ifam_flags = ifa->ifa_flags;
+ ifam->ifam_metric = ifa->ifa_metric;
+ ifam->ifam_addrs = info.rti_addrs;
+ error = SYSCTL_OUT(w->w_req, w->w_tmem, len);
+ if (error)
+ return (error);
+ }
+ }
+ info.rti_info[RTAX_IFA] = info.rti_info[RTAX_NETMASK] = info.rti_info[RTAX_BRD] = 0;
+ }
+ return (0);
+}
+
+static int
+sysctl_rtsock(SYSCTL_HANDLER_ARGS)
+{
+ int *name = (int *)arg1;
+ u_int namelen = arg2;
+ struct radix_node_head *rnh;
+ int i, s, error = EINVAL;
+ u_char af;
+ struct walkarg w;
+
+ name ++;
+ namelen--;
+ if (req->newptr)
+ return (EPERM);
+ if (namelen != 3)
+ return (EINVAL);
+ af = name[0];
+ Bzero(&w, sizeof(w));
+ w.w_op = name[1];
+ w.w_arg = name[2];
+ w.w_req = req;
+
+ s = splnet();
+ switch (w.w_op) {
+
+ case NET_RT_DUMP:
+ case NET_RT_FLAGS:
+ for (i = 1; i <= AF_MAX; i++)
+ if ((rnh = rt_tables[i]) && (af == 0 || af == i) &&
+ (error = rnh->rnh_walktree(rnh,
+ sysctl_dumpentry, &w)))
+ break;
+ break;
+
+ case NET_RT_IFLIST:
+ error = sysctl_iflist(af, &w);
+ }
+ splx(s);
+ if (w.w_tmem)
+ free(w.w_tmem, M_RTABLE);
+ return (error);
+}
+
+SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsock,"");
+
+/*
+ * Definitions of protocols supported in the ROUTE domain.
+ */
+
+extern struct domain routedomain; /* or at least forward */
+
+static struct protosw routesw[] = {
+{ SOCK_RAW, &routedomain, 0, PR_ATOMIC|PR_ADDR,
+ 0, route_output, raw_ctlinput, 0,
+ route_usrreq,
+ raw_init, NULL, NULL, NULL,
+ NULL
+}
+};
+
+struct domain routedomain =
+ { PF_ROUTE, "route", route_init, 0, 0,
+ routesw, &routesw[sizeof(routesw)/sizeof(routesw[0])],
+ NULL, NULL, 0, 0 };
+
+DOMAIN_SET(route);
diff --git a/cpukit/libnetworking/net/slcompress.c b/cpukit/libnetworking/net/slcompress.c
new file mode 100644
index 0000000000..9606c9e3c2
--- /dev/null
+++ b/cpukit/libnetworking/net/slcompress.c
@@ -0,0 +1,601 @@
+/*-
+ * Copyright (c) 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)slcompress.c 8.2 (Berkeley) 4/16/94
+ * $FreeBSD: src/sys/net/slcompress.c,v 1.19 2004/04/07 20:46:12 imp Exp $
+ */
+
+/*
+ * Routines to compress and uncompess tcp packets (for transmission
+ * over low speed serial lines.
+ *
+ * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
+ * - Initial distribution.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+
+#include <sys/param.h>
+#include <sys/mbuf.h>
+#include <sys/systm.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+
+#include <net/slcompress.h>
+
+#ifndef SL_NO_STATS
+#define INCR(counter) ++comp->counter;
+#else
+#define INCR(counter)
+#endif
+
+#define BCMP(p1, p2, n) bcmp((void *)(p1), (void *)(p2), (int)(n))
+#define BCOPY(p1, p2, n) bcopy((void *)(p1), (void *)(p2), (int)(n))
+
+void
+sl_compress_init(struct slcompress *comp, int max_state)
+{
+ register u_int i;
+ register struct cstate *tstate = comp->tstate;
+
+ if (max_state == -1) {
+ max_state = MAX_STATES - 1;
+ bzero((char *)comp, sizeof(*comp));
+ } else {
+ /* Don't reset statistics */
+ bzero((char *)comp->tstate, sizeof(comp->tstate));
+ bzero((char *)comp->rstate, sizeof(comp->rstate));
+ }
+ for (i = max_state; i > 0; --i) {
+ tstate[i].cs_id = i;
+ tstate[i].cs_next = &tstate[i - 1];
+ }
+ tstate[0].cs_next = &tstate[max_state];
+ tstate[0].cs_id = 0;
+ comp->last_cs = &tstate[0];
+ comp->last_recv = 255;
+ comp->last_xmit = 255;
+ comp->flags = SLF_TOSS;
+}
+
+
+/* ENCODE encodes a number that is known to be non-zero. ENCODEZ
+ * checks for zero (since zero has to be encoded in the long, 3 byte
+ * form).
+ */
+#define ENCODE(n) { \
+ if ((u_int16_t)(n) >= 256) { \
+ *cp++ = 0; \
+ cp[1] = (n); \
+ cp[0] = (n) >> 8; \
+ cp += 2; \
+ } else { \
+ *cp++ = (n); \
+ } \
+}
+#define ENCODEZ(n) { \
+ if ((u_int16_t)(n) >= 256 || (u_int16_t)(n) == 0) { \
+ *cp++ = 0; \
+ cp[1] = (n); \
+ cp[0] = (n) >> 8; \
+ cp += 2; \
+ } else { \
+ *cp++ = (n); \
+ } \
+}
+
+#define DECODEL(f) { \
+ if (*cp == 0) {\
+ (f) = htonl(ntohl(f) + ((cp[1] << 8) | cp[2])); \
+ cp += 3; \
+ } else { \
+ (f) = htonl(ntohl(f) + (u_int32_t)*cp++); \
+ } \
+}
+
+#define DECODES(f) { \
+ if (*cp == 0) {\
+ (f) = htons(ntohs(f) + ((cp[1] << 8) | cp[2])); \
+ cp += 3; \
+ } else { \
+ (f) = htons(ntohs(f) + (u_int32_t)*cp++); \
+ } \
+}
+
+#define DECODEU(f) { \
+ if (*cp == 0) {\
+ (f) = htons((cp[1] << 8) | cp[2]); \
+ cp += 3; \
+ } else { \
+ (f) = htons((u_int32_t)*cp++); \
+ } \
+}
+
+/*
+ * Attempt to compress an outgoing TCP packet and return the type of
+ * the result. The caller must have already verified that the protocol
+ * is TCP. The first mbuf must contain the complete IP and TCP headers,
+ * and "ip" must be == mtod(m, struct ip *). "comp" supplies the
+ * compression state, and "compress_cid" tells us whether it is OK
+ * to leave out the CID field when feasible.
+ *
+ * The caller is responsible for adjusting m->m_pkthdr.len upon return,
+ * if m is an M_PKTHDR mbuf.
+ */
+u_int
+sl_compress_tcp(struct mbuf *m, struct ip *ip, struct slcompress *comp,
+ int compress_cid)
+{
+ register struct cstate *cs = comp->last_cs->cs_next;
+ register u_int hlen = ip->ip_hl;
+ register struct tcphdr *oth;
+ register struct tcphdr *th;
+ register u_int deltaS, deltaA;
+ register u_int changes = 0;
+ u_char new_seq[16];
+ register u_char *cp = new_seq;
+
+ /*
+ * Bail if this is an IP fragment or if the TCP packet isn't
+ * `compressible' (i.e., ACK isn't set or some other control bit is
+ * set). (We assume that the caller has already made sure the
+ * packet is IP proto TCP).
+ */
+ if ((ip->ip_off & htons(0x3fff)) || m->m_len < 40)
+ return (TYPE_IP);
+
+ th = (struct tcphdr *)&((int32_t *)ip)[hlen];
+ if ((th->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_ACK)) != TH_ACK)
+ return (TYPE_IP);
+ /*
+ * Packet is compressible -- we're going to send either a
+ * COMPRESSED_TCP or UNCOMPRESSED_TCP packet. Either way we need
+ * to locate (or create) the connection state. Special case the
+ * most recently used connection since it's most likely to be used
+ * again & we don't have to do any reordering if it's used.
+ */
+ INCR(sls_packets)
+ if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr ||
+ ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr ||
+ *(int32_t *)th != ((int32_t *)&cs->cs_ip)[cs->cs_ip.ip_hl]) {
+ /*
+ * Wasn't the first -- search for it.
+ *
+ * States are kept in a circularly linked list with
+ * last_cs pointing to the end of the list. The
+ * list is kept in lru order by moving a state to the
+ * head of the list whenever it is referenced. Since
+ * the list is short and, empirically, the connection
+ * we want is almost always near the front, we locate
+ * states via linear search. If we don't find a state
+ * for the datagram, the oldest state is (re-)used.
+ */
+ register struct cstate *lcs;
+ register struct cstate *lastcs = comp->last_cs;
+
+ do {
+ lcs = cs; cs = cs->cs_next;
+ INCR(sls_searches)
+ if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
+ && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
+ && *(int32_t *)th ==
+ ((int32_t *)&cs->cs_ip)[cs->cs_ip.ip_hl])
+ goto found;
+ } while (cs != lastcs);
+
+ /*
+ * Didn't find it -- re-use oldest cstate. Send an
+ * uncompressed packet that tells the other side what
+ * connection number we're using for this conversation.
+ * Note that since the state list is circular, the oldest
+ * state points to the newest and we only need to set
+ * last_cs to update the lru linkage.
+ */
+ INCR(sls_misses)
+ comp->last_cs = lcs;
+ hlen += th->th_off;
+ hlen <<= 2;
+ if (hlen > m->m_len)
+ return TYPE_IP;
+ goto uncompressed;
+
+ found:
+ /*
+ * Found it -- move to the front on the connection list.
+ */
+ if (cs == lastcs)
+ comp->last_cs = lcs;
+ else {
+ lcs->cs_next = cs->cs_next;
+ cs->cs_next = lastcs->cs_next;
+ lastcs->cs_next = cs;
+ }
+ }
+
+ /*
+ * Make sure that only what we expect to change changed. The first
+ * line of the `if' checks the IP protocol version, header length &
+ * type of service. The 2nd line checks the "Don't fragment" bit.
+ * The 3rd line checks the time-to-live and protocol (the protocol
+ * check is unnecessary but costless). The 4th line checks the TCP
+ * header length. The 5th line checks IP options, if any. The 6th
+ * line checks TCP options, if any. If any of these things are
+ * different between the previous & current datagram, we send the
+ * current datagram `uncompressed'.
+ */
+ oth = (struct tcphdr *)&((int32_t *)&cs->cs_ip)[hlen];
+ deltaS = hlen;
+ hlen += th->th_off;
+ hlen <<= 2;
+ if (hlen > m->m_len)
+ return TYPE_IP;
+
+ if (((u_int16_t *)ip)[0] != ((u_int16_t *)&cs->cs_ip)[0] ||
+ ((u_int16_t *)ip)[3] != ((u_int16_t *)&cs->cs_ip)[3] ||
+ ((u_int16_t *)ip)[4] != ((u_int16_t *)&cs->cs_ip)[4] ||
+ th->th_off != oth->th_off ||
+ (deltaS > 5 &&
+ BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
+ (th->th_off > 5 &&
+ BCMP(th + 1, oth + 1, (th->th_off - 5) << 2)))
+ goto uncompressed;
+
+ /*
+ * Figure out which of the changing fields changed. The
+ * receiver expects changes in the order: urgent, window,
+ * ack, seq (the order minimizes the number of temporaries
+ * needed in this section of code).
+ */
+ if (th->th_flags & TH_URG) {
+ deltaS = ntohs(th->th_urp);
+ ENCODEZ(deltaS);
+ changes |= NEW_U;
+ } else if (th->th_urp != oth->th_urp)
+ /* argh! URG not set but urp changed -- a sensible
+ * implementation should never do this but RFC793
+ * doesn't prohibit the change so we have to deal
+ * with it. */
+ goto uncompressed;
+
+ deltaS = (u_int16_t)(ntohs(th->th_win) - ntohs(oth->th_win));
+ if (deltaS) {
+ ENCODE(deltaS);
+ changes |= NEW_W;
+ }
+
+ deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack);
+ if (deltaA) {
+ if (deltaA > 0xffff)
+ goto uncompressed;
+ ENCODE(deltaA);
+ changes |= NEW_A;
+ }
+
+ deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq);
+ if (deltaS) {
+ if (deltaS > 0xffff)
+ goto uncompressed;
+ ENCODE(deltaS);
+ changes |= NEW_S;
+ }
+
+ switch(changes) {
+
+ case 0:
+ /*
+ * Nothing changed. If this packet contains data and the
+ * last one didn't, this is probably a data packet following
+ * an ack (normal on an interactive connection) and we send
+ * it compressed. Otherwise it's probably a retransmit,
+ * retransmitted ack or window probe. Send it uncompressed
+ * in case the other side missed the compressed version.
+ */
+ if (ip->ip_len != cs->cs_ip.ip_len &&
+ ntohs(cs->cs_ip.ip_len) == hlen)
+ break;
+
+ /* FALLTHROUGH */
+
+ case SPECIAL_I:
+ case SPECIAL_D:
+ /*
+ * actual changes match one of our special case encodings --
+ * send packet uncompressed.
+ */
+ goto uncompressed;
+
+ case NEW_S|NEW_A:
+ if (deltaS == deltaA &&
+ deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
+ /* special case for echoed terminal traffic */
+ changes = SPECIAL_I;
+ cp = new_seq;
+ }
+ break;
+
+ case NEW_S:
+ if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
+ /* special case for data xfer */
+ changes = SPECIAL_D;
+ cp = new_seq;
+ }
+ break;
+ }
+
+ deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
+ if (deltaS != 1) {
+ ENCODEZ(deltaS);
+ changes |= NEW_I;
+ }
+ if (th->th_flags & TH_PUSH)
+ changes |= TCP_PUSH_BIT;
+ /*
+ * Grab the cksum before we overwrite it below. Then update our
+ * state with this packet's header.
+ */
+ deltaA = ntohs(th->th_sum);
+ BCOPY(ip, &cs->cs_ip, hlen);
+
+ /*
+ * We want to use the original packet as our compressed packet.
+ * (cp - new_seq) is the number of bytes we need for compressed
+ * sequence numbers. In addition we need one byte for the change
+ * mask, one for the connection id and two for the tcp checksum.
+ * So, (cp - new_seq) + 4 bytes of header are needed. hlen is how
+ * many bytes of the original packet to toss so subtract the two to
+ * get the new packet size.
+ */
+ deltaS = cp - new_seq;
+ cp = (u_char *)ip;
+ if (compress_cid == 0 || comp->last_xmit != cs->cs_id) {
+ comp->last_xmit = cs->cs_id;
+ hlen -= deltaS + 4;
+ cp += hlen;
+ *cp++ = changes | NEW_C;
+ *cp++ = cs->cs_id;
+ } else {
+ hlen -= deltaS + 3;
+ cp += hlen;
+ *cp++ = changes;
+ }
+ m->m_len -= hlen;
+ m->m_data += hlen;
+ *cp++ = deltaA >> 8;
+ *cp++ = deltaA;
+ BCOPY(new_seq, cp, deltaS);
+ INCR(sls_compressed)
+ return (TYPE_COMPRESSED_TCP);
+
+ /*
+ * Update connection state cs & send uncompressed packet ('uncompressed'
+ * means a regular ip/tcp packet but with the 'conversation id' we hope
+ * to use on future compressed packets in the protocol field).
+ */
+uncompressed:
+ BCOPY(ip, &cs->cs_ip, hlen);
+ ip->ip_p = cs->cs_id;
+ comp->last_xmit = cs->cs_id;
+ return (TYPE_UNCOMPRESSED_TCP);
+}
+
+
+int
+sl_uncompress_tcp(u_char **bufp, int len, u_int type, struct slcompress *comp)
+{
+ u_char *hdr, *cp;
+ u_int hlen;
+ int vjlen;
+
+ cp = bufp? *bufp: NULL;
+ vjlen = sl_uncompress_tcp_core(cp, len, len, type, comp, &hdr, &hlen);
+ if (vjlen < 0)
+ return (0); /* error */
+ if (vjlen == 0)
+ return (len); /* was uncompressed already */
+
+ cp += vjlen;
+ len -= vjlen;
+
+ /*
+ * At this point, cp points to the first byte of data in the
+ * packet. If we're not aligned on a 4-byte boundary, copy the
+ * data down so the ip & tcp headers will be aligned. Then back up
+ * cp by the tcp/ip header length to make room for the reconstructed
+ * header (we assume the packet we were handed has enough space to
+ * prepend 128 bytes of header).
+ */
+ if ((intptr_t)cp & 3) {
+ if (len > 0)
+ BCOPY(cp, ((intptr_t)cp &~ 3), len);
+ cp = (u_char *)((intptr_t)cp &~ 3);
+ }
+ cp -= hlen;
+ len += hlen;
+ BCOPY(hdr, cp, hlen);
+
+ *bufp = cp;
+ return (len);
+}
+
+/*
+ * Uncompress a packet of total length total_len. The first buflen
+ * bytes are at buf; this must include the entire (compressed or
+ * uncompressed) TCP/IP header. This procedure returns the length
+ * of the VJ header, with a pointer to the uncompressed IP header
+ * in *hdrp and its length in *hlenp.
+ */
+int
+sl_uncompress_tcp_core(u_char *buf, int buflen, int total_len,
+ u_int type, struct slcompress *comp,
+ u_char **hdrp, u_int *hlenp)
+{
+ register u_char *cp;
+ register uint32_t hlen, changes;
+ register struct tcphdr *th;
+ register struct cstate *cs;
+ register struct ip *ip;
+ register u_int16_t *bp;
+ register u_int vjlen;
+
+ switch (type) {
+
+ case TYPE_UNCOMPRESSED_TCP:
+ ip = (struct ip *) buf;
+ if (ip->ip_p >= MAX_STATES)
+ goto bad;
+ cs = &comp->rstate[comp->last_recv = ip->ip_p];
+ comp->flags &=~ SLF_TOSS;
+ ip->ip_p = IPPROTO_TCP;
+ /*
+ * Calculate the size of the TCP/IP header and make sure that
+ * we don't overflow the space we have available for it.
+ */
+ hlen = ip->ip_hl << 2;
+ if (hlen + sizeof(struct tcphdr) > buflen)
+ goto bad;
+ hlen += ((struct tcphdr *)&((char *)ip)[hlen])->th_off << 2;
+ if (hlen > MAX_HDR || hlen > buflen)
+ goto bad;
+ BCOPY(ip, &cs->cs_ip, hlen);
+ cs->cs_hlen = hlen;
+ INCR(sls_uncompressedin)
+ *hdrp = (u_char *) &cs->cs_ip;
+ *hlenp = hlen;
+ return (0);
+
+ default:
+ goto bad;
+
+ case TYPE_COMPRESSED_TCP:
+ break;
+ }
+ /* We've got a compressed packet. */
+ INCR(sls_compressedin)
+ cp = buf;
+ changes = *cp++;
+ if (changes & NEW_C) {
+ /* Make sure the state index is in range, then grab the state.
+ * If we have a good state index, clear the 'discard' flag. */
+ if (*cp >= MAX_STATES)
+ goto bad;
+
+ comp->flags &=~ SLF_TOSS;
+ comp->last_recv = *cp++;
+ } else {
+ /* this packet has an implicit state index. If we've
+ * had a line error since the last time we got an
+ * explicit state index, we have to toss the packet. */
+ if (comp->flags & SLF_TOSS) {
+ INCR(sls_tossed)
+ return (-1);
+ }
+ }
+ cs = &comp->rstate[comp->last_recv];
+ hlen = cs->cs_ip.ip_hl << 2;
+ th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen];
+ th->th_sum = htons((*cp << 8) | cp[1]);
+ cp += 2;
+ if (changes & TCP_PUSH_BIT)
+ th->th_flags |= TH_PUSH;
+ else
+ th->th_flags &=~ TH_PUSH;
+
+ switch (changes & SPECIALS_MASK) {
+ case SPECIAL_I:
+ {
+ register u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
+ th->th_ack = htonl(ntohl(th->th_ack) + i);
+ th->th_seq = htonl(ntohl(th->th_seq) + i);
+ }
+ break;
+
+ case SPECIAL_D:
+ th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
+ - cs->cs_hlen);
+ break;
+
+ default:
+ if (changes & NEW_U) {
+ th->th_flags |= TH_URG;
+ DECODEU(th->th_urp)
+ } else
+ th->th_flags &=~ TH_URG;
+ if (changes & NEW_W)
+ DECODES(th->th_win)
+ if (changes & NEW_A)
+ DECODEL(th->th_ack)
+ if (changes & NEW_S)
+ DECODEL(th->th_seq)
+ break;
+ }
+ if (changes & NEW_I) {
+ DECODES(cs->cs_ip.ip_id)
+ } else
+ cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
+
+ /*
+ * At this point, cp points to the first byte of data in the
+ * packet. Fill in the IP total length and update the IP
+ * header checksum.
+ */
+ vjlen = cp - buf;
+ buflen -= vjlen;
+ if (buflen < 0)
+ /* we must have dropped some characters (crc should detect
+ * this but the old slip framing won't) */
+ goto bad;
+
+ total_len += cs->cs_hlen - vjlen;
+ cs->cs_ip.ip_len = htons(total_len);
+
+ /* recompute the ip header checksum */
+ bp = (u_int16_t *) &cs->cs_ip;
+ cs->cs_ip.ip_sum = 0;
+ for (changes = 0; hlen > 0; hlen -= 2)
+ changes += *bp++;
+ changes = (changes & 0xffff) + (changes >> 16);
+ changes = (changes & 0xffff) + (changes >> 16);
+ cs->cs_ip.ip_sum = ~ changes;
+
+ *hdrp = (u_char *) &cs->cs_ip;
+ *hlenp = cs->cs_hlen;
+ return vjlen;
+
+bad:
+ comp->flags |= SLF_TOSS;
+ INCR(sls_errorin)
+ return (-1);
+}
diff --git a/cpukit/libnetworking/net/slcompress.h b/cpukit/libnetworking/net/slcompress.h
new file mode 100644
index 0000000000..e1dd9b0c3f
--- /dev/null
+++ b/cpukit/libnetworking/net/slcompress.h
@@ -0,0 +1,157 @@
+/*
+ * Definitions for tcp compression routines.
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
+ * - Initial distribution.
+ * $FreeBSD: src/sys/net/slcompress.h,v 1.19 2005/01/07 01:45:35 imp Exp $
+ */
+
+#ifndef _NET_SLCOMPRESS_H_
+#define _NET_SLCOMPRESS_H_
+
+#define MAX_STATES 16 /* must be > 2 and < 256 */
+#define MAX_HDR 128
+
+/*
+ * Compressed packet format:
+ *
+ * The first octet contains the packet type (top 3 bits), TCP
+ * 'push' bit, and flags that indicate which of the 4 TCP sequence
+ * numbers have changed (bottom 5 bits). The next octet is a
+ * conversation number that associates a saved IP/TCP header with
+ * the compressed packet. The next two octets are the TCP checksum
+ * from the original datagram. The next 0 to 15 octets are
+ * sequence number changes, one change per bit set in the header
+ * (there may be no changes and there are two special cases where
+ * the receiver implicitly knows what changed -- see below).
+ *
+ * There are 5 numbers which can change (they are always inserted
+ * in the following order): TCP urgent pointer, window,
+ * acknowledgement, sequence number and IP ID. (The urgent pointer
+ * is different from the others in that its value is sent, not the
+ * change in value.) Since typical use of SLIP links is biased
+ * toward small packets (see comments on MTU/MSS below), changes
+ * use a variable length coding with one octet for numbers in the
+ * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
+ * range 256 - 65535 or 0. (If the change in sequence number or
+ * ack is more than 65535, an uncompressed packet is sent.)
+ */
+
+/*
+ * Packet types (must not conflict with IP protocol version)
+ *
+ * The top nibble of the first octet is the packet type. There are
+ * three possible types: IP (not proto TCP or tcp with one of the
+ * control flags set); uncompressed TCP (a normal IP/TCP packet but
+ * with the 8-bit protocol field replaced by an 8-bit connection id --
+ * this type of packet syncs the sender & receiver); and compressed
+ * TCP (described above).
+ *
+ * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
+ * is logically part of the 4-bit "changes" field that follows. Top
+ * three bits are actual packet type. For backward compatibility
+ * and in the interest of conserving bits, numbers are chosen so the
+ * IP protocol version number (4) which normally appears in this nibble
+ * means "IP packet".
+ */
+
+/* packet types */
+#define TYPE_IP 0x40
+#define TYPE_UNCOMPRESSED_TCP 0x70
+#define TYPE_COMPRESSED_TCP 0x80
+#define TYPE_ERROR 0x00
+
+/* Bits in first octet of compressed packet */
+#define NEW_C 0x40 /* flag bits for what changed in a packet */
+#define NEW_I 0x20
+#define NEW_S 0x08
+#define NEW_A 0x04
+#define NEW_W 0x02
+#define NEW_U 0x01
+
+/* reserved, special-case values of above */
+#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
+#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
+#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
+
+#define TCP_PUSH_BIT 0x10
+
+
+/*
+ * "state" data for each active tcp conversation on the wire. This is
+ * basically a copy of the entire IP/TCP header from the last packet
+ * we saw from the conversation together with a small identifier
+ * the transmit & receive ends of the line use to locate saved header.
+ */
+struct cstate {
+ struct cstate *cs_next; /* next most recently used cstate (xmit only) */
+ u_int16_t cs_hlen; /* size of hdr (receive only) */
+ u_char cs_id; /* connection # associated with this state */
+ u_char cs_filler;
+ union {
+ char csu_hdr[MAX_HDR];
+ struct ip csu_ip; /* ip/tcp hdr from most recent packet */
+ } slcs_u;
+};
+#define cs_ip slcs_u.csu_ip
+#define cs_hdr slcs_u.csu_hdr
+
+/*
+ * all the state data for one serial line (we need one of these
+ * per line).
+ */
+struct slcompress {
+ struct cstate *last_cs; /* most recently used tstate */
+ u_char last_recv; /* last rcvd conn. id */
+ u_char last_xmit; /* last sent conn. id */
+ u_int16_t flags;
+#ifndef SL_NO_STATS
+ int sls_packets; /* outbound packets */
+ int sls_compressed; /* outbound compressed packets */
+ int sls_searches; /* searches for connection state */
+ int sls_misses; /* times couldn't find conn. state */
+ int sls_uncompressedin; /* inbound uncompressed packets */
+ int sls_compressedin; /* inbound compressed packets */
+ int sls_errorin; /* inbound unknown type packets */
+ int sls_tossed; /* inbound packets tossed because of error */
+#endif
+ struct cstate tstate[MAX_STATES]; /* xmit connection states */
+ struct cstate rstate[MAX_STATES]; /* receive connection states */
+};
+/* flag values */
+#define SLF_TOSS 1 /* tossing rcvd frames because of input err */
+
+void sl_compress_init(struct slcompress *, int);
+u_int sl_compress_tcp(struct mbuf *, struct ip *, struct slcompress *, int);
+int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *);
+int sl_uncompress_tcp_core(u_char *, int, int, u_int,
+ struct slcompress *, u_char **, u_int *);
+
+#endif /* !_NET_SLCOMPRESS_H_ */
diff --git a/cpukit/libnetworking/netdb.h b/cpukit/libnetworking/netdb.h
new file mode 100644
index 0000000000..8d4c60c5b5
--- /dev/null
+++ b/cpukit/libnetworking/netdb.h
@@ -0,0 +1,198 @@
+/*-
+ * Copyright (c) 1980, 1983, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*
+ * @(#)netdb.h 8.1 (Berkeley) 6/2/93
+ * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
+ * $FreeBSD: src/include/netdb.h,v 1.34 2005/02/14 11:33:11 phantom Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETDB_H_
+#define _NETDB_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <rtems/bsdnet/_types.h>
+
+#ifndef _SOCKLEN_T_DECLARED
+typedef __socklen_t socklen_t;
+#define _SOCKLEN_T_DECLARED
+#endif
+
+#ifndef _PATH_HEQUIV
+# define _PATH_HEQUIV "/etc/hosts.equiv"
+#endif
+#define _PATH_HOSTS "/etc/hosts"
+#define _PATH_NETWORKS "/etc/networks"
+#define _PATH_PROTOCOLS "/etc/protocols"
+#define _PATH_SERVICES "/etc/services"
+
+extern int h_errno;
+
+/*
+ * Structures returned by network data base library. All addresses are
+ * supplied in host order, and returned in network order (suitable for
+ * use in system calls).
+ */
+struct hostent {
+ char *h_name; /* official name of host */
+ char **h_aliases; /* alias list */
+ int h_addrtype; /* host address type */
+ int h_length; /* length of address */
+ char **h_addr_list; /* list of addresses from name server */
+#define h_addr h_addr_list[0] /* address, for backward compatibility */
+};
+
+struct netent {
+ char *n_name; /* official name of net */
+ char **n_aliases; /* alias list */
+ int n_addrtype; /* net address type */
+ uint32_t n_net; /* network # */
+};
+
+struct servent {
+ char *s_name; /* official service name */
+ char **s_aliases; /* alias list */
+ int s_port; /* port # */
+ char *s_proto; /* protocol to use */
+};
+
+struct protoent {
+ char *p_name; /* official protocol name */
+ char **p_aliases; /* alias list */
+ int p_proto; /* protocol # */
+};
+
+/*
+ * Error return codes from gethostbyname() and gethostbyaddr()
+ * (left in h_errno).
+ */
+
+#define NETDB_INTERNAL -1 /* see errno */
+#define NETDB_SUCCESS 0 /* no problem */
+#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
+#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
+#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
+#define NO_DATA 4 /* Valid name, no data record of requested type */
+#define NO_ADDRESS NO_DATA /* no address, look for MX record */
+
+__BEGIN_DECLS
+void endhostent(void);
+void endnetent(void);
+void endprotoent(void);
+void endservent(void);
+struct hostent *gethostbyaddr(const void *, socklen_t, int);
+struct hostent *gethostbyname(const char *);
+struct hostent *gethostbyname2(const char *, int);
+struct hostent *gethostent(void);
+struct netent *getnetbyaddr(uint32_t, int);
+struct netent *getnetbyname(const char *);
+struct netent *getnetent(void);
+struct protoent *getprotobyname(const char *);
+struct protoent *getprotobynumber(int);
+struct protoent *getprotoent(void);
+struct servent *getservbyname(const char *, const char *);
+struct servent *getservbyport(int, const char *);
+struct servent *getservent(void);
+void herror(const char *);
+__const char *hstrerror(int);
+void sethostent(int);
+/* void sethostfile(const char *); */
+void setnetent(int);
+void setprotoent(int);
+void setservent(int);
+
+#ifdef _THREAD_SAFE
+struct hostent* gethostent_r(char* buf, int len);
+int gethostbyname_r(const char* name,
+ struct hostent* result,
+ char *buf,
+ int buflen,
+ struct hostent **RESULT,
+ int *h_errnop) ;
+#endif
+
+/*
+ * PRIVATE functions specific to the FreeBSD implementation
+ */
+
+/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
+void _sethosthtent(int);
+void _endhosthtent(void);
+void _sethostdnsent(int);
+void _endhostdnsent(void);
+void _setnethtent(int);
+void _endnethtent(void);
+void _setnetdnsent(int);
+void _endnetdnsent(void);
+struct hostent * _gethostbyhtname(const char *, int);
+struct hostent * _gethostbydnsname(const char *, int);
+struct hostent * _gethostbynisname(const char *, int);
+struct hostent * _gethostbyhtaddr (const char *, int, int);
+struct hostent * _gethostbydnsaddr(const char *, int, int);
+struct hostent * _gethostbynisaddr(const char *, int, int);
+struct netent * _getnetbyhtname (const char *);
+struct netent * _getnetbydnsname(const char *);
+struct netent * _getnetbynisname(const char *);
+struct netent * _getnetbyhtaddr (unsigned long, int);
+struct netent * _getnetbydnsaddr(unsigned long, int);
+struct netent * _getnetbynisaddr(unsigned long, int);
+void _map_v4v6_address(const char *, char *);
+void _map_v4v6_hostent(struct hostent *, char **, int *len);
+__END_DECLS
+
+#endif /* !_NETDB_H_ */
diff --git a/cpukit/libnetworking/netinet/icmp_var.h b/cpukit/libnetworking/netinet/icmp_var.h
new file mode 100644
index 0000000000..da74e58f98
--- /dev/null
+++ b/cpukit/libnetworking/netinet/icmp_var.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)icmp_var.h 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifndef _NETINET_ICMP_VAR_H_
+#define _NETINET_ICMP_VAR_H_
+
+/*
+ * Variables related to this implementation
+ * of the internet control message protocol.
+ */
+struct icmpstat {
+/* statistics related to icmp packets generated */
+ u_long icps_error; /* # of calls to icmp_error */
+ u_long icps_oldshort; /* no error 'cuz old ip too short */
+ u_long icps_oldicmp; /* no error 'cuz old was icmp */
+ u_long icps_outhist[ICMP_MAXTYPE + 1];
+/* statistics related to input messages processed */
+ u_long icps_badcode; /* icmp_code out of range */
+ u_long icps_tooshort; /* packet < ICMP_MINLEN */
+ u_long icps_checksum; /* bad checksum */
+ u_long icps_badlen; /* calculated bound mismatch */
+ u_long icps_reflect; /* number of responses */
+ u_long icps_inhist[ICMP_MAXTYPE + 1];
+ u_long icps_allecho; /* all echo requests dropped */
+ u_long icps_bmcastecho; /* b/mcast echo requests dropped */
+ u_long icps_bmcasttstamp; /* b/mcast tstamp requests dropped */
+};
+
+/*
+ * Names for ICMP sysctl objects
+ */
+#define ICMPCTL_MASKREPL 1 /* allow replies to netmask requests */
+#define ICMPCTL_STATS 2 /* statistics (read-only) */
+#define ICMPCTL_MAXID 3
+
+#define ICMPCTL_NAMES { \
+ { 0, 0 }, \
+ { "maskrepl", CTLTYPE_INT }, \
+ { "stats", CTLTYPE_STRUCT }, \
+}
+
+#ifdef _KERNEL
+SYSCTL_DECL(_net_inet_icmp);
+extern struct icmpstat icmpstat;
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/netinet/if_ether.c b/cpukit/libnetworking/netinet/if_ether.c
new file mode 100644
index 0000000000..2742c3b678
--- /dev/null
+++ b/cpukit/libnetworking/netinet/if_ether.c
@@ -0,0 +1,642 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_ether.c 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/if_ether.c,v 1.136 2005/03/13 11:23:22 glebius Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * Ethernet address resolution protocol.
+ * TODO:
+ * add "inuse/lock" bit (or ref. count) along with valid bit
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_inet.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/queue.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <net/route.h>
+#include <net/netisr.h>
+
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/if_ether.h>
+
+#define SIN(s) ((struct sockaddr_in *)s)
+#define SDL(s) ((struct sockaddr_dl *)s)
+
+SYSCTL_DECL(_net_link_ether);
+SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
+
+/* timer values */
+static int arpt_prune = (5*60*1); /* walk list every 5 minutes */
+static int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
+static int arpt_down = 20; /* once declared down, don't send for 20 sec */
+
+SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW,
+ &arpt_prune, 0, "");
+SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW,
+ &arpt_keep, 0, "");
+SYSCTL_INT(_net_link_ether_inet, OID_AUTO, host_down_time, CTLFLAG_RW,
+ &arpt_down, 0, "");
+
+#define rt_expire rt_rmx.rmx_expire
+
+struct llinfo_arp {
+ LIST_ENTRY(llinfo_arp) la_le;
+ struct rtentry *la_rt;
+ struct mbuf *la_hold; /* last packet until resolved/timeout */
+ long la_asked; /* last time we QUERIED for this addr */
+#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
+};
+
+static LIST_HEAD(, llinfo_arp) llinfo_arp;
+
+struct ifqueue arpintrq = {0, 0, 0, 50, 0};
+static int arp_inuse, arp_allocated;
+
+static int arp_maxtries = 5;
+static int useloopback = 1; /* use loopback interface for local traffic */
+static int arp_proxyall = 0;
+
+SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW,
+ &arp_maxtries, 0, "");
+SYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW,
+ &useloopback, 0, "");
+SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
+ &arp_proxyall, 0, "");
+
+static void arp_rtrequest(int, struct rtentry *, struct sockaddr *);
+static void arprequest(struct arpcom *, struct in_addr *, struct in_addr *, u_char *);
+void arpintr(void);
+static void arptfree(struct llinfo_arp *);
+static void arptimer(void *);
+static struct llinfo_arp
+ *arplookup(u_long, int, int);
+#ifdef INET
+static void in_arpinput(struct mbuf *);
+#endif
+
+/*
+ * Timeout routine. Age arp_tab entries periodically.
+ */
+/* ARGSUSED */
+static void
+arptimer(void *ignored_arg)
+{
+ int s = splnet();
+ struct llinfo_arp *la, *ola;
+
+ la = llinfo_arp.lh_first;
+ timeout(arptimer, (caddr_t)0, arpt_prune * hz);
+ while ((ola = la) != 0) {
+ register struct rtentry *rt = la->la_rt;
+ la = la->la_le.le_next;
+ if (rt->rt_expire && rt->rt_expire <= rtems_bsdnet_seconds_since_boot())
+ arptfree(ola); /* timer has expired, clear */
+ }
+ splx(s);
+}
+
+/*
+ * Parallel to llc_rtrequest.
+ */
+static void
+arp_rtrequest(int req, struct rtentry *rt, struct sockaddr *sa)
+{
+ struct sockaddr *gate;
+ struct llinfo_arp *la;
+ static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK, 0, 0, 0, 0, 0, { 0 } };
+ static int arpinit_done;
+
+ if (!arpinit_done) {
+ arpinit_done = 1;
+ LIST_INIT(&llinfo_arp);
+ timeout(arptimer, (caddr_t)0, hz);
+ }
+ if (rt->rt_flags & RTF_GATEWAY)
+ return;
+ gate = rt->rt_gateway;
+ la = (struct llinfo_arp *)rt->rt_llinfo;
+ switch (req) {
+
+ case RTM_ADD:
+ /*
+ * XXX: If this is a manually added route to interface
+ * such as older version of routed or gated might provide,
+ * restore cloning bit.
+ */
+ if ((rt->rt_flags & RTF_HOST) == 0 &&
+ rt_mask(rt) != NULL &&
+ SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
+ rt->rt_flags |= RTF_CLONING;
+ if (rt->rt_flags & RTF_CLONING) {
+ /*
+ * Case 1: This route should come from a route to iface.
+ */
+ rt_setgate(rt, rt_key(rt),
+ (struct sockaddr *)&null_sdl);
+ gate = rt->rt_gateway;
+ SDL(gate)->sdl_type = rt->rt_ifp->if_type;
+ SDL(gate)->sdl_index = rt->rt_ifp->if_index;
+ rt->rt_expire = rtems_bsdnet_seconds_since_boot();
+ break;
+ }
+ /* Announce a new entry if requested. */
+ if (rt->rt_flags & RTF_ANNOUNCE)
+ arprequest((struct arpcom *)rt->rt_ifp,
+ &SIN(rt_key(rt))->sin_addr,
+ &SIN(rt_key(rt))->sin_addr,
+ (u_char *)LLADDR(SDL(gate)));
+ /*FALLTHROUGH*/
+ case RTM_RESOLVE:
+ if (gate->sa_family != AF_LINK ||
+ gate->sa_len < sizeof(null_sdl)) {
+ log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
+ break;
+ }
+ SDL(gate)->sdl_type = rt->rt_ifp->if_type;
+ SDL(gate)->sdl_index = rt->rt_ifp->if_index;
+ if (la != 0)
+ break; /* This happens on a route change */
+ /*
+ * Case 2: This route may come from cloning, or a manual route
+ * add with a LL address.
+ */
+ R_Malloc(la, struct llinfo_arp *, sizeof(*la));
+ rt->rt_llinfo = (caddr_t)la;
+ if (la == 0) {
+ log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
+ break;
+ }
+ arp_inuse++;
+ arp_allocated++;
+ Bzero(la, sizeof(*la));
+ la->la_rt = rt;
+ rt->rt_flags |= RTF_LLINFO;
+ LIST_INSERT_HEAD(&llinfo_arp, la, la_le);
+
+ /*
+ * This keeps the multicast addresses from showing up
+ * in `arp -a' listings as unresolved. It's not actually
+ * functional. Then the same for broadcast.
+ */
+ if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))) {
+ ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr,
+ LLADDR(SDL(gate)));
+ SDL(gate)->sdl_alen = 6;
+ rt->rt_expire = 0;
+ }
+ if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) {
+ memcpy(LLADDR(SDL(gate)), etherbroadcastaddr, 6);
+ SDL(gate)->sdl_alen = 6;
+ rt->rt_expire = 0;
+ }
+
+ if (SIN(rt_key(rt))->sin_addr.s_addr ==
+ (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) {
+ /*
+ * This test used to be
+ * if (loif.if_flags & IFF_UP)
+ * It allowed local traffic to be forced
+ * through the hardware by configuring the loopback down.
+ * However, it causes problems during network configuration
+ * for boards that can't receive packets they send.
+ * It is now necessary to clear "useloopback" and remove
+ * the route to force traffic out to the hardware.
+ */
+ rt->rt_expire = 0;
+ Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr,
+ LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6);
+ if (useloopback)
+ rt->rt_ifp = loif;
+
+ }
+ break;
+
+ case RTM_DELETE:
+ if (la == 0)
+ break;
+ arp_inuse--;
+ LIST_REMOVE(la, la_le);
+ rt->rt_llinfo = 0;
+ rt->rt_flags &= ~RTF_LLINFO;
+ if (la->la_hold)
+ m_freem(la->la_hold);
+ Free((caddr_t)la);
+ }
+}
+
+/*
+ * Broadcast an ARP request. Caller specifies:
+ * - arp header source ip address
+ * - arp header target ip address
+ * - arp header source ethernet address
+ */
+static void
+arprequest(struct arpcom *ac, struct in_addr *sip, struct in_addr *tip, u_char *enaddr)
+{
+ struct mbuf *m;
+ struct ether_header *eh;
+ struct ether_arp *ea;
+ struct sockaddr sa;
+
+ if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
+ return;
+ m->m_len = sizeof(*ea);
+ m->m_pkthdr.len = sizeof(*ea);
+ MH_ALIGN(m, sizeof(*ea));
+ ea = mtod(m, struct ether_arp *);
+ eh = (struct ether_header *)sa.sa_data;
+ bzero((caddr_t)ea, sizeof (*ea));
+ (void)memcpy(eh->ether_dhost, etherbroadcastaddr, sizeof(eh->ether_dhost));
+ eh->ether_type = htons(ETHERTYPE_ARP); /* if_output will not swap */
+ ea->arp_hrd = htons(ARPHRD_ETHER);
+ ea->arp_pro = htons(ETHERTYPE_IP);
+ ea->arp_hln = sizeof(ea->arp_sha); /* hardware address length */
+ ea->arp_pln = sizeof(ea->arp_spa); /* protocol address length */
+ ea->arp_op = htons(ARPOP_REQUEST);
+ (void)memcpy(ea->arp_sha, enaddr, sizeof(ea->arp_sha));
+ (void)memcpy(ea->arp_spa, sip, sizeof(ea->arp_spa));
+ (void)memcpy(ea->arp_tpa, tip, sizeof(ea->arp_tpa));
+ sa.sa_family = AF_UNSPEC;
+ sa.sa_len = sizeof(sa);
+ (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
+}
+
+/*
+ * Resolve an IP address into an ethernet address. If success,
+ * desten is filled in. If there is no entry in arptab,
+ * set one up and broadcast a request for the IP address.
+ * Hold onto this mbuf and resend it once the address
+ * is finally resolved. A return value of 1 indicates
+ * that desten has been filled in and the packet should be sent
+ * normally; a 0 return indicates that the packet has been
+ * taken over here, either now or for later transmission.
+ */
+int
+arpresolve(
+ struct arpcom *ac,
+ struct rtentry *rt,
+ struct mbuf *m,
+ struct sockaddr *dst,
+ u_char *desten,
+ struct rtentry *rt0)
+{
+ struct llinfo_arp *la = 0;
+ struct sockaddr_dl *sdl;
+
+ if (m->m_flags & M_BCAST) { /* broadcast */
+ (void)memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
+ return (1);
+ }
+ if (m->m_flags & M_MCAST) { /* multicast */
+ ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
+ return(1);
+ }
+ if (rt)
+ la = (struct llinfo_arp *)rt->rt_llinfo;
+ else {
+ la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0);
+ if (la)
+ rt = la->la_rt;
+ }
+ if (la == 0 || rt == 0) {
+ log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s\n",
+ inet_ntoa(SIN(dst)->sin_addr));
+ m_freem(m);
+ return (0);
+ }
+ sdl = SDL(rt->rt_gateway);
+ /*
+ * Check the address family and length is valid, the address
+ * is resolved; otherwise, try to resolve.
+ */
+ if ((rt->rt_expire == 0 || rt->rt_expire > rtems_bsdnet_seconds_since_boot()) &&
+ sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
+ bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
+ return 1;
+ }
+ /*
+ * There is an arptab entry, but no ethernet address
+ * response yet. Replace the held mbuf with this
+ * latest one.
+ */
+ if (la->la_hold)
+ m_freem(la->la_hold);
+ la->la_hold = m;
+ if (rt->rt_expire) {
+ rt->rt_flags &= ~RTF_REJECT;
+ if (la->la_asked == 0 || rt->rt_expire != rtems_bsdnet_seconds_since_boot()) {
+ rt->rt_expire = rtems_bsdnet_seconds_since_boot();
+ if (la->la_asked++ < arp_maxtries)
+ arprequest(ac,
+ &(SIN(rt->rt_ifa->ifa_addr)->sin_addr),
+ &(SIN(dst)->sin_addr),
+ ac->ac_enaddr);
+ else {
+ rt->rt_flags |= RTF_REJECT;
+ rt->rt_expire += arpt_down;
+ la->la_asked = 0;
+ }
+
+ }
+ }
+ return (0);
+}
+
+/*
+ * Common length and type checks are done here,
+ * then the protocol-specific routine is called.
+ */
+void
+arpintr(void)
+{
+ struct mbuf *m;
+ struct arphdr *ar;
+ int s;
+
+ while (arpintrq.ifq_head) {
+ s = splimp();
+ IF_DEQUEUE(&arpintrq, m);
+ splx(s);
+ if (m == 0 || (m->m_flags & M_PKTHDR) == 0)
+ panic("arpintr");
+ if (m->m_len >= sizeof(struct arphdr) &&
+ (ar = mtod(m, struct arphdr *)) &&
+ ntohs(ar->ar_hrd) == ARPHRD_ETHER &&
+ m->m_len >=
+ sizeof(struct arphdr) + 2 * ar->ar_hln + 2 * ar->ar_pln)
+
+ switch (ntohs(ar->ar_pro)) {
+
+ case ETHERTYPE_IP:
+ in_arpinput(m);
+ continue;
+ }
+ m_freem(m);
+ }
+}
+
+NETISR_SET(NETISR_ARP, arpintr);
+
+/*
+ * ARP for Internet protocols on 10 Mb/s Ethernet.
+ * Algorithm is that given in RFC 826.
+ * In addition, a sanity check is performed on the sender
+ * protocol address, to catch impersonators.
+ * We no longer handle negotiations for use of trailer protocol:
+ * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
+ * along with IP replies if we wanted trailers sent to us,
+ * and also sent them in response to IP replies.
+ * This allowed either end to announce the desire to receive
+ * trailer packets.
+ * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
+ * but formerly didn't normally send requests.
+ */
+static void
+in_arpinput(struct mbuf *m)
+{
+ struct ether_arp *ea;
+ struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif;
+ struct ether_header *eh;
+ struct llinfo_arp *la = 0;
+ struct rtentry *rt;
+ struct in_ifaddr *ia;
+ struct in_ifaddr *maybe_ia = 0;
+ struct sockaddr_dl *sdl;
+ struct sockaddr sa;
+ struct in_addr isaddr, itaddr, myaddr;
+ int op;
+
+ ea = mtod(m, struct ether_arp *);
+ op = ntohs(ea->arp_op);
+ (void)memcpy(&isaddr, ea->arp_spa, sizeof (isaddr));
+ (void)memcpy(&itaddr, ea->arp_tpa, sizeof (itaddr));
+ for (ia = in_ifaddr; ia; ia = ia->ia_next)
+ if (ia->ia_ifp == &ac->ac_if) {
+ maybe_ia = ia;
+ if ((itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) ||
+ (isaddr.s_addr == ia->ia_addr.sin_addr.s_addr))
+ break;
+ }
+ if (maybe_ia == 0) {
+ m_freem(m);
+ return;
+ }
+ myaddr = ia ? ia->ia_addr.sin_addr : maybe_ia->ia_addr.sin_addr;
+ if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr,
+ sizeof (ea->arp_sha))) {
+ m_freem(m); /* it's from me, ignore it. */
+ return;
+ }
+ if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr,
+ sizeof (ea->arp_sha))) {
+ log(LOG_ERR,
+ "arp: ether address is broadcast for IP address %s!\n",
+ inet_ntoa(isaddr));
+ m_freem(m);
+ return;
+ }
+ if (isaddr.s_addr == myaddr.s_addr) {
+ log(LOG_ERR,
+ "arp: %6D is using my IP address %s!\n",
+ ea->arp_sha, ":", inet_ntoa(isaddr));
+ itaddr = myaddr;
+ goto reply;
+ }
+ la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0);
+ if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
+ if (sdl->sdl_alen &&
+ bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen))
+ log(LOG_INFO, "arp: %s moved from %6D to %6D\n",
+ inet_ntoa(isaddr), (u_char *)LLADDR(sdl), ":",
+ ea->arp_sha, ":");
+ (void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
+ sdl->sdl_alen = sizeof(ea->arp_sha);
+ if (rt->rt_expire)
+ rt->rt_expire = rtems_bsdnet_seconds_since_boot() + arpt_keep;
+ rt->rt_flags &= ~RTF_REJECT;
+ la->la_asked = 0;
+ if (la->la_hold) {
+ (*ac->ac_if.if_output)(&ac->ac_if, la->la_hold,
+ rt_key(rt), rt);
+ la->la_hold = 0;
+ }
+ }
+reply:
+ if (op != ARPOP_REQUEST) {
+ m_freem(m);
+ return;
+ }
+ if (itaddr.s_addr == myaddr.s_addr) {
+ /* I am the target */
+ (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
+ (void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
+ } else {
+ la = arplookup(itaddr.s_addr, 0, SIN_PROXY);
+ if (la == NULL) {
+ struct sockaddr_in sin;
+
+ if (!arp_proxyall) {
+ m_freem(m);
+ return;
+ }
+
+ bzero(&sin, sizeof sin);
+ sin.sin_family = AF_INET;
+ sin.sin_len = sizeof sin;
+ sin.sin_addr = itaddr;
+
+ rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
+ if (!rt) {
+ m_freem(m);
+ return;
+ }
+ /*
+ * Don't send proxies for nodes on the same interface
+ * as this one came out of, or we'll get into a fight
+ * over who claims what Ether address.
+ */
+ if (rt->rt_ifp == &ac->ac_if) {
+ rtfree(rt);
+ m_freem(m);
+ return;
+ }
+ (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
+ (void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
+ rtfree(rt);
+#ifdef DEBUG_PROXY
+ printf("arp: proxying for %s\n",
+ inet_ntoa(itaddr));
+#endif
+ } else {
+ rt = la->la_rt;
+ (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
+ sdl = SDL(rt->rt_gateway);
+ (void)memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
+ }
+ }
+
+ (void)memcpy(ea->arp_tpa, ea->arp_spa, sizeof(ea->arp_spa));
+ (void)memcpy(ea->arp_spa, &itaddr, sizeof(ea->arp_spa));
+ ea->arp_op = htons(ARPOP_REPLY);
+ ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */
+ eh = (struct ether_header *)sa.sa_data;
+ (void)memcpy(eh->ether_dhost, ea->arp_tha, sizeof(eh->ether_dhost));
+ eh->ether_type = htons(ETHERTYPE_ARP);
+ sa.sa_family = AF_UNSPEC;
+ sa.sa_len = sizeof(sa);
+ (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
+ return;
+}
+
+/*
+ * Free an arp entry.
+ */
+static void
+arptfree(struct llinfo_arp *la)
+{
+ struct rtentry *rt = la->la_rt;
+ struct sockaddr_dl *sdl;
+ if (rt == 0)
+ panic("arptfree");
+ if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
+ sdl->sdl_family == AF_LINK) {
+ sdl->sdl_alen = 0;
+ la->la_asked = 0;
+ rt->rt_flags &= ~RTF_REJECT;
+ return;
+ }
+ rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
+ 0, (struct rtentry **)0);
+}
+/*
+ * Lookup or enter a new address in arptab.
+ */
+static struct llinfo_arp *
+arplookup(u_long addr, int create, int proxy)
+{
+ struct rtentry *rt;
+ static struct sockaddr_inarp sin = {sizeof(sin), AF_INET, 0, { 0 }, { 0 }, 0, 0 };
+ const char *why = 0;
+
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = addr;
+ sin.sin_other = proxy ? SIN_PROXY : 0;
+ rt = rtalloc1((struct sockaddr *)&sin, create, 0UL);
+ if (rt == 0)
+ return (0);
+ rt->rt_refcnt--;
+
+ if (rt->rt_flags & RTF_GATEWAY)
+ why = "host is not on local network";
+ else if ((rt->rt_flags & RTF_LLINFO) == 0)
+ why = "could not allocate llinfo";
+ else if (rt->rt_gateway->sa_family != AF_LINK)
+ why = "gateway route is not ours";
+
+ if (why && create) {
+ log(LOG_DEBUG, "arplookup %s failed: %s\n",
+ inet_ntoa(sin.sin_addr), why);
+ return 0;
+ } else if (why) {
+ return 0;
+ }
+ return ((struct llinfo_arp *)rt->rt_llinfo);
+}
+
+void
+arp_ifinit(struct arpcom *ac, struct ifaddr *ifa)
+{
+ if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY)
+ arprequest(ac, &(IA_SIN(ifa)->sin_addr),
+ &(IA_SIN(ifa)->sin_addr), ac->ac_enaddr);
+ ifa->ifa_rtrequest = arp_rtrequest;
+ ifa->ifa_flags |= RTF_CLONING;
+}
diff --git a/cpukit/libnetworking/netinet/if_ether.h b/cpukit/libnetworking/netinet/if_ether.h
new file mode 100644
index 0000000000..9c3ce62b76
--- /dev/null
+++ b/cpukit/libnetworking/netinet/if_ether.h
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_ether.h 8.3 (Berkeley) 5/2/95
+ * $FreeBSD: src/sys/netinet/if_ether.h,v 1.32 2005/02/22 13:04:03 glebius Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IF_ETHER_H_
+#define _NETINET_IF_ETHER_H_
+
+#include <net/ethernet.h>
+#include <net/if_arp.h>
+
+#ifdef _KERNEL
+/*
+ * Macro to map an IP multicast address to an Ethernet multicast address.
+ * The high-order 25 bits of the Ethernet address are statically assigned,
+ * and the low-order 23 bits are taken from the low end of the IP address.
+ */
+#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
+ /* struct in_addr *ipaddr; */ \
+ /* u_char enaddr[ETHER_ADDR_LEN]; */ \
+{ \
+ (enaddr)[0] = 0x01; \
+ (enaddr)[1] = 0x00; \
+ (enaddr)[2] = 0x5e; \
+ (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
+ (enaddr)[4] = ((u_char *)ipaddr)[2]; \
+ (enaddr)[5] = ((u_char *)ipaddr)[3]; \
+}
+#endif
+
+/*
+ * Ethernet Address Resolution Protocol.
+ *
+ * See RFC 826 for protocol description. Structure below is adapted
+ * to resolving internet addresses. Field names used correspond to
+ * RFC 826.
+ */
+struct ether_arp {
+ struct arphdr ea_hdr; /* fixed-size header */
+ u_char arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */
+ u_char arp_spa[4]; /* sender protocol address */
+ u_char arp_tha[ETHER_ADDR_LEN]; /* target hardware address */
+ u_char arp_tpa[4]; /* target protocol address */
+};
+#define arp_hrd ea_hdr.ar_hrd
+#define arp_pro ea_hdr.ar_pro
+#define arp_hln ea_hdr.ar_hln
+#define arp_pln ea_hdr.ar_pln
+#define arp_op ea_hdr.ar_op
+
+struct sockaddr_inarp {
+ u_char sin_len;
+ u_char sin_family;
+ u_short sin_port;
+ struct in_addr sin_addr;
+ struct in_addr sin_srcaddr;
+ u_short sin_tos;
+ u_short sin_other;
+#define SIN_PROXY 1
+};
+/*
+ * IP and ethernet specific routing flags
+ */
+#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
+#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
+
+#ifdef _KERNEL
+extern u_char etherbroadcastaddr[ETHER_ADDR_LEN];
+extern u_char ether_ipmulticast_min[ETHER_ADDR_LEN];
+extern u_char ether_ipmulticast_max[ETHER_ADDR_LEN];
+extern struct ifqueue arpintrq;
+
+int arpresolve(struct arpcom *, struct rtentry *, struct mbuf *,
+ struct sockaddr *, u_char *, struct rtentry *);
+void arp_ifinit(struct arpcom *, struct ifaddr *);
+int ether_addmulti(struct ifreq *, struct arpcom *);
+int ether_delmulti(struct ifreq *, struct arpcom *);
+
+/*
+ * Ethernet multicast address structure. There is one of these for each
+ * multicast address or range of multicast addresses that we are supposed
+ * to listen to on a particular interface. They are kept in a linked list,
+ * rooted in the interface's arpcom structure. (This really has nothing to
+ * do with ARP, or with the Internet address family, but this appears to be
+ * the minimally-disrupting place to put it.)
+ */
+struct ether_multi {
+ u_char enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */
+ u_char enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */
+ struct arpcom *enm_ac; /* back pointer to arpcom */
+ u_int enm_refcount; /* no. claims to this addr/range */
+ struct ether_multi *enm_next; /* ptr to next ether_multi */
+};
+
+/*
+ * Structure used by macros below to remember position when stepping through
+ * all of the ether_multi records.
+ */
+struct ether_multistep {
+ struct ether_multi *e_enm;
+};
+
+/*
+ * Macro for looking up the ether_multi record for a given range of Ethernet
+ * multicast addresses connected to a given arpcom structure. If no matching
+ * record is found, "enm" returns NULL.
+ */
+#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
+ /* u_char addrlo[ETHER_ADDR_LEN]; */ \
+ /* u_char addrhi[ETHER_ADDR_LEN]; */ \
+ /* struct arpcom *ac; */ \
+ /* struct ether_multi *enm; */ \
+{ \
+ for ((enm) = (ac)->ac_multiaddrs; \
+ (enm) != NULL && \
+ (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \
+ bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \
+ (enm) = (enm)->enm_next); \
+}
+
+/*
+ * Macro to step through all of the ether_multi records, one at a time.
+ * The current position is remembered in "step", which the caller must
+ * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step"
+ * and get the first record. Both macros return a NULL "enm" when there
+ * are no remaining records.
+ */
+#define ETHER_NEXT_MULTI(step, enm) \
+ /* struct ether_multistep step; */ \
+ /* struct ether_multi *enm; */ \
+{ \
+ if (((enm) = (step).e_enm) != NULL) \
+ (step).e_enm = (enm)->enm_next; \
+}
+
+#define ETHER_FIRST_MULTI(step, ac, enm) \
+ /* struct ether_multistep step; */ \
+ /* struct arpcom *ac; */ \
+ /* struct ether_multi *enm; */ \
+{ \
+ (step).e_enm = (ac)->ac_multiaddrs; \
+ ETHER_NEXT_MULTI((step), (enm)); \
+}
+
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/netinet/igmp.c b/cpukit/libnetworking/netinet/igmp.c
new file mode 100644
index 0000000000..7bd10eafa7
--- /dev/null
+++ b/cpukit/libnetworking/netinet/igmp.c
@@ -0,0 +1,471 @@
+/*
+ * Copyright (c) 1988 Stephen Deering.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Stephen Deering of Stanford University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)igmp.c 8.1 (Berkeley) 7/19/93
+ * $Id$
+ */
+
+/*
+ * Internet Group Management Protocol (IGMP) routines.
+ *
+ * Written by Steve Deering, Stanford, May 1988.
+ * Modified by Rosen Sharma, Stanford, Aug 1994.
+ * Modified by Bill Fenner, Xerox PARC, Feb 1995.
+ * Modified to fully comply to IGMPv2 by Bill Fenner, Oct 1995.
+ *
+ * MULTICAST Revision: 3.5.1.4
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/igmp.h>
+#include <netinet/igmp_var.h>
+
+static struct router_info *
+ find_rti (struct ifnet *ifp);
+
+static struct igmpstat igmpstat;
+
+SYSCTL_STRUCT(_net_inet_igmp, IGMPCTL_STATS, stats, CTLFLAG_RD,
+ &igmpstat, igmpstat, "");
+
+static int igmp_timers_are_running;
+static u_long igmp_all_hosts_group;
+static u_long igmp_all_rtrs_group;
+static struct mbuf *router_alert;
+static struct router_info *Head;
+
+static void igmp_sendpkt(struct in_multi *, int, unsigned long);
+
+void
+igmp_init(void)
+{
+ struct ipoption *ra;
+
+ /*
+ * To avoid byte-swapping the same value over and over again.
+ */
+ igmp_all_hosts_group = htonl(INADDR_ALLHOSTS_GROUP);
+ igmp_all_rtrs_group = htonl(INADDR_ALLRTRS_GROUP);
+
+ igmp_timers_are_running = 0;
+
+ /*
+ * Construct a Router Alert option to use in outgoing packets
+ */
+ MGET(router_alert, M_DONTWAIT, MT_DATA);
+ ra = mtod(router_alert, struct ipoption *);
+ ra->ipopt_dst.s_addr = 0;
+ ra->ipopt_list[0] = IPOPT_RA; /* Router Alert Option */
+ ra->ipopt_list[1] = 0x04; /* 4 bytes long */
+ ra->ipopt_list[2] = 0x00;
+ ra->ipopt_list[3] = 0x00;
+ router_alert->m_len = sizeof(ra->ipopt_dst) + ra->ipopt_list[1];
+
+ Head = (struct router_info *) 0;
+}
+
+static struct router_info *
+find_rti(struct ifnet *ifp)
+{
+ register struct router_info *rti = Head;
+
+#ifdef IGMP_DEBUG
+ printf("[igmp.c, _find_rti] --> entering \n");
+#endif
+ while (rti) {
+ if (rti->rti_ifp == ifp) {
+#ifdef IGMP_DEBUG
+ printf("[igmp.c, _find_rti] --> found old entry \n");
+#endif
+ return rti;
+ }
+ rti = rti->rti_next;
+ }
+ MALLOC(rti, struct router_info *, sizeof *rti, M_MRTABLE, M_NOWAIT);
+ rti->rti_ifp = ifp;
+ rti->rti_type = IGMP_V2_ROUTER;
+ rti->rti_time = 0;
+ rti->rti_next = Head;
+ Head = rti;
+#ifdef IGMP_DEBUG
+ printf("[igmp.c, _find_rti] --> created an entry \n");
+#endif
+ return rti;
+}
+
+void
+igmp_input(struct mbuf *m, int iphlen)
+{
+ register struct igmp *igmp;
+ register struct ip *ip;
+ register int igmplen;
+ register struct ifnet *ifp = m->m_pkthdr.rcvif;
+ register int minlen;
+ register struct in_multi *inm;
+ register struct in_ifaddr *ia;
+ struct in_multistep step;
+ struct router_info *rti;
+
+ int timer; /** timer value in the igmp query header **/
+
+ ++igmpstat.igps_rcv_total;
+
+ ip = mtod(m, struct ip *);
+ igmplen = ip->ip_len;
+
+ /*
+ * Validate lengths
+ */
+ if (igmplen < IGMP_MINLEN) {
+ ++igmpstat.igps_rcv_tooshort;
+ m_freem(m);
+ return;
+ }
+ minlen = iphlen + IGMP_MINLEN;
+ if ((m->m_flags & M_EXT || m->m_len < minlen) &&
+ (m = m_pullup(m, minlen)) == 0) {
+ ++igmpstat.igps_rcv_tooshort;
+ return;
+ }
+
+ /*
+ * Validate checksum
+ */
+ m->m_data += iphlen;
+ m->m_len -= iphlen;
+ igmp = mtod(m, struct igmp *);
+ if (in_cksum(m, igmplen)) {
+ ++igmpstat.igps_rcv_badsum;
+ m_freem(m);
+ return;
+ }
+ m->m_data -= iphlen;
+ m->m_len += iphlen;
+
+ ip = mtod(m, struct ip *);
+ timer = igmp->igmp_code * PR_FASTHZ / IGMP_TIMER_SCALE;
+ rti = find_rti(ifp);
+
+ /*
+ * In the IGMPv2 specification, there are 3 states and a flag.
+ *
+ * In Non-Member state, we simply don't have a membership record.
+ * In Delaying Member state, our timer is running (inm->inm_timer)
+ * In Idle Member state, our timer is not running (inm->inm_timer==0)
+ *
+ * The flag is inm->inm_state, it is set to IGMP_OTHERMEMBER if
+ * we have heard a report from another member, or IGMP_IREPORTEDLAST
+ * if I sent the last report.
+ */
+ switch (igmp->igmp_type) {
+
+ case IGMP_MEMBERSHIP_QUERY:
+ ++igmpstat.igps_rcv_queries;
+
+ if (ifp->if_flags & IFF_LOOPBACK)
+ break;
+
+ if (igmp->igmp_code == 0) {
+ /*
+ * Old router. Remember that the querier on this
+ * interface is old, and set the timer to the
+ * value in RFC 1112.
+ */
+
+ rti->rti_type = IGMP_V1_ROUTER;
+ rti->rti_time = 0;
+
+ timer = IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ;
+
+ if (ip->ip_dst.s_addr != igmp_all_hosts_group ||
+ igmp->igmp_group.s_addr != 0) {
+ ++igmpstat.igps_rcv_badqueries;
+ m_freem(m);
+ return;
+ }
+ } else {
+ /*
+ * New router. Simply do the new validity check.
+ */
+
+ if (igmp->igmp_group.s_addr != 0 &&
+ !IN_MULTICAST(ntohl(igmp->igmp_group.s_addr))) {
+ ++igmpstat.igps_rcv_badqueries;
+ m_freem(m);
+ return;
+ }
+ }
+
+ /*
+ * - Start the timers in all of our membership records
+ * that the query applies to for the interface on
+ * which the query arrived excl. those that belong
+ * to the "all-hosts" group (224.0.0.1).
+ * - Restart any timer that is already running but has
+ * a value longer than the requested timeout.
+ * - Use the value specified in the query message as
+ * the maximum timeout.
+ */
+ IN_FIRST_MULTI(step, inm);
+ while (inm != NULL) {
+ if (inm->inm_ifp == ifp &&
+ inm->inm_addr.s_addr != igmp_all_hosts_group &&
+ (igmp->igmp_group.s_addr == 0 ||
+ igmp->igmp_group.s_addr == inm->inm_addr.s_addr)) {
+ if (inm->inm_timer == 0 ||
+ inm->inm_timer > timer) {
+ inm->inm_timer =
+ IGMP_RANDOM_DELAY(timer);
+ igmp_timers_are_running = 1;
+ }
+ }
+ IN_NEXT_MULTI(step, inm);
+ }
+
+ break;
+
+ case IGMP_V1_MEMBERSHIP_REPORT:
+ case IGMP_V2_MEMBERSHIP_REPORT:
+ /*
+ * For fast leave to work, we have to know that we are the
+ * last person to send a report for this group. Reports
+ * can potentially get looped back if we are a multicast
+ * router, so discard reports sourced by me.
+ */
+ IFP_TO_IA(ifp, ia);
+ if (ia && ip->ip_src.s_addr == IA_SIN(ia)->sin_addr.s_addr)
+ break;
+
+ ++igmpstat.igps_rcv_reports;
+
+ if (ifp->if_flags & IFF_LOOPBACK)
+ break;
+
+ if (!IN_MULTICAST(ntohl(igmp->igmp_group.s_addr))) {
+ ++igmpstat.igps_rcv_badreports;
+ m_freem(m);
+ return;
+ }
+
+ /*
+ * KLUDGE: if the IP source address of the report has an
+ * unspecified (i.e., zero) subnet number, as is allowed for
+ * a booting host, replace it with the correct subnet number
+ * so that a process-level multicast routing demon can
+ * determine which subnet it arrived from. This is necessary
+ * to compensate for the lack of any way for a process to
+ * determine the arrival interface of an incoming packet.
+ */
+ if ((ntohl(ip->ip_src.s_addr) & IN_CLASSA_NET) == 0)
+ if (ia) ip->ip_src.s_addr = htonl(ia->ia_subnet);
+
+ /*
+ * If we belong to the group being reported, stop
+ * our timer for that group.
+ */
+ IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
+
+ if (inm != NULL) {
+ inm->inm_timer = 0;
+ ++igmpstat.igps_rcv_ourreports;
+
+ inm->inm_state = IGMP_OTHERMEMBER;
+ }
+
+ break;
+ }
+
+ /*
+ * Pass all valid IGMP packets up to any process(es) listening
+ * on a raw IGMP socket.
+ */
+ rip_input(m, iphlen);
+}
+
+void
+igmp_joingroup(struct in_multi *inm)
+{
+ int s = splnet();
+
+ if (inm->inm_addr.s_addr == igmp_all_hosts_group
+ || inm->inm_ifp->if_flags & IFF_LOOPBACK) {
+ inm->inm_timer = 0;
+ inm->inm_state = IGMP_OTHERMEMBER;
+ } else {
+ inm->inm_rti = find_rti(inm->inm_ifp);
+ igmp_sendpkt(inm, inm->inm_rti->rti_type, 0);
+ inm->inm_timer = IGMP_RANDOM_DELAY(
+ IGMP_MAX_HOST_REPORT_DELAY*PR_FASTHZ);
+ inm->inm_state = IGMP_IREPORTEDLAST;
+ igmp_timers_are_running = 1;
+ }
+ splx(s);
+}
+
+void
+igmp_leavegroup(struct in_multi *inm)
+{
+ if (inm->inm_state == IGMP_IREPORTEDLAST &&
+ inm->inm_addr.s_addr != igmp_all_hosts_group &&
+ !(inm->inm_ifp->if_flags & IFF_LOOPBACK) &&
+ inm->inm_rti->rti_type != IGMP_V1_ROUTER)
+ igmp_sendpkt(inm, IGMP_V2_LEAVE_GROUP, igmp_all_rtrs_group);
+}
+
+void
+igmp_fasttimo(void)
+{
+ register struct in_multi *inm;
+ struct in_multistep step;
+ int s;
+
+ /*
+ * Quick check to see if any work needs to be done, in order
+ * to minimize the overhead of fasttimo processing.
+ */
+
+ if (!igmp_timers_are_running)
+ return;
+
+ s = splnet();
+ igmp_timers_are_running = 0;
+ IN_FIRST_MULTI(step, inm);
+ while (inm != NULL) {
+ if (inm->inm_timer == 0) {
+ /* do nothing */
+ } else if (--inm->inm_timer == 0) {
+ igmp_sendpkt(inm, inm->inm_rti->rti_type, 0);
+ inm->inm_state = IGMP_IREPORTEDLAST;
+ } else {
+ igmp_timers_are_running = 1;
+ }
+ IN_NEXT_MULTI(step, inm);
+ }
+ splx(s);
+}
+
+void
+igmp_slowtimo(void)
+{
+ int s = splnet();
+ register struct router_info *rti = Head;
+
+#ifdef IGMP_DEBUG
+ printf("[igmp.c,_slowtimo] -- > entering \n");
+#endif
+ while (rti) {
+ if (rti->rti_type == IGMP_V1_ROUTER) {
+ rti->rti_time++;
+ if (rti->rti_time >= IGMP_AGE_THRESHOLD) {
+ rti->rti_type = IGMP_V2_ROUTER;
+ }
+ }
+ rti = rti->rti_next;
+ }
+#ifdef IGMP_DEBUG
+ printf("[igmp.c,_slowtimo] -- > exiting \n");
+#endif
+ splx(s);
+}
+
+static struct route igmprt;
+
+static void
+igmp_sendpkt(struct in_multi *inm, int type, unsigned long addr)
+{
+ struct mbuf *m;
+ struct igmp *igmp;
+ struct ip *ip;
+ struct ip_moptions imo;
+
+ MGETHDR(m, M_DONTWAIT, MT_HEADER);
+ if (m == NULL)
+ return;
+
+ m->m_pkthdr.rcvif = loif;
+ m->m_pkthdr.len = sizeof(struct ip) + IGMP_MINLEN;
+ MH_ALIGN(m, IGMP_MINLEN + sizeof(struct ip));
+ m->m_data += sizeof(struct ip);
+ m->m_len = IGMP_MINLEN;
+ igmp = mtod(m, struct igmp *);
+ igmp->igmp_type = type;
+ igmp->igmp_code = 0;
+ igmp->igmp_group = inm->inm_addr;
+ igmp->igmp_cksum = 0;
+ igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN);
+
+ m->m_data -= sizeof(struct ip);
+ m->m_len += sizeof(struct ip);
+ ip = mtod(m, struct ip *);
+ ip->ip_tos = 0;
+ ip->ip_len = sizeof(struct ip) + IGMP_MINLEN;
+ ip->ip_off = 0;
+ ip->ip_p = IPPROTO_IGMP;
+ ip->ip_src.s_addr = INADDR_ANY;
+ ip->ip_dst.s_addr = addr ? addr : igmp->igmp_group.s_addr;
+
+ imo.imo_multicast_ifp = inm->inm_ifp;
+ imo.imo_multicast_ttl = 1;
+ imo.imo_multicast_vif = -1;
+ /*
+ * Request loopback of the report if we are acting as a multicast
+ * router, so that the process-level routing demon can hear it.
+ */
+ imo.imo_multicast_loop = (ip_mrouter != NULL);
+
+ /*
+ * XXX
+ * Do we have to worry about reentrancy here? Don't think so.
+ */
+ ip_output(m, router_alert, &igmprt, 0, &imo);
+
+ ++igmpstat.igps_snd_reports;
+}
diff --git a/cpukit/libnetworking/netinet/igmp.h b/cpukit/libnetworking/netinet/igmp.h
new file mode 100644
index 0000000000..01d6d09179
--- /dev/null
+++ b/cpukit/libnetworking/netinet/igmp.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 1988 Stephen Deering.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Stephen Deering of Stanford University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)igmp.h 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifndef _NETINET_IGMP_H_
+#define _NETINET_IGMP_H_
+
+/*
+ * Internet Group Management Protocol (IGMP) definitions.
+ *
+ * Written by Steve Deering, Stanford, May 1988.
+ *
+ * MULTICAST Revision: 3.5.1.2
+ */
+
+/*
+ * IGMP packet format.
+ */
+struct igmp {
+ u_char igmp_type; /* version & type of IGMP message */
+ u_char igmp_code; /* subtype for routing msgs */
+ u_short igmp_cksum; /* IP-style checksum */
+ struct in_addr igmp_group; /* group address being reported */
+}; /* (zero for queries) */
+
+#define IGMP_MINLEN 8
+
+/*
+ * Message types, including version number.
+ */
+#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */
+#define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */
+#define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */
+#define IGMP_V2_LEAVE_GROUP 0x17 /* Leave-group message */
+
+#define IGMP_DVMRP 0x13 /* DVMRP routing message */
+#define IGMP_PIM 0x14 /* PIM routing message */
+
+#define IGMP_MTRACE_RESP 0x1e /* traceroute resp.(to sender)*/
+#define IGMP_MTRACE 0x1f /* mcast traceroute messages */
+
+#define IGMP_MAX_HOST_REPORT_DELAY 10 /* max delay for response to */
+ /* query (in seconds) according */
+ /* to RFC1112 */
+
+
+#define IGMP_TIMER_SCALE 10 /* denotes that the igmp code field */
+ /* specifies time in 10th of seconds*/
+
+/*
+ * The following four defininitions are for backwards compatibility.
+ * They should be removed as soon as all applications are updated to
+ * use the new constant names.
+ */
+#define IGMP_HOST_MEMBERSHIP_QUERY IGMP_MEMBERSHIP_QUERY
+#define IGMP_HOST_MEMBERSHIP_REPORT IGMP_V1_MEMBERSHIP_REPORT
+#define IGMP_HOST_NEW_MEMBERSHIP_REPORT IGMP_V2_MEMBERSHIP_REPORT
+#define IGMP_HOST_LEAVE_MESSAGE IGMP_V2_LEAVE_GROUP
+
+#endif /* _NETINET_IGMP_H_ */
diff --git a/cpukit/libnetworking/netinet/igmp_var.h b/cpukit/libnetworking/netinet/igmp_var.h
new file mode 100644
index 0000000000..d1454e0521
--- /dev/null
+++ b/cpukit/libnetworking/netinet/igmp_var.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 1988 Stephen Deering.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Stephen Deering of Stanford University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)igmp_var.h 8.1 (Berkeley) 7/19/93
+ * $FreeBSD: src/sys/netinet/igmp_var.h,v 1.20 2004/04/07 20:46:13 imp Exp $
+ */
+
+#ifndef _NETINET_IGMP_VAR_H_
+#define _NETINET_IGMP_VAR_H_
+
+/*
+ * Internet Group Management Protocol (IGMP),
+ * implementation-specific definitions.
+ *
+ * Written by Steve Deering, Stanford, May 1988.
+ *
+ * MULTICAST Revision: 3.5.1.3
+ */
+
+struct igmpstat {
+ u_int igps_rcv_total; /* total IGMP messages received */
+ u_int igps_rcv_tooshort; /* received with too few bytes */
+ u_int igps_rcv_badsum; /* received with bad checksum */
+ u_int igps_rcv_queries; /* received membership queries */
+ u_int igps_rcv_badqueries; /* received invalid queries */
+ u_int igps_rcv_reports; /* received membership reports */
+ u_int igps_rcv_badreports; /* received invalid reports */
+ u_int igps_rcv_ourreports; /* received reports for our groups */
+ u_int igps_snd_reports; /* sent membership reports */
+};
+
+#ifdef _KERNEL
+#define IGMP_RANDOM_DELAY(X) (random() % (X) + 1)
+
+/*
+ * States for IGMPv2's leave processing
+ */
+#define IGMP_OTHERMEMBER 0
+#define IGMP_IREPORTEDLAST 1
+
+/*
+ * We must remember what version the subnet's querier is.
+ * We conveniently use the IGMP message type for the proper
+ * membership report to keep this state.
+ */
+#define IGMP_V1_ROUTER IGMP_V1_MEMBERSHIP_REPORT
+#define IGMP_V2_ROUTER IGMP_V2_MEMBERSHIP_REPORT
+
+/*
+ * Revert to new router if we haven't heard from an old router in
+ * this amount of time.
+ */
+#define IGMP_AGE_THRESHOLD 540
+
+void igmp_init(void);
+void igmp_input(struct mbuf *, int);
+void igmp_joingroup(struct in_multi *);
+void igmp_leavegroup(struct in_multi *);
+void igmp_fasttimo(void);
+void igmp_slowtimo(void);
+
+SYSCTL_DECL(_net_inet_igmp);
+
+#endif
+
+/*
+ * Names for IGMP sysctl objects
+ */
+#define IGMPCTL_STATS 1 /* statistics (read-only) */
+#define IGMPCTL_MAXID 2
+
+#define IGMPCTL_NAMES { \
+ { 0, 0 }, \
+ { "stats", CTLTYPE_STRUCT }, \
+}
+#endif
diff --git a/cpukit/libnetworking/netinet/in.c b/cpukit/libnetworking/netinet/in.c
new file mode 100644
index 0000000000..a23d4f598c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in.c
@@ -0,0 +1,709 @@
+/*
+ * Copyright (c) 1982, 1986, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in.c 8.4 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/netinet/in.c,v 1.75 2004/04/07 20:46:13 imp Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <sys/malloc.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/if_ether.h>
+
+#include <netinet/igmp_var.h>
+
+/*
+ * This structure is used to keep track of in_multi chains which belong to
+ * deleted interface addresses.
+ */
+static LIST_HEAD(, multi_kludge) in_mk; /* XXX BSS initialization */
+
+struct multi_kludge {
+ LIST_ENTRY(multi_kludge) mk_entry;
+ struct ifnet *mk_ifp;
+ struct in_multihead mk_head;
+};
+
+static void in_socktrim(struct sockaddr_in *);
+static int in_ifinit(struct ifnet *,
+ struct in_ifaddr *, struct sockaddr_in *, int);
+static void in_ifscrub(struct ifnet *, struct in_ifaddr *);
+
+static int subnetsarelocal = 0;
+SYSCTL_INT(_net_inet_ip, OID_AUTO, subnets_are_local, CTLFLAG_RW,
+ &subnetsarelocal, 0, "");
+/*
+ * Return 1 if an internet address is for a ``local'' host
+ * (one to which we have a connection). If subnetsarelocal
+ * is true, this includes other subnets of the local net.
+ * Otherwise, it includes only the directly-connected (sub)nets.
+ */
+int
+in_localaddr(struct in_addr in)
+{
+ register u_long i = ntohl(in.s_addr);
+ register struct in_ifaddr *ia;
+
+ if (subnetsarelocal) {
+ for (ia = in_ifaddr; ia; ia = ia->ia_next)
+ if ((i & ia->ia_netmask) == ia->ia_net)
+ return (1);
+ } else {
+ for (ia = in_ifaddr; ia; ia = ia->ia_next)
+ if ((i & ia->ia_subnetmask) == ia->ia_subnet)
+ return (1);
+ }
+ return (0);
+}
+
+/*
+ * Determine whether an IP address is in a reserved set of addresses
+ * that may not be forwarded, or whether datagrams to that destination
+ * may be forwarded.
+ */
+int
+in_canforward(struct in_addr in)
+{
+ register u_long i = ntohl(in.s_addr);
+ register u_long net;
+
+ if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i))
+ return (0);
+ if (IN_CLASSA(i)) {
+ net = i & IN_CLASSA_NET;
+ if (net == 0 || net == (IN_LOOPBACKNET << IN_CLASSA_NSHIFT))
+ return (0);
+ }
+ return (1);
+}
+
+/*
+ * Trim a mask in a sockaddr
+ */
+static void
+in_socktrim(struct sockaddr_in *ap)
+{
+ register char *cplim = (char *) &ap->sin_addr;
+ register char *cp = (char *) (&ap->sin_addr + 1);
+
+ ap->sin_len = 0;
+ while (--cp >= cplim)
+ if (*cp) {
+ (ap)->sin_len = cp - (char *) (ap) + 1;
+ break;
+ }
+}
+
+static int in_interfaces; /* number of external internet interfaces */
+
+/*
+ * Generic internet control operations (ioctl's).
+ * Ifp is 0 if not an interface-specific ioctl.
+ */
+int
+in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp)
+{
+ register struct ifreq *ifr = (struct ifreq *)data;
+ register struct in_ifaddr *ia = 0, *iap;
+ register struct ifaddr *ifa;
+ struct in_ifaddr *oia;
+ struct in_aliasreq *ifra = (struct in_aliasreq *)data;
+ struct sockaddr_in oldaddr;
+ int error, hostIsNew, maskIsNew, s;
+ struct multi_kludge *mk;
+
+ /*
+ * Find address for this interface, if it exists.
+ *
+ * If an alias address was specified, find that one instead of
+ * the first one on the interface.
+ */
+ if (ifp)
+ for (iap = in_ifaddr; iap; iap = iap->ia_next)
+ if (iap->ia_ifp == ifp) {
+ if (((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr ==
+ iap->ia_addr.sin_addr.s_addr) {
+ ia = iap;
+ break;
+ } else if (ia == NULL) {
+ ia = iap;
+ if (ifr->ifr_addr.sa_family != AF_INET)
+ break;
+ }
+ }
+
+ switch (cmd) {
+
+ case SIOCAIFADDR:
+ case SIOCDIFADDR:
+ if (ifra->ifra_addr.sin_family == AF_INET) {
+ for (oia = ia; ia; ia = ia->ia_next) {
+ if (ia->ia_ifp == ifp &&
+ ia->ia_addr.sin_addr.s_addr ==
+ ifra->ifra_addr.sin_addr.s_addr)
+ break;
+ }
+ if ((ifp->if_flags & IFF_POINTOPOINT)
+ && (cmd == SIOCAIFADDR)
+ && (ifra->ifra_dstaddr.sin_addr.s_addr
+ == INADDR_ANY)) {
+ return EDESTADDRREQ;
+ }
+ }
+ if (cmd == SIOCDIFADDR && ia == 0)
+ return (EADDRNOTAVAIL);
+ /* FALLTHROUGH */
+ case SIOCSIFADDR:
+ case SIOCSIFNETMASK:
+ case SIOCSIFDSTADDR:
+ if ((so->so_state & SS_PRIV) == 0)
+ return (EPERM);
+
+ if (ifp == 0)
+ panic("in_control");
+ if (ia == (struct in_ifaddr *)0) {
+ oia = (struct in_ifaddr *)
+ malloc(sizeof *oia, M_IFADDR, M_WAITOK);
+ if (oia == (struct in_ifaddr *)NULL)
+ return (ENOBUFS);
+ bzero((caddr_t)oia, sizeof *oia);
+ ia = in_ifaddr;
+ /*
+ * Protect from ipintr() traversing address list
+ * while we're modifying it.
+ */
+ s = splnet();
+
+ if (ia) {
+ for ( ; ia->ia_next; ia = ia->ia_next)
+ continue;
+ ia->ia_next = oia;
+ } else
+ in_ifaddr = oia;
+ ia = oia;
+ ifa = ifp->if_addrlist;
+ if (ifa) {
+ for ( ; ifa->ifa_next; ifa = ifa->ifa_next)
+ continue;
+ ifa->ifa_next = (struct ifaddr *) ia;
+ } else
+ ifp->if_addrlist = (struct ifaddr *) ia;
+ ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
+ ia->ia_ifa.ifa_dstaddr
+ = (struct sockaddr *)&ia->ia_dstaddr;
+ ia->ia_ifa.ifa_netmask
+ = (struct sockaddr *)&ia->ia_sockmask;
+ ia->ia_sockmask.sin_len = 8;
+ if (ifp->if_flags & IFF_BROADCAST) {
+ ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr);
+ ia->ia_broadaddr.sin_family = AF_INET;
+ }
+ ia->ia_ifp = ifp;
+ if (!(ifp->if_flags & IFF_LOOPBACK))
+ in_interfaces++;
+ splx(s);
+ }
+ break;
+
+ case SIOCSIFBRDADDR:
+ if ((so->so_state & SS_PRIV) == 0)
+ return (EPERM);
+ /* FALLTHROUGH */
+
+ case SIOCGIFADDR:
+ case SIOCGIFNETMASK:
+ case SIOCGIFDSTADDR:
+ case SIOCGIFBRDADDR:
+ if (ia == (struct in_ifaddr *)0)
+ return (EADDRNOTAVAIL);
+ break;
+ }
+ switch (cmd) {
+
+ case SIOCGIFADDR:
+ *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_addr;
+ break;
+
+ case SIOCGIFBRDADDR:
+ if ((ifp->if_flags & IFF_BROADCAST) == 0)
+ return (EINVAL);
+ *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_broadaddr;
+ break;
+
+ case SIOCGIFDSTADDR:
+ if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
+ return (EINVAL);
+ *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_dstaddr;
+ break;
+
+ case SIOCGIFNETMASK:
+ *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_sockmask;
+ break;
+
+ case SIOCSIFDSTADDR:
+ if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
+ return (EINVAL);
+ oldaddr = ia->ia_dstaddr;
+ ia->ia_dstaddr = *(struct sockaddr_in *)&ifr->ifr_dstaddr;
+ if (ifp->if_ioctl && (error = (*ifp->if_ioctl)
+ (ifp, SIOCSIFDSTADDR, (caddr_t)ia))) {
+ ia->ia_dstaddr = oldaddr;
+ return (error);
+ }
+ if (ia->ia_flags & IFA_ROUTE) {
+ ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&oldaddr;
+ rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
+ ia->ia_ifa.ifa_dstaddr =
+ (struct sockaddr *)&ia->ia_dstaddr;
+ rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
+ }
+ break;
+
+ case SIOCSIFBRDADDR:
+ if ((ifp->if_flags & IFF_BROADCAST) == 0)
+ return (EINVAL);
+ ia->ia_broadaddr = *(struct sockaddr_in *)&ifr->ifr_broadaddr;
+ break;
+
+ case SIOCSIFADDR:
+ return (in_ifinit(ifp, ia,
+ (struct sockaddr_in *) &ifr->ifr_addr, 1));
+
+ case SIOCSIFNETMASK:
+ ia->ia_sockmask.sin_addr = ifra->ifra_addr.sin_addr;
+ ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr);
+ break;
+
+ case SIOCAIFADDR:
+ maskIsNew = 0;
+ hostIsNew = 1;
+ error = 0;
+ if (ia->ia_addr.sin_family == AF_INET) {
+ if (ifra->ifra_addr.sin_len == 0) {
+ ifra->ifra_addr = ia->ia_addr;
+ hostIsNew = 0;
+ } else if (ifra->ifra_addr.sin_addr.s_addr ==
+ ia->ia_addr.sin_addr.s_addr)
+ hostIsNew = 0;
+ }
+ if (ifra->ifra_mask.sin_len) {
+ in_ifscrub(ifp, ia);
+ ia->ia_sockmask = ifra->ifra_mask;
+ ia->ia_subnetmask =
+ ntohl(ia->ia_sockmask.sin_addr.s_addr);
+ maskIsNew = 1;
+ }
+ if ((ifp->if_flags & IFF_POINTOPOINT) &&
+ (ifra->ifra_dstaddr.sin_family == AF_INET)) {
+ in_ifscrub(ifp, ia);
+ ia->ia_dstaddr = ifra->ifra_dstaddr;
+ maskIsNew = 1; /* We lie; but the effect's the same */
+ }
+ if (ifra->ifra_addr.sin_family == AF_INET &&
+ (hostIsNew || maskIsNew))
+ error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0);
+ if ((ifp->if_flags & IFF_BROADCAST) &&
+ (ifra->ifra_broadaddr.sin_family == AF_INET))
+ ia->ia_broadaddr = ifra->ifra_broadaddr;
+ return (error);
+
+ case SIOCDIFADDR:
+ mk = malloc(sizeof *mk, M_IPMADDR, M_WAITOK);
+ if (!mk)
+ return ENOBUFS;
+
+ in_ifscrub(ifp, ia);
+ /*
+ * Protect from ipintr() traversing address list
+ * while we're modifying it.
+ */
+ s = splnet();
+
+ if ((ifa = ifp->if_addrlist) == (struct ifaddr *)ia)
+ ifp->if_addrlist = ifa->ifa_next;
+ else {
+ while (ifa->ifa_next &&
+ (ifa->ifa_next != (struct ifaddr *)ia))
+ ifa = ifa->ifa_next;
+ if (ifa->ifa_next)
+ ifa->ifa_next = ((struct ifaddr *)ia)->ifa_next;
+ else
+ printf("Couldn't unlink inifaddr from ifp\n");
+ }
+ oia = ia;
+ if (oia == (ia = in_ifaddr))
+ in_ifaddr = ia->ia_next;
+ else {
+ while (ia->ia_next && (ia->ia_next != oia))
+ ia = ia->ia_next;
+ if (ia->ia_next)
+ ia->ia_next = oia->ia_next;
+ else
+ printf("Didn't unlink inifadr from list\n");
+ }
+
+ if (!oia->ia_multiaddrs.lh_first) {
+ IFAFREE(&oia->ia_ifa);
+ FREE(mk, M_IPMADDR);
+ splx(s);
+ break;
+ }
+
+ /*
+ * Multicast address kludge:
+ * If there were any multicast addresses attached to this
+ * interface address, either move them to another address
+ * on this interface, or save them until such time as this
+ * interface is reconfigured for IP.
+ */
+ IFP_TO_IA(oia->ia_ifp, ia);
+ if (ia) { /* there is another address */
+ struct in_multi *inm;
+ for(inm = oia->ia_multiaddrs.lh_first; inm;
+ inm = inm->inm_entry.le_next) {
+ IFAFREE(&inm->inm_ia->ia_ifa);
+ ia->ia_ifa.ifa_refcnt++;
+ inm->inm_ia = ia;
+ LIST_INSERT_HEAD(&ia->ia_multiaddrs, inm,
+ inm_entry);
+ }
+ FREE(mk, M_IPMADDR);
+ } else { /* last address on this if deleted, save */
+ struct in_multi *inm;
+
+ LIST_INIT(&mk->mk_head);
+ mk->mk_ifp = ifp;
+
+ for(inm = oia->ia_multiaddrs.lh_first; inm;
+ inm = inm->inm_entry.le_next) {
+ LIST_INSERT_HEAD(&mk->mk_head, inm, inm_entry);
+ }
+
+ if (mk->mk_head.lh_first) {
+ LIST_INSERT_HEAD(&in_mk, mk, mk_entry);
+ } else {
+ FREE(mk, M_IPMADDR);
+ }
+ }
+
+ IFAFREE((&oia->ia_ifa));
+ splx(s);
+ break;
+
+ default:
+ if (ifp == 0 || ifp->if_ioctl == 0)
+ return (EOPNOTSUPP);
+ return ((*ifp->if_ioctl)(ifp, cmd, data));
+ }
+ return (0);
+}
+
+/*
+ * Delete any existing route for an interface.
+ */
+static void
+in_ifscrub(struct ifnet *ifp, struct in_ifaddr *ia)
+{
+
+ if ((ia->ia_flags & IFA_ROUTE) == 0)
+ return;
+ if (ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT))
+ rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
+ else
+ rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0);
+ ia->ia_flags &= ~IFA_ROUTE;
+}
+
+/*
+ * Initialize an interface's internet address
+ * and routing table entry.
+ */
+static int
+in_ifinit(struct ifnet *ifp, struct in_ifaddr *ia, struct sockaddr_in *sin,
+ int scrub)
+{
+ register u_long i = ntohl(sin->sin_addr.s_addr);
+ struct sockaddr_in oldaddr;
+ int s = splimp(), flags = RTF_UP, error;
+ struct multi_kludge *mk;
+
+ oldaddr = ia->ia_addr;
+ ia->ia_addr = *sin;
+ /*
+ * Give the interface a chance to initialize
+ * if this is its first address,
+ * and to validate the address if necessary.
+ */
+ if (ifp->if_ioctl &&
+ (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia))) {
+ splx(s);
+ ia->ia_addr = oldaddr;
+ return (error);
+ }
+ splx(s);
+ if (scrub) {
+ ia->ia_ifa.ifa_addr = (struct sockaddr *)&oldaddr;
+ in_ifscrub(ifp, ia);
+ ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
+ }
+ if (IN_CLASSA(i))
+ ia->ia_netmask = IN_CLASSA_NET;
+ else if (IN_CLASSB(i))
+ ia->ia_netmask = IN_CLASSB_NET;
+ else
+ ia->ia_netmask = IN_CLASSC_NET;
+ /*
+ * The subnet mask usually includes at least the standard network part,
+ * but may may be smaller in the case of supernetting.
+ * If it is set, we believe it.
+ */
+ if (ia->ia_subnetmask == 0) {
+ ia->ia_subnetmask = ia->ia_netmask;
+ ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
+ } else
+ ia->ia_netmask &= ia->ia_subnetmask;
+ ia->ia_net = i & ia->ia_netmask;
+ ia->ia_subnet = i & ia->ia_subnetmask;
+ in_socktrim(&ia->ia_sockmask);
+ /*
+ * Add route for the network.
+ */
+ ia->ia_ifa.ifa_metric = ifp->if_metric;
+ if (ifp->if_flags & IFF_BROADCAST) {
+ ia->ia_broadaddr.sin_addr.s_addr =
+ htonl(ia->ia_subnet | ~ia->ia_subnetmask);
+ ia->ia_netbroadcast.s_addr =
+ htonl(ia->ia_net | ~ ia->ia_netmask);
+ } else if (ifp->if_flags & IFF_LOOPBACK) {
+ ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;
+ flags |= RTF_HOST;
+ } else if (ifp->if_flags & IFF_POINTOPOINT) {
+ if (ia->ia_dstaddr.sin_family != AF_INET)
+ return (0);
+ flags |= RTF_HOST;
+ }
+ if ((error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, flags)) == 0)
+ ia->ia_flags |= IFA_ROUTE;
+
+ LIST_INIT(&ia->ia_multiaddrs);
+ /*
+ * If the interface supports multicast, join the "all hosts"
+ * multicast group on that interface.
+ */
+ if (ifp->if_flags & IFF_MULTICAST) {
+ struct in_addr addr;
+
+ /*
+ * Continuation of multicast address hack:
+ * If there was a multicast group list previously saved
+ * for this interface, then we re-attach it to the first
+ * address configured on the i/f.
+ */
+ for(mk = in_mk.lh_first; mk; mk = mk->mk_entry.le_next) {
+ if(mk->mk_ifp == ifp) {
+ struct in_multi *inm;
+
+ for(inm = mk->mk_head.lh_first; inm;
+ inm = inm->inm_entry.le_next) {
+ IFAFREE(&inm->inm_ia->ia_ifa);
+ ia->ia_ifa.ifa_refcnt++;
+ inm->inm_ia = ia;
+ LIST_INSERT_HEAD(&ia->ia_multiaddrs,
+ inm, inm_entry);
+ }
+ LIST_REMOVE(mk, mk_entry);
+ free(mk, M_IPMADDR);
+ break;
+ }
+ }
+
+ addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
+ in_addmulti(&addr, ifp);
+ }
+ return (error);
+}
+
+
+/*
+ * Return 1 if the address might be a local broadcast address.
+ */
+int
+in_broadcast(struct in_addr in, struct ifnet *ifp)
+{
+ register struct ifaddr *ifa;
+ u_long t;
+
+ if (in.s_addr == INADDR_BROADCAST ||
+ in.s_addr == INADDR_ANY)
+ return 1;
+ if ((ifp->if_flags & IFF_BROADCAST) == 0)
+ return 0;
+ t = ntohl(in.s_addr);
+ /*
+ * Look through the list of addresses for a match
+ * with a broadcast address.
+ */
+#define ia ((struct in_ifaddr *)ifa)
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+ if (ifa->ifa_addr->sa_family == AF_INET &&
+ (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
+ in.s_addr == ia->ia_netbroadcast.s_addr ||
+ /*
+ * Check for old-style (host 0) broadcast.
+ */
+ t == ia->ia_subnet || t == ia->ia_net) &&
+ /*
+ * Check for an all one subnetmask. These
+ * only exist when an interface gets a secondary
+ * address.
+ */
+ ia->ia_subnetmask != (u_long)0xffffffff)
+ return 1;
+ return (0);
+#undef ia
+}
+/*
+ * Add an address to the list of IP multicast addresses for a given interface.
+ */
+struct in_multi *
+in_addmulti(struct in_addr *ap, struct ifnet *ifp)
+{
+ register struct in_multi *inm;
+ struct ifreq ifr;
+ struct in_ifaddr *ia;
+ int s = splnet();
+
+ /*
+ * See if address already in list.
+ */
+ IN_LOOKUP_MULTI(*ap, ifp, inm);
+ if (inm != NULL) {
+ /*
+ * Found it; just increment the reference count.
+ */
+ ++inm->inm_refcount;
+ }
+ else {
+ /*
+ * New address; allocate a new multicast record
+ * and link it into the interface's multicast list.
+ */
+ inm = (struct in_multi *)malloc(sizeof(*inm),
+ M_IPMADDR, M_NOWAIT);
+ if (inm == NULL) {
+ splx(s);
+ return (NULL);
+ }
+ inm->inm_addr = *ap;
+ inm->inm_ifp = ifp;
+ inm->inm_refcount = 1;
+ IFP_TO_IA(ifp, ia);
+ if (ia == NULL) {
+ free(inm, M_IPMADDR);
+ splx(s);
+ return (NULL);
+ }
+ inm->inm_ia = ia;
+ ia->ia_ifa.ifa_refcnt++; /* gain a reference */
+ LIST_INSERT_HEAD(&ia->ia_multiaddrs, inm, inm_entry);
+
+ /*
+ * Ask the network driver to update its multicast reception
+ * filter appropriately for the new address.
+ */
+ ((struct sockaddr_in *)&ifr.ifr_addr)->sin_family = AF_INET;
+ ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr = *ap;
+ if ((ifp->if_ioctl == NULL) ||
+ (*ifp->if_ioctl)(ifp, SIOCADDMULTI,(caddr_t)&ifr) != 0) {
+ LIST_REMOVE(inm, inm_entry);
+ IFAFREE(&ia->ia_ifa); /* release reference */
+ free(inm, M_IPMADDR);
+ splx(s);
+ return (NULL);
+ }
+ /*
+ * Let IGMP know that we have joined a new IP multicast group.
+ */
+ igmp_joingroup(inm);
+ }
+ splx(s);
+ return (inm);
+}
+
+/*
+ * Delete a multicast address record.
+ */
+void
+in_delmulti(struct in_multi *inm)
+{
+ struct ifreq ifr;
+ int s = splnet();
+
+ if (--inm->inm_refcount == 0) {
+ /*
+ * No remaining claims to this record; let IGMP know that
+ * we are leaving the multicast group.
+ */
+ igmp_leavegroup(inm);
+ /*
+ * Unlink from list.
+ */
+ LIST_REMOVE(inm, inm_entry);
+ IFAFREE(&inm->inm_ia->ia_ifa); /* release reference */
+
+ /*
+ * Notify the network driver to update its multicast reception
+ * filter.
+ */
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_family = AF_INET;
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr =
+ inm->inm_addr;
+ (*inm->inm_ifp->if_ioctl)(inm->inm_ifp, SIOCDELMULTI,
+ (caddr_t)&ifr);
+ free(inm, M_IPMADDR);
+ }
+ splx(s);
+}
diff --git a/cpukit/libnetworking/netinet/in.h b/cpukit/libnetworking/netinet/in.h
new file mode 100644
index 0000000000..31f9f98dbf
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in.h
@@ -0,0 +1,461 @@
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in.h 8.3 (Berkeley) 1/3/94
+ * $FreeBSD: src/sys/netinet/in.h,v 1.91 2005/08/22 16:13:07 andre Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IN_H_
+#define _NETINET_IN_H_
+
+#include <rtems/bsdnet/_types.h>
+#include <rtems/endian.h>
+
+#ifndef _IN_ADDR_T_DECLARED
+typedef uint32_t in_addr_t;
+#define _IN_ADDR_T_DECLARED
+#endif
+
+/* Protocols common to RFC 1700, POSIX, and X/Open. */
+#define IPPROTO_IP 0 /* dummy for IP */
+#define IPPROTO_ICMP 1 /* control message protocol */
+#define IPPROTO_TCP 6 /* tcp */
+#define IPPROTO_UDP 17 /* user datagram protocol */
+
+#define INADDR_ANY (u_int32_t)0x00000000
+#define INADDR_BROADCAST (u_int32_t)0xffffffff /* must be masked */
+
+#ifndef _IN_PORT_T_DECLARED
+typedef uint16_t in_port_t;
+#define _IN_PORT_T_DECLARED
+#endif
+
+#ifndef _SA_FAMILY_T_DECLARED
+typedef __sa_family_t sa_family_t;
+#define _SA_FAMILY_T_DECLARED
+#endif
+
+/* Internet address (a structure for historical reasons). */
+#ifndef _STRUCT_IN_ADDR_DECLARED
+struct in_addr {
+ in_addr_t s_addr;
+};
+#define _STRUCT_IN_ADDR_DECLARED
+#endif
+
+/* Socket address, internet style. */
+struct sockaddr_in {
+ uint8_t sin_len;
+ sa_family_t sin_family;
+ in_port_t sin_port;
+ struct in_addr sin_addr;
+ char sin_zero[8];
+};
+
+
+/*
+ * Constants and structures defined by the internet system,
+ * Per RFC 790, September 1981, and numerous additions.
+ */
+
+/*
+ * Protocols (RFC 1700)
+ */
+#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */
+#define IPPROTO_IGMP 2 /* group mgmt protocol */
+#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
+#define IPPROTO_IPV4 4 /* IPv4 encapsulation */
+#define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */
+#define IPPROTO_ST 7 /* Stream protocol II */
+#define IPPROTO_EGP 8 /* exterior gateway protocol */
+#define IPPROTO_PIGP 9 /* private interior gateway */
+#define IPPROTO_RCCMON 10 /* BBN RCC Monitoring */
+#define IPPROTO_NVPII 11 /* network voice protocol*/
+#define IPPROTO_PUP 12 /* pup */
+#define IPPROTO_ARGUS 13 /* Argus */
+#define IPPROTO_EMCON 14 /* EMCON */
+#define IPPROTO_XNET 15 /* Cross Net Debugger */
+#define IPPROTO_CHAOS 16 /* Chaos*/
+#define IPPROTO_MUX 18 /* Multiplexing */
+#define IPPROTO_MEAS 19 /* DCN Measurement Subsystems */
+#define IPPROTO_HMP 20 /* Host Monitoring */
+#define IPPROTO_PRM 21 /* Packet Radio Measurement */
+#define IPPROTO_IDP 22 /* xns idp */
+#define IPPROTO_TRUNK1 23 /* Trunk-1 */
+#define IPPROTO_TRUNK2 24 /* Trunk-2 */
+#define IPPROTO_LEAF1 25 /* Leaf-1 */
+#define IPPROTO_LEAF2 26 /* Leaf-2 */
+#define IPPROTO_RDP 27 /* Reliable Data */
+#define IPPROTO_IRTP 28 /* Reliable Transaction */
+#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
+#define IPPROTO_BLT 30 /* Bulk Data Transfer */
+#define IPPROTO_NSP 31 /* Network Services */
+#define IPPROTO_INP 32 /* Merit Internodal */
+#define IPPROTO_SEP 33 /* Sequential Exchange */
+#define IPPROTO_3PC 34 /* Third Party Connect */
+#define IPPROTO_IDPR 35 /* InterDomain Policy Routing */
+#define IPPROTO_XTP 36 /* XTP */
+#define IPPROTO_DDP 37 /* Datagram Delivery */
+#define IPPROTO_CMTP 38 /* Control Message Transport */
+#define IPPROTO_TPXX 39 /* TP++ Transport */
+#define IPPROTO_IL 40 /* IL transport protocol */
+#define IPPROTO_IPV6 41 /* IP6 header */
+#define IPPROTO_SDRP 42 /* Source Demand Routing */
+#define IPPROTO_ROUTING 43 /* IP6 routing header */
+#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */
+#define IPPROTO_IDRP 45 /* InterDomain Routing*/
+#define IPPROTO_RSVP 46 /* resource reservation */
+#define IPPROTO_GRE 47 /* General Routing Encap. */
+#define IPPROTO_MHRP 48 /* Mobile Host Routing */
+#define IPPROTO_BHA 49 /* BHA */
+#define IPPROTO_ESP 50 /* IP6 Encap Sec. Payload */
+#define IPPROTO_AH 51 /* IP6 Auth Header */
+#define IPPROTO_INLSP 52 /* Integ. Net Layer Security */
+#define IPPROTO_SWIPE 53 /* IP with encryption */
+#define IPPROTO_NHRP 54 /* Next Hop Resolution */
+#define IPPROTO_MOBILE 55 /* IP Mobility */
+#define IPPROTO_TLSP 56 /* Transport Layer Security */
+#define IPPROTO_SKIP 57 /* SKIP */
+#define IPPROTO_ICMPV6 58 /* ICMP6 */
+#define IPPROTO_NONE 59 /* IP6 no next header */
+#define IPPROTO_DSTOPTS 60 /* IP6 destination option */
+#define IPPROTO_AHIP 61 /* any host internal protocol */
+#define IPPROTO_CFTP 62 /* CFTP */
+#define IPPROTO_HELLO 63 /* "hello" routing protocol */
+#define IPPROTO_SATEXPAK 64 /* SATNET/Backroom EXPAK */
+#define IPPROTO_KRYPTOLAN 65 /* Kryptolan */
+#define IPPROTO_RVD 66 /* Remote Virtual Disk */
+#define IPPROTO_IPPC 67 /* Pluribus Packet Core */
+#define IPPROTO_ADFS 68 /* Any distributed FS */
+#define IPPROTO_SATMON 69 /* Satnet Monitoring */
+#define IPPROTO_VISA 70 /* VISA Protocol */
+#define IPPROTO_IPCV 71 /* Packet Core Utility */
+#define IPPROTO_CPNX 72 /* Comp. Prot. Net. Executive */
+#define IPPROTO_CPHB 73 /* Comp. Prot. HeartBeat */
+#define IPPROTO_WSN 74 /* Wang Span Network */
+#define IPPROTO_PVP 75 /* Packet Video Protocol */
+#define IPPROTO_BRSATMON 76 /* BackRoom SATNET Monitoring */
+#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */
+#define IPPROTO_WBMON 78 /* WIDEBAND Monitoring */
+#define IPPROTO_WBEXPAK 79 /* WIDEBAND EXPAK */
+#define IPPROTO_EON 80 /* ISO cnlp */
+#define IPPROTO_VMTP 81 /* VMTP */
+#define IPPROTO_SVMTP 82 /* Secure VMTP */
+#define IPPROTO_VINES 83 /* Banyon VINES */
+#define IPPROTO_TTP 84 /* TTP */
+#define IPPROTO_IGP 85 /* NSFNET-IGP */
+#define IPPROTO_DGP 86 /* dissimilar gateway prot. */
+#define IPPROTO_TCF 87 /* TCF */
+#define IPPROTO_IGRP 88 /* Cisco/GXS IGRP */
+#define IPPROTO_OSPFIGP 89 /* OSPFIGP */
+#define IPPROTO_SRPC 90 /* Strite RPC protocol */
+#define IPPROTO_LARP 91 /* Locus Address Resoloution */
+#define IPPROTO_MTP 92 /* Multicast Transport */
+#define IPPROTO_AX25 93 /* AX.25 Frames */
+#define IPPROTO_IPEIP 94 /* IP encapsulated in IP */
+#define IPPROTO_MICP 95 /* Mobile Int.ing control */
+#define IPPROTO_SCCSP 96 /* Semaphore Comm. security */
+#define IPPROTO_ETHERIP 97 /* Ethernet IP encapsulation */
+#define IPPROTO_ENCAP 98 /* encapsulation header */
+#define IPPROTO_APES 99 /* any private encr. scheme */
+#define IPPROTO_GMTP 100 /* GMTP*/
+#define IPPROTO_IPCOMP 108 /* payload compression (IPComp) */
+/* 101-254: Partly Unassigned */
+#define IPPROTO_PIM 103 /* Protocol Independent Mcast */
+#define IPPROTO_CARP 112 /* CARP */
+#define IPPROTO_PGM 113 /* PGM */
+#define IPPROTO_PFSYNC 240 /* PFSYNC */
+/* 255: Reserved */
+/* BSD Private, local use, namespace incursion */
+#define IPPROTO_DIVERT 254 /* divert pseudo-protocol */
+#define IPPROTO_RAW 255 /* raw IP packet */
+#define IPPROTO_MAX 256
+
+/*
+ * Merged from FreeBSD 1.78 of this file so Python compiles.
+ * This is a size value for functions such as inet_ntop().
+ */
+#define INET_ADDRSTRLEN 16
+
+/*
+ * Local port number conventions:
+ *
+ * When a user does a bind(2) or connect(2) with a port number of zero,
+ * a non-conflicting local port address is chosen.
+ * The default range is IPPORT_HIFIRSTAUTO through
+ * IPPORT_HILASTAUTO, although that is settable by sysctl.
+ *
+ * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
+ * default assignment range.
+ *
+ * The value IP_PORTRANGE_DEFAULT causes the default behavior.
+ *
+ * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
+ * into the "high" range. These are reserved for client outbound connections
+ * which do not want to be filtered by any firewalls.
+ *
+ * The value IP_PORTRANGE_LOW changes the range to the "low" are
+ * that is (by convention) restricted to privileged processes. This
+ * convention is based on "vouchsafe" principles only. It is only secure
+ * if you trust the remote host to restrict these ports.
+ *
+ * The default range of ports and the high range can be changed by
+ * sysctl(3). (net.inet.ip.port{hi,low}{first,last}_auto)
+ *
+ * Changing those values has bad security implications if you are
+ * using a stateless firewall that is allowing packets outside of that
+ * range in order to allow transparent outgoing connections.
+ *
+ * Such a firewall configuration will generally depend on the use of these
+ * default values. If you change them, you may find your Security
+ * Administrator looking for you with a heavy object.
+ */
+
+/*
+ * Ports < IPPORT_RESERVED are reserved for
+ * privileged processes (e.g. root). (IP_PORTRANGE_LOW)
+ * Ports > IPPORT_USERRESERVED are reserved
+ * for servers, not necessarily privileged. (IP_PORTRANGE_DEFAULT)
+ */
+#define IPPORT_RESERVED 1024
+#define IPPORT_USERRESERVED 5000
+
+/*
+ * Default local port range to use by setting IP_PORTRANGE_HIGH
+ */
+#define IPPORT_HIFIRSTAUTO 40000
+#define IPPORT_HILASTAUTO 44999
+
+/*
+ * Scanning for a free reserved port return a value below IPPORT_RESERVED,
+ * but higher than IPPORT_RESERVEDSTART. Traditionally the start value was
+ * 512, but that conflicts with some well-known-services that firewalls may
+ * have a fit if we use.
+ */
+#define IPPORT_RESERVEDSTART 600
+/*
+ * Definitions of bits in internet address integers.
+ * On subnets, the decomposition of addresses to host and net parts
+ * is done according to subnet mask, not the masks here.
+ */
+#define IN_CLASSA(i) (((u_int32_t)(i) & 0x80000000) == 0)
+#define IN_CLASSA_NET 0xff000000
+#define IN_CLASSA_NSHIFT 24
+#define IN_CLASSA_HOST 0x00ffffff
+#define IN_CLASSA_MAX 128
+
+#define IN_CLASSB(i) (((u_int32_t)(i) & 0xc0000000) == 0x80000000)
+#define IN_CLASSB_NET 0xffff0000
+#define IN_CLASSB_NSHIFT 16
+#define IN_CLASSB_HOST 0x0000ffff
+#define IN_CLASSB_MAX 65536
+
+#define IN_CLASSC(i) (((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
+#define IN_CLASSC_NET 0xffffff00
+#define IN_CLASSC_NSHIFT 8
+#define IN_CLASSC_HOST 0x000000ff
+
+#define IN_CLASSD(i) (((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
+#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
+#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
+#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
+#define IN_MULTICAST(i) IN_CLASSD(i)
+
+#define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
+#define IN_BADCLASS(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
+
+#define INADDR_LOOPBACK (u_int32_t)0x7f000001
+#ifndef _KERNEL
+#define INADDR_NONE 0xffffffff /* -1 return */
+#endif
+
+#define INADDR_UNSPEC_GROUP (u_int32_t)0xe0000000 /* 224.0.0.0 */
+#define INADDR_ALLHOSTS_GROUP (u_int32_t)0xe0000001 /* 224.0.0.1 */
+#define INADDR_ALLRTRS_GROUP (u_int32_t)0xe0000002 /* 224.0.0.2 */
+#define INADDR_MAX_LOCAL_GROUP (u_int32_t)0xe00000ff /* 224.0.0.255 */
+
+#define IN_LOOPBACKNET (u_int32_t)127 /* official! */
+
+/*
+ * Options for use with [gs]etsockopt at the IP level.
+ * First word of comment is data type; bool is stored in int.
+ */
+#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */
+#define IP_HDRINCL 2 /* int; header is included with data */
+#define IP_TOS 3 /* int; IP type of service and preced. */
+#define IP_TTL 4 /* int; IP time to live */
+#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */
+#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */
+#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */
+#define IP_SENDSRCADDR IP_RECVDSTADDR /* cmsg_type to set src addr */
+#define IP_RETOPTS 8 /* ip_opts; set/get IP options */
+#define IP_MULTICAST_IF 9 /* u_char; set/get IP multicast i/f */
+#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */
+#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */
+#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */
+#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */
+#define IP_MULTICAST_VIF 14 /* set/get IP mcast virt. iface */
+#define IP_RSVP_ON 15 /* enable RSVP in kernel */
+#define IP_RSVP_OFF 16 /* disable RSVP in kernel */
+#define IP_RSVP_VIF_ON 17 /* set RSVP per-vif socket */
+#define IP_RSVP_VIF_OFF 18 /* unset RSVP per-vif socket */
+#define IP_PORTRANGE 19 /* int; range to choose for unspec port */
+#define IP_RECVIF 20 /* bool; receive reception if w/dgram */
+
+#define IP_FW_ADD 50 /* add a firewall rule to chain */
+#define IP_FW_DEL 51 /* delete a firewall rule from chain */
+#define IP_FW_FLUSH 52 /* flush firewall rule chain */
+#define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */
+#define IP_FW_GET 54 /* get entire firewall rule chain */
+#define IP_NAT 55 /* set/get NAT opts */
+
+/*
+ * Defaults and limits for options
+ */
+#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
+#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
+#define IP_MAX_MEMBERSHIPS 20 /* per socket */
+
+/*
+ * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
+ */
+struct ip_mreq {
+ struct in_addr imr_multiaddr; /* IP multicast address of group */
+ struct in_addr imr_interface; /* local IP address of interface */
+};
+
+/*
+ * Argument for IP_PORTRANGE:
+ * - which range to search when port is unspecified at bind() or connect()
+ */
+#define IP_PORTRANGE_DEFAULT 0 /* default range */
+#define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
+#define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
+
+/*
+ * Definitions for inet sysctl operations.
+ *
+ * Third level is protocol number.
+ * Fourth level is desired variable within that protocol.
+ */
+#define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */
+
+#define CTL_IPPROTO_NAMES { \
+ { "ip", CTLTYPE_NODE }, \
+ { "icmp", CTLTYPE_NODE }, \
+ { "igmp", CTLTYPE_NODE }, \
+ { "ggp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "tcp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { "egp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "pup", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "udp", CTLTYPE_NODE }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { 0, 0 }, \
+ { "idp", CTLTYPE_NODE }, \
+}
+
+/*
+ * Names for IP sysctl objects
+ */
+#define IPCTL_FORWARDING 1 /* act as router */
+#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */
+#define IPCTL_DEFTTL 3 /* default TTL */
+#ifdef notyet
+#define IPCTL_DEFMTU 4 /* default MTU */
+#endif
+#define IPCTL_RTEXPIRE 5 /* cloned route expiration time */
+#define IPCTL_RTMINEXPIRE 6 /* min value for expiration time */
+#define IPCTL_RTMAXCACHE 7 /* trigger level for dynamic expire */
+#define IPCTL_SOURCEROUTE 8 /* may perform source routes */
+#define IPCTL_DIRECTEDBROADCAST 9 /* may re-broadcast received packets */
+#define IPCTL_INTRQMAXLEN 10 /* max length of netisr queue */
+#define IPCTL_INTRQDROPS 11 /* number of netisr q drops */
+#define IPCTL_ACCEPTSOURCEROUTE 13 /* may accept source routed packets */
+#define IPCTL_MAXID 13
+
+#define IPCTL_NAMES { \
+ { 0, 0 }, \
+ { "forwarding", CTLTYPE_INT }, \
+ { "redirect", CTLTYPE_INT }, \
+ { "ttl", CTLTYPE_INT }, \
+ { "mtu", CTLTYPE_INT }, \
+ { "rtexpire", CTLTYPE_INT }, \
+ { "rtminexpire", CTLTYPE_INT }, \
+ { "rtmaxcache", CTLTYPE_INT }, \
+ { "sourceroute", CTLTYPE_INT }, \
+ { "directed-broadcast", CTLTYPE_INT }, \
+ { "intr-queue-maxlen", CTLTYPE_INT }, \
+ { "intr-queue-drops", CTLTYPE_INT }, \
+ { "accept_sourceroute", CTLTYPE_INT }, \
+}
+
+
+#ifdef _KERNEL
+
+struct ifnet; struct mbuf; /* forward declarations for Standard C */
+
+int in_broadcast(struct in_addr, struct ifnet *);
+int in_canforward(struct in_addr);
+int in_cksum(struct mbuf *, int);
+int in_localaddr(struct in_addr);
+char *inet_ntoa(struct in_addr); /* in libkern */
+
+/* Firewall hooks */
+struct ip;
+typedef int ip_fw_chk_t(struct ip**, int, struct ifnet*, int, struct mbuf**);
+typedef int ip_fw_ctl_t(int, struct mbuf**);
+extern ip_fw_chk_t *ip_fw_chk_ptr;
+extern ip_fw_ctl_t *ip_fw_ctl_ptr;
+
+/* IP NAT hooks */
+typedef int ip_nat_t(struct ip**, struct mbuf**, struct ifnet*, int);
+typedef int ip_nat_ctl_t(int, struct mbuf**);
+extern ip_nat_t *ip_nat_ptr;
+extern ip_nat_ctl_t *ip_nat_ctl_ptr;
+#define IP_NAT_IN 0x00000001
+#define IP_NAT_OUT 0x00000002
+
+#endif /* _KERNEL */
+
+#endif /* !_NETINET_IN_H_*/
diff --git a/cpukit/libnetworking/netinet/in_cksum.c b/cpukit/libnetworking/netinet/in_cksum.c
new file mode 100644
index 0000000000..39e85e14ae
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_cksum.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 1988, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/mbuf.h>
+
+/*
+ * Try to use a CPU specific version, then punt to the portable C one.
+ */
+
+
+#if (defined(__GNUC__) && (defined(__arm__) && !defined(__thumb__)))
+
+/* This currently does not support Thumb assembly */
+#include "in_cksum_arm.h"
+
+#elif (defined(__GNUC__) && defined(__i386__))
+
+#include "in_cksum_i386.h"
+
+#elif (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)))
+
+#include "in_cksum_m68k.h"
+#elif (defined(__GNUC__) && defined(__PPC__))
+
+#include "in_cksum_powerpc.h"
+
+#else
+
+#include <stdio.h> /* for puts */
+
+/*
+ * Checksum routine for Internet Protocol family headers (Portable Version).
+ *
+ * This routine is very heavily used in the network
+ * code and should be modified for each CPU to be as fast as possible.
+ */
+
+#define ADDCARRY(x) (x > 65535L ? x -= 65535L : x)
+#define REDUCE \
+ {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}
+
+int
+in_cksum(
+ struct mbuf *m,
+ uint32_t len )
+{
+ register u_short *w;
+ register int32_t sum = 0;
+ register int32_t mlen = 0;
+ int byte_swapped = 0;
+
+ union {
+ char c[2];
+ u_short s;
+ } s_util;
+ union {
+ u_short s[2];
+ long l;
+ } l_util;
+
+ for (;m && len; m = m->m_next) {
+ if (m->m_len == 0)
+ continue;
+ w = mtod(m, u_short *);
+ if (mlen == -1) {
+ /*
+ * The first byte of this mbuf is the continuation
+ * of a word spanning between this mbuf and the
+ * last mbuf.
+ *
+ * s_util.c[0] is already saved when scanning previous
+ * mbuf.
+ */
+ s_util.c[1] = *(char *)w;
+ sum += s_util.s;
+ w = (u_short *)((char *)w + 1);
+ mlen = m->m_len - 1;
+ len--;
+ } else
+ mlen = m->m_len;
+ if (len < mlen)
+ mlen = len;
+ len -= mlen;
+ /*
+ * Force to even boundary.
+ */
+ if ((1 & (intptr_t) w) && (mlen > 0)) {
+ REDUCE;
+ sum <<= 8;
+ s_util.c[0] = *(u_char *)w;
+ w = (u_short *)((char *)w + 1);
+ mlen--;
+ byte_swapped = 1;
+ }
+ /*
+ * Unroll the loop to make overhead from
+ * branches &c small.
+ */
+ while ((mlen -= 32) >= 0) {
+ sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];
+ sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];
+ sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];
+ sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];
+ w += 16;
+ }
+ mlen += 32;
+ while ((mlen -= 8) >= 0) {
+ sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];
+ w += 4;
+ }
+ mlen += 8;
+ if (mlen == 0 && byte_swapped == 0)
+ continue;
+ REDUCE;
+ while ((mlen -= 2) >= 0) {
+ sum += *w++;
+ }
+ if (byte_swapped) {
+ REDUCE;
+ sum <<= 8;
+ byte_swapped = 0;
+ if (mlen == -1) {
+ s_util.c[1] = *(char *)w;
+ sum += s_util.s;
+ mlen = 0;
+ } else
+ mlen = -1;
+ } else if (mlen == -1)
+ s_util.c[0] = *(char *)w;
+ }
+ if (len)
+ puts("cksum: out of data");
+ if (mlen == -1) {
+ /* The last mbuf has odd # of bytes. Follow the
+ standard (the odd byte may be shifted left by 8 bits
+ or not as determined by endian-ness of the machine) */
+ s_util.c[1] = 0;
+ sum += s_util.s;
+ }
+ REDUCE;
+ return (~sum & 0xffff);
+}
+#endif
diff --git a/cpukit/libnetworking/netinet/in_cksum_arm.h b/cpukit/libnetworking/netinet/in_cksum_arm.h
new file mode 100644
index 0000000000..74a3c6839e
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_cksum_arm.h
@@ -0,0 +1,277 @@
+/* $NetBSD: in_cksum_arm.c,v 1.3 2001/12/08 21:18:50 chris Exp $ */
+
+/*
+ * ARM version:
+ *
+ * Copyright (c) 1997 Mark Brinicome
+ * Copyright (c) 1997 Causality Limited
+ *
+ * Based on the sparc version.
+ */
+
+/*
+ * Sparc version:
+ *
+ * Copyright (c) 1995 Zubin Dittia.
+ * Copyright (c) 1995 Matthew R. Green.
+ * Copyright (c) 1994 Charles M. Hannum.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_cksum.c 8.1 (Berkeley) 6/11/93
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+
+/*
+ * Checksum routine for Internet Protocol family headers.
+ *
+ * This routine is very heavily used in the network
+ * code and should be modified for each CPU to be as fast as possible.
+ *
+ * ARM version.
+ */
+
+#define ADD64 __asm __volatile(" \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adds %1,%7,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adcs %1,%1,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adcs %1,%1,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adcs %1,%1,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ adcs %1,%1,#0\n" \
+ : "=r" (w), "=r" (sum), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
+ : "0" (w), "r" (sum) \
+ : "cc")
+
+#define ADD32 __asm __volatile(" \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adds %1,%7,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adcs %1,%1,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ adcs %1,%1,#0\n" \
+ : "=r" (w), "=r" (sum), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
+ : "0" (w), "r" (sum) \
+ : "cc")
+
+#define ADD16 __asm __volatile(" \n\
+ ldmia %0!, {%2, %3, %4, %5} \n\
+ adds %1,%7,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,%4; adcs %1,%1,%5 \n\
+ adcs %1,%1,#0\n" \
+ : "=r" (w), "=r" (sum), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
+ : "0" (w), "r" (sum) \
+ : "cc")
+
+#define ADD8 __asm __volatile(" \n\
+ ldmia %0!, {%2, %3} \n\
+ adds %1,%5,%2; adcs %1,%1,%3 \n\
+ adcs %1,%1,#0\n" \
+ : "=r" (w), "=r" (sum), "=&r" (tmp1), "=&r" (tmp2) \
+ : "0" (w), "r" (sum) \
+ : "cc" )
+
+#define ADD4 __asm __volatile(" \n\
+ ldr %2,[%0],#4 \n\
+ adds %1,%4,%2 \n\
+ adcs %1,%1,#0\n" \
+ : "=r" (w), "=r" (sum), "=&r" (tmp1) \
+ : "0" (w), "r" (sum) \
+ : "cc")
+
+/*#define REDUCE {sum = (sum & 0xffff) + (sum >> 16);}*/
+#define REDUCE __asm __volatile(" \n\
+ mov %2, #0x00ff \n\
+ orr %2, %2, #0xff00 \n\
+ and %2, %0, %2 \n\
+ add %0, %2, %0, lsr #16\n" \
+ : "=r" (sum) \
+ : "0" (sum), "r" (tmp1))
+
+#define ADDCARRY {if (sum > 0xffff) sum -= 0xffff;}
+#define ROL {sum = sum << 8;} /* depends on recent REDUCE */
+#define ADDBYTE {ROL; sum += (*w << 8); byte_swapped ^= 1;}
+#define ADDSHORT {sum += *(u_short *)w;}
+#define ADVANCE(n) {w += n; mlen -= n;}
+#define ADVANCEML(n) {mlen -= n;}
+
+static __inline__ int
+in_cksum_internal(struct mbuf *m, int off, int len, u_int sum)
+{
+ u_char *w;
+ int mlen = 0;
+ int byte_swapped = 0;
+
+ /*
+ * Declare four temporary registers for use by the asm code. We
+ * allow the compiler to pick which specific machine registers to
+ * use, instead of hard-coding this in the asm code above.
+ */
+ register u_int tmp1=0, tmp2, tmp3, tmp4;
+
+ for (; m && len; m = m->m_next) {
+ if (m->m_len == 0)
+ continue;
+ w = mtod(m, u_char *) + off;
+ mlen = m->m_len - off;
+ off = 0;
+ if (len < mlen)
+ mlen = len;
+ len -= mlen;
+
+ /*
+ * Ensure that we're aligned on a word boundary here so
+ * that we can do 32 bit operations below.
+ */
+ if ((3 & (long)w) != 0) {
+ REDUCE;
+ if ((1 & (long)w) != 0 && mlen >= 1) {
+ ADDBYTE;
+ ADVANCE(1);
+ }
+ if ((2 & (long)w) != 0 && mlen >= 2) {
+ ADDSHORT;
+ ADVANCE(2);
+ }
+ }
+
+ /*
+ * Do as many 32 bit operations as possible using the
+ * 64/32/16/8/4 macro's above, using as many as possible of
+ * these.
+ */
+
+ while (mlen >= 64) {
+ ADD64;
+ ADVANCEML(64);
+ }
+ if (mlen >= 32) {
+ ADD32;
+ ADVANCEML(32);
+ }
+ if (mlen >= 16) {
+ ADD16;
+ ADVANCEML(16);
+ }
+ if (mlen >= 8) {
+ ADD8;
+ ADVANCEML(8);
+ }
+ if (mlen >= 4) {
+ ADD4;
+ ADVANCEML(4)
+ }
+ if (mlen == 0)
+ continue;
+
+ REDUCE;
+ if (mlen >= 2) {
+ ADDSHORT;
+ ADVANCE(2);
+ }
+ if (mlen == 1) {
+ ADDBYTE;
+ }
+ }
+ if (byte_swapped) {
+ REDUCE;
+ ROL;
+ }
+ REDUCE;
+ ADDCARRY;
+
+ return (0xffff ^ sum);
+}
+
+int
+in_cksum(
+ struct mbuf *m,
+ int len)
+{
+ int cksum;
+ cksum =in_cksum_internal(m, 0, len, 0);
+ return cksum;
+}
+
+int
+in4_cksum(
+ struct mbuf *m,
+ u_int8_t nxt,
+ int off,
+ int len )
+{
+ u_int sum = 0;
+
+ if (nxt != 0) {
+ /* for ADD macros */
+ register u_int tmp1, tmp2, tmp3, tmp4;
+ u_char *w;
+ struct ipovly ipov;
+ /* pseudo header */
+ if (off < sizeof(struct ipovly))
+ panic("in4_cksum: offset too short");
+ if (m->m_len < sizeof(struct ip))
+ panic("in4_cksum: bad mbuf chain");
+
+ bzero(&ipov, sizeof(ipov));
+ ipov.ih_len = htons(len);
+ ipov.ih_pr = nxt;
+ ipov.ih_src = mtod(m, struct ip *)->ip_src;
+ ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+ w = (u_char *)&ipov;
+
+ /* assumes sizeof(ipov) == 20 */
+ ADD16;
+ ADD4;
+ }
+ /* skip unnecessary part */
+ while (m && off > 0) {
+ if (m->m_len > off)
+ break;
+ off -= m->m_len;
+ m = m->m_next;
+ }
+ return (in_cksum_internal(m, off, len, sum));
+}
diff --git a/cpukit/libnetworking/netinet/in_cksum_i386.h b/cpukit/libnetworking/netinet/in_cksum_i386.h
new file mode 100644
index 0000000000..c7e03511f9
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_cksum_i386.h
@@ -0,0 +1,204 @@
+/*
+ * Checksum routine for Internet Protocol family headers.
+ *
+ * This routine is very heavily used in the network
+ * code and should be modified for each CPU to be as fast as possible.
+ *
+ * This implementation is 386 version.
+ *
+ * $Id$
+ */
+
+#include <stdio.h> /* for puts */
+
+#undef ADDCARRY
+#define ADDCARRY(x) if ((x) > 0xffff) (x) -= 0xffff
+#define REDUCE {sum = (sum & 0xffff) + (sum >> 16); ADDCARRY(sum);}
+
+/*
+ * Thanks to gcc we don't have to guess
+ * which registers contain sum & w.
+ */
+#define ADD(n) __asm__ volatile \
+ ("addl " #n "(%2), %0" : "=r" (sum) : "0" (sum), "r" (w))
+#define ADDC(n) __asm__ volatile \
+ ("adcl " #n "(%2), %0" : "=r" (sum) : "0" (sum), "r" (w))
+#define LOAD(n) __asm__ volatile \
+ ("movb " #n "(%1), %0" : "=q" (junk) : "r" (w))
+#define MOP __asm__ volatile \
+ ("adcl $0, %0" : "=r" (sum) : "0" (sum))
+
+int
+in_cksum(
+ struct mbuf *m,
+ int len )
+{
+ register u_short *w;
+ register unsigned sum = 0;
+ register int mlen = 0;
+ int byte_swapped = 0;
+ union { char c[2]; u_short s; } su;
+
+ for (;m && len; m = m->m_next) {
+ if (m->m_len == 0)
+ continue;
+ w = mtod(m, u_short *);
+ if (mlen == -1) {
+ /*
+ * The first byte of this mbuf is the continuation
+ * of a word spanning between this mbuf and the
+ * last mbuf.
+ */
+
+ /* su.c[0] is already saved when scanning previous
+ * mbuf. sum was REDUCEd when we found mlen == -1
+ */
+ su.c[1] = *(u_char *)w;
+ sum += su.s;
+ w = (u_short *)((char *)w + 1);
+ mlen = m->m_len - 1;
+ len--;
+ } else
+ mlen = m->m_len;
+ if (len < mlen)
+ mlen = len;
+ len -= mlen;
+ /*
+ * Force to long boundary so we do longword aligned
+ * memory operations
+ */
+ if (3 & (int) w) {
+ REDUCE;
+ if ((1 & (int) w) && (mlen > 0)) {
+ sum <<= 8;
+ su.c[0] = *(char *)w;
+ w = (u_short *)((char *)w + 1);
+ mlen--;
+ byte_swapped = 1;
+ }
+ if ((2 & (int) w) && (mlen >= 2)) {
+ sum += *w++;
+ mlen -= 2;
+ }
+ }
+ /*
+ * Advance to a 486 cache line boundary.
+ */
+ if (4 & (int) w && mlen >= 4) {
+ ADD(0);
+ MOP;
+ w += 2;
+ mlen -= 4;
+ }
+ if (8 & (int) w && mlen >= 8) {
+ ADD(0);
+ ADDC(4);
+ MOP;
+ w += 4;
+ mlen -= 8;
+ }
+ /*
+ * Do as much of the checksum as possible 32 bits at at time.
+ * In fact, this loop is unrolled to make overhead from
+ * branches &c small.
+ */
+ mlen -= 1;
+ while ((mlen -= 32) >= 0) {
+ u_char junk;
+ /*
+ * Add with carry 16 words and fold in the last
+ * carry by adding a 0 with carry.
+ *
+ * The early ADD(16) and the LOAD(32) are to load
+ * the next 2 cache lines in advance on 486's. The
+ * 486 has a penalty of 2 clock cycles for loading
+ * a cache line, plus whatever time the external
+ * memory takes to load the first word(s) addressed.
+ * These penalties are unavoidable. Subsequent
+ * accesses to a cache line being loaded (and to
+ * other external memory?) are delayed until the
+ * whole load finishes. These penalties are mostly
+ * avoided by not accessing external memory for
+ * 8 cycles after the ADD(16) and 12 cycles after
+ * the LOAD(32). The loop terminates when mlen
+ * is initially 33 (not 32) to guaranteed that
+ * the LOAD(32) is within bounds.
+ */
+ ADD(16);
+ ADDC(0);
+ ADDC(4);
+ ADDC(8);
+ ADDC(12);
+ LOAD(32);
+ ADDC(20);
+ ADDC(24);
+ ADDC(28);
+ MOP;
+ w += 16;
+ }
+ mlen += 32 + 1;
+ if (mlen >= 32) {
+ ADD(16);
+ ADDC(0);
+ ADDC(4);
+ ADDC(8);
+ ADDC(12);
+ ADDC(20);
+ ADDC(24);
+ ADDC(28);
+ MOP;
+ w += 16;
+ mlen -= 32;
+ }
+ if (mlen >= 16) {
+ ADD(0);
+ ADDC(4);
+ ADDC(8);
+ ADDC(12);
+ MOP;
+ w += 8;
+ mlen -= 16;
+ }
+ if (mlen >= 8) {
+ ADD(0);
+ ADDC(4);
+ MOP;
+ w += 4;
+ mlen -= 8;
+ }
+ if (mlen == 0 && byte_swapped == 0)
+ continue; /* worth 1% maybe ?? */
+ REDUCE;
+ while ((mlen -= 2) >= 0) {
+ sum += *w++;
+ }
+ if (byte_swapped) {
+ sum <<= 8;
+ byte_swapped = 0;
+ if (mlen == -1) {
+ su.c[1] = *(char *)w;
+ sum += su.s;
+ mlen = 0;
+ } else
+ mlen = -1;
+ } else if (mlen == -1)
+ /*
+ * This mbuf has odd number of bytes.
+ * There could be a word split betwen
+ * this mbuf and the next mbuf.
+ * Save the last byte (to prepend to next mbuf).
+ */
+ su.c[0] = *(char *)w;
+ }
+
+ if (len)
+ puts("cksum: out of data");
+ if (mlen == -1) {
+ /* The last mbuf has odd # of bytes. Follow the
+ standard (the odd byte is shifted left by 8 bits) */
+ su.c[1] = 0;
+ sum += su.s;
+ }
+ REDUCE;
+ return (~sum & 0xffff);
+}
diff --git a/cpukit/libnetworking/netinet/in_cksum_m68k.h b/cpukit/libnetworking/netinet/in_cksum_m68k.h
new file mode 100644
index 0000000000..073504d4a8
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_cksum_m68k.h
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 1988, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/mbuf.h>
+
+#if defined(__mcoldfire__)
+# define IS_COLDFIRE 1
+#else
+# define IS_COLDFIRE 0
+#endif
+
+#define REDUCE { sum = (sum & 0xFFFF) + (sum >> 16); if (sum > 0xFFFF) sum -= 0xFFFF; }
+
+/*
+ * Motorola 68k version of Internet Protocol Checksum routine
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * August, 1998
+ */
+int
+in_cksum( struct mbuf *m,
+ int len )
+{
+ unsigned short *w;
+ unsigned long sum = 0;
+ int mlen = 0;
+ int byte_swapped = 0;
+ union {
+ char c[2];
+ u_short s;
+ } s_util;
+
+ for ( ; m && len ; m = m->m_next) {
+ if (m->m_len == 0)
+ continue;
+ w = mtod(m, u_short *);
+ if (mlen == -1) {
+ /*
+ * The first byte of this mbuf is the continuation
+ * of a word spanning between this mbuf and the
+ * last mbuf.
+ *
+ * s_util.c[0] is already saved when scanning previous
+ * mbuf.
+ */
+ s_util.c[1] = *(char *)w;
+ sum += s_util.s;
+ w = (u_short *)((char *)w + 1);
+ mlen = m->m_len - 1;
+ len--;
+ } else
+ mlen = m->m_len;
+ if (len < mlen)
+ mlen = len;
+ len -= mlen;
+
+ /*
+ * Force to longword boundary.
+ */
+ if (3 & (int)w) {
+ REDUCE;
+ if ((1 & (int) w) && (mlen > 0)) {
+ sum <<= 8;
+ s_util.c[0] = *(u_char *)w;
+ w = (u_short *)((char *)w + 1);
+ mlen--;
+ byte_swapped = 1;
+ }
+ if ((2 & (int) w) && (mlen >= 2)) {
+ sum += *w++;
+ mlen -= 2;
+ }
+ }
+
+ /*
+ * Sum all the longwords in the buffer.
+ * See RFC 1071 -- Computing the Internet Checksum.
+ * It should work for all 68k family members.
+ */
+ {
+ unsigned long tcnt = mlen, t1;
+ __asm__ volatile (
+ "movel %2,%3\n\t"
+ "lsrl #6,%2 | count/64 = # loop traversals\n\t"
+ "andl #0x3c,%3 | Then find fractions of a chunk\n\t"
+ "negl %3\n\t | Each long uses 4 instruction bytes\n\t"
+#if IS_COLDFIRE
+ "addql #1,%2 | Clear X (extended carry flag)\n\t"
+ "subql #1,%2 | \n\t"
+#else
+ "andi #0xf,%%cc | Clear X (extended carry flag)\n\t"
+#endif
+ "jmp %%pc@(2f-.-2:b,%3) | Jump into loop\n"
+ "1: | Begin inner loop...\n\t"
+ "movel %1@+,%3 | 0: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 1: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 2: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 3: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 4: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 5: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 6: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 7: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 8: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | 9: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | A: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | B: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | C: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | D: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | E: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n\t"
+ "movel %1@+,%3 | F: Fetch 32-bit word\n\t"
+ "addxl %3,%0 | Add word + previous carry\n"
+ "2: | End of unrolled loop\n\t"
+#if IS_COLDFIRE
+ "moveq #0,%3 | Add in last carry\n\t"
+ "addxl %3,%0 |\n\t"
+ "subql #1,%2 | Update loop count\n\t"
+ "bplb 1b | Loop (with X clear) if not done\n\t"
+ "movel #0xffff,%2 | Get word mask\n\t"
+ "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t"
+ "swap %3 |\n\t"
+ "andl %2,%0 | Mask to 16-bit sum\n\t"
+ "andl %2,%3 | Mask to 16-bit sum\n\t"
+ "addl %3,%0 |\n\t"
+ "movel %0,%3 | Add in last carry\n\t"
+ "swap %3 |\n\t"
+ "addl %3,%0 |\n\t"
+ "andl %2,%0 | Mask to 16-bit sum\n\t"
+#else
+ "dbf %2,1b | (NB- dbf doesn't affect X)\n\t"
+ "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t"
+ "swap %3 | (NB- swap doesn't affect X)\n\t"
+ "addxw %3,%0 |\n\t"
+ "moveq #0,%3 | Add in last carry\n\t"
+ "addxw %3,%0 |\n\t"
+ "andl #0xffff,%0 | Mask to 16-bit sum\n"
+#endif
+ :
+ "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1) :
+ "0" (sum), "1" (w), "2" (tcnt) :
+ "cc", "memory");
+ }
+ mlen &= 3;
+
+ /*
+ * Soak up the last 1, 2 or 3 bytes
+ */
+ while ((mlen -= 2) >= 0)
+ sum += *w++;
+ if (byte_swapped) {
+ REDUCE;
+ sum <<= 8;
+ byte_swapped = 0;
+ if (mlen == -1) {
+ s_util.c[1] = *(char *)w;
+ sum += s_util.s;
+ mlen = 0;
+ } else
+ mlen = -1;
+ } else if (mlen == -1)
+ s_util.c[0] = *(char *)w;
+ }
+ if (len)
+ sum = 0xDEAD;
+ if (mlen == -1) {
+ /* The last mbuf has odd # of bytes. Follow the
+ standard (the odd byte may be shifted left by 8 bits
+ or not as determined by endian-ness of the machine) */
+ s_util.c[1] = 0;
+ sum += s_util.s;
+ }
+ REDUCE;
+ return (~sum & 0xffff);
+}
diff --git a/cpukit/libnetworking/netinet/in_cksum_powerpc.h b/cpukit/libnetworking/netinet/in_cksum_powerpc.h
new file mode 100644
index 0000000000..9de5a95e35
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_cksum_powerpc.h
@@ -0,0 +1,174 @@
+/*
+ * Checksum routine for Internet Protocol family headers.
+ *
+ * This routine is very heavily used in the network
+ * code and should be modified for each CPU to be as fast as possible.
+ *
+ * This implementation is the PowerPC version.
+ *
+ * $Id$
+ */
+
+#include <stdio.h> /* for puts */
+
+#undef ADDCARRY
+#define ADDCARRY(x) if ((x) > 0xffff) (x) -= 0xffff
+#define REDUCE {sum = (sum & 0xffff) + (sum >> 16); ADDCARRY(sum);}
+
+/*
+ * Thanks to gcc we don't have to guess
+ * which registers contain sum & w.
+ */
+
+#define LDTMP(n) tmp = *((u_int *)((u_char *)w + n))
+
+#define ADD(n) \
+ LDTMP(n); \
+ __asm__ volatile("addc %0,%0,%2" : "=r" (sum) : "0" (sum), "r" (tmp))
+
+#define ADDC(n) \
+ LDTMP(n); \
+ __asm__ volatile("adde %0,%0,%2" : "=r" (sum) : "0" (sum), "r" (tmp))
+
+#define MOP \
+ tmp = 0; \
+ __asm__ volatile("adde %0,%0,%2" : "=r" (sum) : "0" (sum), "r" (tmp))
+
+#define LOAD(n) junk = (u_char) *((volatile u_char *) w + n)
+
+
+int
+in_cksum(
+ struct mbuf *m,
+ int len
+)
+{
+ u_char junk;
+ register u_short *w;
+ register unsigned sum = 0;
+ register unsigned tmp;
+ register int mlen = 0;
+ int byte_swapped = 0;
+ union { char c[2]; u_short s; } su;
+
+ for (;m && len; m = m->m_next) {
+ if (m->m_len == 0)
+ continue;
+ w = mtod(m, u_short *);
+ if (mlen == -1) {
+ /*
+ * The first byte of this mbuf is the continuation
+ * of a word spanning between this mbuf and the
+ * last mbuf.
+ */
+
+ /* su.c[0] is already saved when scanning previous
+ * mbuf. sum was REDUCEd when we found mlen == -1
+ */
+ su.c[1] = *(u_char *)w;
+ sum += su.s;
+ w = (u_short *)((char *)w + 1);
+ mlen = m->m_len - 1;
+ len--;
+ } else
+ mlen = m->m_len;
+ if (len < mlen)
+ mlen = len;
+ len -= mlen;
+ /*
+ * Force to long boundary so we do longword aligned
+ * memory operations
+ */
+ if (3 & (int) w) {
+ REDUCE;
+ if ((1 & (int) w) && (mlen > 0)) {
+ sum <<= 8;
+ su.c[0] = *(char *)w;
+ w = (u_short *)((char *)w + 1);
+ mlen--;
+ byte_swapped = 1;
+ }
+ if ((2 & (int) w) && (mlen >= 2)) {
+ sum += *w++;
+ mlen -= 2;
+ }
+ }
+
+ /*
+ * Do as much of the checksum as possible 32 bits at at time.
+ * In fact, this loop is unrolled to keep overhead from
+ * branches small.
+ */
+ while (mlen >= 32) {
+ /*
+ * Add with carry 16 words and fold in the last
+ * carry by adding a 0 with carry.
+ *
+ * The early ADD(16) and the LOAD(32) are intended
+ * to help get the data into the cache.
+ */
+ ADD(16);
+ ADDC(0);
+ ADDC(4);
+ ADDC(8);
+ ADDC(12);
+ LOAD(32);
+ ADDC(20);
+ ADDC(24);
+ ADDC(28);
+ MOP;
+ w += 16;
+ mlen -= 32;
+ }
+ if (mlen >= 16) {
+ ADD(0);
+ ADDC(4);
+ ADDC(8);
+ ADDC(12);
+ MOP;
+ w += 8;
+ mlen -= 16;
+ }
+ if (mlen >= 8) {
+ ADD(0);
+ ADDC(4);
+ MOP;
+ w += 4;
+ mlen -= 8;
+ }
+ if (mlen == 0 && byte_swapped == 0)
+ continue; /* worth 1% maybe ?? */
+ REDUCE;
+ while ((mlen -= 2) >= 0) {
+ sum += *w++;
+ }
+ if (byte_swapped) {
+ sum <<= 8;
+ byte_swapped = 0;
+ if (mlen == -1) {
+ su.c[1] = *(char *)w;
+ sum += su.s;
+ mlen = 0;
+ } else
+ mlen = -1;
+ } else if (mlen == -1)
+ /*
+ * This mbuf has odd number of bytes.
+ * There could be a word split betwen
+ * this mbuf and the next mbuf.
+ * Save the last byte (to prepend to next mbuf).
+ */
+ su.c[0] = *(char *)w;
+ }
+
+ if (len)
+ puts("cksum: out of data");
+ if (mlen == -1) {
+ /* The last mbuf has odd # of bytes. Follow the
+ standard (the odd byte is shifted left by 8 bits) */
+ su.c[1] = 0;
+ sum += su.s;
+ }
+ REDUCE;
+ return (~sum & 0xffff);
+}
diff --git a/cpukit/libnetworking/netinet/in_pcb.c b/cpukit/libnetworking/netinet/in_pcb.c
new file mode 100644
index 0000000000..00cdcd2f2e
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_pcb.c
@@ -0,0 +1,738 @@
+/*
+ * Copyright (c) 1982, 1986, 1991, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95
+ * $FreeBSD: src/sys/netinet/in_pcb.c,v 1.158 2005/01/07 01:45:44 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/proc.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
+
+struct in_addr zeroin_addr;
+
+static void in_pcbinshash(struct inpcb *);
+static void in_rtchange(struct inpcb *, int);
+
+/*
+ * These configure the range of local port addresses assigned to
+ * "unspecified" outgoing connections/packets/whatever.
+ */
+static int ipport_lowfirstauto = IPPORT_RESERVED - 1; /* 1023 */
+static int ipport_lowlastauto = IPPORT_RESERVEDSTART; /* 600 */
+static int ipport_firstauto = IPPORT_RESERVED; /* 1024 */
+static int ipport_lastauto = IPPORT_USERRESERVED; /* 5000 */
+static int ipport_hifirstauto = IPPORT_HIFIRSTAUTO; /* 40000 */
+static int ipport_hilastauto = IPPORT_HILASTAUTO; /* 44999 */
+
+#define RANGECHK(var, min, max) \
+ if ((var) < (min)) { (var) = (min); } \
+ else if ((var) > (max)) { (var) = (max); }
+
+static int
+sysctl_net_ipport_check(SYSCTL_HANDLER_ARGS)
+{
+ int error = sysctl_handle_int(oidp,
+ oidp->oid_arg1, oidp->oid_arg2, req);
+ if (!error) {
+ RANGECHK(ipport_lowfirstauto, 1, IPPORT_RESERVED - 1);
+ RANGECHK(ipport_lowlastauto, 1, IPPORT_RESERVED - 1);
+ RANGECHK(ipport_firstauto, IPPORT_RESERVED, USHRT_MAX);
+ RANGECHK(ipport_lastauto, IPPORT_RESERVED, USHRT_MAX);
+ RANGECHK(ipport_hifirstauto, IPPORT_RESERVED, USHRT_MAX);
+ RANGECHK(ipport_hilastauto, IPPORT_RESERVED, USHRT_MAX);
+ }
+ return error;
+}
+
+#undef RANGECHK
+
+SYSCTL_NODE(_net_inet_ip, IPPROTO_IP, portrange, CTLFLAG_RW, 0, "IP Ports");
+
+SYSCTL_PROC(_net_inet_ip_portrange, OID_AUTO, lowfirst, CTLTYPE_INT|CTLFLAG_RW,
+ &ipport_lowfirstauto, 0, &sysctl_net_ipport_check, "I", "");
+SYSCTL_PROC(_net_inet_ip_portrange, OID_AUTO, lowlast, CTLTYPE_INT|CTLFLAG_RW,
+ &ipport_lowlastauto, 0, &sysctl_net_ipport_check, "I", "");
+SYSCTL_PROC(_net_inet_ip_portrange, OID_AUTO, first, CTLTYPE_INT|CTLFLAG_RW,
+ &ipport_firstauto, 0, &sysctl_net_ipport_check, "I", "");
+SYSCTL_PROC(_net_inet_ip_portrange, OID_AUTO, last, CTLTYPE_INT|CTLFLAG_RW,
+ &ipport_lastauto, 0, &sysctl_net_ipport_check, "I", "");
+SYSCTL_PROC(_net_inet_ip_portrange, OID_AUTO, hifirst, CTLTYPE_INT|CTLFLAG_RW,
+ &ipport_hifirstauto, 0, &sysctl_net_ipport_check, "I", "");
+SYSCTL_PROC(_net_inet_ip_portrange, OID_AUTO, hilast, CTLTYPE_INT|CTLFLAG_RW,
+ &ipport_hilastauto, 0, &sysctl_net_ipport_check, "I", "");
+
+int
+in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo)
+{
+ register struct inpcb *inp;
+ int s;
+
+ MALLOC(inp, struct inpcb *, sizeof(*inp), M_PCB, M_NOWAIT);
+ if (inp == NULL)
+ return (ENOBUFS);
+ bzero((caddr_t)inp, sizeof(*inp));
+ inp->inp_gencnt = ++pcbinfo->ipi_gencnt;
+ inp->inp_pcbinfo = pcbinfo;
+ inp->inp_socket = so;
+ s = splnet();
+ LIST_INSERT_HEAD(pcbinfo->listhead, inp, inp_list);
+ pcbinfo->ipi_count++;
+ in_pcbinshash(inp);
+ splx(s);
+ so->so_pcb = (caddr_t)inp;
+ return (0);
+}
+
+int
+in_pcbbind(struct inpcb *inp, struct mbuf *nam)
+{
+ register struct socket *so = inp->inp_socket;
+ unsigned short *lastport;
+ struct sockaddr_in *sin;
+ u_short lport = 0;
+ int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
+ int error;
+
+ if (in_ifaddr == 0)
+ return (EADDRNOTAVAIL);
+ if (inp->inp_lport || inp->inp_laddr.s_addr != INADDR_ANY)
+ return (EINVAL);
+ if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0 &&
+ ((so->so_proto->pr_flags & PR_CONNREQUIRED) == 0 ||
+ (so->so_options & SO_ACCEPTCONN) == 0))
+ wild = 1;
+ if (nam) {
+ sin = mtod(nam, struct sockaddr_in *);
+ if (nam->m_len != sizeof (*sin))
+ return (EINVAL);
+#ifdef notdef
+ /*
+ * We should check the family, but old programs
+ * incorrectly fail to initialize it.
+ */
+ if (sin->sin_family != AF_INET)
+ return (EAFNOSUPPORT);
+#endif
+ lport = sin->sin_port;
+ if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
+ /*
+ * Treat SO_REUSEADDR as SO_REUSEPORT for multicast;
+ * allow complete duplication of binding if
+ * SO_REUSEPORT is set, or if SO_REUSEADDR is set
+ * and a multicast address is bound on both
+ * new and duplicated sockets.
+ */
+ if (so->so_options & SO_REUSEADDR)
+ reuseport = SO_REUSEADDR|SO_REUSEPORT;
+ } else if (sin->sin_addr.s_addr != INADDR_ANY) {
+ sin->sin_port = 0; /* yech... */
+ if (ifa_ifwithaddr((struct sockaddr *)sin) == 0)
+ return (EADDRNOTAVAIL);
+ }
+ if (lport) {
+ struct inpcb *t;
+
+ /* GROSS */
+ if (ntohs(lport) < IPPORT_RESERVED &&
+ (error = suser(p->p_ucred, &p->p_acflag)))
+ return (EACCES);
+ if (so->so_uid) {
+ t = in_pcblookup(inp->inp_pcbinfo, zeroin_addr,
+ 0, sin->sin_addr, lport,
+ INPLOOKUP_WILDCARD);
+ if (t && (so->so_uid != t->inp_socket->so_uid))
+ return (EADDRINUSE);
+ }
+ t = in_pcblookup(inp->inp_pcbinfo, zeroin_addr, 0,
+ sin->sin_addr, lport, wild);
+ if (t && (reuseport & t->inp_socket->so_options) == 0)
+ return (EADDRINUSE);
+ }
+ inp->inp_laddr = sin->sin_addr;
+ }
+ if (lport == 0) {
+ unsigned short first, last;
+ int count;
+
+ inp->inp_flags |= INP_ANONPORT;
+
+ if (inp->inp_flags & INP_HIGHPORT) {
+ first = ipport_hifirstauto; /* sysctl */
+ last = ipport_hilastauto;
+ lastport = &inp->inp_pcbinfo->lasthi;
+ } else if (inp->inp_flags & INP_LOWPORT) {
+ if ((error = suser(p->p_ucred, &p->p_acflag)))
+ return (EACCES);
+ first = ipport_lowfirstauto; /* 1023 */
+ last = ipport_lowlastauto; /* 600 */
+ lastport = &inp->inp_pcbinfo->lastlow;
+ } else {
+ first = ipport_firstauto; /* sysctl */
+ last = ipport_lastauto;
+ lastport = &inp->inp_pcbinfo->lastport;
+ }
+ /*
+ * Simple check to ensure all ports are not used up causing
+ * a deadlock here.
+ *
+ * We split the two cases (up and down) so that the direction
+ * is not being tested on each round of the loop.
+ */
+ if (first > last) {
+ /*
+ * counting down
+ */
+ count = first - last;
+
+ do {
+ if (count-- <= 0) /* completely used? */
+ return (EADDRNOTAVAIL);
+ --*lastport;
+ if (*lastport > first || *lastport < last)
+ *lastport = first;
+ lport = htons(*lastport);
+ } while (in_pcblookup(inp->inp_pcbinfo,
+ zeroin_addr, 0, inp->inp_laddr, lport, wild));
+ } else {
+ /*
+ * counting up
+ */
+ count = last - first;
+
+ do {
+ if (count-- <= 0) /* completely used? */
+ return (EADDRNOTAVAIL);
+ ++*lastport;
+ if (*lastport < first || *lastport > last)
+ *lastport = first;
+ lport = htons(*lastport);
+ } while (in_pcblookup(inp->inp_pcbinfo,
+ zeroin_addr, 0, inp->inp_laddr, lport, wild));
+ }
+ }
+ inp->inp_lport = lport;
+ in_pcbrehash(inp);
+ return (0);
+}
+
+/*
+ * Transform old in_pcbconnect() into an inner subroutine for new
+ * in_pcbconnect(): Do some validity-checking on the remote
+ * address (in mbuf 'nam') and then determine local host address
+ * (i.e., which interface) to use to access that remote host.
+ *
+ * This preserves definition of in_pcbconnect(), while supporting a
+ * slightly different version for T/TCP. (This is more than
+ * a bit of a kludge, but cleaning up the internal interfaces would
+ * have forced minor changes in every protocol).
+ */
+
+int
+in_pcbladdr(struct inpcb *inp, struct mbuf *nam, struct sockaddr_in **plocal_sin)
+{
+ struct in_ifaddr *ia;
+ register struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
+
+ if (nam->m_len != sizeof (*sin))
+ return (EINVAL);
+ if (sin->sin_family != AF_INET)
+ return (EAFNOSUPPORT);
+ if (sin->sin_port == 0)
+ return (EADDRNOTAVAIL);
+ if (in_ifaddr) {
+ /*
+ * If the destination address is INADDR_ANY,
+ * use the primary local address.
+ * If the supplied address is INADDR_BROADCAST,
+ * and the primary interface supports broadcast,
+ * choose the broadcast address for that interface.
+ */
+#define satosin(sa) ((struct sockaddr_in *)(sa))
+#define sintosa(sin) ((struct sockaddr *)(sin))
+#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
+ if (sin->sin_addr.s_addr == INADDR_ANY)
+ sin->sin_addr = IA_SIN(in_ifaddr)->sin_addr;
+ else if (sin->sin_addr.s_addr == (u_long)INADDR_BROADCAST &&
+ (in_ifaddr->ia_ifp->if_flags & IFF_BROADCAST))
+ sin->sin_addr = satosin(&in_ifaddr->ia_broadaddr)->sin_addr;
+ }
+ if (inp->inp_laddr.s_addr == INADDR_ANY) {
+ register struct route *ro;
+
+ ia = (struct in_ifaddr *)0;
+ /*
+ * If route is known or can be allocated now,
+ * our src addr is taken from the i/f, else punt.
+ */
+ ro = &inp->inp_route;
+ if (ro->ro_rt &&
+ (satosin(&ro->ro_dst)->sin_addr.s_addr !=
+ sin->sin_addr.s_addr ||
+ inp->inp_socket->so_options & SO_DONTROUTE)) {
+ RTFREE(ro->ro_rt);
+ ro->ro_rt = (struct rtentry *)0;
+ }
+ if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/
+ (ro->ro_rt == (struct rtentry *)0 ||
+ ro->ro_rt->rt_ifp == (struct ifnet *)0)) {
+ /* No route yet, so try to acquire one */
+ ro->ro_dst.sa_family = AF_INET;
+ ro->ro_dst.sa_len = sizeof(struct sockaddr_in);
+ ((struct sockaddr_in *) &ro->ro_dst)->sin_addr =
+ sin->sin_addr;
+ rtalloc(ro);
+ }
+ /*
+ * If we found a route, use the address
+ * corresponding to the outgoing interface
+ * unless it is the loopback (in case a route
+ * to our address on another net goes to loopback).
+ */
+ if (ro->ro_rt && !(ro->ro_rt->rt_ifp->if_flags & IFF_LOOPBACK))
+ ia = ifatoia(ro->ro_rt->rt_ifa);
+ if (ia == 0) {
+ u_short fport = sin->sin_port;
+
+ sin->sin_port = 0;
+ ia = ifatoia(ifa_ifwithdstaddr(sintosa(sin)));
+ if (ia == 0)
+ ia = ifatoia(ifa_ifwithnet(sintosa(sin)));
+ sin->sin_port = fport;
+ if (ia == 0)
+ ia = in_ifaddr;
+ if (ia == 0)
+ return (EADDRNOTAVAIL);
+ }
+ /*
+ * If the destination address is multicast and an outgoing
+ * interface has been set as a multicast option, use the
+ * address of that interface as our source address.
+ */
+ if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)) &&
+ inp->inp_moptions != NULL) {
+ struct ip_moptions *imo;
+ struct ifnet *ifp;
+
+ imo = inp->inp_moptions;
+ if (imo->imo_multicast_ifp != NULL) {
+ ifp = imo->imo_multicast_ifp;
+ for (ia = in_ifaddr; ia; ia = ia->ia_next)
+ if (ia->ia_ifp == ifp)
+ break;
+ if (ia == 0)
+ return (EADDRNOTAVAIL);
+ }
+ }
+ /*
+ * Don't do pcblookup call here; return interface in plocal_sin
+ * and exit to caller, that will do the lookup.
+ */
+ *plocal_sin = &ia->ia_addr;
+
+ }
+ return(0);
+}
+
+/*
+ * Outer subroutine:
+ * Connect from a socket to a specified address.
+ * Both address and port must be specified in argument sin.
+ * If don't have a local address for this socket yet,
+ * then pick one.
+ */
+int
+in_pcbconnect(struct inpcb *inp, struct mbuf *nam)
+{
+ struct sockaddr_in *ifaddr;
+ register struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
+ int error;
+
+ /*
+ * Call inner routine, to assign local interface address.
+ */
+ if ((error = in_pcbladdr(inp, nam, &ifaddr)))
+ return(error);
+
+ if (in_pcblookuphash(inp->inp_pcbinfo, sin->sin_addr, sin->sin_port,
+ inp->inp_laddr.s_addr ? inp->inp_laddr : ifaddr->sin_addr,
+ inp->inp_lport, 0) != NULL)
+ return (EADDRINUSE);
+ if (inp->inp_laddr.s_addr == INADDR_ANY) {
+ if (inp->inp_lport == 0)
+ (void)in_pcbbind(inp, (struct mbuf *)0);
+ inp->inp_laddr = ifaddr->sin_addr;
+ }
+ inp->inp_faddr = sin->sin_addr;
+ inp->inp_fport = sin->sin_port;
+ in_pcbrehash(inp);
+ return (0);
+}
+
+void
+in_pcbdisconnect(struct inpcb *inp)
+{
+
+ inp->inp_faddr.s_addr = INADDR_ANY;
+ inp->inp_fport = 0;
+ in_pcbrehash(inp);
+ if (inp->inp_socket->so_state & SS_NOFDREF)
+ in_pcbdetach(inp);
+}
+
+void
+in_pcbdetach(struct inpcb *inp)
+{
+ struct socket *so = inp->inp_socket;
+ struct inpcbinfo *ipi = inp->inp_pcbinfo;
+ int s;
+
+ inp->inp_gencnt = ++ipi->ipi_gencnt;
+ so->so_pcb = 0;
+ sofree(so);
+ if (inp->inp_options)
+ (void)m_free(inp->inp_options);
+ if (inp->inp_route.ro_rt)
+ rtfree(inp->inp_route.ro_rt);
+ ip_freemoptions(inp->inp_moptions);
+ s = splnet();
+ LIST_REMOVE(inp, inp_hash);
+ LIST_REMOVE(inp, inp_list);
+ splx(s);
+ FREE(inp, M_PCB);
+}
+
+void
+in_setsockaddr(struct inpcb *inp, struct mbuf *nam)
+{
+ register struct sockaddr_in *sin;
+
+ nam->m_len = sizeof (*sin);
+ sin = mtod(nam, struct sockaddr_in *);
+ bzero((caddr_t)sin, sizeof (*sin));
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = inp->inp_lport;
+ sin->sin_addr = inp->inp_laddr;
+}
+
+void
+in_setpeeraddr(struct inpcb *inp, struct mbuf *nam)
+{
+ register struct sockaddr_in *sin;
+
+ nam->m_len = sizeof (*sin);
+ sin = mtod(nam, struct sockaddr_in *);
+ bzero((caddr_t)sin, sizeof (*sin));
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = inp->inp_fport;
+ sin->sin_addr = inp->inp_faddr;
+}
+
+/*
+ * Pass some notification to all connections of a protocol
+ * associated with address dst. The local address and/or port numbers
+ * may be specified to limit the search. The "usual action" will be
+ * taken, depending on the ctlinput cmd. The caller must filter any
+ * cmds that are uninteresting (e.g., no error in the map).
+ * Call the protocol specific routine (if any) to report
+ * any errors for each matching socket.
+ *
+ * Must be called at splnet.
+ */
+void
+in_pcbnotify(struct inpcbhead *head, struct sockaddr *dst, u_int fport_arg,
+ struct in_addr laddr, u_int lport_arg, int cmd,
+ void (*notify)(struct inpcb *, int))
+{
+ register struct inpcb *inp, *oinp;
+ struct in_addr faddr;
+ u_short fport = fport_arg, lport = lport_arg;
+ int errnum, s;
+
+ if ((unsigned)cmd > PRC_NCMDS || dst->sa_family != AF_INET)
+ return;
+ faddr = ((struct sockaddr_in *)dst)->sin_addr;
+ if (faddr.s_addr == INADDR_ANY)
+ return;
+
+ /*
+ * Redirects go to all references to the destination,
+ * and use in_rtchange to invalidate the route cache.
+ * Dead host indications: notify all references to the destination.
+ * Otherwise, if we have knowledge of the local port and address,
+ * deliver only to that socket.
+ */
+ if (PRC_IS_REDIRECT(cmd) || cmd == PRC_HOSTDEAD) {
+ fport = 0;
+ lport = 0;
+ laddr.s_addr = 0;
+ if (cmd != PRC_HOSTDEAD)
+ notify = in_rtchange;
+ }
+ errnum = inetctlerrmap[cmd];
+ s = splnet();
+ for (inp = head->lh_first; inp != NULL;) {
+ if (inp->inp_faddr.s_addr != faddr.s_addr ||
+ inp->inp_socket == 0 ||
+ (lport && inp->inp_lport != lport) ||
+ (laddr.s_addr && inp->inp_laddr.s_addr != laddr.s_addr) ||
+ (fport && inp->inp_fport != fport)) {
+ inp = inp->inp_list.le_next;
+ continue;
+ }
+ oinp = inp;
+ inp = inp->inp_list.le_next;
+ if (notify)
+ (*notify)(oinp, errnum);
+ }
+ splx(s);
+}
+
+/*
+ * Check for alternatives when higher level complains
+ * about service problems. For now, invalidate cached
+ * routing information. If the route was created dynamically
+ * (by a redirect), time to try a default gateway again.
+ */
+void
+in_losing(struct inpcb *inp)
+{
+ register struct rtentry *rt;
+ struct rt_addrinfo info;
+
+ if ((rt = inp->inp_route.ro_rt)) {
+ inp->inp_route.ro_rt = 0;
+ bzero((caddr_t)&info, sizeof(info));
+ info.rti_info[RTAX_DST] =
+ (struct sockaddr *)&inp->inp_route.ro_dst;
+ info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
+ info.rti_info[RTAX_NETMASK] = rt_mask(rt);
+ rt_missmsg(RTM_LOSING, &info, rt->rt_flags, 0);
+ if (rt->rt_flags & RTF_DYNAMIC)
+ (void) rtrequest(RTM_DELETE, rt_key(rt),
+ rt->rt_gateway, rt_mask(rt), rt->rt_flags,
+ (struct rtentry **)0);
+ else
+ /*
+ * A new route can be allocated
+ * the next time output is attempted.
+ */
+ rtfree(rt);
+ }
+}
+
+/*
+ * After a routing change, flush old routing
+ * and allocate a (hopefully) better one.
+ */
+static void
+in_rtchange(struct inpcb *inp, int errnum)
+{
+ if (inp->inp_route.ro_rt) {
+ rtfree(inp->inp_route.ro_rt);
+ inp->inp_route.ro_rt = 0;
+ /*
+ * A new route can be allocated the next time
+ * output is attempted.
+ */
+ }
+}
+
+struct inpcb *
+in_pcblookup(struct inpcbinfo *pcbinfo,
+ struct in_addr faddr, u_int fport_arg,
+ struct in_addr laddr, u_int lport_arg,
+ int wild_okay)
+{
+ register struct inpcb *inp, *match = NULL;
+ int matchwild = 3, wildcard;
+ u_short fport = fport_arg, lport = lport_arg;
+ int s;
+
+ s = splnet();
+
+ for (inp = pcbinfo->listhead->lh_first; inp != NULL; inp = inp->inp_list.le_next) {
+ if (inp->inp_lport != lport)
+ continue;
+ wildcard = 0;
+ if (inp->inp_faddr.s_addr != INADDR_ANY) {
+ if (faddr.s_addr == INADDR_ANY)
+ wildcard++;
+ else if (inp->inp_faddr.s_addr != faddr.s_addr ||
+ inp->inp_fport != fport)
+ continue;
+ } else {
+ if (faddr.s_addr != INADDR_ANY)
+ wildcard++;
+ }
+ if (inp->inp_laddr.s_addr != INADDR_ANY) {
+ if (laddr.s_addr == INADDR_ANY)
+ wildcard++;
+ else if (inp->inp_laddr.s_addr != laddr.s_addr)
+ continue;
+ } else {
+ if (laddr.s_addr != INADDR_ANY)
+ wildcard++;
+ }
+ if (wildcard && wild_okay == 0)
+ continue;
+ if (wildcard < matchwild) {
+ match = inp;
+ matchwild = wildcard;
+ if (matchwild == 0) {
+ break;
+ }
+ }
+ }
+ splx(s);
+ return (match);
+}
+
+/*
+ * Lookup PCB in hash list.
+ */
+struct inpcb *
+in_pcblookuphash(struct inpcbinfo *pcbinfo,
+ struct in_addr faddr, u_int fport_arg,
+ struct in_addr laddr, u_int lport_arg,
+ int wildcard)
+{
+ struct inpcbhead *head;
+ register struct inpcb *inp;
+ u_short fport = fport_arg, lport = lport_arg;
+ int s;
+
+ s = splnet();
+ /*
+ * First look for an exact match.
+ */
+ head = &pcbinfo->hashbase[INP_PCBHASH(faddr.s_addr, lport, fport, pcbinfo->hashmask)];
+ for (inp = head->lh_first; inp != NULL; inp = inp->inp_hash.le_next) {
+ if (inp->inp_faddr.s_addr == faddr.s_addr &&
+ inp->inp_laddr.s_addr == laddr.s_addr &&
+ inp->inp_fport == fport &&
+ inp->inp_lport == lport)
+ goto found;
+ }
+ if (wildcard) {
+ struct inpcb *local_wild = NULL;
+
+ head = &pcbinfo->hashbase[INP_PCBHASH(INADDR_ANY, lport, 0, pcbinfo->hashmask)];
+ for (inp = head->lh_first; inp != NULL; inp = inp->inp_hash.le_next) {
+ if (inp->inp_faddr.s_addr == INADDR_ANY &&
+ inp->inp_fport == 0 && inp->inp_lport == lport) {
+ if (inp->inp_laddr.s_addr == laddr.s_addr)
+ goto found;
+ else if (inp->inp_laddr.s_addr == INADDR_ANY)
+ local_wild = inp;
+ }
+ }
+ if (local_wild != NULL) {
+ inp = local_wild;
+ goto found;
+ }
+ }
+ splx(s);
+ return (NULL);
+
+found:
+ /*
+ * Move PCB to head of this hash chain so that it can be
+ * found more quickly in the future.
+ * XXX - this is a pessimization on machines with few
+ * concurrent connections.
+ */
+ if (inp != head->lh_first) {
+ LIST_REMOVE(inp, inp_hash);
+ LIST_INSERT_HEAD(head, inp, inp_hash);
+ }
+ splx(s);
+ return (inp);
+}
+
+/*
+ * Insert PCB into hash chain. Must be called at splnet.
+ */
+static void
+in_pcbinshash(struct inpcb *inp)
+{
+ struct inpcbhead *head;
+
+ head = &inp->inp_pcbinfo->hashbase[INP_PCBHASH(inp->inp_faddr.s_addr,
+ inp->inp_lport, inp->inp_fport, inp->inp_pcbinfo->hashmask)];
+
+ LIST_INSERT_HEAD(head, inp, inp_hash);
+}
+
+void
+in_pcbrehash(struct inpcb *inp)
+{
+ struct inpcbhead *head;
+ int s;
+
+ s = splnet();
+ LIST_REMOVE(inp, inp_hash);
+
+ head = &inp->inp_pcbinfo->hashbase[INP_PCBHASH(inp->inp_faddr.s_addr,
+ inp->inp_lport, inp->inp_fport, inp->inp_pcbinfo->hashmask)];
+
+ LIST_INSERT_HEAD(head, inp, inp_hash);
+ inp->inp_pcbinfo->ipi_count--;
+ splx(s);
+}
diff --git a/cpukit/libnetworking/netinet/in_pcb.h b/cpukit/libnetworking/netinet/in_pcb.h
new file mode 100644
index 0000000000..f3a3cc178d
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_pcb.h
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.89 2006/07/18 22:34:27 ups Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IN_PCB_H_
+#define _NETINET_IN_PCB_H_
+
+#include <sys/queue.h>
+
+/*
+ * Common structure pcb for internet protocol implementation.
+ * Here are stored pointers to local and foreign host table
+ * entries, local and foreign socket numbers, and pointers
+ * up (to a socket structure) and down (to a protocol-specific)
+ * control block.
+ */
+LIST_HEAD(inpcbhead, inpcb);
+
+typedef u_int64_t inp_gen_t;
+
+struct inpcb {
+ LIST_ENTRY(inpcb) inp_hash; /* hash list */
+ LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
+ struct inpcbinfo *inp_pcbinfo; /* PCB list info */
+ struct in_addr inp_faddr; /* foreign host table entry */
+ struct in_addr inp_laddr; /* local host table entry */
+ u_short inp_fport; /* foreign port */
+ u_short inp_lport; /* local port */
+ caddr_t inp_ppcb; /* pointer to per-protocol pcb */
+ struct socket *inp_socket; /* back pointer to socket */
+ struct route inp_route; /* placeholder for routing entry */
+ int inp_flags; /* generic IP/datagram flags */
+ u_char inp_vflag; /* IP version flag (v4/v6) */
+ u_char inp_ip_ttl; /* time to live proto */
+ u_char inp_ip_p; /* protocol proto */
+ u_char inp_ip_minttl; /* minimum TTL or drop */
+
+ /* protocol dependent part; options */
+ struct {
+ u_char inp4_ip_tos; /* type of service proto */
+ struct mbuf *inp4_options; /* IP options */
+ struct ip_moptions *inp4_moptions; /* IP multicast options */
+ } inp_depend4;
+#define inp_ip_tos inp_depend4.inp4_ip_tos
+#define inp_options inp_depend4.inp4_options
+#define inp_moptions inp_depend4.inp4_moptions
+ inp_gen_t inp_gencnt; /* generation count of this instance */
+};
+
+/*
+ * Interface exported to userland by various protocols which use
+ * inpcbs. Hack alert -- only define if struct xsocket is in scope.
+ */
+#ifdef _SYS_SOCKETVAR_H_
+struct xinpcb {
+ size_t xi_len; /* length of this structure */
+ struct inpcb xi_inp;
+/* struct xsocket xi_socket; ccj removed */
+ u_int64_t xi_alignment_hack;
+};
+
+struct xinpgen {
+ size_t xig_len; /* length of this structure */
+ u_int xig_count; /* number of PCBs at this time */
+ inp_gen_t xig_gen; /* generation count at this time */
+ so_gen_t xig_sogen; /* socket generation count at this time */
+};
+#endif /* _SYS_SOCKETVAR_H_ */
+
+struct inpcbinfo { /* XXX documentation, prefixes */
+ struct inpcbhead *listhead;
+ struct inpcbhead *hashbase;
+ unsigned long hashmask;
+ unsigned short lastport;
+ unsigned short lastlow;
+ unsigned short lasthi;
+ u_int ipi_count; /* number of pcbs in this list */
+ u_int64_t ipi_gencnt; /* current generation count */
+};
+
+#define INP_PCBHASH(faddr, lport, fport, mask) \
+ (((faddr) ^ ((faddr) >> 16) ^ (lport) ^ (fport)) & (mask))
+
+/* flags in inp_flags: */
+#define INP_RECVOPTS 0x01 /* receive incoming IP options */
+#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
+#define INP_RECVDSTADDR 0x04 /* receive IP dst address */
+#define INP_HDRINCL 0x08 /* user supplies entire IP header */
+#define INP_HIGHPORT 0x10 /* user wants "high" port binding */
+#define INP_LOWPORT 0x20 /* user wants "low" port binding */
+#define INP_ANONPORT 0x40 /* port chosen for user */
+#define INP_RECVIF 0x80 /* receive incoming interface */
+#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
+ INP_RECVIF)
+
+#define INPLOOKUP_WILDCARD 1
+#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
+
+#ifdef _KERNEL
+void in_losing(struct inpcb *);
+int in_pcballoc(struct socket *, struct inpcbinfo *);
+int in_pcbbind(struct inpcb *, struct mbuf *);
+int in_pcbconnect(struct inpcb *, struct mbuf *);
+void in_pcbdetach(struct inpcb *);
+void in_pcbdisconnect(struct inpcb *);
+int in_pcbladdr(struct inpcb *, struct mbuf *,
+ struct sockaddr_in **);
+struct inpcb *
+ in_pcblookup(struct inpcbinfo *,
+ struct in_addr, u_int, struct in_addr, u_int, int);
+struct inpcb *
+ in_pcblookuphash(struct inpcbinfo *,
+ struct in_addr, u_int, struct in_addr, u_int, int);
+void in_pcbnotify(struct inpcbhead *, struct sockaddr *,
+ u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int));
+void in_pcbrehash(struct inpcb *);
+void in_setpeeraddr(struct inpcb *, struct mbuf *);
+void in_setsockaddr(struct inpcb *, struct mbuf *);
+#endif /* _KERNEL */
+
+#endif /* !_NETINET_IN_PCB_H_ */
diff --git a/cpukit/libnetworking/netinet/in_proto.c b/cpukit/libnetworking/netinet/in_proto.c
new file mode 100644
index 0000000000..a79dbebf11
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_proto.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_tcpdebug.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/radix.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/in_pcb.h>
+#include <netinet/igmp_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#ifdef TCPDEBUG
+#include <netinet/tcp_debug.h>
+#endif
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+/*
+ * TCP/IP protocol family: IP, ICMP, UDP, TCP.
+ */
+
+#ifdef IPXIP
+#include <netipx/ipx.h>
+#include <netipx/ipx_ip.h>
+#endif
+
+#ifdef NSIP
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#ifdef TPIP
+void tpip_input(), tpip_ctlinput(), tp_init(), tp_slowtimo(), tp_drain();
+int tp_ctloutput(), tp_usrreq();
+#endif
+
+#ifdef EON
+void eoninput(), eonctlinput(), eonprotoinit();
+#endif /* EON */
+
+extern struct domain inetdomain;
+
+struct protosw inetsw[] = {
+{ 0, &inetdomain, 0, 0,
+ 0, 0, 0, 0,
+ 0,
+ ip_init, 0, ip_slowtimo, ip_drain,
+ NULL
+},
+{ SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR,
+ udp_input, 0, udp_ctlinput, ip_ctloutput,
+ udp_usrreq,
+ udp_init, 0, 0, 0,
+ NULL
+},
+{ SOCK_STREAM, &inetdomain, IPPROTO_TCP,
+ PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
+ tcp_input, 0, tcp_ctlinput, tcp_ctloutput,
+ 0,
+ tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain,
+ &tcp_usrreqs
+},
+{ SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR,
+ rip_input, 0, 0, rip_ctloutput,
+ rip_usrreq,
+ 0, 0, 0, 0,
+ NULL
+},
+{ SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR,
+ icmp_input, 0, 0, rip_ctloutput,
+ rip_usrreq,
+ 0, 0, 0, 0,
+ NULL
+},
+{ SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR,
+ igmp_input, 0, 0, rip_ctloutput,
+ rip_usrreq,
+ igmp_init, igmp_fasttimo, igmp_slowtimo, 0,
+ NULL
+},
+{ SOCK_RAW, &inetdomain, IPPROTO_RSVP, PR_ATOMIC|PR_ADDR,
+ rsvp_input, 0, 0, rip_ctloutput,
+ rip_usrreq,
+ 0, 0, 0, 0,
+ NULL
+},
+{ SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR,
+ ipip_input, 0, 0, rip_ctloutput,
+ rip_usrreq,
+ 0, 0, 0, 0,
+ NULL
+},
+#ifdef IPDIVERT
+{ SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR,
+ div_input, 0, 0, ip_ctloutput,
+ div_usrreq,
+ div_init, 0, 0, 0,
+ NULL
+},
+#endif
+#ifdef TPIP
+{ SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD,
+ tpip_input, 0, tpip_ctlinput, tp_ctloutput,
+ tp_usrreq,
+ tp_init, 0, tp_slowtimo, tp_drain,
+ NULL
+},
+#endif
+/* EON (ISO CLNL over IP) */
+#ifdef EON
+{ SOCK_RAW, &inetdomain, IPPROTO_EON, 0,
+ eoninput, 0, eonctlinput, 0,
+ 0,
+ eonprotoinit, 0, 0, 0,
+ NULL
+},
+#endif
+#ifdef IPXIP
+{ SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR,
+ ipxip_input, 0, ipxip_ctlinput, 0,
+ rip_usrreq,
+ 0, 0, 0, 0,
+ NULL
+},
+#endif
+#ifdef NSIP
+{ SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR,
+ idpip_input, 0, nsip_ctlinput, 0,
+ rip_usrreq,
+ 0, 0, 0, 0,
+ NULL
+},
+#endif
+ /* raw wildcard */
+{ SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR,
+ rip_input, 0, 0, rip_ctloutput,
+ rip_usrreq,
+ rip_init, 0, 0, 0,
+ NULL
+},
+};
+
+extern int in_inithead(void **, int);
+
+struct domain inetdomain =
+ { AF_INET, "internet", 0, 0, 0,
+ inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
+ in_inithead, 32, sizeof(struct sockaddr_in)
+ };
+
+DOMAIN_SET(inet);
+
+SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
+ "Internet Family");
+
+SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
+SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
+SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
+SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
+SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
+#ifdef IPDIVERT
+SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, div, CTLFLAG_RW, 0, "DIVERT");
+#endif
diff --git a/cpukit/libnetworking/netinet/in_rmx.c b/cpukit/libnetworking/netinet/in_rmx.c
new file mode 100644
index 0000000000..e21ae4a59c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_rmx.c
@@ -0,0 +1,387 @@
+/*
+ * Copyright 1994, 1995 Massachusetts Institute of Technology
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that both the above copyright notice and this
+ * permission notice appear in all copies, that both the above
+ * copyright notice and this permission notice appear in all
+ * supporting documentation, and that the name of M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. M.I.T. makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+ * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+/*
+ * This code does two things necessary for the enhanced TCP metrics to
+ * function in a useful manner:
+ * 1) It marks all non-host routes as `cloning', thus ensuring that
+ * every actual reference to such a route actually gets turned
+ * into a reference to a host route to the specific destination
+ * requested.
+ * 2) When such routes lose all their references, it arranges for them
+ * to be deleted in some random collection of circumstances, so that
+ * a large quantity of stale routing data is not kept in kernel memory
+ * indefinitely. See in_rtqtimo() below for the exact mechanism.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/mbuf.h>
+#include <sys/syslog.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+
+#include <netinet/tcp.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+
+extern int in_inithead(void **head, int off);
+
+#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */
+
+/*
+ * Do what we need to do when inserting a route.
+ */
+static struct radix_node *
+in_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
+ struct radix_node *treenodes)
+{
+ struct rtentry *rt = (struct rtentry *)treenodes;
+ struct sockaddr_in *sin = (struct sockaddr_in *)rt_key(rt);
+ struct radix_node *ret;
+
+ /*
+ * For IP, all unicast non-host routes are automatically cloning.
+ */
+ if(IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
+ rt->rt_flags |= RTF_MULTICAST;
+
+ if(!(rt->rt_flags & (RTF_HOST | RTF_CLONING | RTF_MULTICAST))) {
+ rt->rt_flags |= RTF_PRCLONING;
+ }
+
+ /*
+ * A little bit of help for both IP output and input:
+ * For host routes, we make sure that RTF_BROADCAST
+ * is set for anything that looks like a broadcast address.
+ * This way, we can avoid an expensive call to in_broadcast()
+ * in ip_output() most of the time (because the route passed
+ * to ip_output() is almost always a host route).
+ *
+ * We also do the same for local addresses, with the thought
+ * that this might one day be used to speed up ip_input().
+ *
+ * We also mark routes to multicast addresses as such, because
+ * it's easy to do and might be useful (but this is much more
+ * dubious since it's so easy to inspect the address). (This
+ * is done above.)
+ */
+ if (rt->rt_flags & RTF_HOST) {
+ if (in_broadcast(sin->sin_addr, rt->rt_ifp)) {
+ rt->rt_flags |= RTF_BROADCAST;
+ } else {
+#define satosin(sa) ((struct sockaddr_in *)sa)
+ if (satosin(rt->rt_ifa->ifa_addr)->sin_addr.s_addr
+ == sin->sin_addr.s_addr)
+ rt->rt_flags |= RTF_LOCAL;
+#undef satosin
+ }
+ }
+
+ /*
+ * We also specify a send and receive pipe size for every
+ * route added, to help TCP a bit. TCP doesn't actually
+ * want a true pipe size, which would be prohibitive in memory
+ * costs and is hard to compute anyway; it simply uses these
+ * values to size its buffers. So, we fill them in with the
+ * same values that TCP would have used anyway, and allow the
+ * installing program or the link layer to override these values
+ * as it sees fit. This will hopefully allow TCP more
+ * opportunities to save its ssthresh value.
+ */
+ if (!rt->rt_rmx.rmx_sendpipe && !(rt->rt_rmx.rmx_locks & RTV_SPIPE))
+ rt->rt_rmx.rmx_sendpipe = tcp_sendspace;
+
+ if (!rt->rt_rmx.rmx_recvpipe && !(rt->rt_rmx.rmx_locks & RTV_RPIPE))
+ rt->rt_rmx.rmx_recvpipe = tcp_recvspace;
+
+ if (!rt->rt_rmx.rmx_mtu && !(rt->rt_rmx.rmx_locks & RTV_MTU)
+ && rt->rt_ifp)
+ rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu;
+
+ ret = rn_addroute(v_arg, n_arg, head, treenodes);
+ if (ret == NULL && rt->rt_flags & RTF_HOST) {
+ struct rtentry *rt2;
+ /*
+ * We are trying to add a host route, but can't.
+ * Find out if it is because of an
+ * ARP entry and delete it if so.
+ */
+ rt2 = rtalloc1((struct sockaddr *)sin, 0,
+ RTF_CLONING | RTF_PRCLONING);
+ if (rt2) {
+ if (rt2->rt_flags & RTF_LLINFO &&
+ rt2->rt_flags & RTF_HOST &&
+ rt2->rt_gateway &&
+ rt2->rt_gateway->sa_family == AF_LINK) {
+ rtrequest(RTM_DELETE,
+ (struct sockaddr *)rt_key(rt2),
+ rt2->rt_gateway,
+ rt_mask(rt2), rt2->rt_flags, 0);
+ ret = rn_addroute(v_arg, n_arg, head,
+ treenodes);
+ }
+ RTFREE(rt2);
+ }
+ }
+ return ret;
+}
+
+/*
+ * This code is the inverse of in_clsroute: on first reference, if we
+ * were managing the route, stop doing so and set the expiration timer
+ * back off again.
+ */
+static struct radix_node *
+in_matroute(void *v_arg, struct radix_node_head *head)
+{
+ struct radix_node *rn = rn_match(v_arg, head);
+ struct rtentry *rt = (struct rtentry *)rn;
+
+ if(rt && rt->rt_refcnt == 0) { /* this is first reference */
+ if(rt->rt_flags & RTPRF_OURS) {
+ rt->rt_flags &= ~RTPRF_OURS;
+ rt->rt_rmx.rmx_expire = 0;
+ }
+ }
+ return rn;
+}
+
+static int rtq_reallyold = 60*60;
+ /* one hour is ``really old'' */
+SYSCTL_INT(_net_inet_ip, IPCTL_RTEXPIRE, rtexpire,
+ CTLFLAG_RW, &rtq_reallyold , 0, "");
+
+static int rtq_minreallyold = 10;
+ /* never automatically crank down to less */
+SYSCTL_INT(_net_inet_ip, IPCTL_RTMINEXPIRE, rtminexpire,
+ CTLFLAG_RW, &rtq_minreallyold , 0, "");
+
+static int rtq_toomany = 128;
+ /* 128 cached routes is ``too many'' */
+SYSCTL_INT(_net_inet_ip, IPCTL_RTMAXCACHE, rtmaxcache,
+ CTLFLAG_RW, &rtq_toomany , 0, "");
+
+
+/*
+ * On last reference drop, mark the route as belong to us so that it can be
+ * timed out.
+ */
+static void
+in_clsroute(struct radix_node *rn, struct radix_node_head *head)
+{
+ struct rtentry *rt = (struct rtentry *)rn;
+
+ if(!(rt->rt_flags & RTF_UP))
+ return; /* prophylactic measures */
+
+ if((rt->rt_flags & (RTF_LLINFO | RTF_HOST)) != RTF_HOST)
+ return;
+
+ if((rt->rt_flags & (RTF_WASCLONED | RTPRF_OURS))
+ != RTF_WASCLONED)
+ return;
+
+ /*
+ * As requested by David Greenman:
+ * If rtq_reallyold is 0, just delete the route without
+ * waiting for a timeout cycle to kill it.
+ */
+ if(rtq_reallyold != 0) {
+ rt->rt_flags |= RTPRF_OURS;
+ rt->rt_rmx.rmx_expire = rtems_bsdnet_seconds_since_boot() + rtq_reallyold;
+ } else {
+ rtrequest(RTM_DELETE,
+ (struct sockaddr *)rt_key(rt),
+ rt->rt_gateway, rt_mask(rt),
+ rt->rt_flags, 0);
+ }
+}
+
+struct rtqk_arg {
+ struct radix_node_head *rnh;
+ int draining;
+ int killed;
+ int found;
+ int updating;
+ time_t nextstop;
+};
+
+/*
+ * Get rid of old routes. When draining, this deletes everything, even when
+ * the timeout is not expired yet. When updating, this makes sure that
+ * nothing has a timeout longer than the current value of rtq_reallyold.
+ */
+static int
+in_rtqkill(struct radix_node *rn, void *rock)
+{
+ struct rtqk_arg *ap = rock;
+ struct rtentry *rt = (struct rtentry *)rn;
+ int err;
+
+ if(rt->rt_flags & RTPRF_OURS) {
+ ap->found++;
+
+ if(ap->draining || rt->rt_rmx.rmx_expire <= rtems_bsdnet_seconds_since_boot()) {
+ if(rt->rt_refcnt > 0)
+ panic("rtqkill route really not free");
+
+ err = rtrequest(RTM_DELETE,
+ (struct sockaddr *)rt_key(rt),
+ rt->rt_gateway, rt_mask(rt),
+ rt->rt_flags, 0);
+ if(err) {
+ log(LOG_WARNING, "in_rtqkill: error %d\n", err);
+ } else {
+ ap->killed++;
+ }
+ } else {
+ if(ap->updating
+ && (rt->rt_rmx.rmx_expire - rtems_bsdnet_seconds_since_boot()
+ > rtq_reallyold)) {
+ rt->rt_rmx.rmx_expire = rtems_bsdnet_seconds_since_boot()
+ + rtq_reallyold;
+ }
+ ap->nextstop = lmin(ap->nextstop,
+ rt->rt_rmx.rmx_expire);
+ }
+ }
+
+ return 0;
+}
+
+#define RTQ_TIMEOUT 60*10 /* run no less than once every ten minutes */
+static int rtq_timeout = RTQ_TIMEOUT;
+
+static void
+in_rtqtimo(void *rock)
+{
+ struct radix_node_head *rnh = rock;
+ struct rtqk_arg arg;
+ struct timeval atv;
+ static time_t last_adjusted_timeout = 0;
+ int s;
+
+ arg.found = arg.killed = 0;
+ arg.rnh = rnh;
+ arg.nextstop = rtems_bsdnet_seconds_since_boot() + rtq_timeout;
+ arg.draining = arg.updating = 0;
+ s = splnet();
+ rnh->rnh_walktree(rnh, in_rtqkill, &arg);
+ splx(s);
+
+ /*
+ * Attempt to be somewhat dynamic about this:
+ * If there are ``too many'' routes sitting around taking up space,
+ * then crank down the timeout, and see if we can't make some more
+ * go away. However, we make sure that we will never adjust more
+ * than once in rtq_timeout seconds, to keep from cranking down too
+ * hard.
+ */
+ if((arg.found - arg.killed > rtq_toomany)
+ && (rtems_bsdnet_seconds_since_boot() - last_adjusted_timeout >= rtq_timeout)
+ && rtq_reallyold > rtq_minreallyold) {
+ rtq_reallyold = 2*rtq_reallyold / 3;
+ if(rtq_reallyold < rtq_minreallyold) {
+ rtq_reallyold = rtq_minreallyold;
+ }
+
+ last_adjusted_timeout = rtems_bsdnet_seconds_since_boot();
+#ifdef DIAGNOSTIC
+ log(LOG_DEBUG, "in_rtqtimo: adjusted rtq_reallyold to %d\n",
+ rtq_reallyold);
+#endif
+ arg.found = arg.killed = 0;
+ arg.updating = 1;
+ s = splnet();
+ rnh->rnh_walktree(rnh, in_rtqkill, &arg);
+ splx(s);
+ }
+
+ atv.tv_usec = 0;
+ atv.tv_sec = arg.nextstop;
+ timeout(in_rtqtimo, rock, hzto(&atv));
+}
+
+void
+in_rtqdrain(void)
+{
+ struct radix_node_head *rnh = rt_tables[AF_INET];
+ struct rtqk_arg arg;
+ int s;
+ arg.found = arg.killed = 0;
+ arg.rnh = rnh;
+ arg.nextstop = 0;
+ arg.draining = 1;
+ arg.updating = 0;
+ s = splnet();
+ rnh->rnh_walktree(rnh, in_rtqkill, &arg);
+ splx(s);
+}
+
+/*
+ * Initialize our routing tree.
+ */
+int
+in_inithead(void **head, int off)
+{
+ struct radix_node_head *rnh;
+
+ if(!rn_inithead(head, off))
+ return 0;
+
+ if(head != (void **)&rt_tables[AF_INET]) /* BOGUS! */
+ return 1; /* only do this for the real routing table */
+
+ rnh = *head;
+ rnh->rnh_addaddr = in_addroute;
+ rnh->rnh_matchaddr = in_matroute;
+ rnh->rnh_close = in_clsroute;
+ in_rtqtimo(rnh); /* kick off timeout first time */
+ return 1;
+}
diff --git a/cpukit/libnetworking/netinet/in_systm.h b/cpukit/libnetworking/netinet/in_systm.h
new file mode 100644
index 0000000000..43d458fa20
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_systm.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_systm.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/in_systm.h,v 1.13 2009/02/13 15:14:43 luigi Exp $
+ */
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IN_SYSTM_H_
+#define _NETINET_IN_SYSTM_H_
+
+/*
+ * Miscellaneous internetwork
+ * definitions for kernel.
+ */
+
+/*
+ * Network types.
+ *
+ * Internally the system keeps counters in the headers with the bytes
+ * swapped so that VAX instructions will work on them. It reverses
+ * the bytes before transmission at each protocol level. The n_ types
+ * represent the types with the bytes in ``high-ender'' order.
+ */
+typedef u_int16_t n_short; /* short as received from the net */
+typedef u_int32_t n_long; /* long as received from the net */
+
+typedef u_int32_t n_time; /* ms since 00:00 GMT, byte rev */
+
+#ifdef _KERNEL
+uint32_t iptime(void);
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/netinet/in_var.h b/cpukit/libnetworking/netinet/in_var.h
new file mode 100644
index 0000000000..3d555803f8
--- /dev/null
+++ b/cpukit/libnetworking/netinet/in_var.h
@@ -0,0 +1,238 @@
+/* $Id */
+/*
+ * Copyright (c) 1985, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_var.h 8.2 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/netinet/in_var.h,v 1.52 2004/10/19 21:06:14 andre Exp $
+ */
+
+#ifndef _NETINET_IN_VAR_H_
+#define _NETINET_IN_VAR_H_
+
+#include <sys/queue.h>
+#if !defined(__rtems__)
+#include <sys/fnv_hash.h>
+#endif
+
+/*
+ * Interface address, Internet version. One of these structures
+ * is allocated for each Internet address on an interface.
+ * The ifaddr structure contains the protocol-independent part
+ * of the structure and is assumed to be first.
+ */
+struct in_ifaddr {
+ struct ifaddr ia_ifa; /* protocol-independent info */
+#define ia_ifp ia_ifa.ifa_ifp
+#define ia_flags ia_ifa.ifa_flags
+ /* ia_{,sub}net{,mask} in host order */
+ u_long ia_net; /* network number of interface */
+ u_long ia_netmask; /* mask of net part */
+ u_long ia_subnet; /* subnet number, including net */
+ u_long ia_subnetmask; /* mask of subnet part */
+ struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
+ struct in_ifaddr *ia_next; /* next in list of internet addresses */
+ struct sockaddr_in ia_addr; /* reserve space for interface name */
+ struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
+#define ia_broadaddr ia_dstaddr
+ struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
+ LIST_HEAD(in_multihead, in_multi) ia_multiaddrs;
+ /* list of multicast addresses */
+};
+
+struct in_aliasreq {
+ char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ struct sockaddr_in ifra_addr;
+ struct sockaddr_in ifra_broadaddr;
+#define ifra_dstaddr ifra_broadaddr
+ struct sockaddr_in ifra_mask;
+};
+/*
+ * Given a pointer to an in_ifaddr (ifaddr),
+ * return a pointer to the addr as a sockaddr_in.
+ */
+#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
+#define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
+
+#define IN_LNAOF(in, ifa) \
+ ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
+
+
+#ifdef _KERNEL
+extern struct in_ifaddr *in_ifaddr;
+extern struct ifqueue ipintrq; /* ip packet input queue */
+extern struct in_addr zeroin_addr;
+extern u_char inetctlerrmap[];
+
+/*
+ * Macro for finding the interface (ifnet structure) corresponding to one
+ * of our IP addresses.
+ */
+#define INADDR_TO_IFP(addr, ifp) \
+ /* struct in_addr addr; */ \
+ /* struct ifnet *ifp; */ \
+{ \
+ register struct in_ifaddr *ia; \
+\
+ for (ia = in_ifaddr; \
+ ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \
+ IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \
+ ia = ia->ia_next) \
+ continue; \
+ if (ia == NULL) \
+ for (ia = in_ifaddr; \
+ ia != NULL; \
+ ia = ia->ia_next) \
+ if (ia->ia_ifp->if_flags & IFF_POINTOPOINT && \
+ IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
+ break; \
+ (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
+}
+
+/*
+ * Macro for finding the internet address structure (in_ifaddr) corresponding
+ * to a given interface (ifnet structure).
+ */
+#define IFP_TO_IA(ifp, ia) \
+ /* struct ifnet *ifp; */ \
+ /* struct in_ifaddr *ia; */ \
+{ \
+ for ((ia) = in_ifaddr; \
+ (ia) != NULL && (ia)->ia_ifp != (ifp); \
+ (ia) = (ia)->ia_next) \
+ continue; \
+}
+#endif
+
+/*
+ * This information should be part of the ifnet structure but we don't wish
+ * to change that - as it might break a number of things
+ */
+
+struct router_info {
+ struct ifnet *rti_ifp;
+ int rti_type; /* type of router which is querier on this interface */
+ int rti_time; /* # of slow timeouts since last old query */
+ struct router_info *rti_next;
+};
+
+/*
+ * Internet multicast address structure. There is one of these for each IP
+ * multicast group to which this host belongs on a given network interface.
+ * They are kept in a linked list, rooted in the interface's in_ifaddr
+ * structure.
+ */
+struct in_multi {
+ LIST_ENTRY(in_multi) inm_entry; /* list glue */
+ struct in_addr inm_addr; /* IP multicast address */
+ struct ifnet *inm_ifp; /* back pointer to ifnet */
+ struct in_ifaddr *inm_ia; /* back pointer to in_ifaddr */
+ u_int inm_refcount; /* no. membership claims by sockets */
+ u_int inm_timer; /* IGMP membership report timer */
+ u_int inm_state; /* state of the membership */
+ struct router_info *inm_rti; /* router info*/
+};
+
+#ifdef _KERNEL
+
+#ifdef SYSCTL_DECL
+SYSCTL_DECL(_net_inet_ip);
+SYSCTL_DECL(_net_inet_raw);
+#endif
+
+/*
+ * Structure used by macros below to remember position when stepping through
+ * all of the in_multi records.
+ */
+struct in_multistep {
+ struct in_ifaddr *i_ia;
+ struct in_multi *i_inm;
+};
+
+/*
+ * Macro for looking up the in_multi record for a given IP multicast address
+ * on a given interface. If no matching record is found, "inm" returns NULL.
+ */
+#define IN_LOOKUP_MULTI(addr, ifp, inm) \
+ /* struct in_addr addr; */ \
+ /* struct ifnet *ifp; */ \
+ /* struct in_multi *inm; */ \
+{ \
+ register struct in_ifaddr *ia; \
+\
+ IFP_TO_IA((ifp), ia); \
+ if (ia == NULL) \
+ (inm) = NULL; \
+ else \
+ for ((inm) = ia->ia_multiaddrs.lh_first; \
+ (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr; \
+ (inm) = inm->inm_entry.le_next) \
+ continue; \
+}
+
+/*
+ * Macro to step through all of the in_multi records, one at a time.
+ * The current position is remembered in "step", which the caller must
+ * provide. IN_FIRST_MULTI(), below, must be called to initialize "step"
+ * and get the first record. Both macros return a NULL "inm" when there
+ * are no remaining records.
+ */
+#define IN_NEXT_MULTI(step, inm) \
+ /* struct in_multistep step; */ \
+ /* struct in_multi *inm; */ \
+{ \
+ if (((inm) = (step).i_inm) != NULL) \
+ (step).i_inm = (inm)->inm_entry.le_next; \
+ else \
+ while ((step).i_ia != NULL) { \
+ (inm) = (step).i_ia->ia_multiaddrs.lh_first; \
+ (step).i_ia = (step).i_ia->ia_next; \
+ if ((inm) != NULL) { \
+ (step).i_inm = (inm)->inm_entry.le_next; \
+ break; \
+ } \
+ } \
+}
+
+#define IN_FIRST_MULTI(step, inm) \
+ /* struct in_multistep step; */ \
+ /* struct in_multi *inm; */ \
+{ \
+ (step).i_ia = in_ifaddr; \
+ (step).i_inm = NULL; \
+ IN_NEXT_MULTI((step), (inm)); \
+}
+
+struct in_multi *in_addmulti(struct in_addr *, struct ifnet *);
+void in_delmulti(struct in_multi *);
+int in_control(struct socket *, u_long, caddr_t, struct ifnet *);
+void in_rtqdrain(void);
+void ip_input(struct mbuf *);
+
+#endif /* _KERNEL */
+
+#endif /* _NETINET_IN_VAR_H_ */
diff --git a/cpukit/libnetworking/netinet/ip.h b/cpukit/libnetworking/netinet/ip.h
new file mode 100644
index 0000000000..04625b95a6
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip.h
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip.h 8.2 (Berkeley) 6/1/94
+ * $FreeBSD: src/sys/netinet/ip.h,v 1.29 2005/01/07 01:45:44 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IP_H_
+#define _NETINET_IP_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+
+/*
+ * Definitions for internet protocol version 4.
+ * Per RFC 791, September 1981.
+ */
+#define IPVERSION 4
+
+#ifndef __packed
+#if defined(__GNUC__)
+#define __packed __attribute__((packed))
+#define __aligned(x) __attribute__((aligned(x)))
+#else
+#define __packed
+#define __aligned(x)
+#endif
+#endif
+
+/*
+ * Structure of an internet header, naked of options.
+ */
+struct ip {
+#ifdef _IP_VHL
+ u_char ip_vhl; /* version << 4 | header length >> 2 */
+#else
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_int ip_hl:4, /* header length */
+ ip_v:4; /* version */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ u_int ip_v:4, /* version */
+ ip_hl:4; /* header length */
+#endif
+#endif /* not _IP_VHL */
+ u_char ip_tos; /* type of service */
+ u_short ip_len; /* total length */
+ u_short ip_id; /* identification */
+ u_short ip_off; /* fragment offset field */
+#define IP_RF 0x8000 /* reserved fragment flag */
+#define IP_DF 0x4000 /* dont fragment flag */
+#define IP_MF 0x2000 /* more fragments flag */
+#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
+ u_char ip_ttl; /* time to live */
+ u_char ip_p; /* protocol */
+ u_short ip_sum; /* checksum */
+ struct in_addr ip_src,ip_dst; /* source and dest address */
+} __packed __aligned(4);
+
+#ifdef _IP_VHL
+#define IP_MAKE_VHL(v, hl) ((v) << 4 | (hl))
+#define IP_VHL_HL(vhl) ((vhl) & 0x0f)
+#define IP_VHL_V(vhl) ((vhl) >> 4)
+#define IP_VHL_BORING 0x45
+#endif
+
+#ifdef CTASSERT
+CTASSERT(sizeof (struct ip) == 20);
+#endif
+
+#define IP_MAXPACKET 65535L /* maximum packet size */
+
+/*
+ * Definitions for IP type of service (ip_tos)
+ */
+#define IPTOS_LOWDELAY 0x10
+#define IPTOS_THROUGHPUT 0x08
+#define IPTOS_RELIABILITY 0x04
+#define IPTOS_MINCOST 0x02
+#if 1
+/* ECN RFC3168 obsoletes RFC2481, and these will be deprecated soon. */
+#define IPTOS_CE 0x01
+#define IPTOS_ECT 0x02
+#endif
+
+/*
+ * Definitions for IP precedence (also in ip_tos) (hopefully unused)
+ */
+#define IPTOS_PREC_NETCONTROL 0xe0
+#define IPTOS_PREC_INTERNETCONTROL 0xc0
+#define IPTOS_PREC_CRITIC_ECP 0xa0
+#define IPTOS_PREC_FLASHOVERRIDE 0x80
+#define IPTOS_PREC_FLASH 0x60
+#define IPTOS_PREC_IMMEDIATE 0x40
+#define IPTOS_PREC_PRIORITY 0x20
+#define IPTOS_PREC_ROUTINE 0x00
+
+/*
+ * ECN (Explicit Congestion Notification) codepoints in RFC3168
+ * mapped to the lower 2 bits of the TOS field.
+ */
+#define IPTOS_ECN_NOTECT 0x00 /* not-ECT */
+#define IPTOS_ECN_ECT1 0x01 /* ECN-capable transport (1) */
+#define IPTOS_ECN_ECT0 0x02 /* ECN-capable transport (0) */
+#define IPTOS_ECN_CE 0x03 /* congestion experienced */
+#define IPTOS_ECN_MASK 0x03 /* ECN field mask */
+
+/*
+ * Definitions for options.
+ */
+#define IPOPT_COPIED(o) ((o)&0x80)
+#define IPOPT_CLASS(o) ((o)&0x60)
+#define IPOPT_NUMBER(o) ((o)&0x1f)
+
+#define IPOPT_CONTROL 0x00
+#define IPOPT_RESERVED1 0x20
+#define IPOPT_DEBMEAS 0x40
+#define IPOPT_RESERVED2 0x60
+
+#define IPOPT_EOL 0 /* end of option list */
+#define IPOPT_NOP 1 /* no operation */
+
+#define IPOPT_RR 7 /* record packet route */
+#define IPOPT_TS 68 /* timestamp */
+#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
+#define IPOPT_LSRR 131 /* loose source route */
+#define IPOPT_ESO 133 /* extended security */
+#define IPOPT_CIPSO 134 /* commerical security */
+#define IPOPT_SATID 136 /* satnet id */
+#define IPOPT_SSRR 137 /* strict source route */
+#define IPOPT_RA 148 /* router alert */
+
+/*
+ * Offsets to fields in options other than EOL and NOP.
+ */
+#define IPOPT_OPTVAL 0 /* option ID */
+#define IPOPT_OLEN 1 /* option length */
+#define IPOPT_OFFSET 2 /* offset within option */
+#define IPOPT_MINOFF 4 /* min value of above */
+
+/*
+ * Time stamp option structure.
+ */
+struct ip_timestamp {
+ u_char ipt_code; /* IPOPT_TS */
+ u_char ipt_len; /* size of structure (variable) */
+ u_char ipt_ptr; /* index of current entry */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_int ipt_flg:4, /* flags, see below */
+ ipt_oflw:4; /* overflow counter */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ u_int ipt_oflw:4, /* overflow counter */
+ ipt_flg:4; /* flags, see below */
+#endif
+ union ipt_timestamp {
+ n_long ipt_time[1];
+ struct ipt_ta {
+ struct in_addr ipt_addr;
+ n_long ipt_time;
+ } ipt_ta[1];
+ } ipt_timestamp;
+};
+
+#include <machine/in_cksum.h>
+
+/* flag bits for ipt_flg */
+#define IPOPT_TS_TSONLY 0 /* timestamps only */
+#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
+#define IPOPT_TS_PRESPEC 3 /* specified modules only */
+
+/* bits for security (not byte swapped) */
+#define IPOPT_SECUR_UNCLASS 0x0000
+#define IPOPT_SECUR_CONFID 0xf135
+#define IPOPT_SECUR_EFTO 0x789a
+#define IPOPT_SECUR_MMMM 0xbc4d
+#define IPOPT_SECUR_RESTR 0xaf13
+#define IPOPT_SECUR_SECRET 0xd788
+#define IPOPT_SECUR_TOPSECRET 0x6bc5
+
+/*
+ * Internet implementation parameters.
+ */
+#define MAXTTL 255 /* maximum time to live (seconds) */
+#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
+#define IPFRAGTTL 60 /* time to live for frags, slowhz */
+#define IPTTLDEC 1 /* subtracted when forwarding */
+
+#define IP_MSS 576 /* default maximum segment size */
+
+/*
+ * This is the real IPv4 pseudo header, used for computing the TCP and UDP
+ * checksums. For the Internet checksum, struct ipovly can be used instead.
+ * For stronger checksums, the real thing must be used.
+ */
+struct ippseudo {
+ struct in_addr ippseudo_src; /* source internet address */
+ struct in_addr ippseudo_dst; /* destination internet address */
+ u_char ippseudo_pad; /* pad, must be zero */
+ u_char ippseudo_p; /* protocol */
+ u_short ippseudo_len; /* protocol length */
+};
+#endif
diff --git a/cpukit/libnetworking/netinet/ip_divert.c b/cpukit/libnetworking/netinet/ip_divert.c
new file mode 100644
index 0000000000..6e480989ad
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_divert.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/netinet/ip_divert.c,v 1.113 2005/05/13 11:44:37 glebius Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/socketvar.h>
+#include <errno.h>
+#include <sys/systm.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
+
+/*
+ * Divert sockets
+ */
+
+/*
+ * Allocate enough space to hold a full IP packet
+ */
+#define DIVSNDQ (65536 + 100)
+#define DIVRCVQ (65536 + 100)
+
+/* Global variables */
+
+/*
+ * ip_input() and ip_output() set this secret value before calling us to
+ * let us know which divert port to divert a packet to; this is done so
+ * we can use the existing prototype for struct protosw's pr_input().
+ * This is stored in host order.
+ */
+u_short ip_divert_port;
+
+/*
+ * We set this value to a non-zero port number when we want the call to
+ * ip_fw_chk() in ip_input() or ip_output() to ignore ``divert <port>''
+ * chain entries. This is stored in host order.
+ */
+u_short ip_divert_ignore;
+
+/* Internal variables. */
+static struct inpcbhead divcb;
+static struct inpcbinfo divcbinfo;
+
+static u_long div_sendspace = DIVSNDQ; /* XXX sysctl ? */
+static u_long div_recvspace = DIVRCVQ; /* XXX sysctl ? */
+
+/* Optimization: have this preinitialized */
+static struct sockaddr_in divsrc = { sizeof(divsrc), AF_INET, 0, { 0 }, { 0 } };
+
+/* Internal functions */
+
+static int div_output(struct socket *so,
+ struct mbuf *m, struct mbuf *addr, struct mbuf *control);
+
+/*
+ * Initialize divert connection block queue.
+ */
+void
+div_init(void)
+{
+ LIST_INIT(&divcb);
+ divcbinfo.listhead = &divcb;
+ /*
+ * XXX We don't use the hash list for divert IP, but it's easier
+ * to allocate a one entry hash list than it is to check all
+ * over the place for hashbase == NULL.
+ */
+ divcbinfo.hashbase = hashinit(1, M_PCB, &divcbinfo.hashmask);
+}
+
+/*
+ * Setup generic address and protocol structures
+ * for div_input routine, then pass them along with
+ * mbuf chain. ip->ip_len is assumed to have had
+ * the header length (hlen) subtracted out already.
+ * We tell whether the packet was incoming or outgoing
+ * by seeing if hlen == 0, which is a hack.
+ */
+void
+div_input(struct mbuf *m, int hlen)
+{
+ struct ip *ip;
+ struct inpcb *inp;
+ struct socket *sa;
+
+ /* Sanity check */
+ if (ip_divert_port == 0)
+ panic("div_input: port is 0");
+
+ /* Assure header */
+ if (m->m_len < sizeof(struct ip) &&
+ (m = m_pullup(m, sizeof(struct ip))) == 0) {
+ return;
+ }
+ ip = mtod(m, struct ip *);
+
+ /* Record divert port */
+ divsrc.sin_port = htons(ip_divert_port);
+
+ /* Restore packet header fields */
+ ip->ip_len += hlen;
+ HTONS(ip->ip_len);
+ HTONS(ip->ip_off);
+
+ /* Record receive interface address, if any */
+ divsrc.sin_addr.s_addr = 0;
+ if (hlen) {
+ struct ifaddr *ifa;
+
+#ifdef DIAGNOSTIC
+ /* Sanity check */
+ if (!(m->m_flags & M_PKTHDR))
+ panic("div_input: no pkt hdr");
+#endif
+
+ /* More fields affected by ip_input() */
+ HTONS(ip->ip_id);
+
+ /* Find IP address for recieve interface */
+ for (ifa = m->m_pkthdr.rcvif->if_addrlist;
+ ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL)
+ continue;
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ continue;
+ divsrc.sin_addr =
+ ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr;
+ break;
+ }
+ }
+
+ /* Put packet on socket queue, if any */
+ sa = NULL;
+ for (inp = divcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
+ if (inp->inp_lport == htons(ip_divert_port))
+ sa = inp->inp_socket;
+ }
+ if (sa) {
+ if (sbappendaddr(&sa->so_rcv, (struct sockaddr *)&divsrc,
+ m, (struct mbuf *)0) == 0)
+ m_freem(m);
+ else
+ sorwakeup(sa);
+ } else {
+ m_freem(m);
+ ipstat.ips_noproto++;
+ ipstat.ips_delivered--;
+ }
+}
+
+/*
+ * Deliver packet back into the IP processing machinery.
+ *
+ * If no address specified, or address is 0.0.0.0, send to ip_output();
+ * otherwise, send to ip_input() and mark as having been received on
+ * the interface with that address.
+ *
+ * If no address specified, or dest port is 0, allow packet to divert
+ * back to this socket; otherwise, don't.
+ */
+static int
+div_output(struct socket *so, struct mbuf *m,
+ struct mbuf *addr, struct mbuf *control)
+{
+ register struct inpcb *const inp = sotoinpcb(so);
+ register struct ip *const ip = mtod(m, struct ip *);
+ struct sockaddr_in *sin = NULL;
+ int error = 0;
+
+ if (control)
+ m_freem(control); /* XXX */
+ if (addr)
+ sin = mtod(addr, struct sockaddr_in *);
+
+ /* Loopback avoidance option */
+ ip_divert_ignore = ntohs(inp->inp_lport);
+
+ /* Reinject packet into the system as incoming or outgoing */
+ if (!sin || sin->sin_addr.s_addr == 0) {
+ /* Don't allow both user specified and setsockopt options,
+ and don't allow packet length sizes that will crash */
+ if (((ip->ip_hl != (sizeof (*ip) >> 2)) && inp->inp_options) ||
+ ((u_short)ntohs(ip->ip_len) > m->m_pkthdr.len)) {
+ error = EINVAL;
+ goto cantsend;
+ }
+
+ /* Convert fields to host order for ip_output() */
+ NTOHS(ip->ip_len);
+ NTOHS(ip->ip_off);
+
+ /* Send packet to output processing */
+ ipstat.ips_rawout++; /* XXX */
+ error = ip_output(m, inp->inp_options, &inp->inp_route,
+ (so->so_options & SO_DONTROUTE) |
+ IP_ALLOWBROADCAST | IP_RAWOUTPUT, inp->inp_moptions);
+ } else {
+ struct ifaddr *ifa;
+
+ /* Find receive interface with the given IP address */
+ sin->sin_port = 0;
+ if ((ifa = ifa_ifwithaddr((struct sockaddr *) sin)) == 0) {
+ error = EADDRNOTAVAIL;
+ goto cantsend;
+ }
+ m->m_pkthdr.rcvif = ifa->ifa_ifp;
+
+ /* Send packet to input processing */
+ ip_input(m);
+ }
+
+ /* Reset for next time (and other packets) */
+ ip_divert_ignore = 0;
+ return error;
+
+cantsend:
+ ip_divert_ignore = 0;
+ m_freem(m);
+ return error;
+}
+
+/*ARGSUSED*/
+int
+div_usrreq(
+ struct socket *so,
+ int req,
+ struct mbuf *m,
+ struct mbuf *nam,
+ struct mbuf *control )
+{
+ register int error = 0;
+ register struct inpcb *inp = sotoinpcb(so);
+ int s;
+
+ if (inp == NULL && req != PRU_ATTACH) {
+ error = EINVAL;
+ goto release;
+ }
+ switch (req) {
+
+ case PRU_ATTACH:
+ if (inp)
+ panic("div_attach");
+ if ((so->so_state & SS_PRIV) == 0) {
+ error = EACCES;
+ break;
+ }
+ s = splnet();
+ error = in_pcballoc(so, &divcbinfo);
+ splx(s);
+ if (error)
+ break;
+ error = soreserve(so, div_sendspace, div_recvspace);
+ if (error)
+ break;
+ inp = (struct inpcb *)so->so_pcb;
+ inp->inp_ip_p = (intptr_t)nam; /* XXX */
+ inp->inp_flags |= INP_HDRINCL;
+ /* The socket is always "connected" because
+ we always know "where" to send the packet */
+ so->so_state |= SS_ISCONNECTED;
+ break;
+
+ case PRU_DISCONNECT:
+ if ((so->so_state & SS_ISCONNECTED) == 0) {
+ error = ENOTCONN;
+ break;
+ }
+ /* FALLTHROUGH */
+ case PRU_ABORT:
+ soisdisconnected(so);
+ /* FALLTHROUGH */
+ case PRU_DETACH:
+ if (inp == 0)
+ panic("div_detach");
+ in_pcbdetach(inp);
+ break;
+
+ case PRU_BIND:
+ s = splnet();
+ error = in_pcbbind(inp, nam);
+ splx(s);
+ break;
+
+ /*
+ * Mark the connection as being incapable of further input.
+ */
+ case PRU_SHUTDOWN:
+ socantsendmore(so);
+ break;
+
+ case PRU_SEND:
+ /* Packet must have a header (but that's about it) */
+ if (m->m_len < sizeof (struct ip) ||
+ (m = m_pullup(m, sizeof (struct ip))) == 0) {
+ ipstat.ips_toosmall++;
+ error = EINVAL;
+ break;
+ }
+
+ /* Send packet */
+ error = div_output(so, m, nam, control);
+ m = NULL;
+ break;
+
+ case PRU_SOCKADDR:
+ in_setsockaddr(inp, nam);
+ break;
+
+ case PRU_SENSE:
+ /*
+ * stat: don't bother with a blocksize.
+ */
+ return (0);
+
+ /*
+ * Not supported.
+ */
+ case PRU_CONNECT:
+ case PRU_CONNECT2:
+ case PRU_CONTROL:
+ case PRU_RCVOOB:
+ case PRU_RCVD:
+ case PRU_LISTEN:
+ case PRU_ACCEPT:
+ case PRU_SENDOOB:
+ case PRU_PEERADDR:
+ error = EOPNOTSUPP;
+ break;
+
+ default:
+ panic("div_usrreq");
+ }
+release:
+ if (m)
+ m_freem(m);
+ return (error);
+}
diff --git a/cpukit/libnetworking/netinet/ip_fw.c b/cpukit/libnetworking/netinet/ip_fw.c
new file mode 100644
index 0000000000..a371cdbab7
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_fw.c
@@ -0,0 +1,1079 @@
+/*
+ * Copyright (c) 1996 Alex Nash
+ * Copyright (c) 1993 Daniel Boulet
+ * Copyright (c) 1994 Ugen J.S.Antsilevich
+ *
+ * Redistribution and use in source forms, with and without modification,
+ * are permitted provided that this entire comment appears intact.
+ *
+ * Redistribution in binary form may occur without any restrictions.
+ * Obviously, it would be nice if you gave credit where credit is due
+ * but requiring it would be too onerous.
+ *
+ * This software is provided ``AS IS'' without any warranties of any kind.
+ *
+ * $Id$
+ */
+
+/*
+ * Implement IP packet firewall
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef IPFIREWALL_MODULE
+#include "opt_ipfw.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/queue.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/sysctl.h>
+#include <net/if.h>
+#include <net/route.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/ip_fw.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#include <netinet/udp.h>
+
+static int fw_debug = 1;
+#ifdef IPFIREWALL_VERBOSE
+static int fw_verbose = 1;
+#else
+static int fw_verbose = 0;
+#endif
+#ifdef IPFIREWALL_VERBOSE_LIMIT
+static int fw_verbose_limit = IPFIREWALL_VERBOSE_LIMIT;
+#else
+static int fw_verbose_limit = 0;
+#endif
+
+LIST_HEAD (ip_fw_head, ip_fw_chain) ip_fw_chain;
+
+/*
+ * ccj - No current need for firewall so have provided the MIB.
+ */
+#if 0
+#ifdef SYSCTL_NODE
+SYSCTL_NODE(_net_inet_ip, OID_AUTO, fw, CTLFLAG_RW, 0, "Firewall");
+SYSCTL_INT(_net_inet_ip_fw, OID_AUTO, debug, CTLFLAG_RW, &fw_debug, 0, "");
+SYSCTL_INT(_net_inet_ip_fw, OID_AUTO, verbose, CTLFLAG_RW, &fw_verbose, 0, "");
+SYSCTL_INT(_net_inet_ip_fw, OID_AUTO, verbose_limit, CTLFLAG_RW, &fw_verbose_limit, 0, "");
+#endif
+#endif
+
+#define dprintf(a) if (!fw_debug); else printf a
+
+#define print_ip(a) printf("%"PRId32".%"PRId32".%"PRId32".%"PRId32,\
+ (ntohl(a.s_addr)>>24)&0xFF,\
+ (ntohl(a.s_addr)>>16)&0xFF,\
+ (ntohl(a.s_addr)>>8)&0xFF,\
+ (ntohl(a.s_addr))&0xFF);
+
+#define dprint_ip(a) if (!fw_debug); else print_ip(a)
+
+static int add_entry(struct ip_fw_head *chainptr, struct ip_fw *frwl);
+static int del_entry(struct ip_fw_head *chainptr, u_short number);
+static int zero_entry(struct mbuf *m);
+static struct ip_fw *check_ipfw_struct(struct ip_fw *m);
+static struct ip_fw *check_ipfw_mbuf(struct mbuf *fw);
+static int ipopts_match(struct ip *ip, struct ip_fw *f);
+static int port_match(u_short *portptr, int nports, u_short port,
+ int range_flag);
+static int tcpflg_match(struct tcphdr *tcp, struct ip_fw *f);
+static int icmptype_match(struct icmp * icmp, struct ip_fw * f);
+static void ipfw_report(struct ip_fw *f, struct ip *ip,
+ struct ifnet *rif, struct ifnet *oif);
+
+#ifdef IPFIREWALL_MODULE
+static ip_fw_chk_t *old_chk_ptr;
+static ip_fw_ctl_t *old_ctl_ptr;
+#endif
+
+static int ip_fw_chk(struct ip **pip, int hlen,
+ struct ifnet *oif, int ignport, struct mbuf **m);
+static int ip_fw_ctl(int stage, struct mbuf **mm);
+
+static char err_prefix[] = "ip_fw_ctl:";
+
+/*
+ * Returns 1 if the port is matched by the vector, 0 otherwise
+ */
+static inline int
+port_match(u_short *portptr, int nports, u_short port, int range_flag)
+{
+ if (!nports)
+ return 1;
+ if (range_flag) {
+ if (portptr[0] <= port && port <= portptr[1]) {
+ return 1;
+ }
+ nports -= 2;
+ portptr += 2;
+ }
+ while (nports-- > 0) {
+ if (*portptr++ == port) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static int
+tcpflg_match(struct tcphdr *tcp, struct ip_fw *f)
+{
+ u_char flg_set, flg_clr;
+
+ if ((f->fw_tcpf & IP_FW_TCPF_ESTAB) &&
+ (tcp->th_flags & (IP_FW_TCPF_RST | IP_FW_TCPF_ACK)))
+ return 1;
+
+ flg_set = tcp->th_flags & f->fw_tcpf;
+ flg_clr = tcp->th_flags & f->fw_tcpnf;
+
+ if (flg_set != f->fw_tcpf)
+ return 0;
+ if (flg_clr)
+ return 0;
+
+ return 1;
+}
+
+static int
+icmptype_match(struct icmp *icmp, struct ip_fw *f)
+{
+ int type;
+
+ if (!(f->fw_flg & IP_FW_F_ICMPBIT))
+ return(1);
+
+ type = icmp->icmp_type;
+
+ /* check for matching type in the bitmap */
+ if (type < IP_FW_ICMPTYPES_DIM * sizeof(unsigned) * 8 &&
+ (f->fw_icmptypes[type / (sizeof(unsigned) * 8)] &
+ (1U << (type % (8 * sizeof(unsigned))))))
+ return(1);
+
+ return(0); /* no match */
+}
+
+static int
+ipopts_match(struct ip *ip, struct ip_fw *f)
+{
+ register u_char *cp;
+ int opt, optlen, cnt;
+ u_char opts, nopts, nopts_sve;
+
+ cp = (u_char *)(ip + 1);
+ cnt = (ip->ip_hl << 2) - sizeof (struct ip);
+ opts = f->fw_ipopt;
+ nopts = nopts_sve = f->fw_ipnopt;
+
+ for (; cnt > 0; cnt -= optlen, cp += optlen) {
+ opt = cp[IPOPT_OPTVAL];
+ if (opt == IPOPT_EOL)
+ break;
+ if (opt == IPOPT_NOP)
+ optlen = 1;
+ else {
+ optlen = cp[IPOPT_OLEN];
+ if (optlen <= 0 || optlen > cnt) {
+ return 0; /*XXX*/
+ }
+ }
+ switch (opt) {
+
+ default:
+ break;
+
+ case IPOPT_LSRR:
+ opts &= ~IP_FW_IPOPT_LSRR;
+ nopts &= ~IP_FW_IPOPT_LSRR;
+ break;
+
+ case IPOPT_SSRR:
+ opts &= ~IP_FW_IPOPT_SSRR;
+ nopts &= ~IP_FW_IPOPT_SSRR;
+ break;
+
+ case IPOPT_RR:
+ opts &= ~IP_FW_IPOPT_RR;
+ nopts &= ~IP_FW_IPOPT_RR;
+ break;
+ case IPOPT_TS:
+ opts &= ~IP_FW_IPOPT_TS;
+ nopts &= ~IP_FW_IPOPT_TS;
+ break;
+ }
+ if (opts == nopts)
+ break;
+ }
+ if (opts == 0 && nopts == nopts_sve)
+ return 1;
+ else
+ return 0;
+}
+
+static inline int
+iface_match(struct ifnet *ifp, union ip_fw_if *ifu, int byname)
+{
+ /* Check by name or by IP address */
+ if (byname) {
+ /* Check unit number (-1 is wildcard) */
+ if (ifu->fu_via_if.unit != -1
+ && ifp->if_unit != ifu->fu_via_if.unit)
+ return(0);
+ /* Check name */
+ if (strncmp(ifp->if_name, ifu->fu_via_if.name, FW_IFNLEN))
+ return(0);
+ return(1);
+ } else if (ifu->fu_via_ip.s_addr != 0) { /* Zero == wildcard */
+ struct ifaddr *ia;
+
+ for (ia = ifp->if_addrlist; ia; ia = ia->ifa_next) {
+ if (ia->ifa_addr == NULL)
+ continue;
+ if (ia->ifa_addr->sa_family != AF_INET)
+ continue;
+ if (ifu->fu_via_ip.s_addr != ((struct sockaddr_in *)
+ (ia->ifa_addr))->sin_addr.s_addr)
+ continue;
+ return(1);
+ }
+ return(0);
+ }
+ return(1);
+}
+
+static void
+ipfw_report(struct ip_fw *f, struct ip *ip,
+ struct ifnet *rif, struct ifnet *oif)
+{
+ static int counter;
+ struct tcphdr *const tcp = (struct tcphdr *) ((u_long *) ip+ ip->ip_hl);
+ struct udphdr *const udp = (struct udphdr *) ((u_long *) ip+ ip->ip_hl);
+ struct icmp *const icmp = (struct icmp *) ((u_long *) ip + ip->ip_hl);
+ int count;
+
+ count = f ? f->fw_pcnt : ++counter;
+ if (fw_verbose_limit != 0 && count > fw_verbose_limit)
+ return;
+
+ /* Print command name */
+ printf("ipfw: %d ", f ? f->fw_number : -1);
+ if (!f)
+ printf("Refuse");
+ else
+ switch (f->fw_flg & IP_FW_F_COMMAND) {
+ case IP_FW_F_DENY:
+ printf("Deny");
+ break;
+ case IP_FW_F_REJECT:
+ if (f->fw_reject_code == IP_FW_REJECT_RST)
+ printf("Reset");
+ else
+ printf("Unreach");
+ break;
+ case IP_FW_F_ACCEPT:
+ printf("Accept");
+ break;
+ case IP_FW_F_COUNT:
+ printf("Count");
+ break;
+ case IP_FW_F_DIVERT:
+ printf("Divert %d", f->fw_divert_port);
+ break;
+ case IP_FW_F_TEE:
+ printf("Tee %d", f->fw_divert_port);
+ break;
+ case IP_FW_F_SKIPTO:
+ printf("SkipTo %d", f->fw_skipto_rule);
+ break;
+ default:
+ printf("UNKNOWN");
+ break;
+ }
+ printf(" ");
+
+ switch (ip->ip_p) {
+ case IPPROTO_TCP:
+ printf("TCP ");
+ print_ip(ip->ip_src);
+ if ((ip->ip_off & IP_OFFMASK) == 0)
+ printf(":%d ", ntohs(tcp->th_sport));
+ else
+ printf(" ");
+ print_ip(ip->ip_dst);
+ if ((ip->ip_off & IP_OFFMASK) == 0)
+ printf(":%d", ntohs(tcp->th_dport));
+ break;
+ case IPPROTO_UDP:
+ printf("UDP ");
+ print_ip(ip->ip_src);
+ if ((ip->ip_off & IP_OFFMASK) == 0)
+ printf(":%d ", ntohs(udp->uh_sport));
+ else
+ printf(" ");
+ print_ip(ip->ip_dst);
+ if ((ip->ip_off & IP_OFFMASK) == 0)
+ printf(":%d", ntohs(udp->uh_dport));
+ break;
+ case IPPROTO_ICMP:
+ printf("ICMP:%u.%u ", icmp->icmp_type, icmp->icmp_code);
+ print_ip(ip->ip_src);
+ printf(" ");
+ print_ip(ip->ip_dst);
+ break;
+ default:
+ printf("P:%d ", ip->ip_p);
+ print_ip(ip->ip_src);
+ printf(" ");
+ print_ip(ip->ip_dst);
+ break;
+ }
+ if (oif)
+ printf(" out via %s%d", oif->if_name, oif->if_unit);
+ else if (rif)
+ printf(" in via %s%d", rif->if_name, rif->if_unit);
+ if ((ip->ip_off & IP_OFFMASK))
+ printf(" Fragment = %d",ip->ip_off & IP_OFFMASK);
+ printf("\n");
+ if (fw_verbose_limit != 0 && count == fw_verbose_limit)
+ printf("ipfw: limit reached on rule #%d\n",
+ f ? f->fw_number : -1);
+}
+
+/*
+ * Parameters:
+ *
+ * ip Pointer to packet header (struct ip *)
+ * hlen Packet header length
+ * oif Outgoing interface, or NULL if packet is incoming
+ * ignport Ignore all divert/tee rules to this port (if non-zero)
+ * *m The packet; we set to NULL when/if we nuke it.
+ *
+ * Return value:
+ *
+ * 0 The packet is to be accepted and routed normally OR
+ * the packet was denied/rejected and has been dropped;
+ * in the latter case, *m is equal to NULL upon return.
+ * port Divert the packet to port.
+ */
+
+static int
+ip_fw_chk(struct ip **pip, int hlen,
+ struct ifnet *oif, int ignport, struct mbuf **m)
+{
+ struct ip_fw_chain *chain;
+ struct ip_fw *rule = NULL;
+ struct ip *ip = *pip;
+ struct ifnet *const rif = (*m)->m_pkthdr.rcvif;
+ u_short offset = (ip->ip_off & IP_OFFMASK);
+ u_short src_port, dst_port;
+
+ /*
+ * Go down the chain, looking for enlightment
+ */
+ for (chain=ip_fw_chain.lh_first; chain; chain = chain->chain.le_next) {
+ register struct ip_fw *const f = chain->rule;
+
+ /* Check direction inbound */
+ if (!oif && !(f->fw_flg & IP_FW_F_IN))
+ continue;
+
+ /* Check direction outbound */
+ if (oif && !(f->fw_flg & IP_FW_F_OUT))
+ continue;
+
+ /* Fragments */
+ if ((f->fw_flg & IP_FW_F_FRAG) && !(ip->ip_off & IP_OFFMASK))
+ continue;
+
+ /* If src-addr doesn't match, not this rule. */
+ if (((f->fw_flg & IP_FW_F_INVSRC) != 0) ^ ((ip->ip_src.s_addr
+ & f->fw_smsk.s_addr) != f->fw_src.s_addr))
+ continue;
+
+ /* If dest-addr doesn't match, not this rule. */
+ if (((f->fw_flg & IP_FW_F_INVDST) != 0) ^ ((ip->ip_dst.s_addr
+ & f->fw_dmsk.s_addr) != f->fw_dst.s_addr))
+ continue;
+
+ /* Interface check */
+ if ((f->fw_flg & IF_FW_F_VIAHACK) == IF_FW_F_VIAHACK) {
+ struct ifnet *const iface = oif ? oif : rif;
+
+ /* Backwards compatibility hack for "via" */
+ if (!iface || !iface_match(iface,
+ &f->fw_in_if, f->fw_flg & IP_FW_F_OIFNAME))
+ continue;
+ } else {
+ /* Check receive interface */
+ if ((f->fw_flg & IP_FW_F_IIFACE)
+ && (!rif || !iface_match(rif,
+ &f->fw_in_if, f->fw_flg & IP_FW_F_IIFNAME)))
+ continue;
+ /* Check outgoing interface */
+ if ((f->fw_flg & IP_FW_F_OIFACE)
+ && (!oif || !iface_match(oif,
+ &f->fw_out_if, f->fw_flg & IP_FW_F_OIFNAME)))
+ continue;
+ }
+
+ /* Check IP options */
+ if (f->fw_ipopt != f->fw_ipnopt && !ipopts_match(ip, f))
+ continue;
+
+ /* Check protocol; if wildcard, match */
+ if (f->fw_prot == IPPROTO_IP)
+ goto got_match;
+
+ /* If different, don't match */
+ if (ip->ip_p != f->fw_prot)
+ continue;
+
+#define PULLUP_TO(len) do { \
+ if ((*m)->m_len < (len) \
+ && (*m = m_pullup(*m, (len))) == 0) { \
+ goto bogusfrag; \
+ } \
+ *pip = ip = mtod(*m, struct ip *); \
+ offset = (ip->ip_off & IP_OFFMASK); \
+ } while (0)
+
+ /* Protocol specific checks */
+ switch (ip->ip_p) {
+ case IPPROTO_TCP:
+ {
+ struct tcphdr *tcp;
+
+ if (offset == 1) /* cf. RFC 1858 */
+ goto bogusfrag;
+ if (offset != 0) {
+ /*
+ * TCP flags and ports aren't available in this
+ * packet -- if this rule specified either one,
+ * we consider the rule a non-match.
+ */
+ if (f->fw_nports != 0 ||
+ f->fw_tcpf != f->fw_tcpnf)
+ continue;
+
+ break;
+ }
+ PULLUP_TO(hlen + 14);
+ tcp = (struct tcphdr *) ((u_long *)ip + ip->ip_hl);
+ if (f->fw_tcpf != f->fw_tcpnf && !tcpflg_match(tcp, f))
+ continue;
+ src_port = ntohs(tcp->th_sport);
+ dst_port = ntohs(tcp->th_dport);
+ goto check_ports;
+ }
+
+ case IPPROTO_UDP:
+ {
+ struct udphdr *udp;
+
+ if (offset != 0) {
+ /*
+ * Port specification is unavailable -- if this
+ * rule specifies a port, we consider the rule
+ * a non-match.
+ */
+ if (f->fw_nports != 0)
+ continue;
+
+ break;
+ }
+ PULLUP_TO(hlen + 4);
+ udp = (struct udphdr *) ((u_long *)ip + ip->ip_hl);
+ src_port = ntohs(udp->uh_sport);
+ dst_port = ntohs(udp->uh_dport);
+check_ports:
+ if (!port_match(&f->fw_pts[0],
+ IP_FW_GETNSRCP(f), src_port,
+ f->fw_flg & IP_FW_F_SRNG))
+ continue;
+ if (!port_match(&f->fw_pts[IP_FW_GETNSRCP(f)],
+ IP_FW_GETNDSTP(f), dst_port,
+ f->fw_flg & IP_FW_F_DRNG))
+ continue;
+ break;
+ }
+
+ case IPPROTO_ICMP:
+ {
+ struct icmp *icmp;
+
+ if (offset != 0) /* Type isn't valid */
+ break;
+ PULLUP_TO(hlen + 2);
+ icmp = (struct icmp *) ((u_long *)ip + ip->ip_hl);
+ if (!icmptype_match(icmp, f))
+ continue;
+ break;
+ }
+#undef PULLUP_TO
+
+bogusfrag:
+ if (fw_verbose)
+ ipfw_report(NULL, ip, rif, oif);
+ goto dropit;
+ }
+
+got_match:
+ /* Ignore divert/tee rule if socket port is "ignport" */
+ switch (f->fw_flg & IP_FW_F_COMMAND) {
+ case IP_FW_F_DIVERT:
+ case IP_FW_F_TEE:
+ if (f->fw_divert_port == ignport)
+ continue; /* ignore this rule */
+ break;
+ }
+
+ /* Update statistics */
+ f->fw_pcnt += 1;
+ f->fw_bcnt += ip->ip_len;
+ f->timestamp = rtems_bsdnet_seconds_since_boot();
+
+ /* Log to console if desired */
+ if ((f->fw_flg & IP_FW_F_PRN) && fw_verbose)
+ ipfw_report(f, ip, rif, oif);
+
+ /* Take appropriate action */
+ switch (f->fw_flg & IP_FW_F_COMMAND) {
+ case IP_FW_F_ACCEPT:
+ return(0);
+ case IP_FW_F_COUNT:
+ continue;
+ case IP_FW_F_DIVERT:
+ return(f->fw_divert_port);
+ case IP_FW_F_TEE:
+ /*
+ * XXX someday tee packet here, but beware that you
+ * can't use m_copym() or m_copypacket() because
+ * the divert input routine modifies the mbuf
+ * (and these routines only increment reference
+ * counts in the case of mbuf clusters), so need
+ * to write custom routine.
+ */
+ continue;
+ case IP_FW_F_SKIPTO:
+#ifdef DIAGNOSTIC
+ while (chain->chain.le_next
+ && chain->chain.le_next->rule->fw_number
+ < f->fw_skipto_rule)
+#else
+ while (chain->chain.le_next->rule->fw_number
+ < f->fw_skipto_rule)
+#endif
+ chain = chain->chain.le_next;
+ continue;
+ }
+
+ /* Deny/reject this packet using this rule */
+ rule = f;
+ break;
+ }
+
+#ifdef DIAGNOSTIC
+ /* Rule 65535 should always be there and should always match */
+ if (!chain)
+ panic("ip_fw: chain");
+#endif
+
+ /*
+ * At this point, we're going to drop the packet.
+ * Send a reject notice if all of the following are true:
+ *
+ * - The packet matched a reject rule
+ * - The packet is not an ICMP packet
+ * - The packet is not a multicast or broadcast packet
+ */
+ if ((rule->fw_flg & IP_FW_F_COMMAND) == IP_FW_F_REJECT
+ && ip->ip_p != IPPROTO_ICMP
+ && !((*m)->m_flags & (M_BCAST|M_MCAST))
+ && !IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
+ switch (rule->fw_reject_code) {
+ case IP_FW_REJECT_RST:
+ {
+ struct tcphdr *const tcp =
+ (struct tcphdr *) ((u_long *)ip + ip->ip_hl);
+ struct tcpiphdr ti, *const tip = (struct tcpiphdr *) ip;
+
+ if (offset != 0 || (tcp->th_flags & TH_RST))
+ break;
+ ti.ti_i = *((struct ipovly *) ip);
+ ti.ti_t = *tcp;
+ bcopy(&ti, ip, sizeof(ti));
+ NTOHL(tip->ti_seq);
+ NTOHL(tip->ti_ack);
+ tip->ti_len = ip->ip_len - hlen - (tip->ti_off << 2);
+ if (tcp->th_flags & TH_ACK) {
+ tcp_respond(NULL, tip, *m,
+ (tcp_seq)0, ntohl(tcp->th_ack), TH_RST);
+ } else {
+ if (tcp->th_flags & TH_SYN)
+ tip->ti_len++;
+ tcp_respond(NULL, tip, *m, tip->ti_seq
+ + tip->ti_len, (tcp_seq)0, TH_RST|TH_ACK);
+ }
+ *m = NULL;
+ break;
+ }
+ default: /* Send an ICMP unreachable using code */
+ icmp_error(*m, ICMP_UNREACH,
+ rule->fw_reject_code, 0L, 0);
+ *m = NULL;
+ break;
+ }
+ }
+
+dropit:
+ /*
+ * Finally, drop the packet.
+ */
+ if (*m) {
+ m_freem(*m);
+ *m = NULL;
+ }
+ return(0);
+}
+
+static int
+add_entry(struct ip_fw_head *chainptr, struct ip_fw *frwl)
+{
+ struct ip_fw *ftmp = 0;
+ struct ip_fw_chain *fwc = 0, *fcp, *fcpl = 0;
+ u_short nbr = 0;
+ int s;
+
+ fwc = malloc(sizeof *fwc, M_IPFW, M_DONTWAIT);
+ ftmp = malloc(sizeof *ftmp, M_IPFW, M_DONTWAIT);
+ if (!fwc || !ftmp) {
+ dprintf(("%s malloc said no\n", err_prefix));
+ if (fwc) free(fwc, M_IPFW);
+ if (ftmp) free(ftmp, M_IPFW);
+ return (ENOSPC);
+ }
+
+ bcopy(frwl, ftmp, sizeof(struct ip_fw));
+ ftmp->fw_in_if.fu_via_if.name[FW_IFNLEN - 1] = '\0';
+ ftmp->fw_pcnt = 0L;
+ ftmp->fw_bcnt = 0L;
+ fwc->rule = ftmp;
+
+ s = splnet();
+
+ if (!chainptr->lh_first) {
+ LIST_INSERT_HEAD(chainptr, fwc, chain);
+ splx(s);
+ return(0);
+ } else if (ftmp->fw_number == (u_short)-1) {
+ if (fwc) free(fwc, M_IPFW);
+ if (ftmp) free(ftmp, M_IPFW);
+ splx(s);
+ dprintf(("%s bad rule number\n", err_prefix));
+ return (EINVAL);
+ }
+
+ /* If entry number is 0, find highest numbered rule and add 100 */
+ if (ftmp->fw_number == 0) {
+ for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) {
+ if (fcp->rule->fw_number != (u_short)-1)
+ nbr = fcp->rule->fw_number;
+ else
+ break;
+ }
+ if (nbr < (u_short)-1 - 100)
+ nbr += 100;
+ ftmp->fw_number = nbr;
+ }
+
+ /* Got a valid number; now insert it, keeping the list ordered */
+ for (fcp = chainptr->lh_first; fcp; fcp = fcp->chain.le_next) {
+ if (fcp->rule->fw_number > ftmp->fw_number) {
+ if (fcpl) {
+ LIST_INSERT_AFTER(fcpl, fwc, chain);
+ } else {
+ LIST_INSERT_HEAD(chainptr, fwc, chain);
+ }
+ break;
+ } else {
+ fcpl = fcp;
+ }
+ }
+
+ splx(s);
+ return (0);
+}
+
+static int
+del_entry(struct ip_fw_head *chainptr, u_short number)
+{
+ struct ip_fw_chain *fcp;
+ int s;
+
+ s = splnet();
+
+ fcp = chainptr->lh_first;
+ if (number != (u_short)-1) {
+ for (; fcp; fcp = fcp->chain.le_next) {
+ if (fcp->rule->fw_number == number) {
+ LIST_REMOVE(fcp, chain);
+ splx(s);
+ free(fcp->rule, M_IPFW);
+ free(fcp, M_IPFW);
+ return 0;
+ }
+ }
+ }
+
+ splx(s);
+ return (EINVAL);
+}
+
+static int
+zero_entry(struct mbuf *m)
+{
+ struct ip_fw *frwl;
+ struct ip_fw_chain *fcp;
+ int s;
+
+ if (m) {
+ if (m->m_len != sizeof(struct ip_fw))
+ return(EINVAL);
+ frwl = mtod(m, struct ip_fw *);
+ }
+ else
+ frwl = NULL;
+
+ /*
+ * It's possible to insert multiple chain entries with the
+ * same number, so we don't stop after finding the first
+ * match if zeroing a specific entry.
+ */
+ s = splnet();
+ for (fcp = ip_fw_chain.lh_first; fcp; fcp = fcp->chain.le_next)
+ if (!frwl || frwl->fw_number == fcp->rule->fw_number) {
+ fcp->rule->fw_bcnt = fcp->rule->fw_pcnt = 0;
+ fcp->rule->timestamp = 0;
+ }
+ splx(s);
+
+ if (fw_verbose) {
+ if (frwl)
+ printf("ipfw: Entry %d cleared.\n", frwl->fw_number);
+ else
+ printf("ipfw: Accounting cleared.\n");
+ }
+
+ return(0);
+}
+
+static struct ip_fw *
+check_ipfw_mbuf(struct mbuf *m)
+{
+ /* Check length */
+ if (m->m_len != sizeof(struct ip_fw)) {
+ dprintf(("%s len=%d, want %d\n", err_prefix, m->m_len,
+ (int)sizeof(struct ip_fw)));
+ return (NULL);
+ }
+ return(check_ipfw_struct(mtod(m, struct ip_fw *)));
+}
+
+static struct ip_fw *
+check_ipfw_struct(struct ip_fw *frwl)
+{
+ /* Check for invalid flag bits */
+ if ((frwl->fw_flg & ~IP_FW_F_MASK) != 0) {
+ dprintf(("%s undefined flag bits set (flags=%x)\n",
+ err_prefix, frwl->fw_flg));
+ return (NULL);
+ }
+ /* Must apply to incoming or outgoing (or both) */
+ if (!(frwl->fw_flg & (IP_FW_F_IN | IP_FW_F_OUT))) {
+ dprintf(("%s neither in nor out\n", err_prefix));
+ return (NULL);
+ }
+ /* Empty interface name is no good */
+ if (((frwl->fw_flg & IP_FW_F_IIFNAME)
+ && !*frwl->fw_in_if.fu_via_if.name)
+ || ((frwl->fw_flg & IP_FW_F_OIFNAME)
+ && !*frwl->fw_out_if.fu_via_if.name)) {
+ dprintf(("%s empty interface name\n", err_prefix));
+ return (NULL);
+ }
+ /* Sanity check interface matching */
+ if ((frwl->fw_flg & IF_FW_F_VIAHACK) == IF_FW_F_VIAHACK) {
+ ; /* allow "via" backwards compatibility */
+ } else if ((frwl->fw_flg & IP_FW_F_IN)
+ && (frwl->fw_flg & IP_FW_F_OIFACE)) {
+ dprintf(("%s outgoing interface check on incoming\n",
+ err_prefix));
+ return (NULL);
+ }
+ /* Sanity check port ranges */
+ if ((frwl->fw_flg & IP_FW_F_SRNG) && IP_FW_GETNSRCP(frwl) < 2) {
+ dprintf(("%s src range set but n_src_p=%d\n",
+ err_prefix, IP_FW_GETNSRCP(frwl)));
+ return (NULL);
+ }
+ if ((frwl->fw_flg & IP_FW_F_DRNG) && IP_FW_GETNDSTP(frwl) < 2) {
+ dprintf(("%s dst range set but n_dst_p=%d\n",
+ err_prefix, IP_FW_GETNDSTP(frwl)));
+ return (NULL);
+ }
+ if (IP_FW_GETNSRCP(frwl) + IP_FW_GETNDSTP(frwl) > IP_FW_MAX_PORTS) {
+ dprintf(("%s too many ports (%d+%d)\n",
+ err_prefix, IP_FW_GETNSRCP(frwl), IP_FW_GETNDSTP(frwl)));
+ return (NULL);
+ }
+ /*
+ * Protocols other than TCP/UDP don't use port range
+ */
+ if ((frwl->fw_prot != IPPROTO_TCP) &&
+ (frwl->fw_prot != IPPROTO_UDP) &&
+ (IP_FW_GETNSRCP(frwl) || IP_FW_GETNDSTP(frwl))) {
+ dprintf(("%s port(s) specified for non TCP/UDP rule\n",
+ err_prefix));
+ return(NULL);
+ }
+
+ /*
+ * Rather than modify the entry to make such entries work,
+ * we reject this rule and require user level utilities
+ * to enforce whatever policy they deem appropriate.
+ */
+ if ((frwl->fw_src.s_addr & (~frwl->fw_smsk.s_addr)) ||
+ (frwl->fw_dst.s_addr & (~frwl->fw_dmsk.s_addr))) {
+ dprintf(("%s rule never matches\n", err_prefix));
+ return(NULL);
+ }
+
+ if ((frwl->fw_flg & IP_FW_F_FRAG) &&
+ (frwl->fw_prot == IPPROTO_UDP || frwl->fw_prot == IPPROTO_TCP)) {
+ if (frwl->fw_nports) {
+ dprintf(("%s cannot mix 'frag' and ports\n", err_prefix));
+ return(NULL);
+ }
+ if (frwl->fw_prot == IPPROTO_TCP &&
+ frwl->fw_tcpf != frwl->fw_tcpnf) {
+ dprintf(("%s cannot mix 'frag' with TCP flags\n", err_prefix));
+ return(NULL);
+ }
+ }
+
+ /* Check command specific stuff */
+ switch (frwl->fw_flg & IP_FW_F_COMMAND)
+ {
+ case IP_FW_F_REJECT:
+ if (frwl->fw_reject_code >= 0x100
+ && !(frwl->fw_prot == IPPROTO_TCP
+ && frwl->fw_reject_code == IP_FW_REJECT_RST)) {
+ dprintf(("%s unknown reject code\n", err_prefix));
+ return(NULL);
+ }
+ break;
+ case IP_FW_F_DIVERT: /* Diverting to port zero is invalid */
+ case IP_FW_F_TEE:
+ if (frwl->fw_divert_port == 0) {
+ dprintf(("%s can't divert to port 0\n", err_prefix));
+ return (NULL);
+ }
+ break;
+ case IP_FW_F_DENY:
+ case IP_FW_F_ACCEPT:
+ case IP_FW_F_COUNT:
+ case IP_FW_F_SKIPTO:
+ break;
+ default:
+ dprintf(("%s invalid command\n", err_prefix));
+ return(NULL);
+ }
+
+ return frwl;
+}
+
+static int
+ip_fw_ctl(int stage, struct mbuf **mm)
+{
+ int error;
+ struct mbuf *m;
+
+ if (stage == IP_FW_GET) {
+ struct ip_fw_chain *fcp = ip_fw_chain.lh_first;
+ *mm = m = m_get(M_WAIT, MT_SOOPTS);
+ for (; fcp; fcp = fcp->chain.le_next) {
+ memcpy(m->m_data, fcp->rule, sizeof *(fcp->rule));
+ m->m_len = sizeof *(fcp->rule);
+ m->m_next = m_get(M_WAIT, MT_SOOPTS);
+ m = m->m_next;
+ m->m_len = 0;
+ }
+ return (0);
+ }
+ m = *mm;
+ /* only allow get calls if secure mode > 2 */
+ if (securelevel > 2) {
+ if (m) (void)m_free(m);
+ return(EPERM);
+ }
+ if (stage == IP_FW_FLUSH) {
+ while (ip_fw_chain.lh_first != NULL &&
+ ip_fw_chain.lh_first->rule->fw_number != (u_short)-1) {
+ struct ip_fw_chain *fcp = ip_fw_chain.lh_first;
+ int s = splnet();
+ LIST_REMOVE(ip_fw_chain.lh_first, chain);
+ splx(s);
+ free(fcp->rule, M_IPFW);
+ free(fcp, M_IPFW);
+ }
+ if (m) (void)m_free(m);
+ return (0);
+ }
+ if (stage == IP_FW_ZERO) {
+ error = zero_entry(m);
+ if (m) (void)m_free(m);
+ return (error);
+ }
+ if (m == NULL) {
+ printf("%s NULL mbuf ptr\n", err_prefix);
+ return (EINVAL);
+ }
+
+ if (stage == IP_FW_ADD) {
+ struct ip_fw *frwl = check_ipfw_mbuf(m);
+
+ if (!frwl)
+ error = EINVAL;
+ else
+ error = add_entry(&ip_fw_chain, frwl);
+ if (m) (void)m_free(m);
+ return error;
+ }
+ if (stage == IP_FW_DEL) {
+ if (m->m_len != sizeof(struct ip_fw)) {
+ dprintf(("%s len=%d, want %d\n", err_prefix, m->m_len,
+ (int)sizeof(struct ip_fw)));
+ error = EINVAL;
+ } else if (mtod(m, struct ip_fw *)->fw_number == (u_short)-1) {
+ dprintf(("%s can't delete rule 65535\n", err_prefix));
+ error = EINVAL;
+ } else
+ error = del_entry(&ip_fw_chain,
+ mtod(m, struct ip_fw *)->fw_number);
+ if (m) (void)m_free(m);
+ return error;
+ }
+
+ dprintf(("%s unknown request %d\n", err_prefix, stage));
+ if (m) (void)m_free(m);
+ return (EINVAL);
+}
+
+void
+ip_fw_init(void)
+{
+ struct ip_fw default_rule;
+
+ ip_fw_chk_ptr = ip_fw_chk;
+ ip_fw_ctl_ptr = ip_fw_ctl;
+ LIST_INIT(&ip_fw_chain);
+
+ bzero(&default_rule, sizeof default_rule);
+ default_rule.fw_prot = IPPROTO_IP;
+ default_rule.fw_number = (u_short)-1;
+#ifdef IPFIREWALL_DEFAULT_TO_ACCEPT
+ default_rule.fw_flg |= IP_FW_F_ACCEPT;
+#else
+ default_rule.fw_flg |= IP_FW_F_DENY;
+#endif
+ default_rule.fw_flg |= IP_FW_F_IN | IP_FW_F_OUT;
+ if (check_ipfw_struct(&default_rule) == NULL ||
+ add_entry(&ip_fw_chain, &default_rule))
+ panic(__FUNCTION__);
+
+ printf("IP packet filtering initialized, "
+#ifdef IPDIVERT
+ "divert enabled, ");
+#else
+ "divert disabled, ");
+#endif
+#ifdef IPFIREWALL_DEFAULT_TO_ACCEPT
+ printf("default to accept, ");
+#endif
+#ifndef IPFIREWALL_VERBOSE
+ printf("logging disabled\n");
+#else
+ if (fw_verbose_limit == 0)
+ printf("unlimited logging\n");
+ else
+ printf("logging limited to %d packets/entry\n",
+ fw_verbose_limit);
+#endif
+}
+
+#ifdef IPFIREWALL_MODULE
+
+#include <sys/exec.h>
+#include <sys/sysent.h>
+#include <sys/lkm.h>
+
+MOD_MISC(ipfw);
+
+static int
+ipfw_load(struct lkm_table *lkmtp, int cmd)
+{
+ int s=splnet();
+
+ old_chk_ptr = ip_fw_chk_ptr;
+ old_ctl_ptr = ip_fw_ctl_ptr;
+
+ ip_fw_init();
+ splx(s);
+ return 0;
+}
+
+static int
+ipfw_unload(struct lkm_table *lkmtp, int cmd)
+{
+ int s=splnet();
+
+ ip_fw_chk_ptr = old_chk_ptr;
+ ip_fw_ctl_ptr = old_ctl_ptr;
+
+ while (ip_fw_chain.lh_first != NULL) {
+ struct ip_fw_chain *fcp = ip_fw_chain.lh_first;
+ LIST_REMOVE(ip_fw_chain.lh_first, chain);
+ free(fcp->rule, M_IPFW);
+ free(fcp, M_IPFW);
+ }
+
+ splx(s);
+ printf("IP firewall unloaded\n");
+ return 0;
+}
+
+int
+ipfw_mod(struct lkm_table *lkmtp, int cmd, int ver)
+{
+ DISPATCH(lkmtp, cmd, ver, ipfw_load, ipfw_unload, lkm_nullcmd);
+}
+#endif
diff --git a/cpukit/libnetworking/netinet/ip_fw.h b/cpukit/libnetworking/netinet/ip_fw.h
new file mode 100644
index 0000000000..f90deb96c2
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_fw.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 1993 Daniel Boulet
+ * Copyright (c) 1994 Ugen J.S.Antsilevich
+ *
+ * Redistribution and use in source forms, with and without modification,
+ * are permitted provided that this entire comment appears intact.
+ *
+ * Redistribution in binary form may occur without any restrictions.
+ * Obviously, it would be nice if you gave credit where credit is due
+ * but requiring it would be too onerous.
+ *
+ * This software is provided ``AS IS'' without any warranties of any kind.
+ *
+ * $Id$
+ */
+
+#ifndef _IP_FW_H
+#define _IP_FW_H
+
+#include <net/if.h>
+
+/*
+ * This union structure identifies an interface, either explicitly
+ * by name or implicitly by IP address. The flags IP_FW_F_IIFNAME
+ * and IP_FW_F_OIFNAME say how to interpret this structure. An
+ * interface unit number of -1 matches any unit number, while an
+ * IP address of 0.0.0.0 indicates matches any interface.
+ *
+ * The receive and transmit interfaces are only compared against the
+ * the packet if the corresponding bit (IP_FW_F_IIFACE or IP_FW_F_OIFACE)
+ * is set. Note some packets lack a receive or transmit interface
+ * (in which case the missing "interface" never matches).
+ */
+
+union ip_fw_if {
+ struct in_addr fu_via_ip; /* Specified by IP address */
+ struct { /* Specified by interface name */
+#define FW_IFNLEN IFNAMSIZ
+ char name[FW_IFNLEN];
+ short unit; /* -1 means match any unit */
+ } fu_via_if;
+};
+
+/*
+ * Format of an IP firewall descriptor
+ *
+ * fw_src, fw_dst, fw_smsk, fw_dmsk are always stored in network byte order.
+ * fw_flg and fw_n*p are stored in host byte order (of course).
+ * Port numbers are stored in HOST byte order.
+ * Warning: setsockopt() will fail if sizeof(struct ip_fw) > MLEN (108)
+ */
+
+struct ip_fw {
+ u_long fw_pcnt,fw_bcnt; /* Packet and byte counters */
+ struct in_addr fw_src, fw_dst; /* Source and destination IP addr */
+ struct in_addr fw_smsk, fw_dmsk; /* Mask for src and dest IP addr */
+ u_short fw_number; /* Rule number */
+ u_short fw_flg; /* Flags word */
+#define IP_FW_MAX_PORTS 10 /* A reasonable maximum */
+ u_short fw_pts[IP_FW_MAX_PORTS]; /* Array of port numbers to match */
+ u_char fw_ipopt,fw_ipnopt; /* IP options set/unset */
+ u_char fw_tcpf,fw_tcpnf; /* TCP flags set/unset */
+#define IP_FW_ICMPTYPES_DIM (32 / (sizeof(unsigned) * 8))
+ unsigned fw_icmptypes[IP_FW_ICMPTYPES_DIM]; /* ICMP types bitmap */
+ long timestamp; /* timestamp (tv_sec) of last match */
+ union ip_fw_if fw_in_if, fw_out_if; /* Incoming and outgoing interfaces */
+ union {
+ u_short fu_divert_port; /* Divert/tee port (options IPDIVERT) */
+ u_short fu_skipto_rule; /* SKIPTO command rule number */
+ u_short fu_reject_code; /* REJECT response code */
+ } fw_un;
+ u_char fw_prot; /* IP protocol */
+ u_char fw_nports; /* N'of src ports and # of dst ports */
+ /* in ports array (dst ports follow */
+ /* src ports; max of 10 ports in all; */
+ /* count of 0 means match all ports) */
+};
+
+#define IP_FW_GETNSRCP(rule) ((rule)->fw_nports & 0x0f)
+#define IP_FW_SETNSRCP(rule, n) do { \
+ (rule)->fw_nports &= ~0x0f; \
+ (rule)->fw_nports |= (n); \
+ } while (0)
+#define IP_FW_GETNDSTP(rule) ((rule)->fw_nports >> 4)
+#define IP_FW_SETNDSTP(rule, n) do { \
+ (rule)->fw_nports &= ~0xf0; \
+ (rule)->fw_nports |= (n) << 4;\
+ } while (0)
+
+#define fw_divert_port fw_un.fu_divert_port
+#define fw_skipto_rule fw_un.fu_skipto_rule
+#define fw_reject_code fw_un.fu_reject_code
+
+struct ip_fw_chain {
+ LIST_ENTRY(ip_fw_chain) chain;
+ struct ip_fw *rule;
+};
+
+/*
+ * Values for "flags" field .
+ */
+#define IP_FW_F_IN 0x0001 /* Check inbound packets */
+#define IP_FW_F_OUT 0x0002 /* Check outbound packets */
+#define IP_FW_F_IIFACE 0x0004 /* Apply inbound interface test */
+#define IP_FW_F_OIFACE 0x0008 /* Apply outbound interface test */
+
+#define IP_FW_F_COMMAND 0x0070 /* Mask for type of chain entry: */
+#define IP_FW_F_DENY 0x0000 /* This is a deny rule */
+#define IP_FW_F_REJECT 0x0010 /* Deny and send a response packet */
+#define IP_FW_F_ACCEPT 0x0020 /* This is an accept rule */
+#define IP_FW_F_COUNT 0x0030 /* This is a count rule */
+#define IP_FW_F_DIVERT 0x0040 /* This is a divert rule */
+#define IP_FW_F_TEE 0x0050 /* This is a tee rule */
+#define IP_FW_F_SKIPTO 0x0060 /* This is a skipto rule */
+
+#define IP_FW_F_PRN 0x0080 /* Print if this rule matches */
+
+#define IP_FW_F_SRNG 0x0100 /* The first two src ports are a min *
+ * and max range (stored in host byte *
+ * order). */
+
+#define IP_FW_F_DRNG 0x0200 /* The first two dst ports are a min *
+ * and max range (stored in host byte *
+ * order). */
+
+#define IP_FW_F_IIFNAME 0x0400 /* In interface by name/unit (not IP) */
+#define IP_FW_F_OIFNAME 0x0800 /* Out interface by name/unit (not IP) */
+
+#define IP_FW_F_INVSRC 0x1000 /* Invert sense of src check */
+#define IP_FW_F_INVDST 0x2000 /* Invert sense of dst check */
+
+#define IP_FW_F_FRAG 0x4000 /* Fragment */
+
+#define IP_FW_F_ICMPBIT 0x8000 /* ICMP type bitmap is valid */
+
+#define IP_FW_F_MASK 0xFFFF /* All possible flag bits mask */
+
+/*
+ * For backwards compatibility with rules specifying "via iface" but
+ * not restricted to only "in" or "out" packets, we define this combination
+ * of bits to represent this configuration.
+ */
+
+#define IF_FW_F_VIAHACK (IP_FW_F_IN|IP_FW_F_OUT|IP_FW_F_IIFACE|IP_FW_F_OIFACE)
+
+/*
+ * Definitions for REJECT response codes.
+ * Values less than 256 correspond to ICMP unreachable codes.
+ */
+#define IP_FW_REJECT_RST 0x0100 /* TCP packets: send RST */
+
+/*
+ * Definitions for IP option names.
+ */
+#define IP_FW_IPOPT_LSRR 0x01
+#define IP_FW_IPOPT_SSRR 0x02
+#define IP_FW_IPOPT_RR 0x04
+#define IP_FW_IPOPT_TS 0x08
+
+/*
+ * Definitions for TCP flags.
+ */
+#define IP_FW_TCPF_FIN TH_FIN
+#define IP_FW_TCPF_SYN TH_SYN
+#define IP_FW_TCPF_RST TH_RST
+#define IP_FW_TCPF_PSH TH_PUSH
+#define IP_FW_TCPF_ACK TH_ACK
+#define IP_FW_TCPF_URG TH_URG
+#define IP_FW_TCPF_ESTAB 0x40
+
+/*
+ * Main firewall chains definitions and global var's definitions.
+ */
+#ifdef _KERNEL
+
+/*
+ * Function definitions.
+ */
+void ip_fw_init(void);
+
+#endif /* _KERNEL */
+
+#endif /* _IP_FW_H */
diff --git a/cpukit/libnetworking/netinet/ip_icmp.c b/cpukit/libnetworking/netinet/ip_icmp.c
new file mode 100644
index 0000000000..1bcd648f66
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_icmp.c
@@ -0,0 +1,771 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
+ * $FreeBSD: src/sys/netinet/ip_icmp.c,v 1.101 2005/05/04 13:23:54 andre Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/route.h>
+
+#define _IP_VHL
+#include <netinet/in.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#include <netinet/icmp_var.h>
+
+#ifdef IPSEC
+#include <netinet6/ipsec.h>
+#include <netkey/key.h>
+#endif
+
+#ifdef FAST_IPSEC
+#include <netipsec/ipsec.h>
+#include <netipsec/key.h>
+#define IPSEC
+#endif
+
+#include <machine/in_cksum.h>
+
+/*
+ * ICMP routines: error generation, receive packet processing, and
+ * routines to turnaround packets back to the originator, and
+ * host table maintenance routines.
+ */
+
+ struct icmpstat icmpstat;
+SYSCTL_STRUCT(_net_inet_icmp, ICMPCTL_STATS, stats, CTLFLAG_RD,
+ &icmpstat, icmpstat, "");
+
+static int icmpmaskrepl = 0;
+SYSCTL_INT(_net_inet_icmp, ICMPCTL_MASKREPL, maskrepl, CTLFLAG_RW,
+ &icmpmaskrepl, 0, "");
+
+static int icmpbmcastecho = 1;
+SYSCTL_INT(_net_inet_icmp, OID_AUTO, bmcastecho, CTLFLAG_RW, &icmpbmcastecho,
+ 0, "");
+
+static int icmpallecho = 1;
+SYSCTL_INT(_net_inet_icmp, OID_AUTO, allecho, CTLFLAG_RW, &icmpallecho,
+ 0, "");
+
+#ifdef ICMPPRINTFS
+int icmpprintfs = 0;
+#endif
+
+static void icmp_reflect(struct mbuf *);
+static void icmp_send(struct mbuf *, struct mbuf *);
+
+extern struct protosw inetsw[];
+unsigned int icmplenPanicAvoided;
+
+/*
+ * Generate an error packet of type error
+ * in response to bad packet ip.
+ */
+void
+icmp_error(struct mbuf *n, int type, int code, n_long dest,
+ struct ifnet *destifp)
+{
+ register struct ip *oip = mtod(n, struct ip *), *nip;
+#ifdef _IP_VHL
+ register unsigned oiplen = IP_VHL_HL(oip->ip_vhl) << 2;
+#else
+ register unsigned oiplen = oip->ip_hl << 2;
+#endif
+ register struct icmp *icp;
+ register struct mbuf *m;
+ unsigned icmplen;
+
+#ifdef ICMPPRINTFS
+ if (icmpprintfs)
+ printf("icmp_error(%p, %x, %d)\n", oip, type, code);
+#endif
+ if (type != ICMP_REDIRECT)
+ icmpstat.icps_error++;
+ /*
+ * Don't send error if not the first fragment of message.
+ * Don't error if the old packet protocol was ICMP
+ * error message, only known informational types.
+ */
+ if (oip->ip_off &~ (IP_MF|IP_DF))
+ goto freeit;
+ if (oip->ip_p == IPPROTO_ICMP && type != ICMP_REDIRECT &&
+ n->m_len >= oiplen + ICMP_MINLEN &&
+ !ICMP_INFOTYPE(((struct icmp *)((caddr_t)oip + oiplen))->icmp_type)) {
+ icmpstat.icps_oldicmp++;
+ goto freeit;
+ }
+ /* Don't send error in response to a multicast or broadcast packet */
+ if (n->m_flags & (M_BCAST|M_MCAST))
+ goto freeit;
+ /* Don't send error in response to malicious packet */
+ icmplen = min(oiplen + 8, oip->ip_len);
+ if (icmplen < sizeof(struct ip)) {
+ icmplenPanicAvoided++;
+ goto freeit;
+ }
+
+ /*
+ * First, formulate icmp message
+ */
+ m = m_gethdr(M_DONTWAIT, MT_HEADER);
+ if (m == NULL)
+ goto freeit;
+#ifdef MAC
+ mac_create_mbuf_netlayer(n, m);
+#endif
+ m->m_len = icmplen + ICMP_MINLEN;
+ MH_ALIGN(m, m->m_len);
+ icp = mtod(m, struct icmp *);
+ if ((u_int)type > ICMP_MAXTYPE)
+ panic("icmp_error");
+ icmpstat.icps_outhist[type]++;
+ icp->icmp_type = type;
+ if (type == ICMP_REDIRECT)
+ icp->icmp_gwaddr.s_addr = dest;
+ else {
+ icp->icmp_void = 0;
+ /*
+ * The following assignments assume an overlay with the
+ * zeroed icmp_void field.
+ */
+ if (type == ICMP_PARAMPROB) {
+ icp->icmp_pptr = code;
+ code = 0;
+ } else if (type == ICMP_UNREACH &&
+ code == ICMP_UNREACH_NEEDFRAG && destifp) {
+ icp->icmp_nextmtu = htons(destifp->if_mtu);
+ }
+ }
+
+ icp->icmp_code = code;
+ bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, icmplen);
+ nip = &icp->icmp_ip;
+ nip->ip_len = htons((u_short)(nip->ip_len + oiplen));
+
+ /*
+ * Now, copy old ip header (without options)
+ * in front of icmp message.
+ */
+ if (m->m_data - sizeof(struct ip) < m->m_pktdat)
+ panic("icmp len");
+ m->m_data -= sizeof(struct ip);
+ m->m_len += sizeof(struct ip);
+ m->m_pkthdr.len = m->m_len;
+ m->m_pkthdr.rcvif = n->m_pkthdr.rcvif;
+ nip = mtod(m, struct ip *);
+ bcopy((caddr_t)oip, (caddr_t)nip, sizeof(struct ip));
+ nip->ip_len = m->m_len;
+#ifdef _IP_VHL
+ nip->ip_vhl = IP_VHL_BORING;
+#else
+ nip->ip_v = IPVERSION;
+ nip->ip_hl = 5;
+#endif
+ nip->ip_p = IPPROTO_ICMP;
+ nip->ip_tos = 0;
+ icmp_reflect(m);
+
+freeit:
+ m_freem(n);
+}
+
+static struct sockaddr_in icmpsrc = { sizeof (struct sockaddr_in), AF_INET, 0, {0}, {0} };
+static struct sockaddr_in icmpdst = { sizeof (struct sockaddr_in), AF_INET, 0, {0}, {0} };
+static struct sockaddr_in icmpgw = { sizeof (struct sockaddr_in), AF_INET, 0, {0}, {0} };
+
+/*
+ * Process a received ICMP message.
+ */
+void
+icmp_input(struct mbuf *m, int off)
+{
+ struct icmp *icp;
+ struct in_ifaddr *ia;
+ struct ip *ip = mtod(m, struct ip *);
+ int hlen = off;
+ int icmplen = ip->ip_len;
+ int i, code;
+ void (*ctlfunc)(int, struct sockaddr *, void *);
+
+ /*
+ * Locate icmp structure in mbuf, and check
+ * that not corrupted and of at least minimum length.
+ */
+#ifdef ICMPPRINTFS
+ if (icmpprintfs) {
+ char buf[4 * sizeof "123"];
+ strcpy(buf, inet_ntoa(ip->ip_src));
+ printf("icmp_input from %s to %s, len %d\n",
+ buf, inet_ntoa(ip->ip_dst), icmplen);
+ }
+#endif
+ if (icmplen < ICMP_MINLEN) {
+ icmpstat.icps_tooshort++;
+ goto freeit;
+ }
+ i = hlen + min(icmplen, ICMP_ADVLENMIN);
+ if (m->m_len < i && (m = m_pullup(m, i)) == NULL) {
+ icmpstat.icps_tooshort++;
+ return;
+ }
+ ip = mtod(m, struct ip *);
+ m->m_len -= hlen;
+ m->m_data += hlen;
+ icp = mtod(m, struct icmp *);
+ if (in_cksum(m, icmplen)) {
+ icmpstat.icps_checksum++;
+ goto freeit;
+ }
+ m->m_len += hlen;
+ m->m_data -= hlen;
+
+#ifdef ICMPPRINTFS
+ if (icmpprintfs)
+ printf("icmp_input, type %d code %d\n", icp->icmp_type,
+ icp->icmp_code);
+#endif
+
+ /*
+ * Message type specific processing.
+ */
+ if (icp->icmp_type > ICMP_MAXTYPE)
+ goto raw;
+ icmpstat.icps_inhist[icp->icmp_type]++;
+ code = icp->icmp_code;
+ switch (icp->icmp_type) {
+
+ case ICMP_UNREACH:
+ switch (code) {
+ case ICMP_UNREACH_NET:
+ case ICMP_UNREACH_HOST:
+ case ICMP_UNREACH_PROTOCOL:
+ case ICMP_UNREACH_PORT:
+ case ICMP_UNREACH_SRCFAIL:
+ code = PRC_UNREACH_NET;
+ break;
+
+ case ICMP_UNREACH_NEEDFRAG:
+ code = PRC_MSGSIZE;
+ break;
+
+ case ICMP_UNREACH_NET_UNKNOWN:
+ case ICMP_UNREACH_NET_PROHIB:
+ case ICMP_UNREACH_TOSNET:
+ code = PRC_UNREACH_NET;
+ break;
+
+ case ICMP_UNREACH_HOST_UNKNOWN:
+ case ICMP_UNREACH_ISOLATED:
+ case ICMP_UNREACH_HOST_PROHIB:
+ case ICMP_UNREACH_TOSHOST:
+ code = PRC_UNREACH_HOST;
+ break;
+
+ case ICMP_UNREACH_FILTER_PROHIB:
+ case ICMP_UNREACH_HOST_PRECEDENCE:
+ case ICMP_UNREACH_PRECEDENCE_CUTOFF:
+ code = PRC_UNREACH_PORT;
+ break;
+
+ default:
+ goto badcode;
+ }
+ goto deliver;
+
+ case ICMP_TIMXCEED:
+ if (code > 1)
+ goto badcode;
+ code += PRC_TIMXCEED_INTRANS;
+ goto deliver;
+
+ case ICMP_PARAMPROB:
+ if (code > 1)
+ goto badcode;
+ code = PRC_PARAMPROB;
+ goto deliver;
+
+ case ICMP_SOURCEQUENCH:
+ if (code)
+ goto badcode;
+ code = PRC_QUENCH;
+ deliver:
+ /*
+ * Problem with datagram; advise higher level routines.
+ */
+ if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp) ||
+#ifdef _IP_VHL
+ IP_VHL_HL(icp->icmp_ip.ip_vhl) < (sizeof(struct ip) >> 2)) {
+#else
+ icp->icmp_ip.ip_hl < (sizeof(struct ip) >> 2)) {
+#endif
+ icmpstat.icps_badlen++;
+ goto freeit;
+ }
+ NTOHS(icp->icmp_ip.ip_len);
+ /* Discard ICMP's in response to multicast packets */
+ if (IN_MULTICAST(ntohl(icp->icmp_ip.ip_dst.s_addr)))
+ goto badcode;
+#ifdef ICMPPRINTFS
+ if (icmpprintfs)
+ printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
+#endif
+ icmpsrc.sin_addr = icp->icmp_ip.ip_dst;
+#if 1
+ /*
+ * MTU discovery:
+ * If we got a needfrag and there is a host route to the
+ * original destination, and the MTU is not locked, then
+ * set the MTU in the route to the suggested new value
+ * (if given) and then notify as usual. The ULPs will
+ * notice that the MTU has changed and adapt accordingly.
+ * If no new MTU was suggested, then we guess a new one
+ * less than the current value. If the new MTU is
+ * unreasonably small (arbitrarily set at 296), then
+ * we reset the MTU to the interface value and enable the
+ * lock bit, indicating that we are no longer doing MTU
+ * discovery.
+ */
+ if (code == PRC_MSGSIZE) {
+ struct rtentry *rt;
+ int mtu;
+
+ rt = rtalloc1((struct sockaddr *)&icmpsrc, 0,
+ RTF_CLONING | RTF_PRCLONING);
+ if (rt && (rt->rt_flags & RTF_HOST)
+ && !(rt->rt_rmx.rmx_locks & RTV_MTU)) {
+ mtu = ntohs(icp->icmp_nextmtu);
+ if (!mtu)
+ mtu = ip_next_mtu(rt->rt_rmx.rmx_mtu,
+ 1);
+#ifdef DEBUG_MTUDISC
+ printf("MTU for %s reduced to %d\n",
+ inet_ntoa(icmpsrc.sin_addr), mtu);
+#endif
+ if (mtu < 296) {
+ /* rt->rt_rmx.rmx_mtu =
+ rt->rt_ifp->if_mtu; */
+ rt->rt_rmx.rmx_locks |= RTV_MTU;
+ } else if (rt->rt_rmx.rmx_mtu > mtu) {
+ rt->rt_rmx.rmx_mtu = mtu;
+ }
+ }
+ if (rt)
+ RTFREE(rt);
+ }
+
+#endif
+ ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput;
+ if (ctlfunc)
+ (*ctlfunc)(code, (struct sockaddr *)&icmpsrc,
+ (void *)&icp->icmp_ip);
+ break;
+
+ badcode:
+ icmpstat.icps_badcode++;
+ break;
+
+ case ICMP_ECHO:
+ if (!icmpallecho) {
+ icmpstat.icps_allecho++;
+ break;
+ }
+ if (!icmpbmcastecho
+ && (m->m_flags & (M_MCAST | M_BCAST)) != 0
+ && IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
+ icmpstat.icps_bmcastecho++;
+ break;
+ }
+ icp->icmp_type = ICMP_ECHOREPLY;
+ goto reflect;
+
+ case ICMP_TSTAMP:
+ if (!icmpbmcastecho
+ && (m->m_flags & (M_MCAST | M_BCAST)) != 0
+ && IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
+ icmpstat.icps_bmcasttstamp++;
+ break;
+ }
+ if (icmplen < ICMP_TSLEN) {
+ icmpstat.icps_badlen++;
+ break;
+ }
+ icp->icmp_type = ICMP_TSTAMPREPLY;
+ icp->icmp_rtime = iptime();
+ icp->icmp_ttime = icp->icmp_rtime; /* bogus, do later! */
+ goto reflect;
+
+ case ICMP_MASKREQ:
+#define satosin(sa) ((struct sockaddr_in *)(sa))
+ if (icmpmaskrepl == 0)
+ break;
+ /*
+ * We are not able to respond with all ones broadcast
+ * unless we receive it over a point-to-point interface.
+ */
+ if (icmplen < ICMP_MASKLEN)
+ break;
+ switch (ip->ip_dst.s_addr) {
+
+ case INADDR_BROADCAST:
+ case INADDR_ANY:
+ icmpdst.sin_addr = ip->ip_src;
+ break;
+
+ default:
+ icmpdst.sin_addr = ip->ip_dst;
+ }
+ ia = (struct in_ifaddr *)ifaof_ifpforaddr(
+ (struct sockaddr *)&icmpdst, m->m_pkthdr.rcvif);
+ if (ia == NULL)
+ break;
+ if (ia->ia_ifp == NULL) {
+ break;
+ }
+ icp->icmp_type = ICMP_MASKREPLY;
+ icp->icmp_mask = ia->ia_sockmask.sin_addr.s_addr;
+ if (ip->ip_src.s_addr == 0) {
+ if (ia->ia_ifp->if_flags & IFF_BROADCAST)
+ ip->ip_src = satosin(&ia->ia_broadaddr)->sin_addr;
+ else if (ia->ia_ifp->if_flags & IFF_POINTOPOINT)
+ ip->ip_src = satosin(&ia->ia_dstaddr)->sin_addr;
+ }
+reflect:
+ ip->ip_len += hlen; /* since ip_input deducts this */
+ icmpstat.icps_reflect++;
+ icmpstat.icps_outhist[icp->icmp_type]++;
+ icmp_reflect(m);
+ return;
+
+ case ICMP_REDIRECT:
+ if (code > 3)
+ goto badcode;
+ if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp) ||
+#ifdef _IP_VHL
+ IP_VHL_HL(icp->icmp_ip.ip_vhl) < (sizeof(struct ip) >> 2)) {
+#else
+ icp->icmp_ip.ip_hl < (sizeof(struct ip) >> 2)) {
+#endif
+ icmpstat.icps_badlen++;
+ break;
+ }
+ /*
+ * Short circuit routing redirects to force
+ * immediate change in the kernel's routing
+ * tables. The message is also handed to anyone
+ * listening on a raw socket (e.g. the routing
+ * daemon for use in updating its tables).
+ */
+ icmpgw.sin_addr = ip->ip_src;
+ icmpdst.sin_addr = icp->icmp_gwaddr;
+#ifdef ICMPPRINTFS
+ if (icmpprintfs) {
+ char buf[4 * sizeof "123"];
+ strcpy(buf, inet_ntoa(icp->icmp_ip.ip_dst));
+
+ printf("redirect dst %s to %s\n",
+ buf, inet_ntoa(icp->icmp_gwaddr));
+ }
+#endif
+ icmpsrc.sin_addr = icp->icmp_ip.ip_dst;
+ rtredirect((struct sockaddr *)&icmpsrc,
+ (struct sockaddr *)&icmpdst,
+ (struct sockaddr *)0, RTF_GATEWAY | RTF_HOST,
+ (struct sockaddr *)&icmpgw, (struct rtentry **)0);
+ pfctlinput(PRC_REDIRECT_HOST, (struct sockaddr *)&icmpsrc);
+ break;
+
+ /*
+ * No kernel processing for the following;
+ * just fall through to send to raw listener.
+ */
+ case ICMP_ECHOREPLY:
+ case ICMP_ROUTERADVERT:
+ case ICMP_ROUTERSOLICIT:
+ case ICMP_TSTAMPREPLY:
+ case ICMP_IREQREPLY:
+ case ICMP_MASKREPLY:
+ default:
+ break;
+ }
+
+raw:
+ rip_input(m, hlen);
+ return;
+
+freeit:
+ m_freem(m);
+}
+
+/*
+ * Reflect the ip packet back to the source
+ */
+static void
+icmp_reflect(struct mbuf *m)
+{
+ struct ip *ip = mtod(m, struct ip *);
+ struct in_ifaddr *ia;
+ struct in_addr t;
+ struct mbuf *opts = 0;
+#ifdef _IP_VHL
+ int optlen = (IP_VHL_HL(ip->ip_vhl) << 2) - sizeof(struct ip);
+#else
+ int optlen = (ip->ip_hl << 2) - sizeof(struct ip);
+#endif
+ if (!in_canforward(ip->ip_src) &&
+ ((ntohl(ip->ip_src.s_addr) & IN_CLASSA_NET) !=
+ (IN_LOOPBACKNET << IN_CLASSA_NSHIFT))) {
+ m_freem(m); /* Bad return address */
+ goto done; /* Ip_output() will check for broadcast */
+ }
+ t = ip->ip_dst;
+ ip->ip_dst = ip->ip_src;
+ /*
+ * If the incoming packet was addressed directly to us,
+ * use dst as the src for the reply. Otherwise (broadcast
+ * or anonymous), use the address which corresponds
+ * to the incoming interface.
+ */
+ for (ia = in_ifaddr; ia; ia = ia->ia_next) {
+ if (t.s_addr == IA_SIN(ia)->sin_addr.s_addr)
+ break;
+ if (ia->ia_ifp && (ia->ia_ifp->if_flags & IFF_BROADCAST) &&
+ t.s_addr == satosin(&ia->ia_broadaddr)->sin_addr.s_addr)
+ break;
+ }
+ icmpdst.sin_addr = t;
+ if ((ia == (struct in_ifaddr *)0) && m->m_pkthdr.rcvif)
+ ia = (struct in_ifaddr *)ifaof_ifpforaddr(
+ (struct sockaddr *)&icmpdst, m->m_pkthdr.rcvif);
+ /*
+ * The following happens if the packet was not addressed to us,
+ * and was received on an interface with no IP address.
+ */
+ if (ia == (struct in_ifaddr *)0)
+ ia = in_ifaddr;
+ t = IA_SIN(ia)->sin_addr;
+ ip->ip_src = t;
+ ip->ip_ttl = MAXTTL;
+
+ if (optlen > 0) {
+ register u_char *cp;
+ int opt, cnt;
+ u_int len;
+
+ /*
+ * Retrieve any source routing from the incoming packet;
+ * add on any record-route or timestamp options.
+ */
+ cp = (u_char *) (ip + 1);
+ if ((opts = ip_srcroute()) == 0 &&
+ (opts = m_gethdr(M_DONTWAIT, MT_HEADER))) {
+ opts->m_len = sizeof(struct in_addr);
+ mtod(opts, struct in_addr *)->s_addr = 0;
+ }
+ if (opts) {
+#ifdef ICMPPRINTFS
+ if (icmpprintfs)
+ printf("icmp_reflect optlen %d rt %d => ",
+ optlen, opts->m_len);
+#endif
+ for (cnt = optlen; cnt > 0; cnt -= len, cp += len) {
+ opt = cp[IPOPT_OPTVAL];
+ if (opt == IPOPT_EOL)
+ break;
+ if (opt == IPOPT_NOP)
+ len = 1;
+ else {
+ if (cnt < IPOPT_OLEN + sizeof(*cp))
+ break;
+ len = cp[IPOPT_OLEN];
+ if (len < IPOPT_OLEN + sizeof(*cp) ||
+ len > cnt)
+ break;
+ }
+ /*
+ * Should check for overflow, but it "can't happen"
+ */
+ if (opt == IPOPT_RR || opt == IPOPT_TS ||
+ opt == IPOPT_SECURITY) {
+ bcopy((caddr_t)cp,
+ mtod(opts, caddr_t) + opts->m_len, len);
+ opts->m_len += len;
+ }
+ }
+ /* Terminate & pad, if necessary */
+ cnt = opts->m_len % 4;
+ if (cnt) {
+ for (; cnt < 4; cnt++) {
+ *(mtod(opts, caddr_t) + opts->m_len) =
+ IPOPT_EOL;
+ opts->m_len++;
+ }
+ }
+#ifdef ICMPPRINTFS
+ if (icmpprintfs)
+ printf("%d\n", opts->m_len);
+#endif
+ }
+ /*
+ * Now strip out original options by copying rest of first
+ * mbuf's data back, and adjust the IP length.
+ */
+ ip->ip_len -= optlen;
+#ifdef _IP_VHL
+ ip->ip_vhl = IP_VHL_BORING;
+#else
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = 5;
+#endif
+ m->m_len -= optlen;
+ if (m->m_flags & M_PKTHDR)
+ m->m_pkthdr.len -= optlen;
+ optlen += sizeof(struct ip);
+ bcopy((caddr_t)ip + optlen, (caddr_t)(ip + 1),
+ (unsigned)(m->m_len - sizeof(struct ip)));
+ }
+ m->m_flags &= ~(M_BCAST|M_MCAST);
+ icmp_send(m, opts);
+done:
+ if (opts)
+ (void)m_free(opts);
+}
+
+/*
+ * Send an icmp packet back to the ip level,
+ * after supplying a checksum.
+ */
+static void
+icmp_send(struct mbuf *m, struct mbuf *opts)
+{
+ register struct ip *ip = mtod(m, struct ip *);
+ register int hlen;
+ register struct icmp *icp;
+ struct route ro;
+
+#ifdef _IP_VHL
+ hlen = IP_VHL_HL(ip->ip_vhl) << 2;
+#else
+ hlen = ip->ip_hl << 2;
+#endif
+ m->m_data += hlen;
+ m->m_len -= hlen;
+ icp = mtod(m, struct icmp *);
+ icp->icmp_cksum = 0;
+ icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen);
+ m->m_data -= hlen;
+ m->m_len += hlen;
+#ifdef ICMPPRINTFS
+ if (icmpprintfs) {
+ char buf[4 * sizeof "123"];
+ strcpy(buf, inet_ntoa(ip->ip_dst));
+ printf("icmp_send dst %s src %s\n",
+ buf, inet_ntoa(ip->ip_src));
+ }
+#endif
+ bzero(&ro, sizeof ro);
+ (void) ip_output(m, opts, &ro, 0, NULL);
+ if (ro.ro_rt)
+ RTFREE(ro.ro_rt);
+}
+
+/*
+ * Return milliseconds since 00:00 GMT in network format.
+ */
+uint32_t
+iptime(void)
+{
+ struct timeval atv;
+ u_long t;
+
+ microtime(&atv);
+ t = (atv.tv_sec % (24L*60L*60L)) * 1000L + atv.tv_usec / 1000L;
+ return (htonl(t));
+}
+
+/*
+ * Return the next larger or smaller MTU plateau (table from RFC 1191)
+ * given current value MTU. If DIR is less than zero, a larger plateau
+ * is returned; otherwise, a smaller value is returned.
+ */
+int
+ip_next_mtu(int mtu, int dir)
+{
+ static int mtutab[] = {
+ 65535, 32000, 17914, 8166, 4352, 2002, 1492, 1280, 1006, 508,
+ 296, 68, 0
+ };
+ int i;
+
+ for (i = 0; i < (sizeof mtutab) / (sizeof mtutab[0]); i++) {
+ if (mtu >= mtutab[i])
+ break;
+ }
+
+ if (dir < 0) {
+ if (i == 0) {
+ return 0;
+ } else {
+ return mtutab[i - 1];
+ }
+ } else {
+ if (mtutab[i] == 0) {
+ return 0;
+ } else if(mtu > mtutab[i]) {
+ return mtutab[i];
+ } else {
+ return mtutab[i + 1];
+ }
+ }
+}
diff --git a/cpukit/libnetworking/netinet/ip_icmp.h b/cpukit/libnetworking/netinet/ip_icmp.h
new file mode 100644
index 0000000000..655e687b62
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_icmp.h
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/ip_icmp.h,v 1.26 2005/05/04 13:09:19 andre Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IP_ICMP_H_
+#define _NETINET_IP_ICMP_H_
+
+/*
+ * Interface Control Message Protocol Definitions.
+ * Per RFC 792, September 1981.
+ */
+
+/*
+ * Internal of an ICMP Router Advertisement
+ */
+struct icmp_ra_addr {
+ u_int32_t ira_addr;
+ u_int32_t ira_preference;
+};
+
+/*
+ * Structure of an icmp header.
+ */
+struct icmp {
+ u_char icmp_type; /* type of message, see below */
+ u_char icmp_code; /* type sub code */
+ u_short icmp_cksum; /* ones complement cksum of struct */
+ union {
+ u_char ih_pptr; /* ICMP_PARAMPROB */
+ struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
+ struct ih_idseq {
+ uint16_t icd_id; /* network format */
+ uint16_t icd_seq; /* network format */
+ } ih_idseq;
+ int ih_void;
+
+ /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
+ struct ih_pmtu {
+ uint16_t ipm_void; /* network format */
+ uint16_t ipm_nextmtu; /* network format */
+ } ih_pmtu;
+
+ struct ih_rtradv {
+ u_char irt_num_addrs;
+ u_char irt_wpa;
+ u_int16_t irt_lifetime;
+ } ih_rtradv;
+ } icmp_hun;
+#define icmp_pptr icmp_hun.ih_pptr
+#define icmp_gwaddr icmp_hun.ih_gwaddr
+#define icmp_id icmp_hun.ih_idseq.icd_id
+#define icmp_seq icmp_hun.ih_idseq.icd_seq
+#define icmp_void icmp_hun.ih_void
+#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
+#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
+#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
+#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
+#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
+ union {
+ struct id_ts { /* ICMP Timestamp */
+ /*
+ * The next 3 fields are in network format,
+ * milliseconds since 00:00 GMT
+ */
+ uint32_t its_otime; /* Originate */
+ uint32_t its_rtime; /* Receive */
+ uint32_t its_ttime; /* Transmit */
+ } id_ts;
+ struct id_ip {
+ struct ip idi_ip;
+ /* options and then 64 bits of data */
+ } id_ip;
+ struct icmp_ra_addr id_radv;
+ u_int32_t id_mask;
+ char id_data[1];
+ } icmp_dun;
+#define icmp_otime icmp_dun.id_ts.its_otime
+#define icmp_rtime icmp_dun.id_ts.its_rtime
+#define icmp_ttime icmp_dun.id_ts.its_ttime
+#define icmp_ip icmp_dun.id_ip.idi_ip
+#define icmp_radv icmp_dun.id_radv
+#define icmp_mask icmp_dun.id_mask
+#define icmp_data icmp_dun.id_data
+};
+
+/*
+ * Lower bounds on packet lengths for various types.
+ * For the error advice packets must first insure that the
+ * packet is large enough to contain the returned ip header.
+ * Only then can we do the check to see if 64 bits of packet
+ * data have been returned, since we need to check the returned
+ * ip header length.
+ */
+#define ICMP_MINLEN 8 /* abs minimum */
+#define ICMP_TSLEN (8 + 3 * sizeof (uint32_t)) /* timestamp */
+#define ICMP_MASKLEN 12 /* address mask */
+#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
+#ifndef _IP_VHL
+#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
+ /* N.B.: must separately check that ip_hl >= 5 */
+#else
+#define ICMP_ADVLEN(p) (8 + (IP_VHL_HL((p)->icmp_ip.ip_vhl) << 2) + 8)
+ /* N.B.: must separately check that header length >= 5 */
+#endif
+
+/*
+ * Definition of type and code field values.
+ */
+#define ICMP_ECHOREPLY 0 /* echo reply */
+#define ICMP_UNREACH 3 /* dest unreachable, codes: */
+#define ICMP_UNREACH_NET 0 /* bad net */
+#define ICMP_UNREACH_HOST 1 /* bad host */
+#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
+#define ICMP_UNREACH_PORT 3 /* bad port */
+#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
+#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
+#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */
+#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */
+#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */
+#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */
+#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */
+#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */
+#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */
+#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */
+#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */
+#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */
+#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
+#define ICMP_REDIRECT 5 /* shorter route, codes: */
+#define ICMP_REDIRECT_NET 0 /* for network */
+#define ICMP_REDIRECT_HOST 1 /* for host */
+#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
+#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
+#define ICMP_ALTHOSTADDR 6 /* alternate host address */
+#define ICMP_ECHO 8 /* echo service */
+#define ICMP_ROUTERADVERT 9 /* router advertisement */
+#define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */
+#define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */
+#define ICMP_ROUTERSOLICIT 10 /* router solicitation */
+#define ICMP_TIMXCEED 11 /* time exceeded, code: */
+#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
+#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
+#define ICMP_PARAMPROB 12 /* ip header bad */
+#define ICMP_PARAMPROB_ERRATPTR 0 /* error at param ptr */
+#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */
+#define ICMP_PARAMPROB_LENGTH 2 /* bad length */
+#define ICMP_TSTAMP 13 /* timestamp request */
+#define ICMP_TSTAMPREPLY 14 /* timestamp reply */
+#define ICMP_IREQ 15 /* information request */
+#define ICMP_IREQREPLY 16 /* information reply */
+#define ICMP_MASKREQ 17 /* address mask request */
+#define ICMP_MASKREPLY 18 /* address mask reply */
+#define ICMP_TRACEROUTE 30 /* traceroute */
+#define ICMP_DATACONVERR 31 /* data conversion error */
+#define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */
+#define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */
+#define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */
+#define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */
+#define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */
+#define ICMP_SKIP 39 /* SKIP */
+#define ICMP_PHOTURIS 40 /* Photuris */
+#define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */
+#define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */
+#define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */
+
+#define ICMP_MAXTYPE 40
+
+#define ICMP_INFOTYPE(type) \
+ ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
+ (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
+ (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
+ (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
+ (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
+
+#ifdef _KERNEL
+void icmp_error(struct mbuf *, int, int, n_long, struct ifnet *);
+void icmp_input(struct mbuf *, int);
+int ip_next_mtu(int, int);
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/netinet/ip_input.c b/cpukit/libnetworking/netinet/ip_input.c
new file mode 100644
index 0000000000..582067d1a6
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_input.c
@@ -0,0 +1,1506 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
+ * $Id$
+ * $ANA: ip_input.c,v 1.5 1996/09/18 14:34:59 wollman Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _IP_VHL
+
+#include "opt_ipfw.h"
+
+#include <stddef.h>
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/kernel.h>
+#include <sys/syslog.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/route.h>
+#include <net/netisr.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/ip_var.h>
+#include <netinet/ip_icmp.h>
+#include <machine/in_cksum.h>
+
+#include <sys/socketvar.h>
+
+#ifdef IPFIREWALL
+#include <netinet/ip_fw.h>
+#endif
+
+int rsvp_on = 0;
+static int ip_rsvp_on;
+struct socket *ip_rsvpd;
+
+int ipforwarding = 0;
+SYSCTL_INT(_net_inet_ip, IPCTL_FORWARDING, forwarding, CTLFLAG_RW,
+ &ipforwarding, 0, "Enable IP forwarding between interfaces");
+
+static int ipsendredirects = 1; /* XXX */
+SYSCTL_INT(_net_inet_ip, IPCTL_SENDREDIRECTS, redirect, CTLFLAG_RW,
+ &ipsendredirects, 0, "Enable sending IP redirects");
+
+int ip_defttl = IPDEFTTL;
+SYSCTL_INT(_net_inet_ip, IPCTL_DEFTTL, ttl, CTLFLAG_RW,
+ &ip_defttl, 0, "Maximum TTL on IP packets");
+
+static int ip_dosourceroute = 0;
+SYSCTL_INT(_net_inet_ip, IPCTL_SOURCEROUTE, sourceroute, CTLFLAG_RW,
+ &ip_dosourceroute, 0, "");
+
+static int ip_acceptsourceroute = 0;
+SYSCTL_INT(_net_inet_ip, IPCTL_ACCEPTSOURCEROUTE, accept_sourceroute,
+ CTLFLAG_RW, &ip_acceptsourceroute, 0, "");
+#ifdef DIAGNOSTIC
+static int ipprintfs = 0;
+#endif
+
+extern struct domain inetdomain;
+extern struct protosw inetsw[];
+u_char ip_protox[IPPROTO_MAX];
+static int ipqmaxlen = IFQ_MAXLEN;
+struct in_ifaddr *in_ifaddr; /* first inet address */
+struct ifqueue ipintrq;
+SYSCTL_INT(_net_inet_ip, IPCTL_INTRQMAXLEN, intr_queue_maxlen, CTLFLAG_RD,
+ &ipintrq.ifq_maxlen, 0, "");
+SYSCTL_INT(_net_inet_ip, IPCTL_INTRQDROPS, intr_queue_drops, CTLFLAG_RD,
+ &ipintrq.ifq_drops, 0,
+ "Number of packets dropped from the IP input queue");
+
+struct ipstat ipstat;
+
+/* Packet reassembly stuff */
+#define IPREASS_NHASH_LOG2 6
+#define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
+#define IPREASS_HMASK (IPREASS_NHASH - 1)
+#define IPREASS_HASH(x,y) \
+ (((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
+
+static struct ipq ipq[IPREASS_NHASH];
+static int nipq = 0; /* total # of reass queues */
+static int maxnipq;
+
+#ifdef IPCTL_DEFMTU
+SYSCTL_INT(_net_inet_ip, IPCTL_DEFMTU, mtu, CTLFLAG_RW,
+ &ip_mtu, 0, "Default MTU");
+#endif
+
+#if !defined(COMPAT_IPFW) || COMPAT_IPFW == 1
+#undef COMPAT_IPFW
+#define COMPAT_IPFW 1
+#else
+#undef COMPAT_IPFW
+#endif
+
+#ifdef COMPAT_IPFW
+/* Firewall hooks */
+ip_fw_chk_t *ip_fw_chk_ptr;
+ip_fw_ctl_t *ip_fw_ctl_ptr;
+
+/* IP Network Address Translation (NAT) hooks */
+ip_nat_t *ip_nat_ptr;
+ip_nat_ctl_t *ip_nat_ctl_ptr;
+#endif
+
+/*
+ * We need to save the IP options in case a protocol wants to respond
+ * to an incoming packet over the same route if the packet got here
+ * using IP source routing. This allows connection establishment and
+ * maintenance when the remote end is on a network that is not known
+ * to us.
+ */
+static int ip_nhops = 0;
+static struct ip_srcrt {
+ struct in_addr dst; /* final destination */
+ char nop; /* one NOP to align */
+ char srcopt[IPOPT_OFFSET + 1]; /* OPTVAL, OLEN and OFFSET */
+ struct in_addr route[MAX_IPOPTLEN/sizeof(struct in_addr)];
+} ip_srcrt;
+
+#ifdef IPDIVERT
+/*
+ * Shared variable between ip_input() and ip_reass() to communicate
+ * about which packets, once assembled from fragments, get diverted,
+ * and to which port.
+ */
+static u_short frag_divert_port;
+#endif
+
+static void save_rte(u_char *, struct in_addr);
+static void ip_deq(struct ipasfrag *);
+static int ip_dooptions(struct mbuf *);
+static void ip_enq(struct ipasfrag *, struct ipasfrag *);
+static void ip_forward(struct mbuf *, int);
+static void ip_freef(struct ipq *);
+static struct ip *
+ ip_reass(struct ipasfrag *, struct ipq *, struct ipq *);
+static struct in_ifaddr *
+ ip_rtaddr(struct in_addr);
+void ipintr(void);
+/*
+ * IP initialization: fill in IP protocol switch table.
+ * All protocols not implemented in kernel go to raw IP protocol handler.
+ */
+void
+ip_init(void)
+{
+ register struct protosw *pr;
+ register int i;
+
+ pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW);
+ if (pr == NULL)
+ panic("ip_init: PF_INET not found");
+
+ /* Initialize the entire ip_protox[] array to IPPROTO_RAW. */
+ for (i = 0; i < IPPROTO_MAX; i++)
+ ip_protox[i] = pr - inetsw;
+ /*
+ * Cycle through IP protocols and put them into the appropriate place
+ * in ip_protox[].
+ */
+ for (pr = inetdomain.dom_protosw;
+ pr < inetdomain.dom_protoswNPROTOSW; pr++)
+ if (pr->pr_domain->dom_family == PF_INET &&
+ pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) {
+ ip_protox[pr->pr_protocol] = pr - inetsw;
+ }
+
+ for (i = 0; i < IPREASS_NHASH; i++)
+ ipq[i].next = ipq[i].prev = &ipq[i];
+
+ maxnipq = nmbclusters/4;
+
+ /* Initialize various other remaining things. */
+ ip_id = rtems_bsdnet_seconds_since_boot() & 0xffff;
+ ipintrq.ifq_maxlen = ipqmaxlen;
+#ifdef IPFIREWALL
+ ip_fw_init();
+#endif
+#ifdef IPNAT
+ ip_nat_init();
+#endif
+
+}
+
+static struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET, 0, {0}, {0} };
+static struct route ipforward_rt;
+
+/*
+ * Ip input routine. Checksum and byte swap header. If fragmented
+ * try to reassemble. Process options. Pass to next level.
+ */
+void
+ip_input(struct mbuf *m)
+{
+ struct ip *ip = NULL;
+ struct ipq *fp;
+ struct in_ifaddr *ia = NULL;
+ int i, hlen;
+ u_short sum;
+
+#ifdef DIAGNOSTIC
+ if ((m->m_flags & M_PKTHDR) == 0)
+ panic("ip_input no HDR");
+#endif
+ /*
+ * If no IP addresses have been set yet but the interfaces
+ * are receiving, can't do anything with incoming packets yet.
+ */
+ if (in_ifaddr == NULL)
+ goto bad;
+ ipstat.ips_total++;
+
+ if (m->m_pkthdr.len < sizeof(struct ip))
+ goto tooshort;
+
+#if defined(DIAGNOSTIC) && defined(ORIGINAL_FREEBSD_CODE)
+ if (m->m_len < sizeof(struct ip))
+ panic("ipintr mbuf too short");
+#endif
+
+ if (m->m_len < sizeof (struct ip) &&
+ (m = m_pullup(m, sizeof (struct ip))) == NULL) {
+ ipstat.ips_toosmall++;
+ return;
+ }
+ ip = mtod(m, struct ip *);
+
+#ifdef _IP_VHL
+ if (IP_VHL_V(ip->ip_vhl) != IPVERSION) {
+#else
+ if (ip->ip_v != IPVERSION) {
+#endif
+ ipstat.ips_badvers++;
+ goto bad;
+ }
+
+#ifdef _IP_VHL
+ hlen = IP_VHL_HL(ip->ip_vhl) << 2;
+#else
+ hlen = ip->ip_hl << 2;
+#endif
+ if (hlen < sizeof(struct ip)) { /* minimum header length */
+ ipstat.ips_badhlen++;
+ goto bad;
+ }
+ if (hlen > m->m_len) {
+ if ((m = m_pullup(m, hlen)) == NULL) {
+ ipstat.ips_badhlen++;
+ return;
+ }
+ ip = mtod(m, struct ip *);
+ }
+ if (hlen == sizeof(struct ip)) {
+ sum = in_cksum_hdr(ip);
+ } else {
+ sum = in_cksum(m, hlen);
+ }
+ if (sum) {
+ ipstat.ips_badsum++;
+ goto bad;
+ }
+
+ /*
+ * Convert fields to host representation.
+ */
+ ip->ip_len = ntohs(ip->ip_len);
+ if (ip->ip_len < hlen) {
+ ipstat.ips_badlen++;
+ goto bad;
+ }
+ NTOHS(ip->ip_id);
+ ip->ip_off = ntohs(ip->ip_off);
+
+ /*
+ * Check that the amount of data in the buffers
+ * is as at least much as the IP header would have us expect.
+ * Trim mbufs if longer than we expect.
+ * Drop packet if shorter than we expect.
+ */
+ if (m->m_pkthdr.len < ip->ip_len) {
+tooshort:
+ ipstat.ips_tooshort++;
+ goto bad;
+ }
+ if (m->m_pkthdr.len > ip->ip_len) {
+ if (m->m_len == m->m_pkthdr.len) {
+ m->m_len = ip->ip_len;
+ m->m_pkthdr.len = ip->ip_len;
+ } else
+ m_adj(m, ip->ip_len - m->m_pkthdr.len);
+ }
+ /*
+ * IpHack's section.
+ * Right now when no processing on packet has done
+ * and it is still fresh out of network we do our black
+ * deals with it.
+ * - Firewall: deny/allow/divert
+ * - Xlate: translate packet's addr/port (NAT).
+ * - Wrap: fake packet's addr/port <unimpl.>
+ * - Encapsulate: put it in another IP and send out. <unimp.>
+ */
+
+#ifdef COMPAT_IPFW
+ if (ip_fw_chk_ptr) {
+#ifdef IPDIVERT
+ u_short port;
+
+ port = (*ip_fw_chk_ptr)(&ip, hlen, NULL, ip_divert_ignore, &m);
+ ip_divert_ignore = 0;
+ if (port) { /* Divert packet */
+ frag_divert_port = port;
+ goto ours;
+ }
+#else
+ /* If ipfw says divert, we have to just drop packet */
+ if ((*ip_fw_chk_ptr)(&ip, hlen, NULL, 0, &m)) {
+ m_freem(m);
+ m = NULL;
+ }
+#endif
+ if (!m)
+ return;
+ }
+
+ if (ip_nat_ptr && !(*ip_nat_ptr)(&ip, &m, m->m_pkthdr.rcvif, IP_NAT_IN))
+ return;
+#endif
+
+ /*
+ * Process options and, if not destined for us,
+ * ship it on. ip_dooptions returns 1 when an
+ * error was detected (causing an icmp message
+ * to be sent and the original packet to be freed).
+ */
+ ip_nhops = 0; /* for source routed packets */
+ if (hlen > sizeof (struct ip) && ip_dooptions(m))
+ return;
+
+ /* greedy RSVP, snatches any PATH packet of the RSVP protocol and no
+ * matter if it is destined to another node, or whether it is
+ * a multicast one, RSVP wants it! and prevents it from being forwarded
+ * anywhere else. Also checks if the rsvp daemon is running before
+ * grabbing the packet.
+ */
+ if (rsvp_on && ip->ip_p==IPPROTO_RSVP)
+ goto ours;
+
+ /*
+ * Check our list of addresses, to see if the packet is for us.
+ */
+ for (ia = in_ifaddr; ia; ia = ia->ia_next) {
+#define satosin(sa) ((struct sockaddr_in *)(sa))
+
+ if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr)
+ goto ours;
+#ifdef BOOTP_COMPAT
+ if (IA_SIN(ia)->sin_addr.s_addr == INADDR_ANY)
+ goto ours;
+#endif
+ if (ia->ia_ifp && ia->ia_ifp->if_flags & IFF_BROADCAST) {
+ if (satosin(&ia->ia_broadaddr)->sin_addr.s_addr ==
+ ip->ip_dst.s_addr)
+ goto ours;
+ if (ip->ip_dst.s_addr == ia->ia_netbroadcast.s_addr)
+ goto ours;
+ }
+ }
+ if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
+ struct in_multi *inm;
+ if (ip_mrouter) {
+ /*
+ * If we are acting as a multicast router, all
+ * incoming multicast packets are passed to the
+ * kernel-level multicast forwarding function.
+ * The packet is returned (relatively) intact; if
+ * ip_mforward() returns a non-zero value, the packet
+ * must be discarded, else it may be accepted below.
+ *
+ * (The IP ident field is put in the same byte order
+ * as expected when ip_mforward() is called from
+ * ip_output().)
+ */
+ ip->ip_id = htons(ip->ip_id);
+ if (ip_mforward(ip, m->m_pkthdr.rcvif, m, 0) != 0) {
+ ipstat.ips_cantforward++;
+ m_freem(m);
+ return;
+ }
+ ip->ip_id = ntohs(ip->ip_id);
+
+ /*
+ * The process-level routing daemon needs to receive
+ * all multicast IGMP packets, whether or not this
+ * host belongs to their destination groups.
+ */
+ if (ip->ip_p == IPPROTO_IGMP)
+ goto ours;
+ ipstat.ips_forward++;
+ }
+ /*
+ * See if we belong to the destination multicast group on the
+ * arrival interface.
+ */
+ IN_LOOKUP_MULTI(ip->ip_dst, m->m_pkthdr.rcvif, inm);
+ if (inm == NULL) {
+ ipstat.ips_cantforward++;
+ m_freem(m);
+ return;
+ }
+ goto ours;
+ }
+ if (ip->ip_dst.s_addr == (u_long)INADDR_BROADCAST)
+ goto ours;
+ if (ip->ip_dst.s_addr == INADDR_ANY)
+ goto ours;
+
+ /*
+ * Not for us; forward if possible and desirable.
+ */
+ if (ipforwarding == 0) {
+ ipstat.ips_cantforward++;
+ m_freem(m);
+ } else {
+ ip_forward(m, 0);
+ }
+ return;
+
+ours:
+
+ /*
+ * If offset or IP_MF are set, must reassemble.
+ * Otherwise, nothing need be done.
+ * (We could look in the reassembly queue to see
+ * if the packet was previously fragmented,
+ * but it's not worth the time; just let them time out.)
+ */
+ if (ip->ip_off &~ (IP_DF | IP_RF)) {
+ if (m->m_flags & M_EXT) { /* XXX */
+ if ((m = m_pullup(m, sizeof (struct ip))) == 0) {
+ ipstat.ips_toosmall++;
+#ifdef IPDIVERT
+ frag_divert_port = 0;
+#endif
+ return;
+ }
+ ip = mtod(m, struct ip *);
+ }
+ sum = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
+ /*
+ * Look for queue of fragments
+ * of this datagram.
+ */
+ for (fp = ipq[sum].next; fp != &ipq[sum]; fp = fp->next)
+ if (ip->ip_id == fp->ipq_id &&
+ ip->ip_src.s_addr == fp->ipq_src.s_addr &&
+ ip->ip_dst.s_addr == fp->ipq_dst.s_addr &&
+ ip->ip_p == fp->ipq_p)
+ goto found;
+
+ fp = 0;
+
+ /* check if there's a place for the new queue */
+ if (nipq > maxnipq) {
+ /*
+ * drop something from the tail of the current queue
+ * before proceeding further
+ */
+ if (ipq[sum].prev == &ipq[sum]) { /* gak */
+ for (i = 0; i < IPREASS_NHASH; i++) {
+ if (ipq[i].prev != &ipq[i]) {
+ ip_freef(ipq[i].prev);
+ break;
+ }
+ }
+ } else
+ ip_freef(ipq[sum].prev);
+ }
+found:
+ /*
+ * Adjust ip_len to not reflect header,
+ * set ip_mff if more fragments are expected,
+ * convert offset of this to bytes.
+ */
+ ip->ip_len -= hlen;
+ ((struct ipasfrag *)ip)->ipf_mff &= ~1;
+ if (ip->ip_off & IP_MF)
+ ((struct ipasfrag *)ip)->ipf_mff |= 1;
+ ip->ip_off <<= 3;
+
+ /*
+ * If datagram marked as having more fragments
+ * or if this is not the first fragment,
+ * attempt reassembly; if it succeeds, proceed.
+ */
+ if (((struct ipasfrag *)ip)->ipf_mff & 1 || ip->ip_off) {
+ ipstat.ips_fragments++;
+ ip = ip_reass((struct ipasfrag *)ip, fp, &ipq[sum]);
+ if (ip == 0)
+ return;
+ ipstat.ips_reassembled++;
+ m = dtom(ip);
+#ifdef IPDIVERT
+ if (frag_divert_port) {
+ ip->ip_len += hlen;
+ HTONS(ip->ip_len);
+ HTONS(ip->ip_off);
+ HTONS(ip->ip_id);
+ ip->ip_sum = 0;
+ ip->ip_sum = in_cksum_hdr(ip);
+ NTOHS(ip->ip_id);
+ NTOHS(ip->ip_off);
+ NTOHS(ip->ip_len);
+ ip->ip_len -= hlen;
+ }
+#endif
+ } else
+ if (fp)
+ ip_freef(fp);
+ } else
+ ip->ip_len -= hlen;
+
+#ifdef IPDIVERT
+ /*
+ * Divert reassembled packets to the divert protocol if required
+ */
+ if (frag_divert_port) {
+ ipstat.ips_delivered++;
+ ip_divert_port = frag_divert_port;
+ frag_divert_port = 0;
+ (*inetsw[ip_protox[IPPROTO_DIVERT]].pr_input)(m, hlen);
+ return;
+ }
+
+ /* Don't let packets divert themselves */
+ if (ip->ip_p == IPPROTO_DIVERT) {
+ ipstat.ips_noproto++;
+ goto bad;
+ }
+#endif
+
+ /*
+ * Switch out to protocol's input routine.
+ */
+ ipstat.ips_delivered++;
+
+ (*inetsw[ip_protox[ip->ip_p]].pr_input)(m, hlen);
+ return;
+bad:
+ m_freem(m);
+}
+
+/*
+ * IP software interrupt routine - to go away sometime soon
+ */
+void
+ipintr(void)
+{
+ int s;
+ struct mbuf *m;
+
+ while(1) {
+ s = splimp();
+ IF_DEQUEUE(&ipintrq, m);
+ splx(s);
+ if (m == 0)
+ return;
+ ip_input(m);
+ }
+}
+
+NETISR_SET(NETISR_IP, ipintr);
+
+/*
+ * Take incoming datagram fragment and try to
+ * reassemble it into whole datagram. If a chain for
+ * reassembly of this datagram already exists, then it
+ * is given as fp; otherwise have to make a chain.
+ */
+static struct ip *
+ip_reass(struct ipasfrag *ip, struct ipq *fp, struct ipq *where)
+{
+ register struct mbuf *m = dtom(ip);
+ register struct ipasfrag *q;
+ struct mbuf *t;
+ int hlen = ip->ip_hl << 2;
+ int i;
+ int32_t next;
+
+ /*
+ * Presence of header sizes in mbufs
+ * would confuse code below.
+ */
+ m->m_data += hlen;
+ m->m_len -= hlen;
+
+ /*
+ * If first fragment to arrive, create a reassembly queue.
+ */
+ if (fp == NULL) {
+ if ((t = m_get(M_DONTWAIT, MT_FTABLE)) == NULL)
+ goto dropfrag;
+ fp = mtod(t, struct ipq *);
+ insque(fp, where);
+ nipq++;
+ fp->ipq_ttl = IPFRAGTTL;
+ fp->ipq_p = ip->ip_p;
+ fp->ipq_id = ip->ip_id;
+ fp->ipq_next = fp->ipq_prev = (struct ipasfrag *)fp;
+ fp->ipq_src = ((struct ip *)ip)->ip_src;
+ fp->ipq_dst = ((struct ip *)ip)->ip_dst;
+#ifdef IPDIVERT
+ fp->ipq_divert = 0;
+#endif
+ q = (struct ipasfrag *)fp;
+ goto insert;
+ }
+
+ /*
+ * Find a segment which begins after this one does.
+ */
+ for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next)
+ if (q->ip_off > ip->ip_off)
+ break;
+
+ /*
+ * If there is a preceding segment, it may provide some of
+ * our data already. If so, drop the data from the incoming
+ * segment. If it provides all of our data, drop us.
+ */
+ if (q->ipf_prev != (struct ipasfrag *)fp) {
+ i = q->ipf_prev->ip_off + q->ipf_prev->ip_len - ip->ip_off;
+ if (i > 0) {
+ if (i >= ip->ip_len)
+ goto dropfrag;
+ m_adj(dtom(ip), i);
+ ip->ip_off += i;
+ ip->ip_len -= i;
+ }
+ }
+
+ /*
+ * While we overlap succeeding segments trim them or,
+ * if they are completely covered, dequeue them.
+ */
+ while (q != (struct ipasfrag *)fp && ip->ip_off + ip->ip_len > q->ip_off) {
+ struct mbuf *m0;
+
+ i = (ip->ip_off + ip->ip_len) - q->ip_off;
+ if (i < q->ip_len) {
+ q->ip_len -= i;
+ q->ip_off += i;
+ m_adj(dtom(q), i);
+ break;
+ }
+ m0 = dtom(q);
+ q = q->ipf_next;
+ ip_deq(q->ipf_prev);
+ m_freem(m0);
+ }
+
+insert:
+
+#ifdef IPDIVERT
+ /*
+ * Any fragment diverting causes the whole packet to divert
+ */
+ if (frag_divert_port != 0)
+ fp->ipq_divert = frag_divert_port;
+ frag_divert_port = 0;
+#endif
+
+ /*
+ * Stick new segment in its place;
+ * check for complete reassembly.
+ */
+ ip_enq(ip, q->ipf_prev);
+ next = 0;
+ for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next) {
+ if (q->ip_off != next)
+ return (0);
+ next += q->ip_len;
+ }
+ if (q->ipf_prev->ipf_mff & 1)
+ return (0);
+
+ /*
+ * Reassembly is complete. Make sure the packet is a sane size.
+ */
+#ifdef _IP_VHL
+ if (next + (IP_VHL_HL(((struct ip *)fp->ipq_next)->ip_vhl) << 2)
+#else
+ if (next + ((((struct ip *)fp->ipq_next)->ip_hl) << 2)
+#endif
+ > IP_MAXPACKET) {
+ ipstat.ips_toolong++;
+ ip_freef(fp);
+ return (0);
+ }
+
+ /*
+ * Concatenate fragments.
+ */
+ q = fp->ipq_next;
+ m = dtom(q);
+ t = m->m_next;
+ m->m_next = NULL;
+ m_cat(m, t);
+ q = q->ipf_next;
+ while (q != (struct ipasfrag *)fp) {
+ t = dtom(q);
+ q = q->ipf_next;
+ m_cat(m, t);
+ }
+
+#ifdef IPDIVERT
+ /*
+ * Record divert port for packet, if any
+ */
+ frag_divert_port = fp->ipq_divert;
+#endif
+
+ /*
+ * Create header for new ip packet by modifying header of first
+ * packet; dequeue and discard fragment reassembly header.
+ * Make header visible.
+ */
+ ip = fp->ipq_next;
+ ip->ip_len = next;
+ ip->ipf_mff &= ~1;
+ ((struct ip *)ip)->ip_src = fp->ipq_src;
+ ((struct ip *)ip)->ip_dst = fp->ipq_dst;
+ remque(fp);
+ nipq--;
+ (void) m_free(dtom(fp));
+ m = dtom(ip);
+ m->m_len += (ip->ip_hl << 2);
+ m->m_data -= (ip->ip_hl << 2);
+ /* some debugging cruft by sklower, below, will go away soon */
+ if (m->m_flags & M_PKTHDR) { /* XXX this should be done elsewhere */
+ register int plen = 0;
+ for (t = m; m; m = m->m_next)
+ plen += m->m_len;
+ t->m_pkthdr.len = plen;
+ }
+ return ((struct ip *)ip);
+
+dropfrag:
+ ipstat.ips_fragdropped++;
+ m_freem(m);
+ return (0);
+}
+
+/*
+ * Free a fragment reassembly header and all
+ * associated datagrams.
+ */
+static void
+ip_freef(struct ipq *fp)
+{
+ register struct ipasfrag *q, *p;
+
+ for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = p) {
+ p = q->ipf_next;
+ ip_deq(q);
+ m_freem(dtom(q));
+ }
+ remque(fp);
+ (void) m_free(dtom(fp));
+ nipq--;
+}
+
+/*
+ * Put an ip fragment on a reassembly chain.
+ * Like insque, but pointers in middle of structure.
+ */
+static void
+ip_enq(struct ipasfrag *p, struct ipasfrag *prev)
+{
+
+ p->ipf_prev = prev;
+ p->ipf_next = prev->ipf_next;
+ prev->ipf_next->ipf_prev = p;
+ prev->ipf_next = p;
+}
+
+/*
+ * To ip_enq as remque is to insque.
+ */
+static void
+ip_deq(struct ipasfrag *p)
+{
+
+ p->ipf_prev->ipf_next = p->ipf_next;
+ p->ipf_next->ipf_prev = p->ipf_prev;
+}
+
+/*
+ * IP timer processing;
+ * if a timer expires on a reassembly
+ * queue, discard it.
+ */
+void
+ip_slowtimo(void)
+{
+ register struct ipq *fp;
+ int s = splnet();
+ int i;
+
+ for (i = 0; i < IPREASS_NHASH; i++) {
+ fp = ipq[i].next;
+ if (fp == 0)
+ continue;
+ while (fp != &ipq[i]) {
+ --fp->ipq_ttl;
+ fp = fp->next;
+ if (fp->prev->ipq_ttl == 0) {
+ ipstat.ips_fragtimeout++;
+ ip_freef(fp->prev);
+ }
+ }
+ }
+ splx(s);
+}
+
+/*
+ * Drain off all datagram fragments.
+ */
+void
+ip_drain(void)
+{
+ int i;
+
+ for (i = 0; i < IPREASS_NHASH; i++) {
+ while (ipq[i].next != &ipq[i]) {
+ ipstat.ips_fragdropped++;
+ ip_freef(ipq[i].next);
+ }
+ }
+ in_rtqdrain();
+}
+
+/*
+ * Do option processing on a datagram,
+ * possibly discarding it if bad options are encountered,
+ * or forwarding it if source-routed.
+ * Returns 1 if packet has been forwarded/freed,
+ * 0 if the packet should be processed further.
+ */
+static int
+ip_dooptions(struct mbuf *m)
+{
+ register struct ip *ip = mtod(m, struct ip *);
+ register u_char *cp;
+ register struct ip_timestamp *ipt;
+ register struct in_ifaddr *ia;
+ int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
+ struct in_addr *sin, dst;
+ n_time ntime;
+
+ dst = ip->ip_dst;
+ cp = (u_char *)(ip + 1);
+#ifdef _IP_VHL
+ cnt = (IP_VHL_HL(ip->ip_vhl) << 2) - sizeof (struct ip);
+#else
+ cnt = (ip->ip_hl << 2) - sizeof (struct ip);
+#endif
+ for (; cnt > 0; cnt -= optlen, cp += optlen) {
+ opt = cp[IPOPT_OPTVAL];
+ if (opt == IPOPT_EOL)
+ break;
+ if (opt == IPOPT_NOP)
+ optlen = 1;
+ else {
+ optlen = cp[IPOPT_OLEN];
+ if (optlen <= 0 || optlen > cnt) {
+ code = &cp[IPOPT_OLEN] - (u_char *)ip;
+ goto bad;
+ }
+ }
+ switch (opt) {
+
+ default:
+ break;
+
+ /*
+ * Source routing with record.
+ * Find interface with current destination address.
+ * If none on this machine then drop if strictly routed,
+ * or do nothing if loosely routed.
+ * Record interface address and bring up next address
+ * component. If strictly routed make sure next
+ * address is on directly accessible net.
+ */
+ case IPOPT_LSRR:
+ case IPOPT_SSRR:
+ if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
+ code = &cp[IPOPT_OFFSET] - (u_char *)ip;
+ goto bad;
+ }
+ ipaddr.sin_addr = ip->ip_dst;
+ ia = (struct in_ifaddr *)
+ ifa_ifwithaddr((struct sockaddr *)&ipaddr);
+ if (ia == 0) {
+ if (opt == IPOPT_SSRR) {
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_SRCFAIL;
+ goto bad;
+ }
+ if (!ip_dosourceroute)
+ goto nosourcerouting;
+ /*
+ * Loose routing, and not at next destination
+ * yet; nothing to do except forward.
+ */
+ break;
+ }
+ off--; /* 0 origin */
+ if (off > optlen - sizeof(struct in_addr)) {
+ /*
+ * End of source route. Should be for us.
+ */
+ if (!ip_acceptsourceroute)
+ goto nosourcerouting;
+ save_rte(cp, ip->ip_src);
+ break;
+ }
+
+ if (!ip_dosourceroute) {
+ char buf[4*sizeof "123"];
+
+nosourcerouting:
+ strcpy(buf, inet_ntoa(ip->ip_dst));
+ log(LOG_WARNING,
+ "attempted source route from %s to %s\n",
+ inet_ntoa(ip->ip_src), buf);
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_SRCFAIL;
+ goto bad;
+ }
+
+ /*
+ * locate outgoing interface
+ */
+ (void)memcpy(&ipaddr.sin_addr, cp + off,
+ sizeof(ipaddr.sin_addr));
+
+ if (opt == IPOPT_SSRR) {
+#define INA struct in_ifaddr *
+#define SA struct sockaddr *
+ if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0)
+ ia = (INA)ifa_ifwithnet((SA)&ipaddr);
+ } else
+ ia = ip_rtaddr(ipaddr.sin_addr);
+ if (ia == 0) {
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_SRCFAIL;
+ goto bad;
+ }
+ ip->ip_dst = ipaddr.sin_addr;
+ (void)memcpy(cp + off, &(IA_SIN(ia)->sin_addr),
+ sizeof(struct in_addr));
+ cp[IPOPT_OFFSET] += sizeof(struct in_addr);
+ /*
+ * Let ip_intr's mcast routing check handle mcast pkts
+ */
+ forward = !IN_MULTICAST(ntohl(ip->ip_dst.s_addr));
+ break;
+
+ case IPOPT_RR:
+ if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
+ code = &cp[IPOPT_OFFSET] - (u_char *)ip;
+ goto bad;
+ }
+ /*
+ * If no space remains, ignore.
+ */
+ off--; /* 0 origin */
+ if (off > optlen - sizeof(struct in_addr))
+ break;
+ (void)memcpy(&ipaddr.sin_addr, &ip->ip_dst,
+ sizeof(ipaddr.sin_addr));
+ /*
+ * locate outgoing interface; if we're the destination,
+ * use the incoming interface (should be same).
+ */
+ if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == 0 &&
+ (ia = ip_rtaddr(ipaddr.sin_addr)) == 0) {
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_HOST;
+ goto bad;
+ }
+ (void)memcpy(cp + off, &(IA_SIN(ia)->sin_addr),
+ sizeof(struct in_addr));
+ cp[IPOPT_OFFSET] += sizeof(struct in_addr);
+ break;
+
+ case IPOPT_TS:
+ code = cp - (u_char *)ip;
+ ipt = (struct ip_timestamp *)cp;
+ if (ipt->ipt_len < 5)
+ goto bad;
+ if (ipt->ipt_ptr > ipt->ipt_len - sizeof (long)) {
+ if (++ipt->ipt_oflw == 0)
+ goto bad;
+ break;
+ }
+ sin = (struct in_addr *)(cp + ipt->ipt_ptr - 1);
+ switch (ipt->ipt_flg) {
+
+ case IPOPT_TS_TSONLY:
+ break;
+
+ case IPOPT_TS_TSANDADDR:
+ if (ipt->ipt_ptr + sizeof(n_time) +
+ sizeof(struct in_addr) > ipt->ipt_len)
+ goto bad;
+ ipaddr.sin_addr = dst;
+ ia = (INA)ifaof_ifpforaddr((SA)&ipaddr,
+ m->m_pkthdr.rcvif);
+ if (ia == 0)
+ continue;
+ (void)memcpy(sin, &IA_SIN(ia)->sin_addr,
+ sizeof(struct in_addr));
+ ipt->ipt_ptr += sizeof(struct in_addr);
+ break;
+
+ case IPOPT_TS_PRESPEC:
+ if (ipt->ipt_ptr + sizeof(n_time) +
+ sizeof(struct in_addr) > ipt->ipt_len)
+ goto bad;
+ (void)memcpy(&ipaddr.sin_addr, sin,
+ sizeof(struct in_addr));
+ if (ifa_ifwithaddr((SA)&ipaddr) == 0)
+ continue;
+ ipt->ipt_ptr += sizeof(struct in_addr);
+ break;
+
+ default:
+ goto bad;
+ }
+ ntime = iptime();
+ (void)memcpy(cp + ipt->ipt_ptr - 1, &ntime,
+ sizeof(n_time));
+ ipt->ipt_ptr += sizeof(n_time);
+ }
+ }
+ if (forward && ipforwarding) {
+ ip_forward(m, 1);
+ return (1);
+ }
+ return (0);
+bad:
+#ifdef _IP_VHL
+ ip->ip_len -= IP_VHL_HL(ip->ip_vhl) << 2; /* XXX icmp_error adds in hdr length */
+#else
+ ip->ip_len -= ip->ip_hl << 2; /* XXX icmp_error adds in hdr length */
+#endif
+ icmp_error(m, type, code, 0, 0);
+ ipstat.ips_badoptions++;
+ return (1);
+}
+
+/*
+ * Given address of next destination (final or next hop),
+ * return internet address info of interface to be used to get there.
+ */
+static struct in_ifaddr *
+ip_rtaddr(struct in_addr dst)
+{
+ struct sockaddr_in *sin;
+
+ sin = (struct sockaddr_in *) &ipforward_rt.ro_dst;
+
+ if (ipforward_rt.ro_rt == 0 || dst.s_addr != sin->sin_addr.s_addr) {
+ if (ipforward_rt.ro_rt) {
+ RTFREE(ipforward_rt.ro_rt);
+ ipforward_rt.ro_rt = 0;
+ }
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_addr = dst;
+
+ rtalloc_ign(&ipforward_rt, RTF_PRCLONING);
+ }
+ if (ipforward_rt.ro_rt == 0)
+ return ((struct in_ifaddr *)0);
+ return ((struct in_ifaddr *) ipforward_rt.ro_rt->rt_ifa);
+}
+
+/*
+ * Save incoming source route for use in replies,
+ * to be picked up later by ip_srcroute if the receiver is interested.
+ */
+void
+save_rte(u_char *option, struct in_addr dst)
+{
+ unsigned olen;
+
+ olen = option[IPOPT_OLEN];
+#ifdef DIAGNOSTIC
+ if (ipprintfs)
+ printf("save_rte: olen %d\n", olen);
+#endif
+ if (olen > sizeof(ip_srcrt) - (1 + sizeof(dst)))
+ return;
+ bcopy(option, ip_srcrt.srcopt, olen);
+ ip_nhops = (olen - IPOPT_OFFSET - 1) / sizeof(struct in_addr);
+ ip_srcrt.dst = dst;
+}
+
+/*
+ * Retrieve incoming source route for use in replies,
+ * in the same form used by setsockopt.
+ * The first hop is placed before the options, will be removed later.
+ */
+struct mbuf *
+ip_srcroute(void)
+{
+ register struct in_addr *p, *q;
+ register struct mbuf *m;
+
+ if (ip_nhops == 0)
+ return ((struct mbuf *)0);
+ m = m_get(M_DONTWAIT, MT_SOOPTS);
+ if (m == 0)
+ return ((struct mbuf *)0);
+
+#define OPTSIZ (sizeof(ip_srcrt.nop) + sizeof(ip_srcrt.srcopt))
+
+ /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */
+ m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) +
+ OPTSIZ;
+#ifdef DIAGNOSTIC
+ if (ipprintfs)
+ printf("ip_srcroute: nhops %d mlen %d", ip_nhops, m->m_len);
+#endif
+
+ /*
+ * First save first hop for return route
+ */
+ p = &ip_srcrt.route[ip_nhops - 1];
+ *(mtod(m, struct in_addr *)) = *p--;
+#ifdef DIAGNOSTIC
+ if (ipprintfs)
+ printf(" hops %"PRIx32, ntohl(mtod(m, struct in_addr *)->s_addr));
+#endif
+
+ /*
+ * Copy option fields and padding (nop) to mbuf.
+ */
+ ip_srcrt.nop = IPOPT_NOP;
+ ip_srcrt.srcopt[IPOPT_OFFSET] = IPOPT_MINOFF;
+ (void)memcpy(mtod(m, caddr_t) + sizeof(struct in_addr),
+ &ip_srcrt.nop, OPTSIZ);
+ q = (struct in_addr *)(mtod(m, caddr_t) +
+ sizeof(struct in_addr) + OPTSIZ);
+#undef OPTSIZ
+ /*
+ * Record return path as an IP source route,
+ * reversing the path (pointers are now aligned).
+ */
+ while (p >= ip_srcrt.route) {
+#ifdef DIAGNOSTIC
+ if (ipprintfs)
+ printf(" %"PRIx32, ntohl(q->s_addr));
+#endif
+ *q++ = *p--;
+ }
+ /*
+ * Last hop goes to final destination.
+ */
+ *q = ip_srcrt.dst;
+#ifdef DIAGNOSTIC
+ if (ipprintfs)
+ printf(" %"PRIx32"\n", ntohl(q->s_addr));
+#endif
+ return (m);
+}
+
+/*
+ * Strip out IP options, at higher
+ * level protocol in the kernel.
+ * Second argument is buffer to which options
+ * will be moved, and return value is their length.
+ * XXX should be deleted; last arg currently ignored.
+ */
+void
+ip_stripoptions(struct mbuf *m, struct mbuf *mopt)
+{
+ register int i;
+ struct ip *ip = mtod(m, struct ip *);
+ register caddr_t opts;
+ int olen;
+
+#ifdef _IP_VHL
+ olen = (IP_VHL_HL(ip->ip_vhl) << 2) - sizeof (struct ip);
+#else
+ olen = (ip->ip_hl << 2) - sizeof (struct ip);
+#endif
+ opts = (caddr_t)(ip + 1);
+ i = m->m_len - (sizeof (struct ip) + olen);
+ bcopy(opts + olen, opts, (unsigned)i);
+ m->m_len -= olen;
+ if (m->m_flags & M_PKTHDR)
+ m->m_pkthdr.len -= olen;
+#ifdef _IP_VHL
+ ip->ip_vhl = IP_MAKE_VHL(IPVERSION, sizeof(struct ip) >> 2);
+#else
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = (sizeof(struct ip) >> 2);
+#endif
+}
+
+u_char inetctlerrmap[PRC_NCMDS] = {
+ 0, 0, 0, 0,
+ 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
+ EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
+ EMSGSIZE, EHOSTUNREACH, 0, 0,
+ 0, 0, 0, 0,
+ ENOPROTOOPT
+};
+
+/*
+ * Forward a packet. If some error occurs return the sender
+ * an icmp packet. Note we can't always generate a meaningful
+ * icmp message because icmp doesn't have a large enough repertoire
+ * of codes and types.
+ *
+ * If not forwarding, just drop the packet. This could be confusing
+ * if ipforwarding was zero but some routing protocol was advancing
+ * us as a gateway to somewhere. However, we must let the routing
+ * protocol deal with that.
+ *
+ * The srcrt parameter indicates whether the packet is being forwarded
+ * via a source route.
+ */
+static void
+ip_forward(struct mbuf *m, int srcrt)
+{
+ struct ip *ip = mtod(m, struct ip *);
+ register struct sockaddr_in *sin;
+ register struct rtentry *rt;
+ int error, type = 0, code = 0;
+ struct mbuf *mcopy;
+ n_long dest;
+ struct ifnet *destifp;
+
+ dest = 0;
+#ifdef DIAGNOSTIC
+ if (ipprintfs)
+ printf("forward: src %"PRIx32" dst %"PRIx32" ttl %x\n",
+ ip->ip_src.s_addr, ip->ip_dst.s_addr, ip->ip_ttl);
+#endif
+
+
+ if (m->m_flags & M_BCAST || in_canforward(ip->ip_dst) == 0) {
+ ipstat.ips_cantforward++;
+ m_freem(m);
+ return;
+ }
+ HTONS(ip->ip_id);
+ if (ip->ip_ttl <= IPTTLDEC) {
+ icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
+ return;
+ }
+ ip->ip_ttl -= IPTTLDEC;
+
+ sin = (struct sockaddr_in *)&ipforward_rt.ro_dst;
+ if ((rt = ipforward_rt.ro_rt) == 0 ||
+ ip->ip_dst.s_addr != sin->sin_addr.s_addr) {
+ if (ipforward_rt.ro_rt) {
+ RTFREE(ipforward_rt.ro_rt);
+ ipforward_rt.ro_rt = 0;
+ }
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_addr = ip->ip_dst;
+
+ rtalloc_ign(&ipforward_rt, RTF_PRCLONING);
+ if (ipforward_rt.ro_rt == 0) {
+ icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, dest, 0);
+ return;
+ }
+ rt = ipforward_rt.ro_rt;
+ }
+
+ /*
+ * Save at most 64 bytes of the packet in case
+ * we need to generate an ICMP message to the src.
+ */
+ mcopy = m_copy(m, 0, imin((int)ip->ip_len, 64));
+
+ /*
+ * If forwarding packet using same interface that it came in on,
+ * perhaps should send a redirect to sender to shortcut a hop.
+ * Only send redirect if source is sending directly to us,
+ * and if packet was not source routed (or has any options).
+ * Also, don't send redirect if forwarding using a default route
+ * or a route modified by a redirect.
+ */
+#define satosin(sa) ((struct sockaddr_in *)(sa))
+ if (rt->rt_ifp == m->m_pkthdr.rcvif &&
+ (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
+ satosin(rt_key(rt))->sin_addr.s_addr != 0 &&
+ ipsendredirects && !srcrt) {
+#define RTA(rt) ((struct in_ifaddr *)(rt->rt_ifa))
+ u_long src = ntohl(ip->ip_src.s_addr);
+
+ if (RTA(rt) &&
+ (src & RTA(rt)->ia_subnetmask) == RTA(rt)->ia_subnet) {
+ if (rt->rt_flags & RTF_GATEWAY)
+ dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
+ else
+ dest = ip->ip_dst.s_addr;
+ /* Router requirements says to only send host redirects */
+ type = ICMP_REDIRECT;
+ code = ICMP_REDIRECT_HOST;
+ }
+ }
+
+ error = ip_output(m, (struct mbuf *)0, &ipforward_rt,
+ IP_FORWARDING, 0);
+ if (error)
+ ipstat.ips_cantforward++;
+ else {
+ ipstat.ips_forward++;
+ if (type)
+ ipstat.ips_redirectsent++;
+ else {
+ if (mcopy)
+ m_freem(mcopy);
+ return;
+ }
+ }
+ if (mcopy == NULL)
+ return;
+ destifp = NULL;
+
+ switch (error) {
+
+ case 0: /* forwarded, but need redirect */
+ /* type, code set above */
+ break;
+
+ case ENETUNREACH: /* shouldn't happen, checked above */
+ case EHOSTUNREACH:
+ case ENETDOWN:
+ case EHOSTDOWN:
+ default:
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_HOST;
+ break;
+
+ case EMSGSIZE:
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_NEEDFRAG;
+ if (ipforward_rt.ro_rt)
+ destifp = ipforward_rt.ro_rt->rt_ifp;
+ ipstat.ips_cantfrag++;
+ break;
+
+ case ENOBUFS:
+ type = ICMP_SOURCEQUENCH;
+ code = 0;
+ break;
+ }
+ icmp_error(mcopy, type, code, dest, destifp);
+}
+
+void
+ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip,
+ struct mbuf *m)
+{
+ if (inp->inp_socket->so_options & SO_TIMESTAMP) {
+ struct timeval tv;
+
+ microtime(&tv);
+ *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
+ SCM_TIMESTAMP, SOL_SOCKET);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
+ if (inp->inp_flags & INP_RECVDSTADDR) {
+ *mp = sbcreatecontrol((caddr_t) &ip->ip_dst,
+ sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
+#ifdef notyet
+ /* XXX
+ * Moving these out of udp_input() made them even more broken
+ * than they already were.
+ */
+ /* options were tossed already */
+ if (inp->inp_flags & INP_RECVOPTS) {
+ *mp = sbcreatecontrol((caddr_t) opts_deleted_above,
+ sizeof(struct in_addr), IP_RECVOPTS, IPPROTO_IP);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
+ /* ip_srcroute doesn't do what we want here, need to fix */
+ if (inp->inp_flags & INP_RECVRETOPTS) {
+ *mp = sbcreatecontrol((caddr_t) ip_srcroute(m),
+ sizeof(struct in_addr), IP_RECVRETOPTS, IPPROTO_IP);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
+#endif
+ if (inp->inp_flags & INP_RECVIF) {
+ struct sockaddr_dl sdl;
+
+ sdl.sdl_len = offsetof(struct sockaddr_dl, sdl_data[0]);
+ sdl.sdl_family = AF_LINK;
+ sdl.sdl_index = m->m_pkthdr.rcvif ?
+ m->m_pkthdr.rcvif->if_index : 0;
+ sdl.sdl_nlen = sdl.sdl_alen = sdl.sdl_slen = 0;
+ *mp = sbcreatecontrol((caddr_t) &sdl, sdl.sdl_len,
+ IP_RECVIF, IPPROTO_IP);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
+}
+
+int
+ip_rsvp_init(struct socket *so)
+{
+ if (so->so_type != SOCK_RAW ||
+ so->so_proto->pr_protocol != IPPROTO_RSVP)
+ return EOPNOTSUPP;
+
+ if (ip_rsvpd != NULL)
+ return EADDRINUSE;
+
+ ip_rsvpd = so;
+ /*
+ * This may seem silly, but we need to be sure we don't over-increment
+ * the RSVP counter, in case something slips up.
+ */
+ if (!ip_rsvp_on) {
+ ip_rsvp_on = 1;
+ rsvp_on++;
+ }
+
+ return 0;
+}
+
+int
+ip_rsvp_done(void)
+{
+ ip_rsvpd = NULL;
+ /*
+ * This may seem silly, but we need to be sure we don't over-decrement
+ * the RSVP counter, in case something slips up.
+ */
+ if (ip_rsvp_on) {
+ ip_rsvp_on = 0;
+ rsvp_on--;
+ }
+ return 0;
+}
diff --git a/cpukit/libnetworking/netinet/ip_mroute.c b/cpukit/libnetworking/netinet/ip_mroute.c
new file mode 100644
index 0000000000..fe0bcc2a8c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_mroute.c
@@ -0,0 +1,2231 @@
+/*
+ * IP multicast forwarding procedures
+ *
+ * Written by David Waitzman, BBN Labs, August 1988.
+ * Modified by Steve Deering, Stanford, February 1989.
+ * Modified by Mark J. Steiglitz, Stanford, May, 1991
+ * Modified by Van Jacobson, LBL, January 1993
+ * Modified by Ajit Thyagarajan, PARC, August 1993
+ * Modified by Bill Fenner, PARC, April 1995
+ *
+ * MROUTING Revision: 3.5
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_mrouting.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/sysctl.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/kernel.h>
+#include <sys/ioctl.h>
+#include <sys/syslog.h>
+#include <net/if.h>
+#include <net/route.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/igmp.h>
+#include <netinet/igmp_var.h>
+#include <netinet/ip_mroute.h>
+#include <netinet/udp.h>
+
+#ifndef NTOHL
+#if BYTE_ORDER != BIG_ENDIAN
+#define NTOHL(d) ((d) = ntohl((d)))
+#define NTOHS(d) ((d) = ntohs((u_short)(d)))
+#define HTONL(d) ((d) = htonl((d)))
+#define HTONS(d) ((d) = htons((u_short)(d)))
+#else
+#define NTOHL(d)
+#define NTOHS(d)
+#define HTONL(d)
+#define HTONS(d)
+#endif
+#endif
+
+#ifndef MROUTING
+extern u_long _ip_mcast_src(int vifi);
+extern int _ip_mforward(struct ip *ip, struct ifnet *ifp,
+ struct mbuf *m, struct ip_moptions *imo);
+extern int _ip_mrouter_done(void);
+extern int _ip_mrouter_get(int cmd, struct socket *so,
+ struct mbuf **m);
+extern int _ip_mrouter_set(int cmd, struct socket *so,
+ struct mbuf *m);
+extern int _mrt_ioctl(int req, caddr_t data, struct proc *p);
+
+/*
+ * Dummy routines and globals used when multicast routing is not compiled in.
+ */
+
+struct socket *ip_mrouter = NULL;
+/* static u_int ip_mrtproto = 0; */
+/* static struct mrtstat mrtstat; */
+u_int rsvpdebug = 0;
+
+int
+_ip_mrouter_set(int cmd, struct socket *so, struct mbuf *m)
+{
+ return(EOPNOTSUPP);
+}
+
+int (*ip_mrouter_set)(int, struct socket *, struct mbuf *) = _ip_mrouter_set;
+
+
+int
+_ip_mrouter_get(int cmd, struct socket *so, struct mbuf **m)
+{
+ return(EOPNOTSUPP);
+}
+
+int (*ip_mrouter_get)(int, struct socket *, struct mbuf **) = _ip_mrouter_get;
+
+int
+_ip_mrouter_done(void)
+{
+ return(0);
+}
+
+int (*ip_mrouter_done)(void) = _ip_mrouter_done;
+
+int
+_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m,
+ struct ip_moptions *imo)
+{
+ return(0);
+}
+
+int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
+ struct ip_moptions *) = _ip_mforward;
+
+int
+_mrt_ioctl(int req, caddr_t data, struct proc *p)
+{
+ return EOPNOTSUPP;
+}
+
+int (*mrt_ioctl)(int, caddr_t, struct proc *) = _mrt_ioctl;
+
+void
+rsvp_input(struct mbuf *m, int iphlen)
+{
+ /* Can still get packets with rsvp_on = 0 if there is a local member
+ * of the group to which the RSVP packet is addressed. But in this
+ * case we want to throw the packet away.
+ */
+ if (!rsvp_on) {
+ m_freem(m);
+ return;
+ }
+
+ if (ip_rsvpd != NULL) {
+ if (rsvpdebug)
+ printf("rsvp_input: Sending packet up old-style socket\n");
+ rip_input(m, iphlen);
+ return;
+ }
+ /* Drop the packet */
+ m_freem(m);
+}
+
+void ipip_input(struct mbuf *m, int iphlen)
+{ /* XXX must fixup manually */
+ rip_input(m, iphlen);
+}
+
+int (*legal_vif_num)(int) = 0;
+
+/*
+ * This should never be called, since IP_MULTICAST_VIF should fail, but
+ * just in case it does get called, the code a little lower in ip_output
+ * will assign the packet a local address.
+ */
+u_long
+_ip_mcast_src(int vifi) { return INADDR_ANY; }
+u_long (*ip_mcast_src)(int) = _ip_mcast_src;
+
+int
+ip_rsvp_vif_init(struct socket *so, struct mbuf *m)
+{
+ return(EINVAL);
+}
+
+int
+ip_rsvp_vif_done(struct socket *so, struct mbuf *m)
+{
+ return(EINVAL);
+}
+
+void
+ip_rsvp_force_done(struct socket *so)
+{
+ return;
+}
+
+#else /* MROUTING */
+
+#define M_HASCL(m) ((m)->m_flags & M_EXT)
+
+#define INSIZ sizeof(struct in_addr)
+#define same(a1, a2) \
+ (bcmp((caddr_t)(a1), (caddr_t)(a2), INSIZ) == 0)
+
+#define MT_MRTABLE MT_RTABLE /* since nothing else uses it */
+
+/*
+ * Globals. All but ip_mrouter and ip_mrtproto could be static,
+ * except for netstat or debugging purposes.
+ */
+#ifndef MROUTE_LKM
+struct socket *ip_mrouter = NULL;
+struct mrtstat mrtstat;
+
+int ip_mrtproto = IGMP_DVMRP; /* for netstat only */
+#else /* MROUTE_LKM */
+extern void X_ipip_input(struct mbuf *m, int iphlen);
+extern struct mrtstat mrtstat;
+static int ip_mrtproto;
+#endif
+
+#define NO_RTE_FOUND 0x1
+#define RTE_FOUND 0x2
+
+static struct mbuf *mfctable[MFCTBLSIZ];
+static u_char nexpire[MFCTBLSIZ];
+static struct vif viftable[MAXVIFS];
+static u_int mrtdebug = 0; /* debug level */
+#define DEBUG_MFC 0x02
+#define DEBUG_FORWARD 0x04
+#define DEBUG_EXPIRE 0x08
+#define DEBUG_XMIT 0x10
+static u_int tbfdebug = 0; /* tbf debug level */
+static u_int rsvpdebug = 0; /* rsvp debug level */
+
+#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
+#define UPCALL_EXPIRE 6 /* number of timeouts */
+
+/*
+ * Define the token bucket filter structures
+ * tbftable -> each vif has one of these for storing info
+ */
+
+static struct tbf tbftable[MAXVIFS];
+#define TBF_REPROCESS (hz / 100) /* 100x / second */
+
+/*
+ * 'Interfaces' associated with decapsulator (so we can tell
+ * packets that went through it from ones that get reflected
+ * by a broken gateway). These interfaces are never linked into
+ * the system ifnet list & no routes point to them. I.e., packets
+ * can't be sent this way. They only exist as a placeholder for
+ * multicast source verification.
+ */
+static struct ifnet multicast_decap_if[MAXVIFS];
+
+#define ENCAP_TTL 64
+#define ENCAP_PROTO IPPROTO_IPIP /* 4 */
+
+/* prototype IP hdr for encapsulated packets */
+static struct ip multicast_encap_iphdr = {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ sizeof(struct ip) >> 2, IPVERSION,
+#else
+ IPVERSION, sizeof(struct ip) >> 2,
+#endif
+ 0, /* tos */
+ sizeof(struct ip), /* total length */
+ 0, /* id */
+ 0, /* frag offset */
+ ENCAP_TTL, ENCAP_PROTO,
+ 0, /* checksum */
+};
+
+/*
+ * Private variables.
+ */
+static vifi_t numvifs = 0;
+static int have_encap_tunnel = 0;
+
+/*
+ * one-back cache used by ipip_input to locate a tunnel's vif
+ * given a datagram's src ip address.
+ */
+static u_long last_encap_src;
+static struct vif *last_encap_vif;
+
+static u_long X_ip_mcast_src(int vifi);
+static int X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m, struct ip_moptions *imo);
+static int X_ip_mrouter_done(void);
+static int X_ip_mrouter_get(int cmd, struct socket *so, struct mbuf **m);
+static int X_ip_mrouter_set(int cmd, struct socket *so, struct mbuf *m);
+static int X_legal_vif_num(int vif);
+static int X_mrt_ioctl(int cmd, caddr_t data);
+
+static int get_sg_cnt(struct sioc_sg_req *);
+static int get_vif_cnt(struct sioc_vif_req *);
+static int ip_mrouter_init(struct socket *, struct mbuf *);
+static int add_vif(struct vifctl *);
+static int del_vif(vifi_t *);
+static int add_mfc(struct mfcctl *);
+static int del_mfc(struct mfcctl *);
+static int socket_send(struct socket *, struct mbuf *, struct sockaddr_in *);
+static int get_version(struct mbuf *);
+static int get_assert(struct mbuf *);
+static int set_assert(int *);
+static void expire_upcalls(void *);
+static int ip_mdq(struct mbuf *, struct ifnet *, struct mfc *,
+ vifi_t);
+static void phyint_send(struct ip *, struct vif *, struct mbuf *);
+static void encap_send(struct ip *, struct vif *, struct mbuf *);
+static void tbf_control(struct vif *, struct mbuf *, struct ip *, u_long);
+static void tbf_queue(struct vif *, struct mbuf *);
+static void tbf_process_q(struct vif *);
+static void tbf_reprocess_q(void *);
+static int tbf_dq_sel(struct vif *, struct ip *);
+static void tbf_send_packet(struct vif *, struct mbuf *);
+static void tbf_update_tokens(struct vif *);
+static int priority(struct vif *, struct ip *);
+void multiencap_decap(struct mbuf *);
+
+/*
+ * whether or not special PIM assert processing is enabled.
+ */
+static int pim_assert;
+/*
+ * Rate limit for assert notification messages, in usec
+ */
+#define ASSERT_MSG_TIME 3000000
+
+/*
+ * Hash function for a source, group entry
+ */
+#define MFCHASH(a, g) MFCHASHMOD(((a) >> 20) ^ ((a) >> 10) ^ (a) ^ \
+ ((g) >> 20) ^ ((g) >> 10) ^ (g))
+
+/*
+ * Find a route for a given origin IP address and Multicast group address
+ * Type of service parameter to be added in the future!!!
+ */
+
+#define MFCFIND(o, g, rt) { \
+ register struct mbuf *_mb_rt = mfctable[MFCHASH(o,g)]; \
+ register struct mfc *_rt = NULL; \
+ rt = NULL; \
+ ++mrtstat.mrts_mfc_lookups; \
+ while (_mb_rt) { \
+ _rt = mtod(_mb_rt, struct mfc *); \
+ if ((_rt->mfc_origin.s_addr == o) && \
+ (_rt->mfc_mcastgrp.s_addr == g) && \
+ (_mb_rt->m_act == NULL)) { \
+ rt = _rt; \
+ break; \
+ } \
+ _mb_rt = _mb_rt->m_next; \
+ } \
+ if (rt == NULL) { \
+ ++mrtstat.mrts_mfc_misses; \
+ } \
+}
+
+
+/*
+ * Macros to compute elapsed time efficiently
+ * Borrowed from Van Jacobson's scheduling code
+ */
+#define TV_DELTA(a, b, delta) { \
+ register int xxs; \
+ \
+ delta = (a).tv_usec - (b).tv_usec; \
+ if ((xxs = (a).tv_sec - (b).tv_sec)) { \
+ switch (xxs) { \
+ case 2: \
+ delta += 1000000; \
+ /* fall through */ \
+ case 1: \
+ delta += 1000000; \
+ break; \
+ default: \
+ delta += (1000000 * xxs); \
+ } \
+ } \
+}
+
+#define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
+ (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
+
+#ifdef UPCALL_TIMING
+u_long upcall_data[51];
+static void collate(struct timeval *);
+#endif /* UPCALL_TIMING */
+
+
+/*
+ * Handle MRT setsockopt commands to modify the multicast routing tables.
+ */
+static int
+X_ip_mrouter_set(int cmd, struct socket *so, struct mbuf *m)
+{
+ if (cmd != MRT_INIT && so != ip_mrouter) return EACCES;
+
+ switch (cmd) {
+ case MRT_INIT: return ip_mrouter_init(so, m);
+ case MRT_DONE: return ip_mrouter_done();
+ case MRT_ADD_VIF: return add_vif (mtod(m, struct vifctl *));
+ case MRT_DEL_VIF: return del_vif (mtod(m, vifi_t *));
+ case MRT_ADD_MFC: return add_mfc (mtod(m, struct mfcctl *));
+ case MRT_DEL_MFC: return del_mfc (mtod(m, struct mfcctl *));
+ case MRT_ASSERT: return set_assert(mtod(m, int *));
+ default: return EOPNOTSUPP;
+ }
+}
+
+#ifndef MROUTE_LKM
+int (*ip_mrouter_set)(int, struct socket *, struct mbuf *) = X_ip_mrouter_set;
+#endif
+
+/*
+ * Handle MRT getsockopt commands
+ */
+static int
+X_ip_mrouter_get(int cmd, struct socket *so, struct mbuf **m)
+{
+ struct mbuf *mb;
+
+ if (so != ip_mrouter) return EACCES;
+
+ *m = mb = m_get(M_WAIT, MT_SOOPTS);
+
+ switch (cmd) {
+ case MRT_VERSION: return get_version(mb);
+ case MRT_ASSERT: return get_assert(mb);
+ default: return EOPNOTSUPP;
+ }
+}
+
+#ifndef MROUTE_LKM
+int (*ip_mrouter_get)(int, struct socket *, struct mbuf **) = X_ip_mrouter_get;
+#endif
+
+/*
+ * Handle ioctl commands to obtain information from the cache
+ */
+static int
+X_mrt_ioctl(int cmd, caddr_t data)
+{
+ int error = 0;
+
+ switch (cmd) {
+ case (SIOCGETVIFCNT):
+ return (get_vif_cnt((struct sioc_vif_req *)data));
+ break;
+ case (SIOCGETSGCNT):
+ return (get_sg_cnt((struct sioc_sg_req *)data));
+ break;
+ default:
+ return (EINVAL);
+ break;
+ }
+ return error;
+}
+
+#ifndef MROUTE_LKM
+int (*mrt_ioctl)(int, caddr_t) = X_mrt_ioctl;
+#endif
+
+/*
+ * returns the packet, byte, rpf-failure count for the source group provided
+ */
+static int
+get_sg_cnt(struct sioc_sg_req *req)
+{
+ register struct mfc *rt;
+ int s;
+
+ s = splnet();
+ MFCFIND(req->src.s_addr, req->grp.s_addr, rt);
+ splx(s);
+ if (rt != NULL) {
+ req->pktcnt = rt->mfc_pkt_cnt;
+ req->bytecnt = rt->mfc_byte_cnt;
+ req->wrong_if = rt->mfc_wrong_if;
+ } else
+ req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
+
+ return 0;
+}
+
+/*
+ * returns the input and output packet and byte counts on the vif provided
+ */
+static int
+get_vif_cnt(struct sioc_vif_req *req)
+{
+ register vifi_t vifi = req->vifi;
+
+ if (vifi >= numvifs) return EINVAL;
+
+ req->icount = viftable[vifi].v_pkt_in;
+ req->ocount = viftable[vifi].v_pkt_out;
+ req->ibytes = viftable[vifi].v_bytes_in;
+ req->obytes = viftable[vifi].v_bytes_out;
+
+ return 0;
+}
+
+/*
+ * Enable multicast routing
+ */
+static int
+ip_mrouter_init(struct socket *so, struct mbuf *m)
+{
+ int *v;
+
+ if (mrtdebug)
+ log(LOG_DEBUG,"ip_mrouter_init: so_type = %d, pr_protocol = %d\n",
+ so->so_type, so->so_proto->pr_protocol);
+
+ if (so->so_type != SOCK_RAW ||
+ so->so_proto->pr_protocol != IPPROTO_IGMP) return EOPNOTSUPP;
+
+ if (!m || (m->m_len != sizeof(int *)))
+ return ENOPROTOOPT;
+
+ v = mtod(m, int *);
+ if (*v != 1)
+ return ENOPROTOOPT;
+
+ if (ip_mrouter != NULL) return EADDRINUSE;
+
+ ip_mrouter = so;
+
+ bzero((caddr_t)mfctable, sizeof(mfctable));
+ bzero((caddr_t)nexpire, sizeof(nexpire));
+
+ pim_assert = 0;
+
+ timeout(expire_upcalls, (caddr_t)NULL, EXPIRE_TIMEOUT);
+
+ if (mrtdebug)
+ log(LOG_DEBUG, "ip_mrouter_init\n");
+
+ return 0;
+}
+
+/*
+ * Disable multicast routing
+ */
+static int
+X_ip_mrouter_done(void)
+{
+ vifi_t vifi;
+ int i;
+ struct ifnet *ifp;
+ struct ifreq ifr;
+ struct mbuf *mb_rt;
+ struct mbuf *m;
+ struct rtdetq *rte;
+ int s;
+
+ s = splnet();
+
+ /*
+ * For each phyint in use, disable promiscuous reception of all IP
+ * multicasts.
+ */
+ for (vifi = 0; vifi < numvifs; vifi++) {
+ if (viftable[vifi].v_lcl_addr.s_addr != 0 &&
+ !(viftable[vifi].v_flags & VIFF_TUNNEL)) {
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_family = AF_INET;
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr.s_addr
+ = INADDR_ANY;
+ ifp = viftable[vifi].v_ifp;
+ (*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)&ifr);
+ }
+ }
+ bzero((caddr_t)tbftable, sizeof(tbftable));
+ bzero((caddr_t)viftable, sizeof(viftable));
+ numvifs = 0;
+ pim_assert = 0;
+
+ untimeout(expire_upcalls, (caddr_t)NULL);
+
+ /*
+ * Free all multicast forwarding cache entries.
+ */
+ for (i = 0; i < MFCTBLSIZ; i++) {
+ mb_rt = mfctable[i];
+ while (mb_rt) {
+ if (mb_rt->m_act != NULL) {
+ while (mb_rt->m_act) {
+ m = mb_rt->m_act;
+ mb_rt->m_act = m->m_act;
+ rte = mtod(m, struct rtdetq *);
+ m_freem(rte->m);
+ m_free(m);
+ }
+ }
+ mb_rt = m_free(mb_rt);
+ }
+ }
+
+ bzero((caddr_t)mfctable, sizeof(mfctable));
+
+ /*
+ * Reset de-encapsulation cache
+ */
+ last_encap_src = 0;
+ last_encap_vif = NULL;
+ have_encap_tunnel = 0;
+
+ ip_mrouter = NULL;
+
+ splx(s);
+
+ if (mrtdebug)
+ log(LOG_DEBUG, "ip_mrouter_done\n");
+
+ return 0;
+}
+
+#ifndef MROUTE_LKM
+int (*ip_mrouter_done)(void) = X_ip_mrouter_done;
+#endif
+
+static int
+get_version(struct mbuf *mb)
+{
+ int *v;
+
+ v = mtod(mb, int *);
+
+ *v = 0x0305; /* XXX !!!! */
+ mb->m_len = sizeof(int);
+
+ return 0;
+}
+
+/*
+ * Set PIM assert processing global
+ */
+static int
+set_assert(int *i)
+{
+ if ((*i != 1) && (*i != 0))
+ return EINVAL;
+
+ pim_assert = *i;
+
+ return 0;
+}
+
+/*
+ * Get PIM assert processing global
+ */
+static int
+get_assert(struct mbuf *m)
+{
+ int *i;
+
+ i = mtod(m, int *);
+
+ *i = pim_assert;
+
+ return 0;
+}
+
+/*
+ * Add a vif to the vif table
+ */
+static int
+add_vif(struct vifctl *vifcp)
+{
+ register struct vif *vifp = viftable + vifcp->vifc_vifi;
+ static struct sockaddr_in sin = {sizeof sin, AF_INET};
+ struct ifaddr *ifa;
+ struct ifnet *ifp;
+ struct ifreq ifr;
+ int error, s;
+ struct tbf *v_tbf = tbftable + vifcp->vifc_vifi;
+
+ if (vifcp->vifc_vifi >= MAXVIFS) return EINVAL;
+ if (vifp->v_lcl_addr.s_addr != 0) return EADDRINUSE;
+
+ /* Find the interface with an address in AF_INET family */
+ sin.sin_addr = vifcp->vifc_lcl_addr;
+ ifa = ifa_ifwithaddr((struct sockaddr *)&sin);
+ if (ifa == 0) return EADDRNOTAVAIL;
+ ifp = ifa->ifa_ifp;
+
+ if (vifcp->vifc_flags & VIFF_TUNNEL) {
+ if ((vifcp->vifc_flags & VIFF_SRCRT) == 0) {
+ /*
+ * An encapsulating tunnel is wanted. Tell ipip_input() to
+ * start paying attention to encapsulated packets.
+ */
+ if (have_encap_tunnel == 0) {
+ have_encap_tunnel = 1;
+ for (s = 0; s < MAXVIFS; ++s) {
+ multicast_decap_if[s].if_name = "mdecap";
+ multicast_decap_if[s].if_unit = s;
+ }
+ }
+ /*
+ * Set interface to fake encapsulator interface
+ */
+ ifp = &multicast_decap_if[vifcp->vifc_vifi];
+ /*
+ * Prepare cached route entry
+ */
+ bzero(&vifp->v_route, sizeof(vifp->v_route));
+ } else {
+ log(LOG_ERR, "source routed tunnels not supported\n");
+ return EOPNOTSUPP;
+ }
+ } else {
+ /* Make sure the interface supports multicast */
+ if ((ifp->if_flags & IFF_MULTICAST) == 0)
+ return EOPNOTSUPP;
+
+ /* Enable promiscuous reception of all IP multicasts from the if */
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_family = AF_INET;
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY;
+ s = splnet();
+ error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (caddr_t)&ifr);
+ splx(s);
+ if (error)
+ return error;
+ }
+
+ s = splnet();
+ /* define parameters for the tbf structure */
+ vifp->v_tbf = v_tbf;
+ GET_TIME(vifp->v_tbf->tbf_last_pkt_t);
+ vifp->v_tbf->tbf_n_tok = 0;
+ vifp->v_tbf->tbf_q_len = 0;
+ vifp->v_tbf->tbf_max_q_len = MAXQSIZE;
+ vifp->v_tbf->tbf_q = vifp->v_tbf->tbf_t = NULL;
+
+ vifp->v_flags = vifcp->vifc_flags;
+ vifp->v_threshold = vifcp->vifc_threshold;
+ vifp->v_lcl_addr = vifcp->vifc_lcl_addr;
+ vifp->v_rmt_addr = vifcp->vifc_rmt_addr;
+ vifp->v_ifp = ifp;
+ /* scaling up here allows division by 1024 in critical code */
+ vifp->v_rate_limit= vifcp->vifc_rate_limit * 1024 / 1000;
+ vifp->v_rsvp_on = 0;
+ vifp->v_rsvpd = NULL;
+ /* initialize per vif pkt counters */
+ vifp->v_pkt_in = 0;
+ vifp->v_pkt_out = 0;
+ vifp->v_bytes_in = 0;
+ vifp->v_bytes_out = 0;
+ splx(s);
+
+ /* Adjust numvifs up if the vifi is higher than numvifs */
+ if (numvifs <= vifcp->vifc_vifi) numvifs = vifcp->vifc_vifi + 1;
+
+ if (mrtdebug)
+ log(LOG_DEBUG, "add_vif #%d, lcladdr %x, %s %x, thresh %x, rate %d\n",
+ vifcp->vifc_vifi,
+ ntohl(vifcp->vifc_lcl_addr.s_addr),
+ (vifcp->vifc_flags & VIFF_TUNNEL) ? "rmtaddr" : "mask",
+ ntohl(vifcp->vifc_rmt_addr.s_addr),
+ vifcp->vifc_threshold,
+ vifcp->vifc_rate_limit);
+
+ return 0;
+}
+
+/*
+ * Delete a vif from the vif table
+ */
+static int
+del_vif(vifi_t *vifip)
+{
+ register struct vif *vifp = viftable + *vifip;
+ register vifi_t vifi;
+ register struct mbuf *m;
+ struct ifnet *ifp;
+ struct ifreq ifr;
+ int s;
+
+ if (*vifip >= numvifs) return EINVAL;
+ if (vifp->v_lcl_addr.s_addr == 0) return EADDRNOTAVAIL;
+
+ s = splnet();
+
+ if (!(vifp->v_flags & VIFF_TUNNEL)) {
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_family = AF_INET;
+ ((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY;
+ ifp = vifp->v_ifp;
+ (*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)&ifr);
+ }
+
+ if (vifp == last_encap_vif) {
+ last_encap_vif = 0;
+ last_encap_src = 0;
+ }
+
+ /*
+ * Free packets queued at the interface
+ */
+ while (vifp->v_tbf->tbf_q) {
+ m = vifp->v_tbf->tbf_q;
+ vifp->v_tbf->tbf_q = m->m_act;
+ m_freem(m);
+ }
+
+ bzero((caddr_t)vifp->v_tbf, sizeof(*(vifp->v_tbf)));
+ bzero((caddr_t)vifp, sizeof (*vifp));
+
+ /* Adjust numvifs down */
+ for (vifi = numvifs; vifi > 0; vifi--)
+ if (viftable[vifi-1].v_lcl_addr.s_addr != 0) break;
+ numvifs = vifi;
+
+ splx(s);
+
+ if (mrtdebug)
+ log(LOG_DEBUG, "del_vif %d, numvifs %d\n", *vifip, numvifs);
+
+ return 0;
+}
+
+/*
+ * Add an mfc entry
+ */
+static int
+add_mfc(struct mfcctl *mfccp)
+{
+ struct mfc *rt;
+ register struct mbuf *mb_rt;
+ u_long hash;
+ struct mbuf *mb_ntry;
+ struct rtdetq *rte;
+ register u_short nstl;
+ int s;
+ int i;
+
+ MFCFIND(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr, rt);
+
+ /* If an entry already exists, just update the fields */
+ if (rt) {
+ if (mrtdebug & DEBUG_MFC)
+ log(LOG_DEBUG,"add_mfc update o %x g %x p %x\n",
+ ntohl(mfccp->mfcc_origin.s_addr),
+ ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ mfccp->mfcc_parent);
+
+ s = splnet();
+ rt->mfc_parent = mfccp->mfcc_parent;
+ for (i = 0; i < numvifs; i++)
+ rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
+ splx(s);
+ return 0;
+ }
+
+ /*
+ * Find the entry for which the upcall was made and update
+ */
+ s = splnet();
+ hash = MFCHASH(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
+ for (mb_rt = mfctable[hash], nstl = 0; mb_rt; mb_rt = mb_rt->m_next) {
+
+ rt = mtod(mb_rt, struct mfc *);
+ if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
+ (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr) &&
+ (mb_rt->m_act != NULL)) {
+
+ if (nstl++)
+ log(LOG_ERR, "add_mfc %s o %x g %x p %x dbx %x\n",
+ "multiple kernel entries",
+ ntohl(mfccp->mfcc_origin.s_addr),
+ ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ mfccp->mfcc_parent, mb_rt->m_act);
+
+ if (mrtdebug & DEBUG_MFC)
+ log(LOG_DEBUG,"add_mfc o %x g %x p %x dbg %x\n",
+ ntohl(mfccp->mfcc_origin.s_addr),
+ ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ mfccp->mfcc_parent, mb_rt->m_act);
+
+ rt->mfc_origin = mfccp->mfcc_origin;
+ rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
+ rt->mfc_parent = mfccp->mfcc_parent;
+ for (i = 0; i < numvifs; i++)
+ rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
+ /* initialize pkt counters per src-grp */
+ rt->mfc_pkt_cnt = 0;
+ rt->mfc_byte_cnt = 0;
+ rt->mfc_wrong_if = 0;
+ rt->mfc_last_assert.tv_sec = rt->mfc_last_assert.tv_usec = 0;
+
+ rt->mfc_expire = 0; /* Don't clean this guy up */
+ nexpire[hash]--;
+
+ /* free packets Qed at the end of this entry */
+ while (mb_rt->m_act) {
+ mb_ntry = mb_rt->m_act;
+ rte = mtod(mb_ntry, struct rtdetq *);
+/* #ifdef RSVP_ISI */
+ ip_mdq(rte->m, rte->ifp, rt, -1);
+/* #endif */
+ mb_rt->m_act = mb_ntry->m_act;
+ m_freem(rte->m);
+#ifdef UPCALL_TIMING
+ collate(&(rte->t));
+#endif /* UPCALL_TIMING */
+ m_free(mb_ntry);
+ }
+ }
+ }
+
+ /*
+ * It is possible that an entry is being inserted without an upcall
+ */
+ if (nstl == 0) {
+ if (mrtdebug & DEBUG_MFC)
+ log(LOG_DEBUG,"add_mfc no upcall h %d o %x g %x p %x\n",
+ hash, ntohl(mfccp->mfcc_origin.s_addr),
+ ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ mfccp->mfcc_parent);
+
+ for (mb_rt = mfctable[hash]; mb_rt; mb_rt = mb_rt->m_next) {
+
+ rt = mtod(mb_rt, struct mfc *);
+ if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
+ (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr)) {
+
+ rt->mfc_origin = mfccp->mfcc_origin;
+ rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
+ rt->mfc_parent = mfccp->mfcc_parent;
+ for (i = 0; i < numvifs; i++)
+ rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
+ /* initialize pkt counters per src-grp */
+ rt->mfc_pkt_cnt = 0;
+ rt->mfc_byte_cnt = 0;
+ rt->mfc_wrong_if = 0;
+ rt->mfc_last_assert.tv_sec = rt->mfc_last_assert.tv_usec = 0;
+ if (rt->mfc_expire)
+ nexpire[hash]--;
+ rt->mfc_expire = 0;
+ }
+ }
+ if (mb_rt == NULL) {
+ /* no upcall, so make a new entry */
+ MGET(mb_rt, M_DONTWAIT, MT_MRTABLE);
+ if (mb_rt == NULL) {
+ splx(s);
+ return ENOBUFS;
+ }
+
+ rt = mtod(mb_rt, struct mfc *);
+
+ /* insert new entry at head of hash chain */
+ rt->mfc_origin = mfccp->mfcc_origin;
+ rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
+ rt->mfc_parent = mfccp->mfcc_parent;
+ for (i = 0; i < numvifs; i++)
+ rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
+ /* initialize pkt counters per src-grp */
+ rt->mfc_pkt_cnt = 0;
+ rt->mfc_byte_cnt = 0;
+ rt->mfc_wrong_if = 0;
+ rt->mfc_last_assert.tv_sec = rt->mfc_last_assert.tv_usec = 0;
+ rt->mfc_expire = 0;
+
+ /* link into table */
+ mb_rt->m_next = mfctable[hash];
+ mfctable[hash] = mb_rt;
+ mb_rt->m_act = NULL;
+ }
+ }
+ splx(s);
+ return 0;
+}
+
+#ifdef UPCALL_TIMING
+/*
+ * collect delay statistics on the upcalls
+ */
+static void collate(struct timeval *t)
+{
+ register u_long d;
+ register struct timeval tp;
+ register u_long delta;
+
+ GET_TIME(tp);
+
+ if (TV_LT(*t, tp))
+ {
+ TV_DELTA(tp, *t, delta);
+
+ d = delta >> 10;
+ if (d > 50)
+ d = 50;
+
+ ++upcall_data[d];
+ }
+}
+#endif /* UPCALL_TIMING */
+
+/*
+ * Delete an mfc entry
+ */
+static int
+del_mfc(struct mfcctl *mfccp)
+{
+ struct in_addr origin;
+ struct in_addr mcastgrp;
+ struct mfc *rt;
+ struct mbuf *mb_rt;
+ struct mbuf **nptr;
+ u_long hash;
+ int s;
+
+ origin = mfccp->mfcc_origin;
+ mcastgrp = mfccp->mfcc_mcastgrp;
+ hash = MFCHASH(origin.s_addr, mcastgrp.s_addr);
+
+ if (mrtdebug & DEBUG_MFC)
+ log(LOG_DEBUG,"del_mfc orig %x mcastgrp %x\n",
+ ntohl(origin.s_addr), ntohl(mcastgrp.s_addr));
+
+ s = splnet();
+
+ nptr = &mfctable[hash];
+ while ((mb_rt = *nptr) != NULL) {
+ rt = mtod(mb_rt, struct mfc *);
+ if (origin.s_addr == rt->mfc_origin.s_addr &&
+ mcastgrp.s_addr == rt->mfc_mcastgrp.s_addr &&
+ mb_rt->m_act == NULL)
+ break;
+
+ nptr = &mb_rt->m_next;
+ }
+ if (mb_rt == NULL) {
+ splx(s);
+ return EADDRNOTAVAIL;
+ }
+
+ MFREE(mb_rt, *nptr);
+
+ splx(s);
+
+ return 0;
+}
+
+/*
+ * Send a message to mrouted on the multicast routing socket
+ */
+static int
+socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src)
+{
+ if (s) {
+ if (sbappendaddr(&s->so_rcv,
+ (struct sockaddr *)src,
+ mm, (struct mbuf *)0) != 0) {
+ sorwakeup(s);
+ return 0;
+ }
+ }
+ m_freem(mm);
+ return -1;
+}
+
+/*
+ * IP multicast forwarding function. This function assumes that the packet
+ * pointed to by "ip" has arrived on (or is about to be sent to) the interface
+ * pointed to by "ifp", and the packet is to be relayed to other networks
+ * that have members of the packet's destination IP multicast group.
+ *
+ * The packet is returned unscathed to the caller, unless it is
+ * erroneous, in which case a non-zero return value tells the caller to
+ * discard it.
+ */
+
+#define IP_HDR_LEN 20 /* # bytes of fixed IP header (excluding options) */
+#define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */
+
+static int
+X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m,
+ struct ip_moptions *imo)
+{
+ register struct mfc *rt;
+ register u_char *ipoptions;
+ static struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
+ static int srctun = 0;
+ register struct mbuf *mm;
+ int s;
+ vifi_t vifi;
+ struct vif *vifp;
+
+ if (mrtdebug & DEBUG_FORWARD)
+ log(LOG_DEBUG, "ip_mforward: src %x, dst %x, ifp %x\n",
+ ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr), ifp);
+
+ if (ip->ip_hl < (IP_HDR_LEN + TUNNEL_LEN) >> 2 ||
+ (ipoptions = (u_char *)(ip + 1))[1] != IPOPT_LSRR ) {
+ /*
+ * Packet arrived via a physical interface or
+ * an encapsulated tunnel.
+ */
+ } else {
+ /*
+ * Packet arrived through a source-route tunnel.
+ * Source-route tunnels are no longer supported.
+ */
+ if ((srctun++ % 1000) == 0)
+ log(LOG_ERR, "ip_mforward: received source-routed packet from %x\n",
+ ntohl(ip->ip_src.s_addr));
+
+ return 1;
+ }
+
+ if ((imo) && ((vifi = imo->imo_multicast_vif) < numvifs)) {
+ if (ip->ip_ttl < 255)
+ ip->ip_ttl++; /* compensate for -1 in *_send routines */
+ if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
+ vifp = viftable + vifi;
+ printf("Sending IPPROTO_RSVP from %lx to %lx on vif %d (%s%s%d)\n",
+ ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr), vifi,
+ (vifp->v_flags & VIFF_TUNNEL) ? "tunnel on " : "",
+ vifp->v_ifp->if_name, vifp->v_ifp->if_unit);
+ }
+ return (ip_mdq(m, ifp, NULL, vifi));
+ }
+ if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
+ printf("Warning: IPPROTO_RSVP from %lx to %lx without vif option\n",
+ ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr));
+ if(!imo)
+ printf("In fact, no options were specified at all\n");
+ }
+
+ /*
+ * Don't forward a packet with time-to-live of zero or one,
+ * or a packet destined to a local-only group.
+ */
+ if (ip->ip_ttl <= 1 ||
+ ntohl(ip->ip_dst.s_addr) <= INADDR_MAX_LOCAL_GROUP)
+ return 0;
+
+ /*
+ * Determine forwarding vifs from the forwarding cache table
+ */
+ s = splnet();
+ MFCFIND(ip->ip_src.s_addr, ip->ip_dst.s_addr, rt);
+
+ /* Entry exists, so forward if necessary */
+ if (rt != NULL) {
+ splx(s);
+ return (ip_mdq(m, ifp, rt, -1));
+ } else {
+ /*
+ * If we don't have a route for packet's origin,
+ * Make a copy of the packet &
+ * send message to routing daemon
+ */
+
+ register struct mbuf *mb_rt;
+ register struct mbuf *mb_ntry;
+ register struct mbuf *mb0;
+ register struct rtdetq *rte;
+ register struct mbuf *rte_m;
+ register u_long hash;
+ register int npkts;
+ int hlen = ip->ip_hl << 2;
+#ifdef UPCALL_TIMING
+ struct timeval tp;
+
+ GET_TIME(tp);
+#endif
+
+ mrtstat.mrts_no_route++;
+ if (mrtdebug & (DEBUG_FORWARD | DEBUG_MFC))
+ log(LOG_DEBUG, "ip_mforward: no rte s %x g %x\n",
+ ntohl(ip->ip_src.s_addr),
+ ntohl(ip->ip_dst.s_addr));
+
+ /*
+ * Allocate mbufs early so that we don't do extra work if we are
+ * just going to fail anyway. Make sure to pullup the header so
+ * that other people can't step on it.
+ */
+ MGET(mb_ntry, M_DONTWAIT, MT_DATA);
+ if (mb_ntry == NULL) {
+ splx(s);
+ return ENOBUFS;
+ }
+ mb0 = m_copy(m, 0, M_COPYALL);
+ if (mb0 && (M_HASCL(mb0) || mb0->m_len < hlen))
+ mb0 = m_pullup(mb0, hlen);
+ if (mb0 == NULL) {
+ m_free(mb_ntry);
+ splx(s);
+ return ENOBUFS;
+ }
+
+ /* is there an upcall waiting for this packet? */
+ hash = MFCHASH(ip->ip_src.s_addr, ip->ip_dst.s_addr);
+ for (mb_rt = mfctable[hash]; mb_rt; mb_rt = mb_rt->m_next) {
+ rt = mtod(mb_rt, struct mfc *);
+ if ((ip->ip_src.s_addr == rt->mfc_origin.s_addr) &&
+ (ip->ip_dst.s_addr == rt->mfc_mcastgrp.s_addr) &&
+ (mb_rt->m_act != NULL))
+ break;
+ }
+
+ if (mb_rt == NULL) {
+ int i;
+ struct igmpmsg *im;
+
+ /* no upcall, so make a new entry */
+ MGET(mb_rt, M_DONTWAIT, MT_MRTABLE);
+ if (mb_rt == NULL) {
+ m_free(mb_ntry);
+ m_freem(mb0);
+ splx(s);
+ return ENOBUFS;
+ }
+ /* Make a copy of the header to send to the user level process */
+ mm = m_copy(mb0, 0, hlen);
+ if (mm == NULL) {
+ m_free(mb_ntry);
+ m_freem(mb0);
+ m_free(mb_rt);
+ splx(s);
+ return ENOBUFS;
+ }
+
+ /*
+ * Send message to routing daemon to install
+ * a route into the kernel table
+ */
+ k_igmpsrc.sin_addr = ip->ip_src;
+
+ im = mtod(mm, struct igmpmsg *);
+ im->im_msgtype = IGMPMSG_NOCACHE;
+ im->im_mbz = 0;
+
+ mrtstat.mrts_upcalls++;
+
+ if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
+ log(LOG_WARNING, "ip_mforward: ip_mrouter socket queue full\n");
+ ++mrtstat.mrts_upq_sockfull;
+ m_free(mb_ntry);
+ m_freem(mb0);
+ m_free(mb_rt);
+ splx(s);
+ return ENOBUFS;
+ }
+
+ rt = mtod(mb_rt, struct mfc *);
+
+ /* insert new entry at head of hash chain */
+ rt->mfc_origin.s_addr = ip->ip_src.s_addr;
+ rt->mfc_mcastgrp.s_addr = ip->ip_dst.s_addr;
+ rt->mfc_expire = UPCALL_EXPIRE;
+ nexpire[hash]++;
+ for (i = 0; i < numvifs; i++)
+ rt->mfc_ttls[i] = 0;
+ rt->mfc_parent = -1;
+
+ /* link into table */
+ mb_rt->m_next = mfctable[hash];
+ mfctable[hash] = mb_rt;
+ mb_rt->m_act = NULL;
+
+ rte_m = mb_rt;
+ } else {
+ /* determine if q has overflowed */
+ for (rte_m = mb_rt, npkts = 0; rte_m->m_act; rte_m = rte_m->m_act)
+ npkts++;
+
+ if (npkts > MAX_UPQ) {
+ mrtstat.mrts_upq_ovflw++;
+ m_free(mb_ntry);
+ m_freem(mb0);
+ splx(s);
+ return 0;
+ }
+ }
+
+ mb_ntry->m_act = NULL;
+ rte = mtod(mb_ntry, struct rtdetq *);
+
+ rte->m = mb0;
+ rte->ifp = ifp;
+#ifdef UPCALL_TIMING
+ rte->t = tp;
+#endif
+
+ /* Add this entry to the end of the queue */
+ rte_m->m_act = mb_ntry;
+
+ splx(s);
+
+ return 0;
+ }
+}
+
+#ifndef MROUTE_LKM
+int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
+ struct ip_moptions *) = X_ip_mforward;
+#endif
+
+/*
+ * Clean up the cache entry if upcall is not serviced
+ */
+static void
+expire_upcalls(void *unused)
+{
+ struct mbuf *mb_rt, *m, **nptr;
+ struct rtdetq *rte;
+ struct mfc *mfc;
+ int i;
+ int s;
+
+ s = splnet();
+ for (i = 0; i < MFCTBLSIZ; i++) {
+ if (nexpire[i] == 0)
+ continue;
+ nptr = &mfctable[i];
+ for (mb_rt = *nptr; mb_rt != NULL; mb_rt = *nptr) {
+ mfc = mtod(mb_rt, struct mfc *);
+
+ /*
+ * Skip real cache entries
+ * Make sure it wasn't marked to not expire (shouldn't happen)
+ * If it expires now
+ */
+ if (mb_rt->m_act != NULL &&
+ mfc->mfc_expire != 0 &&
+ --mfc->mfc_expire == 0) {
+ if (mrtdebug & DEBUG_EXPIRE)
+ log(LOG_DEBUG, "expire_upcalls: expiring (%x %x)\n",
+ ntohl(mfc->mfc_origin.s_addr),
+ ntohl(mfc->mfc_mcastgrp.s_addr));
+ /*
+ * drop all the packets
+ * free the mbuf with the pkt, if, timing info
+ */
+ while (mb_rt->m_act) {
+ m = mb_rt->m_act;
+ mb_rt->m_act = m->m_act;
+
+ rte = mtod(m, struct rtdetq *);
+ m_freem(rte->m);
+ m_free(m);
+ }
+ ++mrtstat.mrts_cache_cleanups;
+ nexpire[i]--;
+
+ MFREE(mb_rt, *nptr);
+ } else {
+ nptr = &mb_rt->m_next;
+ }
+ }
+ }
+ splx(s);
+ timeout(expire_upcalls, (caddr_t)NULL, EXPIRE_TIMEOUT);
+}
+
+/*
+ * Packet forwarding routine once entry in the cache is made
+ */
+static int
+ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt,
+ vifi_t xmt_vif)
+{
+ register struct ip *ip = mtod(m, struct ip *);
+ register vifi_t vifi;
+ register struct vif *vifp;
+ register int plen = ntohs(ip->ip_len);
+
+/*
+ * Macro to send packet on vif. Since RSVP packets don't get counted on
+ * input, they shouldn't get counted on output, so statistics keeping is
+ * seperate.
+ */
+#define MC_SEND(ip,vifp,m) { \
+ if ((vifp)->v_flags & VIFF_TUNNEL) \
+ encap_send((ip), (vifp), (m)); \
+ else \
+ phyint_send((ip), (vifp), (m)); \
+}
+
+ /*
+ * If xmt_vif is not -1, send on only the requested vif.
+ *
+ * (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.)
+ */
+ if (xmt_vif < numvifs) {
+ MC_SEND(ip, viftable + xmt_vif, m);
+ return 1;
+ }
+
+ /*
+ * Don't forward if it didn't arrive from the parent vif for its origin.
+ */
+ vifi = rt->mfc_parent;
+ if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) {
+ /* came in the wrong interface */
+ if (mrtdebug & DEBUG_FORWARD)
+ log(LOG_DEBUG, "wrong if: ifp %x vifi %d vififp %x\n",
+ ifp, vifi, viftable[vifi].v_ifp);
+ ++mrtstat.mrts_wrong_if;
+ ++rt->mfc_wrong_if;
+ /*
+ * If we are doing PIM assert processing, and we are forwarding
+ * packets on this interface, and it is a broadcast medium
+ * interface (and not a tunnel), send a message to the routing daemon.
+ */
+ if (pim_assert && rt->mfc_ttls[vifi] &&
+ (ifp->if_flags & IFF_BROADCAST) &&
+ !(viftable[vifi].v_flags & VIFF_TUNNEL)) {
+ struct sockaddr_in k_igmpsrc;
+ struct mbuf *mm;
+ struct igmpmsg *im;
+ int hlen = ip->ip_hl << 2;
+ struct timeval now;
+ register u_long delta;
+
+ GET_TIME(now);
+
+ TV_DELTA(rt->mfc_last_assert, now, delta);
+
+ if (delta > ASSERT_MSG_TIME) {
+ mm = m_copy(m, 0, hlen);
+ if (mm && (M_HASCL(mm) || mm->m_len < hlen))
+ mm = m_pullup(mm, hlen);
+ if (mm == NULL) {
+ return ENOBUFS;
+ }
+
+ rt->mfc_last_assert = now;
+
+ im = mtod(mm, struct igmpmsg *);
+ im->im_msgtype = IGMPMSG_WRONGVIF;
+ im->im_mbz = 0;
+ im->im_vif = vifi;
+
+ k_igmpsrc.sin_addr = im->im_src;
+
+ socket_send(ip_mrouter, mm, &k_igmpsrc);
+ }
+ }
+ return 0;
+ }
+
+ /* If I sourced this packet, it counts as output, else it was input. */
+ if (ip->ip_src.s_addr == viftable[vifi].v_lcl_addr.s_addr) {
+ viftable[vifi].v_pkt_out++;
+ viftable[vifi].v_bytes_out += plen;
+ } else {
+ viftable[vifi].v_pkt_in++;
+ viftable[vifi].v_bytes_in += plen;
+ }
+ rt->mfc_pkt_cnt++;
+ rt->mfc_byte_cnt += plen;
+
+ /*
+ * For each vif, decide if a copy of the packet should be forwarded.
+ * Forward if:
+ * - the ttl exceeds the vif's threshold
+ * - there are group members downstream on interface
+ */
+ for (vifp = viftable, vifi = 0; vifi < numvifs; vifp++, vifi++)
+ if ((rt->mfc_ttls[vifi] > 0) &&
+ (ip->ip_ttl > rt->mfc_ttls[vifi])) {
+ vifp->v_pkt_out++;
+ vifp->v_bytes_out += plen;
+ MC_SEND(ip, vifp, m);
+ }
+
+ return 0;
+}
+
+/*
+ * check if a vif number is legal/ok. This is used by ip_output, to export
+ * numvifs there,
+ */
+static int
+X_legal_vif_num(int vif)
+{
+ if (vif >= 0 && vif < numvifs)
+ return(1);
+ else
+ return(0);
+}
+
+#ifndef MROUTE_LKM
+int (*legal_vif_num)(int) = X_legal_vif_num;
+#endif
+
+/*
+ * Return the local address used by this vif
+ */
+static u_long
+X_ip_mcast_src(int vifi)
+{
+ if (vifi >= 0 && vifi < numvifs)
+ return viftable[vifi].v_lcl_addr.s_addr;
+ else
+ return INADDR_ANY;
+}
+
+#ifndef MROUTE_LKM
+u_long (*ip_mcast_src)(int) = X_ip_mcast_src;
+#endif
+
+static void
+phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
+{
+ register struct mbuf *mb_copy;
+ register int hlen = ip->ip_hl << 2;
+
+ /*
+ * Make a new reference to the packet; make sure that
+ * the IP header is actually copied, not just referenced,
+ * so that ip_output() only scribbles on the copy.
+ */
+ mb_copy = m_copy(m, 0, M_COPYALL);
+ if (mb_copy && (M_HASCL(mb_copy) || mb_copy->m_len < hlen))
+ mb_copy = m_pullup(mb_copy, hlen);
+ if (mb_copy == NULL)
+ return;
+
+ if (vifp->v_rate_limit <= 0)
+ tbf_send_packet(vifp, mb_copy);
+ else
+ tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *), ip->ip_len);
+}
+
+static void
+encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
+{
+ register struct mbuf *mb_copy;
+ register struct ip *ip_copy;
+ register int i, len = ip->ip_len;
+
+ /*
+ * copy the old packet & pullup it's IP header into the
+ * new mbuf so we can modify it. Try to fill the new
+ * mbuf since if we don't the ethernet driver will.
+ */
+ MGETHDR(mb_copy, M_DONTWAIT, MT_HEADER);
+ if (mb_copy == NULL)
+ return;
+ mb_copy->m_data += max_linkhdr;
+ mb_copy->m_len = sizeof(multicast_encap_iphdr);
+
+ if ((mb_copy->m_next = m_copy(m, 0, M_COPYALL)) == NULL) {
+ m_freem(mb_copy);
+ return;
+ }
+ i = MHLEN - M_LEADINGSPACE(mb_copy);
+ if (i > len)
+ i = len;
+ mb_copy = m_pullup(mb_copy, i);
+ if (mb_copy == NULL)
+ return;
+ mb_copy->m_pkthdr.len = len + sizeof(multicast_encap_iphdr);
+
+ /*
+ * fill in the encapsulating IP header.
+ */
+ ip_copy = mtod(mb_copy, struct ip *);
+ *ip_copy = multicast_encap_iphdr;
+ ip_copy->ip_id = htons(ip_id++);
+ ip_copy->ip_len += len;
+ ip_copy->ip_src = vifp->v_lcl_addr;
+ ip_copy->ip_dst = vifp->v_rmt_addr;
+
+ /*
+ * turn the encapsulated IP header back into a valid one.
+ */
+ ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
+ --ip->ip_ttl;
+ HTONS(ip->ip_len);
+ HTONS(ip->ip_off);
+ ip->ip_sum = 0;
+ mb_copy->m_data += sizeof(multicast_encap_iphdr);
+ ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
+ mb_copy->m_data -= sizeof(multicast_encap_iphdr);
+
+ if (vifp->v_rate_limit <= 0)
+ tbf_send_packet(vifp, mb_copy);
+ else
+ tbf_control(vifp, mb_copy, ip, ip_copy->ip_len);
+}
+
+/*
+ * De-encapsulate a packet and feed it back through ip input (this
+ * routine is called whenever IP gets a packet with proto type
+ * ENCAP_PROTO and a local destination address).
+ */
+void
+#ifdef MROUTE_LKM
+X_ipip_input(struct mbuf *m, int iphlen)
+#else
+ipip_input(struct mbuf *m, int iphlen)
+#endif
+{
+ struct ifnet *ifp = m->m_pkthdr.rcvif;
+ register struct ip *ip = mtod(m, struct ip *);
+ register int hlen = ip->ip_hl << 2;
+ register int s;
+ register struct ifqueue *ifq;
+ register struct vif *vifp;
+
+ if (!have_encap_tunnel) {
+ rip_input(m, iphlen);
+ return;
+ }
+ /*
+ * dump the packet if it's not to a multicast destination or if
+ * we don't have an encapsulating tunnel with the source.
+ * Note: This code assumes that the remote site IP address
+ * uniquely identifies the tunnel (i.e., that this site has
+ * at most one tunnel with the remote site).
+ */
+ if (! IN_MULTICAST(ntohl(((struct ip *)((char *)ip + hlen))->ip_dst.s_addr))) {
+ ++mrtstat.mrts_bad_tunnel;
+ m_freem(m);
+ return;
+ }
+ if (ip->ip_src.s_addr != last_encap_src) {
+ register struct vif *vife;
+
+ vifp = viftable;
+ vife = vifp + numvifs;
+ last_encap_src = ip->ip_src.s_addr;
+ last_encap_vif = 0;
+ for ( ; vifp < vife; ++vifp)
+ if (vifp->v_rmt_addr.s_addr == ip->ip_src.s_addr) {
+ if ((vifp->v_flags & (VIFF_TUNNEL|VIFF_SRCRT))
+ == VIFF_TUNNEL)
+ last_encap_vif = vifp;
+ break;
+ }
+ }
+ if ((vifp = last_encap_vif) == 0) {
+ last_encap_src = 0;
+ mrtstat.mrts_cant_tunnel++; /*XXX*/
+ m_freem(m);
+ if (mrtdebug)
+ log(LOG_DEBUG, "ip_mforward: no tunnel with %x\n",
+ ntohl(ip->ip_src.s_addr));
+ return;
+ }
+ ifp = vifp->v_ifp;
+
+ if (hlen > IP_HDR_LEN)
+ ip_stripoptions(m, (struct mbuf *) 0);
+ m->m_data += IP_HDR_LEN;
+ m->m_len -= IP_HDR_LEN;
+ m->m_pkthdr.len -= IP_HDR_LEN;
+ m->m_pkthdr.rcvif = ifp;
+
+ ifq = &ipintrq;
+ s = splimp();
+ if (IF_QFULL(ifq)) {
+ IF_DROP(ifq);
+ m_freem(m);
+ } else {
+ IF_ENQUEUE(ifq, m);
+ /*
+ * normally we would need a "schednetisr(NETISR_IP)"
+ * here but we were called by ip_input and it is going
+ * to loop back & try to dequeue the packet we just
+ * queued as soon as we return so we avoid the
+ * unnecessary software interrrupt.
+ */
+ }
+ splx(s);
+}
+
+/*
+ * Token bucket filter module
+ */
+
+static void
+tbf_control(struct vif *vifp, struct mbuf *m, struct ip *ip, u_long p_len)
+{
+ register struct tbf *t = vifp->v_tbf;
+
+ if (p_len > MAX_BKT_SIZE) {
+ /* drop if packet is too large */
+ mrtstat.mrts_pkt2large++;
+ m_freem(m);
+ return;
+ }
+
+ tbf_update_tokens(vifp);
+
+ /* if there are enough tokens,
+ * and the queue is empty,
+ * send this packet out
+ */
+
+ if (t->tbf_q_len == 0) {
+ /* queue empty, send packet if enough tokens */
+ if (p_len <= t->tbf_n_tok) {
+ t->tbf_n_tok -= p_len;
+ tbf_send_packet(vifp, m);
+ } else {
+ /* queue packet and timeout till later */
+ tbf_queue(vifp, m);
+ timeout(tbf_reprocess_q, (caddr_t)vifp, TBF_REPROCESS);
+ }
+ } else if (t->tbf_q_len < t->tbf_max_q_len) {
+ /* finite queue length, so queue pkts and process queue */
+ tbf_queue(vifp, m);
+ tbf_process_q(vifp);
+ } else {
+ /* queue length too much, try to dq and queue and process */
+ if (!tbf_dq_sel(vifp, ip)) {
+ mrtstat.mrts_q_overflow++;
+ m_freem(m);
+ return;
+ } else {
+ tbf_queue(vifp, m);
+ tbf_process_q(vifp);
+ }
+ }
+ return;
+}
+
+/*
+ * adds a packet to the queue at the interface
+ */
+static void
+tbf_queue(struct vif *vifp, struct mbuf *m)
+{
+ register int s = splnet();
+ register struct tbf *t = vifp->v_tbf;
+
+ if (t->tbf_t == NULL) {
+ /* Queue was empty */
+ t->tbf_q = m;
+ } else {
+ /* Insert at tail */
+ t->tbf_t->m_act = m;
+ }
+
+ /* Set new tail pointer */
+ t->tbf_t = m;
+
+#ifdef DIAGNOSTIC
+ /* Make sure we didn't get fed a bogus mbuf */
+ if (m->m_act)
+ panic("tbf_queue: m_act");
+#endif
+ m->m_act = NULL;
+
+ t->tbf_q_len++;
+
+ splx(s);
+}
+
+
+/*
+ * processes the queue at the interface
+ */
+static void
+tbf_process_q(struct vif *vifp)
+{
+ register struct mbuf *m;
+ register int len;
+ register int s = splnet();
+ register struct tbf *t = vifp->v_tbf;
+
+ /* loop through the queue at the interface and send as many packets
+ * as possible
+ */
+ while (t->tbf_q_len > 0) {
+ m = t->tbf_q;
+
+ len = mtod(m, struct ip *)->ip_len;
+
+ /* determine if the packet can be sent */
+ if (len <= t->tbf_n_tok) {
+ /* if so,
+ * reduce no of tokens, dequeue the packet,
+ * send the packet.
+ */
+ t->tbf_n_tok -= len;
+
+ t->tbf_q = m->m_act;
+ if (--t->tbf_q_len == 0)
+ t->tbf_t = NULL;
+
+ m->m_act = NULL;
+ tbf_send_packet(vifp, m);
+
+ } else break;
+ }
+ splx(s);
+}
+
+static void
+tbf_reprocess_q(void *xvifp)
+{
+ register struct vif *vifp = xvifp;
+ if (ip_mrouter == NULL)
+ return;
+
+ tbf_update_tokens(vifp);
+
+ tbf_process_q(vifp);
+
+ if (vifp->v_tbf->tbf_q_len)
+ timeout(tbf_reprocess_q, (caddr_t)vifp, TBF_REPROCESS);
+}
+
+/* function that will selectively discard a member of the queue
+ * based on the precedence value and the priority
+ */
+static int
+tbf_dq_sel(struct vif *vifp, struct ip *ip)
+{
+ register int s = splnet();
+ register u_int p;
+ register struct mbuf *m, *last;
+ register struct mbuf **np;
+ register struct tbf *t = vifp->v_tbf;
+
+ p = priority(vifp, ip);
+
+ np = &t->tbf_q;
+ last = NULL;
+ while ((m = *np) != NULL) {
+ if (p > priority(vifp, mtod(m, struct ip *))) {
+ *np = m->m_act;
+ /* If we're removing the last packet, fix the tail pointer */
+ if (m == t->tbf_t)
+ t->tbf_t = last;
+ m_freem(m);
+ /* it's impossible for the queue to be empty, but
+ * we check anyway. */
+ if (--t->tbf_q_len == 0)
+ t->tbf_t = NULL;
+ splx(s);
+ mrtstat.mrts_drop_sel++;
+ return(1);
+ }
+ np = &m->m_act;
+ last = m;
+ }
+ splx(s);
+ return(0);
+}
+
+static void
+tbf_send_packet(struct vif *vifp, struct mbuf *m)
+{
+ struct ip_moptions imo;
+ int error;
+ static struct route ro;
+ int s = splnet();
+
+ if (vifp->v_flags & VIFF_TUNNEL) {
+ /* If tunnel options */
+ ip_output(m, (struct mbuf *)0, &vifp->v_route,
+ IP_FORWARDING, (struct ip_moptions *)0);
+ } else {
+ imo.imo_multicast_ifp = vifp->v_ifp;
+ imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
+ imo.imo_multicast_loop = 1;
+ imo.imo_multicast_vif = -1;
+
+ /*
+ * Re-entrancy should not be a problem here, because
+ * the packets that we send out and are looped back at us
+ * should get rejected because they appear to come from
+ * the loopback interface, thus preventing looping.
+ */
+ error = ip_output(m, (struct mbuf *)0, &ro,
+ IP_FORWARDING, &imo);
+
+ if (mrtdebug & DEBUG_XMIT)
+ log(LOG_DEBUG, "phyint_send on vif %d err %d\n",
+ vifp - viftable, error);
+ }
+ splx(s);
+}
+
+/* determine the current time and then
+ * the elapsed time (between the last time and time now)
+ * in milliseconds & update the no. of tokens in the bucket
+ */
+static void
+tbf_update_tokens(struct vif *vifp)
+{
+ struct timeval tp;
+ register u_long tm;
+ register int s = splnet();
+ register struct tbf *t = vifp->v_tbf;
+
+ GET_TIME(tp);
+
+ TV_DELTA(tp, t->tbf_last_pkt_t, tm);
+
+ /*
+ * This formula is actually
+ * "time in seconds" * "bytes/second".
+ *
+ * (tm / 1000000) * (v_rate_limit * 1000 * (1000/1024) / 8)
+ *
+ * The (1000/1024) was introduced in add_vif to optimize
+ * this divide into a shift.
+ */
+ t->tbf_n_tok += tm * vifp->v_rate_limit / 1024 / 8;
+ t->tbf_last_pkt_t = tp;
+
+ if (t->tbf_n_tok > MAX_BKT_SIZE)
+ t->tbf_n_tok = MAX_BKT_SIZE;
+
+ splx(s);
+}
+
+static int
+priority(struct vif *vifp, struct ip *ip)
+{
+ register int prio;
+
+ /* temporary hack; may add general packet classifier some day */
+
+ /*
+ * The UDP port space is divided up into four priority ranges:
+ * [0, 16384) : unclassified - lowest priority
+ * [16384, 32768) : audio - highest priority
+ * [32768, 49152) : whiteboard - medium priority
+ * [49152, 65536) : video - low priority
+ */
+ if (ip->ip_p == IPPROTO_UDP) {
+ struct udphdr *udp = (struct udphdr *)(((char *)ip) + (ip->ip_hl << 2));
+ switch (ntohs(udp->uh_dport) & 0xc000) {
+ case 0x4000:
+ prio = 70;
+ break;
+ case 0x8000:
+ prio = 60;
+ break;
+ case 0xc000:
+ prio = 55;
+ break;
+ default:
+ prio = 50;
+ break;
+ }
+ if (tbfdebug > 1)
+ log(LOG_DEBUG, "port %x prio%d\n", ntohs(udp->uh_dport), prio);
+ } else {
+ prio = 50;
+ }
+ return prio;
+}
+
+/*
+ * End of token bucket filter modifications
+ */
+
+int
+ip_rsvp_vif_init(struct socket *so, struct mbuf *m)
+{
+ int i;
+ register int s;
+
+ if (rsvpdebug)
+ printf("ip_rsvp_vif_init: so_type = %d, pr_protocol = %d\n",
+ so->so_type, so->so_proto->pr_protocol);
+
+ if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
+ return EOPNOTSUPP;
+
+ /* Check mbuf. */
+ if (m == NULL || m->m_len != sizeof(int)) {
+ return EINVAL;
+ }
+ i = *(mtod(m, int *));
+
+ if (rsvpdebug)
+ printf("ip_rsvp_vif_init: vif = %d rsvp_on = %d\n",i,rsvp_on);
+
+ s = splnet();
+
+ /* Check vif. */
+ if (!legal_vif_num(i)) {
+ splx(s);
+ return EADDRNOTAVAIL;
+ }
+
+ /* Check if socket is available. */
+ if (viftable[i].v_rsvpd != NULL) {
+ splx(s);
+ return EADDRINUSE;
+ }
+
+ viftable[i].v_rsvpd = so;
+ /* This may seem silly, but we need to be sure we don't over-increment
+ * the RSVP counter, in case something slips up.
+ */
+ if (!viftable[i].v_rsvp_on) {
+ viftable[i].v_rsvp_on = 1;
+ rsvp_on++;
+ }
+
+ splx(s);
+ return 0;
+}
+
+int
+ip_rsvp_vif_done(struct socket *so, struct mbuf *m)
+{
+ int i;
+ register int s;
+
+ if (rsvpdebug)
+ printf("ip_rsvp_vif_done: so_type = %d, pr_protocol = %d\n",
+ so->so_type, so->so_proto->pr_protocol);
+
+ if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
+ return EOPNOTSUPP;
+
+ /* Check mbuf. */
+ if (m == NULL || m->m_len != sizeof(int)) {
+ return EINVAL;
+ }
+ i = *(mtod(m, int *));
+
+ s = splnet();
+
+ /* Check vif. */
+ if (!legal_vif_num(i)) {
+ splx(s);
+ return EADDRNOTAVAIL;
+ }
+
+ if (rsvpdebug)
+ printf("ip_rsvp_vif_done: v_rsvpd = %p so = %p\n",
+ viftable[i].v_rsvpd, so);
+
+ viftable[i].v_rsvpd = NULL;
+ /* This may seem silly, but we need to be sure we don't over-decrement
+ * the RSVP counter, in case something slips up.
+ */
+ if (viftable[i].v_rsvp_on) {
+ viftable[i].v_rsvp_on = 0;
+ rsvp_on--;
+ }
+
+ splx(s);
+ return 0;
+}
+
+void
+ip_rsvp_force_done(struct socket *so)
+{
+ int vifi;
+ register int s;
+
+ /* Don't bother if it is not the right type of socket. */
+ if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
+ return;
+
+ s = splnet();
+
+ /* The socket may be attached to more than one vif...this
+ * is perfectly legal.
+ */
+ for (vifi = 0; vifi < numvifs; vifi++) {
+ if (viftable[vifi].v_rsvpd == so) {
+ viftable[vifi].v_rsvpd = NULL;
+ /* This may seem silly, but we need to be sure we don't
+ * over-decrement the RSVP counter, in case something slips up.
+ */
+ if (viftable[vifi].v_rsvp_on) {
+ viftable[vifi].v_rsvp_on = 0;
+ rsvp_on--;
+ }
+ }
+ }
+
+ splx(s);
+ return;
+}
+
+void
+rsvp_input(struct mbuf *m, int iphlen)
+{
+ int vifi;
+ register struct ip *ip = mtod(m, struct ip *);
+ static struct sockaddr_in rsvp_src = { sizeof rsvp_src, AF_INET };
+ register int s;
+ struct ifnet *ifp;
+
+ if (rsvpdebug)
+ printf("rsvp_input: rsvp_on %d\n",rsvp_on);
+
+ /* Can still get packets with rsvp_on = 0 if there is a local member
+ * of the group to which the RSVP packet is addressed. But in this
+ * case we want to throw the packet away.
+ */
+ if (!rsvp_on) {
+ m_freem(m);
+ return;
+ }
+
+ /* If the old-style non-vif-associated socket is set, then use
+ * it and ignore the new ones.
+ */
+ if (ip_rsvpd != NULL) {
+ if (rsvpdebug)
+ printf("rsvp_input: Sending packet up old-style socket\n");
+ rip_input(m, iphlen);
+ return;
+ }
+
+ s = splnet();
+
+ if (rsvpdebug)
+ printf("rsvp_input: check vifs\n");
+
+#ifdef DIAGNOSTIC
+ if (!(m->m_flags & M_PKTHDR))
+ panic("rsvp_input no hdr");
+#endif
+
+ ifp = m->m_pkthdr.rcvif;
+ /* Find which vif the packet arrived on. */
+ for (vifi = 0; vifi < numvifs; vifi++) {
+ if (viftable[vifi].v_ifp == ifp)
+ break;
+ }
+
+ if (vifi == numvifs) {
+ /* Can't find vif packet arrived on. Drop packet. */
+ if (rsvpdebug)
+ printf("rsvp_input: Can't find vif for packet...dropping it.\n");
+ m_freem(m);
+ splx(s);
+ return;
+ }
+
+ if (rsvpdebug)
+ printf("rsvp_input: check socket\n");
+
+ if (viftable[vifi].v_rsvpd == NULL) {
+ /* drop packet, since there is no specific socket for this
+ * interface */
+ if (rsvpdebug)
+ printf("rsvp_input: No socket defined for vif %d\n",vifi);
+ m_freem(m);
+ splx(s);
+ return;
+ }
+ rsvp_src.sin_addr = ip->ip_src;
+
+ if (rsvpdebug && m)
+ printf("rsvp_input: m->m_len = %d, sbspace() = %ld\n",
+ m->m_len,sbspace(&(viftable[vifi].v_rsvpd->so_rcv)));
+
+ if (socket_send(viftable[vifi].v_rsvpd, m, &rsvp_src) < 0)
+ if (rsvpdebug)
+ printf("rsvp_input: Failed to append to socket\n");
+ else
+ if (rsvpdebug)
+ printf("rsvp_input: send packet up\n");
+
+ splx(s);
+}
+
+#ifdef MROUTE_LKM
+#include <sys/conf.h>
+#include <sys/exec.h>
+#include <sys/sysent.h>
+#include <sys/lkm.h>
+
+MOD_MISC("ip_mroute_mod")
+
+static int
+ip_mroute_mod_handle(struct lkm_table *lkmtp, int cmd)
+{
+ int i;
+ struct lkm_misc *args = lkmtp->private.lkm_misc;
+ int err = 0;
+
+ switch(cmd) {
+ static int (*old_ip_mrouter_cmd)();
+ static int (*old_ip_mrouter_done)();
+ static int (*old_ip_mforward)();
+ static int (*old_mrt_ioctl)();
+ static void (*old_proto4_input)();
+ static int (*old_legal_vif_num)();
+ extern struct protosw inetsw[];
+
+ case LKM_E_LOAD:
+ if(lkmexists(lkmtp) || ip_mrtproto)
+ return(EEXIST);
+ old_ip_mrouter_cmd = ip_mrouter_cmd;
+ ip_mrouter_cmd = X_ip_mrouter_cmd;
+ old_ip_mrouter_done = ip_mrouter_done;
+ ip_mrouter_done = X_ip_mrouter_done;
+ old_ip_mforward = ip_mforward;
+ ip_mforward = X_ip_mforward;
+ old_mrt_ioctl = mrt_ioctl;
+ mrt_ioctl = X_mrt_ioctl;
+ old_proto4_input = inetsw[ip_protox[ENCAP_PROTO]].pr_input;
+ inetsw[ip_protox[ENCAP_PROTO]].pr_input = X_ipip_input;
+ old_legal_vif_num = legal_vif_num;
+ legal_vif_num = X_legal_vif_num;
+ ip_mrtproto = IGMP_DVMRP;
+
+ printf("\nIP multicast routing loaded\n");
+ break;
+
+ case LKM_E_UNLOAD:
+ if (ip_mrouter)
+ return EINVAL;
+
+ ip_mrouter_cmd = old_ip_mrouter_cmd;
+ ip_mrouter_done = old_ip_mrouter_done;
+ ip_mforward = old_ip_mforward;
+ mrt_ioctl = old_mrt_ioctl;
+ inetsw[ip_protox[ENCAP_PROTO]].pr_input = old_proto4_input;
+ legal_vif_num = old_legal_vif_num;
+ ip_mrtproto = 0;
+ break;
+
+ default:
+ err = EINVAL;
+ break;
+ }
+
+ return(err);
+}
+
+int
+ip_mroute_mod(struct lkm_table *lkmtp, int cmd, int ver) {
+ DISPATCH(lkmtp, cmd, ver, ip_mroute_mod_handle, ip_mroute_mod_handle,
+ nosys);
+}
+
+#endif /* MROUTE_LKM */
+#endif /* MROUTING */
diff --git a/cpukit/libnetworking/netinet/ip_mroute.h b/cpukit/libnetworking/netinet/ip_mroute.h
new file mode 100644
index 0000000000..139c755675
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_mroute.h
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 1989 Stephen Deering.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Stephen Deering of Stanford University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip_mroute.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/ip_mroute.h,v 1.31 2007/02/08 23:05:08 bms Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IP_MROUTE_H_
+#define _NETINET_IP_MROUTE_H_
+
+/*
+ * Definitions for IP multicast forwarding.
+ *
+ * Written by David Waitzman, BBN Labs, August 1988.
+ * Modified by Steve Deering, Stanford, February 1989.
+ * Modified by Ajit Thyagarajan, PARC, August 1993.
+ * Modified by Ajit Thyagarajan, PARC, August 1994.
+ * Modified by Ahmed Helmy, SGI, June 1996.
+ * Modified by Pavlin Radoslavov, ICSI, October 2002.
+ *
+ * MROUTING Revision: 3.3.1.3
+ * and PIM-SMv2 and PIM-DM support, advanced API support,
+ * bandwidth metering and signaling.
+ */
+
+
+/*
+ * Multicast Routing set/getsockopt commands.
+ */
+#define MRT_INIT 100 /* initialize forwarder */
+#define MRT_DONE 101 /* shut down forwarder */
+#define MRT_ADD_VIF 102 /* create virtual interface */
+#define MRT_DEL_VIF 103 /* delete virtual interface */
+#define MRT_ADD_MFC 104 /* insert forwarding cache entry */
+#define MRT_DEL_MFC 105 /* delete forwarding cache entry */
+#define MRT_VERSION 106 /* get kernel version number */
+#define MRT_ASSERT 107 /* enable assert processing */
+#define MRT_PIM MRT_ASSERT /* enable PIM processing */
+#define MRT_API_SUPPORT 109 /* supported MRT API */
+#define MRT_API_CONFIG 110 /* config MRT API */
+#define MRT_ADD_BW_UPCALL 111 /* create bandwidth monitor */
+#define MRT_DEL_BW_UPCALL 112 /* delete bandwidth monitor */
+
+
+#define GET_TIME(t) microtime(&t)
+
+/*
+ * Types and macros for handling bitmaps with one bit per virtual interface.
+ */
+#define MAXVIFS 32
+typedef u_long vifbitmap_t;
+typedef u_short vifi_t; /* type of a vif index */
+#define ALL_VIFS (vifi_t)-1
+
+#define VIFM_SET(n, m) ((m) |= (1 << (n)))
+#define VIFM_CLR(n, m) ((m) &= ~(1 << (n)))
+#define VIFM_ISSET(n, m) ((m) & (1 << (n)))
+#define VIFM_CLRALL(m) ((m) = 0x00000000)
+#define VIFM_COPY(mfrom, mto) ((mto) = (mfrom))
+#define VIFM_SAME(m1, m2) ((m1) == (m2))
+
+
+/*
+ * Argument structure for MRT_ADD_VIF.
+ * (MRT_DEL_VIF takes a single vifi_t argument.)
+ */
+struct vifctl {
+ vifi_t vifc_vifi; /* the index of the vif to be added */
+ u_char vifc_flags; /* VIFF_ flags defined below */
+ u_char vifc_threshold; /* min ttl required to forward on vif */
+ u_int vifc_rate_limit; /* max rate */
+ struct in_addr vifc_lcl_addr; /* local interface address */
+ struct in_addr vifc_rmt_addr; /* remote address (tunnels only) */
+};
+
+#define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */
+#define VIFF_SRCRT 0x2 /* tunnel uses IP source routing */
+
+/*
+ * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
+ * (mfcc_tos to be added at a future point)
+ */
+struct mfcctl {
+ struct in_addr mfcc_origin; /* ip origin of mcasts */
+ struct in_addr mfcc_mcastgrp; /* multicast group associated*/
+ vifi_t mfcc_parent; /* incoming vif */
+ u_char mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
+};
+
+/*
+ * The kernel's multicast routing statistics.
+ */
+struct mrtstat {
+ u_long mrts_mfc_lookups; /* # forw. cache hash table hits */
+ u_long mrts_mfc_misses; /* # forw. cache hash table misses */
+ u_long mrts_upcalls; /* # calls to mrouted */
+ u_long mrts_no_route; /* no route for packet's origin */
+ u_long mrts_bad_tunnel; /* malformed tunnel options */
+ u_long mrts_cant_tunnel; /* no room for tunnel options */
+ u_long mrts_wrong_if; /* arrived on wrong interface */
+ u_long mrts_upq_ovflw; /* upcall Q overflow */
+ u_long mrts_cache_cleanups; /* # entries with no upcalls */
+ u_long mrts_drop_sel; /* pkts dropped selectively */
+ u_long mrts_q_overflow; /* pkts dropped - Q overflow */
+ u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */
+ u_long mrts_upq_sockfull; /* upcalls dropped - socket full */
+};
+
+/*
+ * Argument structure used by mrouted to get src-grp pkt counts
+ */
+struct sioc_sg_req {
+ struct in_addr src;
+ struct in_addr grp;
+ u_long pktcnt;
+ u_long bytecnt;
+ u_long wrong_if;
+};
+
+/*
+ * Argument structure used by mrouted to get vif pkt counts
+ */
+struct sioc_vif_req {
+ vifi_t vifi; /* vif number */
+ u_long icount; /* Input packet count on vif */
+ u_long ocount; /* Output packet count on vif */
+ u_long ibytes; /* Input byte count on vif */
+ u_long obytes; /* Output byte count on vif */
+};
+
+
+/*
+ * The kernel's virtual-interface structure.
+ */
+struct vif {
+ u_char v_flags; /* VIFF_ flags defined above */
+ u_char v_threshold; /* min ttl required to forward on vif*/
+ u_int v_rate_limit; /* max rate */
+ struct tbf *v_tbf; /* token bucket structure at intf. */
+ struct in_addr v_lcl_addr; /* local interface address */
+ struct in_addr v_rmt_addr; /* remote address (tunnels only) */
+ struct ifnet *v_ifp; /* pointer to interface */
+ u_long v_pkt_in; /* # pkts in on interface */
+ u_long v_pkt_out; /* # pkts out on interface */
+ u_long v_bytes_in; /* # bytes in on interface */
+ u_long v_bytes_out; /* # bytes out on interface */
+ struct route v_route; /* cached route if this is a tunnel */
+ u_int v_rsvp_on; /* RSVP listening on this vif */
+ struct socket *v_rsvpd; /* RSVP daemon socket */
+};
+
+/*
+ * The kernel's multicast forwarding cache entry structure
+ * (A field for the type of service (mfc_tos) is to be added
+ * at a future point)
+ */
+struct mfc {
+ struct in_addr mfc_origin; /* IP origin of mcasts */
+ struct in_addr mfc_mcastgrp; /* multicast group associated*/
+ vifi_t mfc_parent; /* incoming vif */
+ u_char mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
+ u_long mfc_pkt_cnt; /* pkt count for src-grp */
+ u_long mfc_byte_cnt; /* byte count for src-grp */
+ u_long mfc_wrong_if; /* wrong if for src-grp */
+ int mfc_expire; /* time to clean entry up */
+ struct timeval mfc_last_assert; /* last time I sent an assert*/
+};
+
+/*
+ * Struct used to communicate from kernel to multicast router
+ * note the convenient similarity to an IP packet
+ */
+struct igmpmsg {
+ u_long unused1;
+ u_long unused2;
+ u_char im_msgtype; /* what type of message */
+#define IGMPMSG_NOCACHE 1
+#define IGMPMSG_WRONGVIF 2
+ u_char im_mbz; /* must be zero */
+ u_char im_vif; /* vif rec'd on */
+ u_char unused3;
+ struct in_addr im_src, im_dst;
+};
+
+/*
+ * Argument structure used for pkt info. while upcall is made
+ */
+struct rtdetq {
+ struct mbuf *m; /* A copy of the packet */
+ struct ifnet *ifp; /* Interface pkt came in on */
+ vifi_t xmt_vif; /* Saved copy of imo_multicast_vif */
+#ifdef UPCALL_TIMING
+ struct timeval t; /* Timestamp */
+#endif /* UPCALL_TIMING */
+};
+
+#define MFCTBLSIZ 256
+#if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0 /* from sys:route.h */
+#define MFCHASHMOD(h) ((h) & (MFCTBLSIZ - 1))
+#else
+#define MFCHASHMOD(h) ((h) % MFCTBLSIZ)
+#endif
+
+#define MAX_UPQ 4 /* max. no of pkts in upcall Q */
+
+/*
+ * Token Bucket filter code
+ */
+#define MAX_BKT_SIZE 10000 /* 10K bytes size */
+#define MAXQSIZE 10 /* max # of pkts in queue */
+
+/*
+ * the token bucket filter at each vif
+ */
+struct tbf
+{
+ struct timeval tbf_last_pkt_t; /* arr. time of last pkt */
+ u_long tbf_n_tok; /* no of tokens in bucket */
+ u_long tbf_q_len; /* length of queue at this vif */
+ u_long tbf_max_q_len; /* max. queue length */
+ struct mbuf *tbf_q; /* Packet queue */
+ struct mbuf *tbf_t; /* tail-insertion pointer */
+};
+
+#ifdef _KERNEL
+
+extern int (*ip_mrouter_set)(int, struct socket *, struct mbuf *);
+extern int (*ip_mrouter_get)(int, struct socket *, struct mbuf **);
+extern int (*ip_mrouter_done)(void);
+#ifdef MROUTING
+extern int (*mrt_ioctl)(int, caddr_t);
+#else
+extern int (*mrt_ioctl)(int, caddr_t, struct proc *);
+#endif
+
+#endif /* _KERNEL */
+
+#endif /* _NETINET_IP_MROUTE_H_ */
diff --git a/cpukit/libnetworking/netinet/ip_output.c b/cpukit/libnetworking/netinet/ip_output.c
new file mode 100644
index 0000000000..510f9d046b
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_output.c
@@ -0,0 +1,1327 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
+ * $FreeBSD: src/sys/netinet/ip_output.c,v 1.271 2007/03/23 09:43:36 bms Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _IP_VHL
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <errno.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
+
+#include <machine/in_cksum.h>
+
+#if !defined(COMPAT_IPFW) || COMPAT_IPFW == 1
+#undef COMPAT_IPFW
+#define COMPAT_IPFW 1
+#else
+#undef COMPAT_IPFW
+#endif
+
+u_short ip_id;
+
+static struct mbuf *ip_insertoptions(struct mbuf *, struct mbuf *, int *);
+static void ip_mloopback
+ (struct ifnet *, struct mbuf *, struct sockaddr_in *, int);
+static int ip_getmoptions
+ (int, struct ip_moptions *, struct mbuf **);
+static int ip_optcopy(struct ip *, struct ip *);
+static int ip_pcbopts(struct mbuf **, struct mbuf *);
+static int ip_setmoptions
+ (int, struct ip_moptions **, struct mbuf *);
+
+extern struct protosw inetsw[];
+
+/*
+ * IP output. The packet in mbuf chain m contains a skeletal IP
+ * header (with len, off, ttl, proto, tos, src, dst).
+ * The mbuf chain containing the packet will be freed.
+ * The mbuf opt, if present, will not be freed.
+ */
+int
+ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, int flags,
+ struct ip_moptions *imo)
+{
+ struct ip *ip, *mhip;
+ struct ifnet *ifp;
+ struct mbuf *m = m0;
+ int hlen = sizeof (struct ip);
+ int len = 0, off, error = 0;
+ struct sockaddr_in *dst;
+ struct in_ifaddr *ia;
+ int isbroadcast;
+
+#ifdef DIAGNOSTIC
+ if ((m->m_flags & M_PKTHDR) == 0)
+ panic("ip_output no HDR");
+ if (!ro)
+ panic("ip_output no route, proto = %d",
+ mtod(m, struct ip *)->ip_p);
+#endif
+ if (opt) {
+ m = ip_insertoptions(m, opt, &len);
+ hlen = len;
+ }
+ ip = mtod(m, struct ip *);
+ /*
+ * Fill in IP header.
+ */
+ if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) {
+#ifdef _IP_VHL
+ ip->ip_vhl = IP_MAKE_VHL(IPVERSION, hlen >> 2);
+#else
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = hlen >> 2;
+#endif
+ ip->ip_off &= IP_DF;
+ ip->ip_id = htons(ip_id++);
+ ipstat.ips_localout++;
+ } else {
+#ifdef _IP_VHL
+ hlen = IP_VHL_HL(ip->ip_vhl) << 2;
+#else
+ hlen = ip->ip_hl << 2;
+#endif
+ }
+
+ dst = (struct sockaddr_in *)&ro->ro_dst;
+ /*
+ * If there is a cached route,
+ * check that it is to the same destination
+ * and is still up. If not, free it and try again.
+ */
+ if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 ||
+ dst->sin_addr.s_addr != ip->ip_dst.s_addr)) {
+ RTFREE(ro->ro_rt);
+ ro->ro_rt = (struct rtentry *)0;
+ }
+ if (ro->ro_rt == NULL) {
+ dst->sin_family = AF_INET;
+ dst->sin_len = sizeof(*dst);
+ dst->sin_addr = ip->ip_dst;
+ }
+ /*
+ * If routing to interface only,
+ * short circuit routing lookup.
+ */
+#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
+#define sintosa(sin) ((struct sockaddr *)(sin))
+ if (flags & IP_ROUTETOIF) {
+ if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
+ (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) {
+ ipstat.ips_noroute++;
+ error = ENETUNREACH;
+ goto bad;
+ }
+ ifp = ia->ia_ifp;
+ ip->ip_ttl = 1;
+ isbroadcast = in_broadcast(dst->sin_addr, ifp);
+ } else {
+ /*
+ * If this is the case, we probably don't want to allocate
+ * a protocol-cloned route since we didn't get one from the
+ * ULP. This lets TCP do its thing, while not burdening
+ * forwarding or ICMP with the overhead of cloning a route.
+ * Of course, we still want to do any cloning requested by
+ * the link layer, as this is probably required in all cases
+ * for correct operation (as it is for ARP).
+ */
+ if (ro->ro_rt == 0)
+ rtalloc_ign(ro, RTF_PRCLONING);
+ if (ro->ro_rt == 0) {
+ ipstat.ips_noroute++;
+ error = EHOSTUNREACH;
+ goto bad;
+ }
+ ia = ifatoia(ro->ro_rt->rt_ifa);
+ ifp = ro->ro_rt->rt_ifp;
+ ro->ro_rt->rt_use++;
+ if (ro->ro_rt->rt_flags & RTF_GATEWAY)
+ dst = (struct sockaddr_in *)ro->ro_rt->rt_gateway;
+ if (ro->ro_rt->rt_flags & RTF_HOST)
+ isbroadcast = (ro->ro_rt->rt_flags & RTF_BROADCAST);
+ else
+ isbroadcast = in_broadcast(dst->sin_addr, ifp);
+ }
+ if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
+ struct in_multi *inm;
+
+ m->m_flags |= M_MCAST;
+ /*
+ * IP destination address is multicast. Make sure "dst"
+ * still points to the address in "ro". (It may have been
+ * changed to point to a gateway address, above.)
+ */
+ dst = (struct sockaddr_in *)&ro->ro_dst;
+ /*
+ * See if the caller provided any multicast options
+ */
+ if (imo != NULL) {
+ ip->ip_ttl = imo->imo_multicast_ttl;
+ if (imo->imo_multicast_ifp != NULL)
+ ifp = imo->imo_multicast_ifp;
+ if (imo->imo_multicast_vif != -1)
+ ip->ip_src.s_addr =
+ ip_mcast_src(imo->imo_multicast_vif);
+ } else
+ ip->ip_ttl = IP_DEFAULT_MULTICAST_TTL;
+ /*
+ * Confirm that the outgoing interface supports multicast.
+ */
+ if ((imo == NULL) || (imo->imo_multicast_vif == -1)) {
+ if ((ifp->if_flags & IFF_MULTICAST) == 0) {
+ ipstat.ips_noroute++;
+ error = ENETUNREACH;
+ goto bad;
+ }
+ }
+ /*
+ * If source address not specified yet, use address
+ * of outgoing interface.
+ */
+ if (ip->ip_src.s_addr == INADDR_ANY) {
+ register struct in_ifaddr *ia;
+
+ for (ia = in_ifaddr; ia; ia = ia->ia_next)
+ if (ia->ia_ifp == ifp) {
+ ip->ip_src = IA_SIN(ia)->sin_addr;
+ break;
+ }
+ }
+
+ IN_LOOKUP_MULTI(ip->ip_dst, ifp, inm);
+ if (inm != NULL &&
+ (imo == NULL || imo->imo_multicast_loop)) {
+ /*
+ * If we belong to the destination multicast group
+ * on the outgoing interface, and the caller did not
+ * forbid loopback, loop back a copy.
+ */
+ ip_mloopback(ifp, m, dst, hlen);
+ }
+ else {
+ /*
+ * If we are acting as a multicast router, perform
+ * multicast forwarding as if the packet had just
+ * arrived on the interface to which we are about
+ * to send. The multicast forwarding function
+ * recursively calls this function, using the
+ * IP_FORWARDING flag to prevent infinite recursion.
+ *
+ * Multicasts that are looped back by ip_mloopback(),
+ * above, will be forwarded by the ip_input() routine,
+ * if necessary.
+ */
+ if (ip_mrouter && (flags & IP_FORWARDING) == 0) {
+ /*
+ * Check if rsvp daemon is running. If not, don't
+ * set ip_moptions. This ensures that the packet
+ * is multicast and not just sent down one link
+ * as prescribed by rsvpd.
+ */
+ if (!rsvp_on)
+ imo = NULL;
+ if (ip_mforward(ip, ifp, m, imo) != 0) {
+ m_freem(m);
+ goto done;
+ }
+ }
+ }
+
+ /*
+ * Multicasts with a time-to-live of zero may be looped-
+ * back, above, but must not be transmitted on a network.
+ * Also, multicasts addressed to the loopback interface
+ * are not sent -- the above call to ip_mloopback() will
+ * loop back a copy if this host actually belongs to the
+ * destination group on the loopback interface.
+ */
+ if (ip->ip_ttl == 0 || ifp->if_flags & IFF_LOOPBACK) {
+ m_freem(m);
+ goto done;
+ }
+
+ goto sendit;
+ }
+#ifndef notdef
+ /*
+ * If source address not specified yet, use address
+ * of outgoing interface.
+ */
+ if (ip->ip_src.s_addr == INADDR_ANY)
+ ip->ip_src = IA_SIN(ia)->sin_addr;
+#endif
+ /*
+ * Verify that we have any chance at all of being able to queue
+ * the packet or packet fragments
+ */
+ if ((ifp->if_snd.ifq_len + ip->ip_len / ifp->if_mtu + 1) >=
+ ifp->if_snd.ifq_maxlen) {
+ error = ENOBUFS;
+ goto bad;
+ }
+
+ /*
+ * Look for broadcast address and
+ * verify user is allowed to send
+ * such a packet.
+ */
+ if (isbroadcast) {
+ if ((ifp->if_flags & IFF_BROADCAST) == 0) {
+ error = EADDRNOTAVAIL;
+ goto bad;
+ }
+ if ((flags & IP_ALLOWBROADCAST) == 0) {
+ error = EACCES;
+ goto bad;
+ }
+ /* don't allow broadcast messages to be fragmented */
+ if (ip->ip_len > ifp->if_mtu) {
+ error = EMSGSIZE;
+ goto bad;
+ }
+ m->m_flags |= M_BCAST;
+ } else {
+ m->m_flags &= ~M_BCAST;
+ }
+
+sendit:
+ /*
+ * IpHack's section.
+ * - Xlate: translate packet's addr/port (NAT).
+ * - Firewall: deny/allow/etc.
+ * - Wrap: fake packet's addr/port <unimpl.>
+ * - Encapsulate: put it in another IP and send out. <unimp.>
+ */
+
+#ifdef COMPAT_IPFW
+ if (ip_nat_ptr && !(*ip_nat_ptr)(&ip, &m, ifp, IP_NAT_OUT)) {
+ error = EACCES;
+ goto done;
+ }
+
+ /*
+ * Check with the firewall...
+ */
+ if (ip_fw_chk_ptr) {
+#ifdef IPDIVERT
+ ip_divert_port = (*ip_fw_chk_ptr)(&ip,
+ hlen, ifp, ip_divert_ignore, &m);
+ ip_divert_ignore = 0;
+ if (ip_divert_port) { /* Divert packet */
+ (*inetsw[ip_protox[IPPROTO_DIVERT]].pr_input)(m, 0);
+ goto done;
+ }
+#else
+ /* If ipfw says divert, we have to just drop packet */
+ if ((*ip_fw_chk_ptr)(&ip, hlen, ifp, 0, &m)) {
+ m_freem(m);
+ goto done;
+ }
+#endif
+ if (!m) {
+ error = EACCES;
+ goto done;
+ }
+ }
+#endif /* COMPAT_IPFW */
+
+ /*
+ * If small enough for interface, or the interface will take
+ * care of the fragmentation for us, we can just send directly.
+ */
+ if ((u_short)ip->ip_len <= ifp->if_mtu) {
+ ip->ip_len = htons(ip->ip_len);
+ ip->ip_off = htons(ip->ip_off);
+ ip->ip_sum = 0;
+#ifdef _IP_VHL
+ if (ip->ip_vhl == IP_VHL_BORING) {
+#else
+ if ((ip->ip_hl == 5) && (ip->ip_v = IPVERSION)) {
+#endif
+ ip->ip_sum = in_cksum_hdr(ip);
+ } else {
+ ip->ip_sum = in_cksum(m, hlen);
+ }
+ error = (*ifp->if_output)(ifp, m,
+ (struct sockaddr *)dst, ro->ro_rt);
+ goto done;
+ }
+ /*
+ * Too large for interface; fragment if possible.
+ * Must be able to put at least 8 bytes per fragment.
+ */
+ if (ip->ip_off & IP_DF) {
+ error = EMSGSIZE;
+ /*
+ * This case can happen if the user changed the MTU
+ * of an interface after enabling IP on it. Because
+ * most netifs don't keep track of routes pointing to
+ * them, there is no way for one to update all its
+ * routes when the MTU is changed.
+ */
+ if ((ro->ro_rt->rt_flags & (RTF_UP | RTF_HOST))
+ && !(ro->ro_rt->rt_rmx.rmx_locks & RTV_MTU)
+ && (ro->ro_rt->rt_rmx.rmx_mtu > ifp->if_mtu)) {
+ ro->ro_rt->rt_rmx.rmx_mtu = ifp->if_mtu;
+ }
+ ipstat.ips_cantfrag++;
+ goto bad;
+ }
+ len = (ifp->if_mtu - hlen) &~ 7;
+ if (len < 8) {
+ error = EMSGSIZE;
+ goto bad;
+ }
+
+ {
+ int mhlen, firstlen = len;
+ struct mbuf **mnext = &m->m_nextpkt;
+
+ /*
+ * Loop through length of segment after first fragment,
+ * make new header and copy data of each part and link onto chain.
+ */
+ m0 = m;
+ mhlen = sizeof (struct ip);
+ for (off = hlen + len; off < (u_short)ip->ip_len; off += len) {
+ MGETHDR(m, M_DONTWAIT, MT_HEADER);
+ if (m == 0) {
+ error = ENOBUFS;
+ ipstat.ips_odropped++;
+ goto sendorfree;
+ }
+ m->m_flags |= (m0->m_flags & M_MCAST);
+ m->m_data += max_linkhdr;
+ mhip = mtod(m, struct ip *);
+ *mhip = *ip;
+ if (hlen > sizeof (struct ip)) {
+ mhlen = ip_optcopy(ip, mhip) + sizeof (struct ip);
+#ifdef _IP_VHL
+ mhip->ip_vhl = IP_MAKE_VHL(IPVERSION, mhlen >> 2);
+#else
+ mhip->ip_v = IPVERSION;
+ mhip->ip_hl = mhlen >> 2;
+#endif
+ }
+ m->m_len = mhlen;
+ mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF);
+ if (ip->ip_off & IP_MF)
+ mhip->ip_off |= IP_MF;
+ if (off + len >= (u_short)ip->ip_len)
+ len = (u_short)ip->ip_len - off;
+ else
+ mhip->ip_off |= IP_MF;
+ mhip->ip_len = htons((u_short)(len + mhlen));
+ m->m_next = m_copy(m0, off, len);
+ if (m->m_next == 0) {
+ (void) m_free(m);
+ error = ENOBUFS; /* ??? */
+ ipstat.ips_odropped++;
+ goto sendorfree;
+ }
+ m->m_pkthdr.len = mhlen + len;
+ m->m_pkthdr.rcvif = NULL;
+ mhip->ip_off = htons(mhip->ip_off);
+ mhip->ip_sum = 0;
+#ifdef _IP_VHL
+ if (mhip->ip_vhl == IP_VHL_BORING) {
+#else
+ if ((mhip->ip_hl == 5) && (mhip->ip_v == IPVERSION) ) {
+#endif
+ mhip->ip_sum = in_cksum_hdr(mhip);
+ } else {
+ mhip->ip_sum = in_cksum(m, mhlen);
+ }
+ *mnext = m;
+ mnext = &m->m_nextpkt;
+ ipstat.ips_ofragments++;
+ }
+ /*
+ * Update first fragment by trimming what's been copied out
+ * and updating header, then send each fragment (in order).
+ */
+ m = m0;
+ m_adj(m, hlen + firstlen - (u_short)ip->ip_len);
+ m->m_pkthdr.len = hlen + firstlen;
+ ip->ip_len = htons((u_short)m->m_pkthdr.len);
+ ip->ip_off |= IP_MF;
+ ip->ip_off = htons(ip->ip_off);
+ ip->ip_sum = 0;
+#ifdef _IP_VHL
+ if (ip->ip_vhl == IP_VHL_BORING) {
+#else
+ if ((ip->ip_hl == 5) && (ip->ip_v == IPVERSION) ) {
+#endif
+ ip->ip_sum = in_cksum_hdr(ip);
+ } else {
+ ip->ip_sum = in_cksum(m, hlen);
+ }
+sendorfree:
+ for (m = m0; m; m = m0) {
+ m0 = m->m_nextpkt;
+ m->m_nextpkt = 0;
+ if (error == 0)
+ error = (*ifp->if_output)(ifp, m,
+ (struct sockaddr *)dst, ro->ro_rt);
+ else
+ m_freem(m);
+ }
+
+ if (error == 0)
+ ipstat.ips_fragmented++;
+ }
+done:
+ return (error);
+bad:
+ m_freem(m0);
+ goto done;
+}
+
+/*
+ * Insert IP options into preformed packet.
+ * Adjust IP destination as required for IP source routing,
+ * as indicated by a non-zero in_addr at the start of the options.
+ *
+ * XXX This routine assumes that the packet has no options in place.
+ */
+static struct mbuf *
+ip_insertoptions(struct mbuf *m, struct mbuf *opt, int *phlen)
+{
+ register struct ipoption *p = mtod(opt, struct ipoption *);
+ struct mbuf *n;
+ register struct ip *ip = mtod(m, struct ip *);
+ uint32_t optlen;
+
+ optlen = opt->m_len - sizeof(p->ipopt_dst);
+ if (optlen + ip->ip_len > IP_MAXPACKET)
+ return (m); /* XXX should fail */
+ if (p->ipopt_dst.s_addr)
+ ip->ip_dst = p->ipopt_dst;
+ if (m->m_flags & M_EXT || m->m_data - optlen < m->m_pktdat) {
+ MGETHDR(n, M_DONTWAIT, MT_HEADER);
+ if (n == 0)
+ return (m);
+ n->m_pkthdr.len = m->m_pkthdr.len + optlen;
+ m->m_len -= sizeof(struct ip);
+ m->m_data += sizeof(struct ip);
+ n->m_next = m;
+ m = n;
+ m->m_len = optlen + sizeof(struct ip);
+ m->m_data += max_linkhdr;
+ (void)memcpy(mtod(m, void *), ip, sizeof(struct ip));
+ } else {
+ m->m_data -= optlen;
+ m->m_len += optlen;
+ m->m_pkthdr.len += optlen;
+ ovbcopy((caddr_t)ip, mtod(m, caddr_t), sizeof(struct ip));
+ }
+ ip = mtod(m, struct ip *);
+ bcopy(p->ipopt_list, ip + 1, optlen);
+ *phlen = sizeof(struct ip) + optlen;
+#ifdef _IP_VHL
+ ip->ip_vhl = IP_MAKE_VHL(IPVERSION, *phlen >> 2);
+#else
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = *phlen >> 2;
+#endif
+ ip->ip_len += optlen;
+ return (m);
+}
+
+/*
+ * Copy options from ip to jp,
+ * omitting those not copied during fragmentation.
+ */
+static int
+ip_optcopy(struct ip *ip, struct ip *jp)
+{
+ register u_char *cp, *dp;
+ int opt, optlen, cnt;
+
+ cp = (u_char *)(ip + 1);
+ dp = (u_char *)(jp + 1);
+#ifdef _IP_VHL
+ cnt = (IP_VHL_HL(ip->ip_vhl) << 2) - sizeof (struct ip);
+#else
+ cnt = (ip->ip_hl << 2) - sizeof (struct ip);
+#endif
+ for (; cnt > 0; cnt -= optlen, cp += optlen) {
+ opt = cp[0];
+ if (opt == IPOPT_EOL)
+ break;
+ if (opt == IPOPT_NOP) {
+ /* Preserve for IP mcast tunnel's LSRR alignment. */
+ *dp++ = IPOPT_NOP;
+ optlen = 1;
+ continue;
+ } else
+ optlen = cp[IPOPT_OLEN];
+ /* bogus lengths should have been caught by ip_dooptions */
+ if (optlen > cnt)
+ optlen = cnt;
+ if (IPOPT_COPIED(opt)) {
+ bcopy(cp, dp, optlen);
+ dp += optlen;
+ }
+ }
+ for (optlen = dp - (u_char *)(jp+1); optlen & 0x3; optlen++)
+ *dp++ = IPOPT_EOL;
+ return (optlen);
+}
+
+/*
+ * IP socket option processing.
+ */
+int
+ip_ctloutput(int op, struct socket *so, int level, int optname,
+ struct mbuf **mp)
+{
+ struct inpcb *inp = sotoinpcb(so);
+ register struct mbuf *m = *mp;
+ register int optval = 0;
+ int error = 0;
+
+ if (level != IPPROTO_IP) {
+ error = EINVAL;
+ if (op == PRCO_SETOPT && *mp)
+ (void) m_free(*mp);
+ } else switch (op) {
+
+ case PRCO_SETOPT:
+ switch (optname) {
+ case IP_OPTIONS:
+#ifdef notyet
+ case IP_RETOPTS:
+ return (ip_pcbopts(optname, &inp->inp_options, m));
+#else
+ return (ip_pcbopts(&inp->inp_options, m));
+#endif
+
+ case IP_TOS:
+ case IP_TTL:
+ case IP_RECVOPTS:
+ case IP_RECVRETOPTS:
+ case IP_RECVDSTADDR:
+ case IP_RECVIF:
+ if (m == 0 || m->m_len != sizeof(int))
+ error = EINVAL;
+ else {
+ optval = *mtod(m, int *);
+ switch (optname) {
+
+ case IP_TOS:
+ inp->inp_ip_tos = optval;
+ break;
+
+ case IP_TTL:
+ inp->inp_ip_ttl = optval;
+ break;
+#define OPTSET(bit) \
+ if (optval) \
+ inp->inp_flags |= bit; \
+ else \
+ inp->inp_flags &= ~bit;
+
+ case IP_RECVOPTS:
+ OPTSET(INP_RECVOPTS);
+ break;
+
+ case IP_RECVRETOPTS:
+ OPTSET(INP_RECVRETOPTS);
+ break;
+
+ case IP_RECVDSTADDR:
+ OPTSET(INP_RECVDSTADDR);
+ break;
+
+ case IP_RECVIF:
+ OPTSET(INP_RECVIF);
+ break;
+ }
+ }
+ break;
+#undef OPTSET
+
+ case IP_MULTICAST_IF:
+ case IP_MULTICAST_VIF:
+ case IP_MULTICAST_TTL:
+ case IP_MULTICAST_LOOP:
+ case IP_ADD_MEMBERSHIP:
+ case IP_DROP_MEMBERSHIP:
+ error = ip_setmoptions(optname, &inp->inp_moptions, m);
+ break;
+
+ case IP_PORTRANGE:
+ if (m == 0 || m->m_len != sizeof(int))
+ error = EINVAL;
+ else {
+ optval = *mtod(m, int *);
+
+ switch (optval) {
+
+ case IP_PORTRANGE_DEFAULT:
+ inp->inp_flags &= ~(INP_LOWPORT);
+ inp->inp_flags &= ~(INP_HIGHPORT);
+ break;
+
+ case IP_PORTRANGE_HIGH:
+ inp->inp_flags &= ~(INP_LOWPORT);
+ inp->inp_flags |= INP_HIGHPORT;
+ break;
+
+ case IP_PORTRANGE_LOW:
+ inp->inp_flags &= ~(INP_HIGHPORT);
+ inp->inp_flags |= INP_LOWPORT;
+ break;
+
+ default:
+ error = EINVAL;
+ break;
+ }
+ }
+ break;
+
+ default:
+ error = ENOPROTOOPT;
+ break;
+ }
+ if (m)
+ (void)m_free(m);
+ break;
+
+ case PRCO_GETOPT:
+ switch (optname) {
+ case IP_OPTIONS:
+ case IP_RETOPTS:
+ *mp = m = m_get(M_WAIT, MT_SOOPTS);
+ if (inp->inp_options) {
+ m->m_len = inp->inp_options->m_len;
+ bcopy(mtod(inp->inp_options, void *),
+ mtod(m, void *), m->m_len);
+ } else
+ m->m_len = 0;
+ break;
+
+ case IP_TOS:
+ case IP_TTL:
+ case IP_RECVOPTS:
+ case IP_RECVRETOPTS:
+ case IP_RECVDSTADDR:
+ case IP_RECVIF:
+ *mp = m = m_get(M_WAIT, MT_SOOPTS);
+ m->m_len = sizeof(int);
+ switch (optname) {
+
+ case IP_TOS:
+ optval = inp->inp_ip_tos;
+ break;
+
+ case IP_TTL:
+ optval = inp->inp_ip_ttl;
+ break;
+
+#define OPTBIT(bit) (inp->inp_flags & bit ? 1 : 0)
+
+ case IP_RECVOPTS:
+ optval = OPTBIT(INP_RECVOPTS);
+ break;
+
+ case IP_RECVRETOPTS:
+ optval = OPTBIT(INP_RECVRETOPTS);
+ break;
+
+ case IP_RECVDSTADDR:
+ optval = OPTBIT(INP_RECVDSTADDR);
+ break;
+
+ case IP_RECVIF:
+ optval = OPTBIT(INP_RECVIF);
+ break;
+ }
+ *mtod(m, int *) = optval;
+ break;
+
+ case IP_MULTICAST_IF:
+ case IP_MULTICAST_VIF:
+ case IP_MULTICAST_TTL:
+ case IP_MULTICAST_LOOP:
+ case IP_ADD_MEMBERSHIP:
+ case IP_DROP_MEMBERSHIP:
+ error = ip_getmoptions(optname, inp->inp_moptions, mp);
+ break;
+
+ case IP_PORTRANGE:
+ *mp = m = m_get(M_WAIT, MT_SOOPTS);
+ m->m_len = sizeof(int);
+
+ if (inp->inp_flags & INP_HIGHPORT)
+ optval = IP_PORTRANGE_HIGH;
+ else if (inp->inp_flags & INP_LOWPORT)
+ optval = IP_PORTRANGE_LOW;
+ else
+ optval = 0;
+
+ *mtod(m, int *) = optval;
+ break;
+
+ default:
+ error = ENOPROTOOPT;
+ break;
+ }
+ break;
+ }
+ return (error);
+}
+
+/*
+ * Set up IP options in pcb for insertion in output packets.
+ * Store in mbuf with pointer in pcbopt, adding pseudo-option
+ * with destination address if source routed.
+ */
+static int
+#ifdef notyet
+ip_pcbopts(int optname, struct mbuf **pcbopt, struct mbuf *m)
+#else
+ip_pcbopts(struct mbuf **pcbopt, struct mbuf *m)
+#endif
+{
+ register int cnt, optlen;
+ register u_char *cp;
+ u_char opt;
+
+ /* turn off any old options */
+ if (*pcbopt)
+ (void)m_free(*pcbopt);
+ *pcbopt = 0;
+ if (m == (struct mbuf *)0 || m->m_len == 0) {
+ /*
+ * Only turning off any previous options.
+ */
+ if (m)
+ (void)m_free(m);
+ return (0);
+ }
+
+#ifndef vax
+ if (m->m_len % sizeof(long))
+ goto bad;
+#endif
+ /*
+ * IP first-hop destination address will be stored before
+ * actual options; move other options back
+ * and clear it when none present.
+ */
+ if (m->m_data + m->m_len + sizeof(struct in_addr) >= &m->m_dat[MLEN])
+ goto bad;
+ cnt = m->m_len;
+ m->m_len += sizeof(struct in_addr);
+ cp = mtod(m, u_char *) + sizeof(struct in_addr);
+ ovbcopy(mtod(m, caddr_t), (caddr_t)cp, (unsigned)cnt);
+ bzero(mtod(m, caddr_t), sizeof(struct in_addr));
+
+ for (; cnt > 0; cnt -= optlen, cp += optlen) {
+ opt = cp[IPOPT_OPTVAL];
+ if (opt == IPOPT_EOL)
+ break;
+ if (opt == IPOPT_NOP)
+ optlen = 1;
+ else {
+ optlen = cp[IPOPT_OLEN];
+ if (optlen <= IPOPT_OLEN || optlen > cnt)
+ goto bad;
+ }
+ switch (opt) {
+
+ default:
+ break;
+
+ case IPOPT_LSRR:
+ case IPOPT_SSRR:
+ /*
+ * user process specifies route as:
+ * ->A->B->C->D
+ * D must be our final destination (but we can't
+ * check that since we may not have connected yet).
+ * A is first hop destination, which doesn't appear in
+ * actual IP option, but is stored before the options.
+ */
+ if (optlen < IPOPT_MINOFF - 1 + sizeof(struct in_addr))
+ goto bad;
+ m->m_len -= sizeof(struct in_addr);
+ cnt -= sizeof(struct in_addr);
+ optlen -= sizeof(struct in_addr);
+ cp[IPOPT_OLEN] = optlen;
+ /*
+ * Move first hop before start of options.
+ */
+ bcopy((caddr_t)&cp[IPOPT_OFFSET+1], mtod(m, caddr_t),
+ sizeof(struct in_addr));
+ /*
+ * Then copy rest of options back
+ * to close up the deleted entry.
+ */
+ ovbcopy((caddr_t)(&cp[IPOPT_OFFSET+1] +
+ sizeof(struct in_addr)),
+ (caddr_t)&cp[IPOPT_OFFSET+1],
+ (unsigned)cnt + sizeof(struct in_addr));
+ break;
+ }
+ }
+ if (m->m_len > MAX_IPOPTLEN + sizeof(struct in_addr))
+ goto bad;
+ *pcbopt = m;
+ return (0);
+
+bad:
+ (void)m_free(m);
+ return (EINVAL);
+}
+
+/*
+ * Set the IP multicast options in response to user setsockopt().
+ */
+static int
+ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m)
+{
+ int error = 0;
+ u_char loop;
+ int i;
+ struct in_addr addr;
+ struct ip_mreq *mreq;
+ struct ifnet *ifp;
+ struct ip_moptions *imo = *imop;
+ struct route ro;
+ register struct sockaddr_in *dst;
+ int s;
+
+ if (imo == NULL) {
+ /*
+ * No multicast option buffer attached to the pcb;
+ * allocate one and initialize to default values.
+ */
+ imo = (struct ip_moptions*)malloc(sizeof(*imo), M_IPMOPTS,
+ M_WAITOK);
+
+ if (imo == NULL)
+ return (ENOBUFS);
+ *imop = imo;
+ imo->imo_multicast_ifp = NULL;
+ imo->imo_multicast_vif = -1;
+ imo->imo_multicast_ttl = IP_DEFAULT_MULTICAST_TTL;
+ imo->imo_multicast_loop = IP_DEFAULT_MULTICAST_LOOP;
+ imo->imo_num_memberships = 0;
+ }
+
+ switch (optname) {
+ /* store an index number for the vif you wanna use in the send */
+ case IP_MULTICAST_VIF:
+ if (!legal_vif_num) {
+ error = EOPNOTSUPP;
+ break;
+ }
+ if (m == NULL || m->m_len != sizeof(int)) {
+ error = EINVAL;
+ break;
+ }
+ i = *(mtod(m, int *));
+ if (!legal_vif_num(i) && (i != -1)) {
+ error = EINVAL;
+ break;
+ }
+ imo->imo_multicast_vif = i;
+ break;
+
+ case IP_MULTICAST_IF:
+ /*
+ * Select the interface for outgoing multicast packets.
+ */
+ if (m == NULL || m->m_len != sizeof(struct in_addr)) {
+ error = EINVAL;
+ break;
+ }
+ addr = *(mtod(m, struct in_addr *));
+ /*
+ * INADDR_ANY is used to remove a previous selection.
+ * When no interface is selected, a default one is
+ * chosen every time a multicast packet is sent.
+ */
+ if (addr.s_addr == INADDR_ANY) {
+ imo->imo_multicast_ifp = NULL;
+ break;
+ }
+ /*
+ * The selected interface is identified by its local
+ * IP address. Find the interface and confirm that
+ * it supports multicasting.
+ */
+ s = splimp();
+ INADDR_TO_IFP(addr, ifp);
+ if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
+ splx(s);
+ error = EADDRNOTAVAIL;
+ break;
+ }
+ imo->imo_multicast_ifp = ifp;
+ splx(s);
+ break;
+
+ case IP_MULTICAST_TTL:
+ /*
+ * Set the IP time-to-live for outgoing multicast packets.
+ */
+ if (m == NULL || m->m_len != 1) {
+ error = EINVAL;
+ break;
+ }
+ imo->imo_multicast_ttl = *(mtod(m, u_char *));
+ break;
+
+ case IP_MULTICAST_LOOP:
+ /*
+ * Set the loopback flag for outgoing multicast packets.
+ * Must be zero or one.
+ */
+ if (m == NULL || m->m_len != 1 ||
+ (loop = *(mtod(m, u_char *))) > 1) {
+ error = EINVAL;
+ break;
+ }
+ imo->imo_multicast_loop = loop;
+ break;
+
+ case IP_ADD_MEMBERSHIP:
+ /*
+ * Add a multicast group membership.
+ * Group must be a valid IP multicast address.
+ */
+ if (m == NULL || m->m_len != sizeof(struct ip_mreq)) {
+ error = EINVAL;
+ break;
+ }
+ mreq = mtod(m, struct ip_mreq *);
+ if (!IN_MULTICAST(ntohl(mreq->imr_multiaddr.s_addr))) {
+ error = EINVAL;
+ break;
+ }
+ s = splimp();
+ /*
+ * If no interface address was provided, use the interface of
+ * the route to the given multicast address.
+ */
+ if (mreq->imr_interface.s_addr == INADDR_ANY) {
+ bzero((caddr_t)&ro, sizeof(ro));
+ dst = (struct sockaddr_in *)&ro.ro_dst;
+ dst->sin_len = sizeof(*dst);
+ dst->sin_family = AF_INET;
+ dst->sin_addr = mreq->imr_multiaddr;
+ rtalloc(&ro);
+ if (ro.ro_rt == NULL) {
+ error = EADDRNOTAVAIL;
+ splx(s);
+ break;
+ }
+ ifp = ro.ro_rt->rt_ifp;
+ rtfree(ro.ro_rt);
+ }
+ else {
+ INADDR_TO_IFP(mreq->imr_interface, ifp);
+ }
+
+ /*
+ * See if we found an interface, and confirm that it
+ * supports multicast.
+ */
+ if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
+ error = EADDRNOTAVAIL;
+ splx(s);
+ break;
+ }
+ /*
+ * See if the membership already exists or if all the
+ * membership slots are full.
+ */
+ for (i = 0; i < imo->imo_num_memberships; ++i) {
+ if (imo->imo_membership[i]->inm_ifp == ifp &&
+ imo->imo_membership[i]->inm_addr.s_addr
+ == mreq->imr_multiaddr.s_addr)
+ break;
+ }
+ if (i < imo->imo_num_memberships) {
+ error = EADDRINUSE;
+ splx(s);
+ break;
+ }
+ if (i == IP_MAX_MEMBERSHIPS) {
+ error = ETOOMANYREFS;
+ splx(s);
+ break;
+ }
+ /*
+ * Everything looks good; add a new record to the multicast
+ * address list for the given interface.
+ */
+ if ((imo->imo_membership[i] =
+ in_addmulti(&mreq->imr_multiaddr, ifp)) == NULL) {
+ error = ENOBUFS;
+ splx(s);
+ break;
+ }
+ ++imo->imo_num_memberships;
+ splx(s);
+ break;
+
+ case IP_DROP_MEMBERSHIP:
+ /*
+ * Drop a multicast group membership.
+ * Group must be a valid IP multicast address.
+ */
+ if (m == NULL || m->m_len != sizeof(struct ip_mreq)) {
+ error = EINVAL;
+ break;
+ }
+ mreq = mtod(m, struct ip_mreq *);
+ if (!IN_MULTICAST(ntohl(mreq->imr_multiaddr.s_addr))) {
+ error = EINVAL;
+ break;
+ }
+
+ s = splimp();
+ /*
+ * If an interface address was specified, get a pointer
+ * to its ifnet structure.
+ */
+ if (mreq->imr_interface.s_addr == INADDR_ANY)
+ ifp = NULL;
+ else {
+ INADDR_TO_IFP(mreq->imr_interface, ifp);
+ if (ifp == NULL) {
+ error = EADDRNOTAVAIL;
+ splx(s);
+ break;
+ }
+ }
+ /*
+ * Find the membership in the membership array.
+ */
+ for (i = 0; i < imo->imo_num_memberships; ++i) {
+ if ((ifp == NULL ||
+ imo->imo_membership[i]->inm_ifp == ifp) &&
+ imo->imo_membership[i]->inm_addr.s_addr ==
+ mreq->imr_multiaddr.s_addr)
+ break;
+ }
+ if (i == imo->imo_num_memberships) {
+ error = EADDRNOTAVAIL;
+ splx(s);
+ break;
+ }
+ /*
+ * Give up the multicast address record to which the
+ * membership points.
+ */
+ in_delmulti(imo->imo_membership[i]);
+ /*
+ * Remove the gap in the membership array.
+ */
+ for (++i; i < imo->imo_num_memberships; ++i)
+ imo->imo_membership[i-1] = imo->imo_membership[i];
+ --imo->imo_num_memberships;
+ splx(s);
+ break;
+
+ default:
+ error = EOPNOTSUPP;
+ break;
+ }
+
+ /*
+ * If all options have default values, no need to keep the mbuf.
+ */
+ if (imo->imo_multicast_ifp == NULL &&
+ imo->imo_multicast_vif == -1 &&
+ imo->imo_multicast_ttl == IP_DEFAULT_MULTICAST_TTL &&
+ imo->imo_multicast_loop == IP_DEFAULT_MULTICAST_LOOP &&
+ imo->imo_num_memberships == 0) {
+ free(*imop, M_IPMOPTS);
+ *imop = NULL;
+ }
+
+ return (error);
+}
+
+/*
+ * Return the IP multicast options in response to user getsockopt().
+ */
+static int
+ip_getmoptions(int optname, struct ip_moptions *imo,
+ struct mbuf **mp)
+{
+ u_char *ttl;
+ u_char *loop;
+ struct in_addr *addr;
+ struct in_ifaddr *ia;
+
+ *mp = m_get(M_WAIT, MT_SOOPTS);
+
+ switch (optname) {
+
+ case IP_MULTICAST_VIF:
+ if (imo != NULL)
+ *(mtod(*mp, int *)) = imo->imo_multicast_vif;
+ else
+ *(mtod(*mp, int *)) = -1;
+ (*mp)->m_len = sizeof(int);
+ return(0);
+
+ case IP_MULTICAST_IF:
+ addr = mtod(*mp, struct in_addr *);
+ (*mp)->m_len = sizeof(struct in_addr);
+ if (imo == NULL || imo->imo_multicast_ifp == NULL)
+ addr->s_addr = INADDR_ANY;
+ else {
+ IFP_TO_IA(imo->imo_multicast_ifp, ia);
+ addr->s_addr = (ia == NULL) ? INADDR_ANY
+ : IA_SIN(ia)->sin_addr.s_addr;
+ }
+ return (0);
+
+ case IP_MULTICAST_TTL:
+ ttl = mtod(*mp, u_char *);
+ (*mp)->m_len = 1;
+ *ttl = (imo == NULL) ? IP_DEFAULT_MULTICAST_TTL
+ : imo->imo_multicast_ttl;
+ return (0);
+
+ case IP_MULTICAST_LOOP:
+ loop = mtod(*mp, u_char *);
+ (*mp)->m_len = 1;
+ *loop = (imo == NULL) ? IP_DEFAULT_MULTICAST_LOOP
+ : imo->imo_multicast_loop;
+ return (0);
+
+ default:
+ return (EOPNOTSUPP);
+ }
+}
+
+/*
+ * Discard the IP multicast options.
+ */
+void
+ip_freemoptions(struct ip_moptions *imo)
+{
+ register int i;
+
+ if (imo != NULL) {
+ for (i = 0; i < imo->imo_num_memberships; ++i)
+ in_delmulti(imo->imo_membership[i]);
+ free(imo, M_IPMOPTS);
+ }
+}
+
+/*
+ * Routine called from ip_output() to loop back a copy of an IP multicast
+ * packet to the input queue of a specified interface. Note that this
+ * calls the output routine of the loopback "driver", but with an interface
+ * pointer that might NOT be a loopback interface -- evil, but easier than
+ * replicating that code here.
+ */
+static void
+ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst,
+ int hlen)
+{
+ register struct ip *ip;
+ struct mbuf *copym;
+
+ copym = m_copy(m, 0, M_COPYALL);
+ if (copym != NULL && (copym->m_flags & M_EXT || copym->m_len < hlen))
+ copym = m_pullup(copym, hlen);
+ if (copym != NULL) {
+ /*
+ * We don't bother to fragment if the IP length is greater
+ * than the interface's MTU. Can this possibly matter?
+ */
+ ip = mtod(copym, struct ip *);
+ ip->ip_len = htons(ip->ip_len);
+ ip->ip_off = htons(ip->ip_off);
+ ip->ip_sum = 0;
+#ifdef _IP_VHL
+ if (ip->ip_vhl == IP_VHL_BORING) {
+ ip->ip_sum = in_cksum_hdr(ip);
+ } else {
+ ip->ip_sum = in_cksum(copym, hlen);
+ }
+#else
+ ip->ip_sum = in_cksum(copym, hlen);
+#endif
+ /*
+ * NB:
+ * It's not clear whether there are any lingering
+ * reentrancy problems in other areas which might
+ * be exposed by using ip_input directly (in
+ * particular, everything which modifies the packet
+ * in-place). Yet another option is using the
+ * protosw directly to deliver the looped back
+ * packet. For the moment, we'll err on the side
+ * of safety by continuing to abuse looutput().
+ */
+#ifdef notdef
+ copym->m_pkthdr.rcvif = ifp;
+ ip_input(copym);
+#else
+ (void) looutput(ifp, copym, (struct sockaddr *)dst, NULL);
+#endif
+ }
+}
diff --git a/cpukit/libnetworking/netinet/ip_var.h b/cpukit/libnetworking/netinet/ip_var.h
new file mode 100644
index 0000000000..6b06a1cd79
--- /dev/null
+++ b/cpukit/libnetworking/netinet/ip_var.h
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/netinet/ip_var.h,v 1.94 2005/01/07 01:45:44 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_IP_VAR_H_
+#define _NETINET_IP_VAR_H_
+
+/*
+ * Overlay for ip header used by other protocols (tcp, udp).
+ */
+struct ipovly {
+ caddr_t ih_next;
+ caddr_t ih_prev; /* for protocol sequence q's */
+ u_char ih_x1; /* (unused) */
+ u_char ih_pr; /* protocol */
+ u_short ih_len; /* protocol length */
+ struct in_addr ih_src; /* source internet address */
+ struct in_addr ih_dst; /* destination internet address */
+};
+
+/*
+ * Ip reassembly queue structure. Each fragment
+ * being reassembled is attached to one of these structures.
+ * They are timed out after ipq_ttl drops to 0, and may also
+ * be reclaimed if memory becomes tight.
+ */
+struct ipq {
+ struct ipq *next,*prev; /* to other reass headers */
+ u_char ipq_ttl; /* time for reass q to live */
+ u_char ipq_p; /* protocol of this fragment */
+ u_short ipq_id; /* sequence id for reassembly */
+ struct ipasfrag *ipq_next,*ipq_prev;
+ /* to ip headers of fragments */
+ struct in_addr ipq_src,ipq_dst;
+#ifdef IPDIVERT
+ u_short ipq_divert; /* divert protocol port */
+#endif
+};
+
+/*
+ * Ip header, when holding a fragment.
+ *
+ * Note: ipf_next must be at same offset as ipq_next above
+ */
+struct ipasfrag {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_char ip_hl:4,
+ ip_v:4;
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ u_char ip_v:4,
+ ip_hl:4;
+#endif
+ u_char ipf_mff; /* XXX overlays ip_tos: use low bit
+ * to avoid destroying tos;
+ * copied from (ip_off&IP_MF) */
+ u_short ip_len;
+ u_short ip_id;
+ u_short ip_off;
+ u_char ip_ttl;
+ u_char ip_p;
+ u_short ip_sum;
+ struct ipasfrag *ipf_next; /* next fragment */
+ struct ipasfrag *ipf_prev; /* previous fragment */
+};
+
+/*
+ * Structure stored in mbuf in inpcb.ip_options
+ * and passed to ip_output when ip options are in use.
+ * The actual length of the options (including ipopt_dst)
+ * is in m_len.
+ */
+#define MAX_IPOPTLEN 40
+
+struct ipoption {
+ struct in_addr ipopt_dst; /* first-hop dst if source routed */
+ char ipopt_list[MAX_IPOPTLEN]; /* options proper */
+};
+
+/*
+ * Structure attached to inpcb.ip_moptions and
+ * passed to ip_output when IP multicast options are in use.
+ */
+struct ip_moptions {
+ struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
+ u_char imo_multicast_ttl; /* TTL for outgoing multicasts */
+ u_char imo_multicast_loop; /* 1 => hear sends if a member */
+ u_short imo_num_memberships; /* no. memberships this socket */
+ struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
+ u_long imo_multicast_vif; /* vif num outgoing multicasts */
+};
+
+struct ipstat {
+ u_long ips_total; /* total packets received */
+ u_long ips_badsum; /* checksum bad */
+ u_long ips_tooshort; /* packet too short */
+ u_long ips_toosmall; /* not enough data */
+ u_long ips_badhlen; /* ip header length < data size */
+ u_long ips_badlen; /* ip length < ip header length */
+ u_long ips_fragments; /* fragments received */
+ u_long ips_fragdropped; /* frags dropped (dups, out of space) */
+ u_long ips_fragtimeout; /* fragments timed out */
+ u_long ips_forward; /* packets forwarded */
+ u_long ips_cantforward; /* packets rcvd for unreachable dest */
+ u_long ips_redirectsent; /* packets forwarded on same net */
+ u_long ips_noproto; /* unknown or unsupported protocol */
+ u_long ips_delivered; /* datagrams delivered to upper level*/
+ u_long ips_localout; /* total ip packets generated here */
+ u_long ips_odropped; /* lost packets due to nobufs, etc. */
+ u_long ips_reassembled; /* total packets reassembled ok */
+ u_long ips_fragmented; /* datagrams successfully fragmented */
+ u_long ips_ofragments; /* output fragments created */
+ u_long ips_cantfrag; /* don't fragment flag was set, etc. */
+ u_long ips_badoptions; /* error in option processing */
+ u_long ips_noroute; /* packets discarded due to no route */
+ u_long ips_badvers; /* ip version != 4 */
+ u_long ips_rawout; /* total raw ip packets generated */
+ u_long ips_toolong; /* ip length > max ip packet size */
+};
+
+#ifdef _KERNEL
+/* flags passed to ip_output as last parameter */
+#define IP_FORWARDING 0x1 /* most of ip header exists */
+#define IP_RAWOUTPUT 0x2 /* raw ip header exists */
+#define IP_SENDONES 0x4 /* send all-ones broadcast */
+#define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */
+#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
+
+struct ip;
+struct inpcb;
+struct route;
+struct sockopt;
+struct mbuf;
+
+extern struct ipstat ipstat;
+extern u_short ip_id; /* ip packet ctr, for ids */
+extern int ip_defttl; /* default IP ttl */
+extern u_char ip_protox[];
+extern struct socket *ip_rsvpd; /* reservation protocol daemon */
+extern struct socket *ip_mrouter; /* multicast routing daemon */
+extern int (*legal_vif_num)(int);
+extern u_long (*ip_mcast_src)(int);
+extern int rsvp_on;
+
+int ip_ctloutput(int, struct socket *, int, int, struct mbuf **);
+void ip_drain(void);
+void ip_freemoptions(struct ip_moptions *);
+void ip_init(void);
+extern int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
+ struct ip_moptions *);
+int ip_output(struct mbuf *,
+ struct mbuf *, struct route *, int, struct ip_moptions *);
+void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
+ struct mbuf *);
+void ip_slowtimo(void);
+struct mbuf *
+ ip_srcroute(void);
+void ip_stripoptions(struct mbuf *, struct mbuf *);
+int rip_ctloutput(int, struct socket *, int, int, struct mbuf **);
+void rip_init(void);
+void rip_input(struct mbuf *, int);
+int rip_output(struct mbuf *, struct socket *, u_long);
+int rip_usrreq(struct socket *,
+ int, struct mbuf *, struct mbuf *, struct mbuf *);
+void ipip_input(struct mbuf *, int);
+void rsvp_input(struct mbuf *, int);
+int ip_rsvp_init(struct socket *);
+int ip_rsvp_done(void);
+int ip_rsvp_vif_init(struct socket *, struct mbuf *);
+int ip_rsvp_vif_done(struct socket *, struct mbuf *);
+void ip_rsvp_force_done(struct socket *);
+
+#ifdef IPDIVERT
+void div_init(void);
+void div_input(struct mbuf *, int);
+int div_usrreq(struct socket *,
+ int, struct mbuf *, struct mbuf *, struct mbuf *);
+extern u_short ip_divert_port;
+extern u_short ip_divert_ignore;
+#endif /* IPDIVERT */
+
+#endif /* _KERNEL */
+
+#endif /* !_NETINET_IP_VAR_H_ */
diff --git a/cpukit/libnetworking/netinet/raw_ip.c b/cpukit/libnetworking/netinet/raw_ip.c
new file mode 100644
index 0000000000..12a05aa6a4
--- /dev/null
+++ b/cpukit/libnetworking/netinet/raw_ip.c
@@ -0,0 +1,492 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95
+ * $FreeBSD: src/sys/netinet/raw_ip.c,v 1.147 2005/01/07 01:45:45 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_inet6.h"
+#include "opt_ipsec.h"
+#include "opt_mac.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/socketvar.h>
+#include <errno.h>
+#include <sys/systm.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#define _IP_VHL
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/ip_mroute.h>
+
+#include <netinet/ip_fw.h>
+
+#if !defined(COMPAT_IPFW) || COMPAT_IPFW == 1
+#undef COMPAT_IPFW
+#define COMPAT_IPFW 1
+#else
+#undef COMPAT_IPFW
+#endif
+
+static struct inpcbhead ripcb;
+static struct inpcbinfo ripcbinfo;
+
+/*
+ * Nominal space allocated to a raw ip socket.
+ */
+#define RIPSNDQ 8192
+#define RIPRCVQ 8192
+
+/*
+ * Raw interface to IP protocol.
+ */
+
+/*
+ * Initialize raw connection block q.
+ */
+void
+rip_init(void)
+{
+ LIST_INIT(&ripcb);
+ ripcbinfo.listhead = &ripcb;
+ /*
+ * XXX We don't use the hash list for raw IP, but it's easier
+ * to allocate a one entry hash list than it is to check all
+ * over the place for hashbase == NULL.
+ */
+ ripcbinfo.hashbase = hashinit(1, M_PCB, &ripcbinfo.hashmask);
+}
+
+static struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET, 0, {0}, {0} };
+/*
+ * Setup generic address and protocol structures
+ * for raw_input routine, then pass them along with
+ * mbuf chain.
+ */
+void
+rip_input(struct mbuf *m, int iphlen)
+{
+ struct ip *ip = mtod(m, struct ip *);
+ register struct inpcb *inp;
+ struct inpcb *last = 0;
+ struct mbuf *opts = 0;
+
+ ripsrc.sin_addr = ip->ip_src;
+ for (inp = ripcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
+ if (inp->inp_ip_p && inp->inp_ip_p != ip->ip_p)
+ continue;
+ if (inp->inp_laddr.s_addr &&
+ inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
+ continue;
+ if (inp->inp_faddr.s_addr &&
+ inp->inp_faddr.s_addr != ip->ip_src.s_addr)
+ continue;
+ if (last) {
+ struct mbuf *n = m_copy(m, 0, (int)M_COPYALL);
+ if (n) {
+ if (last->inp_flags & INP_CONTROLOPTS ||
+ last->inp_socket->so_options & SO_TIMESTAMP)
+ ip_savecontrol(last, &opts, ip, n);
+ if (sbappendaddr(&last->inp_socket->so_rcv,
+ (struct sockaddr *)&ripsrc, n,
+ opts) == 0) {
+ /* should notify about lost packet */
+ m_freem(n);
+ if (opts)
+ m_freem(opts);
+ } else
+ sorwakeup(last->inp_socket);
+ opts = 0;
+ }
+ }
+ last = inp;
+ }
+ if (last) {
+ if (last->inp_flags & INP_CONTROLOPTS ||
+ last->inp_socket->so_options & SO_TIMESTAMP)
+ ip_savecontrol(last, &opts, ip, m);
+ if (sbappendaddr(&last->inp_socket->so_rcv,
+ (struct sockaddr *)&ripsrc, m, opts) == 0) {
+ m_freem(m);
+ if (opts)
+ m_freem(opts);
+ } else
+ sorwakeup(last->inp_socket);
+ } else {
+ m_freem(m);
+ ipstat.ips_noproto++;
+ ipstat.ips_delivered--;
+ }
+}
+
+/*
+ * Generate IP header and pass packet to ip_output.
+ * Tack on options user may have setup with control call.
+ */
+int
+rip_output(struct mbuf *m, struct socket *so, u_long dst)
+{
+ struct ip *ip;
+ struct inpcb *inp = sotoinpcb(so);
+ int flags = ((so->so_options & SO_DONTROUTE) ? IP_ROUTETOIF : 0) |
+ IP_ALLOWBROADCAST;
+
+ /*
+ * If the user handed us a complete IP packet, use it.
+ * Otherwise, allocate an mbuf for a header and fill it in.
+ */
+ if ((inp->inp_flags & INP_HDRINCL) == 0) {
+ if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
+ m_freem(m);
+ return(EMSGSIZE);
+ }
+ M_PREPEND(m, sizeof(struct ip), M_WAIT);
+ ip = mtod(m, struct ip *);
+ ip->ip_tos = 0;
+ ip->ip_off = 0;
+ ip->ip_p = inp->inp_ip_p;
+ ip->ip_len = m->m_pkthdr.len;
+ ip->ip_src = inp->inp_laddr;
+ ip->ip_dst.s_addr = dst;
+ ip->ip_ttl = MAXTTL;
+ } else {
+ if (m->m_pkthdr.len > IP_MAXPACKET) {
+ m_freem(m);
+ return(EMSGSIZE);
+ }
+ ip = mtod(m, struct ip *);
+ /* don't allow both user specified and setsockopt options,
+ and don't allow packet length sizes that will crash */
+#ifdef _IP_VHL
+ if (((IP_VHL_HL(ip->ip_vhl) != (sizeof (*ip) >> 2))
+ && inp->inp_options)
+ || (ip->ip_len > m->m_pkthdr.len)
+ || (ip->ip_len < (IP_VHL_HL(ip->ip_vhl) << 2))) {
+#else
+ if (((ip->ip_hl != (sizeof (*ip) >> 2))
+ && inp->inp_options)
+ || (ip->ip_len > m->m_pkthdr.len)
+ || (ip->ip_len < (ip->ip_hl << 2))) {
+#endif
+ m_freem(m);
+ return EINVAL;
+ }
+ if (ip->ip_id == 0)
+ ip->ip_id = htons(ip_id++);
+ /* XXX prevent ip_output from overwriting header fields */
+ flags |= IP_RAWOUTPUT;
+ ipstat.ips_rawout++;
+ }
+ return (ip_output(m, inp->inp_options, &inp->inp_route, flags,
+ inp->inp_moptions));
+}
+
+/*
+ * Raw IP socket option processing.
+ */
+int
+rip_ctloutput(int op, struct socket *so, int level, int optname,
+ struct mbuf **m)
+{
+ struct inpcb *inp = sotoinpcb(so);
+ int error;
+
+ if (level != IPPROTO_IP) {
+ if (op == PRCO_SETOPT && *m)
+ (void)m_free(*m);
+ return (EINVAL);
+ }
+
+ switch (optname) {
+
+ case IP_HDRINCL:
+ error = 0;
+ if (op == PRCO_SETOPT) {
+ if (m == 0 || *m == 0 || (*m)->m_len < sizeof (int))
+ error = EINVAL;
+ else if (*mtod(*m, int *))
+ inp->inp_flags |= INP_HDRINCL;
+ else
+ inp->inp_flags &= ~INP_HDRINCL;
+ if (*m)
+ (void)m_free(*m);
+ } else {
+ *m = m_get(M_WAIT, MT_SOOPTS);
+ (*m)->m_len = sizeof (int);
+ *mtod(*m, int *) = inp->inp_flags & INP_HDRINCL;
+ }
+ return (error);
+
+#ifdef COMPAT_IPFW
+ case IP_FW_GET:
+ if (ip_fw_ctl_ptr == NULL || op == PRCO_SETOPT) {
+ if (*m) (void)m_free(*m);
+ return(EINVAL);
+ }
+ return (*ip_fw_ctl_ptr)(optname, m);
+
+ case IP_FW_ADD:
+ case IP_FW_DEL:
+ case IP_FW_FLUSH:
+ case IP_FW_ZERO:
+ if (ip_fw_ctl_ptr == NULL || op != PRCO_SETOPT) {
+ if (*m) (void)m_free(*m);
+ return(EINVAL);
+ }
+ return (*ip_fw_ctl_ptr)(optname, m);
+
+ case IP_NAT:
+ if (ip_nat_ctl_ptr == NULL) {
+ if (*m) (void)m_free(*m);
+ return(EINVAL);
+ }
+ return (*ip_nat_ctl_ptr)(op, m);
+
+#endif
+ case IP_RSVP_ON:
+ return ip_rsvp_init(so);
+ break;
+
+ case IP_RSVP_OFF:
+ return ip_rsvp_done();
+ break;
+
+ case IP_RSVP_VIF_ON:
+ return ip_rsvp_vif_init(so, *m);
+
+ case IP_RSVP_VIF_OFF:
+ return ip_rsvp_vif_done(so, *m);
+
+ case MRT_INIT:
+ case MRT_DONE:
+ case MRT_ADD_VIF:
+ case MRT_DEL_VIF:
+ case MRT_ADD_MFC:
+ case MRT_DEL_MFC:
+ case MRT_VERSION:
+ case MRT_ASSERT:
+ if (op == PRCO_SETOPT) {
+ error = ip_mrouter_set(optname, so, *m);
+ if (*m)
+ (void)m_free(*m);
+ } else if (op == PRCO_GETOPT) {
+ error = ip_mrouter_get(optname, so, m);
+ } else
+ error = EINVAL;
+ return (error);
+ }
+ return (ip_ctloutput(op, so, level, optname, m));
+}
+
+static u_long rip_sendspace = RIPSNDQ; /* XXX sysctl ? */
+static u_long rip_recvspace = RIPRCVQ; /* XXX sysctl ? */
+
+/*ARGSUSED*/
+int
+rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
+ struct mbuf *control)
+{
+ register int error = 0;
+ register struct inpcb *inp = sotoinpcb(so);
+ int s;
+
+ if (req == PRU_CONTROL)
+ return (in_control(so, (uintptr_t)m, (caddr_t)nam,
+ (struct ifnet *)control));
+
+ switch (req) {
+
+ case PRU_ATTACH:
+ if (inp)
+ panic("rip_attach");
+ if ((so->so_state & SS_PRIV) == 0) {
+ error = EACCES;
+ break;
+ }
+ s = splnet();
+ error = in_pcballoc(so, &ripcbinfo);
+ splx(s);
+ if (error)
+ break;
+ error = soreserve(so, rip_sendspace, rip_recvspace);
+ if (error)
+ break;
+ inp = (struct inpcb *)so->so_pcb;
+ inp->inp_ip_p = (uintptr_t)nam;
+ break;
+
+ case PRU_DISCONNECT:
+ if ((so->so_state & SS_ISCONNECTED) == 0) {
+ error = ENOTCONN;
+ break;
+ }
+ /* FALLTHROUGH */
+ case PRU_ABORT:
+ soisdisconnected(so);
+ /* FALLTHROUGH */
+ case PRU_DETACH:
+ if (inp == 0)
+ panic("rip_detach");
+ if (so == ip_mrouter)
+ ip_mrouter_done();
+ ip_rsvp_force_done(so);
+ if (so == ip_rsvpd)
+ ip_rsvp_done();
+ in_pcbdetach(inp);
+ break;
+
+ case PRU_BIND:
+ {
+ struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
+
+ if (nam->m_len != sizeof(*addr)) {
+ error = EINVAL;
+ break;
+ }
+ if ((ifnet == 0) ||
+ ((addr->sin_family != AF_INET) &&
+ (addr->sin_family != AF_IMPLINK)) ||
+ (addr->sin_addr.s_addr &&
+ ifa_ifwithaddr((struct sockaddr *)addr) == 0)) {
+ error = EADDRNOTAVAIL;
+ break;
+ }
+ inp->inp_laddr = addr->sin_addr;
+ break;
+ }
+ case PRU_CONNECT:
+ {
+ struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
+
+ if (nam->m_len != sizeof(*addr)) {
+ error = EINVAL;
+ break;
+ }
+ if (ifnet == 0) {
+ error = EADDRNOTAVAIL;
+ break;
+ }
+ if ((addr->sin_family != AF_INET) &&
+ (addr->sin_family != AF_IMPLINK)) {
+ error = EAFNOSUPPORT;
+ break;
+ }
+ inp->inp_faddr = addr->sin_addr;
+ soisconnected(so);
+ break;
+ }
+
+ case PRU_CONNECT2:
+ error = EOPNOTSUPP;
+ break;
+
+ /*
+ * Mark the connection as being incapable of further input.
+ */
+ case PRU_SHUTDOWN:
+ socantsendmore(so);
+ break;
+
+ /*
+ * Ship a packet out. The appropriate raw output
+ * routine handles any massaging necessary.
+ */
+ case PRU_SEND:
+ {
+ register u_long dst;
+
+ if (so->so_state & SS_ISCONNECTED) {
+ if (nam) {
+ error = EISCONN;
+ break;
+ }
+ dst = inp->inp_faddr.s_addr;
+ } else {
+ if (nam == NULL) {
+ error = ENOTCONN;
+ break;
+ }
+ dst = mtod(nam, struct sockaddr_in *)->sin_addr.s_addr;
+ }
+ error = rip_output(m, so, dst);
+ m = NULL;
+ break;
+ }
+
+ case PRU_SENSE:
+ /*
+ * stat: don't bother with a blocksize.
+ */
+ return (0);
+
+ /*
+ * Not supported.
+ */
+ case PRU_RCVOOB:
+ case PRU_RCVD:
+ case PRU_LISTEN:
+ case PRU_ACCEPT:
+ case PRU_SENDOOB:
+ error = EOPNOTSUPP;
+ break;
+
+ case PRU_SOCKADDR:
+ in_setsockaddr(inp, nam);
+ break;
+
+ case PRU_PEERADDR:
+ in_setpeeraddr(inp, nam);
+ break;
+
+ default:
+ panic("rip_usrreq");
+ }
+ if (m != NULL)
+ m_freem(m);
+ return (error);
+}
diff --git a/cpukit/libnetworking/netinet/tcp.h b/cpukit/libnetworking/netinet/tcp.h
new file mode 100644
index 0000000000..9bd4a1454c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/tcp.h,v 1.30 2005/01/07 01:45:45 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_TCP_H_
+#define _NETINET_TCP_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#if __BSD_VISIBLE
+
+typedef u_int32_t tcp_seq;
+
+#define tcp6_seq tcp_seq /* for KAME src sync over BSD*'s */
+#define tcp6hdr tcphdr /* for KAME src sync over BSD*'s */
+
+typedef u_long tcp_cc; /* connection count per rfc1644 */
+
+/*
+ * TCP header.
+ * Per RFC 793, September, 1981.
+ */
+struct tcphdr {
+ u_short th_sport; /* source port */
+ u_short th_dport; /* destination port */
+ tcp_seq th_seq; /* sequence number */
+ tcp_seq th_ack; /* acknowledgement number */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_int th_x2:4, /* (unused) */
+ th_off:4; /* data offset */
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ u_int th_off:4, /* data offset */
+ th_x2:4; /* (unused) */
+#endif
+ u_char th_flags;
+#define TH_FIN 0x01
+#define TH_SYN 0x02
+#define TH_RST 0x04
+#define TH_PUSH 0x08
+#define TH_ACK 0x10
+#define TH_URG 0x20
+#define TH_ECE 0x40
+#define TH_CWR 0x80
+#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
+
+ u_short th_win; /* window */
+ u_short th_sum; /* checksum */
+ u_short th_urp; /* urgent pointer */
+};
+
+#define TCPOPT_EOL 0L
+#define TCPOPT_NOP 1L
+#define TCPOPT_MAXSEG 2L
+#define TCPOLEN_MAXSEG 4L
+#define TCPOPT_WINDOW 3L
+#define TCPOLEN_WINDOW 3L
+#define TCPOPT_SACK_PERMITTED 4L /* Experimental */
+#define TCPOLEN_SACK_PERMITTED 2L
+#define TCPOPT_SACK 5L /* Experimental */
+#define TCPOPT_TIMESTAMP 8L
+#define TCPOLEN_TIMESTAMP 10L
+#define TCPOLEN_TSTAMP_APPA (uint32_t)(TCPOLEN_TIMESTAMP+2) /* appendix A */
+#define TCPOPT_TSTAMP_HDR \
+ (uint32_t)(((uint32_t)TCPOPT_NOP<<24)| \
+ ((uint32_t)TCPOPT_NOP<<16)| \
+ ((uint32_t)TCPOPT_TIMESTAMP<<8)| \
+ ((uint32_t)TCPOLEN_TIMESTAMP))
+
+#define TCPOPT_CC 11 /* CC options: RFC-1644 */
+#define TCPOPT_CCNEW 12
+#define TCPOPT_CCECHO 13
+#define TCPOLEN_CC 6
+#define TCPOLEN_CC_APPA (TCPOLEN_CC+2)
+#define TCPOPT_CC_HDR(ccopt) \
+ (TCPOPT_NOP<<24|TCPOPT_NOP<<16|(ccopt)<<8|TCPOLEN_CC)
+
+/*
+ * Default maximum segment size for TCP.
+ * With an IP MTU of 576, this is 536,
+ * but 512 is probably more convenient.
+ * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
+ */
+#define TCP_MSS 512
+
+#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
+#define TTCP_CLIENT_SND_WND 4096 /* dflt send window for T/TCP client */
+
+#define TCP_MAX_WINSHIFT 14 /* maximum window shift */
+
+#define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */
+#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr))
+ /* max space left for options */
+#endif /* __BSD_VISIBLE */
+
+/*
+ * User-settable options (used with setsockopt).
+ */
+#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
+#if __BSD_VISIBLE
+#define TCP_MAXSEG 0x02 /* set maximum segment size */
+#define TCP_NOPUSH 0x04 /* don't push last block of write */
+#define TCP_NOOPT 0x08 /* don't use TCP options */
+#define TCP_MD5SIG 0x10 /* use MD5 digests (RFC2385) */
+#define TCP_INFO 0x20 /* retrieve tcp_info structure */
+#endif
+
+#endif /* !_NETINET_TCP_H_ */
diff --git a/cpukit/libnetworking/netinet/tcp_debug.c b/cpukit/libnetworking/netinet/tcp_debug.c
new file mode 100644
index 0000000000..779c5fb5c7
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_debug.c
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_debug.c 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/bsd/sys/cdefs.h>
+#include "opt_inet.h"
+#include "opt_tcpdebug.h"
+
+#ifdef TCPDEBUG
+/* load symbolic names */
+#define PRUREQUESTS
+#define TCPSTATES
+#define TCPTIMERS
+#define TANAMES
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#include <netinet/tcp_debug.h>
+
+#ifdef TCPDEBUG
+static int tcpconsdebug = 0;
+#endif
+
+/*
+ * Global ring buffer of TCP debugging state. Each entry captures a snapshot
+ * of TCP connection state at any given moment. tcp_debx addresses at the
+ * next available slot. There is no explicit export of this data structure;
+ * it will be read via /dev/kmem by debugging tools.
+ */
+static struct tcp_debug tcp_debug[TCP_NDEBUG];
+static int tcp_debx;
+
+/*
+ * Save TCP state at a given moment; optionally, both tcpcb and TCP packet
+ * header state will be saved.
+ */
+void
+tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpiphdr *ti,
+ int req)
+{
+#ifdef TCPDEBUG
+ tcp_seq seq, ack;
+ int len, flags;
+#endif
+ struct tcp_debug *td;
+
+ td = &tcp_debug[tcp_debx++];
+ if (tcp_debx == TCP_NDEBUG)
+ tcp_debx = 0;
+ td->td_time = iptime();
+ td->td_act = act;
+ td->td_ostate = ostate;
+ td->td_tcb = (caddr_t)tp;
+ if (tp != NULL)
+ td->td_cb = *tp;
+ else
+ bzero((caddr_t)&td->td_cb, sizeof (*tp));
+ if (ti)
+ td->td_ti = *ti;
+ else
+ bzero((caddr_t)&td->td_ti, sizeof (*ti));
+ td->td_req = req;
+#ifdef TCPDEBUG
+ if (tcpconsdebug == 0)
+ return;
+ if (tp != NULL)
+ printf("%p %s:", tp, tcpstates[ostate]);
+ else
+ printf("???????? ");
+ printf("%s ", tanames[act]);
+ switch (act) {
+ case TA_INPUT:
+ case TA_OUTPUT:
+ case TA_DROP:
+ if (ti == 0)
+ break;
+ seq = ti->ti_seq;
+ ack = ti->ti_ack;
+ len = ti->ti_len;
+ if (act == TA_OUTPUT) {
+ seq = ntohl(seq);
+ ack = ntohl(ack);
+ len = ntohs((u_short)len);
+ }
+ if (act == TA_OUTPUT)
+ len -= sizeof (struct tcphdr);
+ if (len)
+ printf("[%x..%x)", seq, seq+len);
+ else
+ printf("%x", seq);
+ printf("@%x, urp=%x", ack, ti->ti_urp);
+ flags = ti->ti_flags;
+ if (flags) {
+ char *cp = "<";
+#define pf(f) { \
+ if (ti->ti_flags & TH_##f) { \
+ printf("%s%s", cp, #f); \
+ cp = ","; \
+ } \
+}
+ pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
+ printf(">");
+ }
+ break;
+
+ case TA_USER:
+ printf("%s", prurequests[req&0xff]);
+ if ((req & 0xff) == PRU_SLOWTIMO)
+ printf("<%s>", tcptimers[req>>8]);
+ break;
+ }
+ if (tp != NULL)
+ printf(" -> %s", tcpstates[tp->t_state]);
+ /* print out internal state of tp !?! */
+ printf("\n");
+ if (tp == NULL)
+ return;
+ printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
+ tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
+ tp->snd_max);
+ printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
+ tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
+#endif /* TCPDEBUG */
+}
diff --git a/cpukit/libnetworking/netinet/tcp_debug.h b/cpukit/libnetworking/netinet/tcp_debug.h
new file mode 100644
index 0000000000..11a2b003f4
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_debug.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_debug.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/tcp_debug.h,v 1.17 2009/02/13 15:14:43 luigi Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_TCP_DEBUG_H_
+#define _NETINET_TCP_DEBUG_H_
+
+struct tcp_debug {
+ uint32_t td_time; /* network format */
+ short td_act;
+ short td_ostate;
+ caddr_t td_tcb;
+ struct tcpiphdr td_ti;
+ short td_req;
+ struct tcpcb td_cb;
+};
+
+#define TA_INPUT 0
+#define TA_OUTPUT 1
+#define TA_USER 2
+#define TA_RESPOND 3
+#define TA_DROP 4
+
+#ifdef TANAMES
+static const char *tanames[] =
+ { "input", "output", "user", "respond", "drop" };
+#endif
+
+#define TCP_NDEBUG 100
+
+#ifndef _KERNEL
+/* XXX common variables for broken applications. */
+struct tcp_debug tcp_debug[TCP_NDEBUG];
+int tcp_debx;
+#endif
+
+#endif /* !_NETINET_TCP_DEBUG_H_ */
diff --git a/cpukit/libnetworking/netinet/tcp_fsm.h b/cpukit/libnetworking/netinet/tcp_fsm.h
new file mode 100644
index 0000000000..3f2c12f54f
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_fsm.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_fsm.h 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifndef _NETINET_TCP_FSM_H_
+#define _NETINET_TCP_FSM_H_
+
+/*
+ * TCP FSM state definitions.
+ * Per RFC793, September, 1981.
+ */
+
+#define TCP_NSTATES 11
+
+#define TCPS_CLOSED 0 /* closed */
+#define TCPS_LISTEN 1 /* listening for connection */
+#define TCPS_SYN_SENT 2 /* active, have sent syn */
+#define TCPS_SYN_RECEIVED 3 /* have send and received syn */
+/* states < TCPS_ESTABLISHED are those where connections not established */
+#define TCPS_ESTABLISHED 4 /* established */
+#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
+/* states > TCPS_CLOSE_WAIT are those where user has closed */
+#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
+#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
+#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
+/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
+#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
+#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
+
+#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)
+#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
+#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT)
+
+#ifdef TCPOUTFLAGS
+/*
+ * Flags used when sending segments in tcp_output.
+ * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally
+ * determined by state, with the proviso that TH_FIN is sent only
+ * if all data queued for output is included in the segment.
+ */
+static u_char tcp_outflags[TCP_NSTATES] = {
+ TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
+ TH_ACK, TH_ACK,
+ TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK,
+};
+#endif
+
+#ifdef KPROF
+int tcp_acounts[TCP_NSTATES][PRU_NREQ];
+#endif
+
+#ifdef TCPSTATES
+char *tcpstates[] = {
+ "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD",
+ "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING",
+ "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT",
+};
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/netinet/tcp_input.c b/cpukit/libnetworking/netinet/tcp_input.c
new file mode 100644
index 0000000000..6d75c5c841
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_input.c
@@ -0,0 +1,2148 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_tcpdebug.h"
+
+#ifndef TUBA_INCLUDE
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <errno.h>
+#include <sys/syslog.h>
+
+#include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#ifdef TCPDEBUG
+#include <netinet/tcp_debug.h>
+static struct tcpiphdr tcp_saveti;
+#endif
+
+static int tcprexmtthresh = 3;
+tcp_seq tcp_iss;
+tcp_cc tcp_ccgen;
+
+struct tcpstat tcpstat;
+SYSCTL_STRUCT(_net_inet_tcp, TCPCTL_STATS, stats,
+ CTLFLAG_RD, &tcpstat , tcpstat, "");
+
+static int log_in_vain = 0;
+SYSCTL_INT(_net_inet_tcp, OID_AUTO, log_in_vain, CTLFLAG_RW,
+ &log_in_vain, 0, "");
+
+u_long tcp_now;
+struct inpcbhead tcb;
+struct inpcbinfo tcbinfo;
+
+static void tcp_dooptions(struct tcpcb *,
+ u_char *, int, struct tcpiphdr *, struct tcpopt *);
+static void tcp_pulloutofband(struct socket *,
+ struct tcpiphdr *, struct mbuf *);
+static int tcp_reass(struct tcpcb *, struct tcpiphdr *, struct mbuf *);
+static void tcp_xmit_timer(struct tcpcb *, int);
+
+#endif /* TUBA_INCLUDE */
+
+/*
+ * Insert segment ti into reassembly queue of tcp with
+ * control block tp. Return TH_FIN if reassembly now includes
+ * a segment with FIN. The macro form does the common case inline
+ * (segment is the next to be received on an established connection,
+ * and the queue is empty), avoiding linkage into and removal
+ * from the queue and repetition of various conversions.
+ * Set DELACK for segments received in order, but ack immediately
+ * when segments are out of order (so fast retransmit can work).
+ */
+#ifdef TCP_ACK_HACK
+#define TCP_REASS(tp, ti, m, so, flags) { \
+ if ((ti)->ti_seq == (tp)->rcv_nxt && \
+ (tp)->seg_next == (struct tcpiphdr *)(tp) && \
+ (tp)->t_state == TCPS_ESTABLISHED) { \
+ if (ti->ti_flags & TH_PUSH) \
+ tp->t_flags |= TF_ACKNOW; \
+ else \
+ tp->t_flags |= TF_DELACK; \
+ (tp)->rcv_nxt += (ti)->ti_len; \
+ flags = (ti)->ti_flags & TH_FIN; \
+ tcpstat.tcps_rcvpack++;\
+ tcpstat.tcps_rcvbyte += (ti)->ti_len;\
+ sbappend(&(so)->so_rcv, (m)); \
+ sorwakeup(so); \
+ } else { \
+ (flags) = tcp_reass((tp), (ti), (m)); \
+ tp->t_flags |= TF_ACKNOW; \
+ } \
+}
+#else
+#define TCP_REASS(tp, ti, m, so, flags) { \
+ if ((ti)->ti_seq == (tp)->rcv_nxt && \
+ (tp)->seg_next == (struct tcpiphdr *)(tp) && \
+ (tp)->t_state == TCPS_ESTABLISHED) { \
+ tp->t_flags |= TF_DELACK; \
+ (tp)->rcv_nxt += (ti)->ti_len; \
+ flags = (ti)->ti_flags & TH_FIN; \
+ tcpstat.tcps_rcvpack++;\
+ tcpstat.tcps_rcvbyte += (ti)->ti_len;\
+ sbappend(&(so)->so_rcv, (m)); \
+ sorwakeup(so); \
+ } else { \
+ (flags) = tcp_reass((tp), (ti), (m)); \
+ tp->t_flags |= TF_ACKNOW; \
+ } \
+}
+#endif
+#ifndef TUBA_INCLUDE
+
+static int
+tcp_reass(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m)
+{
+ register struct tcpiphdr *q;
+ struct socket *so = tp->t_inpcb->inp_socket;
+ int flags;
+ /*
+ * Call with ti==0 after become established to
+ * force pre-ESTABLISHED data up to user socket.
+ */
+ if (ti == 0)
+ goto present;
+
+ /*
+ * Find a segment which begins after this one does.
+ */
+ for (q = tp->seg_next; q != (struct tcpiphdr *)tp;
+ q = (struct tcpiphdr *)q->ti_next)
+ if (SEQ_GT(q->ti_seq, ti->ti_seq))
+ break;
+
+ /*
+ * If there is a preceding segment, it may provide some of
+ * our data already. If so, drop the data from the incoming
+ * segment. If it provides all of our data, drop us.
+ */
+ if ((struct tcpiphdr *)q->ti_prev != (struct tcpiphdr *)tp) {
+ register int i;
+ q = (struct tcpiphdr *)q->ti_prev;
+ /* conversion to int (in i) handles seq wraparound */
+ i = q->ti_seq + q->ti_len - ti->ti_seq;
+ if (i > 0) {
+ if (i >= ti->ti_len) {
+ tcpstat.tcps_rcvduppack++;
+ tcpstat.tcps_rcvdupbyte += ti->ti_len;
+ m_freem(m);
+ /*
+ * Try to present any queued data
+ * at the left window edge to the user.
+ * This is needed after the 3-WHS
+ * completes.
+ */
+ goto present; /* ??? */
+ }
+ m_adj(m, i);
+ ti->ti_len -= i;
+ ti->ti_seq += i;
+ }
+ q = (struct tcpiphdr *)(q->ti_next);
+ }
+ tcpstat.tcps_rcvoopack++;
+ tcpstat.tcps_rcvoobyte += ti->ti_len;
+#if (defined(__GNUC__) && (defined(__arm__) || defined(__mips__)))
+ STR32_UNALGN(ti,m);
+#else
+ REASS_MBUF(ti) = m; /* XXX */
+#endif
+ /*
+ * While we overlap succeeding segments trim them or,
+ * if they are completely covered, dequeue them.
+ */
+ while (q != (struct tcpiphdr *)tp) {
+ register int i = (ti->ti_seq + ti->ti_len) - q->ti_seq;
+ if (i <= 0)
+ break;
+ if (i < q->ti_len) {
+ q->ti_seq += i;
+ q->ti_len -= i;
+#if (defined(__GNUC__) && (defined(__arm__) || defined(__mips__)))
+ LD32_UNALGN(q,m);
+ m_adj(m, i);
+#else
+ m_adj(REASS_MBUF(q), i);
+#endif
+ break;
+ }
+ q = (struct tcpiphdr *)q->ti_next;
+#if (defined(__GNUC__) && (defined(__arm__) || defined(__mips__)))
+ LD32_UNALGN((struct tcpiphdr *)q->ti_prev,m);
+#else
+ m = REASS_MBUF((struct tcpiphdr *)q->ti_prev);
+#endif
+ remque(q->ti_prev);
+ m_freem(m);
+ }
+
+ /*
+ * Stick new segment in its place.
+ */
+ insque(ti, q->ti_prev);
+
+present:
+ /*
+ * Present data to user, advancing rcv_nxt through
+ * completed sequence space.
+ */
+ if (!TCPS_HAVEESTABLISHED(tp->t_state))
+ return (0);
+ ti = tp->seg_next;
+ if (ti == (struct tcpiphdr *)tp || ti->ti_seq != tp->rcv_nxt)
+ return (0);
+ do {
+ tp->rcv_nxt += ti->ti_len;
+ flags = ti->ti_flags & TH_FIN;
+ remque(ti);
+#if (defined(__GNUC__) && (defined(__arm__) || defined(__mips__)))
+ LD32_UNALGN(ti,m);
+#else
+ m = REASS_MBUF(ti);
+#endif
+ ti = (struct tcpiphdr *)ti->ti_next;
+ if (so->so_state & SS_CANTRCVMORE)
+ m_freem(m);
+ else
+ sbappend(&so->so_rcv, m);
+ } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt);
+ sorwakeup(so);
+ return (flags);
+}
+
+/*
+ * TCP input routine, follows pages 65-76 of the
+ * protocol specification dated September, 1981 very closely.
+ */
+void
+tcp_input(struct mbuf *m, int iphlen)
+{
+ register struct tcpiphdr *ti;
+ register struct inpcb *inp;
+ u_char *optp = NULL;
+ int optlen = 0;
+ int len, tlen, off;
+ register struct tcpcb *tp = 0;
+ register int tiflags;
+ struct socket *so = 0;
+ int todrop, acked, ourfinisacked, needoutput = 0;
+ struct in_addr laddr;
+ int dropsocket = 0;
+ int iss = 0;
+ u_long tiwin;
+ struct tcpopt to; /* options in this segment */
+ struct rmxp_tao *taop; /* pointer to our TAO cache entry */
+ struct rmxp_tao tao_noncached; /* in case there's no cached entry */
+#ifdef TCPDEBUG
+ short ostate = 0;
+#endif
+
+ bzero((char *)&to, sizeof(to));
+
+ tcpstat.tcps_rcvtotal++;
+ /*
+ * Get IP and TCP header together in first mbuf.
+ * Note: IP leaves IP header in first mbuf.
+ */
+ ti = mtod(m, struct tcpiphdr *);
+ if (iphlen > sizeof (struct ip))
+ ip_stripoptions(m, (struct mbuf *)0);
+ if (m->m_len < sizeof (struct tcpiphdr)) {
+ if ((m = m_pullup(m, sizeof (struct tcpiphdr))) == 0) {
+ tcpstat.tcps_rcvshort++;
+ return;
+ }
+ ti = mtod(m, struct tcpiphdr *);
+ }
+
+ /*
+ * Checksum extended TCP header and data.
+ */
+ tlen = ((struct ip *)ti)->ip_len;
+ len = sizeof (struct ip) + tlen;
+ ti->ti_next = ti->ti_prev = 0;
+ ti->ti_x1 = 0;
+ ti->ti_len = (u_short)tlen;
+ HTONS(ti->ti_len);
+ ti->ti_sum = in_cksum(m, len);
+ if (ti->ti_sum) {
+ tcpstat.tcps_rcvbadsum++;
+ goto drop;
+ }
+#endif /* TUBA_INCLUDE */
+
+ /*
+ * Check that TCP offset makes sense,
+ * pull out TCP options and adjust length. XXX
+ */
+ off = ti->ti_off << 2;
+ if (off < sizeof (struct tcphdr) || off > tlen) {
+ tcpstat.tcps_rcvbadoff++;
+ goto drop;
+ }
+ tlen -= off;
+ ti->ti_len = tlen;
+ if (off > sizeof (struct tcphdr)) {
+ if (m->m_len < sizeof(struct ip) + off) {
+ if ((m = m_pullup(m, sizeof (struct ip) + off)) == 0) {
+ tcpstat.tcps_rcvshort++;
+ return;
+ }
+ ti = mtod(m, struct tcpiphdr *);
+ }
+ optlen = off - sizeof (struct tcphdr);
+ optp = mtod(m, u_char *) + sizeof (struct tcpiphdr);
+ }
+ tiflags = ti->ti_flags;
+
+ /*
+ * Convert TCP protocol specific fields to host format.
+ */
+ NTOHL(ti->ti_seq);
+ NTOHL(ti->ti_ack);
+ NTOHS(ti->ti_win);
+ NTOHS(ti->ti_urp);
+
+ /*
+ * Drop TCP, IP headers and TCP options.
+ */
+ m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
+ m->m_len -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
+
+ /*
+ * Locate pcb for segment.
+ */
+findpcb:
+ inp = in_pcblookuphash(&tcbinfo, ti->ti_src, ti->ti_sport,
+ ti->ti_dst, ti->ti_dport, 1);
+
+ /*
+ * If the state is CLOSED (i.e., TCB does not exist) then
+ * all data in the incoming segment is discarded.
+ * If the TCB exists but is in CLOSED state, it is embryonic,
+ * but should either do a listen or a connect soon.
+ */
+ if (inp == NULL) {
+ if (log_in_vain && tiflags & TH_SYN) {
+ char buf[4*sizeof "123"];
+
+ strcpy(buf, inet_ntoa(ti->ti_dst));
+ log(LOG_INFO, "Connection attempt to TCP %s:%d"
+ " from %s:%d\n",
+ buf, ntohs(ti->ti_dport),
+ inet_ntoa(ti->ti_src), ntohs(ti->ti_sport));
+ }
+ goto dropwithreset;
+ }
+ tp = intotcpcb(inp);
+ if (tp == 0)
+ goto dropwithreset;
+ if (tp->t_state == TCPS_CLOSED)
+ goto drop;
+
+ /* Unscale the window into a 32-bit value. */
+ if ((tiflags & TH_SYN) == 0)
+ tiwin = ti->ti_win << tp->snd_scale;
+ else
+ tiwin = ti->ti_win;
+
+ so = inp->inp_socket;
+ if (so->so_options & (SO_DEBUG|SO_ACCEPTCONN)) {
+#ifdef TCPDEBUG
+ if (so->so_options & SO_DEBUG) {
+ ostate = tp->t_state;
+ tcp_saveti = *ti;
+ }
+#endif
+ if (so->so_options & SO_ACCEPTCONN) {
+ register struct tcpcb *tp0 = tp;
+ struct socket *so2;
+ if ((tiflags & (TH_RST|TH_ACK|TH_SYN)) != TH_SYN) {
+ /*
+ * Note: dropwithreset makes sure we don't
+ * send a RST in response to a RST.
+ */
+ if (tiflags & TH_ACK) {
+ tcpstat.tcps_badsyn++;
+ goto dropwithreset;
+ }
+ goto drop;
+ }
+ so2 = sonewconn(so, 0);
+ if (so2 == 0) {
+ tcpstat.tcps_listendrop++;
+ so2 = sodropablereq(so);
+ if (so2) {
+ tcp_drop(sototcpcb(so2), ETIMEDOUT);
+ so2 = sonewconn(so, 0);
+ }
+ if (!so2)
+ goto drop;
+ }
+ so = so2;
+ /*
+ * This is ugly, but ....
+ *
+ * Mark socket as temporary until we're
+ * committed to keeping it. The code at
+ * ``drop'' and ``dropwithreset'' check the
+ * flag dropsocket to see if the temporary
+ * socket created here should be discarded.
+ * We mark the socket as discardable until
+ * we're committed to it below in TCPS_LISTEN.
+ */
+ dropsocket++;
+ inp = (struct inpcb *)so->so_pcb;
+ inp->inp_laddr = ti->ti_dst;
+ inp->inp_lport = ti->ti_dport;
+ in_pcbrehash(inp);
+#if BSD>=43
+ inp->inp_options = ip_srcroute();
+#endif
+ tp = intotcpcb(inp);
+ tp->t_state = TCPS_LISTEN;
+ tp->t_flags |= tp0->t_flags & (TF_NOPUSH|TF_NOOPT);
+
+ /* Compute proper scaling value from buffer space */
+ while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
+ TCP_MAXWIN << tp->request_r_scale < so->so_rcv.sb_hiwat)
+ tp->request_r_scale++;
+ }
+ }
+
+ /*
+ * Segment received on connection.
+ * Reset idle time and keep-alive timer.
+ */
+ tp->t_idle = 0;
+ if (TCPS_HAVEESTABLISHED(tp->t_state))
+ tp->t_timer[TCPT_KEEP] = tcp_keepidle;
+
+ /*
+ * Process options if not in LISTEN state,
+ * else do it below (after getting remote address).
+ */
+ if (tp->t_state != TCPS_LISTEN)
+ tcp_dooptions(tp, optp, optlen, ti, &to);
+
+ /*
+ * Header prediction: check for the two common cases
+ * of a uni-directional data xfer. If the packet has
+ * no control flags, is in-sequence, the window didn't
+ * change and we're not retransmitting, it's a
+ * candidate. If the length is zero and the ack moved
+ * forward, we're the sender side of the xfer. Just
+ * free the data acked & wake any higher level process
+ * that was blocked waiting for space. If the length
+ * is non-zero and the ack didn't move, we're the
+ * receiver side. If we're getting packets in-order
+ * (the reassembly queue is empty), add the data to
+ * the socket buffer and note that we need a delayed ack.
+ * Make sure that the hidden state-flags are also off.
+ * Since we check for TCPS_ESTABLISHED above, it can only
+ * be TH_NEEDSYN.
+ */
+ if (tp->t_state == TCPS_ESTABLISHED &&
+ (tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) == TH_ACK &&
+ ((tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) == 0) &&
+ ((to.to_flags & TOF_TS) == 0 ||
+ TSTMP_GEQ(to.to_tsval, tp->ts_recent)) &&
+ /*
+ * Using the CC option is compulsory if once started:
+ * the segment is OK if no T/TCP was negotiated or
+ * if the segment has a CC option equal to CCrecv
+ */
+ ((tp->t_flags & (TF_REQ_CC|TF_RCVD_CC)) != (TF_REQ_CC|TF_RCVD_CC) ||
+ ((to.to_flags & TOF_CC) != 0 && to.to_cc == tp->cc_recv)) &&
+ ti->ti_seq == tp->rcv_nxt &&
+ tiwin && tiwin == tp->snd_wnd &&
+ tp->snd_nxt == tp->snd_max) {
+
+ /*
+ * If last ACK falls within this segment's sequence numbers,
+ * record the timestamp.
+ * NOTE that the test is modified according to the latest
+ * proposal of the tcplw@cray.com list (Braden 1993/04/26).
+ */
+ if ((to.to_flags & TOF_TS) != 0 &&
+ SEQ_LEQ(ti->ti_seq, tp->last_ack_sent)) {
+ tp->ts_recent_age = tcp_now;
+ tp->ts_recent = to.to_tsval;
+ }
+
+ if (ti->ti_len == 0) {
+ if (SEQ_GT(ti->ti_ack, tp->snd_una) &&
+ SEQ_LEQ(ti->ti_ack, tp->snd_max) &&
+ tp->snd_cwnd >= tp->snd_wnd &&
+ tp->t_dupacks < tcprexmtthresh) {
+ /*
+ * this is a pure ack for outstanding data.
+ */
+ ++tcpstat.tcps_predack;
+ if ((to.to_flags & TOF_TS) != 0)
+ tcp_xmit_timer(tp,
+ tcp_now - to.to_tsecr + 1);
+ else if (tp->t_rtt &&
+ SEQ_GT(ti->ti_ack, tp->t_rtseq))
+ tcp_xmit_timer(tp, tp->t_rtt);
+ acked = ti->ti_ack - tp->snd_una;
+ tcpstat.tcps_rcvackpack++;
+ tcpstat.tcps_rcvackbyte += acked;
+ sbdrop(&so->so_snd, acked);
+ tp->snd_una = ti->ti_ack;
+ m_freem(m);
+
+ /*
+ * If all outstanding data are acked, stop
+ * retransmit timer, otherwise restart timer
+ * using current (possibly backed-off) value.
+ * If process is waiting for space,
+ * wakeup/selwakeup/signal. If data
+ * are ready to send, let tcp_output
+ * decide between more output or persist.
+ */
+ if (tp->snd_una == tp->snd_max)
+ tp->t_timer[TCPT_REXMT] = 0;
+ else if (tp->t_timer[TCPT_PERSIST] == 0)
+ tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
+
+ if (so->so_snd.sb_flags & SB_NOTIFY)
+ sowwakeup(so);
+ if (so->so_snd.sb_cc)
+ (void) tcp_output(tp);
+ return;
+ }
+ } else if (ti->ti_ack == tp->snd_una &&
+ tp->seg_next == (struct tcpiphdr *)tp &&
+ ti->ti_len <= sbspace(&so->so_rcv)) {
+ /*
+ * this is a pure, in-sequence data packet
+ * with nothing on the reassembly queue and
+ * we have enough buffer space to take it.
+ */
+ ++tcpstat.tcps_preddat;
+ tp->rcv_nxt += ti->ti_len;
+ tcpstat.tcps_rcvpack++;
+ tcpstat.tcps_rcvbyte += ti->ti_len;
+ /*
+ * Add data to socket buffer.
+ */
+ sbappend(&so->so_rcv, m);
+ sorwakeup(so);
+#ifdef TCP_ACK_HACK
+ /*
+ * If this is a short packet, then ACK now - with Nagel
+ * congestion avoidance sender won't send more until
+ * he gets an ACK.
+ */
+ if (tiflags & TH_PUSH) {
+ tp->t_flags |= TF_ACKNOW;
+ tcp_output(tp);
+ } else {
+ tp->t_flags |= TF_DELACK;
+ }
+#else
+ tp->t_flags |= TF_DELACK;
+#endif
+ return;
+ }
+ }
+
+ /*
+ * Calculate amount of space in receive window,
+ * and then do TCP input processing.
+ * Receive window is amount of space in rcv queue,
+ * but not less than advertised window.
+ */
+ { int win;
+
+ win = sbspace(&so->so_rcv);
+ if (win < 0)
+ win = 0;
+ tp->rcv_wnd = imax(win, (int)(tp->rcv_adv - tp->rcv_nxt));
+ }
+
+ switch (tp->t_state) {
+
+ /*
+ * If the state is LISTEN then ignore segment if it contains an RST.
+ * If the segment contains an ACK then it is bad and send a RST.
+ * If it does not contain a SYN then it is not interesting; drop it.
+ * If it is from this socket, drop it, it must be forged.
+ * Don't bother responding if the destination was a broadcast.
+ * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
+ * tp->iss, and send a segment:
+ * <SEQ=ISS><ACK=RCV_NXT><CTL=SYN,ACK>
+ * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
+ * Fill in remote peer address fields if not previously specified.
+ * Enter SYN_RECEIVED state, and process any other fields of this
+ * segment in this state.
+ */
+ case TCPS_LISTEN: {
+ struct mbuf *am;
+ register struct sockaddr_in *sin;
+
+ if (tiflags & TH_RST)
+ goto drop;
+ if (tiflags & TH_ACK)
+ goto dropwithreset;
+ if ((tiflags & TH_SYN) == 0)
+ goto drop;
+ if ((ti->ti_dport == ti->ti_sport) &&
+ (ti->ti_dst.s_addr == ti->ti_src.s_addr))
+ goto drop;
+ /*
+ * RFC1122 4.2.3.10, p. 104: discard bcast/mcast SYN
+ * in_broadcast() should never return true on a received
+ * packet with M_BCAST not set.
+ */
+ if (m->m_flags & (M_BCAST|M_MCAST) ||
+ IN_MULTICAST(ntohl(ti->ti_dst.s_addr)))
+ goto drop;
+ am = m_get(M_DONTWAIT, MT_SONAME); /* XXX */
+ if (am == NULL)
+ goto drop;
+ am->m_len = sizeof (struct sockaddr_in);
+ sin = mtod(am, struct sockaddr_in *);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_addr = ti->ti_src;
+ sin->sin_port = ti->ti_sport;
+ bzero((caddr_t)sin->sin_zero, sizeof(sin->sin_zero));
+ laddr = inp->inp_laddr;
+ if (inp->inp_laddr.s_addr == INADDR_ANY)
+ inp->inp_laddr = ti->ti_dst;
+ if (in_pcbconnect(inp, am)) {
+ inp->inp_laddr = laddr;
+ (void) m_free(am);
+ goto drop;
+ }
+ (void) m_free(am);
+ tp->t_template = tcp_template(tp);
+ if (tp->t_template == 0) {
+ tp = tcp_drop(tp, ENOBUFS);
+ dropsocket = 0; /* socket is already gone */
+ goto drop;
+ }
+ if ((taop = tcp_gettaocache(inp)) == NULL) {
+ taop = &tao_noncached;
+ bzero(taop, sizeof(*taop));
+ }
+ tcp_dooptions(tp, optp, optlen, ti, &to);
+ if (iss)
+ tp->iss = iss;
+ else
+ tp->iss = tcp_iss;
+ tcp_iss += TCP_ISSINCR/4;
+ tp->irs = ti->ti_seq;
+ tcp_sendseqinit(tp);
+ tcp_rcvseqinit(tp);
+ /*
+ * Initialization of the tcpcb for transaction;
+ * set SND.WND = SEG.WND,
+ * initialize CCsend and CCrecv.
+ */
+ tp->snd_wnd = tiwin; /* initial send-window */
+ tp->cc_send = CC_INC(tcp_ccgen);
+ tp->cc_recv = to.to_cc;
+ /*
+ * Perform TAO test on incoming CC (SEG.CC) option, if any.
+ * - compare SEG.CC against cached CC from the same host,
+ * if any.
+ * - if SEG.CC > chached value, SYN must be new and is accepted
+ * immediately: save new CC in the cache, mark the socket
+ * connected, enter ESTABLISHED state, turn on flag to
+ * send a SYN in the next segment.
+ * A virtual advertised window is set in rcv_adv to
+ * initialize SWS prevention. Then enter normal segment
+ * processing: drop SYN, process data and FIN.
+ * - otherwise do a normal 3-way handshake.
+ */
+ if ((to.to_flags & TOF_CC) != 0) {
+ if (taop->tao_cc != 0 && CC_GT(to.to_cc, taop->tao_cc)) {
+ taop->tao_cc = to.to_cc;
+ tp->t_state = TCPS_ESTABLISHED;
+
+ /*
+ * If there is a FIN, or if there is data and the
+ * connection is local, then delay SYN,ACK(SYN) in
+ * the hope of piggy-backing it on a response
+ * segment. Otherwise must send ACK now in case
+ * the other side is slow starting.
+ */
+ if ((tiflags & TH_FIN) || (ti->ti_len != 0 &&
+ in_localaddr(inp->inp_faddr)))
+ tp->t_flags |= (TF_DELACK | TF_NEEDSYN);
+ else
+ tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN);
+
+ /*
+ * Limit the `virtual advertised window' to TCP_MAXWIN
+ * here. Even if we requested window scaling, it will
+ * become effective only later when our SYN is acked.
+ */
+ tp->rcv_adv += min(tp->rcv_wnd, TCP_MAXWIN);
+ tcpstat.tcps_connects++;
+ soisconnected(so);
+ tp->t_timer[TCPT_KEEP] = tcp_keepinit;
+ dropsocket = 0; /* committed to socket */
+ tcpstat.tcps_accepts++;
+ goto trimthenstep6;
+ }
+ /* else do standard 3-way handshake */
+ } else {
+ /*
+ * No CC option, but maybe CC.NEW:
+ * invalidate cached value.
+ */
+ taop->tao_cc = 0;
+ }
+ /*
+ * TAO test failed or there was no CC option,
+ * do a standard 3-way handshake.
+ */
+ tp->t_flags |= TF_ACKNOW;
+ tp->t_state = TCPS_SYN_RECEIVED;
+ tp->t_timer[TCPT_KEEP] = tcp_keepinit;
+ dropsocket = 0; /* committed to socket */
+ tcpstat.tcps_accepts++;
+ goto trimthenstep6;
+ }
+
+ /*
+ * If the state is SYN_RECEIVED:
+ * if seg contains SYN/ACK, send a RST.
+ * if seg contains an ACK, but not for our SYN/ACK, send a RST.
+ */
+ case TCPS_SYN_RECEIVED:
+ if (tiflags & TH_ACK) {
+ if (tiflags & TH_SYN) {
+ tcpstat.tcps_badsyn++;
+ goto dropwithreset;
+ }
+ if (SEQ_LEQ(ti->ti_ack, tp->snd_una) ||
+ SEQ_GT(ti->ti_ack, tp->snd_max))
+ goto dropwithreset;
+ }
+ break;
+
+ /*
+ * If the state is SYN_SENT:
+ * if seg contains an ACK, but not for our SYN, drop the input.
+ * if seg contains a RST, then drop the connection.
+ * if seg does not contain SYN, then drop it.
+ * Otherwise this is an acceptable SYN segment
+ * initialize tp->rcv_nxt and tp->irs
+ * if seg contains ack then advance tp->snd_una
+ * if SYN has been acked change to ESTABLISHED else SYN_RCVD state
+ * arrange for segment to be acked (eventually)
+ * continue processing rest of data/controls, beginning with URG
+ */
+ case TCPS_SYN_SENT:
+ if ((taop = tcp_gettaocache(inp)) == NULL) {
+ taop = &tao_noncached;
+ bzero(taop, sizeof(*taop));
+ }
+
+ if ((tiflags & TH_ACK) &&
+ (SEQ_LEQ(ti->ti_ack, tp->iss) ||
+ SEQ_GT(ti->ti_ack, tp->snd_max))) {
+ /*
+ * If we have a cached CCsent for the remote host,
+ * hence we haven't just crashed and restarted,
+ * do not send a RST. This may be a retransmission
+ * from the other side after our earlier ACK was lost.
+ * Our new SYN, when it arrives, will serve as the
+ * needed ACK.
+ */
+ if (taop->tao_ccsent != 0)
+ goto drop;
+ else
+ goto dropwithreset;
+ }
+ if (tiflags & TH_RST) {
+ if (tiflags & TH_ACK)
+ tp = tcp_drop(tp, ECONNREFUSED);
+ goto drop;
+ }
+ if ((tiflags & TH_SYN) == 0)
+ goto drop;
+ tp->snd_wnd = ti->ti_win; /* initial send window */
+ tp->cc_recv = to.to_cc; /* foreign CC */
+
+ tp->irs = ti->ti_seq;
+ tcp_rcvseqinit(tp);
+ if (tiflags & TH_ACK) {
+ /*
+ * Our SYN was acked. If segment contains CC.ECHO
+ * option, check it to make sure this segment really
+ * matches our SYN. If not, just drop it as old
+ * duplicate, but send an RST if we're still playing
+ * by the old rules. If no CC.ECHO option, make sure
+ * we don't get fooled into using T/TCP.
+ */
+ if (to.to_flags & TOF_CCECHO) {
+ if (tp->cc_send != to.to_ccecho) {
+ if (taop->tao_ccsent != 0)
+ goto drop;
+ else
+ goto dropwithreset;
+ }
+ } else
+ tp->t_flags &= ~TF_RCVD_CC;
+ tcpstat.tcps_connects++;
+ soisconnected(so);
+ /* Do window scaling on this connection? */
+ if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
+ (TF_RCVD_SCALE|TF_REQ_SCALE)) {
+ tp->snd_scale = tp->requested_s_scale;
+ tp->rcv_scale = tp->request_r_scale;
+ }
+ /* Segment is acceptable, update cache if undefined. */
+ if (taop->tao_ccsent == 0)
+ taop->tao_ccsent = to.to_ccecho;
+
+ tp->rcv_adv += tp->rcv_wnd;
+ tp->snd_una++; /* SYN is acked */
+ /*
+ * If there's data, delay ACK; if there's also a FIN
+ * ACKNOW will be turned on later.
+ */
+ if (ti->ti_len != 0)
+ tp->t_flags |= TF_DELACK;
+ else
+ tp->t_flags |= TF_ACKNOW;
+ /*
+ * Received <SYN,ACK> in SYN_SENT[*] state.
+ * Transitions:
+ * SYN_SENT --> ESTABLISHED
+ * SYN_SENT* --> FIN_WAIT_1
+ */
+ if (tp->t_flags & TF_NEEDFIN) {
+ tp->t_state = TCPS_FIN_WAIT_1;
+ tp->t_flags &= ~TF_NEEDFIN;
+ tiflags &= ~TH_SYN;
+ } else {
+ tp->t_state = TCPS_ESTABLISHED;
+ tp->t_timer[TCPT_KEEP] = tcp_keepidle;
+ }
+ } else {
+ /*
+ * Received initial SYN in SYN-SENT[*] state => simul-
+ * taneous open. If segment contains CC option and there is
+ * a cached CC, apply TAO test; if it succeeds, connection is
+ * half-synchronized. Otherwise, do 3-way handshake:
+ * SYN-SENT -> SYN-RECEIVED
+ * SYN-SENT* -> SYN-RECEIVED*
+ * If there was no CC option, clear cached CC value.
+ */
+ tp->t_flags |= TF_ACKNOW;
+ tp->t_timer[TCPT_REXMT] = 0;
+ if (to.to_flags & TOF_CC) {
+ if (taop->tao_cc != 0 &&
+ CC_GT(to.to_cc, taop->tao_cc)) {
+ /*
+ * update cache and make transition:
+ * SYN-SENT -> ESTABLISHED*
+ * SYN-SENT* -> FIN-WAIT-1*
+ */
+ taop->tao_cc = to.to_cc;
+ if (tp->t_flags & TF_NEEDFIN) {
+ tp->t_state = TCPS_FIN_WAIT_1;
+ tp->t_flags &= ~TF_NEEDFIN;
+ } else {
+ tp->t_state = TCPS_ESTABLISHED;
+ tp->t_timer[TCPT_KEEP] = tcp_keepidle;
+ }
+ tp->t_flags |= TF_NEEDSYN;
+ } else
+ tp->t_state = TCPS_SYN_RECEIVED;
+ } else {
+ /* CC.NEW or no option => invalidate cache */
+ taop->tao_cc = 0;
+ tp->t_state = TCPS_SYN_RECEIVED;
+ }
+ }
+
+trimthenstep6:
+ /*
+ * Advance ti->ti_seq to correspond to first data byte.
+ * If data, trim to stay within window,
+ * dropping FIN if necessary.
+ */
+ ti->ti_seq++;
+ if (ti->ti_len > tp->rcv_wnd) {
+ todrop = ti->ti_len - tp->rcv_wnd;
+ m_adj(m, -todrop);
+ ti->ti_len = tp->rcv_wnd;
+ tiflags &= ~TH_FIN;
+ tcpstat.tcps_rcvpackafterwin++;
+ tcpstat.tcps_rcvbyteafterwin += todrop;
+ }
+ tp->snd_wl1 = ti->ti_seq - 1;
+ tp->rcv_up = ti->ti_seq;
+ /*
+ * Client side of transaction: already sent SYN and data.
+ * If the remote host used T/TCP to validate the SYN,
+ * our data will be ACK'd; if so, enter normal data segment
+ * processing in the middle of step 5, ack processing.
+ * Otherwise, goto step 6.
+ */
+ if (tiflags & TH_ACK)
+ goto process_ACK;
+ goto step6;
+ /*
+ * If the state is LAST_ACK or CLOSING or TIME_WAIT:
+ * if segment contains a SYN and CC [not CC.NEW] option:
+ * if state == TIME_WAIT and connection duration > MSL,
+ * drop packet and send RST;
+ *
+ * if SEG.CC > CCrecv then is new SYN, and can implicitly
+ * ack the FIN (and data) in retransmission queue.
+ * Complete close and delete TCPCB. Then reprocess
+ * segment, hoping to find new TCPCB in LISTEN state;
+ *
+ * else must be old SYN; drop it.
+ * else do normal processing.
+ */
+ case TCPS_LAST_ACK:
+ case TCPS_CLOSING:
+ case TCPS_TIME_WAIT:
+ if ((tiflags & TH_SYN) &&
+ (to.to_flags & TOF_CC) && tp->cc_recv != 0) {
+ if (tp->t_state == TCPS_TIME_WAIT &&
+ tp->t_duration > TCPTV_MSL)
+ goto dropwithreset;
+ if (CC_GT(to.to_cc, tp->cc_recv)) {
+ tp = tcp_close(tp);
+ goto findpcb;
+ }
+ else
+ goto drop;
+ }
+ break; /* continue normal processing */
+ }
+
+ /*
+ * States other than LISTEN or SYN_SENT.
+ * First check timestamp, if present.
+ * Then check the connection count, if present.
+ * Then check that at least some bytes of segment are within
+ * receive window. If segment begins before rcv_nxt,
+ * drop leading data (and SYN); if nothing left, just ack.
+ *
+ * RFC 1323 PAWS: If we have a timestamp reply on this segment
+ * and it's less than ts_recent, drop it.
+ */
+ if ((to.to_flags & TOF_TS) != 0 && (tiflags & TH_RST) == 0 &&
+ tp->ts_recent && TSTMP_LT(to.to_tsval, tp->ts_recent)) {
+
+ /* Check to see if ts_recent is over 24 days old. */
+ if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) {
+ /*
+ * Invalidate ts_recent. If this segment updates
+ * ts_recent, the age will be reset later and ts_recent
+ * will get a valid value. If it does not, setting
+ * ts_recent to zero will at least satisfy the
+ * requirement that zero be placed in the timestamp
+ * echo reply when ts_recent isn't valid. The
+ * age isn't reset until we get a valid ts_recent
+ * because we don't want out-of-order segments to be
+ * dropped when ts_recent is old.
+ */
+ tp->ts_recent = 0;
+ } else {
+ tcpstat.tcps_rcvduppack++;
+ tcpstat.tcps_rcvdupbyte += ti->ti_len;
+ tcpstat.tcps_pawsdrop++;
+ goto dropafterack;
+ }
+ }
+
+ /*
+ * T/TCP mechanism
+ * If T/TCP was negotiated and the segment doesn't have CC,
+ * or if it's CC is wrong then drop the segment.
+ * RST segments do not have to comply with this.
+ */
+ if ((tp->t_flags & (TF_REQ_CC|TF_RCVD_CC)) == (TF_REQ_CC|TF_RCVD_CC) &&
+ ((to.to_flags & TOF_CC) == 0 || tp->cc_recv != to.to_cc) &&
+ (tiflags & TH_RST) == 0)
+ goto dropafterack;
+
+ todrop = tp->rcv_nxt - ti->ti_seq;
+ if (todrop > 0) {
+ if (tiflags & TH_SYN) {
+ tiflags &= ~TH_SYN;
+ ti->ti_seq++;
+ if (ti->ti_urp > 1)
+ ti->ti_urp--;
+ else
+ tiflags &= ~TH_URG;
+ todrop--;
+ }
+ /*
+ * Following if statement from Stevens, vol. 2, p. 960.
+ */
+ if (todrop > ti->ti_len
+ || (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) {
+ /*
+ * Any valid FIN must be to the left of the window.
+ * At this point the FIN must be a duplicate or out
+ * of sequence; drop it.
+ */
+ tiflags &= ~TH_FIN;
+
+ /*
+ * Send an ACK to resynchronize and drop any data.
+ * But keep on processing for RST or ACK.
+ */
+ tp->t_flags |= TF_ACKNOW;
+ todrop = ti->ti_len;
+ tcpstat.tcps_rcvduppack++;
+ tcpstat.tcps_rcvdupbyte += todrop;
+ } else {
+ tcpstat.tcps_rcvpartduppack++;
+ tcpstat.tcps_rcvpartdupbyte += todrop;
+ }
+ m_adj(m, todrop);
+ ti->ti_seq += todrop;
+ ti->ti_len -= todrop;
+ if (ti->ti_urp > todrop)
+ ti->ti_urp -= todrop;
+ else {
+ tiflags &= ~TH_URG;
+ ti->ti_urp = 0;
+ }
+ }
+
+ /*
+ * If new data are received on a connection after the
+ * user processes are gone, then RST the other end.
+ */
+ if ((so->so_state & SS_NOFDREF) &&
+ tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) {
+ tp = tcp_close(tp);
+ tcpstat.tcps_rcvafterclose++;
+ goto dropwithreset;
+ }
+
+ /*
+ * If segment ends after window, drop trailing data
+ * (and PUSH and FIN); if nothing left, just ACK.
+ */
+ todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd);
+ if (todrop > 0) {
+ tcpstat.tcps_rcvpackafterwin++;
+ if (todrop >= ti->ti_len) {
+ tcpstat.tcps_rcvbyteafterwin += ti->ti_len;
+ /*
+ * If a new connection request is received
+ * while in TIME_WAIT, drop the old connection
+ * and start over if the sequence numbers
+ * are above the previous ones.
+ */
+ if (tiflags & TH_SYN &&
+ tp->t_state == TCPS_TIME_WAIT &&
+ SEQ_GT(ti->ti_seq, tp->rcv_nxt)) {
+ iss = tp->rcv_nxt + TCP_ISSINCR;
+ tp = tcp_close(tp);
+ goto findpcb;
+ }
+ /*
+ * If window is closed can only take segments at
+ * window edge, and have to drop data and PUSH from
+ * incoming segments. Continue processing, but
+ * remember to ack. Otherwise, drop segment
+ * and ack.
+ */
+ if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) {
+ tp->t_flags |= TF_ACKNOW;
+ tcpstat.tcps_rcvwinprobe++;
+ } else
+ goto dropafterack;
+ } else
+ tcpstat.tcps_rcvbyteafterwin += todrop;
+ m_adj(m, -todrop);
+ ti->ti_len -= todrop;
+ tiflags &= ~(TH_PUSH|TH_FIN);
+ }
+
+ /*
+ * If last ACK falls within this segment's sequence numbers,
+ * record its timestamp.
+ * NOTE that the test is modified according to the latest
+ * proposal of the tcplw@cray.com list (Braden 1993/04/26).
+ */
+ if ((to.to_flags & TOF_TS) != 0 &&
+ SEQ_LEQ(ti->ti_seq, tp->last_ack_sent)) {
+ tp->ts_recent_age = tcp_now;
+ tp->ts_recent = to.to_tsval;
+ }
+
+ /*
+ * If the RST bit is set examine the state:
+ * SYN_RECEIVED STATE:
+ * If passive open, return to LISTEN state.
+ * If active open, inform user that connection was refused.
+ * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
+ * Inform user that connection was reset, and close tcb.
+ * CLOSING, LAST_ACK, TIME_WAIT STATES
+ * Close the tcb.
+ */
+ if (tiflags&TH_RST) switch (tp->t_state) {
+
+ case TCPS_SYN_RECEIVED:
+ so->so_error = ECONNREFUSED;
+ goto close;
+
+ case TCPS_ESTABLISHED:
+ case TCPS_FIN_WAIT_1:
+ case TCPS_FIN_WAIT_2:
+ case TCPS_CLOSE_WAIT:
+ so->so_error = ECONNRESET;
+ close:
+ tp->t_state = TCPS_CLOSED;
+ tcpstat.tcps_drops++;
+ tp = tcp_close(tp);
+ goto drop;
+
+ case TCPS_CLOSING:
+ case TCPS_LAST_ACK:
+ case TCPS_TIME_WAIT:
+ tp = tcp_close(tp);
+ goto drop;
+ }
+
+ /*
+ * If a SYN is in the window, then this is an
+ * error and we send an RST and drop the connection.
+ */
+ if (tiflags & TH_SYN) {
+ tp = tcp_drop(tp, ECONNRESET);
+ goto dropwithreset;
+ }
+
+ /*
+ * If the ACK bit is off: if in SYN-RECEIVED state or SENDSYN
+ * flag is on (half-synchronized state), then queue data for
+ * later processing; else drop segment and return.
+ */
+ if ((tiflags & TH_ACK) == 0) {
+ if (tp->t_state == TCPS_SYN_RECEIVED ||
+ (tp->t_flags & TF_NEEDSYN))
+ goto step6;
+ else
+ goto drop;
+ }
+
+ /*
+ * Ack processing.
+ */
+ switch (tp->t_state) {
+
+ /*
+ * In SYN_RECEIVED state, the ack ACKs our SYN, so enter
+ * ESTABLISHED state and continue processing.
+ * The ACK was checked above.
+ */
+ case TCPS_SYN_RECEIVED:
+
+ tcpstat.tcps_connects++;
+ soisconnected(so);
+ /* Do window scaling? */
+ if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
+ (TF_RCVD_SCALE|TF_REQ_SCALE)) {
+ tp->snd_scale = tp->requested_s_scale;
+ tp->rcv_scale = tp->request_r_scale;
+ }
+ /*
+ * Upon successful completion of 3-way handshake,
+ * update cache.CC if it was undefined, pass any queued
+ * data to the user, and advance state appropriately.
+ */
+ if ((taop = tcp_gettaocache(inp)) != NULL &&
+ taop->tao_cc == 0)
+ taop->tao_cc = tp->cc_recv;
+
+ /*
+ * Make transitions:
+ * SYN-RECEIVED -> ESTABLISHED
+ * SYN-RECEIVED* -> FIN-WAIT-1
+ */
+ if (tp->t_flags & TF_NEEDFIN) {
+ tp->t_state = TCPS_FIN_WAIT_1;
+ tp->t_flags &= ~TF_NEEDFIN;
+ } else {
+ tp->t_state = TCPS_ESTABLISHED;
+ tp->t_timer[TCPT_KEEP] = tcp_keepidle;
+ }
+ /*
+ * If segment contains data or ACK, will call tcp_reass()
+ * later; if not, do so now to pass queued data to user.
+ */
+ if (ti->ti_len == 0 && (tiflags & TH_FIN) == 0)
+ (void) tcp_reass(tp, (struct tcpiphdr *)0,
+ (struct mbuf *)0);
+ tp->snd_wl1 = ti->ti_seq - 1;
+ /* fall into ... */
+
+ /*
+ * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
+ * ACKs. If the ack is in the range
+ * tp->snd_una < ti->ti_ack <= tp->snd_max
+ * then advance tp->snd_una to ti->ti_ack and drop
+ * data from the retransmission queue. If this ACK reflects
+ * more up to date window information we update our window information.
+ */
+ case TCPS_ESTABLISHED:
+ case TCPS_FIN_WAIT_1:
+ case TCPS_FIN_WAIT_2:
+ case TCPS_CLOSE_WAIT:
+ case TCPS_CLOSING:
+ case TCPS_LAST_ACK:
+ case TCPS_TIME_WAIT:
+
+ if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
+ if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
+ tcpstat.tcps_rcvdupack++;
+ /*
+ * If we have outstanding data (other than
+ * a window probe), this is a completely
+ * duplicate ack (ie, window info didn't
+ * change), the ack is the biggest we've
+ * seen and we've seen exactly our rexmt
+ * threshhold of them, assume a packet
+ * has been dropped and retransmit it.
+ * Kludge snd_nxt & the congestion
+ * window so we send only this one
+ * packet.
+ *
+ * We know we're losing at the current
+ * window size so do congestion avoidance
+ * (set ssthresh to half the current window
+ * and pull our congestion window back to
+ * the new ssthresh).
+ *
+ * Dup acks mean that packets have left the
+ * network (they're now cached at the receiver)
+ * so bump cwnd by the amount in the receiver
+ * to keep a constant cwnd packets in the
+ * network.
+ */
+ if (tp->t_timer[TCPT_REXMT] == 0 ||
+ ti->ti_ack != tp->snd_una)
+ tp->t_dupacks = 0;
+ else if (++tp->t_dupacks == tcprexmtthresh) {
+ tcp_seq onxt = tp->snd_nxt;
+ u_int win =
+ min(tp->snd_wnd, tp->snd_cwnd) / 2 /
+ tp->t_maxseg;
+
+ if (win < 2)
+ win = 2;
+ tp->snd_ssthresh = win * tp->t_maxseg;
+ tp->t_timer[TCPT_REXMT] = 0;
+ tp->t_rtt = 0;
+ tp->snd_nxt = ti->ti_ack;
+ tp->snd_cwnd = tp->t_maxseg;
+ (void) tcp_output(tp);
+ tp->snd_cwnd = tp->snd_ssthresh +
+ tp->t_maxseg * tp->t_dupacks;
+ if (SEQ_GT(onxt, tp->snd_nxt))
+ tp->snd_nxt = onxt;
+ goto drop;
+ } else if (tp->t_dupacks > tcprexmtthresh) {
+ tp->snd_cwnd += tp->t_maxseg;
+ (void) tcp_output(tp);
+ goto drop;
+ }
+ } else
+ tp->t_dupacks = 0;
+ break;
+ }
+ /*
+ * If the congestion window was inflated to account
+ * for the other side's cached packets, retract it.
+ */
+ if (tp->t_dupacks >= tcprexmtthresh &&
+ tp->snd_cwnd > tp->snd_ssthresh)
+ tp->snd_cwnd = tp->snd_ssthresh;
+ tp->t_dupacks = 0;
+ if (SEQ_GT(ti->ti_ack, tp->snd_max)) {
+ tcpstat.tcps_rcvacktoomuch++;
+ goto dropafterack;
+ }
+ /*
+ * If we reach this point, ACK is not a duplicate,
+ * i.e., it ACKs something we sent.
+ */
+ if (tp->t_flags & TF_NEEDSYN) {
+ /*
+ * T/TCP: Connection was half-synchronized, and our
+ * SYN has been ACK'd (so connection is now fully
+ * synchronized). Go to non-starred state,
+ * increment snd_una for ACK of SYN, and check if
+ * we can do window scaling.
+ */
+ tp->t_flags &= ~TF_NEEDSYN;
+ tp->snd_una++;
+ /* Do window scaling? */
+ if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
+ (TF_RCVD_SCALE|TF_REQ_SCALE)) {
+ tp->snd_scale = tp->requested_s_scale;
+ tp->rcv_scale = tp->request_r_scale;
+ }
+ }
+
+process_ACK:
+ acked = ti->ti_ack - tp->snd_una;
+ tcpstat.tcps_rcvackpack++;
+ tcpstat.tcps_rcvackbyte += acked;
+
+ /*
+ * If we have a timestamp reply, update smoothed
+ * round trip time. If no timestamp is present but
+ * transmit timer is running and timed sequence
+ * number was acked, update smoothed round trip time.
+ * Since we now have an rtt measurement, cancel the
+ * timer backoff (cf., Phil Karn's retransmit alg.).
+ * Recompute the initial retransmit timer.
+ */
+ if (to.to_flags & TOF_TS)
+ tcp_xmit_timer(tp, tcp_now - to.to_tsecr + 1);
+ else if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
+ tcp_xmit_timer(tp,tp->t_rtt);
+
+ /*
+ * If all outstanding data is acked, stop retransmit
+ * timer and remember to restart (more output or persist).
+ * If there is more data to be acked, restart retransmit
+ * timer, using current (possibly backed-off) value.
+ */
+ if (ti->ti_ack == tp->snd_max) {
+ tp->t_timer[TCPT_REXMT] = 0;
+ needoutput = 1;
+ } else if (tp->t_timer[TCPT_PERSIST] == 0)
+ tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
+
+ /*
+ * If no data (only SYN) was ACK'd,
+ * skip rest of ACK processing.
+ */
+ if (acked == 0)
+ goto step6;
+
+ /*
+ * When new data is acked, open the congestion window.
+ * If the window gives us less than ssthresh packets
+ * in flight, open exponentially (maxseg per packet).
+ * Otherwise open linearly: maxseg per window
+ * (maxseg^2 / cwnd per packet).
+ */
+ {
+ register u_int cw = tp->snd_cwnd;
+ register u_int incr = tp->t_maxseg;
+
+ if (cw > tp->snd_ssthresh)
+ incr = incr * incr / cw;
+ tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
+ }
+ if (acked > so->so_snd.sb_cc) {
+ tp->snd_wnd -= so->so_snd.sb_cc;
+ sbdrop(&so->so_snd, (int)so->so_snd.sb_cc);
+ ourfinisacked = 1;
+ } else {
+ sbdrop(&so->so_snd, acked);
+ tp->snd_wnd -= acked;
+ ourfinisacked = 0;
+ }
+ if (so->so_snd.sb_flags & SB_NOTIFY)
+ sowwakeup(so);
+ tp->snd_una = ti->ti_ack;
+ if (SEQ_LT(tp->snd_nxt, tp->snd_una))
+ tp->snd_nxt = tp->snd_una;
+
+ switch (tp->t_state) {
+
+ /*
+ * In FIN_WAIT_1 STATE in addition to the processing
+ * for the ESTABLISHED state if our FIN is now acknowledged
+ * then enter FIN_WAIT_2.
+ */
+ case TCPS_FIN_WAIT_1:
+ if (ourfinisacked) {
+ /*
+ * If we can't receive any more
+ * data, then closing user can proceed.
+ * Starting the timer is contrary to the
+ * specification, but if we don't get a FIN
+ * we'll hang forever.
+ */
+ if (so->so_state & SS_CANTRCVMORE) {
+ soisdisconnected(so);
+ tp->t_timer[TCPT_2MSL] = tcp_maxidle;
+ }
+ tp->t_state = TCPS_FIN_WAIT_2;
+ }
+ break;
+
+ /*
+ * In CLOSING STATE in addition to the processing for
+ * the ESTABLISHED state if the ACK acknowledges our FIN
+ * then enter the TIME-WAIT state, otherwise ignore
+ * the segment.
+ */
+ case TCPS_CLOSING:
+ if (ourfinisacked) {
+ tp->t_state = TCPS_TIME_WAIT;
+ tcp_canceltimers(tp);
+ /* Shorten TIME_WAIT [RFC-1644, p.28] */
+ if (tp->cc_recv != 0 &&
+ tp->t_duration < TCPTV_MSL)
+ tp->t_timer[TCPT_2MSL] =
+ tp->t_rxtcur * TCPTV_TWTRUNC;
+ else
+ tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
+ soisdisconnected(so);
+ }
+ break;
+
+ /*
+ * In LAST_ACK, we may still be waiting for data to drain
+ * and/or to be acked, as well as for the ack of our FIN.
+ * If our FIN is now acknowledged, delete the TCB,
+ * enter the closed state and return.
+ */
+ case TCPS_LAST_ACK:
+ if (ourfinisacked) {
+ tp = tcp_close(tp);
+ goto drop;
+ }
+ break;
+
+ /*
+ * In TIME_WAIT state the only thing that should arrive
+ * is a retransmission of the remote FIN. Acknowledge
+ * it and restart the finack timer.
+ */
+ case TCPS_TIME_WAIT:
+ tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
+ goto dropafterack;
+ }
+ }
+
+step6:
+ /*
+ * Update window information.
+ * Don't look at window if no ACK: TAC's send garbage on first SYN.
+ */
+ if ((tiflags & TH_ACK) &&
+ (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
+ (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
+ (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) {
+ /* keep track of pure window updates */
+ if (ti->ti_len == 0 &&
+ tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd)
+ tcpstat.tcps_rcvwinupd++;
+ tp->snd_wnd = tiwin;
+ tp->snd_wl1 = ti->ti_seq;
+ tp->snd_wl2 = ti->ti_ack;
+ if (tp->snd_wnd > tp->max_sndwnd)
+ tp->max_sndwnd = tp->snd_wnd;
+ needoutput = 1;
+ }
+
+ /*
+ * Process segments with URG.
+ */
+ if ((tiflags & TH_URG) && ti->ti_urp &&
+ TCPS_HAVERCVDFIN(tp->t_state) == 0) {
+ /*
+ * This is a kludge, but if we receive and accept
+ * random urgent pointers, we'll crash in
+ * soreceive. It's hard to imagine someone
+ * actually wanting to send this much urgent data.
+ */
+ if (ti->ti_urp + so->so_rcv.sb_cc > sb_max) {
+ ti->ti_urp = 0; /* XXX */
+ tiflags &= ~TH_URG; /* XXX */
+ goto dodata; /* XXX */
+ }
+ /*
+ * If this segment advances the known urgent pointer,
+ * then mark the data stream. This should not happen
+ * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
+ * a FIN has been received from the remote side.
+ * In these states we ignore the URG.
+ *
+ * According to RFC961 (Assigned Protocols),
+ * the urgent pointer points to the last octet
+ * of urgent data. We continue, however,
+ * to consider it to indicate the first octet
+ * of data past the urgent section as the original
+ * spec states (in one of two places).
+ */
+ if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up)) {
+ tp->rcv_up = ti->ti_seq + ti->ti_urp;
+ so->so_oobmark = so->so_rcv.sb_cc +
+ (tp->rcv_up - tp->rcv_nxt) - 1;
+ if (so->so_oobmark == 0)
+ so->so_state |= SS_RCVATMARK;
+ sohasoutofband(so);
+ tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA);
+ }
+ /*
+ * Remove out of band data so doesn't get presented to user.
+ * This can happen independent of advancing the URG pointer,
+ * but if two URG's are pending at once, some out-of-band
+ * data may creep in... ick.
+ */
+ if (ti->ti_urp <= (u_long)ti->ti_len
+#ifdef SO_OOBINLINE
+ && (so->so_options & SO_OOBINLINE) == 0
+#endif
+ )
+ tcp_pulloutofband(so, ti, m);
+ } else
+ /*
+ * If no out of band data is expected,
+ * pull receive urgent pointer along
+ * with the receive window.
+ */
+ if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
+ tp->rcv_up = tp->rcv_nxt;
+dodata: /* XXX */
+
+ /*
+ * Process the segment text, merging it into the TCP sequencing queue,
+ * and arranging for acknowledgment of receipt if necessary.
+ * This process logically involves adjusting tp->rcv_wnd as data
+ * is presented to the user (this happens in tcp_usrreq.c,
+ * case PRU_RCVD). If a FIN has already been received on this
+ * connection then we just ignore the text.
+ */
+ if ((ti->ti_len || (tiflags&TH_FIN)) &&
+ TCPS_HAVERCVDFIN(tp->t_state) == 0) {
+ TCP_REASS(tp, ti, m, so, tiflags);
+ /*
+ * Note the amount of data that peer has sent into
+ * our window, in order to estimate the sender's
+ * buffer size.
+ */
+ len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt);
+ } else {
+ m_freem(m);
+ tiflags &= ~TH_FIN;
+ }
+
+ /*
+ * If FIN is received ACK the FIN and let the user know
+ * that the connection is closing.
+ */
+ if (tiflags & TH_FIN) {
+ if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
+ socantrcvmore(so);
+ /*
+ * If connection is half-synchronized
+ * (ie NEEDSYN flag on) then delay ACK,
+ * so it may be piggybacked when SYN is sent.
+ * Otherwise, since we received a FIN then no
+ * more input can be expected, send ACK now.
+ */
+ if (tp->t_flags & TF_NEEDSYN)
+ tp->t_flags |= TF_DELACK;
+ else
+ tp->t_flags |= TF_ACKNOW;
+ tp->rcv_nxt++;
+ }
+ switch (tp->t_state) {
+
+ /*
+ * In SYN_RECEIVED and ESTABLISHED STATES
+ * enter the CLOSE_WAIT state.
+ */
+ case TCPS_SYN_RECEIVED:
+ case TCPS_ESTABLISHED:
+ tp->t_state = TCPS_CLOSE_WAIT;
+ break;
+
+ /*
+ * If still in FIN_WAIT_1 STATE FIN has not been acked so
+ * enter the CLOSING state.
+ */
+ case TCPS_FIN_WAIT_1:
+ tp->t_state = TCPS_CLOSING;
+ break;
+
+ /*
+ * In FIN_WAIT_2 state enter the TIME_WAIT state,
+ * starting the time-wait timer, turning off the other
+ * standard timers.
+ */
+ case TCPS_FIN_WAIT_2:
+ tp->t_state = TCPS_TIME_WAIT;
+ tcp_canceltimers(tp);
+ /* Shorten TIME_WAIT [RFC-1644, p.28] */
+ if (tp->cc_recv != 0 &&
+ tp->t_duration < TCPTV_MSL) {
+ tp->t_timer[TCPT_2MSL] =
+ tp->t_rxtcur * TCPTV_TWTRUNC;
+ /* For transaction client, force ACK now. */
+ tp->t_flags |= TF_ACKNOW;
+ }
+ else
+ tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
+ soisdisconnected(so);
+ break;
+
+ /*
+ * In TIME_WAIT state restart the 2 MSL time_wait timer.
+ */
+ case TCPS_TIME_WAIT:
+ tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
+ break;
+ }
+ }
+#ifdef TCPDEBUG
+ if (so->so_options & SO_DEBUG)
+ tcp_trace(TA_INPUT, ostate, tp, &tcp_saveti, 0);
+#endif
+
+ /*
+ * Return any desired output.
+ */
+ if (needoutput || (tp->t_flags & TF_ACKNOW))
+ (void) tcp_output(tp);
+ return;
+
+dropafterack:
+ /*
+ * Generate an ACK dropping incoming segment if it occupies
+ * sequence space, where the ACK reflects our state.
+ */
+ if (tiflags & TH_RST)
+ goto drop;
+#ifdef TCPDEBUG
+ if (so->so_options & SO_DEBUG)
+ tcp_trace(TA_DROP, ostate, tp, &tcp_saveti, 0);
+#endif
+ m_freem(m);
+ tp->t_flags |= TF_ACKNOW;
+ (void) tcp_output(tp);
+ return;
+
+dropwithreset:
+ /*
+ * Generate a RST, dropping incoming segment.
+ * Make ACK acceptable to originator of segment.
+ * Don't bother to respond if destination was broadcast/multicast.
+ */
+ if ((tiflags & TH_RST) || m->m_flags & (M_BCAST|M_MCAST) ||
+ IN_MULTICAST(ntohl(ti->ti_dst.s_addr)))
+ goto drop;
+#ifdef TCPDEBUG
+ if (tp == 0 || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
+ tcp_trace(TA_DROP, ostate, tp, &tcp_saveti, 0);
+#endif
+ if (tiflags & TH_ACK)
+ tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
+ else {
+ if (tiflags & TH_SYN)
+ ti->ti_len++;
+ tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
+ TH_RST|TH_ACK);
+ }
+ /* destroy temporarily created socket */
+ if (dropsocket)
+ (void) soabort(so);
+ return;
+
+drop:
+ /*
+ * Drop space held by incoming segment and return.
+ */
+#ifdef TCPDEBUG
+ if (tp == 0 || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
+ tcp_trace(TA_DROP, ostate, tp, &tcp_saveti, 0);
+#endif
+ m_freem(m);
+ /* destroy temporarily created socket */
+ if (dropsocket)
+ (void) soabort(so);
+ return;
+#ifndef TUBA_INCLUDE
+}
+
+static void
+tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti,
+ struct tcpopt *to)
+{
+ u_short mss = 0;
+ int opt, optlen;
+
+ for (; cnt > 0; cnt -= optlen, cp += optlen) {
+ opt = cp[0];
+ if (opt == TCPOPT_EOL)
+ break;
+ if (opt == TCPOPT_NOP)
+ optlen = 1;
+ else {
+ optlen = cp[1];
+ if (optlen <= 0)
+ break;
+ }
+ switch (opt) {
+
+ default:
+ continue;
+
+ case TCPOPT_MAXSEG:
+ if (optlen != TCPOLEN_MAXSEG)
+ continue;
+ if (!(ti->ti_flags & TH_SYN))
+ continue;
+ bcopy((char *) cp + 2, (char *) &mss, sizeof(mss));
+ NTOHS(mss);
+ break;
+
+ case TCPOPT_WINDOW:
+ if (optlen != TCPOLEN_WINDOW)
+ continue;
+ if (!(ti->ti_flags & TH_SYN))
+ continue;
+ tp->t_flags |= TF_RCVD_SCALE;
+ tp->requested_s_scale = min(cp[2], TCP_MAX_WINSHIFT);
+ break;
+
+ case TCPOPT_TIMESTAMP:
+ if (optlen != TCPOLEN_TIMESTAMP)
+ continue;
+ to->to_flags |= TOF_TS;
+ bcopy((char *)cp + 2,
+ (char *)&to->to_tsval, sizeof(to->to_tsval));
+ NTOHL(to->to_tsval);
+ bcopy((char *)cp + 6,
+ (char *)&to->to_tsecr, sizeof(to->to_tsecr));
+ NTOHL(to->to_tsecr);
+
+ /*
+ * A timestamp received in a SYN makes
+ * it ok to send timestamp requests and replies.
+ */
+ if (ti->ti_flags & TH_SYN) {
+ tp->t_flags |= TF_RCVD_TSTMP;
+ tp->ts_recent = to->to_tsval;
+ tp->ts_recent_age = tcp_now;
+ }
+ break;
+ case TCPOPT_CC:
+ if (optlen != TCPOLEN_CC)
+ continue;
+ to->to_flags |= TOF_CC;
+ bcopy((char *)cp + 2,
+ (char *)&to->to_cc, sizeof(to->to_cc));
+ NTOHL(to->to_cc);
+ /*
+ * A CC or CC.new option received in a SYN makes
+ * it ok to send CC in subsequent segments.
+ */
+ if (ti->ti_flags & TH_SYN)
+ tp->t_flags |= TF_RCVD_CC;
+ break;
+ case TCPOPT_CCNEW:
+ if (optlen != TCPOLEN_CC)
+ continue;
+ if (!(ti->ti_flags & TH_SYN))
+ continue;
+ to->to_flags |= TOF_CCNEW;
+ bcopy((char *)cp + 2,
+ (char *)&to->to_cc, sizeof(to->to_cc));
+ NTOHL(to->to_cc);
+ /*
+ * A CC or CC.new option received in a SYN makes
+ * it ok to send CC in subsequent segments.
+ */
+ tp->t_flags |= TF_RCVD_CC;
+ break;
+ case TCPOPT_CCECHO:
+ if (optlen != TCPOLEN_CC)
+ continue;
+ if (!(ti->ti_flags & TH_SYN))
+ continue;
+ to->to_flags |= TOF_CCECHO;
+ bcopy((char *)cp + 2,
+ (char *)&to->to_ccecho, sizeof(to->to_ccecho));
+ NTOHL(to->to_ccecho);
+ break;
+ }
+ }
+ if (ti->ti_flags & TH_SYN)
+ tcp_mss(tp, mss); /* sets t_maxseg */
+}
+
+/*
+ * Pull out of band byte out of a segment so
+ * it doesn't appear in the user's data queue.
+ * It is still reflected in the segment length for
+ * sequencing purposes.
+ */
+static void
+tcp_pulloutofband(struct socket *so, struct tcpiphdr *ti, struct mbuf *m)
+{
+ int cnt = ti->ti_urp - 1;
+
+ while (cnt >= 0) {
+ if (m->m_len > cnt) {
+ char *cp = mtod(m, caddr_t) + cnt;
+ struct tcpcb *tp = sototcpcb(so);
+
+ tp->t_iobc = *cp;
+ tp->t_oobflags |= TCPOOB_HAVEDATA;
+ bcopy(cp+1, cp, (unsigned)(m->m_len - cnt - 1));
+ m->m_len--;
+ return;
+ }
+ cnt -= m->m_len;
+ m = m->m_next;
+ if (m == 0)
+ break;
+ }
+ panic("tcp_pulloutofband");
+}
+
+/*
+ * Collect new round-trip time estimate
+ * and update averages and current timeout.
+ */
+static void
+tcp_xmit_timer(struct tcpcb *tp, int rtt)
+{
+ int delta;
+
+ tcpstat.tcps_rttupdated++;
+ tp->t_rttupdated++;
+ if (tp->t_srtt != 0) {
+ /*
+ * srtt is stored as fixed point with 5 bits after the
+ * binary point (i.e., scaled by 8). The following magic
+ * is equivalent to the smoothing algorithm in rfc793 with
+ * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
+ * point). Adjust rtt to origin 0.
+ */
+ delta = ((rtt - 1) << TCP_DELTA_SHIFT)
+ - (tp->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT));
+
+ if ((tp->t_srtt += delta) <= 0)
+ tp->t_srtt = 1;
+
+ /*
+ * We accumulate a smoothed rtt variance (actually, a
+ * smoothed mean difference), then set the retransmit
+ * timer to smoothed rtt + 4 times the smoothed variance.
+ * rttvar is stored as fixed point with 4 bits after the
+ * binary point (scaled by 16). The following is
+ * equivalent to rfc793 smoothing with an alpha of .75
+ * (rttvar = rttvar*3/4 + |delta| / 4). This replaces
+ * rfc793's wired-in beta.
+ */
+ if (delta < 0)
+ delta = -delta;
+ delta -= tp->t_rttvar >> (TCP_RTTVAR_SHIFT - TCP_DELTA_SHIFT);
+ if ((tp->t_rttvar += delta) <= 0)
+ tp->t_rttvar = 1;
+ } else {
+ /*
+ * No rtt measurement yet - use the unsmoothed rtt.
+ * Set the variance to half the rtt (so our first
+ * retransmit happens at 3*rtt).
+ */
+ tp->t_srtt = rtt << TCP_RTT_SHIFT;
+ tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
+ }
+ tp->t_rtt = 0;
+ tp->t_rxtshift = 0;
+
+ /*
+ * the retransmit should happen at rtt + 4 * rttvar.
+ * Because of the way we do the smoothing, srtt and rttvar
+ * will each average +1/2 tick of bias. When we compute
+ * the retransmit timer, we want 1/2 tick of rounding and
+ * 1 extra tick because of +-1/2 tick uncertainty in the
+ * firing of the timer. The bias will give us exactly the
+ * 1.5 tick we need. But, because the bias is
+ * statistical, we have to test that we don't drop below
+ * the minimum feasible timer (which is 2 ticks).
+ */
+ TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
+ max(tp->t_rttmin, rtt + 2), TCPTV_REXMTMAX);
+
+ /*
+ * We received an ack for a packet that wasn't retransmitted;
+ * it is probably safe to discard any error indications we've
+ * received recently. This isn't quite right, but close enough
+ * for now (a route might have failed after we sent a segment,
+ * and the return path might not be symmetrical).
+ */
+ tp->t_softerror = 0;
+}
+
+/*
+ * Determine a reasonable value for maxseg size.
+ * If the route is known, check route for mtu.
+ * If none, use an mss that can be handled on the outgoing
+ * interface without forcing IP to fragment; if bigger than
+ * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES
+ * to utilize large mbufs. If no route is found, route has no mtu,
+ * or the destination isn't local, use a default, hopefully conservative
+ * size (usually 512 or the default IP max size, but no more than the mtu
+ * of the interface), as we can't discover anything about intervening
+ * gateways or networks. We also initialize the congestion/slow start
+ * window to be a single segment if the destination isn't local.
+ * While looking at the routing entry, we also initialize other path-dependent
+ * parameters from pre-set or cached values in the routing entry.
+ *
+ * Also take into account the space needed for options that we
+ * send regularly. Make maxseg shorter by that amount to assure
+ * that we can send maxseg amount of data even when the options
+ * are present. Store the upper limit of the length of options plus
+ * data in maxopd.
+ *
+ * NOTE that this routine is only called when we process an incoming
+ * segment, for outgoing segments only tcp_mssopt is called.
+ *
+ * In case of T/TCP, we call this routine during implicit connection
+ * setup as well (offer = -1), to initialize maxseg from the cached
+ * MSS of our peer.
+ */
+void
+tcp_mss(struct tcpcb *tp, int offer)
+{
+ register struct rtentry *rt;
+ struct ifnet *ifp;
+ register int rtt, mss;
+ u_long bufsize;
+ struct inpcb *inp;
+ struct socket *so;
+ struct rmxp_tao *taop;
+ int origoffer = offer;
+
+ inp = tp->t_inpcb;
+ if ((rt = tcp_rtlookup(inp)) == NULL) {
+ tp->t_maxopd = tp->t_maxseg = tcp_mssdflt;
+ return;
+ }
+ ifp = rt->rt_ifp;
+ so = inp->inp_socket;
+
+ taop = rmx_taop(rt->rt_rmx);
+ /*
+ * Offer == -1 means that we didn't receive SYN yet,
+ * use cached value in that case;
+ */
+ if (offer == -1)
+ offer = taop->tao_mssopt;
+ /*
+ * Offer == 0 means that there was no MSS on the SYN segment,
+ * in this case we use tcp_mssdflt.
+ */
+ if (offer == 0)
+ offer = tcp_mssdflt;
+ else
+ /*
+ * Sanity check: make sure that maxopd will be large
+ * enough to allow some data on segments even is the
+ * all the option space is used (40bytes). Otherwise
+ * funny things may happen in tcp_output.
+ */
+ offer = max(offer, 64);
+ taop->tao_mssopt = offer;
+
+ /*
+ * While we're here, check if there's an initial rtt
+ * or rttvar. Convert from the route-table units
+ * to scaled multiples of the slow timeout timer.
+ */
+ if (tp->t_srtt == 0 && (rtt = rt->rt_rmx.rmx_rtt)) {
+ /*
+ * XXX the lock bit for RTT indicates that the value
+ * is also a minimum value; this is subject to time.
+ */
+ if (rt->rt_rmx.rmx_locks & RTV_RTT)
+ tp->t_rttmin = rtt / (RTM_RTTUNIT / PR_SLOWHZ);
+ tp->t_srtt = rtt / (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTT_SCALE));
+ tcpstat.tcps_usedrtt++;
+ if (rt->rt_rmx.rmx_rttvar) {
+ tp->t_rttvar = rt->rt_rmx.rmx_rttvar /
+ (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTTVAR_SCALE));
+ tcpstat.tcps_usedrttvar++;
+ } else {
+ /* default variation is +- 1 rtt */
+ tp->t_rttvar =
+ tp->t_srtt * TCP_RTTVAR_SCALE / TCP_RTT_SCALE;
+ }
+ TCPT_RANGESET(tp->t_rxtcur,
+ ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1,
+ tp->t_rttmin, TCPTV_REXMTMAX);
+ }
+ /*
+ * if there's an mtu associated with the route, use it
+ */
+ if (rt->rt_rmx.rmx_mtu)
+ mss = rt->rt_rmx.rmx_mtu - sizeof(struct tcpiphdr);
+ else
+ {
+ mss = ifp->if_mtu - sizeof(struct tcpiphdr);
+ if (!in_localaddr(inp->inp_faddr))
+ mss = min(mss, tcp_mssdflt);
+ }
+ mss = min(mss, offer);
+ /*
+ * maxopd stores the maximum length of data AND options
+ * in a segment; maxseg is the amount of data in a normal
+ * segment. We need to store this value (maxopd) apart
+ * from maxseg, because now every segment carries options
+ * and thus we normally have somewhat less data in segments.
+ */
+ tp->t_maxopd = mss;
+
+ /*
+ * In case of T/TCP, origoffer==-1 indicates, that no segments
+ * were received yet. In this case we just guess, otherwise
+ * we do the same as before T/TCP.
+ */
+ if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
+ (origoffer == -1 ||
+ (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP))
+ mss -= TCPOLEN_TSTAMP_APPA;
+ if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
+ (origoffer == -1 ||
+ (tp->t_flags & TF_RCVD_CC) == TF_RCVD_CC))
+ mss -= TCPOLEN_CC_APPA;
+
+#if (MCLBYTES & (MCLBYTES - 1)) == 0
+ if (mss > MCLBYTES)
+ mss &= ~(MCLBYTES-1);
+#else
+ if (mss > MCLBYTES)
+ mss = mss / MCLBYTES * MCLBYTES;
+#endif
+ /*
+ * If there's a pipesize, change the socket buffer
+ * to that size. Make the socket buffers an integral
+ * number of mss units; if the mss is larger than
+ * the socket buffer, decrease the mss.
+ */
+#ifdef RTV_SPIPE
+ if ((bufsize = rt->rt_rmx.rmx_sendpipe) == 0)
+#endif
+ bufsize = so->so_snd.sb_hiwat;
+ if (bufsize < mss)
+ mss = bufsize;
+ else {
+ bufsize = roundup(bufsize, mss);
+ if (bufsize > sb_max)
+ bufsize = sb_max;
+ (void)sbreserve(&so->so_snd, bufsize);
+ }
+ tp->t_maxseg = mss;
+
+#ifdef RTV_RPIPE
+ if ((bufsize = rt->rt_rmx.rmx_recvpipe) == 0)
+#endif
+ bufsize = so->so_rcv.sb_hiwat;
+ if (bufsize > mss) {
+ bufsize = roundup(bufsize, mss);
+ if (bufsize > sb_max)
+ bufsize = sb_max;
+ (void)sbreserve(&so->so_rcv, bufsize);
+ }
+ /*
+ * Don't force slow-start on local network.
+ */
+ if (!in_localaddr(inp->inp_faddr))
+ tp->snd_cwnd = mss;
+
+ if (rt->rt_rmx.rmx_ssthresh) {
+ /*
+ * There's some sort of gateway or interface
+ * buffer limit on the path. Use this to set
+ * the slow start threshhold, but set the
+ * threshold to no less than 2*mss.
+ */
+ tp->snd_ssthresh = max(2 * mss, rt->rt_rmx.rmx_ssthresh);
+ tcpstat.tcps_usedssthresh++;
+ }
+}
+
+/*
+ * Determine the MSS option to send on an outgoing SYN.
+ */
+int
+tcp_mssopt(struct tcpcb *tp)
+{
+ struct rtentry *rt;
+
+ rt = tcp_rtlookup(tp->t_inpcb);
+ if (rt == NULL)
+ return tcp_mssdflt;
+
+ return rt->rt_ifp->if_mtu - sizeof(struct tcpiphdr);
+}
+#endif /* TUBA_INCLUDE */
diff --git a/cpukit/libnetworking/netinet/tcp_output.c b/cpukit/libnetworking/netinet/tcp_output.c
new file mode 100644
index 0000000000..d5f0c311b4
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_output.c
@@ -0,0 +1,755 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_tcpdebug.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <errno.h>
+
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#define TCPOUTFLAGS
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#ifdef TCPDEBUG
+#include <netinet/tcp_debug.h>
+#endif
+
+#ifdef notyet
+extern struct mbuf *m_copypack();
+#endif
+
+
+/*
+ * Tcp output routine: figure out what should be sent and send it.
+ */
+int
+tcp_output(
+ register struct tcpcb *tp)
+{
+ register struct socket *so = tp->t_inpcb->inp_socket;
+ register long len, win;
+ int off, flags, error;
+ register struct mbuf *m;
+ register struct tcpiphdr *ti;
+ u_char opt[TCP_MAXOLEN];
+ unsigned optlen, hdrlen;
+ int idle, sendalot;
+ struct rmxp_tao *taop;
+ struct rmxp_tao tao_noncached;
+
+ /*
+ * Determine length of data that should be transmitted,
+ * and flags that will be used.
+ * If there is some data or critical controls (SYN, RST)
+ * to send, then transmit; otherwise, investigate further.
+ */
+ idle = (tp->snd_max == tp->snd_una);
+ if (idle && tp->t_idle >= tp->t_rxtcur)
+ /*
+ * We have been idle for "a while" and no acks are
+ * expected to clock out any data we send --
+ * slow start to get ack "clock" running again.
+ */
+ tp->snd_cwnd = tp->t_maxseg;
+again:
+ sendalot = 0;
+ off = tp->snd_nxt - tp->snd_una;
+ win = min(tp->snd_wnd, tp->snd_cwnd);
+
+ flags = tcp_outflags[tp->t_state];
+ /*
+ * Get standard flags, and add SYN or FIN if requested by 'hidden'
+ * state flags.
+ */
+ if (tp->t_flags & TF_NEEDFIN)
+ flags |= TH_FIN;
+ if (tp->t_flags & TF_NEEDSYN)
+ flags |= TH_SYN;
+
+ /*
+ * If in persist timeout with window of 0, send 1 byte.
+ * Otherwise, if window is small but nonzero
+ * and timer expired, we will send what we can
+ * and go to transmit state.
+ */
+ if (tp->t_force) {
+ if (win == 0) {
+ /*
+ * If we still have some data to send, then
+ * clear the FIN bit. Usually this would
+ * happen below when it realizes that we
+ * aren't sending all the data. However,
+ * if we have exactly 1 byte of unset data,
+ * then it won't clear the FIN bit below,
+ * and if we are in persist state, we wind
+ * up sending the packet without recording
+ * that we sent the FIN bit.
+ *
+ * We can't just blindly clear the FIN bit,
+ * because if we don't have any more data
+ * to send then the probe will be the FIN
+ * itself.
+ */
+ if (off < so->so_snd.sb_cc)
+ flags &= ~TH_FIN;
+ win = 1;
+ } else {
+ tp->t_timer[TCPT_PERSIST] = 0;
+ tp->t_rxtshift = 0;
+ }
+ }
+
+ len = min(so->so_snd.sb_cc, win) - off;
+
+ if ((taop = tcp_gettaocache(tp->t_inpcb)) == NULL) {
+ taop = &tao_noncached;
+ bzero(taop, sizeof(*taop));
+ }
+
+ /*
+ * Lop off SYN bit if it has already been sent. However, if this
+ * is SYN-SENT state and if segment contains data and if we don't
+ * know that foreign host supports TAO, suppress sending segment.
+ */
+ if ((flags & TH_SYN) && SEQ_GT(tp->snd_nxt, tp->snd_una)) {
+ flags &= ~TH_SYN;
+ off--, len++;
+ if (len > 0 && tp->t_state == TCPS_SYN_SENT &&
+ taop->tao_ccsent == 0)
+ return 0;
+ }
+
+ /*
+ * Be careful not to send data and/or FIN on SYN segments
+ * in cases when no CC option will be sent.
+ * This measure is needed to prevent interoperability problems
+ * with not fully conformant TCP implementations.
+ */
+ if ((flags & TH_SYN) &&
+ ((tp->t_flags & TF_NOOPT) || !(tp->t_flags & TF_REQ_CC) ||
+ ((flags & TH_ACK) && !(tp->t_flags & TF_RCVD_CC)))) {
+ len = 0;
+ flags &= ~TH_FIN;
+ }
+
+ if (len < 0) {
+ /*
+ * If FIN has been sent but not acked,
+ * but we haven't been called to retransmit,
+ * len will be -1. Otherwise, window shrank
+ * after we sent into it. If window shrank to 0,
+ * cancel pending retransmit, pull snd_nxt back
+ * to (closed) window, and set the persist timer
+ * if it isn't already going. If the window didn't
+ * close completely, just wait for an ACK.
+ */
+ len = 0;
+ if (win == 0) {
+ tp->t_timer[TCPT_REXMT] = 0;
+ tp->t_rxtshift = 0;
+ tp->snd_nxt = tp->snd_una;
+ if (tp->t_timer[TCPT_PERSIST] == 0)
+ tcp_setpersist(tp);
+ }
+ }
+ if (len > tp->t_maxseg) {
+ len = tp->t_maxseg;
+ sendalot = 1;
+ }
+ if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
+ flags &= ~TH_FIN;
+
+ win = sbspace(&so->so_rcv);
+
+ /*
+ * Sender silly window avoidance. If connection is idle
+ * and can send all data, a maximum segment,
+ * at least a maximum default-size segment do it,
+ * or are forced, do it; otherwise don't bother.
+ * If peer's buffer is tiny, then send
+ * when window is at least half open.
+ * If retransmitting (possibly after persist timer forced us
+ * to send into a small window), then must resend.
+ */
+ if (len) {
+ if (len == tp->t_maxseg)
+ goto send;
+ if ((idle || tp->t_flags & TF_NODELAY) &&
+ (tp->t_flags & TF_NOPUSH) == 0 &&
+ len + off >= so->so_snd.sb_cc)
+ goto send;
+ if (tp->t_force)
+ goto send;
+ if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
+ goto send;
+ if (SEQ_LT(tp->snd_nxt, tp->snd_max))
+ goto send;
+ }
+
+ /*
+ * Compare available window to amount of window
+ * known to peer (as advertised window less
+ * next expected input). If the difference is at least two
+ * max size segments, or at least 50% of the maximum possible
+ * window, then want to send a window update to peer.
+ */
+ if (win > 0) {
+ /*
+ * "adv" is the amount we can increase the window,
+ * taking into account that we are limited by
+ * TCP_MAXWIN << tp->rcv_scale.
+ */
+ long adv = min(win, (long)TCP_MAXWIN << tp->rcv_scale) -
+ (tp->rcv_adv - tp->rcv_nxt);
+
+ if (adv >= (long) (2 * tp->t_maxseg))
+ goto send;
+ if (2 * adv >= (long) so->so_rcv.sb_hiwat)
+ goto send;
+ }
+
+ /*
+ * Send if we owe peer an ACK.
+ */
+ if (tp->t_flags & TF_ACKNOW)
+ goto send;
+ if ((flags & TH_RST) ||
+ ((flags & TH_SYN) && (tp->t_flags & TF_NEEDSYN) == 0))
+ goto send;
+ if (SEQ_GT(tp->snd_up, tp->snd_una))
+ goto send;
+ /*
+ * If our state indicates that FIN should be sent
+ * and we have not yet done so, or we're retransmitting the FIN,
+ * then we need to send.
+ */
+ if (flags & TH_FIN &&
+ ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
+ goto send;
+
+ /*
+ * TCP window updates are not reliable, rather a polling protocol
+ * using ``persist'' packets is used to insure receipt of window
+ * updates. The three ``states'' for the output side are:
+ * idle not doing retransmits or persists
+ * persisting to move a small or zero window
+ * (re)transmitting and thereby not persisting
+ *
+ * tp->t_timer[TCPT_PERSIST]
+ * is set when we are in persist state.
+ * tp->t_force
+ * is set when we are called to send a persist packet.
+ * tp->t_timer[TCPT_REXMT]
+ * is set when we are retransmitting
+ * The output side is idle when both timers are zero.
+ *
+ * If send window is too small, there is data to transmit, and no
+ * retransmit or persist is pending, then go to persist state.
+ * If nothing happens soon, send when timer expires:
+ * if window is nonzero, transmit what we can,
+ * otherwise force out a byte.
+ */
+ if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 &&
+ tp->t_timer[TCPT_PERSIST] == 0) {
+ tp->t_rxtshift = 0;
+ tcp_setpersist(tp);
+ }
+
+ /*
+ * No reason to send a segment, just return.
+ */
+ return (0);
+
+send:
+ /*
+ * Before ESTABLISHED, force sending of initial options
+ * unless TCP set not to do any options.
+ * NOTE: we assume that the IP/TCP header plus TCP options
+ * always fit in a single mbuf, leaving room for a maximum
+ * link header, i.e.
+ * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN
+ */
+ optlen = 0;
+ hdrlen = sizeof (struct tcpiphdr);
+ if (flags & TH_SYN) {
+ tp->snd_nxt = tp->iss;
+ if ((tp->t_flags & TF_NOOPT) == 0) {
+ u_short mss;
+
+ opt[0] = TCPOPT_MAXSEG;
+ opt[1] = TCPOLEN_MAXSEG;
+ mss = htons((u_short) tcp_mssopt(tp));
+ (void)memcpy(opt + 2, &mss, sizeof(mss));
+ optlen = TCPOLEN_MAXSEG;
+
+ if ((tp->t_flags & TF_REQ_SCALE) &&
+ ((flags & TH_ACK) == 0 ||
+ (tp->t_flags & TF_RCVD_SCALE))) {
+ *((u_long *) (opt + optlen)) = htonl(
+ TCPOPT_NOP << 24 |
+ TCPOPT_WINDOW << 16 |
+ TCPOLEN_WINDOW << 8 |
+ tp->request_r_scale);
+ optlen += 4;
+ }
+ }
+ }
+
+ /*
+ * Send a timestamp and echo-reply if this is a SYN and our side
+ * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
+ * and our peer have sent timestamps in our SYN's.
+ */
+ if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
+ (flags & TH_RST) == 0 &&
+ ((flags & TH_ACK) == 0 ||
+ (tp->t_flags & TF_RCVD_TSTMP))) {
+ u_long *lp = (u_long *)(opt + optlen);
+
+ /* Form timestamp option as shown in appendix A of RFC 1323. */
+ *lp++ = htonl(TCPOPT_TSTAMP_HDR);
+ *lp++ = htonl(tcp_now);
+ *lp = htonl(tp->ts_recent);
+ optlen += TCPOLEN_TSTAMP_APPA;
+ }
+
+ /*
+ * Send `CC-family' options if our side wants to use them (TF_REQ_CC),
+ * options are allowed (!TF_NOOPT) and it's not a RST.
+ */
+ if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
+ (flags & TH_RST) == 0) {
+ switch (flags & (TH_SYN|TH_ACK)) {
+ /*
+ * This is a normal ACK, send CC if we received CC before
+ * from our peer.
+ */
+ case TH_ACK:
+ if (!(tp->t_flags & TF_RCVD_CC))
+ break;
+ /*FALLTHROUGH*/
+
+ /*
+ * We can only get here in T/TCP's SYN_SENT* state, when
+ * we're a sending a non-SYN segment without waiting for
+ * the ACK of our SYN. A check above assures that we only
+ * do this if our peer understands T/TCP.
+ */
+ case 0:
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_CC;
+ opt[optlen++] = TCPOLEN_CC;
+ *(u_int32_t *)&opt[optlen] = htonl(tp->cc_send);
+
+ optlen += 4;
+ break;
+
+ /*
+ * This is our initial SYN, check whether we have to use
+ * CC or CC.new.
+ */
+ case TH_SYN:
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = tp->t_flags & TF_SENDCCNEW ?
+ TCPOPT_CCNEW : TCPOPT_CC;
+ opt[optlen++] = TCPOLEN_CC;
+ *(u_int32_t *)&opt[optlen] = htonl(tp->cc_send);
+ optlen += 4;
+ break;
+
+ /*
+ * This is a SYN,ACK; send CC and CC.echo if we received
+ * CC from our peer.
+ */
+ case (TH_SYN|TH_ACK):
+ if (tp->t_flags & TF_RCVD_CC) {
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_CC;
+ opt[optlen++] = TCPOLEN_CC;
+ *(u_int32_t *)&opt[optlen] =
+ htonl(tp->cc_send);
+ optlen += 4;
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_NOP;
+ opt[optlen++] = TCPOPT_CCECHO;
+ opt[optlen++] = TCPOLEN_CC;
+ *(u_int32_t *)&opt[optlen] =
+ htonl(tp->cc_recv);
+ optlen += 4;
+ }
+ break;
+ }
+ }
+
+ hdrlen += optlen;
+
+ /*
+ * Adjust data length if insertion of options will
+ * bump the packet length beyond the t_maxopd length.
+ * Clear the FIN bit because we cut off the tail of
+ * the segment.
+ */
+ if (len + optlen > tp->t_maxopd) {
+ /*
+ * If there is still more to send, don't close the connection.
+ */
+ flags &= ~TH_FIN;
+ len = tp->t_maxopd - optlen;
+ sendalot = 1;
+ }
+
+/*#ifdef DIAGNOSTIC*/
+ if (max_linkhdr + hdrlen > MHLEN)
+ panic("tcphdr too big");
+/*#endif*/
+
+ /*
+ * Grab a header mbuf, attaching a copy of data to
+ * be transmitted, and initialize the header from
+ * the template for sends on this connection.
+ */
+ if (len) {
+ if (tp->t_force && len == 1)
+ tcpstat.tcps_sndprobe++;
+ else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
+ tcpstat.tcps_sndrexmitpack++;
+ tcpstat.tcps_sndrexmitbyte += len;
+ } else {
+ tcpstat.tcps_sndpack++;
+ tcpstat.tcps_sndbyte += len;
+ }
+#ifdef notyet
+ if ((m = m_copypack(so->so_snd.sb_mb, off,
+ (int)len, max_linkhdr + hdrlen)) == 0) {
+ error = ENOBUFS;
+ goto out;
+ }
+ /*
+ * m_copypack left space for our hdr; use it.
+ */
+ m->m_len += hdrlen;
+ m->m_data -= hdrlen;
+#else
+ MGETHDR(m, M_DONTWAIT, MT_HEADER);
+ if (m == NULL) {
+ error = ENOBUFS;
+ goto out;
+ }
+ m->m_data += max_linkhdr;
+ m->m_len = hdrlen;
+ if (len <= MHLEN - hdrlen - max_linkhdr) {
+ m_copydata(so->so_snd.sb_mb, off, (int) len,
+ mtod(m, caddr_t) + hdrlen);
+ m->m_len += len;
+ } else {
+ m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
+ if (m->m_next == 0) {
+ (void) m_free(m);
+ error = ENOBUFS;
+ goto out;
+ }
+ }
+#endif
+ /*
+ * If we're sending everything we've got, set PUSH.
+ * (This will keep happy those implementations which only
+ * give data to the user when a buffer fills or
+ * a PUSH comes in.)
+ */
+ if (off + len == so->so_snd.sb_cc)
+ flags |= TH_PUSH;
+ } else {
+ if (tp->t_flags & TF_ACKNOW)
+ tcpstat.tcps_sndacks++;
+ else if (flags & (TH_SYN|TH_FIN|TH_RST))
+ tcpstat.tcps_sndctrl++;
+ else if (SEQ_GT(tp->snd_up, tp->snd_una))
+ tcpstat.tcps_sndurg++;
+ else
+ tcpstat.tcps_sndwinup++;
+
+ MGETHDR(m, M_DONTWAIT, MT_HEADER);
+ if (m == NULL) {
+ error = ENOBUFS;
+ goto out;
+ }
+ m->m_data += max_linkhdr;
+ m->m_len = hdrlen;
+ }
+ m->m_pkthdr.rcvif = (struct ifnet *)0;
+ ti = mtod(m, struct tcpiphdr *);
+ if (tp->t_template == 0)
+ panic("tcp_output");
+ (void)memcpy(ti, tp->t_template, sizeof (struct tcpiphdr));
+
+ /*
+ * Fill in fields, remembering maximum advertised
+ * window for use in delaying messages about window sizes.
+ * If resending a FIN, be sure not to use a new sequence number.
+ */
+ if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
+ tp->snd_nxt == tp->snd_max)
+ tp->snd_nxt--;
+ /*
+ * If we are doing retransmissions, then snd_nxt will
+ * not reflect the first unsent octet. For ACK only
+ * packets, we do not want the sequence number of the
+ * retransmitted packet, we want the sequence number
+ * of the next unsent octet. So, if there is no data
+ * (and no SYN or FIN), use snd_max instead of snd_nxt
+ * when filling in ti_seq. But if we are in persist
+ * state, snd_max might reflect one byte beyond the
+ * right edge of the window, so use snd_nxt in that
+ * case, since we know we aren't doing a retransmission.
+ * (retransmit and persist are mutually exclusive...)
+ */
+ if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST])
+ ti->ti_seq = htonl(tp->snd_nxt);
+ else
+ ti->ti_seq = htonl(tp->snd_max);
+ ti->ti_ack = htonl(tp->rcv_nxt);
+ if (optlen) {
+ bcopy(opt, ti + 1, optlen);
+ ti->ti_off = (sizeof (struct tcphdr) + optlen) >> 2;
+ }
+ ti->ti_flags = flags;
+ /*
+ * Calculate receive window. Don't shrink window,
+ * but avoid silly window syndrome.
+ */
+ if (win < (long)(so->so_rcv.sb_hiwat / 4) && win < (long)tp->t_maxseg)
+ win = 0;
+ if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
+ win = (long)(tp->rcv_adv - tp->rcv_nxt);
+ if (win > (long)TCP_MAXWIN << tp->rcv_scale)
+ win = (long)TCP_MAXWIN << tp->rcv_scale;
+ ti->ti_win = htons((u_short) (win>>tp->rcv_scale));
+ if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
+ ti->ti_urp = htons((u_short)(tp->snd_up - tp->snd_nxt));
+ ti->ti_flags |= TH_URG;
+ } else
+ /*
+ * If no urgent pointer to send, then we pull
+ * the urgent pointer to the left edge of the send window
+ * so that it doesn't drift into the send window on sequence
+ * number wraparound.
+ */
+ tp->snd_up = tp->snd_una; /* drag it along */
+
+ /*
+ * Put TCP length in extended header, and then
+ * checksum extended header and data.
+ */
+ if (len + optlen)
+ ti->ti_len = htons((u_short)(sizeof (struct tcphdr) +
+ optlen + len));
+ ti->ti_sum = in_cksum(m, (int)(hdrlen + len));
+
+ /*
+ * In transmit state, time the transmission and arrange for
+ * the retransmit. In persist state, just set snd_max.
+ */
+ if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) {
+ tcp_seq startseq = tp->snd_nxt;
+
+ /*
+ * Advance snd_nxt over sequence space of this segment.
+ */
+ if (flags & (TH_SYN|TH_FIN)) {
+ if (flags & TH_SYN)
+ tp->snd_nxt++;
+ if (flags & TH_FIN) {
+ tp->snd_nxt++;
+ tp->t_flags |= TF_SENTFIN;
+ }
+ }
+ tp->snd_nxt += len;
+ if (SEQ_GT(tp->snd_nxt, tp->snd_max)) {
+ tp->snd_max = tp->snd_nxt;
+ /*
+ * Time this transmission if not a retransmission and
+ * not currently timing anything.
+ */
+ if (tp->t_rtt == 0) {
+ tp->t_rtt = 1;
+ tp->t_rtseq = startseq;
+ tcpstat.tcps_segstimed++;
+ }
+ }
+
+ /*
+ * Set retransmit timer if not currently set,
+ * and not doing an ack or a keep-alive probe.
+ * Initial value for retransmit timer is smoothed
+ * round-trip time + 2 * round-trip time variance.
+ * Initialize shift counter which is used for backoff
+ * of retransmit time.
+ */
+ if (tp->t_timer[TCPT_REXMT] == 0 &&
+ tp->snd_nxt != tp->snd_una) {
+ tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
+ if (tp->t_timer[TCPT_PERSIST]) {
+ tp->t_timer[TCPT_PERSIST] = 0;
+ tp->t_rxtshift = 0;
+ }
+ }
+ } else
+ if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
+ tp->snd_max = tp->snd_nxt + len;
+
+#ifdef TCPDEBUG
+ /*
+ * Trace.
+ */
+ if (so->so_options & SO_DEBUG)
+ tcp_trace(TA_OUTPUT, tp->t_state, tp, ti, 0);
+#endif
+
+ /*
+ * Fill in IP length and desired time to live and
+ * send to IP level. There should be a better way
+ * to handle ttl and tos; we could keep them in
+ * the template, but need a way to checksum without them.
+ */
+ m->m_pkthdr.len = hdrlen + len;
+#ifdef TUBA
+ if (tp->t_tuba_pcb)
+ error = tuba_output(m, tp);
+ else
+#endif
+ {
+#if 1
+ struct rtentry *rt;
+#endif
+ ((struct ip *)ti)->ip_len = m->m_pkthdr.len;
+ ((struct ip *)ti)->ip_ttl = tp->t_inpcb->inp_ip_ttl; /* XXX */
+ ((struct ip *)ti)->ip_tos = tp->t_inpcb->inp_ip_tos; /* XXX */
+#if 1
+ /*
+ * See if we should do MTU discovery. We do it only if the following
+ * are true:
+ * 1) we have a valid route to the destination
+ * 2) the MTU is not locked (if it is, then discovery has been
+ * disabled)
+ */
+ if ((rt = tp->t_inpcb->inp_route.ro_rt)
+ && rt->rt_flags & RTF_UP
+ && !(rt->rt_rmx.rmx_locks & RTV_MTU)) {
+ ((struct ip *)ti)->ip_off |= IP_DF;
+ }
+#endif
+ error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
+ so->so_options & SO_DONTROUTE, 0);
+ }
+ if (error) {
+out:
+ if (error == ENOBUFS) {
+ tcp_quench(tp->t_inpcb, 0);
+ return (0);
+ }
+#if 1
+ if (error == EMSGSIZE) {
+ /*
+ * ip_output() will have already fixed the route
+ * for us. tcp_mtudisc() will, as its last action,
+ * initiate retransmission, so it is important to
+ * not do so here.
+ */
+ tcp_mtudisc(tp->t_inpcb, 0);
+ return 0;
+ }
+#endif
+ if ((error == EHOSTUNREACH || error == ENETDOWN)
+ && TCPS_HAVERCVDSYN(tp->t_state)) {
+ tp->t_softerror = error;
+ return (0);
+ }
+ return (error);
+ }
+ tcpstat.tcps_sndtotal++;
+
+ /*
+ * Data sent (as far as we can tell).
+ * If this advertises a larger window than any other segment,
+ * then remember the size of the advertised window.
+ * Any pending ACK has now been sent.
+ */
+ if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
+ tp->rcv_adv = tp->rcv_nxt + win;
+ tp->last_ack_sent = tp->rcv_nxt;
+ tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
+ if (sendalot)
+ goto again;
+ return (0);
+}
+
+void
+tcp_setpersist(
+ register struct tcpcb *tp)
+{
+ register int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;
+
+ if (tp->t_timer[TCPT_REXMT])
+ panic("tcp_output REXMT");
+ /*
+ * Start/restart persistance timer.
+ */
+ TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
+ t * tcp_backoff[tp->t_rxtshift],
+ TCPTV_PERSMIN, TCPTV_PERSMAX);
+ if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
+ tp->t_rxtshift++;
+}
diff --git a/cpukit/libnetworking/netinet/tcp_seq.h b/cpukit/libnetworking/netinet/tcp_seq.h
new file mode 100644
index 0000000000..5d42a8ed3e
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_seq.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 1982, 1986, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_seq.h 8.3 (Berkeley) 6/21/95
+ * $FreeBSD: src/sys/netinet/tcp_seq.h,v 1.26 2006/06/18 14:24:12 andre Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_TCP_SEQ_H_
+#define _NETINET_TCP_SEQ_H_
+/*
+ * TCP sequence numbers are 32 bit integers operated
+ * on with modular arithmetic. These macros can be
+ * used to compare such integers.
+ */
+#define SEQ_LT(a,b) ((int)((a)-(b)) < 0)
+#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
+#define SEQ_GT(a,b) ((int)((a)-(b)) > 0)
+#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)
+
+/* for modulo comparisons of timestamps */
+#define TSTMP_LT(a,b) ((int)((a)-(b)) < 0)
+#define TSTMP_GEQ(a,b) ((int)((a)-(b)) >= 0)
+
+/*
+ * TCP connection counts are 32 bit integers operated
+ * on with modular arithmetic. These macros can be
+ * used to compare such integers.
+ */
+#define CC_LT(a,b) ((int)((a)-(b)) < 0)
+#define CC_LEQ(a,b) ((int)((a)-(b)) <= 0)
+#define CC_GT(a,b) ((int)((a)-(b)) > 0)
+#define CC_GEQ(a,b) ((int)((a)-(b)) >= 0)
+
+/* Macro to increment a CC: skip 0 which has a special meaning */
+#define CC_INC(c) (++(c) == 0 ? ++(c) : (c))
+
+/*
+ * Macros to initialize tcp sequence numbers for
+ * send and receive from initial send and receive
+ * sequence numbers.
+ */
+#define tcp_rcvseqinit(tp) \
+ (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
+
+#define tcp_sendseqinit(tp) \
+ (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
+ (tp)->iss
+
+#define TCP_PAWS_IDLE (uint32_t)(24L * 24L * 60L * 60L * PR_SLOWHZ)
+ /* timestamp wrap-around time */
+
+#ifdef _KERNEL
+extern tcp_cc tcp_ccgen; /* global connection count */
+
+/*
+ * Increment for tcp_iss each second.
+ * This is designed to increment at the standard 250 KB/s,
+ * but with a random component averaging 128 KB.
+ * We also increment tcp_iss by a quarter of this amount
+ * each time we use the value for a new connection.
+ * If defined, the tcp_random18() macro should produce a
+ * number in the range [0-0x3ffff] that is hard to predict.
+ */
+#ifndef tcp_random18
+#define tcp_random18() (((uint32_t)random() >> 14) & 0x3ffffL)
+#endif
+#define TCP_ISSINCR (uint32_t)(122L*1024L + tcp_random18())
+
+extern tcp_seq tcp_iss; /* tcp initial send seq # */
+#else
+#define TCP_ISSINCR (250*1024) /* increment for tcp_iss each second */
+#endif /* _KERNEL */
+#endif /* _NETINET_TCP_SEQ_H_ */
diff --git a/cpukit/libnetworking/netinet/tcp_subr.c b/cpukit/libnetworking/netinet/tcp_subr.c
new file mode 100644
index 0000000000..e3c6f9323c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_subr.c
@@ -0,0 +1,729 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
+ * $FreeBSD: src/sys/netinet/tcp_subr.c,v 1.226 2005/05/07 00:41:36 cperciva Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_tcpdebug.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <errno.h>
+
+#include <net/route.h>
+#include <net/if.h>
+
+#define _IP_VHL
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#ifdef TCPDEBUG
+#include <netinet/tcp_debug.h>
+#endif
+
+int tcp_mssdflt = TCP_MSS;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW,
+ &tcp_mssdflt , 0, "Default TCP Maximum Segment Size");
+
+static int tcp_do_rfc1323 = 1;
+#if !defined(__rtems__)
+static int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt,
+ CTLFLAG_RW, &tcp_rttdflt , 0, "");
+
+SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323,
+ CTLFLAG_RW, &tcp_do_rfc1323 , 0, "");
+#endif
+
+static void tcp_notify(struct inpcb *, int);
+
+/*
+ * Target size of TCP PCB hash table. Will be rounded down to a prime
+ * number.
+ */
+#ifndef TCBHASHSIZE
+#define TCBHASHSIZE 128
+#endif
+
+/*
+ * Tcp initialization
+ */
+void
+tcp_init(void)
+{
+
+ tcp_iss = random(); /* wrong, but better than a constant */
+ tcp_ccgen = 1;
+ LIST_INIT(&tcb);
+ tcbinfo.listhead = &tcb;
+ tcbinfo.hashbase = hashinit(TCBHASHSIZE, M_PCB, &tcbinfo.hashmask);
+ if (max_protohdr < sizeof(struct tcpiphdr))
+ max_protohdr = sizeof(struct tcpiphdr);
+ if (max_linkhdr + sizeof(struct tcpiphdr) > MHLEN)
+ panic("tcp_init");
+}
+
+/*
+ * Create template to be used to send tcp packets on a connection.
+ * Call after host entry created, allocates an mbuf and fills
+ * in a skeletal tcp/ip header, minimizing the amount of work
+ * necessary when the connection is used.
+ */
+struct tcpiphdr *
+tcp_template(struct tcpcb *tp)
+{
+ register struct inpcb *inp = tp->t_inpcb;
+ register struct mbuf *m;
+ register struct tcpiphdr *n;
+
+ if ((n = tp->t_template) == 0) {
+ m = m_get(M_DONTWAIT, MT_HEADER);
+ if (m == NULL)
+ return (0);
+ m->m_len = sizeof (struct tcpiphdr);
+ n = mtod(m, struct tcpiphdr *);
+ }
+ n->ti_next = n->ti_prev = 0;
+ n->ti_x1 = 0;
+ n->ti_pr = IPPROTO_TCP;
+ n->ti_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip));
+ n->ti_src = inp->inp_laddr;
+ n->ti_dst = inp->inp_faddr;
+ n->ti_sport = inp->inp_lport;
+ n->ti_dport = inp->inp_fport;
+ n->ti_seq = 0;
+ n->ti_ack = 0;
+ n->ti_x2 = 0;
+ n->ti_off = 5;
+ n->ti_flags = 0;
+ n->ti_win = 0;
+ n->ti_sum = 0;
+ n->ti_urp = 0;
+ return (n);
+}
+
+/*
+ * Send a single message to the TCP at address specified by
+ * the given TCP/IP header. If m == 0, then we make a copy
+ * of the tcpiphdr at ti and send directly to the addressed host.
+ * This is used to force keep alive messages out using the TCP
+ * template for a connection tp->t_template. If flags are given
+ * then we send a message back to the TCP which originated the
+ * segment ti, and discard the mbuf containing it and any other
+ * attached mbufs.
+ *
+ * In any case the ack and sequence number of the transmitted
+ * segment are as specified by the parameters.
+ *
+ * NOTE: If m != NULL, then ti must point to *inside* the mbuf.
+ */
+void
+tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m,
+ tcp_seq ack, tcp_seq seq, int flags)
+{
+ register int tlen;
+ int win = 0;
+ struct route *ro = 0;
+ struct route sro;
+
+ if (tp) {
+ win = sbspace(&tp->t_inpcb->inp_socket->so_rcv);
+ ro = &tp->t_inpcb->inp_route;
+ } else {
+ ro = &sro;
+ bzero(ro, sizeof *ro);
+ }
+ if (m == NULL) {
+ m = m_gethdr(M_DONTWAIT, MT_HEADER);
+ if (m == NULL)
+ return;
+#ifdef TCP_COMPAT_42
+ tlen = 1;
+#else
+ tlen = 0;
+#endif
+ m->m_data += max_linkhdr;
+ *mtod(m, struct tcpiphdr *) = *ti;
+ ti = mtod(m, struct tcpiphdr *);
+ flags = TH_ACK;
+ } else {
+ m_freem(m->m_next);
+ m->m_next = NULL;
+ m->m_data = (caddr_t)ti;
+ m->m_len = sizeof (struct tcpiphdr);
+ tlen = 0;
+#define xchg(a,b,type) { type t; t=a; a=b; b=t; }
+ xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, u_long);
+ xchg(ti->ti_dport, ti->ti_sport, u_short);
+#undef xchg
+ }
+ ti->ti_len = htons((u_short)(sizeof (struct tcphdr) + tlen));
+ tlen += sizeof (struct tcpiphdr);
+ m->m_len = tlen;
+ m->m_pkthdr.len = tlen;
+ m->m_pkthdr.rcvif = (struct ifnet *) 0;
+ ti->ti_next = ti->ti_prev = 0;
+ ti->ti_x1 = 0;
+ ti->ti_seq = htonl(seq);
+ ti->ti_ack = htonl(ack);
+ ti->ti_x2 = 0;
+ ti->ti_off = sizeof (struct tcphdr) >> 2;
+ ti->ti_flags = flags;
+ if (tp)
+ ti->ti_win = htons((u_short) (win >> tp->rcv_scale));
+ else
+ ti->ti_win = htons((u_short)win);
+ ti->ti_urp = 0;
+ ti->ti_sum = 0;
+ ti->ti_sum = in_cksum(m, tlen);
+ ((struct ip *)ti)->ip_len = tlen;
+ ((struct ip *)ti)->ip_ttl = ip_defttl;
+#ifdef TCPDEBUG
+ if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
+ tcp_trace(TA_OUTPUT, 0, tp, ti, 0);
+#endif
+ (void) ip_output(m, NULL, ro, 0, NULL);
+ if (ro == &sro && ro->ro_rt) {
+ RTFREE(ro->ro_rt);
+ }
+}
+
+/*
+ * Create a new TCP control block, making an
+ * empty reassembly queue and hooking it to the argument
+ * protocol control block.
+ */
+struct tcpcb *
+tcp_newtcpcb(struct inpcb *inp)
+{
+ struct tcpcb *tp;
+
+ tp = malloc(sizeof(*tp), M_PCB, M_NOWAIT);
+ if (tp == NULL)
+ return ((struct tcpcb *)0);
+ bzero((char *) tp, sizeof(struct tcpcb));
+ tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp;
+ tp->t_maxseg = tp->t_maxopd = tcp_mssdflt;
+
+ if (tcp_do_rfc1323)
+ tp->t_flags = (TF_REQ_SCALE|TF_REQ_TSTMP);
+ tp->t_inpcb = inp;
+ /*
+ * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no
+ * rtt estimate. Set rttvar so that srtt + 4 * rttvar gives
+ * reasonable initial retransmit time.
+ */
+ tp->t_srtt = TCPTV_SRTTBASE;
+ tp->t_rttvar = ((TCPTV_RTOBASE - TCPTV_SRTTBASE) << TCP_RTTVAR_SHIFT) / 4;
+ tp->t_rttmin = TCPTV_MIN;
+ tp->t_rxtcur = TCPTV_RTOBASE;
+ tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT;
+ tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT;
+ inp->inp_ip_ttl = ip_defttl;
+ inp->inp_ppcb = (caddr_t)tp;
+ return (tp);
+}
+
+/*
+ * Drop a TCP connection, reporting
+ * the specified error. If connection is synchronized,
+ * then send a RST to peer.
+ */
+struct tcpcb *
+tcp_drop(struct tcpcb *tp, int errnum)
+{
+ struct socket *so = tp->t_inpcb->inp_socket;
+
+ if (TCPS_HAVERCVDSYN(tp->t_state)) {
+ tp->t_state = TCPS_CLOSED;
+ (void) tcp_output(tp);
+ tcpstat.tcps_drops++;
+ } else
+ tcpstat.tcps_conndrops++;
+ if (errnum == ETIMEDOUT && tp->t_softerror)
+ errnum = tp->t_softerror;
+ so->so_error = errnum;
+ return (tcp_close(tp));
+}
+
+/*
+ * Close a TCP control block:
+ * discard all space held by the tcp
+ * discard internet protocol block
+ * wake up any sleepers
+ */
+struct tcpcb *
+tcp_close(struct tcpcb *tp)
+{
+ register struct tcpiphdr *t;
+ struct inpcb *inp = tp->t_inpcb;
+ struct socket *so = inp->inp_socket;
+ register struct mbuf *m;
+ register struct rtentry *rt;
+
+ /*
+ * If we got enough samples through the srtt filter,
+ * save the rtt and rttvar in the routing entry.
+ * 'Enough' is arbitrarily defined as the 16 samples.
+ * 16 samples is enough for the srtt filter to converge
+ * to within 5% of the correct value; fewer samples and
+ * we could save a very bogus rtt.
+ *
+ * Don't update the default route's characteristics and don't
+ * update anything that the user "locked".
+ */
+ if (tp->t_rttupdated >= 16 &&
+ (rt = inp->inp_route.ro_rt) &&
+ ((struct sockaddr_in *)rt_key(rt))->sin_addr.s_addr != INADDR_ANY) {
+ register u_long i = 0;
+
+ if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) {
+ i = tp->t_srtt *
+ (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTT_SCALE));
+ if (rt->rt_rmx.rmx_rtt && i)
+ /*
+ * filter this update to half the old & half
+ * the new values, converting scale.
+ * See route.h and tcp_var.h for a
+ * description of the scaling constants.
+ */
+ rt->rt_rmx.rmx_rtt =
+ (rt->rt_rmx.rmx_rtt + i) / 2;
+ else
+ rt->rt_rmx.rmx_rtt = i;
+ tcpstat.tcps_cachedrtt++;
+ }
+ if ((rt->rt_rmx.rmx_locks & RTV_RTTVAR) == 0) {
+ i = tp->t_rttvar *
+ (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTTVAR_SCALE));
+ if (rt->rt_rmx.rmx_rttvar && i)
+ rt->rt_rmx.rmx_rttvar =
+ (rt->rt_rmx.rmx_rttvar + i) / 2;
+ else
+ rt->rt_rmx.rmx_rttvar = i;
+ tcpstat.tcps_cachedrttvar++;
+ }
+ /*
+ * update the pipelimit (ssthresh) if it has been updated
+ * already or if a pipesize was specified & the threshhold
+ * got below half the pipesize. I.e., wait for bad news
+ * before we start updating, then update on both good
+ * and bad news.
+ */
+ if (((rt->rt_rmx.rmx_locks & RTV_SSTHRESH) == 0 &&
+ ((i = tp->snd_ssthresh) != 0) && rt->rt_rmx.rmx_ssthresh) ||
+ i < (rt->rt_rmx.rmx_sendpipe / 2)) {
+ /*
+ * convert the limit from user data bytes to
+ * packets then to packet data bytes.
+ */
+ i = (i + tp->t_maxseg / 2) / tp->t_maxseg;
+ if (i < 2)
+ i = 2;
+ i *= (u_long)(tp->t_maxseg + sizeof (struct tcpiphdr));
+ if (rt->rt_rmx.rmx_ssthresh)
+ rt->rt_rmx.rmx_ssthresh =
+ (rt->rt_rmx.rmx_ssthresh + i) / 2;
+ else
+ rt->rt_rmx.rmx_ssthresh = i;
+ tcpstat.tcps_cachedssthresh++;
+ }
+ }
+ /* free the reassembly queue, if any */
+ t = tp->seg_next;
+ while (t != (struct tcpiphdr *)tp) {
+ t = (struct tcpiphdr *)t->ti_next;
+#if (defined(__GNUC__) && (defined(__arm__) || defined(__mips__)))
+ LD32_UNALGN((struct tcpiphdr *)t->ti_prev,m);
+#else
+ m = REASS_MBUF((struct tcpiphdr *)t->ti_prev);
+#endif
+ remque(t->ti_prev);
+ m_freem(m);
+ }
+ if (tp->t_template)
+ (void) m_free(dtom(tp->t_template));
+ free(tp, M_PCB);
+ inp->inp_ppcb = 0;
+ soisdisconnected(so);
+ in_pcbdetach(inp);
+ tcpstat.tcps_closed++;
+ return ((struct tcpcb *)0);
+}
+
+void
+tcp_drain(void)
+{
+
+}
+
+/*
+ * Notify a tcp user of an asynchronous error;
+ * store error as soft error, but wake up user
+ * (for now, won't do anything until can select for soft error).
+ */
+static void
+tcp_notify(struct inpcb *inp, int error)
+{
+ struct tcpcb *tp = (struct tcpcb *)inp->inp_ppcb;
+ struct socket *so = inp->inp_socket;
+
+ /*
+ * Ignore some errors if we are hooked up.
+ * If connection hasn't completed, has retransmitted several times,
+ * and receives a second error, give up now. This is better
+ * than waiting a long time to establish a connection that
+ * can never complete.
+ */
+ if (tp->t_state == TCPS_ESTABLISHED &&
+ (error == EHOSTUNREACH || error == ENETUNREACH ||
+ error == EHOSTDOWN)) {
+ return;
+ } else if (tp->t_state < TCPS_ESTABLISHED && tp->t_rxtshift > 3 &&
+ tp->t_softerror)
+ so->so_error = error;
+ else
+ tp->t_softerror = error;
+ soconnwakeup (so);
+ sorwakeup(so);
+ sowwakeup(so);
+}
+
+#ifdef __rtems__
+#define INP_INFO_RLOCK(a)
+#define INP_INFO_RUNLOCK(a)
+#define INP_LOCK(a)
+#define INP_UNLOCK(a)
+#endif
+
+static int
+tcp_pcblist(SYSCTL_HANDLER_ARGS)
+{
+ int error, i, n, s;
+ struct inpcb *inp, **inp_list;
+ inp_gen_t gencnt;
+ struct xinpgen xig;
+
+ /*
+ * The process of preparing the TCB list is too time-consuming and
+ * resource-intensive to repeat twice on every request.
+ */
+ if (req->oldptr == NULL) {
+ n = tcbinfo.ipi_count;
+ req->oldidx = 2 * (sizeof xig)
+ + (n + n/8) * sizeof(struct xtcpcb);
+ return (0);
+ }
+
+ if (req->newptr != NULL)
+ return (EPERM);
+
+ /*
+ * OK, now we're committed to doing something.
+ */
+ s = splnet();
+ INP_INFO_RLOCK(&tcbinfo);
+ gencnt = tcbinfo.ipi_gencnt;
+ n = tcbinfo.ipi_count;
+ INP_INFO_RUNLOCK(&tcbinfo);
+ splx(s);
+
+ sysctl_wire_old_buffer(req, 2 * (sizeof xig)
+ + n * sizeof(struct xtcpcb));
+
+ xig.xig_len = sizeof xig;
+ xig.xig_count = n;
+ xig.xig_gen = gencnt;
+/* xig.xig_sogen = so_gencnt; remove by ccj */
+ error = SYSCTL_OUT(req, &xig, sizeof xig);
+ if (error)
+ return error;
+
+ /* ccj add exit if the count is 0 */
+ if (!n)
+ return error;
+
+ inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
+ if (inp_list == 0)
+ return ENOMEM;
+
+ s = splnet();
+ INP_INFO_RLOCK(&tcbinfo);
+ for (inp = LIST_FIRST(tcbinfo.listhead), i = 0; inp && i < n;
+ inp = LIST_NEXT(inp, inp_list)) {
+ INP_LOCK(inp);
+ if (inp->inp_gencnt <= gencnt)
+#if 0
+ &&
+ cr_canseesocket(req->td->td_ucred, inp->inp_socket) == 0)
+#endif
+ inp_list[i++] = inp;
+ INP_UNLOCK(inp);
+ }
+ INP_INFO_RUNLOCK(&tcbinfo);
+ splx(s);
+ n = i;
+
+ error = 0;
+ for (i = 0; i < n; i++) {
+ inp = inp_list[i];
+ INP_LOCK(inp);
+ if (inp->inp_gencnt <= gencnt) {
+ struct xtcpcb xt;
+ caddr_t inp_ppcb;
+ xt.xt_len = sizeof xt;
+ /* XXX should avoid extra copy */
+ bcopy(inp, &xt.xt_inp, sizeof *inp);
+ inp_ppcb = inp->inp_ppcb;
+ if (inp_ppcb != NULL)
+ bcopy(inp_ppcb, &xt.xt_tp, sizeof xt.xt_tp);
+ else
+ bzero((char *) &xt.xt_tp, sizeof xt.xt_tp);
+#if 0
+ if (inp->inp_socket)
+ sotoxsocket(inp->inp_socket, &xt.xt_socket);
+#endif
+ error = SYSCTL_OUT(req, &xt, sizeof xt);
+ }
+ INP_UNLOCK(inp);
+ }
+ if (!error) {
+ /*
+ * Give the user an updated idea of our state.
+ * If the generation differs from what we told
+ * her before, she knows that something happened
+ * while we were processing this request, and it
+ * might be necessary to retry.
+ */
+ s = splnet();
+ INP_INFO_RLOCK(&tcbinfo);
+ xig.xig_gen = tcbinfo.ipi_gencnt;
+#if 0
+ xig.xig_sogen = so_gencnt;
+#endif
+ xig.xig_count = tcbinfo.ipi_count;
+ INP_INFO_RUNLOCK(&tcbinfo);
+ splx(s);
+ error = SYSCTL_OUT(req, &xig, sizeof xig);
+ }
+ free(inp_list, M_TEMP);
+ return error;
+}
+
+SYSCTL_PROC(_net_inet_tcp, TCPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
+ tcp_pcblist, "S,xtcpcb", "List of active TCP connections");
+
+void
+tcp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
+{
+ struct ip *ip = vip;
+ struct tcphdr *th;
+ void (*notify)(struct inpcb *, int) = tcp_notify;
+
+ if (cmd == PRC_QUENCH)
+ notify = tcp_quench;
+#if 1
+ else if (cmd == PRC_MSGSIZE)
+ notify = tcp_mtudisc;
+#endif
+ else if (!PRC_IS_REDIRECT(cmd) &&
+ ((unsigned)cmd > PRC_NCMDS || inetctlerrmap[cmd] == 0))
+ return;
+ if (ip != NULL) {
+#ifdef _IP_VHL
+ th = (struct tcphdr *)((caddr_t)ip
+ + (IP_VHL_HL(ip->ip_vhl) << 2));
+#else
+ th = (struct tcphdr *)((caddr_t)ip
+ + (ip->ip_hl << 2));
+#endif
+ in_pcbnotify(&tcb, sa, th->th_dport, ip->ip_src, th->th_sport,
+ cmd, notify);
+ } else
+ in_pcbnotify(&tcb, sa, 0, zeroin_addr, 0, cmd, notify);
+}
+
+/*
+ * When a source quench is received, close congestion window
+ * to one segment. We will gradually open it again as we proceed.
+ */
+void
+tcp_quench( struct inpcb *inp, int errnum)
+{
+ struct tcpcb *tp = intotcpcb(inp);
+
+ if (tp)
+ tp->snd_cwnd = tp->t_maxseg;
+}
+
+/*
+ * When `need fragmentation' ICMP is received, update our idea of the MSS
+ * based on the new value in the route. Also nudge TCP to send something,
+ * since we know the packet we just sent was dropped.
+ * This duplicates some code in the tcp_mss() function in tcp_input.c.
+ */
+void
+tcp_mtudisc(struct inpcb *inp, int errnum)
+{
+ struct tcpcb *tp = intotcpcb(inp);
+ struct rtentry *rt;
+ struct rmxp_tao *taop;
+ struct socket *so = inp->inp_socket;
+ int offered;
+ int mss;
+
+ if (tp) {
+ rt = tcp_rtlookup(inp);
+ if (!rt || !rt->rt_rmx.rmx_mtu) {
+ tp->t_maxopd = tp->t_maxseg = tcp_mssdflt;
+ return;
+ }
+ taop = rmx_taop(rt->rt_rmx);
+ offered = taop->tao_mssopt;
+ mss = rt->rt_rmx.rmx_mtu - sizeof(struct tcpiphdr);
+ if (offered)
+ mss = min(mss, offered);
+ /*
+ * XXX - The above conditional probably violates the TCP
+ * spec. The problem is that, since we don't know the
+ * other end's MSS, we are supposed to use a conservative
+ * default. But, if we do that, then MTU discovery will
+ * never actually take place, because the conservative
+ * default is much less than the MTUs typically seen
+ * on the Internet today. For the moment, we'll sweep
+ * this under the carpet.
+ *
+ * The conservative default might not actually be a problem
+ * if the only case this occurs is when sending an initial
+ * SYN with options and data to a host we've never talked
+ * to before. Then, they will reply with an MSS value which
+ * will get recorded and the new parameters should get
+ * recomputed. For Further Study.
+ */
+ if (tp->t_maxopd <= mss)
+ return;
+ tp->t_maxopd = mss;
+
+ if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
+ (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP)
+ mss -= TCPOLEN_TSTAMP_APPA;
+ if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
+ (tp->t_flags & TF_RCVD_CC) == TF_RCVD_CC)
+ mss -= TCPOLEN_CC_APPA;
+#if (MCLBYTES & (MCLBYTES - 1)) == 0
+ if (mss > MCLBYTES)
+ mss &= ~(MCLBYTES-1);
+#else
+ if (mss > MCLBYTES)
+ mss = mss / MCLBYTES * MCLBYTES;
+#endif
+ if (so->so_snd.sb_hiwat < mss)
+ mss = so->so_snd.sb_hiwat;
+
+ tp->t_maxseg = mss;
+
+ tcpstat.tcps_mturesent++;
+ tp->t_rtt = 0;
+ tp->snd_nxt = tp->snd_una;
+ tcp_output(tp);
+ }
+}
+
+/*
+ * Look-up the routing entry to the peer of this inpcb. If no route
+ * is found and it cannot be allocated, then return NULL. This routine
+ * is called by TCP routines that access the rmx structure and by tcp_mss
+ * to get the interface MTU.
+ */
+struct rtentry *
+tcp_rtlookup(struct inpcb *inp)
+{
+ struct route *ro;
+ struct rtentry *rt;
+
+ ro = &inp->inp_route;
+ rt = ro->ro_rt;
+ if (rt == NULL || !(rt->rt_flags & RTF_UP)) {
+ /* No route yet, so try to acquire one */
+ if (inp->inp_faddr.s_addr != INADDR_ANY) {
+ ro->ro_dst.sa_family = AF_INET;
+ ro->ro_dst.sa_len = sizeof(ro->ro_dst);
+ ((struct sockaddr_in *) &ro->ro_dst)->sin_addr =
+ inp->inp_faddr;
+ rtalloc(ro);
+ rt = ro->ro_rt;
+ }
+ }
+ return rt;
+}
+
+/*
+ * Return a pointer to the cached information about the remote host.
+ * The cached information is stored in the protocol specific part of
+ * the route metrics.
+ */
+struct rmxp_tao *
+tcp_gettaocache(struct inpcb *inp)
+{
+ struct rtentry *rt = tcp_rtlookup(inp);
+
+ /* Make sure this is a host route and is up. */
+ if (rt == NULL ||
+ (rt->rt_flags & (RTF_UP|RTF_HOST)) != (RTF_UP|RTF_HOST))
+ return NULL;
+
+ return rmx_taop(rt->rt_rmx);
+}
diff --git a/cpukit/libnetworking/netinet/tcp_timer.c b/cpukit/libnetworking/netinet/tcp_timer.c
new file mode 100644
index 0000000000..174368780c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_timer.c
@@ -0,0 +1,384 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_tcpdebug.h"
+
+#ifndef TUBA_INCLUDE
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <errno.h>
+
+#include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#ifdef TCPDEBUG
+#include <netinet/tcp_debug.h>
+#endif
+
+int tcp_keepinit = TCPTV_KEEP_INIT;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_KEEPINIT, keepinit,
+ CTLFLAG_RW, &tcp_keepinit , 0, "");
+
+int tcp_keepidle = TCPTV_KEEP_IDLE;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_KEEPIDLE, keepidle,
+ CTLFLAG_RW, &tcp_keepidle , 0, "");
+
+static int tcp_keepintvl = TCPTV_KEEPINTVL;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_KEEPINTVL, keepintvl,
+ CTLFLAG_RW, &tcp_keepintvl , 0, "");
+
+static int always_keepalive = 0;
+SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive,
+ CTLFLAG_RW, &always_keepalive , 0, "");
+
+static int tcp_keepcnt = TCPTV_KEEPCNT;
+ /* max idle probes */
+static int tcp_maxpersistidle = TCPTV_KEEP_IDLE;
+ /* max idle time in persist */
+int tcp_maxidle;
+#else /* TUBA_INCLUDE */
+
+static int tcp_maxpersistidle;
+#endif /* TUBA_INCLUDE */
+
+/*
+ * Fast timeout routine for processing delayed acks
+ */
+void
+tcp_fasttimo(void)
+{
+ register struct inpcb *inp;
+ register struct tcpcb *tp;
+ int s;
+
+ s = splnet();
+
+ for (inp = tcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
+ if ((tp = (struct tcpcb *)inp->inp_ppcb) &&
+ (tp->t_flags & TF_DELACK)) {
+ tp->t_flags &= ~TF_DELACK;
+ tp->t_flags |= TF_ACKNOW;
+ tcpstat.tcps_delack++;
+ (void) tcp_output(tp);
+ }
+ }
+ splx(s);
+}
+
+/*
+ * Tcp protocol timeout routine called every 500 ms.
+ * Updates the timers in all active tcb's and
+ * causes finite state machine actions if timers expire.
+ */
+void
+tcp_slowtimo(void)
+{
+ register struct inpcb *ip, *ipnxt;
+ register struct tcpcb *tp;
+ register int i;
+ int s;
+#ifdef TCPDEBUG
+ int ostate;
+#endif
+
+ s = splnet();
+
+ tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
+
+ ip = tcb.lh_first;
+ if (ip == NULL) {
+ splx(s);
+ return;
+ }
+ /*
+ * Search through tcb's and update active timers.
+ */
+ for (; ip != NULL; ip = ipnxt) {
+ ipnxt = ip->inp_list.le_next;
+ tp = intotcpcb(ip);
+ if (tp == 0 || tp->t_state == TCPS_LISTEN)
+ continue;
+ for (i = 0; i < TCPT_NTIMERS; i++) {
+ if (tp->t_timer[i] && --tp->t_timer[i] == 0) {
+#ifdef TCPDEBUG
+ ostate = tp->t_state;
+#endif
+ tp = tcp_timers(tp, i);
+ if (tp == NULL)
+ goto tpgone;
+#ifdef TCPDEBUG
+ if (tp->t_inpcb->inp_socket->so_options
+ & SO_DEBUG)
+ tcp_trace(TA_USER, ostate, tp,
+ (struct tcpiphdr *)0,
+ PRU_SLOWTIMO);
+#endif
+ }
+ }
+ tp->t_idle++;
+ tp->t_duration++;
+ if (tp->t_rtt)
+ tp->t_rtt++;
+tpgone:
+ ;
+ }
+ tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */
+#ifdef TCP_COMPAT_42
+ if ((int)tcp_iss < 0)
+ tcp_iss = TCP_ISSINCR; /* XXX */
+#endif
+ tcp_now++; /* for timestamps */
+ splx(s);
+}
+#ifndef TUBA_INCLUDE
+
+/*
+ * Cancel all timers for TCP tp.
+ */
+void
+tcp_canceltimers(struct tcpcb *tp)
+{
+ register int i;
+
+ for (i = 0; i < TCPT_NTIMERS; i++)
+ tp->t_timer[i] = 0;
+}
+
+int tcp_backoff[TCP_MAXRXTSHIFT + 1] =
+ { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
+
+static int tcp_totbackoff = 511; /* sum of tcp_backoff[] */
+
+/*
+ * TCP timer processing.
+ */
+struct tcpcb *
+tcp_timers(struct tcpcb *tp, int timer)
+{
+ register int rexmt;
+
+ switch (timer) {
+
+ /*
+ * 2 MSL timeout in shutdown went off. If we're closed but
+ * still waiting for peer to close and connection has been idle
+ * too long, or if 2MSL time is up from TIME_WAIT, delete connection
+ * control block. Otherwise, check again in a bit.
+ */
+ case TCPT_2MSL:
+ if (tp->t_state != TCPS_TIME_WAIT &&
+ tp->t_idle <= tcp_maxidle)
+ tp->t_timer[TCPT_2MSL] = tcp_keepintvl;
+ else
+ tp = tcp_close(tp);
+ break;
+
+ /*
+ * Retransmission timer went off. Message has not
+ * been acked within retransmit interval. Back off
+ * to a longer retransmit interval and retransmit one segment.
+ */
+ case TCPT_REXMT:
+ if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
+ tp->t_rxtshift = TCP_MAXRXTSHIFT;
+ tcpstat.tcps_timeoutdrop++;
+ tp = tcp_drop(tp, tp->t_softerror ?
+ tp->t_softerror : ETIMEDOUT);
+ break;
+ }
+ tcpstat.tcps_rexmttimeo++;
+ rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
+ TCPT_RANGESET(tp->t_rxtcur, rexmt,
+ tp->t_rttmin, TCPTV_REXMTMAX);
+ tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
+ /*
+ * If losing, let the lower level know and try for
+ * a better route. Also, if we backed off this far,
+ * our srtt estimate is probably bogus. Clobber it
+ * so we'll take the next rtt measurement as our srtt;
+ * move the current srtt into rttvar to keep the current
+ * retransmit times until then.
+ */
+ if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
+ in_losing(tp->t_inpcb);
+ tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
+ tp->t_srtt = 0;
+ }
+ tp->snd_nxt = tp->snd_una;
+ /*
+ * Force a segment to be sent.
+ */
+ tp->t_flags |= TF_ACKNOW;
+ /*
+ * If timing a segment in this window, stop the timer.
+ */
+ tp->t_rtt = 0;
+ /*
+ * Close the congestion window down to one segment
+ * (we'll open it by one segment for each ack we get).
+ * Since we probably have a window's worth of unacked
+ * data accumulated, this "slow start" keeps us from
+ * dumping all that data as back-to-back packets (which
+ * might overwhelm an intermediate gateway).
+ *
+ * There are two phases to the opening: Initially we
+ * open by one mss on each ack. This makes the window
+ * size increase exponentially with time. If the
+ * window is larger than the path can handle, this
+ * exponential growth results in dropped packet(s)
+ * almost immediately. To get more time between
+ * drops but still "push" the network to take advantage
+ * of improving conditions, we switch from exponential
+ * to linear window opening at some threshhold size.
+ * For a threshhold, we use half the current window
+ * size, truncated to a multiple of the mss.
+ *
+ * (the minimum cwnd that will give us exponential
+ * growth is 2 mss. We don't allow the threshhold
+ * to go below this.)
+ */
+ {
+ u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
+ if (win < 2)
+ win = 2;
+ tp->snd_cwnd = tp->t_maxseg;
+ tp->snd_ssthresh = win * tp->t_maxseg;
+ tp->t_dupacks = 0;
+ }
+ (void) tcp_output(tp);
+ break;
+
+ /*
+ * Persistance timer into zero window.
+ * Force a byte to be output, if possible.
+ */
+ case TCPT_PERSIST:
+ tcpstat.tcps_persisttimeo++;
+ /*
+ * Hack: if the peer is dead/unreachable, we do not
+ * time out if the window is closed. After a full
+ * backoff, drop the connection if the idle time
+ * (no responses to probes) reaches the maximum
+ * backoff that we would use if retransmitting.
+ */
+ if (tp->t_rxtshift == TCP_MAXRXTSHIFT) {
+ u_long maxidle = TCP_REXMTVAL(tp);
+ if (maxidle < tp->t_rttmin)
+ maxidle = tp->t_rttmin;
+ maxidle *= tcp_totbackoff;
+ if (tp->t_idle >= tcp_maxpersistidle ||
+ tp->t_idle >= maxidle) {
+ tcpstat.tcps_persistdrop++;
+ tp = tcp_drop(tp, ETIMEDOUT);
+ break;
+ }
+ }
+ tcp_setpersist(tp);
+ tp->t_force = 1;
+ (void) tcp_output(tp);
+ tp->t_force = 0;
+ break;
+
+ /*
+ * Keep-alive timer went off; send something
+ * or drop connection if idle for too long.
+ */
+ case TCPT_KEEP:
+ tcpstat.tcps_keeptimeo++;
+ if (tp->t_state < TCPS_ESTABLISHED)
+ goto dropit;
+ if ((always_keepalive ||
+ tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) &&
+ tp->t_state <= TCPS_CLOSING) {
+ if (tp->t_idle >= tcp_keepidle + tcp_maxidle)
+ goto dropit;
+ /*
+ * Send a packet designed to force a response
+ * if the peer is up and reachable:
+ * either an ACK if the connection is still alive,
+ * or an RST if the peer has closed the connection
+ * due to timeout or reboot.
+ * Using sequence number tp->snd_una-1
+ * causes the transmitted zero-length segment
+ * to lie outside the receive window;
+ * by the protocol spec, this requires the
+ * correspondent TCP to respond.
+ */
+ tcpstat.tcps_keepprobe++;
+#ifdef TCP_COMPAT_42
+ /*
+ * The keepalive packet must have nonzero length
+ * to get a 4.2 host to respond.
+ */
+ tcp_respond(tp, tp->t_template, (struct mbuf *)NULL,
+ tp->rcv_nxt - 1, tp->snd_una - 1, 0);
+#else
+ tcp_respond(tp, tp->t_template, (struct mbuf *)NULL,
+ tp->rcv_nxt, tp->snd_una - 1, 0);
+#endif
+ tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
+ } else
+ tp->t_timer[TCPT_KEEP] = tcp_keepidle;
+ break;
+ dropit:
+ tcpstat.tcps_keepdrops++;
+ tp = tcp_drop(tp, ETIMEDOUT);
+ break;
+ }
+ return (tp);
+}
+#endif /* TUBA_INCLUDE */
diff --git a/cpukit/libnetworking/netinet/tcp_timer.h b/cpukit/libnetworking/netinet/tcp_timer.h
new file mode 100644
index 0000000000..4bbbb712b6
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_timer.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/tcp_timer.h,v 1.26 2004/08/16 18:32:07 rwatson Exp $
+ */
+
+#ifndef _NETINET_TCP_TIMER_H_
+#define _NETINET_TCP_TIMER_H_
+
+/*
+ * Definitions of the TCP timers. These timers are counted
+ * down PR_SLOWHZ times a second.
+ */
+#define TCPT_NTIMERS 4
+
+#define TCPT_REXMT 0 /* retransmit */
+#define TCPT_PERSIST 1 /* retransmit persistence */
+#define TCPT_KEEP 2 /* keep alive */
+#define TCPT_2MSL 3 /* 2*msl quiet time timer */
+
+/*
+ * The TCPT_REXMT timer is used to force retransmissions.
+ * The TCP has the TCPT_REXMT timer set whenever segments
+ * have been sent for which ACKs are expected but not yet
+ * received. If an ACK is received which advances tp->snd_una,
+ * then the retransmit timer is cleared (if there are no more
+ * outstanding segments) or reset to the base value (if there
+ * are more ACKs expected). Whenever the retransmit timer goes off,
+ * we retransmit one unacknowledged segment, and do a backoff
+ * on the retransmit timer.
+ *
+ * The TCPT_PERSIST timer is used to keep window size information
+ * flowing even if the window goes shut. If all previous transmissions
+ * have been acknowledged (so that there are no retransmissions in progress),
+ * and the window is too small to bother sending anything, then we start
+ * the TCPT_PERSIST timer. When it expires, if the window is nonzero,
+ * we go to transmit state. Otherwise, at intervals send a single byte
+ * into the peer's window to force him to update our window information.
+ * We do this at most as often as TCPT_PERSMIN time intervals,
+ * but no more frequently than the current estimate of round-trip
+ * packet time. The TCPT_PERSIST timer is cleared whenever we receive
+ * a window update from the peer.
+ *
+ * The TCPT_KEEP timer is used to keep connections alive. If an
+ * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
+ * but not yet established, then we drop the connection. Once the connection
+ * is established, if the connection is idle for TCPTV_KEEP_IDLE time
+ * (and keepalives have been enabled on the socket), we begin to probe
+ * the connection. We force the peer to send us a segment by sending:
+ * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
+ * This segment is (deliberately) outside the window, and should elicit
+ * an ack segment in response from the peer. If, despite the TCPT_KEEP
+ * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
+ * amount of time probing, then we drop the connection.
+ */
+
+/*
+ * Time constants.
+ */
+#define TCPTV_MSL ( 30*PR_SLOWHZ) /* max seg lifetime (hah!) */
+#define TCPTV_SRTTBASE 0 /* base roundtrip time;
+ if 0, no idea yet */
+#define TCPTV_RTOBASE ( 3*PR_SLOWHZ) /* assumed RTO if no info */
+#define TCPTV_SRTTDFLT ( 3*PR_SLOWHZ) /* assumed RTT if no info */
+
+#define TCPTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistence */
+#define TCPTV_PERSMAX ( 60*PR_SLOWHZ) /* maximum persist interval */
+
+#define TCPTV_KEEP_INIT ( 75*PR_SLOWHZ) /* initial connect keep alive */
+#define TCPTV_KEEP_IDLE (120*60*PR_SLOWHZ) /* dflt time before probing */
+#define TCPTV_KEEPINTVL ( 75*PR_SLOWHZ) /* default probe interval */
+#define TCPTV_KEEPCNT 8 /* max probes before drop */
+
+#define TCPTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */
+#define TCPTV_REXMTMAX ( 64*PR_SLOWHZ) /* max allowable REXMT value */
+
+#define TCPTV_TWTRUNC 8 /* RTO factor to truncate TW */
+
+#define TCP_LINGERTIME 120 /* linger at most 2 minutes */
+
+#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */
+
+#ifdef TCPTIMERS
+static char *tcptimers[] =
+ { "REXMT", "PERSIST", "KEEP", "2MSL" };
+#endif
+
+/*
+ * Force a time value to be in a certain range.
+ */
+#define TCPT_RANGESET(tv, value, tvmin, tvmax) { \
+ (tv) = (value); \
+ if ((u_long)(tv) < (u_long)(tvmin)) \
+ (tv) = (tvmin); \
+ else if ((u_long)(tv) > (u_long)(tvmax)) \
+ (tv) = (tvmax); \
+}
+
+#ifdef _KERNEL
+extern int tcp_keepinit; /* time to establish connection */
+extern int tcp_keepidle; /* time before keepalive probes begin */
+extern int tcp_maxidle; /* time to drop after starting probes */
+extern int tcp_ttl; /* time to live for TCP segs */
+extern int tcp_backoff[];
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/netinet/tcp_usrreq.c b/cpukit/libnetworking/netinet/tcp_usrreq.c
new file mode 100644
index 0000000000..0771f7e4e0
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_usrreq.c
@@ -0,0 +1,845 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
+ * $FreeBSD: src/sys/netinet/tcp_usrreq.c,v 1.120 2005/05/01 14:01:38 rwatson Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "opt_tcpdebug.h"
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/tcpip.h>
+#ifdef TCPDEBUG
+#include <netinet/tcp_debug.h>
+#endif
+
+/*
+ * TCP protocol interface to socket abstraction.
+ */
+extern char *tcpstates[];
+
+static int tcp_attach(struct socket *);
+static int tcp_connect(struct tcpcb *, struct mbuf *);
+static struct tcpcb *
+ tcp_disconnect(struct tcpcb *);
+static struct tcpcb *
+ tcp_usrclosed(struct tcpcb *);
+
+#ifdef TCPDEBUG
+#define TCPDEBUG0 int ostate
+#define TCPDEBUG1() ostate = tp ? tp->t_state : 0
+#define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
+ tcp_trace(TA_USER, ostate, tp, 0, req)
+#else
+#define TCPDEBUG0
+#define TCPDEBUG1()
+#define TCPDEBUG2(req)
+#endif
+
+/*
+ * TCP attaches to socket via pru_attach(), reserving space,
+ * and an internet control block.
+ */
+static int
+tcp_usr_attach(struct socket *so, intptr_t proto)
+{
+ int s = splnet();
+ int error;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp = 0;
+ TCPDEBUG0;
+
+ TCPDEBUG1();
+ if (inp) {
+ error = EISCONN;
+ goto out;
+ }
+
+ error = tcp_attach(so);
+ if (error)
+ goto out;
+
+ if ((so->so_options & SO_LINGER) && so->so_linger == 0)
+ so->so_linger = TCP_LINGERTIME * hz;
+ tp = sototcpcb(so);
+out:
+ TCPDEBUG2(PRU_ATTACH);
+ splx(s);
+ return error;
+}
+
+/*
+ * pru_detach() detaches the TCP protocol from the socket.
+ * If the protocol state is non-embryonic, then can't
+ * do this directly: have to initiate a pru_disconnect(),
+ * which may finish later; embryonic TCB's can just
+ * be discarded here.
+ */
+static int
+tcp_usr_detach(struct socket *so)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+ TCPDEBUG0;
+
+ if (inp == 0) {
+ splx(s);
+ return EINVAL; /* XXX */
+ }
+ tp = intotcpcb(inp);
+ TCPDEBUG1();
+ if (tp->t_state > TCPS_LISTEN)
+ tp = tcp_disconnect(tp);
+ else
+ tp = tcp_close(tp);
+
+ TCPDEBUG2(PRU_DETACH);
+ splx(s);
+ return error;
+}
+
+#define COMMON_START() TCPDEBUG0; \
+ do { \
+ if (inp == 0) { \
+ splx(s); \
+ return EINVAL; \
+ } \
+ tp = intotcpcb(inp); \
+ TCPDEBUG1(); \
+ } while(0)
+
+#define COMMON_END(req) out: TCPDEBUG2(req); splx(s); return error; goto out
+
+
+/*
+ * Give the socket an address.
+ */
+static int
+tcp_usr_bind(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+ struct sockaddr_in *sinp;
+
+ COMMON_START();
+
+ /*
+ * Must check for multicast addresses and disallow binding
+ * to them.
+ */
+ sinp = mtod(nam, struct sockaddr_in *);
+ if (sinp->sin_family == AF_INET &&
+ IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
+ error = EAFNOSUPPORT;
+ goto out;
+ }
+ error = in_pcbbind(inp, nam);
+ if (error)
+ goto out;
+ COMMON_END(PRU_BIND);
+
+}
+
+/*
+ * Prepare to accept connections.
+ */
+static int
+tcp_usr_listen(struct socket *so)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ if (inp->inp_lport == 0)
+ error = in_pcbbind(inp, NULL);
+ if (error == 0)
+ tp->t_state = TCPS_LISTEN;
+ COMMON_END(PRU_LISTEN);
+}
+
+/*
+ * Initiate connection to peer.
+ * Create a template for use in transmissions on this connection.
+ * Enter SYN_SENT state, and mark socket as connecting.
+ * Start keep-alive timer, and seed output sequence space.
+ * Send initial segment on connection.
+ */
+static int
+tcp_usr_connect(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+ struct sockaddr_in *sinp;
+
+ COMMON_START();
+
+ /*
+ * Must disallow TCP ``connections'' to multicast addresses.
+ */
+ sinp = mtod(nam, struct sockaddr_in *);
+ if (sinp->sin_family == AF_INET
+ && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
+ error = EAFNOSUPPORT;
+ goto out;
+ }
+
+ if ((error = tcp_connect(tp, nam)) != 0)
+ goto out;
+ error = tcp_output(tp);
+ COMMON_END(PRU_CONNECT);
+}
+
+/*
+ * Initiate disconnect from peer.
+ * If connection never passed embryonic stage, just drop;
+ * else if don't need to let data drain, then can just drop anyways,
+ * else have to begin TCP shutdown process: mark socket disconnecting,
+ * drain unread data, state switch to reflect user close, and
+ * send segment (e.g. FIN) to peer. Socket will be really disconnected
+ * when peer sends FIN and acks ours.
+ *
+ * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
+ */
+static int
+tcp_usr_disconnect(struct socket *so)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ tp = tcp_disconnect(tp);
+ COMMON_END(PRU_DISCONNECT);
+}
+
+/*
+ * Accept a connection. Essentially all the work is
+ * done at higher levels; just return the address
+ * of the peer, storing through addr.
+ */
+static int
+tcp_usr_accept(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ in_setpeeraddr(inp, nam);
+ COMMON_END(PRU_ACCEPT);
+}
+
+/*
+ * Mark the connection as being incapable of further output.
+ */
+static int
+tcp_usr_shutdown(struct socket *so)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ socantsendmore(so);
+ tp = tcp_usrclosed(tp);
+ if (tp)
+ error = tcp_output(tp);
+ COMMON_END(PRU_SHUTDOWN);
+}
+
+/*
+ * After a receive, possibly send window update to peer.
+ */
+static int
+tcp_usr_rcvd(struct socket *so, intptr_t flags)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ tcp_output(tp);
+ COMMON_END(PRU_RCVD);
+}
+
+/*
+ * Do a send by putting data in output queue and updating urgent
+ * marker if URG set. Possibly send more data.
+ */
+static int
+tcp_usr_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
+ struct mbuf *control)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ if (control && control->m_len) {
+ m_freem(control); /* XXX shouldn't caller do this??? */
+ if (m)
+ m_freem(m);
+ error = EINVAL;
+ goto out;
+ }
+
+ if(!(flags & PRUS_OOB)) {
+ sbappend(&so->so_snd, m);
+ if (nam && tp->t_state < TCPS_SYN_SENT) {
+ /*
+ * Do implied connect if not yet connected,
+ * initialize window to default value, and
+ * initialize maxseg/maxopd using peer's cached
+ * MSS.
+ */
+ error = tcp_connect(tp, nam);
+ if (error)
+ goto out;
+ tp->snd_wnd = TTCP_CLIENT_SND_WND;
+ tcp_mss(tp, -1);
+ }
+
+ if (flags & PRUS_EOF) {
+ /*
+ * Close the send side of the connection after
+ * the data is sent.
+ */
+ socantsendmore(so);
+ tp = tcp_usrclosed(tp);
+ }
+ if (tp != NULL)
+ error = tcp_output(tp);
+ } else {
+ if (sbspace(&so->so_snd) < -512) {
+ m_freem(m);
+ error = ENOBUFS;
+ goto out;
+ }
+ /*
+ * According to RFC961 (Assigned Protocols),
+ * the urgent pointer points to the last octet
+ * of urgent data. We continue, however,
+ * to consider it to indicate the first octet
+ * of data past the urgent section.
+ * Otherwise, snd_up should be one lower.
+ */
+ sbappend(&so->so_snd, m);
+ if (nam && tp->t_state < TCPS_SYN_SENT) {
+ /*
+ * Do implied connect if not yet connected,
+ * initialize window to default value, and
+ * initialize maxseg/maxopd using peer's cached
+ * MSS.
+ */
+ error = tcp_connect(tp, nam);
+ if (error)
+ goto out;
+ tp->snd_wnd = TTCP_CLIENT_SND_WND;
+ tcp_mss(tp, -1);
+ }
+ tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
+ tp->t_force = 1;
+ error = tcp_output(tp);
+ tp->t_force = 0;
+ }
+ COMMON_END((flags & PRUS_OOB) ? PRU_SENDOOB :
+ ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
+}
+
+/*
+ * Abort the TCP.
+ */
+static int
+tcp_usr_abort(struct socket *so)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ tp = tcp_drop(tp, ECONNABORTED);
+ COMMON_END(PRU_ABORT);
+}
+
+/*
+ * Fill in st_bklsize for fstat() operations on a socket.
+ */
+static int
+tcp_usr_sense(struct socket *so, struct stat *sb)
+{
+ int s = splnet();
+
+ sb->st_blksize = so->so_snd.sb_hiwat;
+ splx(s);
+ return 0;
+}
+
+/*
+ * Receive out-of-band data.
+ */
+static int
+tcp_usr_rcvoob(struct socket *so, struct mbuf *m, intptr_t flags)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ if ((so->so_oobmark == 0 &&
+ (so->so_state & SS_RCVATMARK) == 0) ||
+ so->so_options & SO_OOBINLINE ||
+ tp->t_oobflags & TCPOOB_HADDATA) {
+ error = EINVAL;
+ goto out;
+ }
+ if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
+ error = EWOULDBLOCK;
+ goto out;
+ }
+ m->m_len = 1;
+ *mtod(m, caddr_t) = tp->t_iobc;
+ if ((flags & MSG_PEEK) == 0)
+ tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
+ COMMON_END(PRU_RCVOOB);
+}
+
+static int
+tcp_usr_sockaddr(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ in_setsockaddr(inp, nam);
+ COMMON_END(PRU_SOCKADDR);
+}
+
+static int
+tcp_usr_peeraddr(struct socket *so, struct mbuf *nam)
+{
+ int s = splnet();
+ int error = 0;
+ struct inpcb *inp = sotoinpcb(so);
+ struct tcpcb *tp;
+
+ COMMON_START();
+ in_setpeeraddr(inp, nam);
+ COMMON_END(PRU_PEERADDR);
+}
+
+/*
+ * XXX - this should just be a call to in_control, but we need to get
+ * the types worked out.
+ */
+static int
+tcp_usr_control(struct socket *so, intptr_t cmd, caddr_t arg, struct ifnet *ifp)
+{
+ return in_control(so, cmd, arg, ifp);
+}
+
+/* xxx - should be const */
+struct pr_usrreqs tcp_usrreqs = {
+ tcp_usr_abort, tcp_usr_accept, tcp_usr_attach, tcp_usr_bind,
+ tcp_usr_connect, pru_connect2_notsupp, tcp_usr_control, tcp_usr_detach,
+ tcp_usr_disconnect, tcp_usr_listen, tcp_usr_peeraddr, tcp_usr_rcvd,
+ tcp_usr_rcvoob, tcp_usr_send, tcp_usr_sense, tcp_usr_shutdown,
+ tcp_usr_sockaddr
+};
+
+/*
+ * Common subroutine to open a TCP connection to remote host specified
+ * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
+ * port number if needed. Call in_pcbladdr to do the routing and to choose
+ * a local host address (interface). If there is an existing incarnation
+ * of the same connection in TIME-WAIT state and if the remote host was
+ * sending CC options and if the connection duration was < MSL, then
+ * truncate the previous TIME-WAIT state and proceed.
+ * Initialize connection parameters and enter SYN-SENT state.
+ */
+static int
+tcp_connect(struct tcpcb *tp, struct mbuf *nam)
+{
+ struct inpcb *inp = tp->t_inpcb, *oinp;
+ struct socket *so = inp->inp_socket;
+ struct tcpcb *otp;
+ struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
+ struct sockaddr_in *ifaddr;
+ int error;
+ struct rmxp_tao *taop;
+ struct rmxp_tao tao_noncached;
+
+ if (inp->inp_lport == 0) {
+ error = in_pcbbind(inp, NULL);
+ if (error)
+ return error;
+ }
+
+ /*
+ * Cannot simply call in_pcbconnect, because there might be an
+ * earlier incarnation of this same connection still in
+ * TIME_WAIT state, creating an ADDRINUSE error.
+ */
+ error = in_pcbladdr(inp, nam, &ifaddr);
+ if (error)
+ return error;
+ oinp = in_pcblookuphash(inp->inp_pcbinfo,
+ sin->sin_addr, sin->sin_port,
+ inp->inp_laddr.s_addr != INADDR_ANY ? inp->inp_laddr
+ : ifaddr->sin_addr,
+ inp->inp_lport, 0);
+ if (oinp) {
+ if (oinp != inp && (otp = intotcpcb(oinp)) != NULL &&
+ otp->t_state == TCPS_TIME_WAIT &&
+ otp->t_duration < TCPTV_MSL &&
+ (otp->t_flags & TF_RCVD_CC))
+ otp = tcp_close(otp);
+ else
+ return EADDRINUSE;
+ }
+ if (inp->inp_laddr.s_addr == INADDR_ANY)
+ inp->inp_laddr = ifaddr->sin_addr;
+ inp->inp_faddr = sin->sin_addr;
+ inp->inp_fport = sin->sin_port;
+ in_pcbrehash(inp);
+
+ tp->t_template = tcp_template(tp);
+ if (tp->t_template == 0) {
+ in_pcbdisconnect(inp);
+ return ENOBUFS;
+ }
+
+ /* Compute window scaling to request. */
+ while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
+ (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
+ tp->request_r_scale++;
+
+ soisconnecting(so);
+ tcpstat.tcps_connattempt++;
+ tp->t_state = TCPS_SYN_SENT;
+ tp->t_timer[TCPT_KEEP] = tcp_keepinit;
+ tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2;
+ tcp_sendseqinit(tp);
+
+ /*
+ * Generate a CC value for this connection and
+ * check whether CC or CCnew should be used.
+ */
+ if ((taop = tcp_gettaocache(tp->t_inpcb)) == NULL) {
+ taop = &tao_noncached;
+ bzero(taop, sizeof(*taop));
+ }
+
+ tp->cc_send = CC_INC(tcp_ccgen);
+ if (taop->tao_ccsent != 0 &&
+ CC_GEQ(tp->cc_send, taop->tao_ccsent)) {
+ taop->tao_ccsent = tp->cc_send;
+ } else {
+ taop->tao_ccsent = 0;
+ tp->t_flags |= TF_SENDCCNEW;
+ }
+
+ return 0;
+}
+
+int
+tcp_ctloutput(int op, struct socket *so, int level, int optname,
+ struct mbuf **mp)
+{
+ int error = 0, s;
+ struct inpcb *inp;
+ register struct tcpcb *tp;
+ register struct mbuf *m;
+ register int i;
+
+ s = splnet();
+ inp = sotoinpcb(so);
+ if (inp == NULL) {
+ splx(s);
+ if (op == PRCO_SETOPT && *mp)
+ (void) m_free(*mp);
+ return (ECONNRESET);
+ }
+ if (level != IPPROTO_TCP) {
+ error = ip_ctloutput(op, so, level, optname, mp);
+ splx(s);
+ return (error);
+ }
+ tp = intotcpcb(inp);
+
+ switch (op) {
+
+ case PRCO_SETOPT:
+ m = *mp;
+ switch (optname) {
+
+ case TCP_NODELAY:
+ if (m == NULL || m->m_len < sizeof (int))
+ error = EINVAL;
+ else if (*mtod(m, int *))
+ tp->t_flags |= TF_NODELAY;
+ else
+ tp->t_flags &= ~TF_NODELAY;
+ break;
+
+ case TCP_MAXSEG:
+ if (m && (i = *mtod(m, int *)) > 0 && i <= tp->t_maxseg)
+ tp->t_maxseg = i;
+ else
+ error = EINVAL;
+ break;
+
+ case TCP_NOOPT:
+ if (m == NULL || m->m_len < sizeof (int))
+ error = EINVAL;
+ else if (*mtod(m, int *))
+ tp->t_flags |= TF_NOOPT;
+ else
+ tp->t_flags &= ~TF_NOOPT;
+ break;
+
+ case TCP_NOPUSH:
+ if (m == NULL || m->m_len < sizeof (int))
+ error = EINVAL;
+ else if (*mtod(m, int *))
+ tp->t_flags |= TF_NOPUSH;
+ else
+ tp->t_flags &= ~TF_NOPUSH;
+ break;
+
+ default:
+ error = ENOPROTOOPT;
+ break;
+ }
+ if (m)
+ (void) m_free(m);
+ break;
+
+ case PRCO_GETOPT:
+ *mp = m = m_get(M_WAIT, MT_SOOPTS);
+ m->m_len = sizeof(int);
+
+ switch (optname) {
+ case TCP_NODELAY:
+ *mtod(m, int *) = tp->t_flags & TF_NODELAY;
+ break;
+ case TCP_MAXSEG:
+ *mtod(m, int *) = tp->t_maxseg;
+ break;
+ case TCP_NOOPT:
+ *mtod(m, int *) = tp->t_flags & TF_NOOPT;
+ break;
+ case TCP_NOPUSH:
+ *mtod(m, int *) = tp->t_flags & TF_NOPUSH;
+ break;
+ default:
+ error = ENOPROTOOPT;
+ break;
+ }
+ break;
+ }
+ splx(s);
+ return (error);
+}
+
+/*
+ * tcp_sendspace and tcp_recvspace are the default send and receive window
+ * sizes, respectively. These are obsolescent (this information should
+ * be set by the route).
+ */
+u_long tcp_sendspace = 1024*16;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace,
+ CTLFLAG_RW, &tcp_sendspace , 0, "");
+u_long tcp_recvspace = 1024*16;
+SYSCTL_INT(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace,
+ CTLFLAG_RW, &tcp_recvspace , 0, "");
+
+#if defined(__rtems__)
+void rtems_set_tcp_buffer_sizes(u_long sendspace, u_long recvspace)
+{
+ if ( sendspace != 0 )
+ tcp_sendspace = sendspace;
+ if ( recvspace != 0 )
+ tcp_recvspace = recvspace;
+}
+#endif
+
+/*
+ * Attach TCP protocol to socket, allocating
+ * internet protocol control block, tcp control block,
+ * bufer space, and entering LISTEN state if to accept connections.
+ */
+static int
+tcp_attach(struct socket *so)
+{
+ register struct tcpcb *tp;
+ struct inpcb *inp;
+ int error;
+
+ if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
+ error = soreserve(so, tcp_sendspace, tcp_recvspace);
+ if (error)
+ return (error);
+ }
+ error = in_pcballoc(so, &tcbinfo);
+ if (error)
+ return (error);
+ inp = sotoinpcb(so);
+ tp = tcp_newtcpcb(inp);
+ if (tp == 0) {
+ int nofd = so->so_state & SS_NOFDREF; /* XXX */
+
+ so->so_state &= ~SS_NOFDREF; /* don't free the socket yet */
+ in_pcbdetach(inp);
+ so->so_state |= nofd;
+ return (ENOBUFS);
+ }
+ tp->t_state = TCPS_CLOSED;
+ return (0);
+}
+
+/*
+ * Initiate (or continue) disconnect.
+ * If embryonic state, just send reset (once).
+ * If in ``let data drain'' option and linger null, just drop.
+ * Otherwise (hard), mark socket disconnecting and drop
+ * current input data; switch states based on user close, and
+ * send segment to peer (with FIN).
+ */
+static struct tcpcb *
+tcp_disconnect(struct tcpcb *tp)
+{
+ struct socket *so = tp->t_inpcb->inp_socket;
+
+ if (tp->t_state < TCPS_ESTABLISHED)
+ tp = tcp_close(tp);
+ else if ((so->so_options & SO_LINGER) && so->so_linger == 0)
+ tp = tcp_drop(tp, 0);
+ else {
+ soisdisconnecting(so);
+ sbflush(&so->so_rcv);
+ tp = tcp_usrclosed(tp);
+ if (tp)
+ (void) tcp_output(tp);
+ }
+ return (tp);
+}
+
+/*
+ * User issued close, and wish to trail through shutdown states:
+ * if never received SYN, just forget it. If got a SYN from peer,
+ * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
+ * If already got a FIN from peer, then almost done; go to LAST_ACK
+ * state. In all other cases, have already sent FIN to peer (e.g.
+ * after PRU_SHUTDOWN), and just have to play tedious game waiting
+ * for peer to send FIN or not respond to keep-alives, etc.
+ * We can let the user exit from the close as soon as the FIN is acked.
+ */
+static struct tcpcb *
+tcp_usrclosed(struct tcpcb *tp)
+{
+
+ switch (tp->t_state) {
+
+ case TCPS_CLOSED:
+ case TCPS_LISTEN:
+ tp->t_state = TCPS_CLOSED;
+ tp = tcp_close(tp);
+ break;
+
+ case TCPS_SYN_SENT:
+ case TCPS_SYN_RECEIVED:
+ tp->t_flags |= TF_NEEDFIN;
+ break;
+
+ case TCPS_ESTABLISHED:
+ tp->t_state = TCPS_FIN_WAIT_1;
+ break;
+
+ case TCPS_CLOSE_WAIT:
+ tp->t_state = TCPS_LAST_ACK;
+ break;
+ }
+ if (tp && tp->t_state >= TCPS_FIN_WAIT_2) {
+ soisdisconnected(tp->t_inpcb->inp_socket);
+ /* To prevent the connection hanging in FIN_WAIT_2 forever. */
+ if (tp->t_state == TCPS_FIN_WAIT_2)
+ tp->t_timer[TCPT_2MSL] = tcp_maxidle;
+ }
+ return (tp);
+}
diff --git a/cpukit/libnetworking/netinet/tcp_var.h b/cpukit/libnetworking/netinet/tcp_var.h
new file mode 100644
index 0000000000..12fab1995c
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcp_var.h
@@ -0,0 +1,418 @@
+/*
+ * Copyright (c) 1982, 1986, 1993, 1994, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
+ * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.121 2005/04/21 20:11:01 ps Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_TCP_VAR_H_
+#define _NETINET_TCP_VAR_H_
+
+#include <netinet/tcp.h>
+
+/*
+ * Kernel variables for tcp.
+ */
+
+#ifdef __BSD_VISIBLE
+#include <netinet/tcp_timer.h> /* TCPT_NTIMERS */
+
+/*
+ * Tcp control block, one per tcp; fields:
+ */
+struct tcpcb {
+ struct tcpiphdr *seg_next; /* sequencing queue */
+ struct tcpiphdr *seg_prev;
+ int t_state; /* state of this connection */
+ u_int t_flags;
+#define TF_ACKNOW 0x000001 /* ack peer immediately */
+#define TF_DELACK 0x000002 /* ack, but try to delay it */
+#define TF_NODELAY 0x000004 /* don't delay packets to coalesce */
+#define TF_NOOPT 0x000008 /* don't use tcp options */
+#define TF_SENTFIN 0x000010 /* have sent FIN */
+#define TF_REQ_SCALE 0x000020 /* have/will request window scaling */
+#define TF_RCVD_SCALE 0x000040 /* other side has requested scaling */
+#define TF_REQ_TSTMP 0x000080 /* have/will request timestamps */
+#define TF_RCVD_TSTMP 0x000100 /* a timestamp was received in SYN */
+#define TF_SACK_PERMIT 0x000200 /* other side said I could SACK */
+#define TF_NEEDSYN 0x000400 /* send SYN (implicit state) */
+#define TF_NEEDFIN 0x000800 /* send FIN (implicit state) */
+#define TF_NOPUSH 0x001000 /* don't push */
+#define TF_REQ_CC 0x002000 /* have/will request CC */
+#define TF_RCVD_CC 0x004000 /* a CC was received in SYN */
+#define TF_SENDCCNEW 0x008000 /* send CCnew instead of CC in SYN */
+#define TF_MORETOCOME 0x010000 /* More data to be appended to sock */
+#define TF_LQ_OVERFLOW 0x020000 /* listen queue overflow */
+#define TF_LASTIDLE 0x040000 /* connection was previously idle */
+#define TF_RXWIN0SENT 0x080000 /* sent a receiver win 0 in response */
+#define TF_FASTRECOVERY 0x100000 /* in NewReno Fast Recovery */
+#define TF_WASFRECOVERY 0x200000 /* was in NewReno Fast Recovery */
+#define TF_SIGNATURE 0x400000 /* require MD5 digests (RFC2385) */
+ int t_force; /* 1 if forcing out a byte */
+ int t_timer[TCPT_NTIMERS]; /* tcp timers */
+ int t_rxtshift; /* log(2) of rexmt exp. backoff */
+ int t_rxtcur; /* current retransmit value */
+ int t_dupacks; /* consecutive dup acks recd */
+ u_int t_maxseg; /* maximum segment size */
+ u_int t_maxopd; /* mss plus options */
+ struct tcpiphdr *t_template; /* skeletal packet for transmit */
+ struct inpcb *t_inpcb; /* back pointer to internet pcb */
+/*
+ * The following fields are used as in the protocol specification.
+ * See RFC783, Dec. 1981, page 21.
+ */
+/* send sequence variables */
+ tcp_seq snd_una; /* send unacknowledged */
+ tcp_seq snd_max; /* highest sequence number sent;
+ * used to recognize retransmits
+ */
+ tcp_seq snd_nxt; /* send next */
+ tcp_seq snd_up; /* send urgent pointer */
+
+ tcp_seq snd_wl1; /* window update seg seq number */
+ tcp_seq snd_wl2; /* window update seg ack number */
+ tcp_seq iss; /* initial send sequence number */
+ tcp_seq irs; /* initial receive sequence number */
+
+ tcp_seq rcv_nxt; /* receive next */
+ tcp_seq rcv_adv; /* advertised window */
+ u_long rcv_wnd; /* receive window */
+ tcp_seq rcv_up; /* receive urgent pointer */
+
+ u_long snd_wnd; /* send window */
+/*
+ * Additional variables for this implementation.
+ */
+/* congestion control (for slow start, source quench, retransmit after loss) */
+ u_long snd_cwnd; /* congestion-controlled window */
+ u_long snd_ssthresh; /* snd_cwnd size threshold for
+ * for slow start exponential to
+ * linear switch
+ */
+/*
+ * transmit timing stuff. See below for scale of srtt and rttvar.
+ * "Variance" is actually smoothed difference.
+ */
+ u_int t_idle; /* inactivity time */
+ int t_rtt; /* round trip time */
+ tcp_seq t_rtseq; /* sequence number being timed */
+ int t_srtt; /* smoothed round-trip time */
+ int t_rttvar; /* variance in round-trip time */
+ u_int t_rttmin; /* minimum rtt allowed */
+ u_long max_sndwnd; /* largest window peer has offered */
+
+ int t_softerror; /* possible error not yet reported */
+/* out-of-band data */
+ char t_oobflags; /* have some */
+ char t_iobc; /* input character */
+#define TCPOOB_HAVEDATA 0x01
+#define TCPOOB_HADDATA 0x02
+/* RFC 1323 variables */
+ u_char snd_scale; /* window scaling for send window */
+ u_char rcv_scale; /* window scaling for recv window */
+ u_char request_r_scale; /* pending window scaling */
+ u_char requested_s_scale;
+ u_long ts_recent; /* timestamp echo data */
+
+ u_long ts_recent_age; /* when last updated */
+ tcp_seq last_ack_sent;
+/* RFC 1644 variables */
+ tcp_cc cc_send; /* send connection count */
+ tcp_cc cc_recv; /* receive connection count */
+ u_long t_duration; /* connection duration */
+
+/* TUBA stuff */
+ caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */
+/* More RTT stuff */
+ u_long t_rttupdated; /* number of times rtt sampled */
+};
+
+/*
+ * Structure to hold TCP options that are only used during segment
+ * processing (in tcp_input), but not held in the tcpcb.
+ * It's basically used to reduce the number of parameters
+ * to tcp_dooptions.
+ */
+struct tcpopt {
+ u_long to_flags; /* which options are present */
+#define TOF_TS 0x0001 /* timestamp */
+#define TOF_CC 0x0002 /* CC and CCnew are exclusive */
+#define TOF_CCNEW 0x0004
+#define TOF_CCECHO 0x0008
+#define TOF_MSS 0x0010
+#define TOF_SCALE 0x0020
+#define TOF_SIGNATURE 0x0040 /* signature option present */
+#define TOF_SIGLEN 0x0080 /* signature length valid (RFC2385) */
+#define TOF_SACK 0x0100 /* Peer sent SACK option */
+ u_int32_t to_tsval;
+ u_int32_t to_tsecr;
+ tcp_cc to_cc; /* holds CC or CCnew */
+ tcp_cc to_ccecho;
+};
+
+/*
+ * The TAO cache entry which is stored in the protocol family specific
+ * portion of the route metrics.
+ */
+struct rmxp_tao {
+ tcp_cc tao_cc; /* latest CC in valid SYN */
+ tcp_cc tao_ccsent; /* latest CC sent to peer */
+ u_short tao_mssopt; /* peer's cached MSS */
+};
+#define rmx_taop(r) ((struct rmxp_tao *)(r).rmx_filler)
+
+#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
+#define intotw(ip) ((struct tcptw *)(ip)->inp_ppcb)
+#define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
+#endif /* __BSD_VISIBLE */
+
+/*
+ * The smoothed round-trip time and estimated variance
+ * are stored as fixed point numbers scaled by the values below.
+ * For convenience, these scales are also used in smoothing the average
+ * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
+ * With these scales, srtt has 3 bits to the right of the binary point,
+ * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the
+ * binary point, and is smoothed with an ALPHA of 0.75.
+ */
+#define TCP_RTT_SCALE 32 /* multiplier for srtt; 3 bits frac. */
+#define TCP_RTT_SHIFT 5 /* shift for srtt; 3 bits frac. */
+#define TCP_RTTVAR_SCALE 16 /* multiplier for rttvar; 2 bits */
+#define TCP_RTTVAR_SHIFT 4 /* shift for rttvar; 2 bits */
+#define TCP_DELTA_SHIFT 2 /* see tcp_input.c */
+
+/*
+ * The initial retransmission should happen at rtt + 4 * rttvar.
+ * Because of the way we do the smoothing, srtt and rttvar
+ * will each average +1/2 tick of bias. When we compute
+ * the retransmit timer, we want 1/2 tick of rounding and
+ * 1 extra tick because of +-1/2 tick uncertainty in the
+ * firing of the timer. The bias will give us exactly the
+ * 1.5 tick we need. But, because the bias is
+ * statistical, we have to test that we don't drop below
+ * the minimum feasible timer (which is 2 ticks).
+ * This version of the macro adapted from a paper by Lawrence
+ * Brakmo and Larry Peterson which outlines a problem caused
+ * by insufficient precision in the original implementation,
+ * which results in inappropriately large RTO values for very
+ * fast networks.
+ */
+#define TCP_REXMTVAL(tp) \
+ ((((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)) \
+ + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
+
+/* XXX
+ * We want to avoid doing m_pullup on incoming packets but that
+ * means avoiding dtom on the tcp reassembly code. That in turn means
+ * keeping an mbuf pointer in the reassembly queue (since we might
+ * have a cluster). As a quick hack, the source & destination
+ * port numbers (which are no longer needed once we've located the
+ * tcpcb) are overlayed with an mbuf pointer.
+ */
+#if (defined(__GNUC__) && (defined(__arm__) || defined(__mips__)))
+#define STR32_UNALGN(ti,m) \
+ (ti)->ti_sport = (unsigned short)(((unsigned int) m & 0xffff0000) >> 16); \
+ (ti)->ti_dport = (unsigned short) ((unsigned int) m & 0x0000ffff);
+#define LD32_UNALGN(ti,m) \
+ m = (struct mbuf *)((((unsigned int) (ti)->ti_sport) << 16) | ( (unsigned int)(ti)->ti_dport));
+
+#else
+#define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
+#endif
+
+/*
+ * TCP statistics.
+ * Many of these should be kept per connection,
+ * but that's inconvenient at the moment.
+ */
+struct tcpstat {
+ u_long tcps_connattempt; /* connections initiated */
+ u_long tcps_accepts; /* connections accepted */
+ u_long tcps_connects; /* connections established */
+ u_long tcps_drops; /* connections dropped */
+ u_long tcps_conndrops; /* embryonic connections dropped */
+ u_long tcps_closed; /* conn. closed (includes drops) */
+ u_long tcps_segstimed; /* segs where we tried to get rtt */
+ u_long tcps_rttupdated; /* times we succeeded */
+ u_long tcps_delack; /* delayed acks sent */
+ u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
+ u_long tcps_rexmttimeo; /* retransmit timeouts */
+ u_long tcps_persisttimeo; /* persist timeouts */
+ u_long tcps_keeptimeo; /* keepalive timeouts */
+ u_long tcps_keepprobe; /* keepalive probes sent */
+ u_long tcps_keepdrops; /* connections dropped in keepalive */
+
+ u_long tcps_sndtotal; /* total packets sent */
+ u_long tcps_sndpack; /* data packets sent */
+ u_long tcps_sndbyte; /* data bytes sent */
+ u_long tcps_sndrexmitpack; /* data packets retransmitted */
+ u_long tcps_sndrexmitbyte; /* data bytes retransmitted */
+ u_long tcps_sndacks; /* ack-only packets sent */
+ u_long tcps_sndprobe; /* window probes sent */
+ u_long tcps_sndurg; /* packets sent with URG only */
+ u_long tcps_sndwinup; /* window update-only packets sent */
+ u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
+
+ u_long tcps_rcvtotal; /* total packets received */
+ u_long tcps_rcvpack; /* packets received in sequence */
+ u_long tcps_rcvbyte; /* bytes received in sequence */
+ u_long tcps_rcvbadsum; /* packets received with ccksum errs */
+ u_long tcps_rcvbadoff; /* packets received with bad offset */
+ u_long tcps_rcvshort; /* packets received too short */
+ u_long tcps_rcvduppack; /* duplicate-only packets received */
+ u_long tcps_rcvdupbyte; /* duplicate-only bytes received */
+ u_long tcps_rcvpartduppack; /* packets with some duplicate data */
+ u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
+ u_long tcps_rcvoopack; /* out-of-order packets received */
+ u_long tcps_rcvoobyte; /* out-of-order bytes received */
+ u_long tcps_rcvpackafterwin; /* packets with data after window */
+ u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */
+ u_long tcps_rcvafterclose; /* packets rcvd after "close" */
+ u_long tcps_rcvwinprobe; /* rcvd window probe packets */
+ u_long tcps_rcvdupack; /* rcvd duplicate acks */
+ u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */
+ u_long tcps_rcvackpack; /* rcvd ack packets */
+ u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */
+ u_long tcps_rcvwinupd; /* rcvd window update packets */
+ u_long tcps_pawsdrop; /* segments dropped due to PAWS */
+ u_long tcps_predack; /* times hdr predict ok for acks */
+ u_long tcps_preddat; /* times hdr predict ok for data pkts */
+ u_long tcps_pcbcachemiss;
+ u_long tcps_cachedrtt; /* times cached RTT in route updated */
+ u_long tcps_cachedrttvar; /* times cached rttvar updated */
+ u_long tcps_cachedssthresh; /* times cached ssthresh updated */
+ u_long tcps_usedrtt; /* times RTT initialized from route */
+ u_long tcps_usedrttvar; /* times RTTVAR initialized from rt */
+ u_long tcps_usedssthresh; /* times ssthresh initialized from rt*/
+ u_long tcps_persistdrop; /* timeout in persist state */
+ u_long tcps_badsyn; /* bogus SYN, e.g. premature ACK */
+ u_long tcps_mturesent; /* resends due to MTU discovery */
+ u_long tcps_listendrop; /* listen queue overflows */
+};
+
+/*
+ * TCB structure exported to user-land via sysctl(3).
+ * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
+ * included. Not all of our clients do.
+ */
+#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
+struct xtcpcb {
+ size_t xt_len;
+ struct inpcb xt_inp;
+ struct tcpcb xt_tp;
+#if 0
+ struct xsocket xt_socket;
+ u_quad_t xt_alignment_hack;
+#endif
+};
+#endif
+
+/*
+ * Names for TCP sysctl objects
+ */
+#define TCPCTL_DO_RFC1323 1 /* use RFC-1323 extensions */
+#define TCPCTL_DO_RFC1644 2 /* use RFC-1644 extensions */
+#define TCPCTL_MSSDFLT 3 /* MSS default */
+#define TCPCTL_STATS 4 /* statistics (read-only) */
+#define TCPCTL_RTTDFLT 5 /* default RTT estimate */
+#define TCPCTL_KEEPIDLE 6 /* keepalive idle timer */
+#define TCPCTL_KEEPINTVL 7 /* interval to send keepalives */
+#define TCPCTL_SENDSPACE 8 /* send buffer space */
+#define TCPCTL_RECVSPACE 9 /* receive buffer space */
+#define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */
+#define TCPCTL_PCBLIST 11 /* list of all outstanding PCBs */
+#define TCPCTL_MAXID 12
+
+#define TCPCTL_NAMES { \
+ { 0, 0 }, \
+ { "rfc1323", CTLTYPE_INT }, \
+ { "rfc1644", CTLTYPE_INT }, \
+ { "mssdflt", CTLTYPE_INT }, \
+ { "stats", CTLTYPE_STRUCT }, \
+ { "rttdflt", CTLTYPE_INT }, \
+ { "keepidle", CTLTYPE_INT }, \
+ { "keepintvl", CTLTYPE_INT }, \
+ { "sendspace", CTLTYPE_INT }, \
+ { "recvspace", CTLTYPE_INT }, \
+ { "keepinit", CTLTYPE_INT }, \
+}
+
+#ifdef _KERNEL
+#ifdef SYSCTL_DECL
+SYSCTL_DECL(_net_inet_tcp);
+#endif
+
+extern struct inpcbhead tcb; /* head of queue of active tcpcb's */
+extern struct inpcbinfo tcbinfo;
+extern struct tcpstat tcpstat; /* tcp statistics */
+extern int tcp_mssdflt; /* XXX */
+extern u_long tcp_now; /* for RFC 1323 timestamps */
+
+void tcp_canceltimers(struct tcpcb *);
+struct tcpcb *
+ tcp_close(struct tcpcb *);
+void tcp_ctlinput(int, struct sockaddr *, void *);
+int tcp_ctloutput(int, struct socket *, int, int, struct mbuf **);
+struct tcpcb *
+ tcp_drop(struct tcpcb *, int);
+void tcp_drain(void);
+void tcp_fasttimo(void);
+struct rmxp_tao *
+ tcp_gettaocache(struct inpcb *);
+void tcp_init(void);
+void tcp_input(struct mbuf *, int);
+void tcp_mss(struct tcpcb *, int);
+int tcp_mssopt(struct tcpcb *);
+void tcp_mtudisc(struct inpcb *, int);
+struct tcpcb *
+ tcp_newtcpcb(struct inpcb *);
+int tcp_output(struct tcpcb *);
+void tcp_quench(struct inpcb *, int);
+void tcp_respond(struct tcpcb *,
+ struct tcpiphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
+struct rtentry *
+ tcp_rtlookup(struct inpcb *);
+void tcp_setpersist(struct tcpcb *);
+void tcp_slowtimo(void);
+struct tcpiphdr *
+ tcp_template(struct tcpcb *);
+struct tcpcb *
+ tcp_timers(struct tcpcb *, int);
+void tcp_trace(short, short, struct tcpcb *, struct tcpiphdr *, int);
+
+extern struct pr_usrreqs tcp_usrreqs;
+extern u_long tcp_sendspace;
+extern u_long tcp_recvspace;
+
+#endif /* _KERNEL */
+
+#endif /* _NETINET_TCP_VAR_H_ */
diff --git a/cpukit/libnetworking/netinet/tcpip.h b/cpukit/libnetworking/netinet/tcpip.h
new file mode 100644
index 0000000000..0b136633b7
--- /dev/null
+++ b/cpukit/libnetworking/netinet/tcpip.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tcpip.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/tcpip.h,v 1.12.22.1.4.1 2010/06/14 02:09:06 kensmith Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_TCPIP_H_
+#define _NETINET_TCPIP_H_
+
+/*
+ * Tcp+ip header, after ip options removed.
+ */
+struct tcpiphdr {
+ struct ipovly ti_i; /* overlaid ip structure */
+ struct tcphdr ti_t; /* tcp header */
+};
+#define ti_next ti_i.ih_next
+#define ti_prev ti_i.ih_prev
+#define ti_x1 ti_i.ih_x1
+#define ti_pr ti_i.ih_pr
+#define ti_len ti_i.ih_len
+#define ti_src ti_i.ih_src
+#define ti_dst ti_i.ih_dst
+#define ti_sport ti_t.th_sport
+#define ti_dport ti_t.th_dport
+#define ti_seq ti_t.th_seq
+#define ti_ack ti_t.th_ack
+#define ti_x2 ti_t.th_x2
+#define ti_off ti_t.th_off
+#define ti_flags ti_t.th_flags
+#define ti_win ti_t.th_win
+#define ti_sum ti_t.th_sum
+#define ti_urp ti_t.th_urp
+
+#endif
diff --git a/cpukit/libnetworking/netinet/udp.h b/cpukit/libnetworking/netinet/udp.h
new file mode 100644
index 0000000000..e73e1f4ddb
--- /dev/null
+++ b/cpukit/libnetworking/netinet/udp.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)udp.h 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifndef _NETINET_UDP_H_
+#define _NETINET_UDP_H_
+
+/*
+ * Udp protocol header.
+ * Per RFC 768, September, 1981.
+ */
+struct udphdr {
+ u_short uh_sport; /* source port */
+ u_short uh_dport; /* destination port */
+ u_short uh_ulen; /* udp length */
+ u_short uh_sum; /* udp checksum */
+};
+
+#endif
diff --git a/cpukit/libnetworking/netinet/udp_usrreq.c b/cpukit/libnetworking/netinet/udp_usrreq.c
new file mode 100644
index 0000000000..8b56c28bec
--- /dev/null
+++ b/cpukit/libnetworking/netinet/udp_usrreq.c
@@ -0,0 +1,730 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
+ * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.170 2004/11/08 14:44:53 phk Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/syslog.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+
+/*
+ * UDP protocol implementation.
+ * Per RFC 768, August, 1980.
+ */
+#ifndef COMPAT_42
+static int udpcksum = 1;
+#else
+static int udpcksum = 0; /* XXX */
+#endif
+SYSCTL_INT(_net_inet_udp, UDPCTL_CHECKSUM, checksum, CTLFLAG_RW,
+ &udpcksum, 0, "");
+
+static int log_in_vain = 0;
+SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_RW,
+ &log_in_vain, 0, "");
+
+struct inpcbhead udb; /* from udp_var.h */
+struct inpcbinfo udbinfo;
+
+#ifndef UDBHASHSIZE
+#define UDBHASHSIZE 64
+#endif
+
+ struct udpstat udpstat; /* from udp_var.h */
+SYSCTL_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RD,
+ &udpstat, udpstat, "");
+
+static struct sockaddr_in udp_in = { sizeof(udp_in), AF_INET, 0, {0}, {0} };
+
+static void udp_detach(struct inpcb *);
+static int udp_output(struct inpcb *, struct mbuf *, struct mbuf *,
+ struct mbuf *);
+static void udp_notify(struct inpcb *, int);
+
+void
+udp_init(void)
+{
+ LIST_INIT(&udb);
+ udbinfo.listhead = &udb;
+ udbinfo.hashbase = hashinit(UDBHASHSIZE, M_PCB, &udbinfo.hashmask);
+}
+
+void
+udp_input(struct mbuf *m, int iphlen)
+{
+ register struct ip *ip;
+ register struct udphdr *uh;
+ register struct inpcb *inp;
+ struct mbuf *opts = 0;
+ int len;
+ struct ip save_ip;
+
+ udpstat.udps_ipackets++;
+
+ /*
+ * Strip IP options, if any; should skip this,
+ * make available to user, and use on returned packets,
+ * but we don't yet have a way to check the checksum
+ * with options still present.
+ */
+ if (iphlen > sizeof (struct ip)) {
+ ip_stripoptions(m, (struct mbuf *)0);
+ iphlen = sizeof(struct ip);
+ }
+
+ /*
+ * Get IP and UDP header together in first mbuf.
+ */
+ ip = mtod(m, struct ip *);
+ if (m->m_len < iphlen + sizeof(struct udphdr)) {
+ if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == 0) {
+ udpstat.udps_hdrops++;
+ return;
+ }
+ ip = mtod(m, struct ip *);
+ }
+ uh = (struct udphdr *)((caddr_t)ip + iphlen);
+
+ /*
+ * Make mbuf data length reflect UDP length.
+ * If not enough data to reflect UDP length, drop.
+ */
+ len = ntohs((u_short)uh->uh_ulen);
+ if (ip->ip_len != len) {
+ if (len > ip->ip_len || len < sizeof(struct udphdr)) {
+ udpstat.udps_badlen++;
+ goto bad;
+ }
+ m_adj(m, len - ip->ip_len);
+ /* ip->ip_len = len; */
+ }
+ /*
+ * Save a copy of the IP header in case we want restore it
+ * for sending an ICMP error message in response.
+ */
+ save_ip = *ip;
+
+ /*
+ * Checksum extended UDP header and data.
+ */
+ if (uh->uh_sum) {
+ ((struct ipovly *)ip)->ih_next = 0;
+ ((struct ipovly *)ip)->ih_prev = 0;
+ ((struct ipovly *)ip)->ih_x1 = 0;
+ ((struct ipovly *)ip)->ih_len = uh->uh_ulen;
+ uh->uh_sum = in_cksum(m, len + sizeof (struct ip));
+ if (uh->uh_sum) {
+ udpstat.udps_badsum++;
+ m_freem(m);
+ return;
+ }
+ }
+
+ if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
+ in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif)) {
+ struct inpcb *last;
+ /*
+ * Deliver a multicast or broadcast datagram to *all* sockets
+ * for which the local and remote addresses and ports match
+ * those of the incoming datagram. This allows more than
+ * one process to receive multi/broadcasts on the same port.
+ * (This really ought to be done for unicast datagrams as
+ * well, but that would cause problems with existing
+ * applications that open both address-specific sockets and
+ * a wildcard socket listening to the same port -- they would
+ * end up receiving duplicates of every unicast datagram.
+ * Those applications open the multiple sockets to overcome an
+ * inadequacy of the UDP socket interface, but for backwards
+ * compatibility we avoid the problem here rather than
+ * fixing the interface. Maybe 4.5BSD will remedy this?)
+ */
+
+ /*
+ * Construct sockaddr format source address.
+ */
+ udp_in.sin_port = uh->uh_sport;
+ udp_in.sin_addr = ip->ip_src;
+ m->m_len -= sizeof (struct udpiphdr);
+ m->m_data += sizeof (struct udpiphdr);
+ /*
+ * Locate pcb(s) for datagram.
+ * (Algorithm copied from raw_intr().)
+ */
+ last = NULL;
+ for (inp = udb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
+ if (inp->inp_lport != uh->uh_dport)
+ continue;
+ if (inp->inp_laddr.s_addr != INADDR_ANY) {
+ if (inp->inp_laddr.s_addr !=
+ ip->ip_dst.s_addr)
+ continue;
+ }
+ if (inp->inp_faddr.s_addr != INADDR_ANY) {
+ if (inp->inp_faddr.s_addr !=
+ ip->ip_src.s_addr ||
+ inp->inp_fport != uh->uh_sport)
+ continue;
+ }
+
+ if (last != NULL) {
+ struct mbuf *n;
+
+ if ((n = m_copy(m, 0, M_COPYALL)) != NULL) {
+ if (last->inp_flags & INP_CONTROLOPTS
+ || last->inp_socket->so_options & SO_TIMESTAMP)
+ ip_savecontrol(last, &opts, ip, n);
+ if (sbappendaddr(&last->inp_socket->so_rcv,
+ (struct sockaddr *)&udp_in,
+ n, opts) == 0) {
+ m_freem(n);
+ if (opts)
+ m_freem(opts);
+ udpstat.udps_fullsock++;
+ } else
+ sorwakeup(last->inp_socket);
+ opts = 0;
+ }
+ }
+ last = inp;
+ /*
+ * Don't look for additional matches if this one does
+ * not have either the SO_REUSEPORT or SO_REUSEADDR
+ * socket options set. This heuristic avoids searching
+ * through all pcbs in the common case of a non-shared
+ * port. It * assumes that an application will never
+ * clear these options after setting them.
+ */
+ if (((last->inp_socket->so_options&(SO_REUSEPORT|SO_REUSEADDR)) == 0))
+ break;
+ }
+
+ if (last == NULL) {
+ /*
+ * No matching pcb found; discard datagram.
+ * (No need to send an ICMP Port Unreachable
+ * for a broadcast or multicast datgram.)
+ */
+ udpstat.udps_noportbcast++;
+ goto bad;
+ }
+ if (last->inp_flags & INP_CONTROLOPTS
+ || last->inp_socket->so_options & SO_TIMESTAMP)
+ ip_savecontrol(last, &opts, ip, m);
+ if (sbappendaddr(&last->inp_socket->so_rcv,
+ (struct sockaddr *)&udp_in,
+ m, opts) == 0) {
+ udpstat.udps_fullsock++;
+ goto bad;
+ }
+ sorwakeup(last->inp_socket);
+ return;
+ }
+ /*
+ * Locate pcb for datagram.
+ */
+ inp = in_pcblookuphash(&udbinfo, ip->ip_src, uh->uh_sport,
+ ip->ip_dst, uh->uh_dport, 1);
+ if (inp == NULL) {
+ if (log_in_vain) {
+ char buf[4*sizeof "123"];
+
+ strcpy(buf, inet_ntoa(ip->ip_dst));
+ log(LOG_INFO, "Connection attempt to UDP %s:%d"
+ " from %s:%d\n",
+ buf, ntohs(uh->uh_dport),
+ inet_ntoa(ip->ip_src), ntohs(uh->uh_sport));
+ }
+ udpstat.udps_noport++;
+ if (m->m_flags & (M_BCAST | M_MCAST)) {
+ udpstat.udps_noportbcast++;
+ goto bad;
+ }
+ *ip = save_ip;
+ icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
+ return;
+ }
+
+ /*
+ * Construct sockaddr format source address.
+ * Stuff source address and datagram in user buffer.
+ */
+ udp_in.sin_port = uh->uh_sport;
+ udp_in.sin_addr = ip->ip_src;
+ if (inp->inp_flags & INP_CONTROLOPTS
+ || inp->inp_socket->so_options & SO_TIMESTAMP)
+ ip_savecontrol(inp, &opts, ip, m);
+ iphlen += sizeof(struct udphdr);
+ m->m_len -= iphlen;
+ m->m_pkthdr.len -= iphlen;
+ m->m_data += iphlen;
+ if (sbappendaddr(&inp->inp_socket->so_rcv, (struct sockaddr *)&udp_in,
+ m, opts) == 0) {
+ udpstat.udps_fullsock++;
+ goto bad;
+ }
+ sorwakeup(inp->inp_socket);
+ return;
+bad:
+ m_freem(m);
+ if (opts)
+ m_freem(opts);
+}
+
+/*
+ * Notify a udp user of an asynchronous error;
+ * just wake up so that he can collect error status.
+ */
+static void
+udp_notify(struct inpcb *inp, int errnum)
+{
+ inp->inp_socket->so_error = errnum;
+ sorwakeup(inp->inp_socket);
+ sowwakeup(inp->inp_socket);
+}
+
+void
+udp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
+{
+ register struct ip *ip = vip;
+ register struct udphdr *uh;
+
+ if (!PRC_IS_REDIRECT(cmd) &&
+ ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0))
+ return;
+ if (ip) {
+ uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
+ in_pcbnotify(&udb, sa, uh->uh_dport, ip->ip_src, uh->uh_sport,
+ cmd, udp_notify);
+ } else
+ in_pcbnotify(&udb, sa, 0, zeroin_addr, 0, cmd, udp_notify);
+}
+
+static int
+udp_output(struct inpcb *inp, struct mbuf *m, struct mbuf *addr,
+ struct mbuf *control)
+{
+ register struct udpiphdr *ui;
+ register int len = m->m_pkthdr.len;
+ struct in_addr laddr;
+ int s = 0, error = 0;
+
+ laddr.s_addr = 0;
+ if (control)
+ m_freem(control); /* XXX */
+
+ if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
+ error = EMSGSIZE;
+ goto release;
+ }
+
+ if (addr) {
+ laddr = inp->inp_laddr;
+ if (inp->inp_faddr.s_addr != INADDR_ANY) {
+ error = EISCONN;
+ goto release;
+ }
+ /*
+ * Must block input while temporarily connected.
+ */
+ s = splnet();
+ error = in_pcbconnect(inp, addr);
+ if (error) {
+ splx(s);
+ goto release;
+ }
+ } else {
+ if (inp->inp_faddr.s_addr == INADDR_ANY) {
+ error = ENOTCONN;
+ goto release;
+ }
+ }
+ /*
+ * Calculate data length and get a mbuf
+ * for UDP and IP headers.
+ */
+ M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT);
+ if (m == 0) {
+ error = ENOBUFS;
+ if (addr)
+ splx(s);
+ goto release;
+ }
+
+ /*
+ * Fill in mbuf with extended UDP header
+ * and addresses and length put into network format.
+ */
+ ui = mtod(m, struct udpiphdr *);
+ ui->ui_next = ui->ui_prev = 0;
+ ui->ui_x1 = 0;
+ ui->ui_pr = IPPROTO_UDP;
+ ui->ui_len = htons((u_short)len + sizeof (struct udphdr));
+ ui->ui_src = inp->inp_laddr;
+ ui->ui_dst = inp->inp_faddr;
+ ui->ui_sport = inp->inp_lport;
+ ui->ui_dport = inp->inp_fport;
+ ui->ui_ulen = ui->ui_len;
+
+ /*
+ * Stuff checksum and output datagram.
+ */
+ ui->ui_sum = 0;
+ if (udpcksum) {
+ if ((ui->ui_sum = in_cksum(m, sizeof (struct udpiphdr) + len)) == 0)
+ ui->ui_sum = 0xffff;
+ }
+ ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len;
+ ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */
+ ((struct ip *)ui)->ip_tos = inp->inp_ip_tos; /* XXX */
+ udpstat.udps_opackets++;
+ error = ip_output(m, inp->inp_options, &inp->inp_route,
+ inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST),
+ inp->inp_moptions);
+
+ if (addr) {
+ in_pcbdisconnect(inp);
+ inp->inp_laddr = laddr;
+ splx(s);
+ }
+ return (error);
+
+release:
+ m_freem(m);
+ return (error);
+}
+
+#ifdef __rtems__
+#define INP_INFO_RLOCK(a)
+#define INP_INFO_RUNLOCK(a)
+#define INP_LOCK(a)
+#define INP_UNLOCK(a)
+#endif
+
+static int
+udp_pcblist(SYSCTL_HANDLER_ARGS)
+{
+ int error, i, n, s;
+ struct inpcb *inp, **inp_list;
+ inp_gen_t gencnt;
+ struct xinpgen xig;
+
+ /*
+ * The process of preparing the TCB list is too time-consuming and
+ * resource-intensive to repeat twice on every request.
+ */
+ if (req->oldptr == 0) {
+ n = udbinfo.ipi_count;
+ req->oldidx = 2 * (sizeof xig)
+ + (n + n/8) * sizeof(struct xinpcb);
+ return 0;
+ }
+
+ if (req->newptr != 0)
+ return EPERM;
+
+ /*
+ * OK, now we're committed to doing something.
+ */
+ s = splnet();
+ gencnt = udbinfo.ipi_gencnt;
+ n = udbinfo.ipi_count;
+ splx(s);
+
+ sysctl_wire_old_buffer(req, 2 * (sizeof xig)
+ + n * sizeof(struct xinpcb));
+
+ xig.xig_len = sizeof xig;
+ xig.xig_count = n;
+ xig.xig_gen = gencnt;
+#if 0
+ xig.xig_sogen = so_gencnt;
+#endif
+ error = SYSCTL_OUT(req, &xig, sizeof xig);
+ if (error)
+ return error;
+
+ /* ccj add the exit if count is 0 */
+ if (!n)
+ return error;
+
+ inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
+ if (inp_list == 0)
+ return ENOMEM;
+
+ s = splnet();
+ INP_INFO_RLOCK(&udbinfo);
+ for (inp = LIST_FIRST(udbinfo.listhead), i = 0; inp && i < n;
+ inp = LIST_NEXT(inp, inp_list)) {
+ INP_LOCK(inp);
+ if (inp->inp_gencnt <= gencnt)
+#if 0
+ &&
+ cr_canseesocket(req->td->td_ucred, inp->inp_socket) == 0)
+#endif
+ inp_list[i++] = inp;
+ INP_UNLOCK(inp);
+ }
+ INP_INFO_RUNLOCK(&udbinfo);
+ splx(s);
+ n = i;
+
+ error = 0;
+ for (i = 0; i < n; i++) {
+ inp = inp_list[i];
+ INP_LOCK(inp);
+ if (inp->inp_gencnt <= gencnt) {
+ struct xinpcb xi;
+ xi.xi_len = sizeof xi;
+ /* XXX should avoid extra copy */
+ bcopy(inp, &xi.xi_inp, sizeof *inp);
+#if 0
+ if (inp->inp_socket)
+ sotoxsocket(inp->inp_socket, &xi.xi_socket);
+#endif
+ error = SYSCTL_OUT(req, &xi, sizeof xi);
+ }
+ INP_UNLOCK(inp);
+ }
+ if (!error) {
+ /*
+ * Give the user an updated idea of our state.
+ * If the generation differs from what we told
+ * her before, she knows that something happened
+ * while we were processing this request, and it
+ * might be necessary to retry.
+ */
+ s = splnet();
+ INP_INFO_RLOCK(&udbinfo);
+ xig.xig_gen = udbinfo.ipi_gencnt;
+#if 0
+ xig.xig_sogen = so_gencnt;
+#endif
+ xig.xig_count = udbinfo.ipi_count;
+ INP_INFO_RUNLOCK(&udbinfo);
+ splx(s);
+ error = SYSCTL_OUT(req, &xig, sizeof xig);
+ }
+ free(inp_list, M_TEMP);
+ return error;
+}
+
+SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
+ udp_pcblist, "S,xinpcb", "List of active UDP sockets");
+
+static u_long udp_sendspace = 9216; /* really max datagram size */
+ /* 40 1K datagrams */
+SYSCTL_INT(_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram, CTLFLAG_RW,
+ &udp_sendspace, 0, "");
+
+static u_long udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));
+SYSCTL_INT(_net_inet_udp, UDPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
+ &udp_recvspace, 0, "");
+
+#if defined(__rtems__)
+void rtems_set_udp_buffer_sizes(u_long sendspace, u_long recvspace)
+{
+ if ( sendspace != 0 )
+ udp_sendspace = sendspace;
+ if ( recvspace != 0 )
+ udp_recvspace = recvspace;
+}
+#endif
+
+/*ARGSUSED*/
+int
+udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr,
+ struct mbuf *control)
+{
+ struct inpcb *inp = sotoinpcb(so);
+ int error = 0;
+ int s;
+
+ if (req == PRU_CONTROL)
+ return (in_control(so, (uintptr_t)m, (caddr_t)addr,
+ (struct ifnet *)control));
+ if (inp == NULL && req != PRU_ATTACH) {
+ error = EINVAL;
+ goto release;
+ }
+ /*
+ * Note: need to block udp_input while changing
+ * the udp pcb queue and/or pcb addresses.
+ */
+ switch (req) {
+
+ case PRU_ATTACH:
+ if (inp != NULL) {
+ error = EINVAL;
+ break;
+ }
+ s = splnet();
+ error = in_pcballoc(so, &udbinfo);
+ splx(s);
+ if (error)
+ break;
+ error = soreserve(so, udp_sendspace, udp_recvspace);
+ if (error)
+ break;
+ ((struct inpcb *) so->so_pcb)->inp_ip_ttl = ip_defttl;
+ break;
+
+ case PRU_DETACH:
+ udp_detach(inp);
+ break;
+
+ case PRU_BIND:
+ s = splnet();
+ error = in_pcbbind(inp, addr);
+ splx(s);
+ break;
+
+ case PRU_LISTEN:
+ error = EOPNOTSUPP;
+ break;
+
+ case PRU_CONNECT:
+ if (inp->inp_faddr.s_addr != INADDR_ANY) {
+ error = EISCONN;
+ break;
+ }
+ s = splnet();
+ error = in_pcbconnect(inp, addr);
+ splx(s);
+ if (error == 0)
+ soisconnected(so);
+ break;
+
+ case PRU_CONNECT2:
+ error = EOPNOTSUPP;
+ break;
+
+ case PRU_ACCEPT:
+ error = EOPNOTSUPP;
+ break;
+
+ case PRU_DISCONNECT:
+ if (inp->inp_faddr.s_addr == INADDR_ANY) {
+ error = ENOTCONN;
+ break;
+ }
+ s = splnet();
+ in_pcbdisconnect(inp);
+ inp->inp_laddr.s_addr = INADDR_ANY;
+ splx(s);
+ so->so_state &= ~SS_ISCONNECTED; /* XXX */
+ break;
+
+ case PRU_SHUTDOWN:
+ socantsendmore(so);
+ break;
+
+ case PRU_SEND:
+ return (udp_output(inp, m, addr, control));
+
+ case PRU_ABORT:
+ soisdisconnected(so);
+ udp_detach(inp);
+ break;
+
+ case PRU_SOCKADDR:
+ in_setsockaddr(inp, addr);
+ break;
+
+ case PRU_PEERADDR:
+ in_setpeeraddr(inp, addr);
+ break;
+
+ case PRU_SENSE:
+ /*
+ * stat: don't bother with a blocksize.
+ */
+ return (0);
+
+ case PRU_SENDOOB:
+ case PRU_FASTTIMO:
+ case PRU_SLOWTIMO:
+ case PRU_PROTORCV:
+ case PRU_PROTOSEND:
+ error = EOPNOTSUPP;
+ break;
+
+ case PRU_RCVD:
+ case PRU_RCVOOB:
+ return (EOPNOTSUPP); /* do not free mbuf's */
+
+ default:
+ panic("udp_usrreq");
+ }
+
+release:
+ if (control) {
+ printf("udp control data unexpectedly retained\n");
+ m_freem(control);
+ }
+ if (m)
+ m_freem(m);
+ return (error);
+}
+
+static void
+udp_detach(struct inpcb *inp)
+{
+ int s = splnet();
+
+ in_pcbdetach(inp);
+ splx(s);
+}
diff --git a/cpukit/libnetworking/netinet/udp_var.h b/cpukit/libnetworking/netinet/udp_var.h
new file mode 100644
index 0000000000..9c86cf91dc
--- /dev/null
+++ b/cpukit/libnetworking/netinet/udp_var.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)udp_var.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/netinet/udp_var.h,v 1.29 2005/01/07 01:45:45 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NETINET_UDP_VAR_H_
+#define _NETINET_UDP_VAR_H_
+
+/*
+ * UDP kernel structures and variables.
+ */
+struct udpiphdr {
+ struct ipovly ui_i; /* overlaid ip structure */
+ struct udphdr ui_u; /* udp header */
+};
+#define ui_next ui_i.ih_next
+#define ui_prev ui_i.ih_prev
+#define ui_x1 ui_i.ih_x1
+#define ui_pr ui_i.ih_pr
+#define ui_len ui_i.ih_len
+#define ui_src ui_i.ih_src
+#define ui_dst ui_i.ih_dst
+#define ui_sport ui_u.uh_sport
+#define ui_dport ui_u.uh_dport
+#define ui_ulen ui_u.uh_ulen
+#define ui_sum ui_u.uh_sum
+
+struct udpstat {
+ /* input statistics: */
+ u_long udps_ipackets; /* total input packets */
+ u_long udps_hdrops; /* packet shorter than header */
+ u_long udps_badsum; /* checksum error */
+ u_long udps_badlen; /* data length larger than packet */
+ u_long udps_noport; /* no socket on port */
+ u_long udps_noportbcast; /* of above, arrived as broadcast */
+ u_long udps_fullsock; /* not delivered, input socket full */
+ u_long udpps_pcbcachemiss; /* input packets missing pcb cache */
+ u_long udpps_pcbhashmiss; /* input packets not for hashed pcb */
+ /* output statistics: */
+ u_long udps_opackets; /* total output packets */
+};
+
+/*
+ * Names for UDP sysctl objects
+ */
+#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */
+#define UDPCTL_STATS 2 /* statistics (read-only) */
+#define UDPCTL_MAXDGRAM 3 /* max datagram size */
+#define UDPCTL_RECVSPACE 4 /* default receive buffer space */
+#define UDPCTL_PCBLIST 5 /* list of PCBs for UDP sockets */
+#define UDPCTL_MAXID 6
+
+#define UDPCTL_NAMES { \
+ { 0, 0 }, \
+ { "checksum", CTLTYPE_INT }, \
+ { "stats", CTLTYPE_STRUCT }, \
+ { "maxdgram", CTLTYPE_INT }, \
+ { "recvspace", CTLTYPE_INT }, \
+}
+
+#ifdef _KERNEL
+SYSCTL_DECL(_net_inet_udp);
+
+extern struct inpcbhead udb;
+extern struct inpcbinfo udbinfo;
+extern struct udpstat udpstat;
+
+void udp_ctlinput(int, struct sockaddr *, void *);
+void udp_init(void);
+void udp_input(struct mbuf *, int);
+int udp_usrreq(struct socket *,
+ int, struct mbuf *, struct mbuf *, struct mbuf *);
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/nfs/bootp_subr.c b/cpukit/libnetworking/nfs/bootp_subr.c
new file mode 100644
index 0000000000..e976227d4d
--- /dev/null
+++ b/cpukit/libnetworking/nfs/bootp_subr.c
@@ -0,0 +1,1213 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 1995 Gordon Ross, Adam Glass
+ * Copyright (c) 1992 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Lawrence Berkeley Laboratory and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * based on:
+ * nfs/krpc_subr.c
+ * $NetBSD: krpc_subr.c,v 1.10 1995/08/08 20:43:43 gwr Exp $
+ */
+
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/conf.h>
+#include <sys/sockio.h>
+#include <sys/mount.h>
+#include <sys/mbuf.h>
+#include <sys/proc.h>
+#include <sys/reboot.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <net/if_types.h>
+#include <net/if_dl.h>
+#include <netinet/if_ether.h>
+
+#include <nfs/nfsproto.h>
+#include <nfsclient/nfsargs.h>
+#include <nfsclient/nfsdiskless.h>
+#include <nfs/xdr_subs.h>
+
+#include <fcntl.h>
+#include <rtems/mkrootfs.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/bsdnet/servers.h>
+#include <inttypes.h>
+
+#define BOOTP_MIN_LEN 300 /* Minimum size of bootp udp packet */
+
+/*
+ * What is the longest we will wait before re-sending a request?
+ * Note this is also the frequency of "RPC timeout" messages.
+ * The re-send loop counts up linearly to this maximum, so the
+ * first complaint will happen after (1+2+3+4+5)=15 seconds.
+ */
+#define MAX_RESEND_DELAY 5 /* seconds */
+
+/* Definitions from RFC951 */
+struct bootp_packet {
+ u_int8_t op;
+ u_int8_t htype;
+ u_int8_t hlen;
+ u_int8_t hops;
+ u_int32_t xid;
+ u_int16_t secs;
+ u_int16_t flags;
+ struct in_addr ciaddr;
+ struct in_addr yiaddr;
+ struct in_addr siaddr;
+ struct in_addr giaddr;
+ unsigned char chaddr[16];
+ char sname[64];
+ char file[128];
+ unsigned char vend[256];
+};
+
+#define IPPORT_BOOTPC 68
+#define IPPORT_BOOTPS 67
+
+extern int nfs_diskless_valid;
+extern struct nfsv3_diskless nfsv3_diskless;
+
+/* mountd RPC */
+#if !defined(__rtems__)
+static int md_mount(struct sockaddr_in *mdsin, char *path,
+ u_char *fhp, int *fhsizep, struct nfs_args *args,struct proc *procp);
+static int md_lookup_swap(struct sockaddr_in *mdsin,char *path,
+ u_char *fhp, int *fhsizep,
+ struct nfs_args *args,
+ struct proc *procp);
+static int setfs(struct sockaddr_in *addr, char *path, char *p);
+static int getdec(char **ptr);
+#endif
+#if !defined(__rtems__)
+static char *substr(char *a,char *b);
+static void mountopts(struct nfs_args *args, char *p);
+static int xdr_opaque_decode(struct mbuf **ptr,u_char *buf,
+ int len);
+static int xdr_int_decode(struct mbuf **ptr,int *iptr);
+#endif
+static void printip(char *prefix,struct in_addr addr);
+
+#ifdef BOOTP_DEBUG
+void bootpboot_p_sa(struct sockaddr *sa, struct sockaddr *ma);
+void bootpboot_p_ma(struct sockaddr *ma);
+void bootpboot_p_rtentry(struct rtentry *rt);
+void bootpboot_p_tree(struct radix_node *rn);
+void bootpboot_p_rtlist(void);
+void bootpboot_p_iflist(void);
+#endif
+
+int bootpc_call(struct bootp_packet *call,
+ struct bootp_packet *reply,
+ struct proc *procp);
+
+int bootpc_fakeup_interface(struct ifreq *ireq,struct socket *so,
+ struct proc *procp);
+
+int
+bootpc_adjust_interface(struct ifreq *ireq,struct socket *so,
+ struct sockaddr_in *myaddr,
+ struct sockaddr_in *netmask,
+ struct sockaddr_in *gw,
+ struct proc *procp);
+
+#ifdef BOOTP_DEBUG
+void
+bootpboot_p_sa(struct sockaddr *sa, struct sockaddr *ma)
+{
+
+ if (sa == NULL) {
+ printf("(sockaddr *) <null>");
+ return;
+ }
+ switch (sa->sa_family) {
+ case AF_INET:
+ {
+ struct sockaddr_in *sin = (struct sockaddr_in *) sa;
+ printf("inet %x",ntohl(sin->sin_addr.s_addr));
+ if (ma) {
+ struct sockaddr_in *sin = (struct sockaddr_in *) ma;
+ printf(" mask %x",ntohl(sin->sin_addr.s_addr));
+ }
+ }
+ break;
+ case AF_LINK:
+ {
+ struct sockaddr_dl *sli = (struct sockaddr_dl *) sa;
+ int i;
+ printf("link %.*s ",sli->sdl_nlen,sli->sdl_data);
+ for (i=0;i<sli->sdl_alen;i++) {
+ if (i>0)
+ printf(":");
+ printf("%x",(unsigned char) sli->sdl_data[i+sli->sdl_nlen]);
+ }
+ }
+ break;
+ default:
+ printf("af%d",sa->sa_family);
+ }
+}
+
+void
+bootpboot_p_ma(struct sockaddr *ma)
+{
+
+ if (ma == NULL) {
+ printf("<null>");
+ return;
+ }
+ printf("%x", *(int*)ma);
+}
+
+void
+bootpboot_p_rtentry(struct rtentry *rt)
+{
+
+ bootpboot_p_sa(rt_key(rt), rt_mask(rt));
+ printf(" ");
+ bootpboot_p_ma(rt->rt_genmask);
+ printf(" ");
+ bootpboot_p_sa(rt->rt_gateway, NULL);
+ printf(" ");
+ printf("flags %x", (unsigned short) rt->rt_flags);
+ printf(" %d", rt->rt_rmx.rmx_expire);
+ printf(" %s%d\n", rt->rt_ifp->if_name,rt->rt_ifp->if_unit);
+}
+
+void
+bootpboot_p_tree(struct radix_node *rn)
+{
+
+ while (rn != NULL) {
+ if (rn->rn_b < 0) {
+ if (rn->rn_flags & RNF_ROOT) {
+ } else {
+ bootpboot_p_rtentry((struct rtentry *) rn);
+ }
+ rn = rn->rn_dupedkey;
+ } else {
+ bootpboot_p_tree(rn->rn_l);
+ bootpboot_p_tree(rn->rn_r);
+ return;
+ }
+
+ }
+}
+
+void
+bootpboot_p_rtlist(void)
+{
+
+ printf("Routing table:\n");
+ bootpboot_p_tree(rt_tables[AF_INET]->rnh_treetop);
+}
+
+void
+bootpboot_p_iflist(void)
+{
+ struct ifnet *ifp;
+ struct ifaddr *ifa;
+ printf("Interface list:\n");
+ for (ifp = TAILQ_FIRST(&ifnet); ifp != 0; ifp = TAILQ_NEXT(ifp,if_link))
+ {
+ for (ifa = TAILQ_FIRST(&ifp->if_addrhead) ;ifa;
+ ifa=TAILQ_NEXT(ifa,ifa_link))
+ if (ifa->ifa_addr->sa_family == AF_INET ) {
+ printf("%s%d flags %x, addr %x, bcast %x, net %x\n",
+ ifp->if_name,ifp->if_unit,
+ (unsigned short) ifp->if_flags,
+ ntohl(((struct sockaddr_in *) ifa->ifa_addr)->sin_addr.s_addr),
+ ntohl(((struct sockaddr_in *) ifa->ifa_dstaddr)->sin_addr.s_addr),
+ ntohl(((struct sockaddr_in *) ifa->ifa_netmask)->sin_addr.s_addr)
+ );
+ }
+ }
+}
+#endif
+
+/*
+ * - determine space needed to store src string
+ * - allocate or reallocate dst, so that string fits in
+ * - copy string from src to dest
+ */
+void *bootp_strdup_realloc(char *dst,const char *src)
+{
+ size_t len;
+
+ if (dst == NULL) {
+ /* first allocation, simply use strdup */
+ if (src)
+ dst = strdup(src);
+ }
+ else {
+ /* already allocated, so use realloc/strcpy */
+ len = src ? strlen(src) + 1 : 0;
+ /* src == NULL tells us to effectively free dst */
+ dst = realloc(dst,len);
+ if (dst != NULL) {
+ strcpy(dst,src);
+ }
+ }
+ return dst;
+}
+
+int
+bootpc_call(
+ struct bootp_packet *call,
+ struct bootp_packet *reply, /* output */
+ struct proc *procp)
+{
+ struct socket *so;
+ struct sockaddr_in *sin;
+ struct mbuf *m, *nam;
+ struct uio auio;
+ struct iovec aio;
+ int error, rcvflg, timo, secs, len;
+
+ /* Free at end if not null. */
+ nam = NULL;
+
+ /*
+ * Create socket and set its recieve timeout.
+ */
+ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp)))
+ goto out;
+
+ m = m_get(M_WAIT, MT_SOOPTS);
+ if (m == NULL) {
+ error = ENOBUFS;
+ goto out;
+ } else {
+ struct timeval *tv;
+ tv = mtod(m, struct timeval *);
+ m->m_len = sizeof(*tv);
+ tv->tv_sec = 1;
+ tv->tv_usec = 0;
+ if ((error = sosetopt(so, SOL_SOCKET, SO_RCVTIMEO, m)))
+ goto out;
+ }
+
+ /*
+ * Enable broadcast.
+ */
+ {
+ int *on;
+ m = m_get(M_WAIT, MT_SOOPTS);
+ if (m == NULL) {
+ error = ENOBUFS;
+ goto out;
+ }
+ on = mtod(m, int *);
+ m->m_len = sizeof(*on);
+ *on = 1;
+ if ((error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m)))
+ goto out;
+ }
+
+ /*
+ * Bind the local endpoint to a bootp client port.
+ */
+ m = m_getclr(M_WAIT, MT_SONAME);
+ sin = mtod(m, struct sockaddr_in *);
+ sin->sin_len = m->m_len = sizeof(*sin);
+ sin->sin_family = AF_INET;
+ sin->sin_addr.s_addr = INADDR_ANY;
+ sin->sin_port = htons(IPPORT_BOOTPC);
+ error = sobind(so, m);
+ m_freem(m);
+ if (error) {
+ printf("bind failed\n");
+ goto out;
+ }
+
+ /*
+ * Setup socket address for the server.
+ */
+ nam = m_get(M_WAIT, MT_SONAME);
+ if (nam == NULL) {
+ error = ENOBUFS;
+ goto out;
+ }
+ sin = mtod(nam, struct sockaddr_in *);
+ sin-> sin_len = sizeof(*sin);
+ sin-> sin_family = AF_INET;
+ sin->sin_addr.s_addr = INADDR_BROADCAST;
+ sin->sin_port = htons(IPPORT_BOOTPS);
+
+ nam->m_len = sizeof(*sin);
+
+ /*
+ * Send it, repeatedly, until a reply is received,
+ * but delay each re-send by an increasing amount.
+ * If the delay hits the maximum, start complaining.
+ */
+ for (timo=1; timo <= MAX_RESEND_DELAY; timo++) {
+ /* Send BOOTP request (or re-send). */
+
+ aio.iov_base = (caddr_t) call;
+ aio.iov_len = sizeof(*call);
+
+ auio.uio_iov = &aio;
+ auio.uio_iovcnt = 1;
+ auio.uio_segflg = UIO_SYSSPACE;
+ auio.uio_rw = UIO_WRITE;
+ auio.uio_offset = 0;
+ auio.uio_resid = sizeof(*call);
+ auio.uio_procp = procp;
+ error = sosend(so, nam, &auio, NULL, NULL, 0);
+ if (error) {
+ printf("bootpc_call: sosend: %d\n", error);
+ switch (error) {
+ case ENOBUFS: /* No buffer space available */
+ case ENETUNREACH: /* Network is unreachable */
+ case ENETDOWN: /* Network interface is not configured */
+ case EHOSTDOWN: /* Host is down */
+ case EHOSTUNREACH: /* Host is unreachable */
+ case EMSGSIZE: /* Message too long */
+ /* This is a possibly transient error.
+ We can still receive replies from previous attempts. */
+ break;
+ default:
+ goto out;
+ }
+ }
+
+ /*
+ * Wait for up to timo seconds for a reply.
+ * The socket receive timeout was set to 1 second.
+ */
+ secs = timo;
+ while (secs > 0) {
+ aio.iov_base = (caddr_t) reply;
+ aio.iov_len = sizeof(*reply);
+
+ auio.uio_iov = &aio;
+ auio.uio_iovcnt = 1;
+ auio.uio_segflg = UIO_SYSSPACE;
+ auio.uio_rw = UIO_READ;
+ auio.uio_offset = 0;
+ auio.uio_resid = sizeof(*reply);
+ auio.uio_procp = procp;
+
+ rcvflg = 0;
+ error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg);
+ if (error == EWOULDBLOCK) {
+ secs--;
+ call->secs=htons(ntohs(call->secs)+1);
+ continue;
+ }
+ if (error)
+ goto out;
+ len = sizeof(*reply) - auio.uio_resid;
+
+ /* Do we have the required number of bytes ? */
+ if (len < BOOTP_MIN_LEN)
+ continue;
+
+ /* Is it the right reply? */
+ if (reply->op != 2)
+ continue;
+
+ if (reply->xid != call->xid)
+ continue;
+
+ if (reply->hlen != call->hlen)
+ continue;
+
+ if (bcmp(reply->chaddr,call->chaddr,call->hlen))
+ continue;
+
+ goto gotreply; /* break two levels */
+
+ } /* while secs */
+ } /* send/receive a number of times then return an error */
+ {
+ uint32_t addr = ntohl(sin->sin_addr.s_addr);
+ printf("BOOTP timeout for server %"PRIu32".%"PRIu32".%"PRIu32".%"PRIu32"\n",
+ (addr >> 24) & 0xff, (addr >> 16) & 0xff,
+ (addr >> 8) & 0xff, addr & 0xff);
+ }
+ error = ETIMEDOUT;
+ goto out;
+
+ gotreply:
+ out:
+ if (nam) m_freem(nam);
+ soclose(so);
+ return error;
+}
+
+int
+bootpc_fakeup_interface(struct ifreq *ireq,struct socket *so,
+ struct proc *procp)
+{
+ struct sockaddr_in *sin;
+ int error;
+ struct sockaddr_in dst;
+ struct sockaddr_in gw;
+ struct sockaddr_in mask;
+
+ /*
+ * Bring up the interface.
+ *
+ * Get the old interface flags and or IFF_UP into them; if
+ * IFF_UP set blindly, interface selection can be clobbered.
+ */
+ error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_fakeup_interface: GIFFLAGS, error=%s\n", strerror(error));
+ return error;
+ }
+ ireq->ifr_flags |= IFF_UP;
+ error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_fakeup_interface: SIFFLAGS, error=%s\n", strerror(error));
+ return error;
+ }
+
+ /*
+ * Do enough of ifconfig(8) so that the chosen interface
+ * can talk to the servers. (just set the address)
+ */
+ /* addr is 0.0.0.0 */
+
+ sin = (struct sockaddr_in *)&ireq->ifr_addr;
+ bzero((caddr_t)sin, sizeof(*sin));
+ sin->sin_len = sizeof(*sin);
+ sin->sin_family = AF_INET;
+ sin->sin_addr.s_addr = INADDR_ANY;
+ error = ifioctl(so, SIOCSIFADDR, (caddr_t)ireq, procp);
+ /*
+ * Ignore a File already exists (EEXIST) error code. This means a
+ * route for the address is already present and is returned on
+ * a second pass to here.
+ */
+ if (error && (error != EEXIST)) {
+ printf("bootpc_fakeup_interface: set if addr, error=%s\n", strerror(error));
+ return error;
+ }
+
+ /* netmask is 0.0.0.0 */
+
+ sin = (struct sockaddr_in *)&ireq->ifr_addr;
+ bzero((caddr_t)sin, sizeof(*sin));
+ sin->sin_len = sizeof(*sin);
+ sin->sin_family = AF_INET;
+ sin->sin_addr.s_addr = INADDR_ANY;
+ error = ifioctl(so, SIOCSIFNETMASK, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_fakeup_interface: set if netmask, error=%s\n", strerror(error));
+ return error;
+ }
+
+ /* Broadcast is 255.255.255.255 */
+
+ sin = (struct sockaddr_in *)&ireq->ifr_addr;
+ bzero((caddr_t)sin, sizeof(*sin));
+ sin->sin_len = sizeof(*sin);
+ sin->sin_family = AF_INET;
+ sin->sin_addr.s_addr = INADDR_BROADCAST;
+ error = ifioctl(so, SIOCSIFBRDADDR, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_fakeup_interface: set broadcast addr, error=%s\n", strerror(error));
+ return error;
+ }
+
+ /* Add default route to 0.0.0.0 so we can send data */
+
+ bzero((caddr_t) &dst, sizeof(dst));
+ dst.sin_len=sizeof(dst);
+ dst.sin_family=AF_INET;
+ dst.sin_addr.s_addr = htonl(0);
+
+ bzero((caddr_t) &gw, sizeof(gw));
+ gw.sin_len=sizeof(gw);
+ gw.sin_family=AF_INET;
+ gw.sin_addr.s_addr = htonl(0x0);
+
+ bzero((caddr_t) &mask, sizeof(mask));
+ mask.sin_len=sizeof(mask);
+ mask.sin_family=AF_INET;
+ mask.sin_addr.s_addr = htonl(0);
+
+ error = rtrequest(RTM_ADD,
+ (struct sockaddr *) &dst,
+ (struct sockaddr *) &gw,
+ (struct sockaddr *) &mask,
+ RTF_UP | RTF_STATIC
+ , NULL);
+ if (error && error != EEXIST)
+ printf("bootpc_fakeup_interface: add default route, error=%s\n",
+ strerror(error));
+
+ return error;
+}
+
+int
+bootpc_adjust_interface(struct ifreq *ireq,struct socket *so,
+ struct sockaddr_in *myaddr,
+ struct sockaddr_in *netmask,
+ struct sockaddr_in *gw,
+ struct proc *procp)
+{
+ int error;
+ struct sockaddr_in oldgw;
+ struct sockaddr_in olddst;
+ struct sockaddr_in oldmask;
+ struct sockaddr_in *sin;
+
+ /* Remove old default route to 0.0.0.0 */
+
+ bzero((caddr_t) &olddst, sizeof(olddst));
+ olddst.sin_len=sizeof(olddst);
+ olddst.sin_family=AF_INET;
+ olddst.sin_addr.s_addr = INADDR_ANY;
+
+ bzero((caddr_t) &oldgw, sizeof(oldgw));
+ oldgw.sin_len=sizeof(oldgw);
+ oldgw.sin_family=AF_INET;
+ oldgw.sin_addr.s_addr = INADDR_ANY;
+
+ bzero((caddr_t) &oldmask, sizeof(oldmask));
+ oldmask.sin_len=sizeof(oldmask);
+ oldmask.sin_family=AF_INET;
+ oldmask.sin_addr.s_addr = INADDR_ANY;
+
+ error = rtrequest(RTM_DELETE,
+ (struct sockaddr *) &olddst,
+ (struct sockaddr *) &oldgw,
+ (struct sockaddr *) &oldmask,
+ (RTF_UP | RTF_STATIC), NULL);
+ if (error) {
+ printf("nfs_boot: del default route, error=%d\n", error);
+ return error;
+ }
+
+ /*
+ * Do enough of ifconfig(8) so that the chosen interface
+ * can talk to the servers. (just set the address)
+ */
+ bcopy(netmask,&ireq->ifr_addr,sizeof(*netmask));
+ error = ifioctl(so, SIOCSIFNETMASK, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_adjust_interface: set netmask, error=%s\n", strerror(error));
+ return error;
+ }
+
+ /* Broadcast is with host part of IP address all 1's */
+
+ sin = (struct sockaddr_in *)&ireq->ifr_addr;
+ bzero((caddr_t)sin, sizeof(*sin));
+ sin->sin_len = sizeof(*sin);
+ sin->sin_family = AF_INET;
+ sin->sin_addr.s_addr = myaddr->sin_addr.s_addr | ~ netmask->sin_addr.s_addr;
+ error = ifioctl(so, SIOCSIFBRDADDR, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_adjust_interface: set broadcast addr, error=%s\n", strerror(error));
+ return error;
+ }
+
+ bcopy(myaddr,&ireq->ifr_addr,sizeof(*myaddr));
+ error = ifioctl(so, SIOCSIFADDR, (caddr_t)ireq, procp);
+ if (error) {
+ printf("bootpc_adjust_interface: set if addr, error=%s\n", strerror(error));
+ return error;
+ }
+
+ /* Add new default route */
+
+ error = rtrequest(RTM_ADD,
+ (struct sockaddr *) &olddst,
+ (struct sockaddr *) gw,
+ (struct sockaddr *) &oldmask,
+ (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL);
+ if (error) {
+ printf("bootpc_adjust_interface: add net route, error=%d\n", error);
+ }
+
+ return error;
+}
+
+#if !defined(__rtems__)
+static int
+setfs(struct sockaddr_in *addr, char *path, char *p)
+{
+ unsigned ip = 0;
+ int val;
+
+ if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
+ ip = val << 24;
+ if (*p != '.') return(0);
+ p++;
+ if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
+ ip |= (val << 16);
+ if (*p != '.') return(0);
+ p++;
+ if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
+ ip |= (val << 8);
+ if (*p != '.') return(0);
+ p++;
+ if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
+ ip |= val;
+ if (*p != ':') return(0);
+ p++;
+
+ addr->sin_addr.s_addr = htonl(ip);
+ addr->sin_len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+
+ strncpy(path,p,MNAMELEN-1);
+ return(1);
+}
+#endif
+
+#if !defined(__rtems__)
+static int
+getdec(char **ptr)
+{
+ char *p = *ptr;
+ int ret=0;
+ if ((*p < '0') || (*p > '9')) return(-1);
+ while ((*p >= '0') && (*p <= '9')) {
+ ret = ret*10 + (*p - '0');
+ p++;
+ }
+ *ptr = p;
+ return(ret);
+}
+#endif
+
+static void printip(char *prefix,struct in_addr addr)
+{
+ uint32_t ip;
+
+ ip = ntohl(addr.s_addr);
+
+ printf("%s is %" PRId32" .%" PRId32" .%" PRId32" .%" PRId32" \n",prefix,
+ ip >> 24, (ip >> 16) & 0xff ,(ip >> 8) & 0xff ,ip & 0xff );
+}
+
+static int dhcpOptionOverload = 0;
+static char dhcp_gotgw = 0;
+static char dhcp_gotnetmask = 0;
+static char dhcp_gotserver = 0;
+static char dhcp_gotlogserver = 0;
+static struct sockaddr_in dhcp_netmask;
+static struct sockaddr_in dhcp_gw;
+static char *dhcp_hostname = NULL;
+
+static void
+processOptions (unsigned char *optbuf, int optbufSize)
+{
+ int j = 0;
+ int len;
+ int code, ncode;
+ unsigned char *p;
+
+ ncode = optbuf[0];
+ while (j < optbufSize) {
+ code = optbuf[j] = ncode;
+ if (code == 255)
+ return;
+ if (code == 0) {
+ j++;
+ continue;
+ }
+ len = optbuf[j+1];
+ j += 2;
+ if ((len + j) >= optbufSize) {
+ printf ("Truncated field for code %d", code);
+ return;
+ }
+ ncode = optbuf[j+len];
+ optbuf[j+len] = '\0';
+ p = &optbuf[j];
+ j += len;
+
+ /*
+ * Process the option
+ */
+ switch (code) {
+ case 1:
+ /* Subnet mask */
+ if (len!=4) {
+ printf("bootpc: subnet mask len is %d\n",len);
+ continue;
+ }
+ bcopy (p, &dhcp_netmask.sin_addr, 4);
+ dhcp_gotnetmask = 1;
+ break;
+
+ case 2:
+ /* Time offset */
+ if (len!=4) {
+ printf("bootpc: time offset len is %d\n",len);
+ continue;
+ }
+ bcopy (p, &rtems_bsdnet_timeoffset, 4);
+ rtems_bsdnet_timeoffset = ntohl (rtems_bsdnet_timeoffset);
+ break;
+
+ case 3:
+ /* Routers */
+ if (len % 4) {
+ printf ("bootpc: Router Len is %d\n", len);
+ continue;
+ }
+ if (len > 0) {
+ bcopy(p, &dhcp_gw.sin_addr, 4);
+ dhcp_gotgw = 1;
+ }
+ break;
+
+ case 42:
+ /* NTP servers */
+ if (len % 4) {
+ printf ("bootpc: time server Len is %d\n", len);
+ continue;
+ }
+ {
+ int tlen = 0;
+ while ((tlen < len) &&
+ (rtems_bsdnet_ntpserver_count < sizeof rtems_bsdnet_config.ntp_server /
+ sizeof rtems_bsdnet_config.ntp_server[0])) {
+ bcopy (p+tlen,
+ &rtems_bsdnet_ntpserver[rtems_bsdnet_ntpserver_count],
+ 4);
+ printip("Time Server",
+ rtems_bsdnet_ntpserver[rtems_bsdnet_ntpserver_count]);
+ rtems_bsdnet_ntpserver_count++;
+ tlen += 4;
+ }
+ }
+ break;
+
+ case 6:
+ /* Domain Name servers */
+ if (len % 4) {
+ printf ("bootpc: DNS Len is %d", len);
+ continue;
+ }
+ {
+ int dlen = 0;
+ while ((dlen < len) &&
+ (rtems_bsdnet_nameserver_count < sizeof rtems_bsdnet_config.name_server /
+ sizeof rtems_bsdnet_config.name_server[0])) {
+ bcopy (p+dlen,
+ &rtems_bsdnet_nameserver[rtems_bsdnet_nameserver_count],
+ 4);
+ printip("Domain Name Server",
+ rtems_bsdnet_nameserver[rtems_bsdnet_nameserver_count]);
+ rtems_bsdnet_nameserver_count++;
+ dlen += 4;
+ }
+ }
+ break;
+
+ case 12:
+ /* Host name */
+ if (len>=MAXHOSTNAMELEN) {
+ printf ("bootpc: hostname >=%d bytes", MAXHOSTNAMELEN);
+ continue;
+ }
+ if (sethostname ((char *)p, len) < 0) {
+ printf("bootpc: Can't set host name");
+ }
+ printf("Hostname is %s\n", p);
+ dhcp_hostname = bootp_strdup_realloc(dhcp_hostname,(char *)p);
+ break;
+
+ case 7:
+ /* Log servers */
+ if (len % 4) {
+ printf ("bootpc: Log server Len is %d", len);
+ continue;
+ }
+ if (len > 0) {
+ bcopy(p, &rtems_bsdnet_log_host_address, 4);
+ dhcp_gotlogserver = 1;
+ }
+ break;
+
+ case 15:
+ /* Domain name */
+ if (p[0]) {
+ rtems_bsdnet_domain_name =
+ bootp_strdup_realloc(rtems_bsdnet_domain_name,(char *)p);
+ printf("Domain name is %s\n", rtems_bsdnet_domain_name);
+ }
+ break;
+
+ case 16: /* Swap server IP address. unused */
+ break;
+
+ case 52:
+ /* DHCP option override */
+ if (len != 1) {
+ printf ("bootpc: DHCP option overload len is %d", len);
+ continue;
+ }
+ dhcpOptionOverload = p[0];
+ break;
+
+ case 128: /* Site-specific option for DHCP servers that
+ * a) don't supply tag 54
+ * and
+ * b) don't supply the server address in siaddr
+ * For example, on Solaris 2.6 in.dhcpd, include in the dhcptab:
+ * Bootsrv s Site,128,IP,1,1
+ * and use that symbol in the macro that defines the client:
+ * Bootsrv=<tftp-server-ip-address>
+ */
+ case 54:
+ /* DHCP server */
+ if (len != 4) {
+ printf ("bootpc: DHCP server len is %d", len);
+ continue;
+ }
+ bcopy(p, &rtems_bsdnet_bootp_server_address, 4);
+ dhcp_gotserver = 1;
+ break;
+
+ case 66:
+ /* DHCP server name option */
+ if (p[0])
+ rtems_bsdnet_bootp_server_name =
+ bootp_strdup_realloc(rtems_bsdnet_bootp_server_name,(char *)p);
+ break;
+
+ case 67:
+ /* DHCP bootfile option */
+ if (p[0])
+ rtems_bsdnet_bootp_boot_file_name =
+ bootp_strdup_realloc(rtems_bsdnet_bootp_boot_file_name,(char *)p);
+ break;
+
+ case 129:
+ /* Site specific option; we use this to get
+ * a 'command line string'
+ */
+ if (p[0])
+ rtems_bsdnet_bootp_cmdline = strdup((char *)p);
+ break;
+
+ default:
+ printf ("Ignoring BOOTP/DHCP option code %d\n", code);
+ break;
+ }
+ }
+}
+
+#define EALEN 6
+
+bool
+bootpc_init(bool update_files, bool forever)
+{
+ struct bootp_packet call;
+ struct bootp_packet reply;
+ static u_int32_t xid = ~0xFF;
+
+ struct ifreq ireq;
+ struct ifnet *ifp;
+ struct socket *so;
+ int j;
+ int error;
+ struct sockaddr_in myaddr;
+ struct ifaddr *ifa;
+ struct sockaddr_dl *sdl = NULL;
+ char *delim;
+ struct proc *procp = NULL;
+
+ /*
+ * If already filled in, don't touch it here
+ */
+ if (nfs_diskless_valid)
+ return true;
+
+ /*
+ * If we are to update the files create the root
+ * file structure.
+ */
+ if (update_files)
+ if (rtems_create_root_fs () < 0) {
+ printf("Error creating the root filesystem.\nFile not created.\n");
+ update_files = 0;
+ }
+
+ if (dhcp_hostname != NULL) {
+ /* free it */
+ dhcp_hostname=bootp_strdup_realloc(dhcp_hostname,0);
+ }
+
+ /*
+ * Find a network interface.
+ */
+ for (ifp = ifnet; ifp != 0; ifp = ifp->if_next)
+ if ((ifp->if_flags &
+ (IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
+ break;
+ if (ifp == NULL) {
+ printf("bootpc_init: no suitable interface\n");
+ return false;
+ }
+ bzero(&ireq,sizeof(ireq));
+ sprintf(ireq.ifr_name, "%s%d", ifp->if_name,ifp->if_unit);
+ printf("bootpc_init: using network interface '%s'\n",
+ ireq.ifr_name);
+
+ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp)) != 0) {
+ printf("bootpc_init: socreate, error=%d", error);
+ return false;
+ }
+ if (bootpc_fakeup_interface(&ireq,so,procp) != 0) {
+ soclose(so);
+ return false;
+ }
+
+ /* Get HW address */
+
+ for (ifa = ifp->if_addrlist;ifa; ifa = ifa->ifa_next)
+ if (ifa->ifa_addr->sa_family == AF_LINK &&
+ (sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) &&
+ sdl->sdl_type == IFT_ETHER)
+ break;
+
+ if (!sdl) {
+ printf("bootpc: Unable to find HW address\n");
+ soclose(so);
+ return false;
+ }
+ if (sdl->sdl_alen != EALEN ) {
+ printf("bootpc: HW address len is %d, expected value is %d\n",
+ sdl->sdl_alen,EALEN);
+ soclose(so);
+ return false;
+ }
+
+ printf("bootpc hw address is ");
+ delim="";
+ for (j=0;j<sdl->sdl_alen;j++) {
+ printf("%s%x",delim,((unsigned char *)LLADDR(sdl))[j]);
+ delim=":";
+ }
+ printf("\n");
+
+#if 0
+ bootpboot_p_iflist();
+ bootpboot_p_rtlist();
+#endif
+
+ while (true) {
+ bzero((caddr_t) &call, sizeof(call));
+
+ /* bootpc part */
+ call.op = 1; /* BOOTREQUEST */
+ call.htype= 1; /* 10mb ethernet */
+ call.hlen=sdl->sdl_alen; /* Hardware address length */
+ call.hops=0;
+ xid++;
+ call.xid = txdr_unsigned(xid);
+ bcopy(LLADDR(sdl),&call.chaddr,sdl->sdl_alen);
+
+ call.vend[0]=99;
+ call.vend[1]=130;
+ call.vend[2]=83;
+ call.vend[3]=99;
+ call.vend[4]=255;
+
+ call.secs = 0;
+ call.flags = htons(0x8000); /* We need an broadcast answer */
+
+ error = bootpc_call(&call,&reply,procp);
+
+ if (!error)
+ break;
+
+ printf("BOOTP call failed -- error %d", error);
+
+ if (!forever) {
+ soclose(so);
+ return false;
+ }
+ }
+
+ /*
+ * Initialize network address structures
+ */
+ bzero(&myaddr,sizeof(myaddr));
+ bzero(&dhcp_netmask,sizeof(dhcp_netmask));
+ bzero(&dhcp_gw,sizeof(dhcp_gw));
+ myaddr.sin_len = sizeof(myaddr);
+ myaddr.sin_family = AF_INET;
+ dhcp_netmask.sin_len = sizeof(dhcp_netmask);
+ dhcp_netmask.sin_family = AF_INET;
+ dhcp_gw.sin_len = sizeof(dhcp_gw);
+ dhcp_gw.sin_family= AF_INET;
+
+ /*
+ * Set our address
+ */
+ myaddr.sin_addr = reply.yiaddr;
+ printip("My ip address",myaddr.sin_addr);
+
+ /*
+ * Process BOOTP/DHCP options
+ */
+ if (reply.vend[0]==99 && reply.vend[1]==130 &&
+ reply.vend[2]==83 && reply.vend[3]==99) {
+ processOptions (&reply.vend[4], sizeof(reply.vend) - 4);
+ }
+ if (dhcpOptionOverload & 1) {
+ processOptions ((unsigned char *)reply.file, sizeof reply.file);
+ }
+ else {
+ if (reply.file[0])
+ rtems_bsdnet_bootp_boot_file_name =
+ bootp_strdup_realloc(rtems_bsdnet_bootp_boot_file_name,reply.file);
+ }
+ if (dhcpOptionOverload & 2) {
+ processOptions ((unsigned char *)reply.sname, sizeof reply.sname);
+ }
+ else {
+ if (reply.sname[0])
+ rtems_bsdnet_bootp_server_name =
+ bootp_strdup_realloc(rtems_bsdnet_bootp_server_name,reply.sname);
+ }
+ if (rtems_bsdnet_bootp_server_name)
+ printf ("Server name is %s\n", rtems_bsdnet_bootp_server_name);
+ if (rtems_bsdnet_bootp_boot_file_name)
+ printf ("Boot file is %s\n", rtems_bsdnet_bootp_boot_file_name);
+ if (rtems_bsdnet_bootp_cmdline)
+ printf ("Command line is %s\n", rtems_bsdnet_bootp_cmdline);
+
+ /*
+ * Use defaults if values were not supplied by BOOTP/DHCP options
+ */
+ if (!dhcp_gotnetmask) {
+ if (IN_CLASSA(ntohl(myaddr.sin_addr.s_addr)))
+ dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET);
+ else if (IN_CLASSB(ntohl(myaddr.sin_addr.s_addr)))
+ dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET);
+ else
+ dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET);
+ }
+ printip ("Subnet mask", dhcp_netmask.sin_addr);
+ if (!dhcp_gotserver)
+ rtems_bsdnet_bootp_server_address = reply.siaddr;
+ printip ("Server ip address" ,rtems_bsdnet_bootp_server_address);
+ if (!dhcp_gotgw)
+ dhcp_gw.sin_addr = reply.giaddr;
+ printip ("Gateway ip address", dhcp_gw.sin_addr);
+ if (!dhcp_gotlogserver)
+ rtems_bsdnet_log_host_address = rtems_bsdnet_bootp_server_address;
+ printip ("Log server ip address", rtems_bsdnet_log_host_address);
+
+ /*
+ * Update the files if we are asked too.
+ */
+ if (update_files) {
+ char *dn = rtems_bsdnet_domain_name;
+ char *hn = dhcp_hostname;
+ if (!dn)
+ dn = "mydomain";
+ if (!hn)
+ hn = "me";
+ rtems_rootfs_append_host_rec(myaddr.sin_addr.s_addr, hn, dn);
+
+ /*
+ * Should the given domainname be used here ?
+ */
+ if (dhcp_gotserver) {
+ if (rtems_bsdnet_bootp_server_name)
+ hn = rtems_bsdnet_bootp_server_name;
+ else
+ hn = "bootps";
+ rtems_rootfs_append_host_rec(rtems_bsdnet_bootp_server_address.s_addr,
+ hn, dn);
+ }
+
+ if (dhcp_gotlogserver) {
+ rtems_rootfs_append_host_rec(rtems_bsdnet_log_host_address.s_addr,
+ "logs", dn);
+ }
+
+ /*
+ * Setup the DNS configuration file /etc/resolv.conf.
+ */
+ if (rtems_bsdnet_nameserver_count) {
+ int i;
+ char buf[64];
+ const char *bufl[1];
+
+ bufl[0] = buf;
+
+#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH)
+
+ if (rtems_bsdnet_domain_name &&
+ (strlen(rtems_bsdnet_domain_name) < (sizeof(buf) - 1))) {
+ strcpy(buf, "search ");
+ strcat(buf, rtems_bsdnet_domain_name);
+ strcat(buf, "\n");
+ rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl);
+ }
+
+ for (i = 0; i < rtems_bsdnet_nameserver_count; i++) {
+ strcpy(buf, "nameserver ");
+ strcat(buf, inet_ntoa(rtems_bsdnet_nameserver[i]));
+ strcat(buf, "\n");
+ if (rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl))
+ break;
+ }
+ }
+ }
+
+ /*
+ * Configure the interface with the new settings
+ */
+ error = bootpc_adjust_interface(&ireq,so,
+ &myaddr,&dhcp_netmask,&dhcp_gw,procp);
+ soclose(so);
+
+ return true;
+}
diff --git a/cpukit/libnetworking/nfs/nfsproto.h b/cpukit/libnetworking/nfs/nfsproto.h
new file mode 100644
index 0000000000..9c937068a2
--- /dev/null
+++ b/cpukit/libnetworking/nfs/nfsproto.h
@@ -0,0 +1,424 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95
+ * $FreeBSD: src/sys/nfs/nfsproto.h,v 1.11 2005/01/07 01:45:50 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NFS_NFSPROTO_H_
+#define _NFS_NFSPROTO_H_
+
+/*
+ * nfs definitions as per the Version 2 and 3 specs
+ */
+
+/*
+ * Constants as defined in the Sun NFS Version 2 and 3 specs.
+ * "NFS: Network File System Protocol Specification" RFC1094
+ * and in the "NFS: Network File System Version 3 Protocol
+ * Specification"
+ */
+
+#define NFS_PORT 2049
+#define NFS_PROG 100003
+#define NFS_VER2 2
+#define NFS_VER3 3
+#define NFS_V2MAXDATA 8192
+#define NFS_MAXDGRAMDATA 16384
+#define NFS_MAXDATA 32768
+#define NFS_MAXPATHLEN 1024
+#define NFS_MAXNAMLEN 255
+#define NFS_MAXPKTHDR 404
+#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA)
+#define NFS_MINPACKET 20
+#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */
+
+/* Stat numbers for rpc returns (version 2 and 3) */
+#define NFS_OK 0
+#define NFSERR_PERM 1
+#define NFSERR_NOENT 2
+#define NFSERR_IO 5
+#define NFSERR_NXIO 6
+#define NFSERR_ACCES 13
+#define NFSERR_EXIST 17
+#define NFSERR_XDEV 18 /* Version 3 only */
+#define NFSERR_NODEV 19
+#define NFSERR_NOTDIR 20
+#define NFSERR_ISDIR 21
+#define NFSERR_INVAL 22 /* Version 3 only */
+#define NFSERR_FBIG 27
+#define NFSERR_NOSPC 28
+#define NFSERR_ROFS 30
+#define NFSERR_MLINK 31 /* Version 3 only */
+#define NFSERR_NAMETOL 63
+#define NFSERR_NOTEMPTY 66
+#define NFSERR_DQUOT 69
+#define NFSERR_STALE 70
+#define NFSERR_REMOTE 71 /* Version 3 only */
+#define NFSERR_WFLUSH 99 /* Version 2 only */
+#define NFSERR_BADHANDLE 10001 /* The rest Version 3, 4 only */
+#define NFSERR_NOT_SYNC 10002
+#define NFSERR_BAD_COOKIE 10003
+#define NFSERR_NOTSUPP 10004
+#define NFSERR_TOOSMALL 10005
+#define NFSERR_SERVERFAULT 10006
+#define NFSERR_BADTYPE 10007
+#define NFSERR_JUKEBOX 10008
+#define NFSERR_TRYLATER NFSERR_JUKEBOX
+#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */
+
+
+
+#define NFSERR_RETVOID 0x20000000 /* Return void, not error */
+#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */
+#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */
+
+/* Sizes in bytes of various nfs rpc components */
+#define NFSX_UNSIGNED 4
+
+/* specific to NFS Version 2 */
+#define NFSX_V2FH 32
+#define NFSX_V2FATTR 68
+#define NFSX_V2SATTR 32
+#define NFSX_V2COOKIE 4
+#define NFSX_V2STATFS 20
+
+/* specific to NFS Version 3 */
+#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */
+#define NFSX_V3FHMAX 64 /* max. allowed by protocol */
+#define NFSX_V3FATTR 84
+#define NFSX_V3SATTR 60 /* max. all fields filled in */
+#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr))
+#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED)
+#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED)
+#define NFSX_V3COOKIEVERF 8
+#define NFSX_V3WRITEVERF 8
+#define NFSX_V3CREATEVERF 8
+#define NFSX_V3STATFS 52
+#define NFSX_V3FSINFO 48
+#define NFSX_V3PATHCONF 24
+
+/* variants for both versions */
+#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \
+ NFSX_V2FH)
+#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH)
+#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR)
+#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0)
+#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0)
+#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \
+ NFSX_V2FATTR)
+#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0)
+#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR)
+#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR)
+#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0)
+#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0)
+#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \
+ (2 * NFSX_UNSIGNED))
+#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS)
+
+/* nfs rpc procedure numbers (before version mapping) */
+#define NFSPROC_NULL 0
+#define NFSPROC_GETATTR 1
+#define NFSPROC_SETATTR 2
+#define NFSPROC_LOOKUP 3
+#define NFSPROC_ACCESS 4
+#define NFSPROC_READLINK 5
+#define NFSPROC_READ 6
+#define NFSPROC_WRITE 7
+#define NFSPROC_CREATE 8
+#define NFSPROC_MKDIR 9
+#define NFSPROC_SYMLINK 10
+#define NFSPROC_MKNOD 11
+#define NFSPROC_REMOVE 12
+#define NFSPROC_RMDIR 13
+#define NFSPROC_RENAME 14
+#define NFSPROC_LINK 15
+#define NFSPROC_READDIR 16
+#define NFSPROC_READDIRPLUS 17
+#define NFSPROC_FSSTAT 18
+#define NFSPROC_FSINFO 19
+#define NFSPROC_PATHCONF 20
+#define NFSPROC_COMMIT 21
+#define NFSPROC_NOOP 22
+#define NFS_NPROCS 23
+
+/* Actual Version 2 procedure numbers */
+#define NFSV2PROC_NULL 0
+#define NFSV2PROC_GETATTR 1
+#define NFSV2PROC_SETATTR 2
+#define NFSV2PROC_NOOP 3
+#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */
+#define NFSV2PROC_LOOKUP 4
+#define NFSV2PROC_READLINK 5
+#define NFSV2PROC_READ 6
+#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */
+#define NFSV2PROC_WRITE 8
+#define NFSV2PROC_CREATE 9
+#define NFSV2PROC_REMOVE 10
+#define NFSV2PROC_RENAME 11
+#define NFSV2PROC_LINK 12
+#define NFSV2PROC_SYMLINK 13
+#define NFSV2PROC_MKDIR 14
+#define NFSV2PROC_RMDIR 15
+#define NFSV2PROC_READDIR 16
+#define NFSV2PROC_STATFS 17
+
+/*
+ * Constants used by the Version 3 protocol for various RPCs
+ */
+#define NFSV3SATTRTIME_DONTCHANGE 0
+#define NFSV3SATTRTIME_TOSERVER 1
+#define NFSV3SATTRTIME_TOCLIENT 2
+
+#define NFSV3ACCESS_READ 0x01
+#define NFSV3ACCESS_LOOKUP 0x02
+#define NFSV3ACCESS_MODIFY 0x04
+#define NFSV3ACCESS_EXTEND 0x08
+#define NFSV3ACCESS_DELETE 0x10
+#define NFSV3ACCESS_EXECUTE 0x20
+
+#define NFSV3WRITE_UNSTABLE 0
+#define NFSV3WRITE_DATASYNC 1
+#define NFSV3WRITE_FILESYNC 2
+
+#define NFSV3CREATE_UNCHECKED 0
+#define NFSV3CREATE_GUARDED 1
+#define NFSV3CREATE_EXCLUSIVE 2
+
+#define NFSV3FSINFO_LINK 0x01
+#define NFSV3FSINFO_SYMLINK 0x02
+#define NFSV3FSINFO_HOMOGENEOUS 0x08
+#define NFSV3FSINFO_CANSETTIME 0x10
+
+/* File types */
+typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5,
+ NFSOCK=6, NFFIFO=7 } nfstype;
+
+/* Structs for common parts of the rpc's */
+/*
+ * File Handle (32 bytes for version 2), variable up to 64 for version 3.
+ * File Handles of up to NFS_SMALLFH in size are stored directly in the
+ * nfs node, whereas larger ones are malloc'd. (This never happens when
+ * NFS_SMALLFH is set to 64.)
+ * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4.
+ */
+#ifndef NFS_SMALLFH
+#define NFS_SMALLFH 64
+#endif
+union nfsfh {
+ fhandle_t fh_generic;
+ u_char fh_bytes[NFS_SMALLFH];
+};
+typedef union nfsfh nfsfh_t;
+
+struct nfsv2_time {
+ u_int32_t nfsv2_sec;
+ u_int32_t nfsv2_usec;
+};
+typedef struct nfsv2_time nfstime2;
+
+struct nfsv3_time {
+ u_int32_t nfsv3_sec;
+ u_int32_t nfsv3_nsec;
+};
+typedef struct nfsv3_time nfstime3;
+
+/*
+ * Quads are defined as arrays of 2 longs to ensure dense packing for the
+ * protocol and to facilitate xdr conversion.
+ */
+struct nfs_uquad {
+ u_int32_t nfsuquad[2];
+};
+typedef struct nfs_uquad nfsuint64;
+
+/*
+ * Used to convert between two u_longs and a u_quad_t.
+ */
+union nfs_quadconvert {
+ u_int32_t lval[2];
+ u_quad_t qval;
+};
+typedef union nfs_quadconvert nfsquad_t;
+
+/*
+ * NFS Version 3 special file number.
+ */
+struct nfsv3_spec {
+ u_int32_t specdata1;
+ u_int32_t specdata2;
+};
+typedef struct nfsv3_spec nfsv3spec;
+
+/*
+ * File attributes and setable attributes. These structures cover both
+ * NFS version 2 and the version 3 protocol. Note that the union is only
+ * used so that one pointer can refer to both variants. These structures
+ * go out on the wire and must be densely packed, so no quad data types
+ * are used. (all fields are longs or u_longs or structures of same)
+ * NB: You can't do sizeof(struct nfs_fattr), you must use the
+ * NFSX_FATTR(v3) macro.
+ */
+struct nfs_fattr {
+ u_int32_t fa_type;
+ u_int32_t fa_mode;
+ u_int32_t fa_nlink;
+ u_int32_t fa_uid;
+ u_int32_t fa_gid;
+ union {
+ struct {
+ u_int32_t nfsv2fa_size;
+ u_int32_t nfsv2fa_blocksize;
+ u_int32_t nfsv2fa_rdev;
+ u_int32_t nfsv2fa_blocks;
+ u_int32_t nfsv2fa_fsid;
+ u_int32_t nfsv2fa_fileid;
+ nfstime2 nfsv2fa_atime;
+ nfstime2 nfsv2fa_mtime;
+ nfstime2 nfsv2fa_ctime;
+ } fa_nfsv2;
+ struct {
+ nfsuint64 nfsv3fa_size;
+ nfsuint64 nfsv3fa_used;
+ nfsv3spec nfsv3fa_rdev;
+ nfsuint64 nfsv3fa_fsid;
+ nfsuint64 nfsv3fa_fileid;
+ nfstime3 nfsv3fa_atime;
+ nfstime3 nfsv3fa_mtime;
+ nfstime3 nfsv3fa_ctime;
+ } fa_nfsv3;
+ } fa_un;
+};
+
+/* and some ugly defines for accessing union components */
+#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size
+#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize
+#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev
+#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks
+#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid
+#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid
+#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime
+#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime
+#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime
+#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size
+#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used
+#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev
+#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid
+#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid
+#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime
+#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime
+#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime
+
+struct nfsv2_sattr {
+ u_int32_t sa_mode;
+ u_int32_t sa_uid;
+ u_int32_t sa_gid;
+ u_int32_t sa_size;
+ nfstime2 sa_atime;
+ nfstime2 sa_mtime;
+};
+
+/*
+ * NFS Version 3 sattr structure for the new node creation case.
+ */
+struct nfsv3_sattr {
+ u_int32_t sa_modetrue;
+ u_int32_t sa_mode;
+ u_int32_t sa_uidfalse;
+ u_int32_t sa_gidfalse;
+ u_int32_t sa_sizefalse;
+ u_int32_t sa_atimetype;
+ nfstime3 sa_atime;
+ u_int32_t sa_mtimetype;
+ nfstime3 sa_mtime;
+};
+
+struct nfs_statfs {
+ union {
+ struct {
+ u_int32_t nfsv2sf_tsize;
+ u_int32_t nfsv2sf_bsize;
+ u_int32_t nfsv2sf_blocks;
+ u_int32_t nfsv2sf_bfree;
+ u_int32_t nfsv2sf_bavail;
+ } sf_nfsv2;
+ struct {
+ nfsuint64 nfsv3sf_tbytes;
+ nfsuint64 nfsv3sf_fbytes;
+ nfsuint64 nfsv3sf_abytes;
+ nfsuint64 nfsv3sf_tfiles;
+ nfsuint64 nfsv3sf_ffiles;
+ nfsuint64 nfsv3sf_afiles;
+ u_int32_t nfsv3sf_invarsec;
+ } sf_nfsv3;
+ } sf_un;
+};
+
+#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize
+#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize
+#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks
+#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree
+#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail
+#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes
+#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes
+#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes
+#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles
+#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles
+#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles
+#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec
+
+struct nfsv3_fsinfo {
+ u_int32_t fs_rtmax;
+ u_int32_t fs_rtpref;
+ u_int32_t fs_rtmult;
+ u_int32_t fs_wtmax;
+ u_int32_t fs_wtpref;
+ u_int32_t fs_wtmult;
+ u_int32_t fs_dtpref;
+ nfsuint64 fs_maxfilesize;
+ nfstime3 fs_timedelta;
+ u_int32_t fs_properties;
+};
+
+struct nfsv3_pathconf {
+ u_int32_t pc_linkmax;
+ u_int32_t pc_namemax;
+ u_int32_t pc_notrunc;
+ u_int32_t pc_chownrestricted;
+ u_int32_t pc_caseinsensitive;
+ u_int32_t pc_casepreserving;
+};
+
+#endif
diff --git a/cpukit/libnetworking/nfs/rpcv2.h b/cpukit/libnetworking/nfs/rpcv2.h
new file mode 100644
index 0000000000..c8a41698e7
--- /dev/null
+++ b/cpukit/libnetworking/nfs/rpcv2.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)rpcv2.h 8.2 (Berkeley) 3/30/95
+ * $FreeBSD: src/sys/nfs/rpcv2.h,v 1.14 2005/01/07 01:45:50 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NFS_RPCV2_H_
+#define _NFS_RPCV2_H_
+
+/*
+ * Definitions for Sun RPC Version 2, from
+ * "RPC: Remote Procedure Call Protocol Specification" RFC1057
+ */
+
+/* Version # */
+#define RPC_VER2 2
+
+/* Authentication */
+#define RPCAUTH_NULL 0
+#define RPCAUTH_UNIX 1
+#define RPCAUTH_SHORT 2
+#define RPCAUTH_KERB4 4
+#define RPCAUTH_MAXSIZ 400
+#define RPCVERF_MAXSIZ 12 /* For Kerb, can actually be 400 */
+#define RPCAUTH_UNIXGIDS 16
+
+/*
+ * Constants associated with authentication flavours.
+ */
+#define RPCAKN_FULLNAME 0
+#define RPCAKN_NICKNAME 1
+
+/* msg type */
+#define RPC_CALL 0
+#define RPC_REPLY 1
+
+/* reply status */
+#define RPC_MSGACCEPTED 0
+#define RPC_MSGDENIED 1
+
+/* accepted status */
+#define RPC_SUCCESS 0
+#define RPC_PROGUNAVAIL 1
+#define RPC_PROGMISMATCH 2
+#define RPC_PROCUNAVAIL 3
+#define RPC_GARBAGE 4 /* I like this one */
+#define RPC_SYSTEMERR 5
+
+/* rejected status */
+#define RPC_MISMATCH 0
+#define RPC_AUTHERR 1
+
+/* Authentication failures */
+#define AUTH_OK 0
+#define AUTH_BADCRED 1
+#define AUTH_REJECTCRED 2
+#define AUTH_BADVERF 3
+#define AUTH_REJECTVERF 4
+#define AUTH_TOOWEAK 5 /* Give em wheaties */
+
+/* Sizes of rpc header parts */
+#define RPC_SIZ 24
+#define RPC_REPLYSIZ 28
+
+/* RPC Prog definitions */
+#define RPCPROG_MNT 100005
+#define RPCMNT_VER1 1
+#define RPCMNT_VER3 3
+#define RPCMNT_MOUNT 1
+#define RPCMNT_DUMP 2
+#define RPCMNT_UMOUNT 3
+#define RPCMNT_UMNTALL 4
+#define RPCMNT_EXPORT 5
+#define RPCMNT_NAMELEN 255
+#define RPCMNT_PATHLEN 1024
+#define RPCPROG_NFS 100003
+
+#endif
diff --git a/cpukit/libnetworking/nfs/xdr_subs.h b/cpukit/libnetworking/nfs/xdr_subs.h
new file mode 100644
index 0000000000..62358a57ea
--- /dev/null
+++ b/cpukit/libnetworking/nfs/xdr_subs.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)xdr_subs.h 8.3 (Berkeley) 3/30/95
+ * $FreeBSD: src/sys/nfs/xdr_subs.h,v 1.15 2005/01/07 01:45:50 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NFS_XDR_SUBS_H_
+#define _NFS_XDR_SUBS_H_
+
+/*
+ * Macros used for conversion to/from xdr representation by nfs...
+ * These use the MACHINE DEPENDENT routines ntohl, htonl
+ * As defined by "XDR: External Data Representation Standard" RFC1014
+ *
+ * To simplify the implementation, we use ntohl/htonl even on big-endian
+ * machines, and count on them being `#define'd away. Some of these
+ * might be slightly more efficient as quad_t copies on a big-endian,
+ * but we cannot count on their alignment anyway.
+ */
+
+#define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v)))
+#define txdr_unsigned(v) (htonl((int32_t)(v)))
+
+#define fxdr_nfsv2time(f, t) { \
+ (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \
+ if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \
+ (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \
+ else \
+ (t)->tv_nsec = 0; \
+}
+#define txdr_nfsv2time(f, t) { \
+ ((struct nfsv2_time *)(t))->nfsv2_sec = htonl((f)->tv_sec); \
+ if ((f)->tv_nsec != -1) \
+ ((struct nfsv2_time *)(t))->nfsv2_usec = htonl((f)->tv_nsec / 1000); \
+ else \
+ ((struct nfsv2_time *)(t))->nfsv2_usec = 0xffffffff; \
+}
+
+#define fxdr_nfsv3time(f, t) { \
+ (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \
+ (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \
+}
+#define txdr_nfsv3time(f, t) { \
+ ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \
+ ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \
+}
+
+#define fxdr_hyper(f) \
+ ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \
+ (u_quad_t)(ntohl(((u_int32_t *)(f))[1])))
+#define txdr_hyper(f, t) \
+do { \
+ ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \
+ ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \
+} while (0)
+
+#endif
diff --git a/cpukit/libnetworking/nfsclient/nfsargs.h b/cpukit/libnetworking/nfsclient/nfsargs.h
new file mode 100644
index 0000000000..697ee0c59d
--- /dev/null
+++ b/cpukit/libnetworking/nfsclient/nfsargs.h
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 1989, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)nfs.h 8.4 (Berkeley) 5/1/95
+ * $FreeBSD: src/sys/nfsclient/nfsargs.h,v 1.67 2005/01/07 01:45:51 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _NFSCLIENT_NFSARGS_H_
+#define _NFSCLIENT_NFSARGS_H_
+
+/*
+ * Arguments to mount NFS
+ */
+struct nfs_args {
+ struct sockaddr *addr; /* file server address */
+ int addrlen; /* length of address */
+ int sotype; /* Socket type */
+ int proto; /* and Protocol */
+ u_char *fh; /* File handle to be mounted */
+ int fhsize; /* Size, in bytes, of fh */
+ int flags; /* flags */
+ int wsize; /* write size in bytes */
+ int rsize; /* read size in bytes */
+ int readdirsize; /* readdir size in bytes */
+ int timeo; /* initial timeout in .1 secs */
+ int retrans; /* times to retry send */
+ int maxgrouplist; /* Max. size of group list */
+ int readahead; /* # of blocks to readahead */
+ int leaseterm; /* Term (sec) of lease */
+ int deadthresh; /* Retrans threshold */
+ char *hostname; /* server's name */
+};
+
+/*
+ * NFS mount option flags
+ */
+#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
+#define NFSMNT_WSIZE 0x00000002 /* set write size */
+#define NFSMNT_RSIZE 0x00000004 /* set read size */
+#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
+#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
+#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
+#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
+#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
+/* 0x100 free, was NFSMNT_NQNFS */
+#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
+/* 0x400 free, was NFSMNT_KERB */
+#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
+/* 0x1000 free, was NFSMNT_LEASETERM */
+#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
+#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
+#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
+#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
+#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
+#define NFSMNT_ACREGMIN 0x00040000
+#define NFSMNT_ACREGMAX 0x00080000
+#define NFSMNT_ACDIRMIN 0x00100000
+#define NFSMNT_ACDIRMAX 0x00200000
+#define NFSMNT_NOLOCKD 0x00400000 /* Locks are local */
+#define NFSMNT_NFSV4 0x00800000 /* Use NFS Version 4 protocol */
+#define NFSMNT_HASWRITEVERF 0x01000000 /* NFSv4 Write verifier */
+
+#endif
diff --git a/cpukit/libnetworking/nfsclient/nfsdiskless.h b/cpukit/libnetworking/nfsclient/nfsdiskless.h
new file mode 100644
index 0000000000..9c9a41913c
--- /dev/null
+++ b/cpukit/libnetworking/nfsclient/nfsdiskless.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)nfsdiskless.h 8.1 (Berkeley) 6/10/93
+ * $Id$
+ */
+
+#ifndef _NFS_NFSDISKLESS_H_
+#define _NFS_NFSDISKLESS_H_
+
+/*
+ * Structure that must be initialized for a diskless nfs client.
+ * This structure is used by nfs_mountroot() to set up the root and swap
+ * vnodes plus do a partial ifconfig(8) and route(8) so that the critical net
+ * interface can communicate with the server.
+ * The primary bootstrap is expected to fill in the appropriate fields before
+ * starting the kernel. Whether or not the swap area is nfs mounted is determined
+ * by the value in swdevt[0]. (equal to NODEV --> swap over nfs)
+ * Currently only works for AF_INET protocols.
+ * NB: All fields are stored in net byte order to avoid hassles with
+ * client/server byte ordering differences.
+ */
+
+/*
+ * I have defined a new structure that can handle an NFS Version 3 file handle
+ * but the kernel still expects the old Version 2 one to be provided. The
+ * changes required in nfs_vfsops.c for using the new are documented there in
+ * comments. (I felt that breaking network booting code by changing this
+ * structure would not be prudent at this time, since almost all servers are
+ * still Version 2 anyhow.)
+ */
+struct nfsv3_diskless {
+ struct ifaliasreq myif; /* Default interface */
+ struct sockaddr_in mygateway; /* Default gateway */
+ struct nfs_args swap_args; /* Mount args for swap file */
+ int swap_fhsize; /* Size of file handle */
+ u_char swap_fh[NFSX_V3FHMAX]; /* Swap file's file handle */
+ struct sockaddr_in swap_saddr; /* Address of swap server */
+ char swap_hostnam[MNAMELEN]; /* Host name for mount pt */
+ int swap_nblks; /* Size of server swap file */
+ struct ucred swap_ucred; /* Swap credentials */
+ struct nfs_args root_args; /* Mount args for root fs */
+ int root_fhsize; /* Size of root file handle */
+ u_char root_fh[NFSX_V3FHMAX]; /* File handle of root dir */
+ struct sockaddr_in root_saddr; /* Address of root server */
+ char root_hostnam[MNAMELEN]; /* Host name for mount pt */
+ long root_time; /* Timestamp of root fs */
+ char my_hostnam[MAXHOSTNAMELEN]; /* Client host name */
+};
+
+struct nfs_diskless {
+ struct ifaliasreq myif; /* Default interface */
+ struct sockaddr_in mygateway; /* Default gateway */
+ struct nfs_args swap_args; /* Mount args for swap file */
+ u_char swap_fh[NFSX_V2FH]; /* Swap file's file handle */
+ struct sockaddr_in swap_saddr; /* Address of swap server */
+ char swap_hostnam[MNAMELEN]; /* Host name for mount pt */
+ int swap_nblks; /* Size of server swap file */
+ struct ucred swap_ucred; /* Swap credentials */
+ struct nfs_args root_args; /* Mount args for root fs */
+ u_char root_fh[NFSX_V2FH]; /* File handle of root dir */
+ struct sockaddr_in root_saddr; /* Address of root server */
+ char root_hostnam[MNAMELEN]; /* Host name for mount pt */
+ long root_time; /* Timestamp of root fs */
+ char my_hostnam[MAXHOSTNAMELEN]; /* Client host name */
+};
+
+#endif
diff --git a/cpukit/libnetworking/opt_atalk.h b/cpukit/libnetworking/opt_atalk.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_atalk.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_bdg.h b/cpukit/libnetworking/opt_bdg.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_bdg.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_compat.h b/cpukit/libnetworking/opt_compat.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_compat.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_inet.h b/cpukit/libnetworking/opt_inet.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_inet.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_inet6.h b/cpukit/libnetworking/opt_inet6.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_inet6.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_ipfw.h b/cpukit/libnetworking/opt_ipfw.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_ipfw.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_ipsec.h b/cpukit/libnetworking/opt_ipsec.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_ipsec.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_ipx.h b/cpukit/libnetworking/opt_ipx.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_ipx.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_mac.h b/cpukit/libnetworking/opt_mac.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_mac.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_mrouting.h b/cpukit/libnetworking/opt_mrouting.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_mrouting.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_netgraph.h b/cpukit/libnetworking/opt_netgraph.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/opt_netgraph.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/opt_ppp.h b/cpukit/libnetworking/opt_ppp.h
new file mode 100644
index 0000000000..d318f6a5f9
--- /dev/null
+++ b/cpukit/libnetworking/opt_ppp.h
@@ -0,0 +1,11 @@
+
+#ifndef _PPP_H_
+#define _PPP_H_
+
+#define NPPP 1
+#define NBPFILTER 0
+#undef VJC
+#undef PPP_FILTER
+#undef PPP_COMPRESS
+
+#endif
diff --git a/cpukit/libnetworking/opt_tcpdebug.h b/cpukit/libnetworking/opt_tcpdebug.h
new file mode 100644
index 0000000000..4c10d1bac2
--- /dev/null
+++ b/cpukit/libnetworking/opt_tcpdebug.h
@@ -0,0 +1,16 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
+
+/*
+ * Uncomment the following line to turn on debug code. When you define
+ * this symbol, tcp_trace() is called. If you want tcp_trace() to
+ * print, then you need to edit netinet/tcp_debug to set the variable
+ * "tcpconsdebug" to 1.
+ */
+
+/*
+#define TCPDEBUG
+*/
diff --git a/cpukit/libnetworking/poll.h b/cpukit/libnetworking/poll.h
new file mode 100644
index 0000000000..0287495599
--- /dev/null
+++ b/cpukit/libnetworking/poll.h
@@ -0,0 +1,6 @@
+#ifndef _POLL_H_
+#define _POLL_H_
+
+#include <sys/poll.h>
+
+#endif /* !_POLL_H_ */
diff --git a/cpukit/libnetworking/preinstall.am b/cpukit/libnetworking/preinstall.am
new file mode 100644
index 0000000000..bff90653f3
--- /dev/null
+++ b/cpukit/libnetworking/preinstall.am
@@ -0,0 +1,443 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+if LIBNETWORKING
+$(PROJECT_INCLUDE)/netdb.h: netdb.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netdb.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netdb.h
+
+$(PROJECT_INCLUDE)/resolv.h: resolv.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/resolv.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/resolv.h
+
+$(PROJECT_INCLUDE)/syslog.h: syslog.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/syslog.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/syslog.h
+
+$(PROJECT_INCLUDE)/arpa/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/arpa
+ @: > $(PROJECT_INCLUDE)/arpa/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/arpa/$(dirstamp)
+
+$(PROJECT_INCLUDE)/arpa/ftp.h: arpa/ftp.h $(PROJECT_INCLUDE)/arpa/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/arpa/ftp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/arpa/ftp.h
+
+$(PROJECT_INCLUDE)/arpa/inet.h: arpa/inet.h $(PROJECT_INCLUDE)/arpa/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/arpa/inet.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/arpa/inet.h
+
+$(PROJECT_INCLUDE)/arpa/nameser.h: arpa/nameser.h $(PROJECT_INCLUDE)/arpa/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/arpa/nameser.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/arpa/nameser.h
+
+$(PROJECT_INCLUDE)/arpa/nameser_compat.h: arpa/nameser_compat.h $(PROJECT_INCLUDE)/arpa/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/arpa/nameser_compat.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/arpa/nameser_compat.h
+
+$(PROJECT_INCLUDE)/machine/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/machine
+ @: > $(PROJECT_INCLUDE)/machine/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/machine/$(dirstamp)
+
+$(PROJECT_INCLUDE)/machine/cpu.h: machine/cpu.h $(PROJECT_INCLUDE)/machine/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/machine/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/machine/cpu.h
+
+$(PROJECT_INCLUDE)/machine/cpufunc.h: machine/cpufunc.h $(PROJECT_INCLUDE)/machine/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/machine/cpufunc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/machine/cpufunc.h
+
+$(PROJECT_INCLUDE)/machine/in_cksum.h: machine/in_cksum.h $(PROJECT_INCLUDE)/machine/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/machine/in_cksum.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/machine/in_cksum.h
+
+$(PROJECT_INCLUDE)/machine/vmparam.h: machine/vmparam.h $(PROJECT_INCLUDE)/machine/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/machine/vmparam.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/machine/vmparam.h
+
+$(PROJECT_INCLUDE)/net/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/net
+ @: > $(PROJECT_INCLUDE)/net/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/net/$(dirstamp)
+
+$(PROJECT_INCLUDE)/net/bpf.h: net/bpf.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/bpf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/bpf.h
+
+$(PROJECT_INCLUDE)/net/ethernet.h: net/ethernet.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/ethernet.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/ethernet.h
+
+$(PROJECT_INCLUDE)/net/if.h: net/if.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if.h
+
+$(PROJECT_INCLUDE)/net/if_arp.h: net/if_arp.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_arp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_arp.h
+
+$(PROJECT_INCLUDE)/net/if_dl.h: net/if_dl.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_dl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_dl.h
+
+$(PROJECT_INCLUDE)/net/if_llc.h: net/if_llc.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_llc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_llc.h
+
+$(PROJECT_INCLUDE)/net/if_ppp.h: net/if_ppp.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_ppp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_ppp.h
+
+$(PROJECT_INCLUDE)/net/if_types.h: net/if_types.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_types.h
+
+$(PROJECT_INCLUDE)/net/if_var.h: net/if_var.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_var.h
+
+$(PROJECT_INCLUDE)/net/netisr.h: net/netisr.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/netisr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/netisr.h
+
+$(PROJECT_INCLUDE)/net/ppp_defs.h: net/ppp_defs.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/ppp_defs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/ppp_defs.h
+
+$(PROJECT_INCLUDE)/net/radix.h: net/radix.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/radix.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/radix.h
+
+$(PROJECT_INCLUDE)/net/raw_cb.h: net/raw_cb.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/raw_cb.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/raw_cb.h
+
+$(PROJECT_INCLUDE)/net/route.h: net/route.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/route.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/route.h
+
+$(PROJECT_INCLUDE)/net/if_pppvar.h: net/if_pppvar.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_pppvar.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_pppvar.h
+
+$(PROJECT_INCLUDE)/net/slcompress.h: net/slcompress.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/slcompress.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/slcompress.h
+
+$(PROJECT_INCLUDE)/net/if_media.h: net/if_media.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/if_media.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/if_media.h
+
+$(PROJECT_INCLUDE)/net/ppp_comp.h: net/ppp_comp.h $(PROJECT_INCLUDE)/net/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/net/ppp_comp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/net/ppp_comp.h
+
+$(PROJECT_INCLUDE)/netinet/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/netinet
+ @: > $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+
+$(PROJECT_INCLUDE)/netinet/icmp_var.h: netinet/icmp_var.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/icmp_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/icmp_var.h
+
+$(PROJECT_INCLUDE)/netinet/if_ether.h: netinet/if_ether.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/if_ether.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/if_ether.h
+
+$(PROJECT_INCLUDE)/netinet/igmp.h: netinet/igmp.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/igmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/igmp.h
+
+$(PROJECT_INCLUDE)/netinet/igmp_var.h: netinet/igmp_var.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/igmp_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/igmp_var.h
+
+$(PROJECT_INCLUDE)/netinet/in.h: netinet/in.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/in.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/in.h
+
+$(PROJECT_INCLUDE)/netinet/in_pcb.h: netinet/in_pcb.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/in_pcb.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/in_pcb.h
+
+$(PROJECT_INCLUDE)/netinet/in_systm.h: netinet/in_systm.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/in_systm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/in_systm.h
+
+$(PROJECT_INCLUDE)/netinet/in_var.h: netinet/in_var.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/in_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/in_var.h
+
+$(PROJECT_INCLUDE)/netinet/ip.h: netinet/ip.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/ip.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/ip.h
+
+$(PROJECT_INCLUDE)/netinet/ip_fw.h: netinet/ip_fw.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/ip_fw.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/ip_fw.h
+
+$(PROJECT_INCLUDE)/netinet/ip_icmp.h: netinet/ip_icmp.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/ip_icmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/ip_icmp.h
+
+$(PROJECT_INCLUDE)/netinet/ip_mroute.h: netinet/ip_mroute.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/ip_mroute.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/ip_mroute.h
+
+$(PROJECT_INCLUDE)/netinet/ip_var.h: netinet/ip_var.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/ip_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/ip_var.h
+
+$(PROJECT_INCLUDE)/netinet/tcp.h: netinet/tcp.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcp.h
+
+$(PROJECT_INCLUDE)/netinet/tcp_debug.h: netinet/tcp_debug.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcp_debug.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcp_debug.h
+
+$(PROJECT_INCLUDE)/netinet/tcp_fsm.h: netinet/tcp_fsm.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcp_fsm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcp_fsm.h
+
+$(PROJECT_INCLUDE)/netinet/tcp_seq.h: netinet/tcp_seq.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcp_seq.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcp_seq.h
+
+$(PROJECT_INCLUDE)/netinet/tcp_timer.h: netinet/tcp_timer.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcp_timer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcp_timer.h
+
+$(PROJECT_INCLUDE)/netinet/tcp_var.h: netinet/tcp_var.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcp_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcp_var.h
+
+$(PROJECT_INCLUDE)/netinet/tcpip.h: netinet/tcpip.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/tcpip.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/tcpip.h
+
+$(PROJECT_INCLUDE)/netinet/udp.h: netinet/udp.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/udp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/udp.h
+
+$(PROJECT_INCLUDE)/netinet/udp_var.h: netinet/udp_var.h $(PROJECT_INCLUDE)/netinet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/netinet/udp_var.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/netinet/udp_var.h
+
+$(PROJECT_INCLUDE)/nfs/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/nfs
+ @: > $(PROJECT_INCLUDE)/nfs/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/nfs/$(dirstamp)
+
+$(PROJECT_INCLUDE)/nfs/nfsproto.h: nfs/nfsproto.h $(PROJECT_INCLUDE)/nfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/nfs/nfsproto.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/nfs/nfsproto.h
+
+$(PROJECT_INCLUDE)/nfs/rpcv2.h: nfs/rpcv2.h $(PROJECT_INCLUDE)/nfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/nfs/rpcv2.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/nfs/rpcv2.h
+
+$(PROJECT_INCLUDE)/nfs/xdr_subs.h: nfs/xdr_subs.h $(PROJECT_INCLUDE)/nfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/nfs/xdr_subs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/nfs/xdr_subs.h
+
+$(PROJECT_INCLUDE)/nfsclient/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/nfsclient
+ @: > $(PROJECT_INCLUDE)/nfsclient/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/nfsclient/$(dirstamp)
+
+$(PROJECT_INCLUDE)/nfsclient/nfsargs.h: nfsclient/nfsargs.h $(PROJECT_INCLUDE)/nfsclient/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/nfsclient/nfsargs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/nfsclient/nfsargs.h
+
+$(PROJECT_INCLUDE)/nfsclient/nfsdiskless.h: nfsclient/nfsdiskless.h $(PROJECT_INCLUDE)/nfsclient/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/nfsclient/nfsdiskless.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/nfsclient/nfsdiskless.h
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/rtems_bsdnet.h: rtems/rtems_bsdnet.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems_bsdnet.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems_bsdnet.h
+
+$(PROJECT_INCLUDE)/rtems/rtems_bsdnet_internal.h: rtems/rtems_bsdnet_internal.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems_bsdnet_internal.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems_bsdnet_internal.h
+
+$(PROJECT_INCLUDE)/rtems/dhcp.h: rtems/dhcp.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/dhcp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/dhcp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems_dhcp_failsafe.h: rtems/rtems_dhcp_failsafe.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems_dhcp_failsafe.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems_dhcp_failsafe.h
+
+$(PROJECT_INCLUDE)/rtems/tftp.h: rtems/tftp.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/tftp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/tftp.h
+
+$(PROJECT_INCLUDE)/rtems/ftpfs.h: rtems/ftpfs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ftpfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ftpfs.h
+
+$(PROJECT_INCLUDE)/rtems/mkrootfs.h: rtems/mkrootfs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mkrootfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mkrootfs.h
+
+$(PROJECT_INCLUDE)/rtems/rtems_mii_ioctl.h: rtems/rtems_mii_ioctl.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems_mii_ioctl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems_mii_ioctl.h
+
+$(PROJECT_INCLUDE)/sys/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/sys
+ @: > $(PROJECT_INCLUDE)/sys/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/sys/$(dirstamp)
+
+$(PROJECT_INCLUDE)/sys/callout.h: sys/callout.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/callout.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/callout.h
+
+$(PROJECT_INCLUDE)/sys/conf.h: sys/conf.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/conf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/conf.h
+
+$(PROJECT_INCLUDE)/sys/domain.h: sys/domain.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/domain.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/domain.h
+
+$(PROJECT_INCLUDE)/sys/kernel.h: sys/kernel.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/kernel.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/kernel.h
+
+$(PROJECT_INCLUDE)/sys/libkern.h: sys/libkern.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/libkern.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/libkern.h
+
+$(PROJECT_INCLUDE)/sys/linker_set.h: sys/linker_set.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/linker_set.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/linker_set.h
+
+$(PROJECT_INCLUDE)/sys/malloc.h: sys/malloc.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/malloc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/malloc.h
+
+$(PROJECT_INCLUDE)/sys/mbuf.h: sys/mbuf.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/mbuf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/mbuf.h
+
+$(PROJECT_INCLUDE)/sys/mount.h: sys/mount.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/mount.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/mount.h
+
+$(PROJECT_INCLUDE)/sys/proc.h: sys/proc.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/proc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/proc.h
+
+$(PROJECT_INCLUDE)/sys/protosw.h: sys/protosw.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/protosw.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/protosw.h
+
+$(PROJECT_INCLUDE)/sys/reboot.h: sys/reboot.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/reboot.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/reboot.h
+
+$(PROJECT_INCLUDE)/sys/resourcevar.h: sys/resourcevar.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/resourcevar.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/resourcevar.h
+
+$(PROJECT_INCLUDE)/sys/select.h: sys/select.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/select.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/select.h
+
+$(PROJECT_INCLUDE)/sys/signalvar.h: sys/signalvar.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/signalvar.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/signalvar.h
+
+$(PROJECT_INCLUDE)/sys/socket.h: sys/socket.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/socket.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/socket.h
+
+$(PROJECT_INCLUDE)/sys/socketvar.h: sys/socketvar.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/socketvar.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/socketvar.h
+
+$(PROJECT_INCLUDE)/sys/sysctl.h: sys/sysctl.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/sysctl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/sysctl.h
+
+$(PROJECT_INCLUDE)/sys/syslog.h: sys/syslog.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/syslog.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/syslog.h
+
+$(PROJECT_INCLUDE)/sys/systm.h: sys/systm.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/systm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/systm.h
+
+$(PROJECT_INCLUDE)/sys/ttydefaults.h: sys/ttydefaults.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/ttydefaults.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/ttydefaults.h
+
+$(PROJECT_INCLUDE)/sys/ucred.h: sys/ucred.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/ucred.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/ucred.h
+
+$(PROJECT_INCLUDE)/sys/un.h: sys/un.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/un.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/un.h
+
+$(PROJECT_INCLUDE)/vm/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/vm
+ @: > $(PROJECT_INCLUDE)/vm/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/vm/$(dirstamp)
+
+$(PROJECT_INCLUDE)/vm/vm.h: vm/vm.h $(PROJECT_INCLUDE)/vm/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/vm/vm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/vm/vm.h
+
+$(PROJECT_INCLUDE)/vm/vm_extern.h: vm/vm_extern.h $(PROJECT_INCLUDE)/vm/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/vm/vm_extern.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/vm/vm_extern.h
+
+$(PROJECT_INCLUDE)/vm/vm_kern.h: vm/vm_kern.h $(PROJECT_INCLUDE)/vm/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/vm/vm_kern.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/vm/vm_kern.h
+
+$(PROJECT_INCLUDE)/vm/vm_param.h: vm/vm_param.h $(PROJECT_INCLUDE)/vm/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/vm/vm_param.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/vm/vm_param.h
+
+$(PROJECT_INCLUDE)/dev/mii/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/dev/mii
+ @: > $(PROJECT_INCLUDE)/dev/mii/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/dev/mii/$(dirstamp)
+
+$(PROJECT_INCLUDE)/dev/mii/mii.h: dev/mii/mii.h $(PROJECT_INCLUDE)/dev/mii/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/dev/mii/mii.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/dev/mii/mii.h
+
+$(PROJECT_INCLUDE)/ifaddrs.h: ifaddrs.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/ifaddrs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/ifaddrs.h
+endif
diff --git a/cpukit/libnetworking/resolv.h b/cpukit/libnetworking/resolv.h
new file mode 100644
index 0000000000..9e45285a6e
--- /dev/null
+++ b/cpukit/libnetworking/resolv.h
@@ -0,0 +1,306 @@
+/*-
+ * Copyright (c) 1983, 1987, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * @(#)resolv.h 8.1 (Berkeley) 6/2/93
+ * From Id: resolv.h,v 8.12 1998/04/28 19:36:46 halley Exp $
+ * $Id$
+ */
+
+#ifndef _RESOLV_H_
+#define _RESOLV_H_
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <rtems/bsd/sys/cdefs.h>
+#include <stdio.h>
+
+/*
+ * Revision information. This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__RES > 19931104)". Do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define __RES 19960801
+
+/*
+ * This used to be defined in res_query.c, now it's in herror.c. It was
+ * never extern'd by any *.h file before it was placed here. herror.c is
+ * part of libresolv.a even though it might make more sense in libnetdb.a
+ * or even libnet.a.
+ */
+
+extern int h_errno;
+
+/*
+ * Resolver configuration file.
+ * Normally not present, but may contain the address of the
+ * initial name server(s) to query and the domain search list.
+ */
+
+#ifndef _PATH_RESCONF
+#define _PATH_RESCONF "/etc/resolv.conf"
+#endif
+
+/*
+ * Global defines and variables for resolver stub.
+ */
+#define MAXNS 3 /* max # name servers we'll track */
+#define MAXDFLSRCH 3 /* # default domain levels to try */
+#define MAXDNSRCH 6 /* max # domains in search path */
+#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */
+
+#define RES_TIMEOUT 5 /* min. seconds between retries */
+#define MAXRESOLVSORT 10 /* number of net to sort on */
+#define RES_MAXNDOTS 15 /* should reflect bit field size */
+
+struct __res_state {
+ int retrans; /* retransmission time interval */
+ int retry; /* number of times to retransmit */
+ u_long options; /* option flags - see below. */
+ int nscount; /* number of name servers */
+ struct sockaddr_in
+ nsaddr_list[MAXNS]; /* address of name server */
+#define nsaddr nsaddr_list[0] /* for backward compatibility */
+ u_short id; /* current message id */
+ char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
+ char defdname[256]; /* default domain (deprecated) */
+ u_long pfcode; /* RES_PRF_ flags - see below. */
+ unsigned ndots:4; /* threshold for initial abs. query */
+ unsigned nsort:4; /* number of elements in sort_list[] */
+ char unused[3];
+ struct {
+ struct in_addr addr;
+ u_int32_t mask;
+ } sort_list[MAXRESOLVSORT];
+ char pad[72]; /* on an i386 this means 512b total */
+};
+
+/*
+ * Resolver options (keep these in synch with res_debug.c, please)
+ */
+#define RES_INIT 0x00000001 /* address initialized */
+#define RES_DEBUG 0x00000002 /* print debug messages */
+#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
+#define RES_USEVC 0x00000008 /* use virtual circuit */
+#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
+#define RES_IGNTC 0x00000020 /* ignore truncation errors */
+#define RES_RECURSE 0x00000040 /* recursion desired */
+#define RES_DEFNAMES 0x00000080 /* use default domain name */
+#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
+#define RES_DNSRCH 0x00000200 /* search up local domain tree */
+#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
+#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
+#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
+#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
+#define RES_NOTLDQUERY 0x00004000 /* Don't query TLD names */
+
+#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
+
+/*
+ * Resolver "pfcode" values. Used by dig.
+ */
+#define RES_PRF_STATS 0x00000001
+#define RES_PRF_UPDATE 0x00000002
+#define RES_PRF_CLASS 0x00000004
+#define RES_PRF_CMD 0x00000008
+#define RES_PRF_QUES 0x00000010
+#define RES_PRF_ANS 0x00000020
+#define RES_PRF_AUTH 0x00000040
+#define RES_PRF_ADD 0x00000080
+#define RES_PRF_HEAD1 0x00000100
+#define RES_PRF_HEAD2 0x00000200
+#define RES_PRF_TTLID 0x00000400
+#define RES_PRF_HEADX 0x00000800
+#define RES_PRF_QUERY 0x00001000
+#define RES_PRF_REPLY 0x00002000
+#define RES_PRF_INIT 0x00004000
+/* 0x00008000 */
+
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+ res_sendhookact;
+
+typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
+ const u_char **query,
+ int *querylen,
+ u_char *ans,
+ int anssiz,
+ int *resplen);
+
+typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
+ const u_char *query,
+ int querylen,
+ u_char *ans,
+ int anssiz,
+ int *resplen);
+
+struct res_sym {
+ int number; /* Identifying number, like T_MX */
+ char * name; /* Its symbolic name, like "MX" */
+ char * humanname; /* Its fun name, like "mail exchanger" */
+};
+
+extern struct __res_state _res;
+extern const struct res_sym __p_class_syms[];
+extern const struct res_sym __p_type_syms[];
+
+/* Private routines shared between libc/net, named, nslookup and others. */
+#define res_hnok __res_hnok
+#define res_ownok __res_ownok
+#define res_mailok __res_mailok
+#define res_dnok __res_dnok
+#define sym_ston __sym_ston
+#define sym_ntos __sym_ntos
+#define sym_ntop __sym_ntop
+#define b64_ntop __b64_ntop
+#define b64_pton __b64_pton
+#define loc_ntoa __loc_ntoa
+#define loc_aton __loc_aton
+#define fp_resstat __fp_resstat
+#define p_query __p_query
+#define dn_skipname __dn_skipname
+#define fp_resstat __fp_resstat
+#define fp_query __fp_query
+#define fp_nquery __fp_nquery
+#define hostalias __hostalias
+#define putlong __putlong
+#define putshort __putshort
+#define p_class __p_class
+#define p_time __p_time
+#define p_type __p_type
+#define p_query __p_query
+#define p_cdnname __p_cdnname
+#define p_section __p_section
+#define p_cdname __p_cdname
+#define p_fqnname __p_fqnname
+#define p_fqname __p_fqname
+#define p_option __p_option
+#define p_secstodate __p_secstodate
+#define dn_count_labels __dn_count_labels
+#define dn_comp __dn_comp
+#define dn_expand __dn_expand
+#define res_init __res_init
+#define res_randomid __res_randomid
+#define res_query __res_query
+#define res_search __res_search
+#define res_querydomain __res_querydomain
+#define res_mkquery __res_mkquery
+#define res_send __res_send
+#define res_isourserver __res_isourserver
+#define res_nameinquery __res_nameinquery
+#define res_queriesmatch __res_queriesmatch
+#define res_close __res_close
+#define res_mkupdate __res_mkupdate
+#define res_mkupdrec __res_mkupdrec
+#define res_freeupdrec __res_freeupdrec
+
+__BEGIN_DECLS
+int res_hnok (const char *);
+int res_ownok (const char *);
+int res_mailok (const char *);
+int res_dnok (const char *);
+int sym_ston (const struct res_sym *, const char *, int *);
+const char * sym_ntos (const struct res_sym *, int, int *);
+const char * sym_ntop (const struct res_sym *, int, int *);
+int b64_ntop (u_char const *, size_t, char *, size_t);
+int b64_pton (char const *, u_char *, size_t);
+int loc_aton (const char *, u_char *);
+const char * loc_ntoa (const u_char *, char *);
+int dn_skipname (const u_char *, const u_char *);
+void fp_resstat (struct __res_state *, FILE *);
+void fp_query (const u_char *, FILE *);
+void fp_nquery (const u_char *, int, FILE *);
+const char * hostalias (const char *);
+void putlong (u_int32_t, u_char *);
+void putshort (u_int16_t, u_char *);
+const char * p_class (int);
+const char * p_time (u_int32_t);
+const char * p_type (int);
+void p_query (const u_char *);
+const u_char * p_cdnname (const u_char *, const u_char *, int, FILE *);
+const u_char * p_cdname (const u_char *, const u_char *, FILE *);
+const u_char * p_fqnname (const u_char *, const u_char *,
+ int, char *, int);
+const u_char * p_fqname (const u_char *, const u_char *, FILE *);
+const char * p_option (u_long);
+char * p_secstodate (u_long);
+int dn_count_labels (const char *);
+int dn_comp (const char *, u_char *, int,
+ u_char **, u_char **);
+int dn_expand (const u_char *, const u_char *, const u_char *,
+ char *, int);
+int res_init (void);
+u_int res_randomid (void);
+int res_query (const char *, int, int, u_char *, int);
+int res_search (const char *, int, int, u_char *, int);
+int res_querydomain (const char *, const char *, int, int,
+ u_char *, int);
+int res_mkquery (int, const char *, int, int, const u_char *,
+ int, const u_char *, u_char *, int);
+int res_send (const u_char *, int, u_char *, int);
+int res_isourserver (const struct sockaddr_in *);
+int res_nameinquery (const char *, int, int,
+ const u_char *, const u_char *);
+int res_queriesmatch (const u_char *, const u_char *,
+ const u_char *, const u_char *);
+void res_close (void);
+const char * p_section (int, int);
+/* XXX The following depend on the ns_updrec typedef in arpa/nameser.h */
+#ifdef _ARPA_NAMESER_H_
+int res_update (ns_updrec *);
+int res_mkupdate (ns_updrec *, u_char *, int);
+ns_updrec * res_mkupdrec (int, const char *, u_int, u_int, u_long);
+void res_freeupdrec (ns_updrec *);
+#endif
+__END_DECLS
+
+#endif /* !_RESOLV_H_ */
diff --git a/cpukit/libnetworking/rtems/bsdnet/_types.h b/cpukit/libnetworking/rtems/bsdnet/_types.h
new file mode 100644
index 0000000000..3f600ff670
--- /dev/null
+++ b/cpukit/libnetworking/rtems/bsdnet/_types.h
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/_types.h,v 1.21 2005/03/22 01:19:17 das Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _RTEMS_BSDNET__TYPES_H_
+#define _RTEMS_BSDNET__TYPES_H_
+
+#include <stdint.h>
+
+/*
+ * Standard type definitions.
+ */
+typedef uint8_t __sa_family_t;
+typedef uint32_t __socklen_t;
+
+#endif /* !_RTEMS_BSDNET_TYPES_H_ */
diff --git a/cpukit/libnetworking/rtems/bsdnet/servers.h b/cpukit/libnetworking/rtems/bsdnet/servers.h
new file mode 100644
index 0000000000..ca6c702cea
--- /dev/null
+++ b/cpukit/libnetworking/rtems/bsdnet/servers.h
@@ -0,0 +1,21 @@
+/**
+ * @file rtems/rtems_bsdnet.h
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _RTEMS_BSDNET_SERVERS_H
+#define _RTEMS_BSDNET_SERVERS_H
+
+extern struct in_addr *rtems_bsdnet_ntpserver;
+extern int rtems_bsdnet_ntpserver_count;
+
+/*
+ * Network configuration
+ */
+extern struct in_addr *rtems_bsdnet_nameserver;
+extern int rtems_bsdnet_nameserver_count;
+
+#endif /* _RTEMS_BSDNET_SERVERS_H */
diff --git a/cpukit/libnetworking/rtems/dhcp.h b/cpukit/libnetworking/rtems/dhcp.h
new file mode 100644
index 0000000000..b29fc66c65
--- /dev/null
+++ b/cpukit/libnetworking/rtems/dhcp.h
@@ -0,0 +1,49 @@
+/*
+ ------------------------------------------------------------------------
+ $Id$
+ ------------------------------------------------------------------------
+
+ Copyright Cybertec Pty Ltd, 2005
+ All rights reserved Cybertec Pty Ltd, 2005
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ ------------------------------------------------------------------------
+ */
+
+/**
+ @file
+
+ DHCP Server interface.
+*/
+
+#if !defined (__RTEMS_DHCP_H__)
+#define __RTEMS_DHCP_H__
+
+#if __cplusplus
+extern "C"
+{
+#endif
+
+/*
+ * Perform DHCP.
+ */
+void rtems_bsdnet_do_dhcp (void);
+int rtems_bsdnet_do_dhcp_timeout (void);
+void rtems_bsdnet_dhcp_down (void);
+
+/*
+ * Maintain a DHCP offer that has already been accepted.
+ */
+void rtems_bsdnet_do_dhcp_refresh_only (unsigned long xid,
+ unsigned long lease_time,
+ unsigned long elapsed_time,
+ unsigned long ip_address,
+ unsigned long srv_address,
+ const char *hostname);
+
+#if __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/rtems/ftpfs.h b/cpukit/libnetworking/rtems/ftpfs.h
new file mode 100644
index 0000000000..0bb500229d
--- /dev/null
+++ b/cpukit/libnetworking/rtems/ftpfs.h
@@ -0,0 +1,162 @@
+/**
+ * @file
+ *
+ * @brief File Transfer Protocol file system (FTP client).
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * (c) Copyright 2002
+ * Thomas Doerfler
+ * IMD Ingenieurbuero fuer Microcomputertechnik
+ * Herbststr. 8
+ * 82178 Puchheim, Germany
+ * <Thomas.Doerfler@imd-systems.de>
+ *
+ * Modified by Sebastian Huber <sebastian.huber@embedded-brains.de>.
+ *
+ * This code has been created after closly inspecting "tftpdriver.c" from Eric
+ * Norum.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_FTPFS_H
+#define _RTEMS_FTPFS_H
+
+#include <sys/time.h>
+#include <sys/ioctl.h>
+
+#include <rtems/libio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup rtems_ftpfs File Transfer Protocol File System
+ *
+ * @brief The FTP file system (FTP client) can be used to transfer files from
+ * or to remote hosts.
+ *
+ * You can mount the FTP file system with a call to mount() or
+ * mount_and_make_target_path() with the @ref RTEMS_FILESYSTEM_TYPE_FTPFS file
+ * system type.
+ *
+ * You have to add @ref CONFIGURE_FILESYSTEM_FTPFS to your application
+ * configuration.
+ *
+ * You can open files either read-only or write-only. A seek is not allowed.
+ * A close terminates the control and data connections.
+ *
+ * To open a file @c file.txt in the directory @c dir (relative to home
+ * directory of the server) on a server named @c host using the user name
+ * @c user and the password @c pw you must specify the following path:
+ * <tt>/FTP/user:pw@@host/dir/file.txt</tt>.
+ *
+ * If the server is the default server specified in BOOTP, it can be ommitted:
+ * <tt>/FTP/user:pw/dir/file.txt</tt>.
+ *
+ * The user name will be used for the password if it is ommitted:
+ * <tt>/FTP/user@@host/dir/file.txt</tt>.
+ *
+ * For the data transfer passive (= default) and active (= fallback) mode are
+ * supported.
+ *
+ * @{
+ */
+
+/**
+ * @brief Well-known port number for FTP control connection.
+ */
+#define RTEMS_FTPFS_CTRL_PORT 21
+
+/**
+ * @brief Default mount point for FTP file system.
+ */
+#define RTEMS_FTPFS_MOUNT_POINT_DEFAULT "/FTP"
+
+/**
+ * @brief FTP file system IO control requests.
+ */
+typedef enum {
+ RTEMS_FTPFS_IOCTL_GET_VERBOSE = _IOR( 'd', 1, bool *),
+ RTEMS_FTPFS_IOCTL_SET_VERBOSE = _IOW( 'd', 1, bool *),
+ RTEMS_FTPFS_IOCTL_GET_TIMEOUT = _IOR( 'd', 2, struct timeval *),
+ RTEMS_FTPFS_IOCTL_SET_TIMEOUT = _IOW( 'd', 2, struct timeval *)
+} rtems_ftpfs_ioctl_numbers;
+
+/**
+ * @brief Returns in @a verbose if the verbose mode is enabled or disabled for
+ * the file system at @a mount_point.
+ *
+ * If @a mount_point is @c NULL the default mount point
+ * @ref RTEMS_FTPFS_MOUNT_POINT_DEFAULT will be used.
+ */
+rtems_status_code rtems_ftpfs_get_verbose( const char *mount_point, bool *verbose);
+
+/**
+ * @brief Enables or disables the verbose mode if @a verbose is @c true or
+ * @c false respectively for the file system at @a mount_point.
+ *
+ * In the enabled verbose mode the commands and replies of the FTP control
+ * connections will be printed to standard error.
+ *
+ * If @a mount_point is @c NULL the default mount point
+ * @ref RTEMS_FTPFS_MOUNT_POINT_DEFAULT will be used.
+ */
+rtems_status_code rtems_ftpfs_set_verbose( const char *mount_point, bool verbose);
+
+/**
+ * @brief Returns the current timeout value in @a timeout for the file system
+ * at @a mount_point.
+ *
+ * If @a mount_point is @c NULL the default mount point
+ * @ref RTEMS_FTPFS_MOUNT_POINT_DEFAULT will be used.
+ */
+rtems_status_code rtems_ftpfs_get_timeout(
+ const char *mount_point,
+ struct timeval *timeout
+);
+
+/**
+ * @brief Sets the timeout value to @a timeout for the file system at
+ * @a mount_point.
+ *
+ * The timeout value will be used during connection establishment of active
+ * data connections. It will be also used for send and receive operations on
+ * data and control connections.
+ *
+ * If @a mount_point is @c NULL the default mount point
+ * @ref RTEMS_FTPFS_MOUNT_POINT_DEFAULT will be used.
+ */
+rtems_status_code rtems_ftpfs_set_timeout(
+ const char *mount_point,
+ const struct timeval *timeout
+);
+
+/** @} */
+
+/**
+ * @brief Do not call directly, use mount().
+ */
+int rtems_ftpfs_initialize(
+ rtems_filesystem_mount_table_entry_t *mt_entry,
+ const void *data
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/rtems/mkrootfs.c b/cpukit/libnetworking/rtems/mkrootfs.c
new file mode 100644
index 0000000000..63d67e26b3
--- /dev/null
+++ b/cpukit/libnetworking/rtems/mkrootfs.c
@@ -0,0 +1,246 @@
+/*
+ ------------------------------------------------------------------------
+ $Id$
+ ------------------------------------------------------------------------
+
+ Copyright Cybertec Pty Ltd, 2000
+ All rights reserved Cybertec Pty Ltd, 2000
+
+ COPYRIGHT (c) 1989-1998.
+ On-Line Applications Research Corporation (OAR).
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution or at
+
+ http://www.rtems.com/license/LICENSE.
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ ------------------------------------------------------------------------
+
+ Set of helpers when creating a root file system. The root filesystem
+ in RTEMS is the In Memory Filesystem (IMFS). We could copy an exiting
+ filesystem to here, how-ever a number of files can have target
+ specific initialisation info which we need to write.
+
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <rtems/mkrootfs.h>
+#include <rtems/libio.h>
+
+/*
+ * A table a list of names and their modes.
+ */
+
+typedef struct rtems_rootfs_dir_table
+{
+ const char *name;
+ int mode;
+} rtems_rootfs_dir_table;
+
+/*
+ * Table of directorys to make.
+ */
+
+static const rtems_rootfs_dir_table default_directories[] =
+{
+ { "/bin", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH },
+ { "/etc", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH },
+ { "/dev", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH },
+ { "/usr/bin", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH }
+};
+
+#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH)
+#define MKDIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
+
+/*
+ * Create enough files to support the networking stack.
+ * Points to a table of strings.
+ */
+
+int
+rtems_rootfs_file_append (const char *file,
+ mode_t omode,
+ const int line_cnt,
+ const char **lines)
+{
+ struct stat sb;
+ int fd;
+ int i;
+
+ /*
+ * See is a file exists. If it does not, create the
+ * file and the path to the file.
+ */
+
+ fd = -1;
+
+ if (stat(file, &sb))
+ {
+ if (errno == ENOENT)
+ {
+ /*
+ * Get the path to the file if one exists and create the
+ * path. If it exists nothing happens.
+ */
+
+ int i = strlen (file);
+
+ while (i)
+ {
+ if (file[i] == '/')
+ {
+ char path[128];
+
+ if (i >= sizeof path)
+ {
+ printf ("root fs, path too long `%s'\n", file);
+ return -1;
+ }
+
+ strncpy (path, file, i);
+ path[i] = '\0';
+
+ if (rtems_mkdir (path, MKDIR_MODE))
+ return -1;
+ break;
+ }
+ i--;
+ }
+
+ if ((fd = open (file, O_CREAT | O_APPEND | O_WRONLY, omode)) < 0)
+ {
+ printf ("root fs, cannot create file `%s' : %s\n",
+ file, strerror (errno));
+ return -1;
+ }
+ }
+ }
+
+ if (fd < 0)
+ {
+ if ((fd = open (file, O_APPEND | O_WRONLY)) < 0)
+ {
+ printf ("root fs, cannot open file `%s' : %s\n",
+ file, strerror (errno));
+ return -1;
+ }
+ }
+
+ for (i = 0; i < line_cnt; i++)
+ {
+ int len = strlen (lines[i]);
+
+ if (len)
+ {
+ if (write (fd, lines[i], strlen (lines[i])) < 0)
+ {
+ close (fd);
+ printf ("root fs, cannot write to `%s' : %s\n",
+ file, strerror (errno));
+ return -1;
+ }
+ }
+ }
+
+ return close (fd);
+}
+
+/*
+ * Write hosts record.
+ */
+
+int
+rtems_rootfs_append_host_rec (in_addr_t cip,
+ const char *cname,
+ const char *dname)
+{
+ char buf[128];
+ char *bufp = buf;
+ const char *bufl[1];
+ struct in_addr ip;
+
+ ip.s_addr = cip;
+
+ if (cname && strlen (cname))
+ {
+ snprintf (bufp, sizeof (buf), "%s\t\t%s", inet_ntoa (ip), cname);
+ bufp += strlen (buf);
+
+ if (dname && strlen (dname))
+ {
+ snprintf (bufp, sizeof (buf), "\t\t%s.%s", cname, dname);
+ bufp += strlen (buf);
+ }
+
+ strcat (buf, "\n");
+
+ bufl[0] = buf;
+
+ if (rtems_rootfs_file_append ("/etc/hosts", MKFILE_MODE, 1, bufl) < 0)
+ return -1;
+ }
+ else
+ {
+ printf ("rootfs hosts rec append, no cname supplied\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Create a root file system.
+ */
+
+int
+rtems_create_root_fs (void)
+{
+ const char *lines[1];
+ int i;
+
+ /*
+ * Create the directories.
+ */
+
+ for (i = 0;
+ i < (sizeof (default_directories) / sizeof (rtems_rootfs_dir_table));
+ i++)
+ if (rtems_mkdir (default_directories[i].name,
+ default_directories[i].mode))
+ return -1;
+
+ /*
+ * The TCP/IP stack likes this one. If DNS does not work
+ * use the host file.
+ */
+
+ lines[0] = "hosts,bind\n";
+
+ if (rtems_rootfs_file_append ("/etc/host.conf", MKFILE_MODE, 1, lines))
+ return -1;
+
+ /*
+ * Create a `/etc/hosts' file.
+ */
+
+ if (rtems_rootfs_append_host_rec (htonl (0x7f000001), "localhost", "localdomain"))
+ return -1;
+
+ return 0;
+}
diff --git a/cpukit/libnetworking/rtems/mkrootfs.h b/cpukit/libnetworking/rtems/mkrootfs.h
new file mode 100644
index 0000000000..8bf053bc52
--- /dev/null
+++ b/cpukit/libnetworking/rtems/mkrootfs.h
@@ -0,0 +1,81 @@
+/**
+ * @file rtems/mkrootfs.h
+ *
+ * RTEMS Root FS creation support.
+ */
+
+/*
+ Copyright Cybertec Pty Ltd, 2000
+ All rights reserved Cybertec Pty Ltd, 2000
+
+ COPYRIGHT (c) 1989-1998.
+ On-Line Applications Research Corporation (OAR).
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution or at
+
+ http://www.rtems.com/license/LICENSE.
+
+ This software with is provided ``as is'' and with NO WARRANTY.
+
+ $Id$
+*/
+
+#ifndef _RTEMS_MKROOTFS_H
+#define _RTEMS_MKROOTFS_H
+
+#include <rtems.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Appends the lines to the a file. Create the file
+ * and builds the path if it does not exist.
+ *
+ * @param file
+ * @param omode
+ * @param line_cnt
+ * @param lines
+ *
+ * @return 0 on success, -1 on error
+ */
+
+int
+rtems_rootfs_file_append (const char *file,
+ mode_t omode,
+ const int line_cnt,
+ const char **lines);
+
+/**
+ * @brief Helper for bulding an /etc/hosts file.
+ *
+ * @param cip
+ * @param cname
+ * @param dname
+ *
+ * @return 0 on success, -1 on error
+ */
+
+int
+rtems_rootfs_append_host_rec (in_addr_t cip,
+ const char *cname,
+ const char *dname);
+
+/**
+ * Create a few common directories, plus a:
+ * /etc/passwd, /etc/group, /etc/host.conf, and
+ * /etc/hosts file.
+ *
+ * @return 0 on success, -1 on error
+ */
+
+int
+rtems_create_root_fs ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/rtems/rtems_bootp.c b/cpukit/libnetworking/rtems/rtems_bootp.c
new file mode 100644
index 0000000000..caf2faa6e2
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_bootp.c
@@ -0,0 +1,42 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <sys/types.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/rtems_bsdnet_internal.h>
+
+/*
+ * Perform a BOOTP request
+ */
+void
+rtems_bsdnet_do_bootp (void)
+{
+ bool ok;
+ rtems_bsdnet_semaphore_obtain ();
+ ok = bootpc_init (false, true);
+ rtems_bsdnet_semaphore_release ();
+ if (!ok)
+ panic ("rtems_bsdnet_do_bootp: bootp failed");
+}
+
+/*
+ * Perform a BOOTP request and update "standard" files in /etc
+ * with the results.
+ */
+void
+rtems_bsdnet_do_bootp_and_rootfs (void)
+{
+ bool ok;
+ rtems_bsdnet_semaphore_obtain ();
+ ok = bootpc_init (true, true);
+ rtems_bsdnet_semaphore_release ();
+ if (!ok)
+ panic ("rtems_bsdnet_do_bootp_and_rootfs: bootp failed");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet.h b/cpukit/libnetworking/rtems/rtems_bsdnet.h
new file mode 100644
index 0000000000..6c40e73f10
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet.h
@@ -0,0 +1,317 @@
+/**
+ * @file rtems/rtems_bsdnet.h
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _RTEMS_BSDNET_H
+#define _RTEMS_BSDNET_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems.h>
+
+/*
+ * If this file is included from inside the Network Stack proper or
+ * a device driver, then __INSIDE_RTEMS_BSD_TCPIP_STACK__ should be
+ * defined. This triggers a number of internally used definitions.
+ */
+
+#if defined(__INSIDE_RTEMS_BSD_TCPIP_STACK__)
+#undef _KERNEL
+#undef INET
+#undef NFS
+#undef DIAGNOSTIC
+#undef BOOTP_COMPAT
+#undef __BSD_VISIBLE
+
+#define _KERNEL
+#define INET
+#define NFS
+#define DIAGNOSTIC
+#define BOOTP_COMPAT
+#define __BSD_VISIBLE 1
+#endif
+
+/*
+ * Values that may be obtained by BOOTP
+ */
+extern struct in_addr rtems_bsdnet_bootp_server_address;
+extern char *rtems_bsdnet_bootp_server_name;
+extern char *rtems_bsdnet_bootp_boot_file_name;
+extern char *rtems_bsdnet_bootp_cmdline;
+extern int32_t rtems_bsdnet_timeoffset;
+
+/*
+ * Manipulate routing tables
+ */
+struct sockaddr;
+struct rtentry;
+int rtems_bsdnet_rtrequest (
+ int req,
+ struct sockaddr *dst,
+ struct sockaddr *gateway,
+ struct sockaddr *netmask,
+ int flags,
+ struct rtentry **net_nrt);
+
+/*
+ * Diagnostics
+ */
+void rtems_bsdnet_show_inet_routes (void);
+void rtems_bsdnet_show_mbuf_stats (void);
+void rtems_bsdnet_show_if_stats (void);
+void rtems_bsdnet_show_ip_stats (void);
+void rtems_bsdnet_show_icmp_stats (void);
+void rtems_bsdnet_show_udp_stats (void);
+void rtems_bsdnet_show_tcp_stats (void);
+
+/*
+ * Network configuration
+ */
+struct rtems_bsdnet_ifconfig {
+ /*
+ * These three entries must be supplied for each interface.
+ */
+ char *name;
+
+ /*
+ * This function now handles attaching and detaching an interface.
+ * The parameter attaching indicates the operation being invoked.
+ * For older attach functions which do not have the extra parameter
+ * it will be ignored.
+ */
+ int (*attach)(struct rtems_bsdnet_ifconfig *conf, int attaching);
+
+ /*
+ * Link to next interface
+ */
+ struct rtems_bsdnet_ifconfig *next;
+
+ /*
+ * The following entries may be obtained
+ * from BOOTP or explicitily supplied.
+ */
+ char *ip_address;
+ char *ip_netmask;
+ void *hardware_address;
+
+ /*
+ * The driver assigns defaults values to the following
+ * entries if they are not explicitly supplied.
+ */
+ int ignore_broadcast;
+ int mtu;
+ int rbuf_count;
+ int xbuf_count;
+
+ /*
+ * For external ethernet controller board the following
+ * parameters are needed
+ */
+ unsigned int port; /* port of the board */
+ unsigned int irno; /* irq of the board */
+ unsigned int bpar; /* memory of the board */
+
+ /*
+ * Driver control block pointer. Typcially this points to the driver's
+ * controlling structure. You set this when you have the structure allocated
+ * externally to the driver.
+ */
+ void *drv_ctrl;
+
+};
+
+struct rtems_bsdnet_config {
+ /*
+ * This entry points to the head of the ifconfig chain.
+ */
+ struct rtems_bsdnet_ifconfig *ifconfig;
+
+ /*
+ * This entry should be rtems_bsdnet_do_bootp if BOOTP
+ * is being used to configure the network, and NULL
+ * if BOOTP is not being used.
+ */
+ void (*bootp)(void);
+
+ /*
+ * The remaining items can be initialized to 0, in
+ * which case the default value will be used.
+ */
+ rtems_task_priority network_task_priority; /* 100 */
+ unsigned long mbuf_bytecount; /* 64 kbytes */
+ unsigned long mbuf_cluster_bytecount; /* 128 kbytes */
+ char *hostname; /* BOOTP */
+ char *domainname; /* BOOTP */
+ char *gateway; /* BOOTP */
+ char *log_host; /* BOOTP */
+ char *name_server[3]; /* BOOTP */
+ char *ntp_server[3]; /* BOOTP */
+ /*
+ * Default "multiplier" on buffer size. This is
+ * claimed by the TCP/IP implementation to be for
+ * efficiency but you will have to measure the
+ * benefit for buffering beyond double buffering
+ * in your own application.
+ *
+ * The default value is 2.
+ *
+ * See kern/uipc_socket2.c for details.
+ */
+ unsigned long sb_efficiency;
+ /*
+ * Default UDP buffer sizes PER SOCKET!!
+ *
+ * TX = 9216 -- max datagram size
+ * RX = 40 * (1024 + sizeof(struct sockaddr_in))
+ *
+ * See netinet/udp_usrreq.c for details
+ */
+ unsigned long udp_tx_buf_size;
+ unsigned long udp_rx_buf_size;
+ /*
+ * Default UDP buffer sizes PER SOCKET!!
+ *
+ * TX = 16 * 1024
+ * RX = 16 * 1024
+ *
+ * See netinet/tcp_usrreq.c for details
+ */
+ unsigned long tcp_tx_buf_size;
+ unsigned long tcp_rx_buf_size;
+};
+
+/*
+ * Default global device configuration structure. This is scanned
+ * by the initialize network function. Check the network demo's for
+ * an example of the structure. Like the RTEMS configuration tables,
+ * they are not part of RTEMS but part of your application or bsp
+ * code.
+ */
+extern struct rtems_bsdnet_config rtems_bsdnet_config;
+
+/*
+ * Initialise the BSD stack, attach and `up' interfaces
+ * in the `rtems_bsdnet_config'. RTEMS must already be initialised.
+ */
+int rtems_bsdnet_initialize_network (void);
+
+/*
+ * Dynamic interface control. Drivers must free any resources such as
+ * memory, interrupts, io regions claimed during the `attach' and/or
+ * `up' operations when asked to `detach'.
+ * You must configure the interface after attaching it.
+ */
+void rtems_bsdnet_attach (struct rtems_bsdnet_ifconfig *ifconfig);
+void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifconfig);
+
+/*
+ * Interface configuration. The commands are listed in `sys/sockio.h'.
+ */
+int rtems_bsdnet_ifconfig (const char *ifname, uint32_t cmd, void *param);
+
+void rtems_bsdnet_do_bootp (void);
+void rtems_bsdnet_do_bootp_and_rootfs (void);
+
+/* NTP tuning parameters */
+extern int rtems_bsdnet_ntp_retry_count;
+extern int rtems_bsdnet_ntp_timeout_secs;
+extern int rtems_bsdnet_ntp_bcast_timeout_secs;
+
+
+struct timestamp {
+ uint32_t integer;
+ uint32_t fraction;
+};
+
+/* Data is passed in network byte order */
+struct ntpPacketSmall {
+ uint8_t li_vn_mode;
+ uint8_t stratum;
+ int8_t poll_interval;
+ int8_t precision;
+ int32_t root_delay;
+ int32_t root_dispersion;
+ char reference_identifier[4];
+ struct timestamp reference_timestamp;
+ struct timestamp originate_timestamp;
+ struct timestamp receive_timestamp;
+ struct timestamp transmit_timestamp;
+};
+
+/* NOTE: packet data is *only* accessible from the callback
+ *
+ * 'callback' is invoked twice, once prior to sending a request
+ * to the server and one more time after receiving a valid reply.
+ * This allows for the user to measure round-trip times.
+ *
+ * Semantics of the 'state' parameter:
+ *
+ * state == 1: 1st call, just prior to sending request. The
+ * packet has been set up already but may be
+ * modified by the callback (e.g. to set the originate
+ * timestamp).
+ * state == -1: 1st call - no request will be sent but we'll
+ * wait for a reply from a broadcast server. The
+ * packet has not been set up.
+ * state == 0: 2nd call. The user is responsible for keeping track
+ * of the 'state' during the first call in order to
+ * know if it makes sense to calculate 'round-trip' times.
+ *
+ * RETURN VALUE: the callback should return 0 if processing the packet was
+ * successful and -1 on error in which case rtems_bsdnet_get_ntp()
+ * may try another server.
+ */
+typedef int (*rtems_bsdnet_ntp_callback_t)(
+ struct ntpPacketSmall *packet,
+ int state,
+ void *usr_data);
+
+/* Obtain time from a NTP server and call user callback to process data;
+ * socket parameter may be -1 to request the routine to open and close its own socket.
+ * Networking parameters as configured are used...
+ *
+ * It is legal to pass a NULL callback pointer. In this case, a default callback
+ * is used which determines the current time by contacting an NTP server. The current
+ * time is converted to a 'struct timespec' (seconds/nanoseconds) and passed into *usr_data.
+ * The caller is responsible for providing a memory area >= sizeof(struct timespec).
+ *
+ * RETURNS: 0 on success, -1 on failure.
+ */
+int rtems_bsdnet_get_ntp(int socket, rtems_bsdnet_ntp_callback_t callback, void *usr_data);
+
+int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority);
+
+/*
+ * Callback to report BSD malloc starvation.
+ * The default implementation just prints a message but an application
+ * can provide its own version.
+ */
+void rtems_bsdnet_malloc_starvation(void);
+
+/*
+ * mbuf malloc interface to enable custom allocation of mbuf's
+ *
+ * May be declared in user code. If not, then the default is to
+ * malloc.
+ */
+void* rtems_bsdnet_malloc_mbuf(size_t size, int type);
+
+/*
+ * Possible values of the type parameter to rtems_bsdnet_malloc_mbuf to assist
+ * in allocation of the structure.
+ */
+#define MBUF_MALLOC_NMBCLUSTERS (0)
+#define MBUF_MALLOC_MCLREFCNT (1)
+#define MBUF_MALLOC_MBUF (2)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_BSDNET_H */
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
new file mode 100644
index 0000000000..a22a22391c
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
@@ -0,0 +1,205 @@
+/*
+ * Declarations to fit FreeBSD to RTEMS.
+ *
+ *******************************************************************
+ * WARNING *
+ * This file should *never* be included by any application program *
+ *******************************************************************
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_BSDNET_INTERNAL_H
+#define _RTEMS_RTEMS_BSDNET_INTERNAL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems.h>
+
+typedef unsigned int vm_offset_t;
+typedef long long vm_ooffset_t;
+typedef unsigned int vm_pindex_t;
+typedef unsigned int vm_size_t;
+
+#ifndef __ioctl_command_defined
+typedef u_int32_t ioctl_command_t;
+#define __ioctl_command_defined
+#endif
+
+
+#define _BSD_OFF_T_ int32_t
+#define _BSD_PID_T_ rtems_id
+#define _BSD_VA_LIST_ char *
+
+/* make sure we get the network versions of these */
+#include <machine/types.h>
+#include <machine/param.h>
+#include <rtems/bsd/sys/cdefs.h>
+
+#include <sys/time.h>
+
+struct mdproc {
+ int md_flags;
+ int *md_regs;
+};
+
+/*
+ * Other RTEMS/BSD glue
+ */
+struct socket;
+extern int soconnsleep (struct socket *so);
+extern void soconnwakeup (struct socket *so);
+#define splnet() 0
+#define splimp() 0
+#define splx(_s) do { (_s) = 0; } while(0)
+
+/* to avoid warnings */
+void *memcpy(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+
+#define ovbcopy(f,t,n) bcopy(f,t,n)
+#define copyout(f,t,n) (memcpy(t,f,n),0)
+#define copyin(f,t,n) (memcpy(t,f,n),0)
+
+#define random() rtems_bsdnet_random()
+#define panic rtems_panic
+#define suser(a,b) 0
+
+void microtime (struct timeval *tv);
+#define hz rtems_bsdnet_ticks_per_second
+#define tick rtems_bsdnet_microseconds_per_tick
+
+#define log rtems_bsdnet_log
+
+/*
+ * Since we can't have two sys/types.h files, we'll hack around
+ * and copy the contents of the BSD sys/types.h to here....
+ */
+
+typedef u_int64_t u_quad_t; /* quads */
+typedef int64_t quad_t;
+typedef quad_t * qaddr_t;
+
+typedef void __sighandler_t(int);
+typedef __sighandler_t *sig_t; /* type of pointer to a signal function */
+#define NSIG 32
+struct sigaltstack {
+ char *ss_sp; /* signal stack base */
+ int ss_size; /* signal stack length */
+ int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
+};
+
+#ifdef _KERNEL
+typedef int boolean_t;
+#endif
+
+#ifndef _POSIX_SOURCE
+/*
+ * minor() gives a cookie instead of an index since we don't want to
+ * change the meanings of bits 0-15 or waste time and space shifting
+ * bits 16-31 for devices that don't use them.
+ */
+#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */
+#define minor(x) ((int)((x)&0xffff00ff)) /* minor number */
+#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) /* create dev_t */
+#endif
+
+#include <rtems/endian.h>
+
+typedef quad_t rlim_t; /* resource limit */
+typedef u_int32_t fixpt_t; /* fixed point number */
+
+/*
+ * Forward structure declarations for function prototypes. We include the
+ * common structures that cross subsystem boundaries here; others are mostly
+ * used in the same place that the structure is defined.
+ */
+struct proc;
+struct pgrp;
+struct ucred;
+struct rusage;
+struct buf;
+struct tty;
+struct uio;
+struct rtems_bsdnet_ifconfig;
+
+/*
+ * Redo kernel memory allocation
+ */
+#define malloc(size,type,flags) rtems_bsdnet_malloc(size,type,flags)
+#define free(ptr,type) rtems_bsdnet_free(ptr,type)
+#define timeout(ftn,arg,ticks) rtems_bsdnet_timeout(ftn,arg,ticks)
+
+#define M_NOWAIT 0x0001
+void *rtems_bsdnet_malloc (size_t size, int type, int flags);
+void rtems_bsdnet_free (void *addr, int type);
+
+void rtems_bsdnet_semaphore_obtain (void);
+void rtems_bsdnet_semaphore_release (void);
+void rtems_bsdnet_schednetisr (int n);
+int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
+
+unsigned long rtems_bsdnet_seconds_since_boot (void);
+unsigned long rtems_bsdnet_random (void);
+
+rtems_id rtems_bsdnet_newproc (
+ char *name,
+ int stacksize,
+ void (*entry)(void *),
+ void *arg
+);
+
+rtems_status_code rtems_bsdnet_event_receive (
+ rtems_event_set event_in,
+ rtems_option option_set,
+ rtems_interval ticks,
+ rtems_event_set *event_out
+);
+
+/*
+ * Network configuration
+ */
+extern int rtems_bsdnet_ticks_per_second;
+extern int rtems_bsdnet_microseconds_per_tick;
+extern struct in_addr rtems_bsdnet_log_host_address;
+extern char *rtems_bsdnet_domain_name;
+
+/*
+ * Internal IOCTL command
+ */
+#define SIO_RTEMS_SHOW_STATS _IO('i', 250)
+
+/*
+ * Some extra prototypes
+ */
+int sethostname (char *name, size_t namelen);
+void domaininit (void *);
+void ifinit (void *);
+void ipintr (void);
+void arpintr (void);
+bool bootpc_init(bool, bool);
+int socket (int, int, int);
+int ioctl (int, ioctl_command_t, ...);
+
+/*
+ * Events used by networking routines.
+ * Everything will break if the application
+ * tries to use these events or if the `sleep'
+ * events are equal to any of the NETISR * events.
+ */
+#define SBWAIT_EVENT RTEMS_EVENT_24
+#define SOSLEEP_EVENT RTEMS_EVENT_25
+#define NETISR_IP_EVENT (1L << NETISR_IP)
+#define NETISR_ARP_EVENT (1L << NETISR_ARP)
+#define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)
+#if (SBWAIT_EVENT & SOSLEEP_EVENT & NETISR_EVENTS)
+# error "Network event conflict"
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_RTEMS_BSDNET_INTERNAL_H */
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet_malloc_starvation.c b/cpukit/libnetworking/rtems/rtems_bsdnet_malloc_starvation.c
new file mode 100644
index 0000000000..5e7d45d713
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet_malloc_starvation.c
@@ -0,0 +1,19 @@
+/*
+ * Routine called when malloc() is not succeeding. This can be overridden
+ * by a BSP.
+ *
+ * $Id*
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <rtems/rtems_bsdnet.h>
+
+void
+rtems_bsdnet_malloc_starvation(void)
+{
+ printf ("rtems_bsdnet_malloc still waiting.\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c
new file mode 100644
index 0000000000..82f8fd9c5b
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_dhcp.c
@@ -0,0 +1,1231 @@
+/*
+ * DCHP client for RTEMS
+ * Andrew Bythell, <abythell@nortelnetworks.com>
+ * based on and uses subroutines from c/src/libnetworking/nfs/bootp_subr.c
+ */
+
+/*
+ * DHCP task added.
+ * Brendan Gannon, <bgannon@cybertec.com.au>
+ */
+
+/*
+ * Added interface to terminate DHCP task, and removed panics.
+ * Arnout Vandecappelle <arnout@mind.be>, Essensium/Mind
+ * Maarten Van Es <maarten@mind.be>, Essensium/Mind
+ */
+
+/*
+ * Copyright (c) 1995 Gordon Ross, Adam Glass
+ * Copyright (c) 1992 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Lawrence Berkeley Laboratory and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ * WARNING:
+ * This file should be moved into c/src/libnetworking/nfs
+ * and the following two #ifndef...#endif blocks and the #undefs at
+ * the end of the file should be removed
+ */
+
+#ifndef __INSIDE_RTEMS_BSD_TCPIP_STACK__
+#define __INSIDE_RTEMS_BSD_TCPIP_STACK__
+#endif
+
+#ifndef __BSD_VISIBLE
+#define __BSD_VISIBLE 1
+#endif
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/bsdnet/servers.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <sys/ioctl.h>
+#include <sys/param.h> /* for MAXHOSTNAMELEN */
+#include <sys/systm.h>
+#include <sys/socketvar.h> /* for socreat() soclose() */
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/if_var.h>
+#include <netinet/in.h> /* for NBO-HBO conversions */
+#include <net/if_types.h> /* for IFT_ETHER */
+#include <net/if_dl.h> /* for LLADDR */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <rtems/mkrootfs.h>
+
+#include "rtems/dhcp.h"
+
+#ifndef EALEN
+#define EALEN 6
+#endif
+
+/*
+ *DHCP flags
+ */
+#define DHCP_BROADCAST 0x8000
+#define DHCP_UNICAST 0x0000
+
+/*
+ * DHCP Op Codes
+ */
+#define DHCP_BOOTREQUEST 1
+#define DHCP_BOOTREPLY 2
+
+/*
+ * DHCP Messages
+ */
+#define DHCP_DISCOVER 1
+#define DHCP_OFFER 2
+#define DHCP_REQUEST 3
+#define DHCP_DECLINE 4
+#define DHCP_ACK 5
+#define DHCP_NACK 6
+#define DHCP_RELEASE 7
+
+/*
+ * DHCP Options
+ */
+#define DHCP_OPTION_PAD 0
+#define DHCP_SUBNET 1
+#define DHCP_GATEWAY 3
+#define DHCP_DNS 6
+#define DHCP_HOST 12
+#define DHCP_DOMAIN_NAME 15
+#define DHCP_NETMASK 28
+#define DHCP_REQUESTED_IP 50
+#define DHCP_LEASE 51
+#define DHCP_MESSAGE 53
+#define DHCP_SERVER 54
+#define DHCP_PARAMETERS 55
+#define DHCP_OPTION_END 255
+
+/*
+ * Definitions from RFC
+ */
+struct dhcp_packet
+{
+ u_int8_t op;
+ u_int8_t htype;
+ u_int8_t hlen;
+ u_int8_t hops;
+ u_int32_t xid;
+ u_int16_t secs;
+ u_int16_t flags;
+ struct in_addr ciaddr;
+ struct in_addr yiaddr;
+ struct in_addr siaddr;
+ struct in_addr giaddr;
+ unsigned char chaddr[16];
+ char sname[64];
+ char file[128];
+ unsigned char vend[312];
+};
+
+/*
+ * External Declarations for Functions found in
+ * rtems/c/src/libnetworking/nfs/
+ */
+extern int bootpc_call (struct dhcp_packet *call,
+ struct dhcp_packet *reply,
+ struct proc *procp);
+extern int bootpc_fakeup_interface (struct ifreq *ireq,
+ struct socket *so,
+ struct proc *procp);
+extern int bootpc_adjust_interface (struct ifreq *ireq,
+ struct socket *so,
+ struct sockaddr_in *myaddr,
+ struct sockaddr_in *netmask,
+ struct sockaddr_in *gw,
+ struct proc *procp);
+extern void *bootp_strdup_realloc (char *dst,
+ const char *src);
+
+/*
+ * Variables
+ */
+static int dhcp_option_overload = 0;
+static char dhcp_gotgw = 0;
+static char dhcp_gotnetmask = 0;
+static char dhcp_gotserver = 0;
+static char dhcp_gotlogserver = 0;
+static struct sockaddr_in dhcp_netmask;
+static struct sockaddr_in dhcp_gw;
+static char *dhcp_hostname;
+static int dhcp_message_type = 0;
+static unsigned long dhcp_lease_time;
+static unsigned long dhcp_elapsed_time = 0;
+static const char dhcp_magic_cookie[4] = { 99, 130, 83, 99 };
+static const char dhcp_request_parameters[5] = { DHCP_SUBNET,
+ DHCP_GATEWAY,
+ DHCP_DNS,
+ DHCP_HOST,
+ DHCP_DOMAIN_NAME };
+
+/*
+ * Format an IP address in dotted decimal.
+ */
+void
+format_ip (unsigned long ip, char* buffer)
+{
+ sprintf (buffer,
+ "%lu.%lu.%lu.%lu",
+ (ip >> 24),
+ (ip >> 16) & 0xff,
+ (ip >> 8) & 0xff,
+ (ip & 0xff));
+
+ return;
+}
+
+/*
+ * Print the IP setup
+ */
+static void
+printsetup (const char *iface,
+ struct in_addr ip_addr,
+ struct in_addr mask_addr,
+ struct in_addr srv_addr,
+ struct in_addr gw_addr)
+{
+ unsigned long ip;
+ char ip_str[15];
+
+ printf ("dhcpc: %s: ", iface);
+
+ ip = ntohl (ip_addr.s_addr);
+ format_ip (ip, ip_str);
+ printf ("inet: %-15s ", ip_str);
+
+ ip = ntohl (mask_addr.s_addr);
+ format_ip (ip, ip_str);
+ printf ("mask: %-15s\n", ip_str);
+
+ ip = ntohl (srv_addr.s_addr);
+ format_ip (ip, ip_str);
+ printf (" srv: %-15s ", ip_str);
+
+ ip = ntohl (gw_addr.s_addr);
+ format_ip (ip, ip_str);
+ printf (" gw: %-15s\n", ip_str);
+
+ return;
+}
+
+/*
+ * Process options from the DHCP packet.
+ * Based on BOOTP routine.
+ */
+static void
+process_options (unsigned char *optbuf, int optbufSize)
+{
+ int j = 0;
+ int len;
+ int code, ncode;
+ char *p;
+
+ dhcp_message_type = 0;
+
+ ncode = optbuf[0];
+ while (j < optbufSize)
+ {
+ code = optbuf[j] = ncode;
+ if (code == 255)
+ return;
+ if (code == 0)
+ {
+ j++;
+ continue;
+ }
+ len = optbuf[j + 1];
+ j += 2;
+
+ if ((len + j) >= optbufSize)
+ {
+ printf ("Truncated field for code %d", code);
+ return;
+ }
+
+ ncode = optbuf[j + len];
+ optbuf[j + len] = '\0';
+ p = (char*) &optbuf[j];
+ j += len;
+
+ /*
+ * Process the option
+ */
+ switch (code)
+ {
+ case 1:
+ /* Subnet mask */
+ if (len != 4) {
+ printf ("dhcpc: subnet mask len is %d\n", len);
+ continue;
+ }
+ memcpy (&dhcp_netmask.sin_addr, p, 4);
+ dhcp_gotnetmask = 1;
+ break;
+
+ case 2:
+ /* Time offset */
+ if (len != 4) {
+ printf ("dhcpc: time offset len is %d\n", len);
+ continue;
+ }
+ memcpy (&rtems_bsdnet_timeoffset, p, 4);
+ rtems_bsdnet_timeoffset = ntohl (rtems_bsdnet_timeoffset);
+ break;
+
+ case 3:
+ /* Routers */
+ if (len % 4) {
+ printf ("dhcpc: Router Len is %d\n", len);
+ continue;
+ }
+ if (len > 0)
+ {
+ memcpy (&dhcp_gw.sin_addr, p, 4);
+ dhcp_gotgw = 1;
+ }
+ break;
+
+ case 42:
+ /* NTP servers */
+ if (len % 4) {
+ printf ("dhcpc: time server Len is %d\n", len);
+ continue;
+ }
+ {
+ int tlen = 0;
+ while ((tlen < len) &&
+ (rtems_bsdnet_ntpserver_count <
+ sizeof rtems_bsdnet_config.ntp_server /
+ sizeof rtems_bsdnet_config.ntp_server[0]))
+ {
+ memcpy (&rtems_bsdnet_ntpserver[rtems_bsdnet_ntpserver_count],
+ p + tlen, 4);
+ rtems_bsdnet_ntpserver_count++;
+ tlen += 4;
+ }
+ }
+ break;
+
+ case 6:
+ /* Domain Name servers */
+ if (len % 4) {
+ printf ("dhcpc: DNS Len is %d\n", len);
+ continue;
+ }
+ {
+ int dlen = 0;
+ while ((dlen < len) &&
+ (rtems_bsdnet_nameserver_count <
+ sizeof rtems_bsdnet_config.name_server /
+ sizeof rtems_bsdnet_config.name_server[0]))
+ {
+ memcpy (&rtems_bsdnet_nameserver
+ [rtems_bsdnet_nameserver_count], p + dlen, 4);
+ rtems_bsdnet_nameserver_count++;
+ dlen += 4;
+ }
+ }
+ break;
+
+ case 12:
+ /* Host name */
+ if (len >= MAXHOSTNAMELEN) {
+ printf ("dhcpc: hostname >= %d bytes\n", MAXHOSTNAMELEN);
+ len = MAXHOSTNAMELEN-1;
+ }
+ if (sethostname (p, len) < 0)
+ printf ("dhcpc: can't set host name");
+ if (dhcp_hostname != NULL)
+ {
+ dhcp_hostname = realloc (dhcp_hostname, len);
+ strncpy (dhcp_hostname, p, len);
+ }
+ else
+ dhcp_hostname = strndup (p, len);
+ break;
+
+ case 7:
+ /* Log servers */
+ if (len % 4) {
+ printf ("dhcpc: Log server Len is %d\n", len);
+ continue;
+ }
+ if (len > 0)
+ {
+ memcpy (&rtems_bsdnet_log_host_address, p, 4);
+ dhcp_gotlogserver = 1;
+ }
+ break;
+
+ case 15:
+ /* Domain name */
+ if (p[0])
+ {
+ rtems_bsdnet_domain_name = strdup (p);
+ }
+ break;
+
+ case 16: /* Swap server IP address. unused */
+ break;
+
+ case 50:
+ /* DHCP Requested IP Address */
+ if (len != 4)
+ printf ("dhcpc: DHCP option requested IP len is %d", len);
+ /*
+ * although nothing happens here, this case keeps the client
+ * from complaining about unknown options. The Requested IP
+ * is necessary to return to the server for a DHCP REQUEST
+ */
+ break;
+
+ case 51:
+ /* DHCP Lease Length */
+ if (len != 4) {
+ printf ("dhcpc: DHCP option lease-length len is %d", len);
+ continue;
+ }
+ memcpy (&dhcp_lease_time, &p[0], 4);
+ dhcp_lease_time = ntohl (dhcp_lease_time);
+ break;
+
+ case 52:
+ /* DHCP option override */
+ if (len != 1) {
+ printf ("dhcpc: DHCP option overload len is %d", len);
+ continue;
+ }
+ dhcp_option_overload = p[0];
+ break;
+
+ case 53:
+ /* DHCP message */
+ if (len != 1) {
+ printf ("dhcpc: DHCP message len is %d", len);
+ continue;
+ }
+ dhcp_message_type = p[0];
+ break;
+
+ case 128: /* Site-specific option for DHCP servers that
+ * a) don't supply tag 54
+ * and
+ * b) don't supply the server address in siaddr
+ * For example, on Solaris 2.6 in.dhcpd, include in the dhcptab:
+ * Bootsrv s Site,128,IP,1,1
+ * and use that symbol in the macro that defines the client:
+ * Bootsrv=<tftp-server-ip-address>
+ */
+ case 54:
+ /* DHCP server */
+ if (len != 4) {
+ printf ("dhcpc: DHCP server len is %d", len);
+ continue;
+ }
+ memcpy (&rtems_bsdnet_bootp_server_address, p, 4);
+ dhcp_gotserver = 1;
+ break;
+
+ case 66:
+ /* DHCP server name option */
+ if (p[0])
+ rtems_bsdnet_bootp_server_name = strdup (p);
+ break;
+
+ case 67:
+ /* DHCP bootfile option */
+ if (p[0])
+ rtems_bsdnet_bootp_boot_file_name = strdup (p);
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+/*
+ * Generate the packet for a DHCP DISCOVER.
+ */
+static int
+dhcp_discover_req (struct dhcp_packet* call,
+ struct sockaddr_dl *sdl,
+ unsigned long *xid)
+{
+ int len = 0;
+
+ memset (call, 0, sizeof (struct dhcp_packet));
+
+ /*
+ * Send a DHCP DISCOVER Message
+ */
+ call->op = DHCP_BOOTREQUEST;
+ call->htype = 1; /* 10mb ethernet */
+ call->hlen = sdl->sdl_alen; /* Hardware address length */
+ call->hops = 0;
+ (*xid)++;
+ call->xid = htonl (*xid);
+ call->flags = htons (DHCP_BROADCAST);
+
+ memcpy (&call->chaddr, LLADDR (sdl), sdl->sdl_alen);
+
+ /*
+ * Magic cookie.
+ */
+ memcpy (&call->vend[len], dhcp_magic_cookie, sizeof (dhcp_magic_cookie));
+ len += sizeof (dhcp_magic_cookie);
+
+ /*
+ * DHCP Message type.
+ */
+ call->vend[len++] = DHCP_MESSAGE;
+ call->vend[len++] = 1;
+ call->vend[len++] = DHCP_DISCOVER;
+
+ /*
+ * DHCP Parameter request list
+ */
+ call->vend[len++] = DHCP_PARAMETERS;
+ call->vend[len++] = sizeof (dhcp_request_parameters);
+ memcpy (&call->vend[len], &dhcp_request_parameters, sizeof (dhcp_request_parameters));
+ len += sizeof (dhcp_request_parameters);
+
+ /*
+ * Lease time.
+ */
+ call->vend[len++] = DHCP_LEASE;
+ call->vend[len++] = 4;
+ memset (&call->vend[len], 0xFF, 4); /* request infinite lease time */
+ len += 4;
+
+ /*
+ * End.
+ */
+ call->vend[len++] = DHCP_OPTION_END;
+ call->secs = 0;
+
+ return len;
+}
+
+/*
+ * Generate the packet for a DHCP REQUEST.
+ */
+static int
+dhcp_request_req (struct dhcp_packet* call,
+ struct dhcp_packet* reply,
+ struct sockaddr_dl *sdl,
+ int broadcast)
+{
+ int len = 0;
+ unsigned long temp;
+ char *hostname;
+
+ memset (call, 0, sizeof (struct dhcp_packet));
+
+ /*
+ * Send a DHCP REQUEST Message
+ */
+ call->op = DHCP_BOOTREQUEST;
+ call->htype = 1; /* 10mb ethernet */
+ call->hlen = sdl->sdl_alen; /* Hardware address length */
+ call->hops = 0;
+ call->xid = reply->xid;
+ if (broadcast)
+ call->flags = htons (DHCP_BROADCAST);
+ else
+ {
+ call->flags = htons (DHCP_UNICAST);
+ call->ciaddr = reply->yiaddr;
+ }
+ memcpy (&call->chaddr, LLADDR (sdl), sdl->sdl_alen);
+
+ /*
+ * Magic cookie.
+ */
+ memcpy (&call->vend[len], dhcp_magic_cookie, sizeof (dhcp_magic_cookie));
+ len += sizeof (dhcp_magic_cookie);
+
+ /*
+ * DHCP Message type.
+ */
+ call->vend[len++] = DHCP_MESSAGE;
+ call->vend[len++] = 1;
+ call->vend[len++] = DHCP_REQUEST;
+
+ /*
+ * DHCP server
+ */
+ if (broadcast)
+ {
+ call->vend[len++] = DHCP_SERVER;
+ call->vend[len++] = sizeof (rtems_bsdnet_bootp_server_address);
+ memcpy (&call->vend[len], &rtems_bsdnet_bootp_server_address,
+ sizeof (rtems_bsdnet_bootp_server_address));
+ len += sizeof (rtems_bsdnet_bootp_server_address);
+ }
+
+ /*
+ * Requested IP
+ */
+ call->vend[len++] = DHCP_REQUESTED_IP;
+ call->vend[len++] = sizeof (reply->yiaddr);
+ memcpy (&call->vend[len], &reply->yiaddr, sizeof (reply->yiaddr));
+ len += sizeof (reply->yiaddr);
+
+ /*
+ * DHCP Parameter request list
+ */
+ call->vend[len++] = DHCP_PARAMETERS;
+ call->vend[len++] = sizeof (dhcp_request_parameters);
+ memcpy (&call->vend[len], &dhcp_request_parameters, sizeof (dhcp_request_parameters));
+ len += sizeof (dhcp_request_parameters);
+
+ /*
+ * Lease time.
+ * For the REQUEST, return the lease time the server offered.
+ */
+ call->vend[len++] = DHCP_LEASE;
+ call->vend[len++] = 4;
+ temp = htonl (dhcp_lease_time);
+ memcpy (&call->vend[len], &temp, sizeof (unsigned long));
+ len += 4;
+
+ /*
+ * Host name.
+ */
+ hostname = malloc (MAXHOSTNAMELEN, 0, M_NOWAIT);
+ if (hostname != NULL)
+ {
+ if (gethostname (hostname, MAXHOSTNAMELEN) == 0)
+ {
+ call->vend[len++] = DHCP_HOST;
+ call->vend[len++] = strlen (hostname);
+ strcpy ((char*) &call->vend[len], hostname);
+ len += strlen (hostname);
+ }
+ free (hostname, 0);
+ }
+
+ /*
+ * End.
+ */
+ call->vend[len++] = DHCP_OPTION_END;
+ call->secs = 0;
+
+ return len;
+}
+
+/*
+ * Variables for the DHCP task.
+ */
+static struct dhcp_packet dhcp_req;
+static rtems_id dhcp_task_id;
+
+/*
+ * The DHCP task counts until half the lease time has expired.
+ * When this period is up, it sends a DHCP REQUEST packet to the
+ * server again to renew the lease.
+ * If the lease is renewed, the task starts counting again.
+ * If the lease is not renewed, the task retries until it is.
+ *
+ * The task will not rebind if the lease is not renewed.
+ */
+static void
+dhcp_task (rtems_task_argument _sdl)
+{
+ unsigned long count;
+ struct dhcp_packet call;
+ struct sockaddr_dl *sdl;
+ rtems_event_set event_out;
+ unsigned int timeout = 0;
+ int error;
+ struct proc *procp = NULL;
+ int disconnected;
+ rtems_status_code ev_st;
+
+ sdl = (struct sockaddr_dl *) _sdl;
+
+ count = dhcp_elapsed_time;
+ disconnected = 0;
+
+ while (true)
+ {
+ /*
+ * Sleep until the next poll
+ */
+ timeout = TOD_MILLISECONDS_TO_TICKS (1000);
+ ev_st = rtems_event_receive (RTEMS_EVENT_0,
+ RTEMS_WAIT | RTEMS_EVENT_ANY,
+ timeout, &event_out);
+
+ /*
+ * Check if not a poll timeout. So when ANY event received, exit task.
+ * Actually, only event RTEMS_EVENT_0 sent from rtem_dhcp_failsafe.c
+ * if "failsafe" dhcp enabled when interface down. Otherwise, no
+ * event should occur, just timeout.
+ */
+ if(ev_st != RTEMS_TIMEOUT)
+ break;
+
+ count++;
+
+ if (count >= (dhcp_lease_time / 2))
+ {
+ rtems_bsdnet_semaphore_obtain ();
+
+ dhcp_request_req (&call, &dhcp_req, sdl, true);
+
+ /*
+ * Send the Request.
+ */
+ error = bootpc_call (&call, &dhcp_req, procp);
+ if (error) {
+ rtems_bsdnet_semaphore_release ();
+ printf ("DHCP call failed -- error %d", error);
+ continue;
+ }
+
+ /*
+ * Check for DHCP ACK/NACK
+ */
+ if (memcmp (&dhcp_req.vend[0],
+ dhcp_magic_cookie,
+ sizeof (dhcp_magic_cookie)) != 0)
+ {
+ rtems_bsdnet_semaphore_release ();
+ printf ("DHCP server did not send Magic Cookie.\n");
+ continue;
+ }
+
+ process_options (&dhcp_req.vend[4], sizeof (dhcp_req.vend) - 4);
+
+ if (dhcp_message_type != DHCP_ACK)
+ {
+ rtems_bsdnet_semaphore_release ();
+ printf ("DHCP server did not accept the DHCP request");
+ continue;
+ }
+
+ rtems_bsdnet_semaphore_release ();
+
+ count = 0;
+ }
+ }
+
+
+ dhcp_task_id = 0;
+ printf ("dhcpc: exiting lease renewal task.\n");
+ rtems_task_delete( RTEMS_SELF);
+
+}
+
+/*
+ * Start the DHCP task.
+ */
+static rtems_status_code
+dhcp_start_task (struct sockaddr_dl *sdl,
+ struct dhcp_packet *reply,
+ int priority)
+{
+ rtems_status_code sc;
+
+ memcpy (&dhcp_req, reply, sizeof (struct dhcp_packet));
+
+ sc = rtems_task_create (rtems_build_name ('d','h','c','p'),
+ priority,
+ 2048,
+ RTEMS_PREEMPT |
+ RTEMS_NO_TIMESLICE |
+ RTEMS_NO_ASR |
+ RTEMS_INTERRUPT_LEVEL (0),
+ RTEMS_LOCAL,
+ &dhcp_task_id);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ sc = rtems_task_start (dhcp_task_id,
+ dhcp_task,
+ (rtems_task_argument) sdl);
+
+ if (sc != RTEMS_SUCCESSFUL)
+ return sc;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * Check if the chosen interface already has an IP.
+ */
+static int
+dhcp_interface_has_ip (struct ifreq *ireq, struct socket *so, struct proc *procp)
+{
+ struct sockaddr_in* sin;
+ int error;
+
+ /*
+ * Check if the interface is already up.
+ */
+ error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)ireq, procp);
+ if (error)
+ return 0;
+
+ if ((ireq->ifr_flags & IFF_UP) == 0)
+ return 0;
+
+ sin = (struct sockaddr_in *)&ireq->ifr_addr;
+ bzero ((caddr_t)sin, sizeof (struct sockaddr_in));
+ sin->sin_len = sizeof (struct sockaddr_in);
+ sin->sin_family = AF_INET;
+ error = ifioctl (so, SIOCGIFADDR, (caddr_t)ireq, procp);
+ if (error)
+ return 0;
+
+ if (sin->sin_addr.s_addr != 0)
+ return 1;
+
+ return 0;
+}
+
+/*
+ * DCHP Client Routine
+ * - The first DHCP offer is always accepted
+ * - No DHCP DECLINE message is sent if ARPing fails
+ *
+ * return value:
+ * 0: ok
+ * < 0: failed to startup or configure interface
+ */
+int
+dhcp_init (int update_files)
+{
+ struct dhcp_packet call;
+ struct dhcp_packet reply;
+ static unsigned long xid = ~0xFF;
+ struct ifreq ireq;
+ struct ifnet *ifp;
+ struct socket *so;
+ int len;
+ int error;
+ struct sockaddr_in myaddr;
+ struct ifaddr *ifa;
+ struct sockaddr_dl *sdl = NULL;
+ struct proc *procp = NULL;
+
+ /*
+ * If we are to update the files create the root
+ * file structure.
+ */
+ if (update_files)
+ if (rtems_create_root_fs () < 0) {
+ printf("Error creating the root filesystem.\nFile not created.\n");
+ update_files = 0;
+ }
+
+ /*
+ * Find a network interface.
+ */
+ for (ifp = ifnet; ifp != 0; ifp = ifp->if_next)
+ if ((ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) == 0)
+ break;
+ if (ifp == NULL){
+ printf ("dhcpc_init: no suitable interface\n");
+ return -1;
+ }
+
+ memset (&ireq, 0, sizeof (ireq));
+ sprintf (ireq.ifr_name, "%s%d", ifp->if_name, ifp->if_unit);
+
+ if ((error = socreate (AF_INET, &so, SOCK_DGRAM, 0, procp)) != 0) {
+ printf ("dhcpc_init: socreate, error: %s\n", strerror(error));
+ return -1;
+ }
+
+ if (!dhcp_interface_has_ip (&ireq, so, procp))
+ bootpc_fakeup_interface (&ireq, so, procp);
+
+ /*
+ * Get HW address
+ */
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+ if (ifa->ifa_addr->sa_family == AF_LINK &&
+ (sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) &&
+ sdl->sdl_type == IFT_ETHER)
+ break;
+
+ if (!sdl){
+ printf ("dhcpc_init: Unable to find HW address\n");
+ soclose (so);
+ return -1;
+ }
+ if (sdl->sdl_alen != EALEN) {
+ printf ("dhcpc_init: HW address len is %d, expected value is %d\n",
+ sdl->sdl_alen, EALEN);
+ soclose (so);
+ return -1;
+ }
+
+ /*
+ * Build the DHCP Discover
+ */
+ len = dhcp_discover_req (&call, sdl, &xid);
+
+ /*
+ * Send the Discover.
+ */
+ error = bootpc_call (&call, &reply, procp);
+ if (error) {
+ printf ("BOOTP call failed -- %s\n", strerror(error));
+ soclose (so);
+ return -1;
+ }
+
+ /*
+ * Check for DHCP OFFER
+ */
+ if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) {
+ printf ("DHCP server did not send Magic Cookie.\n");
+ soclose (so);
+ return -1;
+ }
+
+ process_options (&reply.vend[4], sizeof (reply.vend) - 4);
+
+ if (dhcp_message_type != DHCP_OFFER) {
+ printf ("DHCP server did not send a DHCP Offer.\n");
+ soclose (so);
+ return -1;
+ }
+
+ /*
+ * Send a DHCP REQUEST
+ */
+ dhcp_request_req (&call, &reply, sdl, true);
+
+ error = bootpc_call (&call, &reply, procp);
+ if (error) {
+ printf ("BOOTP call failed -- %s\n", strerror(error));
+ soclose (so);
+ return -1;
+ }
+
+ /*
+ * Check for DHCP ACK/NACK
+ */
+ if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) {
+ printf ("DHCP server did not send Magic Cookie.\n");
+ soclose (so);
+ return -1;
+ }
+
+ process_options (&reply.vend[4], sizeof (reply.vend) - 4);
+
+ if (dhcp_message_type != DHCP_ACK) {
+ printf ("DHCP server did not accept the DHCP request\n");
+ soclose (so);
+ return -1;
+ }
+
+ /*
+ * Initialize network address structures
+ */
+ memset (&myaddr, 0, sizeof (myaddr));
+ memset (&dhcp_netmask, 0, sizeof (dhcp_netmask));
+ memset (&dhcp_gw, 0, sizeof (dhcp_gw));
+ myaddr.sin_len = sizeof (myaddr);
+ myaddr.sin_family = AF_INET;
+ dhcp_netmask.sin_len = sizeof (dhcp_netmask);
+ dhcp_netmask.sin_family = AF_INET;
+ dhcp_gw.sin_len = sizeof (dhcp_gw);
+ dhcp_gw.sin_family = AF_INET;
+
+ /*
+ * Set our address
+ */
+ myaddr.sin_addr = reply.yiaddr;
+
+ /*
+ * Process BOOTP/DHCP options
+ */
+ if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) == 0)
+ process_options (&reply.vend[4], sizeof (reply.vend) - 4);
+
+ if (dhcp_option_overload & 1)
+ process_options ((unsigned char*) reply.file, sizeof reply.file);
+ else
+ if (reply.file[0])
+ rtems_bsdnet_bootp_boot_file_name = strdup (reply.file);
+
+ if (dhcp_option_overload & 2)
+ process_options ((unsigned char*) reply.sname, sizeof reply.sname);
+ else
+ if (reply.sname[0])
+ rtems_bsdnet_bootp_server_name = strdup (reply.sname);
+
+ /*
+ * Use defaults if values were not supplied by BOOTP/DHCP options
+ */
+ if (!dhcp_gotnetmask)
+ {
+ if (IN_CLASSA (ntohl (myaddr.sin_addr.s_addr)))
+ dhcp_netmask.sin_addr.s_addr = htonl (IN_CLASSA_NET);
+ else if (IN_CLASSB (ntohl (myaddr.sin_addr.s_addr)))
+ dhcp_netmask.sin_addr.s_addr = htonl (IN_CLASSB_NET);
+ else
+ dhcp_netmask.sin_addr.s_addr = htonl (IN_CLASSC_NET);
+ }
+
+ if (!dhcp_gotserver)
+ rtems_bsdnet_bootp_server_address = reply.siaddr;
+
+ if (!dhcp_gotgw)
+ dhcp_gw.sin_addr = reply.giaddr;
+
+ if (!dhcp_gotlogserver)
+ rtems_bsdnet_log_host_address = rtems_bsdnet_bootp_server_address;
+
+ printsetup (ifp->if_name, myaddr.sin_addr, dhcp_netmask.sin_addr,
+ rtems_bsdnet_bootp_server_address, dhcp_gw.sin_addr);
+
+ /*
+ * Update the files if we are asked too.
+ */
+ if (update_files) {
+ char *dn = rtems_bsdnet_domain_name;
+ char *hn = dhcp_hostname;
+ if (!dn)
+ dn = "mydomain";
+ if (!hn)
+ {
+ hn = "me";
+ sethostname (hn, strlen (hn));
+ }
+ rtems_rootfs_append_host_rec(myaddr.sin_addr.s_addr, hn, dn);
+
+ /*
+ * Should the given domainname be used here ?
+ */
+ if (dhcp_gotserver) {
+ if (rtems_bsdnet_bootp_server_name)
+ hn = rtems_bsdnet_bootp_server_name;
+ else
+ hn = "bootps";
+ rtems_rootfs_append_host_rec(rtems_bsdnet_bootp_server_address.s_addr,
+ hn, dn);
+ }
+
+ if (dhcp_gotlogserver) {
+ rtems_rootfs_append_host_rec(rtems_bsdnet_log_host_address.s_addr,
+ "logs", dn);
+ }
+
+ /*
+ * Setup the DNS configuration file /etc/resolv.conf.
+ */
+ if (rtems_bsdnet_nameserver_count) {
+ int i;
+ char buf[64];
+ const char *bufl[1];
+
+ bufl[0] = buf;
+
+#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH)
+
+ if (rtems_bsdnet_domain_name &&
+ (strlen(rtems_bsdnet_domain_name) < (sizeof(buf) - 1))) {
+ strcpy(buf, "search ");
+ strcat(buf, rtems_bsdnet_domain_name);
+ strcat(buf, "\n");
+ rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl);
+ }
+
+ for (i = 0; i < rtems_bsdnet_nameserver_count; i++) {
+ strcpy(buf, "nameserver ");
+ strcat(buf, inet_ntoa(rtems_bsdnet_ntpserver[i]));
+ strcat(buf, "\n");
+ if (rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl))
+ break;
+ }
+ }
+ }
+
+ /*
+ * Configure the interface with the new settings
+ */
+ error = bootpc_adjust_interface (&ireq, so,
+ &myaddr, &dhcp_netmask, &dhcp_gw, procp);
+
+ /*
+ * Start the DHCP task if the lease isn't infinite.
+ */
+ if (dhcp_lease_time != 0xffffffff)
+ dhcp_start_task (sdl, &reply, 150);
+
+ soclose (so);
+
+ return 0;
+}
+
+/*
+ *
+ * RTEMS Entry point to DHCP client
+ *
+ */
+void rtems_bsdnet_do_dhcp (void)
+{
+ bool update = true;
+ rtems_bsdnet_semaphore_obtain ();
+ while( dhcp_init (update) < 0 ) {
+ update = false;
+ rtems_bsdnet_semaphore_release();
+ rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(1000));
+ rtems_bsdnet_semaphore_obtain ();
+ }
+ rtems_bsdnet_semaphore_release ();
+}
+
+int rtems_bsdnet_do_dhcp_timeout( void )
+{
+ int return_value;
+
+ rtems_bsdnet_semaphore_obtain ();
+ return_value = dhcp_init (false);
+ rtems_bsdnet_semaphore_release ();
+
+ return return_value;
+}
+
+void rtems_bsdnet_dhcp_down (void)
+{
+ if(dhcp_task_id != 0) {
+ rtems_event_send (dhcp_task_id, RTEMS_EVENT_0);
+ }
+}
+
+void
+rtems_bsdnet_do_dhcp_refresh_only (unsigned long xid,
+ unsigned long lease_time,
+ unsigned long elapsed_time,
+ unsigned long ip_address,
+ unsigned long srv_address,
+ const char* hostname)
+{
+ struct dhcp_packet reply;
+ struct ifnet *ifp = NULL;
+ struct ifaddr *ifa = NULL;
+ struct sockaddr_dl *sdl = NULL;
+ struct sockaddr_in *sin = NULL;
+ int match = 0;
+ struct ifnet *mtif = NULL;
+
+ /*
+ * If an infinite lease has been granted, no task is needed.
+ */
+ if (lease_time == 0xffffffff)
+ return;
+
+ /*
+ * Find a network interface.
+ */
+ for (ifp = ifnet; (ifp != NULL) && !match; ifp = ifp->if_next)
+ if ((ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) == 0)
+ for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+ if (ifa->ifa_addr->sa_family == AF_INET)
+ {
+ sin = (struct sockaddr_in *) ifa->ifa_addr;
+ if (sin->sin_addr.s_addr == htonl (ip_address))
+ {
+ mtif = ifp;
+ match = 1;
+ break;
+ }
+ }
+
+ if (!match) {
+ printf ("dhcpc: no matching interface\n");
+ return;
+ }
+
+ for (ifa = mtif->if_addrlist; ifa != NULL; ifa = ifa->ifa_next)
+ if (ifa->ifa_addr->sa_family == AF_LINK &&
+ (sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) &&
+ sdl->sdl_type == IFT_ETHER)
+ break;
+
+ if (!match) {
+ printf ("dhcpc: no matching interface address\n");
+ return;
+ }
+
+ /*
+ * Set up given values in a simulated DHCP reply.
+ */
+ memset (&reply, 0x00, sizeof (reply));
+ reply.xid = htonl (xid);
+ reply.yiaddr.s_addr = htonl (ip_address);
+ reply.siaddr.s_addr = htonl (srv_address);
+ if (reply.siaddr.s_addr != rtems_bsdnet_bootp_server_address.s_addr)
+ {
+ memcpy (&rtems_bsdnet_bootp_server_address, &reply.siaddr,
+ sizeof (reply.siaddr));
+ }
+
+ dhcp_lease_time = lease_time;
+ dhcp_elapsed_time = elapsed_time;
+
+ if (hostname)
+ {
+ sethostname ((char *) hostname, strlen (hostname));
+ dhcp_hostname = bootp_strdup_realloc (dhcp_hostname, hostname);
+ }
+
+ dhcp_start_task (sdl, &reply, 150);
+}
diff --git a/cpukit/libnetworking/rtems/rtems_dhcp_failsafe.c b/cpukit/libnetworking/rtems/rtems_dhcp_failsafe.c
new file mode 100644
index 0000000000..609a19eb0a
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_dhcp_failsafe.c
@@ -0,0 +1,372 @@
+/*
+ $Id$
+
+ Description: Wrapper around DHCP client to restart it when the interface
+ moves to another network.
+
+ Authors: Arnout Vandecappelle <arnout@mind.be>, Essensium/Mind
+ Maarten Van Es <maarten@mind.be>, Essensium/Mind
+ (C) Septentrio 2008
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution or at
+ http://www.rtems.com/license/LICENSE.
+
+
+ To use this functionality, call rtems_bsdnet_do_dhcp_failsafe() or set it
+ as the bootp member of the rtems_bsdnet_config structure.
+
+ The rtems_bsdnet_do_dhcp_failsafe() function provides the following
+ functionalities:
+
+ * It starts DHCP on the first non-loopback, non-point-to-point interface.
+ Before DHCP is started, any existing IP address on that interface is
+ removed, as well as the default route.
+
+ * If DHCP fails to acquire an address for whatever reason, the interface
+ is reconfigured with the static address provided in its
+ rtems_bsdnet_ifconfig structure, and the default route from
+ rtems_bsdnet_config is restored.
+ It is possible to change the address in the rtems_bsdnet_ifconfig structure
+ while the system is running.
+
+ * Optionally, after the interface is configured (either with DHCP or
+ statically), a task is started to monitor it. When the interface remains
+ disconnected (i.e. its IFF_RUNNING flag is off) for NETWORK_FAIL_TIMEOUT
+ seconds, the dhcp lease renewal is stopped. As soon as the interface is
+ connected again, DHCP is started again as above.
+ If NETWORK_FAIL_TIMEOUT is set to 0, the monitor task is not started.
+
+ * Optionally, when the interface is disconnected, it is also brought down
+ for NETWORK_DOWN_TIME seconds. Since this possibly makes the IFF_RUNNING
+ flag unuseable, the interface is brought up again before the flag is
+ polled.
+ If NETWORK_DOWN_TIME is set to 0, the interface is not brought down.
+
+ * Optionally, before DHCP is started, we wait for BROADCAST_DELAY seconds.
+ This is necessary to allow some routers to perform spanning tree discovery.
+
+ Note that DHCP doesn't work well with multiple interfaces: only one of them
+ is configured using DHCP, and we can't guarantee it's the same one that is
+ monitored by this function.
+
+*/
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/rtems_bsdnet_internal.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <rtems/dhcp.h>
+
+struct proc; /* Unused parameter of some functions. */
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/route.h>
+#include <netinet/in.h> /* for sockaddr_in */
+#include <net/if.h> /* for if.h */
+#include <net/if_var.h> /* for in_var.h */
+#include <netinet/in_var.h> /* for in_aliasreq */
+#include <sys/sockio.h> /* for ioctl definitions */
+#include <arpa/inet.h> /* for inet_addr, inet_ntop */
+
+
+#define NETWORK_FAIL_TIMEOUT 5 /* the number of seconds before the interface is considered disconnected */
+#define NETWORK_DOWN_TIME 30 /* number of seconds the interface remains down */
+#define BROADCAST_DELAY 0 /* Delay (seconds) before broadcasts are sent */
+#define DHCP_MONITOR_PRIORITY 250 /* Low priority */
+
+/*
+ * returns 0 when successful, negative value for failure
+ */
+static int remove_address(const char *if_name)
+{
+ struct sockaddr_in address;
+ struct in_aliasreq ifra;
+ int retval = 0;
+
+ memset (&address, '\0', sizeof (address));
+ address.sin_len = sizeof (address);
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = INADDR_ANY;
+
+ /* Remove old default route to 0.0.0.0 */
+ if (rtems_bsdnet_rtrequest (RTM_DELETE, (struct sockaddr *)&address, NULL,
+ (struct sockaddr *)&address,
+ (RTF_UP | RTF_STATIC), NULL) < 0 ) {
+ printf ("Failed to delete default route: %s (%d)\n", strerror (errno), errno);
+ retval = -1;
+ }
+
+ /* Remove old ip-address */
+ if (rtems_bsdnet_ifconfig(if_name, SIOCGIFADDR, &address) < 0) {
+ printf ("Failed to get if address: %s (%d)\n", strerror (errno), errno);
+ return -1;
+ }
+
+ strncpy (ifra.ifra_name, if_name, IFNAMSIZ);
+ memcpy (&ifra.ifra_addr, &address, sizeof(address));
+ if (rtems_bsdnet_ifconfig(if_name, SIOCDIFADDR, &ifra)) {
+ printf ("Can't delete if address: %s (%d)\n", strerror (errno), errno);
+ return -1;
+ }
+
+ return retval;
+}
+
+
+#if NETWORK_DOWN_TIME
+static int
+dhcp_if_down (const char* ifname)
+{
+ int flags;
+ if (rtems_bsdnet_ifconfig (ifname, SIOCGIFFLAGS, &flags) < 0) {
+ printf ("Can't get flags for %s: %s\n", ifname, strerror (errno));
+ return -1;
+ }
+ if (flags & IFF_UP) {
+ flags &= ~IFF_UP;
+ if (rtems_bsdnet_ifconfig (ifname, SIOCSIFFLAGS, &flags) < 0) {
+ printf ("Can't bring %s down: %s\n", ifname, strerror (errno));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+#endif
+
+static int
+dhcp_if_up (const char* ifname)
+{
+ int flags;
+ if (rtems_bsdnet_ifconfig (ifname, SIOCGIFFLAGS, &flags) < 0) {
+ printf ("Can't get flags for %s: %s\n", ifname, strerror (errno));
+ return -1;
+ }
+ if (!(flags & IFF_UP)) {
+ flags |= IFF_UP;
+ if (rtems_bsdnet_ifconfig (ifname, SIOCSIFFLAGS, &flags) < 0) {
+ printf ("Can't bring %s up: %s\n", ifname, strerror (errno));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
+static int
+set_static_address (struct rtems_bsdnet_ifconfig *ifp)
+{
+ short flags;
+ struct sockaddr_in address;
+ struct sockaddr_in netmask;
+ struct sockaddr_in broadcast;
+ struct sockaddr_in gateway;
+
+ if (ifp->ip_address != NULL) {
+ printf("Setting static address for interface %s.\n", ifp->name);
+
+ /*
+ * Bring interface up
+ */
+ if (dhcp_if_up (ifp->name) < 0)
+ return -1;
+
+ /*
+ * Set interface netmask
+ */
+ memset (&netmask, '\0', sizeof netmask);
+ netmask.sin_len = sizeof netmask;
+ netmask.sin_family = AF_INET;
+ netmask.sin_addr.s_addr = inet_addr (ifp->ip_netmask);
+ if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFNETMASK, &netmask) < 0) {
+ printf ("Can't set %s netmask: %s\n", ifp->name, strerror (errno));
+ return -1;
+ }
+
+ /*
+ * Set interface address
+ */
+ memset (&address, '\0', sizeof address);
+ address.sin_len = sizeof address;
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = inet_addr (ifp->ip_address);
+ if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFADDR, &address) < 0) {
+ printf ("Can't set %s address: %s\n", ifp->name, strerror (errno));
+ return -1;
+ }
+
+ /*
+ * Set interface broadcast address if the interface has the
+ * broadcast flag set.
+ */
+ if (rtems_bsdnet_ifconfig (ifp->name, SIOCGIFFLAGS, &flags) < 0) {
+ printf ("Can't read %s flags: %s\n", ifp->name, strerror (errno));
+ return -1;
+ }
+ if (flags & IFF_BROADCAST) {
+ memset (&broadcast, '\0', sizeof broadcast);
+ broadcast.sin_len = sizeof broadcast;
+ broadcast.sin_family = AF_INET;
+ broadcast.sin_addr.s_addr = address.sin_addr.s_addr | ~netmask.sin_addr.s_addr;
+
+ if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFBRDADDR, &broadcast) < 0) {
+ struct in_addr in_addr;
+ char buf[20];
+
+ in_addr.s_addr = broadcast.sin_addr.s_addr;
+ if (!inet_ntop (AF_INET, &in_addr, buf, sizeof (buf)))
+ strcpy (buf, "?.?.?.?");
+ printf ("Can't set %s broadcast address %s: %s\n", ifp->name, buf, strerror (errno));
+ }
+ }
+ }
+
+ /*
+ * Set default route
+ */
+ if (rtems_bsdnet_config.gateway) {
+ address.sin_addr.s_addr = INADDR_ANY;
+ netmask.sin_addr.s_addr = INADDR_ANY;
+ memset (&gateway, '\0', sizeof gateway);
+ gateway.sin_len = sizeof gateway;
+ gateway.sin_family = AF_INET;
+ gateway.sin_addr.s_addr = inet_addr (rtems_bsdnet_config.gateway);
+
+ if (rtems_bsdnet_rtrequest (RTM_ADD,
+ (struct sockaddr *) &address,
+ (struct sockaddr *) &gateway,
+ (struct sockaddr *) &netmask,
+ (RTF_UP | RTF_GATEWAY | RTF_STATIC),
+ NULL
+ ) < 0) {
+ printf ("Can't set default route: %s\n", strerror (errno));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static void
+do_dhcp_init (struct rtems_bsdnet_ifconfig *ifp)
+{
+#if BROADCAST_DELAY
+ /* Wait before sending broadcast. */
+ rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(BROADCAST_DELAY * 1000));
+#endif
+
+ printf ("starting dhcp client...\n");
+
+ remove_address(ifp->name);
+ if (rtems_bsdnet_do_dhcp_timeout () != 0) {
+ remove_address(ifp->name);
+ set_static_address (ifp); /* use static ip-address if dhcp failed */
+ }
+
+}
+
+/*
+ * Main dhcp monitor thread
+ */
+static void dhcp_monitor_task (rtems_task_argument ifp_arg)
+{
+ struct rtems_bsdnet_ifconfig *ifp = (struct rtems_bsdnet_ifconfig *)ifp_arg;
+ char *ifname = ifp->name;
+ unsigned int downcount = 0;
+ int ifflags;
+ int must_renew = FALSE;
+
+ while (TRUE) {
+ if (rtems_bsdnet_ifconfig(ifname, SIOCGIFFLAGS, &ifflags) < 0) {
+ printf ("Failed to get if flags: %s (%d)\n", strerror (errno), errno);
+ goto error_out;
+ }
+
+ if ((ifflags & IFF_RUNNING) != 0) {
+ if(must_renew) {
+ must_renew = FALSE;
+ do_dhcp_init(ifp);
+ }
+ downcount = 0;
+ } else {
+ if (downcount < NETWORK_FAIL_TIMEOUT) {
+ downcount++;
+
+ if (downcount == NETWORK_FAIL_TIMEOUT) {
+ printf ("lost network connection...\n");
+ rtems_bsdnet_dhcp_down ();
+ must_renew = TRUE;
+#if NETWORK_DOWN_TIME
+ dhcp_if_down(ifname);
+ rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(NETWORK_DOWN_TIME * 1000));
+ dhcp_if_up(ifname);
+ downcount = 0;
+#endif
+ }
+ }
+ }
+
+ rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(1000));
+ }
+
+error_out:
+ printf("Stopping dhcp monitoring application.\n");
+ rtems_task_delete(RTEMS_SELF);
+}
+
+/*
+* initialize dhcp monitoring application
+* start dhcp monitoring thread
+*/
+void rtems_bsdnet_do_dhcp_failsafe (void)
+{
+ rtems_status_code sc;
+ rtems_id id;
+ struct rtems_bsdnet_ifconfig *ifp;
+ int ifflags;
+
+ /* Find a suitable interface */
+ for (ifp = rtems_bsdnet_config.ifconfig; ifp; ifp = ifp->next) {
+ if (rtems_bsdnet_ifconfig (ifp->name, SIOCGIFFLAGS, &ifflags) < 0)
+ continue;
+ if ((ifflags & (IFF_LOOPBACK | IFF_POINTOPOINT)) == 0)
+ break;
+ }
+ if (ifp == NULL){
+ printf ("dhcpc_failsafe: no suitable interface\n");
+ return;
+ }
+ printf("starting dhcp on interface %s\n", ifp->name);
+ do_dhcp_init(ifp);
+
+#if NETWORK_FAIL_TIMEOUT
+ sc = rtems_task_create (rtems_build_name ('d','h','c','m'),
+ DHCP_MONITOR_PRIORITY,
+ 2048,
+ RTEMS_PREEMPT |
+ RTEMS_NO_TIMESLICE |
+ RTEMS_NO_ASR |
+ RTEMS_INTERRUPT_LEVEL (0),
+ RTEMS_LOCAL,
+ &id);
+
+ if (sc != RTEMS_SUCCESSFUL) {
+ printf ("Failed to create dhcp monitor task, code %d\n", sc);
+ return;
+ }
+
+ sc = rtems_task_start (id, dhcp_monitor_task, (rtems_task_argument) ifp);
+
+ if (sc != RTEMS_SUCCESSFUL) {
+ printf ("Failed to start dhcp monitor task, code %d\n", sc);
+ }
+#endif
+}
+
diff --git a/cpukit/libnetworking/rtems/rtems_dhcp_failsafe.h b/cpukit/libnetworking/rtems/rtems_dhcp_failsafe.h
new file mode 100644
index 0000000000..320f9bf151
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_dhcp_failsafe.h
@@ -0,0 +1,29 @@
+/*
+ $Id$
+
+ Description: Wrapper around DHCP client to restart it when the interface
+ moves to another network.
+
+ Authors: Arnout Vandecappelle <arnout@mind.be>, Essensium/Mind
+ Maarten Van Es <maarten@mind.be>, Essensium/Mind
+ (C) Septentrio 2008
+
+ The license and distribution terms for this file may be
+ found in the file LICENSE in this distribution or at
+ http://www.rtems.com/license/LICENSE.
+*/
+
+#ifndef _RTEMS_DHCP_FAILSAFE_H_
+#define _RTEMS_DHCP_FAILSAFE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void rtems_bsdnet_do_dhcp_failsafe (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
new file mode 100644
index 0000000000..088479cfb8
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_glue.c
@@ -0,0 +1,1310 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define RTEMS_FAST_MUTEX
+
+#ifdef RTEMS_FAST_MUTEX
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/domain.h>
+#include <sys/mbuf.h>
+#include <sys/socketvar.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/callout.h>
+#include <sys/proc.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/route.h>
+#include <netinet/in.h>
+#include <vm/vm.h>
+#include <arpa/inet.h>
+
+#include <net/netisr.h>
+#include <net/route.h>
+
+#include "loop.h"
+
+/*
+ * Sysctl init all.
+ */
+void sysctl_register_all(void *arg);
+
+/*
+ * Memory allocation
+ */
+static uint32_t nmbuf = (64L * 1024L) / MSIZE;
+ uint32_t nmbclusters = (128L * 1024L) / MCLBYTES;
+
+/*
+ * Network task synchronization
+ */
+static rtems_id networkSemaphore;
+#ifdef RTEMS_FAST_MUTEX
+Semaphore_Control *the_networkSemaphore;
+#endif
+static rtems_id networkDaemonTid;
+static uint32_t networkDaemonPriority;
+static void networkDaemon (void *task_argument);
+
+/*
+ * Network timing
+ */
+int rtems_bsdnet_ticks_per_second;
+int rtems_bsdnet_microseconds_per_tick;
+
+/*
+ * Callout processing
+ */
+static rtems_interval ticksWhenCalloutsLastChecked;
+struct callout *callfree = NULL;
+struct callout calltodo;
+
+/*
+ * FreeBSD variables
+ */
+int nfs_diskless_valid;
+
+/*
+ * BOOTP values
+ */
+struct in_addr rtems_bsdnet_log_host_address = {0};
+struct in_addr rtems_bsdnet_bootp_server_address = {0};
+char *rtems_bsdnet_bootp_boot_file_name = 0;
+char *rtems_bsdnet_bootp_server_name = 0;
+char *rtems_bsdnet_domain_name = 0;
+char *rtems_bsdnet_bootp_cmdline = 0;
+static struct in_addr _rtems_bsdnet_nameserver[sizeof rtems_bsdnet_config.name_server /
+ sizeof rtems_bsdnet_config.name_server[0]];
+struct in_addr *rtems_bsdnet_nameserver = _rtems_bsdnet_nameserver;
+int rtems_bsdnet_nameserver_count = 0;
+static struct in_addr _rtems_bsdnet_ntpserver[sizeof rtems_bsdnet_config.ntp_server /
+ sizeof rtems_bsdnet_config.ntp_server[0]];
+struct in_addr *rtems_bsdnet_ntpserver = _rtems_bsdnet_ntpserver;
+int rtems_bsdnet_ntpserver_count = 0;
+int32_t rtems_bsdnet_timeoffset = 0;
+
+static const struct sockaddr_in address_template = {
+ sizeof(address_template),
+ AF_INET,
+ 0,
+ { INADDR_ANY },
+ { 0, 0, 0, 0, 0, 0, 0, 0 }
+};
+
+static void
+rtems_bsdnet_initialize_sockaddr_in(struct sockaddr_in *addr)
+{
+ memcpy(addr, &address_template, sizeof(*addr));
+}
+
+/*
+ * Perform FreeBSD memory allocation.
+ * FIXME: This should be modified to keep memory allocation statistics.
+ */
+#undef malloc
+#undef free
+extern void *malloc (size_t);
+extern void free (void *);
+void *
+rtems_bsdnet_malloc (size_t size, int type, int flags)
+{
+ void *p;
+ int try = 0;
+
+ for (;;) {
+ p = malloc (size);
+ if (p || (flags & M_NOWAIT))
+ return p;
+ rtems_bsdnet_semaphore_release ();
+ if (++try >= 30) {
+ rtems_bsdnet_malloc_starvation();
+ try = 0;
+ }
+ rtems_task_wake_after (rtems_bsdnet_ticks_per_second);
+ rtems_bsdnet_semaphore_obtain ();
+ }
+}
+
+/*
+ * Free FreeBSD memory
+ * FIXME: This should be modified to keep memory allocation statistics.
+ */
+void
+rtems_bsdnet_free (void *addr, int type)
+{
+ free (addr);
+}
+
+/*
+ * Externs for BSD data we have to access during initialization
+ */
+extern struct domain routedomain;
+extern struct domain inetdomain;
+
+/*
+ * Do the initializations required by the BSD code
+ */
+static int
+bsd_init (void)
+{
+ int i;
+ char *p;
+
+ /*
+ * Set up mbuf cluster data strutures
+ */
+ p = rtems_bsdnet_malloc_mbuf ((nmbclusters*MCLBYTES)+MCLBYTES-1, MBUF_MALLOC_NMBCLUSTERS);
+ if (p == NULL) {
+ printf ("Can't get network cluster memory.\n");
+ return -1;
+ }
+ p = (char *)(((intptr_t)p + (MCLBYTES-1)) & ~(MCLBYTES-1));
+ mbutl = (struct mbuf *)p;
+ for (i = 0; i < nmbclusters; i++) {
+ ((union mcluster *)p)->mcl_next = mclfree;
+ mclfree = (union mcluster *)p;
+ p += MCLBYTES;
+ mbstat.m_clfree++;
+ }
+ mbstat.m_clusters = nmbclusters;
+ mclrefcnt = rtems_bsdnet_malloc_mbuf (nmbclusters, MBUF_MALLOC_MCLREFCNT);
+ if (mclrefcnt == NULL) {
+ printf ("Can't get mbuf cluster reference counts memory.\n");
+ return -1;
+ }
+ memset (mclrefcnt, '\0', nmbclusters);
+
+ /*
+ * Set up mbuf data structures
+ */
+
+ p = rtems_bsdnet_malloc_mbuf(nmbuf * MSIZE + MSIZE - 1,MBUF_MALLOC_MBUF);
+ p = (char *)(((uintptr_t)p + MSIZE - 1) & ~(MSIZE - 1));
+ if (p == NULL) {
+ printf ("Can't get network memory.\n");
+ return -1;
+ }
+ for (i = 0; i < nmbuf; i++) {
+ ((struct mbuf *)p)->m_next = mmbfree;
+ mmbfree = (struct mbuf *)p;
+ p += MSIZE;
+ }
+ mbstat.m_mbufs = nmbuf;
+ mbstat.m_mtypes[MT_FREE] = nmbuf;
+
+ /*
+ * Set up domains
+ */
+ {
+
+ routedomain.dom_next = domains;
+ domains = &routedomain;
+ inetdomain.dom_next = domains;
+ domains = &inetdomain;
+ domaininit (NULL);
+ }
+
+ /*
+ * Setup the sysctl, normally done by a SYSINIT call.
+ */
+ sysctl_register_all(0);
+
+ /*
+ * Set up interfaces
+ */
+ ifinit (NULL);
+ return 0;
+}
+
+/*
+ * RTEMS Specific Helper Routines
+ */
+extern void rtems_set_udp_buffer_sizes( u_long, u_long );
+extern void rtems_set_tcp_buffer_sizes( u_long, u_long );
+extern void rtems_set_sb_efficiency( u_long );
+
+/*
+ * Initialize and start network operations
+ */
+static int
+rtems_bsdnet_initialize (void)
+{
+ rtems_status_code sc;
+
+ /*
+ * Set the priority of all network tasks
+ */
+ if (rtems_bsdnet_config.network_task_priority == 0)
+ networkDaemonPriority = 100;
+ else
+ networkDaemonPriority = rtems_bsdnet_config.network_task_priority;
+
+ /*
+ * Set the memory allocation limits
+ */
+ if (rtems_bsdnet_config.mbuf_bytecount)
+ nmbuf = rtems_bsdnet_config.mbuf_bytecount / MSIZE;
+ if (rtems_bsdnet_config.mbuf_cluster_bytecount)
+ nmbclusters = rtems_bsdnet_config.mbuf_cluster_bytecount / MCLBYTES;
+
+ rtems_set_udp_buffer_sizes(
+ rtems_bsdnet_config.udp_tx_buf_size,
+ rtems_bsdnet_config.udp_rx_buf_size
+ );
+
+ rtems_set_tcp_buffer_sizes(
+ rtems_bsdnet_config.tcp_tx_buf_size,
+ rtems_bsdnet_config.tcp_rx_buf_size
+ );
+
+ rtems_set_sb_efficiency( rtems_bsdnet_config.sb_efficiency );
+
+ /*
+ * Create the task-synchronization semaphore
+ */
+ sc = rtems_semaphore_create (rtems_build_name('B', 'S', 'D', 'n'),
+ 0,
+ RTEMS_PRIORITY |
+ RTEMS_BINARY_SEMAPHORE |
+ RTEMS_INHERIT_PRIORITY |
+ RTEMS_NO_PRIORITY_CEILING |
+ RTEMS_LOCAL,
+ 0,
+ &networkSemaphore);
+ if (sc != RTEMS_SUCCESSFUL) {
+ printf ("Can't create network seamphore: `%s'\n", rtems_status_text (sc));
+ return -1;
+ }
+#ifdef RTEMS_FAST_MUTEX
+ {
+ Objects_Locations location;
+ the_networkSemaphore = _Semaphore_Get( networkSemaphore, &location );
+ _Thread_Enable_dispatch();
+ }
+#endif
+
+ /*
+ * Compute clock tick conversion factors
+ */
+ rtems_bsdnet_ticks_per_second = rtems_clock_get_ticks_per_second();
+ if (rtems_bsdnet_ticks_per_second <= 0)
+ rtems_bsdnet_ticks_per_second = 1;
+ rtems_bsdnet_microseconds_per_tick =
+ 1000000 / rtems_bsdnet_ticks_per_second;
+
+ /*
+ * Ensure that `seconds' is greater than 0
+ */
+ while (rtems_bsdnet_seconds_since_boot() == 0)
+ rtems_task_wake_after(1);
+
+ /*
+ * Set up BSD-style sockets
+ */
+ if (bsd_init () < 0)
+ return -1;
+
+ /*
+ * Start network daemon
+ */
+ networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL);
+
+ /*
+ * Let other network tasks begin
+ */
+ rtems_bsdnet_semaphore_release ();
+
+ rtems_bsdnet_initialize_loop();
+
+ return 0;
+}
+
+/*
+ * Obtain network mutex
+ */
+void
+rtems_bsdnet_semaphore_obtain (void)
+{
+#ifdef RTEMS_FAST_MUTEX
+ ISR_Level level;
+ _ISR_Disable (level);
+ _CORE_mutex_Seize (
+ &the_networkSemaphore->Core_control.mutex,
+ networkSemaphore,
+ 1, /* wait */
+ 0, /* forever */
+ level
+ );
+ if (_Thread_Executing->Wait.return_code)
+ rtems_panic ("rtems-net: can't obtain network sema: %d\n",
+ _Thread_Executing->Wait.return_code);
+#else
+ rtems_status_code sc;
+
+ sc = rtems_semaphore_obtain (networkSemaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_panic ("rtems-net: can't obtain network semaphore: `%s'\n",
+ rtems_status_text (sc));
+#endif
+}
+
+/*
+ * Release network mutex
+ */
+void
+rtems_bsdnet_semaphore_release (void)
+{
+#ifdef RTEMS_FAST_MUTEX
+ int i;
+
+ _Thread_Disable_dispatch();
+ i = _CORE_mutex_Surrender (
+ &the_networkSemaphore->Core_control.mutex,
+ networkSemaphore,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+ if (i)
+ rtems_panic ("rtems-net: can't release network sema: %i\n");
+#else
+ rtems_status_code sc;
+
+ sc = rtems_semaphore_release (networkSemaphore);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_panic ("rtems-net: can't release network semaphore: `%s'\n",
+ rtems_status_text (sc));
+#endif
+}
+
+/*
+ * Wait for something to happen to a socket buffer
+ */
+int
+sbwait(struct sockbuf *sb)
+{
+ rtems_event_set events;
+ rtems_id tid;
+ rtems_status_code sc;
+
+ /*
+ * Soak up any pending events.
+ * The sleep/wakeup synchronization in the FreeBSD
+ * kernel has no memory.
+ */
+ rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &events);
+
+ /*
+ * Set this task as the target of the wakeup operation.
+ */
+ rtems_task_ident (RTEMS_SELF, 0, &tid);
+ sb->sb_sel.si_pid = tid;
+
+ /*
+ * Show that socket is waiting
+ */
+ sb->sb_flags |= SB_WAIT;
+
+ /*
+ * Release the network semaphore.
+ */
+ rtems_bsdnet_semaphore_release ();
+
+ /*
+ * Wait for the wakeup event.
+ */
+ sc = rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, sb->sb_timeo, &events);
+
+ /*
+ * Reobtain the network semaphore.
+ */
+ rtems_bsdnet_semaphore_obtain ();
+
+ /*
+ * Return the status of the wait.
+ */
+ switch (sc) {
+ case RTEMS_SUCCESSFUL: return 0;
+ case RTEMS_TIMEOUT: return EWOULDBLOCK;
+ default: return ENXIO;
+ }
+}
+
+
+/*
+ * Wake up the task waiting on a socket buffer.
+ */
+void
+sowakeup(
+ struct socket *so,
+ struct sockbuf *sb)
+{
+ if (sb->sb_flags & SB_WAIT) {
+ sb->sb_flags &= ~SB_WAIT;
+ rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT);
+ }
+ if (sb->sb_wakeup) {
+ (*sb->sb_wakeup) (so, sb->sb_wakeuparg);
+ }
+}
+
+/*
+ * For now, a socket can be used by only one task at a time.
+ */
+int
+sb_lock(struct sockbuf *sb)
+{
+ rtems_panic ("Socket buffer is already in use.");
+ return 0;
+}
+void
+wakeup (void *p)
+{
+ rtems_panic ("Wakeup called");
+}
+
+/*
+ * Wait for a connection/disconnection event.
+ */
+int
+soconnsleep (struct socket *so)
+{
+ rtems_event_set events;
+ rtems_id tid;
+ rtems_status_code sc;
+
+ /*
+ * Soak up any pending events.
+ * The sleep/wakeup synchronization in the FreeBSD
+ * kernel has no memory.
+ */
+ rtems_event_receive (SOSLEEP_EVENT, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &events);
+
+ /*
+ * Set this task as the target of the wakeup operation.
+ */
+ if (so->so_pgid)
+ rtems_panic ("Another task is already sleeping on that socket");
+ rtems_task_ident (RTEMS_SELF, 0, &tid);
+ so->so_pgid = tid;
+
+ /*
+ * Wait for the wakeup event.
+ */
+ sc = rtems_bsdnet_event_receive (SOSLEEP_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, so->so_rcv.sb_timeo, &events);
+
+ /*
+ * Relinquish ownership of the socket.
+ */
+ so->so_pgid = 0;
+
+ switch (sc) {
+ case RTEMS_SUCCESSFUL: return 0;
+ case RTEMS_TIMEOUT: return EWOULDBLOCK;
+ default: return ENXIO;
+ }
+}
+
+/*
+ * Wake up a task waiting for a connection/disconnection to complete.
+ */
+void
+soconnwakeup (struct socket *so)
+{
+ if (so->so_pgid)
+ rtems_event_send (so->so_pgid, SOSLEEP_EVENT);
+}
+
+/*
+ * Send an event to the network daemon.
+ * This corresponds to sending a software interrupt in the BSD kernel.
+ */
+void
+rtems_bsdnet_schednetisr (int n)
+{
+ rtems_event_send (networkDaemonTid, 1 << n);
+}
+
+/*
+ * The network daemon
+ * This provides a context to run BSD software interrupts
+ */
+static void
+networkDaemon (void *task_argument)
+{
+ rtems_status_code sc;
+ rtems_event_set events;
+ rtems_interval now;
+ int ticksPassed;
+ uint32_t timeout;
+ struct callout *c;
+
+ for (;;) {
+ c = calltodo.c_next;
+ if (c)
+ timeout = c->c_time;
+ else
+ timeout = RTEMS_NO_TIMEOUT;
+
+ sc = rtems_bsdnet_event_receive (NETISR_EVENTS,
+ RTEMS_EVENT_ANY | RTEMS_WAIT,
+ timeout,
+ &events);
+ if ( sc == RTEMS_SUCCESSFUL ) {
+ if (events & NETISR_IP_EVENT)
+ ipintr ();
+ if (events & NETISR_ARP_EVENT)
+ arpintr ();
+ }
+
+ now = rtems_clock_get_ticks_since_boot();
+ ticksPassed = now - ticksWhenCalloutsLastChecked;
+ if (ticksPassed != 0) {
+ ticksWhenCalloutsLastChecked = now;
+
+ c = calltodo.c_next;
+ if (c) {
+ c->c_time -= ticksPassed;
+ while ((c = calltodo.c_next) != NULL && c->c_time <= 0) {
+ void *arg;
+ void (*func) (void *);
+
+ func = c->c_func;
+ arg = c->c_arg;
+ calltodo.c_next = c->c_next;
+ c->c_next = callfree;
+ callfree = c;
+ (*func)(arg);
+ }
+ }
+ }
+ }
+}
+
+/*
+ * Structure passed to task-start stub
+ */
+struct newtask {
+ void (*entry)(void *);
+ void *arg;
+};
+
+/*
+ * Task-start stub
+ */
+static void
+taskEntry (rtems_task_argument arg)
+{
+ struct newtask t;
+
+ /*
+ * Pick up task information and free
+ * the memory allocated to pass the
+ * information to this task.
+ */
+ t = *(struct newtask *)arg;
+ free ((struct newtask *)arg);
+
+ /*
+ * Enter the competition for the network semaphore
+ */
+ rtems_bsdnet_semaphore_obtain ();
+
+ /*
+ * Enter the task
+ */
+ (*t.entry)(t.arg);
+ rtems_panic ("Network task returned!\n");
+}
+
+/*
+ * Start a network task
+ */
+rtems_id
+rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg)
+{
+ struct newtask *t;
+ char nm[4];
+ rtems_id tid;
+ rtems_status_code sc;
+
+ strncpy (nm, name, 4);
+ sc = rtems_task_create (rtems_build_name(nm[0], nm[1], nm[2], nm[3]),
+ networkDaemonPriority,
+ stacksize,
+ RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
+ &tid);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_panic ("Can't create network daemon `%s': `%s'\n", name, rtems_status_text (sc));
+
+ /*
+ * Set up task arguments
+ */
+ t = malloc (sizeof *t);
+ t->entry = entry;
+ t->arg = arg;
+
+ /*
+ * Start the task
+ */
+ sc = rtems_task_start (tid, taskEntry, (rtems_task_argument)t);
+ if (sc != RTEMS_SUCCESSFUL)
+ rtems_panic ("Can't start network daemon `%s': `%s'\n", name, rtems_status_text (sc));
+
+ /*
+ * Let our caller know the i.d. of the new task
+ */
+ return tid;
+}
+
+rtems_status_code rtems_bsdnet_event_receive (
+ rtems_event_set event_in,
+ rtems_option option_set,
+ rtems_interval ticks,
+ rtems_event_set *event_out)
+{
+ rtems_status_code sc;
+
+ rtems_bsdnet_semaphore_release ();
+ sc = rtems_event_receive (event_in, option_set, ticks, event_out);
+ rtems_bsdnet_semaphore_obtain ();
+ return sc;
+}
+
+/*
+ * Return time since startup
+ */
+void
+microtime (struct timeval *t)
+{
+ rtems_interval now;
+
+ now = rtems_clock_get_ticks_since_boot();
+ t->tv_sec = now / rtems_bsdnet_ticks_per_second;
+ t->tv_usec = (now % rtems_bsdnet_ticks_per_second) * rtems_bsdnet_microseconds_per_tick;
+}
+
+unsigned long
+rtems_bsdnet_seconds_since_boot (void)
+{
+ rtems_interval now;
+
+ now = rtems_clock_get_ticks_since_boot();
+ return now / rtems_bsdnet_ticks_per_second;
+}
+
+/*
+ * Fake random number generator
+ */
+unsigned long
+rtems_bsdnet_random (void)
+{
+ rtems_interval now;
+
+ now = rtems_clock_get_ticks_since_boot();
+ return (now * 99991);
+}
+
+/*
+ * Callout list processing
+ */
+void
+rtems_bsdnet_timeout(void (*ftn)(void *), void *arg, int ticks)
+{
+ register struct callout *new, *p, *t;
+
+ if (ticks <= 0)
+ ticks = 1;
+
+ /* Fill in the next free callout structure. */
+ if (callfree == NULL) {
+ callfree = malloc (sizeof *callfree);
+ if (callfree == NULL)
+ rtems_panic ("No memory for timeout table entry");
+ callfree->c_next = NULL;
+ }
+
+ new = callfree;
+ callfree = new->c_next;
+ new->c_arg = arg;
+ new->c_func = ftn;
+
+ /*
+ * The time for each event is stored as a difference from the time
+ * of the previous event on the queue. Walk the queue, correcting
+ * the ticks argument for queue entries passed. Correct the ticks
+ * value for the queue entry immediately after the insertion point
+ * as well. Watch out for negative c_time values; these represent
+ * overdue events.
+ */
+ for (p = &calltodo;
+ (t = p->c_next) != NULL && ticks > t->c_time; p = t)
+ if (t->c_time > 0)
+ ticks -= t->c_time;
+ new->c_time = ticks;
+ if (t != NULL)
+ t->c_time -= ticks;
+
+ /* Insert the new entry into the queue. */
+ p->c_next = new;
+ new->c_next = t;
+}
+
+/*
+ * Ticks till specified time
+ * XXX: This version worries only about seconds, but that's good
+ * enough for the way the network code uses this routine.
+ */
+int
+hzto(struct timeval *tv)
+{
+ long diff = tv->tv_sec - rtems_bsdnet_seconds_since_boot();
+
+ if (diff <= 0)
+ return 1;
+ return diff * rtems_bsdnet_ticks_per_second;
+}
+
+/*
+ * Kernel debugging
+ */
+int rtems_bsdnet_log_priority;
+void
+rtems_bsdnet_log (int priority, const char *fmt, ...)
+{
+ va_list args;
+
+ if (priority & rtems_bsdnet_log_priority) {
+ va_start (args, fmt);
+ vprintf (fmt, args);
+ va_end (args);
+ }
+}
+
+/*
+ * IP header checksum routine for processors which don't have an inline version
+ */
+u_int
+in_cksum_hdr (const void *ip)
+{
+ uint32_t sum;
+ const uint16_t *sp;
+ int i;
+
+ sum = 0;
+ sp = (uint16_t *)ip;
+ for (i = 0 ; i < 10 ; i++)
+ sum += *sp++;
+ while (sum > 0xFFFF)
+ sum = (sum & 0xffff) + (sum >> 16);
+ return ~sum & 0xFFFF;
+}
+
+/*
+ * Manipulate routing tables
+ */
+int rtems_bsdnet_rtrequest (
+ int req,
+ struct sockaddr *dst,
+ struct sockaddr *gateway,
+ struct sockaddr *netmask,
+ int flags,
+ struct rtentry **net_nrt)
+{
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ error = rtrequest (req, dst, gateway, netmask, flags, net_nrt);
+ rtems_bsdnet_semaphore_release ();
+ if (error) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+static bool
+rtems_bsdnet_setup_interface(
+ const char *name,
+ const char *ip_address,
+ const char *ip_netmask
+)
+{
+ struct sockaddr_in address;
+ struct sockaddr_in netmask;
+ short flags;
+
+ /*
+ * Bring interface up
+ */
+ flags = IFF_UP;
+ if (rtems_bsdnet_ifconfig (name, SIOCSIFFLAGS, &flags) < 0) {
+ printf ("Can't bring %s up: %s\n", name, strerror (errno));
+ return false;
+ }
+
+ /*
+ * Set interface netmask
+ */
+ rtems_bsdnet_initialize_sockaddr_in(&netmask);
+ netmask.sin_addr.s_addr = inet_addr (ip_netmask);
+ if (rtems_bsdnet_ifconfig (name, SIOCSIFNETMASK, &netmask) < 0) {
+ printf ("Can't set %s netmask: %s\n", name, strerror (errno));
+ return false;
+ }
+
+ /*
+ * Set interface address
+ */
+ rtems_bsdnet_initialize_sockaddr_in(&address);
+ address.sin_addr.s_addr = inet_addr (ip_address);
+ if (rtems_bsdnet_ifconfig (name, SIOCSIFADDR, &address) < 0) {
+ printf ("Can't set %s address: %s\n", name, strerror (errno));
+ return false;
+ }
+
+ /*
+ * Set interface broadcast address if the interface has the
+ * broadcast flag set.
+ */
+ if (rtems_bsdnet_ifconfig (name, SIOCGIFFLAGS, &flags) < 0) {
+ printf ("Can't read %s flags: %s\n", name, strerror (errno));
+ return false;
+ }
+
+ if (flags & IFF_BROADCAST) {
+ struct sockaddr_in broadcast;
+
+ rtems_bsdnet_initialize_sockaddr_in(&broadcast);
+ broadcast.sin_addr.s_addr =
+ address.sin_addr.s_addr | ~netmask.sin_addr.s_addr;
+ if (rtems_bsdnet_ifconfig (name, SIOCSIFBRDADDR, &broadcast) < 0) {
+ struct in_addr in_addr;
+ char buf[20];
+ in_addr.s_addr = broadcast.sin_addr.s_addr;
+ if (!inet_ntop(AF_INET, &in_addr, buf, sizeof(buf)))
+ strcpy(buf,"?.?.?.?");
+ printf ("Can't set %s broadcast address %s: %s\n",
+ name, buf, strerror (errno));
+ }
+ }
+
+ return true;
+}
+
+static int
+rtems_bsdnet_setup (void)
+{
+ struct rtems_bsdnet_ifconfig *ifp;
+ int i;
+ bool any_if_configured = false;
+
+ /*
+ * Set local parameters
+ */
+ if (rtems_bsdnet_config.hostname)
+ sethostname (rtems_bsdnet_config.hostname,
+ strlen (rtems_bsdnet_config.hostname));
+ if (rtems_bsdnet_config.domainname)
+ rtems_bsdnet_domain_name =
+ strdup (rtems_bsdnet_config.domainname);
+ if (rtems_bsdnet_config.log_host)
+ rtems_bsdnet_log_host_address.s_addr =
+ inet_addr (rtems_bsdnet_config.log_host);
+ for (i = 0 ; i < sizeof rtems_bsdnet_config.name_server /
+ sizeof rtems_bsdnet_config.name_server[0] ; i++) {
+ if (!rtems_bsdnet_config.name_server[i])
+ break;
+ rtems_bsdnet_nameserver[rtems_bsdnet_nameserver_count++].s_addr
+ = inet_addr (rtems_bsdnet_config.name_server[i]);
+ }
+ for (i = 0 ; i < sizeof rtems_bsdnet_config.ntp_server /
+ sizeof rtems_bsdnet_config.ntp_server[0] ; i++) {
+ if (!rtems_bsdnet_config.ntp_server[i])
+ break;
+ rtems_bsdnet_ntpserver[rtems_bsdnet_ntpserver_count++].s_addr
+ = inet_addr (rtems_bsdnet_config.ntp_server[i]);
+ }
+
+ /*
+ * Configure interfaces
+ */
+ any_if_configured |= rtems_bsdnet_setup_interface(
+ "lo0",
+ "127.0.0.1",
+ "255.0.0.0"
+ );
+ for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) {
+ if (ifp->ip_address == NULL)
+ continue;
+
+ any_if_configured |= rtems_bsdnet_setup_interface(
+ ifp->name,
+ ifp->ip_address,
+ ifp->ip_netmask
+ );
+ }
+
+ /*
+ * Set default route
+ */
+ if (rtems_bsdnet_config.gateway && any_if_configured) {
+ struct sockaddr_in address;
+ struct sockaddr_in netmask;
+ struct sockaddr_in gateway;
+
+ rtems_bsdnet_initialize_sockaddr_in(&address);
+ rtems_bsdnet_initialize_sockaddr_in(&netmask);
+ rtems_bsdnet_initialize_sockaddr_in(&gateway);
+
+ gateway.sin_addr.s_addr = inet_addr (rtems_bsdnet_config.gateway);
+
+ if (rtems_bsdnet_rtrequest (
+ RTM_ADD,
+ (struct sockaddr *)&address,
+ (struct sockaddr *)&gateway,
+ (struct sockaddr *)&netmask,
+ (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL) < 0) {
+ printf ("Can't set default route: %s\n", strerror (errno));
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Initialize the network
+ */
+int
+rtems_bsdnet_initialize_network(void)
+{
+ struct rtems_bsdnet_ifconfig *ifp;
+
+ /*
+ * Start network tasks.
+ * Initialize BSD network data structures.
+ */
+ if (rtems_bsdnet_initialize () < 0)
+ return -1;
+
+ /*
+ * Attach interfaces
+ */
+ for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) {
+ rtems_bsdnet_attach (ifp);
+ }
+
+ /*
+ * Bring up the network
+ */
+ if (rtems_bsdnet_setup () < 0)
+ return -1;
+ if (rtems_bsdnet_config.bootp)
+ (*rtems_bsdnet_config.bootp)();
+ return 0;
+}
+
+/*
+ * Attach a network interface.
+ */
+void rtems_bsdnet_attach(struct rtems_bsdnet_ifconfig *ifp)
+{
+ if (ifp) {
+ rtems_bsdnet_semaphore_obtain ();
+ (ifp->attach)(ifp, 1);
+ rtems_bsdnet_semaphore_release ();
+ }
+}
+
+/*
+ * Detach a network interface.
+ */
+void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifp)
+{
+ if (ifp) {
+ rtems_bsdnet_semaphore_obtain ();
+ (ifp->attach)(ifp, 0);
+ rtems_bsdnet_semaphore_release ();
+ }
+}
+
+/*
+ * Interface Configuration.
+ */
+int rtems_bsdnet_ifconfig(const char *ifname, uint32_t cmd, void *param)
+{
+ int s, r = 0;
+ struct ifreq ifreq;
+
+ /*
+ * Configure interfaces
+ */
+ s = socket (AF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -1;
+
+ strncpy (ifreq.ifr_name, ifname, IFNAMSIZ);
+
+ rtems_bsdnet_semaphore_obtain ();
+
+ switch (cmd) {
+ case SIOCSIFADDR:
+ case SIOCSIFNETMASK:
+ memcpy (&ifreq.ifr_addr, param, sizeof (struct sockaddr));
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case OSIOCGIFADDR:
+ case SIOCGIFADDR:
+ case OSIOCGIFNETMASK:
+ case SIOCGIFNETMASK:
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ memcpy (param, &ifreq.ifr_addr, sizeof (struct sockaddr));
+ break;
+
+ case SIOCGIFFLAGS:
+ case SIOCSIFFLAGS:
+ if ((r = ioctl (s, SIOCGIFFLAGS, &ifreq)) < 0)
+ break;
+ if (cmd == SIOCGIFFLAGS) {
+ *((short*) param) = ifreq.ifr_flags;
+ break;
+ }
+ ifreq.ifr_flags |= *((short*) param);
+ if ( (*((short*) param) & IFF_UP ) == 0 ) {
+ /* set the interface down */
+ ifreq.ifr_flags &= ~(IFF_UP);
+ }
+ r = ioctl (s, SIOCSIFFLAGS, &ifreq);
+ break;
+
+ case SIOCSIFDSTADDR:
+ memcpy (&ifreq.ifr_dstaddr, param, sizeof (struct sockaddr));
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case OSIOCGIFDSTADDR:
+ case SIOCGIFDSTADDR:
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ memcpy (param, &ifreq.ifr_dstaddr, sizeof (struct sockaddr));
+ break;
+
+ case SIOCSIFBRDADDR:
+ memcpy (&ifreq.ifr_broadaddr, param, sizeof (struct sockaddr));
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case OSIOCGIFBRDADDR:
+ case SIOCGIFBRDADDR:
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ memcpy (param, &ifreq.ifr_broadaddr, sizeof (struct sockaddr));
+ break;
+
+ case SIOCSIFMETRIC:
+ ifreq.ifr_metric = *((int*) param);
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case SIOCGIFMETRIC:
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ *((int*) param) = ifreq.ifr_metric;
+ break;
+
+ case SIOCSIFMTU:
+ ifreq.ifr_mtu = *((int*) param);
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case SIOCGIFMTU:
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ *((int*) param) = ifreq.ifr_mtu;
+ break;
+
+ case SIOCSIFPHYS:
+ ifreq.ifr_phys = *((int*) param);
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case SIOCGIFPHYS:
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ *((int*) param) = ifreq.ifr_phys;
+ break;
+
+ case SIOCSIFMEDIA:
+ ifreq.ifr_media = *((int*) param);
+ r = ioctl (s, cmd, &ifreq);
+ break;
+
+ case SIOCGIFMEDIA:
+ /* 'param' passes the phy index they want to
+ * look at...
+ */
+ ifreq.ifr_media = *((int*) param);
+ if ((r = ioctl (s, cmd, &ifreq)) < 0)
+ break;
+ *((int*) param) = ifreq.ifr_media;
+ break;
+
+ case SIOCAIFADDR:
+ case SIOCDIFADDR:
+ r = ioctl(s, cmd, (struct ifreq *) param);
+ break;
+
+ default:
+ errno = EOPNOTSUPP;
+ r = -1;
+ break;
+ }
+
+ rtems_bsdnet_semaphore_release ();
+
+ close (s);
+ return r;
+}
+
+/**
+ * @brief Splits a network interface name with interface configuration @a
+ * config into the unit name and number parts.
+ *
+ * Memory for the unit name will be allocated from the heap and copied to @a
+ * namep. If @a namep is NULL nothing will be allocated and copied.
+ *
+ * Returns the unit number or -1 on error.
+ */
+int
+rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
+{
+ const char *cp = config->name;
+ char c;
+ int unitNumber = 0;
+
+ if (cp == NULL) {
+ printf ("No network driver name.\n");
+ return -1;
+ }
+ while ((c = *cp++) != '\0') {
+ if ((c >= '0') && (c <= '9')) {
+ int len = cp - config->name;
+ if ((len < 2) || (len > 50))
+ break;
+ for (;;) {
+ unitNumber = (unitNumber * 10) + (c - '0');
+ c = *cp++;
+ if (c == '\0') {
+ if (namep != NULL) {
+ char *unitName = malloc (len);
+ if (unitName == NULL) {
+ printf ("No memory.\n");
+ return -1;
+ }
+ strncpy (unitName, config->name, len - 1);
+ unitName[len-1] = '\0';
+ *namep = unitName;
+ }
+ return unitNumber;
+ }
+ if ((c < '0') || (c > '9'))
+ break;
+ }
+ break;
+ }
+ }
+ printf ("Bad network driver name `%s'.\n", config->name);
+ return -1;
+}
+
+/*
+ * Handle requests for more network memory
+ * XXX: Another possibility would be to use a semaphore here with
+ * a release in the mbuf free macro. I have chosen this `polling'
+ * approach because:
+ * 1) It is simpler.
+ * 2) It adds no complexity to the free macro.
+ * 3) Running out of mbufs should be a rare
+ * condition -- predeployment testing of
+ * an application should indicate the
+ * required mbuf pool size.
+ * XXX: Should there be a panic if a task is stuck in the loop for
+ * more than a minute or so?
+ */
+int
+m_mballoc(int nmb, int nowait)
+{
+ if (nowait)
+ return 0;
+ m_reclaim ();
+ if (mmbfree == NULL) {
+ int try = 0;
+ int print_limit = 30 * rtems_bsdnet_ticks_per_second;
+
+ mbstat.m_wait++;
+ for (;;) {
+ rtems_bsdnet_semaphore_release ();
+ rtems_task_wake_after (1);
+ rtems_bsdnet_semaphore_obtain ();
+ if (mmbfree)
+ break;
+ if (++try >= print_limit) {
+ printf ("Still waiting for mbuf.\n");
+ try = 0;
+ }
+ }
+ }
+ else {
+ mbstat.m_drops++;
+ }
+ return 1;
+}
+
+int
+m_clalloc(int ncl, int nowait)
+{
+ if (nowait)
+ return 0;
+ m_reclaim ();
+ if (mclfree == NULL) {
+ int try = 0;
+ int print_limit = 30 * rtems_bsdnet_ticks_per_second;
+
+ mbstat.m_wait++;
+ for (;;) {
+ rtems_bsdnet_semaphore_release ();
+ rtems_task_wake_after (1);
+ rtems_bsdnet_semaphore_obtain ();
+ if (mclfree)
+ break;
+ if (++try >= print_limit) {
+ printf ("Still waiting for mbuf cluster.\n");
+ try = 0;
+ }
+ }
+ }
+ else {
+ mbstat.m_drops++;
+ }
+ return 1;
+}
diff --git a/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c b/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c
new file mode 100644
index 0000000000..a2bd34a4c4
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define RTEMS_FAST_MUTEX
+
+#ifdef RTEMS_FAST_MUTEX
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+
+/*
+ * We want to use the REAL system malloc. Do not let the BSD malloc macro
+ * invade this file.
+ */
+extern void *malloc(size_t);
+
+/*
+ * Default allocator for mbuf data. Over-ride in user code to change
+ * the way mbuf's are allocated.
+ */
+
+void* rtems_bsdnet_malloc_mbuf(size_t size, int type)
+{
+ return malloc(size);
+}
+
+
diff --git a/cpukit/libnetworking/rtems/rtems_mii_ioctl.c b/cpukit/libnetworking/rtems/rtems_mii_ioctl.c
new file mode 100644
index 0000000000..93e9a0d580
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_mii_ioctl.c
@@ -0,0 +1,172 @@
+/* $Id$ */
+
+/* Simple (default) implementation for SIOCGIFMEDIA/SIOCSIFMEDIA
+ * to be used by ethernet drivers [from their ioctl].
+ *
+ * USERSPACE UTILITIES
+ *
+ * NOTE: This much simpler than the BSD ifmedia API
+ */
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2005,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#include <rtems.h>
+#include <inttypes.h>
+
+#undef _KERNEL
+
+#include <rtems/rtems_mii_ioctl.h>
+
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+static struct ifmedia_description shared_media_strings[] =
+ IFM_SUBTYPE_SHARED_DESCRIPTIONS;
+static struct ifmedia_description ethern_media_strings[] =
+ IFM_SUBTYPE_ETHERNET_DESCRIPTIONS;
+static struct ifmedia_description eth_al_media_strings[] =
+ IFM_SUBTYPE_ETHERNET_ALIASES;
+
+static const char *
+find_desc (int tag, struct ifmedia_description *list)
+{
+ while (list->ifmt_string && tag != list->ifmt_word)
+ list++;
+ return list->ifmt_string;
+}
+
+#define WHATPRINT(buf,sz,fmt...) \
+ ( (sz) > 0 ? snprintf((buf),(sz),fmt) : fprintf((buf) ? (FILE*)(buf) : stdout, fmt) )
+
+int
+rtems_ifmedia2str (int media, char *buf, int bufsz)
+{
+ const char *mdesc;
+ const char *dupdesc = 0;
+
+ /* only ethernet supported, so far */
+ if (IFM_ETHER != IFM_TYPE (media))
+ return -1;
+
+ if (!(mdesc = find_desc (IFM_SUBTYPE (media), shared_media_strings)))
+ mdesc = find_desc (IFM_SUBTYPE (media), ethern_media_strings);
+
+ if (!mdesc)
+ return -1;
+
+ if (IFM_NONE != IFM_SUBTYPE (media))
+ dupdesc = IFM_FDX & media ? " full-duplex" : " half-duplex";
+
+ return WHATPRINT (buf, bufsz,
+ "Ethernet [phy instance: %" PRId32 "]: (link %s, autoneg %s) -- media: %s%s",
+ (int32_t) IFM_INST (media),
+ IFM_LINK_OK & media ? "ok" : "down",
+ IFM_ANEG_DIS & media ? "off" : "on",
+ mdesc, dupdesc ? dupdesc : "");
+}
+
+static int
+find_tag (const char *desc, struct ifmedia_description *list)
+{
+ while (list->ifmt_string) {
+ if (strstr (desc, list->ifmt_string))
+ return list->ifmt_word;
+ list++;
+ }
+ return -1;
+}
+
+
+/* convert a string to a media word
+ * RETURNS: 0 on failure; valid results have always at least IFM_ETHER set
+ */
+int
+rtems_str2ifmedia (const char *str, int phy)
+{
+ int sub, opt = 0;
+ char *chpt;
+
+ if (!strncmp (str, "auto", 4)) {
+ sub = IFM_AUTO;
+ } else if ((sub = find_tag (str, ethern_media_strings)) < 0) {
+ if ((sub = find_tag (str, eth_al_media_strings)) < 0) {
+ /* allow more */
+
+ /* if no number, 0 is returned which will not pass the test */
+ switch (strtol (str, &chpt, 10)) {
+ case 10:
+ sub = IFM_10_T;
+ break;
+ case 100:
+ sub = IFM_100_TX;
+ break;
+ case 1000:
+ sub = IFM_1000_T;
+ break;
+ default:
+ return 0;
+ }
+
+ /* need 'b' or 'base' */
+ if ('b' != *chpt++)
+ return 0;
+ if (!strncmp (chpt, "ase", 3))
+ chpt += 3;
+ if (toupper ((unsigned char)*chpt++) != 'T')
+ return 0;
+ if (IFM_100_TX == sub && toupper ((unsigned char)*chpt++) != 'X')
+ return 0;
+ }
+ }
+
+ if (strstr (str, "full") || strstr (str, "FDX") || strstr (str, "fdx"))
+ opt |= IFM_FDX;
+
+ return IFM_MAKEWORD (IFM_ETHER, sub, opt, phy);
+}
diff --git a/cpukit/libnetworking/rtems/rtems_mii_ioctl.h b/cpukit/libnetworking/rtems/rtems_mii_ioctl.h
new file mode 100644
index 0000000000..160de34e92
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_mii_ioctl.h
@@ -0,0 +1,141 @@
+/* Simple (default) implementation for SIOCGIFMEDIA/SIOCSIFMEDIA
+ * to be used by ethernet drivers [from their ioctl].
+ *
+ * NOTE: This much simpler than the BSD ifmedia API
+ *
+ * $Id$
+ */
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2005,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+#ifndef RTEMS_MII_IOCTL_H
+#define RTEMS_MII_IOCTL_H
+
+#include <dev/mii/mii.h> /* MII register definitions */
+#include <net/if_media.h> /* media word definitions; rest of API (ifmedia) unused! */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_KERNEL) || defined(KERNEL) || \
+ defined(__KERNEL) || defined(__KERNEL__)
+/* mdio routines to be provided by driver */
+
+/* read mii register 'reg' at 'phy' (-1 meaning any/currently active)
+ * RETURNS 0 on success, -1 otherwise (e.g., illegal phy)
+ */
+typedef int (*rtems_mdio_read_func) (int phy, void *uarg, unsigned reg,
+ uint32_t * pval);
+
+/* write mii register 'reg' at 'phy' (-1 meaning any/currently active)
+ * RETURNS 0 on success, -1 otherwise (e.g., illegal phy)
+ */
+typedef int (*rtems_mdio_write_func) (int phy, void *uarg, unsigned reg,
+ uint32_t val);
+
+/* Values to this must be provided by the driver */
+struct rtems_mdio_info {
+ rtems_mdio_read_func mdio_r;
+ rtems_mdio_write_func mdio_w;
+ unsigned has_gmii:1; /* supports gigabit */
+};
+
+/* Implement SIOCSIFMEDIA/SIOCGIFMEDIA; get/set the current media word. Note
+ * that this does NOT implement the full BSD 'ifmedia' API; also, it only
+ * implements IFM_ETHER...
+ *
+ * INPUT:
+ * SIOCGIFMEDIA: the media word must set the phy instance (-1 for 'any')
+ *
+ */
+int
+rtems_mii_ioctl (struct rtems_mdio_info *info, void *uarg, uint32_t cmd,
+ int *media);
+
+#endif
+
+/* The driver flags have the following meaning (SIOCGIFMEDIA only):
+ */
+#define IFM_LINK_OK IFM_FLAG0
+#define IFM_ANEG_DIS IFM_FLAG1 /* autoneg. disabled; media forced */
+
+/* convert a media word to a string;
+ *
+ * RETURNS: number of characters written to 'buf'
+ *
+ * INPUT: if 'bufsz' is set to IFMEDIA2STR_PRINT_TO_FILE, 'buf' can be a FILE
+ * pointer where the info is printed insted. This can be NULL in which
+ * case 'stdout' is used.
+ */
+
+#define IFMEDIA2STR_PRINT_TO_FILE 0
+
+int rtems_ifmedia2str (int media, char *buf, int bufsz);
+
+/* convert a string to a media word
+ * RETURNS: 0 on failure (unrecognized or invalid mode);
+ * valid results have always at least IFM_ETHER set.
+ *
+ * In addition to IFM_SUBTYPE_ETHERNET_DESCRIPTIONS and
+ * IFM_SUBTYPE_ETHERNET_ALIASES, the strings
+ *
+ * '10' [ '0' [ '0' ]] 'b' [ 'ase' ] ( 't' | 'T' )
+ * (* if 100bT [ 'x' | 'X' ] is required here *)
+ *
+ * are recognized (e.g., 10bT, 100bTX)
+ *
+ * if any of the strings 'full' or 'FDX' or 'fdx' is present, a full-duplex mode
+ * is selected (half-duplex otherwise).
+ * e.g., '100bTx-full'
+ */
+
+int rtems_str2ifmedia (const char *str, int phy);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/rtems/rtems_mii_ioctl_kern.c b/cpukit/libnetworking/rtems/rtems_mii_ioctl_kern.c
new file mode 100644
index 0000000000..c43f0d077b
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_mii_ioctl_kern.c
@@ -0,0 +1,259 @@
+/* $Id$ */
+
+/* Simple (default) implementation for SIOCGIFMEDIA/SIOCSIFMEDIA
+ * to be used by ethernet drivers [from their ioctl].
+ *
+ * KERNEL PART (support for drivers)
+ *
+ * NOTE: This much simpler than the BSD ifmedia API
+ */
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2005,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+/* include first to avoid 'malloc' clash with rtems_bsdnet_malloc() hack */
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+
+#ifndef __KERNEL__
+#define __KERNEL__
+#endif
+
+#include <rtems/rtems_mii_ioctl.h>
+
+#include <errno.h>
+
+
+#define DEBUG
+
+
+#ifndef MII_1000TCR
+#define MII_1000TCR MII_100T2CR
+#endif
+
+#ifndef MII_1000TSR
+#define MII_1000TSR MII_100T2SR
+#endif
+
+int
+rtems_mii_ioctl (struct rtems_mdio_info *info, void *uarg, uint32_t cmd,
+ int *media)
+{
+ uint32_t bmcr, bmsr, aner, bmcr2 = 0, bmsr2 = 0, anar, lpar;
+ int phy = IFM_INST (*media);
+ uint32_t tmp;
+ int subtype = 0, options = 0;
+
+ switch (cmd) {
+ default:
+ return EINVAL;
+
+#ifdef DEBUG
+ case 0:
+#endif
+ case SIOCGIFMEDIA:
+ if (info->mdio_r (phy, uarg, MII_BMCR, &bmcr))
+ return EINVAL;
+ /* read BMSR twice to clear latched link status low */
+ if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr))
+ return EINVAL;
+ if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr))
+ return EINVAL;
+ if (info->mdio_r (phy, uarg, MII_ANER, &aner))
+ return EINVAL;
+ if (info->has_gmii) {
+ if (info->mdio_r (phy, uarg, MII_1000TCR, &bmcr2))
+ return EINVAL;
+ if (info->mdio_r (phy, uarg, MII_1000TSR, &bmsr2))
+ return EINVAL;
+ }
+
+ /* link status */
+ if (BMSR_LINK & bmsr)
+ options |= IFM_LINK_OK;
+
+ /* do we have autonegotiation disabled ? */
+ if (!(BMCR_AUTOEN & bmcr)) {
+ options |= IFM_ANEG_DIS;
+
+ /* duplex is enforced */
+ options |= BMCR_FDX & bmcr ? IFM_FDX : IFM_HDX;
+
+ /* determine speed */
+ switch (BMCR_SPEED (bmcr)) {
+ case BMCR_S10:
+ subtype = IFM_10_T;
+ break;
+ case BMCR_S100:
+ subtype = IFM_100_TX;
+ break;
+ case BMCR_S1000:
+ subtype = IFM_1000_T;
+ break;
+ default:
+ return ENOTSUP; /* ?? */
+ }
+ } else if (!(BMSR_LINK & bmsr) || !(BMSR_ACOMP & bmsr)) {
+ subtype = IFM_NONE;
+ } else {
+ /* everything ok on our side */
+
+ if ( ! (ANER_LPAN & aner) ) {
+ /* Link partner doesn't autonegotiate --> our settings are the
+ * result of 'parallel detect' (in particular: duplex status is HALF
+ * according to the standard!).
+ * Let them know that something's fishy...
+ */
+ options |= IFM_ANEG_DIS;
+ }
+
+ tmp = ((bmcr2 << 2) & bmsr2) & (GTSR_LP_1000THDX | GTSR_LP_1000TFDX);
+ if (tmp) {
+ if (GTSR_LP_1000TFDX & tmp)
+ options |= IFM_FDX;
+ subtype = IFM_1000_T;
+ } else {
+ if (info->mdio_r (phy, uarg, MII_ANAR, &anar))
+ return EINVAL;
+ if (info->mdio_r (phy, uarg, MII_ANLPAR, &lpar))
+ return EINVAL;
+ if (ANLPAR_ACK & lpar) {
+ /* this is a negotiated link; otherwise we merely detect the partner's ability */
+ }
+ tmp = anar & lpar;
+ if (ANLPAR_TX_FD & tmp) {
+ options |= IFM_FDX;
+ subtype = IFM_100_TX;
+ } else if (ANLPAR_T4 & tmp) {
+ subtype = IFM_100_T4;
+ } else if (ANLPAR_TX & tmp) {
+ subtype = IFM_100_TX;
+ } else if (ANLPAR_10_FD & tmp) {
+ options |= IFM_FDX;
+ subtype = IFM_10_T;
+ } else {
+ subtype = IFM_10_T;
+ }
+ }
+ }
+
+ *media = IFM_MAKEWORD (IFM_ETHER, subtype, options, phy);
+
+ break;
+
+#ifdef DEBUG
+ case 1:
+#endif
+ case SIOCSIFMEDIA:
+ if (IFM_ETHER != IFM_TYPE (*media))
+ return EINVAL;
+
+ if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr))
+ return EINVAL;
+
+ tmp = (IFM_FDX & *media);
+
+ switch (IFM_SUBTYPE (*media)) {
+ default:
+ return ENOTSUP;
+
+ case IFM_AUTO:
+ bmcr = BMCR_AUTOEN | BMCR_STARTNEG;
+ tmp = 0;
+ break;
+
+ case IFM_1000_T:
+ if (!info->has_gmii)
+ return ENOTSUP;
+
+ if (info->mdio_r (phy, uarg, MII_EXTSR, &bmsr2))
+ return EINVAL;
+
+ if (!(bmsr2 & (tmp ? EXTSR_1000TFDX : EXTSR_1000THDX)))
+ return EOPNOTSUPP;
+
+ /* NOTE: gige standard demands auto-negotiation for gige links.
+ * Disabling autoneg did NOT work on the PHYs I tried
+ * (BCM5421S, intel 82540).
+ * I've seen drivers that simply change what they advertise
+ * to the desired gig mode and re-negotiate.
+ * We could do that here, too, but we don't see the point -
+ * If autoneg works fine then we can as well use it.
+ */
+ bmcr = BMCR_S1000;
+ break;
+
+ case IFM_100_TX:
+ if (!(bmsr & (tmp ? BMSR_100TXFDX : BMSR_100TXHDX)))
+ return EOPNOTSUPP;
+ bmcr = BMCR_S100;
+ break;
+
+ case IFM_10_T:
+ if (!(bmsr & (tmp ? BMSR_10TFDX : BMSR_10THDX)))
+ return EOPNOTSUPP;
+ bmcr = BMCR_S10;
+ break;
+ }
+
+ if (tmp)
+ bmcr |= BMCR_FDX;
+
+ if (info->mdio_w (phy, uarg, MII_BMCR, bmcr))
+ return EINVAL;
+
+ /* TODO: should we adapt advertised capabilites ? */
+
+ break;
+ }
+
+ return 0;
+}
diff --git a/cpukit/libnetworking/rtems/rtems_select.c b/cpukit/libnetworking/rtems/rtems_select.c
new file mode 100644
index 0000000000..927c07daa6
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_select.c
@@ -0,0 +1,178 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+/* #include <stdlib.h> */
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+
+#include <errno.h>
+#include <sys/fcntl.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/filio.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+/*
+ *********************************************************************
+ * RTEMS implementation of select() system call *
+ *********************************************************************
+ */
+
+/*
+ * This implementation is quite restricted:
+ * Works on sockets only -- no support for other devices!
+ * A given socket can be in a read-select or a read/recv* by only
+ * one task at a time.
+ * A given socket can be in a write-select or a write/send* by only
+ * one task at a time.
+ *
+ * NOTE - select() is a very expensive system call. It should be avoided
+ * if at all possible. In many cases, rewriting the application
+ * to use multiple tasks (one per socket) is a better solution.
+ */
+
+static __inline int imin(int a, int b) { return (a < b ? a : b); }
+struct socket *rtems_bsdnet_fdToSocket(int fd);
+
+static int
+socket_select (struct socket *so, int which, rtems_id tid)
+{
+ switch (which) {
+
+ case FREAD:
+ if (soreadable(so))
+ return (1);
+ so->so_rcv.sb_flags |= SB_WAIT;
+ so->so_rcv.sb_sel.si_pid = tid;
+ break;
+
+ case FWRITE:
+ if (sowriteable(so))
+ return (1);
+ so->so_snd.sb_flags |= SB_WAIT;
+ so->so_snd.sb_sel.si_pid = tid;
+ break;
+
+ case 0:
+ if (so->so_oobmark || (so->so_state & SS_RCVATMARK))
+ return (1);
+ so->so_rcv.sb_sel.si_pid = tid;
+ break;
+ }
+ return (0);
+}
+
+static int
+selscan (rtems_id tid, fd_mask **ibits, fd_mask **obits, int nfd, int *retval)
+{
+ struct socket *so;
+ int msk, i, fd;
+ fd_mask bits, bit;
+ int n = 0;
+ static int flag[3] = { FREAD, FWRITE, 0 };
+
+ for (msk = 0; msk < 3; msk++) {
+ if (ibits[msk] == NULL)
+ continue;
+ for (i = 0; i < nfd; i += NFDBITS) {
+ bits = ibits[msk][i/NFDBITS];
+ for (fd = i, bit = 1 ; bits && (fd < nfd) ; fd++, bit <<= 1) {
+ if ((bits & bit) == 0)
+ continue;
+ bits &= ~bit;
+ so = rtems_bsdnet_fdToSocket (fd);
+ if (so == NULL)
+ return (EBADF);
+ if (socket_select (so, flag[msk], tid)) {
+ obits[msk][fd/NFDBITS] |=
+ (1 << (fd % NFDBITS));
+ n++;
+ }
+ }
+ }
+ }
+ *retval = n;
+ return (0);
+}
+
+int
+select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *tv)
+{
+ fd_mask *ibits[3], *obits[3];
+ fd_set ob[3];
+ int error, timo;
+ int retval = 0;
+ rtems_id tid;
+ rtems_interval then = 0, now;
+ rtems_event_set events;
+
+ if (nfds < 0)
+ return (EINVAL);
+ if (tv) {
+ timo = tv->tv_sec * hz + tv->tv_usec / tick;
+ if (timo == 0)
+ timo = 1;
+ then = rtems_clock_get_ticks_since_boot();
+ }
+ else {
+ timo = 0;
+ }
+
+#define getbits(name,i) if (name) { \
+ ibits[i] = &name->fds_bits[0]; \
+ obits[i] = &ob[i].fds_bits[0]; \
+ FD_ZERO(&ob[i]); \
+ } \
+ else ibits[i] = NULL
+ getbits (readfds, 0);
+ getbits (writefds, 1);
+ getbits (exceptfds, 2);
+#undef getbits
+
+ rtems_task_ident (RTEMS_SELF, 0, &tid);
+ rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &events);
+ for (;;) {
+ rtems_bsdnet_semaphore_obtain ();
+ error = selscan(tid, ibits, obits, nfds, &retval);
+ rtems_bsdnet_semaphore_release ();
+ if (error || retval)
+ break;
+ if (timo) {
+ now = rtems_clock_get_ticks_since_boot();
+ timo -= now - then;
+ if (timo <= 0)
+ break;
+ then = now;
+ }
+ rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, timo, &events);
+ }
+
+#define putbits(name,i) if (name) *name = ob[i]
+ putbits (readfds, 0);
+ putbits (writefds, 1);
+ putbits (exceptfds, 2);
+#undef putbits
+ if (error) {
+ errno = error;
+ retval = -1;
+ }
+ return (retval);
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showicmpstat.c b/cpukit/libnetworking/rtems/rtems_showicmpstat.c
new file mode 100644
index 0000000000..c554fa70a1
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showicmpstat.c
@@ -0,0 +1,70 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/icmp_var.h>
+
+/*
+ * Display ICMP statistics
+ * Don't lock the rest of the network tasks out while printing.
+ * It's no big deal if the values change while being printed.
+ */
+static void
+showicmpstat (const char *name, unsigned long n)
+{
+ if (n)
+ printf ("%35s%12lu\n", name, n);
+}
+
+/*
+ * External data we peek at during statistics reporting
+ */
+extern unsigned int icmplenPanicAvoided;
+
+void
+rtems_bsdnet_show_icmp_stats (void)
+{
+ int i;
+ char cbuf[20];
+
+ printf ("************ ICMP Statistics ************\n");
+ showicmpstat ("Calls to icmp_error()", icmpstat.icps_error);
+ showicmpstat ("Errors not sent -- old was icmp", icmpstat.icps_oldicmp);
+ for (i = 0 ; i <= ICMP_MAXTYPE ; i++) {
+ if (icmpstat.icps_outhist[i]) {
+ sprintf (cbuf, "Type %d sent", i);
+ showicmpstat (cbuf, icmpstat.icps_outhist[i]);
+ }
+ }
+ showicmpstat ("icmp_code out of range", icmpstat.icps_badcode);
+ showicmpstat ("packet < ICMP_MINLEN", icmpstat.icps_tooshort);
+ showicmpstat ("bad checksum", icmpstat.icps_checksum);
+ showicmpstat ("calculated bound mismatch", icmpstat.icps_badlen);
+ showicmpstat ("number of responses", icmpstat.icps_reflect);
+ showicmpstat ("all echo requests dropped", icmpstat.icps_allecho);
+ showicmpstat ("b/mcast echo requests dropped", icmpstat.icps_bmcastecho);
+ showicmpstat ("b/mcast tstamp requests dropped", icmpstat.icps_bmcasttstamp);
+ for (i = 0 ; i <= ICMP_MAXTYPE ; i++) {
+ if (icmpstat.icps_inhist[i]) {
+ sprintf (cbuf, "Type %d received", i);
+ showicmpstat (cbuf, icmpstat.icps_inhist[i]);
+ }
+ }
+ showicmpstat ("ICMP panic avoided", icmplenPanicAvoided);
+ printf ("\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showifstat.c b/cpukit/libnetworking/rtems/rtems_showifstat.c
new file mode 100644
index 0000000000..17722093fb
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showifstat.c
@@ -0,0 +1,157 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/mbuf.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * Display an address
+ */
+static int
+showaddress (char *name, struct sockaddr *a)
+{
+ struct sockaddr_in *sa;
+ char buf[17];
+
+ if (!a)
+ return 0;
+ printf ("%s:", name);
+ sa = (struct sockaddr_in *)a;
+ printf ("%-16s", inet_ntop (AF_INET, &sa->sin_addr, buf, sizeof(buf)));
+ return 1;
+}
+
+/*
+ * Display interface statistics
+ */
+void
+rtems_bsdnet_show_if_stats (void)
+{
+ struct ifnet *ifp;
+ struct ifaddr *ifa;
+ unsigned short bit, flags;
+
+ printf ("************ INTERFACE STATISTICS ************\n");
+ for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+ printf ("***** %s%d *****\n", ifp->if_name, ifp->if_unit);
+ for (ifa = ifp->if_addrlist ; ifa ; ifa = ifa->ifa_next) {
+
+ if ( !ifa->ifa_addr )
+ continue;
+
+ switch ( ifa->ifa_addr->sa_family ) {
+ case AF_LINK:
+ {
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ unsigned char *cp = (unsigned char *)LLADDR(sdl);
+ int i;
+
+ switch ( sdl->sdl_type ) {
+ case IFT_ETHER:
+ if ( (i=sdl->sdl_alen) > 0 ) {
+ printf("Ethernet Address: ");
+ do {
+ i--;
+ printf("%02X%c", *cp++, i ? ':' : '\n');
+ } while ( i>0 );
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+
+ case AF_INET:
+ {
+ int printed;
+ printed = showaddress ("Address", ifa->ifa_addr);
+ if (ifp->if_flags & IFF_BROADCAST)
+ printed |= showaddress ("Broadcast Address", ifa->ifa_broadaddr);
+ if (ifp->if_flags & IFF_POINTOPOINT)
+ printed |= showaddress ("Destination Address", ifa->ifa_dstaddr);
+ printed |= showaddress ("Net mask", ifa->ifa_netmask);
+ if (printed)
+ printf ("\n");
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ printf ("Flags:");
+ for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) {
+ char *cp;
+ char xbuf[20];
+ switch (flags & bit) {
+ case 0: cp = NULL; break;
+ case IFF_UP: cp = "Up"; break;
+ case IFF_BROADCAST: cp = "Broadcast"; break;
+ case IFF_DEBUG: cp = "Debug"; break;
+ case IFF_LOOPBACK: cp = "Loopback"; break;
+ case IFF_POINTOPOINT: cp = "Point-to-point"; break;
+ case IFF_RUNNING: cp = "Running"; break;
+ case IFF_NOARP: cp = "No-ARP"; break;
+ case IFF_PROMISC: cp = "Promiscuous"; break;
+ case IFF_ALLMULTI: cp = "All-multicast"; break;
+ case IFF_OACTIVE: cp = "Active"; break;
+ case IFF_SIMPLEX: cp = "Simplex"; break;
+ case IFF_LINK0: cp = "Link0"; break;
+ case IFF_LINK1: cp = "Link1"; break;
+ case IFF_LINK2: cp = "Link2"; break;
+ case IFF_MULTICAST: cp = "Multicast"; break;
+ default: sprintf (xbuf, "%#x", bit); cp = xbuf; break;
+ }
+ if (cp) {
+ flags &= ~bit;
+ printf (" %s", cp);
+ }
+ }
+ printf ("\n");
+
+ printf ("Send queue limit:%-4d length:%-4d Dropped:%-8d\n",
+ ifp->if_snd.ifq_maxlen,
+ ifp->if_snd.ifq_len,
+ ifp->if_snd.ifq_drops);
+
+ /*
+ * FIXME: Could print if_data statistics here,
+ * but right now the drivers maintain their
+ * own statistics.
+ */
+
+ /*
+ * Grab the network semaphore.
+ * In most cases this is not necessary, but it's
+ * easier to always call the driver ioctl function
+ * while holding the semaphore than to try
+ * and explain why some ioctl commands are invoked
+ * while holding the semaphore and others are
+ * invoked while not holding the semaphore.
+ */
+ rtems_bsdnet_semaphore_obtain ();
+ (*ifp->if_ioctl)(ifp, SIO_RTEMS_SHOW_STATS, NULL);
+ rtems_bsdnet_semaphore_release ();
+ }
+ printf ("\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showipstat.c b/cpukit/libnetworking/rtems/rtems_showipstat.c
new file mode 100644
index 0000000000..75eabca2c1
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showipstat.c
@@ -0,0 +1,63 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+
+/*
+ * Display IP statistics
+ * Don't lock the rest of the network tasks out while printing.
+ * It's no big deal if the values change while being printed.
+ */
+static void
+showipstat (const char *name, unsigned long n)
+{
+ if (n)
+ printf ("%35s%12lu\n", name, n);
+}
+
+void
+rtems_bsdnet_show_ip_stats (void)
+{
+ printf ("************ IP Statistics ************\n");
+ showipstat ("total packets received", ipstat.ips_total);
+ showipstat ("checksum bad", ipstat.ips_badsum);
+ showipstat ("packet too short", ipstat.ips_tooshort);
+ showipstat ("not enough data", ipstat.ips_toosmall);
+ showipstat ("ip header length < data size", ipstat.ips_badhlen);
+ showipstat ("ip length < ip header length", ipstat.ips_badlen);
+ showipstat ("fragments received", ipstat.ips_fragments);
+ showipstat ("frags dropped (dups, out of space)", ipstat.ips_fragdropped);
+ showipstat ("fragments timed out", ipstat.ips_fragtimeout);
+ showipstat ("packets forwarded", ipstat.ips_forward);
+ showipstat ("packets rcvd for unreachable dest", ipstat.ips_cantforward);
+ showipstat ("packets forwarded on same net", ipstat.ips_redirectsent);
+ showipstat ("unknown or unsupported protocol", ipstat.ips_noproto);
+ showipstat ("datagrams delivered to upper level", ipstat.ips_delivered);
+ showipstat ("total ip packets generated here", ipstat.ips_localout);
+ showipstat ("lost packets due to nobufs, etc.", ipstat.ips_odropped);
+ showipstat ("total packets reassembled ok", ipstat.ips_reassembled);
+ showipstat ("datagrams successfully fragmented", ipstat.ips_fragmented);
+ showipstat ("output fragments created", ipstat.ips_ofragments);
+ showipstat ("don't fragment flag was set, etc.", ipstat.ips_cantfrag);
+ showipstat ("error in option processing", ipstat.ips_badoptions);
+ showipstat ("packets discarded due to no route", ipstat.ips_noroute);
+ showipstat ("ip version != 4", ipstat.ips_badvers);
+ showipstat ("total raw ip packets generated", ipstat.ips_rawout);
+ showipstat ("ip length > max ip packet size", ipstat.ips_toolong);
+ printf ("\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showmbuf.c b/cpukit/libnetworking/rtems/rtems_showmbuf.c
new file mode 100644
index 0000000000..a4404a5a6c
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showmbuf.c
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+
+/*
+ * Display MBUF statistics
+ * Don't lock the rest of the network tasks out while printing.
+ * It's no big deal if the values change while being printed.
+ */
+void
+rtems_bsdnet_show_mbuf_stats (void)
+{
+ int i;
+ int printed = 0;
+ char *cp;
+
+ printf ("************ MBUF STATISTICS ************\n");
+ printf ("mbufs:%4lu clusters:%4lu free:%4lu\n",
+ mbstat.m_mbufs, mbstat.m_clusters, mbstat.m_clfree);
+ printf ("drops:%4lu waits:%4lu drains:%4lu\n",
+ mbstat.m_drops, mbstat.m_wait, mbstat.m_drain);
+ for (i = 0 ; i < 20 ; i++) {
+ switch (i) {
+ case MT_FREE: cp = "free"; break;
+ case MT_DATA: cp = "data"; break;
+ case MT_HEADER: cp = "header"; break;
+ case MT_SOCKET: cp = "socket"; break;
+ case MT_PCB: cp = "pcb"; break;
+ case MT_RTABLE: cp = "rtable"; break;
+ case MT_HTABLE: cp = "htable"; break;
+ case MT_ATABLE: cp = "atable"; break;
+ case MT_SONAME: cp = "soname"; break;
+ case MT_SOOPTS: cp = "soopts"; break;
+ case MT_FTABLE: cp = "ftable"; break;
+ case MT_RIGHTS: cp = "rights"; break;
+ case MT_IFADDR: cp = "ifaddr"; break;
+ case MT_CONTROL: cp = "control"; break;
+ case MT_OOBDATA: cp = "oobdata"; break;
+ default: cp = NULL; break;
+ }
+ if ((cp != NULL) || (mbstat.m_mtypes[i] != 0)) {
+ char cbuf[16];
+ if (cp == NULL) {
+ sprintf (cbuf, "Type %d", i);
+ cp = cbuf;
+ }
+ printf ("%10s:%-8u", cp, mbstat.m_mtypes[i]);
+ if (++printed == 4) {
+ printf ("\n");
+ printed = 0;
+ }
+ }
+ }
+ if (printed)
+ printf ("\n");
+ printf ("\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showroute.c b/cpukit/libnetworking/rtems/rtems_showroute.c
new file mode 100644
index 0000000000..e30c0eaccf
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showroute.c
@@ -0,0 +1,240 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+/*
+ * We'll use the application versions of realloc and free.
+ */
+#undef free
+#undef malloc
+#include <stdlib.h>
+
+/*
+ * Information per route
+ */
+struct rinfo {
+ struct sockaddr dst;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_dl sdl;
+ } un;
+ unsigned long pksent;
+ unsigned long expire;
+ int flags;
+ char ifname[16];
+ short ifunit;
+ short refcnt;
+};
+
+/*
+ * Information per display
+ */
+struct dinfo {
+ int capacity;
+ int count;
+ struct rinfo *routes;
+};
+
+/*
+ * Copy address
+ */
+static void
+copyAddress (void *to, void *from, int tolen)
+{
+ int ncopy;
+ struct sockaddr dummy;
+
+ if (from == NULL) {
+ /*
+ * Create a fake address of unspecified type
+ */
+ from = &dummy;
+ dummy.sa_len = 4;
+ dummy.sa_family = AF_UNSPEC;
+ }
+ ncopy = ((struct sockaddr *)from)->sa_len;
+ if (ncopy > tolen)
+ ncopy = tolen;
+ memcpy (to, from, ncopy);
+}
+
+/*
+ * Package everything up before printing it.
+ * We don't want to block all network operations till
+ * the printing completes!
+ */
+static int
+show_inet_route (
+ struct radix_node *rn,
+ void *vw )
+{
+ struct rtentry *rt = (struct rtentry *)rn;
+ struct ifnet *ifp;
+ struct dinfo *dp = (struct dinfo *)vw;
+ struct rinfo *r;
+
+ /*
+ * Get a pointer to a new route info structure
+ */
+ if (dp->count >= dp->capacity) {
+ r = realloc (dp->routes, (sizeof *r) * (dp->capacity + 20));
+ if (r == 0)
+ return ENOMEM;
+ dp->capacity += 20;
+ dp->routes = r;
+ }
+ r = dp->routes + dp->count++;
+
+ /*
+ * Fill in the route info structure
+ */
+ copyAddress (&r->dst, rt_key(rt), sizeof r->dst);
+ if (rt->rt_flags & (RTF_GATEWAY | RTF_HOST)) {
+ copyAddress (&r->un, rt->rt_gateway, sizeof r->un);
+ }
+ else {
+ /*
+ * Create a fake address to hold the mask
+ */
+ struct sockaddr_in dummy;
+
+ dummy.sin_family = AF_INET;
+ dummy.sin_len = sizeof dummy;
+ dummy.sin_addr = ((struct sockaddr_in *)rt_mask(rt))->sin_addr;
+ copyAddress (&r->un, &dummy, sizeof r->un);
+ }
+ r->flags = rt->rt_flags;
+ r->refcnt = rt->rt_refcnt;
+ r->pksent = rt->rt_rmx.rmx_pksent;
+ r->expire = rt->rt_rmx.rmx_expire;
+ ifp = rt->rt_ifp;
+ strncpy (r->ifname, (ifp->if_name ? ifp->if_name : ""), sizeof r->ifname);
+ r->ifunit = ifp->if_unit;
+ return 0;
+}
+
+/*
+ * Convert link address to ASCII
+ */
+static char *
+link_ascii (struct sockaddr_dl *sdl, char *buf, int bufsize)
+{
+ char *cp;
+ int i;
+ int first = 1;
+ int nleft = sdl->sdl_alen;
+ char *ap = LLADDR (sdl);
+ static const char hextab[16] = "0123456789ABCDEF";
+
+ cp = buf;
+ while (nleft && (bufsize > 4)) {
+ if (first) {
+ first = 0;
+ }
+ else {
+ *cp++ = ':';
+ bufsize--;
+ }
+ i = *ap++;
+ *cp++ = hextab[(i >> 4) & 0xf];
+ *cp++ = hextab[i & 0xf];
+ nleft--;
+ bufsize -= 2;
+ }
+ *cp = '\0';
+ return buf;
+}
+
+void
+rtems_bsdnet_show_inet_routes (void)
+{
+ struct radix_node_head *rnh;
+ struct dinfo d;
+ struct rinfo *r;
+ int i, error;
+
+ /*
+ * For now we'll handle only AF_INET
+ */
+ rnh = rt_tables[AF_INET];
+ if (!rnh)
+ return;
+ d.count = d.capacity = 0;
+ d.routes = NULL;
+ rtems_bsdnet_semaphore_obtain ();
+ error = rnh->rnh_walktree(rnh, show_inet_route, &d);
+ rtems_bsdnet_semaphore_release ();
+ if (error) {
+ printf ("Can't get route info: %s\n", strerror (error));
+ return;
+ }
+ if (d.count == 0) {
+ printf ("No routes!\n");
+ return;
+ }
+ printf ("Destination Gateway/Mask/Hw Flags Refs Use Expire Interface\n");
+ for (i = 0, r = d.routes ; i < d.count ; i++, r++) {
+ char buf[30];
+ char *cp, *fc, flagbuf[10];
+ const char *addr;
+ unsigned long flagbit;
+ struct sockaddr_in *sin;
+
+ sin = (struct sockaddr_in *)&r->dst;
+ if (sin->sin_addr.s_addr == INADDR_ANY)
+ addr = "default";
+ else
+ addr = inet_ntop (AF_INET, &sin->sin_addr, buf, sizeof buf);
+ printf ("%-16s", addr);
+ switch (r->un.sa.sa_family) {
+ case AF_INET:
+ addr = inet_ntop (AF_INET, &r->un.sin.sin_addr, buf, sizeof buf);
+ break;
+
+ case AF_LINK:
+ addr = link_ascii (&r->un.sdl, buf, sizeof buf);
+ break;
+
+ default:
+ addr = "";
+ break;
+ }
+ printf ("%-19s", addr);
+ fc = "UGHRDM XLS";
+ for (flagbit = 0x1, cp = flagbuf ; *fc ; flagbit <<= 1, fc++) {
+ if ((r->flags & flagbit) && (*fc != ' '))
+ *cp++ = *fc;
+ }
+ *cp = '\0';
+ printf ("%-10s%3d%9ld%7ld %.*s%d\n", flagbuf,
+ r->refcnt, r->pksent,
+ r->expire,
+ (int)sizeof r->ifname, r->ifname,
+ r->ifunit);
+ }
+ free (d.routes);
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showtcpstat.c b/cpukit/libnetworking/rtems/rtems_showtcpstat.c
new file mode 100644
index 0000000000..15612878ef
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showtcpstat.c
@@ -0,0 +1,106 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_var.h>
+
+/*
+ * Display TCP statistics
+ * Don't lock the rest of the network tasks out while printing.
+ * It's no big deal if the values change while being printed.
+ */
+static void
+showtcpstat (const char *name, unsigned long n)
+{
+ if (n)
+ printf ("%35s%12lu\n", name, n);
+}
+
+void
+rtems_bsdnet_show_tcp_stats (void)
+{
+ printf ("************ TCP Statistics ************\n");
+ showtcpstat ("connections initiated", tcpstat.tcps_connattempt);
+ showtcpstat ("connections accepted", tcpstat.tcps_accepts);
+ showtcpstat ("connections established", tcpstat.tcps_connects);
+ showtcpstat ("connections dropped", tcpstat.tcps_drops);
+ showtcpstat ("embryonic connections dropped", tcpstat.tcps_conndrops);
+ showtcpstat ("conn. closed (includes drops)", tcpstat.tcps_closed);
+ showtcpstat ("segs where we tried to get rtt", tcpstat.tcps_segstimed);
+ showtcpstat ("times we succeeded", tcpstat.tcps_rttupdated);
+ showtcpstat ("delayed acks sent", tcpstat.tcps_delack);
+ showtcpstat ("conn. dropped in rxmt timeout", tcpstat.tcps_timeoutdrop);
+ showtcpstat ("retransmit timeouts", tcpstat.tcps_rexmttimeo);
+ showtcpstat ("persist timeouts", tcpstat.tcps_persisttimeo);
+ showtcpstat ("keepalive timeouts", tcpstat.tcps_keeptimeo);
+ showtcpstat ("keepalive probes sent", tcpstat.tcps_keepprobe);
+ showtcpstat ("connections dropped in keepalive", tcpstat.tcps_keepdrops);
+
+ showtcpstat ("total packets sent", tcpstat.tcps_sndtotal);
+ showtcpstat ("data packets sent", tcpstat.tcps_sndpack);
+ showtcpstat ("data bytes sent", tcpstat.tcps_sndbyte);
+ showtcpstat ("data packets retransmitted", tcpstat.tcps_sndrexmitpack);
+ showtcpstat ("data bytes retransmitted", tcpstat.tcps_sndrexmitbyte);
+ showtcpstat ("ack-only packets sent", tcpstat.tcps_sndacks);
+ showtcpstat ("window probes sent", tcpstat.tcps_sndprobe);
+ showtcpstat ("packets sent with URG only", tcpstat.tcps_sndurg);
+ showtcpstat ("window update-only packets sent", tcpstat.tcps_sndwinup);
+ showtcpstat ("control (SYN|FIN|RST) packets sent", tcpstat.tcps_sndctrl);
+
+ showtcpstat ("total packets received", tcpstat.tcps_rcvtotal);
+ showtcpstat ("packets received in sequence", tcpstat.tcps_rcvpack);
+ showtcpstat ("bytes received in sequence", tcpstat.tcps_rcvbyte);
+ showtcpstat ("packets received with ccksum errs", tcpstat.tcps_rcvbadsum);
+ showtcpstat ("packets received with bad offset", tcpstat.tcps_rcvbadoff);
+ showtcpstat ("packets received too short", tcpstat.tcps_rcvshort);
+ showtcpstat ("duplicate-only packets received", tcpstat.tcps_rcvduppack);
+ showtcpstat ("duplicate-only bytes received", tcpstat.tcps_rcvdupbyte);
+ showtcpstat ("packets with some duplicate data", tcpstat.tcps_rcvpartduppack);
+ showtcpstat ("dup. bytes in part-dup. packets", tcpstat.tcps_rcvpartdupbyte);
+ showtcpstat ("out-of-order packets received", tcpstat.tcps_rcvoopack);
+ showtcpstat ("out-of-order bytes received", tcpstat.tcps_rcvoobyte);
+ showtcpstat ("packets with data after window", tcpstat.tcps_rcvpackafterwin);
+ showtcpstat ("bytes rcvd after window", tcpstat.tcps_rcvbyteafterwin);
+ showtcpstat ("packets rcvd after \"close\"", tcpstat.tcps_rcvafterclose);
+ showtcpstat ("rcvd window probe packets", tcpstat.tcps_rcvwinprobe);
+ showtcpstat ("rcvd duplicate acks", tcpstat.tcps_rcvdupack);
+ showtcpstat ("rcvd acks for unsent data", tcpstat.tcps_rcvacktoomuch);
+ showtcpstat ("rcvd ack packets", tcpstat.tcps_rcvackpack);
+ showtcpstat ("bytes acked by rcvd acks", tcpstat.tcps_rcvackbyte);
+ showtcpstat ("rcvd window update packets", tcpstat.tcps_rcvwinupd);
+ showtcpstat ("segments dropped due to PAWS", tcpstat.tcps_pawsdrop);
+ showtcpstat ("times hdr predict ok for acks", tcpstat.tcps_predack);
+ showtcpstat ("times hdr predict ok for data pkts", tcpstat.tcps_preddat);
+ showtcpstat ("pcb cache misses", tcpstat.tcps_pcbcachemiss);
+ showtcpstat ("times cached RTT in route updated", tcpstat.tcps_cachedrtt);
+ showtcpstat ("times cached rttvar updated", tcpstat.tcps_cachedrttvar);
+ showtcpstat ("times cached ssthresh updated", tcpstat.tcps_cachedssthresh);
+ showtcpstat ("times RTT initialized from route", tcpstat.tcps_usedrtt);
+ showtcpstat ("times RTTVAR initialized from rt", tcpstat.tcps_usedrttvar);
+ showtcpstat ("times ssthresh initialized from rt", tcpstat.tcps_usedssthresh);
+ showtcpstat ("timeout in persist state", tcpstat.tcps_persistdrop);
+ showtcpstat ("bogus SYN, e.g. premature ACK", tcpstat.tcps_badsyn);
+ showtcpstat ("resends due to MTU discovery", tcpstat.tcps_mturesent);
+ showtcpstat ("listen queue overflows", tcpstat.tcps_listendrop);
+ printf ("\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_showudpstat.c b/cpukit/libnetworking/rtems/rtems_showudpstat.c
new file mode 100644
index 0000000000..d47534d964
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_showudpstat.c
@@ -0,0 +1,52 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+
+/*
+ * Display UDP statistics
+ * Don't lock the rest of the network tasks out while printing.
+ * It's no big deal if the values change while being printed.
+ */
+static void
+showudpstat (const char *name, unsigned long n)
+{
+ if (n)
+ printf ("%35s%12lu\n", name, n);
+}
+
+void
+rtems_bsdnet_show_udp_stats (void)
+{
+ printf ("************ UDP Statistics ************\n");
+ showudpstat ("total input packets", udpstat.udps_ipackets);
+ showudpstat ("packet shorter than header", udpstat.udps_hdrops);
+ showudpstat ("checksum error", udpstat.udps_badsum);
+ showudpstat ("data length larger than packet", udpstat.udps_badlen);
+ showudpstat ("no socket on port", udpstat.udps_noport);
+ showudpstat ("of above, arrived as broadcast", udpstat.udps_noportbcast);
+ showudpstat ("not delivered, input socket full", udpstat.udps_fullsock);
+ showudpstat ("input packets missing pcb cache", udpstat.udpps_pcbcachemiss);
+ showudpstat ("input packets not for hashed pcb", udpstat.udpps_pcbhashmiss);
+ showudpstat ("total output packets", udpstat.udps_opackets);
+ printf ("\n");
+}
diff --git a/cpukit/libnetworking/rtems/rtems_socketpair.c b/cpukit/libnetworking/rtems/rtems_socketpair.c
new file mode 100644
index 0000000000..09f93ad69a
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_socketpair.c
@@ -0,0 +1,51 @@
+/*
+ * socketpair() for RTEMS
+ *
+ * This file exists primarily to document what is required to provide
+ * a functional implementation of socketpair() for RTEMS.
+ *
+ * The socketpair() service requires that the "local domain" sockets
+ * be functional. This is denoted by the domain constants AF_LOCAL
+ * and AF_UNIX and the protocol constants PF_LOCAL and PF_UNIX. The
+ * local domain functionality is implemented in the file kern/uipc_usrreq.c
+ * which was not part of the initial port of the FreeBSD stack to
+ * RTEMS.
+ *
+ * The FreeBSD socketpair implementation appears to be dependent on
+ * file system features which are not available currently in RTEMS.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+int socketpair (int domain, int type, int protocol, int *rsv)
+{
+ if ( !rsv ) {
+ errno = EFAULT;
+ return -1;
+ }
+
+ /*
+ * Yes, we do not support socketpair() so this is really paranoid.
+ * But it ensures that someone calling this routine and ignoring
+ * the return status will get errors from subsequent socket calls.
+ */
+ rsv[ 0 ] = -1;
+ rsv[ 1 ] = -1;
+ errno = ENOSYS;
+ return -1;
+}
diff --git a/cpukit/libnetworking/rtems/rtems_syscall.c b/cpukit/libnetworking/rtems/rtems_syscall.c
new file mode 100644
index 0000000000..ee2cf1728e
--- /dev/null
+++ b/cpukit/libnetworking/rtems/rtems_syscall.c
@@ -0,0 +1,782 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+/* #include <stdlib.h> */
+#include <stdio.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/fcntl.h>
+#include <sys/filio.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+/*
+ * Since we are "in the kernel", these do not get prototyped in sys/socket.h
+ */
+ssize_t send(int, const void *, size_t, int);
+ssize_t recv(int, void *, size_t, int);
+
+/*
+ * Hooks to RTEMS I/O system
+ */
+static const rtems_filesystem_file_handlers_r socket_handlers;
+int rtems_bsdnet_makeFdForSocket(
+ void *so, const rtems_filesystem_file_handlers_r *h);
+struct socket *rtems_bsdnet_fdToSocket(int fd);
+
+/*
+ * Package system call argument into mbuf.
+ */
+static int
+sockargstombuf (struct mbuf **mp, const void *buf, int buflen, int type)
+{
+ struct mbuf *m;
+
+ if ((u_int)buflen > MLEN)
+ return (EINVAL);
+ m = m_get(M_WAIT, type);
+ if (m == NULL)
+ return (ENOBUFS);
+ m->m_len = buflen;
+ memcpy (mtod(m, caddr_t), buf, buflen);
+ *mp = m;
+ if (type == MT_SONAME) {
+ struct sockaddr *sa;
+ sa = mtod(m, struct sockaddr *);
+ sa->sa_len = buflen;
+ }
+ return 0;
+}
+
+/*
+ *********************************************************************
+ * BSD-style entry points *
+ *********************************************************************
+ */
+int
+socket (int domain, int type, int protocol)
+{
+ int fd;
+ int error;
+ struct socket *so;
+
+ rtems_bsdnet_semaphore_obtain ();
+ error = socreate(domain, &so, type, protocol, NULL);
+ if (error == 0) {
+ fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
+ if (fd < 0)
+ soclose (so);
+ }
+ else {
+ errno = error;
+ fd = -1;
+ }
+ rtems_bsdnet_semaphore_release ();
+ return fd;
+}
+
+int
+bind (int s, struct sockaddr *name, int namelen)
+{
+ int error;
+ int ret = -1;
+ struct socket *so;
+ struct mbuf *nam;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
+ error = sockargstombuf (&nam, name, namelen, MT_SONAME);
+ if (error == 0) {
+ error = sobind (so, nam);
+ if (error == 0)
+ ret = 0;
+ else
+ errno = error;
+ m_freem (nam);
+ }
+ else {
+ errno = error;
+ }
+ }
+ rtems_bsdnet_semaphore_release ();
+ return ret;
+}
+
+int
+connect (int s, struct sockaddr *name, int namelen)
+{
+ int error;
+ int ret = -1;
+ struct socket *so;
+ struct mbuf *nam;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
+ errno = EALREADY;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ error = sockargstombuf (&nam, name, namelen, MT_SONAME);
+ if (error) {
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ error = soconnect (so, nam);
+ if (error)
+ goto bad;
+ if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
+ m_freem(nam);
+ errno = EINPROGRESS;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
+ error = soconnsleep (so);
+ if (error)
+ break;
+ }
+ if (error == 0) {
+ error = so->so_error;
+ so->so_error = 0;
+ }
+ bad:
+ so->so_state &= ~SS_ISCONNECTING;
+ m_freem (nam);
+ if (error)
+ errno = error;
+ else
+ ret = 0;
+ rtems_bsdnet_semaphore_release ();
+ return ret;
+}
+
+int
+listen (int s, int backlog)
+{
+ int error;
+ int ret = -1;
+ struct socket *so;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
+ error = solisten (so, backlog);
+ if (error == 0)
+ ret = 0;
+ else
+ errno = error;
+ }
+ rtems_bsdnet_semaphore_release ();
+ return ret;
+}
+
+int
+accept (int s, struct sockaddr *name, int *namelen)
+{
+ int fd;
+ struct socket *head, *so;
+ struct mbuf *nam;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if ((head->so_options & SO_ACCEPTCONN) == 0) {
+ errno = EINVAL;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if ((head->so_state & SS_NBIO) && head->so_comp.tqh_first == NULL) {
+ errno = EWOULDBLOCK;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ while (head->so_comp.tqh_first == NULL && head->so_error == 0) {
+ if (head->so_state & SS_CANTRCVMORE) {
+ head->so_error = ECONNABORTED;
+ break;
+ }
+ head->so_error = soconnsleep (head);
+ }
+ if (head->so_error) {
+ errno = head->so_error;
+ head->so_error = 0;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+
+ so = head->so_comp.tqh_first;
+ TAILQ_REMOVE(&head->so_comp, so, so_list);
+ head->so_qlen--;
+
+ fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
+ if (fd < 0) {
+ TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
+ head->so_qlen++;
+ soconnwakeup (head);
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ so->so_state &= ~SS_COMP;
+ so->so_head = NULL;
+
+ nam = m_get(M_WAIT, MT_SONAME);
+ (void) soaccept(so, nam);
+ if (name) {
+ /* check length before it is destroyed */
+ if (*namelen > nam->m_len)
+ *namelen = nam->m_len;
+ memcpy (name, mtod(nam, caddr_t), *namelen);
+ }
+ m_freem(nam);
+ rtems_bsdnet_semaphore_release ();
+ return (fd);
+
+}
+
+/*
+ * Shutdown routine
+ */
+
+int
+shutdown (int s, int how)
+{
+ struct socket *so;
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ error = soshutdown(so, how);
+ rtems_bsdnet_semaphore_release ();
+ if (error) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * All `transmit' operations end up calling this routine.
+ */
+ssize_t
+sendmsg (int s, const struct msghdr *mp, int flags)
+{
+ int ret = -1;
+ int error;
+ struct uio auio;
+ struct iovec *iov;
+ struct socket *so;
+ struct mbuf *to;
+ struct mbuf *control = NULL;
+ int i;
+ int len;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ auio.uio_iov = mp->msg_iov;
+ auio.uio_iovcnt = mp->msg_iovlen;
+ auio.uio_segflg = UIO_USERSPACE;
+ auio.uio_rw = UIO_WRITE;
+ auio.uio_offset = 0;
+ auio.uio_resid = 0;
+ iov = mp->msg_iov;
+ for (i = 0; i < mp->msg_iovlen; i++, iov++) {
+ if ((auio.uio_resid += iov->iov_len) < 0) {
+ errno = EINVAL;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ }
+ if (mp->msg_name) {
+ error = sockargstombuf (&to, mp->msg_name, mp->msg_namelen, MT_SONAME);
+ if (error) {
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ }
+ else {
+ to = NULL;
+ }
+ if (mp->msg_control) {
+ if (mp->msg_controllen < sizeof (struct cmsghdr)) {
+ errno = EINVAL;
+ if (to)
+ m_freem(to);
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ sockargstombuf (&control, mp->msg_control, mp->msg_controllen, MT_CONTROL);
+ }
+ else {
+ control = NULL;
+ }
+ len = auio.uio_resid;
+ error = sosend (so, to, &auio, (struct mbuf *)0, control, flags);
+ if (error) {
+ if (auio.uio_resid != len && (error == EINTR || error == EWOULDBLOCK))
+ error = 0;
+ }
+ if (error)
+ errno = error;
+ else
+ ret = len - auio.uio_resid;
+ if (to)
+ m_freem(to);
+ rtems_bsdnet_semaphore_release ();
+ return (ret);
+}
+
+/*
+ * Send a message to a host
+ */
+ssize_t
+sendto (int s, const void *buf, size_t buflen, int flags, const struct sockaddr *to, int tolen)
+{
+ struct msghdr msg;
+ struct iovec iov;
+
+ iov.iov_base = (void *)buf;
+ iov.iov_len = buflen;
+ msg.msg_name = (caddr_t)to;
+ msg.msg_namelen = tolen;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ return sendmsg (s, &msg, flags);
+}
+
+/*
+ * All `receive' operations end up calling this routine.
+ */
+ssize_t
+recvmsg (int s, struct msghdr *mp, int flags)
+{
+ int ret = -1;
+ int error;
+ struct uio auio;
+ struct iovec *iov;
+ struct socket *so;
+ struct mbuf *from = NULL, *control = NULL;
+ int i;
+ int len;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ auio.uio_iov = mp->msg_iov;
+ auio.uio_iovcnt = mp->msg_iovlen;
+ auio.uio_segflg = UIO_USERSPACE;
+ auio.uio_rw = UIO_READ;
+ auio.uio_offset = 0;
+ auio.uio_resid = 0;
+ iov = mp->msg_iov;
+ for (i = 0; i < mp->msg_iovlen; i++, iov++) {
+ if ((auio.uio_resid += iov->iov_len) < 0) {
+ errno = EINVAL;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ }
+ len = auio.uio_resid;
+ mp->msg_flags = flags;
+ error = soreceive (so, &from, &auio, (struct mbuf **)NULL,
+ mp->msg_control ? &control : (struct mbuf **)NULL,
+ &mp->msg_flags);
+ if (error) {
+ if (auio.uio_resid != len && (error == EINTR || error == EWOULDBLOCK))
+ error = 0;
+ }
+ if (error) {
+ errno = error;
+ }
+ else {
+ ret = len - auio.uio_resid;
+ if (mp->msg_name) {
+ len = mp->msg_namelen;
+ if ((len <= 0) || (from == NULL)) {
+ len = 0;
+ }
+ else {
+ if (len > from->m_len)
+ len = from->m_len;
+ memcpy (mp->msg_name, mtod(from, caddr_t), len);
+ }
+ mp->msg_namelen = len;
+ }
+ if (mp->msg_control) {
+ struct mbuf *m;
+ void *ctlbuf;
+
+ len = mp->msg_controllen;
+ m = control;
+ mp->msg_controllen = 0;
+ ctlbuf = mp->msg_control;
+
+ while (m && (len > 0)) {
+ unsigned int tocopy;
+
+ if (len >= m->m_len)
+ tocopy = m->m_len;
+ else {
+ mp->msg_flags |= MSG_CTRUNC;
+ tocopy = len;
+ }
+ memcpy(ctlbuf, mtod(m, caddr_t), tocopy);
+ ctlbuf += tocopy;
+ len -= tocopy;
+ m = m->m_next;
+ }
+ mp->msg_controllen = ctlbuf - mp->msg_control;
+ }
+ }
+ if (from)
+ m_freem (from);
+ if (control)
+ m_freem (control);
+ rtems_bsdnet_semaphore_release ();
+ return (ret);
+}
+
+/*
+ * Receive a message from a host
+ */
+ssize_t
+recvfrom (int s, void *buf, size_t buflen, int flags, const struct sockaddr *from, int *fromlen)
+{
+ struct msghdr msg;
+ struct iovec iov;
+ int ret;
+
+ iov.iov_base = buf;
+ iov.iov_len = buflen;
+ msg.msg_name = (caddr_t)from;
+ if (fromlen)
+ msg.msg_namelen = *fromlen;
+ else
+ msg.msg_namelen = 0;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ ret = recvmsg (s, &msg, flags);
+ if ((from != NULL) && (fromlen != NULL) && (ret >= 0))
+ *fromlen = msg.msg_namelen;
+ return ret;
+}
+
+int
+setsockopt (int s, int level, int name, const void *val, int len)
+{
+ struct socket *so;
+ struct mbuf *m = NULL;
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if (len > MLEN) {
+ errno = EINVAL;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if (val) {
+ error = sockargstombuf (&m, val, len, MT_SOOPTS);
+ if (error) {
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ }
+ error = sosetopt(so, level, name, m);
+ if (error) {
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ rtems_bsdnet_semaphore_release ();
+ return 0;
+}
+
+int
+getsockopt (int s, int level, int name, void *aval, int *avalsize)
+{
+ struct socket *so;
+ struct mbuf *m = NULL, *m0;
+ char *val = aval;
+ int i, op, valsize;
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if (val)
+ valsize = *avalsize;
+ else
+ valsize = 0;
+ if (((error = sogetopt(so, level, name, &m)) == 0) && val && valsize && m) {
+ op = 0;
+ while (m && op < valsize) {
+ i = valsize - op;
+ if (i > m->m_len)
+ i = m->m_len;
+ memcpy (val, mtod(m, caddr_t), i);
+ op += i;
+ val += i;
+ m0 = m;
+ MFREE (m0, m);
+ }
+ *avalsize = op;
+ }
+ if (m != NULL)
+ (void) m_free(m);
+ if (error) {
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ rtems_bsdnet_semaphore_release ();
+ return 0;
+}
+
+static int
+getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
+{
+ struct socket *so;
+ struct mbuf *m;
+ int len = *namelen;
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ m = m_getclr(M_WAIT, MT_SONAME);
+ if (m == NULL) {
+ errno = ENOBUFS;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if (pflag)
+ error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, m);
+ else
+ error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, m);
+ if (error) {
+ m_freem(m);
+ errno = error;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ if (len > m->m_len) {
+ len = m->m_len;
+ *namelen = len;
+ }
+ memcpy (name, mtod(m, caddr_t), len);
+ m_freem (m);
+ rtems_bsdnet_semaphore_release ();
+ return 0;
+}
+
+int
+getpeername (int s, struct sockaddr *name, int *namelen)
+{
+ return getpeersockname (s, name, namelen, 1);
+}
+int
+getsockname (int s, struct sockaddr *name, int *namelen)
+{
+ return getpeersockname (s, name, namelen, 0);
+}
+
+int
+sysctl(int *name, u_int namelen, void *oldp,
+ size_t *oldlenp, void *newp, size_t newlen)
+{
+ int error;
+ size_t j;
+
+ rtems_bsdnet_semaphore_obtain ();
+ error = userland_sysctl (0, name, namelen, oldp, oldlenp, 1, newp, newlen, &j);
+ rtems_bsdnet_semaphore_release ();
+
+ if (oldlenp)
+ *oldlenp = j;
+
+ if (error)
+ {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ ************************************************************************
+ * RTEMS I/O HANDLER ROUTINES *
+ ************************************************************************
+ */
+static int
+rtems_bsdnet_close (rtems_libio_t *iop)
+{
+ struct socket *so;
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = iop->data1) == NULL) {
+ errno = EBADF;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ error = soclose (so);
+ rtems_bsdnet_semaphore_release ();
+ if (error) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+static ssize_t
+rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, size_t count)
+{
+ return recv (iop->data0, buffer, count, 0);
+}
+
+static ssize_t
+rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, size_t count)
+{
+ return send (iop->data0, buffer, count, 0);
+}
+
+static int
+so_ioctl (rtems_libio_t *iop, struct socket *so, uint32_t command, void *buffer)
+{
+ switch (command) {
+ case FIONBIO:
+ if (*(int *)buffer) {
+ iop->flags |= O_NONBLOCK;
+ so->so_state |= SS_NBIO;
+ }
+ else {
+ iop->flags &= ~O_NONBLOCK;
+ so->so_state &= ~SS_NBIO;
+ }
+ return 0;
+
+ case FIONREAD:
+ *(int *)buffer = so->so_rcv.sb_cc;
+ return 0;
+ }
+
+ if (IOCGROUP(command) == 'i')
+ return ifioctl (so, command, buffer, NULL);
+ if (IOCGROUP(command) == 'r')
+ return rtioctl (command, buffer, NULL);
+ return (*so->so_proto->pr_usrreqs->pru_control)(so, command, buffer, 0);
+}
+
+static int
+rtems_bsdnet_ioctl (rtems_libio_t *iop, uint32_t command, void *buffer)
+{
+ struct socket *so;
+ int error;
+
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = iop->data1) == NULL) {
+ errno = EBADF;
+ rtems_bsdnet_semaphore_release ();
+ return -1;
+ }
+ error = so_ioctl (iop, so, command, buffer);
+ rtems_bsdnet_semaphore_release ();
+ if (error) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+static int
+rtems_bsdnet_fcntl (int cmd, rtems_libio_t *iop)
+{
+ struct socket *so;
+
+ if (cmd == F_SETFL) {
+ rtems_bsdnet_semaphore_obtain ();
+ if ((so = iop->data1) == NULL) {
+ rtems_bsdnet_semaphore_release ();
+ return EBADF;
+ }
+ if (iop->flags & LIBIO_FLAGS_NO_DELAY)
+ so->so_state |= SS_NBIO;
+ else
+ so->so_state &= ~SS_NBIO;
+ rtems_bsdnet_semaphore_release ();
+ }
+ return 0;
+}
+
+static int
+rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
+{
+ sp->st_mode = S_IFSOCK;
+ return 0;
+}
+
+static const rtems_filesystem_file_handlers_r socket_handlers = {
+ rtems_filesystem_default_open, /* open */
+ rtems_bsdnet_close, /* close */
+ rtems_bsdnet_read, /* read */
+ rtems_bsdnet_write, /* write */
+ rtems_bsdnet_ioctl, /* ioctl */
+ rtems_filesystem_default_lseek, /* lseek */
+ rtems_bsdnet_fstat, /* fstat */
+ rtems_filesystem_default_fchmod, /* fchmod */
+ rtems_filesystem_default_ftruncate, /* ftruncate */
+ rtems_filesystem_default_fpathconf, /* fpathconf */
+ rtems_filesystem_default_fsync, /* fsync */
+ rtems_filesystem_default_fdatasync, /* fdatasync */
+ rtems_bsdnet_fcntl, /* fcntl */
+ rtems_filesystem_default_rmnod /* rmnod */
+};
diff --git a/cpukit/libnetworking/rtems/sghostname.c b/cpukit/libnetworking/rtems/sghostname.c
new file mode 100644
index 0000000000..0303813e12
--- /dev/null
+++ b/cpukit/libnetworking/rtems/sghostname.c
@@ -0,0 +1,53 @@
+/*
+ * RTEMS versions of hostname functions
+ * FIXME: Not thread-safe
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <errno.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/param.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+
+static char *rtems_hostname;
+
+int
+gethostname (char *name, size_t namelen)
+{
+ char *cp = rtems_hostname;
+
+ if (cp == NULL)
+ cp = "";
+ strncpy (name, cp, namelen);
+ return 0;
+}
+
+int
+sethostname (char *name, size_t namelen)
+{
+ char *old, *new;
+
+ if (namelen >= MAXHOSTNAMELEN) {
+ errno = EINVAL;
+ return -1;
+ }
+ new = malloc (namelen + 1, M_HTABLE, M_NOWAIT);
+ if (new == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ strncpy (new, name, namelen);
+ new[namelen] = '\0';
+ old = rtems_hostname;
+ rtems_hostname = new;
+ if (old)
+ free (old, M_HTABLE);
+ return 0;
+}
diff --git a/cpukit/libnetworking/rtems/tftp.h b/cpukit/libnetworking/rtems/tftp.h
new file mode 100644
index 0000000000..ae8588deca
--- /dev/null
+++ b/cpukit/libnetworking/rtems/tftp.h
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ */
+
+/*
+ * Trivial File Transfer Protocol (TFTP)
+ *
+ * Transfer file to/from remote host
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ */
+
+/*
+ * Usage:
+ *
+ * To open `/bootfiles/image' on `hostname' for reading:
+ * fd = open ("/TFTP/hostname/bootfiles/image", O_RDONLY);
+ *
+ * The 'TFTP' is the mount path and the `hostname' must be four dot-separated
+ * decimal values.
+ */
+
+#ifndef _RTEMS_TFTP_H
+#define _RTEMS_TFTP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/libio.h>
+
+/*
+ * Filesystem Mount table entry.
+ */
+int rtems_tftpfs_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/sys/callout.h b/cpukit/libnetworking/sys/callout.h
new file mode 100644
index 0000000000..150609eef6
--- /dev/null
+++ b/cpukit/libnetworking/sys/callout.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)callout.h 8.2 (Berkeley) 1/21/94
+ * $FreeBSD: src/sys/sys/callout.h,v 1.27 2004/04/20 15:49:31 cperciva Exp $
+ */
+
+#ifndef _SYS_CALLOUT_H_
+#define _SYS_CALLOUT_H_
+
+struct callout {
+ struct callout *c_next; /* next callout in queue */
+ void *c_arg; /* function argument */
+ void (*c_func)(void *); /* function to call */
+ int c_time; /* ticks to the event */
+};
+
+#ifdef _KERNEL
+extern struct callout *callfree, *callout, calltodo;
+extern int ncallout;
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/sys/conf.h b/cpukit/libnetworking/sys/conf.h
new file mode 100644
index 0000000000..a72e0963b8
--- /dev/null
+++ b/cpukit/libnetworking/sys/conf.h
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 2000
+ * Poul-Henning Kamp. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)conf.h 8.5 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/sys/conf.h,v 1.231 2007/02/02 22:27:45 bms Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_CONF_H_
+#define _SYS_CONF_H_
+
+#ifdef _KERNEL
+
+/*
+ * Definitions of device driver entry switches
+ */
+
+struct buf;
+struct proc;
+struct tty;
+struct uio;
+struct vnode;
+#endif /* _KERNEL */
+
+#endif /* !_SYS_CONF_H_ */
diff --git a/cpukit/libnetworking/sys/domain.h b/cpukit/libnetworking/sys/domain.h
new file mode 100644
index 0000000000..0c90944171
--- /dev/null
+++ b/cpukit/libnetworking/sys/domain.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)domain.h 8.1 (Berkeley) 6/2/93
+ * $Id$
+ */
+
+#ifndef _SYS_DOMAIN_H_
+#define _SYS_DOMAIN_H_
+
+/*
+ * Structure per communications domain.
+ */
+
+/*
+ * Forward structure declarations for function prototypes [sic].
+ */
+struct mbuf;
+
+struct domain {
+ int dom_family; /* AF_xxx */
+ char *dom_name;
+ void (*dom_init) /* initialize domain data structures */
+ (void);
+ int (*dom_externalize) /* externalize access rights */
+ (struct mbuf *);
+ void (*dom_dispose) /* dispose of internalized rights */
+ (struct mbuf *);
+ struct protosw *dom_protosw, *dom_protoswNPROTOSW;
+ struct domain *dom_next;
+ int (*dom_rtattach) /* initialize routing table */
+ (void **, int);
+ int dom_rtoffset; /* an arg to rtattach, in bits */
+ int dom_maxrtkey; /* for routing layer */
+};
+
+#ifdef _KERNEL
+extern struct domain *domains;
+extern struct domain localdomain;
+
+#define DOMAIN_SET(name) \
+ DATA_SET(domain_set, name ## domain);
+
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/sys/kernel.h b/cpukit/libnetworking/sys/kernel.h
new file mode 100644
index 0000000000..c601938486
--- /dev/null
+++ b/cpukit/libnetworking/sys/kernel.h
@@ -0,0 +1,189 @@
+/*-
+ * Copyright (c) 1995 Terrence R. Lambert
+ * All rights reserved.
+ *
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)kernel.h 8.3 (Berkeley) 1/21/94
+ * $Id$
+ */
+
+#ifndef _SYS_KERNEL_H_
+#define _SYS_KERNEL_H_
+
+#include <sys/linker_set.h>
+
+#ifdef _KERNEL
+
+/* Global variables for the kernel. */
+
+/* 1.1 */
+extern long hostid;
+extern char hostname[MAXHOSTNAMELEN];
+extern char domainname[MAXHOSTNAMELEN];
+extern char kernelname[MAXPATHLEN];
+
+/* 1.2 */
+extern volatile struct timeval mono_time;
+extern struct timeval boottime;
+extern struct timeval runtime;
+/* extern volatile struct timeval time; */
+extern struct timezone tz; /* XXX */
+
+extern int tick; /* usec per tick (1000000 / hz) */
+extern int hz; /* system clock's frequency */
+extern int psratio; /* ratio: prof / stat */
+extern int stathz; /* statistics clock's frequency */
+extern int profhz; /* profiling clock's frequency */
+extern int ticks;
+
+#endif /* _KERNEL */
+
+/*
+ * Enumerated types for known system startup interfaces.
+ *
+ * Startup occurs in ascending numeric order; the list entries are
+ * sorted prior to attempting startup to guarantee order. Items
+ * of the same level are arbitrated for order based on the 'order'
+ * element.
+ *
+ * These numbers are arbitrary and are chosen ONLY for ordering; the
+ * enumeration values are explicit rather than implicit to provide
+ * for binary compatibility with inserted elements.
+ *
+ * The SI_SUB_RUN_SCHEDULER value must have the highest lexical value.
+ *
+ * The SI_SUB_CONSOLE and SI_SUB_SWAP values represent values used by
+ * the BSD 4.4Lite but not by FreeBSD; they are maintained in dependent
+ * order to support porting.
+ *
+ * The SI_SUB_PROTO_BEGIN and SI_SUB_PROTO_END bracket a range of
+ * initializations to take place at splimp(). This is a historical
+ * wart that should be removed -- probably running everything at
+ * splimp() until the first init that doesn't want it is the correct
+ * fix. They are currently present to ensure historical behavior.
+ */
+enum sysinit_sub_id {
+ SI_SUB_DUMMY = 0x00000000, /* not executed; for linker*/
+ SI_SUB_CONSOLE = 0x08000000, /* console*/
+ SI_SUB_COPYRIGHT = 0x08000001, /* first use of console*/
+ SI_SUB_VM = 0x10000000, /* virtual memory system init*/
+ SI_SUB_KMEM = 0x18000000, /* kernel memory*/
+ SI_SUB_CPU = 0x20000000, /* CPU resource(s)*/
+ SI_SUB_DEVFS = 0x22000000, /* get DEVFS ready */
+ SI_SUB_DRIVERS = 0x23000000, /* Let Drivers initialize */
+ SI_SUB_CONFIGURE = 0x24000000, /* Configure devices */
+ SI_SUB_INTRINSIC = 0x28000000, /* proc 0*/
+ SI_SUB_RUN_QUEUE = 0x30000000, /* the run queue*/
+ SI_SUB_VM_CONF = 0x38000000, /* config VM, set limits*/
+ SI_SUB_VFS = 0x40000000, /* virtual file system*/
+ SI_SUB_CLOCKS = 0x48000000, /* real time and stat clocks*/
+ SI_SUB_MBUF = 0x50000000, /* mbufs*/
+ SI_SUB_CLIST = 0x58000000, /* clists*/
+ SI_SUB_SYSV_SHM = 0x64000000, /* System V shared memory*/
+ SI_SUB_SYSV_SEM = 0x68000000, /* System V semaphores*/
+ SI_SUB_SYSV_MSG = 0x6C000000, /* System V message queues*/
+ SI_SUB_PSEUDO = 0x70000000, /* pseudo devices*/
+ SI_SUB_PROTO_BEGIN = 0x80000000, /* XXX: set splimp (kludge)*/
+ SI_SUB_PROTO_IF = 0x84000000, /* interfaces*/
+ SI_SUB_PROTO_DOMAIN = 0x88000000, /* domains (address families?)*/
+ SI_SUB_PROTO_END = 0x8fffffff, /* XXX: set splx (kludge)*/
+ SI_SUB_KPROF = 0x90000000, /* kernel profiling*/
+ SI_SUB_KICK_SCHEDULER = 0xa0000000, /* start the timeout events*/
+ SI_SUB_ROOT = 0xb0000000, /* root mount*/
+ SI_SUB_ROOT_FDTAB = 0xb8000000, /* root vnode in fd table...*/
+ SI_SUB_SWAP = 0xc0000000, /* swap*/
+ SI_SUB_INTRINSIC_POST = 0xd0000000, /* proc 0 cleanup*/
+ SI_SUB_KTHREAD_INIT = 0xe0000000, /* init process*/
+ SI_SUB_KTHREAD_PAGE = 0xe4000000, /* pageout daemon*/
+ SI_SUB_KTHREAD_VM = 0xe8000000, /* vm daemon*/
+ SI_SUB_KTHREAD_UPDATE = 0xec000000, /* update daemon*/
+ SI_SUB_RUN_SCHEDULER = 0xffffffff /* scheduler: no return*/
+};
+
+
+/*
+ * Some enumerated orders; "ANY" sorts last.
+ */
+enum sysinit_elem_order {
+ SI_ORDER_FIRST = 0x00000000, /* first*/
+ SI_ORDER_SECOND = 0x00000001, /* second*/
+ SI_ORDER_THIRD = 0x00000002, /* third*/
+ SI_ORDER_MIDDLE = 0x10000000, /* somewhere in the middle */
+ SI_ORDER_ANY = 0xffffffff /* last*/
+};
+
+
+/*
+ * A system initialization call instance
+ *
+ * The subsystem
+ */
+struct sysinit {
+ unsigned int subsystem; /* subsystem identifier*/
+ unsigned int order; /* init order within subsystem*/
+ void (*func)(void *); /* init function*/
+ void *udata; /* multiplexer/argument */
+};
+
+
+/*
+ * Default: no special processing
+ */
+#define SYSINIT(uniquifier, subsystem, order, func, ident)
+
+/*
+ * Call 'fork()' before calling '(*func)(ident)';
+ * for making a kernel 'thread' (or builtin process.)
+ */
+#define SYSINIT_KT(uniquifier, subsystem, order, func, ident)
+
+
+/*
+ * A kernel process descriptor; used to start "internal" daemons
+ *
+ * Note: global_procpp may be NULL for no global save area
+ */
+struct kproc_desc {
+ char *arg0; /* arg 0 (for 'ps' listing)*/
+ void (*func)(void); /* "main" for kernel process*/
+ struct proc **global_procpp; /* ptr to proc ptr save area*/
+};
+
+void kproc_start(void *udata);
+
+#endif /* !_SYS_KERNEL_H_*/
diff --git a/cpukit/libnetworking/sys/libkern.h b/cpukit/libnetworking/sys/libkern.h
new file mode 100644
index 0000000000..3c0b025714
--- /dev/null
+++ b/cpukit/libnetworking/sys/libkern.h
@@ -0,0 +1,94 @@
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)libkern.h 8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/sys/libkern.h,v 1.48 2005/02/10 20:39:39 glebius Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_LIBKERN_H_
+#define _SYS_LIBKERN_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <sys/types.h>
+
+/* BCD conversions. */
+extern u_char const bcd2bin_data[];
+extern u_char const bin2bcd_data[];
+extern char const hex2ascii_data[];
+
+#define bcd2bin(bcd) (bcd2bin_data[bcd])
+#define bin2bcd(bin) (bin2bcd_data[bin])
+#define hex2ascii(hex) (hex2ascii_data[hex])
+
+static __inline int imax(int a, int b) { return (a > b ? a : b); }
+static __inline int imin(int a, int b) { return (a < b ? a : b); }
+static __inline long lmax(long a, long b) { return (a > b ? a : b); }
+static __inline long lmin(long a, long b) { return (a < b ? a : b); }
+static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
+static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
+static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
+static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
+static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
+static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
+
+/* Prototypes for non-quad routines. */
+int bcmp(const void *, const void *, size_t);
+#ifndef HAVE_INLINE_FFS
+int ffs(int);
+#endif
+#ifndef HAVE_INLINE_FLS
+int fls(int);
+#endif
+int locc(int, char *, u_int);
+void qsort(void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *));
+#if defined(__rtems__)
+u_long rtems_bsdnet_random(void);
+#define random() rtems_bsdnet_random()
+#else
+u_long random(void);
+#endif
+char *index(const char *, int);
+char *rindex(const char *, int);
+int scanc(u_int, const u_char *, const u_char *, int);
+int skpc(int, int, char *);
+void srandom(u_long);
+char *strcat(char * __restrict, const char * __restrict);
+int strcmp(const char *, const char *);
+char *strdup(const char *s);
+char *strcpy(char * __restrict, const char * __restrict);
+size_t strlen(const char *);
+int strncmp(const char *, const char *, size_t);
+char *strncpy(char * __restrict, const char * __restrict, size_t);
+char *strerror(int errnum);
+
+#endif /* !_SYS_LIBKERN_H_ */
diff --git a/cpukit/libnetworking/sys/linker_set.h b/cpukit/libnetworking/sys/linker_set.h
new file mode 100644
index 0000000000..a2354ed397
--- /dev/null
+++ b/cpukit/libnetworking/sys/linker_set.h
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 1999 John D. Polstra
+ * Copyright (c) 1999,2001 Peter Wemm <peter@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/linker_set.h,v 1.13 2002/09/23 06:11:29 peter Exp $
+ */
+
+#ifndef _SYS_LINKER_SET_H_
+#define _SYS_LINKER_SET_H_
+
+/*
+ * The following macros are used to declare global sets of objects, which
+ * are collected by the linker into a `linker_set' as defined below.
+ * For ELF, this is done by constructing a separate segment for each set.
+ */
+
+/*
+ * Private macros, not to be used outside this header file.
+ */
+#ifdef __GNUC__
+#define __MAKE_SET(set, sym) \
+ static void const * const __set_##set##_sym_##sym \
+ __attribute((section("set_" #set))) __used = &sym
+#else /* !__GNUC__ */
+#ifndef lint
+#error "This file needs to be compiled by GCC or lint"
+#endif /* lint */
+#define __MAKE_SET(set, sym) extern void const * const (__set_##set##_sym_##sym)
+#endif /* __GNUC__ */
+
+/*
+ * Public macros.
+ */
+#define TEXT_SET(set, sym) __MAKE_SET(set, sym)
+#define DATA_SET(set, sym) __MAKE_SET(set, sym)
+#define BSS_SET(set, sym) __MAKE_SET(set, sym)
+#define ABS_SET(set, sym) __MAKE_SET(set, sym)
+#define SET_ENTRY(set, sym) __MAKE_SET(set, sym)
+
+/*
+ * Initialize before referring to a give linker set
+ */
+#define SET_DECLARE(set, ptype) \
+ extern ptype *__CONCAT(__start_set_,set)[]; \
+ extern ptype *__CONCAT(__stop_set_,set)[]
+
+#define SET_BEGIN(set) \
+ (__CONCAT(__start_set_,set))
+#define SET_LIMIT(set) \
+ (__CONCAT(__stop_set_,set))
+
+/*
+ * Iterate over all the elements of a set.
+ *
+ * Sets always contain addresses of things, and "pvar" points to words
+ * containing those addresses. Thus is must be declared as "type **pvar",
+ * and the address of each set item is obtained inside the loop by "*pvar".
+ */
+#define SET_FOREACH(pvar, set) \
+ for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++)
+
+#define SET_ITEM(set, i) \
+ ((SET_BEGIN(set))[i])
+
+/*
+ * Provide a count of the items in a set.
+ */
+#define SET_COUNT(set) \
+ (SET_LIMIT(set) - SET_BEGIN(set))
+
+#endif /* _SYS_LINKER_SET_H_ */
diff --git a/cpukit/libnetworking/sys/malloc.h b/cpukit/libnetworking/sys/malloc.h
new file mode 100644
index 0000000000..10b0a7964c
--- /dev/null
+++ b/cpukit/libnetworking/sys/malloc.h
@@ -0,0 +1,355 @@
+/*
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)malloc.h 8.5 (Berkeley) 5/3/95
+ * $Id$
+ */
+
+#ifndef _SYS_MALLOC_H_
+#define _SYS_MALLOC_H_
+
+#include <rtems/rtems_bsdnet_internal.h> /* Ensure we get RTEMS malloc hooks */
+#define KMEMSTATS
+
+/*
+ * flags to malloc
+ */
+#define M_WAITOK 0x0000
+#define M_NOWAIT 0x0001
+#define M_KERNEL 0x0002
+
+/*
+ * Types of memory to be allocated
+ */
+#define M_FREE 0 /* should be on free list */
+#define M_MBUF 1 /* mbuf */
+#define M_DEVBUF 2 /* device driver memory */
+#define M_SOCKET 3 /* socket structure */
+#define M_PCB 4 /* protocol control block */
+#define M_RTABLE 5 /* routing tables */
+#define M_HTABLE 6 /* IMP host tables */
+#define M_FTABLE 7 /* fragment reassembly header */
+#define M_ZOMBIE 8 /* zombie proc status */
+#define M_IFADDR 9 /* interface address */
+#define M_SOOPTS 10 /* socket options */
+#define M_SONAME 11 /* socket name */
+#define M_NAMEI 12 /* namei path name buffer */
+#define M_GPROF 13 /* kernel profiling buffer */
+#define M_IOCTLOPS 14 /* ioctl data buffer */
+#define M_MAPMEM 15 /* mapped memory descriptors */
+#define M_CRED 16 /* credentials */
+#define M_PGRP 17 /* process group header */
+#define M_SESSION 18 /* session header */
+#define M_IOV 19 /* large iov's */
+#define M_MOUNT 20 /* vfs mount struct */
+#define M_FHANDLE 21 /* network file handle */
+#define M_NFSREQ 22 /* NFS request header */
+#define M_NFSMNT 23 /* NFS mount structure */
+#define M_NFSNODE 24 /* NFS vnode private part */
+#define M_VNODE 25 /* Dynamically allocated vnodes */
+#define M_CACHE 26 /* Dynamically allocated cache entries */
+#define M_DQUOT 27 /* UFS quota entries */
+#define M_UFSMNT 28 /* UFS mount structure */
+#define M_SHM 29 /* SVID compatible shared memory segments */
+#define M_VMMAP 30 /* VM map structures */
+#define M_VMMAPENT 31 /* VM map entry structures */
+#define M_VMOBJ 32 /* VM object structure */
+#define M_VMOBJHASH 33 /* VM object hash structure */
+#define M_VMPMAP 34 /* VM pmap */
+#define M_VMPVENT 35 /* VM phys-virt mapping entry */
+#define M_VMPAGER 36 /* XXX: VM pager struct */
+#define M_VMPGDATA 37 /* XXX: VM pager private data */
+#define M_FILE 38 /* Open file structure */
+#define M_FILEDESC 39 /* Open file descriptor table */
+#define M_LOCKF 40 /* Byte-range locking structures */
+#define M_PROC 41 /* Proc structures */
+#define M_SUBPROC 42 /* Proc sub-structures */
+#define M_SEGMENT 43 /* Segment for LFS */
+#define M_LFSNODE 44 /* LFS vnode private part */
+#define M_FFSNODE 45 /* FFS vnode private part */
+#define M_MFSNODE 46 /* MFS vnode private part */
+#define M_NQLEASE 47 /* Nqnfs lease */
+#define M_NQMHOST 48 /* Nqnfs host address table */
+#define M_NETADDR 49 /* Export host address structure */
+#define M_NFSSVC 50 /* Nfs server structure */
+#define M_NFSUID 51 /* Nfs uid mapping structure */
+#define M_NFSD 52 /* Nfs server daemon structure */
+#define M_IPMOPTS 53 /* internet multicast options */
+#define M_IPMADDR 54 /* internet multicast address */
+#define M_IFMADDR 55 /* link-level multicast address */
+#define M_MRTABLE 56 /* multicast routing tables */
+#define M_ISOFSMNT 57 /* ISOFS mount structure */
+#define M_ISOFSNODE 58 /* ISOFS vnode private part */
+#define M_NFSRVDESC 59 /* NFS server socket descriptor */
+#define M_NFSDIROFF 60 /* NFS directory offset data */
+#define M_NFSBIGFH 61 /* NFS version 3 file handle */
+#define M_MSDOSFSMNT 67 /* MSDOSFS mount structure */
+#define M_MSDOSFSNODE 68 /* MSDOSFS vnode private part */
+#define M_MSDOSFSFAT 69 /* MSDOSFS file allocation table */
+#define M_DEVFSMNT 70 /* DEVFS mount structure */
+#define M_DEVFSBACK 71 /* DEVFS Back node */
+#define M_DEVFSFRONT 72 /* DEVFS Front node */
+#define M_DEVFSNODE 73 /* DEVFS node */
+#define M_TEMP 74 /* misc temporary data buffers */
+#define M_TTYS 75 /* tty data structures */
+#define M_GZIP 76 /* Gzip trees */
+#define M_IPFW 77 /* IpFw/IpAcct chain's */
+#define M_DEVL 78 /* isa_device lists in userconfig() */
+#define M_PKTCLASS 79 /* structures used in packet classifier */
+#define M_SYSCTL 80 /* sysctl internal magic */
+#define M_SECA 81 /* security associations, key management */
+#define M_BIOBUF 82 /* BIO buffer */
+#define M_KTRACE 83 /* KTRACE */
+#define M_SELECT 84 /* select() buffer */
+#define M_CFS 85 /* Coda */
+#define M_LAST 86 /* Must be last type + 1 */
+
+#define INITKMEMNAMES { \
+ "free", /* 0 M_FREE */ \
+ "mbuf", /* 1 M_MBUF */ \
+ "devbuf", /* 2 M_DEVBUF */ \
+ "socket", /* 3 M_SOCKET */ \
+ "pcb", /* 4 M_PCB */ \
+ "routetbl", /* 5 M_RTABLE */ \
+ "hosttbl", /* 6 M_HTABLE */ \
+ "fragtbl", /* 7 M_FTABLE */ \
+ "zombie", /* 8 M_ZOMBIE */ \
+ "ifaddr", /* 9 M_IFADDR */ \
+ "soopts", /* 10 M_SOOPTS */ \
+ "soname", /* 11 M_SONAME */ \
+ "namei", /* 12 M_NAMEI */ \
+ "gprof", /* 13 M_GPROF */ \
+ "ioctlops", /* 14 M_IOCTLOPS */ \
+ "mapmem", /* 15 M_MAPMEM */ \
+ "cred", /* 16 M_CRED */ \
+ "pgrp", /* 17 M_PGRP */ \
+ "session", /* 18 M_SESSION */ \
+ "iov", /* 19 M_IOV */ \
+ "mount", /* 20 M_MOUNT */ \
+ "fhandle", /* 21 M_FHANDLE */ \
+ "NFS req", /* 22 M_NFSREQ */ \
+ "NFS mount", /* 23 M_NFSMNT */ \
+ "NFS node", /* 24 M_NFSNODE */ \
+ "vnodes", /* 25 M_VNODE */ \
+ "namecache", /* 26 M_CACHE */ \
+ "UFS quota", /* 27 M_DQUOT */ \
+ "UFS mount", /* 28 M_UFSMNT */ \
+ "shm", /* 29 M_SHM */ \
+ "VM map", /* 30 M_VMMAP */ \
+ "VM mapent", /* 31 M_VMMAPENT */ \
+ "VM object", /* 32 M_VMOBJ */ \
+ "VM objhash", /* 33 M_VMOBJHASH */ \
+ "VM pmap", /* 34 M_VMPMAP */ \
+ "VM pvmap", /* 35 M_VMPVENT */ \
+ "VM pager", /* 36 M_VMPAGER */ \
+ "VM pgdata", /* 37 M_VMPGDATA */ \
+ "file", /* 38 M_FILE */ \
+ "file desc", /* 39 M_FILEDESC */ \
+ "lockf", /* 40 M_LOCKF */ \
+ "proc", /* 41 M_PROC */ \
+ "subproc", /* 42 M_SUBPROC */ \
+ "LFS segment", /* 43 M_SEGMENT */ \
+ "LFS node", /* 44 M_LFSNODE */ \
+ "FFS node", /* 45 M_FFSNODE */ \
+ "MFS node", /* 46 M_MFSNODE */ \
+ "NQNFS Lease", /* 47 M_NQLEASE */ \
+ "NQNFS Host", /* 48 M_NQMHOST */ \
+ "Export Host", /* 49 M_NETADDR */ \
+ "NFS srvsock", /* 50 M_NFSSVC */ \
+ "NFS uid", /* 51 M_NFSUID */ \
+ "NFS daemon", /* 52 M_NFSD */ \
+ "ip_moptions", /* 53 M_IPMOPTS */ \
+ "in_multi", /* 54 M_IPMADDR */ \
+ "ether_multi", /* 55 M_IFMADDR */ \
+ "mrt", /* 56 M_MRTABLE */ \
+ "ISOFS mount", /* 57 M_ISOFSMNT */ \
+ "ISOFS node", /* 58 M_ISOFSNODE */ \
+ "NFSV3 srvdesc",/* 59 M_NFSRVDESC */ \
+ "NFSV3 diroff", /* 60 M_NFSDIROFF */ \
+ "NFSV3 bigfh", /* 61 M_NFSBIGFH */ \
+ NULL, \
+ NULL, NULL, NULL, NULL, \
+ "MSDOSFS mount",/* 67 M_MSDOSFSMNT */ \
+ "MSDOSFS node", /* 68 M_MSDOSFSNODE */ \
+ "MSDOSFS FAT", /* 69 M_MSDOSFSFAR */ \
+ "DEVFS mount", /* 70 M_DEVFSMNT */ \
+ "DEVFS back", /* 71 M_DEVFSBACK */ \
+ "DEVFS front", /* 72 M_DEVFSFRONT */ \
+ "DEVFS node", /* 73 M_DEVFSNODE */ \
+ "temp", /* 74 M_TEMP */ \
+ "ttys", /* 75 M_TTYS */ \
+ "Gzip trees", /* 76 M_GZIP */ \
+ "IpFw/IpAcct", /* 77 M_IPFW */ \
+ "isa_devlist", /* 78 M_DEVL */ \
+ "PktClass", /* 79 M_PKTCLASS */ \
+ "sysctl", /* 80 M_SYSCTL */ \
+ "key mgmt", /* 81 M_SECA */ \
+ "BIO buffer", /* 82 M_BIOBUF */ \
+ "KTRACE", /* 83 M_KTRACE */ \
+ "select", /* 84 M_SELECT */ \
+ "Coda", /* 85 M_CFS */ \
+}
+
+struct kmemstats {
+ long ks_inuse; /* # of packets of this type currently in use */
+ long ks_calls; /* total packets of this type ever allocated */
+ long ks_memuse; /* total memory held in bytes */
+ u_short ks_limblocks; /* number of times blocked for hitting limit */
+ u_short ks_mapblocks; /* number of times blocked for kernel map */
+ long ks_maxused; /* maximum number ever used */
+ long ks_limit; /* most that are allowed to exist */
+ long ks_size; /* sizes of this thing that are allocated */
+ long ks_spare;
+};
+
+/*
+ * Array of descriptors that describe the contents of each page
+ */
+struct kmemusage {
+ short ku_indx; /* bucket index */
+ union {
+ u_short freecnt;/* for small allocations, free pieces in page */
+ u_short pagecnt;/* for large allocations, pages alloced */
+ } ku_un;
+};
+#define ku_freecnt ku_un.freecnt
+#define ku_pagecnt ku_un.pagecnt
+
+/*
+ * Set of buckets for each size of memory block that is retained
+ */
+struct kmembuckets {
+ caddr_t kb_next; /* list of free blocks */
+ caddr_t kb_last; /* last free block */
+ long kb_calls; /* total calls to allocate this size */
+ long kb_total; /* total number of blocks allocated */
+ long kb_totalfree; /* # of free elements in this bucket */
+ long kb_elmpercl; /* # of elements in this sized allocation */
+ long kb_highwat; /* high water mark */
+ long kb_couldfree; /* over high water mark and could free */
+};
+
+#ifdef _KERNEL
+#define MINALLOCSIZE (1 << MINBUCKET)
+#define BUCKETINDX(size) \
+ ((size) <= (MINALLOCSIZE * 128) \
+ ? (size) <= (MINALLOCSIZE * 8) \
+ ? (size) <= (MINALLOCSIZE * 2) \
+ ? (size) <= (MINALLOCSIZE * 1) \
+ ? (MINBUCKET + 0) \
+ : (MINBUCKET + 1) \
+ : (size) <= (MINALLOCSIZE * 4) \
+ ? (MINBUCKET + 2) \
+ : (MINBUCKET + 3) \
+ : (size) <= (MINALLOCSIZE* 32) \
+ ? (size) <= (MINALLOCSIZE * 16) \
+ ? (MINBUCKET + 4) \
+ : (MINBUCKET + 5) \
+ : (size) <= (MINALLOCSIZE * 64) \
+ ? (MINBUCKET + 6) \
+ : (MINBUCKET + 7) \
+ : (size) <= (MINALLOCSIZE * 2048) \
+ ? (size) <= (MINALLOCSIZE * 512) \
+ ? (size) <= (MINALLOCSIZE * 256) \
+ ? (MINBUCKET + 8) \
+ : (MINBUCKET + 9) \
+ : (size) <= (MINALLOCSIZE * 1024) \
+ ? (MINBUCKET + 10) \
+ : (MINBUCKET + 11) \
+ : (size) <= (MINALLOCSIZE * 8192) \
+ ? (size) <= (MINALLOCSIZE * 4096) \
+ ? (MINBUCKET + 12) \
+ : (MINBUCKET + 13) \
+ : (size) <= (MINALLOCSIZE * 16384) \
+ ? (MINBUCKET + 14) \
+ : (MINBUCKET + 15))
+
+/*
+ * Turn virtual addresses into kmem map indices
+ */
+#define kmemxtob(alloc) (kmembase + (alloc) * PAGE_SIZE)
+#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / PAGE_SIZE)
+#define btokup(addr) (&kmemusage[(caddr_t)(addr) - kmembase >> PAGE_SHIFT])
+
+/*
+ * Macro versions for the usual cases of malloc/free
+ */
+#if defined(KMEMSTATS) || defined(DIAGNOSTIC)
+#define MALLOC(space, cast, size, type, flags) \
+ (space) = (cast)malloc((u_long)(size), type, flags)
+#define FREE(addr, type) free((addr), type)
+
+#else /* do not collect statistics */
+#define MALLOC(space, cast, size, type, flags) { \
+ register struct kmembuckets *kbp = &bucket[BUCKETINDX(size)]; \
+ long s = splimp(); \
+ if (kbp->kb_next == NULL) { \
+ (space) = (cast)malloc((u_long)(size), type, flags); \
+ } else { \
+ (space) = (cast)kbp->kb_next; \
+ kbp->kb_next = *(caddr_t *)(space); \
+ } \
+ splx(s); \
+}
+
+#define FREE(addr, type) { \
+ register struct kmembuckets *kbp; \
+ register struct kmemusage *kup = btokup(addr); \
+ long s = splimp(); \
+ if (1 << kup->ku_indx > MAXALLOCSAVE) { \
+ free((addr), type); \
+ } else { \
+ kbp = &bucket[kup->ku_indx]; \
+ if (kbp->kb_next == NULL) \
+ kbp->kb_next = (caddr_t)(addr); \
+ else \
+ *(caddr_t *)(kbp->kb_last) = (caddr_t)(addr); \
+ *(caddr_t *)(addr) = NULL; \
+ kbp->kb_last = (caddr_t)(addr); \
+ } \
+ splx(s); \
+}
+#endif /* do not collect statistics */
+
+extern struct kmemstats kmemstats[];
+extern struct kmemusage *kmemusage;
+extern char *kmembase;
+extern struct kmembuckets bucket[];
+
+void free (void *addr, int type);
+void *malloc (size_t size, int type, int flags);
+/* standard realloc but we cannot include stdlib.h */
+void *realloc(void * __r, size_t __size);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_MALLOC_H_ */
diff --git a/cpukit/libnetworking/sys/mbuf.h b/cpukit/libnetworking/sys/mbuf.h
new file mode 100644
index 0000000000..bad425e4ae
--- /dev/null
+++ b/cpukit/libnetworking/sys/mbuf.h
@@ -0,0 +1,440 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
+ * $FreeBSD: src/sys/sys/mbuf.h,v 1.169 2005/03/17 19:34:57 jmg Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_MBUF_H_
+#define _SYS_MBUF_H_
+
+#ifndef M_WAITOK
+#include <sys/malloc.h>
+#endif
+
+/*
+ * Mbufs are of a single size, MSIZE (machine/machparam.h), which
+ * includes overhead. An mbuf may add a single "mbuf cluster" of size
+ * MCLBYTES (also in machine/machparam.h), which has no additional overhead
+ * and is used instead of the internal data area; this is done when
+ * at least MINCLSIZE of data must be stored.
+ */
+
+#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
+#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
+#define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */
+#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
+
+/*-
+ * Macros for type conversion:
+ * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type.
+ * dtom(x) -- Convert data pointer within mbuf to mbuf pointer (XXX).
+ * mtocl(x) -- Convert pointer within cluster to cluster index #
+ * cltom(x) -- Convert cluster # to ptr to beginning of cluster
+ */
+#define mtod(m, t) ((t)((m)->m_data))
+#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1)))
+#define mtocl(x) (((uintptr_t)(x) - (uintptr_t)mbutl) >> MCLSHIFT)
+#define cltom(x) ((caddr_t)((u_long)mbutl + ((u_long)(x) << MCLSHIFT)))
+
+/*
+ * Header present at the beginning of every mbuf.
+ */
+struct m_hdr {
+ struct mbuf *mh_next; /* next buffer in chain */
+ struct mbuf *mh_nextpkt; /* next chain in queue/record */
+ caddr_t mh_data; /* location of data */
+ int mh_len; /* amount of data in this mbuf */
+ int mh_flags; /* flags; see below */
+ short mh_type; /* type of data in this mbuf */
+};
+
+/*
+ * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set.
+ */
+struct pkthdr {
+ struct ifnet *rcvif; /* rcv interface */
+ int32_t len; /* total packet length */
+};
+
+/*
+ * Description of external storage mapped into mbuf; valid only if M_EXT is set.
+ */
+struct m_ext {
+ caddr_t ext_buf; /* start of buffer */
+ void (*ext_free) /* free routine if not the usual */
+ (caddr_t, u_int);
+ u_int ext_size; /* size of buffer, for ext_free */
+ void (*ext_ref) /* add a reference to the ext object */
+ (caddr_t, u_int);
+};
+
+/*
+ * The core of the mbuf object along with some shortcut defines for
+ * practical purposes.
+ */
+struct mbuf {
+ struct m_hdr m_hdr;
+ union {
+ struct {
+ struct pkthdr MH_pkthdr; /* M_PKTHDR set */
+ union {
+ struct m_ext MH_ext; /* M_EXT set */
+ char MH_databuf[MHLEN];
+ } MH_dat;
+ } MH;
+ char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
+ } M_dat;
+};
+#define m_next m_hdr.mh_next
+#define m_len m_hdr.mh_len
+#define m_data m_hdr.mh_data
+#define m_type m_hdr.mh_type
+#define m_flags m_hdr.mh_flags
+#define m_nextpkt m_hdr.mh_nextpkt
+#define m_act m_nextpkt
+#define m_pkthdr M_dat.MH.MH_pkthdr
+#define m_ext M_dat.MH.MH_dat.MH_ext
+#define m_pktdat M_dat.MH.MH_dat.MH_databuf
+#define m_dat M_dat.M_databuf
+
+/*
+ * mbuf flags.
+ */
+#define M_EXT 0x0001 /* has associated external storage */
+#define M_PKTHDR 0x0002 /* start of record */
+#define M_EOR 0x0004 /* end of record */
+#define M_PROTO1 0x0008 /* protocol-specific */
+
+/*
+ * mbuf pkthdr flags (also stored in m_flags).
+ */
+#define M_BCAST 0x0100 /* send/received as link-level broadcast */
+#define M_MCAST 0x0200 /* send/received as link-level multicast */
+
+/*
+ * Flags copied when copying m_pkthdr.
+ */
+#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_BCAST|M_MCAST)
+
+/*
+ * mbuf types.
+ */
+#define MT_FREE 0 /* should be on free list */
+#define MT_DATA 1 /* dynamic (data) allocation */
+#define MT_HEADER 2 /* packet header */
+#define MT_SOCKET 3 /* socket structure */
+#define MT_PCB 4 /* protocol control block */
+#define MT_RTABLE 5 /* routing tables */
+#define MT_HTABLE 6 /* IMP host tables */
+#define MT_ATABLE 7 /* address resolution tables */
+#define MT_SONAME 8 /* socket name */
+#define MT_SOOPTS 10 /* socket options */
+#define MT_FTABLE 11 /* fragment reassembly header */
+#define MT_RIGHTS 12 /* access rights */
+#define MT_IFADDR 13 /* interface address */
+#define MT_CONTROL 14 /* extra-data protocol message */
+#define MT_OOBDATA 15 /* expedited data */
+
+/*
+ * General mbuf allocator statistics structure.
+ */
+struct mbstat {
+ u_long m_mbufs; /* mbufs obtained from page pool */
+ u_long m_clusters; /* clusters obtained from page pool */
+ u_long m_spare; /* spare field */
+ u_long m_clfree; /* free clusters */
+ u_long m_drops; /* times failed to find space */
+ u_long m_wait; /* times waited for space */
+ u_long m_drain; /* times drained protocols for space */
+ u_short m_mtypes[256]; /* type specific mbuf allocations */
+};
+
+
+/* flags to m_get/MGET */
+#define M_DONTWAIT M_NOWAIT
+#define M_WAIT M_WAITOK
+
+/* Freelists:
+ *
+ * Normal mbuf clusters are normally treated as character arrays
+ * after allocation, but use the first word of the buffer as a free list
+ * pointer while on the free list.
+ */
+union mcluster {
+ union mcluster *mcl_next;
+ char mcl_buf[MCLBYTES];
+};
+
+/*
+ * mbuf utility macros:
+ *
+ * MBUFLOCK(code)
+ * prevents a section of code from from being interrupted by network
+ * drivers.
+ */
+#define MBUFLOCK(code) \
+ { int ms = splimp(); \
+ { code } \
+ splx(ms); \
+ }
+
+/*
+ * mbuf allocation/deallocation macros:
+ *
+ * MGET(struct mbuf *m, int how, int type)
+ * allocates an mbuf and initializes it to contain internal data.
+ *
+ * MGETHDR(struct mbuf *m, int how, int type)
+ * allocates an mbuf and initializes it to contain a packet header
+ * and internal data.
+ */
+#define MGET(m, how, type) { \
+ int _ms = splimp(); \
+ if (mmbfree == 0) \
+ (void)m_mballoc(1, (how)); \
+ if (((m) = mmbfree) != 0) { \
+ mmbfree = (m)->m_next; \
+ mbstat.m_mtypes[MT_FREE]--; \
+ (m)->m_type = (type); \
+ mbstat.m_mtypes[type]++; \
+ (m)->m_next = (struct mbuf *)NULL; \
+ (m)->m_nextpkt = (struct mbuf *)NULL; \
+ (m)->m_data = (m)->m_dat; \
+ (m)->m_flags = 0; \
+ splx(_ms); \
+ } else { \
+ splx(_ms); \
+ (m) = m_retry((how), (type)); \
+ } \
+}
+
+#define MGETHDR(m, how, type) { \
+ int _ms = splimp(); \
+ if (mmbfree == 0) \
+ (void)m_mballoc(1, (how)); \
+ if (((m) = mmbfree) != 0) { \
+ mmbfree = (m)->m_next; \
+ mbstat.m_mtypes[MT_FREE]--; \
+ (m)->m_type = (type); \
+ mbstat.m_mtypes[type]++; \
+ (m)->m_next = (struct mbuf *)NULL; \
+ (m)->m_nextpkt = (struct mbuf *)NULL; \
+ (m)->m_data = (m)->m_pktdat; \
+ (m)->m_flags = M_PKTHDR; \
+ splx(_ms); \
+ } else { \
+ splx(_ms); \
+ (m) = m_retryhdr((how), (type)); \
+ } \
+}
+
+/*
+ * Mbuf cluster macros.
+ * MCLALLOC(caddr_t p, int how) allocates an mbuf cluster.
+ * MCLGET adds such clusters to a normal mbuf;
+ * the flag M_EXT is set upon success.
+ * MCLFREE releases a reference to a cluster allocated by MCLALLOC,
+ * freeing the cluster if the reference count has reached 0.
+ */
+#define MCLALLOC(p, how) \
+ MBUFLOCK( \
+ if (mclfree == 0) \
+ (void)m_clalloc(1, (how)); \
+ if (((p) = (caddr_t)mclfree) != 0) { \
+ ++mclrefcnt[mtocl(p)]; \
+ mbstat.m_clfree--; \
+ mclfree = ((union mcluster *)(p))->mcl_next; \
+ } \
+ )
+
+#define MCLGET(m, how) \
+ { MCLALLOC((m)->m_ext.ext_buf, (how)); \
+ if ((m)->m_ext.ext_buf != NULL) { \
+ (m)->m_data = (m)->m_ext.ext_buf; \
+ (m)->m_flags |= M_EXT; \
+ (m)->m_ext.ext_free = NULL; \
+ (m)->m_ext.ext_ref = NULL; \
+ (m)->m_ext.ext_size = MCLBYTES; \
+ } \
+ }
+
+#define MCLFREE(p) \
+ MBUFLOCK ( \
+ if (--mclrefcnt[mtocl(p)] == 0) { \
+ ((union mcluster *)(p))->mcl_next = mclfree; \
+ mclfree = (union mcluster *)(p); \
+ mbstat.m_clfree++; \
+ } \
+ )
+
+/*
+ * MFREE(struct mbuf *m, struct mbuf *n)
+ * Free a single mbuf and associated external storage.
+ * Place the successor, if any, in n.
+ */
+#define MFREE(m, n) \
+ MBUFLOCK( \
+ mbstat.m_mtypes[(m)->m_type]--; \
+ if ((m)->m_flags & M_EXT) { \
+ if ((m)->m_ext.ext_free) \
+ (*((m)->m_ext.ext_free))((m)->m_ext.ext_buf, \
+ (m)->m_ext.ext_size); \
+ else { \
+ char *p = (m)->m_ext.ext_buf; \
+ if (--mclrefcnt[mtocl(p)] == 0) { \
+ ((union mcluster *)(p))->mcl_next = mclfree; \
+ mclfree = (union mcluster *)(p); \
+ mbstat.m_clfree++; \
+ } \
+ } \
+ } \
+ (n) = (m)->m_next; \
+ (m)->m_type = MT_FREE; \
+ mbstat.m_mtypes[MT_FREE]++; \
+ (m)->m_next = mmbfree; \
+ mmbfree = (m); \
+ )
+
+/*
+ * Copy mbuf pkthdr from from to to.
+ * from must have M_PKTHDR set, and to must be empty.
+ */
+#define M_COPY_PKTHDR(to, from) { \
+ (to)->m_pkthdr = (from)->m_pkthdr; \
+ (to)->m_flags = (from)->m_flags & M_COPYFLAGS; \
+ (to)->m_data = (to)->m_pktdat; \
+}
+
+/*
+ * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
+ * an object of the specified size at the end of the mbuf, longword aligned.
+ */
+#define M_ALIGN(m, len) do { \
+ (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \
+} while (0)
+
+/*
+ * As above, for mbufs allocated with m_gethdr/MGETHDR
+ * or initialized by M_COPY_PKTHDR.
+ */
+#define MH_ALIGN(m, len) do { \
+ (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
+} while (0)
+
+/*
+ * Compute the amount of space available
+ * before the current start of data in an mbuf.
+ */
+#define M_LEADINGSPACE(m) \
+ ((m)->m_flags & M_EXT ? /* (m)->m_data - (m)->m_ext.ext_buf */ 0 : \
+ (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
+ (m)->m_data - (m)->m_dat)
+
+/*
+ * Compute the amount of space available
+ * after the end of data in an mbuf.
+ */
+#define M_TRAILINGSPACE(m) \
+ ((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - \
+ ((m)->m_data + (m)->m_len) : \
+ &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
+
+/*
+ * Arrange to prepend space of size plen to mbuf m.
+ * If a new mbuf must be allocated, how specifies whether to wait.
+ * If how is M_DONTWAIT and allocation fails, the original mbuf chain
+ * is freed and m is set to NULL.
+ */
+#define M_PREPEND(m, plen, how) { \
+ if (M_LEADINGSPACE(m) >= (plen)) { \
+ (m)->m_data -= (plen); \
+ (m)->m_len += (plen); \
+ } else \
+ (m) = m_prepend((m), (plen), (how)); \
+ if ((m) && (m)->m_flags & M_PKTHDR) \
+ (m)->m_pkthdr.len += (plen); \
+}
+
+/*
+ * Change mbuf to new type.
+ * This is a relatively expensive operation and should be avoided.
+ */
+#define MCHTYPE(m, t) { \
+ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--; mbstat.m_mtypes[t]++;) \
+ (m)->m_type = t;\
+}
+
+/* Length to m_copy to copy all. */
+#define M_COPYALL (uint32_t)1000000000L
+
+/* Compatibility with 4.3. */
+#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
+
+#ifdef _KERNEL
+extern struct mbuf *mbutl; /* virtual address of mclusters */
+extern char *mclrefcnt; /* cluster reference counts */
+extern struct mbstat mbstat;
+extern uint32_t nmbclusters;
+extern uint32_t nmbufs;
+extern struct mbuf *mmbfree;
+extern union mcluster *mclfree;
+extern int max_linkhdr; /* largest link-level header */
+extern int max_protohdr; /* largest protocol header */
+extern int max_hdr; /* largest link+protocol header */
+extern int max_datalen; /* MHLEN - max_hdr */
+
+struct mbuf *m_copym(struct mbuf *, int, uint32_t, int);
+struct mbuf *m_copypacket(struct mbuf *, int);
+struct mbuf *m_devget(char *, int, int, struct ifnet *,
+ void (*copy)(char *, caddr_t, u_int));
+struct mbuf *m_free(struct mbuf *);
+struct mbuf *m_get(int, int);
+struct mbuf *m_getclr(int, int);
+struct mbuf *m_gethdr(int, int);
+struct mbuf *m_prepend(struct mbuf *,int,int);
+struct mbuf *m_pullup(struct mbuf *, int);
+struct mbuf *m_retry(int, int);
+struct mbuf *m_retryhdr(int, int);
+struct mbuf *m_split(struct mbuf *,int,int);
+void m_adj(struct mbuf *, int);
+void m_cat(struct mbuf *,struct mbuf *);
+int m_mballoc(int, int);
+int m_clalloc(int, int);
+int m_copyback(struct mbuf *, int, int, caddr_t);
+int m_copydata(const struct mbuf *, int, int, caddr_t);
+void m_freem(struct mbuf *);
+void m_reclaim(void);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_MBUF_H_ */
diff --git a/cpukit/libnetworking/sys/mount.h b/cpukit/libnetworking/sys/mount.h
new file mode 100644
index 0000000000..fec316f2ed
--- /dev/null
+++ b/cpukit/libnetworking/sys/mount.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 1989, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)mount.h 8.21 (Berkeley) 5/20/95
+ * $FreeBSD: src/sys/sys/mount.h,v 1.198 2005/08/06 01:42:04 ssouhlal Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_MOUNT_H_
+#define _SYS_MOUNT_H_
+
+#ifndef _KERNEL
+#include <sys/ucred.h>
+#endif
+#include <sys/queue.h>
+
+typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */
+
+/*
+ * File identifier.
+ * These are unique per filesystem on a single machine.
+ */
+#define MAXFIDSZ 16
+
+struct fid {
+ u_short fid_len; /* length of data in bytes */
+ u_short fid_reserved; /* force longword alignment */
+ char fid_data[MAXFIDSZ]; /* data (variable length) */
+};
+
+/*
+ * filesystem statistics
+ */
+#define MFSNAMELEN 16 /* length of type name including null */
+#define MNAMELEN 88 /* size of on/from name bufs */
+
+/*
+ * User specifiable flags.
+ */
+#define MNT_RDONLY 0x00000001 /* read only filesystem */
+#define MNT_SYNCHRONOUS 0x00000002 /* filesystem written synchronously */
+#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
+#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
+#define MNT_NODEV 0x00000010 /* don't interpret special files */
+#define MNT_UNION 0x00000020 /* union with underlying filesystem */
+#define MNT_ASYNC 0x00000040 /* filesystem written asynchronously */
+#define MNT_NOATIME 0x10000000 /* disable update of file access time */
+
+/*
+ * NFS export related mount flags.
+ */
+#define MNT_EXRDONLY 0x00000080 /* exported read only */
+#define MNT_EXPORTED 0x00000100 /* filesystem is exported */
+#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
+#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
+#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */
+#define MNT_EXPUBLIC 0x20000000 /* public export (WebNFS) */
+
+/*
+ * Flags set by internal operations,
+ * but visible to the user.
+ */
+#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
+#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
+#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
+#define MNT_USER 0x00008000 /* mounted by a user */
+#define MNT_IGNORE 0x00800000 /* do not show entry in df */
+
+/*
+ * External filesystem command modifier flags.
+ * Unmount can use the MNT_FORCE flag.
+ */
+#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
+#define MNT_DELEXPORT 0x00020000 /* delete export host lists */
+#define MNT_RELOAD 0x00040000 /* reload filesystem data */
+#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
+
+/*
+ * Generic file handle
+ */
+struct fhandle {
+ fsid_t fh_fsid; /* Filesystem id of mount point */
+ struct fid fh_fid; /* Filesys specific id */
+};
+typedef struct fhandle fhandle_t;
+
+#ifdef _KERNEL
+
+#else /* !_KERNEL */
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_MOUNT_H_ */
diff --git a/cpukit/libnetworking/sys/poll.h b/cpukit/libnetworking/sys/poll.h
new file mode 100644
index 0000000000..8237ba303c
--- /dev/null
+++ b/cpukit/libnetworking/sys/poll.h
@@ -0,0 +1,104 @@
+/*-
+ * Copyright (c) 1997 Peter Wemm <peter@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/poll.h,v 1.13 2002/07/10 04:47:25 mike Exp $
+ */
+
+#ifndef _SYS_POLL_H_
+#define _SYS_POLL_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+
+/*
+ * This file is intended to be compatible with the traditional poll.h.
+ */
+
+typedef unsigned int nfds_t;
+
+/*
+ * This structure is passed as an array to poll(2).
+ */
+struct pollfd {
+ int fd; /* which file descriptor to poll */
+ short events; /* events we are interested in */
+ short revents; /* events found on return */
+};
+
+/*
+ * Requestable events. If poll(2) finds any of these set, they are
+ * copied to revents on return.
+ * XXX Note that FreeBSD doesn't make much distinction between POLLPRI
+ * and POLLRDBAND since none of the file types have distinct priority
+ * bands - and only some have an urgent "mode".
+ * XXX Note POLLIN isn't really supported in true SVSV terms. Under SYSV
+ * POLLIN includes all of normal, band and urgent data. Most poll handlers
+ * on FreeBSD only treat it as "normal" data.
+ */
+#define POLLIN 0x0001 /* any readable data available */
+#define POLLPRI 0x0002 /* OOB/Urgent readable data */
+#define POLLOUT 0x0004 /* file descriptor is writeable */
+#define POLLRDNORM 0x0040 /* non-OOB/URG data available */
+#define POLLWRNORM POLLOUT /* no write type differentiation */
+#define POLLRDBAND 0x0080 /* OOB/Urgent readable data */
+#define POLLWRBAND 0x0100 /* OOB/Urgent data can be written */
+
+#if __BSD_VISIBLE
+/* General FreeBSD extension (currently only supported for sockets): */
+#define POLLINIGNEOF 0x2000 /* like POLLIN, except ignore EOF */
+#endif
+
+/*
+ * These events are set if they occur regardless of whether they were
+ * requested.
+ */
+#define POLLERR 0x0008 /* some poll error occurred */
+#define POLLHUP 0x0010 /* file descriptor was "hung up" */
+#define POLLNVAL 0x0020 /* requested events "invalid" */
+
+#if __BSD_VISIBLE
+
+#define POLLSTANDARD (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|\
+ POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
+
+/*
+ * Request that poll() wait forever.
+ * XXX in SYSV, this is defined in stropts.h, which is not included
+ * by poll.h.
+ */
+#define INFTIM (-1)
+
+#endif
+
+#ifndef _KERNEL
+
+__BEGIN_DECLS
+int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_POLL_H_ */
diff --git a/cpukit/libnetworking/sys/proc.h b/cpukit/libnetworking/sys/proc.h
new file mode 100644
index 0000000000..2189a33b11
--- /dev/null
+++ b/cpukit/libnetworking/sys/proc.h
@@ -0,0 +1,8 @@
+/*
+ * Dummy structure
+ *
+ * $Id$
+ */
+struct proc {
+ int this_should_never_be_referenced;
+};
diff --git a/cpukit/libnetworking/sys/protosw.h b/cpukit/libnetworking/sys/protosw.h
new file mode 100644
index 0000000000..e1119f9378
--- /dev/null
+++ b/cpukit/libnetworking/sys/protosw.h
@@ -0,0 +1,300 @@
+/*-
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)protosw.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: src/sys/sys/protosw.h,v 1.43 2004/04/07 04:19:49 imp Exp $
+ */
+
+#ifndef _SYS_PROTOSW_H_
+#define _SYS_PROTOSW_H_
+
+/* Forward declare these structures referenced from prototypes below. */
+struct mbuf;
+struct sockaddr;
+struct socket;
+struct sockproto;
+struct stat;
+
+/*
+ * Protocol switch table.
+ *
+ * Each protocol has a handle initializing one of these structures,
+ * which is used for protocol-protocol and system-protocol communication.
+ *
+ * A protocol is called through the pr_init entry before any other.
+ * Thereafter it is called every 200ms through the pr_fasttimo entry and
+ * every 500ms through the pr_slowtimo for timer based actions.
+ * The system will call the pr_drain entry if it is low on space and
+ * this should throw away any non-critical data.
+ *
+ * Protocols pass data between themselves as chains of mbufs using
+ * the pr_input and pr_output hooks. Pr_input passes data up (towards
+ * UNIX) and pr_output passes it down (towards the imps); control
+ * information passes up and down on pr_ctlinput and pr_ctloutput.
+ * The protocol is responsible for the space occupied by any the
+ * arguments to these entries and must dispose it.
+ *
+ * The userreq routine interfaces protocols to the system and is
+ * described below.
+ */
+struct protosw {
+ short pr_type; /* socket type used for */
+ struct domain *pr_domain; /* domain protocol a member of */
+ short pr_protocol; /* protocol number */
+ short pr_flags; /* see below */
+/* protocol-protocol hooks */
+ void (*pr_input)(struct mbuf *, int len);
+ /* input to protocol (from below) */
+ int (*pr_output)(struct mbuf *m, struct socket *so);
+ /* output to protocol (from above) */
+ void (*pr_ctlinput)(int, struct sockaddr *, void *);
+ /* control input (from below) */
+ int (*pr_ctloutput)(int, struct socket *, int, int,
+ struct mbuf **);
+ /* control output (from above) */
+/* user-protocol hook */
+ int (*pr_ousrreq)(struct socket *, int, struct mbuf *,
+ struct mbuf *, struct mbuf *);
+ /* user request: see list below */
+/* utility hooks */
+ void (*pr_init)(void); /* initialization hook */
+ void (*pr_fasttimo)(void);
+ /* fast timeout (200ms) */
+ void (*pr_slowtimo)(void);
+ /* slow timeout (500ms) */
+ void (*pr_drain)(void);
+ /* flush any excess space possible */
+ struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */
+};
+
+#define PR_SLOWHZ 2L /* 2 slow timeouts per second */
+#define PR_FASTHZ 5L /* 5 fast timeouts per second */
+
+/*
+ * Values for pr_flags.
+ * PR_ADDR requires PR_ATOMIC;
+ * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
+ * PR_IMPLOPCL means that the protocol allows sendto without prior connect,
+ * and the protocol understands the MSG_EOF flag. The first property is
+ * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
+ * anyhow).
+ */
+#define PR_ATOMIC 0x01 /* exchange atomic messages only */
+#define PR_ADDR 0x02 /* addresses given with messages */
+#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
+#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
+#define PR_RIGHTS 0x10 /* passes capabilities */
+#define PR_IMPLOPCL 0x20 /* implied open/close */
+#define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */
+
+/*
+ * The arguments to usrreq are:
+ * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
+ * where up is a (struct socket *), req is one of these requests,
+ * m is an optional mbuf chain containing a message,
+ * nam is an optional mbuf chain containing an address,
+ * and opt is a pointer to a socketopt structure or nil.
+ * The protocol is responsible for disposal of the mbuf chain m,
+ * the caller is responsible for any space held by nam and opt.
+ * A non-zero return from usrreq gives an
+ * UNIX error number which should be passed to higher level software.
+ */
+#define PRU_ATTACH 0 /* attach protocol to up */
+#define PRU_DETACH 1 /* detach protocol from up */
+#define PRU_BIND 2 /* bind socket to address */
+#define PRU_LISTEN 3 /* listen for connection */
+#define PRU_CONNECT 4 /* establish connection to peer */
+#define PRU_ACCEPT 5 /* accept connection from peer */
+#define PRU_DISCONNECT 6 /* disconnect from peer */
+#define PRU_SHUTDOWN 7 /* won't send any more data */
+#define PRU_RCVD 8 /* have taken data; more room now */
+#define PRU_SEND 9 /* send this data */
+#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
+#define PRU_CONTROL 11 /* control operations on protocol */
+#define PRU_SENSE 12 /* return status into m */
+#define PRU_RCVOOB 13 /* retrieve out of band data */
+#define PRU_SENDOOB 14 /* send out of band data */
+#define PRU_SOCKADDR 15 /* fetch socket's address */
+#define PRU_PEERADDR 16 /* fetch peer's address */
+#define PRU_CONNECT2 17 /* connect two sockets */
+/* begin for protocols internal use */
+#define PRU_FASTTIMO 18 /* 200ms timeout */
+#define PRU_SLOWTIMO 19 /* 500ms timeout */
+#define PRU_PROTORCV 20 /* receive from below */
+#define PRU_PROTOSEND 21 /* send to below */
+/* end for protocol's internal use */
+#define PRU_SEND_EOF 22 /* send and close */
+#define PRU_NREQ 22
+
+#ifdef PRUREQUESTS
+const char *prurequests[] = {
+ "ATTACH", "DETACH", "BIND", "LISTEN",
+ "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
+ "RCVD", "SEND", "ABORT", "CONTROL",
+ "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
+ "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
+ "PROTORCV", "PROTOSEND",
+ "SEND_EOF",
+};
+#endif
+
+#ifdef _KERNEL /* users shouldn't see this decl */
+struct stat;
+struct ifnet;
+
+/*
+ * If the ordering here looks odd, that's because it's alphabetical.
+ */
+struct pr_usrreqs {
+ int (*pru_abort)(struct socket *so);
+ int (*pru_accept)(struct socket *so, struct mbuf *nam);
+ int (*pru_attach)(struct socket *so, intptr_t proto);
+ int (*pru_bind)(struct socket *so, struct mbuf *nam);
+ int (*pru_connect)(struct socket *so, struct mbuf *nam);
+ int (*pru_connect2)(struct socket *so1, struct socket *so2);
+ int (*pru_control)(struct socket *so, intptr_t cmd, caddr_t data,
+ struct ifnet *ifp);
+ int (*pru_detach)(struct socket *so);
+ int (*pru_disconnect)(struct socket *so);
+ int (*pru_listen)(struct socket *so);
+ int (*pru_peeraddr)(struct socket *so, struct mbuf *nam);
+ int (*pru_rcvd)(struct socket *so, intptr_t flags);
+ int (*pru_rcvoob)(struct socket *so, struct mbuf *m,
+ intptr_t flags);
+ /*
+ * The `m' parameter here is almost certainly going to become a
+ * `struct uio' at some point in the future. Similar changes
+ * will probably happen for the receive entry points.
+ */
+ int (*pru_send)(struct socket *so, int flags, struct mbuf *m,
+ struct mbuf *addr, struct mbuf *control);
+#define PRUS_OOB 0x1
+#define PRUS_EOF 0x2
+ int (*pru_sense)(struct socket *so, struct stat *sb);
+ int (*pru_shutdown)(struct socket *so);
+ int (*pru_sockaddr)(struct socket *so, struct mbuf *nam);
+};
+
+int pru_accept_notsupp(struct socket *so, struct mbuf *nam);
+int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
+int pru_control_notsupp(struct socket *so, int cmd, caddr_t data,
+ struct ifnet *ifp);
+int pru_listen_notsupp(struct socket *so);
+int pru_rcvd_notsupp(struct socket *so, int flags);
+int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags);
+int pru_sense_null(struct socket *so, struct stat *sb);
+
+#define PRU_OLDSTYLE
+
+#ifdef PRU_OLDSTYLE
+/*
+ * Protocols which don't yet implement pr_usrreqs can point it to this
+ * structure, which will call the old pr_usrreq() entry point with the
+ * appropriate arguments.
+ */
+extern struct pr_usrreqs pru_oldstyle;
+#endif /* PRU_OLDSTYLE */
+
+#endif /* _KERNEL */
+
+/*
+ * The arguments to the ctlinput routine are
+ * (*protosw[].pr_ctlinput)(cmd, sa, arg);
+ * where cmd is one of the commands below, sa is a pointer to a sockaddr,
+ * and arg is a `void *' argument used within a protocol family.
+ */
+#define PRC_IFDOWN 0 /* interface transition */
+#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
+#define PRC_IFUP 2 /* interface has come back up */
+#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
+#define PRC_QUENCH 4 /* some one said to slow down */
+#define PRC_MSGSIZE 5 /* message size forced drop */
+#define PRC_HOSTDEAD 6 /* host appears to be down */
+#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
+#define PRC_UNREACH_NET 8 /* no route to network */
+#define PRC_UNREACH_HOST 9 /* no route to host */
+#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
+#define PRC_UNREACH_PORT 11 /* bad port # */
+/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
+#define PRC_UNREACH_SRCFAIL 13 /* source route failed */
+#define PRC_REDIRECT_NET 14 /* net routing redirect */
+#define PRC_REDIRECT_HOST 15 /* host routing redirect */
+#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
+#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
+#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
+#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
+#define PRC_PARAMPROB 20 /* header incorrect */
+#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */
+
+#define PRC_NCMDS 22
+
+#define PRC_IS_REDIRECT(cmd) \
+ ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
+
+#ifdef PRCREQUESTS
+char *prcrequests[] = {
+ "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
+ "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
+ "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
+ "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
+ "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
+ "PARAMPROB", "ADMIN-UNREACH"
+};
+#endif
+
+/*
+ * The arguments to ctloutput are:
+ * (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
+ * req is one of the actions listed below, so is a (struct socket *),
+ * level is an indication of which protocol layer the option is intended.
+ * optname is a protocol dependent socket option request,
+ * optval is a pointer to a mbuf-chain pointer, for value-return results.
+ * The protocol is responsible for disposal of the mbuf chain *optval
+ * if supplied,
+ * the caller is responsible for any space held by *optval, when returned.
+ * A non-zero return from usrreq gives an
+ * UNIX error number which should be passed to higher level software.
+ */
+#define PRCO_GETOPT 0
+#define PRCO_SETOPT 1
+
+#define PRCO_NCMDS 2
+
+#ifdef PRCOREQUESTS
+char *prcorequests[] = {
+ "GETOPT", "SETOPT",
+};
+#endif
+
+#ifdef _KERNEL
+void pfctlinput(int, struct sockaddr *);
+struct protosw *pffindproto(int family, int protocol, int type);
+struct protosw *pffindtype(int family, int type);
+#endif
+
+#endif
diff --git a/cpukit/libnetworking/sys/reboot.h b/cpukit/libnetworking/sys/reboot.h
new file mode 100644
index 0000000000..48a7f0f782
--- /dev/null
+++ b/cpukit/libnetworking/sys/reboot.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)reboot.h 8.3 (Berkeley) 12/13/94
+ * $Id$
+ */
+
+#ifndef _SYS_REBOOT_H_
+#define _SYS_REBOOT_H_
+
+/*
+ * Arguments to reboot system call. These are passed to
+ * the boot program and on to init.
+ */
+#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */
+
+#define RB_ASKNAME 0x001 /* ask for file name to reboot from */
+#define RB_SINGLE 0x002 /* reboot to single user only */
+#define RB_NOSYNC 0x004 /* dont sync before reboot */
+#define RB_HALT 0x008 /* don't reboot, just halt */
+#define RB_INITNAME 0x010 /* name given for /etc/init (unused) */
+#define RB_DFLTROOT 0x020 /* use compiled-in rootdev */
+#define RB_KDB 0x040 /* give control to kernel debugger */
+#define RB_RDONLY 0x080 /* mount root fs read-only */
+#define RB_DUMP 0x100 /* dump kernel memory before reboot */
+#define RB_MINIROOT 0x200 /* mini-root present in memory at boot time */
+#define RB_CONFIG 0x400 /* invoke user configuration routing */
+#define RB_VERBOSE 0x800 /* print all potentially useful info */
+#define RB_SERIAL 0x1000 /* user serial port as console */
+#define RB_CDROM 0x2000 /* use cdrom as root */
+#define RB_POWEROFF 0x4000 /* if you can, turn the power off */
+#define RB_GDB 0x8000 /* use GDB remote debugger instead of DDB */
+#define RB_MUTE 0x10000 /* Come up with the console muted */
+#define RB_SELFTEST 0x20000 /* don't boot to normal operation, do selftest */
+
+#define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */
+
+/*
+ * Constants for converting boot-style device number to type,
+ * adaptor (uba, mba, etc), unit number and partition number.
+ * Type (== major device number) is in the low byte
+ * for backward compatibility. Except for that of the "magic
+ * number", each mask applies to the shifted value.
+ * Format:
+ * (4) (4) (4) (4) (8) (8)
+ * --------------------------------
+ * |MA | AD| CT| UN| PART | TYPE |
+ * --------------------------------
+ */
+#define B_ADAPTORSHIFT 24
+#define B_ADAPTORMASK 0x0f
+#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK)
+#define B_CONTROLLERSHIFT 20
+#define B_CONTROLLERMASK 0xf
+#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK)
+#define B_SLICESHIFT 20
+#define B_SLICEMASK 0xff
+#define B_SLICE(val) (((val)>>B_SLICESHIFT) & B_SLICEMASK)
+#define B_UNITSHIFT 16
+#define B_UNITMASK 0xf
+#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK)
+#define B_PARTITIONSHIFT 8
+#define B_PARTITIONMASK 0xff
+#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK)
+#define B_TYPESHIFT 0
+#define B_TYPEMASK 0xff
+#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK)
+
+#define B_MAGICMASK 0xf0000000
+#define B_DEVMAGIC 0xa0000000
+
+#define MAKEBOOTDEV(type, adaptor, controller, unit, partition) \
+ (((type) << B_TYPESHIFT) | ((adaptor) << B_ADAPTORSHIFT) | \
+ ((controller) << B_CONTROLLERSHIFT) | ((unit) << B_UNITSHIFT) | \
+ ((partition) << B_PARTITIONSHIFT) | B_DEVMAGIC)
+
+#endif
diff --git a/cpukit/libnetworking/sys/resourcevar.h b/cpukit/libnetworking/sys/resourcevar.h
new file mode 100644
index 0000000000..2b4c47e48f
--- /dev/null
+++ b/cpukit/libnetworking/sys/resourcevar.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+/* intentionally empty file */
diff --git a/cpukit/libnetworking/sys/select.h b/cpukit/libnetworking/sys/select.h
new file mode 100644
index 0000000000..0b99ba50b8
--- /dev/null
+++ b/cpukit/libnetworking/sys/select.h
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)select.h 8.2 (Berkeley) 1/4/94
+ * $Id$
+ */
+
+#ifndef _SYS_SELECT_H_
+#define _SYS_SELECT_H_
+
+#include <sys/time.h> /* struct timeval */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Used to maintain information about processes that wish to be
+ * notified when I/O becomes possible.
+ */
+struct selinfo {
+ pid_t si_pid; /* process to be notified */
+ short si_flags; /* see below */
+};
+#define SI_COLL 0x0001 /* collision occurred */
+
+/* Check the first NFDS descriptors each in READFDS (if not NULL) for read
+ readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
+ (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
+ after waiting the interval specified therein. Returns the number of ready
+ descriptors, or -1 for errors. */
+extern int select (int __nfds, fd_set *__readfds,
+ fd_set *__writefds,
+ fd_set *__exceptfds,
+ struct timeval *__timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_SYS_SELECT_H_ */
diff --git a/cpukit/libnetworking/sys/signalvar.h b/cpukit/libnetworking/sys/signalvar.h
new file mode 100644
index 0000000000..83c9b4dc96
--- /dev/null
+++ b/cpukit/libnetworking/sys/signalvar.h
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)signalvar.h 8.6 (Berkeley) 2/19/95
+ * $Id$
+ */
+
+#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
+#define _SYS_SIGNALVAR_H_
+
+/*
+ * Kernel signal definitions and data structures,
+ * not exported to user programs.
+ */
+
+#if !defined(__rtems__)
+/*
+ * Process signal actions and state, needed only within the process
+ * (not necessarily resident).
+ */
+struct sigacts {
+ sig_t ps_sigact[NSIG]; /* disposition of signals */
+ sigset_t ps_catchmask[NSIG]; /* signals to be blocked */
+ sigset_t ps_sigonstack; /* signals to take on sigstack */
+ sigset_t ps_sigintr; /* signals that interrupt syscalls */
+ sigset_t ps_sigreset; /* signals that reset when caught */
+ sigset_t ps_signodefer; /* signals not masked while handled */
+ sigset_t ps_oldmask; /* saved mask from before sigpause */
+ int ps_flags; /* signal flags, below */
+ struct sigaltstack ps_sigstk; /* sp & on stack state variable */
+ int ps_sig; /* for core dump/debugger XXX */
+ u_long ps_code; /* for core dump/debugger XXX */
+ sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */
+};
+#endif
+
+/* signal flags */
+#define SAS_OLDMASK 0x01 /* need to restore mask before pause */
+#define SAS_ALTSTACK 0x02 /* have alternate signal stack */
+
+/* additional signal action values, used only temporarily/internally */
+#define SIG_CATCH ((__sighandler_t *)2)
+#define SIG_HOLD ((__sighandler_t *)3)
+
+#if !defined(__rtems__)
+/*
+ * get signal action for process and signal; currently only for current process
+ */
+#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[(sig)])
+#endif
+
+/*
+ * Determine signal that should be delivered to process p, the current
+ * process, 0 if none. If there is a pending stop signal with default
+ * action, the process stops in issignal().
+ */
+#define CURSIG(p) \
+ (((p)->p_siglist == 0 || \
+ (((p)->p_flag & P_TRACED) == 0 && \
+ ((p)->p_siglist & ~(p)->p_sigmask) == 0)) ? \
+ 0 : issignal(p))
+
+/*
+ * Clear a pending signal from a process.
+ */
+#define CLRSIG(p, sig) { (p)->p_siglist &= ~sigmask(sig); }
+
+/*
+ * Signal properties and actions.
+ * The array below categorizes the signals and their default actions
+ * according to the following properties:
+ */
+#define SA_KILL 0x01 /* terminates process by default */
+#define SA_CORE 0x02 /* ditto and coredumps */
+#define SA_STOP 0x04 /* suspend process */
+#define SA_TTYSTOP 0x08 /* ditto, from tty */
+#define SA_IGNORE 0x10 /* ignore by default */
+#define SA_CONT 0x20 /* continue if suspended */
+#define SA_CANTMASK 0x40 /* non-maskable, catchable */
+
+#ifdef SIGPROP
+static int sigprop[NSIG + 1] = {
+ 0, /* unused */
+ SA_KILL, /* SIGHUP */
+ SA_KILL, /* SIGINT */
+ SA_KILL|SA_CORE, /* SIGQUIT */
+ SA_KILL|SA_CORE, /* SIGILL */
+ SA_KILL|SA_CORE, /* SIGTRAP */
+ SA_KILL|SA_CORE, /* SIGABRT */
+ SA_KILL|SA_CORE, /* SIGEMT */
+ SA_KILL|SA_CORE, /* SIGFPE */
+ SA_KILL, /* SIGKILL */
+ SA_KILL|SA_CORE, /* SIGBUS */
+ SA_KILL|SA_CORE, /* SIGSEGV */
+ SA_KILL|SA_CORE, /* SIGSYS */
+ SA_KILL, /* SIGPIPE */
+ SA_KILL, /* SIGALRM */
+ SA_KILL, /* SIGTERM */
+ SA_IGNORE, /* SIGURG */
+ SA_STOP, /* SIGSTOP */
+ SA_STOP|SA_TTYSTOP, /* SIGTSTP */
+ SA_IGNORE|SA_CONT, /* SIGCONT */
+ SA_IGNORE, /* SIGCHLD */
+ SA_STOP|SA_TTYSTOP, /* SIGTTIN */
+ SA_STOP|SA_TTYSTOP, /* SIGTTOU */
+ SA_IGNORE, /* SIGIO */
+ SA_KILL, /* SIGXCPU */
+ SA_KILL, /* SIGXFSZ */
+ SA_KILL, /* SIGVTALRM */
+ SA_KILL, /* SIGPROF */
+ SA_IGNORE, /* SIGWINCH */
+ SA_IGNORE, /* SIGINFO */
+ SA_KILL, /* SIGUSR1 */
+ SA_KILL, /* SIGUSR2 */
+};
+
+#define contsigmask (sigmask(SIGCONT))
+#define stopsigmask (sigmask(SIGSTOP) | sigmask(SIGTSTP) | \
+ sigmask(SIGTTIN) | sigmask(SIGTTOU))
+
+#endif /* SIGPROP */
+
+#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
+
+#ifdef _KERNEL
+/*
+ * Machine-independent functions:
+ */
+void execsigs(struct proc *p);
+void gsignal(int pgid, int sig);
+int issignal(struct proc *p);
+void killproc(struct proc *p, char *why);
+void pgsignal(struct pgrp *pgrp, int sig, int checkctty);
+void postsig(int sig);
+void psignal(struct proc *p, int sig);
+void setsigvec(struct proc *p, int signum, struct sigaction *sa);
+void sigexit(struct proc *p, int signum);
+void siginit(struct proc *p);
+void trapsignal(struct proc *p, int sig, u_long code);
+
+/*
+ * Machine-dependent functions:
+ */
+void sendsig(sig_t action, int sig, int returnmask, u_long code);
+#endif /* _KERNEL */
+#endif /* !_SYS_SIGNALVAR_H_ */
diff --git a/cpukit/libnetworking/sys/socket.h b/cpukit/libnetworking/sys/socket.h
new file mode 100644
index 0000000000..0bc1dcdefa
--- /dev/null
+++ b/cpukit/libnetworking/sys/socket.h
@@ -0,0 +1,407 @@
+/*
+ * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)socket.h 8.4 (Berkeley) 2/21/94
+ * $FreeBSD: src/sys/sys/socket.h,v 1.88 2005/04/13 00:01:46 mdodd Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_SOCKET_H_
+#define _SYS_SOCKET_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <rtems/bsdnet/_types.h>
+
+/*
+ * Definitions related to sockets: types, address families, options.
+ */
+
+/*
+ * Data types.
+ */
+
+#ifndef _SA_FAMILY_T_DECLARED
+typedef __sa_family_t sa_family_t;
+#define _SA_FAMILY_T_DECLARED
+#endif
+
+#ifndef _SOCKLEN_T_DECLARED
+typedef __socklen_t socklen_t;
+#define _SOCKLEN_T_DECLARED
+#endif
+
+/*
+ * Types
+ */
+#define SOCK_STREAM 1 /* stream socket */
+#define SOCK_DGRAM 2 /* datagram socket */
+#define SOCK_RAW 3 /* raw-protocol interface */
+#if __BSD_VISIBLE
+#define SOCK_RDM 4 /* reliably-delivered message */
+#endif
+#define SOCK_SEQPACKET 5 /* sequenced packet stream */
+
+/*
+ * Option flags per-socket.
+ */
+#define SO_DEBUG 0x0001 /* turn on debugging info recording */
+#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
+#define SO_REUSEADDR 0x0004 /* allow local address reuse */
+#define SO_KEEPALIVE 0x0008 /* keep connections alive */
+#define SO_DONTROUTE 0x0010 /* just use interface addresses */
+#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
+#if __BSD_VISIBLE
+#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
+#endif
+#define SO_LINGER 0x0080 /* linger on close if data present */
+#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
+#if __BSD_VISIBLE
+#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
+#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
+#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
+#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
+#define SO_BINTIME 0x2000 /* timestamp received dgram traffic */
+#endif
+
+/*
+ * Additional options, not kept in so_options.
+ */
+#define SO_SNDBUF 0x1001 /* send buffer size */
+#define SO_RCVBUF 0x1002 /* receive buffer size */
+#define SO_SNDLOWAT 0x1003 /* send low-water mark */
+#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
+#define SO_SNDTIMEO 0x1005 /* send timeout */
+#define SO_RCVTIMEO 0x1006 /* receive timeout */
+#define SO_ERROR 0x1007 /* get error status and clear */
+#define SO_TYPE 0x1008 /* get socket type */
+#define SO_PRIVSTATE 0x1009 /* get/deny privileged state */
+
+/*
+ * RTEMS addition: get and set wakeup functions.
+ */
+#define SO_SNDWAKEUP 0x1020 /* wakeup when ready to send */
+#define SO_RCVWAKEUP 0x1021 /* wakeup when ready to receive */
+
+/*
+ * Structure used for manipulating linger option.
+ */
+struct linger {
+ int l_onoff; /* option on/off */
+ int l_linger; /* linger time */
+};
+
+/*
+ * RTEMS addition: structure used to get and set wakeup function.
+ */
+struct socket;
+struct sockwakeup {
+ void (*sw_pfn)(struct socket *, void *);
+ void *sw_arg;
+};
+
+/*
+ * Level number for (get/set)sockopt() to apply to socket itself.
+ */
+#define SOL_SOCKET 0xffff /* options for socket level */
+
+/*
+ * Address families.
+ */
+#define AF_UNSPEC 0 /* unspecified */
+#if __BSD_VISIBLE
+#define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */
+#endif
+#define AF_UNIX 1 /* standardized name for AF_LOCAL */
+#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
+#if __BSD_VISIBLE
+#define AF_IMPLINK 3 /* arpanet imp addresses */
+#define AF_PUP 4 /* pup protocols: e.g. BSP */
+#define AF_CHAOS 5 /* mit CHAOS protocols */
+#define AF_NETBIOS 6 /* SMB protocols */
+#define AF_ISO 7 /* ISO protocols */
+#define AF_OSI AF_ISO
+#define AF_ECMA 8 /* European computer manufacturers */
+#define AF_DATAKIT 9 /* datakit protocols */
+#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
+#define AF_SNA 11 /* IBM SNA */
+#define AF_DECnet 12 /* DECnet */
+#define AF_DLI 13 /* DEC Direct data link interface */
+#define AF_LAT 14 /* LAT */
+#define AF_HYLINK 15 /* NSC Hyperchannel */
+#define AF_APPLETALK 16 /* Apple Talk */
+#define AF_ROUTE 17 /* Internal Routing Protocol */
+#define AF_LINK 18 /* Link layer interface */
+#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
+#define AF_COIP 20 /* connection-oriented IP, aka ST II */
+#define AF_CNT 21 /* Computer Network Technology */
+#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
+#define AF_IPX 23 /* Novell Internet Protocol */
+#define AF_SIP 24 /* Simple Internet Protocol */
+#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
+#define AF_ISDN 26 /* Integrated Services Digital Network*/
+#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
+#define pseudo_AF_KEY 27 /* Internal key-management function */
+#endif
+#define AF_INET6 28 /* IPv6 */
+
+#define AF_MAX 29
+
+/*
+ * Structure used by kernel to store most
+ * addresses.
+ */
+struct sockaddr {
+ unsigned char sa_len; /* total length */
+ sa_family_t sa_family; /* address family */
+ char sa_data[14]; /* actually longer; address value */
+};
+
+/*
+ * Structure used by kernel to pass protocol
+ * information in raw sockets.
+ */
+struct sockproto {
+ unsigned short sp_family; /* address family */
+ unsigned short sp_protocol; /* protocol */
+};
+
+/*
+ * Protocol families, same as address families for now.
+ */
+#define PF_UNSPEC AF_UNSPEC
+#define PF_LOCAL AF_LOCAL
+#define PF_UNIX PF_LOCAL /* backward compatibility */
+#define PF_INET AF_INET
+#define PF_IMPLINK AF_IMPLINK
+#define PF_PUP AF_PUP
+#define PF_CHAOS AF_CHAOS
+#define PF_NETBIOS AF_NETBIOS
+#define PF_ISO AF_ISO
+#define PF_OSI AF_ISO
+#define PF_ECMA AF_ECMA
+#define PF_DATAKIT AF_DATAKIT
+#define PF_CCITT AF_CCITT
+#define PF_SNA AF_SNA
+#define PF_DECnet AF_DECnet
+#define PF_DLI AF_DLI
+#define PF_LAT AF_LAT
+#define PF_HYLINK AF_HYLINK
+#define PF_APPLETALK AF_APPLETALK
+#define PF_ROUTE AF_ROUTE
+#define PF_LINK AF_LINK
+#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
+#define PF_COIP AF_COIP
+#define PF_CNT AF_CNT
+#define PF_SIP AF_SIP
+#define PF_IPX AF_IPX
+#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
+#define PF_PIP pseudo_AF_PIP
+#define PF_ISDN AF_ISDN
+#define PF_KEY pseudo_AF_KEY
+#define PF_INET6 AF_INET6
+
+#define PF_MAX AF_MAX
+
+/*
+ * Definitions for network related sysctl, CTL_NET.
+ *
+ * Second level is protocol family.
+ * Third level is protocol number.
+ *
+ * Further levels are defined by the individual families below.
+ */
+#define NET_MAXID AF_MAX
+
+#define CTL_NET_NAMES { \
+ { 0, 0 }, \
+ { "unix", CTLTYPE_NODE }, \
+ { "inet", CTLTYPE_NODE }, \
+ { "implink", CTLTYPE_NODE }, \
+ { "pup", CTLTYPE_NODE }, \
+ { "chaos", CTLTYPE_NODE }, \
+ { "xerox_ns", CTLTYPE_NODE }, \
+ { "iso", CTLTYPE_NODE }, \
+ { "emca", CTLTYPE_NODE }, \
+ { "datakit", CTLTYPE_NODE }, \
+ { "ccitt", CTLTYPE_NODE }, \
+ { "ibm_sna", CTLTYPE_NODE }, \
+ { "decnet", CTLTYPE_NODE }, \
+ { "dec_dli", CTLTYPE_NODE }, \
+ { "lat", CTLTYPE_NODE }, \
+ { "hylink", CTLTYPE_NODE }, \
+ { "appletalk", CTLTYPE_NODE }, \
+ { "route", CTLTYPE_NODE }, \
+ { "link_layer", CTLTYPE_NODE }, \
+ { "xtp", CTLTYPE_NODE }, \
+ { "coip", CTLTYPE_NODE }, \
+ { "cnt", CTLTYPE_NODE }, \
+ { "rtip", CTLTYPE_NODE }, \
+ { "ipx", CTLTYPE_NODE }, \
+ { "sip", CTLTYPE_NODE }, \
+ { "pip", CTLTYPE_NODE }, \
+ { "isdn", CTLTYPE_NODE }, \
+ { "key", CTLTYPE_NODE }, \
+}
+
+/*
+ * PF_ROUTE - Routing table
+ *
+ * Three additional levels are defined:
+ * Fourth: address family, 0 is wildcard
+ * Fifth: type of info, defined below
+ * Sixth: flag(s) to mask with for NET_RT_FLAGS
+ */
+#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
+#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
+#define NET_RT_IFLIST 3 /* survey interface list */
+#define NET_RT_MAXID 4
+
+#define CTL_NET_RT_NAMES { \
+ { 0, 0 }, \
+ { "dump", CTLTYPE_STRUCT }, \
+ { "flags", CTLTYPE_STRUCT }, \
+ { "iflist", CTLTYPE_STRUCT }, \
+}
+
+/*
+ * Maximum queue length specifiable by listen.
+ */
+#define SOMAXCONN 128
+
+/*
+ * Message header for recvmsg and sendmsg calls.
+ * Used value-result for recvmsg, value only for sendmsg.
+ */
+struct msghdr {
+ void *msg_name; /* optional address */
+ socklen_t msg_namelen; /* size of address */
+ struct iovec *msg_iov; /* scatter/gather array */
+ int msg_iovlen; /* # elements in msg_iov */
+ void *msg_control; /* ancillary data, see below */
+ socklen_t msg_controllen; /* ancillary data buffer len */
+ int msg_flags; /* flags on received message */
+};
+
+#define MSG_OOB 0x1 /* process out-of-band data */
+#define MSG_PEEK 0x2 /* peek at incoming message */
+#define MSG_DONTROUTE 0x4 /* send without using routing tables */
+#define MSG_EOR 0x8 /* data completes record */
+#define MSG_TRUNC 0x10 /* data discarded before delivery */
+#define MSG_CTRUNC 0x20 /* control data lost before delivery */
+#define MSG_WAITALL 0x40 /* wait for full request or error */
+#if __BSD_VISIBLE
+#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
+#define MSG_EOF 0x100 /* data completes connection */
+#define MSG_COMPAT 0x8000 /* used in sendit() */
+#endif
+
+/*
+ * Header for ancillary data objects in msg_control buffer.
+ * Used for additional information with/about a datagram
+ * not expressible by flags. The format is a sequence
+ * of message elements headed by cmsghdr structures.
+ */
+struct cmsghdr {
+ socklen_t cmsg_len; /* data byte count, including hdr */
+ int cmsg_level; /* originating protocol */
+ int cmsg_type; /* protocol-specific type */
+/* followed by u_char cmsg_data[]; */
+};
+
+/* given pointer to struct cmsghdr, return pointer to data */
+#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
+
+/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
+#define CMSG_NXTHDR(mhdr, cmsg) \
+ (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
+ (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
+ (struct cmsghdr *)NULL : \
+ (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
+
+#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
+
+/* "Socket"-level control message types: */
+#define SCM_RIGHTS 0x01 /* access rights (array of int) */
+#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
+
+/*
+ * 4.3 compat sockaddr, move to compat file later
+ */
+struct osockaddr {
+ unsigned short sa_family; /* address family */
+ char sa_data[14]; /* up to 14 bytes of direct address */
+};
+
+/*
+ * 4.3-compat message header (move to compat file later).
+ */
+struct omsghdr {
+ char *msg_name; /* optional address */
+ int msg_namelen; /* size of address */
+ struct iovec *msg_iov; /* scatter/gather array */
+ int msg_iovlen; /* # elements in msg_iov */
+ char *msg_accrights; /* access rights sent/received */
+ int msg_accrightslen;
+};
+
+/*
+ * howto arguments for shutdown(2), specified by Posix.1g.
+ */
+#define SHUT_RD 0 /* shut down the reading side */
+#define SHUT_WR 1 /* shut down the writing side */
+#define SHUT_RDWR 2 /* shut down both sides */
+
+#ifndef _KERNEL
+
+__BEGIN_DECLS
+int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int bind(int, const struct sockaddr *, socklen_t);
+int connect(int, const struct sockaddr *, socklen_t);
+int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
+int listen(int, int);
+ssize_t recv(int, void *, size_t, int);
+ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
+ssize_t recvmsg(int, struct msghdr *, int);
+ssize_t send(int, const void *, size_t, int);
+ssize_t sendto(int, const void *,
+ size_t, int, const struct sockaddr *, socklen_t);
+ssize_t sendmsg(int, const struct msghdr *, int);
+int setsockopt(int, int, int, const void *, socklen_t);
+int shutdown(int, int);
+int socket(int, int, int);
+int socketpair(int, int, int, int *);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SOCKET_H_ */
diff --git a/cpukit/libnetworking/sys/socketvar.h b/cpukit/libnetworking/sys/socketvar.h
new file mode 100644
index 0000000000..62bce69f3d
--- /dev/null
+++ b/cpukit/libnetworking/sys/socketvar.h
@@ -0,0 +1,273 @@
+/* $Id$ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
+ * $FreeBSD: src/sys/sys/socketvar.h,v 1.135 2004/10/18 22:19:43 rwatson Exp $
+ */
+
+#ifndef _SYS_SOCKETVAR_H_
+#define _SYS_SOCKETVAR_H_
+
+#include <sys/queue.h> /* for TAILQ macros */
+#include <sys/select.h> /* for struct selinfo */
+
+
+/*
+ * Kernel structure per socket.
+ * Contains send and receive buffer queues,
+ * handle on protocol and pointer to protocol
+ * private data and error information.
+ */
+typedef u_quad_t so_gen_t;
+
+struct socket {
+ short so_type; /* generic type, see socket.h */
+ short so_options; /* from socket call, see socket.h */
+ short so_linger; /* time to linger while closing */
+ short so_state; /* internal state flags SS_*, below */
+ void *so_pcb; /* protocol control block */
+ struct protosw *so_proto; /* protocol handle */
+/*
+ * Variables for connection queuing.
+ * Socket where accepts occur is so_head in all subsidiary sockets.
+ * If so_head is 0, socket is not related to an accept.
+ * For head socket so_q0 queues partially completed connections,
+ * while so_q is a queue of connections ready to be accepted.
+ * If a connection is aborted and it has so_head set, then
+ * it has to be pulled out of either so_q0 or so_q.
+ * We allow connections to queue up based on current queue lengths
+ * and limit on number of queued connections for this socket.
+ */
+ struct socket *so_head; /* back pointer to accept socket */
+ TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
+ TAILQ_HEAD(, socket) so_comp; /* queue of complete unaccepted connections */
+ TAILQ_ENTRY(socket) so_list; /* list of unaccepted connections */
+ short so_qlen; /* number of unaccepted connections */
+ short so_incqlen; /* number of unaccepted incomplete
+ connections */
+ short so_qlimit; /* max number queued connections */
+ short so_timeo; /* connection timeout */
+ u_short so_error; /* error affecting connection */
+ pid_t so_pgid; /* pgid for signals */
+ u_long so_oobmark; /* chars to oob mark */
+/*
+ * Variables for socket buffering.
+ */
+ struct sockbuf {
+ u_int sb_cc; /* actual chars in buffer */
+ u_int sb_hiwat; /* max actual char count */
+ u_int sb_mbcnt; /* chars of mbufs used */
+ u_int sb_mbmax; /* max chars of mbufs to use */
+ int sb_lowat; /* low water mark */
+ struct mbuf *sb_mb; /* the mbuf chain */
+ struct selinfo sb_sel; /* process selecting read/write */
+ short sb_flags; /* flags, see below */
+ int sb_timeo; /* timeout for read/write */
+ void (*sb_wakeup)(struct socket *, void *);
+ void *sb_wakeuparg; /* arg for above */
+ } so_rcv, so_snd;
+#define SB_MAX (256L*1024L) /* default for max chars in sockbuf */
+#define SB_LOCK 0x01 /* lock on data queue */
+#define SB_WANT 0x02 /* someone is waiting to lock */
+#define SB_WAIT 0x04 /* someone is waiting for data/space */
+#define SB_SEL 0x08 /* someone is selecting */
+#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
+#define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
+#define SB_NOINTR 0x40 /* operations not interruptible */
+
+ caddr_t so_tpcb; /* Wisc. protocol control block XXX */
+ void (*so_upcall)(struct socket *, void *arg, int);
+ void *so_upcallarg; /* Arg for above */
+ uid_t so_uid; /* who opened the socket */
+};
+
+/*
+ * Socket state bits.
+ */
+#define SS_NOFDREF 0x0001 /* no file table ref any more */
+#define SS_ISCONNECTED 0x0002 /* socket connected to a peer */
+#define SS_ISCONNECTING 0x0004 /* in process of connecting to peer */
+#define SS_ISDISCONNECTING 0x0008 /* in process of disconnecting */
+#define SS_CANTSENDMORE 0x0010 /* can't send more data to peer */
+#define SS_CANTRCVMORE 0x0020 /* can't receive more data from peer */
+#define SS_RCVATMARK 0x0040 /* at mark on input */
+
+#define SS_PRIV 0x0080 /* privileged for broadcast, raw... */
+#define SS_NBIO 0x0100 /* non-blocking ops */
+#define SS_ASYNC 0x0200 /* async i/o notify */
+#define SS_ISCONFIRMING 0x0400 /* deciding to accept connection req */
+
+#define SS_INCOMP 0x0800 /* unaccepted, incomplete connection */
+#define SS_COMP 0x1000 /* unaccepted, complete connection */
+
+
+/*
+ * Macros for sockets and socket buffering.
+ */
+
+/*
+ * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
+ * This is problematical if the fields are unsigned, as the space might
+ * still be negative (cc > hiwat or mbcnt > mbmax). Should detect
+ * overflow and return 0. Should use "lmin" but it doesn't exist now.
+ */
+#define sbspace(sb) \
+ ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
+ (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
+
+/* do we have to send all at once on a socket? */
+#define sosendallatonce(so) \
+ ((so)->so_proto->pr_flags & PR_ATOMIC)
+
+/* can we read something from so? */
+#define soreadable(so) \
+ ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
+ ((so)->so_state & SS_CANTRCVMORE) || \
+ (so)->so_comp.tqh_first || (so)->so_error)
+
+/* can we write something to so? */
+#define sowriteable(so) \
+ ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
+ (((so)->so_state&SS_ISCONNECTED) || \
+ ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
+ ((so)->so_state & SS_CANTSENDMORE) || \
+ (so)->so_error)
+
+/* adjust counters in sb reflecting allocation of m */
+#define sballoc(sb, m) { \
+ (sb)->sb_cc += (m)->m_len; \
+ (sb)->sb_mbcnt += MSIZE; \
+ if ((m)->m_flags & M_EXT) \
+ (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
+}
+
+/* adjust counters in sb reflecting freeing of m */
+#define sbfree(sb, m) { \
+ (sb)->sb_cc -= (m)->m_len; \
+ (sb)->sb_mbcnt -= MSIZE; \
+ if ((m)->m_flags & M_EXT) \
+ (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
+}
+
+/*
+ * Set lock on sockbuf sb; sleep if lock is already held.
+ * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
+ * Returns error without lock if sleep is interrupted.
+ */
+#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
+ (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
+ ((sb)->sb_flags |= SB_LOCK), 0)
+
+/* release lock on sockbuf sb */
+#define sbunlock(sb) { \
+ (sb)->sb_flags &= ~SB_LOCK; \
+ if ((sb)->sb_flags & SB_WANT) { \
+ (sb)->sb_flags &= ~SB_WANT; \
+ wakeup((caddr_t)&(sb)->sb_flags); \
+ } \
+}
+
+#define sorwakeup(so) { sowakeup((so), &(so)->so_rcv); \
+ if ((so)->so_upcall) \
+ (*((so)->so_upcall))((so), (so)->so_upcallarg, M_DONTWAIT); \
+ }
+
+#define sowwakeup(so) sowakeup((so), &(so)->so_snd)
+
+#ifdef _KERNEL
+extern u_long sb_max;
+
+/* to catch callers missing new second argument to sonewconn: */
+#define sonewconn(head, connstatus) sonewconn1((head), (connstatus))
+
+struct filedesc;
+struct mbuf;
+struct sockaddr;
+struct stat;
+
+/*
+ * From uipc_socket and friends
+ */
+int sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
+void sbappend(struct sockbuf *sb, struct mbuf *m);
+int sbappendaddr(struct sockbuf *sb, struct sockaddr *asa,
+ struct mbuf *m0, struct mbuf *control);
+int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
+ struct mbuf *control);
+void sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
+void sbcheck(struct sockbuf *sb);
+void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
+struct mbuf *
+ sbcreatecontrol(caddr_t p, int size, int type, int level);
+void sbdrop(struct sockbuf *sb, int len);
+void sbdroprecord(struct sockbuf *sb);
+void sbflush(struct sockbuf *sb);
+void sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
+void sbrelease(struct sockbuf *sb);
+int sbreserve(struct sockbuf *sb, u_long cc);
+int sbwait(struct sockbuf *sb);
+int sb_lock(struct sockbuf *sb);
+int soabort(struct socket *so);
+int soaccept(struct socket *so, struct mbuf *nam);
+int sobind(struct socket *so, struct mbuf *nam);
+void socantrcvmore(struct socket *so);
+void socantsendmore(struct socket *so);
+int soclose(struct socket *so);
+int soconnect(struct socket *so, struct mbuf *nam);
+int soconnect2(struct socket *so1, struct socket *so2);
+int socreate(int dom, struct socket **aso, int type, int proto,
+ struct proc *p);
+int sodisconnect(struct socket *so);
+void sofree(struct socket *so);
+int sogetopt(struct socket *so, int level, int optname,
+ struct mbuf **mp);
+void sohasoutofband(struct socket *so);
+void soisconnected(struct socket *so);
+void soisconnecting(struct socket *so);
+void soisdisconnected(struct socket *so);
+void soisdisconnecting(struct socket *so);
+int solisten(struct socket *so, int backlog);
+struct socket *
+ sodropablereq(struct socket *head);
+struct socket *
+ sonewconn1(struct socket *head, int connstatus);
+int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
+ struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
+int soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
+void sorflush(struct socket *so);
+int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
+ struct mbuf *top, struct mbuf *control, int flags);
+int sosetopt(struct socket *so, int level, int optname,
+ struct mbuf *m0);
+int soshutdown(struct socket *so, int how);
+void sowakeup(struct socket *so, struct sockbuf *sb);
+#endif /* _KERNEL */
+
+#endif /* !_SYS_SOCKETVAR_H_ */
diff --git a/cpukit/libnetworking/sys/sysctl.h b/cpukit/libnetworking/sys/sysctl.h
new file mode 100644
index 0000000000..125d33cbf7
--- /dev/null
+++ b/cpukit/libnetworking/sys/sysctl.h
@@ -0,0 +1,642 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Karels at Berkeley Software Design, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)sysctl.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: src/sys/sys/sysctl.h,v 1.133 2004/10/11 22:04:16 peter Exp $
+ */
+
+#ifndef _SYS_SYSCTL_H_
+#define _SYS_SYSCTL_H_
+
+#include <stdint.h>
+#include <sys/queue.h>
+
+struct thread;
+/*
+ * Definitions for sysctl call. The sysctl call uses a hierarchical name
+ * for objects that can be examined or modified. The name is expressed as
+ * a sequence of integers. Like a file path name, the meaning of each
+ * component depends on its place in the hierarchy. The top-level and kern
+ * identifiers are defined here, and other identifiers are defined in the
+ * respective subsystem header files.
+ */
+
+#define CTL_MAXNAME 24 /* largest number of components supported */
+
+/*
+ * Each subsystem defined by sysctl defines a list of variables
+ * for that subsystem. Each name is either a node with further
+ * levels defined below it, or it is a leaf of some particular
+ * type given below. Each sysctl level defines a set of name/type
+ * pairs to be used by sysctl(8) in manipulating the subsystem.
+ */
+struct ctlname {
+ char *ctl_name; /* subsystem name */
+ int ctl_type; /* type of name */
+};
+
+#define CTLTYPE 0xf /* Mask for the type */
+#define CTLTYPE_NODE 1 /* name is a node */
+#define CTLTYPE_INT 2 /* name describes an integer */
+#define CTLTYPE_STRING 3 /* name describes a string */
+#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
+#define CTLTYPE_OPAQUE 5 /* name describes a structure */
+#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
+#define CTLTYPE_UINT 6 /* name describes an unsigned integer */
+#define CTLTYPE_LONG 7 /* name describes a long */
+#define CTLTYPE_ULONG 8 /* name describes an unsigned long */
+
+#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
+#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
+#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
+#define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */
+#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
+#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
+#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
+#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
+#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
+#define CTLMASK_SECURE 0x00F00000 /* Secure level */
+#define CTLFLAG_TUN 0x00080000 /* Tunable variable */
+#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
+
+/*
+ * Secure level. Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
+ *
+ * Secure when the securelevel is raised to at least N.
+ */
+#define CTLSHIFT_SECURE 20
+#define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
+#define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
+#define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
+
+/*
+ * USE THIS instead of a hardwired number from the categories below
+ * to get dynamically assigned sysctl entries using the linker-set
+ * technology. This is the way nearly all new sysctl variables should
+ * be implemented.
+ * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
+ */
+#define OID_AUTO (-1)
+
+/*
+ * The starting number for dynamically-assigned entries. WARNING!
+ * ALL static sysctl entries should have numbers LESS than this!
+ */
+#define CTL_AUTO_START 0x100
+
+#ifdef _KERNEL
+#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \
+ struct sysctl_req *req
+
+/* definitions for sysctl_req 'lock' member */
+#define REQ_UNLOCKED 0 /* not locked and not wired */
+#define REQ_LOCKED 1 /* locked and not wired */
+#define REQ_WIRED 2 /* locked and wired */
+
+/*
+ * This describes the access space for a sysctl request. This is needed
+ * so that we can use the interface from the kernel or from user-space.
+ */
+struct sysctl_req {
+ struct thread *td; /* used for access checking */
+ int lock; /* locking/wiring state */
+ void *oldptr;
+ size_t oldlen;
+ size_t oldidx;
+ int (*oldfunc)(struct sysctl_req *, const void *, size_t);
+ void *newptr;
+ size_t newlen;
+ size_t newidx;
+ int (*newfunc)(struct sysctl_req *, void *, size_t);
+ size_t validlen;
+};
+
+SLIST_HEAD(sysctl_oid_list, sysctl_oid);
+
+/*
+ * This describes one "oid" in the MIB tree. Potentially more nodes can
+ * be hidden behind it, expanded by the handler.
+ */
+struct sysctl_oid {
+ struct sysctl_oid_list *oid_parent;
+ SLIST_ENTRY(sysctl_oid) oid_link;
+ int oid_number;
+ uint32_t oid_kind;
+ void *oid_arg1;
+ int32_t oid_arg2;
+ const char *oid_name;
+ int (*oid_handler)(SYSCTL_HANDLER_ARGS);
+ const char *oid_fmt;
+ int oid_refcnt;
+ const char *descr;
+};
+
+#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
+#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
+
+int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_intptr(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
+
+/*
+ * These functions are used to add/remove an oid from the mib.
+ */
+void sysctl_register_oid(struct sysctl_oid *oidp);
+void sysctl_unregister_oid(struct sysctl_oid *oidp);
+
+/* Declare a static oid to allow child oids to be added to it. */
+#define SYSCTL_DECL(name) \
+ extern struct sysctl_oid_list sysctl_##name##_children
+
+/* Hide these in macros */
+#define SYSCTL_CHILDREN(oid_ptr) (struct sysctl_oid_list *) \
+ (oid_ptr)->oid_arg1
+#define SYSCTL_CHILDREN_SET(oid_ptr, val) \
+ (oid_ptr)->oid_arg1 = (val);
+#define SYSCTL_STATIC_CHILDREN(oid_name) \
+ (&sysctl_##oid_name##_children)
+
+/* === Structs and macros related to context handling === */
+
+/* All dynamically created sysctls can be tracked in a context list. */
+struct sysctl_ctx_entry {
+ struct sysctl_oid *entry;
+ TAILQ_ENTRY(sysctl_ctx_entry) link;
+};
+
+TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
+
+#define SYSCTL_NODE_CHILDREN(parent, name) \
+ sysctl_##parent##_##name##_children
+
+/* This constructs a "raw" MIB oid. */
+#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
+ static struct sysctl_oid sysctl__##parent##_##name = { \
+ &sysctl_##parent##_children, { 0 }, \
+ nbr, kind, a1, a2, #name, handler, fmt, 0, descr }; \
+ DATA_SET(sysctl_set, sysctl__##parent##_##name)
+
+#define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr)
+
+/* This constructs a node from which other oids can hang. */
+#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
+ struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name); \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|(access), \
+ (void*)&SYSCTL_NODE_CHILDREN(parent, name), 0, handler, \
+ "N", descr)
+
+#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \
+ 0, 0, handler, "N", descr)
+
+/* Oid for a string. len can be 0 to indicate '\0' termination. */
+#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), \
+ arg, len, sysctl_handle_string, "A", descr)
+
+#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \
+ arg, len, sysctl_handle_string, "A", descr)
+
+/* Oid for an int. If ptr is NULL, val is returned. */
+#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|(access), \
+ ptr, val, sysctl_handle_int, "I", descr)
+
+#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_INT|(access), \
+ ptr, val, sysctl_handle_int, "I", descr)
+
+/* Oid for an unsigned int. If ptr is NULL, val is returned. */
+#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_UINT|(access), \
+ ptr, val, sysctl_handle_int, "IU", descr)
+
+#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \
+ ptr, val, sysctl_handle_int, "IU", descr)
+
+/* Oid for a long. The pointer must be non NULL. */
+#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_LONG|(access), \
+ ptr, val, sysctl_handle_long, "L", descr)
+
+#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_LONG|(access), \
+ ptr, 0, sysctl_handle_long, "L", descr)
+
+/* Oid for an unsigned long. The pointer must be non NULL. */
+#define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_ULONG|(access), \
+ ptr, val, sysctl_handle_long, "LU", descr)
+
+#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \
+ ptr, 0, sysctl_handle_long, "LU", descr)
+
+/* Oid for an opaque object. Specified by a pointer and a length. */
+#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \
+ ptr, len, sysctl_handle_opaque, fmt, descr)
+
+#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)\
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \
+ ptr, len, sysctl_handle_opaque, fmt, descr)
+
+/* Oid for a struct. Specified by a pointer and a type. */
+#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \
+ ptr, sizeof(struct type), sysctl_handle_opaque, \
+ "S," #type, descr)
+
+#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \
+ ptr, sizeof(struct type), sysctl_handle_opaque, "S," #type, descr)
+
+/* Oid for a procedure. Specified by a pointer and an arg. */
+#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
+ SYSCTL_OID(parent, nbr, name, (access), \
+ ptr, arg, handler, fmt, descr)
+
+#define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, (access), \
+ ptr, arg, handler, fmt, descr)
+
+#endif /* _KERNEL */
+
+/*
+ * Top-level identifiers
+ */
+#define CTL_UNSPEC 0 /* unused */
+#define CTL_KERN 1 /* "high kernel": proc, limits */
+#define CTL_VM 2 /* virtual memory */
+#define CTL_VFS 3 /* filesystem, mount type is next */
+#define CTL_NET 4 /* network, see socket.h */
+#define CTL_DEBUG 5 /* debugging parameters */
+#define CTL_HW 6 /* generic cpu/io */
+#define CTL_MACHDEP 7 /* machine dependent */
+#define CTL_USER 8 /* user-level */
+#define CTL_P1003_1B 9 /* POSIX 1003.1B */
+#define CTL_MAXID 10 /* number of valid top-level ids */
+
+#define CTL_NAMES { \
+ { 0, 0 }, \
+ { "kern", CTLTYPE_NODE }, \
+ { "vm", CTLTYPE_NODE }, \
+ { "vfs", CTLTYPE_NODE }, \
+ { "net", CTLTYPE_NODE }, \
+ { "debug", CTLTYPE_NODE }, \
+ { "hw", CTLTYPE_NODE }, \
+ { "machdep", CTLTYPE_NODE }, \
+ { "user", CTLTYPE_NODE }, \
+ { "p1003_1b", CTLTYPE_NODE }, \
+}
+
+/*
+ * CTL_KERN identifiers
+ */
+#define KERN_OSTYPE 1 /* string: system version */
+#define KERN_OSRELEASE 2 /* string: system release */
+#define KERN_OSREV 3 /* int: system revision */
+#define KERN_VERSION 4 /* string: compile time info */
+#define KERN_MAXVNODES 5 /* int: max vnodes */
+#define KERN_MAXPROC 6 /* int: max processes */
+#define KERN_MAXFILES 7 /* int: max open files */
+#define KERN_ARGMAX 8 /* int: max arguments to exec */
+#define KERN_SECURELVL 9 /* int: system security level */
+#define KERN_HOSTNAME 10 /* string: hostname */
+#define KERN_HOSTID 11 /* int: host identifier */
+#define KERN_CLOCKRATE 12 /* struct: struct clockrate */
+#define KERN_VNODE 13 /* struct: vnode structures */
+#define KERN_PROC 14 /* struct: process entries */
+#define KERN_FILE 15 /* struct: file entries */
+#define KERN_PROF 16 /* node: kernel profiling info */
+#define KERN_POSIX1 17 /* int: POSIX.1 version */
+#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
+#define KERN_JOB_CONTROL 19 /* int: is job control available */
+#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
+#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
+#define KERN_NISDOMAINNAME 22 /* string: YP domain name */
+#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */
+#define KERN_OSRELDATE 24 /* int: kernel release date */
+#define KERN_NTP_PLL 25 /* node: NTP PLL control */
+#define KERN_BOOTFILE 26 /* string: name of booted kernel */
+#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */
+#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */
+#define KERN_DUMPDEV 29 /* struct cdev *: device to dump on */
+#define KERN_IPC 30 /* node: anything related to IPC */
+#define KERN_DUMMY 31 /* unused */
+#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */
+#define KERN_USRSTACK 33 /* int: address of USRSTACK */
+#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */
+#define KERN_IOV_MAX 35 /* int: value of UIO_MAXIOV */
+#define KERN_MAXID 36 /* number of valid kern ids */
+
+#define CTL_KERN_NAMES { \
+ { 0, 0 }, \
+ { "ostype", CTLTYPE_STRING }, \
+ { "osrelease", CTLTYPE_STRING }, \
+ { "osrevision", CTLTYPE_INT }, \
+ { "version", CTLTYPE_STRING }, \
+ { "maxvnodes", CTLTYPE_INT }, \
+ { "maxproc", CTLTYPE_INT }, \
+ { "maxfiles", CTLTYPE_INT }, \
+ { "argmax", CTLTYPE_INT }, \
+ { "securelevel", CTLTYPE_INT }, \
+ { "hostname", CTLTYPE_STRING }, \
+ { "hostid", CTLTYPE_UINT }, \
+ { "clockrate", CTLTYPE_STRUCT }, \
+ { "vnode", CTLTYPE_STRUCT }, \
+ { "proc", CTLTYPE_STRUCT }, \
+ { "file", CTLTYPE_STRUCT }, \
+ { "profiling", CTLTYPE_NODE }, \
+ { "posix1version", CTLTYPE_INT }, \
+ { "ngroups", CTLTYPE_INT }, \
+ { "job_control", CTLTYPE_INT }, \
+ { "saved_ids", CTLTYPE_INT }, \
+ { "boottime", CTLTYPE_STRUCT }, \
+ { "nisdomainname", CTLTYPE_STRING }, \
+ { "update", CTLTYPE_INT }, \
+ { "osreldate", CTLTYPE_INT }, \
+ { "ntp_pll", CTLTYPE_NODE }, \
+ { "bootfile", CTLTYPE_STRING }, \
+ { "maxfilesperproc", CTLTYPE_INT }, \
+ { "maxprocperuid", CTLTYPE_INT }, \
+ { "ipc", CTLTYPE_NODE }, \
+ { "dummy", CTLTYPE_INT }, \
+ { "ps_strings", CTLTYPE_INT }, \
+ { "usrstack", CTLTYPE_INT }, \
+ { "logsigexit", CTLTYPE_INT }, \
+ { "iov_max", CTLTYPE_INT }, \
+}
+
+/*
+ * CTL_VFS identifiers
+ */
+#define CTL_VFS_NAMES { \
+ { "vfsconf", CTLTYPE_STRUCT }, \
+}
+
+/*
+ * KERN_PROC subtypes
+ */
+#define KERN_PROC_ALL 0 /* everything */
+#define KERN_PROC_PID 1 /* by process id */
+#define KERN_PROC_PGRP 2 /* by process group id */
+#define KERN_PROC_SESSION 3 /* by session of pid */
+#define KERN_PROC_TTY 4 /* by controlling tty */
+#define KERN_PROC_UID 5 /* by effective uid */
+#define KERN_PROC_RUID 6 /* by real uid */
+#define KERN_PROC_ARGS 7 /* get/set arguments/proctitle */
+#define KERN_PROC_PROC 8 /* only return procs */
+#define KERN_PROC_SV_NAME 9 /* get syscall vector name */
+#define KERN_PROC_RGID 10 /* by real group id */
+#define KERN_PROC_GID 11 /* by effective group id */
+#define KERN_PROC_INC_THREAD 0x10 /*
+ * modifier for pid, pgrp, tty,
+ * uid, ruid, gid, rgid and proc
+ */
+
+/*
+ * KERN_IPC identifiers
+ */
+#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
+#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
+#define KIPC_SOMAXCONN 3 /* int: max length of connection q */
+#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
+#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
+#define KIPC_MAX_HDR 6 /* int: max total length of headers */
+#define KIPC_MAX_DATALEN 7 /* int: max length of data? */
+
+/*
+ * CTL_HW identifiers
+ */
+#define HW_MACHINE 1 /* string: machine class */
+#define HW_MODEL 2 /* string: specific machine model */
+#define HW_NCPU 3 /* int: number of cpus */
+#define HW_BYTEORDER 4 /* int: machine byte order */
+#define HW_PHYSMEM 5 /* int: total memory */
+#define HW_USERMEM 6 /* int: non-kernel memory */
+#define HW_PAGESIZE 7 /* int: software page size */
+#define HW_DISKNAMES 8 /* strings: disk drive names */
+#define HW_DISKSTATS 9 /* struct: diskstats[] */
+#define HW_FLOATINGPT 10 /* int: has HW floating point? */
+#define HW_MACHINE_ARCH 11 /* string: machine architecture */
+#define HW_MAXID 12 /* number of valid hw ids */
+
+#define CTL_HW_NAMES { \
+ { 0, 0 }, \
+ { "machine", CTLTYPE_STRING }, \
+ { "model", CTLTYPE_STRING }, \
+ { "ncpu", CTLTYPE_INT }, \
+ { "byteorder", CTLTYPE_INT }, \
+ { "physmem", CTLTYPE_ULONG }, \
+ { "usermem", CTLTYPE_ULONG }, \
+ { "pagesize", CTLTYPE_INT }, \
+ { "disknames", CTLTYPE_STRUCT }, \
+ { "diskstats", CTLTYPE_STRUCT }, \
+ { "floatingpoint", CTLTYPE_INT }, \
+}
+
+/*
+ * CTL_USER definitions
+ */
+#define USER_CS_PATH 1 /* string: _CS_PATH */
+#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
+#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
+#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
+#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
+#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
+#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
+#define USER_LINE_MAX 8 /* int: LINE_MAX */
+#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
+#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
+#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
+#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
+#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
+#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
+#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
+#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
+#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
+#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
+#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
+#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
+#define USER_MAXID 21 /* number of valid user ids */
+
+#define CTL_USER_NAMES { \
+ { 0, 0 }, \
+ { "cs_path", CTLTYPE_STRING }, \
+ { "bc_base_max", CTLTYPE_INT }, \
+ { "bc_dim_max", CTLTYPE_INT }, \
+ { "bc_scale_max", CTLTYPE_INT }, \
+ { "bc_string_max", CTLTYPE_INT }, \
+ { "coll_weights_max", CTLTYPE_INT }, \
+ { "expr_nest_max", CTLTYPE_INT }, \
+ { "line_max", CTLTYPE_INT }, \
+ { "re_dup_max", CTLTYPE_INT }, \
+ { "posix2_version", CTLTYPE_INT }, \
+ { "posix2_c_bind", CTLTYPE_INT }, \
+ { "posix2_c_dev", CTLTYPE_INT }, \
+ { "posix2_char_term", CTLTYPE_INT }, \
+ { "posix2_fort_dev", CTLTYPE_INT }, \
+ { "posix2_fort_run", CTLTYPE_INT }, \
+ { "posix2_localedef", CTLTYPE_INT }, \
+ { "posix2_sw_dev", CTLTYPE_INT }, \
+ { "posix2_upe", CTLTYPE_INT }, \
+ { "stream_max", CTLTYPE_INT }, \
+ { "tzname_max", CTLTYPE_INT }, \
+}
+
+#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */
+#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */
+#define CTL_P1003_1B_MEMLOCK 3 /* boolean */
+#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */
+#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */
+#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */
+#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */
+#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */
+#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */
+#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */
+#define CTL_P1003_1B_FSYNC 11 /* boolean */
+#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */
+#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */
+#define CTL_P1003_1B_TIMERS 14 /* boolean */
+#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */
+#define CTL_P1003_1B_AIO_MAX 16 /* int */
+#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */
+#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */
+#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */
+#define CTL_P1003_1B_PAGESIZE 20 /* int */
+#define CTL_P1003_1B_RTSIG_MAX 21 /* int */
+#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */
+#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */
+#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */
+#define CTL_P1003_1B_TIMER_MAX 25 /* int */
+
+#define CTL_P1003_1B_MAXID 26
+
+#define CTL_P1003_1B_NAMES { \
+ { 0, 0 }, \
+ { "asynchronous_io", CTLTYPE_INT }, \
+ { "mapped_files", CTLTYPE_INT }, \
+ { "memlock", CTLTYPE_INT }, \
+ { "memlock_range", CTLTYPE_INT }, \
+ { "memory_protection", CTLTYPE_INT }, \
+ { "message_passing", CTLTYPE_INT }, \
+ { "prioritized_io", CTLTYPE_INT }, \
+ { "priority_scheduling", CTLTYPE_INT }, \
+ { "realtime_signals", CTLTYPE_INT }, \
+ { "semaphores", CTLTYPE_INT }, \
+ { "fsync", CTLTYPE_INT }, \
+ { "shared_memory_objects", CTLTYPE_INT }, \
+ { "synchronized_io", CTLTYPE_INT }, \
+ { "timers", CTLTYPE_INT }, \
+ { "aio_listio_max", CTLTYPE_INT }, \
+ { "aio_max", CTLTYPE_INT }, \
+ { "aio_prio_delta_max", CTLTYPE_INT }, \
+ { "delaytimer_max", CTLTYPE_INT }, \
+ { "mq_open_max", CTLTYPE_INT }, \
+ { "pagesize", CTLTYPE_INT }, \
+ { "rtsig_max", CTLTYPE_INT }, \
+ { "nsems_max", CTLTYPE_INT }, \
+ { "sem_value_max", CTLTYPE_INT }, \
+ { "sigqueue_max", CTLTYPE_INT }, \
+ { "timer_max", CTLTYPE_INT }, \
+}
+
+#ifdef _KERNEL
+
+/*
+ * Declare some common oids.
+ */
+extern struct sysctl_oid_list sysctl__children;
+SYSCTL_DECL(_kern);
+SYSCTL_DECL(_sysctl);
+SYSCTL_DECL(_vm);
+SYSCTL_DECL(_vfs);
+SYSCTL_DECL(_net);
+SYSCTL_DECL(_debug);
+SYSCTL_DECL(_debug_sizeof);
+SYSCTL_DECL(_hw);
+SYSCTL_DECL(_machdep);
+SYSCTL_DECL(_user);
+SYSCTL_DECL(_compat);
+
+extern char machine[];
+extern char osrelease[];
+extern char ostype[];
+extern char kern_ident[];
+
+/* Dynamic oid handling */
+struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
+ struct sysctl_oid_list *parent, int nbr, const char *name,
+ int kind, void *arg1, int arg2,
+ int (*handler) (SYSCTL_HANDLER_ARGS),
+ const char *fmt, const char *descr);
+int sysctl_move_oid(struct sysctl_oid *oidp,
+ struct sysctl_oid_list *parent);
+int sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
+int sysctl_ctx_init(struct sysctl_ctx_list *clist);
+int sysctl_ctx_free(struct sysctl_ctx_list *clist);
+struct sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
+ struct sysctl_oid *oidp);
+struct sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
+ struct sysctl_oid *oidp);
+int sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
+ struct sysctl_oid *oidp);
+
+int kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
+ size_t *oldlenp, void *new, size_t newlen,
+ size_t *retval);
+int kernel_sysctlbyname(struct thread *td, char *name,
+ void *old, size_t *oldlenp, void *new, size_t newlen,
+ size_t *retval);
+int userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
+ size_t *oldlenp, int inkernel, void *new, size_t newlen,
+ size_t *retval);
+int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
+ int *nindx, struct sysctl_req *req);
+int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
+
+#else /* !_KERNEL */
+#include <rtems/bsd/sys/cdefs.h>
+
+__BEGIN_DECLS
+int sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int sysctlbyname(const char *, void *, size_t *, void *, size_t);
+int sysctlnametomib(const char *, int *, size_t *);
+__END_DECLS
+#endif /* _KERNEL */
+
+#endif /* !_SYS_SYSCTL_H_ */
diff --git a/cpukit/libnetworking/sys/syslog.h b/cpukit/libnetworking/sys/syslog.h
new file mode 100644
index 0000000000..8927b8a8ff
--- /dev/null
+++ b/cpukit/libnetworking/sys/syslog.h
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)syslog.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: src/sys/sys/syslog.h,v 1.26 2005/01/07 02:29:24 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_SYSLOG_H_
+#define _SYS_SYSLOG_H_
+
+#define _PATH_LOG "/var/run/log"
+#define _PATH_OLDLOG "/dev/log" /* backward compatibility */
+
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number). Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code. This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+#define LOG_EMERG 0 /* system is unusable */
+#define LOG_ALERT 1 /* action must be taken immediately */
+#define LOG_CRIT 2 /* critical conditions */
+#define LOG_ERR 3 /* error conditions */
+#define LOG_WARNING 4 /* warning conditions */
+#define LOG_NOTICE 5 /* normal but significant condition */
+#define LOG_INFO 6 /* informational */
+#define LOG_DEBUG 7 /* debug-level messages */
+
+#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
+ /* extract priority */
+#define LOG_PRI(p) ((p) & LOG_PRIMASK)
+#define LOG_MAKEPRI(fac, pri) ((fac) | (pri))
+
+#ifdef SYSLOG_NAMES
+#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
+ /* mark "facility" */
+#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0)
+typedef struct _code {
+ const char *c_name;
+ int c_val;
+} CODE;
+
+CODE prioritynames[] = {
+ { "alert", LOG_ALERT, },
+ { "crit", LOG_CRIT, },
+ { "debug", LOG_DEBUG, },
+ { "emerg", LOG_EMERG, },
+ { "err", LOG_ERR, },
+ { "error", LOG_ERR, }, /* DEPRECATED */
+ { "info", LOG_INFO, },
+ { "none", INTERNAL_NOPRI, }, /* INTERNAL */
+ { "notice", LOG_NOTICE, },
+ { "panic", LOG_EMERG, }, /* DEPRECATED */
+ { "warn", LOG_WARNING, }, /* DEPRECATED */
+ { "warning", LOG_WARNING, },
+ { NULL, -1, }
+};
+#endif
+
+/* facility codes */
+#define LOG_KERN (0<<3) /* kernel messages */
+#define LOG_USER (1<<3) /* random user-level messages */
+#define LOG_MAIL (2<<3) /* mail system */
+#define LOG_DAEMON (3<<3) /* system daemons */
+#define LOG_AUTH (4<<3) /* authorization messages */
+#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
+#define LOG_LPR (6<<3) /* line printer subsystem */
+#define LOG_NEWS (7<<3) /* network news subsystem */
+#define LOG_UUCP (8<<3) /* UUCP subsystem */
+#define LOG_CRON (9<<3) /* clock daemon */
+#define LOG_AUTHPRIV (10<<3) /* authorization messages (private) */
+ /* Facility #10 clashes in DEC UNIX, where */
+ /* it's defined as LOG_MEGASAFE for AdvFS */
+ /* event logging. */
+#define LOG_FTP (11<<3) /* ftp daemon */
+#define LOG_NTP (12<<3) /* NTP subsystem */
+
+ /* other codes through 15 reserved for system use */
+#define LOG_LOCAL0 (16<<3) /* reserved for local use */
+#define LOG_LOCAL1 (17<<3) /* reserved for local use */
+#define LOG_LOCAL2 (18<<3) /* reserved for local use */
+#define LOG_LOCAL3 (19<<3) /* reserved for local use */
+#define LOG_LOCAL4 (20<<3) /* reserved for local use */
+#define LOG_LOCAL5 (21<<3) /* reserved for local use */
+#define LOG_LOCAL6 (22<<3) /* reserved for local use */
+#define LOG_LOCAL7 (23<<3) /* reserved for local use */
+
+#define LOG_NFACILITIES 24 /* current number of facilities */
+#define LOG_FACMASK 0x03f8 /* mask to extract facility part */
+ /* facility of pri */
+#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
+
+#ifdef SYSLOG_NAMES
+CODE facilitynames[] = {
+ { "auth", LOG_AUTH, },
+ { "authpriv", LOG_AUTHPRIV, },
+ { "cron", LOG_CRON, },
+ { "daemon", LOG_DAEMON, },
+ { "ftp", LOG_FTP, },
+ { "kern", LOG_KERN, },
+ { "lpr", LOG_LPR, },
+ { "mail", LOG_MAIL, },
+ { "mark", INTERNAL_MARK, }, /* INTERNAL */
+ { "news", LOG_NEWS, },
+ { "ntp", LOG_NTP, },
+ { "security", LOG_AUTH, }, /* DEPRECATED */
+ { "syslog", LOG_SYSLOG, },
+ { "user", LOG_USER, },
+ { "uucp", LOG_UUCP, },
+ { "local0", LOG_LOCAL0, },
+ { "local1", LOG_LOCAL1, },
+ { "local2", LOG_LOCAL2, },
+ { "local3", LOG_LOCAL3, },
+ { "local4", LOG_LOCAL4, },
+ { "local5", LOG_LOCAL5, },
+ { "local6", LOG_LOCAL6, },
+ { "local7", LOG_LOCAL7, },
+ { NULL, -1, }
+};
+#endif
+
+#ifdef _KERNEL
+#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */
+#endif
+
+/*
+ * arguments to setlogmask.
+ */
+#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
+#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
+
+/*
+ * Option flags for openlog.
+ *
+ * LOG_ODELAY no longer does anything.
+ * LOG_NDELAY is the inverse of what it used to be.
+ */
+#define LOG_PID 0x01 /* log the pid with each message */
+#define LOG_CONS 0x02 /* log on the console if errors in sending */
+#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
+#define LOG_NDELAY 0x08 /* don't delay open */
+#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
+#define LOG_PERROR 0x20 /* log to stderr as well */
+
+#ifdef _KERNEL
+
+#else /* not _KERNEL */
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <stdarg.h>
+
+__BEGIN_DECLS
+void closelog(void);
+void openlog(const char *, int, int);
+int setlogmask(int);
+void syslog(int, const char *, ...);
+void vsyslog(int, const char *, va_list);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif
diff --git a/cpukit/libnetworking/sys/systm.h b/cpukit/libnetworking/sys/systm.h
new file mode 100644
index 0000000000..a66c746121
--- /dev/null
+++ b/cpukit/libnetworking/sys/systm.h
@@ -0,0 +1,107 @@
+/*-
+ * Copyright (c) 1982, 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)systm.h 8.7 (Berkeley) 3/29/95
+ * $FreeBSD: src/sys/sys/systm.h,v 1.248 2007/01/15 15:06:27 rrs Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_SYSTM_H_
+#define _SYS_SYSTM_H_
+
+#include <rtems/rtems_bsdnet_internal.h> /* for __BSD_VA_LIST__ */
+#include <machine/cpufunc.h>
+
+extern int securelevel; /* system security level (see init(8)) */
+
+extern int cold; /* nonzero if we are doing a cold boot */
+extern const char *panicstr; /* panic message */
+extern char version[]; /* system version */
+extern char copyright[]; /* system copyright */
+
+extern int physmem; /* physical memory */
+
+/*
+ * General function declarations.
+ */
+int nullop(void);
+int ureadc(int, struct uio *);
+void *hashinit(int count, int type, u_long *hashmask);
+void *phashinit(int count, int type, u_long *nentries);
+
+void panic(const char *, ...) __dead2;
+void boot(int) __dead2;
+void cpu_boot(int);
+int kvprintf(char const *, void (*)(int, void*), void *, int,
+ _BSD_VA_LIST_);
+void log(int, const char *, ...);
+int printf(const char *, ...);
+int sprintf(char *buf, const char *, ...);
+void uprintf(const char *, ...);
+void ttyprintf(struct tty *, const char *, ...);
+
+#define bcopy(f,t,n) memcpy((t),(f),(n))
+#define bzero(p,n) memset((p),(0),(n))
+
+int copystr(const void *kfaddr, void *kdaddr, size_t len,
+ size_t *lencopied);
+int copyinstr(const void *udaddr, void *kaddr, size_t len,
+ size_t *lencopied);
+#ifndef __rtems__
+/* FIXME: these clash with defines in rtems_bsdnet_internal.h */
+int copyin(const void *udaddr, void *kaddr, size_t len);
+int copyout(const void *kaddr, void *udaddr, size_t len);
+#endif
+
+int hzto(struct timeval *tv);
+
+#include <sys/libkern.h>
+
+/* Timeouts */
+typedef void (timeout_t)(void *); /* actual timeout function type */
+typedef timeout_t *timeout_func_t; /* a pointer to this type */
+
+void timeout(timeout_func_t, void *, int);
+void untimeout(timeout_func_t, void *);
+
+/*
+ * Common `proc' functions are declared here so that proc.h can be included
+ * less often.
+ */
+int tsleep(void *chan, int pri, char *wmesg, int timo);
+void wakeup(void *chan);
+
+#endif /* !_SYS_SYSTM_H_ */
diff --git a/cpukit/libnetworking/sys/ttydefaults.h b/cpukit/libnetworking/sys/ttydefaults.h
new file mode 100644
index 0000000000..68f0ddbe77
--- /dev/null
+++ b/cpukit/libnetworking/sys/ttydefaults.h
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94
+ * $Id$
+ */
+
+/*
+ * System wide defaults for terminal state.
+ */
+#ifndef _SYS_TTYDEFAULTS_H_
+#define _SYS_TTYDEFAULTS_H_
+
+/*
+ * Defaults on "first" open.
+ */
+#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
+#define TTYDEF_OFLAG (OPOST | ONLCR)
+#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
+#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
+#define TTYDEF_SPEED (B9600)
+
+/*
+ * Control Character Defaults
+ */
+#define CTRL(x) (x&037)
+#define CEOF CTRL('d')
+#define CEOL 0xff /* XXX avoid _POSIX_VDISABLE */
+#define CERASE 0177
+#define CINTR CTRL('c')
+#define CSTATUS CTRL('t')
+#define CKILL CTRL('u')
+#define CMIN 1
+#define CQUIT 034 /* FS, ^\ */
+#define CSUSP CTRL('z')
+#define CTIME 0
+#define CDSUSP CTRL('y')
+#define CSTART CTRL('q')
+#define CSTOP CTRL('s')
+#define CLNEXT CTRL('v')
+#define CDISCARD CTRL('o')
+#define CWERASE CTRL('w')
+#define CREPRINT CTRL('r')
+#define CEOT CEOF
+/* compat */
+#define CBRK CEOL
+#define CRPRNT CREPRINT
+#define CFLUSH CDISCARD
+
+/* PROTECTED INCLUSION ENDS HERE */
+#endif /* !_SYS_TTYDEFAULTS_H_ */
+
+/*
+ * #define TTYDEFCHARS to include an array of default control characters.
+ */
+#ifdef TTYDEFCHARS
+static cc_t ttydefchars[NCCS] = {
+ CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT,
+ _POSIX_VDISABLE, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT,
+ CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE
+};
+#undef TTYDEFCHARS
+#endif
diff --git a/cpukit/libnetworking/sys/ucred.h b/cpukit/libnetworking/sys/ucred.h
new file mode 100644
index 0000000000..e26bacd15a
--- /dev/null
+++ b/cpukit/libnetworking/sys/ucred.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)ucred.h 8.4 (Berkeley) 1/9/95
+ * $Id$
+ */
+
+#ifndef _SYS_UCRED_H_
+#define _SYS_UCRED_H_
+
+/*
+ * Credentials.
+ */
+struct ucred {
+ u_short cr_ref; /* reference count */
+ uid_t cr_uid; /* effective user id */
+ short cr_ngroups; /* number of groups */
+ gid_t cr_groups[NGROUPS]; /* groups */
+};
+#define cr_gid cr_groups[0]
+#define NOCRED ((struct ucred *)0) /* no credential available */
+#define FSCRED ((struct ucred *)-1) /* filesystem credential */
+
+#ifdef _KERNEL
+int suser(struct ucred *cred, u_short *acflag);
+#endif /* _KERNEL */
+
+#endif /* !_SYS_UCRED_H_ */
diff --git a/cpukit/libnetworking/sys/uio.h b/cpukit/libnetworking/sys/uio.h
new file mode 100644
index 0000000000..6b12a91260
--- /dev/null
+++ b/cpukit/libnetworking/sys/uio.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 1982, 1986, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)uio.h 8.5 (Berkeley) 2/22/94
+ * $FreeBSD: src/sys/sys/uio.h,v 1.40 2006/11/29 19:08:45 alfred Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_UIO_H_
+#define _SYS_UIO_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <sys/types.h>
+
+/*
+ * POSIX compliant iovec definition
+ */
+struct iovec {
+ void *iov_base; /* pointer to data to be written */
+ size_t iov_len; /* length of this data block */
+};
+
+#if __BSD_VISIBLE
+enum uio_rw { UIO_READ, UIO_WRITE };
+
+/* Segment flag values. */
+enum uio_seg {
+ UIO_USERSPACE, /* from user data space */
+ UIO_SYSSPACE, /* from system space */
+ UIO_NOCOPY /* don't copy, already in object */
+};
+#endif
+
+#ifdef _KERNEL
+
+struct uio {
+ struct iovec *uio_iov; /* scatter/gather list */
+ int uio_iovcnt; /* length of scatter/gather list */
+ off_t uio_offset; /* offset in target object */
+ ssize_t uio_resid; /* remaining bytes to process */
+ enum uio_seg uio_segflg; /* address space */
+ enum uio_rw uio_rw; /* operation */
+#if !defined(__rtems__)
+ struct thread *uio_td; /* owner */
+#else
+ struct proc *uio_procp;
+#endif /* !__rtems__ */
+};
+
+/*
+ * Limits
+ *
+ * N.B.: UIO_MAXIOV must be no less than IOV_MAX from <sys/syslimits.h>
+ * which in turn must be no less than _XOPEN_IOV_MAX from <limits.h>. If
+ * we ever make this tunable (probably pointless), then IOV_MAX should be
+ * removed from <sys/syslimits.h> and applications would be expected to use
+ * sysconf(3) to find out the correct value, or else assume the worst
+ * (_XOPEN_IOV_MAX). Perhaps UIO_MAXIOV should be simply defined as
+ * IOV_MAX.
+ */
+#define UIO_MAXIOV 1024 /* max 1K of iov's */
+
+int uiomove(void *cp, int n, struct uio *uio);
+
+#else /* !_KERNEL */
+
+__BEGIN_DECLS
+ssize_t readv(int, const struct iovec *, int);
+ssize_t writev(int, const struct iovec *, int);
+__END_DECLS
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_UIO_H_ */
diff --git a/cpukit/libnetworking/sys/un.h b/cpukit/libnetworking/sys/un.h
new file mode 100644
index 0000000000..cf169d3274
--- /dev/null
+++ b/cpukit/libnetworking/sys/un.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)un.h 8.3 (Berkeley) 2/19/95
+ * $FreeBSD: src/sys/sys/un.h,v 1.29 2005/04/13 00:01:46 mdodd Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _SYS_UN_H_
+#define _SYS_UN_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+#include <rtems/bsdnet/_types.h>
+
+#ifndef _SA_FAMILY_T_DECLARED
+typedef __sa_family_t sa_family_t;
+#define _SA_FAMILY_T_DECLARED
+#endif
+
+/*
+ * Definitions for UNIX IPC domain.
+ */
+struct sockaddr_un {
+ unsigned char sun_len; /* sockaddr len including null */
+ sa_family_t sun_family; /* AF_UNIX */
+ char sun_path[104]; /* path name (gag) */
+};
+
+#if __BSD_VISIBLE
+
+/* Socket options. */
+#define LOCAL_PEERCRED 0x001 /* retrieve peer credentials */
+#define LOCAL_CREDS 0x002 /* pass credentials to receiver */
+#define LOCAL_CONNWAIT 0x004 /* connects block until accepted */
+
+#ifdef _KERNEL
+struct mbuf;
+struct socket;
+struct sockopt;
+
+#else /* !_KERNEL */
+
+/* actual length of an initialized sockaddr_un */
+#define SUN_LEN(su) \
+ (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+
+#endif /* _KERNEL */
+
+#endif /* __BSD_VISIBLE */
+
+#endif /* !_SYS_UN_H_ */
diff --git a/cpukit/libnetworking/syslog.h b/cpukit/libnetworking/syslog.h
new file mode 100644
index 0000000000..6d223d00b7
--- /dev/null
+++ b/cpukit/libnetworking/syslog.h
@@ -0,0 +1,5 @@
+/*
+ * $Id$
+ */
+
+#include <sys/syslog.h>
diff --git a/cpukit/libnetworking/vm/vm.h b/cpukit/libnetworking/vm/vm.h
new file mode 100644
index 0000000000..4951ec6ec7
--- /dev/null
+++ b/cpukit/libnetworking/vm/vm.h
@@ -0,0 +1,99 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)vm.h 8.2 (Berkeley) 12/13/93
+ * @(#)vm_prot.h 8.1 (Berkeley) 6/11/93
+ * @(#)vm_inherit.h 8.1 (Berkeley) 6/11/93
+ *
+ * Copyright (c) 1987, 1990 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Authors: Avadis Tevanian, Jr., Michael Wayne Young
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ *
+ * $FreeBSD: src/sys/vm/vm.h,v 1.28 2007/12/27 17:08:11 alc Exp $
+ */
+
+#ifndef VM_H
+#define VM_H
+
+typedef char vm_inherit_t; /* XXX: inheritance codes */
+typedef u_char vm_prot_t; /* protection codes */
+
+union vm_map_object;
+typedef union vm_map_object vm_map_object_t;
+
+struct vm_map_entry;
+typedef struct vm_map_entry *vm_map_entry_t;
+
+struct vm_map;
+typedef struct vm_map *vm_map_t;
+
+struct vm_object;
+typedef struct vm_object *vm_object_t;
+
+#ifndef _KERNEL
+/*
+ * This is defined in <sys/types.h> for the kernel so that non-vm kernel
+ * sources (mainly Mach-derived ones such as ddb) don't have to include
+ * vm stuff. Defining it there for applications might break things.
+ * Define it here for "applications" that include vm headers (e.g.,
+ * genassym).
+ */
+typedef int boolean_t;
+
+/*
+ * This is defined in <sys/types.h> for the kernel so that vnode_if.h
+ * doesn't have to include <vm/vm.h>.
+ */
+struct vm_page;
+typedef struct vm_page *vm_page_t;
+#endif /* _KERNEL */
+
+#endif /* VM_H */
diff --git a/cpukit/libnetworking/vm/vm_extern.h b/cpukit/libnetworking/vm/vm_extern.h
new file mode 100644
index 0000000000..a610df3b4a
--- /dev/null
+++ b/cpukit/libnetworking/vm/vm_extern.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)vm_extern.h 8.2 (Berkeley) 1/12/94
+ * $FreeBSD: src/sys/vm/vm_extern.h,v 1.78 2006/05/29 21:28:56 tegge Exp $
+ */
+
+/*
+ * $Id$
+ */
+#ifndef _VM_EXTERN_H_
+#define _VM_EXTERN_H_
+
+struct buf;
+struct proc;
+struct vmtotal;
+struct mount;
+struct vnode;
+
+#endif /* !_VM_EXTERN_H_ */
diff --git a/cpukit/libnetworking/vm/vm_kern.h b/cpukit/libnetworking/vm/vm_kern.h
new file mode 100644
index 0000000000..c34ae65d49
--- /dev/null
+++ b/cpukit/libnetworking/vm/vm_kern.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * The Mach Operating System project at Carnegie-Mellon University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)vm_kern.h 8.1 (Berkeley) 6/11/93
+ *
+ *
+ * Copyright (c) 1987, 1990 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Authors: Avadis Tevanian, Jr., Michael Wayne Young
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ *
+ * $FreeBSD: src/sys/vm/vm_kern.h,v 1.28 2005/01/07 02:29:27 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _VM_VM_KERN_H_
+#define _VM_VM_KERN_H_ 1
+
+#if !defined(__rtems__)
+/* Kernel memory management definitions. */
+extern vm_map_t buffer_map;
+extern vm_map_t kernel_map;
+extern vm_map_t kmem_map;
+extern vm_map_t clean_map;
+extern vm_map_t exec_map;
+extern vm_map_t pipe_map;
+extern u_int vm_kmem_size;
+#endif
+
+#endif /* _VM_VM_KERN_H_ */
diff --git a/cpukit/libnetworking/vm/vm_param.h b/cpukit/libnetworking/vm/vm_param.h
new file mode 100644
index 0000000000..e7eac938ee
--- /dev/null
+++ b/cpukit/libnetworking/vm/vm_param.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * The Mach Operating System project at Carnegie-Mellon University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)vm_param.h 8.1 (Berkeley) 6/11/93
+ *
+ *
+ * Copyright (c) 1987, 1990 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Authors: Avadis Tevanian, Jr., Michael Wayne Young
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ *
+ * $FreeBSD: src/sys/vm/vm_param.h,v 1.21 2005/01/07 02:29:27 imp Exp $
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * Machine independent virtual memory parameters.
+ */
+
+#ifndef _VM_PARAM_
+#define _VM_PARAM_
+
+#include <machine/vmparam.h>
+
+/*
+ * CTL_VM identifiers
+ */
+#define VM_TOTAL 1 /* struct vmtotal */
+#define VM_METER VM_TOTAL/* deprecated, use VM_TOTAL */
+#define VM_LOADAVG 2 /* struct loadavg */
+#define VM_V_FREE_MIN 3 /* cnt.v_free_min */
+#define VM_V_FREE_TARGET 4 /* cnt.v_free_target */
+#define VM_V_FREE_RESERVED 5 /* cnt.v_free_reserved */
+#define VM_V_INACTIVE_TARGET 6 /* cnt.v_inactive_target */
+#define VM_V_CACHE_MIN 7 /* cnt.v_cache_max */
+#define VM_V_CACHE_MAX 8 /* cnt.v_cache_min */
+#define VM_V_PAGEOUT_FREE_MIN 9 /* cnt.v_pageout_free_min */
+#define VM_PAGEOUT_ALGORITHM 10 /* pageout algorithm */
+#define VM_SWAPPING_ENABLED 11 /* swapping enabled */
+#define VM_MAXID 12 /* number of valid vm ids */
+
+#define CTL_VM_NAMES { \
+ { 0, 0 }, \
+ { "vmtotal", CTLTYPE_STRUCT }, \
+ { "loadavg", CTLTYPE_STRUCT }, \
+ { "v_free_min", CTLTYPE_INT }, \
+ { "v_free_target", CTLTYPE_INT }, \
+ { "v_free_reserved", CTLTYPE_INT }, \
+ { "v_inactive_target", CTLTYPE_INT }, \
+ { "v_cache_min", CTLTYPE_INT }, \
+ { "v_cache_max", CTLTYPE_INT }, \
+ { "v_pageout_free_min", CTLTYPE_INT}, \
+ { "pageout_algorithm", CTLTYPE_INT}, \
+ { "swapping_enabled", CTLTYPE_INT},\
+}
+
+/*
+ * Return values from the VM routines.
+ */
+#define KERN_SUCCESS 0
+#define KERN_INVALID_ADDRESS 1
+#define KERN_PROTECTION_FAILURE 2
+#define KERN_NO_SPACE 3
+#define KERN_INVALID_ARGUMENT 4
+#define KERN_FAILURE 5
+#define KERN_RESOURCE_SHORTAGE 6
+#define KERN_NOT_RECEIVER 7
+#define KERN_NO_ACCESS 8
+
+#ifndef ASSEMBLER
+#ifdef _KERNEL
+#define num_pages(x) \
+ ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT))
+extern unsigned long maxtsiz;
+extern unsigned long dfldsiz;
+extern unsigned long maxdsiz;
+extern unsigned long dflssiz;
+extern unsigned long maxssiz;
+extern unsigned long sgrowsiz;
+#endif /* _KERNEL */
+#endif /* ASSEMBLER */
+#endif /* _VM_PARAM_ */
diff --git a/cpukit/librpc/.cvsignore b/cpukit/librpc/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/librpc/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/librpc/Makefile.am b/cpukit/librpc/Makefile.am
new file mode 100644
index 0000000000..98663f8e3f
--- /dev/null
+++ b/cpukit/librpc/Makefile.am
@@ -0,0 +1,91 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+EXTRA_DIST =
+
+if LIBRPC
+include_rpcdir = $(includedir)/rpc
+
+include_rpc_HEADERS = include/rpc/auth.h include/rpc/auth_unix.h
+include_rpc_HEADERS += include/rpc/clnt.h include/rpc/clnt_stat.h \
+ include/rpc/clnt_soc.h
+include_rpc_HEADERS += include/rpc/svc.h include/rpc/svc_auth.h \
+ include/rpc/svc_soc.h
+include_rpc_HEADERS += include/rpc/pmap_clnt.h include/rpc/pmap_prot.h \
+ include/rpc/pmap_rmt.h
+include_rpc_HEADERS += include/rpc/rpc.h include/rpc/types.h \
+ include/rpc/xdr.h include/rpc/rpc_com.h include/rpc/rpc_msg.h \
+ include/rpc/rpcent.h
+
+man_MANS =
+
+noinst_LIBRARIES = libxdr.a
+libxdr_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+libxdr_a_SOURCES = src/xdr/xdr.c src/xdr/xdr_array.c src/xdr/xdr_float.c \
+ src/xdr/xdr_mem.c src/xdr/xdr_rec.c src/xdr/xdr_reference.c \
+ src/xdr/xdr_sizeof.c src/xdr/xdr_stdio.c
+endif
+
+libxdr_mans = src/xdr/xdr.3
+EXTRA_DIST += $(libxdr_mans)
+
+if LIBRPC
+man_MANS += $(libxdr_mans)
+
+noinst_LIBRARIES += librpc.a
+librpc_a_CPPFLAGS = $(AM_CPPFLAGS) $(librpc_CPPFLAGS)
+
+librpc_a_SOURCES = src/rpc/auth_none.c src/rpc/auth_unix.c \
+ src/rpc/authunix_prot.c src/rpc/bindresvport.c src/rpc/clnt_generic.c \
+ src/rpc/clnt_perror.c src/rpc/clnt_raw.c src/rpc/clnt_simple.c \
+ src/rpc/clnt_tcp.c src/rpc/clnt_udp.c src/rpc/get_myaddress.c \
+ src/rpc/getrpcent.c src/rpc/getrpcport.c src/rpc/netname.c \
+ src/rpc/netnamer.c src/rpc/pmap_clnt.c src/rpc/pmap_getmaps.c \
+ src/rpc/pmap_getport.c src/rpc/pmap_prot.c src/rpc/pmap_prot2.c \
+ src/rpc/pmap_rmt.c src/rpc/rpc_callmsg.c src/rpc/rpc_commondata.c \
+ src/rpc/rpc_dtablesize.c src/rpc/rpc_prot.c src/rpc/rpcdname.c \
+ src/rpc/rtime.c src/rpc/svc.c src/rpc/svc_auth.c src/rpc/svc_auth_unix.c \
+ src/rpc/svc_raw.c src/rpc/svc_run.c src/rpc/svc_simple.c \
+ src/rpc/svc_tcp.c src/rpc/svc_udp.c src/rpc/rtems_portmapper.c \
+ src/rpc/rtems_rpc.c
+
+librpc_CPPFLAGS = -D_RPC_read=read -D_RPC_write=write -D_RPC_close=close \
+ -D_RTEMS_RPC_INTERNAL_
+endif
+
+librpc_mans = src/rpc/bindresvport.3 src/rpc/getrpcent.3 src/rpc/publickey.3 \
+ src/rpc/rpc.3 src/rpc/rpc_secure.3 src/rpc/rstat_svc.8 \
+ src/rpc/des_crypt.3 src/rpc/getrpcport.3 src/rpc/publickey.5 \
+ src/rpc/rpc.5 src/rpc/rstat.1 src/rpc/rtime.3
+EXTRA_DIST += $(librpc_mans)
+
+if LIBRPC
+man_MANS += $(librpc_mans)
+endif
+
+EXTRA_DIST += src/rpc/DISCLAIMER src/rpc/README
+
+EXTRA_DIST += README_RTEMS
+
+## FIXME: Unused
+EXTRA_DIST += include/rpcsvc/bootparam_prot.x include/rpcsvc/crypt.x \
+ include/rpcsvc/key_prot.x include/rpcsvc/klm_prot.x \
+ include/rpcsvc/mount.x include/rpcsvc/nfs_prot.x \
+ include/rpcsvc/nis_cache.x include/rpcsvc/nis_callback.x \
+ include/rpcsvc/nis_db.h include/rpcsvc/nislib.h \
+ include/rpcsvc/nis_object.x include/rpcsvc/nis_tags.h \
+ include/rpcsvc/nis.x include/rpcsvc/nlm_prot.x \
+ include/rpcsvc/pmap_prot.x include/rpcsvc/rex.x include/rpcsvc/rnusers.x \
+ include/rpcsvc/rquota.x include/rpcsvc/rstat.x include/rpcsvc/rwall.x \
+ include/rpcsvc/sm_inter.x include/rpcsvc/spray.x include/rpcsvc/ypclnt.h \
+ include/rpcsvc/yppasswd.x include/rpcsvc/yp_prot.h \
+ include/rpcsvc/ypupdate_prot.x include/rpcsvc/yp.x \
+ include/rpcsvc/ypxfrd.x
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/librpc/README_RTEMS b/cpukit/librpc/README_RTEMS
new file mode 100644
index 0000000000..e60f8799aa
--- /dev/null
+++ b/cpukit/librpc/README_RTEMS
@@ -0,0 +1,64 @@
+USING RPC/XDR ON RTEMS
+======================
+For the most part, programmers using RPC/XDR routines on RTEMS
+can proceed as if they were to be using a POSIX/UNIX system.
+The only significant changes are those to start the portmapper
+and to allow use of RPC/XDR by multiple threads.
+
+Starting the portmapper
+=======================
+The SUN portmapper program has been modified to run as an RTEMS
+task. Applications which need the portmapper can start this
+task by calling:
+ int rtems_rpc_start_portmapper (int priority);
+The return value is an RTEMS status code.
+
+Multi-threaded operation
+========================
+The RPC/XDR package has been modified to allow for multiple RTEMS
+tasks to use RPC/XDR routines. If more than one task is to call
+an RPC/XDR routine, the additional tasks must call:
+ int rtems_rpc_task_init(void);
+before calling any RPC/XDR routines. For example, the portmapper
+calls this routine since the portmapper uses RPC/XDR routines in
+a separate thread.
+The return value is an RTEMS status code.
+
+
+Porting Notes
+=============
+Most of the FreeBSD rpc library ports to RTEMS with little
+or no modification beyond that required to provide for operation
+in a multitasking environment. Multitasking operation was
+provided by moving all `static persistence' variables into
+a single structure and using an RTEMS task variable to point
+to that structure.
+
+Some of the library, however, has not made it into the RTEMS
+implementation. FreeBSD source files which have been left out include:
+- Files which provide RPC to the AF_UNIX address family:
+ clnt_unix.c
+ svc_unix.c
+ An `ifndef __rtems__' was added to clnt_generic.c because clnt_unix.c
+ was omitted.
+- Files which need NIS:
+ auth_time.c
+- Files which provide DES authentication:
+ auth_des.c
+ authdes_prot.c
+ crypt_client.c
+ des_crypt.c
+ des_soft.c
+ getpublickey.c
+ key_call.c
+ key_prot_xdr.c
+ svc_auth_des.c
+
+The FreeBSD xdr source compiles and runs on RTEMS without modification.
+
+The original source was obtained from:
+ ftp://ftp.FreeBSD.org/pub/FreeBSD/
+ branches/4.0-stable/src/lib/libc/rpc
+ branches/4.0-stable/src/lib/libc/xdr
+ branches/4.0-stable/src/include/rpc
+ branches/4.0-stable/src/include/rpcsvc
diff --git a/cpukit/librpc/include/rpc/auth.h b/cpukit/librpc/include/rpc/auth.h
new file mode 100644
index 0000000000..f644532f3e
--- /dev/null
+++ b/cpukit/librpc/include/rpc/auth.h
@@ -0,0 +1,260 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)auth.h 1.17 88/02/08 SMI
+ * from: @(#)auth.h 2.3 88/08/07 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/auth.h,v 1.15 1999/08/27 23:45:02 peter Exp $
+ */
+
+/*
+ * auth.h, Authentication interface.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * The data structures are completely opaque to the client. The client
+ * is required to pass a AUTH * to routines that create rpc
+ * "sessions".
+ */
+
+#ifndef _RPC_AUTH_H
+#define _RPC_AUTH_H
+#include <rtems/bsd/sys/cdefs.h>
+#include <sys/socket.h>
+
+#define MAX_AUTH_BYTES 400
+#define MAXNETNAMELEN 255 /* maximum length of network user's name */
+
+/*
+ * Status returned from authentication check
+ */
+enum auth_stat {
+ AUTH_OK=0,
+ /*
+ * failed at remote end
+ */
+ AUTH_BADCRED=1, /* bogus credentials (seal broken) */
+ AUTH_REJECTEDCRED=2, /* client should begin new session */
+ AUTH_BADVERF=3, /* bogus verifier (seal broken) */
+ AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
+ AUTH_TOOWEAK=5, /* rejected due to security reasons */
+ /*
+ * failed locally
+ */
+ AUTH_INVALIDRESP=6, /* bogus response verifier */
+ AUTH_FAILED=7 /* some unknown reason */
+};
+
+union des_block {
+ struct {
+ u_int32_t high;
+ u_int32_t low;
+ } key;
+ char c[8];
+};
+typedef union des_block des_block;
+__BEGIN_DECLS
+extern bool_t xdr_des_block (XDR *, des_block *);
+__END_DECLS
+
+/*
+ * Authentication info. Opaque to client.
+ */
+struct opaque_auth {
+ enum_t oa_flavor; /* flavor of auth */
+ caddr_t oa_base; /* address of more auth stuff */
+ u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
+};
+__BEGIN_DECLS
+bool_t xdr_opaque_auth (XDR *xdrs, struct opaque_auth *ap);
+__END_DECLS
+
+
+/*
+ * Auth handle, interface to client side authenticators.
+ */
+typedef struct __rpc_auth {
+ struct opaque_auth ah_cred;
+ struct opaque_auth ah_verf;
+ union des_block ah_key;
+ struct auth_ops {
+ void (*ah_nextverf) (struct __rpc_auth *);
+ /* nextverf & serialize */
+ int (*ah_marshal) (struct __rpc_auth *, XDR *);
+ /* validate verifier */
+ int (*ah_validate) (struct __rpc_auth *,
+ struct opaque_auth *);
+ /* refresh credentials */
+ int (*ah_refresh) (struct __rpc_auth *);
+ /* destroy this structure */
+ void (*ah_destroy) (struct __rpc_auth *);
+ } *ah_ops;
+ caddr_t ah_private;
+} AUTH;
+
+
+/*
+ * Authentication ops.
+ * The ops and the auth handle provide the interface to the authenticators.
+ *
+ * AUTH *auth;
+ * XDR *xdrs;
+ * struct opaque_auth verf;
+ */
+#define AUTH_NEXTVERF(auth) \
+ ((*((auth)->ah_ops->ah_nextverf))(auth))
+#define auth_nextverf(auth) \
+ ((*((auth)->ah_ops->ah_nextverf))(auth))
+
+#define AUTH_MARSHALL(auth, xdrs) \
+ ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
+#define auth_marshall(auth, xdrs) \
+ ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
+
+#define AUTH_VALIDATE(auth, verfp) \
+ ((*((auth)->ah_ops->ah_validate))((auth), verfp))
+#define auth_validate(auth, verfp) \
+ ((*((auth)->ah_ops->ah_validate))((auth), verfp))
+
+#define AUTH_REFRESH(auth) \
+ ((*((auth)->ah_ops->ah_refresh))(auth))
+#define auth_refresh(auth) \
+ ((*((auth)->ah_ops->ah_refresh))(auth))
+
+#define AUTH_DESTROY(auth) \
+ ((*((auth)->ah_ops->ah_destroy))(auth))
+#define auth_destroy(auth) \
+ ((*((auth)->ah_ops->ah_destroy))(auth))
+
+
+extern struct opaque_auth _null_auth;
+
+/*
+ * These are the various implementations of client side authenticators.
+ */
+
+/*
+ * Unix style authentication
+ * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
+ * char *machname;
+ * int uid;
+ * int gid;
+ * int len;
+ * int *aup_gids;
+ */
+__BEGIN_DECLS
+struct sockaddr_in;
+extern AUTH *authunix_create (char *, int, int, int, int *);
+extern AUTH *authunix_create_default (void);
+extern AUTH *authnone_create (void);
+__END_DECLS
+
+/* Forward compatibility with TI-RPC */
+#define authsys_create authunix_create
+#define authsys_create_default authunix_create_default
+
+/*
+ * DES style authentication
+ * AUTH *authdes_create(servername, window, timehost, ckey)
+ * char *servername; - network name of server
+ * u_int window; - time to live
+ * struct sockaddr *timehost; - optional hostname to sync with
+ * des_block *ckey; - optional conversation key to use
+ */
+__BEGIN_DECLS
+extern AUTH *authdes_create ( char *, u_int, struct sockaddr *, des_block * );
+#ifdef NOTYET
+/*
+ * TI-RPC supports this call, but it requires the inclusion of
+ * NIS+-specific headers which would require the inclusion of other
+ * headers which would result in a tangled mess. For now, the NIS+
+ * code prototypes this routine internally.
+ */
+extern AUTH *authdes_pk_create ( char *, netobj *, u_int,
+ struct sockaddr *, des_block *,
+ nis_server * );
+#endif
+__END_DECLS
+
+/*
+ * Netname manipulation routines.
+ */
+__BEGIN_DECLS
+extern int netname2user ( char *, uid_t *, gid_t *, int *, gid_t *);
+extern int netname2host ( char *, char *, int );
+extern int getnetname ( char * );
+extern int user2netname ( char *, uid_t, char * );
+extern int host2netname ( char *, char *, char * );
+extern void passwd2des ( char *, char * );
+__END_DECLS
+
+/*
+ * Keyserv interface routines.
+ * XXX Should not be here.
+ */
+#ifndef HEXKEYBYTES
+#define HEXKEYBYTES 48
+#endif
+typedef char kbuf[HEXKEYBYTES];
+typedef char *namestr;
+
+struct netstarg {
+ kbuf st_priv_key;
+ kbuf st_pub_key;
+ namestr st_netname;
+};
+
+__BEGIN_DECLS
+extern int key_decryptsession ( const char *, des_block * );
+extern int key_decryptsession_pk ( char *, netobj *, des_block * );
+extern int key_encryptsession ( const char *, des_block * );
+extern int key_encryptsession_pk ( char *, netobj *, des_block * );
+extern int key_gendes ( des_block * );
+extern int key_setsecret ( const char * );
+extern int key_secretkey_is_set ( void );
+extern int key_setnet ( struct netstarg * );
+extern int key_get_conv ( char *, des_block * );
+__END_DECLS
+
+/*
+ * Publickey routines.
+ */
+__BEGIN_DECLS
+extern int getpublickey ( char *, char * );
+extern int getpublicandprivatekey ( char *, char * );
+extern int getsecretkey ( char *, char *, char * );
+__END_DECLS
+
+
+#define AUTH_NONE 0 /* no authentication */
+#define AUTH_NULL 0 /* backward compatibility */
+#define AUTH_UNIX 1 /* unix style (uid, gids) */
+#define AUTH_SYS 1 /* forward compatibility */
+#define AUTH_SHORT 2 /* short hand unix style */
+#define AUTH_DES 3 /* des style (encrypted timestamps) */
+
+#endif /* !_RPC_AUTH_H */
diff --git a/cpukit/librpc/include/rpc/auth_unix.h b/cpukit/librpc/include/rpc/auth_unix.h
new file mode 100644
index 0000000000..ee4467217b
--- /dev/null
+++ b/cpukit/librpc/include/rpc/auth_unix.h
@@ -0,0 +1,84 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)auth_unix.h 1.8 88/02/08 SMI
+ * from: @(#)auth_unix.h 2.2 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/auth_unix.h,v 1.10 1999/08/27 23:45:03 peter Exp $
+ */
+
+/*
+ * auth_unix.h, Protocol for UNIX style authentication parameters for RPC
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+/*
+ * The system is very weak. The client uses no encryption for it
+ * credentials and only sends null verifiers. The server sends backs
+ * null verifiers or optionally a verifier that suggests a new short hand
+ * for the credentials.
+ */
+
+#ifndef _RPC_AUTH_UNIX_H
+#define _RPC_AUTH_UNIX_H
+#include <rtems/bsd/sys/cdefs.h>
+
+/* The machine name is part of a credential; it may not exceed 255 bytes */
+#define MAX_MACHINE_NAME 255
+
+/* gids compose part of a credential; there may not be more than 16 of them */
+#define NGRPS 16
+
+/*
+ * Unix style credentials.
+ */
+struct authunix_parms {
+ u_long aup_time;
+ char *aup_machname;
+ int aup_uid;
+ int aup_gid;
+ u_int aup_len;
+ int *aup_gids;
+};
+
+#define authsys_parms authunix_parms
+
+__BEGIN_DECLS
+extern bool_t xdr_authunix_parms(XDR *, struct authunix_parms *);
+__END_DECLS
+
+/*
+ * If a response verifier has flavor AUTH_SHORT,
+ * then the body of the response verifier encapsulates the following structure;
+ * again it is serialized in the obvious fashion.
+ */
+struct short_hand_verf {
+ struct opaque_auth new_cred;
+};
+
+#endif /* !_RPC_AUTH_UNIX_H */
diff --git a/cpukit/librpc/include/rpc/clnt.h b/cpukit/librpc/include/rpc/clnt.h
new file mode 100644
index 0000000000..b92abe367a
--- /dev/null
+++ b/cpukit/librpc/include/rpc/clnt.h
@@ -0,0 +1,312 @@
+/* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */
+
+/*
+ * The contents of this file are subject to the Sun Standards
+ * License Version 1.0 the (the "License";) You may not use
+ * this file except in compliance with the License. You may
+ * obtain a copy of the License at lib/libc/rpc/LICENSE
+ *
+ * Software distributed under the License is distributed on
+ * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the License for the specific
+ * language governing rights and limitations under the License.
+ *
+ * The Original Code is Copyright 1998 by Sun Microsystems, Inc
+ *
+ * The Initial Developer of the Original Code is: Sun
+ * Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)clnt.h 1.31 94/04/29 SMI
+ * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/clnt.h,v 1.21 2003/01/24 01:47:55 fjoe Exp $
+ */
+
+/*
+ * clnt.h - Client side remote procedure call interface.
+ *
+ * Copyright (c) 1986-1991,1994-1999 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _RPC_CLNT_H_
+#define _RPC_CLNT_H_
+#include <rpc/clnt_stat.h>
+#include <rtems/bsd/sys/cdefs.h>
+#include <sys/un.h>
+
+/*
+ * Error info.
+ */
+struct rpc_err {
+ enum clnt_stat re_status;
+ union {
+ int RE_errno; /* related system error */
+ enum auth_stat RE_why; /* why the auth error occurred */
+ struct {
+ rpcvers_t low; /* lowest version supported */
+ rpcvers_t high; /* highest version supported */
+ } RE_vers;
+ struct { /* maybe meaningful if RPC_FAILED */
+ int32_t s1;
+ int32_t s2;
+ } RE_lb; /* life boot & debugging only */
+ } ru;
+#define re_errno ru.RE_errno
+#define re_why ru.RE_why
+#define re_vers ru.RE_vers
+#define re_lb ru.RE_lb
+};
+
+
+/*
+ * Client rpc handle.
+ * Created by individual implementations
+ * Client is responsible for initializing auth, see e.g. auth_none.c.
+ */
+typedef struct __rpc_client {
+ AUTH *cl_auth; /* authenticator */
+ struct clnt_ops {
+ /* call remote procedure */
+ enum clnt_stat (*cl_call)(struct __rpc_client *,
+ rpcproc_t, xdrproc_t, void *, xdrproc_t,
+ void *, struct timeval);
+ /* abort a call */
+ void (*cl_abort)(void);
+ /* get specific error code */
+ void (*cl_geterr)(struct __rpc_client *,
+ struct rpc_err *);
+ /* frees results */
+ bool_t (*cl_freeres)(struct __rpc_client *,
+ xdrproc_t, void *);
+ /* destroy this structure */
+ void (*cl_destroy)(struct __rpc_client *);
+ /* the ioctl() of rpc */
+ bool_t (*cl_control)(struct __rpc_client *, int,
+ char *);
+ } *cl_ops;
+ void *cl_private; /* private stuff */
+} CLIENT;
+
+#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
+
+/*
+ * client side rpc interface ops
+ *
+ * Parameter types are:
+ *
+ */
+
+/*
+ * enum clnt_stat
+ * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
+ * CLIENT *rh;
+ * rpcproc_t proc;
+ * xdrproc_t xargs;
+ * void *argsp;
+ * xdrproc_t xres;
+ * void *resp;
+ * struct timeval timeout;
+ */
+#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
+ ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
+ argsp, xres, resp, secs))
+#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
+ ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
+ argsp, xres, resp, secs))
+
+/*
+ * void
+ * CLNT_ABORT(rh);
+ * CLIENT *rh;
+ */
+#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
+#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
+
+/*
+ * struct rpc_err
+ * CLNT_GETERR(rh);
+ * CLIENT *rh;
+ */
+#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
+#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
+
+
+/*
+ * bool_t
+ * CLNT_FREERES(rh, xres, resp);
+ * CLIENT *rh;
+ * xdrproc_t xres;
+ * void *resp;
+ */
+#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
+#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
+
+/*
+ * bool_t
+ * CLNT_CONTROL(cl, request, info)
+ * CLIENT *cl;
+ * u_int request;
+ * char *info;
+ */
+#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
+#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
+
+/*
+ * control operations that apply to udp, tcp and unix transports
+ *
+ * Note: options marked XXX are no-ops in this implementation of RPC.
+ * The are present in TI-RPC but can't be implemented here since they
+ * depend on the presence of STREAMS/TLI, which we don't have.
+ *
+ */
+#define CLSET_TIMEOUT 1 /* set timeout (timeval) */
+#define CLGET_TIMEOUT 2 /* get timeout (timeval) */
+#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
+#define CLGET_FD 6 /* get connections file descriptor */
+#define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */
+#define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */
+#define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */
+#define CLGET_XID 10 /* Get xid */
+#define CLSET_XID 11 /* Set xid */
+#define CLGET_VERS 12 /* Get version number */
+#define CLSET_VERS 13 /* Set version number */
+#define CLGET_PROG 14 /* Get program number */
+#define CLSET_PROG 15 /* Set program number */
+#define CLSET_SVC_ADDR 16 /* get server's address (netbuf) XXX */
+#define CLSET_PUSH_TIMOD 17 /* push timod if not already present XXX */
+#define CLSET_POP_TIMOD 18 /* pop timod XXX */
+
+/*
+ * Connectionless only control operations
+ */
+#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
+#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
+
+/*
+ * Operations which GSSAPI needs. (Bletch.)
+ */
+#define CLGET_LOCAL_ADDR 19 /* get local addr (sockaddr) */
+
+
+/*
+ * void
+ * CLNT_DESTROY(rh);
+ * CLIENT *rh;
+ */
+#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
+#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
+
+
+/*
+ * RPCTEST is a test program which is accessible on every rpc
+ * transport/port. It is used for testing, performance evaluation,
+ * and network administration.
+ */
+
+#define RPCTEST_PROGRAM ((rpcprog_t)1)
+#define RPCTEST_VERSION ((rpcvers_t)1)
+#define RPCTEST_NULL_PROC ((rpcproc_t)2)
+#define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
+
+/*
+ * By convention, procedure 0 takes null arguments and returns them
+ */
+
+#define NULLPROC ((rpcproc_t)0)
+
+/*
+ * Below are the client handle creation routines for the various
+ * implementations of client side rpc. They can return NULL if a
+ * creation failure occurs.
+ */
+
+/*
+ * Generic client creation routine. Supported protocols are "udp", "tcp"
+ * and "unix".
+ */
+__BEGIN_DECLS
+extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
+ const char *);
+__END_DECLS
+
+/*
+ * Added for compatibility to old rpc 4.0. Obsoleted by clnt_vc_create().
+ */
+__BEGIN_DECLS
+extern CLIENT *clntunix_create(struct sockaddr_un *,
+ u_long, u_long, int *, u_int, u_int);
+__END_DECLS
+
+
+/*
+ * Print why creation failed
+ */
+__BEGIN_DECLS
+extern void clnt_pcreateerror(const char *); /* stderr */
+extern char *clnt_spcreateerror(const char *); /* string */
+__END_DECLS
+
+/*
+ * Like clnt_perror(), but is more verbose in its output
+ */
+__BEGIN_DECLS
+extern void clnt_perrno(enum clnt_stat); /* stderr */
+extern char *clnt_sperrno(enum clnt_stat); /* string */
+__END_DECLS
+
+/*
+ * Print an English error message, given the client error code
+ */
+__BEGIN_DECLS
+extern void clnt_perror(CLIENT *, const char *); /* stderr */
+extern char *clnt_sperror(CLIENT *, const char *); /* string */
+__END_DECLS
+
+
+/*
+ * If a creation fails, the following allows the user to figure out why.
+ */
+struct rpc_createerr {
+ enum clnt_stat cf_stat;
+ struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
+};
+
+extern struct rpc_createerr rpc_createerr;
+
+/* For backward compatibility */
+#include <rpc/clnt_soc.h>
+
+#endif /* !_RPC_CLNT_H_ */
diff --git a/cpukit/librpc/include/rpc/clnt_soc.h b/cpukit/librpc/include/rpc/clnt_soc.h
new file mode 100644
index 0000000000..f00a0b6e60
--- /dev/null
+++ b/cpukit/librpc/include/rpc/clnt_soc.h
@@ -0,0 +1,106 @@
+/* $NetBSD: clnt_soc.h,v 1.1 2000/06/02 22:57:55 fvdl Exp $ */
+/* $FreeBSD: src/include/rpc/clnt_soc.h,v 1.2 2002/03/23 17:24:55 imp Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+/*
+ * Copyright (c) 1984 - 1991 by Sun Microsystems, Inc.
+ */
+
+/*
+ * clnt.h - Client side remote procedure call interface.
+ */
+
+#ifndef _RPC_CLNT_SOC_H
+#define _RPC_CLNT_SOC_H
+
+/* derived from clnt_soc.h 1.3 88/12/17 SMI */
+
+/*
+ * All the following declarations are only for backward compatibility
+ * with TS-RPC.
+ */
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
+
+/*
+ * TCP based rpc
+ * CLIENT *
+ * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
+ * struct sockaddr_in *raddr;
+ * u_long prog;
+ * u_long version;
+ * register int *sockp;
+ * u_int sendsz;
+ * u_int recvsz;
+ */
+__BEGIN_DECLS
+extern CLIENT *clnttcp_create(struct sockaddr_in *, u_long, u_long, int *,
+ u_int, u_int);
+__END_DECLS
+
+/*
+ * Raw (memory) rpc.
+ */
+__BEGIN_DECLS
+extern CLIENT *clntraw_create(u_long, u_long);
+__END_DECLS
+
+
+/*
+ * UDP based rpc.
+ * CLIENT *
+ * clntudp_create(raddr, program, version, wait, sockp)
+ * struct sockaddr_in *raddr;
+ * u_long program;
+ * u_long version;
+ * struct timeval wait;
+ * int *sockp;
+ *
+ * Same as above, but you specify max packet sizes.
+ * CLIENT *
+ * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
+ * struct sockaddr_in *raddr;
+ * u_long program;
+ * u_long version;
+ * struct timeval wait;
+ * int *sockp;
+ * u_int sendsz;
+ * u_int recvsz;
+ */
+__BEGIN_DECLS
+extern CLIENT *clntudp_create(struct sockaddr_in *, u_long, u_long,
+ struct timeval, int *);
+extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, u_long, u_long,
+ struct timeval, int *, u_int, u_int);
+__END_DECLS
+
+#endif /* _RPC_CLNT_SOC_H */
diff --git a/cpukit/librpc/include/rpc/clnt_stat.h b/cpukit/librpc/include/rpc/clnt_stat.h
new file mode 100644
index 0000000000..397bdbc596
--- /dev/null
+++ b/cpukit/librpc/include/rpc/clnt_stat.h
@@ -0,0 +1,83 @@
+/* $FreeBSD: src/include/rpc/clnt_stat.h,v 1.2 2001/03/20 08:20:50 alfred Exp $ */
+/*
+ * Copyright (c) 1986 - 1991, 1994, 1996, 1997 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+/*
+ * clnt_stat.h - Client side remote procedure call enum
+ *
+ */
+
+#ifndef _RPC_CLNT_STAT_H
+#define _RPC_CLNT_STAT_H
+
+/* #pragma ident "@(#)clnt_stat.h 1.2 97/04/28 SMI" */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum clnt_stat {
+ RPC_SUCCESS = 0, /* call succeeded */
+ /*
+ * local errors
+ */
+ RPC_CANTENCODEARGS = 1, /* can't encode arguments */
+ RPC_CANTDECODERES = 2, /* can't decode results */
+ RPC_CANTSEND = 3, /* failure in sending call */
+ RPC_CANTRECV = 4,
+ /* failure in receiving result */
+ RPC_TIMEDOUT = 5, /* call timed out */
+ RPC_INTR = 18, /* call interrupted */
+ RPC_UDERROR = 23, /* recv got uderr indication */
+ /*
+ * remote errors
+ */
+ RPC_VERSMISMATCH = 6, /* rpc versions not compatible */
+ RPC_AUTHERROR = 7, /* authentication error */
+ RPC_PROGUNAVAIL = 8, /* program not available */
+ RPC_PROGVERSMISMATCH = 9, /* program version mismatched */
+ RPC_PROCUNAVAIL = 10, /* procedure unavailable */
+ RPC_CANTDECODEARGS = 11, /* decode arguments error */
+ RPC_SYSTEMERROR = 12, /* generic "other problem" */
+
+ /*
+ * rpc_call & clnt_create errors
+ */
+ RPC_UNKNOWNHOST = 13, /* unknown host name */
+ RPC_UNKNOWNPROTO = 17, /* unknown protocol */
+ RPC_UNKNOWNADDR = 19, /* Remote address unknown */
+ RPC_NOBROADCAST = 21, /* Broadcasting not supported */
+
+ /*
+ * rpcbind errors
+ */
+ RPC_RPCBFAILURE = 14, /* the pmapper failed in its call */
+#define RPC_PMAPFAILURE RPC_RPCBFAILURE
+ RPC_PROGNOTREGISTERED = 15, /* remote program is not registered */
+ RPC_N2AXLATEFAILURE = 22,
+ /* Name to address translation failed */
+ /*
+ * Misc error in the TLI library
+ */
+ RPC_TLIERROR = 20,
+ /*
+ * unspecified error
+ */
+ RPC_FAILED = 16,
+ /*
+ * asynchronous errors
+ */
+ RPC_INPROGRESS = 24,
+ RPC_STALERACHANDLE = 25,
+ RPC_CANTCONNECT = 26, /* couldn't make connection (cots) */
+ RPC_XPRTFAILED = 27, /* received discon from remote (cots) */
+ RPC_CANTCREATESTREAM = 28 /* can't push rpc module (cots) */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_RPC_CLNT_STAT_H */
diff --git a/cpukit/librpc/include/rpc/pmap_clnt.h b/cpukit/librpc/include/rpc/pmap_clnt.h
new file mode 100644
index 0000000000..379bb46489
--- /dev/null
+++ b/cpukit/librpc/include/rpc/pmap_clnt.h
@@ -0,0 +1,85 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)pmap_clnt.h 1.11 88/02/08 SMI
+ * from: @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/pmap_clnt.h,v 1.11 1999/08/27 23:45:04 peter Exp $
+ */
+
+/*
+ * pmap_clnt.h
+ * Supplies C routines to get to portmap services.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+/*
+ * Usage:
+ * success = pmap_set(program, version, protocol, port);
+ * success = pmap_unset(program, version);
+ * port = pmap_getport(address, program, version, protocol);
+ * head = pmap_getmaps(address);
+ * clnt_stat = pmap_rmtcall(address, program, version, procedure,
+ * xdrargs, argsp, xdrres, resp, tout, port_ptr)
+ * (works for udp only.)
+ * clnt_stat = clnt_broadcast(program, version, procedure,
+ * xdrargs, argsp, xdrres, resp, eachresult)
+ * (like pmap_rmtcall, except the call is broadcasted to all
+ * locally connected nets. For each valid response received,
+ * the procedure eachresult is called. Its form is:
+ * done = eachresult(resp, raddr)
+ * bool_t done;
+ * caddr_t resp;
+ * struct sockaddr_in raddr;
+ * where resp points to the results of the call and raddr is the
+ * address if the responder to the broadcast.
+ */
+
+#ifndef _RPC_PMAPCLNT_H
+#define _RPC_PMAPCLNT_H
+#include <rtems/bsd/sys/cdefs.h>
+
+__BEGIN_DECLS
+extern bool_t pmap_set (u_long, u_long, int, int);
+extern bool_t pmap_unset (u_long, u_long);
+extern struct pmaplist *pmap_getmaps (struct sockaddr_in *);
+extern enum clnt_stat pmap_rmtcall (struct sockaddr_in *,
+ u_long, u_long, u_long,
+ xdrproc_t, caddr_t,
+ xdrproc_t, caddr_t,
+ struct timeval, u_long *);
+extern enum clnt_stat clnt_broadcast (u_long, u_long, u_long,
+ xdrproc_t, char *,
+ xdrproc_t, char *,
+ bool_t (*) (caddr_t,
+ struct sockaddr_in *));
+extern u_short pmap_getport (struct sockaddr_in *,
+ u_long, u_long, u_int);
+__END_DECLS
+
+#endif /* !_RPC_PMAPCLNT_H */
diff --git a/cpukit/librpc/include/rpc/pmap_prot.h b/cpukit/librpc/include/rpc/pmap_prot.h
new file mode 100644
index 0000000000..6ec7468dcc
--- /dev/null
+++ b/cpukit/librpc/include/rpc/pmap_prot.h
@@ -0,0 +1,104 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)pmap_prot.h 1.14 88/02/08 SMI
+ * from: @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/pmap_prot.h,v 1.10 1999/08/27 23:45:04 peter Exp $
+ */
+
+/*
+ * pmap_prot.h
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * The following procedures are supported by the protocol:
+ *
+ * PMAPPROC_NULL() returns ()
+ * takes nothing, returns nothing
+ *
+ * PMAPPROC_SET(struct pmap) returns (bool_t)
+ * TRUE is success, FALSE is failure. Registers the tuple
+ * [prog, vers, prot, port].
+ *
+ * PMAPPROC_UNSET(struct pmap) returns (bool_t)
+ * TRUE is success, FALSE is failure. Un-registers pair
+ * [prog, vers]. prot and port are ignored.
+ *
+ * PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
+ * 0 is failure. Otherwise returns the port number where the pair
+ * [prog, vers] is registered. It may lie!
+ *
+ * PMAPPROC_DUMP() RETURNS (struct pmaplist *)
+ *
+ * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
+ * RETURNS (port, string<>);
+ * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
+ * Calls the procedure on the local machine. If it is not registered,
+ * this procedure is quite; ie it does not return error information!!!
+ * This procedure only is supported on rpc/udp and calls via
+ * rpc/udp. This routine only passes null authentication parameters.
+ * This file has no interface to xdr routines for PMAPPROC_CALLIT.
+ *
+ * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
+ */
+
+#ifndef _RPC_PMAPPROT_H
+#define _RPC_PMAPPROT_H
+#include <rtems/bsd/sys/cdefs.h>
+
+#define PMAPPORT ((u_short)111)
+#define PMAPPROG ((u_long)100000)
+#define PMAPVERS ((u_long)2)
+#define PMAPVERS_PROTO ((u_long)2)
+#define PMAPVERS_ORIG ((u_long)1)
+#define PMAPPROC_NULL ((u_long)0)
+#define PMAPPROC_SET ((u_long)1)
+#define PMAPPROC_UNSET ((u_long)2)
+#define PMAPPROC_GETPORT ((u_long)3)
+#define PMAPPROC_DUMP ((u_long)4)
+#define PMAPPROC_CALLIT ((u_long)5)
+
+struct pmap {
+ long unsigned pm_prog;
+ long unsigned pm_vers;
+ long unsigned pm_prot;
+ long unsigned pm_port;
+};
+
+struct pmaplist {
+ struct pmap pml_map;
+ struct pmaplist *pml_next;
+};
+
+__BEGIN_DECLS
+extern bool_t xdr_pmap (XDR *, struct pmap *);
+extern bool_t xdr_pmaplist (XDR *, struct pmaplist **);
+__END_DECLS
+
+#endif /* !_RPC_PMAPPROT_H */
diff --git a/cpukit/librpc/include/rpc/pmap_rmt.h b/cpukit/librpc/include/rpc/pmap_rmt.h
new file mode 100644
index 0000000000..fb2727b6f9
--- /dev/null
+++ b/cpukit/librpc/include/rpc/pmap_rmt.h
@@ -0,0 +1,63 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)pmap_rmt.h 1.2 88/02/08 SMI
+ * from: @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/pmap_rmt.h,v 1.10 1999/08/27 23:45:05 peter Exp $
+ */
+
+/*
+ * Structures and XDR routines for parameters to and replies from
+ * the portmapper remote-call-service.
+ *
+ * Copyright (C) 1986, Sun Microsystems, Inc.
+ */
+
+#ifndef _RPC_PMAPRMT_H
+#define _RPC_PMAPRMT_H
+#include <rtems/bsd/sys/cdefs.h>
+
+struct rmtcallargs {
+ u_long prog, vers, proc, arglen;
+ caddr_t args_ptr;
+ xdrproc_t xdr_args;
+};
+
+struct rmtcallres {
+ u_long *port_ptr;
+ u_long resultslen;
+ caddr_t results_ptr;
+ xdrproc_t xdr_results;
+};
+
+__BEGIN_DECLS
+extern bool_t xdr_rmtcall_args (XDR *, struct rmtcallargs *);
+extern bool_t xdr_rmtcallres (XDR *, struct rmtcallres *);
+__END_DECLS
+
+#endif /* !_RPC_PMAPRMT_H */
diff --git a/cpukit/librpc/include/rpc/rpc.h b/cpukit/librpc/include/rpc/rpc.h
new file mode 100644
index 0000000000..95df085926
--- /dev/null
+++ b/cpukit/librpc/include/rpc/rpc.h
@@ -0,0 +1,116 @@
+/* $NetBSD: rpc.h,v 1.13 2000/06/02 22:57:56 fvdl Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)rpc.h 1.9 88/02/08 SMI
+ * from: @(#)rpc.h 2.4 89/07/11 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/rpc.h,v 1.17 2002/03/23 17:24:55 imp Exp $
+ */
+
+/*
+ * rpc.h, Just includes the billions of rpc header files necessary to
+ * do remote procedure calling.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+#ifndef _RPC_RPC_H
+#define _RPC_RPC_H
+
+#include <rpc/types.h> /* some typedefs */
+#include <netinet/in.h>
+
+/* external data representation interfaces */
+#include <rpc/xdr.h> /* generic (de)serializer */
+
+/* Client side only authentication */
+#include <rpc/auth.h> /* generic authenticator (client side) */
+
+/* Client side (mostly) remote procedure call */
+#include <rpc/clnt.h> /* generic rpc stuff */
+
+/* semi-private protocol headers */
+#include <rpc/rpc_msg.h> /* protocol for rpc messages */
+#include <rpc/auth_unix.h> /* protocol for unix style cred */
+
+/* Server side only remote procedure callee */
+#include <rpc/svc.h> /* service manager and multiplexer */
+#include <rpc/svc_auth.h> /* service side authenticator */
+
+#include <rpc/rpcent.h>
+
+__BEGIN_DECLS
+extern int get_myaddress(struct sockaddr_in *);
+extern int bindresvport(int, struct sockaddr_in *);
+extern int bindresvport_sa(int, struct sockaddr *);
+__END_DECLS
+
+int rtems_rpc_task_init (void);
+int rtems_rpc_start_portmapper (int priority);
+
+#ifdef _RTEMS_RPC_INTERNAL_
+/*
+ * Multi-threaded support
+ * Group all global and static variables into a single spot.
+ * This area will be allocated on a per-task basis
+ */
+struct _rtems_rpc_task_variables {
+ int svc_svc_maxfd;
+ fd_set svc_svc_fdset;
+ SVCXPRT ** svc_xports;
+ int svc_xportssize;
+ int svc__svc_fdsetsize;
+ fd_set *svc__svc_fdset;
+ struct svc_callout *svc_svc_head;
+
+ char *clnt_perror_buf;
+
+ struct clnt_raw_private *clnt_raw_private;
+
+ void *call_rpc_private;
+
+ struct call_rpc_private *svc_raw_private;
+
+ struct prog_lst *svc_simple_proglst;
+ struct prog_lst *svc_simple_pl;
+ SVCXPRT *svc_simple_transp;
+
+ char *rpcdname_default_domain;
+
+ struct authsvc *svc_auths_Auths;
+};
+extern struct _rtems_rpc_task_variables *rtems_rpc_task_variables;
+
+#define svc_maxfd (rtems_rpc_task_variables->svc_svc_maxfd)
+#define svc_fdset (rtems_rpc_task_variables->svc_svc_fdset)
+#define __svc_fdsetsize (rtems_rpc_task_variables->svc__svc_fdsetsize)
+#define __svc_fdset (rtems_rpc_task_variables->svc__svc_fdset)
+
+#endif /* _RTEMS_RPC_INTERNAL_ */
+
+#endif /* !_RPC_RPC_H */
diff --git a/cpukit/librpc/include/rpc/rpc_com.h b/cpukit/librpc/include/rpc/rpc_com.h
new file mode 100644
index 0000000000..8434babea9
--- /dev/null
+++ b/cpukit/librpc/include/rpc/rpc_com.h
@@ -0,0 +1,68 @@
+/* $NetBSD: rpc_com.h,v 1.3 2000/12/10 04:10:08 christos Exp $ */
+/* $FreeBSD: src/include/rpc/rpc_com.h,v 1.6 2003/01/16 07:13:51 mbr Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+/*
+ * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * rpc_com.h, Common definitions for both the server and client side.
+ * All for the topmost layer of rpc
+ *
+ */
+
+#ifndef _RPC_RPCCOM_H
+#define _RPC_RPCCOM_H
+
+#include <rtems/bsd/sys/cdefs.h>
+
+/* #pragma ident "@(#)rpc_com.h 1.11 93/07/05 SMI" */
+
+/*
+ * The max size of the transport, if the size cannot be determined
+ * by other means.
+ */
+#define RPC_MAXDATASIZE 9000
+#define RPC_MAXADDRSIZE 1024
+
+__BEGIN_DECLS
+extern u_int __rpc_get_a_size(int);
+extern u_int __rpc_get_t_size(int, long);
+extern int __rpc_dtbsize(void);
+extern int _rpc_dtablesize(void);
+extern int _rpc_get_default_domain(char **);
+__END_DECLS
+
+#endif /* _RPC_RPCCOM_H */
diff --git a/cpukit/librpc/include/rpc/rpc_msg.h b/cpukit/librpc/include/rpc/rpc_msg.h
new file mode 100644
index 0000000000..21fcb841a1
--- /dev/null
+++ b/cpukit/librpc/include/rpc/rpc_msg.h
@@ -0,0 +1,199 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)rpc_msg.h 1.7 86/07/16 SMI
+ * from: @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/rpc_msg.h,v 1.15 2003/01/01 18:48:42 schweikh Exp $
+ */
+
+/*
+ * rpc_msg.h
+ * rpc message definition
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+/*
+ * $Id$
+ */
+
+#ifndef _RPC_RPC_MSG_H
+#define _RPC_RPC_MSG_H
+
+#define RPC_MSG_VERSION ((u_int32_t) 2)
+#define RPC_SERVICE_PORT ((u_short) 2048)
+
+/*
+ * Bottom up definition of an rpc message.
+ * NOTE: call and reply use the same overall stuct but
+ * different parts of unions within it.
+ */
+
+enum msg_type {
+ CALL=0,
+ REPLY=1
+};
+
+enum reply_stat {
+ MSG_ACCEPTED=0,
+ MSG_DENIED=1
+};
+
+enum accept_stat {
+ SUCCESS=0,
+ PROG_UNAVAIL=1,
+ PROG_MISMATCH=2,
+ PROC_UNAVAIL=3,
+ GARBAGE_ARGS=4,
+ SYSTEM_ERR=5
+};
+
+enum reject_stat {
+ RPC_MISMATCH=0,
+ AUTH_ERROR=1
+};
+
+/*
+ * Reply part of an rpc exchange
+ */
+
+/*
+ * Reply to an rpc request that was accepted by the server.
+ * Note: there could be an error even though the request was
+ * accepted.
+ */
+struct accepted_reply {
+ struct opaque_auth ar_verf;
+ enum accept_stat ar_stat;
+ union {
+ struct {
+ rpcvers_t low;
+ rpcvers_t high;
+ } AR_versions;
+ struct {
+ caddr_t where;
+ xdrproc_t proc;
+ } AR_results;
+ /* and many other null cases */
+ } ru;
+#define ar_results ru.AR_results
+#define ar_vers ru.AR_versions
+};
+
+/*
+ * Reply to an rpc request that was rejected by the server.
+ */
+struct rejected_reply {
+ enum reject_stat rj_stat;
+ union {
+ struct {
+ rpcvers_t low;
+ rpcvers_t high;
+ } RJ_versions;
+ enum auth_stat RJ_why; /* why authentication did not work */
+ } ru;
+#define rj_vers ru.RJ_versions
+#define rj_why ru.RJ_why
+};
+
+/*
+ * Body of a reply to an rpc request.
+ */
+struct reply_body {
+ enum reply_stat rp_stat;
+ union {
+ struct accepted_reply RP_ar;
+ struct rejected_reply RP_dr;
+ } ru;
+#define rp_acpt ru.RP_ar
+#define rp_rjct ru.RP_dr
+};
+
+/*
+ * Body of an rpc request call.
+ */
+struct call_body {
+ rpcvers_t cb_rpcvers; /* must be equal to two */
+ rpcprog_t cb_prog;
+ rpcvers_t cb_vers;
+ rpcproc_t cb_proc;
+ struct opaque_auth cb_cred;
+ struct opaque_auth cb_verf; /* protocol specific - provided by client */
+};
+
+/*
+ * The rpc message
+ */
+struct rpc_msg {
+ u_int32_t rm_xid;
+ enum msg_type rm_direction;
+ union {
+ struct call_body RM_cmb;
+ struct reply_body RM_rmb;
+ } ru;
+#define rm_call ru.RM_cmb
+#define rm_reply ru.RM_rmb
+};
+#define acpted_rply ru.RM_rmb.ru.RP_ar
+#define rjcted_rply ru.RM_rmb.ru.RP_dr
+
+__BEGIN_DECLS
+/*
+ * XDR routine to handle a rpc message.
+ * xdr_callmsg(xdrs, cmsg)
+ * XDR *xdrs;
+ * struct rpc_msg *cmsg;
+ */
+extern bool_t xdr_callmsg(XDR *, struct rpc_msg *);
+
+/*
+ * XDR routine to pre-serialize the static part of a rpc message.
+ * xdr_callhdr(xdrs, cmsg)
+ * XDR *xdrs;
+ * struct rpc_msg *cmsg;
+ */
+extern bool_t xdr_callhdr(XDR *, struct rpc_msg *);
+
+/*
+ * XDR routine to handle a rpc reply.
+ * xdr_replymsg(xdrs, rmsg)
+ * XDR *xdrs;
+ * struct rpc_msg *rmsg;
+ */
+extern bool_t xdr_replymsg(XDR *, struct rpc_msg *);
+
+/*
+ * Fills in the error part of a reply message.
+ * _seterr_reply(msg, error)
+ * struct rpc_msg *msg;
+ * struct rpc_err *error;
+ */
+extern void _seterr_reply(struct rpc_msg *, struct rpc_err *);
+__END_DECLS
+
+#endif /* !_RPC_RPC_MSG_H */
diff --git a/cpukit/librpc/include/rpc/rpcent.h b/cpukit/librpc/include/rpc/rpcent.h
new file mode 100644
index 0000000000..e9fbaf6660
--- /dev/null
+++ b/cpukit/librpc/include/rpc/rpcent.h
@@ -0,0 +1,71 @@
+/* $NetBSD: rpcent.h,v 1.1 2000/06/02 22:57:56 fvdl Exp $ */
+/* $FreeBSD: src/include/rpc/rpcent.h,v 1.2 2002/03/23 17:24:55 imp Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+/*
+ * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
+ */
+
+/*
+ * rpcent.h,
+ * For converting rpc program numbers to names etc.
+ *
+ */
+
+#ifndef _RPC_RPCENT_H
+#define _RPC_RPCENT_H
+
+#include <rtems/bsd/sys/cdefs.h>
+
+/* #pragma ident "@(#)rpcent.h 1.13 94/04/25 SMI" */
+/* @(#)rpcent.h 1.1 88/12/06 SMI */
+
+
+struct rpcent {
+ char *r_name; /* name of server for this rpc program */
+ char **r_aliases; /* alias list */
+ int r_number; /* rpc program number */
+};
+
+__BEGIN_DECLS
+extern struct rpcent *getrpcbyname_r(const char *, struct rpcent *,
+ char *, int);
+extern struct rpcent *getrpcbynumber_r(int, struct rpcent *, char *, int);
+extern struct rpcent *getrpcent_r(struct rpcent *, char *, int);
+
+/* Old interfaces that return a pointer to a static area; MT-unsafe */
+extern struct rpcent *getrpcbyname(char *);
+extern struct rpcent *getrpcbynumber(int);
+extern struct rpcent *getrpcent(void);
+extern void setrpcent(int);
+extern void endrpcent(void);
+__END_DECLS
+
+#endif /* !_RPC_CENT_H */
diff --git a/cpukit/librpc/include/rpc/svc.h b/cpukit/librpc/include/rpc/svc.h
new file mode 100644
index 0000000000..f7c6ebd0e5
--- /dev/null
+++ b/cpukit/librpc/include/rpc/svc.h
@@ -0,0 +1,289 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)svc.h 1.35 88/12/17 SMI
+ * from: @(#)svc.h 1.27 94/04/25 SMI
+ * $FreeBSD: src/include/rpc/svc.h,v 1.24 2003/06/15 10:32:01 mbr Exp $
+ */
+
+/*
+ * svc.h, Server-side remote procedure call interface.
+ *
+ * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
+ */
+
+#ifndef _RPC_SVC_H
+#define _RPC_SVC_H
+#include <rtems/bsd/sys/cdefs.h>
+
+/*
+ * This interface must manage two items concerning remote procedure calling:
+ *
+ * 1) An arbitrary number of transport connections upon which rpc requests
+ * are received. The two most notable transports are TCP and UDP; they are
+ * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
+ * they in turn call xprt_register and xprt_unregister.
+ *
+ * 2) An arbitrary number of locally registered services. Services are
+ * described by the following four data: program number, version number,
+ * "service dispatch" function, a transport handle, and a boolean that
+ * indicates whether or not the exported program should be registered with a
+ * local binder service; if true the program's number and version and the
+ * port number from the transport handle are registered with the binder.
+ * These data are registered with the rpc svc system via svc_register.
+ *
+ * A service's dispatch function is called whenever an rpc request comes in
+ * on a transport. The request's program and version numbers must match
+ * those of the registered service. The dispatch function is passed two
+ * parameters, struct svc_req * and SVCXPRT *, defined below.
+ */
+
+enum xprt_stat {
+ XPRT_DIED,
+ XPRT_MOREREQS,
+ XPRT_IDLE
+};
+
+struct rpc_msg;
+
+/*
+ * Server side transport handle
+ */
+typedef struct __rpc_svcxprt {
+ int xp_sock;
+ u_short xp_port; /* associated port number */
+ struct xp_ops {
+ /* receive incoming requests */
+ bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
+ /* get transport status */
+ enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
+ /* get arguments */
+ bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
+ caddr_t args_ptr);
+ /* send reply */
+ bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
+ /* free mem allocated for args */
+ bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
+ caddr_t args_ptr);
+ /* destroy this struct */
+ void (*xp_destroy)(struct __rpc_svcxprt *);
+ } *xp_ops;
+ socklen_t xp_addrlen; /* length of remote address */
+ struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */
+ struct opaque_auth xp_verf; /* raw response verifier */
+ void *xp_p1; /* private: for use by svc ops */
+ void *xp_p2; /* private: for use by svc ops */
+} SVCXPRT;
+
+/*
+ * Service request
+ */
+struct svc_req {
+ u_int32_t rq_prog; /* service program number */
+ u_int32_t rq_vers; /* service protocol version */
+ u_int32_t rq_proc; /* the desired procedure */
+ struct opaque_auth rq_cred; /* raw creds from the wire */
+ caddr_t rq_clntcred; /* read only cooked cred */
+ SVCXPRT *rq_xprt; /* associated transport */
+};
+
+
+/*
+ * Operations defined on an SVCXPRT handle
+ *
+ * SVCXPRT *xprt;
+ * struct rpc_msg *msg;
+ * xdrproc_t xargs;
+ * caddr_t argsp;
+ */
+#define SVC_RECV(xprt, msg) \
+ (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
+#define svc_recv(xprt, msg) \
+ (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
+
+#define SVC_STAT(xprt) \
+ (*(xprt)->xp_ops->xp_stat)(xprt)
+#define svc_stat(xprt) \
+ (*(xprt)->xp_ops->xp_stat)(xprt)
+
+#define SVC_GETARGS(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
+#define svc_getargs(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
+
+#define SVC_REPLY(xprt, msg) \
+ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
+#define svc_reply(xprt, msg) \
+ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
+
+#define SVC_FREEARGS(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
+#define svc_freeargs(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
+
+#define SVC_DESTROY(xprt) \
+ (*(xprt)->xp_ops->xp_destroy)(xprt)
+#define svc_destroy(xprt) \
+ (*(xprt)->xp_ops->xp_destroy)(xprt)
+
+/*
+ * Transport registration.
+ *
+ * xprt_register(xprt)
+ * SVCXPRT *xprt;
+ */
+__BEGIN_DECLS
+extern void xprt_register(SVCXPRT *);
+__END_DECLS
+
+/*
+ * Transport un-register
+ *
+ * xprt_unregister(xprt)
+ * SVCXPRT *xprt;
+ */
+__BEGIN_DECLS
+extern void xprt_unregister(SVCXPRT *);
+__END_DECLS
+
+
+/*
+ * When the service routine is called, it must first check to see if it
+ * knows about the procedure; if not, it should call svcerr_noproc
+ * and return. If so, it should deserialize its arguments via
+ * SVC_GETARGS (defined above). If the deserialization does not work,
+ * svcerr_decode should be called followed by a return. Successful
+ * decoding of the arguments should be followed the execution of the
+ * procedure's code and a call to svc_sendreply.
+ *
+ * Also, if the service refuses to execute the procedure due to too-
+ * weak authentication parameters, svcerr_weakauth should be called.
+ * Note: do not confuse access-control failure with weak authentication!
+ *
+ * NB: In pure implementations of rpc, the caller always waits for a reply
+ * msg. This message is sent when svc_sendreply is called.
+ * Therefore pure service implementations should always call
+ * svc_sendreply even if the function logically returns void; use
+ * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
+ * for the abuse of pure rpc via batched calling or pipelining. In the
+ * case of a batched call, svc_sendreply should NOT be called since
+ * this would send a return message, which is what batching tries to avoid.
+ * It is the service/protocol writer's responsibility to know which calls are
+ * batched and which are not. Warning: responding to batch calls may
+ * deadlock the caller and server processes!
+ */
+
+__BEGIN_DECLS
+extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
+extern void svcerr_decode(SVCXPRT *);
+extern void svcerr_weakauth(SVCXPRT *);
+extern void svcerr_noproc(SVCXPRT *);
+extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
+extern void svcerr_auth(SVCXPRT *, enum auth_stat);
+extern void svcerr_noprog(SVCXPRT *);
+extern void svcerr_systemerr(SVCXPRT *);
+__END_DECLS
+
+/*
+ * Lowest level dispatching -OR- who owns this process anyway.
+ * Somebody has to wait for incoming requests and then call the correct
+ * service routine. The routine svc_run does infinite waiting; i.e.,
+ * svc_run never returns.
+ * Since another (co-existant) package may wish to selectively wait for
+ * incoming calls or other events outside of the rpc architecture, the
+ * routine svc_getreq is provided. It must be passed readfds, the
+ * "in-place" results of a select system call (see select, section 2).
+ */
+
+/*
+ * Global keeper of rpc service descriptors in use
+ * dynamic; must be inspected before each call to select
+ */
+extern int svc_maxfd;
+extern fd_set svc_fdset;
+#define svc_fds svc_fdset.fds_bits[0] /* compatibility */
+
+#ifndef _KERNEL
+/*
+ * a small program implemented by the svc_rpc implementation itself;
+ * also see clnt.h for protocol numbers.
+ */
+__BEGIN_DECLS
+extern void rpctest_service(void);
+__END_DECLS
+#endif
+
+__BEGIN_DECLS
+extern void svc_getreq(int);
+extern void svc_getreqset(fd_set *);
+extern void svc_getreqset2(fd_set *, int); /* XXX: nonstd, undoc */
+extern void svc_run(void);
+__END_DECLS
+
+/*
+ * Socket to use on svcxxx_create call to get default socket
+ */
+#define RPC_ANYSOCK -1
+#define RPC_ANYFD RPC_ANYSOCK
+
+/*
+ * These are the existing service side transport implementations
+ */
+
+__BEGIN_DECLS
+/*
+ * Transport independent svc_create routine.
+ */
+
+/*
+ * Connectionless and connectionful create routines
+ */
+
+extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
+/*
+ * const int fd; -- open connection end point
+ * const u_int sendsize; -- max send size
+ * const u_int recvsize; -- max recv size
+ */
+
+/*
+ * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
+ */
+extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
+
+/*
+ * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
+ */
+extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
+__END_DECLS
+
+
+/* for backward compatibility */
+#include <rpc/svc_soc.h>
+
+#endif /* !_RPC_SVC_H */
diff --git a/cpukit/librpc/include/rpc/svc_auth.h b/cpukit/librpc/include/rpc/svc_auth.h
new file mode 100644
index 0000000000..49533803cc
--- /dev/null
+++ b/cpukit/librpc/include/rpc/svc_auth.h
@@ -0,0 +1,56 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)svc_auth.h 1.6 86/07/16 SMI
+ * from: @(#)svc_auth.h 2.1 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/svc_auth.h,v 1.12 1999/08/27 23:45:05 peter Exp $
+ */
+
+/*
+ * svc_auth.h, Service side of rpc authentication.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifndef _RPC_SVCAUTH_H
+#define _RPC_SVCAUTH_H
+
+struct rpc_msg;
+struct svc_req;
+
+/*
+ * Server side authenticator
+ */
+__BEGIN_DECLS
+extern enum auth_stat _authenticate (struct svc_req *, struct rpc_msg *);
+extern int svc_auth_reg (int, enum auth_stat (*)(struct svc_req *,
+ struct rpc_msg *));
+extern enum auth_stat _svcauth_des (struct svc_req *, struct rpc_msg *);
+__END_DECLS
+
+#endif /* !_RPC_SVCAUTH_H */
diff --git a/cpukit/librpc/include/rpc/svc_soc.h b/cpukit/librpc/include/rpc/svc_soc.h
new file mode 100644
index 0000000000..0c4d987673
--- /dev/null
+++ b/cpukit/librpc/include/rpc/svc_soc.h
@@ -0,0 +1,123 @@
+/* $NetBSD: svc_soc.h,v 1.1 2000/06/02 22:57:57 fvdl Exp $ */
+/* $FreeBSD: src/include/rpc/svc_soc.h,v 1.2 2002/03/23 17:24:55 imp Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+/*
+ * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
+ */
+
+/*
+ * svc.h, Server-side remote procedure call interface.
+ */
+
+#ifndef _RPC_SVC_SOC_H
+#define _RPC_SVC_SOC_H
+#include <rtems/bsd/sys/cdefs.h>
+
+/* #pragma ident "@(#)svc_soc.h 1.11 94/04/25 SMI" */
+/* svc_soc.h 1.8 89/05/01 SMI */
+
+/*
+ * All the following declarations are only for backward compatibility
+ * with TS-RPC
+ */
+
+/*
+ * Approved way of getting address of caller
+ */
+#define svc_getcaller(x) (&(x)->xp_raddr)
+
+/*
+ * Service registration
+ *
+ * svc_register(xprt, prog, vers, dispatch, protocol)
+ * SVCXPRT *xprt;
+ * u_long prog;
+ * u_long vers;
+ * void (*dispatch)();
+ * int protocol; like TCP or UDP, zero means do not register
+ */
+__BEGIN_DECLS
+extern bool_t svc_register(SVCXPRT *, u_long, u_long,
+ void (*)(struct svc_req *, SVCXPRT *), int);
+__END_DECLS
+
+/*
+ * Service un-registration
+ *
+ * svc_unregister(prog, vers)
+ * u_long prog;
+ * u_long vers;
+ */
+__BEGIN_DECLS
+extern void svc_unregister(u_long, u_long);
+__END_DECLS
+
+
+/*
+ * Memory based rpc for testing and timing.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcraw_create(void);
+__END_DECLS
+
+
+/*
+ * Udp based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcudp_create(int);
+extern SVCXPRT *svcudp_bufcreate(int, u_int, u_int);
+__END_DECLS
+
+
+/*
+ * Tcp based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svctcp_create(int, u_int, u_int);
+__END_DECLS
+
+/*
+ * Fd based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcfd_create(int, u_int, u_int);
+__END_DECLS
+
+/*
+ * AF_UNIX socket based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcunix_create (int, u_int, u_int, char *);
+extern SVCXPRT *svcunixfd_create (int, u_int, u_int);
+__END_DECLS
+
+#endif /* !_RPC_SVC_SOC_H */
diff --git a/cpukit/librpc/include/rpc/types.h b/cpukit/librpc/include/rpc/types.h
new file mode 100644
index 0000000000..05375d32e9
--- /dev/null
+++ b/cpukit/librpc/include/rpc/types.h
@@ -0,0 +1,68 @@
+/* $NetBSD: types.h,v 1.13 2000/06/13 01:02:44 thorpej Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)types.h 1.18 87/07/24 SMI
+ * from: @(#)types.h 2.3 88/08/15 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/types.h,v 1.11 2003/12/07 21:10:06 marcel Exp $
+ */
+
+/*
+ * Rpc additions to <sys/types.h>
+ */
+#ifndef _RPC_TYPES_H
+#define _RPC_TYPES_H
+
+#include <stdint.h>
+
+typedef int32_t bool_t;
+typedef int32_t enum_t;
+
+typedef uint32_t rpcprog_t;
+typedef uint32_t rpcvers_t;
+typedef uint32_t rpcproc_t;
+typedef uint32_t rpcprot_t;
+typedef uint32_t rpcport_t;
+typedef int32_t rpc_inline_t;
+
+#define __dontcare__ -1
+
+#ifndef FALSE
+# define FALSE (0)
+#endif
+#ifndef TRUE
+# define TRUE (1)
+#endif
+
+#define mem_alloc(bsize) malloc(bsize)
+#define mem_free(ptr, bsize) free(ptr)
+
+#include <sys/time.h>
+
+#endif /* !_RPC_TYPES_H */
diff --git a/cpukit/librpc/include/rpc/xdr.h b/cpukit/librpc/include/rpc/xdr.h
new file mode 100644
index 0000000000..e5c04974d4
--- /dev/null
+++ b/cpukit/librpc/include/rpc/xdr.h
@@ -0,0 +1,312 @@
+/* $NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * from: @(#)xdr.h 1.19 87/04/22 SMI
+ * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC
+ * $FreeBSD: src/include/rpc/xdr.h,v 1.23 2003/03/07 13:19:40 nectar Exp $
+ */
+
+/*
+ * xdr.h, External Data Representation Serialization Routines.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifndef _RPC_XDR_H
+#define _RPC_XDR_H
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#include <rpc/types.h>
+
+/*
+ * XDR provides a conventional way for converting between C data
+ * types and an external bit-string representation. Library supplied
+ * routines provide for the conversion on built-in C data types. These
+ * routines and utility routines defined here are used to help implement
+ * a type encode/decode routine for each user-defined type.
+ *
+ * Each data type provides a single procedure which takes two arguments:
+ *
+ * bool_t
+ * xdrproc(xdrs, argresp)
+ * XDR *xdrs;
+ * <type> *argresp;
+ *
+ * xdrs is an instance of a XDR handle, to which or from which the data
+ * type is to be converted. argresp is a pointer to the structure to be
+ * converted. The XDR handle contains an operation field which indicates
+ * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
+ *
+ * XDR_DECODE may allocate space if the pointer argresp is null. This
+ * data can be freed with the XDR_FREE operation.
+ *
+ * We write only one procedure per data type to make it easy
+ * to keep the encode and decode procedures for a data type consistent.
+ * In many cases the same code performs all operations on a user defined type,
+ * because all the hard work is done in the component type routines.
+ * decode as a series of calls on the nested data types.
+ */
+
+/*
+ * Xdr operations. XDR_ENCODE causes the type to be encoded into the
+ * stream. XDR_DECODE causes the type to be extracted from the stream.
+ * XDR_FREE can be used to release the space allocated by an XDR_DECODE
+ * request.
+ */
+enum xdr_op {
+ XDR_ENCODE=0,
+ XDR_DECODE=1,
+ XDR_FREE=2
+};
+
+/*
+ * This is the number of bytes per unit of external data.
+ */
+#define BYTES_PER_XDR_UNIT (4)
+#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
+ * BYTES_PER_XDR_UNIT)
+
+/*
+ * The XDR handle.
+ * Contains operation which is being applied to the stream,
+ * an operations vector for the particular implementation (e.g. see xdr_mem.c),
+ * and two private fields for the use of the particular implementation.
+ */
+typedef struct __rpc_xdr {
+ enum xdr_op x_op; /* operation; fast additional param */
+ const struct xdr_ops {
+ /* get a long from underlying stream */
+ bool_t (*x_getlong)(struct __rpc_xdr *, long *);
+ /* put a long to " */
+ bool_t (*x_putlong)(struct __rpc_xdr *, const long *);
+ /* get some bytes from " */
+ bool_t (*x_getbytes)(struct __rpc_xdr *, char *, u_int);
+ /* put some bytes to " */
+ bool_t (*x_putbytes)(struct __rpc_xdr *, const char *, u_int);
+ /* returns bytes off from beginning */
+ u_int (*x_getpostn)(struct __rpc_xdr *);
+ /* lets you reposition the stream */
+ bool_t (*x_setpostn)(struct __rpc_xdr *, u_int);
+ /* buf quick ptr to buffered data */
+ int32_t *(*x_inline)(struct __rpc_xdr *, u_int);
+ /* free privates of this xdr_stream */
+ void (*x_destroy)(struct __rpc_xdr *);
+ } *x_ops;
+ char * x_public; /* users' data */
+ void * x_private; /* pointer to private data */
+ char * x_base; /* private used for position info */
+ u_int x_handy; /* extra private word */
+} XDR;
+
+/*
+ * A xdrproc_t exists for each data type which is to be encoded or decoded.
+ *
+ * The second argument to the xdrproc_t is a pointer to an opaque pointer.
+ * The opaque pointer generally points to a structure of the data type
+ * to be decoded. If this pointer is 0, then the type routines should
+ * allocate dynamic storage of the appropriate size and return it.
+ */
+typedef bool_t (*xdrproc_t) (XDR *, void *, ...);
+
+/*
+ * Operations defined on a XDR handle
+ *
+ * XDR *xdrs;
+ * long *longp;
+ * caddr_t addr;
+ * u_int len;
+ * u_int pos;
+ */
+#define XDR_GETLONG(xdrs, longp) \
+ (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
+#define xdr_getlong(xdrs, longp) \
+ (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
+
+#define XDR_PUTLONG(xdrs, longp) \
+ (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
+#define xdr_putlong(xdrs, longp) \
+ (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
+
+#define XDR_GETBYTES(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
+#define xdr_getbytes(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
+
+#define XDR_PUTBYTES(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
+#define xdr_putbytes(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
+
+#define XDR_GETPOS(xdrs) \
+ (*(xdrs)->x_ops->x_getpostn)(xdrs)
+#define xdr_getpos(xdrs) \
+ (*(xdrs)->x_ops->x_getpostn)(xdrs)
+
+#define XDR_SETPOS(xdrs, pos) \
+ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
+#define xdr_setpos(xdrs, pos) \
+ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
+
+#define XDR_INLINE(xdrs, len) \
+ (*(xdrs)->x_ops->x_inline)(xdrs, len)
+#define xdr_inline(xdrs, len) \
+ (*(xdrs)->x_ops->x_inline)(xdrs, len)
+
+#define XDR_DESTROY(xdrs) \
+ if ((xdrs)->x_ops->x_destroy) \
+ (*(xdrs)->x_ops->x_destroy)(xdrs)
+#define xdr_destroy(xdrs) \
+ if ((xdrs)->x_ops->x_destroy) \
+ (*(xdrs)->x_ops->x_destroy)(xdrs)
+
+/*
+ * Support struct for discriminated unions.
+ * You create an array of xdrdiscrim structures, terminated with
+ * an entry with a null procedure pointer. The xdr_union routine gets
+ * the discriminant value and then searches the array of structures
+ * for a matching value. If a match is found the associated xdr routine
+ * is called to handle that part of the union. If there is
+ * no match, then a default routine may be called.
+ * If there is no match and no default routine it is an error.
+ */
+#define NULL_xdrproc_t ((xdrproc_t)0)
+struct xdr_discrim {
+ int value;
+ xdrproc_t proc;
+};
+
+/*
+ * In-line routines for fast encode/decode of primitive data types.
+ * Caveat emptor: these use single memory cycles to get the
+ * data from the underlying buffer, and will fail to operate
+ * properly if the data is not aligned. The standard way to use these
+ * is to say:
+ * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
+ * return (FALSE);
+ * <<< macro calls >>>
+ * where ``count'' is the number of bytes of data occupied
+ * by the primitive data types.
+ *
+ * N.B. and frozen for all time: each data type here uses 4 bytes
+ * of external representation.
+ */
+#define IXDR_GET_LONG(buf) ((long)ntohl((u_long)*(buf)++))
+#define IXDR_PUT_LONG(buf, v) (*(buf)++ = (long)htonl((u_long)v))
+
+#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
+#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
+#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf))
+#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
+#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf))
+
+#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+
+/*
+ * These are the "generic" xdr routines.
+ */
+__BEGIN_DECLS
+extern bool_t xdr_void(void);
+extern bool_t xdr_int(XDR *, int *);
+extern bool_t xdr_u_int(XDR *, u_int *);
+extern bool_t xdr_long(XDR *, long *);
+extern bool_t xdr_u_long(XDR *, u_long *);
+extern bool_t xdr_short(XDR *, short *);
+extern bool_t xdr_u_short(XDR *, u_short *);
+extern bool_t xdr_int16_t(XDR *, int16_t *);
+extern bool_t xdr_u_int16_t(XDR *, u_int16_t *);
+extern bool_t xdr_int32_t(XDR *, int32_t *);
+extern bool_t xdr_u_int32_t(XDR *, u_int32_t *);
+extern bool_t xdr_int64_t(XDR *, int64_t *);
+extern bool_t xdr_u_int64_t(XDR *, u_int64_t *);
+extern bool_t xdr_bool(XDR *, bool_t *);
+extern bool_t xdr_enum(XDR *, enum_t *);
+extern bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t);
+extern bool_t xdr_bytes(XDR *, char **, u_int *, u_int);
+extern bool_t xdr_opaque(XDR *, caddr_t, u_int);
+extern bool_t xdr_string(XDR *, char **, u_int);
+extern bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t);
+extern unsigned long xdr_sizeof (xdrproc_t, void *);
+extern bool_t xdr_char(XDR *, char *);
+extern bool_t xdr_u_char(XDR *, u_char *);
+extern bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t);
+extern bool_t xdr_float(XDR *, float *);
+extern bool_t xdr_double(XDR *, double *);
+extern bool_t xdr_reference(XDR *, caddr_t *, u_int, xdrproc_t);
+extern bool_t xdr_pointer(XDR *, caddr_t *, u_int, xdrproc_t);
+extern bool_t xdr_wrapstring(XDR *, char **);
+extern void xdr_free(xdrproc_t, char *);
+__END_DECLS
+
+/*
+ * Common opaque bytes objects used by many rpc protocols;
+ * declared here due to commonality.
+ */
+#define MAX_NETOBJ_SZ 1024
+struct netobj {
+ u_int n_len;
+ char *n_bytes;
+};
+typedef struct netobj netobj;
+extern bool_t xdr_netobj(XDR *, struct netobj *);
+
+/*
+ * These are the public routines for the various implementations of
+ * xdr streams.
+ */
+__BEGIN_DECLS
+/* XDR using memory buffers */
+extern void xdrmem_create(XDR *, char *, u_int, enum xdr_op);
+
+/* XDR using stdio library */
+#ifdef _STDIO_H_
+extern void xdrstdio_create(XDR *, FILE *, enum xdr_op);
+#endif
+
+/* XDR pseudo records for tcp */
+extern void xdrrec_create(XDR *, u_int, u_int, char *,
+ int (*) (caddr_t, caddr_t, int),
+ int (*) (caddr_t, caddr_t, int));
+
+/* make end of xdr record */
+extern bool_t xdrrec_endofrecord(XDR *, bool_t);
+
+/* move to beginning of next record */
+extern bool_t xdrrec_skiprecord(XDR *);
+
+/* true if no more input */
+extern bool_t xdrrec_eof(XDR *);
+__END_DECLS
+
+#endif /* !_RPC_XDR_H */
diff --git a/cpukit/librpc/include/rpcsvc/bootparam_prot.x b/cpukit/librpc/include/rpcsvc/bootparam_prot.x
new file mode 100644
index 0000000000..0f74c8f8ad
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/bootparam_prot.x
@@ -0,0 +1,103 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * RPC for bootparms service.
+ * There are two procedures:
+ * WHOAMI takes a net address and returns a client name and also a
+ * likely net address for routing
+ * GETFILE takes a client name and file identifier and returns the
+ * server name, server net address and pathname for the file.
+ * file identifiers typically include root, swap, pub and dump
+ */
+
+#ifdef RPC_HDR
+%#include <rpc/types.h>
+%#include <sys/time.h>
+%#include <sys/errno.h>
+%#include <sys/param.h>
+%#include <sys/syslimits.h>
+%#include <sys/ucred.h>
+#else
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)bootparam_prot.x 1.2 87/06/24 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)bootparam_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/bootparam_prot.x,v 1.5 1999/08/27 23:45:07 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const MAX_MACHINE_NAME = 255;
+const MAX_PATH_LEN = 1024;
+const MAX_FILEID = 32;
+const IP_ADDR_TYPE = 1;
+
+typedef string bp_machine_name_t<MAX_MACHINE_NAME>;
+typedef string bp_path_t<MAX_PATH_LEN>;
+typedef string bp_fileid_t<MAX_FILEID>;
+
+struct ip_addr_t {
+ char net;
+ char host;
+ char lh;
+ char impno;
+};
+
+union bp_address switch (int address_type) {
+ case IP_ADDR_TYPE:
+ ip_addr_t ip_addr;
+};
+
+struct bp_whoami_arg {
+ bp_address client_address;
+};
+
+struct bp_whoami_res {
+ bp_machine_name_t client_name;
+ bp_machine_name_t domain_name;
+ bp_address router_address;
+};
+
+struct bp_getfile_arg {
+ bp_machine_name_t client_name;
+ bp_fileid_t file_id;
+};
+
+struct bp_getfile_res {
+ bp_machine_name_t server_name;
+ bp_address server_address;
+ bp_path_t server_path;
+};
+
+program BOOTPARAMPROG {
+ version BOOTPARAMVERS {
+ bp_whoami_res BOOTPARAMPROC_WHOAMI(bp_whoami_arg) = 1;
+ bp_getfile_res BOOTPARAMPROC_GETFILE(bp_getfile_arg) = 2;
+ } = 1;
+} = 100026;
diff --git a/cpukit/librpc/include/rpcsvc/crypt.x b/cpukit/librpc/include/rpcsvc/crypt.x
new file mode 100644
index 0000000000..8df1654440
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/crypt.x
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 1996
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/include/rpcsvc/crypt.x,v 1.3 1999/08/27 23:45:08 peter Exp $
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/crypt.x,v 1.3 1999/08/27 23:45:08 peter Exp $";
+%#endif
+#endif
+
+/*
+ * This protocol definition exists because of the U.S. government and
+ * its stupid export laws. We can't export DES code from the United
+ * States to other countries (even though the code already exists
+ * outside the U.S. -- go figure that one out) but we need to make
+ * Secure RPC work. The normal way around this is to break the DES
+ * code out into a shared library; we can then provide a dummy lib
+ * in the base OS and provide the real lib in the secure dist, which
+ * the user can install later. But we need Secure RPC for NIS+, and
+ * there are several system programs that use NIS+ which are statically
+ * linked. We would have to provide replacements for these programs
+ * in the secure dist, but there are a lot, and this is a pain. The
+ * shared lib trick won't work for these programs, and we can't change
+ * them once they're compiled.
+ *
+ * One solution for this problem is to do the DES encryption as a system
+ * call; no programs need to be changed and we can even supply the DES
+ * support as an LKM. But this bloats the kernel. Maybe if we have
+ * Secure NFS one day this will be worth it, but for now we should keep
+ * this mess in user space.
+ *
+ * So we have this second solution: we provide a server that does the
+ * DES encryption for us. In this case, the server is keyserv (we need
+ * it to make Secure RPC work anyway) and we use this protocol to ship
+ * the data back and forth between keyserv and the application.
+ */
+
+enum des_dir { ENCRYPT_DES, DECRYPT_DES };
+enum des_mode { CBC_DES, ECB_DES };
+
+struct desargs {
+ u_char des_key[8]; /* key (with low bit parity) */
+ des_dir des_dir; /* direction */
+ des_mode des_mode; /* mode */
+ u_char des_ivec[8]; /* input vector */
+ opaque desbuf<>;
+};
+
+struct desresp {
+ opaque desbuf<>;
+ u_char des_ivec[8];
+ int stat;
+};
+
+program CRYPT_PROG {
+ version CRYPT_VERS {
+ desresp
+ DES_CRYPT(desargs) = 1;
+ } = 1;
+} = 600100029;
diff --git a/cpukit/librpc/include/rpcsvc/key_prot.x b/cpukit/librpc/include/rpcsvc/key_prot.x
new file mode 100644
index 0000000000..f545569e01
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/key_prot.x
@@ -0,0 +1,282 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+/*
+ * Key server protocol definition
+ * Copyright (C) 1990, 1991 Sun Microsystems, Inc.
+ *
+ * The keyserver is a public key storage/encryption/decryption service
+ * The encryption method used is based on the Diffie-Hellman exponential
+ * key exchange technology.
+ *
+ * The key server is local to each machine, akin to the portmapper.
+ * Under TI-RPC, communication with the keyserver is through the
+ * loopback transport.
+ *
+ * NOTE: This .x file generates the USER level headers for the keyserver.
+ * the KERNEL level headers are created by hand as they kernel has special
+ * requirements.
+ */
+
+%/* From: #pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI" */
+%
+%/* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */
+%
+%/*
+% * Compiled from key_prot.x using rpcgen.
+% * DO NOT EDIT THIS FILE!
+% * This is NOT source code!
+% */
+
+/*
+ * PROOT and MODULUS define the way the Diffie-Hellman key is generated.
+ *
+ * MODULUS should be chosen as a prime of the form: MODULUS == 2*p + 1,
+ * where p is also prime.
+ *
+ * PROOT satisfies the following two conditions:
+ * (1) (PROOT ** 2) % MODULUS != 1
+ * (2) (PROOT ** p) % MODULUS != 1
+ *
+ */
+
+const PROOT = 3;
+const HEXMODULUS = "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b";
+
+const HEXKEYBYTES = 48; /* HEXKEYBYTES == strlen(HEXMODULUS) */
+const KEYSIZE = 192; /* KEYSIZE == bit length of key */
+const KEYBYTES = 24; /* byte length of key */
+
+/*
+ * The first 16 hex digits of the encrypted secret key are used as
+ * a checksum in the database.
+ */
+const KEYCHECKSUMSIZE = 16;
+
+/*
+ * status of operation
+ */
+enum keystatus {
+ KEY_SUCCESS, /* no problems */
+ KEY_NOSECRET, /* no secret key stored */
+ KEY_UNKNOWN, /* unknown netname */
+ KEY_SYSTEMERR /* system error (out of memory, encryption failure) */
+};
+
+typedef opaque keybuf[HEXKEYBYTES]; /* store key in hex */
+
+typedef string netnamestr<MAXNETNAMELEN>;
+
+/*
+ * Argument to ENCRYPT or DECRYPT
+ */
+struct cryptkeyarg {
+ netnamestr remotename;
+ des_block deskey;
+};
+
+/*
+ * Argument to ENCRYPT_PK or DECRYPT_PK
+ */
+struct cryptkeyarg2 {
+ netnamestr remotename;
+ netobj remotekey; /* Contains a length up to 1024 bytes */
+ des_block deskey;
+};
+
+
+/*
+ * Result of ENCRYPT, DECRYPT, ENCRYPT_PK, and DECRYPT_PK
+ */
+union cryptkeyres switch (keystatus status) {
+case KEY_SUCCESS:
+ des_block deskey;
+default:
+ void;
+};
+
+const MAXGIDS = 16; /* max number of gids in gid list */
+
+/*
+ * Unix credential
+ */
+struct unixcred {
+ u_int uid;
+ u_int gid;
+ u_int gids<MAXGIDS>;
+};
+
+/*
+ * Result returned from GETCRED
+ */
+union getcredres switch (keystatus status) {
+case KEY_SUCCESS:
+ unixcred cred;
+default:
+ void;
+};
+/*
+ * key_netstarg;
+ */
+
+struct key_netstarg {
+ keybuf st_priv_key;
+ keybuf st_pub_key;
+ netnamestr st_netname;
+};
+
+union key_netstres switch (keystatus status){
+case KEY_SUCCESS:
+ key_netstarg knet;
+default:
+ void;
+};
+
+#ifdef RPC_HDR
+%
+%#ifndef opaque
+%#define opaque char
+%#endif
+%
+#endif
+program KEY_PROG {
+ version KEY_VERS {
+
+ /*
+ * This is my secret key.
+ * Store it for me.
+ */
+ keystatus
+ KEY_SET(keybuf) = 1;
+
+ /*
+ * I want to talk to X.
+ * Encrypt a conversation key for me.
+ */
+ cryptkeyres
+ KEY_ENCRYPT(cryptkeyarg) = 2;
+
+ /*
+ * X just sent me a message.
+ * Decrypt the conversation key for me.
+ */
+ cryptkeyres
+ KEY_DECRYPT(cryptkeyarg) = 3;
+
+ /*
+ * Generate a secure conversation key for me
+ */
+ des_block
+ KEY_GEN(void) = 4;
+
+ /*
+ * Get me the uid, gid and group-access-list associated
+ * with this netname (for kernel which cannot use NIS)
+ */
+ getcredres
+ KEY_GETCRED(netnamestr) = 5;
+ } = 1;
+ version KEY_VERS2 {
+
+ /*
+ * #######
+ * Procedures 1-5 are identical to version 1
+ * #######
+ */
+
+ /*
+ * This is my secret key.
+ * Store it for me.
+ */
+ keystatus
+ KEY_SET(keybuf) = 1;
+
+ /*
+ * I want to talk to X.
+ * Encrypt a conversation key for me.
+ */
+ cryptkeyres
+ KEY_ENCRYPT(cryptkeyarg) = 2;
+
+ /*
+ * X just sent me a message.
+ * Decrypt the conversation key for me.
+ */
+ cryptkeyres
+ KEY_DECRYPT(cryptkeyarg) = 3;
+
+ /*
+ * Generate a secure conversation key for me
+ */
+ des_block
+ KEY_GEN(void) = 4;
+
+ /*
+ * Get me the uid, gid and group-access-list associated
+ * with this netname (for kernel which cannot use NIS)
+ */
+ getcredres
+ KEY_GETCRED(netnamestr) = 5;
+
+ /*
+ * I want to talk to X. and I know X's public key
+ * Encrypt a conversation key for me.
+ */
+ cryptkeyres
+ KEY_ENCRYPT_PK(cryptkeyarg2) = 6;
+
+ /*
+ * X just sent me a message. and I know X's public key
+ * Decrypt the conversation key for me.
+ */
+ cryptkeyres
+ KEY_DECRYPT_PK(cryptkeyarg2) = 7;
+
+ /*
+ * Store my public key, netname and private key.
+ */
+ keystatus
+ KEY_NET_PUT(key_netstarg) = 8;
+
+ /*
+ * Retrieve my public key, netname and private key.
+ */
+ key_netstres
+ KEY_NET_GET(void) = 9;
+
+ /*
+ * Return me the conversation key that is constructed
+ * from my secret key and this publickey.
+ */
+
+ cryptkeyres
+ KEY_GET_CONV(keybuf) = 10;
+
+
+ } = 2;
+} = 100029;
diff --git a/cpukit/librpc/include/rpcsvc/klm_prot.x b/cpukit/librpc/include/rpcsvc/klm_prot.x
new file mode 100644
index 0000000000..c4cfe36d42
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/klm_prot.x
@@ -0,0 +1,139 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Kernel/lock manager protocol definition
+ * Copyright (C) 1986 Sun Microsystems, Inc.
+ *
+ * protocol used between the UNIX kernel (the "client") and the
+ * local lock manager. The local lock manager is a deamon running
+ * above the kernel.
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)klm_prot.x 1.7 87/07/08 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)klm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/klm_prot.x,v 1.6 1999/08/27 23:45:08 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const LM_MAXSTRLEN = 1024;
+
+/*
+ * lock manager status returns
+ */
+enum klm_stats {
+ klm_granted = 0, /* lock is granted */
+ klm_denied = 1, /* lock is denied */
+ klm_denied_nolocks = 2, /* no lock entry available */
+ klm_working = 3 /* lock is being processed */
+};
+
+/*
+ * lock manager lock identifier
+ */
+struct klm_lock {
+ string server_name<LM_MAXSTRLEN>;
+ netobj fh; /* a counted file handle */
+ int pid; /* holder of the lock */
+ unsigned l_offset; /* beginning offset of the lock */
+ unsigned l_len; /* byte length of the lock;
+ * zero means through end of file */
+};
+
+/*
+ * lock holder identifier
+ */
+struct klm_holder {
+ bool exclusive; /* FALSE if shared lock */
+ int svid; /* holder of the lock (pid) */
+ unsigned l_offset; /* beginning offset of the lock */
+ unsigned l_len; /* byte length of the lock;
+ * zero means through end of file */
+};
+
+/*
+ * reply to KLM_LOCK / KLM_UNLOCK / KLM_CANCEL
+ */
+struct klm_stat {
+ klm_stats stat;
+};
+
+/*
+ * reply to a KLM_TEST call
+ */
+union klm_testrply switch (klm_stats stat) {
+ case klm_denied:
+ struct klm_holder holder;
+ default: /* All other cases return no arguments */
+ void;
+};
+
+
+/*
+ * arguments to KLM_LOCK
+ */
+struct klm_lockargs {
+ bool block;
+ bool exclusive;
+ struct klm_lock alock;
+};
+
+/*
+ * arguments to KLM_TEST
+ */
+struct klm_testargs {
+ bool exclusive;
+ struct klm_lock alock;
+};
+
+/*
+ * arguments to KLM_UNLOCK
+ */
+struct klm_unlockargs {
+ struct klm_lock alock;
+};
+
+program KLM_PROG {
+ version KLM_VERS {
+
+ klm_testrply KLM_TEST (struct klm_testargs) = 1;
+
+ klm_stat KLM_LOCK (struct klm_lockargs) = 2;
+
+ klm_stat KLM_CANCEL (struct klm_lockargs) = 3;
+ /* klm_granted=> the cancel request fails due to lock is already granted */
+ /* klm_denied=> the cancel request successfully aborts
+lock request */
+
+ klm_stat KLM_UNLOCK (struct klm_unlockargs) = 4;
+ } = 1;
+} = 100020;
diff --git a/cpukit/librpc/include/rpcsvc/mount.x b/cpukit/librpc/include/rpcsvc/mount.x
new file mode 100644
index 0000000000..f68a06fe9b
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/mount.x
@@ -0,0 +1,257 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Protocol description for the mount program
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)mount.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)mount.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/mount.x,v 1.6 1999/08/27 23:45:08 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const MNTPATHLEN = 1024; /* maximum bytes in a pathname argument */
+const MNTNAMLEN = 255; /* maximum bytes in a name argument */
+const FHSIZE = 32; /* size in bytes of a file handle */
+#ifdef WANT_NFS3
+const FHSIZE3 = 64; /* size in bytes of a file handle (v3) */
+#endif
+
+/*
+ * The fhandle is the file handle that the server passes to the client.
+ * All file operations are done using the file handles to refer to a file
+ * or a directory. The file handle can contain whatever information the
+ * server needs to distinguish an individual file.
+ */
+typedef opaque fhandle[FHSIZE];
+#ifdef WANT_NFS3
+typedef opaque fhandle3<FHSIZE3>;
+#endif
+
+/*
+ * If a status of zero is returned, the call completed successfully, and
+ * a file handle for the directory follows. A non-zero status indicates
+ * some sort of error. The status corresponds with UNIX error numbers.
+ */
+union fhstatus switch (unsigned fhs_status) {
+case 0:
+ fhandle fhs_fhandle;
+default:
+ void;
+};
+
+#ifdef WANT_NFS3
+/*
+ * Status codes returned by the version 3 mount call.
+ */
+enum mountstat3 {
+ MNT3_OK = 0, /* no error */
+ MNT3ERR_PERM = 1, /* Not owner */
+ MNT3ERR_NOENT = 2, /* No such file or directory */
+ MNT3ERR_IO = 5, /* I/O error */
+ MNT3ERR_ACCES = 13, /* Permission denied */
+ MNT3ERR_NOTDIR = 20, /* Not a directory */
+ MNT3ERR_INVAL = 22, /* Invalid argument */
+ MNT3ERR_NAMETOOLONG = 63, /* Filename too long */
+ MNT3ERR_NOTSUPP = 10004, /* Operation not supported */
+ MNT3ERR_SERVERFAULT = 10006 /* A failure on the server */
+};
+
+struct mountres3_ok {
+ fhandle3 fhandle;
+ int auth_flavors<>;
+};
+
+union mountres3 switch (mountstat3 fhs_status) {
+case 0:
+ mountres3_ok mountinfo;
+default:
+ void;
+};
+#endif
+
+/*
+ * The type dirpath is the pathname of a directory
+ */
+typedef string dirpath<MNTPATHLEN>;
+
+/*
+ * The type name is used for arbitrary names (hostnames, groupnames)
+ */
+typedef string name<MNTNAMLEN>;
+
+/*
+ * A list of who has what mounted
+ */
+typedef struct mountbody *mountlist;
+struct mountbody {
+ name ml_hostname;
+ dirpath ml_directory;
+ mountlist ml_next;
+};
+
+/*
+ * A list of netgroups
+ */
+typedef struct groupnode *groups;
+struct groupnode {
+ name gr_name;
+ groups gr_next;
+};
+
+/*
+ * A list of what is exported and to whom
+ */
+typedef struct exportnode *exports;
+struct exportnode {
+ dirpath ex_dir;
+ groups ex_groups;
+ exports ex_next;
+};
+
+program MOUNTPROG {
+ /*
+ * Version one of the mount protocol communicates with version two
+ * of the NFS protocol. Version three communicates with
+ * version three of the NFS protocol. The only connecting
+ * point is the fhandle structure, which is the same for both
+ * protocols.
+ */
+ version MOUNTVERS {
+ /*
+ * Does no work. It is made available in all RPC services
+ * to allow server reponse testing and timing
+ */
+ void
+ MOUNTPROC_NULL(void) = 0;
+
+ /*
+ * If fhs_status is 0, then fhs_fhandle contains the
+ * file handle for the directory. This file handle may
+ * be used in the NFS protocol. This procedure also adds
+ * a new entry to the mount list for this client mounting
+ * the directory.
+ * Unix authentication required.
+ */
+ fhstatus
+ MOUNTPROC_MNT(dirpath) = 1;
+
+ /*
+ * Returns the list of remotely mounted filesystems. The
+ * mountlist contains one entry for each hostname and
+ * directory pair.
+ */
+ mountlist
+ MOUNTPROC_DUMP(void) = 2;
+
+ /*
+ * Removes the mount list entry for the directory
+ * Unix authentication required.
+ */
+ void
+ MOUNTPROC_UMNT(dirpath) = 3;
+
+ /*
+ * Removes all of the mount list entries for this client
+ * Unix authentication required.
+ */
+ void
+ MOUNTPROC_UMNTALL(void) = 4;
+
+ /*
+ * Returns a list of all the exported filesystems, and which
+ * machines are allowed to import it.
+ */
+ exports
+ MOUNTPROC_EXPORT(void) = 5;
+
+ /*
+ * Identical to MOUNTPROC_EXPORT above
+ */
+ exports
+ MOUNTPROC_EXPORTALL(void) = 6;
+ } = 1;
+#ifdef WANT_NFS3
+ version MOUNTVERS3 {
+ /*
+ * Does no work. It is made available in all RPC services
+ * to allow server reponse testing and timing
+ */
+ void
+ MOUNTPROC_NULL(void) = 0;
+
+ /*
+ * If mountres3.fhs_status is MNT3_OK, then
+ * mountres3.mountinfo contains the file handle for
+ * the directory and a list of acceptable
+ * authentication flavors. This file handle may only
+ * be used in the NFS version 3 protocol. This
+ * procedure also results in the server adding a new
+ * entry to its mount list recording that this client
+ * has mounted the directory. AUTH_UNIX authentication
+ * or better is required.
+ */
+ mountres3
+ MOUNTPROC_MNT(dirpath) = 1;
+
+ /*
+ * Returns the list of remotely mounted filesystems. The
+ * mountlist contains one entry for each hostname and
+ * directory pair.
+ */
+ mountlist
+ MOUNTPROC_DUMP(void) = 2;
+
+ /*
+ * Removes the mount list entry for the directory
+ * Unix authentication required.
+ */
+ void
+ MOUNTPROC_UMNT(dirpath) = 3;
+
+ /*
+ * Removes all of the mount list entries for this client
+ * Unix authentication required.
+ */
+ void
+ MOUNTPROC_UMNTALL(void) = 4;
+
+ /*
+ * Returns a list of all the exported filesystems, and which
+ * machines are allowed to import it.
+ */
+ exports
+ MOUNTPROC_EXPORT(void) = 5;
+ } = 3;
+#endif
+} = 100005;
diff --git a/cpukit/librpc/include/rpcsvc/nfs_prot.x b/cpukit/librpc/include/rpcsvc/nfs_prot.x
new file mode 100644
index 0000000000..c1e592c1a1
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nfs_prot.x
@@ -0,0 +1,1265 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)nfs_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/nfs_prot.x,v 1.7 1999/08/27 23:45:08 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const NFS_PORT = 2049;
+const NFS_MAXDATA = 8192;
+const NFS_MAXPATHLEN = 1024;
+const NFS_MAXNAMLEN = 255;
+const NFS_FHSIZE = 32;
+const NFS_COOKIESIZE = 4;
+const NFS_FIFO_DEV = -1; /* size kludge for named pipes */
+
+/*
+ * File types
+ */
+const NFSMODE_FMT = 0170000; /* type of file */
+const NFSMODE_DIR = 0040000; /* directory */
+const NFSMODE_CHR = 0020000; /* character special */
+const NFSMODE_BLK = 0060000; /* block special */
+const NFSMODE_REG = 0100000; /* regular */
+const NFSMODE_LNK = 0120000; /* symbolic link */
+const NFSMODE_SOCK = 0140000; /* socket */
+const NFSMODE_FIFO = 0010000; /* fifo */
+
+/*
+ * Error status
+ */
+enum nfsstat {
+ NFS_OK= 0, /* no error */
+ NFSERR_PERM=1, /* Not owner */
+ NFSERR_NOENT=2, /* No such file or directory */
+ NFSERR_IO=5, /* I/O error */
+ NFSERR_NXIO=6, /* No such device or address */
+ NFSERR_ACCES=13, /* Permission denied */
+ NFSERR_EXIST=17, /* File exists */
+ NFSERR_NODEV=19, /* No such device */
+ NFSERR_NOTDIR=20, /* Not a directory*/
+ NFSERR_ISDIR=21, /* Is a directory */
+ NFSERR_FBIG=27, /* File too large */
+ NFSERR_NOSPC=28, /* No space left on device */
+ NFSERR_ROFS=30, /* Read-only file system */
+ NFSERR_NAMETOOLONG=63, /* File name too long */
+ NFSERR_NOTEMPTY=66, /* Directory not empty */
+ NFSERR_DQUOT=69, /* Disc quota exceeded */
+ NFSERR_STALE=70, /* Stale NFS file handle */
+ NFSERR_WFLUSH=99 /* write cache flushed */
+};
+
+/*
+ * File types
+ */
+enum ftype {
+ NFNON = 0, /* non-file */
+ NFREG = 1, /* regular file */
+ NFDIR = 2, /* directory */
+ NFBLK = 3, /* block special */
+ NFCHR = 4, /* character special */
+ NFLNK = 5, /* symbolic link */
+ NFSOCK = 6, /* unix domain sockets */
+ NFBAD = 7, /* unused */
+ NFFIFO = 8 /* named pipe */
+};
+
+/*
+ * File access handle
+ */
+struct nfs_fh {
+ opaque data[NFS_FHSIZE];
+};
+
+/*
+ * Timeval
+ */
+struct nfstime {
+ unsigned seconds;
+ unsigned useconds;
+};
+
+
+/*
+ * File attributes
+ */
+struct fattr {
+ ftype type; /* file type */
+ unsigned mode; /* protection mode bits */
+ unsigned nlink; /* # hard links */
+ unsigned uid; /* owner user id */
+ unsigned gid; /* owner group id */
+ unsigned size; /* file size in bytes */
+ unsigned blocksize; /* prefered block size */
+ unsigned rdev; /* special device # */
+ unsigned blocks; /* Kb of disk used by file */
+ unsigned fsid; /* device # */
+ unsigned fileid; /* inode # */
+ nfstime atime; /* time of last access */
+ nfstime mtime; /* time of last modification */
+ nfstime ctime; /* time of last change */
+};
+
+/*
+ * File attributes which can be set
+ */
+struct sattr {
+ unsigned mode; /* protection mode bits */
+ unsigned uid; /* owner user id */
+ unsigned gid; /* owner group id */
+ unsigned size; /* file size in bytes */
+ nfstime atime; /* time of last access */
+ nfstime mtime; /* time of last modification */
+};
+
+
+typedef string filename<NFS_MAXNAMLEN>;
+typedef string nfspath<NFS_MAXPATHLEN>;
+
+/*
+ * Reply status with file attributes
+ */
+union attrstat switch (nfsstat status) {
+case NFS_OK:
+ fattr attributes;
+default:
+ void;
+};
+
+struct sattrargs {
+ nfs_fh file;
+ sattr attributes;
+};
+
+/*
+ * Arguments for directory operations
+ */
+struct diropargs {
+ nfs_fh dir; /* directory file handle */
+ filename name; /* name (up to NFS_MAXNAMLEN bytes) */
+};
+
+struct diropokres {
+ nfs_fh file;
+ fattr attributes;
+};
+
+/*
+ * Results from directory operation
+ */
+union diropres switch (nfsstat status) {
+case NFS_OK:
+ diropokres diropres;
+default:
+ void;
+};
+
+union readlinkres switch (nfsstat status) {
+case NFS_OK:
+ nfspath data;
+default:
+ void;
+};
+
+/*
+ * Arguments to remote read
+ */
+struct readargs {
+ nfs_fh file; /* handle for file */
+ unsigned offset; /* byte offset in file */
+ unsigned count; /* immediate read count */
+ unsigned totalcount; /* total read count (from this offset)*/
+};
+
+/*
+ * Status OK portion of remote read reply
+ */
+struct readokres {
+ fattr attributes; /* attributes, need for pagin*/
+ opaque data<NFS_MAXDATA>;
+};
+
+union readres switch (nfsstat status) {
+case NFS_OK:
+ readokres reply;
+default:
+ void;
+};
+
+/*
+ * Arguments to remote write
+ */
+struct writeargs {
+ nfs_fh file; /* handle for file */
+ unsigned beginoffset; /* beginning byte offset in file */
+ unsigned offset; /* current byte offset in file */
+ unsigned totalcount; /* total write count (to this offset)*/
+ opaque data<NFS_MAXDATA>;
+};
+
+struct createargs {
+ diropargs where;
+ sattr attributes;
+};
+
+struct renameargs {
+ diropargs from;
+ diropargs to;
+};
+
+struct linkargs {
+ nfs_fh from;
+ diropargs to;
+};
+
+struct symlinkargs {
+ diropargs from;
+ nfspath to;
+ sattr attributes;
+};
+
+
+typedef opaque nfscookie[NFS_COOKIESIZE];
+
+/*
+ * Arguments to readdir
+ */
+struct readdirargs {
+ nfs_fh dir; /* directory handle */
+ nfscookie cookie;
+ unsigned count; /* number of directory bytes to read */
+};
+
+struct entry {
+ unsigned fileid;
+ filename name;
+ nfscookie cookie;
+ entry *nextentry;
+};
+
+struct dirlist {
+ entry *entries;
+ bool eof;
+};
+
+union readdirres switch (nfsstat status) {
+case NFS_OK:
+ dirlist reply;
+default:
+ void;
+};
+
+struct statfsokres {
+ unsigned tsize; /* preferred transfer size in bytes */
+ unsigned bsize; /* fundamental file system block size */
+ unsigned blocks; /* total blocks in file system */
+ unsigned bfree; /* free blocks in fs */
+ unsigned bavail; /* free blocks avail to non-superuser */
+};
+
+union statfsres switch (nfsstat status) {
+case NFS_OK:
+ statfsokres reply;
+default:
+ void;
+};
+
+#ifdef WANT_NFS3
+
+/*
+ * NFSv3 constants and types
+ */
+const NFS3_FHSIZE = 64; /* maximum size in bytes of a file handle */
+const NFS3_COOKIEVERFSIZE = 8; /* size of a cookie verifier for READDIR */
+const NFS3_CREATEVERFSIZE = 8; /* size of the verifier used for CREATE */
+const NFS3_WRITEVERFSIZE = 8; /* size of the verifier used for WRITE */
+
+typedef unsigned hyper uint64;
+typedef hyper int64;
+typedef unsigned long uint32;
+typedef long int32;
+typedef string filename3<>;
+typedef string nfspath3<>;
+typedef uint64 fileid3;
+typedef uint64 cookie3;
+typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
+typedef opaque createverf3[NFS3_CREATEVERFSIZE];
+typedef opaque writeverf3[NFS3_WRITEVERFSIZE];
+typedef uint32 uid3;
+typedef uint32 gid3;
+typedef uint64 size3;
+typedef uint64 offset3;
+typedef uint32 mode3;
+typedef uint32 count3;
+
+/*
+ * Error status (v3)
+ */
+enum nfsstat3 {
+ NFS3_OK = 0,
+ NFS3ERR_PERM = 1,
+ NFS3ERR_NOENT = 2,
+ NFS3ERR_IO = 5,
+ NFS3ERR_NXIO = 6,
+ NFS3ERR_ACCES = 13,
+ NFS3ERR_EXIST = 17,
+ NFS3ERR_XDEV = 18,
+ NFS3ERR_NODEV = 19,
+ NFS3ERR_NOTDIR = 20,
+ NFS3ERR_ISDIR = 21,
+ NFS3ERR_INVAL = 22,
+ NFS3ERR_FBIG = 27,
+ NFS3ERR_NOSPC = 28,
+ NFS3ERR_ROFS = 30,
+ NFS3ERR_MLINK = 31,
+ NFS3ERR_NAMETOOLONG = 63,
+ NFS3ERR_NOTEMPTY = 66,
+ NFS3ERR_DQUOT = 69,
+ NFS3ERR_STALE = 70,
+ NFS3ERR_REMOTE = 71,
+ NFS3ERR_BADHANDLE = 10001,
+ NFS3ERR_NOT_SYNC = 10002,
+ NFS3ERR_BAD_COOKIE = 10003,
+ NFS3ERR_NOTSUPP = 10004,
+ NFS3ERR_TOOSMALL = 10005,
+ NFS3ERR_SERVERFAULT = 10006,
+ NFS3ERR_BADTYPE = 10007,
+ NFS3ERR_JUKEBOX = 10008
+};
+
+/*
+ * File types (v3)
+ */
+enum ftype3 {
+ NF3REG = 1, /* regular file */
+ NF3DIR = 2, /* directory */
+ NF3BLK = 3, /* block special */
+ NF3CHR = 4, /* character special */
+ NF3LNK = 5, /* symbolic link */
+ NF3SOCK = 6, /* unix domain sockets */
+ NF3FIFO = 7 /* named pipe */
+};
+
+struct specdata3 {
+ uint32 specdata1;
+ uint32 specdata2;
+};
+
+/*
+ * File access handle (v3)
+ */
+struct nfs_fh3 {
+ opaque data<NFS3_FHSIZE>;
+};
+
+/*
+ * Timeval (v3)
+ */
+struct nfstime3 {
+ uint32 seconds;
+ uint32 nseconds;
+};
+
+
+/*
+ * File attributes (v3)
+ */
+struct fattr3 {
+ ftype3 type; /* file type */
+ mode3 mode; /* protection mode bits */
+ uint32 nlink; /* # hard links */
+ uid3 uid; /* owner user id */
+ gid3 gid; /* owner group id */
+ size3 size; /* file size in bytes */
+ size3 used; /* prefered block size */
+ specdata3 rdev; /* special device # */
+ uint64 fsid; /* device # */
+ fileid3 fileid; /* inode # */
+ nfstime3 atime; /* time of last access */
+ nfstime3 mtime; /* time of last modification */
+ nfstime3 ctime; /* time of last change */
+};
+
+union post_op_attr switch (bool attributes_follow) {
+case TRUE:
+ fattr3 attributes;
+case FALSE:
+ void;
+};
+
+struct wcc_attr {
+ size3 size;
+ nfstime3 mtime;
+ nfstime3 ctime;
+};
+
+union pre_op_attr switch (bool attributes_follow) {
+case TRUE:
+ wcc_attr attributes;
+case FALSE:
+ void;
+};
+
+struct wcc_data {
+ pre_op_attr before;
+ post_op_attr after;
+};
+
+union post_op_fh3 switch (bool handle_follows) {
+case TRUE:
+ nfs_fh3 handle;
+case FALSE:
+ void;
+};
+
+/*
+ * File attributes which can be set (v3)
+ */
+enum time_how {
+ DONT_CHANGE = 0,
+ SET_TO_SERVER_TIME = 1,
+ SET_TO_CLIENT_TIME = 2
+};
+
+union set_mode3 switch (bool set_it) {
+case TRUE:
+ mode3 mode;
+default:
+ void;
+};
+
+union set_uid3 switch (bool set_it) {
+case TRUE:
+ uid3 uid;
+default:
+ void;
+};
+
+union set_gid3 switch (bool set_it) {
+case TRUE:
+ gid3 gid;
+default:
+ void;
+};
+
+union set_size3 switch (bool set_it) {
+case TRUE:
+ size3 size;
+default:
+ void;
+};
+
+union set_atime switch (time_how set_it) {
+case SET_TO_CLIENT_TIME:
+ nfstime3 atime;
+default:
+ void;
+};
+
+union set_mtime switch (time_how set_it) {
+case SET_TO_CLIENT_TIME:
+ nfstime3 mtime;
+default:
+ void;
+};
+
+struct sattr3 {
+ set_mode3 mode;
+ set_uid3 uid;
+ set_gid3 gid;
+ set_size3 size;
+ set_atime atime;
+ set_mtime mtime;
+};
+
+/*
+ * Arguments for directory operations (v3)
+ */
+struct diropargs3 {
+ nfs_fh3 dir; /* directory file handle */
+ filename3 name; /* name (up to NFS_MAXNAMLEN bytes) */
+};
+
+/*
+ * Arguments to getattr (v3).
+ */
+struct GETATTR3args {
+ nfs_fh3 object;
+};
+
+struct GETATTR3resok {
+ fattr3 obj_attributes;
+};
+
+union GETATTR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ GETATTR3resok resok;
+default:
+ void;
+};
+
+/*
+ * Arguments to setattr (v3).
+ */
+union sattrguard3 switch (bool check) {
+case TRUE:
+ nfstime3 obj_ctime;
+case FALSE:
+ void;
+};
+
+struct SETATTR3args {
+ nfs_fh3 object;
+ sattr3 new_attributes;
+ sattrguard3 guard;
+};
+
+struct SETATTR3resok {
+ wcc_data obj_wcc;
+};
+
+struct SETATTR3resfail {
+ wcc_data obj_wcc;
+};
+
+union SETATTR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ SETATTR3resok resok;
+default:
+ SETATTR3resfail resfail;
+};
+
+/*
+ * Arguments to lookup (v3).
+ */
+struct LOOKUP3args {
+ diropargs3 what;
+};
+
+struct LOOKUP3resok {
+ nfs_fh3 object;
+ post_op_attr obj_attributes;
+ post_op_attr dir_attributes;
+};
+
+struct LOOKUP3resfail {
+ post_op_attr dir_attributes;
+};
+
+union LOOKUP3res switch (nfsstat3 status) {
+case NFS3_OK:
+ LOOKUP3resok resok;
+default:
+ LOOKUP3resfail resfail;
+};
+
+/*
+ * Arguments to access (v3).
+ */
+const ACCESS3_READ = 0x0001;
+const ACCESS3_LOOKUP = 0x0002;
+const ACCESS3_MODIFY = 0x0004;
+const ACCESS3_EXTEND = 0x0008;
+const ACCESS3_DELETE = 0x0010;
+const ACCESS3_EXECUTE = 0x0020;
+
+struct ACCESS3args {
+ nfs_fh3 object;
+ uint32 access;
+};
+
+struct ACCESS3resok {
+ post_op_attr obj_attributes;
+ uint32 access;
+};
+
+struct ACCESS3resfail {
+ post_op_attr obj_attributes;
+};
+
+union ACCESS3res switch (nfsstat3 status) {
+case NFS3_OK:
+ ACCESS3resok resok;
+default:
+ ACCESS3resfail resfail;
+};
+
+/*
+ * Arguments to readlink (v3).
+ */
+struct READLINK3args {
+ nfs_fh3 symlink;
+};
+
+struct READLINK3resok {
+ post_op_attr symlink_attributes;
+ nfspath3 data;
+};
+
+struct READLINK3resfail {
+ post_op_attr symlink_attributes;
+};
+
+union READLINK3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READLINK3resok resok;
+default:
+ READLINK3resfail resfail;
+};
+
+/*
+ * Arguments to read (v3).
+ */
+struct READ3args {
+ nfs_fh3 file;
+ offset3 offset;
+ count3 count;
+};
+
+struct READ3resok {
+ post_op_attr file_attributes;
+ count3 count;
+ bool eof;
+ opaque data<>;
+};
+
+struct READ3resfail {
+ post_op_attr file_attributes;
+};
+
+/* XXX: solaris 2.6 uses ``nfsstat'' here */
+union READ3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READ3resok resok;
+default:
+ READ3resfail resfail;
+};
+
+/*
+ * Arguments to write (v3).
+ */
+enum stable_how {
+ UNSTABLE = 0,
+ DATA_SYNC = 1,
+ FILE_SYNC = 2
+};
+
+struct WRITE3args {
+ nfs_fh3 file;
+ offset3 offset;
+ count3 count;
+ stable_how stable;
+ opaque data<>;
+};
+
+struct WRITE3resok {
+ wcc_data file_wcc;
+ count3 count;
+ stable_how committed;
+ writeverf3 verf;
+};
+
+struct WRITE3resfail {
+ wcc_data file_wcc;
+};
+
+union WRITE3res switch (nfsstat3 status) {
+case NFS3_OK:
+ WRITE3resok resok;
+default:
+ WRITE3resfail resfail;
+};
+
+/*
+ * Arguments to create (v3).
+ */
+enum createmode3 {
+ UNCHECKED = 0,
+ GUARDED = 1,
+ EXCLUSIVE = 2
+};
+
+union createhow3 switch (createmode3 mode) {
+case UNCHECKED:
+case GUARDED:
+ sattr3 obj_attributes;
+case EXCLUSIVE:
+ createverf3 verf;
+};
+
+struct CREATE3args {
+ diropargs3 where;
+ createhow3 how;
+};
+
+struct CREATE3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct CREATE3resfail {
+ wcc_data dir_wcc;
+};
+
+union CREATE3res switch (nfsstat3 status) {
+case NFS3_OK:
+ CREATE3resok resok;
+default:
+ CREATE3resfail resfail;
+};
+
+/*
+ * Arguments to mkdir (v3).
+ */
+struct MKDIR3args {
+ diropargs3 where;
+ sattr3 attributes;
+};
+
+struct MKDIR3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct MKDIR3resfail {
+ wcc_data dir_wcc;
+};
+
+union MKDIR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ MKDIR3resok resok;
+default:
+ MKDIR3resfail resfail;
+};
+
+/*
+ * Arguments to symlink (v3).
+ */
+struct symlinkdata3 {
+ sattr3 symlink_attributes;
+ nfspath3 symlink_data;
+};
+
+struct SYMLINK3args {
+ diropargs3 where;
+ symlinkdata3 symlink;
+};
+
+struct SYMLINK3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct SYMLINK3resfail {
+ wcc_data dir_wcc;
+};
+
+union SYMLINK3res switch (nfsstat3 status) {
+case NFS3_OK:
+ SYMLINK3resok resok;
+default:
+ SYMLINK3resfail resfail;
+};
+
+/*
+ * Arguments to mknod (v3).
+ */
+struct devicedata3 {
+ sattr3 dev_attributes;
+ specdata3 spec;
+};
+
+union mknoddata3 switch (ftype3 type) {
+case NF3CHR:
+case NF3BLK:
+ devicedata3 device;
+case NF3SOCK:
+case NF3FIFO:
+ sattr3 pipe_attributes;
+default:
+ void;
+};
+
+struct MKNOD3args {
+ diropargs3 where;
+ mknoddata3 what;
+};
+
+struct MKNOD3resok {
+ post_op_fh3 obj;
+ post_op_attr obj_attributes;
+ wcc_data dir_wcc;
+};
+
+struct MKNOD3resfail {
+ wcc_data dir_wcc;
+};
+
+union MKNOD3res switch (nfsstat3 status) {
+case NFS3_OK:
+ MKNOD3resok resok;
+default:
+ MKNOD3resfail resfail;
+};
+
+/*
+ * Arguments to remove (v3).
+ */
+struct REMOVE3args {
+ diropargs3 object;
+};
+
+struct REMOVE3resok {
+ wcc_data dir_wcc;
+};
+
+struct REMOVE3resfail {
+ wcc_data dir_wcc;
+};
+
+union REMOVE3res switch (nfsstat3 status) {
+case NFS3_OK:
+ REMOVE3resok resok;
+default:
+ REMOVE3resfail resfail;
+};
+
+/*
+ * Arguments to rmdir (v3).
+ */
+struct RMDIR3args {
+ diropargs3 object;
+};
+
+struct RMDIR3resok {
+ wcc_data dir_wcc;
+};
+
+struct RMDIR3resfail {
+ wcc_data dir_wcc;
+};
+
+union RMDIR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ RMDIR3resok resok;
+default:
+ RMDIR3resfail resfail;
+};
+
+/*
+ * Arguments to rename (v3).
+ */
+struct RENAME3args {
+ diropargs3 from;
+ diropargs3 to;
+};
+
+struct RENAME3resok {
+ wcc_data fromdir_wcc;
+ wcc_data todir_wcc;
+};
+
+struct RENAME3resfail {
+ wcc_data fromdir_wcc;
+ wcc_data todir_wcc;
+};
+
+union RENAME3res switch (nfsstat3 status) {
+case NFS3_OK:
+ RENAME3resok resok;
+default:
+ RENAME3resfail resfail;
+};
+
+/*
+ * Arguments to link (v3).
+ */
+struct LINK3args {
+ nfs_fh3 file;
+ diropargs3 link;
+};
+
+struct LINK3resok {
+ post_op_attr file_attributes;
+ wcc_data linkdir_wcc;
+};
+
+struct LINK3resfail {
+ post_op_attr file_attributes;
+ wcc_data linkdir_wcc;
+};
+
+union LINK3res switch (nfsstat3 status) {
+case NFS3_OK:
+ LINK3resok resok;
+default:
+ LINK3resfail resfail;
+};
+
+/*
+ * Arguments to readdir (v3).
+ */
+struct READDIR3args {
+ nfs_fh3 dir;
+ cookie3 cookie;
+ cookieverf3 cookieverf;
+ count3 count;
+};
+
+struct entry3 {
+ fileid3 fileid;
+ filename3 name;
+ cookie3 cookie;
+ entry3 *nextentry;
+};
+
+struct dirlist3 {
+ entry3 *entries;
+ bool eof;
+};
+
+struct READDIR3resok {
+ post_op_attr dir_attributes;
+ cookieverf3 cookieverf;
+ dirlist3 reply;
+};
+
+struct READDIR3resfail {
+ post_op_attr dir_attributes;
+};
+
+union READDIR3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READDIR3resok resok;
+default:
+ READDIR3resfail resfail;
+};
+
+/*
+ * Arguments to readdirplus (v3).
+ */
+struct READDIRPLUS3args {
+ nfs_fh3 dir;
+ cookie3 cookie;
+ cookieverf3 cookieverf;
+ count3 dircount;
+ count3 maxcount;
+};
+
+struct entryplus3 {
+ fileid3 fileid;
+ filename3 name;
+ cookie3 cookie;
+ post_op_attr name_attributes;
+ post_op_fh3 name_handle;
+ entryplus3 *nextentry;
+};
+
+struct dirlistplus3 {
+ entryplus3 *entries;
+ bool eof;
+};
+
+struct READDIRPLUS3resok {
+ post_op_attr dir_attributes;
+ cookieverf3 cookieverf;
+ dirlistplus3 reply;
+};
+
+struct READDIRPLUS3resfail {
+ post_op_attr dir_attributes;
+};
+
+union READDIRPLUS3res switch (nfsstat3 status) {
+case NFS3_OK:
+ READDIRPLUS3resok resok;
+default:
+ READDIRPLUS3resfail resfail;
+};
+
+/*
+ * Arguments to fsstat (v3).
+ */
+struct FSSTAT3args {
+ nfs_fh3 fsroot;
+};
+
+struct FSSTAT3resok {
+ post_op_attr obj_attributes;
+ size3 tbytes;
+ size3 fbytes;
+ size3 abytes;
+ size3 tfiles;
+ size3 ffiles;
+ size3 afiles;
+ uint32 invarsec;
+};
+
+struct FSSTAT3resfail {
+ post_op_attr obj_attributes;
+};
+
+union FSSTAT3res switch (nfsstat3 status) {
+case NFS3_OK:
+ FSSTAT3resok resok;
+default:
+ FSSTAT3resfail resfail;
+};
+
+/*
+ * Arguments to fsinfo (v3).
+ */
+const FSF3_LINK = 0x0001;
+const FSF3_SYMLINK = 0x0002;
+const FSF3_HOMOGENEOUS = 0x0008;
+const FSF3_CANSETTIME = 0x0010;
+
+struct FSINFO3args {
+ nfs_fh3 fsroot;
+};
+
+struct FSINFO3resok {
+ post_op_attr obj_attributes;
+ uint32 rtmax;
+ uint32 rtpref;
+ uint32 rtmult;
+ uint32 wtmax;
+ uint32 wtpref;
+ uint32 wtmult;
+ uint32 dtpref;
+ size3 maxfilesize;
+ nfstime3 time_delta;
+ uint32 properties;
+};
+
+struct FSINFO3resfail {
+ post_op_attr obj_attributes;
+};
+
+union FSINFO3res switch (nfsstat3 status) {
+case NFS3_OK:
+ FSINFO3resok resok;
+default:
+ FSINFO3resfail resfail;
+};
+
+/*
+ * Arguments to pathconf (v3).
+ */
+struct PATHCONF3args {
+ nfs_fh3 object;
+};
+
+struct PATHCONF3resok {
+ post_op_attr obj_attributes;
+ uint32 linkmax;
+ uint32 name_max;
+ bool no_trunc;
+ bool chown_restricted;
+ bool case_insensitive;
+ bool case_preserving;
+};
+
+struct PATHCONF3resfail {
+ post_op_attr obj_attributes;
+};
+
+union PATHCONF3res switch (nfsstat3 status) {
+case NFS3_OK:
+ PATHCONF3resok resok;
+default:
+ PATHCONF3resfail resfail;
+};
+
+/*
+ * Arguments to commit (v3).
+ */
+struct COMMIT3args {
+ nfs_fh3 file;
+ offset3 offset;
+ count3 count;
+};
+
+struct COMMIT3resok {
+ wcc_data file_wcc;
+ writeverf3 verf;
+};
+
+struct COMMIT3resfail {
+ wcc_data file_wcc;
+};
+
+union COMMIT3res switch (nfsstat3 status) {
+case NFS3_OK:
+ COMMIT3resok resok;
+default:
+ COMMIT3resfail resfail;
+};
+
+#endif /* WANT_NFS3 */
+
+/*
+ * Remote file service routines
+ */
+program NFS_PROGRAM {
+ version NFS_VERSION {
+ void
+ NFSPROC_NULL(void) = 0;
+
+ attrstat
+ NFSPROC_GETATTR(nfs_fh) = 1;
+
+ attrstat
+ NFSPROC_SETATTR(sattrargs) = 2;
+
+ void
+ NFSPROC_ROOT(void) = 3;
+
+ diropres
+ NFSPROC_LOOKUP(diropargs) = 4;
+
+ readlinkres
+ NFSPROC_READLINK(nfs_fh) = 5;
+
+ readres
+ NFSPROC_READ(readargs) = 6;
+
+ void
+ NFSPROC_WRITECACHE(void) = 7;
+
+ attrstat
+ NFSPROC_WRITE(writeargs) = 8;
+
+ diropres
+ NFSPROC_CREATE(createargs) = 9;
+
+ nfsstat
+ NFSPROC_REMOVE(diropargs) = 10;
+
+ nfsstat
+ NFSPROC_RENAME(renameargs) = 11;
+
+ nfsstat
+ NFSPROC_LINK(linkargs) = 12;
+
+ nfsstat
+ NFSPROC_SYMLINK(symlinkargs) = 13;
+
+ diropres
+ NFSPROC_MKDIR(createargs) = 14;
+
+ nfsstat
+ NFSPROC_RMDIR(diropargs) = 15;
+
+ readdirres
+ NFSPROC_READDIR(readdirargs) = 16;
+
+ statfsres
+ NFSPROC_STATFS(nfs_fh) = 17;
+ } = 2;
+} = 100003;
+#ifdef WANT_NFS3
+program NFS3_PROGRAM {
+ version NFS_V3 {
+ void
+ NFSPROC3_NULL(void) = 0;
+
+ GETATTR3res
+ NFSPROC3_GETATTR(GETATTR3args) = 1;
+
+ SETATTR3res
+ NFSPROC3_SETATTR(SETATTR3args) = 2;
+
+ LOOKUP3res
+ NFSPROC3_LOOKUP(LOOKUP3args) = 3;
+
+ ACCESS3res
+ NFSPROC3_ACCESS(ACCESS3args) = 4;
+
+ READLINK3res
+ NFSPROC3_READLINK(READLINK3args) = 5;
+
+ READ3res
+ NFSPROC3_READ(READ3args) = 6;
+
+ WRITE3res
+ NFSPROC3_WRITE(WRITE3args) = 7;
+
+ CREATE3res
+ NFSPROC3_CREATE(CREATE3args) = 8;
+
+ MKDIR3res
+ NFSPROC3_MKDIR(MKDIR3args) = 9;
+
+ SYMLINK3res
+ NFSPROC3_SYMLINK(SYMLINK3args) = 10;
+
+ MKNOD3res
+ NFSPROC3_MKNOD(MKNOD3args) = 11;
+
+ REMOVE3res
+ NFSPROC3_REMOVE(REMOVE3args) = 12;
+
+ RMDIR3res
+ NFSPROC3_RMDIR(RMDIR3args) = 13;
+
+ RENAME3res
+ NFSPROC3_RENAME(RENAME3args) = 14;
+
+ LINK3res
+ NFSPROC3_LINK(LINK3args) = 15;
+
+ READDIR3res
+ NFSPROC3_READDIR(READDIR3args) = 16;
+
+ READDIRPLUS3res
+ NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17;
+
+ FSSTAT3res
+ NFSPROC3_FSSTAT(FSSTAT3args) = 18;
+
+ FSINFO3res
+ NFSPROC3_FSINFO(FSINFO3args) = 19;
+
+ PATHCONF3res
+ NFSPROC3_PATHCONF(PATHCONF3args) = 20;
+
+ COMMIT3res
+ NFSPROC3_COMMIT(COMMIT3args) = 21;
+ } = 3;
+} = 100003;
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/nis.x b/cpukit/librpc/include/rpcsvc/nis.x
new file mode 100644
index 0000000000..ba6c6d1576
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nis.x
@@ -0,0 +1,466 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user or with the express written consent of
+% * Sun Microsystems, Inc.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/nis.x,v 1.3 1999/08/27 23:45:09 peter Exp $";
+%#endif /* not lint */
+#endif
+
+/*
+ * From 4.1 : @(#)nis.x 1.61 Copyright 1989 Sun Microsystems
+ *
+ * RPC Language Protocol description file for NIS Plus
+ * This version : 1.61
+ * Last Modified : 3/19/91
+ */
+#ifdef RPC_HDR
+%/*
+% * nis.h
+% *
+% * This file is the main include file for NIS clients. It contains
+% * both the client library function defines and the various data
+% * structures used by the NIS service. It includes the file nis_tags.h
+% * which defines the tag values. This allows the tags to change without
+% * having to change the nis.x file.
+% *
+% * NOTE : DO NOT EDIT THIS FILE! It is automatically generated when
+% * rpcgen is run on the nis.x file. Note that there is a
+% * simple sed script to remove some unneeded lines. (See the
+% * Makefile target nis.h)
+% *
+% */
+%#include <rpcsvc/nis_tags.h>
+#endif
+
+/* This gets stuffed into the source files. */
+#if RPC_HDR
+%#include <rpc/xdr.h>
+#endif
+/*
+ * This is just pointless.
+ */
+#ifdef SUN_STUPIDITY
+#if RPC_SVC
+%#include "nis_svc.h"
+#endif
+#endif
+
+/* Include the RPC Language description of NIS objects */
+#include "nis_object.x"
+
+/* Errors that can be returned by the service */
+enum nis_error {
+ NIS_SUCCESS = 0, /* A-ok, let's rock n roll */
+ NIS_S_SUCCESS = 1, /* Name found (maybe) */
+ NIS_NOTFOUND = 2, /* Name definitely not found */
+ NIS_S_NOTFOUND = 3, /* Name maybe not found */
+ NIS_CACHEEXPIRED = 4, /* Name exists but cache out of date */
+ NIS_NAMEUNREACHABLE = 5, /* Can't get there from here */
+ NIS_UNKNOWNOBJ = 6, /* Object type is bogus */
+ NIS_TRYAGAIN = 7, /* I'm busy, call back */
+ NIS_SYSTEMERROR = 8, /* Out of band failure */
+ NIS_CHAINBROKEN = 9, /* First/Next warning */
+ NIS_PERMISSION = 10, /* Not enough permission to access */
+ NIS_NOTOWNER = 11, /* You don't own it, sorry */
+ NIS_NOT_ME = 12, /* I don't serve this name */
+ NIS_NOMEMORY = 13, /* Outta VM! Help! */
+ NIS_NAMEEXISTS = 14, /* Can't create over another name */
+ NIS_NOTMASTER = 15, /* I'm justa secondaray, don't ask me */
+ NIS_INVALIDOBJ = 16, /* Object is broken somehow */
+ NIS_BADNAME = 17, /* Unparsable name */
+ NIS_NOCALLBACK = 18, /* Couldn't talk to call back proc */
+ NIS_CBRESULTS = 19, /* Results being called back to you */
+ NIS_NOSUCHNAME = 20, /* Name unknown */
+ NIS_NOTUNIQUE = 21, /* Value is not uniques (entry) */
+ NIS_IBMODERROR = 22, /* Inf. Base. Modify error. */
+ NIS_NOSUCHTABLE = 23, /* Name for table was wrong */
+ NIS_TYPEMISMATCH = 24, /* Entry and table type mismatch */
+ NIS_LINKNAMEERROR = 25, /* Link points to bogus name */
+ NIS_PARTIAL = 26, /* Partial success, found table */
+ NIS_TOOMANYATTRS = 27, /* Too many attributes */
+ NIS_RPCERROR = 28, /* RPC error encountered */
+ NIS_BADATTRIBUTE = 29, /* Bad or invalid attribute */
+ NIS_NOTSEARCHABLE = 30, /* Non-searchable object searched */
+ NIS_CBERROR = 31, /* Error during callback (svc crash) */
+ NIS_FOREIGNNS = 32, /* Foreign Namespace */
+ NIS_BADOBJECT = 33, /* Malformed object structure */
+ NIS_NOTSAMEOBJ = 34, /* Object swapped during deletion */
+ NIS_MODFAIL = 35, /* Failure during a Modify. */
+ NIS_BADREQUEST = 36, /* Illegal query for table */
+ NIS_NOTEMPTY = 37, /* Attempt to remove a non-empty tbl */
+ NIS_COLDSTART_ERR = 38, /* Error accesing the cold start file */
+ NIS_RESYNC = 39, /* Transaction log too far out of date */
+ NIS_FAIL = 40, /* NIS operation failed. */
+ NIS_UNAVAIL = 41, /* NIS+ service is unavailable (client) */
+ NIS_RES2BIG = 42, /* NIS+ result too big for datagram */
+ NIS_SRVAUTH = 43, /* NIS+ server wasn't authenticated. */
+ NIS_CLNTAUTH = 44, /* NIS+ Client wasn't authenticated. */
+ NIS_NOFILESPACE = 45, /* NIS+ server ran out of disk space */
+ NIS_NOPROC = 46, /* NIS+ server couldn't create new proc */
+ NIS_DUMPLATER = 47 /* NIS+ server already has dump child */
+};
+
+
+/*
+ * Structure definitions for the parameters and results of the actual
+ * NIS RPC calls.
+ *
+ * This is the standard result (in the protocol) of most of the nis
+ * requests.
+ */
+
+struct nis_result {
+ nis_error status; /* Status of the response */
+ nis_object objects<>; /* objects found */
+ netobj cookie; /* Cookie Data */
+ u_long zticks; /* server ticks */
+ u_long dticks; /* DBM ticks. */
+ u_long aticks; /* Cache (accel) ticks */
+ u_long cticks; /* Client ticks */
+};
+
+/*
+ * A Name Service request
+ * This request is used to access the name space, ns_name is the name
+ * of the object within the namespace and the object is it's value, for
+ * add/modify, a copy of the original for remove.
+ */
+
+struct ns_request {
+ nis_name ns_name; /* Name in the NIS name space */
+ nis_object ns_object<1>; /* Optional Object (add/remove) */
+};
+
+/*
+ * An information base request
+ * This request includes the NIS name of the table we wish to search, the
+ * search criteria in the form of attribute/value pairs and an optional
+ * callback program number. If the callback program number is provided
+ * the server will send back objects one at a time, otherwise it will
+ * return them all in the response.
+ */
+
+struct ib_request {
+ nis_name ibr_name; /* The name of the Table */
+ nis_attr ibr_srch<>; /* The search critereia */
+ u_long ibr_flags; /* Optional flags */
+ nis_object ibr_obj<1>; /* optional object (add/modify) */
+ nis_server ibr_cbhost<1>; /* Optional callback info */
+ u_long ibr_bufsize; /* Optional first/next bufsize */
+ netobj ibr_cookie; /* The first/next cookie */
+};
+
+/*
+ * This argument to the PING call notifies the replicas that something in
+ * a directory has changed and this is it's timestamp. The replica will use
+ * the timestamp to determine if its resync operation was successful.
+ */
+struct ping_args {
+ nis_name dir; /* Directory that had the change */
+ u_long stamp; /* timestamp of the transaction */
+};
+
+/*
+ * These are the type of entries that are stored in the transaction log,
+ * note that modifications will appear as two entries, for names, they have
+ * a "OLD" entry followed by a "NEW" entry. For entries in tables, there
+ * is a remove followed by an add. It is done this way so that we can read
+ * the log backwards to back out transactions and forwards to propogate
+ * updated.
+ */
+enum log_entry_t {
+ LOG_NOP = 0,
+ ADD_NAME = 1, /* Name Added to name space */
+ REM_NAME = 2, /* Name removed from name space */
+ MOD_NAME_OLD = 3, /* Name was modified in the name space */
+ MOD_NAME_NEW = 4, /* Name was modified in the name space */
+ ADD_IBASE = 5, /* Entry added to information base */
+ REM_IBASE = 6, /* Entry removed from information base */
+ MOD_IBASE = 7, /* Entry was modified in information base */
+ UPD_STAMP = 8 /* Update timestamp (used as fenceposts) */
+};
+
+/*
+ * This result is returned from the name service when it is requested to
+ * dump logged entries from its transaction log. Information base updates
+ * will have the name of the information base in the le_name field and
+ * a canonical set of attribute/value pairs to fully specify the entry's
+ * 'name'.
+ */
+struct log_entry {
+ u_long le_time; /* Time in seconds */
+ log_entry_t le_type; /* Type of log entry */
+ nis_name le_princp; /* Principal making the change */
+ nis_name le_name; /* Name of table/dir involved */
+ nis_attr le_attrs<>; /* List of AV pairs. */
+ nis_object le_object; /* Actual object value */
+};
+
+struct log_result {
+ nis_error lr_status; /* The status itself */
+ netobj lr_cookie; /* Used by the dump callback */
+ log_entry lr_entries<>; /* zero or more entries */
+};
+
+struct cp_result {
+ nis_error cp_status; /* Status of the checkpoint */
+ u_long cp_zticks; /* Service 'ticks' */
+ u_long cp_dticks; /* Database 'ticks' */
+};
+
+/*
+ * This structure defines a generic NIS tag list. The taglist contains
+ * zero or tags, each of which is a type and a value. (u_long).
+ * These are used to report statistics (see tag definitions below)
+ * and to set or reset state variables.
+ */
+struct nis_tag {
+ u_long tag_type; /* Statistic tag (may vary) */
+ string tag_val<1024>; /* Statistic value may also vary */
+};
+
+struct nis_taglist {
+ nis_tag tags<>; /* List of tags */
+};
+
+struct dump_args {
+ nis_name da_dir; /* Directory to dump */
+ u_long da_time; /* From this timestamp */
+ nis_server da_cbhost<1>; /* Callback to use. */
+};
+
+struct fd_args {
+ nis_name dir_name; /* The directory we're looking for */
+ nis_name requester; /* Host principal name for signature */
+};
+
+struct fd_result {
+ nis_error status; /* Status returned by function */
+ nis_name source; /* Source of this answer */
+ opaque dir_data<>; /* Directory Data (XDR'ed) */
+ opaque signature<>; /* Signature of the source */
+};
+
+
+/*
+ * What's going on here? Well, it's like this. When the service
+ * is being compiled it wants to have the service definition specific
+ * info included, and when the client is being compiled it wants that
+ * info. This includes the appropriate file which was generated by
+ * make in the protocols directory (probably /usr/include/rpcsvc).
+ *
+ * Uhm... guys? With RPC, you aren't supposed to have seperate
+ * server-specific and client-specific header files. You have one header
+ * file that's suitable for both. If your code doesn't work using just
+ * the one header file, I submit to you that it's broken.
+ * -Bill
+ */
+#ifdef SUN_STUPIDITY
+#ifdef RPC_SVC
+%#include "nis_svc.h"
+#endif
+#ifdef RPC_CLNT
+%#include "nis_clnt.h"
+#endif
+#endif
+
+program NIS_PROG {
+
+ /* RPC Language description of the NIS+ protocol */
+ version NIS_VERSION {
+ /* The name service functions */
+ nis_result NIS_LOOKUP(ns_request) = 1;
+ nis_result NIS_ADD(ns_request) = 2;
+ nis_result NIS_MODIFY(ns_request) = 3;
+ nis_result NIS_REMOVE(ns_request) = 4;
+
+ /* The information base functions */
+ nis_result NIS_IBLIST(ib_request) = 5;
+ nis_result NIS_IBADD(ib_request) = 6;
+ nis_result NIS_IBMODIFY(ib_request) = 7;
+ nis_result NIS_IBREMOVE(ib_request) = 8;
+ nis_result NIS_IBFIRST(ib_request) = 9;
+ nis_result NIS_IBNEXT(ib_request) = 10;
+
+ /* NIS Administrative functions */
+ fd_result NIS_FINDDIRECTORY(fd_args) = 12;
+
+ /* If fetch and optionally reset statistics */
+ nis_taglist NIS_STATUS(nis_taglist) = 14;
+
+ /* Dump changes to directory since time in da_time */
+ log_result NIS_DUMPLOG(dump_args) = 15;
+
+ /* Dump contents of directory named */
+ log_result NIS_DUMP(dump_args) = 16;
+
+ /* Check status of callback thread */
+ bool NIS_CALLBACK(netobj) = 17;
+
+ /* Return last update time for named dir */
+ u_long NIS_CPTIME(nis_name) = 18;
+
+ /* Checkpoint directory or table named */
+ cp_result NIS_CHECKPOINT(nis_name) = 19;
+
+ /* Send 'status changed' ping to replicates */
+ void NIS_PING(ping_args) = 20;
+
+ /* Modify server behaviour (such as debugging) */
+ nis_taglist NIS_SERVSTATE(nis_taglist) = 21;
+
+ /* Create a Directory */
+ nis_error NIS_MKDIR(nis_name) = 22;
+
+ /* Remove a Directory */
+ nis_error NIS_RMDIR(nis_name) = 23;
+
+ /* Update public keys of a directory object */
+ nis_error NIS_UPDKEYS(nis_name) = 24;
+ } = 3;
+} = 100300;
+
+/*
+ * Included below are the defines that become part of nis.h,
+ * they are technically not part of the protocol, but do define
+ * key aspects of the implementation and are therefore useful
+ * in building a conforming server or client.
+ */
+#if RPC_HDR
+%/*
+% * Generic "hash" datastructures, used by all types of hashed data.
+% */
+%struct nis_hash_data {
+% nis_name name; /* NIS name of hashed item */
+% int keychain; /* It's hash key (for pop) */
+% struct nis_hash_data *next; /* Hash collision pointer */
+% struct nis_hash_data *prv_item; /* A serial, doubly linked list */
+% struct nis_hash_data *nxt_item; /* of items in the hash table */
+%};
+%typedef struct nis_hash_data NIS_HASH_ITEM;
+%
+%struct nis_hash_table {
+% NIS_HASH_ITEM *keys[64]; /* A hash table of items */
+% NIS_HASH_ITEM *first; /* The first "item" in serial list */
+%};
+%typedef struct nis_hash_table NIS_HASH_TABLE;
+%
+%/* Structure for storing dynamically allocated static data */
+%struct nis_sdata {
+% void *buf; /* Memory allocation pointer */
+% u_long size; /* Buffer size */
+%};
+%
+%/* Generic client creating flags */
+%#define ZMH_VC 1
+%#define ZMH_DG 2
+%#define ZMH_AUTH 4
+%
+%/* Testing Access rights for objects */
+%
+%#define NIS_READ_ACC 1
+%#define NIS_MODIFY_ACC 2
+%#define NIS_CREATE_ACC 4
+%#define NIS_DESTROY_ACC 8
+%/* Test macros. a == access rights, m == desired rights. */
+%#define WORLD(a, m) (((a) & (m)) != 0)
+%#define GROUP(a, m) (((a) & ((m) << 8)) != 0)
+%#define OWNER(a, m) (((a) & ((m) << 16)) != 0)
+%#define NOBODY(a, m) (((a) & ((m) << 24)) != 0)
+%
+%#define OATYPE(d, n) (((d)->do_armask.do_armask_val+n)->oa_otype)
+%#define OARIGHTS(d, n) (((d)->do_armask.do_armask_val+n)->oa_rights)
+%#define WORLD_DEFAULT (NIS_READ_ACC)
+%#define GROUP_DEFAULT (NIS_READ_ACC << 8)
+%#define OWNER_DEFAULT ((NIS_READ_ACC +\
+ NIS_MODIFY_ACC +\
+ NIS_CREATE_ACC +\
+ NIS_DESTROY_ACC) << 16)
+%#define DEFAULT_RIGHTS (WORLD_DEFAULT | GROUP_DEFAULT | OWNER_DEFAULT)
+%
+%/* Result manipulation defines ... */
+%#define NIS_RES_NUMOBJ(x) ((x)->objects.objects_len)
+%#define NIS_RES_OBJECT(x) ((x)->objects.objects_val)
+%#define NIS_RES_COOKIE(x) ((x)->cookie)
+%#define NIS_RES_STATUS(x) ((x)->status)
+%
+%/* These defines make getting at the variant part of the object easier. */
+%#define TA_data zo_data.objdata_u.ta_data
+%#define EN_data zo_data.objdata_u.en_data
+%#define DI_data zo_data.objdata_u.di_data
+%#define LI_data zo_data.objdata_u.li_data
+%#define GR_data zo_data.objdata_u.gr_data
+%
+%#define __type_of(o) ((o)->zo_data.zo_type)
+%
+%/* Declarations for the internal subroutines in nislib.c */
+%enum name_pos {SAME_NAME, HIGHER_NAME, LOWER_NAME, NOT_SEQUENTIAL, BAD_NAME};
+%typedef enum name_pos name_pos;
+%
+%/*
+% * Defines for getting at column data in entry objects. Because RPCGEN
+% * generates some rather wordy structures, we create some defines that
+% * collapse the needed keystrokes to access a particular value using
+% * these definitions they take an nis_object *, and an int and return
+% * a u_char * for Value, and an int for length.
+% */
+%#define ENTRY_VAL(obj, col) \
+ (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val
+%#define ENTRY_LEN(obj, col) \
+ (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len
+%
+%#ifdef __cplusplus
+%}
+%#endif
+%
+%/* Prototypes, and extern declarations for the NIS library functions. */
+%#include <rpcsvc/nislib.h>
+%#endif /* __NIS_RPCGEN_H */
+%/* EDIT_START */
+%
+%/*
+% * nis_3.h
+% *
+% * This file contains definitions that are only of interest to the actual
+% * service daemon and client stubs. Normal users of NIS will not include
+% * this file.
+% *
+% * NOTE : This include file is automatically created by a combination
+% * of rpcgen and sed. DO NOT EDIT IT, change the nis.x file instead
+% * and then remake this file.
+% */
+%#ifndef __nis_3_h
+%#define __nis_3_h
+%#ifdef __cplusplus
+%extern "C" {
+%#endif
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/nis_cache.x b/cpukit/librpc/include/rpcsvc/nis_cache.x
new file mode 100644
index 0000000000..8343cfd050
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nis_cache.x
@@ -0,0 +1,87 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user or with the express written consent of
+% * Sun Microsystems, Inc.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+
+/*
+ * nis_cache.x
+ *
+ * Copyright (c) 1988-1992 Sun Microsystems Inc
+ * All Rights Reserved.
+ */
+
+/* From: %#pragma ident "@(#)nis_cache.x 1.11 94/05/03 SMI" */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/nis_cache.x,v 1.3 1999/08/27 23:45:09 peter Exp $";
+%#endif /* not lint */
+#endif
+
+#ifdef RPC_HDR
+%#include <rpc/types.h>
+%#include <rpcsvc/nis.h>
+%
+%/* default cache file */
+%#define CACHEFILE "/var/nis/NIS_SHARED_DIRCACHE"
+%
+%/* clients have to read-lock the cache file, and SVR4 locking requires that */
+%/* the file be writable, but we don't want a world-writable cache file. */
+%/* So... everyone agrees to use a different, world-writable file for the */
+%/* locking operations, but the data is in CACHEFILE. */
+%#define CACHELOCK "/usr/tmp/.NIS_DIR_CACHELOCK"
+%
+%/* the file containing one trusted XDR'ed directory object.
+% * This has to be present for the system to work.
+% */
+%#define COLD_START_FILE "/var/nis/NIS_COLD_START"
+%
+%enum pc_status {HIT, MISS, NEAR_MISS};
+%
+%extern int __nis_debuglevel;
+%
+%
+#endif
+
+#ifdef RPC_CLNT
+#ifdef SOLARIS
+%#include "../gen/nis_clnt.h"
+#else
+%#include "nis.h"
+#endif
+#endif
+
+program CACHEPROG {
+ version CACHE_VER_1 {
+ void NIS_CACHE_ADD_ENTRY(fd_result) = 1;
+ void NIS_CACHE_REMOVE_ENTRY(directory_obj) = 2;
+ void NIS_CACHE_READ_COLDSTART(void) = 3;
+ void NIS_CACHE_REFRESH_ENTRY(string<>) = 4;
+ } = 1;
+} = 100301;
diff --git a/cpukit/librpc/include/rpcsvc/nis_callback.x b/cpukit/librpc/include/rpcsvc/nis_callback.x
new file mode 100644
index 0000000000..4e74aa0a2e
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nis_callback.x
@@ -0,0 +1,76 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user or with the express written consent of
+% * Sun Microsystems, Inc.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+
+/*
+ * nis_callback.x
+ *
+ * Copyright (c) 1988-1992 Sun Microsystems Inc
+ * All Rights Reserved.
+ */
+
+/* From: %#pragma ident "@(#)nis_callback.x 1.7 94/05/03 SMI" */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/nis_callback.x,v 1.3 1999/08/27 23:45:09 peter Exp $";
+%#endif /* not lint */
+#endif
+
+/*
+ * "@(#)zns_cback.x 1.2 90/09/10 Copyr 1990 Sun Micro"
+ *
+ * RPCL description of the Callback Service.
+ */
+
+#ifdef RPC_HDR
+%#include <rpcsvc/nis.h>
+#endif
+#ifdef RPC_XDR
+#ifdef SOLARIS
+%#include "nis_clnt.h"
+#else
+%#include "nis.h"
+#endif
+#endif
+
+typedef nis_object *obj_p;
+
+struct cback_data {
+ obj_p entries<>; /* List of objects */
+};
+
+program CB_PROG {
+ version CB_VERS {
+ bool CBPROC_RECEIVE(cback_data) = 1;
+ void CBPROC_FINISH(void) = 2;
+ void CBPROC_ERROR(nis_error) = 3;
+ } = 1;
+} = 100302;
diff --git a/cpukit/librpc/include/rpcsvc/nis_db.h b/cpukit/librpc/include/rpcsvc/nis_db.h
new file mode 100644
index 0000000000..dbdee5aac8
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nis_db.h
@@ -0,0 +1,162 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ *
+ * $FreeBSD: src/include/rpcsvc/nis_db.h,v 1.5 1999/08/27 23:45:09 peter Exp $
+ */
+
+/*
+ * Copyright (c) 1991, by Sun Microsystems Inc.
+ */
+
+/*
+ * This header file defines the interface to the NIS database. All
+ * implementations of the database must export at least these routines.
+ * They must also follow the conventions set herein. See the implementors
+ * guide for specific semantics that are required.
+ */
+
+#ifndef _RPCSVC_NIS_DB_H
+#define _RPCSVC_NIS_DB_H
+
+
+/* From: #pragma ident "@(#)nis_db.h 1.8 94/05/03 SMI" */
+
+/*
+ * Note: although the version of <rpcsvc/nis_db.h> shipped with Solaris
+ * 2.5/2.5.x is actually older than this one (according to the ident
+ * string), it contains changes and a few added functions. Those changes
+ * have been hand merged into this file to bring it up to date.
+ */
+
+#include <rpc/rpc.h>
+#include <rpcsvc/nis.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum db_status {
+ DB_SUCCESS = 0,
+ DB_NOTFOUND = 1,
+ DB_NOTUNIQUE = 2,
+ DB_BADTABLE = 3,
+ DB_BADQUERY = 4,
+ DB_BADOBJECT = 5,
+ DB_MEMORY_LIMIT = 6,
+ DB_STORAGE_LIMIT = 7,
+ DB_INTERNAL_ERROR = 8
+};
+typedef enum db_status db_status;
+
+enum db_action {
+ DB_LOOKUP = 0,
+ DB_REMOVE = 1,
+ DB_ADD = 2,
+ DB_FIRST = 3,
+ DB_NEXT = 4,
+ DB_ALL = 5,
+ DB_RESET_NEXT = 6
+};
+typedef enum db_action db_action;
+
+typedef entry_obj *entry_object_p;
+
+typedef struct {
+ u_int db_next_desc_len;
+ char *db_next_desc_val;
+} db_next_desc;
+
+struct db_result {
+ db_status status;
+ db_next_desc nextinfo;
+ struct {
+ u_int objects_len;
+ entry_object_p *objects_val;
+ } objects;
+ long ticks;
+};
+typedef struct db_result db_result;
+
+/*
+ * Prototypes for the database functions.
+ */
+
+#if (__STDC__)
+
+extern bool_t db_initialize(char *);
+#ifdef ORIGINAL_DECLS
+extern bool_t db_create_table(char *, table_obj *);
+extern bool_t db_destroy_table(char *);
+#else
+extern db_status db_create_table(char *, table_obj *);
+extern db_status db_destroy_table(char *);
+#endif
+extern db_result *db_first_entry(char *, int, nis_attr *);
+extern db_result *db_next_entry(char *, db_next_desc *);
+extern db_result *db_reset_next_entry(char *, db_next_desc *);
+extern db_result *db_list_entries(char *, int, nis_attr *);
+extern db_result *db_add_entry(char *, int, nis_attr *, entry_obj *);
+extern db_result *db_remove_entry(char *, int, nis_attr *);
+extern db_status db_checkpoint(char *);
+extern db_status db_standby(char *);
+#ifndef ORIGINAL_DECLS
+extern db_status db_table_exists(char *);
+extern db_status db_unload_table(char *);
+extern void db_free_result(db_result *);
+#endif
+
+#else /* Non-prototype definitions */
+
+extern bool_t db_initialize();
+#ifdef ORIGINAL_DECLS
+extern bool_t db_create_table();
+extern bool_t db_destroy_table();
+#else
+extern db_status db_create_table();
+extern db_status db_destroy_table();
+#endif
+extern db_result *db_first_entry();
+extern db_result *db_next_entry();
+extern db_result *db_reset_next_entry();
+extern db_result *db_list_entries();
+extern db_result *db_add_entry();
+extern db_result *db_remove_entry();
+extern db_status db_checkpoint();
+extern db_status db_standby();
+#ifndef ORIGINAL_DECLS
+extern db_status db_table_exists();
+extern db_status db_unload_table();
+extern void db_free_result();
+#endif
+#endif /* __STDC__ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RPCSVC_NIS_DB_H */
diff --git a/cpukit/librpc/include/rpcsvc/nis_object.x b/cpukit/librpc/include/rpcsvc/nis_object.x
new file mode 100644
index 0000000000..3156724f1b
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nis_object.x
@@ -0,0 +1,317 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user or with the express written consent of
+% * Sun Microsystems, Inc.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+
+/*
+ * nis_object.x
+ *
+ * Copyright (c) 1988-1992 Sun Microsystems Inc
+ * All Rights Reserved.
+ */
+
+/* From: %#pragma ident "@(#)nis_object.x 1.10 94/05/03 SMI" */
+
+#if RPC_HDR
+%
+%#ifndef __nis_object_h
+%#define __nis_object_h
+%
+#endif
+/*
+ * This file defines the format for a NIS object in RPC language.
+ * It is included by the main .x file and the database access protocol
+ * file. It is common because both of them need to deal with the same
+ * type of object. Generating the actual code though is a bit messy because
+ * the nis.x file and the nis_dba.x file will generate xdr routines to
+ * encode/decode objects when only one set is needed. Such is life when
+ * one is using rpcgen.
+ *
+ * Note, the protocol doesn't specify any limits on such things as
+ * maximum name length, number of attributes, etc. These are enforced
+ * by the database backend. When you hit them you will no. Also see
+ * the db_getlimits() function for fetching the limit values.
+ *
+ */
+
+/* Some manifest constants, chosen to maximize flexibility without
+ * plugging the wire full of data.
+ */
+const NIS_MAXSTRINGLEN = 255;
+const NIS_MAXNAMELEN = 1024;
+const NIS_MAXATTRNAME = 32;
+const NIS_MAXATTRVAL = 2048;
+const NIS_MAXCOLUMNS = 64;
+const NIS_MAXATTR = 16;
+const NIS_MAXPATH = 1024;
+const NIS_MAXREPLICAS = 128;
+const NIS_MAXLINKS = 16;
+
+const NIS_PK_NONE = 0; /* no public key (unix/sys auth) */
+const NIS_PK_DH = 1; /* Public key is Diffie-Hellman type */
+const NIS_PK_RSA = 2; /* Public key if RSA type */
+const NIS_PK_KERB = 3; /* Use kerberos style authentication */
+
+/*
+ * The fundamental name type of NIS. The name may consist of two parts,
+ * the first being the fully qualified name, and the second being an
+ * optional set of attribute/value pairs.
+ */
+struct nis_attr {
+ string zattr_ndx<>; /* name of the index */
+ opaque zattr_val<>; /* Value for the attribute. */
+};
+
+typedef string nis_name<>; /* The NIS name itself. */
+
+/* NIS object types are defined by the following enumeration. The numbers
+ * they use are based on the following scheme :
+ * 0 - 1023 are reserved for Sun,
+ * 1024 - 2047 are defined to be private to a particular tree.
+ * 2048 - 4095 are defined to be user defined.
+ * 4096 - ... are reserved for future use.
+ */
+
+enum zotypes {
+ BOGUS_OBJ = 0, /* Uninitialized object structure */
+ NO_OBJ = 1, /* NULL object (no data) */
+ DIRECTORY_OBJ = 2, /* Directory object describing domain */
+ GROUP_OBJ = 3, /* Group object (a list of names) */
+ TABLE_OBJ = 4, /* Table object (a database schema) */
+ ENTRY_OBJ = 5, /* Entry object (a database record) */
+ LINK_OBJ = 6, /* A name link. */
+ PRIVATE_OBJ = 7 /* Private object (all opaque data) */
+};
+
+/*
+ * The types of Name services NIS knows about. They are enumerated
+ * here. The Binder code will use this type to determine if it has
+ * a set of library routines that will access the indicated name service.
+ */
+enum nstype {
+ UNKNOWN = 0,
+ NIS = 1, /* Nis Plus Service */
+ SUNYP = 2, /* Old NIS Service */
+ IVY = 3, /* Nis Plus Plus Service */
+ DNS = 4, /* Domain Name Service */
+ X500 = 5, /* ISO/CCCIT X.500 Service */
+ DNANS = 6, /* Digital DECNet Name Service */
+ XCHS = 7, /* Xerox ClearingHouse Service */
+ CDS= 8
+};
+
+/*
+ * DIRECTORY - The name service object. These objects identify other name
+ * servers that are serving some portion of the name space. Each has a
+ * type associated with it. The resolver library will note whether or not
+ * is has the needed routines to access that type of service.
+ * The oarmask structure defines an access rights mask on a per object
+ * type basis for the name spaces. The only bits currently used are
+ * create and destroy. By enabling or disabling these access rights for
+ * a specific object type for a one of the accessor entities (owner,
+ * group, world) the administrator can control what types of objects
+ * may be freely added to the name space and which require the
+ * administrator's approval.
+ */
+struct oar_mask {
+ u_long oa_rights; /* Access rights mask */
+ zotypes oa_otype; /* Object type */
+};
+
+struct endpoint {
+ string uaddr<>;
+ string family<>; /* Transport family (INET, OSI, etc) */
+ string proto<>; /* Protocol (TCP, UDP, CLNP, etc) */
+};
+
+/*
+ * Note: pkey is a netobj which is limited to 1024 bytes which limits the
+ * keysize to 8192 bits. This is consider to be a reasonable limit for
+ * the expected lifetime of this service.
+ */
+struct nis_server {
+ nis_name name; /* Principal name of the server */
+ endpoint ep<>; /* Universal addr(s) for server */
+ u_long key_type; /* Public key type */
+ netobj pkey; /* server's public key */
+};
+
+struct directory_obj {
+ nis_name do_name; /* Name of the directory being served */
+ nstype do_type; /* one of NIS, DNS, IVY, YP, or X.500 */
+ nis_server do_servers<>; /* <0> == Primary name server */
+ u_long do_ttl; /* Time To Live (for caches) */
+ oar_mask do_armask<>; /* Create/Destroy rights by object type */
+};
+
+/*
+ * ENTRY - This is one row of data from an information base.
+ * The type value is used by the client library to convert the entry to
+ * it's internal structure representation. The Table name is a back pointer
+ * to the table where the entry is stored. This allows the client library
+ * to determine where to send a request if the client wishes to change this
+ * entry but got to it through a LINK rather than directly.
+ * If the entry is a "standalone" entry then this field is void.
+ */
+const EN_BINARY = 1; /* Indicates value is binary data */
+const EN_CRYPT = 2; /* Indicates the value is encrypted */
+const EN_XDR = 4; /* Indicates the value is XDR encoded */
+const EN_MODIFIED = 8; /* Indicates entry is modified. */
+const EN_ASN1 = 64; /* Means contents use ASN.1 encoding */
+
+struct entry_col {
+ u_long ec_flags; /* Flags for this value */
+ opaque ec_value<>; /* It's textual value */
+};
+
+struct entry_obj {
+ string en_type<>; /* Type of entry such as "passwd" */
+ entry_col en_cols<>; /* Value for the entry */
+};
+
+/*
+ * GROUP - The group object contains a list of NIS principal names. Groups
+ * are used to authorize principals. Each object has a set of access rights
+ * for members of its group. Principal names in groups are in the form
+ * name.directory and recursive groups are expressed as @groupname.directory
+ */
+struct group_obj {
+ u_long gr_flags; /* Flags controlling group */
+ nis_name gr_members<>; /* List of names in group */
+};
+
+/*
+ * LINK - This is the LINK object. It is quite similar to a symbolic link
+ * in the UNIX filesystem. The attributes in the main object structure are
+ * relative to the LINK data and not what it points to (like the file system)
+ * "modify" privleges here indicate the right to modify what the link points
+ * at and not to modify that actual object pointed to by the link.
+ */
+struct link_obj {
+ zotypes li_rtype; /* Real type of the object */
+ nis_attr li_attrs<>; /* Attribute/Values for tables */
+ nis_name li_name; /* The object's real NIS name */
+};
+
+/*
+ * TABLE - This is the table object. It implements a simple
+ * data base that applications and use for configuration or
+ * administration purposes. The role of the table is to group together
+ * a set of related entries. Tables are the simple database component
+ * of NIS. Like many databases, tables are logically divided into columns
+ * and rows. The columns are labeled with indexes and each ENTRY makes
+ * up a row. Rows may be addressed within the table by selecting one
+ * or more indexes, and values for those indexes. Each row which has
+ * a value for the given index that matches the desired value is returned.
+ * Within the definition of each column there is a flags variable, this
+ * variable contains flags which determine whether or not the column is
+ * searchable, contains binary data, and access rights for the entry objects
+ * column value.
+ */
+
+const TA_BINARY = 1; /* Means table data is binary */
+const TA_CRYPT = 2; /* Means value should be encrypted */
+const TA_XDR = 4; /* Means value is XDR encoded */
+const TA_SEARCHABLE = 8; /* Means this column is searchable */
+const TA_CASE = 16; /* Means this column is Case Sensitive */
+const TA_MODIFIED = 32; /* Means this columns attrs are modified*/
+const TA_ASN1 = 64; /* Means contents use ASN.1 encoding */
+
+struct table_col {
+ string tc_name<64>; /* Column Name */
+ u_long tc_flags; /* control flags */
+ u_long tc_rights; /* Access rights mask */
+};
+
+struct table_obj {
+ string ta_type<64>; /* Table type such as "passwd" */
+ int ta_maxcol; /* Total number of columns */
+ u_char ta_sep; /* Separator character */
+ table_col ta_cols<>; /* The number of table indexes */
+ string ta_path<>; /* A search path for this table */
+};
+
+/*
+ * This union joins together all of the currently known objects.
+ */
+union objdata switch (zotypes zo_type) {
+ case DIRECTORY_OBJ :
+ struct directory_obj di_data;
+ case GROUP_OBJ :
+ struct group_obj gr_data;
+ case TABLE_OBJ :
+ struct table_obj ta_data;
+ case ENTRY_OBJ:
+ struct entry_obj en_data;
+ case LINK_OBJ :
+ struct link_obj li_data;
+ case PRIVATE_OBJ :
+ opaque po_data<>;
+ case NO_OBJ :
+ void;
+ case BOGUS_OBJ :
+ void;
+ default :
+ void;
+};
+
+/*
+ * This is the basic NIS object data type. It consists of a generic part
+ * which all objects contain, and a specialized part which varies depending
+ * on the type of the object. All of the specialized sections have been
+ * described above. You might have wondered why they all start with an
+ * integer size, followed by the useful data. The answer is, when the
+ * server doesn't recognize the type returned it treats it as opaque data.
+ * And the definition for opaque data is {int size; char *data;}. In this
+ * way, servers and utility routines that do not understand a given type
+ * may still pass it around. One has to be careful in setting
+ * this variable accurately, it must take into account such things as
+ * XDR padding of structures etc. The best way to set it is to note one's
+ * position in the XDR encoding stream, encode the structure, look at the
+ * new position and calculate the size.
+ */
+struct nis_oid {
+ u_long ctime; /* Time of objects creation */
+ u_long mtime; /* Time of objects modification */
+};
+
+struct nis_object {
+ nis_oid zo_oid; /* object identity verifier. */
+ nis_name zo_name; /* The NIS name for this object */
+ nis_name zo_owner; /* NIS name of object owner. */
+ nis_name zo_group; /* NIS name of access group. */
+ nis_name zo_domain; /* The administrator for the object */
+ u_long zo_access; /* Access rights (owner, group, world) */
+ u_long zo_ttl; /* Object's time to live in seconds. */
+ objdata zo_data; /* Data structure for this type */
+};
+#if RPC_HDR
+%
+%#endif /* if __nis_object_h */
+%
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/nis_tags.h b/cpukit/librpc/include/rpcsvc/nis_tags.h
new file mode 100644
index 0000000000..0eaee6d442
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nis_tags.h
@@ -0,0 +1,137 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Copyright (c) 1991, Sun Microsystems Inc.
+ */
+
+/*
+ * nis_tags.h
+ *
+ * This file contains the tags and statistics definitions. It is
+ * automatically included by nis.h
+ */
+
+#ifndef _RPCSVC_NIS_TAGS_H
+#define _RPCSVC_NIS_TAGS_H
+
+/* From: #pragma ident "@(#)nis_tags.h 1.10 94/05/03 SMI" */
+/* from file: zns_tags.h 1.7 Copyright (c) 1990 Sun Microsystems */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef ORIGINAL_DECLS
+#define NIS_DIR "data"
+#endif
+
+/* Lookup and List function flags */
+#define FOLLOW_LINKS (1<<0) /* Follow link objects */
+#define FOLLOW_PATH (1<<1) /* Follow the path in a table */
+#define HARD_LOOKUP (1<<2) /* Block until successful */
+#define ALL_RESULTS (1<<3) /* Retrieve all results */
+#define NO_CACHE (1<<4) /* Do not return 'cached' results */
+#define MASTER_ONLY (1<<5) /* Get value only from master server */
+#define EXPAND_NAME (1<<6) /* Expand partitially qualified names */
+
+/* Semantic modification for table operations flags */
+#define RETURN_RESULT (1<<7) /* Return resulting object to client */
+#define ADD_OVERWRITE (1<<8) /* Allow overwrites on ADD */
+#define REM_MULTIPLE (1<<9) /* Allow wildcard deletes */
+#define MOD_SAMEOBJ (1<<10) /* Check modified object before write */
+#define ADD_RESERVED (1<<11) /* Spare ADD semantic */
+#define REM_RESERVED (1<<12) /* Spare REM semantic */
+#ifdef ORIGINAL_DECLS
+#define MOD_RESERVED (1<<13) /* Spare MOD semantic */
+#else
+#define MOD_EXCLUSIVE (1<<13) /* Modify no overwrite on modified keys */
+#endif
+
+/* Transport specific modifications to the operation */
+#define USE_DGRAM (1<<16) /* Use a datagram transport */
+#define NO_AUTHINFO (1<<17) /* Don't bother attaching auth info */
+
+/*
+ * Declarations for "standard" NIS+ tags
+ * State variable tags have values 0 - 2047
+ * Statistic tags have values 2048 - 65535
+ * User Tags have values >2^16
+ */
+#define TAG_DEBUG 1 /* set debug level */
+#define TAG_STATS 2 /* Enable/disable statistics */
+#define TAG_GCACHE 3 /* Flush the Group Cache */
+#ifndef ORIGINAL_DECLS
+#define TAG_GCACHE_ALL TAG_GCACHE
+#endif
+#define TAG_DCACHE 4 /* Flush the directory cache */
+#ifndef ORIGINAL_DECLS
+#define TAG_DCACHE_ONE TAG_DCACHE
+#endif
+#define TAG_OCACHE 5 /* Flush the Object Cache */
+#define TAG_SECURE 6 /* Set the security level */
+#ifndef ORIGINAL_DECLS
+#define TAG_TCACHE_ONE 7 /* Flush the table cache */
+#define TAG_DCACHE_ALL 8 /* Flush entire directory cache */
+#define TAG_TCACHE_ALL 9 /* Flush entire table cache */
+#define TAG_GCACHE_ONE 10 /* Flush one group object */
+#define TAG_DCACHE_ONE_REFRESH 11 /* Flush and refresh one DO */
+#endif
+
+#define TAG_OPSTATS 2048 /* NIS+ operations statistics */
+#define TAG_THREADS 2049 /* Child process/thread status */
+#define TAG_HEAP 2050 /* Heap usage statistics */
+#define TAG_UPDATES 2051 /* Updates to this service */
+#define TAG_VISIBLE 2052 /* First update that isn't replicated */
+#define TAG_S_DCACHE 2053 /* Directory cache statistics */
+#define TAG_S_OCACHE 2054 /* Object cache statistics */
+#define TAG_S_GCACHE 2055 /* Group cache statistics */
+#define TAG_S_STORAGE 2056 /* Group cache statistics */
+#define TAG_UPTIME 2057 /* Time that server has been up */
+#ifndef ORIGINAL_DECLS
+#define TAG_DIRLIST 2058 /* Dir served by this server */
+#define TAG_NISCOMPAT 2059 /* Whether supports NIS compat mode */
+#define TAG_DNSFORWARDING 2060 /* Whether DNS forwarding supported*/
+#define TAG_SECURITY_LEVEL 2061 /* Security level of the server */
+#define TAG_ROOTSERVER 2062 /* Whether root server */
+#endif
+
+/*
+ * Declarations for the Group object flags. Currently
+ * there are only 3.
+ */
+#define IMPMEM_GROUPS 1 /* Implicit Membership allowed */
+#define RECURS_GROUPS 2 /* Recursive Groups allowed */
+#define NEGMEM_GROUPS 4 /* Negative Groups allowed */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RPCSVC_NIS_TAGS_H */
diff --git a/cpukit/librpc/include/rpcsvc/nislib.h b/cpukit/librpc/include/rpcsvc/nislib.h
new file mode 100644
index 0000000000..9f874d270e
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nislib.h
@@ -0,0 +1,317 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Copyright (c) 1991, Sun Microsystems Inc.
+ */
+
+/*
+ * This file contains the interfaces that are visible in the SunOS 5.x
+ * implementation of NIS Plus. When using C++ the defined __cplusplus and
+ * __STDC__ should both be true.
+ */
+
+#ifndef _RPCSVC_NISLIB_H
+#define _RPCSVC_NISLIB_H
+
+/* From: #pragma ident "@(#)nislib.h 1.16 94/05/03 SMI" */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct signature {
+ int signature_len;
+ char *signature_val;
+};
+
+#ifdef __STDC__
+extern void nis_freeresult(nis_result *);
+extern nis_result * nis_lookup(nis_name, u_long);
+extern nis_result * nis_list(nis_name, u_long,
+ int (*)(nis_name, nis_object *, void *), void *);
+extern nis_result * nis_add(nis_name, nis_object *);
+extern nis_result * nis_remove(nis_name, nis_object *);
+extern nis_result * nis_modify(nis_name, nis_object *);
+
+extern nis_result * nis_add_entry(nis_name, nis_object *, u_long);
+extern nis_result * nis_remove_entry(nis_name, nis_object *, u_long);
+extern nis_result * nis_modify_entry(nis_name, nis_object *, u_long);
+extern nis_result * nis_first_entry(nis_name);
+extern nis_result * nis_next_entry(nis_name, netobj *);
+
+extern nis_error nis_mkdir(nis_name, nis_server *);
+extern nis_error nis_rmdir(nis_name, nis_server *);
+extern name_pos nis_dir_cmp(nis_name, nis_name);
+
+extern nis_name * nis_getnames(nis_name);
+extern void nis_freenames(nis_name *);
+extern nis_name nis_domain_of(nis_name);
+extern nis_name nis_leaf_of(nis_name);
+extern nis_name nis_leaf_of_r(const nis_name, char *, size_t);
+extern nis_name nis_name_of(nis_name);
+extern nis_name nis_local_group(void);
+extern nis_name nis_local_directory(void);
+extern nis_name nis_local_principal(void);
+extern nis_name nis_local_host(void);
+
+extern void nis_destroy_object(nis_object *);
+extern nis_object * nis_clone_object(nis_object *, nis_object *);
+extern void nis_print_object(nis_object *);
+
+extern char * nis_sperrno(nis_error);
+extern void nis_perror(nis_error, char *);
+extern char * nis_sperror(nis_error, char *);
+extern void nis_lerror(nis_error, char *);
+
+extern void nis_print_group_entry(nis_name);
+extern bool_t nis_ismember(nis_name, nis_name);
+extern nis_error nis_creategroup(nis_name, u_long);
+extern nis_error nis_destroygroup(nis_name);
+extern nis_error nis_addmember(nis_name, nis_name);
+extern nis_error nis_removemember(nis_name, nis_name);
+extern nis_error nis_verifygroup(nis_name);
+
+extern void nis_freeservlist(nis_server **);
+extern nis_server ** nis_getservlist(nis_name);
+extern nis_error nis_stats(nis_server *, nis_tag *, int, nis_tag **);
+extern nis_error nis_servstate(nis_server *, nis_tag *, int, nis_tag **);
+extern void nis_freetags(nis_tag *, int);
+
+extern nis_result * nis_checkpoint(nis_name);
+extern void nis_ping(nis_name, u_long, nis_object *);
+
+/*
+ * XXX: PLEASE NOTE THAT THE FOLLOWING FUNCTIONS ARE INTERNAL
+ * TO NIS+ AND SHOULD NOT BE USED BY ANY APPLICATION PROGRAM.
+ * THEIR SEMANTICS AND/OR SIGNATURE CAN CHANGE WITHOUT NOTICE.
+ * SO, PLEASE DO NOT USE THEM. YOU ARE WARNED!!!!
+ */
+
+extern char ** __break_name(nis_name, int *);
+extern int __name_distance(char **, char **);
+extern nis_result * nis_make_error(nis_error, u_long, u_long, u_long, u_long);
+extern nis_attr * __cvt2attr(int *, char **);
+extern void nis_free_request(ib_request *);
+extern nis_error nis_get_request(nis_name, nis_object *, netobj*, ib_request*);
+extern nis_object * nis_read_obj(char *);
+extern int nis_write_obj(char *, nis_object *);
+extern int nis_in_table(nis_name, NIS_HASH_TABLE *, int *);
+extern int nis_insert_item(NIS_HASH_ITEM *, NIS_HASH_TABLE *);
+extern NIS_HASH_ITEM * nis_find_item(nis_name, NIS_HASH_TABLE *);
+extern NIS_HASH_ITEM * nis_remove_item(nis_name, NIS_HASH_TABLE *);
+extern void nis_insert_name(nis_name, NIS_HASH_TABLE *);
+extern void nis_remove_name(nis_name, NIS_HASH_TABLE *);
+extern CLIENT * nis_make_rpchandle(nis_server *, int, u_long, u_long, u_long,
+ int, int);
+extern void * nis_get_static_storage(struct nis_sdata *, u_long, u_long);
+extern char * nis_data(char *);
+extern void nis_print_rights(u_long);
+extern void nis_print_directory(directory_obj *);
+extern void nis_print_group(group_obj *);
+extern void nis_print_table(table_obj *);
+extern void nis_print_link(link_obj *);
+extern void nis_print_entry(entry_obj *);
+extern nis_object * nis_get_object(char *, char *, char *, u_long, u_long,
+ zotypes);
+extern nis_server * __nis_init_callback(CLIENT *,
+ int (*)(nis_name, nis_object *, void *), void *);
+extern int nis_getdtblsize(void);
+extern int __nis_run_callback(netobj *, u_long, struct timeval *, CLIENT *);
+
+extern log_result *nis_dumplog(nis_server *, nis_name, u_long);
+extern log_result *nis_dump(nis_server *, nis_name,
+ int (*)(nis_name, nis_object *, void *));
+
+extern bool_t __do_ismember(nis_name, nis_name,
+ nis_result *(*)(nis_name, u_long));
+extern nis_name __nis_map_group(nis_name);
+extern nis_name __nis_map_group_r(nis_name, char*, size_t);
+
+extern nis_error __nis_CacheBind(char *, directory_obj *);
+extern nis_error __nis_CacheSearch(char *, directory_obj *);
+extern bool_t __nis_CacheRemoveEntry(directory_obj *);
+extern void __nis_CacheRestart(void);
+extern void __nis_CachePrint(void);
+extern void __nis_CacheDumpStatistics(void);
+extern bool_t writeColdStartFile(directory_obj *);
+
+extern CLIENT * __get_ti_clnt(char *, CLIENT *, char **, pid_t *);
+extern int __strcmp_case_insens(char *, char *);
+extern int __strncmp_case_insens(char *, char *);
+
+extern fd_result * nis_finddirectory(directory_obj *, nis_name);
+extern int __start_clock(int);
+extern u_long __stop_clock(int);
+
+/*
+ * This particular function is part of the FreeBSD NIS+ implementation
+ * only. Ideally it should be somewhere else, but it is used by both
+ * rpc.nisd and nis_cachemgr, and there aren't that many headers common
+ * to both programs.
+ */
+
+extern struct signature *__nis_calculate_encrypted_cksum(unsigned char *, unsigned int, char *, int);
+
+#else
+
+/* Non-prototype definitions (old fashioned C) */
+
+extern void nis_freeresult();
+extern nis_result * nis_lookup();
+extern nis_result * nis_list();
+extern nis_result * nis_add();
+extern nis_result * nis_remove();
+extern nis_result * nis_modify();
+
+extern nis_result * nis_add_entry();
+extern nis_result * nis_remove_entry();
+extern nis_result * nis_modify_entry();
+extern nis_result * nis_first_entry();
+extern nis_result * nis_next_entry();
+
+extern nis_error nis_mkdir();
+extern nis_error nis_rmdir();
+extern name_pos nis_dir_cmp();
+
+extern nis_name *nis_getnames();
+extern void nis_freenames();
+extern nis_name nis_domain_of();
+extern nis_name nis_leaf_of();
+extern nis_name nis_leaf_of_r();
+extern nis_name nis_name_of();
+extern nis_name nis_local_group();
+extern nis_name nis_local_directory();
+extern nis_name nis_local_principal();
+extern nis_name nis_local_host();
+
+extern void nis_destroy_object();
+extern nis_object * nis_clone_object();
+extern void nis_print_object();
+
+extern char * nis_sperrno();
+extern void nis_perror();
+extern char * nis_sperror();
+extern void nis_lerror();
+
+extern void nis_print_group_entry();
+extern bool_t nis_ismember();
+extern nis_error nis_creategroup();
+extern nis_error nis_destroygroup();
+extern nis_error nis_addmember();
+extern nis_error nis_removemember();
+extern nis_error nis_verifygroup();
+
+extern void nis_freeservlist();
+extern nis_server ** nis_getservlist();
+extern nis_error nis_stats();
+extern nis_error nis_servstate();
+extern void nis_freetags();
+
+extern nis_result * nis_checkpoint();
+extern void nis_ping();
+
+/*
+ * XXX: PLEASE NOTE THAT THE FOLLOWING FUNCTIONS ARE INTERNAL
+ * TO NIS+ AND SHOULD NOT BE USED BY ANY APPLICATION PROGRAM.
+ * THEIR SEMANTICS AND/OR SIGNATURE CAN CHANGE WITHOUT NOTICE.
+ * SO, PLEASE DO NOT USE THEM. YOU ARE WARNED!!!!
+ */
+extern char ** __break_name();
+extern int __name_distance();
+extern nis_result * nis_make_error();
+extern nis_attr * __cvt2attr();
+extern void nis_free_request();
+extern nis_error nis_get_request();
+extern nis_object * nis_read_obj();
+extern int nis_write_obj();
+extern int nis_in_table();
+extern int nis_insert_item();
+extern NIS_HASH_ITEM * nis_find_item();
+extern NIS_HASH_ITEM * nis_remove_item();
+extern void nis_insert_name();
+extern void nis_remove_name();
+extern CLIENT * nis_make_rpchandle();
+extern void * nis_get_static_storage();
+extern char * nis_data();
+
+extern void nis_print_rights();
+extern void nis_print_directory();
+extern void nis_print_group();
+extern void nis_print_table();
+extern void nis_print_link();
+extern void nis_print_entry();
+extern nis_object * nis_get_object();
+
+extern nis_server * __nis_init_callback();
+extern int nis_getdtblsize();
+extern int __nis_run_callback();
+
+extern log_result * nis_dump();
+extern log_result * nis_dumplog();
+
+extern bool_t __do_ismember();
+extern nis_name __nis_map_group();
+extern nis_name __nis_map_group_r();
+
+
+extern nis_error __nis_CacheBind();
+extern directory_obj * __nis_CacheSearch();
+extern bool_t __nis_CacheRemoveEntry();
+extern void __nis_CacheRestart();
+extern void __nis_CachePrint();
+extern void __nis_CacheDumpStatistics();
+extern bool_t writeColdStartFile();
+
+extern CLIENT * __get_ti_clnt();
+extern int __strcmp_case_insens();
+extern int __strncmp_case_insens();
+
+extern fd_result * nis_finddirectory();
+extern int __start_clock();
+extern u_long __stop_clock();
+
+/*
+ * This particular function is part of the FreeBSD NIS+ implementation
+ * only. Ideally it should be somewhere else, but it is used by both
+ * rpc.nisd and nis_cachemgr, and there aren't that many headers common
+ * to both programs.
+ */
+
+extern struct signature *__nis_calculate_encrypted_cksum();
+
+#endif
+
+#define NUL '\0'
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RPCSVC_NISLIB_H */
diff --git a/cpukit/librpc/include/rpcsvc/nlm_prot.x b/cpukit/librpc/include/rpcsvc/nlm_prot.x
new file mode 100644
index 0000000000..fdc6d6ea96
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/nlm_prot.x
@@ -0,0 +1,183 @@
+/* @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC */
+/* @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro */
+
+/*
+ * Network lock manager protocol definition
+ * Copyright (C) 1986 Sun Microsystems, Inc.
+ *
+ * protocol used between local lock manager and remote lock manager
+ */
+
+#ifdef RPC_HDR
+%#define LM_MAXSTRLEN 1024
+%#define MAXNAMELEN LM_MAXSTRLEN+1
+#else
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/nlm_prot.x,v 1.8 1999/08/27 23:45:10 peter Exp $";
+%#endif /* not lint */
+#endif
+
+/*
+ * status of a call to the lock manager
+ */
+enum nlm_stats {
+ nlm_granted = 0,
+ nlm_denied = 1,
+ nlm_denied_nolocks = 2,
+ nlm_blocked = 3,
+ nlm_denied_grace_period = 4
+};
+
+struct nlm_holder {
+ bool exclusive;
+ int svid;
+ netobj oh;
+ unsigned l_offset;
+ unsigned l_len;
+};
+
+union nlm_testrply switch (nlm_stats stat) {
+ case nlm_denied:
+ struct nlm_holder holder;
+ default:
+ void;
+};
+
+struct nlm_stat {
+ nlm_stats stat;
+};
+
+struct nlm_res {
+ netobj cookie;
+ nlm_stat stat;
+};
+
+struct nlm_testres {
+ netobj cookie;
+ nlm_testrply stat;
+};
+
+struct nlm_lock {
+ string caller_name<LM_MAXSTRLEN>;
+ netobj fh; /* identify a file */
+ netobj oh; /* identify owner of a lock */
+ int svid; /* generated from pid for svid */
+ unsigned l_offset;
+ unsigned l_len;
+};
+
+struct nlm_lockargs {
+ netobj cookie;
+ bool block;
+ bool exclusive;
+ struct nlm_lock alock;
+ bool reclaim; /* used for recovering locks */
+ int state; /* specify local status monitor state */
+};
+
+struct nlm_cancargs {
+ netobj cookie;
+ bool block;
+ bool exclusive;
+ struct nlm_lock alock;
+};
+
+struct nlm_testargs {
+ netobj cookie;
+ bool exclusive;
+ struct nlm_lock alock;
+};
+
+struct nlm_unlockargs {
+ netobj cookie;
+ struct nlm_lock alock;
+};
+
+
+#ifdef RPC_HDR
+%/*
+% * The following enums are actually bit encoded for efficient
+% * boolean algebra.... DON'T change them.....
+% */
+#endif
+enum fsh_mode {
+ fsm_DN = 0, /* deny none */
+ fsm_DR = 1, /* deny read */
+ fsm_DW = 2, /* deny write */
+ fsm_DRW = 3 /* deny read/write */
+};
+
+enum fsh_access {
+ fsa_NONE = 0, /* for completeness */
+ fsa_R = 1, /* read only */
+ fsa_W = 2, /* write only */
+ fsa_RW = 3 /* read/write */
+};
+
+struct nlm_share {
+ string caller_name<LM_MAXSTRLEN>;
+ netobj fh;
+ netobj oh;
+ fsh_mode mode;
+ fsh_access access;
+};
+
+struct nlm_shareargs {
+ netobj cookie;
+ nlm_share share;
+ bool reclaim;
+};
+
+struct nlm_shareres {
+ netobj cookie;
+ nlm_stats stat;
+ int sequence;
+};
+
+struct nlm_notify {
+ string name<MAXNAMELEN>;
+ long state;
+};
+
+/*
+ * Over-the-wire protocol used between the network lock managers
+ */
+
+program NLM_PROG {
+ version NLM_VERS {
+
+ nlm_testres NLM_TEST(struct nlm_testargs) = 1;
+
+ nlm_res NLM_LOCK(struct nlm_lockargs) = 2;
+
+ nlm_res NLM_CANCEL(struct nlm_cancargs) = 3;
+ nlm_res NLM_UNLOCK(struct nlm_unlockargs) = 4;
+
+ /*
+ * remote lock manager call-back to grant lock
+ */
+ nlm_res NLM_GRANTED(struct nlm_testargs)= 5;
+ /*
+ * message passing style of requesting lock
+ */
+ void NLM_TEST_MSG(struct nlm_testargs) = 6;
+ void NLM_LOCK_MSG(struct nlm_lockargs) = 7;
+ void NLM_CANCEL_MSG(struct nlm_cancargs) =8;
+ void NLM_UNLOCK_MSG(struct nlm_unlockargs) = 9;
+ void NLM_GRANTED_MSG(struct nlm_testargs) = 10;
+ void NLM_TEST_RES(nlm_testres) = 11;
+ void NLM_LOCK_RES(nlm_res) = 12;
+ void NLM_CANCEL_RES(nlm_res) = 13;
+ void NLM_UNLOCK_RES(nlm_res) = 14;
+ void NLM_GRANTED_RES(nlm_res) = 15;
+ } = 1;
+
+ version NLM_VERSX {
+ nlm_shareres NLM_SHARE(nlm_shareargs) = 20;
+ nlm_shareres NLM_UNSHARE(nlm_shareargs) = 21;
+ nlm_res NLM_NM_LOCK(nlm_lockargs) = 22;
+ void NLM_FREE_ALL(nlm_notify) = 23;
+ } = 3;
+
+} = 100021;
diff --git a/cpukit/librpc/include/rpcsvc/pmap_prot.x b/cpukit/librpc/include/rpcsvc/pmap_prot.x
new file mode 100644
index 0000000000..2e9c089484
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/pmap_prot.x
@@ -0,0 +1,284 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+%/*
+% * Copyright (c) 1984,1989 by Sun Microsystems, Inc.
+% */
+
+%/* from pmap_prot.x */
+
+#ifdef RPC_HDR
+%
+%#pragma ident "@(#)pmap_prot.x 1.6 94/04/29 SMI"
+%
+%#ifndef _KERNEL
+%
+#endif
+
+/*
+ * Port Mapper Protocol Specification (in RPC Language)
+ * derived from RFC 1057
+ */
+
+%/*
+% * Protocol for the local binder service, or pmap.
+% *
+% * Copyright (C) 1984, Sun Microsystems, Inc.
+% *
+% * The following procedures are supported by the protocol:
+% *
+% * PMAPPROC_NULL() returns ()
+% * takes nothing, returns nothing
+% *
+% * PMAPPROC_SET(struct pmap) returns (bool_t)
+% * TRUE is success, FALSE is failure. Registers the tuple
+% * [prog, vers, prot, port].
+% *
+% * PMAPPROC_UNSET(struct pmap) returns (bool_t)
+% * TRUE is success, FALSE is failure. Un-registers pair
+% * [prog, vers]. prot and port are ignored.
+% *
+% * PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
+% * 0 is failure. Otherwise returns the port number where the pair
+% * [prog, vers] is registered. It may lie!
+% *
+% * PMAPPROC_DUMP() RETURNS (struct pmaplist_ptr)
+% *
+% * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
+% * RETURNS (port, string<>);
+% * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc,
+% * encapsulatedargs);
+% * Calls the procedure on the local machine. If it is not registered,
+% * this procedure is quite; ie it does not return error information!!!
+% * This procedure only is supported on rpc/udp and calls via
+% * rpc/udp. This routine only passes null authentication parameters.
+% * This file has no interface to xdr routines for PMAPPROC_CALLIT.
+% *
+% * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
+% */
+%
+const PMAPPORT = 111; /* portmapper port number */
+%
+%
+%/*
+% * A mapping of (program, version, protocol) to port number
+% */
+
+struct pmap {
+ unsigned long pm_prog;
+ unsigned long pm_vers;
+ unsigned long pm_prot;
+ unsigned long pm_port;
+};
+#ifdef RPC_HDR
+%
+%typedef pmap PMAP;
+%
+#endif
+%
+%/*
+% * Supported values for the "prot" field
+% */
+%
+const PMAP_IPPROTO_TCP = 6; /* protocol number for TCP/IP */
+const PMAP_IPPROTO_UDP = 17; /* protocol number for UDP/IP */
+%
+%
+%/*
+% * A list of mappings
+% *
+% * Below are two definitions for the pmaplist structure. This is done because
+% * xdr_pmaplist() is specified to take a struct pmaplist **, rather than a
+% * struct pmaplist * that rpcgen would produce. One version of the pmaplist
+% * structure (actually called pm__list) is used with rpcgen, and the other is
+% * defined only in the header file for compatibility with the specified
+% * interface.
+% */
+
+struct pm__list {
+ pmap pml_map;
+ struct pm__list *pml_next;
+};
+
+typedef pm__list *pmaplist_ptr; /* results of PMAPPROC_DUMP */
+
+#ifdef RPC_HDR
+%
+%typedef struct pm__list pmaplist;
+%typedef struct pm__list PMAPLIST;
+%
+%#ifndef __cplusplus
+%struct pmaplist {
+% PMAP pml_map;
+% struct pmaplist *pml_next;
+%};
+%#endif
+%
+%#ifdef __cplusplus
+%extern "C" {
+%#endif
+%#ifdef __STDC__
+%extern bool_t xdr_pmaplist(XDR *, pmaplist**);
+%#else /* K&R C */
+%bool_t xdr_pmaplist();
+%#endif
+%#ifdef __cplusplus
+%}
+%#endif
+%
+#endif
+
+%
+%/*
+% * Arguments to callit
+% */
+
+struct rmtcallargs {
+ unsigned long prog;
+ unsigned long vers;
+ unsigned long proc;
+ opaque args<>;
+};
+#ifdef RPC_HDR
+%
+%/*
+% * Client-side only representation of rmtcallargs structure.
+% *
+% * The routine that XDRs the rmtcallargs structure must deal with the
+% * opaque arguments in the "args" structure. xdr_rmtcall_args() needs to be
+% * passed the XDR routine that knows the args' structure. This routine
+% * doesn't need to go over-the-wire (and it wouldn't make sense anyway) since
+% * the application being called knows the args structure already. So we use a
+% * different "XDR" structure on the client side, p_rmtcallargs, which includes
+% * the args' XDR routine.
+% */
+%struct p_rmtcallargs {
+% u_long prog;
+% u_long vers;
+% u_long proc;
+% struct {
+% u_int args_len;
+% char *args_val;
+% } args;
+% xdrproc_t xdr_args; /* encodes args */
+%};
+%
+#endif /* def RPC_HDR */
+%
+%
+%/*
+% * Results of callit
+% */
+
+struct rmtcallres {
+ unsigned long port;
+ opaque res<>;
+};
+#ifdef RPC_HDR
+%
+%/*
+% * Client-side only representation of rmtcallres structure.
+% */
+%struct p_rmtcallres {
+% u_long port;
+% struct {
+% u_int res_len;
+% char *res_val;
+% } res;
+% xdrproc_t xdr_res; /* decodes res */
+%};
+%
+#endif /* def RPC_HDR */
+
+/*
+ * Port mapper procedures
+ */
+
+program PMAPPROG {
+ version PMAPVERS {
+ void
+ PMAPPROC_NULL(void) = 0;
+
+ bool
+ PMAPPROC_SET(pmap) = 1;
+
+ bool
+ PMAPPROC_UNSET(pmap) = 2;
+
+ unsigned long
+ PMAPPROC_GETPORT(pmap) = 3;
+
+ pmaplist_ptr
+ PMAPPROC_DUMP(void) = 4;
+
+ rmtcallres
+ PMAPPROC_CALLIT(rmtcallargs) = 5;
+ } = 2;
+} = 100000;
+%
+#ifdef RPC_HDR
+%#define PMAPVERS_PROTO ((u_long)2)
+%#define PMAPVERS_ORIG ((u_long)1)
+%
+%#else /* ndef _KERNEL */
+%
+%#include <rpc/pmap_rmt.h>
+%
+%#ifdef __cplusplus
+%extern "C" {
+%#endif
+%
+%#define PMAPPORT 111
+%
+%struct pmap {
+% long unsigned pm_prog;
+% long unsigned pm_vers;
+% long unsigned pm_prot;
+% long unsigned pm_port;
+%};
+%typedef struct pmap PMAP;
+%#ifdef __STDC__
+%extern bool_t xdr_pmap (XDR *, struct pmap *);
+%#else
+%extern bool_t xdr_pmap ();
+%#endif
+%
+%struct pmaplist {
+% struct pmap pml_map;
+% struct pmaplist *pml_next;
+%};
+%typedef struct pmaplist PMAPLIST;
+%typedef struct pmaplist *pmaplist_ptr;
+%
+%
+%#ifdef __cplusplus
+%}
+%#endif
+%
+%#endif /* ndef _KERNEL */
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/rex.x b/cpukit/librpc/include/rpcsvc/rex.x
new file mode 100644
index 0000000000..928efa21e7
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/rex.x
@@ -0,0 +1,235 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Remote execution (rex) protocol specification
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)rex.x 1.3 87/09/18 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)rex.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/rex.x,v 1.6 1999/08/27 23:45:10 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const STRINGSIZE = 1024;
+typedef string rexstring<1024>;
+
+/*
+ * values to pass to REXPROC_SIGNAL
+ */
+const SIGINT = 2; /* interrupt */
+
+/*
+ * Values for rst_flags, below
+ */
+const REX_INTERACTIVE = 1; /* interactive mode */
+
+struct rex_start {
+ rexstring rst_cmd<>; /* list of command and args */
+ rexstring rst_host; /* working directory host name */
+ rexstring rst_fsname; /* working directory file system name */
+ rexstring rst_dirwithin;/* working directory within file system */
+ rexstring rst_env<>; /* list of environment */
+ unsigned int rst_port0; /* port for stdin */
+ unsigned int rst_port1; /* port for stdout */
+ unsigned int rst_port2; /* port for stderr */
+ unsigned int rst_flags; /* options - see const above */
+};
+
+struct rex_result {
+ int rlt_stat; /* integer status code */
+ rexstring rlt_message; /* string message for human consumption */
+};
+
+
+struct sgttyb {
+ unsigned four; /* always equals 4 */
+ opaque chars[4];
+ /* chars[0] == input speed */
+ /* chars[1] == output speed */
+ /* chars[2] == kill character */
+ /* chars[3] == erase character */
+ unsigned flags;
+};
+/* values for speeds above (baud rates) */
+const B0 = 0;
+const B50 = 1;
+const B75 = 2;
+const B110 = 3;
+const B134 = 4;
+const B150 = 5;
+const B200 = 6;
+const B300 = 7;
+const B600 = 8;
+const B1200 = 9;
+const B1800 = 10;
+const B2400 = 11;
+const B4800 = 12;
+const B9600 = 13;
+const B19200 = 14;
+const B38400 = 15;
+
+/* values for flags above */
+const TANDEM = 0x00000001; /* send stopc on out q full */
+const CBREAK = 0x00000002; /* half-cooked mode */
+const LCASE = 0x00000004; /* simulate lower case */
+const ECHO = 0x00000008; /* echo input */
+const CRMOD = 0x00000010; /* map \r to \r\n on output */
+const RAW = 0x00000020; /* no i/o processing */
+const ODDP = 0x00000040; /* get/send odd parity */
+const EVENP = 0x00000080; /* get/send even parity */
+const ANYP = 0x000000c0; /* get any parity/send none */
+const NLDELAY = 0x00000300; /* \n delay */
+const NL0 = 0x00000000;
+const NL1 = 0x00000100; /* tty 37 */
+const NL2 = 0x00000200; /* vt05 */
+const NL3 = 0x00000300;
+const TBDELAY = 0x00000c00; /* horizontal tab delay */
+const TAB0 = 0x00000000;
+const TAB1 = 0x00000400; /* tty 37 */
+const TAB2 = 0x00000800;
+const XTABS = 0x00000c00; /* expand tabs on output */
+const CRDELAY = 0x00003000; /* \r delay */
+const CR0 = 0x00000000;
+const CR1 = 0x00001000; /* tn 300 */
+const CR2 = 0x00002000; /* tty 37 */
+const CR3 = 0x00003000; /* concept 100 */
+const VTDELAY = 0x00004000; /* vertical tab delay */
+const FF0 = 0x00000000;
+const FF1 = 0x00004000; /* tty 37 */
+const BSDELAY = 0x00008000; /* \b delay */
+const BS0 = 0x00000000;
+const BS1 = 0x00008000;
+const CRTBS = 0x00010000; /* do backspacing for crt */
+const PRTERA = 0x00020000; /* \ ... / erase */
+const CRTERA = 0x00040000; /* " \b " to wipe out char */
+const TILDE = 0x00080000; /* hazeltine tilde kludge */
+const MDMBUF = 0x00100000; /* start/stop output on carrier intr */
+const LITOUT = 0x00200000; /* literal output */
+const TOSTOP = 0x00400000; /* SIGTTOU on background output */
+const FLUSHO = 0x00800000; /* flush output to terminal */
+const NOHANG = 0x01000000; /* no SIGHUP on carrier drop */
+const L001000 = 0x02000000;
+const CRTKIL = 0x04000000; /* kill line with " \b " */
+const PASS8 = 0x08000000;
+const CTLECH = 0x10000000; /* echo control chars as ^X */
+const PENDIN = 0x20000000; /* tp->t_rawq needs reread */
+const DECCTQ = 0x40000000; /* only ^Q starts after ^S */
+const NOFLSH = 0x80000000; /* no output flush on signal */
+
+struct tchars {
+ unsigned six; /* always equals 6 */
+ opaque chars[6];
+ /* chars[0] == interrupt char */
+ /* chars[1] == quit char */
+ /* chars[2] == start output char */
+ /* chars[3] == stop output char */
+ /* chars[4] == end-of-file char */
+ /* chars[5] == input delimeter (like nl) */
+};
+
+struct ltchars {
+ unsigned six; /* always equals 6 */
+ opaque chars[6];
+ /* chars[0] == stop process signal */
+ /* chars[1] == delayed stop process signal */
+ /* chars[2] == reprint line */
+ /* chars[3] == flush output */
+ /* chars[4] == word erase */
+ /* chars[5] == literal next character */
+ unsigned mode;
+};
+
+struct rex_ttysize {
+ int ts_lines;
+ int ts_cols;
+};
+
+struct rex_ttymode {
+ sgttyb basic; /* standard unix tty flags */
+ tchars more; /* interrupt, kill characters, etc. */
+ ltchars yetmore; /* special Berkeley characters */
+ unsigned andmore; /* and Berkeley modes */
+};
+
+/* values for andmore above */
+const LCRTBS = 0x0001; /* do backspacing for crt */
+const LPRTERA = 0x0002; /* \ ... / erase */
+const LCRTERA = 0x0004; /* " \b " to wipe out char */
+const LTILDE = 0x0008; /* hazeltine tilde kludge */
+const LMDMBUF = 0x0010; /* start/stop output on carrier intr */
+const LLITOUT = 0x0020; /* literal output */
+const LTOSTOP = 0x0040; /* SIGTTOU on background output */
+const LFLUSHO = 0x0080; /* flush output to terminal */
+const LNOHANG = 0x0100; /* no SIGHUP on carrier drop */
+const LL001000 = 0x0200;
+const LCRTKIL = 0x0400; /* kill line with " \b " */
+const LPASS8 = 0x0800;
+const LCTLECH = 0x1000; /* echo control chars as ^X */
+const LPENDIN = 0x2000; /* needs reread */
+const LDECCTQ = 0x4000; /* only ^Q starts after ^S */
+const LNOFLSH = 0x8000; /* no output flush on signal */
+
+program REXPROG {
+ version REXVERS {
+
+ /*
+ * Start remote execution
+ */
+ rex_result
+ REXPROC_START(rex_start) = 1;
+
+ /*
+ * Wait for remote execution to terminate
+ */
+ rex_result
+ REXPROC_WAIT(void) = 2;
+
+ /*
+ * Send tty modes
+ */
+ void
+ REXPROC_MODES(rex_ttymode) = 3;
+
+ /*
+ * Send window size change
+ */
+ void
+ REXPROC_WINCH(rex_ttysize) = 4;
+
+ /*
+ * Send other signal
+ */
+ void
+ REXPROC_SIGNAL(int) = 5;
+ } = 1;
+} = 100017;
diff --git a/cpukit/librpc/include/rpcsvc/rnusers.x b/cpukit/librpc/include/rpcsvc/rnusers.x
new file mode 100644
index 0000000000..393eaf4eac
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/rnusers.x
@@ -0,0 +1,122 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Find out about remote users
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)rnusers.x 1.2 87/09/20 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)rnusers.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/rnusers.x,v 1.6 1999/08/27 23:45:10 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const MAXUSERS = 100;
+const MAXUTLEN = 256;
+
+struct utmp {
+ string ut_line<MAXUTLEN>;
+ string ut_name<MAXUTLEN>;
+ string ut_host<MAXUTLEN>;
+ int ut_time;
+};
+
+
+struct utmpidle {
+ utmp ui_utmp;
+ unsigned int ui_idle;
+};
+
+typedef utmp utmparr<MAXUSERS>;
+
+typedef utmpidle utmpidlearr<MAXUSERS>;
+
+const RUSERS_MAXUSERLEN = 32;
+const RUSERS_MAXLINELEN = 32;
+const RUSERS_MAXHOSTLEN = 257;
+
+struct rusers_utmp {
+ string ut_user<RUSERS_MAXUSERLEN>; /* aka ut_name */
+ string ut_line<RUSERS_MAXLINELEN>; /* device */
+ string ut_host<RUSERS_MAXHOSTLEN>; /* host user logged on from */
+ int ut_type; /* type of entry */
+ int ut_time; /* time entry was made */
+ unsigned int ut_idle; /* minutes idle */
+};
+
+typedef rusers_utmp utmp_array<>;
+
+program RUSERSPROG {
+ /*
+ * Old version does not include idle information
+ */
+ version RUSERSVERS_ORIG {
+ int
+ RUSERSPROC_NUM(void) = 1;
+
+ utmparr
+ RUSERSPROC_NAMES(void) = 2;
+
+ utmparr
+ RUSERSPROC_ALLNAMES(void) = 3;
+ } = 1;
+
+ /*
+ * Includes idle information
+ */
+ version RUSERSVERS_IDLE {
+ int
+ RUSERSPROC_NUM(void) = 1;
+
+ utmpidlearr
+ RUSERSPROC_NAMES(void) = 2;
+
+ utmpidlearr
+ RUSERSPROC_ALLNAMES(void) = 3;
+ } = 2;
+
+ /*
+ * Version 3 rusers procedures (from Solaris).
+ * (Thanks a lot Sun.)
+ */
+ version RUSERSVERS_3 {
+ int
+ RUSERSPROC_NUM(void) = 1;
+
+ utmp_array
+ RUSERSPROC_NAMES(void) = 2;
+
+ utmp_array
+ RUSERSPROC_ALLNAMES(void) = 3;
+ } = 3;
+
+} = 100002;
diff --git a/cpukit/librpc/include/rpcsvc/rquota.x b/cpukit/librpc/include/rpcsvc/rquota.x
new file mode 100644
index 0000000000..72864d1c69
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/rquota.x
@@ -0,0 +1,67 @@
+/*
+ * Remote quota protocol
+ * Requires unix authentication
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)rquota.x 1.2 87/09/20 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)rquota.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/rquota.x,v 1.6 1999/08/27 23:45:10 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const RQ_PATHLEN = 1024;
+
+struct getquota_args {
+ string gqa_pathp<RQ_PATHLEN>; /* path to filesystem of interest */
+ int gqa_uid; /* inquire about quota for uid */
+};
+
+/*
+ * remote quota structure
+ */
+struct rquota {
+ int rq_bsize; /* block size for block counts */
+ bool rq_active; /* indicates whether quota is active */
+ unsigned int rq_bhardlimit; /* absolute limit on disk blks alloc */
+ unsigned int rq_bsoftlimit; /* preferred limit on disk blks */
+ unsigned int rq_curblocks; /* current block count */
+ unsigned int rq_fhardlimit; /* absolute limit on allocated files */
+ unsigned int rq_fsoftlimit; /* preferred file limit */
+ unsigned int rq_curfiles; /* current # allocated files */
+ unsigned int rq_btimeleft; /* time left for excessive disk use */
+ unsigned int rq_ftimeleft; /* time left for excessive files */
+};
+
+enum gqr_status {
+ Q_OK = 1, /* quota returned */
+ Q_NOQUOTA = 2, /* noquota for uid */
+ Q_EPERM = 3 /* no permission to access quota */
+};
+
+union getquota_rslt switch (gqr_status status) {
+case Q_OK:
+ rquota gqr_rquota; /* valid if status == Q_OK */
+case Q_NOQUOTA:
+ void;
+case Q_EPERM:
+ void;
+};
+
+program RQUOTAPROG {
+ version RQUOTAVERS {
+ /*
+ * Get all quotas
+ */
+ getquota_rslt
+ RQUOTAPROC_GETQUOTA(getquota_args) = 1;
+
+ /*
+ * Get active quotas only
+ */
+ getquota_rslt
+ RQUOTAPROC_GETACTIVEQUOTA(getquota_args) = 2;
+ } = 1;
+} = 100011;
diff --git a/cpukit/librpc/include/rpcsvc/rstat.x b/cpukit/librpc/include/rpcsvc/rstat.x
new file mode 100644
index 0000000000..fee9d52032
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/rstat.x
@@ -0,0 +1,151 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Gather statistics on remote machines
+ */
+
+#ifdef RPC_HDR
+
+%#ifndef FSCALE
+%/*
+% * Scale factor for scaled integers used to count load averages.
+% */
+%#define FSHIFT 8 /* bits to right of fixed binary point */
+%#define FSCALE (1<<FSHIFT)
+%
+%#endif /* ndef FSCALE */
+
+#else
+
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)rstat.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)rstat.x 2.2 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/rstat.x,v 1.6 1999/08/27 23:45:11 peter Exp $";
+%#endif /* not lint */
+
+#endif /* def RPC_HDR */
+
+const RSTAT_CPUSTATES = 4;
+const RSTAT_DK_NDRIVE = 4;
+
+/*
+ * GMT since 0:00, January 1, 1970
+ */
+struct rstat_timeval {
+ unsigned int tv_sec; /* seconds */
+ unsigned int tv_usec; /* and microseconds */
+};
+
+struct statstime { /* RSTATVERS_TIME */
+ int cp_time[RSTAT_CPUSTATES];
+ int dk_xfer[RSTAT_DK_NDRIVE];
+ unsigned int v_pgpgin; /* these are cumulative sum */
+ unsigned int v_pgpgout;
+ unsigned int v_pswpin;
+ unsigned int v_pswpout;
+ unsigned int v_intr;
+ int if_ipackets;
+ int if_ierrors;
+ int if_oerrors;
+ int if_collisions;
+ unsigned int v_swtch;
+ int avenrun[3]; /* scaled by FSCALE */
+ rstat_timeval boottime;
+ rstat_timeval curtime;
+ int if_opackets;
+};
+
+struct statsswtch { /* RSTATVERS_SWTCH */
+ int cp_time[RSTAT_CPUSTATES];
+ int dk_xfer[RSTAT_DK_NDRIVE];
+ unsigned int v_pgpgin; /* these are cumulative sum */
+ unsigned int v_pgpgout;
+ unsigned int v_pswpin;
+ unsigned int v_pswpout;
+ unsigned int v_intr;
+ int if_ipackets;
+ int if_ierrors;
+ int if_oerrors;
+ int if_collisions;
+ unsigned int v_swtch;
+ unsigned int avenrun[3];/* scaled by FSCALE */
+ rstat_timeval boottime;
+ int if_opackets;
+};
+
+struct stats { /* RSTATVERS_ORIG */
+ int cp_time[RSTAT_CPUSTATES];
+ int dk_xfer[RSTAT_DK_NDRIVE];
+ unsigned int v_pgpgin; /* these are cumulative sum */
+ unsigned int v_pgpgout;
+ unsigned int v_pswpin;
+ unsigned int v_pswpout;
+ unsigned int v_intr;
+ int if_ipackets;
+ int if_ierrors;
+ int if_oerrors;
+ int if_collisions;
+ int if_opackets;
+};
+
+
+program RSTATPROG {
+ /*
+ * Newest version includes current time and context switching info
+ */
+ version RSTATVERS_TIME {
+ statstime
+ RSTATPROC_STATS(void) = 1;
+
+ unsigned int
+ RSTATPROC_HAVEDISK(void) = 2;
+ } = 3;
+ /*
+ * Does not have current time
+ */
+ version RSTATVERS_SWTCH {
+ statsswtch
+ RSTATPROC_STATS(void) = 1;
+
+ unsigned int
+ RSTATPROC_HAVEDISK(void) = 2;
+ } = 2;
+ /*
+ * Old version has no info about current time or context switching
+ */
+ version RSTATVERS_ORIG {
+ stats
+ RSTATPROC_STATS(void) = 1;
+
+ unsigned int
+ RSTATPROC_HAVEDISK(void) = 2;
+ } = 1;
+} = 100001;
diff --git a/cpukit/librpc/include/rpcsvc/rwall.x b/cpukit/librpc/include/rpcsvc/rwall.x
new file mode 100644
index 0000000000..6c26c1f18f
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/rwall.x
@@ -0,0 +1,57 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user or with the express written consent of
+% * Sun Microsystems, Inc.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+
+%/*
+% * Copyright (c) 1984, 1990 by Sun Microsystems, Inc.
+% */
+%
+%/* from @(#)rwall.x 1.6 91/03/11 TIRPC 1.0 */
+
+#ifdef RPC_HDR
+%
+%#ifndef _rpcsvc_rwall_h
+%#define _rpcsvc_rwall_h
+%
+%typedef char *wrapstring;
+%
+#endif
+
+program WALLPROG {
+ version WALLVERS {
+ void
+ WALLPROC_WALL(wrapstring) = 2;
+
+ } = 1;
+} = 100008;
+
+#ifdef RPC_HDR
+%
+%#endif /* ! _rpcsvc_rwall_h */
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/sm_inter.x b/cpukit/librpc/include/rpcsvc/sm_inter.x
new file mode 100644
index 0000000000..2071516a7f
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/sm_inter.x
@@ -0,0 +1,122 @@
+/* @(#)sm_inter.x 2.2 88/08/01 4.0 RPCSRC */
+/* @(#)sm_inter.x 1.7 87/06/24 Copyr 1987 Sun Micro */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Status monitor protocol specification
+ * Copyright (C) 1986 Sun Microsystems, Inc.
+ *
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/sm_inter.x,v 1.8 1999/08/27 23:45:11 peter Exp $";
+%#endif /* not lint */
+#endif
+
+program SM_PROG {
+ version SM_VERS {
+ /* res_stat = stat_succ if status monitor agrees to monitor */
+ /* res_stat = stat_fail if status monitor cannot monitor */
+ /* if res_stat == stat_succ, state = state number of site sm_name */
+ struct sm_stat_res SM_STAT(struct sm_name) = 1;
+
+ /* res_stat = stat_succ if status monitor agrees to monitor */
+ /* res_stat = stat_fail if status monitor cannot monitor */
+ /* stat consists of state number of local site */
+ struct sm_stat_res SM_MON(struct mon) = 2;
+
+ /* stat consists of state number of local site */
+ struct sm_stat SM_UNMON(struct mon_id) = 3;
+
+ /* stat consists of state number of local site */
+ struct sm_stat SM_UNMON_ALL(struct my_id) = 4;
+
+ void SM_SIMU_CRASH(void) = 5;
+
+ } = 1;
+} = 100024;
+
+const SM_MAXSTRLEN = 1024;
+
+struct sm_name {
+ string mon_name<SM_MAXSTRLEN>;
+};
+
+struct my_id {
+ string my_name<SM_MAXSTRLEN>; /* name of the site iniates the monitoring request*/
+ int my_prog; /* rpc program # of the requesting process */
+ int my_vers; /* rpc version # of the requesting process */
+ int my_proc; /* rpc procedure # of the requesting process */
+};
+
+struct mon_id {
+ string mon_name<SM_MAXSTRLEN>; /* name of the site to be monitored */
+ struct my_id my_id;
+};
+
+
+struct mon{
+ struct mon_id mon_id;
+ opaque priv[16]; /* private information to store at monitor for requesting process */
+};
+
+
+/*
+ * state # of status monitor monitonically increases each time
+ * status of the site changes:
+ * an even number (>= 0) indicates the site is down and
+ * an odd number (> 0) indicates the site is up;
+ */
+struct sm_stat {
+ int state; /* state # of status monitor */
+};
+
+enum res {
+ stat_succ = 0, /* status monitor agrees to monitor */
+ stat_fail = 1 /* status monitor cannot monitor */
+};
+
+struct sm_stat_res {
+ res res_stat;
+ int state;
+};
+
+/*
+ * structure of the status message sent back by the status monitor
+ * when monitor site status changes
+ */
+struct status {
+ string mon_name<SM_MAXSTRLEN>;
+ int state;
+ opaque priv[16]; /* stored private information */
+};
diff --git a/cpukit/librpc/include/rpcsvc/spray.x b/cpukit/librpc/include/rpcsvc/spray.x
new file mode 100644
index 0000000000..a4d086af48
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/spray.x
@@ -0,0 +1,90 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Spray a server with packets
+ * Useful for testing flakiness of network interfaces
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)spray.x 1.2 87/09/18 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)spray.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/spray.x,v 1.6 1999/08/27 23:45:11 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const SPRAYMAX = 8845; /* max amount can spray */
+
+/*
+ * GMT since 0:00, 1 January 1970
+ */
+struct spraytimeval {
+ unsigned int sec;
+ unsigned int usec;
+};
+
+/*
+ * spray statistics
+ */
+struct spraycumul {
+ unsigned int counter;
+ spraytimeval clock;
+};
+
+/*
+ * spray data
+ */
+typedef opaque sprayarr<SPRAYMAX>;
+
+program SPRAYPROG {
+ version SPRAYVERS {
+ /*
+ * Just throw away the data and increment the counter
+ * This call never returns, so the client should always
+ * time it out.
+ */
+ void
+ SPRAYPROC_SPRAY(sprayarr) = 1;
+
+ /*
+ * Get the value of the counter and elapsed time since
+ * last CLEAR.
+ */
+ spraycumul
+ SPRAYPROC_GET(void) = 2;
+
+ /*
+ * Clear the counter and reset the elapsed time
+ */
+ void
+ SPRAYPROC_CLEAR(void) = 3;
+ } = 1;
+} = 100012;
diff --git a/cpukit/librpc/include/rpcsvc/yp.x b/cpukit/librpc/include/rpcsvc/yp.x
new file mode 100644
index 0000000000..aa872653ff
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/yp.x
@@ -0,0 +1,379 @@
+/* @(#)yp.x 2.1 88/08/01 4.0 RPCSRC */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Protocol description file for the Yellow Pages Service
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/yp.x,v 1.12 1999/08/27 23:45:12 peter Exp $";
+%#endif /* not lint */
+#endif
+
+const YPMAXRECORD = 1024;
+const YPMAXDOMAIN = 64;
+const YPMAXMAP = 64;
+const YPMAXPEER = 64;
+
+
+enum ypstat {
+ YP_TRUE = 1,
+ YP_NOMORE = 2,
+ YP_FALSE = 0,
+ YP_NOMAP = -1,
+ YP_NODOM = -2,
+ YP_NOKEY = -3,
+ YP_BADOP = -4,
+ YP_BADDB = -5,
+ YP_YPERR = -6,
+ YP_BADARGS = -7,
+ YP_VERS = -8
+};
+
+
+enum ypxfrstat {
+ YPXFR_SUCC = 1,
+ YPXFR_AGE = 2,
+ YPXFR_NOMAP = -1,
+ YPXFR_NODOM = -2,
+ YPXFR_RSRC = -3,
+ YPXFR_RPC = -4,
+ YPXFR_MADDR = -5,
+ YPXFR_YPERR = -6,
+ YPXFR_BADARGS = -7,
+ YPXFR_DBM = -8,
+ YPXFR_FILE = -9,
+ YPXFR_SKEW = -10,
+ YPXFR_CLEAR = -11,
+ YPXFR_FORCE = -12,
+ YPXFR_XFRERR = -13,
+ YPXFR_REFUSED = -14
+};
+
+
+typedef string domainname<YPMAXDOMAIN>;
+typedef string mapname<YPMAXMAP>;
+typedef string peername<YPMAXPEER>;
+typedef opaque keydat<YPMAXRECORD>;
+typedef opaque valdat<YPMAXRECORD>;
+
+
+struct ypmap_parms {
+ domainname domain;
+ mapname map;
+ unsigned int ordernum;
+ peername peer;
+};
+
+struct ypreq_key {
+ domainname domain;
+ mapname map;
+ keydat key;
+};
+
+struct ypreq_nokey {
+ domainname domain;
+ mapname map;
+};
+
+struct ypreq_xfr {
+ ypmap_parms map_parms;
+ unsigned int transid;
+ unsigned int prog;
+ unsigned int port;
+};
+
+
+struct ypresp_val {
+ ypstat stat;
+ valdat val;
+};
+
+struct ypresp_key_val {
+ ypstat stat;
+#ifdef STUPID_SUN_BUG /* These are backwards */
+ keydat key;
+ valdat val;
+#else
+ valdat val;
+ keydat key;
+#endif
+};
+
+
+struct ypresp_master {
+ ypstat stat;
+ peername peer;
+};
+
+struct ypresp_order {
+ ypstat stat;
+ unsigned int ordernum;
+};
+
+union ypresp_all switch (bool more) {
+case TRUE:
+ ypresp_key_val val;
+case FALSE:
+ void;
+};
+
+struct ypresp_xfr {
+ unsigned int transid;
+ ypxfrstat xfrstat;
+};
+
+struct ypmaplist {
+ mapname map;
+ ypmaplist *next;
+};
+
+struct ypresp_maplist {
+ ypstat stat;
+ ypmaplist *maps;
+};
+
+enum yppush_status {
+ YPPUSH_SUCC = 1, /* Success */
+ YPPUSH_AGE = 2, /* Master's version not newer */
+ YPPUSH_NOMAP = -1, /* Can't find server for map */
+ YPPUSH_NODOM = -2, /* Domain not supported */
+ YPPUSH_RSRC = -3, /* Local resource alloc failure */
+ YPPUSH_RPC = -4, /* RPC failure talking to server */
+ YPPUSH_MADDR = -5, /* Can't get master address */
+ YPPUSH_YPERR = -6, /* YP server/map db error */
+ YPPUSH_BADARGS = -7, /* Request arguments bad */
+ YPPUSH_DBM = -8, /* Local dbm operation failed */
+ YPPUSH_FILE = -9, /* Local file I/O operation failed */
+ YPPUSH_SKEW = -10, /* Map version skew during transfer */
+ YPPUSH_CLEAR = -11, /* Can't send "Clear" req to local ypserv */
+ YPPUSH_FORCE = -12, /* No local order number in map use -f flag. */
+ YPPUSH_XFRERR = -13, /* ypxfr error */
+ YPPUSH_REFUSED = -14 /* Transfer request refused by ypserv */
+};
+
+struct yppushresp_xfr {
+ unsigned transid;
+ yppush_status status;
+};
+
+/*
+ * Response structure and overall result status codes. Success and failure
+ * represent two separate response message types.
+ */
+
+enum ypbind_resptype {
+ YPBIND_SUCC_VAL = 1,
+ YPBIND_FAIL_VAL = 2
+};
+
+struct ypbind_binding {
+ opaque ypbind_binding_addr[4]; /* In network order */
+ opaque ypbind_binding_port[2]; /* In network order */
+};
+
+union ypbind_resp switch (ypbind_resptype ypbind_status) {
+case YPBIND_FAIL_VAL:
+ unsigned ypbind_error;
+case YPBIND_SUCC_VAL:
+ ypbind_binding ypbind_bindinfo;
+};
+
+/* Detailed failure reason codes for response field ypbind_error*/
+
+const YPBIND_ERR_ERR = 1; /* Internal error */
+const YPBIND_ERR_NOSERV = 2; /* No bound server for passed domain */
+const YPBIND_ERR_RESC = 3; /* System resource allocation failure */
+
+
+/*
+ * Request data structure for ypbind "Set domain" procedure.
+ */
+struct ypbind_setdom {
+ domainname ypsetdom_domain;
+ ypbind_binding ypsetdom_binding;
+ unsigned ypsetdom_vers;
+};
+
+
+/*
+ * NIS v1 support for backwards compatibility
+ */
+enum ypreqtype {
+ YPREQ_KEY = 1,
+ YPREQ_NOKEY = 2,
+ YPREQ_MAP_PARMS = 3
+};
+
+enum ypresptype {
+ YPRESP_VAL = 1,
+ YPRESP_KEY_VAL = 2,
+ YPRESP_MAP_PARMS = 3
+};
+
+union yprequest switch (ypreqtype yp_reqtype) {
+case YPREQ_KEY:
+ ypreq_key yp_req_keytype;
+case YPREQ_NOKEY:
+ ypreq_nokey yp_req_nokeytype;
+case YPREQ_MAP_PARMS:
+ ypmap_parms yp_req_map_parmstype;
+};
+
+union ypresponse switch (ypresptype yp_resptype) {
+case YPRESP_VAL:
+ ypresp_val yp_resp_valtype;
+case YPRESP_KEY_VAL:
+ ypresp_key_val yp_resp_key_valtype;
+case YPRESP_MAP_PARMS:
+ ypmap_parms yp_resp_map_parmstype;
+};
+
+#if !defined(YPBIND_ONLY) && !defined(YPPUSH_ONLY)
+/*
+ * YP access protocol
+ */
+program YPPROG {
+/*
+ * NIS v1 support for backwards compatibility
+ */
+ version YPOLDVERS {
+ void
+ YPOLDPROC_NULL(void) = 0;
+
+ bool
+ YPOLDPROC_DOMAIN(domainname) = 1;
+
+ bool
+ YPOLDPROC_DOMAIN_NONACK(domainname) = 2;
+
+ ypresponse
+ YPOLDPROC_MATCH(yprequest) = 3;
+
+ ypresponse
+ YPOLDPROC_FIRST(yprequest) = 4;
+
+ ypresponse
+ YPOLDPROC_NEXT(yprequest) = 5;
+
+ ypresponse
+ YPOLDPROC_POLL(yprequest) = 6;
+
+ ypresponse
+ YPOLDPROC_PUSH(yprequest) = 7;
+
+ ypresponse
+ YPOLDPROC_PULL(yprequest) = 8;
+
+ ypresponse
+ YPOLDPROC_GET(yprequest) = 9;
+ } = 1;
+
+ version YPVERS {
+ void
+ YPPROC_NULL(void) = 0;
+
+ bool
+ YPPROC_DOMAIN(domainname) = 1;
+
+ bool
+ YPPROC_DOMAIN_NONACK(domainname) = 2;
+
+ ypresp_val
+ YPPROC_MATCH(ypreq_key) = 3;
+
+ ypresp_key_val
+#ifdef STUPID_SUN_BUG /* should be ypreq_nokey */
+ YPPROC_FIRST(ypreq_key) = 4;
+#else
+ YPPROC_FIRST(ypreq_nokey) = 4;
+#endif
+ ypresp_key_val
+ YPPROC_NEXT(ypreq_key) = 5;
+
+ ypresp_xfr
+ YPPROC_XFR(ypreq_xfr) = 6;
+
+ void
+ YPPROC_CLEAR(void) = 7;
+
+ ypresp_all
+ YPPROC_ALL(ypreq_nokey) = 8;
+
+ ypresp_master
+ YPPROC_MASTER(ypreq_nokey) = 9;
+
+ ypresp_order
+ YPPROC_ORDER(ypreq_nokey) = 10;
+
+ ypresp_maplist
+ YPPROC_MAPLIST(domainname) = 11;
+ } = 2;
+} = 100004;
+#endif
+#if !defined(YPSERV_ONLY) && !defined(YPBIND_ONLY)
+/*
+ * YPPUSHPROC_XFRRESP is the callback routine for result of YPPROC_XFR
+ */
+program YPPUSH_XFRRESPPROG {
+ version YPPUSH_XFRRESPVERS {
+ void
+ YPPUSHPROC_NULL(void) = 0;
+#ifdef STUPID_SUN_BUG /* argument and return value are backwards */
+ yppushresp_xfr
+ YPPUSHPROC_XFRRESP(void) = 1;
+#else
+ void
+ YPPUSHPROC_XFRRESP(yppushresp_xfr) = 1;
+#endif
+ } = 1;
+} = 0x40000000; /* transient: could be anything up to 0x5fffffff */
+#endif
+#if !defined(YPSERV_ONLY) && !defined(YPPUSH_ONLY)
+/*
+ * YP binding protocol
+ */
+program YPBINDPROG {
+ version YPBINDVERS {
+ void
+ YPBINDPROC_NULL(void) = 0;
+
+ ypbind_resp
+ YPBINDPROC_DOMAIN(domainname) = 1;
+
+ void
+ YPBINDPROC_SETDOM(ypbind_setdom) = 2;
+ } = 2;
+} = 100007;
+
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/yp_prot.h b/cpukit/librpc/include/rpcsvc/yp_prot.h
new file mode 100644
index 0000000000..5abe0e2514
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/yp_prot.h
@@ -0,0 +1,329 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/include/rpcsvc/yp_prot.h,v 1.10 1999/08/27 23:45:12 peter Exp $
+ */
+
+#ifndef _RPCSVC_YP_PROT_H_
+#define _RPCSVC_YP_PROT_H_
+
+/*
+ * YPSERV PROTOCOL:
+ *
+ * ypserv supports the following procedures:
+ *
+ * YPPROC_NULL takes (void), returns (void).
+ * called to check if server is alive.
+ * YPPROC_DOMAIN takes (char *), returns (bool_t).
+ * true if ypserv serves the named domain.
+ * YPPROC_DOMAIN_NOACK takes (char *), returns (bool_t).
+ * true if ypserv serves the named domain.
+ * used for broadcasts, does not ack if ypserv
+ * doesn't handle named domain.
+ * YPPROC_MATCH takes (struct ypreq_key), returns (struct ypresp_val)
+ * does a lookup.
+ * YPPROC_FIRST takes (struct ypreq_nokey) returns (ypresp_key_val).
+ * gets the first key/datum from the map.
+ * YPPROC_NEXT takes (struct ypreq_key) returns (ypresp_key_val).
+ * gets the next key/datum from the map.
+ * YPPROC_XFR takes (struct ypreq_xfr), returns (void).
+ * tells ypserv to check if there is a new version of
+ * the map.
+ * YPPROC_CLEAR takes (void), returns (void).
+ * tells ypserv to flush it's file cache, so that
+ * newly transferred files will get read.
+ * YPPROC_ALL takes (struct ypreq_nokey), returns (bool_t and
+ * struct ypresp_key_val).
+ * returns an array of data, with the bool_t being
+ * false on the last datum. read the source, it's
+ * convoluted.
+ * YPPROC_MASTER takes (struct ypreq_nokey), returns (ypresp_master).
+ * YPPROC_ORDER takes (struct ypreq_nokey), returns (ypresp_order).
+ * YPPROC_MAPLIST takes (char *), returns (struct ypmaplist *).
+ */
+
+#ifndef BOOL_DEFINED
+typedef u_int bool;
+#define BOOL_DEFINED
+#endif
+
+/* Program and version symbols, magic numbers */
+
+#define YPPROG ((u_long)100004)
+#define YPVERS ((u_long)2)
+#define YPVERS_ORIG ((u_long)1)
+#define YPMAXRECORD ((u_long)1024)
+#define YPMAXDOMAIN ((u_long)64)
+#define YPMAXMAP ((u_long)64)
+#define YPMAXPEER ((u_long)256)
+
+/*
+ * I don't know if anything of sun's depends on this, or if they
+ * simply defined it so that their own code wouldn't try to send
+ * packets over the ethernet MTU. This YP code doesn't use it.
+ */
+#define YPMSGSZ 1600
+
+#ifndef DATUM
+typedef struct {
+ char *dptr;
+ int dsize;
+} datum;
+#define DATUM
+#endif
+
+struct ypmap_parms {
+ char *domain;
+ char *map;
+ u_long ordernum;
+ char *owner;
+};
+
+struct ypreq_key {
+ char *domain;
+ char *map;
+ datum keydat;
+};
+
+struct ypreq_nokey {
+ char *domain;
+ char *map;
+};
+
+struct ypreq_xfr {
+ struct ypmap_parms map_parms;
+ u_long transid;
+ u_long proto;
+ u_short port;
+};
+#define ypxfr_domain map_parms.domain
+#define ypxfr_map map_parms.map
+#define ypxfr_ordernum map_parms.ordernum
+#define ypxfr_owner map_parms.owner
+
+struct ypresp_val {
+ u_long status;
+ datum valdat;
+};
+
+struct ypresp_key_val {
+ u_long status;
+ datum keydat;
+ datum valdat;
+};
+
+struct ypresp_master {
+ u_long status;
+ char *master;
+};
+
+struct ypresp_order {
+ u_long status;
+ u_long ordernum;
+};
+
+struct ypmaplist {
+ char ypml_name[YPMAXMAP + 1];
+ struct ypmaplist *ypml_next;
+};
+
+struct ypresp_maplist {
+ u_long status;
+ struct ypmaplist *list;
+};
+
+/* ypserv procedure numbers */
+#define YPPROC_NULL ((u_long)0)
+#define YPPROC_DOMAIN ((u_long)1)
+#define YPPROC_DOMAIN_NONACK ((u_long)2)
+#define YPPROC_MATCH ((u_long)3)
+#define YPPROC_FIRST ((u_long)4)
+#define YPPROC_NEXT ((u_long)5)
+#define YPPROC_XFR ((u_long)6)
+#define YPPROC_CLEAR ((u_long)7)
+#define YPPROC_ALL ((u_long)8)
+#define YPPROC_MASTER ((u_long)9)
+#define YPPROC_ORDER ((u_long)10)
+#define YPPROC_MAPLIST ((u_long)11)
+
+/* ypserv procedure return status values */
+#define YP_TRUE ((long)1) /* general purpose success code */
+#define YP_NOMORE ((long)2) /* no more entries in map */
+#define YP_FALSE ((long)0) /* general purpose failure code */
+#define YP_NOMAP ((long)-1) /* no such map in domain */
+#define YP_NODOM ((long)-2) /* domain not supported */
+#define YP_NOKEY ((long)-3) /* no such key in map */
+#define YP_BADOP ((long)-4) /* invalid operation */
+#define YP_BADDB ((long)-5) /* server data base is bad */
+#define YP_YPERR ((long)-6) /* YP server error */
+#define YP_BADARGS ((long)-7) /* request arguments bad */
+#define YP_VERS ((long)-8) /* YP server version mismatch */
+
+/*
+ * Sun's header file says:
+ * "Domain binding data structure, used by ypclnt package and ypserv modules.
+ * Users of the ypclnt package (or of this protocol) don't HAVE to know about
+ * it, but it must be available to users because _yp_dobind is a public
+ * interface."
+ *
+ * This is totally bogus! Nowhere else does Sun state that _yp_dobind() is
+ * a public interface, and I don't know any reason anyone would want to call
+ * it. But, just in case anyone does actually expect it to be available..
+ * we provide this.. exactly as Sun wants it.
+ */
+struct dom_binding {
+ struct dom_binding *dom_pnext;
+ char dom_domain[YPMAXDOMAIN + 1];
+ struct sockaddr_in dom_server_addr;
+ u_short dom_server_port;
+ int dom_socket;
+ CLIENT *dom_client;
+ u_short dom_local_port;
+ long dom_vers;
+};
+
+/*
+ * YPBIND PROTOCOL:
+ *
+ * ypbind supports the following procedures:
+ *
+ * YPBINDPROC_NULL takes (void), returns (void).
+ * to check if ypbind is running.
+ * YPBINDPROC_DOMAIN takes (char *), returns (struct ypbind_resp).
+ * requests that ypbind start to serve the
+ * named domain (if it doesn't already)
+ * YPBINDPROC_SETDOM takes (struct ypbind_setdom), returns (void).
+ * used by ypset.
+ */
+
+#define YPBINDPROG ((u_long)100007)
+#define YPBINDVERS ((u_long)2)
+#define YPBINDVERS_ORIG ((u_long)1)
+
+/* ypbind procedure numbers */
+#define YPBINDPROC_NULL ((u_long)0)
+#define YPBINDPROC_DOMAIN ((u_long)1)
+#define YPBINDPROC_SETDOM ((u_long)2)
+
+/* error code in ypbind_resp.ypbind_status */
+enum ypbind_resptype {
+ YPBIND_SUCC_VAL = 1,
+ YPBIND_FAIL_VAL = 2
+};
+
+/* network order, of course */
+struct ypbind_binding {
+ struct in_addr ypbind_binding_addr;
+ u_short ypbind_binding_port;
+};
+
+struct ypbind_resp {
+ enum ypbind_resptype ypbind_status;
+ union {
+ u_long ypbind_error;
+ struct ypbind_binding ypbind_bindinfo;
+ } ypbind_respbody;
+};
+
+/* error code in ypbind_resp.ypbind_respbody.ypbind_error */
+#define YPBIND_ERR_ERR 1 /* internal error */
+#define YPBIND_ERR_NOSERV 2 /* no bound server for passed domain */
+#define YPBIND_ERR_RESC 3 /* system resource allocation failure */
+
+/*
+ * Request data structure for ypbind "Set domain" procedure.
+ */
+struct ypbind_setdom {
+ char ypsetdom_domain[YPMAXDOMAIN + 1];
+ struct ypbind_binding ypsetdom_binding;
+ u_short ypsetdom_vers;
+};
+#define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr
+#define ypsetdom_port ypsetdom_binding.ypbind_binding_port
+
+/*
+ * YPPUSH PROTOCOL:
+ *
+ * Sun says:
+ * "Protocol between clients (ypxfr, only) and yppush
+ * yppush speaks a protocol in the transient range, which
+ * is supplied to ypxfr as a command-line parameter when it
+ * is activated by ypserv."
+ *
+ * This protocol is not implemented, naturally, because this YP
+ * implementation only does the client side.
+ */
+#define YPPUSHVERS ((u_long)1)
+#define YPPUSHVERS_ORIG ((u_long)1)
+
+/* yppush procedure numbers */
+#define YPPUSHPROC_NULL ((u_long)0)
+#define YPPUSHPROC_XFRRESP ((u_long)1)
+
+struct yppushresp_xfr {
+ u_long transid;
+ u_long status;
+};
+
+/* yppush status value in yppushresp_xfr.status */
+#define YPPUSH_SUCC ((long)1) /* Success */
+#define YPPUSH_AGE ((long)2) /* Master's version not newer */
+#define YPPUSH_NOMAP ((long)-1) /* Can't find server for map */
+#define YPPUSH_NODOM ((long)-2) /* Domain not supported */
+#define YPPUSH_RSRC ((long)-3) /* Local resource alloc failure */
+#define YPPUSH_RPC ((long)-4) /* RPC failure talking to server */
+#define YPPUSH_MADDR ((long)-5) /* Can't get master address */
+#define YPPUSH_YPERR ((long)-6) /* YP server/map db error */
+#define YPPUSH_BADARGS ((long)-7) /* Request arguments bad */
+#define YPPUSH_DBM ((long)-8) /* Local dbm operation failed */
+#define YPPUSH_FILE ((long)-9) /* Local file I/O operation failed */
+#define YPPUSH_SKEW ((long)-10) /* Map version skew during transfer */
+#define YPPUSH_CLEAR ((long)-11) /* Can't send "Clear" req to local ypserv */
+#define YPPUSH_FORCE ((long)-12) /* No local order number in map - use -f */
+#define YPPUSH_XFRERR ((long)-13) /* ypxfr error */
+#define YPPUSH_REFUSED ((long)-14) /* Transfer request refused by ypserv */
+
+struct inaddr;
+__BEGIN_DECLS
+bool_t xdr_datum (XDR *, datum *);
+bool_t xdr_ypreq_key (XDR *, struct ypreq_key *);
+bool_t xdr_ypreq_nokey (XDR *, struct ypreq_nokey *);
+bool_t xdr_ypreq_xfr (XDR *, struct ypreq_xfr *);
+bool_t xdr_ypresp_val (XDR *, struct ypresp_val *);
+bool_t xdr_ypresp_key_val (XDR *, struct ypresp_key_val *);
+bool_t xdr_ypbind_resp (XDR *, struct ypbind_resp *);
+bool_t xdr_ypbind_setdom (XDR *, struct ypbind_setdom *);
+bool_t xdr_yp_inaddr (XDR *, struct inaddr *);
+bool_t xdr_ypmap_parms (XDR *, struct ypmap_parms *);
+bool_t xdr_yppushresp_xfr (XDR *, struct yppushresp_xfr *);
+bool_t xdr_ypresp_order (XDR *, struct ypresp_order *);
+bool_t xdr_ypresp_master (XDR *, struct ypresp_master *);
+bool_t xdr_ypresp_maplist (XDR *, struct ypresp_maplist *);
+__END_DECLS
+
+#endif /* _RPCSVC_YP_PROT_H_ */
diff --git a/cpukit/librpc/include/rpcsvc/ypclnt.h b/cpukit/librpc/include/rpcsvc/ypclnt.h
new file mode 100644
index 0000000000..c429ff7ee0
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/ypclnt.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/include/rpcsvc/ypclnt.h,v 1.11 1999/08/27 23:45:12 peter Exp $
+ */
+
+#ifndef _RPCSVC_YPCLNT_H_
+#define _RPCSVC_YPCLNT_H_
+
+#include <rtems/bsd/sys/cdefs.h>
+
+#define YPERR_BADARGS 1 /* args to function are bad */
+#define YPERR_RPC 2 /* RPC failure */
+#define YPERR_DOMAIN 3 /* can't bind to a server for domain */
+#define YPERR_MAP 4 /* no such map in server's domain */
+#define YPERR_KEY 5 /* no such key in map */
+#define YPERR_YPERR 6 /* some internal YP server or client error */
+#define YPERR_RESRC 7 /* local resource allocation failure */
+#define YPERR_NOMORE 8 /* no more records in map database */
+#define YPERR_PMAP 9 /* can't communicate with portmapper */
+#define YPERR_YPBIND 10 /* can't communicate with ypbind */
+#define YPERR_YPSERV 11 /* can't communicate with ypserv */
+#define YPERR_NODOM 12 /* local domain name not set */
+#define YPERR_BADDB 13 /* YP data base is bad */
+#define YPERR_VERS 14 /* YP version mismatch */
+#define YPERR_ACCESS 15 /* access violation */
+#define YPERR_BUSY 16 /* database is busy */
+
+/*
+ * Types of update operations
+ */
+#define YPOP_CHANGE 1 /* change, do not add */
+#define YPOP_INSERT 2 /* add, do not change */
+#define YPOP_DELETE 3 /* delete this entry */
+#define YPOP_STORE 4 /* add, or change */
+
+struct ypall_callback {
+ /* return non-0 to stop getting called */
+ int (*foreach) (unsigned long, char *, int, char *, int, void *);
+ char *data; /* opaque pointer for use of callback fn */
+};
+
+struct dom_binding;
+
+__BEGIN_DECLS
+int yp_bind (char *dom);
+int _yp_dobind (char *dom, struct dom_binding **ypdb);
+void yp_unbind (char *dom);
+int yp_get_default_domain (char **domp);
+int yp_match (char *indomain, char *inmap,
+ const char *inkey, int inkeylen, char **outval,
+ int *outvallen);
+int yp_first (char *indomain, char *inmap,
+ char **outkey, int *outkeylen, char **outval,
+ int *outvallen);
+int yp_next (char *indomain, char *inmap,
+ char *inkey, int inkeylen, char **outkey,
+ int *outkeylen, char **outval, int *outvallen);
+int yp_master (char *indomain, char *inmap, char **outname);
+int yp_order (char *indomain, char *inmap, int *outorder);
+int yp_all (char *indomain, char *inmap,
+ struct ypall_callback *incallback);
+char * yperr_string (int incode);
+char * ypbinderr_string (int incode);
+int ypprot_err (unsigned int incode);
+__END_DECLS
+
+#endif /* _RPCSVC_YPCLNT_H_ */
diff --git a/cpukit/librpc/include/rpcsvc/yppasswd.x b/cpukit/librpc/include/rpcsvc/yppasswd.x
new file mode 100644
index 0000000000..73dca8e7ca
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/yppasswd.x
@@ -0,0 +1,75 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * YP password update protocol
+ * Requires unix authentication
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%/*static char sccsid[] = "from: @(#)yppasswd.x 1.1 87/04/13 Copyr 1987 Sun Micro";*/
+%/*static char sccsid[] = "from: @(#)yppasswd.x 2.1 88/08/01 4.0 RPCSRC";*/
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/yppasswd.x,v 1.6 1999/08/27 23:45:12 peter Exp $";
+%#endif /* not lint */
+#endif
+
+program YPPASSWDPROG {
+ version YPPASSWDVERS {
+ /*
+ * Update my passwd entry
+ */
+ int
+ YPPASSWDPROC_UPDATE(yppasswd) = 1;
+ } = 1;
+} = 100009;
+
+
+struct x_passwd {
+ string pw_name<>; /* username */
+ string pw_passwd<>; /* encrypted password */
+ int pw_uid; /* user id */
+ int pw_gid; /* group id */
+ string pw_gecos<>; /* in real life name */
+ string pw_dir<>; /* home directory */
+ string pw_shell<>; /* default shell */
+};
+
+struct yppasswd {
+ string oldpass<>; /* unencrypted old password */
+ x_passwd newpw; /* new passwd entry */
+};
+
+
+#ifdef RPC_HDR
+%#include <sys/cdefs.h>
+%extern int _yppasswd ( char * , struct x_passwd * );
+%#define yppasswd(x,y) _yppasswd(x,y)
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/ypupdate_prot.x b/cpukit/librpc/include/rpcsvc/ypupdate_prot.x
new file mode 100644
index 0000000000..f16d5ee45e
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/ypupdate_prot.x
@@ -0,0 +1,88 @@
+%/*
+% * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+% * unrestricted use provided that this legend is included on all tape
+% * media and as a part of the software program in whole or part. Users
+% * may copy or modify Sun RPC without charge, but are not authorized
+% * to license or distribute it to anyone else except as part of a product or
+% * program developed by the user or with the express written consent of
+% * Sun Microsystems, Inc.
+% *
+% * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+% * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+% * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+% *
+% * Sun RPC is provided with no support and without any obligation on the
+% * part of Sun Microsystems, Inc. to assist in its use, correction,
+% * modification or enhancement.
+% *
+% * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+% * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+% * OR ANY PART THEREOF.
+% *
+% * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+% * or profits or other special, indirect and consequential damages, even if
+% * Sun has been advised of the possibility of such damages.
+% *
+% * Sun Microsystems, Inc.
+% * 2550 Garcia Avenue
+% * Mountain View, California 94043
+% */
+
+%/*
+% * Copyright (c) 1986, 1990 by Sun Microsystems, Inc.
+% */
+%
+%/* from @(#)ypupdate_prot.x 1.3 91/03/11 TIRPC 1.0 */
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/ypupdate_prot.x,v 1.3 1999/08/27 23:45:13 peter Exp $";
+%#endif
+#endif
+%
+%/*
+% * Compiled from ypupdate_prot.x using rpcgen
+% * This is NOT source code!
+% * DO NOT EDIT THIS FILE!
+% */
+
+/*
+ * YP update service protocol
+ */
+#ifdef RPC_HDR
+%
+%#ifndef _rpcsvc_ypupdate_prot_h
+%#define _rpcsvc_ypupdate_prot_h
+%
+#endif
+
+const MAXMAPNAMELEN = 255;
+const MAXYPDATALEN = 1023;
+const MAXERRMSGLEN = 255;
+
+program YPU_PROG {
+ version YPU_VERS {
+ u_int YPU_CHANGE(ypupdate_args) = 1;
+ u_int YPU_INSERT(ypupdate_args) = 2;
+ u_int YPU_DELETE(ypdelete_args) = 3;
+ u_int YPU_STORE(ypupdate_args) = 4;
+ } = 1;
+} = 100028;
+
+typedef opaque yp_buf<MAXYPDATALEN>;
+
+struct ypupdate_args {
+ string mapname<MAXMAPNAMELEN>;
+ yp_buf key;
+ yp_buf datum;
+};
+
+struct ypdelete_args {
+ string mapname<MAXMAPNAMELEN>;
+ yp_buf key;
+};
+
+#ifdef RPC_HDR
+%
+%#endif /* !_rpcsvc_ypupdate_prot_h */
+#endif
diff --git a/cpukit/librpc/include/rpcsvc/ypxfrd.x b/cpukit/librpc/include/rpcsvc/ypxfrd.x
new file mode 100644
index 0000000000..1845a4f43b
--- /dev/null
+++ b/cpukit/librpc/include/rpcsvc/ypxfrd.x
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 1995, 1996
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/include/rpcsvc/ypxfrd.x,v 1.7 1999/08/27 23:45:13 peter Exp $
+ */
+
+/*
+ * This protocol definition file describes a file transfer
+ * system used to very quickly move NIS maps from one host to
+ * another. This is similar to what Sun does with their ypxfrd
+ * protocol, but it must be stressed that this protocol is _NOT_
+ * compatible with Sun's. There are a couple of reasons for this:
+ *
+ * 1) Sun's protocol is proprietary. The protocol definition is
+ * not freely available in any of the SunRPC source distributions,
+ * even though the NIS v2 protocol is.
+ *
+ * 2) The idea here is to transfer entire raw files rather than
+ * sending just the records. Sun uses ndbm for its NIS map files,
+ * while FreeBSD uses Berkeley DB. Both are hash databases, but the
+ * formats are incompatible, making it impossible for them to
+ * use each others' files. Even if FreeBSD adopted ndbm for its
+ * database format, FreeBSD/i386 is a little-endian OS and
+ * SunOS/SPARC is big-endian; ndbm is byte-order sensitive and
+ * not very smart about it, which means an attempt to read a
+ * database on a little-endian box that was created on a big-endian
+ * box (or vice-versa) can cause the ndbm code to eat itself.
+ * Luckily, Berkeley DB is able to deal with this situation in
+ * a more graceful manner.
+ *
+ * While the protocol is incompatible, the idea is the same: we just open
+ * up a TCP pipe to the client and transfer the raw map database
+ * from the master server to the slave. This is many times faster than
+ * the standard yppush/ypxfr transfer method since it saves us from
+ * having to recreate the map databases via the DB library each time.
+ * For example: creating a passwd database with 30,000 entries with yp_mkdb
+ * can take a couple of minutes, but to just copy the file takes only a few
+ * seconds.
+ */
+
+#ifndef RPC_HDR
+%#ifndef lint
+%static const char rcsid[] =
+% "$FreeBSD: src/include/rpcsvc/ypxfrd.x,v 1.7 1999/08/27 23:45:13 peter Exp $";
+%#endif /* not lint */
+#endif
+
+/* XXX cribbed from yp.x */
+const _YPMAXRECORD = 1024;
+const _YPMAXDOMAIN = 64;
+const _YPMAXMAP = 64;
+const _YPMAXPEER = 64;
+
+/* Suggested default -- not necesarrily the one used. */
+const YPXFRBLOCK = 32767;
+
+/*
+ * Possible return codes from the remote server.
+ */
+enum xfrstat {
+ XFR_REQUEST_OK = 1, /* Transfer request granted */
+ XFR_DENIED = 2, /* Transfer request denied */
+ XFR_NOFILE = 3, /* Requested map file doesn't exist */
+ XFR_ACCESS = 4, /* File exists, but I couldn't access it */
+ XFR_BADDB = 5, /* File is not a hash database */
+ XFR_READ_OK = 6, /* Block read successfully */
+ XFR_READ_ERR = 7, /* Read error during transfer */
+ XFR_DONE = 8, /* Transfer completed */
+ XFR_DB_ENDIAN_MISMATCH = 9, /* Database byte order mismatch */
+ XFR_DB_TYPE_MISMATCH = 10 /* Database type mismatch */
+};
+
+/*
+ * Database type specifications. The client can use this to ask
+ * the server for a particular type of database or just take whatever
+ * the server has to offer.
+ */
+enum xfr_db_type {
+ XFR_DB_ASCII = 1, /* Flat ASCII text */
+ XFR_DB_BSD_HASH = 2, /* Berkeley DB, hash method */
+ XFR_DB_BSD_BTREE = 3, /* Berkeley DB, btree method */
+ XFR_DB_BSD_RECNO = 4, /* Berkeley DB, recno method */
+ XFR_DB_BSD_MPOOL = 5, /* Berkeley DB, mpool method */
+ XFR_DB_BSD_NDBM = 6, /* Berkeley DB, hash, ndbm compat */
+ XFR_DB_GNU_GDBM = 7, /* GNU GDBM */
+ XFR_DB_DBM = 8, /* Old, deprecated dbm format */
+ XFR_DB_NDBM = 9, /* ndbm format (used by Sun's NISv2) */
+ XFR_DB_OPAQUE = 10, /* Mystery format -- just pass along */
+ XFR_DB_ANY = 11, /* I'll take any format you've got */
+ XFR_DB_UNKNOWN = 12 /* Unknown format */
+};
+
+/*
+ * Machine byte order specification. This allows the client to check
+ * that it's copying a map database from a machine of similar byte sex.
+ * This is necessary for handling database libraries that are fatally
+ * byte order sensitive.
+ *
+ * The XFR_ENDIAN_ANY type is for use with the Berkeley DB database
+ * formats; Berkeley DB is smart enough to make up for byte order
+ * differences, so byte sex isn't important.
+ */
+enum xfr_byte_order {
+ XFR_ENDIAN_BIG = 1, /* We want big endian */
+ XFR_ENDIAN_LITTLE = 2, /* We want little endian */
+ XFR_ENDIAN_ANY = 3 /* We'll take whatever you got */
+};
+
+typedef string xfrdomain<_YPMAXDOMAIN>;
+typedef string xfrmap<_YPMAXMAP>;
+typedef string xfrmap_filename<_YPMAXMAP>; /* actual name of map file */
+
+/*
+ * Ask the remote ypxfrd for a map using this structure.
+ * Note: we supply both a map name and a map file name. These are not
+ * the same thing. In the case of ndbm, maps are stored in two files:
+ * map.bykey.pag and may.bykey.dir. We may also have to deal with
+ * file extensions (on the off chance that the remote server is supporting
+ * multiple DB formats). To handle this, we tell the remote server both
+ * what map we want and, in the case of ndbm, whether we want the .dir
+ * or the .pag part. This name should not be a fully qualified path:
+ * it's up to the remote server to decide which directories to look in.
+ */
+struct ypxfr_mapname {
+ xfrmap xfrmap;
+ xfrdomain xfrdomain;
+ xfrmap_filename xfrmap_filename;
+ xfr_db_type xfr_db_type;
+ xfr_byte_order xfr_byte_order;
+};
+
+/* Read response using this structure. */
+union xfr switch (bool ok) {
+case TRUE:
+ opaque xfrblock_buf<>;
+case FALSE:
+ xfrstat xfrstat;
+};
+
+program YPXFRD_FREEBSD_PROG {
+ version YPXFRD_FREEBSD_VERS {
+ union xfr
+ YPXFRD_GETMAP(ypxfr_mapname) = 1;
+ } = 1;
+} = 600100069; /* 100069 + 60000000 -- 100069 is the Sun ypxfrd prog number */
diff --git a/cpukit/librpc/preinstall.am b/cpukit/librpc/preinstall.am
new file mode 100644
index 0000000000..9dd5969507
--- /dev/null
+++ b/cpukit/librpc/preinstall.am
@@ -0,0 +1,89 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+if LIBRPC
+$(PROJECT_INCLUDE)/rpc/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rpc
+ @: > $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rpc/auth.h: include/rpc/auth.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/auth.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/auth.h
+
+$(PROJECT_INCLUDE)/rpc/auth_unix.h: include/rpc/auth_unix.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/auth_unix.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/auth_unix.h
+
+$(PROJECT_INCLUDE)/rpc/clnt.h: include/rpc/clnt.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/clnt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/clnt.h
+
+$(PROJECT_INCLUDE)/rpc/clnt_stat.h: include/rpc/clnt_stat.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/clnt_stat.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/clnt_stat.h
+
+$(PROJECT_INCLUDE)/rpc/clnt_soc.h: include/rpc/clnt_soc.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/clnt_soc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/clnt_soc.h
+
+$(PROJECT_INCLUDE)/rpc/svc.h: include/rpc/svc.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/svc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/svc.h
+
+$(PROJECT_INCLUDE)/rpc/svc_auth.h: include/rpc/svc_auth.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/svc_auth.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/svc_auth.h
+
+$(PROJECT_INCLUDE)/rpc/svc_soc.h: include/rpc/svc_soc.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/svc_soc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/svc_soc.h
+
+$(PROJECT_INCLUDE)/rpc/pmap_clnt.h: include/rpc/pmap_clnt.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/pmap_clnt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/pmap_clnt.h
+
+$(PROJECT_INCLUDE)/rpc/pmap_prot.h: include/rpc/pmap_prot.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/pmap_prot.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/pmap_prot.h
+
+$(PROJECT_INCLUDE)/rpc/pmap_rmt.h: include/rpc/pmap_rmt.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/pmap_rmt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/pmap_rmt.h
+
+$(PROJECT_INCLUDE)/rpc/rpc.h: include/rpc/rpc.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/rpc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/rpc.h
+
+$(PROJECT_INCLUDE)/rpc/types.h: include/rpc/types.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/types.h
+
+$(PROJECT_INCLUDE)/rpc/xdr.h: include/rpc/xdr.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/xdr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/xdr.h
+
+$(PROJECT_INCLUDE)/rpc/rpc_com.h: include/rpc/rpc_com.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/rpc_com.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/rpc_com.h
+
+$(PROJECT_INCLUDE)/rpc/rpc_msg.h: include/rpc/rpc_msg.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/rpc_msg.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/rpc_msg.h
+
+$(PROJECT_INCLUDE)/rpc/rpcent.h: include/rpc/rpcent.h $(PROJECT_INCLUDE)/rpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rpc/rpcent.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rpc/rpcent.h
+endif
diff --git a/cpukit/librpc/src/rpc/DISCLAIMER b/cpukit/librpc/src/rpc/DISCLAIMER
new file mode 100644
index 0000000000..1a66d5f4c9
--- /dev/null
+++ b/cpukit/librpc/src/rpc/DISCLAIMER
@@ -0,0 +1,28 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
diff --git a/cpukit/librpc/src/rpc/README b/cpukit/librpc/src/rpc/README
new file mode 100644
index 0000000000..ad9d70f990
--- /dev/null
+++ b/cpukit/librpc/src/rpc/README
@@ -0,0 +1,233 @@
+RPCSRC 4.0 7/11/89
+
+This distribution contains Sun Microsystem's implementation of the
+RPC and XDR protocols and is compatible with 4.2BSD and 4.3BSD. Also
+included is complete documentation, utilities, RPC service
+specification files, and demonstration services in the format used by
+the RPC protocol compiler (rpcgen). See WHAT'S NEW below for
+details.
+
+NOTE ABOUT SECURE RPC:
+
+This release of RPCSRC contains most of the code needed to implement
+Secure RPC (see "DES Authentication" in the RPC Protocol Specification,
+doc/rpc.rfc.ms). Due to legal considerations, we are unable to
+distribute an implementation of DES, the Data Encryption Standard, which
+Secure RPC requires. For this reason, all of the files, documentation, and
+programs associated with Secure RPC have been placed into a separate
+directory, secure_rpc. The RPC library contained in the main body of this
+release *DOES NOT* support Secure RPC. See secure_rpc/README for more
+details. (A DES library was posted in Volume 18 of comp.sources.unix.)
+
+If you wish to report bugs found in this release, send mail to:
+
+Portable ONC/NFS
+Sun Microsystems, Inc
+MS 12-33
+2550 Garcia Avenue
+Mountain View, CA 94043
+
+or send Email to nfsnet@sun.com (the Internet) or sun!nfsnet (Usenet).
+
+ROADMAP
+
+The directory hierarchy is as follows:
+
+ demo/ Various demonstration services
+ demo/dir Remote directory lister
+ demo/msg Remote console message delivery service
+ demo/sort Remote sort service
+
+ doc/ Documentation for RPC, XDR and NFS in "-ms" format.
+
+ etc/ Utilities (rpcinfo and portmap). portmap must be
+ started by root before any other RPC network services are
+ used. SEE BELOW FOR BUGFIX TO 4.3BSD COMPILER.
+
+ man/ Manual pages for RPC library, rpcgen, and utilities.
+
+ rpc/ The RPC and XDR library. SEE BELOW
+ FOR BUGFIX TO 4.2BSD COMPILER.
+
+ rpcgen/ The RPC Language compiler (for .x files)
+
+ rpcsvc/ Service definition files for various services and the
+ server and client code for the Remote Status service.
+
+ secure_rpc/ The files in this directory are used to build a version of
+ the RPC library with DES Authentication. See the README
+ file in that directory for more details.
+
+BUILD INSTRUCTIONS
+
+Makefiles can be found in all directories except for man. The
+Makefile in the top directory will cause these others to be invoked
+(except for in the doc, man and demo directories), in turn building the
+entire release.
+
+WARNING! THE DEFAULT INSTALLATION PROCEDURES WILL INSTALL FILES
+IN /usr/include, /usr/lib, /usr/bin and /etc.
+
+The master RPC include file, rpc/rpc.h, is used by all programs and
+routines that use RPC. It includes other RPC and system include files
+needed by the RPC system. PLEASE NOTE: If your system has NFS, it
+may have been based on Sun's NFS Source. The include files installed
+by this package may duplicate include files you will find on your NFS
+system. The RPCSRC 4.0 include files are upwardly compatible to all
+NFS Source include files as of the date of this distribution (not
+including any new definitions or declarations added by your system
+vendor). HOWEVER: Please read the comments towards the end of
+rpc/rpc.h regarding rpc/netdb.h. You may need to uncomment the
+inclusion of that file if the structures it defines are already
+defined by your system's include files.
+
+After making any compiler fixes that are needed (see below), at
+the top directory, type:
+
+ make install
+
+For all installations, the Makefile macro DESTDIR is prepended to the
+installation path. It is defined to be null in the Makefiles, so
+installations are relative to root. (You will probably need root
+privileges for installing the files under the default path.) To
+install the files under some other tree (e.g., /usr/local), use the
+command:
+
+ make install DESTDIR=/usr/local
+
+This will place the include files in /usr/local/usr/include, the RPC
+library in /usr/local/usr/lib, rpcgen in /usr/local/usr/bin, and the
+utilities in /usr/local/etc. You'll have to edit the Makefiles or
+install the files by hand if you want to do anything other than this
+kind of relocation of the installation tree.
+
+The RPC library will be built and installed first. By default it is
+installed in /usr/lib as "librpclib.a". The directory
+/usr/include/rpc will also be created, and several header files will
+be installed there. ALL RPC SERVICES INCLUDE THESE HEADER FILES.
+
+The programs in etc/ link in routines from librpclib.a. If you change
+where it is installed, be sure to edit etc/'s Makefile to reflect this.
+These programs are installed in /etc. PORTMAP MUST BE RUNNING ON
+YOUR SYSTEM BEFORE YOU START ANY OTHER RPC SERVICE.
+
+rpcgen is installed in /usr/bin. This program is required to build
+the demonstration services in demo and the rstat client and server in
+rpcsvc/.
+
+The rpcsvc/ directory will install its files in the directory
+/usr/include/rpcsvc. The Remote Status service (rstat_svc) will be
+compiled and installed in /etc. If you wish to make this service
+available, you should either start this service when needed or have
+it started at boot time by invoking it in your /etc/rc.local script.
+(Be sure that portmap is started first!) Sun has modified its
+version of inetd to automatically start RPC services. (Use "make
+LIB=" when building rstat on a Sun Workstation.) The Remote Status
+client (rstat) will be installed in /usr/bin. This program queries
+the rstat_svc on a remote host and prints a system status summary
+similar to the one printed by "uptime".
+
+The documentation is not built during the "make install" command.
+Typing "make" in the doc directory will cause all of the manuals to
+be formatted using nroff into a single file. We have had a report
+that certain "troff" equivalents have trouble processing the full
+manual. If you have trouble, try building the manuals individually
+(see the Makefile).
+
+The demonstration services in the demo directory are not built by the
+top-level "make install" command. To build these, cd to the demo
+directory and enter "make". The three services will be built.
+RPCGEN MUST BE INSTALLED in a path that make can find. To run the
+services, start the portmap program as root and invoke the service
+(you probably will want to put it in the background). rpcinfo can be
+used to check that the service succeeded in getting registered with
+portmap, and to ping the service (see rpcinfo's man page). You can
+then use the corresponding client program to exercise the service.
+To build these services on a Sun workstation, you must prevent the
+Makefile from trying to link the RPC library (as these routines are
+already a part of Sun's libc). Use: "make LIB=".
+
+BUGFIX FOR 4.3BSD COMPILER
+
+The use of a 'void *' declaration for one of the arguments in
+the reply_proc() procedure in etc/rpcinfo.c will trigger a bug
+in the 4.3BSD compiler. The bug is fixed by the following change to
+the compiler file mip/manifest.h:
+
+*** manifest.h.r1.1 Thu Apr 30 13:52:25 1987
+--- manifest.h.r1.2 Mon Nov 23 18:58:17 1987
+***************
+*** 21,27 ****
+ /*
+ * Bogus type values
+ */
+! #define TNULL PTR /* pointer to UNDEF */
+ #define TVOID FTN /* function returning UNDEF (for void) */
+
+ /*
+--- 21,27 ----
+ /*
+ * Bogus type values
+ */
+! #define TNULL INCREF(MOETY) /* pointer to MOETY -- impossible type */
+ #define TVOID FTN /* function returning UNDEF (for void) */
+
+ /*
+
+If you cannot fix your compiler, change the declaration in reply_proc()
+from 'void *' to 'char *'.
+
+BUGFIX FOR 4.2BSD COMPILER
+
+Unpatched 4.2BSD compilers complain about valid C. You can make old
+compilers happy by changing some voids to ints. However, the fix to
+the 4.2 VAX compiler is as follows (to mip/trees.c):
+
+*** trees.c.r1.1 Mon May 11 13:47:58 1987
+--- trees.c.r1.2 Wed Jul 2 18:28:52 1986
+***************
+*** 1247,1253 ****
+ if(o==CAST && mt1==0)return(TYPL+TYMATCH);
+ if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
+ else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
+! else if( mt12 == 0 ) break;
+ else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
+ else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
+ break;
+--- 1261,1269 ----
+ if(o==CAST && mt1==0)return(TYPL+TYMATCH);
+ if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
+ else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
+! /* if right is TVOID and looks like a CALL, is not ok */
+! else if (mt2 == 0 && (p->in.right->in.op == CALL || p->in.right->in.op == UNARY CALL))
+! break;
+ else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
+ else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
+ break;
+
+WHAT'S NEW IN THIS RELEASE: RPCSRC 4.0
+
+The previous release was RPCSRC 3.9. As with all previous releases,
+this release is based directly on files from Sun Microsystem's
+implementation.
+
+Upgrade from RPCSRC 3.9
+
+1) RPCSRC 4.0 upgrades RPCSRC 3.9. Improvements from SunOS 4.0 have
+ been integrated into this release.
+
+Secure RPC (in the secure_rpc/ directory)
+
+2) DES Authentication routines and programs are provided.
+3) A new manual, "Secure NFS" is provided, which describes Secure RPC
+ and Secure NFS.
+4) Skeleton routines and manual pages are provided which describe the
+ DES encryption procedures required by Secure RPC. HOWEVER, NO DES
+ ROUTINE IS PROVIDED.
+
+New Functionality
+
+5) rpcinfo can now be used to de-register services from the portmapper
+ which may have terminated abnormally.
+6) A new client, rstat, is provided which queries the rstat_svc and
+ prints a status line similar to the one displayed by "uptime".
diff --git a/cpukit/librpc/src/rpc/auth_none.c b/cpukit/librpc/src/rpc/auth_none.c
new file mode 100644
index 0000000000..48b3741df7
--- /dev/null
+++ b/cpukit/librpc/src/rpc/auth_none.c
@@ -0,0 +1,138 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/auth_none.c,v 1.9 1999/08/28 00:00:32 peter Exp $";
+#endif
+
+/*
+ * auth_none.c
+ * Creates a client authentication handle for passing "null"
+ * credentials and verifiers to remote systems.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#define MAX_MARSHAL_SIZE 20
+
+/*
+ * Authenticator operations routines
+ */
+static void authnone_verf(AUTH*);
+static void authnone_destroy(AUTH*);
+static int authnone_marshal(AUTH*, XDR*);
+static int authnone_validate(AUTH*, struct opaque_auth *);
+static int authnone_refresh(AUTH*);
+
+static struct auth_ops ops = {
+ authnone_verf,
+ authnone_marshal,
+ authnone_validate,
+ authnone_refresh,
+ authnone_destroy
+};
+
+static struct authnone_private {
+ AUTH no_client;
+ char marshalled_client[MAX_MARSHAL_SIZE];
+ u_int mcnt;
+} *authnone_private;
+
+AUTH *
+authnone_create(void)
+{
+ struct authnone_private *ap = authnone_private;
+ XDR xdr_stream;
+ XDR *xdrs;
+
+ if (ap == 0) {
+ ap = (struct authnone_private *)calloc(1, sizeof (*ap));
+ if (ap == 0)
+ return (0);
+ authnone_private = ap;
+ }
+ if (!ap->mcnt) {
+ ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
+ ap->no_client.ah_ops = &ops;
+ xdrs = &xdr_stream;
+ xdrmem_create(xdrs, ap->marshalled_client, (u_int)MAX_MARSHAL_SIZE,
+ XDR_ENCODE);
+ (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
+ (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
+ ap->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+ }
+ return (&ap->no_client);
+}
+
+/*ARGSUSED*/
+static int
+authnone_marshal(AUTH *client, XDR *xdrs)
+{
+ struct authnone_private *ap = authnone_private;
+
+ if (ap == 0)
+ return (0);
+ return ((*xdrs->x_ops->x_putbytes)(xdrs,
+ ap->marshalled_client, ap->mcnt));
+}
+
+static void
+authnone_verf(AUTH *client)
+{
+}
+
+static int
+authnone_validate(AUTH *client, struct opaque_auth *opaque)
+{
+
+ return (TRUE);
+}
+
+static int
+authnone_refresh(AUTH *client)
+{
+
+ return (FALSE);
+}
+
+static void
+authnone_destroy(AUTH *client)
+{
+}
diff --git a/cpukit/librpc/src/rpc/auth_unix.c b/cpukit/librpc/src/rpc/auth_unix.c
new file mode 100644
index 0000000000..67d3962bae
--- /dev/null
+++ b/cpukit/librpc/src/rpc/auth_unix.c
@@ -0,0 +1,345 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)auth_unix.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/auth_unix.c,v 1.12 1999/12/29 05:04:16 peter Exp $";
+#endif
+
+/*
+ * auth_unix.c, Implements UNIX style authentication parameters.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * The system is very weak. The client uses no encryption for it's
+ * credentials and only sends null verifiers. The server sends backs
+ * null verifiers or optionally a verifier that suggests a new short hand
+ * for the credentials.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/param.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+
+/*
+ * Unix authenticator operations vector
+ */
+static void authunix_nextverf(AUTH*);
+static int authunix_marshal(AUTH*, XDR*);
+static int authunix_validate(AUTH*, struct opaque_auth *);
+static int authunix_refresh(AUTH*);
+static void authunix_destroy(AUTH*);
+
+static struct auth_ops auth_unix_ops = {
+ authunix_nextverf,
+ authunix_marshal,
+ authunix_validate,
+ authunix_refresh,
+ authunix_destroy
+};
+
+/*
+ * This struct is pointed to by the ah_private field of an auth_handle.
+ */
+struct audata {
+ struct opaque_auth au_origcred; /* original credentials */
+ struct opaque_auth au_shcred; /* short hand cred */
+ u_long au_shfaults; /* short hand cache faults */
+ char au_marshed[MAX_AUTH_BYTES];
+ u_int au_mpos; /* xdr pos at end of marshed */
+};
+#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
+
+static void marshal_new_auth(AUTH *);
+
+/*
+ * This goop is here because some servers refuse to accept a
+ * credential with more than some number (usually 8) supplementary
+ * groups. Blargh!
+ */
+static int authunix_maxgrouplist = 0;
+
+void
+set_rpc_maxgrouplist(int num)
+{
+ authunix_maxgrouplist = num;
+}
+
+/*
+ * Create a unix style authenticator.
+ * Returns an auth handle with the given stuff in it.
+ */
+AUTH *
+authunix_create(
+ char *machname,
+ int uid,
+ int gid,
+ int len,
+ int *aup_gids)
+{
+ struct authunix_parms aup;
+ char mymem[MAX_AUTH_BYTES];
+ struct timeval now;
+ XDR xdrs;
+ register AUTH *auth;
+ register struct audata *au;
+
+ /*
+ * Allocate and set up auth handle
+ */
+ auth = (AUTH *)mem_alloc(sizeof(*auth));
+#ifndef _KERNEL
+ if (auth == NULL) {
+ (void)fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ au = (struct audata *)mem_alloc(sizeof(*au));
+#ifndef _KERNEL
+ if (au == NULL) {
+ (void)fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ auth->ah_ops = &auth_unix_ops;
+ auth->ah_private = (caddr_t)au;
+ auth->ah_verf = au->au_shcred = _null_auth;
+ au->au_shfaults = 0;
+
+ /*
+ * fill in param struct from the given params
+ */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ aup.aup_time = now.tv_sec;
+ aup.aup_machname = machname;
+ aup.aup_uid = uid;
+ aup.aup_gid = gid;
+ /* GW: continuation of max group list hack */
+ if(authunix_maxgrouplist != 0) {
+ aup.aup_len = ((len < authunix_maxgrouplist) ? len
+ : authunix_maxgrouplist);
+ } else {
+ aup.aup_len = (u_int)len;
+ }
+ aup.aup_gids = aup_gids;
+
+ /*
+ * Serialize the parameters into origcred
+ */
+ xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
+ if (! xdr_authunix_parms(&xdrs, &aup))
+ abort();
+ au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
+ au->au_origcred.oa_flavor = AUTH_UNIX;
+#ifdef _KERNEL
+ au->au_origcred.oa_base = mem_alloc((u_int) len);
+#else
+ if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
+ (void)fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ memcpy(au->au_origcred.oa_base, mymem, (u_int)len);
+
+ /*
+ * set auth handle to reflect new cred.
+ */
+ auth->ah_cred = au->au_origcred;
+ marshal_new_auth(auth);
+ return (auth);
+}
+
+/*
+ * Returns an auth handle with parameters determined by doing lots of
+ * syscalls.
+ */
+AUTH *
+authunix_create_default(void)
+{
+ register int len;
+ char machname[MAX_MACHINE_NAME + 1];
+ register int uid;
+ register int gid;
+ int gids[NGRPS];
+ int i;
+ gid_t real_gids[NGROUPS];
+
+ if (gethostname(machname, MAX_MACHINE_NAME) == -1)
+ abort();
+ machname[MAX_MACHINE_NAME] = 0;
+ uid = (int)geteuid();
+ gid = (int)getegid();
+ if ((len = getgroups(NGROUPS, real_gids)) < 0)
+ abort();
+ if(len > NGRPS) len = NGRPS; /* GW: turn `gid_t's into `int's */
+ for(i = 0; i < len; i++) {
+ gids[i] = (int)real_gids[i];
+ }
+ return (authunix_create(machname, uid, gid, len, gids));
+}
+
+/*
+ * authunix operations
+ */
+
+static void
+authunix_nextverf(AUTH *auth)
+{
+ /* no action necessary */
+}
+
+static int
+authunix_marshal(AUTH *auth, XDR *xdrs)
+{
+ struct audata *au = AUTH_PRIVATE(auth);
+
+ return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
+}
+
+static int
+authunix_validate( AUTH *auth, struct opaque_auth *verf )
+{
+ register struct audata *au;
+ XDR xdrs;
+
+ if (verf->oa_flavor == AUTH_SHORT) {
+ au = AUTH_PRIVATE(auth);
+ xdrmem_create(&xdrs, verf->oa_base, verf->oa_length, XDR_DECODE);
+
+ if (au->au_shcred.oa_base != NULL) {
+ mem_free(au->au_shcred.oa_base,
+ au->au_shcred.oa_length);
+ au->au_shcred.oa_base = NULL;
+ }
+ if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
+ auth->ah_cred = au->au_shcred;
+ } else {
+ xdrs.x_op = XDR_FREE;
+ (void)xdr_opaque_auth(&xdrs, &au->au_shcred);
+ au->au_shcred.oa_base = NULL;
+ auth->ah_cred = au->au_origcred;
+ }
+ marshal_new_auth(auth);
+ }
+ return (TRUE);
+}
+
+static int
+authunix_refresh(AUTH *auth)
+{
+ struct audata *au = AUTH_PRIVATE(auth);
+ struct authunix_parms aup;
+ struct timeval now;
+ XDR xdrs;
+ int stat;
+
+ if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
+ /* there is no hope. Punt */
+ return (FALSE);
+ }
+ au->au_shfaults ++;
+
+ /* first deserialize the creds back into a struct authunix_parms */
+ aup.aup_machname = NULL;
+ aup.aup_gids = (int *)NULL;
+ xdrmem_create(&xdrs, au->au_origcred.oa_base,
+ au->au_origcred.oa_length, XDR_DECODE);
+ stat = xdr_authunix_parms(&xdrs, &aup);
+ if (! stat)
+ goto done;
+
+ /* update the time and serialize in place */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ aup.aup_time = now.tv_sec;
+ xdrs.x_op = XDR_ENCODE;
+ XDR_SETPOS(&xdrs, 0);
+ stat = xdr_authunix_parms(&xdrs, &aup);
+ if (! stat)
+ goto done;
+ auth->ah_cred = au->au_origcred;
+ marshal_new_auth(auth);
+done:
+ /* free the struct authunix_parms created by deserializing */
+ xdrs.x_op = XDR_FREE;
+ (void)xdr_authunix_parms(&xdrs, &aup);
+ XDR_DESTROY(&xdrs);
+ return (stat);
+}
+
+static void
+authunix_destroy(AUTH *auth)
+{
+ struct audata *au = AUTH_PRIVATE(auth);
+
+ mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
+
+ if (au->au_shcred.oa_base != NULL)
+ mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
+
+ mem_free(auth->ah_private, sizeof(struct audata));
+
+ if (auth->ah_verf.oa_base != NULL)
+ mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
+
+ mem_free((caddr_t)auth, sizeof(*auth));
+}
+
+/*
+ * Marshals (pre-serializes) an auth struct.
+ * sets private data, au_marshed and au_mpos
+ */
+static void
+marshal_new_auth(AUTH *auth)
+{
+ XDR xdr_stream;
+ XDR *xdrs = &xdr_stream;
+ struct audata *au = AUTH_PRIVATE(auth);
+
+ xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
+ if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
+ (! xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
+ perror("auth_none.c - Fatal marshalling problem");
+ } else {
+ au->au_mpos = XDR_GETPOS(xdrs);
+ }
+ XDR_DESTROY(xdrs);
+}
diff --git a/cpukit/librpc/src/rpc/authunix_prot.c b/cpukit/librpc/src/rpc/authunix_prot.c
new file mode 100644
index 0000000000..84acf46c6b
--- /dev/null
+++ b/cpukit/librpc/src/rpc/authunix_prot.c
@@ -0,0 +1,71 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/authunix_prot.c,v 1.6 1999/08/28 00:00:33 peter Exp $";
+#endif
+
+/*
+ * authunix_prot.c
+ * XDR for UNIX style authentication parameters for RPC
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+
+/*
+ * XDR for unix authentication parameters.
+ */
+bool_t
+xdr_authunix_parms(
+ XDR *xdrs,
+ struct authunix_parms *p)
+{
+
+ if (xdr_u_long(xdrs, &(p->aup_time))
+ && xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
+ && xdr_int(xdrs, &(p->aup_uid))
+ && xdr_int(xdrs, &(p->aup_gid))
+ && xdr_array(xdrs, (caddr_t *)(void *)&(p->aup_gids),
+ &(p->aup_len), NGRPS, sizeof(int), (xdrproc_t) xdr_int) ) {
+ return (TRUE);
+ }
+ return (FALSE);
+}
diff --git a/cpukit/librpc/src/rpc/bindresvport.3 b/cpukit/librpc/src/rpc/bindresvport.3
new file mode 100644
index 0000000000..02a079decc
--- /dev/null
+++ b/cpukit/librpc/src/rpc/bindresvport.3
@@ -0,0 +1,106 @@
+.\" @(#)bindresvport.3n 2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
+.\" $FreeBSD: src/lib/libc/rpc/bindresvport.3,v 1.10 2000/01/27 02:55:01 bde Exp $
+.\"
+.Dd January 27, 2000
+.Dt BINDRESVPORT 3
+.Os
+.Sh NAME
+.Nm bindresvport ,
+.Nm bindresvport_sa
+.Ndbind a socket to a privileged IP port
+.Sh SYNOPSIS
+.Fd #include <rpc/rpc.h>
+.Ft int
+.Fn bindresvport "int sd" "struct sockaddr_in *sin"
+.Ft int
+.Fn bindresvport_sa "int sd" "struct sockaddr *sa"
+.Sh DESCRIPTION
+.Fn bindresvport
+and
+.Fn bindresvport_sa
+are used to bind a socket descriptor to a privileged
+.Tn IP
+port, that is, a
+port number in the range 0-1023.
+.Pp
+Only root can bind to a privileged port; this call will fail for any
+other users.
+.Pp
+When
+.Va sin
+is not null,
+.Va sin->sin_family
+must be initialized to the address family of the socket, passed by
+.Va sd .
+If the value of sin->sin_port is non-zero
+.Fn bindresvport
+will attempt to use that specific port. If it fails, it chooses another
+privileged port automatically.
+.Pp
+It is legal to pass null pointer to
+.Va sin .
+In this case, the caller cannot get the port number
+.Fn bindresvport
+has picked.
+.Pp
+Function prototype of
+.Fn bindresvport
+is biased to
+.Dv AF_INET
+socket.
+.Fn bindresvport_sa
+acts exactly the same, with more neutral function prototype.
+Note that both functions behave exactly the same, and
+both support
+.Dv AF_INET6
+sockets as well as
+.Dv AF_INET
+sockets.
+.Sh RETURN VALUES
+.Fn bindresvport
+and
+.Fn bindresvport_sa
+return 0 if they are successful, otherwise \-1 is returned and
+.Va errno
+set to reflect the cause of the error.
+.Sh ERRORS
+The
+.Fn bindresvport
+and
+.Fn bindresvport_sa
+functions fail if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+.Fa sd
+is not a valid descriptor.
+.It Bq Er ENOTSOCK
+.Fa sd
+is not a socket.
+.It Bq Er EADDRNOTAVAIL
+The specified address is not available from the local machine.
+.It Bq Er EADDRINUSE
+The specified address is already in use.
+.It Bq Er EINVAL
+The socket is already bound to an address,
+or the socket family and the family of specified address mismatch.
+.It Bq Er EACCES
+The requested address is protected, and the current user
+has inadequate permission to access it.
+.It Bq Er EFAULT
+The
+.Fa name
+parameter is not in a valid part of the user
+address space.
+.It Bq Er ENOBUFS
+Insufficient resources were available in the system
+to perform the operation.
+.It Bq Er EPFNOSUPPORT
+The protocol family has not been configured into the
+system, no implementation for it exists,
+or address family did not match between arguments.
+.El
+.Sh "SEE ALSO"
+.Xr bind 2 ,
+.Xr socket 2 ,
+.Xr rresvport 3 ,
+.Xr rresvport_af 3
diff --git a/cpukit/librpc/src/rpc/bindresvport.c b/cpukit/librpc/src/rpc/bindresvport.c
new file mode 100644
index 0000000000..849d664f33
--- /dev/null
+++ b/cpukit/librpc/src/rpc/bindresvport.c
@@ -0,0 +1,160 @@
+/* $NetBSD: bindresvport.c,v 1.19 2000/07/06 03:03:59 christos Exp $ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)bindresvport.c 1.8 88/02/08 SMI";*/
+/*static char *sccsid = "from: @(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC";*/
+/*from: OpenBSD: bindresvport.c,v 1.7 1996/07/30 16:25:47 downsj Exp */
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/bindresvport.c,v 1.12 2000/01/26 09:02:42 shin Exp $";
+#endif
+
+/*
+ * Copyright (c) 1987 by Sun Microsystems, Inc.
+ *
+ * Portions Copyright(C) 1996, Jason Downs. All rights reserved.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rpc/rpc.h>
+
+/*
+ * Bind a socket to a privileged IP port
+ */
+int
+bindresvport(
+ int sd,
+ struct sockaddr_in *sin)
+{
+ return bindresvport_sa(sd, (struct sockaddr *)sin);
+}
+
+/*
+ * Bind a socket to a privileged IP port
+ */
+int
+bindresvport_sa(
+ int sd,
+ struct sockaddr *sa)
+{
+ int old, error, af;
+ struct sockaddr myaddr;
+ struct sockaddr_in *sin;
+#ifdef INET6
+ struct sockaddr_in6 *sin6;
+#endif
+ int proto, portrange, portlow;
+ u_int16_t port;
+ socklen_t salen;
+
+ if (sa == NULL) {
+ salen = sizeof(myaddr);
+ sa = (struct sockaddr *)&myaddr;
+
+ if (getsockname(sd, sa, &salen) == -1)
+ return -1; /* errno is correctly set */
+
+ af = sa->sa_family;
+ memset(&myaddr, 0, salen);
+ } else
+ af = sa->sa_family;
+
+ switch (af) {
+ case AF_INET:
+ proto = IPPROTO_IP;
+ portrange = IP_PORTRANGE;
+ portlow = IP_PORTRANGE_LOW;
+ sin = (struct sockaddr_in *)sa;
+ salen = sizeof(struct sockaddr_in);
+ port = sin->sin_port;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ proto = IPPROTO_IPV6;
+ portrange = IPV6_PORTRANGE;
+ portlow = IPV6_PORTRANGE_LOW;
+ sin6 = (struct sockaddr_in6 *)sa;
+ salen = sizeof(struct sockaddr_in6);
+ port = sin6->sin6_port;
+ break;
+#endif
+ default:
+ errno = EPFNOSUPPORT;
+ return (-1);
+ }
+ sa->sa_family = af;
+ sa->sa_len = salen;
+
+ if (port == 0) {
+ socklen_t oldlen = sizeof(old);
+
+ error = getsockopt(sd, proto, portrange, &old, &oldlen);
+ if (error < 0)
+ return (error);
+
+ error = setsockopt(sd, proto, portrange, &portlow,
+ sizeof(portlow));
+ if (error < 0)
+ return (error);
+ }
+
+ error = bind(sd, sa, salen);
+
+ if (port == 0) {
+ int saved_errno = errno;
+
+ if (error) {
+ if (setsockopt(sd, proto, portrange, &old,
+ sizeof(old)) < 0)
+ errno = saved_errno;
+ return (error);
+ }
+
+ if (sa != (struct sockaddr *)&myaddr) {
+ /* Hmm, what did the kernel assign? */
+ if (getsockname(sd, sa, &salen) < 0)
+ errno = saved_errno;
+ return (error);
+ }
+ }
+ return (error);
+}
diff --git a/cpukit/librpc/src/rpc/clnt_generic.c b/cpukit/librpc/src/rpc/clnt_generic.c
new file mode 100644
index 0000000000..232af02cd7
--- /dev/null
+++ b/cpukit/librpc/src/rpc/clnt_generic.c
@@ -0,0 +1,145 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";*/
+/*static char *sccsid = "from: @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_generic.c,v 1.9 1999/08/28 00:00:35 peter Exp $";
+#endif
+
+/*
+ * Copyright (C) 1987, Sun Microsystems, Inc.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/*
+ * Generic client creation: takes (hostname, program-number, protocol) and
+ * returns client handle. Default options are set, which the user can
+ * change using the rpc equivalent of ioctl()'s.
+ */
+CLIENT *
+clnt_create(
+ const char *hostname,
+ rpcprog_t prog,
+ rpcvers_t vers,
+ const char *proto)
+{
+ struct hostent *h;
+ struct protoent *p;
+ struct sockaddr_in sin;
+#ifndef __rtems__
+ struct sockaddr_un sun;
+#endif
+ int sock;
+ struct timeval tv;
+ CLIENT *client;
+
+#ifndef __rtems__
+ if (!strcmp(proto, "unix")) {
+ bzero((char *)&sun, sizeof(sun));
+ sun.sun_family = AF_UNIX;
+ strcpy(sun.sun_path, hostname);
+ sun.sun_len = sizeof(sun.sun_len) + sizeof(sun.sun_family) +
+ strlen(sun.sun_path) + 1;
+ sock = RPC_ANYSOCK;
+ client = clntunix_create(&sun, prog, vers, &sock, 0, 0);
+ if (client == NULL)
+ return(NULL);
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, &tv);
+ return(client);
+ }
+#endif
+
+ h = gethostbyname(hostname);
+ if (h == NULL) {
+ rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
+ return (NULL);
+ }
+ if (h->h_addrtype != AF_INET) {
+ /*
+ * Only support INET for now
+ */
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_len = sizeof(struct sockaddr_in);
+ sin.sin_family = h->h_addrtype;
+ sin.sin_port = 0;
+ memcpy((char*)&sin.sin_addr, h->h_addr, h->h_length);
+ p = getprotobyname(proto);
+ if (p == NULL) {
+ rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
+ rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
+ return (NULL);
+ }
+ sock = RPC_ANYSOCK;
+ switch (p->p_proto) {
+ case IPPROTO_UDP:
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ client = clntudp_create(&sin, prog, vers, tv, &sock);
+ if (client == NULL) {
+ return (NULL);
+ }
+#if 0 /* XXX do we need this? */
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, &tv);
+#endif
+ break;
+ case IPPROTO_TCP:
+ client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
+ if (client == NULL) {
+ return (NULL);
+ }
+#if 0 /* XXX do we need this? */
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, &tv);
+#endif
+ break;
+ default:
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
+ return (NULL);
+ }
+ return (client);
+}
diff --git a/cpukit/librpc/src/rpc/clnt_perror.c b/cpukit/librpc/src/rpc/clnt_perror.c
new file mode 100644
index 0000000000..1d2cfc0b40
--- /dev/null
+++ b/cpukit/librpc/src/rpc/clnt_perror.c
@@ -0,0 +1,259 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_perror.c,v 1.11 1999/08/28 00:00:35 peter Exp $";
+#endif
+
+/*
+ * clnt_perror.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/types.h>
+#include <rpc/auth.h>
+#include <rpc/clnt.h>
+
+static char *auth_errmsg(enum auth_stat stat);
+#define CLNT_PERROR_BUFLEN 256
+
+#define buf (rtems_rpc_task_variables->clnt_perror_buf)
+
+static char *
+_buf(void)
+{
+
+ if (buf == 0)
+ buf = (char *)malloc(CLNT_PERROR_BUFLEN);
+ return (buf);
+}
+
+/*
+ * Print reply error info
+ */
+char *
+clnt_sperror(
+ CLIENT *rpch,
+ const char *s)
+{
+ struct rpc_err e;
+ char *err;
+ char *str = _buf();
+ char *strstart = str;
+
+ if (str == 0)
+ return (0);
+ CLNT_GETERR(rpch, &e);
+
+ (void) sprintf(str, "%s: %s", s, clnt_sperrno(e.re_status));
+ str += strlen(str);
+
+ switch (e.re_status) {
+ case RPC_SUCCESS:
+ case RPC_CANTENCODEARGS:
+ case RPC_CANTDECODERES:
+ case RPC_TIMEDOUT:
+ case RPC_PROGUNAVAIL:
+ case RPC_PROCUNAVAIL:
+ case RPC_CANTDECODEARGS:
+ case RPC_SYSTEMERROR:
+ case RPC_UNKNOWNHOST:
+ case RPC_UNKNOWNPROTO:
+ case RPC_PMAPFAILURE:
+ case RPC_PROGNOTREGISTERED:
+ case RPC_FAILED:
+ break;
+
+ case RPC_CANTSEND:
+ case RPC_CANTRECV:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN - (str - strstart),
+ "; errno = %s\n", strerror(e.re_errno));
+ break;
+
+ case RPC_VERSMISMATCH:
+ (void) sprintf(str,
+ "; low version = %lu, high version = %lu\n",
+ (u_long)e.re_vers.low, (u_long)e.re_vers.high);
+ break;
+
+ case RPC_AUTHERROR:
+ err = auth_errmsg(e.re_why);
+ (void) sprintf(str,"; why = ");
+ str += strlen(str);
+ if (err != NULL) {
+ (void) sprintf(str, "%s\n",err);
+ } else {
+ (void) sprintf(str,
+ "(unknown authentication error - %d)\n",
+ (int) e.re_why);
+ }
+ break;
+
+ case RPC_PROGVERSMISMATCH:
+ (void) sprintf(str,
+ "; low version = %lu, high version = %lu\n",
+ (u_long)e.re_vers.low, (u_long)e.re_vers.high);
+ break;
+
+ default: /* unknown */
+ (void) sprintf(str,
+ "; s1 = %lu, s2 = %lu\n",
+ (long)e.re_lb.s1, (long)e.re_lb.s2);
+ break;
+ }
+ strstart[CLNT_PERROR_BUFLEN-2] = '\n';
+ strstart[CLNT_PERROR_BUFLEN-1] = '\0';
+ return(strstart) ;
+}
+
+void
+clnt_perror(
+ CLIENT *rpch,
+ const char *s)
+{
+ (void) fprintf(stderr,"%s\n",clnt_sperror(rpch,s));
+}
+
+
+static const char *const rpc_errlist[] = {
+ "RPC: Success", /* 0 - RPC_SUCCESS */
+ "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */
+ "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */
+ "RPC: Unable to send", /* 3 - RPC_CANTSEND */
+ "RPC: Unable to receive", /* 4 - RPC_CANTRECV */
+ "RPC: Timed out", /* 5 - RPC_TIMEDOUT */
+ "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */
+ "RPC: Authentication error", /* 7 - RPC_AUTHERROR */
+ "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */
+ "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */
+ "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */
+ "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */
+ "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */
+ "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */
+ "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */
+ "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */
+ "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */
+ "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */
+};
+
+
+/*
+ * This interface for use by clntrpc
+ */
+char *
+clnt_sperrno(
+ enum clnt_stat stat)
+{
+ unsigned int errnum = stat;
+
+ if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
+ return (char *)rpc_errlist[errnum];
+
+ return ("RPC: (unknown error code)");
+}
+
+void
+clnt_perrno(
+ enum clnt_stat num)
+{
+ (void) fprintf(stderr,"%s\n",clnt_sperrno(num));
+}
+
+
+char *
+clnt_spcreateerror(
+ const char *s)
+{
+ char *str = _buf();
+
+ if (str == 0)
+ return(0);
+ switch (rpc_createerr.cf_stat) {
+ case RPC_PMAPFAILURE:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s - %s\n", s,
+ clnt_sperrno(rpc_createerr.cf_stat),
+ clnt_sperrno(rpc_createerr.cf_error.re_status));
+ break;
+
+ case RPC_SYSTEMERROR:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s - %s\n", s,
+ clnt_sperrno(rpc_createerr.cf_stat),
+ strerror(rpc_createerr.cf_error.re_errno));
+ break;
+ default:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s\n", s,
+ clnt_sperrno(rpc_createerr.cf_stat));
+ break;
+ }
+ str[CLNT_PERROR_BUFLEN-2] = '\n';
+ str[CLNT_PERROR_BUFLEN-1] = '\0';
+ return (str);
+}
+
+void
+clnt_pcreateerror(
+ const char *s)
+{
+ (void) fprintf(stderr,"%s\n",clnt_spcreateerror(s));
+}
+
+static const char *const auth_errlist[] = {
+ "Authentication OK", /* 0 - AUTH_OK */
+ "Invalid client credential", /* 1 - AUTH_BADCRED */
+ "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */
+ "Invalid client verifier", /* 3 - AUTH_BADVERF */
+ "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */
+ "Client credential too weak", /* 5 - AUTH_TOOWEAK */
+ "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */
+ "Failed (unspecified error)" /* 7 - AUTH_FAILED */
+};
+
+static char *
+auth_errmsg(
+ enum auth_stat stat)
+{
+ unsigned int errnum = stat;
+
+ if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
+ return (char *)auth_errlist[errnum];
+
+ return(NULL);
+}
diff --git a/cpukit/librpc/src/rpc/clnt_raw.c b/cpukit/librpc/src/rpc/clnt_raw.c
new file mode 100644
index 0000000000..c522cecc7e
--- /dev/null
+++ b/cpukit/librpc/src/rpc/clnt_raw.c
@@ -0,0 +1,248 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_raw.c,v 1.10 1999/08/28 00:00:36 peter Exp $";
+#endif
+
+/*
+ * clnt_raw.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Memory based rpc for simple testing and timing.
+ * Interface to create an rpc client and server in the same process.
+ * This lets us similate rpc and get round trip overhead, without
+ * any interference from the kernel.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define MCALL_MSG_SIZE 24
+
+/*
+ * This is the "network" we will be moving stuff over.
+ */
+struct clnt_raw_private {
+ CLIENT client_object;
+ XDR xdr_stream;
+ char _raw_buf[UDPMSGSIZE];
+ union {
+ struct rpc_msg mashl_rpcmsg;
+ char mashl_callmsg[MCALL_MSG_SIZE];
+ } u;
+ u_int mcnt;
+};
+#define clntraw_private (rtems_rpc_task_variables->clnt_raw_private)
+
+static enum clnt_stat clntraw_call(CLIENT *h, rpcproc_t proc, xdrproc_t xargs, void *argsp, xdrproc_t xresults, void *resultsp, struct timeval timeout);
+static void clntraw_abort(void);
+static void clntraw_geterr(CLIENT *h, struct rpc_err*);
+static bool_t clntraw_freeres(CLIENT *, xdrproc_t, void*);
+static bool_t clntraw_control(CLIENT *, int, char *);
+static void clntraw_destroy(CLIENT *);
+
+static struct clnt_ops client_ops = {
+ clntraw_call,
+ clntraw_abort,
+ clntraw_geterr,
+ clntraw_freeres,
+ clntraw_destroy,
+ clntraw_control
+};
+
+/*
+ * Create a client handle for memory based rpc.
+ */
+CLIENT *
+clntraw_create(
+ u_long prog,
+ u_long vers )
+{
+ struct clnt_raw_private *clp = clntraw_private;
+ struct rpc_msg call_msg;
+ XDR *xdrs = &clp->xdr_stream;
+ CLIENT *client = &clp->client_object;
+
+ if (clp == 0) {
+ clp = (struct clnt_raw_private *)calloc(1, sizeof (*clp));
+ if (clp == 0)
+ return (0);
+ clntraw_private = clp;
+ }
+ /*
+ * pre-serialize the static part of the call msg and stash it away
+ */
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+ xdrmem_create(xdrs, clp->u.mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
+ if (! xdr_callhdr(xdrs, &call_msg)) {
+ perror("clnt_raw.c - Fatal header serialization error.");
+ }
+ clp->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+
+ /*
+ * Set xdrmem for client/server shared buffer
+ */
+ xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+
+ /*
+ * create client handle
+ */
+ client->cl_ops = &client_ops;
+ client->cl_auth = authnone_create();
+ return (client);
+}
+
+static enum clnt_stat
+clntraw_call(
+ CLIENT *h,
+ rpcproc_t proc,
+ xdrproc_t xargs,
+ void *argsp,
+ xdrproc_t xresults,
+ void *resultsp,
+ struct timeval timeout )
+{
+ struct clnt_raw_private *clp = clntraw_private;
+ XDR *xdrs = &clp->xdr_stream;
+ struct rpc_msg msg;
+ enum clnt_stat status;
+ struct rpc_err error;
+
+ if (clp == 0)
+ return (RPC_FAILED);
+call_again:
+ /*
+ * send request
+ */
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ clp->u.mashl_rpcmsg.rm_xid ++ ;
+ if ((! XDR_PUTBYTES(xdrs, clp->u.mashl_callmsg, clp->mcnt)) ||
+ (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
+ (! (*xargs)(xdrs, argsp))) {
+ return (RPC_CANTENCODEARGS);
+ }
+ (void)XDR_GETPOS(xdrs); /* called just to cause overhead */
+
+ /*
+ * We have to call server input routine here because this is
+ * all going on in one process. Yuk.
+ */
+ svc_getreq(1);
+
+ /*
+ * get results
+ */
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = resultsp;
+ msg.acpted_rply.ar_results.proc = xresults;
+ if (! xdr_replymsg(xdrs, &msg))
+ return (RPC_CANTDECODERES);
+ _seterr_reply(&msg, &error);
+ status = error.re_status;
+
+ if (status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
+ status = RPC_AUTHERROR;
+ }
+ } /* end successful completion */
+ else {
+ if (AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+
+ if (status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
+ status = RPC_AUTHERROR;
+ }
+ if (msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
+ }
+ }
+
+ return (status);
+}
+
+static void
+clntraw_geterr(CLIENT *cl, struct rpc_err *err)
+{
+}
+
+
+static bool_t
+clntraw_freeres(
+ CLIENT *cl,
+ xdrproc_t xdr_res,
+ void *res_ptr )
+{
+ struct clnt_raw_private *clp = clntraw_private;
+ XDR *xdrs = &clp->xdr_stream;
+ bool_t rval;
+
+ if (clp == 0)
+ {
+ rval = (bool_t) RPC_FAILED;
+ return (rval);
+ }
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clntraw_abort(void)
+{
+}
+
+static bool_t
+clntraw_control(CLIENT *cl, int request, char *info)
+{
+ return (FALSE);
+}
+
+static void
+clntraw_destroy(CLIENT *cl)
+{
+}
diff --git a/cpukit/librpc/src/rpc/clnt_simple.c b/cpukit/librpc/src/rpc/clnt_simple.c
new file mode 100644
index 0000000000..3cf17b4350
--- /dev/null
+++ b/cpukit/librpc/src/rpc/clnt_simple.c
@@ -0,0 +1,127 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_simple.c,v 1.12 2000/01/27 23:06:35 jasone Exp $";
+#endif
+
+/*
+ * clnt_simple.c
+ * Simplified front end to rpc.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+struct call_rpc_private {
+ CLIENT *client;
+ int socket;
+ int oldprognum, oldversnum, valid;
+ char *oldhost;
+};
+#define callrpc_private (rtems_rpc_task_variables->call_rpc_private)
+
+int
+callrpc(
+ char *host,
+ int prognum, int versnum, int procnum,
+ xdrproc_t inproc, char *in,
+ xdrproc_t outproc, char *out )
+{
+ register struct call_rpc_private *crp = callrpc_private;
+ struct sockaddr_in server_addr;
+ enum clnt_stat clnt_stat;
+ struct hostent *hp;
+ struct timeval timeout, tottimeout;
+
+ if (crp == 0) {
+ crp = (struct call_rpc_private *)calloc(1, sizeof (*crp));
+ if (crp == 0)
+ return (0);
+ callrpc_private = crp;
+ }
+ if (crp->oldhost == NULL) {
+ crp->oldhost = malloc(MAXHOSTNAMELEN);
+ crp->oldhost[0] = 0;
+ crp->socket = RPC_ANYSOCK;
+ }
+ if (crp->valid && crp->oldprognum == prognum && crp->oldversnum == versnum
+ && strcmp(crp->oldhost, host) == 0) {
+ /* reuse old client */
+ } else {
+ crp->valid = 0;
+ if (crp->socket != -1)
+ (void)_RPC_close(crp->socket);
+ crp->socket = RPC_ANYSOCK;
+ if (crp->client) {
+ clnt_destroy(crp->client);
+ crp->client = NULL;
+ }
+ if ((hp = gethostbyname(host)) == NULL)
+ return ((int) RPC_UNKNOWNHOST);
+ timeout.tv_usec = 0;
+ timeout.tv_sec = 5;
+ memset(&server_addr, 0, sizeof(server_addr));
+ memcpy((char *)&server_addr.sin_addr, hp->h_addr, hp->h_length);
+ server_addr.sin_len = sizeof(struct sockaddr_in);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+ if ((crp->client = clntudp_create(&server_addr, (u_long)prognum,
+ (u_long)versnum, timeout, &crp->socket)) == NULL)
+ return ((int) rpc_createerr.cf_stat);
+ crp->valid = 1;
+ crp->oldprognum = prognum;
+ crp->oldversnum = versnum;
+ (void) strcpy(crp->oldhost, host);
+ }
+ tottimeout.tv_sec = 25;
+ tottimeout.tv_usec = 0;
+ clnt_stat = clnt_call(crp->client, procnum, inproc, in,
+ outproc, out, tottimeout);
+ /*
+ * if call failed, empty cache
+ */
+ if (clnt_stat != RPC_SUCCESS)
+ crp->valid = 0;
+ return ((int) clnt_stat);
+}
diff --git a/cpukit/librpc/src/rpc/clnt_tcp.c b/cpukit/librpc/src/rpc/clnt_tcp.c
new file mode 100644
index 0000000000..f53edae638
--- /dev/null
+++ b/cpukit/librpc/src/rpc/clnt_tcp.c
@@ -0,0 +1,605 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_tcp.c,v 1.14 2000/01/27 23:06:36 jasone Exp $";
+#endif
+
+/*
+ * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * TCP based RPC supports 'batched calls'.
+ * A sequence of calls may be batched-up in a send buffer. The rpc call
+ * return immediately to the client even though the call was not necessarily
+ * sent. The batching occurs if the results' xdr routine is NULL (0) AND
+ * the rpc timeout value is zero (see clnt.h, rpc).
+ *
+ * Clients should NOT casually batch calls that in fact return results; that is,
+ * the server side should be aware that a call is batched and not produce any
+ * return message. Batched calls that produce many result messages can
+ * deadlock (netlock) the client and the server....
+ *
+ * Now go hang yourself.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/select.h>
+
+#define MCALL_MSG_SIZE 24
+
+static int readtcp(char *, char*, int);
+static int writetcp(char *, char*, int);
+
+static enum clnt_stat clnttcp_call(CLIENT *, rpcproc_t, xdrproc_t, void*, xdrproc_t, void*, struct timeval);
+static void clnttcp_abort(void);
+static void clnttcp_geterr(CLIENT *, struct rpc_err*);
+static bool_t clnttcp_freeres(CLIENT *, xdrproc_t, void*);
+static bool_t clnttcp_control(CLIENT *, int, char *);
+static void clnttcp_destroy(CLIENT *);
+
+static struct clnt_ops tcp_ops = {
+ clnttcp_call,
+ clnttcp_abort,
+ clnttcp_geterr,
+ clnttcp_freeres,
+ clnttcp_destroy,
+ clnttcp_control
+};
+
+struct ct_data {
+ int ct_sock;
+ bool_t ct_closeit; /* close it on destroy */
+ struct timeval ct_wait; /* wait interval in milliseconds */
+ bool_t ct_waitset; /* wait set by clnt_control? */
+ struct sockaddr_in ct_addr;
+ struct rpc_err ct_error;
+ union {
+ char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
+ u_int32_t ct_mcalli;
+ } ct_u;
+ u_int ct_mpos; /* pos after marshal */
+ XDR ct_xdrs; /* XDR stream */
+};
+
+/*
+ * Create a client handle for a tcp/ip connection.
+ * If *sockp<0, *sockp is set to a newly created TCP socket and it is
+ * connected to raddr. If *sockp non-negative then
+ * raddr is ignored. The rpc/tcp package does buffering
+ * similar to stdio, so the client must pick send and receive buffer sizes,];
+ * 0 => use the default.
+ * If raddr->sin_port is 0, then a binder on the remote machine is
+ * consulted for the right port number.
+ * NB: *sockp is copied into a private area.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is set null authentication. Caller may wish to set this
+ * something more useful.
+ */
+CLIENT *
+clnttcp_create(
+ struct sockaddr_in *raddr,
+ u_long prog, /* program number */
+ u_long vers, /* version number */
+ int *sockp,
+ u_int sendsz,
+ u_int recvsz)
+{
+ CLIENT *h;
+ struct ct_data *ct = NULL; /* client handle */
+ struct timeval now;
+ struct rpc_msg call_msg;
+ static uintptr_t disrupt;
+
+ if (disrupt == 0)
+ disrupt = (uintptr_t)raddr;
+
+ h = (CLIENT *)mem_alloc(sizeof(*h));
+ if (h == NULL) {
+ (void)fprintf(stderr, "clnttcp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ ct = (struct ct_data *)mem_alloc(sizeof (*ct));
+ if (ct == NULL) {
+ (void)fprintf(stderr, "clnttcp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+
+ /*
+ * If no port number given ask the pmap for one
+ */
+ if (raddr->sin_port == 0) {
+ u_short port;
+ if ((port = pmap_getport(raddr, prog, vers, IPPROTO_TCP)) == 0) {
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ mem_free((caddr_t)h, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+ }
+ raddr->sin_port = htons(port);
+ }
+
+ /*
+ * If no socket given, open one
+ */
+ if (*sockp < 0) {
+ *sockp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ (void)bindresvport(*sockp, (struct sockaddr_in *)0);
+ if ((*sockp < 0)
+ || (connect(*sockp, (struct sockaddr *)raddr,
+ sizeof(*raddr)) < 0)) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ if (*sockp != -1)
+ (void)_RPC_close(*sockp);
+ goto fooy;
+ }
+ ct->ct_closeit = TRUE;
+ } else {
+ ct->ct_closeit = FALSE;
+ }
+
+ /*
+ * Set up private data struct
+ */
+ ct->ct_sock = *sockp;
+ ct->ct_wait.tv_usec = 0;
+ ct->ct_waitset = FALSE;
+ ct->ct_addr = *raddr;
+
+ /*
+ * Initialize call message
+ */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ call_msg.rm_xid = (++disrupt) ^ getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+
+ /*
+ * pre-serialize the static part of the call msg and stash it away
+ */
+ xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
+ XDR_ENCODE);
+ if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
+ if (ct->ct_closeit) {
+ (void)_RPC_close(*sockp);
+ }
+ goto fooy;
+ }
+ ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
+ XDR_DESTROY(&(ct->ct_xdrs));
+
+ /*
+ * Create a client handle which uses xdrrec for serialization
+ * and authnone for authentication.
+ */
+ xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
+ (caddr_t)ct, readtcp, writetcp);
+ h->cl_ops = &tcp_ops;
+ h->cl_private = (caddr_t) ct;
+ h->cl_auth = authnone_create();
+ return (h);
+
+fooy:
+ /*
+ * Something goofed, free stuff and barf
+ */
+ if (ct)
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ if (h)
+ mem_free((caddr_t)h, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+}
+
+static enum clnt_stat
+clnttcp_call(
+ CLIENT *h,
+ rpcproc_t proc,
+ xdrproc_t xdr_args,
+ void *args_ptr,
+ xdrproc_t xdr_results,
+ void *results_ptr,
+ struct timeval timeout)
+{
+ struct ct_data *ct = (struct ct_data *) h->cl_private;
+ XDR *xdrs = &(ct->ct_xdrs);
+ struct rpc_msg reply_msg;
+ u_int32_t x_id;
+ u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
+ bool_t shipnow;
+ int refreshes = 2;
+
+ if (!ct->ct_waitset) {
+ ct->ct_wait = timeout;
+ }
+
+ shipnow =
+ (xdr_results == (xdrproc_t)0 && timeout.tv_sec == 0
+ && timeout.tv_usec == 0) ? FALSE : TRUE;
+
+call_again:
+ xdrs->x_op = XDR_ENCODE;
+ ct->ct_error.re_status = RPC_SUCCESS;
+ x_id = ntohl(--(*msg_x_id));
+ if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
+ (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
+ (! (*xdr_args)(xdrs, args_ptr))) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTENCODEARGS;
+ (void)xdrrec_endofrecord(xdrs, TRUE);
+ return (ct->ct_error.re_status);
+ }
+ if (! xdrrec_endofrecord(xdrs, shipnow)) {
+ return (ct->ct_error.re_status = RPC_CANTSEND);
+ }
+ if (! shipnow) {
+ return (RPC_SUCCESS);
+ }
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
+ return(ct->ct_error.re_status = RPC_TIMEDOUT);
+ }
+
+
+ /*
+ * Keep receiving until we get a valid transaction id
+ */
+ xdrs->x_op = XDR_DECODE;
+ while (TRUE) {
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = NULL;
+ reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
+ if (! xdrrec_skiprecord(xdrs))
+ return (ct->ct_error.re_status);
+ /* now decode and validate the response header */
+ if (! xdr_replymsg(xdrs, &reply_msg)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ continue;
+ return (ct->ct_error.re_status);
+ }
+ if (reply_msg.rm_xid == x_id)
+ break;
+ }
+
+ /*
+ * process header
+ */
+ _seterr_reply(&reply_msg, &(ct->ct_error));
+ if (ct->ct_error.re_status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &reply_msg.acpted_rply.ar_verf)) {
+ ct->ct_error.re_status = RPC_AUTHERROR;
+ ct->ct_error.re_why = AUTH_INVALIDRESP;
+ } else if (! (*xdr_results)(xdrs, results_ptr)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTDECODERES;
+ }
+ /* free verifier ... */
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs, &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (refreshes-- && AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+ return (ct->ct_error.re_status);
+}
+
+static void
+clnttcp_geterr(
+ CLIENT *h,
+ struct rpc_err *errp)
+{
+ struct ct_data *ct;
+
+ ct = (struct ct_data *) h->cl_private;
+ *errp = ct->ct_error;
+}
+
+static bool_t
+clnttcp_freeres(
+ CLIENT *cl,
+ xdrproc_t xdr_res,
+ void *res_ptr)
+{
+ struct ct_data *ct;
+ XDR *xdrs;
+
+ ct = (struct ct_data *)cl->cl_private;
+ xdrs = &(ct->ct_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clnttcp_abort(void)
+{
+}
+
+
+static bool_t
+clnttcp_control(
+ CLIENT *cl,
+ int request,
+ char *info)
+{
+ struct ct_data *ct;
+ struct timeval *tv;
+ socklen_t len;
+
+ ct = (struct ct_data *)cl->cl_private;
+
+ switch (request) {
+ case CLSET_FD_CLOSE:
+ ct->ct_closeit = TRUE;
+ break;
+ case CLSET_FD_NCLOSE:
+ ct->ct_closeit = FALSE;
+ break;
+ case CLSET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ ct->ct_wait.tv_sec = tv->tv_sec;
+ ct->ct_wait.tv_usec = tv->tv_usec;
+ ct->ct_waitset = TRUE;
+ break;
+ case CLGET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = ct->ct_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ if (info == NULL)
+ return(FALSE);
+ *(struct sockaddr_in *)info = ct->ct_addr;
+ break;
+ case CLGET_FD:
+ if (info == NULL)
+ return(FALSE);
+ *(int *)info = ct->ct_sock;
+ break;
+ case CLGET_XID:
+ /*
+ * use the knowledge that xid is the
+ * first element in the call structure
+ * This will get the xid of the PREVIOUS call
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_int32_t *)info =
+ ntohl(*(u_int32_t *)&ct->ct_u.ct_mcalli);
+ break;
+ case CLSET_XID:
+ /* This will set the xid of the NEXT call */
+ if (info == NULL)
+ return(FALSE);
+ *(u_int32_t *)&ct->ct_u.ct_mcalli =
+ htonl(*((u_int32_t *)info) + 1);
+ /* decrement by 1 as clnttcp_call() increments once */
+ case CLGET_VERS:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the version number field is the fifth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_int32_t *)info =
+ ntohl(*(u_int32_t *)(ct->ct_u.ct_mcallc +
+ 4 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_VERS:
+ if (info == NULL)
+ return(FALSE);
+ *(u_int32_t *)(ct->ct_u.ct_mcallc +
+ 4 * BYTES_PER_XDR_UNIT) =
+ htonl(*(u_int32_t *)info);
+ break;
+
+ case CLGET_PROG:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the program number field is the fourth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_int32_t *)info = ntohl(*(u_int32_t *)(ct->ct_u.ct_mcallc +
+ 3 * BYTES_PER_XDR_UNIT));
+ break;
+
+ case CLSET_PROG:
+ if (info == NULL)
+ return(FALSE);
+ *(u_int32_t *)(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_int32_t *)info);
+ break;
+
+ case CLGET_LOCAL_ADDR:
+ len = sizeof(struct sockaddr);
+ if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0)
+ return(FALSE);
+ break;
+
+ case CLGET_RETRY_TIMEOUT:
+ case CLSET_RETRY_TIMEOUT:
+ case CLGET_SVC_ADDR:
+ case CLSET_SVC_ADDR:
+ case CLSET_PUSH_TIMOD:
+ case CLSET_POP_TIMOD:
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+
+static void
+clnttcp_destroy(
+ CLIENT *h)
+{
+ struct ct_data *ct =
+ (struct ct_data *) h->cl_private;
+
+ if (ct->ct_closeit) {
+ (void)_RPC_close(ct->ct_sock);
+ }
+ XDR_DESTROY(&(ct->ct_xdrs));
+ mem_free(ct, sizeof(struct ct_data));
+ mem_free(h, sizeof(CLIENT));
+}
+
+/*
+ * Interface between xdr serializer and tcp connection.
+ * Behaves like the system calls, read & write, but keeps some error state
+ * around for the rpc level.
+ */
+static int
+readtcp(
+ char *_ct,
+ char *buf,
+ int len)
+{
+ struct ct_data *ct = (struct ct_data*) _ct;
+ fd_set *fds, readfds;
+ struct timeval start, after, duration, delta, tmp, tv;
+ int r, save_errno;
+
+ if (len == 0)
+ return (0);
+
+ if (ct->ct_sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(ct->ct_sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL)
+ return (-1);
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ gettimeofday(&start, NULL);
+ delta = ct->ct_wait;
+ while (TRUE) {
+ /* XXX we know the other bits are still clear */
+ FD_SET(ct->ct_sock, fds);
+ tv = delta; /* in case select writes back */
+ r = select(ct->ct_sock+1, fds, NULL, NULL, &tv);
+ save_errno = errno;
+
+ gettimeofday(&after, NULL);
+ timersub(&start, &after, &duration);
+ timersub(&ct->ct_wait, &duration, &tmp);
+ delta = tmp;
+ if (delta.tv_sec < 0 || !timerisset(&delta))
+ r = 0;
+
+ switch (r) {
+ case 0:
+ if (fds != &readfds)
+ free(fds);
+ ct->ct_error.re_status = RPC_TIMEDOUT;
+ return (-1);
+
+ case -1:
+ if (errno == EINTR)
+ continue;
+ if (fds != &readfds)
+ free(fds);
+ ct->ct_error.re_status = RPC_CANTRECV;
+ ct->ct_error.re_errno = save_errno;
+ return (-1);
+ }
+ break;
+ }
+ switch (len = _RPC_read(ct->ct_sock, buf, len)) {
+
+ case 0:
+ /* premature eof */
+ ct->ct_error.re_errno = ECONNRESET;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ len = -1; /* it's really an error */
+ break;
+
+ case -1:
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ break;
+ }
+ return (len);
+}
+
+static int
+writetcp(
+ char *_ct,
+ char *buf,
+ int len)
+{
+ struct ct_data *ct = (struct ct_data *) _ct;
+ int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = _RPC_write(ct->ct_sock, buf, cnt)) == -1) {
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTSEND;
+ return (-1);
+ }
+ }
+ return (len);
+}
diff --git a/cpukit/librpc/src/rpc/clnt_udp.c b/cpukit/librpc/src/rpc/clnt_udp.c
new file mode 100644
index 0000000000..aeace640a8
--- /dev/null
+++ b/cpukit/librpc/src/rpc/clnt_udp.c
@@ -0,0 +1,571 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_udp.c,v 1.15 2000/01/27 23:06:36 jasone Exp $";
+#endif
+
+/*
+ * clnt_udp.c, Implements a UDP/IP based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/select.h>
+
+/*
+ * UDP bases client side rpc operations
+ */
+static enum clnt_stat clntudp_call(CLIENT *, rpcproc_t, xdrproc_t, void*, xdrproc_t, void*, struct timeval);
+static void clntudp_abort(void);
+static void clntudp_geterr(CLIENT *, struct rpc_err*);
+static bool_t clntudp_freeres(CLIENT *, xdrproc_t, void*);
+static bool_t clntudp_control(CLIENT *, int, char *);
+static void clntudp_destroy(CLIENT *);
+
+static struct clnt_ops udp_ops = {
+ clntudp_call,
+ clntudp_abort,
+ clntudp_geterr,
+ clntudp_freeres,
+ clntudp_destroy,
+ clntudp_control
+};
+
+/*
+ * Private data kept per client handle
+ */
+struct cu_data {
+ int cu_sock;
+ bool_t cu_closeit; /* opened by library */
+ struct sockaddr_in cu_raddr;
+ int cu_rlen;
+ struct timeval cu_wait; /* retransmit interval */
+ struct timeval cu_total; /* total time for the call */
+ struct rpc_err cu_error;
+ XDR cu_outxdrs;
+ u_int cu_xdrpos;
+ u_int cu_sendsz; /* send size */
+ char *cu_outbuf;
+ u_int cu_recvsz; /* recv size */
+ char cu_inbuf[1];
+};
+
+/*
+ * Create a UDP based client handle.
+ * If *sockp<0, *sockp is set to a newly created UPD socket.
+ * If raddr->sin_port is 0 a binder on the remote machine
+ * is consulted for the correct port number.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is initialized to null authentication.
+ * Caller may wish to set this something more useful.
+ *
+ * wait is the amount of time used between retransmitting a call if
+ * no response has been heard; retransmition occurs until the actual
+ * rpc call times out.
+ *
+ * sendsz and recvsz are the maximum allowable packet sizes that can be
+ * sent and received.
+ */
+CLIENT *
+clntudp_bufcreate(
+ struct sockaddr_in *raddr,
+ u_long program, /* program number */
+ u_long version, /* version number */
+ struct timeval wait,
+ int *sockp,
+ u_int sendsz,
+ u_int recvsz)
+{
+ CLIENT *cl = NULL; /* client handle */
+ struct cu_data *cu = NULL; /* private data */
+ struct timeval now;
+ struct rpc_msg call_msg;
+ static uintptr_t disrupt;
+
+ if (disrupt == 0)
+ disrupt = (uintptr_t)raddr;
+
+ cl = (CLIENT *)mem_alloc(sizeof(CLIENT));
+ if (cl == NULL) {
+ (void) fprintf(stderr, "clntudp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ sendsz = ((sendsz + 3) / 4) * 4;
+ recvsz = ((recvsz + 3) / 4) * 4;
+ cu = mem_alloc(sizeof (*cu) + sendsz + recvsz);
+ if (cu == NULL) {
+ (void) fprintf(stderr, "clntudp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ cu->cu_outbuf = &cu->cu_inbuf[recvsz];
+
+ (void)gettimeofday(&now, (struct timezone *)0);
+ if (raddr->sin_port == 0) {
+ u_short port;
+ if ((port =
+ pmap_getport(raddr, program, version, IPPROTO_UDP)) == 0) {
+ goto fooy;
+ }
+ raddr->sin_port = htons(port);
+ }
+ cl->cl_ops = &udp_ops;
+ cl->cl_private = (caddr_t)cu;
+ cu->cu_raddr = *raddr;
+ cu->cu_rlen = sizeof (cu->cu_raddr);
+ cu->cu_wait = wait;
+ cu->cu_total.tv_sec = -1;
+ cu->cu_total.tv_usec = -1;
+ cu->cu_sendsz = sendsz;
+ cu->cu_recvsz = recvsz;
+ call_msg.rm_xid = (++disrupt) ^ getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = program;
+ call_msg.rm_call.cb_vers = version;
+ xdrmem_create(&(cu->cu_outxdrs), cu->cu_outbuf,
+ sendsz, XDR_ENCODE);
+ if (! xdr_callhdr(&(cu->cu_outxdrs), &call_msg)) {
+ goto fooy;
+ }
+ cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
+ if (*sockp < 0) {
+ int dontblock = 1;
+
+ *sockp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (*sockp < 0) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ /* attempt to bind to priv port */
+ (void)bindresvport(*sockp, (struct sockaddr_in *)0);
+ /* the sockets rpc controls are non-blocking */
+ (void)ioctl(*sockp, FIONBIO, (char *) &dontblock);
+ cu->cu_closeit = TRUE;
+ } else {
+ cu->cu_closeit = FALSE;
+ }
+ cu->cu_sock = *sockp;
+ cl->cl_auth = authnone_create();
+ return (cl);
+fooy:
+ if (cu)
+ mem_free((caddr_t)cu, sizeof(*cu) + sendsz + recvsz);
+ if (cl)
+ mem_free((caddr_t)cl, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+}
+
+CLIENT *
+clntudp_create(
+ struct sockaddr_in *raddr,
+ u_long program, /* program number */
+ u_long version, /* version number */
+ struct timeval wait,
+ int *sockp)
+{
+
+ return(clntudp_bufcreate(raddr, program, version, wait, sockp,
+ UDPMSGSIZE, UDPMSGSIZE));
+}
+
+static enum clnt_stat
+clntudp_call(
+ CLIENT *cl, /* client handle */
+ rpcproc_t proc, /* procedure number */
+ xdrproc_t xargs, /* xdr routine for args */
+ void *argsp, /* pointer to args */
+ xdrproc_t xresults, /* xdr routine for results */
+ void *resultsp, /* pointer to results */
+ struct timeval utimeout ) /* seconds to wait before giving up */
+{
+ struct cu_data *cu = (struct cu_data *)cl->cl_private;
+ XDR *xdrs;
+ size_t outlen = 0;
+ int inlen;
+ socklen_t fromlen;
+ fd_set *fds, readfds;
+ struct sockaddr_in from;
+ struct rpc_msg reply_msg;
+ XDR reply_xdrs;
+ struct timeval time_waited, start, after, tmp1, tmp2, tv;
+ bool_t ok;
+ int nrefreshes = 2; /* number of times to refresh cred */
+ struct timeval timeout;
+
+ if (cu->cu_total.tv_usec == -1)
+ timeout = utimeout; /* use supplied timeout */
+ else
+ timeout = cu->cu_total; /* use default timeout */
+
+ if (cu->cu_sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(cu->cu_sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL)
+ return (cu->cu_error.re_status = RPC_CANTSEND);
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ timerclear(&time_waited);
+
+call_again:
+ xdrs = &(cu->cu_outxdrs);
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, cu->cu_xdrpos);
+ /*
+ * the transaction is the first thing in the out buffer
+ */
+ (*(u_short *)(cu->cu_outbuf))++;
+ if ((! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
+ (! (*xargs)(xdrs, argsp))) {
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
+ }
+ outlen = (size_t)XDR_GETPOS(xdrs);
+
+send_again:
+ if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0,
+ (struct sockaddr *)&(cu->cu_raddr), cu->cu_rlen) != outlen) {
+ cu->cu_error.re_errno = errno;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTSEND);
+ }
+
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (!timerisset(&timeout)) {
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+ }
+ /*
+ * sub-optimal code appears here because we have
+ * some clock time to spare while the packets are in flight.
+ * (We assume that this is actually only executed once.)
+ */
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = resultsp;
+ reply_msg.acpted_rply.ar_results.proc = xresults;
+
+ gettimeofday(&start, NULL);
+ for (;;) {
+ /* XXX we know the other bits are still clear */
+ FD_SET(cu->cu_sock, fds);
+ tv = cu->cu_wait;
+ switch (select(cu->cu_sock+1, fds, NULL, NULL, &tv)) {
+
+ case 0:
+ timeradd(&time_waited, &cu->cu_wait, &tmp1);
+ time_waited = tmp1;
+ if (timercmp(&time_waited, &timeout, <))
+ goto send_again;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+
+ case -1:
+ if (errno == EINTR) {
+ gettimeofday(&after, NULL);
+ timersub(&after, &start, &tmp1);
+ timeradd(&time_waited, &tmp1, &tmp2);
+ time_waited = tmp2;
+ if (timercmp(&time_waited, &timeout, <))
+ continue;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+ }
+ cu->cu_error.re_errno = errno;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTRECV);
+ }
+
+ do {
+ fromlen = sizeof(struct sockaddr);
+ inlen = recvfrom(cu->cu_sock, cu->cu_inbuf,
+ (int) cu->cu_recvsz, 0,
+ (struct sockaddr *)&from, &fromlen);
+ } while (inlen < 0 && errno == EINTR);
+ if (inlen < 0) {
+ if (errno == EWOULDBLOCK)
+ continue;
+ cu->cu_error.re_errno = errno;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTRECV);
+ }
+ if (inlen < sizeof(u_int32_t))
+ continue;
+ /* see if reply transaction id matches sent id */
+ if (*((u_int32_t *)(cu->cu_inbuf)) != *((u_int32_t *)(cu->cu_outbuf)))
+ continue;
+ /* we now assume we have the proper reply */
+ break;
+ }
+
+ /*
+ * now decode and validate the response
+ */
+ xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)inlen, XDR_DECODE);
+ ok = xdr_replymsg(&reply_xdrs, &reply_msg);
+ /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
+ if (ok) {
+ _seterr_reply(&reply_msg, &(cu->cu_error));
+ if (cu->cu_error.re_status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(cl->cl_auth,
+ &reply_msg.acpted_rply.ar_verf)) {
+ cu->cu_error.re_status = RPC_AUTHERROR;
+ cu->cu_error.re_why = AUTH_INVALIDRESP;
+ }
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs,
+ &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (nrefreshes > 0 && AUTH_REFRESH(cl->cl_auth)) {
+ nrefreshes--;
+ goto call_again;
+ }
+ } /* end of unsuccessful completion */
+ } /* end of valid reply message */
+ else {
+ /*
+ * It's possible for xdr_replymsg() to fail partway
+ * through its attempt to decode the result from the
+ * server. If this happens, it will leave the reply
+ * structure partially populated with dynamically
+ * allocated memory. (This can happen if someone uses
+ * clntudp_bufcreate() to create a CLIENT handle and
+ * specifies a receive buffer size that is too small.)
+ * This memory must be free()ed to avoid a leak.
+ */
+ int op = reply_xdrs.x_op;
+ reply_xdrs.x_op = XDR_FREE;
+ xdr_replymsg(&reply_xdrs, &reply_msg);
+ reply_xdrs.x_op = op;
+ cu->cu_error.re_status = RPC_CANTDECODERES;
+ }
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status);
+}
+
+static void
+clntudp_geterr(
+ CLIENT *cl,
+ struct rpc_err *errp)
+{
+ struct cu_data *cu = (struct cu_data *)cl->cl_private;
+
+ *errp = cu->cu_error;
+}
+
+
+static bool_t
+clntudp_freeres(
+ CLIENT *cl,
+ xdrproc_t xdr_res,
+ void *res_ptr)
+{
+ struct cu_data *cu = (struct cu_data *)cl->cl_private;
+ XDR *xdrs = &(cu->cu_outxdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clntudp_abort(void)
+{
+}
+
+
+static bool_t
+clntudp_control(
+ CLIENT *cl,
+ int request,
+ char *info)
+{
+ struct cu_data *cu = (struct cu_data *)cl->cl_private;
+ struct timeval *tv;
+ socklen_t len;
+
+ switch (request) {
+ case CLSET_FD_CLOSE:
+ cu->cu_closeit = TRUE;
+ break;
+ case CLSET_FD_NCLOSE:
+ cu->cu_closeit = FALSE;
+ break;
+ case CLSET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ cu->cu_total.tv_sec = tv->tv_sec;
+ cu->cu_total.tv_usec = tv->tv_usec;
+ break;
+ case CLGET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = cu->cu_total;
+ break;
+ case CLSET_RETRY_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ cu->cu_wait.tv_sec = tv->tv_sec;
+ cu->cu_wait.tv_usec = tv->tv_usec;
+ break;
+ case CLGET_RETRY_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = cu->cu_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ if (info == NULL)
+ return(FALSE);
+ *(struct sockaddr_in *)info = cu->cu_raddr;
+ break;
+ case CLGET_FD:
+ if (info == NULL)
+ return(FALSE);
+ *(int *)info = cu->cu_sock;
+ break;
+ case CLGET_XID:
+ /*
+ * use the knowledge that xid is the
+ * first element in the call structure *.
+ * This will get the xid of the PREVIOUS call
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)cu->cu_outbuf);
+ break;
+ case CLSET_XID:
+ /* This will set the xid of the NEXT call */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)cu->cu_outbuf = htonl(*(u_long *)info - 1);
+ /* decrement by 1 as clntudp_call() increments once */
+ case CLGET_VERS:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the version number field is the fifth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf +
+ 4 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_VERS:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_PROG:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the program number field is the fourth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf +
+ 3 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_PROG:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_LOCAL_ADDR:
+ len = sizeof(struct sockaddr);
+ if (getsockname(cu->cu_sock, (struct sockaddr *)info, &len) <0)
+ return(FALSE);
+ break;
+ case CLGET_SVC_ADDR:
+ case CLSET_SVC_ADDR:
+ case CLSET_PUSH_TIMOD:
+ case CLSET_POP_TIMOD:
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+static void
+clntudp_destroy(
+ CLIENT *cl)
+{
+ struct cu_data *cu = (struct cu_data *)cl->cl_private;
+
+ if (cu->cu_closeit) {
+ (void)_RPC_close(cu->cu_sock);
+ }
+ XDR_DESTROY(&(cu->cu_outxdrs));
+ mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
+ mem_free(cl, sizeof (CLIENT));
+}
diff --git a/cpukit/librpc/src/rpc/des_crypt.3 b/cpukit/librpc/src/rpc/des_crypt.3
new file mode 100644
index 0000000000..a92f577a56
--- /dev/null
+++ b/cpukit/librpc/src/rpc/des_crypt.3
@@ -0,0 +1,130 @@
+.\" @(#)des_crypt.3 2.1 88/08/11 4.0 RPCSRC; from 1.16 88/03/02 SMI;
+.\" $FreeBSD: src/lib/libc/rpc/des_crypt.3,v 1.4 2000/03/02 09:13:45 sheldonh Exp $
+.\"
+.TH DES_CRYPT 3 "6 October 1987"
+.SH NAME
+des_crypt, ecb_crypt, cbc_crypt, des_setparity \- fast DES encryption
+.SH SYNOPSIS
+.nf
+.B #include <des_crypt.h>
+.LP
+.B int ecb_crypt(key, data, datalen, mode)
+.B char *key;
+.B char *data;
+.B unsigned datalen;
+.B unsigned mode;
+.LP
+.B int cbc_crypt(key, data, datalen, mode, ivec)
+.B char *key;
+.B char *data;
+.B unsigned datalen;
+.B unsigned mode;
+.B char *ivec;
+.LP
+.B void des_setparity(key)
+.B char *key;
+.fi
+.SH DESCRIPTION
+.IX encryption cbc_crypt "" \fLcbc_crypt\fP
+.IX "des encryption" cbc_crypt "DES encryption" \fLcbc_crypt\fP
+.IX encryption des_setparity "" \fLdes_setparity\fP
+.IX "des encryption" des_setparity "DES encryption" \fLdes_setparity\fP
+.B ecb_crypt(\|)
+and
+.B cbc_crypt(\|)
+implement the
+.SM NBS
+.SM DES
+(Data Encryption Standard).
+These routines are faster and more general purpose than
+.BR crypt (3).
+They also are able to utilize
+.SM DES
+hardware if it is available.
+.B ecb_crypt(\|)
+encrypts in
+.SM ECB
+(Electronic Code Book)
+mode, which encrypts blocks of data independently.
+.B cbc_crypt(\|)
+encrypts in
+.SM CBC
+(Cipher Block Chaining)
+mode, which chains together
+successive blocks.
+.SM CBC
+mode protects against insertions, deletions and
+substitutions of blocks.
+Also, regularities in the clear text will
+not appear in the cipher text.
+.LP
+Here is how to use these routines. The first parameter,
+.IR key ,
+is the 8-byte encryption key with parity.
+To set the key's parity, which for
+.SM DES
+is in the low bit of each byte, use
+.IR des_setparity .
+The second parameter,
+.IR data ,
+contains the data to be encrypted or decrypted.
+The
+third parameter,
+.IR datalen ,
+is the length in bytes of
+.IR data ,
+which must be a multiple of 8. The fourth parameter,
+.IR mode ,
+is formed by
+.SM OR\s0'ing
+together some things. For the encryption direction 'or' in either
+.SM DES_ENCRYPT
+or
+.SM DES_DECRYPT\s0.
+For software versus hardware
+encryption, 'or' in either
+.SM DES_HW
+or
+.SM DES_SW\s0.
+If
+.SM DES_HW
+is specified, and there is no hardware, then the encryption is performed
+in software and the routine returns
+.SM DESERR_NOHWDEVICE\s0.
+For
+.IR cbc_crypt ,
+the parameter
+.I ivec
+is the the 8-byte initialization
+vector for the chaining. It is updated to the next initialization
+vector upon return.
+.LP
+.SH "SEE ALSO"
+.BR des (1),
+.BR crypt (3)
+.SH DIAGNOSTICS
+.PD 0
+.TP 20
+.SM DESERR_NONE
+No error.
+.TP
+.SM DESERR_NOHWDEVICE
+Encryption succeeded, but done in software instead of the requested hardware.
+.TP
+.SM DESERR_HWERR
+An error occurred in the hardware or driver.
+.TP
+.SM DESERR_BADPARAM
+Bad parameter to routine.
+.PD
+.LP
+Given a result status
+.IR stat ,
+the macro
+.SM DES_FAILED\c
+.BR ( stat )
+is false only for the first two statuses.
+.SH RESTRICTIONS
+These routines are not available in RPCSRC 4.0.
+This information is provided to describe the DES interface expected by
+Secure RPC.
diff --git a/cpukit/librpc/src/rpc/get_myaddress.c b/cpukit/librpc/src/rpc/get_myaddress.c
new file mode 100644
index 0000000000..0804c85e67
--- /dev/null
+++ b/cpukit/librpc/src/rpc/get_myaddress.c
@@ -0,0 +1,117 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)get_myaddress.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/get_myaddress.c,v 1.17 2000/01/27 23:06:37 jasone Exp $";
+#endif
+
+/*
+ * get_myaddress.c
+ *
+ * Get client's IP address via ioctl. This avoids using the yellowpages.
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mbuf.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * don't use gethostbyname, which would invoke yellow pages
+ *
+ * Avoid loopback interfaces. We return information from a loopback
+ * interface only if there are no other possible interfaces.
+ */
+int
+get_myaddress(
+ struct sockaddr_in *addr)
+{
+ int s;
+ char buf[BUFSIZ];
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr, *end;
+ int loopback = 0, gotit = 0;
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ return(-1);
+ }
+ ifc.ifc_len = sizeof (buf);
+ ifc.ifc_buf = buf;
+ if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
+ _RPC_close(s);
+ return(-1);
+ }
+again:
+ ifr = ifc.ifc_req;
+ end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+
+ while (ifr < end) {
+ ifreq = *ifr;
+ if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+ _RPC_close(s);
+ return(-1);
+ }
+ if (((ifreq.ifr_flags & IFF_UP) &&
+ ifr->ifr_addr.sa_family == AF_INET &&
+ !(ifreq.ifr_flags & IFF_LOOPBACK)) ||
+ (loopback == 1 && (ifreq.ifr_flags & IFF_LOOPBACK)
+ && (ifr->ifr_addr.sa_family == AF_INET)
+ && (ifreq.ifr_flags & IFF_UP))) {
+ *addr = *((struct sockaddr_in *)&ifr->ifr_addr);
+ addr->sin_port = htons(PMAPPORT);
+ gotit = 1;
+ break;
+ }
+ if (ifr->ifr_addr.sa_len)
+ ifr = (struct ifreq *) ((caddr_t) ifr +
+ ifr->ifr_addr.sa_len -
+ sizeof(struct sockaddr));
+ ifr++;
+ }
+ if (gotit == 0 && loopback == 0) {
+ loopback = 1;
+ goto again;
+ }
+ (void)_RPC_close(s);
+ return (gotit ? 0 : -1);
+}
diff --git a/cpukit/librpc/src/rpc/getrpcent.3 b/cpukit/librpc/src/rpc/getrpcent.3
new file mode 100644
index 0000000000..1e92e9d03d
--- /dev/null
+++ b/cpukit/librpc/src/rpc/getrpcent.3
@@ -0,0 +1,98 @@
+.\" @(#)getrpcent.3n 2.2 88/08/02 4.0 RPCSRC; from 1.11 88/03/14 SMI
+.\" $FreeBSD: src/lib/libc/rpc/getrpcent.3,v 1.11 1999/08/28 00:00:39 peter Exp $
+.\"
+.Dd December 14, 1987
+.Dt GETRPCENT 3
+.Os
+.Sh NAME
+.Nm getrpcent ,
+.Nm getrpcbyname ,
+.Nm getrpcbynumber ,
+.Nm endrpcent ,
+.Nm setrpcent
+.Nd get RPC entry
+.Sh SYNOPSIS
+.Fd #include <rpc/rpc.h>
+.Ft struct rpcent *
+.Fn getrpcent void
+.Ft struct rpcent *
+.Fn getrpcbyname "char *name"
+.Ft struct rpcent *
+.Fn getrpcbynumber "int number"
+.Ft void
+.Fn setrpcent "int stayopen"
+.Ft void
+.Fn endrpcent void
+.Sh DESCRIPTION
+The
+.Fn getrpcent ,
+.Fn getrpcbyname ,
+and
+.Fn getrpcbynumber
+functions each return a pointer to an object with the
+following structure
+containing the broken-out
+fields of a line in the rpc program number data base,
+.Pa /etc/rpc .
+.Bd -literal
+
+struct rpcent {
+ char *r_name; /* name of server for this rpc program */
+ char **r_aliases; /* alias list */
+ long r_number; /* rpc program number */
+};
+.Ed
+.Pp
+The members of this structure are:
+.Bl -tag -width r_aliasesxxx
+.It Fa r_name
+The name of the server for this rpc program.
+.It Fa r_aliases
+A zero terminated list of alternate names for the rpc program.
+.It Fa r_number
+The rpc program number for this service.
+.El
+.Pp
+The
+.Fn getrpcent
+function reads the next line of the file, opening the file if necessary.
+The
+.Nm getrpcent
+function opens and rewinds the file. If the
+.Fa stayopen
+flag is non-zero,
+the net data base will not be closed after each call to
+.Fn getrpcent
+(either directly, or indirectly through one of
+the other
+.Fn getrpcent
+function family.
+.Pp
+.Fn endrpcent
+closes the file.
+.Pp
+.Fn getrpcbyname
+and
+.Fn getrpcbynumber
+sequentially search from the beginning
+of the file until a matching rpc program name or
+program number is found, or until end-of-file is encountered.
+.Sh FILES
+.Bl -tag -width /etc/rpc -compact
+.It Pa /etc/rpc
+.El
+.Sh "SEE ALSO"
+.Xr rpc 5 ,
+.Xr rpcinfo 8 ,
+.Xr ypserv 8
+.Sh DIAGNOSTICS
+A
+.Dv NULL
+pointer is returned on
+.Dv EOF
+or error.
+.Sh BUGS
+All information
+is contained in a static area
+so it must be copied if it is
+to be saved.
diff --git a/cpukit/librpc/src/rpc/getrpcent.c b/cpukit/librpc/src/rpc/getrpcent.c
new file mode 100644
index 0000000000..fdd0f88ec2
--- /dev/null
+++ b/cpukit/librpc/src/rpc/getrpcent.c
@@ -0,0 +1,301 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/getrpcent.c,v 1.10 1999/08/28 00:00:39 peter Exp $";
+#endif
+
+/*
+ * Copyright (c) 1984 by Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+/*
+ * Internet version.
+ */
+struct rpcdata {
+ FILE *rpcf;
+ int stayopen;
+#define MAXALIASES 35
+ char *rpc_aliases[MAXALIASES];
+ struct rpcent rpc;
+ char line[BUFSIZ+1];
+#ifdef YP
+ char *domain;
+ char *current;
+ int currentlen;
+#endif
+} *rpcdata;
+
+#ifdef YP
+static int __yp_nomap = 0;
+extern int _yp_check(char **);
+#endif /* YP */
+
+static struct rpcent *interpret(char *val, int len);
+
+static char RPCDB[] = "/etc/rpc";
+
+static struct rpcdata *
+_rpcdata(void)
+{
+ register struct rpcdata *d = rpcdata;
+
+ if (d == 0) {
+ d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
+ rpcdata = d;
+ }
+ return (d);
+}
+
+struct rpcent *
+getrpcbynumber(int number)
+{
+ register struct rpcdata *d = _rpcdata();
+ register struct rpcent *p;
+#ifdef YP
+ int reason;
+ char adrstr[16];
+#endif
+
+ if (d == 0)
+ return (0);
+#ifdef YP
+ if (!__yp_nomap && _yp_check(&d->domain)) {
+ sprintf(adrstr, "%d", number);
+ reason = yp_match(d->domain, "rpc.bynumber", adrstr, strlen(adrstr),
+ &d->current, &d->currentlen);
+ switch(reason) {
+ case 0:
+ break;
+ case YPERR_MAP:
+ __yp_nomap = 1;
+ goto no_yp;
+ break;
+ default:
+ return(0);
+ break;
+ }
+ d->current[d->currentlen] = '\0';
+ p = interpret(d->current, d->currentlen);
+ (void) free(d->current);
+ return p;
+ }
+no_yp:
+#endif /* YP */
+ setrpcent(0);
+ while ((p = getrpcent())) {
+ if (p->r_number == number)
+ break;
+ }
+ endrpcent();
+ return (p);
+}
+
+struct rpcent *
+getrpcbyname(char *name)
+{
+ struct rpcent *rpc = NULL;
+ char **rp;
+
+ setrpcent(0);
+ while ((rpc = getrpcent())) {
+ if (strcmp(rpc->r_name, name) == 0)
+ goto done;
+ for (rp = rpc->r_aliases; *rp != NULL; rp++) {
+ if (strcmp(*rp, name) == 0)
+ goto done;
+ }
+ }
+done:
+ endrpcent();
+ return (rpc);
+}
+
+void
+setrpcent(int f)
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return;
+#ifdef YP
+ if (!__yp_nomap && _yp_check(NULL)) {
+ if (d->current)
+ free(d->current);
+ d->current = NULL;
+ d->currentlen = 0;
+ return;
+ }
+ __yp_nomap = 0;
+#endif /* YP */
+ if (d->rpcf == NULL)
+ d->rpcf = fopen(RPCDB, "r");
+ else
+ rewind(d->rpcf);
+ d->stayopen |= f;
+}
+
+void
+endrpcent(void)
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return;
+#ifdef YP
+ if (!__yp_nomap && _yp_check(NULL)) {
+ if (d->current && !d->stayopen)
+ free(d->current);
+ d->current = NULL;
+ d->currentlen = 0;
+ return;
+ }
+ __yp_nomap = 0;
+#endif /* YP */
+ if (d->rpcf && !d->stayopen) {
+ fclose(d->rpcf);
+ d->rpcf = NULL;
+ }
+}
+
+struct rpcent *
+getrpcent(void)
+{
+ register struct rpcdata *d = _rpcdata();
+#ifdef YP
+ struct rpcent *hp;
+ int reason;
+ char *val = NULL;
+ int vallen;
+#endif
+
+ if (d == 0)
+ return(NULL);
+#ifdef YP
+ if (!__yp_nomap && _yp_check(&d->domain)) {
+ if (d->current == NULL && d->currentlen == 0) {
+ reason = yp_first(d->domain, "rpc.bynumber",
+ &d->current, &d->currentlen,
+ &val, &vallen);
+ } else {
+ reason = yp_next(d->domain, "rpc.bynumber",
+ d->current, d->currentlen,
+ &d->current, &d->currentlen,
+ &val, &vallen);
+ }
+ switch(reason) {
+ case 0:
+ break;
+ case YPERR_MAP:
+ __yp_nomap = 1;
+ goto no_yp;
+ break;
+ default:
+ return(0);
+ break;
+ }
+ val[vallen] = '\0';
+ hp = interpret(val, vallen);
+ (void) free(val);
+ return hp;
+ }
+no_yp:
+#endif /* YP */
+ if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
+ return (NULL);
+ /* -1 so there is room to append a \n below */
+ if (fgets(d->line, BUFSIZ - 1, d->rpcf) == NULL)
+ return (NULL);
+ return (interpret(d->line, strlen(d->line)));
+}
+
+static struct rpcent *
+interpret(
+ char *val,
+ int len)
+{
+ register struct rpcdata *d = _rpcdata();
+ char *p;
+ register char *cp, **q;
+
+ if (d == 0)
+ return (0);
+ (void) strncpy(d->line, val, BUFSIZ);
+ d->line[BUFSIZ] = '\0';
+ p = d->line;
+ p[len] = '\n';
+ if (*p == '#')
+ return (getrpcent());
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ return (getrpcent());
+ *cp = '\0';
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ return (getrpcent());
+ *cp++ = '\0';
+ /* THIS STUFF IS INTERNET SPECIFIC */
+ d->rpc.r_name = d->line;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ d->rpc.r_number = atoi(cp);
+ q = d->rpc.r_aliases = d->rpc_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &(d->rpc_aliases[MAXALIASES - 1]))
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&d->rpc);
+}
diff --git a/cpukit/librpc/src/rpc/getrpcport.3 b/cpukit/librpc/src/rpc/getrpcport.3
new file mode 100644
index 0000000000..0e9175ec12
--- /dev/null
+++ b/cpukit/librpc/src/rpc/getrpcport.3
@@ -0,0 +1,31 @@
+.\" @(#)getrpcport.3r 2.2 88/08/02 4.0 RPCSRC; from 1.12 88/02/26 SMI
+.\" $FreeBSD: src/lib/libc/rpc/getrpcport.3,v 1.6 1999/08/28 00:00:40 peter Exp $
+.\"
+.Dd October 6, 1987
+.Dt GETRPCPORT 3
+.Os
+.Sh NAME
+.Nm getrpcport
+.Nd get RPC port number
+.Sh SYNOPSIS
+.Ft int
+.Fn getrpcport "char *host" "int prognum" "int versnum" "int proto"
+.Sh DESCRIPTION
+.Fn getrpcport
+returns the port number for version
+.Fa versnum
+of the RPC program
+.Fa prognum
+running on
+.Fa host
+and using protocol
+.Fa proto .
+It returns 0 if it cannot contact the portmapper, or if
+.Fa prognum
+is not registered. If
+.Fa prognum
+is registered but not with version
+.Fa versnum ,
+it will still return a port number (for some version of the program)
+indicating that the program is indeed registered.
+The version mismatch will be detected upon the first call to the service.
diff --git a/cpukit/librpc/src/rpc/getrpcport.c b/cpukit/librpc/src/rpc/getrpcport.c
new file mode 100644
index 0000000000..f783bac29b
--- /dev/null
+++ b/cpukit/librpc/src/rpc/getrpcport.c
@@ -0,0 +1,69 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)getrpcport.c 1.3 87/08/11 SMI";*/
+/*static char *sccsid = "from: @(#)getrpcport.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/getrpcport.c,v 1.10 1999/08/28 00:00:40 peter Exp $";
+#endif
+
+/*
+ * Copyright (c) 1985 by Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <netdb.h>
+#include <sys/socket.h>
+
+int
+getrpcport(
+ char *host,
+ int prognum,
+ int versnum,
+ int proto )
+{
+ struct sockaddr_in addr;
+ struct hostent *hp;
+
+ if ((hp = gethostbyname(host)) == NULL)
+ return (0);
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_len = sizeof(struct sockaddr_in);
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0;
+ memcpy((char *)&addr.sin_addr, hp->h_addr, hp->h_length);
+ return (pmap_getport(&addr, prognum, versnum, proto));
+}
diff --git a/cpukit/librpc/src/rpc/netname.c b/cpukit/librpc/src/rpc/netname.c
new file mode 100644
index 0000000000..e75ef73725
--- /dev/null
+++ b/cpukit/librpc/src/rpc/netname.c
@@ -0,0 +1,139 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro";
+#endif
+
+/*
+ * netname utility routines
+ * convert from unix names to network names and vice-versa
+ * This module is operating system dependent!
+ * What we define here will work with any unix system that has adopted
+ * the sun NIS domain architecture.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 256
+#endif
+#ifndef NGROUPS
+#define NGROUPS 16
+#endif
+
+static char *OPSYS = "unix";
+
+/*
+ * Figure out my fully qualified network name
+ */
+int
+getnetname(char name[MAXNETNAMELEN+1])
+{
+ uid_t uid;
+
+ uid = geteuid();
+ if (uid == 0) {
+ return (host2netname(name, (char *) NULL, (char *) NULL));
+ } else {
+ return (user2netname(name, uid, (char *) NULL));
+ }
+}
+
+
+/*
+ * Convert unix cred to network-name
+ */
+int
+user2netname(
+ char netname[MAXNETNAMELEN + 1],
+ uid_t uid,
+ char *domain)
+{
+ char *dfltdom;
+
+#define MAXIPRINT (11) /* max length of printed integer */
+
+ if (domain == NULL) {
+ if (_rpc_get_default_domain(&dfltdom) != 0) {
+ return (0);
+ }
+ domain = dfltdom;
+ }
+ if (strlen(domain) + 1 + MAXIPRINT > MAXNETNAMELEN) {
+ return (0);
+ }
+ (void) sprintf(netname, "%s.%ld@%s", OPSYS, (u_long)uid, domain);
+ return (1);
+}
+
+
+/*
+ * Convert host to network-name
+ */
+int
+host2netname(
+ char netname[MAXNETNAMELEN + 1],
+ char *host,
+ char *domain)
+{
+ char *dfltdom;
+ char hostname[MAXHOSTNAMELEN+1];
+
+ if (domain == NULL) {
+ if (_rpc_get_default_domain(&dfltdom) != 0) {
+ return (0);
+ }
+ domain = dfltdom;
+ }
+ if (host == NULL) {
+ (void) gethostname(hostname, sizeof(hostname));
+ host = hostname;
+ }
+ if (strlen(domain) + 1 + strlen(host) > MAXNETNAMELEN) {
+ return (0);
+ }
+ (void) sprintf(netname, "%s.%s@%s", OPSYS, host, domain);
+ return (1);
+}
diff --git a/cpukit/librpc/src/rpc/netnamer.c b/cpukit/librpc/src/rpc/netnamer.c
new file mode 100644
index 0000000000..aa9397e03c
--- /dev/null
+++ b/cpukit/librpc/src/rpc/netnamer.c
@@ -0,0 +1,331 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)netnamer.c 1.13 91/03/11 Copyr 1986 Sun Micro";
+#endif
+/*
+ * netname utility routines convert from unix names to network names and
+ * vice-versa This module is operating system dependent! What we define here
+ * will work with any unix system that has adopted the sun NIS domain
+ * architecture.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+#include <ctype.h>
+#include <stdio.h>
+#include <grp.h>
+#include <pwd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static char *OPSYS = "unix";
+#ifdef YP
+static char *NETID = "netid.byname";
+#endif
+static char *NETIDFILE = "/etc/netid";
+
+static int getnetid ( char *, char * );
+static int _getgroups ( char *, gid_t * );
+
+#ifndef NGROUPS
+#define NGROUPS 16
+#endif
+
+/*
+ * Convert network-name into unix credential
+ */
+int
+netname2user(
+ char netname[MAXNETNAMELEN + 1],
+ uid_t *uidp,
+ gid_t *gidp,
+ int *gidlenp,
+ gid_t *gidlist)
+{
+ char *p;
+ int gidlen;
+ uid_t uid;
+ long luid;
+ struct passwd *pwd;
+ char val[1024];
+ char *val1, *val2;
+ char *domain;
+ int vallen;
+ int err;
+
+ if (getnetid(netname, val)) {
+ p = strtok(val, ":");
+ if (p == NULL)
+ return (0);
+ *uidp = (uid_t) atol(val);
+ p = strtok(NULL, "\n,");
+ *gidp = (gid_t) atol(p);
+ if (p == NULL) {
+ return (0);
+ }
+ gidlen = 0;
+ for (gidlen = 0; gidlen < NGROUPS; gidlen++) {
+ p = strtok(NULL, "\n,");
+ if (p == NULL)
+ break;
+ gidlist[gidlen] = (gid_t) atol(p);
+ }
+ *gidlenp = gidlen;
+
+ return (1);
+ }
+ val1 = strchr(netname, '.');
+ if (val1 == NULL)
+ return (0);
+ if (strncmp(netname, OPSYS, (val1-netname)))
+ return (0);
+ val1++;
+ val2 = strchr(val1, '@');
+ if (val2 == NULL)
+ return (0);
+ vallen = val2 - val1;
+ if (vallen > (1024 - 1))
+ vallen = 1024 - 1;
+ (void) strncpy(val, val1, 1024);
+ val[vallen] = 0;
+
+ err = _rpc_get_default_domain(&domain); /* change to rpc */
+ if (err)
+ return (0);
+
+ if (strcmp(val2 + 1, domain))
+ return (0); /* wrong domain */
+
+ if (sscanf(val, "%ld", &luid) != 1)
+ return (0);
+ uid = luid;
+
+ /* use initgroups method */
+ pwd = getpwuid(uid);
+ if (pwd == NULL)
+ return (0);
+ *uidp = pwd->pw_uid;
+ *gidp = pwd->pw_gid;
+ *gidlenp = _getgroups(pwd->pw_name, gidlist);
+ return (1);
+}
+
+/*
+ * initgroups
+ */
+
+static int
+_getgroups(
+ char *uname,
+ gid_t groups[NGROUPS])
+{
+ gid_t ngroups = 0;
+ register struct group *grp;
+ register int i;
+ register int j;
+ int filter;
+
+ setgrent();
+ while ((grp = getgrent())) {
+ for (i = 0; grp->gr_mem[i]; i++)
+ if (!strcmp(grp->gr_mem[i], uname)) {
+ if (ngroups == NGROUPS) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "initgroups: %s is in too many groups\n", uname);
+#endif
+ goto toomany;
+ }
+ /* filter out duplicate group entries */
+ filter = 0;
+ for (j = 0; j < ngroups; j++)
+ if (groups[j] == grp->gr_gid) {
+ filter++;
+ break;
+ }
+ if (!filter)
+ groups[ngroups++] = grp->gr_gid;
+ }
+ }
+toomany:
+ endgrent();
+ return (ngroups);
+}
+
+/*
+ * Convert network-name to hostname
+ */
+int
+netname2host(
+ char netname[MAXNETNAMELEN + 1],
+ char *hostname,
+ int hostlen)
+{
+ int err;
+ char valbuf[1024];
+ char *val;
+ char *val2;
+ int vallen;
+ char *domain;
+
+ if (getnetid(netname, valbuf)) {
+ val = valbuf;
+ if ((*val == '0') && (val[1] == ':')) {
+ (void) strncpy(hostname, val + 2, hostlen);
+ return (1);
+ }
+ }
+ val = strchr(netname, '.');
+ if (val == NULL)
+ return (0);
+ if (strncmp(netname, OPSYS, (val - netname)))
+ return (0);
+ val++;
+ val2 = strchr(val, '@');
+ if (val2 == NULL)
+ return (0);
+ vallen = val2 - val;
+ if (vallen > (hostlen - 1))
+ vallen = hostlen - 1;
+ (void) strncpy(hostname, val, vallen);
+ hostname[vallen] = 0;
+
+ err = _rpc_get_default_domain(&domain); /* change to rpc */
+ if (err)
+ return (0);
+
+ if (strcmp(val2 + 1, domain))
+ return (0); /* wrong domain */
+ else
+ return (1);
+}
+
+/*
+ * reads the file /etc/netid looking for a + to optionally go to the
+ * network information service.
+ */
+int
+getnetid(
+ char *key,
+ char *ret)
+{
+ char buf[1024]; /* big enough */
+ char *res;
+ char *mkey;
+ char *mval;
+ FILE *fd;
+#ifdef YP
+ char *domain;
+ int err;
+ char *lookup;
+ int len;
+#endif
+
+ fd = fopen(NETIDFILE, "r");
+ if (fd == (FILE *) 0) {
+#ifdef YP
+ res = "+";
+ goto getnetidyp;
+#else
+ return (0);
+#endif
+ }
+ for (;;) {
+ if (fd == (FILE *) 0)
+ return (0); /* getnetidyp brings us here */
+ res = fgets(buf, 1024, fd);
+ if (res == 0) {
+ fclose(fd);
+ return (0);
+ }
+ if (res[0] == '#')
+ continue;
+ else if (res[0] == '+') {
+#ifdef YP
+ getnetidyp:
+ err = yp_get_default_domain(&domain);
+ if (err) {
+ continue;
+ }
+ lookup = NULL;
+ err = yp_match(domain, NETID, key,
+ strlen(key), &lookup, &len);
+ if (err) {
+#ifdef DEBUG
+ fprintf(stderr, "match failed error %d\n", err);
+#endif
+ continue;
+ }
+ lookup[len] = 0;
+ strcpy(ret, lookup);
+ free(lookup);
+ if (fd != NULL)
+ fclose(fd);
+ return (2);
+#else /* YP */
+#ifdef DEBUG
+ fprintf(stderr,
+"Bad record in %s '+' -- NIS not supported in this library copy\n",
+ NETIDFILE);
+#endif
+ continue;
+#endif /* YP */
+ } else {
+ mkey = strtok(buf, "\t ");
+ if (mkey == NULL) {
+ fprintf(stderr,
+ "Bad record in %s -- %s", NETIDFILE, buf);
+ continue;
+ }
+ mval = strtok(NULL, " \t#\n");
+ if (mval == NULL) {
+ fprintf(stderr,
+ "Bad record in %s val problem - %s", NETIDFILE, buf);
+ continue;
+ }
+ if (strcmp(mkey, key) == 0) {
+ strcpy(ret, mval);
+ fclose(fd);
+ return (1);
+
+ }
+ }
+ }
+}
diff --git a/cpukit/librpc/src/rpc/pmap_clnt.c b/cpukit/librpc/src/rpc/pmap_clnt.c
new file mode 100644
index 0000000000..7c02867ea2
--- /dev/null
+++ b/cpukit/librpc/src/rpc/pmap_clnt.c
@@ -0,0 +1,151 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_clnt.c,v 1.11 2000/01/27 23:06:39 jasone Exp $";
+#endif
+
+/*
+ * pmap_clnt.c
+ * Client interface to pmap rpc service.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <netinet/in.h>
+
+static struct timeval timeout = { 5, 0 };
+static struct timeval tottimeout = { 60, 0 };
+
+#ifndef PORTMAPSOCK
+#define PORTMAPSOCK "/var/run/portmapsock"
+#endif
+
+/*
+ * Set a mapping between program,version and port.
+ * Calls the pmap service remotely to do the mapping.
+ */
+bool_t
+pmap_set(
+ u_long program,
+ u_long version,
+ int protocol,
+ int port) /* was u_short but changed to match prototype */
+{
+ struct sockaddr_in myaddress;
+ int socket = -1;
+ CLIENT *client;
+ struct pmap parms;
+ bool_t rslt;
+ struct stat st;
+
+ /*
+ * Temporary hack for backwards compatibility. Eventually
+ * this test will go away and we'll use only the "unix" transport.
+ */
+ if (stat(PORTMAPSOCK, &st) == 0 && st.st_mode & S_IFSOCK)
+ client = clnt_create(PORTMAPSOCK, PMAPPROG, PMAPVERS, "unix");
+ else {
+ if (get_myaddress(&myaddress) != 0)
+ return (FALSE);
+ myaddress.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
+ timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+ }
+
+ if (client == (CLIENT *)NULL)
+ return (FALSE);
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_prot = protocol;
+ parms.pm_port = port;
+ if (CLNT_CALL(client, PMAPPROC_SET, (xdrproc_t)xdr_pmap, &parms, (xdrproc_t)xdr_bool, &rslt,
+ tottimeout) != RPC_SUCCESS) {
+ clnt_perror(client, "Cannot register service");
+ return (FALSE);
+ }
+ CLNT_DESTROY(client);
+ if (socket != -1)
+ (void)_RPC_close(socket);
+ return (rslt);
+}
+
+/*
+ * Remove the mapping between program, version and port.
+ * Calls the pmap service remotely to do the un-mapping.
+ */
+bool_t
+pmap_unset(
+ u_long program,
+ u_long version)
+{
+ struct sockaddr_in myaddress;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+ bool_t rslt;
+ struct stat st;
+
+ /*
+ * Temporary hack for backwards compatibility. Eventually
+ * this test will go away and we'll use only the "unix" transport.
+ */
+ if (stat(PORTMAPSOCK, &st) == 0 && st.st_mode & S_IFSOCK)
+ client = clnt_create(PORTMAPSOCK, PMAPPROG, PMAPVERS, "unix");
+ else {
+ if (get_myaddress(&myaddress) != 0)
+ return (FALSE);
+ myaddress.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
+ timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+ }
+ if (client == (CLIENT *)NULL)
+ return (FALSE);
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_port = parms.pm_prot = 0;
+ CLNT_CALL(client, PMAPPROC_UNSET, (xdrproc_t)xdr_pmap, &parms, (xdrproc_t)xdr_bool, &rslt,
+ tottimeout);
+ CLNT_DESTROY(client);
+ if (socket != -1)
+ (void)_RPC_close(socket);
+ return (rslt);
+}
diff --git a/cpukit/librpc/src/rpc/pmap_getmaps.c b/cpukit/librpc/src/rpc/pmap_getmaps.c
new file mode 100644
index 0000000000..b284b57254
--- /dev/null
+++ b/cpukit/librpc/src/rpc/pmap_getmaps.c
@@ -0,0 +1,92 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_getmaps.c,v 1.11 2000/01/27 23:06:39 jasone Exp $";
+#endif
+
+/*
+ * pmap_getmap.c
+ * Client interface to pmap rpc service.
+ * contains pmap_getmaps, which is only tcp service involved
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mbuf.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#define NAMELEN 255
+#define MAX_BROADCAST_SIZE 1400
+
+/*
+ * Get a copy of the current port maps.
+ * Calls the pmap service remotely to do get the maps.
+ */
+struct pmaplist *
+pmap_getmaps(struct sockaddr_in *address)
+{
+ struct pmaplist *head = NULL;
+ int socket = -1;
+ struct timeval minutetimeout;
+ CLIENT *client;
+
+ minutetimeout.tv_sec = 60;
+ minutetimeout.tv_usec = 0;
+ address->sin_port = htons(PMAPPORT);
+ client = clnttcp_create(address, PMAPPROG,
+ PMAPVERS, &socket, 50, 500);
+ if (client != NULL) {
+ if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_DUMP,
+ (xdrproc_t)xdr_void, NULL,
+ (xdrproc_t)xdr_pmaplist, &head, minutetimeout) !=
+ RPC_SUCCESS) {
+ clnt_perror(client, "pmap_getmaps rpc problem");
+ }
+ CLNT_DESTROY(client);
+ }
+ if (socket != -1)
+ (void)_RPC_close(socket);
+ address->sin_port = 0;
+ return (head);
+}
diff --git a/cpukit/librpc/src/rpc/pmap_getport.c b/cpukit/librpc/src/rpc/pmap_getport.c
new file mode 100644
index 0000000000..c75b4d5444
--- /dev/null
+++ b/cpukit/librpc/src/rpc/pmap_getport.c
@@ -0,0 +1,98 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_getport.c,v 1.10 2000/01/27 23:06:40 jasone Exp $";
+#endif
+
+/*
+ * pmap_getport.c
+ * Client interface to pmap rpc service.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <sys/mbuf.h>
+#include <net/if.h>
+#include <unistd.h>
+
+static const struct timeval timeout = { 5, 0 };
+static const struct timeval tottimeout = { 60, 0 };
+
+/*
+ * Find the mapped port for program,version.
+ * Calls the pmap service remotely to do the lookup.
+ * Returns 0 if no map exists.
+ */
+u_short
+pmap_getport(
+ struct sockaddr_in *address,
+ u_long program,
+ u_long version,
+ u_int protocol )
+{
+ u_short port = 0;
+ int socket = -1;
+ CLIENT *client;
+ struct pmap parms;
+
+ address->sin_port = htons(PMAPPORT);
+ client = clntudp_bufcreate(address, PMAPPROG,
+ PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+ if (client != NULL) {
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_prot = protocol;
+ parms.pm_port = 0; /* not needed or used */
+ if (CLNT_CALL(client, (rpcproc_t)PMAPPROC_GETPORT,
+ (xdrproc_t)xdr_pmap,
+ &parms, (xdrproc_t)xdr_u_short, &port, tottimeout) !=
+ RPC_SUCCESS){
+ rpc_createerr.cf_stat = RPC_PMAPFAILURE;
+ clnt_geterr(client, &rpc_createerr.cf_error);
+ } else if (port == 0) {
+ rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
+ }
+ CLNT_DESTROY(client);
+ }
+ if (socket != -1)
+ (void)_RPC_close(socket);
+ address->sin_port = 0;
+ return (port);
+}
diff --git a/cpukit/librpc/src/rpc/pmap_prot.c b/cpukit/librpc/src/rpc/pmap_prot.c
new file mode 100644
index 0000000000..30aedce444
--- /dev/null
+++ b/cpukit/librpc/src/rpc/pmap_prot.c
@@ -0,0 +1,63 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_prot.c 1.17 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_prot.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_prot.c,v 1.6 1999/08/28 00:00:42 peter Exp $";
+#endif
+
+/*
+ * pmap_prot.c
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+
+
+bool_t
+xdr_pmap(
+ XDR *xdrs,
+ struct pmap *regs)
+{
+
+ if (xdr_u_long(xdrs, &regs->pm_prog) &&
+ xdr_u_long(xdrs, &regs->pm_vers) &&
+ xdr_u_long(xdrs, &regs->pm_prot))
+ return (xdr_u_long(xdrs, &regs->pm_port));
+ return (FALSE);
+}
diff --git a/cpukit/librpc/src/rpc/pmap_prot2.c b/cpukit/librpc/src/rpc/pmap_prot2.c
new file mode 100644
index 0000000000..208c8a412a
--- /dev/null
+++ b/cpukit/librpc/src/rpc/pmap_prot2.c
@@ -0,0 +1,122 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_prot2.c,v 1.7 1999/08/28 00:00:42 peter Exp $";
+#endif
+
+/*
+ * pmap_prot2.c
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+
+
+/*
+ * What is going on with linked lists? (!)
+ * First recall the link list declaration from pmap_prot.h:
+ *
+ * struct pmaplist {
+ * struct pmap pml_map;
+ * struct pmaplist *pml_map;
+ * };
+ *
+ * Compare that declaration with a corresponding xdr declaration that
+ * is (a) pointer-less, and (b) recursive:
+ *
+ * typedef union switch (bool_t) {
+ *
+ * case TRUE: struct {
+ * struct pmap;
+ * pmaplist_t foo;
+ * };
+ *
+ * case FALSE: struct {};
+ * } pmaplist_t;
+ *
+ * Notice that the xdr declaration has no nxt pointer while
+ * the C declaration has no bool_t variable. The bool_t can be
+ * interpreted as ``more data follows me''; if FALSE then nothing
+ * follows this bool_t; if TRUE then the bool_t is followed by
+ * an actual struct pmap, and then (recursively) by the
+ * xdr union, pamplist_t.
+ *
+ * This could be implemented via the xdr_union primitive, though this
+ * would cause a one recursive call per element in the list. Rather than do
+ * that we can ``unwind'' the recursion
+ * into a while loop and do the union arms in-place.
+ *
+ * The head of the list is what the C programmer wishes to past around
+ * the net, yet is the data that the pointer points to which is interesting;
+ * this sounds like a job for xdr_reference!
+ */
+bool_t
+xdr_pmaplist(
+ XDR *xdrs,
+ struct pmaplist **rp)
+{
+ /*
+ * more_elements is pre-computed in case the direction is
+ * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
+ * xdr_bool when the direction is XDR_DECODE.
+ */
+ bool_t more_elements;
+ register int freeing = (xdrs->x_op == XDR_FREE);
+ register struct pmaplist **next = NULL;
+
+ while (TRUE) {
+ more_elements = (bool_t)(*rp != NULL);
+ if (! xdr_bool(xdrs, &more_elements))
+ return (FALSE);
+ if (! more_elements)
+ return (TRUE); /* we are done */
+ /*
+ * the unfortunate side effect of non-recursion is that in
+ * the case of freeing we must remember the next object
+ * before we free the current object ...
+ */
+ if (freeing)
+ next = &((*rp)->pml_next);
+ if (! xdr_reference(xdrs, (caddr_t *)rp,
+ (u_int)sizeof(struct pmaplist), (xdrproc_t) xdr_pmap))
+ return (FALSE);
+ rp = (freeing) ? next : &((*rp)->pml_next);
+ }
+}
diff --git a/cpukit/librpc/src/rpc/pmap_rmt.c b/cpukit/librpc/src/rpc/pmap_rmt.c
new file mode 100644
index 0000000000..1ab72b2f15
--- /dev/null
+++ b/cpukit/librpc/src/rpc/pmap_rmt.c
@@ -0,0 +1,441 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/pmap_rmt.c,v 1.15 2000/01/27 23:06:40 jasone Exp $";
+#endif
+
+/*
+ * pmap_rmt.c
+ * Client interface to pmap rpc service.
+ * remote call and broadcast service
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <rpc/pmap_rmt.h>
+
+#include <stdlib.h>
+#include <sys/select.h>
+
+#define MAX_BROADCAST_SIZE 1400
+
+static const struct timeval timeout = { 3, 0 };
+
+/*
+ * pmapper remote-call-service interface.
+ * This routine is used to call the pmapper remote call service
+ * which will look up a service program in the port maps, and then
+ * remotely call that routine with the given parameters. This allows
+ * programs to do a lookup and call in one step.
+*/
+enum clnt_stat
+pmap_rmtcall(
+ struct sockaddr_in *addr,
+ u_long prog,
+ u_long vers,
+ u_long proc,
+ xdrproc_t xdrargs,
+ caddr_t argsp,
+ xdrproc_t xdrres,
+ caddr_t resp,
+ struct timeval tout,
+ u_long *port_ptr)
+{
+ int sock = -1;
+ CLIENT *client;
+ struct rmtcallargs a;
+ struct rmtcallres r;
+ enum clnt_stat stat;
+
+ assert(addr != NULL);
+ assert(port_ptr != NULL);
+
+ addr->sin_port = htons(PMAPPORT);
+ client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
+ if (client != NULL) {
+ a.prog = prog;
+ a.vers = vers;
+ a.proc = proc;
+ a.args_ptr = argsp;
+ a.xdr_args = xdrargs;
+ r.port_ptr = port_ptr;
+ r.results_ptr = resp;
+ r.xdr_results = xdrres;
+ stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
+ (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
+ &r, tout);
+ CLNT_DESTROY(client);
+ } else {
+ stat = RPC_FAILED;
+ }
+ if (sock != -1)
+ (void)_RPC_close(sock);
+ addr->sin_port = 0;
+ return (stat);
+}
+
+
+/*
+ * XDR remote call arguments
+ * written for XDR_ENCODE direction only
+ */
+bool_t
+xdr_rmtcall_args(
+ XDR *xdrs,
+ struct rmtcallargs *cap)
+{
+ u_int lenposition, argposition, position;
+
+ assert(xdrs != NULL);
+ assert(cap != NULL);
+
+ if (xdr_u_long(xdrs, &(cap->prog)) &&
+ xdr_u_long(xdrs, &(cap->vers)) &&
+ xdr_u_long(xdrs, &(cap->proc))) {
+ lenposition = XDR_GETPOS(xdrs);
+ if (! xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
+ argposition = XDR_GETPOS(xdrs);
+ if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
+ return (FALSE);
+ position = XDR_GETPOS(xdrs);
+ cap->arglen = (u_long)position - (u_long)argposition;
+ XDR_SETPOS(xdrs, lenposition);
+ if (! xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
+ XDR_SETPOS(xdrs, position);
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR remote call results
+ * written for XDR_DECODE direction only
+ */
+bool_t
+xdr_rmtcallres(
+ XDR *xdrs,
+ struct rmtcallres *crp)
+{
+ caddr_t port_ptr;
+
+ assert(xdrs != NULL);
+ assert(crp != NULL);
+
+ port_ptr = (caddr_t)(void *)crp->port_ptr;
+ if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
+ (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
+ crp->port_ptr = (u_long *)(void *)port_ptr;
+ return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
+ }
+ return (FALSE);
+}
+
+
+/*
+ * The following is kludged-up support for simple rpc broadcasts.
+ * Someday a large, complicated system will replace these trivial
+ * routines which only support udp/ip .
+ */
+
+static int
+getbroadcastnets(
+ struct in_addr *addrs,
+ int sock, /* any valid socket will do */
+ char *buf /* why allocxate more when we can use existing... */ )
+{
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr;
+ struct sockaddr_in *sin;
+ struct in_addr addr;
+ char *cp, *cplim;
+ int n, i = 0;
+
+ ifc.ifc_len = UDPMSGSIZE;
+ ifc.ifc_buf = buf;
+ if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
+ perror("broadcast: ioctl (get interface configuration)");
+ return (0);
+ }
+#define max(a, b) (a > b ? a : b)
+#define size(p) max((p).sa_len, sizeof(p))
+ cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
+ for (cp = buf; cp < cplim;
+ cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) {
+ ifr = (struct ifreq *)cp;
+ if (ifr->ifr_addr.sa_family != AF_INET)
+ continue;
+ ifreq = *ifr;
+ if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+ perror("broadcast: ioctl (get interface flags)");
+ continue;
+ }
+ if ((ifreq.ifr_flags & IFF_BROADCAST) &&
+ (ifreq.ifr_flags & IFF_UP)) {
+ sin = (struct sockaddr_in *)&ifr->ifr_addr;
+#ifdef SIOCGIFBRDADDR /* 4.3BSD */
+ if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
+ addr =
+ inet_makeaddr(inet_netof(sin->sin_addr),
+ INADDR_ANY);
+ } else {
+ addr = ((struct sockaddr_in*)
+ &ifreq.ifr_addr)->sin_addr;
+ }
+#else /* 4.2 BSD */
+ addr = inet_makeaddr(inet_netof(sin->sin_addr),
+ INADDR_ANY);
+#endif
+ for (n=i-1; n>=0; n--) {
+ if (addr.s_addr == addrs[n].s_addr)
+ break;
+ }
+ if (n<0) {
+ addrs[i++] = addr;
+ }
+ }
+ }
+ return (i);
+}
+
+typedef bool_t (*resultproc_t)(caddr_t, struct sockaddr_in *);
+
+enum clnt_stat
+clnt_broadcast(
+ u_long prog, /* program number */
+ u_long vers, /* version number */
+ u_long proc, /* procedure number */
+ xdrproc_t xargs, /* xdr routine for args */
+ caddr_t argsp, /* pointer to args */
+ xdrproc_t xresults, /* xdr routine for results */
+ caddr_t resultsp, /* pointer to results */
+ resultproc_t eachresult /* call with each result obtained */ )
+{
+ enum clnt_stat stat = RPC_SUCCESS; /* to avoid warning */
+ AUTH *unix_auth = authunix_create_default();
+ XDR xdr_stream;
+ register XDR *xdrs = &xdr_stream;
+ int outlen, inlen, nets;
+ socklen_t fromlen;
+ register int sock;
+ int on = 1;
+ fd_set *fds = 0, readfds; /* initialized to avoid warning */
+ register int i;
+ bool_t done = FALSE;
+ register u_long xid;
+ u_long port;
+ struct in_addr addrs[20];
+ struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
+ struct rmtcallargs a;
+ struct rmtcallres r;
+ struct rpc_msg msg;
+ struct timeval t, tv;
+ char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
+ static uintptr_t disrupt;
+
+ if (disrupt == 0)
+ disrupt = (uintptr_t) resultsp;
+
+ /*
+ * initialization: create a socket, a broadcast address, and
+ * preserialize the arguments into a send buffer.
+ */
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("Cannot create socket for broadcast rpc");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+#ifdef SO_BROADCAST
+ if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
+ perror("Cannot set socket option SO_BROADCAST");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+#endif /* def SO_BROADCAST */
+ if (sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL) {
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ nets = getbroadcastnets(addrs, sock, inbuf);
+ memset(&baddr, 0, sizeof (baddr));
+ baddr.sin_len = sizeof(struct sockaddr_in);
+ baddr.sin_family = AF_INET;
+ baddr.sin_port = htons(PMAPPORT);
+ baddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ (void)gettimeofday(&t, (struct timezone *)0);
+ msg.rm_xid = xid = (++disrupt) ^ getpid() ^ t.tv_sec ^ t.tv_usec;
+ t.tv_usec = 0;
+ msg.rm_direction = CALL;
+ msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ msg.rm_call.cb_prog = PMAPPROG;
+ msg.rm_call.cb_vers = PMAPVERS;
+ msg.rm_call.cb_proc = PMAPPROC_CALLIT;
+ msg.rm_call.cb_cred = unix_auth->ah_cred;
+ msg.rm_call.cb_verf = unix_auth->ah_verf;
+ a.prog = prog;
+ a.vers = vers;
+ a.proc = proc;
+ a.xdr_args = xargs;
+ a.args_ptr = argsp;
+ r.port_ptr = &port;
+ r.xdr_results = xresults;
+ r.results_ptr = resultsp;
+ xdrmem_create(xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
+ if ((! xdr_callmsg(xdrs, &msg)) || (! xdr_rmtcall_args(xdrs, &a))) {
+ stat = RPC_CANTENCODEARGS;
+ goto done_broad;
+ }
+ outlen = (int)xdr_getpos(xdrs);
+ xdr_destroy(xdrs);
+ /*
+ * Basic loop: broadcast a packet and wait a while for response(s).
+ * The response timeout grows larger per iteration.
+ *
+ * XXX This will loop about 5 times the stop. If there are
+ * lots of signals being received by the process it will quit
+ * send them all in one quick burst, not paying attention to
+ * the intended function of sending them slowly over half a
+ * minute or so
+ */
+ for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2) {
+ for (i = 0; i < nets; i++) {
+ baddr.sin_addr = addrs[i];
+ if (sendto(sock, outbuf, outlen, 0,
+ (struct sockaddr *)&baddr,
+ sizeof (struct sockaddr)) != outlen) {
+ perror("Cannot send broadcast packet");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+ }
+ if (eachresult == NULL) {
+ stat = RPC_SUCCESS;
+ goto done_broad;
+ }
+ recv_again:
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = (caddr_t)&r;
+ msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_rmtcallres;
+ /* XXX we know the other bits are still clear */
+ FD_SET(sock, fds);
+ tv = t; /* for select() that copies back */
+ switch (select(sock + 1, fds, NULL, NULL, &tv)) {
+
+ case 0: /* timed out */
+ stat = RPC_TIMEDOUT;
+ continue;
+
+ case -1: /* some kind of error */
+ if (errno == EINTR)
+ goto recv_again;
+ perror("Broadcast select problem");
+ stat = RPC_CANTRECV;
+ goto done_broad;
+
+ } /* end of select results switch */
+ try_again:
+ fromlen = sizeof(struct sockaddr);
+ inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
+ (struct sockaddr *)&raddr, &fromlen);
+ if (inlen < 0) {
+ if (errno == EINTR)
+ goto try_again;
+ perror("Cannot receive reply to broadcast");
+ stat = RPC_CANTRECV;
+ goto done_broad;
+ }
+ if (inlen < sizeof(u_int32_t))
+ goto recv_again;
+ /*
+ * see if reply transaction id matches sent id.
+ * If so, decode the results.
+ */
+ xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
+ if (xdr_replymsg(xdrs, &msg)) {
+ if ((msg.rm_xid == xid) &&
+ (msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
+ (msg.acpted_rply.ar_stat == SUCCESS)) {
+ raddr.sin_port = htons((u_short)port);
+ done = (*eachresult)(resultsp, &raddr);
+ }
+ /* otherwise, we just ignore the errors ... */
+ }
+ xdrs->x_op = XDR_FREE;
+ msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
+ (void)xdr_replymsg(xdrs, &msg);
+ (void)(*xresults)(xdrs, resultsp);
+ xdr_destroy(xdrs);
+ if (done) {
+ stat = RPC_SUCCESS;
+ goto done_broad;
+ } else {
+ goto recv_again;
+ }
+ }
+done_broad:
+ if (fds != &readfds)
+ free(fds);
+ if (sock >= 0)
+ (void)_RPC_close(sock);
+ AUTH_DESTROY(unix_auth);
+ return (stat);
+}
diff --git a/cpukit/librpc/src/rpc/publickey.3 b/cpukit/librpc/src/rpc/publickey.3
new file mode 100644
index 0000000000..29094f98b2
--- /dev/null
+++ b/cpukit/librpc/src/rpc/publickey.3
@@ -0,0 +1,47 @@
+.\" @(#)publickey.3r 2.1 88/08/07 4.0 RPCSRC
+.\" $FreeBSD: src/lib/libc/rpc/publickey.3,v 1.4 2000/03/02 09:13:46 sheldonh Exp $
+.\"
+.TH PUBLICKEY 3R "6 October 1987"
+.SH NAME
+publickey, getpublickey, getsecretkey \- get public or secret key
+.SH SYNOPSIS
+.nf
+.B #include <rpc/rpc.h>
+.B #include <rpc/key_prot.h>
+.LP
+.B getpublickey(netname, publickey)
+.B char netname[\s-1MAXNETNAMELEN\s0+1];
+.B char publickey[\s-1HEXKEYBYTES\s0+1];
+.LP
+.B getsecretkey(netname, secretkey, passwd)
+.B char netname[\s-1MAXNETNAMELEN\s0+1];
+.B char secretkey[\s-1HEXKEYBYTES\s0+1];
+.B char *passwd;
+.fi
+.SH DESCRIPTION
+.IX "getpublickey function" "" "\fLgetpublickey()\fP function"
+.IX "getsecretkey function" "" "\fLgetsecretkey()\fP function"
+These routines are used to get public and secret keys from the
+.SM YP
+database.
+.B getsecretkey(\|)
+has an extra argument,
+.IR passwd ,
+which is used to decrypt the encrypted secret key stored in the database.
+Both routines return 1 if they are successful in finding the key, 0 otherwise.
+The keys are returned as
+.SM NULL\s0-terminated,
+hexadecimal strings.
+If the password supplied to
+.B getsecretkey(\|)
+fails to decrypt the secret key, the routine will return 1 but the
+.I secretkey
+argument will be a
+.SM NULL
+string (``'').
+.SH "SEE ALSO"
+.BR publickey (5)
+.LP
+.I \s-1RPC\s0 Programmer's Manual
+in
+.TX NETP
diff --git a/cpukit/librpc/src/rpc/publickey.5 b/cpukit/librpc/src/rpc/publickey.5
new file mode 100644
index 0000000000..9f7a325488
--- /dev/null
+++ b/cpukit/librpc/src/rpc/publickey.5
@@ -0,0 +1,38 @@
+.\" $FreeBSD: src/lib/libc/rpc/publickey.5,v 1.5 2000/03/02 09:13:46 sheldonh Exp $
+.\" @(#)publickey.5 2.1 88/08/07 4.0 RPCSRC; from 1.6 88/02/29 SMI;
+.TH PUBLICKEY 5 "19 October 1987"
+.SH NAME
+publickey \- public key database
+.SH SYNOPSIS
+.B /etc/publickey
+.SH DESCRIPTION
+.LP
+.B /etc/publickey
+is the public key database used for secure
+networking.
+Each entry in
+the database consists of a network user
+name (which may either refer to
+a user or a hostname), followed by the user's
+public key (in hex
+notation), a colon, and then the user's
+secret key encrypted with
+its login password (also in hex notation).
+.LP
+This file is altered either by the user through the
+.BR chkey (1)
+command or by the system administrator through the
+.BR newkey (8)
+command.
+The file
+.B /etc/publickey
+should only contain data on the NIS master machine, where it
+is converted into the
+.SM NIS
+database
+.BR publickey.byname .
+.SH SEE ALSO
+.BR chkey (1),
+.BR publickey (3R),
+.BR newkey (8),
+.BR ypupdated (8C)
diff --git a/cpukit/librpc/src/rpc/rpc.3 b/cpukit/librpc/src/rpc/rpc.3
new file mode 100644
index 0000000000..f40b643827
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc.3
@@ -0,0 +1,1767 @@
+.\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
+.\" $FreeBSD: src/lib/libc/rpc/rpc.3,v 1.11 2000/03/02 09:13:47 sheldonh Exp $
+.\"
+.TH RPC 3 "16 February 1988"
+.SH NAME
+rpc \- library routines for remote procedure calls
+.SH SYNOPSIS AND DESCRIPTION
+These routines allow C programs to make procedure
+calls on other machines across the network.
+First, the client calls a procedure to send a
+data packet to the server.
+Upon receipt of the packet, the server calls a dispatch routine
+to perform the requested service, and then sends back a
+reply.
+Finally, the procedure call returns to the client.
+.LP
+Routines that are used for Secure RPC (DES authentication) are described in
+.BR rpc_secure (3).
+Secure RPC can be used only if DES encryption is available.
+.LP
+.ft B
+.nf
+.sp .5
+#include <rpc/rpc.h>
+.fi
+.ft R
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+auth_destroy(auth)
+\s-1AUTH\s0 *auth;
+.fi
+.ft R
+.IP
+A macro that destroys the authentication information associated with
+.IR auth .
+Destruction usually involves deallocation of private data
+structures.
+The use of
+.I auth
+is undefined after calling
+.BR auth_destroy(\|) .
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authnone_create(\|)
+.fi
+.ft R
+.IP
+Create and returns an
+.SM RPC
+authentication handle that passes nonusable authentication
+information with each remote procedure call.
+This is the
+default authentication used by
+.SM RPC.
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authunix_create(host, uid, gid, len, aup_gids)
+char *host;
+int uid, gid, len, *aup.gids;
+.fi
+.ft R
+.IP
+Create and return an
+.SM RPC
+authentication handle that contains
+.UX
+authentication information.
+The parameter
+.I host
+is the name of the machine on which the information was
+created;
+.I uid
+is the user's user
+.SM ID ;
+.I gid
+is the user's current group
+.SM ID ;
+.I len
+and
+.I aup_gids
+refer to a counted array of groups to which the user belongs.
+It is easy to impersonate a user.
+.br
+.if t .ne 5
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authunix_create_default(\|)
+.fi
+.ft R
+.IP
+Calls
+.B authunix_create(\|)
+with the appropriate parameters.
+.br
+.if t .ne 13
+.LP
+.ft B
+.nf
+.sp .5
+callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
+char *host;
+u_long prognum, versnum, procnum;
+char *in, *out;
+xdrproc_t inproc, outproc;
+.fi
+.ft R
+.IP
+Call the remote procedure associated with
+.IR prognum ,
+.IR versnum ,
+and
+.I procnum
+on the machine,
+.IR host .
+The parameter
+.I in
+is the address of the procedure's argument(s), and
+.I out
+is the address of where to place the result(s);
+.I inproc
+is used to encode the procedure's parameters, and
+.I outproc
+is used to decode the procedure's results.
+This routine returns zero if it succeeds, or the value of
+.B "enum clnt_stat"
+cast to an integer if it fails.
+The routine
+.B clnt_perrno(\|)
+is handy for translating failure statuses into messages.
+.IP
+Warning: calling remote procedures with this routine
+uses
+.SM UDP/IP
+as a transport; see
+.B clntudp_create(\|)
+for restrictions.
+You do not have control of timeouts or authentication using
+this routine.
+.br
+.if t .ne 16
+.LP
+.ft B
+.nf
+.sp .5
+enum clnt_stat
+clnt_broadcast(prognum, versnum, procnum, inproc, in, outproc, out, eachresult)
+u_long prognum, versnum, procnum;
+char *in, *out;
+xdrproc_t inproc, outproc;
+resultproc_t eachresult;
+.fi
+.ft R
+.IP
+Like
+.BR callrpc(\|) ,
+except the call message is broadcast to all locally
+connected broadcast nets.
+Each time it receives a
+response, this routine calls
+.BR eachresult(\|) ,
+whose form is:
+.IP
+.RS 1i
+.ft B
+.nf
+eachresult(out, addr)
+char *out;
+struct sockaddr_in *addr;
+.ft R
+.fi
+.RE
+.IP
+where
+.I out
+is the same as
+.I out
+passed to
+.BR clnt_broadcast(\|) ,
+except that the remote procedure's output is decoded there;
+.I addr
+points to the address of the machine that sent the results.
+If
+.B eachresult(\|)
+returns zero,
+.B clnt_broadcast(\|)
+waits for more replies; otherwise it returns with appropriate
+status.
+.IP
+Warning: broadcast sockets are limited in size to the
+maximum transfer unit of the data link.
+For ethernet,
+this value is 1500 bytes.
+.br
+.if t .ne 13
+.LP
+.ft B
+.nf
+.sp .5
+enum clnt_stat
+clnt_call(clnt, procnum, inproc, in, outproc, out, tout)
+\s-1CLIENT\s0 *clnt;
+u_long
+procnum;
+xdrproc_t inproc, outproc;
+char *in, *out;
+struct timeval tout;
+.fi
+.ft R
+.IP
+A macro that calls the remote procedure
+.I procnum
+associated with the client handle,
+.IR clnt ,
+which is obtained with an
+.SM RPC
+client creation routine such as
+.BR clnt_create(\|) .
+The parameter
+.I in
+is the address of the procedure's argument(s), and
+.I out
+is the address of where to place the result(s);
+.I inproc
+is used to encode the procedure's parameters, and
+.I outproc
+is used to decode the procedure's results;
+.I tout
+is the time allowed for results to come back.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+clnt_destroy(clnt)
+\s-1CLIENT\s0 *clnt;
+.fi
+.ft R
+.IP
+A macro that destroys the client's
+.SM RPC
+handle.
+Destruction usually involves deallocation
+of private data structures, including
+.I clnt
+itself. Use of
+.I clnt
+is undefined after calling
+.BR clnt_destroy(\|) .
+If the
+.SM RPC
+library opened the associated socket, it will close it also.
+Otherwise, the socket remains open.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clnt_create(host, prog, vers, proto)
+char *host;
+u_long prog, vers;
+char *proto;
+.fi
+.ft R
+.IP
+Generic client creation routine.
+.I host
+identifies the name of the remote host where the server
+is located.
+.I proto
+indicates which kind of transport protocol to use.
+The
+currently supported values for this field are \(lqudp\(rq
+and \(lqtcp\(rq.
+Default timeouts are set, but can be modified using
+.BR clnt_control(\|) .
+.IP
+Warning: Using
+.SM UDP
+has its shortcomings. Since
+.SM UDP\s0-based
+.SM RPC
+messages can only hold up to 8 Kbytes of encoded data,
+this transport cannot be used for procedures that take
+large arguments or return huge results.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+bool_t
+clnt_control(cl, req, info)
+\s-1CLIENT\s0 *cl;
+u_int req;
+char *info;
+.fi
+.ft R
+.IP
+A macro used to change or retrieve various information
+about a client object.
+.I req
+indicates the type of operation, and
+.I info
+is a pointer to the information.
+For both
+.SM UDP
+and
+.SM TCP\s0,
+the supported values of
+.I req
+and their argument types and what they do are:
+.IP
+.nf
+.ta +2.0i +2.0i +2.0i
+.SM CLSET_TIMEOUT\s0 struct timeval set total timeout
+.SM CLGET_TIMEOUT\s0 struct timeval get total timeout
+.fi
+.IP
+Note: if you set the timeout using
+.BR clnt_control(\|) ,
+the timeout parameter passed to
+.B clnt_call(\|)
+will be ignored in all future calls.
+.IP
+.nf
+.SM CLGET_SERVER_ADDR\s0 struct sockaddr_in get server's address
+.fi
+.br
+.IP
+The following operations are valid for
+.SM UDP
+only:
+.IP
+.nf
+.ta +2.0i ; +2.0i ; +2.0i
+.SM CLSET_RETRY_TIMEOUT\s0 struct timeval set the retry timeout
+.SM CLGET_RETRY_TIMEOUT\s0 struct timeval get the retry timeout
+.fi
+.br
+.IP
+The retry timeout is the time that
+.SM "UDP RPC"
+waits for the server to reply before
+retransmitting the request.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+clnt_freeres(clnt, outproc, out)
+\s-1CLIENT\s0 *clnt;
+xdrproc_t outproc;
+char *out;
+.fi
+.ft R
+.IP
+A macro that frees any data allocated by the
+.SM RPC/XDR
+system when it decoded the results of an
+.SM RPC
+call. The
+parameter
+.I out
+is the address of the results, and
+.I outproc
+is the
+.SM XDR
+routine describing the results.
+This routine returns one if the results were successfully
+freed,
+and zero otherwise.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+void
+clnt_geterr(clnt, errp)
+\s-1CLIENT\s0 *clnt;
+struct rpc_err *errp;
+.fi
+.ft R
+.IP
+A macro that copies the error structure out of the client
+handle
+to the structure at address
+.IR errp .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+clnt_pcreateerror(s)
+char *s;
+.fi
+.ft R
+.IP
+Print a message to standard error indicating
+why a client
+.SM RPC
+handle could not be created.
+The message is prepended with string
+.I s
+and a colon.
+Used when a
+.BR clnt_create(\|) ,
+.BR clntraw_create(\|) ,
+.BR clnttcp_create(\|) ,
+or
+.B clntudp_create(\|)
+call fails.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+clnt_perrno(stat)
+enum clnt_stat stat;
+.fi
+.ft R
+.IP
+Print a message to standard error corresponding
+to the condition indicated by
+.IR stat .
+Used after
+.BR callrpc(\|) .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+clnt_perror(clnt, s)
+\s-1CLIENT\s0 *clnt;
+char *s;
+.fi
+.ft R
+.IP
+Print a message to standard error indicating why an
+.SM RPC
+call failed;
+.I clnt
+is the handle used to do the call.
+The message is prepended with string
+.I s
+and a colon.
+Used after
+.BR clnt_call(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+char *
+clnt_spcreateerror
+char *s;
+.fi
+.ft R
+.IP
+Like
+.BR clnt_pcreateerror(\|) ,
+except that it returns a string
+instead of printing to the standard error.
+.IP
+Bugs: returns pointer to static data that is overwritten
+on each call.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+char *
+clnt_sperrno(stat)
+enum clnt_stat stat;
+.fi
+.ft R
+.IP
+Take the same arguments as
+.BR clnt_perrno(\|) ,
+but instead of sending a message to the standard error
+indicating why an
+.SM RPC
+call failed, return a pointer to a string which contains
+the message. The string ends with a
+.SM NEWLINE\s0.
+.IP
+.B clnt_sperrno(\|)
+is used instead of
+.B clnt_perrno(\|)
+if the program does not have a standard error (as a program
+running as a server quite likely does not), or if the
+programmer
+does not want the message to be output with
+.BR printf ,
+or if a message format different from that supported by
+.B clnt_perrno(\|)
+is to be used.
+Note: unlike
+.B clnt_sperror(\|)
+and
+.BR clnt_spcreaterror(\|) ,
+.B clnt_sperrno(\|)
+returns pointer to static data, but the
+result will not get overwritten on each call.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+char *
+clnt_sperror(rpch, s)
+\s-1CLIENT\s0 *rpch;
+char *s;
+.fi
+.ft R
+.IP
+Like
+.BR clnt_perror(\|) ,
+except that (like
+.BR clnt_sperrno(\|) )
+it returns a string instead of printing to standard error.
+.IP
+Bugs: returns pointer to static data that is overwritten
+on each call.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clntraw_create(prognum, versnum)
+u_long prognum, versnum;
+.fi
+.ft R
+.IP
+This routine creates a toy
+.SM RPC
+client for the remote program
+.IR prognum ,
+version
+.IR versnum .
+The transport used to pass messages to the service is
+actually a buffer within the process's address space, so the
+corresponding
+.SM RPC
+server should live in the same address space; see
+.BR svcraw_create(\|) .
+This allows simulation of
+.SM RPC
+and acquisition of
+.SM RPC
+overheads, such as round trip times, without any
+kernel interference.
+This routine returns
+.SM NULL
+if it fails.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clnttcp_create(addr, prognum, versnum, sockp, sendsz, recvsz)
+struct sockaddr_in *addr;
+u_long prognum, versnum;
+int *sockp;
+u_int sendsz, recvsz;
+.fi
+.ft R
+.IP
+This routine creates an
+.SM RPC
+client for the remote program
+.IR prognum ,
+version
+.IR versnum ;
+the client uses
+.SM TCP/IP
+as a transport.
+The remote program is located at Internet
+address
+.IR *addr .
+If
+.\"The following in-line font conversion is necessary for the hyphen indicator
+\fB\%addr\->sin_port\fR
+is zero, then it is set to the actual port that the remote
+program is listening on (the remote
+.B portmap
+service is consulted for this information). The parameter
+.I sockp
+is a socket; if it is
+.BR \s-1RPC_ANYSOCK\s0 ,
+then this routine opens a new one and sets
+.IR sockp .
+Since
+.SM TCP\s0-based
+.SM RPC
+uses buffered
+.SM I/O ,
+the user may specify the size of the send and receive buffers
+with the parameters
+.I sendsz
+and
+.IR recvsz ;
+values of zero choose suitable defaults.
+This routine returns
+.SM NULL
+if it fails.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clntudp_create(addr, prognum, versnum, wait, sockp)
+struct sockaddr_in *addr;
+u_long prognum, versnum;
+struct timeval wait;
+int *sockp;
+.fi
+.ft R
+.IP
+This routine creates an
+.SM RPC
+client for the remote program
+.IR prognum ,
+version
+.IR versnum ;
+the client uses
+.SM UDP/IP
+as a transport.
+The remote program is located at Internet
+address
+.IR addr .
+If
+\fB\%addr\->sin_port\fR
+is zero, then it is set to actual port that the remote
+program is listening on (the remote
+.B portmap
+service is consulted for this information). The parameter
+.I sockp
+is a socket; if it is
+.BR \s-1RPC_ANYSOCK\s0 ,
+then this routine opens a new one and sets
+.IR sockp .
+The
+.SM UDP
+transport resends the call message in intervals of
+.B wait
+time until a response is received or until the call times
+out.
+The total time for the call to time out is specified by
+.BR clnt_call(\|) .
+.IP
+Warning: since
+.SM UDP\s0-based
+.SM RPC
+messages can only hold up to 8 Kbytes
+of encoded data, this transport cannot be used for procedures
+that take large arguments or return huge results.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clntudp_bufcreate(addr, prognum, versnum, wait, sockp, sendsize, recosize)
+struct sockaddr_in *addr;
+u_long prognum, versnum;
+struct timeval wait;
+int *sockp;
+unsigned int sendsize;
+unsigned int recosize;
+.fi
+.ft R
+.IP
+This routine creates an
+.SM RPC
+client for the remote program
+.IR prognum ,
+on
+.IR versnum ;
+the client uses
+.SM UDP/IP
+as a transport.
+The remote program is located at Internet
+address
+.IR addr .
+If
+\fB\%addr\->sin_port\fR
+is zero, then it is set to actual port that the remote
+program is listening on (the remote
+.B portmap
+service is consulted for this information). The parameter
+.I sockp
+is a socket; if it is
+.BR \s-1RPC_ANYSOCK\s0 ,
+then this routine opens a new one and sets
+.BR sockp .
+The
+.SM UDP
+transport resends the call message in intervals of
+.B wait
+time until a response is received or until the call times
+out.
+The total time for the call to time out is specified by
+.BR clnt_call(\|) .
+.IP
+This allows the user to specify the maximum packet size for sending and receiving
+.SM UDP\s0-based
+.SM RPC
+messages.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+int
+get_myaddress(addr)
+struct sockaddr_in *addr;
+.fi
+.ft R
+.IP
+Stuff the machine's
+.SM IP
+address into
+.IR *addr ,
+without consulting the library routines that deal with
+.BR /etc/hosts .
+The port number is always set to
+.BR htons(\s-1PMAPPORT\s0) .
+Returns zero on success, non-zero on failure.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+struct pmaplist *
+pmap_getmaps(addr)
+struct sockaddr_in *addr;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which returns a list of the current
+.SM RPC
+program-to-port mappings
+on the host located at
+.SM IP
+address
+.IR *addr .
+This routine can return
+.SM NULL .
+The command
+.RB ` "rpcinfo \-p" '
+uses this routine.
+.br
+.if t .ne 12
+.LP
+.ft B
+.nf
+.sp .5
+u_short
+pmap_getport(addr, prognum, versnum, protocol)
+struct sockaddr_in *addr;
+u_long prognum, versnum, protocol;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which returns the port number
+on which waits a service that supports program number
+.IR prognum ,
+version
+.IR versnum ,
+and speaks the transport protocol associated with
+.IR protocol .
+The value of
+.I protocol
+is most likely
+.B
+.SM IPPROTO_UDP
+or
+.BR \s-1IPPROTO_TCP\s0 .
+A return value of zero means that the mapping does not exist
+or that
+the
+.SM RPC
+system failed to contact the remote
+.B portmap
+service. In the latter case, the global variable
+.B rpc_createerr(\|)
+contains the
+.SM RPC
+status.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+enum clnt_stat
+pmap_rmtcall(addr, prognum, versnum, procnum, inproc, in, outproc, out, tout, portp)
+struct sockaddr_in *addr;
+u_long prognum, versnum, procnum;
+char *in, *out;
+xdrproc_t inproc, outproc;
+struct timeval tout;
+u_long *portp;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which instructs
+.B portmap
+on the host at
+.SM IP
+address
+.I *addr
+to make an
+.SM RPC
+call on your behalf to a procedure on that host.
+The parameter
+.I *portp
+will be modified to the program's port number if the
+procedure
+succeeds.
+The definitions of other parameters are discussed
+in
+.B callrpc(\|)
+and
+.BR clnt_call(\|) .
+This procedure should be used for a \(lqping\(rq and nothing
+else.
+See also
+.BR clnt_broadcast(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+pmap_set(prognum, versnum, protocol, port)
+u_long prognum, versnum, protocol;
+u_short port;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which establishes a mapping between the triple
+.RI [ prognum , versnum , protocol\fR]
+and
+.I port
+on the machine's
+.B portmap
+service.
+The value of
+.I protocol
+is most likely
+.B
+.SM IPPROTO_UDP
+or
+.BR \s-1IPPROTO_TCP\s0 .
+This routine returns one if it succeeds, zero otherwise.
+Automatically done by
+.BR svc_register(\|) .
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+pmap_unset(prognum, versnum)
+u_long prognum, versnum;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which destroys all mapping between the triple
+.RI [ prognum , versnum , *\fR]
+and
+.B ports
+on the machine's
+.B portmap
+service.
+This routine returns one if it succeeds, zero
+otherwise.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+registerrpc(prognum, versnum, procnum, procname, inproc, outproc)
+u_long prognum, versnum, procnum;
+char *(*procname) (\|) ;
+xdrproc_t inproc, outproc;
+.fi
+.ft R
+.IP
+Register procedure
+.I procname
+with the
+.SM RPC
+service package. If a request arrives for program
+.IR prognum ,
+version
+.IR versnum ,
+and procedure
+.IR procnum ,
+.I procname
+is called with a pointer to its parameter(s);
+.I progname
+should return a pointer to its static result(s);
+.I inproc
+is used to decode the parameters while
+.I outproc
+is used to encode the results.
+This routine returns zero if the registration succeeded, \-1
+otherwise.
+.IP
+Warning: remote procedures registered in this form
+are accessed using the
+.SM UDP/IP
+transport; see
+.B svcudp_create(\|)
+for restrictions.
+.br
+.if t .ne 5
+.LP
+.ft B
+.nf
+.sp .5
+struct rpc_createerr rpc_createerr;
+.fi
+.ft R
+.IP
+A global variable whose value is set by any
+.SM RPC
+client creation routine
+that does not succeed. Use the routine
+.B clnt_pcreateerror(\|)
+to print the reason why.
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+svc_destroy(xprt)
+\s-1SVCXPRT\s0 *
+xprt;
+.fi
+.ft R
+.IP
+A macro that destroys the
+.SM RPC
+service transport handle,
+.IR xprt .
+Destruction usually involves deallocation
+of private data structures, including
+.I xprt
+itself. Use of
+.I xprt
+is undefined after calling this routine.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+fd_set svc_fdset;
+.fi
+.ft R
+.IP
+A global variable reflecting the
+.SM RPC
+service side's
+read file descriptor bit mask; it is suitable as a template parameter
+to the
+.B select
+system call.
+This is only of interest
+if a service implementor does not call
+.BR svc_run(\|) ,
+but rather does his own asynchronous event processing.
+This variable is read-only (do not pass its address to
+.BR select !),
+yet it may change after calls to
+.B svc_getreqset(\|)
+or any creation routines.
+.br
+As well, note that if the process has descriptor limits
+which are extended beyond
+.BR FD_SETSIZE ,
+this variable will only be usable for the first
+.BR FD_SETSIZE
+descriptors.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+int svc_fds;
+.fi
+.ft R
+.IP
+Similar to
+.BR svc_fedset(\|) ,
+but limited to 32 descriptors.
+This
+interface is obsoleted by
+.BR svc_fdset(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+svc_freeargs(xprt, inproc, in)
+\s-1SVCXPRT\s0 *xprt;
+xdrproc_t inproc;
+char *in;
+.fi
+.ft R
+.IP
+A macro that frees any data allocated by the
+.SM RPC/XDR
+system when it decoded the arguments to a service procedure
+using
+.BR svc_getargs(\|) .
+This routine returns 1 if the results were successfully
+freed,
+and zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+svc_getargs(xprt, inproc, in)
+\s-1SVCXPRT\s0 *xprt;
+xdrproc_t inproc;
+char *in;
+.fi
+.ft R
+.IP
+A macro that decodes the arguments of an
+.SM RPC
+request
+associated with the
+.SM RPC
+service transport handle,
+.IR xprt .
+The parameter
+.I in
+is the address where the arguments will be placed;
+.I inproc
+is the
+.SM XDR
+routine used to decode the arguments.
+This routine returns one if decoding succeeds, and zero
+otherwise.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+struct sockaddr_in *
+svc_getcaller(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+The approved way of getting the network address of the caller
+of a procedure associated with the
+.SM RPC
+service transport handle,
+.IR xprt .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+svc_getreqset(rdfds)
+fd_set *rdfds;
+.fi
+.ft R
+.IP
+This routine is only of interest if a service implementor
+does not call
+.BR svc_run(\|) ,
+but instead implements custom asynchronous event processing.
+It is called when the
+.B select
+system call has determined that an
+.SM RPC
+request has arrived on some
+.SM RPC
+.B socket(s) ;
+.I rdfds
+is the resultant read file descriptor bit mask.
+The routine returns when all sockets associated with the
+value of
+.I rdfds
+have been serviced.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+svc_getreq(rdfds)
+int rdfds;
+.fi
+.ft R
+.IP
+Similar to
+.BR svc_getreqset(\|) ,
+but limited to 32 descriptors.
+This interface is obsoleted by
+.BR svc_getreqset(\|) .
+.br
+.if t .ne 17
+.LP
+.ft B
+.nf
+.sp .5
+svc_register(xprt, prognum, versnum, dispatch, protocol)
+\s-1SVCXPRT\s0 *xprt;
+u_long prognum, versnum;
+void (*dispatch) (\|);
+u_long protocol;
+.fi
+.ft R
+.IP
+Associates
+.I prognum
+and
+.I versnum
+with the service dispatch procedure,
+.IR dispatch .
+If
+.I protocol
+is zero, the service is not registered with the
+.B portmap
+service. If
+.I protocol
+is non-zero, then a mapping of the triple
+.RI [ prognum , versnum , protocol\fR]
+to
+\fB\%xprt\->xp_port\fR
+is established with the local
+.B portmap
+service (generally
+.I protocol
+is zero,
+.B
+.SM IPPROTO_UDP
+or
+.B
+.SM IPPROTO_TCP
+).
+The procedure
+.I dispatch
+has the following form:
+.RS 1i
+.ft B
+.nf
+dispatch(request, xprt)
+struct svc_req *request;
+\s-1SVCXPRT\s0 *xprt;
+.ft R
+.fi
+.RE
+.IP
+The
+.B svc_register(\|)
+routine returns one if it succeeds, and zero otherwise.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+svc_run(\|)
+.fi
+.ft R
+.IP
+This routine never returns.
+It waits for
+.SM RPC
+requests to arrive, and calls the appropriate service
+procedure using
+.B svc_getreq(\|)
+when one arrives.
+This procedure is usually waiting for a
+.B select(\|)
+system call to return.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+svc_sendreply(xprt, outproc, out)
+\s-1SVCXPRT\s0 *xprt;
+xdrproc_t outproc;
+char *out;
+.fi
+.ft R
+.IP
+Called by an
+.SM RPC
+service's dispatch routine to send the results of a
+remote procedure call. The parameter
+.I xprt
+is the request's associated transport handle;
+.I outproc
+is the
+.SM XDR
+routine which is used to encode the results; and
+.I out
+is the address of the results.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svc_unregister(prognum, versnum)
+u_long prognum, versnum;
+.fi
+.ft R
+.IP
+Remove all mapping of the double
+.RI [ prognum , versnum ]
+to dispatch routines, and of the triple
+.RI [ prognum , versnum , *\fR]
+to port number.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_auth(xprt, why)
+\s-1SVCXPRT\s0 *xprt;
+enum auth_stat why;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that refuses to perform
+a remote procedure call due to an authentication error.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_decode(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that cannot successfully
+decode its parameters.
+See also
+.BR svc_getargs(\|) .
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_noproc(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that does not implement
+the procedure number that the caller requests.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_noprog(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called when the desired program is not registered with the
+.SM RPC
+package.
+Service implementors usually do not need this routine.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_progvers(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called when the desired version of a program is not registered
+with the
+.SM RPC
+package.
+Service implementors usually do not need this routine.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_systemerr(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine when it detects a system
+error
+not covered by any particular protocol.
+For example, if a service can no longer allocate storage,
+it may call this routine.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_weakauth(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that refuses to perform
+a remote procedure call due to insufficient
+authentication parameters. The routine calls
+.BR "svcerr_auth(xprt, \s-1AUTH_TOOWEAK\s0)" .
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svcraw_create(\|)
+.fi
+.ft R
+.IP
+This routine creates a toy
+.SM RPC
+service transport, to which it returns a pointer. The
+transport
+is really a buffer within the process's address space,
+so the corresponding
+.SM RPC
+client should live in the same
+address space;
+see
+.BR clntraw_create(\|) .
+This routine allows simulation of
+.SM RPC
+and acquisition of
+.SM RPC
+overheads (such as round trip times), without any kernel
+interference.
+This routine returns
+.SM NULL
+if it fails.
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svctcp_create(sock, send_buf_size, recv_buf_size)
+int sock;
+u_int send_buf_size, recv_buf_size;
+.fi
+.ft R
+.IP
+This routine creates a
+.SM TCP/IP\s0-based
+.SM RPC
+service transport, to which it returns a pointer.
+The transport is associated with the socket
+.IR sock ,
+which may be
+.BR \s-1RPC_ANYSOCK\s0 ,
+in which case a new socket is created.
+If the socket is not bound to a local
+.SM TCP
+port, then this routine binds it to an arbitrary port. Upon
+completion,
+\fB\%xprt\->xp_sock\fR
+is the transport's socket descriptor, and
+\fB\%xprt\->xp_port\fR
+is the transport's port number.
+This routine returns
+.SM NULL
+if it fails.
+Since
+.SM TCP\s0-based
+.SM RPC
+uses buffered
+.SM I/O ,
+users may specify the size of buffers; values of zero
+choose suitable defaults.
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svcfd_create(fd, sendsize, recvsize)
+int fd;
+u_int sendsize;
+u_int recvsize;
+.fi
+.ft R
+.IP
+Create a service on top of any open descriptor.
+Typically,
+this
+descriptor is a connected socket for a stream protocol such
+as
+.SM TCP\s0.
+.I sendsize
+and
+.I recvsize
+indicate sizes for the send and receive buffers. If they are
+zero, a reasonable default is chosen.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svcudp_bufcreate(sock, sendsize, recosize)
+int sock;
+.fi
+.ft R
+.IP
+This routine creates a
+.SM UDP/IP\s0-based
+.SM RPC
+service transport, to which it returns a pointer.
+The transport is associated with the socket
+.IR sock ,
+which may be
+.B \s-1RPC_ANYSOCK\s0 ,
+in which case a new socket is created.
+If the socket is not bound to a local
+.SM UDP
+port, then this routine binds it to an arbitrary port.
+Upon
+completion,
+\fB\%xprt\->xp_sock\fR
+is the transport's socket descriptor, and
+\fB\%xprt\->xp_port\fR
+is the transport's port number.
+This routine returns
+.SM NULL
+if it fails.
+.IP
+This allows the user to specify the maximum packet size for sending and
+receiving
+.SM UDP\s0-based
+.SM RPC messages.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_accepted_reply(xdrs, ar)
+\s-1XDR\s0 *xdrs;
+struct accepted_reply *ar;
+.fi
+.ft R
+.IP
+Used for encoding
+.SM RPC
+reply messages.
+This routine is useful for users who
+wish to generate
+\s-1RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_authunix_parms(xdrs, aupp)
+\s-1XDR\s0 *xdrs;
+struct authunix_parms *aupp;
+.fi
+.ft R
+.IP
+Used for describing
+.SM UNIX
+credentials.
+This routine is useful for users
+who wish to generate these credentials without using the
+.SM RPC
+authentication package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdr_callhdr(xdrs, chdr)
+\s-1XDR\s0 *xdrs;
+struct rpc_msg *chdr;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+call header messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_callmsg(xdrs, cmsg)
+\s-1XDR\s0 *xdrs;
+struct rpc_msg *cmsg;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+call messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_opaque_auth(xdrs, ap)
+\s-1XDR\s0 *xdrs;
+struct opaque_auth *ap;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+authentication information messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_pmap(xdrs, regs)
+\s-1XDR\s0 *xdrs;
+struct pmap *regs;
+.fi
+.ft R
+.IP
+Used for describing parameters to various
+.B portmap
+procedures, externally.
+This routine is useful for users who wish to generate
+these parameters without using the
+.B pmap
+interface.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_pmaplist(xdrs, rp)
+\s-1XDR\s0 *xdrs;
+struct pmaplist **rp;
+.fi
+.ft R
+.IP
+Used for describing a list of port mappings, externally.
+This routine is useful for users who wish to generate
+these parameters without using the
+.B pmap
+interface.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_rejected_reply(xdrs, rr)
+\s-1XDR\s0 *xdrs;
+struct rejected_reply *rr;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+reply messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_replymsg(xdrs, rmsg)
+\s-1XDR\s0 *xdrs;
+struct rpc_msg *rmsg;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+reply messages.
+This routine is useful for users who wish to generate
+.SM RPC
+style messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+xprt_register(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+After
+.SM RPC
+service transport handles are created,
+they should register themselves with the
+.SM RPC
+service package.
+This routine modifies the global variable
+.BR svc_fds(\|) .
+Service implementors usually do not need this routine.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+xprt_unregister(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Before an
+.SM RPC
+service transport handle is destroyed,
+it should unregister itself with the
+.SM RPC
+service package.
+This routine modifies the global variable
+.BR svc_fds(\|) .
+Service implementors usually do not need this routine.
+.SH SEE ALSO
+.BR rpc_secure (3),
+.BR xdr (3)
+.br
+The following manuals:
+.RS
+.ft I
+Remote Procedure Calls: Protocol Specification
+.br
+Remote Procedure Call Programming Guide
+.br
+rpcgen Programming Guide
+.br
+.ft R
+.RE
+.IR "\s-1RPC\s0: Remote Procedure Call Protocol Specification" ,
+.SM RFC1050, Sun Microsystems, Inc.,
+.SM USC-ISI\s0.
+
diff --git a/cpukit/librpc/src/rpc/rpc.5 b/cpukit/librpc/src/rpc/rpc.5
new file mode 100644
index 0000000000..36f895dbf2
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc.5
@@ -0,0 +1,35 @@
+.\" $FreeBSD: src/lib/libc/rpc/rpc.5,v 1.6 1999/08/28 00:00:44 peter Exp $
+.\" @(#)rpc.5 2.2 88/08/03 4.0 RPCSRC; from 1.4 87/11/27 SMI;
+.Dd September 26, 1985
+.Dt RPC 5
+.Sh NAME
+.Nm rpc
+.Nd rpc program number data base
+.Sh SYNOPSIS
+/etc/rpc
+.Sh DESCRIPTION
+The
+.Pa /etc/rpc
+file contains user readable names that
+can be used in place of rpc program numbers.
+Each line has the following information:
+.Pp
+.Bl -bullet -compact
+.It
+name of server for the rpc program
+.It
+rpc program number
+.It
+aliases
+.El
+.Pp
+Items are separated by any number of blanks and/or
+tab characters.
+A ``#'' indicates the beginning of a comment; characters up to the end of
+the line are not interpreted by routines which search the file.
+.Sh FILES
+.Bl -tag -compact -width /etc/rpc
+.Pa /etc/rpc
+.El
+.Sh "SEE ALSO"
+.Xr getrpcent 3
diff --git a/cpukit/librpc/src/rpc/rpc_callmsg.c b/cpukit/librpc/src/rpc/rpc_callmsg.c
new file mode 100644
index 0000000000..b44ebb4a36
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc_callmsg.c
@@ -0,0 +1,196 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_callmsg.c,v 1.9 1999/08/28 00:00:45 peter Exp $";
+#endif
+
+/*
+ * rpc_callmsg.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/rpc.h>
+
+/*
+ * XDR a call message
+ */
+bool_t
+xdr_callmsg(
+ XDR *xdrs,
+ struct rpc_msg *cmsg)
+{
+ register int32_t *buf;
+ register struct opaque_auth *oa;
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
+ + RNDUP(cmsg->rm_call.cb_cred.oa_length)
+ + 2 * BYTES_PER_XDR_UNIT
+ + RNDUP(cmsg->rm_call.cb_verf.oa_length));
+ if (buf != NULL) {
+ IXDR_PUT_LONG(buf, cmsg->rm_xid);
+ IXDR_PUT_ENUM(buf, cmsg->rm_direction);
+ if (cmsg->rm_direction != CALL) {
+ return (FALSE);
+ }
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
+ if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
+ return (FALSE);
+ }
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
+ oa = &cmsg->rm_call.cb_cred;
+ IXDR_PUT_ENUM(buf, oa->oa_flavor);
+ IXDR_PUT_LONG(buf, oa->oa_length);
+ if (oa->oa_length) {
+ memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
+ buf += RNDUP(oa->oa_length) / sizeof (int32_t);
+ }
+ oa = &cmsg->rm_call.cb_verf;
+ IXDR_PUT_ENUM(buf, oa->oa_flavor);
+ IXDR_PUT_LONG(buf, oa->oa_length);
+ if (oa->oa_length) {
+ memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
+ /* no real need....
+ buf += RNDUP(oa->oa_length) / sizeof (int32_t);
+ */
+ }
+ return (TRUE);
+ }
+ }
+ if (xdrs->x_op == XDR_DECODE) {
+ buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
+ if (buf != NULL) {
+ cmsg->rm_xid = IXDR_GET_LONG(buf);
+ cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
+ if (cmsg->rm_direction != CALL) {
+ return (FALSE);
+ }
+ cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
+ if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
+ return (FALSE);
+ }
+ cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
+ cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
+ cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
+ oa = &cmsg->rm_call.cb_cred;
+ oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
+ oa->oa_length = IXDR_GET_LONG(buf);
+ if (oa->oa_length) {
+ if (oa->oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (oa->oa_base == NULL) {
+ oa->oa_base = (caddr_t)
+ mem_alloc(oa->oa_length);
+ }
+ buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
+ if (buf == NULL) {
+ if (xdr_opaque(xdrs, oa->oa_base,
+ oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ memcpy(oa->oa_base, (caddr_t)buf,
+ oa->oa_length);
+ /* no real need....
+ buf += RNDUP(oa->oa_length) /
+ sizeof (int32_t);
+ */
+ }
+ }
+ oa = &cmsg->rm_call.cb_verf;
+ buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
+ xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
+ oa->oa_length = IXDR_GET_LONG(buf);
+ }
+ if (oa->oa_length) {
+ if (oa->oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (oa->oa_base == NULL) {
+ oa->oa_base = (caddr_t)
+ mem_alloc(oa->oa_length);
+ }
+ buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
+ if (buf == NULL) {
+ if (xdr_opaque(xdrs, oa->oa_base,
+ oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ memcpy(oa->oa_base, (caddr_t)buf,
+ oa->oa_length);
+ /* no real need...
+ buf += RNDUP(oa->oa_length) /
+ sizeof (int32_t);
+ */
+ }
+ }
+ return (TRUE);
+ }
+ }
+ if (
+ xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *)(void *)&(cmsg->rm_direction)) &&
+ (cmsg->rm_direction == CALL) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
+ (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
+ xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
+ return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
+ return (FALSE);
+}
diff --git a/cpukit/librpc/src/rpc/rpc_commondata.c b/cpukit/librpc/src/rpc/rpc_commondata.c
new file mode 100644
index 0000000000..ad22568446
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc_commondata.c
@@ -0,0 +1,45 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_commondata.c,v 1.7 1999/08/28 00:00:45 peter Exp $";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+/*
+ * This file should only contain common data (global data) that is exported
+ * by public interfaces
+ */
+struct opaque_auth _null_auth;
+struct rpc_createerr rpc_createerr;
diff --git a/cpukit/librpc/src/rpc/rpc_dtablesize.c b/cpukit/librpc/src/rpc/rpc_dtablesize.c
new file mode 100644
index 0000000000..65f295315e
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc_dtablesize.c
@@ -0,0 +1,65 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";*/
+/*static char *sccsid = "from: @(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_dtablesize.c,v 1.10 1999/08/28 00:00:45 peter Exp $";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+
+/*
+ * Cache the result of getdtablesize(), so we don't have to do an
+ * expensive system call every time.
+ */
+/*
+ * XXX In FreeBSD 2.x, you can have the maximum number of open file
+ * descriptors be greater than FD_SETSIZE (which us 256 by default).
+ *
+ * Since old programs tend to use this call to determine the first arg
+ * for select(), having this return > FD_SETSIZE is a Bad Idea(TM)!
+ */
+int
+_rpc_dtablesize(void)
+{
+ static int size;
+
+ if (size == 0) {
+ size = getdtablesize();
+ if (size > FD_SETSIZE)
+ size = FD_SETSIZE;
+ }
+ return (size);
+}
diff --git a/cpukit/librpc/src/rpc/rpc_prot.c b/cpukit/librpc/src/rpc/rpc_prot.c
new file mode 100644
index 0000000000..0718c9a990
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc_prot.c
@@ -0,0 +1,336 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_prot.c,v 1.8 1999/08/28 00:00:46 peter Exp $";
+#endif
+
+/*
+ * rpc_prot.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * This set of routines implements the rpc message definition,
+ * its serializer and some common rpc utility routines.
+ * The routines are meant for various implementations of rpc -
+ * they are NOT for the rpc client or rpc service implementations!
+ * Because authentication stuff is easy and is part of rpc, the opaque
+ * routines are also in this program.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <sys/param.h>
+
+#include <rpc/rpc.h>
+
+static void accepted(enum accept_stat, struct rpc_err *);
+static void rejected(enum reject_stat, struct rpc_err *);
+
+/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
+
+extern struct opaque_auth _null_auth;
+
+/*
+ * XDR an opaque authentication struct
+ * (see auth.h)
+ */
+bool_t
+xdr_opaque_auth(
+ XDR *xdrs,
+ struct opaque_auth *ap)
+{
+
+ assert(xdrs != NULL);
+ assert(ap != NULL);
+
+ if (xdr_enum(xdrs, &(ap->oa_flavor)))
+ return (xdr_bytes(xdrs, &ap->oa_base,
+ &ap->oa_length, MAX_AUTH_BYTES));
+ return (FALSE);
+}
+
+/*
+ * XDR a DES block
+ */
+bool_t
+xdr_des_block(
+ XDR *xdrs,
+ des_block *blkp)
+{
+
+ assert(xdrs != NULL);
+ assert(blkp != NULL);
+
+ return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof(des_block)));
+}
+
+/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
+
+/*
+ * XDR the MSG_ACCEPTED part of a reply message union
+ */
+bool_t
+xdr_accepted_reply(
+ XDR *xdrs,
+ struct accepted_reply *ar)
+{
+
+ /* personalized union, rather than calling xdr_union */
+ if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
+ return (FALSE);
+ if (! xdr_enum(xdrs, (enum_t *)(void *)&(ar->ar_stat)))
+ return (FALSE);
+ switch (ar->ar_stat) {
+
+ case SUCCESS:
+ return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
+
+ case PROG_MISMATCH:
+ if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low)))
+ return (FALSE);
+ return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high)));
+
+ case GARBAGE_ARGS:
+ case SYSTEM_ERR:
+ case PROC_UNAVAIL:
+ case PROG_UNAVAIL:
+ break;
+ }
+ return (TRUE); /* TRUE => open ended set of problems */
+}
+
+/*
+ * XDR the MSG_DENIED part of a reply message union
+ */
+bool_t
+xdr_rejected_reply(
+ XDR *xdrs,
+ struct rejected_reply *rr )
+{
+
+ /* personalized union, rather than calling xdr_union */
+ if (! xdr_enum(xdrs, (enum_t *)(void *)&(rr->rj_stat)))
+ return (FALSE);
+ switch (rr->rj_stat) {
+
+ case RPC_MISMATCH:
+ if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low)))
+ return (FALSE);
+ return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high)));
+
+ case AUTH_ERROR:
+ return (xdr_enum(xdrs, (enum_t *)(void *)&(rr->rj_why)));
+ }
+ return (FALSE);
+}
+
+static const struct xdr_discrim reply_dscrm[3] = {
+ { (int)MSG_ACCEPTED, (xdrproc_t)xdr_accepted_reply },
+ { (int)MSG_DENIED, (xdrproc_t)xdr_rejected_reply },
+ { __dontcare__, NULL_xdrproc_t } };
+
+/*
+ * XDR a reply message
+ */
+bool_t
+xdr_replymsg(
+ XDR *xdrs,
+ struct rpc_msg *rmsg)
+{
+ if (
+ xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *)(void *)&(rmsg->rm_direction)) &&
+ (rmsg->rm_direction == REPLY) )
+ return (xdr_union(xdrs, (enum_t *)(void *)&(rmsg->rm_reply.rp_stat),
+ (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
+ return (FALSE);
+}
+
+
+/*
+ * Serializes the "static part" of a call message header.
+ * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
+ * The rm_xid is not really static, but the user can easily munge on the fly.
+ */
+bool_t
+xdr_callhdr(
+ XDR *xdrs,
+ struct rpc_msg *cmsg)
+{
+
+ cmsg->rm_direction = CALL;
+ cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ if (
+ (xdrs->x_op == XDR_ENCODE) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *)(void *)&(cmsg->rm_direction)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
+ return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
+ return (FALSE);
+}
+
+/* ************************** Client utility routine ************* */
+
+static void
+accepted(
+ enum accept_stat acpt_stat,
+ struct rpc_err *error)
+{
+
+ assert(error != NULL);
+
+ switch (acpt_stat) {
+
+ case PROG_UNAVAIL:
+ error->re_status = RPC_PROGUNAVAIL;
+ return;
+
+ case PROG_MISMATCH:
+ error->re_status = RPC_PROGVERSMISMATCH;
+ return;
+
+ case PROC_UNAVAIL:
+ error->re_status = RPC_PROCUNAVAIL;
+ return;
+
+ case GARBAGE_ARGS:
+ error->re_status = RPC_CANTDECODEARGS;
+ return;
+
+ case SYSTEM_ERR:
+ error->re_status = RPC_SYSTEMERROR;
+ return;
+
+ case SUCCESS:
+ error->re_status = RPC_SUCCESS;
+ return;
+ }
+ /* something's wrong, but we don't know what ... */
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
+ error->re_lb.s2 = (int32_t)acpt_stat;
+}
+
+static void
+rejected(
+ enum reject_stat rjct_stat,
+ struct rpc_err *error)
+{
+
+ assert(error != NULL);
+
+ switch (rjct_stat) {
+ case RPC_MISMATCH:
+ error->re_status = RPC_VERSMISMATCH;
+ return;
+
+ case AUTH_ERROR:
+ error->re_status = RPC_AUTHERROR;
+ return;
+ }
+ /* something's wrong, but we don't know what ... */
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (int32_t)MSG_DENIED;
+ error->re_lb.s2 = (int32_t)rjct_stat;
+}
+
+/*
+ * given a reply message, fills in the error
+ */
+void
+_seterr_reply(
+ struct rpc_msg *msg,
+ struct rpc_err *error)
+{
+
+ assert(msg != NULL);
+ assert(error != NULL);
+
+ /* optimized for normal, SUCCESSful case */
+ switch (msg->rm_reply.rp_stat) {
+
+ case MSG_ACCEPTED:
+ if (msg->acpted_rply.ar_stat == SUCCESS) {
+ error->re_status = RPC_SUCCESS;
+ return;
+ }
+ accepted(msg->acpted_rply.ar_stat, error);
+ break;
+
+ case MSG_DENIED:
+ rejected(msg->rjcted_rply.rj_stat, error);
+ break;
+
+ default:
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
+ break;
+ }
+ switch (error->re_status) {
+
+ case RPC_VERSMISMATCH:
+ error->re_vers.low = msg->rjcted_rply.rj_vers.low;
+ error->re_vers.high = msg->rjcted_rply.rj_vers.high;
+ break;
+
+ case RPC_AUTHERROR:
+ error->re_why = msg->rjcted_rply.rj_why;
+ break;
+
+ case RPC_PROGVERSMISMATCH:
+ error->re_vers.low = msg->acpted_rply.ar_vers.low;
+ error->re_vers.high = msg->acpted_rply.ar_vers.high;
+ break;
+
+ case RPC_FAILED:
+ case RPC_SUCCESS:
+ case RPC_PROGNOTREGISTERED:
+ case RPC_PMAPFAILURE:
+ case RPC_UNKNOWNPROTO:
+ case RPC_UNKNOWNHOST:
+ case RPC_SYSTEMERROR:
+ case RPC_CANTDECODEARGS:
+ case RPC_PROCUNAVAIL:
+ case RPC_PROGUNAVAIL:
+ case RPC_TIMEDOUT:
+ case RPC_CANTRECV:
+ case RPC_CANTSEND:
+ case RPC_CANTDECODERES:
+ case RPC_CANTENCODEARGS:
+ default:
+ break;
+ }
+}
diff --git a/cpukit/librpc/src/rpc/rpc_secure.3 b/cpukit/librpc/src/rpc/rpc_secure.3
new file mode 100644
index 0000000000..4efd9b8614
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpc_secure.3
@@ -0,0 +1,254 @@
+.\" @(#)rpc_secure.3n 2.1 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
+.\" $FreeBSD: src/lib/libc/rpc/rpc_secure.3,v 1.6 2000/03/02 09:13:48 sheldonh Exp $
+.\"
+.Dd February 16, 1988
+.Dt RPC 3
+.Sh NAME
+.Nm rpc_secure
+.Nd library routines for secure remote procedure calls
+.Sh SYNOPSIS
+.Fd #include <rpc/rpc.h>
+.Ft AUTH *
+.Fo authdes_create
+.Fa "char *name"
+.Fa "unsigned window"
+.Fa "struct sockaddr *addr"
+.Fa "des_block *ckey"
+.Fc
+.Ft int
+.Fn authdes_getucred "struct authdes_cred *adc" "uid_t *uid" "gid_t *gid" "int *grouplen" "gid_t *groups"
+.Ft int
+.Fn getnetname "char *name"
+.Ft int
+.Fn host2netname "char *name" "char *host" "char *domain"
+.Ft int
+.Fn key_decryptsession "const char *remotename" "des_block *deskey"
+.Ft int
+.Fn key_encryptsession "const char *remotename" "des_block *deskey"
+.Ft int
+.Fn key_gendes "des_block *deskey"
+.Ft int
+.Fn key_setsecret "const char *key"
+.Ft int
+.Fn netname2host "char *name" "char *host" "int hostlen"
+.Ft int
+.Fn netname2user "char *name" "uid_t *uidp" "gid_t *gidp" "int *gidlenp" "gid_t *gidlist"
+.Ft int
+.Fn user2netname "char *name" "uid_t uid" "char *domain"
+.Sh DESCRIPTION
+These routines are part of the
+.Tn RPC
+library. They implement
+.Tn DES
+Authentication. See
+.Xr rpc 3
+for further details about
+.Tn RPC .
+.Pp
+The
+.Fn authdes_create
+is the first of two routines which interface to the
+.Tn RPC
+secure authentication system, known as
+.Tn DES
+authentication.
+The second is
+.Fn authdes_getucred ,
+below.
+.Pp
+Note: the keyserver daemon
+.Xr keyserv 8
+must be running for the
+.Tn DES
+authentication system to work.
+.Pp
+.Fn Authdes_create ,
+used on the client side, returns an authentication handle that
+will enable the use of the secure authentication system.
+The first parameter
+.Fa name
+is the network name, or
+.Fa netname ,
+of the owner of the server process.
+This field usually
+represents a
+.Fa hostname
+derived from the utility routine
+.Fn host2netname ,
+but could also represent a user name using
+.Fn user2netname .
+The second field is window on the validity of
+the client credential, given in seconds. A small
+window is more secure than a large one, but choosing
+too small of a window will increase the frequency of
+resynchronizations because of clock drift.
+The third
+parameter
+.Fa addr
+is optional. If it is
+.Dv NULL ,
+then the authentication system will assume
+that the local clock is always in sync with the server's
+clock, and will not attempt resynchronizations.
+If an address
+is supplied, however, then the system will use the address
+for consulting the remote time service whenever
+resynchronization
+is required.
+This parameter is usually the
+address of the
+.Tn RPC
+server itself.
+The final parameter
+.Fa ckey
+is also optional. If it is
+.Dv NULL ,
+then the authentication system will
+generate a random
+.Tn DES
+key to be used for the encryption of credentials.
+If it is supplied, however, then it will be used instead.
+.Pp
+.Fn Authdes_getucred ,
+the second of the two
+.Tn DES
+authentication routines,
+is used on the server side for converting a
+.Tn DES
+credential, which is
+operating system independent, into a
+.Ux
+credential.
+This routine differs from utility routine
+.Fn netname2user
+in that
+.Fn authdes_getucred
+pulls its information from a cache, and does not have to do a
+Yellow Pages lookup every time it is called to get its information.
+.Pp
+.Fn Getnetname
+installs the unique, operating-system independent netname of
+the
+caller in the fixed-length array
+.Fa name .
+Returns
+.Dv TRUE
+if it succeeds and
+.Dv FALSE
+if it fails.
+.Pp
+.Fn Host2netname
+converts from a domain-specific hostname to an
+operating-system independent netname.
+Returns
+.Dv TRUE
+if it succeeds and
+.Dv FALSE
+if it fails.
+Inverse of
+.Fn netname2host .
+.Pp
+.Fn Key_decryptsession
+is an interface to the keyserver daemon, which is associated
+with
+.Tn RPC Ns 's
+secure authentication system (
+.Tn DES
+authentication).
+User programs rarely need to call it, or its associated routines
+.Fn key_encryptsession ,
+.Fn key_gendes
+and
+.Fn key_setsecret .
+System commands such as
+.Xr login 1
+and the
+.Tn RPC
+library are the main clients of these four routines.
+.Pp
+.Fn Key_decryptsession
+takes a server netname and a
+.Tn DES
+key, and decrypts the key by
+using the the public key of the the server and the secret key
+associated with the effective uid of the calling process. It
+is the inverse of
+.Fn key_encryptsession .
+.Pp
+.Fn Key_encryptsession
+is a keyserver interface routine.
+It
+takes a server netname and a des key, and encrypts
+it using the public key of the the server and the secret key
+associated with the effective uid of the calling process. It
+is the inverse of
+.Fn key_decryptsession .
+.Pp
+.Fn Key_gendes
+is a keyserver interface routine.
+It
+is used to ask the keyserver for a secure conversation key.
+Choosing one
+.Qq random
+is usually not good enough,
+because
+the common ways of choosing random numbers, such as using the
+current time, are very easy to guess.
+.Pp
+.Fn Key_setsecret
+is a keyserver interface routine.
+It is used to set the key for
+the effective
+.Fa uid
+of the calling process.
+.Pp
+.Fn Netname2host
+converts from an operating-system independent netname to a
+domain-specific hostname.
+Returns
+.Dv TRUE
+if it succeeds and
+.Dv FALSE
+if it fails. Inverse of
+.Fn host2netname .
+.Pp
+.Fn Netname2user
+converts from an operating-system independent netname to a
+domain-specific user ID.
+Returns
+.Dv TRUE
+if it succeeds and
+.Dv FALSE
+if it fails.
+Inverse of
+.Fn user2netname .
+.Pp
+.Fn User2netname
+converts from a domain-specific username to an operating-system
+independent netname.
+Returns
+.Dv TRUE
+if it succeeds and
+.Dv FALSE
+if it fails.
+Inverse of
+.Fn netname2user .
+.Sh SEE ALSO
+.Xr rpc 3 ,
+.Xr xdr 3 ,
+.Xr keyserv 8
+.Pp
+The following manuals:
+.Rs
+.%B Remote Procedure Calls: Protocol Specification
+.Re
+.Rs
+.%B Remote Procedure Call Programming Guide
+.Re
+.Rs
+.%B Rpcgen Programming Guide
+.Re
+.Rs
+.%B RPC: Remote Procedure Call Protocol Specification
+.%O RFC1050, Sun Microsystems Inc., USC-ISI
+.Re
diff --git a/cpukit/librpc/src/rpc/rpcdname.c b/cpukit/librpc/src/rpc/rpcdname.c
new file mode 100644
index 0000000000..6482a74493
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rpcdname.c
@@ -0,0 +1,84 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)rpcdname.c 1.7 91/03/11 Copyr 1989 Sun Micro";
+#endif
+
+/*
+ * rpcdname.c
+ * Gets the default domain name
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+
+int getdomainname(char *, size_t);
+
+#define default_domain (rtems_rpc_task_variables->rpcdname_default_domain)
+
+static char *
+get_default_domain(void)
+{
+ char temp[256];
+
+ if (default_domain)
+ return (default_domain);
+ if (getdomainname(temp, sizeof(temp)) < 0)
+ return (0);
+ if (strlen(temp) > 0) {
+ default_domain = (char *)malloc((strlen(temp)+(size_t)1));
+ if (default_domain == 0)
+ return (0);
+ (void) strcpy(default_domain, temp);
+ return (default_domain);
+ }
+ return (0);
+}
+
+/*
+ * This is a wrapper for the system call getdomainname which returns a
+ * ypclnt.h error code in the failure case. It also checks to see that
+ * the domain name is non-null, knowing that the null string is going to
+ * get rejected elsewhere in the NIS client package.
+ */
+int
+_rpc_get_default_domain(
+ char **domain )
+{
+ if ((*domain = get_default_domain()) != 0)
+ return (0);
+ return (-1);
+}
diff --git a/cpukit/librpc/src/rpc/rstat.1 b/cpukit/librpc/src/rpc/rstat.1
new file mode 100644
index 0000000000..6cc47c26c8
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rstat.1
@@ -0,0 +1,58 @@
+.\" $FreeBSD: src/lib/libc/rpc/rstat.1,v 1.5 1999/08/28 00:00:46 peter Exp $
+.\" @(#)rstat.1 2.1 88/08/03 4.0 RPCSRC
+.TH RSTAT 1 "3 August 1988"
+.SH NAME
+rstat \- remote status display
+.SH SYNOPSIS
+.B rstat
+.B host
+.SH DESCRIPTION
+.LP
+.B rstat
+displays a summary of the current system status of a particular
+.BR host .
+The output shows the current time of day, how long the system has
+been up,
+and the load averages.
+The load average numbers give the number of jobs in the run queue
+averaged over 1, 5 and 15 minutes.
+.PP
+The
+.B rstat_svc(8)
+daemon must be running on the remote host for this command to
+work.
+.B rstat
+uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x.
+.SH EXAMPLE
+.RS
+.ft B
+.nf
+example% rstat otherhost
+7:36am up 6 days, 16:45, load average: 0.20, 0.23, 0.18
+example%
+.ft R
+.fi
+.RE
+.SH DIAGNOSTICS
+.LP
+rstat: RPC: Program not registered
+.IP
+The
+.B rstat_svc
+daemon has not been started on the remote host.
+.LP
+rstat: RPC: Timed out
+.IP
+A communication error occurred. Either the network is
+excessively congested, or the
+.B rstat_svc
+daemon has terminated on the remote host.
+.LP
+rstat: RPC: Port mapper failure - RPC: Timed out
+.IP
+The remote host is not running the portmapper (see
+.BR portmap(8) ),
+and cannot accommodate any RPC-based services. The host may be down.
+.SH "SEE ALSO"
+.BR portmap (8),
+.BR rstat_svc (8)
diff --git a/cpukit/librpc/src/rpc/rstat_svc.8 b/cpukit/librpc/src/rpc/rstat_svc.8
new file mode 100644
index 0000000000..e2eae8be3d
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rstat_svc.8
@@ -0,0 +1,22 @@
+.\" $FreeBSD: src/lib/libc/rpc/rstat_svc.8,v 1.5 1999/08/28 00:00:47 peter Exp $
+.\" @(#)rstat_svc.8c 2.2 88/08/03 4.0 RPCSRC; from 1.10 87/09/09 SMI
+.TH RSTAT_SVC 8 "24 November 1987"
+.SH NAME
+rstat_svc \- kernel statistics server
+.SH SYNOPSIS
+.B /etc/rstat_svc
+.SH DESCRIPTION
+.LP
+.B rstat_svc
+is a server which returns performance statistics
+obtained from the kernel.
+These statistics are graphically displayed by the Sun Microsystems program,
+.BR perfmeter (1).
+The
+.B rstat_svc
+daemon is normally invoked at boot time through /etc/rc.local.
+.PP
+.B rstat_svc
+uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x.
+.\" .SH "SEE ALSO"
+.\" .BR rstat (1),
diff --git a/cpukit/librpc/src/rpc/rtems_portmapper.c b/cpukit/librpc/src/rpc/rtems_portmapper.c
new file mode 100644
index 0000000000..9d327b5ded
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rtems_portmapper.c
@@ -0,0 +1,500 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/wait.h>
+#include <sys/signal.h>
+
+static void reg_service(struct svc_req *rqstp, SVCXPRT *xprt);
+static void callit(struct svc_req *rqstp, SVCXPRT *xprt);
+static struct pmaplist *pmaplist;
+static int debugging = 0;
+
+#include <rtems.h>
+#define fork() (-1)
+
+
+static rtems_task rtems_portmapper (rtems_task_argument unused)
+{
+ SVCXPRT *xprt;
+ int sock;
+ struct sockaddr_in addr;
+ int len = sizeof(struct sockaddr_in);
+ register struct pmaplist *pml;
+
+ rtems_rpc_task_init ();
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("portmap cannot create socket");
+ rtems_task_delete (RTEMS_SELF);
+ }
+
+ addr.sin_addr.s_addr = 0;
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(PMAPPORT);
+ if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
+ perror("portmap cannot bind");
+ close (sock);
+ rtems_task_delete (RTEMS_SELF);
+ }
+
+ if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
+ fprintf(stderr, "couldn't do udp_create\n");
+ close (sock);
+ rtems_task_delete (RTEMS_SELF);
+ }
+ /* make an entry for ourself */
+ pml = (struct pmaplist *)malloc(sizeof(struct pmaplist));
+ pml->pml_next = 0;
+ pml->pml_map.pm_prog = PMAPPROG;
+ pml->pml_map.pm_vers = PMAPVERS;
+ pml->pml_map.pm_prot = IPPROTO_UDP;
+ pml->pml_map.pm_port = PMAPPORT;
+ pmaplist = pml;
+
+ if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("portmap cannot create socket");
+ close (sock);
+ rtems_task_delete (RTEMS_SELF);
+ }
+ if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
+ perror("portmap cannot bind");
+ close (sock);
+ rtems_task_delete (RTEMS_SELF);
+ }
+ if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
+ == (SVCXPRT *)NULL) {
+ fprintf(stderr, "couldn't do tcp_create\n");
+ close (sock);
+ rtems_task_delete (RTEMS_SELF);
+ }
+ /* make an entry for ourself */
+ pml = (struct pmaplist *)malloc(sizeof(struct pmaplist));
+ pml->pml_map.pm_prog = PMAPPROG;
+ pml->pml_map.pm_vers = PMAPVERS;
+ pml->pml_map.pm_prot = IPPROTO_TCP;
+ pml->pml_map.pm_port = PMAPPORT;
+ pml->pml_next = pmaplist;
+ pmaplist = pml;
+
+ (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
+
+ svc_run();
+ fprintf(stderr, "run_svc returned unexpectedly\n");
+ close (sock);
+ rtems_task_delete (RTEMS_SELF);
+}
+
+static struct pmaplist *
+find_service(
+ u_long prog,
+ u_long vers,
+ int prot )
+{
+ register struct pmaplist *hit = NULL;
+ register struct pmaplist *pml;
+
+ for (pml = pmaplist; pml != NULL; pml = pml->pml_next) {
+ if ((pml->pml_map.pm_prog != prog) ||
+ (pml->pml_map.pm_prot != prot))
+ continue;
+ hit = pml;
+ if (pml->pml_map.pm_vers == vers)
+ break;
+ }
+ return (hit);
+}
+
+/*
+ * 1 OK, 0 not
+ */
+static void reg_service(
+ struct svc_req *rqstp,
+ SVCXPRT *xprt )
+{
+ struct pmap reg;
+ struct pmaplist *pml, *prevpml, *fnd;
+ int ans, port;
+ caddr_t t;
+
+#ifdef DEBUG
+ fprintf(stderr, "server: about do a switch\n");
+#endif
+ switch (rqstp->rq_proc) {
+
+ case PMAPPROC_NULL:
+ /*
+ * Null proc call
+ */
+ if ((!svc_sendreply(xprt, (xdrproc_t) xdr_void, NULL)) &&
+ debugging) {
+ abort();
+ }
+ break;
+
+ case PMAPPROC_SET:
+ /*
+ * Set a program,version to port mapping
+ */
+ if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (caddr_t)&reg))
+ svcerr_decode(xprt);
+ else {
+ /*
+ * check to see if already used
+ * find_service returns a hit even if
+ * the versions don't match, so check for it
+ */
+ fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot);
+ if (fnd && fnd->pml_map.pm_vers == reg.pm_vers) {
+ if (fnd->pml_map.pm_port == reg.pm_port) {
+ ans = 1;
+ goto done;
+ }
+ else {
+ ans = 0;
+ goto done;
+ }
+ } else {
+ /*
+ * add to END of list
+ */
+ pml = (struct pmaplist *)
+ malloc(sizeof(struct pmaplist));
+ pml->pml_map = reg;
+ pml->pml_next = 0;
+ if (pmaplist == 0) {
+ pmaplist = pml;
+ } else {
+ for (fnd= pmaplist; fnd->pml_next != 0;
+ fnd = fnd->pml_next);
+ fnd->pml_next = pml;
+ }
+ ans = 1;
+ }
+ done:
+ if ((!svc_sendreply(xprt, (xdrproc_t) xdr_long, (caddr_t)&ans)) &&
+ debugging) {
+ fprintf(stderr, "svc_sendreply\n");
+ abort();
+ }
+ }
+ break;
+
+ case PMAPPROC_UNSET:
+ /*
+ * Remove a program,version to port mapping.
+ */
+ if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (caddr_t)&reg))
+ svcerr_decode(xprt);
+ else {
+ ans = 0;
+ for (prevpml = NULL, pml = pmaplist; pml != NULL; ) {
+ if ((pml->pml_map.pm_prog != reg.pm_prog) ||
+ (pml->pml_map.pm_vers != reg.pm_vers)) {
+ /* both pml & prevpml move forwards */
+ prevpml = pml;
+ pml = pml->pml_next;
+ continue;
+ }
+ /* found it; pml moves forward, prevpml stays */
+ ans = 1;
+ t = (caddr_t)pml;
+ pml = pml->pml_next;
+ if (prevpml == NULL)
+ pmaplist = pml;
+ else
+ prevpml->pml_next = pml;
+ free(t);
+ }
+ if ((!svc_sendreply(xprt, (xdrproc_t) xdr_long, (caddr_t)&ans)) &&
+ debugging) {
+ fprintf(stderr, "svc_sendreply\n");
+ abort();
+ }
+ }
+ break;
+
+ case PMAPPROC_GETPORT:
+ /*
+ * Lookup the mapping for a program,version and return its port
+ */
+ if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (caddr_t)&reg))
+ svcerr_decode(xprt);
+ else {
+ fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot);
+ if (fnd)
+ port = fnd->pml_map.pm_port;
+ else
+ port = 0;
+ if ((!svc_sendreply(xprt, (xdrproc_t) xdr_long, (caddr_t)&port)) &&
+ debugging) {
+ fprintf(stderr, "svc_sendreply\n");
+ abort();
+ }
+ }
+ break;
+
+ case PMAPPROC_DUMP:
+ /*
+ * Return the current set of mapped program,version
+ */
+ if (!svc_getargs(xprt, (xdrproc_t) xdr_void, NULL))
+ svcerr_decode(xprt);
+ else {
+ if ((!svc_sendreply(xprt, (xdrproc_t) xdr_pmaplist,
+ (caddr_t)&pmaplist)) && debugging) {
+ fprintf(stderr, "svc_sendreply\n");
+ abort();
+ }
+ }
+ break;
+
+ case PMAPPROC_CALLIT:
+ /*
+ * Calls a procedure on the local machine. If the requested
+ * procedure is not registered this procedure does not return
+ * error information!!
+ * This procedure is only supported on rpc/udp and calls via
+ * rpc/udp. It passes null authentication parameters.
+ */
+ callit(rqstp, xprt);
+ break;
+
+ default:
+ svcerr_noproc(xprt);
+ break;
+ }
+}
+
+
+/*
+ * Stuff for the rmtcall service
+ */
+#define ARGSIZE 9000
+
+struct encap_parms {
+ u_long arglen;
+ char *args;
+};
+
+static bool_t
+xdr_encap_parms(
+ XDR *xdrs,
+ struct encap_parms *epp )
+{
+
+ u_int temp_epp_arglen = epp->arglen;
+ return (xdr_bytes(xdrs, &(epp->args), &temp_epp_arglen, ARGSIZE));
+}
+
+struct rmtcallargs {
+ u_long rmt_prog;
+ u_long rmt_vers;
+ u_long rmt_port;
+ u_long rmt_proc;
+ struct encap_parms rmt_args;
+};
+
+static bool_t
+xdr_rmtcall_args(
+ register XDR *xdrs,
+ register struct rmtcallargs *cap )
+{
+
+ /* does not get a port number */
+ if (xdr_u_long(xdrs, &(cap->rmt_prog)) &&
+ xdr_u_long(xdrs, &(cap->rmt_vers)) &&
+ xdr_u_long(xdrs, &(cap->rmt_proc))) {
+ return (xdr_encap_parms(xdrs, &(cap->rmt_args)));
+ }
+ return (FALSE);
+}
+
+static bool_t
+xdr_rmtcall_result(
+ register XDR *xdrs,
+ register struct rmtcallargs *cap )
+{
+ if (xdr_u_long(xdrs, &(cap->rmt_port)))
+ return (xdr_encap_parms(xdrs, &(cap->rmt_args)));
+ return (FALSE);
+}
+
+/*
+ * only worries about the struct encap_parms part of struct rmtcallargs.
+ * The arglen must already be set!!
+ */
+static bool_t
+xdr_opaque_parms(
+ XDR *xdrs,
+ void *args,
+ ... )
+{
+ struct rmtcallargs *cap = (struct rmtcallargs *) args;
+
+ return (xdr_opaque(xdrs, cap->rmt_args.args, cap->rmt_args.arglen));
+}
+
+/*
+ * This routine finds and sets the length of incoming opaque paraters
+ * and then calls xdr_opaque_parms.
+ */
+static bool_t
+xdr_len_opaque_parms(
+ XDR *xdrs,
+ void *args,
+ ... )
+{
+ struct rmtcallargs *cap = (struct rmtcallargs *) args;
+ register u_int beginpos, lowpos, highpos, currpos, pos;
+
+ beginpos = lowpos = pos = xdr_getpos(xdrs);
+ highpos = lowpos + ARGSIZE;
+ while ((int)(highpos - lowpos) >= 0) {
+ currpos = (lowpos + highpos) / 2;
+ if (xdr_setpos(xdrs, currpos)) {
+ pos = currpos;
+ lowpos = currpos + 1;
+ } else {
+ highpos = currpos - 1;
+ }
+ }
+ xdr_setpos(xdrs, beginpos);
+ cap->rmt_args.arglen = pos - beginpos;
+ return (xdr_opaque_parms(xdrs, cap));
+}
+
+/*
+ * Call a remote procedure service
+ * This procedure is very quiet when things go wrong.
+ * The proc is written to support broadcast rpc. In the broadcast case,
+ * a machine should shut-up instead of complain, less the requestor be
+ * overrun with complaints at the expense of not hearing a valid reply ...
+ *
+ * This now forks so that the program & process that it calls can call
+ * back to the portmapper.
+ */
+static void
+callit(
+ struct svc_req *rqstp,
+ SVCXPRT *xprt )
+{
+ struct rmtcallargs a;
+ struct pmaplist *pml;
+ u_short port;
+ struct sockaddr_in me;
+ int pid, socket = -1;
+ CLIENT *client;
+ struct authunix_parms *au = (struct authunix_parms *)rqstp->rq_clntcred;
+ struct timeval timeout;
+ char buf[ARGSIZE];
+
+ timeout.tv_sec = 5;
+ timeout.tv_usec = 0;
+ a.rmt_args.args = buf;
+ if (!svc_getargs(xprt, (xdrproc_t) xdr_rmtcall_args, (caddr_t)&a))
+ return;
+ if ((pml = find_service(a.rmt_prog, a.rmt_vers, IPPROTO_UDP)) == NULL)
+ return;
+ /*
+ * fork a child to do the work. Parent immediately returns.
+ * Child exits upon completion.
+ */
+ if ((pid = fork()) != 0) {
+ if (debugging && (pid < 0)) {
+ fprintf(stderr, "portmap CALLIT: cannot fork.\n");
+ }
+ return;
+ }
+ port = pml->pml_map.pm_port;
+ get_myaddress(&me);
+ me.sin_port = htons(port);
+ client = clntudp_create(&me, a.rmt_prog, a.rmt_vers, timeout, &socket);
+ if (client != (CLIENT *)NULL) {
+ if (rqstp->rq_cred.oa_flavor == AUTH_UNIX) {
+ client->cl_auth = authunix_create(au->aup_machname,
+ au->aup_uid, au->aup_gid, au->aup_len, au->aup_gids);
+ }
+ a.rmt_port = (u_long)port;
+ if (clnt_call(client, a.rmt_proc, xdr_opaque_parms, &a,
+ xdr_len_opaque_parms, &a, timeout) == RPC_SUCCESS) {
+ svc_sendreply(xprt, (xdrproc_t) xdr_rmtcall_result, (caddr_t)&a);
+ }
+ AUTH_DESTROY(client->cl_auth);
+ clnt_destroy(client);
+ }
+ (void)close(socket);
+ exit(0);
+}
+
+/*
+ * Start the RPC portmapper
+ */
+int rtems_rpc_start_portmapper (int priority)
+{
+ rtems_mode mode;
+ rtems_status_code sc;
+ rtems_id tid;
+ static int started;
+
+ rtems_task_mode (RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &mode);
+ if (started) {
+ rtems_task_mode (mode, RTEMS_PREEMPT_MASK, &mode);
+ return RTEMS_SUCCESSFUL;
+ }
+ sc = rtems_task_create (rtems_build_name('P', 'M', 'A', 'P'),
+ priority,
+ ARGSIZE + 8000,
+ RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
+ &tid);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_task_mode (mode, RTEMS_PREEMPT_MASK, &mode);
+ return sc;
+ }
+ sc = rtems_task_start (tid, rtems_portmapper, 0);
+ if (sc != RTEMS_SUCCESSFUL) {
+ rtems_task_mode (mode, RTEMS_PREEMPT_MASK, &mode);
+ return sc;
+ }
+ started = 1;
+ rtems_task_mode (mode, RTEMS_PREEMPT_MASK, &mode);
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/librpc/src/rpc/rtems_rpc.c b/cpukit/librpc/src/rpc/rtems_rpc.c
new file mode 100644
index 0000000000..1a8f861e88
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rtems_rpc.c
@@ -0,0 +1,97 @@
+/*
+ * RTEMS multi-tasking support
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <rtems.h>
+#include <stdlib.h>
+
+/*
+ * RPC variables for single-thread
+ */
+static struct _rtems_rpc_task_variables rpc_default = {
+ -1, /* svc_maxfd */
+ {{0}}, /* svc_svc_fdset */
+ NULL, /* svc_xports */
+ 0, /* svc_xportssize */
+ 0, /* svc__svc_fdsetsize */
+ 0, /* svc__svc_fdset */
+ NULL, /* svc_svc_head */
+ 0, /* clnt_perror_buf */
+ 0, /* clnt_raw_private */
+ 0, /* call_rpc_private */
+ 0, /* svc_raw_private */
+
+ 0, /* svc_simple_proglst */
+ 0, /* svc_simple_pl */
+ 0, /* svc_simple_transp */
+
+ 0, /* rpcdname_default_domain */
+ 0 /* svc_auths_Auths */
+};
+
+/*
+ * RPC values for initializing a new per-task set of variables
+ */
+static const struct _rtems_rpc_task_variables rpc_init = {
+ -1, /* svc_maxfd */
+ {{0}}, /* svc_svc_fdset */
+ NULL, /* svc_xports */
+ 0, /* svc_xportssize */
+ 0, /* svc__svc_fdsetsize */
+ 0, /* svc__svc_fdset */
+ NULL, /* svc_svc_head */
+ 0, /* clnt_perror_buf */
+ 0, /* clnt_raw_private */
+ 0, /* call_rpc_private */
+ 0, /* svc_raw_private */
+
+ 0, /* svc_simple_proglst */
+ 0, /* svc_simple_pl */
+ 0, /* svc_simple_transp */
+
+ 0, /* rpcdname_default_domain */
+ 0 /* svc_auths_Auths */
+};
+
+/*
+ * Per-task pointer to RPC data
+ */
+struct _rtems_rpc_task_variables *rtems_rpc_task_variables = &rpc_default;
+
+/*
+ * Set up per-task RPC variables
+ */
+int rtems_rpc_task_init (void)
+{
+ rtems_status_code sc;
+ struct _rtems_rpc_task_variables *tvp;
+
+ if (rtems_rpc_task_variables == &rpc_default) {
+ tvp = malloc (sizeof *tvp);
+ if (tvp == NULL)
+ return RTEMS_NO_MEMORY;
+ /*
+ * FIXME: Should have destructor which cleans up
+ * all RPC stuff:
+ * - Close all files
+ * - Go through and free linked list elements
+ * - Free other allocated memory (e.g. clnt_perror_buf)
+ */
+ sc = rtems_task_variable_add (
+ RTEMS_SELF, (void *)&rtems_rpc_task_variables, NULL);
+ if (sc != RTEMS_SUCCESSFUL) {
+ free (tvp);
+ return sc;
+ }
+ *tvp = rpc_init;
+ rtems_rpc_task_variables = tvp;
+ }
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/librpc/src/rpc/rtime.3 b/cpukit/librpc/src/rpc/rtime.3
new file mode 100644
index 0000000000..ad3e538c43
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rtime.3
@@ -0,0 +1,47 @@
+.\" @(#)rtime.3n 2.1 88/08/08 4.0 RPCSRC; from 1.5 88/02/08 SMI
+.\" $FreeBSD: src/lib/libc/rpc/rtime.3,v 1.4 2000/03/02 09:13:48 sheldonh Exp $
+.\"
+.TH RTIME 3 "22 November 1987"
+.SH NAME
+rtime \- get remote time
+.SH SYNOPSIS
+.nf
+.B #include <sys/types.h>
+.B #include <sys/time.h>
+.B #include <netinet/in.h>
+.LP
+.B int rtime(addrp, timep, timeout)
+.B struct sockaddr_in \(**addrp;
+.B struct timeval \(**timep;
+.B struct timeval \(**timeout;
+.fi
+.SH DESCRIPTION
+.B rtime(\|)
+consults the Internet Time Server at the address pointed to by
+.I addrp
+and returns the remote time in the
+.B timeval
+struct pointed to by
+.IR timep .
+Normally, the
+.SM UDP
+protocol is used when consulting the Time Server.
+The
+.I timeout
+parameter specifies how long the
+routine should wait before giving
+up when waiting for a reply. If
+.I timeout
+is specified as
+.SM NULL\s0,
+however, the routine will instead use
+.SM TCP
+and block until a reply is received from the time server.
+.LP
+The routine returns 0 if it is successful.
+Otherwise,
+it returns \-1 and
+.B errno
+is set to reflect the cause of the error.
+.SH "SEE ALSO"
+.BR timed (8c)
diff --git a/cpukit/librpc/src/rpc/rtime.c b/cpukit/librpc/src/rpc/rtime.c
new file mode 100644
index 0000000000..af63d5b8e4
--- /dev/null
+++ b/cpukit/librpc/src/rpc/rtime.c
@@ -0,0 +1,163 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+/*
+ * Copyright (c) 1988 by Sun Microsystems, Inc.
+
+ */
+
+/*
+ * rtime - get time from remote machine
+ *
+ * gets time, obtaining value from host
+ * on the udp/time socket. Since timeserver returns
+ * with time of day in seconds since Jan 1, 1900, must
+ * subtract seconds before Jan 1, 1970 to get
+ * what unix uses.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <sys/select.h>
+#include <inttypes.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/* from: static char sccsid[] = "@(#)rtime.c 2.2 88/08/10 4.0 RPCSRC; from 1.8 88/02/08 SMI"; */
+static const char rcsid[] = "$FreeBSD: src/lib/libc/rpc/rtime.c,v 1.5 2000/01/27 23:06:41 jasone Exp $";
+#endif
+
+extern int _rpc_dtablesize( void );
+
+#define NYEARS (UINT32_C(1970) - UINT32_C(1900))
+#define TOFFSET (UINT32_C(60)*UINT32_C(60)*UINT32_C(24)*(UINT32_C(365)*NYEARS + (NYEARS/UINT32_C(4))))
+
+static void do_close( int );
+
+int
+rtime(
+ struct sockaddr_in *addrp,
+ struct timeval *timep,
+ struct timeval *timeout )
+{
+ int s;
+ fd_set readfds;
+ int res;
+ uint32_t thetime;
+ struct sockaddr_in from;
+ socklen_t fromlen;
+ int type;
+ struct servent *serv;
+
+ if (timeout == NULL) {
+ type = SOCK_STREAM;
+ } else {
+ type = SOCK_DGRAM;
+ }
+ s = socket(AF_INET, type, 0);
+ if (s < 0) {
+ return(-1);
+ }
+ addrp->sin_family = AF_INET;
+
+ /* TCP and UDP port are the same in this case */
+ if ((serv = getservbyname("time", "tcp")) == NULL) {
+ return(-1);
+ }
+
+ addrp->sin_port = serv->s_port;
+
+ if (type == SOCK_DGRAM) {
+ res = sendto(s, (char *)&thetime, sizeof(thetime), 0,
+ (struct sockaddr *)addrp, sizeof(*addrp));
+ if (res < 0) {
+ do_close(s);
+ return(-1);
+ }
+ do {
+ FD_ZERO(&readfds);
+ FD_SET(s, &readfds);
+ res = select(_rpc_dtablesize(), &readfds,
+ (fd_set *)NULL, (fd_set *)NULL, timeout);
+ } while (res < 0 && errno == EINTR);
+ if (res <= 0) {
+ if (res == 0) {
+ errno = ETIMEDOUT;
+ }
+ do_close(s);
+ return(-1);
+ }
+ fromlen = sizeof(from);
+ res = recvfrom(s, (char *)&thetime, sizeof(thetime), 0,
+ (struct sockaddr *)&from, &fromlen);
+ do_close(s);
+ if (res < 0) {
+ return(-1);
+ }
+ } else {
+ if (connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) {
+ do_close(s);
+ return(-1);
+ }
+ res = _RPC_read(s, (char *)&thetime, sizeof(thetime));
+ do_close(s);
+ if (res < 0) {
+ return(-1);
+ }
+ }
+ if (res != sizeof(thetime)) {
+ errno = EIO;
+ return(-1);
+ }
+ thetime = ntohl(thetime);
+ timep->tv_sec = thetime - TOFFSET;
+ timep->tv_usec = 0;
+ return(0);
+}
+
+static void
+do_close(int s)
+{
+ int save;
+
+ save = errno;
+ (void)_RPC_close(s);
+ errno = save;
+}
diff --git a/cpukit/librpc/src/rpc/svc.c b/cpukit/librpc/src/rpc/svc.c
new file mode 100644
index 0000000000..9cc5cf3871
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc.c
@@ -0,0 +1,499 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc.c 2.4 88/08/11 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc.c,v 1.14 1999/08/28 00:00:48 peter Exp $";
+#endif
+
+/*
+ * svc.c, Server-side remote procedure call interface.
+ *
+ * There are two sets of procedures here. The xprt routines are
+ * for handling transport handles. The svc routines handle the
+ * list of service routines.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h> /* for ffs */
+#endif
+#include <stdlib.h>
+#include <sys/errno.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+
+#define xports (rtems_rpc_task_variables->svc_xports)
+#define xportssize (rtems_rpc_task_variables->svc_xportssize)
+
+#define NULL_SVC ((struct svc_callout *)0)
+#define RQCRED_SIZE 400 /* this size is excessive */
+
+#define max(a, b) (a > b ? a : b)
+
+/*
+ * The services list
+ * Each entry represents a set of procedures (an rpc program).
+ * The dispatch routine takes request structs and runs the
+ * apropriate procedure.
+ */
+struct svc_callout {
+ struct svc_callout *sc_next;
+ u_long sc_prog;
+ u_long sc_vers;
+ void (*sc_dispatch)(struct svc_req *r, SVCXPRT *xprt);
+};
+#define svc_head (rtems_rpc_task_variables->svc_svc_head)
+
+static struct svc_callout *svc_find(u_long prog, u_long vers,
+ struct svc_callout **prev);
+
+/* *************** SVCXPRT related stuff **************** */
+
+/*
+ * Activate a transport handle.
+ */
+void
+xprt_register(
+ SVCXPRT *xprt )
+{
+ register int sock = xprt->xp_sock;
+
+ if (sock + 1 > __svc_fdsetsize) {
+ int bytes = sizeof (fd_set);
+ fd_set *fds;
+
+ fds = (fd_set *)malloc(bytes);
+ memset(fds, 0, bytes);
+ if (__svc_fdset) {
+ memcpy(fds, __svc_fdset, bytes);
+ free(__svc_fdset);
+ }
+ __svc_fdset = fds;
+ __svc_fdsetsize = bytes * NBBY;
+ }
+
+ if (sock < FD_SETSIZE)
+ FD_SET(sock, &svc_fdset);
+ FD_SET(sock, __svc_fdset);
+
+ if (xports == NULL || sock + 1 > xportssize) {
+ SVCXPRT **xp;
+ int size = FD_SETSIZE;
+
+ if (sock + 1 > size)
+ size = sock + 1;
+ xp = (SVCXPRT **)mem_alloc(size * sizeof(SVCXPRT *));
+ memset(xp, 0, size * sizeof(SVCXPRT *));
+ if (xports) {
+ memcpy(xp, xports, xportssize * sizeof(SVCXPRT *));
+ free(xports);
+ }
+ xportssize = size;
+ xports = xp;
+ }
+ xports[sock] = xprt;
+ svc_maxfd = max(svc_maxfd, sock);
+}
+
+/*
+ * De-activate a transport handle.
+ */
+void
+xprt_unregister(
+ SVCXPRT *xprt )
+{
+ register int sock = xprt->xp_sock;
+
+ if (xports[sock] == xprt) {
+ xports[sock] = (SVCXPRT *)0;
+ if (sock < FD_SETSIZE)
+ FD_CLR(sock, &svc_fdset);
+ FD_CLR(sock, __svc_fdset);
+ if (sock == svc_maxfd) {
+ for (svc_maxfd--; svc_maxfd >= 0; svc_maxfd--)
+ if (xports[svc_maxfd])
+ break;
+ }
+ /*
+ * XXX could use svc_maxfd as a hint to
+ * decrease the size of __svc_fdset
+ */
+ }
+}
+
+
+/* ********************** CALLOUT list related stuff ************* */
+
+/*
+ * Add a service program to the callout list.
+ * The dispatch routine will be called when a rpc request for this
+ * program number comes in.
+ */
+bool_t
+svc_register(
+ SVCXPRT *xprt,
+ u_long prog,
+ u_long vers,
+ void (*dispatch)(struct svc_req *r, SVCXPRT *xprt),
+ int protocol )
+{
+ struct svc_callout *prev;
+ register struct svc_callout *s;
+
+ if ((s = svc_find(prog, vers, &prev)) != NULL_SVC) {
+ if (s->sc_dispatch == dispatch)
+ goto pmap_it; /* he is registering another xptr */
+ return (FALSE);
+ }
+ s = (struct svc_callout *)mem_alloc(sizeof(struct svc_callout));
+ if (s == (struct svc_callout *)0) {
+ return (FALSE);
+ }
+ s->sc_prog = prog;
+ s->sc_vers = vers;
+ s->sc_dispatch = dispatch;
+ s->sc_next = svc_head;
+ svc_head = s;
+pmap_it:
+ /* now register the information with the local binder service */
+ if (protocol) {
+ return (pmap_set(prog, vers, protocol, xprt->xp_port));
+ }
+ return (TRUE);
+}
+
+/*
+ * Remove a service program from the callout list.
+ */
+void
+svc_unregister(
+ u_long prog,
+ u_long vers )
+{
+ struct svc_callout *prev;
+ register struct svc_callout *s;
+
+ if ((s = svc_find(prog, vers, &prev)) == NULL_SVC)
+ return;
+ if (prev == NULL_SVC) {
+ svc_head = s->sc_next;
+ } else {
+ prev->sc_next = s->sc_next;
+ }
+ s->sc_next = NULL_SVC;
+ mem_free((char *) s, (u_int) sizeof(struct svc_callout));
+ /* now unregister the information with the local binder service */
+ (void)pmap_unset(prog, vers);
+}
+
+/*
+ * Search the callout list for a program number, return the callout
+ * struct.
+ */
+static struct svc_callout *
+svc_find(
+ u_long prog,
+ u_long vers,
+ struct svc_callout **prev )
+{
+ register struct svc_callout *s, *p;
+
+ p = NULL_SVC;
+ for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
+ if ((s->sc_prog == prog) && (s->sc_vers == vers))
+ goto done;
+ p = s;
+ }
+done:
+ *prev = p;
+ return (s);
+}
+
+/* ******************* REPLY GENERATION ROUTINES ************ */
+
+/*
+ * Send a reply to an rpc request
+ */
+bool_t
+svc_sendreply(
+ register SVCXPRT *xprt,
+ xdrproc_t xdr_results,
+ void *xdr_location )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = SUCCESS;
+ rply.acpted_rply.ar_results.where = xdr_location;
+ rply.acpted_rply.ar_results.proc = xdr_results;
+ return (SVC_REPLY(xprt, &rply));
+}
+
+/*
+ * No procedure error reply
+ */
+void
+svcerr_noproc(
+ register SVCXPRT *xprt )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROC_UNAVAIL;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Can't decode args error reply
+ */
+void
+svcerr_decode(
+ register SVCXPRT *xprt )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = GARBAGE_ARGS;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Some system error
+ */
+void
+svcerr_systemerr(
+ register SVCXPRT *xprt )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = SYSTEM_ERR;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Authentication error reply
+ */
+void
+svcerr_auth(
+ SVCXPRT *xprt,
+ enum auth_stat why )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_DENIED;
+ rply.rjcted_rply.rj_stat = AUTH_ERROR;
+ rply.rjcted_rply.rj_why = why;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Auth too weak error reply
+ */
+void
+svcerr_weakauth(
+ SVCXPRT *xprt )
+{
+
+ svcerr_auth(xprt, AUTH_TOOWEAK);
+}
+
+/*
+ * Program unavailable error reply
+ */
+void
+svcerr_noprog(
+ register SVCXPRT *xprt )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROG_UNAVAIL;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Program version mismatch error reply
+ */
+void
+svcerr_progvers(
+ register SVCXPRT *xprt,
+ rpcvers_t low_vers,
+ rpcvers_t high_vers )
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROG_MISMATCH;
+ rply.acpted_rply.ar_vers.low = low_vers;
+ rply.acpted_rply.ar_vers.high = high_vers;
+ SVC_REPLY(xprt, &rply);
+}
+
+/* ******************* SERVER INPUT STUFF ******************* */
+
+/*
+ * Get server side input from some transport.
+ *
+ * Statement of authentication parameters management:
+ * This function owns and manages all authentication parameters, specifically
+ * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
+ * the "cooked" credentials (rqst->rq_clntcred).
+ * However, this function does not know the structure of the cooked
+ * credentials, so it make the following assumptions:
+ * a) the structure is contiguous (no pointers), and
+ * b) the cred structure size does not exceed RQCRED_SIZE bytes.
+ * In all events, all three parameters are freed upon exit from this routine.
+ * The storage is trivially management on the call stack in user land, but
+ * is mallocated in kernel land.
+ */
+
+void
+svc_getreq(
+ int rdfds )
+{
+ fd_set readfds;
+
+ FD_ZERO(&readfds);
+ readfds.fds_bits[0] = rdfds;
+ svc_getreqset(&readfds);
+}
+
+void
+svc_getreqset(
+ fd_set *readfds )
+{
+ svc_getreqset2(readfds, FD_SETSIZE);
+}
+
+void
+svc_getreqset2(
+ fd_set *readfds,
+ int width )
+{
+ enum xprt_stat stat;
+ struct rpc_msg msg;
+ int prog_found;
+ u_long low_vers;
+ u_long high_vers;
+ struct svc_req r;
+ register SVCXPRT *xprt;
+ register int bit;
+ register int sock;
+ register fd_mask mask, *maskp;
+ char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];
+ msg.rm_call.cb_cred.oa_base = cred_area;
+ msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
+ r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]);
+
+
+ maskp = readfds->fds_bits;
+ for (sock = 0; sock < width; sock += NFDBITS) {
+ for (mask = *maskp++; (bit = ffs(mask)); mask ^= (1 << (bit - 1))) {
+ /* sock has input waiting */
+ xprt = xports[sock + bit - 1];
+ if (xprt == NULL)
+ /* But do we control sock? */
+ continue;
+ /* now receive msgs from xprtprt (support batch calls) */
+ do {
+ if (SVC_RECV(xprt, &msg)) {
+
+ /* now find the exported program and call it */
+ register struct svc_callout *s;
+ enum auth_stat why;
+
+ r.rq_xprt = xprt;
+ r.rq_prog = msg.rm_call.cb_prog;
+ r.rq_vers = msg.rm_call.cb_vers;
+ r.rq_proc = msg.rm_call.cb_proc;
+ r.rq_cred = msg.rm_call.cb_cred;
+ /* first authenticate the message */
+ if ((why= _authenticate(&r, &msg)) != AUTH_OK) {
+ svcerr_auth(xprt, why);
+ goto call_done;
+ }
+ /* now match message with a registered service*/
+ prog_found = FALSE;
+ low_vers = (u_long) - 1;
+ high_vers = 0;
+ for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
+ if (s->sc_prog == r.rq_prog) {
+ if (s->sc_vers == r.rq_vers) {
+ (*s->sc_dispatch)(&r, xprt);
+ goto call_done;
+ } /* found correct version */
+ prog_found = TRUE;
+ if (s->sc_vers < low_vers)
+ low_vers = s->sc_vers;
+ if (s->sc_vers > high_vers)
+ high_vers = s->sc_vers;
+ } /* found correct program */
+ }
+ /*
+ * if we got here, the program or version
+ * is not served ...
+ */
+ if (prog_found)
+ svcerr_progvers(xprt,
+ low_vers, high_vers);
+ else
+ svcerr_noprog(xprt);
+ /* Fall through to ... */
+ }
+ call_done:
+ if ((stat = SVC_STAT(xprt)) == XPRT_DIED){
+ SVC_DESTROY(xprt);
+ break;
+ }
+ } while (stat == XPRT_MOREREQS);
+ }
+ }
+}
diff --git a/cpukit/librpc/src/rpc/svc_auth.c b/cpukit/librpc/src/rpc/svc_auth.c
new file mode 100644
index 0000000000..b498a9c0dd
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_auth.c
@@ -0,0 +1,220 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+/*
+ * Copyright (c) 1986-1991 by Sun Microsystems Inc.
+ */
+
+/* #ident "@(#)svc_auth.c 1.16 94/04/24 SMI" */
+
+#if !defined(lint) && defined(SCCSIDS)
+#if 0
+static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro";
+#else
+static const char rcsid[] =
+ "$FreeBSD: src/lib/libc/rpc/svc_auth.c,v 1.7 1999/12/29 05:04:16 peter Exp $";
+#endif
+#endif
+
+/*
+ * svc_auth.c, Server-side rpc authenticator interface.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef _KERNEL
+#include <sys/param.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/clnt.h>
+#include <rpc/rpc_msg.h>
+#include <rpc/svc.h>
+#include <rpc/svc_auth.h>
+#else
+#include <stdlib.h>
+#include <rpc/rpc.h>
+#endif
+#include <sys/types.h>
+
+/*
+ * svcauthsw is the bdevsw of server side authentication.
+ *
+ * Server side authenticators are called from authenticate by
+ * using the client auth struct flavor field to index into svcauthsw.
+ * The server auth flavors must implement a routine that looks
+ * like:
+ *
+ * enum auth_stat
+ * flavorx_auth(rqst, msg)
+ * register struct svc_req *rqst;
+ * register struct rpc_msg *msg;
+ *
+ */
+
+enum auth_stat _svcauth_null(struct svc_req *rqst, struct rpc_msg *msg); /* no authentication */
+enum auth_stat _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg); /* (system) unix style (uid, gids) */
+enum auth_stat _svcauth_short(struct svc_req *rqst, struct rpc_msg *msg); /* short hand unix style */
+enum auth_stat _svcauth_des(struct svc_req *rqst, struct rpc_msg *msg); /* des style */
+
+/* declarations to allow servers to specify new authentication flavors */
+struct authsvc {
+ int flavor;
+ enum auth_stat (*handler)(struct svc_req *rqst, struct rpc_msg *msg);
+ struct authsvc *next;
+};
+#define Auths (rtems_rpc_task_variables->svc_auths_Auths)
+
+/*
+ * The call rpc message, msg has been obtained from the wire. The msg contains
+ * the raw form of credentials and verifiers. authenticate returns AUTH_OK
+ * if the msg is successfully authenticated. If AUTH_OK then the routine also
+ * does the following things:
+ * set rqst->rq_xprt->verf to the appropriate response verifier;
+ * sets rqst->rq_client_cred to the "cooked" form of the credentials.
+ *
+ * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
+ * its length is set appropriately.
+ *
+ * The caller still owns and is responsible for msg->u.cmb.cred and
+ * msg->u.cmb.verf. The authentication system retains ownership of
+ * rqst->rq_client_cred, the cooked credentials.
+ *
+ * There is an assumption that any flavour less than AUTH_NULL is
+ * invalid.
+ */
+enum auth_stat
+_authenticate(
+ struct svc_req *rqst,
+ struct rpc_msg *msg )
+{
+ register int cred_flavor;
+ register struct authsvc *asp;
+
+ rqst->rq_cred = msg->rm_call.cb_cred;
+ rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
+ rqst->rq_xprt->xp_verf.oa_length = 0;
+ cred_flavor = rqst->rq_cred.oa_flavor;
+ switch (cred_flavor) {
+ case AUTH_NULL:
+ return(_svcauth_null(rqst, msg));
+ case AUTH_UNIX:
+ return(_svcauth_unix(rqst, msg));
+ case AUTH_SHORT:
+ return(_svcauth_short(rqst, msg));
+ /*
+ * We leave AUTH_DES turned off by default because svcauth_des()
+ * needs getpublickey(), which is in librpcsvc, not libc. If we
+ * included AUTH_DES as a built-in flavor, programs that don't
+ * have -lrpcsvc in their Makefiles wouldn't link correctly, even
+ * though they don't use AUTH_DES. And I'm too lazy to go through
+ * the tree looking for all of them.
+ */
+#ifdef DES_BUILTIN
+ case AUTH_DES:
+ return(_svcauth_des(rqst, msg));
+#endif
+ }
+
+ /* flavor doesn't match any of the builtin types, so try new ones */
+ for (asp = Auths; asp; asp = asp->next) {
+ if (asp->flavor == cred_flavor) {
+ enum auth_stat as;
+
+ as = (*asp->handler)(rqst, msg);
+ return (as);
+ }
+ }
+
+ return (AUTH_REJECTEDCRED);
+}
+
+/*ARGSUSED*/
+enum auth_stat
+_svcauth_null(
+ struct svc_req *rqst,
+ struct rpc_msg *msg)
+{
+ return (AUTH_OK);
+}
+
+/*
+ * Allow the rpc service to register new authentication types that it is
+ * prepared to handle. When an authentication flavor is registered,
+ * the flavor is checked against already registered values. If not
+ * registered, then a new Auths entry is added on the list.
+ *
+ * There is no provision to delete a registration once registered.
+ *
+ * This routine returns:
+ * 0 if registration successful
+ * 1 if flavor already registered
+ * -1 if can't register (errno set)
+ */
+
+int
+svc_auth_reg(
+ int cred_flavor,
+ enum auth_stat (*handler)(struct svc_req *rqst, struct rpc_msg *msg))
+{
+ register struct authsvc *asp;
+
+ switch (cred_flavor) {
+ case AUTH_NULL:
+ case AUTH_UNIX:
+ case AUTH_SHORT:
+#ifdef DES_BUILTIN
+ case AUTH_DES:
+#endif
+ /* already registered */
+ return (1);
+
+ default:
+ for (asp = Auths; asp; asp = asp->next) {
+ if (asp->flavor == cred_flavor) {
+ /* already registered */
+ return (1);
+ }
+ }
+
+ /* this is a new one, so go ahead and register it */
+ asp = (struct authsvc *)mem_alloc(sizeof (*asp));
+ if (asp == NULL) {
+ return (-1);
+ }
+ asp->flavor = cred_flavor;
+ asp->handler = handler;
+ asp->next = Auths;
+ Auths = asp;
+ break;
+ }
+ return (0);
+}
diff --git a/cpukit/librpc/src/rpc/svc_auth_unix.c b/cpukit/librpc/src/rpc/svc_auth_unix.c
new file mode 100644
index 0000000000..ce395998bd
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_auth_unix.c
@@ -0,0 +1,152 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_auth_unix.c,v 1.8 1999/08/28 00:00:49 peter Exp $";
+#endif
+
+/*
+ * svc_auth_unix.c
+ * Handles UNIX flavor authentication parameters on the service side of rpc.
+ * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
+ * _svcauth_unix does full blown unix style uid,gid+gids auth,
+ * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
+ * Note: the shorthand has been gutted for efficiency.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <rpc/rpc.h>
+
+/*
+ * Unix longhand authenticator
+ */
+enum auth_stat
+_svcauth_unix(
+ struct svc_req *rqst,
+ struct rpc_msg *msg )
+{
+ register enum auth_stat stat;
+ XDR xdrs;
+ register struct authunix_parms *aup;
+ register int32_t *buf;
+ struct area {
+ struct authunix_parms area_aup;
+ char area_machname[MAX_MACHINE_NAME+1];
+ int area_gids[NGRPS];
+ } *area;
+ u_int auth_len;
+ int str_len, gid_len;
+ register int i;
+
+ area = (struct area *) rqst->rq_clntcred;
+ aup = &area->area_aup;
+ aup->aup_machname = area->area_machname;
+ aup->aup_gids = area->area_gids;
+ auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
+ xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
+ buf = XDR_INLINE(&xdrs, auth_len);
+ if (buf != NULL) {
+ aup->aup_time = IXDR_GET_LONG(buf);
+ str_len = IXDR_GET_U_LONG(buf);
+ if (str_len > MAX_MACHINE_NAME) {
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ memcpy(aup->aup_machname, (caddr_t)buf, (u_int)str_len);
+ aup->aup_machname[str_len] = 0;
+ str_len = RNDUP(str_len);
+ buf += str_len / sizeof (int32_t);
+ aup->aup_uid = IXDR_GET_LONG(buf);
+ aup->aup_gid = IXDR_GET_LONG(buf);
+ gid_len = IXDR_GET_U_LONG(buf);
+ if (gid_len > NGRPS) {
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ aup->aup_len = gid_len;
+ for (i = 0; i < gid_len; i++) {
+ aup->aup_gids[i] = IXDR_GET_LONG(buf);
+ }
+ /*
+ * five is the smallest unix credentials structure -
+ * timestamp, hostname len (0), uid, gid, and gids len (0).
+ */
+ if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
+ (void) printf("bad auth_len gid %d str %d auth %d\n",
+ gid_len, str_len, auth_len);
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ } else if (! xdr_authunix_parms(&xdrs, aup)) {
+ xdrs.x_op = XDR_FREE;
+ (void)xdr_authunix_parms(&xdrs, aup);
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+
+ /* get the verifier */
+ if ((u_int)msg->rm_call.cb_verf.oa_length) {
+ rqst->rq_xprt->xp_verf.oa_flavor =
+ msg->rm_call.cb_verf.oa_flavor;
+ rqst->rq_xprt->xp_verf.oa_base =
+ msg->rm_call.cb_verf.oa_base;
+ rqst->rq_xprt->xp_verf.oa_length =
+ msg->rm_call.cb_verf.oa_length;
+ } else {
+ rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
+ rqst->rq_xprt->xp_verf.oa_length = 0;
+ }
+ stat = AUTH_OK;
+done:
+ XDR_DESTROY(&xdrs);
+ return (stat);
+}
+
+
+/*
+ * Shorthand unix authenticator
+ * Looks up longhand in a cache.
+ */
+/*ARGSUSED*/
+enum auth_stat
+_svcauth_short(
+ struct svc_req *rqst,
+ struct rpc_msg *msg )
+{
+ return (AUTH_REJECTEDCRED);
+}
diff --git a/cpukit/librpc/src/rpc/svc_raw.c b/cpukit/librpc/src/rpc/svc_raw.c
new file mode 100644
index 0000000000..4685370e7a
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_raw.c
@@ -0,0 +1,173 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_raw.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_raw.c,v 1.7 1999/08/28 00:00:49 peter Exp $";
+#endif
+
+/*
+ * svc_raw.c, This a toy for simple testing and timing.
+ * Interface to create an rpc client and server in the same UNIX process.
+ * This lets us similate rpc and get rpc (round trip) overhead, without
+ * any interference from the kernal.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <stdlib.h>
+
+/*
+ * This is the "network" that we will be moving data over
+ */
+struct svc_raw_private {
+ char _raw_buf[UDPMSGSIZE];
+ SVCXPRT server;
+ XDR xdr_stream;
+ char verf_body[MAX_AUTH_BYTES];
+};
+#define svcraw_private ((struct svc_raw_private *)(rtems_rpc_task_variables)->svc_raw_private)
+
+static bool_t svcraw_recv(SVCXPRT *xprt, struct rpc_msg *msg);
+static enum xprt_stat svcraw_stat(SVCXPRT *xprt);
+static bool_t svcraw_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr);
+static bool_t svcraw_reply(SVCXPRT *xprt, struct rpc_msg *msg);
+static bool_t svcraw_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr);
+static void svcraw_destroy(SVCXPRT *xprt);
+
+static struct xp_ops server_ops = {
+ svcraw_recv,
+ svcraw_stat,
+ svcraw_getargs,
+ svcraw_reply,
+ svcraw_freeargs,
+ svcraw_destroy
+};
+
+SVCXPRT *
+svcraw_create(void)
+{
+ register struct svc_raw_private *srp = svcraw_private;
+
+ if (srp == 0) {
+ srp = (struct svc_raw_private *)calloc(1, sizeof (*srp));
+ if (srp == 0)
+ return (0);
+ }
+ srp->server.xp_sock = 0;
+ srp->server.xp_port = 0;
+ srp->server.xp_ops = &server_ops;
+ srp->server.xp_verf.oa_base = srp->verf_body;
+ xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+ return (&srp->server);
+}
+
+static enum xprt_stat
+svcraw_stat(SVCXPRT *xprt)
+{
+
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svcraw_recv(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ register struct svc_raw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (0);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ if (! xdr_callmsg(xdrs, msg))
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t
+svcraw_reply(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ register struct svc_raw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (FALSE);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ if (! xdr_replymsg(xdrs, msg))
+ return (FALSE);
+ (void)XDR_GETPOS(xdrs); /* called just for overhead */
+ return (TRUE);
+}
+
+static bool_t
+svcraw_getargs(
+ SVCXPRT *xprt,
+ xdrproc_t xdr_args,
+ caddr_t args_ptr)
+{
+ register struct svc_raw_private *srp = svcraw_private;
+
+ if (srp == 0)
+ return (FALSE);
+ return ((*xdr_args)(&srp->xdr_stream, args_ptr));
+}
+
+static bool_t
+svcraw_freeargs(
+ SVCXPRT *xprt,
+ xdrproc_t xdr_args,
+ caddr_t args_ptr)
+{
+ register struct svc_raw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (FALSE);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static void
+svcraw_destroy(SVCXPRT *xprt)
+{
+}
diff --git a/cpukit/librpc/src/rpc/svc_run.c b/cpukit/librpc/src/rpc/svc_run.c
new file mode 100644
index 0000000000..963aa0d80b
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_run.c
@@ -0,0 +1,89 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_run.c,v 1.10 1999/08/28 00:00:49 peter Exp $";
+#endif
+
+/*
+ * This is the rpc server side idle loop
+ * Wait for input, call server program.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/rpc.h>
+#include <stdio.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/select.h>
+
+void
+svc_run(void)
+{
+ fd_set *fds;
+
+ for (;;) {
+ if (__svc_fdset) {
+ int bytes = sizeof (fd_set);
+ fds = (fd_set *)malloc(bytes);
+ memcpy(fds, __svc_fdset, bytes);
+ } else
+ fds = NULL;
+ switch (select(svc_maxfd + 1, fds, NULL, NULL,
+ (struct timeval *)0)) {
+ case -1:
+ if (errno == EINTR) {
+ if (fds)
+ free(fds);
+ continue;
+ }
+ perror("svc_run: - select failed");
+ if (fds)
+ free(fds);
+ return;
+ case 0:
+ if (fds)
+ free(fds);
+ continue;
+ default:
+ /* if fds == NULL, select() can't return a result */
+ svc_getreqset2(fds, svc_maxfd + 1);
+ free(fds);
+ }
+ }
+}
diff --git a/cpukit/librpc/src/rpc/svc_simple.c b/cpukit/librpc/src/rpc/svc_simple.c
new file mode 100644
index 0000000000..30f213db83
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_simple.c
@@ -0,0 +1,161 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_simple.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_simple.c,v 1.9 1999/08/28 00:00:50 peter Exp $";
+#endif
+
+/*
+ * svc_simple.c
+ * Simplified front end to rpc.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include <inttypes.h> /* for PRIxx printf formats */
+
+struct prog_lst {
+ char *(*p_progname)(char *);
+ rpcprog_t p_prognum;
+ rpcproc_t p_procnum;
+ xdrproc_t p_inproc, p_outproc;
+ struct prog_lst *p_nxt;
+};
+static void universal(struct svc_req *, SVCXPRT *);
+#define proglst (rtems_rpc_task_variables->svc_simple_proglst)
+#define pl (rtems_rpc_task_variables->svc_simple_pl)
+#define transp (rtems_rpc_task_variables->svc_simple_transp)
+
+int
+registerrpc(
+ int prognum,
+ int versnum,
+ int procnum,
+ char *(*progname)(char *),
+ xdrproc_t inproc,
+ xdrproc_t outproc )
+{
+
+ if (procnum == NULLPROC) {
+ (void) fprintf(stderr,
+ "can't reassign procedure number %" PRIu32 "\n", NULLPROC);
+ return (-1);
+ }
+ if (transp == 0) {
+ transp = svcudp_create(RPC_ANYSOCK);
+ if (transp == NULL) {
+ (void) fprintf(stderr, "couldn't create an rpc server\n");
+ return (-1);
+ }
+ }
+ (void) pmap_unset((u_long)prognum, (u_long)versnum);
+ if (!svc_register(transp, (u_long)prognum, (u_long)versnum,
+ universal, IPPROTO_UDP)) {
+ (void) fprintf(stderr, "couldn't register prog %d vers %d\n",
+ prognum, versnum);
+ return (-1);
+ }
+ pl = (struct prog_lst *)malloc(sizeof(struct prog_lst));
+ if (pl == NULL) {
+ (void) fprintf(stderr, "registerrpc: out of memory\n");
+ return (-1);
+ }
+ pl->p_progname = progname;
+ pl->p_prognum = prognum;
+ pl->p_procnum = procnum;
+ pl->p_inproc = inproc;
+ pl->p_outproc = outproc;
+ pl->p_nxt = proglst;
+ proglst = pl;
+ return (0);
+}
+
+static void
+universal(
+ struct svc_req *rqstp,
+ SVCXPRT *atransp )
+{
+ int prog, proc;
+ char *outdata;
+ char xdrbuf[UDPMSGSIZE];
+ struct prog_lst *lpl;
+
+ /*
+ * enforce "procnum 0 is echo" convention
+ */
+ if (rqstp->rq_proc == NULLPROC) {
+ if (svc_sendreply(atransp, (xdrproc_t) xdr_void, NULL) == FALSE) {
+ (void) fprintf(stderr, "xxx\n");
+ exit(1);
+ }
+ return;
+ }
+ prog = rqstp->rq_prog;
+ proc = rqstp->rq_proc;
+ for (lpl = proglst; lpl != NULL; lpl = lpl->p_nxt)
+ if (lpl->p_prognum == prog && lpl->p_procnum == proc) {
+ /* decode arguments into a CLEAN buffer */
+ memset(xdrbuf, 0, sizeof(xdrbuf)); /* required ! */
+ if (!svc_getargs(atransp, lpl->p_inproc, xdrbuf)) {
+ svcerr_decode(atransp);
+ return;
+ }
+ outdata = (*(lpl->p_progname))(xdrbuf);
+ if (outdata == NULL &&
+ lpl->p_outproc != (xdrproc_t) xdr_void)
+ /* there was an error */
+ return;
+ if (!svc_sendreply(atransp, lpl->p_outproc, outdata)) {
+ (void) fprintf(stderr,
+ "trouble replying to prog %" PRIu32 "\n",
+ lpl->p_prognum);
+ exit(1);
+ }
+ /* free the decoded arguments */
+ (void)svc_freeargs(atransp, lpl->p_inproc, xdrbuf);
+ return;
+ }
+ (void) fprintf(stderr, "never registered prog %d\n", prog);
+ exit(1);
+}
diff --git a/cpukit/librpc/src/rpc/svc_tcp.c b/cpukit/librpc/src/rpc/svc_tcp.c
new file mode 100644
index 0000000000..0f87080b74
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_tcp.c
@@ -0,0 +1,489 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_tcp.c,v 1.18 2000/01/27 23:06:41 jasone Exp $";
+#endif
+
+/*
+ * svc_tcp.c, Server side for TCP/IP based RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Actually implements two flavors of transporter -
+ * a tcp rendezvouser (a listner and connection establisher)
+ * and a record/tcp stream.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <sys/select.h>
+
+/*
+ * Ops vector for TCP/IP based rpc service handle
+ */
+static bool_t svctcp_recv(SVCXPRT *xprt, struct rpc_msg *msg);
+static enum xprt_stat svctcp_stat(SVCXPRT *xprt);
+static bool_t svctcp_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr);
+static bool_t svctcp_reply(SVCXPRT *xprt, struct rpc_msg *msg);
+static bool_t svctcp_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr);
+static void svctcp_destroy(SVCXPRT *xprt);
+
+static struct xp_ops svctcp_op = {
+ svctcp_recv,
+ svctcp_stat,
+ svctcp_getargs,
+ svctcp_reply,
+ svctcp_freeargs,
+ svctcp_destroy
+};
+
+/*
+ * Ops vector for TCP/IP rendezvous handler
+ */
+static bool_t rendezvous_request(SVCXPRT *xprt, struct rpc_msg *msg);
+static enum xprt_stat rendezvous_stat(SVCXPRT *xprt);
+
+static struct xp_ops svctcp_rendezvous_op = {
+ rendezvous_request,
+ rendezvous_stat,
+ (bool_t (*)(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr))abort,
+ (bool_t (*)(SVCXPRT *xprt, struct rpc_msg *msg))abort,
+ (bool_t (*)(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr))abort,
+ svctcp_destroy
+};
+
+static int readtcp(char *, char*, int), writetcp(char *, char*, int);
+static SVCXPRT *makefd_xprt( int fd, u_int sendsize, u_int recvsize);
+
+struct tcp_rendezvous { /* kept in xprt->xp_p1 */
+ u_int sendsize;
+ u_int recvsize;
+};
+
+struct tcp_conn { /* kept in xprt->xp_p1 */
+ enum xprt_stat strm_stat;
+ u_long x_id;
+ XDR xdrs;
+ char verf_body[MAX_AUTH_BYTES];
+};
+
+/*
+ * Usage:
+ * xprt = svctcp_create(sock, send_buf_size, recv_buf_size);
+ *
+ * Creates, registers, and returns a (rpc) tcp based transporter.
+ * Once *xprt is initialized, it is registered as a transporter
+ * see (svc.h, xprt_register). This routine returns
+ * a NULL if a problem occurred.
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svctcp_create
+ * binds it to an arbitrary port. The routine then starts a tcp
+ * listener on the socket's associated port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ *
+ * Since tcp streams do buffered io similar to stdio, the caller can specify
+ * how big the send and receive buffers are via the second and third parms;
+ * 0 => use the system default.
+ */
+SVCXPRT *
+svctcp_create(
+ int sock,
+ u_int sendsize,
+ u_int recvsize)
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct tcp_rendezvous *r;
+ struct sockaddr_in addr;
+ socklen_t len = sizeof(struct sockaddr_in);
+ int on;
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("svctcp_.c - udp socket creation problem");
+ return ((SVCXPRT *)NULL);
+ }
+ madesock = TRUE;
+ }
+ on = 1;
+ if (ioctl(sock, FIONBIO, &on) < 0) {
+ perror("svc_tcp.c - cannot turn on non-blocking mode");
+ if (madesock)
+ (void)_RPC_close(sock);
+ return ((SVCXPRT *)NULL);
+ }
+ memset(&addr, 0, sizeof (addr));
+ addr.sin_len = sizeof(struct sockaddr_in);
+ addr.sin_family = AF_INET;
+ if (bindresvport(sock, &addr)) {
+ addr.sin_port = 0;
+ (void)bind(sock, (struct sockaddr *)&addr, len);
+ }
+ if ((getsockname(sock, (struct sockaddr *)&addr, &len) != 0) ||
+ (listen(sock, 2) != 0)) {
+ perror("svctcp_.c - cannot getsockname or listen");
+ if (madesock)
+ (void)_RPC_close(sock);
+ return ((SVCXPRT *)NULL);
+ }
+ r = (struct tcp_rendezvous *)mem_alloc(sizeof(*r));
+ if (r == NULL) {
+ (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ return (NULL);
+ }
+ r->sendsize = sendsize;
+ r->recvsize = recvsize;
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ return (NULL);
+ }
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t)r;
+ xprt->xp_verf = _null_auth;
+ xprt->xp_ops = &svctcp_rendezvous_op;
+ xprt->xp_port = ntohs(addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+/*
+ * Like svtcp_create(), except the routine takes any *open* UNIX file
+ * descriptor as its first input.
+ */
+SVCXPRT *
+svcfd_create(
+ int fd,
+ u_int sendsize,
+ u_int recvsize)
+{
+
+ return (makefd_xprt(fd, sendsize, recvsize));
+}
+
+static SVCXPRT *
+makefd_xprt(
+ int fd,
+ u_int sendsize,
+ u_int recvsize)
+{
+ register SVCXPRT *xprt;
+ register struct tcp_conn *cd;
+
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == (SVCXPRT *)NULL) {
+ (void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
+ goto done;
+ }
+ cd = (struct tcp_conn *)mem_alloc(sizeof(struct tcp_conn));
+ if (cd == (struct tcp_conn *)NULL) {
+ (void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
+ mem_free((char *) xprt, sizeof(SVCXPRT));
+ xprt = (SVCXPRT *)NULL;
+ goto done;
+ }
+ cd->strm_stat = XPRT_IDLE;
+ xdrrec_create(&(cd->xdrs), sendsize, recvsize,
+ (caddr_t)xprt, readtcp, writetcp);
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t)cd;
+ xprt->xp_verf.oa_base = cd->verf_body;
+ xprt->xp_addrlen = 0;
+ xprt->xp_ops = &svctcp_op; /* truely deals with calls */
+ xprt->xp_port = 0; /* this is a connection, not a rendezvouser */
+ xprt->xp_sock = fd;
+ xprt_register(xprt);
+ done:
+ return (xprt);
+}
+
+static bool_t
+rendezvous_request(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ int sock;
+ struct tcp_rendezvous *r;
+ struct sockaddr_in addr;
+ socklen_t len;
+ int off;
+
+ r = (struct tcp_rendezvous *)xprt->xp_p1;
+ again:
+ len = sizeof(struct sockaddr_in);
+ if ((sock = accept(xprt->xp_sock, (struct sockaddr *)&addr,
+ &len)) < 0) {
+ if (errno == EINTR)
+ goto again;
+ return (FALSE);
+ }
+ /*
+ * Guard against FTP bounce attacks.
+ */
+ if (addr.sin_port == htons(20)) {
+ _RPC_close(sock);
+ return (FALSE);
+ }
+ /*
+ * The listening socket is in FIONBIO mode and we inherit it.
+ */
+ off = 0;
+ if (ioctl(sock, FIONBIO, &off) < 0) {
+ _RPC_close(sock);
+ return (FALSE);
+ }
+ /*
+ * make a new transporter (re-uses xprt)
+ */
+ xprt = makefd_xprt(sock, r->sendsize, r->recvsize);
+ xprt->xp_raddr = addr;
+ xprt->xp_addrlen = len;
+ return (FALSE); /* there is never an rpc msg to be processed */
+}
+
+static enum xprt_stat
+rendezvous_stat(SVCXPRT *xprt)
+{
+
+ return (XPRT_IDLE);
+}
+
+static void
+svctcp_destroy(
+ SVCXPRT *xprt)
+{
+ register struct tcp_conn *cd = (struct tcp_conn *)xprt->xp_p1;
+
+ xprt_unregister(xprt);
+ (void)_RPC_close(xprt->xp_sock);
+ if (xprt->xp_port != 0) {
+ /* a rendezvouser socket */
+ xprt->xp_port = 0;
+ } else {
+ /* an actual connection socket */
+ XDR_DESTROY(&(cd->xdrs));
+ }
+ mem_free((caddr_t)cd, sizeof(struct tcp_conn));
+ mem_free((caddr_t)xprt, sizeof(SVCXPRT));
+}
+
+/*
+ * All read operations timeout after 35 seconds.
+ * A timeout is fatal for the connection.
+ */
+static struct timeval wait_per_try = { 35, 0 };
+
+/*
+ * reads data from the tcp conection.
+ * any error is fatal and the connection is closed.
+ * (And a read of zero bytes is a half closed stream => error.)
+ *
+ * Note: we have to be careful here not to allow ourselves to become
+ * blocked too long in this routine. While we're waiting for data from one
+ * client, another client may be trying to connect. To avoid this situation,
+ * some code from svc_run() is transplanted here: the select() loop checks
+ * all RPC descriptors including the one we want and calls svc_getreqset2()
+ * to handle new requests if any are detected.
+ */
+static int
+readtcp(
+ char *_xprt,
+ char *buf,
+ int len)
+{
+ SVCXPRT *xprt = (SVCXPRT*) _xprt;
+ register int sock = xprt->xp_sock;
+ struct timeval start, delta, tv;
+ struct timeval tmp1, tmp2;
+ fd_set *fds;
+
+ delta = wait_per_try;
+ fds = NULL;
+ gettimeofday(&start, NULL);
+ do {
+ int bytes = sizeof (fd_set);
+ if (fds != NULL)
+ free(fds);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL)
+ goto fatal_err;
+ memcpy(fds, __svc_fdset, bytes);
+
+ /* XXX we know the other bits are still clear */
+ FD_SET(sock, fds);
+ tv = delta; /* in case select() implements writeback */
+ switch (select(svc_maxfd + 1, fds, NULL, NULL, &tv)) {
+ case -1:
+ if (errno != EINTR)
+ goto fatal_err;
+ gettimeofday(&tmp1, NULL);
+ timersub(&tmp1, &start, &tmp2);
+ timersub(&wait_per_try, &tmp2, &tmp1);
+ if (tmp1.tv_sec < 0 || !timerisset(&tmp1))
+ goto fatal_err;
+ delta = tmp1;
+ continue;
+ case 0:
+ goto fatal_err;
+ default:
+ if (!FD_ISSET(sock, fds)) {
+ svc_getreqset2(fds, svc_maxfd + 1);
+ gettimeofday(&tmp1, NULL);
+ timersub(&tmp1, &start, &tmp2);
+ timersub(&wait_per_try, &tmp2, &tmp1);
+ if (tmp1.tv_sec < 0 || !timerisset(&tmp1))
+ goto fatal_err;
+ delta = tmp1;
+ continue;
+ }
+ }
+ } while (!FD_ISSET(sock, fds));
+ if ((len = _RPC_read(sock, buf, len)) > 0) {
+ if (fds != NULL)
+ free(fds);
+ return (len);
+ }
+fatal_err:
+ ((struct tcp_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
+ if (fds != NULL)
+ free(fds);
+ return (-1);
+}
+
+/*
+ * writes data to the tcp connection.
+ * Any error is fatal and the connection is closed.
+ */
+static int
+writetcp(
+ char *_xprt,
+ char *buf,
+ int len)
+{
+ SVCXPRT *xprt = (SVCXPRT *) _xprt;
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = _RPC_write(xprt->xp_sock, buf, cnt)) < 0) {
+ ((struct tcp_conn *)(xprt->xp_p1))->strm_stat =
+ XPRT_DIED;
+ return (-1);
+ }
+ }
+ return (len);
+}
+
+static enum xprt_stat
+svctcp_stat(
+ SVCXPRT *xprt)
+{
+ register struct tcp_conn *cd =
+ (struct tcp_conn *)(xprt->xp_p1);
+
+ if (cd->strm_stat == XPRT_DIED)
+ return (XPRT_DIED);
+ if (! xdrrec_eof(&(cd->xdrs)))
+ return (XPRT_MOREREQS);
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svctcp_recv(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ register struct tcp_conn *cd =
+ (struct tcp_conn *)(xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+
+ xdrs->x_op = XDR_DECODE;
+ (void)xdrrec_skiprecord(xdrs);
+ if (xdr_callmsg(xdrs, msg)) {
+ cd->x_id = msg->rm_xid;
+ return (TRUE);
+ }
+ cd->strm_stat = XPRT_DIED; /* XXXX */
+ return (FALSE);
+}
+
+static bool_t
+svctcp_getargs(
+ SVCXPRT *xprt,
+ xdrproc_t xdr_args,
+ caddr_t args_ptr)
+{
+
+ return ((*xdr_args)(&(((struct tcp_conn *)(xprt->xp_p1))->xdrs), args_ptr));
+}
+
+static bool_t
+svctcp_freeargs(
+ SVCXPRT *xprt,
+ xdrproc_t xdr_args,
+ caddr_t args_ptr)
+{
+ register XDR *xdrs =
+ &(((struct tcp_conn *)(xprt->xp_p1))->xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static bool_t
+svctcp_reply(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ register struct tcp_conn *cd =
+ (struct tcp_conn *)(xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+ register bool_t stat;
+
+ xdrs->x_op = XDR_ENCODE;
+ msg->rm_xid = cd->x_id;
+ stat = xdr_replymsg(xdrs, msg);
+ (void)xdrrec_endofrecord(xdrs, TRUE);
+ return (stat);
+}
diff --git a/cpukit/librpc/src/rpc/svc_udp.c b/cpukit/librpc/src/rpc/svc_udp.c
new file mode 100644
index 0000000000..8b7e1677f2
--- /dev/null
+++ b/cpukit/librpc/src/rpc/svc_udp.c
@@ -0,0 +1,484 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_udp.c 2.2 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/rpc/svc_udp.c,v 1.13 2000/01/27 23:06:41 jasone Exp $";
+#endif
+
+/*
+ * svc_udp.c,
+ * Server side for UDP/IP based RPC. (Does some caching in the hopes of
+ * achieving execute-at-most-once semantics.)
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#define rpc_buffer(xprt) ((xprt)->xp_p1)
+#define MAX(a, b) ((a > b) ? a : b)
+
+static bool_t svcudp_recv(SVCXPRT *xprt, struct rpc_msg *msg);
+static bool_t svcudp_reply(SVCXPRT *xprt, struct rpc_msg *msg);
+static enum xprt_stat svcudp_stat(SVCXPRT *xprt);
+static bool_t svcudp_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr);
+static bool_t svcudp_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr);
+static void svcudp_destroy(SVCXPRT *xprt);
+static void cache_set (SVCXPRT *, u_long);
+static int cache_get (SVCXPRT *, struct rpc_msg *, char **, u_long *);
+
+static struct xp_ops svcudp_op = {
+ svcudp_recv,
+ svcudp_stat,
+ svcudp_getargs,
+ svcudp_reply,
+ svcudp_freeargs,
+ svcudp_destroy
+};
+
+/*
+ * kept in xprt->xp_p2
+ */
+struct svcudp_data {
+ u_int su_iosz; /* byte size of send.recv buffer */
+ u_long su_xid; /* transaction id */
+ XDR su_xdrs; /* XDR handle */
+ char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
+ char * su_cache; /* cached data, NULL if no cache */
+};
+#define su_data(xprt) ((struct svcudp_data *)(xprt->xp_p2))
+
+/*
+ * Usage:
+ * xprt = svcudp_create(sock);
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svcudp_create
+ * binds it to an arbitrary port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ * Once *xprt is initialized, it is registered as a transporter;
+ * see (svc.h, xprt_register).
+ * The routines returns NULL if a problem occurred.
+ */
+SVCXPRT *
+svcudp_bufcreate(
+ int sock,
+ u_int sendsz,
+ u_int recvsz )
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct svcudp_data *su;
+ struct sockaddr_in addr;
+ socklen_t len = sizeof(struct sockaddr_in);
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("svcudp_create: socket creation problem");
+ return ((SVCXPRT *)NULL);
+ }
+ madesock = TRUE;
+ }
+ memset((char *)&addr, 0, sizeof (addr));
+ addr.sin_len = sizeof(struct sockaddr_in);
+ addr.sin_family = AF_INET;
+ if (bindresvport(sock, &addr)) {
+ addr.sin_port = 0;
+ (void)bind(sock, (struct sockaddr *)&addr, len);
+ }
+ if (getsockname(sock, (struct sockaddr *)&addr, &len) != 0) {
+ perror("svcudp_create - cannot getsockname");
+ if (madesock)
+ (void)_RPC_close(sock);
+ return ((SVCXPRT *)NULL);
+ }
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void)fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ su = (struct svcudp_data *)mem_alloc(sizeof(*su));
+ if (su == NULL) {
+ (void)fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ su->su_iosz = ((MAX(sendsz, recvsz) + 3) / 4) * 4;
+ if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL) {
+ (void)fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ xdrmem_create(
+ &(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, XDR_DECODE);
+ su->su_cache = NULL;
+ xprt->xp_p2 = (caddr_t)su;
+ xprt->xp_verf.oa_base = su->su_verfbody;
+ xprt->xp_ops = &svcudp_op;
+ xprt->xp_port = ntohs(addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+SVCXPRT *
+svcudp_create(
+ int sock)
+{
+
+ return(svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE));
+}
+
+static enum xprt_stat
+svcudp_stat(
+ SVCXPRT *xprt)
+{
+
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svcudp_recv(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ register struct svcudp_data *su = su_data(xprt);
+ register XDR *xdrs = &(su->su_xdrs);
+ register int rlen;
+ char *reply;
+ u_long replylen;
+
+ again:
+ xprt->xp_addrlen = sizeof(struct sockaddr_in);
+ rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
+ 0, (struct sockaddr *)&(xprt->xp_raddr), &(xprt->xp_addrlen));
+ if (rlen == -1 && errno == EINTR)
+ goto again;
+ if (rlen == -1 || rlen < 4*sizeof(u_int32_t))
+ return (FALSE);
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ if (! xdr_callmsg(xdrs, msg))
+ return (FALSE);
+ su->su_xid = msg->rm_xid;
+ if (su->su_cache != NULL) {
+ if (cache_get(xprt, msg, &reply, &replylen)) {
+ (void) sendto(xprt->xp_sock, reply, (int) replylen, 0,
+ (struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen);
+ return (TRUE);
+ }
+ }
+ return (TRUE);
+}
+
+static bool_t
+svcudp_reply(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg)
+{
+ register struct svcudp_data *su = su_data(xprt);
+ register XDR *xdrs = &(su->su_xdrs);
+ register int slen;
+ register bool_t stat = FALSE;
+
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ msg->rm_xid = su->su_xid;
+ if (xdr_replymsg(xdrs, msg)) {
+ slen = (int)XDR_GETPOS(xdrs);
+ if (sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0,
+ (struct sockaddr *)&(xprt->xp_raddr), xprt->xp_addrlen)
+ == slen) {
+ stat = TRUE;
+ if (su->su_cache && slen >= 0) {
+ cache_set(xprt, (u_long) slen);
+ }
+ }
+ }
+ return (stat);
+}
+
+static bool_t
+svcudp_getargs(
+ SVCXPRT *xprt,
+ xdrproc_t xdr_args,
+ caddr_t args_ptr)
+{
+
+ return ((*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr));
+}
+
+static bool_t
+svcudp_freeargs(
+ SVCXPRT *xprt,
+ xdrproc_t xdr_args,
+ caddr_t args_ptr)
+{
+ register XDR *xdrs = &(su_data(xprt)->su_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static void
+svcudp_destroy(
+ SVCXPRT *xprt)
+{
+ register struct svcudp_data *su = su_data(xprt);
+
+ xprt_unregister(xprt);
+ (void)_RPC_close(xprt->xp_sock);
+ XDR_DESTROY(&(su->su_xdrs));
+ mem_free(rpc_buffer(xprt), su->su_iosz);
+ mem_free((caddr_t)su, sizeof(struct svcudp_data));
+ mem_free((caddr_t)xprt, sizeof(SVCXPRT));
+}
+
+
+/***********this could be a separate file*********************/
+
+/*
+ * Fifo cache for udp server
+ * Copies pointers to reply buffers into fifo cache
+ * Buffers are sent again if retransmissions are detected.
+ */
+
+#define SPARSENESS 4 /* 75% sparse */
+
+#define CACHE_PERROR(msg) \
+ (void) fprintf(stderr,"%s\n", msg)
+
+#define ALLOC(type, size) \
+ (type *) mem_alloc((unsigned) (sizeof(type) * (size)))
+
+#define BZERO(addr, type, size) \
+ memset((char *) addr, 0, sizeof(type) * (int) (size))
+
+/*
+ * An entry in the cache
+ */
+typedef struct cache_node *cache_ptr;
+struct cache_node {
+ /*
+ * Index into cache is xid, proc, vers, prog and address
+ */
+ u_long cache_xid;
+ u_long cache_proc;
+ u_long cache_vers;
+ u_long cache_prog;
+ struct sockaddr_in cache_addr;
+ /*
+ * The cached reply and length
+ */
+ char * cache_reply;
+ u_long cache_replylen;
+ /*
+ * Next node on the list, if there is a collision
+ */
+ cache_ptr cache_next;
+};
+
+
+
+/*
+ * The entire cache
+ */
+struct udp_cache {
+ u_long uc_size; /* size of cache */
+ cache_ptr *uc_entries; /* hash table of entries in cache */
+ cache_ptr *uc_fifo; /* fifo list of entries in cache */
+ u_long uc_nextvictim; /* points to next victim in fifo list */
+ u_long uc_prog; /* saved program number */
+ u_long uc_vers; /* saved version number */
+ u_long uc_proc; /* saved procedure number */
+ struct sockaddr_in uc_addr; /* saved caller's address */
+};
+
+
+/*
+ * the hashing function
+ */
+#define CACHE_LOC(transp, xid) \
+ (xid % (SPARSENESS*((struct udp_cache *) su_data(transp)->su_cache)->uc_size))
+
+
+/*
+ * Enable use of the cache.
+ * Note: there is no disable.
+ */
+int svcudp_enablecache(
+ SVCXPRT *transp,
+ u_long size)
+{
+ struct svcudp_data *su = su_data(transp);
+ struct udp_cache *uc;
+
+ if (su->su_cache != NULL) {
+ CACHE_PERROR("enablecache: cache already enabled");
+ return(0);
+ }
+ uc = ALLOC(struct udp_cache, 1);
+ if (uc == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache");
+ return(0);
+ }
+ uc->uc_size = size;
+ uc->uc_nextvictim = 0;
+ uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
+ if (uc->uc_entries == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache data");
+ return(0);
+ }
+ BZERO(uc->uc_entries, cache_ptr, size * SPARSENESS);
+ uc->uc_fifo = ALLOC(cache_ptr, size);
+ if (uc->uc_fifo == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache fifo");
+ return(0);
+ }
+ BZERO(uc->uc_fifo, cache_ptr, size);
+ su->su_cache = (char *) uc;
+ return(1);
+}
+
+
+/*
+ * Set an entry in the cache
+ */
+static void
+cache_set(
+ SVCXPRT *xprt,
+ u_long replylen)
+{
+ register cache_ptr victim;
+ register cache_ptr *vicp;
+ register struct svcudp_data *su = su_data(xprt);
+ struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+ u_int loc;
+ char *newbuf;
+
+ /*
+ * Find space for the new entry, either by
+ * reusing an old entry, or by mallocing a new one
+ */
+ victim = uc->uc_fifo[uc->uc_nextvictim];
+ if (victim != NULL) {
+ loc = CACHE_LOC(xprt, victim->cache_xid);
+ for (vicp = &uc->uc_entries[loc];
+ *vicp != NULL && *vicp != victim;
+ vicp = &(*vicp)->cache_next)
+ ;
+ if (*vicp == NULL) {
+ CACHE_PERROR("cache_set: victim not found");
+ return;
+ }
+ *vicp = victim->cache_next; /* remote from cache */
+ newbuf = victim->cache_reply;
+ } else {
+ victim = ALLOC(struct cache_node, 1);
+ if (victim == NULL) {
+ CACHE_PERROR("cache_set: victim alloc failed");
+ return;
+ }
+ newbuf = mem_alloc(su->su_iosz);
+ if (newbuf == NULL) {
+ CACHE_PERROR("cache_set: could not allocate new rpc_buffer");
+ return;
+ }
+ }
+
+ /*
+ * Store it away
+ */
+ victim->cache_replylen = replylen;
+ victim->cache_reply = rpc_buffer(xprt);
+ rpc_buffer(xprt) = newbuf;
+ xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, XDR_ENCODE);
+ victim->cache_xid = su->su_xid;
+ victim->cache_proc = uc->uc_proc;
+ victim->cache_vers = uc->uc_vers;
+ victim->cache_prog = uc->uc_prog;
+ victim->cache_addr = uc->uc_addr;
+ loc = CACHE_LOC(xprt, victim->cache_xid);
+ victim->cache_next = uc->uc_entries[loc];
+ uc->uc_entries[loc] = victim;
+ uc->uc_fifo[uc->uc_nextvictim++] = victim;
+ uc->uc_nextvictim %= uc->uc_size;
+}
+
+/*
+ * Try to get an entry from the cache
+ * return 1 if found, 0 if not found
+ */
+static int
+cache_get(
+ SVCXPRT *xprt,
+ struct rpc_msg *msg,
+ char **replyp,
+ u_long *replylenp)
+{
+ u_int loc;
+ register cache_ptr ent;
+ register struct svcudp_data *su = su_data(xprt);
+ register struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+
+# define EQADDR(a1, a2) (memcmp(&a1, &a2, sizeof(a1)) == 0)
+
+ loc = CACHE_LOC(xprt, su->su_xid);
+ for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
+ if (ent->cache_xid == su->su_xid &&
+ ent->cache_proc == uc->uc_proc &&
+ ent->cache_vers == uc->uc_vers &&
+ ent->cache_prog == uc->uc_prog &&
+ EQADDR(ent->cache_addr, uc->uc_addr)) {
+ *replyp = ent->cache_reply;
+ *replylenp = ent->cache_replylen;
+ return(1);
+ }
+ }
+ /*
+ * Failed to find entry
+ * Remember a few things so we can do a set later
+ */
+ uc->uc_proc = msg->rm_call.cb_proc;
+ uc->uc_vers = msg->rm_call.cb_vers;
+ uc->uc_prog = msg->rm_call.cb_prog;
+ uc->uc_addr = xprt->xp_raddr;
+ return(0);
+}
diff --git a/cpukit/librpc/src/xdr/xdr.3 b/cpukit/librpc/src/xdr/xdr.3
new file mode 100644
index 0000000000..c1cdb11015
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr.3
@@ -0,0 +1,837 @@
+.\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
+.\" $FreeBSD: src/lib/libc/xdr/xdr.3,v 1.8 2000/03/02 09:14:05 sheldonh Exp $
+.\"
+.TH XDR 3 "16 February 1988"
+.SH NAME
+xdr \- library routines for external data representation
+.SH SYNOPSIS AND DESCRIPTION
+.LP
+These routines allow C programmers to describe
+arbitrary data structures in a machine-independent fashion.
+Data for remote procedure calls are transmitted using these
+routines.
+.LP
+.ft B
+.nf
+.sp .5
+xdr_array(xdrs, arrp, sizep, maxsize, elsize, elproc)
+\s-1XDR\s0 *xdrs;
+char **arrp;
+u_int *sizep, maxsize, elsize;
+xdrproc_t elproc;
+.fi
+.ft R
+.IP
+A filter primitive that translates between variable-length
+arrays
+and their corresponding external representations.
+The
+parameter
+.I arrp
+is the address of the pointer to the array, while
+.I sizep
+is the address of the element count of the array;
+this element count cannot exceed
+.IR maxsize .
+The parameter
+.I elsize
+is the
+.I sizeof
+each of the array's elements, and
+.I elproc
+is an
+.SM XDR
+filter that translates between
+the array elements' C form, and their external
+representation.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_bool(xdrs, bp)
+\s-1XDR\s0 *xdrs;
+bool_t *bp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between booleans (C
+integers)
+and their external representations.
+When encoding data, this
+filter produces values of either one or zero.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_bytes(xdrs, sp, sizep, maxsize)
+\s-1XDR\s0 *xdrs;
+char **sp;
+u_int *sizep, maxsize;
+.fi
+.ft R
+.IP
+A filter primitive that translates between counted byte
+strings and their external representations.
+The parameter
+.I sp
+is the address of the string pointer.
+The length of the
+string is located at address
+.IR sizep ;
+strings cannot be longer than
+.IR maxsize .
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_char(xdrs, cp)
+\s-1XDR\s0 *xdrs;
+char *cp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C characters
+and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+Note: encoded characters are not packed, and occupy 4 bytes
+each.
+For arrays of characters, it is worthwhile to
+consider
+.BR xdr_bytes(\|) ,
+.B xdr_opaque(\|)
+or
+.BR xdr_string(\|) .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdr_destroy(xdrs)
+\s-1XDR\s0 *xdrs;
+.fi
+.ft R
+.IP
+A macro that invokes the destroy routine associated with the
+.SM XDR
+stream,
+.IR xdrs .
+Destruction usually involves freeing private data structures
+associated with the stream. Using
+.I xdrs
+after invoking
+.B xdr_destroy(\|)
+is undefined.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_double(xdrs, dp)
+\s-1XDR\s0 *xdrs;
+double *dp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B double
+precision numbers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_enum(xdrs, ep)
+\s-1XDR\s0 *xdrs;
+enum_t *ep;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.BR enum s
+(actually integers) and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_float(xdrs, fp)
+\s-1XDR\s0 *xdrs;
+float *fp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.BR float s
+and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdr_free(proc, objp)
+xdrproc_t proc;
+char *objp;
+.fi
+.ft R
+.IP
+Generic freeing routine.
+The first argument is the
+.SM XDR
+routine for the object being freed.
+The second argument
+is a pointer to the object itself.
+Note: the pointer passed
+to this routine is
+.I not
+freed, but what it points to
+.I is
+freed (recursively).
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+u_int
+xdr_getpos(xdrs)
+\s-1XDR\s0 *xdrs;
+.fi
+.ft R
+.IP
+A macro that invokes the get-position routine
+associated with the
+.SM XDR
+stream,
+.IR xdrs .
+The routine returns an unsigned integer,
+which indicates the position of the
+.SM XDR
+byte stream.
+A desirable feature of
+.SM XDR
+streams is that simple arithmetic works with this number,
+although the
+.SM XDR
+stream instances need not guarantee this.
+.br
+.if t .ne 4
+.LP
+.ft B
+.nf
+.sp .5
+.br
+long *
+xdr_inline(xdrs, len)
+\s-1XDR\s0 *xdrs;
+int len;
+.fi
+.ft R
+.IP
+A macro that invokes the in-line routine associated with the
+.SM XDR
+stream,
+.IR xdrs .
+The routine returns a pointer
+to a contiguous piece of the stream's buffer;
+.I len
+is the byte length of the desired buffer.
+Note: pointer is cast to
+.BR "long *" .
+.IP
+Warning:
+.B xdr_inline(\|)
+may return
+.SM NULL
+(0)
+if it cannot allocate a contiguous piece of a buffer.
+Therefore the behavior may vary among stream instances;
+it exists for the sake of efficiency.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_int(xdrs, ip)
+\s-1XDR\s0 *xdrs;
+int *ip;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C integers
+and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_long(xdrs, lp)
+\s-1XDR\s0 *xdrs;
+long *lp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B long
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 12
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdrmem_create(xdrs, addr, size, op)
+\s-1XDR\s0 *xdrs;
+char *addr;
+u_int size;
+enum xdr_op op;
+.fi
+.ft R
+.IP
+This routine initializes the
+.SM XDR
+stream object pointed to by
+.IR xdrs .
+The stream's data is written to, or read from,
+a chunk of memory at location
+.I addr
+whose length is no more than
+.I size
+bytes long. The
+.I op
+determines the direction of the
+.SM XDR
+stream
+(either
+.BR \s-1XDR_ENCODE\s0 ,
+.BR \s-1XDR_DECODE\s0 ,
+or
+.BR \s-1XDR_FREE\s0 ).
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_opaque(xdrs, cp, cnt)
+\s-1XDR\s0 *xdrs;
+char *cp;
+u_int cnt;
+.fi
+.ft R
+.IP
+A filter primitive that translates between fixed size opaque
+data
+and its external representation.
+The parameter
+.I cp
+is the address of the opaque object, and
+.I cnt
+is its size in bytes.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_pointer(xdrs, objpp, objsize, xdrobj)
+\s-1XDR\s0 *xdrs;
+char **objpp;
+u_int objsize;
+xdrproc_t xdrobj;
+.fi
+.ft R
+.IP
+Like
+.B xdr_reference(\|)
+execpt that it serializes
+.SM NULL
+pointers, whereas
+.B xdr_reference(\|)
+does not. Thus,
+.B xdr_pointer(\|)
+can represent
+recursive data structures, such as binary trees or
+linked lists.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdrrec_create(xdrs, sendsize, recvsize, handle, readit, writeit)
+\s-1XDR\s0 *xdrs;
+u_int sendsize, recvsize;
+char *handle;
+int (*readit) (\|), (*writeit) (\|);
+.fi
+.ft R
+.IP
+This routine initializes the
+.SM XDR
+stream object pointed to by
+.IR xdrs .
+The stream's data is written to a buffer of size
+.IR sendsize ;
+a value of zero indicates the system should use a suitable
+default.
+The stream's data is read from a buffer of size
+.IR recvsize ;
+it too can be set to a suitable default by passing a zero
+value.
+When a stream's output buffer is full,
+.I writeit
+is called. Similarly, when a stream's input buffer is empty,
+.I readit
+is called. The behavior of these two routines is similar to
+the
+system calls
+.B read
+and
+.BR write ,
+except that
+.I handle
+is passed to the former routines as the first parameter.
+Note: the
+.SM XDR
+stream's
+.I op
+field must be set by the caller.
+.IP
+Warning: this
+.SM XDR
+stream implements an intermediate record stream.
+Therefore there are additional bytes in the stream
+to provide record boundary information.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+xdrrec_endofrecord(xdrs, sendnow)
+\s-1XDR\s0 *xdrs;
+int sendnow;
+.fi
+.ft R
+.IP
+This routine can be invoked only on
+streams created by
+.BR xdrrec_create(\|) .
+The data in the output buffer is marked as a completed
+record,
+and the output buffer is optionally written out if
+.I sendnow
+is non-zero.
+This routine returns one if it succeeds, zero
+otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdrrec_eof(xdrs)
+\s-1XDR\s0 *xdrs;
+int empty;
+.fi
+.ft R
+.IP
+This routine can be invoked only on
+streams created by
+.BR xdrrec_create(\|) .
+After consuming the rest of the current record in the stream,
+this routine returns one if the stream has no more input,
+zero otherwise.
+.br
+.if t .ne 3
+.LP
+.ft B
+.nf
+.sp .5
+xdrrec_skiprecord(xdrs)
+\s-1XDR\s0 *xdrs;
+.fi
+.ft R
+.IP
+This routine can be invoked only on
+streams created by
+.BR xdrrec_create(\|) .
+It tells the
+.SM XDR
+implementation that the rest of the current record
+in the stream's input buffer should be discarded.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+xdr_reference(xdrs, pp, size, proc)
+\s-1XDR\s0 *xdrs;
+char **pp;
+u_int size;
+xdrproc_t proc;
+.fi
+.ft R
+.IP
+A primitive that provides pointer chasing within structures.
+The parameter
+.I pp
+is the address of the pointer;
+.I size
+is the
+.I sizeof
+the structure that
+.I *pp
+points to; and
+.I proc
+is an
+.SM XDR
+procedure that filters the structure
+between its C form and its external representation.
+This routine returns one if it succeeds, zero otherwise.
+.IP
+Warning: this routine does not understand
+.SM NULL
+pointers.
+Use
+.B xdr_pointer(\|)
+instead.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_setpos(xdrs, pos)
+\s-1XDR\s0 *xdrs;
+u_int pos;
+.fi
+.ft R
+.IP
+A macro that invokes the set position routine associated with
+the
+.SM XDR
+stream
+.IR xdrs .
+The parameter
+.I pos
+is a position value obtained from
+.BR xdr_getpos(\|) .
+This routine returns one if the
+.SM XDR
+stream could be repositioned,
+and zero otherwise.
+.IP
+Warning: it is difficult to reposition some types of
+.SM XDR
+streams, so this routine may fail with one
+type of stream and succeed with another.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_short(xdrs, sp)
+\s-1XDR\s0 *xdrs;
+short *sp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B short
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdrstdio_create(xdrs, file, op)
+\s-1XDR\s0 *xdrs;
+\s-1FILE\s0 *file;
+enum xdr_op op;
+.fi
+.ft R
+.IP
+This routine initializes the
+.SM XDR
+stream object pointed to by
+.IR xdrs .
+The
+.SM XDR
+stream data is written to, or read from, the Standard
+.B I/O
+stream
+.IR file .
+The parameter
+.I op
+determines the direction of the
+.SM XDR
+stream (either
+.BR \s-1XDR_ENCODE\s0 ,
+.BR \s-1XDR_DECODE\s0 ,
+or
+.BR \s-1XDR_FREE\s0 ).
+.IP
+Warning: the destroy routine associated with such
+.SM XDR
+streams calls
+.B fflush(\|)
+on the
+.I file
+stream, but never
+.BR fclose(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+xdr_string(xdrs, sp, maxsize)
+\s-1XDR\s0
+*xdrs;
+char **sp;
+u_int maxsize;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C strings and
+their
+corresponding external representations.
+Strings cannot be longer than
+.IR maxsize .
+Note:
+.I sp
+is the address of the string's pointer.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_char(xdrs, ucp)
+\s-1XDR\s0 *xdrs;
+unsigned char *ucp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between
+.B unsigned
+C characters and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_int(xdrs, up)
+\s-1XDR\s0 *xdrs;
+unsigned *up;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B unsigned
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_long(xdrs, ulp)
+\s-1XDR\s0 *xdrs;
+unsigned long *ulp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B "unsigned long"
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_short(xdrs, usp)
+\s-1XDR\s0 *xdrs;
+unsigned short *usp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B "unsigned short"
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 16
+.LP
+.ft B
+.nf
+.sp .5
+xdr_union(xdrs, dscmp, unp, choices, dfault)
+\s-1XDR\s0 *xdrs;
+int *dscmp;
+char *unp;
+struct xdr_discrim *choices;
+bool_t (*defaultarm) (\|); /* may equal \s-1NULL\s0 */
+.fi
+.ft R
+.IP
+A filter primitive that translates between a discriminated C
+.B union
+and its corresponding external representation.
+It first
+translates the discriminant of the union located at
+.IR dscmp .
+This discriminant is always an
+.BR enum_t .
+Next the union located at
+.I unp
+is translated. The parameter
+.I choices
+is a pointer to an array of
+.B xdr_discrim(\|)
+structures.
+Each structure contains an ordered pair of
+.RI [ value , proc ].
+If the union's discriminant is equal to the associated
+.IR value ,
+then the
+.I proc
+is called to translate the union. The end of the
+.B xdr_discrim(\|)
+structure array is denoted by a routine of value
+.SM NULL\s0.
+If the discriminant is not found in the
+.I choices
+array, then the
+.I defaultarm
+procedure is called (if it is not
+.SM NULL\s0).
+Returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+xdr_vector(xdrs, arrp, size, elsize, elproc)
+\s-1XDR\s0 *xdrs;
+char *arrp;
+u_int size, elsize;
+xdrproc_t elproc;
+.fi
+.ft R
+.IP
+A filter primitive that translates between fixed-length
+arrays
+and their corresponding external representations. The
+parameter
+.I arrp
+is the address of the pointer to the array, while
+.I size
+is the element count of the array. The parameter
+.I elsize
+is the
+.I sizeof
+each of the array's elements, and
+.I elproc
+is an
+.SM XDR
+filter that translates between
+the array elements' C form, and their external
+representation.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 5
+.LP
+.ft B
+.nf
+.sp .5
+xdr_void(\|)
+.fi
+.ft R
+.IP
+This routine always returns one.
+It may be passed to
+.SM RPC
+routines that require a function parameter,
+where nothing is to be done.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_wrapstring(xdrs, sp)
+\s-1XDR\s0 *xdrs;
+char **sp;
+.fi
+.ft R
+.IP
+A primitive that calls
+.B "xdr_string(xdrs, sp,\s-1MAXUN.UNSIGNED\s0 );"
+where
+.B
+.SM MAXUN.UNSIGNED
+is the maximum value of an unsigned integer.
+.B xdr_wrapstring(\|)
+is handy because the
+.SM RPC
+package passes a maximum of two
+.SM XDR
+routines as parameters, and
+.BR xdr_string(\|) ,
+one of the most frequently used primitives, requires three.
+Returns one if it succeeds, zero otherwise.
+.SH SEE ALSO
+.BR rpc (3)
+.LP
+The following manuals:
+.RS
+.ft I
+eXternal Data Representation Standard: Protocol Specification
+.br
+eXternal Data Representation: Sun Technical Notes
+.ft R
+.br
+.IR "\s-1XDR\s0: External Data Representation Standard" ,
+.SM RFC1014, Sun Microsystems, Inc.,
+.SM USC-ISI\s0.
diff --git a/cpukit/librpc/src/xdr/xdr.c b/cpukit/librpc/src/xdr/xdr.c
new file mode 100644
index 0000000000..02631e60ef
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr.c
@@ -0,0 +1,860 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
+/*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr.c,v 1.9 1999/08/28 00:02:55 peter Exp $";
+#endif
+
+/*
+ * xdr.c, Generic XDR routines implementation.
+ *
+ * Copyright (C) 1986, Sun Microsystems, Inc.
+ *
+ * These are the "generic" xdr routines used to serialize and de-serialize
+ * most common data items. See xdr.h for more info on the interface to
+ * xdr.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#if defined(__rtems__)
+#define warnx(msg) fprintf(stderr, msg "\n");
+#endif
+
+/*
+ * constants specific to the xdr "protocol"
+ */
+#define XDR_FALSE ((long) 0)
+#define XDR_TRUE ((long) 1)
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * for unit alignment
+ */
+static const char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
+
+/*
+ * Free a data structure using XDR
+ * Not a filter, but a convenient utility nonetheless
+ */
+void
+xdr_free(
+ xdrproc_t proc,
+ char *objp)
+{
+ XDR x;
+
+ x.x_op = XDR_FREE;
+ (*proc)(&x, objp);
+}
+
+/*
+ * XDR nothing
+ */
+bool_t
+xdr_void(void)
+{
+
+ return (TRUE);
+}
+
+
+/*
+ * XDR integers
+ */
+bool_t
+xdr_int(
+ XDR *xdrs,
+ int *ip)
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *ip;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *ip = (int) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned integers
+ */
+bool_t
+xdr_u_int(
+ XDR *xdrs,
+ u_int *up)
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *up;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *up = (u_int) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+
+/*
+ * XDR long integers
+ * same as xdr_u_long - open coded to save a proc call!
+ */
+bool_t
+xdr_long(
+ XDR *xdrs,
+ long *lp)
+{
+ switch (xdrs->x_op) {
+ case XDR_ENCODE:
+ return (XDR_PUTLONG(xdrs, lp));
+ case XDR_DECODE:
+ return (XDR_GETLONG(xdrs, lp));
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned long integers
+ * same as xdr_long - open coded to save a proc call!
+ */
+bool_t
+xdr_u_long(
+ XDR *xdrs,
+ u_long *ulp)
+{
+ switch (xdrs->x_op) {
+ case XDR_ENCODE:
+ return (XDR_PUTLONG(xdrs, (long *)ulp));
+ case XDR_DECODE:
+ return (XDR_GETLONG(xdrs, (long *)ulp));
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+
+/*
+ * XDR 32-bit integers
+ * same as xdr_u_int32_t - open coded to save a proc call!
+ */
+bool_t
+xdr_int32_t(
+ XDR *xdrs,
+ int32_t *int32_p)
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *int32_p;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *int32_p = (int32_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned 32-bit integers
+ * same as xdr_int32_t - open coded to save a proc call!
+ */
+bool_t
+xdr_u_int32_t(
+ XDR *xdrs,
+ u_int32_t *u_int32_p)
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *u_int32_p;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *u_int32_p = (u_int32_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR short integers
+ */
+bool_t
+xdr_short(
+ XDR *xdrs,
+ short *sp)
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *sp;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *sp = (short) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned short integers
+ */
+bool_t
+xdr_u_short(
+ XDR *xdrs,
+ u_short *usp)
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *usp;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *usp = (u_short) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+
+/*
+ * XDR 16-bit integers
+ */
+bool_t
+xdr_int16_t(
+ XDR *xdrs,
+ int16_t *int16_p)
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *int16_p;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *int16_p = (int16_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned 16-bit integers
+ */
+bool_t
+xdr_u_int16_t(
+ XDR *xdrs,
+ u_int16_t *u_int16_p)
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *u_int16_p;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *u_int16_p = (u_int16_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+
+/*
+ * XDR a char
+ */
+bool_t
+xdr_char(
+ XDR *xdrs,
+ char *cp)
+{
+ int i;
+
+ i = (*cp);
+ if (!xdr_int(xdrs, &i)) {
+ return (FALSE);
+ }
+ *cp = i;
+ return (TRUE);
+}
+
+/*
+ * XDR an unsigned char
+ */
+bool_t
+xdr_u_char(
+ XDR *xdrs,
+ u_char *cp)
+{
+ u_int u;
+
+ u = (*cp);
+ if (!xdr_u_int(xdrs, &u)) {
+ return (FALSE);
+ }
+ *cp = u;
+ return (TRUE);
+}
+
+/*
+ * XDR booleans
+ */
+bool_t
+xdr_bool(
+ XDR *xdrs,
+ bool_t *bp)
+{
+ long lb;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ lb = *bp ? XDR_TRUE : XDR_FALSE;
+ return (XDR_PUTLONG(xdrs, &lb));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &lb)) {
+ return (FALSE);
+ }
+ *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * XDR enumerations
+ */
+bool_t
+xdr_enum(
+ XDR *xdrs,
+ enum_t *ep)
+{
+#ifndef lint
+ enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
+
+ /*
+ * enums are treated as ints
+ */
+ if (sizeof (enum sizecheck) == sizeof (long)) {
+ return (xdr_long(xdrs, (long *)ep));
+ } else if (sizeof (enum sizecheck) == sizeof (int)) {
+ return (xdr_int(xdrs, (int *)ep));
+ } else if (sizeof (enum sizecheck) == sizeof (short)) {
+ return (xdr_short(xdrs, (short *)ep));
+ } else {
+ return (FALSE);
+ }
+#else
+ (void) (xdr_short(xdrs, (short *)ep));
+ (void) (xdr_int(xdrs, (int *)ep));
+ return (xdr_long(xdrs, (long *)ep));
+#endif
+}
+
+/*
+ * XDR opaque data
+ * Allows the specification of a fixed size sequence of opaque bytes.
+ * cp points to the opaque object and cnt gives the byte length.
+ */
+bool_t
+xdr_opaque(
+ XDR *xdrs,
+ caddr_t cp,
+ u_int cnt)
+{
+ u_int rndup;
+ static int crud[BYTES_PER_XDR_UNIT];
+
+ /*
+ * if no data we are done
+ */
+ if (cnt == 0)
+ return (TRUE);
+
+ /*
+ * round byte count to full xdr units
+ */
+ rndup = cnt % BYTES_PER_XDR_UNIT;
+ if (rndup > 0)
+ rndup = BYTES_PER_XDR_UNIT - rndup;
+
+ if (xdrs->x_op == XDR_DECODE) {
+ if (!XDR_GETBYTES(xdrs, cp, cnt)) {
+ return (FALSE);
+ }
+ if (rndup == 0)
+ return (TRUE);
+ return (XDR_GETBYTES(xdrs, (caddr_t)crud, rndup));
+ }
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
+ return (FALSE);
+ }
+ if (rndup == 0)
+ return (TRUE);
+ return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
+ }
+
+ if (xdrs->x_op == XDR_FREE) {
+ return (TRUE);
+ }
+
+ return (FALSE);
+}
+
+/*
+ * XDR counted bytes
+ * *cpp is a pointer to the bytes, *sizep is the count.
+ * If *cpp is NULL maxsize bytes are allocated
+ */
+bool_t
+xdr_bytes(
+ XDR *xdrs,
+ char **cpp,
+ u_int *sizep,
+ u_int maxsize)
+{
+ char *sp = *cpp; /* sp is the actual string pointer */
+ u_int nodesize;
+
+ /*
+ * first deal with the length since xdr bytes are counted
+ */
+ if (! xdr_u_int(xdrs, sizep)) {
+ return (FALSE);
+ }
+ nodesize = *sizep;
+ if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
+ return (FALSE);
+ }
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op) {
+
+ case XDR_DECODE:
+ if (nodesize == 0) {
+ return (TRUE);
+ }
+ if (sp == NULL) {
+ *cpp = sp = mem_alloc(nodesize);
+ }
+ if (sp == NULL) {
+ warnx("xdr_bytes: out of memory");
+ return (FALSE);
+ }
+ /* FALLTHROUGH */
+
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, sp, nodesize));
+
+ case XDR_FREE:
+ if (sp != NULL) {
+ mem_free(sp, nodesize);
+ *cpp = NULL;
+ }
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * Implemented here due to commonality of the object.
+ */
+bool_t
+xdr_netobj(
+ XDR *xdrs,
+ struct netobj *np)
+{
+
+ return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
+}
+
+/*
+ * XDR a descriminated union
+ * Support routine for discriminated unions.
+ * You create an array of xdrdiscrim structures, terminated with
+ * an entry with a null procedure pointer. The routine gets
+ * the discriminant value and then searches the array of xdrdiscrims
+ * looking for that value. It calls the procedure given in the xdrdiscrim
+ * to handle the discriminant. If there is no specific routine a default
+ * routine may be called.
+ * If there is no specific or default routine an error is returned.
+ */
+bool_t
+xdr_union(
+ XDR *xdrs,
+ enum_t *dscmp, /* enum to decide which arm to work on */
+ char *unp, /* the union itself */
+ const struct xdr_discrim *choices, /* [value, xdr proc] for each arm */
+ xdrproc_t dfault) /* default xdr routine */
+{
+ enum_t dscm;
+
+ /*
+ * we deal with the discriminator; it's an enum
+ */
+ if (! xdr_enum(xdrs, dscmp)) {
+ return (FALSE);
+ }
+ dscm = *dscmp;
+
+ /*
+ * search choices for a value that matches the discriminator.
+ * if we find one, execute the xdr routine for that value.
+ */
+ for (; choices->proc != NULL_xdrproc_t; choices++) {
+ if (choices->value == dscm)
+ return ((*(choices->proc))(xdrs, unp, LASTUNSIGNED));
+ }
+
+ /*
+ * no match - execute the default xdr routine if there is one
+ */
+ return ((dfault == NULL_xdrproc_t) ? FALSE :
+ (*dfault)(xdrs, unp, LASTUNSIGNED));
+}
+
+
+/*
+ * Non-portable xdr primitives.
+ * Care should be taken when moving these routines to new architectures.
+ */
+
+
+/*
+ * XDR null terminated ASCII strings
+ * xdr_string deals with "C strings" - arrays of bytes that are
+ * terminated by a NULL character. The parameter cpp references a
+ * pointer to storage; If the pointer is null, then the necessary
+ * storage is allocated. The last parameter is the max allowed length
+ * of the string as specified by a protocol.
+ */
+bool_t
+xdr_string(
+ XDR *xdrs,
+ char **cpp,
+ u_int maxsize)
+{
+ char *sp = *cpp; /* sp is the actual string pointer */
+ u_int size = 0;
+ u_int nodesize;
+
+ /*
+ * first deal with the length since xdr strings are counted-strings
+ */
+ switch (xdrs->x_op) {
+ case XDR_FREE:
+ if (sp == NULL) {
+ return(TRUE); /* already free */
+ }
+ /* FALLTHROUGH */
+ case XDR_ENCODE:
+ size = strlen(sp);
+ break;
+ case XDR_DECODE:
+ break;
+ }
+ if (! xdr_u_int(xdrs, &size)) {
+ return (FALSE);
+ }
+ if (size > maxsize) {
+ return (FALSE);
+ }
+ nodesize = size + 1;
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op) {
+
+ case XDR_DECODE:
+ if (nodesize == 0) {
+ return (TRUE);
+ }
+ if (sp == NULL)
+ *cpp = sp = mem_alloc(nodesize);
+ if (sp == NULL) {
+ warnx("xdr_string: out of memory");
+ return (FALSE);
+ }
+ sp[size] = 0;
+ /* FALLTHROUGH */
+
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, sp, size));
+
+ case XDR_FREE:
+ mem_free(sp, nodesize);
+ *cpp = NULL;
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/*
+ * Wrapper for xdr_string that can be called directly from
+ * routines like clnt_call
+ */
+bool_t
+xdr_wrapstring(
+ XDR *xdrs,
+ char **cpp)
+{
+ return xdr_string(xdrs, cpp, LASTUNSIGNED);
+}
+
+/*
+ * XDR 64-bit integers
+ */
+bool_t
+xdr_int64_t(
+ XDR *xdrs,
+ int64_t *int64_p)
+{
+ int64_t x;
+
+ switch (xdrs->x_op) {
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, (caddr_t)int64_p, sizeof(int64_t)));
+ case XDR_DECODE:
+ if (!xdr_opaque(xdrs, (caddr_t)&x, sizeof x)) {
+ return (FALSE);
+ }
+ *int64_p = x;
+ return (TRUE);
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+
+/*
+ * XDR unsigned 64-bit integers
+ */
+bool_t
+xdr_u_int64_t(
+ XDR *xdrs,
+ u_int64_t *uint64_p)
+{
+ u_int64_t x;
+
+ switch (xdrs->x_op) {
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, (caddr_t)uint64_p, sizeof(u_int64_t)));
+ case XDR_DECODE:
+ if (!xdr_opaque(xdrs, (caddr_t)&x, sizeof x)) {
+ return (FALSE);
+ }
+ *uint64_p = x;
+ return (TRUE);
+ case XDR_FREE:
+ return (TRUE);
+ }
+ /* NOTREACHED */
+ return (FALSE);
+}
+
+/* FIXME: RTEMS does not support u_longlong_t and longlong_t, yet */
+#if !defined(__rtems__)
+/*
+ * XDR hypers
+ */
+bool_t
+xdr_hyper(xdrs, llp)
+ XDR *xdrs;
+ longlong_t *llp;
+{
+
+ /*
+ * Don't bother open-coding this; it's a fair amount of code. Just
+ * call xdr_int64_t().
+ */
+ return (xdr_int64_t(xdrs, (int64_t *)llp));
+}
+
+
+/*
+ * XDR unsigned hypers
+ */
+bool_t
+xdr_u_hyper(xdrs, ullp)
+ XDR *xdrs;
+ u_longlong_t *ullp;
+{
+
+ /*
+ * Don't bother open-coding this; it's a fair amount of code. Just
+ * call xdr_u_int64_t().
+ */
+ return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
+}
+
+
+/*
+ * XDR longlong_t's
+ */
+bool_t
+xdr_longlong_t(xdrs, llp)
+ XDR *xdrs;
+ longlong_t *llp;
+{
+
+ /*
+ * Don't bother open-coding this; it's a fair amount of code. Just
+ * call xdr_int64_t().
+ */
+ return (xdr_int64_t(xdrs, (int64_t *)llp));
+}
+
+
+/*
+ * XDR u_longlong_t's
+ */
+bool_t
+xdr_u_longlong_t(xdrs, ullp)
+ XDR *xdrs;
+ u_longlong_t *ullp;
+{
+
+ /*
+ * Don't bother open-coding this; it's a fair amount of code. Just
+ * call xdr_u_int64_t().
+ */
+ return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
+}
+#endif
diff --git a/cpukit/librpc/src/xdr/xdr_array.c b/cpukit/librpc/src/xdr/xdr_array.c
new file mode 100644
index 0000000000..190dc3cf87
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_array.c
@@ -0,0 +1,160 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_array.c,v 1.8 1999/08/28 00:02:55 peter Exp $";
+#endif
+
+/*
+ * xdr_array.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "non-trivial" xdr primitives used to serialize and de-serialize
+ * arrays. See xdr.h for more info on the interface to xdr.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * XDR an array of arbitrary elements
+ * *addrp is a pointer to the array, *sizep is the number of elements.
+ * If addrp is NULL (*sizep * elsize) bytes are allocated.
+ * elsize is the size (in bytes) of each element, and elproc is the
+ * xdr procedure to call to handle each element of the array.
+ */
+bool_t
+xdr_array(
+ register XDR *xdrs,
+ caddr_t *addrp, /* array pointer */
+ u_int *sizep, /* number of elements */
+ u_int maxsize, /* max numberof elements */
+ u_int elsize, /* size in bytes of each element */
+ xdrproc_t elproc) /* xdr routine to handle each element */
+{
+ register u_int i;
+ register caddr_t target = *addrp;
+ register u_int c; /* the actual element count */
+ register bool_t stat = TRUE;
+ register u_int nodesize;
+
+ /* like strings, arrays are really counted arrays */
+ if (! xdr_u_int(xdrs, sizep)) {
+ return (FALSE);
+ }
+ c = *sizep;
+ if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
+ return (FALSE);
+ }
+ nodesize = c * elsize;
+
+ /*
+ * if we are deserializing, we may need to allocate an array.
+ * We also save time by checking for a null array if we are freeing.
+ */
+ if (target == NULL)
+ switch (xdrs->x_op) {
+ case XDR_DECODE:
+ if (c == 0)
+ return (TRUE);
+ *addrp = target = mem_alloc(nodesize);
+ if (target == NULL) {
+ (void) fprintf(stderr,
+ "xdr_array: out of memory\n");
+ return (FALSE);
+ }
+ memset(target, 0, nodesize);
+ break;
+
+ case XDR_FREE:
+ return (TRUE);
+ case XDR_ENCODE: /* to avoid warning */
+ break;
+ }
+
+ /*
+ * now we xdr each element of array
+ */
+ for (i = 0; (i < c) && stat; i++) {
+ stat = (*elproc)(xdrs, target, LASTUNSIGNED);
+ target += elsize;
+ }
+
+ /*
+ * the array may need freeing
+ */
+ if (xdrs->x_op == XDR_FREE) {
+ mem_free(*addrp, nodesize);
+ *addrp = NULL;
+ }
+ return (stat);
+}
+
+/*
+ * xdr_vector():
+ *
+ * XDR a fixed length array. Unlike variable-length arrays,
+ * the storage of fixed length arrays is static and unfreeable.
+ * > basep: base of the array
+ * > size: size of the array
+ * > elemsize: size of each element
+ * > xdr_elem: routine to XDR each element
+ */
+bool_t
+xdr_vector(
+ register XDR *xdrs,
+ register char *basep,
+ register u_int nelem,
+ register u_int elemsize,
+ register xdrproc_t xdr_elem)
+{
+ register u_int i;
+ register char *elptr;
+
+ elptr = basep;
+ for (i = 0; i < nelem; i++) {
+ if (! (*xdr_elem)(xdrs, elptr, LASTUNSIGNED)) {
+ return(FALSE);
+ }
+ elptr += elemsize;
+ }
+ return(TRUE);
+}
diff --git a/cpukit/librpc/src/xdr/xdr_float.c b/cpukit/librpc/src/xdr/xdr_float.c
new file mode 100644
index 0000000000..544a52b193
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_float.c
@@ -0,0 +1,342 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_float.c,v 1.7 1999/08/28 00:02:55 peter Exp $";
+#endif
+
+/*
+ * xdr_float.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "floating point" xdr routines used to (de)serialize
+ * most common data items. See xdr.h for more info on the interface to
+ * xdr.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+/*
+ * NB: Not portable.
+ * This routine works on machines with IEEE754 FP and Vaxen.
+ */
+
+#if defined(__alpha__) || \
+ defined(_AM29K) || \
+ defined(__arm__) || \
+ defined(__H8300__) || defined(__h8300__) || \
+ defined(__hppa__) || \
+ defined(__i386__) || \
+ defined(__lm32__) || \
+ defined(__m68k__) || defined(__mc68000__) || \
+ defined(__mips__) || \
+ defined(__nios2__) || \
+ defined(__ns32k__) || \
+ defined(__sparc__) || \
+ defined(__ppc__) || defined(__PPC__) || \
+ defined(__sh__) || \
+ defined(__AVR__) || \
+ defined(__BFIN__) || \
+ defined(__m32c__) || \
+ defined(__M32R__)
+
+#include <rtems/endian.h>
+#if !defined(IEEEFP)
+#define IEEEFP
+#endif
+
+#elif defined(_TMS320C3x) || defined(_TMS320C4x)
+#error "Texas Instruments C3x/C4x Not supported."
+
+#elif defined(vax)
+
+/* What IEEE single precision floating point looks like on a Vax */
+struct ieee_single {
+ unsigned int mantissa: 23;
+ unsigned int exp : 8;
+ unsigned int sign : 1;
+};
+
+/* Vax single precision floating point */
+struct vax_single {
+ unsigned int mantissa1 : 7;
+ unsigned int exp : 8;
+ unsigned int sign : 1;
+ unsigned int mantissa2 : 16;
+};
+
+#define VAX_SNG_BIAS 0x81
+#define IEEE_SNG_BIAS 0x7f
+
+static struct sgl_limits {
+ struct vax_single s;
+ struct ieee_single ieee;
+} sgl_limits[2] = {
+ {{ 0x7f, 0xff, 0x0, 0xffff }, /* Max Vax */
+ { 0x0, 0xff, 0x0 }}, /* Max IEEE */
+ {{ 0x0, 0x0, 0x0, 0x0 }, /* Min Vax */
+ { 0x0, 0x0, 0x0 }} /* Min IEEE */
+};
+/* end of vax */
+#else
+#error "xdr_float.c: unknown CPU"
+#endif
+
+
+bool_t
+xdr_float(
+ register XDR *xdrs,
+ register float *fp)
+{
+#ifdef IEEEFP
+ bool_t rv;
+ long tmpl;
+#else
+ struct ieee_single is;
+ struct vax_single vs, *vsp;
+ struct sgl_limits *lim;
+ int i;
+#endif
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+#ifdef IEEEFP
+ tmpl = *(int32_t *)fp;
+ return (XDR_PUTLONG(xdrs, &tmpl));
+#else
+ vs = *((struct vax_single *)fp);
+ for (i = 0, lim = sgl_limits;
+ i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
+ i++, lim++) {
+ if ((vs.mantissa2 == lim->s.mantissa2) &&
+ (vs.exp == lim->s.exp) &&
+ (vs.mantissa1 == lim->s.mantissa1)) {
+ is = lim->ieee;
+ goto shipit;
+ }
+ }
+ is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
+ is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
+ shipit:
+ is.sign = vs.sign;
+ return (XDR_PUTLONG(xdrs, (long *)&is));
+#endif
+
+ case XDR_DECODE:
+#ifdef IEEEFP
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *(int32_t *)fp = tmpl;
+ return (rv);
+#else
+ vsp = (struct vax_single *)fp;
+ if (!XDR_GETLONG(xdrs, (long *)&is))
+ return (FALSE);
+ for (i = 0, lim = sgl_limits;
+ i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
+ i++, lim++) {
+ if ((is.exp == lim->ieee.exp) &&
+ (is.mantissa == lim->ieee.mantissa)) {
+ *vsp = lim->s;
+ goto doneit;
+ }
+ }
+ vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS;
+ vsp->mantissa2 = is.mantissa;
+ vsp->mantissa1 = (is.mantissa >> 16);
+ doneit:
+ vsp->sign = is.sign;
+ return (TRUE);
+#endif
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+#ifdef vax
+/* What IEEE double precision floating point looks like on a Vax */
+struct ieee_double {
+ unsigned int mantissa1 : 20;
+ unsigned int exp : 11;
+ unsigned int sign : 1;
+ unsigned int mantissa2 : 32;
+};
+
+/* Vax double precision floating point */
+struct vax_double {
+ unsigned int mantissa1 : 7;
+ unsigned int exp : 8;
+ unsigned int sign : 1;
+ unsigned int mantissa2 : 16;
+ unsigned int mantissa3 : 16;
+ unsigned int mantissa4 : 16;
+};
+
+#define VAX_DBL_BIAS 0x81
+#define IEEE_DBL_BIAS 0x3ff
+#define MASK(nbits) ((1 << nbits) - 1)
+
+static struct dbl_limits {
+ struct vax_double d;
+ struct ieee_double ieee;
+} dbl_limits[2] = {
+ {{ 0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff }, /* Max Vax */
+ { 0x0, 0x7ff, 0x0, 0x0 }}, /* Max IEEE */
+ {{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* Min Vax */
+ { 0x0, 0x0, 0x0, 0x0 }} /* Min IEEE */
+};
+
+#endif /* vax */
+
+
+bool_t
+xdr_double(
+ register XDR *xdrs,
+ double *dp)
+{
+#ifdef IEEEFP
+ register int32_t *i32p;
+ bool_t rv;
+ long tmpl;
+#else
+ register long *lp;
+ struct ieee_double id;
+ struct vax_double vd;
+ register struct dbl_limits *lim;
+ int i;
+#endif
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+#ifdef IEEEFP
+ i32p = (int32_t *)dp;
+#if BYTE_ORDER == BIG_ENDIAN
+ tmpl = *i32p++;
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+ if (!rv)
+ return (rv);
+ tmpl = *i32p;
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+#else
+ tmpl = *(i32p+1);
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+ if (!rv)
+ return (rv);
+ tmpl = *i32p;
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+#endif
+ return (rv);
+#else
+ vd = *((struct vax_double *)dp);
+ for (i = 0, lim = dbl_limits;
+ i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
+ i++, lim++) {
+ if ((vd.mantissa4 == lim->d.mantissa4) &&
+ (vd.mantissa3 == lim->d.mantissa3) &&
+ (vd.mantissa2 == lim->d.mantissa2) &&
+ (vd.mantissa1 == lim->d.mantissa1) &&
+ (vd.exp == lim->d.exp)) {
+ id = lim->ieee;
+ goto shipit;
+ }
+ }
+ id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
+ id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3);
+ id.mantissa2 = ((vd.mantissa2 & MASK(3)) << 29) |
+ (vd.mantissa3 << 13) |
+ ((vd.mantissa4 >> 3) & MASK(13));
+ shipit:
+ id.sign = vd.sign;
+ lp = (long *)&id;
+ return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
+#endif
+
+ case XDR_DECODE:
+#ifdef IEEEFP
+ i32p = (int32_t *)dp;
+#if BYTE_ORDER == BIG_ENDIAN
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *i32p++ = tmpl;
+ if (!rv)
+ return (rv);
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *i32p = tmpl;
+#else
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *(i32p+1) = tmpl;
+ if (!rv)
+ return (rv);
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *i32p = tmpl;
+#endif
+ return (rv);
+#else
+ lp = (long *)&id;
+ if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))
+ return (FALSE);
+ for (i = 0, lim = dbl_limits;
+ i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
+ i++, lim++) {
+ if ((id.mantissa2 == lim->ieee.mantissa2) &&
+ (id.mantissa1 == lim->ieee.mantissa1) &&
+ (id.exp == lim->ieee.exp)) {
+ vd = lim->d;
+ goto doneit;
+ }
+ }
+ vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
+ vd.mantissa1 = (id.mantissa1 >> 13);
+ vd.mantissa2 = ((id.mantissa1 & MASK(13)) << 3) |
+ (id.mantissa2 >> 29);
+ vd.mantissa3 = (id.mantissa2 >> 13);
+ vd.mantissa4 = (id.mantissa2 << 3);
+ doneit:
+ vd.sign = id.sign;
+ *dp = *((double *)&vd);
+ return (TRUE);
+#endif
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
diff --git a/cpukit/librpc/src/xdr/xdr_mem.c b/cpukit/librpc/src/xdr/xdr_mem.c
new file mode 100644
index 0000000000..5b30419d7a
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_mem.c
@@ -0,0 +1,245 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_mem.c,v 1.8 1999/08/28 00:02:56 peter Exp $";
+#endif
+
+/*
+ * xdr_mem.h, XDR implementation using memory buffers.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * If you have some data to be interpreted as external data representation
+ * or to be converted to external data representation in a memory buffer,
+ * then this is the package for you.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+
+static bool_t xdrmem_getlong_aligned(XDR *xdrs, long *lp);
+static bool_t xdrmem_putlong_aligned(XDR *xdrs, const long *lp);
+static bool_t xdrmem_getlong_unaligned(XDR *xdrs, long *lp);
+static bool_t xdrmem_putlong_unaligned(XDR *xdrs, const long *lp);
+static bool_t xdrmem_getbytes(XDR *xdrs, caddr_t addr, u_int len);
+static bool_t xdrmem_putbytes(XDR *xdrs, const char *addr, u_int len);
+static u_int xdrmem_getpos(XDR *xdrs); /* XXX w/64-bit pointers, u_int not enough! */
+static bool_t xdrmem_setpos(XDR *xdrs, u_int pos);
+static int32_t *xdrmem_inline_aligned(XDR *xdrs, u_int len);
+static int32_t *xdrmem_inline_unaligned(XDR *xdrs, u_int len);
+static void xdrmem_destroy(XDR *);
+
+static struct xdr_ops xdrmem_ops_aligned = {
+ xdrmem_getlong_aligned,
+ xdrmem_putlong_aligned,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline_aligned,
+ xdrmem_destroy
+};
+
+static struct xdr_ops xdrmem_ops_unaligned = {
+ xdrmem_getlong_unaligned,
+ xdrmem_putlong_unaligned,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline_unaligned,
+ xdrmem_destroy
+};
+
+/*
+ * The procedure xdrmem_create initializes a stream descriptor for a
+ * memory buffer.
+ */
+void
+xdrmem_create(
+ XDR *xdrs,
+ char * addr,
+ u_int size,
+ enum xdr_op op)
+{
+
+ xdrs->x_op = op;
+ xdrs->x_ops = ((uintptr_t)addr & (sizeof(int32_t) - 1))
+ ? &xdrmem_ops_unaligned : &xdrmem_ops_aligned;
+ xdrs->x_private = xdrs->x_base = addr;
+ xdrs->x_handy = size;
+}
+
+static void
+xdrmem_destroy(XDR *xdrs)
+{
+
+}
+
+static bool_t
+xdrmem_getlong_aligned(
+ XDR *xdrs,
+ long *lp)
+{
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ *lp = ntohl(*(int32_t *)(xdrs->x_private));
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putlong_aligned(
+ XDR *xdrs,
+ const long *lp)
+{
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ *(int32_t *)xdrs->x_private = htonl(*lp);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_getlong_unaligned(
+ XDR *xdrs,
+ long *lp)
+{
+ int32_t l;
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ memcpy(&l, xdrs->x_private, sizeof(int32_t));
+ *lp = ntohl(l);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putlong_unaligned(
+ XDR *xdrs,
+ const long *lp)
+{
+ int32_t l;
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ l = htonl(*lp);
+ memcpy(xdrs->x_private, &l, sizeof(int32_t));
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_getbytes(
+ XDR *xdrs,
+ caddr_t addr,
+ u_int len)
+{
+
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ memcpy(addr, xdrs->x_private, len);
+ xdrs->x_private += len;
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putbytes(
+ XDR *xdrs,
+ const char *addr,
+ u_int len)
+{
+
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ memcpy(xdrs->x_private, addr, len);
+ xdrs->x_private += len;
+ return (TRUE);
+}
+
+static u_int
+xdrmem_getpos(
+ XDR *xdrs)
+{
+
+ /* XXX w/64-bit pointers, u_int not enough! */
+ return ((uintptr_t)xdrs->x_private - (uintptr_t)xdrs->x_base);
+}
+
+static bool_t
+xdrmem_setpos(
+ XDR *xdrs,
+ u_int pos)
+{
+ void *newaddr = xdrs->x_base + pos;
+ void *lastaddr = xdrs->x_private + xdrs->x_handy;
+
+ if (newaddr > lastaddr)
+ return (FALSE);
+ xdrs->x_private = newaddr;
+ xdrs->x_handy = (intptr_t)lastaddr - (intptr_t)newaddr;
+ return (TRUE);
+}
+
+static int32_t *
+xdrmem_inline_aligned(
+ XDR *xdrs,
+ u_int len)
+{
+ int32_t *buf = 0;
+
+ if (xdrs->x_handy >= len) {
+ xdrs->x_handy -= len;
+ buf = (int32_t *)xdrs->x_private;
+ xdrs->x_private += len;
+ }
+ return (buf);
+}
+
+static int32_t *
+xdrmem_inline_unaligned(
+ XDR *xdrs,
+ u_int len)
+{
+
+ return (0);
+}
diff --git a/cpukit/librpc/src/xdr/xdr_rec.c b/cpukit/librpc/src/xdr/xdr_rec.c
new file mode 100644
index 0000000000..7e47527d3c
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_rec.c
@@ -0,0 +1,608 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_rec.c,v 1.12 2000/01/19 06:12:32 wpaul Exp $";
+#endif
+
+/*
+ * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
+ * layer above tcp (for rpc's use).
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These routines interface XDRSTREAMS to a tcp/ip connection.
+ * There is a record marking layer between the xdr stream
+ * and the tcp transport level. A record is composed on one or more
+ * record fragments. A record fragment is a thirty-two bit header followed
+ * by n bytes of data, where n is contained in the header. The header
+ * is represented as a htonl(u_long). Thegh order bit encodes
+ * whether or not the fragment is the last fragment of the record
+ * (1 => fragment is last, 0 => more fragments to follow.
+ * The other 31 bits encode the byte length of the fragment.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+#include <unistd.h> /* for lseek() */
+
+typedef struct rec_strm RECSTREAM;
+
+static u_int fix_buf_size(u_int);
+static bool_t flush_out(RECSTREAM *rstrm, bool_t eor);
+static bool_t get_input_bytes(RECSTREAM *rstrm, caddr_t addr, int len);
+static bool_t set_input_fragment(RECSTREAM *rstrm);
+static bool_t skip_input_bytes(RECSTREAM *rstrm, long cnt);
+
+static bool_t xdrrec_getlong(XDR *xdrs, long *lp);
+static bool_t xdrrec_putlong(XDR *xdrs, const long *lp);
+static bool_t xdrrec_getbytes(XDR *xdrs, caddr_t addr, u_int len);
+static bool_t xdrrec_putbytes(XDR *xdrs, const char *addr, u_int len);
+static u_int xdrrec_getpos(XDR *xdrs);
+static bool_t xdrrec_setpos(XDR *xdrs, u_int pos);
+static int32_t *xdrrec_inline(XDR *xdrs, u_int len);
+static void xdrrec_destroy(XDR *xdrs);
+
+static struct xdr_ops xdrrec_ops = {
+ xdrrec_getlong,
+ xdrrec_putlong,
+ xdrrec_getbytes,
+ xdrrec_putbytes,
+ xdrrec_getpos,
+ xdrrec_setpos,
+ xdrrec_inline,
+ xdrrec_destroy
+};
+
+/*
+ * A record is composed of one or more record fragments.
+ * A record fragment is a two-byte header followed by zero to
+ * 2**32-1 bytes. The header is treated as a long unsigned and is
+ * encode/decoded to the network via htonl/ntohl. The low order 31 bits
+ * are a byte count of the fragment. The highest order bit is a boolean:
+ * 1 => this fragment is the last fragment of the record,
+ * 0 => this fragment is followed by more fragment(s).
+ *
+ * The fragment/record machinery is not general; it is constructed to
+ * meet the needs of xdr and rpc based on tcp.
+ */
+
+#define LAST_FRAG ((u_int32_t)(1L << 31))
+
+struct rec_strm {
+ caddr_t tcp_handle;
+ caddr_t the_buffer;
+ /*
+ * out-goung bits
+ */
+ int (*writeit) (caddr_t, caddr_t, int);
+ caddr_t out_base; /* output buffer (points to frag header) */
+ caddr_t out_finger; /* next output position */
+ caddr_t out_boundry; /* data cannot up to this address */
+ u_int32_t *frag_header; /* beginning of current fragment */
+ bool_t frag_sent; /* true if buffer sent in middle of record */
+ /*
+ * in-coming bits
+ */
+ int (*readit) (caddr_t, caddr_t, int);
+ u_long in_size; /* fixed size of the input buffer */
+ caddr_t in_base;
+ caddr_t in_finger; /* location of next byte to be had */
+ caddr_t in_boundry; /* can read up to this location */
+ long fbtbc; /* fragment bytes to be consumed */
+ bool_t last_frag;
+ u_int sendsize;
+ u_int recvsize;
+};
+
+
+/*
+ * Create an xdr handle for xdrrec
+ * xdrrec_create fills in xdrs. Sendsize and recvsize are
+ * send and recv buffer sizes (0 => use default).
+ * tcp_handle is an opaque handle that is passed as the first parameter to
+ * the procedures readit and writeit. Readit and writeit are read and
+ * write respectively. They are like the system
+ * calls expect that they take an opaque handle rather than an fd.
+ */
+void
+xdrrec_create(
+ XDR *xdrs,
+ u_int sendsize,
+ u_int recvsize,
+ caddr_t tcp_handle,
+ int (*readit)(char*, char*, int), /* like read, but pass it a tcp_handle, not sock */
+ int (*writeit)(char*, char*, int) /* like write, but pass it a tcp_handle, not sock */
+)
+{
+ RECSTREAM *rstrm =
+ (RECSTREAM *)mem_alloc(sizeof(RECSTREAM));
+
+ if (rstrm == NULL) {
+ (void)fprintf(stderr, "xdrrec_create: out of memory\n");
+ /*
+ * This is bad. Should rework xdrrec_create to
+ * return a handle, and in this case return NULL
+ */
+ return;
+ }
+ /*
+ * adjust sizes and allocate buffer quad byte aligned
+ */
+ rstrm->sendsize = sendsize = fix_buf_size(sendsize);
+ rstrm->recvsize = recvsize = fix_buf_size(recvsize);
+ rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
+ if (rstrm->the_buffer == NULL) {
+ (void)fprintf(stderr, "xdrrec_create: out of memory\n");
+ return;
+ }
+ for (rstrm->out_base = rstrm->the_buffer;
+ (uintptr_t)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
+ rstrm->out_base++);
+ rstrm->in_base = rstrm->out_base + sendsize;
+ /*
+ * now the rest ...
+ */
+ xdrs->x_ops = &xdrrec_ops;
+ xdrs->x_private = (caddr_t)rstrm;
+ rstrm->tcp_handle = tcp_handle;
+ rstrm->readit = readit;
+ rstrm->writeit = writeit;
+ rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
+ rstrm->frag_header = (u_int32_t *)rstrm->out_base;
+ rstrm->out_finger += sizeof(u_int32_t);
+ rstrm->out_boundry += sendsize;
+ rstrm->frag_sent = FALSE;
+ rstrm->in_size = recvsize;
+ rstrm->in_boundry = rstrm->in_base;
+ rstrm->in_finger = (rstrm->in_boundry += recvsize);
+ rstrm->fbtbc = 0;
+ rstrm->last_frag = TRUE;
+}
+
+
+/*
+ * The reoutines defined below are the xdr ops which will go into the
+ * xdr handle filled in by xdrrec_create.
+ */
+
+static bool_t
+xdrrec_getlong(
+ XDR *xdrs,
+ long *lp)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ int32_t *buflp = (int32_t *)(rstrm->in_finger);
+ int32_t mylong;
+
+ /* first try the inline, fast case */
+ if ((rstrm->fbtbc >= sizeof(int32_t)) &&
+ (((intptr_t)rstrm->in_boundry - (intptr_t)buflp) >= sizeof(int32_t))) {
+ *lp = (long)ntohl((u_int32_t)(*buflp));
+ rstrm->fbtbc -= sizeof(int32_t);
+ rstrm->in_finger += sizeof(int32_t);
+ } else {
+ if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(int32_t)))
+ return (FALSE);
+ *lp = (long)ntohl((u_int32_t)mylong);
+ }
+ return (TRUE);
+}
+
+static bool_t
+xdrrec_putlong(
+ XDR *xdrs,
+ const long *lp)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ int32_t *dest_lp = ((int32_t *)(rstrm->out_finger));
+
+ if ((rstrm->out_finger += sizeof(int32_t)) > rstrm->out_boundry) {
+ /*
+ * this case should almost never happen so the code is
+ * inefficient
+ */
+ rstrm->out_finger -= sizeof(int32_t);
+ rstrm->frag_sent = TRUE;
+ if (! flush_out(rstrm, FALSE))
+ return (FALSE);
+ dest_lp = ((int32_t *)(rstrm->out_finger));
+ rstrm->out_finger += sizeof(int32_t);
+ }
+ *dest_lp = (int32_t)htonl((u_int32_t)(*lp));
+ return (TRUE);
+}
+
+static bool_t /* must manage buffers, fragments, and records */
+xdrrec_getbytes(
+ XDR *xdrs,
+ caddr_t addr,
+ u_int len)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ int current;
+
+ while (len > 0) {
+ current = rstrm->fbtbc;
+ if (current == 0) {
+ if (rstrm->last_frag)
+ return (FALSE);
+ if (! set_input_fragment(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (len < current) ? len : current;
+ if (! get_input_bytes(rstrm, addr, current))
+ return (FALSE);
+ addr += current;
+ rstrm->fbtbc -= current;
+ len -= current;
+ }
+ return (TRUE);
+}
+
+static bool_t
+xdrrec_putbytes(
+ XDR *xdrs,
+ const char *addr,
+ u_int len)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ long current;
+
+ while (len > 0) {
+ current = (intptr_t)rstrm->out_boundry -
+ (intptr_t)rstrm->out_finger;
+ current = (len < current) ? len : current;
+ memcpy(rstrm->out_finger, addr, current);
+ rstrm->out_finger += current;
+ addr += current;
+ len -= current;
+ if (rstrm->out_finger == rstrm->out_boundry) {
+ rstrm->frag_sent = TRUE;
+ if (! flush_out(rstrm, FALSE))
+ return (FALSE);
+ }
+ }
+ return (TRUE);
+}
+
+static u_int
+xdrrec_getpos(
+ XDR *xdrs)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ long pos;
+
+ pos = lseek((intptr_t)rstrm->tcp_handle, (off_t) 0, 1);
+ if (pos != -1)
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ pos += rstrm->out_finger - rstrm->out_base;
+ break;
+
+ case XDR_DECODE:
+ pos -= rstrm->in_boundry - rstrm->in_finger;
+ break;
+
+ default:
+ pos = -1;
+ break;
+ }
+ return ((u_int) pos);
+}
+
+static bool_t
+xdrrec_setpos(
+ XDR *xdrs,
+ u_int pos)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ u_int currpos = xdrrec_getpos(xdrs);
+ int delta = currpos - pos;
+ caddr_t newpos;
+
+ if ((int)currpos != -1)
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ newpos = rstrm->out_finger - delta;
+ if ((newpos > (caddr_t)(rstrm->frag_header)) &&
+ (newpos < rstrm->out_boundry)) {
+ rstrm->out_finger = newpos;
+ return (TRUE);
+ }
+ break;
+
+ case XDR_DECODE:
+ newpos = rstrm->in_finger - delta;
+ if ((delta < (int)(rstrm->fbtbc)) &&
+ (newpos <= rstrm->in_boundry) &&
+ (newpos >= rstrm->in_base)) {
+ rstrm->in_finger = newpos;
+ rstrm->fbtbc -= delta;
+ return (TRUE);
+ }
+ break;
+ case XDR_FREE: /* to avoid warning */
+ break;
+ }
+ return (FALSE);
+}
+
+static int32_t *
+xdrrec_inline(
+ XDR *xdrs,
+ u_int len)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ int32_t * buf = NULL;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
+ buf = (int32_t *) rstrm->out_finger;
+ rstrm->out_finger += len;
+ }
+ break;
+
+ case XDR_DECODE:
+ if ((len <= rstrm->fbtbc) &&
+ ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
+ buf = (int32_t *) rstrm->in_finger;
+ rstrm->fbtbc -= len;
+ rstrm->in_finger += len;
+ }
+ break;
+ case XDR_FREE: /* to avoid warning */
+ break;
+ }
+ return (buf);
+}
+
+static void
+xdrrec_destroy(
+ XDR *xdrs)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+
+ mem_free(rstrm->the_buffer,
+ rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
+ mem_free((caddr_t)rstrm, sizeof(RECSTREAM));
+}
+
+
+/*
+ * Exported routines to manage xdr records
+ */
+
+/*
+ * Before reading (deserializing from the stream, one should always call
+ * this procedure to guarantee proper record alignment.
+ */
+bool_t
+xdrrec_skiprecord(
+ XDR *xdrs)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+
+ while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
+ if (! skip_input_bytes(rstrm, rstrm->fbtbc))
+ return (FALSE);
+ rstrm->fbtbc = 0;
+ if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
+ return (FALSE);
+ }
+ rstrm->last_frag = FALSE;
+ return (TRUE);
+}
+
+/*
+ * Look ahead fuction.
+ * Returns TRUE iff there is no more input in the buffer
+ * after consuming the rest of the current record.
+ */
+bool_t
+xdrrec_eof(
+ XDR *xdrs)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+
+ while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
+ if (! skip_input_bytes(rstrm, rstrm->fbtbc))
+ return (TRUE);
+ rstrm->fbtbc = 0;
+ if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
+ return (TRUE);
+ }
+ if (rstrm->in_finger == rstrm->in_boundry)
+ return (TRUE);
+ return (FALSE);
+}
+
+/*
+ * The client must tell the package when an end-of-record has occurred.
+ * The second paraemters tells whether the record should be flushed to the
+ * (output) tcp stream. (This let's the package support batched or
+ * pipelined procedure calls.) TRUE => immmediate flush to tcp connection.
+ */
+bool_t
+xdrrec_endofrecord(
+ XDR *xdrs,
+ bool_t sendnow)
+{
+ RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ u_long len; /* fragment length */
+
+ if (sendnow || rstrm->frag_sent ||
+ ((uintptr_t)rstrm->out_finger + sizeof(u_int32_t) >=
+ (uintptr_t)rstrm->out_boundry)) {
+ rstrm->frag_sent = FALSE;
+ return (flush_out(rstrm, TRUE));
+ }
+ len = (uintptr_t)(rstrm->out_finger) - (uintptr_t)(rstrm->frag_header) -
+ sizeof(u_int32_t);
+ *(rstrm->frag_header) = htonl((u_int32_t)len | LAST_FRAG);
+ rstrm->frag_header = (u_int32_t *)rstrm->out_finger;
+ rstrm->out_finger += sizeof(u_int32_t);
+ return (TRUE);
+}
+
+
+/*
+ * Internal useful routines
+ */
+static bool_t
+flush_out(
+ RECSTREAM *rstrm,
+ bool_t eor)
+{
+ u_int32_t eormask = (eor == TRUE) ? LAST_FRAG : 0;
+ u_int32_t len = (uintptr_t)(rstrm->out_finger) -
+ (uintptr_t)(rstrm->frag_header) - sizeof(u_int32_t);
+
+ *(rstrm->frag_header) = htonl(len | eormask);
+ len = (uintptr_t)(rstrm->out_finger) - (uintptr_t)(rstrm->out_base);
+ if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
+ != (int)len)
+ return (FALSE);
+ rstrm->frag_header = (u_int32_t *)rstrm->out_base;
+ rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_int32_t);
+ return (TRUE);
+}
+
+static bool_t /* knows nothing about records! Only about input buffers */
+fill_input_buf(
+ RECSTREAM *rstrm)
+{
+ caddr_t where;
+ u_long i;
+ long len;
+
+ where = rstrm->in_base;
+ i = (uintptr_t)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
+ where += i;
+ len = rstrm->in_size - i;
+ if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
+ return (FALSE);
+ rstrm->in_finger = where;
+ where += len;
+ rstrm->in_boundry = where;
+ return (TRUE);
+}
+
+static bool_t /* knows nothing about records! Only about input buffers */
+get_input_bytes(
+ RECSTREAM *rstrm,
+ caddr_t addr,
+ int len)
+{
+ long current;
+
+ while (len > 0) {
+ current = (intptr_t)rstrm->in_boundry - (intptr_t)rstrm->in_finger;
+ if (current == 0) {
+ if (! fill_input_buf(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (len < current) ? len : current;
+ memcpy(addr, rstrm->in_finger, current);
+ rstrm->in_finger += current;
+ addr += current;
+ len -= current;
+ }
+ return (TRUE);
+}
+
+static bool_t /* next two bytes of the input stream are treated as a header */
+set_input_fragment(
+ RECSTREAM *rstrm)
+{
+ u_int32_t header;
+
+ if (! get_input_bytes(rstrm, (caddr_t)&header, sizeof(header)))
+ return (FALSE);
+ header = (long)ntohl(header);
+ rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
+ /*
+ * Sanity check. Try not to accept wildly incorrect
+ * record sizes. Unfortunately, the only record size
+ * we can positively identify as being 'wildly incorrect'
+ * is zero. Ridiculously large record sizes may look wrong,
+ * but we don't have any way to be certain that they aren't
+ * what the client actually intended to send us.
+ */
+ if (header == 0)
+ return(FALSE);
+ rstrm->fbtbc = header & (~LAST_FRAG);
+ return (TRUE);
+}
+
+static bool_t /* consumes input bytes; knows nothing about records! */
+skip_input_bytes(
+ RECSTREAM *rstrm,
+ long cnt)
+{
+ long current;
+
+ while (cnt > 0) {
+ current = (intptr_t)rstrm->in_boundry - (intptr_t)rstrm->in_finger;
+ if (current == 0) {
+ if (! fill_input_buf(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (cnt < current) ? cnt : current;
+ rstrm->in_finger += current;
+ cnt -= current;
+ }
+ return (TRUE);
+}
+
+static u_int
+fix_buf_size(
+ u_int s)
+{
+
+ if (s < 100)
+ s = 4000;
+ return (RNDUP(s));
+}
diff --git a/cpukit/librpc/src/xdr/xdr_reference.c b/cpukit/librpc/src/xdr/xdr_reference.c
new file mode 100644
index 0000000000..a2a6ee5135
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_reference.c
@@ -0,0 +1,142 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_reference.c 1.11 87/08/11 SMI";*/
+/*static char *sccsid = "from: @(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_reference.c,v 1.8 1999/08/28 00:02:56 peter Exp $";
+#endif
+
+/*
+ * xdr_reference.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1987, Sun Microsystems, Inc.
+ *
+ * These are the "non-trivial" xdr primitives used to serialize and de-serialize
+ * "pointers". See xdr.h for more info on the interface to xdr.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * XDR an indirect pointer
+ * xdr_reference is for recursively translating a structure that is
+ * referenced by a pointer inside the structure that is currently being
+ * translated. pp references a pointer to storage. If *pp is null
+ * the necessary storage is allocated.
+ * size is the sizeof the referneced structure.
+ * proc is the routine to handle the referenced structure.
+ */
+bool_t
+xdr_reference(
+ register XDR *xdrs,
+ caddr_t *pp, /* the pointer to work on */
+ u_int size, /* size of the object pointed to */
+ xdrproc_t proc) /* xdr routine to handle the object */
+{
+ register caddr_t loc = *pp;
+ register bool_t stat;
+
+ if (loc == NULL)
+ switch (xdrs->x_op) {
+ case XDR_FREE:
+ return (TRUE);
+
+ case XDR_DECODE:
+ *pp = loc = (caddr_t) mem_alloc(size);
+ if (loc == NULL) {
+ (void) fprintf(stderr,
+ "xdr_reference: out of memory\n");
+ return (FALSE);
+ }
+ memset(loc, 0, (int)size);
+ break;
+ case XDR_ENCODE: /* to avoid warning */
+ break;
+ }
+
+ stat = (*proc)(xdrs, loc, LASTUNSIGNED);
+
+ if (xdrs->x_op == XDR_FREE) {
+ mem_free(loc, size);
+ *pp = NULL;
+ }
+ return (stat);
+}
+
+
+/*
+ * xdr_pointer():
+ *
+ * XDR a pointer to a possibly recursive data structure. This
+ * differs with xdr_reference in that it can serialize/deserialiaze
+ * trees correctly.
+ *
+ * What's sent is actually a union:
+ *
+ * union object_pointer switch (boolean b) {
+ * case TRUE: object_data data;
+ * case FALSE: void nothing;
+ * }
+ *
+ * > objpp: Pointer to the pointer to the object.
+ * > obj_size: size of the object.
+ * > xdr_obj: routine to XDR an object.
+ *
+ */
+bool_t
+xdr_pointer(
+ register XDR *xdrs,
+ char **objpp,
+ u_int obj_size,
+ xdrproc_t xdr_obj)
+{
+
+ bool_t more_data;
+
+ more_data = (*objpp != NULL);
+ if (! xdr_bool(xdrs,&more_data)) {
+ return (FALSE);
+ }
+ if (! more_data) {
+ *objpp = NULL;
+ return (TRUE);
+ }
+ return (xdr_reference(xdrs,objpp,obj_size,xdr_obj));
+}
diff --git a/cpukit/librpc/src/xdr/xdr_sizeof.c b/cpukit/librpc/src/xdr/xdr_sizeof.c
new file mode 100644
index 0000000000..72a7ff979d
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_sizeof.c
@@ -0,0 +1,167 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+/*
+ * xdr_sizeof.c
+ *
+ * Copyright 1990 Sun Microsystems, Inc.
+ *
+ * General purpose routine to see how much space something will use
+ * when serialized using XDR.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+/* ARGSUSED */
+static bool_t
+x_putlong(
+ XDR *xdrs,
+ const long *longp)
+{
+ xdrs->x_handy += BYTES_PER_XDR_UNIT;
+ return (TRUE);
+}
+
+/* ARGSUSED */
+static bool_t
+x_putbytes(
+ XDR *xdrs,
+ const char *bp,
+ u_int len)
+{
+ xdrs->x_handy += len;
+ return (TRUE);
+}
+
+static u_int
+x_getpostn(
+ XDR *xdrs)
+{
+ return (xdrs->x_handy);
+}
+
+/* ARGSUSED */
+static bool_t
+x_setpostn(
+ XDR *xdrs,
+ u_int pos)
+{
+ /* This is not allowed */
+ return (FALSE);
+}
+
+static int32_t *
+x_inline(
+ XDR *xdrs,
+ u_int len)
+{
+ if (len == 0) {
+ return (NULL);
+ }
+ if (xdrs->x_op != XDR_ENCODE) {
+ return (NULL);
+ }
+ if (len < (intptr_t) xdrs->x_base) {
+ /* x_private was already allocated */
+ xdrs->x_handy += len;
+ return ((int32_t *) xdrs->x_private);
+ } else {
+ /* Free the earlier space and allocate new area */
+ if (xdrs->x_private)
+ free(xdrs->x_private);
+ if ((xdrs->x_private = (caddr_t) malloc(len)) == NULL) {
+ xdrs->x_base = 0;
+ return (NULL);
+ }
+ xdrs->x_base = (caddr_t)((intptr_t) len);
+ xdrs->x_handy += len;
+ return ((int32_t *) xdrs->x_private);
+ }
+}
+
+static int
+harmless(void)
+{
+ /* Always return FALSE/NULL, as the case may be */
+ return (0);
+}
+
+static void
+x_destroy(
+ XDR *xdrs)
+{
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
+ if (xdrs->x_private) {
+ free(xdrs->x_private);
+ xdrs->x_private = NULL;
+ }
+ return;
+}
+
+unsigned long
+xdr_sizeof(
+ xdrproc_t func,
+ void *data)
+{
+ XDR x;
+ struct xdr_ops ops;
+ bool_t stat;
+ /* to stop ANSI-C compiler from complaining */
+ typedef bool_t (* dummyfunc1)(XDR *, long *);
+ typedef bool_t (* dummyfunc2)(XDR *, caddr_t, u_int);
+
+ ops.x_putlong = x_putlong;
+ ops.x_putbytes = x_putbytes;
+ ops.x_inline = x_inline;
+ ops.x_getpostn = x_getpostn;
+ ops.x_setpostn = x_setpostn;
+ ops.x_destroy = x_destroy;
+
+ /* the other harmless ones */
+ ops.x_getlong = (dummyfunc1) harmless;
+ ops.x_getbytes = (dummyfunc2) harmless;
+
+ x.x_op = XDR_ENCODE;
+ x.x_ops = &ops;
+ x.x_handy = 0;
+ x.x_private = (caddr_t) NULL;
+ x.x_base = (caddr_t) 0;
+
+ stat = func(&x, data);
+ if (x.x_private)
+ free(x.x_private);
+ return (stat == TRUE ? (unsigned) x.x_handy: 0);
+}
diff --git a/cpukit/librpc/src/xdr/xdr_stdio.c b/cpukit/librpc/src/xdr/xdr_stdio.c
new file mode 100644
index 0000000000..ca67941eb2
--- /dev/null
+++ b/cpukit/librpc/src/xdr/xdr_stdio.c
@@ -0,0 +1,194 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ *
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ *
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ *
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ *
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ *
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California 94043
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_stdio.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_stdio.c,v 1.7 1999/08/28 00:02:56 peter Exp $";
+#endif
+
+/*
+ * xdr_stdio.c, XDR implementation on standard i/o file.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * This set of routines implements a XDR on a stdio stream.
+ * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes
+ * from the stream.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rpc/types.h>
+#include <stdio.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+
+static bool_t xdrstdio_getlong(XDR *xdrs, long *lp);
+static bool_t xdrstdio_putlong(XDR *xdrs, const long *lp);
+static bool_t xdrstdio_getbytes(XDR *xdrs, caddr_t addr, u_int len);
+static bool_t xdrstdio_putbytes(XDR *xdrs, const char *addr, u_int len);
+static u_int xdrstdio_getpos(XDR *xdrs);
+static bool_t xdrstdio_setpos(XDR *xdrs, u_int pos);
+static int32_t *xdrstdio_inline(XDR *xdrs, u_int len);
+static void xdrstdio_destroy(XDR *);
+
+/*
+ * Ops vector for stdio type XDR
+ */
+static struct xdr_ops xdrstdio_ops = {
+ xdrstdio_getlong, /* deseraialize a long int */
+ xdrstdio_putlong, /* seraialize a long int */
+ xdrstdio_getbytes, /* deserialize counted bytes */
+ xdrstdio_putbytes, /* serialize counted bytes */
+ xdrstdio_getpos, /* get offset in the stream */
+ xdrstdio_setpos, /* set offset in the stream */
+ xdrstdio_inline, /* prime stream for inline macros */
+ xdrstdio_destroy /* destroy stream */
+};
+
+/*
+ * Initialize a stdio xdr stream.
+ * Sets the xdr stream handle xdrs for use on the stream file.
+ * Operation flag is set to op.
+ */
+void
+xdrstdio_create(
+ XDR *xdrs,
+ FILE *file,
+ enum xdr_op op)
+{
+
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrstdio_ops;
+ xdrs->x_private = (caddr_t)file;
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
+}
+
+/*
+ * Destroy a stdio xdr stream.
+ * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
+ */
+static void
+xdrstdio_destroy(
+ XDR *xdrs)
+{
+ (void)fflush((FILE *)xdrs->x_private);
+ /* xx should we close the file ?? */
+}
+
+static bool_t
+xdrstdio_getlong(
+ XDR *xdrs,
+ long *lp)
+{
+
+ if (fread((caddr_t)lp, sizeof(int32_t), 1,
+ (FILE *)xdrs->x_private) != 1)
+ return (FALSE);
+ *lp = (long)ntohl((int32_t)*lp);
+ return (TRUE);
+}
+
+static bool_t
+xdrstdio_putlong(
+ XDR *xdrs,
+ const long *lp)
+{
+
+ long mycopy = (long)htonl((int32_t)*lp);
+
+ if (fwrite((caddr_t)&mycopy, sizeof(int32_t), 1,
+ (FILE *)xdrs->x_private) != 1)
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t
+xdrstdio_getbytes(
+ XDR *xdrs,
+ caddr_t addr,
+ u_int len )
+{
+
+ if ((len != 0) && (fread(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t
+xdrstdio_putbytes(
+ XDR *xdrs,
+ const char *addr,
+ u_int len)
+{
+
+ if ((len != 0) && (fwrite(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
+ return (FALSE);
+ return (TRUE);
+}
+
+static u_int
+xdrstdio_getpos(
+ XDR *xdrs)
+{
+
+ return ((u_int) ftell((FILE *)xdrs->x_private));
+}
+
+static bool_t
+xdrstdio_setpos(
+ XDR *xdrs,
+ u_int pos)
+{
+
+ return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ?
+ FALSE : TRUE);
+}
+
+static int32_t *
+xdrstdio_inline(
+ XDR *xdrs,
+ u_int len)
+{
+
+ /*
+ * Must do some work to implement this: must insure
+ * enough data in the underlying stdio buffer,
+ * that the buffer is aligned so that we can indirect through a
+ * long *, and stuff this pointer in xdrs->x_buf. Doing
+ * a fread or fwrite to a scratch buffer would defeat
+ * most of the gains to be had here and require storage
+ * management on this buffer, so we don't do this.
+ */
+ return (NULL);
+}
diff --git a/cpukit/mghttpd/.cvsignore b/cpukit/mghttpd/.cvsignore
new file mode 100644
index 0000000000..70845e08eb
--- /dev/null
+++ b/cpukit/mghttpd/.cvsignore
@@ -0,0 +1 @@
+Makefile.in
diff --git a/cpukit/mghttpd/Makefile.am b/cpukit/mghttpd/Makefile.am
new file mode 100644
index 0000000000..2c2a918029
--- /dev/null
+++ b/cpukit/mghttpd/Makefile.am
@@ -0,0 +1,16 @@
+include $(top_srcdir)/automake/compile.am
+
+if LIBNETWORKING
+include_mghttpddir = $(includedir)/mghttpd
+
+project_lib_LIBRARIES = libmghttpd.a
+libmghttpd_a_CPPFLAGS = $(AM_CPPFLAGS)
+# libmghttpd_a_CPPFLAGS += -DHAVE_MD5
+libmghttpd_a_CPPFLAGS += -DNO_SSI -DNO_SSL -DNO_CGI
+
+libmghttpd_a_SOURCES = mongoose.c mongoose.h
+include_mghttpd_HEADERS = mongoose.h
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/mghttpd/mongoose.1 b/cpukit/mghttpd/mongoose.1
new file mode 100644
index 0000000000..e62227a4b4
--- /dev/null
+++ b/cpukit/mghttpd/mongoose.1
@@ -0,0 +1,181 @@
+.\" Process this file with
+.\" groff -man -Tascii mongoose.1
+.\" $Id$
+.Dd Dec 1, 2008
+.Dt mongoose 1
+.Sh NAME
+.Nm mongoose
+.Nd lightweight web server
+.Sh SYNOPSIS
+.Nm
+.Op Ar options
+.Op Ar config_file
+.Nm
+.Fl A Ar htpasswd_file domain_name user_name password
+.Sh DESCRIPTION
+.Nm
+is small, fast and easy to use web server with CGI, SSL, Digest Authorization
+support.
+.Pp
+.Nm
+does not detach from terminal, and uses current working directory
+as the web root, unless
+.Fl root
+option is specified.
+.Pp
+It is possible to specify multiple ports to listen on. For example, to
+make
+.Nm
+listen on HTTP port 80 and HTTPS port 443, one should start it as
+.Dq mongoose -ssl_cert cert.pem -ports 80,443s .
+.Pp
+Options may be specified in any order, with one exception: if SSL listening
+port is specified in the -ports option, then -ssl_cert option must be set
+before -ports option.
+.Pp
+Unlike other web servers,
+.Nm
+does not expect CGI scripts to be put in a special directory. CGI scripts may
+be anywhere. CGI files are recognized by the file extension.
+.Pp
+SSI files are also recognized by extension. Unknown SSI directives are silently
+ignored. Currently, two SSI directives supported, "include" and "exec". For the
+"include" directive, included file name can be specified in three different
+ways. Below is the summary of supported SSI directives:
+.Bl -bullet
+.It
+<!--#exec "shell command"--> Execute shell command.
+.It
+<!--#include "path"--> File path must be relative to the current document.
+.It
+<!--#include virtual="path"--> File path must be relative to the document root.
+.It
+<!--#include file="path"--> File path must be the absolute path.
+.El
+.Pp
+.Nm
+can use the configuration file. By default, it is "mongoose.conf", and if it
+is present in the same directory where
+.Nm
+lives, the command line options are read from it. Alternatively, the
+configuration file may be specified as a last argument. The format of the
+configuration file is exactly the same as for the command line options, the
+only difference is that the command line options must be specified on
+separate lines, and leading dashes for option names must be omitted.
+Lines beginning with '#' are regarded as comments and ignored.
+.Pp
+.Sh OPTIONS
+.Bl -tag -width indent
+.It Fl A Ar htpasswd_file domain_name user_name password
+Add/edit user's password in the passwords file. Deleting users can be done
+with any text editor. Functionality similar to Apache's
+.Ic htdigest
+utility.
+.It Fl access_log Ar file
+Access log file. Default: not set, no logging is done.
+.It Fl acl Ar (+|-)x.x.x.x[/x],...
+Specify access control list (ACL). ACL is a comma separated list
+of IP subnets, each subnet is prepended by '-' or '+' sign. Plus means allow,
+minus means deny. If subnet mask is
+omitted, like "-1.2.3.4", then it means single IP address. Mask may vary
+from 0 to 32 inclusive. On each request, full list is traversed, and
+last match wins. Default: not set, allow all.
+.It Fl admin_uri Ar uri
+If set,
+.Nm
+creates special administrative URI where options may be changed at runtime.
+This URI probably wants to be password-protected, look at
+.Fl protect
+option, and in the EXAMPLES section on how to do it. Default: not set.
+.It Fl aliases Ar list
+This options gives an ability to serve the directories outside web root
+by sort of symbolic linking to certain URI. The
+.Ar list
+must be comma-separated list of URI=PATH pairs, like this:
+"/etc/=/my_etc,/tmp=/my_tmp". Default: not set.
+.It Fl auth_PUT Ar file
+PUT and DELETE passwords file. This must be specified if PUT or
+DELETE methods are used. Default: not set.
+.It Fl auth_gpass Ar file
+Location of global passwords file. When set, per-directory .htpasswd files are
+ignored, and all accessed must be authorised against global passwords file.
+Default: not set.
+.It Fl auth_realm Ar domain_name
+Authorization realm. Default: "mydomain.com".
+.It Fl cgi_env Ar list
+Pass environment variables to the CGI script in addition to standard ones.
+The list must be comma-separated list of X=Y pairs, like this:
+"VARIABLE1=VALUE1,VARIABLE2=VALUE2". Default: not set.
+.It Fl cgi_ext Ar list
+Comma-separated list of CGI extensions. All files having these extensions
+are treated as CGI scripts. Default: "cgi,pl,php"
+.It Fl cgi_interp Ar file
+Force
+.Ar file
+to be a CGI interpreter for all CGI scripts. By default this option is not
+set, and
+.Nm
+decides which interpreter to use by looking at the first line of CGI script.
+.It Fl dir_list Ar yes|no
+Enable/disable directory listing. Default: "1" (enabled).
+.It Fl error_log Ar file
+Error log file. Default: not set, no errors are logged.
+.It Fl idle_time Ar num_seconds
+Number of seconds worker thread waits for some work before exit. Default: 10
+.It Fl max_threads Ar number
+Maximum number of worker threads to start. Default: 100
+.It Fl mime_types Ar list
+Additional to builtin mime types, in form
+"extension1=type1,extension2=type2,...". Extension must include dot.
+.It Fl ports Ar port_list
+Comma-separated list of ports to listen on. If the port is SSL, a letter 's'
+must be appeneded, for example, "-ports 80,443s" will open port 80 and port 443,
+and connections on port 443 will be SSL-ed. It is possible to specify an
+IP address to bind to. In this case, an IP address and a colon must be
+prepended to the port number, for example, "-ports 127.0.0.1:8080". Note that
+if SSL listening port is requested, then
+.Fl ssl_cert
+option must specified BEFORE
+.Fl ports
+option. Default: 8080
+.It Fl protect Ar list
+Comma separated list of URI=PATH pairs, specifying that given URIs
+must the protected with respected password files. Default: not set.
+.It Fl root Ar directory
+Location of the WWW root directory. Default: working directory from which
+.Nm
+has been started.
+.It Fl ssi_ext Ar list
+Comma separated list of SSI extensions. Default: "shtml,shtm".
+.It Fl ssl_cert Ar pem_file
+Location of SSL certificate file. Default: not set.
+.It Fl uid Ar login
+Switch to given user after startup. Default: not set.
+.El
+.Pp
+.Sh EMBEDDING
+.Nm
+was designed to be embeddable into C/C++ applications. Since the
+source code is contained in single C file, it is fairly easy to embed it,
+and to follow the updates. Please refer to http://code.google.com/p/mongoose
+for details.
+.Pp
+.Sh EXAMPLES
+.Bl -tag -width indent
+.It Nm Fl root Ar /var/www Fl ssl_cert Ar /etc/cert.pem Fl ports Ar 8080,8043s Fl aliases Ar /aa=/tmp,/bb=/etc
+Start listening on port 8080 for HTTP, and 8043 for HTTPS connections.
+Use /etc/cert.pem as SSL certificate file. Web root is /var/www. In addition,
+map directory /tmp to URI /aa, directory /etc to URI /bb.
+.It Nm Fl acl Ar -0.0.0.0/0,+10.0.0.0/8,+1.2.3.4
+Deny connections from everywhere, allow only IP address 1.2.3.4 and
+all IP addresses from 10.0.0.0/8 subnet to connect.
+.It Nm Fl admin_uri Ar /ctl Fl protect Ar /ctl=/tmp/passwords.txt
+Create an administrative URI "/ctl" where
+options may be changed at runtime, and protect that URI with authorization.
+.El
+.Pp
+.Sh COPYRIGHT
+.Nm
+is licensed under the terms of the MIT license.
+.Sh AUTHOR
+.An Sergey Lyubka Aq valenok@gmail.com .
diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c
new file mode 100644
index 0000000000..f863847491
--- /dev/null
+++ b/cpukit/mghttpd/mongoose.c
@@ -0,0 +1,4739 @@
+/*
+ * Copyright (c) 2004-2009 Sergey Lyubka
+ * Portions Copyright (c) 2009 Gilbert Wellisch
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(_WIN32)
+#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */
+#endif /* _WIN32 */
+
+#ifndef _WIN32_WCE /* Some ANSI #includes are not available on Windows CE */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <signal.h>
+#include <fcntl.h>
+#endif /* !_WIN32_WCE */
+
+#include <time.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#if defined(_WIN32) /* Windows specific #includes and #defines */
+#define _WIN32_WINNT 0x0400 /* To make it link in VS2005 */
+#include <windows.h>
+
+#ifndef _WIN32_WCE
+#include <process.h>
+#include <direct.h>
+#include <io.h>
+#else /* _WIN32_WCE */
+/* Windows CE-specific definitions */
+#include <winsock2.h>
+#define NO_CGI /* WinCE has no pipes */
+#define NO_SSI /* WinCE has no pipes */
+
+#define FILENAME_MAX MAX_PATH
+#define BUFSIZ 4096
+typedef long off_t;
+
+#define errno GetLastError()
+#define strerror(x) _ultoa(x, (char *) _alloca(sizeof(x) *3 ), 10)
+#endif /* _WIN32_WCE */
+
+#define EPOCH_DIFF 0x019DB1DED53E8000 /* 116444736000000000 nsecs */
+#define RATE_DIFF 10000000 /* 100 nsecs */
+#define MAKEUQUAD(lo, hi) ((uint64_t)(((uint32_t)(lo)) | \
+ ((uint64_t)((uint32_t)(hi))) << 32))
+#define SYS2UNIX_TIME(lo, hi) \
+ (time_t) ((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF)
+
+/*
+ * Visual Studio 6 does not know __func__ or __FUNCTION__
+ * The rest of MS compilers use __FUNCTION__, not C99 __func__
+ * Also use _strtoui64 on modern M$ compilers
+ */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define STRX(x) #x
+#define STR(x) STRX(x)
+#define __func__ "line " STR(__LINE__)
+#define strtoull(x, y, z) strtoul(x, y, z)
+#else
+#define __func__ __FUNCTION__
+#define strtoull(x, y, z) _strtoui64(x, y, z)
+#endif /* _MSC_VER */
+
+#define ERRNO GetLastError()
+#define NO_SOCKLEN_T
+#define SSL_LIB "ssleay32.dll"
+#define CRYPTO_LIB "libeay32.dll"
+#define DIRSEP '\\'
+#define IS_DIRSEP_CHAR(c) ((c) == '/' || (c) == '\\')
+#define O_NONBLOCK 0
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define _POSIX_
+#define INT64_FMT "I64"
+
+#define SHUT_WR 1
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#define sleep(x) Sleep((x) * 1000)
+
+#define popen(x, y) _popen(x, y)
+#define pclose(x) _pclose(x)
+#define close(x) _close(x)
+#define dlsym(x,y) GetProcAddress((HINSTANCE) (x), (y))
+#define RTLD_LAZY 0
+#define fseeko(x, y, z) fseek((x), (y), (z))
+#define fdopen(x, y) _fdopen((x), (y))
+#define write(x, y, z) _write((x), (y), (unsigned) z)
+#define read(x, y, z) _read((x), (y), (unsigned) z)
+#define flockfile(x) (void) 0
+#define funlockfile(x) (void) 0
+
+#if !defined(fileno)
+#define fileno(x) _fileno(x)
+#endif /* !fileno MINGW #defines fileno */
+
+typedef HANDLE pthread_mutex_t;
+typedef HANDLE pthread_cond_t;
+typedef DWORD pthread_t;
+#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
+
+struct timespec {
+ long tv_nsec;
+ long tv_sec;
+};
+
+static int pthread_mutex_lock(pthread_mutex_t *);
+static int pthread_mutex_unlock(pthread_mutex_t *);
+
+#if defined(HAVE_STDINT)
+#include <stdint.h>
+#else
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t;
+typedef unsigned __int64 uint64_t;
+typedef __int64 int64_t;
+#define INT64_MAX 9223372036854775807
+#endif /* HAVE_STDINT */
+
+/*
+ * POSIX dirent interface
+ */
+struct dirent {
+ char d_name[FILENAME_MAX];
+};
+
+typedef struct DIR {
+ HANDLE handle;
+ WIN32_FIND_DATAW info;
+ struct dirent result;
+} DIR;
+
+#else /* UNIX specific */
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/select.h>
+#if HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+#if defined(__rtems__)
+#define flockfile(x) (void) 0
+#define funlockfile(x) (void) 0
+#endif
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#include <pwd.h>
+#include <unistd.h>
+#include <dirent.h>
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+#include <pthread.h>
+#define SSL_LIB "libssl.so"
+#define CRYPTO_LIB "libcrypto.so"
+#define DIRSEP '/'
+#define IS_DIRSEP_CHAR(c) ((c) == '/')
+#define O_BINARY 0
+#define closesocket(a) close(a)
+#define mg_fopen(x, y) fopen(x, y)
+#define mg_mkdir(x, y) mkdir(x, y)
+#define mg_remove(x) remove(x)
+#define mg_rename(x, y) rename(x, y)
+#define ERRNO errno
+#define INVALID_SOCKET (-1)
+#define INT64_FMT PRId64
+typedef int SOCKET;
+
+#endif /* End of Windows and UNIX specific includes */
+
+#include "mongoose.h"
+
+#define MONGOOSE_VERSION "2.9"
+#define PASSWORDS_FILE_NAME ".htpasswd"
+#define CGI_ENVIRONMENT_SIZE 4096
+#define MAX_CGI_ENVIR_VARS 64
+#define MAX_REQUEST_SIZE 8192
+#define MAX_LISTENING_SOCKETS 10
+#define MAX_CALLBACKS 20
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+#define DEBUG_MGS_PREFIX "*** Mongoose debug *** "
+
+#if defined(DEBUG)
+#define DEBUG_TRACE(x) do {printf x; putchar('\n'); fflush(stdout);} while (0)
+#else
+#define DEBUG_TRACE(x)
+#endif /* DEBUG */
+
+/*
+ * Darwin prior to 7.0 and Win32 do not have socklen_t
+ */
+#ifdef NO_SOCKLEN_T
+typedef int socklen_t;
+#endif /* NO_SOCKLEN_T */
+
+#if !defined(FALSE)
+enum {FALSE, TRUE};
+#endif /* !FALSE */
+
+typedef int bool_t;
+typedef void * (*mg_thread_func_t)(void *);
+
+static const char *http_500_error = "Internal Server Error";
+
+/*
+ * Snatched from OpenSSL includes. I put the prototypes here to be independent
+ * from the OpenSSL source installation. Having this, mongoose + SSL can be
+ * built on any system with binary SSL libraries installed.
+ */
+typedef struct ssl_st SSL;
+typedef struct ssl_method_st SSL_METHOD;
+typedef struct ssl_ctx_st SSL_CTX;
+
+#define SSL_ERROR_WANT_READ 2
+#define SSL_ERROR_WANT_WRITE 3
+#define SSL_FILETYPE_PEM 1
+#define CRYPTO_LOCK 1
+
+/*
+ * Dynamically loaded SSL functionality
+ */
+struct ssl_func {
+ const char *name; /* SSL function name */
+ void (*ptr)(void); /* Function pointer */
+};
+
+#define SSL_free(x) (* (void (*)(SSL *)) ssl_sw[0].ptr)(x)
+#define SSL_accept(x) (* (int (*)(SSL *)) ssl_sw[1].ptr)(x)
+#define SSL_connect(x) (* (int (*)(SSL *)) ssl_sw[2].ptr)(x)
+#define SSL_read(x,y,z) (* (int (*)(SSL *, void *, int)) \
+ ssl_sw[3].ptr)((x),(y),(z))
+#define SSL_write(x,y,z) (* (int (*)(SSL *, const void *,int)) \
+ ssl_sw[4].ptr)((x), (y), (z))
+#define SSL_get_error(x,y)(* (int (*)(SSL *, int)) ssl_sw[5])((x), (y))
+#define SSL_set_fd(x,y) (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr)((x), (y))
+#define SSL_new(x) (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)(x)
+#define SSL_CTX_new(x) (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)(x)
+#define SSLv23_server_method() (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr)()
+#define SSL_library_init() (* (int (*)(void)) ssl_sw[10].ptr)()
+#define SSL_CTX_use_PrivateKey_file(x,y,z) (* (int (*)(SSL_CTX *, \
+ const char *, int)) ssl_sw[11].ptr)((x), (y), (z))
+#define SSL_CTX_use_certificate_file(x,y,z) (* (int (*)(SSL_CTX *, \
+ const char *, int)) ssl_sw[12].ptr)((x), (y), (z))
+#define SSL_CTX_set_default_passwd_cb(x,y) \
+ (* (void (*)(SSL_CTX *, mg_spcb_t)) ssl_sw[13].ptr)((x),(y))
+#define SSL_CTX_free(x) (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr)(x)
+
+#define CRYPTO_num_locks() (* (int (*)(void)) crypto_sw[0].ptr)()
+#define CRYPTO_set_locking_callback(x) \
+ (* (void (*)(void (*)(int, int, const char *, int))) \
+ crypto_sw[1].ptr)(x)
+#define CRYPTO_set_id_callback(x) \
+ (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr)(x)
+
+/*
+ * set_ssl_option() function when called, updates this array.
+ * It loads SSL library dynamically and changes NULLs to the actual addresses
+ * of respective functions. The macros above (like SSL_connect()) are really
+ * just calling these functions indirectly via the pointer.
+ */
+static struct ssl_func ssl_sw[] = {
+ {"SSL_free", NULL},
+ {"SSL_accept", NULL},
+ {"SSL_connect", NULL},
+ {"SSL_read", NULL},
+ {"SSL_write", NULL},
+ {"SSL_get_error", NULL},
+ {"SSL_set_fd", NULL},
+ {"SSL_new", NULL},
+ {"SSL_CTX_new", NULL},
+ {"SSLv23_server_method", NULL},
+ {"SSL_library_init", NULL},
+ {"SSL_CTX_use_PrivateKey_file", NULL},
+ {"SSL_CTX_use_certificate_file",NULL},
+ {"SSL_CTX_set_default_passwd_cb",NULL},
+ {"SSL_CTX_free", NULL},
+ {NULL, NULL}
+};
+
+#if !defined(NO_SSL)
+/*
+ * Similar array as ssl_sw. These functions are located in different lib.
+ */
+static struct ssl_func crypto_sw[] = {
+ {"CRYPTO_num_locks", NULL},
+ {"CRYPTO_set_locking_callback", NULL},
+ {"CRYPTO_set_id_callback", NULL},
+ {NULL, NULL}
+};
+#endif
+
+/*
+ * Month names
+ */
+static const char *month_names[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+/*
+ * Unified socket address. For IPv6 support, add IPv6 address structure
+ * in the union u.
+ */
+struct usa {
+ socklen_t len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ } u;
+};
+
+/*
+ * Specifies a string (chunk of memory).
+ * Used to traverse comma separated lists of options.
+ */
+struct vec {
+ const char *ptr;
+ size_t len;
+};
+
+/*
+ * Structure used by mg_stat() function. Uses 64 bit file length.
+ */
+struct mgstat {
+ bool_t is_directory; /* Directory marker */
+ int64_t size; /* File size */
+ time_t mtime; /* Modification time */
+};
+
+struct mg_option {
+ const char *name;
+ const char *description;
+ const char *default_value;
+ int index;
+ bool_t (*setter)(struct mg_context *, const char *);
+};
+
+/*
+ * Numeric indexes for the option values in context, ctx->options
+ */
+enum mg_option_index {
+ OPT_ROOT, OPT_INDEX_FILES, OPT_PORTS, OPT_DIR_LIST, OPT_CGI_EXTENSIONS,
+ OPT_CGI_INTERPRETER, OPT_CGI_ENV, OPT_SSI_EXTENSIONS, OPT_AUTH_DOMAIN,
+ OPT_AUTH_GPASSWD, OPT_AUTH_PUT, OPT_ACCESS_LOG, OPT_ERROR_LOG,
+ OPT_SSL_CERTIFICATE, OPT_ALIASES, OPT_ACL, OPT_UID, OPT_PROTECT,
+ OPT_SERVICE, OPT_HIDE, OPT_ADMIN_URI, OPT_MAX_THREADS, OPT_IDLE_TIME,
+ OPT_MIME_TYPES,
+ NUM_OPTIONS
+};
+
+/*
+ * Structure used to describe listening socket, or socket which was
+ * accept()-ed by the master thread and queued for future handling
+ * by the worker thread.
+ */
+struct socket {
+ SOCKET sock; /* Listening socket */
+ struct usa lsa; /* Local socket address */
+ struct usa rsa; /* Remote socket address */
+ bool_t is_ssl; /* Is socket SSL-ed */
+};
+
+/*
+ * Callback function, and where it is bound to
+ */
+struct callback {
+ char *uri_regex; /* URI regex to handle */
+ mg_callback_t func; /* user callback */
+ bool_t is_auth; /* func is auth checker */
+ int status_code; /* error code to handle */
+ void *user_data; /* opaque user data */
+};
+
+/*
+ * Mongoose context
+ */
+struct mg_context {
+ int stop_flag; /* Should we stop event loop */
+ SSL_CTX *ssl_ctx; /* SSL context */
+
+ FILE *access_log; /* Opened access log */
+ FILE *error_log; /* Opened error log */
+
+ struct socket listeners[MAX_LISTENING_SOCKETS];
+ int num_listeners;
+
+ struct callback callbacks[MAX_CALLBACKS];
+ int num_callbacks;
+
+ char *options[NUM_OPTIONS]; /* Configured opions */
+ pthread_mutex_t opt_mutex[NUM_OPTIONS]; /* Option protector */
+
+ int max_threads; /* Maximum number of threads */
+ int num_threads; /* Number of threads */
+ int num_idle; /* Number of idle threads */
+ pthread_mutex_t thr_mutex; /* Protects (max|num)_threads */
+ pthread_cond_t thr_cond;
+ pthread_mutex_t bind_mutex; /* Protects bind operations */
+
+ struct socket queue[20]; /* Accepted sockets */
+ int sq_head; /* Head of the socket queue */
+ int sq_tail; /* Tail of the socket queue */
+ pthread_cond_t empty_cond; /* Socket queue empty condvar */
+ pthread_cond_t full_cond; /* Socket queue full condvar */
+
+ mg_spcb_t ssl_password_callback;
+ mg_callback_t log_callback;
+};
+
+/*
+ * Client connection.
+ */
+struct mg_connection {
+ struct mg_request_info request_info;
+ struct mg_context *ctx; /* Mongoose context we belong to*/
+ SSL *ssl; /* SSL descriptor */
+ struct socket client; /* Connected client */
+ time_t birth_time; /* Time connection was accepted */
+ bool_t free_post_data; /* post_data was malloc-ed */
+ bool_t embedded_auth; /* Used for authorization */
+ int64_t num_bytes_sent; /* Total bytes sent to client */
+};
+
+/*
+ * Print error message to the opened error log stream.
+ */
+static void
+cry(struct mg_connection *conn, const char *fmt, ...)
+{
+ char buf[BUFSIZ];
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void) vsnprintf(buf, sizeof(buf), fmt, ap);
+ conn->ctx->log_callback(conn, &conn->request_info, buf);
+ va_end(ap);
+}
+
+/*
+ * Return fake connection structure. Used for logging, if connection
+ * is not applicable at the moment of logging.
+ */
+static struct mg_connection *
+fc(struct mg_context *ctx)
+{
+ static struct mg_connection fake_connection;
+ fake_connection.ctx = ctx;
+ return (&fake_connection);
+}
+
+/*
+ * If an embedded code does not intercept logging by calling
+ * mg_set_log_callback(), this function is used for logging. It prints
+ * stuff to the conn->error_log, which is stderr unless "error_log"
+ * option was set.
+ */
+static void
+builtin_error_log(struct mg_connection *conn,
+ const struct mg_request_info *request_info, void *message)
+{
+ FILE *fp;
+ time_t timestamp;
+
+ fp = conn->ctx->error_log;
+ flockfile(fp);
+
+ timestamp = time(NULL);
+
+ (void) fprintf(fp,
+ "[%010lu] [error] [client %s] ",
+ (unsigned long) timestamp,
+ inet_ntoa(conn->client.rsa.u.sin.sin_addr));
+
+ if (request_info->request_method != NULL)
+ (void) fprintf(fp, "%s %s: ",
+ request_info->request_method,
+ request_info->uri);
+
+ (void) fprintf(fp, "%s", (char *) message);
+
+ fputc('\n', fp);
+
+ funlockfile(fp);
+}
+
+const char *
+mg_version(void)
+{
+ return (MONGOOSE_VERSION);
+}
+
+static void
+mg_strlcpy(register char *dst, register const char *src, size_t n)
+{
+ for (; *src != '\0' && n > 1; n--)
+ *dst++ = *src++;
+ *dst = '\0';
+}
+
+static int
+lowercase(const char *s)
+{
+ return (tolower(* (unsigned char *) s));
+}
+
+static int
+mg_strncasecmp(const char *s1, const char *s2, size_t len)
+{
+ int diff = 0;
+
+ if (len > 0)
+ do {
+ diff = lowercase(s1++) - lowercase(s2++);
+ } while (diff == 0 && s1[-1] != '\0' && --len > 0);
+
+ return (diff);
+}
+
+static int
+mg_strcasecmp(const char *s1, const char *s2)
+{
+ int diff;
+
+ do {
+ diff = lowercase(s1++) - lowercase(s2++);
+ } while (diff == 0 && s1[-1] != '\0');
+
+ return (diff);
+}
+
+static char *
+mg_strndup(const char *ptr, size_t len)
+{
+ char *p;
+
+ if ((p = (char *) malloc(len + 1)) != NULL)
+ mg_strlcpy(p, ptr, len + 1);
+
+ return (p);
+
+}
+
+static char *
+mg_strdup(const char *str)
+{
+ return (mg_strndup(str, strlen(str)));
+}
+
+/*
+ * Like snprintf(), but never returns negative value, or the value
+ * that is larger than a supplied buffer.
+ * Thanks to Adam Zeldis to pointing snprintf()-caused vulnerability
+ * in his audit report.
+ */
+static int
+mg_vsnprintf(struct mg_connection *conn,
+ char *buf, size_t buflen, const char *fmt, va_list ap)
+{
+ int n;
+
+ if (buflen == 0)
+ return (0);
+
+ n = vsnprintf(buf, buflen, fmt, ap);
+
+ if (n < 0) {
+ cry(conn, "vsnprintf error");
+ n = 0;
+ } else if (n >= (int) buflen) {
+ cry(conn, "truncating vsnprintf buffer: [%.*s]",
+ n > 200 ? 200 : n, buf);
+ n = (int) buflen - 1;
+ }
+ buf[n] = '\0';
+
+ return (n);
+}
+
+static int
+mg_snprintf(struct mg_connection *conn,
+ char *buf, size_t buflen, const char *fmt, ...)
+{
+ va_list ap;
+ int n;
+
+ va_start(ap, fmt);
+ n = mg_vsnprintf(conn, buf, buflen, fmt, ap);
+ va_end(ap);
+
+ return (n);
+}
+
+/*
+ * Convert string representing a boolean value to a boolean value
+ */
+static bool_t
+is_true(const char *str)
+{
+ static const char *trues[] = {"1", "yes", "true", "ja", NULL};
+ int i;
+
+ for (i = 0; trues[i] != NULL; i++)
+ if (str != NULL && mg_strcasecmp(str, trues[i]) == 0)
+ return (TRUE);
+
+ return (FALSE);
+}
+
+/*
+ * Skip the characters until one of the delimiters characters found.
+ * 0-terminate resulting word. Skip the rest of the delimiters if any.
+ * Advance pointer to buffer to the next word. Return found 0-terminated word.
+ */
+static char *
+skip(char **buf, const char *delimiters)
+{
+ char *p, *begin_word, *end_word, *end_delimiters;
+
+ begin_word = *buf;
+ end_word = begin_word + strcspn(begin_word, delimiters);
+ end_delimiters = end_word + strspn(end_word, delimiters);
+
+ for (p = end_word; p < end_delimiters; p++)
+ *p = '\0';
+
+ *buf = end_delimiters;
+
+ return (begin_word);
+}
+
+/*
+ * Return HTTP header value, or NULL if not found.
+ */
+static const char *
+get_header(const struct mg_request_info *ri, const char *name)
+{
+ int i;
+
+ for (i = 0; i < ri->num_headers; i++)
+ if (!mg_strcasecmp(name, ri->http_headers[i].name))
+ return (ri->http_headers[i].value);
+
+ return (NULL);
+}
+
+const char *
+mg_get_header(const struct mg_connection *conn, const char *name)
+{
+ return (get_header(&conn->request_info, name));
+}
+
+/*
+ * A helper function for traversing comma separated list of values.
+ * It returns a list pointer shifted to the next value, of NULL if the end
+ * of the list found.
+ * Value is stored in val vector. If value has form "x=y", then eq_val
+ * vector is initialized to point to the "y" part, and val vector length
+ * is adjusted to point only to "x".
+ */
+static const char *
+next_option(const char *list, struct vec *val, struct vec *eq_val)
+{
+ if (list == NULL || *list == '\0') {
+ /* End of the list */
+ list = NULL;
+ } else {
+ val->ptr = list;
+ if ((list = strchr(val->ptr, ',')) != NULL) {
+ /* Comma found. Store length and shift the list ptr */
+ val->len = list - val->ptr;
+ list++;
+ } else {
+ /* This value is the last one */
+ list = val->ptr + strlen(val->ptr);
+ val->len = list - val->ptr;
+ }
+
+ if (eq_val != NULL) {
+ /*
+ * Value has form "x=y", adjust pointers and lengths
+ * so that val points to "x", and eq_val points to "y".
+ */
+ eq_val->len = 0;
+ eq_val->ptr = memchr(val->ptr, '=', val->len);
+ if (eq_val->ptr != NULL) {
+ eq_val->ptr++; /* Skip over '=' character */
+ eq_val->len = val->ptr + val->len - eq_val->ptr;
+ val->len = (eq_val->ptr - val->ptr) - 1;
+ }
+ }
+ }
+
+ return (list);
+}
+
+#if !(defined(NO_CGI) && defined(NO_SSI))
+/*
+ * Verify that given file has certain extension
+ */
+static bool_t
+match_extension(const char *path, const char *ext_list)
+{
+ struct vec ext_vec;
+ size_t path_len;
+
+ path_len = strlen(path);
+
+ while ((ext_list = next_option(ext_list, &ext_vec, NULL)) != NULL)
+ if (ext_vec.len < path_len &&
+ mg_strncasecmp(path + path_len - ext_vec.len,
+ ext_vec.ptr, ext_vec.len) == 0)
+ return (TRUE);
+
+ return (FALSE);
+}
+#endif /* !(NO_CGI && NO_SSI) */
+
+/*
+ * Return TRUE if "uri" matches "regexp".
+ * '*' in the regexp means zero or more characters.
+ */
+static bool_t
+match_regex(const char *uri, const char *regexp)
+{
+ if (*regexp == '\0')
+ return (*uri == '\0');
+
+ if (*regexp == '*')
+ do {
+ if (match_regex(uri, regexp + 1))
+ return (TRUE);
+ } while (*uri++ != '\0');
+
+ if (*uri != '\0' && *regexp == *uri)
+ return (match_regex(uri + 1, regexp + 1));
+
+ return (FALSE);
+}
+
+static const struct callback *
+find_callback(struct mg_context *ctx, bool_t is_auth,
+ const char *uri, int status_code)
+{
+ const struct callback *cb, *found;
+ int i;
+
+ found = NULL;
+ pthread_mutex_lock(&ctx->bind_mutex);
+ for (i = 0; i < ctx->num_callbacks; i++) {
+ cb = ctx->callbacks + i;
+ if ((uri != NULL && cb->uri_regex != NULL &&
+ ((is_auth && cb->is_auth) || (!is_auth && !cb->is_auth)) &&
+ match_regex(uri, cb->uri_regex)) || (uri == NULL &&
+ (cb->status_code == 0 ||
+ cb->status_code == status_code))) {
+ found = cb;
+ break;
+ }
+ }
+ pthread_mutex_unlock(&ctx->bind_mutex);
+
+ return (found);
+}
+
+/*
+ * For use by external application. This sets custom logging function.
+ */
+void
+mg_set_log_callback(struct mg_context *ctx, mg_callback_t log_callback)
+{
+ /* If NULL is specified as a callback, revert back to the default */
+ if (log_callback == NULL)
+ ctx->log_callback = &builtin_error_log;
+ else
+ ctx->log_callback = log_callback;
+}
+
+/*
+ * Send error message back to the client.
+ */
+static void
+send_error(struct mg_connection *conn, int status, const char *reason,
+ const char *fmt, ...)
+{
+ const struct callback *cb;
+ char buf[BUFSIZ];
+ va_list ap;
+ int len;
+
+ conn->request_info.status_code = status;
+
+ /* If error handler is set, call it. Otherwise, send error message */
+ if ((cb = find_callback(conn->ctx, FALSE, NULL, status)) != NULL) {
+ cb->func(conn, &conn->request_info, cb->user_data);
+ } else {
+ buf[0] = '\0';
+ len = 0;
+
+ /* Errors 1xx, 204 and 304 MUST NOT send a body */
+ if (status > 199 && status != 204 && status != 304) {
+ len = mg_snprintf(conn, buf, sizeof(buf),
+ "Error %d: %s\n", status, reason);
+ cry(conn, "%s", buf);
+
+ va_start(ap, fmt);
+ len += mg_vsnprintf(conn, buf + len, sizeof(buf) - len,
+ fmt, ap);
+ va_end(ap);
+ conn->num_bytes_sent = len;
+ }
+
+ (void) mg_printf(conn,
+ "HTTP/1.1 %d %s\r\n"
+ "Content-Type: text/plain\r\n"
+ "Content-Length: %d\r\n"
+ "Connection: close\r\n"
+ "\r\n%s", status, reason, len, buf);
+ }
+}
+
+#ifdef _WIN32
+static int
+pthread_mutex_init(pthread_mutex_t *mutex, void *unused)
+{
+ unused = NULL;
+ *mutex = CreateMutex(NULL, FALSE, NULL);
+ return (*mutex == NULL ? -1 : 0);
+}
+
+static int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ return (CloseHandle(*mutex) == 0 ? -1 : 0);
+}
+
+static int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ return (WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0? 0 : -1);
+}
+
+static int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ return (ReleaseMutex(*mutex) == 0 ? -1 : 0);
+}
+
+static int
+pthread_cond_init(pthread_cond_t *cv, const void *unused)
+{
+ unused = NULL;
+ *cv = CreateEvent(NULL, FALSE, FALSE, NULL);
+ return (*cv == NULL ? -1 : 0);
+}
+
+static int
+pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex,
+ const struct timespec *ts)
+{
+ DWORD status;
+ DWORD msec = INFINITE;
+ time_t now;
+
+ if (ts != NULL) {
+ now = time(NULL);
+ msec = 1000 * (now > ts->tv_sec ? 0 : ts->tv_sec - now);
+ }
+
+ (void) ReleaseMutex(*mutex);
+ status = WaitForSingleObject(*cv, msec);
+ (void) WaitForSingleObject(*mutex, INFINITE);
+
+ return (status == WAIT_OBJECT_0 ? 0 : -1);
+}
+
+static int
+pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex)
+{
+ return (pthread_cond_timedwait(cv, mutex, NULL));
+}
+
+static int
+pthread_cond_signal(pthread_cond_t *cv)
+{
+ return (SetEvent(*cv) == 0 ? -1 : 0);
+}
+
+static int
+pthread_cond_destroy(pthread_cond_t *cv)
+{
+ return (CloseHandle(*cv) == 0 ? -1 : 0);
+}
+
+static pthread_t
+pthread_self(void)
+{
+ return (GetCurrentThreadId());
+}
+
+/*
+ * Change all slashes to backslashes. It is Windows.
+ */
+static void
+fix_directory_separators(char *path)
+{
+ int i;
+
+ for (i = 0; path[i] != '\0'; i++) {
+ if (path[i] == '/')
+ path[i] = '\\';
+ /* i > 0 check is to preserve UNC paths, \\server\file.txt */
+ if (path[i] == '\\' && i > 0)
+ while (path[i + 1] == '\\' || path[i + 1] == '/')
+ (void) memmove(path + i + 1,
+ path + i + 2, strlen(path + i + 1));
+ }
+}
+
+/*
+ * Encode 'path' which is assumed UTF-8 string, into UNICODE string.
+ * wbuf and wbuf_len is a target buffer and its length.
+ */
+static void
+to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len)
+{
+ char buf[FILENAME_MAX], *p;
+
+ mg_strlcpy(buf, path, sizeof(buf));
+ fix_directory_separators(buf);
+
+ /* Point p to the end of the file name */
+ p = buf + strlen(buf) - 1;
+
+ /* Trim trailing backslash character */
+ while (p > buf && *p == '\\' && p[-1] != ':')
+ *p-- = '\0';
+
+ /*
+ * Protect from CGI code disclosure.
+ * This is very nasty hole. Windows happily opens files with
+ * some garbage in the end of file name. So fopen("a.cgi ", "r")
+ * actually opens "a.cgi", and does not return an error!
+ */
+ if (*p == 0x20 || /* No space at the end */
+ (*p == 0x2e && p > buf) || /* No '.' but allow '.' as full path */
+ *p == 0x2b || /* No '+' */
+ (*p & ~0x7f)) { /* And generally no non-ascii chars */
+ (void) fprintf(stderr, "Rejecting suspicious path: [%s]", buf);
+ buf[0] = '\0';
+ }
+
+ (void) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
+}
+
+#if defined(_WIN32_WCE)
+
+static time_t
+time(time_t *ptime)
+{
+ time_t t;
+ SYSTEMTIME st;
+ FILETIME ft;
+
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, &ft);
+ t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime);
+
+ if (ptime != NULL)
+ *ptime = t;
+
+ return (t);
+}
+
+static time_t
+mktime(struct tm *ptm)
+{
+ SYSTEMTIME st;
+ FILETIME ft, lft;
+
+ st.wYear = ptm->tm_year + 1900;
+ st.wMonth = ptm->tm_mon + 1;
+ st.wDay = ptm->tm_mday;
+ st.wHour = ptm->tm_hour;
+ st.wMinute = ptm->tm_min;
+ st.wSecond = ptm->tm_sec;
+ st.wMilliseconds = 0;
+
+ SystemTimeToFileTime(&st, &ft);
+ LocalFileTimeToFileTime(&ft, &lft);
+ return (time_t)((MAKEUQUAD(lft.dwLowDateTime, lft.dwHighDateTime) -
+ EPOCH_DIFF) / RATE_DIFF);
+}
+
+static struct tm *
+localtime(const time_t *ptime, struct tm *ptm)
+{
+ int64_t t = ((int64_t)*ptime) * RATE_DIFF + EPOCH_DIFF;
+ FILETIME ft, lft;
+ SYSTEMTIME st;
+ TIME_ZONE_INFORMATION tzinfo;
+
+ if (ptm == NULL)
+ return NULL;
+
+ * (int64_t *) &ft = t;
+ FileTimeToLocalFileTime(&ft, &lft);
+ FileTimeToSystemTime(&lft, &st);
+ ptm->tm_year = st.wYear - 1900;
+ ptm->tm_mon = st.wMonth - 1;
+ ptm->tm_wday = st.wDayOfWeek;
+ ptm->tm_mday = st.wDay;
+ ptm->tm_hour = st.wHour;
+ ptm->tm_min = st.wMinute;
+ ptm->tm_sec = st.wSecond;
+ ptm->tm_yday = 0; // hope nobody uses this
+ ptm->tm_isdst = ((GetTimeZoneInformation(&tzinfo) ==
+ TIME_ZONE_ID_DAYLIGHT) ? 1 : 0);
+
+ return ptm;
+}
+
+static size_t
+strftime(char *dst, size_t dst_size, const char *fmt, const struct tm *tm)
+{
+ (void) snprintf(dst, dst_size, "implement strftime() for WinCE");
+ return (0);
+}
+#endif
+
+static int
+mg_rename(const char* oldname, const char* newname)
+{
+ wchar_t woldbuf[FILENAME_MAX];
+ wchar_t wnewbuf[FILENAME_MAX];
+
+ to_unicode(oldname, woldbuf, ARRAY_SIZE(woldbuf));
+ to_unicode(newname, wnewbuf, ARRAY_SIZE(wnewbuf));
+
+ return (MoveFileW(woldbuf, wnewbuf) ? 0 : -1);
+}
+
+
+static FILE *
+mg_fopen(const char *path, const char *mode)
+{
+ wchar_t wbuf[FILENAME_MAX], wmode[20];
+
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+ MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, ARRAY_SIZE(wmode));
+
+ return (_wfopen(wbuf, wmode));
+}
+
+static int
+mg_stat(const char *path, struct mgstat *stp)
+{
+ int ok = -1; /* Error */
+ wchar_t wbuf[FILENAME_MAX];
+ WIN32_FILE_ATTRIBUTE_DATA info;
+
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+
+ if (GetFileAttributesExW(wbuf, GetFileExInfoStandard, &info) != 0) {
+ stp->size = MAKEUQUAD(info.nFileSizeLow, info.nFileSizeHigh);
+ stp->mtime = SYS2UNIX_TIME(info.ftLastWriteTime.dwLowDateTime,
+ info.ftLastWriteTime.dwHighDateTime);
+ stp->is_directory =
+ info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+ ok = 0; /* Success */
+ }
+
+ return (ok);
+}
+
+static int
+mg_remove(const char *path)
+{
+ wchar_t wbuf[FILENAME_MAX];
+
+ to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
+
+ return (DeleteFileW(wbuf) ? 0 : -1);
+}
+
+static int
+mg_mkdir(const char *path, int mode)
+{
+ char buf[FILENAME_MAX];
+ wchar_t wbuf[FILENAME_MAX];
+
+ mode = 0; /* Unused */
+ mg_strlcpy(buf, path, sizeof(buf));
+ fix_directory_separators(buf);
+
+ (void) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf));
+
+ return (CreateDirectoryW(wbuf, NULL) ? 0 : -1);
+}
+
+/*
+ * Implementation of POSIX opendir/closedir/readdir for Windows.
+ */
+static DIR *
+opendir(const char *name)
+{
+ DIR *dir = NULL;
+ wchar_t wpath[FILENAME_MAX];
+ DWORD attrs;
+
+ if (name == NULL) {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ } else if ((dir = (DIR *) malloc(sizeof(*dir))) == NULL) {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ } else {
+ to_unicode(name, wpath, ARRAY_SIZE(wpath));
+ attrs = GetFileAttributesW(wpath);
+ if (attrs != 0xFFFFFFFF &&
+ ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
+ (void) wcscat(wpath, L"\\*");
+ dir->handle = FindFirstFileW(wpath, &dir->info);
+ dir->result.d_name[0] = '\0';
+ } else {
+ free(dir);
+ dir = NULL;
+ }
+ }
+
+ return (dir);
+}
+
+static int
+closedir(DIR *dir)
+{
+ int result = 0;
+
+ if (dir != NULL) {
+ if (dir->handle != INVALID_HANDLE_VALUE)
+ result = FindClose(dir->handle) ? 0 : -1;
+
+ free(dir);
+ } else {
+ result = -1;
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ }
+
+ return (result);
+}
+
+struct dirent *
+readdir(DIR *dir)
+{
+ struct dirent *result = 0;
+
+ if (dir) {
+ if (dir->handle != INVALID_HANDLE_VALUE) {
+ result = &dir->result;
+ (void) WideCharToMultiByte(CP_UTF8, 0,
+ dir->info.cFileName, -1, result->d_name,
+ sizeof(result->d_name), NULL, NULL);
+
+ if (!FindNextFileW(dir->handle, &dir->info)) {
+ (void) FindClose(dir->handle);
+ dir->handle = INVALID_HANDLE_VALUE;
+ }
+
+ } else {
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ }
+ } else {
+ SetLastError(ERROR_BAD_ARGUMENTS);
+ }
+
+ return (result);
+}
+
+#define set_close_on_exec(fd) /* No FD_CLOEXEC on Windows */
+
+static int
+start_thread(struct mg_context *ctx, mg_thread_func_t func, void *param)
+{
+ HANDLE hThread;
+
+ ctx = NULL; /* Unused */
+
+ hThread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) func, param, 0, NULL);
+
+ if (hThread != NULL)
+ (void) CloseHandle(hThread);
+
+ return (hThread == NULL ? -1 : 0);
+}
+
+static HANDLE
+dlopen(const char *dll_name, int flags)
+{
+ wchar_t wbuf[FILENAME_MAX];
+
+ flags = 0; /* Unused */
+ to_unicode(dll_name, wbuf, ARRAY_SIZE(wbuf));
+
+ return (LoadLibraryW(wbuf));
+}
+
+#if !defined(NO_CGI)
+static int
+kill(pid_t pid, int sig_num)
+{
+ (void) TerminateProcess(pid, sig_num);
+ (void) CloseHandle(pid);
+ return (0);
+}
+
+static pid_t
+spawn_process(struct mg_connection *conn, const char *prog, char *envblk,
+ char *envp[], int fd_stdin, int fd_stdout, const char *dir)
+{
+ HANDLE me;
+ char *p, *interp, cmdline[FILENAME_MAX], line[FILENAME_MAX];
+ FILE *fp;
+ STARTUPINFOA si;
+ PROCESS_INFORMATION pi;
+
+ envp = NULL; /* Unused */
+
+ (void) memset(&si, 0, sizeof(si));
+ (void) memset(&pi, 0, sizeof(pi));
+
+ /* XXX redirect CGI errors to the error log file */
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+
+ me = GetCurrentProcess();
+ (void) DuplicateHandle(me, (HANDLE) _get_osfhandle(fd_stdin), me,
+ &si.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS);
+ (void) DuplicateHandle(me, (HANDLE) _get_osfhandle(fd_stdout), me,
+ &si.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
+
+ /* If CGI file is a script, try to read the interpreter line */
+ interp = conn->ctx->options[OPT_CGI_INTERPRETER];
+ if (interp == NULL) {
+ line[2] = '\0';
+ (void) mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%c%s",
+ dir, DIRSEP, prog);
+ if ((fp = fopen(cmdline, "r")) != NULL) {
+ (void) fgets(line, sizeof(line), fp);
+ if (memcmp(line, "#!", 2) != 0)
+ line[2] = '\0';
+ /* Trim whitespaces from interpreter name */
+ for (p = &line[strlen(line) - 1]; p > line &&
+ isspace(*p); p--)
+ *p = '\0';
+ (void) fclose(fp);
+ }
+ interp = line + 2;
+ }
+
+ if ((p = (char *) strrchr(prog, '/')) != NULL)
+ prog = p + 1;
+
+ (void) mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s%s",
+ interp, interp[0] == '\0' ? "" : " ", prog);
+
+ (void) mg_snprintf(conn, line, sizeof(line), "%s", dir);
+ fix_directory_separators(line);
+
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: Running [%s]", __func__, cmdline));
+ if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE,
+ CREATE_NEW_PROCESS_GROUP, envblk, line, &si, &pi) == 0) {
+ cry(conn, "%s: CreateProcess(%s): %d",
+ __func__, cmdline, ERRNO);
+ pi.hProcess = (pid_t) -1;
+ } else {
+ (void) close(fd_stdin);
+ (void) close(fd_stdout);
+ }
+
+ (void) CloseHandle(si.hStdOutput);
+ (void) CloseHandle(si.hStdInput);
+ (void) CloseHandle(pi.hThread);
+
+ return ((pid_t) pi.hProcess);
+}
+
+static int
+pipe(int *fds)
+{
+ return (_pipe(fds, BUFSIZ, _O_BINARY));
+}
+#endif /* !NO_CGI */
+
+static int
+set_non_blocking_mode(struct mg_connection *conn, SOCKET sock)
+{
+ unsigned long on = 1;
+
+ conn = NULL; /* unused */
+ return (ioctlsocket(sock, FIONBIO, &on));
+}
+
+#else
+
+static int
+mg_stat(const char *path, struct mgstat *stp)
+{
+ struct stat st;
+ int ok;
+
+ if (stat(path, &st) == 0) {
+ ok = 0;
+ stp->size = st.st_size;
+ stp->mtime = st.st_mtime;
+ stp->is_directory = S_ISDIR(st.st_mode);
+ } else {
+ ok = -1;
+ }
+
+ return (ok);
+}
+
+static void
+set_close_on_exec(int fd)
+{
+ (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
+}
+
+static int
+start_thread(struct mg_context *ctx, mg_thread_func_t func, void *param)
+{
+ pthread_t thread_id;
+ pthread_attr_t attr;
+ int retval;
+
+ (void) pthread_attr_init(&attr);
+ (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if ((retval = pthread_create(&thread_id, &attr, func, param)) != 0)
+ cry(fc(ctx), "%s: %s", __func__, strerror(retval));
+
+ return (retval);
+}
+
+#ifndef NO_CGI
+static pid_t
+spawn_process(struct mg_connection *conn, const char *prog, char *envblk,
+ char *envp[], int fd_stdin, int fd_stdout, const char *dir)
+{
+ pid_t pid;
+ const char *interp;
+
+ envblk = NULL; /* unused */
+
+ if ((pid = fork()) == -1) {
+ /* Parent */
+ send_error(conn, 500, http_500_error,
+ "fork(): %s", strerror(ERRNO));
+ } else if (pid == 0) {
+ /* Child */
+ if (chdir(dir) != 0) {
+ cry(conn, "%s: chdir(%s): %s",
+ __func__, dir, strerror(ERRNO));
+ } else if (dup2(fd_stdin, 0) == -1) {
+ cry(conn, "%s: dup2(stdin, %d): %s",
+ __func__, fd_stdin, strerror(ERRNO));
+ } else if (dup2(fd_stdout, 1) == -1) {
+ cry(conn, "%s: dup2(stdout, %d): %s",
+ __func__, fd_stdout, strerror(ERRNO));
+ } else {
+ /* If error file is specified, send errors there */
+ if (conn->ctx->error_log != NULL)
+ (void) dup2(fileno(conn->ctx->error_log), 2);
+
+ (void) close(fd_stdin);
+ (void) close(fd_stdout);
+
+ /* Execute CGI program */
+ interp = conn->ctx->options[OPT_CGI_INTERPRETER];
+ if (interp == NULL) {
+ (void) execle(prog, prog, NULL, envp);
+ cry(conn, "%s: execle(%s): %s",
+ __func__, prog, strerror(ERRNO));
+ } else {
+ (void) execle(interp, interp, prog, NULL, envp);
+ cry(conn, "%s: execle(%s %s): %s",
+ __func__, interp, prog, strerror(ERRNO));
+ }
+ }
+ exit(EXIT_FAILURE);
+ } else {
+ /* Parent. Close stdio descriptors */
+ (void) close(fd_stdin);
+ (void) close(fd_stdout);
+ }
+
+ return (pid);
+}
+#endif /* !NO_CGI */
+
+static int
+set_non_blocking_mode(struct mg_connection *conn, SOCKET sock)
+{
+ int flags, ok = -1;
+
+ if ((flags = fcntl(sock, F_GETFL, 0)) == -1) {
+ cry(conn, "%s: fcntl(F_GETFL): %d", __func__, ERRNO);
+ } else if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) != 0) {
+ cry(conn, "%s: fcntl(F_SETFL): %d", __func__, ERRNO);
+ } else {
+ ok = 0; /* Success */
+ }
+
+ return (ok);
+}
+#endif /* _WIN32 */
+
+static void
+lock_option(struct mg_context *ctx, int opt_index)
+{
+ if (pthread_mutex_lock(&ctx->opt_mutex[opt_index]) != 0)
+ cry(fc(ctx), "pthread_mutex_lock: %s", strerror(ERRNO));
+}
+
+static void
+unlock_option(struct mg_context *ctx, int opt_index)
+{
+ if (pthread_mutex_unlock(&ctx->opt_mutex[opt_index]) != 0)
+ cry(fc(ctx), "pthread_mutex_unlock: %s", strerror(ERRNO));
+}
+
+/*
+ * Write data to the IO channel - opened file descriptor, socket or SSL
+ * descriptor. Return number of bytes written.
+ */
+static int64_t
+push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
+{
+ int64_t sent;
+ int n, k;
+
+ sent = 0;
+ while (sent < len) {
+
+ /* How many bytes we send in this iteration */
+ k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent);
+
+ if (ssl != NULL) {
+ n = SSL_write(ssl, buf + sent, k);
+ } else if (fp != NULL) {
+ n = fwrite(buf + sent, 1, k, fp);
+ if (ferror(fp))
+ n = -1;
+ } else {
+ n = send(sock, buf + sent, k, 0);
+ }
+
+ if (n < 0)
+ break;
+
+ sent += n;
+ }
+
+ return (sent);
+}
+
+/*
+ * Read from IO channel - opened file descriptor, socket, or SSL descriptor.
+ * Return number of bytes read.
+ */
+static int
+pull(FILE *fp, SOCKET sock, SSL *ssl, char *buf, int len)
+{
+ int nread;
+
+ if (ssl != NULL) {
+ nread = SSL_read(ssl, buf, len);
+ } else if (fp != NULL) {
+ nread = fread(buf, 1, (size_t) len, fp);
+ if (ferror(fp))
+ nread = -1;
+ } else {
+ nread = recv(sock, buf, (size_t) len, 0);
+ }
+
+ return (nread);
+}
+
+int
+mg_write(struct mg_connection *conn, const void *buf, int len)
+{
+ assert(len >= 0);
+ return ((int) push(NULL, conn->client.sock, conn->ssl,
+ (const char *) buf, (int64_t) len));
+}
+
+int
+mg_printf(struct mg_connection *conn, const char *fmt, ...)
+{
+ char buf[MAX_REQUEST_SIZE];
+ int len;
+ va_list ap;
+
+ va_start(ap, fmt);
+ len = mg_vsnprintf(conn, buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
+ return (mg_write(conn, buf, len));
+}
+
+/*
+ * Return content length of the request, or -1 constant if
+ * Content-Length header is not set.
+ */
+static int64_t
+get_content_length(const struct mg_connection *conn)
+{
+ const char *cl = mg_get_header(conn, "Content-Length");
+ return (cl == NULL ? -1 : strtoll(cl, NULL, 10));
+}
+
+/*
+ * URL-decode input buffer into destination buffer.
+ * 0-terminate the destination buffer. Return the length of decoded data.
+ * form-url-encoded data differs from URI encoding in a way that it
+ * uses '+' as character for space, see RFC 1866 section 8.2.1
+ * http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
+ */
+static size_t
+url_decode(const char *src, size_t src_len, char *dst, size_t dst_len,
+ bool_t is_form_url_encoded)
+{
+ size_t i, j;
+ int a, b;
+#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
+
+ for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
+ if (src[i] == '%' &&
+ isxdigit(* (unsigned char *) (src + i + 1)) &&
+ isxdigit(* (unsigned char *) (src + i + 2))) {
+ a = tolower(* (unsigned char *) (src + i + 1));
+ b = tolower(* (unsigned char *) (src + i + 2));
+ dst[j] = ((HEXTOI(a) << 4) | HEXTOI(b)) & 0xff;
+ i += 2;
+ } else if (is_form_url_encoded && src[i] == '+') {
+ dst[j] = ' ';
+ } else {
+ dst[j] = src[i];
+ }
+ }
+
+ dst[j] = '\0'; /* Null-terminate the destination */
+
+ return (j);
+}
+
+/*
+ * Search for a form variable in a given buffer.
+ * Semantic is the same as for mg_get_var().
+ */
+static char *
+get_var(const char *name, const char *buf, size_t buf_len)
+{
+ const char *p, *e, *s;
+ char *val;
+ size_t var_len, len;
+
+ var_len = strlen(name);
+ e = buf + buf_len;
+ val = NULL;
+
+ /* buf is "var1=val1&var2=val2...". Find variable first */
+ for (p = buf; p + var_len < e; p++)
+ if ((p == buf || p[-1] == '&') && p[var_len] == '=' &&
+ !mg_strncasecmp(name, p, var_len)) {
+
+ /* Point p to variable value */
+ p += var_len + 1;
+
+ /* Point s to the end of the value */
+ s = (const char *) memchr(p, '&', e - p);
+ if (s == NULL)
+ s = e;
+
+ /* Try to allocate the buffer */
+ len = s - p;
+ if ((val = (char *) malloc(len + 1)) != NULL)
+ (void) url_decode(p, len, val, len + 1, TRUE);
+ break;
+ }
+
+ return (val);
+}
+
+/*
+ * Free the pointer returned by mg_get_var(). This is needed for languages
+ * like python, to have an ability to free allocated data without
+ * loading C runtime library and calling free().
+ */
+void
+mg_free(char *data)
+{
+ free(data);
+}
+
+/*
+ * Return form data variable.
+ * It can be specified in query string, or in the POST data.
+ * Return NULL if the variable not found, or allocated 0-terminated value.
+ * It is caller's responsibility to free the returned value.
+ */
+char *
+mg_get_var(const struct mg_connection *conn, const char *name)
+{
+ const struct mg_request_info *ri = &conn->request_info;
+ char *v1, *v2;
+
+ v1 = v2 = NULL;
+
+ /* Look in both query_string and POST data */
+ if (ri->query_string != NULL)
+ v1 = get_var(name, ri->query_string, strlen(ri->query_string));
+ if (ri->post_data_len > 0)
+ v2 = get_var(name, ri->post_data, ri->post_data_len);
+
+ /* If they both have queried variable, POST data wins */
+ if (v1 != NULL && v2 != NULL)
+ free(v1);
+
+ return (v2 == NULL ? v1 : v2);
+}
+
+/*
+ * Transform URI to the file name.
+ */
+static void
+convert_uri_to_file_name(struct mg_connection *conn, const char *uri,
+ char *buf, size_t buf_len)
+{
+ struct mg_context *ctx = conn->ctx;
+ struct vec uri_vec, path_vec;
+ const char *list;
+
+ lock_option(ctx, OPT_ROOT);
+ mg_snprintf(conn, buf, buf_len, "%s%s", ctx->options[OPT_ROOT], uri);
+ unlock_option(ctx, OPT_ROOT);
+
+ /* If requested URI has aliased prefix, use alternate root */
+ lock_option(ctx, OPT_ALIASES);
+ list = ctx->options[OPT_ALIASES];
+
+ while ((list = next_option(list, &uri_vec, &path_vec)) != NULL) {
+ if (memcmp(uri, uri_vec.ptr, uri_vec.len) == 0) {
+ (void) mg_snprintf(conn, buf, buf_len, "%.*s%s",
+ path_vec.len, path_vec.ptr, uri + uri_vec.len);
+ break;
+ }
+ }
+ unlock_option(ctx, OPT_ALIASES);
+
+#ifdef _WIN32
+ fix_directory_separators(buf);
+#endif /* _WIN32 */
+
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: [%s] -> [%s]", __func__, uri, buf));
+}
+
+/*
+ * Setup listening socket on given address, return socket.
+ * Address format: [local_ip_address:]port_number
+ */
+static SOCKET
+mg_open_listening_port(struct mg_context *ctx, const char *str, struct usa *usa)
+{
+ SOCKET sock;
+ int on = 1, a, b, c, d, port;
+
+ /* MacOS needs that. If we do not zero it, bind() will fail. */
+ (void) memset(usa, 0, sizeof(*usa));
+
+ if (sscanf(str, "%d.%d.%d.%d:%d", &a, &b, &c, &d, &port) == 5) {
+ /* IP address to bind to is specified */
+ usa->u.sin.sin_addr.s_addr =
+ htonl(((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d);
+ } else if (sscanf(str, "%d", &port) == 1) {
+ /* Only port number is specified. Bind to all addresses */
+ usa->u.sin.sin_addr.s_addr = htonl(INADDR_ANY);
+ } else {
+ return (INVALID_SOCKET);
+ }
+
+ usa->len = sizeof(usa->u.sin);
+ usa->u.sin.sin_family = AF_INET;
+ usa->u.sin.sin_port = htons((uint16_t) port);
+
+ if ((sock = socket(PF_INET, SOCK_STREAM, 6)) != INVALID_SOCKET &&
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &on, sizeof(on)) == 0 &&
+ bind(sock, &usa->u.sa, usa->len) == 0 &&
+ listen(sock, 20) == 0) {
+ /* Success */
+ set_close_on_exec(sock);
+ } else {
+ /* Error */
+ cry(fc(ctx), "%s(%d): %s", __func__, port, strerror(ERRNO));
+ if (sock != INVALID_SOCKET)
+ (void) closesocket(sock);
+ sock = INVALID_SOCKET;
+ }
+
+ return (sock);
+}
+
+/*
+ * Check whether full request is buffered. Return:
+ * -1 if request is malformed
+ * 0 if request is not yet fully buffered
+ * >0 actual request length, including last \r\n\r\n
+ */
+static int
+get_request_len(const char *buf, size_t buflen)
+{
+ const char *s, *e;
+ int len = 0;
+
+ for (s = buf, e = s + buflen - 1; len <= 0 && s < e; s++)
+ /* Control characters are not allowed but >=128 is. */
+ if (!isprint(* (unsigned char *) s) && *s != '\r' &&
+ *s != '\n' && * (unsigned char *) s < 128)
+ len = -1;
+ else if (s[0] == '\n' && s[1] == '\n')
+ len = (int) (s - buf) + 2;
+ else if (s[0] == '\n' && &s[1] < e &&
+ s[1] == '\r' && s[2] == '\n')
+ len = (int) (s - buf) + 3;
+
+ return (len);
+}
+
+/*
+ * Convert month to the month number. Return -1 on error, or month number
+ */
+static int
+montoi(const char *s)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(month_names) / sizeof(month_names[0]); i++)
+ if (!strcmp(s, month_names[i]))
+ return ((int) i);
+
+ return (-1);
+}
+
+/*
+ * Parse date-time string, and return the corresponding time_t value
+ */
+static time_t
+date_to_epoch(const char *s)
+{
+ time_t current_time;
+ struct tm tm, *tmp;
+ char mon[32];
+ int sec, min, hour, mday, month, year;
+
+ (void) memset(&tm, 0, sizeof(tm));
+ sec = min = hour = mday = month = year = 0;
+
+ if (((sscanf(s, "%d/%3s/%d %d:%d:%d",
+ &mday, mon, &year, &hour, &min, &sec) == 6) ||
+ (sscanf(s, "%d %3s %d %d:%d:%d",
+ &mday, mon, &year, &hour, &min, &sec) == 6) ||
+ (sscanf(s, "%*3s, %d %3s %d %d:%d:%d",
+ &mday, mon, &year, &hour, &min, &sec) == 6) ||
+ (sscanf(s, "%d-%3s-%d %d:%d:%d",
+ &mday, mon, &year, &hour, &min, &sec) == 6)) &&
+ (month = montoi(mon)) != -1) {
+ tm.tm_mday = mday;
+ tm.tm_mon = month;
+ tm.tm_year = year;
+ tm.tm_hour = hour;
+ tm.tm_min = min;
+ tm.tm_sec = sec;
+ }
+
+ if (tm.tm_year > 1900)
+ tm.tm_year -= 1900;
+ else if (tm.tm_year < 70)
+ tm.tm_year += 100;
+
+ /* Set Daylight Saving Time field */
+ current_time = time(NULL);
+ tmp = localtime(&current_time);
+ tm.tm_isdst = tmp->tm_isdst;
+
+ return (mktime(&tm));
+}
+
+/*
+ * Protect against directory disclosure attack by removing '..',
+ * excessive '/' and '\' characters
+ */
+static void
+remove_double_dots_and_double_slashes(char *s)
+{
+ char *p = s;
+
+ while (*s != '\0') {
+ *p++ = *s++;
+ if (s[-1] == '/' || s[-1] == '\\') {
+ /* Skip all following slashes and backslashes */
+ while (*s == '/' || *s == '\\')
+ s++;
+
+ /* Skip all double-dots */
+ while (*s == '.' && s[1] == '.')
+ s += 2;
+ }
+ }
+ *p = '\0';
+}
+
+/*
+ * Built-in mime types
+ */
+static const struct {
+ const char *extension;
+ size_t ext_len;
+ const char *mime_type;
+ size_t mime_type_len;
+} mime_types[] = {
+ {".html", 5, "text/html", 9},
+ {".htm", 4, "text/html", 9},
+ {".shtm", 5, "text/html", 9},
+ {".shtml", 6, "text/html", 9},
+ {".css", 4, "text/css", 8},
+ {".js", 3, "application/x-javascript", 24},
+ {".ico", 4, "image/x-icon", 12},
+ {".gif", 4, "image/gif", 9},
+ {".jpg", 4, "image/jpeg", 10},
+ {".jpeg", 5, "image/jpeg", 10},
+ {".png", 4, "image/png", 9},
+ {".svg", 4, "image/svg+xml", 13},
+ {".torrent", 8, "application/x-bittorrent", 24},
+ {".wav", 4, "audio/x-wav", 11},
+ {".mp3", 4, "audio/x-mp3", 11},
+ {".mid", 4, "audio/mid", 9},
+ {".m3u", 4, "audio/x-mpegurl", 15},
+ {".ram", 4, "audio/x-pn-realaudio", 20},
+ {".xml", 4, "text/xml", 8},
+ {".xslt", 5, "application/xml", 15},
+ {".ra", 3, "audio/x-pn-realaudio", 20},
+ {".doc", 4, "application/msword", 19},
+ {".exe", 4, "application/octet-stream", 24},
+ {".zip", 4, "application/x-zip-compressed", 28},
+ {".xls", 4, "application/excel", 17},
+ {".tgz", 4, "application/x-tar-gz", 20},
+ {".tar", 4, "application/x-tar", 17},
+ {".gz", 3, "application/x-gunzip", 20},
+ {".arj", 4, "application/x-arj-compressed", 28},
+ {".rar", 4, "application/x-arj-compressed", 28},
+ {".rtf", 4, "application/rtf", 15},
+ {".pdf", 4, "application/pdf", 15},
+ {".swf", 4, "application/x-shockwave-flash",29},
+ {".mpg", 4, "video/mpeg", 10},
+ {".mpeg", 5, "video/mpeg", 10},
+ {".asf", 4, "video/x-ms-asf", 14},
+ {".avi", 4, "video/x-msvideo", 15},
+ {".bmp", 4, "image/bmp", 9},
+ {NULL, 0, NULL, 0}
+};
+
+/*
+ * Look at the "path" extension and figure what mime type it has.
+ * Store mime type in the vector.
+ */
+static void
+get_mime_type(struct mg_context *ctx, const char *path, struct vec *vec)
+{
+ struct vec ext_vec, mime_vec;
+ const char *list, *ext;
+ size_t i, path_len;
+
+ path_len = strlen(path);
+
+ /*
+ * Scan user-defined mime types first, in case user wants to
+ * override default mime types.
+ */
+ lock_option(ctx, OPT_MIME_TYPES);
+ list = ctx->options[OPT_MIME_TYPES];
+ while ((list = next_option(list, &ext_vec, &mime_vec)) != NULL) {
+ /* ext now points to the path suffix */
+ ext = path + path_len - ext_vec.len;
+ if (mg_strncasecmp(ext, ext_vec.ptr, ext_vec.len) == 0) {
+ *vec = mime_vec;
+ unlock_option(ctx, OPT_MIME_TYPES);
+ return;
+ }
+ }
+ unlock_option(ctx, OPT_MIME_TYPES);
+
+ /* Now scan built-in mime types */
+ for (i = 0; mime_types[i].extension != NULL; i++) {
+ ext = path + (path_len - mime_types[i].ext_len);
+ if (path_len > mime_types[i].ext_len &&
+ mg_strcasecmp(ext, mime_types[i].extension) == 0) {
+ vec->ptr = mime_types[i].mime_type;
+ vec->len = mime_types[i].mime_type_len;
+ return;
+ }
+ }
+
+ /* Nothing found. Fall back to text/plain */
+ vec->ptr = "text/plain";
+ vec->len = 10;
+}
+
+#ifndef HAVE_MD5
+typedef struct MD5Context {
+ uint32_t buf[4];
+ uint32_t bits[2];
+ unsigned char in[64];
+} MD5_CTX;
+
+#if __BYTE_ORDER == 1234
+#define byteReverse(buf, len) /* Nothing */
+#else
+/*
+ * Note: this code is harmless on little-endian machines.
+ */
+static void
+byteReverse(unsigned char *buf, unsigned longs)
+{
+ uint32_t t;
+ do {
+ t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
+ ((unsigned) buf[1] << 8 | buf[0]);
+ *(uint32_t *) buf = t;
+ buf += 4;
+ } while (--longs);
+}
+#endif /* __BYTE_ORDER */
+
+/* The four core functions - F1 is optimized somewhat */
+
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
+
+/*
+ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+static void
+MD5Init(MD5_CTX *ctx)
+{
+ ctx->buf[0] = 0x67452301;
+ ctx->buf[1] = 0xefcdab89;
+ ctx->buf[2] = 0x98badcfe;
+ ctx->buf[3] = 0x10325476;
+
+ ctx->bits[0] = 0;
+ ctx->bits[1] = 0;
+}
+
+/*
+ * The core of the MD5 algorithm, this alters an existing MD5 hash to
+ * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * the data and converts bytes into longwords for this routine.
+ */
+static void
+MD5Transform(uint32_t buf[4], uint32_t const in[16])
+{
+ register uint32_t a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+static void
+MD5Update(MD5_CTX *ctx, unsigned char const *buf, uint32_t len)
+{
+ uint32_t t;
+
+ /* Update bitcount */
+
+ t = ctx->bits[0];
+ if ((ctx->bits[0] = t + (len << 3)) < t)
+ ctx->bits[1]++; /* Carry from low to high */
+ ctx->bits[1] += len >> 29;
+
+ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
+
+ /* Handle any leading odd-sized chunks */
+
+ if (t) {
+ unsigned char *p = (unsigned char *) ctx->in + t;
+
+ t = 64 - t;
+ if (len < t) {
+ memcpy(p, buf, len);
+ return;
+ }
+ memcpy(p, buf, t);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ buf += t;
+ len -= t;
+ }
+ /* Process data in 64-byte chunks */
+
+ while (len >= 64) {
+ memcpy(ctx->in, buf, 64);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ buf += 64;
+ len -= 64;
+ }
+
+ /* Handle any remaining bytes of data. */
+
+ memcpy(ctx->in, buf, len);
+}
+
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+static void
+MD5Final(unsigned char digest[16], MD5_CTX *ctx)
+{
+ unsigned count;
+ unsigned char *p;
+
+ /* Compute number of bytes mod 64 */
+ count = (ctx->bits[0] >> 3) & 0x3F;
+
+ /* Set the first char of padding to 0x80. This is safe since there is
+ always at least one byte free */
+ p = ctx->in + count;
+ *p++ = 0x80;
+
+ /* Bytes of padding needed to make 64 bytes */
+ count = 64 - 1 - count;
+
+ /* Pad out to 56 mod 64 */
+ if (count < 8) {
+ /* Two lots of padding: Pad the first block to 64 bytes */
+ memset(p, 0, count);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+
+ /* Now fill the next block with 56 bytes */
+ memset(ctx->in, 0, 56);
+ } else {
+ /* Pad block to 56 bytes */
+ memset(p, 0, count - 8);
+ }
+ byteReverse(ctx->in, 14);
+
+ /* Append length in bits and transform */
+ ((uint32_t *) ctx->in)[14] = ctx->bits[0];
+ ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byteReverse((unsigned char *) ctx->buf, 4);
+ memcpy(digest, ctx->buf, 16);
+ memset((char *) ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+}
+#endif /* !HAVE_MD5 */
+
+/*
+ * Stringify binary data. Output buffer must be twice as big as input,
+ * because each byte takes 2 bytes in string representation
+ */
+static void
+bin2str(char *to, const unsigned char *p, size_t len)
+{
+ static const char *hex = "0123456789abcdef";
+
+ for (; len--; p++) {
+ *to++ = hex[p[0] >> 4];
+ *to++ = hex[p[0] & 0x0f];
+ }
+ *to = '\0';
+}
+
+/*
+ * Return stringified MD5 hash for list of vectors.
+ * buf must point to 33-bytes long buffer
+ */
+static void
+mg_md5(char *buf, ...)
+{
+ unsigned char hash[16];
+ const char *p;
+ va_list ap;
+ MD5_CTX ctx;
+
+ MD5Init(&ctx);
+
+ va_start(ap, buf);
+ while ((p = va_arg(ap, const char *)) != NULL)
+ MD5Update(&ctx, (unsigned char *) p, strlen(p));
+ va_end(ap);
+
+ MD5Final(hash, &ctx);
+ bin2str(buf, hash, sizeof(hash));
+}
+
+/*
+ * Check the user's password, return 1 if OK
+ */
+static bool_t
+check_password(const char *method, const char *ha1, const char *uri,
+ const char *nonce, const char *nc, const char *cnonce,
+ const char *qop, const char *response)
+{
+ char ha2[32 + 1], expected_response[32 + 1];
+
+ /* XXX Due to a bug in MSIE, we do not compare the URI */
+ /* Also, we do not check for authentication timeout */
+ if (/*strcmp(dig->uri, c->ouri) != 0 || */
+ strlen(response) != 32 /*||
+ now - strtoul(dig->nonce, NULL, 10) > 3600 */)
+ return (FALSE);
+
+ mg_md5(ha2, method, ":", uri, NULL);
+ mg_md5(expected_response, ha1, ":", nonce, ":", nc,
+ ":", cnonce, ":", qop, ":", ha2, NULL);
+
+ return (!mg_strcasecmp(response, expected_response));
+}
+
+/*
+ * Use the global passwords file, if specified by auth_gpass option,
+ * or search for .htpasswd in the requested directory.
+ */
+static FILE *
+open_auth_file(struct mg_connection *conn, const char *path)
+{
+ struct mg_context *ctx = conn->ctx;
+ char name[FILENAME_MAX];
+ const char *p, *e;
+ struct mgstat st;
+ FILE *fp;
+
+ if (ctx->options[OPT_AUTH_GPASSWD] != NULL) {
+ /* Use global passwords file */
+ fp = mg_fopen(ctx->options[OPT_AUTH_GPASSWD], "r");
+ if (fp == NULL)
+ cry(fc(ctx), "fopen(%s): %s",
+ ctx->options[OPT_AUTH_GPASSWD], strerror(ERRNO));
+ } else if (!mg_stat(path, &st) && st.is_directory) {
+ (void) mg_snprintf(conn, name, sizeof(name), "%s%c%s",
+ path, DIRSEP, PASSWORDS_FILE_NAME);
+ fp = mg_fopen(name, "r");
+ } else {
+ /*
+ * Try to find .htpasswd in requested directory.
+ * Given the path, create the path to .htpasswd file
+ * in the same directory. Find the right-most
+ * directory separator character first. That would be the
+ * directory name. If directory separator character is not
+ * found, 'e' will point to 'p'.
+ */
+ for (p = path, e = p + strlen(p) - 1; e > p; e--)
+ if (IS_DIRSEP_CHAR(*e))
+ break;
+
+ /*
+ * Make up the path by concatenating directory name and
+ * .htpasswd file name.
+ */
+ (void) mg_snprintf(conn, name, sizeof(name), "%.*s%c%s",
+ (int) (e - p), p, DIRSEP, PASSWORDS_FILE_NAME);
+ fp = mg_fopen(name, "r");
+ }
+
+ return (fp);
+}
+
+/*
+ * Parsed Authorization: header
+ */
+struct ah {
+ char *user, *uri, *cnonce, *response, *qop, *nc, *nonce;
+};
+
+static bool_t
+parse_auth_header(struct mg_connection *conn, char *buf, size_t buf_size,
+ struct ah *ah)
+{
+ char *name, *value, *s;
+ const char *auth_header;
+
+ if ((auth_header = mg_get_header(conn, "Authorization")) == NULL ||
+ mg_strncasecmp(auth_header, "Digest ", 7) != 0)
+ return (FALSE);
+
+ /* Make modifiable copy of the auth header */
+ (void) mg_strlcpy(buf, auth_header + 7, buf_size);
+
+ s = buf;
+ (void) memset(ah, 0, sizeof(*ah));
+
+ /* Gobble initial spaces */
+ while (isspace(* (unsigned char *) s))
+ s++;
+
+ /* Parse authorization header */
+ for (;;) {
+ name = skip(&s, "=");
+ value = skip(&s, ", ");
+
+ if (*value == '"') {
+ value++;
+ value[strlen(value) - 1] = '\0';
+ } else if (*value == '\0') {
+ break;
+ }
+
+ if (!strcmp(name, "username")) {
+ ah->user = value;
+ } else if (!strcmp(name, "cnonce")) {
+ ah->cnonce = value;
+ } else if (!strcmp(name, "response")) {
+ ah->response = value;
+ } else if (!strcmp(name, "uri")) {
+ ah->uri = value;
+ } else if (!strcmp(name, "qop")) {
+ ah->qop = value;
+ } else if (!strcmp(name, "nc")) {
+ ah->nc = value;
+ } else if (!strcmp(name, "nonce")) {
+ ah->nonce = value;
+ }
+ }
+
+ /* CGI needs it as REMOTE_USER */
+ if (ah->user != NULL)
+ conn->request_info.remote_user = mg_strdup(ah->user);
+
+ return (TRUE);
+}
+
+/*
+ * Authorize against the opened passwords file. Return 1 if authorized.
+ */
+static bool_t
+authorize(struct mg_connection *conn, FILE *fp)
+{
+ struct ah ah;
+ char line[256], f_user[256], domain[256], ha1[256],
+ buf[MAX_REQUEST_SIZE];
+
+ if (!parse_auth_header(conn, buf, sizeof(buf), &ah))
+ return (FALSE);
+
+ /* Loop over passwords file */
+ while (fgets(line, sizeof(line), fp) != NULL) {
+
+ if (sscanf(line, "%[^:]:%[^:]:%s", f_user, domain, ha1) != 3)
+ continue;
+
+ if (!strcmp(ah.user, f_user) &&
+ !strcmp(domain, conn->ctx->options[OPT_AUTH_DOMAIN]))
+ return (check_password(
+ conn->request_info.request_method, ha1,
+ ah.uri, ah.nonce, ah.nc, ah.cnonce,
+ ah.qop, ah.response));
+ }
+
+ return (FALSE);
+}
+
+/*
+ * Return TRUE if request is authorised, FALSE otherwise.
+ */
+static bool_t
+check_authorization(struct mg_connection *conn, const char *path)
+{
+ FILE *fp;
+ char fname[FILENAME_MAX];
+ struct vec uri_vec, filename_vec;
+ const char *list;
+ bool_t authorized;
+
+ fp = NULL;
+ authorized = TRUE;
+
+ lock_option(conn->ctx, OPT_PROTECT);
+ list = conn->ctx->options[OPT_PROTECT];
+ while ((list = next_option(list, &uri_vec, &filename_vec)) != NULL) {
+ if (!memcmp(conn->request_info.uri, uri_vec.ptr, uri_vec.len)) {
+ (void) mg_snprintf(conn, fname, sizeof(fname), "%.*s",
+ filename_vec.len, filename_vec.ptr);
+ if ((fp = mg_fopen(fname, "r")) == NULL)
+ cry(conn, "%s: cannot open %s: %s",
+ __func__, fname, strerror(errno));
+ break;
+ }
+ }
+ unlock_option(conn->ctx, OPT_PROTECT);
+
+ if (fp == NULL)
+ fp = open_auth_file(conn, path);
+
+ if (fp != NULL) {
+ authorized = authorize(conn, fp);
+ (void) fclose(fp);
+ }
+
+ return (authorized);
+}
+
+static void
+send_authorization_request(struct mg_connection *conn)
+{
+ conn->request_info.status_code = 401;
+ (void) mg_printf(conn,
+ "HTTP/1.1 401 Unauthorized\r\n"
+ "WWW-Authenticate: Digest qop=\"auth\", "
+ "realm=\"%s\", nonce=\"%lu\"\r\n\r\n",
+ conn->ctx->options[OPT_AUTH_DOMAIN], (unsigned long) time(NULL));
+}
+
+static bool_t
+is_authorized_for_put(struct mg_connection *conn)
+{
+ FILE *fp;
+ int ret = FALSE;
+
+ if ((fp = mg_fopen(conn->ctx->options[OPT_AUTH_PUT], "r")) != NULL) {
+ set_close_on_exec(fileno(fp));
+ ret = authorize(conn, fp);
+ (void) fclose(fp);
+ }
+
+ return (ret);
+}
+
+int
+mg_modify_passwords_file(struct mg_context *ctx, const char *fname,
+ const char *user, const char *pass)
+{
+ int found;
+ char line[512], u[512], d[512], ha1[33], tmp[FILENAME_MAX];
+ const char *domain;
+ FILE *fp, *fp2;
+
+ found = 0;
+ fp = fp2 = NULL;
+ domain = ctx->options[OPT_AUTH_DOMAIN];
+
+ /* Regard empty password as no password - remove user record. */
+ if (pass[0] == '\0')
+ pass = NULL;
+
+ (void) snprintf(tmp, sizeof(tmp), "%s.tmp", fname);
+
+ /* Create the file if does not exist */
+ if ((fp = mg_fopen(fname, "a+")) != NULL)
+ (void) fclose(fp);
+
+ /* Open the given file and temporary file */
+ if ((fp = mg_fopen(fname, "r")) == NULL) {
+ cry(fc(ctx), "Cannot open %s: %s", fname, strerror(errno));
+ return (0);
+ } else if ((fp2 = mg_fopen(tmp, "w+")) == NULL) {
+ cry(fc(ctx), "Cannot open %s: %s", tmp, strerror(errno));
+ return (0);
+ }
+
+ /* Copy the stuff to temporary file */
+ while (fgets(line, sizeof(line), fp) != NULL) {
+
+ if (sscanf(line, "%[^:]:%[^:]:%*s", u, d) != 2)
+ continue;
+
+ if (!strcmp(u, user) && !strcmp(d, domain)) {
+ found++;
+ if (pass != NULL) {
+ mg_md5(ha1, user, ":", domain, ":", pass, NULL);
+ fprintf(fp2, "%s:%s:%s\n", user, domain, ha1);
+ }
+ } else {
+ (void) fprintf(fp2, "%s", line);
+ }
+ }
+
+ /* If new user, just add it */
+ if (!found && pass != NULL) {
+ mg_md5(ha1, user, ":", domain, ":", pass, NULL);
+ (void) fprintf(fp2, "%s:%s:%s\n", user, domain, ha1);
+ }
+
+ /* Close files */
+ (void) fclose(fp);
+ (void) fclose(fp2);
+
+ /* Put the temp file in place of real file */
+ (void) mg_remove(fname);
+ (void) mg_rename(tmp, fname);
+
+ return (0);
+}
+
+struct de {
+ struct mg_connection *conn;
+ char *file_name;
+ struct mgstat st;
+};
+
+static void
+url_encode(const char *src, char *dst, size_t dst_len)
+{
+ const char *dont_escape = "._-$,;~()";
+ const char *hex = "0123456789abcdef";
+ const char *end = dst + dst_len - 1;
+
+ for (; *src != '\0' && dst < end; src++, dst++) {
+ if (isalnum(*(unsigned char *) src) ||
+ strchr(dont_escape, * (unsigned char *) src) != NULL) {
+ *dst = *src;
+ } else if (dst + 2 < end) {
+ dst[0] = '%';
+ dst[1] = hex[(* (unsigned char *) src) >> 4];
+ dst[2] = hex[(* (unsigned char *) src) & 0xf];
+ dst += 2;
+ }
+ }
+
+ *dst = '\0';
+}
+
+/*
+ * This function is called from send_directory() and prints out
+ * single directory entry.
+ */
+static void
+print_dir_entry(struct de *de)
+{
+ char size[64], mod[64], href[FILENAME_MAX];
+
+ if (de->st.is_directory) {
+ (void) mg_snprintf(de->conn,
+ size, sizeof(size), "%s", "[DIRECTORY]");
+ } else {
+ /*
+ * We use (signed) cast below because MSVC 6 compiler cannot
+ * convert unsigned __int64 to double. Sigh.
+ */
+ if (de->st.size < 1024)
+ (void) mg_snprintf(de->conn, size, sizeof(size),
+ "%lu", (unsigned long) de->st.size);
+ else if (de->st.size < 0x100000 /* 1024 * 1024 */)
+ (void) mg_snprintf(de->conn, size, sizeof(size),
+ "%.1fk", (double) de->st.size / 1024.0);
+ else if (de->st.size < 0x40000000 /* 1024 * 1024 * 1024 */)
+ (void) mg_snprintf(de->conn, size, sizeof(size),
+ "%.1fM", (double) de->st.size / 1048576);
+ else
+ (void) mg_snprintf(de->conn, size, sizeof(size),
+ "%.1fG", (double) de->st.size / 1073741824);
+ }
+ (void) strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M",
+ localtime(&de->st.mtime));
+
+ url_encode(de->file_name, href, sizeof(href));
+
+ de->conn->num_bytes_sent += mg_printf(de->conn,
+ "<tr><td><a href=\"%s%s%s\">%s%s</a></td>"
+ "<td>&nbsp;%s</td><td>&nbsp;&nbsp;%s</td></tr>\n",
+ de->conn->request_info.uri, href, de->st.is_directory ? "/" : "",
+ de->file_name, de->st.is_directory ? "/" : "", mod, size);
+}
+
+/*
+ * This function is called from send_directory() and used for
+ * sorting direcotory entries by size, or name, or modification time.
+ */
+static int
+compare_dir_entries(const void *p1, const void *p2)
+{
+ const struct de *a = (struct de *) p1, *b = (struct de *) p2;
+ const char *query_string = a->conn->request_info.query_string;
+ int cmp_result = 0;
+
+ if (query_string == NULL)
+ query_string = "na";
+
+ if (a->st.is_directory && !b->st.is_directory) {
+ return (-1); /* Always put directories on top */
+ } else if (!a->st.is_directory && b->st.is_directory) {
+ return (1); /* Always put directories on top */
+ } else if (*query_string == 'n') {
+ cmp_result = strcmp(a->file_name, b->file_name);
+ } else if (*query_string == 's') {
+ cmp_result = a->st.size == b->st.size ? 0 :
+ a->st.size > b->st.size ? 1 : -1;
+ } else if (*query_string == 'd') {
+ cmp_result = a->st.mtime == b->st.mtime ? 0 :
+ a->st.mtime > b->st.mtime ? 1 : -1;
+ }
+
+ return (query_string[1] == 'd' ? -cmp_result : cmp_result);
+}
+
+/*
+ * Send directory contents.
+ */
+static void
+send_directory(struct mg_connection *conn, const char *dir)
+{
+ struct dirent *dp;
+ DIR *dirp;
+ struct de *entries = NULL;
+ char path[FILENAME_MAX];
+ int i, sort_direction, num_entries = 0, arr_size = 128;
+
+ if ((dirp = opendir(dir)) == NULL) {
+ send_error(conn, 500, "Cannot open directory",
+ "Error: opendir(%s): %s", path, strerror(ERRNO));
+ return;
+ }
+
+ (void) mg_printf(conn, "%s",
+ "HTTP/1.1 200 OK\r\n"
+ "Connection: close\r\n"
+ "Content-Type: text/html; charset=utf-8\r\n\r\n");
+
+ sort_direction = conn->request_info.query_string != NULL &&
+ conn->request_info.query_string[1] == 'd' ? 'a' : 'd';
+
+ while ((dp = readdir(dirp)) != NULL) {
+
+ /* Do not show current dir and passwords file */
+ if (!strcmp(dp->d_name, ".") ||
+ !strcmp(dp->d_name, "..") ||
+ !strcmp(dp->d_name, PASSWORDS_FILE_NAME))
+ continue;
+
+ if (entries == NULL || num_entries >= arr_size) {
+ arr_size *= 2;
+ entries = (struct de *) realloc(entries,
+ arr_size * sizeof(entries[0]));
+ }
+
+ if (entries == NULL) {
+ send_error(conn, 500, "Cannot open directory",
+ "%s", "Error: cannot allocate memory");
+ return;
+ }
+
+ (void) mg_snprintf(conn, path, sizeof(path), "%s%c%s",
+ dir, DIRSEP, dp->d_name);
+
+ /*
+ * If we don't memset stat structure to zero, mtime will have
+ * garbage and strftime() will segfault later on in
+ * print_dir_entry(). memset is required only if mg_stat()
+ * fails. For more details, see
+ * http://code.google.com/p/mongoose/issues/detail?id=79
+ */
+ if (mg_stat(path, &entries[num_entries].st) != 0)
+ (void) memset(&entries[num_entries].st, 0,
+ sizeof(entries[num_entries].st));
+
+ entries[num_entries].conn = conn;
+ entries[num_entries].file_name = mg_strdup(dp->d_name);
+ num_entries++;
+ }
+ (void) closedir(dirp);
+
+ conn->num_bytes_sent += mg_printf(conn,
+ "<html><head><title>Index of %s</title>"
+ "<style>th {text-align: left;}</style></head>"
+ "<body><h1>Index of %s</h1><pre><table cellpadding=\"0\">"
+ "<tr><th><a href=\"?n%c\">Name</a></th>"
+ "<th><a href=\"?d%c\">Modified</a></th>"
+ "<th><a href=\"?s%c\">Size</a></th></tr>"
+ "<tr><td colspan=\"3\"><hr></td></tr>",
+ conn->request_info.uri, conn->request_info.uri,
+ sort_direction, sort_direction, sort_direction);
+
+ /* Print first entry - link to a parent directory */
+ conn->num_bytes_sent += mg_printf(conn,
+ "<tr><td><a href=\"%s%s\">%s</a></td>"
+ "<td>&nbsp;%s</td><td>&nbsp;&nbsp;%s</td></tr>\n",
+ conn->request_info.uri, "..", "Parent directory", "-", "-");
+
+ /* Sort and print directory entries */
+ qsort(entries, num_entries, sizeof(entries[0]), compare_dir_entries);
+ for (i = 0; i < num_entries; i++) {
+ print_dir_entry(&entries[i]);
+ free(entries[i].file_name);
+ }
+ free(entries);
+
+ conn->num_bytes_sent += mg_printf(conn, "%s", "</table></body></html>");
+ conn->request_info.status_code = 200;
+}
+
+/*
+ * Send len bytes from the opened file to the client.
+ */
+static void
+send_opened_file_stream(struct mg_connection *conn, FILE *fp, int64_t len)
+{
+ char buf[BUFSIZ];
+ int to_read, num_read, num_written;
+
+ while (len > 0) {
+ /* Calculate how much to read from the file in the buffer */
+ to_read = sizeof(buf);
+ if ((int64_t) to_read > len)
+ to_read = (int) len;
+
+ /* Read from file, exit the loop on error */
+ if ((num_read = fread(buf, 1, to_read, fp)) == 0)
+ break;
+
+ /* Send read bytes to the client, exit the loop on error */
+ if ((num_written = mg_write(conn, buf, num_read)) != num_read)
+ break;
+
+ /* Both read and were successful, adjust counters */
+ conn->num_bytes_sent += num_written;
+ len -= num_written;
+ }
+}
+
+/*
+ * Send regular file contents.
+ */
+static void
+send_file(struct mg_connection *conn, const char *path, struct mgstat *stp)
+{
+ char date[64], lm[64], etag[64], range[64];
+ const char *fmt = "%a, %d %b %Y %H:%M:%S %Z", *msg = "OK", *hdr;
+ time_t curtime = time(NULL);
+ int64_t cl, r1, r2;
+ struct vec mime_vec;
+ FILE *fp;
+ int n;
+
+ get_mime_type(conn->ctx, path, &mime_vec);
+ cl = stp->size;
+ conn->request_info.status_code = 200;
+ range[0] = '\0';
+
+ if ((fp = mg_fopen(path, "rb")) == NULL) {
+ send_error(conn, 500, http_500_error,
+ "fopen(%s): %s", path, strerror(ERRNO));
+ return;
+ }
+ set_close_on_exec(fileno(fp));
+
+ /* If Range: header specified, act accordingly */
+ r1 = r2 = 0;
+ hdr = mg_get_header(conn, "Range");
+ if (hdr != NULL && (n = sscanf(hdr,
+ "bytes=%" INT64_FMT "-%" INT64_FMT, &r1, &r2)) > 0) {
+ conn->request_info.status_code = 206;
+ (void) fseeko(fp, (off_t) r1, SEEK_SET);
+ cl = n == 2 ? r2 - r1 + 1: cl - r1;
+ (void) mg_snprintf(conn, range, sizeof(range),
+ "Content-Range: bytes "
+ "%" INT64_FMT "-%"
+ INT64_FMT "/%" INT64_FMT "\r\n",
+ r1, r1 + cl - 1, stp->size);
+ msg = "Partial Content";
+ }
+
+ /* Prepare Etag, Date, Last-Modified headers */
+ (void) strftime(date, sizeof(date), fmt, localtime(&curtime));
+ (void) strftime(lm, sizeof(lm), fmt, localtime(&stp->mtime));
+ (void) mg_snprintf(conn, etag, sizeof(etag), "%lx.%lx",
+ (unsigned long) stp->mtime, (unsigned long) stp->size);
+
+ (void) mg_printf(conn,
+ "HTTP/1.1 %d %s\r\n"
+ "Date: %s\r\n"
+ "Last-Modified: %s\r\n"
+ "Etag: \"%s\"\r\n"
+ "Content-Type: %.*s\r\n"
+ "Content-Length: %" INT64_FMT "\r\n"
+ "Connection: close\r\n"
+ "Accept-Ranges: bytes\r\n"
+ "%s\r\n",
+ conn->request_info.status_code, msg, date, lm, etag,
+ mime_vec.len, mime_vec.ptr, cl, range);
+
+ if (strcmp(conn->request_info.request_method, "HEAD") != 0)
+ send_opened_file_stream(conn, fp, cl);
+ (void) fclose(fp);
+}
+
+/*
+ * Parse HTTP headers from the given buffer, advance buffer to the point
+ * where parsing stopped.
+ */
+static void
+parse_http_headers(char **buf, struct mg_request_info *ri)
+{
+ int i;
+
+ for (i = 0; i < (int) ARRAY_SIZE(ri->http_headers); i++) {
+ ri->http_headers[i].name = skip(buf, ": ");
+ ri->http_headers[i].value = skip(buf, "\r\n");
+ if (ri->http_headers[i].name[0] == '\0')
+ break;
+ ri->num_headers = i + 1;
+ }
+}
+
+static bool_t
+is_valid_http_method(const char *method)
+{
+ return (!strcmp(method, "GET") ||
+ !strcmp(method, "POST") ||
+ !strcmp(method, "HEAD") ||
+ !strcmp(method, "PUT") ||
+ !strcmp(method, "DELETE"));
+}
+
+/*
+ * Parse HTTP request, fill in mg_request_info structure.
+ */
+static bool_t
+parse_http_request(char *buf, struct mg_request_info *ri, const struct usa *usa)
+{
+ int success_code = FALSE;
+
+ ri->request_method = skip(&buf, " ");
+ ri->uri = skip(&buf, " ");
+ ri->http_version = skip(&buf, "\r\n");
+
+ if (is_valid_http_method(ri->request_method) &&
+ ri->uri[0] == '/' &&
+ strncmp(ri->http_version, "HTTP/", 5) == 0) {
+ ri->http_version += 5; /* Skip "HTTP/" */
+ parse_http_headers(&buf, ri);
+ ri->remote_port = ntohs(usa->u.sin.sin_port);
+ (void) memcpy(&ri->remote_ip, &usa->u.sin.sin_addr.s_addr, 4);
+ ri->remote_ip = ntohl(ri->remote_ip);
+ success_code = TRUE;
+ }
+
+ return (success_code);
+}
+
+/*
+ * Keep reading the input (either opened file descriptor fd, or socket sock,
+ * or SSL descriptor ssl) into buffer buf, until \r\n\r\n appears in the
+ * buffer (which marks the end of HTTP request). Buffer buf may already
+ * have some data. The length of the data is stored in nread.
+ * Upon every read operation, increase nread by the number of bytes read.
+ */
+static int
+read_request(FILE *fp, SOCKET sock, SSL *ssl, char *buf, int bufsiz, int *nread)
+{
+ int n, request_len;
+
+ request_len = 0;
+ while (*nread < bufsiz && request_len == 0) {
+ n = pull(fp, sock, ssl, buf + *nread, bufsiz - *nread);
+ if (n <= 0) {
+ break;
+ } else {
+ *nread += n;
+ request_len = get_request_len(buf, (size_t) *nread);
+ }
+ }
+
+ return (request_len);
+}
+
+/*
+ * For given directory path, substitute it to valid index file.
+ * Return 0 if index file has been found, -1 if not found.
+ * If the file is found, it's stats is returned in stp.
+ */
+static bool_t
+substitute_index_file(struct mg_connection *conn,
+ char *path, size_t path_len, struct mgstat *stp)
+{
+ const char *list;
+ struct mgstat st;
+ struct vec filename_vec;
+ size_t n;
+ bool_t found;
+
+ n = strlen(path);
+
+ /*
+ * The 'path' given to us points to the directory. Remove all trailing
+ * directory separator characters from the end of the path, and
+ * then append single directory separator character.
+ */
+ while (n > 0 && IS_DIRSEP_CHAR(path[n - 1]))
+ n--;
+ path[n] = DIRSEP;
+
+ /*
+ * Traverse index files list. For each entry, append it to the given
+ * path and see if the file exists. If it exists, break the loop
+ */
+ lock_option(conn->ctx, OPT_INDEX_FILES);
+ list = conn->ctx->options[OPT_INDEX_FILES];
+ found = FALSE;
+
+ while ((list = next_option(list, &filename_vec, NULL)) != NULL) {
+
+ /* Ignore too long entries that may overflow path buffer */
+ if (filename_vec.len > path_len - n)
+ continue;
+
+ /* Prepare full path to the index file */
+ (void) mg_strlcpy(path + n + 1,
+ filename_vec.ptr, filename_vec.len + 1);
+
+ /* Does it exist ? */
+ if (mg_stat(path, &st) == 0) {
+ /* Yes it does, break the loop */
+ *stp = st;
+ found = TRUE;
+ break;
+ }
+ }
+ unlock_option(conn->ctx, OPT_INDEX_FILES);
+
+ /* If no index file exists, restore directory path */
+ if (found == FALSE)
+ path[n] = '\0';
+
+ return (found);
+}
+
+static void
+remove_callback(struct mg_context *ctx,
+ const char *uri_regex, int status_code, bool_t is_auth)
+{
+ struct callback *cb;
+ int i;
+
+ for (i = 0; i < ctx->num_callbacks; i++) {
+ cb = ctx->callbacks + i;
+ if ((uri_regex != NULL && cb->uri_regex != NULL &&
+ ((is_auth && cb->is_auth) || (!is_auth && !cb->is_auth)) &&
+ !strcmp(uri_regex, cb->uri_regex)) || (uri_regex == NULL &&
+ (cb->status_code == 0 ||
+ cb->status_code == status_code))) {
+ (void) memmove(cb, cb + 1,
+ (char *) (ctx->callbacks + ctx->num_callbacks) -
+ (char *) (cb + 1));
+ break;
+ }
+ }
+}
+
+static void
+add_callback(struct mg_context *ctx, const char *uri_regex, int status_code,
+ mg_callback_t func, bool_t is_auth, void *user_data)
+{
+ struct callback *cb;
+
+ pthread_mutex_lock(&ctx->bind_mutex);
+ if (func == NULL) {
+ remove_callback(ctx, uri_regex, status_code, is_auth);
+ } else if (ctx->num_callbacks >= (int) ARRAY_SIZE(ctx->callbacks) - 1) {
+ cry(fc(ctx), "Too many callbacks! Increase MAX_CALLBACKS.");
+ } else {
+ cb = &ctx->callbacks[ctx->num_callbacks];
+ cb->uri_regex = uri_regex ? mg_strdup(uri_regex) : NULL;
+ cb->func = func;
+ cb->is_auth = is_auth;
+ cb->status_code = status_code;
+ cb->user_data = user_data;
+ ctx->num_callbacks++;
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: uri %s code %d",
+ __func__, uri_regex ? uri_regex : "NULL", status_code));
+ }
+ pthread_mutex_unlock(&ctx->bind_mutex);
+}
+
+void
+mg_set_uri_callback(struct mg_context *ctx, const char *uri_regex,
+ mg_callback_t func, void *user_data)
+{
+ assert(uri_regex != NULL);
+ add_callback(ctx, uri_regex, -1, func, FALSE, user_data);
+}
+
+void
+mg_set_error_callback(struct mg_context *ctx, int error_code,
+ mg_callback_t func, void *user_data)
+{
+ assert(error_code >= 0 && error_code < 1000);
+ add_callback(ctx, NULL, error_code, func, FALSE, user_data);
+}
+
+void
+mg_set_auth_callback(struct mg_context *ctx, const char *uri_regex,
+ mg_callback_t func, void *user_data)
+{
+ assert(uri_regex != NULL);
+ add_callback(ctx, uri_regex, -1, func, TRUE, user_data);
+}
+
+/*
+ * Return True if we should reply 304 Not Modified.
+ */
+static bool_t
+is_not_modified(const struct mg_connection *conn, const struct mgstat *stp)
+{
+ const char *ims = mg_get_header(conn, "If-Modified-Since");
+ return (ims != NULL && stp->mtime < date_to_epoch(ims));
+}
+
+static bool_t
+append_chunk(struct mg_request_info *ri, FILE *fp, const char *buf, int len)
+{
+ bool_t ret_code = TRUE;
+
+ if (fp == NULL) {
+ /* TODO: check for NULL here */
+ ri->post_data = (char *) realloc(ri->post_data,
+ ri->post_data_len + len);
+ (void) memcpy(ri->post_data + ri->post_data_len, buf, len);
+ ri->post_data_len += len;
+ } else if (push(fp, INVALID_SOCKET,
+ NULL, buf, (int64_t) len) != (int64_t) len) {
+ ret_code = FALSE;
+ }
+
+ return (ret_code);
+}
+
+static bool_t
+handle_request_body(struct mg_connection *conn, FILE *fp)
+{
+ struct mg_request_info *ri = &conn->request_info;
+ const char *expect, *tmp;
+ int64_t content_len;
+ char buf[BUFSIZ];
+ int to_read, nread, already_read;
+ bool_t success_code = FALSE;
+
+ content_len = get_content_length(conn);
+ expect = mg_get_header(conn, "Expect");
+
+ if (content_len == -1) {
+ send_error(conn, 411, "Length Required", "");
+ } else if (expect != NULL && mg_strcasecmp(expect, "100-continue")) {
+ send_error(conn, 417, "Expectation Failed", "");
+ } else {
+ if (expect != NULL)
+ (void) mg_printf(conn, "HTTP/1.1 100 Continue\r\n\r\n");
+
+ already_read = ri->post_data_len;
+ assert(already_read >= 0);
+
+ if (content_len <= (int64_t) already_read) {
+ ri->post_data_len = (int) content_len;
+ /*
+ * If fp is NULL, this is embedded mode, and we do not
+ * have to do anything: POST data is already there,
+ * no need to allocate a buffer and copy it in.
+ * If fp != NULL, we need to write the data.
+ */
+ success_code = fp == NULL || (push(fp, INVALID_SOCKET,
+ NULL, ri->post_data, content_len) == content_len) ?
+ TRUE : FALSE;
+ } else {
+
+ if (fp == NULL) {
+ conn->free_post_data = TRUE;
+ tmp = ri->post_data;
+ /* +1 in case if already_read == 0 */
+ ri->post_data = (char*)malloc(already_read + 1);
+ (void) memcpy(ri->post_data, tmp, already_read);
+ } else {
+ (void) push(fp, INVALID_SOCKET, NULL,
+ ri->post_data, (int64_t) already_read);
+ }
+
+ content_len -= already_read;
+
+ while (content_len > 0) {
+ to_read = sizeof(buf);
+ if ((int64_t) to_read > content_len)
+ to_read = (int) content_len;
+ nread = pull(NULL, conn->client.sock,
+ conn->ssl, buf, to_read);
+ if (nread <= 0)
+ break;
+ if (!append_chunk(ri, fp, buf, nread))
+ break;
+ content_len -= nread;
+ }
+ success_code = content_len == 0 ? TRUE : FALSE;
+ }
+
+ /* Each error code path in this function must send an error */
+ if (success_code != TRUE)
+ send_error(conn, 577, http_500_error,
+ "%s", "Error handling body data");
+ }
+
+ return (success_code);
+}
+
+#if !defined(NO_CGI)
+
+/*
+ * This structure helps to create an environment for the spawned CGI program.
+ * Environment is an array of "VARIABLE=VALUE\0" ASCIIZ strings,
+ * last element must be NULL.
+ * However, on Windows there is a requirement that all these VARIABLE=VALUE\0
+ * strings must reside in a contiguous buffer. The end of the buffer is
+ * marked by two '\0' characters.
+ * We satisfy both worlds: we create an envp array (which is vars), all
+ * entries are actually pointers inside buf.
+ */
+struct cgi_env_block {
+ struct mg_connection *conn;
+ char buf[CGI_ENVIRONMENT_SIZE]; /* Environment buffer */
+ int len; /* Space taken */
+ char *vars[MAX_CGI_ENVIR_VARS]; /* char **envp */
+ int nvars; /* Number of variables */
+};
+
+/*
+ * Append VARIABLE=VALUE\0 string to the buffer, and add a respective
+ * pointer into the vars array.
+ */
+static char *
+addenv(struct cgi_env_block *block, const char *fmt, ...)
+{
+ int n, space;
+ char *added;
+ va_list ap;
+
+ /* Calculate how much space is left in the buffer */
+ space = sizeof(block->buf) - block->len - 2;
+ assert(space >= 0);
+
+ /* Make a pointer to the free space int the buffer */
+ added = block->buf + block->len;
+
+ /* Copy VARIABLE=VALUE\0 string into the free space */
+ va_start(ap, fmt);
+ n = mg_vsnprintf(block->conn, added, (size_t) space, fmt, ap);
+ va_end(ap);
+
+ /* Make sure we do not overflow buffer and the envp array */
+ if (n > 0 && n < space &&
+ block->nvars < (int) ARRAY_SIZE(block->vars) - 2) {
+ /* Append a pointer to the added string into the envp array */
+ block->vars[block->nvars++] = block->buf + block->len;
+ /* Bump up used length counter. Include \0 terminator */
+ block->len += n + 1;
+ }
+
+ return (added);
+}
+
+static void
+prepare_cgi_environment(struct mg_connection *conn, const char *prog,
+ struct cgi_env_block *blk)
+{
+ const char *s, *script_filename, *root, *slash;
+ struct vec var_vec;
+ char *p;
+ int i;
+
+ blk->len = blk->nvars = 0;
+ blk->conn = conn;
+
+ /* SCRIPT_FILENAME */
+ script_filename = prog;
+ if ((s = strrchr(prog, '/')) != NULL)
+ script_filename = s + 1;
+
+ lock_option(conn->ctx, OPT_ROOT);
+ root = conn->ctx->options[OPT_ROOT];
+ addenv(blk, "SERVER_NAME=%s", conn->ctx->options[OPT_AUTH_DOMAIN]);
+ unlock_option(conn->ctx, OPT_ROOT);
+
+ /* Prepare the environment block */
+ addenv(blk, "%s", "GATEWAY_INTERFACE=CGI/1.1");
+ addenv(blk, "%s", "SERVER_PROTOCOL=HTTP/1.1");
+ addenv(blk, "%s", "REDIRECT_STATUS=200"); /* PHP */
+ addenv(blk, "SERVER_PORT=%d", ntohs(conn->client.lsa.u.sin.sin_port));
+ addenv(blk, "SERVER_ROOT=%s", root);
+ addenv(blk, "DOCUMENT_ROOT=%s", root);
+ addenv(blk, "REQUEST_METHOD=%s", conn->request_info.request_method);
+ addenv(blk, "REMOTE_ADDR=%s",
+ inet_ntoa(conn->client.rsa.u.sin.sin_addr));
+ addenv(blk, "REMOTE_PORT=%d", conn->request_info.remote_port);
+ addenv(blk, "REQUEST_URI=%s", conn->request_info.uri);
+
+ slash = strrchr(conn->request_info.uri, '/');
+ addenv(blk, "SCRIPT_NAME=%.*s%s",
+ (slash - conn->request_info.uri) + 1, conn->request_info.uri,
+ script_filename);
+
+ addenv(blk, "SCRIPT_FILENAME=%s", script_filename); /* PHP */
+ addenv(blk, "PATH_TRANSLATED=%s", prog);
+ addenv(blk, "HTTPS=%s", conn->ssl == NULL ? "off" : "on");
+
+ if ((s = mg_get_header(conn, "Content-Type")) != NULL)
+ addenv(blk, "CONTENT_TYPE=%s", s);
+
+ if (conn->request_info.query_string != NULL)
+ addenv(blk, "QUERY_STRING=%s", conn->request_info.query_string);
+
+ if ((s = mg_get_header(conn, "Content-Length")) != NULL)
+ addenv(blk, "CONTENT_LENGTH=%s", s);
+
+ if ((s = getenv("PATH")) != NULL)
+ addenv(blk, "PATH=%s", s);
+
+#if defined(_WIN32)
+ if ((s = getenv("COMSPEC")) != NULL)
+ addenv(blk, "COMSPEC=%s", s);
+ if ((s = getenv("SYSTEMROOT")) != NULL)
+ addenv(blk, "SYSTEMROOT=%s", s);
+#else
+ if ((s = getenv("LD_LIBRARY_PATH")) != NULL)
+ addenv(blk, "LD_LIBRARY_PATH=%s", s);
+#endif /* _WIN32 */
+
+ if ((s = getenv("PERLLIB")) != NULL)
+ addenv(blk, "PERLLIB=%s", s);
+
+ if (conn->request_info.remote_user != NULL) {
+ addenv(blk, "REMOTE_USER=%s", conn->request_info.remote_user);
+ addenv(blk, "%s", "AUTH_TYPE=Digest");
+ }
+
+ /* Add all headers as HTTP_* variables */
+ for (i = 0; i < conn->request_info.num_headers; i++) {
+ p = addenv(blk, "HTTP_%s=%s",
+ conn->request_info.http_headers[i].name,
+ conn->request_info.http_headers[i].value);
+
+ /* Convert variable name into uppercase, and change - to _ */
+ for (; *p != '=' && *p != '\0'; p++) {
+ if (*p == '-')
+ *p = '_';
+ *p = (char) toupper(* (unsigned char *) p);
+ }
+ }
+
+ /* Add user-specified variables */
+ lock_option(conn->ctx, OPT_CGI_ENV);
+ s = conn->ctx->options[OPT_CGI_ENV];
+ while ((s = next_option(s, &var_vec, NULL)) != NULL)
+ addenv(blk, "%.*s", var_vec.len, var_vec.ptr);
+ unlock_option(conn->ctx, OPT_CGI_ENV);
+
+ blk->vars[blk->nvars++] = NULL;
+ blk->buf[blk->len++] = '\0';
+
+ assert(blk->nvars < (int) ARRAY_SIZE(blk->vars));
+ assert(blk->len > 0);
+ assert(blk->len < (int) sizeof(blk->buf));
+}
+
+static void
+send_cgi(struct mg_connection *conn, const char *prog)
+{
+ int headers_len, data_len, i;
+ const char *status;
+ char buf[MAX_REQUEST_SIZE], *pbuf;
+ struct mg_request_info ri;
+ struct cgi_env_block blk;
+ char dir[FILENAME_MAX], *p;
+ int fd_stdin[2], fd_stdout[2];
+ FILE *in, *out;
+ pid_t pid;
+
+ prepare_cgi_environment(conn, prog, &blk);
+
+ /* CGI must be executed in its own directory */
+ (void) mg_snprintf(conn, dir, sizeof(dir), "%s", prog);
+ if ((p = strrchr(dir, DIRSEP)) != NULL)
+ *p++ = '\0';
+
+ pid = (pid_t) -1;
+ fd_stdin[0] = fd_stdin[1] = fd_stdout[0] = fd_stdout[1] = -1;
+ in = out = NULL;
+
+ if (pipe(fd_stdin) != 0 || pipe(fd_stdout) != 0) {
+ send_error(conn, 500, http_500_error,
+ "Cannot create CGI pipe: %s", strerror(ERRNO));
+ goto done;
+ } else if ((pid = spawn_process(conn, p, blk.buf, blk.vars,
+ fd_stdin[0], fd_stdout[1], dir)) == (pid_t) -1) {
+ goto done;
+ } else if ((in = fdopen(fd_stdin[1], "wb")) == NULL ||
+ (out = fdopen(fd_stdout[0], "rb")) == NULL) {
+ send_error(conn, 500, http_500_error,
+ "fopen: %s", strerror(ERRNO));
+ goto done;
+ }
+
+ setbuf(in, NULL);
+ setbuf(out, NULL);
+
+ /*
+ * spawn_process() must close those!
+ * If we don't mark them as closed, close() attempt before
+ * return from this function throws an exception on Windows.
+ * Windows does not like when closed descriptor is closed again.
+ */
+ fd_stdin[0] = fd_stdout[1] = -1;
+
+ /* Send POST data to the CGI process if needed */
+ if (!strcmp(conn->request_info.request_method, "POST") &&
+ !handle_request_body(conn, in)) {
+ goto done;
+ }
+
+ /*
+ * Now read CGI reply into a buffer. We need to set correct
+ * status code, thus we need to see all HTTP headers first.
+ * Do not send anything back to client, until we buffer in all
+ * HTTP headers.
+ */
+ data_len = 0;
+ headers_len = read_request(out, INVALID_SOCKET, NULL,
+ buf, sizeof(buf), &data_len);
+ if (headers_len <= 0) {
+ send_error(conn, 500, http_500_error,
+ "CGI program sent malformed HTTP headers: [%.*s]",
+ data_len, buf);
+ goto done;
+ }
+ pbuf = buf;
+ buf[headers_len - 1] = '\0';
+ parse_http_headers(&pbuf, &ri);
+
+ /* Make up and send the status line */
+ status = get_header(&ri, "Status");
+ conn->request_info.status_code = status == NULL ? 200 : atoi(status);
+ (void) mg_printf(conn, "HTTP/1.1 %d OK\r\n",
+ conn->request_info.status_code);
+
+ /* Send headers */
+ for (i = 0; i < ri.num_headers; i++)
+ (void) mg_printf(conn, "%s: %s\r\n",
+ ri.http_headers[i].name,
+ ri.http_headers[i].value);
+ (void) mg_write(conn, "\r\n", 2);
+
+ /* Send chunk of data that may be read after the headers */
+ conn->num_bytes_sent += mg_write(conn,
+ buf + headers_len, data_len - headers_len);
+
+ /* Read the rest of CGI output and send to the client */
+ send_opened_file_stream(conn, out, INT64_MAX);
+
+done:
+ if (pid != (pid_t) -1)
+ kill(pid, SIGTERM);
+ if (fd_stdin[0] != -1)
+ (void) close(fd_stdin[0]);
+ if (fd_stdout[1] != -1)
+ (void) close(fd_stdout[1]);
+
+ if (in != NULL)
+ (void) fclose(in);
+ else if (fd_stdin[1] != -1)
+ (void) close(fd_stdin[1]);
+
+ if (out != NULL)
+ (void) fclose(out);
+ else if (fd_stdout[0] != -1)
+ (void) close(fd_stdout[0]);
+}
+#endif /* !NO_CGI */
+
+/*
+ * For a given PUT path, create all intermediate subdirectories
+ * for given path. Return 0 if the path itself is a directory,
+ * or -1 on error, 1 if OK.
+ */
+static int
+put_dir(const char *path)
+{
+ char buf[FILENAME_MAX];
+ const char *s, *p;
+ struct mgstat st;
+ size_t len;
+
+ for (s = p = path + 2; (p = strchr(s, '/')) != NULL; s = ++p) {
+ len = p - path;
+ assert(len < sizeof(buf));
+ (void) memcpy(buf, path, len);
+ buf[len] = '\0';
+
+ /* Try to create intermediate directory */
+ if (mg_stat(buf, &st) == -1 && mg_mkdir(buf, 0755) != 0)
+ return (-1);
+
+ /* Is path itself a directory ? */
+ if (p[1] == '\0')
+ return (0);
+ }
+
+ return (1);
+}
+
+static void
+put_file(struct mg_connection *conn, const char *path)
+{
+ struct mgstat st;
+ FILE *fp;
+ int rc;
+
+ conn->request_info.status_code = mg_stat(path, &st) == 0 ? 200 : 201;
+
+ if (mg_get_header(conn, "Range")) {
+ send_error(conn, 501, "Not Implemented",
+ "%s", "Range support for PUT requests is not implemented");
+ } else if ((rc = put_dir(path)) == 0) {
+ (void) mg_printf(conn, "HTTP/1.1 %d OK\r\n\r\n",
+ conn->request_info.status_code);
+ } else if (rc == -1) {
+ send_error(conn, 500, http_500_error,
+ "put_dir(%s): %s", path, strerror(ERRNO));
+ } else if ((fp = mg_fopen(path, "wb+")) == NULL) {
+ send_error(conn, 500, http_500_error,
+ "fopen(%s): %s", path, strerror(ERRNO));
+ } else {
+ set_close_on_exec(fileno(fp));
+ if (handle_request_body(conn, fp))
+ (void) mg_printf(conn, "HTTP/1.1 %d OK\r\n\r\n",
+ conn->request_info.status_code);
+ (void) fclose(fp);
+ }
+}
+
+#if !defined(NO_SSI)
+static void send_ssi_file(struct mg_connection *, const char *, FILE *, int);
+
+static void
+do_ssi_include(struct mg_connection *conn, const char *ssi, char *tag,
+ int include_level)
+{
+ char file_name[BUFSIZ], path[FILENAME_MAX], *p;
+ FILE *fp;
+
+ /*
+ * sscanf() is safe here, since send_ssi_file() also uses buffer
+ * of size BUFSIZ to get the tag. So strlen(tag) is always < BUFSIZ.
+ */
+ if (sscanf(tag, " virtual=\"%[^\"]\"", file_name) == 1) {
+ /* File name is relative to the webserver root */
+ lock_option(conn->ctx, OPT_ROOT);
+ (void) mg_snprintf(conn, path, sizeof(path), "%s%c%s",
+ conn->ctx->options[OPT_ROOT], DIRSEP, file_name);
+ unlock_option(conn->ctx, OPT_ROOT);
+ } else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1) {
+ /*
+ * File name is relative to the webserver working directory
+ * or it is absolute system path
+ */
+ (void) mg_snprintf(conn, path, sizeof(path), "%s", file_name);
+ } else if (sscanf(tag, " \"%[^\"]\"", file_name) == 1) {
+ /* File name is relative to the currect document */
+ (void) mg_snprintf(conn, path, sizeof(path), "%s", ssi);
+ if ((p = strrchr(path, DIRSEP)) != NULL)
+ p[1] = '\0';
+ (void) mg_snprintf(conn, path + strlen(path),
+ sizeof(path) - strlen(path), "%s", file_name);
+ } else {
+ cry(conn, "Bad SSI #include: [%s]", tag);
+ return;
+ }
+
+ if ((fp = mg_fopen(path, "rb")) == NULL) {
+ cry(conn, "Cannot open SSI #include: [%s]: fopen(%s): %s",
+ tag, path, strerror(ERRNO));
+ } else {
+ set_close_on_exec(fileno(fp));
+ if (match_extension(path,
+ conn->ctx->options[OPT_SSI_EXTENSIONS])) {
+ send_ssi_file(conn, path, fp, include_level + 1);
+ } else {
+ send_opened_file_stream(conn, fp, INT64_MAX);
+ }
+ (void) fclose(fp);
+ }
+}
+
+static void
+do_ssi_exec(struct mg_connection *conn, char *tag)
+{
+ char cmd[BUFSIZ];
+ FILE *fp;
+
+ if (sscanf(tag, " \"%[^\"]\"", cmd) != 1) {
+ cry(conn, "Bad SSI #exec: [%s]", tag);
+ } else if ((fp = popen(cmd, "r")) == NULL) {
+ cry(conn, "Cannot SSI #exec: [%s]: %s", cmd, strerror(ERRNO));
+ } else {
+ send_opened_file_stream(conn, fp, INT64_MAX);
+ (void) pclose(fp);
+ }
+}
+
+static void
+send_ssi_file(struct mg_connection *conn, const char *path, FILE *fp,
+ int include_level)
+{
+ char buf[BUFSIZ];
+ int ch, len, in_ssi_tag;
+
+ if (include_level > 10) {
+ cry(conn, "SSI #include level is too deep (%s)", path);
+ return;
+ }
+
+ in_ssi_tag = FALSE;
+ len = 0;
+
+ while ((ch = fgetc(fp)) != EOF) {
+ if (in_ssi_tag && ch == '>') {
+ in_ssi_tag = FALSE;
+ buf[len++] = ch & 0xff;
+ buf[len] = '\0';
+ assert(len <= (int) sizeof(buf));
+ if (len < 6 || memcmp(buf, "<!--#", 5) != 0) {
+ /* Not an SSI tag, pass it */
+ (void) mg_write(conn, buf, len);
+ } else {
+ if (!memcmp(buf + 5, "include", 7)) {
+ do_ssi_include(conn, path, buf + 12,
+ include_level);
+ } else if (!memcmp(buf + 5, "exec", 4)) {
+ do_ssi_exec(conn, buf + 9);
+ } else {
+ cry(conn, "%s: unknown SSI "
+ "command: \"%s\"", path, buf);
+ }
+ }
+ len = 0;
+ } else if (in_ssi_tag) {
+ if (len == 5 && memcmp(buf, "<!--#", 5) != 0) {
+ /* Not an SSI tag */
+ in_ssi_tag = FALSE;
+ } else if (len == (int) sizeof(buf) - 2) {
+ cry(conn, "%s: SSI tag is too large", path);
+ len = 0;
+ }
+ buf[len++] = ch & 0xff;
+ } else if (ch == '<') {
+ in_ssi_tag = TRUE;
+ if (len > 0)
+ (void) mg_write(conn, buf, len);
+ len = 0;
+ buf[len++] = ch & 0xff;
+ } else {
+ buf[len++] = ch & 0xff;
+ if (len == (int) sizeof(buf)) {
+ (void) mg_write(conn, buf, len);
+ len = 0;
+ }
+ }
+ }
+
+ /* Send the rest of buffered data */
+ if (len > 0)
+ (void) mg_write(conn, buf, len);
+
+}
+
+static void
+send_ssi(struct mg_connection *conn, const char *path)
+{
+ FILE *fp;
+
+ if ((fp = mg_fopen(path, "rb")) == NULL) {
+ send_error(conn, 500, http_500_error,
+ "fopen(%s): %s", path, strerror(ERRNO));
+ } else {
+ set_close_on_exec(fileno(fp));
+ (void) mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/html\r\nConnection: close\r\n\r\n");
+ send_ssi_file(conn, path, fp, 0);
+ (void) fclose(fp);
+ }
+}
+#endif /* !NO_SSI */
+
+void
+mg_authorize(struct mg_connection *conn)
+{
+ conn->embedded_auth = TRUE;
+}
+
+static bool_t
+check_embedded_authorization(struct mg_connection *conn)
+{
+ const struct callback *cb;
+ bool_t authorized;
+
+ authorized = TRUE;
+ cb = find_callback(conn->ctx, TRUE, conn->request_info.uri, -1);
+
+ if (cb != NULL) {
+ cb->func(conn, &conn->request_info, cb->user_data);
+ authorized = conn->embedded_auth;
+ }
+
+ return (authorized);
+}
+
+/*
+ * This is the heart of the Mongoose's logic.
+ * This function is called when the request is read, parsed and validated,
+ * and Mongoose must decide what action to take: serve a file, or
+ * a directory, or call embedded function, etcetera.
+ */
+static void
+analyze_request(struct mg_connection *conn)
+{
+ struct mg_request_info *ri = &conn->request_info;
+ char path[FILENAME_MAX], *uri = ri->uri;
+ struct mgstat st;
+ const struct callback *cb;
+
+ if ((conn->request_info.query_string = strchr(uri, '?')) != NULL)
+ * conn->request_info.query_string++ = '\0';
+
+ (void) url_decode(uri, (int) strlen(uri), uri, strlen(uri) + 1, FALSE);
+ remove_double_dots_and_double_slashes(uri);
+ convert_uri_to_file_name(conn, uri, path, sizeof(path));
+
+ if (!check_authorization(conn, path)) {
+ send_authorization_request(conn);
+ } else if (check_embedded_authorization(conn) == FALSE) {
+ /*
+ * Embedded code failed authorization. Do nothing here, since
+ * an embedded code must handle this itself by either
+ * showing proper error message, or redirecting to some
+ * sort of login page, or something else.
+ */
+ } else if ((cb = find_callback(conn->ctx, FALSE, uri, -1)) != NULL) {
+ if ((strcmp(ri->request_method, "POST") != 0 &&
+ strcmp(ri->request_method, "PUT") != 0) ||
+ handle_request_body(conn, NULL))
+ cb->func(conn, &conn->request_info, cb->user_data);
+ } else if (strstr(path, PASSWORDS_FILE_NAME)) {
+ /* Do not allow to view passwords files */
+ send_error(conn, 403, "Forbidden", "Access Forbidden");
+ } else if ((!strcmp(ri->request_method, "PUT") ||
+ !strcmp(ri->request_method, "DELETE")) &&
+ (conn->ctx->options[OPT_AUTH_PUT] == NULL ||
+ !is_authorized_for_put(conn))) {
+ send_authorization_request(conn);
+ } else if (!strcmp(ri->request_method, "PUT")) {
+ put_file(conn, path);
+ } else if (!strcmp(ri->request_method, "DELETE")) {
+ if (mg_remove(path) == 0)
+ send_error(conn, 200, "OK", "");
+ else
+ send_error(conn, 500, http_500_error,
+ "remove(%s): %s", path, strerror(ERRNO));
+ } else if (mg_stat(path, &st) != 0) {
+ send_error(conn, 404, "Not Found", "%s", "File not found");
+ } else if (st.is_directory && uri[strlen(uri) - 1] != '/') {
+ (void) mg_printf(conn,
+ "HTTP/1.1 301 Moved Permanently\r\n"
+ "Location: %s/\r\n\r\n", uri);
+ } else if (st.is_directory &&
+ substitute_index_file(conn, path, sizeof(path), &st) == FALSE) {
+ if (is_true(conn->ctx->options[OPT_DIR_LIST])) {
+ send_directory(conn, path);
+ } else {
+ send_error(conn, 403, "Directory Listing Denied",
+ "Directory listing denied");
+ }
+#if !defined(NO_CGI)
+ } else if (match_extension(path,
+ conn->ctx->options[OPT_CGI_EXTENSIONS])) {
+ if (strcmp(ri->request_method, "POST") &&
+ strcmp(ri->request_method, "GET")) {
+ send_error(conn, 501, "Not Implemented",
+ "Method %s is not implemented", ri->request_method);
+ } else {
+ send_cgi(conn, path);
+ }
+#endif /* NO_CGI */
+#if !defined(NO_SSI)
+ } else if (match_extension(path,
+ conn->ctx->options[OPT_SSI_EXTENSIONS])) {
+ send_ssi(conn, path);
+#endif /* NO_SSI */
+ } else if (is_not_modified(conn, &st)) {
+ send_error(conn, 304, "Not Modified", "");
+ } else {
+ send_file(conn, path, &st);
+ }
+}
+
+static void
+close_all_listening_sockets(struct mg_context *ctx)
+{
+ int i;
+
+ for (i = 0; i < ctx->num_listeners; i++)
+ (void) closesocket(ctx->listeners[i].sock);
+ ctx->num_listeners = 0;
+}
+
+static bool_t
+set_ports_option(struct mg_context *ctx, const char *list)
+{
+ SOCKET sock;
+ int is_ssl;
+ struct vec vec;
+ struct socket *listener;
+
+ close_all_listening_sockets(ctx);
+ assert(ctx->num_listeners == 0);
+
+ while ((list = next_option(list, &vec, NULL)) != NULL) {
+
+ is_ssl = vec.ptr[vec.len - 1] == 's' ? TRUE : FALSE;
+ listener = ctx->listeners + ctx->num_listeners;
+
+ if (ctx->num_listeners >=
+ (int) (ARRAY_SIZE(ctx->listeners) - 1)) {
+ cry(fc(ctx), "%s", "Too many listeninig sockets");
+ return (FALSE);
+ } else if ((sock = mg_open_listening_port(ctx,
+ vec.ptr, &listener->lsa)) == INVALID_SOCKET) {
+ cry(fc(ctx), "cannot bind to %.*s", vec.len, vec.ptr);
+ return (FALSE);
+ } else if (is_ssl == TRUE && ctx->ssl_ctx == NULL) {
+ (void) closesocket(sock);
+ cry(fc(ctx), "cannot add SSL socket, please specify "
+ "-ssl_cert option BEFORE -ports option");
+ return (FALSE);
+ } else {
+ listener->sock = sock;
+ listener->is_ssl = is_ssl;
+ ctx->num_listeners++;
+ }
+ }
+
+ return (TRUE);
+}
+
+static void
+log_header(const struct mg_connection *conn, const char *header, FILE *fp)
+{
+ const char *header_value;
+
+ if ((header_value = mg_get_header(conn, header)) == NULL) {
+ (void) fprintf(fp, "%s", " -");
+ } else {
+ (void) fprintf(fp, " \"%s\"", header_value);
+ }
+}
+
+static void
+log_access(const struct mg_connection *conn)
+{
+ const struct mg_request_info *ri;
+ char date[64];
+
+ if (conn->ctx->access_log == NULL)
+ return;
+
+ (void) strftime(date, sizeof(date), "%d/%b/%Y:%H:%M:%S %z",
+ localtime(&conn->birth_time));
+
+ ri = &conn->request_info;
+
+ flockfile(conn->ctx->access_log);
+
+ (void) fprintf(conn->ctx->access_log,
+ "%s - %s [%s] \"%s %s HTTP/%s\" %d %" INT64_FMT,
+ inet_ntoa(conn->client.rsa.u.sin.sin_addr),
+ ri->remote_user == NULL ? "-" : ri->remote_user,
+ date,
+ ri->request_method ? ri->request_method : "-",
+ ri->uri ? ri->uri : "-",
+ ri->http_version,
+ conn->request_info.status_code, conn->num_bytes_sent);
+ log_header(conn, "Referer", conn->ctx->access_log);
+ log_header(conn, "User-Agent", conn->ctx->access_log);
+ (void) fputc('\n', conn->ctx->access_log);
+ (void) fflush(conn->ctx->access_log);
+
+ funlockfile(conn->ctx->access_log);
+}
+
+static bool_t
+isbyte(int n) {
+ return (n >= 0 && n <= 255);
+}
+
+/*
+ * Verify given socket address against the ACL.
+ * Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
+ */
+static int
+check_acl(struct mg_context *ctx, const char *list, const struct usa *usa)
+{
+ int a, b, c, d, n, mask, allowed;
+ char flag;
+ uint32_t acl_subnet, acl_mask, remote_ip;
+ struct vec vec;
+
+ (void) memcpy(&remote_ip, &usa->u.sin.sin_addr, sizeof(remote_ip));
+
+ /* If any ACL is set, deny by default */
+ allowed = '-';
+
+ while ((list = next_option(list, &vec, NULL)) != NULL) {
+
+ mask = 32;
+
+ if (sscanf(vec.ptr, "%c%d.%d.%d.%d%n",
+ &flag, &a, &b, &c, &d, &n) != 5) {
+ cry(fc(ctx),
+ "%s: subnet must be [+|-]x.x.x.x[/x]", __func__);
+ return (-1);
+ } else if (flag != '+' && flag != '-') {
+ cry(fc(ctx), "%s: flag must be + or -: [%s]",
+ __func__, vec.ptr);
+ return (-1);
+ } else if (!isbyte(a)||!isbyte(b)||!isbyte(c)||!isbyte(d)) {
+ cry(fc(ctx),
+ "%s: bad ip address: [%s]", __func__, vec.ptr);
+ return (-1);
+ } else if (sscanf(vec.ptr + n, "/%d", &mask) == 0) {
+ /* Do nothing, no mask specified */
+ } else if (mask < 0 || mask > 32) {
+ cry(fc(ctx), "%s: bad subnet mask: %d [%s]",
+ __func__, n, vec.ptr);
+ return (-1);
+ }
+
+ acl_subnet = ((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d;
+ acl_mask = mask ? 0xffffffffU << (32 - mask) : 0;
+
+ if (acl_subnet == (ntohl(remote_ip) & acl_mask))
+ allowed = flag;
+ }
+
+ return (allowed == '+' ? 1 : 0);
+}
+
+static void
+add_to_set(SOCKET fd, fd_set *set, int *max_fd)
+{
+ FD_SET(fd, set);
+ if (fd > (SOCKET) *max_fd)
+ *max_fd = (int) fd;
+}
+
+/*
+ * Deallocate mongoose context, free up the resources
+ */
+static void
+mg_fini(struct mg_context *ctx)
+{
+ int i;
+
+ close_all_listening_sockets(ctx);
+
+ /* Wait until all threads finish */
+ (void) pthread_mutex_lock(&ctx->thr_mutex);
+ while (ctx->num_threads > 0)
+ (void) pthread_cond_wait(&ctx->thr_cond, &ctx->thr_mutex);
+ (void) pthread_mutex_unlock(&ctx->thr_mutex);
+
+ /* Deallocate all registered callbacks */
+ for (i = 0; i < ctx->num_callbacks; i++)
+ if (ctx->callbacks[i].uri_regex != NULL)
+ free(ctx->callbacks[i].uri_regex);
+
+ /* Deallocate all options */
+ for (i = 0; i < NUM_OPTIONS; i++)
+ if (ctx->options[i] != NULL)
+ free(ctx->options[i]);
+
+ /* Close log files */
+ if (ctx->access_log)
+ (void) fclose(ctx->access_log);
+ if (ctx->error_log)
+ (void) fclose(ctx->error_log);
+
+ /* Deallocate SSL context */
+ if (ctx->ssl_ctx)
+ SSL_CTX_free(ctx->ssl_ctx);
+
+ /* Deallocate mutexes and condvars */
+ for (i = 0; i < NUM_OPTIONS; i++)
+ (void) pthread_mutex_destroy(&ctx->opt_mutex[i]);
+
+ (void) pthread_mutex_destroy(&ctx->thr_mutex);
+ (void) pthread_mutex_destroy(&ctx->bind_mutex);
+ (void) pthread_cond_destroy(&ctx->thr_cond);
+ (void) pthread_cond_destroy(&ctx->empty_cond);
+ (void) pthread_cond_destroy(&ctx->full_cond);
+
+ /* Signal mg_stop() that we're done */
+ ctx->stop_flag = 2;
+}
+
+#if !defined(_WIN32)
+static bool_t
+set_uid_option(struct mg_context *ctx, const char *uid)
+{
+ struct passwd *pw;
+ int retval = FALSE;
+
+ if ((pw = getpwnam(uid)) == NULL)
+ cry(fc(ctx), "%s: unknown user [%s]", __func__, uid);
+ else if (setgid(pw->pw_gid) == -1)
+ cry(fc(ctx), "%s: setgid(%s): %s",
+ __func__, uid, strerror(errno));
+ else if (setuid(pw->pw_uid) == -1)
+ cry(fc(ctx), "%s: setuid(%s): %s",
+ __func__, uid, strerror(errno));
+ else
+ retval = TRUE;
+
+ return (retval);
+}
+#endif /* !_WIN32 */
+
+#if !defined(NO_SSL)
+void
+mg_set_ssl_password_callback(struct mg_context *ctx, mg_spcb_t func)
+{
+ ctx->ssl_password_callback = func;
+}
+
+static pthread_mutex_t *ssl_mutexes;
+
+static void
+ssl_locking_callback(int mode, int mutex_num, const char *file, int line)
+{
+ line = 0; /* Unused */
+ file = NULL; /* Unused */
+
+ if (mode & CRYPTO_LOCK)
+ (void) pthread_mutex_lock(&ssl_mutexes[mutex_num]);
+ else
+ (void) pthread_mutex_unlock(&ssl_mutexes[mutex_num]);
+}
+
+static unsigned long
+ssl_id_callback(void)
+{
+ return ((unsigned long) pthread_self());
+}
+
+static bool_t
+load_dll(struct mg_context *ctx, const char *dll_name, struct ssl_func *sw)
+{
+ union {void *p; void (*fp)(void);} u;
+ void *dll_handle;
+ struct ssl_func *fp;
+
+ if ((dll_handle = dlopen(dll_name, RTLD_LAZY)) == NULL) {
+ cry(fc(ctx), "%s: cannot load %s", __func__, dll_name);
+ return (FALSE);
+ }
+
+ for (fp = sw; fp->name != NULL; fp++) {
+#ifdef _WIN32
+ /* GetProcAddress() returns pointer to function */
+ u.fp = (void (*)(void)) dlsym(dll_handle, fp->name);
+#else
+ /*
+ * dlsym() on UNIX returns void *.
+ * ISO C forbids casts of data pointers to function
+ * pointers. We need to use a union to make a cast.
+ */
+ u.p = dlsym(dll_handle, fp->name);
+#endif /* _WIN32 */
+ if (u.fp == NULL) {
+ cry(fc(ctx), "%s: cannot find %s", __func__, fp->name);
+ return (FALSE);
+ } else {
+ fp->ptr = u.fp;
+ }
+ }
+
+ return (TRUE);
+}
+
+/*
+ * Dynamically load SSL library. Set up ctx->ssl_ctx pointer.
+ */
+static bool_t
+set_ssl_option(struct mg_context *ctx, const char *pem)
+{
+ SSL_CTX *CTX;
+ int i, size, retval = FALSE;
+
+ if (load_dll(ctx, SSL_LIB, ssl_sw) == FALSE ||
+ load_dll(ctx, CRYPTO_LIB, crypto_sw) == FALSE)
+ return (FALSE);
+
+ /* Initialize SSL crap */
+ SSL_library_init();
+
+ if ((CTX = SSL_CTX_new(SSLv23_server_method())) == NULL)
+ cry(fc(ctx), "SSL_CTX_new error");
+ else if (ctx->ssl_password_callback != NULL)
+ SSL_CTX_set_default_passwd_cb(CTX, ctx->ssl_password_callback);
+
+ if (CTX != NULL && SSL_CTX_use_certificate_file(
+ CTX, pem, SSL_FILETYPE_PEM) == 0)
+ cry(fc(ctx), "%s: cannot open %s", __func__, pem);
+ else if (CTX != NULL && SSL_CTX_use_PrivateKey_file(
+ CTX, pem, SSL_FILETYPE_PEM) == 0)
+ cry(fc(ctx), "%s: cannot open %s", NULL, pem);
+ else
+ retval = TRUE;
+
+ /*
+ * Initialize locking callbacks, needed for thread safety.
+ * http://www.openssl.org/support/faq.html#PROG1
+ */
+ size = sizeof(pthread_mutex_t) * CRYPTO_num_locks();
+ if ((ssl_mutexes = (pthread_mutex_t *) malloc(size)) == NULL) {
+ cry(fc(ctx), "%s: cannot allocate mutexes", __func__);
+ return (FALSE);
+ }
+
+ for (i = 0; i < CRYPTO_num_locks(); i++)
+ pthread_mutex_init(&ssl_mutexes[i], NULL);
+
+ CRYPTO_set_locking_callback(&ssl_locking_callback);
+ CRYPTO_set_id_callback(&ssl_id_callback);
+
+ /* Done with everything. Save the context. */
+ ctx->ssl_ctx = CTX;
+
+ return (retval);
+}
+#endif /* !NO_SSL */
+
+static bool_t
+open_log_file(struct mg_context *ctx, FILE **fpp, const char *path)
+{
+ bool_t retval = TRUE;
+
+ if (*fpp != NULL)
+ (void) fclose(*fpp);
+
+ if (path == NULL) {
+ *fpp = NULL;
+ } else if ((*fpp = mg_fopen(path, "a")) == NULL) {
+ cry(fc(ctx), "%s(%s): %s", __func__, path, strerror(errno));
+ retval = FALSE;
+ } else {
+ set_close_on_exec(fileno(*fpp));
+ }
+
+ return (retval);
+}
+
+static bool_t
+set_alog_option(struct mg_context *ctx, const char *path)
+{
+ return (open_log_file(ctx, &ctx->access_log, path));
+}
+
+static bool_t
+set_elog_option(struct mg_context *ctx, const char *path)
+{
+ return (open_log_file(ctx, &ctx->error_log, path));
+}
+
+static bool_t
+set_gpass_option(struct mg_context *ctx, const char *path)
+{
+ struct mgstat mgstat;
+ ctx = NULL;
+ return (mg_stat(path, &mgstat) == 0);
+}
+
+static bool_t
+set_max_threads_option(struct mg_context *ctx, const char *str)
+{
+ ctx->max_threads = atoi(str);
+ return (TRUE);
+}
+
+static bool_t
+set_acl_option(struct mg_context *ctx, const char *acl)
+{
+ struct usa fake;
+
+ return (check_acl(ctx, acl, &fake) != -1);
+}
+
+static void admin_page(struct mg_connection *,
+ const struct mg_request_info *, void *);
+static bool_t
+set_admin_uri_option(struct mg_context *ctx, const char *uri)
+{
+ mg_set_uri_callback(ctx, uri, &admin_page, NULL);
+ return (TRUE);
+}
+
+/*
+ * Check if the comma-separated list of options has a format of key-value
+ * pairs: "k1=v1,k2=v2". Return FALSE if any entry has invalid key or value.
+ */
+static bool_t
+set_kv_list_option(struct mg_context *ctx, const char *str)
+{
+ const char *list;
+ struct vec key, value;
+
+ list = str;
+ while ((list = next_option(list, &key, &value)) != NULL)
+ if (key.len == 0 || value.len == 0) {
+ cry(fc(ctx), "Invalid list specified: [%s], "
+ "expecting key1=value1,key2=value2,...", str);
+ return (FALSE);
+ }
+
+ return (TRUE);
+}
+
+static const struct mg_option known_options[] = {
+ {"root", "\tWeb root directory", ".", OPT_ROOT, NULL},
+ {"index_files", "Index files", "index.html,index.htm,index.cgi",
+ OPT_INDEX_FILES, NULL},
+#if !defined(NO_SSL)
+ {"ssl_cert", "SSL certificate file", NULL,
+ OPT_SSL_CERTIFICATE, &set_ssl_option},
+#endif /* !NO_SSL */
+ {"ports", "Listening ports", NULL,
+ OPT_PORTS, &set_ports_option},
+ {"dir_list", "Directory listing", "yes",
+ OPT_DIR_LIST, NULL},
+ {"protect", "URI to htpasswd mapping", NULL,
+ OPT_PROTECT, &set_kv_list_option},
+#if !defined(NO_CGI)
+ {"cgi_ext", "CGI extensions", ".cgi,.pl,.php",
+ OPT_CGI_EXTENSIONS, NULL},
+ {"cgi_interp", "CGI interpreter to use with all CGI scripts", NULL,
+ OPT_CGI_INTERPRETER, NULL},
+ {"cgi_env", "Custom CGI enviroment variables", NULL,
+ OPT_CGI_ENV, &set_kv_list_option},
+#endif /* NO_CGI */
+ {"ssi_ext", "SSI extensions", ".shtml,.shtm",
+ OPT_SSI_EXTENSIONS, NULL},
+ {"auth_realm", "Authentication domain name", "mydomain.com",
+ OPT_AUTH_DOMAIN, NULL},
+ {"auth_gpass", "Global passwords file", NULL,
+ OPT_AUTH_GPASSWD, &set_gpass_option},
+ {"auth_PUT", "PUT,DELETE auth file", NULL,
+ OPT_AUTH_PUT, NULL},
+#if !defined(_WIN32)
+ {"uid", "\tRun as user", NULL, OPT_UID, &set_uid_option},
+#endif /* !_WIN32 */
+ {"access_log", "Access log file", NULL,
+ OPT_ACCESS_LOG, &set_alog_option},
+ {"error_log", "Error log file", NULL,
+ OPT_ERROR_LOG, &set_elog_option},
+ {"aliases", "Path=URI mappings", NULL,
+ OPT_ALIASES, &set_kv_list_option},
+ {"admin_uri", "Administration page URI", NULL,
+ OPT_ADMIN_URI, &set_admin_uri_option},
+ {"acl", "\tAllow/deny IP addresses/subnets", NULL,
+ OPT_ACL, &set_acl_option},
+ {"max_threads", "Maximum simultaneous threads to spawn", "100",
+ OPT_MAX_THREADS, &set_max_threads_option},
+ {"idle_time", "Time in seconds connection stays idle", "10",
+ OPT_IDLE_TIME, NULL},
+ {"mime_types", "Comma separated list of ext=mime_type pairs", NULL,
+ OPT_MIME_TYPES, &set_kv_list_option},
+ {NULL, NULL, NULL, 0, NULL}
+};
+
+static const struct mg_option *
+find_opt(const char *opt_name)
+{
+ int i;
+
+ for (i = 0; known_options[i].name != NULL; i++)
+ if (!strcmp(opt_name, known_options[i].name))
+ return (known_options + i);
+
+ return (NULL);
+}
+
+int
+mg_set_option(struct mg_context *ctx, const char *opt, const char *val)
+{
+ const struct mg_option *option;
+ int i, retval;
+
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: [%s]->[%s]", __func__, opt, val));
+ if (opt != NULL && (option = find_opt(opt)) != NULL) {
+ i = (int) (option - known_options);
+ lock_option(ctx, i);
+
+ if (option->setter != NULL)
+ retval = option->setter(ctx, val);
+ else
+ retval = TRUE;
+
+ /* Free old value if any */
+ if (ctx->options[option->index] != NULL)
+ free(ctx->options[option->index]);
+
+ /* Set new option value */
+ ctx->options[option->index] = val ? mg_strdup(val) : NULL;
+ unlock_option(ctx, i);
+
+ if (retval == FALSE)
+ cry(fc(ctx), "%s(%s): failure", __func__, opt);
+ } else {
+ cry(fc(ctx), "%s: No such option: [%s]", __func__, opt);
+ retval = -1;
+ }
+
+ return (retval);
+}
+
+void
+mg_show_usage_string(FILE *fp)
+{
+ const struct mg_option *o;
+
+ (void) fprintf(stderr,
+ "Mongoose version %s (c) Sergey Lyubka\n"
+ "usage: mongoose [options] [config_file]\n", mg_version());
+
+ fprintf(fp, " -A <htpasswd_file> <realm> <user> <passwd>\n");
+
+ for (o = known_options; o->name != NULL; o++) {
+ (void) fprintf(fp, " -%s\t%s", o->name, o->description);
+ if (o->default_value != NULL)
+ fprintf(fp, " (default: \"%s\")", o->default_value);
+ fputc('\n', fp);
+ }
+}
+
+const char *
+mg_get_option(const struct mg_context *ctx, const char *option_name)
+{
+ const struct mg_option *option;
+
+ if ((option = find_opt(option_name)) != NULL)
+ return (ctx->options[option->index]);
+ else
+ return (NULL);
+}
+
+static void
+admin_page(struct mg_connection *conn, const struct mg_request_info *ri,
+ void *user_data)
+{
+ const struct mg_option *option;
+ const char *option_name, *option_value;
+
+ user_data = NULL; /* Unused */
+
+ (void) mg_printf(conn,
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/html\r\n\r\n"
+ "<html><body><h1>Mongoose v. %s</h1>", mg_version());
+
+ if (!strcmp(ri->request_method, "POST")) {
+ option_name = mg_get_var(conn, "o");
+ option_value = mg_get_var(conn, "v");
+ if (mg_set_option(conn->ctx,
+ option_name, option_value) == -1) {
+ (void) mg_printf(conn,
+ "<p style=\"background: red\">Error setting "
+ "option \"%s\"</p>",
+ option_name ? option_name : "(null)");
+ } else {
+ (void) mg_printf(conn,
+ "<p style=\"color: green\">Saved: %s=%s</p>",
+ option_name, option_value ? option_value : "NULL");
+ }
+ }
+
+ /* Print table with all options */
+ (void) mg_printf(conn, "%s", "<table border=\"1\""
+ "<tr><th>Option</th><th>Description</th>"
+ "<th colspan=2>Value</th></tr>");
+
+ for (option = known_options; option->name != NULL; option++) {
+ option_value = mg_get_option(conn->ctx, option->name);
+ if (option_value == NULL)
+ option_value = "";
+ (void) mg_printf(conn,
+ "<form method=post><tr><td>%s</td><td>%s</td>"
+ "<input type=hidden name=o value='%s'>"
+ "<td><input type=text name=v value='%s'></td>"
+ "<td><input type=submit value=save></td></form></tr>",
+ option->name, option->description,
+ option->name, option_value);
+ }
+
+ (void) mg_printf(conn, "%s", "</table></body></html>");
+}
+
+static void
+reset_per_request_attributes(struct mg_connection *conn)
+{
+ if (conn->request_info.remote_user != NULL) {
+ free((void *) conn->request_info.remote_user);
+ conn->request_info.remote_user = NULL;
+ }
+ if (conn->free_post_data && conn->request_info.post_data != NULL) {
+ free((void *) conn->request_info.post_data);
+ conn->request_info.post_data = NULL;
+ }
+}
+
+static void
+close_socket_gracefully(struct mg_connection *conn, SOCKET sock)
+{
+ char buf[BUFSIZ];
+ int n;
+
+ /* Send FIN to the client */
+ (void) shutdown(sock, SHUT_WR);
+ set_non_blocking_mode(conn, sock);
+
+ /*
+ * Read and discard pending data. If we do not do that and close the
+ * socket, the data in the send buffer may be discarded. This
+ * behaviour is seen on Windows, when client keeps sending data
+ * when server decide to close the connection; then when client
+ * does recv() it gets no data back.
+ */
+ do {
+ n = pull(NULL, sock, NULL, buf, sizeof(buf));
+ } while (n > 0);
+
+ /* Now we know that our FIN is ACK-ed, safe to close */
+ (void) closesocket(sock);
+}
+
+static void
+close_connection(struct mg_connection *conn)
+{
+ reset_per_request_attributes(conn);
+
+ if (conn->ssl)
+ SSL_free(conn->ssl);
+
+ if (conn->client.sock != INVALID_SOCKET)
+ close_socket_gracefully(conn, conn->client.sock);
+}
+
+static void
+reset_connection_attributes(struct mg_connection *conn)
+{
+ reset_per_request_attributes(conn);
+ conn->free_post_data = FALSE;
+ conn->request_info.status_code = -1;
+ conn->num_bytes_sent = 0;
+ (void) memset(&conn->request_info, 0, sizeof(conn->request_info));
+}
+
+static void
+shift_to_next(struct mg_connection *conn, char *buf, int req_len, int *nread)
+{
+ int64_t cl;
+ int over_len, body_len;
+
+ cl = get_content_length(conn);
+ over_len = *nread - req_len;
+ assert(over_len >= 0);
+
+ if (cl == -1) {
+ body_len = 0;
+ } else if (cl < (int64_t) over_len) {
+ body_len = (int) cl;
+ } else {
+ body_len = over_len;
+ }
+
+ *nread -= req_len + body_len;
+ (void) memmove(buf, buf + req_len + body_len, *nread);
+}
+
+static void
+process_new_connection(struct mg_connection *conn)
+{
+ struct mg_request_info *ri = &conn->request_info;
+ char buf[MAX_REQUEST_SIZE];
+ int request_len, nread;
+
+ nread = 0;
+ reset_connection_attributes(conn);
+
+ /* If next request is not pipelined, read it in */
+ if ((request_len = get_request_len(buf, (size_t) nread)) == 0)
+ request_len = read_request(NULL, conn->client.sock,
+ conn->ssl, buf, sizeof(buf), &nread);
+ assert(nread >= request_len);
+
+ if (request_len <= 0)
+ return; /* Remote end closed the connection */
+
+ /* 0-terminate the request: parse_request uses sscanf */
+ buf[request_len - 1] = '\0';
+
+ if (parse_http_request(buf, ri, &conn->client.rsa)) {
+ if (strcmp(ri->http_version, "1.0") != 0 &&
+ strcmp(ri->http_version, "1.1") != 0) {
+ send_error(conn, 505,
+ "HTTP version not supported",
+ "%s", "Weird HTTP version");
+ log_access(conn);
+ } else {
+ ri->post_data = buf + request_len;
+ ri->post_data_len = nread - request_len;
+ conn->birth_time = time(NULL);
+ analyze_request(conn);
+ log_access(conn);
+ shift_to_next(conn, buf, request_len, &nread);
+ }
+ } else {
+ /* Do not put garbage in the access log */
+ send_error(conn, 400, "Bad Request",
+ "Can not parse request: [%.*s]", nread, buf);
+ }
+
+}
+
+/*
+ * Worker threads take accepted socket from the queue
+ */
+static bool_t
+get_socket(struct mg_context *ctx, struct socket *sp)
+{
+ struct timespec ts;
+
+ (void) pthread_mutex_lock(&ctx->thr_mutex);
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: thread %p: going idle",
+ __func__, (void *) pthread_self()));
+
+ /* If the queue is empty, wait. We're idle at this point. */
+ ctx->num_idle++;
+ while (ctx->sq_head == ctx->sq_tail) {
+ ts.tv_nsec = 0;
+ ts.tv_sec = time(NULL) + atoi(ctx->options[OPT_IDLE_TIME]) + 1;
+ if (pthread_cond_timedwait(&ctx->empty_cond,
+ &ctx->thr_mutex, &ts) != 0) {
+ /* Timeout! release the mutex and return */
+ (void) pthread_mutex_unlock(&ctx->thr_mutex);
+ return (FALSE);
+ }
+ }
+ assert(ctx->sq_head > ctx->sq_tail);
+
+ /* We're going busy now: got a socket to process! */
+ ctx->num_idle--;
+
+ /* Copy socket from the queue and increment tail */
+ *sp = ctx->queue[ctx->sq_tail % ARRAY_SIZE(ctx->queue)];
+ ctx->sq_tail++;
+ DEBUG_TRACE((DEBUG_MGS_PREFIX
+ "%s: thread %p grabbed socket %d, going busy",
+ __func__, (void *) pthread_self(), sp->sock));
+
+ /* Wrap pointers if needed */
+ while (ctx->sq_tail > (int) ARRAY_SIZE(ctx->queue)) {
+ ctx->sq_tail -= ARRAY_SIZE(ctx->queue);
+ ctx->sq_head -= ARRAY_SIZE(ctx->queue);
+ }
+
+ pthread_cond_signal(&ctx->full_cond);
+ (void) pthread_mutex_unlock(&ctx->thr_mutex);
+
+ return (TRUE);
+}
+
+static void
+worker_thread(struct mg_context *ctx)
+{
+ struct mg_connection conn;
+
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: thread %p starting",
+ __func__, (void *) pthread_self()));
+
+ (void) memset(&conn, 0, sizeof(conn));
+
+ while (get_socket(ctx, &conn.client) == TRUE) {
+ conn.birth_time = time(NULL);
+ conn.ctx = ctx;
+
+ if (conn.client.is_ssl &&
+ (conn.ssl = SSL_new(conn.ctx->ssl_ctx)) == NULL) {
+ cry(&conn, "%s: SSL_new: %d", __func__, ERRNO);
+ } else if (conn.client.is_ssl &&
+ SSL_set_fd(conn.ssl, conn.client.sock) != 1) {
+ cry(&conn, "%s: SSL_set_fd: %d", __func__, ERRNO);
+ } else if (conn.client.is_ssl && SSL_accept(conn.ssl) != 1) {
+ cry(&conn, "%s: SSL handshake error", __func__);
+ } else {
+ process_new_connection(&conn);
+ }
+
+ close_connection(&conn);
+ }
+
+ /* Signal master that we're done with connection and exiting */
+ pthread_mutex_lock(&ctx->thr_mutex);
+ ctx->num_threads--;
+ ctx->num_idle--;
+ pthread_cond_signal(&ctx->thr_cond);
+ assert(ctx->num_threads >= 0);
+ pthread_mutex_unlock(&ctx->thr_mutex);
+
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: thread %p exiting",
+ __func__, (void *) pthread_self()));
+}
+
+/*
+ * Master thread adds accepted socket to a queue
+ */
+static void
+put_socket(struct mg_context *ctx, const struct socket *sp)
+{
+ (void) pthread_mutex_lock(&ctx->thr_mutex);
+
+ /* If the queue is full, wait */
+ while (ctx->sq_head - ctx->sq_tail >= (int) ARRAY_SIZE(ctx->queue))
+ (void) pthread_cond_wait(&ctx->full_cond, &ctx->thr_mutex);
+ assert(ctx->sq_head - ctx->sq_tail < (int) ARRAY_SIZE(ctx->queue));
+
+ /* Copy socket to the queue and increment head */
+ ctx->queue[ctx->sq_head % ARRAY_SIZE(ctx->queue)] = *sp;
+ ctx->sq_head++;
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: queued socket %d",
+ __func__, sp->sock));
+
+ /* If there are no idle threads, start one */
+ if (ctx->num_idle == 0 && ctx->num_threads < ctx->max_threads) {
+ if (start_thread(ctx,
+ (mg_thread_func_t) worker_thread, ctx) != 0)
+ cry(fc(ctx), "Cannot start thread: %d", ERRNO);
+ else
+ ctx->num_threads++;
+ }
+
+ pthread_cond_signal(&ctx->empty_cond);
+ (void) pthread_mutex_unlock(&ctx->thr_mutex);
+}
+
+static void
+accept_new_connection(const struct socket *listener, struct mg_context *ctx)
+{
+ struct socket accepted;
+
+ accepted.rsa.len = sizeof(accepted.rsa.u.sin);
+ accepted.lsa = listener->lsa;
+ if ((accepted.sock = accept(listener->sock,
+ &accepted.rsa.u.sa, &accepted.rsa.len)) == INVALID_SOCKET)
+ return;
+
+ lock_option(ctx, OPT_ACL);
+ if (ctx->options[OPT_ACL] != NULL &&
+ !check_acl(ctx, ctx->options[OPT_ACL], &accepted.rsa)) {
+ cry(fc(ctx), "%s: %s is not allowed to connect",
+ __func__, inet_ntoa(accepted.rsa.u.sin.sin_addr));
+ (void) closesocket(accepted.sock);
+ unlock_option(ctx, OPT_ACL);
+ return;
+ }
+ unlock_option(ctx, OPT_ACL);
+
+ /* Put accepted socket structure into the queue */
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: accepted socket %d",
+ __func__, accepted.sock));
+ accepted.is_ssl = listener->is_ssl;
+ put_socket(ctx, &accepted);
+}
+
+static void
+master_thread(struct mg_context *ctx)
+{
+ fd_set read_set;
+ struct timeval tv;
+ int i, max_fd;
+
+ while (ctx->stop_flag == 0) {
+ FD_ZERO(&read_set);
+ max_fd = -1;
+
+ /* Add listening sockets to the read set */
+ lock_option(ctx, OPT_PORTS);
+ for (i = 0; i < ctx->num_listeners; i++)
+ add_to_set(ctx->listeners[i].sock, &read_set, &max_fd);
+ unlock_option(ctx, OPT_PORTS);
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+
+ if (select(max_fd + 1, &read_set, NULL, NULL, &tv) < 0) {
+#ifdef _WIN32
+ /*
+ * On windows, if read_set and write_set are empty,
+ * select() returns "Invalid parameter" error
+ * (at least on my Windows XP Pro). So in this case,
+ * we sleep here.
+ */
+ sleep(1);
+#endif /* _WIN32 */
+ } else {
+ lock_option(ctx, OPT_PORTS);
+ for (i = 0; i < ctx->num_listeners; i++)
+ if (FD_ISSET(ctx->listeners[i].sock, &read_set))
+ accept_new_connection(
+ ctx->listeners + i, ctx);
+ unlock_option(ctx, OPT_PORTS);
+ }
+ }
+
+ /* Stop signal received: somebody called mg_stop. Quit. */
+ mg_fini(ctx);
+}
+
+void
+mg_stop(struct mg_context *ctx)
+{
+ ctx->stop_flag = 1;
+
+ /* Wait until mg_fini() stops */
+ while (ctx->stop_flag != 2)
+ (void) sleep(1);
+
+ assert(ctx->num_threads == 0);
+ free(ctx);
+
+#if defined(_WIN32)
+ (void) WSACleanup();
+#endif /* _WIN32 */
+}
+
+struct mg_context *
+mg_start(void)
+{
+ struct mg_context *ctx;
+ const struct mg_option *option;
+ int i;
+
+#if defined(_WIN32)
+ WSADATA data;
+ WSAStartup(MAKEWORD(2,2), &data);
+#endif /* _WIN32 */
+
+ if ((ctx = (struct mg_context *) calloc(1, sizeof(*ctx))) == NULL) {
+ cry(fc(ctx), "cannot allocate mongoose context");
+ return (NULL);
+ }
+
+ ctx->error_log = stderr;
+ mg_set_log_callback(ctx, builtin_error_log);
+
+ /* Initialize options. First pass: set default option values */
+ for (option = known_options; option->name != NULL; option++)
+ ctx->options[option->index] = option->default_value == NULL ?
+ NULL : mg_strdup(option->default_value);
+
+ /* Call setter functions */
+ for (option = known_options; option->name != NULL; option++)
+ if (option->setter != NULL &&
+ ctx->options[option->index] != NULL)
+ if (option->setter(ctx,
+ ctx->options[option->index]) == FALSE) {
+ mg_fini(ctx);
+ return (NULL);
+ }
+
+ DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: root [%s]",
+ __func__, ctx->options[OPT_ROOT]));
+
+#if !defined(_WIN32)
+ /*
+ * Ignore SIGPIPE signal, so if browser cancels the request, it
+ * won't kill the whole process.
+ */
+ (void) signal(SIGPIPE, SIG_IGN);
+#endif /* _WIN32 */
+
+ /* Initialize options mutexes */
+ for (i = 0; i < NUM_OPTIONS; i++)
+ (void) pthread_mutex_init(&ctx->opt_mutex[i], NULL);
+
+ (void) pthread_mutex_init(&ctx->thr_mutex, NULL);
+ (void) pthread_mutex_init(&ctx->bind_mutex, NULL);
+ (void) pthread_cond_init(&ctx->thr_cond, NULL);
+ (void) pthread_cond_init(&ctx->empty_cond, NULL);
+ (void) pthread_cond_init(&ctx->full_cond, NULL);
+
+ /* Start master (listening) thread */
+ start_thread(ctx, (mg_thread_func_t) master_thread, ctx);
+
+ return (ctx);
+}
diff --git a/cpukit/mghttpd/mongoose.h b/cpukit/mghttpd/mongoose.h
new file mode 100644
index 0000000000..6ff2c28d7f
--- /dev/null
+++ b/cpukit/mghttpd/mongoose.h
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 2004-2009 Sergey Lyubka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * $Id$
+ */
+
+#ifndef MONGOOSE_HEADER_INCLUDED
+#define MONGOOSE_HEADER_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct mg_context; /* Handle for the HTTP service itself */
+struct mg_connection; /* Handle for the individual connection */
+
+
+/*
+ * This structure contains full information about the HTTP request.
+ * It is passed to the user-specified callback function as a parameter.
+ */
+struct mg_request_info {
+ char *request_method; /* "GET", "POST", etc */
+ char *uri; /* Normalized URI */
+ char *http_version; /* E.g. "1.0", "1.1" */
+ char *query_string; /* \0 - terminated */
+ char *post_data; /* POST data buffer */
+ char *remote_user; /* Authenticated user */
+ long remote_ip; /* Client's IP address */
+ int remote_port; /* Client's port */
+ int post_data_len; /* POST buffer length */
+ int status_code; /* HTTP status code */
+ int num_headers; /* Number of headers */
+ struct mg_header {
+ char *name; /* HTTP header name */
+ char *value; /* HTTP header value */
+ } http_headers[64]; /* Maximum 64 headers */
+};
+
+
+/*
+ * User-defined callback function prototype for URI handling, error handling,
+ * or logging server messages.
+ */
+typedef void (*mg_callback_t)(struct mg_connection *,
+ const struct mg_request_info *info, void *user_data);
+
+
+/*
+ * Start the web server.
+ * This must be the first function called by the application.
+ * It creates a serving thread, and returns a context structure that
+ * can be used to alter the configuration, and stop the server.
+ */
+struct mg_context *mg_start(void);
+
+
+/*
+ * Stop the web server.
+ * Must be called last, when an application wants to stop the web server and
+ * release all associated resources. This function blocks until all Mongoose
+ * threads are stopped. Context pointer becomes invalid.
+ */
+void mg_stop(struct mg_context *);
+
+
+/*
+ * Return current value of a particular option.
+ */
+const char *mg_get_option(const struct mg_context *, const char *option_name);
+
+
+/*
+ * Set a value for a particular option.
+ * Mongoose makes an internal copy of the option value string, which must be
+ * valid nul-terminated ASCII or UTF-8 string. It is safe to change any option
+ * at any time. The order of setting various options is also irrelevant with
+ * one exception: if "ports" option contains SSL listening ports, a "ssl_cert"
+ * option must be set BEFORE the "ports" option.
+ * Return value:
+ * -1 if option is unknown
+ * 0 if mg_set_option() failed
+ * 1 if mg_set_option() succeeded
+ */
+int mg_set_option(struct mg_context *, const char *opt_name, const char *value);
+
+
+/*
+ * Add, edit or delete the entry in the passwords file.
+ * This function allows an application to manipulate .htpasswd files on the
+ * fly by adding, deleting and changing user records. This is one of the two
+ * ways of implementing authentication on the server side. For another,
+ * cookie-based way please refer to the examples/authentication.c in the
+ * source tree.
+ * If password is not NULL, entry is added (or modified if already exists).
+ * If password is NULL, entry is deleted. Return:
+ * 1 on success
+ * 0 on error
+ */
+int mg_modify_passwords_file(struct mg_context *ctx, const char *file_name,
+ const char *user_name, const char *password);
+
+
+/*
+ * Register URI handler.
+ * It is possible to handle many URIs if using * in the uri_regex, which
+ * matches zero or more characters. user_data pointer will be passed to the
+ * handler as a third parameter. If func is NULL, then the previously installed
+ * handler for this uri_regex is removed.
+ */
+void mg_set_uri_callback(struct mg_context *ctx, const char *uri_regex,
+ mg_callback_t func, void *user_data);
+
+
+/*
+ * Register HTTP error handler.
+ * An application may use that function if it wants to customize the error
+ * page that user gets on the browser (for example, 404 File Not Found message).
+ * It is possible to specify a error handler for all errors by passing 0 as
+ * error_code. That '0' error handler must be set last, if more specific error
+ * handlers are also used. The actual error code value can be taken from
+ * the request info structure that is passed to the callback.
+ */
+void mg_set_error_callback(struct mg_context *ctx, int error_code,
+ mg_callback_t func, void *user_data);
+
+
+/*
+ * Register authorization handler.
+ * This function provides a mechanism to implement custom authorization,
+ * for example cookie based (look at examples/authorization.c).
+ * The callback function must analyze the request, and make its own judgement
+ * on wether it should be authorized or not. After the decision is made, a
+ * callback must call mg_authorize() if the request is authorized.
+ */
+void mg_set_auth_callback(struct mg_context *ctx, const char *uri_regex,
+ mg_callback_t func, void *user_data);
+
+
+/*
+ * Register log handler.
+ * By default, Mongoose logs all error messages to stderr. If "error_log"
+ * option is specified, the errors are written in the specified file. However,
+ * if an application registers its own log handler, Mongoose will not log
+ * anything but call the handler function, passing an error message as
+ * "user_data" callback argument.
+ */
+void mg_set_log_callback(struct mg_context *ctx, mg_callback_t func);
+
+
+/*
+ * Register SSL password handler.
+ * This is needed only if SSL certificate asks for a password. Instead of
+ * prompting for a password on a console a specified function will be called.
+ */
+typedef int (*mg_spcb_t)(char *buf, int num, int w, void *key);
+void mg_set_ssl_password_callback(struct mg_context *ctx, mg_spcb_t func);
+
+
+/*
+ * Send data to the browser.
+ * Return number of bytes sent. If the number of bytes sent is less then
+ * requested or equals to -1, network error occured, usually meaning the
+ * remote side has closed the connection.
+ */
+int mg_write(struct mg_connection *, const void *buf, int len);
+
+
+/*
+ * Send data to the browser using printf() semantics.
+ * Works exactly like mg_write(), but allows to do message formatting.
+ * Note that mg_printf() uses internal buffer of size MAX_REQUEST_SIZE
+ * (8 Kb by default) as temporary message storage for formatting. Do not
+ * print data that is bigger than that, otherwise it will be truncated.
+ * Return number of bytes sent.
+ */
+int mg_printf(struct mg_connection *, const char *fmt, ...);
+
+
+/*
+ * Read data from the remote or local end.
+ */
+int mg_read(struct mg_connection *, int local, void *buf, int len);
+
+/*
+ * Get the value of particular HTTP header.
+ * This is a helper function. It traverses request_info->http_headers array,
+ * and if the header is present in the array, returns its value. If it is
+ * not present, NULL is returned.
+ */
+const char *mg_get_header(const struct mg_connection *, const char *hdr_name);
+
+
+/*
+ * Authorize the request.
+ * See the documentation for mg_set_auth_callback() function.
+ */
+void mg_authorize(struct mg_connection *);
+
+
+/*
+ * Get a value of particular form variable.
+ * Both query string (whatever comes after '?' in the URL) and a POST buffer
+ * are scanned. If a variable is specified in both query string and POST
+ * buffer, POST buffer wins. Return value:
+ * NULL if the variable is not found
+ * non-NULL if found. NOTE: this returned value is dynamically allocated
+ * and is subject to mg_free() when no longer needed. It is
+ * an application's responsibility to mg_free() the variable.
+ */
+char *mg_get_var(const struct mg_connection *, const char *var_name);
+
+
+/*
+ * Free up memory returned by mg_get_var().
+ */
+void mg_free(char *var);
+
+
+/*
+ * Return Mongoose version.
+ */
+const char *mg_version(void);
+
+
+/*
+ * Print command line usage string.
+ */
+void mg_show_usage_string(FILE *fp);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* MONGOOSE_HEADER_INCLUDED */
diff --git a/cpukit/mghttpd/preinstall.am b/cpukit/mghttpd/preinstall.am
new file mode 100644
index 0000000000..aa246f014e
--- /dev/null
+++ b/cpukit/mghttpd/preinstall.am
@@ -0,0 +1,39 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+if LIBNETWORKING
+$(PROJECT_INCLUDE)/mghttpd/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/mghttpd
+ @: > $(PROJECT_INCLUDE)/mghttpd/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/mghttpd/$(dirstamp)
+
+$(PROJECT_LIB)/libmghttpd.a: libmghttpd.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libmghttpd.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libmghttpd.a
+
+$(PROJECT_INCLUDE)/mghttpd/mongoose.h: mongoose.h $(PROJECT_INCLUDE)/mghttpd/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/mghttpd/mongoose.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/mghttpd/mongoose.h
+endif
diff --git a/cpukit/posix/.cvsignore b/cpukit/posix/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/posix/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
new file mode 100644
index 0000000000..34e1cfa0ab
--- /dev/null
+++ b/cpukit/posix/Makefile.am
@@ -0,0 +1,195 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+EXTRA_DIST =
+
+AM_CPPFLAGS += -D__RTEMS_INSIDE__
+
+noinst_LIBRARIES = libposix.a
+libposix_a_CPPFLAGS = $(AM_CPPFLAGS)
+libposix_a_SOURCES =
+
+# Some POSIX functions that are nice to always have
+libposix_a_SOURCES += src/nanosleep.c src/clockgettime.c src/clocksettime.c \
+ src/clockgetres.c src/sysconf.c
+
+include_rtems_posixdir = $(includedir)/rtems/posix
+
+include_rtems_posix_HEADERS = include/rtems/posix/sigset.h
+
+if HAS_PTHREADS
+# include
+include_HEADERS = include/aio.h include/mqueue.h \
+ include/semaphore.h
+
+# include/rtems/posix
+include_rtems_posix_HEADERS += include/rtems/posix/aio_misc.h
+
+include_rtems_posix_HEADERS += include/rtems/posix/cancel.h \
+ include/rtems/posix/cond.h include/rtems/posix/config.h \
+ include/rtems/posix/key.h include/rtems/posix/mqueue.h \
+ include/rtems/posix/mutex.h include/rtems/posix/posixapi.h \
+ include/rtems/posix/priority.h include/rtems/posix/psignal.h \
+ include/rtems/posix/pthread.h include/rtems/posix/ptimer.h \
+ include/rtems/posix/semaphore.h include/rtems/posix/threadsup.h \
+ include/rtems/posix/time.h include/rtems/posix/timer.h \
+ include/rtems/posix/barrier.h include/rtems/posix/rwlock.h \
+ include/rtems/posix/spinlock.h
+
+include_rtems_posix_HEADERS += inline/rtems/posix/cond.inl \
+ inline/rtems/posix/key.inl inline/rtems/posix/mqueue.inl \
+ inline/rtems/posix/mutex.inl inline/rtems/posix/pthread.inl \
+ inline/rtems/posix/priority.inl inline/rtems/posix/semaphore.inl \
+ inline/rtems/posix/timer.inl inline/rtems/posix/barrier.inl \
+ inline/rtems/posix/rwlock.inl inline/rtems/posix/spinlock.inl
+
+## src
+libposix_a_SOURCES += src/aio_cancel.c src/aio_error.c src/aio_fsync.c \
+ src/aio_read.c src/aio_return.c src/aio_suspend.c src/aio_write.c \
+ src/lio_listio.c src/aio_misc.c
+
+## ENOSYS_C_FILES
+libposix_a_SOURCES += src/_execve.c src/execl.c src/execle.c src/execlp.c \
+ src/execv.c src/execve.c src/execvp.c
+endif
+
+libposix_a_SOURCES += src/fork.c src/vfork.c
+
+libposix_a_SOURCES += src/wait.c src/waitpid.c
+
+if HAS_PTHREADS
+libposix_a_SOURCES += src/pthreadatfork.c
+
+## BARRIER_C_FILES
+libposix_a_SOURCES += src/barrierattrdestroy.c src/barrierattrgetpshared.c \
+ src/barrierattrinit.c src/barrierattrsetpshared.c src/pbarrier.c \
+ src/pbarrierdestroy.c src/pbarrierinit.c \
+ src/pbarriertranslatereturncode.c src/pbarrierwait.c
+
+## CANCEL_C_FILES
+libposix_a_SOURCES += src/cancel.c src/canceleval.c src/cancelrun.c \
+ src/cleanuppop.c src/cleanuppush.c src/setcancelstate.c \
+ src/setcanceltype.c src/testcancel.c
+
+## CONDITION_VARIABLE_C_FILES
+libposix_a_SOURCES += src/cond.c src/condattrdestroy.c \
+ src/condattrgetpshared.c src/condattrinit.c src/condattrsetpshared.c \
+ src/condbroadcast.c src/conddefaultattributes.c src/conddestroy.c \
+ src/condinit.c src/condsignal.c src/condsignalsupp.c \
+ src/condtimedwait.c src/condwait.c src/condwaitsupp.c src/condget.c
+
+## KEY_C_FILES
+libposix_a_SOURCES += src/key.c src/keycreate.c src/keydelete.c \
+ src/keygetspecific.c src/keyfreememory.c src/keyrundestructors.c \
+ src/keysetspecific.c
+
+## MEMORY_C_FILES
+libposix_a_SOURCES += src/mprotect.c
+
+## MESSAGE_QUEUE_C_FILES
+libposix_a_SOURCES += src/mqueue.c src/mqueueclose.c \
+ src/mqueuecreatesupp.c src/mqueuedeletesupp.c src/mqueuegetattr.c \
+ src/mqueuenametoid.c src/mqueuenotify.c src/mqueueopen.c \
+ src/mqueuereceive.c src/mqueuerecvsupp.c src/mqueuesend.c \
+ src/mqueuesendsupp.c src/mqueuesetattr.c src/mqueuetimedreceive.c \
+ src/mqueuetimedsend.c src/mqueuetranslatereturncode.c \
+ src/mqueueunlink.c
+
+## MUTEX_C_FILES
+libposix_a_SOURCES += src/mutexattrdestroy.c src/mutexattrgetprioceiling.c \
+ src/mutexattrgetprotocol.c src/mutexattrgetpshared.c \
+ src/mutexattrgettype.c src/mutexattrinit.c src/mutexattrsetprioceiling.c \
+ src/mutexattrsetprotocol.c src/mutexattrsetpshared.c \
+ src/mutexattrsettype.c src/mutex.c src/mutexdestroy.c src/mutexget.c \
+ src/mutexgetprioceiling.c src/mutexinit.c src/mutexlock.c \
+ src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
+ src/mutextranslatereturncode.c src/mutextrylock.c src/mutexunlock.c
+
+## PTHREAD_C_FILES
+libposix_a_SOURCES += src/pthreadatfork.c src/pthreadattrdestroy.c \
+ src/pthreadattrgetdetachstate.c src/pthreadattrgetinheritsched.c \
+ src/pthreadattrgetschedparam.c src/pthreadattrgetschedpolicy.c \
+ src/pthreadattrgetscope.c src/pthreadattrgetstackaddr.c \
+ src/pthreadattrgetstack.c src/pthreadattrgetstacksize.c \
+ src/pthreadattrinit.c src/pthreadattrsetdetachstate.c \
+ src/pthreadattrsetguardsize.c src/pthreadattrsetinheritsched.c \
+ src/pthreadattrsetschedparam.c src/pthreadattrsetschedpolicy.c \
+ src/pthreadattrsetscope.c src/pthreadattrsetstackaddr.c \
+ src/pthreadattrsetstack.c src/pthreadattrsetstacksize.c \
+ src/pthreadattrgetguardsize.c src/pthread.c \
+ src/pthreadcreate.c src/pthreaddetach.c src/pthreadequal.c \
+ src/pthreadexit.c src/pthreadgetcpuclockid.c \
+ src/pthreadgetcputime.c src/pthreadgetschedparam.c \
+ src/pthreadinitthreads.c src/pthreadjoin.c src/pthreadkill.c \
+ src/pthreadonce.c src/pthreadself.c src/pthreadsetcputime.c \
+ src/pthreadsetschedparam.c src/pthreadsigmask.c \
+ src/psxpriorityisvalid.c src/psxtransschedparam.c
+
+## PSIGNAL_C_FILES
+libposix_a_SOURCES += src/psignal.c src/alarm.c src/kill.c src/killinfo.c \
+ src/kill_r.c src/pause.c src/psignalclearprocesssignals.c \
+ src/psignalsetprocesssignals.c src/psignalchecksignal.c \
+ src/psignalclearsignals.c src/psignalunblockthread.c src/pthreadkill.c \
+ src/pthreadsigmask.c src/sigaction.c
+endif
+
+libposix_a_SOURCES += src/sigaddset.c src/sigdelset.c src/sigfillset.c \
+ src/sigemptyset.c src/sigismember.c
+
+libposix_a_SOURCES += src/sigprocmask.c
+
+if HAS_PTHREADS
+libposix_a_SOURCES += src/sigpending.c \
+ src/sigqueue.c src/sigsuspend.c src/sigtimedwait.c \
+ src/sigwait.c src/sigwaitinfo.c src/signal_2.c src/ualarm.c
+
+## RWLOCK_C_FILES
+libposix_a_SOURCES += src/prwlock.c src/prwlockdestroy.c src/prwlockinit.c \
+ src/prwlockrdlock.c src/prwlocktimedrdlock.c src/prwlocktimedwrlock.c \
+ src/prwlocktryrdlock.c src/prwlocktrywrlock.c src/prwlockunlock.c \
+ src/prwlockwrlock.c src/rwlockattrdestroy.c src/rwlockattrgetpshared.c \
+ src/rwlockattrinit.c src/rwlockattrsetpshared.c \
+ src/prwlocktranslatereturncode.c
+
+## SEMAPHORE_C_FILES
+libposix_a_SOURCES += src/semaphore.c src/semaphorecreatesupp.c \
+ src/semaphoredeletesupp.c src/semaphorenametoid.c \
+ src/semaphoretranslatereturncode.c src/semaphorewaitsupp.c \
+ src/semclose.c src/semdestroy.c src/semgetvalue.c src/seminit.c \
+ src/semopen.c src/sempost.c src/semtimedwait.c src/semtrywait.c \
+ src/semunlink.c src/semwait.c
+
+## SPINLOCK_C_FILES
+libposix_a_SOURCES += src/pspin.c src/pspindestroy.c src/pspininit.c \
+ src/pspinlock.c src/pspinlocktranslatereturncode.c src/pspintrylock.c \
+ src/pspinunlock.c
+
+## TIME_C_FILES
+libposix_a_SOURCES += src/adjtime.c src/posixtimespecabsolutetimeout.c \
+ src/clockgetcpuclockid.c src/clockgetenableattr.c src/clocksetenableattr.c
+
+## TIMER_C_FILES
+libposix_a_SOURCES += src/ptimer.c src/timercreate.c src/timerdelete.c \
+ src/timergetoverrun.c src/timergettime.c src/timersettime.c \
+ src/timertsr.c src/timerinserthelper.c
+
+## ITIMER_C_FILES
+libposix_a_SOURCES += src/getitimer.c src/setitimer.c
+
+## SUPPORT_C_FILES
+libposix_a_SOURCES += src/psxpriorityisvalid.c
+
+EXTRA_DIST += src/README.mqueue
+
+libposix_a_SOURCES += src/sched_getparam.c src/sched_getprioritymax.c \
+ src/sched_getprioritymin.c src/sched_getscheduler.c \
+ src/sched_rr_get_interval.c src/sched_setparam.c \
+ src/sched_setscheduler.c src/sched_yield.c
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/posix/include/aio.h b/cpukit/posix/include/aio.h
new file mode 100644
index 0000000000..becb4abb86
--- /dev/null
+++ b/cpukit/posix/include/aio.h
@@ -0,0 +1,167 @@
+/**
+ * @file aio.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _AIO_H
+#define _AIO_H
+
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_POSIX_ASYNCHRONOUS_IO)
+
+/*
+ * 6.7.1 Data Definitions for Asynchronous Input and Output,
+ * P1003.1b-1993, p. 151
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#include <time.h>
+#include <fcntl.h>
+
+/*
+ * 6.7.1.2 Manifest Constants, P1003.1b-1993, p. 153
+ */
+
+#define AIO_CANCELED 0 /* all requested operations have been canceled */
+#define AIO_NOTCANCELED 1 /* some of the operations could not be canceled */
+ /* since they are in progress */
+#define AIO_ALLDONE 2 /* none of the requested operations could be */
+ /* canceled since they are already complete */
+
+/* lio_listio() options */
+
+/*
+ * LIO modes
+ */
+#define LIO_WAIT 0 /* calling process is to suspend until the */
+ /* operation is complete */
+#define LIO_NOWAIT 1 /* calling process is to continue execution while */
+ /* the operation is performed and no notification */
+ /* shall be given when the operation is completed */
+
+/*
+ * LIO opcodes
+ */
+#define LIO_NOP 0 /* no transfer is requested */
+#define LIO_READ 1 /* request a read() */
+#define LIO_WRITE 2 /* request a write() */
+#define LIO_SYNC 3 /* needed by aio_fsync() */
+
+/*
+ * 6.7.1.1 Asynchronous I/O Control Block, P1003.1b-1993, p. 151
+ */
+
+struct aiocb {
+ /* public */
+ int aio_fildes; /* File descriptor */
+ off_t aio_offset; /* File offset */
+ volatile void *aio_buf; /* Location of buffer */
+ size_t aio_nbytes; /* Length of transfer */
+ int aio_reqprio; /* Request priority offset */
+ struct sigevent aio_sigevent; /* Signal number and value */
+ int aio_lio_opcode; /* Operation to be performed */
+ /* private */
+ int error_code; /* Used for aio_error() */
+ ssize_t return_value; /* Used for aio_return() */
+};
+
+/*
+ * 6.7.2 Asynchronous Read, P1003.1b-1993, p. 154
+ */
+
+int aio_read(
+ struct aiocb *aiocbp
+);
+
+/*
+ * 6.7.3 Asynchronous Write, P1003.1b-1993, p. 155
+ */
+
+int aio_write(
+ struct aiocb *aiocbp
+);
+
+/*
+ * 6.7.4 List Directed I/O, P1003.1b-1993, p. 158
+ */
+
+int lio_listio(
+ int mode,
+ struct aiocb * const list[],
+ int nent,
+ struct sigevent *sig
+);
+
+/*
+ * 6.7.5 Retrieve Error of Asynchronous I/O Operation, P1003.1b-1993, p. 161
+ */
+
+int aio_error(
+ const struct aiocb *aiocbp
+);
+
+/*
+ * 6.7.6 Retrieve Return Status of Asynchronous I/O Operation,
+ * P1003.1b-1993, p. 162
+ */
+
+ssize_t aio_return(
+ const struct aiocb *aiocbp
+);
+
+/*
+ * 6.7.7 Cancel Asynchronous I/O Operation, P1003.1b-1993, p. 163
+ */
+
+int aio_cancel(
+ int filedes,
+ struct aiocb *aiocbp
+);
+
+/*
+ * 6.7.7 Wait for Asynchronous I/O Request, P1003.1b-1993, p. 164
+ */
+
+int aio_suspend(
+ const struct aiocb * const list[],
+ int nent,
+ const struct timespec *timeout
+);
+
+#if defined(_POSIX_SYNCHRONIZED_IO)
+
+/*
+ * 6.7.9 Asynchronous File Synchronization, P1003.1b-1993, p. 166
+ */
+
+int aio_fsync(
+ int op,
+ struct aiocb *aiocbp
+);
+
+#endif /* _POSIX_SYNCHRONIZED_IO */
+
+#endif /* _POSIX_ASYNCHRONOUS_IO */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/mqueue.h b/cpukit/posix/include/mqueue.h
new file mode 100644
index 0000000000..f08dc0754b
--- /dev/null
+++ b/cpukit/posix/include/mqueue.h
@@ -0,0 +1,172 @@
+/**
+ * @file mqueue.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _MQUEUE_H
+#define _MQUEUE_H
+
+
+#include <unistd.h>
+
+#if defined(_POSIX_MESSAGE_PASSING)
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * 15.1.1 Data Structures, P1003.1b-1993, p. 271
+ */
+
+/**
+ * Message queue id type.
+ *
+ * @note Use uint32_t since all POSIX Ids are 32-bit currently.
+ */
+typedef uint32_t mqd_t;
+
+/**
+ * This is the message queue attributes structure.
+ */
+struct mq_attr {
+ /** This is the message queue flags */
+ long mq_flags;
+ /** This is the maximum number of messages */
+ long mq_maxmsg;
+ /** This is the maximum message size */
+ long mq_msgsize;
+ /** This is the mumber of messages currently queued */
+ long mq_curmsgs;
+};
+
+/**
+ * 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
+ */
+mqd_t mq_open(
+ const char *name,
+ int oflag,
+ ...
+);
+
+/**
+ * 15.2.2 Close a Message Queue, P1003.1b-1993, p. 275
+ */
+int mq_close(
+ mqd_t mqdes
+);
+
+/**
+ * 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276
+ */
+int mq_unlink(
+ const char *name
+);
+
+/**
+ * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277
+ *
+ * @note P1003.4b/D8, p. 45 adds mq_timedsend().
+ */
+int mq_send(
+ mqd_t mqdes,
+ const char *msg_ptr,
+ size_t msg_len,
+ unsigned int msg_prio
+);
+
+#if defined(_POSIX_TIMEOUTS)
+
+#include <time.h>
+
+int mq_timedsend(
+ mqd_t mqdes,
+ const char *msg_ptr,
+ size_t msg_len,
+ unsigned int msg_prio,
+ const struct timespec *abstime
+);
+
+#endif /* _POSIX_TIMEOUTS */
+
+/*
+ * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279
+ *
+ * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive().
+ */
+
+ssize_t mq_receive(
+ mqd_t mqdes,
+ char *msg_ptr,
+ size_t msg_len,
+ unsigned int *msg_prio
+);
+
+#if defined(_POSIX_TIMEOUTS)
+
+ssize_t mq_timedreceive(
+ mqd_t mqdes,
+ char *msg_ptr,
+ size_t msg_len,
+ unsigned int *msg_prio,
+ const struct timespec *abstime
+);
+
+#endif /* _POSIX_TIMEOUTS */
+
+#if defined(_POSIX_REALTIME_SIGNALS)
+
+/*
+ * 15.2.6 Notify Process that a Message is Available on a Queue,
+ * P1003.1b-1993, p. 280
+ */
+
+int mq_notify(
+ mqd_t mqdes,
+ const struct sigevent *notification
+);
+
+#endif /* _POSIX_REALTIME_SIGNALS */
+
+/*
+ * 15.2.7 Set Message Queue Attributes, P1003.1b-1993, p. 281
+ */
+
+int mq_setattr(
+ mqd_t mqdes,
+ const struct mq_attr *mqstat,
+ struct mq_attr *omqstat
+);
+
+/*
+ * 15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283
+ */
+
+int mq_getattr(
+ mqd_t mqdes,
+ struct mq_attr *mqstat
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _POSIX_MESSAGE_PASSING */
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/aio_misc.h b/cpukit/posix/include/rtems/posix/aio_misc.h
new file mode 100644
index 0000000000..c90d509d44
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/aio_misc.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#ifndef _AIO_MISC_H
+#define _AIO_MISC_H
+
+#include <stdio.h>
+#include <string.h>
+#include <aio.h>
+#include <pthread.h>
+#include <rtems.h>
+#include <rtems/chain.h>
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /* Actual request being processed */
+ typedef struct
+ {
+ rtems_chain_node next_prio; /* chain requests in order of priority */
+ int policy; /* If _POSIX_PRIORITIZED_IO and
+ _POSIX_PRIORITY_SCHEDULING are defined */
+ int priority; /* see above */
+ pthread_t caller_thread; /* used for notification */
+ struct aiocb *aiocbp; /* aio control block */
+ } rtems_aio_request;
+
+ typedef struct
+ {
+ rtems_chain_node next_fd; /* order fd chains in queue */
+ rtems_chain_control perfd; /* chain of requests for this fd */
+ int fildes; /* file descriptor to be processed */
+ int new_fd; /* if this is a newly created chain */
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+
+ } rtems_aio_request_chain;
+
+ typedef struct
+ {
+ pthread_mutex_t mutex;
+ pthread_cond_t new_req;
+ pthread_attr_t attr;
+
+ rtems_chain_control work_req; /* chains being worked by active threads */
+ rtems_chain_control idle_req; /* fd chains waiting to be processed */
+ unsigned int initialized; /* specific value if queue is initialized */
+ int active_threads; /* the number of active threads */
+ int idle_threads; /* number of idle threads */
+
+ } rtems_aio_queue;
+
+extern rtems_aio_queue aio_request_queue;
+
+#define AIO_QUEUE_INITIALIZED 0xB00B
+
+#ifndef AIO_MAX_THREADS
+#define AIO_MAX_THREADS 5
+#endif
+
+#ifndef AIO_MAX_QUEUE_SIZE
+#define AIO_MAX_QUEUE_SIZE 30
+#endif
+
+int rtems_aio_init (void);
+int rtems_aio_enqueue (rtems_aio_request *req);
+rtems_aio_request_chain *rtems_aio_search_fd
+(
+ rtems_chain_control *chain,
+ int fildes,
+ int create
+);
+void rtems_aio_remove_fd (rtems_aio_request_chain *r_chain);
+int rtems_aio_remove_req (rtems_chain_control *chain,
+ struct aiocb *aiocbp);
+
+#ifdef RTEMS_DEBUG
+#include <assert.h>
+
+#define AIO_assert(_x) assert(_x)
+#define AIO_printf(_x) printf(_x)
+#else
+#define AIO_assert(_x)
+#define AIO_printf(_x)
+#endif
+
+#define rtems_aio_set_errno_return_minus_one( _error, _aiocbp ) \
+ do { (_aiocbp)->error_code = (_error); \
+ (_aiocbp)->return_value = -1; \
+ rtems_set_errno_and_return_minus_one (_error);} while(0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/posix/include/rtems/posix/barrier.h b/cpukit/posix/include/rtems/posix/barrier.h
new file mode 100644
index 0000000000..6bb2aa2e5c
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/barrier.h
@@ -0,0 +1,88 @@
+/**
+ * @file rtems/posix/barrier.h
+ */
+
+/*
+ * This include file contains all the constants and structures associated
+ * with the POSIX Barrier Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a barrier
+ * + delete a barrier
+ * + wait for a barrier
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_BARRIER_H
+#define _RTEMS_POSIX_BARRIER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/corebarrier.h>
+
+/**
+ * This type defines the control block used to manage each barrier.
+ */
+
+typedef struct {
+ /** This is used to manage a barrier as an object. */
+ Objects_Control Object;
+ /** This is used to implement the barrier. */
+ CORE_barrier_Control Barrier;
+} POSIX_Barrier_Control;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_Barrier_Information;
+
+/**
+ * @brief _POSIX_Barrier_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ *
+ * @param[in] maximum_barriers is the total number of barriers allowed to
+ * concurrently be active in the system.
+ */
+
+void _POSIX_Barrier_Manager_initialization(void);
+
+/**
+ * @brief _POSIX_Barrier_Translate_core_barrier_return_code (
+ *
+ * This routine translates SuperCore Barrier status codes into the
+ * corresponding POSIX ones.
+ *
+ *
+ * @param[in] the_barrier_status is the SuperCore status.
+ *
+ * @return the corresponding POSIX status
+ */
+int _POSIX_Barrier_Translate_core_barrier_return_code(
+ CORE_barrier_Status the_barrier_status
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/posix/barrier.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/cancel.h b/cpukit/posix/include/rtems/posix/cancel.h
new file mode 100644
index 0000000000..6e6b32a71c
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/cancel.h
@@ -0,0 +1,62 @@
+/**
+ * @file rtems/posix/cancel.h
+ *
+ * This file contains the prototypes and data types used to implement
+ * POSIX thread cancelation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_CANCEL_H
+#define _RTEMS_POSIX_CANCEL_H
+
+#include <rtems/posix/threadsup.h>
+
+/**
+ * This structure is used to manage the cancelation handlers.
+ */
+typedef struct {
+ /** This field is the Chain Node so we can put these on lists. */
+ Chain_Node Node;
+ /** This field is the cancelation routine. */
+ void (*routine)( void * );
+ /** This field is the argument to the cancelation routine. */
+ void *arg;
+} POSIX_Cancel_Handler_control;
+
+/**
+ * @brief _POSIX_Threads_cancel_run
+ *
+ * This support routine runs through the chain of cancel handlers that
+ * have been registered and executes them.
+ *
+ * @param[in] the_thread is the thread whose cancelation handlers
+ * should be run
+ */
+void _POSIX_Threads_cancel_run(
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch
+ *
+ * This routine separates a piece of code that existed as part of
+ * another routine, but had to be separated to improve coverage.
+ *
+ * @param[in] the_thread is the thread to evaluate canceling
+ */
+void _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch (
+ Thread_Control *the_thread
+);
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/cond.h b/cpukit/posix/include/rtems/posix/cond.h
new file mode 100644
index 0000000000..5ed8dfeed7
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/cond.h
@@ -0,0 +1,181 @@
+/**
+ * @file rtems/posix/cond.h
+ */
+
+/*
+ * This include file contains all the private support information for
+ * POSIX condition variables.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_COND_H
+#define _RTEMS_POSIX_COND_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/threadq.h>
+
+/*
+ * Constant to indicate condition variable does not currently have
+ * a mutex assigned to it.
+ */
+
+#define POSIX_CONDITION_VARIABLES_NO_MUTEX 0
+
+/*
+ * Data Structure used to manage a POSIX condition variable
+ */
+
+typedef struct {
+ Objects_Control Object;
+ int process_shared;
+ pthread_mutex_t Mutex;
+ Thread_queue_Control Wait_queue;
+} POSIX_Condition_variables_Control;
+
+/*
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_Condition_variables_Information;
+
+/*
+ * The default condition variable attributes structure.
+ */
+
+extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes;
+
+/*
+ * _POSIX_Condition_variables_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+
+void _POSIX_Condition_variables_Manager_initialization(void);
+
+/*
+ * _POSIX_Condition_variables_Allocate
+ *
+ * DESCRIPTION:
+ *
+ * This function allocates a condition variable control block from
+ * the inactive chain of free condition variable control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Condition_variables_Control *
+ _POSIX_Condition_variables_Allocate( void );
+
+/*
+ * _POSIX_Condition_variables_Free
+ *
+ * DESCRIPTION:
+ *
+ * This routine frees a condition variable control block to the
+ * inactive chain of free condition variable control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Free (
+ POSIX_Condition_variables_Control *the_condition_variable
+);
+
+/*
+ * _POSIX_Condition_variables_Get
+ *
+ * DESCRIPTION:
+ *
+ * This function maps condition variable IDs to condition variable control
+ * blocks. If ID corresponds to a local condition variable, then it returns
+ * the_condition variable control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the condition variable ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_condition variable is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_condition variable is undefined.
+ */
+
+#if 0
+RTEMS_INLINE_ROUTINE POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get (
+ Objects_Id *id,
+ Objects_Locations *location
+);
+#endif
+
+/*
+ * _POSIX_Condition_variables_Is_null
+ *
+ * DESCRIPTION:
+ *
+ * This function returns TRUE if the_condition variable is NULL
+ * and FALSE otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Condition_variables_Is_null (
+ POSIX_Condition_variables_Control *the_condition_variable
+);
+
+/*
+ * _POSIX_Condition_variables_Signal_support
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which implements guts of the broadcast and single task
+ * wake up version of the "signal" operation.
+ */
+
+int _POSIX_Condition_variables_Signal_support(
+ pthread_cond_t *cond,
+ bool is_broadcast
+);
+
+/*
+ * _POSIX_Condition_variables_Wait_support
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which implements guts of the blocking, non-blocking, and
+ * timed wait version of condition variable wait routines.
+ */
+
+int _POSIX_Condition_variables_Wait_support(
+ pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ Watchdog_Interval timeout,
+ bool already_timedout
+);
+
+/*
+ * _POSIX_Condition_variables_Get
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which translates the condition variable id into
+ * a local pointer. As a side-effect, it may create the condition
+ * variable.
+ */
+
+POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get (
+ pthread_cond_t *cond,
+ Objects_Locations *location
+);
+
+#include <rtems/posix/cond.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/config.h b/cpukit/posix/include/rtems/posix/config.h
new file mode 100644
index 0000000000..b6ad91fb34
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/config.h
@@ -0,0 +1,77 @@
+/**
+ * @file rtems/posix/config.h
+ *
+ * This include file contains the table of user defined configuration
+ * parameters specific for the POSIX API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_CONFIG_H
+#define _RTEMS_POSIX_CONFIG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * XXX
+ *
+ * The following records define the Configuration Table. The
+ * information contained in this table is required in all
+ * RTEMS systems, whether single or multiprocessor. This
+ * table primarily defines the following:
+ *
+ * + required number of each object type
+ */
+
+/*
+ * For now, we are only allowing the user to specify the entry point
+ * and stack size for POSIX initialization threads.
+ */
+
+typedef struct {
+ void *(*thread_entry)(void *);
+ int stack_size;
+} posix_initialization_threads_table;
+
+typedef struct {
+ int maximum_threads;
+ int maximum_mutexes;
+ int maximum_condition_variables;
+ int maximum_keys;
+ int maximum_timers;
+ int maximum_queued_signals;
+ int maximum_message_queues;
+ int maximum_message_queue_descriptors;
+ int maximum_semaphores;
+ int maximum_barriers;
+ int maximum_rwlocks;
+ int maximum_spinlocks;
+ int number_of_initialization_threads;
+ posix_initialization_threads_table *User_initialization_threads_table;
+} posix_api_configuration_table;
+
+/**
+ * @brief POSIX API Configuration Table
+ *
+ * This is the POSIX API Configuration Table expected to be generated
+ * by confdefs.h.
+ */
+extern posix_api_configuration_table Configuration_POSIX_API;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/key.h b/cpukit/posix/include/rtems/posix/key.h
new file mode 100644
index 0000000000..e39aa98d53
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/key.h
@@ -0,0 +1,103 @@
+/**
+ * @file rtems/posix/key.h
+ */
+
+/* rtems/posix/key.h
+ *
+ * This include file contains all the private support information for
+ * POSIX key.
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_KEY_H
+#define _RTEMS_POSIX_KEY_H
+
+#include <rtems/score/object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is the data Structure used to manage a POSIX key.
+ *
+ * @note The Values is a table indexed by the index portion of the
+ * ID of the currently executing thread.
+ */
+typedef struct {
+ /** This field is the Object control structure. */
+ Objects_Control Object;
+ /** This field points to the optional destructor method. */
+ void (*destructor)( void * );
+ /** This field points to the values per thread. */
+ void **Values[ OBJECTS_APIS_LAST + 1 ];
+} POSIX_Keys_Control;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+POSIX_EXTERN Objects_Information _POSIX_Keys_Information;
+
+/**
+ * @brief _POSIX_Keys_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _POSIX_Key_Manager_initialization(void);
+
+/**
+ * @brief _POSIX_Keys_Run_destructors
+ *
+ * This function executes all the destructors associated with the thread's
+ * keys. This function will execute until all values have been set to NULL.
+ *
+ * @param[in] thread is the thread whose keys should have all their
+ * destructors run.
+ *
+ * @note This is the routine executed when a thread exits to
+ * run through all the keys and do the destructor action.
+ */
+void _POSIX_Keys_Run_destructors(
+ Thread_Control *thread
+);
+
+/**
+ * @brief Free Key Memory
+ *
+ * This memory frees the key table memory associated with @a the_key.
+ *
+ * @param[in] the_key is the POSIX key to free the table memory of.
+ */
+void _POSIX_Keys_Free_memory(
+ POSIX_Keys_Control *the_key
+);
+
+/**
+ * @brief _POSIX_Keys_Free
+ *
+ * This routine frees a keys control block to the
+ * inactive chain of free keys control blocks.
+ *
+ * @param[in] the_key is the POSIX key to free.
+ */
+RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
+ POSIX_Keys_Control *the_key
+);
+
+#include <rtems/posix/key.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/mqueue.h b/cpukit/posix/include/rtems/posix/mqueue.h
new file mode 100644
index 0000000000..1e2e7a7429
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/mqueue.h
@@ -0,0 +1,248 @@
+/**
+ * @file rtems/posix/mqueue.h
+ *
+ * This include file contains all the private support information for
+ * POSIX Message Queues.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_MQUEUE_H
+#define _RTEMS_POSIX_MQUEUE_H
+
+#include <signal.h>
+#include <mqueue.h> /* struct mq_attr */
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Data Structure used to manage a POSIX message queue
+ */
+
+typedef struct {
+ Objects_Control Object;
+ int process_shared;
+ bool named;
+ bool linked;
+ uint32_t open_count;
+ CORE_message_queue_Control Message_queue;
+ struct sigevent notification;
+} POSIX_Message_queue_Control;
+
+typedef struct {
+ Objects_Control Object;
+ POSIX_Message_queue_Control *Queue;
+ int oflag;
+} POSIX_Message_queue_Control_fd;
+
+/*
+ * The following defines the information control block used to manage
+ * this class of objects. The second item is used to manage the set
+ * of "file descriptors" associated with the message queues.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_Message_queue_Information;
+POSIX_EXTERN Objects_Information _POSIX_Message_queue_Information_fds;
+
+/*
+ * _POSIX_Message_queue_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+
+void _POSIX_Message_queue_Manager_initialization(void);
+
+/*
+ *
+ * _POSIX_Message_queue_Create_support
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the creation of a message queue utilizing the
+ * core message queue.
+ */
+
+int _POSIX_Message_queue_Create_support(
+ const char *name,
+ int pshared,
+ struct mq_attr *attr,
+ POSIX_Message_queue_Control **message_queue
+);
+
+/*
+ * _POSIX_Message_queue_Delete
+ *
+ * DESCRIPTION:
+ *
+ * This routine supports the mq_unlink and mq_close routines by
+ * doing most of the work involved with removing a message queue.
+ */
+
+void _POSIX_Message_queue_Delete(
+ POSIX_Message_queue_Control *the_mq
+);
+
+/*
+ * _POSIX_Message_queue_Receive_support
+ *
+ * DESCRIPTION:
+ *
+ * This routine supports the various flavors of receiving a message.
+ */
+
+ssize_t _POSIX_Message_queue_Receive_support(
+ mqd_t mqdes,
+ char *msg_ptr,
+ size_t msg_len,
+ unsigned int *msg_prio,
+ bool wait,
+ Watchdog_Interval timeout
+);
+
+/*
+ * _POSIX_Message_queue_Send_support
+ *
+ * DESCRIPTION:
+ *
+ * This routine posts a message to a specified message queue.
+ */
+
+int _POSIX_Message_queue_Send_support(
+ mqd_t mqdes,
+ const char *msg_ptr,
+ size_t msg_len,
+ uint32_t msg_prio,
+ bool wait,
+ Watchdog_Interval timeout
+);
+
+/*
+ * _POSIX_Message_queue_Allocate
+ *
+ * DESCRIPTION:
+ *
+ * This function allocates a message queue control block from
+ * the inactive chain of free message queue control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control *_POSIX_Message_queue_Allocate( void );
+
+/*
+ * _POSIX_Message_queue_Free
+ *
+ * DESCRIPTION:
+ *
+ * This routine frees a message queue control block to the
+ * inactive chain of free message queue control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Message_queue_Free (
+ POSIX_Message_queue_Control *the_mq
+);
+
+/*
+ * _POSIX_Message_queue_Get
+ *
+ * DESCRIPTION:
+ *
+ * This function maps message queue IDs to message queue control blocks.
+ * If ID corresponds to a local message queue, then it returns
+ * the_mq control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the message queue ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_message queue is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_mq is undefined.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control *_POSIX_Message_queue_Get (
+ Objects_Id id,
+ Objects_Locations *location
+);
+
+/*
+ * _POSIX_Message_queue_Is_null
+ *
+ * DESCRIPTION:
+ *
+ * This function returns TRUE if the_message_queue is NULL and FALSE otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Message_queue_Is_null (
+ POSIX_Message_queue_Control *the_mq
+);
+
+/*
+ * _POSIX_Message_queue_Name_to_id
+ *
+ * DESCRIPTION:
+ *
+ * This routine looks up the specified name for a message queue and returns the
+ * id of the message queue associated with it.
+ */
+
+int _POSIX_Message_queue_Name_to_id(
+ const char *name,
+ Objects_Id *id
+);
+
+/*
+ * _POSIX_Message_queue_Priority_to_core
+ *
+ * DESCRIPTION:
+ *
+ * XXX
+ */
+
+RTEMS_INLINE_ROUTINE CORE_message_queue_Submit_types _POSIX_Message_queue_Priority_to_core(
+ unsigned int priority
+);
+
+/*
+ * _POSIX_Message_queue_Priority_from_core
+ *
+ * DESCRIPTION:
+ *
+ * XXX
+ */
+
+RTEMS_INLINE_ROUTINE unsigned int _POSIX_Message_queue_Priority_from_core(
+ CORE_message_queue_Submit_types priority
+);
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Translate_core_message_queue_return_code
+ *
+ * DESCRIPTION:
+ *
+ * XXX
+ */
+
+int _POSIX_Message_queue_Translate_core_message_queue_return_code(
+ uint32_t the_message_queue_status
+);
+
+
+#include <rtems/posix/mqueue.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/mutex.h b/cpukit/posix/include/rtems/posix/mutex.h
new file mode 100644
index 0000000000..4309edfaa8
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/mutex.h
@@ -0,0 +1,192 @@
+/**
+ * @file rtems/posix/mutex.h
+ */
+
+/*
+ * This include file contains all the private support information for
+ * POSIX mutex's.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_MUTEX_H
+#define _RTEMS_POSIX_MUTEX_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/coremutex.h>
+#include <pthread.h>
+
+/*
+ * Data Structure used to manage a POSIX mutex
+ */
+
+typedef struct {
+ Objects_Control Object;
+ int process_shared;
+ CORE_mutex_Control Mutex;
+} POSIX_Mutex_Control;
+
+/*
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_Mutex_Information;
+
+/*
+ * The default mutex attributes structure.
+ */
+
+POSIX_EXTERN pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
+
+/*
+ * _POSIX_Mutex_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+
+void _POSIX_Mutex_Manager_initialization(void);
+
+/*
+ * _POSIX_Mutex_Allocate
+ *
+ * DESCRIPTION:
+ *
+ * This function allocates a mutexes control block from
+ * the inactive chain of free mutexes control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void );
+
+/*
+ * _POSIX_Mutex_Free
+ *
+ * DESCRIPTION:
+ *
+ * This routine frees a mutexes control block to the
+ * inactive chain of free mutexes control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free (
+ POSIX_Mutex_Control *the_mutex
+);
+
+#if 0
+/*
+ * _POSIX_Mutex_Get
+ *
+ * DESCRIPTION:
+ *
+ * This function maps mutexes IDs to mutexes control blocks.
+ * If ID corresponds to a local mutexes, then it returns
+ * the_mutex control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the mutexes ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_mutex is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_mutex is undefined.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Get (
+ Objects_Id *id,
+ Objects_Locations *location
+);
+
+/*
+ * _POSIX_Mutex_Is_null
+ *
+ * DESCRIPTION:
+ *
+ * This function returns TRUE if the_mutex is NULL and FALSE otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Mutex_Is_null (
+ POSIX_Mutex_Control *the_mutex
+);
+#endif
+
+/*
+ * _POSIX_Mutex_Lock_support
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which implements guts of the blocking, non-blocking, and
+ * timed wait version of mutex lock.
+ */
+
+int _POSIX_Mutex_Lock_support(
+ pthread_mutex_t *mutex,
+ bool blocking,
+ Watchdog_Interval timeout
+);
+
+/*
+ * _POSIX_Mutex_Translate_core_mutex_return_code
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which converts core mutex status codes into the
+ * appropriate POSIX status values.
+ */
+
+int _POSIX_Mutex_Translate_core_mutex_return_code(
+ CORE_mutex_Status the_mutex_status
+);
+
+
+/*
+ * _POSIX_Mutex_Get
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which translates the mutex id into a local pointer.
+ * As a side-effect, it may create the mutex.
+ *
+ * NOTE:
+ *
+ * This version of the method uses a dispatching critical section.
+ */
+
+POSIX_Mutex_Control *_POSIX_Mutex_Get (
+ pthread_mutex_t *mutex,
+ Objects_Locations *location
+);
+
+/*
+ * _POSIX_Mutex_Get
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which translates the mutex id into a local pointer.
+ * As a side-effect, it may create the mutex.
+ *
+ * NOTE:
+ *
+ * This version of the method uses an interrupt critical section.
+ */
+
+POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable (
+ pthread_mutex_t *mutex,
+ Objects_Locations *location,
+ ISR_Level *level
+);
+
+#include <rtems/posix/mutex.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/posixapi.h b/cpukit/posix/include/rtems/posix/posixapi.h
new file mode 100644
index 0000000000..729a6db163
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/posixapi.h
@@ -0,0 +1,30 @@
+/**
+ * @file rtems/posix/posixapi.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_POSIXAPI_H
+#define _RTEMS_POSIX_POSIXAPI_H
+
+#include <rtems/config.h>
+
+/**
+ * @brief Initialize POSIX API
+ *
+ * This method is responsible for initializing each of the POSIX
+ * API managers.
+ */
+void _POSIX_API_Initialize(void);
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/priority.h b/cpukit/posix/include/rtems/posix/priority.h
new file mode 100644
index 0000000000..5944c4e7c3
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/priority.h
@@ -0,0 +1,91 @@
+/**
+ * @file rtems/posix/priority.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_PRIORITY_H
+#define _RTEMS_POSIX_PRIORITY_H
+
+#include <rtems/score/priority.h>
+
+/**
+ * 1003.1b-1993,2.2.2.80 definition of priority, p. 19
+ *
+ * "Numerically higher values represent higher priorities."
+ *
+ * Thus, RTEMS Core has priorities run in the opposite sense of the POSIX API.
+ *
+ * There are only 254 posix priority levels since a task at priority level
+ * 255 would never run because of the RTEMS idle task. This is necessary
+ * because GNAT maps the lowest Ada task priority to the lowest thread
+ * priority. The lowest priority Ada task should get to run, so there is
+ * a fundamental conflict with having 255 priorities.
+ *
+ * But since RTEMS can be configured with fewer than 256 priorities,
+ * we use the internal constant.
+ */
+#define POSIX_SCHEDULER_MAXIMUM_PRIORITY (PRIORITY_MAXIMUM - 1)
+
+
+/**
+ * This is the numerically least important POSIX priority.
+ */
+#define POSIX_SCHEDULER_MINIMUM_PRIORITY (1)
+
+/**
+ * 1003.1b-1993,2.2.2.80 definition of priority, p. 19
+ *
+ * "Numerically higher values represent higher priorities."
+ *
+ * Thus, RTEMS Core has priorities run in the opposite sense of the POSIX API.
+ *
+ * @param[in] priority is the priority to test
+ *
+ * @return This method returns true if the priority is valid and
+ * false otherwise.
+ */
+bool _POSIX_Priority_Is_valid(
+ int priority
+);
+
+/**
+ * @brief Convert POSIX Priority To SuperCore Priority
+ *
+ * This method converts a POSIX API priority into onto the corresponding
+ * SuperCore value.
+ *
+ * @param[in] priority is the POSIX API priority.
+ *
+ * @return This method returns the corresponding SuperCore priority.
+ */
+RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
+ int priority
+);
+
+/**
+ * @brief Convert SuperCore Priority To POSIX Priority
+ *
+ * This method converts a SuperCore priority into onto the corresponding
+ * POSIX API value.
+ *
+ * @param[in] priority is the POSIX API priority.
+ *
+ * @return This method returns the corresponding POSIX priority.
+ */
+RTEMS_INLINE_ROUTINE int _POSIX_Priority_From_core(
+ Priority_Control priority
+);
+
+#include <rtems/posix/priority.inl>
+
+#endif
diff --git a/cpukit/posix/include/rtems/posix/psignal.h b/cpukit/posix/include/rtems/posix/psignal.h
new file mode 100644
index 0000000000..87b629ef52
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/psignal.h
@@ -0,0 +1,121 @@
+/**
+ * @file rtems/posix/psignal.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_PSIGNAL_H
+#define _RTEMS_POSIX_PSIGNAL_H
+
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/sigset.h>
+
+#define _States_Is_interruptible_signal( _states ) \
+ ( ((_states) & \
+ (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL)) == \
+ (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL))
+
+#define SIGACTION_TERMINATE \
+ { 0, SIGNAL_ALL_MASK, {_POSIX_signals_Abnormal_termination_handler} }
+#define SIGACTION_IGNORE \
+ { 0, SIGNAL_ALL_MASK, {SIG_IGN} }
+#define SIGACTION_STOP \
+ { 0, SIGNAL_ALL_MASK, {_POSIX_signals_Stop_handler} }
+#define SIGACTION_CONTINUE \
+ { 0, SIGNAL_ALL_MASK, {_POSIX_signals_Continue_handler} }
+
+#define SIG_ARRAY_MAX (SIGRTMAX + 1)
+
+/*
+ * Variables
+ */
+
+extern sigset_t _POSIX_signals_Pending;
+
+extern const struct sigaction _POSIX_signals_Default_vectors[ SIG_ARRAY_MAX ];
+
+extern struct sigaction _POSIX_signals_Vectors[ SIG_ARRAY_MAX ];
+
+extern Watchdog_Control _POSIX_signals_Alarm_timer;
+
+extern Watchdog_Control _POSIX_signals_Ualarm_timer;
+
+extern Thread_queue_Control _POSIX_signals_Wait_queue;
+
+extern Chain_Control _POSIX_signals_Inactive_siginfo;
+
+extern Chain_Control _POSIX_signals_Siginfo[ SIG_ARRAY_MAX ];
+
+/*
+ * POSIX internal siginfo structure
+ */
+
+typedef struct {
+ Chain_Node Node;
+ siginfo_t Info;
+} POSIX_signals_Siginfo_node;
+
+/*
+ * Internal routines
+ */
+
+void _POSIX_signals_Manager_Initialization(void);
+
+void _POSIX_signals_Post_switch_extension(
+ Thread_Control *the_thread
+);
+
+bool _POSIX_signals_Unblock_thread(
+ Thread_Control *the_thread,
+ int signo,
+ siginfo_t *info
+);
+
+bool _POSIX_signals_Check_signal(
+ POSIX_API_Control *api,
+ int signo,
+ bool is_global
+);
+
+bool _POSIX_signals_Clear_signals(
+ POSIX_API_Control *api,
+ int signo,
+ siginfo_t *info,
+ bool is_global,
+ bool check_blocked
+);
+
+int killinfo(
+ pid_t pid,
+ int sig,
+ const union sigval *value
+);
+
+void _POSIX_signals_Set_process_signals(
+ sigset_t mask
+);
+
+void _POSIX_signals_Clear_process_signals(
+ int signo
+);
+
+/*
+ * Default signal handlers
+ */
+
+#define _POSIX_signals_Stop_handler NULL
+#define _POSIX_signals_Continue_handler NULL
+
+void _POSIX_signals_Abnormal_termination_handler( int signo );
+
+#endif
+/* end of file */
diff --git a/cpukit/posix/include/rtems/posix/pthread.h b/cpukit/posix/include/rtems/posix/pthread.h
new file mode 100644
index 0000000000..6185afa62c
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/pthread.h
@@ -0,0 +1,175 @@
+/**
+ * @file rtems/posix/pthread.h
+ */
+
+/*
+ * This include file contains all the private support information for
+ * POSIX threads.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_PTHREAD_H
+#define _RTEMS_POSIX_PTHREAD_H
+
+
+#include <rtems/posix/config.h>
+#include <rtems/posix/threadsup.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * The following sets the minimum stack size for POSIX threads.
+ */
+#define PTHREAD_MINIMUM_STACK_SIZE (_Stack_Minimum() * 2)
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+POSIX_EXTERN Objects_Information _POSIX_Threads_Information;
+
+/**
+ * This variable contains the default POSIX Thread attributes.
+ */
+extern const pthread_attr_t _POSIX_Threads_Default_attributes;
+
+/**
+ * When the user configures a set of POSIX API initialization threads,
+ * This variable will point to the method used to initialize them.
+ *
+ * @note It is instantiated and initialized by confdefs.h based upon
+ * application requirements.
+ */
+extern void (*_POSIX_Threads_Initialize_user_threads_p)(void);
+
+/**
+ * @brief _POSIX_Threads_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _POSIX_Threads_Manager_initialization(void);
+
+/**
+ * @brief _POSIX_Threads_Allocate
+ *
+ * This function allocates a pthread control block from
+ * the inactive chain of free pthread control blocks.
+ *
+ * @return This method returns a newly allocated thread.
+ */
+RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void );
+
+/**
+ * @brief _POSIX_Threads_Free
+ *
+ * This routine frees a pthread control block to the
+ * inactive chain of free pthread control blocks.
+ *
+ * @param[in] the_pthread is the thread to free
+ */
+RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free(
+ Thread_Control *the_pthread
+);
+
+/**
+ * @brief _POSIX_Threads_Get
+ *
+ * This function maps pthread IDs to pthread control blocks.
+ * If ID corresponds to a local pthread, then it returns
+ * the_pthread control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the pthread ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_pthread is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_pthread is undefined.
+ *
+ * @param[in] id is the id to lookup
+ * @param[in] location points to the returned location value
+ *
+ * @return This methods returns a pointer to the corresponding Thread_Control.
+ */
+RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get(
+ pthread_t id,
+ Objects_Locations *location
+);
+
+/**
+ * @brief _POSIX_Threads_Is_null
+ *
+ * This function returns TRUE if the_pthread is NULL and FALSE otherwise.
+ *
+ * @param[in] the_pthread is the thread pointer to check.
+ *
+ * @return This method returns true if the thread pointer is null.
+ */
+RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null(
+ Thread_Control *the_pthread
+);
+
+/**
+ * @brief _POSIX_Threads_Sporadic_budget_callout
+ *
+ * This routine handles the sporadic scheduling algorithm.
+ *
+ * @param[in] the_thread is the thread whose budget has been exceeded.
+ */
+void _POSIX_Threads_Sporadic_budget_callout(
+ Thread_Control *the_thread
+);
+
+/**
+ * _POSIX_Threads_Sporadic_budget_TSR
+ *
+ * This routine supports the sporadic scheduling algorithm. It
+ * is scheduled to be executed at the end of each replenishment
+ * period. In sporadic scheduling a thread will execute at a
+ * high priority for a user specified amount of CPU time. When
+ * it exceeds that amount of CPU time, its priority is automatically
+ * lowered. This TSR is executed when it is time to replenish
+ * the thread's processor budget and raise its priority.
+ *
+ * @param[in] id is ignored
+ * @param[in] argument is a pointer to the Thread_Control structure
+ * for the thread being replenished.
+ */
+void _POSIX_Threads_Sporadic_budget_TSR(
+ Objects_Id id,
+ void *argument
+);
+
+/**
+ * @brief Translate sched_param into SuperCore Terms
+ *
+ * This method translates the POSIX API sched_param into the corresponding
+ * SuperCore settings.
+ *
+ * @param[in] policy is the POSIX scheduling policy
+ * @param[in] param points to the scheduling parameter structure
+ * @param[in] budget_algorithm points to the output CPU Budget algorithm
+ * @param[in] budget_callout points to the output CPU Callout
+ *
+ * @return This method returns 0 on success or a POSIX error code.
+ */
+int _POSIX_Thread_Translate_sched_param(
+ int policy,
+ struct sched_param *param,
+ Thread_CPU_budget_algorithms *budget_algorithm,
+ Thread_CPU_budget_algorithm_callout *budget_callout
+);
+
+#include <rtems/posix/pthread.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/ptimer.h b/cpukit/posix/include/rtems/posix/ptimer.h
new file mode 100644
index 0000000000..79fba9d819
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/ptimer.h
@@ -0,0 +1,94 @@
+/**
+ * @file rtems/posix/ptimer.h
+ */
+
+/* rtems/posix/ptimer.h
+ *
+ * This include file contains all the private support information for
+ * POSIX timers.
+ *
+ * COPYRIGHT (c) 1998.
+ * Alfonso Escalera Piña
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * ptimer.h,v 1.0 1998/03/31 16:21:16
+ */
+
+#ifndef _RTEMS_POSIX_PTIMER_H
+#define _RTEMS_POSIX_PTIMER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/posix/config.h>
+
+/*
+ * _POSIX_Timers_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+
+void _POSIX_Timer_Manager_initialization(void);
+
+/*
+ * 14.2.2 Create a Per-Process Timer, P1003.1b-1993, p. 264
+ *
+ * timer_create
+ */
+
+int timer_create(
+ clockid_t clock_id,
+ struct sigevent *evp,
+ timer_t *timerid
+);
+
+/*
+ * 14.2.3 Delete a Per_process Timer, P1003.1b-1993, p. 266
+ */
+
+int timer_delete(
+ timer_t timerid
+);
+
+/*
+ * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
+ *
+ * timer_settime
+ */
+
+int timer_settime(
+ timer_t timerid,
+ int flags,
+ const struct itimerspec *value,
+ struct itimerspec *ovalue
+);
+
+/*
+ * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
+ *
+ * timer_gettime
+ */
+
+int timer_gettime(
+ timer_t timerid,
+ struct itimerspec *value
+);
+
+/*
+ * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
+ *
+ * timer_getoverrun
+ *
+ */
+
+int timer_getoverrun(
+ timer_t timerid
+);
+
+#endif
diff --git a/cpukit/posix/include/rtems/posix/rwlock.h b/cpukit/posix/include/rtems/posix/rwlock.h
new file mode 100644
index 0000000000..2774e02379
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/rwlock.h
@@ -0,0 +1,88 @@
+/**
+ * @file rtems/posix/rwlock.h
+ */
+
+/*
+ * This include file contains all the constants and structures associated
+ * with the POSIX RWLock Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a RWLock
+ * + delete a RWLock
+ * + wait for a RWLock
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_RWLOCK_H
+#define _RTEMS_POSIX_RWLOCK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/corerwlock.h>
+
+/**
+ * This type defines the control block used to manage each RWLock.
+ */
+
+typedef struct {
+ /** This is used to manage a RWLock as an object. */
+ Objects_Control Object;
+ /** This is used to implement the RWLock. */
+ CORE_RWLock_Control RWLock;
+} POSIX_RWLock_Control;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_RWLock_Information;
+
+/**
+ * @brief _POSIX_RWLock_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ *
+ * @param[in] maximum_rwlocks is the total number of RWLocks allowed to
+ * concurrently be active in the system.
+ */
+
+void _POSIX_RWLock_Manager_initialization(void);
+
+/**
+ * @brief _POSIX_RWLock_Translate_core_RWLock_return_code (
+ *
+ * This routine translates SuperCore RWLock status codes into the
+ * corresponding POSIX ones.
+ *
+ *
+ * @param[in] the_RWLock_status is the SuperCore status.
+ *
+ * @return the corresponding POSIX status
+ */
+int _POSIX_RWLock_Translate_core_RWLock_return_code(
+ CORE_RWLock_Status the_RWLock_status
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/posix/rwlock.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/semaphore.h b/cpukit/posix/include/rtems/posix/semaphore.h
new file mode 100644
index 0000000000..5f232eea54
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/semaphore.h
@@ -0,0 +1,198 @@
+/**
+ * @file rtems/posix/semaphore.h
+ */
+
+/* rtems/posix/semaphore.h
+ *
+ * This include file contains all the private support information for
+ * POSIX Semaphores.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_SEMAPHORE_H
+#define _RTEMS_POSIX_SEMAPHORE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <semaphore.h>
+#include <rtems/score/coresem.h>
+
+/*
+ * Data Structure used to manage a POSIX semaphore
+ */
+
+typedef struct {
+ Objects_Control Object;
+ int process_shared;
+ bool named;
+ bool linked;
+ uint32_t open_count;
+ CORE_semaphore_Control Semaphore;
+ /*
+ * sem_t is 32-bit. If Object_Id is 16-bit, then they are not
+ * interchangeable. We have to be able to return a pointer to
+ * a 32-bit form of the 16-bit Id.
+ */
+ #if defined(RTEMS_USE_16_BIT_OBJECT)
+ sem_t Semaphore_id;
+ #endif
+} POSIX_Semaphore_Control;
+
+/*
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_Semaphore_Information;
+
+/*
+ * _POSIX_Semaphore_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+
+void _POSIX_Semaphore_Manager_initialization(void);
+
+/*
+ * _POSIX_Semaphore_Allocate
+ *
+ * DESCRIPTION:
+ *
+ * This function allocates a semaphore control block from
+ * the inactive chain of free semaphore control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void );
+
+/*
+ * _POSIX_Semaphore_Free
+ *
+ * DESCRIPTION:
+ *
+ * This routine frees a semaphore control block to the
+ * inactive chain of free semaphore control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free (
+ POSIX_Semaphore_Control *the_semaphore
+);
+
+/*
+ * _POSIX_Semaphore_Get
+ *
+ * DESCRIPTION:
+ *
+ * This function maps semaphore IDs to semaphore control blocks.
+ * If ID corresponds to a local semaphore, then it returns
+ * the_semaphore control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the semaphore ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_semaphore is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_semaphore is undefined.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
+ sem_t *id,
+ Objects_Locations *location
+);
+
+/*
+ * _POSIX_Semaphore_Is_null
+ *
+ * DESCRIPTION:
+ *
+ * This function returns TRUE if the_semaphore is NULL and FALSE otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Semaphore_Is_null (
+ POSIX_Semaphore_Control *the_semaphore
+);
+
+/*
+ * _POSIX_Semaphore_Create_support
+ *
+ * DESCRIPTION:
+ *
+ * This routine supports the sem_init and sem_open routines.
+ */
+
+int _POSIX_Semaphore_Create_support(
+ const char *name,
+ int pshared,
+ unsigned int value,
+ POSIX_Semaphore_Control **the_sem
+);
+
+/*
+ * _POSIX_Semaphore_Delete
+ *
+ * DESCRIPTION:
+ *
+ * This routine supports the sem_close and sem_unlink routines.
+ */
+
+void _POSIX_Semaphore_Delete(
+ POSIX_Semaphore_Control *the_semaphore
+);
+
+/*
+ * _POSIX_Semaphore_Wait_support
+ *
+ * DESCRIPTION:
+ *
+ * This routine supports the sem_wait, sem_trywait, and sem_timedwait
+ * services.
+ */
+
+int _POSIX_Semaphore_Wait_support(
+ sem_t *sem,
+ bool blocking,
+ Watchdog_Interval timeout
+);
+
+/*
+ * _POSIX_Semaphore_Name_to_id
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs name to id translation.
+ */
+
+int _POSIX_Semaphore_Name_to_id(
+ const char *name,
+ sem_t *id
+);
+
+/*
+ * _POSIX_Semaphore_Translate_core_semaphore_return_code
+ *
+ * DESCRIPTION:
+ *
+ * A support routine which converts core semaphore status codes into the
+ * appropriate POSIX status values.
+ */
+
+int _POSIX_Semaphore_Translate_core_semaphore_return_code(
+ CORE_semaphore_Status the_semaphore_status
+);
+
+#include <rtems/posix/semaphore.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/sigset.h b/cpukit/posix/include/rtems/posix/sigset.h
new file mode 100644
index 0000000000..338879e5e2
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/sigset.h
@@ -0,0 +1,42 @@
+/**
+ * @file rtems/posix/sigset.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_SIGSET_H
+#define _RTEMS_POSIX_SIGSET_H
+
+#include <signal.h> // sigset_t
+
+/*
+ * Currently 32 signals numbered 1-32 are defined
+ */
+
+#define SIGNAL_EMPTY_MASK 0x00000000L
+#define SIGNAL_ALL_MASK 0xffffffffL
+
+static inline sigset_t signo_to_mask(
+ uint32_t sig
+)
+{
+ return 1u << (sig - 1);
+}
+
+static inline bool is_valid_signo(
+ int signo
+)
+{
+ return ((signo) >= 1 && (signo) <= 32 );
+}
+
+#endif
diff --git a/cpukit/posix/include/rtems/posix/spinlock.h b/cpukit/posix/include/rtems/posix/spinlock.h
new file mode 100644
index 0000000000..cf6cb6fbd2
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/spinlock.h
@@ -0,0 +1,88 @@
+/**
+ * @file rtems/posix/spinlock.h
+ */
+
+/*
+ * This include file contains all the constants and structures associated
+ * with the POSIX Spinlock Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a spinlock
+ * + delete a spinlock
+ * + wait for a spinlock
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_SPINLOCK_H
+#define _RTEMS_POSIX_SPINLOCK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/corespinlock.h>
+
+/**
+ * This type defines the control block used to manage each spinlock.
+ */
+
+typedef struct {
+ /** This is used to manage a spinlock as an object. */
+ Objects_Control Object;
+ /** This is used to implement the spinlock. */
+ CORE_spinlock_Control Spinlock;
+} POSIX_Spinlock_Control;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+
+POSIX_EXTERN Objects_Information _POSIX_Spinlock_Information;
+
+/**
+ * @brief _POSIX_Spinlock_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ *
+ * @param[in] maximum_spinlocks is the total number of spinlocks allowed to
+ * concurrently be active in the system.
+ */
+
+void _POSIX_Spinlock_Manager_initialization(void);
+
+/**
+ * @brief _POSIX_Spinlock_Translate_core_spinlock_return_code (
+ *
+ * This routine translates SuperCore Spinlock status codes into the
+ * corresponding POSIX ones.
+ *
+ *
+ * @param[in] the_spinlock_status is the SuperCore status.
+ *
+ * @return the corresponding POSIX status
+ */
+int _POSIX_Spinlock_Translate_core_spinlock_return_code(
+ CORE_spinlock_Status the_spinlock_status
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/posix/spinlock.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
new file mode 100644
index 0000000000..cc3a87e99a
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -0,0 +1,95 @@
+/**
+ * @file rtems/posix/threadsup.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_THREADSUP_H
+#define _RTEMS_POSIX_THREADSUP_H
+
+#include <sys/signal.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/tqdata.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+ * This defines the POSIX API support structure associated with
+ * each thread in a system with POSIX configured.
+ */
+typedef struct {
+ /** This is the POSIX threads attribute set. */
+ pthread_attr_t Attributes;
+ /** This indicates whether the thread is attached or detached. */
+ int detachstate;
+ /** This is the set of threads waiting for the thread to exit. */
+ Thread_queue_Control Join_List;
+ /** This is the thread's current scheduling policy. */
+ int schedpolicy;
+ /** This is the thread's current set of scheduling parameters. */
+ struct sched_param schedparam;
+ /**
+ * This is the high priority to execute at when using the sporadic
+ * scheduler.
+ */
+ int ss_high_priority;
+ /**
+ * This is the timer which controls when the thread executes at
+ * high and low priority when using the sporadic scheduler.
+ */
+ Watchdog_Control Sporadic_timer;
+
+ /** This is the set of signals which are currently blocked. */
+ sigset_t signals_blocked;
+ /** This is the set of signals which are currently pending. */
+ sigset_t signals_pending;
+
+ /*******************************************************************/
+ /*******************************************************************/
+ /*************** POSIX Cancelability ***************/
+ /*******************************************************************/
+ /*******************************************************************/
+
+ /** This is the cancelability state. */
+ int cancelability_state;
+ /** This is the cancelability type. */
+ int cancelability_type;
+ /** This indicates if a cancelation has been requested. */
+ int cancelation_requested;
+ /** This is the set of cancelation handlers. */
+ Chain_Control Cancellation_Handlers;
+
+} POSIX_API_Control;
+
+/*!
+ * @brief POSIX Thread Exit Shared Helper
+ *
+ * This method is a helper routine which ensures that all
+ * POSIX thread calls which result in a thread exiting will
+ * do so in the same manner.
+ *
+ * @param[in] the_thread is the thread exiting or being canceled
+ * @param[in] value_ptr is the value to be returned by the thread
+ */
+void _POSIX_Thread_Exit(
+ Thread_Control *the_thread,
+ void *value_ptr
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/time.h b/cpukit/posix/include/rtems/posix/time.h
new file mode 100644
index 0000000000..93e3af0f44
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/time.h
@@ -0,0 +1,59 @@
+/**
+ * @file rtems/posix/time.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_TIME_H
+#define _RTEMS_POSIX_TIME_H
+
+#include <rtems/score/timespec.h>
+#include <rtems/score/watchdog.h>
+
+/** @brief Absolute Timeout Conversion Results
+ *
+ * This enumeration defines the possible results of converting
+ * an absolute time used for timeouts to POSIX blocking calls to
+ * a number of ticks.
+ */
+typedef enum {
+ /** The timeout is invalid. */
+ POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ /** The timeout represents a time that is in the past. */
+ POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST,
+ /** The timeout represents a time that is equal to the current time. */
+ POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ /** The timeout represents a time that is in the future. */
+ POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE,
+} POSIX_Absolute_timeout_conversion_results_t;
+
+/**
+ * @brief Convert Absolute Timeout to Ticks
+ *
+ * This method takes an absolute time being used as a timeout
+ * to a blocking directive, validates it and returns the number
+ * of corresponding clock ticks for use by the SuperCore.
+ *
+ * @param[in] abstime is the timeout
+ * @param[in] ticks_out will contain the number of ticks
+ *
+ * @return This method returns the number of ticks in @a ticks_out
+ * and a status value indicating whether the absolute time
+ * is valid, in the past, equal to the current time or in
+ * the future as it should be.
+ */
+POSIX_Absolute_timeout_conversion_results_t _POSIX_Absolute_timeout_to_ticks(
+ const struct timespec *abstime,
+ Watchdog_Interval *ticks_out
+);
+
+#endif
diff --git a/cpukit/posix/include/rtems/posix/timer.h b/cpukit/posix/include/rtems/posix/timer.h
new file mode 100644
index 0000000000..c061e9d6b7
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/timer.h
@@ -0,0 +1,107 @@
+/**
+ * @file rtems/posix/timer.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_TIMER_H
+#define _RTEMS_POSIX_TIMER_H
+
+#include <rtems/posix/config.h>
+#include <rtems/score/object.h>
+#include <rtems/score/watchdog.h> /* Watchdog_Control */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Timer is free */
+#define POSIX_TIMER_STATE_FREE 0x01
+
+/* Created timer but not running */
+#define POSIX_TIMER_STATE_CREATE_NEW 0x02
+
+/* Created timer and running */
+#define POSIX_TIMER_STATE_CREATE_RUN 0x03
+
+/* Created, ran and stopped timer */
+#define POSIX_TIMER_STATE_CREATE_STOP 0x04
+
+/* Indicates that the fire time is relative to the current one */
+#define POSIX_TIMER_RELATIVE 0
+
+/*
+ * POSIX defines TIMER_ABSTIME but no constant for relative. So
+ * we have one internally but we need to be careful it has a different
+ * value.
+ */
+#if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME)
+#error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME"
+#endif
+
+
+/*
+ * Data for a timer
+ */
+typedef struct {
+ Objects_Control Object;
+ Watchdog_Control Timer; /* Internal Timer */
+ pthread_t thread_id; /* Thread identifier */
+ char state; /* State of the timer */
+ struct sigevent inf; /* Information associated to the timer */
+ struct itimerspec timer_data; /* Timing data of the timer */
+ uint32_t ticks; /* Number of ticks of the initialization */
+ uint32_t overrun; /* Number of expirations of the timer */
+ struct timespec time; /* Time at which the timer was started */
+} POSIX_Timer_Control;
+
+/*
+ * _POSIX_Timers_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _POSIX_Timer_Manager_initialization(void);
+
+/*
+ * Timer TSR
+ */
+void _POSIX_Timer_TSR(Objects_Id timer, void *data);
+
+/*
+ * Watchdog Insert helper
+ */
+bool _POSIX_Timer_Insert_helper(
+ Watchdog_Control *timer,
+ Watchdog_Interval ticks,
+ Objects_Id id,
+ Watchdog_Service_routine_entry TSR,
+ void *arg
+);
+
+/*
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+POSIX_EXTERN Objects_Information _POSIX_Timer_Information;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/posix/timer.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/semaphore.h b/cpukit/posix/include/semaphore.h
new file mode 100644
index 0000000000..5727456b34
--- /dev/null
+++ b/cpukit/posix/include/semaphore.h
@@ -0,0 +1,124 @@
+/**
+ * @file semaphore.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _SEMAPHORE_H
+#define _SEMAPHORE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <unistd.h>
+
+#if defined(_POSIX_SEMAPHORES)
+
+#include <sys/time.h>
+
+/*
+ * 11.1 Semaphore Characteristics, P1003.1b-1993, p.219
+ */
+typedef int sem_t;
+
+/*
+ * Bad semaphore Id
+ */
+#define SEM_FAILED (sem_t *) -1
+
+/*
+ * 11.2.1 Initialize an Unnamed Semaphore, P1003.1b-1993, p.219
+ */
+int sem_init(
+ sem_t *sem,
+ int pshared,
+ unsigned int value
+);
+
+/*
+ * 11.2.2 Destroy an Unnamed Semaphore, P1003.1b-1993, p.220
+ */
+int sem_destroy(
+ sem_t *sem
+);
+
+/*
+ * 11.2.3 Initialize/Open a Named Semaphore, P1003.1b-1993, p.221
+ *
+ * NOTE: Follows open() calling conventions.
+ */
+sem_t *sem_open(
+ const char *name,
+ int oflag,
+ ...
+);
+
+/*
+ * 11.2.4 Close a Named Semaphore, P1003.1b-1993, p.224
+ */
+int sem_close(
+ sem_t *sem
+);
+
+/*
+ * 11.2.5 Remove a Named Semaphore, P1003.1b-1993, p.225
+ */
+int sem_unlink(
+ const char *name
+);
+
+/*
+ * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226
+ *
+ * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27
+ */
+int sem_wait(
+ sem_t *sem
+);
+
+int sem_trywait(
+ sem_t *sem
+);
+
+#if defined(_POSIX_TIMEOUTS)
+int sem_timedwait(
+ sem_t *sem,
+ const struct timespec *timeout
+);
+#endif
+
+/*
+ * 11.2.7 Unlock a Semaphore, P1003.1b-1993, p.227
+ */
+
+int sem_post(
+ sem_t *sem
+);
+
+/*
+ * 11.2.8 Get the Value of a Semaphore, P1003.1b-1993, p.229
+ */
+
+int sem_getvalue(
+ sem_t *sem,
+ int *sval
+);
+
+#endif /* _POSIX_SEMAPHORES */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/inline/rtems/posix/barrier.inl b/cpukit/posix/inline/rtems/posix/barrier.inl
new file mode 100644
index 0000000000..2557f33cd8
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/barrier.inl
@@ -0,0 +1,89 @@
+/**
+ * @file rtems/posix/barrier.inl
+ */
+
+/*
+ * This file contains the static inlin implementation of the inlined
+ * routines from the POSIX Barrier Manager.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_BARRIER_H
+# error "Never use <rtems/posix/barrier.inl> directly; include <rtems/posix/barrier.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_BARRIER_INL
+#define _RTEMS_POSIX_BARRIER_INL
+
+#include <pthread.h>
+
+/**
+ * @brief _POSIX_Barrier_Allocate
+ *
+ * This function allocates a barrier control block from
+ * the inactive chain of free barrier control blocks.
+ */
+RTEMS_INLINE_ROUTINE POSIX_Barrier_Control *_POSIX_Barrier_Allocate( void )
+{
+ return (POSIX_Barrier_Control *)
+ _Objects_Allocate( &_POSIX_Barrier_Information );
+}
+
+/**
+ * @brief _POSIX_Barrier_Free
+ *
+ * This routine frees a barrier control block to the
+ * inactive chain of free barrier control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _POSIX_Barrier_Free (
+ POSIX_Barrier_Control *the_barrier
+)
+{
+ _Objects_Free( &_POSIX_Barrier_Information, &the_barrier->Object );
+}
+
+/**
+ * @brief _POSIX_Barrier_Get
+ *
+ * This function maps barrier IDs to barrier control blocks.
+ * If ID corresponds to a local barrier, then it returns
+ * the_barrier control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the barrier ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_barrier is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_barrier is undefined.
+ */
+RTEMS_INLINE_ROUTINE POSIX_Barrier_Control *_POSIX_Barrier_Get (
+ pthread_barrier_t *barrier,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Barrier_Control *) _Objects_Get(
+ &_POSIX_Barrier_Information,
+ (Objects_Id) *barrier,
+ location
+ );
+}
+
+/**
+ * @brief _POSIX_Barrier_Is_null
+ *
+ * This function returns TRUE if the_barrier is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _POSIX_Barrier_Is_null (
+ POSIX_Barrier_Control *the_barrier
+)
+{
+ return ( the_barrier == NULL );
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/inline/rtems/posix/cond.inl b/cpukit/posix/inline/rtems/posix/cond.inl
new file mode 100644
index 0000000000..3b011c0383
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/cond.inl
@@ -0,0 +1,70 @@
+/**
+ * @file rtems/posix/cond.inl
+ */
+
+/* rtems/posix/cond.inl
+ *
+ * This include file contains the static inline implementation of the private
+ * inlined routines for POSIX condition variables.
+ *
+ * COPYRIGHT (c) 1989-2002.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_COND_H
+# error "Never use <rtems/posix/cond.inl> directly; include <rtems/posix/cond.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_COND_INL
+#define _RTEMS_POSIX_COND_INL
+
+#include <pthread.h>
+
+/*PAGE
+ *
+ * _POSIX_Condition_variables_Allocate
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Condition_variables_Control
+ *_POSIX_Condition_variables_Allocate( void )
+{
+ return (POSIX_Condition_variables_Control *)
+ _Objects_Allocate( &_POSIX_Condition_variables_Information );
+}
+
+/*PAGE
+ *
+ * _POSIX_Condition_variables_Free
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Free (
+ POSIX_Condition_variables_Control *the_condition_variable
+)
+{
+ _Objects_Free(
+ &_POSIX_Condition_variables_Information,
+ &the_condition_variable->Object
+ );
+}
+
+/*PAGE
+ *
+ * _POSIX_Condition_variables_Is_null
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Condition_variables_Is_null (
+ POSIX_Condition_variables_Control *the_condition_variable
+)
+{
+ return !the_condition_variable;
+}
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/posix/inline/rtems/posix/key.inl b/cpukit/posix/inline/rtems/posix/key.inl
new file mode 100644
index 0000000000..c5c6324d06
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/key.inl
@@ -0,0 +1,86 @@
+/**
+ * @file rtems/posix/key.inl
+ *
+ * This include file contains the static inline implementation of the private
+ * inlined routines for POSIX key's.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_KEY_H
+# error "Never use <rtems/posix/key.inl> directly; include <rtems/posix/key.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_KEY_INL
+#define _RTEMS_POSIX_KEY_INL
+
+/**
+ * @brief _POSIX_Keys_Allocate
+ *
+ * This function allocates a keys control block from
+ * the inactive chain of free keys control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
+{
+ return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
+}
+
+/**
+ * @brief _POSIX_Keys_Free
+ *
+ * This routine frees a keys control block to the
+ * inactive chain of free keys control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
+ POSIX_Keys_Control *the_key
+)
+{
+ _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
+}
+
+/**
+ * @brief _POSIX_Keys_Get
+ *
+ * This function maps key IDs to key control blocks.
+ * If ID corresponds to a local keys, then it returns
+ * the_key control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the keys ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_key is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_key is undefined.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get (
+ pthread_key_t id,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Keys_Control *)
+ _Objects_Get( &_POSIX_Keys_Information, (Objects_Id) id, location );
+}
+
+/**
+ * @brief _POSIX_Keys_Is_null
+ *
+ * This function returns TRUE if the_key is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _POSIX_Keys_Is_null (
+ POSIX_Keys_Control *the_key
+)
+{
+ return !the_key;
+}
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/posix/inline/rtems/posix/mqueue.inl b/cpukit/posix/inline/rtems/posix/mqueue.inl
new file mode 100644
index 0000000000..62bc3ce327
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/mqueue.inl
@@ -0,0 +1,160 @@
+/**
+ * @file rtems/posix/mqueue.inl
+ */
+
+/* rtems/posix/mqueue.inl
+ *
+ * This include file contains the static inline implementation of the private
+ * inlined routines for POSIX Message Queue.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_MQUEUE_H
+# error "Never use <rtems/posix/mqueue.inl> directly; include <rtems/posix/mqueue.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_MQUEUE_INL
+#define _RTEMS_POSIX_MQUEUE_INL
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Allocate
+ */
+
+RTEMS_INLINE_ROUTINE
+ POSIX_Message_queue_Control *_POSIX_Message_queue_Allocate( void )
+{
+ return (POSIX_Message_queue_Control *)
+ _Objects_Allocate( &_POSIX_Message_queue_Information );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Allocate_fd
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control_fd *
+ _POSIX_Message_queue_Allocate_fd( void )
+{
+ return (POSIX_Message_queue_Control_fd *)
+ _Objects_Allocate( &_POSIX_Message_queue_Information_fds );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Free
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Message_queue_Free (
+ POSIX_Message_queue_Control *the_mq
+)
+{
+ _Objects_Free( &_POSIX_Message_queue_Information, &the_mq->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Free_fd
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Message_queue_Free_fd (
+ POSIX_Message_queue_Control_fd *the_mq_fd
+)
+{
+ _Objects_Free( &_POSIX_Message_queue_Information_fds, &the_mq_fd->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Namespace_remove
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Message_queue_Namespace_remove (
+ POSIX_Message_queue_Control *the_mq
+)
+{
+ _Objects_Namespace_remove(
+ &_POSIX_Message_queue_Information, &the_mq->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Get
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control *_POSIX_Message_queue_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Message_queue_Control *)
+ _Objects_Get( &_POSIX_Message_queue_Information, id, location );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Get_fd
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control_fd *_POSIX_Message_queue_Get_fd (
+ mqd_t id,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Message_queue_Control_fd *) _Objects_Get(
+ &_POSIX_Message_queue_Information_fds,
+ (Objects_Id)id,
+ location
+ );
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Is_null
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Message_queue_Is_null (
+ POSIX_Message_queue_Control *the_mq
+)
+{
+ return !the_mq;
+}
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Priority_to_core
+ */
+
+RTEMS_INLINE_ROUTINE CORE_message_queue_Submit_types _POSIX_Message_queue_Priority_to_core(
+ unsigned int priority
+)
+{
+ return priority * -1;
+}
+
+/*
+ * _POSIX_Message_queue_Priority_from_core
+ *
+ * DESCRIPTION:
+ *
+ * XXX
+ */
+
+RTEMS_INLINE_ROUTINE unsigned int _POSIX_Message_queue_Priority_from_core(
+ CORE_message_queue_Submit_types priority
+)
+{
+ /* absolute value without a library dependency */
+ return ((priority >= 0) ? priority : -priority);
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/inline/rtems/posix/mutex.inl b/cpukit/posix/inline/rtems/posix/mutex.inl
new file mode 100644
index 0000000000..b5e3721a3a
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/mutex.inl
@@ -0,0 +1,63 @@
+/**
+ * @file rtems/posix/mutex.inl
+ */
+
+/* rtems/posix/mutex.inl
+ *
+ * This include file contains the static inline implementation of the private
+ * inlined routines for POSIX mutex's.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_MUTEX_H
+# error "Never use <rtems/posix/mutex.inl> directly; include <rtems/posix/mutex.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_MUTEX_INL
+#define _RTEMS_POSIX_MUTEX_INL
+
+/*PAGE
+ *
+ * _POSIX_Mutex_Allocate
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void )
+{
+ return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information );
+}
+
+/*PAGE
+ *
+ * _POSIX_Mutex_Free
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free (
+ POSIX_Mutex_Control *the_mutex
+)
+{
+ _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Mutex_Is_null
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Mutex_Is_null (
+ POSIX_Mutex_Control *the_mutex
+)
+{
+ return !the_mutex;
+}
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/posix/inline/rtems/posix/priority.inl b/cpukit/posix/inline/rtems/posix/priority.inl
new file mode 100644
index 0000000000..9a9f538a61
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/priority.inl
@@ -0,0 +1,37 @@
+/**
+ * @file rtems/posix/priority.inl
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_PRIORITY_H
+# error "Never use <rtems/posix/priority.inl> directly; include <rtems/posix/priority.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_PRIORITY_INL
+#define _RTEMS_POSIX_PRIORITY_INL
+
+RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
+ int priority
+)
+{
+ return (Priority_Control) (POSIX_SCHEDULER_MAXIMUM_PRIORITY - priority + 1);
+}
+
+RTEMS_INLINE_ROUTINE int _POSIX_Priority_From_core(
+ Priority_Control priority
+)
+{
+ return (POSIX_SCHEDULER_MAXIMUM_PRIORITY - priority + 1);
+}
+
+#endif
diff --git a/cpukit/posix/inline/rtems/posix/pthread.inl b/cpukit/posix/inline/rtems/posix/pthread.inl
new file mode 100644
index 0000000000..7f35e9a08b
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/pthread.inl
@@ -0,0 +1,77 @@
+/**
+ * @file rtems/posix/pthread.inl
+ */
+
+/* rtems/posix/pthread.inl
+ *
+ * This include file contains the static inline implementation of the private
+ * inlined routines for POSIX threads.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_PTHREAD_H
+# error "Never use <rtems/posix/pthread.inl> directly; include <rtems/posix/pthread.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_PTHREAD_INL
+#define _RTEMS_POSIX_PTHREAD_INL
+
+/*PAGE
+ *
+ * _POSIX_Threads_Allocate
+ */
+
+RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void )
+{
+ return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information );
+}
+
+/*PAGE
+ *
+ * _POSIX_Threads_Free
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
+ Thread_Control *the_pthread
+)
+{
+ _Objects_Free( &_POSIX_Threads_Information, &the_pthread->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Threads_Get
+ */
+
+RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Get (
+ pthread_t id,
+ Objects_Locations *location
+)
+{
+ return (Thread_Control *)
+ _Objects_Get( &_POSIX_Threads_Information, (Objects_Id)id, location );
+}
+
+/*PAGE
+ *
+ * _POSIX_Threads_Is_null
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null (
+ Thread_Control *the_pthread
+)
+{
+ return !the_pthread;
+}
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/posix/inline/rtems/posix/rwlock.inl b/cpukit/posix/inline/rtems/posix/rwlock.inl
new file mode 100644
index 0000000000..ac11d35d3c
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/rwlock.inl
@@ -0,0 +1,89 @@
+/**
+ * @file rtems/posix/RWLock.inl
+ */
+
+/*
+ * This file contains the static inlin implementation of the inlined
+ * routines from the POSIX RWLock Manager.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_RWLOCK_H
+# error "Never use <rtems/posix/rwlock.inl> directly; include <rtems/posix/rwlock.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_RWLOCK_INL
+#define _RTEMS_POSIX_RWLOCK_INL
+
+#include <pthread.h>
+
+/**
+ * @brief _POSIX_RWLock_Allocate
+ *
+ * This function allocates a RWLock control block from
+ * the inactive chain of free RWLock control blocks.
+ */
+RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Allocate( void )
+{
+ return (POSIX_RWLock_Control *)
+ _Objects_Allocate( &_POSIX_RWLock_Information );
+}
+
+/**
+ * @brief _POSIX_RWLock_Free
+ *
+ * This routine frees a RWLock control block to the
+ * inactive chain of free RWLock control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _POSIX_RWLock_Free (
+ POSIX_RWLock_Control *the_RWLock
+)
+{
+ _Objects_Free( &_POSIX_RWLock_Information, &the_RWLock->Object );
+}
+
+/**
+ * @brief _POSIX_RWLock_Get
+ *
+ * This function maps RWLock IDs to RWLock control blocks.
+ * If ID corresponds to a local RWLock, then it returns
+ * the_RWLock control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the RWLock ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_RWLock is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_RWLock is undefined.
+ */
+RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Get (
+ pthread_rwlock_t *RWLock,
+ Objects_Locations *location
+)
+{
+ return (POSIX_RWLock_Control *) _Objects_Get(
+ &_POSIX_RWLock_Information,
+ (Objects_Id) *RWLock,
+ location
+ );
+}
+
+/**
+ * @brief _POSIX_RWLock_Is_null
+ *
+ * This function returns TRUE if the_RWLock is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _POSIX_RWLock_Is_null (
+ POSIX_RWLock_Control *the_RWLock
+)
+{
+ return ( the_RWLock == NULL );
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/inline/rtems/posix/semaphore.inl b/cpukit/posix/inline/rtems/posix/semaphore.inl
new file mode 100644
index 0000000000..eb885f1aa0
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/semaphore.inl
@@ -0,0 +1,92 @@
+/**
+ * @file rtems/posix/semaphore.inl
+ */
+
+/* rtems/posix/semaphore.inl
+ *
+ * This include file contains the static inline implementation of the private
+ * inlined routines for POSIX Semaphores.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_SEMAPHORE_H
+# error "Never use <rtems/posix/semaphore.inl> directly; include <rtems/posix/semaphore.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_SEMAPHORE_INL
+#define _RTEMS_POSIX_SEMAPHORE_INL
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Allocate
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void )
+{
+ return (POSIX_Semaphore_Control *)
+ _Objects_Allocate( &_POSIX_Semaphore_Information );
+}
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Free
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free (
+ POSIX_Semaphore_Control *the_semaphore
+)
+{
+ _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Namespace_remove
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove (
+ POSIX_Semaphore_Control *the_semaphore
+)
+{
+ _Objects_Namespace_remove(
+ &_POSIX_Semaphore_Information, &the_semaphore->Object );
+}
+
+
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Get
+ */
+RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
+ sem_t *id,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Semaphore_Control *)
+ _Objects_Get( &_POSIX_Semaphore_Information, (Objects_Id)*id, location );
+}
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Is_null
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Semaphore_Is_null (
+ POSIX_Semaphore_Control *the_semaphore
+)
+{
+ return !the_semaphore;
+}
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/posix/inline/rtems/posix/spinlock.inl b/cpukit/posix/inline/rtems/posix/spinlock.inl
new file mode 100644
index 0000000000..6007258e01
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/spinlock.inl
@@ -0,0 +1,89 @@
+/**
+ * @file rtems/posix/spinlock.inl
+ */
+
+/*
+ * This file contains the static inlin implementation of the inlined
+ * routines from the POSIX Spinlock Manager.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_SPINLOCK_H
+# error "Never use <rtems/posix/spinlock.inl> directly; include <rtems/posix/spinlock.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_SPINLOCK_INL
+#define _RTEMS_POSIX_SPINLOCK_INL
+
+#include <pthread.h>
+
+/**
+ * @brief _POSIX_Spinlock_Allocate
+ *
+ * This function allocates a spinlock control block from
+ * the inactive chain of free spinlock control blocks.
+ */
+RTEMS_INLINE_ROUTINE POSIX_Spinlock_Control *_POSIX_Spinlock_Allocate( void )
+{
+ return (POSIX_Spinlock_Control *)
+ _Objects_Allocate( &_POSIX_Spinlock_Information );
+}
+
+/**
+ * @brief _POSIX_Spinlock_Free
+ *
+ * This routine frees a spinlock control block to the
+ * inactive chain of free spinlock control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _POSIX_Spinlock_Free (
+ POSIX_Spinlock_Control *the_spinlock
+)
+{
+ _Objects_Free( &_POSIX_Spinlock_Information, &the_spinlock->Object );
+}
+
+/**
+ * @brief _POSIX_Spinlock_Get
+ *
+ * This function maps spinlock IDs to spinlock control blocks.
+ * If ID corresponds to a local spinlock, then it returns
+ * the_spinlock control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the spinlock ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_spinlock is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_spinlock is undefined.
+ */
+RTEMS_INLINE_ROUTINE POSIX_Spinlock_Control *_POSIX_Spinlock_Get (
+ pthread_spinlock_t *spinlock,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Spinlock_Control *) _Objects_Get(
+ &_POSIX_Spinlock_Information,
+ (Objects_Id) *spinlock,
+ location
+ );
+}
+
+/**
+ * @brief _POSIX_Spinlock_Is_null
+ *
+ * This function returns TRUE if the_spinlock is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _POSIX_Spinlock_Is_null (
+ POSIX_Spinlock_Control *the_spinlock
+)
+{
+ return ( the_spinlock == NULL );
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/inline/rtems/posix/timer.inl b/cpukit/posix/inline/rtems/posix/timer.inl
new file mode 100644
index 0000000000..63db10c8ab
--- /dev/null
+++ b/cpukit/posix/inline/rtems/posix/timer.inl
@@ -0,0 +1,98 @@
+/**
+ * @file rtems/posix/timer.inl
+ */
+
+/* timer.inl
+ *
+ * This file contains the static inline implementation of the inlined routines
+ * from the POSIX Timer Manager.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POSIX_TIMER_H
+# error "Never use <rtems/posix/timer.inl> directly; include <rtems/posix/timer.h> instead."
+#endif
+
+#ifndef _RTEMS_POSIX_TIMER_INL
+#define _RTEMS_POSIX_TIMER_INL
+
+/*PAGE
+ *
+ * _POSIX_Timer_Allocate
+ *
+ * DESCRIPTION:
+ *
+ * This function allocates a timer control block from
+ * the inactive chain of free timer control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Allocate( void )
+{
+ return (POSIX_Timer_Control *) _Objects_Allocate( &_POSIX_Timer_Information );
+}
+
+/*PAGE
+ *
+ * _POSIX_Timer_Free
+ *
+ * DESCRIPTION:
+ *
+ * This routine frees a timer control block to the
+ * inactive chain of free timer control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE void _POSIX_Timer_Free (
+ POSIX_Timer_Control *the_timer
+)
+{
+ _Objects_Free( &_POSIX_Timer_Information, &the_timer->Object );
+}
+
+/*PAGE
+ *
+ * _POSIX_Timer_Get
+ *
+ * DESCRIPTION:
+ *
+ * This function maps timer IDs to timer control blocks.
+ * If ID corresponds to a local timer, then it returns
+ * the timer control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. Otherwise, location is set
+ * to OBJECTS_ERROR and the returned value is undefined.
+ */
+
+RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Get (
+ timer_t id,
+ Objects_Locations *location
+)
+{
+ return (POSIX_Timer_Control *)
+ _Objects_Get( &_POSIX_Timer_Information, (Objects_Id) id, location );
+}
+
+/*PAGE
+ *
+ * _POSIX_Timer_Is_null
+ *
+ * DESCRIPTION:
+ *
+ * This function returns TRUE if the_timer is NULL and FALSE otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _POSIX_Timer_Is_null (
+ POSIX_Timer_Control *the_timer
+)
+{
+ return (the_timer == NULL);
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
new file mode 100644
index 0000000000..119790b17e
--- /dev/null
+++ b/cpukit/posix/preinstall.am
@@ -0,0 +1,162 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/posix/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/posix
+ @: > $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/posix/sigset.h: include/rtems/posix/sigset.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/sigset.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/sigset.h
+
+if HAS_PTHREADS
+$(PROJECT_INCLUDE)/aio.h: include/aio.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/aio.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/aio.h
+
+$(PROJECT_INCLUDE)/mqueue.h: include/mqueue.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/mqueue.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/mqueue.h
+
+$(PROJECT_INCLUDE)/semaphore.h: include/semaphore.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/semaphore.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/semaphore.h
+
+$(PROJECT_INCLUDE)/rtems/posix/aio_misc.h: include/rtems/posix/aio_misc.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/aio_misc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/aio_misc.h
+
+$(PROJECT_INCLUDE)/rtems/posix/cancel.h: include/rtems/posix/cancel.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/cancel.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/cancel.h
+
+$(PROJECT_INCLUDE)/rtems/posix/cond.h: include/rtems/posix/cond.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/cond.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/cond.h
+
+$(PROJECT_INCLUDE)/rtems/posix/config.h: include/rtems/posix/config.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/config.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/config.h
+
+$(PROJECT_INCLUDE)/rtems/posix/key.h: include/rtems/posix/key.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/key.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/key.h
+
+$(PROJECT_INCLUDE)/rtems/posix/mqueue.h: include/rtems/posix/mqueue.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/mqueue.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/mqueue.h
+
+$(PROJECT_INCLUDE)/rtems/posix/mutex.h: include/rtems/posix/mutex.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/mutex.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/mutex.h
+
+$(PROJECT_INCLUDE)/rtems/posix/posixapi.h: include/rtems/posix/posixapi.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/posixapi.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/posixapi.h
+
+$(PROJECT_INCLUDE)/rtems/posix/priority.h: include/rtems/posix/priority.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priority.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priority.h
+
+$(PROJECT_INCLUDE)/rtems/posix/psignal.h: include/rtems/posix/psignal.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/psignal.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/psignal.h
+
+$(PROJECT_INCLUDE)/rtems/posix/pthread.h: include/rtems/posix/pthread.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/pthread.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/pthread.h
+
+$(PROJECT_INCLUDE)/rtems/posix/ptimer.h: include/rtems/posix/ptimer.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/ptimer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/ptimer.h
+
+$(PROJECT_INCLUDE)/rtems/posix/semaphore.h: include/rtems/posix/semaphore.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/semaphore.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/semaphore.h
+
+$(PROJECT_INCLUDE)/rtems/posix/threadsup.h: include/rtems/posix/threadsup.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/threadsup.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/threadsup.h
+
+$(PROJECT_INCLUDE)/rtems/posix/time.h: include/rtems/posix/time.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/time.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/time.h
+
+$(PROJECT_INCLUDE)/rtems/posix/timer.h: include/rtems/posix/timer.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timer.h
+
+$(PROJECT_INCLUDE)/rtems/posix/barrier.h: include/rtems/posix/barrier.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/barrier.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/barrier.h
+
+$(PROJECT_INCLUDE)/rtems/posix/rwlock.h: include/rtems/posix/rwlock.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlock.h
+
+$(PROJECT_INCLUDE)/rtems/posix/spinlock.h: include/rtems/posix/spinlock.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/spinlock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/spinlock.h
+
+$(PROJECT_INCLUDE)/rtems/posix/cond.inl: inline/rtems/posix/cond.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/cond.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/cond.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/key.inl: inline/rtems/posix/key.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/key.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/key.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/mqueue.inl: inline/rtems/posix/mqueue.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/mqueue.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/mqueue.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/mutex.inl: inline/rtems/posix/mutex.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/mutex.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/mutex.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/pthread.inl: inline/rtems/posix/pthread.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/pthread.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/pthread.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/priority.inl: inline/rtems/posix/priority.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priority.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priority.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/semaphore.inl: inline/rtems/posix/semaphore.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/semaphore.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/semaphore.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/timer.inl: inline/rtems/posix/timer.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timer.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timer.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/barrier.inl: inline/rtems/posix/barrier.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/barrier.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/barrier.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/rwlock.inl: inline/rtems/posix/rwlock.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlock.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlock.inl
+
+$(PROJECT_INCLUDE)/rtems/posix/spinlock.inl: inline/rtems/posix/spinlock.inl $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/spinlock.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/spinlock.inl
+endif
diff --git a/cpukit/posix/src/.cvsignore b/cpukit/posix/src/.cvsignore
new file mode 100644
index 0000000000..000074c626
--- /dev/null
+++ b/cpukit/posix/src/.cvsignore
@@ -0,0 +1,4 @@
+stamp-h
+stamp-h.in
+config.h
+config.h.in
diff --git a/cpukit/posix/src/README.mqueue b/cpukit/posix/src/README.mqueue
new file mode 100644
index 0000000000..12c8afc03e
--- /dev/null
+++ b/cpukit/posix/src/README.mqueue
@@ -0,0 +1,38 @@
+#
+# $Id$
+#
+
+This program should print out the default attribute settings for a
+POSIX message queue.
+
+#include <mqueue.h>
+#include <stdio.h>
+
+main()
+{
+ mqd_t mqfd;
+ struct mq_attr mqstat;
+ int status;
+
+ /* this should create it */
+ mqfd = mq_open("myipc",O_WRONLY|O_CREAT,NULL);
+ if ( (int)mqfd == -1 ) {
+ perror( "Unable to open message queue" );
+ exit( 1 );
+ }
+
+ status = mq_getattr(mqfd, &mqstat);
+ if ( !status ) {
+ printf( "mq_maxmsg: %d\n", mqstat.mq_maxmsg );
+ printf( "mq_msgsize: %d\n", mqstat.mq_msgsize );
+ printf( "mq_curmsgs: %d\n", mqstat.mq_curmsgs );
+ } else {
+ perror( "Unable to get attributes on message queue" );
+ exit( 1 );
+ }
+
+ /* this should delete it */
+ (void) mq_close( mqfd );
+ exit( 0 );
+}
+
diff --git a/cpukit/posix/src/_execve.c b/cpukit/posix/src/_execve.c
new file mode 100644
index 0000000000..0bd8c2e7d1
--- /dev/null
+++ b/cpukit/posix/src/_execve.c
@@ -0,0 +1,28 @@
+/*
+ * execve() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int _execve(
+ const char *path __attribute__((unused)),
+ char *const argv[] __attribute__((unused)),
+ char *const envp[] __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/adjtime.c b/cpukit/posix/src/adjtime.c
new file mode 100644
index 0000000000..89ccd7950d
--- /dev/null
+++ b/cpukit/posix/src/adjtime.c
@@ -0,0 +1,104 @@
+/*
+ * adjime() function
+ *
+ * This method was initially added as part of porting NTP to RTEMS.
+ * It is a BSD compatability function and now is available on
+ * GNU/Linux.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <sys/time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/seterr.h>
+#include <rtems/score/tod.h>
+#include <rtems/posix/time.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/timespec.h>
+
+/*
+ * At one point there was a static variable named adjustment
+ * used by this implementation. I don't see any reason for it
+ * to be here based upon the GNU/Linux documentation.
+ */
+
+int adjtime(
+ struct timeval *delta,
+ struct timeval *olddelta
+)
+{
+ struct timespec ts;
+ long adjustment;
+
+ /*
+ * Simple validations
+ */
+ if ( !delta )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( olddelta ) {
+ olddelta->tv_sec = 0;
+ olddelta->tv_usec = 0;
+ }
+
+ /* convert delta to microseconds */
+ adjustment = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND);
+ adjustment += delta->tv_usec;
+
+ /* too small to account for */
+ if ( adjustment < rtems_configuration_get_microseconds_per_tick() )
+ return 0;
+
+ /*
+ * This prevents context switches while we are adjusting the TOD
+ */
+
+ _Thread_Disable_dispatch();
+
+ _TOD_Get( &ts );
+
+ ts.tv_sec += delta->tv_sec;
+ ts.tv_nsec += delta->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
+
+ /* if adjustment is too much positive */
+ while ( ts.tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
+ ts.tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
+ ts.tv_sec++;
+ }
+
+ /* if adjustment is too much negative */
+ while ( ts.tv_nsec <= (-1 * TOD_NANOSECONDS_PER_SECOND) ) {
+ ts.tv_nsec += TOD_NANOSECONDS_PER_SECOND;
+ ts.tv_sec--;
+ }
+
+ _TOD_Set( &ts );
+
+ _Thread_Enable_dispatch();
+
+ /* set the user's output */
+ if ( olddelta )
+ *olddelta = *delta;
+
+ return 0;
+}
diff --git a/cpukit/posix/src/aio_cancel.c b/cpukit/posix/src/aio_cancel.c
new file mode 100644
index 0000000000..56b7b01079
--- /dev/null
+++ b/cpukit/posix/src/aio_cancel.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <rtems/posix/aio_misc.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+/*
+ * aio_cancel
+ *
+ * Cancel an asynchronous I/O request
+ *
+ * Input parameters:
+ * fildes - file descriptor
+ * aiocbp - asynchronous I/O control block
+ *
+ * Output parameters:
+ * AIO_CANCELED - if the requested operation(s)
+ * were canceled
+ * AIO_NOTCANCELED - if at least one of the requested
+ * operation(s) cannot be canceled
+ */
+
+
+int aio_cancel(int fildes, struct aiocb *aiocbp)
+{
+ rtems_aio_request_chain *r_chain;
+ int result;
+
+ pthread_mutex_lock (&aio_request_queue.mutex);
+
+ if (fcntl (fildes, F_GETFD) < 0) {
+ pthread_mutex_unlock(&aio_request_queue.mutex);
+ rtems_set_errno_and_return_minus_one (EBADF);
+ }
+
+ /* if aiocbp is NULL remove all request for given file descriptor */
+ if (aiocbp == NULL) {
+ AIO_printf ("Cancel all requests\n");
+
+ r_chain = rtems_aio_search_fd (&aio_request_queue.work_req, fildes, 0);
+ if (r_chain == NULL) {
+ AIO_printf ("Request chain not on [WQ]\n");
+
+ if (!rtems_chain_is_empty (&aio_request_queue.idle_req)) {
+ r_chain = rtems_aio_search_fd (&aio_request_queue.idle_req, fildes, 0);
+ if (r_chain == NULL) {
+ pthread_mutex_unlock(&aio_request_queue.mutex);
+ return AIO_ALLDONE;
+ }
+
+ AIO_printf ("Request chain on [IQ]\n");
+
+ rtems_chain_extract (&r_chain->next_fd);
+ rtems_aio_remove_fd (r_chain);
+ pthread_mutex_destroy (&r_chain->mutex);
+ pthread_cond_destroy (&r_chain->mutex);
+ free (r_chain);
+
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return AIO_CANCELED;
+ }
+
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return AIO_ALLDONE;
+ }
+
+ AIO_printf ("Request chain on [WQ]\n");
+
+ pthread_mutex_lock (&r_chain->mutex);
+ rtems_chain_extract (&r_chain->next_fd);
+ rtems_aio_remove_fd (r_chain);
+ pthread_mutex_unlock (&r_chain->mutex);
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return AIO_CANCELED;
+ } else {
+ AIO_printf ("Cancel request\n");
+
+ if (aiocbp->aio_fildes != fildes) {
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ rtems_set_errno_and_return_minus_one (EINVAL);
+ }
+
+ r_chain = rtems_aio_search_fd (&aio_request_queue.work_req, fildes, 0);
+ if (r_chain == NULL) {
+ if (!rtems_chain_is_empty (&aio_request_queue.idle_req)) {
+ r_chain = rtems_aio_search_fd (&aio_request_queue.idle_req, fildes, 0);
+ if (r_chain == NULL) {
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ rtems_set_errno_and_return_minus_one (EINVAL);
+ }
+
+ AIO_printf ("Request on [IQ]\n");
+
+ result = rtems_aio_remove_req (&r_chain->perfd, aiocbp);
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return result;
+ } else {
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return AIO_ALLDONE;
+ }
+ }
+ AIO_printf ("Request on [WQ]\n");
+
+ pthread_mutex_lock (&r_chain->mutex);
+ result = rtems_aio_remove_req (&r_chain->perfd, aiocbp);
+ pthread_mutex_unlock (&r_chain->mutex);
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return result;
+ }
+ return AIO_ALLDONE;
+}
diff --git a/cpukit/posix/src/aio_error.c b/cpukit/posix/src/aio_error.c
new file mode 100644
index 0000000000..1c0e582bc9
--- /dev/null
+++ b/cpukit/posix/src/aio_error.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+/*
+ * aio_error
+ *
+ * Retrieve errors status for an asynchronous I/O operation
+ *
+ * Input parameters:
+ * aiocbp - asynchronous I/O control block
+ *
+ * Output parameters:
+ * aiocbp->error_code
+ */
+
+
+int
+aio_error (const struct aiocb *aiocbp)
+{
+ return aiocbp->error_code;
+}
diff --git a/cpukit/posix/src/aio_fsync.c b/cpukit/posix/src/aio_fsync.c
new file mode 100644
index 0000000000..4a28b194b5
--- /dev/null
+++ b/cpukit/posix/src/aio_fsync.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <rtems/posix/aio_misc.h>
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+/*
+ * aio_fsync
+ *
+ * Asynchronous file synchronization
+ *
+ * Input parameters:
+ * op - O_SYNC
+ * aiocbp - asynchronous I/O control block
+ *
+ * Output parameters:
+ * -1 - request could not pe enqueued
+ * - FD not opened for write
+ * - not enough memory
+ * - op is not O_SYNC
+ * 0 - otherwise
+ */
+
+int aio_fsync(
+ int op,
+ struct aiocb *aiocbp
+)
+{
+ rtems_aio_request *req;
+ int mode;
+
+ if (op != O_SYNC)
+ rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
+
+ mode = fcntl (aiocbp->aio_fildes, F_GETFL);
+ if (!(((mode & O_ACCMODE) == O_WRONLY) || ((mode & O_ACCMODE) == O_RDWR)))
+ rtems_aio_set_errno_return_minus_one (EBADF, aiocbp);
+
+ req = malloc (sizeof (rtems_aio_request));
+ if (req == NULL)
+ rtems_aio_set_errno_return_minus_one (EAGAIN, aiocbp);
+
+ req->aiocbp = aiocbp;
+ req->aiocbp->aio_lio_opcode = LIO_SYNC;
+
+ return rtems_aio_enqueue (req);
+
+}
diff --git a/cpukit/posix/src/aio_misc.c b/cpukit/posix/src/aio_misc.c
new file mode 100644
index 0000000000..fa731b8d90
--- /dev/null
+++ b/cpukit/posix/src/aio_misc.c
@@ -0,0 +1,556 @@
+/*
+ * Copyright 2010-2011, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <rtems/posix/aio_misc.h>
+#include <errno.h>
+
+static void *rtems_aio_handle (void *arg);
+
+rtems_aio_queue aio_request_queue;
+
+/*
+ * rtems_aio_init
+ *
+ * Initialize the request queue for aio
+ *
+ * Input parameters:
+ * NONE
+ *
+ * Output parameters:
+ * 0 - if initialization succeeded
+ */
+
+int
+rtems_aio_init (void)
+{
+ int result = 0;
+
+ result = pthread_attr_init (&aio_request_queue.attr);
+ if (result != 0)
+ return result;
+
+ result =
+ pthread_attr_setdetachstate (&aio_request_queue.attr,
+ PTHREAD_CREATE_DETACHED);
+ if (result != 0)
+ pthread_attr_destroy (&aio_request_queue.attr);
+
+
+ result = pthread_mutex_init (&aio_request_queue.mutex, NULL);
+ if (result != 0)
+ pthread_attr_destroy (&aio_request_queue.attr);
+
+
+ result = pthread_cond_init (&aio_request_queue.new_req, NULL);
+ if (result != 0) {
+ pthread_mutex_destroy (&aio_request_queue.mutex);
+ pthread_attr_destroy (&aio_request_queue.attr);
+ }
+
+ rtems_chain_initialize_empty (&aio_request_queue.work_req);
+ rtems_chain_initialize_empty (&aio_request_queue.idle_req);
+
+ aio_request_queue.active_threads = 0;
+ aio_request_queue.idle_threads = 0;
+ aio_request_queue.initialized = AIO_QUEUE_INITIALIZED;
+
+ return result;
+}
+
+/*
+ * rtems_aio_search_fd
+ *
+ * Search and create chain of requests for given FD
+ *
+ * Input parameters:
+ * chain - chain of FD chains
+ * fildes - file descriptor to search
+ * create - if 1 search and create
+ * - if 0 just search
+ *
+ * Output parameters:
+ * r_chain - NULL if create == 0 and there is
+ * no chain for given fildes
+ * - pointer to chain is there exists
+ * a chain for given fildes
+ * - pointer to newly create chain if
+ * create == 1
+ *
+ */
+
+rtems_aio_request_chain *
+rtems_aio_search_fd (rtems_chain_control *chain, int fildes, int create)
+{
+ rtems_aio_request_chain *r_chain;
+ rtems_chain_node *node;
+
+ node = rtems_chain_first (chain);
+ r_chain = (rtems_aio_request_chain *) node;
+
+ while (r_chain->fildes < fildes && !rtems_chain_is_tail (chain, node)) {
+ node = rtems_chain_next (node);
+ r_chain = (rtems_aio_request_chain *) node;
+ }
+
+ if (r_chain->fildes == fildes)
+ r_chain->new_fd = 0;
+ else {
+ if (create == 0)
+ r_chain = NULL;
+ else {
+ r_chain = malloc (sizeof (rtems_aio_request_chain));
+ rtems_chain_initialize_empty (&r_chain->perfd);
+
+ if (rtems_chain_is_empty (chain))
+ rtems_chain_prepend (chain, &r_chain->next_fd);
+ else
+ rtems_chain_insert (rtems_chain_previous (node), &r_chain->next_fd);
+
+ r_chain->new_fd = 1;
+ r_chain->fildes = fildes;
+ }
+ }
+ return r_chain;
+}
+
+/*
+ * rtems_aio_move_to_work
+ *
+ * Move chain of requests from IQ to WQ
+ *
+ * Input parameters:
+ * r_chain - chain of requests
+ *
+ * Output paramteres:
+ * NONE
+ */
+
+void
+rtems_aio_move_to_work (rtems_aio_request_chain *r_chain)
+{
+ rtems_aio_request_chain *temp;
+ rtems_chain_node *node;
+
+ node = rtems_chain_first (&aio_request_queue.work_req);
+ temp = (rtems_aio_request_chain *) node;
+
+ while (temp->fildes < r_chain->fildes &&
+ !rtems_chain_is_tail (&aio_request_queue.work_req, node)) {
+ node = rtems_chain_next (node);
+ temp = (rtems_aio_request_chain *) node;
+ }
+
+ rtems_chain_insert (rtems_chain_previous (node), &r_chain->next_fd);
+}
+
+
+/*
+ * rtems_aio_insert_prio
+ *
+ * Add request to given FD chain. The chain is ordered
+ * by priority
+ *
+ * Input parameters:
+ * chain - chain of requests for a given FD
+ * req - request (see aio_misc.h)
+ *
+ * Output parameters:
+ * NONE
+ */
+
+void
+rtems_aio_insert_prio (rtems_chain_control *chain, rtems_aio_request *req)
+{
+ rtems_chain_node *node;
+
+ AIO_printf ("FD exists \n");
+ node = rtems_chain_first (chain);
+
+ if (rtems_chain_is_empty (chain)) {
+ AIO_printf ("First in chain \n");
+ rtems_chain_prepend (chain, &req->next_prio);
+ } else {
+ AIO_printf ("Add by priority \n");
+ int prio = ((rtems_aio_request *) node)->aiocbp->aio_reqprio;
+
+ while (req->aiocbp->aio_reqprio > prio &&
+ !rtems_chain_is_tail (chain, node)) {
+ node = rtems_chain_next (node);
+ prio = ((rtems_aio_request *) node)->aiocbp->aio_reqprio;
+ }
+
+ rtems_chain_insert (node->previous, &req->next_prio);
+
+ }
+}
+
+/*
+ * rtems_aio_remove_fd
+ *
+ * Removes all the requests in a fd chain
+ *
+ * Input parameters:
+ * r_chain - pointer to the fd chain request
+ *
+ * Output parameters:
+ * NONE
+ */
+
+void rtems_aio_remove_fd (rtems_aio_request_chain *r_chain)
+{
+ rtems_chain_control *chain;
+ rtems_chain_node *node;
+ chain = &r_chain->perfd;
+ node = rtems_chain_first (chain);
+
+ while (!rtems_chain_is_tail (chain, node))
+ {
+ rtems_chain_extract (node);
+ rtems_aio_request *req = (rtems_aio_request *) node;
+ node = rtems_chain_next (node);
+ req->aiocbp->error_code = ECANCELED;
+ req->aiocbp->return_value = -1;
+ free (req);
+ }
+}
+
+/*
+ * rtems_aio_remove_req
+ *
+ * Removes request from given chain
+ *
+ * Input parameters:
+ * chain - pointer to fd chain which may contain
+ * the request
+ * aiocbp - pointer to request that needs to be
+ * canceled
+ *
+ * Output parameters:
+ * AIO_NOTCANCELED - if request was not canceled
+ * AIO_CANCELED - if request was canceled
+ */
+
+int rtems_aio_remove_req (rtems_chain_control *chain, struct aiocb *aiocbp)
+{
+ if (rtems_chain_is_empty (chain))
+ return AIO_ALLDONE;
+
+ rtems_chain_node *node = rtems_chain_first (chain);
+ rtems_aio_request *current;
+
+ current = (rtems_aio_request *) node;
+
+ while (!rtems_chain_is_tail (chain, node) && current->aiocbp != aiocbp) {
+ node = rtems_chain_next (node);
+ current = (rtems_aio_request *) node;
+ }
+
+ if (rtems_chain_is_tail (chain, node))
+ return AIO_NOTCANCELED;
+ else
+ {
+ rtems_chain_extract (node);
+ current->aiocbp->error_code = ECANCELED;
+ current->aiocbp->return_value = -1;
+ free (current);
+ }
+
+ return AIO_CANCELED;
+}
+
+/*
+ * rtems_aio_enqueue
+ *
+ * Enqueue requests, and creates threads to process them
+ *
+ * Input parameters:
+ * req - see aio_misc.h
+ *
+ * Output parameters:
+ * 0 - if request was added to queue
+ * errno - otherwise
+ */
+
+int
+rtems_aio_enqueue (rtems_aio_request *req)
+{
+
+ rtems_aio_request_chain *r_chain;
+ rtems_chain_control *chain;
+ pthread_t thid;
+ int result, policy;
+ struct sched_param param;
+
+ /* The queue should be initialized */
+ AIO_assert (aio_request_queue.initialized == AIO_QUEUE_INITIALIZED);
+
+ result = pthread_mutex_lock (&aio_request_queue.mutex);
+ if (result != 0) {
+ free (req);
+ return result;
+ }
+
+ /* _POSIX_PRIORITIZED_IO and _POSIX_PRIORITY_SCHEDULING are defined,
+ we can use aio_reqprio to lower the priority of the request */
+ pthread_getschedparam (pthread_self(), &policy, &param);
+
+ req->caller_thread = pthread_self ();
+ req->priority = param.sched_priority - req->aiocbp->aio_reqprio;
+ req->policy = policy;
+ req->aiocbp->error_code = EINPROGRESS;
+ req->aiocbp->return_value = 0;
+
+ if ((aio_request_queue.idle_threads == 0) &&
+ aio_request_queue.active_threads < AIO_MAX_THREADS)
+ /* we still have empty places on the active_threads chain */
+ {
+ chain = &aio_request_queue.work_req;
+ r_chain = rtems_aio_search_fd (chain, req->aiocbp->aio_fildes, 1);
+
+ if (r_chain->new_fd == 1) {
+ rtems_chain_prepend (&r_chain->perfd, &req->next_prio);
+ r_chain->new_fd = 0;
+ pthread_mutex_init (&r_chain->mutex, NULL);
+ pthread_cond_init (&r_chain->cond, NULL);
+
+ AIO_printf ("New thread \n");
+ result = pthread_create (&thid, &aio_request_queue.attr,
+ rtems_aio_handle, (void *) r_chain);
+ if (result != 0) {
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return result;
+ }
+ ++aio_request_queue.active_threads;
+ }
+ else {
+ /* put request in the fd chain it belongs to */
+ pthread_mutex_lock (&r_chain->mutex);
+ rtems_aio_insert_prio (&r_chain->perfd, req);
+ pthread_cond_signal (&r_chain->cond);
+ pthread_mutex_unlock (&r_chain->mutex);
+ }
+ }
+ else
+ {
+ /* the maximum number of threads has been already created
+ even though some of them might be idle.
+ The request belongs to one of the active fd chain */
+ r_chain = rtems_aio_search_fd (&aio_request_queue.work_req,
+ req->aiocbp->aio_fildes, 0);
+ if (r_chain != NULL)
+ {
+ pthread_mutex_lock (&r_chain->mutex);
+ rtems_aio_insert_prio (&r_chain->perfd, req);
+ pthread_cond_signal (&r_chain->cond);
+ pthread_mutex_unlock (&r_chain->mutex);
+
+ } else {
+
+ /* or to the idle chain */
+ chain = &aio_request_queue.idle_req;
+ r_chain = rtems_aio_search_fd (chain, req->aiocbp->aio_fildes, 1);
+
+ if (r_chain->new_fd == 1) {
+ /* If this is a new fd chain we signal the idle threads that
+ might be waiting for requests */
+ AIO_printf (" New chain on waiting queue \n ");
+ rtems_chain_prepend (&r_chain->perfd, &req->next_prio);
+ r_chain->new_fd = 0;
+ pthread_mutex_init (&r_chain->mutex, NULL);
+ pthread_cond_init (&r_chain->cond, NULL);
+ } else
+ /* just insert the request in the existing fd chain */
+ rtems_aio_insert_prio (&r_chain->perfd, req);
+ if (aio_request_queue.idle_threads > 0)
+ pthread_cond_signal (&aio_request_queue.new_req);
+ }
+ }
+
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return 0;
+}
+
+/*
+ * rtems_aio_handle
+ *
+ * Thread processing requests
+ *
+ * Input parameters:
+ * arg - the chain for the fd to be worked on
+ *
+ * Output parameters:
+ * NULL - if error
+ */
+
+static void *
+rtems_aio_handle (void *arg)
+{
+
+ rtems_aio_request_chain *r_chain = arg;
+ rtems_aio_request *req;
+ rtems_chain_control *chain;
+ rtems_chain_node *node;
+ int result, policy;
+ struct sched_param param;
+
+ AIO_printf ("Thread started\n");
+
+ while (1) {
+
+ /* acquire the mutex of the current fd chain.
+ we don't need to lock the queue mutex since we can
+ add requests to idle fd chains or even active ones
+ if the working request has been extracted from the
+ chain */
+ result = pthread_mutex_lock (&r_chain->mutex);
+ if (result != 0)
+ return NULL;
+
+ chain = &r_chain->perfd;
+
+ /* If the locked chain is not empty, take the first
+ request extract it, unlock the chain and process
+ the request, in this way the user can supply more
+ requests to this fd chain */
+ if (!rtems_chain_is_empty (chain)) {
+
+ AIO_printf ("Get new request from not empty chain\n");
+ node = rtems_chain_first (chain);
+ req = (rtems_aio_request *) node;
+
+ /* See _POSIX_PRIORITIZE_IO and _POSIX_PRIORITY_SCHEDULING
+ discussion in rtems_aio_enqueue () */
+ pthread_getschedparam (pthread_self(), &policy, &param);
+ param.sched_priority = req->priority;
+ pthread_setschedparam (pthread_self(), req->policy, &param);
+
+ rtems_chain_extract (node);
+
+ pthread_mutex_unlock (&r_chain->mutex);
+
+ switch (req->aiocbp->aio_lio_opcode) {
+ case LIO_READ:
+ AIO_printf ("read\n");
+ result = pread (req->aiocbp->aio_fildes,
+ (void *) req->aiocbp->aio_buf,
+ req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
+ break;
+
+ case LIO_WRITE:
+ AIO_printf ("write\n");
+ result = pwrite (req->aiocbp->aio_fildes,
+ (void *) req->aiocbp->aio_buf,
+ req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
+ break;
+
+ case LIO_SYNC:
+ AIO_printf ("sync\n");
+ result = fsync (req->aiocbp->aio_fildes);
+ break;
+
+ default:
+ result = -1;
+ }
+ if (result == -1) {
+ req->aiocbp->return_value = -1;
+ req->aiocbp->error_code = errno;
+ } else {
+ req->aiocbp->return_value = result;
+ req->aiocbp->error_code = 0;
+ }
+
+ // notification needed for lio
+
+ } else {
+ /* If the fd chain is empty we unlock the fd chain
+ and we lock the queue chain, this will ensure that
+ we have at most one request comming to our fd chain
+ when we check.
+
+ If there was no request added sleep for 3 seconds and
+ wait for a signal on chain, this will unlock the queue.
+ The fd chain is already unlocked */
+
+ struct timespec timeout;
+
+ AIO_printf ("Chain is empty [WQ], wait for work\n");
+
+ pthread_mutex_unlock (&r_chain->mutex);
+ pthread_mutex_lock (&aio_request_queue.mutex);
+
+ if (rtems_chain_is_empty (chain))
+ {
+ clock_gettime (CLOCK_REALTIME, &timeout);
+ timeout.tv_sec += 3;
+ timeout.tv_nsec = 0;
+ result = pthread_cond_timedwait (&r_chain->cond,
+ &aio_request_queue.mutex,
+ &timeout);
+
+ /* If no requests were added to the chain we delete the fd chain from
+ the queue and start working with idle fd chains */
+ if (result == ETIMEDOUT) {
+ rtems_chain_extract (&r_chain->next_fd);
+ pthread_mutex_destroy (&r_chain->mutex);
+ pthread_cond_destroy (&r_chain->cond);
+ free (r_chain);
+
+ /* If the idle chain is empty sleep for 3 seconds and wait for a
+ signal. The thread now becomes idle. */
+ if (rtems_chain_is_empty (&aio_request_queue.idle_req)) {
+ AIO_printf ("Chain is empty [IQ], wait for work\n");
+
+ ++aio_request_queue.idle_threads;
+ --aio_request_queue.active_threads;
+ clock_gettime (CLOCK_REALTIME, &timeout);
+ timeout.tv_sec += 3;
+ timeout.tv_nsec = 0;
+
+ result = pthread_cond_timedwait (&aio_request_queue.new_req,
+ &aio_request_queue.mutex,
+ &timeout);
+
+ /* If no new fd chain was added in the idle requests
+ then this thread is finished */
+ if (result == ETIMEDOUT) {
+ AIO_printf ("Etimeout\n");
+ --aio_request_queue.idle_threads;
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+ return NULL;
+ }
+ }
+ /* Otherwise move this chain to the working chain and
+ start the loop all over again */
+ AIO_printf ("Work on idle\n");
+ --aio_request_queue.idle_threads;
+ ++aio_request_queue.active_threads;
+
+ node = rtems_chain_first (&aio_request_queue.idle_req);
+ rtems_chain_extract (node);
+
+ r_chain = (rtems_aio_request_chain *) node;
+ rtems_aio_move_to_work (r_chain);
+
+ }
+ }
+ /* If there was a request added in the initial fd chain then release
+ the mutex and process it */
+ pthread_mutex_unlock (&aio_request_queue.mutex);
+
+ }
+ }
+
+ AIO_printf ("Thread finished\n");
+ return NULL;
+}
diff --git a/cpukit/posix/src/aio_read.c b/cpukit/posix/src/aio_read.c
new file mode 100644
index 0000000000..43536fff74
--- /dev/null
+++ b/cpukit/posix/src/aio_read.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <rtems/posix/aio_misc.h>
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <stdlib.h>
+
+/*
+ * aio_read
+ *
+ * Asynchronous write to a file
+ *
+ * Input parameters:
+ * aiocbp - asynchronous I/O control block
+ *
+ * Output parameters:
+ * -1 - request could not pe enqueued
+ * - FD not opened for write
+ * - invalid aio_reqprio or aio_offset or
+ * aio_nbytes
+ * - not enough memory
+ * 0 - otherwise
+ */
+
+int
+aio_read (struct aiocb *aiocbp)
+{
+ rtems_aio_request *req;
+ int mode;
+
+ mode = fcntl (aiocbp->aio_fildes, F_GETFL);
+ if (!(((mode & O_ACCMODE) == O_RDONLY) || ((mode & O_ACCMODE) == O_RDWR)))
+ rtems_aio_set_errno_return_minus_one (EBADF, aiocbp);
+
+ if (aiocbp->aio_reqprio < 0 || aiocbp->aio_reqprio > AIO_PRIO_DELTA_MAX)
+ rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
+
+ if (aiocbp->aio_offset < 0)
+ rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
+
+ req = malloc (sizeof (rtems_aio_request));
+ if (req == NULL)
+ rtems_aio_set_errno_return_minus_one (EAGAIN, aiocbp);
+
+ req->aiocbp = aiocbp;
+ req->aiocbp->aio_lio_opcode = LIO_READ;
+
+ return rtems_aio_enqueue (req);
+}
diff --git a/cpukit/posix/src/aio_return.c b/cpukit/posix/src/aio_return.c
new file mode 100644
index 0000000000..2a9e56ae7a
--- /dev/null
+++ b/cpukit/posix/src/aio_return.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+/*
+ * aio_return
+ *
+ * Retrieve return status of an asynchronous I/O operation
+ *
+ * Input parameters:
+ * aiocbp - asynchronous I/O control block
+ *
+ * Output parameters:
+ * aiocbp->return_value
+ */
+
+ssize_t
+aio_return (const struct aiocb *aiocbp)
+{
+ return aiocbp->return_value;
+}
diff --git a/cpukit/posix/src/aio_suspend.c b/cpukit/posix/src/aio_suspend.c
new file mode 100644
index 0000000000..28ed3565e5
--- /dev/null
+++ b/cpukit/posix/src/aio_suspend.c
@@ -0,0 +1,31 @@
+/*
+ * 6.7.7 Wait for Asynchronous I/O Request, P1003.1b-1993, p. 164
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+int aio_suspend(
+ const struct aiocb * const list[] __attribute__((unused)),
+ int nent __attribute__((unused)),
+ const struct timespec *timeout __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/aio_write.c b/cpukit/posix/src/aio_write.c
new file mode 100644
index 0000000000..03f6b90c64
--- /dev/null
+++ b/cpukit/posix/src/aio_write.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <rtems/posix/aio_misc.h>
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <stdlib.h>
+
+/*
+ * aio_write
+ *
+ * Asynchronous write to a file
+ *
+ * Input parameters:
+ * aiocbp - asynchronous I/O control block
+ *
+ * Output parameters:
+ * -1 - request could not be enqueued
+ * - FD not opened for write
+ * - invalid aio_reqprio or aio_offset or
+ * aio_nbytes
+ * - not enough memory
+ * 0 - otherwise
+ */
+
+int
+aio_write (struct aiocb *aiocbp)
+{
+ rtems_aio_request *req;
+ int mode;
+
+ mode = fcntl (aiocbp->aio_fildes, F_GETFL);
+ if (!(((mode & O_ACCMODE) == O_WRONLY) || ((mode & O_ACCMODE) == O_RDWR)))
+ rtems_aio_set_errno_return_minus_one (EBADF, aiocbp);
+
+ if (aiocbp->aio_reqprio < 0 || aiocbp->aio_reqprio > AIO_PRIO_DELTA_MAX)
+ rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
+
+ if (aiocbp->aio_offset < 0)
+ rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
+
+ req = malloc (sizeof (rtems_aio_request));
+ if (req == NULL)
+ rtems_aio_set_errno_return_minus_one (EAGAIN, aiocbp);
+
+ req->aiocbp = aiocbp;
+ req->aiocbp->aio_lio_opcode = LIO_WRITE;
+
+ return rtems_aio_enqueue (req);
+}
diff --git a/cpukit/posix/src/alarm.c b/cpukit/posix/src/alarm.c
new file mode 100644
index 0000000000..ec381878a5
--- /dev/null
+++ b/cpukit/posix/src/alarm.c
@@ -0,0 +1,76 @@
+/*
+ * 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
+ */
+
+/* COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+/*PAGE
+ *
+ * _POSIX_signals_Alarm_TSR
+ */
+
+void _POSIX_signals_Alarm_TSR(
+ Objects_Id id __attribute__((unused)),
+ void *argument __attribute__((unused))
+)
+{
+ int status;
+
+ status = kill( getpid(), SIGALRM );
+ /* XXX can't print from an ISR, should this be fatal? */
+}
+
+unsigned int alarm(
+ unsigned int seconds
+)
+{
+ unsigned int remaining = 0;
+ Watchdog_Control *the_timer;
+
+ the_timer = &_POSIX_signals_Alarm_timer;
+
+ /*
+ * Initialize the timer used to implement alarm().
+ */
+
+ if ( !the_timer->routine ) {
+ _Watchdog_Initialize( the_timer, _POSIX_signals_Alarm_TSR, 0, NULL );
+ } else {
+ Watchdog_States state;
+
+ state = _Watchdog_Remove( the_timer );
+ if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) {
+ /*
+ * The stop_time and start_time fields are snapshots of ticks since
+ * boot. Since alarm() is dealing in seconds, we must account for
+ * this.
+ */
+
+ remaining = the_timer->initial -
+ ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND);
+ }
+ }
+
+ if ( seconds )
+ _Watchdog_Insert_seconds( the_timer, seconds );
+
+ return remaining;
+}
diff --git a/cpukit/posix/src/barrierattrdestroy.c b/cpukit/posix/src/barrierattrdestroy.c
new file mode 100644
index 0000000000..8821866af9
--- /dev/null
+++ b/cpukit/posix/src/barrierattrdestroy.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * Barrier Initialization Attributes
+ */
+
+int pthread_barrierattr_destroy(
+ pthread_barrierattr_t *attr
+)
+{
+ if ( !attr || attr->is_initialized == false )
+ return EINVAL;
+
+ attr->is_initialized = false;
+ return 0;
+}
diff --git a/cpukit/posix/src/barrierattrgetpshared.c b/cpukit/posix/src/barrierattrgetpshared.c
new file mode 100644
index 0000000000..0d8d7f1d33
--- /dev/null
+++ b/cpukit/posix/src/barrierattrgetpshared.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * Barrier Attributes Get Process Shared
+ */
+
+int pthread_barrierattr_getpshared(
+ const pthread_barrierattr_t *attr,
+ int *pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ *pshared = attr->process_shared;
+ return 0;
+}
diff --git a/cpukit/posix/src/barrierattrinit.c b/cpukit/posix/src/barrierattrinit.c
new file mode 100644
index 0000000000..b1a6e980c9
--- /dev/null
+++ b/cpukit/posix/src/barrierattrinit.c
@@ -0,0 +1,36 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+
+/*PAGE
+ *
+ * Barrier Attributes Initialization
+ */
+
+int pthread_barrierattr_init(
+ pthread_barrierattr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ attr->is_initialized = true;
+ attr->process_shared = PTHREAD_PROCESS_PRIVATE;
+ return 0;
+}
diff --git a/cpukit/posix/src/barrierattrsetpshared.c b/cpukit/posix/src/barrierattrsetpshared.c
new file mode 100644
index 0000000000..a899bb91c2
--- /dev/null
+++ b/cpukit/posix/src/barrierattrsetpshared.c
@@ -0,0 +1,44 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * Barrier Attributes Set Process Shared
+ */
+
+int pthread_barrierattr_setpshared(
+ pthread_barrierattr_t *attr,
+ int pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_SHARED:
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->process_shared = pshared;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c
new file mode 100644
index 0000000000..0167c0a328
--- /dev/null
+++ b/cpukit/posix/src/cancel.c
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+/*
+ * 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181
+ */
+
+int pthread_cancel(
+ pthread_t thread
+)
+{
+ Thread_Control *the_thread;
+ POSIX_API_Control *thread_support;
+ Objects_Locations location;
+
+ /*
+ * Don't even think about deleting a resource from an ISR.
+ */
+
+ if ( _ISR_Is_in_progress() )
+ return EPROTO;
+
+ the_thread = _Thread_Get( thread, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ thread_support->cancelation_requested = 1;
+
+ /* This enables dispatch implicitly */
+ _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( the_thread );
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/canceleval.c b/cpukit/posix/src/canceleval.c
new file mode 100644
index 0000000000..f2e6d9c4c8
--- /dev/null
+++ b/cpukit/posix/src/canceleval.c
@@ -0,0 +1,38 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+
+void _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch(
+ Thread_Control *the_thread
+)
+{
+ POSIX_API_Control *thread_support;
+
+ thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
+ thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
+ thread_support->cancelation_requested ) {
+ _Thread_Unnest_dispatch();
+ _POSIX_Thread_Exit( the_thread, PTHREAD_CANCELED );
+ } else
+ _Thread_Enable_dispatch();
+
+}
diff --git a/cpukit/posix/src/cancelrun.c b/cpukit/posix/src/cancelrun.c
new file mode 100644
index 0000000000..8ac96a762d
--- /dev/null
+++ b/cpukit/posix/src/cancelrun.c
@@ -0,0 +1,54 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+void _POSIX_Threads_cancel_run(
+ Thread_Control *the_thread
+)
+{
+ POSIX_Cancel_Handler_control *handler;
+ Chain_Control *handler_stack;
+ POSIX_API_Control *thread_support;
+ ISR_Level level;
+
+ thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ handler_stack = &thread_support->Cancellation_Handlers;
+
+ thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
+
+ while ( !_Chain_Is_empty( handler_stack ) ) {
+ _ISR_Disable( level );
+ handler = (POSIX_Cancel_Handler_control *)
+ _Chain_Tail( handler_stack )->previous;
+ _Chain_Extract_unprotected( &handler->Node );
+ _ISR_Enable( level );
+
+ (*handler->routine)( handler->arg );
+
+ _Workspace_Free( handler );
+ }
+}
diff --git a/cpukit/posix/src/cleanuppop.c b/cpukit/posix/src/cleanuppop.c
new file mode 100644
index 0000000000..cc327fa33d
--- /dev/null
+++ b/cpukit/posix/src/cleanuppop.c
@@ -0,0 +1,77 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+/*PAGE
+ *
+ * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
+ */
+
+void pthread_cleanup_pop(
+ int execute
+)
+{
+ POSIX_Cancel_Handler_control *handler;
+ POSIX_Cancel_Handler_control tmp_handler;
+ Chain_Control *handler_stack;
+ POSIX_API_Control *thread_support;
+ ISR_Level level;
+
+ thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ handler_stack = &thread_support->Cancellation_Handlers;
+
+ /*
+ * We need interrupts disabled to safely check the chain and pull
+ * the last element off. But we also need dispatching disabled to
+ * ensure that we do not get prempted and deleted while we are holding
+ * memory that needs to be freed.
+ */
+
+ _Thread_Disable_dispatch();
+ _ISR_Disable( level );
+
+ if ( _Chain_Is_empty( handler_stack ) ) {
+ _Thread_Enable_dispatch();
+ _ISR_Enable( level );
+ return;
+ }
+
+ handler = (POSIX_Cancel_Handler_control *)
+ _Chain_Tail( handler_stack )->previous;
+ _Chain_Extract_unprotected( &handler->Node );
+
+ _ISR_Enable( level );
+
+ tmp_handler = *handler;
+
+ _Workspace_Free( handler );
+
+ _Thread_Enable_dispatch();
+
+ if ( execute )
+ (*tmp_handler.routine)( tmp_handler.arg );
+}
diff --git a/cpukit/posix/src/cleanuppush.c b/cpukit/posix/src/cleanuppush.c
new file mode 100644
index 0000000000..71079200ef
--- /dev/null
+++ b/cpukit/posix/src/cleanuppush.c
@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+/*PAGE
+ *
+ * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
+ */
+
+void pthread_cleanup_push(
+ void (*routine)( void * ),
+ void *arg
+)
+{
+ POSIX_Cancel_Handler_control *handler;
+ Chain_Control *handler_stack;
+ POSIX_API_Control *thread_support;
+
+ /*
+ * The POSIX standard does not address what to do when the routine
+ * is NULL. It also does not address what happens when we cannot
+ * allocate memory or anything else bad happens.
+ */
+ if ( !routine )
+ return;
+
+ _Thread_Disable_dispatch();
+ handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
+
+ if ( handler ) {
+ thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ handler_stack = &thread_support->Cancellation_Handlers;
+
+ handler->routine = routine;
+ handler->arg = arg;
+
+ _Chain_Append( handler_stack, &handler->Node );
+ }
+ _Thread_Enable_dispatch();
+}
diff --git a/cpukit/posix/src/clockgetcpuclockid.c b/cpukit/posix/src/clockgetcpuclockid.c
new file mode 100644
index 0000000000..b4472f8a10
--- /dev/null
+++ b/cpukit/posix/src/clockgetcpuclockid.c
@@ -0,0 +1,38 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 20.1.3 Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55
+ */
+
+int clock_getcpuclockid(
+ pid_t pid,
+ clockid_t *clock_id
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/clockgetenableattr.c b/cpukit/posix/src/clockgetenableattr.c
new file mode 100644
index 0000000000..95efe0de3b
--- /dev/null
+++ b/cpukit/posix/src/clockgetenableattr.c
@@ -0,0 +1,38 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58
+ */
+
+int clock_getenable_attr(
+ clockid_t clock_id,
+ int *attr
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/clockgetres.c b/cpukit/posix/src/clockgetres.c
new file mode 100644
index 0000000000..7507bee614
--- /dev/null
+++ b/cpukit/posix/src/clockgetres.c
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 14.2.1 Clocks, P1003.1b-1993, p. 263
+ */
+
+int clock_getres(
+ clockid_t clock_id,
+ struct timespec *res
+)
+{
+ if ( !res )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ switch ( clock_id ) {
+
+ /*
+ * All time in rtems is based on the same clock tick.
+ */
+
+ case CLOCK_REALTIME:
+ case CLOCK_PROCESS_CPUTIME:
+ case CLOCK_THREAD_CPUTIME:
+ if ( res ) {
+ res->tv_sec = rtems_configuration_get_microseconds_per_tick() /
+ TOD_MICROSECONDS_PER_SECOND;
+ res->tv_nsec = rtems_configuration_get_nanoseconds_per_tick();
+ }
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ }
+ return 0;
+}
diff --git a/cpukit/posix/src/clockgettime.c b/cpukit/posix/src/clockgettime.c
new file mode 100644
index 0000000000..852ac8e039
--- /dev/null
+++ b/cpukit/posix/src/clockgettime.c
@@ -0,0 +1,65 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 14.2.1 Clocks, P1003.1b-1993, p. 263
+ */
+
+int clock_gettime(
+ clockid_t clock_id,
+ struct timespec *tp
+)
+{
+ if ( !tp )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( clock_id == CLOCK_REALTIME ) {
+ _TOD_Get(tp);
+ return 0;
+ }
+#ifdef CLOCK_MONOTONIC
+ if ( clock_id == CLOCK_MONOTONIC ) {
+ _TOD_Get_uptime_as_timespec( tp );
+ return 0;
+ }
+#endif
+
+#ifdef _POSIX_CPUTIME
+ if ( clock_id == CLOCK_PROCESS_CPUTIME ) {
+ _TOD_Get_uptime_as_timespec( tp );
+ return 0;
+ }
+#endif
+
+#ifdef _POSIX_THREAD_CPUTIME
+ if ( clock_id == CLOCK_THREAD_CPUTIME )
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+#endif
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ return 0;
+}
diff --git a/cpukit/posix/src/clocksetenableattr.c b/cpukit/posix/src/clocksetenableattr.c
new file mode 100644
index 0000000000..f11f8d14e8
--- /dev/null
+++ b/cpukit/posix/src/clocksetenableattr.c
@@ -0,0 +1,38 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58
+ */
+
+int clock_setenable_attr(
+ clockid_t clock_id,
+ int attr
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/clocksettime.c b/cpukit/posix/src/clocksettime.c
new file mode 100644
index 0000000000..aa3743d9f9
--- /dev/null
+++ b/cpukit/posix/src/clocksettime.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 14.2.1 Clocks, P1003.1b-1993, p. 263
+ */
+
+int clock_settime(
+ clockid_t clock_id,
+ const struct timespec *tp
+)
+{
+ if ( !tp )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( clock_id == CLOCK_REALTIME ) {
+ if ( tp->tv_sec < TOD_SECONDS_1970_THROUGH_1988 )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ _Thread_Disable_dispatch();
+ _TOD_Set( tp );
+ _Thread_Enable_dispatch();
+ }
+#ifdef _POSIX_CPUTIME
+ else if ( clock_id == CLOCK_PROCESS_CPUTIME )
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+#endif
+#ifdef _POSIX_THREAD_CPUTIME
+ else if ( clock_id == CLOCK_THREAD_CPUTIME )
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+#endif
+ else
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ return 0;
+}
diff --git a/cpukit/posix/src/cond.c b/cpukit/posix/src/cond.c
new file mode 100644
index 0000000000..954fb34b78
--- /dev/null
+++ b/cpukit/posix/src/cond.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * _POSIX_Condition_variables_Manager_initialization
+ *
+ * This routine initializes all condition variable manager related data
+ * structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Condition_variables_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Condition_variables_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_CONDITION_VARIABLES, /* object class */
+ Configuration_POSIX_API.maximum_condition_variables,
+ /* maximum objects of this class */
+ sizeof( POSIX_Condition_variables_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/condattrdestroy.c b/cpukit/posix/src/condattrdestroy.c
new file mode 100644
index 0000000000..821f93fba9
--- /dev/null
+++ b/cpukit/posix/src/condattrdestroy.c
@@ -0,0 +1,42 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.1 Condition Variable Initialization Attributes,
+ * P1003.1c/Draft 10, p. 96
+ */
+
+int pthread_condattr_destroy(
+ pthread_condattr_t *attr
+)
+{
+ if ( !attr || attr->is_initialized == false )
+ return EINVAL;
+
+ attr->is_initialized = false;
+ return 0;
+}
diff --git a/cpukit/posix/src/condattrgetpshared.c b/cpukit/posix/src/condattrgetpshared.c
new file mode 100644
index 0000000000..0710fcc120
--- /dev/null
+++ b/cpukit/posix/src/condattrgetpshared.c
@@ -0,0 +1,43 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.1 Condition Variable Initialization Attributes,
+ * P1003.1c/Draft 10, p. 96
+ */
+
+int pthread_condattr_getpshared(
+ const pthread_condattr_t *attr,
+ int *pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ *pshared = attr->process_shared;
+ return 0;
+}
diff --git a/cpukit/posix/src/condattrinit.c b/cpukit/posix/src/condattrinit.c
new file mode 100644
index 0000000000..f06683ad47
--- /dev/null
+++ b/cpukit/posix/src/condattrinit.c
@@ -0,0 +1,42 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.1 Condition Variable Initialization Attributes,
+ * P1003.1c/Draft 10, p. 96
+ */
+
+int pthread_condattr_init(
+ pthread_condattr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ *attr = _POSIX_Condition_variables_Default_attributes;
+ return 0;
+}
diff --git a/cpukit/posix/src/condattrsetpshared.c b/cpukit/posix/src/condattrsetpshared.c
new file mode 100644
index 0000000000..33a4d28a7c
--- /dev/null
+++ b/cpukit/posix/src/condattrsetpshared.c
@@ -0,0 +1,50 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.1 Condition Variable Initialization Attributes,
+ * P1003.1c/Draft 10, p. 96
+ */
+
+int pthread_condattr_setpshared(
+ pthread_condattr_t *attr,
+ int pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_SHARED:
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->process_shared = pshared;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/condbroadcast.c b/cpukit/posix/src/condbroadcast.c
new file mode 100644
index 0000000000..73875f7952
--- /dev/null
+++ b/cpukit/posix/src/condbroadcast.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101
+ */
+
+int pthread_cond_broadcast(
+ pthread_cond_t *cond
+)
+{
+ return _POSIX_Condition_variables_Signal_support( cond, true );
+}
diff --git a/cpukit/posix/src/conddefaultattributes.c b/cpukit/posix/src/conddefaultattributes.c
new file mode 100644
index 0000000000..7d83bf473c
--- /dev/null
+++ b/cpukit/posix/src/conddefaultattributes.c
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * The default condition variable attributes structure.
+ */
+
+const pthread_condattr_t _POSIX_Condition_variables_Default_attributes = {
+ true, /* is_initialized */
+ PTHREAD_PROCESS_PRIVATE /* process_shared */
+};
diff --git a/cpukit/posix/src/conddestroy.c b/cpukit/posix/src/conddestroy.c
new file mode 100644
index 0000000000..d01364f0ef
--- /dev/null
+++ b/cpukit/posix/src/conddestroy.c
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.2 Initializing and Destroying a Condition Variable,
+ * P1003.1c/Draft 10, p. 87
+ */
+
+int pthread_cond_destroy(
+ pthread_cond_t *cond
+)
+{
+ POSIX_Condition_variables_Control *the_cond;
+ Objects_Locations location;
+
+ the_cond = _POSIX_Condition_variables_Get( cond, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ if ( _Thread_queue_First( &the_cond->Wait_queue ) ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ _Objects_Close(
+ &_POSIX_Condition_variables_Information,
+ &the_cond->Object
+ );
+
+ _POSIX_Condition_variables_Free( the_cond );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/condget.c b/cpukit/posix/src/condget.c
new file mode 100644
index 0000000000..0305b45e3b
--- /dev/null
+++ b/cpukit/posix/src/condget.c
@@ -0,0 +1,60 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get (
+ pthread_cond_t *cond,
+ Objects_Locations *location
+)
+{
+ int status;
+
+ if ( !cond ) {
+ *location = OBJECTS_ERROR;
+ return (POSIX_Condition_variables_Control *) 0;
+ }
+
+ if ( *cond == PTHREAD_COND_INITIALIZER ) {
+ /*
+ * Do an "auto-create" here.
+ */
+
+ status = pthread_cond_init( cond, 0 );
+ if ( status ) {
+ *location = OBJECTS_ERROR;
+ return (POSIX_Condition_variables_Control *) 0;
+ }
+ }
+
+ /*
+ * Now call Objects_Get()
+ */
+ return (POSIX_Condition_variables_Control *)_Objects_Get(
+ &_POSIX_Condition_variables_Information,
+ (Objects_Id) *cond,
+ location
+ );
+}
+
diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c
new file mode 100644
index 0000000000..8bdbe2be00
--- /dev/null
+++ b/cpukit/posix/src/condinit.c
@@ -0,0 +1,84 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.2 Initializing and Destroying a Condition Variable,
+ * P1003.1c/Draft 10, p. 87
+ */
+
+int pthread_cond_init(
+ pthread_cond_t *cond,
+ const pthread_condattr_t *attr
+)
+{
+ POSIX_Condition_variables_Control *the_cond;
+ const pthread_condattr_t *the_attr;
+
+ if ( attr ) the_attr = attr;
+ else the_attr = &_POSIX_Condition_variables_Default_attributes;
+
+ /*
+ * Be careful about attributes when global!!!
+ */
+ if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED )
+ return EINVAL;
+
+ if ( !the_attr->is_initialized )
+ return EINVAL;
+
+ _Thread_Disable_dispatch();
+
+ the_cond = _POSIX_Condition_variables_Allocate();
+
+ if ( !the_cond ) {
+ _Thread_Enable_dispatch();
+ return ENOMEM;
+ }
+
+ the_cond->process_shared = the_attr->process_shared;
+
+ the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
+
+ _Thread_queue_Initialize(
+ &the_cond->Wait_queue,
+ THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_CONDITION_VARIABLE | STATES_INTERRUPTIBLE_BY_SIGNAL,
+ ETIMEDOUT
+ );
+
+ _Objects_Open_u32(
+ &_POSIX_Condition_variables_Information,
+ &the_cond->Object,
+ 0
+ );
+
+ *cond = the_cond->Object.id;
+
+ _Thread_Enable_dispatch();
+
+ return 0;
+}
diff --git a/cpukit/posix/src/condsignal.c b/cpukit/posix/src/condsignal.c
new file mode 100644
index 0000000000..fd607fd641
--- /dev/null
+++ b/cpukit/posix/src/condsignal.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101
+ */
+
+int pthread_cond_signal(
+ pthread_cond_t *cond
+)
+{
+ return _POSIX_Condition_variables_Signal_support( cond, false );
+}
diff --git a/cpukit/posix/src/condsignalsupp.c b/cpukit/posix/src/condsignalsupp.c
new file mode 100644
index 0000000000..47e23b5b8e
--- /dev/null
+++ b/cpukit/posix/src/condsignalsupp.c
@@ -0,0 +1,66 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * _POSIX_Condition_variables_Signal_support
+ *
+ * A support routine which implements guts of the broadcast and single task
+ * wake up version of the "signal" operation.
+ */
+
+int _POSIX_Condition_variables_Signal_support(
+ pthread_cond_t *cond,
+ bool is_broadcast
+)
+{
+ register POSIX_Condition_variables_Control *the_cond;
+ Objects_Locations location;
+ Thread_Control *the_thread;
+
+ the_cond = _POSIX_Condition_variables_Get( cond, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ do {
+ the_thread = _Thread_queue_Dequeue( &the_cond->Wait_queue );
+ if ( !the_thread )
+ the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
+ } while ( is_broadcast && the_thread );
+
+ _Thread_Enable_dispatch();
+
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/condtimedwait.c b/cpukit/posix/src/condtimedwait.c
new file mode 100644
index 0000000000..4134a73f8a
--- /dev/null
+++ b/cpukit/posix/src/condtimedwait.c
@@ -0,0 +1,70 @@
+/*
+ * $Id$
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105
+ */
+
+int pthread_cond_timedwait(
+ pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime
+)
+{
+ Watchdog_Interval ticks;
+ bool already_timedout;
+ POSIX_Absolute_timeout_conversion_results_t status;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
+ already_timedout = false;
+ status = _POSIX_Absolute_timeout_to_ticks(abstime, &ticks);
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
+ return EINVAL;
+
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
+ status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
+ already_timedout = true;
+
+ return _POSIX_Condition_variables_Wait_support(
+ cond,
+ mutex,
+ ticks,
+ already_timedout
+ );
+}
diff --git a/cpukit/posix/src/condwait.c b/cpukit/posix/src/condwait.c
new file mode 100644
index 0000000000..2d925a3b80
--- /dev/null
+++ b/cpukit/posix/src/condwait.c
@@ -0,0 +1,43 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105
+ */
+
+int pthread_cond_wait(
+ pthread_cond_t *cond,
+ pthread_mutex_t *mutex
+)
+{
+ return _POSIX_Condition_variables_Wait_support(
+ cond,
+ mutex,
+ THREAD_QUEUE_WAIT_FOREVER,
+ false
+ );
+}
diff --git a/cpukit/posix/src/condwaitsupp.c b/cpukit/posix/src/condwaitsupp.c
new file mode 100644
index 0000000000..745d224d3d
--- /dev/null
+++ b/cpukit/posix/src/condwaitsupp.c
@@ -0,0 +1,122 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * _POSIX_Condition_variables_Wait_support
+ *
+ * A support routine which implements guts of the blocking, non-blocking, and
+ * timed wait version of condition variable wait routines.
+ */
+
+int _POSIX_Condition_variables_Wait_support(
+ pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ Watchdog_Interval timeout,
+ bool already_timedout
+)
+{
+ register POSIX_Condition_variables_Control *the_cond;
+ Objects_Locations location;
+ int status;
+ int mutex_status;
+
+ if ( !_POSIX_Mutex_Get( mutex, &location ) ) {
+ return EINVAL;
+ }
+
+ _Thread_Unnest_dispatch();
+
+ the_cond = _POSIX_Condition_variables_Get( cond, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ if ( the_cond->Mutex && ( the_cond->Mutex != *mutex ) ) {
+ _Thread_Enable_dispatch();
+ return EINVAL;
+ }
+
+ (void) pthread_mutex_unlock( mutex );
+/* XXX ignore this for now since behavior is undefined
+ if ( mutex_status ) {
+ _Thread_Enable_dispatch();
+ return EINVAL;
+ }
+*/
+
+ if ( !already_timedout ) {
+ the_cond->Mutex = *mutex;
+
+ _Thread_queue_Enter_critical_section( &the_cond->Wait_queue );
+ _Thread_Executing->Wait.return_code = 0;
+ _Thread_Executing->Wait.queue = &the_cond->Wait_queue;
+ _Thread_Executing->Wait.id = *cond;
+
+ _Thread_queue_Enqueue( &the_cond->Wait_queue, timeout );
+
+ _Thread_Enable_dispatch();
+
+ /*
+ * Switch ourself out because we blocked as a result of the
+ * _Thread_queue_Enqueue.
+ */
+
+ /*
+ * If the thread is interrupted, while in the thread queue, by
+ * a POSIX signal, then pthread_cond_wait returns spuriously,
+ * according to the POSIX standard. It means that pthread_cond_wait
+ * returns a success status, except for the fact that it was not
+ * woken up a pthread_cond_signal or a pthread_cond_broadcast.
+ */
+ status = _Thread_Executing->Wait.return_code;
+ if ( status == EINTR )
+ status = 0;
+
+ } else {
+ _Thread_Enable_dispatch();
+ status = ETIMEDOUT;
+ }
+
+ /*
+ * When we get here the dispatch disable level is 0.
+ */
+
+ mutex_status = pthread_mutex_lock( mutex );
+ if ( mutex_status )
+ return EINVAL;
+
+ return status;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/execl.c b/cpukit/posix/src/execl.c
new file mode 100644
index 0000000000..9edaba341d
--- /dev/null
+++ b/cpukit/posix/src/execl.c
@@ -0,0 +1,32 @@
+/*
+ * execl() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_EXECL
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int execl(
+ const char *path,
+ const char *arg,
+ ...
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
+
+#endif
diff --git a/cpukit/posix/src/execle.c b/cpukit/posix/src/execle.c
new file mode 100644
index 0000000000..947a4e104f
--- /dev/null
+++ b/cpukit/posix/src/execle.c
@@ -0,0 +1,32 @@
+/*
+ * execle() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_EXECLE
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int execle(
+ const char *path,
+ char const *arg,
+ ...
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
+
+#endif
diff --git a/cpukit/posix/src/execlp.c b/cpukit/posix/src/execlp.c
new file mode 100644
index 0000000000..fabc6986bb
--- /dev/null
+++ b/cpukit/posix/src/execlp.c
@@ -0,0 +1,32 @@
+/*
+ * execlp() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_EXECLP
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int execlp(
+ const char *file,
+ const char *arg,
+ ...
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
+
+#endif
diff --git a/cpukit/posix/src/execv.c b/cpukit/posix/src/execv.c
new file mode 100644
index 0000000000..46595232ad
--- /dev/null
+++ b/cpukit/posix/src/execv.c
@@ -0,0 +1,31 @@
+/*
+ * execv() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_EXECV
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int execv(
+ const char *file,
+ char *const argv[]
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
+
+#endif
diff --git a/cpukit/posix/src/execve.c b/cpukit/posix/src/execve.c
new file mode 100644
index 0000000000..b89009866e
--- /dev/null
+++ b/cpukit/posix/src/execve.c
@@ -0,0 +1,32 @@
+/*
+ * execve() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_EXECVE
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int execve(
+ const char *path,
+ char *const argv[],
+ char *const envp[]
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
+
+#endif
diff --git a/cpukit/posix/src/execvp.c b/cpukit/posix/src/execvp.c
new file mode 100644
index 0000000000..720543fcdf
--- /dev/null
+++ b/cpukit/posix/src/execvp.c
@@ -0,0 +1,31 @@
+/*
+ * execvp() - POSIX 1003.1b 3.1.2
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef HAVE_EXECVP
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int execvp(
+ const char *path,
+ char *const argv[]
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
+
+#endif
diff --git a/cpukit/posix/src/fork.c b/cpukit/posix/src/fork.c
new file mode 100644
index 0000000000..f0023e2978
--- /dev/null
+++ b/cpukit/posix/src/fork.c
@@ -0,0 +1,25 @@
+/*
+ * fork() - POSIX 1003.1b 3.1.1
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int fork( void )
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/getitimer.c b/cpukit/posix/src/getitimer.c
new file mode 100644
index 0000000000..8d1bb97904
--- /dev/null
+++ b/cpukit/posix/src/getitimer.c
@@ -0,0 +1,39 @@
+/*
+ * COPYRIGHT (c) 1989-20089
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int getitimer(
+ int which,
+ struct itimerval *value
+)
+{
+ if ( !value )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ switch ( which ) {
+ case ITIMER_REAL:
+ case ITIMER_VIRTUAL:
+ case ITIMER_PROF:
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+ default:
+ break;
+ }
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
+
diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c
new file mode 100644
index 0000000000..a32853cac4
--- /dev/null
+++ b/cpukit/posix/src/key.c
@@ -0,0 +1,58 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <string.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/key.h>
+
+/*
+ * _POSIX_Key_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Key_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Keys_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_KEYS, /* object class */
+ Configuration_POSIX_API.maximum_keys,
+ /* maximum objects of this class */
+ sizeof( POSIX_Keys_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/keycreate.c b/cpukit/posix/src/keycreate.c
new file mode 100644
index 0000000000..1fc87641e5
--- /dev/null
+++ b/cpukit/posix/src/keycreate.c
@@ -0,0 +1,99 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/key.h>
+
+/*
+ * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163
+ */
+
+int pthread_key_create(
+ pthread_key_t *key,
+ void (*destructor)( void * )
+)
+{
+ POSIX_Keys_Control *the_key;
+ void *table;
+ uint32_t the_api;
+ uint32_t bytes_to_allocate;
+
+
+ _Thread_Disable_dispatch();
+
+ the_key = _POSIX_Keys_Allocate();
+
+ if ( !the_key ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ the_key->destructor = destructor;
+
+ /*
+ * This is a bit more complex than one might initially expect because
+ * APIs are optional.
+ *
+ * NOTE: Currently RTEMS Classic API tasks are always enabled.
+ */
+ for ( the_api = 1; the_api <= OBJECTS_APIS_LAST; the_api++ ) {
+ the_key->Values[ the_api ] = NULL;
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * Since the removal of ITRON, this cannot occur.
+ */
+ if ( !_Objects_Information_table[ the_api ] )
+ continue;
+
+ /*
+ * Currently all managers are installed if the API is installed.
+ * This would be a horrible implementation error.
+ */
+ if (_Objects_Information_table[ the_api ][ 1 ] == NULL )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY
+ );
+ #endif
+
+ bytes_to_allocate = sizeof( void * ) *
+ (_Objects_Information_table[ the_api ][ 1 ]->maximum + 1);
+ table = _Workspace_Allocate( bytes_to_allocate );
+ if ( !table ) {
+ _POSIX_Keys_Free_memory( the_key );
+
+ _POSIX_Keys_Free( the_key );
+ _Thread_Enable_dispatch();
+ return ENOMEM;
+ }
+
+ the_key->Values[ the_api ] = table;
+ memset( table, '\0', bytes_to_allocate );
+ }
+
+ _Objects_Open_u32( &_POSIX_Keys_Information, &the_key->Object, 0 );
+ *key = the_key->Object.id;
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/keydelete.c b/cpukit/posix/src/keydelete.c
new file mode 100644
index 0000000000..99b6e7eedd
--- /dev/null
+++ b/cpukit/posix/src/keydelete.c
@@ -0,0 +1,60 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/key.h>
+
+/*
+ * 17.1.3 Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167
+ */
+int pthread_key_delete(
+ pthread_key_t key
+)
+{
+ POSIX_Keys_Control *the_key;
+ Objects_Locations location;
+
+ the_key = _POSIX_Keys_Get( key, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Close( &_POSIX_Keys_Information, &the_key->Object );
+
+ _POSIX_Keys_Free_memory( the_key );
+
+ /*
+ * NOTE: The destructor is not called and it is the responsibility
+ * of the application to free the memory.
+ */
+ _POSIX_Keys_Free( the_key );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never happen */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/keyfreememory.c b/cpukit/posix/src/keyfreememory.c
new file mode 100644
index 0000000000..b6449ffa21
--- /dev/null
+++ b/cpukit/posix/src/keyfreememory.c
@@ -0,0 +1,29 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/key.h>
+
+void _POSIX_Keys_Free_memory(
+ POSIX_Keys_Control *the_key
+)
+{
+ uint32_t the_api;
+
+ for ( the_api = 1; the_api <= OBJECTS_APIS_LAST; the_api++ )
+ _Workspace_Free( the_key->Values[ the_api ] );
+}
diff --git a/cpukit/posix/src/keygetspecific.c b/cpukit/posix/src/keygetspecific.c
new file mode 100644
index 0000000000..e0acff1455
--- /dev/null
+++ b/cpukit/posix/src/keygetspecific.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/key.h>
+
+/*PAGE
+ *
+ * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165
+ */
+
+void *pthread_getspecific(
+ pthread_key_t key
+)
+{
+ register POSIX_Keys_Control *the_key;
+ uint32_t api;
+ uint32_t index;
+ Objects_Locations location;
+ void *key_data;
+
+ the_key = _POSIX_Keys_Get( key, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = _Objects_Get_API( _Thread_Executing->Object.id );
+ index = _Objects_Get_index( _Thread_Executing->Object.id );
+ key_data = (void *) the_key->Values[ api ][ index ];
+ _Thread_Enable_dispatch();
+ return key_data;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never happen */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return NULL;
+}
diff --git a/cpukit/posix/src/keyrundestructors.c b/cpukit/posix/src/keyrundestructors.c
new file mode 100644
index 0000000000..cc8bad94e8
--- /dev/null
+++ b/cpukit/posix/src/keyrundestructors.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/key.h>
+
+/*PAGE
+ *
+ * _POSIX_Keys_Run_destructors
+ *
+ * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163
+ *
+ * NOTE: This is the routine executed when a thread exits to
+ * run through all the keys and do the destructor action.
+ */
+
+void _POSIX_Keys_Run_destructors(
+ Thread_Control *thread
+)
+{
+ Objects_Maximum thread_index = _Objects_Get_index( thread->Object.id );
+ Objects_APIs thread_api = _Objects_Get_API( thread->Object.id );
+ bool done = false;
+
+ /*
+ * The standard allows one to avoid a potential infinite loop and limit the
+ * number of iterations. An infinite loop may happen if destructors set
+ * thread specific data. This can be considered dubious.
+ *
+ * Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99.
+ */
+ while ( !done ) {
+ Objects_Maximum index = 0;
+ Objects_Maximum max = _POSIX_Keys_Information.maximum;
+
+ done = true;
+
+ for ( index = 1 ; index <= max ; ++index ) {
+ POSIX_Keys_Control *key = (POSIX_Keys_Control *)
+ _POSIX_Keys_Information.local_table [ index ];
+
+ if ( key != NULL && key->destructor != NULL ) {
+ void *value = key->Values [ thread_api ][ thread_index ];
+
+ if ( value != NULL ) {
+ key->Values [ thread_api ][ thread_index ] = NULL;
+ (*key->destructor)( value );
+ done = false;
+ }
+ }
+ }
+ }
+}
diff --git a/cpukit/posix/src/keysetspecific.c b/cpukit/posix/src/keysetspecific.c
new file mode 100644
index 0000000000..8f85ffbcf9
--- /dev/null
+++ b/cpukit/posix/src/keysetspecific.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/key.h>
+
+/*PAGE
+ *
+ * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165
+ */
+
+int pthread_setspecific(
+ pthread_key_t key,
+ const void *value
+)
+{
+ register POSIX_Keys_Control *the_key;
+ uint32_t api;
+ uint32_t index;
+ Objects_Locations location;
+
+ the_key = _POSIX_Keys_Get( key, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = _Objects_Get_API( _Thread_Executing->Object.id );
+ index = _Objects_Get_index( _Thread_Executing->Object.id );
+ the_key->Values[ api ][ index ] = (void *) value;
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never happen */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/kill.c b/cpukit/posix/src/kill.c
new file mode 100644
index 0000000000..34ea487806
--- /dev/null
+++ b/cpukit/posix/src/kill.c
@@ -0,0 +1,32 @@
+/*
+ * 3.3.2 Send a Signal to a Process, P1003.1b-1993, p. 68
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+int kill(
+ pid_t pid,
+ int sig
+)
+{
+ return killinfo( pid, sig, NULL );
+}
+
diff --git a/cpukit/posix/src/kill_r.c b/cpukit/posix/src/kill_r.c
new file mode 100644
index 0000000000..2da710f799
--- /dev/null
+++ b/cpukit/posix/src/kill_r.c
@@ -0,0 +1,37 @@
+/*
+ * 3.3.2 Send a Signal to a Process, P1003.1b-1993, p. 68
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+#if defined(RTEMS_NEWLIB)
+
+#include <reent.h>
+
+int _kill_r(
+ struct _reent *ptr,
+ pid_t pid,
+ int sig
+)
+{
+ return killinfo( pid, sig, NULL );
+}
+#endif
diff --git a/cpukit/posix/src/killinfo.c b/cpukit/posix/src/killinfo.c
new file mode 100644
index 0000000000..b1569e791b
--- /dev/null
+++ b/cpukit/posix/src/killinfo.c
@@ -0,0 +1,351 @@
+/*
+ * kill() support routine
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/seterr.h>
+#include <rtems/score/isr.h>
+
+/*
+ * If you enable this, then you get printk() feedback on each path
+ * and the input to the decision that lead to the decision. Hopefully
+ * this will help in debugging the algorithm that distributes process
+ * signals to individual threads.
+ */
+
+/* #define DEBUG_SIGNAL_PROCESSING */
+#if defined(DEBUG_SIGNAL_PROCESSING)
+ #include <rtems/bspIo.h>
+ #define DEBUG_STEP(_x) printk(_x)
+#else
+ #define DEBUG_STEP(_x)
+#endif
+
+/*
+ * 3.3.2 Send a Signal to a Process, P1003.1b-1993, p. 68
+ *
+ * NOTE: Behavior of kill() depends on _POSIX_SAVED_IDS.
+ */
+
+#define _POSIX_signals_Is_interested( _api, _mask ) \
+ ( ~(_api)->signals_blocked & (_mask) )
+
+int killinfo(
+ pid_t pid,
+ int sig,
+ const union sigval *value
+)
+{
+ sigset_t mask;
+ POSIX_API_Control *api;
+ uint32_t the_api;
+ uint32_t index;
+ uint32_t maximum;
+ Objects_Information *the_info;
+ Objects_Control **object_table;
+ Thread_Control *the_thread;
+ Thread_Control *interested;
+ Priority_Control interested_priority;
+ Chain_Control *the_chain;
+ Chain_Node *the_node;
+ siginfo_t siginfo_struct;
+ siginfo_t *siginfo;
+ POSIX_signals_Siginfo_node *psiginfo;
+
+ /*
+ * Only supported for the "calling process" (i.e. this node).
+ */
+ if ( pid != getpid() )
+ rtems_set_errno_and_return_minus_one( ESRCH );
+
+ /*
+ * Validate the signal passed.
+ */
+ if ( !sig )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !is_valid_signo(sig) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * If the signal is being ignored, then we are out of here.
+ */
+ if ( _POSIX_signals_Vectors[ sig ].sa_handler == SIG_IGN )
+ return 0;
+
+ /*
+ * P1003.1c/Draft 10, p. 33 says that certain signals should always
+ * be directed to the executing thread such as those caused by hardware
+ * faults.
+ */
+ if ( (sig == SIGFPE) || (sig == SIGILL) || (sig == SIGSEGV ) )
+ return pthread_kill( pthread_self(), sig );
+
+ mask = signo_to_mask( sig );
+
+ /*
+ * Build up a siginfo structure
+ */
+ siginfo = &siginfo_struct;
+ siginfo->si_signo = sig;
+ siginfo->si_code = SI_USER;
+ if ( !value ) {
+ siginfo->si_value.sival_int = 0;
+ } else {
+ siginfo->si_value = *value;
+ }
+
+ _Thread_Disable_dispatch();
+
+ /*
+ * Is the currently executing thread interested? If so then it will
+ * get it an execute it as soon as the dispatcher executes.
+ */
+ the_thread = _Thread_Executing;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+ if ( _POSIX_signals_Is_interested( api, mask ) ) {
+ goto process_it;
+ }
+
+ /*
+ * Is an interested thread waiting for this signal (sigwait())?
+ *
+ * There is no requirement on the order of threads pending on a sigwait().
+ */
+
+ /* XXX violation of visibility -- need to define thread queue support */
+
+ the_chain = &_POSIX_signals_Wait_queue.Queues.Fifo;
+
+ for ( the_node = _Chain_First( the_chain );
+ !_Chain_Is_tail( the_chain, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_thread = (Thread_Control *)the_node;
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ #if defined(DEBUG_SIGNAL_PROCESSING)
+ printk( "Waiting Thread=%p option=0x%08x mask=0x%08x blocked=0x%08x\n",
+ the_thread, the_thread->Wait.option, mask, api->signals_blocked);
+ #endif
+
+ /*
+ * Is this thread is actually blocked waiting for the signal?
+ */
+ if (the_thread->Wait.option & mask)
+ goto process_it;
+
+ /*
+ * Is this thread is blocked waiting for another signal but has
+ * not blocked this one?
+ */
+ if (~api->signals_blocked & mask)
+ goto process_it;
+ }
+
+ /*
+ * Is any other thread interested? The highest priority interested
+ * thread is selected. In the event of a tie, then the following
+ * additional criteria is used:
+ *
+ * + ready thread over blocked
+ * + blocked on call interruptible by signal (can return EINTR)
+ * + blocked on call not interruptible by signal
+ *
+ * This looks at every thread in the system regardless of the creating API.
+ *
+ * NOTES:
+ *
+ * + rtems internal threads do not receive signals.
+ */
+ interested = NULL;
+ interested_priority = PRIORITY_MAXIMUM + 1;
+
+ for (the_api = OBJECTS_CLASSIC_API; the_api <= OBJECTS_APIS_LAST; the_api++) {
+
+ /*
+ * This can occur when no one is interested and an API is not configured.
+ */
+ if ( !_Objects_Information_table[ the_api ] )
+ continue;
+
+ the_info = _Objects_Information_table[ the_api ][ 1 ];
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * This cannot happen in the current (as of June 2009) implementation
+ * of initialization but at some point, the object information
+ * structure for a particular manager may not be installed.
+ */
+ if ( !the_info )
+ continue;
+ #endif
+
+ maximum = the_info->maximum;
+ object_table = the_info->local_table;
+
+ for ( index = 1 ; index <= maximum ; index++ ) {
+ the_thread = (Thread_Control *) object_table[ index ];
+
+ if ( !the_thread )
+ continue;
+
+ #if defined(DEBUG_SIGNAL_PROCESSING)
+ printk("\n 0x%08x/0x%08x %d/%d 0x%08x 1",
+ the_thread->Object.id,
+ ((interested) ? interested->Object.id : 0),
+ the_thread->current_priority, interested_priority,
+ the_thread->current_state
+ );
+ #endif
+
+ /*
+ * If this thread is of lower priority than the interested thread,
+ * go on to the next thread.
+ */
+ if ( the_thread->current_priority > interested_priority )
+ continue;
+ DEBUG_STEP("2");
+
+ /*
+ * If this thread is not interested, then go on to the next thread.
+ */
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ #if defined(RTEMS_DEBUG)
+ if ( !api )
+ continue;
+ #endif
+
+ if ( !_POSIX_signals_Is_interested( api, mask ) )
+ continue;
+ DEBUG_STEP("3");
+
+ /*
+ * Now we know the thread under consideration is interested.
+ * If the thread under consideration is of higher priority, then
+ * it becomes the interested thread.
+ *
+ * NOTE: We initialized interested_priority to PRIORITY_MAXIMUM + 1
+ * so we never have to worry about deferencing a NULL
+ * interested thread.
+ */
+ if ( the_thread->current_priority < interested_priority ) {
+ interested = the_thread;
+ interested_priority = the_thread->current_priority;
+ continue;
+ }
+ DEBUG_STEP("4");
+
+ /*
+ * Now the thread and the interested thread have the same priority.
+ * We have to sort through the combinations of blocked/not blocked
+ * and blocking interruptibutable by signal.
+ *
+ * If the interested thread is ready, don't think about changing.
+ */
+
+ if ( interested && !_States_Is_ready( interested->current_state ) ) {
+ /* preferred ready over blocked */
+ DEBUG_STEP("5");
+ if ( _States_Is_ready( the_thread->current_state ) ) {
+ interested = the_thread;
+ interested_priority = the_thread->current_priority;
+ continue;
+ }
+
+ DEBUG_STEP("6");
+ /* prefer blocked/interruptible over blocked/not interruptible */
+ if ( !_States_Is_interruptible_by_signal(interested->current_state) ) {
+ DEBUG_STEP("7");
+ if ( _States_Is_interruptible_by_signal(the_thread->current_state) ) {
+ DEBUG_STEP("8");
+ interested = the_thread;
+ interested_priority = the_thread->current_priority;
+ continue;
+ }
+ }
+ }
+ }
+ }
+
+ if ( interested ) {
+ the_thread = interested;
+ goto process_it;
+ }
+
+ /*
+ * OK so no threads were interested right now. It will be left on the
+ * global pending until a thread receives it. The global set of threads
+ * can change interest in this signal in one of the following ways:
+ *
+ * + a thread is created with the signal unblocked,
+ * + pthread_sigmask() unblocks the signal,
+ * + sigprocmask() unblocks the signal, OR
+ * + sigaction() which changes the handler to SIG_IGN.
+ */
+ the_thread = NULL;
+ goto post_process_signal;
+
+ /*
+ * We found a thread which was interested, so now we mark that this
+ * thread needs to do the post context switch extension so it can
+ * evaluate the signals pending.
+ */
+process_it:
+
+ /*
+ * Returns true if the signal was synchronously given to a thread
+ * blocked waiting for the signal.
+ */
+ if ( _POSIX_signals_Unblock_thread( the_thread, sig, siginfo ) ) {
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+post_process_signal:
+
+ /*
+ * We may have woken up a thread but we definitely need to post the
+ * signal to the process wide information set.
+ */
+ _POSIX_signals_Set_process_signals( mask );
+
+ if ( _POSIX_signals_Vectors[ sig ].sa_flags == SA_SIGINFO ) {
+
+ psiginfo = (POSIX_signals_Siginfo_node *)
+ _Chain_Get( &_POSIX_signals_Inactive_siginfo );
+ if ( !psiginfo ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EAGAIN );
+ }
+
+ psiginfo->Info = *siginfo;
+
+ _Chain_Append( &_POSIX_signals_Siginfo[ sig ], &psiginfo->Node );
+ }
+
+ DEBUG_STEP("\n");
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/lio_listio.c b/cpukit/posix/src/lio_listio.c
new file mode 100644
index 0000000000..4444b10302
--- /dev/null
+++ b/cpukit/posix/src/lio_listio.c
@@ -0,0 +1,32 @@
+/*
+ * 6.7.4 List Directed I/O, P1003.1b-1993, p. 158
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <aio.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+int lio_listio(
+ int mode __attribute__((unused)),
+ struct aiocb * const list[] __attribute__((unused)),
+ int nent __attribute__((unused)),
+ struct sigevent *sig __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/mprotect.c b/cpukit/posix/src/mprotect.c
new file mode 100644
index 0000000000..d3fa8bf9c9
--- /dev/null
+++ b/cpukit/posix/src/mprotect.c
@@ -0,0 +1,36 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+
+/*PAGE
+ *
+ * 12.2.3 Change Memory Protection, P1003.1b-1996, p. 277.
+ *
+ * This is not a functional version but the SPARC backend for at least
+ * gcc 2.8.1 plus gnat 3.13p and gcc 3.0.1 require it to be there and
+ * return 0.
+ *
+ * As of gcc 4.2.2, the gcc SPARC backend doesn't appear to have a
+ * way to call this for RTEMS anymore but it doesn't hurt to leave it.
+ */
+
+int mprotect(
+ const void *addr __attribute__((unused)),
+ size_t len __attribute__((unused)),
+ int prot __attribute__((unused)) )
+{
+ return 0;
+}
diff --git a/cpukit/posix/src/mqueue.c b/cpukit/posix/src/mqueue.c
new file mode 100644
index 0000000000..5229bd4d67
--- /dev/null
+++ b/cpukit/posix/src/mqueue.c
@@ -0,0 +1,87 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Manager_initialization
+ *
+ * This routine initializes all message_queue manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Message_queue_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Message_queue_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_MESSAGE_QUEUES, /* object class */
+ Configuration_POSIX_API.maximum_message_queues,
+ /* maximum objects of this class */
+ sizeof( POSIX_Message_queue_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+ _Objects_Initialize_information(
+ &_POSIX_Message_queue_Information_fds,
+ OBJECTS_POSIX_API,
+ OBJECTS_POSIX_MESSAGE_QUEUE_FDS,
+ Configuration_POSIX_API.maximum_message_queue_descriptors,
+ sizeof( POSIX_Message_queue_Control_fd ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ NAME_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/mqueueclose.c b/cpukit/posix/src/mqueueclose.c
new file mode 100644
index 0000000000..35b4dc3ec1
--- /dev/null
+++ b/cpukit/posix/src/mqueueclose.c
@@ -0,0 +1,85 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*
+ *
+ * 15.2.2 Close a Message Queue, P1003.1b-1993, p. 275
+ */
+
+int mq_close(
+ mqd_t mqdes
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ Objects_Locations location;
+
+ the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
+ if ( location == OBJECTS_LOCAL ) {
+ /* OBJECTS_LOCAL:
+ *
+ * First update the actual message queue to reflect this descriptor
+ * being disassociated. This may result in the queue being really
+ * deleted.
+ */
+
+ the_mq = the_mq_fd->Queue;
+ the_mq->open_count -= 1;
+ _POSIX_Message_queue_Delete( the_mq );
+
+ /*
+ * Now close this file descriptor.
+ */
+
+ _Objects_Close(
+ &_POSIX_Message_queue_Information_fds, &the_mq_fd->Object );
+ _POSIX_Message_queue_Free_fd( the_mq_fd );
+
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ /*
+ * OBJECTS_REMOTE:
+ * OBJECTS_ERROR:
+ */
+ rtems_set_errno_and_return_minus_one( EBADF );
+}
diff --git a/cpukit/posix/src/mqueuecreatesupp.c b/cpukit/posix/src/mqueuecreatesupp.c
new file mode 100644
index 0000000000..90bab33ed7
--- /dev/null
+++ b/cpukit/posix/src/mqueuecreatesupp.c
@@ -0,0 +1,153 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/* pure ANSI mode does not have this prototype */
+size_t strnlen(const char *, size_t);
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Create_support
+ *
+ * This routine does the actual creation and initialization of
+ * a poxix message queue.
+ */
+
+int _POSIX_Message_queue_Create_support(
+ const char *name_arg,
+ int pshared,
+ struct mq_attr *attr_ptr,
+ POSIX_Message_queue_Control **message_queue
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+ CORE_message_queue_Attributes *the_mq_attr;
+ struct mq_attr attr;
+ char *name;
+ size_t n;
+
+ n = strnlen( name_arg, NAME_MAX );
+ /* length of name has already been validated */
+
+ _Thread_Disable_dispatch();
+
+ /*
+ * There is no real basis for the default values. They will work
+ * but were not compared against any existing implementation for
+ * compatibility. See README.mqueue for an example program we
+ * think will print out the defaults. Report anything you find with it.
+ */
+ if ( attr_ptr == NULL ) {
+ attr.mq_maxmsg = 10;
+ attr.mq_msgsize = 16;
+ } else {
+ if ( attr_ptr->mq_maxmsg <= 0 ){
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ if ( attr_ptr->mq_msgsize <= 0 ){
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ attr = *attr_ptr;
+ }
+
+ the_mq = _POSIX_Message_queue_Allocate();
+ if ( !the_mq ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( ENFILE );
+ }
+
+ the_mq->process_shared = pshared;
+ the_mq->named = true;
+ the_mq->open_count = 1;
+ the_mq->linked = true;
+
+ /*
+ * Make a copy of the user's string for name just in case it was
+ * dynamically constructed.
+ */
+ name = _Workspace_Allocate(n+1);
+ if (!name) {
+ _POSIX_Message_queue_Free( the_mq );
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+ strncpy( name, name_arg, n+1 );
+
+ /*
+ * NOTE: That thread blocking discipline should be based on the
+ * current scheduling policy.
+ *
+ * Joel: Cite POSIX or OpenGroup on above statement so we can determine
+ * if it is a real requirement.
+ */
+ the_mq_attr = &the_mq->Message_queue.Attributes;
+ the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
+
+ if ( !_CORE_message_queue_Initialize(
+ &the_mq->Message_queue,
+ the_mq_attr,
+ attr.mq_maxmsg,
+ attr.mq_msgsize
+ ) ) {
+
+ _POSIX_Message_queue_Free( the_mq );
+ _Workspace_Free(name);
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( ENOSPC );
+ }
+
+ _Objects_Open_string(
+ &_POSIX_Message_queue_Information,
+ &the_mq->Object,
+ name
+ );
+
+ *message_queue = the_mq;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/mqueuedeletesupp.c b/cpukit/posix/src/mqueuedeletesupp.c
new file mode 100644
index 0000000000..4c95b08c95
--- /dev/null
+++ b/cpukit/posix/src/mqueuedeletesupp.c
@@ -0,0 +1,82 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+#if defined(RTEMS_DEBUG)
+ #include <rtems/bspIo.h>
+#endif
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Delete
+ */
+
+void _POSIX_Message_queue_Delete(
+ POSIX_Message_queue_Control *the_mq
+)
+{
+ if ( !the_mq->linked && !the_mq->open_count ) {
+ Objects_Control *the_object = &the_mq->Object;
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * the name memory will have been freed by unlink.
+ */
+ if ( the_object->name.name_p ) {
+ printk(
+ "POSIX MQ name (%p) not freed by unlink\n",
+ (void *)the_object->name.name_p
+ );
+ _Workspace_Free( (void *)the_object->name.name_p );
+ }
+ #endif
+
+ _Objects_Close( &_POSIX_Message_queue_Information, the_object );
+
+ _CORE_message_queue_Close(
+ &the_mq->Message_queue,
+ NULL, /* no MP support */
+ CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED
+ );
+
+ _POSIX_Message_queue_Free( the_mq );
+
+ }
+}
diff --git a/cpukit/posix/src/mqueuegetattr.c b/cpukit/posix/src/mqueuegetattr.c
new file mode 100644
index 0000000000..16a5c50b5f
--- /dev/null
+++ b/cpukit/posix/src/mqueuegetattr.c
@@ -0,0 +1,88 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283
+ */
+
+int mq_getattr(
+ mqd_t mqdes,
+ struct mq_attr *mqstat
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ Objects_Locations location;
+ CORE_message_queue_Attributes *the_mq_attr;
+
+ if ( !mqstat )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_mq = the_mq_fd->Queue;
+
+ /*
+ * Return the old values.
+ */
+
+ the_mq_attr = &the_mq->Message_queue.Attributes;
+
+ mqstat->mq_flags = the_mq_fd->oflag;
+ mqstat->mq_msgsize = the_mq->Message_queue.maximum_message_size;
+ mqstat->mq_maxmsg = the_mq->Message_queue.maximum_pending_messages;
+ mqstat->mq_curmsgs = the_mq->Message_queue.number_of_pending_messages;
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EBADF );
+}
diff --git a/cpukit/posix/src/mqueuenametoid.c b/cpukit/posix/src/mqueuenametoid.c
new file mode 100644
index 0000000000..f52e3383c2
--- /dev/null
+++ b/cpukit/posix/src/mqueuenametoid.c
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/* pure ANSI mode does not have this prototype */
+size_t strnlen(const char *, size_t);
+
+/*
+ * _POSIX_Message_queue_Name_to_id
+ *
+ * Look up the specified name and attempt to locate the id
+ * for the associated message queue.
+ */
+int _POSIX_Message_queue_Name_to_id(
+ const char *name,
+ Objects_Id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+ Objects_Id the_id;
+
+ if ( !name )
+ return EINVAL;
+
+ if ( !name[0] )
+ return EINVAL;
+
+ if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
+ return ENAMETOOLONG;
+
+ status = _Objects_Name_to_id_string(
+ &_POSIX_Message_queue_Information,
+ name,
+ &the_id
+ );
+ *id = the_id;
+
+ if ( status == OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL )
+ return 0;
+
+ return ENOENT;
+}
diff --git a/cpukit/posix/src/mqueuenotify.c b/cpukit/posix/src/mqueuenotify.c
new file mode 100644
index 0000000000..1b9660ccbf
--- /dev/null
+++ b/cpukit/posix/src/mqueuenotify.c
@@ -0,0 +1,116 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Notify_handler
+ *
+ */
+
+void _POSIX_Message_queue_Notify_handler(
+ void *user_data
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+
+ the_mq = user_data;
+
+ kill( getpid(), the_mq->notification.sigev_signo );
+
+ _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL );
+}
+
+/*PAGE
+ *
+ * 15.2.6 Notify Process that a Message is Available on a Queue,
+ * P1003.1b-1993, p. 280
+ */
+
+int mq_notify(
+ mqd_t mqdes,
+ const struct sigevent *notification
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ Objects_Locations location;
+
+ the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_mq = the_mq_fd->Queue;
+
+ if ( notification ) {
+ if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EBUSY );
+ }
+
+ _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL );
+
+ the_mq->notification = *notification;
+
+ _CORE_message_queue_Set_notify(
+ &the_mq->Message_queue,
+ _POSIX_Message_queue_Notify_handler,
+ the_mq
+ );
+ } else {
+
+ _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL );
+
+ }
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EBADF );
+}
diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c
new file mode 100644
index 0000000000..2b96236fb5
--- /dev/null
+++ b/cpukit/posix/src/mqueueopen.c
@@ -0,0 +1,155 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*
+ * 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
+ */
+mqd_t mq_open(
+ const char *name,
+ int oflag,
+ ...
+ /* mode_t mode, */
+ /* struct mq_attr attr */
+)
+{
+ va_list arg;
+ mode_t mode;
+ struct mq_attr *attr = NULL;
+ int status;
+ Objects_Id the_mq_id;
+ POSIX_Message_queue_Control *the_mq;
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ Objects_Locations location;
+
+ _Thread_Disable_dispatch();
+
+ if ( oflag & O_CREAT ) {
+ va_start(arg, oflag);
+ mode = (mode_t) va_arg( arg, unsigned int );
+ attr = (struct mq_attr *) va_arg( arg, struct mq_attr * );
+ va_end(arg);
+ }
+
+ the_mq_fd = _POSIX_Message_queue_Allocate_fd();
+ if ( !the_mq_fd ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( ENFILE );
+ }
+ the_mq_fd->oflag = oflag;
+
+ status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id );
+
+ /*
+ * If the name to id translation worked, then the message queue exists
+ * and we can just return a pointer to the id. Otherwise we may
+ * need to check to see if this is a "message queue does not exist"
+ * or some other miscellaneous error on the name.
+ */
+ if ( status ) {
+ /*
+ * Unless provided a valid name that did not already exist
+ * and we are willing to create then it is an error.
+ */
+ if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
+ _POSIX_Message_queue_Free_fd( the_mq_fd );
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
+ }
+
+ } else { /* name -> ID translation succeeded */
+ /*
+ * Check for existence with creation.
+ */
+ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
+ _POSIX_Message_queue_Free_fd( the_mq_fd );
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
+ }
+
+ /*
+ * In this case we need to do an ID->pointer conversion to
+ * check the mode.
+ */
+ the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
+ the_mq->open_count += 1;
+ the_mq_fd->Queue = the_mq;
+ _Objects_Open_string(
+ &_POSIX_Message_queue_Information_fds,
+ &the_mq_fd->Object,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+ _Thread_Enable_dispatch();
+ return (mqd_t)the_mq_fd->Object.id;
+
+ }
+
+ /*
+ * At this point, the message queue does not exist and everything has been
+ * checked. We should go ahead and create a message queue.
+ */
+ status = _POSIX_Message_queue_Create_support(
+ name,
+ true, /* shared across processes */
+ attr,
+ &the_mq
+ );
+
+ /*
+ * errno was set by Create_support, so don't set it again.
+ */
+ if ( status == -1 ) {
+ _POSIX_Message_queue_Free_fd( the_mq_fd );
+ _Thread_Enable_dispatch();
+ return (mqd_t) -1;
+ }
+
+ the_mq_fd->Queue = the_mq;
+ _Objects_Open_string(
+ &_POSIX_Message_queue_Information_fds,
+ &the_mq_fd->Object,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+
+ return (mqd_t) the_mq_fd->Object.id;
+}
diff --git a/cpukit/posix/src/mqueuereceive.c b/cpukit/posix/src/mqueuereceive.c
new file mode 100644
index 0000000000..46b46b8359
--- /dev/null
+++ b/cpukit/posix/src/mqueuereceive.c
@@ -0,0 +1,64 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279
+ *
+ * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive().
+ */
+
+ssize_t mq_receive(
+ mqd_t mqdes,
+ char *msg_ptr,
+ size_t msg_len,
+ unsigned int *msg_prio
+)
+{
+ return _POSIX_Message_queue_Receive_support(
+ mqdes,
+ msg_ptr,
+ msg_len,
+ msg_prio,
+ true,
+ THREAD_QUEUE_WAIT_FOREVER
+ );
+}
diff --git a/cpukit/posix/src/mqueuerecvsupp.c b/cpukit/posix/src/mqueuerecvsupp.c
new file mode 100644
index 0000000000..9c3fb47371
--- /dev/null
+++ b/cpukit/posix/src/mqueuerecvsupp.c
@@ -0,0 +1,128 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*
+ * _POSIX_Message_queue_Receive_support
+ *
+ * NOTE: XXX Document how size, priority, length, and the buffer go
+ * through the layers.
+ */
+
+ssize_t _POSIX_Message_queue_Receive_support(
+ mqd_t mqdes,
+ char *msg_ptr,
+ size_t msg_len,
+ unsigned int *msg_prio,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ Objects_Locations location;
+ size_t length_out;
+ bool do_wait;
+
+ the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( (the_mq_fd->oflag & O_ACCMODE) == O_WRONLY ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EBADF );
+ }
+
+ the_mq = the_mq_fd->Queue;
+
+ if ( msg_len < the_mq->Message_queue.maximum_message_size ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EMSGSIZE );
+ }
+
+ /*
+ * Now if something goes wrong, we return a "length" of -1
+ * to indicate an error.
+ */
+
+ length_out = -1;
+
+ /*
+ * A timed receive with a bad time will do a poll regardless.
+ */
+ if ( wait )
+ do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? false : true;
+ else
+ do_wait = wait;
+
+ /*
+ * Now perform the actual message receive
+ */
+ _CORE_message_queue_Seize(
+ &the_mq->Message_queue,
+ mqdes,
+ msg_ptr,
+ &length_out,
+ do_wait,
+ timeout
+ );
+
+ _Thread_Enable_dispatch();
+ *msg_prio =
+ _POSIX_Message_queue_Priority_from_core(_Thread_Executing->Wait.count);
+
+ if ( !_Thread_Executing->Wait.return_code )
+ return length_out;
+
+ rtems_set_errno_and_return_minus_one(
+ _POSIX_Message_queue_Translate_core_message_queue_return_code(
+ _Thread_Executing->Wait.return_code
+ )
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EBADF );
+}
diff --git a/cpukit/posix/src/mqueuesend.c b/cpukit/posix/src/mqueuesend.c
new file mode 100644
index 0000000000..312b04dac2
--- /dev/null
+++ b/cpukit/posix/src/mqueuesend.c
@@ -0,0 +1,64 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277
+ *
+ * NOTE: P1003.4b/D8, p. 45 adds mq_timedsend().
+ */
+
+int mq_send(
+ mqd_t mqdes,
+ const char *msg_ptr,
+ size_t msg_len,
+ unsigned int msg_prio
+)
+{
+ return _POSIX_Message_queue_Send_support(
+ mqdes,
+ msg_ptr,
+ msg_len,
+ msg_prio,
+ true,
+ THREAD_QUEUE_WAIT_FOREVER
+ );
+}
diff --git a/cpukit/posix/src/mqueuesendsupp.c b/cpukit/posix/src/mqueuesendsupp.c
new file mode 100644
index 0000000000..13e91756e8
--- /dev/null
+++ b/cpukit/posix/src/mqueuesendsupp.c
@@ -0,0 +1,133 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Send_support
+ */
+
+int _POSIX_Message_queue_Send_support(
+ mqd_t mqdes,
+ const char *msg_ptr,
+ size_t msg_len,
+ uint32_t msg_prio,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ POSIX_Message_queue_Control *the_mq;
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ Objects_Locations location;
+ CORE_message_queue_Status msg_status;
+ bool do_wait;
+
+ /*
+ * Validate the priority.
+ * XXX - Do not validate msg_prio is not less than 0.
+ */
+
+ if ( msg_prio > MQ_PRIO_MAX )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( (the_mq_fd->oflag & O_ACCMODE) == O_RDONLY ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EBADF );
+ }
+
+ the_mq = the_mq_fd->Queue;
+
+ /*
+ * A timed receive with a bad time will do a poll regardless.
+ */
+ if ( wait )
+ do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? false : true;
+ else
+ do_wait = wait;
+
+ /*
+ * Now perform the actual message receive
+ */
+ msg_status = _CORE_message_queue_Submit(
+ &the_mq->Message_queue,
+ (void *)msg_ptr,
+ msg_len,
+ mqdes, /* mqd_t is an object id */
+ NULL,
+ _POSIX_Message_queue_Priority_to_core( msg_prio ),
+ do_wait,
+ timeout /* no timeout */
+ );
+
+ _Thread_Enable_dispatch();
+
+ /*
+ * If we had to block, then this is where the task returns
+ * after it wakes up. The returned status is correct for
+ * non-blocking operations but if we blocked, then we need
+ * to look at the status in our TCB.
+ */
+
+ if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT )
+ msg_status = _Thread_Executing->Wait.return_code;
+
+ if ( !msg_status )
+ return msg_status;
+
+ rtems_set_errno_and_return_minus_one(
+ _POSIX_Message_queue_Translate_core_message_queue_return_code(
+ msg_status
+ )
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EBADF );
+}
diff --git a/cpukit/posix/src/mqueuesetattr.c b/cpukit/posix/src/mqueuesetattr.c
new file mode 100644
index 0000000000..683c3887b2
--- /dev/null
+++ b/cpukit/posix/src/mqueuesetattr.c
@@ -0,0 +1,90 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.7 Set Message Queue Attributes, P1003.1b-1993, p. 281
+ */
+
+int mq_setattr(
+ mqd_t mqdes,
+ const struct mq_attr *mqstat,
+ struct mq_attr *omqstat
+)
+{
+ POSIX_Message_queue_Control_fd *the_mq_fd;
+ CORE_message_queue_Control *the_core_mq;
+ Objects_Locations location;
+
+ if ( !mqstat )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ the_core_mq = &the_mq_fd->Queue->Message_queue;
+
+ /*
+ * Return the old values.
+ */
+
+ if ( omqstat ) {
+ omqstat->mq_flags = the_mq_fd->oflag;
+ omqstat->mq_msgsize = the_core_mq->maximum_message_size;
+ omqstat->mq_maxmsg = the_core_mq->maximum_pending_messages;
+ omqstat->mq_curmsgs = the_core_mq->number_of_pending_messages;
+ }
+
+ the_mq_fd->oflag = mqstat->mq_flags;
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EBADF );
+}
diff --git a/cpukit/posix/src/mqueuetimedreceive.c b/cpukit/posix/src/mqueuetimedreceive.c
new file mode 100644
index 0000000000..678d364cdf
--- /dev/null
+++ b/cpukit/posix/src/mqueuetimedreceive.c
@@ -0,0 +1,88 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279
+ *
+ * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive().
+ */
+
+ssize_t mq_timedreceive(
+ mqd_t mqdes,
+ char *msg_ptr,
+ size_t msg_len,
+ unsigned int *msg_prio,
+ const struct timespec *abstime
+)
+{
+ Watchdog_Interval ticks;
+ bool do_wait = true;
+ POSIX_Absolute_timeout_conversion_results_t status;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ *
+ * If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ * POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ * then we should not wait.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
+ do_wait = false;
+
+ return _POSIX_Message_queue_Receive_support(
+ mqdes,
+ msg_ptr,
+ msg_len,
+ msg_prio,
+ do_wait,
+ ticks
+ );
+}
diff --git a/cpukit/posix/src/mqueuetimedsend.c b/cpukit/posix/src/mqueuetimedsend.c
new file mode 100644
index 0000000000..9048e8f077
--- /dev/null
+++ b/cpukit/posix/src/mqueuetimedsend.c
@@ -0,0 +1,88 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277
+ *
+ * NOTE: P1003.4b/D8, p. 45 adds mq_timedsend().
+ */
+
+int mq_timedsend(
+ mqd_t mqdes,
+ const char *msg_ptr,
+ size_t msg_len,
+ unsigned int msg_prio,
+ const struct timespec *abstime
+)
+{
+ Watchdog_Interval ticks;
+ bool do_wait = true;
+ POSIX_Absolute_timeout_conversion_results_t status;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ *
+ * If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ * POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ * then we should not wait.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
+ do_wait = false;
+
+ return _POSIX_Message_queue_Send_support(
+ mqdes,
+ msg_ptr,
+ msg_len,
+ msg_prio,
+ do_wait,
+ ticks
+ );
+}
diff --git a/cpukit/posix/src/mqueuetranslatereturncode.c b/cpukit/posix/src/mqueuetranslatereturncode.c
new file mode 100644
index 0000000000..9fe57a9920
--- /dev/null
+++ b/cpukit/posix/src/mqueuetranslatereturncode.c
@@ -0,0 +1,62 @@
+/*
+ * POSIX Message Queue Error Translation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremsg.h>
+
+
+/*PAGE
+ *
+ * _POSIX_Message_queue_Translate_core_message_queue_return_code
+ *
+ * Input parameters:
+ * the_message_queue_status - message_queue status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static
+ int _POSIX_Message_queue_Return_codes[CORE_MESSAGE_QUEUE_STATUS_LAST + 1] = {
+ 0, /* CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL */
+ EMSGSIZE, /* CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE */
+ EAGAIN, /* CORE_MESSAGE_QUEUE_STATUS_TOO_MANY */
+ ENOMEM, /* CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED */
+ EAGAIN, /* CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT */
+ EBADF, /* CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED */
+ ETIMEDOUT, /* CORE_MESSAGE_QUEUE_STATUS_TIMEOUT */
+ ENOSYS /* CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT */
+};
+
+
+int _POSIX_Message_queue_Translate_core_message_queue_return_code(
+ uint32_t the_message_queue_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_message_queue_status > CORE_MESSAGE_QUEUE_STATUS_LAST )
+ return EINVAL;
+ #endif
+ return _POSIX_Message_queue_Return_codes[the_message_queue_status];
+}
diff --git a/cpukit/posix/src/mqueueunlink.c b/cpukit/posix/src/mqueueunlink.c
new file mode 100644
index 0000000000..67bb26928f
--- /dev/null
+++ b/cpukit/posix/src/mqueueunlink.c
@@ -0,0 +1,75 @@
+/*
+ * NOTE: The structure of the routines is identical to that of POSIX
+ * Message_queues to leave the option of having unnamed message
+ * queues at a future date. They are currently not part of the
+ * POSIX standard but unnamed message_queues are. This is also
+ * the reason for the apparently unnecessary tracking of
+ * the process_shared attribute. [In addition to the fact that
+ * it would be trivial to add pshared to the mq_attr structure
+ * and have process private message queues.]
+ *
+ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
+ * time.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <pthread.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276
+ */
+
+int mq_unlink(
+ const char *name
+)
+{
+ int status;
+ register POSIX_Message_queue_Control *the_mq;
+ Objects_Id the_mq_id;
+
+ _Thread_Disable_dispatch();
+
+ status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id );
+ if ( status != 0 ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( status );
+ }
+
+ the_mq = (POSIX_Message_queue_Control *) _Objects_Get_local_object(
+ &_POSIX_Message_queue_Information,
+ _Objects_Get_index( the_mq_id )
+ );
+
+ the_mq->linked = false;
+ _POSIX_Message_queue_Namespace_remove( the_mq );
+ _POSIX_Message_queue_Delete( the_mq );
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/mutex.c b/cpukit/posix/src/mutex.c
new file mode 100644
index 0000000000..6046b219f5
--- /dev/null
+++ b/cpukit/posix/src/mutex.c
@@ -0,0 +1,79 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_Mutex_Manager_initialization
+ *
+ * This routine initializes all mutex manager related data structures.
+ *
+ * Input parameters:
+ * maximum_mutexes - maximum configured mutexes
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Mutex_Manager_initialization(void)
+{
+ pthread_mutexattr_t *default_attr = &_POSIX_Mutex_Default_attributes;
+
+ /*
+ * Since the maximum priority is run-time configured, this
+ * structure cannot be initialized statically.
+ */
+ default_attr->is_initialized = true;
+ default_attr->process_shared = PTHREAD_PROCESS_PRIVATE;
+ default_attr->prio_ceiling = POSIX_SCHEDULER_MAXIMUM_PRIORITY;
+ default_attr->protocol = PTHREAD_PRIO_NONE;
+ default_attr->recursive = false;
+ #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
+ default_attr->type = PTHREAD_MUTEX_DEFAULT;
+ #endif
+
+ /*
+ * Initialize the POSIX mutex object class information structure.
+ */
+ _Objects_Initialize_information(
+ &_POSIX_Mutex_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_MUTEXES, /* object class */
+ Configuration_POSIX_API.maximum_mutexes,
+ /* maximum objects of this class */
+ sizeof( POSIX_Mutex_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/mutexattrdestroy.c b/cpukit/posix/src/mutexattrdestroy.c
new file mode 100644
index 0000000000..86e8c4597c
--- /dev/null
+++ b/cpukit/posix/src/mutexattrdestroy.c
@@ -0,0 +1,40 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81
+ */
+
+int pthread_mutexattr_destroy(
+ pthread_mutexattr_t *attr
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ attr->is_initialized = false;
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexattrgetprioceiling.c b/cpukit/posix/src/mutexattrgetprioceiling.c
new file mode 100644
index 0000000000..65944687aa
--- /dev/null
+++ b/cpukit/posix/src/mutexattrgetprioceiling.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128
+ */
+
+int pthread_mutexattr_getprioceiling(
+ const pthread_mutexattr_t *attr,
+ int *prioceiling
+)
+{
+ if ( !attr || !attr->is_initialized || !prioceiling )
+ return EINVAL;
+
+ *prioceiling = attr->prio_ceiling;
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexattrgetprotocol.c b/cpukit/posix/src/mutexattrgetprotocol.c
new file mode 100644
index 0000000000..6cd09979c8
--- /dev/null
+++ b/cpukit/posix/src/mutexattrgetprotocol.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128
+ */
+
+int pthread_mutexattr_getprotocol(
+ const pthread_mutexattr_t *attr,
+ int *protocol
+)
+{
+ if ( !attr || !attr->is_initialized || !protocol )
+ return EINVAL;
+
+ *protocol = attr->protocol;
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexattrgetpshared.c b/cpukit/posix/src/mutexattrgetpshared.c
new file mode 100644
index 0000000000..162de9fe4d
--- /dev/null
+++ b/cpukit/posix/src/mutexattrgetpshared.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81
+ */
+
+int pthread_mutexattr_getpshared(
+ const pthread_mutexattr_t *attr,
+ int *pshared
+)
+{
+ if ( !attr || !attr->is_initialized || !pshared )
+ return EINVAL;
+
+ *pshared = attr->process_shared;
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexattrgettype.c b/cpukit/posix/src/mutexattrgettype.c
new file mode 100644
index 0000000000..59b69de0d9
--- /dev/null
+++ b/cpukit/posix/src/mutexattrgettype.c
@@ -0,0 +1,45 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
+int pthread_mutexattr_gettype(
+ const pthread_mutexattr_t *attr,
+ int *type
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ if ( !type )
+ return EINVAL;
+
+ *type = attr->type;
+ return 0;
+}
+#endif
+
diff --git a/cpukit/posix/src/mutexattrinit.c b/cpukit/posix/src/mutexattrinit.c
new file mode 100644
index 0000000000..9f6988fab2
--- /dev/null
+++ b/cpukit/posix/src/mutexattrinit.c
@@ -0,0 +1,40 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81
+ */
+
+int pthread_mutexattr_init(
+ pthread_mutexattr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ *attr = _POSIX_Mutex_Default_attributes;
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexattrsetprioceiling.c b/cpukit/posix/src/mutexattrsetprioceiling.c
new file mode 100644
index 0000000000..aee51cc6e5
--- /dev/null
+++ b/cpukit/posix/src/mutexattrsetprioceiling.c
@@ -0,0 +1,44 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128
+ */
+
+int pthread_mutexattr_setprioceiling(
+ pthread_mutexattr_t *attr,
+ int prioceiling
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ if ( !_POSIX_Priority_Is_valid( prioceiling ) )
+ return EINVAL;
+
+ attr->prio_ceiling = prioceiling;
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexattrsetprotocol.c b/cpukit/posix/src/mutexattrsetprotocol.c
new file mode 100644
index 0000000000..54d0c4ab8d
--- /dev/null
+++ b/cpukit/posix/src/mutexattrsetprotocol.c
@@ -0,0 +1,49 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128
+ */
+
+int pthread_mutexattr_setprotocol(
+ pthread_mutexattr_t *attr,
+ int protocol
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( protocol ) {
+ case PTHREAD_PRIO_NONE:
+ case PTHREAD_PRIO_INHERIT:
+ case PTHREAD_PRIO_PROTECT:
+ attr->protocol = protocol;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/mutexattrsetpshared.c b/cpukit/posix/src/mutexattrsetpshared.c
new file mode 100644
index 0000000000..58dc5fd9d0
--- /dev/null
+++ b/cpukit/posix/src/mutexattrsetpshared.c
@@ -0,0 +1,48 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81
+ */
+
+int pthread_mutexattr_setpshared(
+ pthread_mutexattr_t *attr,
+ int pshared
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_SHARED:
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->process_shared = pshared;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/mutexattrsettype.c b/cpukit/posix/src/mutexattrsettype.c
new file mode 100644
index 0000000000..1cfb94d4d9
--- /dev/null
+++ b/cpukit/posix/src/mutexattrsettype.c
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
+int pthread_mutexattr_settype(
+ pthread_mutexattr_t *attr,
+ int type
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( type ) {
+ case PTHREAD_MUTEX_NORMAL:
+ case PTHREAD_MUTEX_RECURSIVE:
+ case PTHREAD_MUTEX_ERRORCHECK:
+ case PTHREAD_MUTEX_DEFAULT:
+ attr->type = type;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
+#endif
diff --git a/cpukit/posix/src/mutexdestroy.c b/cpukit/posix/src/mutexdestroy.c
new file mode 100644
index 0000000000..f8c01549c7
--- /dev/null
+++ b/cpukit/posix/src/mutexdestroy.c
@@ -0,0 +1,68 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87
+ */
+
+int pthread_mutex_destroy(
+ pthread_mutex_t *mutex
+)
+{
+ register POSIX_Mutex_Control *the_mutex;
+ Objects_Locations location;
+
+ the_mutex = _POSIX_Mutex_Get( mutex, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ /*
+ * XXX: There is an error for the mutex being locked
+ * or being in use by a condition variable.
+ */
+
+ if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object );
+
+ _CORE_mutex_Flush( &the_mutex->Mutex, NULL, EINVAL );
+
+ _POSIX_Mutex_Free( the_mutex );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/mutexget.c b/cpukit/posix/src/mutexget.c
new file mode 100644
index 0000000000..71e46766ba
--- /dev/null
+++ b/cpukit/posix/src/mutexget.c
@@ -0,0 +1,91 @@
+/*
+ * Convert POSIX Mutex ID to local object pointer
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+
+
+/*
+ * _POSIX_Mutex_Get_support
+ *
+ * NOTE: The support macro makes it possible for both to use exactly
+ * the same code to check for NULL id pointer and
+ * PTHREAD_MUTEX_INITIALIZER without adding overhead.
+ */
+
+#define ___POSIX_Mutex_Get_support_error_check( _id, _location ) \
+ do { \
+ if ( !_id ) { \
+ *_location = OBJECTS_ERROR; \
+ return (POSIX_Mutex_Control *) 0; \
+ } \
+ } while (0)
+
+#define ___POSIX_Mutex_Get_support_auto_initialization( _id, _location ) \
+ do { \
+ int _status; \
+ \
+ if ( *_id == PTHREAD_MUTEX_INITIALIZER ) { \
+ /* \
+ * Do an "auto-create" here. \
+ */ \
+ \
+ _status = pthread_mutex_init( (pthread_mutex_t *)_id, 0 ); \
+ if ( _status ) { \
+ *_location = OBJECTS_ERROR; \
+ return (POSIX_Mutex_Control *) 0; \
+ } \
+ } \
+ } while (0)
+
+POSIX_Mutex_Control *_POSIX_Mutex_Get (
+ pthread_mutex_t *mutex,
+ Objects_Locations *location
+)
+{
+ ___POSIX_Mutex_Get_support_error_check( mutex, location );
+
+ ___POSIX_Mutex_Get_support_auto_initialization( mutex, location );
+
+ return (POSIX_Mutex_Control *)
+ _Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
+}
+
+POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable (
+ pthread_mutex_t *mutex,
+ Objects_Locations *location,
+ ISR_Level *level
+)
+{
+ ___POSIX_Mutex_Get_support_error_check( mutex, location );
+
+ ___POSIX_Mutex_Get_support_auto_initialization( mutex, location );
+
+ return (POSIX_Mutex_Control *) _Objects_Get_isr_disable(
+ &_POSIX_Mutex_Information,
+ (Objects_Id) *mutex,
+ location,
+ level
+ );
+}
diff --git a/cpukit/posix/src/mutexgetprioceiling.c b/cpukit/posix/src/mutexgetprioceiling.c
new file mode 100644
index 0000000000..58537d9242
--- /dev/null
+++ b/cpukit/posix/src/mutexgetprioceiling.c
@@ -0,0 +1,63 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131
+ */
+
+int pthread_mutex_getprioceiling(
+ pthread_mutex_t *mutex,
+ int *prioceiling
+)
+{
+ register POSIX_Mutex_Control *the_mutex;
+ Objects_Locations location;
+
+ if ( !prioceiling )
+ return EINVAL;
+
+ the_mutex = _POSIX_Mutex_Get( mutex, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ *prioceiling = _POSIX_Priority_From_core(
+ the_mutex->Mutex.Attributes.priority_ceiling
+ );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
new file mode 100644
index 0000000000..d6102d44a1
--- /dev/null
+++ b/cpukit/posix/src/mutexinit.c
@@ -0,0 +1,188 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87
+ *
+ * NOTE: XXX Could be optimized so all the attribute error checking
+ * is not performed when attr is NULL.
+ */
+
+int pthread_mutex_init(
+ pthread_mutex_t *mutex,
+ const pthread_mutexattr_t *attr
+)
+{
+ POSIX_Mutex_Control *the_mutex;
+ CORE_mutex_Attributes *the_mutex_attr;
+ const pthread_mutexattr_t *the_attr;
+ CORE_mutex_Disciplines the_discipline;
+
+ if ( attr ) the_attr = attr;
+ else the_attr = &_POSIX_Mutex_Default_attributes;
+
+ /* Check for NULL mutex */
+ if ( !mutex )
+ return EINVAL;
+
+ /*
+ * This code should eventually be removed.
+ *
+ * Although the POSIX specification says:
+ *
+ * "Attempting to initialize an already initialized mutex results
+ * in undefined behavior."
+ *
+ * Trying to keep the caller from doing the create when *mutex
+ * is actually a valid ID causes grief. All it takes is the wrong
+ * value in an uninitialized variable to make this fail. As best
+ * I can tell, RTEMS was the only pthread implementation to choose
+ * this option for "undefined behavior" and doing so has created
+ * portability problems. In particular, Rosimildo DaSilva
+ * <rdasilva@connecttel.com> saw seemingly random failures in the
+ * RTEMS port of omniORB2 when this code was enabled.
+ *
+ * Joel Sherrill <joel@OARcorp.com> 14 May 1999
+ * NOTE: Be careful to avoid infinite recursion on call to this
+ * routine in _POSIX_Mutex_Get.
+ */
+ #if 0
+ {
+ POSIX_Mutex_Control *mutex_in_use;
+ Objects_Locations location;
+
+ if ( *mutex != PTHREAD_MUTEX_INITIALIZER ) {
+
+ /* EBUSY if *mutex is a valid id */
+
+ mutex_in_use = _POSIX_Mutex_Get( mutex, &location );
+ switch ( location ) {
+ case OBJECTS_LOCAL:
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ #if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ #endif
+ case OBJECTS_ERROR:
+ break;
+ }
+ }
+ }
+ #endif
+
+ if ( !the_attr->is_initialized )
+ return EINVAL;
+
+ /*
+ * We only support process private mutexes.
+ */
+ if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED )
+ return ENOSYS;
+
+ if ( the_attr->process_shared != PTHREAD_PROCESS_PRIVATE )
+ return EINVAL;
+
+ /*
+ * Determine the discipline of the mutex
+ */
+ switch ( the_attr->protocol ) {
+ case PTHREAD_PRIO_NONE:
+ the_discipline = CORE_MUTEX_DISCIPLINES_FIFO;
+ break;
+ case PTHREAD_PRIO_INHERIT:
+ the_discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
+ break;
+ case PTHREAD_PRIO_PROTECT:
+ the_discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ /*
+ * Validate the priority ceiling field -- should always be valid.
+ */
+ if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) )
+ return EINVAL;
+
+#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
+ /*
+ * Validate the mutex type and set appropriate SuperCore mutex
+ * attributes.
+ */
+ switch ( the_attr->type ) {
+ case PTHREAD_MUTEX_NORMAL:
+ case PTHREAD_MUTEX_RECURSIVE:
+ case PTHREAD_MUTEX_ERRORCHECK:
+ case PTHREAD_MUTEX_DEFAULT:
+ break;
+
+ default:
+ return EINVAL;
+ }
+#endif
+
+ /*
+ * Enter a dispatching critical section and begin to do the real work.
+ */
+ _Thread_Disable_dispatch();
+
+ the_mutex = _POSIX_Mutex_Allocate();
+
+ if ( !the_mutex ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ the_mutex->process_shared = the_attr->process_shared;
+
+ the_mutex_attr = &the_mutex->Mutex.Attributes;
+
+ if ( the_attr->recursive )
+ the_mutex_attr->lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
+ else
+ the_mutex_attr->lock_nesting_behavior = CORE_MUTEX_NESTING_IS_ERROR;
+ the_mutex_attr->only_owner_release = true;
+ the_mutex_attr->priority_ceiling =
+ _POSIX_Priority_To_core( the_attr->prio_ceiling );
+ the_mutex_attr->discipline = the_discipline;
+
+ /*
+ * Must be initialized to unlocked.
+ */
+ _CORE_mutex_Initialize(
+ &the_mutex->Mutex,
+ the_mutex_attr,
+ CORE_MUTEX_UNLOCKED
+ );
+
+ _Objects_Open_u32( &_POSIX_Mutex_Information, &the_mutex->Object, 0 );
+
+ *mutex = the_mutex->Object.id;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/mutexlock.c b/cpukit/posix/src/mutexlock.c
new file mode 100644
index 0000000000..85d1bd623b
--- /dev/null
+++ b/cpukit/posix/src/mutexlock.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
+ *
+ * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29
+ */
+
+int pthread_mutex_lock(
+ pthread_mutex_t *mutex
+)
+{
+ return _POSIX_Mutex_Lock_support( mutex, true, THREAD_QUEUE_WAIT_FOREVER );
+}
diff --git a/cpukit/posix/src/mutexlocksupp.c b/cpukit/posix/src/mutexlocksupp.c
new file mode 100644
index 0000000000..43c80d054e
--- /dev/null
+++ b/cpukit/posix/src/mutexlocksupp.c
@@ -0,0 +1,70 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_Mutex_Lock_support
+ *
+ * A support routine which implements guts of the blocking, non-blocking, and
+ * timed wait version of mutex lock.
+ */
+
+int _POSIX_Mutex_Lock_support(
+ pthread_mutex_t *mutex,
+ bool blocking,
+ Watchdog_Interval timeout
+)
+{
+ register POSIX_Mutex_Control *the_mutex;
+ Objects_Locations location;
+ ISR_Level level;
+
+ the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &location, &level );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _CORE_mutex_Seize(
+ &the_mutex->Mutex,
+ the_mutex->Object.id,
+ blocking,
+ timeout,
+ level
+ );
+ return _POSIX_Mutex_Translate_core_mutex_return_code(
+ (CORE_mutex_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/mutexsetprioceiling.c b/cpukit/posix/src/mutexsetprioceiling.c
new file mode 100644
index 0000000000..f132b38e04
--- /dev/null
+++ b/cpukit/posix/src/mutexsetprioceiling.c
@@ -0,0 +1,91 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131
+ */
+
+int pthread_mutex_setprioceiling(
+ pthread_mutex_t *mutex,
+ int prioceiling,
+ int *old_ceiling
+)
+{
+ register POSIX_Mutex_Control *the_mutex;
+ Objects_Locations location;
+ Priority_Control the_priority;
+
+ if ( !old_ceiling )
+ return EINVAL;
+
+ if ( !_POSIX_Priority_Is_valid( prioceiling ) )
+ return EINVAL;
+
+ the_priority = _POSIX_Priority_To_core( prioceiling );
+
+ /*
+ * Must acquire the mutex before we can change it's ceiling.
+ * POSIX says block until we acquire it.
+ */
+ (void) pthread_mutex_lock( mutex );
+
+ /*
+ * Do not worry about the return code from this. The Get operation
+ * will also fail if it is a bad id or was deleted between the two
+ * operations.
+ *
+ * NOTE: This makes it easier to get 100% binary coverage since the
+ * bad Id case is handled by the switch.
+ */
+ the_mutex = _POSIX_Mutex_Get( mutex, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ *old_ceiling = _POSIX_Priority_From_core(
+ the_mutex->Mutex.Attributes.priority_ceiling
+ );
+ the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
+ /*
+ * We are required to unlock the mutex before we return.
+ */
+ _CORE_mutex_Surrender(
+ &the_mutex->Mutex,
+ the_mutex->Object.id,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* impossible to get here */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/mutextimedlock.c b/cpukit/posix/src/mutextimedlock.c
new file mode 100644
index 0000000000..7773d84af6
--- /dev/null
+++ b/cpukit/posix/src/mutextimedlock.c
@@ -0,0 +1,83 @@
+/*
+ * Mutex Timed Lock
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
+ *
+ * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29
+ */
+
+int pthread_mutex_timedlock(
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime
+)
+{
+ Watchdog_Interval ticks;
+ bool do_wait = true;
+ POSIX_Absolute_timeout_conversion_results_t status;
+ int lock_status;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ *
+ * If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ * POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ * then we should not wait.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
+ do_wait = false;
+
+ lock_status = _POSIX_Mutex_Lock_support( mutex, do_wait, ticks );
+ /*
+ * This service only gives us the option to block. We used a polling
+ * attempt to lock if the abstime was not in the future. If we did
+ * not obtain the mutex, then not look at the status immediately,
+ * make sure the right reason is returned.
+ */
+ if ( !do_wait && (lock_status == EBUSY) ) {
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
+ return EINVAL;
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
+ status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
+ return ETIMEDOUT;
+ }
+
+ return lock_status;
+}
diff --git a/cpukit/posix/src/mutextranslatereturncode.c b/cpukit/posix/src/mutextranslatereturncode.c
new file mode 100644
index 0000000000..48b9a9a199
--- /dev/null
+++ b/cpukit/posix/src/mutextranslatereturncode.c
@@ -0,0 +1,61 @@
+/*
+ * POSIX Mutex Error Translation
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+
+/*
+ * _POSIX_Mutex_Translate_core_mutex_return_code
+ *
+ * Input parameters:
+ * the_mutex_status - mutex status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1] = {
+ 0, /* CORE_MUTEX_STATUS_SUCCESSFUL */
+ EBUSY, /* CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT */
+ EDEADLK, /* CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED */
+ EPERM, /* CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE */
+ EINVAL, /* CORE_MUTEX_WAS_DELETED */
+ ETIMEDOUT, /* CORE_MUTEX_TIMEOUT */
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ EDEADLK, /* CORE_MUTEX_RELEASE_NOT_ORDER */
+#endif
+ EINVAL /* CORE_MUTEX_STATUS_CEILING_VIOLATED */
+};
+
+
+int _POSIX_Mutex_Translate_core_mutex_return_code(
+ CORE_mutex_Status the_mutex_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_mutex_status > CORE_MUTEX_STATUS_LAST )
+ return EINVAL;
+ #endif
+ return _POSIX_Mutex_Return_codes[the_mutex_status];
+}
diff --git a/cpukit/posix/src/mutextrylock.c b/cpukit/posix/src/mutextrylock.c
new file mode 100644
index 0000000000..d44f216614
--- /dev/null
+++ b/cpukit/posix/src/mutextrylock.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
+ *
+ * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29
+ */
+
+int pthread_mutex_trylock(
+ pthread_mutex_t *mutex
+)
+{
+ return _POSIX_Mutex_Lock_support( mutex, false, THREAD_QUEUE_WAIT_FOREVER );
+}
diff --git a/cpukit/posix/src/mutexunlock.c b/cpukit/posix/src/mutexunlock.c
new file mode 100644
index 0000000000..cdcd03f50c
--- /dev/null
+++ b/cpukit/posix/src/mutexunlock.c
@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
+ *
+ * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29
+ */
+
+int pthread_mutex_unlock(
+ pthread_mutex_t *mutex
+)
+{
+ register POSIX_Mutex_Control *the_mutex;
+ Objects_Locations location;
+ CORE_mutex_Status status;
+
+ the_mutex = _POSIX_Mutex_Get( mutex, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_mutex_Surrender(
+ &the_mutex->Mutex,
+ the_mutex->Object.id,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+ return _POSIX_Mutex_Translate_core_mutex_return_code( status );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/nanosleep.c b/cpukit/posix/src/nanosleep.c
new file mode 100644
index 0000000000..dc81a378d5
--- /dev/null
+++ b/cpukit/posix/src/nanosleep.c
@@ -0,0 +1,107 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/seterr.h>
+#include <rtems/score/timespec.h>
+
+/*PAGE
+ *
+ * 14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269
+ */
+
+int nanosleep(
+ const struct timespec *rqtp,
+ struct timespec *rmtp
+)
+{
+ Watchdog_Interval ticks;
+
+
+ /*
+ * Return EINVAL if the delay interval is negative.
+ *
+ * NOTE: This behavior is beyond the POSIX specification.
+ * FSU and GNU/Linux pthreads shares this behavior.
+ */
+ if ( !_Timespec_Is_valid( rqtp ) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ ticks = _Timespec_To_ticks( rqtp );
+
+ /*
+ * A nanosleep for zero time is implemented as a yield.
+ * This behavior is also beyond the POSIX specification but is
+ * consistent with the RTEMS API and yields desirable behavior.
+ */
+
+ if ( !ticks ) {
+ _Thread_Disable_dispatch();
+ _Scheduler_Yield();
+ _Thread_Enable_dispatch();
+ if ( rmtp ) {
+ rmtp->tv_sec = 0;
+ rmtp->tv_nsec = 0;
+ }
+ return 0;
+ }
+
+ /*
+ * Block for the desired amount of time
+ */
+ _Thread_Disable_dispatch();
+ _Thread_Set_state(
+ _Thread_Executing,
+ STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL
+ );
+ _Watchdog_Initialize(
+ &_Thread_Executing->Timer,
+ _Thread_Delay_ended,
+ _Thread_Executing->Object.id,
+ NULL
+ );
+ _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks );
+ _Thread_Enable_dispatch();
+
+ /* calculate time remaining */
+
+ if ( rmtp ) {
+ ticks -=
+ _Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time;
+
+ _Timespec_From_ticks( ticks, rmtp );
+
+ /*
+ * Only when POSIX is enabled, can a sleep be interrupted.
+ */
+ #if defined(RTEMS_POSIX_API)
+ /*
+ * If there is time remaining, then we were interrupted by a signal.
+ */
+ if ( ticks )
+ rtems_set_errno_and_return_minus_one( EINTR );
+ #endif
+ }
+
+ return 0;
+}
diff --git a/cpukit/posix/src/pause.c b/cpukit/posix/src/pause.c
new file mode 100644
index 0000000000..e4a8782bc4
--- /dev/null
+++ b/cpukit/posix/src/pause.c
@@ -0,0 +1,40 @@
+/*
+ * 3.4.2 Suspend Process Execution, P1003.1b-1993, p. 81
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+/*
+ * 3.4.2 Suspend Process Execution, P1003.1b-1993, p. 81
+ */
+
+int pause( void )
+{
+ sigset_t all_signals;
+ int status;
+
+ (void) sigfillset( &all_signals );
+
+ status = sigtimedwait( &all_signals, NULL, NULL );
+
+ return status;
+}
diff --git a/cpukit/posix/src/pbarrier.c b/cpukit/posix/src/pbarrier.c
new file mode 100644
index 0000000000..d131000e89
--- /dev/null
+++ b/cpukit/posix/src/pbarrier.c
@@ -0,0 +1,57 @@
+/*
+ * Barrier Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Barrier Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a barrier
+ * + get an ID of a barrier
+ * + delete a barrier
+ * + acquire a barrier
+ * + release a barrier
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/posix/barrier.h>
+
+/**
+ * @brief _POSIX_Barrier_Manager_initialization
+ */
+
+void _POSIX_Barrier_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Barrier_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_BARRIERS, /* object class */
+ Configuration_POSIX_API.maximum_barriers,
+ /* maximum objects of this class */
+ sizeof( POSIX_Barrier_Control ),/* size of this object's control block */
+ true, /* true if the name is a string */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/pbarrierdestroy.c b/cpukit/posix/src/pbarrierdestroy.c
new file mode 100644
index 0000000000..0caf8a1586
--- /dev/null
+++ b/cpukit/posix/src/pbarrierdestroy.c
@@ -0,0 +1,73 @@
+/*
+ * POSIX Barrier Manager -- Destroy a Barrier
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * pthread_barrier_destroy
+ *
+ * This directive allows a thread to delete a barrier specified by
+ * the barrier id. The barrier is freed back to the inactive
+ * barrier chain.
+ *
+ * Input parameters:
+ * barrier - barrier id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_barrier_destroy(
+ pthread_barrier_t *barrier
+)
+{
+ POSIX_Barrier_Control *the_barrier = NULL;
+ Objects_Locations location;
+
+ if ( !barrier )
+ return EINVAL;
+
+ the_barrier = _POSIX_Barrier_Get( barrier, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object );
+
+ _POSIX_Barrier_Free( the_barrier );
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c
new file mode 100644
index 0000000000..a2a77f83a5
--- /dev/null
+++ b/cpukit/posix/src/pbarrierinit.c
@@ -0,0 +1,116 @@
+/*
+ * POSIX Barrier Manager -- Initialize a Barrier Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * pthread_barrier_init
+ *
+ * This directive creates a barrier. A barrier id is returned.
+ *
+ * Input parameters:
+ * barrier - pointer to barrier id
+ * attr - barrier attributes
+ * count - number of threads before automatic release
+ *
+ * Output parameters:
+ * barrier - barrier id
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_barrier_init(
+ pthread_barrier_t *barrier,
+ const pthread_barrierattr_t *attr,
+ unsigned int count
+)
+{
+ POSIX_Barrier_Control *the_barrier;
+ CORE_barrier_Attributes the_attributes;
+ pthread_barrierattr_t my_attr;
+ const pthread_barrierattr_t *the_attr;
+
+ /*
+ * Error check parameters
+ */
+ if ( !barrier )
+ return EINVAL;
+
+ if ( count == 0 )
+ return EINVAL;
+
+ /*
+ * If the user passed in NULL, use the default attributes
+ */
+ if ( attr ) {
+ the_attr = attr;
+ } else {
+ (void) pthread_barrierattr_init( &my_attr );
+ the_attr = &my_attr;
+ }
+
+ /*
+ * Now start error checking the attributes that we are going to use
+ */
+ if ( !the_attr->is_initialized )
+ return EINVAL;
+
+ switch ( the_attr->process_shared ) {
+ case PTHREAD_PROCESS_PRIVATE: /* only supported values */
+ break;
+ case PTHREAD_PROCESS_SHARED:
+ default:
+ return EINVAL;
+ }
+
+ /*
+ * Convert from POSIX attributes to Core Barrier attributes
+ */
+ the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
+ the_attributes.maximum_count = count;
+
+ /*
+ * Enter dispatching critical section to allocate and initialize barrier
+ */
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_barrier = _POSIX_Barrier_Allocate();
+
+ if ( !the_barrier ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
+
+ _Objects_Open_u32(
+ &_POSIX_Barrier_Information,
+ &the_barrier->Object,
+ 0
+ );
+
+ /*
+ * Exit the critical section and return the user an operational barrier
+ */
+ *barrier = the_barrier->Object.id;
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/pbarriertranslatereturncode.c b/cpukit/posix/src/pbarriertranslatereturncode.c
new file mode 100644
index 0000000000..0351fc5a65
--- /dev/null
+++ b/cpukit/posix/src/pbarriertranslatereturncode.c
@@ -0,0 +1,56 @@
+/*
+ * Barrier Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * _POSIX_Barrier_Translate_core_barrier_return_code
+ *
+ * Input parameters:
+ * the_barrier_status - barrier status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static int _POSIX_Barrier_Return_codes[CORE_BARRIER_STATUS_LAST + 1] = {
+ 0, /* CORE_BARRIER_STATUS_SUCCESSFUL */
+ PTHREAD_BARRIER_SERIAL_THREAD,
+ /* CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED */
+ -1, /* CORE_BARRIER_WAS_DELETED */
+ 0 /* CORE_BARRIER_TIMEOUT */
+};
+
+
+int _POSIX_Barrier_Translate_core_barrier_return_code(
+ CORE_barrier_Status the_barrier_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_barrier_status > CORE_BARRIER_STATUS_LAST )
+ return EINVAL;
+ #endif
+ return _POSIX_Barrier_Return_codes[the_barrier_status];
+}
diff --git a/cpukit/posix/src/pbarrierwait.c b/cpukit/posix/src/pbarrierwait.c
new file mode 100644
index 0000000000..71533b65b1
--- /dev/null
+++ b/cpukit/posix/src/pbarrierwait.c
@@ -0,0 +1,71 @@
+/*
+ * POSIX Barrier Manager -- Wait at a Barrier
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * pthread_barrier_wait
+ *
+ * This directive allows a thread to wait at a barrier.
+ *
+ * Input parameters:
+ * barrier - barrier id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * PTHREAD_BARRIER_SERIAL_THREAD - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_barrier_wait(
+ pthread_barrier_t *barrier
+)
+{
+ POSIX_Barrier_Control *the_barrier = NULL;
+ Objects_Locations location;
+
+ if ( !barrier )
+ return EINVAL;
+
+ the_barrier = _POSIX_Barrier_Get( barrier, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _CORE_barrier_Wait(
+ &the_barrier->Barrier,
+ the_barrier->Object.id,
+ true,
+ 0,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+ return _POSIX_Barrier_Translate_core_barrier_return_code(
+ _Thread_Executing->Wait.return_code );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/posixtimespecabsolutetimeout.c b/cpukit/posix/src/posixtimespecabsolutetimeout.c
new file mode 100644
index 0000000000..27d5db5abe
--- /dev/null
+++ b/cpukit/posix/src/posixtimespecabsolutetimeout.c
@@ -0,0 +1,88 @@
+/*
+ * Convert abstime timeout to ticks
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*
+ * The abstime is a walltime. We turn it into an interval.
+ */
+POSIX_Absolute_timeout_conversion_results_t _POSIX_Absolute_timeout_to_ticks(
+ const struct timespec *abstime,
+ Watchdog_Interval *ticks_out
+)
+{
+ struct timespec current_time;
+ struct timespec difference;
+
+
+ /*
+ * Make sure there is always a value returned.
+ */
+ *ticks_out = 0;
+
+ /*
+ * Is the absolute time even valid?
+ */
+ if ( !_Timespec_Is_valid(abstime) )
+ return POSIX_ABSOLUTE_TIMEOUT_INVALID;
+
+ /*
+ * Is the absolute time in the past?
+ */
+ _TOD_Get( &current_time );
+
+ if ( _Timespec_Less_than( abstime, &current_time ) )
+ return POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST;
+
+ /*
+ * How long until the requested absolute time?
+ */
+ _Timespec_Subtract( &current_time, abstime, &difference );
+
+ /*
+ * Internally the SuperCore uses ticks, so convert to them.
+ */
+ *ticks_out = _Timespec_To_ticks( &difference );
+
+ /*
+ * If the difference was 0, then the future is now. It is so bright
+ * we better wear shades.
+ */
+ if ( !*ticks_out )
+ return POSIX_ABSOLUTE_TIMEOUT_IS_NOW;
+
+ /*
+ * This is the case we were expecting and it took this long to
+ * get here.
+ */
+ return POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE;
+}
+
diff --git a/cpukit/posix/src/prwlock.c b/cpukit/posix/src/prwlock.c
new file mode 100644
index 0000000000..9c3fd707d8
--- /dev/null
+++ b/cpukit/posix/src/prwlock.c
@@ -0,0 +1,45 @@
+/*
+ * RWLock Manager -- Initialization
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/posix/rwlock.h>
+
+/**
+ * @brief _POSIX_RWLock_Manager_initialization
+ */
+
+void _POSIX_RWLock_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_RWLock_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_SPINLOCKS, /* object class */
+ Configuration_POSIX_API.maximum_rwlocks,
+ /* maximum objects of this class */
+ sizeof( POSIX_RWLock_Control ), /* size of this object's control block */
+ true, /* true if the name is a string */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c
new file mode 100644
index 0000000000..8b32517c37
--- /dev/null
+++ b/cpukit/posix/src/prwlockdestroy.c
@@ -0,0 +1,80 @@
+/*
+ * POSIX RWLock Manager -- Destroy a RWLock
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_destroy
+ *
+ * This directive allows a thread to delete a rwlock specified by
+ * the rwlock id. The rwlock is freed back to the inactive
+ * rwlock chain.
+ *
+ * Input parameters:
+ * rwlock - rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_destroy(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock = NULL;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ /*
+ * If there is at least one thread waiting, then do not delete it.
+ */
+ if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ /*
+ * POSIX doesn't require behavior when it is locked.
+ */
+
+ _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
+
+ _POSIX_RWLock_Free( the_rwlock );
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
new file mode 100644
index 0000000000..c79b260b50
--- /dev/null
+++ b/cpukit/posix/src/prwlockinit.c
@@ -0,0 +1,110 @@
+/*
+ * POSIX RWLock Manager -- Destroy a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_init
+ *
+ * This directive creates a rwlock. A rwlock id is returned.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ * attr - rwlock attributes
+ *
+ * Output parameters:
+ * rwlock - rwlock id
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_init(
+ pthread_rwlock_t *rwlock,
+ const pthread_rwlockattr_t *attr
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ CORE_RWLock_Attributes the_attributes;
+ pthread_rwlockattr_t default_attr;
+ const pthread_rwlockattr_t *the_attr;
+
+ /*
+ * Error check parameters
+ */
+ if ( !rwlock )
+ return EINVAL;
+
+ /*
+ * If the user passed in NULL, use the default attributes
+ */
+ if ( attr ) {
+ the_attr = attr;
+ } else {
+ (void) pthread_rwlockattr_init( &default_attr );
+ the_attr = &default_attr;
+ }
+
+ /*
+ * Now start error checking the attributes that we are going to use
+ */
+ if ( !the_attr->is_initialized )
+ return EINVAL;
+
+ switch ( the_attr->process_shared ) {
+ case PTHREAD_PROCESS_PRIVATE: /* only supported values */
+ break;
+ case PTHREAD_PROCESS_SHARED:
+ default:
+ return EINVAL;
+ }
+
+ /*
+ * Convert from POSIX attributes to Core RWLock attributes
+ *
+ * NOTE: Currently there are no core rwlock attributes
+ */
+ _CORE_RWLock_Initialize_attributes( &the_attributes );
+
+ /*
+ * Enter dispatching critical section to allocate and initialize RWLock
+ */
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_rwlock = _POSIX_RWLock_Allocate();
+
+ if ( !the_rwlock ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ _CORE_RWLock_Initialize( &the_rwlock->RWLock, &the_attributes );
+
+ _Objects_Open_u32(
+ &_POSIX_RWLock_Information,
+ &the_rwlock->Object,
+ 0
+ );
+
+ *rwlock = the_rwlock->Object.id;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/prwlockrdlock.c b/cpukit/posix/src/prwlockrdlock.c
new file mode 100644
index 0000000000..fe9d6196d9
--- /dev/null
+++ b/cpukit/posix/src/prwlockrdlock.c
@@ -0,0 +1,73 @@
+/*
+ * POSIX RWLock Manager -- Obtain a Read Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_rdlock
+ *
+ * This directive attempts to obtain a read only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_rdlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_reading(
+ &the_rwlock->RWLock,
+ *rwlock,
+ true, /* we are willing to wait forever */
+ 0,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlocktimedrdlock.c b/cpukit/posix/src/prwlocktimedrdlock.c
new file mode 100644
index 0000000000..d6df7815a8
--- /dev/null
+++ b/cpukit/posix/src/prwlocktimedrdlock.c
@@ -0,0 +1,105 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+#include <rtems/posix/time.h>
+
+/*
+ * pthread_rwlock_timedrdlock
+ *
+ * This directive attempts to obtain a read only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_timedrdlock(
+ pthread_rwlock_t *rwlock,
+ const struct timespec *abstime
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ Watchdog_Interval ticks;
+ bool do_wait = true;
+ POSIX_Absolute_timeout_conversion_results_t status;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ *
+ * If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ * POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ * then we should not wait.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
+ do_wait = false;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_reading(
+ &the_rwlock->RWLock,
+ *rwlock,
+ do_wait,
+ ticks,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ if ( !do_wait ) {
+ if ( _Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) {
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
+ return EINVAL;
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
+ status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
+ return ETIMEDOUT;
+ }
+ }
+
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlocktimedwrlock.c b/cpukit/posix/src/prwlocktimedwrlock.c
new file mode 100644
index 0000000000..d34ee69489
--- /dev/null
+++ b/cpukit/posix/src/prwlocktimedwrlock.c
@@ -0,0 +1,104 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+#include <rtems/posix/time.h>
+
+/*
+ * pthread_rwlock_timedwrlock
+ *
+ * This directive attempts to obtain a write only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_timedwrlock(
+ pthread_rwlock_t *rwlock,
+ const struct timespec *abstime
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ Watchdog_Interval ticks;
+ bool do_wait = true;
+ POSIX_Absolute_timeout_conversion_results_t status;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ *
+ * If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ * POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ * then we should not wait.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
+ do_wait = false;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_writing(
+ &the_rwlock->RWLock,
+ *rwlock,
+ do_wait,
+ ticks,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ if ( !do_wait &&
+ (_Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
+ return EINVAL;
+ if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
+ status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
+ return ETIMEDOUT;
+ }
+
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlocktranslatereturncode.c b/cpukit/posix/src/prwlocktranslatereturncode.c
new file mode 100644
index 0000000000..3378d577b2
--- /dev/null
+++ b/cpukit/posix/src/prwlocktranslatereturncode.c
@@ -0,0 +1,55 @@
+/*
+ * RWLock Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * _POSIX_RWLock_Translate_core_rwlock_return_code
+ *
+ * Input parameters:
+ * the_rwlock_status - rwlock status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static int _POSIX_RWLock_Return_codes[CORE_RWLOCK_STATUS_LAST + 1] = {
+ 0, /* CORE_RWLOCK_SUCCESSFUL */
+ EINVAL, /* CORE_RWLOCK_DELETED */
+ EBUSY, /* CORE_RWLOCK_UNAVAILABLE */
+ ETIMEDOUT, /* CORE_RWLOCK_TIMEOUT */
+};
+
+
+int _POSIX_RWLock_Translate_core_RWLock_return_code(
+ CORE_RWLock_Status the_rwlock_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_rwlock_status > CORE_RWLOCK_STATUS_LAST )
+ return EINVAL;
+ #endif
+ return _POSIX_RWLock_Return_codes[the_rwlock_status];
+}
diff --git a/cpukit/posix/src/prwlocktryrdlock.c b/cpukit/posix/src/prwlocktryrdlock.c
new file mode 100644
index 0000000000..f07edf5f4d
--- /dev/null
+++ b/cpukit/posix/src/prwlocktryrdlock.c
@@ -0,0 +1,74 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_tryrdlock
+ *
+ * This directive attempts to obtain a read only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_tryrdlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_reading(
+ &the_rwlock->RWLock,
+ *rwlock,
+ false, /* do not wait for the rwlock */
+ 0,
+ NULL
+ );
+
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlocktrywrlock.c b/cpukit/posix/src/prwlocktrywrlock.c
new file mode 100644
index 0000000000..326e643910
--- /dev/null
+++ b/cpukit/posix/src/prwlocktrywrlock.c
@@ -0,0 +1,73 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_trywrlock
+ *
+ * This directive attempts to obtain a Write only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_trywrlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_writing(
+ &the_rwlock->RWLock,
+ *rwlock,
+ false, /* we are not willing to wait */
+ 0,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlockunlock.c b/cpukit/posix/src/prwlockunlock.c
new file mode 100644
index 0000000000..665ee1fb34
--- /dev/null
+++ b/cpukit/posix/src/prwlockunlock.c
@@ -0,0 +1,64 @@
+/*
+ * POSIX RWLock Manager -- Release a lock held on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_unlock
+ *
+ * This directive attempts to release a lock on an RWLock.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_unlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ CORE_RWLock_Status status;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_RWLock_Release( &the_rwlock->RWLock );
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code( status );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/prwlockwrlock.c b/cpukit/posix/src/prwlockwrlock.c
new file mode 100644
index 0000000000..61d5facbef
--- /dev/null
+++ b/cpukit/posix/src/prwlockwrlock.c
@@ -0,0 +1,73 @@
+/*
+ * POSIX RWLock Manager -- Obtain a Write Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_wrlock
+ *
+ * This directive attempts to obtain a write only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_wrlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_writing(
+ &the_rwlock->RWLock,
+ *rwlock,
+ true, /* do not timeout -- wait forever */
+ 0,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/psignal.c b/cpukit/posix/src/psignal.c
new file mode 100644
index 0000000000..3040718874
--- /dev/null
+++ b/cpukit/posix/src/psignal.c
@@ -0,0 +1,224 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_DEBUG)
+ #include <assert.h>
+#endif
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <string.h> /* memcpy */
+#include <stdlib.h> /* exit */
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/threadsup.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/time.h>
+#include <stdio.h>
+
+/*** PROCESS WIDE STUFF ****/
+
+sigset_t _POSIX_signals_Pending;
+
+void _POSIX_signals_Abnormal_termination_handler(
+ int signo __attribute__((unused)) )
+{
+ exit( 1 );
+}
+
+#define SIG_ARRAY_MAX (SIGRTMAX + 1)
+const struct sigaction _POSIX_signals_Default_vectors[ SIG_ARRAY_MAX ] = {
+ /* NO SIGNAL 0 */ SIGACTION_IGNORE,
+ /* SIGHUP 1 */ SIGACTION_TERMINATE,
+ /* SIGINT 2 */ SIGACTION_TERMINATE,
+ /* SIGQUIT 3 */ SIGACTION_TERMINATE,
+ /* SIGILL 4 */ SIGACTION_TERMINATE,
+ /* SIGTRAP 5 */ SIGACTION_TERMINATE,
+ /* SIGIOT 6 */ SIGACTION_TERMINATE,
+ /* SIGABRT 6 SIGACTION_TERMINATE, -- alias for SIGIOT */
+ /* SIGEMT 7 */ SIGACTION_TERMINATE,
+ /* SIGFPE 8 */ SIGACTION_TERMINATE,
+ /* SIGKILL 9 */ SIGACTION_TERMINATE,
+ /* SIGBUS 10 */ SIGACTION_TERMINATE,
+ /* SIGSEGV 11 */ SIGACTION_TERMINATE,
+ /* SIGSYS 12 */ SIGACTION_TERMINATE,
+ /* SIGPIPE 13 */ SIGACTION_TERMINATE,
+ /* SIGALRM 14 */ SIGACTION_TERMINATE,
+ /* SIGTERM 15 */ SIGACTION_TERMINATE,
+ /* SIGURG 16 */ SIGACTION_TERMINATE,
+ /* SIGSTOP 17 */ SIGACTION_TERMINATE,
+ /* SIGTSTP 18 */ SIGACTION_TERMINATE,
+ /* SIGCONT 19 */ SIGACTION_TERMINATE,
+ /* SIGCHLD 20 */ SIGACTION_TERMINATE,
+ /* SIGTTIN 21 */ SIGACTION_TERMINATE,
+ /* SIGTTOU 22 */ SIGACTION_TERMINATE,
+ /* SIGIO 23 */ SIGACTION_TERMINATE,
+ /* SIGWINCH 24 */ SIGACTION_TERMINATE,
+ /* SIGUSR1 25 */ SIGACTION_TERMINATE,
+ /* SIGUSR2 26 */ SIGACTION_TERMINATE,
+ /* SIGRT 27 */ SIGACTION_TERMINATE,
+ /* SIGRT 28 */ SIGACTION_TERMINATE,
+ /* SIGRT 29 */ SIGACTION_TERMINATE,
+ /* SIGRT 30 */ SIGACTION_TERMINATE,
+ /* SIGRTMAX 31 */ SIGACTION_TERMINATE
+};
+
+struct sigaction _POSIX_signals_Vectors[ SIG_ARRAY_MAX ];
+
+Thread_queue_Control _POSIX_signals_Wait_queue;
+
+Chain_Control _POSIX_signals_Inactive_siginfo;
+Chain_Control _POSIX_signals_Siginfo[ SIG_ARRAY_MAX ];
+
+Watchdog_Control _POSIX_signals_Alarm_timer;
+Watchdog_Control _POSIX_signals_Ualarm_timer;
+
+/*PAGE
+ *
+ * XXX - move these
+ */
+
+#define _States_Is_interruptible_signal( _states ) \
+ ( ((_states) & \
+ (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL)) == \
+ (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL))
+
+/*
+ * _POSIX_signals_Post_switch_extension
+ */
+
+void _POSIX_signals_Post_switch_extension(
+ Thread_Control *the_thread
+)
+{
+ POSIX_API_Control *api;
+ int signo;
+ ISR_Level level;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ /*
+ * api may be NULL in case of a thread close in progress
+ */
+ if ( !api )
+ return;
+
+ /*
+ * If we invoke any user code, there is the possibility that
+ * a new signal has been posted that we should process so we
+ * restart the loop if a signal handler was invoked.
+ *
+ * The first thing done is to check there are any signals to be
+ * processed at all. No point in doing this loop otherwise.
+ */
+ while (1) {
+ _ISR_Disable( level );
+ if ( !(~api->signals_blocked &
+ (api->signals_pending | _POSIX_signals_Pending)) ) {
+ _ISR_Enable( level );
+ break;
+ }
+ _ISR_Enable( level );
+
+ for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
+ _POSIX_signals_Check_signal( api, signo, false );
+ _POSIX_signals_Check_signal( api, signo, true );
+ }
+ /* Unfortunately - nothing like __SIGFIRSTNOTRT in newlib signal .h */
+
+ for ( signo = SIGHUP ; signo <= __SIGLASTNOTRT ; signo++ ) {
+ _POSIX_signals_Check_signal( api, signo, false );
+ _POSIX_signals_Check_signal( api, signo, true );
+ }
+ }
+}
+
+/*PAGE
+ *
+ * _POSIX_signals_Manager_Initialization
+ */
+
+void _POSIX_signals_Manager_Initialization(void)
+{
+ uint32_t signo;
+ uint32_t maximum_queued_signals;
+
+ maximum_queued_signals = Configuration_POSIX_API.maximum_queued_signals;
+
+ /*
+ * Ensure we have the same number of vectors and default vector entries
+ */
+
+ #if defined(RTEMS_DEBUG)
+ assert(
+ sizeof(_POSIX_signals_Vectors) == sizeof(_POSIX_signals_Default_vectors)
+ );
+ #endif
+
+ memcpy(
+ _POSIX_signals_Vectors,
+ _POSIX_signals_Default_vectors,
+ sizeof( _POSIX_signals_Vectors )
+ );
+
+ /*
+ * Initialize the set of pending signals for the entire process
+ */
+ sigemptyset( &_POSIX_signals_Pending );
+
+ /*
+ * Initialize the queue we use to block for signals
+ */
+ _Thread_queue_Initialize(
+ &_POSIX_signals_Wait_queue,
+ THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_SIGNAL | STATES_INTERRUPTIBLE_BY_SIGNAL,
+ EAGAIN
+ );
+
+ /* XXX status codes */
+
+ /*
+ * Allocate the siginfo pools.
+ */
+ for ( signo=1 ; signo<= SIGRTMAX ; signo++ )
+ _Chain_Initialize_empty( &_POSIX_signals_Siginfo[ signo ] );
+
+ if ( maximum_queued_signals ) {
+ _Chain_Initialize(
+ &_POSIX_signals_Inactive_siginfo,
+ _Workspace_Allocate_or_fatal_error(
+ maximum_queued_signals * sizeof( POSIX_signals_Siginfo_node )
+ ),
+ maximum_queued_signals,
+ sizeof( POSIX_signals_Siginfo_node )
+ );
+ } else {
+ _Chain_Initialize_empty( &_POSIX_signals_Inactive_siginfo );
+ }
+
+ /*
+ * Initialize the Alarm Timer
+ */
+ _Watchdog_Initialize( &_POSIX_signals_Alarm_timer, NULL, 0, NULL );
+ _Watchdog_Initialize( &_POSIX_signals_Ualarm_timer, NULL, 0, NULL );
+}
diff --git a/cpukit/posix/src/psignalchecksignal.c b/cpukit/posix/src/psignalchecksignal.c
new file mode 100644
index 0000000000..8bba7a4226
--- /dev/null
+++ b/cpukit/posix/src/psignalchecksignal.c
@@ -0,0 +1,113 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(RTEMS_DEBUG)
+ #include <assert.h>
+#endif
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/threadsup.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/time.h>
+#include <stdio.h>
+
+
+/*PAGE
+ *
+ * _POSIX_signals_Check_signal
+ */
+
+bool _POSIX_signals_Check_signal(
+ POSIX_API_Control *api,
+ int signo,
+ bool is_global
+)
+{
+ siginfo_t siginfo_struct;
+ sigset_t saved_signals_blocked;
+ Thread_Wait_information stored_thread_wait_information;
+
+ if ( ! _POSIX_signals_Clear_signals( api, signo, &siginfo_struct,
+ is_global, true ) )
+ return false;
+
+ /*
+ * Since we made a union of these, only one test is necessary but this is
+ * safer.
+ */
+ #if defined(RTEMS_DEBUG)
+ assert( _POSIX_signals_Vectors[ signo ].sa_handler ||
+ _POSIX_signals_Vectors[ signo ].sa_sigaction );
+ #endif
+
+ /*
+ * Just to prevent sending a signal which is currently being ignored.
+ */
+ if ( _POSIX_signals_Vectors[ signo ].sa_handler == SIG_IGN )
+ return false;
+
+ /*
+ * Block the signals requested in sa_mask
+ */
+ saved_signals_blocked = api->signals_blocked;
+ api->signals_blocked |= _POSIX_signals_Vectors[ signo ].sa_mask;
+
+ /*
+ * We have to save the blocking information of the current wait queue
+ * because the signal handler may subsequently go on and put the thread
+ * on a wait queue, for its own purposes.
+ */
+ memcpy( &stored_thread_wait_information, &_Thread_Executing->Wait,
+ sizeof( Thread_Wait_information ));
+
+ /*
+ * Here, the signal handler function executes
+ */
+ switch ( _POSIX_signals_Vectors[ signo ].sa_flags ) {
+ case SA_SIGINFO:
+ (*_POSIX_signals_Vectors[ signo ].sa_sigaction)(
+ signo,
+ &siginfo_struct,
+ NULL /* context is undefined per 1003.1b-1993, p. 66 */
+ );
+ break;
+ default:
+ (*_POSIX_signals_Vectors[ signo ].sa_handler)( signo );
+ break;
+ }
+
+ /*
+ * Restore the blocking information
+ */
+ memcpy( &_Thread_Executing->Wait, &stored_thread_wait_information,
+ sizeof( Thread_Wait_information ));
+
+ /*
+ * Restore the previous set of blocked signals
+ */
+ api->signals_blocked = saved_signals_blocked;
+
+ return true;
+}
diff --git a/cpukit/posix/src/psignalclearprocesssignals.c b/cpukit/posix/src/psignalclearprocesssignals.c
new file mode 100644
index 0000000000..b11ae0ebc2
--- /dev/null
+++ b/cpukit/posix/src/psignalclearprocesssignals.c
@@ -0,0 +1,58 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/threadsup.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/time.h>
+#include <stdio.h>
+
+/*PAGE
+ *
+ * _POSIX_signals_Clear_process_signals
+ */
+
+void _POSIX_signals_Clear_process_signals(
+ int signo
+)
+{
+ sigset_t mask;
+ bool clear_signal;
+
+ clear_signal = true;
+ mask = signo_to_mask( signo );
+
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ if ( _POSIX_signals_Vectors[ signo ].sa_flags == SA_SIGINFO ) {
+ if ( !_Chain_Is_empty( &_POSIX_signals_Siginfo[ signo ] ) )
+ clear_signal = false;
+ }
+ if ( clear_signal ) {
+ _POSIX_signals_Pending &= ~mask;
+ }
+ _ISR_Enable( level );
+}
diff --git a/cpukit/posix/src/psignalclearsignals.c b/cpukit/posix/src/psignalclearsignals.c
new file mode 100644
index 0000000000..09942f3bb5
--- /dev/null
+++ b/cpukit/posix/src/psignalclearsignals.c
@@ -0,0 +1,99 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/threadsup.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/time.h>
+#include <stdio.h>
+
+/*PAGE
+ *
+ * _POSIX_signals_Clear_signals
+ */
+
+bool _POSIX_signals_Clear_signals(
+ POSIX_API_Control *api,
+ int signo,
+ siginfo_t *info,
+ bool is_global,
+ bool check_blocked
+)
+{
+ sigset_t mask;
+ sigset_t signals_blocked;
+ ISR_Level level;
+ bool do_callout;
+ POSIX_signals_Siginfo_node *psiginfo;
+
+ mask = signo_to_mask( signo );
+
+ do_callout = false;
+
+ /* set blocked signals based on if checking for them, SIGNAL_ALL_MASK
+ * insures that no signals are blocked and all are checked.
+ */
+
+ if ( check_blocked )
+ signals_blocked = ~api->signals_blocked;
+ else
+ signals_blocked = SIGNAL_ALL_MASK;
+
+ /* XXX is this right for siginfo type signals? */
+ /* XXX are we sure they can be cleared the same way? */
+
+ _ISR_Disable( level );
+ if ( is_global ) {
+ if ( mask & (_POSIX_signals_Pending & signals_blocked) ) {
+ if ( _POSIX_signals_Vectors[ signo ].sa_flags == SA_SIGINFO ) {
+ psiginfo = (POSIX_signals_Siginfo_node *)
+ _Chain_Get_unprotected( &_POSIX_signals_Siginfo[ signo ] );
+ _POSIX_signals_Clear_process_signals( signo );
+ /*
+ * It may be impossible to get here with an empty chain
+ * BUT until that is proven we need to be defensive and
+ * protect against it.
+ */
+ if ( psiginfo ) {
+ *info = psiginfo->Info;
+ _Chain_Append_unprotected(
+ &_POSIX_signals_Inactive_siginfo,
+ &psiginfo->Node
+ );
+ } else
+ do_callout = false;
+ }
+ _POSIX_signals_Clear_process_signals( signo );
+ do_callout = true;
+ }
+ } else {
+ if ( mask & (api->signals_pending & signals_blocked) ) {
+ api->signals_pending &= ~mask;
+ do_callout = true;
+ }
+ }
+ _ISR_Enable( level );
+ return do_callout;
+}
diff --git a/cpukit/posix/src/psignalsetprocesssignals.c b/cpukit/posix/src/psignalsetprocesssignals.c
new file mode 100644
index 0000000000..cb4ad8b241
--- /dev/null
+++ b/cpukit/posix/src/psignalsetprocesssignals.c
@@ -0,0 +1,46 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/threadsup.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/time.h>
+#include <stdio.h>
+
+/*PAGE
+ *
+ * _POSIX_signals_Set_process_signals
+ */
+
+void _POSIX_signals_Set_process_signals(
+ sigset_t mask
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ _POSIX_signals_Pending |= mask;
+ _ISR_Enable( level );
+}
diff --git a/cpukit/posix/src/psignalunblockthread.c b/cpukit/posix/src/psignalunblockthread.c
new file mode 100644
index 0000000000..f6bf5fcc7d
--- /dev/null
+++ b/cpukit/posix/src/psignalunblockthread.c
@@ -0,0 +1,120 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/threadsup.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/time.h>
+#include <stdio.h>
+
+
+/*PAGE
+ *
+ * _POSIX_signals_Unblock_thread
+ */
+
+/* XXX this routine could probably be cleaned up */
+bool _POSIX_signals_Unblock_thread(
+ Thread_Control *the_thread,
+ int signo,
+ siginfo_t *info
+)
+{
+ POSIX_API_Control *api;
+ sigset_t mask;
+ siginfo_t *the_info = NULL;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ mask = signo_to_mask( signo );
+
+ /*
+ * Is the thread is specifically waiting for a signal?
+ */
+
+ if ( _States_Is_interruptible_signal( the_thread->current_state ) ) {
+
+ if ( (the_thread->Wait.option & mask) || (~api->signals_blocked & mask) ) {
+ the_thread->Wait.return_code = EINTR;
+
+ the_info = (siginfo_t *) the_thread->Wait.return_argument;
+
+ if ( !info ) {
+ the_info->si_signo = signo;
+ the_info->si_code = SI_USER;
+ the_info->si_value.sival_int = 0;
+ } else {
+ *the_info = *info;
+ }
+
+ _Thread_queue_Extract_with_proxy( the_thread );
+ return true;
+ }
+
+ /*
+ * This should only be reached via pthread_kill().
+ */
+
+ return false;
+ }
+
+ /*
+ * Thread is not waiting due to a sigwait.
+ */
+ if ( ~api->signals_blocked & mask ) {
+
+ /*
+ * The thread is interested in this signal. We are going
+ * to post it. We have a few broad cases:
+ * + If it is blocked on an interruptible signal, THEN
+ * we unblock the thread.
+ * + If it is in the ready state AND
+ * we are sending from an ISR AND
+ * it is the interrupted thread AND
+ * it is not blocked, THEN
+ * we need to dispatch at the end of this ISR.
+ * + Any other combination, do nothing.
+ */
+
+ if ( _States_Is_interruptible_by_signal( the_thread->current_state ) ) {
+ the_thread->Wait.return_code = EINTR;
+ /*
+ * In pthread_cond_wait, a thread will be blocking on a thread
+ * queue, but is also interruptible by a POSIX signal.
+ */
+ if ( _States_Is_waiting_on_thread_queue(the_thread->current_state) )
+ _Thread_queue_Extract_with_proxy( the_thread );
+ else if ( _States_Is_delaying(the_thread->current_state) ) {
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ _Thread_Unblock( the_thread );
+ }
+
+ } else if ( the_thread->current_state == STATES_READY ) {
+ if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) )
+ _Thread_Dispatch_necessary = true;
+ }
+ }
+ return false;
+}
diff --git a/cpukit/posix/src/pspin.c b/cpukit/posix/src/pspin.c
new file mode 100644
index 0000000000..88dadf2cba
--- /dev/null
+++ b/cpukit/posix/src/pspin.c
@@ -0,0 +1,57 @@
+/*
+ * Spinlock Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Spinlock Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a spinlock
+ * + get an ID of a spinlock
+ * + delete a spinlock
+ * + acquire a spinlock
+ * + release a spinlock
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/posix/spinlock.h>
+
+/**
+ * @brief _POSIX_Spinlock_Manager_initialization
+ */
+
+void _POSIX_Spinlock_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Spinlock_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_SPINLOCKS, /* object class */
+ Configuration_POSIX_API.maximum_spinlocks,
+ /* maximum objects of this class */
+ sizeof( POSIX_Spinlock_Control ),/* size of this object's control block */
+ true, /* true if the name is a string */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/pspindestroy.c b/cpukit/posix/src/pspindestroy.c
new file mode 100644
index 0000000000..aa3c465ec7
--- /dev/null
+++ b/cpukit/posix/src/pspindestroy.c
@@ -0,0 +1,73 @@
+/*
+ * POSIX Spinlock Manager -- Destroy a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_destroy
+ *
+ * This directive allows a thread to delete a spinlock specified by
+ * the spinlock id. The spinlock is freed back to the inactive
+ * spinlock chain.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_destroy(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( _CORE_spinlock_Is_busy( &the_spinlock->Spinlock ) ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ _Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object );
+
+ _POSIX_Spinlock_Free( the_spinlock );
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/pspininit.c b/cpukit/posix/src/pspininit.c
new file mode 100644
index 0000000000..bab6ac3140
--- /dev/null
+++ b/cpukit/posix/src/pspininit.c
@@ -0,0 +1,78 @@
+/*
+ * POSIX Spinlock Manager -- Initialize a Spinlock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spinlock_init
+ *
+ * This directive creates a spinlock. A spinlock id is returned.
+ *
+ * Input parameters:
+ * spinlock - pointer to spinlock id
+ * pshared - is this spinlock shared between processes
+ *
+ * Output parameters:
+ * spinlock - spinlock id
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_init(
+ pthread_spinlock_t *spinlock,
+ int pshared
+)
+{
+ POSIX_Spinlock_Control *the_spinlock;
+ CORE_spinlock_Attributes attributes;
+
+
+ if ( !spinlock )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_PRIVATE: /* only supported values */
+ break;
+ case PTHREAD_PROCESS_SHARED:
+ default:
+ return EINVAL;
+ }
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_spinlock = _POSIX_Spinlock_Allocate();
+
+ if ( !the_spinlock ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ _CORE_spinlock_Initialize_attributes( &attributes );
+
+ _CORE_spinlock_Initialize( &the_spinlock->Spinlock, &attributes );
+
+ _Objects_Open_u32( &_POSIX_Spinlock_Information, &the_spinlock->Object, 0 );
+
+ *spinlock = the_spinlock->Object.id;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/pspinlock.c b/cpukit/posix/src/pspinlock.c
new file mode 100644
index 0000000000..845117a3e3
--- /dev/null
+++ b/cpukit/posix/src/pspinlock.c
@@ -0,0 +1,64 @@
+/*
+ * POSIX Spinlock Manager -- Wait at a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_lock
+ *
+ * This directive allows a thread to wait at a spinlock.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_lock(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+ CORE_spinlock_Status status;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, true, 0 );
+ _Thread_Enable_dispatch();
+ return _POSIX_Spinlock_Translate_core_spinlock_return_code( status );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/pspinlocktranslatereturncode.c b/cpukit/posix/src/pspinlocktranslatereturncode.c
new file mode 100644
index 0000000000..fbce440010
--- /dev/null
+++ b/cpukit/posix/src/pspinlocktranslatereturncode.c
@@ -0,0 +1,58 @@
+/*
+ * Spinlock Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/corespinlock.h>
+
+/*
+ * _POSIX_Spinlock_Translate_core_spinlock_return_code
+ *
+ * Input parameters:
+ * the_spinlock_status - spinlock status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static int _POSIX_Spinlock_Return_codes[CORE_SPINLOCK_STATUS_LAST + 1] = {
+ 0, /* CORE_SPINLOCK_SUCCESSFUL */
+ EDEADLK, /* CORE_SPINLOCK_HOLDER_RELOCKING */
+ EPERM, /* CORE_SPINLOCK_NOT_HOLDER */
+ -1, /* CORE_SPINLOCK_TIMEOUT */
+ EBUSY, /* CORE_SPINLOCK_IS_BUSY */
+ EBUSY, /* CORE_SPINLOCK_UNAVAILABLE */
+ 0 /* CORE_SPINLOCK_NOT_LOCKED */
+};
+
+
+int _POSIX_Spinlock_Translate_core_spinlock_return_code(
+ CORE_spinlock_Status the_spinlock_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_spinlock_status > CORE_SPINLOCK_STATUS_LAST )
+ return EINVAL;
+ #endif
+ return _POSIX_Spinlock_Return_codes[the_spinlock_status];
+}
diff --git a/cpukit/posix/src/pspintrylock.c b/cpukit/posix/src/pspintrylock.c
new file mode 100644
index 0000000000..7e66d88e8b
--- /dev/null
+++ b/cpukit/posix/src/pspintrylock.c
@@ -0,0 +1,64 @@
+/*
+ * POSIX Spinlock Manager -- Wait at a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_trylock
+ *
+ * This directive allows a thread to poll an attempt at locking a spinlock.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_trylock(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+ CORE_spinlock_Status status;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, false, 0 );
+ _Thread_Enable_dispatch();
+ return _POSIX_Spinlock_Translate_core_spinlock_return_code( status );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/pspinunlock.c b/cpukit/posix/src/pspinunlock.c
new file mode 100644
index 0000000000..8bbf4f2f61
--- /dev/null
+++ b/cpukit/posix/src/pspinunlock.c
@@ -0,0 +1,64 @@
+/*
+ * POSIX Spinlock Manager -- Wait at a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_unlock
+ *
+ * This directive allows a thread to wait at a spinlock.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_unlock(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+ CORE_spinlock_Status status;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_spinlock_Release( &the_spinlock->Spinlock );
+ _Thread_Enable_dispatch();
+ return _POSIX_Spinlock_Translate_core_spinlock_return_code( status );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/psxpriorityisvalid.c b/cpukit/posix/src/psxpriorityisvalid.c
new file mode 100644
index 0000000000..4b35a81e62
--- /dev/null
+++ b/cpukit/posix/src/psxpriorityisvalid.c
@@ -0,0 +1,27 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/posix/priority.h>
+
+bool _POSIX_Priority_Is_valid(
+ int priority
+)
+{
+ return ((priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY) &&
+ (priority <= POSIX_SCHEDULER_MAXIMUM_PRIORITY));
+
+}
+
diff --git a/cpukit/posix/src/psxtransschedparam.c b/cpukit/posix/src/psxtransschedparam.c
new file mode 100644
index 0000000000..7be4dcc641
--- /dev/null
+++ b/cpukit/posix/src/psxtransschedparam.c
@@ -0,0 +1,73 @@
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int _POSIX_Thread_Translate_sched_param(
+ int policy,
+ struct sched_param *param,
+ Thread_CPU_budget_algorithms *budget_algorithm,
+ Thread_CPU_budget_algorithm_callout *budget_callout
+)
+{
+ if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
+ return EINVAL;
+
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
+ *budget_callout = NULL;
+
+ if ( policy == SCHED_OTHER ) {
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
+ return 0;
+ }
+
+ if ( policy == SCHED_FIFO ) {
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
+ return 0;
+ }
+
+ if ( policy == SCHED_RR ) {
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
+ return 0;
+ }
+
+ if ( policy == SCHED_SPORADIC ) {
+ if ( (param->sched_ss_repl_period.tv_sec == 0) &&
+ (param->sched_ss_repl_period.tv_nsec == 0) )
+ return EINVAL;
+
+ if ( (param->sched_ss_init_budget.tv_sec == 0) &&
+ (param->sched_ss_init_budget.tv_nsec == 0) )
+ return EINVAL;
+
+ if ( _Timespec_To_ticks( &param->sched_ss_repl_period ) <
+ _Timespec_To_ticks( &param->sched_ss_init_budget ) )
+ return EINVAL;
+
+ if ( !_POSIX_Priority_Is_valid( param->sched_ss_low_priority ) )
+ return EINVAL;
+
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
+ *budget_callout = _POSIX_Threads_Sporadic_budget_callout;
+ return 0;
+ }
+
+ return EINVAL;
+}
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
new file mode 100644
index 0000000000..3890144aa5
--- /dev/null
+++ b/cpukit/posix/src/pthread.c
@@ -0,0 +1,366 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/config.h>
+#include <rtems/posix/key.h>
+#include <rtems/posix/time.h>
+#include <rtems/score/timespec.h>
+
+/*
+ * The default pthreads attributes structure.
+ *
+ * NOTE: Be careful .. if the default attribute set changes,
+ * _POSIX_Threads_Initialize_user_threads will need to be examined.
+ */
+const pthread_attr_t _POSIX_Threads_Default_attributes = {
+ true, /* is_initialized */
+ NULL, /* stackaddr */
+ 0, /* stacksize -- will be adjusted to minimum */
+ PTHREAD_SCOPE_PROCESS, /* contentionscope */
+ PTHREAD_INHERIT_SCHED, /* inheritsched */
+ SCHED_FIFO, /* schedpolicy */
+ { /* schedparam */
+ 2, /* sched_priority */
+ #if defined(_POSIX_SPORADIC_SERVER) || \
+ defined(_POSIX_THREAD_SPORADIC_SERVER)
+ 0, /* sched_ss_low_priority */
+ { 0L, 0 }, /* sched_ss_repl_period */
+ { 0L, 0 } /* sched_ss_init_budget */
+ #endif
+ },
+ #if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
+ 0, /* guardsize */
+ #endif
+ #if defined(_POSIX_THREAD_CPUTIME)
+ 1, /* cputime_clock_allowed */
+ #endif
+ PTHREAD_CREATE_JOINABLE, /* detachstate */
+};
+
+/*
+ * _POSIX_Threads_Sporadic_budget_TSR
+ */
+void _POSIX_Threads_Sporadic_budget_TSR(
+ Objects_Id id __attribute__((unused)),
+ void *argument
+)
+{
+ uint32_t ticks;
+ uint32_t new_priority;
+ Thread_Control *the_thread;
+ POSIX_API_Control *api;
+
+ the_thread = argument;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ /* ticks is guaranteed to be at least one */
+ ticks = _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
+
+ the_thread->cpu_time_budget = ticks;
+
+ new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority );
+ the_thread->real_priority = new_priority;
+
+ /*
+ * If holding a resource, then do not change it.
+ */
+ #if 0
+ printk( "TSR %d %d %d\n", the_thread->resource_count,
+ the_thread->current_priority, new_priority );
+ #endif
+ if ( the_thread->resource_count == 0 ) {
+ /*
+ * If this would make them less important, then do not change it.
+ */
+ if ( the_thread->current_priority > new_priority ) {
+ _Thread_Change_priority( the_thread, new_priority, true );
+ #if 0
+ printk( "raise priority\n" );
+ #endif
+ }
+ }
+
+ /* ticks is guaranteed to be at least one */
+ ticks = _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period );
+
+ _Watchdog_Insert_ticks( &api->Sporadic_timer, ticks );
+}
+
+/*
+ * _POSIX_Threads_Sporadic_budget_callout
+ */
+void _POSIX_Threads_Sporadic_budget_callout(
+ Thread_Control *the_thread
+)
+{
+ POSIX_API_Control *api;
+ uint32_t new_priority;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ /*
+ * This will prevent the thread from consuming its entire "budget"
+ * while at low priority.
+ */
+ the_thread->cpu_time_budget = 0xFFFFFFFF; /* XXX should be based on MAX_U32 */
+
+ new_priority = _POSIX_Priority_To_core(api->schedparam.sched_ss_low_priority);
+ the_thread->real_priority = new_priority;
+
+ /*
+ * If holding a resource, then do not change it.
+ */
+ #if 0
+ printk( "callout %d %d %d\n", the_thread->resource_count,
+ the_thread->current_priority, new_priority );
+ #endif
+ if ( the_thread->resource_count == 0 ) {
+ /*
+ * Make sure we are actually lowering it. If they have lowered it
+ * to logically lower than sched_ss_low_priority, then we do not want to
+ * change it.
+ */
+ if ( the_thread->current_priority < new_priority ) {
+ _Thread_Change_priority( the_thread, new_priority, true );
+ #if 0
+ printk( "lower priority\n" );
+ #endif
+ }
+ }
+}
+
+/*
+ * _POSIX_Threads_Create_extension
+ *
+ * This method is invoked for each thread created.
+ */
+
+bool _POSIX_Threads_Create_extension(
+ Thread_Control *executing __attribute__((unused)),
+ Thread_Control *created
+)
+{
+ POSIX_API_Control *api;
+ POSIX_API_Control *executing_api;
+
+ api = _Workspace_Allocate( sizeof( POSIX_API_Control ) );
+
+ if ( !api )
+ return false;
+
+ created->API_Extensions[ THREAD_API_POSIX ] = api;
+
+ /* XXX check all fields are touched */
+ api->Attributes = _POSIX_Threads_Default_attributes;
+ api->detachstate = _POSIX_Threads_Default_attributes.detachstate;
+ api->schedpolicy = _POSIX_Threads_Default_attributes.schedpolicy;
+ api->schedparam = _POSIX_Threads_Default_attributes.schedparam;
+ api->schedparam.sched_priority =
+ _POSIX_Priority_From_core( created->current_priority );
+
+ /*
+ * POSIX 1003.1 1996, 18.2.2.2
+ */
+ api->cancelation_requested = 0;
+ api->cancelability_state = PTHREAD_CANCEL_ENABLE;
+ api->cancelability_type = PTHREAD_CANCEL_DEFERRED;
+ _Chain_Initialize_empty (&api->Cancellation_Handlers);
+
+ /*
+ * If the thread is not a posix thread, then all posix signals are blocked
+ * by default.
+ *
+ * The check for class == 1 is debug. Should never really happen.
+ */
+
+ /* XXX use signal constants */
+ api->signals_pending = 0;
+ if ( _Objects_Get_API( created->Object.id ) == OBJECTS_POSIX_API
+ #if defined(RTEMS_DEBUG)
+ && _Objects_Get_class( created->Object.id ) == 1
+ #endif
+ ) {
+ executing_api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+ api->signals_blocked = executing_api->signals_blocked;
+ } else {
+ api->signals_blocked = 0xffffffff;
+ }
+
+ _Thread_queue_Initialize(
+ &api->Join_List,
+ THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_JOIN_AT_EXIT,
+ 0
+ );
+
+ _Watchdog_Initialize(
+ &api->Sporadic_timer,
+ _POSIX_Threads_Sporadic_budget_TSR,
+ created->Object.id,
+ created
+ );
+
+ return true;
+}
+
+/*
+ * _POSIX_Threads_Delete_extension
+ *
+ * This method is invoked for each thread deleted.
+ */
+void _POSIX_Threads_Delete_extension(
+ Thread_Control *executing __attribute__((unused)),
+ Thread_Control *deleted
+)
+{
+ Thread_Control *the_thread;
+ POSIX_API_Control *api;
+ void **value_ptr;
+
+ api = deleted->API_Extensions[ THREAD_API_POSIX ];
+
+ /*
+ * Run the POSIX cancellation handlers
+ */
+ _POSIX_Threads_cancel_run( deleted );
+
+ /*
+ * Run all the key destructors
+ */
+ _POSIX_Keys_Run_destructors( deleted );
+
+ /*
+ * Wakeup all the tasks which joined with this one
+ */
+ value_ptr = (void **) deleted->Wait.return_argument;
+
+ while ( (the_thread = _Thread_queue_Dequeue( &api->Join_List )) )
+ *(void **)the_thread->Wait.return_argument = value_ptr;
+
+ if ( api->schedpolicy == SCHED_SPORADIC )
+ (void) _Watchdog_Remove( &api->Sporadic_timer );
+
+ deleted->API_Extensions[ THREAD_API_POSIX ] = NULL;
+
+ _Workspace_Free( api );
+}
+
+/*
+ * _POSIX_Threads_Exitted_extension
+ *
+ * This method is invoked each time a thread exits.
+ */
+void _POSIX_Threads_Exitted_extension(
+ Thread_Control *executing
+)
+{
+ /*
+ * If the executing thread was not created with the POSIX API, then this
+ * API do not get to define its exit behavior.
+ */
+ if ( _Objects_Get_API( executing->Object.id ) == OBJECTS_POSIX_API )
+ pthread_exit( executing->Wait.return_argument );
+}
+
+/*
+ * _POSIX_Threads_Initialize_user_threads
+ *
+ * This routine creates and starts all configured user
+ * initialzation threads.
+ */
+void _POSIX_Threads_Initialize_user_threads( void )
+{
+ if ( _POSIX_Threads_Initialize_user_threads_p )
+ (*_POSIX_Threads_Initialize_user_threads_p)();
+}
+
+/*
+ * API Extension control structures
+ */
+API_extensions_Control _POSIX_Threads_API_extensions = {
+ { NULL, NULL },
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ NULL, /* predriver */
+ #endif
+ _POSIX_Threads_Initialize_user_threads, /* postdriver */
+ _POSIX_signals_Post_switch_extension, /* post switch */
+};
+
+User_extensions_Control _POSIX_Threads_User_extensions = {
+ { NULL, NULL },
+ { { NULL, NULL }, NULL },
+ { _POSIX_Threads_Create_extension, /* create */
+ NULL, /* start */
+ NULL, /* restart */
+ _POSIX_Threads_Delete_extension, /* delete */
+ NULL, /* switch */
+ NULL, /* begin */
+ _POSIX_Threads_Exitted_extension, /* exitted */
+ NULL /* fatal */
+ }
+};
+
+/*
+ * _POSIX_Threads_Manager_initialization
+ *
+ * This routine initializes all threads manager related data structures.
+ */
+void _POSIX_Threads_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Threads_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_THREADS, /* object class */
+ Configuration_POSIX_API.maximum_threads,
+ /* maximum objects of this class */
+ sizeof( Thread_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Add all the extensions for this API
+ */
+ _User_extensions_Add_API_set( &_POSIX_Threads_User_extensions );
+
+ _API_extensions_Add( &_POSIX_Threads_API_extensions );
+
+ /*
+ * If we supported MP, then here we would ...
+ * Register the MP Process Packet routine.
+ */
+}
diff --git a/cpukit/posix/src/pthreadatfork.c b/cpukit/posix/src/pthreadatfork.c
new file mode 100644
index 0000000000..9a08abd254
--- /dev/null
+++ b/cpukit/posix/src/pthreadatfork.c
@@ -0,0 +1,37 @@
+/*
+ * pthread_atfork() - POSIX 1003.1b 3.1.3
+ *
+ * 3.1.3 Register Fork Handlers, P1003.1c/Draft 10, P1003.1c/Draft 10, p. 27
+ *
+ * RTEMS does not support processes, so we fall under this and do not
+ * provide this routine:
+ *
+ * "Either the implementation shall support the pthread_atfork() function
+ * as described above or the pthread_atfork() funciton shall not be
+ * provided."
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int pthread_atfork(
+ void (*prepare)(void) __attribute__((unused)),
+ void (*parent)(void) __attribute__((unused)),
+ void (*child)(void) __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/pthreadattrdestroy.c b/cpukit/posix/src/pthreadattrdestroy.c
new file mode 100644
index 0000000000..60787322e7
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrdestroy.c
@@ -0,0 +1,32 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+
+int pthread_attr_destroy(
+ pthread_attr_t *attr
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ attr->is_initialized = false;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetdetachstate.c b/cpukit/posix/src/pthreadattrgetdetachstate.c
new file mode 100644
index 0000000000..bd8b9a02ae
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetdetachstate.c
@@ -0,0 +1,31 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getdetachstate(
+ const pthread_attr_t *attr,
+ int *detachstate
+)
+{
+ if ( !attr || !attr->is_initialized || !detachstate )
+ return EINVAL;
+
+ *detachstate = attr->detachstate;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetguardsize.c b/cpukit/posix/src/pthreadattrgetguardsize.c
new file mode 100644
index 0000000000..b3c64fbfad
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetguardsize.c
@@ -0,0 +1,33 @@
+/*
+ * 16.1.1 Thread Creation Attributes
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_DECL_PTHREAD_ATTR_GETGUARDSIZE
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getguardsize(
+ const pthread_attr_t *attr,
+ size_t *guardsize
+)
+{
+ if ( !attr || !attr->is_initialized || !guardsize )
+ return EINVAL;
+
+ *guardsize = attr->guardsize;
+ return 0;
+}
+#endif
diff --git a/cpukit/posix/src/pthreadattrgetinheritsched.c b/cpukit/posix/src/pthreadattrgetinheritsched.c
new file mode 100644
index 0000000000..e924f2d26c
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetinheritsched.c
@@ -0,0 +1,31 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getinheritsched(
+ const pthread_attr_t *attr,
+ int *inheritsched
+)
+{
+ if ( !attr || !attr->is_initialized || !inheritsched )
+ return EINVAL;
+
+ *inheritsched = attr->inheritsched;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetschedparam.c b/cpukit/posix/src/pthreadattrgetschedparam.c
new file mode 100644
index 0000000000..2ec95d729e
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetschedparam.c
@@ -0,0 +1,31 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getschedparam(
+ const pthread_attr_t *attr,
+ struct sched_param *param
+)
+{
+ if ( !attr || !attr->is_initialized || !param )
+ return EINVAL;
+
+ *param = attr->schedparam;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetschedpolicy.c b/cpukit/posix/src/pthreadattrgetschedpolicy.c
new file mode 100644
index 0000000000..571430e953
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetschedpolicy.c
@@ -0,0 +1,31 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Parameters, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getschedpolicy(
+ const pthread_attr_t *attr,
+ int *policy
+)
+{
+ if ( !attr || !attr->is_initialized || !policy )
+ return EINVAL;
+
+ *policy = attr->schedpolicy;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetscope.c b/cpukit/posix/src/pthreadattrgetscope.c
new file mode 100644
index 0000000000..2d74dc30ba
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetscope.c
@@ -0,0 +1,31 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getscope(
+ const pthread_attr_t *attr,
+ int *contentionscope
+)
+{
+ if ( !attr || !attr->is_initialized || !contentionscope )
+ return EINVAL;
+
+ *contentionscope = attr->contentionscope;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetstack.c b/cpukit/posix/src/pthreadattrgetstack.c
new file mode 100644
index 0000000000..8303099a96
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetstack.c
@@ -0,0 +1,35 @@
+/*
+ * 16.1.1 Thread Creation Attributes
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_DECL_PTHREAD_ATTR_GETSTACK
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getstack(
+ const pthread_attr_t *attr,
+ void **stackaddr,
+ size_t *stacksize
+)
+{
+ if ( !attr || !attr->is_initialized || !stackaddr || !stacksize )
+ return EINVAL;
+
+ *stackaddr = attr->stackaddr;
+ *stacksize = attr->stacksize;
+ return 0;
+}
+#endif
diff --git a/cpukit/posix/src/pthreadattrgetstackaddr.c b/cpukit/posix/src/pthreadattrgetstackaddr.c
new file mode 100644
index 0000000000..3ca66112aa
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetstackaddr.c
@@ -0,0 +1,31 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getstackaddr(
+ const pthread_attr_t *attr,
+ void **stackaddr
+)
+{
+ if ( !attr || !attr->is_initialized || !stackaddr )
+ return EINVAL;
+
+ *stackaddr = attr->stackaddr;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrgetstacksize.c b/cpukit/posix/src/pthreadattrgetstacksize.c
new file mode 100644
index 0000000000..f7f23c6dd6
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrgetstacksize.c
@@ -0,0 +1,31 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getstacksize(
+ const pthread_attr_t *attr,
+ size_t *stacksize
+)
+{
+ if ( !attr || !attr->is_initialized || !stacksize )
+ return EINVAL;
+
+ *stacksize = attr->stacksize;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrinit.c b/cpukit/posix/src/pthreadattrinit.c
new file mode 100644
index 0000000000..1862623e3e
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrinit.c
@@ -0,0 +1,33 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_init(
+ pthread_attr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ *attr = _POSIX_Threads_Default_attributes;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrsetdetachstate.c b/cpukit/posix/src/pthreadattrsetdetachstate.c
new file mode 100644
index 0000000000..cb29f44d3a
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetdetachstate.c
@@ -0,0 +1,38 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_setdetachstate(
+ pthread_attr_t *attr,
+ int detachstate
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( detachstate ) {
+ case PTHREAD_CREATE_DETACHED:
+ case PTHREAD_CREATE_JOINABLE:
+ attr->detachstate = detachstate;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/pthreadattrsetguardsize.c b/cpukit/posix/src/pthreadattrsetguardsize.c
new file mode 100644
index 0000000000..f69ff7b173
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetguardsize.c
@@ -0,0 +1,36 @@
+/*
+ * 16.1.1 Thread Creation Attributes
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_setguardsize(
+ pthread_attr_t *attr,
+ size_t guardsize
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ attr->guardsize = guardsize;
+ return 0;
+}
+#endif
diff --git a/cpukit/posix/src/pthreadattrsetinheritsched.c b/cpukit/posix/src/pthreadattrsetinheritsched.c
new file mode 100644
index 0000000000..0819eb48b7
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetinheritsched.c
@@ -0,0 +1,41 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_setinheritsched(
+ pthread_attr_t *attr,
+ int inheritsched
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( inheritsched ) {
+ case PTHREAD_INHERIT_SCHED:
+ case PTHREAD_EXPLICIT_SCHED:
+ attr->inheritsched = inheritsched;
+ return 0;
+
+ default:
+ return ENOTSUP;
+ }
+}
diff --git a/cpukit/posix/src/pthreadattrsetschedparam.c b/cpukit/posix/src/pthreadattrsetschedparam.c
new file mode 100644
index 0000000000..cb310a9893
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetschedparam.c
@@ -0,0 +1,31 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Parameters, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_setschedparam(
+ pthread_attr_t *attr,
+ const struct sched_param *param
+)
+{
+ if ( !attr || !attr->is_initialized || !param )
+ return EINVAL;
+
+ attr->schedparam = *param;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrsetschedpolicy.c b/cpukit/posix/src/pthreadattrsetschedpolicy.c
new file mode 100644
index 0000000000..ab61e000ed
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetschedpolicy.c
@@ -0,0 +1,43 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_setschedpolicy(
+ pthread_attr_t *attr,
+ int policy
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( policy ) {
+ case SCHED_OTHER:
+ case SCHED_FIFO:
+ case SCHED_RR:
+ case SCHED_SPORADIC:
+ attr->schedpolicy = policy;
+ return 0;
+
+ default:
+ return ENOTSUP;
+ }
+}
diff --git a/cpukit/posix/src/pthreadattrsetscope.c b/cpukit/posix/src/pthreadattrsetscope.c
new file mode 100644
index 0000000000..8c6d1c3f9c
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetscope.c
@@ -0,0 +1,43 @@
+/*
+ * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_setscope(
+ pthread_attr_t *attr,
+ int contentionscope
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( contentionscope ) {
+ case PTHREAD_SCOPE_PROCESS:
+ attr->contentionscope = contentionscope;
+ return 0;
+
+ case PTHREAD_SCOPE_SYSTEM:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/pthreadattrsetstack.c b/cpukit/posix/src/pthreadattrsetstack.c
new file mode 100644
index 0000000000..f97d3ac885
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetstack.c
@@ -0,0 +1,42 @@
+/*
+ * 16.1.1 Thread Creation Attributes
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAVE_DECL_PTHREAD_ATTR_SETSTACK
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_setstack(
+ pthread_attr_t *attr,
+ void *stackaddr,
+ size_t stacksize
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ if (stacksize < PTHREAD_MINIMUM_STACK_SIZE)
+ attr->stacksize = PTHREAD_MINIMUM_STACK_SIZE;
+ else
+ attr->stacksize = stacksize;
+
+ attr->stackaddr = stackaddr;
+ return 0;
+}
+#endif
diff --git a/cpukit/posix/src/pthreadattrsetstackaddr.c b/cpukit/posix/src/pthreadattrsetstackaddr.c
new file mode 100644
index 0000000000..b7ed212546
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetstackaddr.c
@@ -0,0 +1,31 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_setstackaddr(
+ pthread_attr_t *attr,
+ void *stackaddr
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ attr->stackaddr = stackaddr;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadattrsetstacksize.c b/cpukit/posix/src/pthreadattrsetstacksize.c
new file mode 100644
index 0000000000..9598a8a7d7
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrsetstacksize.c
@@ -0,0 +1,37 @@
+/*
+ * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_attr_setstacksize(
+ pthread_attr_t *attr,
+ size_t stacksize
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ if (stacksize < PTHREAD_MINIMUM_STACK_SIZE)
+ attr->stacksize = PTHREAD_MINIMUM_STACK_SIZE;
+ else
+ attr->stacksize = stacksize;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
new file mode 100644
index 0000000000..d7f08a5527
--- /dev/null
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -0,0 +1,232 @@
+/*
+ * 16.1.2 Thread Creation, P1003.1c/Draft 10, p. 144
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+#include <rtems/score/apimutex.h>
+
+static inline size_t _POSIX_Threads_Ensure_minimum_stack (
+ size_t size
+)
+{
+ if ( size >= PTHREAD_MINIMUM_STACK_SIZE )
+ return size;
+ return PTHREAD_MINIMUM_STACK_SIZE;
+}
+
+
+int pthread_create(
+ pthread_t *thread,
+ const pthread_attr_t *attr,
+ void *(*start_routine)( void * ),
+ void *arg
+)
+{
+ const pthread_attr_t *the_attr;
+ Priority_Control core_priority;
+ Thread_CPU_budget_algorithms budget_algorithm;
+ Thread_CPU_budget_algorithm_callout budget_callout;
+ bool is_fp;
+ bool status;
+ Thread_Control *the_thread;
+ POSIX_API_Control *api;
+ int schedpolicy = SCHED_RR;
+ struct sched_param schedparam;
+ Objects_Name name;
+ int rc;
+
+ if ( !start_routine )
+ return EFAULT;
+
+ the_attr = (attr) ? attr : &_POSIX_Threads_Default_attributes;
+
+ if ( !the_attr->is_initialized )
+ return EINVAL;
+
+ /*
+ * Core Thread Initialize ensures we get the minimum amount of
+ * stack space if it is allowed to allocate it itself.
+ *
+ * NOTE: If the user provides the stack we will let it drop below
+ * twice the minimum.
+ */
+ if ( the_attr->stackaddr && !_Stack_Is_enough(the_attr->stacksize) )
+ return EINVAL;
+
+ #if 0
+ int cputime_clock_allowed; /* see time.h */
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+ #endif
+
+ /*
+ * P1003.1c/Draft 10, p. 121.
+ *
+ * If inheritsched is set to PTHREAD_INHERIT_SCHED, then this thread
+ * inherits scheduling attributes from the creating thread. If it is
+ * PTHREAD_EXPLICIT_SCHED, then scheduling parameters come from the
+ * attributes structure.
+ */
+ switch ( the_attr->inheritsched ) {
+ case PTHREAD_INHERIT_SCHED:
+ api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+ schedpolicy = api->schedpolicy;
+ schedparam = api->schedparam;
+ break;
+
+ case PTHREAD_EXPLICIT_SCHED:
+ schedpolicy = the_attr->schedpolicy;
+ schedparam = the_attr->schedparam;
+ break;
+
+ default:
+ return EINVAL;
+ }
+
+ /*
+ * Check the contentionscope since rtems only supports PROCESS wide
+ * contention (i.e. no system wide contention).
+ */
+ if ( the_attr->contentionscope != PTHREAD_SCOPE_PROCESS )
+ return ENOTSUP;
+
+ /*
+ * Interpret the scheduling parameters.
+ */
+ if ( !_POSIX_Priority_Is_valid( schedparam.sched_priority ) )
+ return EINVAL;
+
+ core_priority = _POSIX_Priority_To_core( schedparam.sched_priority );
+
+ /*
+ * Set the core scheduling policy information.
+ */
+ rc = _POSIX_Thread_Translate_sched_param(
+ schedpolicy,
+ &schedparam,
+ &budget_algorithm,
+ &budget_callout
+ );
+ if ( rc )
+ return rc;
+
+ /*
+ * Currently all POSIX threads are floating point if the hardware
+ * supports it.
+ */
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ is_fp = true;
+ #else
+ is_fp = false;
+ #endif
+
+ /*
+ * Lock the allocator mutex for protection
+ */
+ _RTEMS_Lock_allocator();
+
+ /*
+ * Allocate the thread control block.
+ *
+ * NOTE: Global threads are not currently supported.
+ */
+ the_thread = _POSIX_Threads_Allocate();
+ if ( !the_thread ) {
+ _RTEMS_Unlock_allocator();
+ return EAGAIN;
+ }
+
+ /*
+ * Initialize the core thread for this task.
+ */
+ name.name_p = NULL; /* posix threads don't have a name by default */
+ status = _Thread_Initialize(
+ &_POSIX_Threads_Information,
+ the_thread,
+ the_attr->stackaddr,
+ _POSIX_Threads_Ensure_minimum_stack(the_attr->stacksize),
+ is_fp,
+ core_priority,
+ true, /* preemptible */
+ budget_algorithm,
+ budget_callout,
+ 0, /* isr level */
+ name /* posix threads don't have a name */
+ );
+
+ if ( !status ) {
+ _POSIX_Threads_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return EAGAIN;
+ }
+
+ /*
+ * finish initializing the per API structure
+ */
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ api->Attributes = *the_attr;
+ api->detachstate = the_attr->detachstate;
+ api->schedpolicy = schedpolicy;
+ api->schedparam = schedparam;
+
+ /*
+ * POSIX threads are allocated and started in one operation.
+ */
+ status = _Thread_Start(
+ the_thread,
+ THREAD_START_POINTER,
+ start_routine,
+ arg,
+ 0 /* unused */
+ );
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * _Thread_Start only fails if the thread was in the incorrect state
+ *
+ * NOTE: This can only happen if someone slips in and touches the
+ * thread while we are creating it.
+ */
+ if ( !status ) {
+ _POSIX_Threads_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return EINVAL;
+ }
+ #endif
+
+ if ( schedpolicy == SCHED_SPORADIC ) {
+ _Watchdog_Insert_ticks(
+ &api->Sporadic_timer,
+ _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
+ );
+ }
+
+ /*
+ * Return the id and indicate we successfully created the thread
+ */
+ *thread = the_thread->Object.id;
+
+ _RTEMS_Unlock_allocator();
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreaddetach.c b/cpukit/posix/src/pthreaddetach.c
new file mode 100644
index 0000000000..6078fcc97e
--- /dev/null
+++ b/cpukit/posix/src/pthreaddetach.c
@@ -0,0 +1,51 @@
+/*
+ * 16.1.4 Detaching a Thread, P1003.1c/Draft 10, p. 149
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_detach(
+ pthread_t thread
+)
+{
+ register Thread_Control *the_thread;
+ POSIX_API_Control *api;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( thread, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+ api->detachstate = PTHREAD_CREATE_DETACHED;
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return ESRCH;
+}
diff --git a/cpukit/posix/src/pthreadequal.c b/cpukit/posix/src/pthreadequal.c
new file mode 100644
index 0000000000..9944026f3e
--- /dev/null
+++ b/cpukit/posix/src/pthreadequal.c
@@ -0,0 +1,93 @@
+/*
+ * 16.1.7 Compare Thread IDs, p1003.1c/Draft 10, p. 153
+ *
+ * NOTE: POSIX does not define the behavior when either thread id is invalid.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/score/thread.h>
+
+int pthread_equal(
+ pthread_t t1,
+ pthread_t t2
+)
+{
+ /*
+ * If the system is configured for debug, then we will do everything we
+ * can to insure that both ids are valid. Otherwise, we will do the
+ * cheapest possible thing to determine if they are equal.
+ */
+
+#ifndef RTEMS_DEBUG
+ return _Objects_Are_ids_equal( t1, t2 );
+#else
+ int status;
+ Objects_Locations location;
+
+ /*
+ * By default this is not a match.
+ */
+
+ status = 0;
+
+ /*
+ * Validate the first id and return 0 if it is not valid
+ */
+
+ (void) _Thread_Get( t1, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ /*
+ * Validate the second id and return 0 if it is not valid
+ */
+
+ (void) _Thread_Get( t2, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _Objects_Are_ids_equal( t1, t2 );
+ _Thread_Unnest_dispatch();
+ _Thread_Enable_dispatch();
+ break;
+
+ case OBJECTS_ERROR:
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ /* t1 must have been valid so exit the critical section */
+ _Thread_Enable_dispatch();
+ /* return status == 0 */
+ break;
+ }
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ /* return status == 0 */
+ break;
+ }
+
+ return status;
+#endif
+}
diff --git a/cpukit/posix/src/pthreadexit.c b/cpukit/posix/src/pthreadexit.c
new file mode 100644
index 0000000000..9efe9d9a47
--- /dev/null
+++ b/cpukit/posix/src/pthreadexit.c
@@ -0,0 +1,67 @@
+/*
+ * 16.1.5.1 Thread Termination, p1003.1c/Draft 10, p. 150
+ *
+ * NOTE: Key destructors are executed in the POSIX api delete extension.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/apimutex.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/pthread.h>
+
+void _POSIX_Thread_Exit(
+ Thread_Control *the_thread,
+ void *value_ptr
+)
+{
+ Objects_Information *the_information;
+
+ the_information = _Objects_Get_information_id( the_thread->Object.id );
+
+ /*
+ * The_information has to be non-NULL. Otherwise, we couldn't be
+ * running in a thread of this API and class.
+ *
+ * NOTE: Lock and unlock in different order so we do not throw a
+ * fatal error when locking the allocator mutex. And after
+ * we unlock, we want to defer the context switch until we
+ * are ready to be switched out. Otherwise, an ISR could
+ * occur and preempt us out while we still hold the
+ * allocator mutex.
+ */
+
+ _RTEMS_Lock_allocator();
+ _Thread_Disable_dispatch();
+
+ the_thread->Wait.return_argument = value_ptr;
+
+ _Thread_Close( the_information, the_thread );
+
+ _POSIX_Threads_Free( the_thread );
+
+ _RTEMS_Unlock_allocator();
+ _Thread_Enable_dispatch();
+}
+
+void pthread_exit(
+ void *value_ptr
+)
+{
+ _POSIX_Thread_Exit( _Thread_Executing, value_ptr );
+}
diff --git a/cpukit/posix/src/pthreadgetcpuclockid.c b/cpukit/posix/src/pthreadgetcpuclockid.c
new file mode 100644
index 0000000000..2ba0dcc3e0
--- /dev/null
+++ b/cpukit/posix/src/pthreadgetcpuclockid.c
@@ -0,0 +1,30 @@
+/*
+ * 20.1.6 Accessing a Thread CPU-time Clock, P1003.4b/Draft 8, p. 58
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+int pthread_getcpuclockid(
+ pthread_t pid,
+ clockid_t *clock_id
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/pthreadgetcputime.c b/cpukit/posix/src/pthreadgetcputime.c
new file mode 100644
index 0000000000..7c9bb46c7b
--- /dev/null
+++ b/cpukit/posix/src/pthreadgetcputime.c
@@ -0,0 +1,31 @@
+/*
+ * 20.1.7 CPU-time Clock Thread Creation Attribute, P1003.4b/Draft 8, p. 59
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_getcputime(
+ pthread_attr_t *attr,
+ int *clock_allowed
+)
+{
+ if ( !attr || !attr->is_initialized || !clock_allowed )
+ return EINVAL;
+
+ *clock_allowed = attr->cputime_clock_allowed;
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
new file mode 100644
index 0000000000..b8e0a83153
--- /dev/null
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -0,0 +1,63 @@
+/*
+ * 13.5.2 Dynamic Thread Scheduling Parameters Access,
+ * P1003.1c/Draft 10, p. 124
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+
+int pthread_getschedparam(
+ pthread_t thread,
+ int *policy,
+ struct sched_param *param
+)
+{
+ Objects_Locations location;
+ POSIX_API_Control *api;
+ register Thread_Control *the_thread;
+
+ if ( !policy || !param )
+ return EINVAL;
+
+ the_thread = _Thread_Get( thread, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+ if ( policy )
+ *policy = api->schedpolicy;
+ if ( param ) {
+ *param = api->schedparam;
+ param->sched_priority =
+ _POSIX_Priority_From_core( the_thread->current_priority );
+ }
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return ESRCH;
+
+}
diff --git a/cpukit/posix/src/pthreadinitthreads.c b/cpukit/posix/src/pthreadinitthreads.c
new file mode 100644
index 0000000000..b7c0fdec3b
--- /dev/null
+++ b/cpukit/posix/src/pthreadinitthreads.c
@@ -0,0 +1,87 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <pthread.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/config.h>
+#include <rtems/posix/key.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_Threads_Initialize_user_threads_body
+ *
+ * This routine creates and starts all configured user
+ * initialzation threads.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Threads_Initialize_user_threads_body(void)
+{
+ int status;
+ uint32_t index;
+ uint32_t maximum;
+ posix_initialization_threads_table *user_threads;
+ pthread_t thread_id;
+ pthread_attr_t attr;
+
+ user_threads = Configuration_POSIX_API.User_initialization_threads_table;
+ maximum = Configuration_POSIX_API.number_of_initialization_threads;
+
+ if ( !user_threads || maximum == 0 )
+ return;
+
+ /*
+ * Be careful .. if the default attribute set changes, this may need to.
+ *
+ * Setting the attributes explicitly is critical, since we don't want
+ * to inherit the idle tasks attributes.
+ */
+
+ for ( index=0 ; index < maximum ; index++ ) {
+ /*
+ * There is no way for these calls to fail in this situation.
+ */
+ (void) pthread_attr_init( &attr );
+ (void) pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
+ (void) pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size);
+
+ status = pthread_create(
+ &thread_id,
+ &attr,
+ user_threads[ index ].thread_entry,
+ NULL
+ );
+ if ( status )
+ _Internal_error_Occurred( INTERNAL_ERROR_POSIX_API, true, status );
+ }
+}
+
diff --git a/cpukit/posix/src/pthreadjoin.c b/cpukit/posix/src/pthreadjoin.c
new file mode 100644
index 0000000000..8ee9888b94
--- /dev/null
+++ b/cpukit/posix/src/pthreadjoin.c
@@ -0,0 +1,75 @@
+/*
+ * 16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/pthread.h>
+
+int pthread_join(
+ pthread_t thread,
+ void **value_ptr
+)
+{
+ register Thread_Control *the_thread;
+ POSIX_API_Control *api;
+ Objects_Locations location;
+ void *return_pointer;
+
+ the_thread = _Thread_Get( thread, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ if ( api->detachstate == PTHREAD_CREATE_DETACHED ) {
+ _Thread_Enable_dispatch();
+ return EINVAL;
+ }
+
+ if ( _Thread_Is_executing( the_thread ) ) {
+ _Thread_Enable_dispatch();
+ return EDEADLK;
+ }
+
+ /*
+ * Put ourself on the threads join list
+ */
+
+ _Thread_Executing->Wait.return_argument = &return_pointer;
+
+ _Thread_queue_Enter_critical_section( &api->Join_List );
+
+ _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT );
+
+ _Thread_Enable_dispatch();
+
+ if ( value_ptr )
+ *value_ptr = return_pointer;
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return ESRCH;
+}
diff --git a/cpukit/posix/src/pthreadkill.c b/cpukit/posix/src/pthreadkill.c
new file mode 100644
index 0000000000..777ee6ad0c
--- /dev/null
+++ b/cpukit/posix/src/pthreadkill.c
@@ -0,0 +1,80 @@
+/*
+ * 3.3.10 Send a Signal to a Thread, P1003.1c/D10, p. 43
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/score/isr.h>
+#include <rtems/seterr.h>
+
+int pthread_kill(
+ pthread_t thread,
+ int sig
+)
+{
+ POSIX_API_Control *api;
+ Thread_Control *the_thread;
+ Objects_Locations location;
+
+ if ( !sig )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !is_valid_signo(sig) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ the_thread = _Thread_Get( thread, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ /*
+ * If sig == 0 then just validate arguments
+ */
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ if ( sig ) {
+
+ if ( _POSIX_signals_Vectors[ sig ].sa_handler == SIG_IGN ) {
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ /* XXX critical section */
+
+ api->signals_pending |= signo_to_mask( sig );
+
+ (void) _POSIX_signals_Unblock_thread( the_thread, sig, NULL );
+
+ if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) )
+ _Thread_Dispatch_necessary = true;
+ }
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( ESRCH );
+}
diff --git a/cpukit/posix/src/pthreadonce.c b/cpukit/posix/src/pthreadonce.c
new file mode 100644
index 0000000000..8e4a9dc6d8
--- /dev/null
+++ b/cpukit/posix/src/pthreadonce.c
@@ -0,0 +1,44 @@
+/*
+ * 16.1.8 Dynamic Package Initialization, P1003.1c/Draft 10, p. 154
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+
+int pthread_once(
+ pthread_once_t *once_control,
+ void (*init_routine)(void)
+)
+{
+ if ( !once_control || !init_routine )
+ return EINVAL;
+
+ if ( !once_control->init_executed ) {
+ rtems_mode saveMode;
+ rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &saveMode);
+ if ( !once_control->init_executed ) {
+ once_control->is_initialized = true;
+ once_control->init_executed = true;
+ (*init_routine)();
+ }
+ rtems_task_mode(saveMode, RTEMS_PREEMPT_MASK, &saveMode);
+ }
+ return 0;
+}
diff --git a/cpukit/posix/src/pthreadself.c b/cpukit/posix/src/pthreadself.c
new file mode 100644
index 0000000000..c1baf85177
--- /dev/null
+++ b/cpukit/posix/src/pthreadself.c
@@ -0,0 +1,27 @@
+/*
+ * 16.1.6 Get Calling Thread's ID, p1003.1c/Draft 10, p. 152
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+
+pthread_t pthread_self( void )
+{
+ return _Thread_Executing->Object.id;
+}
diff --git a/cpukit/posix/src/pthreadsetcputime.c b/cpukit/posix/src/pthreadsetcputime.c
new file mode 100644
index 0000000000..70b9594ab9
--- /dev/null
+++ b/cpukit/posix/src/pthreadsetcputime.c
@@ -0,0 +1,38 @@
+/*
+ * 20.1.7 CPU-time Clock Thread Creation Attribute, P1003.4b/Draft 8, p. 59
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+int pthread_attr_setcputime(
+ pthread_attr_t *attr,
+ int clock_allowed
+)
+{
+ if ( !attr || !attr->is_initialized )
+ return EINVAL;
+
+ switch ( clock_allowed ) {
+ case CLOCK_ENABLED:
+ case CLOCK_DISABLED:
+ attr->cputime_clock_allowed = clock_allowed;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
new file mode 100644
index 0000000000..14edfa0218
--- /dev/null
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -0,0 +1,107 @@
+/*
+ * 13.5.2 Dynamic Thread Scheduling Parameters Access,
+ * P1003.1c/Draft 10, p. 124
+ */
+
+/* COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int pthread_setschedparam(
+ pthread_t thread,
+ int policy,
+ struct sched_param *param
+)
+{
+ register Thread_Control *the_thread;
+ POSIX_API_Control *api;
+ Thread_CPU_budget_algorithms budget_algorithm;
+ Thread_CPU_budget_algorithm_callout budget_callout;
+ Objects_Locations location;
+ int rc;
+
+ /*
+ * Check all the parameters
+ */
+ if ( !param )
+ return EINVAL;
+
+ rc = _POSIX_Thread_Translate_sched_param(
+ policy,
+ param,
+ &budget_algorithm,
+ &budget_callout
+ );
+ if ( rc )
+ return rc;
+
+ /*
+ * Actually change the scheduling policy and parameters
+ */
+ the_thread = _Thread_Get( thread, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ if ( api->schedpolicy == SCHED_SPORADIC )
+ (void) _Watchdog_Remove( &api->Sporadic_timer );
+
+ api->schedpolicy = policy;
+ api->schedparam = *param;
+ the_thread->budget_algorithm = budget_algorithm;
+ the_thread->budget_callout = budget_callout;
+
+ switch ( api->schedpolicy ) {
+ case SCHED_OTHER:
+ case SCHED_FIFO:
+ case SCHED_RR:
+ the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
+
+ the_thread->real_priority =
+ _POSIX_Priority_To_core( api->schedparam.sched_priority );
+
+ _Thread_Change_priority(
+ the_thread,
+ the_thread->real_priority,
+ true
+ );
+ break;
+
+ case SCHED_SPORADIC:
+ api->ss_high_priority = api->schedparam.sched_priority;
+ _Watchdog_Remove( &api->Sporadic_timer );
+ _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
+ break;
+ }
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return ESRCH;
+}
diff --git a/cpukit/posix/src/pthreadsigmask.c b/cpukit/posix/src/pthreadsigmask.c
new file mode 100644
index 0000000000..c97e75a89e
--- /dev/null
+++ b/cpukit/posix/src/pthreadsigmask.c
@@ -0,0 +1,72 @@
+/*
+ * 3.3.5 Examine and Change Blocked Signals, P1003.1b-1993, p. 73
+ *
+ * NOTE: P1003.1c/D10, p. 37 adds pthread_sigmask().
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/seterr.h>
+
+int pthread_sigmask(
+ int how,
+ const sigset_t *set,
+ sigset_t *oset
+)
+{
+ POSIX_API_Control *api;
+
+ if ( !set && !oset )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ if ( oset )
+ *oset = api->signals_blocked;
+
+ if ( !set )
+ return 0;
+
+ switch ( how ) {
+ case SIG_BLOCK:
+ api->signals_blocked |= *set;
+ break;
+ case SIG_UNBLOCK:
+ api->signals_blocked &= ~*set;
+ break;
+ case SIG_SETMASK:
+ api->signals_blocked = *set;
+ break;
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ /* XXX are there critical section problems here? */
+
+ /* XXX evaluate the new set */
+
+ if ( ~api->signals_blocked &
+ (api->signals_pending | _POSIX_signals_Pending) ) {
+ _Thread_Dispatch();
+ }
+
+ return 0;
+}
diff --git a/cpukit/posix/src/ptimer.c b/cpukit/posix/src/ptimer.c
new file mode 100644
index 0000000000..6ded55c0a6
--- /dev/null
+++ b/cpukit/posix/src/ptimer.c
@@ -0,0 +1,72 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * ptimer.c,v 1.1 1996/06/03 16:29:58 joel Exp
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+#include <limits.h> /* _POSIX_PATH_MAX */
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/posix/time.h>
+
+/************************************/
+/* These includes are now necessary */
+/************************************/
+
+#include <unistd.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/score/wkspace.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include <rtems/posix/timer.h>
+
+/*
+ * _POSIX_Timer_Manager_initialization
+ *
+ * Description:
+ *
+ * Initialize the internal structure in which the data of all
+ * the timers are stored
+ */
+
+void _POSIX_Timer_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Timer_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_TIMERS, /* object class */
+ Configuration_POSIX_API.maximum_timers,
+ /* maximum objects of this class */
+ sizeof( POSIX_Timer_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/rwlockattrdestroy.c b/cpukit/posix/src/rwlockattrdestroy.c
new file mode 100644
index 0000000000..aa4b6e3345
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrdestroy.c
@@ -0,0 +1,41 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * RWLock Initialization Attributes
+ */
+
+int pthread_rwlockattr_destroy(
+ pthread_rwlockattr_t *attr
+)
+{
+ if ( !attr || attr->is_initialized == false )
+ return EINVAL;
+
+ attr->is_initialized = false;
+ return 0;
+}
diff --git a/cpukit/posix/src/rwlockattrgetpshared.c b/cpukit/posix/src/rwlockattrgetpshared.c
new file mode 100644
index 0000000000..b0536df1b0
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrgetpshared.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * RWLock Attributes Get Process Shared
+ */
+
+int pthread_rwlockattr_getpshared(
+ const pthread_rwlockattr_t *attr,
+ int *pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ *pshared = attr->process_shared;
+ return 0;
+}
diff --git a/cpukit/posix/src/rwlockattrinit.c b/cpukit/posix/src/rwlockattrinit.c
new file mode 100644
index 0000000000..77f5992038
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrinit.c
@@ -0,0 +1,36 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+
+/*PAGE
+ *
+ * RWLock Attributes Initialization
+ */
+
+int pthread_rwlockattr_init(
+ pthread_rwlockattr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ attr->is_initialized = true;
+ attr->process_shared = PTHREAD_PROCESS_PRIVATE;
+ return 0;
+}
diff --git a/cpukit/posix/src/rwlockattrsetpshared.c b/cpukit/posix/src/rwlockattrsetpshared.c
new file mode 100644
index 0000000000..92fc38fa9e
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrsetpshared.c
@@ -0,0 +1,44 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * RWLock Attributes Set Process Shared
+ */
+
+int pthread_rwlockattr_setpshared(
+ pthread_rwlockattr_t *attr,
+ int pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_SHARED:
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->process_shared = pshared;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/sched_getparam.c b/cpukit/posix/src/sched_getparam.c
new file mode 100644
index 0000000000..c25286bdc3
--- /dev/null
+++ b/cpukit/posix/src/sched_getparam.c
@@ -0,0 +1,30 @@
+/*
+ * 13.3.2 Set Scheduling Parameters, P1003.1b-1993, p. 253
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+
+int sched_getparam(
+ pid_t pid __attribute__((unused)),
+ struct sched_param *param __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/sched_getprioritymax.c b/cpukit/posix/src/sched_getprioritymax.c
new file mode 100644
index 0000000000..9f8965e4d5
--- /dev/null
+++ b/cpukit/posix/src/sched_getprioritymax.c
@@ -0,0 +1,41 @@
+/*
+ * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/priority.h>
+
+int sched_get_priority_max(
+ int policy
+)
+{
+ switch ( policy ) {
+ case SCHED_OTHER:
+ case SCHED_FIFO:
+ case SCHED_RR:
+ case SCHED_SPORADIC:
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ return POSIX_SCHEDULER_MAXIMUM_PRIORITY;
+}
diff --git a/cpukit/posix/src/sched_getprioritymin.c b/cpukit/posix/src/sched_getprioritymin.c
new file mode 100644
index 0000000000..88e1170f12
--- /dev/null
+++ b/cpukit/posix/src/sched_getprioritymin.c
@@ -0,0 +1,41 @@
+/*
+ * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/priority.h>
+
+int sched_get_priority_min(
+ int policy
+)
+{
+ switch ( policy ) {
+ case SCHED_OTHER:
+ case SCHED_FIFO:
+ case SCHED_RR:
+ case SCHED_SPORADIC:
+ break;
+
+ default:
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ return POSIX_SCHEDULER_MINIMUM_PRIORITY;
+}
diff --git a/cpukit/posix/src/sched_getscheduler.c b/cpukit/posix/src/sched_getscheduler.c
new file mode 100644
index 0000000000..8afbcfd486
--- /dev/null
+++ b/cpukit/posix/src/sched_getscheduler.c
@@ -0,0 +1,33 @@
+/*
+ * 13.3.4 Get Scheduling Policy, P1003.1b-1993, p. 256
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/thread.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int sched_getscheduler(
+ pid_t pid __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/sched_rr_get_interval.c b/cpukit/posix/src/sched_rr_get_interval.c
new file mode 100644
index 0000000000..c9e3e280ca
--- /dev/null
+++ b/cpukit/posix/src/sched_rr_get_interval.c
@@ -0,0 +1,45 @@
+/*
+ * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h> /* getpid */
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/timespec.h>
+#include <rtems/seterr.h>
+
+int sched_rr_get_interval(
+ pid_t pid,
+ struct timespec *interval
+)
+{
+ /*
+ * Only supported for the "calling process" (i.e. this node).
+ */
+
+ if ( pid && pid != getpid() )
+ rtems_set_errno_and_return_minus_one( ESRCH );
+
+ if ( !interval )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ _Timespec_From_ticks( _Thread_Ticks_per_timeslice, interval );
+ return 0;
+}
diff --git a/cpukit/posix/src/sched_setparam.c b/cpukit/posix/src/sched_setparam.c
new file mode 100644
index 0000000000..155ed2d11b
--- /dev/null
+++ b/cpukit/posix/src/sched_setparam.c
@@ -0,0 +1,34 @@
+/*
+ * 13.3.1 Set Scheduling Parameters, P1003.1b-1993, p. 252
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/thread.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int sched_setparam(
+ pid_t pid __attribute__((unused)),
+ const struct sched_param *param __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/sched_setscheduler.c b/cpukit/posix/src/sched_setscheduler.c
new file mode 100644
index 0000000000..f0bb5496fa
--- /dev/null
+++ b/cpukit/posix/src/sched_setscheduler.c
@@ -0,0 +1,36 @@
+/*
+ * 13.3.3 Set Scheduling Policy and Scheduling Parameters,
+ * P1003.1b-1993, p. 254
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/thread.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int sched_setscheduler(
+ pid_t pid __attribute__((unused)),
+ int policy __attribute__((unused)),
+ const struct sched_param *param __attribute__((unused))
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/sched_yield.c b/cpukit/posix/src/sched_yield.c
new file mode 100644
index 0000000000..b6c5c4fce4
--- /dev/null
+++ b/cpukit/posix/src/sched_yield.c
@@ -0,0 +1,35 @@
+/*
+ * 13.3.5 Yield Processor, P1003.1b-1993, p. 257
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sched.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/thread.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int sched_yield( void )
+{
+ _Thread_Disable_dispatch();
+ _Scheduler_Yield();
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/semaphore.c b/cpukit/posix/src/semaphore.c
new file mode 100644
index 0000000000..e84bea87a4
--- /dev/null
+++ b/cpukit/posix/src/semaphore.c
@@ -0,0 +1,60 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Manager_initialization
+ *
+ * This routine initializes all semaphore manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Semaphore_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Semaphore_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_SEMAPHORES, /* object class */
+ Configuration_POSIX_API.maximum_semaphores,
+ /* maximum objects of this class */
+ sizeof( POSIX_Semaphore_Control ),
+ /* size of this object's control block */
+ true, /* true if names for this object are strings */
+ _POSIX_PATH_MAX /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/semaphorecreatesupp.c b/cpukit/posix/src/semaphorecreatesupp.c
new file mode 100644
index 0000000000..42e530bf07
--- /dev/null
+++ b/cpukit/posix/src/semaphorecreatesupp.c
@@ -0,0 +1,113 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+#include <string.h> /* strlen */
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/* pure ANSI mode does not have this prototype */
+size_t strnlen(const char *, size_t);
+
+/*
+ * _POSIX_Semaphore_Create_support
+ *
+ * This routine does the actual creation and initialization of
+ * a poxix semaphore. It is a support routine for sem_init and
+ * sem_open.
+ */
+int _POSIX_Semaphore_Create_support(
+ const char *name,
+ int pshared,
+ unsigned int value,
+ POSIX_Semaphore_Control **the_sem
+)
+{
+ POSIX_Semaphore_Control *the_semaphore;
+ CORE_semaphore_Attributes *the_sem_attr;
+ char *name_p = (char *)name;
+
+ /* Sharing semaphores among processes is not currently supported */
+ if (pshared != 0)
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+
+ if ( name ) {
+ if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
+ rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
+ }
+
+ _Thread_Disable_dispatch();
+
+ the_semaphore = _POSIX_Semaphore_Allocate();
+
+ if ( !the_semaphore ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( ENOSPC );
+ }
+
+ the_semaphore->process_shared = pshared;
+
+ if ( name ) {
+ the_semaphore->named = true;
+ the_semaphore->open_count = 1;
+ the_semaphore->linked = true;
+ } else {
+ the_semaphore->named = false;
+ the_semaphore->open_count = 0;
+ the_semaphore->linked = false;
+ }
+
+ the_sem_attr = &the_semaphore->Semaphore.Attributes;
+
+ /*
+ * POSIX does not appear to specify what the discipline for
+ * blocking tasks on this semaphore should be. It could somehow
+ * be derived from the current scheduling policy. One
+ * thing is certain, no matter what we decide, it won't be
+ * the same as all other POSIX implementations. :)
+ */
+ the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
+
+ /*
+ * This effectively disables limit checking.
+ */
+ the_sem_attr->maximum_count = 0xFFFFFFFF;
+
+ _CORE_semaphore_Initialize( &the_semaphore->Semaphore, the_sem_attr, value );
+
+ /*
+ * Make the semaphore available for use.
+ */
+ _Objects_Open_string(
+ &_POSIX_Semaphore_Information,
+ &the_semaphore->Object,
+ name_p
+ );
+
+ *the_sem = the_semaphore;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/semaphoredeletesupp.c b/cpukit/posix/src/semaphoredeletesupp.c
new file mode 100644
index 0000000000..b9b8408c76
--- /dev/null
+++ b/cpukit/posix/src/semaphoredeletesupp.c
@@ -0,0 +1,50 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Delete
+ */
+
+void _POSIX_Semaphore_Delete(
+ POSIX_Semaphore_Control *the_semaphore
+)
+{
+ if ( !the_semaphore->linked && !the_semaphore->open_count ) {
+ _Objects_Close( &_POSIX_Semaphore_Information, &the_semaphore->Object );
+
+ _CORE_semaphore_Flush(
+ &the_semaphore->Semaphore,
+ NULL,
+ -1
+ );
+
+ _POSIX_Semaphore_Free( the_semaphore );
+ }
+}
diff --git a/cpukit/posix/src/semaphorenametoid.c b/cpukit/posix/src/semaphorenametoid.c
new file mode 100644
index 0000000000..e550910653
--- /dev/null
+++ b/cpukit/posix/src/semaphorenametoid.c
@@ -0,0 +1,63 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Name_to_id
+ *
+ * Look up the specified name and attempt to locate the id
+ * for the associated semaphore.
+ */
+
+int _POSIX_Semaphore_Name_to_id(
+ const char *name,
+ sem_t *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+ Objects_Id the_id;
+
+ if ( !name )
+ return EINVAL;
+
+ if ( !name[0] )
+ return EINVAL;
+
+ status = _Objects_Name_to_id_string(
+ &_POSIX_Semaphore_Information,
+ name,
+ &the_id
+ );
+ *id = the_id;
+
+ if ( status == OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL )
+ return 0;
+
+ return ENOENT;
+}
diff --git a/cpukit/posix/src/semaphoretranslatereturncode.c b/cpukit/posix/src/semaphoretranslatereturncode.c
new file mode 100644
index 0000000000..c87f5c93c8
--- /dev/null
+++ b/cpukit/posix/src/semaphoretranslatereturncode.c
@@ -0,0 +1,59 @@
+/*
+ * POSIX Semaphore Error Translation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coresem.h>
+
+/*
+ * _POSIX_Semaphore_Translate_core_semaphore_return_code
+ *
+ * Input parameters:
+ * the_semaphore_status - semaphore status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static int _POSIX_Semaphore_Return_codes[CORE_SEMAPHORE_STATUS_LAST + 1] = {
+ 0, /* CORE_SEMAPHORE_STATUS_SUCCESSFUL */
+ EAGAIN, /* CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT */
+ EAGAIN, /* CORE_SEMAPHORE_WAS_DELETED */
+ ETIMEDOUT, /* CORE_SEMAPHORE_TIMEOUT */
+ /* The next error can not occur since we set the maximum
+ * count to the largest value the count can hold.
+ */
+ ENOSYS, /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */
+};
+
+
+int _POSIX_Semaphore_Translate_core_semaphore_return_code(
+ CORE_semaphore_Status the_semaphore_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_semaphore_status > CORE_SEMAPHORE_STATUS_LAST )
+ return EINVAL;
+ #endif
+ return _POSIX_Semaphore_Return_codes[the_semaphore_status];
+}
diff --git a/cpukit/posix/src/semaphorewaitsupp.c b/cpukit/posix/src/semaphorewaitsupp.c
new file mode 100644
index 0000000000..76e7edc4bc
--- /dev/null
+++ b/cpukit/posix/src/semaphorewaitsupp.c
@@ -0,0 +1,73 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * _POSIX_Semaphore_Wait_support
+ */
+
+int _POSIX_Semaphore_Wait_support(
+ sem_t *sem,
+ bool blocking,
+ Watchdog_Interval timeout
+)
+{
+ POSIX_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _POSIX_Semaphore_Get( sem, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _CORE_semaphore_Seize(
+ &the_semaphore->Semaphore,
+ the_semaphore->Object.id,
+ blocking,
+ timeout
+ );
+ _Thread_Enable_dispatch();
+
+ if ( !_Thread_Executing->Wait.return_code )
+ return 0;
+
+ rtems_set_errno_and_return_minus_one(
+ _POSIX_Semaphore_Translate_core_semaphore_return_code(
+ _Thread_Executing->Wait.return_code
+ )
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/semclose.c b/cpukit/posix/src/semclose.c
new file mode 100644
index 0000000000..c265c867d5
--- /dev/null
+++ b/cpukit/posix/src/semclose.c
@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+
+/*PAGE
+ *
+ * sem_close
+ *
+ * Routine to close a semaphore that has been opened or initialized.
+ *
+ * 11.2.4 Close a Named Semaphore, P1003.1b-1993, p.224
+ */
+
+int sem_close(
+ sem_t *sem
+)
+{
+ register POSIX_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _POSIX_Semaphore_Get( sem, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_semaphore->open_count -= 1;
+ _POSIX_Semaphore_Delete( the_semaphore );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/semdestroy.c b/cpukit/posix/src/semdestroy.c
new file mode 100644
index 0000000000..8a3b20c23f
--- /dev/null
+++ b/cpukit/posix/src/semdestroy.c
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.2 Destroy an Unnamed Semaphore, P1003.1b-1993, p.220
+ */
+
+int sem_destroy(
+ sem_t *sem
+)
+{
+ register POSIX_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _POSIX_Semaphore_Get( sem, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ /*
+ * Undefined operation on a named semaphore.
+ */
+
+ if ( the_semaphore->named == true ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ _POSIX_Semaphore_Delete( the_semaphore );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/semgetvalue.c b/cpukit/posix/src/semgetvalue.c
new file mode 100644
index 0000000000..81042bf316
--- /dev/null
+++ b/cpukit/posix/src/semgetvalue.c
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.8 Get the Value of a Semaphore, P1003.1b-1993, p.229
+ */
+
+int sem_getvalue(
+ sem_t *sem,
+ int *sval
+)
+{
+ register POSIX_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _POSIX_Semaphore_Get( sem, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ *sval = _CORE_semaphore_Get_count( &the_semaphore->Semaphore );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/seminit.c b/cpukit/posix/src/seminit.c
new file mode 100644
index 0000000000..132be509e7
--- /dev/null
+++ b/cpukit/posix/src/seminit.c
@@ -0,0 +1,58 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.1 Initialize an Unnamed Semaphore, P1003.1b-1993, p.219
+ */
+
+int sem_init(
+ sem_t *sem,
+ int pshared,
+ unsigned int value
+)
+{
+ int status;
+ POSIX_Semaphore_Control *the_semaphore;
+
+ if ( !sem )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ status = _POSIX_Semaphore_Create_support(
+ NULL,
+ pshared,
+ value,
+ &the_semaphore
+ );
+
+ if ( status != -1 )
+ *sem = the_semaphore->Object.id;
+
+ return status;
+}
diff --git a/cpukit/posix/src/semopen.c b/cpukit/posix/src/semopen.c
new file mode 100644
index 0000000000..b51d2043be
--- /dev/null
+++ b/cpukit/posix/src/semopen.c
@@ -0,0 +1,136 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * sem_open
+ *
+ * Opens a named semaphore. Used in conjunction with the sem_close
+ * and sem_unlink commands.
+ *
+ * 11.2.3 Initialize/Open a Named Semaphore, P1003.1b-1993, p.221
+ *
+ * NOTE: When oflag is O_CREAT, then optional third and fourth
+ * parameters must be present.
+ */
+
+sem_t *sem_open(
+ const char *name,
+ int oflag,
+ ...
+ /* mode_t mode, */
+ /* unsigned int value */
+)
+{
+ va_list arg;
+ mode_t mode;
+ unsigned int value = 0;
+ int status;
+ sem_t the_semaphore_id;
+ sem_t *id;
+ POSIX_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ _Thread_Disable_dispatch();
+
+ if ( oflag & O_CREAT ) {
+ va_start(arg, oflag);
+ mode = (mode_t) va_arg( arg, unsigned int );
+ value = va_arg( arg, unsigned int );
+ va_end(arg);
+ }
+
+ status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id );
+
+ /*
+ * If the name to id translation worked, then the semaphore exists
+ * and we can just return a pointer to the id. Otherwise we may
+ * need to check to see if this is a "semaphore does not exist"
+ * or some other miscellaneous error on the name.
+ */
+
+ if ( status ) {
+
+ /*
+ * Unless provided a valid name that did not already exist
+ * and we are willing to create then it is an error.
+ */
+
+ if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one_cast( status, sem_t * );
+ }
+ } else {
+
+ /*
+ * Check for existence with creation.
+ */
+
+ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one_cast( EEXIST, sem_t * );
+ }
+
+ the_semaphore = _POSIX_Semaphore_Get( &the_semaphore_id, &location );
+ the_semaphore->open_count += 1;
+ _Thread_Enable_dispatch();
+ _Thread_Enable_dispatch();
+ goto return_id;
+ }
+
+ /*
+ * At this point, the semaphore does not exist and everything has been
+ * checked. We should go ahead and create a semaphore.
+ */
+
+ status =_POSIX_Semaphore_Create_support(
+ name,
+ false, /* not shared across processes */
+ value,
+ &the_semaphore
+ );
+
+ /*
+ * errno was set by Create_support, so don't set it again.
+ */
+
+ _Thread_Enable_dispatch();
+
+ if ( status == -1 )
+ return SEM_FAILED;
+
+return_id:
+ #if defined(RTEMS_USE_16_BIT_OBJECT)
+ the_semaphore->Semaphore_id = the_semaphore->Object.id;
+ id = &the_semaphore->Semaphore_id;
+ #else
+ id = (sem_t *)&the_semaphore->Object.id;
+ #endif
+ return id;
+}
diff --git a/cpukit/posix/src/sempost.c b/cpukit/posix/src/sempost.c
new file mode 100644
index 0000000000..785ad3d966
--- /dev/null
+++ b/cpukit/posix/src/sempost.c
@@ -0,0 +1,66 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.7 Unlock a Semaphore, P1003.1b-1993, p.227
+ */
+
+int sem_post(
+ sem_t *sem
+)
+{
+ register POSIX_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _POSIX_Semaphore_Get( sem, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _CORE_semaphore_Surrender(
+ &the_semaphore->Semaphore,
+ the_semaphore->Object.id,
+#if defined(RTEMS_MULTIPROCESSING)
+ NULL /* XXX need to define a routine to handle this case */
+#else
+ NULL
+#endif
+ );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/semtimedwait.c b/cpukit/posix/src/semtimedwait.c
new file mode 100644
index 0000000000..60faafc242
--- /dev/null
+++ b/cpukit/posix/src/semtimedwait.c
@@ -0,0 +1,81 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226
+ *
+ * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27
+ */
+
+int sem_timedwait(
+ sem_t *sem,
+ const struct timespec *abstime
+)
+{
+ Watchdog_Interval ticks;
+ bool do_wait = true;
+ POSIX_Absolute_timeout_conversion_results_t status;
+ int lock_status;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ *
+ * If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ * POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ * then we should not wait.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
+ do_wait = false;
+
+ lock_status = _POSIX_Semaphore_Wait_support( sem, do_wait, ticks );
+
+ /*
+ * This service only gives us the option to block. We used a polling
+ * attempt to obtain if the abstime was not in the future. If we did
+ * not obtain the semaphore, then not look at the status immediately,
+ * make sure the right reason is returned.
+ */
+ if ( !do_wait && (lock_status == EBUSY) ) {
+ if ( lock_status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ if ( lock_status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
+ lock_status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
+ rtems_set_errno_and_return_minus_one( ETIMEDOUT );
+ }
+
+ return lock_status;
+}
diff --git a/cpukit/posix/src/semtrywait.c b/cpukit/posix/src/semtrywait.c
new file mode 100644
index 0000000000..fdf50be29d
--- /dev/null
+++ b/cpukit/posix/src/semtrywait.c
@@ -0,0 +1,42 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226
+ *
+ * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27
+ */
+
+int sem_trywait(
+ sem_t *sem
+)
+{
+ return _POSIX_Semaphore_Wait_support(sem, false, THREAD_QUEUE_WAIT_FOREVER);
+}
diff --git a/cpukit/posix/src/semunlink.c b/cpukit/posix/src/semunlink.c
new file mode 100644
index 0000000000..864749c6ac
--- /dev/null
+++ b/cpukit/posix/src/semunlink.c
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * sem_unlink
+ *
+ * Unlinks a named semaphore, sem_close must also be called to remove
+ * the semaphore.
+ *
+ * 11.2.5 Remove a Named Semaphore, P1003.1b-1993, p.225
+ */
+
+int sem_unlink(
+ const char *name
+)
+{
+ int status;
+ register POSIX_Semaphore_Control *the_semaphore;
+ sem_t the_semaphore_id;
+
+ _Thread_Disable_dispatch();
+
+ status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id );
+ if ( status != 0 ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( status );
+ }
+
+ the_semaphore = (POSIX_Semaphore_Control *) _Objects_Get_local_object(
+ &_POSIX_Semaphore_Information,
+ _Objects_Get_index( the_semaphore_id )
+ );
+
+ the_semaphore->linked = false;
+ _POSIX_Semaphore_Namespace_remove( the_semaphore );
+ _POSIX_Semaphore_Delete( the_semaphore );
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/semwait.c b/cpukit/posix/src/semwait.c
new file mode 100644
index 0000000000..462c31ccda
--- /dev/null
+++ b/cpukit/posix/src/semwait.c
@@ -0,0 +1,42 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <limits.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/time.h>
+#include <rtems/seterr.h>
+
+/*PAGE
+ *
+ * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226
+ *
+ * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27
+ */
+
+int sem_wait(
+ sem_t *sem
+)
+{
+ return _POSIX_Semaphore_Wait_support( sem, true, THREAD_QUEUE_WAIT_FOREVER );
+}
diff --git a/cpukit/posix/src/setcancelstate.c b/cpukit/posix/src/setcancelstate.c
new file mode 100644
index 0000000000..7b7543b639
--- /dev/null
+++ b/cpukit/posix/src/setcancelstate.c
@@ -0,0 +1,66 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+/*
+ * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
+ */
+
+int pthread_setcancelstate(
+ int state,
+ int *oldstate
+)
+{
+ POSIX_API_Control *thread_support;
+
+ /*
+ * Don't even think about deleting a resource from an ISR.
+ * Besides this request is supposed to be for _Thread_Executing
+ * and the ISR context is not a thread.
+ */
+
+ if ( _ISR_Is_in_progress() )
+ return EPROTO;
+
+ if ( !oldstate )
+ return EINVAL;
+
+ if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE )
+ return EINVAL;
+
+ thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ _Thread_Disable_dispatch();
+ *oldstate = thread_support->cancelability_state;
+ thread_support->cancelability_state = state;
+
+ _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch(_Thread_Executing);
+
+ /*
+ * _Thread_Enable_dispatch is invoked by above call.
+ */
+
+ return 0;
+}
diff --git a/cpukit/posix/src/setcanceltype.c b/cpukit/posix/src/setcanceltype.c
new file mode 100644
index 0000000000..85f645bad4
--- /dev/null
+++ b/cpukit/posix/src/setcanceltype.c
@@ -0,0 +1,65 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+/*
+ * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
+ */
+
+int pthread_setcanceltype(
+ int type,
+ int *oldtype
+)
+{
+ POSIX_API_Control *thread_support;
+
+ /*
+ * Don't even think about deleting a resource from an ISR.
+ * Besides this request is supposed to be for _Thread_Executing
+ * and the ISR context is not a thread.
+ */
+
+ if ( _ISR_Is_in_progress() )
+ return EPROTO;
+
+ if ( !oldtype )
+ return EINVAL;
+
+ if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
+ return EINVAL;
+
+ thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ _Thread_Disable_dispatch();
+ *oldtype = thread_support->cancelability_type;
+ thread_support->cancelability_type = type;
+
+ _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch(_Thread_Executing);
+
+ /*
+ * _Thread_Enable_dispatch is invoked by above call.
+ */
+ return 0;
+}
diff --git a/cpukit/posix/src/setitimer.c b/cpukit/posix/src/setitimer.c
new file mode 100644
index 0000000000..24a4723100
--- /dev/null
+++ b/cpukit/posix/src/setitimer.c
@@ -0,0 +1,43 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int setitimer(
+ int which,
+ const struct itimerval *value,
+ struct itimerval *ovalue
+)
+{
+ if ( !value )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ if ( !ovalue )
+ rtems_set_errno_and_return_minus_one( EFAULT );
+
+ switch ( which ) {
+ case ITIMER_REAL:
+ case ITIMER_VIRTUAL:
+ case ITIMER_PROF:
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+ default:
+ break;
+ }
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
+
diff --git a/cpukit/posix/src/sigaction.c b/cpukit/posix/src/sigaction.c
new file mode 100644
index 0000000000..b92154663c
--- /dev/null
+++ b/cpukit/posix/src/sigaction.c
@@ -0,0 +1,93 @@
+/*
+ * 3.3.4 Examine and Change Signal Action, P1003.1b-1993, p. 70
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/seterr.h>
+#include <rtems/score/isr.h>
+
+/*
+ * PARAMETERS_PASSING_S is defined in ptimer.c
+ */
+
+extern void PARAMETERS_PASSING_S (int num_signal, const struct sigaction inf);
+
+int sigaction(
+ int sig,
+ const struct sigaction *act,
+ struct sigaction *oact
+)
+{
+ ISR_Level level;
+
+ if ( oact )
+ *oact = _POSIX_signals_Vectors[ sig ];
+
+ if ( !sig )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !is_valid_signo(sig) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * Some signals cannot be ignored (P1003.1b-1993, pp. 70-72 and references.
+ *
+ * NOTE: Solaris documentation claims to "silently enforce" this which
+ * contradicts the POSIX specification.
+ */
+
+ if ( sig == SIGKILL )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * Evaluate the new action structure and set the global signal vector
+ * appropriately.
+ */
+
+ if ( act ) {
+
+ /*
+ * Unless the user is installing the default signal actions, then
+ * we can just copy the provided sigaction structure into the vectors.
+ */
+
+ _ISR_Disable( level );
+ if ( act->sa_handler == SIG_DFL ) {
+ _POSIX_signals_Vectors[ sig ] = _POSIX_signals_Default_vectors[ sig ];
+ } else {
+ _POSIX_signals_Clear_process_signals( sig );
+ _POSIX_signals_Vectors[ sig ] = *act;
+ }
+ _ISR_Enable( level );
+ }
+
+ /*
+ * No need to evaluate or dispatch because:
+ *
+ * + If we were ignoring the signal before, none could be pending
+ * now (signals not posted when SIG_IGN).
+ * + If we are now ignoring a signal that was previously pending,
+ * we clear the pending signal indicator.
+ */
+
+ return 0;
+}
diff --git a/cpukit/posix/src/sigaddset.c b/cpukit/posix/src/sigaddset.c
new file mode 100644
index 0000000000..5c65ab60eb
--- /dev/null
+++ b/cpukit/posix/src/sigaddset.c
@@ -0,0 +1,40 @@
+/*
+ * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/sigset.h>
+#include <rtems/seterr.h>
+
+int sigaddset(
+ sigset_t *set,
+ int signo
+)
+{
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !signo )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !is_valid_signo(signo) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ *set |= signo_to_mask(signo);
+ return 0;
+}
diff --git a/cpukit/posix/src/sigdelset.c b/cpukit/posix/src/sigdelset.c
new file mode 100644
index 0000000000..856eb384df
--- /dev/null
+++ b/cpukit/posix/src/sigdelset.c
@@ -0,0 +1,44 @@
+/*
+ * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/sigset.h>
+#include <rtems/seterr.h>
+
+/*
+ * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69
+ */
+
+int sigdelset(
+ sigset_t *set,
+ int signo
+)
+{
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !signo )
+ return 0;
+
+ if ( !is_valid_signo(signo) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ *set &= ~signo_to_mask(signo);
+ return 0;
+}
diff --git a/cpukit/posix/src/sigemptyset.c b/cpukit/posix/src/sigemptyset.c
new file mode 100644
index 0000000000..9a6d3580ca
--- /dev/null
+++ b/cpukit/posix/src/sigemptyset.c
@@ -0,0 +1,33 @@
+/*
+ * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/sigset.h>
+#include <rtems/seterr.h>
+
+int sigemptyset(
+ sigset_t *set
+)
+{
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ *set = 0;
+ return 0;
+}
diff --git a/cpukit/posix/src/sigfillset.c b/cpukit/posix/src/sigfillset.c
new file mode 100644
index 0000000000..a67b9b9a3e
--- /dev/null
+++ b/cpukit/posix/src/sigfillset.c
@@ -0,0 +1,33 @@
+/*
+ * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/sigset.h>
+#include <rtems/seterr.h>
+
+int sigfillset(
+ sigset_t *set
+)
+{
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ *set = SIGNAL_ALL_MASK;
+ return 0;
+}
diff --git a/cpukit/posix/src/sigismember.c b/cpukit/posix/src/sigismember.c
new file mode 100644
index 0000000000..958c5336af
--- /dev/null
+++ b/cpukit/posix/src/sigismember.c
@@ -0,0 +1,42 @@
+/*
+ * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/sigset.h>
+#include <rtems/seterr.h>
+
+int sigismember(
+ const sigset_t *set,
+ int signo
+)
+{
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !signo )
+ return 0;
+
+ if ( !is_valid_signo(signo) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( *set & signo_to_mask(signo) )
+ return 1;
+
+ return 0;
+}
diff --git a/cpukit/posix/src/signal_2.c b/cpukit/posix/src/signal_2.c
new file mode 100644
index 0000000000..326861752f
--- /dev/null
+++ b/cpukit/posix/src/signal_2.c
@@ -0,0 +1,54 @@
+/*
+ * signal(2) - Install signal handler
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+#include <errno.h>
+
+#ifndef HAVE_SIGHANDLER_T
+ typedef void (*sighandler_t)(int);
+#endif
+
+sighandler_t signal(
+ int signum,
+ sighandler_t handler
+)
+{
+ struct sigaction s;
+ struct sigaction old;
+
+ s.sa_handler = handler ;
+ sigemptyset(&s.sa_mask);
+
+ /*
+ * Depending on which system we want to behave like, one of
+ * the following versions should be chosen.
+ */
+
+/* #define signal_like_linux */
+
+#if defined(signal_like_linux)
+ s.sa_flags = SA_RESTART | SA_INTERRUPT | SA_NOMASK;
+ s.sa_restorer= NULL ;
+#elif defined(signal_like_SVR4)
+ s.sa_flags = SA_RESTART;
+#else
+ s.sa_flags = 0;
+#endif
+
+ sigaction( signum, &s, &old );
+ return (sighandler_t) old.sa_handler;
+}
diff --git a/cpukit/posix/src/sigpending.c b/cpukit/posix/src/sigpending.c
new file mode 100644
index 0000000000..9f22760a58
--- /dev/null
+++ b/cpukit/posix/src/sigpending.c
@@ -0,0 +1,40 @@
+/*
+ * 3.3.6 Examine Pending Signals, P1003.1b-1993, p. 75
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/seterr.h>
+
+int sigpending(
+ sigset_t *set
+)
+{
+ POSIX_API_Control *api;
+
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ *set = api->signals_pending | _POSIX_signals_Pending;
+
+ return 0;
+}
diff --git a/cpukit/posix/src/sigprocmask.c b/cpukit/posix/src/sigprocmask.c
new file mode 100644
index 0000000000..d20a10d1ba
--- /dev/null
+++ b/cpukit/posix/src/sigprocmask.c
@@ -0,0 +1,38 @@
+/*
+ * 3.3.5 Examine and Change Blocked Signals, P1003.1b-1993, p. 73
+ *
+ * NOTE: P1003.1c/D10, p. 37 adds pthread_sigmask().
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+
+int sigprocmask(
+ int how,
+ const sigset_t *set,
+ sigset_t *oset
+)
+{
+ /*
+ * P1003.1c/Draft 10, p. 38 maps sigprocmask to pthread_sigmask.
+ */
+
+#if defined(RTEMS_POSIX_API)
+ return pthread_sigmask( how, set, oset );
+#else
+ return -1;
+#endif
+}
diff --git a/cpukit/posix/src/sigqueue.c b/cpukit/posix/src/sigqueue.c
new file mode 100644
index 0000000000..727f2c6b42
--- /dev/null
+++ b/cpukit/posix/src/sigqueue.c
@@ -0,0 +1,32 @@
+/*
+ * 3.3.9 Queue a Signal to a Process, P1003.1b-1993, p. 78
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+int sigqueue(
+ pid_t pid,
+ int signo,
+ const union sigval value
+)
+{
+ return killinfo( pid, signo, &value );
+}
diff --git a/cpukit/posix/src/sigsuspend.c b/cpukit/posix/src/sigsuspend.c
new file mode 100644
index 0000000000..77b6d90a29
--- /dev/null
+++ b/cpukit/posix/src/sigsuspend.c
@@ -0,0 +1,59 @@
+/*
+ * 3.3.7 Wait for a Signal, P1003.1b-1993, p. 75
+ *
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/seterr.h>
+
+int sigsuspend(
+ const sigset_t *sigmask
+)
+{
+ sigset_t saved_signals_blocked;
+ sigset_t current_unblocked_signals;
+ int status;
+ POSIX_API_Control *api;
+
+ api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ /*
+ * We use SIG_BLOCK and not SIG_SETMASK because there may be
+ * signals which might be pending, which might get caught here.
+ * We want the signals to be caught inside sigtimedwait.
+ */
+ status = sigprocmask( SIG_BLOCK, sigmask, &saved_signals_blocked );
+
+ current_unblocked_signals = ~(*sigmask);
+ status = sigtimedwait( &current_unblocked_signals, NULL, NULL );
+
+ (void) sigprocmask( SIG_SETMASK, &saved_signals_blocked, NULL );
+
+ /*
+ * sigtimedwait() returns the signal number while sigsuspend()
+ * is supposed to return -1 and EINTR when a signal is caught.
+ */
+ #if defined(RTEMS_DEBUG)
+ assert( status != -1 );
+ #endif
+
+ rtems_set_errno_and_return_minus_one( EINTR );
+}
diff --git a/cpukit/posix/src/sigtimedwait.c b/cpukit/posix/src/sigtimedwait.c
new file mode 100644
index 0000000000..41ebf88677
--- /dev/null
+++ b/cpukit/posix/src/sigtimedwait.c
@@ -0,0 +1,177 @@
+/*
+ * 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/seterr.h>
+#include <rtems/posix/time.h>
+#include <rtems/score/isr.h>
+
+int _POSIX_signals_Get_lowest(
+ sigset_t set
+)
+{
+ int signo;
+
+ for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
+ if ( set & signo_to_mask( signo ) ) {
+ goto found_it;
+ }
+ }
+
+ /*
+ * We assume SIGHUP == 1 and is the first non-real-time signal.
+ */
+
+ #if (SIGHUP != 1)
+ #error "Assumption that SIGHUP==1 violated!!"
+ #endif
+ for ( signo = SIGHUP ; signo <= __SIGLASTNOTRT ; signo++ ) {
+ if ( set & signo_to_mask( signo ) ) {
+ goto found_it;
+ }
+ }
+
+ /*
+ * This is structured this way to eliminate the need to have
+ * a return 0. This routine will NOT be called unless a signal
+ * is pending in the set passed in.
+ */
+found_it:
+ return signo;
+}
+
+int sigtimedwait(
+ const sigset_t *set,
+ siginfo_t *info,
+ const struct timespec *timeout
+)
+{
+ Thread_Control *the_thread;
+ POSIX_API_Control *api;
+ Watchdog_Interval interval;
+ siginfo_t signal_information;
+ siginfo_t *the_info;
+ int signo;
+ ISR_Level level;
+
+ /*
+ * Error check parameters before disabling interrupts.
+ */
+ if ( !set )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /* NOTE: This is very specifically a RELATIVE not ABSOLUTE time
+ * in the Open Group specification.
+ */
+
+ interval = 0;
+ if ( timeout ) {
+
+ if ( !_Timespec_Is_valid( timeout ) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ interval = _Timespec_To_ticks( timeout );
+
+ if ( !interval )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ /*
+ * Initialize local variables.
+ */
+
+ the_info = ( info ) ? info : &signal_information;
+
+ the_thread = _Thread_Executing;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+
+ /*
+ * What if they are already pending?
+ */
+
+ /* API signals pending? */
+
+ _ISR_Disable( level );
+ if ( *set & api->signals_pending ) {
+ /* XXX real info later */
+ the_info->si_signo = _POSIX_signals_Get_lowest( api->signals_pending );
+ _POSIX_signals_Clear_signals(
+ api,
+ the_info->si_signo,
+ the_info,
+ false,
+ false
+ );
+ _ISR_Enable( level );
+
+ the_info->si_code = SI_USER;
+ the_info->si_value.sival_int = 0;
+ return the_info->si_signo;
+ }
+
+ /* Process pending signals? */
+
+ if ( *set & _POSIX_signals_Pending ) {
+ signo = _POSIX_signals_Get_lowest( _POSIX_signals_Pending );
+ _POSIX_signals_Clear_signals( api, signo, the_info, true, false );
+ _ISR_Enable( level );
+
+ the_info->si_signo = signo;
+ the_info->si_code = SI_USER;
+ the_info->si_value.sival_int = 0;
+ return signo;
+ }
+
+ the_info->si_signo = -1;
+
+ _Thread_Disable_dispatch();
+ the_thread->Wait.queue = &_POSIX_signals_Wait_queue;
+ the_thread->Wait.return_code = EINTR;
+ the_thread->Wait.option = *set;
+ the_thread->Wait.return_argument = the_info;
+ _Thread_queue_Enter_critical_section( &_POSIX_signals_Wait_queue );
+ _ISR_Enable( level );
+ _Thread_queue_Enqueue( &_POSIX_signals_Wait_queue, interval );
+ _Thread_Enable_dispatch();
+
+ /*
+ * When the thread is set free by a signal, it is need to eliminate
+ * the signal.
+ */
+
+ _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, false, false );
+
+ /* Set errno only if return code is not EINTR or
+ * if EINTR was caused by a signal being caught, which
+ * was not in our set.
+ */
+
+ if ( (_Thread_Executing->Wait.return_code != EINTR)
+ || !(*set & signo_to_mask( the_info->si_signo )) ) {
+ errno = _Thread_Executing->Wait.return_code;
+ return -1;
+ }
+
+ return the_info->si_signo;
+}
diff --git a/cpukit/posix/src/sigwait.c b/cpukit/posix/src/sigwait.c
new file mode 100644
index 0000000000..1c34b5ee5b
--- /dev/null
+++ b/cpukit/posix/src/sigwait.c
@@ -0,0 +1,44 @@
+/*
+ * 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
+ *
+ * NOTE: P1003.1c/D10, p. 39 adds sigwait().
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+int sigwait(
+ const sigset_t *set,
+ int *sig
+)
+{
+ int status;
+
+ status = sigtimedwait( set, NULL, NULL );
+
+ if ( status != -1 ) {
+ if ( sig )
+ *sig = status;
+ return 0;
+ }
+
+ return errno;
+}
diff --git a/cpukit/posix/src/sigwaitinfo.c b/cpukit/posix/src/sigwaitinfo.c
new file mode 100644
index 0000000000..2c61e2a8fc
--- /dev/null
+++ b/cpukit/posix/src/sigwaitinfo.c
@@ -0,0 +1,33 @@
+/*
+ * 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
+ *
+ * NOTE: P1003.1c/D10, p. 39 adds sigwait().
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+
+int sigwaitinfo(
+ const sigset_t *set,
+ siginfo_t *info
+)
+{
+ return sigtimedwait( set, info, NULL );
+}
diff --git a/cpukit/posix/src/sysconf.c b/cpukit/posix/src/sysconf.c
new file mode 100644
index 0000000000..97a774da25
--- /dev/null
+++ b/cpukit/posix/src/sysconf.c
@@ -0,0 +1,55 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/tod.h>
+#include <rtems/libio_.h>
+
+#include <sys/param.h>
+
+/*PAGE
+ *
+ * 4.8.1 Get Configurable System Variables, P1003.1b-1993, p. 95
+ */
+
+long sysconf(
+ int name
+)
+{
+ if ( name == _SC_CLK_TCK )
+ return (TOD_MICROSECONDS_PER_SECOND /
+ rtems_configuration_get_microseconds_per_tick());
+
+ if ( name == _SC_OPEN_MAX )
+ return rtems_libio_number_iops;
+
+ if ( name == _SC_GETPW_R_SIZE_MAX )
+ return 1024;
+
+ if ( name == _SC_PAGESIZE )
+ return PAGE_SIZE;
+
+#if defined(__sparc__)
+ if ( name == 515 ) /* Solaris _SC_STACK_PROT */
+ return 0;
+#endif
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/testcancel.c b/cpukit/posix/src/testcancel.c
new file mode 100644
index 0000000000..bea71203d1
--- /dev/null
+++ b/cpukit/posix/src/testcancel.c
@@ -0,0 +1,57 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/posix/cancel.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/threadsup.h>
+
+/*PAGE
+ *
+ * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
+ */
+
+void pthread_testcancel( void )
+{
+ POSIX_API_Control *thread_support;
+ bool cancel = false;
+
+ /*
+ * Don't even think about deleting a resource from an ISR.
+ * Besides this request is supposed to be for _Thread_Executing
+ * and the ISR context is not a thread.
+ */
+
+ if ( _ISR_Is_in_progress() )
+ return;
+
+ thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+
+ _Thread_Disable_dispatch();
+ if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
+ thread_support->cancelation_requested )
+ cancel = true;
+ _Thread_Enable_dispatch();
+
+ if ( cancel )
+ _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
+}
diff --git a/cpukit/posix/src/timercreate.c b/cpukit/posix/src/timercreate.c
new file mode 100644
index 0000000000..1d843580ba
--- /dev/null
+++ b/cpukit/posix/src/timercreate.c
@@ -0,0 +1,97 @@
+/*
+ * 14.2.2 Create a Per-Process Timer, P1003.1b-1993, p. 264
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/timer.h>
+
+int timer_create(
+ clockid_t clock_id,
+ struct sigevent *evp,
+ timer_t *timerid
+)
+{
+ POSIX_Timer_Control *ptimer;
+
+ if ( clock_id != CLOCK_REALTIME )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !timerid )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * The data of the structure evp are checked in order to verify if they
+ * are coherent.
+ */
+
+ if (evp != NULL) {
+ /* The structure has data */
+ if ( ( evp->sigev_notify != SIGEV_NONE ) &&
+ ( evp->sigev_notify != SIGEV_SIGNAL ) ) {
+ /* The value of the field sigev_notify is not valid */
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ if ( !evp->sigev_signo )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ if ( !is_valid_signo(evp->sigev_signo) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ _Thread_Disable_dispatch(); /* to prevent deletion */
+
+ /*
+ * Allocate a timer
+ */
+ ptimer = _POSIX_Timer_Allocate();
+ if ( !ptimer ) {
+ _Thread_Enable_dispatch();
+ rtems_set_errno_and_return_minus_one( EAGAIN );
+ }
+
+ /* The data of the created timer are stored to use them later */
+
+ ptimer->state = POSIX_TIMER_STATE_CREATE_NEW;
+ ptimer->thread_id = _Thread_Executing->Object.id;
+
+ if ( evp != NULL ) {
+ ptimer->inf.sigev_notify = evp->sigev_notify;
+ ptimer->inf.sigev_signo = evp->sigev_signo;
+ ptimer->inf.sigev_value = evp->sigev_value;
+ }
+
+ ptimer->overrun = 0;
+ ptimer->timer_data.it_value.tv_sec = 0;
+ ptimer->timer_data.it_value.tv_nsec = 0;
+ ptimer->timer_data.it_interval.tv_sec = 0;
+ ptimer->timer_data.it_interval.tv_nsec = 0;
+
+ _Watchdog_Initialize( &ptimer->Timer, NULL, 0, NULL );
+ _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
+
+ *timerid = ptimer->Object.id;
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/timerdelete.c b/cpukit/posix/src/timerdelete.c
new file mode 100644
index 0000000000..cc70871e3c
--- /dev/null
+++ b/cpukit/posix/src/timerdelete.c
@@ -0,0 +1,63 @@
+/*
+ * 14.2.3 Delete a Per_process Timer, P1003.1b-1993, p. 266
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/timer.h>
+
+
+int timer_delete(
+ timer_t timerid
+)
+{
+ /*
+ * IDEA: This function must probably stop the timer first and then delete it
+ *
+ * It will have to do a call to rtems_timer_cancel and then another
+ * call to rtems_timer_delete.
+ * The call to rtems_timer_delete will be probably unnecessary,
+ * because rtems_timer_delete stops the timer before deleting it.
+ */
+ POSIX_Timer_Control *ptimer;
+ Objects_Locations location;
+
+ ptimer = _POSIX_Timer_Get( timerid, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object );
+ ptimer->state = POSIX_TIMER_STATE_FREE;
+ (void) _Watchdog_Remove( &ptimer->Timer );
+ _POSIX_Timer_Free( ptimer );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/timergetoverrun.c b/cpukit/posix/src/timergetoverrun.c
new file mode 100644
index 0000000000..1ad7bc4d04
--- /dev/null
+++ b/cpukit/posix/src/timergetoverrun.c
@@ -0,0 +1,58 @@
+/*
+ * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/thread.h>
+#include <rtems/posix/timer.h>
+
+/*
+ * timer_getoverrun
+ *
+ * The expiration of a timer must increase by one a counter.
+ * After the signal handler associated to the timer finishes
+ * its execution, _POSIX_Timer_TSR will have to set this counter to 0.
+ */
+int timer_getoverrun(
+ timer_t timerid
+)
+{
+ int overrun;
+ POSIX_Timer_Control *ptimer;
+ Objects_Locations location;
+
+ ptimer = _POSIX_Timer_Get( timerid, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ overrun = ptimer->overrun;
+ ptimer->overrun = 0;
+ _Thread_Enable_dispatch();
+ return overrun;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c
new file mode 100644
index 0000000000..bb39121b81
--- /dev/null
+++ b/cpukit/posix/src/timergettime.c
@@ -0,0 +1,77 @@
+/*
+ * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/timespec.h>
+#include <rtems/posix/timer.h>
+
+/*
+ * - When a timer is initialized, the value of the time in
+ * that moment is stored.
+ * - When this function is called, it returns the difference
+ * between the current time and the initialization time.
+ */
+
+int timer_gettime(
+ timer_t timerid,
+ struct itimerspec *value
+)
+{
+ POSIX_Timer_Control *ptimer;
+ Objects_Locations location;
+ struct timespec current_time;
+ Watchdog_Interval left;
+
+ if ( !value )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /* Reads the current time */
+ _TOD_Get( &current_time );
+
+ ptimer = _POSIX_Timer_Get( timerid, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ /* Calculates the time left before the timer finishes */
+
+ left =
+ (ptimer->Timer.start_time + ptimer->Timer.initial) - /* expire */
+ _Watchdog_Ticks_since_boot; /* now */
+
+ _Timespec_From_ticks( left, &value->it_value );
+
+ value->it_interval = ptimer->timer_data.it_interval;
+
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/timerinserthelper.c b/cpukit/posix/src/timerinserthelper.c
new file mode 100644
index 0000000000..a2ced7a79b
--- /dev/null
+++ b/cpukit/posix/src/timerinserthelper.c
@@ -0,0 +1,57 @@
+/*
+ * Helper routine for POSIX timers
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/timer.h>
+#include <rtems/posix/ptimer.h>
+
+bool _POSIX_Timer_Insert_helper(
+ Watchdog_Control *timer,
+ Watchdog_Interval ticks,
+ Objects_Id id,
+ Watchdog_Service_routine_entry TSR,
+ void *arg
+)
+{
+ ISR_Level level;
+
+ (void) _Watchdog_Remove( timer );
+ _ISR_Disable( level );
+
+ /*
+ * Check to see if the watchdog has just been inserted by a
+ * higher priority interrupt. If so, abandon this insert.
+ */
+ if ( timer->state != WATCHDOG_INACTIVE ) {
+ _ISR_Enable( level );
+ return false;
+ }
+
+ /*
+ * OK. Now we now the timer was not rescheduled by an interrupt
+ * so we can atomically initialize it as in use.
+ */
+ _Watchdog_Initialize( timer, TSR, id, arg );
+ _Watchdog_Insert_ticks( timer, ticks );
+ _ISR_Enable( level );
+ return true;
+}
diff --git a/cpukit/posix/src/timersettime.c b/cpukit/posix/src/timersettime.c
new file mode 100644
index 0000000000..d618bd391e
--- /dev/null
+++ b/cpukit/posix/src/timersettime.c
@@ -0,0 +1,136 @@
+/*
+ * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/ptimer.h>
+#include <rtems/posix/timer.h>
+
+int timer_settime(
+ timer_t timerid,
+ int flags,
+ const struct itimerspec *value,
+ struct itimerspec *ovalue
+)
+{
+ POSIX_Timer_Control *ptimer;
+ Objects_Locations location;
+ bool activated;
+ uint32_t initial_period;
+ struct itimerspec normalize;
+
+ if ( !value )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+
+ /*
+ * First, it verifies if the structure "value" is correct
+ * if the number of nanoseconds is not correct return EINVAL
+ */
+ if ( !_Timespec_Is_valid( &(value->it_value) ) ) {
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+ if ( !_Timespec_Is_valid( &(value->it_interval) ) ) {
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ if ( flags != TIMER_ABSTIME && flags != POSIX_TIMER_RELATIVE ) {
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ }
+
+ normalize = *value;
+
+ /* Convert absolute to relative time */
+ if (flags == TIMER_ABSTIME) {
+ struct timespec now;
+ _TOD_Get( &now );
+ /* Check for seconds in the past */
+ if ( _Timespec_Greater_than( &now, &normalize.it_value ) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ _Timespec_Subtract( &now, &normalize.it_value, &normalize.it_value );
+ }
+
+ /* If the function reaches this point, then it will be necessary to do
+ * something with the structure of times of the timer: to stop, start
+ * or start it again
+ */
+
+ ptimer = _POSIX_Timer_Get( timerid, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ /* First, it verifies if the timer must be stopped */
+ if ( normalize.it_value.tv_sec == 0 && normalize.it_value.tv_nsec == 0 ) {
+ /* Stop the timer */
+ (void) _Watchdog_Remove( &ptimer->Timer );
+ /* The old data of the timer are returned */
+ if ( ovalue )
+ *ovalue = ptimer->timer_data;
+ /* The new data are set */
+ ptimer->timer_data = normalize;
+ /* Indicates that the timer is created and stopped */
+ ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
+ /* Returns with success */
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ /* Convert from seconds and nanoseconds to ticks */
+ ptimer->ticks = _Timespec_To_ticks( &value->it_interval );
+ initial_period = _Timespec_To_ticks( &normalize.it_value );
+
+
+ activated = _POSIX_Timer_Insert_helper(
+ &ptimer->Timer,
+ initial_period,
+ ptimer->Object.id,
+ _POSIX_Timer_TSR,
+ ptimer
+ );
+ if ( !activated ) {
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ /*
+ * The timer has been started and is running. So we return the
+ * old ones in "ovalue"
+ */
+ if ( ovalue )
+ *ovalue = ptimer->timer_data;
+ ptimer->timer_data = normalize;
+
+ /* Indicate that the time is running */
+ ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
+ _TOD_Get( &ptimer->time );
+ _Thread_Enable_dispatch();
+ return 0;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ rtems_set_errno_and_return_minus_one( EINVAL );
+}
diff --git a/cpukit/posix/src/timertsr.c b/cpukit/posix/src/timertsr.c
new file mode 100644
index 0000000000..b2a86ce4fb
--- /dev/null
+++ b/cpukit/posix/src/timertsr.c
@@ -0,0 +1,81 @@
+/*
+ * _POSIX_Timer_TSR
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <rtems/system.h>
+#include <rtems/seterr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/ptimer.h>
+#include <rtems/posix/timer.h>
+
+/*
+ * This is the operation that is run when a timer expires
+ */
+void _POSIX_Timer_TSR(
+ Objects_Id timer __attribute__((unused)),
+ void *data)
+{
+ POSIX_Timer_Control *ptimer;
+ bool activated;
+
+ ptimer = (POSIX_Timer_Control *)data;
+
+ /* Increment the number of expirations. */
+ ptimer->overrun = ptimer->overrun + 1;
+
+ /* The timer must be reprogrammed */
+ if ( ( ptimer->timer_data.it_interval.tv_sec != 0 ) ||
+ ( ptimer->timer_data.it_interval.tv_nsec != 0 ) ) {
+ activated = _POSIX_Timer_Insert_helper(
+ &ptimer->Timer,
+ ptimer->ticks,
+ ptimer->Object.id,
+ _POSIX_Timer_TSR,
+ ptimer
+ );
+ if ( !activated )
+ return;
+
+ /* Store the time when the timer was started again */
+ _TOD_Get( &ptimer->time );
+
+ /* The state really did not change but just to be safe */
+ ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
+ } else {
+ /* Indicates that the timer is stopped */
+ ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
+ }
+
+ /*
+ * The sending of the signal to the process running the handling function
+ * specified for that signal is simulated
+ */
+
+ if ( pthread_kill ( ptimer->thread_id, ptimer->inf.sigev_signo ) ) {
+ /* XXX error handling */
+ }
+
+ /* After the signal handler returns, the count of expirations of the
+ * timer must be set to 0.
+ */
+ ptimer->overrun = 0;
+}
diff --git a/cpukit/posix/src/ualarm.c b/cpukit/posix/src/ualarm.c
new file mode 100644
index 0000000000..f43aabe52c
--- /dev/null
+++ b/cpukit/posix/src/ualarm.c
@@ -0,0 +1,105 @@
+/*
+ * 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+/* #include <errno.h> */
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_signals_Ualarm_TSR
+ */
+
+void _POSIX_signals_Ualarm_TSR(
+ Objects_Id id __attribute__((unused)),
+ void *argument __attribute__((unused))
+)
+{
+ /*
+ * Send a SIGALRM but if there is a problem, ignore it.
+ * It's OK, there isn't a way this should fail.
+ */
+ (void) kill( getpid(), SIGALRM );
+
+ /*
+ * If the reset interval is non-zero, reschedule ourselves.
+ */
+ _Watchdog_Reset( &_POSIX_signals_Ualarm_timer );
+}
+
+useconds_t ualarm(
+ useconds_t useconds,
+ useconds_t interval
+)
+{
+ useconds_t remaining = 0;
+ Watchdog_Control *the_timer;
+ Watchdog_Interval ticks;
+ struct timespec tp;
+
+ the_timer = &_POSIX_signals_Ualarm_timer;
+
+ /*
+ * Initialize the timer used to implement alarm().
+ */
+
+ if ( !the_timer->routine ) {
+ _Watchdog_Initialize( the_timer, _POSIX_signals_Ualarm_TSR, 0, NULL );
+ } else {
+ Watchdog_States state;
+
+ state = _Watchdog_Remove( the_timer );
+ if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) {
+ /*
+ * The stop_time and start_time fields are snapshots of ticks since
+ * boot. Since alarm() is dealing in seconds, we must account for
+ * this.
+ */
+
+ ticks = the_timer->initial;
+ ticks -= (the_timer->stop_time - the_timer->start_time);
+ /* remaining is now in ticks */
+
+ _Timespec_From_ticks( ticks, &tp );
+ remaining = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND;
+ remaining += tp.tv_nsec / 1000;
+ }
+ }
+
+ /*
+ * If useconds is non-zero, then the caller wants to schedule
+ * the alarm repeatedly at that interval. If the interval is
+ * less than a single clock tick, then fudge it to a clock tick.
+ */
+ if ( useconds ) {
+ Watchdog_Interval ticks;
+
+ tp.tv_sec = useconds / TOD_MICROSECONDS_PER_SECOND;
+ tp.tv_nsec = (useconds % TOD_MICROSECONDS_PER_SECOND) * 1000;
+ ticks = _Timespec_To_ticks( &tp );
+ if ( ticks == 0 )
+ ticks = 1;
+
+ _Watchdog_Insert_ticks( the_timer, _Timespec_To_ticks( &tp ) );
+ }
+
+ return remaining;
+}
diff --git a/cpukit/posix/src/vfork.c b/cpukit/posix/src/vfork.c
new file mode 100644
index 0000000000..4db522f015
--- /dev/null
+++ b/cpukit/posix/src/vfork.c
@@ -0,0 +1,23 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+
+pid_t vfork(void)
+{
+ return -1;
+}
+
diff --git a/cpukit/posix/src/wait.c b/cpukit/posix/src/wait.c
new file mode 100644
index 0000000000..b277930b47
--- /dev/null
+++ b/cpukit/posix/src/wait.c
@@ -0,0 +1,28 @@
+/*
+ * waitpid() - POSIX 1003.1b 3.2.1
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int wait(
+ int *stat_loc
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/posix/src/waitpid.c b/cpukit/posix/src/waitpid.c
new file mode 100644
index 0000000000..b3c3918f4e
--- /dev/null
+++ b/cpukit/posix/src/waitpid.c
@@ -0,0 +1,30 @@
+/*
+ * waitpid() - POSIX 1003.1 3.2.1
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <rtems/seterr.h>
+
+int waitpid(
+ pid_t pid,
+ int *stat_loc,
+ int options
+)
+{
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+}
diff --git a/cpukit/pppd/.cvsignore b/cpukit/pppd/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/pppd/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/pppd/Makefile.am b/cpukit/pppd/Makefile.am
new file mode 100644
index 0000000000..391c395807
--- /dev/null
+++ b/cpukit/pppd/Makefile.am
@@ -0,0 +1,21 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+if LIBNETWORKING
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtemspppd.h rtemsdialer.h
+
+project_lib_LIBRARIES = libpppd.a
+libpppd_a_SOURCES = auth.c ccp.c ccp.h chap.c chap.h chap_ms.c chap_ms.h \
+ chat.c demand.c fsm.c fsm.h ipcp.c ipcp.h lcp.c lcp.h magic.c magic.h \
+ options.c upap.c upap.h utils.c sys-rtems.c \
+ rtemsmain.c rtemspppd.c rtemspppd.h pppd.h patchlevel.h pathnames.h \
+ rtemsdialer.h
+libpppd_a_CPPFLAGS = $(AM_CPPFLAGS) -D__BSD_VISIBLE -I$(srcdir)/../libmd
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/pppd/README b/cpukit/pppd/README
new file mode 100644
index 0000000000..28c9f7ef5d
--- /dev/null
+++ b/cpukit/pppd/README
@@ -0,0 +1,29 @@
+#
+# $Id$
+#
+
+This directory contains a port of ppp-2.3.11. The official site for
+the original source for this PPP implementation is:
+
+ftp://cs.anu.edu.au/pub/software/ppp
+
+================================================================
+History
+
+The original port was of 2.3.5 by Tomasz Domin <dot@comarch.pl> of
+ComArch SA and was initially only tested on the mpc823. He
+provided the modem driver as well.
+
+The port was updated to 2.3.11 by Mike Siers <mikes@poliac.com>
+who added an example test.
+
+Updated the chat program to return the correct errors and support
+the ABORT commands. Removed some dead code and did a lot of
+testing on a new Coldfire BSP. Version seems to be very stable.
+
+Update code to use RTEMS pppd network drivers. Now the pppd
+software is not dependent on using task driven mode. This
+change improved stablity and performance. This was updated
+by Mike Siers <mikes@poliac.com>.
+=================================================================
+
diff --git a/cpukit/pppd/STATUS b/cpukit/pppd/STATUS
new file mode 100644
index 0000000000..4c0d35d423
--- /dev/null
+++ b/cpukit/pppd/STATUS
@@ -0,0 +1,27 @@
+#
+# $Id$
+#
+
+The pppd application seems to very stable. It has been tested using
+the example application with the i386/pc586 and m68k/sbc5206e BSPs.
+The tests were executed using a null modem serial cable to connect
+with a UNIX box running either the ppp or pppd application and with
+an external modem to dial up a local ISP.
+
+If you have problems getting your target to make consistent connections
+with an ISP, the problem is most likely with the ppp options. First
+try using the "novj" and "noaccomp" options. If you have questions
+about what other option values are available for the rtems_pppd_set_option
+function, please look at the pppd.8 man page file or the the source code.
+The majority of options that are documented in man page should work
+with this function call.
+
+The pppd code had now been updated to use it's own RTEMS network
+drivers. This removes the requirement for the task driven termios
+support. This update has fixed the large packet ping problem.
+Currently, I do not know of any problems with the port.
+
+If you find any other problems or fix some problems, please post your
+changes to the RTEMS mailing list.
+
+Good Luck
diff --git a/cpukit/pppd/auth.c b/cpukit/pppd/auth.c
new file mode 100644
index 0000000000..fb84f1e8fc
--- /dev/null
+++ b/cpukit/pppd/auth.c
@@ -0,0 +1,1128 @@
+/*
+ * auth.c - PPP authentication and phase control.
+ *
+ * Copyright (c) 1993 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+#if defined(_PATH_LASTLOG) && defined(_linux_)
+#include <lastlog.h>
+#endif
+
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef USE_PAM
+#include <security/pam_appl.h>
+#endif
+
+#ifdef HAS_SHADOW
+#include <shadow.h>
+#ifndef PW_PPP
+#define PW_PPP PW_LOGIN
+#endif
+#endif
+
+#include "pppd.h"
+#include "fsm.h"
+#include "lcp.h"
+#include "ipcp.h"
+#include "upap.h"
+#include "chap.h"
+#ifdef CBCP_SUPPORT
+#include "cbcp.h"
+#endif
+#include "pathnames.h"
+
+static const char rcsid[] = RCSID;
+
+/* The name by which the peer authenticated itself to us. */
+char peer_authname[MAXNAMELEN];
+
+/* Records which authentication operations haven't completed yet. */
+static int auth_pending[NUM_PPP];
+
+/* List of addresses which the peer may use. */
+static struct permitted_ip *addresses[NUM_PPP];
+
+/* Wordlist giving addresses which the peer may use
+ without authenticating itself. */
+static struct wordlist *noauth_addrs;
+
+/* Extra options to apply, from the secrets file entry for the peer. */
+static struct wordlist *extra_options;
+
+/* Number of network protocols which we have opened. */
+static int num_np_open;
+
+/* Number of network protocols which have come up. */
+static int num_np_up;
+
+/* Set if we got the contents of passwd[] from the pap-secrets file. */
+static int passwd_from_file;
+
+/* Set if we require authentication only because we have a default route. */
+static bool default_auth;
+
+/* Hook for a link status */
+void (*auth_linkup_hook)(void) = NULL;
+void (*auth_linkdown_hook)(void) = NULL;
+
+/* Hook to enable a plugin to control the idle time limit */
+int (*idle_time_hook)(struct ppp_idle *) = NULL;
+
+/* Hook for a plugin to say whether we can possibly authenticate any peer */
+int (*pap_check_hook)(void) = NULL;
+
+/* Hook for a plugin to check the PAP user and password */
+int (*pap_auth_hook)(char *user, char *passwd/*, char **msgp,
+ struct wordlist **paddrs,
+ struct wordlist **popts*/) = NULL;
+
+/* Hook for a plugin to know about the PAP user logout */
+void (*pap_logout_hook)(void) = NULL;
+
+/* Hook for a plugin to get the PAP password for authenticating us */
+int (*pap_passwd_hook)(char *user, char *passwd) = NULL;
+
+/*
+ * This is used to ensure that we don't start an auth-up/down
+ * script while one is already running.
+ */
+enum script_state {
+ s_down,
+ s_up
+};
+
+static enum script_state auth_state = s_down;
+static enum script_state auth_script_state = s_down;
+
+/*
+ * Option variables.
+ */
+bool uselogin = 0; /* Use /etc/passwd for checking PAP */
+bool cryptpap = 0; /* Passwords in pap-secrets are encrypted */
+bool refuse_pap = 0; /* Don't wanna auth. ourselves with PAP */
+bool refuse_chap = 0; /* Don't wanna auth. ourselves with CHAP */
+bool usehostname = 0; /* Use hostname for our_name */
+bool auth_required = 0; /* Always require authentication from peer */
+bool allow_any_ip = 0; /* Allow peer to use any IP address */
+bool explicit_remote = 0; /* User specified explicit remote name */
+char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
+
+/* Bits in auth_pending[] */
+#define PAP_WITHPEER 1
+#define PAP_PEER 2
+#define CHAP_WITHPEER 4
+#define CHAP_PEER 8
+
+extern char *crypt(const char *, const char *);
+
+/* Prototypes for procedures local to this file. */
+
+static void network_phase(int);
+static void check_idle(void *);
+static void connect_time_expired(void *);
+static int null_login(int);
+static int get_pap_passwd(char *);
+static int have_pap_secret(int *);
+static int have_chap_secret(char *, char *, int, int *);
+#if 0
+static int ip_addr_check(uint32_t, struct permitted_ip *);
+#endif
+static void free_wordlist(struct wordlist *);
+static void auth_script(enum script_state s);
+static void set_allowed_addrs(int, struct wordlist *, struct wordlist *);
+
+
+/*
+ * Authentication-related options.
+ */
+option_t auth_options[] = {
+ { "require-pap", o_bool, &lcp_wantoptions[0].neg_upap,
+ "Require PAP authentication from peer", 1, &auth_required, 0, 0 },
+ { "+pap", o_bool, &lcp_wantoptions[0].neg_upap,
+ "Require PAP authentication from peer", 1, &auth_required, 0, 0 },
+ { "refuse-pap", o_bool, &refuse_pap,
+ "Don't agree to auth to peer with PAP", 1, NULL, 0, 0 },
+ { "-pap", o_bool, &refuse_pap,
+ "Don't allow PAP authentication with peer", 1, NULL, 0, 0 },
+ { "require-chap", o_bool, &lcp_wantoptions[0].neg_chap,
+ "Require CHAP authentication from peer", 1, &auth_required, 0, 0 },
+ { "+chap", o_bool, &lcp_wantoptions[0].neg_chap,
+ "Require CHAP authentication from peer", 1, &auth_required, 0, 0 },
+ { "refuse-chap", o_bool, &refuse_chap,
+ "Don't agree to auth to peer with CHAP", 1, NULL, 0, 0 },
+ { "-chap", o_bool, &refuse_chap,
+ "Don't allow CHAP authentication with peer", 1, NULL, 0, 0 },
+ { "name", o_string, our_name,
+ "Set local name for authentication",
+ OPT_PRIV|OPT_STATIC, NULL, MAXNAMELEN, 0 },
+ { "user", o_string, user,
+ "Set name for auth with peer", OPT_STATIC, NULL, MAXNAMELEN, 0 },
+ { "usehostname", o_bool, &usehostname,
+ "Must use hostname for authentication", 1, NULL, 0, 0 },
+ { "remotename", o_string, remote_name,
+ "Set remote name for authentication", OPT_STATIC,
+ &explicit_remote, MAXNAMELEN, 0 },
+ { "auth", o_bool, &auth_required,
+ "Require authentication from peer", 1, NULL, 0, 0 },
+ { "noauth", o_bool, &auth_required,
+ "Don't require peer to authenticate", OPT_PRIV, &allow_any_ip, 0, 0 },
+ { "login", o_bool, &uselogin,
+ "Use system password database for PAP", 1, NULL, 0, 0 },
+ { "papcrypt", o_bool, &cryptpap,
+ "PAP passwords are encrypted", 1, NULL, 0, 0 },
+/* Removed for RTEMS PORT
+ { "+ua", o_special, setupapfile,
+ "Get PAP user and password from file" },
+*/
+ { "password", o_string, passwd,
+ "Password for authenticating us to the peer", OPT_STATIC,
+ NULL, MAXSECRETLEN, 0 },
+/* Removed for RTEMS_PORT
+ { "privgroup", o_special, privgroup,
+ "Allow group members to use privileged options", OPT_PRIV },
+ { "allow-ip", o_special, set_noauth_addr,
+ "Set IP address(es) which can be used without authentication",
+ OPT_PRIV },
+*/
+ { NULL, 0, NULL, NULL, 0, NULL, 0, 0 }
+};
+
+/*
+ * An Open on LCP has requested a change from Dead to Establish phase.
+ * Do what's necessary to bring the physical layer up.
+ */
+void
+link_required(
+ int unit )
+{
+}
+
+/*
+ * LCP has terminated the link; go to the Dead phase and take the
+ * physical layer down.
+ */
+void
+link_terminated(
+ int unit)
+{
+ if (pppd_phase == PHASE_DEAD)
+ return;
+ if (pap_logout_hook) {
+ pap_logout_hook();
+ }
+ new_phase(PHASE_DEAD);
+ notice("Connection terminated.");
+}
+
+/*
+ * LCP has gone down; it will either die or try to re-establish.
+ */
+void
+link_down(
+ int unit)
+{
+ int i;
+ struct protent *protp;
+
+ auth_state = s_down;
+ if (auth_script_state == s_up) {
+ update_link_stats(unit);
+ auth_script(s_down);
+ }
+ for (i = 0; (protp = protocols[i]) != NULL; ++i) {
+ if (!protp->enabled_flag)
+ continue;
+ if (protp->protocol != PPP_LCP && protp->lowerdown != NULL)
+ (*protp->lowerdown)(unit);
+ if (protp->protocol < 0xC000 && protp->close != NULL)
+ (*protp->close)(unit, "LCP down");
+ }
+ num_np_open = 0;
+ num_np_up = 0;
+ if (pppd_phase != PHASE_DEAD)
+ new_phase(PHASE_TERMINATE);
+}
+
+/*
+ * The link is established.
+ * Proceed to the Dead, Authenticate or Network phase as appropriate.
+ */
+void
+link_established(
+ int unit )
+{
+ int auth;
+ lcp_options *wo = &lcp_wantoptions[unit];
+ lcp_options *go = &lcp_gotoptions[unit];
+ lcp_options *ho = &lcp_hisoptions[unit];
+ int i;
+ struct protent *protp;
+
+ /*
+ * Tell higher-level protocols that LCP is up.
+ */
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->protocol != PPP_LCP && protp->enabled_flag
+ && protp->lowerup != NULL)
+ (*protp->lowerup)(unit);
+
+ if (auth_required && !(go->neg_chap || go->neg_upap)) {
+ /*
+ * We wanted the peer to authenticate itself, and it refused:
+ * if we have some address(es) it can use without auth, fine,
+ * otherwise treat it as though it authenticated with PAP using
+ * a username * of "" and a password of "". If that's not OK,
+ * boot it out.
+ */
+ if (noauth_addrs != NULL) {
+ set_allowed_addrs(unit, noauth_addrs, NULL);
+ } else if (!wo->neg_upap || !null_login(unit)) {
+ warn("peer refused to authenticate: terminating link");
+ lcp_close(unit, "peer refused to authenticate");
+ pppd_status = EXIT_PEER_AUTH_FAILED;
+ return;
+ }
+ }
+
+ new_phase(PHASE_AUTHENTICATE);
+ auth = 0;
+ if (go->neg_chap) {
+ ChapAuthPeer(unit, our_name, go->chap_mdtype);
+ auth |= CHAP_PEER;
+ } else if (go->neg_upap) {
+ upap_authpeer(unit);
+ auth |= PAP_PEER;
+ }
+ if (ho->neg_chap) {
+ ChapAuthWithPeer(unit, user, ho->chap_mdtype);
+ auth |= CHAP_WITHPEER;
+ } else if (ho->neg_upap) {
+ if (passwd[0] == 0) {
+ passwd_from_file = 1;
+ if (!get_pap_passwd(passwd))
+ error("No secret found for PAP login");
+ }
+ upap_authwithpeer(unit, user, passwd);
+ auth |= PAP_WITHPEER;
+ }
+ auth_pending[unit] = auth;
+
+ if (!auth)
+ network_phase(unit);
+}
+
+/*
+ * Proceed to the network phase.
+ */
+static void
+network_phase(
+ int unit )
+{
+#ifdef CBCP_SUPPORT
+ lcp_options *go = &lcp_gotoptions[unit];
+#endif
+
+ /* always run the auth-up script */
+ auth_state = s_up;
+ if (auth_script_state == s_down) {
+ auth_script(s_up);
+ }
+
+#ifdef CBCP_SUPPORT
+ /*
+ * If we negotiated callback, do it now.
+ */
+ if (go->neg_cbcp) {
+ new_phase(PHASE_CALLBACK);
+ (*cbcp_protent.open)(unit);
+ return;
+ }
+#endif
+
+ /*
+ * Process extra options from the secrets file
+ */
+ if (extra_options) {
+ options_from_list(extra_options, 1);
+ free_wordlist(extra_options);
+ extra_options = 0;
+ }
+ start_networks();
+}
+
+void
+start_networks(void)
+{
+ int i;
+ struct protent *protp;
+
+ new_phase(PHASE_NETWORK);
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->protocol < 0xC000 && protp->enabled_flag
+ && protp->open != NULL) {
+ (*protp->open)(0);
+ if (protp->protocol != PPP_CCP)
+ ++num_np_open;
+ }
+
+ if (num_np_open == 0)
+ /* nothing to do */
+ lcp_close(0, "No network protocols running");
+}
+
+/*
+ * The peer has failed to authenticate himself using `protocol'.
+ */
+void
+auth_peer_fail(
+ int unit,
+ int protocol)
+{
+ /*
+ * Authentication failure: take the link down
+ */
+ lcp_close(unit, "Authentication failed");
+ pppd_status = EXIT_PEER_AUTH_FAILED;
+}
+
+/*
+ * The peer has been successfully authenticated using `protocol'.
+ */
+void
+auth_peer_success(
+ int unit,
+ int protocol,
+ char *name,
+ int namelen)
+{
+ int bit;
+
+ switch (protocol) {
+ case PPP_CHAP:
+ bit = CHAP_PEER;
+ break;
+ case PPP_PAP:
+ bit = PAP_PEER;
+ break;
+ default:
+ warn("auth_peer_success: unknown protocol %x", protocol);
+ return;
+ }
+
+ /*
+ * Save the authenticated name of the peer for later.
+ */
+ if (namelen > sizeof(peer_authname) - 1)
+ namelen = sizeof(peer_authname) - 1;
+ BCOPY(name, peer_authname, namelen);
+ peer_authname[namelen] = 0;
+
+ /*
+ * If there is no more authentication still to be done,
+ * proceed to the network (or callback) phase.
+ */
+ if ((auth_pending[unit] &= ~bit) == 0)
+ network_phase(unit);
+}
+
+/*
+ * We have failed to authenticate ourselves to the peer using `protocol'.
+ */
+void
+auth_withpeer_fail(
+ int unit,
+ int protocol )
+{
+ if (passwd_from_file)
+ BZERO(passwd, MAXSECRETLEN);
+ /*
+ * We've failed to authenticate ourselves to our peer.
+ * Some servers keep sending CHAP challenges, but there
+ * is no point in persisting without any way to get updated
+ * authentication secrets.
+ */
+ lcp_close(unit, "Failed to authenticate ourselves to peer");
+ pppd_status = EXIT_AUTH_TOPEER_FAILED;
+}
+
+/*
+ * We have successfully authenticated ourselves with the peer using `protocol'.
+ */
+void
+auth_withpeer_success(
+ int unit,
+ int protocol )
+{
+ int bit;
+
+ switch (protocol) {
+ case PPP_CHAP:
+ bit = CHAP_WITHPEER;
+ break;
+ case PPP_PAP:
+ if (passwd_from_file)
+ BZERO(passwd, MAXSECRETLEN);
+ bit = PAP_WITHPEER;
+ break;
+ default:
+ warn("auth_withpeer_success: unknown protocol %x", protocol);
+ bit = 0;
+ }
+
+ /*
+ * If there is no more authentication still being done,
+ * proceed to the network (or callback) phase.
+ */
+ if ((auth_pending[unit] &= ~bit) == 0)
+ network_phase(unit);
+}
+
+
+/*
+ * np_up - a network protocol has come up.
+ */
+void
+np_up(
+ int unit,
+ int proto )
+{
+ int tlim;
+
+ if (num_np_up == 0) {
+ /*
+ * At this point we consider that the link has come up successfully.
+ */
+ pppd_status = EXIT_OK;
+ unsuccess = 0;
+ new_phase(PHASE_RUNNING);
+
+ if (idle_time_hook != 0)
+ tlim = (*idle_time_hook)(NULL);
+ else
+ tlim = idle_time_limit;
+ if (tlim > 0)
+ TIMEOUT(check_idle, NULL, tlim);
+
+ /*
+ * Set a timeout to close the connection once the maximum
+ * connect time has expired.
+ */
+ if (maxconnect > 0)
+ TIMEOUT(connect_time_expired, 0, maxconnect);
+ }
+ ++num_np_up;
+}
+
+/*
+ * np_down - a network protocol has gone down.
+ */
+void
+np_down(
+ int unit,
+ int proto)
+{
+ if (--num_np_up == 0) {
+ UNTIMEOUT(check_idle, NULL);
+ new_phase(PHASE_NETWORK);
+ }
+}
+
+/*
+ * np_finished - a network protocol has finished using the link.
+ */
+void
+np_finished(
+ int unit,
+ int proto )
+{
+ if (--num_np_open <= 0) {
+ /* no further use for the link: shut up shop. */
+ lcp_close(0, "No network protocols running");
+ }
+}
+
+/*
+ * check_idle - check whether the link has been idle for long
+ * enough that we can shut it down.
+ */
+static void
+check_idle(
+ void *arg )
+{
+ struct ppp_idle idle;
+ time_t itime;
+ int tlim;
+
+ if (!get_idle_time(0, &idle))
+ return;
+ if (idle_time_hook != 0) {
+ tlim = idle_time_hook(&idle);
+ } else {
+ itime = MIN(idle.xmit_idle, idle.recv_idle);
+ tlim = idle_time_limit - itime;
+ }
+ if (tlim <= 0) {
+ /* link is idle: shut it down. */
+ notice("Terminating connection due to lack of activity.");
+ lcp_close(0, "Link inactive");
+ need_holdoff = 0;
+ pppd_status = EXIT_IDLE_TIMEOUT;
+ } else {
+ TIMEOUT(check_idle, NULL, tlim);
+ }
+}
+
+/*
+ * connect_time_expired - log a message and close the connection.
+ */
+static void
+connect_time_expired(
+ void *arg)
+{
+ info("Connect time expired");
+ lcp_close(0, "Connect time expired"); /* Close connection */
+ pppd_status = EXIT_CONNECT_TIME;
+}
+
+/*
+ * auth_check_options - called to check authentication options.
+ */
+int
+auth_check_options(void)
+{
+ lcp_options *wo = &lcp_wantoptions[0];
+ int status = 1;
+ int can_auth;
+ int lacks_ip;
+
+ /* Default our_name to hostname, and user to our_name */
+ if (our_name[0] == 0 || usehostname)
+ strlcpy(our_name, hostname, sizeof(our_name));
+ if (user[0] == 0)
+ strlcpy(user, our_name, sizeof(user));
+
+ /*
+ * If we have a default route, require the peer to authenticate
+ * unless the noauth option was given or the real user is root.
+ */
+ if (!auth_required && !allow_any_ip && have_route_to(0) && !privileged) {
+ printf("auth_check_options: turning on\n");
+ auth_required = 1;
+ default_auth = 1;
+ }
+
+ /* If authentication is required, ask peer for CHAP or PAP. */
+ if (auth_required) {
+ if (!wo->neg_chap && !wo->neg_upap) {
+ wo->neg_chap = 1;
+ wo->neg_upap = 1;
+ }
+ } else {
+ wo->neg_chap = 0;
+ wo->neg_upap = 0;
+ }
+
+ /*
+ * Check whether we have appropriate secrets to use
+ * to authenticate the peer.
+ */
+ lacks_ip = 0;
+ can_auth = wo->neg_upap && (uselogin || have_pap_secret(&lacks_ip));
+ if (!can_auth && wo->neg_chap) {
+ can_auth = have_chap_secret((explicit_remote? remote_name: NULL),
+ our_name, 1, &lacks_ip);
+ }
+
+ if (auth_required && !can_auth && noauth_addrs == NULL) {
+ if (default_auth) {
+ option_error(
+"By default the remote system is required to authenticate itself");
+ option_error(
+"(because this system has a default route to the internet)");
+ } else if (explicit_remote)
+ option_error(
+"The remote system (%s) is required to authenticate itself",
+ remote_name);
+ else
+ option_error(
+"The remote system is required to authenticate itself");
+ option_error(
+"but I couldn't find any suitable secret (password) for it to use to do so.");
+ if (lacks_ip)
+ option_error(
+"(None of the available passwords would let it use an IP address.)");
+
+ status = 0;
+ }
+ return ( status );
+}
+
+/*
+ * auth_reset - called when LCP is starting negotiations to recheck
+ * authentication options, i.e. whether we have appropriate secrets
+ * to use for authenticating ourselves and/or the peer.
+ */
+void
+auth_reset(
+ int unit)
+{
+ lcp_options *go = &lcp_gotoptions[unit];
+ lcp_options *ao = &lcp_allowoptions[0];
+
+ ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
+ ao->neg_chap = !refuse_chap
+ && (passwd[0] != 0
+ || have_chap_secret(user, (explicit_remote? remote_name: NULL),
+ 0, NULL));
+
+ if (go->neg_upap && !uselogin && !have_pap_secret(NULL))
+ go->neg_upap = 0;
+ if (go->neg_chap) {
+ if (!have_chap_secret((explicit_remote? remote_name: NULL),
+ our_name, 1, NULL))
+ go->neg_chap = 0;
+ }
+}
+
+
+/*
+ * check_passwd - Check the user name and passwd against the PAP secrets
+ * file. If requested, also check against the system password database,
+ * and login the user if OK.
+ *
+ * returns:
+ * UPAP_AUTHNAK: Authentication failed.
+ * UPAP_AUTHACK: Authentication succeeded.
+ * In either case, msg points to an appropriate message.
+ */
+int
+check_passwd(
+ int unit,
+ char *auser,
+ int userlen,
+ char *apasswd,
+ int passwdlen,
+ char **msg)
+{
+ char passwd[64], user[64];
+
+ if (pap_auth_hook)
+ {
+ slprintf(passwd, sizeof(passwd), "%.*v", passwdlen, apasswd);
+ slprintf(user, sizeof(user), "%.*v", userlen, auser);
+
+ return (*pap_auth_hook)(user, passwd/*, NULL, NULL, NULL*/) ?
+ UPAP_AUTHACK : UPAP_AUTHNAK;
+ }
+
+ return UPAP_AUTHACK;
+
+#if 0
+ int ret = (int)UPAP_AUTHNAK;
+
+ if (( userlen == 0 ) && ( passwdlen == 0 )) {
+ ret = (int)UPAP_AUTHACK;
+ }
+ printf("check_passwd: %d\n", ret);
+
+ return ret;
+#endif
+}
+
+/*
+ * null_login - Check if a username of "" and a password of "" are
+ * acceptable, and iff so, set the list of acceptable IP addresses
+ * and return 1.
+ */
+static int
+null_login(
+ int unit)
+{
+ return 0;
+}
+
+
+/*
+ * get_pap_passwd - get a password for authenticating ourselves with
+ * our peer using PAP. Returns 1 on success, 0 if no suitable password
+ * could be found.
+ * Assumes passwd points to MAXSECRETLEN bytes of space (if non-null).
+ */
+static int
+get_pap_passwd(
+ char *passwd)
+{
+ int ret = (int)0;
+
+ /*
+ * Check whether a plugin wants to supply this.
+ */
+ if (pap_passwd_hook) {
+ ret = (*pap_passwd_hook)(user, passwd);
+ }
+
+ return ( ret );
+}
+
+
+/*
+ * have_pap_secret - check whether we have a PAP file with any
+ * secrets that we could possibly use for authenticating the peer.
+ */
+static int
+have_pap_secret(
+ int *lacks_ipp)
+{
+ return 1;
+
+#if 0
+ int ret = (int)0;
+
+ /* let the plugin decide, if there is one */
+ printf("have_pap_secret:\n");
+ if (pap_check_hook) {
+ ret = (*pap_check_hook)();
+ }
+
+ return ( ret );
+#endif
+}
+
+
+/*
+ * have_chap_secret - check whether we have a CHAP file with a
+ * secret that we could possibly use for authenticating `client'
+ * on `server'. Either can be the null string, meaning we don't
+ * know the identity yet.
+ */
+static int
+have_chap_secret(
+ char *client,
+ char *server,
+ int need_ip,
+ int *lacks_ipp)
+{
+ return 0;
+}
+
+
+/*
+ * get_secret - open the CHAP secret file and return the secret
+ * for authenticating the given client on the given server.
+ * (We could be either client or server).
+ */
+int
+get_secret(
+ int unit,
+ char *client,
+ char *server,
+ unsigned char *secret,
+ int *secret_len,
+ int am_server)
+{
+ int len;
+ char secbuf[MAXWORDLEN];
+
+ if (!am_server && passwd[0] != 0) {
+ strlcpy(secbuf, passwd, sizeof(secbuf));
+ } else {
+ return 0;
+ }
+
+ len = strlen(secbuf);
+ if (len > MAXSECRETLEN) {
+ error("Secret for %s on %s is too long", client, server);
+ len = MAXSECRETLEN;
+ }
+ BCOPY(secbuf, secret, len);
+ BZERO(secbuf, sizeof(secbuf));
+ *secret_len = len;
+
+ return 1;
+}
+
+/*
+ * set_allowed_addrs() - set the list of allowed addresses.
+ * Also looks for `--' indicating options to apply for this peer
+ * and leaves the following words in extra_options.
+ */
+static void
+set_allowed_addrs(
+ int unit,
+ struct wordlist *addrs,
+ struct wordlist *opts)
+{
+ int n;
+ struct wordlist *ap, **pap;
+ struct permitted_ip *ip;
+ char *ptr_word, *ptr_mask;
+ struct hostent *hp;
+ struct netent *np;
+ uint32_t a, mask, ah, offset;
+ struct ipcp_options *wo = &ipcp_wantoptions[unit];
+ uint32_t suggested_ip = 0;
+
+ if (addresses[unit] != NULL)
+ free(addresses[unit]);
+ addresses[unit] = NULL;
+ if (extra_options != NULL)
+ free_wordlist(extra_options);
+ extra_options = opts;
+
+ /*
+ * Count the number of IP addresses given.
+ */
+ for (n = 0, pap = &addrs; (ap = *pap) != NULL; pap = &ap->next)
+ ++n;
+ if (n == 0)
+ return;
+ ip = (struct permitted_ip *) malloc((n + 1) * sizeof(struct permitted_ip));
+ if (ip == 0)
+ return;
+
+ n = 0;
+ for (ap = addrs; ap != NULL; ap = ap->next) {
+ /* "-" means no addresses authorized, "*" means any address allowed */
+ ptr_word = ap->word;
+ if (strcmp(ptr_word, "-") == 0)
+ break;
+ if (strcmp(ptr_word, "*") == 0) {
+ ip[n].permit = 1;
+ ip[n].base = ip[n].mask = 0;
+ ++n;
+ break;
+ }
+
+ ip[n].permit = 1;
+ if (*ptr_word == '!') {
+ ip[n].permit = 0;
+ ++ptr_word;
+ }
+
+ mask = ~ (uint32_t) 0;
+ offset = 0;
+ ptr_mask = strchr (ptr_word, '/');
+ if (ptr_mask != NULL) {
+ int bit_count;
+ char *endp;
+
+ bit_count = (int) strtol (ptr_mask+1, &endp, 10);
+ if (bit_count <= 0 || bit_count > 32) {
+ warn("invalid address length %v in auth. address list",
+ ptr_mask+1);
+ continue;
+ }
+ bit_count = 32 - bit_count; /* # bits in host part */
+ if (*endp == '+') {
+ offset = pppifunit + 1;
+ ++endp;
+ }
+ if (*endp != 0) {
+ warn("invalid address length syntax: %v", ptr_mask+1);
+ continue;
+ }
+ *ptr_mask = '\0';
+ mask <<= bit_count;
+ }
+
+ hp = gethostbyname(ptr_word);
+ if (hp != NULL && hp->h_addrtype == AF_INET) {
+ a = *(uint32_t *)hp->h_addr;
+ } else {
+ np = getnetbyname (ptr_word);
+ if (np != NULL && np->n_addrtype == AF_INET) {
+ a = htonl (np->n_net);
+ if (ptr_mask == NULL) {
+ /* calculate appropriate mask for net */
+ ah = ntohl(a);
+ if (IN_CLASSA(ah))
+ mask = IN_CLASSA_NET;
+ else if (IN_CLASSB(ah))
+ mask = IN_CLASSB_NET;
+ else if (IN_CLASSC(ah))
+ mask = IN_CLASSC_NET;
+ }
+ } else {
+ a = inet_addr (ptr_word);
+ }
+ }
+
+ if (ptr_mask != NULL)
+ *ptr_mask = '/';
+
+ if (a == (uint32_t)-1L) {
+ warn("unknown host %s in auth. address list", ap->word);
+ continue;
+ }
+ if (offset != 0) {
+ if (offset >= ~mask) {
+ warn("interface unit %d too large for subnet %v",
+ pppifunit, ptr_word);
+ continue;
+ }
+ a = htonl((ntohl(a) & mask) + offset);
+ mask = ~(uint32_t)0;
+ }
+ ip[n].mask = htonl(mask);
+ ip[n].base = a & ip[n].mask;
+ ++n;
+ if (~mask == 0 && suggested_ip == 0)
+ suggested_ip = a;
+ }
+
+ ip[n].permit = 0; /* make the last entry forbid all addresses */
+ ip[n].base = 0; /* to terminate the list */
+ ip[n].mask = 0;
+
+ addresses[unit] = ip;
+
+ /*
+ * If the address given for the peer isn't authorized, or if
+ * the user hasn't given one, AND there is an authorized address
+ * which is a single host, then use that if we find one.
+ */
+ if (suggested_ip != 0
+ && (wo->hisaddr == 0 || !auth_ip_addr(unit, wo->hisaddr)))
+ wo->hisaddr = suggested_ip;
+}
+
+/*
+ * auth_ip_addr - check whether the peer is authorized to use
+ * a given IP address. Returns 1 if authorized, 0 otherwise.
+ */
+int
+auth_ip_addr(
+ int unit,
+ uint32_t addr)
+{
+#if 0
+ int ok;
+#endif
+
+ /* don't allow loopback or multicast address */
+ if (bad_ip_adrs(addr))
+ return 0;
+
+ return 1;
+
+#if 0
+ if (addresses[unit] != NULL) {
+ ok = ip_addr_check(addr, addresses[unit]);
+ if (ok >= 0)
+ return ok;
+ }
+ if (auth_required)
+ return 0; /* no addresses authorized */
+ return allow_any_ip || !have_route_to(addr);
+#endif
+}
+
+#if 0
+static int
+ip_addr_check(
+ uint32_t addr,
+ struct permitted_ip *addrs)
+{
+ for (; ; ++addrs)
+ if ((addr & addrs->mask) == addrs->base)
+ return addrs->permit;
+}
+#endif
+
+/*
+ * bad_ip_adrs - return 1 if the IP address is one we don't want
+ * to use, such as an address in the loopback net or a multicast address.
+ * addr is in network byte order.
+ */
+int
+bad_ip_adrs(
+ uint32_t addr)
+{
+ addr = ntohl(addr);
+ return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
+ || IN_MULTICAST(addr) || IN_BADCLASS(addr);
+}
+
+/*
+ * free_wordlist - release memory allocated for a wordlist.
+ */
+static void
+free_wordlist(
+ struct wordlist *wp)
+{
+ struct wordlist *next;
+
+ while (wp != NULL) {
+ next = wp->next;
+ free(wp);
+ wp = next;
+ }
+}
+
+/*
+ * auth_script - execute a script with arguments
+ * interface-name peer-name real-user tty speed
+ */
+static void
+auth_script(
+ enum script_state s)
+{
+ switch (s) {
+ case s_up:
+ auth_script_state = s_up;
+ if ( auth_linkup_hook ) {
+ (*auth_linkup_hook)();
+ }
+ break;
+ case s_down:
+ auth_script_state = s_down;
+ if ( auth_linkdown_hook ) {
+ (*auth_linkdown_hook)();
+ }
+ break;
+ }
+}
diff --git a/cpukit/pppd/cbcp.c b/cpukit/pppd/cbcp.c
new file mode 100644
index 0000000000..eb750838cc
--- /dev/null
+++ b/cpukit/pppd/cbcp.c
@@ -0,0 +1,456 @@
+/*
+ * cbcp - Call Back Configuration Protocol.
+ *
+ * Copyright (c) 1995 Pedro Roque Marques
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Pedro Roque Marques. The name of the author may not be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "pppd.h"
+#include "cbcp.h"
+#include "fsm.h"
+#include "lcp.h"
+
+static const char rcsid[] = RCSID;
+
+/*
+ * Options.
+ */
+static int setcbcp(char **);
+
+static option_t cbcp_option_list[] = {
+ { "callback", o_special, setcbcp,
+ "Ask for callback" },
+ { NULL }
+};
+
+/*
+ * Protocol entry points.
+ */
+static void cbcp_init (int unit);
+static void cbcp_open (int unit);
+static void cbcp_lowerup (int unit);
+static void cbcp_input (int unit, u_char *pkt, int len);
+static void cbcp_protrej (int unit);
+static int cbcp_printpkt (u_char *pkt, int len,
+ void (*printer)(void *, char *, ...),
+ void *arg);
+
+struct protent cbcp_protent = {
+ PPP_CBCP,
+ cbcp_init,
+ cbcp_input,
+ cbcp_protrej,
+ cbcp_lowerup,
+ NULL,
+ cbcp_open,
+ NULL,
+ cbcp_printpkt,
+ NULL,
+ 0,
+ "CBCP",
+ NULL,
+ cbcp_option_list,
+ NULL,
+ NULL,
+ NULL
+};
+
+cbcp_state cbcp[NUM_PPP];
+
+/* internal prototypes */
+
+static void cbcp_recvreq(cbcp_state *us, char *pckt, int len);
+static void cbcp_resp(cbcp_state *us);
+static void cbcp_up(cbcp_state *us);
+static void cbcp_recvack(cbcp_state *us, char *pckt, int len);
+static void cbcp_send(cbcp_state *us, u_char code, u_char *buf, int len);
+
+/* option processing */
+static int
+setcbcp(argv)
+ char **argv;
+{
+ lcp_wantoptions[0].neg_cbcp = 1;
+ cbcp_protent.enabled_flag = 1;
+ cbcp[0].us_number = strdup(*argv);
+ if (cbcp[0].us_number == 0)
+ novm("callback number");
+ cbcp[0].us_type |= (1 << CB_CONF_USER);
+ cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
+ return (1);
+}
+
+/* init state */
+static void
+cbcp_init(iface)
+ int iface;
+{
+ cbcp_state *us;
+
+ us = &cbcp[iface];
+ memset(us, 0, sizeof(cbcp_state));
+ us->us_unit = iface;
+ us->us_type |= (1 << CB_CONF_NO);
+}
+
+/* lower layer is up */
+static void
+cbcp_lowerup(iface)
+ int iface;
+{
+ cbcp_state *us = &cbcp[iface];
+
+ dbglog("cbcp_lowerup");
+ dbglog("want: %d", us->us_type);
+
+ if (us->us_type == CB_CONF_USER)
+ dbglog("phone no: %s", us->us_number);
+}
+
+static void
+cbcp_open(unit)
+ int unit;
+{
+ dbglog("cbcp_open");
+}
+
+/* process an incomming packet */
+static void
+cbcp_input(unit, inpacket, pktlen)
+ int unit;
+ u_char *inpacket;
+ int pktlen;
+{
+ u_char *inp;
+ u_char code, id;
+ u_short len;
+
+ cbcp_state *us = &cbcp[unit];
+
+ inp = inpacket;
+
+ if (pktlen < CBCP_MINLEN) {
+ error("CBCP packet is too small");
+ return;
+ }
+
+ GETCHAR(code, inp);
+ GETCHAR(id, inp);
+ GETSHORT(len, inp);
+
+#if 0
+ if (len > pktlen) {
+ error("CBCP packet: invalid length");
+ return;
+ }
+#endif
+
+ len -= CBCP_MINLEN;
+
+ switch(code) {
+ case CBCP_REQ:
+ us->us_id = id;
+ cbcp_recvreq(us, inp, len);
+ break;
+
+ case CBCP_RESP:
+ dbglog("CBCP_RESP received");
+ break;
+
+ case CBCP_ACK:
+ if (id != us->us_id)
+ dbglog("id doesn't match: expected %d recv %d",
+ us->us_id, id);
+
+ cbcp_recvack(us, inp, len);
+ break;
+
+ default:
+ break;
+ }
+}
+
+/* protocol was rejected by foe */
+void cbcp_protrej(int iface)
+{
+}
+
+char *cbcp_codenames[] = {
+ "Request", "Response", "Ack"
+};
+
+char *cbcp_optionnames[] = {
+ "NoCallback",
+ "UserDefined",
+ "AdminDefined",
+ "List"
+};
+
+/* pretty print a packet */
+static int
+cbcp_printpkt(p, plen, printer, arg)
+ u_char *p;
+ int plen;
+ void (*printer)(void *, char *, ...);
+ void *arg;
+{
+ int code, opt, id, len, olen, delay;
+ u_char *pstart;
+
+ if (plen < HEADERLEN)
+ return 0;
+ pstart = p;
+ GETCHAR(code, p);
+ GETCHAR(id, p);
+ GETSHORT(len, p);
+ if (len < HEADERLEN || len > plen)
+ return 0;
+
+ if (code >= 1 && code <= sizeof(cbcp_codenames) / sizeof(char *))
+ printer(arg, " %s", cbcp_codenames[code-1]);
+ else
+ printer(arg, " code=0x%x", code);
+
+ printer(arg, " id=0x%x", id);
+ len -= HEADERLEN;
+
+ switch (code) {
+ case CBCP_REQ:
+ case CBCP_RESP:
+ case CBCP_ACK:
+ while(len >= 2) {
+ GETCHAR(opt, p);
+ GETCHAR(olen, p);
+
+ if (olen < 2 || olen > len) {
+ break;
+ }
+
+ printer(arg, " <");
+ len -= olen;
+
+ if (opt >= 1 && opt <= sizeof(cbcp_optionnames) / sizeof(char *))
+ printer(arg, " %s", cbcp_optionnames[opt-1]);
+ else
+ printer(arg, " option=0x%x", opt);
+
+ if (olen > 2) {
+ GETCHAR(delay, p);
+ printer(arg, " delay = %d", delay);
+ }
+
+ if (olen > 3) {
+ int addrt;
+ char str[256];
+
+ GETCHAR(addrt, p);
+ memcpy(str, p, olen - 4);
+ str[olen - 4] = 0;
+ printer(arg, " number = %s", str);
+ }
+ printer(arg, ">");
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ for (; len > 0; --len) {
+ GETCHAR(code, p);
+ printer(arg, " %.2x", code);
+ }
+
+ return p - pstart;
+}
+
+/* received CBCP request */
+static void
+cbcp_recvreq(us, pckt, pcktlen)
+ cbcp_state *us;
+ char *pckt;
+ int pcktlen;
+{
+ u_char type, opt_len, delay, addr_type;
+ char address[256];
+ int len = pcktlen;
+
+ address[0] = 0;
+
+ while (len) {
+ dbglog("length: %d", len);
+
+ GETCHAR(type, pckt);
+ GETCHAR(opt_len, pckt);
+
+ if (opt_len > 2)
+ GETCHAR(delay, pckt);
+
+ us->us_allowed |= (1 << type);
+
+ switch(type) {
+ case CB_CONF_NO:
+ dbglog("no callback allowed");
+ break;
+
+ case CB_CONF_USER:
+ dbglog("user callback allowed");
+ if (opt_len > 4) {
+ GETCHAR(addr_type, pckt);
+ memcpy(address, pckt, opt_len - 4);
+ address[opt_len - 4] = 0;
+ if (address[0])
+ dbglog("address: %s", address);
+ }
+ break;
+
+ case CB_CONF_ADMIN:
+ dbglog("user admin defined allowed");
+ break;
+
+ case CB_CONF_LIST:
+ break;
+ }
+ len -= opt_len;
+ }
+
+ cbcp_resp(us);
+}
+
+static void
+cbcp_resp(us)
+ cbcp_state *us;
+{
+ u_char cb_type;
+ u_char buf[256];
+ u_char *bufp = buf;
+ int len = 0;
+
+ cb_type = us->us_allowed & us->us_type;
+ dbglog("cbcp_resp cb_type=%d", cb_type);
+
+#if 0
+ if (!cb_type)
+ lcp_down(us->us_unit);
+#endif
+
+ if (cb_type & ( 1 << CB_CONF_USER ) ) {
+ dbglog("cbcp_resp CONF_USER");
+ PUTCHAR(CB_CONF_USER, bufp);
+ len = 3 + 1 + strlen(us->us_number) + 1;
+ PUTCHAR(len , bufp);
+ PUTCHAR(5, bufp); /* delay */
+ PUTCHAR(1, bufp);
+ BCOPY(us->us_number, bufp, strlen(us->us_number) + 1);
+ cbcp_send(us, CBCP_RESP, buf, len);
+ return;
+ }
+
+ if (cb_type & ( 1 << CB_CONF_ADMIN ) ) {
+ dbglog("cbcp_resp CONF_ADMIN");
+ PUTCHAR(CB_CONF_ADMIN, bufp);
+ len = 3;
+ PUTCHAR(len, bufp);
+ PUTCHAR(5, bufp); /* delay */
+ cbcp_send(us, CBCP_RESP, buf, len);
+ return;
+ }
+
+ if (cb_type & ( 1 << CB_CONF_NO ) ) {
+ dbglog("cbcp_resp CONF_NO");
+ PUTCHAR(CB_CONF_NO, bufp);
+ len = 3;
+ PUTCHAR(len , bufp);
+ PUTCHAR(0, bufp);
+ cbcp_send(us, CBCP_RESP, buf, len);
+ start_networks();
+ return;
+ }
+}
+
+static void
+cbcp_send(us, code, buf, len)
+ cbcp_state *us;
+ u_char code;
+ u_char *buf;
+ int len;
+{
+ u_char *outp;
+ int outlen;
+
+ outp = outpacket_buf;
+
+ outlen = 4 + len;
+
+ MAKEHEADER(outp, PPP_CBCP);
+
+ PUTCHAR(code, outp);
+ PUTCHAR(us->us_id, outp);
+ PUTSHORT(outlen, outp);
+
+ if (len)
+ BCOPY(buf, outp, len);
+
+ output(us->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
+}
+
+static void
+cbcp_recvack(us, pckt, len)
+ cbcp_state *us;
+ char *pckt;
+ int len;
+{
+ u_char type, delay, addr_type;
+ int opt_len;
+ char address[256];
+
+ if (len) {
+ GETCHAR(type, pckt);
+ GETCHAR(opt_len, pckt);
+
+ if (opt_len > 2)
+ GETCHAR(delay, pckt);
+
+ if (opt_len > 4) {
+ GETCHAR(addr_type, pckt);
+ memcpy(address, pckt, opt_len - 4);
+ address[opt_len - 4] = 0;
+ if (address[0])
+ dbglog("peer will call: %s", address);
+ }
+ if (type == CB_CONF_NO)
+ return;
+ }
+
+ cbcp_up(us);
+}
+
+/* ok peer will do callback */
+static void
+cbcp_up(us)
+ cbcp_state *us;
+{
+ persist = 0;
+ lcp_close(0, "Call me back, please");
+ status = EXIT_CALLBACK;
+}
diff --git a/cpukit/pppd/cbcp.h b/cpukit/pppd/cbcp.h
new file mode 100644
index 0000000000..c2ab3f6899
--- /dev/null
+++ b/cpukit/pppd/cbcp.h
@@ -0,0 +1,26 @@
+#ifndef CBCP_H
+#define CBCP_H
+
+typedef struct cbcp_state {
+ int us_unit; /* Interface unit number */
+ u_char us_id; /* Current id */
+ u_char us_allowed;
+ int us_type;
+ char *us_number; /* Telefone Number */
+} cbcp_state;
+
+extern cbcp_state cbcp[];
+
+extern struct protent cbcp_protent;
+
+#define CBCP_MINLEN 4
+
+#define CBCP_REQ 1
+#define CBCP_RESP 2
+#define CBCP_ACK 3
+
+#define CB_CONF_NO 1
+#define CB_CONF_USER 2
+#define CB_CONF_ADMIN 3
+#define CB_CONF_LIST 4
+#endif
diff --git a/cpukit/pppd/ccp.c b/cpukit/pppd/ccp.c
new file mode 100644
index 0000000000..d80df270f7
--- /dev/null
+++ b/cpukit/pppd/ccp.c
@@ -0,0 +1,1228 @@
+/*
+ * ccp.c - PPP Compression Control Protocol.
+ *
+ * Copyright (c) 1994 The Australian National University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation is hereby granted, provided that the above copyright
+ * notice appears in all copies. This software is provided without any
+ * warranty, express or implied. The Australian National University
+ * makes no representations about the suitability of this software for
+ * any purpose.
+ *
+ * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
+ * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+ * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
+ * OR MODIFICATIONS.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "pppd.h"
+#include "fsm.h"
+#include "ccp.h"
+#include <net/ppp_comp.h>
+
+static const char rcsid[] = RCSID;
+
+/*
+ * Command-line options.
+ */
+static int setbsdcomp(char **);
+static int setdeflate(char **);
+
+static option_t ccp_option_list[] = {
+ { "noccp", o_bool, &ccp_protent.enabled_flag,
+ "Disable CCP negotiation", 0, NULL, 0, 0 },
+ { "-ccp", o_bool, &ccp_protent.enabled_flag,
+ "Disable CCP negotiation", 0, NULL, 0, 0 },
+ { "bsdcomp", o_special, setbsdcomp,
+ "Request BSD-Compress packet compression", 0, NULL, 0, 0 },
+ { "nobsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
+ "don't allow BSD-Compress", OPT_A2COPY,
+ &ccp_allowoptions[0].bsd_compress, 0, 0 },
+ { "-bsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
+ "don't allow BSD-Compress", OPT_A2COPY,
+ &ccp_allowoptions[0].bsd_compress, 0, 0 },
+ { "deflate", 1, setdeflate,
+ "request Deflate compression", 0, NULL, 0, 0 },
+ { "nodeflate", o_bool, &ccp_wantoptions[0].deflate,
+ "don't allow Deflate compression", OPT_A2COPY,
+ &ccp_allowoptions[0].deflate, 0, 0 },
+ { "-deflate", o_bool, &ccp_wantoptions[0].deflate,
+ "don't allow Deflate compression", OPT_A2COPY,
+ &ccp_allowoptions[0].deflate, 0, 0 },
+ { "nodeflatedraft", o_bool, &ccp_wantoptions[0].deflate_draft,
+ "don't use draft deflate #", OPT_A2COPY,
+ &ccp_allowoptions[0].deflate_draft, 0, 0 },
+ { "predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
+ "request Predictor-1", 1,
+ &ccp_allowoptions[0].predictor_1, 0, 0 },
+ { "nopredictor1", o_bool, &ccp_wantoptions[0].predictor_1,
+ "don't allow Predictor-1", OPT_A2COPY,
+ &ccp_allowoptions[0].predictor_1, 0, 0 },
+ { "-predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
+ "don't allow Predictor-1", OPT_A2COPY,
+ &ccp_allowoptions[0].predictor_1, 0, 0 },
+
+ { NULL, 0, NULL, NULL, 0, NULL, 0, 0 }
+};
+
+/*
+ * Protocol entry points from main code.
+ */
+static void ccp_init(int unit);
+static void ccp_open(int unit);
+static void ccp_close(int unit, char *);
+static void ccp_lowerup(int unit);
+static void ccp_lowerdown(int);
+static void ccp_input(int unit, u_char *pkt, int len);
+static void ccp_protrej(int unit);
+static int ccp_printpkt(u_char *pkt, int len,
+ void (*printer)(void *, char *, ...),
+ void *arg);
+static void ccp_datainput(int unit, u_char *pkt, int len);
+
+struct protent ccp_protent = {
+ PPP_CCP,
+ ccp_init,
+ ccp_input,
+ ccp_protrej,
+ ccp_lowerup,
+ ccp_lowerdown,
+ ccp_open,
+ ccp_close,
+ ccp_printpkt,
+ ccp_datainput,
+ 1,
+ "CCP",
+ "Compressed",
+ ccp_option_list,
+ NULL,
+ NULL,
+ NULL
+};
+
+fsm ccp_fsm[NUM_PPP];
+ccp_options ccp_wantoptions[NUM_PPP]; /* what to request the peer to use */
+ccp_options ccp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
+ccp_options ccp_allowoptions[NUM_PPP]; /* what we'll agree to do */
+ccp_options ccp_hisoptions[NUM_PPP]; /* what we agreed to do */
+
+/*
+ * Callbacks for fsm code.
+ */
+static void ccp_resetci(fsm *);
+static int ccp_cilen(fsm *);
+static void ccp_addci(fsm *, u_char *, int *);
+static int ccp_ackci(fsm *, u_char *, int);
+static int ccp_nakci(fsm *, u_char *, int);
+static int ccp_rejci(fsm *, u_char *, int);
+static int ccp_reqci(fsm *, u_char *, int *, int);
+static void ccp_up(fsm *);
+static void ccp_down(fsm *);
+static int ccp_extcode(fsm *, int, int, u_char *, int);
+static void ccp_rack_timeout(void *);
+static char *method_name(ccp_options *, ccp_options *);
+
+static fsm_callbacks ccp_callbacks = {
+ ccp_resetci,
+ ccp_cilen,
+ ccp_addci,
+ ccp_ackci,
+ ccp_nakci,
+ ccp_rejci,
+ ccp_reqci,
+ ccp_up,
+ ccp_down,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ccp_extcode,
+ "CCP"
+};
+
+/*
+ * Do we want / did we get any compression?
+ */
+#define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
+ || (opt).predictor_1 || (opt).predictor_2)
+
+/*
+ * Local state (mainly for handling reset-reqs and reset-acks).
+ */
+static int ccp_localstate[NUM_PPP];
+#define RACK_PENDING 1 /* waiting for reset-ack */
+#define RREQ_REPEAT 2 /* send another reset-req if no reset-ack */
+
+#define RACKTIMEOUT 1 /* second */
+
+static int all_rejected[NUM_PPP]; /* we rejected all peer's options */
+
+/*
+ * Option parsing.
+ */
+static int
+setbsdcomp(
+ char **argv)
+{
+ int rbits, abits;
+ char *str, *endp;
+
+ str = *argv;
+ abits = rbits = strtol(str, &endp, 0);
+ if (endp != str && *endp == ',') {
+ str = endp + 1;
+ abits = strtol(str, &endp, 0);
+ }
+ if (*endp != 0 || endp == str) {
+ option_error("invalid parameter '%s' for bsdcomp option", *argv);
+ return 0;
+ }
+ if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
+ || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
+ option_error("bsdcomp option values must be 0 or %d .. %d",
+ BSD_MIN_BITS, BSD_MAX_BITS);
+ return 0;
+ }
+ if (rbits > 0) {
+ ccp_wantoptions[0].bsd_compress = 1;
+ ccp_wantoptions[0].bsd_bits = rbits;
+ } else
+ ccp_wantoptions[0].bsd_compress = 0;
+ if (abits > 0) {
+ ccp_allowoptions[0].bsd_compress = 1;
+ ccp_allowoptions[0].bsd_bits = abits;
+ } else
+ ccp_allowoptions[0].bsd_compress = 0;
+ return 1;
+}
+
+static int
+setdeflate(
+ char **argv)
+{
+ int rbits, abits;
+ char *str, *endp;
+
+ str = *argv;
+ abits = rbits = strtol(str, &endp, 0);
+ if (endp != str && *endp == ',') {
+ str = endp + 1;
+ abits = strtol(str, &endp, 0);
+ }
+ if (*endp != 0 || endp == str) {
+ option_error("invalid parameter '%s' for deflate option", *argv);
+ return 0;
+ }
+ if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
+ || (abits != 0 && (abits < DEFLATE_MIN_SIZE
+ || abits > DEFLATE_MAX_SIZE))) {
+ option_error("deflate option values must be 0 or %d .. %d",
+ DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
+ return 0;
+ }
+ if (rbits > 0) {
+ ccp_wantoptions[0].deflate = 1;
+ ccp_wantoptions[0].deflate_size = rbits;
+ } else
+ ccp_wantoptions[0].deflate = 0;
+ if (abits > 0) {
+ ccp_allowoptions[0].deflate = 1;
+ ccp_allowoptions[0].deflate_size = abits;
+ } else
+ ccp_allowoptions[0].deflate = 0;
+ return 1;
+}
+
+
+/*
+ * ccp_init - initialize CCP.
+ */
+static void
+ccp_init(
+ int unit)
+{
+ fsm *f = &ccp_fsm[unit];
+
+ f->unit = unit;
+ f->protocol = PPP_CCP;
+ f->callbacks = &ccp_callbacks;
+ fsm_init(f);
+
+ memset(&ccp_wantoptions[unit], 0, sizeof(ccp_options));
+ memset(&ccp_gotoptions[unit], 0, sizeof(ccp_options));
+ memset(&ccp_allowoptions[unit], 0, sizeof(ccp_options));
+ memset(&ccp_hisoptions[unit], 0, sizeof(ccp_options));
+
+ ccp_wantoptions[0].deflate = 1;
+ ccp_wantoptions[0].deflate_size = DEFLATE_MAX_SIZE;
+ ccp_wantoptions[0].deflate_correct = 1;
+ ccp_wantoptions[0].deflate_draft = 1;
+ ccp_allowoptions[0].deflate = 1;
+ ccp_allowoptions[0].deflate_size = DEFLATE_MAX_SIZE;
+ ccp_allowoptions[0].deflate_correct = 1;
+ ccp_allowoptions[0].deflate_draft = 1;
+
+ ccp_wantoptions[0].bsd_compress = 1;
+ ccp_wantoptions[0].bsd_bits = BSD_MAX_BITS;
+ ccp_allowoptions[0].bsd_compress = 1;
+ ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
+
+ ccp_allowoptions[0].predictor_1 = 1;
+}
+
+/*
+ * ccp_open - CCP is allowed to come up.
+ */
+static void
+ccp_open(
+ int unit)
+{
+ fsm *f = &ccp_fsm[unit];
+
+ if (f->state != OPENED)
+ ccp_flags_set(unit, 1, 0);
+
+ /*
+ * Find out which compressors the kernel supports before
+ * deciding whether to open in silent mode.
+ */
+ ccp_resetci(f);
+ if (!ANY_COMPRESS(ccp_gotoptions[unit]))
+ f->flags |= OPT_SILENT;
+
+ fsm_open(f);
+}
+
+/*
+ * ccp_close - Terminate CCP.
+ */
+static void
+ccp_close(
+ int unit,
+ char *reason)
+{
+ ccp_flags_set(unit, 0, 0);
+ fsm_close(&ccp_fsm[unit], reason);
+}
+
+/*
+ * ccp_lowerup - we may now transmit CCP packets.
+ */
+static void
+ccp_lowerup(
+ int unit)
+{
+ fsm_lowerup(&ccp_fsm[unit]);
+}
+
+/*
+ * ccp_lowerdown - we may not transmit CCP packets.
+ */
+static void
+ccp_lowerdown(
+ int unit)
+{
+ fsm_lowerdown(&ccp_fsm[unit]);
+}
+
+/*
+ * ccp_input - process a received CCP packet.
+ */
+static void
+ccp_input(
+ int unit,
+ u_char *p,
+ int len)
+{
+ fsm *f = &ccp_fsm[unit];
+ int oldstate;
+
+ /*
+ * Check for a terminate-request so we can print a message.
+ */
+ oldstate = f->state;
+ fsm_input(f, p, len);
+ if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED)
+ notice("Compression disabled by peer.");
+
+ /*
+ * If we get a terminate-ack and we're not asking for compression,
+ * close CCP.
+ */
+ if (oldstate == REQSENT && p[0] == TERMACK
+ && !ANY_COMPRESS(ccp_gotoptions[unit]))
+ ccp_close(unit, "No compression negotiated");
+}
+
+/*
+ * Handle a CCP-specific code.
+ */
+static int
+ccp_extcode(
+ fsm *f,
+ int code, int id,
+ u_char *p,
+ int len)
+{
+ switch (code) {
+ case CCP_RESETREQ:
+ if (f->state != OPENED)
+ break;
+ /* send a reset-ack, which the transmitter will see and
+ reset its compression state. */
+ fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
+ break;
+
+ case CCP_RESETACK:
+ if (ccp_localstate[f->unit] & RACK_PENDING && id == f->reqid) {
+ ccp_localstate[f->unit] &= ~(RACK_PENDING | RREQ_REPEAT);
+ UNTIMEOUT(ccp_rack_timeout, f);
+ }
+ break;
+
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * ccp_protrej - peer doesn't talk CCP.
+ */
+static void
+ccp_protrej(
+ int unit)
+{
+ ccp_flags_set(unit, 0, 0);
+ fsm_lowerdown(&ccp_fsm[unit]);
+}
+
+/*
+ * ccp_resetci - initialize at start of negotiation.
+ */
+static void
+ccp_resetci(
+ fsm *f)
+{
+ ccp_options *go = &ccp_gotoptions[f->unit];
+ u_char opt_buf[16];
+
+ *go = ccp_wantoptions[f->unit];
+ all_rejected[f->unit] = 0;
+
+ /*
+ * Check whether the kernel knows about the various
+ * compression methods we might request.
+ */
+ if (go->bsd_compress) {
+ opt_buf[0] = CI_BSD_COMPRESS;
+ opt_buf[1] = CILEN_BSD_COMPRESS;
+ opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, BSD_MIN_BITS);
+ if (ccp_test(f->unit, opt_buf, CILEN_BSD_COMPRESS, 0) <= 0)
+ go->bsd_compress = 0;
+ }
+ if (go->deflate) {
+ if (go->deflate_correct) {
+ opt_buf[0] = CI_DEFLATE;
+ opt_buf[1] = CILEN_DEFLATE;
+ opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_SIZE);
+ opt_buf[3] = DEFLATE_CHK_SEQUENCE;
+ if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
+ go->deflate_correct = 0;
+ }
+ if (go->deflate_draft) {
+ opt_buf[0] = CI_DEFLATE_DRAFT;
+ opt_buf[1] = CILEN_DEFLATE;
+ opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_SIZE);
+ opt_buf[3] = DEFLATE_CHK_SEQUENCE;
+ if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
+ go->deflate_draft = 0;
+ }
+ if (!go->deflate_correct && !go->deflate_draft)
+ go->deflate = 0;
+ }
+ if (go->predictor_1) {
+ opt_buf[0] = CI_PREDICTOR_1;
+ opt_buf[1] = CILEN_PREDICTOR_1;
+ if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
+ go->predictor_1 = 0;
+ }
+ if (go->predictor_2) {
+ opt_buf[0] = CI_PREDICTOR_2;
+ opt_buf[1] = CILEN_PREDICTOR_2;
+ if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
+ go->predictor_2 = 0;
+ }
+}
+
+/*
+ * ccp_cilen - Return total length of our configuration info.
+ */
+static int
+ccp_cilen(
+ fsm *f)
+{
+ ccp_options *go = &ccp_gotoptions[f->unit];
+
+ return (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
+ + (go->deflate? CILEN_DEFLATE: 0)
+ + (go->predictor_1? CILEN_PREDICTOR_1: 0)
+ + (go->predictor_2? CILEN_PREDICTOR_2: 0);
+}
+
+/*
+ * ccp_addci - put our requests in a packet.
+ */
+static void
+ccp_addci(
+ fsm *f,
+ u_char *p,
+ int *lenp)
+{
+ int res;
+ ccp_options *go = &ccp_gotoptions[f->unit];
+ u_char *p0 = p;
+
+ /*
+ * Add the compression types that we can receive, in decreasing
+ * preference order. Get the kernel to allocate the first one
+ * in case it gets Acked.
+ */
+ if (go->deflate) {
+ p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
+ p[1] = CILEN_DEFLATE;
+ p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
+ p[3] = DEFLATE_CHK_SEQUENCE;
+ for (;;) {
+ res = ccp_test(f->unit, p, CILEN_DEFLATE, 0);
+ if (res > 0) {
+ p += CILEN_DEFLATE;
+ break;
+ }
+ if (res < 0 || go->deflate_size <= DEFLATE_MIN_SIZE) {
+ go->deflate = 0;
+ break;
+ }
+ --go->deflate_size;
+ p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
+ }
+ if (p != p0 && go->deflate_correct && go->deflate_draft) {
+ p[0] = CI_DEFLATE_DRAFT;
+ p[1] = CILEN_DEFLATE;
+ p[2] = p[2 - CILEN_DEFLATE];
+ p[3] = DEFLATE_CHK_SEQUENCE;
+ p += CILEN_DEFLATE;
+ }
+ }
+ if (go->bsd_compress) {
+ p[0] = CI_BSD_COMPRESS;
+ p[1] = CILEN_BSD_COMPRESS;
+ p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
+ if (p != p0) {
+ p += CILEN_BSD_COMPRESS; /* not the first option */
+ } else {
+ for (;;) {
+ res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
+ if (res > 0) {
+ p += CILEN_BSD_COMPRESS;
+ break;
+ }
+ if (res < 0 || go->bsd_bits <= BSD_MIN_BITS) {
+ go->bsd_compress = 0;
+ break;
+ }
+ --go->bsd_bits;
+ p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
+ }
+ }
+ }
+ /* XXX Should Predictor 2 be preferable to Predictor 1? */
+ if (go->predictor_1) {
+ p[0] = CI_PREDICTOR_1;
+ p[1] = CILEN_PREDICTOR_1;
+ if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 0) <= 0) {
+ go->predictor_1 = 0;
+ } else {
+ p += CILEN_PREDICTOR_1;
+ }
+ }
+ if (go->predictor_2) {
+ p[0] = CI_PREDICTOR_2;
+ p[1] = CILEN_PREDICTOR_2;
+ if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 0) <= 0) {
+ go->predictor_2 = 0;
+ } else {
+ p += CILEN_PREDICTOR_2;
+ }
+ }
+
+ go->method = (p > p0)? p0[0]: -1;
+
+ *lenp = p - p0;
+}
+
+/*
+ * ccp_ackci - process a received configure-ack, and return
+ * 1 iff the packet was OK.
+ */
+static int
+ccp_ackci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ ccp_options *go = &ccp_gotoptions[f->unit];
+ u_char *p0 = p;
+
+ if (go->deflate) {
+ if (len < CILEN_DEFLATE
+ || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
+ || p[1] != CILEN_DEFLATE
+ || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
+ || p[3] != DEFLATE_CHK_SEQUENCE)
+ return 0;
+ p += CILEN_DEFLATE;
+ len -= CILEN_DEFLATE;
+ /* XXX Cope with first/fast ack */
+ if (len == 0)
+ return 1;
+ if (go->deflate_correct && go->deflate_draft) {
+ if (len < CILEN_DEFLATE
+ || p[0] != CI_DEFLATE_DRAFT
+ || p[1] != CILEN_DEFLATE
+ || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
+ || p[3] != DEFLATE_CHK_SEQUENCE)
+ return 0;
+ p += CILEN_DEFLATE;
+ len -= CILEN_DEFLATE;
+ }
+ }
+ if (go->bsd_compress) {
+ if (len < CILEN_BSD_COMPRESS
+ || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
+ || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
+ return 0;
+ p += CILEN_BSD_COMPRESS;
+ len -= CILEN_BSD_COMPRESS;
+ /* XXX Cope with first/fast ack */
+ if (p == p0 && len == 0)
+ return 1;
+ }
+ if (go->predictor_1) {
+ if (len < CILEN_PREDICTOR_1
+ || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
+ return 0;
+ p += CILEN_PREDICTOR_1;
+ len -= CILEN_PREDICTOR_1;
+ /* XXX Cope with first/fast ack */
+ if (p == p0 && len == 0)
+ return 1;
+ }
+ if (go->predictor_2) {
+ if (len < CILEN_PREDICTOR_2
+ || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
+ return 0;
+ p += CILEN_PREDICTOR_2;
+ len -= CILEN_PREDICTOR_2;
+ /* XXX Cope with first/fast ack */
+ if (p == p0 && len == 0)
+ return 1;
+ }
+
+ if (len != 0)
+ return 0;
+ return 1;
+}
+
+/*
+ * ccp_nakci - process received configure-nak.
+ * Returns 1 iff the nak was OK.
+ */
+static int
+ccp_nakci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ ccp_options *go = &ccp_gotoptions[f->unit];
+ ccp_options no; /* options we've seen already */
+ ccp_options try; /* options to ask for next time */
+
+ memset(&no, 0, sizeof(no));
+ try = *go;
+
+ if (go->deflate && len >= CILEN_DEFLATE
+ && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
+ && p[1] == CILEN_DEFLATE) {
+ no.deflate = 1;
+ /*
+ * Peer wants us to use a different code size or something.
+ * Stop asking for Deflate if we don't understand his suggestion.
+ */
+ if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
+ || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_SIZE
+ || p[3] != DEFLATE_CHK_SEQUENCE)
+ try.deflate = 0;
+ else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
+ try.deflate_size = DEFLATE_SIZE(p[2]);
+ p += CILEN_DEFLATE;
+ len -= CILEN_DEFLATE;
+ if (go->deflate_correct && go->deflate_draft
+ && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
+ && p[1] == CILEN_DEFLATE) {
+ p += CILEN_DEFLATE;
+ len -= CILEN_DEFLATE;
+ }
+ }
+
+ if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
+ && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
+ no.bsd_compress = 1;
+ /*
+ * Peer wants us to use a different number of bits
+ * or a different version.
+ */
+ if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
+ try.bsd_compress = 0;
+ else if (BSD_NBITS(p[2]) < go->bsd_bits)
+ try.bsd_bits = BSD_NBITS(p[2]);
+ p += CILEN_BSD_COMPRESS;
+ len -= CILEN_BSD_COMPRESS;
+ }
+
+ /*
+ * Predictor-1 and 2 have no options, so they can't be Naked.
+ *
+ * There may be remaining options but we ignore them.
+ */
+
+ if (f->state != OPENED)
+ *go = try;
+ return 1;
+}
+
+/*
+ * ccp_rejci - reject some of our suggested compression methods.
+ */
+static int
+ccp_rejci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ ccp_options *go = &ccp_gotoptions[f->unit];
+ ccp_options try; /* options to request next time */
+
+ try = *go;
+
+ /*
+ * Cope with empty configure-rejects by ceasing to send
+ * configure-requests.
+ */
+ if (len == 0 && all_rejected[f->unit])
+ return -1;
+
+ if (go->deflate && len >= CILEN_DEFLATE
+ && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
+ && p[1] == CILEN_DEFLATE) {
+ if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
+ || p[3] != DEFLATE_CHK_SEQUENCE)
+ return 0; /* Rej is bad */
+ if (go->deflate_correct)
+ try.deflate_correct = 0;
+ else
+ try.deflate_draft = 0;
+ p += CILEN_DEFLATE;
+ len -= CILEN_DEFLATE;
+ if (go->deflate_correct && go->deflate_draft
+ && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
+ && p[1] == CILEN_DEFLATE) {
+ if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
+ || p[3] != DEFLATE_CHK_SEQUENCE)
+ return 0; /* Rej is bad */
+ try.deflate_draft = 0;
+ p += CILEN_DEFLATE;
+ len -= CILEN_DEFLATE;
+ }
+ if (!try.deflate_correct && !try.deflate_draft)
+ try.deflate = 0;
+ }
+ if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
+ && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
+ if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
+ return 0;
+ try.bsd_compress = 0;
+ p += CILEN_BSD_COMPRESS;
+ len -= CILEN_BSD_COMPRESS;
+ }
+ if (go->predictor_1 && len >= CILEN_PREDICTOR_1
+ && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
+ try.predictor_1 = 0;
+ p += CILEN_PREDICTOR_1;
+ len -= CILEN_PREDICTOR_1;
+ }
+ if (go->predictor_2 && len >= CILEN_PREDICTOR_2
+ && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
+ try.predictor_2 = 0;
+ p += CILEN_PREDICTOR_2;
+ len -= CILEN_PREDICTOR_2;
+ }
+
+ if (len != 0)
+ return 0;
+
+ if (f->state != OPENED)
+ *go = try;
+
+ return 1;
+}
+
+/*
+ * ccp_reqci - processed a received configure-request.
+ * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
+ * appropriately.
+ */
+static int
+ccp_reqci(
+ fsm *f,
+ u_char *p,
+ int *lenp,
+ int dont_nak)
+{
+ int ret, newret, res;
+ u_char *p0, *retp;
+ int len, clen, type, nb;
+ ccp_options *ho = &ccp_hisoptions[f->unit];
+ ccp_options *ao = &ccp_allowoptions[f->unit];
+
+ ret = CONFACK;
+ retp = p0 = p;
+ len = *lenp;
+
+ memset(ho, 0, sizeof(ccp_options));
+ ho->method = (len > 0)? p[0]: -1;
+
+ while (len > 0) {
+ newret = CONFACK;
+ if (len < 2 || p[1] < 2 || p[1] > len) {
+ /* length is bad */
+ clen = len;
+ newret = CONFREJ;
+
+ } else {
+ type = p[0];
+ clen = p[1];
+
+ switch (type) {
+ case CI_DEFLATE:
+ case CI_DEFLATE_DRAFT:
+ if (!ao->deflate || clen != CILEN_DEFLATE
+ || (!ao->deflate_correct && type == CI_DEFLATE)
+ || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
+ newret = CONFREJ;
+ break;
+ }
+
+ ho->deflate = 1;
+ ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
+ if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
+ || p[3] != DEFLATE_CHK_SEQUENCE
+ || nb > ao->deflate_size || nb < DEFLATE_MIN_SIZE) {
+ newret = CONFNAK;
+ if (!dont_nak) {
+ p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
+ p[3] = DEFLATE_CHK_SEQUENCE;
+ /* fall through to test this #bits below */
+ } else
+ break;
+ }
+
+ /*
+ * Check whether we can do Deflate with the window
+ * size they want. If the window is too big, reduce
+ * it until the kernel can cope and nak with that.
+ * We only check this for the first option.
+ */
+ if (p == p0) {
+ for (;;) {
+ res = ccp_test(f->unit, p, CILEN_DEFLATE, 1);
+ if (res > 0)
+ break; /* it's OK now */
+ if (res < 0 || nb == DEFLATE_MIN_SIZE || dont_nak) {
+ newret = CONFREJ;
+ p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
+ break;
+ }
+ newret = CONFNAK;
+ --nb;
+ p[2] = DEFLATE_MAKE_OPT(nb);
+ }
+ }
+ break;
+
+ case CI_BSD_COMPRESS:
+ if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
+ newret = CONFREJ;
+ break;
+ }
+
+ ho->bsd_compress = 1;
+ ho->bsd_bits = nb = BSD_NBITS(p[2]);
+ if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
+ || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
+ newret = CONFNAK;
+ if (!dont_nak) {
+ p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
+ /* fall through to test this #bits below */
+ } else
+ break;
+ }
+
+ /*
+ * Check whether we can do BSD-Compress with the code
+ * size they want. If the code size is too big, reduce
+ * it until the kernel can cope and nak with that.
+ * We only check this for the first option.
+ */
+ if (p == p0) {
+ for (;;) {
+ res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 1);
+ if (res > 0)
+ break;
+ if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
+ newret = CONFREJ;
+ p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
+ ho->bsd_bits);
+ break;
+ }
+ newret = CONFNAK;
+ --nb;
+ p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
+ }
+ }
+ break;
+
+ case CI_PREDICTOR_1:
+ if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
+ newret = CONFREJ;
+ break;
+ }
+
+ ho->predictor_1 = 1;
+ if (p == p0
+ && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 1) <= 0) {
+ newret = CONFREJ;
+ }
+ break;
+
+ case CI_PREDICTOR_2:
+ if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
+ newret = CONFREJ;
+ break;
+ }
+
+ ho->predictor_2 = 1;
+ if (p == p0
+ && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 1) <= 0) {
+ newret = CONFREJ;
+ }
+ break;
+
+ default:
+ newret = CONFREJ;
+ }
+ }
+
+ if (newret == CONFNAK && dont_nak)
+ newret = CONFREJ;
+ if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
+ /* we're returning this option */
+ if (newret == CONFREJ && ret == CONFNAK)
+ retp = p0;
+ ret = newret;
+ if (p != retp)
+ BCOPY(p, retp, clen);
+ retp += clen;
+ }
+
+ p += clen;
+ len -= clen;
+ }
+
+ if (ret != CONFACK) {
+ if (ret == CONFREJ && *lenp == retp - p0)
+ all_rejected[f->unit] = 1;
+ else
+ *lenp = retp - p0;
+ }
+ return ret;
+}
+
+/*
+ * Make a string name for a compression method (or 2).
+ */
+static char *
+method_name(
+ ccp_options *opt,
+ ccp_options *opt2)
+{
+ static char result[64];
+
+ if (!ANY_COMPRESS(*opt))
+ return "(none)";
+ switch (opt->method) {
+ case CI_DEFLATE:
+ case CI_DEFLATE_DRAFT:
+ if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
+ slprintf(result, sizeof(result), "Deflate%s (%d/%d)",
+ (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
+ opt->deflate_size, opt2->deflate_size);
+ else
+ slprintf(result, sizeof(result), "Deflate%s (%d)",
+ (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
+ opt->deflate_size);
+ break;
+ case CI_BSD_COMPRESS:
+ if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
+ slprintf(result, sizeof(result), "BSD-Compress (%d/%d)",
+ opt->bsd_bits, opt2->bsd_bits);
+ else
+ slprintf(result, sizeof(result), "BSD-Compress (%d)",
+ opt->bsd_bits);
+ break;
+ case CI_PREDICTOR_1:
+ return "Predictor 1";
+ case CI_PREDICTOR_2:
+ return "Predictor 2";
+ default:
+ slprintf(result, sizeof(result), "Method %d", opt->method);
+ }
+ return result;
+}
+
+/*
+ * CCP has come up - inform the kernel driver and log a message.
+ */
+static void
+ccp_up(
+ fsm *f)
+{
+ ccp_options *go = &ccp_gotoptions[f->unit];
+ ccp_options *ho = &ccp_hisoptions[f->unit];
+ char method1[64];
+
+ ccp_flags_set(f->unit, 1, 1);
+ if (ANY_COMPRESS(*go)) {
+ if (ANY_COMPRESS(*ho)) {
+ if (go->method == ho->method) {
+ notice("%s compression enabled", method_name(go, ho));
+ } else {
+ strlcpy(method1, method_name(go, NULL), sizeof(method1));
+ notice("%s / %s compression enabled",
+ method1, method_name(ho, NULL));
+ }
+ } else
+ notice("%s receive compression enabled", method_name(go, NULL));
+ } else if (ANY_COMPRESS(*ho))
+ notice("%s transmit compression enabled", method_name(ho, NULL));
+}
+
+/*
+ * CCP has gone down - inform the kernel driver.
+ */
+static void
+ccp_down(
+ fsm *f)
+{
+ if (ccp_localstate[f->unit] & RACK_PENDING)
+ UNTIMEOUT(ccp_rack_timeout, f);
+ ccp_localstate[f->unit] = 0;
+ ccp_flags_set(f->unit, 1, 0);
+}
+
+/*
+ * Print the contents of a CCP packet.
+ */
+static char *ccp_codenames[] = {
+ "ConfReq", "ConfAck", "ConfNak", "ConfRej",
+ "TermReq", "TermAck", "CodeRej",
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ "ResetReq", "ResetAck",
+};
+
+static int
+ccp_printpkt(
+ u_char *p,
+ int plen,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ u_char *p0, *optend;
+ int code, id, len;
+ int optlen;
+
+ p0 = p;
+ if (plen < HEADERLEN)
+ return 0;
+ code = p[0];
+ id = p[1];
+ len = (p[2] << 8) + p[3];
+ if (len < HEADERLEN || len > plen)
+ return 0;
+
+ if (code >= 1 && code <= sizeof(ccp_codenames) / sizeof(char *)
+ && ccp_codenames[code-1] != NULL)
+ printer(arg, " %s", ccp_codenames[code-1]);
+ else
+ printer(arg, " code=0x%x", code);
+ printer(arg, " id=0x%x", id);
+ len -= HEADERLEN;
+ p += HEADERLEN;
+
+ switch (code) {
+ case CONFREQ:
+ case CONFACK:
+ case CONFNAK:
+ case CONFREJ:
+ /* print list of possible compression methods */
+ while (len >= 2) {
+ code = p[0];
+ optlen = p[1];
+ if (optlen < 2 || optlen > len)
+ break;
+ printer(arg, " <");
+ len -= optlen;
+ optend = p + optlen;
+ switch (code) {
+ case CI_DEFLATE:
+ case CI_DEFLATE_DRAFT:
+ if (optlen >= CILEN_DEFLATE) {
+ printer(arg, "deflate%s %d",
+ (code == CI_DEFLATE_DRAFT? "(old#)": ""),
+ DEFLATE_SIZE(p[2]));
+ if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
+ printer(arg, " method %d", DEFLATE_METHOD(p[2]));
+ if (p[3] != DEFLATE_CHK_SEQUENCE)
+ printer(arg, " check %d", p[3]);
+ p += CILEN_DEFLATE;
+ }
+ break;
+ case CI_BSD_COMPRESS:
+ if (optlen >= CILEN_BSD_COMPRESS) {
+ printer(arg, "bsd v%d %d", BSD_VERSION(p[2]),
+ BSD_NBITS(p[2]));
+ p += CILEN_BSD_COMPRESS;
+ }
+ break;
+ case CI_PREDICTOR_1:
+ if (optlen >= CILEN_PREDICTOR_1) {
+ printer(arg, "predictor 1");
+ p += CILEN_PREDICTOR_1;
+ }
+ break;
+ case CI_PREDICTOR_2:
+ if (optlen >= CILEN_PREDICTOR_2) {
+ printer(arg, "predictor 2");
+ p += CILEN_PREDICTOR_2;
+ }
+ break;
+ }
+ while (p < optend)
+ printer(arg, " %.2x", *p++);
+ printer(arg, ">");
+ }
+ break;
+
+ case TERMACK:
+ case TERMREQ:
+ if (len > 0 && *p >= ' ' && *p < 0x7f) {
+ print_string(p, len, printer, arg);
+ p += len;
+ len = 0;
+ }
+ break;
+ }
+
+ /* dump out the rest of the packet in hex */
+ while (--len >= 0)
+ printer(arg, " %.2x", *p++);
+
+ return p - p0;
+}
+
+/*
+ * We have received a packet that the decompressor failed to
+ * decompress. Here we would expect to issue a reset-request, but
+ * Motorola has a patent on resetting the compressor as a result of
+ * detecting an error in the decompressed data after decompression.
+ * (See US patent 5,130,993; international patent publication number
+ * WO 91/10289; Australian patent 73296/91.)
+ *
+ * So we ask the kernel whether the error was detected after
+ * decompression; if it was, we take CCP down, thus disabling
+ * compression :-(, otherwise we issue the reset-request.
+ */
+static void
+ccp_datainput(
+ int unit,
+ u_char *pkt,
+ int len)
+{
+ fsm *f;
+
+ f = &ccp_fsm[unit];
+ if (f->state == OPENED) {
+ if (ccp_fatal_error(unit)) {
+ /*
+ * Disable compression by taking CCP down.
+ */
+ error("Lost compression sync: disabling compression");
+ ccp_close(unit, "Lost compression sync");
+ } else {
+ /*
+ * Send a reset-request to reset the peer's compressor.
+ * We don't do that if we are still waiting for an
+ * acknowledgement to a previous reset-request.
+ */
+ if (!(ccp_localstate[f->unit] & RACK_PENDING)) {
+ fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
+ TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
+ ccp_localstate[f->unit] |= RACK_PENDING;
+ } else
+ ccp_localstate[f->unit] |= RREQ_REPEAT;
+ }
+ }
+}
+
+/*
+ * Timeout waiting for reset-ack.
+ */
+static void
+ccp_rack_timeout(
+ void *arg)
+{
+ fsm *f = arg;
+
+ if (f->state == OPENED && ccp_localstate[f->unit] & RREQ_REPEAT) {
+ fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
+ TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
+ ccp_localstate[f->unit] &= ~RREQ_REPEAT;
+ } else
+ ccp_localstate[f->unit] &= ~RACK_PENDING;
+}
diff --git a/cpukit/pppd/ccp.h b/cpukit/pppd/ccp.h
new file mode 100644
index 0000000000..609d858c5e
--- /dev/null
+++ b/cpukit/pppd/ccp.h
@@ -0,0 +1,48 @@
+/*
+ * ccp.h - Definitions for PPP Compression Control Protocol.
+ *
+ * Copyright (c) 1994 The Australian National University.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation is hereby granted, provided that the above copyright
+ * notice appears in all copies. This software is provided without any
+ * warranty, express or implied. The Australian National University
+ * makes no representations about the suitability of this software for
+ * any purpose.
+ *
+ * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
+ * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+ * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
+ * OR MODIFICATIONS.
+ *
+ * $Id$
+ */
+
+typedef struct ccp_options {
+ bool bsd_compress; /* do BSD Compress? */
+ bool deflate; /* do Deflate? */
+ bool predictor_1; /* do Predictor-1? */
+ bool predictor_2; /* do Predictor-2? */
+ bool deflate_correct; /* use correct code for deflate? */
+ bool deflate_draft; /* use draft RFC code for deflate? */
+ u_short bsd_bits; /* # bits/code for BSD Compress */
+ u_short deflate_size; /* lg(window size) for Deflate */
+ short method; /* code for chosen compression method */
+} ccp_options;
+
+extern fsm ccp_fsm[];
+extern ccp_options ccp_wantoptions[];
+extern ccp_options ccp_gotoptions[];
+extern ccp_options ccp_allowoptions[];
+extern ccp_options ccp_hisoptions[];
+
+extern struct protent ccp_protent;
diff --git a/cpukit/pppd/chap.c b/cpukit/pppd/chap.c
new file mode 100644
index 0000000000..3fe766f3a5
--- /dev/null
+++ b/cpukit/pppd/chap.c
@@ -0,0 +1,858 @@
+/*
+ * chap.c - Challenge Handshake Authentication Protocol.
+ *
+ * Copyright (c) 1993 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Copyright (c) 1991 Gregory M. Christy.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Gregory M. Christy. The name of the author may not be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+/*
+ * TODO:
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h> /* drand48, srand48 */
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "pppd.h"
+#include "chap.h"
+#include "md5.h"
+#ifdef CHAPMS
+#include "chap_ms.h"
+#endif
+
+static const char rcsid[] = RCSID;
+
+/*
+ * Command-line options.
+ */
+static option_t chap_option_list[] = {
+ { "chap-restart", o_int, &chap[0].timeouttime,
+ "Set timeout for CHAP", 0, NULL, 0, 0 },
+ { "chap-max-challenge", o_int, &chap[0].max_transmits,
+ "Set max #xmits for challenge", 0, NULL, 0, 0 },
+ { "chap-interval", o_int, &chap[0].chal_interval,
+ "Set interval for rechallenge", 0, NULL, 0, 0 },
+#ifdef MSLANMAN
+ { "ms-lanman", o_bool, &ms_lanman,
+ "Use LanMan passwd when using MS-CHAP", 1, NULL, 0, 0 },
+#endif
+ { NULL, 0, NULL, NULL, 0, NULL, 0, 0 }
+};
+
+/*
+ * Protocol entry points.
+ */
+static void ChapInit(int);
+static void ChapLowerUp(int);
+static void ChapLowerDown(int);
+static void ChapInput(int, u_char *, int);
+static void ChapProtocolReject(int);
+static int ChapPrintPkt(u_char *, int,
+ void (*)(void *, char *, ...), void *);
+
+struct protent chap_protent = {
+ PPP_CHAP,
+ ChapInit,
+ ChapInput,
+ ChapProtocolReject,
+ ChapLowerUp,
+ ChapLowerDown,
+ NULL,
+ NULL,
+ ChapPrintPkt,
+ NULL,
+ 1,
+ "CHAP",
+ NULL,
+ chap_option_list,
+ NULL,
+ NULL,
+ NULL
+};
+
+chap_state chap[NUM_PPP]; /* CHAP state; one for each unit */
+
+static void ChapChallengeTimeout(void *);
+static void ChapResponseTimeout(void *);
+static void ChapReceiveChallenge(chap_state *, u_char *, int, int);
+static void ChapRechallenge(void *);
+static void ChapReceiveResponse(chap_state *, u_char *, int, int);
+static void ChapReceiveSuccess(chap_state *, u_char *, u_char, int);
+static void ChapReceiveFailure(chap_state *, u_char *, u_char, int);
+static void ChapSendStatus(chap_state *, int);
+static void ChapSendChallenge(chap_state *);
+static void ChapSendResponse(chap_state *);
+static void ChapGenChallenge(chap_state *);
+
+/*
+ * ChapInit - Initialize a CHAP unit.
+ */
+static void
+ChapInit(
+ int unit)
+{
+ chap_state *cstate = &chap[unit];
+
+ BZERO(cstate, sizeof(*cstate));
+ cstate->unit = unit;
+ cstate->clientstate = CHAPCS_INITIAL;
+ cstate->serverstate = CHAPSS_INITIAL;
+ cstate->timeouttime = CHAP_DEFTIMEOUT;
+ cstate->max_transmits = CHAP_DEFTRANSMITS;
+ /* random number generator is initialized in magic_init */
+}
+
+
+/*
+ * ChapAuthWithPeer - Authenticate us with our peer (start client).
+ *
+ */
+void
+ChapAuthWithPeer(
+ int unit,
+ char *our_name,
+ int digest)
+{
+ chap_state *cstate = &chap[unit];
+
+ cstate->resp_name = our_name;
+ cstate->resp_type = digest;
+
+ if (cstate->clientstate == CHAPCS_INITIAL ||
+ cstate->clientstate == CHAPCS_PENDING) {
+ /* lower layer isn't up - wait until later */
+ cstate->clientstate = CHAPCS_PENDING;
+ return;
+ }
+
+ /*
+ * We get here as a result of LCP coming up.
+ * So even if CHAP was open before, we will
+ * have to re-authenticate ourselves.
+ */
+ cstate->clientstate = CHAPCS_LISTEN;
+}
+
+
+/*
+ * ChapAuthPeer - Authenticate our peer (start server).
+ */
+void
+ChapAuthPeer(
+ int unit,
+ char *our_name,
+ int digest)
+{
+ chap_state *cstate = &chap[unit];
+
+ cstate->chal_name = our_name;
+ cstate->chal_type = digest;
+
+ if (cstate->serverstate == CHAPSS_INITIAL ||
+ cstate->serverstate == CHAPSS_PENDING) {
+ /* lower layer isn't up - wait until later */
+ cstate->serverstate = CHAPSS_PENDING;
+ return;
+ }
+
+ ChapGenChallenge(cstate);
+ ChapSendChallenge(cstate); /* crank it up dude! */
+ cstate->serverstate = CHAPSS_INITIAL_CHAL;
+}
+
+
+/*
+ * ChapChallengeTimeout - Timeout expired on sending challenge.
+ */
+static void
+ChapChallengeTimeout(
+ void *arg)
+{
+ chap_state *cstate = (chap_state *) arg;
+
+ /* if we aren't sending challenges, don't worry. then again we */
+ /* probably shouldn't be here either */
+ if (cstate->serverstate != CHAPSS_INITIAL_CHAL &&
+ cstate->serverstate != CHAPSS_RECHALLENGE)
+ return;
+
+ if (cstate->chal_transmits >= cstate->max_transmits) {
+ /* give up on peer */
+ error("Peer failed to respond to CHAP challenge");
+ cstate->serverstate = CHAPSS_BADAUTH;
+ auth_peer_fail(cstate->unit, PPP_CHAP);
+ return;
+ }
+
+ ChapSendChallenge(cstate); /* Re-send challenge */
+}
+
+
+/*
+ * ChapResponseTimeout - Timeout expired on sending response.
+ */
+static void
+ChapResponseTimeout(
+ void *arg)
+{
+ chap_state *cstate = (chap_state *) arg;
+
+ /* if we aren't sending a response, don't worry. */
+ if (cstate->clientstate != CHAPCS_RESPONSE)
+ return;
+
+ ChapSendResponse(cstate); /* re-send response */
+}
+
+
+/*
+ * ChapRechallenge - Time to challenge the peer again.
+ */
+static void
+ChapRechallenge(
+ void *arg)
+{
+ chap_state *cstate = (chap_state *) arg;
+
+ /* if we aren't sending a response, don't worry. */
+ if (cstate->serverstate != CHAPSS_OPEN)
+ return;
+
+ ChapGenChallenge(cstate);
+ ChapSendChallenge(cstate);
+ cstate->serverstate = CHAPSS_RECHALLENGE;
+}
+
+
+/*
+ * ChapLowerUp - The lower layer is up.
+ *
+ * Start up if we have pending requests.
+ */
+static void
+ChapLowerUp(
+ int unit)
+{
+ chap_state *cstate = &chap[unit];
+
+ if (cstate->clientstate == CHAPCS_INITIAL)
+ cstate->clientstate = CHAPCS_CLOSED;
+ else if (cstate->clientstate == CHAPCS_PENDING)
+ cstate->clientstate = CHAPCS_LISTEN;
+
+ if (cstate->serverstate == CHAPSS_INITIAL)
+ cstate->serverstate = CHAPSS_CLOSED;
+ else if (cstate->serverstate == CHAPSS_PENDING) {
+ ChapGenChallenge(cstate);
+ ChapSendChallenge(cstate);
+ cstate->serverstate = CHAPSS_INITIAL_CHAL;
+ }
+}
+
+
+/*
+ * ChapLowerDown - The lower layer is down.
+ *
+ * Cancel all timeouts.
+ */
+static void
+ChapLowerDown(
+ int unit)
+{
+ chap_state *cstate = &chap[unit];
+
+ /* Timeout(s) pending? Cancel if so. */
+ if (cstate->serverstate == CHAPSS_INITIAL_CHAL ||
+ cstate->serverstate == CHAPSS_RECHALLENGE)
+ UNTIMEOUT(ChapChallengeTimeout, cstate);
+ else if (cstate->serverstate == CHAPSS_OPEN
+ && cstate->chal_interval != 0)
+ UNTIMEOUT(ChapRechallenge, cstate);
+ if (cstate->clientstate == CHAPCS_RESPONSE)
+ UNTIMEOUT(ChapResponseTimeout, cstate);
+
+ cstate->clientstate = CHAPCS_INITIAL;
+ cstate->serverstate = CHAPSS_INITIAL;
+}
+
+
+/*
+ * ChapProtocolReject - Peer doesn't grok CHAP.
+ */
+static void
+ChapProtocolReject(
+ int unit)
+{
+ chap_state *cstate = &chap[unit];
+
+ if (cstate->serverstate != CHAPSS_INITIAL &&
+ cstate->serverstate != CHAPSS_CLOSED)
+ auth_peer_fail(unit, PPP_CHAP);
+ if (cstate->clientstate != CHAPCS_INITIAL &&
+ cstate->clientstate != CHAPCS_CLOSED)
+ auth_withpeer_fail(unit, PPP_CHAP);
+ ChapLowerDown(unit); /* shutdown chap */
+}
+
+
+/*
+ * ChapInput - Input CHAP packet.
+ */
+static void
+ChapInput(
+ int unit,
+ u_char *inpacket,
+ int packet_len)
+{
+ chap_state *cstate = &chap[unit];
+ u_char *inp;
+ u_char code, id;
+ int len;
+
+ /*
+ * Parse header (code, id and length).
+ * If packet too short, drop it.
+ */
+ inp = inpacket;
+ if (packet_len < CHAP_HEADERLEN) {
+ CHAPDEBUG(("ChapInput: rcvd short header."));
+ return;
+ }
+ GETCHAR(code, inp);
+ GETCHAR(id, inp);
+ GETSHORT(len, inp);
+ if (len < CHAP_HEADERLEN) {
+ CHAPDEBUG(("ChapInput: rcvd illegal length."));
+ return;
+ }
+ if (len > packet_len) {
+ CHAPDEBUG(("ChapInput: rcvd short packet."));
+ return;
+ }
+ len -= CHAP_HEADERLEN;
+
+ /*
+ * Action depends on code (as in fact it usually does :-).
+ */
+ switch (code) {
+ case CHAP_CHALLENGE:
+ ChapReceiveChallenge(cstate, inp, id, len);
+ break;
+
+ case CHAP_RESPONSE:
+ ChapReceiveResponse(cstate, inp, id, len);
+ break;
+
+ case CHAP_FAILURE:
+ ChapReceiveFailure(cstate, inp, id, len);
+ break;
+
+ case CHAP_SUCCESS:
+ ChapReceiveSuccess(cstate, inp, id, len);
+ break;
+
+ default: /* Need code reject? */
+ warn("Unknown CHAP code (%d) received.", code);
+ break;
+ }
+}
+
+
+/*
+ * ChapReceiveChallenge - Receive Challenge and send Response.
+ */
+static void
+ChapReceiveChallenge(
+ chap_state *cstate,
+ u_char *inp,
+ int id,
+ int len)
+{
+ int rchallenge_len;
+ u_char *rchallenge;
+ int secret_len;
+ unsigned char secret[MAXSECRETLEN];
+ char rhostname[256];
+ MD5_CTX mdContext;
+ u_char hash[MD5_SIGNATURE_SIZE];
+
+ if (cstate->clientstate == CHAPCS_CLOSED ||
+ cstate->clientstate == CHAPCS_PENDING) {
+ CHAPDEBUG(("ChapReceiveChallenge: in state %d", cstate->clientstate));
+ return;
+ }
+
+ if (len < 2) {
+ CHAPDEBUG(("ChapReceiveChallenge: rcvd short packet."));
+ return;
+ }
+
+ GETCHAR(rchallenge_len, inp);
+ len -= sizeof (u_char) + rchallenge_len; /* now name field length */
+ if (len < 0) {
+ CHAPDEBUG(("ChapReceiveChallenge: rcvd short packet."));
+ return;
+ }
+ rchallenge = inp;
+ INCPTR(rchallenge_len, inp);
+
+ if (len >= sizeof(rhostname))
+ len = sizeof(rhostname) - 1;
+ BCOPY(inp, rhostname, len);
+ rhostname[len] = '\000';
+
+ /* Microsoft doesn't send their name back in the PPP packet */
+ if (explicit_remote || (remote_name[0] != 0 && rhostname[0] == 0)) {
+ strlcpy(rhostname, remote_name, sizeof(rhostname));
+ CHAPDEBUG(("ChapReceiveChallenge: using '%q' as remote name",
+ rhostname));
+ }
+
+ /* get secret for authenticating ourselves with the specified host */
+ if (!get_secret(cstate->unit, cstate->resp_name, rhostname,
+ secret, &secret_len, 0)) {
+ secret_len = 0; /* assume null secret if can't find one */
+ warn("No CHAP secret found for authenticating us to %q", rhostname);
+ }
+
+ /* cancel response send timeout if necessary */
+ if (cstate->clientstate == CHAPCS_RESPONSE)
+ UNTIMEOUT(ChapResponseTimeout, cstate);
+
+ cstate->resp_id = id;
+ cstate->resp_transmits = 0;
+
+ /* generate MD based on negotiated type */
+ switch (cstate->resp_type) {
+
+ case CHAP_DIGEST_MD5:
+ MD5Init(&mdContext);
+ MD5Update(&mdContext, &cstate->resp_id, 1);
+ MD5Update(&mdContext, secret, secret_len);
+ MD5Update(&mdContext, rchallenge, rchallenge_len);
+ MD5Final(hash, &mdContext);
+ BCOPY(hash, cstate->response, MD5_SIGNATURE_SIZE);
+ cstate->resp_length = MD5_SIGNATURE_SIZE;
+ break;
+
+#ifdef CHAPMS
+ case CHAP_MICROSOFT:
+ ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len);
+ break;
+#endif
+
+ default:
+ CHAPDEBUG(("unknown digest type %d", cstate->resp_type));
+ return;
+ }
+
+ BZERO(secret, sizeof(secret));
+ ChapSendResponse(cstate);
+}
+
+
+/*
+ * ChapReceiveResponse - Receive and process response.
+ */
+static void
+ChapReceiveResponse(
+ chap_state *cstate,
+ u_char *inp,
+ int id,
+ int len)
+{
+ u_char *remmd, remmd_len;
+ int secret_len, old_state;
+ int code;
+ char rhostname[256];
+ MD5_CTX mdContext;
+ unsigned char secret[MAXSECRETLEN];
+ u_char hash[MD5_SIGNATURE_SIZE];
+
+ if (cstate->serverstate == CHAPSS_CLOSED ||
+ cstate->serverstate == CHAPSS_PENDING) {
+ CHAPDEBUG(("ChapReceiveResponse: in state %d", cstate->serverstate));
+ return;
+ }
+
+ if (id != cstate->chal_id)
+ return; /* doesn't match ID of last challenge */
+
+ /*
+ * If we have received a duplicate or bogus Response,
+ * we have to send the same answer (Success/Failure)
+ * as we did for the first Response we saw.
+ */
+ if (cstate->serverstate == CHAPSS_OPEN) {
+ ChapSendStatus(cstate, CHAP_SUCCESS);
+ return;
+ }
+ if (cstate->serverstate == CHAPSS_BADAUTH) {
+ ChapSendStatus(cstate, CHAP_FAILURE);
+ return;
+ }
+
+ if (len < 2) {
+ CHAPDEBUG(("ChapReceiveResponse: rcvd short packet."));
+ return;
+ }
+ GETCHAR(remmd_len, inp); /* get length of MD */
+ remmd = inp; /* get pointer to MD */
+ INCPTR(remmd_len, inp);
+
+ len -= sizeof (u_char) + remmd_len;
+ if (len < 0) {
+ CHAPDEBUG(("ChapReceiveResponse: rcvd short packet."));
+ return;
+ }
+
+ UNTIMEOUT(ChapChallengeTimeout, cstate);
+
+ if (len >= sizeof(rhostname))
+ len = sizeof(rhostname) - 1;
+ BCOPY(inp, rhostname, len);
+ rhostname[len] = '\000';
+
+ /*
+ * Get secret for authenticating them with us,
+ * do the hash ourselves, and compare the result.
+ */
+ code = CHAP_FAILURE;
+ if (!get_secret(cstate->unit, (explicit_remote? remote_name: rhostname),
+ cstate->chal_name, secret, &secret_len, 1)) {
+ warn("No CHAP secret found for authenticating %q", rhostname);
+ } else {
+
+ /* generate MD based on negotiated type */
+ switch (cstate->chal_type) {
+
+ case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
+ if (remmd_len != MD5_SIGNATURE_SIZE)
+ break; /* it's not even the right length */
+ MD5Init(&mdContext);
+ MD5Update(&mdContext, &cstate->chal_id, 1);
+ MD5Update(&mdContext, secret, secret_len);
+ MD5Update(&mdContext, cstate->challenge, cstate->chal_len);
+ MD5Final(hash, &mdContext);
+
+ /* compare local and remote MDs and send the appropriate status */
+ if (memcmp (hash, remmd, MD5_SIGNATURE_SIZE) == 0)
+ code = CHAP_SUCCESS; /* they are the same! */
+ break;
+
+ default:
+ CHAPDEBUG(("unknown digest type %d", cstate->chal_type));
+ }
+ }
+
+ BZERO(secret, sizeof(secret));
+ ChapSendStatus(cstate, code);
+
+ if (code == CHAP_SUCCESS) {
+ old_state = cstate->serverstate;
+ cstate->serverstate = CHAPSS_OPEN;
+ if (old_state == CHAPSS_INITIAL_CHAL) {
+ auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len);
+ }
+ if (cstate->chal_interval != 0)
+ TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval);
+ notice("CHAP peer authentication succeeded for %q", rhostname);
+
+ } else {
+ error("CHAP peer authentication failed for remote host %q", rhostname);
+ cstate->serverstate = CHAPSS_BADAUTH;
+ auth_peer_fail(cstate->unit, PPP_CHAP);
+ }
+}
+
+/*
+ * ChapReceiveSuccess - Receive Success
+ */
+static void
+ChapReceiveSuccess(
+ chap_state *cstate,
+ u_char *inp,
+ u_char id,
+ int len)
+{
+
+ if (cstate->clientstate == CHAPCS_OPEN)
+ /* presumably an answer to a duplicate response */
+ return;
+
+ if (cstate->clientstate != CHAPCS_RESPONSE) {
+ /* don't know what this is */
+ CHAPDEBUG(("ChapReceiveSuccess: in state %d\n", cstate->clientstate));
+ return;
+ }
+
+ UNTIMEOUT(ChapResponseTimeout, cstate);
+
+ /*
+ * Print message.
+ */
+ if (len > 0)
+ PRINTMSG(inp, len);
+
+ cstate->clientstate = CHAPCS_OPEN;
+
+ auth_withpeer_success(cstate->unit, PPP_CHAP);
+}
+
+
+/*
+ * ChapReceiveFailure - Receive failure.
+ */
+static void
+ChapReceiveFailure(
+ chap_state *cstate,
+ u_char *inp,
+ u_char id,
+ int len)
+{
+ if (cstate->clientstate != CHAPCS_RESPONSE) {
+ /* don't know what this is */
+ CHAPDEBUG(("ChapReceiveFailure: in state %d\n", cstate->clientstate));
+ return;
+ }
+
+ UNTIMEOUT(ChapResponseTimeout, cstate);
+
+ /*
+ * Print message.
+ */
+ if (len > 0)
+ PRINTMSG(inp, len);
+
+ error("CHAP authentication failed");
+ auth_withpeer_fail(cstate->unit, PPP_CHAP);
+}
+
+
+/*
+ * ChapSendChallenge - Send an Authenticate challenge.
+ */
+static void
+ChapSendChallenge(
+ chap_state *cstate)
+{
+ u_char *outp;
+ int chal_len, name_len;
+ int outlen;
+
+ chal_len = cstate->chal_len;
+ name_len = strlen(cstate->chal_name);
+ outlen = CHAP_HEADERLEN + sizeof (u_char) + chal_len + name_len;
+ outp = outpacket_buf;
+
+ MAKEHEADER(outp, PPP_CHAP); /* paste in a CHAP header */
+
+ PUTCHAR(CHAP_CHALLENGE, outp);
+ PUTCHAR(cstate->chal_id, outp);
+ PUTSHORT(outlen, outp);
+
+ PUTCHAR(chal_len, outp); /* put length of challenge */
+ BCOPY(cstate->challenge, outp, chal_len);
+ INCPTR(chal_len, outp);
+
+ BCOPY(cstate->chal_name, outp, name_len); /* append hostname */
+
+ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
+
+ TIMEOUT(ChapChallengeTimeout, cstate, cstate->timeouttime);
+ ++cstate->chal_transmits;
+}
+
+
+/*
+ * ChapSendStatus - Send a status response (ack or nak).
+ */
+static void
+ChapSendStatus(
+ chap_state *cstate,
+ int code)
+{
+ u_char *outp;
+ int outlen, msglen;
+ char msg[256];
+
+ if (code == CHAP_SUCCESS)
+ slprintf(msg, sizeof(msg), "Welcome to %s.", hostname);
+ else
+ slprintf(msg, sizeof(msg), "I don't like you. Go 'way.");
+ msglen = strlen(msg);
+
+ outlen = CHAP_HEADERLEN + msglen;
+ outp = outpacket_buf;
+
+ MAKEHEADER(outp, PPP_CHAP); /* paste in a header */
+
+ PUTCHAR(code, outp);
+ PUTCHAR(cstate->chal_id, outp);
+ PUTSHORT(outlen, outp);
+ BCOPY(msg, outp, msglen);
+ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
+}
+
+/*
+ * ChapGenChallenge is used to generate a pseudo-random challenge string of
+ * a pseudo-random length between min_len and max_len. The challenge
+ * string and its length are stored in *cstate, and various other fields of
+ * *cstate are initialized.
+ */
+
+static void
+ChapGenChallenge(
+ chap_state *cstate)
+{
+ int chal_len;
+ u_char *ptr = cstate->challenge;
+ int i;
+
+ /* pick a random challenge length between MIN_CHALLENGE_LENGTH and
+ MAX_CHALLENGE_LENGTH */
+ chal_len = (unsigned) ((drand48() *
+ (MAX_CHALLENGE_LENGTH - MIN_CHALLENGE_LENGTH)) +
+ MIN_CHALLENGE_LENGTH);
+ cstate->chal_len = chal_len;
+ cstate->chal_id = ++cstate->id;
+ cstate->chal_transmits = 0;
+
+ /* generate a random string */
+ for (i = 0; i < chal_len; i++)
+ *ptr++ = (char) (drand48() * 0xff);
+}
+
+/*
+ * ChapSendResponse - send a response packet with values as specified
+ * in *cstate.
+ */
+/* ARGSUSED */
+static void
+ChapSendResponse(
+ chap_state *cstate)
+{
+ u_char *outp;
+ int outlen, md_len, name_len;
+
+ md_len = cstate->resp_length;
+ name_len = strlen(cstate->resp_name);
+ outlen = CHAP_HEADERLEN + sizeof (u_char) + md_len + name_len;
+ outp = outpacket_buf;
+
+ MAKEHEADER(outp, PPP_CHAP);
+
+ PUTCHAR(CHAP_RESPONSE, outp); /* we are a response */
+ PUTCHAR(cstate->resp_id, outp); /* copy id from challenge packet */
+ PUTSHORT(outlen, outp); /* packet length */
+
+ PUTCHAR(md_len, outp); /* length of MD */
+ BCOPY(cstate->response, outp, md_len); /* copy MD to buffer */
+ INCPTR(md_len, outp);
+
+ BCOPY(cstate->resp_name, outp, name_len); /* append our name */
+
+ /* send the packet */
+ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
+
+ cstate->clientstate = CHAPCS_RESPONSE;
+ TIMEOUT(ChapResponseTimeout, cstate, cstate->timeouttime);
+ ++cstate->resp_transmits;
+}
+
+/*
+ * ChapPrintPkt - print the contents of a CHAP packet.
+ */
+static char *ChapCodenames[] = {
+ "Challenge", "Response", "Success", "Failure"
+};
+
+static int
+ChapPrintPkt(
+ u_char *p,
+ int plen,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ int code, id, len;
+ int clen, nlen;
+ u_char x;
+
+ if (plen < CHAP_HEADERLEN)
+ return 0;
+ GETCHAR(code, p);
+ GETCHAR(id, p);
+ GETSHORT(len, p);
+ if (len < CHAP_HEADERLEN || len > plen)
+ return 0;
+
+ if (code >= 1 && code <= sizeof(ChapCodenames) / sizeof(char *))
+ printer(arg, " %s", ChapCodenames[code-1]);
+ else
+ printer(arg, " code=0x%x", code);
+ printer(arg, " id=0x%x", id);
+ len -= CHAP_HEADERLEN;
+ switch (code) {
+ case CHAP_CHALLENGE:
+ case CHAP_RESPONSE:
+ if (len < 1)
+ break;
+ clen = p[0];
+ if (len < clen + 1)
+ break;
+ ++p;
+ nlen = len - clen - 1;
+ printer(arg, " <");
+ for (; clen > 0; --clen) {
+ GETCHAR(x, p);
+ printer(arg, "%.2x", x);
+ }
+ printer(arg, ">, name = ");
+ print_string((char *)p, nlen, printer, arg);
+ break;
+ case CHAP_FAILURE:
+ case CHAP_SUCCESS:
+ printer(arg, " ");
+ print_string((char *)p, len, printer, arg);
+ break;
+ default:
+ for (clen = len; clen > 0; --clen) {
+ GETCHAR(x, p);
+ printer(arg, " %.2x", x);
+ }
+ }
+
+ return len + CHAP_HEADERLEN;
+}
diff --git a/cpukit/pppd/chap.h b/cpukit/pppd/chap.h
new file mode 100644
index 0000000000..78833554fe
--- /dev/null
+++ b/cpukit/pppd/chap.h
@@ -0,0 +1,124 @@
+/*
+ * chap.h - Challenge Handshake Authentication Protocol definitions.
+ *
+ * Copyright (c) 1993 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Copyright (c) 1991 Gregory M. Christy
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the author.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+#ifndef __CHAP_INCLUDE__
+
+/* Code + ID + length */
+#define CHAP_HEADERLEN 4
+
+/*
+ * CHAP codes.
+ */
+
+#define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
+#define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
+#define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
+#define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
+
+#define CHAP_CHALLENGE 1
+#define CHAP_RESPONSE 2
+#define CHAP_SUCCESS 3
+#define CHAP_FAILURE 4
+
+/*
+ * Challenge lengths (for challenges we send) and other limits.
+ */
+#define MIN_CHALLENGE_LENGTH 16
+#define MAX_CHALLENGE_LENGTH 24
+#define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
+
+/*
+ * Each interface is described by a chap structure.
+ */
+
+typedef struct chap_state {
+ int unit; /* Interface unit number */
+ int clientstate; /* Client state */
+ int serverstate; /* Server state */
+ u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
+ u_char chal_len; /* challenge length */
+ u_char chal_id; /* ID of last challenge */
+ u_char chal_type; /* hash algorithm for challenges */
+ u_char id; /* Current id */
+ char *chal_name; /* Our name to use with challenge */
+ int chal_interval; /* Time until we challenge peer again */
+ int timeouttime; /* Timeout time in seconds */
+ int max_transmits; /* Maximum # of challenge transmissions */
+ int chal_transmits; /* Number of transmissions of challenge */
+ int resp_transmits; /* Number of transmissions of response */
+ u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
+ u_char resp_length; /* length of response */
+ u_char resp_id; /* ID for response messages */
+ u_char resp_type; /* hash algorithm for responses */
+ char *resp_name; /* Our name to send with response */
+} chap_state;
+
+
+/*
+ * Client (peer) states.
+ */
+#define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
+#define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
+#define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
+#define CHAPCS_LISTEN 3 /* Listening for a challenge */
+#define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
+#define CHAPCS_OPEN 5 /* We've received Success */
+
+/*
+ * Server (authenticator) states.
+ */
+#define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
+#define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
+#define CHAPSS_PENDING 2 /* Auth peer when lower up */
+#define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
+#define CHAPSS_OPEN 4 /* We've sent a Success msg */
+#define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
+#define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
+
+/*
+ * Timeouts.
+ */
+#define CHAP_DEFTIMEOUT 5 /* Timeout time in seconds */
+#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
+
+extern chap_state chap[];
+
+void ChapAuthWithPeer(int, char *, int);
+void ChapAuthPeer(int, char *, int);
+
+extern struct protent chap_protent;
+
+#define __CHAP_INCLUDE__
+#endif /* __CHAP_INCLUDE__ */
diff --git a/cpukit/pppd/chap_ms.c b/cpukit/pppd/chap_ms.c
new file mode 100644
index 0000000000..3ccf83ad8d
--- /dev/null
+++ b/cpukit/pppd/chap_ms.c
@@ -0,0 +1,338 @@
+/*
+ * chap_ms.c - Microsoft MS-CHAP compatible implementation.
+ *
+ * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
+ * http://www.strataware.com/
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Eric Rosenquist. The name of the author may not be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+ * Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997
+ *
+ * Implemented LANManager type password response to MS-CHAP challenges.
+ * Now pppd provides both NT style and LANMan style blocks, and the
+ * prefered is set by option "ms-lanman". Default is to use NT.
+ * The hash text (StdText) was taken from Win95 RASAPI32.DLL.
+ *
+ * You should also use DOMAIN\\USERNAME as described in README.MSCHAP80
+ */
+
+#define RCSID "$Id$"
+
+#ifdef CHAPMS
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+#ifdef HAVE_CRYPT_H
+#include <crypt.h>
+#endif
+
+#include "pppd.h"
+#include "chap.h"
+#include "chap_ms.h"
+#include "md4.h"
+
+#ifndef USE_CRYPT
+#include <des.h>
+#endif
+
+static const char rcsid[] = RCSID;
+
+typedef struct {
+ u_char LANManResp[24];
+ u_char NTResp[24];
+ u_char UseNT; /* If 1, ignore the LANMan response field */
+} MS_ChapResponse;
+/* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
+ in case this struct gets padded. */
+
+
+static void ChallengeResponse(u_char *, u_char *, u_char *);
+static void DesEncrypt(u_char *, u_char *, u_char *);
+static void MakeKey(u_char *, u_char *);
+static u_char Get7Bits(u_char *, int);
+static void ChapMS_NT(char *, int, char *, int, MS_ChapResponse *);
+#ifdef MSLANMAN
+static void ChapMS_LANMan(char *, int, char *, int, MS_ChapResponse *);
+#endif
+
+#ifdef USE_CRYPT
+static void Expand(u_char *, u_char *);
+static void Collapse(u_char *, u_char *);
+#endif
+
+#ifdef MSLANMAN
+bool ms_lanman = 0; /* Use LanMan password instead of NT */
+ /* Has meaning only with MS-CHAP challenges */
+#endif
+
+static void
+ChallengeResponse(challenge, pwHash, response)
+ u_char *challenge; /* IN 8 octets */
+ u_char *pwHash; /* IN 16 octets */
+ u_char *response; /* OUT 24 octets */
+{
+ char ZPasswordHash[21];
+
+ BZERO(ZPasswordHash, sizeof(ZPasswordHash));
+ BCOPY(pwHash, ZPasswordHash, MD4_SIGNATURE_SIZE);
+
+#if 0
+ dbglog("ChallengeResponse - ZPasswordHash %.*B",
+ sizeof(ZPasswordHash), ZPasswordHash);
+#endif
+
+ DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
+ DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
+ DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
+
+#if 0
+ dbglog("ChallengeResponse - response %.24B", response);
+#endif
+}
+
+
+#ifdef USE_CRYPT
+static void
+DesEncrypt(clear, key, cipher)
+ u_char *clear; /* IN 8 octets */
+ u_char *key; /* IN 7 octets */
+ u_char *cipher; /* OUT 8 octets */
+{
+ u_char des_key[8];
+ u_char crypt_key[66];
+ u_char des_input[66];
+
+ MakeKey(key, des_key);
+
+ Expand(des_key, crypt_key);
+ setkey(crypt_key);
+
+#if 0
+ CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %.8B", clear));
+#endif
+
+ Expand(clear, des_input);
+ encrypt(des_input, 0);
+ Collapse(des_input, cipher);
+
+#if 0
+ CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %.8B", cipher));
+#endif
+}
+
+#else /* USE_CRYPT */
+
+static void
+DesEncrypt(clear, key, cipher)
+ u_char *clear; /* IN 8 octets */
+ u_char *key; /* IN 7 octets */
+ u_char *cipher; /* OUT 8 octets */
+{
+ des_cblock des_key;
+ des_key_schedule key_schedule;
+
+ MakeKey(key, des_key);
+
+ des_set_key(&des_key, key_schedule);
+
+#if 0
+ CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %.8B", clear));
+#endif
+
+ des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
+
+#if 0
+ CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %.8B", cipher));
+#endif
+}
+
+#endif /* USE_CRYPT */
+
+
+static u_char Get7Bits(input, startBit)
+ u_char *input;
+ int startBit;
+{
+ register unsigned int word;
+
+ word = (unsigned)input[startBit / 8] << 8;
+ word |= (unsigned)input[startBit / 8 + 1];
+
+ word >>= 15 - (startBit % 8 + 7);
+
+ return word & 0xFE;
+}
+
+#ifdef USE_CRYPT
+
+/* in == 8-byte string (expanded version of the 56-bit key)
+ * out == 64-byte string where each byte is either 1 or 0
+ * Note that the low-order "bit" is always ignored by by setkey()
+ */
+static void Expand(in, out)
+ u_char *in;
+ u_char *out;
+{
+ int j, c;
+ int i;
+
+ for(i = 0; i < 64; in++){
+ c = *in;
+ for(j = 7; j >= 0; j--)
+ *out++ = (c >> j) & 01;
+ i += 8;
+ }
+}
+
+/* The inverse of Expand
+ */
+static void Collapse(in, out)
+ u_char *in;
+ u_char *out;
+{
+ int j;
+ int i;
+ unsigned int c;
+
+ for (i = 0; i < 64; i += 8, out++) {
+ c = 0;
+ for (j = 7; j >= 0; j--, in++)
+ c |= *in << j;
+ *out = c & 0xff;
+ }
+}
+#endif
+
+static void MakeKey(key, des_key)
+ u_char *key; /* IN 56 bit DES key missing parity bits */
+ u_char *des_key; /* OUT 64 bit DES key with parity bits added */
+{
+ des_key[0] = Get7Bits(key, 0);
+ des_key[1] = Get7Bits(key, 7);
+ des_key[2] = Get7Bits(key, 14);
+ des_key[3] = Get7Bits(key, 21);
+ des_key[4] = Get7Bits(key, 28);
+ des_key[5] = Get7Bits(key, 35);
+ des_key[6] = Get7Bits(key, 42);
+ des_key[7] = Get7Bits(key, 49);
+
+#ifndef USE_CRYPT
+ des_set_odd_parity((des_cblock *)des_key);
+#endif
+
+#if 0
+ CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %.7B", key));
+ CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %.8B", des_key));
+#endif
+}
+
+static void
+ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, response)
+ char *rchallenge;
+ int rchallenge_len;
+ char *secret;
+ int secret_len;
+ MS_ChapResponse *response;
+{
+ int i;
+#ifdef __NetBSD__
+ /* NetBSD uses the libc md4 routines which take bytes instead of bits */
+ int mdlen = secret_len * 2;
+#else
+ int mdlen = secret_len * 2 * 8;
+#endif
+ MD4_CTX md4Context;
+ u_char hash[MD4_SIGNATURE_SIZE];
+ u_char unicodePassword[MAX_NT_PASSWORD * 2];
+
+ /* Initialize the Unicode version of the secret (== password). */
+ /* This implicitly supports 8-bit ISO8859/1 characters. */
+ BZERO(unicodePassword, sizeof(unicodePassword));
+ for (i = 0; i < secret_len; i++)
+ unicodePassword[i * 2] = (u_char)secret[i];
+
+ MD4Init(&md4Context);
+ MD4Update(&md4Context, unicodePassword, mdlen);
+
+ MD4Final(hash, &md4Context); /* Tell MD4 we're done */
+
+ ChallengeResponse(rchallenge, hash, response->NTResp);
+}
+
+#ifdef MSLANMAN
+static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
+
+static void
+ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, response)
+ char *rchallenge;
+ int rchallenge_len;
+ char *secret;
+ int secret_len;
+ MS_ChapResponse *response;
+{
+ int i;
+ u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
+ u_char PasswordHash[MD4_SIGNATURE_SIZE];
+
+ /* LANMan password is case insensitive */
+ BZERO(UcasePassword, sizeof(UcasePassword));
+ for (i = 0; i < secret_len; i++)
+ UcasePassword[i] = (u_char)toupper(secret[i]);
+ DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
+ DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
+ ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
+}
+#endif
+
+void
+ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len)
+ chap_state *cstate;
+ char *rchallenge;
+ int rchallenge_len;
+ char *secret;
+ int secret_len;
+{
+ MS_ChapResponse response;
+
+#if 0
+ CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'", secret_len, secret));
+#endif
+ BZERO(&response, sizeof(response));
+
+ /* Calculate both always */
+ ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
+
+#ifdef MSLANMAN
+ ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
+
+ /* prefered method is set by option */
+ response.UseNT = !ms_lanman;
+#else
+ response.UseNT = 1;
+#endif
+
+ BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
+ cstate->resp_length = MS_CHAP_RESPONSE_LEN;
+}
+
+#endif /* CHAPMS */
diff --git a/cpukit/pppd/chap_ms.h b/cpukit/pppd/chap_ms.h
new file mode 100644
index 0000000000..5776251210
--- /dev/null
+++ b/cpukit/pppd/chap_ms.h
@@ -0,0 +1,33 @@
+/*
+ * chap.h - Challenge Handshake Authentication Protocol definitions.
+ *
+ * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
+ * http://www.strataware.com/
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Eric Rosenquist. The name of the author may not be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+#ifndef __CHAPMS_INCLUDE__
+
+#define MD4_SIGNATURE_SIZE 16 /* 16 bytes in a MD4 message digest */
+#define MAX_NT_PASSWORD 256 /* Maximum number of (Unicode) chars in an NT password */
+
+void ChapMS(chap_state *, char *, int, char *, int);
+
+#define __CHAPMS_INCLUDE__
+#endif /* __CHAPMS_INCLUDE__ */
diff --git a/cpukit/pppd/chat.c b/cpukit/pppd/chat.c
new file mode 100644
index 0000000000..45e2707158
--- /dev/null
+++ b/cpukit/pppd/chat.c
@@ -0,0 +1,854 @@
+/*
+ * Chat -- a program for automatic session establishment (i.e. dial
+ * the phone and log in).
+ *
+ * Standard termination codes:
+ * 0 - successful completion of the script
+ * 1 - invalid argument, expect string too large, etc.
+ * 2 - error on an I/O operation or fatal error condition.
+ * 3 - timeout waiting for a simple string.
+ * 4 - the first string declared as "ABORT"
+ * 5 - the second string declared as "ABORT"
+ * 6 - ... and so on for successive ABORT strings.
+ *
+ * This software is in the public domain.
+ *
+ * -----------------
+ * 22-May-99 added environment substitutuion, enabled with -E switch.
+ * Andreas Arens <andras@cityweb.de>.
+ *
+ * 12-May-99 added a feature to read data to be sent from a file,
+ * if the send string starts with @. Idea from gpk <gpk@onramp.net>.
+ *
+ * added -T and -U option and \T and \U substitution to pass a phone
+ * number into chat script. Two are needed for some ISDN TA applications.
+ * Keith Dart <kdart@cisco.com>
+ *
+ *
+ * Added SAY keyword to send output to stderr.
+ * This allows to turn ECHO OFF and to output specific, user selected,
+ * text to give progress messages. This best works when stderr
+ * exists (i.e.: pppd in nodetach mode).
+ *
+ * Added HANGUP directives to allow for us to be called
+ * back. When HANGUP is set to NO, chat will not hangup at HUP signal.
+ * We rely on timeouts in that case.
+ *
+ * Added CLR_ABORT to clear previously set ABORT string. This has been
+ * dictated by the HANGUP above as "NO CARRIER" (for example) must be
+ * an ABORT condition until we know the other host is going to close
+ * the connection for call back. As soon as we have completed the
+ * first stage of the call back sequence, "NO CARRIER" is a valid, non
+ * fatal string. As soon as we got called back (probably get "CONNECT"),
+ * we should re-arm the ABORT "NO CARRIER". Hence the CLR_ABORT command.
+ * Note that CLR_ABORT packs the abort_strings[] array so that we do not
+ * have unused entries not being reclaimed.
+ *
+ * In the same vein as above, added CLR_REPORT keyword.
+ *
+ * Allow for comments. Line starting with '#' are comments and are
+ * ignored. If a '#' is to be expected as the first character, the
+ * expect string must be quoted.
+ *
+ *
+ * Francis Demierre <Francis@SwissMail.Com>
+ * Thu May 15 17:15:40 MET DST 1997
+ *
+ *
+ * Added -r "report file" switch & REPORT keyword.
+ * Robert Geer <bgeer@xmission.com>
+ *
+ * Added -s "use stderr" and -S "don't use syslog" switches.
+ * June 18, 1997
+ * Karl O. Pinc <kop@meme.com>
+ *
+ *
+ * Added -e "echo" switch & ECHO keyword
+ * Dick Streefland <dicks@tasking.nl>
+ *
+ *
+ * Considerable updates and modifications by
+ * Al Longyear <longyear@pobox.com>
+ * Paul Mackerras <paulus@cs.anu.edu.au>
+ *
+ *
+ * The original author is:
+ *
+ * Karl Fox <karl@MorningStar.Com>
+ * Morning Star Technologies, Inc.
+ * 1760 Zollinger Road
+ * Columbus, OH 43221
+ * (614)451-1883
+ *
+ */
+
+/* $Id$ */
+
+/*
+ Fixes and some Changes by Wilfried Busalski Lancier-Monitoring GmbH Germany
+ wilfried.busalski@muenster.de
+
+ Fixes: put_string() Free memory allocated by clean()
+ get_string() Free memory allocated by clean()
+ chat_main() Will Distroy's no more the chat-script
+ getnextcommand() sepatator changed to '@'
+*/
+
+#include <stdio.h>
+#include <ctype.h>
+#include <time.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <syslog.h>
+#include <termios.h>
+#include "pppd.h"
+
+#undef TERMIOS
+#define TERMIOS
+
+
+#define STR_LEN 1024
+char temp2[STR_LEN];
+
+#ifndef SIGTYPE
+#define SIGTYPE void
+#endif
+
+#undef __V
+
+#ifdef __STDC__
+#include <stdarg.h>
+#define __V(x) x
+#else
+#include <varargs.h>
+#define __V(x) (va_alist) va_dcl
+#define const
+#endif
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+
+
+/*************** Micro getopt() *********************************************/
+#define OPTION(c,v) (_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \
+ (--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\
+ &&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0))
+#define OPTARG(c,v) (_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \
+ (_O=4,(char*)0):(char*)0)
+#define OPTONLYARG(c,v) (_O&2&&**v?(_O=1,--c,*v++):(char*)0)
+#define ARG(c,v) (c?(--c,*v++):(char*)0)
+
+#if 0
+static int _O = 0; /* Internal state */
+#endif
+/*************** Micro getopt() *********************************************/
+
+#define MAX_ABORTS 16
+#define MAX_REPORTS 16
+#define DEFAULT_CHAT_TIMEOUT 45
+#define MAX_TIMEOUTS 10
+
+static int echo = 0;
+static int quiet = 0;
+static int use_env = 0;
+static int exit_code = 0;
+static char *phone_num = (char *) 0;
+static char *phone_num2 = (char *) 0;
+static int ttyfd;
+static int timeout = DEFAULT_CHAT_TIMEOUT;
+
+#ifdef TERMIOS
+#define term_parms struct termios
+#define get_term_param(param) tcgetattr(0, param)
+#define set_term_param(param) tcsetattr(0, TCSANOW, param)
+struct termios saved_tty_parameters;
+#endif
+
+char *fail_reason = (char *)0;
+char fail_buffer[50];
+char *abort_string[MAX_ABORTS]={"BUSY","NO DIALTONE","NO CARRIER","NO ANSWER","RING\r\nRING"};
+int n_aborts = 5;
+int abort_next = 0, timeout_next = 0, echo_next = 0;
+int clear_abort_next = 0;
+
+char *report_string[MAX_REPORTS] ;
+char report_buffer[50] ;
+int n_reports = 0, report_next = 0, report_gathering = 0 ;
+int clear_report_next = 0;
+
+int say_next = 0, hup_next = 0;
+
+void *dup_mem(void *b, size_t c);
+void *copy_of(char *s);
+void break_sequence(void);
+static int get_string(register char *string);
+static int put_string(register char *s);
+static int write_char(int c);
+static int put_char(int c);
+static int get_char(void);
+void chat_send(register char *s);
+/* static char *character(int c); */
+void chat_expect(register char *s);
+static char *clean(register char *s, int sending);
+char *expect_strtok(char *, char *);
+int chatmain(int, int, char *);
+
+
+void *dup_mem(
+ void *b,
+ size_t c)
+{
+ void *ans = malloc (c);
+ if (!ans)
+ return NULL;
+
+ memcpy(ans, b, c);
+ return ans;
+}
+
+void *copy_of(
+ char *s)
+{
+ return dup_mem(s, strlen (s) + 1);
+}
+
+char *getnextcommand(char *string,char *buff)
+{
+ char *token;
+ int len;
+
+ token=strchr(string,'@');
+ if (token==NULL){
+ return NULL;
+ }
+ len=token-string;
+ if(len > 78 ){
+ len=78;
+ }
+ memcpy(buff,string,len);
+ buff[len]=0;
+ return(token+1);
+}
+
+int chatmain(int fd, int mode, char *pScript)
+{
+ char arg[80];
+ char *script;
+
+ /* initialize exit code */
+ exit_code = 0;
+ ttyfd = fd;
+
+ script=pScript;
+
+ if ( debug ) {
+ dbglog("chat_main: %s\n", script);
+ }
+
+ /* get first expect string */
+ script = getnextcommand(script,arg);
+ while (( script != NULL ) && ( exit_code == 0 )) {
+ /* process the expect string */
+ chat_expect(arg);
+ if ( exit_code == 0 ) {
+ /* get the next send string */
+ script = getnextcommand(script,arg);
+ if ( script != NULL ) {
+ /* process the send string */
+ chat_send(arg);
+
+ /* get the next expect string */
+ script = getnextcommand(script,arg);
+ }
+ }
+ }
+ ttyfd = (int)-1;
+
+ return ( exit_code );
+}
+
+void break_sequence(void)
+{
+ tcsendbreak(ttyfd, 0);
+}
+
+/*
+ * 'Clean up' this string.
+ */
+static char *clean(
+ char *s,
+ int sending ) /* set to 1 when sending (putting) this string. */
+{
+ char temp[STR_LEN], env_str[STR_LEN], cur_chr;
+ register char *s1, *phchar;
+ int add_return = sending;
+#define isoctal(chr) (((chr) >= '0') && ((chr) <= '7'))
+#define isalnumx(chr) ((((chr) >= '0') && ((chr) <= '9')) \
+ || (((chr) >= 'a') && ((chr) <= 'z')) \
+ || (((chr) >= 'A') && ((chr) <= 'Z')) \
+ || (chr) == '_')
+
+ s1 = temp;
+ while (*s) {
+ cur_chr = *s++;
+ if (cur_chr == '^') {
+ cur_chr = *s++;
+ if (cur_chr == '\0') {
+ *s1++ = '^';
+ break;
+ }
+ cur_chr &= 0x1F;
+ if (cur_chr != 0) {
+ *s1++ = cur_chr;
+ }
+ continue;
+ }
+
+ if (use_env && cur_chr == '$') { /* ARI */
+ phchar = env_str;
+ while (isalnumx(*s))
+ *phchar++ = *s++;
+ *phchar = '\0';
+ phchar = getenv(env_str);
+ if (phchar)
+ while (*phchar)
+ *s1++ = *phchar++;
+ continue;
+ }
+
+ if (cur_chr != '\\') {
+ *s1++ = cur_chr;
+ continue;
+ }
+
+ cur_chr = *s++;
+ if (cur_chr == '\0') {
+ if (sending) {
+ *s1++ = '\\';
+ *s1++ = '\\';
+ }
+ break;
+ }
+
+ switch (cur_chr) {
+ case 'b':
+ *s1++ = '\b';
+ break;
+
+ case 'c':
+ if (sending && *s == '\0')
+ add_return = 0;
+ else
+ *s1++ = cur_chr;
+ break;
+
+ case '\\':
+ case 'K':
+ case 'p':
+ case 'd':
+ if (sending)
+ *s1++ = '\\';
+ *s1++ = cur_chr;
+ break;
+
+ case 'T':
+ if (sending && phone_num) {
+ for (phchar = phone_num; *phchar != '\0'; phchar++)
+ *s1++ = *phchar;
+ }
+ else {
+ *s1++ = '\\';
+ *s1++ = 'T';
+ }
+ break;
+
+ case 'U':
+ if (sending && phone_num2) {
+ for (phchar = phone_num2; *phchar != '\0'; phchar++)
+ *s1++ = *phchar;
+ }
+ else {
+ *s1++ = '\\';
+ *s1++ = 'U';
+ }
+ break;
+
+ case 'q':
+ quiet = 1;
+ break;
+
+ case 'r':
+ *s1++ = '\r';
+ break;
+
+ case 'n':
+ *s1++ = '\n';
+ break;
+
+ case 's':
+ *s1++ = ' ';
+ break;
+
+ case 't':
+ *s1++ = '\t';
+ break;
+
+ case 'N':
+ if (sending) {
+ *s1++ = '\\';
+ *s1++ = '\0';
+ }
+ else
+ *s1++ = 'N';
+ break;
+
+ case '$': /* ARI */
+ if (use_env) {
+ *s1++ = cur_chr;
+ break;
+ }
+ /* FALL THROUGH */
+
+ default:
+ if (isoctal (cur_chr)) {
+ cur_chr &= 0x07;
+ if (isoctal (*s)) {
+ cur_chr <<= 3;
+ cur_chr |= *s++ - '0';
+ if (isoctal (*s)) {
+ cur_chr <<= 3;
+ cur_chr |= *s++ - '0';
+ }
+ }
+
+ if (cur_chr != 0 || sending) {
+ if (sending && (cur_chr == '\\' || cur_chr == 0))
+ *s1++ = '\\';
+ *s1++ = cur_chr;
+ }
+ break;
+ }
+
+ if (sending)
+ *s1++ = '\\';
+ *s1++ = cur_chr;
+ break;
+ }
+ }
+
+ if (add_return)
+ *s1++ = '\r';
+
+ *s1++ = '\0'; /* guarantee closure */
+ *s1++ = '\0'; /* terminate the string */
+ return dup_mem (temp, (size_t) (s1 - temp)); /* may have embedded nuls */
+}
+
+/*
+ * A modified version of 'strtok'. This version skips \ sequences.
+ */
+char *expect_strtok (
+ char *s, char *term)
+{
+ static char *str = "";
+ int escape_flag = 0;
+ char *result;
+
+/*
+ * If a string was specified then do initial processing.
+ */
+ if (s)
+ str = s;
+
+/*
+ * If this is the escape flag then reset it and ignore the character.
+ */
+ if (*str)
+ result = str;
+ else
+ result = (char *) 0;
+
+ while (*str) {
+ if (escape_flag) {
+ escape_flag = 0;
+ ++str;
+ continue;
+ }
+
+ if (*str == '\\') {
+ ++str;
+ escape_flag = 1;
+ continue;
+ }
+
+/*
+ * If this is not in the termination string, continue.
+ */
+ if (strchr (term, *str) == (char *) 0) {
+ ++str;
+ continue;
+ }
+
+/*
+ * This is the terminator. Mark the end of the string and stop.
+ */
+ *str++ = '\0';
+ break;
+ }
+ return (result);
+}
+
+/*
+ * Process the expect string
+ */
+void chat_expect (
+ char *s)
+{
+ char *expect;
+ char *reply;
+
+ if (strcmp(s, "HANGUP") == 0) {
+ ++hup_next;
+ return;
+ }
+
+ if (strcmp(s, "ABORT") == 0) {
+ ++abort_next;
+ return;
+ }
+
+ if (strcmp(s, "CLR_ABORT") == 0) {
+ ++clear_abort_next;
+ return;
+ }
+
+ if (strcmp(s, "REPORT") == 0) {
+ ++report_next;
+ return;
+ }
+
+ if (strcmp(s, "CLR_REPORT") == 0) {
+ ++clear_report_next;
+ return;
+ }
+
+ if (strcmp(s, "TIMEOUT") == 0) {
+ ++timeout_next;
+ return;
+ }
+
+ if (strcmp(s, "ECHO") == 0) {
+ ++echo_next;
+ return;
+ }
+
+ if (strcmp(s, "SAY") == 0) {
+ ++say_next;
+ return;
+ }
+
+/*
+ * Fetch the expect and reply string.
+ */
+ for (;;) {
+ expect = expect_strtok (s, "-");
+ s = (char *) 0;
+
+ if (expect == (char *) 0)
+ return;
+
+ reply = expect_strtok (s, "-");
+
+/*
+ * Handle the expect string. If successful then exit.
+ */
+ if (get_string (expect))
+ return;
+
+/*
+ * If there is a sub-reply string then send it. Otherwise any condition
+ * is terminal.
+ */
+ if (reply == (char *) 0 || exit_code != 3)
+ break;
+
+ chat_send (reply);
+ }
+}
+
+#if 0
+/*
+ * Translate the input character to the appropriate string for printing
+ * the data.
+ */
+
+static char *character(
+ int c)
+{
+ static char string[10];
+ char *meta;
+
+ meta = (c & 0x80) ? "M-" : "";
+ c &= 0x7F;
+
+ if (c < 32)
+ sprintf(string, "%s^%c", meta, (int)c + '@');
+ else if (c == 127)
+ sprintf(string, "%s^?", meta);
+ else
+ sprintf(string, "%s%c", meta, c);
+
+ return (string);
+}
+#endif
+
+/*
+ * process the reply string
+ */
+void chat_send (
+ char *s)
+{
+/* char file_data[STR_LEN]; */
+
+ if (say_next) {
+ say_next = 0;
+ s = clean(s, 1);
+ write(2, s, strlen(s));
+ free(s);
+ return;
+ }
+
+ if (hup_next) {
+ hup_next = 0;
+ return;
+ }
+
+ if (echo_next) {
+ echo_next = 0;
+ echo = (strcmp(s, "ON") == 0);
+ return;
+ }
+
+ if (abort_next) {
+ abort_next = 0;
+ if ( n_aborts < MAX_ABORTS ) {
+ char *s1;
+ s1 = clean(s, 0);
+ if (( strlen(s1) <= strlen(s) ) && ( strlen(s1) < sizeof(fail_buffer)))
+ abort_string[n_aborts++] = s1;
+ else
+ free(s1);
+ }
+ return;
+ }
+
+ if (clear_abort_next) {
+ clear_abort_next = 0;
+ return;
+ }
+
+ if (report_next) {
+ report_next = 0;
+ return;
+ }
+
+ if (clear_report_next) {
+ clear_report_next = 0;
+ return;
+ }
+
+ if (timeout_next) {
+ timeout_next = 0;
+ timeout = atoi(s);
+
+ if (timeout <= 0){
+ timeout = DEFAULT_CHAT_TIMEOUT;
+ }
+ return;
+ }
+
+ if (strcmp(s, "EOT") == 0){
+ s = "^D\\c";
+ }
+ else{
+ if (strcmp(s, "BREAK") == 0){
+ s = "\\K\\c";
+ }
+
+ if (!put_string(s)) {
+ exit_code = 2;
+ }
+ }
+}
+
+static int get_char(void)
+{
+ int status;
+ char c;
+ int tries=MAX_TIMEOUTS;
+
+ while(tries)
+ {
+ status = read(ttyfd, &c, 1);
+ switch (status) {
+ case 1:
+ return ((int)c & 0x7F);
+ default:
+ tries--;
+ }
+ }
+ return -1;
+}
+
+static int put_char(
+ int c)
+{
+ char ch = c;
+
+ return(write(ttyfd, &ch, 1));
+}
+
+static int write_char (
+ int c)
+{
+ if (put_char(c) < 1) {
+ return (0);
+ }
+ return (1);
+}
+
+static int put_string (
+ char *s)
+{
+ char *out,*free_ptr=0;
+
+ quiet = 0;
+ out = free_ptr = clean(s, 1);
+ while (*out) {
+ register char c = *out++;
+
+ if (c != '\\') {
+ if (!write_char (c)){
+ free(free_ptr);
+ return 0;
+ }
+ continue;
+ }
+
+ c = *out++;
+
+ switch (c) {
+ case 'd':
+ sleep(1);
+ break;
+
+ case 'K':
+ break_sequence();
+ break;
+
+ case 'p':
+#if 0 /* FIXME!!! */
+ usleep(10000); /* 1/100th of a second (arg is microseconds) */
+#else
+ sleep(1);
+#endif
+ break;
+
+ default:
+ if (!write_char (c)){
+ free(free_ptr);
+ return 0;
+ }
+ break;
+ }
+ }
+ free(free_ptr);
+
+ return (1);
+}
+
+/*
+ * 'Wait for' this string to appear on this file descriptor.
+ */
+static int get_string(
+ char *in_string)
+{
+ int c, len, minlen;
+ register char *s = temp2, *end = s + STR_LEN;
+ char *logged = temp2;
+ char *string=0;
+ struct termios tios;
+
+ memset(temp2, 0, sizeof(temp2));
+
+ tcgetattr(ttyfd, &tios);
+ tios.c_cc[VMIN] = 0;
+ tios.c_cc[VTIME] = timeout*10/MAX_TIMEOUTS;
+ tcsetattr(ttyfd, TCSANOW, &tios);
+
+ string = clean(in_string, 0);
+ len = strlen(string);
+ minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1;
+
+ if (len > STR_LEN) {
+ exit_code = 1;
+ free(string);
+ return 0;
+ }
+
+ if (len == 0) {
+ free(string);
+ return (1);
+ }
+
+ while ( (c = get_char()) >= 0) {
+ int n, abort_len;
+
+ if(c == '\n' || c == '\r'){
+ s = temp2;
+ *s=0;
+ }
+ else{
+ *s++ = c;
+ *s=0;
+ }
+
+ if (s - temp2 >= len &&
+ c == string[len - 1] &&
+ strncmp(s - len, string, len) == 0) {
+ free(string);
+ return (1);
+ }
+
+ for (n = 0; n < n_aborts; ++n) {
+ if (s - temp2 >= (abort_len = strlen(abort_string[n])) &&
+ strncmp(s - abort_len, abort_string[n], abort_len) == 0) {
+
+ exit_code = n + 4;
+ strcpy(fail_reason = fail_buffer, abort_string[n]);
+ free(string);
+ return (0);
+ }
+ }
+
+ if (s >= end) {
+ if (logged < s - minlen) {
+ logged = s;
+ }
+ s -= minlen;
+ memmove(temp2, s, minlen);
+ logged = temp2 + (logged - s);
+ s = temp2 + minlen;
+ }
+ }
+
+ exit_code = 3;
+ free(string);
+ return (0);
+}
diff --git a/cpukit/pppd/demand.c b/cpukit/pppd/demand.c
new file mode 100644
index 0000000000..a094a15f50
--- /dev/null
+++ b/cpukit/pppd/demand.c
@@ -0,0 +1,347 @@
+/*
+ * demand.c - Support routines for demand-dialling.
+ *
+ * Copyright (c) 1993 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#ifdef PPP_FILTER
+#include <net/if.h>
+#include <net/bpf.h>
+#include <pcap.h>
+#endif
+
+#include "pppd.h"
+#include "fsm.h"
+#include "ipcp.h"
+#include "lcp.h"
+
+static const char rcsid[] = RCSID;
+
+static unsigned char *frame;
+static int framelen;
+static int framemax;
+static int escape_flag;
+static int flush_flag;
+static int fcs;
+
+struct packet {
+ int length;
+ struct packet *next;
+ unsigned char data[1];
+};
+
+struct packet *pend_q;
+struct packet *pend_qtail;
+
+static int active_packet(unsigned char *, int);
+
+/*
+ * demand_conf - configure the interface for doing dial-on-demand.
+ */
+void
+demand_conf(void)
+{
+ int i;
+ struct protent *protp;
+
+/* framemax = lcp_allowoptions[0].mru;
+ if (framemax < PPP_MRU) */
+ framemax = PPP_MRU;
+ framemax += PPP_HDRLEN + PPP_FCSLEN;
+ frame = malloc(framemax);
+ if (frame == NULL)
+ novm("demand frame");
+ framelen = 0;
+ pend_q = NULL;
+ escape_flag = 0;
+ flush_flag = 0;
+ fcs = PPP_INITFCS;
+
+ ppp_send_config(0, PPP_MRU, (uint32_t) 0, 0, 0);
+ ppp_recv_config(0, PPP_MRU, (uint32_t) 0, 0, 0);
+
+#ifdef PPP_FILTER
+ set_filters(&pass_filter, &active_filter);
+#endif
+
+ /*
+ * Call the demand_conf procedure for each protocol that's got one.
+ */
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->enabled_flag && protp->demand_conf != NULL)
+ if (!((*protp->demand_conf)(0)))
+ die(1);
+}
+
+
+/*
+ * demand_block - set each network protocol to block further packets.
+ */
+void
+demand_block(void)
+{
+ int i;
+ struct protent *protp;
+
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->enabled_flag && protp->demand_conf != NULL)
+ sifnpmode(0, protp->protocol & ~0x8000, NPMODE_QUEUE);
+ get_loop_output();
+}
+
+/*
+ * demand_discard - set each network protocol to discard packets
+ * with an error.
+ */
+void
+demand_discard(void)
+{
+ struct packet *pkt, *nextpkt;
+ int i;
+ struct protent *protp;
+
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->enabled_flag && protp->demand_conf != NULL)
+ sifnpmode(0, protp->protocol & ~0x8000, NPMODE_ERROR);
+ get_loop_output();
+
+ /* discard all saved packets */
+ for (pkt = pend_q; pkt != NULL; pkt = nextpkt) {
+ nextpkt = pkt->next;
+ free(pkt);
+ }
+ pend_q = NULL;
+ framelen = 0;
+ flush_flag = 0;
+ escape_flag = 0;
+ fcs = PPP_INITFCS;
+}
+
+/*
+ * demand_unblock - set each enabled network protocol to pass packets.
+ */
+void
+demand_unblock(void)
+{
+ int i;
+ struct protent *protp;
+
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->enabled_flag && protp->demand_conf != NULL)
+ sifnpmode(0, protp->protocol & ~0x8000, NPMODE_PASS);
+}
+
+/*
+ * FCS lookup table as calculated by genfcstab.
+ */
+static u_short fcstab[256] = {
+ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
+ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
+ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
+ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
+ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
+ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
+ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
+ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
+ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
+ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
+ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
+ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
+ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
+ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
+ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
+ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
+ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
+ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
+ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
+ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
+ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
+ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
+ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
+ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
+ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
+ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
+ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
+ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
+ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
+ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
+ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
+ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
+};
+
+/*
+ * loop_chars - process characters received from the loopback.
+ * Calls loop_frame when a complete frame has been accumulated.
+ * Return value is 1 if we need to bring up the link, 0 otherwise.
+ */
+int
+loop_chars(
+ unsigned char *p,
+ int n)
+{
+ int c, rv;
+
+ rv = 0;
+ for (; n > 0; --n) {
+ c = *p++;
+ if (c == PPP_FLAG) {
+ if (!escape_flag && !flush_flag
+ && framelen > 2 && fcs == PPP_GOODFCS) {
+ framelen -= 2;
+ if (loop_frame(frame, framelen))
+ rv = 1;
+ }
+ framelen = 0;
+ flush_flag = 0;
+ escape_flag = 0;
+ fcs = PPP_INITFCS;
+ continue;
+ }
+ if (flush_flag)
+ continue;
+ if (escape_flag) {
+ c ^= PPP_TRANS;
+ escape_flag = 0;
+ } else if (c == PPP_ESCAPE) {
+ escape_flag = 1;
+ continue;
+ }
+ if (framelen >= framemax) {
+ flush_flag = 1;
+ continue;
+ }
+ frame[framelen++] = c;
+ fcs = PPP_FCS(fcs, c);
+ }
+ return rv;
+}
+
+/*
+ * loop_frame - given a frame obtained from the loopback,
+ * decide whether to bring up the link or not, and, if we want
+ * to transmit this frame later, put it on the pending queue.
+ * Return value is 1 if we need to bring up the link, 0 otherwise.
+ * We assume that the kernel driver has already applied the
+ * pass_filter, so we won't get packets it rejected.
+ * We apply the active_filter to see if we want this packet to
+ * bring up the link.
+ */
+int
+loop_frame(
+ unsigned char *frame,
+ int len)
+{
+ struct packet *pkt;
+
+ /* dbglog("from loop: %P", frame, len); */
+ if (len < PPP_HDRLEN)
+ return 0;
+ if ((PPP_PROTOCOL(frame) & 0x8000) != 0)
+ return 0; /* shouldn't get any of these anyway */
+ if (!active_packet(frame, len))
+ return 0;
+
+ pkt = (struct packet *) malloc(sizeof(struct packet) + len);
+ if (pkt != NULL) {
+ pkt->length = len;
+ pkt->next = NULL;
+ memcpy(pkt->data, frame, len);
+ if (pend_q == NULL)
+ pend_q = pkt;
+ else
+ pend_qtail->next = pkt;
+ pend_qtail = pkt;
+ }
+ return 1;
+}
+
+/*
+ * demand_rexmit - Resend all those frames which we got via the
+ * loopback, now that the real serial link is up.
+ */
+void
+demand_rexmit(
+ int proto)
+{
+ struct packet *pkt, *prev, *nextpkt;
+
+ prev = NULL;
+ pkt = pend_q;
+ pend_q = NULL;
+ for (; pkt != NULL; pkt = nextpkt) {
+ nextpkt = pkt->next;
+ if (PPP_PROTOCOL(pkt->data) == proto) {
+ output(0, pkt->data, pkt->length);
+ free(pkt);
+ } else {
+ if (prev == NULL)
+ pend_q = pkt;
+ else
+ prev->next = pkt;
+ prev = pkt;
+ }
+ }
+ pend_qtail = prev;
+ if (prev != NULL)
+ prev->next = NULL;
+}
+
+/*
+ * Scan a packet to decide whether it is an "active" packet,
+ * that is, whether it is worth bringing up the link for.
+ */
+static int
+active_packet(
+ unsigned char *p,
+ int len)
+{
+ int proto, i;
+ struct protent *protp;
+
+ if (len < PPP_HDRLEN)
+ return 0;
+ proto = PPP_PROTOCOL(p);
+#ifdef PPP_FILTER
+ if (active_filter.bf_len != 0
+ && bpf_filter(active_filter.bf_insns, frame, len, len) == 0)
+ return 0;
+#endif
+ for (i = 0; (protp = protocols[i]) != NULL; ++i) {
+ if (protp->protocol < 0xC000 && (protp->protocol & ~0x8000) == proto) {
+ if (!protp->enabled_flag)
+ return 0;
+ if (protp->active_pkt == NULL)
+ return 1;
+ return (*protp->active_pkt)(p, len);
+ }
+ }
+ return 0; /* not a supported protocol !!?? */
+}
diff --git a/cpukit/pppd/example/Makefile-user b/cpukit/pppd/example/Makefile-user
new file mode 100644
index 0000000000..69cc8aab50
--- /dev/null
+++ b/cpukit/pppd/example/Makefile-user
@@ -0,0 +1,45 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+EXEC=ppptest.exe
+PGM=${ARCH}/$(EXEC)
+
+# optional managers required
+MANAGERS=io event semaphore
+
+# C source names
+CSRCS = init.c pppdapp.c
+
+COBJS_ = $(CSRCS:.c=.o)
+COBJS = $(COBJS_:%=${ARCH}/%)
+
+# C++ source names
+CXXSRCS =
+CXXOBJS_ = $(CXXSRCS:.cc=.o)
+CXXOBJS = $(CXXOBJS_:%=${ARCH}/%)
+
+# AS source names
+ASSRCS =
+ASOBJS_ = $(ASSRCS:.s=.o)
+ASOBJS = $(ASOBJS_:%=${ARCH}/%)
+
+# Libraries
+LIBS = -lrtemsall -lc
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+
+include $(RTEMS_CUSTOM)
+include $(PROJECT_ROOT)/make/leaf.cfg
+
+OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)
+
+all: ${ARCH} $(PGM)
+
+$(PGM): $(OBJS)
+ $(make-exe)
+
diff --git a/cpukit/pppd/example/README b/cpukit/pppd/example/README
new file mode 100644
index 0000000000..677e00af33
--- /dev/null
+++ b/cpukit/pppd/example/README
@@ -0,0 +1,15 @@
+#
+# $Id$
+#
+
+This is an example user application using pppd. It is built using
+the RTEMS application Makefiles. The file Makefile-user should
+be renamed to Makefile or the -f option given to make. The file
+is renamed to avoid bootstrap -c removing it.
+
+The files ppp.conf and pppd.options are sample configuration files
+that have successfully used to make ppp connections over a null
+modem serial cable to a UNIX box. Please review the man pages
+for either the ppp or pppd applications to ensure they are configured
+correctly.
+
diff --git a/cpukit/pppd/example/init.c b/cpukit/pppd/example/init.c
new file mode 100644
index 0000000000..f35d195bf2
--- /dev/null
+++ b/cpukit/pppd/example/init.c
@@ -0,0 +1,24 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtemspppd.h>
+
+#define CONFIGURE_INIT
+#include "system.h"
+#include "netconfig.h"
+
+
+extern int pppdapp_initialize(void);
+
+
+rtems_task Init(rtems_task_argument argument)
+{
+ /* initialize network */
+ rtems_bsdnet_initialize_network();
+ rtems_pppd_initialize();
+ pppdapp_initialize();
+
+ rtems_task_delete(RTEMS_SELF);
+}
diff --git a/cpukit/pppd/example/netconfig.h b/cpukit/pppd/example/netconfig.h
new file mode 100644
index 0000000000..3428288cd2
--- /dev/null
+++ b/cpukit/pppd/example/netconfig.h
@@ -0,0 +1,36 @@
+
+#ifndef NETCONFIG_H_
+#define NETCONFIG_H_
+
+#include <bsp.h>
+
+/* external function prototypes */
+extern int rtems_ppp_driver_attach(struct rtems_bsdnet_ifconfig *config, int attaching);
+
+/* Default network interface */
+static struct rtems_bsdnet_ifconfig netdriver_config = {
+ "ppp0", /* name */
+ rtems_ppp_driver_attach, /* attach function */
+ NULL, /* No more interfaces */
+ NULL, /* IP address */
+ NULL, /* IP net mask */
+ NULL, /* Driver supplies hardware address */
+ 0 /* Use default driver parameters */
+};
+
+/* Network configuration */
+struct rtems_bsdnet_config rtems_bsdnet_config = {
+ &netdriver_config,
+ NULL,
+ 30, /* Default network task priority */
+ (256*1024), /* Default mbuf capacity */
+ (512*1024), /* Default mbuf cluster capacity */
+ 0, /* Host name */
+ 0, /* Domain name */
+ 0, /* Gateway */
+ 0, /* Log host */
+ { 0 }, /* Name server(s) */
+ { 0 }, /* NTP server(s) */
+};
+
+#endif
diff --git a/cpukit/pppd/example/ppp.conf b/cpukit/pppd/example/ppp.conf
new file mode 100644
index 0000000000..094b1946a8
--- /dev/null
+++ b/cpukit/pppd/example/ppp.conf
@@ -0,0 +1,27 @@
+
+#
+# Example configuration file for setting up a ppp server
+# using a null-modem serial cable:
+#
+# Tested using ppp on OpenBSD 2.9
+# - just follow instructions in man page for accepting
+# ppp connections over the serial port
+# - if pap and/or chap is enabled, you must have a ppp.secret
+# file which will be used for user authentication
+# - found useful to turn on syslog for ppp
+#
+
+default:
+ set log Phase Chat LQM LCP IPCP CCP command
+ set device /dev/cua00
+ set speed 57600
+ set ctsrts on
+ set dial ""
+
+openbsd-server:
+ set timeout 0
+ set ifaddr 192.168.2.100 192.168.2.123
+ enable dns
+ allow users
+ enable chap
+ enable pap
diff --git a/cpukit/pppd/example/pppd.options b/cpukit/pppd/example/pppd.options
new file mode 100644
index 0000000000..c0706e6ec5
--- /dev/null
+++ b/cpukit/pppd/example/pppd.options
@@ -0,0 +1,9 @@
+/dev/tty00
+57600
+crtscts
+passive
+local
+noauth
+debug
+persist
+192.168.2.222:192.168.2.111
diff --git a/cpukit/pppd/example/pppdapp.c b/cpukit/pppd/example/pppdapp.c
new file mode 100644
index 0000000000..59e5029088
--- /dev/null
+++ b/cpukit/pppd/example/pppdapp.c
@@ -0,0 +1,146 @@
+
+#include <stdio.h>
+#include <rtemspppd.h>
+#include "system.h"
+
+
+/* define global variables */
+static unsigned int pppdapp_linkcount = 0;
+static rtems_id pppdapp_taskid;
+
+
+static void pppdapp_linkup_hook(void)
+{
+ pppdapp_linkcount++;
+ printf("PPP LINK UP [%d]\n", pppdapp_linkcount);
+}
+
+static void pppdapp_linkdown_hook(void)
+{
+ printf("PPP LINK DOWN [%d]\n", pppdapp_linkcount);
+}
+
+static void pppdapp_ipup_hook(void)
+{
+ /* send ipup signal to pppdapp task */
+ rtems_event_send(pppdapp_taskid, RTEMS_EVENT_10);
+}
+
+static void pppdapp_ipdown_hook(void)
+{
+ /* send ip down signal to pppdapp task */
+ rtems_event_send(pppdapp_taskid, RTEMS_EVENT_11);
+}
+
+static void pppdapp_setup(void)
+{
+ const char *pUser = "oscar";
+ const char *pPassword = "goldman";
+
+#undef USE_MODEM
+#ifdef USE_MODEM
+ const char *pTelephone = "5551234";
+ const char *pInitScript = "TIMEOUT@5@@AT@@OK@";
+ const char *pConnectScript = "TIMEOUT@90@@ATDT%s@CONNECT@@name:@%s@word:@%s@";
+ const char *pDisconnectScript = "TIMEOUT@5@@ATH0@@OK@";
+ char pConnect[128];
+
+ /* set the connect string */
+ sprintf(pConnect, pConnectScript, pTelephone, pUser, pPassword);
+
+ /* set pppd options for modem */
+ rtems_pppd_set_option("/dev/ttyS2", NULL);
+ rtems_pppd_set_option("57600", NULL);
+ rtems_pppd_set_option("crtscts", NULL);
+ rtems_pppd_set_option("modem", NULL);
+ rtems_pppd_set_option("noauth", NULL);
+ rtems_pppd_set_option("debug", NULL);
+ rtems_pppd_set_option("init", pInitScript);
+ rtems_pppd_set_option("connect", pConnect);
+ rtems_pppd_set_option("disconnect", pDisconnectScript);
+#else
+ /* set pppd options for null modem direct link serial cable */
+ rtems_pppd_set_option("/dev/ttyS1", NULL);
+ rtems_pppd_set_option("57600", NULL);
+ rtems_pppd_set_option("crtscts", NULL);
+ rtems_pppd_set_option("local", NULL);
+ rtems_pppd_set_option("noauth", NULL);
+ rtems_pppd_set_option("debug", NULL);
+ rtems_pppd_set_option("user", pUser);
+ rtems_pppd_set_option("password", pPassword);
+#endif
+
+ /* set up pppd hooks */
+ rtems_pppd_set_hook(RTEMS_PPPD_LINKUP_HOOK, pppdapp_linkup_hook);
+ rtems_pppd_set_hook(RTEMS_PPPD_LINKDOWN_HOOK, pppdapp_linkdown_hook);
+ rtems_pppd_set_hook(RTEMS_PPPD_IPUP_HOOK, pppdapp_ipup_hook);
+ rtems_pppd_set_hook(RTEMS_PPPD_IPDOWN_HOOK, pppdapp_ipdown_hook);
+}
+
+static rtems_task pppdapp(rtems_task_argument arg)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_interval tickspersecond = 0;
+ rtems_option options;
+ rtems_event_set in;
+ rtems_event_set out;
+
+ /* initialize ticks per second */
+ rtems_clock_get(RTEMS_CLOCK_GET_TICKS_PER_SECOND, &tickspersecond);
+ if ( tickspersecond == 0 ) {
+ /* ensure value is greater than zero */
+ tickspersecond = 100;
+ }
+
+ /* initiate connection */
+ pppdapp_setup();
+ rtems_pppd_connect();
+
+ /* enter processing loop */
+ in = (RTEMS_EVENT_10 | RTEMS_EVENT_11);
+ options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
+ while ( sc == RTEMS_SUCCESSFUL ) {
+ /* wait for the next event */
+ sc = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
+ if ( sc == RTEMS_SUCCESSFUL ) {
+ /* determine which event was sent */
+ if ( out & RTEMS_EVENT_10 ) {
+ /* ip up recived */
+ /* call disconnect function */
+ rtems_pppd_disconnect();
+ }
+ if ( out & RTEMS_EVENT_11 ) {
+ /* ip down recived */
+ /* sleep 10 seconds and call connect function */
+ rtems_task_wake_after(10*tickspersecond);
+ rtems_pppd_connect();
+ }
+ }
+ }
+
+ /* terminate myself */
+ rtems_task_delete(RTEMS_SELF);
+}
+
+int pppdapp_initialize(void)
+{
+ int iReturn = (int)-1;
+ rtems_status_code status;
+ rtems_name taskName;
+
+ taskName = rtems_build_name( 'p', 'a', 'p', 'p' );
+ status = rtems_task_create(taskName,
+ CONFIGURE_INIT_TASK_PRIORITY,
+ CONFIGURE_INIT_TASK_STACK_SIZE,
+ CONFIGURE_INIT_TASK_INITIAL_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &pppdapp_taskid);
+ if ( status == RTEMS_SUCCESSFUL ) {
+ status = rtems_task_start(pppdapp_taskid, pppdapp, 0);
+ if ( status == RTEMS_SUCCESSFUL ) {
+ iReturn = (int)0;
+ }
+ }
+
+ return ( iReturn );
+}
diff --git a/cpukit/pppd/example/system.h b/cpukit/pppd/example/system.h
new file mode 100644
index 0000000000..c727b2f085
--- /dev/null
+++ b/cpukit/pppd/example/system.h
@@ -0,0 +1,42 @@
+
+#ifndef SYSTEM_H
+#define SYSTEM_H
+
+#include <rtems.h>
+#include <tty_drv.h>
+
+/* functions */
+extern rtems_task Init(rtems_task_argument argument);
+
+#include <bsp.h>
+
+#define CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE
+#ifdef CONFIGURE_INIT
+rtems_driver_address_table Device_drivers[5] = {
+ CONSOLE_DRIVER_TABLE_ENTRY,
+ CLOCK_DRIVER_TABLE_ENTRY,
+ TTY1_DRIVER_TABLE_ENTRY,
+ TTY2_DRIVER_TABLE_ENTRY,
+ {NULL, NULL, NULL, NULL, NULL, NULL}
+};
+#endif
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 8
+
+#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_TASKS 20
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 10000
+
+#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY 120
+#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
+ RTEMS_NO_TIMESLICE | \
+ RTEMS_NO_ASR | \
+ RTEMS_INTERRUPT_LEVEL(0))
+
+#include <rtems/confdefs.h>
+
+#endif
diff --git a/cpukit/pppd/fsm.c b/cpukit/pppd/fsm.c
new file mode 100644
index 0000000000..ce06401b1f
--- /dev/null
+++ b/cpukit/pppd/fsm.c
@@ -0,0 +1,764 @@
+/*
+ * fsm.c - {Link, IP} Control Protocol Finite State Machine.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+/*
+ * TODO:
+ * Randomize fsm id on link/init.
+ * Deal with variable outgoing MTU.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "pppd.h"
+#include "fsm.h"
+
+static const char rcsid[] = RCSID;
+
+static void fsm_timeout(void *);
+static void fsm_rconfreq(fsm *, u_char, u_char *, int);
+static void fsm_rconfack(fsm *, int, u_char *, int);
+static void fsm_rconfnakrej(fsm *, int, int, u_char *, int);
+static void fsm_rtermreq(fsm *, int, u_char *, int);
+static void fsm_rtermack(fsm *);
+static void fsm_rcoderej(fsm *, u_char *, int);
+static void fsm_sconfreq(fsm *, int);
+
+#define PROTO_NAME(f) ((f)->callbacks->proto_name)
+
+int peer_mru[NUM_PPP];
+
+
+/*
+ * fsm_init - Initialize fsm.
+ *
+ * Initialize fsm state.
+ */
+void
+fsm_init(
+ fsm *f)
+{
+ f->state = INITIAL;
+ f->flags = 0;
+ f->id = 100; /* XXX Start with random id? */
+ f->timeouttime = DEFTIMEOUT;
+ f->maxconfreqtransmits = DEFMAXCONFREQS;
+ f->maxtermtransmits = DEFMAXTERMREQS;
+ f->maxnakloops = DEFMAXNAKLOOPS;
+ f->term_reason_len = 0;
+}
+
+
+/*
+ * fsm_lowerup - The lower layer is up.
+ */
+void
+fsm_lowerup(
+ fsm *f)
+{
+ switch( f->state ){
+ case INITIAL:
+ f->state = CLOSED;
+ break;
+
+ case STARTING:
+ if( f->flags & OPT_SILENT )
+ f->state = STOPPED;
+ else {
+ /* Send an initial configure-request */
+ fsm_sconfreq(f, 0);
+ f->state = REQSENT;
+ }
+ break;
+
+ default:
+ FSMDEBUG(("%s: Up event in state %d!", PROTO_NAME(f), f->state));
+ }
+}
+
+
+/*
+ * fsm_lowerdown - The lower layer is down.
+ *
+ * Cancel all timeouts and inform upper layers.
+ */
+void
+fsm_lowerdown(
+ fsm *f)
+{
+ switch( f->state ){
+ case CLOSED:
+ f->state = INITIAL;
+ break;
+
+ case STOPPED:
+ f->state = STARTING;
+ if( f->callbacks->starting )
+ (*f->callbacks->starting)(f);
+ break;
+
+ case CLOSING:
+ f->state = INITIAL;
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ break;
+
+ case STOPPING:
+ case REQSENT:
+ case ACKRCVD:
+ case ACKSENT:
+ f->state = STARTING;
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ break;
+
+ case OPENED:
+ if( f->callbacks->down )
+ (*f->callbacks->down)(f);
+ f->state = STARTING;
+ break;
+
+ default:
+ FSMDEBUG(("%s: Down event in state %d!", PROTO_NAME(f), f->state));
+ }
+}
+
+
+/*
+ * fsm_open - Link is allowed to come up.
+ */
+void
+fsm_open(
+ fsm *f)
+{
+ switch( f->state ){
+ case INITIAL:
+ f->state = STARTING;
+ if( f->callbacks->starting )
+ (*f->callbacks->starting)(f);
+ break;
+
+ case CLOSED:
+ if( f->flags & OPT_SILENT )
+ f->state = STOPPED;
+ else {
+ /* Send an initial configure-request */
+ fsm_sconfreq(f, 0);
+ f->state = REQSENT;
+ }
+ break;
+
+ case CLOSING:
+ f->state = STOPPING;
+ /* fall through */
+ case STOPPED:
+ case OPENED:
+ if( f->flags & OPT_RESTART ){
+ fsm_lowerdown(f);
+ fsm_lowerup(f);
+ }
+ break;
+ }
+}
+
+
+/*
+ * fsm_close - Start closing connection.
+ *
+ * Cancel timeouts and either initiate close or possibly go directly to
+ * the CLOSED state.
+ */
+void
+fsm_close(
+ fsm *f,
+ char *reason)
+{
+ f->term_reason = reason;
+ f->term_reason_len = (reason == NULL? 0: strlen(reason));
+ switch( f->state ){
+ case STARTING:
+ f->state = INITIAL;
+ break;
+ case STOPPED:
+ f->state = CLOSED;
+ break;
+ case STOPPING:
+ f->state = CLOSING;
+ break;
+
+ case REQSENT:
+ case ACKRCVD:
+ case ACKSENT:
+ case OPENED:
+ if( f->state != OPENED )
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ else if( f->callbacks->down )
+ (*f->callbacks->down)(f); /* Inform upper layers we're down */
+
+ /* Init restart counter, send Terminate-Request */
+ f->retransmits = f->maxtermtransmits;
+ fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
+ (u_char *) f->term_reason, f->term_reason_len);
+ TIMEOUT(fsm_timeout, f, f->timeouttime);
+ --f->retransmits;
+
+ f->state = CLOSING;
+ break;
+ }
+}
+
+
+/*
+ * fsm_timeout - Timeout expired.
+ */
+static void
+fsm_timeout(
+ void *arg)
+{
+ fsm *f = (fsm *) arg;
+
+ switch (f->state) {
+ case CLOSING:
+ case STOPPING:
+ if( f->retransmits <= 0 ){
+ /*
+ * We've waited for an ack long enough. Peer probably heard us.
+ */
+ f->state = (f->state == CLOSING)? CLOSED: STOPPED;
+ if( f->callbacks->finished )
+ (*f->callbacks->finished)(f);
+ } else {
+ /* Send Terminate-Request */
+ fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
+ (u_char *) f->term_reason, f->term_reason_len);
+ TIMEOUT(fsm_timeout, f, f->timeouttime);
+ --f->retransmits;
+ }
+ break;
+
+ case REQSENT:
+ case ACKRCVD:
+ case ACKSENT:
+ if (f->retransmits <= 0) {
+ warn("%s: timeout sending Config-Requests\n", PROTO_NAME(f));
+ f->state = STOPPED;
+ if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished )
+ (*f->callbacks->finished)(f);
+
+ } else {
+ /* Retransmit the configure-request */
+ if (f->callbacks->retransmit)
+ (*f->callbacks->retransmit)(f);
+ fsm_sconfreq(f, 1); /* Re-send Configure-Request */
+ if( f->state == ACKRCVD )
+ f->state = REQSENT;
+ }
+ break;
+
+ default:
+ FSMDEBUG(("%s: Timeout event in state %d!", PROTO_NAME(f), f->state));
+ }
+}
+
+
+/*
+ * fsm_input - Input packet.
+ */
+void
+fsm_input(
+ fsm *f,
+ u_char *inpacket,
+ int l)
+{
+ u_char *inp;
+ u_char code, id;
+ int len;
+
+ /*
+ * Parse header (code, id and length).
+ * If packet too short, drop it.
+ */
+ inp = inpacket;
+ if (l < HEADERLEN) {
+ FSMDEBUG(("fsm_input(%x): Rcvd short header.", f->protocol));
+ return;
+ }
+ GETCHAR(code, inp);
+ GETCHAR(id, inp);
+ GETSHORT(len, inp);
+ if (len < HEADERLEN) {
+ FSMDEBUG(("fsm_input(%x): Rcvd illegal length.", f->protocol));
+ return;
+ }
+ if (len > l) {
+ FSMDEBUG(("fsm_input(%x): Rcvd short packet.", f->protocol));
+ return;
+ }
+ len -= HEADERLEN; /* subtract header length */
+
+ if( f->state == INITIAL || f->state == STARTING ){
+ FSMDEBUG(("fsm_input(%x): Rcvd packet in state %d.",
+ f->protocol, f->state));
+ return;
+ }
+
+ /*
+ * Action depends on code.
+ */
+ switch (code) {
+ case CONFREQ:
+ fsm_rconfreq(f, id, inp, len);
+ break;
+
+ case CONFACK:
+ fsm_rconfack(f, id, inp, len);
+ break;
+
+ case CONFNAK:
+ case CONFREJ:
+ fsm_rconfnakrej(f, code, id, inp, len);
+ break;
+
+ case TERMREQ:
+ fsm_rtermreq(f, id, inp, len);
+ break;
+
+ case TERMACK:
+ fsm_rtermack(f);
+ break;
+
+ case CODEREJ:
+ fsm_rcoderej(f, inp, len);
+ break;
+
+ default:
+ if( !f->callbacks->extcode
+ || !(*f->callbacks->extcode)(f, code, id, inp, len) )
+ fsm_sdata(f, CODEREJ, ++f->id, inpacket, len + HEADERLEN);
+ break;
+ }
+}
+
+
+/*
+ * fsm_rconfreq - Receive Configure-Request.
+ */
+static void
+fsm_rconfreq(
+ fsm *f,
+ u_char id,
+ u_char *inp,
+ int len)
+{
+ int code, reject_if_disagree;
+
+ switch( f->state ){
+ case CLOSED:
+ /* Go away, we're closed */
+ fsm_sdata(f, TERMACK, id, NULL, 0);
+ return;
+ case CLOSING:
+ case STOPPING:
+ return;
+
+ case OPENED:
+ /* Go down and restart negotiation */
+ if( f->callbacks->down )
+ (*f->callbacks->down)(f); /* Inform upper layers */
+ fsm_sconfreq(f, 0); /* Send initial Configure-Request */
+ break;
+
+ case STOPPED:
+ /* Negotiation started by our peer */
+ fsm_sconfreq(f, 0); /* Send initial Configure-Request */
+ f->state = REQSENT;
+ break;
+ }
+
+ /*
+ * Pass the requested configuration options
+ * to protocol-specific code for checking.
+ */
+ if (f->callbacks->reqci){ /* Check CI */
+ reject_if_disagree = (f->nakloops >= f->maxnakloops);
+ code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree);
+ } else if (len)
+ code = CONFREJ; /* Reject all CI */
+ else
+ code = CONFACK;
+
+ /* send the Ack, Nak or Rej to the peer */
+ fsm_sdata(f, code, id, inp, len);
+
+ if (code == CONFACK) {
+ if (f->state == ACKRCVD) {
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ f->state = OPENED;
+ if (f->callbacks->up)
+ (*f->callbacks->up)(f); /* Inform upper layers */
+ } else {
+ f->state = ACKSENT;
+ ppp_delay();
+ }
+ f->nakloops = 0;
+
+ } else {
+ /* we sent CONFACK or CONFREJ */
+ if (f->state != ACKRCVD)
+ f->state = REQSENT;
+ if( code == CONFNAK )
+ ++f->nakloops;
+ }
+}
+
+
+/*
+ * fsm_rconfack - Receive Configure-Ack.
+ */
+static void
+fsm_rconfack(
+ fsm *f,
+ int id,
+ u_char *inp,
+ int len)
+{
+ if (id != f->reqid || f->seen_ack) /* Expected id? */
+ return; /* Nope, toss... */
+ if( !(f->callbacks->ackci? (*f->callbacks->ackci)(f, inp, len):
+ (len == 0)) ){
+ /* Ack is bad - ignore it */
+ error("Received bad configure-ack: %P", inp, len);
+ return;
+ }
+ f->seen_ack = 1;
+
+ switch (f->state) {
+ case CLOSED:
+ case STOPPED:
+ fsm_sdata(f, TERMACK, id, NULL, 0);
+ break;
+
+ case REQSENT:
+ f->state = ACKRCVD;
+ f->retransmits = f->maxconfreqtransmits;
+ break;
+
+ case ACKRCVD:
+ /* Huh? an extra valid Ack? oh well... */
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ fsm_sconfreq(f, 0);
+ f->state = REQSENT;
+ break;
+
+ case ACKSENT:
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ f->state = OPENED;
+ f->retransmits = f->maxconfreqtransmits;
+ if (f->callbacks->up)
+ (*f->callbacks->up)(f); /* Inform upper layers */
+ break;
+
+ case OPENED:
+ /* Go down and restart negotiation */
+ if (f->callbacks->down)
+ (*f->callbacks->down)(f); /* Inform upper layers */
+ fsm_sconfreq(f, 0); /* Send initial Configure-Request */
+ f->state = REQSENT;
+ break;
+ }
+}
+
+
+/*
+ * fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
+ */
+static void
+fsm_rconfnakrej(
+ fsm *f,
+ int code, int id,
+ u_char *inp,
+ int len)
+{
+ int (*proc)(fsm *, u_char *, int);
+ int ret;
+
+ if (id != f->reqid || f->seen_ack) /* Expected id? */
+ return; /* Nope, toss... */
+ proc = (code == CONFNAK)? f->callbacks->nakci: f->callbacks->rejci;
+ if (!proc || !(ret = proc(f, inp, len))) {
+ /* Nak/reject is bad - ignore it */
+ error("Received bad configure-nak/rej: %P", inp, len);
+ return;
+ }
+ f->seen_ack = 1;
+
+ switch (f->state) {
+ case CLOSED:
+ case STOPPED:
+ fsm_sdata(f, TERMACK, id, NULL, 0);
+ break;
+
+ case REQSENT:
+ case ACKSENT:
+ /* They didn't agree to what we wanted - try another request */
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ if (ret < 0)
+ f->state = STOPPED; /* kludge for stopping CCP */
+ else
+ fsm_sconfreq(f, 0); /* Send Configure-Request */
+ break;
+
+ case ACKRCVD:
+ /* Got a Nak/reject when we had already had an Ack?? oh well... */
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ fsm_sconfreq(f, 0);
+ f->state = REQSENT;
+ break;
+
+ case OPENED:
+ /* Go down and restart negotiation */
+ if (f->callbacks->down)
+ (*f->callbacks->down)(f); /* Inform upper layers */
+ fsm_sconfreq(f, 0); /* Send initial Configure-Request */
+ f->state = REQSENT;
+ break;
+ }
+}
+
+
+/*
+ * fsm_rtermreq - Receive Terminate-Req.
+ */
+static void
+fsm_rtermreq(
+ fsm *f,
+ int id,
+ u_char *p,
+ int len)
+{
+ switch (f->state) {
+ case ACKRCVD:
+ case ACKSENT:
+ f->state = REQSENT; /* Start over but keep trying */
+ break;
+
+ case OPENED:
+ if (len > 0) {
+ info("%s terminated by peer (%0.*v)", PROTO_NAME(f), len, p);
+ } else
+ info("%s terminated by peer", PROTO_NAME(f));
+ if (f->callbacks->down)
+ (*f->callbacks->down)(f); /* Inform upper layers */
+ f->retransmits = 0;
+ f->state = STOPPING;
+ TIMEOUT(fsm_timeout, f, f->timeouttime);
+ break;
+ }
+
+ fsm_sdata(f, TERMACK, id, NULL, 0);
+}
+
+
+/*
+ * fsm_rtermack - Receive Terminate-Ack.
+ */
+static void
+fsm_rtermack(
+ fsm *f)
+{
+ switch (f->state) {
+ case CLOSING:
+ UNTIMEOUT(fsm_timeout, f);
+ f->state = CLOSED;
+ if( f->callbacks->finished )
+ (*f->callbacks->finished)(f);
+ break;
+ case STOPPING:
+ UNTIMEOUT(fsm_timeout, f);
+ f->state = STOPPED;
+ if( f->callbacks->finished )
+ (*f->callbacks->finished)(f);
+ break;
+
+ case ACKRCVD:
+ f->state = REQSENT;
+ break;
+
+ case OPENED:
+ if (f->callbacks->down)
+ (*f->callbacks->down)(f); /* Inform upper layers */
+ fsm_sconfreq(f, 0);
+ break;
+ }
+}
+
+
+/*
+ * fsm_rcoderej - Receive an Code-Reject.
+ */
+static void
+fsm_rcoderej(
+ fsm *f,
+ u_char *inp,
+ int len)
+{
+ u_char code, id;
+
+ if (len < HEADERLEN) {
+ FSMDEBUG(("fsm_rcoderej: Rcvd short Code-Reject packet!"));
+ return;
+ }
+ GETCHAR(code, inp);
+ GETCHAR(id, inp);
+ warn("%s: Rcvd Code-Reject for code %d, id %d", PROTO_NAME(f), code, id);
+
+ if( f->state == ACKRCVD )
+ f->state = REQSENT;
+}
+
+
+/*
+ * fsm_protreject - Peer doesn't speak this protocol.
+ *
+ * Treat this as a catastrophic error (RXJ-).
+ */
+void
+fsm_protreject(
+ fsm *f)
+{
+ switch( f->state ){
+ case CLOSING:
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ /* fall through */
+ case CLOSED:
+ f->state = CLOSED;
+ if( f->callbacks->finished )
+ (*f->callbacks->finished)(f);
+ break;
+
+ case STOPPING:
+ case REQSENT:
+ case ACKRCVD:
+ case ACKSENT:
+ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
+ /* fall through */
+ case STOPPED:
+ f->state = STOPPED;
+ if( f->callbacks->finished )
+ (*f->callbacks->finished)(f);
+ break;
+
+ case OPENED:
+ if( f->callbacks->down )
+ (*f->callbacks->down)(f);
+
+ /* Init restart counter, send Terminate-Request */
+ f->retransmits = f->maxtermtransmits;
+ fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
+ (u_char *) f->term_reason, f->term_reason_len);
+ TIMEOUT(fsm_timeout, f, f->timeouttime);
+ --f->retransmits;
+
+ f->state = STOPPING;
+ break;
+
+ default:
+ FSMDEBUG(("%s: Protocol-reject event in state %d!",
+ PROTO_NAME(f), f->state));
+ }
+}
+
+
+/*
+ * fsm_sconfreq - Send a Configure-Request.
+ */
+static void
+fsm_sconfreq(
+ fsm *f,
+ int retransmit)
+{
+ u_char *outp;
+ int cilen;
+
+ if( f->state != REQSENT && f->state != ACKRCVD && f->state != ACKSENT ){
+ /* Not currently negotiating - reset options */
+ if( f->callbacks->resetci )
+ (*f->callbacks->resetci)(f);
+ f->nakloops = 0;
+ }
+
+ if( !retransmit ){
+ /* New request - reset retransmission counter, use new ID */
+ f->retransmits = f->maxconfreqtransmits;
+ f->reqid = ++f->id;
+ }
+
+ f->seen_ack = 0;
+
+ /*
+ * Make up the request packet
+ */
+ outp = outpacket_buf + PPP_HDRLEN + HEADERLEN;
+ if( f->callbacks->cilen && f->callbacks->addci ){
+ cilen = (*f->callbacks->cilen)(f);
+ if( cilen > peer_mru[f->unit] - HEADERLEN )
+ cilen = peer_mru[f->unit] - HEADERLEN;
+ if (f->callbacks->addci)
+ (*f->callbacks->addci)(f, outp, &cilen);
+ } else
+ cilen = 0;
+
+ /* send the request to our peer */
+ fsm_sdata(f, CONFREQ, f->reqid, outp, cilen);
+
+ /* start the retransmit timer */
+ --f->retransmits;
+ TIMEOUT(fsm_timeout, f, f->timeouttime);
+}
+
+
+/*
+ * fsm_sdata - Send some data.
+ *
+ * Used for all packets sent to our peer by this module.
+ */
+void
+fsm_sdata(
+ fsm *f,
+ u_char code, u_char id,
+ u_char *data,
+ int datalen)
+{
+ u_char *outp;
+ int outlen;
+
+ /* Adjust length to be smaller than MTU */
+ outp = outpacket_buf;
+ if (datalen > peer_mru[f->unit] - HEADERLEN)
+ datalen = peer_mru[f->unit] - HEADERLEN;
+ if (datalen && data != outp + PPP_HDRLEN + HEADERLEN)
+ BCOPY(data, outp + PPP_HDRLEN + HEADERLEN, datalen);
+ outlen = datalen + HEADERLEN;
+ MAKEHEADER(outp, f->protocol);
+ PUTCHAR(code, outp);
+ PUTCHAR(id, outp);
+ PUTSHORT(outlen, outp);
+ output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);
+}
diff --git a/cpukit/pppd/fsm.h b/cpukit/pppd/fsm.h
new file mode 100644
index 0000000000..6b829516c6
--- /dev/null
+++ b/cpukit/pppd/fsm.h
@@ -0,0 +1,144 @@
+/*
+ * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+/*
+ * Packet header = Code, id, length.
+ */
+#define HEADERLEN 4
+
+
+/*
+ * CP (LCP, IPCP, etc.) codes.
+ */
+#define CONFREQ 1 /* Configuration Request */
+#define CONFACK 2 /* Configuration Ack */
+#define CONFNAK 3 /* Configuration Nak */
+#define CONFREJ 4 /* Configuration Reject */
+#define TERMREQ 5 /* Termination Request */
+#define TERMACK 6 /* Termination Ack */
+#define CODEREJ 7 /* Code Reject */
+
+
+/*
+ * Each FSM is described by an fsm structure and fsm callbacks.
+ */
+typedef struct fsm {
+ int unit; /* Interface unit number */
+ int protocol; /* Data Link Layer Protocol field value */
+ int state; /* State */
+ int flags; /* Contains option bits */
+ u_char id; /* Current id */
+ u_char reqid; /* Current request id */
+ u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
+ int timeouttime; /* Timeout time in milliseconds */
+ int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
+ int retransmits; /* Number of retransmissions left */
+ int maxtermtransmits; /* Maximum Terminate-Request transmissions */
+ int nakloops; /* Number of nak loops since last ack */
+ int maxnakloops; /* Maximum number of nak loops tolerated */
+ struct fsm_callbacks *callbacks; /* Callback routines */
+ char *term_reason; /* Reason for closing protocol */
+ int term_reason_len; /* Length of term_reason */
+} fsm;
+
+
+typedef struct fsm_callbacks {
+ void (*resetci) /* Reset our Configuration Information */
+ (fsm *);
+ int (*cilen) /* Length of our Configuration Information */
+ (fsm *);
+ void (*addci) /* Add our Configuration Information */
+ (fsm *, u_char *, int *);
+ int (*ackci) /* ACK our Configuration Information */
+ (fsm *, u_char *, int);
+ int (*nakci) /* NAK our Configuration Information */
+ (fsm *, u_char *, int);
+ int (*rejci) /* Reject our Configuration Information */
+ (fsm *, u_char *, int);
+ int (*reqci) /* Request peer's Configuration Information */
+ (fsm *, u_char *, int *, int);
+ void (*up) /* Called when fsm reaches OPENED state */
+ (fsm *);
+ void (*down) /* Called when fsm leaves OPENED state */
+ (fsm *);
+ void (*starting) /* Called when we want the lower layer */
+ (fsm *);
+ void (*finished) /* Called when we don't want the lower layer */
+ (fsm *);
+ void (*protreject) /* Called when Protocol-Reject received */
+ (int);
+ void (*retransmit) /* Retransmission is necessary */
+ (fsm *);
+ int (*extcode) /* Called when unknown code received */
+ (fsm *, int, int, u_char *, int);
+ char *proto_name; /* String name for protocol (for messages) */
+} fsm_callbacks;
+
+
+/*
+ * Link states.
+ */
+#define INITIAL 0 /* Down, hasn't been opened */
+#define STARTING 1 /* Down, been opened */
+#define CLOSED 2 /* Up, hasn't been opened */
+#define STOPPED 3 /* Open, waiting for down event */
+#define CLOSING 4 /* Terminating the connection, not open */
+#define STOPPING 5 /* Terminating, but open */
+#define REQSENT 6 /* We've sent a Config Request */
+#define ACKRCVD 7 /* We've received a Config Ack */
+#define ACKSENT 8 /* We've sent a Config Ack */
+#define OPENED 9 /* Connection available */
+
+
+/*
+ * Flags - indicate options controlling FSM operation
+ */
+#define OPT_PASSIVE 1 /* Don't die if we don't get a response */
+#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
+#define OPT_SILENT 4 /* Wait for peer to speak first */
+
+
+/*
+ * Timeouts.
+ */
+#define DEFTIMEOUT 5 /* Timeout time in seconds */
+#define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
+#define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
+#define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
+
+
+/*
+ * Prototypes
+ */
+void fsm_init(fsm *);
+void fsm_lowerup(fsm *);
+void fsm_lowerdown(fsm *);
+void fsm_open(fsm *);
+void fsm_close(fsm *, char *);
+void fsm_input(fsm *, u_char *, int);
+void fsm_protreject(fsm *);
+void fsm_sdata(fsm *, u_char, u_char, u_char *, int);
+
+
+/*
+ * Variables
+ */
+extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
diff --git a/cpukit/pppd/ipcp.c b/cpukit/pppd/ipcp.c
new file mode 100644
index 0000000000..ae8f15ba7c
--- /dev/null
+++ b/cpukit/pppd/ipcp.c
@@ -0,0 +1,1772 @@
+/*
+ * ipcp.c - PPP IP Control Protocol.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+/*
+ * TODO:
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <resolv.h>
+
+#include "pppd.h"
+#include "fsm.h"
+#include "ipcp.h"
+#include "pathnames.h"
+
+#include <rtems/bsdnet/servers.h>
+
+static const char rcsid[] = RCSID;
+
+/* global vars */
+ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
+ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
+ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
+ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
+
+bool disable_defaultip = 0; /* Don't use hostname for default IP adrs */
+
+/* Hook for a plugin to know when IP protocol has come up */
+void (*ip_up_hook)(void) = NULL;
+
+/* Hook for a plugin to know when IP protocol has come down */
+void (*ip_down_hook)(void) = NULL;
+
+/* local vars */
+static int default_route_set[NUM_PPP]; /* Have set up a default route */
+static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
+static bool usepeerdns; /* Ask peer for DNS addrs */
+static int ipcp_is_up; /* have called np_up() */
+
+/*
+ * Callbacks for fsm code. (CI = Configuration Information)
+ */
+static void ipcp_resetci(fsm *); /* Reset our CI */
+static int ipcp_cilen(fsm *); /* Return length of our CI */
+static void ipcp_addci(fsm *, u_char *, int *); /* Add our CI */
+static int ipcp_ackci(fsm *, u_char *, int); /* Peer ack'd our CI */
+static int ipcp_nakci(fsm *, u_char *, int); /* Peer nak'd our CI */
+static int ipcp_rejci(fsm *, u_char *, int); /* Peer rej'd our CI */
+static int ipcp_reqci(fsm *, u_char *, int *, int); /* Rcv CI */
+static void ipcp_up(fsm *); /* We're UP */
+static void ipcp_down(fsm *); /* We're DOWN */
+static void ipcp_finished(fsm *); /* Don't need lower layer */
+
+fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
+
+static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
+ ipcp_resetci, /* Reset our Configuration Information */
+ ipcp_cilen, /* Length of our Configuration Information */
+ ipcp_addci, /* Add our Configuration Information */
+ ipcp_ackci, /* ACK our Configuration Information */
+ ipcp_nakci, /* NAK our Configuration Information */
+ ipcp_rejci, /* Reject our Configuration Information */
+ ipcp_reqci, /* Request peer's Configuration Information */
+ ipcp_up, /* Called when fsm reaches OPENED state */
+ ipcp_down, /* Called when fsm leaves OPENED state */
+ NULL, /* Called when we want the lower layer up */
+ ipcp_finished, /* Called when we want the lower layer down */
+ NULL, /* Called when Protocol-Reject received */
+ NULL, /* Retransmission is necessary */
+ NULL, /* Called to handle protocol-specific codes */
+ "IPCP" /* String name of protocol */
+};
+
+/*
+ * Command-line options.
+ */
+static int setvjslots(char **);
+static int setdnsaddr(char **);
+static int setwinsaddr(char **);
+
+static option_t ipcp_option_list[] = {
+ { "noip", o_bool, &ipcp_protent.enabled_flag,
+ "Disable IP and IPCP", 0, NULL, 0, 0 },
+ { "-ip", o_bool, &ipcp_protent.enabled_flag,
+ "Disable IP and IPCP", 0, NULL, 0, 0 },
+ { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
+ "Disable VJ compression", OPT_A2COPY,
+ &ipcp_allowoptions[0].neg_vj, 0, 0 },
+ { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
+ "Disable VJ compression", OPT_A2COPY,
+ &ipcp_allowoptions[0].neg_vj, 0, 0 },
+ { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
+ "Disable VJ connection-ID compression", OPT_A2COPY,
+ &ipcp_allowoptions[0].cflag, 0, 0 },
+ { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
+ "Disable VJ connection-ID compression", OPT_A2COPY,
+ &ipcp_allowoptions[0].cflag, 0, 0 },
+ { "vj-max-slots", 1, setvjslots,
+ "Set maximum VJ header slots", 0, NULL, 0, 0 },
+ { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
+ "Accept peer's address for us", 1, NULL, 0, 0 },
+ { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
+ "Accept peer's address for it", 1, NULL, 0, 0 },
+ { "ipparam", o_string, &ipparam,
+ "Set ip script parameter", 0, NULL, 0, 0 },
+ { "noipdefault", o_bool, &disable_defaultip,
+ "Don't use name for default IP adrs", 1, NULL, 0, 0 },
+ { "ms-dns", 1, setdnsaddr,
+ "DNS address for the peer's use", 0, NULL, 0, 0 },
+ { "ms-wins", 1, setwinsaddr,
+ "Nameserver for SMB over TCP/IP for peer", 0, NULL, 0, 0 },
+ { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
+ "Set timeout for IPCP", 0, NULL, 0, 0 },
+ { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
+ "Set max #xmits for term-reqs", 0, NULL, 0, 0 },
+ { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
+ "Set max #xmits for conf-reqs", 0, NULL, 0, 0 },
+ { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
+ "Set max #conf-naks for IPCP", 0, NULL, 0, 0 },
+ { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
+ "Add default route", OPT_ENABLE|1,
+ &ipcp_allowoptions[0].default_route, 0, 0 },
+ { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
+ "disable defaultroute option", OPT_A2COPY,
+ &ipcp_wantoptions[0].default_route, 0, 0 },
+ { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
+ "disable defaultroute option", OPT_A2COPY,
+ &ipcp_wantoptions[0].default_route, 0, 0 },
+ { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
+ "Add proxy ARP entry", OPT_ENABLE|1,
+ &ipcp_allowoptions[0].proxy_arp, 0, 0 },
+ { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
+ "disable proxyarp option", OPT_A2COPY,
+ &ipcp_wantoptions[0].proxy_arp, 0, 0 },
+ { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
+ "disable proxyarp option", OPT_A2COPY,
+ &ipcp_wantoptions[0].proxy_arp, 0, 0 },
+ { "usepeerdns", o_bool, &usepeerdns,
+ "Ask peer for DNS address(es)", 1, NULL, 0, 0 },
+ { NULL, 0, NULL, NULL, 0, NULL, 0, 0 }
+};
+
+/*
+ * Protocol entry points from main code.
+ */
+static void ipcp_init(int);
+static void ipcp_open(int);
+static void ipcp_close(int, char *);
+static void ipcp_lowerup(int);
+static void ipcp_lowerdown(int);
+static void ipcp_input(int, u_char *, int);
+static void ipcp_protrej(int);
+static int ipcp_printpkt(u_char *, int,
+ void (*)(void *, char *, ...), void *);
+static void ip_check_options(void);
+static int ip_demand_conf(int);
+static int ip_active_pkt(u_char *, int);
+static void create_resolv(uint32_t, uint32_t);
+
+struct protent ipcp_protent = {
+ PPP_IPCP,
+ ipcp_init,
+ ipcp_input,
+ ipcp_protrej,
+ ipcp_lowerup,
+ ipcp_lowerdown,
+ ipcp_open,
+ ipcp_close,
+ ipcp_printpkt,
+ NULL,
+ 1,
+ "IPCP",
+ "IP",
+ ipcp_option_list,
+ ip_check_options,
+ ip_demand_conf,
+ ip_active_pkt
+};
+
+static void ipcp_clear_addrs(int, uint32_t, uint32_t);
+
+/*
+ * Lengths of configuration options.
+ */
+#define CILEN_VOID 2
+#define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
+#define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
+#define CILEN_ADDR 6 /* new-style single address option */
+#define CILEN_ADDRS 10 /* old-style dual address option */
+
+
+#define CODENAME(x) ((x) == CONFACK ? "ACK" : \
+ (x) == CONFNAK ? "NAK" : "REJ")
+
+/*
+ * Make a string representation of a network IP address.
+ */
+char *
+ip_ntoa(
+ uint32_t ipaddr)
+{
+ static char b[64];
+
+ slprintf(b, sizeof(b), "%I", ipaddr);
+ return b;
+}
+
+/*
+ * Option parsing.
+ */
+
+/*
+ * setvjslots - set maximum number of connection slots for VJ compression
+ */
+static int
+setvjslots(
+ char **argv)
+{
+ int value;
+
+ if (!int_option(*argv, &value))
+ return 0;
+ if (value < 2 || value > 16) {
+ option_error("vj-max-slots value must be between 2 and 16");
+ return 0;
+ }
+ ipcp_wantoptions [0].maxslotindex =
+ ipcp_allowoptions[0].maxslotindex = value - 1;
+ return 1;
+}
+
+/*
+ * setdnsaddr - set the dns address(es)
+ */
+static int
+setdnsaddr(
+ char **argv)
+{
+ uint32_t dns;
+ struct hostent *hp;
+
+ dns = inet_addr(*argv);
+ if (dns == (uint32_t) -1) {
+ if ((hp = gethostbyname(*argv)) == NULL) {
+ option_error("invalid address parameter '%s' for ms-dns option",
+ *argv);
+ return 0;
+ }
+ dns = *(uint32_t *)hp->h_addr;
+ }
+
+ /* if there is no primary then update it. */
+ if (ipcp_allowoptions[0].dnsaddr[0] == 0)
+ ipcp_allowoptions[0].dnsaddr[0] = dns;
+
+ /* always set the secondary address value to the same value. */
+ ipcp_allowoptions[0].dnsaddr[1] = dns;
+
+ return (1);
+}
+
+/*
+ * setwinsaddr - set the wins address(es)
+ * This is primrarly used with the Samba package under UNIX or for pointing
+ * the caller to the existing WINS server on a Windows NT platform.
+ */
+static int
+setwinsaddr(
+ char **argv)
+{
+ uint32_t wins;
+ struct hostent *hp;
+
+ wins = inet_addr(*argv);
+ if (wins == (uint32_t) -1) {
+ if ((hp = gethostbyname(*argv)) == NULL) {
+ option_error("invalid address parameter '%s' for ms-wins option",
+ *argv);
+ return 0;
+ }
+ wins = *(uint32_t *)hp->h_addr;
+ }
+
+ /* if there is no primary then update it. */
+ if (ipcp_allowoptions[0].winsaddr[0] == 0)
+ ipcp_allowoptions[0].winsaddr[0] = wins;
+
+ /* always set the secondary address value to the same value. */
+ ipcp_allowoptions[0].winsaddr[1] = wins;
+
+ return (1);
+}
+
+
+/*
+ * ipcp_init - Initialize IPCP.
+ */
+static void
+ipcp_init(
+ int unit)
+{
+ fsm *f = &ipcp_fsm[unit];
+ ipcp_options *wo = &ipcp_wantoptions[unit];
+ ipcp_options *ao = &ipcp_allowoptions[unit];
+
+ f->unit = unit;
+ f->protocol = PPP_IPCP;
+ f->callbacks = &ipcp_callbacks;
+ fsm_init(&ipcp_fsm[unit]);
+
+ memset(wo, 0, sizeof(*wo));
+ memset(ao, 0, sizeof(*ao));
+
+ wo->neg_addr = 1;
+ wo->neg_vj = 1;
+ wo->vj_protocol = IPCP_VJ_COMP;
+ wo->maxslotindex = MAX_STATES - 1; /* really max index */
+ wo->cflag = 1;
+
+ /* max slots and slot-id compression are currently hardwired in */
+ /* ppp_if.c to 16 and 1, this needs to be changed (among other */
+ /* things) gmc */
+
+ ao->neg_addr = 1;
+ ao->neg_vj = 1;
+ ao->maxslotindex = MAX_STATES - 1;
+ ao->cflag = 1;
+
+ /*
+ * XXX These control whether the user may use the proxyarp
+ * and defaultroute options.
+ */
+ ao->proxy_arp = 1;
+ ao->default_route = 1;
+}
+
+
+/*
+ * ipcp_open - IPCP is allowed to come up.
+ */
+static void
+ipcp_open(
+ int unit)
+{
+ fsm_open(&ipcp_fsm[unit]);
+}
+
+
+/*
+ * ipcp_close - Take IPCP down.
+ */
+static void
+ipcp_close(
+ int unit,
+ char *reason)
+{
+ fsm_close(&ipcp_fsm[unit], reason);
+}
+
+
+/*
+ * ipcp_lowerup - The lower layer is up.
+ */
+static void
+ipcp_lowerup(
+ int unit)
+{
+ fsm_lowerup(&ipcp_fsm[unit]);
+}
+
+
+/*
+ * ipcp_lowerdown - The lower layer is down.
+ */
+static void
+ipcp_lowerdown(
+ int unit)
+{
+ fsm_lowerdown(&ipcp_fsm[unit]);
+}
+
+
+/*
+ * ipcp_input - Input IPCP packet.
+ */
+static void
+ipcp_input(
+ int unit,
+ u_char *p,
+ int len)
+{
+ fsm_input(&ipcp_fsm[unit], p, len);
+}
+
+
+/*
+ * ipcp_protrej - A Protocol-Reject was received for IPCP.
+ *
+ * Pretend the lower layer went down, so we shut up.
+ */
+static void
+ipcp_protrej(
+ int unit)
+{
+ fsm_lowerdown(&ipcp_fsm[unit]);
+}
+
+
+/*
+ * ipcp_resetci - Reset our CI.
+ * Called by fsm_sconfreq, Send Configure Request.
+ */
+static void
+ipcp_resetci(
+ fsm *f)
+{
+ ipcp_options *wo = &ipcp_wantoptions[f->unit];
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+
+ wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
+ if (wo->ouraddr == 0 || disable_defaultip)
+ wo->accept_local = 1;
+ if (wo->hisaddr == 0)
+ wo->accept_remote = 1;
+ wo->req_dns1 = usepeerdns; /* Request DNS addresses from the peer */
+ wo->req_dns2 = usepeerdns;
+ *go = *wo;
+ if (disable_defaultip)
+ go->ouraddr = 0;
+}
+
+
+/*
+ * ipcp_cilen - Return length of our CI.
+ * Called by fsm_sconfreq, Send Configure Request.
+ */
+static int
+ipcp_cilen(
+ fsm *f)
+{
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ ipcp_options *wo = &ipcp_wantoptions[f->unit];
+ ipcp_options *ho = &ipcp_hisoptions[f->unit];
+
+#define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
+#define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
+#define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
+
+ /*
+ * First see if we want to change our options to the old
+ * forms because we have received old forms from the peer.
+ */
+ if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
+ /* use the old style of address negotiation */
+ go->neg_addr = 1;
+ go->old_addrs = 1;
+ }
+ if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
+ /* try an older style of VJ negotiation */
+ /* use the old style only if the peer did */
+ if (ho->neg_vj && ho->old_vj) {
+ go->neg_vj = 1;
+ go->old_vj = 1;
+ go->vj_protocol = ho->vj_protocol;
+ }
+ }
+
+ return (LENCIADDR(go->neg_addr, go->old_addrs) +
+ LENCIVJ(go->neg_vj, go->old_vj) +
+ LENCIDNS(go->req_dns1) +
+ LENCIDNS(go->req_dns2)) ;
+}
+
+
+/*
+ * ipcp_addci - Add our desired CIs to a packet.
+ * Called by fsm_sconfreq, Send Configure Request.
+ */
+static void
+ipcp_addci(
+ fsm *f,
+ u_char *ucp,
+ int *lenp)
+{
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ int len = *lenp;
+
+#define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
+ if (neg) { \
+ int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
+ if (len >= vjlen) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(vjlen, ucp); \
+ PUTSHORT(val, ucp); \
+ if (!old) { \
+ PUTCHAR(maxslotindex, ucp); \
+ PUTCHAR(cflag, ucp); \
+ } \
+ len -= vjlen; \
+ } else \
+ neg = 0; \
+ }
+
+#define ADDCIADDR(opt, neg, old, val1, val2) \
+ if (neg) { \
+ int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
+ if (len >= addrlen) { \
+ uint32_t l; \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(addrlen, ucp); \
+ l = ntohl(val1); \
+ PUTLONG(l, ucp); \
+ if (old) { \
+ l = ntohl(val2); \
+ PUTLONG(l, ucp); \
+ } \
+ len -= addrlen; \
+ } else \
+ neg = 0; \
+ }
+
+#define ADDCIDNS(opt, neg, addr) \
+ if (neg) { \
+ if (len >= CILEN_ADDR) { \
+ uint32_t l; \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_ADDR, ucp); \
+ l = ntohl(addr); \
+ PUTLONG(l, ucp); \
+ len -= CILEN_ADDR; \
+ } else \
+ neg = 0; \
+ }
+
+ ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
+ go->old_addrs, go->ouraddr, go->hisaddr);
+
+ ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
+ go->maxslotindex, go->cflag);
+
+ ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
+
+ ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
+
+ *lenp -= len;
+}
+
+
+/*
+ * ipcp_ackci - Ack our CIs.
+ * Called by fsm_rconfack, Receive Configure ACK.
+ *
+ * Returns:
+ * 0 - Ack was bad.
+ * 1 - Ack was good.
+ */
+static int
+ipcp_ackci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ u_short cilen, citype, cishort;
+ uint32_t cilong;
+ u_char cimaxslotindex, cicflag;
+
+ /*
+ * CIs must be in exactly the same order that we sent...
+ * Check packet length and CI length at each step.
+ * If we find any deviations, then this packet is bad.
+ */
+
+#define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
+ if (neg) { \
+ int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
+ if ((len -= vjlen) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != vjlen || \
+ citype != opt) \
+ goto bad; \
+ GETSHORT(cishort, p); \
+ if (cishort != val) \
+ goto bad; \
+ if (!old) { \
+ GETCHAR(cimaxslotindex, p); \
+ if (cimaxslotindex != maxslotindex) \
+ goto bad; \
+ GETCHAR(cicflag, p); \
+ if (cicflag != cflag) \
+ goto bad; \
+ } \
+ }
+
+#define ACKCIADDR(opt, neg, old, val1, val2) \
+ if (neg) { \
+ int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
+ uint32_t l; \
+ if ((len -= addrlen) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != addrlen || \
+ citype != opt) \
+ goto bad; \
+ GETLONG(l, p); \
+ cilong = htonl(l); \
+ if (val1 != cilong) \
+ goto bad; \
+ if (old) { \
+ GETLONG(l, p); \
+ cilong = htonl(l); \
+ if (val2 != cilong) \
+ goto bad; \
+ } \
+ }
+
+#define ACKCIDNS(opt, neg, addr) \
+ if (neg) { \
+ uint32_t l; \
+ if ((len -= CILEN_ADDR) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_ADDR || citype != opt) \
+ goto bad; \
+ GETLONG(l, p); \
+ cilong = htonl(l); \
+ if (addr != cilong) \
+ goto bad; \
+ }
+
+ ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
+ go->old_addrs, go->ouraddr, go->hisaddr);
+
+ ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
+ go->maxslotindex, go->cflag);
+
+ ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
+
+ ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
+
+ /*
+ * If there are any remaining CIs, then this packet is bad.
+ */
+ if (len != 0)
+ goto bad;
+ return (1);
+
+bad:
+ IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
+ return (0);
+}
+
+/*
+ * ipcp_nakci - Peer has sent a NAK for some of our CIs.
+ * This should not modify any state if the Nak is bad
+ * or if IPCP is in the OPENED state.
+ * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
+ *
+ * Returns:
+ * 0 - Nak was bad.
+ * 1 - Nak was good.
+ */
+static int
+ipcp_nakci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ u_char cimaxslotindex, cicflag;
+ u_char citype, cilen, *next;
+ u_short cishort;
+ uint32_t ciaddr1, ciaddr2, l, cidnsaddr;
+ ipcp_options no; /* options we've seen Naks for */
+ ipcp_options try; /* options to request next time */
+
+ BZERO(&no, sizeof(no));
+ try = *go;
+
+ /*
+ * Any Nak'd CIs must be in exactly the same order that we sent.
+ * Check packet length and CI length at each step.
+ * If we find any deviations, then this packet is bad.
+ */
+#define NAKCIADDR(opt, neg, old, code) \
+ if (go->neg && \
+ len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
+ p[1] == cilen && \
+ p[0] == opt) { \
+ len -= cilen; \
+ INCPTR(2, p); \
+ GETLONG(l, p); \
+ ciaddr1 = htonl(l); \
+ if (old) { \
+ GETLONG(l, p); \
+ ciaddr2 = htonl(l); \
+ no.old_addrs = 1; \
+ } else \
+ ciaddr2 = 0; \
+ no.neg = 1; \
+ code \
+ }
+
+#define NAKCIVJ(opt, neg, code) \
+ if (go->neg && \
+ ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
+ len >= cilen && \
+ p[0] == opt) { \
+ len -= cilen; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ no.neg = 1; \
+ code \
+ }
+
+#define NAKCIDNS(opt, neg, code) \
+ if (go->neg && \
+ ((cilen = p[1]) == CILEN_ADDR) && \
+ len >= cilen && \
+ p[0] == opt) { \
+ len -= cilen; \
+ INCPTR(2, p); \
+ GETLONG(l, p); \
+ cidnsaddr = htonl(l); \
+ no.neg = 1; \
+ code \
+ }
+
+ /*
+ * Accept the peer's idea of {our,his} address, if different
+ * from our idea, only if the accept_{local,remote} flag is set.
+ */
+ NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
+ if (go->accept_local && ciaddr1) { /* Do we know our address? */
+ try.ouraddr = ciaddr1;
+ }
+ if (go->accept_remote && ciaddr2) { /* Does he know his? */
+ try.hisaddr = ciaddr2;
+ }
+ );
+
+ /*
+ * Accept the peer's value of maxslotindex provided that it
+ * is less than what we asked for. Turn off slot-ID compression
+ * if the peer wants. Send old-style compress-type option if
+ * the peer wants.
+ */
+ NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
+ if (cilen == CILEN_VJ) {
+ GETCHAR(cimaxslotindex, p);
+ GETCHAR(cicflag, p);
+ if (cishort == IPCP_VJ_COMP) {
+ try.old_vj = 0;
+ if (cimaxslotindex < go->maxslotindex)
+ try.maxslotindex = cimaxslotindex;
+ if (!cicflag)
+ try.cflag = 0;
+ } else {
+ try.neg_vj = 0;
+ }
+ } else {
+ if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
+ try.old_vj = 1;
+ try.vj_protocol = cishort;
+ } else {
+ try.neg_vj = 0;
+ }
+ }
+ );
+
+ NAKCIDNS(CI_MS_DNS1, req_dns1,
+ try.dnsaddr[0] = cidnsaddr;
+ );
+
+ NAKCIDNS(CI_MS_DNS2, req_dns2,
+ try.dnsaddr[1] = cidnsaddr;
+ );
+
+ /*
+ * There may be remaining CIs, if the peer is requesting negotiation
+ * on an option that we didn't include in our request packet.
+ * If they want to negotiate about IP addresses, we comply.
+ * If they want us to ask for compression, we refuse.
+ */
+ while (len > CILEN_VOID) {
+ GETCHAR(citype, p);
+ GETCHAR(cilen, p);
+ if( (len -= cilen) < 0 )
+ goto bad;
+ next = p + cilen - 2;
+
+ switch (citype) {
+ case CI_COMPRESSTYPE:
+ if (go->neg_vj || no.neg_vj ||
+ (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
+ goto bad;
+ no.neg_vj = 1;
+ break;
+ case CI_ADDRS:
+ if ((go->neg_addr && go->old_addrs) || no.old_addrs
+ || cilen != CILEN_ADDRS)
+ goto bad;
+ try.neg_addr = 1;
+ try.old_addrs = 1;
+ GETLONG(l, p);
+ ciaddr1 = htonl(l);
+ if (ciaddr1 && go->accept_local)
+ try.ouraddr = ciaddr1;
+ GETLONG(l, p);
+ ciaddr2 = htonl(l);
+ if (ciaddr2 && go->accept_remote)
+ try.hisaddr = ciaddr2;
+ no.old_addrs = 1;
+ break;
+ case CI_ADDR:
+ if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
+ goto bad;
+ try.old_addrs = 0;
+ GETLONG(l, p);
+ ciaddr1 = htonl(l);
+ if (ciaddr1 && go->accept_local)
+ try.ouraddr = ciaddr1;
+ if (try.ouraddr != 0)
+ try.neg_addr = 1;
+ no.neg_addr = 1;
+ break;
+ }
+ p = next;
+ }
+
+ /*
+ * OK, the Nak is good. Now we can update state.
+ * If there are any remaining options, we ignore them.
+ */
+ if (f->state != OPENED)
+ *go = try;
+
+ return 1;
+
+bad:
+ IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
+ return 0;
+}
+
+
+/*
+ * ipcp_rejci - Reject some of our CIs.
+ * Callback from fsm_rconfnakrej.
+ */
+static int
+ipcp_rejci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ u_char cimaxslotindex, ciflag, cilen;
+ u_short cishort;
+ uint32_t cilong;
+ ipcp_options try; /* options to request next time */
+
+ try = *go;
+ /*
+ * Any Rejected CIs must be in exactly the same order that we sent.
+ * Check packet length and CI length at each step.
+ * If we find any deviations, then this packet is bad.
+ */
+#define REJCIADDR(opt, neg, old, val1, val2) \
+ if (go->neg && \
+ len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
+ p[1] == cilen && \
+ p[0] == opt) { \
+ uint32_t l; \
+ len -= cilen; \
+ INCPTR(2, p); \
+ GETLONG(l, p); \
+ cilong = htonl(l); \
+ /* Check rejected value. */ \
+ if (cilong != val1) \
+ goto bad; \
+ if (old) { \
+ GETLONG(l, p); \
+ cilong = htonl(l); \
+ /* Check rejected value. */ \
+ if (cilong != val2) \
+ goto bad; \
+ } \
+ try.neg = 0; \
+ }
+
+#define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
+ if (go->neg && \
+ p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
+ len >= p[1] && \
+ p[0] == opt) { \
+ len -= p[1]; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ /* Check rejected value. */ \
+ if (cishort != val) \
+ goto bad; \
+ if (!old) { \
+ GETCHAR(cimaxslotindex, p); \
+ if (cimaxslotindex != maxslot) \
+ goto bad; \
+ GETCHAR(ciflag, p); \
+ if (ciflag != cflag) \
+ goto bad; \
+ } \
+ try.neg = 0; \
+ }
+
+#define REJCIDNS(opt, neg, dnsaddr) \
+ if (go->neg && \
+ ((cilen = p[1]) == CILEN_ADDR) && \
+ len >= cilen && \
+ p[0] == opt) { \
+ uint32_t l; \
+ len -= cilen; \
+ INCPTR(2, p); \
+ GETLONG(l, p); \
+ cilong = htonl(l); \
+ /* Check rejected value. */ \
+ if (cilong != dnsaddr) \
+ goto bad; \
+ try.neg = 0; \
+ }
+
+
+ REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
+ go->old_addrs, go->ouraddr, go->hisaddr);
+
+ REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
+ go->maxslotindex, go->cflag);
+
+ REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
+
+ REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
+
+ /*
+ * If there are any remaining CIs, then this packet is bad.
+ */
+ if (len != 0)
+ goto bad;
+ /*
+ * Now we can update state.
+ */
+ if (f->state != OPENED)
+ *go = try;
+ return 1;
+
+bad:
+ IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
+ return 0;
+}
+
+
+/*
+ * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
+ * Callback from fsm_rconfreq, Receive Configure Request
+ *
+ * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
+ * appropriately. If reject_if_disagree is non-zero, doesn't return
+ * CONFNAK; returns CONFREJ if it can't return CONFACK.
+ */
+static int
+ipcp_reqci(
+ fsm *f,
+ u_char *inp, /* Requested CIs */
+ int *len, /* Length of requested CIs */
+ int reject_if_disagree)
+{
+ ipcp_options *wo = &ipcp_wantoptions[f->unit];
+ ipcp_options *ho = &ipcp_hisoptions[f->unit];
+ ipcp_options *ao = &ipcp_allowoptions[f->unit];
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ u_char *cip, *next; /* Pointer to current and next CIs */
+ u_short cilen, citype; /* Parsed len, type */
+ u_short cishort; /* Parsed short value */
+ uint32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
+ int rc = CONFACK; /* Final packet return code */
+ int orc; /* Individual option return code */
+ u_char *p; /* Pointer to next char to parse */
+ u_char *ucp = inp; /* Pointer to current output char */
+ int l = *len; /* Length left */
+ u_char maxslotindex, cflag;
+ int d;
+
+ /*
+ * Reset all his options.
+ */
+ BZERO(ho, sizeof(*ho));
+
+ /*
+ * Process all his options.
+ */
+ next = inp;
+ while (l) {
+ orc = CONFACK; /* Assume success */
+ cip = p = next; /* Remember begining of CI */
+ if (l < 2 || /* Not enough data for CI header or */
+ p[1] < 2 || /* CI length too small or */
+ p[1] > l) { /* CI length too big? */
+ IPCPDEBUG(("ipcp_reqci: bad CI length!"));
+ orc = CONFREJ; /* Reject bad CI */
+ cilen = l; /* Reject till end of packet */
+ l = 0; /* Don't loop again */
+ goto endswitch;
+ }
+ GETCHAR(citype, p); /* Parse CI type */
+ GETCHAR(cilen, p); /* Parse CI length */
+ l -= cilen; /* Adjust remaining length */
+ next += cilen; /* Step to next CI */
+
+ switch (citype) { /* Check CI type */
+ case CI_ADDRS:
+ if (!ao->neg_addr ||
+ cilen != CILEN_ADDRS) { /* Check CI length */
+ orc = CONFREJ; /* Reject CI */
+ break;
+ }
+
+ /*
+ * If he has no address, or if we both have his address but
+ * disagree about it, then NAK it with our idea.
+ * In particular, if we don't know his address, but he does,
+ * then accept it.
+ */
+ GETLONG(tl, p); /* Parse source address (his) */
+ ciaddr1 = htonl(tl);
+ if (ciaddr1 != wo->hisaddr
+ && (ciaddr1 == 0 || !wo->accept_remote)) {
+ orc = CONFNAK;
+ if (!reject_if_disagree) {
+ DECPTR(sizeof(uint32_t), p);
+ tl = ntohl(wo->hisaddr);
+ PUTLONG(tl, p);
+ }
+ } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
+ /*
+ * If neither we nor he knows his address, reject the option.
+ */
+ orc = CONFREJ;
+ wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
+ break;
+ }
+
+ /*
+ * If he doesn't know our address, or if we both have our address
+ * but disagree about it, then NAK it with our idea.
+ */
+ GETLONG(tl, p); /* Parse desination address (ours) */
+ ciaddr2 = htonl(tl);
+ if (ciaddr2 != wo->ouraddr) {
+ if (ciaddr2 == 0 || !wo->accept_local) {
+ orc = CONFNAK;
+ if (!reject_if_disagree) {
+ DECPTR(sizeof(uint32_t), p);
+ tl = ntohl(wo->ouraddr);
+ PUTLONG(tl, p);
+ }
+ } else {
+ go->ouraddr = ciaddr2; /* accept peer's idea */
+ }
+ }
+
+ ho->neg_addr = 1;
+ ho->old_addrs = 1;
+ ho->hisaddr = ciaddr1;
+ ho->ouraddr = ciaddr2;
+ break;
+
+ case CI_ADDR:
+ if (!ao->neg_addr ||
+ cilen != CILEN_ADDR) { /* Check CI length */
+ orc = CONFREJ; /* Reject CI */
+ break;
+ }
+
+ /*
+ * If he has no address, or if we both have his address but
+ * disagree about it, then NAK it with our idea.
+ * In particular, if we don't know his address, but he does,
+ * then accept it.
+ */
+ GETLONG(tl, p); /* Parse source address (his) */
+ ciaddr1 = htonl(tl);
+ if (ciaddr1 != wo->hisaddr
+ && (ciaddr1 == 0 || !wo->accept_remote)) {
+ orc = CONFNAK;
+ if (!reject_if_disagree) {
+ DECPTR(sizeof(uint32_t), p);
+ tl = ntohl(wo->hisaddr);
+ PUTLONG(tl, p);
+ }
+ } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
+ /*
+ * Don't ACK an address of 0.0.0.0 - reject it instead.
+ */
+ orc = CONFREJ;
+ wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
+ break;
+ }
+
+ ho->neg_addr = 1;
+ ho->hisaddr = ciaddr1;
+ break;
+
+ case CI_MS_DNS1:
+ case CI_MS_DNS2:
+ /* Microsoft primary or secondary DNS request */
+ d = citype == CI_MS_DNS2;
+
+ /* If we do not have a DNS address then we cannot send it */
+ if (ao->dnsaddr[d] == 0 ||
+ cilen != CILEN_ADDR) { /* Check CI length */
+ orc = CONFREJ; /* Reject CI */
+ break;
+ }
+ GETLONG(tl, p);
+ if (htonl(tl) != ao->dnsaddr[d]) {
+ DECPTR(sizeof(uint32_t), p);
+ tl = ntohl(ao->dnsaddr[d]);
+ PUTLONG(tl, p);
+ orc = CONFNAK;
+ }
+ break;
+
+ case CI_MS_WINS1:
+ case CI_MS_WINS2:
+ /* Microsoft primary or secondary WINS request */
+ d = citype == CI_MS_WINS2;
+
+ /* If we do not have a DNS address then we cannot send it */
+ if (ao->winsaddr[d] == 0 ||
+ cilen != CILEN_ADDR) { /* Check CI length */
+ orc = CONFREJ; /* Reject CI */
+ break;
+ }
+ GETLONG(tl, p);
+ if (htonl(tl) != ao->winsaddr[d]) {
+ DECPTR(sizeof(uint32_t), p);
+ tl = ntohl(ao->winsaddr[d]);
+ PUTLONG(tl, p);
+ orc = CONFNAK;
+ }
+ break;
+
+ case CI_COMPRESSTYPE:
+ if (!ao->neg_vj ||
+ (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
+ orc = CONFREJ;
+ break;
+ }
+ GETSHORT(cishort, p);
+
+ if (!(cishort == IPCP_VJ_COMP ||
+ (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
+ orc = CONFREJ;
+ break;
+ }
+
+ ho->neg_vj = 1;
+ ho->vj_protocol = cishort;
+ if (cilen == CILEN_VJ) {
+ GETCHAR(maxslotindex, p);
+ if (maxslotindex > ao->maxslotindex) {
+ orc = CONFNAK;
+ if (!reject_if_disagree){
+ DECPTR(1, p);
+ PUTCHAR(ao->maxslotindex, p);
+ }
+ }
+ GETCHAR(cflag, p);
+ if (cflag && !ao->cflag) {
+ orc = CONFNAK;
+ if (!reject_if_disagree){
+ DECPTR(1, p);
+ PUTCHAR(wo->cflag, p);
+ }
+ }
+ ho->maxslotindex = maxslotindex;
+ ho->cflag = cflag;
+ } else {
+ ho->old_vj = 1;
+ ho->maxslotindex = MAX_STATES - 1;
+ ho->cflag = 1;
+ }
+ break;
+
+ default:
+ orc = CONFREJ;
+ break;
+ }
+endswitch:
+ if (orc == CONFACK && /* Good CI */
+ rc != CONFACK) /* but prior CI wasnt? */
+ continue; /* Don't send this one */
+
+ if (orc == CONFNAK) { /* Nak this CI? */
+ if (reject_if_disagree) /* Getting fed up with sending NAKs? */
+ orc = CONFREJ; /* Get tough if so */
+ else {
+ if (rc == CONFREJ) /* Rejecting prior CI? */
+ continue; /* Don't send this one */
+ if (rc == CONFACK) { /* Ack'd all prior CIs? */
+ rc = CONFNAK; /* Not anymore... */
+ ucp = inp; /* Backup */
+ }
+ }
+ }
+
+ if (orc == CONFREJ && /* Reject this CI */
+ rc != CONFREJ) { /* but no prior ones? */
+ rc = CONFREJ;
+ ucp = inp; /* Backup */
+ }
+
+ /* Need to move CI? */
+ if (ucp != cip)
+ BCOPY(cip, ucp, cilen); /* Move it */
+
+ /* Update output pointer */
+ INCPTR(cilen, ucp);
+ }
+
+ /*
+ * If we aren't rejecting this packet, and we want to negotiate
+ * their address, and they didn't send their address, then we
+ * send a NAK with a CI_ADDR option appended. We assume the
+ * input buffer is long enough that we can append the extra
+ * option safely.
+ */
+ if (rc != CONFREJ && !ho->neg_addr &&
+ wo->req_addr && !reject_if_disagree) {
+ if (rc == CONFACK) {
+ rc = CONFNAK;
+ ucp = inp; /* reset pointer */
+ wo->req_addr = 0; /* don't ask again */
+ }
+ PUTCHAR(CI_ADDR, ucp);
+ PUTCHAR(CILEN_ADDR, ucp);
+ tl = ntohl(wo->hisaddr);
+ PUTLONG(tl, ucp);
+ }
+
+ *len = ucp - inp; /* Compute output length */
+ IPCPDEBUG(("ipcp: returning Configure-%s", CODENAME(rc)));
+ return (rc); /* Return final code */
+}
+
+
+/*
+ * ip_check_options - check that any IP-related options are OK,
+ * and assign appropriate defaults.
+ */
+static void
+ip_check_options(void)
+{
+ struct hostent *hp;
+ uint32_t local;
+ ipcp_options *wo = &ipcp_wantoptions[0];
+
+ /*
+ * Default our local IP address based on our hostname.
+ * If local IP address already given, don't bother.
+ */
+ if (wo->ouraddr == 0) {
+ /*
+ * Look up our hostname (possibly with domain name appended)
+ * and take the first IP address as our local IP address.
+ * If there isn't an IP address for our hostname, too bad.
+ */
+ wo->accept_local = 1; /* don't insist on this default value */
+ if ((hp = gethostbyname(hostname)) != NULL) {
+ local = *(uint32_t *)hp->h_addr;
+ if (local != 0 && !bad_ip_adrs(local))
+ wo->ouraddr = local;
+ }
+ }
+}
+
+
+/*
+ * ip_demand_conf - configure the interface as though
+ * IPCP were up, for use with dial-on-demand.
+ */
+static int
+ip_demand_conf(
+ int u)
+{
+ ipcp_options *wo = &ipcp_wantoptions[u];
+
+ if (wo->hisaddr == 0) {
+ /* make up an arbitrary address for the peer */
+ wo->hisaddr = htonl(0x0a707070 + pppifunit);
+ wo->accept_remote = 1;
+ }
+ if (wo->ouraddr == 0) {
+ /* make up an arbitrary address for us */
+ wo->ouraddr = htonl(0x0a404040 + pppifunit);
+ wo->accept_local = 1;
+ disable_defaultip = 1; /* don't tell the peer this address */
+ }
+ if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
+ return 0;
+ if (!sifup(u))
+ return 0;
+ if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
+ return 0;
+ if (wo->default_route)
+ if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
+ default_route_set[u] = 1;
+ if (wo->proxy_arp)
+ if (sifproxyarp(u, wo->hisaddr))
+ proxy_arp_set[u] = 1;
+
+ notice("local IP address %I", wo->ouraddr);
+ notice("remote IP address %I", wo->hisaddr);
+
+ return 1;
+}
+
+
+/*
+ * ipcp_up - IPCP has come UP.
+ *
+ * Configure the IP network interface appropriately and bring it up.
+ */
+static void
+ipcp_up(
+ fsm *f)
+{
+ uint32_t mask;
+ ipcp_options *ho = &ipcp_hisoptions[f->unit];
+ ipcp_options *go = &ipcp_gotoptions[f->unit];
+ ipcp_options *wo = &ipcp_wantoptions[f->unit];
+
+ IPCPDEBUG(("ipcp: up"));
+
+ /*
+ * We must have a non-zero IP address for both ends of the link.
+ */
+ if (!ho->neg_addr)
+ ho->hisaddr = wo->hisaddr;
+
+ if (ho->hisaddr == 0) {
+ error("Could not determine remote IP address");
+ ipcp_close(f->unit, "Could not determine remote IP address");
+ return;
+ }
+ if (go->ouraddr == 0) {
+ error("Could not determine local IP address");
+ ipcp_close(f->unit, "Could not determine local IP address");
+ return;
+ }
+
+ if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
+ create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
+ }
+
+ /*
+ * Check that the peer is allowed to use the IP address it wants.
+ */
+ if (!auth_ip_addr(f->unit, ho->hisaddr)) {
+ error("Peer is not authorized to use remote address %I", ho->hisaddr);
+ ipcp_close(f->unit, "Unauthorized remote IP address");
+ return;
+ }
+
+ /* set tcp compression */
+ sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
+
+ /*
+ * If we are doing dial-on-demand, the interface is already
+ * configured, so we put out any saved-up packets, then set the
+ * interface to pass IP packets.
+ */
+ if (demand) {
+ if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
+ ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
+ if (go->ouraddr != wo->ouraddr) {
+ warn("Local IP address changed to %I", go->ouraddr);
+ wo->ouraddr = go->ouraddr;
+ }
+ if (ho->hisaddr != wo->hisaddr) {
+ warn("Remote IP address changed to %I", ho->hisaddr);
+ wo->hisaddr = ho->hisaddr;
+ }
+
+ /* Set the interface to the new addresses */
+ mask = GetMask(go->ouraddr);
+ if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
+ if (debug)
+ warn("Interface configuration failed");
+ ipcp_close(f->unit, "Interface configuration failed");
+ return;
+ }
+
+ /* assign a default route through the interface if required */
+ if (ipcp_wantoptions[f->unit].default_route)
+ if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
+ default_route_set[f->unit] = 1;
+
+ /* Make a proxy ARP entry if requested. */
+ if (ipcp_wantoptions[f->unit].proxy_arp)
+ if (sifproxyarp(f->unit, ho->hisaddr))
+ proxy_arp_set[f->unit] = 1;
+
+ }
+ demand_rexmit(PPP_IP);
+ sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
+
+ } else {
+ /*
+ * Set IP addresses and (if specified) netmask.
+ */
+ mask = GetMask(go->ouraddr);
+
+#if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
+ if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
+ if (debug)
+ warn("Interface configuration failed");
+ ipcp_close(f->unit, "Interface configuration failed");
+ return;
+ }
+#endif
+
+ /* bring the interface up for IP */
+ if (!sifup(f->unit)) {
+ if (debug)
+ warn("Interface failed to come up");
+ ipcp_close(f->unit, "Interface configuration failed");
+ return;
+ }
+
+#if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
+ if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
+ if (debug)
+ warn("Interface configuration failed");
+ ipcp_close(f->unit, "Interface configuration failed");
+ return;
+ }
+#endif
+ sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
+
+ /* assign a default route through the interface if required */
+ if (ipcp_wantoptions[f->unit].default_route)
+ if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
+ default_route_set[f->unit] = 1;
+
+ /* Make a proxy ARP entry if requested. */
+ if (ipcp_wantoptions[f->unit].proxy_arp)
+ if (sifproxyarp(f->unit, ho->hisaddr))
+ proxy_arp_set[f->unit] = 1;
+
+ ipcp_wantoptions[0].ouraddr = go->ouraddr;
+
+ notice("local IP address %I", go->ouraddr);
+ notice("remote IP address %I", ho->hisaddr);
+ if (go->dnsaddr[0])
+ notice("primary DNS address %I", go->dnsaddr[0]);
+ if (go->dnsaddr[1])
+ notice("secondary DNS address %I", go->dnsaddr[1]);
+ }
+
+ np_up(f->unit, PPP_IP);
+ ipcp_is_up = 1;
+
+ if (ip_up_hook)
+ ip_up_hook();
+}
+
+
+/*
+ * ipcp_down - IPCP has gone DOWN.
+ *
+ * Take the IP network interface down, clear its addresses
+ * and delete routes through it.
+ */
+static void
+ipcp_down(
+ fsm *f)
+{
+ IPCPDEBUG(("ipcp: down"));
+ /* XXX a bit IPv4-centric here, we only need to get the stats
+ * before the interface is marked down. */
+ update_link_stats(f->unit);
+ if (ip_down_hook)
+ ip_down_hook();
+ if (ipcp_is_up) {
+ ipcp_is_up = 0;
+ np_down(f->unit, PPP_IP);
+ }
+ sifvjcomp(f->unit, 0, 0, 0);
+
+ /*
+ * If we are doing dial-on-demand, set the interface
+ * to queue up outgoing packets (for now).
+ */
+ if (demand) {
+ sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE);
+ } else {
+ sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
+ sifdown(f->unit);
+ ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
+ ipcp_hisoptions[f->unit].hisaddr);
+ }
+}
+
+
+/*
+ * ipcp_clear_addrs() - clear the interface addresses, routes,
+ * proxy arp entries, etc.
+ */
+static void
+ipcp_clear_addrs(
+ int unit,
+ uint32_t ouraddr, /* local address */
+ uint32_t hisaddr /* remote address */)
+{
+ if (proxy_arp_set[unit]) {
+ cifproxyarp(unit, hisaddr);
+ proxy_arp_set[unit] = 0;
+ }
+ if (default_route_set[unit]) {
+ cifdefaultroute(unit, ouraddr, hisaddr);
+ default_route_set[unit] = 0;
+ }
+ cifaddr(unit, ouraddr, hisaddr);
+}
+
+
+/*
+ * ipcp_finished - possibly shut down the lower layers.
+ */
+static void
+ipcp_finished(
+ fsm *f)
+{
+ np_finished(f->unit, PPP_IP);
+}
+
+/*
+ * create_resolv - create the replacement resolv.conf file
+ */
+static void
+create_resolv(
+ uint32_t peerdns1, uint32_t peerdns2)
+{
+ /* initialize values */
+ rtems_bsdnet_nameserver_count = 0;
+
+ /* check to see if primary was specified */
+ if ( peerdns1 ) {
+ rtems_bsdnet_nameserver[rtems_bsdnet_nameserver_count].s_addr = peerdns1;
+ rtems_bsdnet_nameserver_count++;
+ }
+
+ /* check to see if secondary was specified */
+ if ( peerdns2 ) {
+ rtems_bsdnet_nameserver[rtems_bsdnet_nameserver_count].s_addr = peerdns2;
+ rtems_bsdnet_nameserver_count++;
+ }
+
+ /* initialize resolver */
+ __res_init();
+}
+
+/*
+ * ipcp_printpkt - print the contents of an IPCP packet.
+ */
+static char *ipcp_codenames[] = {
+ "ConfReq", "ConfAck", "ConfNak", "ConfRej",
+ "TermReq", "TermAck", "CodeRej"
+};
+
+static int
+ipcp_printpkt(
+ u_char *p,
+ int plen,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ int code, id, len, olen;
+ u_char *pstart, *optend;
+ u_short cishort;
+ uint32_t cilong;
+
+ if (plen < HEADERLEN)
+ return 0;
+ pstart = p;
+ GETCHAR(code, p);
+ GETCHAR(id, p);
+ GETSHORT(len, p);
+ if (len < HEADERLEN || len > plen)
+ return 0;
+
+ if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
+ printer(arg, " %s", ipcp_codenames[code-1]);
+ else
+ printer(arg, " code=0x%x", code);
+ printer(arg, " id=0x%x", id);
+ len -= HEADERLEN;
+ switch (code) {
+ case CONFREQ:
+ case CONFACK:
+ case CONFNAK:
+ case CONFREJ:
+ /* print option list */
+ while (len >= 2) {
+ GETCHAR(code, p);
+ GETCHAR(olen, p);
+ p -= 2;
+ if (olen < 2 || olen > len) {
+ break;
+ }
+ printer(arg, " <");
+ len -= olen;
+ optend = p + olen;
+ switch (code) {
+ case CI_ADDRS:
+ if (olen == CILEN_ADDRS) {
+ p += 2;
+ GETLONG(cilong, p);
+ printer(arg, "addrs %I", htonl(cilong));
+ GETLONG(cilong, p);
+ printer(arg, " %I", htonl(cilong));
+ }
+ break;
+ case CI_COMPRESSTYPE:
+ if (olen >= CILEN_COMPRESS) {
+ p += 2;
+ GETSHORT(cishort, p);
+ printer(arg, "compress ");
+ switch (cishort) {
+ case IPCP_VJ_COMP:
+ printer(arg, "VJ");
+ break;
+ case IPCP_VJ_COMP_OLD:
+ printer(arg, "old-VJ");
+ break;
+ default:
+ printer(arg, "0x%x", cishort);
+ }
+ }
+ break;
+ case CI_ADDR:
+ if (olen == CILEN_ADDR) {
+ p += 2;
+ GETLONG(cilong, p);
+ printer(arg, "addr %I", htonl(cilong));
+ }
+ break;
+ case CI_MS_DNS1:
+ case CI_MS_DNS2:
+ p += 2;
+ GETLONG(cilong, p);
+ printer(arg, "ms-dns%d %I", code - CI_MS_DNS1 + 1,
+ htonl(cilong));
+ break;
+ case CI_MS_WINS1:
+ case CI_MS_WINS2:
+ p += 2;
+ GETLONG(cilong, p);
+ printer(arg, "ms-wins %I", htonl(cilong));
+ break;
+ }
+ while (p < optend) {
+ GETCHAR(code, p);
+ printer(arg, " %.2x", code);
+ }
+ printer(arg, ">");
+ }
+ break;
+
+ case TERMACK:
+ case TERMREQ:
+ if (len > 0 && *p >= ' ' && *p < 0x7f) {
+ printer(arg, " ");
+ print_string(p, len, printer, arg);
+ p += len;
+ len = 0;
+ }
+ break;
+ }
+
+ /* print the rest of the bytes in the packet */
+ for (; len > 0; --len) {
+ GETCHAR(code, p);
+ printer(arg, " %.2x", code);
+ }
+
+ return p - pstart;
+}
+
+/*
+ * ip_active_pkt - see if this IP packet is worth bringing the link up for.
+ * We don't bring the link up for IP fragments or for TCP FIN packets
+ * with no data.
+ */
+#define IP_HDRLEN 20 /* bytes */
+#define IP_OFFMASK 0x1fff
+#define IPPROTO_TCP 6
+#define TCP_HDRLEN 20
+#define TH_FIN 0x01
+
+/*
+ * We use these macros because the IP header may be at an odd address,
+ * and some compilers might use word loads to get th_off or ip_hl.
+ */
+
+#define net_short(x) (((x)[0] << 8) + (x)[1])
+#define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
+#define get_ipoff(x) net_short((unsigned char *)(x) + 6)
+#define get_ipproto(x) (((unsigned char *)(x))[9])
+#define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
+#define get_tcpflags(x) (((unsigned char *)(x))[13])
+
+static int
+ip_active_pkt(
+ u_char *pkt,
+ int len)
+{
+ u_char *tcp;
+ int hlen;
+
+ len -= PPP_HDRLEN;
+ pkt += PPP_HDRLEN;
+ if (len < IP_HDRLEN)
+ return 0;
+ if ((get_ipoff(pkt) & IP_OFFMASK) != 0)
+ return 0;
+ if (get_ipproto(pkt) != IPPROTO_TCP)
+ return 1;
+ hlen = get_iphl(pkt) * 4;
+ if (len < hlen + TCP_HDRLEN)
+ return 0;
+ tcp = pkt + hlen;
+ if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)
+ return 0;
+ return 1;
+}
diff --git a/cpukit/pppd/ipcp.h b/cpukit/pppd/ipcp.h
new file mode 100644
index 0000000000..e841cf8b22
--- /dev/null
+++ b/cpukit/pppd/ipcp.h
@@ -0,0 +1,73 @@
+/*
+ * ipcp.h - IP Control Protocol definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+/*
+ * Options.
+ */
+#define CI_ADDRS 1 /* IP Addresses */
+#define CI_COMPRESSTYPE 2 /* Compression Type */
+#define CI_ADDR 3
+
+#define CI_MS_DNS1 129 /* Primary DNS value */
+#define CI_MS_WINS1 130 /* Primary WINS value */
+#define CI_MS_DNS2 131 /* Secondary DNS value */
+#define CI_MS_WINS2 132 /* Secondary WINS value */
+
+#define MAX_STATES 16 /* from slcompress.h */
+
+#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */
+#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */
+#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */
+ /* maxslot and slot number compression) */
+
+#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/
+#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */
+ /* compression option*/
+
+typedef struct ipcp_options {
+ bool neg_addr; /* Negotiate IP Address? */
+ bool old_addrs; /* Use old (IP-Addresses) option? */
+ bool req_addr; /* Ask peer to send IP address? */
+ bool default_route; /* Assign default route through interface? */
+ bool proxy_arp; /* Make proxy ARP entry for peer? */
+ bool neg_vj; /* Van Jacobson Compression? */
+ bool old_vj; /* use old (short) form of VJ option? */
+ bool accept_local; /* accept peer's value for ouraddr */
+ bool accept_remote; /* accept peer's value for hisaddr */
+ bool req_dns1; /* Ask peer to send primary DNS address? */
+ bool req_dns2; /* Ask peer to send secondary DNS address? */
+ int vj_protocol; /* protocol value to use in VJ option */
+ int maxslotindex; /* values for RFC1332 VJ compression neg. */
+ bool cflag;
+ uint32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */
+ uint32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */
+ uint32_t winsaddr[2]; /* Primary and secondary MS WINS entries */
+} ipcp_options;
+
+extern fsm ipcp_fsm[];
+extern ipcp_options ipcp_wantoptions[];
+extern ipcp_options ipcp_gotoptions[];
+extern ipcp_options ipcp_allowoptions[];
+extern ipcp_options ipcp_hisoptions[];
+
+char *ip_ntoa(uint32_t);
+
+extern struct protent ipcp_protent;
diff --git a/cpukit/pppd/lcp.c b/cpukit/pppd/lcp.c
new file mode 100644
index 0000000000..9da1326a1a
--- /dev/null
+++ b/cpukit/pppd/lcp.c
@@ -0,0 +1,1953 @@
+/*
+ * lcp.c - PPP Link Control Protocol.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$";
+
+/*
+ * TODO:
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "pppd.h"
+#include "fsm.h"
+#include "lcp.h"
+#include "chap.h"
+#include "magic.h"
+
+static const char rcsid[] = RCSID;
+
+/*
+ * LCP-related command-line options.
+ */
+static int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
+static int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
+static bool lax_recv = false; /* accept control chars in asyncmap */
+
+static int setescape(char **);
+
+static option_t lcp_option_list[] = {
+ /* LCP options */
+ { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
+ "Disable address/control compression",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_accompression, 0, 0 },
+ { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
+ "Disable address/control compression",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_accompression, 0, 0 },
+ { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap,
+ "Disable asyncmap negotiation",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap, 0, 0 },
+ { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap,
+ "Disable asyncmap negotiation",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap, 0, 0 },
+ { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
+ "Set asyncmap (for received packets)",
+ OPT_OR, &lcp_wantoptions[0].neg_asyncmap, 0, 0 },
+ { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
+ "Set asyncmap (for received packets)",
+ OPT_OR, &lcp_wantoptions[0].neg_asyncmap, 0, 0 },
+ { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
+ "Disable magic number negotiation (looped-back line detection)",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber, 0, 0 },
+ { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
+ "Disable magic number negotiation (looped-back line detection)",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber, 0, 0 },
+ { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
+ "Disable MRU negotiation (use default 1500)",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_mru, 0, 0 },
+ { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
+ "Disable MRU negotiation (use default 1500)",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_mru, 0, 0 },
+ { "mru", o_int, &lcp_wantoptions[0].mru,
+ "Set MRU (maximum received packet size) for negotiation",
+ 0, &lcp_wantoptions[0].neg_mru, 0, 0 },
+ { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
+ "Disable protocol field compression",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression, 0, 0 },
+ { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
+ "Disable protocol field compression",
+ OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression, 0, 0 },
+ { "-p", o_bool, &lcp_wantoptions[0].passive,
+ "Set passive mode", 1, NULL, 0, 0 },
+ { "passive", o_bool, &lcp_wantoptions[0].passive,
+ "Set passive mode", 1, NULL, 0, 0 },
+ { "silent", o_bool, &lcp_wantoptions[0].silent,
+ "Set silent mode", 1, NULL, 0, 0 },
+ { "escape", o_special, setescape,
+ "List of character codes to escape on transmission", 0, NULL, 0, 0 },
+ { "lcp-echo-failure", o_int, &lcp_echo_fails,
+ "Set number of consecutive echo failures to indicate link failure", 0, NULL, 0, 0 },
+ { "lcp-echo-interval", o_int, &lcp_echo_interval,
+ "Set time in seconds between LCP echo requests", 0, NULL, 0, 0 },
+ { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
+ "Set time in seconds between LCP retransmissions", 0, NULL, 0, 0 },
+ { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
+ "Set maximum number of LCP terminate-request transmissions", 0, NULL, 0, 0 },
+ { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
+ "Set maximum number of LCP configure-request transmissions", 0, NULL, 0, 0 },
+ { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
+ "Set limit on number of LCP configure-naks", 0, NULL, 0, 0 },
+ { "receive-all", o_bool, &lax_recv,
+ "Accept all received control characters", 1, NULL, 0, 0 },
+ {NULL, 0, NULL, NULL, 0, NULL, 0, 0}
+};
+
+/* global vars */
+fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
+lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
+lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
+lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
+lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
+uint32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */
+
+static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
+static int lcp_echo_number = 0; /* ID number of next echo frame */
+static int lcp_echo_timer_running = 0; /* set if a timer is running */
+
+static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
+
+/*
+ * Callbacks for fsm code. (CI = Configuration Information)
+ */
+static void lcp_resetci(fsm *); /* Reset our CI */
+static int lcp_cilen(fsm *); /* Return length of our CI */
+static void lcp_addci(fsm *, u_char *, int *); /* Add our CI to pkt */
+static int lcp_ackci(fsm *, u_char *, int); /* Peer ack'd our CI */
+static int lcp_nakci(fsm *, u_char *, int); /* Peer nak'd our CI */
+static int lcp_rejci(fsm *, u_char *, int); /* Peer rej'd our CI */
+static int lcp_reqci(fsm *, u_char *, int *, int); /* Rcv peer CI */
+static void lcp_up(fsm *); /* We're UP */
+static void lcp_down(fsm *); /* We're DOWN */
+static void lcp_starting(fsm *); /* We need lower layer up */
+static void lcp_finished(fsm *); /* We need lower layer down */
+static int lcp_extcode(fsm *, int, int, u_char *, int);
+static void lcp_rprotrej(fsm *, u_char *, int);
+
+/*
+ * routines to send LCP echos to peer
+ */
+
+static void lcp_echo_lowerup(int);
+static void lcp_echo_lowerdown(int);
+static void LcpEchoTimeout(void *);
+static void lcp_received_echo_reply(fsm *, int, u_char *, int);
+static void LcpSendEchoRequest(fsm *);
+static void LcpLinkFailure(fsm *);
+static void LcpEchoCheck(fsm *);
+
+static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
+ lcp_resetci, /* Reset our Configuration Information */
+ lcp_cilen, /* Length of our Configuration Information */
+ lcp_addci, /* Add our Configuration Information */
+ lcp_ackci, /* ACK our Configuration Information */
+ lcp_nakci, /* NAK our Configuration Information */
+ lcp_rejci, /* Reject our Configuration Information */
+ lcp_reqci, /* Request peer's Configuration Information */
+ lcp_up, /* Called when fsm reaches OPENED state */
+ lcp_down, /* Called when fsm leaves OPENED state */
+ lcp_starting, /* Called when we want the lower layer up */
+ lcp_finished, /* Called when we want the lower layer down */
+ NULL, /* Called when Protocol-Reject received */
+ NULL, /* Retransmission is necessary */
+ lcp_extcode, /* Called to handle LCP-specific codes */
+ "LCP" /* String name of protocol */
+};
+
+/*
+ * Protocol entry points.
+ * Some of these are called directly.
+ */
+
+static void lcp_init(int);
+static void lcp_input(int, u_char *, int);
+static void lcp_protrej(int);
+static int lcp_printpkt(u_char *, int,
+ void (*)(void *, char *, ...), void *);
+
+struct protent lcp_protent = {
+ PPP_LCP,
+ lcp_init,
+ lcp_input,
+ lcp_protrej,
+ lcp_lowerup,
+ lcp_lowerdown,
+ lcp_open,
+ lcp_close,
+ lcp_printpkt,
+ NULL,
+ 1,
+ "LCP",
+ NULL,
+ lcp_option_list,
+ NULL,
+ NULL,
+ NULL
+};
+
+int lcp_loopbackfail = DEFLOOPBACKFAIL;
+
+/*
+ * Length of each type of configuration option (in octets)
+ */
+#define CILEN_VOID 2
+#define CILEN_CHAR 3
+#define CILEN_SHORT 4 /* CILEN_VOID + 2 */
+#define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
+#define CILEN_LONG 6 /* CILEN_VOID + 4 */
+#define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
+#define CILEN_CBCP 3
+
+#define CODENAME(x) ((x) == CONFACK ? "ACK" : \
+ (x) == CONFNAK ? "NAK" : "REJ")
+
+
+/*
+ * setescape - add chars to the set we escape on transmission.
+ */
+static int
+setescape(
+ char **argv)
+{
+ int n, ret;
+ char *p, *endp;
+
+ p = *argv;
+ ret = 1;
+ while (*p) {
+ n = strtol(p, &endp, 16);
+ if (p == endp) {
+ option_error("escape parameter contains invalid hex number '%s'",
+ p);
+ return 0;
+ }
+ p = endp;
+ if (n < 0 || n == 0x5E || n > 0xFF) {
+ option_error("can't escape character 0x%x", n);
+ ret = 0;
+ } else
+ xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
+ while (*p == ',' || *p == ' ')
+ ++p;
+ }
+ return ret;
+}
+
+/*
+ * lcp_init - Initialize LCP.
+ */
+static void
+lcp_init(
+ int unit)
+{
+ fsm *f = &lcp_fsm[unit];
+ lcp_options *wo = &lcp_wantoptions[unit];
+ lcp_options *ao = &lcp_allowoptions[unit];
+
+ f->unit = unit;
+ f->protocol = PPP_LCP;
+ f->callbacks = &lcp_callbacks;
+
+ fsm_init(f);
+
+ wo->passive = 0;
+ wo->silent = 0;
+ wo->restart = 0; /* Set to 1 in kernels or multi-line
+ implementations */
+ wo->neg_mru = 1;
+ wo->mru = DEFMRU;
+ wo->neg_asyncmap = 1;
+ wo->asyncmap = 0;
+ wo->neg_chap = 0; /* Set to 1 on server */
+ wo->neg_upap = 0; /* Set to 1 on server */
+ wo->chap_mdtype = CHAP_DIGEST_MD5;
+ wo->neg_magicnumber = 1;
+ wo->neg_pcompression = 1;
+ wo->neg_accompression = 1;
+ wo->neg_lqr = 0; /* no LQR implementation yet */
+ wo->neg_cbcp = 0;
+
+ ao->neg_mru = 1;
+ ao->mru = MAXMRU;
+ ao->neg_asyncmap = 1;
+ ao->asyncmap = 0;
+ ao->neg_chap = 1;
+ ao->chap_mdtype = CHAP_DIGEST_MD5;
+ ao->neg_upap = 1;
+ ao->neg_magicnumber = 1;
+ ao->neg_pcompression = 1;
+ ao->neg_accompression = 1;
+ ao->neg_lqr = 0; /* no LQR implementation yet */
+#ifdef CBCP_SUPPORT
+ ao->neg_cbcp = 1;
+#else
+ ao->neg_cbcp = 0;
+#endif
+
+ memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
+ xmit_accm[unit][3] = 0x60000000;
+}
+
+
+/*
+ * lcp_open - LCP is allowed to come up.
+ */
+void
+lcp_open(
+ int unit)
+{
+ fsm *f = &lcp_fsm[unit];
+ lcp_options *wo = &lcp_wantoptions[unit];
+
+ f->flags = 0;
+ if (wo->passive)
+ f->flags |= OPT_PASSIVE;
+ if (wo->silent)
+ f->flags |= OPT_SILENT;
+ fsm_open(f);
+}
+
+
+/*
+ * lcp_close - Take LCP down.
+ */
+void
+lcp_close(
+ int unit,
+ char *reason)
+{
+ fsm *f = &lcp_fsm[unit];
+
+ if (pppd_phase != PHASE_DEAD)
+ new_phase(PHASE_TERMINATE);
+ if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
+ /*
+ * This action is not strictly according to the FSM in RFC1548,
+ * but it does mean that the program terminates if you do a
+ * lcp_close() in passive/silent mode when a connection hasn't
+ * been established.
+ */
+ f->state = CLOSED;
+ lcp_finished(f);
+
+ } else
+ fsm_close(&lcp_fsm[unit], reason);
+}
+
+
+/*
+ * lcp_lowerup - The lower layer is up.
+ */
+void
+lcp_lowerup(
+ int unit)
+{
+ lcp_options *wo = &lcp_wantoptions[unit];
+
+ /*
+ * Don't use A/C or protocol compression on transmission,
+ * but accept A/C and protocol compressed packets
+ * if we are going to ask for A/C and protocol compression.
+ */
+ ppp_set_xaccm(unit, xmit_accm[unit]);
+ ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
+ ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
+ wo->neg_pcompression, wo->neg_accompression);
+ peer_mru[unit] = PPP_MRU;
+ lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
+
+ fsm_lowerup(&lcp_fsm[unit]);
+}
+
+
+/*
+ * lcp_lowerdown - The lower layer is down.
+ */
+void
+lcp_lowerdown(
+ int unit)
+{
+ fsm_lowerdown(&lcp_fsm[unit]);
+}
+
+
+/*
+ * lcp_input - Input LCP packet.
+ */
+static void
+lcp_input(
+ int unit,
+ u_char *p,
+ int len)
+{
+ fsm *f = &lcp_fsm[unit];
+
+ fsm_input(f, p, len);
+}
+
+
+/*
+ * lcp_extcode - Handle a LCP-specific code.
+ */
+static int
+lcp_extcode(
+ fsm *f,
+ int code, int id,
+ u_char *inp,
+ int len)
+{
+ u_char *magp;
+
+ switch( code ){
+ case PROTREJ:
+ lcp_rprotrej(f, inp, len);
+ break;
+
+ case ECHOREQ:
+ if (f->state != OPENED)
+ break;
+ magp = inp;
+ PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
+ fsm_sdata(f, ECHOREP, id, inp, len);
+ break;
+
+ case ECHOREP:
+ lcp_received_echo_reply(f, id, inp, len);
+ break;
+
+ case DISCREQ:
+ break;
+
+ default:
+ return 0;
+ }
+ return 1;
+}
+
+
+/*
+ * lcp_rprotrej - Receive an Protocol-Reject.
+ *
+ * Figure out which protocol is rejected and inform it.
+ */
+static void
+lcp_rprotrej(
+ fsm *f,
+ u_char *inp,
+ int len)
+{
+ int i;
+ struct protent *protp;
+ u_short prot;
+
+ if (len < 2) {
+ LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
+ return;
+ }
+
+ GETSHORT(prot, inp);
+
+ /*
+ * Protocol-Reject packets received in any state other than the LCP
+ * OPENED state SHOULD be silently discarded.
+ */
+ if( f->state != OPENED ){
+ LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
+ return;
+ }
+
+ /*
+ * Upcall the proper Protocol-Reject routine.
+ */
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->protocol == prot && protp->enabled_flag) {
+ (*protp->protrej)(f->unit);
+ return;
+ }
+
+ warn("Protocol-Reject for unsupported protocol 0x%x", prot);
+}
+
+
+/*
+ * lcp_protrej - A Protocol-Reject was received.
+ */
+/*ARGSUSED*/
+static void
+lcp_protrej(
+ int unit)
+{
+ /*
+ * Can't reject LCP!
+ */
+ error("Received Protocol-Reject for LCP!");
+ fsm_protreject(&lcp_fsm[unit]);
+}
+
+
+/*
+ * lcp_sprotrej - Send a Protocol-Reject for some protocol.
+ */
+void
+lcp_sprotrej(
+ int unit,
+ u_char *p,
+ int len)
+{
+ /*
+ * Send back the protocol and the information field of the
+ * rejected packet. We only get here if LCP is in the OPENED state.
+ */
+ p += 2;
+ len -= 2;
+
+ fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
+ p, len);
+}
+
+
+/*
+ * lcp_resetci - Reset our CI.
+ */
+static void
+lcp_resetci(
+ fsm *f)
+{
+ lcp_wantoptions[f->unit].magicnumber = magic();
+ lcp_wantoptions[f->unit].numloops = 0;
+ lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
+ peer_mru[f->unit] = PPP_MRU;
+ auth_reset(f->unit);
+}
+
+
+/*
+ * lcp_cilen - Return length of our CI.
+ */
+static int
+lcp_cilen(
+ fsm *f)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+
+#define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
+#define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
+#define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
+#define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
+#define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
+#define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
+ /*
+ * NB: we only ask for one of CHAP and UPAP, even if we will
+ * accept either.
+ */
+ return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
+ LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
+ LENCICHAP(go->neg_chap) +
+ LENCISHORT(!go->neg_chap && go->neg_upap) +
+ LENCILQR(go->neg_lqr) +
+ LENCICBCP(go->neg_cbcp) +
+ LENCILONG(go->neg_magicnumber) +
+ LENCIVOID(go->neg_pcompression) +
+ LENCIVOID(go->neg_accompression));
+}
+
+
+/*
+ * lcp_addci - Add our desired CIs to a packet.
+ */
+static void
+lcp_addci(
+ fsm *f,
+ u_char *ucp,
+ int *lenp)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+ u_char *start_ucp = ucp;
+
+#define ADDCIVOID(opt, neg) \
+ if (neg) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_VOID, ucp); \
+ }
+#define ADDCISHORT(opt, neg, val) \
+ if (neg) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_SHORT, ucp); \
+ PUTSHORT(val, ucp); \
+ }
+#define ADDCICHAP(opt, neg, val, digest) \
+ if (neg) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_CHAP, ucp); \
+ PUTSHORT(val, ucp); \
+ PUTCHAR(digest, ucp); \
+ }
+#define ADDCILONG(opt, neg, val) \
+ if (neg) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_LONG, ucp); \
+ PUTLONG(val, ucp); \
+ }
+#define ADDCILQR(opt, neg, val) \
+ if (neg) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_LQR, ucp); \
+ PUTSHORT(PPP_LQR, ucp); \
+ PUTLONG(val, ucp); \
+ }
+#define ADDCICHAR(opt, neg, val) \
+ if (neg) { \
+ PUTCHAR(opt, ucp); \
+ PUTCHAR(CILEN_CHAR, ucp); \
+ PUTCHAR(val, ucp); \
+ }
+
+ ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
+ ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
+ go->asyncmap);
+ ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
+ ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
+ ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
+ ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
+ ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
+ ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
+ ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
+
+ if (ucp - start_ucp != *lenp) {
+ /* this should never happen, because peer_mtu should be 1500 */
+ error("Bug in lcp_addci: wrong length");
+ }
+}
+
+
+/*
+ * lcp_ackci - Ack our CIs.
+ * This should not modify any state if the Ack is bad.
+ *
+ * Returns:
+ * 0 - Ack was bad.
+ * 1 - Ack was good.
+ */
+static int
+lcp_ackci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+ u_char cilen, citype, cichar;
+ u_short cishort;
+ uint32_t cilong;
+
+ /*
+ * CIs must be in exactly the same order that we sent.
+ * Check packet length and CI length at each step.
+ * If we find any deviations, then this packet is bad.
+ */
+#define ACKCIVOID(opt, neg) \
+ if (neg) { \
+ if ((len -= CILEN_VOID) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_VOID || \
+ citype != opt) \
+ goto bad; \
+ }
+#define ACKCISHORT(opt, neg, val) \
+ if (neg) { \
+ if ((len -= CILEN_SHORT) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_SHORT || \
+ citype != opt) \
+ goto bad; \
+ GETSHORT(cishort, p); \
+ if (cishort != val) \
+ goto bad; \
+ }
+#define ACKCICHAR(opt, neg, val) \
+ if (neg) { \
+ if ((len -= CILEN_CHAR) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_CHAR || \
+ citype != opt) \
+ goto bad; \
+ GETCHAR(cichar, p); \
+ if (cichar != val) \
+ goto bad; \
+ }
+#define ACKCICHAP(opt, neg, val, digest) \
+ if (neg) { \
+ if ((len -= CILEN_CHAP) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_CHAP || \
+ citype != opt) \
+ goto bad; \
+ GETSHORT(cishort, p); \
+ if (cishort != val) \
+ goto bad; \
+ GETCHAR(cichar, p); \
+ if (cichar != digest) \
+ goto bad; \
+ }
+#define ACKCILONG(opt, neg, val) \
+ if (neg) { \
+ if ((len -= CILEN_LONG) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_LONG || \
+ citype != opt) \
+ goto bad; \
+ GETLONG(cilong, p); \
+ if (cilong != val) \
+ goto bad; \
+ }
+#define ACKCILQR(opt, neg, val) \
+ if (neg) { \
+ if ((len -= CILEN_LQR) < 0) \
+ goto bad; \
+ GETCHAR(citype, p); \
+ GETCHAR(cilen, p); \
+ if (cilen != CILEN_LQR || \
+ citype != opt) \
+ goto bad; \
+ GETSHORT(cishort, p); \
+ if (cishort != PPP_LQR) \
+ goto bad; \
+ GETLONG(cilong, p); \
+ if (cilong != val) \
+ goto bad; \
+ }
+
+ ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
+ ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
+ go->asyncmap);
+ ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
+ ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
+ ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
+ ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
+ ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
+ ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
+ ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
+
+ /*
+ * If there are any remaining CIs, then this packet is bad.
+ */
+ if (len != 0)
+ goto bad;
+ return (1);
+bad:
+ LCPDEBUG(("lcp_acki: received bad Ack!"));
+ return (0);
+}
+
+
+/*
+ * lcp_nakci - Peer has sent a NAK for some of our CIs.
+ * This should not modify any state if the Nak is bad
+ * or if LCP is in the OPENED state.
+ *
+ * Returns:
+ * 0 - Nak was bad.
+ * 1 - Nak was good.
+ */
+static int
+lcp_nakci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+ lcp_options *wo = &lcp_wantoptions[f->unit];
+ u_char citype, cichar, *next;
+ u_short cishort;
+ uint32_t cilong;
+ lcp_options no; /* options we've seen Naks for */
+ lcp_options try; /* options to request next time */
+ int looped_back = 0;
+ int cilen;
+
+ BZERO(&no, sizeof(no));
+ try = *go;
+
+ /*
+ * Any Nak'd CIs must be in exactly the same order that we sent.
+ * Check packet length and CI length at each step.
+ * If we find any deviations, then this packet is bad.
+ */
+#define NAKCIVOID(opt, neg, code) \
+ if (go->neg && \
+ len >= CILEN_VOID && \
+ p[1] == CILEN_VOID && \
+ p[0] == opt) { \
+ len -= CILEN_VOID; \
+ INCPTR(CILEN_VOID, p); \
+ no.neg = 1; \
+ code \
+ }
+#define NAKCICHAP(opt, neg, code) \
+ if (go->neg && \
+ len >= CILEN_CHAP && \
+ p[1] == CILEN_CHAP && \
+ p[0] == opt) { \
+ len -= CILEN_CHAP; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ GETCHAR(cichar, p); \
+ no.neg = 1; \
+ code \
+ }
+#define NAKCICHAR(opt, neg, code) \
+ if (go->neg && \
+ len >= CILEN_CHAR && \
+ p[1] == CILEN_CHAR && \
+ p[0] == opt) { \
+ len -= CILEN_CHAR; \
+ INCPTR(2, p); \
+ GETCHAR(cichar, p); \
+ no.neg = 1; \
+ code \
+ }
+#define NAKCISHORT(opt, neg, code) \
+ if (go->neg && \
+ len >= CILEN_SHORT && \
+ p[1] == CILEN_SHORT && \
+ p[0] == opt) { \
+ len -= CILEN_SHORT; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ no.neg = 1; \
+ code \
+ }
+#define NAKCILONG(opt, neg, code) \
+ if (go->neg && \
+ len >= CILEN_LONG && \
+ p[1] == CILEN_LONG && \
+ p[0] == opt) { \
+ len -= CILEN_LONG; \
+ INCPTR(2, p); \
+ GETLONG(cilong, p); \
+ no.neg = 1; \
+ code \
+ }
+#define NAKCILQR(opt, neg, code) \
+ if (go->neg && \
+ len >= CILEN_LQR && \
+ p[1] == CILEN_LQR && \
+ p[0] == opt) { \
+ len -= CILEN_LQR; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ GETLONG(cilong, p); \
+ no.neg = 1; \
+ code \
+ }
+
+ /*
+ * We don't care if they want to send us smaller packets than
+ * we want. Therefore, accept any MRU less than what we asked for,
+ * but then ignore the new value when setting the MRU in the kernel.
+ * If they send us a bigger MRU than what we asked, accept it, up to
+ * the limit of the default MRU we'd get if we didn't negotiate.
+ */
+ if (go->neg_mru && go->mru != DEFMRU) {
+ NAKCISHORT(CI_MRU, neg_mru,
+ if (cishort <= wo->mru || cishort <= DEFMRU)
+ try.mru = cishort;
+ );
+ }
+
+ /*
+ * Add any characters they want to our (receive-side) asyncmap.
+ */
+ if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
+ NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
+ try.asyncmap = go->asyncmap | cilong;
+ );
+ }
+
+ /*
+ * If they've nak'd our authentication-protocol, check whether
+ * they are proposing a different protocol, or a different
+ * hash algorithm for CHAP.
+ */
+ if ((go->neg_chap || go->neg_upap)
+ && len >= CILEN_SHORT
+ && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
+ cilen = p[1];
+ len -= cilen;
+ no.neg_chap = go->neg_chap;
+ no.neg_upap = go->neg_upap;
+ INCPTR(2, p);
+ GETSHORT(cishort, p);
+ if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
+ /*
+ * If we were asking for CHAP, they obviously don't want to do it.
+ * If we weren't asking for CHAP, then we were asking for PAP,
+ * in which case this Nak is bad.
+ */
+ if (!go->neg_chap)
+ goto bad;
+ try.neg_chap = 0;
+
+ } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
+ GETCHAR(cichar, p);
+ if (go->neg_chap) {
+ /*
+ * We were asking for CHAP/MD5; they must want a different
+ * algorithm. If they can't do MD5, we can ask for M$-CHAP
+ * if we support it, otherwise we'll have to stop
+ * asking for CHAP.
+ */
+ if (cichar != go->chap_mdtype) {
+#ifdef CHAPMS
+ if (cichar == CHAP_MICROSOFT)
+ go->chap_mdtype = CHAP_MICROSOFT;
+ else
+#endif /* CHAPMS */
+ try.neg_chap = 0;
+ }
+ } else {
+ /*
+ * Stop asking for PAP if we were asking for it.
+ */
+ try.neg_upap = 0;
+ }
+
+ } else {
+ /*
+ * We don't recognize what they're suggesting.
+ * Stop asking for what we were asking for.
+ */
+ if (go->neg_chap)
+ try.neg_chap = 0;
+ else
+ try.neg_upap = 0;
+ p += cilen - CILEN_SHORT;
+ }
+ }
+
+ /*
+ * If they can't cope with our link quality protocol, we'll have
+ * to stop asking for LQR. We haven't got any other protocol.
+ * If they Nak the reporting period, take their value XXX ?
+ */
+ NAKCILQR(CI_QUALITY, neg_lqr,
+ if (cishort != PPP_LQR)
+ try.neg_lqr = 0;
+ else
+ try.lqr_period = cilong;
+ );
+
+ /*
+ * Only implementing CBCP...not the rest of the callback options
+ */
+ NAKCICHAR(CI_CALLBACK, neg_cbcp,
+ try.neg_cbcp = 0;
+ );
+
+ /*
+ * Check for a looped-back line.
+ */
+ NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
+ try.magicnumber = magic();
+ looped_back = 1;
+ );
+
+ /*
+ * Peer shouldn't send Nak for protocol compression or
+ * address/control compression requests; they should send
+ * a Reject instead. If they send a Nak, treat it as a Reject.
+ */
+ NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
+ try.neg_pcompression = 0;
+ );
+ NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
+ try.neg_accompression = 0;
+ );
+
+ /*
+ * There may be remaining CIs, if the peer is requesting negotiation
+ * on an option that we didn't include in our request packet.
+ * If we see an option that we requested, or one we've already seen
+ * in this packet, then this packet is bad.
+ * If we wanted to respond by starting to negotiate on the requested
+ * option(s), we could, but we don't, because except for the
+ * authentication type and quality protocol, if we are not negotiating
+ * an option, it is because we were told not to.
+ * For the authentication type, the Nak from the peer means
+ * `let me authenticate myself with you' which is a bit pointless.
+ * For the quality protocol, the Nak means `ask me to send you quality
+ * reports', but if we didn't ask for them, we don't want them.
+ * An option we don't recognize represents the peer asking to
+ * negotiate some option we don't support, so ignore it.
+ */
+ while (len > CILEN_VOID) {
+ GETCHAR(citype, p);
+ GETCHAR(cilen, p);
+ if (cilen < CILEN_VOID || (len -= cilen) < 0)
+ goto bad;
+ next = p + cilen - 2;
+
+ switch (citype) {
+ case CI_MRU:
+ if ((go->neg_mru && go->mru != DEFMRU)
+ || no.neg_mru || cilen != CILEN_SHORT)
+ goto bad;
+ GETSHORT(cishort, p);
+ if (cishort < DEFMRU)
+ try.mru = cishort;
+ break;
+ case CI_ASYNCMAP:
+ if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
+ || no.neg_asyncmap || cilen != CILEN_LONG)
+ goto bad;
+ break;
+ case CI_AUTHTYPE:
+ if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
+ goto bad;
+ break;
+ case CI_MAGICNUMBER:
+ if (go->neg_magicnumber || no.neg_magicnumber ||
+ cilen != CILEN_LONG)
+ goto bad;
+ break;
+ case CI_PCOMPRESSION:
+ if (go->neg_pcompression || no.neg_pcompression
+ || cilen != CILEN_VOID)
+ goto bad;
+ break;
+ case CI_ACCOMPRESSION:
+ if (go->neg_accompression || no.neg_accompression
+ || cilen != CILEN_VOID)
+ goto bad;
+ break;
+ case CI_QUALITY:
+ if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
+ goto bad;
+ break;
+ }
+ p = next;
+ }
+
+ /*
+ * OK, the Nak is good. Now we can update state.
+ * If there are any options left we ignore them.
+ */
+ if (f->state != OPENED) {
+ if (looped_back) {
+ if (++try.numloops >= lcp_loopbackfail) {
+ notice("Serial line is looped back.");
+ lcp_close(f->unit, "Loopback detected");
+ pppd_status = EXIT_LOOPBACK;
+ }
+ } else
+ try.numloops = 0;
+ *go = try;
+ }
+
+ return 1;
+
+bad:
+ LCPDEBUG(("lcp_nakci: received bad Nak!"));
+ return 0;
+}
+
+
+/*
+ * lcp_rejci - Peer has Rejected some of our CIs.
+ * This should not modify any state if the Reject is bad
+ * or if LCP is in the OPENED state.
+ *
+ * Returns:
+ * 0 - Reject was bad.
+ * 1 - Reject was good.
+ */
+static int
+lcp_rejci(
+ fsm *f,
+ u_char *p,
+ int len)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+ u_char cichar;
+ u_short cishort;
+ uint32_t cilong;
+ lcp_options try; /* options to request next time */
+
+ try = *go;
+
+ /*
+ * Any Rejected CIs must be in exactly the same order that we sent.
+ * Check packet length and CI length at each step.
+ * If we find any deviations, then this packet is bad.
+ */
+#define REJCIVOID(opt, neg) \
+ if (go->neg && \
+ len >= CILEN_VOID && \
+ p[1] == CILEN_VOID && \
+ p[0] == opt) { \
+ len -= CILEN_VOID; \
+ INCPTR(CILEN_VOID, p); \
+ try.neg = 0; \
+ }
+#define REJCISHORT(opt, neg, val) \
+ if (go->neg && \
+ len >= CILEN_SHORT && \
+ p[1] == CILEN_SHORT && \
+ p[0] == opt) { \
+ len -= CILEN_SHORT; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ /* Check rejected value. */ \
+ if (cishort != val) \
+ goto bad; \
+ try.neg = 0; \
+ }
+#define REJCICHAP(opt, neg, val, digest) \
+ if (go->neg && \
+ len >= CILEN_CHAP && \
+ p[1] == CILEN_CHAP && \
+ p[0] == opt) { \
+ len -= CILEN_CHAP; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ GETCHAR(cichar, p); \
+ /* Check rejected value. */ \
+ if (cishort != val || cichar != digest) \
+ goto bad; \
+ try.neg = 0; \
+ try.neg_upap = 0; \
+ }
+#define REJCILONG(opt, neg, val) \
+ if (go->neg && \
+ len >= CILEN_LONG && \
+ p[1] == CILEN_LONG && \
+ p[0] == opt) { \
+ len -= CILEN_LONG; \
+ INCPTR(2, p); \
+ GETLONG(cilong, p); \
+ /* Check rejected value. */ \
+ if (cilong != val) \
+ goto bad; \
+ try.neg = 0; \
+ }
+#define REJCILQR(opt, neg, val) \
+ if (go->neg && \
+ len >= CILEN_LQR && \
+ p[1] == CILEN_LQR && \
+ p[0] == opt) { \
+ len -= CILEN_LQR; \
+ INCPTR(2, p); \
+ GETSHORT(cishort, p); \
+ GETLONG(cilong, p); \
+ /* Check rejected value. */ \
+ if (cishort != PPP_LQR || cilong != val) \
+ goto bad; \
+ try.neg = 0; \
+ }
+#define REJCICBCP(opt, neg, val) \
+ if (go->neg && \
+ len >= CILEN_CBCP && \
+ p[1] == CILEN_CBCP && \
+ p[0] == opt) { \
+ len -= CILEN_CBCP; \
+ INCPTR(2, p); \
+ GETCHAR(cichar, p); \
+ /* Check rejected value. */ \
+ if (cichar != val) \
+ goto bad; \
+ try.neg = 0; \
+ }
+
+ REJCISHORT(CI_MRU, neg_mru, go->mru);
+ REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
+ REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
+ if (!go->neg_chap) {
+ REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
+ }
+ REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
+ REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
+ REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
+ REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
+ REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
+
+ /*
+ * If there are any remaining CIs, then this packet is bad.
+ */
+ if (len != 0)
+ goto bad;
+ /*
+ * Now we can update state.
+ */
+ if (f->state != OPENED)
+ *go = try;
+ return 1;
+
+bad:
+ LCPDEBUG(("lcp_rejci: received bad Reject!"));
+ return 0;
+}
+
+
+/*
+ * lcp_reqci - Check the peer's requested CIs and send appropriate response.
+ *
+ * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
+ * appropriately. If reject_if_disagree is non-zero, doesn't return
+ * CONFNAK; returns CONFREJ if it can't return CONFACK.
+ */
+static int
+lcp_reqci(
+ fsm *f,
+ u_char *inp, /* Requested CIs */
+ int *lenp, /* Length of requested CIs */
+ int reject_if_disagree)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+ lcp_options *ho = &lcp_hisoptions[f->unit];
+ lcp_options *ao = &lcp_allowoptions[f->unit];
+ u_char *cip, *next; /* Pointer to current and next CIs */
+ int cilen, citype, cichar; /* Parsed len, type, char value */
+ u_short cishort; /* Parsed short value */
+ uint32_t cilong; /* Parse long value */
+ int rc = CONFACK; /* Final packet return code */
+ int orc; /* Individual option return code */
+ u_char *p; /* Pointer to next char to parse */
+ u_char *rejp; /* Pointer to next char in reject frame */
+ u_char *nakp; /* Pointer to next char in Nak frame */
+ int l = *lenp; /* Length left */
+
+ /*
+ * Reset all his options.
+ */
+ BZERO(ho, sizeof(*ho));
+
+ /*
+ * Process all his options.
+ */
+ next = inp;
+ nakp = nak_buffer;
+ rejp = inp;
+ while (l) {
+ orc = CONFACK; /* Assume success */
+ cip = p = next; /* Remember begining of CI */
+ if (l < 2 || /* Not enough data for CI header or */
+ p[1] < 2 || /* CI length too small or */
+ p[1] > l) { /* CI length too big? */
+ LCPDEBUG(("lcp_reqci: bad CI length!"));
+ orc = CONFREJ; /* Reject bad CI */
+ cilen = l; /* Reject till end of packet */
+ l = 0; /* Don't loop again */
+ citype = 0;
+ goto endswitch;
+ }
+ GETCHAR(citype, p); /* Parse CI type */
+ GETCHAR(cilen, p); /* Parse CI length */
+ l -= cilen; /* Adjust remaining length */
+ next += cilen; /* Step to next CI */
+
+ switch (citype) { /* Check CI type */
+ case CI_MRU:
+ if (!ao->neg_mru || /* Allow option? */
+ cilen != CILEN_SHORT) { /* Check CI length */
+ orc = CONFREJ; /* Reject CI */
+ break;
+ }
+ GETSHORT(cishort, p); /* Parse MRU */
+
+ /*
+ * He must be able to receive at least our minimum.
+ * No need to check a maximum. If he sends a large number,
+ * we'll just ignore it.
+ */
+ if (cishort < MINMRU) {
+ orc = CONFNAK; /* Nak CI */
+ PUTCHAR(CI_MRU, nakp);
+ PUTCHAR(CILEN_SHORT, nakp);
+ PUTSHORT(MINMRU, nakp); /* Give him a hint */
+ break;
+ }
+ ho->neg_mru = 1; /* Remember he sent MRU */
+ ho->mru = cishort; /* And remember value */
+ break;
+
+ case CI_ASYNCMAP:
+ if (!ao->neg_asyncmap ||
+ cilen != CILEN_LONG) {
+ orc = CONFREJ;
+ break;
+ }
+ GETLONG(cilong, p);
+
+ /*
+ * Asyncmap must have set at least the bits
+ * which are set in lcp_allowoptions[unit].asyncmap.
+ */
+ if ((ao->asyncmap & ~cilong) != 0) {
+ orc = CONFNAK;
+ PUTCHAR(CI_ASYNCMAP, nakp);
+ PUTCHAR(CILEN_LONG, nakp);
+ PUTLONG(ao->asyncmap | cilong, nakp);
+ break;
+ }
+ ho->neg_asyncmap = 1;
+ ho->asyncmap = cilong;
+ break;
+
+ case CI_AUTHTYPE:
+ if (cilen < CILEN_SHORT ||
+ !(ao->neg_upap || ao->neg_chap)) {
+ /*
+ * Reject the option if we're not willing to authenticate.
+ */
+ orc = CONFREJ;
+ break;
+ }
+ GETSHORT(cishort, p);
+
+ /*
+ * Authtype must be PAP or CHAP.
+ *
+ * Note: if both ao->neg_upap and ao->neg_chap are set,
+ * and the peer sends a Configure-Request with two
+ * authenticate-protocol requests, one for CHAP and one
+ * for UPAP, then we will reject the second request.
+ * Whether we end up doing CHAP or UPAP depends then on
+ * the ordering of the CIs in the peer's Configure-Request.
+ */
+
+ if (cishort == PPP_PAP) {
+ if (ho->neg_chap || /* we've already accepted CHAP */
+ cilen != CILEN_SHORT) {
+ LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
+ orc = CONFREJ;
+ break;
+ }
+ if (!ao->neg_upap) { /* we don't want to do PAP */
+ orc = CONFNAK; /* NAK it and suggest CHAP */
+ PUTCHAR(CI_AUTHTYPE, nakp);
+ PUTCHAR(CILEN_CHAP, nakp);
+ PUTSHORT(PPP_CHAP, nakp);
+ PUTCHAR(ao->chap_mdtype, nakp);
+ /* XXX if we can do CHAP_MICROSOFT as well, we should
+ probably put in another option saying so */
+ break;
+ }
+ ho->neg_upap = 1;
+ break;
+ }
+ if (cishort == PPP_CHAP) {
+ if (ho->neg_upap || /* we've already accepted PAP */
+ cilen != CILEN_CHAP) {
+ LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
+ orc = CONFREJ;
+ break;
+ }
+ if (!ao->neg_chap) { /* we don't want to do CHAP */
+ orc = CONFNAK; /* NAK it and suggest PAP */
+ PUTCHAR(CI_AUTHTYPE, nakp);
+ PUTCHAR(CILEN_SHORT, nakp);
+ PUTSHORT(PPP_PAP, nakp);
+ break;
+ }
+ GETCHAR(cichar, p); /* get digest type*/
+ if (cichar != CHAP_DIGEST_MD5
+#ifdef CHAPMS
+ && cichar != CHAP_MICROSOFT
+#endif
+ ) {
+ orc = CONFNAK;
+ PUTCHAR(CI_AUTHTYPE, nakp);
+ PUTCHAR(CILEN_CHAP, nakp);
+ PUTSHORT(PPP_CHAP, nakp);
+ PUTCHAR(ao->chap_mdtype, nakp);
+ break;
+ }
+ ho->chap_mdtype = cichar; /* save md type */
+ ho->neg_chap = 1;
+ break;
+ }
+
+ /*
+ * We don't recognize the protocol they're asking for.
+ * Nak it with something we're willing to do.
+ * (At this point we know ao->neg_upap || ao->neg_chap.)
+ */
+ orc = CONFNAK;
+ PUTCHAR(CI_AUTHTYPE, nakp);
+ if (ao->neg_chap) {
+ PUTCHAR(CILEN_CHAP, nakp);
+ PUTSHORT(PPP_CHAP, nakp);
+ PUTCHAR(ao->chap_mdtype, nakp);
+ } else {
+ PUTCHAR(CILEN_SHORT, nakp);
+ PUTSHORT(PPP_PAP, nakp);
+ }
+ break;
+
+ case CI_QUALITY:
+ if (!ao->neg_lqr ||
+ cilen != CILEN_LQR) {
+ orc = CONFREJ;
+ break;
+ }
+
+ GETSHORT(cishort, p);
+ GETLONG(cilong, p);
+
+ /*
+ * Check the protocol and the reporting period.
+ * XXX When should we Nak this, and what with?
+ */
+ if (cishort != PPP_LQR) {
+ orc = CONFNAK;
+ PUTCHAR(CI_QUALITY, nakp);
+ PUTCHAR(CILEN_LQR, nakp);
+ PUTSHORT(PPP_LQR, nakp);
+ PUTLONG(ao->lqr_period, nakp);
+ break;
+ }
+ break;
+
+ case CI_MAGICNUMBER:
+ if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
+ cilen != CILEN_LONG) {
+ orc = CONFREJ;
+ break;
+ }
+ GETLONG(cilong, p);
+
+ /*
+ * He must have a different magic number.
+ */
+ if (go->neg_magicnumber &&
+ cilong == go->magicnumber) {
+ cilong = magic(); /* Don't put magic() inside macro! */
+ orc = CONFNAK;
+ PUTCHAR(CI_MAGICNUMBER, nakp);
+ PUTCHAR(CILEN_LONG, nakp);
+ PUTLONG(cilong, nakp);
+ break;
+ }
+ ho->neg_magicnumber = 1;
+ ho->magicnumber = cilong;
+ break;
+
+
+ case CI_PCOMPRESSION:
+ if (!ao->neg_pcompression ||
+ cilen != CILEN_VOID) {
+ orc = CONFREJ;
+ break;
+ }
+ ho->neg_pcompression = 1;
+ break;
+
+ case CI_ACCOMPRESSION:
+ if (!ao->neg_accompression ||
+ cilen != CILEN_VOID) {
+ orc = CONFREJ;
+ break;
+ }
+ ho->neg_accompression = 1;
+ break;
+
+ default:
+ LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
+ orc = CONFREJ;
+ break;
+ }
+
+endswitch:
+ if (orc == CONFACK && /* Good CI */
+ rc != CONFACK) /* but prior CI wasnt? */
+ continue; /* Don't send this one */
+
+ if (orc == CONFNAK) { /* Nak this CI? */
+ if (reject_if_disagree /* Getting fed up with sending NAKs? */
+ && citype != CI_MAGICNUMBER) {
+ orc = CONFREJ; /* Get tough if so */
+ } else {
+ if (rc == CONFREJ) /* Rejecting prior CI? */
+ continue; /* Don't send this one */
+ rc = CONFNAK;
+ }
+ }
+ if (orc == CONFREJ) { /* Reject this CI */
+ rc = CONFREJ;
+ if (cip != rejp) /* Need to move rejected CI? */
+ BCOPY(cip, rejp, cilen); /* Move it */
+ INCPTR(cilen, rejp); /* Update output pointer */
+ }
+ }
+
+ /*
+ * If we wanted to send additional NAKs (for unsent CIs), the
+ * code would go here. The extra NAKs would go at *nakp.
+ * At present there are no cases where we want to ask the
+ * peer to negotiate an option.
+ */
+
+ switch (rc) {
+ case CONFACK:
+ *lenp = next - inp;
+ break;
+ case CONFNAK:
+ /*
+ * Copy the Nak'd options from the nak_buffer to the caller's buffer.
+ */
+ *lenp = nakp - nak_buffer;
+ BCOPY(nak_buffer, inp, *lenp);
+ break;
+ case CONFREJ:
+ *lenp = rejp - inp;
+ break;
+ }
+
+ LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
+ return (rc); /* Return final code */
+}
+
+
+/*
+ * lcp_up - LCP has come UP.
+ */
+static void
+lcp_up(
+ fsm *f)
+{
+ lcp_options *wo = &lcp_wantoptions[f->unit];
+ lcp_options *ho = &lcp_hisoptions[f->unit];
+ lcp_options *go = &lcp_gotoptions[f->unit];
+ lcp_options *ao = &lcp_allowoptions[f->unit];
+
+ if (!go->neg_magicnumber)
+ go->magicnumber = 0;
+ if (!ho->neg_magicnumber)
+ ho->magicnumber = 0;
+
+ /*
+ * Set our MTU to the smaller of the MTU we wanted and
+ * the MRU our peer wanted. If we negotiated an MRU,
+ * set our MRU to the larger of value we wanted and
+ * the value we got in the negotiation.
+ */
+ ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
+ (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
+ ho->neg_pcompression, ho->neg_accompression);
+ ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
+ (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
+ go->neg_pcompression, go->neg_accompression);
+
+ if (ho->neg_mru)
+ peer_mru[f->unit] = ho->mru;
+
+ lcp_echo_lowerup(f->unit); /* Enable echo messages */
+
+ link_established(f->unit);
+}
+
+
+/*
+ * lcp_down - LCP has gone DOWN.
+ *
+ * Alert other protocols.
+ */
+static void
+lcp_down(
+ fsm *f)
+{
+ lcp_options *go = &lcp_gotoptions[f->unit];
+
+ lcp_echo_lowerdown(f->unit);
+
+ link_down(f->unit);
+
+ ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
+ ppp_recv_config(f->unit, PPP_MRU,
+ (go->neg_asyncmap? go->asyncmap: 0xffffffff),
+ go->neg_pcompression, go->neg_accompression);
+ peer_mru[f->unit] = PPP_MRU;
+}
+
+
+/*
+ * lcp_starting - LCP needs the lower layer up.
+ */
+static void
+lcp_starting(
+ fsm *f)
+{
+ link_required(f->unit);
+}
+
+
+/*
+ * lcp_finished - LCP has finished with the lower layer.
+ */
+static void
+lcp_finished(
+ fsm *f)
+{
+ link_terminated(f->unit);
+}
+
+
+/*
+ * lcp_printpkt - print the contents of an LCP packet.
+ */
+static char *lcp_codenames[] = {
+ "ConfReq", "ConfAck", "ConfNak", "ConfRej",
+ "TermReq", "TermAck", "CodeRej", "ProtRej",
+ "EchoReq", "EchoRep", "DiscReq"
+};
+
+static int
+lcp_printpkt(
+ u_char *p,
+ int plen,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ int code, id, len, olen;
+ u_char *pstart, *optend;
+ u_short cishort;
+ uint32_t cilong;
+
+ if (plen < HEADERLEN)
+ return 0;
+ pstart = p;
+ GETCHAR(code, p);
+ GETCHAR(id, p);
+ GETSHORT(len, p);
+ if (len < HEADERLEN || len > plen)
+ return 0;
+
+ if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
+ printer(arg, " %s", lcp_codenames[code-1]);
+ else
+ printer(arg, " code=0x%x", code);
+ printer(arg, " id=0x%x", id);
+ len -= HEADERLEN;
+ switch (code) {
+ case CONFREQ:
+ case CONFACK:
+ case CONFNAK:
+ case CONFREJ:
+ /* print option list */
+ while (len >= 2) {
+ GETCHAR(code, p);
+ GETCHAR(olen, p);
+ p -= 2;
+ if (olen < 2 || olen > len) {
+ break;
+ }
+ printer(arg, " <");
+ len -= olen;
+ optend = p + olen;
+ switch (code) {
+ case CI_MRU:
+ if (olen == CILEN_SHORT) {
+ p += 2;
+ GETSHORT(cishort, p);
+ printer(arg, "mru %d", cishort);
+ }
+ break;
+ case CI_ASYNCMAP:
+ if (olen == CILEN_LONG) {
+ p += 2;
+ GETLONG(cilong, p);
+ printer(arg, "asyncmap 0x%x", cilong);
+ }
+ break;
+ case CI_AUTHTYPE:
+ if (olen >= CILEN_SHORT) {
+ p += 2;
+ printer(arg, "auth ");
+ GETSHORT(cishort, p);
+ switch (cishort) {
+ case PPP_PAP:
+ printer(arg, "pap");
+ break;
+ case PPP_CHAP:
+ printer(arg, "chap");
+ if (p < optend) {
+ switch (*p) {
+ case CHAP_DIGEST_MD5:
+ printer(arg, " MD5");
+ ++p;
+ break;
+#ifdef CHAPMS
+ case CHAP_MICROSOFT:
+ printer(arg, " m$oft");
+ ++p;
+ break;
+#endif
+ }
+ }
+ break;
+ default:
+ printer(arg, "0x%x", cishort);
+ }
+ }
+ break;
+ case CI_QUALITY:
+ if (olen >= CILEN_SHORT) {
+ p += 2;
+ printer(arg, "quality ");
+ GETSHORT(cishort, p);
+ switch (cishort) {
+ case PPP_LQR:
+ printer(arg, "lqr");
+ break;
+ default:
+ printer(arg, "0x%x", cishort);
+ }
+ }
+ break;
+ case CI_CALLBACK:
+ if (olen >= CILEN_CHAR) {
+ p += 2;
+ printer(arg, "callback ");
+ GETCHAR(cishort, p);
+ switch (cishort) {
+ case CBCP_OPT:
+ printer(arg, "CBCP");
+ break;
+ default:
+ printer(arg, "0x%x", cishort);
+ }
+ }
+ break;
+ case CI_MAGICNUMBER:
+ if (olen == CILEN_LONG) {
+ p += 2;
+ GETLONG(cilong, p);
+ printer(arg, "magic 0x%x", cilong);
+ }
+ break;
+ case CI_PCOMPRESSION:
+ if (olen == CILEN_VOID) {
+ p += 2;
+ printer(arg, "pcomp");
+ }
+ break;
+ case CI_ACCOMPRESSION:
+ if (olen == CILEN_VOID) {
+ p += 2;
+ printer(arg, "accomp");
+ }
+ break;
+ }
+ while (p < optend) {
+ GETCHAR(code, p);
+ printer(arg, " %.2x", code);
+ }
+ printer(arg, ">");
+ }
+ break;
+
+ case TERMACK:
+ case TERMREQ:
+ if (len > 0 && *p >= ' ' && *p < 0x7f) {
+ printer(arg, " ");
+ print_string(p, len, printer, arg);
+ p += len;
+ len = 0;
+ }
+ break;
+
+ case ECHOREQ:
+ case ECHOREP:
+ case DISCREQ:
+ if (len >= 4) {
+ GETLONG(cilong, p);
+ printer(arg, " magic=0x%x", cilong);
+ p += 4;
+ len -= 4;
+ }
+ break;
+ }
+
+ /* print the rest of the bytes in the packet */
+ for (; len > 0; --len) {
+ GETCHAR(code, p);
+ printer(arg, " %.2x", code);
+ }
+
+ return p - pstart;
+}
+
+/*
+ * Time to shut down the link because there is nothing out there.
+ */
+
+static
+void LcpLinkFailure (
+ fsm *f)
+{
+ if (f->state == OPENED) {
+ info("No response to %d echo-requests", lcp_echos_pending);
+ notice("Serial link appears to be disconnected.");
+ lcp_close(f->unit, "Peer not responding");
+ pppd_status = EXIT_PEER_DEAD;
+ }
+}
+
+/*
+ * Timer expired for the LCP echo requests from this process.
+ */
+
+static void
+LcpEchoCheck (
+ fsm *f)
+{
+ LcpSendEchoRequest (f);
+ if (f->state != OPENED)
+ return;
+
+ /*
+ * Start the timer for the next interval.
+ */
+ if (lcp_echo_timer_running)
+ warn("assertion lcp_echo_timer_running==0 failed");
+ TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
+ lcp_echo_timer_running = 1;
+}
+
+/*
+ * LcpEchoTimeout - Timer expired on the LCP echo
+ */
+
+static void
+LcpEchoTimeout (
+ void *arg)
+{
+ if (lcp_echo_timer_running != 0) {
+ lcp_echo_timer_running = 0;
+ LcpEchoCheck ((fsm *) arg);
+ }
+}
+
+/*
+ * LcpEchoReply - LCP has received a reply to the echo
+ */
+
+static void
+lcp_received_echo_reply (
+ fsm *f,
+ int id,
+ u_char *inp,
+ int len)
+{
+ uint32_t magic;
+
+ /* Check the magic number - don't count replies from ourselves. */
+ if (len < 4) {
+ dbglog("lcp: received short Echo-Reply, length %d", len);
+ return;
+ }
+ GETLONG(magic, inp);
+ if (lcp_gotoptions[f->unit].neg_magicnumber
+ && magic == lcp_gotoptions[f->unit].magicnumber) {
+ warn("appear to have received our own echo-reply!");
+ return;
+ }
+
+ /* Reset the number of outstanding echo frames */
+ lcp_echos_pending = 0;
+}
+
+/*
+ * LcpSendEchoRequest - Send an echo request frame to the peer
+ */
+
+static void
+LcpSendEchoRequest (
+ fsm *f)
+{
+ uint32_t lcp_magic;
+ u_char pkt[4], *pktp;
+
+ /*
+ * Detect the failure of the peer at this point.
+ */
+ if (lcp_echo_fails != 0) {
+ if (lcp_echos_pending >= lcp_echo_fails) {
+ LcpLinkFailure(f);
+ lcp_echos_pending = 0;
+ }
+ }
+
+ /*
+ * Make and send the echo request frame.
+ */
+ if (f->state == OPENED) {
+ lcp_magic = lcp_gotoptions[f->unit].magicnumber;
+ pktp = pkt;
+ PUTLONG(lcp_magic, pktp);
+ fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
+ ++lcp_echos_pending;
+ }
+}
+
+/*
+ * lcp_echo_lowerup - Start the timer for the LCP frame
+ */
+
+static void
+lcp_echo_lowerup (
+ int unit)
+{
+ fsm *f = &lcp_fsm[unit];
+
+ /* Clear the parameters for generating echo frames */
+ lcp_echos_pending = 0;
+ lcp_echo_number = 0;
+ lcp_echo_timer_running = 0;
+
+ /* If a timeout interval is specified then start the timer */
+ if (lcp_echo_interval != 0)
+ LcpEchoCheck (f);
+}
+
+/*
+ * lcp_echo_lowerdown - Stop the timer for the LCP frame
+ */
+
+static void
+lcp_echo_lowerdown (
+ int unit)
+{
+ fsm *f = &lcp_fsm[unit];
+
+ if (lcp_echo_timer_running != 0) {
+ UNTIMEOUT (LcpEchoTimeout, f);
+ lcp_echo_timer_running = 0;
+ }
+}
diff --git a/cpukit/pppd/lcp.h b/cpukit/pppd/lcp.h
new file mode 100644
index 0000000000..6231d270ae
--- /dev/null
+++ b/cpukit/pppd/lcp.h
@@ -0,0 +1,88 @@
+/*
+ * lcp.h - Link Control Protocol definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+/*
+ * Options.
+ */
+#define CI_MRU 1 /* Maximum Receive Unit */
+#define CI_ASYNCMAP 2 /* Async Control Character Map */
+#define CI_AUTHTYPE 3 /* Authentication Type */
+#define CI_QUALITY 4 /* Quality Protocol */
+#define CI_MAGICNUMBER 5 /* Magic Number */
+#define CI_PCOMPRESSION 7 /* Protocol Field Compression */
+#define CI_ACCOMPRESSION 8 /* Address/Control Field Compression */
+#define CI_CALLBACK 13 /* callback */
+
+/*
+ * LCP-specific packet types.
+ */
+#define PROTREJ 8 /* Protocol Reject */
+#define ECHOREQ 9 /* Echo Request */
+#define ECHOREP 10 /* Echo Reply */
+#define DISCREQ 11 /* Discard Request */
+#define CBCP_OPT 6 /* Use callback control protocol */
+
+/*
+ * The state of options is described by an lcp_options structure.
+ */
+typedef struct lcp_options {
+ bool passive; /* Don't die if we don't get a response */
+ bool silent; /* Wait for the other end to start first */
+ bool restart; /* Restart vs. exit after close */
+ bool neg_mru; /* Negotiate the MRU? */
+ bool neg_asyncmap; /* Negotiate the async map? */
+ bool neg_upap; /* Ask for UPAP authentication? */
+ bool neg_chap; /* Ask for CHAP authentication? */
+ bool neg_magicnumber; /* Ask for magic number? */
+ bool neg_pcompression; /* HDLC Protocol Field Compression? */
+ bool neg_accompression; /* HDLC Address/Control Field Compression? */
+ bool neg_lqr; /* Negotiate use of Link Quality Reports */
+ bool neg_cbcp; /* Negotiate use of CBCP */
+ int mru; /* Value of MRU */
+ u_char chap_mdtype; /* which MD type (hashing algorithm) */
+ uint32_t asyncmap; /* Value of async map */
+ uint32_t magicnumber;
+ int numloops; /* Number of loops during magic number neg. */
+ uint32_t lqr_period; /* Reporting period for LQR 1/100ths second */
+} lcp_options;
+
+extern fsm lcp_fsm[];
+extern lcp_options lcp_wantoptions[];
+extern lcp_options lcp_gotoptions[];
+extern lcp_options lcp_allowoptions[];
+extern lcp_options lcp_hisoptions[];
+extern uint32_t xmit_accm[][8];
+
+#define DEFMRU 1500 /* Try for this */
+#define MINMRU 128 /* No MRUs below this */
+#define MAXMRU 16384 /* Normally limit MRU to this */
+
+void lcp_open(int);
+void lcp_close(int, char *);
+void lcp_lowerup(int);
+void lcp_lowerdown(int);
+void lcp_sprotrej(int, u_char *, int); /* send protocol reject */
+
+extern struct protent lcp_protent;
+
+/* Default number of times we receive our magic number from the peer
+ before deciding the link is looped-back. */
+#define DEFLOOPBACKFAIL 10
diff --git a/cpukit/pppd/magic.c b/cpukit/pppd/magic.c
new file mode 100644
index 0000000000..3d297e5e67
--- /dev/null
+++ b/cpukit/pppd/magic.c
@@ -0,0 +1,58 @@
+/*
+ * magic.c - PPP Magic Number routines.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "pppd.h"
+#include "magic.h"
+
+static const char rcsid[] = RCSID;
+
+/*
+ * magic_init - Initialize the magic number generator.
+ *
+ * Attempts to compute a random number seed which will not repeat.
+ * The current method uses the current hostid, current process ID
+ * and current time, currently.
+ */
+void
+magic_init(void)
+{
+ long seed;
+ struct timeval t;
+
+ gettimeofday(&t, NULL);
+ seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
+ srand48(seed);
+}
+
+/*
+ * magic - Returns the next magic number.
+ */
+uint32_t
+magic(void)
+{
+ return (uint32_t) mrand48();
+}
diff --git a/cpukit/pppd/magic.h b/cpukit/pppd/magic.h
new file mode 100644
index 0000000000..572a550042
--- /dev/null
+++ b/cpukit/pppd/magic.h
@@ -0,0 +1,23 @@
+/*
+ * magic.h - PPP Magic Number definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+void magic_init(void); /* Initialize the magic number generator */
+uint32_t magic(void); /* Returns the next magic number */
diff --git a/cpukit/pppd/options.c b/cpukit/pppd/options.c
new file mode 100644
index 0000000000..9b010e3b37
--- /dev/null
+++ b/cpukit/pppd/options.c
@@ -0,0 +1,1520 @@
+/*
+ * options.c - handles option processing for PPP.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <ctype.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <string.h>
+#include <netdb.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#ifdef PLUGIN
+#include <dlfcn.h>
+#endif
+#ifdef PPP_FILTER
+#include <pcap.h>
+#include <pcap-int.h> /* XXX: To get struct pcap */
+#endif
+
+#include "pppd.h"
+#include "pathnames.h"
+#include "patchlevel.h"
+#include "fsm.h"
+#include "lcp.h"
+#include "ipcp.h"
+#include "upap.h"
+#include "chap.h"
+#include "ccp.h"
+
+#include <net/ppp_comp.h>
+
+static const char rcsid[] = RCSID;
+
+/*
+ * Option variables and default values.
+ */
+#ifdef PPP_FILTER
+int dflag = 0; /* Tell libpcap we want debugging */
+#endif
+int debug = 0; /* Debug flag */
+int kdebugflag = 0; /* Tell kernel to print debug messages */
+int default_device = 1; /* Using /dev/tty or equivalent */
+char devnam[MAXPATHLEN]; /* Device name */
+int crtscts = 0; /* Use hardware flow control */
+bool modem = 1; /* Use modem control lines */
+int inspeed = 0; /* Input/Output speed requested */
+uint32_t netmask = 0; /* IP netmask to set on interface */
+bool lockflag = 0; /* Create lock file to lock the serial dev */
+bool nodetach = 0; /* Don't detach from controlling tty */
+bool updetach = 0; /* Detach once link is up */
+char *initializer = NULL; /* Script to initialize physical link */
+char *connect_script = NULL; /* Script to establish physical link */
+char *disconnect_script = NULL; /* Script to disestablish physical link */
+char *welcomer = NULL; /* Script to run after phys link estab. */
+char *ptycommand = NULL; /* Command to run on other side of pty */
+int maxconnect = 0; /* Maximum connect time */
+char user[MAXNAMELEN]; /* Username for PAP */
+char passwd[MAXSECRETLEN]; /* Password for PAP */
+bool persist = 0; /* Reopen link after it goes down */
+char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
+bool demand = 0; /* do dial-on-demand */
+char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
+int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
+int holdoff = 30; /* # seconds to pause before reconnecting */
+bool holdoff_specified; /* true if a holdoff value has been given */
+bool notty = 0; /* Stdin/out is not a tty */
+char *record_file = NULL; /* File to record chars sent/received */
+int using_pty = 0;
+bool sync_serial = 0; /* Device is synchronous serial device */
+int log_to_fd = 1; /* send log messages to this fd too */
+int maxfail = 10; /* max # of unsuccessful connection attempts */
+char linkname[MAXPATHLEN]; /* logical name for link */
+bool tune_kernel; /* may alter kernel settings */
+int connect_delay = 1000; /* wait this many ms after connect script */
+
+extern option_t auth_options[];
+extern struct stat devstat;
+extern int prepass; /* Doing pre-pass to find device name */
+
+struct option_info initializer_info;
+struct option_info connect_script_info;
+struct option_info disconnect_script_info;
+struct option_info welcomer_info;
+struct option_info devnam_info;
+struct option_info ptycommand_info;
+
+#ifdef PPP_FILTER
+struct bpf_program pass_filter;/* Filter program for packets to pass */
+struct bpf_program active_filter; /* Filter program for link-active pkts */
+pcap_t pc; /* Fake struct pcap so we can compile expr */
+#endif
+
+char *current_option; /* the name of the option being parsed */
+int privileged_option; /* set iff the current option came from root */
+char *option_source; /* string saying where the option came from */
+bool log_to_file; /* log_to_fd is a file opened by us */
+
+/*
+ * Prototypes
+ */
+static int setdevname(char *);
+static int setipaddr(char *);
+static int setspeed(char *);
+static int noopt(char **);
+static int setdomain(char **);
+static int setnetmask(char **);
+static int setxonxoff(char **);
+static int readfile(char **);
+static int callfile(char **);
+static void usage(void);
+static int setlogfile(char **);
+#ifdef PLUGIN
+static int loadplugin(char **);
+#endif
+
+#ifdef PPP_FILTER
+static int setpassfilter(char **);
+static int setactivefilter(char **);
+#endif
+
+static option_t *find_option(char *name);
+static int process_option(option_t *, char **);
+static int n_arguments(option_t *);
+static int number_option(char *, uint32_t *, int);
+
+/*
+ * Structure to store extra lists of options.
+ */
+struct option_list {
+ option_t *options;
+ struct option_list *next;
+};
+
+static struct option_list *extra_options = NULL;
+
+/*
+ * Valid arguments.
+ */
+option_t general_options[] = {
+ { "debug", o_int, &debug,
+ "Increase debugging level", OPT_INC|OPT_NOARG|1, NULL, 0, 0 },
+ { "-d", o_int, &debug,
+ "Increase debugging level", OPT_INC|OPT_NOARG|1, NULL, 0, 0 },
+ { "kdebug", o_int, &kdebugflag,
+ "Set kernel driver debug level", 0, NULL, 0, 0 },
+ { "nodetach", o_bool, &nodetach,
+ "Don't detach from controlling tty", 1, NULL, 0, 0 },
+ { "-detach", o_bool, &nodetach,
+ "Don't detach from controlling tty", 1, NULL, 0, 0 },
+ { "updetach", o_bool, &updetach,
+ "Detach from controlling tty once link is up", 1, NULL, 0, 0 },
+ { "holdoff", o_int, &holdoff,
+ "Set time in seconds before retrying connection", 0, NULL, 0, 0 },
+ { "idle", o_int, &idle_time_limit,
+ "Set time in seconds before disconnecting idle link", 0, NULL, 0, 0 },
+ { "lock", o_bool, &lockflag,
+ "Lock serial device with UUCP-style lock file", 1, NULL, 0, 0 },
+ { "-all", o_special_noarg, noopt,
+ "Don't request/allow any LCP or IPCP options (useless)", 0, NULL, 0, 0 },
+ { "init", o_string, &initializer,
+ "A program to initialize the device",
+ OPT_A2INFO | OPT_PRIVFIX, &initializer_info, 0, 0 },
+ { "connect", o_string, &connect_script,
+ "A program to set up a connection",
+ OPT_A2INFO | OPT_PRIVFIX, &connect_script_info, 0, 0 },
+ { "disconnect", o_string, &disconnect_script,
+ "Program to disconnect serial device",
+ OPT_A2INFO | OPT_PRIVFIX, &disconnect_script_info, 0, 0 },
+ { "welcome", o_string, &welcomer,
+ "Script to welcome client",
+ OPT_A2INFO | OPT_PRIVFIX, &welcomer_info, 0, 0 },
+ { "pty", o_string, &ptycommand,
+ "Script to run on pseudo-tty master side",
+ OPT_A2INFO | OPT_PRIVFIX | OPT_DEVNAM, &ptycommand_info, 0, 0 },
+ { "notty", o_bool, &notty,
+ "Input/output is not a tty", OPT_DEVNAM | 1, NULL, 0, 0 },
+ { "record", o_string, &record_file,
+ "Record characters sent/received to file", 0, NULL, 0, 0 },
+ { "maxconnect", o_int, &maxconnect,
+ "Set connection time limit", OPT_LLIMIT|OPT_NOINCR|OPT_ZEROINF, NULL, 0, 0 },
+ { "crtscts", o_int, &crtscts,
+ "Set hardware (RTS/CTS) flow control", OPT_NOARG|OPT_VAL(1), NULL, 0, 0 },
+ { "nocrtscts", o_int, &crtscts,
+ "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1), NULL, 0, 0 },
+ { "-crtscts", o_int, &crtscts,
+ "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1), NULL, 0, 0 },
+ { "cdtrcts", o_int, &crtscts,
+ "Set alternate hardware (DTR/CTS) flow control", OPT_NOARG|OPT_VAL(2), NULL, 0, 0 },
+ { "nocdtrcts", o_int, &crtscts,
+ "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1), NULL, 0, 0 },
+ { "xonxoff", o_special_noarg, setxonxoff,
+ "Set software (XON/XOFF) flow control", 0, NULL, 0, 0 },
+ { "domain", o_special, setdomain,
+ "Add given domain name to hostname", 0, NULL, 0, 0 },
+ { "mtu", o_int, &lcp_allowoptions[0].mru,
+ "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
+ { "netmask", o_special, setnetmask,
+ "set netmask", 0, NULL, 0, 0 },
+ { "modem", o_bool, &modem,
+ "Use modem control lines", 1, NULL, 0, 0 },
+ { "local", o_bool, &modem,
+ "Don't use modem control lines", 0, NULL, 0, 0 },
+ { "file", o_special, readfile,
+ "Take options from a file", OPT_PREPASS, NULL, 0, 0 },
+ { "call", o_special, callfile,
+ "Take options from a privileged file", OPT_PREPASS, NULL, 0, 0 },
+ { "persist", o_bool, &persist,
+ "Keep on reopening connection after close", 1, NULL, 0, 0 },
+ { "nopersist", o_bool, &persist,
+ "Turn off persist option", 0, NULL, 0, 0 },
+ { "demand", o_bool, &demand,
+ "Dial on demand", OPT_INITONLY | 1, &persist, 0, 0 },
+ { "sync", o_bool, &sync_serial,
+ "Use synchronous HDLC serial encoding", 1, NULL, 0, 0 },
+ { "logfd", o_int, &log_to_fd,
+ "Send log messages to this file descriptor", 0, NULL, 0, 0 },
+ { "logfile", o_special, setlogfile,
+ "Append log messages to this file", 0, NULL, 0, 0 },
+ { "nolog", o_int, &log_to_fd,
+ "Don't send log messages to any file",
+ OPT_NOARG | OPT_VAL(-1), NULL, 0, 0 },
+ { "nologfd", o_int, &log_to_fd,
+ "Don't send log messages to any file descriptor",
+ OPT_NOARG | OPT_VAL(-1), NULL, 0, 0 },
+ { "linkname", o_string, linkname,
+ "Set logical name for link",
+ OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN, 0 },
+ { "maxfail", o_int, &maxfail,
+ "Maximum number of unsuccessful connection attempts to allow", 0, NULL, 0, 0 },
+ { "ktune", o_bool, &tune_kernel,
+ "Alter kernel settings as necessary", 1, NULL, 0, 0 },
+ { "noktune", o_bool, &tune_kernel,
+ "Don't alter kernel settings", 0, NULL, 0, 0 },
+ { "connect-delay", o_int, &connect_delay,
+ "Maximum time (in ms) to wait after connect script finishes", 0, NULL, 0, 0 },
+#ifdef PLUGIN
+ { "plugin", o_special, loadplugin,
+ "Load a plug-in module into pppd", OPT_PRIV, NULL, 0, 0 },
+#endif
+
+#ifdef PPP_FILTER
+ { "pdebug", o_int, &dflag,
+ "libpcap debugging", 0, NULL, 0, 0 },
+ { "pass-filter", 1, setpassfilter,
+ "set filter for packets to pass", 0, NULL, 0, 0 },
+ { "active-filter", 1, setactivefilter,
+ "set filter for active pkts", 0, NULL, 0, 0 },
+#endif
+
+ { NULL, 0, NULL, NULL, 0, NULL, 0, 0 }
+};
+
+#ifndef IMPLEMENTATION
+#define IMPLEMENTATION ""
+#endif
+
+static char *usage_string = "\
+pppd version %s.%d%s\n\
+Usage: %s [ options ], where options are:\n\
+ <device> Communicate over the named device\n\
+ <speed> Set the baud rate to <speed>\n\
+ <loc>:<rem> Set the local and/or remote interface IP\n\
+ addresses. Either one may be omitted.\n\
+ asyncmap <n> Set the desired async map to hex <n>\n\
+ auth Require authentication from peer\n\
+ connect <p> Invoke shell command <p> to set up the serial line\n\
+ crtscts Use hardware RTS/CTS flow control\n\
+ defaultroute Add default route through interface\n\
+ file <f> Take options from file <f>\n\
+ modem Use modem control lines\n\
+ mru <n> Set MRU value to <n> for negotiation\n\
+See pppd(8) for more options.\n\
+";
+
+/*
+ * parse_args - parse a string of arguments from the command line.
+ * If prepass is true, we are scanning for the device name and only
+ * processing a few options, so error messages are suppressed.
+ */
+int
+parse_args(
+ int argc,
+ char **argv)
+{
+ char *arg;
+ option_t *opt;
+ int ret;
+
+ privileged_option = privileged;
+ option_source = "command line";
+ while (argc > 0) {
+ arg = *argv++;
+ --argc;
+
+ /*
+ * First see if it's an option in the new option list.
+ */
+ opt = find_option(arg);
+ if (opt != NULL) {
+ int n = n_arguments(opt);
+ if (argc < n) {
+ option_error("too few parameters for option %s", arg);
+ return 0;
+ }
+ current_option = arg;
+ if (!process_option(opt, argv))
+ return 0;
+ argc -= n;
+ argv += n;
+ continue;
+ }
+
+ /*
+ * Maybe a tty name, speed or IP address?
+ */
+ if ((ret = setdevname(arg)) == 0
+ && (ret = setspeed(arg)) == 0
+ && (ret = setipaddr(arg)) == 0
+ && !prepass) {
+ option_error("unrecognized option '%s'", arg);
+ usage();
+ return 0;
+ }
+ if (ret < 0) /* error */
+ return 0;
+ }
+ return 1;
+}
+
+#if 0
+/*
+ * scan_args - scan the command line arguments to get the tty name,
+ * if specified. Also checks whether the notty or pty option was given.
+ */
+void
+scan_args(argc, argv)
+ int argc;
+ char **argv;
+{
+ char *arg;
+ option_t *opt;
+
+ privileged_option = privileged;
+ while (argc > 0) {
+ arg = *argv++;
+ --argc;
+
+ if (strcmp(arg, "notty") == 0 || strcmp(arg, "pty") == 0)
+ using_pty = 1;
+
+ /* Skip options and their arguments */
+ opt = find_option(arg);
+ if (opt != NULL) {
+ int n = n_arguments(opt);
+ argc -= n;
+ argv += n;
+ continue;
+ }
+
+ /* Check if it's a tty name and copy it if so */
+ (void) setdevname(arg, 1);
+ }
+}
+#endif
+
+/*
+ * options_from_file - Read a string of options from a file,
+ * and interpret them.
+ */
+int
+options_from_file(
+ char *filename,
+ int must_exist,
+ int check_prot,
+ int priv)
+{
+ FILE *f;
+ int i, newline, ret, err;
+ option_t *opt;
+ int oldpriv;
+ char *oldsource;
+ char *argv[MAXARGS];
+ char args[MAXARGS][MAXWORDLEN];
+ char cmd[MAXWORDLEN];
+
+ f = fopen(filename, "r");
+ err = errno;
+ if (f == NULL) {
+ if (!must_exist && err == ENOENT)
+ return 1;
+ errno = err;
+ option_error("Can't open options file %s: %m", filename);
+ return 0;
+ }
+
+ oldpriv = privileged_option;
+ privileged_option = priv;
+ oldsource = option_source;
+ option_source = strdup(filename);
+ if (option_source == NULL)
+ option_source = "file";
+ ret = 0;
+ while (getword(f, cmd, &newline, filename)) {
+ /*
+ * First see if it's a command.
+ */
+ opt = find_option(cmd);
+ if (opt != NULL) {
+ int n = n_arguments(opt);
+ for (i = 0; i < n; ++i) {
+ if (!getword(f, args[i], &newline, filename)) {
+ option_error(
+ "In file %s: too few parameters for option '%s'",
+ filename, cmd);
+ goto err;
+ }
+ argv[i] = args[i];
+ }
+ current_option = cmd;
+ if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
+ option_error("the %s option may not be used in the %s file",
+ cmd, filename);
+ goto err;
+ }
+ if (!process_option(opt, argv))
+ goto err;
+ continue;
+ }
+
+ /*
+ * Maybe a tty name, speed or IP address?
+ */
+ if ((i = setdevname(cmd)) == 0
+ && (i = setspeed(cmd)) == 0
+ && (i = setipaddr(cmd)) == 0) {
+ option_error("In file %s: unrecognized option '%s'",
+ filename, cmd);
+ goto err;
+ }
+ if (i < 0) /* error */
+ goto err;
+ }
+ ret = 1;
+
+err:
+ fclose(f);
+ privileged_option = oldpriv;
+ option_source = oldsource;
+ return ret;
+}
+
+/*
+ * options_from_user - See if the use has a ~/.ppprc file,
+ * and if so, interpret options from it.
+ */
+int
+options_from_user(void)
+{
+ return 0;
+}
+
+/*
+ * options_for_tty - See if an options file exists for the serial
+ * device, and if so, interpret options from it.
+ */
+int
+options_for_tty(void)
+{
+ char *dev, *path, *p;
+ int ret;
+ size_t pl;
+
+ dev = devnam;
+ if (strncmp(dev, "/dev/", 5) == 0)
+ dev += 5;
+ if (dev[0] == 0 || strcmp(dev, "tty") == 0)
+ return 1; /* don't look for /etc/ppp/options.tty */
+ pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
+ path = malloc(pl);
+ if (path == NULL)
+ novm("tty init file name");
+ slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
+ /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
+ for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
+ if (*p == '/')
+ *p = '.';
+ ret = options_from_file(path, 0, 0, 1);
+ free(path);
+ return ret;
+}
+
+/*
+ * options_from_list - process a string of options in a wordlist.
+ */
+int
+options_from_list(
+ struct wordlist *w,
+ int priv)
+{
+ char *argv[MAXARGS];
+ option_t *opt;
+ int i, ret = 0;
+
+ privileged_option = priv;
+ option_source = "secrets file";
+
+ while (w != NULL) {
+ /*
+ * First see if it's a command.
+ */
+ opt = find_option(w->word);
+ if (opt != NULL) {
+ int n = n_arguments(opt);
+ struct wordlist *w0 = w;
+ for (i = 0; i < n; ++i) {
+ w = w->next;
+ if (w == NULL) {
+ option_error(
+ "In secrets file: too few parameters for option '%s'",
+ w0->word);
+ goto err;
+ }
+ argv[i] = w->word;
+ }
+ current_option = w0->word;
+ if (!process_option(opt, argv))
+ goto err;
+ w = w->next;
+ continue;
+ }
+
+ /*
+ * Maybe a tty name, speed or IP address?
+ */
+ if ((i = setdevname(w->word)) == 0
+ && (i = setspeed(w->word)) == 0
+ && (i = setipaddr(w->word)) == 0) {
+ option_error("In secrets file: unrecognized option '%s'",
+ w->word);
+ goto err;
+ }
+ if (i < 0) /* error */
+ goto err;
+ w = w->next;
+ }
+ ret = 1;
+
+err:
+ return ret;
+}
+
+/*
+ * find_option - scan the option lists for the various protocols
+ * looking for an entry with the given name.
+ * This could be optimized by using a hash table.
+ */
+static option_t *
+find_option(char *name)
+{
+ option_t *opt;
+ struct option_list *list;
+ int i;
+
+ for (list = extra_options; list != NULL; list = list->next)
+ for (opt = list->options; opt->name != NULL; ++opt)
+ if (strcmp(name, opt->name) == 0)
+ return opt;
+ for (opt = general_options; opt->name != NULL; ++opt)
+ if (strcmp(name, opt->name) == 0)
+ return opt;
+ for (opt = auth_options; opt->name != NULL; ++opt)
+ if (strcmp(name, opt->name) == 0)
+ return opt;
+ for (i = 0; protocols[i] != NULL; ++i)
+ if ((opt = protocols[i]->options) != NULL)
+ for (; opt->name != NULL; ++opt)
+ if (strcmp(name, opt->name) == 0)
+ return opt;
+ return NULL;
+}
+
+/*
+ * process_option - process one new-style option.
+ */
+static int
+process_option(
+ option_t *opt,
+ char **argv)
+{
+ uint32_t v;
+ int iv, a;
+ char *sv;
+ int (*parser)(char **);
+
+ if ((opt->flags & OPT_PREPASS) == 0 && prepass)
+ return 1;
+ if ((opt->flags & OPT_INITONLY) && pppd_phase != PHASE_INITIALIZE) {
+ option_error("it's too late to use the %s option", opt->name);
+ return 0;
+ }
+ if ((opt->flags & OPT_PRIV) && !privileged_option) {
+ option_error("using the %s option requires root privilege", opt->name);
+ return 0;
+ }
+ if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
+ option_error("%s option is disabled", opt->name);
+ return 0;
+ }
+ if ((opt->flags & OPT_PRIVFIX) && !privileged_option) {
+ struct option_info *ip = (struct option_info *) opt->addr2;
+ if (ip && ip->priv) {
+ option_error("%s option cannot be overridden", opt->name);
+ return 0;
+ }
+ }
+
+ switch (opt->type) {
+ case o_bool:
+ v = opt->flags & OPT_VALUE;
+ *(bool *)(opt->addr) = v;
+ if (opt->addr2 && (opt->flags & OPT_A2COPY))
+ *(bool *)(opt->addr2) = v;
+ break;
+
+ case o_int:
+ iv = 0;
+ if ((opt->flags & OPT_NOARG) == 0) {
+ if (!int_option(*argv, &iv))
+ return 0;
+ if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
+ || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
+ && !((opt->flags & OPT_ZEROOK && iv == 0))) {
+ char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
+ switch (opt->flags & OPT_LIMITS) {
+ case OPT_LLIMIT:
+ option_error("%s value must be%s >= %d",
+ opt->name, zok, opt->lower_limit);
+ break;
+ case OPT_ULIMIT:
+ option_error("%s value must be%s <= %d",
+ opt->name, zok, opt->upper_limit);
+ break;
+ case OPT_LIMITS:
+ option_error("%s value must be%s between %d and %d",
+ opt->name, opt->lower_limit, opt->upper_limit);
+ break;
+ }
+ return 0;
+ }
+ }
+ a = opt->flags & OPT_VALUE;
+ if (a >= 128)
+ a -= 256; /* sign extend */
+ iv += a;
+ if (opt->flags & OPT_INC)
+ iv += *(int *)(opt->addr);
+ if ((opt->flags & OPT_NOINCR) && !privileged_option) {
+ int oldv = *(int *)(opt->addr);
+ if ((opt->flags & OPT_ZEROINF) ?
+ (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
+ option_error("%s value cannot be increased", opt->name);
+ return 0;
+ }
+ }
+ *(int *)(opt->addr) = iv;
+ if (opt->addr2 && (opt->flags & OPT_A2COPY))
+ *(int *)(opt->addr2) = iv;
+ break;
+
+ case o_uint32:
+ if (opt->flags & OPT_NOARG) {
+ v = opt->flags & OPT_VALUE;
+ } else if (!number_option(*argv, &v, 16))
+ return 0;
+ if (opt->flags & OPT_OR)
+ v |= *(uint32_t *)(opt->addr);
+ *(uint32_t *)(opt->addr) = v;
+ if (opt->addr2 && (opt->flags & OPT_A2COPY))
+ *(uint32_t *)(opt->addr2) = v;
+ break;
+
+ case o_string:
+ if (opt->flags & OPT_STATIC) {
+ strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
+ } else {
+ sv = strdup(*argv);
+ if (sv == NULL)
+ novm("option argument");
+ if ( *(char **)(opt->addr) != NULL ) {
+ free((void *)*(char **)(opt->addr));
+ *(char **)(opt->addr) = NULL;
+ }
+ *(char **)(opt->addr) = sv;
+ }
+ break;
+
+ case o_special_noarg:
+ case o_special:
+ parser = (int (*)(char **)) opt->addr;
+ if (!(*parser)(argv))
+ return 0;
+ break;
+ }
+
+ if (opt->addr2) {
+ if (opt->flags & OPT_A2INFO) {
+ struct option_info *ip = (struct option_info *) opt->addr2;
+ ip->priv = privileged_option;
+ ip->source = option_source;
+ } else if ((opt->flags & (OPT_A2COPY|OPT_ENABLE)) == 0)
+ *(bool *)(opt->addr2) = 1;
+ }
+
+ return 1;
+}
+
+/*
+ * n_arguments - tell how many arguments an option takes
+ */
+static int
+n_arguments(
+ option_t *opt)
+{
+ return (opt->type == o_bool || opt->type == o_special_noarg
+ || (opt->flags & OPT_NOARG))? 0: 1;
+}
+
+/*
+ * add_options - add a list of options to the set we grok.
+ */
+void
+add_options(
+ option_t *opt)
+{
+ struct option_list *list;
+
+ list = malloc(sizeof(*list));
+ if (list == 0)
+ novm("option list entry");
+ list->options = opt;
+ list->next = extra_options;
+ extra_options = list;
+}
+
+/*
+ * usage - print out a message telling how to use the program.
+ */
+static void
+usage(void)
+{
+ if (pppd_phase == PHASE_INITIALIZE)
+ fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
+ "rtems_pppd");
+}
+
+/*
+ * option_error - print a message about an error in an option.
+ * The message is logged, and also sent to
+ * stderr if pppd_phase == PHASE_INITIALIZE.
+ */
+void
+option_error __V((char *fmt, ...))
+{
+ va_list args;
+ char buf[256];
+
+#if defined(__STDC__)
+ va_start(args, fmt);
+#else
+ char *fmt;
+ va_start(args);
+ fmt = va_arg(args, char *);
+#endif
+ if (prepass) {
+ va_end(args);
+ return;
+ }
+ vslprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
+
+ fprintf(stderr, "pppd: %s\n", buf);
+}
+
+/*
+ * Read a word from a file.
+ * Words are delimited by white-space or by quotes (" or ').
+ * Quotes, white-space and \ may be escaped with \.
+ * \<newline> is ignored.
+ */
+int
+getword(
+ FILE *f,
+ char *word,
+ int *newlinep,
+ char *filename)
+{
+ int c, len, escape;
+ int quoted, comment;
+ int value, digit, got, n;
+
+#define isoctal(c) ((c) >= '0' && (c) < '8')
+
+ *newlinep = 0;
+ len = 0;
+ escape = 0;
+ comment = 0;
+
+ /*
+ * First skip white-space and comments.
+ */
+ for (;;) {
+ c = getc(f);
+ if (c == EOF)
+ break;
+
+ /*
+ * A newline means the end of a comment; backslash-newline
+ * is ignored. Note that we cannot have escape && comment.
+ */
+ if (c == '\n') {
+ if (!escape) {
+ *newlinep = 1;
+ comment = 0;
+ } else
+ escape = 0;
+ continue;
+ }
+
+ /*
+ * Ignore characters other than newline in a comment.
+ */
+ if (comment)
+ continue;
+
+ /*
+ * If this character is escaped, we have a word start.
+ */
+ if (escape)
+ break;
+
+ /*
+ * If this is the escape character, look at the next character.
+ */
+ if (c == '\\') {
+ escape = 1;
+ continue;
+ }
+
+ /*
+ * If this is the start of a comment, ignore the rest of the line.
+ */
+ if (c == '#') {
+ comment = 1;
+ continue;
+ }
+
+ /*
+ * A non-whitespace character is the start of a word.
+ */
+ if (!isspace(c))
+ break;
+ }
+
+ /*
+ * Save the delimiter for quoted strings.
+ */
+ if (!escape && (c == '"' || c == '\'')) {
+ quoted = c;
+ c = getc(f);
+ } else
+ quoted = 0;
+
+ /*
+ * Process characters until the end of the word.
+ */
+ while (c != EOF) {
+ if (escape) {
+ /*
+ * This character is escaped: backslash-newline is ignored,
+ * various other characters indicate particular values
+ * as for C backslash-escapes.
+ */
+ escape = 0;
+ if (c == '\n') {
+ c = getc(f);
+ continue;
+ }
+
+ got = 0;
+ switch (c) {
+ case 'a':
+ value = '\a';
+ break;
+ case 'b':
+ value = '\b';
+ break;
+ case 'f':
+ value = '\f';
+ break;
+ case 'n':
+ value = '\n';
+ break;
+ case 'r':
+ value = '\r';
+ break;
+ case 's':
+ value = ' ';
+ break;
+ case 't':
+ value = '\t';
+ break;
+
+ default:
+ if (isoctal(c)) {
+ /*
+ * \ddd octal sequence
+ */
+ value = 0;
+ for (n = 0; n < 3 && isoctal(c); ++n) {
+ value = (value << 3) + (c & 07);
+ c = getc(f);
+ }
+ got = 1;
+ break;
+ }
+
+ if (c == 'x') {
+ /*
+ * \x<hex_string> sequence
+ */
+ value = 0;
+ c = getc(f);
+ for (n = 0; n < 2 && isxdigit(c); ++n) {
+ digit = toupper(c) - '0';
+ if (digit > 10)
+ digit += '0' + 10 - 'A';
+ value = (value << 4) + digit;
+ c = getc (f);
+ }
+ got = 1;
+ break;
+ }
+
+ /*
+ * Otherwise the character stands for itself.
+ */
+ value = c;
+ break;
+ }
+
+ /*
+ * Store the resulting character for the escape sequence.
+ */
+ if (len < MAXWORDLEN-1)
+ word[len] = value;
+ ++len;
+
+ if (!got)
+ c = getc(f);
+ continue;
+
+ }
+
+ /*
+ * Not escaped: see if we've reached the end of the word.
+ */
+ if (quoted) {
+ if (c == quoted)
+ break;
+ } else {
+ if (isspace(c) || c == '#') {
+ ungetc (c, f);
+ break;
+ }
+ }
+
+ /*
+ * Backslash starts an escape sequence.
+ */
+ if (c == '\\') {
+ escape = 1;
+ c = getc(f);
+ continue;
+ }
+
+ /*
+ * An ordinary character: store it in the word and get another.
+ */
+ if (len < MAXWORDLEN-1)
+ word[len] = c;
+ ++len;
+
+ c = getc(f);
+ }
+
+ /*
+ * End of the word: check for errors.
+ */
+ if (c == EOF) {
+ if (ferror(f)) {
+ if (errno == 0)
+ errno = EIO;
+ option_error("Error reading %s: %m", filename);
+ die(1);
+ }
+ /*
+ * If len is zero, then we didn't find a word before the
+ * end of the file.
+ */
+ if (len == 0)
+ return 0;
+ }
+
+ /*
+ * Warn if the word was too long, and append a terminating null.
+ */
+ if (len >= MAXWORDLEN) {
+ option_error("warning: word in file %s too long (%.20s...)",
+ filename, word);
+ len = MAXWORDLEN - 1;
+ }
+ word[len] = 0;
+
+ return 1;
+
+#undef isoctal
+
+}
+
+/*
+ * number_option - parse an unsigned numeric parameter for an option.
+ */
+static int
+number_option(
+ char *str,
+ uint32_t *valp,
+ int base)
+{
+ char *ptr;
+
+ *valp = strtoul(str, &ptr, base);
+ if (ptr == str) {
+ option_error("invalid numeric parameter '%s' for %s option",
+ str, current_option);
+ return 0;
+ }
+ return 1;
+}
+
+
+/*
+ * int_option - like number_option, but valp is int *,
+ * the base is assumed to be 0, and *valp is not changed
+ * if there is an error.
+ */
+int
+int_option(
+ char *str,
+ int *valp)
+{
+ uint32_t v;
+
+ if (!number_option(str, &v, 0))
+ return 0;
+ *valp = (int) v;
+ return 1;
+}
+
+
+/*
+ * The following procedures parse options.
+ */
+
+/*
+ * readfile - take commands from a file.
+ */
+static int
+readfile(
+ char **argv)
+{
+ return options_from_file(*argv, 1, 1, privileged_option);
+}
+
+/*
+ * callfile - take commands from /etc/ppp/peers/<name>.
+ * Name may not contain /../, start with / or ../, or end in /..
+ */
+static int
+callfile(
+ char **argv)
+{
+ char *fname, *arg, *p;
+ int l, ok;
+
+ arg = *argv;
+ ok = 1;
+ if (arg[0] == '/' || arg[0] == 0)
+ ok = 0;
+ else {
+ for (p = arg; *p != 0; ) {
+ if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
+ ok = 0;
+ break;
+ }
+ while (*p != '/' && *p != 0)
+ ++p;
+ if (*p == '/')
+ ++p;
+ }
+ }
+ if (!ok) {
+ option_error("call option value may not contain .. or start with /");
+ return 0;
+ }
+
+ l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
+ if ((fname = (char *) malloc(l)) == NULL)
+ novm("call file name");
+ slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
+
+ ok = options_from_file(fname, 1, 1, 1);
+
+ free(fname);
+ return ok;
+}
+
+#ifdef PPP_FILTER
+/*
+ * setpdebug - Set libpcap debugging level.
+ */
+static int
+setpdebug(
+ char **argv)
+{
+ return int_option(*argv, &dflag);
+}
+
+/*
+ * setpassfilter - Set the pass filter for packets
+ */
+static int
+setpassfilter(
+ char **argv)
+{
+ pc.linktype = DLT_PPP;
+ pc.snapshot = PPP_HDRLEN;
+
+ if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
+ return 1;
+ option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
+ return 0;
+}
+
+/*
+ * setactivefilter - Set the active filter for packets
+ */
+static int
+setactivefilter(
+ char **argv)
+{
+ pc.linktype = DLT_PPP;
+ pc.snapshot = PPP_HDRLEN;
+
+ if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
+ return 1;
+ option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
+ return 0;
+}
+#endif
+
+/*
+ * noopt - Disable all options.
+ */
+static int
+noopt(
+ char **argv)
+{
+ BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
+ BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
+ BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
+ BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
+
+ return (1);
+}
+
+/*
+ * setdomain - Set domain name to append to hostname
+ */
+static int
+setdomain(
+ char **argv)
+{
+ if (!privileged_option) {
+ option_error("using the domain option requires root privilege");
+ return 0;
+ }
+ gethostname(hostname, MAXNAMELEN);
+ if (**argv != 0) {
+ if (**argv != '.')
+ strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
+ strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
+ }
+ hostname[MAXNAMELEN-1] = 0;
+ return (1);
+}
+
+
+/*
+ * setspeed - Set the speed.
+ */
+static int
+setspeed(
+ char *arg)
+{
+ long spd;
+ uint32_t ret = 1;
+ speed_t spdValue = 0;
+ char *ptr;
+
+ if ( !prepass ) {
+ spd = strtol(arg, &ptr, 0);
+ if (ptr == arg || *ptr != 0 || spd == 0) {
+ ret = 0;
+ }
+ else {
+ switch ( spd ) {
+ case 2400L:
+ spdValue = B2400;
+ break;
+ case 4800L:
+ spdValue = B4800;
+ break;
+ case 9600L:
+ spdValue = B9600;
+ break;
+ case 19200L:
+ spdValue = B19200;
+ break;
+ case 38400L:
+ spdValue = B38400;
+ break;
+ case 57600L:
+ spdValue = B57600;
+ break;
+ case 115200L:
+ spdValue = B115200;
+ break;
+ default:
+ ret = 0;
+ break;
+ }
+
+ if ( spdValue ) {
+ inspeed = spdValue;
+ }
+ }
+ }
+
+ return ( ret );
+}
+
+
+/*
+ * setdevname - Set the device name.
+ */
+static int
+setdevname(
+ char *cp)
+{
+ struct stat statbuf;
+ char dev[MAXPATHLEN];
+
+ if (*cp == 0)
+ return 0;
+
+ if (strncmp("/dev/", cp, 5) != 0) {
+ strlcpy(dev, "/dev/", sizeof(dev));
+ strlcat(dev, cp, sizeof(dev));
+ cp = dev;
+ }
+
+ /*
+ * Check if there is a character device by this name.
+ */
+ if (stat(cp, &statbuf) < 0) {
+ if (errno == ENOENT)
+ return 0;
+ option_error("Couldn't stat %s: %m", cp);
+ return -1;
+ }
+ if (!S_ISCHR(statbuf.st_mode)) {
+ option_error("%s is not a character device", cp);
+ return -1;
+ }
+
+ if (pppd_phase != PHASE_INITIALIZE) {
+ option_error("device name cannot be changed after initialization");
+ return -1;
+ } else if (devnam_fixed) {
+ option_error("per-tty options file may not specify device name");
+ return -1;
+ }
+
+ if (devnam_info.priv && !privileged_option) {
+ option_error("device name cannot be overridden");
+ return -1;
+ }
+
+ strlcpy(devnam, cp, sizeof(devnam));
+ devstat = statbuf;
+ default_device = 0;
+ devnam_info.priv = privileged_option;
+ devnam_info.source = option_source;
+
+ return 1;
+}
+
+
+/*
+ * setipaddr - Set the IP address
+ */
+static int
+setipaddr(
+ char *arg)
+{
+ struct hostent *hp;
+ char *colon;
+ uint32_t local, remote;
+ ipcp_options *wo = &ipcp_wantoptions[0];
+
+ /*
+ * IP address pair separated by ":".
+ */
+ if ((colon = strchr(arg, ':')) == NULL)
+ return 0;
+ if (prepass)
+ return 1;
+
+ /*
+ * If colon first character, then no local addr.
+ */
+ if (colon != arg) {
+ *colon = '\0';
+ if ((local = inet_addr(arg)) == (uint32_t) -1) {
+ if ((hp = gethostbyname(arg)) == NULL) {
+ option_error("unknown host: %s", arg);
+ return -1;
+ } else {
+ local = *(uint32_t *)hp->h_addr;
+ }
+ }
+ if (bad_ip_adrs(local)) {
+ option_error("bad local IP address %s", ip_ntoa(local));
+ return -1;
+ }
+ if (local != 0)
+ wo->ouraddr = local;
+ *colon = ':';
+ }
+
+ /*
+ * If colon last character, then no remote addr.
+ */
+ if (*++colon != '\0') {
+ if ((remote = inet_addr(colon)) == (uint32_t) -1) {
+ if ((hp = gethostbyname(colon)) == NULL) {
+ option_error("unknown host: %s", colon);
+ return -1;
+ } else {
+ remote = *(uint32_t *)hp->h_addr;
+ if (remote_name[0] == 0)
+ strlcpy(remote_name, colon, sizeof(remote_name));
+ }
+ }
+ if (bad_ip_adrs(remote)) {
+ option_error("bad remote IP address %s", ip_ntoa(remote));
+ return -1;
+ }
+ if (remote != 0)
+ wo->hisaddr = remote;
+ }
+
+ return 1;
+}
+
+
+/*
+ * setnetmask - set the netmask to be used on the interface.
+ */
+static int
+setnetmask(
+ char **argv)
+{
+ uint32_t mask, b;
+ int n, ok;
+ char *p, *endp;
+
+ /*
+ * Unfortunately, if we use inet_addr, we can't tell whether
+ * a result of all 1s is an error or a valid 255.255.255.255.
+ */
+ p = *argv;
+ ok = 0;
+ mask = 0;
+ for (n = 3;; --n) {
+ b = strtoul(p, &endp, 0);
+ if (endp == p)
+ break;
+ if (b > 255) {
+ if (n == 3) {
+ /* accept e.g. 0xffffff00 */
+ p = endp;
+ mask = b;
+ }
+ break;
+ }
+ mask |= b << (n * 8);
+ p = endp;
+ if (*p != '.' || n == 0)
+ break;
+ ++p;
+ }
+
+ mask = htonl(mask);
+
+ if (*p != 0 || (netmask & ~mask) != 0) {
+ option_error("invalid netmask value '%s'", *argv);
+ return 0;
+ }
+
+ netmask = mask;
+ return (1);
+}
+
+static int
+setxonxoff(
+ char **argv)
+{
+ lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
+ lcp_wantoptions[0].neg_asyncmap = 1;
+
+ crtscts = -2;
+ return (1);
+}
+
+static int
+setlogfile(
+ char **argv)
+{
+ int fd, err;
+
+ fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
+ if (fd < 0 && errno == EEXIST)
+ fd = open(*argv, O_WRONLY | O_APPEND);
+ err = errno;
+ if (fd < 0) {
+ errno = err;
+ option_error("Can't open log file %s: %m", *argv);
+ return 0;
+ }
+ if (log_to_file && log_to_fd >= 0)
+ close(log_to_fd);
+ log_to_fd = fd;
+ log_to_file = 1;
+ return 1;
+}
+
+#ifdef PLUGIN
+static int
+loadplugin(
+ char **argv)
+{
+ char *arg = *argv;
+ void *handle;
+ const char *err;
+ void (*init)(void);
+
+ handle = dlopen(arg, RTLD_GLOBAL | RTLD_NOW);
+ if (handle == 0) {
+ err = dlerror();
+ if (err != 0)
+ option_error("%s", err);
+ option_error("Couldn't load plugin %s", arg);
+ return 0;
+ }
+ init = dlsym(handle, "plugin_init");
+ if (init == 0) {
+ option_error("%s has no initialization entry point", arg);
+ dlclose(handle);
+ return 0;
+ }
+ info("Plugin %s loaded.", arg);
+ (*init)();
+ return 1;
+}
+#endif /* PLUGIN */
diff --git a/cpukit/pppd/patchlevel.h b/cpukit/pppd/patchlevel.h
new file mode 100644
index 0000000000..54d88b8a66
--- /dev/null
+++ b/cpukit/pppd/patchlevel.h
@@ -0,0 +1,6 @@
+/* $Id$ */
+#define PATCHLEVEL 11
+
+#define VERSION "2.3"
+#define IMPLEMENTATION ""
+#define DATE "23 December 1999"
diff --git a/cpukit/pppd/pathnames.h b/cpukit/pppd/pathnames.h
new file mode 100644
index 0000000000..0a4f6e69f2
--- /dev/null
+++ b/cpukit/pppd/pathnames.h
@@ -0,0 +1,43 @@
+/*
+ * define path names
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+
+#else
+#ifndef _PATH_VARRUN
+#define _PATH_VARRUN "/etc/ppp/"
+#endif
+#define _PATH_DEVNULL "/dev/null"
+#endif
+
+#ifndef _ROOT_PATH
+#define _ROOT_PATH
+#endif
+
+#define _PATH_UPAPFILE _ROOT_PATH "/etc/ppp/pap-secrets"
+#define _PATH_CHAPFILE _ROOT_PATH "/etc/ppp/chap-secrets"
+#define _PATH_SYSOPTIONS _ROOT_PATH "/etc/ppp/options"
+#define _PATH_IPUP _ROOT_PATH "/etc/ppp/ip-up"
+#define _PATH_IPDOWN _ROOT_PATH "/etc/ppp/ip-down"
+#define _PATH_AUTHUP _ROOT_PATH "/etc/ppp/auth-up"
+#define _PATH_AUTHDOWN _ROOT_PATH "/etc/ppp/auth-down"
+#define _PATH_TTYOPT _ROOT_PATH "/etc/ppp/options."
+#define _PATH_CONNERRS _ROOT_PATH "/etc/ppp/connect-errors"
+#define _PATH_PEERFILES _ROOT_PATH "/etc/ppp/peers/"
+#define _PATH_RESOLV _ROOT_PATH "/etc/ppp/resolv.conf"
+
+#define _PATH_USEROPT ".ppprc"
+
+#ifdef INET6
+#define _PATH_IPV6UP _ROOT_PATH "/etc/ppp/ipv6-up"
+#define _PATH_IPV6DOWN _ROOT_PATH "/etc/ppp/ipv6-down"
+#endif
+
+#ifdef IPX_CHANGE
+#define _PATH_IPXUP _ROOT_PATH "/etc/ppp/ipx-up"
+#define _PATH_IPXDOWN _ROOT_PATH "/etc/ppp/ipx-down"
+#endif /* IPX_CHANGE */
diff --git a/cpukit/pppd/pppd.8 b/cpukit/pppd/pppd.8
new file mode 100644
index 0000000000..227345ff5f
--- /dev/null
+++ b/cpukit/pppd/pppd.8
@@ -0,0 +1,1480 @@
+.\" manual page [] for pppd 2.3
+.\" $Id$
+.\" SH section heading
+.\" SS subsection heading
+.\" LP paragraph
+.\" IP indented paragraph
+.\" TP hanging label
+.TH PPPD 8
+.SH NAME
+pppd \- Point to Point Protocol daemon
+.SH SYNOPSIS
+.B pppd
+[
+.I tty_name
+] [
+.I speed
+] [
+.I options
+]
+.SH DESCRIPTION
+.LP
+The Point-to-Point Protocol (PPP) provides a method for transmitting
+datagrams over serial point-to-point links. PPP
+is composed of three parts: a method for encapsulating datagrams over
+serial links, an extensible Link Control Protocol (LCP), and
+a family of Network Control Protocols (NCP) for establishing
+and configuring different network-layer protocols.
+.LP
+The encapsulation scheme is provided by driver code in the kernel.
+Pppd provides the basic LCP, authentication support, and an NCP for
+establishing and configuring the Internet Protocol (IP) (called the IP
+Control Protocol, IPCP).
+.SH FREQUENTLY USED OPTIONS
+.TP
+.I <tty_name>
+Communicate over the named device. The string "/dev/" is prepended if
+necessary. If no device name is given, or if the name of the terminal
+connected to the standard input is given, pppd will use that terminal,
+and will not fork to put itself in the background. A value for this
+option from a privileged source cannot be overridden by a
+non-privileged user.
+.TP
+.I <speed>
+Set the baud rate to <speed> (a decimal number). On systems such as
+4.4BSD and NetBSD, any speed can be specified. Other systems
+(e.g. SunOS) allow only a limited set of speeds.
+.TP
+.B asyncmap \fI<map>
+Set the async character map to <map>. This map describes which
+control characters cannot be successfully received over the serial
+line. Pppd will ask the peer to send these characters as a 2-byte
+escape sequence. The argument is a 32 bit hex number with each bit
+representing a character to escape. Bit 0 (00000001) represents the
+character 0x00; bit 31 (80000000) represents the character 0x1f or ^_.
+If multiple \fIasyncmap\fR options are given, the values are ORed
+together. If no \fIasyncmap\fR option is given, no async character
+map will be negotiated for the receive direction; the peer should then
+escape \fIall\fR control characters. To escape transmitted
+characters, use the \fIescape\fR option.
+.TP
+.B auth
+Require the peer to authenticate itself before allowing network
+packets to be sent or received. This option is the default if the
+system has a default route. If neither this option nor the
+\fInoauth\fR option is specified, pppd will only allow the peer to use
+IP addresses to which the system does not already have a route.
+.TP
+.B call \fIname
+Read options from the file /etc/ppp/peers/\fIname\fR. This file may
+contain privileged options, such as \fInoauth\fR, even if pppd
+is not being run by root. The \fIname\fR string may not begin with /
+or include .. as a pathname component. The format of the options file
+is described below.
+.TP
+.B connect \fIscript
+Use the executable or shell command specified by \fIscript\fR to set
+up the serial line. This script would typically use the chat(8)
+program to dial the modem and start the remote ppp session. A value
+for this option from a privileged source cannot be overridden by a
+non-privileged user.
+.TP
+.B crtscts
+Use hardware flow control (i.e. RTS/CTS) to control the flow of
+data on the serial port. If neither the \fIcrtscts\fR, the
+\fInocrtscts\fR, the \fIcdtrcts\fR nor the \fInocdtrcts\fR option
+is given, the hardware flow control setting for the serial port is
+left unchanged.
+Some serial ports (such as Macintosh serial ports) lack a true
+RTS output. Such serial ports use this mode to implement
+unidirectional flow control. The serial port will
+suspend transmission when requested by the modem (via CTS)
+but will be unable to request the modem stop sending to the
+computer. This mode retains the ability to use DTR as
+a modem control line.
+.TP
+.B defaultroute
+Add a default route to the system routing tables, using the peer as
+the gateway, when IPCP negotiation is successfully completed.
+This entry is removed when the PPP connection is broken. This option
+is privileged if the \fInodefaultroute\fR option has been specified.
+.TP
+.B disconnect \fIscript
+Run the executable or shell command specified by \fIscript\fR after
+pppd has terminated the link. This script could, for example, issue
+commands to the modem to cause it to hang up if hardware modem control
+signals were not available. The disconnect script is not run if the
+modem has already hung up. A value for this option from a privileged
+source cannot be overridden by a non-privileged user.
+.TP
+.B escape \fIxx,yy,...
+Specifies that certain characters should be escaped on transmission
+(regardless of whether the peer requests them to be escaped with its
+async control character map). The characters to be escaped are
+specified as a list of hex numbers separated by commas. Note that
+almost any character can be specified for the \fIescape\fR option,
+unlike the \fIasyncmap\fR option which only allows control characters
+to be specified. The characters which may not be escaped are those
+with hex values 0x20 - 0x3f or 0x5e.
+.TP
+.B file \fIname
+Read options from file \fIname\fR (the format is described below).
+The file must be readable by the user who has invoked pppd.
+.TP
+.B init \fIscript
+Run the executable or shell command specified by \fIscript\fR to
+initialize the serial line. This script would typically use the
+chat(8) program to configure the modem to enable auto answer. A value
+for this option from a privileged source cannot be overridden by a
+non-privileged user.
+.TP
+.B lock
+Specifies that pppd should create a UUCP-style lock file for the
+serial device to ensure exclusive access to the device.
+.TP
+.B mru \fIn
+Set the MRU [Maximum Receive Unit] value to \fIn\fR. Pppd
+will ask the peer to send packets of no more than \fIn\fR bytes. The
+minimum MRU value is 128. The default MRU value is 1500. A value of
+296 is recommended for slow links (40 bytes for TCP/IP header + 256
+bytes of data). (Note that for IPv6 MRU must be at least 1280)
+.TP
+.B mtu \fIn
+Set the MTU [Maximum Transmit Unit] value to \fIn\fR. Unless the
+peer requests a smaller value via MRU negotiation, pppd will
+request that the kernel networking code send data packets of no more
+than \fIn\fR bytes through the PPP network interface. (Note that for
+IPv6 MTU must be at least 1280)
+.TP
+.B passive
+Enables the "passive" option in the LCP. With this option, pppd will
+attempt to initiate a connection; if no reply is received from the
+peer, pppd will then just wait passively for a valid LCP packet from
+the peer, instead of exiting, as it would without this option.
+.SH OPTIONS
+.TP
+.I <local_IP_address>\fB:\fI<remote_IP_address>
+Set the local and/or remote interface IP addresses. Either one may be
+omitted. The IP addresses can be specified with a host name or in
+decimal dot notation (e.g. 150.234.56.78). The default local
+address is the (first) IP address of the system (unless the
+\fInoipdefault\fR
+option is given). The remote address will be obtained from the peer
+if not specified in any option. Thus, in simple cases, this option is
+not required. If a local and/or remote IP address is specified with
+this option, pppd
+will not accept a different value from the peer in the IPCP
+negotiation, unless the \fIipcp-accept-local\fR and/or
+\fIipcp-accept-remote\fR options are given, respectively.
+.TP
+.B ipv6 \fI<local_interface_identifier>\fR,\fI<remote_interface_identifier>
+Set the local and/or remote 64-bit interface identifier. Either one may be
+omitted. The identifier must be specified in standard ascii notation of
+IPv6 addresses (e.g. ::dead:beef). If the
+\fIipv6cp-use-ipaddr\fR
+option is given, the local identifier is the local IPv4 address (see above).
+On systems which supports a unique persistent id, such as EUI-48 derived
+from the Ethernet MAC address, \fIipv6cp-use-persistent\fR option can be
+used to replace the \fIipv6 <local>,<remote>\fR option. Otherwise the
+identifier is randomized.
+.TP
+.B active-filter \fIfilter-expression
+Specifies a packet filter to be applied to data packets to determine
+which packets are to be regarded as link activity, and therefore reset
+the idle timer, or cause the link to be brought up in demand-dialling
+mode. This option is useful in conjunction with the
+\fBidle\fR option if there are packets being sent or received
+regularly over the link (for example, routing information packets)
+which would otherwise prevent the link from ever appearing to be idle.
+The \fIfilter-expression\fR syntax is as described for tcpdump(1),
+except that qualifiers which are inappropriate for a PPP link, such as
+\fBether\fR and \fBarp\fR, are not permitted. Generally the filter
+expression should be enclosed in single-quotes to prevent whitespace
+in the expression from being interpreted by the shell. This option
+is currently only available under NetBSD, and then only
+if both the kernel and pppd were compiled with PPP_FILTER defined.
+.TP
+.B allow-ip \fIaddress(es)
+Allow peers to use the given IP address or subnet without
+authenticating themselves. The parameter is parsed as for each
+element of the list of allowed IP addresses in the secrets files (see
+the AUTHENTICATION section below).
+.TP
+.B bsdcomp \fInr,nt
+Request that the peer compress packets that it sends, using the
+BSD-Compress scheme, with a maximum code size of \fInr\fR bits, and
+agree to compress packets sent to the peer with a maximum code size of
+\fInt\fR bits. If \fInt\fR is not specified, it defaults to the value
+given for \fInr\fR. Values in the range 9 to 15 may be used for
+\fInr\fR and \fInt\fR; larger values give better compression but
+consume more kernel memory for compression dictionaries.
+Alternatively, a value of 0 for \fInr\fR or \fInt\fR disables
+compression in the corresponding direction. Use \fInobsdcomp\fR or
+\fIbsdcomp 0\fR to disable BSD-Compress compression entirely.
+.TP
+.B cdtrcts
+Use a non-standard hardware flow control (i.e. DTR/CTS) to control
+the flow of data on the serial port. If neither the \fIcrtscts\fR,
+the \fInocrtscts\fR, the \fIcdtrcts\fR nor the \fInocdtrcts\fR
+option is given, the hardware flow control setting for the serial
+port is left unchanged.
+Some serial ports (such as Macintosh serial ports) lack a true
+RTS output. Such serial ports use this mode to implement true
+bi-directional flow control. The sacrifice is that this flow
+control mode does not permit using DTR as a modem control line.
+.TP
+.B chap-interval \fIn
+If this option is given, pppd will rechallenge the peer every \fIn\fR
+seconds.
+.TP
+.B chap-max-challenge \fIn
+Set the maximum number of CHAP challenge transmissions to \fIn\fR
+(default 10).
+.TP
+.B chap-restart \fIn
+Set the CHAP restart interval (retransmission timeout for challenges)
+to \fIn\fR seconds (default 3).
+.TP
+.B connect-delay \fIn
+Wait for up \fIn\fR milliseconds after the connect script finishes for
+a valid PPP packet from the peer. At the end of this time, or when a
+valid PPP packet is received from the peer, pppd will commence
+negotiation by sending its first LCP packet. The default value is
+1000 (1 second). This wait period only applies if the \fBconnect\fR
+or \fBpty\fR option is used.
+.TP
+.B debug
+Enables connection debugging facilities.
+If this option is given, pppd will log the contents of all
+control packets sent or received in a readable form. The packets are
+logged through syslog with facility \fIdaemon\fR and level
+\fIdebug\fR. This information can be directed to a file by setting up
+/etc/syslog.conf appropriately (see syslog.conf(5)).
+.TP
+.B default-asyncmap
+Disable asyncmap negotiation, forcing all control characters to be
+escaped for both the transmit and the receive direction.
+.TP
+.B default-mru
+Disable MRU [Maximum Receive Unit] negotiation. With this option,
+pppd will use the default MRU value of 1500 bytes for both the
+transmit and receive direction.
+.TP
+.B deflate \fInr,nt
+Request that the peer compress packets that it sends, using the
+Deflate scheme, with a maximum window size of \fI2**nr\fR bytes, and
+agree to compress packets sent to the peer with a maximum window size
+of \fI2**nt\fR bytes. If \fInt\fR is not specified, it defaults to
+the value given for \fInr\fR. Values in the range 8 to 15 may be used
+for \fInr\fR and \fInt\fR; larger values give better compression but
+consume more kernel memory for compression dictionaries.
+Alternatively, a value of 0 for \fInr\fR or \fInt\fR disables
+compression in the corresponding direction. Use \fInodeflate\fR or
+\fIdeflate 0\fR to disable Deflate compression entirely. (Note: pppd
+requests Deflate compression in preference to BSD-Compress if the peer
+can do either.)
+.TP
+.B demand
+Initiate the link only on demand, i.e. when data traffic is present.
+With this option, the remote IP address must be specified by the user
+on the command line or in an options file. Pppd will initially
+configure the interface and enable it for IP traffic without
+connecting to the peer. When traffic is available, pppd will
+connect to the peer and perform negotiation, authentication, etc.
+When this is completed, pppd will commence passing data packets
+(i.e., IP packets) across the link.
+
+The \fIdemand\fR option implies the \fIpersist\fR option. If this
+behaviour is not desired, use the \fInopersist\fR option after the
+\fIdemand\fR option. The \fIidle\fR and \fIholdoff\fR
+options are also useful in conjuction with the \fIdemand\fR option.
+.TP
+.B domain \fId
+Append the domain name \fId\fR to the local host name for authentication
+purposes. For example, if gethostname() returns the name porsche, but
+the fully qualified domain name is porsche.Quotron.COM, you could
+specify \fIdomain Quotron.COM\fR. Pppd would then use the name
+\fIporsche.Quotron.COM\fR for looking up secrets in the secrets file,
+and as the default name to send to the peer when authenticating itself
+to the peer. This option is privileged.
+.TP
+.B hide-password
+When logging the contents of PAP packets, this option causes pppd to
+exclude the password string from the log. This is the default.
+.TP
+.B holdoff \fIn
+Specifies how many seconds to wait before re-initiating the link after
+it terminates. This option only has any effect if the \fIpersist\fR
+or \fIdemand\fR option is used. The holdoff period is not applied if
+the link was terminated because it was idle.
+.TP
+.B idle \fIn
+Specifies that pppd should disconnect if the link is idle for \fIn\fR
+seconds. The link is idle when no data packets (i.e. IP packets) are
+being sent or received. Note: it is not advisable to use this option
+with the \fIpersist\fR option without the \fIdemand\fR option.
+If the \fBactive-filter\fR
+option is given, data packets which are rejected by the specified
+activity filter also count as the link being idle.
+.TP
+.B ipcp-accept-local
+With this option, pppd will accept the peer's idea of our local IP
+address, even if the local IP address was specified in an option.
+.TP
+.B ipcp-accept-remote
+With this option, pppd will accept the peer's idea of its (remote) IP
+address, even if the remote IP address was specified in an option.
+.TP
+.B ipcp-max-configure \fIn
+Set the maximum number of IPCP configure-request transmissions to
+\fIn\fR (default 10).
+.TP
+.B ipcp-max-failure \fIn
+Set the maximum number of IPCP configure-NAKs returned before starting
+to send configure-Rejects instead to \fIn\fR (default 10).
+.TP
+.B ipcp-max-terminate \fIn
+Set the maximum number of IPCP terminate-request transmissions to
+\fIn\fR (default 3).
+.TP
+.B ipcp-restart \fIn
+Set the IPCP restart interval (retransmission timeout) to \fIn\fR
+seconds (default 3).
+.TP
+.B ipparam \fIstring
+Provides an extra parameter to the ip-up and ip-down scripts. If this
+option is given, the \fIstring\fR supplied is given as the 6th
+parameter to those scripts.
+.TP
+.B ipv6cp-max-configure \fIn
+Set the maximum number of IPv6CP configure-request transmissions to
+\fIn\fR (default 10).
+.TP
+.B ipv6cp-max-failure \fIn
+Set the maximum number of IPv6CP configure-NAKs returned before starting
+to send configure-Rejects instead to \fIn\fR (default 10).
+.TP
+.B ipv6cp-max-terminate \fIn
+Set the maximum number of IPv6CP terminate-request transmissions to
+\fIn\fR (default 3).
+.TP
+.B ipv6cp-restart \fIn
+Set the IPv6CP restart interval (retransmission timeout) to \fIn\fR
+seconds (default 3).
+.TP
+.B ipx
+Enable the IPXCP and IPX protocols. This option is presently only
+supported under Linux, and only if your kernel has been configured to
+include IPX support.
+.TP
+.B ipx-network \fIn
+Set the IPX network number in the IPXCP configure request frame to
+\fIn\fR, a hexadecimal number (without a leading 0x). There is no
+valid default. If this option is not specified, the network number is
+obtained from the peer. If the peer does not have the network number,
+the IPX protocol will not be started.
+.TP
+.B ipx-node \fIn\fB:\fIm
+Set the IPX node numbers. The two node numbers are separated from each
+other with a colon character. The first number \fIn\fR is the local
+node number. The second number \fIm\fR is the peer's node number. Each
+node number is a hexadecimal number, at most 10 digits long. The node
+numbers on the ipx-network must be unique. There is no valid
+default. If this option is not specified then the node numbers are
+obtained from the peer.
+.TP
+.B ipx-router-name \fI<string>
+Set the name of the router. This is a string and is sent to the peer
+as information data.
+.TP
+.B ipx-routing \fIn
+Set the routing protocol to be received by this option. More than one
+instance of \fIipx-routing\fR may be specified. The '\fInone\fR'
+option (0) may be specified as the only instance of ipx-routing. The
+values may be \fI0\fR for \fINONE\fR, \fI2\fR for \fIRIP/SAP\fR, and
+\fI4\fR for \fINLSP\fR.
+.TP
+.B ipxcp-accept-local
+Accept the peer's NAK for the node number specified in the ipx-node
+option. If a node number was specified, and non-zero, the default is
+to insist that the value be used. If you include this option then you
+will permit the peer to override the entry of the node number.
+.TP
+.B ipxcp-accept-network
+Accept the peer's NAK for the network number specified in the
+ipx-network option. If a network number was specified, and non-zero, the
+default is to insist that the value be used. If you include this
+option then you will permit the peer to override the entry of the node
+number.
+.TP
+.B ipxcp-accept-remote
+Use the peer's network number specified in the configure request
+frame. If a node number was specified for the peer and this option was
+not specified, the peer will be forced to use the value which you have
+specified.
+.TP
+.B ipxcp-max-configure \fIn
+Set the maximum number of IPXCP configure request frames which the
+system will send to \fIn\fR. The default is 10.
+.TP
+.B ipxcp-max-failure \fIn
+Set the maximum number of IPXCP NAK frames which the local system will
+send before it rejects the options. The default value is 3.
+.TP
+.B ipxcp-max-terminate \fIn
+Set the maximum nuber of IPXCP terminate request frames before the
+local system considers that the peer is not listening to them. The
+default value is 3.
+.TP
+.B kdebug \fIn
+Enable debugging code in the kernel-level PPP driver. The argument
+\fIn\fR is a number which is the sum of the following values: 1 to
+enable general debug messages, 2 to request that the contents of
+received packets be printed, and 4 to request that the contents of
+transmitted packets be printed. On most systems, messages printed by
+the kernel are logged by syslog(1) to a file as directed in the
+/etc/syslog.conf configuration file.
+.TP
+.B ktune
+Enables pppd to alter kernel settings as appropriate. Under Linux,
+pppd will enable IP forwarding (i.e. set /proc/sys/net/ipv4/ip_forward
+to 1) if the \fIproxyarp\fR option is used, and will enable the
+dynamic IP address option (i.e. set /proc/sys/net/ipv4/ip_dynaddr to
+1) in demand mode if the local address changes.
+.TP
+.B lcp-echo-failure \fIn
+If this option is given, pppd will presume the peer to be dead
+if \fIn\fR LCP echo-requests are sent without receiving a valid LCP
+echo-reply. If this happens, pppd will terminate the
+connection. Use of this option requires a non-zero value for the
+\fIlcp-echo-interval\fR parameter. This option can be used to enable
+pppd to terminate after the physical connection has been broken
+(e.g., the modem has hung up) in situations where no hardware modem
+control lines are available.
+.TP
+.B lcp-echo-interval \fIn
+If this option is given, pppd will send an LCP echo-request frame to
+the peer every \fIn\fR seconds. Normally the peer should respond to
+the echo-request by sending an echo-reply. This option can be used
+with the \fIlcp-echo-failure\fR option to detect that the peer is no
+longer connected.
+.TP
+.B lcp-max-configure \fIn
+Set the maximum number of LCP configure-request transmissions to
+\fIn\fR (default 10).
+.TP
+.B lcp-max-failure \fIn
+Set the maximum number of LCP configure-NAKs returned before starting
+to send configure-Rejects instead to \fIn\fR (default 10).
+.TP
+.B lcp-max-terminate \fIn
+Set the maximum number of LCP terminate-request transmissions to
+\fIn\fR (default 3).
+.TP
+.B lcp-restart \fIn
+Set the LCP restart interval (retransmission timeout) to \fIn\fR
+seconds (default 3).
+.TP
+.B linkname \fIname\fR
+Sets the logical name of the link to \fIname\fR. Pppd will create a
+file named \fBppp-\fIname\fB.pid\fR in /var/run (or /etc/ppp on some
+systems) containing its process ID. This can be useful in determining
+which instance of pppd is responsible for the link to a given peer
+system. This is a privileged option.
+.TP
+.B local
+Don't use the modem control lines. With this option, pppd will ignore
+the state of the CD (Carrier Detect) signal from the modem and will
+not change the state of the DTR (Data Terminal Ready) signal.
+.TP
+.B logfd \fIn
+Send log messages to file descriptor \fIn\fR. Pppd will send log
+messages to at most one file or file descriptor (as well as sending
+the log messages to syslog), so this option and the \fBlogfile\fR
+option are mutually exclusive. The default is for pppd to send log
+messages to stdout (file descriptor 1), unless the serial port is
+already open on stdout.
+.TP
+.B logfile \fIfilename
+Append log messages to the file \fIfilename\fR (as well as sending the
+log messages to syslog). The file is opened with the privileges of
+the user who invoked pppd, in append mode.
+.TP
+.B login
+Use the system password database for authenticating the peer using
+PAP, and record the user in the system wtmp file. Note that the peer
+must have an entry in the /etc/ppp/pap-secrets file as well as the
+system password database to be allowed access.
+.TP
+.B maxconnect \fIn
+Terminate the connection when it has been available for network
+traffic for \fIn\fR seconds (i.e. \fIn\fR seconds after the first
+network control protocol comes up).
+.TP
+.B maxfail \fIn
+Terminate after \fIn\fR consecutive failed connection attempts. A
+value of 0 means no limit. The default value is 10.
+.TP
+.B modem
+Use the modem control lines. This option is the default. With this
+option, pppd will wait for the CD (Carrier Detect) signal from the
+modem to be asserted when opening the serial device (unless a connect
+script is specified), and it will drop the DTR (Data Terminal Ready)
+signal briefly when the connection is terminated and before executing
+the connect script. On Ultrix, this option implies hardware flow
+control, as for the \fIcrtscts\fR option.
+.TP
+.B ms-dns \fI<addr>
+If pppd is acting as a server for Microsoft Windows clients, this
+option allows pppd to supply one or two DNS (Domain Name Server)
+addresses to the clients. The first instance of this option specifies
+the primary DNS address; the second instance (if given) specifies the
+secondary DNS address. (This option was present in some older
+versions of pppd under the name \fBdns-addr\fR.)
+.TP
+.B ms-wins \fI<addr>
+If pppd is acting as a server for Microsoft Windows or "Samba"
+clients, this option allows pppd to supply one or two WINS (Windows
+Internet Name Services) server addresses to the clients. The first
+instance of this option specifies the primary WINS address; the second
+instance (if given) specifies the secondary WINS address.
+.TP
+.B name \fIname
+Set the name of the local system for authentication purposes to
+\fIname\fR. This is a privileged option. With this option, pppd will
+use lines in the secrets files which have \fIname\fR as the second
+field when looking for a secret to use in authenticating the peer. In
+addition, unless overridden with the \fIuser\fR option, \fIname\fR
+will be used as the name to send to the peer when authenticating the
+local system to the peer. (Note that pppd does not append the domain
+name to \fIname\fR.)
+.TP
+.B netmask \fIn
+Set the interface netmask to \fIn\fR, a 32 bit netmask in "decimal dot"
+notation (e.g. 255.255.255.0). If this option is given, the value
+specified is ORed with the default netmask. The default netmask is
+chosen based on the negotiated remote IP address; it is the
+appropriate network mask for the class of the remote IP address, ORed
+with the netmasks for any non point-to-point network interfaces in the
+system which are on the same network. (Note: on some platforms, pppd
+will always use 255.255.255.255 for the netmask, if that is the only
+appropriate value for a point-to-point interface.)
+.TP
+.B noaccomp
+Disable Address/Control compression in both directions (send and
+receive).
+.TP
+.B noauth
+Do not require the peer to authenticate itself. This option is
+privileged.
+.TP
+.B nobsdcomp
+Disables BSD-Compress compression; \fBpppd\fR will not request or
+agree to compress packets using the BSD-Compress scheme.
+.TP
+.B noccp
+Disable CCP (Compression Control Protocol) negotiation. This option
+should only be required if the peer is buggy and gets confused by
+requests from pppd for CCP negotiation.
+.TP
+.B nocrtscts
+Disable hardware flow control (i.e. RTS/CTS) on the serial port.
+If neither the \fIcrtscts\fR nor the \fInocrtscts\fR nor the
+\fIcdtrcts\fR nor the \fInodtrcts\fR option is given, the hardware
+flow control setting for the serial port is left unchanged.
+.TP
+.B nodtrcts
+This option is a synonym for \fInocrtscts\fR. Either of these options will
+disable both forms of hardware flow control.
+.TP
+.B nodefaultroute
+Disable the \fIdefaultroute\fR option. The system administrator who
+wishes to prevent users from creating default routes with pppd
+can do so by placing this option in the /etc/ppp/options file.
+.TP
+.B nodeflate
+Disables Deflate compression; pppd will not request or agree to
+compress packets using the Deflate scheme.
+.TP
+.B nodetach
+Don't detach from the controlling terminal. Without this option, if a
+serial device other than the terminal on the standard input is
+specified, pppd will fork to become a background process.
+.TP
+.B noip
+Disable IPCP negotiation and IP communication. This option should
+only be required if the peer is buggy and gets confused by requests
+from pppd for IPCP negotiation.
+.TP
+.B noipv6
+Disable IPv6CP negotiation and IPv6 communication. This option should
+only be required if the peer is buggy and gets confused by requests
+from pppd for IPv6CP negotiation.
+.TP
+.B noipdefault
+Disables the default behaviour when no local IP address is specified,
+which is to determine (if possible) the local IP address from the
+hostname. With this option, the peer will have to supply the local IP
+address during IPCP negotiation (unless it specified explicitly on the
+command line or in an options file).
+.TP
+.B noipx
+Disable the IPXCP and IPX protocols. This option should only be
+required if the peer is buggy and gets confused by requests from pppd
+for IPXCP negotiation.
+.TP
+.B noktune
+Opposite of the \fIktune\fR option; disables pppd from changing system
+settings.
+.TP
+.B nolog
+Do not send log messages to a file or file descriptor. This option
+cancels the \fBlogfd\fR and \fBlogfile\fR options.
+.B nomagic
+Disable magic number negotiation. With this option, pppd cannot
+detect a looped-back line. This option should only be needed if the
+peer is buggy.
+.TP
+.B nopcomp
+Disable protocol field compression negotiation in both the receive and
+the transmit direction.
+.TP
+.B nopersist
+Exit once a connection has been made and terminated. This is the
+default unless the \fIpersist\fR or \fIdemand\fR option has been
+specified.
+.TP
+.B nopredictor1
+Do not accept or agree to Predictor-1 compression.
+.TP
+.B noproxyarp
+Disable the \fIproxyarp\fR option. The system administrator who
+wishes to prevent users from creating proxy ARP entries with pppd can
+do so by placing this option in the /etc/ppp/options file.
+.TP
+.B notty
+Normally, pppd requires a terminal device. With this option, pppd
+will allocate itself a pseudo-tty master/slave pair and use the slave
+as its terminal device. Pppd will create a child process to act as a
+`character shunt' to transfer characters between the pseudo-tty master
+and its standard input and output. Thus pppd will transmit characters
+on its standard output and receive characters on its standard input
+even if they are not terminal devices. This option increases the
+latency and CPU overhead of transferring data over the ppp interface
+as all of the characters sent and received must flow through the
+character shunt process. An explicit device name may not be given if
+this option is used.
+.TP
+.B novj
+Disable Van Jacobson style TCP/IP header compression in both the
+transmit and the receive direction.
+.TP
+.B novjccomp
+Disable the connection-ID compression option in Van Jacobson style
+TCP/IP header compression. With this option, pppd will not omit the
+connection-ID byte from Van Jacobson compressed TCP/IP headers, nor
+ask the peer to do so.
+.TP
+.B papcrypt
+Indicates that all secrets in the /etc/ppp/pap-secrets file which are
+used for checking the identity of the peer are encrypted, and thus
+pppd should not accept a password which, before encryption, is
+identical to the secret from the /etc/ppp/pap-secrets file.
+.TP
+.B pap-max-authreq \fIn
+Set the maximum number of PAP authenticate-request transmissions to
+\fIn\fR (default 10).
+.TP
+.B pap-restart \fIn
+Set the PAP restart interval (retransmission timeout) to \fIn\fR
+seconds (default 3).
+.TP
+.B pap-timeout \fIn
+Set the maximum time that pppd will wait for the peer to authenticate
+itself with PAP to \fIn\fR seconds (0 means no limit).
+.TP
+.B pass-filter \fIfilter-expression
+Specifies a packet filter to applied to data packets being sent or
+received to determine which packets should be allowed to pass.
+Packets which are rejected by the filter are silently discarded. This
+option can be used to prevent specific network daemons (such as
+routed) using up link bandwidth, or to provide a basic firewall
+capability.
+The \fIfilter-expression\fR syntax is as described for tcpdump(1),
+except that qualifiers which are inappropriate for a PPP link, such as
+\fBether\fR and \fBarp\fR, are not permitted. Generally the filter
+expression should be enclosed in single-quotes to prevent whitespace
+in the expression from being interpreted by the shell. Note that it
+is possible to apply different constraints to incoming and outgoing
+packets using the \fBinbound\fR and \fBoutbound\fR qualifiers. This
+option is currently only available under NetBSD, and then only if both
+the kernel and pppd were compiled with PPP_FILTER defined.
+.TP
+.B persist
+Do not exit after a connection is terminated; instead try to reopen
+the connection.
+.TP
+.B plugin \fIfilename
+Load the shared library object file \fIfilename\fR as a plugin. This
+is a privileged option.
+.TP
+.B predictor1
+Request that the peer compress frames that it sends using Predictor-1
+compression, and agree to compress transmitted frames with Predictor-1
+if requested. This option has no effect unless the kernel driver
+supports Predictor-1 compression.
+.TP
+.B privgroup \fIgroup-name
+Allows members of group \fIgroup-name\fR to use privileged options.
+This is a privileged option. Use of this option requires care as
+there is no guarantee that members of \fIgroup-name\fR cannot use pppd
+to become root themselves. Consider it equivalent to putting the
+members of \fIgroup-name\fR in the kmem or disk group.
+.TP
+.B proxyarp
+Add an entry to this system's ARP [Address Resolution Protocol] table
+with the IP address of the peer and the Ethernet address of this
+system. This will have the effect of making the peer appear to other
+systems to be on the local ethernet.
+.TP
+.B pty \fIscript
+Specifies that the command \fIscript\fR is to be used to communicate
+rather than a specific terminal device. Pppd will allocate itself a
+pseudo-tty master/slave pair and use the slave as its terminal
+device. The \fIscript\fR will be run in a child process with the
+pseudo-tty master as its standard input and output. An explicit
+device name may not be given if this option is used. (Note: if the
+\fIrecord\fR option is used in conjuction with the \fIpty\fR option,
+the child process will have pipes on its standard input and output.)
+.TP
+.B receive-all
+With this option, pppd will accept all control characters from the
+peer, including those marked in the receive asyncmap. Without this
+option, pppd will discard those characters as specified in RFC1662.
+This option should only be needed if the peer is buggy.
+.TP
+.B record \fIfilename
+Specifies that pppd should record all characters sent and received to
+a file named \fIfilename\fR. This file is opened in append mode,
+using the user's user-ID and permissions. This option is implemented
+using a pseudo-tty and a process to transfer characters between the
+pseudo-tty and the real serial device, so it will increase the latency
+and CPU overhead of transferring data over the ppp interface. The
+characters are stored in a tagged format with timestamps, which can be
+displayed in readable form using the pppdump(8) program.
+.TP
+.B remotename \fIname
+Set the assumed name of the remote system for authentication purposes
+to \fIname\fR.
+.TP
+.B refuse-chap
+With this option, pppd will not agree to authenticate itself to the
+peer using CHAP.
+.TP
+.B refuse-pap
+With this option, pppd will not agree to authenticate itself to the
+peer using PAP.
+.TP
+.B require-chap
+Require the peer to authenticate itself using CHAP [Challenge
+Handshake Authentication Protocol] authentication.
+.TP
+.B require-pap
+Require the peer to authenticate itself using PAP [Password
+Authentication Protocol] authentication.
+.TP
+.B show-password
+When logging the contents of PAP packets, this option causes pppd to
+show the password string in the log message.
+.TP
+.B silent
+With this option, pppd will not transmit LCP packets to initiate a
+connection until a valid LCP packet is received from the peer (as for
+the `passive' option with ancient versions of pppd).
+.TP
+.B sync
+Use synchronous HDLC serial encoding instead of asynchronous.
+The device used by pppd with this option must have sync support.
+Currently supports Microgate SyncLink adapters
+under Linux and FreeBSD 2.2.8 and later.
+.TP
+.B updetach
+With this option, pppd will detach from its controlling terminal once
+it has successfully established the ppp connection (to the point where
+the first network control protocol, usually the IP control protocol,
+has come up).
+.TP
+.B usehostname
+Enforce the use of the hostname (with domain name appended, if given)
+as the name of the local system for authentication purposes (overrides
+the \fIname\fR option). This option is not normally needed since the
+\fIname\fR option is privileged.
+.TP
+.B usepeerdns
+Ask the peer for up to 2 DNS server addresses. The addresses supplied
+by the peer (if any) are passed to the /etc/ppp/ip-up script in the
+environment variables DNS1 and DNS2. In addition, pppd will create an
+/etc/ppp/resolv.conf file containing one or two nameserver lines with
+the address(es) supplied by the peer.
+.TP
+.B user \fIname
+Sets the name used for authenticating the local system to the peer to
+\fIname\fR.
+.TP
+.B vj-max-slots \fIn
+Sets the number of connection slots to be used by the Van Jacobson
+TCP/IP header compression and decompression code to \fIn\fR, which
+must be between 2 and 16 (inclusive).
+.TP
+.B welcome \fIscript
+Run the executable or shell command specified by \fIscript\fR before
+initiating PPP negotiation, after the connect script (if any) has
+completed. A value for this option from a privileged source cannot be
+overridden by a non-privileged user.
+.TP
+.B xonxoff
+Use software flow control (i.e. XON/XOFF) to control the flow of data on
+the serial port.
+.SH OPTIONS FILES
+Options can be taken from files as well as the command line. Pppd
+reads options from the files /etc/ppp/options, ~/.ppprc and
+/etc/ppp/options.\fIttyname\fR (in that order) before processing the
+options on the command line. (In fact, the command-line options are
+scanned to find the terminal name before the options.\fIttyname\fR
+file is read.) In forming the name of the options.\fIttyname\fR file,
+the initial /dev/ is removed from the terminal name, and any remaining
+/ characters are replaced with dots.
+.PP
+An options file is parsed into a series of words, delimited by
+whitespace. Whitespace can be included in a word by enclosing the
+word in double-quotes ("). A backslash (\\) quotes the following character.
+A hash (#) starts a comment, which continues until the end of the
+line. There is no restriction on using the \fIfile\fR or \fIcall\fR
+options within an options file.
+.SH SECURITY
+.I pppd
+provides system administrators with sufficient access control that PPP
+access to a server machine can be provided to legitimate users without
+fear of compromising the security of the server or the network it's
+on. This control is provided through restrictions on which IP
+addresses the peer may use, based on its authenticated identity (if
+any), and through restrictions on which options a non-privileged user
+may use. Several of pppd's options are privileged, in particular
+those which permit potentially insecure configurations; these options
+are only accepted in files which are under the control of the system
+administrator, or if pppd is being run by root.
+.PP
+The default behaviour of pppd is to allow an unauthenticated peer to
+use a given IP address only if the system does not already have a
+route to that IP address. For example, a system with a
+permanent connection to the wider internet will normally have a
+default route, and thus all peers will have to authenticate themselves
+in order to set up a connection. On such a system, the \fIauth\fR
+option is the default. On the other hand, a system where the
+PPP link is the only connection to the internet will not normally have
+a default route, so the peer will be able to use almost any IP address
+without authenticating itself.
+.PP
+As indicated above, some security-sensitive options are privileged,
+which means that they may not be used by an ordinary non-privileged
+user running a setuid-root pppd, either on the command line, in the
+user's ~/.ppprc file, or in an options file read using the \fIfile\fR
+option. Privileged options may be used in /etc/ppp/options file or in
+an options file read using the \fIcall\fR option. If pppd is being
+run by the root user, privileged options can be used without
+restriction.
+.PP
+When opening the device, pppd uses either the invoking user's user ID
+or the root UID (that is, 0), depending on whether the device name was
+specified by the user or the system administrator. If the device name
+comes from a privileged source, that is, /etc/ppp/options or an
+options file read using the \fIcall\fR option, pppd uses full root
+privileges when opening the device. Thus, by creating an appropriate
+file under /etc/ppp/peers, the system administrator can allow users to
+establish a ppp connection via a device which they would not normally
+have permission to access. Otherwise pppd uses the invoking user's
+real UID when opening the device.
+.SH AUTHENTICATION
+Authentication is the process whereby one peer convinces the other of
+its identity. This involves the first peer sending its name to the
+other, together with some kind of secret information which could only
+come from the genuine authorized user of that name. In such an
+exchange, we will call the first peer the "client" and the other the
+"server". The client has a name by which it identifies itself to the
+server, and the server also has a name by which it identifies itself
+to the client. Generally the genuine client shares some secret (or
+password) with the server, and authenticates itself by proving that it
+knows that secret. Very often, the names used for authentication
+correspond to the internet hostnames of the peers, but this is not
+essential.
+.LP
+At present, pppd supports two authentication protocols: the Password
+Authentication Protocol (PAP) and the Challenge Handshake
+Authentication Protocol (CHAP). PAP involves the client sending its
+name and a cleartext password to the server to authenticate itself.
+In contrast, the server initiates the CHAP authentication exchange by
+sending a challenge to the client (the challenge packet includes the
+server's name). The client must respond with a response which
+includes its name plus a hash value derived from the shared secret and
+the challenge, in order to prove that it knows the secret.
+.LP
+The PPP protocol, being symmetrical, allows both peers to require the
+other to authenticate itself. In that case, two separate and
+independent authentication exchanges will occur. The two exchanges
+could use different authentication protocols, and in principle,
+different names could be used in the two exchanges.
+.LP
+The default behaviour of pppd is to agree to authenticate if
+requested, and to not require authentication from the peer. However,
+pppd will not agree to authenticate itself with a particular protocol
+if it has no secrets which could be used to do so.
+.LP
+Pppd stores secrets for use in authentication in secrets
+files (/etc/ppp/pap-secrets for PAP, /etc/ppp/chap-secrets for CHAP).
+Both secrets files have the same format. The secrets files can
+contain secrets for pppd to use in authenticating itself to other
+systems, as well as secrets for pppd to use when authenticating other
+systems to itself.
+.LP
+Each line in a secrets file contains one secret. A given secret is
+specific to a particular combination of client and server - it can
+only be used by that client to authenticate itself to that server.
+Thus each line in a secrets file has at least 3 fields: the name of
+the client, the name of the server, and the secret. These fields may
+be followed by a list of the IP addresses that the specified client
+may use when connecting to the specified server.
+.LP
+A secrets file is parsed into words as for a options file, so the
+client name, server name and secrets fields must each be one word,
+with any embedded spaces or other special characters quoted or
+escaped. Note that case is significant in the client and server names
+and in the secret.
+.LP
+If the secret starts with an `@', what follows is assumed to be the
+name of a file from which to read the secret. A "*" as the client or
+server name matches any name. When selecting a secret, pppd takes the
+best match, i.e. the match with the fewest wildcards.
+.LP
+Any following words on the same line are taken to be a list of
+acceptable IP addresses for that client. If there are only 3 words on
+the line, or if the first word is "-", then all IP addresses are
+disallowed. To allow any address, use "*". A word starting with "!"
+indicates that the specified address is \fInot\fR acceptable. An
+address may be followed by "/" and a number \fIn\fR, to indicate a
+whole subnet, i.e. all addresses which have the same value in the most
+significant \fIn\fR bits. In this form, the address may be followed
+by a plus sign ("+") to indicate that one address from the subnet is
+authorized, based on the ppp network interface unit number in use.
+In this case, the host part of the address will be set to the unit
+number plus one.
+.LP
+Thus a secrets file contains both secrets for use in authenticating
+other hosts, plus secrets which we use for authenticating ourselves to
+others. When pppd is authenticating the peer (checking the peer's
+identity), it chooses a secret with the peer's name in the first
+field and the name of the local system in the second field. The
+name of the local system defaults to the hostname, with the domain
+name appended if the \fIdomain\fR option is used. This default can be
+overridden with the \fIname\fR option, except when the
+\fIusehostname\fR option is used.
+.LP
+When pppd is choosing a secret to use in authenticating itself to the
+peer, it first determines what name it is going to use to identify
+itself to the peer. This name can be specified by the user with the
+\fIuser\fR option. If this option is not used, the name defaults to
+the name of the local system, determined as described in the previous
+paragraph. Then pppd looks for a secret with this name in the first
+field and the peer's name in the second field. Pppd will know the
+name of the peer if CHAP authentication is being used, because the
+peer will have sent it in the challenge packet. However, if PAP is being
+used, pppd will have to determine the peer's name from the options
+specified by the user. The user can specify the peer's name directly
+with the \fIremotename\fR option. Otherwise, if the remote IP address
+was specified by a name (rather than in numeric form), that name will
+be used as the peer's name. Failing that, pppd will use the null
+string as the peer's name.
+.LP
+When authenticating the peer with PAP, the supplied password is first
+compared with the secret from the secrets file. If the password
+doesn't match the secret, the password is encrypted using crypt() and
+checked against the secret again. Thus secrets for authenticating the
+peer can be stored in encrypted form if desired. If the
+\fIpapcrypt\fR option is given, the first (unencrypted) comparison is
+omitted, for better security.
+.LP
+Furthermore, if the \fIlogin\fR option was specified, the username and
+password are also checked against the system password database. Thus,
+the system administrator can set up the pap-secrets file to allow PPP
+access only to certain users, and to restrict the set of IP addresses
+that each user can use. Typically, when using the \fIlogin\fR option,
+the secret in /etc/ppp/pap-secrets would be "", which will match any
+password supplied by the peer. This avoids the need to have the same
+secret in two places.
+.LP
+Authentication must be satisfactorily completed before IPCP (or any
+other Network Control Protocol) can be started. If the peer is
+required to authenticate itself, and fails to do so, pppd will
+terminated the link (by closing LCP). If IPCP negotiates an
+unacceptable IP address for the remote host, IPCP will be closed. IP
+packets can only be sent or received when IPCP is open.
+.LP
+In some cases it is desirable to allow some hosts which can't
+authenticate themselves to connect and use one of a restricted set of
+IP addresses, even when the local host generally requires
+authentication. If the peer refuses to authenticate itself when
+requested, pppd takes that as equivalent to authenticating with PAP
+using the empty string for the username and password. Thus, by adding
+a line to the pap-secrets file which specifies the empty string for
+the client and password, it is possible to allow restricted access to
+hosts which refuse to authenticate themselves.
+.SH ROUTING
+.LP
+When IPCP negotiation is completed successfully, pppd will inform the
+kernel of the local and remote IP addresses for the ppp interface.
+This is sufficient to create a host route to the remote end of the
+link, which will enable the peers to exchange IP packets.
+Communication with other machines generally requires further
+modification to routing tables and/or ARP (Address Resolution
+Protocol) tables. In most cases the \fIdefaultroute\fR and/or
+\fIproxyarp\fR options are sufficient for this, but in some cases
+further intervention is required. The /etc/ppp/ip-up script can be
+used for this.
+.LP
+Sometimes it is desirable to add a default route through the remote
+host, as in the case of a machine whose only connection to the
+Internet is through the ppp interface. The \fIdefaultroute\fR option
+causes pppd to create such a default route when IPCP comes up, and
+delete it when the link is terminated.
+.LP
+In some cases it is desirable to use proxy ARP, for example on a
+server machine connected to a LAN, in order to allow other hosts to
+communicate with the remote host. The \fIproxyarp\fR option causes
+pppd to look for a network interface on the same subnet as the remote
+host (an interface supporting broadcast and ARP, which is up and not a
+point-to-point or loopback interface). If found, pppd creates a
+permanent, published ARP entry with the IP address of the remote host
+and the hardware address of the network interface found.
+.LP
+When the \fIdemand\fR option is used, the interface IP addresses have
+already been set at the point when IPCP comes up. If pppd has not
+been able to negotiate the same addresses that it used to configure
+the interface (for example when the peer is an ISP that uses dynamic
+IP address assignment), pppd has to change the interface IP addresses
+to the negotiated addresses. This may disrupt existing connections,
+and the use of demand dialling with peers that do dynamic IP address
+assignment is not recommended.
+.SH EXAMPLES
+.LP
+The following examples assume that the /etc/ppp/options file contains
+the \fIauth\fR option (as in the default /etc/ppp/options file in the
+ppp distribution).
+.LP
+Probably the most common use of pppd is to dial out to an ISP. This
+can be done with a command such as
+.IP
+pppd call isp
+.LP
+where the /etc/ppp/peers/isp file is set up by the system
+administrator to contain something like this:
+.IP
+ttyS0 19200 crtscts
+.br
+connect '/usr/sbin/chat -v -f /etc/ppp/chat-isp'
+.br
+noauth
+.LP
+In this example, we are using chat to dial the ISP's modem and go
+through any logon sequence required. The /etc/ppp/chat-isp file
+contains the script used by chat; it could for example contain
+something like this:
+.IP
+ABORT "NO CARRIER"
+.br
+ABORT "NO DIALTONE"
+.br
+ABORT "ERROR"
+.br
+ABORT "NO ANSWER"
+.br
+ABORT "BUSY"
+.br
+ABORT "Username/Password Incorrect"
+.br
+"" "at"
+.br
+OK "at&d0&c1"
+.br
+OK "atdt2468135"
+.br
+"name:" "^Umyuserid"
+.br
+"word:" "\\qmypassword"
+.br
+"ispts" "\\q^Uppp"
+.br
+"~-^Uppp-~"
+.LP
+See the chat(8) man page for details of chat scripts.
+.LP
+Pppd can also be used to provide a dial-in ppp service for users. If
+the users already have login accounts, the simplest way to set up the
+ppp service is to let the users log in to their accounts and run pppd
+(installed setuid-root) with a command such as
+.IP
+pppd proxyarp
+.LP
+To allow a user to use the PPP facilities, you need to allocate an IP
+address for that user's machine and create an entry in
+/etc/ppp/pap-secrets or /etc/ppp/chap-secrets (depending on which
+authentication method the PPP implementation on the user's machine
+supports), so that the user's
+machine can authenticate itself. For example, if Joe has a machine
+called "joespc" which is to be allowed to dial in to the machine
+called "server" and use the IP address joespc.my.net, you would add an
+entry like this to /etc/ppp/pap-secrets or /etc/ppp/chap-secrets:
+.IP
+joespc server "joe's secret" joespc.my.net
+.LP
+Alternatively, you can create a username called (for example) "ppp",
+whose login shell is pppd and whose home directory is /etc/ppp.
+Options to be used when pppd is run this way can be put in
+/etc/ppp/.ppprc.
+.LP
+If your serial connection is any more complicated than a piece of
+wire, you may need to arrange for some control characters to be
+escaped. In particular, it is often useful to escape XON (^Q) and
+XOFF (^S), using \fIasyncmap a0000\fR. If the path includes a telnet,
+you probably should escape ^] as well (\fIasyncmap 200a0000\fR). If
+the path includes an rlogin, you will need to use the \fIescape ff\fR
+option on the end which is running the rlogin client, since many
+rlogin implementations are not transparent; they will remove the
+sequence [0xff, 0xff, 0x73, 0x73, followed by any 8 bytes] from the
+stream.
+.SH DIAGNOSTICS
+.LP
+Messages are sent to the syslog daemon using facility LOG_DAEMON.
+(This can be overriden by recompiling pppd with the macro
+LOG_PPP defined as the desired facility.) In order to see the error
+and debug messages, you will need to edit your /etc/syslog.conf file
+to direct the messages to the desired output device or file.
+.LP
+The \fIdebug\fR option causes the contents of all control packets sent
+or received to be logged, that is, all LCP, PAP, CHAP or IPCP packets.
+This can be useful if the PPP negotiation does not succeed or if
+authentication fails.
+If debugging is enabled at compile time, the \fIdebug\fR option also
+causes other debugging messages to be logged.
+.LP
+Debugging can also be enabled or disabled by sending a SIGUSR1 signal
+to the pppd process. This signal acts as a toggle.
+.SH EXIT STATUS
+The exit status of pppd is set to indicate whether any error was
+detected, or the reason for the link being terminated. The values
+used are:
+.TP
+.B 0
+Pppd has detached, or otherwise the connection was successfully
+established and terminated at the peer's request.
+.TP
+.B 1
+An immediately fatal error of some kind occurred, such as an essential
+system call failing, or running out of virtual memory.
+.TP
+.B 2
+An error was detected in processing the options given, such as two
+mutually exclusive options being used.
+.TP
+.B 3
+Pppd is not setuid-root and the invoking user is not root.
+.TP
+.B 4
+The kernel does not support PPP, for example, the PPP kernel driver is
+not included or cannot be loaded.
+.TP
+.B 5
+Pppd terminated because it was sent a SIGINT, SIGTERM or SIGHUP
+signal.
+.TP
+.B 6
+The serial port could not be locked.
+.TP
+.B 7
+The serial port could not be opened.
+.TP
+.B 8
+The connect script failed (returned a non-zero exit status).
+.TP
+.B 9
+The command specified as the argument to the \fIpty\fR option could
+not be run.
+.TP
+.B 10
+The PPP negotiation failed, that is, it didn't reach the point where
+at least one network protocol (e.g. IP) was running.
+.TP
+.B 11
+The peer system failed (or refused) to authenticate itself.
+.TP
+.B 12
+The link was established successfully and terminated because it was
+idle.
+.TP
+.B 13
+The link was established successfully and terminated because the
+connect time limit was reached.
+.TP
+.B 14
+Callback was negotiated and an incoming call should arrive shortly.
+.TP
+.B 15
+The link was terminated because the peer is not responding to echo
+requests.
+.TP
+.B 16
+The link was terminated by the modem hanging up.
+.TP
+.B 17
+The PPP negotiation failed because serial loopback was detected.
+.TP
+.B 18
+The init script failed (returned a non-zero exit status).
+.TP
+.B 19
+We failed to authenticate ourselves to the peer.
+.SH SCRIPTS
+Pppd invokes scripts at various stages in its processing which can be
+used to perform site-specific ancillary processing. These scripts are
+usually shell scripts, but could be executable code files instead.
+Pppd does not wait for the scripts to finish. The scripts are
+executed as root (with the real and effective user-id set to 0), so
+that they can do things such as update routing tables or run
+privileged daemons. Be careful that the contents of these scripts do
+not compromise your system's security. Pppd runs the scripts with
+standard input, output and error redirected to /dev/null, and with an
+environment that is empty except for some environment variables that
+give information about the link. The environment variables that pppd
+sets are:
+.TP
+.B DEVICE
+The name of the serial tty device being used.
+.TP
+.B IFNAME
+The name of the network interface being used.
+.TP
+.B IPLOCAL
+The IP address for the local end of the link. This is only set when
+IPCP has come up.
+.TP
+.B IPREMOTE
+The IP address for the remote end of the link. This is only set when
+IPCP has come up.
+.TP
+.B PEERNAME
+The authenticated name of the peer. This is only set if the peer
+authenticates itself.
+.TP
+.B SPEED
+The baud rate of the tty device.
+.TP
+.B ORIG_UID
+The real user-id of the user who invoked pppd.
+.TP
+.B PPPLOGNAME
+The username of the real user-id that invoked pppd. This is always set.
+.P
+For the ip-down and auth-down scripts, pppd also sets the following
+variables giving statistics for the connection:
+.TP
+.B CONNECT_TIME
+The number of seconds from when the PPP negotiation started until the
+connection was terminated.
+.TP
+.B BYTES_SENT
+The number of bytes sent (at the level of the serial port) during the
+connection.
+.TP
+.B BYTES_RCVD
+The number of bytes received (at the level of the serial port) during
+the connection.
+.TP
+.B LINKNAME
+The logical name of the link, set with the \fIlinkname\fR option.
+.P
+Pppd invokes the following scripts, if they exist. It is not an error
+if they don't exist.
+.TP
+.B /etc/ppp/auth-up
+A program or script which is executed after the remote system
+successfully authenticates itself. It is executed with the parameters
+.IP
+\fIinterface-name peer-name user-name tty-device speed\fR
+.IP
+Note that this script is not executed if the peer doesn't authenticate
+itself, for example when the \fInoauth\fR option is used.
+.TP
+.B /etc/ppp/auth-down
+A program or script which is executed when the link goes down, if
+/etc/ppp/auth-up was previously executed. It is executed in the same
+manner with the same parameters as /etc/ppp/auth-up.
+.TP
+.B /etc/ppp/ip-up
+A program or script which is executed when the link is available for
+sending and receiving IP packets (that is, IPCP has come up). It is
+executed with the parameters
+.IP
+\fIinterface-name tty-device speed local-IP-address
+remote-IP-address ipparam\fR
+.TP
+.B /etc/ppp/ip-down
+A program or script which is executed when the link is no longer
+available for sending and receiving IP packets. This script can be
+used for undoing the effects of the /etc/ppp/ip-up script. It is
+invoked in the same manner and with the same parameters as the ip-up
+script.
+.TP
+.B /etc/ppp/ipv6-up
+Like /etc/ppp/ip-up, except that it is executed when the link is available
+for sending and receiving IPv6 packets. It is executed with the parameters
+.IP
+\fIinterface-name tty-device speed local-link-local-address
+remote-link-local-address ipparam\fR
+.TP
+.B /etc/ppp/ipv6-down
+Similar to /etc/ppp/ip-down, but it is executed when IPv6 packets can no
+longer be transmitted on the link. It is executed with the same parameters
+as the ipv6-up script.
+.TP
+.B /etc/ppp/ipx-up
+A program or script which is executed when the link is available for
+sending and receiving IPX packets (that is, IPXCP has come up). It is
+executed with the parameters
+.IP
+\fIinterface-name tty-device speed network-number local-IPX-node-address
+remote-IPX-node-address local-IPX-routing-protocol remote-IPX-routing-protocol
+local-IPX-router-name remote-IPX-router-name ipparam pppd-pid\fR
+.IP
+The local-IPX-routing-protocol and remote-IPX-routing-protocol field
+may be one of the following:
+.IP
+NONE to indicate that there is no routing protocol
+.br
+RIP to indicate that RIP/SAP should be used
+.br
+NLSP to indicate that Novell NLSP should be used
+.br
+RIP NLSP to indicate that both RIP/SAP and NLSP should be used
+.TP
+.B /etc/ppp/ipx-down
+A program or script which is executed when the link is no longer
+available for sending and receiving IPX packets. This script can be
+used for undoing the effects of the /etc/ppp/ipx-up script. It is
+invoked in the same manner and with the same parameters as the ipx-up
+script.
+.SH FILES
+.TP
+.B /var/run/ppp\fIn\fB.pid \fR(BSD or Linux), \fB/etc/ppp/ppp\fIn\fB.pid \fR(others)
+Process-ID for pppd process on ppp interface unit \fIn\fR.
+.TP
+.B /var/run/ppp-\fIname\fB.pid \fR(BSD or Linux), \fB/etc/ppp/ppp-\fIname\fB.pid \fR(others)
+Process-ID for pppd process for logical link \fIname\fR (see the
+\fIlinkname\fR option).
+.TP
+.B /etc/ppp/pap-secrets
+Usernames, passwords and IP addresses for PAP authentication. This
+file should be owned by root and not readable or writable by any other
+user. Pppd will log a warning if this is not the case.
+.TP
+.B /etc/ppp/chap-secrets
+Names, secrets and IP addresses for CHAP authentication. As for
+/etc/ppp/pap-secrets, this file should be owned by root and not
+readable or writable by any other user. Pppd will log a warning if
+this is not the case.
+.TP
+.B /etc/ppp/options
+System default options for pppd, read before user default options or
+command-line options.
+.TP
+.B ~/.ppprc
+User default options, read before /etc/ppp/options.\fIttyname\fR.
+.TP
+.B /etc/ppp/options.\fIttyname
+System default options for the serial port being used, read after
+~/.ppprc. In forming the \fIttyname\fR part of this
+filename, an initial /dev/ is stripped from the port name (if
+present), and any slashes in the remaining part are converted to
+dots.
+.TP
+.B /etc/ppp/peers
+A directory containing options files which may contain privileged
+options, even if pppd was invoked by a user other than root. The
+system administrator can create options files in this directory to
+permit non-privileged users to dial out without requiring the peer to
+authenticate, but only to certain trusted peers.
+.SH SEE ALSO
+.TP
+.B RFC1144
+Jacobson, V.
+\fICompressing TCP/IP headers for low-speed serial links.\fR
+February 1990.
+.TP
+.B RFC1321
+Rivest, R.
+.I The MD5 Message-Digest Algorithm.
+April 1992.
+.TP
+.B RFC1332
+McGregor, G.
+.I PPP Internet Protocol Control Protocol (IPCP).
+May 1992.
+.TP
+.B RFC1334
+Lloyd, B.; Simpson, W.A.
+.I PPP authentication protocols.
+October 1992.
+.TP
+.B RFC1661
+Simpson, W.A.
+.I The Point\-to\-Point Protocol (PPP).
+July 1994.
+.TP
+.B RFC1662
+Simpson, W.A.
+.I PPP in HDLC-like Framing.
+July 1994.
+.TP
+.B RFC2472
+Haskin, D.
+.I IP Version 6 over PPP
+December 1998.
+.SH NOTES
+The following signals have the specified effect when sent to pppd.
+.TP
+.B SIGINT, SIGTERM
+These signals cause pppd to terminate the link (by closing LCP),
+restore the serial device settings, and exit.
+.TP
+.B SIGHUP
+This signal causes pppd to terminate the link, restore the serial
+device settings, and close the serial device. If the \fIpersist\fR or
+\fIdemand\fR option has been specified, pppd will try to reopen the
+serial device and start another connection (after the holdoff period).
+Otherwise pppd will exit. If this signal is received during the
+holdoff period, it causes pppd to end the holdoff period immediately.
+.TP
+.B SIGUSR1
+This signal toggles the state of the \fIdebug\fR option.
+.TP
+.B SIGUSR2
+This signal causes pppd to renegotiate compression. This can be
+useful to re-enable compression after it has been disabled as a result
+of a fatal decompression error. (Fatal decompression errors generally
+indicate a bug in one or other implementation.)
+
+.SH AUTHORS
+Paul Mackerras (Paul.Mackerras@cs.anu.edu.au), based on earlier work by
+Drew Perkins,
+Brad Clements,
+Karl Fox,
+Greg Christy,
+and
+Brad Parker.
diff --git a/cpukit/pppd/pppd.h b/cpukit/pppd/pppd.h
new file mode 100644
index 0000000000..8655f82783
--- /dev/null
+++ b/cpukit/pppd/pppd.h
@@ -0,0 +1,663 @@
+/*
+ * pppd.h - PPP daemon global declarations.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+#ifndef __PPPD_H__
+#define __PPPD_H__
+
+#include <stdbool.h> /* bool */
+#include <stdio.h> /* for FILE */
+#include <limits.h> /* for NGROUPS_MAX */
+#include <sys/param.h> /* for MAXPATHLEN and BSD4_4, if defined */
+#include <sys/types.h> /* for uint32_t, if defined */
+#include <sys/time.h> /* for struct timeval */
+#include <net/ppp_defs.h>
+#include <rtems/rtemsdialer.h>
+#include <stdint.h>
+
+#if defined(__STDC__)
+#include <stdarg.h>
+#define __V(x) x
+#else
+#include <varargs.h>
+#define __V(x) (va_alist) va_dcl
+#define const
+#define volatile
+#endif
+
+#ifdef INET6
+#include "eui64.h"
+#endif
+
+/*
+ * Limits.
+ */
+
+#define NUM_PPP 1 /* One PPP interface supported (per process) */
+#define MAXWORDLEN 1024 /* max length of word in file (incl null) */
+#define MAXARGS 1 /* max # args to a command */
+#define MAXNAMELEN 256 /* max length of hostname or name for auth */
+#define MAXSECRETLEN 256 /* max length of password or secret */
+
+/*
+ * Option descriptor structure.
+ */
+
+enum opt_type {
+ o_special_noarg = 0,
+ o_special = 1,
+ o_bool,
+ o_int,
+ o_uint32,
+ o_string,
+};
+
+typedef struct {
+ char *name; /* name of the option */
+ enum opt_type type;
+ void *addr;
+ char *description;
+ uint32_t flags;
+ void *addr2;
+ int upper_limit;
+ int lower_limit;
+} option_t;
+
+/* Values for flags */
+#define OPT_VALUE 0xffL /* mask for presupplied value */
+#define OPT_HEX 0x100L /* int option is in hex */
+#define OPT_NOARG 0x200L /* option doesn't take argument */
+#define OPT_OR 0x400L /* OR in argument to value */
+#define OPT_INC 0x800L /* increment value */
+#define OPT_PRIV 0x1000L /* privileged option */
+#define OPT_STATIC 0x2000L /* string option goes into static array */
+#define OPT_LLIMIT 0x4000L /* check value against lower limit */
+#define OPT_ULIMIT 0x8000L /* check value against upper limit */
+#define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT)
+#define OPT_ZEROOK 0x10000L /* 0 value is OK even if not within limits */
+#define OPT_NOINCR 0x20000L /* value mustn't be increased */
+#define OPT_ZEROINF 0x40000L /* with OPT_NOINCR, 0 == infinity */
+#define OPT_A2INFO 0x100000L /* addr2 -> option_info to update */
+#define OPT_A2COPY 0x200000L /* addr2 -> second location to rcv value */
+#define OPT_ENABLE 0x400000L /* use *addr2 as enable for option */
+#define OPT_PRIVFIX 0x800000L /* can't be overridden if noauth */
+#define OPT_PREPASS 0x1000000L /* do this opt in pre-pass to find device */
+#define OPT_INITONLY 0x2000000L /* option can only be set in init phase */
+#define OPT_DEVEQUIV 0x4000000L /* equiv to device name */
+#define OPT_DEVNAM (OPT_PREPASS | OPT_INITONLY | OPT_DEVEQUIV)
+
+#define OPT_VAL(x) ((x) & OPT_VALUE)
+
+#ifndef GIDSET_TYPE
+#define GIDSET_TYPE gid_t
+#endif
+
+/* Structure representing a list of permitted IP addresses. */
+struct permitted_ip {
+ int permit; /* 1 = permit, 0 = forbid */
+ uint32_t base; /* match if (addr & mask) == base */
+ uint32_t mask; /* base and mask are in network byte order */
+};
+
+/*
+ * Unfortunately, the linux kernel driver uses a different structure
+ * for statistics from the rest of the ports.
+ * This structure serves as a common representation for the bits
+ * pppd needs.
+ */
+struct pppd_stats {
+ unsigned int bytes_in;
+ unsigned int bytes_out;
+};
+
+/* Used for storing a sequence of words. Usually malloced. */
+struct wordlist {
+ struct wordlist *next;
+ char *word;
+};
+
+/*
+ * Global variables.
+ */
+
+extern int pppd_kill_link; /* Signal to terminate processing loop */
+extern int hungup; /* Physical layer has disconnected */
+extern int pppifunit; /* Interface unit number */
+extern char ifname[]; /* Interface name */
+extern int pppd_ttyfd; /* Serial device file descriptor */
+extern char hostname[]; /* Our hostname */
+extern u_char outpacket_buf[]; /* Buffer for outgoing packets */
+extern int pppd_phase; /* Current state of link - see values below */
+extern int baud_rate; /* Current link speed in bits/sec */
+extern int redirect_stderr;/* Connector's stderr should go to file */
+extern char peer_authname[];/* Authenticated name of peer */
+extern int privileged; /* We were run by real-uid root */
+extern int need_holdoff; /* Need holdoff period after link terminates */
+extern char **script_env; /* Environment variables for scripts */
+extern int detached; /* Have detached from controlling tty */
+extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */
+extern int ngroups; /* How many groups valid in groups */
+extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
+extern int using_pty; /* using pty as device (notty or pty opt.) */
+extern int log_to_fd; /* logging to this fd as well as syslog */
+extern char *no_ppp_msg; /* message to print if ppp not in kernel */
+extern volatile int pppd_status; /* exit status for pppd */
+extern int devnam_fixed; /* can no longer change devnam */
+extern int unsuccess; /* # unsuccessful connection attempts */
+extern int do_callback; /* set if we want to do callback next */
+extern int doing_callback; /* set if this is a callback */
+extern dialerfp pppd_dialer; /* script dialer function callback */
+
+/* Values for do_callback and doing_callback */
+#define CALLBACK_DIALIN 1 /* we are expecting the call back */
+#define CALLBACK_DIALOUT 2 /* we are dialling out to call back */
+
+/*
+ * Variables set by command-line options.
+ */
+
+extern int debug; /* Debug flag */
+extern int kdebugflag; /* Tell kernel to print debug messages */
+extern int default_device; /* Using /dev/tty or equivalent */
+extern char devnam[MAXPATHLEN]; /* Device name */
+extern int crtscts; /* Use hardware flow control */
+extern bool modem; /* Use modem control lines */
+extern int inspeed; /* Input/Output speed requested */
+extern uint32_t netmask; /* IP netmask to set on interface */
+extern bool lockflag; /* Create lock file to lock the serial dev */
+extern bool nodetach; /* Don't detach from controlling tty */
+extern bool updetach; /* Detach from controlling tty when link up */
+extern char *initializer; /* Script to initialize physical link */
+extern char *connect_script; /* Script to establish physical link */
+extern char *disconnect_script; /* Script to disestablish physical link */
+extern char *welcomer; /* Script to welcome client after connection */
+extern char *ptycommand; /* Command to run on other side of pty */
+extern int maxconnect; /* Maximum connect time (seconds) */
+extern char user[MAXNAMELEN];/* Our name for authenticating ourselves */
+extern char passwd[MAXSECRETLEN]; /* Password for PAP or CHAP */
+extern bool auth_required; /* Peer is required to authenticate */
+extern bool persist; /* Reopen link after it goes down */
+extern bool uselogin; /* Use /etc/passwd for checking PAP */
+extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */
+extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
+extern bool explicit_remote;/* remote_name specified with remotename opt */
+extern bool demand; /* Do dial-on-demand */
+extern char *ipparam; /* Extra parameter for ip up/down scripts */
+extern bool cryptpap; /* Others' PAP passwords are encrypted */
+extern int idle_time_limit;/* Shut down link if idle for this long */
+extern int holdoff; /* Dead time before restarting */
+extern bool holdoff_specified; /* true if user gave a holdoff value */
+extern bool notty; /* Stdin/out is not a tty */
+extern char *record_file; /* File to record chars sent/received */
+extern bool sync_serial; /* Device is synchronous serial device */
+extern int maxfail; /* Max # of unsuccessful connection attempts */
+extern char linkname[MAXPATHLEN]; /* logical name for link */
+extern bool tune_kernel; /* May alter kernel settings as necessary */
+extern int connect_delay; /* Time to delay after connect script */
+
+#ifdef PPP_FILTER
+extern struct bpf_program pass_filter; /* Filter for pkts to pass */
+extern struct bpf_program active_filter; /* Filter for link-active pkts */
+#endif
+
+#ifdef MSLANMAN
+extern bool ms_lanman; /* Use LanMan password instead of NT */
+ /* Has meaning only with MS-CHAP challenges */
+#endif
+
+extern char *current_option; /* the name of the option being parsed */
+extern int privileged_option; /* set iff the current option came from root */
+extern char *option_source; /* string saying where the option came from */
+
+/*
+ * Values for phase.
+ */
+#define PHASE_DEAD 0
+#define PHASE_INITIALIZE 1
+#define PHASE_SERIALCONN 2
+#define PHASE_DORMANT 3
+#define PHASE_ESTABLISH 4
+#define PHASE_AUTHENTICATE 5
+#define PHASE_CALLBACK 6
+#define PHASE_NETWORK 7
+#define PHASE_RUNNING 8
+#define PHASE_TERMINATE 9
+#define PHASE_DISCONNECT 10
+#define PHASE_HOLDOFF 11
+
+/*
+ * The following struct gives the addresses of procedures to call
+ * for a particular protocol.
+ */
+struct protent {
+ u_short protocol; /* PPP protocol number */
+ /* Initialization procedure */
+ void (*init)(int unit);
+ /* Process a received packet */
+ void (*input)(int unit, u_char *pkt, int len);
+ /* Process a received protocol-reject */
+ void (*protrej)(int unit);
+ /* Lower layer has come up */
+ void (*lowerup)(int unit);
+ /* Lower layer has gone down */
+ void (*lowerdown)(int unit);
+ /* Open the protocol */
+ void (*open)(int unit);
+ /* Close the protocol */
+ void (*close)(int unit, char *reason);
+ /* Print a packet in readable form */
+ int (*printpkt)(u_char *pkt, int len,
+ void (*printer)(void *, char *, ...),
+ void *arg);
+ /* Process a received data packet */
+ void (*datainput)(int unit, u_char *pkt, int len);
+ bool enabled_flag; /* 0 iff protocol is disabled */
+ char *name; /* Text name of protocol */
+ char *data_name; /* Text name of corresponding data protocol */
+ option_t *options; /* List of command-line options */
+ /* Check requested options, assign defaults */
+ void (*check_options)(void);
+ /* Configure interface for demand-dial */
+ int (*demand_conf)(int unit);
+ /* Say whether to bring up link for this pkt */
+ int (*active_pkt)(u_char *pkt, int len);
+};
+
+/* Table of pointers to supported protocols */
+extern struct protent *protocols[];
+
+/*
+ * Prototypes.
+ */
+
+/* Procedures exported from main.c. */
+void die(int); /* Cleanup and exit */
+void quit(void); /* like die(1) */
+void novm(char *); /* Say we ran out of memory, and die */
+void ppptimeout(void (*func)(void *), void *arg, int t);
+ /* Call func(arg) after t seconds */
+void pppuntimeout(void (*func)(void *), void *arg);
+ /* Cancel call to func(arg) */
+void update_link_stats(int); /* Get stats at link termination */
+void new_phase(int); /* signal start of new phase */
+
+/* Procedures exported from utils.c. */
+void log_packet(u_char *, int, char *, int);
+ /* Format a packet and log it with syslog */
+void print_string(void *, int, void (*) (void *, char *, ...),
+ void *); /* Format a string for output */
+int slprintf(char *, int, char *, ...); /* sprintf++ */
+int vslprintf(char *, int, char *, va_list); /* vsprintf++ */
+size_t strlcpy(char *, const char *, size_t); /* safe strcpy */
+size_t strlcat(char *, const char *, size_t); /* safe strncpy */
+void pppd_dbglog(char *, ...); /* log a debug message */
+void pppd_info(char *, ...); /* log an informational message */
+void pppd_notice(char *, ...); /* log a notice-level message */
+void pppd_warn(char *, ...); /* log a warning message */
+void pppd_error(char *, ...); /* log an error message */
+void pppd_fatal(char *, ...); /* log an error message and die(1) */
+
+#define dbglog pppd_dbglog
+#define info pppd_info
+#define notice pppd_notice
+#define warn pppd_warn
+#define error pppd_error
+#define fatal pppd_fatal
+
+/* Procedures exported from auth.c */
+void link_required(int); /* we are starting to use the link */
+void link_terminated(int); /* we are finished with the link */
+void link_down(int); /* the LCP layer has left the Opened state */
+void link_established(int); /* the link is up; authenticate now */
+void start_networks(void); /* start all the network control protos */
+void np_up(int, int); /* a network protocol has come up */
+void np_down(int, int); /* a network protocol has gone down */
+void np_finished(int, int); /* a network protocol no longer needs link */
+void auth_peer_fail(int, int);
+ /* peer failed to authenticate itself */
+void auth_peer_success(int, int, char *, int);
+ /* peer successfully authenticated itself */
+void auth_withpeer_fail(int, int);
+ /* we failed to authenticate ourselves */
+void auth_withpeer_success(int, int);
+ /* we successfully authenticated ourselves */
+int auth_check_options(void);
+ /* check authentication options supplied */
+void auth_reset(int); /* check what secrets we have */
+int check_passwd(int, char *, int, char *, int, char **);
+ /* Check peer-supplied username/password */
+int get_secret(int, char *, char *, unsigned char *, int *, int);
+ /* get "secret" for chap */
+int auth_ip_addr(int, uint32_t);
+ /* check if IP address is authorized */
+int bad_ip_adrs(uint32_t);
+ /* check if IP address is unreasonable */
+
+/* Procedures exported from demand.c */
+void demand_conf(void); /* config interface(s) for demand-dial */
+void demand_block(void); /* set all NPs to queue up packets */
+void demand_unblock(void); /* set all NPs to pass packets */
+void demand_discard(void); /* set all NPs to discard packets */
+void demand_rexmit(int); /* retransmit saved frames for an NP */
+int loop_chars(unsigned char *, int); /* process chars from loopback */
+int loop_frame(unsigned char *, int); /* should we bring link up? */
+
+/* Procedures exported from sys-*.c */
+void sys_init(void); /* Do system-dependent initialization */
+void sys_cleanup(void); /* Restore system state before exiting */
+int sys_check_options(void); /* Check options specified */
+void sys_close(void); /* Clean up in a child before execing */
+int ppp_available(void); /* Test whether ppp kernel support exists */
+int get_pty(int *, int *, char *, int); /* Get pty master/slave */
+int open_ppp_loopback(void); /* Open loopback for demand-dialling */
+int establish_ppp(int); /* Turn serial port into a ppp interface */
+void restore_loop(void); /* Transfer ppp unit back to loopback */
+void disestablish_ppp(int); /* Restore port to normal operation */
+void clean_check(void); /* Check if line was 8-bit clean */
+void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
+void restore_tty(int); /* Restore port's original parameters */
+void setdtr(int, int); /* Raise or lower port's DTR line */
+void output(int, u_char *, int); /* Output a PPP packet */
+void wait_input(struct timeval *); /* Wait for input, with timeout */
+
+void ppp_delay(void); /* delay task for a little while */
+int read_packet(u_char *); /* Read PPP packet */
+int get_loop_output(void); /* Read pkts from loopback */
+void ppp_send_config(int, int, uint32_t, int, int);
+ /* Configure i/f transmit parameters */
+void ppp_set_xaccm(int, ext_accm);
+ /* Set extended transmit ACCM */
+void ppp_recv_config(int, int, uint32_t, int, int);
+ /* Configure i/f receive parameters */
+int ccp_test(int, u_char *, int, int);
+ /* Test support for compression scheme */
+void ccp_flags_set(int, int, int);
+ /* Set kernel CCP state */
+int ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
+int get_idle_time(int, struct ppp_idle *);
+ /* Find out how long link has been idle */
+int get_ppp_stats(int, struct pppd_stats *);
+ /* Return link statistics */
+int sifvjcomp(int, int, int, int);
+ /* Configure VJ TCP header compression */
+int sifup(int); /* Configure i/f up for one protocol */
+int sifnpmode(int u, int proto, enum NPmode mode);
+ /* Set mode for handling packets for proto */
+int sifdown(int); /* Configure i/f down for one protocol */
+int sifaddr(int, uint32_t, uint32_t, uint32_t);
+ /* Configure IPv4 addresses for i/f */
+int cifaddr(int, uint32_t, uint32_t);
+ /* Reset i/f IP addresses */
+#ifdef INET6
+int sif6addr(int, eui64_t, eui64_t);
+ /* Configure IPv6 addresses for i/f */
+int cif6addr(int, eui64_t, eui64_t);
+ /* Remove an IPv6 address from i/f */
+#endif
+int sifdefaultroute(int, uint32_t, uint32_t);
+ /* Create default route through i/f */
+int cifdefaultroute(int, uint32_t, uint32_t);
+ /* Delete default route through i/f */
+int sifproxyarp(int, uint32_t);
+ /* Add proxy ARP entry for peer */
+int cifproxyarp(int, uint32_t);
+ /* Delete proxy ARP entry for peer */
+uint32_t GetMask(uint32_t); /* Get appropriate netmask for address */
+int lock(char *); /* Create lock file for device */
+int relock(int); /* Rewrite lock file with new pid */
+void unlock(void); /* Delete previously-created lock file */
+void logwtmp(const char *, const char *, const char *);
+ /* Write entry to wtmp file */
+int get_host_seed(void); /* Get host-dependent random number seed */
+int have_route_to(uint32_t); /* Check if route to addr exists */
+#ifdef PPP_FILTER
+int set_filters(struct bpf_program *pass, struct bpf_program *active);
+ /* Set filter programs in kernel */
+#endif
+#ifdef IPX_CHANGE
+int sipxfaddr(int, unsigned long, unsigned char *);
+int cipxfaddr(int);
+#endif
+
+/* Procedures exported from options.c */
+int parse_args(int argc, char **argv);
+ /* Parse options from arguments given */
+int options_from_file(char *filename, int must_exist, int check_prot,
+ int privileged);
+ /* Parse options from an options file */
+int options_from_user(void); /* Parse options from user's .ppprc */
+int options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
+int options_from_list(struct wordlist *, int privileged);
+ /* Parse options from a wordlist */
+int getword(FILE *f, char *word, int *newlinep, char *filename);
+ /* Read a word from a file */
+void option_error(char *fmt, ...);
+ /* Print an error message about an option */
+int int_option(char *, int *);
+ /* Simplified number_option for decimal ints */
+void add_options(option_t *); /* Add extra options */
+
+/*
+ * This structure is used to store information about certain
+ * options, such as where the option value came from (/etc/ppp/options,
+ * command line, etc.) and whether it came from a privileged source.
+ */
+
+struct option_info {
+ int priv; /* was value set by sysadmin? */
+ char *source; /* where option came from */
+};
+
+extern struct option_info devnam_info;
+extern struct option_info initializer_info;
+extern struct option_info connect_script_info;
+extern struct option_info disconnect_script_info;
+extern struct option_info welcomer_info;
+extern struct option_info ptycommand_info;
+
+/*
+ * Hooks to enable plugins to change various things.
+ */
+extern int (*new_phase_hook)(int);
+extern int (*idle_time_hook)(struct ppp_idle *);
+extern int (*holdoff_hook)(void);
+extern int (*pap_check_hook)(void);
+extern int (*pap_auth_hook)(char *user, char *passwd/*, char **msgp,
+ struct wordlist **paddrs,
+ struct wordlist **popts*/);
+extern void (*pap_logout_hook)(void);
+extern int (*pap_passwd_hook)(char *user, char *passwd);
+extern void (*ip_up_hook)(void);
+extern void (*ip_down_hook)(void);
+extern void (*auth_linkup_hook)(void);
+extern void (*auth_linkdown_hook)(void);
+
+/*
+ * Inline versions of get/put char/short/long.
+ * Pointer is advanced; we assume that both arguments
+ * are lvalues and will already be in registers.
+ * cp MUST be u_char *.
+ */
+#define GETCHAR(c, cp) { \
+ (c) = *(cp)++; \
+}
+#define PUTCHAR(c, cp) { \
+ *(cp)++ = (u_char) (c); \
+}
+
+
+#define GETSHORT(s, cp) { \
+ (s) = *(cp)++ << 8; \
+ (s) |= *(cp)++; \
+}
+#define PUTSHORT(s, cp) { \
+ *(cp)++ = (u_char) ((s) >> 8); \
+ *(cp)++ = (u_char) (s); \
+}
+
+#define GETLONG(l, cp) { \
+ (l) = *(cp)++ << 8; \
+ (l) |= *(cp)++; (l) <<= 8; \
+ (l) |= *(cp)++; (l) <<= 8; \
+ (l) |= *(cp)++; \
+}
+#define PUTLONG(l, cp) { \
+ *(cp)++ = (u_char) ((l) >> 24); \
+ *(cp)++ = (u_char) ((l) >> 16); \
+ *(cp)++ = (u_char) ((l) >> 8); \
+ *(cp)++ = (u_char) (l); \
+}
+
+#define INCPTR(n, cp) ((cp) += (n))
+#define DECPTR(n, cp) ((cp) -= (n))
+
+/*
+ * System dependent definitions for user-level 4.3BSD UNIX implementation.
+ */
+
+#define TIMEOUT(r, f, t) ppptimeout((r), (f), (t))
+#define UNTIMEOUT(r, f) pppuntimeout((r), (f))
+
+#define BCOPY(s, d, l) memcpy(d, s, l)
+#define BZERO(s, n) memset(s, 0, n)
+
+#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); }
+
+/*
+ * MAKEHEADER - Add Header fields to a packet.
+ */
+#define MAKEHEADER(p, t) { \
+ PUTCHAR(PPP_ALLSTATIONS, p); \
+ PUTCHAR(PPP_UI, p); \
+ PUTSHORT(t, p); }
+
+/*
+ * Exit status values.
+ */
+#define EXIT_OK 0
+#define EXIT_FATAL_ERROR 1
+#define EXIT_OPTION_ERROR 2
+#define EXIT_NOT_ROOT 3
+#define EXIT_NO_KERNEL_SUPPORT 4
+#define EXIT_USER_REQUEST 5
+#define EXIT_LOCK_FAILED 6
+#define EXIT_OPEN_FAILED 7
+#define EXIT_CONNECT_FAILED 8
+#define EXIT_PTYCMD_FAILED 9
+#define EXIT_NEGOTIATION_FAILED 10
+#define EXIT_PEER_AUTH_FAILED 11
+#define EXIT_IDLE_TIMEOUT 12
+#define EXIT_CONNECT_TIME 13
+#define EXIT_CALLBACK 14
+#define EXIT_PEER_DEAD 15
+#define EXIT_HANGUP 16
+#define EXIT_LOOPBACK 17
+#define EXIT_INIT_FAILED 18
+#define EXIT_AUTH_TOPEER_FAILED 19
+
+/*
+ * Debug macros. Slightly useful for finding bugs in pppd, not particularly
+ * useful for finding out why your connection isn't being established.
+ */
+
+#ifdef DEBUGALL
+#define DEBUGMAIN 1
+#define DEBUGFSM 1
+#define DEBUGLCP 1
+#define DEBUGIPCP 1
+#define DEBUGIPV6CP 1
+#define DEBUGUPAP 1
+#define DEBUGCHAP 1
+#endif
+#define DEBUGMAIN 1
+#define DEBUGUPAP 1
+#define DEBUGCHAP 1
+
+
+#ifdef DEBUGMAIN
+#define MAINDEBUG(x) if (debug) dbglog x
+#else
+#define MAINDEBUG(x)
+#endif
+
+#ifdef DEBUGSYS
+#define SYSDEBUG(x) if (debug) dbglog x
+#else
+#define SYSDEBUG(x)
+#endif
+
+#ifdef DEBUGFSM
+#define FSMDEBUG(x) if (debug) dbglog x
+#else
+#define FSMDEBUG(x)
+#endif
+
+#ifdef DEBUGLCP
+#define LCPDEBUG(x) if (debug) dbglog x
+#else
+#define LCPDEBUG(x)
+#endif
+
+#ifdef DEBUGIPCP
+#define IPCPDEBUG(x) if (debug) dbglog x
+#else
+#define IPCPDEBUG(x)
+#endif
+
+#ifdef DEBUGIPV6CP
+#define IPV6CPDEBUG(x) if (debug) dbglog x
+#else
+#define IPV6CPDEBUG(x)
+#endif
+
+#ifdef DEBUGUPAP
+#define UPAPDEBUG(x) if (debug) dbglog x
+#else
+#define UPAPDEBUG(x)
+#endif
+
+#ifdef DEBUGCHAP
+#define CHAPDEBUG(x) if (debug) dbglog x
+#else
+#define CHAPDEBUG(x)
+#endif
+
+#ifdef DEBUGIPXCP
+#define IPXCPDEBUG(x) if (debug) dbglog x
+#else
+#define IPXCPDEBUG(x)
+#endif
+
+#ifndef SIGTYPE
+#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
+#define SIGTYPE void
+#else
+#define SIGTYPE int
+#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
+#endif /* SIGTYPE */
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b)? (a): (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) ((a) > (b)? (a): (b))
+#endif
+
+#endif /* __PPP_H__ */
diff --git a/cpukit/pppd/preinstall.am b/cpukit/pppd/preinstall.am
new file mode 100644
index 0000000000..9479a04ce8
--- /dev/null
+++ b/cpukit/pppd/preinstall.am
@@ -0,0 +1,43 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+if LIBNETWORKING
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/rtemspppd.h: rtemspppd.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtemspppd.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtemspppd.h
+
+$(PROJECT_INCLUDE)/rtems/rtemsdialer.h: rtemsdialer.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtemsdialer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtemsdialer.h
+
+$(PROJECT_LIB)/libpppd.a: libpppd.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libpppd.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libpppd.a
+endif
diff --git a/cpukit/pppd/rtemsdialer.h b/cpukit/pppd/rtemsdialer.h
new file mode 100644
index 0000000000..611986b802
--- /dev/null
+++ b/cpukit/pppd/rtemsdialer.h
@@ -0,0 +1,24 @@
+
+#ifndef DIALER_H
+#define DIALER_H
+
+/* define constant mode values */
+#define DIALER_INIT 0
+#define DIALER_CONNECT 1
+#define DIALER_WELCOME 2
+#define DIALER_DISCONNECT 3
+
+/* define constant return values */
+#define DIALER_SUCCESS 0
+#define DIALER_INVALIDARG 1
+#define DIALER_UNEXPECTED 2
+#define DIALER_TIMEOUT 3
+#define DIALER_CMDFAILED 4
+
+/* define typedef for dialer function prototype */
+typedef int (*dialerfp)(int tty, int mode, char *pScript);
+
+/* declare default chat program dialer */
+extern int chatmain(int tty, int mode, char *pScript);
+
+#endif
diff --git a/cpukit/pppd/rtemsmain.c b/cpukit/pppd/rtemsmain.c
new file mode 100644
index 0000000000..89ed77682e
--- /dev/null
+++ b/cpukit/pppd/rtemsmain.c
@@ -0,0 +1,896 @@
+/*
+ * main.c - Point-to-Point Protocol main module
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <pwd.h>
+#include <setjmp.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+
+#include "pppd.h"
+#include "magic.h"
+#include "fsm.h"
+#include "lcp.h"
+#include "ipcp.h"
+#ifdef INET6
+#include "ipv6cp.h"
+#endif
+#include "upap.h"
+#include "chap.h"
+#include "ccp.h"
+#include "pathnames.h"
+#include "patchlevel.h"
+#include "rtemsdialer.h"
+
+#ifdef CBCP_SUPPORT
+#include "cbcp.h"
+#endif
+
+#ifdef IPX_CHANGE
+#include "ipxcp.h"
+#endif /* IPX_CHANGE */
+#ifdef AT_CHANGE
+#include "atcp.h"
+#endif
+
+static const char rcsid[] = RCSID;
+
+/* interface vars */
+char ifname[32]; /* Interface name */
+int pppifunit; /* Interface unit number */
+
+char hostname[MAXNAMELEN]; /* Our hostname */
+static char ppp_devnam[MAXPATHLEN]; /* name of PPP tty (maybe ttypx) */
+
+int pppd_ttyfd; /* Serial port file descriptor */
+int baud_rate; /* Actual bits/second for serial device */
+int hungup; /* terminal has been hung up */
+int privileged; /* we're running as real uid root */
+int need_holdoff; /* need holdoff period before restarting */
+int detached; /* have detached from terminal */
+struct stat devstat; /* result of stat() on devnam */
+int prepass = 0; /* doing prepass to find device name */
+int devnam_fixed; /* set while in options.ttyxx file */
+volatile int pppd_status; /* exit status for pppd */
+int unsuccess; /* # unsuccessful connection attempts */
+int do_callback; /* != 0 if we should do callback next */
+int doing_callback; /* != 0 if we are doing callback */
+char *callback_script; /* script for doing callback */
+dialerfp pppd_dialer;
+
+int (*holdoff_hook)(void) = NULL;
+int (*new_phase_hook)(int) = NULL;
+
+static int fd_ppp = -1; /* fd for talking PPP */
+static int pty_master; /* fd for master side of pty */
+static int pty_slave; /* fd for slave side of pty */
+static int real_ttyfd; /* fd for actual serial port (not pty) */
+
+int pppd_phase; /* where the link is at */
+int pppd_kill_link;
+int open_ccp_flag;
+
+char **script_env; /* Env. variable values for scripts */
+int s_env_nalloc; /* # words avail at script_env */
+
+u_char outpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for outgoing packet */
+u_char inpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for incoming packet */
+
+char *no_ppp_msg = "Sorry - this system lacks PPP kernel support\n";
+
+static struct timeval start_time; /* Time when link was started. */
+
+struct pppd_stats link_stats;
+int link_connect_time;
+int link_stats_valid;
+
+/* Prototypes for procedures local to this file. */
+
+static void cleanup(void);
+static void close_tty(void);
+static void get_input(void);
+static void calltimeout(void);
+static struct timeval *timeleft(struct timeval *);
+static void holdoff_end(void *);
+static int device_script(int, int, char *);
+
+extern char *ttyname(int);
+extern char *getlogin(void);
+int pppdmain(int, char *[]);
+
+/*
+ * PPP Data Link Layer "protocol" table.
+ * One entry per supported protocol.
+ * The last entry must be NULL.
+ */
+struct protent *protocols[] = {
+ &lcp_protent,
+ &pap_protent,
+ &chap_protent,
+#ifdef CBCP_SUPPORT
+ &cbcp_protent,
+#endif
+ &ipcp_protent,
+#ifdef INET6
+ &ipv6cp_protent,
+#endif
+ &ccp_protent,
+#ifdef IPX_CHANGE
+ &ipxcp_protent,
+#endif
+#ifdef AT_CHANGE
+ &atcp_protent,
+#endif
+ NULL
+};
+
+int
+pppdmain(
+ int argc,
+ char *argv[])
+{
+ int i, fdflags, t;
+ char *connector;
+ struct timeval timo;
+ struct protent *protp;
+
+ new_phase(PHASE_INITIALIZE);
+
+ script_env = NULL;
+ hostname[MAXNAMELEN-1] = 0;
+ privileged = 1;
+ privileged_option = 1;
+
+ /*
+ * Initialize magic number generator now so that protocols may
+ * use magic numbers in initialization.
+ */
+ magic_init();
+
+#ifdef XXX_XXX
+ /* moved code the the rtems_pppd_reset_options function */
+
+ /*
+ * Initialize to the standard option set, then parse, in order,
+ * the system options file, the user's options file,
+ * the tty's options file, and the command line arguments.
+ */
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ (*protp->init)(0);
+#endif
+
+
+ if (!ppp_available()) {
+ option_error(no_ppp_msg);
+ return(EXIT_NO_KERNEL_SUPPORT);
+ }
+
+ /*
+ * Check that the options given are valid and consistent.
+ */
+ if (!sys_check_options()) {
+ return(EXIT_OPTION_ERROR);
+ }
+ if (!auth_check_options()) {
+ return(EXIT_OPTION_ERROR);
+ }
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (protp->check_options != NULL)
+ (*protp->check_options)();
+
+ /* default holdoff to 0 if no connect script has been given */
+ if (connect_script == 0 && !holdoff_specified)
+ holdoff = 0;
+
+ if (default_device)
+ nodetach = 1;
+
+ /*
+ * Initialize system-dependent stuff.
+ */
+ sys_init();
+ /* if (debug)
+ setlogmask(LOG_UPTO(LOG_DEBUG));
+ */
+
+ do_callback = 0;
+ for (;;) {
+
+ need_holdoff = 1;
+ pppd_ttyfd = -1;
+ real_ttyfd = -1;
+ pppd_status = EXIT_OK;
+ ++unsuccess;
+ doing_callback = do_callback;
+ do_callback = 0;
+
+ new_phase(PHASE_SERIALCONN);
+
+ /*
+ * Get a pty master/slave pair if the pty, notty, or record
+ * options were specified.
+ */
+ strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam));
+ pty_master = -1;
+ pty_slave = -1;
+
+ /*
+ * Open the serial device and set it up to be the ppp interface.
+ * First we open it in non-blocking mode so we can set the
+ * various termios flags appropriately. If we aren't dialling
+ * out and we want to use the modem lines, we reopen it later
+ * in order to wait for the carrier detect signal from the modem.
+ */
+ hungup = 0;
+ pppd_kill_link = 0;
+ connector = doing_callback? callback_script: connect_script;
+ if (devnam[0] != 0) {
+ for (;;) {
+ /* If the user specified the device name, become the
+ user before opening it. */
+ int err;
+ pppd_ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
+ err = errno;
+ if (pppd_ttyfd >= 0) {
+ break;
+ }
+ errno = err;
+ if (err != EINTR) {
+ error("Failed to open %s: %m", devnam);
+ pppd_status = EXIT_OPEN_FAILED;
+ }
+ if (!persist || err != EINTR)
+ goto fail;
+ }
+ if ((fdflags = fcntl(pppd_ttyfd, F_GETFL)) == -1
+ || fcntl(pppd_ttyfd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
+ warn("Couldn't reset non-blocking mode on device: %m");
+
+ /*
+ * Set line speed, flow control, etc.
+ * If we have a non-null connection or initializer script,
+ * on most systems we set CLOCAL for now so that we can talk
+ * to the modem before carrier comes up. But this has the
+ * side effect that we might miss it if CD drops before we
+ * get to clear CLOCAL below. On systems where we can talk
+ * successfully to the modem with CLOCAL clear and CD down,
+ * we could clear CLOCAL at this point.
+ */
+ set_up_tty(pppd_ttyfd, ((connector != NULL && connector[0] != 0)
+ || initializer != NULL));
+ real_ttyfd = pppd_ttyfd;
+ }
+
+ /* run connection script */
+ if ((connector && connector[0]) || initializer) {
+ if (real_ttyfd != -1) {
+ /* XXX do this if doing_callback == CALLBACK_DIALIN? */
+ if (!default_device && modem) {
+ setdtr(real_ttyfd, 0); /* in case modem is off hook */
+ sleep(1);
+ setdtr(real_ttyfd, 1);
+ }
+ }
+
+ if (initializer && initializer[0]) {
+ if (device_script(pppd_ttyfd, DIALER_INIT, initializer) < 0) {
+ error("Initializer script failed");
+ pppd_status = EXIT_INIT_FAILED;
+ goto fail;
+ }
+ if (pppd_kill_link)
+ goto disconnect;
+
+ info("Serial port initialized.");
+ }
+
+ if (connector && connector[0]) {
+ if (device_script(pppd_ttyfd, DIALER_CONNECT, connector) < 0) {
+ error("Connect script failed");
+ pppd_status = EXIT_CONNECT_FAILED;
+ goto fail;
+ }
+ if (pppd_kill_link)
+ goto disconnect;
+
+ info("Serial connection established.");
+ }
+
+ /* set line speed, flow control, etc.;
+ clear CLOCAL if modem option */
+ if (real_ttyfd != -1)
+ set_up_tty(real_ttyfd, 0);
+
+ if (doing_callback == CALLBACK_DIALIN)
+ connector = NULL;
+ }
+
+ /* reopen tty if necessary to wait for carrier */
+ if (connector == NULL && modem && devnam[0] != 0) {
+ for (;;) {
+ if ((i = open(devnam, O_RDWR)) >= 0)
+ break;
+ if (errno != EINTR) {
+ error("Failed to reopen %s: %m", devnam);
+ pppd_status = EXIT_OPEN_FAILED;
+ }
+ if (!persist || errno != EINTR || hungup || pppd_kill_link)
+ goto fail;
+ }
+ close(i);
+ }
+
+ info("Serial connection established.");
+ sleep(1);
+
+ /* run welcome script, if any */
+ if (welcomer && welcomer[0]) {
+ if (device_script(pppd_ttyfd, DIALER_WELCOME, welcomer) < 0)
+ warn("Welcome script failed");
+ }
+
+ /* set up the serial device as a ppp interface */
+ fd_ppp = establish_ppp(pppd_ttyfd);
+ if (fd_ppp < 0) {
+ pppd_status = EXIT_FATAL_ERROR;
+ goto disconnect;
+ }
+
+ if (!demand) {
+ info("Using interface ppp%d", pppifunit);
+ slprintf(ifname, sizeof(ifname), "ppp%d", pppifunit);
+ }
+
+ /*
+ * Start opening the connection and wait for
+ * incoming events (reply, timeout, etc.).
+ */
+ notice("Connect: %s <--> %s", ifname, ppp_devnam);
+ gettimeofday(&start_time, NULL);
+
+ lcp_lowerup(0);
+ lcp_open(0); /* Start protocol */
+
+ open_ccp_flag = 0;
+ pppd_status = EXIT_NEGOTIATION_FAILED;
+ new_phase(PHASE_ESTABLISH);
+ while (pppd_phase != PHASE_DEAD) {
+ wait_input(timeleft(&timo));
+ calltimeout();
+ get_input();
+
+ if (pppd_kill_link) {
+ lcp_close(0, "User request");
+ pppd_kill_link = 0;
+ }
+ if (open_ccp_flag) {
+ if (pppd_phase == PHASE_NETWORK || pppd_phase == PHASE_RUNNING) {
+ ccp_fsm[0].flags = OPT_RESTART; /* clears OPT_SILENT */
+ (*ccp_protent.open)(0);
+ }
+ open_ccp_flag = 0;
+ }
+ }
+
+ /*
+ * If we may want to bring the link up again, transfer
+ * the ppp unit back to the loopback. Set the
+ * real serial device back to its normal mode of operation.
+ */
+ clean_check();
+ if (demand)
+ restore_loop();
+ disestablish_ppp(pppd_ttyfd);
+ fd_ppp = -1;
+ if (!hungup)
+ lcp_lowerdown(0);
+
+ /*
+ * Run disconnector script, if requested.
+ * XXX we may not be able to do this if the line has hung up!
+ */
+ disconnect:
+ if (disconnect_script && !hungup) {
+ new_phase(PHASE_DISCONNECT);
+ if (real_ttyfd >= 0)
+ set_up_tty(real_ttyfd, 1);
+ if (device_script(pppd_ttyfd, DIALER_DISCONNECT, disconnect_script) < 0) {
+ warn("disconnect script failed");
+ } else {
+ info("Serial link disconnected.");
+ }
+ }
+
+ fail:
+ if (pty_master >= 0)
+ close(pty_master);
+ if (pty_slave >= 0)
+ close(pty_slave);
+ if (real_ttyfd >= 0)
+ close_tty();
+
+ if (!persist || (maxfail > 0 && unsuccess >= maxfail))
+ break;
+
+ pppd_kill_link = 0;
+ if (demand)
+ demand_discard();
+ t = need_holdoff? holdoff: 0;
+ if (holdoff_hook)
+ t = (*holdoff_hook)();
+ if (t > 0) {
+ new_phase(PHASE_HOLDOFF);
+ TIMEOUT(holdoff_end, NULL, t);
+ do {
+ wait_input(timeleft(&timo));
+
+ calltimeout();
+ if (pppd_kill_link) {
+ pppd_kill_link = 0;
+ new_phase(PHASE_DORMANT); /* allow signal to end holdoff */
+ }
+ } while (pppd_phase == PHASE_HOLDOFF);
+ if (!persist)
+ break;
+ }
+ }
+
+ die(pppd_status);
+ return pppd_status;
+}
+
+/*
+ * holdoff_end - called via a timeout when the holdoff period ends.
+ */
+static void
+holdoff_end(
+ void *arg)
+{
+ new_phase(PHASE_DORMANT);
+}
+
+/* List of protocol names, to make our messages a little more informative. */
+struct protocol_list {
+ u_short proto;
+ const char *name;
+} protocol_list[] = {
+ { 0x21, "IP" },
+ { 0x23, "OSI Network Layer" },
+ { 0x25, "Xerox NS IDP" },
+ { 0x27, "DECnet Phase IV" },
+ { 0x29, "Appletalk" },
+ { 0x2b, "Novell IPX" },
+ { 0x2d, "VJ compressed TCP/IP" },
+ { 0x2f, "VJ uncompressed TCP/IP" },
+ { 0x31, "Bridging PDU" },
+ { 0x33, "Stream Protocol ST-II" },
+ { 0x35, "Banyan Vines" },
+ { 0x39, "AppleTalk EDDP" },
+ { 0x3b, "AppleTalk SmartBuffered" },
+ { 0x3d, "Multi-Link" },
+ { 0x3f, "NETBIOS Framing" },
+ { 0x41, "Cisco Systems" },
+ { 0x43, "Ascom Timeplex" },
+ { 0x45, "Fujitsu Link Backup and Load Balancing (LBLB)" },
+ { 0x47, "DCA Remote Lan" },
+ { 0x49, "Serial Data Transport Protocol (PPP-SDTP)" },
+ { 0x4b, "SNA over 802.2" },
+ { 0x4d, "SNA" },
+ { 0x4f, "IP6 Header Compression" },
+ { 0x6f, "Stampede Bridging" },
+ { 0xfb, "single-link compression" },
+ { 0xfd, "1st choice compression" },
+ { 0x0201, "802.1d Hello Packets" },
+ { 0x0203, "IBM Source Routing BPDU" },
+ { 0x0205, "DEC LANBridge100 Spanning Tree" },
+ { 0x0231, "Luxcom" },
+ { 0x0233, "Sigma Network Systems" },
+ { 0x8021, "Internet Protocol Control Protocol" },
+ { 0x8023, "OSI Network Layer Control Protocol" },
+ { 0x8025, "Xerox NS IDP Control Protocol" },
+ { 0x8027, "DECnet Phase IV Control Protocol" },
+ { 0x8029, "Appletalk Control Protocol" },
+ { 0x802b, "Novell IPX Control Protocol" },
+ { 0x8031, "Bridging NCP" },
+ { 0x8033, "Stream Protocol Control Protocol" },
+ { 0x8035, "Banyan Vines Control Protocol" },
+ { 0x803d, "Multi-Link Control Protocol" },
+ { 0x803f, "NETBIOS Framing Control Protocol" },
+ { 0x8041, "Cisco Systems Control Protocol" },
+ { 0x8043, "Ascom Timeplex" },
+ { 0x8045, "Fujitsu LBLB Control Protocol" },
+ { 0x8047, "DCA Remote Lan Network Control Protocol (RLNCP)" },
+ { 0x8049, "Serial Data Control Protocol (PPP-SDCP)" },
+ { 0x804b, "SNA over 802.2 Control Protocol" },
+ { 0x804d, "SNA Control Protocol" },
+ { 0x804f, "IP6 Header Compression Control Protocol" },
+ { 0x006f, "Stampede Bridging Control Protocol" },
+ { 0x80fb, "Single Link Compression Control Protocol" },
+ { 0x80fd, "Compression Control Protocol" },
+ { 0xc021, "Link Control Protocol" },
+ { 0xc023, "Password Authentication Protocol" },
+ { 0xc025, "Link Quality Report" },
+ { 0xc027, "Shiva Password Authentication Protocol" },
+ { 0xc029, "CallBack Control Protocol (CBCP)" },
+ { 0xc081, "Container Control Protocol" },
+ { 0xc223, "Challenge Handshake Authentication Protocol" },
+ { 0xc281, "Proprietary Authentication Protocol" },
+ { 0, NULL },
+};
+
+/*
+ * protocol_name - find a name for a PPP protocol.
+ */
+const char *
+protocol_name(
+ int proto)
+{
+ struct protocol_list *lp;
+
+ for (lp = protocol_list; lp->proto != 0; ++lp)
+ if (proto == lp->proto)
+ return lp->name;
+ return NULL;
+}
+
+/*
+ * get_input - called when incoming data is available.
+ */
+static void
+get_input(void)
+{
+ int len, i;
+ u_char *p;
+ u_short protocol;
+ struct protent *protp;
+
+ p = inpacket_buf; /* point to beginning of packet buffer */
+
+ len = read_packet(inpacket_buf);
+ if (len < 0)
+ return;
+
+ if (len == 0) {
+ notice("Modem hangup");
+ hungup = 1;
+ pppd_status = EXIT_HANGUP;
+ lcp_lowerdown(0); /* serial link is no longer available */
+ link_terminated(0);
+ return;
+ }
+
+ if (debug /*&& (debugflags & DBG_INPACKET)*/)
+ dbglog("rcvd %P", p, len);
+
+ if (len < PPP_HDRLEN) {
+ MAINDEBUG(("io(): Received short packet."));
+ return;
+ }
+
+ p += 2; /* Skip address and control */
+ GETSHORT(protocol, p);
+ len -= PPP_HDRLEN;
+
+ /*
+ * Toss all non-LCP packets unless LCP is OPEN.
+ */
+ if (protocol != PPP_LCP && lcp_fsm[0].state != OPENED) {
+ MAINDEBUG(("get_input: Received non-LCP packet when LCP not open."));
+ return;
+ }
+
+ /*
+ * Until we get past the authentication phase, toss all packets
+ * except LCP, LQR and authentication packets.
+ */
+ if (pppd_phase <= PHASE_AUTHENTICATE
+ && !(protocol == PPP_LCP || protocol == PPP_LQR
+ || protocol == PPP_PAP || protocol == PPP_CHAP)) {
+ MAINDEBUG(("get_input: discarding proto 0x%x in phase %d",
+ protocol, pppd_phase));
+ return;
+ }
+
+ /*
+ * Upcall the proper protocol input routine.
+ */
+ for (i = 0; (protp = protocols[i]) != NULL; ++i) {
+ if (protp->protocol == protocol && protp->enabled_flag) {
+ (*protp->input)(0, p, len);
+ return;
+ }
+ if (protocol == (protp->protocol & ~0x8000) && protp->enabled_flag
+ && protp->datainput != NULL) {
+ (*protp->datainput)(0, p, len);
+ return;
+ }
+ }
+
+ if (debug) {
+ const char *pname = protocol_name(protocol);
+ if (pname != NULL)
+ warn("Unsupported protocol '%s' (0x%x) received", pname, protocol);
+ else
+ warn("Unsupported protocol 0x%x received", protocol);
+ }
+ lcp_sprotrej(0, p - PPP_HDRLEN, len + PPP_HDRLEN);
+
+ return;
+}
+
+/*
+ * new_phase - signal the start of a new phase of pppd's operation.
+ */
+void
+new_phase(
+ int p)
+{
+ pppd_phase = p;
+ if (new_phase_hook)
+ (*new_phase_hook)(p);
+}
+
+/*
+ * die - clean up state and exit with the specified status.
+ */
+void
+die(
+ int status)
+{
+ cleanup();
+}
+
+/*
+ * cleanup - restore anything which needs to be restored before we exit
+ */
+/* ARGSUSED */
+static void
+cleanup(void)
+{
+ sys_cleanup();
+
+ if (fd_ppp >= 0)
+ disestablish_ppp(pppd_ttyfd);
+ if (real_ttyfd >= 0)
+ close_tty();
+
+ sys_close();
+}
+
+/*
+ * close_tty - restore the terminal device and close it.
+ */
+static void
+close_tty(void)
+{
+ /* drop dtr to hang up */
+ if (!default_device && modem) {
+ setdtr(real_ttyfd, 0);
+ /*
+ * This sleep is in case the serial port has CLOCAL set by default,
+ * and consequently will reassert DTR when we close the device.
+ */
+ sleep(1);
+ }
+
+ restore_tty(real_ttyfd);
+
+ close(real_ttyfd);
+ real_ttyfd = -1;
+}
+
+/*
+ * update_link_stats - get stats at link termination.
+ */
+void
+update_link_stats(
+ int u)
+{
+ struct timeval now;
+ char numbuf[32];
+
+ if (!get_ppp_stats(u, &link_stats)
+ || gettimeofday(&now, NULL) < 0)
+ return;
+ link_connect_time = now.tv_sec - start_time.tv_sec;
+ link_stats_valid = 1;
+
+ slprintf(numbuf, sizeof(numbuf), "%d", link_connect_time);
+ slprintf(numbuf, sizeof(numbuf), "%d", link_stats.bytes_out);
+ slprintf(numbuf, sizeof(numbuf), "%d", link_stats.bytes_in);
+}
+
+struct callout {
+ struct timeval c_time; /* time at which to call routine */
+ void *c_arg; /* argument to routine */
+ void (*c_func)(void *); /* routine */
+ struct callout *c_next;
+};
+
+static struct callout *callout = NULL; /* Callout list */
+static struct timeval timenow; /* Current time */
+
+/*
+ * timeout - Schedule a timeout.
+ *
+ * Note that this timeout takes the number of seconds, NOT hz (as in
+ * the kernel).
+ */
+void
+ppptimeout(
+ void (*func)(void *),
+ void *arg,
+ int time)
+{
+ struct callout *newp, *p, **pp;
+
+ MAINDEBUG(("Timeout %p:%p in %d seconds.", func, arg, time));
+
+ /*
+ * Allocate timeout.
+ */
+ if ((newp = (struct callout *) malloc(sizeof(struct callout))) == NULL)
+ fatal("Out of memory in timeout()!");
+ newp->c_arg = arg;
+ newp->c_func = func;
+ gettimeofday(&timenow, NULL);
+ newp->c_time.tv_sec = timenow.tv_sec + time;
+ newp->c_time.tv_usec = timenow.tv_usec;
+
+ /*
+ * Find correct place and link it in.
+ */
+ for (pp = &callout; (p = *pp); pp = &p->c_next)
+ if (newp->c_time.tv_sec < p->c_time.tv_sec
+ || (newp->c_time.tv_sec == p->c_time.tv_sec
+ && newp->c_time.tv_usec < p->c_time.tv_usec))
+ break;
+ newp->c_next = p;
+ *pp = newp;
+}
+
+
+/*
+ * untimeout - Unschedule a timeout.
+ */
+void
+pppuntimeout(
+ void (*func)(void *),
+ void *arg)
+{
+ struct callout **copp, *freep;
+
+ MAINDEBUG(("Untimeout %p:%p.", func, arg));
+
+ /*
+ * Find first matching timeout and remove it from the list.
+ */
+ for (copp = &callout; (freep = *copp); copp = &freep->c_next)
+ if (freep->c_func == func && freep->c_arg == arg) {
+ *copp = freep->c_next;
+ free((char *) freep);
+ break;
+ }
+}
+
+
+/*
+ * calltimeout - Call any timeout routines which are now due.
+ */
+static void
+calltimeout(void)
+{
+ struct callout *p;
+
+ while (callout != NULL) {
+ p = callout;
+
+ if (gettimeofday(&timenow, NULL) < 0)
+ fatal("Failed to get time of day: %m");
+ if (!(p->c_time.tv_sec < timenow.tv_sec
+ || (p->c_time.tv_sec == timenow.tv_sec
+ && p->c_time.tv_usec <= timenow.tv_usec)))
+ break; /* no, it's not time yet */
+
+ callout = p->c_next;
+ (*p->c_func)(p->c_arg);
+
+ free((char *) p);
+ }
+}
+
+
+/*
+ * timeleft - return the length of time until the next timeout is due.
+ */
+static struct timeval *
+timeleft(
+ struct timeval *tvp)
+{
+ if (callout == NULL)
+ return NULL;
+
+ gettimeofday(&timenow, NULL);
+ tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
+ tvp->tv_usec = callout->c_time.tv_usec - timenow.tv_usec;
+ if (tvp->tv_usec < 0) {
+ tvp->tv_usec += 1000000;
+ tvp->tv_sec -= 1;
+ }
+ if (tvp->tv_sec < 0)
+ tvp->tv_sec = tvp->tv_usec = 0;
+
+ return tvp;
+}
+
+/*
+ * device_script - run a program to talk to the serial device
+ * (e.g. to run the connector or disconnector script).
+ */
+static int device_script(int fd, int mode, char *program)
+{
+ int iReturn = -1;
+ char pScript[128];
+
+ /* copyt script into temporary location */
+ strcpy(pScript, program);
+
+ /* check to see if dialer was initialized */
+ if ( !pppd_dialer ) {
+ /* set default dialer to chatmain */
+ pppd_dialer = chatmain;
+ }
+
+ /* check to see if dialer is set */
+ if ( pppd_dialer ) {
+ /* call the dialer */
+ iReturn = (*pppd_dialer)(fd, mode, program);
+ }
+
+ return ( -iReturn );
+}
+
+/*
+ * novm - log an error message saying we ran out of memory, and die.
+ */
+void
+novm(
+ char *msg)
+{
+ fatal("Virtual memory exhausted allocating %s\n", msg);
+}
diff --git a/cpukit/pppd/rtemspppd.c b/cpukit/pppd/rtemspppd.c
new file mode 100644
index 0000000000..6f58fce68a
--- /dev/null
+++ b/cpukit/pppd/rtemspppd.c
@@ -0,0 +1,228 @@
+/*
+ * COPYRIGHT (c) 2001, Michael Siers <mikes@poliac.com>.
+ * Poliac Research, Burnsville, Minnesota USA.
+ * COPYRIGHT (c) 2001, On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include "pppd.h"
+#include "rtemspppd.h"
+
+
+/* define pppd function prototypes */
+extern void pppasyncattach(void);
+extern int pppdmain(int, char **);
+
+/* define global variables */
+rtems_id rtems_pppd_taskid;
+rtems_pppd_hookfunction rtems_pppd_errorfp;
+rtems_pppd_hookfunction rtems_pppd_exitfp;
+
+
+static rtems_task pppTask(rtems_task_argument arg)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_option options;
+ rtems_event_set in;
+ rtems_event_set out;
+ int iStatus;
+
+ /* call function to setup ppp line discipline */
+ pppasyncattach();
+
+ /* enter processing loop */
+ in = (RTEMS_EVENT_29 | RTEMS_EVENT_30);
+ options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
+ while ( sc == RTEMS_SUCCESSFUL ) {
+ /* wait for the next event */
+ sc = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
+ if ( sc == RTEMS_SUCCESSFUL ) {
+ /* determine which event was sent */
+ if ( out & RTEMS_EVENT_29 ) {
+ /* terminate event received */
+ /* set value to break out of event loop */
+ sc = RTEMS_UNSATISFIED;
+ }
+ else if ( out & RTEMS_EVENT_30 ) {
+ /* connect request */
+ /* execute the pppd main code */
+ iStatus = pppdmain(0, NULL);
+ if ( iStatus == EXIT_OK ) {
+ /* check exit callback */
+ if ( rtems_pppd_exitfp ) {
+ (*rtems_pppd_exitfp)();
+ }
+ }
+ else {
+ /* check error callback */
+ if ( rtems_pppd_errorfp ) {
+ (*rtems_pppd_errorfp)();
+ }
+ }
+ }
+ }
+ }
+
+ /* terminate myself */
+ rtems_pppd_taskid = 0;
+ rtems_task_delete(RTEMS_SELF);
+}
+
+int rtems_pppd_initialize(void)
+{
+ int iReturn = (int)-1;
+ rtems_task_priority priority = 100;
+ rtems_status_code status;
+ rtems_name taskName;
+
+ /* determine priority value */
+ if ( rtems_bsdnet_config.network_task_priority ) {
+ priority = rtems_bsdnet_config.network_task_priority;
+ }
+
+ /* initialize the exit hook */
+ rtems_pppd_exitfp = (rtems_pppd_hookfunction)0;
+
+ /* create the rtems task */
+ taskName = rtems_build_name( 'p', 'p', 'p', 'd' );
+ status = rtems_task_create(taskName, priority, 8192,
+ (RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0)),
+ RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
+ &rtems_pppd_taskid);
+ if ( status == RTEMS_SUCCESSFUL ) {
+ status = rtems_task_start(rtems_pppd_taskid, pppTask, 0);
+ if ( status == RTEMS_SUCCESSFUL ) {
+ iReturn = rtems_pppd_reset_options();
+ }
+ }
+
+ return ( iReturn );
+}
+
+int rtems_pppd_terminate(void)
+{
+ /* send terminate signal to pppd task */
+ rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_29);
+
+ /* call the disconnect function */
+ rtems_pppd_disconnect();
+
+ return ( 0 );
+}
+
+int rtems_pppd_reset_options(void)
+{
+ int i;
+ struct protent *protp;
+
+ /*
+ * Initialize to the standard option set, then parse, in order,
+ * the system options file, the user's options file,
+ * the tty's options file, and the command line arguments.
+ */
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ (*protp->init)(0);
+
+ return ( 0 );
+}
+
+int rtems_pppd_set_hook(int id, rtems_pppd_hookfunction hookfp)
+{
+ int iReturn = (int)0;
+
+ switch ( id ) {
+ case RTEMS_PPPD_LINKUP_HOOK:
+ auth_linkup_hook = hookfp;
+ break;
+ case RTEMS_PPPD_LINKDOWN_HOOK:
+ auth_linkdown_hook = hookfp;
+ break;
+ case RTEMS_PPPD_IPUP_HOOK:
+ ip_up_hook = hookfp;
+ break;
+ case RTEMS_PPPD_IPDOWN_HOOK:
+ ip_down_hook = hookfp;
+ break;
+ case RTEMS_PPPD_ERROR_HOOK:
+ rtems_pppd_errorfp = hookfp;
+ break;
+ case RTEMS_PPPD_EXIT_HOOK:
+ rtems_pppd_exitfp = hookfp;
+ break;
+ default:
+ iReturn = (int)-1;
+ break;
+ }
+
+ return ( iReturn );
+}
+
+int rtems_pppd_set_dialer(rtems_pppd_dialerfunction dialerfp)
+{
+ pppd_dialer = dialerfp;
+ return ( (int)0 );
+}
+
+int rtems_pppd_set_option(const char *pOption, const char *pValue)
+{
+ int iReturn = (int)0;
+ int prevPhase;
+ struct wordlist option;
+ struct wordlist value;
+
+ if ( pOption != (const char *)0 ) {
+ /* initialize the values */
+ option.word = (char *)pOption;
+ option.next = (struct wordlist *)0;
+ if ( pValue != (const char *)0 ) {
+ option.next = &value;
+ value.word = (char *)pValue;
+ value.next = (struct wordlist *)0;
+ }
+
+ /* save current phase value */
+ prevPhase = pppd_phase;
+ pppd_phase = PHASE_INITIALIZE;
+
+ /* process option and reset phase value */
+ iReturn = options_from_list(&option, 1);
+ pppd_phase = prevPhase;
+ }
+
+ return ( iReturn );
+}
+
+int rtems_pppd_connect(void)
+{
+ /* send connect signal to pppd task */
+ rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_30);
+
+ return ( 0 );
+}
+
+static void timeout_terminate(void *arg)
+{
+ /* set pppd global variables to disconnect */
+ persist = 0;
+ pppd_kill_link = 1;
+}
+
+int rtems_pppd_disconnect(void)
+{
+ /* need to wait a little time before we can bring the link down */
+ /* set up time out in 1 seconds */
+ TIMEOUT(timeout_terminate, NULL, 1);
+
+ /* send event to wake up the pppd code */
+ /* pretend its a serial interrput */
+ rtems_event_send(rtems_pppd_taskid, RTEMS_EVENT_31);
+
+ return ( 0 );
+}
diff --git a/cpukit/pppd/rtemspppd.h b/cpukit/pppd/rtemspppd.h
new file mode 100644
index 0000000000..7905b4bb0e
--- /dev/null
+++ b/cpukit/pppd/rtemspppd.h
@@ -0,0 +1,40 @@
+/*
+ * COPYRIGHT (c) 2001, Michael Siers <mikes@poliac.com>.
+ * Poliac Research, Burnsville, Minnesota USA.
+ * COPYRIGHT (c) 2001, On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef RTEMSPPPD_H
+#define RTEMSPPPD_H
+
+
+/* define hook function identifiers */
+#define RTEMS_PPPD_LINKUP_HOOK 1
+#define RTEMS_PPPD_LINKDOWN_HOOK 2
+#define RTEMS_PPPD_IPUP_HOOK 3
+#define RTEMS_PPPD_IPDOWN_HOOK 4
+#define RTEMS_PPPD_ERROR_HOOK 5
+#define RTEMS_PPPD_EXIT_HOOK 6
+
+/* define hook function pointer prototype */
+typedef void (*rtems_pppd_hookfunction)(void);
+typedef int (*rtems_pppd_dialerfunction)(int tty, int mode, char *pScript);
+
+
+/* define pppd function prototyes */
+int rtems_pppd_initialize(void);
+int rtems_pppd_terminate(void);
+int rtems_pppd_reset_options(void);
+int rtems_pppd_set_hook(int id, rtems_pppd_hookfunction hookfp);
+int rtems_pppd_set_dialer(rtems_pppd_dialerfunction dialerfp);
+int rtems_pppd_set_option(const char *pOption, const char *pValue);
+int rtems_pppd_connect(void);
+int rtems_pppd_disconnect(void);
+
+#endif
diff --git a/cpukit/pppd/sys-rtems.c b/cpukit/pppd/sys-rtems.c
new file mode 100644
index 0000000000..ac87957c1d
--- /dev/null
+++ b/cpukit/pppd/sys-rtems.c
@@ -0,0 +1,1340 @@
+/*
+ * sys-bsd.c - System-dependent procedures for setting up
+ * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.)
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * Copyright (c) 1995 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University and The Australian National University.
+ * The names of the Universities may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#ifdef PPP_FILTER
+#include <net/bpf.h>
+#endif
+
+#include <net/if.h>
+#include <net/ppp_defs.h>
+#include <net/if_ppp.h>
+#include <net/route.h>
+#include <net/if_dl.h>
+#include <netinet/in.h>
+
+#if RTM_VERSION >= 3
+#include <sys/param.h>
+#if defined(NetBSD) && (NetBSD >= 199703)
+#include <netinet/if_inarp.h>
+#else /* NetBSD 1.2D or later */
+#include <netinet/if_ether.h>
+#endif
+#endif
+
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/termiostypes.h>
+extern int rtems_bsdnet_microseconds_per_tick;
+extern rtems_id rtems_pppd_taskid;
+
+#include "pppd.h"
+#include "fsm.h"
+#include "ipcp.h"
+
+static const char rcsid[] = RCSID;
+
+
+static int initdisc = -1; /* Initial TTY discipline for ppp_fd */
+static int initfdflags = -1; /* Initial file descriptor flags for ppp_fd */
+static int ppp_fd = -1; /* fd which is set to PPP discipline */
+static int rtm_seq;
+
+static int restore_term; /* 1 => we've munged the terminal */
+static struct termios inittermios; /* Initial TTY termios */
+static struct winsize wsinfo; /* Initial window size info */
+
+static int loop_slave = -1;
+static int loop_master;
+
+static unsigned char inbuf[512]; /* buffer for chars read from loopback */
+
+static int sockfd; /* socket for doing interface ioctls */
+
+static int if_is_up; /* the interface is currently up */
+static uint32_t ifaddrs[2]; /* local and remote addresses we set */
+static uint32_t default_route_gateway; /* gateway addr for default route */
+static uint32_t proxy_arp_addr; /* remote addr for proxy arp */
+
+/* Prototypes for procedures local to this file. */
+static int dodefaultroute(uint32_t, int);
+static int get_ether_addr(uint32_t, struct sockaddr_dl *);
+
+
+/*
+ * sys_init - System-dependent initialization.
+ */
+void
+sys_init(void)
+{
+ /* Get an internet socket for doing socket ioctl's on. */
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
+}
+
+/*
+ * sys_cleanup - restore any system state we modified before exiting:
+ * mark the interface down, delete default route and/or proxy arp entry.
+ * This should call die() because it's called from die().
+ */
+void
+sys_cleanup(void)
+{
+ struct ifreq ifr;
+
+ if (if_is_up) {
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0
+ && ((ifr.ifr_flags & IFF_UP) != 0)) {
+ ifr.ifr_flags &= ~IFF_UP;
+ ioctl(sockfd, SIOCSIFFLAGS, &ifr);
+ }
+ }
+ if (ifaddrs[0] != 0)
+ cifaddr(0, ifaddrs[0], ifaddrs[1]);
+ if (default_route_gateway)
+ cifdefaultroute(0, 0, default_route_gateway);
+ if (proxy_arp_addr)
+ cifproxyarp(0, proxy_arp_addr);
+}
+
+/*
+ * sys_close - Clean up in a child process before execing.
+ */
+void
+sys_close(void)
+{
+ close(sockfd);
+ if (loop_slave >= 0) {
+ close(loop_slave);
+ close(loop_master);
+ }
+}
+
+/*
+ * sys_check_options - check the options that the user specified
+ */
+int
+sys_check_options(void)
+{
+ return 1;
+}
+
+/*
+ * ppp_available - check whether the system has any ppp interfaces
+ * (in fact we check whether we can do an ioctl on ppp0).
+ */
+int
+ppp_available(void)
+{
+ int s, ok;
+ struct ifreq ifr;
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ return 1; /* can't tell */
+
+ strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
+ ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
+ close(s);
+
+ return ok;
+}
+
+/*
+ * establish_ppp - Turn the serial port into a ppp interface.
+ */
+int
+establish_ppp(
+ int fd)
+{
+ int taskid = (int)rtems_pppd_taskid;
+ int pppdisc = PPPDISC;
+ int x;
+
+ if (demand) {
+ /*
+ * Demand mode - prime the old ppp device to relinquish the unit.
+ */
+ if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
+ fatal("ioctl(transfer ppp unit): %m");
+ }
+
+ /*
+ * Save the old line discipline of fd, and set it to PPP.
+ */
+ if (ioctl(fd, TIOCGETD, &initdisc) < 0)
+ fatal("ioctl(TIOCGETD): %m");
+ if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
+ fatal("ioctl(TIOCSETD): %m");
+
+ /* set pppd taskid into the driver */
+ ioctl(fd, PPPIOCSTASK, &taskid);
+
+ if (!demand) {
+ /*
+ * Find out which interface we were given.
+ */
+ if (ioctl(fd, PPPIOCGUNIT, &pppifunit) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
+ } else {
+ /*
+ * Check that we got the same unit again.
+ */
+ if (ioctl(fd, PPPIOCGUNIT, &x) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
+ if (x != pppifunit)
+ fatal("transfer_ppp failed: wanted unit %d, got %d", pppifunit, x);
+ x = TTYDISC;
+ ioctl(loop_slave, TIOCSETD, &x);
+ }
+
+ ppp_fd = fd;
+
+ /*
+ * Enable debug in the driver if requested.
+ */
+ if (kdebugflag) {
+ if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
+ warn("ioctl (PPPIOCGFLAGS): %m");
+ } else {
+ x |= (kdebugflag & 0xFF) * SC_DEBUG;
+ if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ warn("ioctl(PPPIOCSFLAGS): %m");
+ }
+ }
+
+ /*
+ * Set device for non-blocking reads.
+ */
+ if ((initfdflags = fcntl(fd, F_GETFL)) == -1
+ || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
+ warn("Couldn't set device to non-blocking mode: %m");
+ }
+
+ return fd;
+}
+
+/*
+ * restore_loop - reattach the ppp unit to the loopback.
+ */
+void
+restore_loop(void)
+{
+ int x;
+
+ /*
+ * Transfer the ppp interface back to the loopback.
+ */
+ if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
+ fatal("ioctl(transfer ppp unit): %m");
+ x = PPPDISC;
+ if (ioctl(loop_slave, TIOCSETD, &x) < 0)
+ fatal("ioctl(TIOCSETD): %m");
+
+ /*
+ * Check that we got the same unit again.
+ */
+ if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
+ if (x != pppifunit)
+ fatal("transfer_ppp failed: wanted unit %d, got %d", pppifunit, x);
+ ppp_fd = loop_slave;
+}
+
+
+/*
+ * disestablish_ppp - Restore the serial port to normal operation.
+ * This shouldn't call die() because it's called from die().
+ */
+void
+disestablish_ppp(
+ int fd)
+{
+ int taskid = (int)0;
+
+ /* clear pppd taskid from the driver */
+ ioctl(fd, PPPIOCSTASK, &taskid);
+
+ /* Reset non-blocking mode on fd. */
+ if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
+ warn("Couldn't restore device fd flags: %m");
+ initfdflags = -1;
+
+ /* Restore old line discipline. */
+ if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
+ error("ioctl(TIOCSETD): %m");
+ initdisc = -1;
+
+ if (fd == ppp_fd)
+ ppp_fd = -1;
+}
+
+/*
+ * Check whether the link seems not to be 8-bit clean.
+ */
+void
+clean_check(void)
+{
+ int x;
+ char *s;
+
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) {
+ s = NULL;
+ switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) {
+ case SC_RCV_B7_0:
+ s = "bit 7 set to 1";
+ break;
+ case SC_RCV_B7_1:
+ s = "bit 7 set to 0";
+ break;
+ case SC_RCV_EVNP:
+ s = "odd parity";
+ break;
+ case SC_RCV_ODDP:
+ s = "even parity";
+ break;
+ }
+ if (s != NULL) {
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
+ }
+ }
+}
+
+/*
+ * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
+ * at the requested speed, etc. If `local' is true, set CLOCAL
+ * regardless of whether the modem option was specified.
+ *
+ * For *BSD, we assume that speed_t values numerically equal bits/second.
+ */
+void
+set_up_tty(
+ int fd, int local)
+{
+ struct termios tios;
+
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
+
+ if (!restore_term) {
+ inittermios = tios;
+ ioctl(fd, TIOCGWINSZ, &wsinfo);
+ }
+
+ tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
+ if (crtscts > 0 && !local) {
+ if (crtscts == 2) {
+#ifdef CDTRCTS
+ tios.c_cflag |= CDTRCTS;
+#endif
+ } else
+ tios.c_cflag |= CRTSCTS;
+ } else if (crtscts < 0) {
+ tios.c_cflag &= ~CRTSCTS;
+#ifdef CDTRCTS
+ tios.c_cflag &= ~CDTRCTS;
+#endif
+ }
+
+ tios.c_cflag |= CS8 | CREAD | HUPCL;
+ if (local || !modem)
+ tios.c_cflag |= CLOCAL;
+ tios.c_iflag = IGNBRK | IGNPAR;
+ tios.c_oflag = 0;
+ tios.c_lflag = 0;
+ tios.c_cc[VMIN] = 1;
+ tios.c_cc[VTIME] = 0;
+
+ if (crtscts == -2) {
+ tios.c_iflag |= IXON | IXOFF;
+ tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
+ tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
+ }
+
+ if (inspeed) {
+ cfsetospeed(&tios, inspeed);
+ cfsetispeed(&tios, inspeed);
+ } else {
+ inspeed = cfgetospeed(&tios);
+ /*
+ * We can't proceed if the serial port speed is 0,
+ * since that implies that the serial port is disabled.
+ */
+ if (inspeed == 0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
+ }
+ baud_rate = inspeed;
+
+/* if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) { */
+ if (tcsetattr(fd, TCSADRAIN, &tios) < 0) {
+ fatal("tcsetattr: %m");
+ }
+
+ restore_term = 1;
+}
+
+/*
+ * restore_tty - restore the terminal to the saved settings.
+ */
+void
+restore_tty(
+ int fd)
+{
+ if (restore_term) {
+ if (!default_device) {
+ /*
+ * Turn off echoing, because otherwise we can get into
+ * a loop with the tty and the modem echoing to each other.
+ * We presume we are the sole user of this tty device, so
+ * when we close it, it will revert to its defaults anyway.
+ */
+ inittermios.c_lflag &= ~(ECHO | ECHONL);
+ }
+/* if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0) { */
+ if (tcsetattr(fd, TCSADRAIN, &inittermios) < 0) {
+ if (errno != ENXIO)
+ warn("tcsetattr: %m");
+ }
+ ioctl(fd, TIOCSWINSZ, &wsinfo);
+ restore_term = 0;
+ }
+}
+
+/*
+ * setdtr - control the DTR line on the serial port.
+ * This is called from die(), so it shouldn't call die().
+ */
+void
+setdtr(
+ int fd, int on )
+{
+ int modembits = TIOCM_DTR;
+
+ ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
+}
+
+/*
+ * get_pty - get a pty master/slave pair and chown the slave side
+ * to the uid given. Assumes slave_name points to >= 12 bytes of space.
+ */
+int
+get_pty(
+ int *master_fdp,
+ int *slave_fdp,
+ char *slave_name,
+ int uid)
+{
+ return 1;
+}
+
+
+/*
+ * open_ppp_loopback - open the device we use for getting
+ * packets in demand mode, and connect it to a ppp interface.
+ * Here we use a pty.
+ */
+int
+open_ppp_loopback(void)
+{
+ return loop_master;
+}
+
+
+/*
+ * output - Output PPP packet.
+ */
+void
+output(
+ int unit,
+ u_char *p,
+ int len)
+{
+ if (debug)
+ dbglog("sent %P", p, len);
+/* printf("sent packet [%d]\n", len); */
+
+ if (write(pppd_ttyfd, p, len) < 0) {
+ if (errno != EIO)
+ error("write: %m");
+ }
+}
+
+void
+ppp_delay(void)
+{
+ rtems_interval ticks;
+
+ /* recommended delay to help negotiation */
+ ticks = 300000/rtems_bsdnet_microseconds_per_tick;
+ rtems_task_wake_after(ticks);
+}
+
+/*
+ * wait_input - wait until there is data available,
+ * for the length of time specified by *timo (indefinite
+ * if timo is NULL).
+ */
+void
+wait_input(
+ struct timeval *timo)
+{
+ rtems_event_set events;
+ rtems_interval ticks = 0;
+ rtems_option wait = RTEMS_WAIT;
+
+ if(timo) {
+ if(timo->tv_sec == 0 && timo->tv_usec == 0)
+ wait = RTEMS_NO_WAIT;
+ else {
+ ticks = (timo->tv_sec * 1000000 + timo->tv_usec) /
+ rtems_bsdnet_microseconds_per_tick;
+ if(ticks <= 0)
+ ticks = 1;
+ }
+ }
+ rtems_event_receive(RTEMS_EVENT_31, RTEMS_EVENT_ANY | wait, ticks, &events);
+}
+
+/*
+ * read_packet - get a PPP packet from the serial device.
+ */
+int
+read_packet(
+ u_char *buf)
+{
+ int len;
+
+ if ((len = read(pppd_ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
+ if (errno == EWOULDBLOCK || errno == EINTR) len = -1;
+ /*fatal("read: %m"); */
+ }
+
+/* printf("read packet [%d]\n", len); */
+ return len;
+}
+
+
+/*
+ * get_loop_output - read characters from the loopback, form them
+ * into frames, and detect when we want to bring the real link up.
+ * Return value is 1 if we need to bring up the link, 0 otherwise.
+ */
+int
+get_loop_output(void)
+{
+ int rv = 0;
+ int n;
+
+ while ((n = read(loop_master, inbuf, sizeof(inbuf))) >= 0) {
+ if (loop_chars(inbuf, n))
+ rv = 1;
+ }
+
+ if (n == 0)
+ fatal("eof on loopback");
+ if (errno != EWOULDBLOCK)
+ fatal("read from loopback: %m");
+
+ return rv;
+}
+
+
+/*
+ * ppp_send_config - configure the transmit characteristics of
+ * the ppp interface.
+ */
+void
+ppp_send_config(
+ int unit,
+ int mtu,
+ uint32_t asyncmap,
+ int pcomp,
+ int accomp)
+{
+ u_int x;
+ struct ifreq ifr;
+
+ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+ ifr.ifr_mtu = mtu;
+ if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+ fatal("ioctl(SIOCSIFMTU): %m");
+
+ if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSASYNCMAP): %m");
+
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl (PPPIOCGFLAGS): %m");
+ x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
+ x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
+/* x = sync_serial ? x | SC_SYNC : x & ~SC_SYNC; */
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
+}
+
+
+/*
+ * ppp_set_xaccm - set the extended transmit ACCM for the interface.
+ */
+void
+ppp_set_xaccm(
+ int unit,
+ ext_accm accm)
+{
+ if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
+ warn("ioctl(set extended ACCM): %m");
+}
+
+
+/*
+ * ppp_recv_config - configure the receive-side characteristics of
+ * the ppp interface.
+ */
+void
+ppp_recv_config(
+ int unit,
+ int mru,
+ uint32_t asyncmap,
+ int pcomp, int accomp)
+{
+ int x;
+
+ if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+ fatal("ioctl(PPPIOCSMRU): %m");
+ if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl (PPPIOCGFLAGS): %m");
+ x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
+}
+
+/*
+ * ccp_test - ask kernel whether a given compression method
+ * is acceptable for use. Returns 1 if the method and parameters
+ * are OK, 0 if the method is known but the parameters are not OK
+ * (e.g. code size should be reduced), or -1 if the method is unknown.
+ */
+int
+ccp_test(
+ int unit, u_char *opt_ptr, int opt_len, int for_transmit)
+{
+ struct ppp_option_data data;
+
+ data.ptr = opt_ptr;
+ data.length = opt_len;
+ data.transmit = for_transmit;
+ if (ioctl(pppd_ttyfd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0)
+ return 1;
+ return (errno == ENOBUFS)? 0: -1;
+}
+
+/*
+ * ccp_flags_set - inform kernel about the current state of CCP.
+ */
+void
+ccp_flags_set(
+ int unit, int isopen, int isup)
+{
+ int x;
+
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
+ error("ioctl (PPPIOCGFLAGS): %m");
+ return;
+ }
+ x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
+ x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ error("ioctl(PPPIOCSFLAGS): %m");
+}
+
+/*
+ * ccp_fatal_error - returns 1 if decompression was disabled as a
+ * result of an error detected after decompression of a packet,
+ * 0 otherwise. This is necessary because of patent nonsense.
+ */
+int
+ccp_fatal_error(
+ int unit)
+{
+ int x;
+
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
+ error("ioctl(PPPIOCGFLAGS): %m");
+ return 0;
+ }
+ return x & SC_DC_FERROR;
+}
+
+/*
+ * get_idle_time - return how long the link has been idle.
+ */
+int
+get_idle_time(
+ int u,
+ struct ppp_idle *ip)
+{
+ return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0;
+}
+
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(
+ int u,
+ struct pppd_stats *stats)
+{
+ struct ifpppstatsreq req;
+
+ memset (&req, 0, sizeof (req));
+ strlcpy(req.ifr_name, ifname, sizeof(req.ifr_name));
+ if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) {
+ error("Couldn't get PPP statistics: %m");
+ return 0;
+ }
+ stats->bytes_in = req.stats.p.ppp_ibytes;
+ stats->bytes_out = req.stats.p.ppp_obytes;
+ return 1;
+}
+
+
+#ifdef PPP_FILTER
+/*
+ * set_filters - transfer the pass and active filters to the kernel.
+ */
+int
+set_filters(
+ struct bpf_program *pass, struct bpf_program *active)
+{
+ int ret = 1;
+
+ if (pass->bf_len > 0) {
+ if (ioctl(ppp_fd, PPPIOCSPASS, pass) < 0) {
+ error("Couldn't set pass-filter in kernel: %m");
+ ret = 0;
+ }
+ }
+ if (active->bf_len > 0) {
+ if (ioctl(ppp_fd, PPPIOCSACTIVE, active) < 0) {
+ error("Couldn't set active-filter in kernel: %m");
+ ret = 0;
+ }
+ }
+ return ret;
+}
+#endif
+
+/*
+ * sifvjcomp - config tcp header compression
+ */
+int
+sifvjcomp(
+ int u, int vjcomp, int cidcomp, int maxcid)
+{
+ u_int x;
+
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
+ error("ioctl (PPPIOCGFLAGS): %m");
+ return 0;
+ }
+ x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
+ x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
+ error("ioctl(PPPIOCSFLAGS): %m");
+ return 0;
+ }
+ if (vjcomp && ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
+ error("ioctl(PPPIOCSMAXCID): %m");
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * sifup - Config the interface up and enable IP packets to pass.
+ */
+int
+sifup(
+ int u)
+{
+ struct ifreq ifr;
+
+ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+ if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
+ error("ioctl (SIOCGIFFLAGS): %m");
+ return 0;
+ }
+ ifr.ifr_flags |= IFF_UP;
+ if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
+ error("ioctl(SIOCSIFFLAGS): %m");
+ return 0;
+ }
+ if_is_up = 1;
+ return 1;
+}
+
+/*
+ * sifnpmode - Set the mode for handling packets for a given NP.
+ */
+int
+sifnpmode(
+ int u,
+ int proto,
+ enum NPmode mode)
+{
+ struct npioctl npi;
+
+ npi.protocol = proto;
+ npi.mode = mode;
+ if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * sifdown - Config the interface down and disable IP.
+ */
+int
+sifdown(
+ int u)
+{
+ struct ifreq ifr;
+ int rv;
+ struct npioctl npi;
+
+ rv = 1;
+ npi.protocol = PPP_IP;
+ npi.mode = NPMODE_ERROR;
+ ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi);
+ /* ignore errors, because ppp_fd might have been closed by now. */
+
+ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+ if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
+ error("ioctl (SIOCGIFFLAGS): %m");
+ rv = 0;
+ } else {
+ ifr.ifr_flags &= ~IFF_UP;
+ if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
+ error("ioctl(SIOCSIFFLAGS): %m");
+ rv = 0;
+ } else
+ if_is_up = 0;
+ }
+ return rv;
+}
+
+/*
+ * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
+ * if it exists.
+ */
+#define SET_SA_FAMILY(addr, family) \
+ BZERO((char *) &(addr), sizeof(addr)); \
+ addr.sa_family = (family); \
+ addr.sa_len = sizeof(addr);
+
+/*
+ * sifaddr - Config the interface IP addresses and netmask.
+ */
+int
+sifaddr(
+ int u,
+ uint32_t o, uint32_t h, uint32_t m )
+{
+ struct ifaliasreq ifra;
+ struct ifreq ifr;
+
+ strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
+ SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
+ ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;
+ SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
+ ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;
+ if (m != 0) {
+ SET_SA_FAMILY(ifra.ifra_mask, AF_INET);
+ ((struct sockaddr_in *) &ifra.ifra_mask)->sin_addr.s_addr = m;
+ } else
+ BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
+ BZERO(&ifr, sizeof(ifr));
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
+ if (errno != EADDRNOTAVAIL)
+ warn("Couldn't remove interface address: %m");
+ }
+ if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
+ if (errno != EEXIST) {
+ error("Couldn't set interface address: %m");
+ return 0;
+ }
+ warn("Couldn't set interface address: Address %I already exists", o);
+ }
+ ifaddrs[0] = o;
+ ifaddrs[1] = h;
+ return 1;
+}
+
+/*
+ * cifaddr - Clear the interface IP addresses, and delete routes
+ * through the interface if possible.
+ */
+int
+cifaddr(
+ int u,
+ uint32_t o, uint32_t h )
+{
+ struct ifaliasreq ifra;
+
+ ifaddrs[0] = 0;
+ strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
+ SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
+ ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;
+ SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
+ ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;
+ BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
+ if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
+ if (errno != EADDRNOTAVAIL)
+ warn("Couldn't delete interface address: %m");
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * sifdefaultroute - assign a default route through the address given.
+ */
+int
+sifdefaultroute(
+ int u,
+ uint32_t l, uint32_t g)
+{
+ return dodefaultroute(g, 's');
+}
+
+/*
+ * cifdefaultroute - delete a default route through the address given.
+ */
+int
+cifdefaultroute(
+ int u,
+ uint32_t l, uint32_t g)
+{
+ return dodefaultroute(g, 'c');
+}
+
+/*
+ * dodefaultroute - talk to a routing socket to add/delete a default route.
+ */
+static int
+dodefaultroute(
+ uint32_t g,
+ int cmd)
+{
+/* int status; */
+ struct sockaddr_in address;
+ struct sockaddr_in netmask;
+ struct sockaddr_in gateway;
+
+ memset((void *) &address, 0, sizeof(address));
+ address.sin_len = sizeof address;
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = INADDR_ANY;
+
+ memset((void *) &netmask, 0, sizeof(netmask));
+ netmask.sin_len = sizeof netmask;
+ netmask.sin_addr.s_addr = INADDR_ANY;
+ netmask.sin_family = AF_INET;
+
+ if (cmd=='s') {
+ memset((void *) &gateway, 0, sizeof(gateway));
+ gateway.sin_len = sizeof gateway;
+ gateway.sin_family = AF_INET;
+ gateway.sin_addr.s_addr = g;
+
+ rtems_bsdnet_rtrequest(RTM_ADD,
+ (struct sockaddr *)&address,
+ (struct sockaddr *)&gateway,
+ (struct sockaddr *)&netmask,
+ (RTF_UP|RTF_GATEWAY|RTF_STATIC), NULL);
+ }
+ else {
+ memset((void *) &gateway, 0, sizeof(gateway));
+ gateway.sin_len = sizeof gateway;
+ gateway.sin_family = AF_INET;
+ gateway.sin_addr.s_addr = INADDR_ANY;
+
+ rtems_bsdnet_rtrequest(RTM_DELETE,
+ (struct sockaddr *)&address,
+ (struct sockaddr *)&gateway,
+ (struct sockaddr *)&netmask,
+ (RTF_UP|RTF_STATIC), NULL);
+ }
+
+ default_route_gateway = (cmd == 's')? g: 0;
+
+ return 1;
+}
+
+#if RTM_VERSION >= 3
+
+/*
+ * sifproxyarp - Make a proxy ARP entry for the peer.
+ */
+static struct {
+ struct rt_msghdr hdr;
+ struct sockaddr_inarp dst;
+ struct sockaddr_dl hwa;
+ char extra[128];
+} arpmsg;
+
+static int arpmsg_valid;
+
+int
+sifproxyarp(
+ int unit,
+ uint32_t hisaddr)
+{
+ int routes;
+
+ /*
+ * Get the hardware address of an interface on the same subnet
+ * as our local address.
+ */
+ memset(&arpmsg, 0, sizeof(arpmsg));
+ if (!get_ether_addr(hisaddr, &arpmsg.hwa)) {
+ error("Cannot determine ethernet address for proxy ARP");
+ return 0;
+ }
+
+ if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
+ error("Couldn't add proxy arp entry: socket: %m");
+ return 0;
+ }
+
+ arpmsg.hdr.rtm_type = RTM_ADD;
+ arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC;
+ arpmsg.hdr.rtm_version = RTM_VERSION;
+ arpmsg.hdr.rtm_seq = ++rtm_seq;
+ arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
+ arpmsg.hdr.rtm_inits = RTV_EXPIRE;
+ arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp);
+ arpmsg.dst.sin_family = AF_INET;
+ arpmsg.dst.sin_addr.s_addr = hisaddr;
+ arpmsg.dst.sin_other = SIN_PROXY;
+
+ arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
+ + arpmsg.hwa.sdl_len;
+ if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
+ error("Couldn't add proxy arp entry: %m");
+ close(routes);
+ return 0;
+ }
+
+ close(routes);
+ arpmsg_valid = 1;
+ proxy_arp_addr = hisaddr;
+ return 1;
+}
+
+/*
+ * cifproxyarp - Delete the proxy ARP entry for the peer.
+ */
+int
+cifproxyarp(
+ int unit,
+ uint32_t hisaddr)
+{
+ int routes;
+
+ if (!arpmsg_valid)
+ return 0;
+ arpmsg_valid = 0;
+
+ arpmsg.hdr.rtm_type = RTM_DELETE;
+ arpmsg.hdr.rtm_seq = ++rtm_seq;
+
+ if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
+ error("Couldn't delete proxy arp entry: socket: %m");
+ return 0;
+ }
+
+ if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
+ error("Couldn't delete proxy arp entry: %m");
+ close(routes);
+ return 0;
+ }
+
+ close(routes);
+ proxy_arp_addr = 0;
+ return 1;
+}
+
+#else /* RTM_VERSION */
+
+/*
+ * sifproxyarp - Make a proxy ARP entry for the peer.
+ */
+int
+sifproxyarp(
+ int unit,
+ uint32_t hisaddr)
+{
+ struct arpreq arpreq;
+ struct {
+ struct sockaddr_dl sdl;
+ char space[128];
+ } dls;
+
+ BZERO(&arpreq, sizeof(arpreq));
+
+ /*
+ * Get the hardware address of an interface on the same subnet
+ * as our local address.
+ */
+ if (!get_ether_addr(hisaddr, &dls.sdl)) {
+ error("Cannot determine ethernet address for proxy ARP");
+ return 0;
+ }
+
+ arpreq.arp_ha.sa_len = sizeof(struct sockaddr);
+ arpreq.arp_ha.sa_family = AF_UNSPEC;
+ BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen);
+ SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
+ ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
+ arpreq.arp_flags = ATF_PERM | ATF_PUBL;
+ if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
+ error("Couldn't add proxy arp entry: %m");
+ return 0;
+ }
+
+ proxy_arp_addr = hisaddr;
+ return 1;
+}
+
+/*
+ * cifproxyarp - Delete the proxy ARP entry for the peer.
+ */
+int
+cifproxyarp(
+ int unit,
+ uint32_t hisaddr)
+{
+ struct arpreq arpreq;
+
+ BZERO(&arpreq, sizeof(arpreq));
+ SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
+ ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
+ if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
+ warn("Couldn't delete proxy arp entry: %m");
+ return 0;
+ }
+ proxy_arp_addr = 0;
+ return 1;
+}
+#endif /* RTM_VERSION */
+
+
+/*
+ * get_ether_addr - get the hardware address of an interface on the
+ * the same subnet as ipaddr.
+ */
+#define MAX_IFS 32
+
+static int
+get_ether_addr(
+ uint32_t ipaddr,
+ struct sockaddr_dl *hwaddr)
+{
+ struct ifreq *ifr, *ifend, *ifp;
+ uint32_t ina, mask;
+ struct sockaddr_dl *dla;
+ struct ifreq ifreq;
+ struct ifconf ifc;
+ struct ifreq ifs[MAX_IFS];
+
+ ifc.ifc_len = sizeof(ifs);
+ ifc.ifc_req = ifs;
+ if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
+ error("ioctl(SIOCGIFCONF): %m");
+ return 0;
+ }
+
+ /*
+ * Scan through looking for an interface with an Internet
+ * address on the same subnet as `ipaddr'.
+ */
+ ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+ for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
+ ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len)) {
+ if (ifr->ifr_addr.sa_family == AF_INET) {
+ ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
+ strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+ /*
+ * Check that the interface is up, and not point-to-point
+ * or loopback.
+ */
+ if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
+ continue;
+ if ((ifreq.ifr_flags &
+ (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
+ != (IFF_UP|IFF_BROADCAST))
+ continue;
+ /*
+ * Get its netmask and check that it's on the right subnet.
+ */
+ if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
+ continue;
+ mask = ((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr.s_addr;
+ if ((ipaddr & mask) != (ina & mask))
+ continue;
+
+ break;
+ }
+ }
+
+ if (ifr >= ifend)
+ return 0;
+ info("found interface %s for proxy arp", ifr->ifr_name);
+
+ /*
+ * Now scan through again looking for a link-level address
+ * for this interface.
+ */
+ ifp = ifr;
+ for (ifr = ifc.ifc_req; ifr < ifend; ) {
+ if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
+ && ifr->ifr_addr.sa_family == AF_LINK) {
+ /*
+ * Found the link-level address - copy it out
+ */
+ dla = (struct sockaddr_dl *) &ifr->ifr_addr;
+ BCOPY(dla, hwaddr, dla->sdl_len);
+ return 1;
+ }
+ ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len);
+ }
+
+ return 0;
+}
+
+/*
+ * Return user specified netmask, modified by any mask we might determine
+ * for address `addr' (in network byte order).
+ * Here we scan through the system's list of interfaces, looking for
+ * any non-point-to-point interfaces which might appear to be on the same
+ * network as `addr'. If we find any, we OR in their netmask to the
+ * user-specified netmask.
+ */
+uint32_t
+GetMask(
+ uint32_t addr)
+{
+ uint32_t mask, nmask, ina;
+ struct ifreq *ifr, *ifend, ifreq;
+ struct ifconf ifc;
+ struct ifreq ifs[MAX_IFS];
+
+ addr = ntohl(addr);
+ if (IN_CLASSA(addr)) /* determine network mask for address class */
+ nmask = IN_CLASSA_NET;
+ else if (IN_CLASSB(addr))
+ nmask = IN_CLASSB_NET;
+ else
+ nmask = IN_CLASSC_NET;
+ /* class D nets are disallowed by bad_ip_adrs */
+ mask = netmask | htonl(nmask);
+
+ /*
+ * Scan through the system's network interfaces.
+ */
+ ifc.ifc_len = sizeof(ifs);
+ ifc.ifc_req = ifs;
+ if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
+ warn("ioctl(SIOCGIFCONF): %m");
+ return mask;
+ }
+ ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+ for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
+ ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len)) {
+ /*
+ * Check the interface's internet address.
+ */
+ if (ifr->ifr_addr.sa_family != AF_INET)
+ continue;
+ ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
+ if ((ntohl(ina) & nmask) != (addr & nmask))
+ continue;
+ /*
+ * Check that the interface is up, and not point-to-point or loopback.
+ */
+ strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+ if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
+ continue;
+ if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
+ != IFF_UP)
+ continue;
+ /*
+ * Get its netmask and OR it into our mask.
+ */
+ if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
+ continue;
+ mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
+ }
+
+ return mask;
+}
+
+/*
+ * have_route_to - determine if the system has any route to
+ * a given IP address.
+ * For demand mode to work properly, we have to ignore routes
+ * through our own interface.
+ */
+int have_route_to(uint32_t addr)
+{
+ return -1;
+}
+
+/*
+ * Use the hostid as part of the random number seed.
+ */
+int
+get_host_seed(void)
+{
+ return 17;
+}
diff --git a/cpukit/pppd/upap.c b/cpukit/pppd/upap.c
new file mode 100644
index 0000000000..e8115a68c7
--- /dev/null
+++ b/cpukit/pppd/upap.c
@@ -0,0 +1,631 @@
+/*
+ * upap.c - User/Password Authentication Protocol.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+/*
+ * TODO:
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "pppd.h"
+#include "upap.h"
+
+static const char rcsid[] = RCSID;
+
+static bool hide_password = true;
+
+/*
+ * Command-line options.
+ */
+static option_t pap_option_list[] = {
+ { "hide-password", o_bool, &hide_password,
+ "Don't output passwords to log", 1, NULL, 0, 0 },
+ { "show-password", o_bool, &hide_password,
+ "Show password string in debug log messages", 0, NULL, 0, 0 },
+ { "pap-restart", o_int, &upap[0].us_timeouttime,
+ "Set retransmit timeout for PAP", 0, NULL, 0, 0 },
+ { "pap-max-authreq", o_int, &upap[0].us_maxtransmits,
+ "Set max number of transmissions for auth-reqs", 0, NULL, 0, 0 },
+ { "pap-timeout", o_int, &upap[0].us_reqtimeout,
+ "Set time limit for peer PAP authentication", 0, NULL, 0, 0 },
+ { NULL, 0, NULL, NULL, 0, NULL, 0, 0 }
+};
+
+/*
+ * Protocol entry points.
+ */
+static void upap_init(int);
+static void upap_lowerup(int);
+static void upap_lowerdown(int);
+static void upap_input(int, u_char *, int);
+static void upap_protrej(int);
+static int upap_printpkt(u_char *, int,
+ void (*)(void *, char *, ...), void *);
+
+struct protent pap_protent = {
+ PPP_PAP,
+ upap_init,
+ upap_input,
+ upap_protrej,
+ upap_lowerup,
+ upap_lowerdown,
+ NULL,
+ NULL,
+ upap_printpkt,
+ NULL,
+ 1,
+ "PAP",
+ NULL,
+ pap_option_list,
+ NULL,
+ NULL,
+ NULL
+};
+
+upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */
+
+static void upap_timeout(void *);
+static void upap_reqtimeout(void *);
+static void upap_rauthreq(upap_state *, u_char *, int, int);
+static void upap_rauthack(upap_state *, u_char *, int, int);
+static void upap_rauthnak(upap_state *, u_char *, int, int);
+static void upap_sauthreq(upap_state *);
+static void upap_sresp(upap_state *, u_char, u_char, char *, int);
+
+
+/*
+ * upap_init - Initialize a UPAP unit.
+ */
+static void
+upap_init(int unit)
+{
+ upap_state *u = &upap[unit];
+
+ u->us_unit = unit;
+ u->us_user = NULL;
+ u->us_userlen = 0;
+ u->us_passwd = NULL;
+ u->us_passwdlen = 0;
+ u->us_clientstate = UPAPCS_INITIAL;
+ u->us_serverstate = UPAPSS_INITIAL;
+ u->us_id = 0;
+ u->us_timeouttime = UPAP_DEFTIMEOUT;
+ u->us_maxtransmits = 10;
+ u->us_reqtimeout = UPAP_DEFREQTIME;
+}
+
+
+/*
+ * upap_authwithpeer - Authenticate us with our peer (start client).
+ *
+ * Set new state and send authenticate's.
+ */
+void
+upap_authwithpeer(
+ int unit,
+ char *user,
+ char *password)
+{
+ upap_state *u = &upap[unit];
+
+ /* Save the username and password we're given */
+ u->us_user = user;
+ u->us_userlen = strlen(user);
+ u->us_passwd = password;
+ u->us_passwdlen = strlen(password);
+ u->us_transmits = 0;
+
+ /* Lower layer up yet? */
+ if (u->us_clientstate == UPAPCS_INITIAL ||
+ u->us_clientstate == UPAPCS_PENDING) {
+ u->us_clientstate = UPAPCS_PENDING;
+ return;
+ }
+
+ upap_sauthreq(u); /* Start protocol */
+}
+
+
+/*
+ * upap_authpeer - Authenticate our peer (start server).
+ *
+ * Set new state.
+ */
+void
+upap_authpeer(int unit)
+{
+ upap_state *u = &upap[unit];
+
+ /* Lower layer up yet? */
+ if (u->us_serverstate == UPAPSS_INITIAL ||
+ u->us_serverstate == UPAPSS_PENDING) {
+ u->us_serverstate = UPAPSS_PENDING;
+ return;
+ }
+
+ u->us_serverstate = UPAPSS_LISTEN;
+ if (u->us_reqtimeout > 0)
+ TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
+}
+
+
+/*
+ * upap_timeout - Retransmission timer for sending auth-reqs expired.
+ */
+static void
+upap_timeout(void *arg)
+{
+ upap_state *u = (upap_state *) arg;
+
+ if (u->us_clientstate != UPAPCS_AUTHREQ)
+ return;
+
+ if (u->us_transmits >= u->us_maxtransmits) {
+ /* give up in disgust */
+ error("No response to PAP authenticate-requests");
+ u->us_clientstate = UPAPCS_BADAUTH;
+ auth_withpeer_fail(u->us_unit, PPP_PAP);
+ return;
+ }
+
+ upap_sauthreq(u); /* Send Authenticate-Request */
+}
+
+
+/*
+ * upap_reqtimeout - Give up waiting for the peer to send an auth-req.
+ */
+static void
+upap_reqtimeout(void *arg)
+{
+ upap_state *u = (upap_state *) arg;
+
+ if (u->us_serverstate != UPAPSS_LISTEN)
+ return; /* huh?? */
+
+ auth_peer_fail(u->us_unit, PPP_PAP);
+ u->us_serverstate = UPAPSS_BADAUTH;
+}
+
+
+/*
+ * upap_lowerup - The lower layer is up.
+ *
+ * Start authenticating if pending.
+ */
+static void
+upap_lowerup(int unit)
+{
+ upap_state *u = &upap[unit];
+
+ if (u->us_clientstate == UPAPCS_INITIAL)
+ u->us_clientstate = UPAPCS_CLOSED;
+ else if (u->us_clientstate == UPAPCS_PENDING) {
+ upap_sauthreq(u); /* send an auth-request */
+ }
+
+ if (u->us_serverstate == UPAPSS_INITIAL)
+ u->us_serverstate = UPAPSS_CLOSED;
+ else if (u->us_serverstate == UPAPSS_PENDING) {
+ u->us_serverstate = UPAPSS_LISTEN;
+ if (u->us_reqtimeout > 0)
+ TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
+ }
+}
+
+
+/*
+ * upap_lowerdown - The lower layer is down.
+ *
+ * Cancel all timeouts.
+ */
+static void
+upap_lowerdown(int unit)
+{
+ upap_state *u = &upap[unit];
+
+ if (u->us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */
+ UNTIMEOUT(upap_timeout, u); /* Cancel timeout */
+ if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0)
+ UNTIMEOUT(upap_reqtimeout, u);
+
+ u->us_clientstate = UPAPCS_INITIAL;
+ u->us_serverstate = UPAPSS_INITIAL;
+}
+
+
+/*
+ * upap_protrej - Peer doesn't speak this protocol.
+ *
+ * This shouldn't happen. In any case, pretend lower layer went down.
+ */
+static void
+upap_protrej(int unit)
+{
+ upap_state *u = &upap[unit];
+
+ if (u->us_clientstate == UPAPCS_AUTHREQ) {
+ error("PAP authentication failed due to protocol-reject");
+ auth_withpeer_fail(unit, PPP_PAP);
+ }
+ if (u->us_serverstate == UPAPSS_LISTEN) {
+ error("PAP authentication of peer failed (protocol-reject)");
+ auth_peer_fail(unit, PPP_PAP);
+ }
+ upap_lowerdown(unit);
+}
+
+
+/*
+ * upap_input - Input UPAP packet.
+ */
+static void
+upap_input(
+ int unit,
+ u_char *inpacket,
+ int l)
+{
+ upap_state *u = &upap[unit];
+ u_char *inp;
+ u_char code, id;
+ int len;
+
+ /*
+ * Parse header (code, id and length).
+ * If packet too short, drop it.
+ */
+ inp = inpacket;
+ if (l < UPAP_HEADERLEN) {
+ UPAPDEBUG(("pap_input: rcvd short header."));
+ return;
+ }
+ GETCHAR(code, inp);
+ GETCHAR(id, inp);
+ GETSHORT(len, inp);
+ if (len < UPAP_HEADERLEN) {
+ UPAPDEBUG(("pap_input: rcvd illegal length."));
+ return;
+ }
+ if (len > l) {
+ UPAPDEBUG(("pap_input: rcvd short packet."));
+ return;
+ }
+ len -= UPAP_HEADERLEN;
+
+ /*
+ * Action depends on code.
+ */
+ switch (code) {
+ case UPAP_AUTHREQ:
+ upap_rauthreq(u, inp, id, len);
+ break;
+
+ case UPAP_AUTHACK:
+ upap_rauthack(u, inp, id, len);
+ break;
+
+ case UPAP_AUTHNAK:
+ upap_rauthnak(u, inp, id, len);
+ break;
+
+ default: /* XXX Need code reject */
+ break;
+ }
+}
+
+
+/*
+ * upap_rauth - Receive Authenticate.
+ */
+static void
+upap_rauthreq(
+ upap_state *u,
+ u_char *inp,
+ int id,
+ int len)
+{
+ u_char ruserlen, rpasswdlen;
+ char *ruser, *rpasswd;
+ int retcode;
+ char *msg;
+ int msglen;
+
+ if (u->us_serverstate < UPAPSS_LISTEN)
+ return;
+
+ /*
+ * If we receive a duplicate authenticate-request, we are
+ * supposed to return the same status as for the first request.
+ */
+ if (u->us_serverstate == UPAPSS_OPEN) {
+ upap_sresp(u, UPAP_AUTHACK, id, "", 0); /* return auth-ack */
+ return;
+ }
+ if (u->us_serverstate == UPAPSS_BADAUTH) {
+ upap_sresp(u, UPAP_AUTHNAK, id, "", 0); /* return auth-nak */
+ return;
+ }
+
+ /*
+ * Parse user/passwd.
+ */
+ if (len < 1) {
+ UPAPDEBUG(("pap_rauth: rcvd short packet."));
+ return;
+ }
+ GETCHAR(ruserlen, inp);
+ len -= sizeof (u_char) + ruserlen + sizeof (u_char);
+ if (len < 0) {
+ UPAPDEBUG(("pap_rauth: rcvd short packet."));
+ return;
+ }
+ ruser = (char *) inp;
+ INCPTR(ruserlen, inp);
+ GETCHAR(rpasswdlen, inp);
+ if (len < rpasswdlen) {
+ UPAPDEBUG(("pap_rauth: rcvd short packet."));
+ return;
+ }
+ rpasswd = (char *) inp;
+
+ /*
+ * Check the username and password given.
+ */
+ retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd,
+ rpasswdlen, &msg);
+ BZERO(rpasswd, rpasswdlen);
+ msglen = strlen(msg);
+ if (msglen > 255)
+ msglen = 255;
+
+ upap_sresp(u, retcode, id, msg, msglen);
+
+ if (retcode == UPAP_AUTHACK) {
+ u->us_serverstate = UPAPSS_OPEN;
+ auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen);
+ } else {
+ u->us_serverstate = UPAPSS_BADAUTH;
+ auth_peer_fail(u->us_unit, PPP_PAP);
+ }
+
+ if (u->us_reqtimeout > 0)
+ UNTIMEOUT(upap_reqtimeout, u);
+}
+
+
+/*
+ * upap_rauthack - Receive Authenticate-Ack.
+ */
+static void
+upap_rauthack(
+ upap_state *u,
+ u_char *inp,
+ int id,
+ int len)
+{
+ u_char msglen;
+ char *msg;
+
+ if (u->us_clientstate != UPAPCS_AUTHREQ) /* XXX */
+ return;
+
+ /*
+ * Parse message.
+ */
+ if (len < 1) {
+ UPAPDEBUG(("pap_rauthack: ignoring missing msg-length."));
+ } else {
+ GETCHAR(msglen, inp);
+ if (msglen > 0) {
+ len -= sizeof (u_char);
+ if (len < msglen) {
+ UPAPDEBUG(("pap_rauthack: rcvd short packet."));
+ return;
+ }
+ msg = (char *) inp;
+ PRINTMSG(msg, msglen);
+ }
+ }
+
+ u->us_clientstate = UPAPCS_OPEN;
+
+ auth_withpeer_success(u->us_unit, PPP_PAP);
+}
+
+
+/*
+ * upap_rauthnak - Receive Authenticate-Nakk.
+ */
+static void
+upap_rauthnak(
+ upap_state *u,
+ u_char *inp,
+ int id,
+ int len)
+{
+ u_char msglen;
+ char *msg;
+
+ if (u->us_clientstate != UPAPCS_AUTHREQ) /* XXX */
+ return;
+
+ /*
+ * Parse message.
+ */
+ if (len < 1) {
+ UPAPDEBUG(("pap_rauthnak: ignoring missing msg-length."));
+ } else {
+ GETCHAR(msglen, inp);
+ if (msglen > 0) {
+ len -= sizeof (u_char);
+ if (len < msglen) {
+ UPAPDEBUG(("pap_rauthnak: rcvd short packet."));
+ return;
+ }
+ msg = (char *) inp;
+ PRINTMSG(msg, msglen);
+ }
+ }
+
+ u->us_clientstate = UPAPCS_BADAUTH;
+
+ error("PAP authentication failed");
+ auth_withpeer_fail(u->us_unit, PPP_PAP);
+}
+
+
+/*
+ * upap_sauthreq - Send an Authenticate-Request.
+ */
+static void
+upap_sauthreq(upap_state *u)
+{
+ u_char *outp;
+ int outlen;
+
+ outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) +
+ u->us_userlen + u->us_passwdlen;
+ outp = outpacket_buf;
+
+ MAKEHEADER(outp, PPP_PAP);
+
+ PUTCHAR(UPAP_AUTHREQ, outp);
+ PUTCHAR(++u->us_id, outp);
+ PUTSHORT(outlen, outp);
+ PUTCHAR(u->us_userlen, outp);
+ BCOPY(u->us_user, outp, u->us_userlen);
+ INCPTR(u->us_userlen, outp);
+ PUTCHAR(u->us_passwdlen, outp);
+ BCOPY(u->us_passwd, outp, u->us_passwdlen);
+
+ output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
+
+ TIMEOUT(upap_timeout, u, u->us_timeouttime);
+ ++u->us_transmits;
+ u->us_clientstate = UPAPCS_AUTHREQ;
+}
+
+
+/*
+ * upap_sresp - Send a response (ack or nak).
+ */
+static void
+upap_sresp(
+ upap_state *u,
+ u_char code, u_char id,
+ char *msg,
+ int msglen)
+{
+ u_char *outp;
+ int outlen;
+
+ outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen;
+ outp = outpacket_buf;
+ MAKEHEADER(outp, PPP_PAP);
+
+ PUTCHAR(code, outp);
+ PUTCHAR(id, outp);
+ PUTSHORT(outlen, outp);
+ PUTCHAR(msglen, outp);
+ BCOPY(msg, outp, msglen);
+ output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
+}
+
+/*
+ * upap_printpkt - print the contents of a PAP packet.
+ */
+static char *upap_codenames[] = {
+ "AuthReq", "AuthAck", "AuthNak"
+};
+
+static int
+upap_printpkt(
+ u_char *p,
+ int plen,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ int code, id, len;
+ int mlen, ulen, wlen;
+ char *user, *pwd, *msg;
+ u_char *pstart;
+
+ if (plen < UPAP_HEADERLEN)
+ return 0;
+ pstart = p;
+ GETCHAR(code, p);
+ GETCHAR(id, p);
+ GETSHORT(len, p);
+ if (len < UPAP_HEADERLEN || len > plen)
+ return 0;
+
+ if (code >= 1 && code <= sizeof(upap_codenames) / sizeof(char *))
+ printer(arg, " %s", upap_codenames[code-1]);
+ else
+ printer(arg, " code=0x%x", code);
+ printer(arg, " id=0x%x", id);
+ len -= UPAP_HEADERLEN;
+ switch (code) {
+ case UPAP_AUTHREQ:
+ if (len < 1)
+ break;
+ ulen = p[0];
+ if (len < ulen + 2)
+ break;
+ wlen = p[ulen + 1];
+ if (len < ulen + wlen + 2)
+ break;
+ user = (char *) (p + 1);
+ pwd = (char *) (p + ulen + 2);
+ p += ulen + wlen + 2;
+ len -= ulen + wlen + 2;
+ printer(arg, " user=");
+ print_string(user, ulen, printer, arg);
+ printer(arg, " password=");
+ if (!hide_password)
+ print_string(pwd, wlen, printer, arg);
+ else
+ printer(arg, "<hidden>");
+ break;
+ case UPAP_AUTHACK:
+ case UPAP_AUTHNAK:
+ if (len < 1)
+ break;
+ mlen = p[0];
+ if (len < mlen + 1)
+ break;
+ msg = (char *) (p + 1);
+ p += mlen + 1;
+ len -= mlen + 1;
+ printer(arg, " ");
+ print_string(msg, mlen, printer, arg);
+ break;
+ }
+
+ /* print the rest of the bytes in the packet */
+ for (; len > 0; --len) {
+ GETCHAR(code, p);
+ printer(arg, " %.2x", code);
+ }
+
+ return p - pstart;
+}
diff --git a/cpukit/pppd/upap.h b/cpukit/pppd/upap.h
new file mode 100644
index 0000000000..6ba0900f1a
--- /dev/null
+++ b/cpukit/pppd/upap.h
@@ -0,0 +1,87 @@
+/*
+ * upap.h - User/Password Authentication Protocol definitions.
+ *
+ * Copyright (c) 1989 Carnegie Mellon University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by Carnegie Mellon University. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+/*
+ * Packet header = Code, id, length.
+ */
+#define UPAP_HEADERLEN 4
+
+
+/*
+ * UPAP codes.
+ */
+#define UPAP_AUTHREQ 1 /* Authenticate-Request */
+#define UPAP_AUTHACK 2 /* Authenticate-Ack */
+#define UPAP_AUTHNAK 3 /* Authenticate-Nak */
+
+
+/*
+ * Each interface is described by upap structure.
+ */
+typedef struct upap_state {
+ int us_unit; /* Interface unit number */
+ char *us_user; /* User */
+ int us_userlen; /* User length */
+ char *us_passwd; /* Password */
+ int us_passwdlen; /* Password length */
+ int us_clientstate; /* Client state */
+ int us_serverstate; /* Server state */
+ u_char us_id; /* Current id */
+ int us_timeouttime; /* Timeout (seconds) for auth-req retrans. */
+ int us_transmits; /* Number of auth-reqs sent */
+ int us_maxtransmits; /* Maximum number of auth-reqs to send */
+ int us_reqtimeout; /* Time to wait for auth-req from peer */
+} upap_state;
+
+
+/*
+ * Client states.
+ */
+#define UPAPCS_INITIAL 0 /* Connection down */
+#define UPAPCS_CLOSED 1 /* Connection up, haven't requested auth */
+#define UPAPCS_PENDING 2 /* Connection down, have requested auth */
+#define UPAPCS_AUTHREQ 3 /* We've sent an Authenticate-Request */
+#define UPAPCS_OPEN 4 /* We've received an Ack */
+#define UPAPCS_BADAUTH 5 /* We've received a Nak */
+
+/*
+ * Server states.
+ */
+#define UPAPSS_INITIAL 0 /* Connection down */
+#define UPAPSS_CLOSED 1 /* Connection up, haven't requested auth */
+#define UPAPSS_PENDING 2 /* Connection down, have requested auth */
+#define UPAPSS_LISTEN 3 /* Listening for an Authenticate */
+#define UPAPSS_OPEN 4 /* We've sent an Ack */
+#define UPAPSS_BADAUTH 5 /* We've sent a Nak */
+
+
+/*
+ * Timeouts.
+ */
+#define UPAP_DEFTIMEOUT 5 /* Timeout (seconds) for retransmitting req */
+#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */
+
+extern upap_state upap[];
+
+void upap_authwithpeer(int, char *, char *);
+void upap_authpeer(int);
+
+extern struct protent pap_protent;
diff --git a/cpukit/pppd/utils.c b/cpukit/pppd/utils.c
new file mode 100644
index 0000000000..af39226e24
--- /dev/null
+++ b/cpukit/pppd/utils.c
@@ -0,0 +1,827 @@
+/*
+ * utils.c - various utility functions used in pppd.
+ *
+ * Copyright (c) 1999 The Australian National University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the Australian National University. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define RCSID "$Id$"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <syslog.h>
+#include <pwd.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#ifdef SVR4
+#include <sys/mkdev.h>
+#endif
+
+#include "pppd.h"
+
+static const char rcsid[] = RCSID;
+
+static void pr_log(void *, char *, ...);
+static void logit(int, char *, va_list);
+static void vslp_printer(void *, char *, ...);
+static void format_packet(u_char *, int, void (*) (void *, char *, ...),
+ void *);
+
+struct buffer_info {
+ char *ptr;
+ int len;
+};
+
+/*
+ * slprintf - format a message into a buffer. Like sprintf except we
+ * also specify the length of the output buffer, and we handle
+ * %r (recursive format), %m (error message), %v (visible string),
+ * %q (quoted string), %t (current time) and %I (IP address) formats.
+ * Doesn't do floating-point formats.
+ * Returns the number of chars put into buf.
+ */
+int
+slprintf __V((char *buf, int buflen, char *fmt, ...))
+{
+ va_list args;
+ int n;
+
+#if defined(__STDC__)
+ va_start(args, fmt);
+#else
+ char *buf;
+ int buflen;
+ char *fmt;
+ va_start(args);
+ buf = va_arg(args, char *);
+ buflen = va_arg(args, int);
+ fmt = va_arg(args, char *);
+#endif
+ n = vslprintf(buf, buflen, fmt, args);
+ va_end(args);
+ return n;
+}
+
+/*
+ * vslprintf - like slprintf, takes a va_list instead of a list of args.
+ */
+#define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
+
+int
+vslprintf(
+ char *buf,
+ int buflen,
+ char *fmt,
+ va_list args)
+{
+ int c, i, n;
+ int width, prec, fillch;
+ int base, len, neg, quoted;
+ uintptr_t val = 0;
+ char *str, *f, *buf0;
+ unsigned char *p;
+ char num[32];
+ time_t t;
+ uint32_t ip;
+ static char hexchars[] = "0123456789abcdef";
+ struct buffer_info bufinfo;
+
+ buf0 = buf;
+ --buflen;
+ while (buflen > 0) {
+ for (f = fmt; *f != '%' && *f != 0; ++f)
+ ;
+ if (f > fmt) {
+ len = f - fmt;
+ if (len > buflen)
+ len = buflen;
+ memcpy(buf, fmt, len);
+ buf += len;
+ buflen -= len;
+ fmt = f;
+ }
+ if (*fmt == 0)
+ break;
+ c = *++fmt;
+ width = 0;
+ prec = -1;
+ fillch = ' ';
+ if (c == '0') {
+ fillch = '0';
+ c = *++fmt;
+ }
+ if (c == '*') {
+ width = va_arg(args, int);
+ c = *++fmt;
+ } else {
+ while (isdigit(c)) {
+ width = width * 10 + c - '0';
+ c = *++fmt;
+ }
+ }
+ if (c == '.') {
+ c = *++fmt;
+ if (c == '*') {
+ prec = va_arg(args, int);
+ c = *++fmt;
+ } else {
+ prec = 0;
+ while (isdigit(c)) {
+ prec = prec * 10 + c - '0';
+ c = *++fmt;
+ }
+ }
+ }
+ str = 0;
+ base = 0;
+ neg = 0;
+ ++fmt;
+ switch (c) {
+ case 'd':
+ i = va_arg(args, int);
+ if (i < 0) {
+ neg = 1;
+ val = -i;
+ } else
+ val = i;
+ base = 10;
+ break;
+ case 'o':
+ val = va_arg(args, unsigned int);
+ base = 8;
+ break;
+ case 'x':
+ case 'X':
+ val = va_arg(args, unsigned int);
+ base = 16;
+ break;
+ case 'p':
+ val = (uintptr_t) va_arg(args, void *);
+ base = 16;
+ neg = 2;
+ break;
+ case 's':
+ str = va_arg(args, char *);
+ break;
+ case 'c':
+ num[0] = va_arg(args, int);
+ num[1] = 0;
+ str = num;
+ break;
+ case 'm':
+ str = strerror(errno);
+ break;
+ case 'I':
+ ip = va_arg(args, uint32_t);
+ ip = ntohl(ip);
+ slprintf(num, sizeof(num), "%d.%d.%d.%d", (ip >> 24) & 0xff,
+ (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
+ str = num;
+ break;
+ case 'r':
+ f = va_arg(args, char *);
+#if !defined(__PPC__)
+ n = vslprintf(buf, buflen + 1, f, va_arg(args, va_list));
+#else
+ /* HACK: On the powerpc, a va_list is an array of 1 structure */
+ n = vslprintf(buf, buflen + 1, f, va_arg(args, void *));
+#endif
+ buf += n;
+ buflen -= n;
+ continue;
+ case 't':
+ time(&t);
+ str = ctime(&t);
+ str += 4; /* chop off the day name */
+ str[15] = 0; /* chop off year and newline */
+ break;
+ case 'v': /* "visible" string */
+ case 'q': /* quoted string */
+ quoted = c == 'q';
+ p = va_arg(args, unsigned char *);
+ if (fillch == '0' && prec >= 0) {
+ n = prec;
+ } else {
+ n = strlen((char *)p);
+ if (prec >= 0 && n > prec)
+ n = prec;
+ }
+ while (n > 0 && buflen > 0) {
+ c = *p++;
+ --n;
+ if (!quoted && c >= 0x80) {
+ OUTCHAR('M');
+ OUTCHAR('-');
+ c -= 0x80;
+ }
+ if (quoted && (c == '"' || c == '\\'))
+ OUTCHAR('\\');
+ if (c < 0x20 || (0x7f <= c && c < 0xa0)) {
+ if (quoted) {
+ OUTCHAR('\\');
+ switch (c) {
+ case '\t': OUTCHAR('t'); break;
+ case '\n': OUTCHAR('n'); break;
+ case '\b': OUTCHAR('b'); break;
+ case '\f': OUTCHAR('f'); break;
+ default:
+ OUTCHAR('x');
+ OUTCHAR(hexchars[c >> 4]);
+ OUTCHAR(hexchars[c & 0xf]);
+ }
+ } else {
+ if (c == '\t')
+ OUTCHAR(c);
+ else {
+ OUTCHAR('^');
+ OUTCHAR(c ^ 0x40);
+ }
+ }
+ } else
+ OUTCHAR(c);
+ }
+ continue;
+ case 'P': /* print PPP packet */
+ bufinfo.ptr = buf;
+ bufinfo.len = buflen + 1;
+ p = va_arg(args, unsigned char *);
+ n = va_arg(args, int);
+ format_packet(p, n, vslp_printer, &bufinfo);
+ buf = bufinfo.ptr;
+ buflen = bufinfo.len - 1;
+ continue;
+ case 'B':
+ p = va_arg(args, unsigned char *);
+ for (n = prec; n > 0; --n) {
+ c = *p++;
+ if (fillch == ' ')
+ OUTCHAR(' ');
+ OUTCHAR(hexchars[(c >> 4) & 0xf]);
+ OUTCHAR(hexchars[c & 0xf]);
+ }
+ continue;
+ default:
+ *buf++ = '%';
+ if (c != '%')
+ --fmt; /* so %z outputs %z etc. */
+ --buflen;
+ continue;
+ }
+ if (base != 0) {
+ str = num + sizeof(num);
+ *--str = 0;
+ while (str > num + neg) {
+ *--str = hexchars[val % base];
+ val = val / base;
+ if (--prec <= 0 && val == 0)
+ break;
+ }
+ switch (neg) {
+ case 1:
+ *--str = '-';
+ break;
+ case 2:
+ *--str = 'x';
+ *--str = '0';
+ break;
+ }
+ len = num + sizeof(num) - 1 - str;
+ } else {
+ len = strlen(str);
+ if (prec >= 0 && len > prec)
+ len = prec;
+ }
+ if (width > 0) {
+ if (width > buflen)
+ width = buflen;
+ if ((n = width - len) > 0) {
+ buflen -= n;
+ for (; n > 0; --n)
+ *buf++ = fillch;
+ }
+ }
+ if (len > buflen)
+ len = buflen;
+ memcpy(buf, str, len);
+ buf += len;
+ buflen -= len;
+ }
+ *buf = 0;
+ return buf - buf0;
+}
+
+/*
+ * vslp_printer - used in processing a %P format
+ */
+static void
+vslp_printer __V((void *arg, char *fmt, ...))
+{
+ int n;
+ va_list pvar;
+ struct buffer_info *bi;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ void *arg;
+ char *fmt;
+ va_start(pvar);
+ arg = va_arg(pvar, void *);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ bi = (struct buffer_info *) arg;
+ n = vslprintf(bi->ptr, bi->len, fmt, pvar);
+ va_end(pvar);
+
+ bi->ptr += n;
+ bi->len -= n;
+}
+
+/*
+ * log_packet - format a packet and log it.
+ */
+
+char line[256]; /* line to be logged accumulated here */
+char *linep;
+
+void
+log_packet(
+ u_char *p,
+ int len,
+ char *prefix,
+ int level)
+{
+ strlcpy(line, prefix, sizeof(line));
+ linep = line + strlen(line);
+ format_packet(p, len, pr_log, NULL);
+}
+
+/*
+ * format_packet - make a readable representation of a packet,
+ * calling `printer(arg, format, ...)' to output it.
+ */
+static void
+format_packet(
+ u_char *p,
+ int len,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ int i, n;
+ u_short proto;
+ struct protent *protp;
+
+ if (len >= PPP_HDRLEN && p[0] == PPP_ALLSTATIONS && p[1] == PPP_UI) {
+ p += 2;
+ GETSHORT(proto, p);
+ len -= PPP_HDRLEN;
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (proto == protp->protocol)
+ break;
+ if (protp != NULL) {
+ printer(arg, "[%s", protp->name);
+ n = (*protp->printpkt)(p, len, printer, arg);
+ printer(arg, "]");
+ p += n;
+ len -= n;
+ } else {
+ for (i = 0; (protp = protocols[i]) != NULL; ++i)
+ if (proto == (protp->protocol & ~0x8000))
+ break;
+ if (protp != 0 && protp->data_name != 0) {
+ printer(arg, "[%s data]", protp->data_name);
+ if (len > 8)
+ printer(arg, "%.8B ...", p);
+ else
+ printer(arg, "%.*B", len, p);
+ len = 0;
+ } else
+ printer(arg, "[proto=0x%x]", proto);
+ }
+ }
+
+ if (len > 32)
+ printer(arg, "%.32B ...", p);
+ else
+ printer(arg, "%.*B", len, p);
+}
+
+static void
+pr_log __V((void *arg, char *fmt, ...))
+{
+ int n;
+ va_list pvar;
+ char buf[256];
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ void *arg;
+ char *fmt;
+ va_start(pvar);
+ arg = va_arg(pvar, void *);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ n = vslprintf(buf, sizeof(buf), fmt, pvar);
+ va_end(pvar);
+
+ if (linep + n + 1 > line + sizeof(line)) {
+ linep = line;
+ }
+ strlcpy(linep, buf, line + sizeof(line) - linep);
+ linep += n;
+}
+
+/*
+ * print_string - print a readable representation of a string using
+ * printer.
+ */
+void
+print_string(
+ void *p_arg,
+ int len,
+ void (*printer)(void *, char *, ...),
+ void *arg)
+{
+ int c;
+ unsigned char *p = (unsigned char *)p_arg;
+
+ printer(arg, "\"");
+ for (; len > 0; --len) {
+ c = *p++;
+ if (' ' <= c && c <= '~') {
+ if (c == '\\' || c == '"')
+ printer(arg, "\\");
+ printer(arg, "%c", c);
+ } else {
+ switch (c) {
+ case '\n':
+ printer(arg, "\\n");
+ break;
+ case '\r':
+ printer(arg, "\\r");
+ break;
+ case '\t':
+ printer(arg, "\\t");
+ break;
+ default:
+ printer(arg, "\\%.3o", c);
+ }
+ }
+ }
+ printer(arg, "\"");
+}
+
+/*
+ * logit - does the hard work for fatal et al.
+ */
+static void
+logit(
+ int level,
+ char *fmt,
+ va_list args)
+{
+ int n;
+ char buf[256];
+
+ n = vslprintf(buf, sizeof(buf), fmt, args);
+/* if (log_to_fd >= 0 && (level != LOG_DEBUG || debug)) { */
+ if (log_to_fd >= 0 && (debug)) {
+ if (buf[n-1] != '\n')
+ buf[n++] = '\n';
+ if (write(log_to_fd, buf, n) != n)
+ log_to_fd = -1;
+ }
+}
+
+/*
+ * fatal - log an error message and die horribly.
+ */
+void
+pppd_fatal __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ logit(LOG_ERR, fmt, pvar);
+ va_end(pvar);
+
+ die(1); /* as promised */
+}
+
+/*
+ * error - log an error message.
+ */
+void
+pppd_error __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ logit(LOG_ERR, fmt, pvar);
+ va_end(pvar);
+}
+
+/*
+ * warn - log a warning message.
+ */
+void
+pppd_warn __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ logit(LOG_WARNING, fmt, pvar);
+ va_end(pvar);
+}
+
+/*
+ * notice - log a notice-level message.
+ */
+void
+pppd_notice __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ logit(LOG_NOTICE, fmt, pvar);
+ va_end(pvar);
+}
+
+/*
+ * info - log an informational message.
+ */
+void
+pppd_info __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ logit(LOG_INFO, fmt, pvar);
+ va_end(pvar);
+}
+
+/*
+ * dbglog - log a debug message.
+ */
+void
+pppd_dbglog __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if defined(__STDC__)
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ logit(LOG_DEBUG, fmt, pvar);
+ va_end(pvar);
+}
+
+/* Procedures for locking the serial device using a lock file. */
+#ifndef LOCK_DIR
+#ifdef _linux_
+#define LOCK_DIR "/var/lock"
+#else
+#ifdef SVR4
+#define LOCK_DIR "/var/spool/locks"
+#else
+#define LOCK_DIR "/var/spool/lock"
+#endif
+#endif
+#endif /* LOCK_DIR */
+
+static char lock_file[MAXPATHLEN];
+
+/*
+ * lock - create a lock file for the named device
+ */
+int
+lock(char *dev)
+{
+#ifdef LOCKLIB
+ int result;
+
+ result = mklock (dev, (void *) 0);
+ if (result == 0) {
+ strlcpy(lock_file, sizeof(lock_file), dev);
+ return 0;
+ }
+
+ if (result > 0)
+ notice("Device %s is locked by pid %d", dev, result);
+ else
+ error("Can't create lock file %s", lock_file);
+ return -1;
+
+#else /* LOCKLIB */
+
+ char lock_buffer[12];
+ int fd, pid, n;
+
+#ifdef SVR4
+ struct stat sbuf;
+
+ if (stat(dev, &sbuf) < 0) {
+ error("Can't get device number for %s: %m", dev);
+ return -1;
+ }
+ if ((sbuf.st_mode & S_IFMT) != S_IFCHR) {
+ error("Can't lock %s: not a character device", dev);
+ return -1;
+ }
+ slprintf(lock_file, sizeof(lock_file), "%s/LK.%03d.%03d.%03d",
+ LOCK_DIR, major(sbuf.st_dev),
+ major(sbuf.st_rdev), minor(sbuf.st_rdev));
+#else
+ char *p;
+
+ if ((p = strrchr(dev, '/')) != NULL)
+ dev = p + 1;
+ slprintf(lock_file, sizeof(lock_file), "%s/LCK..%s", LOCK_DIR, dev);
+#endif
+
+ while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
+ if (errno != EEXIST) {
+ error("Can't create lock file %s: %m", lock_file);
+ break;
+ }
+
+ /* Read the lock file to find out who has the device locked. */
+ fd = open(lock_file, O_RDONLY, 0);
+ if (fd < 0) {
+ if (errno == ENOENT) /* This is just a timing problem. */
+ continue;
+ error("Can't open existing lock file %s: %m", lock_file);
+ break;
+ }
+#ifndef LOCK_BINARY
+ n = read(fd, lock_buffer, 11);
+#else
+ n = read(fd, &pid, sizeof(pid));
+#endif /* LOCK_BINARY */
+ close(fd);
+ fd = -1;
+ if (n <= 0) {
+ error("Can't read pid from lock file %s", lock_file);
+ break;
+ }
+
+ /* See if the process still exists. */
+#ifndef LOCK_BINARY
+ lock_buffer[n] = 0;
+ pid = atoi(lock_buffer);
+#endif /* LOCK_BINARY */
+ if (pid == getpid())
+ return 1; /* somebody else locked it for us */
+ if (pid == 0
+ || (kill(pid, 0) == -1 && errno == ESRCH)) {
+ if (unlink (lock_file) == 0) {
+ notice("Removed stale lock on %s (pid %d)", dev, pid);
+ continue;
+ }
+ warn("Couldn't remove stale lock on %s", dev);
+ } else
+ notice("Device %s is locked by pid %d", dev, pid);
+ break;
+ }
+
+ if (fd < 0) {
+ lock_file[0] = 0;
+ return -1;
+ }
+
+ pid = getpid();
+#ifndef LOCK_BINARY
+ slprintf(lock_buffer, sizeof(lock_buffer), "%10d\n", pid);
+ write (fd, lock_buffer, 11);
+#else
+ write(fd, &pid, sizeof (pid));
+#endif
+ close(fd);
+ return 0;
+
+#endif
+}
+
+/*
+ * relock - called to update our lockfile when we are about to detach,
+ * thus changing our pid (we fork, the child carries on, and the parent dies).
+ * Note that this is called by the parent, with pid equal to the pid
+ * of the child. This avoids a potential race which would exist if
+ * we had the child rewrite the lockfile (the parent might die first,
+ * and another process could think the lock was stale if it checked
+ * between when the parent died and the child rewrote the lockfile).
+ */
+int
+relock(int pid)
+{
+#ifdef LOCKLIB
+ /* XXX is there a way to do this? */
+ return -1;
+#else /* LOCKLIB */
+
+ int fd;
+ char lock_buffer[12];
+
+ if (lock_file[0] == 0)
+ return -1;
+ fd = open(lock_file, O_WRONLY, 0);
+ if (fd < 0) {
+ error("Couldn't reopen lock file %s: %m", lock_file);
+ lock_file[0] = 0;
+ return -1;
+ }
+
+#ifndef LOCK_BINARY
+ slprintf(lock_buffer, sizeof(lock_buffer), "%10d\n", pid);
+ write (fd, lock_buffer, 11);
+#else
+ write(fd, &pid, sizeof(pid));
+#endif /* LOCK_BINARY */
+ close(fd);
+ return 0;
+
+#endif /* LOCKLIB */
+}
+
+/*
+ * unlock - remove our lockfile
+ */
+void
+unlock(void)
+{
+ if (lock_file[0]) {
+#ifdef LOCKLIB
+ (void) rmlock(lock_file, (void *) 0);
+#else
+ unlink(lock_file);
+#endif
+ lock_file[0] = 0;
+ }
+}
diff --git a/cpukit/preinstall.am b/cpukit/preinstall.am
new file mode 100644
index 0000000000..d4b72090c8
--- /dev/null
+++ b/cpukit/preinstall.am
@@ -0,0 +1,394 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/bsd/sys/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/bsd/sys
+ @: > $(PROJECT_INCLUDE)/rtems/bsd/sys/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/bsd/sys/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/bsd/sys/queue.h: include/rtems/bsd/sys/queue.h $(PROJECT_INCLUDE)/rtems/bsd/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bsd/sys/queue.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bsd/sys/queue.h
+
+$(PROJECT_INCLUDE)/rtems/bsd/sys/cdefs.h: include/rtems/bsd/sys/cdefs.h $(PROJECT_INCLUDE)/rtems/bsd/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bsd/sys/cdefs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bsd/sys/cdefs.h
+
+$(PROJECT_INCLUDE)/uuid/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/uuid
+ @: > $(PROJECT_INCLUDE)/uuid/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/uuid/$(dirstamp)
+
+$(PROJECT_INCLUDE)/uuid/uuid.h: libmisc/uuid/uuid.h $(PROJECT_INCLUDE)/uuid/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/uuid/uuid.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/uuid/uuid.h
+
+if NEWLIB
+$(PROJECT_INCLUDE)/sys/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/sys
+ @: > $(PROJECT_INCLUDE)/sys/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/sys/$(dirstamp)
+
+$(PROJECT_INCLUDE)/memory.h: libnetworking/memory.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/memory.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/memory.h
+
+$(PROJECT_INCLUDE)/md4.h: libmd/md4.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/md4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/md4.h
+
+$(PROJECT_INCLUDE)/md5.h: libmd/md5.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/md5.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/md5.h
+
+$(PROJECT_INCLUDE)/sys/ioccom.h: libcsupport/include/sys/ioccom.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/ioccom.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/ioccom.h
+
+$(PROJECT_INCLUDE)/sys/filio.h: libcsupport/include/sys/filio.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/filio.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/filio.h
+
+$(PROJECT_INCLUDE)/sys/ioctl.h: libcsupport/include/sys/ioctl.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/ioctl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/ioctl.h
+
+$(PROJECT_INCLUDE)/sys/statvfs.h: libcsupport/include/sys/statvfs.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/statvfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/statvfs.h
+
+$(PROJECT_INCLUDE)/sys/sockio.h: libcsupport/include/sys/sockio.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/sockio.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/sockio.h
+
+$(PROJECT_INCLUDE)/sys/ttycom.h: libcsupport/include/sys/ttycom.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/ttycom.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/ttycom.h
+
+$(PROJECT_INCLUDE)/sys/termios.h: libcsupport/include/sys/termios.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/termios.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/termios.h
+
+$(PROJECT_INCLUDE)/sys/utsname.h: libcsupport/include/sys/utsname.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/utsname.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/utsname.h
+
+$(PROJECT_INCLUDE)/sys/uio.h: libnetworking/sys/uio.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/uio.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/uio.h
+
+$(PROJECT_INCLUDE)/sys/priority.h: include/sys/priority.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/priority.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/priority.h
+
+if LIBNETWORKING
+$(PROJECT_INCLUDE)/rtems/bsdnet/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/bsdnet
+ @: > $(PROJECT_INCLUDE)/rtems/bsdnet/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/bsdnet/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/bsdnet/servers.h: libnetworking/rtems/bsdnet/servers.h $(PROJECT_INCLUDE)/rtems/bsdnet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bsdnet/servers.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bsdnet/servers.h
+
+$(PROJECT_INCLUDE)/rtems/bsdnet/_types.h: libnetworking/rtems/bsdnet/_types.h $(PROJECT_INCLUDE)/rtems/bsdnet/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bsdnet/_types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bsdnet/_types.h
+endif
+endif
+$(PROJECT_INCLUDE)/rtems/bspIo.h: include/rtems/bspIo.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bspIo.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bspIo.h
+
+$(PROJECT_INCLUDE)/rtems/userenv.h: include/rtems/userenv.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/userenv.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/userenv.h
+
+$(PROJECT_INCLUDE)/rtems/fs.h: include/rtems/fs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/fs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/fs.h
+
+$(PROJECT_INCLUDE)/rtems/pci.h: include/rtems/pci.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/pci.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/pci.h
+
+$(PROJECT_INCLUDE)/rtems/concat.h: include/rtems/concat.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/concat.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/concat.h
+
+$(PROJECT_INCLUDE)/rtems/status-checks.h: include/rtems/status-checks.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/status-checks.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/status-checks.h
+
+$(PROJECT_INCLUDE)/rtems/btimer.h: include/rtems/btimer.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/btimer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/btimer.h
+
+$(PROJECT_INCLUDE)/rtems/endian.h: include/rtems/endian.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/endian.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/endian.h
+
+$(PROJECT_INCLUDE)/rtems/irq.h: include/rtems/irq.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/irq.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/irq.h
+
+$(PROJECT_INCLUDE)/rtems/irq-extension.h: include/rtems/irq-extension.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/irq-extension.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/irq-extension.h
+
+$(PROJECT_INCLUDE)/rtems/imfs.h: libfs/src/imfs/imfs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/imfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/imfs.h
+
+$(PROJECT_INCLUDE)/rtems/pipe.h: libfs/src/pipe/pipe.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/pipe.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/pipe.h
+
+$(PROJECT_INCLUDE)/rtems/devfs.h: libfs/src/devfs/devfs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/devfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/devfs.h
+
+if LIBDOSFS
+$(PROJECT_INCLUDE)/rtems/dosfs.h: libfs/src/dosfs/dosfs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/dosfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/dosfs.h
+endif
+$(PROJECT_INCLUDE)/rtems/rtems-rfs.h: libfs/src/rfs/rtems-rfs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems-rfs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems-rfs.h
+
+$(PROJECT_INCLUDE)/rtems/rtems-rfs-format.h: libfs/src/rfs/rtems-rfs-format.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems-rfs-format.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems-rfs-format.h
+
+$(PROJECT_INCLUDE)/rtems/rtems-rfs-shell.h: libfs/src/rfs/rtems-rfs-shell.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems-rfs-shell.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems-rfs-shell.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/rfs
+ @: > $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-bitmaps.h: libfs/src/rfs/rtems-rfs-bitmaps.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-bitmaps.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-bitmaps.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-block-pos.h: libfs/src/rfs/rtems-rfs-block-pos.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-block-pos.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-block-pos.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-block.h: libfs/src/rfs/rtems-rfs-block.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-block.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-block.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-buffer.h: libfs/src/rfs/rtems-rfs-buffer.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-buffer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-buffer.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-data.h: libfs/src/rfs/rtems-rfs-data.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-data.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-data.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-dir.h: libfs/src/rfs/rtems-rfs-dir.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-dir.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-dir.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-dir-hash.h: libfs/src/rfs/rtems-rfs-dir-hash.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-dir-hash.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-dir-hash.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file.h: libfs/src/rfs/rtems-rfs-file.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file-system-fwd.h: libfs/src/rfs/rtems-rfs-file-system-fwd.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file-system-fwd.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file-system-fwd.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file-system.h: libfs/src/rfs/rtems-rfs-file-system.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file-system.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-file-system.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-group.h: libfs/src/rfs/rtems-rfs-group.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-group.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-group.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-inode.h: libfs/src/rfs/rtems-rfs-inode.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-inode.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-inode.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-link.h: libfs/src/rfs/rtems-rfs-link.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-link.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-link.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-mutex.h: libfs/src/rfs/rtems-rfs-mutex.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-mutex.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-mutex.h
+
+$(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-trace.h: libfs/src/rfs/rtems-rfs-trace.h $(PROJECT_INCLUDE)/rtems/rfs/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-trace.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rfs/rtems-rfs-trace.h
+
+$(PROJECT_INCLUDE)/rtems/bdbuf.h: libblock/include/rtems/bdbuf.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bdbuf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bdbuf.h
+
+$(PROJECT_INCLUDE)/rtems/blkdev.h: libblock/include/rtems/blkdev.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/blkdev.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/blkdev.h
+
+$(PROJECT_INCLUDE)/rtems/diskdevs.h: libblock/include/rtems/diskdevs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/diskdevs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/diskdevs.h
+
+$(PROJECT_INCLUDE)/rtems/flashdisk.h: libblock/include/rtems/flashdisk.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/flashdisk.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/flashdisk.h
+
+$(PROJECT_INCLUDE)/rtems/ramdisk.h: libblock/include/rtems/ramdisk.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ramdisk.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ramdisk.h
+
+$(PROJECT_INCLUDE)/rtems/nvdisk.h: libblock/include/rtems/nvdisk.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/nvdisk.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/nvdisk.h
+
+$(PROJECT_INCLUDE)/rtems/nvdisk-sram.h: libblock/include/rtems/nvdisk-sram.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/nvdisk-sram.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/nvdisk-sram.h
+
+$(PROJECT_INCLUDE)/rtems/ide_part_table.h: libblock/include/rtems/ide_part_table.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ide_part_table.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ide_part_table.h
+
+$(PROJECT_INCLUDE)/rtems/bdpart.h: libblock/include/rtems/bdpart.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bdpart.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bdpart.h
+
+$(PROJECT_INCLUDE)/rtems/media.h: libblock/include/rtems/media.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/media.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/media.h
+
+if LIBNETWORKING
+$(PROJECT_INCLUDE)/rtems/ftpd.h: ftpd/ftpd.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ftpd.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ftpd.h
+endif
+$(PROJECT_INCLUDE)/rtems/bspcmdline.h: libmisc/bspcmdline/bspcmdline.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bspcmdline.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bspcmdline.h
+
+$(PROJECT_INCLUDE)/rtems/capture.h: libmisc/capture/capture.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/capture.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/capture.h
+
+$(PROJECT_INCLUDE)/rtems/capture-cli.h: libmisc/capture/capture-cli.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/capture-cli.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/capture-cli.h
+
+$(PROJECT_INCLUDE)/rtems/cpuuse.h: libmisc/cpuuse/cpuuse.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/cpuuse.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/cpuuse.h
+
+$(PROJECT_INCLUDE)/rtems/devnull.h: libmisc/devnull/devnull.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/devnull.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/devnull.h
+
+$(PROJECT_INCLUDE)/rtems/dumpbuf.h: libmisc/dumpbuf/dumpbuf.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/dumpbuf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/dumpbuf.h
+
+$(PROJECT_INCLUDE)/rtems/monitor.h: libmisc/monitor/monitor.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/monitor.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/monitor.h
+
+$(PROJECT_INCLUDE)/rtems/fb.h: libmisc/fb/fb.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/fb.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/fb.h
+
+$(PROJECT_INCLUDE)/rtems/mw_uid.h: libmisc/fb/mw_uid.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mw_uid.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mw_uid.h
+
+$(PROJECT_INCLUDE)/rtems/mouse_parser.h: libmisc/mouse/mouse_parser.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mouse_parser.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mouse_parser.h
+
+$(PROJECT_INCLUDE)/rtems/serial_mouse.h: libmisc/mouse/serial_mouse.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/serial_mouse.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/serial_mouse.h
+
+if LIBSHELL
+$(PROJECT_INCLUDE)/rtems/shell.h: libmisc/shell/shell.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/shell.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/shell.h
+
+$(PROJECT_INCLUDE)/rtems/shellconfig.h: libmisc/shell/shellconfig.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/shellconfig.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/shellconfig.h
+endif
+$(PROJECT_INCLUDE)/rtems/stringto.h: libmisc/stringto/stringto.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/stringto.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/stringto.h
+
+$(PROJECT_INCLUDE)/rtems/libi2c.h: libi2c/libi2c.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/libi2c.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/libi2c.h
+
+if LIBSERDBG
+$(PROJECT_INCLUDE)/rtems/serdbgcnf.h: libmisc/serdbg/serdbgcnf.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/serdbgcnf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/serdbgcnf.h
+
+$(PROJECT_INCLUDE)/rtems/serdbg.h: libmisc/serdbg/serdbg.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/serdbg.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/serdbg.h
+
+$(PROJECT_INCLUDE)/rtems/termios_printk_cnf.h: libmisc/serdbg/termios_printk_cnf.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/termios_printk_cnf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/termios_printk_cnf.h
+
+$(PROJECT_INCLUDE)/rtems/termios_printk.h: libmisc/serdbg/termios_printk.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/termios_printk.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/termios_printk.h
+endif
+$(PROJECT_INCLUDE)/rtems/stackchk.h: libmisc/stackchk/stackchk.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/stackchk.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/stackchk.h
+
+$(PROJECT_INCLUDE)/rtems/untar.h: libmisc/untar/untar.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/untar.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/untar.h
+
+$(PROJECT_INCLUDE)/rtems/fsmount.h: libmisc/fsmount/fsmount.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/fsmount.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/fsmount.h
+
diff --git a/cpukit/rtems/.cvsignore b/cpukit/rtems/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/rtems/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
new file mode 100644
index 0000000000..4af1752512
--- /dev/null
+++ b/cpukit/rtems/Makefile.am
@@ -0,0 +1,149 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+AM_CPPFLAGS += -D__RTEMS_INSIDE__
+
+noinst_LIBRARIES = librtems.a
+librtems_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+# include
+
+include_HEADERS = include/rtems.h
+
+# include/rtems/rtems
+include_rtems_rtemsdir = $(includedir)/rtems/rtems
+
+include_rtems_rtems_HEADERS = include/rtems/rtems/asr.h \
+ include/rtems/rtems/attr.h include/rtems/rtems/barrier.h \
+ include/rtems/rtems/cache.h include/rtems/rtems/clock.h \
+ include/rtems/rtems/config.h include/rtems/rtems/dpmem.h \
+ include/rtems/rtems/event.h include/rtems/rtems/eventset.h \
+ include/rtems/rtems/intr.h include/rtems/rtems/message.h \
+ include/rtems/rtems/modes.h include/rtems/rtems/object.h \
+ include/rtems/rtems/options.h include/rtems/rtems/part.h \
+ include/rtems/rtems/ratemon.h include/rtems/rtems/region.h \
+ include/rtems/rtems/rtemsapi.h include/rtems/rtems/sem.h \
+ include/rtems/rtems/signal.h include/rtems/rtems/status.h \
+ include/rtems/rtems/support.h include/rtems/rtems/tasks.h \
+ include/rtems/rtems/timer.h include/rtems/rtems/types.h \
+ mainpage.h
+
+if HAS_MP
+## We only build multiprocessing related files if HAS_MP was defined
+include_rtems_rtems_HEADERS += include/rtems/rtems/eventmp.h \
+ include/rtems/rtems/mp.h include/rtems/rtems/msgmp.h \
+ include/rtems/rtems/partmp.h include/rtems/rtems/regionmp.h \
+ include/rtems/rtems/semmp.h include/rtems/rtems/signalmp.h \
+ include/rtems/rtems/taskmp.h
+endif
+
+include_rtems_rtems_HEADERS += inline/rtems/rtems/asr.inl \
+ inline/rtems/rtems/attr.inl inline/rtems/rtems/barrier.inl \
+ inline/rtems/rtems/dpmem.inl \
+ inline/rtems/rtems/event.inl inline/rtems/rtems/eventset.inl \
+ inline/rtems/rtems/message.inl inline/rtems/rtems/modes.inl \
+ inline/rtems/rtems/options.inl inline/rtems/rtems/part.inl \
+ inline/rtems/rtems/ratemon.inl inline/rtems/rtems/region.inl \
+ inline/rtems/rtems/sem.inl inline/rtems/rtems/status.inl \
+ inline/rtems/rtems/support.inl inline/rtems/rtems/tasks.inl \
+ inline/rtems/rtems/timer.inl
+
+## src
+librtems_a_SOURCES = src/rtemsbuildid.c src/rtemsbuildname.c \
+ src/rtemsobjectgetname.c src/rtemsobjectsetname.c \
+ src/rtemsobjectidapimaximum.c src/rtemsobjectidapiminimum.c \
+ src/rtemsobjectidgetapi.c src/rtemsobjectidgetclass.c \
+ src/rtemsobjectidgetindex.c src/rtemsobjectidgetnode.c \
+ src/rtemsobjectapiminimumclass.c src/rtemsobjectapimaximumclass.c \
+ src/rtemsobjectgetapiname.c src/rtemsobjectgetapiclassname.c \
+ src/rtemsobjectgetclassinfo.c src/rtemsobjectgetclassicname.c
+
+## TASK_C_FILES
+librtems_a_SOURCES += src/tasks.c src/taskcreate.c src/taskdelete.c \
+ src/taskgetnote.c src/taskident.c src/taskinitusers.c \
+ src/taskissuspended.c src/taskmode.c src/taskrestart.c src/taskresume.c \
+ src/taskself.c src/tasksetnote.c src/tasksetpriority.c src/taskstart.c \
+ src/tasksuspend.c src/taskwakeafter.c src/taskwakewhen.c \
+ src/taskvariableadd.c src/taskvariabledelete.c src/taskvariableget.c \
+ src/taskvariable_invoke_dtor.c src/taskdata.c
+
+## RATEMON_C_FILES
+librtems_a_SOURCES += src/ratemon.c src/ratemoncancel.c src/ratemoncreate.c \
+ src/ratemondelete.c src/ratemongetstatus.c src/ratemongetstatistics.c \
+ src/ratemonresetstatistics.c src/ratemonresetall.c \
+ src/ratemonreportstatistics.c src/ratemonident.c \
+ src/ratemonperiod.c src/ratemontimeout.c src/ratemondata.c
+
+## INTR_C_FILES
+librtems_a_SOURCES += src/intrbody.c src/intrcatch.c
+
+## BARRIER_C_FILES
+librtems_a_SOURCES += src/barrier.c src/barriercreate.c src/barrierdelete.c \
+ src/barrierident.c src/barriertranslatereturncode.c src/barrierrelease.c \
+ src/barrierwait.c src/barrierdata.c
+
+## CLOCK_C_FILES
+librtems_a_SOURCES += src/clockget.c src/clockgetsecondssinceepoch.c \
+ src/clockgettickspersecond.c src/clockgettickssinceboot.c \
+ src/clockgettod.c src/clockgettodtimeval.c src/clockgetuptime.c \
+ src/clockset.c src/clocksetnsecshandler.c src/clocktick.c \
+ src/clocktodtoseconds.c src/clocktodvalidate.c
+
+## TIMER_C_FILES
+librtems_a_SOURCES += src/rtemstimer.c src/timercancel.c src/timercreate.c \
+ src/timerdelete.c src/timerfireafter.c src/timerfirewhen.c \
+ src/timergetinfo.c src/timerident.c src/timerreset.c src/timerserver.c \
+ src/timerserverfireafter.c src/timerserverfirewhen.c src/rtemstimerdata.c
+
+## MESSAGE_QUEUE_C_FILES
+librtems_a_SOURCES += src/msg.c src/msgqallocate.c src/msgqbroadcast.c \
+ src/msgqcreate.c src/msgqdelete.c src/msgqflush.c \
+ src/msgqgetnumberpending.c src/msgqident.c src/msgqreceive.c \
+ src/msgqsend.c src/msgqtranslatereturncode.c src/msgqurgent.c \
+ src/msgdata.c
+
+## SEMAPHORE_C_FILES
+librtems_a_SOURCES += src/sem.c src/semcreate.c src/semdelete.c src/semident.c \
+ src/semobtain.c src/semrelease.c src/semflush.c \
+ src/semtranslatereturncode.c src/semdata.c
+
+## EVENT_C_FILES
+librtems_a_SOURCES += src/event.c src/eventreceive.c src/eventseize.c \
+ src/eventsend.c src/eventsurrender.c src/eventtimeout.c src/eventdata.c
+
+## SIGNAL_C_FILES
+librtems_a_SOURCES += src/signal.c src/signalcatch.c src/signalsend.c
+
+## REGION_C_FILES
+librtems_a_SOURCES += src/region.c src/regioncreate.c src/regiondelete.c \
+ src/regionextend.c src/regiongetsegment.c src/regiongetsegmentsize.c \
+ src/regionident.c src/regionreturnsegment.c src/regiongetinfo.c \
+ src/regiongetfreeinfo.c src/regionresizesegment.c \
+ src/regionprocessqueue.c src/regiondata.c
+
+## PARTITION_C_FILES
+librtems_a_SOURCES += src/part.c src/partcreate.c src/partdelete.c \
+ src/partgetbuffer.c src/partident.c src/partreturnbuffer.c src/partdata.c
+
+## DPMEM_C_FILES
+librtems_a_SOURCES += src/dpmem.c src/dpmemcreate.c src/dpmemdelete.c \
+ src/dpmemexternal2internal.c src/dpmemident.c \
+ src/dpmeminternal2external.c src/dpmemdata.c
+
+## WORKSPACE_FILES
+librtems_a_SOURCES += src/workspace.c
+
+librtems_a_SOURCES += src/attr.c
+
+if HAS_MP
+# We only build multiprocessing related files if HAS_MP was defined
+librtems_a_SOURCES += src/eventmp.c src/mp.c src/msgmp.c src/partmp.c \
+ src/regionmp.c src/semmp.c src/signalmp.c src/taskmp.c
+endif
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/rtems/include/rtems.h b/cpukit/rtems/include/rtems.h
new file mode 100644
index 0000000000..17b1ce0394
--- /dev/null
+++ b/cpukit/rtems/include/rtems.h
@@ -0,0 +1,207 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief Provides the public interface to the RTEMS Classic API.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_H
+#define _RTEMS_H
+
+/**
+ * @defgroup ClassicRTEMS RTEMS Classic API
+ *
+ * RTEMS Classic API definitions and modules.
+ *
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if (!defined(__RTEMS_VIOLATE_KERNEL_VISIBILITY__)) && \
+ (!defined(__RTEMS_INSIDE__))
+/**
+ * @brief Compiling RTEMS application macro.
+ *
+ * Unless told otherwise, the RTEMS include files will hide some stuff from
+ * normal application code. Defining this crosses a boundary which is
+ * undesirable since it means your application is using RTEMS features which
+ * are not included in the formally defined and supported API. Define this at
+ * your own risk.
+ */
+#define __RTEMS_APPLICATION__
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+#include <rtems/config.h>
+#include <rtems/init.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/rtems/intr.h>
+#include <rtems/rtems/barrier.h>
+#include <rtems/rtems/cache.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/extension.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/event.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/rtems/event.h>
+#include <rtems/rtems/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/rtems/region.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/io.h>
+#include <rtems/fatal.h>
+#include <rtems/rtems/ratemon.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/mp.h>
+#endif
+
+#include <rtems/rtems/support.h>
+#include <rtems/score/sysstate.h>
+
+/**
+ * @brief Returns the pointer to the RTEMS version string.
+ */
+const char *rtems_get_version_string(void);
+
+/**
+ * @brief Indicates whether this processor variant has hardware floating point
+ * support.
+ */
+#define RTEMS_HAS_HARDWARE_FP CPU_HARDWARE_FP
+
+/**********************************************************************
+ * CONSTANTS WHICH MAY BE USED IN OBJECT NAME TO ID SEARCHES
+ **********************************************************************/
+
+/**
+ * @brief Indicates that a search is across all nodes.
+ */
+#define RTEMS_SEARCH_ALL_NODES OBJECTS_SEARCH_ALL_NODES
+
+/**
+ * @brief Indicates that a search is across all nodes except the one the call
+ * is made from.
+ */
+#define RTEMS_SEARCH_OTHER_NODES OBJECTS_SEARCH_OTHER_NODES
+
+/**
+ * @brief Indicates that the search is to be restricted to the local node.
+ */
+#define RTEMS_SEARCH_LOCAL_NODE OBJECTS_SEARCH_LOCAL_NODE
+
+/**
+ * @brief Indicates that the caller wants to obtain the name of the currently
+ * executing thread.
+ *
+ * This constant is only meaningful when obtaining the name of a task.
+ */
+#define RTEMS_WHO_AM_I OBJECTS_WHO_AM_I
+
+/**********************************************************************
+ * Parameters and return Id's for _Objects_Get_next
+ **********************************************************************/
+
+/**
+ * @brief Lowest valid index value for the index portion of an object
+ * identifier.
+ */
+#define RTEMS_OBJECT_ID_INITIAL_INDEX OBJECTS_ID_INITIAL_INDEX
+
+/**
+ * @brief Maximum valid index value for the index portion of an object
+ * identifier.
+ */
+#define RTEMS_OBJECT_ID_FINAL_INDEX OBJECTS_ID_FINAL_INDEX
+
+/**
+ * @brief Returns the identifier of the object with the lowest valid index
+ * value.
+ *
+ * The object is specified by the API @a _api, the object class @a _class and
+ * the node @a _node where the object resides.
+ */
+#define RTEMS_OBJECT_ID_INITIAL(_api, _class, _node) \
+ OBJECTS_ID_INITIAL(_api, _class, _node)
+
+/**
+ * @brief Maximum valid object identifier.
+ */
+#define RTEMS_OBJECT_ID_FINAL OBJECTS_ID_FINAL
+
+/**
+ * @brief Minimum stack size which every thread must exceed.
+ *
+ * It is the minimum stack size recommended for use on this processor. This
+ * value is selected by the RTEMS developers conservatively to minimize the
+ * risk of blown stacks for most user applications. Using this constant when
+ * specifying the task stack size, indicates that the stack size will be at
+ * least RTEMS_MINIMUM_STACK_SIZE bytes in size. If the user configured minimum
+ * stack size is larger than the recommended minimum, then it will be used.
+ */
+#define RTEMS_MINIMUM_STACK_SIZE STACK_MINIMUM_SIZE
+
+/**
+ * @brief Specifies that the task should be created with the configured minimum
+ * stack size.
+ *
+ * Using this constant when specifying the task stack size indicates that this
+ * task is to be created with a stack size of the minimum stack size that was
+ * configured by the application. If not explicitly configured by the
+ * application, the default configured minimum stack size is the processor
+ * dependent value RTEMS_MINIMUM_STACK_SIZE. Since this uses the configured
+ * minimum stack size value, you may get a stack size that is smaller or larger
+ * than the recommended minimum. This can be used to provide large stacks for
+ * all tasks on complex applications or small stacks on applications that are
+ * trying to conserve memory.
+ */
+#define RTEMS_CONFIGURED_MINIMUM_STACK_SIZE 0
+
+/**
+ * @brief Constant for indefinite wait.
+ *
+ * This is actually an illegal interval value.
+ */
+#define RTEMS_NO_TIMEOUT WATCHDOG_NO_TIMEOUT
+
+/**
+ * @brief An MPCI must support packets of at least this size.
+ */
+#define RTEMS_MINIMUM_PACKET_SIZE MP_PACKET_MINIMUM_PACKET_SIZE
+
+/**
+ * @brief Defines the count of @c uint32_t numbers in a packet which must be
+ * converted to native format in a heterogeneous system.
+ *
+ * In packets longer than this value, some of the extra data may be a user
+ * message buffer which is not automatically endian swapped.
+ */
+#define RTEMS_MINIMUN_HETERO_CONVERSION MP_PACKET_MINIMUN_HETERO_CONVERSION
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/asr.h b/cpukit/rtems/include/rtems/rtems/asr.h
new file mode 100644
index 0000000000..d733bd0626
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/asr.h
@@ -0,0 +1,156 @@
+/**
+ * @file rtems/rtems/asr.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Asynchronous Signal Handler. This Handler provides the low-level
+ * support required by the Signal Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_ASR_H
+#define _RTEMS_RTEMS_ASR_H
+
+#include <rtems/rtems/modes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicASR ASR Support
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following type defines the control block used to manage
+ * each signal set.
+ */
+typedef uint32_t rtems_signal_set;
+
+/**
+ * Return type for ASR Handler
+ */
+typedef void rtems_asr;
+
+/**
+ * The following type corresponds to the applications asynchronous
+ * signal processing routine.
+ */
+typedef rtems_asr ( *rtems_asr_entry )(
+ rtems_signal_set
+ );
+
+/**
+ * The following defines the control structure used to manage
+ * signals. Each thread has a copy of this record.
+ */
+typedef struct {
+ /** This field indicates if are ASRs enabled currently. */
+ bool is_enabled;
+ /** This field indicates if address of the signal handler function. */
+ rtems_asr_entry handler;
+ /** This field indicates if the task mode the signal will run with. */
+ Modes_Control mode_set;
+ /** This field indicates the signal set that is posted. */
+ rtems_signal_set signals_posted;
+ /** This field indicates the signal set that is pending. */
+ rtems_signal_set signals_pending;
+ /** This field indicates if nest level of signals being processed */
+ uint32_t nest_level;
+} ASR_Information;
+
+/*
+ * The following constants define the individual signals which may
+ * be used to compose a signal set.
+ */
+
+/** This defines the bit in the signal set associated with signal 0. */
+#define RTEMS_SIGNAL_0 0x00000001
+/** This defines the bit in the signal set associated with signal 1. */
+#define RTEMS_SIGNAL_1 0x00000002
+/** This defines the bit in the signal set associated with signal 2. */
+#define RTEMS_SIGNAL_2 0x00000004
+/** This defines the bit in the signal set associated with signal 3. */
+#define RTEMS_SIGNAL_3 0x00000008
+/** This defines the bit in the signal set associated with signal 4. */
+#define RTEMS_SIGNAL_4 0x00000010
+/** This defines the bit in the signal set associated with signal 5. */
+#define RTEMS_SIGNAL_5 0x00000020
+/** This defines the bit in the signal set associated with signal 6. */
+#define RTEMS_SIGNAL_6 0x00000040
+/** This defines the bit in the signal set associated with signal 7. */
+#define RTEMS_SIGNAL_7 0x00000080
+/** This defines the bit in the signal set associated with signal 8. */
+#define RTEMS_SIGNAL_8 0x00000100
+/** This defines the bit in the signal set associated with signal 9. */
+#define RTEMS_SIGNAL_9 0x00000200
+/** This defines the bit in the signal set associated with signal 10. */
+#define RTEMS_SIGNAL_10 0x00000400
+/** This defines the bit in the signal set associated with signal 11. */
+#define RTEMS_SIGNAL_11 0x00000800
+/** This defines the bit in the signal set associated with signal 12. */
+#define RTEMS_SIGNAL_12 0x00001000
+/** This defines the bit in the signal set associated with signal 13. */
+#define RTEMS_SIGNAL_13 0x00002000
+/** This defines the bit in the signal set associated with signal 14. */
+#define RTEMS_SIGNAL_14 0x00004000
+/** This defines the bit in the signal set associated with signal 15. */
+#define RTEMS_SIGNAL_15 0x00008000
+/** This defines the bit in the signal set associated with signal 16. */
+#define RTEMS_SIGNAL_16 0x00010000
+/** This defines the bit in the signal set associated with signal 17. */
+#define RTEMS_SIGNAL_17 0x00020000
+/** This defines the bit in the signal set associated with signal 18. */
+#define RTEMS_SIGNAL_18 0x00040000
+/** This defines the bit in the signal set associated with signal 19. */
+#define RTEMS_SIGNAL_19 0x00080000
+/** This defines the bit in the signal set associated with signal 20. */
+#define RTEMS_SIGNAL_20 0x00100000
+/** This defines the bit in the signal set associated with signal 21. */
+#define RTEMS_SIGNAL_21 0x00200000
+/** This defines the bit in the signal set associated with signal 22. */
+#define RTEMS_SIGNAL_22 0x00400000
+/** This defines the bit in the signal set associated with signal 23. */
+#define RTEMS_SIGNAL_23 0x00800000
+/** This defines the bit in the signal set associated with signal 24. */
+#define RTEMS_SIGNAL_24 0x01000000
+/** This defines the bit in the signal set associated with signal 25. */
+#define RTEMS_SIGNAL_25 0x02000000
+/** This defines the bit in the signal set associated with signal 26. */
+#define RTEMS_SIGNAL_26 0x04000000
+/** This defines the bit in the signal set associated with signal 27. */
+#define RTEMS_SIGNAL_27 0x08000000
+/** This defines the bit in the signal set associated with signal 28. */
+#define RTEMS_SIGNAL_28 0x10000000
+/** This defines the bit in the signal set associated with signal 29. */
+#define RTEMS_SIGNAL_29 0x20000000
+/** This defines the bit in the signal set associated with signal 30. */
+#define RTEMS_SIGNAL_30 0x40000000
+/** This defines the bit in the signal set associated with signal 31. */
+#define RTEMS_SIGNAL_31 0x80000000
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/asr.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/attr.h b/cpukit/rtems/include/rtems/rtems/attr.h
new file mode 100644
index 0000000000..0206ad5cc6
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/attr.h
@@ -0,0 +1,198 @@
+/**
+ * @file rtems/rtems/attr.h
+ *
+ * This include file contains all information about the Object Attributes
+ * Handler.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_ATTR_H
+#define _RTEMS_RTEMS_ATTR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicAttributes Attributes
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which defines and manages the
+ * set of Classic API object attributes.
+ */
+/**@{*/
+
+/**
+ * This defines the type used to contain Classic API attributes. These
+ * are primarily used when creating objects.
+ */
+typedef uint32_t rtems_attribute;
+
+/** This is the default value for an attribute set. */
+
+#define RTEMS_DEFAULT_ATTRIBUTES 0x00000000
+
+/**
+ * This is the attribute constant to indicate local resource.
+ */
+#define RTEMS_LOCAL 0x00000000
+
+/**
+ * This is the attribute constant to indicate global resource.
+ */
+#define RTEMS_GLOBAL 0x00000002
+
+/**
+ * This is the attribute constant which reflects that blocking
+ * tasks will be managed using FIFO discipline.
+ */
+#define RTEMS_FIFO 0x00000000
+
+/**
+ * This is the attribute constant which reflects that blocking
+ * tasks will be managed using task priority discipline.
+ */
+#define RTEMS_PRIORITY 0x00000004
+
+/******************** RTEMS Task Specific Attributes *********************/
+
+/**
+ * This attribute constant indicates that the task will not use the
+ * floating point hardware. If the architecture permits it, then
+ * the FPU will be disabled when the task is executing.
+ */
+#define RTEMS_NO_FLOATING_POINT 0x00000000
+
+/**
+ * This attribute constant indicates that the task will use the
+ * floating point hardware. There will be a floating point
+ * context associated with this task.
+ */
+#define RTEMS_FLOATING_POINT 0x00000001
+
+/***************** RTEMS Semaphore Specific Attributes ********************/
+
+/**
+ * This is the mask for the attribute bits associated with the
+ * Classic API Semaphore Manager.
+ */
+#define RTEMS_SEMAPHORE_CLASS 0x00000030
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will be a counting semaphore.
+ */
+#define RTEMS_COUNTING_SEMAPHORE 0x00000000
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will be a proper binary semaphore or mutex.
+ */
+#define RTEMS_BINARY_SEMAPHORE 0x00000010
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will be a simple binary semaphore.
+ */
+#define RTEMS_SIMPLE_BINARY_SEMAPHORE 0x00000020
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will NOT use the Priority Inheritance Protocol.
+ */
+#define RTEMS_NO_INHERIT_PRIORITY 0x00000000
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will use the Priority Inheritance Protocol.
+ *
+ * @note The semaphore instance must be a binary semaphore.
+ */
+#define RTEMS_INHERIT_PRIORITY 0x00000040
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will NOT use the Priority Ceiling Protocol.
+ */
+#define RTEMS_NO_PRIORITY_CEILING 0x00000000
+
+/**
+ * This attribute constant indicates that the Classic API Semaphore
+ * instance created will use the Priority Ceiling Protocol.
+ *
+ * @note The semaphore instance must be a binary semaphore.
+ */
+#define RTEMS_PRIORITY_CEILING 0x00000080
+
+/******************** RTEMS Barrier Specific Attributes ********************/
+
+/**
+ * This attribute constant indicates that the Classic API Barrier
+ * instance created will use an automatic release protocol.
+ */
+#define RTEMS_BARRIER_AUTOMATIC_RELEASE 0x00000010
+
+/**
+ * This attribute constant indicates that the Classic API Barrier
+ * instance created will use the manual release protocol.
+ */
+#define RTEMS_BARRIER_MANUAL_RELEASE 0x00000000
+
+/**************** RTEMS Internal Task Specific Attributes ****************/
+
+/**
+ * This attribute constant indicates that the task was created
+ * by the application using normal Classic API methods.
+ */
+#define RTEMS_APPLICATION_TASK 0x00000000
+
+/**
+ * This attribute constant indicates that the task was created
+ * by RTEMS as a support task.
+ */
+#define RTEMS_SYSTEM_TASK 0x00008000
+
+/****************** Forced Attributes in Configuration ****************/
+
+/**
+ * This attribute constant indicates the attributes that are not
+ * supportable given the hardware configuration.
+ */
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+#define ATTRIBUTES_NOT_SUPPORTED 0
+#else
+#define ATTRIBUTES_NOT_SUPPORTED RTEMS_FLOATING_POINT
+#endif
+
+/**
+ * This attribute constant indicates the attributes that are
+ * required given the hardware configuration.
+ */
+#if ( CPU_ALL_TASKS_ARE_FP == TRUE )
+#define ATTRIBUTES_REQUIRED RTEMS_FLOATING_POINT
+#else
+#define ATTRIBUTES_REQUIRED 0
+#endif
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/attr.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/barrier.h b/cpukit/rtems/include/rtems/rtems/barrier.h
new file mode 100644
index 0000000000..566d0299e5
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/barrier.h
@@ -0,0 +1,205 @@
+/**
+ * @file rtems/rtems/barrier.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Barrier Manager.
+ *
+ * Directives provided are:
+ *
+ * - create a barrier
+ * - get an ID of a barrier
+ * - delete a barrier
+ * - wait for a barrier
+ * - signal a barrier
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_BARRIER_H
+#define _RTEMS_RTEMS_BARRIER_H
+
+/**
+ * @defgroup ClassicBarrier Barriers
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_BARRIER_EXTERN
+#define RTEMS_BARRIER_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/object.h>
+#include <rtems/score/corebarrier.h>
+
+/**
+ * This type defines the control block used to manage each barrier.
+ */
+typedef struct {
+ /** This is used to manage a barrier as an object. */
+ Objects_Control Object;
+ /** This is used to specify the attributes of a barrier. */
+ rtems_attribute attribute_set;
+ /** This is used to implement the barrier. */
+ CORE_barrier_Control Barrier;
+} Barrier_Control;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+RTEMS_BARRIER_EXTERN Objects_Information _Barrier_Information;
+
+/**
+ * @brief _Barrier_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Barrier_Manager_initialization(void);
+
+/**
+ * @brief rtems_barrier_create
+ *
+ * This routine implements the rtems_barrier_create directive. The
+ * barrier will have the name name. The starting count for
+ * the barrier is count. The attribute_set determines if
+ * the barrier is global or local and the thread queue
+ * discipline. It returns the id of the created barrier in ID.
+ *
+ * @param[in] name is the name of this barrier instance.
+ * @param[in] attribute_set specifies the attributes of this barrier instance.
+ * @param[in] maximum_waiters is the maximum number of threads which will
+ * be allowed to concurrently wait at the barrier.
+ * @param[out] id will contain the id of this barrier.
+ *
+ * @return a status code indicating success or the reason for failure.
+ */
+rtems_status_code rtems_barrier_create(
+ rtems_name name,
+ rtems_attribute attribute_set,
+ uint32_t maximum_waiters,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_barrier_ident
+ *
+ * This routine implements the rtems_barrier_ident directive.
+ * This directive returns the barrier ID associated with name.
+ * If more than one barrier is named name, then the barrier
+ * to which the ID belongs is arbitrary. node indicates the
+ * extent of the search for the ID of the barrier named name.
+ * The search can be limited to a particular node or allowed to
+ * encompass all nodes.
+ *
+ * @param[in] name is the name of this barrier instance.
+ * @param[out] id will contain the id of this barrier.
+ *
+ * @return a status code indicating success or the reason for failure.
+ */
+rtems_status_code rtems_barrier_ident(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_barrier_delete
+ *
+ * This routine implements the rtems_barrier_delete directive. The
+ * barrier indicated by @a id is deleted.
+ *
+ * @param[in] id indicates the barrier to delete
+ *
+ * @return a status code indicating success or the reason for failure.
+ */
+rtems_status_code rtems_barrier_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_barrier_wait
+ *
+ * This routine implements the rtems_barrier_wait directive. It
+ * attempts to wait at the barrier associated with @a id. The calling task
+ * may block waiting for the barrier with an optional timeout of @a timeout
+ * clock ticks.
+ *
+ * @param[in] id indicates the barrier to wait at.
+ * @param[in] timeout is the maximum length of time in ticks the calling
+ * thread is willing to block.
+ *
+ * @return a status code indicating success or the reason for failure.
+ */
+rtems_status_code rtems_barrier_wait(
+ rtems_id id,
+ rtems_interval timeout
+);
+
+/**
+ * @brief rtems_barrier_release
+ *
+ * This routine implements the rtems_barrier_release directive. It
+ * unblocks all of the threads waiting on the barrier associated with
+ * @a id. The number of threads unblocked is returned in @a released.
+ *
+ *
+ * @param[in] id indicates the barrier to wait at.
+ * @param[out] released will contain the number of threads unblocked.
+ *
+ * @return a status code indicating success or the reason for failure.
+ */
+rtems_status_code rtems_barrier_release(
+ rtems_id id,
+ uint32_t *released
+);
+
+/**
+ * @brief Translate SuperCore Barrier Status Code to RTEMS Status Code
+ *
+ * This function returns a RTEMS status code based on the barrier
+ * status code specified.
+ *
+ * @param[in] the_status is the SuperCore Barrier status to translate.
+ *
+ * @return a status code indicating success or the reason for failure.
+ */
+rtems_status_code _Barrier_Translate_core_barrier_return_code (
+ CORE_barrier_Status the_status
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/barrier.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/barriermp.h b/cpukit/rtems/include/rtems/rtems/barriermp.h
new file mode 100644
index 0000000000..1a20680665
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/barriermp.h
@@ -0,0 +1,151 @@
+/**
+ * @file rtems/rtems/barriermp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Barrier Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SEMMP_H
+#define _RTEMS_RTEMS_SEMMP_H
+
+/**
+ * @defgroup ClassicBarrierMP Barrier MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/barrier.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * The following enumerated type defines the list of
+ * remote barrier operations.
+ */
+typedef enum {
+ BARRIER_MP_ANNOUNCE_CREATE = 0,
+ BARRIER_MP_ANNOUNCE_DELETE = 1,
+ BARRIER_MP_EXTRACT_PROXY = 2,
+ BARRIER_MP_WAIT_REQUEST = 3,
+ BARRIER_MP_WAIT_RESPONSE = 4,
+ BARRIER_MP_RELEASE_REQUEST = 5,
+ BARRIER_MP_RELEASE_RESPONSE = 6
+} Barrier_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote barrier operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Barrier_MP_Remote_operations operation;
+ rtems_name name;
+ rtems_option option_set;
+ Objects_Id proxy_id;
+} Barrier_MP_Packet;
+
+/**
+ * @brief _Barrier_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ */
+void _Barrier_MP_Send_process_packet (
+ Barrier_MP_Remote_operations operation,
+ Objects_Id barrier_id,
+ rtems_name name,
+ Objects_Id proxy_id
+);
+
+/**
+ * @brief _Barrier_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Barrier_MP_Send_request_packet (
+ Barrier_MP_Remote_operations operation,
+ Objects_Id barrier_id,
+ rtems_interval timeout
+);
+
+/**
+ * @brief _Barrier_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+
+void _Barrier_MP_Send_response_packet (
+ Barrier_MP_Remote_operations operation,
+ Objects_Id barrier_id,
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief _Barrier_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Barrier_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/**
+ * @brief _Barrier_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ */
+void _Barrier_MP_Send_object_was_deleted (
+ Thread_Control *the_proxy
+);
+
+/**
+ * @brief _Barrier_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ */
+void _Barrier_MP_Send_extract_proxy (
+ void *argument
+);
+
+/**
+ * @brief _Barrier_MP_Get_packet
+ *
+ * This function is used to obtain a barrier mp packet.
+ */
+Barrier_MP_Packet *_Barrier_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/cache.h b/cpukit/rtems/include/rtems/rtems/cache.h
new file mode 100644
index 0000000000..72aab56cea
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/cache.h
@@ -0,0 +1,158 @@
+/**
+ * @file rtems/rtems/cache.h
+ *
+ * Cache Manager
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ *
+ * The functions in this file define the API to the RTEMS Cache Manager and
+ * are divided into data cache and instruction cache functions. Data cache
+ * functions are only meaningful if a data cache is supported. Instruction
+ * cache functions are only meaningful if an instruction cache is supported.
+ *
+ * The functions below are implemented with CPU dependent support routines
+ * implemented as part of libcpu. In the event that a CPU does not support a
+ * specific function, the CPU dependent routine does nothing (but does exist).
+ *
+ * At this point, the Cache Manager makes no considerations, and provides no
+ * support for BSP specific issues such as a secondary cache. In such a system,
+ * the CPU dependent routines would have to be modified, or a BSP layer added
+ * to this Manager.
+ */
+
+#ifndef _RTEMS_RTEMS_CACHE_H
+#define _RTEMS_RTEMS_CACHE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+
+/**
+ * @defgroup ClassicCache Cache
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/*
+ * These functions will ONLY do something if the
+ * libcpu support includes data cache routines AND
+ * the CPU model supports data caching.
+ */
+
+/**
+ * This function is called to flush the data cache by performing cache
+ * copybacks. It must determine how many cache lines need to be copied
+ * back and then perform the copybacks.
+ */
+void rtems_cache_flush_multiple_data_lines( const void *, size_t );
+
+/**
+ * This function is responsible for performing a data cache invalidate.
+ * It must determine how many cache lines need to be invalidated and then
+ * perform the invalidations.
+ */
+void rtems_cache_invalidate_multiple_data_lines( const void *, size_t );
+
+/**
+ * This function is responsible for performing a data cache flush.
+ * It flushes the entire cache.
+ */
+void rtems_cache_flush_entire_data( void );
+
+/**
+ * This function is responsible for performing a data cache
+ * invalidate. It invalidates the entire cache.
+ */
+void rtems_cache_invalidate_entire_data( void );
+
+/**
+ * This function returns the data cache granularity.
+ */
+int rtems_cache_get_data_line_size( void );
+
+/**
+ * This function freezes the data cache.
+ */
+void rtems_cache_freeze_data( void );
+
+/**
+ * This function unfreezes the data cache.
+ */
+void rtems_cache_unfreeze_data( void );
+
+/**
+ * This function enables the data cache.
+ */
+void rtems_cache_enable_data( void );
+
+/**
+ * This function disables the data cache.
+ */
+void rtems_cache_disable_data( void );
+
+/**
+ * These functions will ONLY do something if the
+ * libcpu support includes instruction cache routines AND
+ * the CPU model supports instruction caching.
+ */
+
+/**
+ * This function is responsible for performing an instruction cache
+ * invalidate. It must determine how many cache lines need to be invalidated
+ * and then perform the invalidations.
+ */
+void rtems_cache_invalidate_multiple_instruction_lines( const void *, size_t );
+
+/**
+ * This function is responsible for performing an instruction cache
+ * invalidate. It invalidates the entire cache.
+ */
+void rtems_cache_invalidate_entire_instruction( void );
+
+/**
+ * This function returns the instruction cache granularity.
+ */
+int rtems_cache_get_instruction_line_size( void );
+
+/**
+ * This function freezes the instruction cache.
+ */
+void rtems_cache_freeze_instruction( void );
+
+/**
+ * This function unfreezes the instruction cache.
+ */
+void rtems_cache_unfreeze_instruction( void );
+
+/**
+ * This function enables the instruction cache.
+ */
+void rtems_cache_enable_instruction( void );
+
+/**
+ * This function disables the instruction cache.
+ */
+void rtems_cache_disable_instruction( void );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/clock.h b/cpukit/rtems/include/rtems/rtems/clock.h
new file mode 100644
index 0000000000..7e2d776fe6
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/clock.h
@@ -0,0 +1,267 @@
+/**
+ * @file rtems/rtems/clock.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Clock Manager. This manager provides facilities to set, obtain,
+ * and continually update the current date and time.
+ *
+ * This manager provides directives to:
+ *
+ * - set the current date and time
+ * - obtain the current date and time
+ * - set the nanoseconds since last clock tick handler
+ * - announce a clock tick
+ * - obtain the system uptime
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_CLOCK_H
+#define _RTEMS_RTEMS_CLOCK_H
+
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+#include <sys/time.h> /* struct timeval */
+
+/**
+ * @defgroup ClassicClock Clocks
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * List of things which can be returned by the rtems_clock_get directive.
+ */
+typedef enum {
+ /** This value indicates obtain TOD in Classic API format. */
+ RTEMS_CLOCK_GET_TOD,
+ /** This value indicates obtain the number of seconds since the epoch. */
+ RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH,
+ /** This value indicates obtain the number of ticks since system boot. */
+ RTEMS_CLOCK_GET_TICKS_SINCE_BOOT,
+ /** This value indicates obtain the number of ticks per second. */
+ RTEMS_CLOCK_GET_TICKS_PER_SECOND,
+ /** This value indicates obtain the TOD in struct timeval format. */
+ RTEMS_CLOCK_GET_TIME_VALUE
+} rtems_clock_get_options;
+
+/**
+ * Type for the nanoseconds since last tick BSP extension.
+ */
+typedef Watchdog_Nanoseconds_since_last_tick_routine
+ rtems_nanoseconds_extension_routine;
+
+/**
+ * @brief Obtain Current Time of Day
+ *
+ * This routine implements the rtems_clock_get directive. It returns
+ * one of the following:
+ * + current time of day
+ * + seconds since epoch
+ * + ticks since boot
+ * + ticks per second
+ *
+ * @param[in] option is the format of time to return
+ * @param[in] time_buffer points to the output area
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error.
+ */
+rtems_status_code rtems_clock_get(
+ rtems_clock_get_options option,
+ void *time_buffer
+);
+
+/**
+ * @brief Obtain Current Time of Day (Classic TOD)
+ *
+ * This routine implements the rtems_clock_get_tod directive. It returns
+ * the current time of day in the format defined by RTEID.
+ *
+ * @param[in] time_buffer points to the time of day structure
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error. If successful, the time_buffer will
+ * be filled in with the current time of day.
+ */
+rtems_status_code rtems_clock_get_tod(
+ rtems_time_of_day *time_buffer
+);
+
+/**
+ * @brief Obtain TOD in struct timeval Format
+ *
+ * This routine implements the rtems_clock_get_tod_timeval
+ * directive.
+ *
+ * @param[in] time points to the struct timeval variable to fill in
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error. If successful, the time will
+ * be filled in with the current time of day.
+ */
+rtems_status_code rtems_clock_get_tod_timeval(
+ struct timeval *time
+);
+
+/**
+ * @brief Obtain Seconds Since Epoch
+ *
+ * This routine implements the rtems_clock_get_seconds_since_epoch
+ * directive.
+ *
+ * @param[in] the_interval points to the interval variable to fill in
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error. If successful, the time_buffer will
+ * be filled in with the current time of day.
+ */
+rtems_status_code rtems_clock_get_seconds_since_epoch(
+ rtems_interval *the_interval
+);
+
+/**
+ * @brief Obtain Ticks Since Boot
+ *
+ * This routine implements the rtems_clock_get_ticks_since_boot
+ * directive.
+ *
+ * @return This method returns the number of ticks since boot. It cannot
+ * fail since RTEMS always keeps a running count of ticks since boot.
+ */
+rtems_interval rtems_clock_get_ticks_since_boot(void);
+
+/**
+ * @brief Obtain Ticks Per Seconds
+ *
+ * This routine implements the rtems_clock_get_ticks_per_second
+ * directive.
+ *
+ * @return This method returns the number of ticks since boot. It cannot
+ * fail since RTEMS is always configured to know the number of
+ * ticks per second.
+ */
+rtems_interval rtems_clock_get_ticks_per_second(void);
+
+/**
+ * @brief Set the Current TOD
+ *
+ * This routine implements the rtems_clock_set directive. It sets
+ * the current time of day to that in the time_buffer record.
+ *
+ * @param[in] time_buffer points to the new TOD
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error.
+ *
+ * @note Activities scheduled based upon the current time of day
+ * may be executed immediately if the time is moved forward.
+ */
+rtems_status_code rtems_clock_set(
+ rtems_time_of_day *time_buffer
+);
+
+/**
+ * @brief Announce a Clock Tick
+ *
+ * This routine implements the rtems_clock_tick directive. It is invoked
+ * to inform RTEMS of the occurrence of a clock tick.
+ *
+ * @return This directive always returns RTEMS_SUCCESSFUL.
+ *
+ * @note This method is typically called from an ISR and is the basis
+ * for all timeouts and delays.
+ */
+rtems_status_code rtems_clock_tick( void );
+
+/**
+ * @brief Set the BSP specific Nanoseconds Extension
+ *
+ * This directive sets the BSP provided nanoseconds since last tick
+ * extension.
+ *
+ * @param[in] routine is a pointer to the extension routine
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error.
+ */
+rtems_status_code rtems_clock_set_nanoseconds_extension(
+ rtems_nanoseconds_extension_routine routine
+);
+
+/**
+ * @brief Obtain the System Uptime
+ *
+ * This directive returns the system uptime.
+ *
+ * @param[in] uptime is a pointer to the time structure
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if there was not an
+ * error. Otherwise, a status code is returned indicating the
+ * source of the error. If successful, the uptime will be
+ * filled in.
+ */
+rtems_status_code rtems_clock_get_uptime(
+ struct timespec *uptime
+);
+
+/**
+ * @brief _TOD_Validate
+ *
+ * This support function returns true if @a the_tod contains
+ * a valid time of day, and false otherwise.
+ *
+ * @param[in] the_tod is the TOD structure to validate
+ *
+ * @return This method returns true if the TOD is valid and false otherwise.
+ */
+bool _TOD_Validate(
+ const rtems_time_of_day *the_tod
+);
+
+/**
+ * @brief _TOD_To_seconds
+ *
+ * This function returns the number seconds between the epoch and @a the_tod.
+ *
+ * @param[in] the_tod is the TOD structure to convert to seconds
+ *
+ * @return This method returns the number of seconds since epoch represented
+ * by @a the_tod
+ */
+Watchdog_Interval _TOD_To_seconds(
+ const rtems_time_of_day *the_tod
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/config.h b/cpukit/rtems/include/rtems/rtems/config.h
new file mode 100644
index 0000000000..2217463d5a
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/config.h
@@ -0,0 +1,151 @@
+/**
+ * @file rtems/rtems/config.h
+ *
+ * This include file contains the table of user defined configuration
+ * parameters specific for the RTEMS API.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_CONFIG_H
+#define _RTEMS_RTEMS_CONFIG_H
+
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/tasks.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicConfig Configuration
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following records define the Configuration Table. The
+ * information contained in this table is required in all
+ * RTEMS systems, whether single or multiprocessor. This
+ * table primarily defines the following:
+ *
+ * + required number of each object type
+ */
+typedef struct {
+ /**
+ * This field contains the maximum number of Classic API
+ * Tasks which are configured for this application.
+ */
+ uint32_t maximum_tasks;
+
+ /**
+ * This field indicates whether Classic API notepads are
+ * enabled or disabled.
+ */
+ bool notepads_enabled;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Timers which are configured for this application.
+ */
+ uint32_t maximum_timers;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Semaphores which are configured for this application.
+ */
+ uint32_t maximum_semaphores;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Message Queues which are configured for this application.
+ */
+ uint32_t maximum_message_queues;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Partitions which are configured for this application.
+ */
+ uint32_t maximum_partitions;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Regions which are configured for this application.
+ */
+ uint32_t maximum_regions;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Dual Ported Memory Areas which are configured for this
+ * application.
+ */
+ uint32_t maximum_ports;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Rate Monotonic Periods which are configured for this
+ * application.
+ */
+ uint32_t maximum_periods;
+
+ /**
+ * This field contains the maximum number of Classic API
+ * Barriers which are configured for this application.
+ */
+ uint32_t maximum_barriers;
+
+ /**
+ * This field contains the number of Classic API Initialization
+ * Tasks which are configured for this application.
+ */
+ uint32_t number_of_initialization_tasks;
+
+ /**
+ * This field is the set of Classic API Initialization
+ * Tasks which are configured for this application.
+ */
+ rtems_initialization_tasks_table *User_initialization_tasks_table;
+} rtems_api_configuration_table;
+
+/**
+ * @brief RTEMS API Configuration Table
+ *
+ * This is the RTEMS API Configuration Table expected to be generated
+ * by confdefs.h.
+ */
+extern rtems_api_configuration_table Configuration_RTEMS_API;
+
+/**@}*/
+
+/**
+ * This macro returns the value of the notepads enabled field
+ * in the Classic API configuration table.
+ */
+#define rtems_configuration_get_notepads_enabled() \
+ rtems_configuration_get_rtems_api_configuration()->notepads_enabled
+
+/**
+ * This macro returns the number of Classic API semaphores configured.
+ */
+#define rtems_configuration_get_maximum_semaphores() \
+ rtems_configuration_get_rtems_api_configuration()->maximum_semaphores
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/dpmem.h b/cpukit/rtems/include/rtems/rtems/dpmem.h
new file mode 100644
index 0000000000..86885143b5
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/dpmem.h
@@ -0,0 +1,164 @@
+/**
+ * @file rtems/rtems/dpmem.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Dual Ported Memory Manager. This manager provides a mechanism
+ * for converting addresses between internal and external representations
+ * for multiple dual-ported memory areas.
+ *
+ * Directives provided are:
+ *
+ * - create a port
+ * - get ID of a port
+ * - delete a port
+ * - convert external to internal address
+ * - convert internal to external address
+ *
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_DPMEM_H
+#define _RTEMS_RTEMS_DPMEM_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_DPMEM_EXTERN
+#define RTEMS_DPMEM_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/status.h>
+
+/**
+ * @defgroup ClassicDPMEM Dual Ported Memory
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality related to the
+ * Classic API Dual Ported Memory Manager.
+ */
+/**@{*/
+
+/**
+ * The following structure defines the port control block. Each port
+ * has a control block associated with it. This control block contains
+ * all information required to support the port related operations.
+ */
+typedef struct {
+ /** This field is the object management portion of a Port instance. */
+ Objects_Control Object;
+ /** This field is the base internal address of the port. */
+ void *internal_base;
+ /** This field is the base external address of the port. */
+ void *external_base;
+ /** This field is the length of dual-ported area of the port. */
+ uint32_t length;
+} Dual_ported_memory_Control;
+
+/**
+ * The following define the internal Dual Ported Memory information.
+ */
+RTEMS_DPMEM_EXTERN Objects_Information _Dual_ported_memory_Information;
+
+/**
+ * @brief _Dual_ported_memory_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Dual_ported_memory_Manager_initialization(void);
+
+/**
+ * @brief rtems_port_create
+ *
+ * This routine implements the rtems_port_create directive. The port
+ * will have the name name. The port maps onto an area of dual ported
+ * memory of length bytes which has internal_start and external_start
+ * as the internal and external starting addresses, respectively.
+ * It returns the id of the created port in ID.
+ */
+rtems_status_code rtems_port_create(
+ rtems_name name,
+ void *internal_start,
+ void *external_start,
+ uint32_t length,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_port_ident
+ *
+ * This routine implements the rtems_port_ident directive. This directive
+ * returns the port ID associated with name. If more than one port is
+ * named name, then the port to which the ID belongs is arbitrary.
+ */
+rtems_status_code rtems_port_ident(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_port_delete
+ *
+ * This routine implements the rtems_port_delete directive. It deletes
+ * the port associated with ID.
+ */
+rtems_status_code rtems_port_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_port_external_to_internal
+ *
+ * This routine implements the rtems_port_external_to_internal directive.
+ * It returns the internal port address which maps to the provided
+ * external port address for the specified port ID.
+ */
+rtems_status_code rtems_port_external_to_internal(
+ rtems_id id,
+ void *external,
+ void **internal
+);
+
+/**
+ * @brief rtems_port_internal_to_external
+ *
+ * This routine implements the Port_internal_to_external directive.
+ * It returns the external port address which maps to the provided
+ * internal port address for the specified port ID.
+ */
+rtems_status_code rtems_port_internal_to_external(
+ rtems_id id,
+ void *internal,
+ void **external
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/dpmem.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/event.h b/cpukit/rtems/include/rtems/rtems/event.h
new file mode 100644
index 0000000000..05f66d64cd
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/event.h
@@ -0,0 +1,166 @@
+/**
+ * @file rtems/rtems/event.h
+ *
+ * This include file contains the information pertaining to the Event
+ * Manager. This manager provides a high performance method of communication
+ * and synchronization.
+ *
+ * Directives provided are:
+ *
+ * - send an event set to a task
+ * - receive event condition
+ *
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_EVENT_H
+#define _RTEMS_RTEMS_EVENT_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_EVENT_EXTERN
+#define RTEMS_EVENT_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadsync.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/eventset.h>
+
+/**
+ * @defgroup ClassicEvent Events
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * This constant is passed as the event_in to the
+ * rtems_event_receive directive to determine which events are pending.
+ */
+#define EVENT_CURRENT 0
+
+/**
+ * @brief Event_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Event_Manager_initialization( void );
+
+/**
+ * @brief rtems_event_send
+ *
+ * This routine implements the rtems_event_send directive. It sends
+ * event_in to the task specified by ID. If the task is blocked
+ * waiting to receive events and the posting of event_in satisfies
+ * the task's event condition, then it is unblocked.
+ */
+rtems_status_code rtems_event_send (
+ rtems_id id,
+ rtems_event_set event_in
+);
+
+/**
+ * @brief rtems_event_receive
+ *
+ * This routine implements the rtems_event_receive directive. This
+ * directive is invoked when the calling task wishes to receive
+ * the event_in event condition. One of the fields in the option_set
+ * parameter determines whether the receive request is satisfied if
+ * any or all of the events are pending. If the event condition
+ * is not satisfied immediately, then the task may block with an
+ * optional timeout of TICKS clock ticks or return immediately.
+ * This determination is based on another field in the option_set
+ * parameter. This directive returns the events received in the
+ * event_out parameter.
+ */
+rtems_status_code rtems_event_receive (
+ rtems_event_set event_in,
+ rtems_option option_set,
+ rtems_interval ticks,
+ rtems_event_set *event_out
+);
+
+/**
+ * @brief Event_Seize
+ *
+ * This routine determines if the event condition event_in is
+ * satisfied. If so or if the no_wait option is enabled in option_set,
+ * then the procedure returns immediately. If neither of these
+ * conditions is true, then the calling task is blocked with an
+ * optional timeout of ticks clock ticks.
+ */
+void _Event_Seize (
+ rtems_event_set event_in,
+ rtems_option option_set,
+ rtems_interval ticks,
+ rtems_event_set *event_out
+);
+
+/**
+ * @brief Event_Surrender
+ *
+ * This routine determines if the event condition of the_thread
+ * has been satisfied. If so, it unblocks the_thread.
+ */
+void _Event_Surrender (
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief Event_Timeout
+ *
+ * This routine is invoked when a task's event receive request
+ * has not been satisfied after the specified timeout interval.
+ * The task represented by ID will be unblocked and its status
+ * code will be set in it's control block to indicate that a timeout
+ * has occurred.
+ */
+void _Event_Timeout (
+ Objects_Id id,
+ void *ignored
+);
+
+/**
+ * @brief he following defines the synchronization flag used by the
+ */
+RTEMS_EVENT_EXTERN volatile Thread_blocking_operation_States _Event_Sync_state;
+
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/eventmp.h>
+#endif
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/event.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/eventmp.h b/cpukit/rtems/include/rtems/rtems/eventmp.h
new file mode 100644
index 0000000000..bc44fe6aab
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/eventmp.h
@@ -0,0 +1,138 @@
+/**
+ * @file rtems/rtems/eventmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Event Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_EVENTMP_H
+#define _RTEMS_RTEMS_EVENTMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/event.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * @defgroup ClassicEventMP Event MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following enumerated type defines the list of
+ * remote event operations.
+ */
+typedef enum {
+ EVENT_MP_SEND_REQUEST = 0,
+ EVENT_MP_SEND_RESPONSE = 1
+} Event_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote event operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Event_MP_Remote_operations operation;
+ rtems_event_set event_in;
+} Event_MP_Packet;
+
+/*
+ * @brief Event_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ *
+ * @note This routine is not needed since there are no process
+ * packets to be sent by this manager.
+ */
+
+/**
+ * @brief Event_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Event_MP_Send_request_packet (
+ Event_MP_Remote_operations operation,
+ Objects_Id event_id,
+ rtems_event_set event_in
+);
+
+/**
+ * @brief Event_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _Event_MP_Send_response_packet (
+ Event_MP_Remote_operations operation,
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief Event_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Event_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/*
+ * @brief Event_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ */
+
+/*
+ * @brief Event_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ */
+
+/**
+ * @brief Event_MP_Get_packet
+ *
+ * This function is used to obtain a event mp packet.
+ */
+Event_MP_Packet *_Event_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/eventset.h b/cpukit/rtems/include/rtems/rtems/eventset.h
new file mode 100644
index 0000000000..679934f22b
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/eventset.h
@@ -0,0 +1,135 @@
+/**
+ * @file rtems/rtems/eventset.h
+ *
+ * This include file contains the information pertaining to the
+ * Event Sets Handler. This handler provides methods for the manipulation
+ * of event sets which will be sent and received by tasks.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_EVENTSET_H
+#define _RTEMS_RTEMS_EVENTSET_H
+
+/**
+ * @defgroup ClassicEventSet Event Sets
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality related to Classic API
+ * Event Sets. These are used by the Classic API Event Manager.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following defines the type used to control event sets.
+ */
+typedef uint32_t rtems_event_set;
+
+/**
+ * The following constant is used to receive the set of currently pending
+ * events.
+ */
+#define RTEMS_PENDING_EVENTS 0
+
+/**
+ * The following constant is used when you wish to send or receive all
+ * events.
+ */
+#define RTEMS_ALL_EVENTS 0xFFFFFFFF
+
+/** This defines the bit in the event set associated with event 0. */
+#define RTEMS_EVENT_0 0x00000001
+/** This defines the bit in the event set associated with event 1. */
+#define RTEMS_EVENT_1 0x00000002
+/** This defines the bit in the event set associated with event 2. */
+#define RTEMS_EVENT_2 0x00000004
+/** This defines the bit in the event set associated with event 3. */
+#define RTEMS_EVENT_3 0x00000008
+/** This defines the bit in the event set associated with event 4. */
+#define RTEMS_EVENT_4 0x00000010
+/** This defines the bit in the event set associated with event 5. */
+#define RTEMS_EVENT_5 0x00000020
+/** This defines the bit in the event set associated with event 6. */
+#define RTEMS_EVENT_6 0x00000040
+/** This defines the bit in the event set associated with event 7. */
+#define RTEMS_EVENT_7 0x00000080
+/** This defines the bit in the event set associated with event 8. */
+#define RTEMS_EVENT_8 0x00000100
+/** This defines the bit in the event set associated with event 9. */
+#define RTEMS_EVENT_9 0x00000200
+/** This defines the bit in the event set associated with event 10. */
+#define RTEMS_EVENT_10 0x00000400
+/** This defines the bit in the event set associated with event 11. */
+#define RTEMS_EVENT_11 0x00000800
+/** This defines the bit in the event set associated with event 12. */
+#define RTEMS_EVENT_12 0x00001000
+/** This defines the bit in the event set associated with event 13. */
+#define RTEMS_EVENT_13 0x00002000
+/** This defines the bit in the event set associated with event 14. */
+#define RTEMS_EVENT_14 0x00004000
+/** This defines the bit in the event set associated with event 15. */
+#define RTEMS_EVENT_15 0x00008000
+/** This defines the bit in the event set associated with event 16. */
+#define RTEMS_EVENT_16 0x00010000
+/** This defines the bit in the event set associated with event 17. */
+#define RTEMS_EVENT_17 0x00020000
+/** This defines the bit in the event set associated with event 18. */
+#define RTEMS_EVENT_18 0x00040000
+/** This defines the bit in the event set associated with event 19. */
+#define RTEMS_EVENT_19 0x00080000
+/** This defines the bit in the event set associated with event 20. */
+#define RTEMS_EVENT_20 0x00100000
+/** This defines the bit in the event set associated with event 21. */
+#define RTEMS_EVENT_21 0x00200000
+/** This defines the bit in the event set associated with event 22. */
+#define RTEMS_EVENT_22 0x00400000
+/** This defines the bit in the event set associated with event 23. */
+#define RTEMS_EVENT_23 0x00800000
+/** This defines the bit in the event set associated with event 24. */
+#define RTEMS_EVENT_24 0x01000000
+/** This defines the bit in the event set associated with event 25. */
+#define RTEMS_EVENT_25 0x02000000
+/** This defines the bit in the event set associated with event 26. */
+#define RTEMS_EVENT_26 0x04000000
+/** This defines the bit in the event set associated with event 27. */
+#define RTEMS_EVENT_27 0x08000000
+/** This defines the bit in the event set associated with event 29. */
+#define RTEMS_EVENT_28 0x10000000
+/** This defines the bit in the event set associated with event 29. */
+#define RTEMS_EVENT_29 0x20000000
+/** This defines the bit in the event set associated with event 30. */
+#define RTEMS_EVENT_30 0x40000000
+/** This defines the bit in the event set associated with event 31. */
+#define RTEMS_EVENT_31 0x80000000
+
+/**
+ * The following constant is the value of an event set which
+ * has no events pending.
+ */
+#define EVENT_SETS_NONE_PENDING 0
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/eventset.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/intr.h b/cpukit/rtems/include/rtems/rtems/intr.h
new file mode 100644
index 0000000000..9b0b1b4608
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/intr.h
@@ -0,0 +1,136 @@
+/**
+ * @file rtems/rtems/intr.h
+ *
+ * @brief Header file for the Interrupt Manager.
+ *
+ * This include file contains all the constants and structures associated with
+ * the Interrupt Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_INTR_H
+#define _RTEMS_RTEMS_INTR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/isr.h>
+
+/**
+ * @defgroup ClassicINTR Interrupts
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * @brief Interrupt level type.
+ */
+typedef ISR_Level rtems_interrupt_level;
+
+/**
+ * @brief Control block type used to manage the vectors.
+ */
+typedef ISR_Vector_number rtems_vector_number;
+
+/**
+ * @brief Return type for interrupt handler.
+ */
+typedef void rtems_isr;
+
+/**
+ * @brief Interrupt handler type.
+ *
+ * @see rtems_interrupt_catch()
+ */
+typedef rtems_isr ( *rtems_isr_entry )(
+ rtems_vector_number
+ );
+
+#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
+/**
+ * @brief Implementation of the rtems_interrupt_catch directive.
+ *
+ * This directive installs @a new_isr_handler as the RTEMS interrupt service
+ * routine for the interrupt vector with number @a vector. The previous RTEMS
+ * interrupt service routine is returned in @a old_isr_handler.
+ */
+rtems_status_code rtems_interrupt_catch(
+ rtems_isr_entry new_isr_handler,
+ rtems_vector_number vector,
+ rtems_isr_entry *old_isr_handler
+);
+#endif
+
+/**
+ * @brief Disables all maskable interrupts and returns the previous level in
+ * @a _isr_cookie.
+ *
+ * @note The interrupt level shall be of type @ref rtems_interrupt_level.
+ */
+#define rtems_interrupt_disable( _isr_cookie ) \
+ _ISR_Disable(_isr_cookie)
+
+/**
+ * @brief Enables maskable interrupts to the level indicated by @a
+ * _isr_cookie.
+ *
+ * @note The interrupt level shall be of type @ref rtems_interrupt_level.
+ */
+#define rtems_interrupt_enable( _isr_cookie ) \
+ _ISR_Enable(_isr_cookie)
+
+/**
+ * @brief Temporarily enables maskable interrupts to the level in @a
+ * _isr_cookie before redisabling them.
+ *
+ * @note The interrupt level shall be of type @ref rtems_interrupt_level.
+ */
+#define rtems_interrupt_flash( _isr_cookie ) \
+ _ISR_Flash(_isr_cookie)
+
+/**
+ * @brief Returns true if the processor is currently servicing an interrupt
+ * and false otherwise.
+ *
+ * A return value of true indicates that the caller is an interrupt service
+ * routine and @b not a thread. The directives available to an interrupt
+ * service routine are restricted.
+ */
+#define rtems_interrupt_is_in_progress() \
+ _ISR_Is_in_progress()
+
+/**
+ * @brief This routine generates an interrupt.
+ *
+ * @note No implementation.
+ */
+#define rtems_interrupt_cause( _interrupt_to_cause )
+
+/**
+ * @brief This routine clears the specified interrupt.
+ *
+ * @note No implementation.
+ */
+#define rtems_interrupt_clear( _interrupt_to_clear )
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/message.h b/cpukit/rtems/include/rtems/rtems/message.h
new file mode 100644
index 0000000000..c56cc220a1
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/message.h
@@ -0,0 +1,313 @@
+/**
+ * @file rtems/rtems/message.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Message Queue Manager. This manager provides a mechanism for
+ * communication and synchronization between tasks using messages.
+ *
+ * Directives provided are:
+ *
+ * - create a queue
+ * - get ID of a queue
+ * - delete a queue
+ * - put a message at the rear of a queue
+ * - put a message at the front of a queue
+ * - broadcast N messages to a queue
+ * - receive message from a queue
+ * - flush all messages on a queue
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_MESSAGE_H
+#define _RTEMS_RTEMS_MESSAGE_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_MESSAGE_EXTERN
+#define RTEMS_MESSAGE_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/coremsg.h>
+
+/**
+ * @defgroup ClassicMessageQueue Message Queues
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following enumerated type details the modes in which a message
+ * may be submitted to a message queue. The message may be posted
+ * in a send or urgent fashion.
+ */
+typedef enum {
+ /**
+ * This value indicates the user wants to send the message using the
+ * normal message insertion protocol (FIFO or priority).
+ */
+ MESSAGE_QUEUE_SEND_REQUEST = 0,
+ /**
+ * This value indicates the user considers the message to be urgent
+ * and wants it inserted at the head of the pending message queue.
+ */
+ MESSAGE_QUEUE_URGENT_REQUEST = 1
+} Message_queue_Submit_types;
+
+/**
+ * The following records define the control block used to manage
+ * each message queue.
+ */
+typedef struct {
+ /** This field is the inherited object characteristics. */
+ Objects_Control Object;
+ /** This field is the attribute set as defined by the API. */
+ rtems_attribute attribute_set;
+ /** This field is the instance of the SuperCore Message Queue. */
+ CORE_message_queue_Control message_queue;
+} Message_queue_Control;
+
+/**
+ * The following defines the information control block used to
+ * manage this class of objects.
+ */
+RTEMS_MESSAGE_EXTERN Objects_Information _Message_queue_Information;
+
+/**
+ * @brief Message_queue_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Message_queue_Manager_initialization(void);
+
+/**
+ * @brief rtems_message_queue_create
+ *
+ * This routine implements the rtems_message_queue_create directive. The
+ * message queue will have the name name. If the attribute_set indicates
+ * that the message queue is to be limited in the number of messages
+ * that can be outstanding, then count indicates the maximum number of
+ * messages that will be held. It returns the id of the created
+ * message queue in ID.
+ */
+rtems_status_code rtems_message_queue_create(
+ rtems_name name,
+ uint32_t count,
+ size_t max_message_size,
+ rtems_attribute attribute_set,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_message_queue_ident
+ *
+ * This routine implements the rtems_message_queue_ident directive.
+ * This directive returns the message queue ID associated with NAME.
+ * If more than one message queue is named name, then the message
+ * queue to which the ID belongs is arbitrary. node indicates the
+ * extent of the search for the ID of the message queue named name.
+ * The search can be limited to a particular node or allowed to
+ * encompass all nodes.
+ */
+rtems_status_code rtems_message_queue_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_message_queue_delete
+ *
+ * This routine implements the rtems_message_queue_delete directive. The
+ * message queue indicated by ID is deleted.
+ */
+rtems_status_code rtems_message_queue_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_message_queue_send
+ *
+ * This routine implements the rtems_message_queue_send directive.
+ * This directive sends the message buffer to the message queue
+ * indicated by ID. If one or more tasks is blocked waiting
+ * to receive a message from this message queue, then one will
+ * receive the message. The task selected to receive the
+ * message is based on the task queue discipline algorithm in
+ * use by this particular message queue. If no tasks are waiting,
+ * then the message buffer will be placed at the REAR of the
+ * chain of pending messages for this message queue.
+ */
+rtems_status_code rtems_message_queue_send(
+ rtems_id id,
+ const void *buffer,
+ size_t size
+);
+
+/**
+ * @brief rtems_message_queue_urgent
+ *
+ * This routine implements the rtems_message_queue_urgent directive.
+ * This directive has the same behavior as rtems_message_queue_send
+ * except that if no tasks are waiting, the message buffer will
+ * be placed at the FRONT of the chain of pending messages rather
+ * than at the REAR.
+ */
+rtems_status_code rtems_message_queue_urgent(
+ rtems_id id,
+ const void *buffer,
+ size_t size
+);
+
+/**
+ * @brief rtems_message_queue_broadcast
+ *
+ * This routine implements the rtems_message_queue_broadcast directive.
+ * This directive sends the message buffer to all of the tasks blocked
+ * waiting for a message on the message queue indicated by ID.
+ * If no tasks are waiting, then the message buffer will not be queued.
+ */
+rtems_status_code rtems_message_queue_broadcast(
+ rtems_id id,
+ const void *buffer,
+ size_t size,
+ uint32_t *count
+);
+
+/**
+ * @brief rtems_message_queue_receive
+ *
+ * This routine implements the rtems_message_queue_receive directive.
+ * This directive is invoked when the calling task wishes to receive
+ * a message from the message queue indicated by ID. The received
+ * message is to be placed in buffer. If no messages are outstanding
+ * and the option_set indicates that the task is willing to block,
+ * then the task will be blocked until a message arrives or until,
+ * optionally, timeout clock ticks have passed.
+ */
+rtems_status_code rtems_message_queue_receive(
+ rtems_id id,
+ void *buffer,
+ size_t *size,
+ rtems_option option_set,
+ rtems_interval timeout
+);
+
+/**
+ * @brief rtems_message_queue_flush
+ *
+ * This routine implements the rtems_message_queue_flush directive.
+ * This directive takes all outstanding messages for the message
+ * queue indicated by ID and returns them to the inactive message
+ * chain. The number of messages flushed is returned in COUNT.
+ */
+rtems_status_code rtems_message_queue_flush(
+ rtems_id id,
+ uint32_t *count
+);
+
+/**
+ * @brief rtems_message_queue_get_number_pending
+ *
+ * This routine implements the rtems_message_queue_get_number_pending
+ * directive. This directive returns the number of pending
+ * messages for the message queue indicated by ID
+ * chain. The number of messages pending is returned in COUNT.
+ */
+rtems_status_code rtems_message_queue_get_number_pending(
+ rtems_id id,
+ uint32_t *count
+);
+
+
+/**
+ * @brief Message_queue_Submit
+ *
+ * This routine implements the directives rtems_message_queue_send
+ * and rtems_message_queue_urgent. It processes a message that is
+ * to be submitted to the designated message queue. The message will
+ * either be processed as a send send message which it will be inserted
+ * at the rear of the queue or it will be processed as an urgent message
+ * which will be inserted at the front of the queue.
+ */
+rtems_status_code _Message_queue_Submit(
+ rtems_id id,
+ const void *buffer,
+ size_t size,
+ Message_queue_Submit_types submit_type
+);
+
+/**
+ * @brief Message_queue_Allocate
+ *
+ * This function allocates a message queue control block from
+ * the inactive chain of free message queue control blocks.
+ */
+Message_queue_Control *_Message_queue_Allocate (void);
+
+/**
+ * @brief Message_queue_Translate_core_message_queue_return_code
+ *
+ * This function returns a RTEMS status code based on the core message queue
+ * status code specified.
+ */
+rtems_status_code _Message_queue_Translate_core_message_queue_return_code (
+ uint32_t the_message_queue_status
+);
+
+#if defined(RTEMS_MULTIPROCESSING)
+/**
+ * @brief Message_queue_Core_message_queue_mp_support
+ *
+ * Input parameters:
+ * the_thread - the remote thread the message was submitted to
+ * id - id of the message queue
+ *
+ * Output parameters: NONE
+ */
+void _Message_queue_Core_message_queue_mp_support (
+ Thread_Control *the_thread,
+ rtems_id id
+);
+#endif
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/message.inl>
+#endif
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/msgmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/modes.h b/cpukit/rtems/include/rtems/rtems/modes.h
new file mode 100644
index 0000000000..0665d17c8b
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/modes.h
@@ -0,0 +1,111 @@
+/**
+ * @file rtems/rtems/modes.h
+ *
+ * This include file contains all constants and structures associated
+ * with the RTEMS thread and RTEMS_ASR modes.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_MODES_H
+#define _RTEMS_RTEMS_MODES_H
+
+/**
+ * @defgroup ClassicModes Modes
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/isr.h>
+
+/**
+ * The following type defines the control block used to manage
+ * each a mode set.
+ */
+typedef uint32_t Modes_Control;
+
+/**
+ * The following constants define the individual modes and masks
+ * which may be used to compose a mode set and to alter modes.
+ */
+#define RTEMS_ALL_MODE_MASKS 0x0000ffff
+
+/**
+ * This mode constant is the default mode set.
+ */
+#define RTEMS_DEFAULT_MODES 0x00000000
+
+/**
+ * This mode constant is used when the user wishes to obtain their
+ * current execution mode.
+ */
+#define RTEMS_CURRENT_MODE 0
+
+/** This mode constant corresponds to the timeslice enable/disable bit. */
+#define RTEMS_TIMESLICE_MASK 0x00000200
+
+/** This mode constant corresponds to the preemption enable/disable bit. */
+#define RTEMS_PREEMPT_MASK 0x00000100
+
+/** This mode constant corresponds to the signal enable/disable bit. */
+#define RTEMS_ASR_MASK 0x00000400
+
+/** This mode constant corresponds to the interrupt enable/disable bits. */
+#define RTEMS_INTERRUPT_MASK CPU_MODES_INTERRUPT_MASK
+
+/** This mode constant is used to indicate preemption is enabled. */
+#define RTEMS_PREEMPT 0x00000000
+/** This mode constant is used to indicate preemption is disabled. */
+#define RTEMS_NO_PREEMPT 0x00000100
+
+/** This mode constant is used to indicate timeslicing is disabled. */
+#define RTEMS_NO_TIMESLICE 0x00000000
+/** This mode constant is used to indicate timeslicing is enabled. */
+#define RTEMS_TIMESLICE 0x00000200
+
+/** This mode constant is used to indicate signal processing is enabled. */
+#define RTEMS_ASR 0x00000000
+/** This mode constant is used to indicate signal processing is disabled. */
+#define RTEMS_NO_ASR 0x00000400
+
+/**
+ * @brief RTEMS_INTERRUPT_LEVEL
+ *
+ * This function returns the processor dependent interrupt
+ * level which corresponds to the requested interrupt level.
+ *
+ * @note RTEMS supports 256 interrupt levels using the least
+ * significant eight bits of MODES.CONTROL. On any
+ * particular CPU, fewer than 256 levels may be supported.
+ */
+#define RTEMS_INTERRUPT_LEVEL( _mode_set ) \
+ ( (_mode_set) & RTEMS_INTERRUPT_MASK )
+
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/modes.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/mp.h b/cpukit/rtems/include/rtems/rtems/mp.h
new file mode 100644
index 0000000000..1f8252aac3
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/mp.h
@@ -0,0 +1,57 @@
+/**
+ * @file rtems/rtems/mp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_MP_H
+#define _RTEMS_RTEMS_MP_H
+
+/**
+ * @defgroup ClassicMP Multiprocessing
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Multiprocessing_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Multiprocessing_Manager_initialization ( void );
+
+/**
+ * @brief rtems_multiprocessing_announce
+ *
+ * This routine implements the MULTIPROCESSING_ANNOUNCE directive.
+ * It is invoked by the MPCI layer to indicate that an MPCI packet
+ * has been received.
+ */
+void rtems_multiprocessing_announce ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/msgmp.h b/cpukit/rtems/include/rtems/rtems/msgmp.h
new file mode 100644
index 0000000000..8aa5f533ae
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/msgmp.h
@@ -0,0 +1,166 @@
+/**
+ * @file rtems/rtems/msgmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Message Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_MSGMP_H
+#define _RTEMS_RTEMS_MSGMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/message.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * @defgroup ClassicMsgMP Message Queue MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**{*/
+
+/**
+ * The following enumerated type defines the list of
+ * remote message queue operations.
+ */
+typedef enum {
+ MESSAGE_QUEUE_MP_ANNOUNCE_CREATE = 0,
+ MESSAGE_QUEUE_MP_ANNOUNCE_DELETE = 1,
+ MESSAGE_QUEUE_MP_EXTRACT_PROXY = 2,
+ MESSAGE_QUEUE_MP_RECEIVE_REQUEST = 3,
+ MESSAGE_QUEUE_MP_RECEIVE_RESPONSE = 4,
+ MESSAGE_QUEUE_MP_SEND_REQUEST = 5,
+ MESSAGE_QUEUE_MP_SEND_RESPONSE = 6,
+ MESSAGE_QUEUE_MP_URGENT_REQUEST = 7,
+ MESSAGE_QUEUE_MP_URGENT_RESPONSE = 8,
+ MESSAGE_QUEUE_MP_BROADCAST_REQUEST = 9,
+ MESSAGE_QUEUE_MP_BROADCAST_RESPONSE = 10,
+ MESSAGE_QUEUE_MP_FLUSH_REQUEST = 11,
+ MESSAGE_QUEUE_MP_FLUSH_RESPONSE = 12,
+ MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST = 13,
+ MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE = 14
+} Message_queue_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote message queue operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Message_queue_MP_Remote_operations operation;
+ rtems_name name;
+ rtems_option option_set;
+ Objects_Id proxy_id;
+ uint32_t count;
+ size_t size;
+ uint32_t pad0;
+ CORE_message_queue_Buffer Buffer;
+} Message_queue_MP_Packet;
+
+/**
+ * @brief _Message_queue_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ */
+void _Message_queue_MP_Send_process_packet (
+ Message_queue_MP_Remote_operations operation,
+ Objects_Id message_queue_id,
+ rtems_name name,
+ Objects_Id proxy_id
+);
+
+/**
+ * @brief _Message_queue_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Message_queue_MP_Send_request_packet (
+ Message_queue_MP_Remote_operations operation,
+ Objects_Id message_queue_id,
+ const void *buffer,
+ size_t *size_p,
+ rtems_option option_set,
+ rtems_interval timeout
+);
+
+/**
+ * @brief _Message_queue_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _Message_queue_MP_Send_response_packet (
+ Message_queue_MP_Remote_operations operation,
+ Objects_Id message_queue_id,
+ Thread_Control *the_thread
+);
+
+/**
+ *
+ @brief * _Message_queue_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Message_queue_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/**
+ * @brief _Message_queue_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ */
+void _Message_queue_MP_Send_object_was_deleted (
+ Thread_Control *the_proxy
+);
+
+/**
+ * @brief _Message_queue_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ */
+void _Message_queue_MP_Send_extract_proxy (
+ void *argument
+);
+
+/**
+ * @brief _Message_queue_MP_Get_packet
+ *
+ * This function is used to obtain a message queue mp packet.
+ */
+Message_queue_MP_Packet *_Message_queue_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/object.h b/cpukit/rtems/include/rtems/rtems/object.h
new file mode 100644
index 0000000000..72d65c6562
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/object.h
@@ -0,0 +1,356 @@
+/**
+ * @file rtems/rtems/object.h
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_OBJECT_H
+#define _RTEMS_RTEMS_OBJECT_H
+
+#include <stdint.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicClassInfo Object Class Information
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * This structure is used to return information to the application
+ * about the objects configured for a specific API/Class combination.
+ */
+typedef struct {
+ /** This field is the minimum valid object Id for this class. */
+ rtems_id minimum_id;
+ /** This field is the maximum valid object Id for this class. */
+ rtems_id maximum_id;
+ /** This field is the number of object instances configured for this class. */
+ uint32_t maximum;
+ /** This field indicates if the class is configured for auto-extend. */
+ bool auto_extend;
+ /** This field is the number of currently unallocated objects. */
+ uint32_t unallocated;
+} rtems_object_api_class_information;
+
+/**
+ * @brief Build Object Id
+ *
+ * This function returns an object id composed of the
+ * specified @a api, @a class, @a node,
+ * and @a index.
+ *
+ * @param[in] _api indicates the api to use for the Id
+ * @param[in] _class indicates the class to use for the Id
+ * @param[in] _node indicates the node to use for the Id
+ * @param[in] _index indicates the index to use for the Id
+ *
+ * @return This method returns an object Id built from the
+ * specified values.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_build_id( _api, _class, _node, _index ) \
+ _Objects_Build_id( _api, _class, _node, _index )
+
+/**
+ * @brief Build Thirty-Two Bit Object Name
+ *
+ * This function returns an object name composed of the four characters
+ * C1, C2, C3, and C4.
+ *
+ * @param[in] _C1 is the first character of the name
+ * @param[in] _C2 is the second character of the name
+ * @param[in] _C3 is the third character of the name
+ * @param[in] _C4 is the fourth character of the name
+ *
+ * @note This must be implemented as a macro for use in
+ * Configuration Tables. A body is also provided.
+ *
+ */
+#define rtems_build_name( _C1, _C2, _C3, _C4 ) \
+ _Objects_Build_name( _C1, _C2, _C3, _C4 )
+
+/** @brief Obtain name of object
+ *
+ * This directive returns the name associated with the specified
+ * object ID.
+ *
+ * @param[in] id is the Id of the object to obtain the name of.
+ * @param[out] name will be set to the name of the object
+ *
+ * @note The object must be have a name of the 32-bit form.
+ *
+ * @return @a *name will contain user defined object name
+ * @return @a RTEMS_SUCCESSFUL - if successful
+ * @return error code - if unsuccessful
+ */
+rtems_status_code rtems_object_get_classic_name(
+ rtems_id id,
+ rtems_name *name
+);
+
+/**
+ * @brief Obtain Object Name as String
+ *
+ * This directive returns the name associated with the specified
+ * object ID.
+ *
+ * @param[in] id is the Id of the object to obtain the name of
+ * @param[in] length is the length of the output name buffer
+ * @param[out] name will be set to the name of the object
+ *
+ * @return @a *name will contain user defined object name
+ * @return @a name - if successful
+ * @return @a NULL - if unsuccessful
+ */
+char *rtems_object_get_name(
+ rtems_id id,
+ size_t length,
+ char *name
+);
+
+/**
+ * @brief Set Name of Object
+ *
+ * This method allows the caller to set the name of an
+ * object. This can be used to set the name of objects
+ * which do not have a naming scheme per their API.
+ *
+ * @param[in] id is the Id of the object to obtain the name of
+ * @param[out] name will be set to the name of the object
+ *
+ * @return @a *name will contain user defined object name
+ * @return @a RTEMS_SUCCESSFUL - if successful
+ * @return error code - if unsuccessful
+ */
+rtems_status_code rtems_object_set_name(
+ rtems_id id,
+ const char *name
+);
+
+/**
+ * @brief Get API Portion of Object Id
+ *
+ * This function returns the API portion of the Id.
+ *
+ * @param[in] _id is the Id of the object to obtain the API from
+ *
+ * @return This method returns the API portion of the provided
+ * @a _id.
+ *
+ * @note This method does NOT validate the @a _id provided.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_object_id_get_api( _id ) \
+ _Objects_Get_API( _id )
+
+/**
+ * @brief Get Class Portion of Object Id
+ *
+ * This function returns the class portion of the ID.
+ *
+ * @param[in] _id is the Id of the object to obtain the class from
+ *
+ * @return This method returns the class portion of the provided
+ * @a _id.
+ *
+ * @note This method does NOT validate the @a _id provided.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_object_id_get_class( _id ) \
+ _Objects_Get_class( _id )
+
+/**
+ * @brief Get Node Portion of Object Id
+ *
+ * This function returns the node portion of the ID.
+ *
+ * @param[in] _id is the Id of the object to obtain the node from
+ *
+ * @return This method returns the node portion of the provided
+ * @a _id.
+ *
+ * @note This method does NOT validate the @a _id provided.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_object_id_get_node( _id ) \
+ _Objects_Get_node( _id )
+
+/**
+ * @brief Get Index Portion of Object Id
+ *
+ * This function returns the index portion of the ID.
+ *
+ * @param[in] _id is the Id of the object to obtain the index from
+ *
+ * @return This method returns the index portion of the provided
+ * @a _id.
+ *
+ * @note This method does NOT validate the @a _id provided.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_object_id_get_index( _id ) \
+ _Objects_Get_index( _id )
+
+/**
+ * @brief Get Lowest Valid API Index
+ *
+ * This method returns the lowest valid value for the API
+ * portion of an RTEMS object Id.
+ *
+ * @return This method returns the least valid value for
+ * the API portion of an RTEMS object Id.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_object_id_api_minimum() \
+ OBJECTS_INTERNAL_API
+
+/**
+ * @brief Get Highest Valid API Index
+ *
+ * This method returns the highest valid value for the API
+ * portion of an RTEMS object Id.
+ *
+ * @return This method returns the greatest valid value for
+ * the API portion of an RTEMS object Id.
+ *
+ * @note A body is also provided.
+ */
+#define rtems_object_id_api_maximum() \
+ OBJECTS_APIS_LAST
+
+/**
+ * @brief Get Lowest Valid Class Value
+ *
+ * This method returns the lowest valid value Class for the
+ * specified @a api. Each API supports a different number
+ * of object classes.
+ *
+ * @param[in] api is the API to obtain the minimum class of
+ *
+ * @return This method returns the least valid value for
+ * class number for the specified @a api.
+ */
+int rtems_object_api_minimum_class(
+ int api
+);
+
+/**
+ * @brief Get Highest Valid Class Value
+ *
+ * This method returns the highest valid value Class for the
+ * specified @a api. Each API supports a different number
+ * of object classes.
+ *
+ * @param[in] api is the API to obtain the maximum class of
+ *
+ * @return This method returns the greatet valid value for
+ * class number for the specified @a api.
+ */
+int rtems_object_api_maximum_class(
+ int api
+);
+
+
+/**
+ * @brief Get Highest Valid Class Value
+ *
+ * This method returns the lowest valid value Class for the
+ * specified @a api. Each API supports a different number
+ * of object classes.
+ *
+ * @param[in] api is the API to obtain the maximum class of
+ *
+ * @return This method returns the least valid value for
+ * class number for the specified @a api.
+ */
+int rtems_object_id_api_maximum_class(
+ int api
+);
+
+/**
+ * @brief Get API Name
+ *
+ * This method returns a string containing the name of the
+ * specified @a api.
+ *
+ * @param[in] api is the API to obtain the name of
+ *
+ * @return If successful, this method returns the name of
+ * the specified @a api. Otherwise, it returns
+ * the string "BAD API"
+ */
+const char *rtems_object_get_api_name(
+ int api
+);
+
+/**
+ * @brief Get Class Name
+ *
+ * This method returns a string containing the name of the
+ * @a class from the specified @a api.
+ *
+ * @param[in] the_api is the API for the class
+ * @param[in] the_class is the class to obtain the name of
+ *
+ * @return If successful, this method returns the name of
+ * the specified @a class. Otherwise, it returns
+ * the string "BAD CLASS"
+ */
+const char *rtems_object_get_api_class_name(
+ int the_api,
+ int the_class
+);
+
+/**
+ * @brief Get Class Name
+ *
+ * This method returns a string containing the name of the
+ * @a the_class from the specified @a api.
+ *
+ * @param[in] the_api is the API for the class
+ * @param[in] the_class is the class to obtain information about
+ * @param[in] info points to the information structure to fill in
+ *
+ * @return If successful, this method returns the name of
+ * RTEMS_SUCCESSFUL with @a *info filled in. Otherwise,
+ * a status is returned to indicate the error.
+ *
+ */
+rtems_status_code rtems_object_get_class_information(
+ int the_api,
+ int the_class,
+ rtems_object_api_class_information *info
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/options.h b/cpukit/rtems/include/rtems/rtems/options.h
new file mode 100644
index 0000000000..240854519c
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/options.h
@@ -0,0 +1,78 @@
+/**
+ * @file rtems/rtems/options.h
+ *
+ * This include file contains information which defines the
+ * options available on many directives.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_OPTIONS_H
+#define _RTEMS_RTEMS_OPTIONS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicOptions Classic API Options
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following type defines the control block used to manage
+ * option sets.
+ */
+typedef uint32_t rtems_option;
+
+/**
+ * The following constants define the individual options which may
+ * be used to compose an option set.
+ */
+#define RTEMS_DEFAULT_OPTIONS 0x00000000
+
+/**
+ * This option constants indicates that the task is to wait on resource.
+ */
+#define RTEMS_WAIT 0x00000000
+/**
+ * This option constants indicates that the task is to not wait on
+ * the resource. If it is not available, return immediately with
+ * a status to indicate unsatisfied.
+ */
+#define RTEMS_NO_WAIT 0x00000001
+
+/**
+ * This option constants indicates that the task wishes to wait until
+ * all events of interest are available.
+ */
+#define RTEMS_EVENT_ALL 0x00000000
+
+/**
+ * This option constants indicates that the task wishes to wait until
+ * ANY events of interest are available.
+ */
+#define RTEMS_EVENT_ANY 0x00000002
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/options.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/part.h b/cpukit/rtems/include/rtems/rtems/part.h
new file mode 100644
index 0000000000..3d3d2938ab
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/part.h
@@ -0,0 +1,180 @@
+/**
+ * @file rtems/rtems/part.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Partition Manager. This manager provides facilities to
+ * dynamically allocate memory in fixed-sized units which are returned
+ * as buffers.
+ *
+ * Directives provided are:
+ *
+ * - create a partition
+ * - get an ID of a partition
+ * - delete a partition
+ * - get a buffer from a partition
+ * - return a buffer to a partition
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_PART_H
+#define _RTEMS_RTEMS_PART_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_PART_EXTERN
+#define RTEMS_PART_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/types.h>
+
+/**
+ * @defgroup ClassicPart Partitions
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality related to the
+ * Classic API Partition Manager.
+ */
+/**@{*/
+
+/**
+ * The following defines the control block used to manage each partition.
+ */
+typedef struct {
+ /** This field is the object management portion of a Partition instance. */
+ Objects_Control Object;
+ /** This field is the physical starting address of the Partition. */
+ void *starting_address;
+ /** This field is the size of the Partition in bytes. */
+ intptr_t length;
+ /** This field is the size of each buffer in bytes */
+ uint32_t buffer_size;
+ /** This field is the attribute set provided at create time. */
+ rtems_attribute attribute_set;
+ /** This field is the of allocated buffers. */
+ uint32_t number_of_used_blocks;
+ /** This field is the chain used to manage unallocated buffers. */
+ Chain_Control Memory;
+} Partition_Control;
+
+/**
+ * The following defines the information control block used to
+ * manage this class of objects.
+ */
+RTEMS_PART_EXTERN Objects_Information _Partition_Information;
+
+/**
+ * @brief Partition_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Partition_Manager_initialization(void);
+
+/**
+ * @brief rtems_partition_create
+ *
+ * This routine implements the rtems_partition_create directive. The
+ * partition will have the name name. The memory area managed by
+ * the partition is of length bytes and starts at starting_address.
+ * The memory area will be divided into as many buffers of
+ * buffer_size bytes as possible. The attribute_set determines if
+ * the partition is global or local. It returns the id of the
+ * created partition in ID.
+ */
+rtems_status_code rtems_partition_create(
+ rtems_name name,
+ void *starting_address,
+ uint32_t length,
+ uint32_t buffer_size,
+ rtems_attribute attribute_set,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_partition_ident
+ *
+ * This routine implements the rtems_partition_ident directive.
+ * This directive returns the partition ID associated with name.
+ * If more than one partition is named name, then the partition
+ * to which the ID belongs is arbitrary. node indicates the
+ * extent of the search for the ID of the partition named name.
+ * The search can be limited to a particular node or allowed to
+ * encompass all nodes.
+ */
+rtems_status_code rtems_partition_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_partition_delete
+ *
+ * This routine implements the rtems_partition_delete directive. The
+ * partition indicated by ID is deleted.
+ */
+rtems_status_code rtems_partition_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_partition_get_buffer
+ *
+ * This routine implements the rtems_partition_get_buffer directive. It
+ * attempts to allocate a buffer from the partition associated with ID.
+ * If a buffer is allocated, its address is returned in buffer.
+ */
+rtems_status_code rtems_partition_get_buffer(
+ rtems_id id,
+ void **buffer
+);
+
+/**
+ * @brief rtems_partition_return_buffer
+ *
+ * This routine implements the rtems_partition_return_buffer directive. It
+ * frees the buffer to the partition associated with ID. The buffer must
+ * have been previously allocated from the same partition.
+ */
+rtems_status_code rtems_partition_return_buffer(
+ rtems_id id,
+ void *buffer
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/part.inl>
+#endif
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/partmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/partmp.h b/cpukit/rtems/include/rtems/rtems/partmp.h
new file mode 100644
index 0000000000..f36f0e259c
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/partmp.h
@@ -0,0 +1,151 @@
+/**
+ * @file rtems/rtems/partmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Partition Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_PARTMP_H
+#define _RTEMS_RTEMS_PARTMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/thread.h>
+
+#include <rtems/rtems/part.h>
+
+/**
+ * @defgroup ClassicPartMP Partition MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**{*/
+
+/**
+ * The following enumerated type defines the list of
+ * remote partition operations.
+ */
+typedef enum {
+ PARTITION_MP_ANNOUNCE_CREATE = 0,
+ PARTITION_MP_ANNOUNCE_DELETE = 1,
+ PARTITION_MP_EXTRACT_PROXY = 2,
+ PARTITION_MP_GET_BUFFER_REQUEST = 3,
+ PARTITION_MP_GET_BUFFER_RESPONSE = 4,
+ PARTITION_MP_RETURN_BUFFER_REQUEST = 5,
+ PARTITION_MP_RETURN_BUFFER_RESPONSE = 6
+} Partition_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote partition operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Partition_MP_Remote_operations operation;
+ rtems_name name;
+ void *buffer;
+ Objects_Id proxy_id;
+} Partition_MP_Packet;
+
+/**
+ * @brief Partition_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ */
+void _Partition_MP_Send_process_packet (
+ Partition_MP_Remote_operations operation,
+ Objects_Id partition_id,
+ rtems_name name,
+ Objects_Id proxy_id
+);
+
+/**
+ * @brief Partition_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Partition_MP_Send_request_packet (
+ Partition_MP_Remote_operations operation,
+ Objects_Id partition_id,
+ void *buffer
+);
+
+/**
+ * @brief Partition_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _Partition_MP_Send_response_packet (
+ Partition_MP_Remote_operations operation,
+ Objects_Id partition_id,
+ Thread_Control *the_thread
+);
+
+/**
+ *
+ * @brief Partition_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Partition_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/*
+ * @brief Partition_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed by the Partition since a partition
+ * cannot be deleted when buffers are in use.
+ */
+
+/**
+ * @brief Partition_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ */
+void _Partition_MP_Send_extract_proxy (
+ void *argument
+);
+
+/**
+ * @brief Partition_MP_Get_packet
+ *
+ * This function is used to obtain a partition mp packet.
+ */
+Partition_MP_Packet *_Partition_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/ratemon.h b/cpukit/rtems/include/rtems/rtems/ratemon.h
new file mode 100644
index 0000000000..9e0f1fda09
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/ratemon.h
@@ -0,0 +1,517 @@
+/**
+ * @file rtems/rtems/ratemon.h
+ *
+ * This include file contains all the constants, structures, and
+ * prototypes associated with the Rate Monotonic Manager. This manager
+ * provides facilities to implement threads which execute in a periodic
+ * fashion.
+ *
+ * Directives provided are:
+ *
+ * - create a rate monotonic timer
+ * - cancel a period
+ * - delete a rate monotonic timer
+ * - conclude current and start the next period
+ * - obtain status information on a period
+ */
+
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_RATEMON_H
+#define _RTEMS_RTEMS_RATEMON_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_RATEMON_EXTERN
+#define RTEMS_RATEMON_EXTERN extern
+#endif
+
+#include <rtems/bspIo.h>
+
+/**
+ * @defgroup ClassicRateMon Rate Monotonic Scheduler
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality related to the
+ * Classic API Rate Monotonic Manager.
+ *
+ * Statistics are kept for each period and can be obtained or printed via
+ * API calls. The statistics kept include minimum, maximum and average times
+ * for both cpu usage and wall time. The statistics indicate the execution time
+ * used by the owning thread between successive calls to rtems_rate_monotonic_period.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is the public type used for the rate monotonic timing
+ * statistics.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timespec.h>
+
+ typedef struct timespec rtems_rate_monotonic_period_time_t;
+#else
+ typedef uint32_t rtems_rate_monotonic_period_time_t;
+#endif
+
+/**
+ * This is the internal type used for the rate monotonic timing
+ * statistics.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timestamp.h>
+
+ typedef Timestamp_Control Rate_monotonic_Period_time_t;
+#else
+ typedef uint32_t Rate_monotonic_Period_time_t;
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+
+#include <string.h>
+
+
+/**
+ * The following enumerated type defines the states in which a
+ * period may be.
+ */
+typedef enum {
+ /**
+ * This value indicates the period is off the watchdog chain,
+ * and has never been initialized.
+ */
+ RATE_MONOTONIC_INACTIVE,
+
+ /**
+ * This value indicates the period is on the watchdog chain, and
+ * the owner is blocked waiting on it.
+ */
+ RATE_MONOTONIC_OWNER_IS_BLOCKING,
+
+ /**
+ * This value indicates the period is on the watchdog chain, and
+ * running. The owner should be executed or blocked waiting on
+ * another object.
+ */
+ RATE_MONOTONIC_ACTIVE,
+
+ /**
+ * This value indicates the period is on the watchdog chain, and
+ * has expired. The owner should be blocked waiting for the next period.
+ */
+ RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING,
+
+ /**
+ * This value indicates the period is off the watchdog chain, and
+ * has expired. The owner is still executing and has taken too much
+ * all time to complete this iteration of the period.
+ */
+ RATE_MONOTONIC_EXPIRED
+} rtems_rate_monotonic_period_states;
+
+/**
+ * The following constant is the interval passed to the rate_monontonic_period
+ * directive to obtain status information.
+ */
+#define RTEMS_PERIOD_STATUS WATCHDOG_NO_TIMEOUT
+
+/**
+ * The following defines the PUBLIC data structure that has the
+ * statistics kept on each period instance.
+ *
+ * @note The public structure uses struct timespec while the
+ * internal one uses Timestamp_Control.
+ */
+typedef struct {
+ /** This field contains the number of periods executed. */
+ uint32_t count;
+ /** This field contains the number of periods missed. */
+ uint32_t missed_count;
+
+ /** This field contains the least amount of CPU time used in a period. */
+ rtems_thread_cpu_usage_t min_cpu_time;
+ /** This field contains the highest amount of CPU time used in a period. */
+ rtems_thread_cpu_usage_t max_cpu_time;
+ /** This field contains the total amount of wall time used in a period. */
+ rtems_thread_cpu_usage_t total_cpu_time;
+
+ /** This field contains the least amount of wall time used in a period. */
+ rtems_rate_monotonic_period_time_t min_wall_time;
+ /** This field contains the highest amount of wall time used in a period. */
+ rtems_rate_monotonic_period_time_t max_wall_time;
+ /** This field contains the total amount of CPU time used in a period. */
+ rtems_rate_monotonic_period_time_t total_wall_time;
+} rtems_rate_monotonic_period_statistics;
+
+/**
+ * The following defines the INTERNAL data structure that has the
+ * statistics kept on each period instance.
+ */
+typedef struct {
+ /** This field contains the number of periods executed. */
+ uint32_t count;
+ /** This field contains the number of periods missed. */
+ uint32_t missed_count;
+
+ /** This field contains the least amount of CPU time used in a period. */
+ Thread_CPU_usage_t min_cpu_time;
+ /** This field contains the highest amount of CPU time used in a period. */
+ Thread_CPU_usage_t max_cpu_time;
+ /** This field contains the total amount of wall time used in a period. */
+ Thread_CPU_usage_t total_cpu_time;
+
+ /** This field contains the least amount of wall time used in a period. */
+ Rate_monotonic_Period_time_t min_wall_time;
+ /** This field contains the highest amount of wall time used in a period. */
+ Rate_monotonic_Period_time_t max_wall_time;
+ /** This field contains the total amount of CPU time used in a period. */
+ Rate_monotonic_Period_time_t total_wall_time;
+} Rate_monotonic_Statistics;
+
+/**
+ * The following defines the period status structure.
+ */
+typedef struct {
+ /** This is the Id of the thread using this period. */
+ rtems_id owner;
+
+ /** This is the current state of this period. */
+ rtems_rate_monotonic_period_states state;
+
+ /**
+ * This is the length of wall time that has passed since this period
+ * was last initiated. If the period is expired or has not been initiated,
+ * then this field has no meaning.
+ */
+ rtems_rate_monotonic_period_time_t since_last_period;
+
+ /**
+ * This is the amount of CPU time that has been used since this period
+ * was last initiated. If the period is expired or has not been initiated,
+ * then this field has no meaning.
+ */
+ rtems_thread_cpu_usage_t executed_since_last_period;
+} rtems_rate_monotonic_period_status;
+
+/**
+ * The following structure defines the control block used to manage
+ * each period.
+ */
+typedef struct {
+ /** This field is the object management portion of a Period instance. */
+ Objects_Control Object;
+
+ /** This is the timer used to provide the unblocking mechanism. */
+ Watchdog_Control Timer;
+
+ /** This field indicates the current state of the period. */
+ rtems_rate_monotonic_period_states state;
+
+ /**
+ * This field contains the length of the next period to be
+ * executed.
+ */
+ uint32_t next_length;
+
+ /**
+ * This field contains a pointer to the TCB for the thread
+ * which owns and uses this period instance.
+ */
+ Thread_Control *owner;
+
+ /**
+ * This field contains the cpu usage value of the owning thread when
+ * the period was initiated. It is used to compute the period's
+ * statistics.
+ */
+ Thread_CPU_usage_t cpu_usage_period_initiated;
+
+ /**
+ * This field contains the wall time value when the period
+ * was initiated. It is used to compute the period's statistics.
+ */
+ Rate_monotonic_Period_time_t time_period_initiated;
+
+ /**
+ * This field contains the statistics maintained for the period.
+ */
+ Rate_monotonic_Statistics Statistics;
+} Rate_monotonic_Control;
+
+/**
+ * @brief Rate Monotonic Period Class Management Structure
+ *
+ * This instance of Objects_Information is used to manage the
+ * set of rate monotonic period instances.
+ */
+RTEMS_RATEMON_EXTERN Objects_Information _Rate_monotonic_Information;
+
+/**
+ * @brief Rate Monotonic Manager Initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Rate_monotonic_Manager_initialization(void);
+
+/**
+ * @brief rtems_rate_monotonic_create
+ *
+ * This routine implements the rate_monotonic_create directive. The
+ * period will have the name name. It returns the id of the
+ * created period in ID.
+ */
+rtems_status_code rtems_rate_monotonic_create(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_rate_monotonic_ident
+ *
+ * This routine implements the rtems_rate_monotonic_ident directive.
+ * It returns the period ID associated with name. If more than one period
+ * is named name, then the period to which the ID belongs is arbitrary.
+ */
+rtems_status_code rtems_rate_monotonic_ident(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_rate_monotonic_cancel
+ *
+ * This routine implements the rtems_rate_monotonic_cancel directive. This
+ * directive stops the period associated with ID from continuing to
+ * run.
+ */
+rtems_status_code rtems_rate_monotonic_cancel(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_rate_monotonic_delete
+ *
+ * This routine implements the rtems_rate_monotonic_delete directive. The
+ * period indicated by ID is deleted.
+ */
+rtems_status_code rtems_rate_monotonic_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_rate_monotonic_get_status
+ *
+ * This routine implements the rtems_rate_monotonic_get_status directive.
+ * Information about the period indicated by ID is returned.
+ *
+ */
+rtems_status_code rtems_rate_monotonic_get_status(
+ rtems_id id,
+ rtems_rate_monotonic_period_status *status
+);
+
+/**
+ * @brief rtems_rate_monotonic_get_statistics
+ *
+ * This routine implements the rtems_rate_monotonic_get_statistics directive.
+ * Statistics gathered from the use of this period are returned.
+ */
+rtems_status_code rtems_rate_monotonic_get_statistics(
+ rtems_id id,
+ rtems_rate_monotonic_period_statistics *statistics
+);
+
+/**
+ * @brief rtems_rate_monotonic_reset_statistics
+ *
+ * This routine allows a thread to reset the statistics information
+ * on a specific period instance.
+ */
+rtems_status_code rtems_rate_monotonic_reset_statistics(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_rate_monotonic_reset_all_statistics
+ *
+ * This routine allows a thread to reset the statistics information
+ * on ALL period instances.
+ */
+void rtems_rate_monotonic_reset_all_statistics( void );
+
+/**
+ * @brief rtems_rate_monotonic_report_statistics
+ *
+ * This routine allows a thread to print the statistics information
+ * on ALL period instances which have non-zero counts using printk.
+ */
+void rtems_rate_monotonic_report_statistics_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+);
+
+/**
+ * @brief rtems_rate_monotonic_report_statistics
+ *
+ * This routine allows a thread to print the statistics information
+ * on ALL period instances which have non-zero counts using printk.
+ */
+void rtems_rate_monotonic_report_statistics( void );
+
+/**
+ * @brief rtems_rate_monotonic_period
+ *
+ * This routine implements the rtems_rate_monotonic_period directive. When
+ * length is non-zero, this directive initiates the period associated with
+ * ID from continuing for a period of length. If length is zero, then
+ * result is set to indicate the current state of the period.
+ */
+rtems_status_code rtems_rate_monotonic_period(
+ rtems_id id,
+ rtems_interval length
+);
+
+/**
+ * @brief _Rate_monotonic_Timeout
+ *
+ * This routine is invoked when the period represented
+ * by ID expires. If the thread which owns this period is blocked
+ * waiting for the period to expire, then it is readied and the
+ * period is restarted. If the owning thread is not waiting for the
+ * period to expire, then the period is placed in the EXPIRED
+ * state and not restarted.
+ */
+void _Rate_monotonic_Timeout(
+ rtems_id id,
+ void *ignored
+);
+
+/**
+ * @brief _Rate_monotonic_Get_status(
+ *
+ * This routine is invoked to compute the elapsed wall time and cpu
+ * time for a period.
+ *
+ * @param[in] the_period points to the period being operated upon.
+ * @param[out] wall_since_last_period is set to the wall time elapsed
+ * since the period was initiated.
+ * @param[out] cpu_since_last_period is set to the cpu time used by the
+ * owning thread since the period was initiated.
+ *
+ * @return This routine returns true if the status can be determined
+ * and false otherwise.
+ */
+bool _Rate_monotonic_Get_status(
+ Rate_monotonic_Control *the_period,
+ Rate_monotonic_Period_time_t *wall_since_last_period,
+ Thread_CPU_usage_t *cpu_since_last_period
+);
+
+/**
+ * @brief _Rate_monotonic_Initiate_statistics(
+ *
+ * This routine is invoked when a period is initiated via an explicit
+ * call to rtems_rate_monotonic_period for the period's first iteration
+ * or from _Rate_monotonic_Timeout for period iterations 2-n.
+ *
+ * @param[in] the_period points to the period being operated upon.
+ */
+void _Rate_monotonic_Initiate_statistics(
+ Rate_monotonic_Control *the_period
+);
+
+/**
+ * @brief _Rate_monotonic_Reset_wall_time_statistics
+ *
+ * This method resets the statistics information for a period instance.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) \
+ do { \
+ /* set the minimums to a large value */ \
+ _Timestamp_Set( \
+ &(_the_period)->Statistics.min_wall_time, \
+ 0x7fffffff, \
+ 0x7fffffff \
+ ); \
+ } while (0)
+#else
+ #define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) \
+ do { \
+ /* set the minimum to a large value */ \
+ (_the_period)->Statistics.min_wall_time = 0xffffffff; \
+ } while (0)
+#endif
+
+/**
+ * @brief Rate_monotonic_Reset_cpu_use_statistics
+ *
+ * This helper method resets the period CPU usage statistics structure.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) \
+ do { \
+ /* set the minimums to a large value */ \
+ _Timestamp_Set( \
+ &(_the_period)->Statistics.min_cpu_time, \
+ 0x7fffffff, \
+ 0x7fffffff \
+ ); \
+ } while (0)
+#else
+ #define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) \
+ do { \
+ /* set the minimum to a large value */ \
+ (_the_period)->Statistics.min_cpu_time = 0xffffffff; \
+ } while (0)
+#endif
+
+/**
+ * @brief Rate_monotonic_Reset_statistics
+ *
+ * This helper method resets the period wall time statistics structure.
+ */
+#define _Rate_monotonic_Reset_statistics( _the_period ) \
+ do { \
+ memset( \
+ &(_the_period)->Statistics, \
+ 0, \
+ sizeof( rtems_rate_monotonic_period_statistics ) \
+ ); \
+ _Rate_monotonic_Reset_cpu_use_statistics( _the_period ); \
+ _Rate_monotonic_Reset_wall_time_statistics( _the_period ); \
+ } while (0)
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/ratemon.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/region.h b/cpukit/rtems/include/rtems/rtems/region.h
new file mode 100644
index 0000000000..adab79b999
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/region.h
@@ -0,0 +1,292 @@
+/**
+ * @file rtems/rtems/region.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Region Manager. This manager provides facilities to dynamically
+ * allocate memory in variable sized units which are returned as segments.
+ *
+ * Directives provided are:
+ *
+ * - create a region
+ * - get an ID of a region
+ * - delete a region
+ * - get a segment from a region
+ * - return a segment to a region
+ */
+
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_REGION_H
+#define _RTEMS_RTEMS_REGION_H
+
+#include <rtems/score/object.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/heap.h>
+#include <rtems/debug.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/types.h>
+
+/**
+ * @defgroup ClassicRegion Regions
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_REGION_EXTERN
+#define RTEMS_REGION_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following records define the control block used to manage
+ * each region.
+ */
+
+typedef struct {
+ Objects_Control Object;
+ Thread_queue_Control Wait_queue; /* waiting threads */
+ void *starting_address; /* physical start addr */
+ uintptr_t length; /* physical length(bytes) */
+ uintptr_t page_size; /* in bytes */
+ uintptr_t maximum_segment_size; /* in bytes */
+ rtems_attribute attribute_set;
+ uint32_t number_of_used_blocks; /* blocks allocated */
+ Heap_Control Memory;
+} Region_Control;
+
+/**
+ * The following defines the information control block used to
+ * manage this class of objects.
+ */
+RTEMS_REGION_EXTERN Objects_Information _Region_Information;
+
+/**
+ * @brief _Region_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Region_Manager_initialization(void);
+
+/**
+ * @brief rtems_region_create
+ *
+ * This routine implements the rtems_region_create directive. The
+ * region will have the name name. The memory area managed by
+ * the region is of length bytes and starts at starting_address.
+ * The memory area will be divided into as many allocatable units of
+ * page_size bytes as possible. The attribute_set determines which
+ * thread queue discipline is used by the region. It returns the
+ * id of the created region in ID.
+ */
+rtems_status_code rtems_region_create(
+ rtems_name name,
+ void *starting_address,
+ uintptr_t length,
+ uintptr_t page_size,
+ rtems_attribute attribute_set,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_region_extend
+ *
+ * This routine implements the rtems_region_extend directive. The
+ * region will have the name name. The memory area managed by
+ * the region will be attempted to be grown by length bytes using
+ * the memory starting at starting_address.
+ */
+rtems_status_code rtems_region_extend(
+ rtems_id id,
+ void *starting_address,
+ uintptr_t length
+);
+
+/**
+ * @brief rtems_region_ident
+ *
+ * This routine implements the rtems_region_ident directive.
+ * This directive returns the region ID associated with name.
+ * If more than one region is named name, then the region
+ * to which the ID belongs is arbitrary.
+ */
+rtems_status_code rtems_region_ident(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_region_get_information
+ *
+ * This routine implements the rtems_region_get_information directive.
+ * This directive returns information about the heap associated with
+ * this region.
+ */
+rtems_status_code rtems_region_get_information(
+ rtems_id id,
+ Heap_Information_block *the_info
+);
+
+/**
+ * @brief rtems_region_get_free_information
+ *
+ * This routine implements the rtems_region_get_free_information directive.
+ * This directive returns information about the free blocks in the
+ * heap associated with this region.
+ */
+rtems_status_code rtems_region_get_free_information(
+ rtems_id id,
+ Heap_Information_block *the_info
+);
+
+/**
+ * @brief rtems_region_delete
+ *
+ * This routine implements the rtems_region_delete directive. The
+ * region indicated by ID is deleted.
+ */
+rtems_status_code rtems_region_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_region_get_segment
+ *
+ * This routine implements the rtems_region_get_segment directive. It
+ * attempts to allocate a segment from the region associated with ID.
+ * If a segment of the requested size can be allocated, its address
+ * is returned in segment. If no segment is available, then the task
+ * may return immediately or block waiting for a segment with an optional
+ * timeout of timeout clock ticks. Whether the task blocks or returns
+ * immediately is based on the no_wait option in the option_set.
+ */
+rtems_status_code rtems_region_get_segment(
+ rtems_id id,
+ uintptr_t size,
+ rtems_option option_set,
+ rtems_interval timeout,
+ void **segment
+);
+
+/**
+ * @brief rtems_region_get_segment_size
+ *
+ * This routine implements the rtems_region_get_segment_size directive. It
+ * returns the size in bytes of the specified user memory area.
+ */
+rtems_status_code rtems_region_get_segment_size(
+ rtems_id id,
+ void *segment,
+ uintptr_t *size
+);
+
+/**
+ * @brief rtems_region_return_segment
+ *
+ * This routine implements the rtems_region_return_segment directive. It
+ * frees the segment to the region associated with ID. The segment must
+ * have been previously allocated from the same region. If freeing the
+ * segment results in enough memory being available to satisfy the
+ * rtems_region_get_segment of the first blocked task, then that task and as
+ * many subsequent tasks as possible will be unblocked with their requests
+ * satisfied.
+ */
+rtems_status_code rtems_region_return_segment(
+ rtems_id id,
+ void *segment
+);
+
+/**
+ * @brief rtems_region_resize_segment
+ *
+ * This routine implements the rtems_region_resize_segment directive. It
+ * tries to resize segment in the region associated with 'id' to the new size
+ * 'size' in place. The first 'size' or old size bytes of the segment
+ * (whatever is less) are guaranteed to remain unmodified. The segment must
+ * have been previously allocated from the same region. If resizing the
+ * segment results in enough memory being available to satisfy the
+ * rtems_region_get_segment of the first blocked task, then that task and as
+ * many subsequent tasks as possible will be unblocked with their requests
+ * satisfied.
+ * Returns:
+ * RTEMS_SUCCESSFUL - operation successful
+ * RTEMS_UNSATISFIED - the segment can't be resized in place
+ * any other code - failure.
+ * On RTEMS_SUCCESSFUL or RTEMS_UNSATISFIED exit it returns into the
+ * 'old_size' the old size in bytes of the user memory area of the specified
+ * segment.
+ */
+rtems_status_code rtems_region_resize_segment(
+ rtems_id id,
+ void *segment,
+ uintptr_t size,
+ uintptr_t *old_size
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/region.inl>
+/**
+ * @brief Region_Process_queue
+ *
+ * This is a helper routine which is invoked any time memory is
+ * freed. It looks at the set of waiting tasks and attempts to
+ * satisfy all outstanding requests.
+ */
+extern void _Region_Process_queue(Region_Control *the_region);
+
+#endif
+
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/regionmp.h>
+#endif
+
+/**
+ * @brief _Region_Debug_Walk
+ *
+ * This routine is invoked to verify the integrity of a heap associated
+ * with the_region.
+ */
+#ifdef RTEMS_DEBUG
+
+#define _Region_Debug_Walk( _the_region, _source ) \
+ do { \
+ if ( rtems_debug_is_enabled( RTEMS_DEBUG_REGION ) ) \
+ _Heap_Walk( &(_the_region)->Memory, _source, false ); \
+ } while ( 0 )
+
+#else
+
+#define _Region_Debug_Walk( _the_region, _source )
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/regionmp.h b/cpukit/rtems/include/rtems/rtems/regionmp.h
new file mode 100644
index 0000000000..b748aba8e8
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/regionmp.h
@@ -0,0 +1,155 @@
+/**
+ * @file rtems/rtems/regionmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Region Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_REGIONMP_H
+#define _RTEMS_RTEMS_REGIONMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+
+/**
+ * @defgroup ClassicRegionMP Region MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following enumerated type defines the list of
+ * remote region operations.
+ */
+typedef enum {
+ REGION_MP_ANNOUNCE_CREATE = 0,
+ REGION_MP_ANNOUNCE_DELETE = 1,
+ REGION_MP_EXTRACT_PROXY = 2,
+ REGION_MP_GET_SEGMENT_REQUEST = 3,
+ REGION_MP_GET_SEGMENT_RESPONSE = 4,
+ REGION_MP_RETURN_SEGMENT_REQUEST = 5,
+ REGION_MP_RETURN_SEGMENT_RESPONSE = 6
+} Region_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote region operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Region_MP_Remote_operations operation;
+ rtems_name name;
+ rtems_option option_set;
+ uint32_t size;
+ Objects_Id proxy_id;
+ void *segment;
+} Region_MP_Packet;
+
+/**
+ * @brief _Region_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ */
+void _Region_MP_Send_process_packet (
+ Region_MP_Remote_operations operation,
+ Objects_Id region_id,
+ rtems_name name,
+ Objects_Id proxy_id
+);
+
+/**
+ * @brief _Region_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Region_MP_Send_request_packet (
+ Region_MP_Remote_operations operation,
+ Objects_Id region_id,
+ void *segment,
+ intptr_t size,
+ rtems_option option_set,
+ rtems_interval timeout
+);
+
+/**
+ * @brief _Region_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _Region_MP_Send_response_packet (
+ Region_MP_Remote_operations operation,
+ Objects_Id region_id,
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief _Region_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Region_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/*
+ * @brief _Region_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed by the Region since a region
+ * cannot be deleted when segments are in use.
+ */
+
+/**
+ * @brief _Region_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ */
+void _Region_MP_Send_extract_proxy (
+ void *argument
+);
+
+/**
+ * @brief _Region_MP_Get_packet
+ *
+ * This function is used to obtain a region mp packet.
+ */
+Region_MP_Packet *_Region_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/rtemsapi.h b/cpukit/rtems/include/rtems/rtems/rtemsapi.h
new file mode 100644
index 0000000000..d75dbb0490
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/rtemsapi.h
@@ -0,0 +1,32 @@
+/**
+ * @file rtems/rtems/rtemsapi.h
+ *
+ * RTEMS API Support
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_RTEMSAPI_H
+#define _RTEMS_RTEMS_RTEMSAPI_H
+
+#include <rtems/config.h>
+
+/**
+ * _RTEMS_API_Initialize
+ *
+ * This routine initializes the RTEMS API by invoking the initialization
+ * routine for each RTEMS manager with the appropriate parameters
+ * from the configuration_table.
+ */
+void _RTEMS_API_Initialize(void);
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/sem.h b/cpukit/rtems/include/rtems/rtems/sem.h
new file mode 100644
index 0000000000..b4443241c0
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/sem.h
@@ -0,0 +1,244 @@
+/**
+ * @file rtems/rtems/sem.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Semaphore Manager. This manager utilizes standard Dijkstra
+ * counting semaphores to provide synchronization and mutual exclusion
+ * capabilities.
+ *
+ * Directives provided are:
+ *
+ * - create a semaphore
+ * - get an ID of a semaphore
+ * - delete a semaphore
+ * - acquire a semaphore
+ * - release a semaphore
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SEM_H
+#define _RTEMS_RTEMS_SEM_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_SEM_EXTERN
+#define RTEMS_SEM_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coresem.h>
+
+/**
+ * @defgroup ClassicSem Semaphores
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality related to the Classic API
+ * Semaphore Manager.
+ */
+/**@{*/
+
+/**
+ * The following defines the control block used to manage each semaphore.
+ */
+typedef struct {
+ /** This field is the object management portion of a Semaphore instance. */
+ Objects_Control Object;
+
+ /**
+ * This is the Classic API attribute provided to the create directive.
+ * It is translated into behavioral attributes on the SuperCore Semaphore
+ * or Mutex instance.
+ */
+ rtems_attribute attribute_set;
+
+ /**
+ * This contains the memory associated with the SuperCore Semaphore or
+ * Mutex instance that provides the primary functionality of each
+ * Classic API Semaphore instance. The structure used is dependent
+ * on the attributes specified by the user on the create directive.
+ *
+ * @note Only one of these has meaning in a particular Classic API
+ * Semaphore instance.
+ */
+ union {
+ /**
+ * This is the SuperCore Mutex instance associated with this Classic
+ * API Semaphore instance.
+ */
+ CORE_mutex_Control mutex;
+
+ /**
+ * This is the SuperCore Semaphore instance associated with this Classic
+ * API Semaphore instance.
+ */
+ CORE_semaphore_Control semaphore;
+ } Core_control;
+} Semaphore_Control;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+RTEMS_SEM_EXTERN Objects_Information _Semaphore_Information;
+
+/**
+ * @brief Semaphore_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Semaphore_Manager_initialization(void);
+
+/**
+ * @brief rtems_semaphore_create
+ *
+ * This routine implements the rtems_semaphore_create directive. The
+ * semaphore will have the name name. The starting count for
+ * the semaphore is count. The attribute_set determines if
+ * the semaphore is global or local and the thread queue
+ * discipline. It returns the id of the created semaphore in ID.
+ */
+rtems_status_code rtems_semaphore_create(
+ rtems_name name,
+ uint32_t count,
+ rtems_attribute attribute_set,
+ rtems_task_priority priority_ceiling,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_semaphore_ident
+ *
+ * This routine implements the rtems_semaphore_ident directive.
+ * This directive returns the semaphore ID associated with name.
+ * If more than one semaphore is named name, then the semaphore
+ * to which the ID belongs is arbitrary. node indicates the
+ * extent of the search for the ID of the semaphore named name.
+ * The search can be limited to a particular node or allowed to
+ * encompass all nodes.
+ */
+rtems_status_code rtems_semaphore_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_semaphore_delete
+ *
+ * This routine implements the rtems_semaphore_delete directive. The
+ * semaphore indicated by ID is deleted.
+ */
+rtems_status_code rtems_semaphore_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_semaphore_obtain
+ *
+ * This routine implements the rtems_semaphore_obtain directive. It
+ * attempts to obtain a unit from the semaphore associated with ID.
+ * If a unit can be allocated, the calling task will return immediately.
+ * If no unit is available, then the task may return immediately or
+ * block waiting for a unit with an optional timeout of timeout
+ * clock ticks. Whether the task blocks or returns immediately
+ * is based on the RTEMS_NO_WAIT option in the option_set.
+ */
+rtems_status_code rtems_semaphore_obtain(
+ rtems_id id,
+ rtems_option option_set,
+ rtems_interval timeout
+);
+
+/**
+ * @brief rtems_semaphore_release
+ *
+ * This routine implements the rtems_semaphore_release directive. It
+ * frees a unit to the semaphore associated with ID. If a task was
+ * blocked waiting for a unit from this semaphore, then that task will
+ * be readied and the unit given to that task. Otherwise, the unit
+ * will be returned to the semaphore.
+ */
+rtems_status_code rtems_semaphore_release(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_semaphore_flush
+ * pending on the semaphore.
+ */
+rtems_status_code rtems_semaphore_flush(
+ rtems_id id
+);
+
+/**
+ * @brief _Semaphore_Seize
+ *
+ * This routine attempts to receive a unit from the_semaphore.
+ * If a unit is available or if the RTEMS_NO_WAIT option is enabled in
+ * option_set, then the routine returns. Otherwise, the calling task
+ * is blocked until a unit becomes available.
+ */
+bool _Semaphore_Seize(
+ Semaphore_Control *the_semaphore,
+ uint32_t option_set
+);
+
+/**
+ * @brief _Semaphore_Translate_core_mutex_return_code
+ *
+ * This function returns a RTEMS status code based on the mutex
+ * status code specified.
+ */
+rtems_status_code _Semaphore_Translate_core_mutex_return_code (
+ uint32_t the_mutex_status
+);
+
+/**
+ * @brief _Semaphore_Translate_core_semaphore_return_code
+ *
+ * This function returns a RTEMS status code based on the semaphore
+ * status code specified.
+ */
+rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
+ uint32_t the_mutex_status
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/sem.inl>
+#endif
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/semmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/semmp.h b/cpukit/rtems/include/rtems/rtems/semmp.h
new file mode 100644
index 0000000000..f3a06aeb2f
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/semmp.h
@@ -0,0 +1,175 @@
+/**
+ * @file rtems/rtems/semmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Semaphore Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SEMMP_H
+#define _RTEMS_RTEMS_SEMMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * @defgroup ClassicSEM Semaphore MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+/**
+ * The following enumerated type defines the list of
+ * remote semaphore operations.
+ */
+typedef enum {
+ SEMAPHORE_MP_ANNOUNCE_CREATE = 0,
+ SEMAPHORE_MP_ANNOUNCE_DELETE = 1,
+ SEMAPHORE_MP_EXTRACT_PROXY = 2,
+ SEMAPHORE_MP_OBTAIN_REQUEST = 3,
+ SEMAPHORE_MP_OBTAIN_RESPONSE = 4,
+ SEMAPHORE_MP_RELEASE_REQUEST = 5,
+ SEMAPHORE_MP_RELEASE_RESPONSE = 6
+} Semaphore_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote semaphore operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Semaphore_MP_Remote_operations operation;
+ rtems_name name;
+ rtems_option option_set;
+ Objects_Id proxy_id;
+} Semaphore_MP_Packet;
+
+/**
+ * @brief Semaphore_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ */
+void _Semaphore_MP_Send_process_packet (
+ Semaphore_MP_Remote_operations operation,
+ Objects_Id semaphore_id,
+ rtems_name name,
+ Objects_Id proxy_id
+);
+
+/**
+ * @brief Semaphore_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Semaphore_MP_Send_request_packet (
+ Semaphore_MP_Remote_operations operation,
+ Objects_Id semaphore_id,
+ rtems_option option_set,
+ rtems_interval timeout
+);
+
+/**
+ * @brief Semaphore_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _Semaphore_MP_Send_response_packet (
+ Semaphore_MP_Remote_operations operation,
+ Objects_Id semaphore_id,
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief Semaphore_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Semaphore_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/**
+ * @brief Semaphore_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ */
+void _Semaphore_MP_Send_object_was_deleted (
+ Thread_Control *the_proxy
+);
+
+/**
+ * @brief Semaphore_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ */
+void _Semaphore_MP_Send_extract_proxy (
+ void *argument
+);
+
+/**
+ * @brief Semaphore_MP_Get_packet
+ *
+ * This function is used to obtain a semaphore mp packet.
+ */
+Semaphore_MP_Packet *_Semaphore_MP_Get_packet ( void );
+
+/**
+ * @brief _Semaphore_Core_mutex_mp_support
+ *
+ * This function processes the global actions necessary for remote
+ * accesses to a global semaphore based on a core mutex. This function
+ * is called by the core.
+ */
+void _Semaphore_Core_mutex_mp_support (
+ Thread_Control *the_thread,
+ Objects_Id id
+);
+
+/**
+ * @brief Semaphore_Core_mp_support
+ *
+ * This function processes the global actions necessary for remote
+ * accesses to a global semaphore based on a core semaphore. This function
+ * is called by the core.
+ */
+void _Semaphore_Core_semaphore_mp_support (
+ Thread_Control *the_thread,
+ Objects_Id id
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/signal.h b/cpukit/rtems/include/rtems/rtems/signal.h
new file mode 100644
index 0000000000..1517dce734
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/signal.h
@@ -0,0 +1,87 @@
+/**
+ * @file rtems/rtems/signal.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Signal Manager. This manager provides capabilities required
+ * for asynchronous communication between tasks via signal sets.
+ *
+ * Directives provided are:
+ *
+ * + establish an asynchronous signal routine
+ * + send a signal set to a task
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SIGNAL_H
+#define _RTEMS_RTEMS_SIGNAL_H
+
+/**
+ * @defgroup ClassicSignal Signals
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+#include <rtems/rtems/asr.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * @brief _Signal_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Signal_Manager_initialization( void );
+
+/**
+ * @brief rtems_signal_catch
+ *
+ * This routine implements the rtems_signal_catch directive. This directive
+ * is used to establish asr_handler as the Asynchronous Signal Routine
+ * (RTEMS_ASR) for the calling task. The asr_handler will execute with a
+ * mode of mode_set.
+ */
+rtems_status_code rtems_signal_catch(
+ rtems_asr_entry asr_handler,
+ rtems_mode mode_set
+);
+
+/**
+ * @brief rtems_signal_send
+ *
+ * This routine implements the rtems_signal_send directive. This directive
+ * sends the signal_set to the task specified by ID.
+ */
+rtems_status_code rtems_signal_send(
+ rtems_id id,
+ rtems_signal_set signal_set
+);
+
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/signalmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/signalmp.h b/cpukit/rtems/include/rtems/rtems/signalmp.h
new file mode 100644
index 0000000000..46e6a60538
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/signalmp.h
@@ -0,0 +1,138 @@
+/**
+ * @file rtems/rtems/signalmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Multiprocessing Support in the Signal Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SIGNALMP_H
+#define _RTEMS_RTEMS_SIGNALMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/asr.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * @defgroup ClassicSignalMP Signal MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**{*/
+
+/**
+ * The following enumerated type defines the list of
+ * remote signal operations.
+ */
+typedef enum {
+ SIGNAL_MP_SEND_REQUEST = 0,
+ SIGNAL_MP_SEND_RESPONSE = 1
+} Signal_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote signal operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ Signal_MP_Remote_operations operation;
+ rtems_signal_set signal_in;
+} Signal_MP_Packet;
+
+/*
+ * @brief Signal_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ *
+ * This routine is not needed since there are no process
+ * packets to be sent by this manager.
+ */
+
+/**
+ * @brief Signal_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _Signal_MP_Send_request_packet (
+ Signal_MP_Remote_operations operation,
+ Objects_Id task_id,
+ rtems_signal_set signal_in
+);
+
+/**
+ * @brief Signal_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _Signal_MP_Send_response_packet (
+ Signal_MP_Remote_operations operation,
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief Signal_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _Signal_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/*
+ * @brief Signal_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ */
+
+/*
+ * @brief Signal_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ */
+
+/**
+ * @brief Signal_MP_Get_packet
+ *
+ * This function is used to obtain a signal mp packet.
+ */
+Signal_MP_Packet *_Signal_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/status.h b/cpukit/rtems/include/rtems/rtems/status.h
new file mode 100644
index 0000000000..0f42a8b54d
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/status.h
@@ -0,0 +1,220 @@
+/**
+ * @file rtems/rtems/status.h
+ *
+ * This include file contains the status codes returned from the
+ * executive directives.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_STATUS_H
+#define _RTEMS_RTEMS_STATUS_H
+
+/**
+ * @defgroup ClassicStatus Status Codes
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Classic API Status
+ *
+ * This enumerates the possible status values returned b
+ * Classic API directives.
+ */
+typedef enum {
+ /**
+ * This is the status to indicate successful completion.
+ */
+ RTEMS_SUCCESSFUL = 0,
+ /**
+ * This is the status to indicate that a thread exited.
+ */
+ RTEMS_TASK_EXITTED = 1,
+ /**
+ * This is the status to indicate multiprocessing is not configured.
+ */
+ RTEMS_MP_NOT_CONFIGURED = 2,
+ /**
+ * This is the status to indicate that the object name was invalid.
+ */
+ RTEMS_INVALID_NAME = 3,
+ /**
+ * This is the status to indicate that the object Id was invalid.
+ */
+ RTEMS_INVALID_ID = 4,
+ /**
+ * This is the status to indicate you have attempted to create too many
+ * instances of a particular object class.
+ */
+ RTEMS_TOO_MANY = 5,
+ /**
+ * This is the status to indicate that a blocking directive timed out.
+ */
+ RTEMS_TIMEOUT = 6,
+ /**
+ * This is the status to indicate the the object was deleted
+ * while the task was blocked waiting.
+ */
+ RTEMS_OBJECT_WAS_DELETED = 7,
+ /**
+ * This is the status to indicate that the specified size was invalid.
+ */
+ RTEMS_INVALID_SIZE = 8,
+ /**
+ * This is the status to indicate that the specified address is invalid.
+ */
+ RTEMS_INVALID_ADDRESS = 9,
+ /**
+ * This is the status to indicate that the specified number was invalid.
+ */
+ RTEMS_INVALID_NUMBER = 10,
+ /**
+ * This is the status to indicate that the item has not been initialized.
+ */
+ RTEMS_NOT_DEFINED = 11,
+ /**
+ * This is the status to indicate that the object still has
+ * resources in use.
+ */
+ RTEMS_RESOURCE_IN_USE = 12,
+ /**
+ * This is the status to indicate that the request was not satisfied.
+ */
+ RTEMS_UNSATISFIED = 13,
+ /**
+ * This is the status to indicate that a thread is in wrong state
+ * was in the wrong execution state for the requested operation.
+ */
+ RTEMS_INCORRECT_STATE = 14,
+ /**
+ * This is the status to indicate thread was already suspended.
+ */
+ RTEMS_ALREADY_SUSPENDED = 15,
+ /**
+ * This is the status to indicate that the operation is illegal
+ * on calling thread.
+ */
+ RTEMS_ILLEGAL_ON_SELF = 16,
+ /**
+ * This is the status to indicate illegal for remote object.
+ */
+ RTEMS_ILLEGAL_ON_REMOTE_OBJECT = 17,
+ /**
+ * This is the status to indicate that the operation should not be
+ * called from from this excecution environment.
+ */
+ RTEMS_CALLED_FROM_ISR = 18,
+ /**
+ * This is the status to indicate that an invalid thread priority
+ * was provided.
+ */
+ RTEMS_INVALID_PRIORITY = 19,
+ /**
+ * This is the status to indicate that the specified date/time was invalid.
+ */
+ RTEMS_INVALID_CLOCK = 20,
+ /**
+ * This is the status to indicate that the specified node Id was invalid.
+ */
+ RTEMS_INVALID_NODE = 21,
+ /**
+ * This is the status to indicate that the directive was not configured.
+ */
+ RTEMS_NOT_CONFIGURED = 22,
+ /**
+ * This is the status to indicate that the caller is not the
+ * owner of the resource.
+ */
+ RTEMS_NOT_OWNER_OF_RESOURCE = 23,
+ /**
+ * This is the status to indicate the the directive or requested
+ * portion of the directive is not implemented. This is a hint
+ * that you have stumbled across an opportunity to submit code
+ * to the RTEMS Project.
+ */
+ RTEMS_NOT_IMPLEMENTED = 24,
+ /**
+ * This is the status to indicate that an internal RTEMS inconsistency
+ * was detected.
+ */
+ RTEMS_INTERNAL_ERROR = 25,
+ /**
+ * This is the status to indicate that the directive attempted to allocate
+ * memory but was unable to do so.
+ */
+ RTEMS_NO_MEMORY = 26,
+ /**
+ * This is the status to indicate an driver IO error.
+ */
+ RTEMS_IO_ERROR = 27,
+ /**
+ * This is the status is used internally to RTEMS when performing
+ * operations on behalf of remote tasks. This is referred to as
+ * proxying operations and this status indicates that the operation
+ * could not be completed immediately and the "proxy is blocking."
+ *
+ * @note This status will @b NOT be returned to the user.
+ */
+ RTEMS_PROXY_BLOCKING = 28
+} rtems_status_code;
+
+/**
+ * This is the lowest valid value for a Classic API status code.
+ */
+#define RTEMS_STATUS_CODES_FIRST RTEMS_SUCCESSFUL
+
+/**
+ * This is the highest valid value for a Classic API status code.
+ */
+#define RTEMS_STATUS_CODES_LAST RTEMS_PROXY_BLOCKING
+
+/**
+ * This array is used to map SuperCore Object Handler return
+ * codes to Classic API status codes.
+ */
+#ifdef RTEMS_API_INIT
+const rtems_status_code _Status_Object_name_errors_to_status[] = {
+ /** This maps OBJECTS_SUCCESSFUL to RTEMS_SUCCESSFUL. */
+ RTEMS_SUCCESSFUL,
+ /** This maps OBJECTS_INVALID_NAME to RTEMS_INVALID_NAME. */
+ RTEMS_INVALID_NAME,
+ /** This maps OBJECTS_INVALID_ADDRESS to RTEMS_INVALID_NAME. */
+ RTEMS_INVALID_ADDRESS,
+ /** This maps OBJECTS_INVALID_ID to RTEMS_INVALID_ADDRESS. */
+ RTEMS_INVALID_ID,
+ /** This maps OBJECTS_INVALID_NODE to RTEMS_INVALID_NODE. */
+ RTEMS_INVALID_NODE
+};
+#else
+extern rtems_status_code _Status_Object_name_errors_to_status[];
+#endif
+
+/*
+ * Applications are allowed to use the macros to compare status codes.
+ */
+#include <rtems/rtems/status.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/support.h b/cpukit/rtems/include/rtems/rtems/support.h
new file mode 100644
index 0000000000..220411d984
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/support.h
@@ -0,0 +1,117 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @ingroup ClassicRTEMSWorkspace
+ *
+ * @brief Classic API support.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SUPPORT_H
+#define _RTEMS_RTEMS_SUPPORT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/types.h>
+
+/**
+ * @addtogroup ClassicRTEMS
+ *
+ * @{
+ */
+
+/**
+ * @brief Returns the number of micro seconds for the milli seconds value @a _ms.
+ */
+#define RTEMS_MILLISECONDS_TO_MICROSECONDS(_ms) \
+ TOD_MILLISECONDS_TO_MICROSECONDS(_ms)
+
+/**
+ * @brief Returns the number of ticks for the milli seconds value @a _ms.
+ */
+#define RTEMS_MILLISECONDS_TO_TICKS(_ms) \
+ (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / \
+ rtems_configuration_get_microseconds_per_tick())
+
+/**
+ * @brief Returns the number of ticks for the micro seconds value @a _us.
+ */
+#define RTEMS_MICROSECONDS_TO_TICKS(_us) \
+ ((_us) / rtems_configuration_get_microseconds_per_tick())
+
+/** @} */
+
+/**
+ * @defgroup ClassicRTEMSWorkspace Workspace
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * Workspace definitions.
+ *
+ * @{
+ */
+
+/**
+ * @brief Gets workspace information.
+ *
+ * Returns information about the heap that is used as the RTEMS Executive
+ * Workspace in @a the_info.
+ *
+ * Returns @c true if successful, and @a false otherwise.
+ */
+bool rtems_workspace_get_information(
+ Heap_Information_block *the_info
+);
+
+/**
+ * @brief Allocates memory from the workspace.
+ *
+ * A number of @a bytes bytes will be allocated from the RTEMS Executive
+ * Workspace and returned in @a pointer.
+ *
+ * Returns @c true if successful, and @a false otherwise.
+ */
+bool rtems_workspace_allocate(
+ size_t bytes,
+ void **pointer
+);
+
+/**
+ * @brief Frees memory allocated from the workspace.
+ *
+ * This frees the memory indicated by @a pointer that was allocated from the
+ * RTEMS Executive Workspace.
+ *
+ * Returns @c true if successful, and @a false otherwise.
+ */
+bool rtems_workspace_free(
+ void *pointer
+);
+
+/** @} */
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/support.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/taskmp.h b/cpukit/rtems/include/rtems/rtems/taskmp.h
new file mode 100644
index 0000000000..16bf205d8d
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/taskmp.h
@@ -0,0 +1,156 @@
+/**
+ * @file rtems/rtems/taskmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the multiprocessing support in the task manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_TASKMP_H
+#define _RTEMS_RTEMS_TASKMP_H
+
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/priority.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+
+/**
+ * @defgroup ClassicTaskMP Task MP Support
+ *
+ * @ingroup ClassicMP
+ *
+ * This encapsulates functionality which XXX
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * The following enumerated type defines the list of
+ * remote task operations.
+ */
+typedef enum {
+ RTEMS_TASKS_MP_ANNOUNCE_CREATE = 0,
+ RTEMS_TASKS_MP_ANNOUNCE_DELETE = 1,
+ RTEMS_TASKS_MP_SUSPEND_REQUEST = 2,
+ RTEMS_TASKS_MP_SUSPEND_RESPONSE = 3,
+ RTEMS_TASKS_MP_RESUME_REQUEST = 4,
+ RTEMS_TASKS_MP_RESUME_RESPONSE = 5,
+ RTEMS_TASKS_MP_SET_PRIORITY_REQUEST = 6,
+ RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE = 7,
+ RTEMS_TASKS_MP_GET_NOTE_REQUEST = 8,
+ RTEMS_TASKS_MP_GET_NOTE_RESPONSE = 9,
+ RTEMS_TASKS_MP_SET_NOTE_REQUEST = 10,
+ RTEMS_TASKS_MP_SET_NOTE_RESPONSE = 11
+} RTEMS_tasks_MP_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote task operations.
+ */
+typedef struct {
+ rtems_packet_prefix Prefix;
+ RTEMS_tasks_MP_Remote_operations operation;
+ rtems_name name;
+ rtems_task_priority the_priority;
+ uint32_t notepad;
+ uint32_t note;
+} RTEMS_tasks_MP_Packet;
+
+/**
+ * @brief _RTEMS_tasks_MP_Send_process_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ */
+void _RTEMS_tasks_MP_Send_process_packet (
+ RTEMS_tasks_MP_Remote_operations operation,
+ Objects_Id task_id,
+ rtems_name name
+);
+
+/**
+ * @brief _RTEMS_tasks_MP_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ */
+rtems_status_code _RTEMS_tasks_MP_Send_request_packet (
+ RTEMS_tasks_MP_Remote_operations operation,
+ Objects_Id task_id,
+ rtems_task_priority the_priority,
+ uint32_t notepad,
+ uint32_t note
+);
+
+/**
+ * @brief _RTEMS_tasks_MP_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ */
+void _RTEMS_tasks_MP_Send_response_packet (
+ RTEMS_tasks_MP_Remote_operations operation,
+ Thread_Control *the_thread
+);
+
+/**
+ * @brief _RTEMS_tasks_MP_Process_packet
+ *
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _RTEMS_tasks_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+);
+
+/**
+ * @brief _RTEMS_tasks_MP_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed by RTEMS_tasks since a task
+ * cannot be deleted when segments are in use.
+ */
+
+/*
+ * _RTEMS_tasks_MP_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/**
+ * @brief _RTEMS_tasks_MP_Get_packet
+ *
+ * This function is used to obtain a task mp packet.
+ */
+RTEMS_tasks_MP_Packet *_RTEMS_tasks_MP_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of file */
diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h
new file mode 100644
index 0000000000..1e9a9c57e6
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/tasks.h
@@ -0,0 +1,505 @@
+/**
+ * @file rtems/rtems/tasks.h
+ *
+ * This include file contains all constants and structures associated
+ * with RTEMS tasks. This manager provides a comprehensive set of directives
+ * to create, delete, and administer tasks.
+ *
+ * Directives provided are:
+ *
+ * - create a task
+ * - get an ID of a task
+ * - start a task
+ * - restart a task
+ * - delete a task
+ * - suspend a task
+ * - resume a task
+ * - set a task's priority
+ * - change the current task's mode
+ * - get a task notepad entry
+ * - set a task notepad entry
+ * - wake up after interval
+ * - wake up when specified
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_TASKS_H
+#define _RTEMS_RTEMS_TASKS_H
+
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/types.h>
+#include <rtems/rtems/eventset.h>
+#include <rtems/rtems/asr.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/status.h>
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_TASKS_EXTERN
+#define RTEMS_TASKS_EXTERN extern
+#endif
+
+/**
+ * @defgroup ClassicTasks Tasks
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality which X XX
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Constant to be used as the ID of current task
+ */
+#define RTEMS_SELF OBJECTS_ID_OF_SELF
+
+/**
+ * This constant is passed to the rtems_task_wake_after directive as the
+ * interval when a task wishes to yield the CPU.
+ */
+#define RTEMS_YIELD_PROCESSOR WATCHDOG_NO_TIMEOUT
+
+/**
+ * Define the type for an RTEMS API task priority.
+ */
+typedef Priority_Control rtems_task_priority;
+
+/**
+ * This is the constant used with the rtems_task_set_priority
+ * directive to indicate that the caller wants to obtain its
+ * current priority rather than set it as the name of the
+ * directive indicates.
+ */
+#define RTEMS_NO_PRIORITY RTEMS_CURRENT_PRIORITY
+
+/**
+ * This constant is the least valid value for a Classic API
+ * task priority.
+ */
+#define RTEMS_MINIMUM_PRIORITY (PRIORITY_MINIMUM + 1)
+
+/**
+ * This constant is the maximum valid value for a Classic API
+ * task priority.
+ *
+ * @note This is actually the priority of the IDLE thread so
+ * using this priority will result in having a task
+ * which never executes. This could be useful if you
+ * want to ensure that a task does not executes during
+ * certain operations such as a system mode change.
+ */
+#define RTEMS_MAXIMUM_PRIORITY PRIORITY_MAXIMUM
+
+/**
+ * The following constant is passed to rtems_task_set_priority when the
+ * caller wants to obtain the current priority.
+ */
+#define RTEMS_CURRENT_PRIORITY PRIORITY_MINIMUM
+
+/** This is used to indicate the lowest numbered notepad */
+#define RTEMS_NOTEPAD_FIRST 0
+/** This is used to indicate the notepad location 0. */
+#define RTEMS_NOTEPAD_0 0
+/** This is used to indicate the notepad location 1. */
+#define RTEMS_NOTEPAD_1 1
+/** This is used to indicate the notepad location 2. */
+#define RTEMS_NOTEPAD_2 2
+/** This is used to indicate the notepad location 3. */
+#define RTEMS_NOTEPAD_3 3
+/** This is used to indicate the notepad location 4. */
+#define RTEMS_NOTEPAD_4 4
+/** This is used to indicate the notepad location 5. */
+#define RTEMS_NOTEPAD_5 5
+/** This is used to indicate the notepad location 6. */
+#define RTEMS_NOTEPAD_6 6
+/** This is used to indicate the notepad location 7. */
+#define RTEMS_NOTEPAD_7 7
+/** This is used to indicate the notepad location 8. */
+#define RTEMS_NOTEPAD_8 8
+/** This is used to indicate the notepad location 9. */
+#define RTEMS_NOTEPAD_9 9
+/** This is used to indicate the notepad location 10. */
+#define RTEMS_NOTEPAD_10 10
+/** This is used to indicate the notepad location 11. */
+#define RTEMS_NOTEPAD_11 11
+/** This is used to indicate the notepad location 12. */
+#define RTEMS_NOTEPAD_12 12
+/** This is used to indicate the notepad location 13. */
+#define RTEMS_NOTEPAD_13 13
+/** This is used to indicate the notepad location 14. */
+#define RTEMS_NOTEPAD_14 14
+/** This is used to indicate the notepad location 15. */
+#define RTEMS_NOTEPAD_15 15
+/** This is used to indicate the highest numbered notepad. */
+#define RTEMS_NOTEPAD_LAST RTEMS_NOTEPAD_15
+
+/** This is used to indicate the number of notepads available. */
+#define RTEMS_NUMBER_NOTEPADS (RTEMS_NOTEPAD_LAST+1)
+
+/**
+ * External API name for Thread_Control
+ */
+typedef Thread_Control rtems_tcb;
+
+/**
+ * The following defines the "return type" of an RTEMS task.
+ */
+typedef void rtems_task;
+
+/**
+ * The following defines the argument to an RTEMS task.
+ */
+typedef Thread_Entry_numeric_type rtems_task_argument;
+
+/**
+ * The following defines the type for the entry point of an RTEMS task.
+ */
+typedef rtems_task ( *rtems_task_entry )(
+ rtems_task_argument
+ );
+
+/**
+ * The following records define the Initialization Tasks Table.
+ * Each entry contains the information required by RTEMS to
+ * create and start a user task automatically at executive
+ * initialization time.
+ */
+typedef struct {
+ /** This is the Initialization Task's name. */
+ rtems_name name;
+ /** This is the Initialization Task's stack size. */
+ size_t stack_size;
+ /** This is the Initialization Task's priority. */
+ rtems_task_priority initial_priority;
+ /** This is the Initialization Task's attributes. */
+ rtems_attribute attribute_set;
+ /** This is the Initialization Task's entry point. */
+ rtems_task_entry entry_point;
+ /** This is the Initialization Task's initial mode. */
+ rtems_mode mode_set;
+ /** This is the Initialization Task's argument. */
+ rtems_task_argument argument;
+} rtems_initialization_tasks_table;
+
+/**
+ * This is the API specific information required by each thread for
+ * the RTEMS API to function correctly.
+ *
+ * @note Notepads must be the last entry in the structure and memory
+ * will be taken away from this structure when allocated if
+ * notespads are disabled by the application configuration.
+ */
+typedef struct {
+ /** This field contains the pending events for this task. */
+ rtems_event_set pending_events;
+ /** This field contains the event wait condition for this task. */
+ rtems_event_set event_condition;
+ /** This field contains the Classic API Signal information for this task. */
+ ASR_Information Signal;
+ /**
+ * This field contains the notepads for this task.
+ *
+ * @note MUST BE LAST ENTRY.
+ */
+ uint32_t Notepads[ RTEMS_NUMBER_NOTEPADS ];
+} RTEMS_API_Control;
+
+/**
+ * The following instantiates the information control block used to
+ * manage this class of objects.
+ */
+RTEMS_TASKS_EXTERN Objects_Information _RTEMS_tasks_Information;
+
+/**
+ * When the user configures a set of Classic API initialization tasks,
+ * This variable will point to the method used to initialize them.
+ *
+ * @note It is instantiated and initialized by confdefs.h based upon
+ * application requirements.
+ */
+extern void (*_RTEMS_tasks_Initialize_user_tasks_p)(void);
+
+/**
+ * @brief _RTEMS_tasks_Manager_initialization
+ *
+ * This routine initializes all Task Manager related data structures.
+ */
+void _RTEMS_tasks_Manager_initialization(void);
+
+/**
+ * @brief rtems_task_create
+ *
+ * This routine implements the rtems_task_create directive. The task
+ * will have the name name. The attribute_set can be used to indicate
+ * that the task will be globally accessible or utilize floating point.
+ * The task's stack will be stack_size bytes. The task will begin
+ * execution with initial_priority and initial_modes. It returns the
+ * id of the created task in ID.
+ */
+rtems_status_code rtems_task_create(
+ rtems_name name,
+ rtems_task_priority initial_priority,
+ size_t stack_size,
+ rtems_mode initial_modes,
+ rtems_attribute attribute_set,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_task_ident
+ *
+ * This routine implements the rtems_task_ident directive.
+ * This directive returns the task ID associated with name.
+ * If more than one task is named name, then the task to
+ * which the ID belongs is arbitrary. node indicates the
+ * extent of the search for the ID of the task named name.
+ * The search can be limited to a particular node or allowed to
+ * encompass all nodes.
+ */
+rtems_status_code rtems_task_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_task_delete
+ *
+ * This routine implements the rtems_task_delete directive. The
+ * task indicated by ID is deleted.
+ */
+rtems_status_code rtems_task_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_task_get_note
+ *
+ * This routine implements the rtems_task_get_note directive. The
+ * value of the indicated notepad for the task associated with ID
+ * is returned in note.
+ */
+rtems_status_code rtems_task_get_note(
+ rtems_id id,
+ uint32_t notepad,
+ uint32_t *note
+);
+
+/**
+ * @brief rtems_task_set_note
+ *
+ * This routine implements the rtems_task_set_note directive. The
+ * value of the indicated notepad for the task associated with ID
+ * is returned in note.
+ */
+rtems_status_code rtems_task_set_note(
+ rtems_id id,
+ uint32_t notepad,
+ uint32_t note
+);
+
+/**
+ * @brief rtems_task_mode
+ *
+ * This routine implements the rtems_task_mode directive. The current
+ * values of the modes indicated by mask of the calling task are changed
+ * to that indicated in mode_set. The former mode of the task is
+ * returned in mode_set.
+ */
+rtems_status_code rtems_task_mode(
+ rtems_mode mode_set,
+ rtems_mode mask,
+ rtems_mode *previous_mode_set
+);
+
+/**
+ * @brief rtems_task_restart
+ *
+ * This routine implements the rtems_task_restart directive. The
+ * task associated with ID is restarted at its initial entry
+ * point with the new argument.
+ */
+rtems_status_code rtems_task_restart(
+ rtems_id id,
+ uint32_t arg
+);
+
+/**
+ * @brief rtems_task_suspend
+ *
+ * This routine implements the rtems_task_suspend directive. The
+ * SUSPENDED state is set for task associated with ID.
+ */
+rtems_status_code rtems_task_suspend(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_task_resume
+ *
+ * This routine implements the rtems_task_resume Directive. The
+ * SUSPENDED state is cleared for task associated with ID.
+ */
+rtems_status_code rtems_task_resume(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_task_set_priority
+ *
+ * This routine implements the rtems_task_set_priority directive. The
+ * current priority of the task associated with ID is set to
+ * new_priority. The former priority of that task is returned
+ * in old_priority.
+ */
+rtems_status_code rtems_task_set_priority(
+ rtems_id id,
+ rtems_task_priority new_priority,
+ rtems_task_priority *old_priority
+);
+
+/**
+ * @brief rtems_task_start
+ *
+ * This routine implements the rtems_task_start directive. The
+ * starting execution point of the task associated with ID is
+ * set to entry_point with the initial argument.
+ */
+rtems_status_code rtems_task_start(
+ rtems_id id,
+ rtems_task_entry entry_point,
+ rtems_task_argument argument
+);
+
+/**
+ * @brief rtems_task_wake_when
+ *
+ * This routine implements the rtems_task_wake_when directive. The
+ * calling task is blocked until the current time of day is
+ * equal to that indicated by time_buffer.
+ */
+rtems_status_code rtems_task_wake_when(
+ rtems_time_of_day *time_buffer
+);
+
+/**
+ * @brief rtems_task_wake_after
+ *
+ * This routine implements the rtems_task_wake_after directive. The
+ * calling task is blocked until the indicated number of clock
+ * ticks have occurred.
+ */
+rtems_status_code rtems_task_wake_after(
+ rtems_interval ticks
+);
+
+/**
+ * @brief rtems_task_is_suspended
+
+ * This directive returns a status indicating whether or not
+ * the specified task is suspended.
+ */
+rtems_status_code rtems_task_is_suspended(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_task_variable_add
+ *
+ * This directive adds a per task variable.
+ */
+rtems_status_code rtems_task_variable_add(
+ rtems_id tid,
+ void **ptr,
+ void (*dtor)(void *)
+);
+
+/**
+ * @brief rtems_task_variable_get
+ *
+ * This directive gets the value of a task variable.
+ */
+rtems_status_code rtems_task_variable_get(
+ rtems_id tid,
+ void **ptr,
+ void **result
+);
+
+/**
+ * @brief rtems_task_variable_delete
+ *
+ * This directive removes a per task variable.
+ */
+rtems_status_code rtems_task_variable_delete(
+ rtems_id tid,
+ void **ptr
+);
+
+/**
+ * @brief rtems_task_self
+ *
+ * This directive returns the ID of the currently executing task.
+ */
+rtems_id rtems_task_self(void);
+
+/**
+ * @brief _RTEMS_tasks_Initialize_user_tasks
+ *
+ * This routine creates and starts all configured user
+ * initialzation threads.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+void _RTEMS_tasks_Initialize_user_tasks( void );
+
+/**
+ * @brief _RTEMS_Tasks_Invoke_task_variable_dtor(
+ *
+ * This routine invokes the optional user provided destructor on the
+ * task variable and frees the memory for the task variable.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+void _RTEMS_Tasks_Invoke_task_variable_dtor(
+ Thread_Control *the_thread,
+ rtems_task_variable_t *tvp
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/tasks.inl>
+#endif
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/taskmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/timer.h b/cpukit/rtems/include/rtems/rtems/timer.h
new file mode 100644
index 0000000000..a328e9a0d1
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/timer.h
@@ -0,0 +1,408 @@
+/**
+ * @file rtems/rtems/timer.h
+ *
+ * This include file contains all the constants, structures, and
+ * prototypes associated with the Timer Manager. This manager provides
+ * facilities to configure, initiate, cancel, and delete timers which will
+ * fire at specified intervals of time.
+ *
+ * Directives provided are:
+ *
+ * - create a timer
+ * - get an ID of a timer
+ * - delete a timer
+ * - set timer to fire in context of clock tick
+ * - after a number of ticks have passed
+ * - when a specified date and time has been reached
+ * - initiate the timer server task
+ * - set timer to fire in context of the timer server task
+ * - after a number of ticks have passed
+ * - when a specified date and time has been reached
+ * - reset a timer
+ * - cancel a time
+ */
+
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_TIMER_H
+#define _RTEMS_RTEMS_TIMER_H
+
+/**
+ * This constant is defined to extern most of the time when using
+ * this header file. However by defining it to nothing, the data
+ * declared in this header file can be instantiated. This is done
+ * in a single per manager file.
+ */
+#ifndef RTEMS_TIMER_EXTERN
+#define RTEMS_TIMER_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/chain.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/rtems/attr.h>
+
+/**
+ * @defgroup ClassicTimer Timers
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * This encapsulates functionality related to the Classic API Timer
+ * Manager. This manager provides functionality which allows the
+ * application to schedule the execution of methods at a specified
+ * time in the future. These methods may be scheduled based upon
+ * interval or wall time and may be executed in either the clock tick
+ * ISR or in a special dedicated timer server task.
+ */
+/**@{*/
+
+/**
+ * The following enumerated type details the classes to which a timer
+ * may belong.
+ */
+typedef enum {
+ /**
+ * This value indicates the timer is currently in use as an interval
+ * timer which will fire in the clock tick ISR.
+ */
+ TIMER_INTERVAL,
+
+ /**
+ * This value indicates the timer is currently in use as an interval
+ * timer which will fire in the timer server task.
+ */
+ TIMER_INTERVAL_ON_TASK,
+
+ /**
+ * This value indicates the timer is currently in use as an time of day
+ * timer which will fire in the clock tick ISR.
+ */
+ TIMER_TIME_OF_DAY,
+
+ /**
+ * This value indicates the timer is currently in use as an time of day
+ * timer which will fire in the timer server task.
+ */
+ TIMER_TIME_OF_DAY_ON_TASK,
+
+ /**
+ * This value indicates the timer is currently not in use.
+ */
+ TIMER_DORMANT
+} Timer_Classes;
+
+/**
+ * The following types define a pointer to a timer service routine.
+ */
+typedef void rtems_timer_service_routine;
+
+/**
+ * This type defines the type used to manage and indirectly invoke
+ * Timer Service Routines (TSRs). This defines the prototype and interface
+ * for a function which is to be used as a TSR.
+ */
+typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )(
+ rtems_id,
+ void *
+ );
+
+/**
+ * The following records define the control block used to manage
+ * each timer.
+ */
+typedef struct {
+ /** This field is the object management portion of a Timer instance. */
+ Objects_Control Object;
+ /** This field is the Watchdog instance which will be the scheduled. */
+ Watchdog_Control Ticker;
+ /** This field indicates what type of timer this currently is. */
+ Timer_Classes the_class;
+} Timer_Control;
+
+typedef struct Timer_server_Control Timer_server_Control;
+
+/**
+ * @brief Method used to schedule the insertion of task based timers.
+ */
+typedef void (*Timer_server_Schedule_operation)(
+ Timer_server_Control *timer_server,
+ Timer_Control *timer
+);
+
+typedef struct {
+ /**
+ * @brief This watchdog that will be registered in the system tick mechanic
+ * for timer server wake-up.
+ */
+ Watchdog_Control System_watchdog;
+
+ /**
+ * @brief Chain for watchdogs which will be triggered by the timer server.
+ */
+ Chain_Control Chain;
+
+ /**
+ * @brief Last known time snapshot of the timer server.
+ *
+ * The units may be ticks or seconds.
+ */
+ Watchdog_Interval volatile last_snapshot;
+} Timer_server_Watchdogs;
+
+struct Timer_server_Control {
+ /**
+ * @brief Timer server thread.
+ */
+ Thread_Control *thread;
+
+ /**
+ * @brief The schedule operation method of the timer server.
+ */
+ Timer_server_Schedule_operation schedule_operation;
+
+ /**
+ * @brief Interval watchdogs triggered by the timer server.
+ */
+ Timer_server_Watchdogs Interval_watchdogs;
+
+ /**
+ * @brief TOD watchdogs triggered by the timer server.
+ */
+ Timer_server_Watchdogs TOD_watchdogs;
+
+ /**
+ * @brief Chain of timers scheduled for insert.
+ *
+ * This pointer is not @c NULL whenever the interval and TOD chains are
+ * processed. After the processing this list will be checked and if
+ * necessary the processing will be restarted. Processing of these chains
+ * can be only interrupted through interrupts.
+ */
+ Chain_Control *volatile insert_chain;
+
+ /**
+ * @brief Indicates that the timer server is active or not.
+ *
+ * The server is active after the delay on a system watchdog. The activity
+ * period of the server ends when no more watchdogs managed by the server
+ * fire. The system watchdogs must not be manipulated when the server is
+ * active.
+ */
+ bool volatile active;
+};
+
+/**
+ * @brief Pointer to default timer server control block.
+ *
+ * This value is @c NULL when the default timer server is not initialized.
+ */
+RTEMS_TIMER_EXTERN Timer_server_Control *volatile _Timer_server;
+
+/**
+ * The following defines the information control block used to manage
+ * this class of objects.
+ */
+RTEMS_TIMER_EXTERN Objects_Information _Timer_Information;
+
+/**
+ * @brief _Timer_Manager_initialization
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Timer_Manager_initialization(void);
+
+/**
+ * @brief rtems_timer_create
+ *
+ * This routine implements the rtems_timer_create directive. The
+ * timer will have the name name. It returns the id of the
+ * created timer in ID.
+ */
+rtems_status_code rtems_timer_create(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_timer_ident
+ *
+ * This routine implements the rtems_timer_ident directive.
+ * This directive returns the timer ID associated with name.
+ * If more than one timer is named name, then the timer
+ * to which the ID belongs is arbitrary.
+ */
+rtems_status_code rtems_timer_ident(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief rtems_timer_cancel
+ *
+ * This routine implements the rtems_timer_cancel directive. It is used
+ * to stop the timer associated with ID from firing.
+ */
+rtems_status_code rtems_timer_cancel(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_timer_delete
+ *
+ * This routine implements the rtems_timer_delete directive. The
+ * timer indicated by ID is deleted.
+ */
+rtems_status_code rtems_timer_delete(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_timer_fire_after
+ *
+ * This routine implements the rtems_timer_fire_after directive. It
+ * initiates the timer associated with ID to fire in ticks clock ticks.
+ * When the timer fires, the routine will be invoked in the context
+ * of the rtems_clock_tick directive which is normally invoked as
+ * part of servicing a periodic interupt.
+ */
+rtems_status_code rtems_timer_fire_after(
+ rtems_id id,
+ rtems_interval ticks,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+);
+
+/**
+ * @brief rtems_timer_server_fire_after
+ *
+ * This routine implements the rtems_timer_server_fire_after directive. It
+ * initiates the timer associated with ID to fire in ticks clock
+ * ticks. When the timer fires, the routine will be invoked by the
+ * Timer Server in the context of a task NOT IN THE CONTEXT of the
+ * clock tick interrupt.
+ */
+rtems_status_code rtems_timer_server_fire_after(
+ rtems_id id,
+ rtems_interval ticks,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+);
+
+/**
+ * @brief rtems_timer_fire_when
+ *
+ * This routine implements the rtems_timer_fire_when directive. It
+ * initiates the timer associated with ID to fire at wall_time
+ * When the timer fires, the routine will be invoked in the context
+ * of the rtems_clock_tick directive which is normally invoked as
+ * part of servicing a periodic interupt.
+ */
+rtems_status_code rtems_timer_fire_when(
+ rtems_id id,
+ rtems_time_of_day *wall_time,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+);
+
+/**
+ * @brief rtems_timer_server_fire_when
+ *
+ * This routine implements the rtems_timer_server_fire_when directive. It
+ * initiates the timer associated with ID to fire at wall_time
+ * When the timer fires, the routine will be invoked by the
+ * Timer Server in the context of a task NOT IN THE CONTEXT of the
+ * clock tick interrupt.
+ */
+rtems_status_code rtems_timer_server_fire_when(
+ rtems_id id,
+ rtems_time_of_day *wall_time,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+);
+
+/**
+ * @brief rtems_timer_reset
+ *
+ * This routine implements the rtems_timer_reset directive. It is used
+ * to reinitialize the interval timer associated with ID just as if
+ * rtems_timer_fire_after were re-invoked with the same arguments that
+ * were used to initiate this timer.
+ */
+rtems_status_code rtems_timer_reset(
+ rtems_id id
+);
+
+/**
+ * @brief rtems_timer_initiate_server
+ *
+ * This routine implements the rtems_timer_initiate_server directive.
+ * It creates and starts the server that executes task-based timers.
+ * It must be invoked before any task-based timers can be initiated.
+ */
+rtems_status_code rtems_timer_initiate_server(
+ uint32_t priority,
+ uint32_t stack_size,
+ rtems_attribute attribute_set
+);
+
+/**
+ * This is the default value for the priority of the Timer Server.
+ * When given this priority, a special high priority not accessible
+ * via the Classic API is used.
+ */
+#define RTEMS_TIMER_SERVER_DEFAULT_PRIORITY (uint32_t) -1
+
+/**
+ * This is the structure filled in by the timer get information
+ * service.
+ */
+typedef struct {
+ /** This indicates the current type of the timer. */
+ Timer_Classes the_class;
+ /** This indicates the initial requested interval. */
+ Watchdog_Interval initial;
+ /** This indicates the time the timer was initially scheduled. */
+ Watchdog_Interval start_time;
+ /** This indicates the time the timer is scheduled to fire. */
+ Watchdog_Interval stop_time;
+} rtems_timer_information;
+
+/**
+ * @brief rtems_timer_get_information
+ *
+ * This routine implements the rtems_timer_get_information directive.
+ * This directive returns information about the timer.
+ */
+rtems_status_code rtems_timer_get_information(
+ rtems_id id,
+ rtems_timer_information *the_info
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/rtems/timer.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/include/rtems/rtems/types.h b/cpukit/rtems/include/rtems/rtems/types.h
new file mode 100644
index 0000000000..2ceeeaa203
--- /dev/null
+++ b/cpukit/rtems/include/rtems/rtems/types.h
@@ -0,0 +1,238 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief Types used by the Classic API.
+ */
+
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_TYPES_H
+#define _RTEMS_RTEMS_TYPES_H
+
+/*
+ * RTEMS basic type definitions
+ */
+
+#include <stdint.h>
+#include <rtems/score/heap.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/modes.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup ClassicRTEMS
+ *
+ * @{
+ */
+
+#ifdef RTEMS_DEPRECATED_TYPES
+/**
+ * @brief Single precision float type.
+ *
+ * @deprecated Use @c float instead.
+ */
+typedef single_precision rtems_single;
+
+/**
+ * @brief Double precision float type.
+ *
+ * @deprecated Use @c double instead.
+ */
+typedef double_precision rtems_double;
+
+/**
+ * @brief RTEMS boolean type.
+ *
+ * @deprecated Use @c bool instead
+ */
+typedef boolean rtems_boolean;
+#endif
+
+/**
+ * @brief Classic API @ref ClassicRTEMSSubSecObjectNames "object name" type.
+ *
+ * Contains the name of a Classic API object. It is an unsigned 32-bit integer
+ * which can be treated as a numeric value or initialized using
+ * rtems_build_name() to contain four ASCII characters.
+ */
+typedef uint32_t rtems_name;
+
+/**
+ * @brief Used to manage and manipulate
+ * @ref ClassicRTEMSSubSecObjectIdentifiers "RTEMS object identifiers".
+ */
+typedef Objects_Id rtems_id;
+
+/**
+ * @brief Invalid object identifier value.
+ *
+ * No object can have this identifier value.
+ */
+#define RTEMS_ID_NONE OBJECTS_ID_NONE
+
+/**
+ * @brief Public name for task context area.
+ */
+typedef Context_Control rtems_context;
+
+#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
+/**
+ * @brief Public name for task floating point context area.
+ */
+typedef Context_Control_fp rtems_context_fp;
+#endif
+
+/**
+ * @brief Defines the format of the interrupt stack frame as it appears to a
+ * user ISR.
+ *
+ * This data structure may not be defined on all ports
+ */
+typedef CPU_Interrupt_frame rtems_interrupt_frame;
+
+/**
+ * @brief Information structure returned by the Heap Handler via the Region
+ * Manager.
+ */
+typedef Heap_Information_block region_information_block;
+
+/**
+ * @brief Used to manage and manipulate intervals specified by
+ * @ref ClassicRTEMSSecTime "clock ticks".
+ */
+typedef Watchdog_Interval rtems_interval;
+
+/**
+ * @brief Represents the CPU usage per thread.
+ *
+ * When using nano seconds granularity timing, RTEMS may internally use a
+ * variety of representations.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ typedef struct timespec rtems_thread_cpu_usage_t;
+#else
+ typedef uint32_t rtems_thread_cpu_usage_t;
+#endif
+
+/**
+ * @brief Data structure to manage and manipulate calendar
+ * @ref ClassicRTEMSSecTime "time".
+ */
+typedef struct {
+ /**
+ * @brief Year, A.D.
+ */
+ uint32_t year;
+ /**
+ * @brief Month, 1 .. 12.
+ */
+ uint32_t month;
+ /**
+ * @brief Day, 1 .. 31.
+ */
+ uint32_t day;
+ /**
+ * @brief Hour, 0 .. 23.
+ */
+ uint32_t hour;
+ /**
+ * @brief Minute, 0 .. 59.
+ */
+ uint32_t minute;
+ /**
+ * @brief Second, 0 .. 59.
+ */
+ uint32_t second;
+ /**
+ * @brief Elapsed ticks between seconds.
+ */
+ uint32_t ticks;
+} rtems_time_of_day;
+
+/**
+ * @brief Task mode type.
+ */
+typedef Modes_Control rtems_mode;
+
+/*
+ * MPCI related entries
+ */
+#if defined(RTEMS_MULTIPROCESSING)
+/**
+ * @brief Set of MPCI packet classes which are internally dispatched to the
+ * managers.
+ */
+typedef MP_packet_Classes rtems_mp_packet_classes;
+
+/**
+ * @brief Prefix found at the beginning of each MPCI packet sent between nodes.
+ */
+typedef MP_packet_Prefix rtems_packet_prefix;
+
+/**
+ * @brief Indirect pointer to the initialization entry point for an MPCI
+ * handler.
+ */
+typedef MPCI_initialization_entry rtems_mpci_initialization_entry;
+
+/**
+ * @brief Indirect pointer to the get_packet entry point for an MPCI handler.
+ */
+typedef MPCI_get_packet_entry rtems_mpci_get_packet_entry;
+
+/**
+ * @brief Indirect pointer to the return_packet entry point for an MPCI
+ * handler.
+ */
+typedef MPCI_return_packet_entry rtems_mpci_return_packet_entry;
+
+/**
+ * @brief Indirect pointer to the send_packet entry point for an MPCI handler.
+ */
+typedef MPCI_send_entry rtems_mpci_send_packet_entry;
+
+/**
+ * @brief Indirect pointer to the receive entry point for an MPCI handler.
+ */
+typedef MPCI_receive_entry rtems_mpci_receive_packet_entry;
+
+/**
+ * @brief Return type from every MPCI handler routine.
+ */
+typedef MPCI_Entry rtems_mpci_entry;
+
+/**
+ * @brief Structure which is used to configure an MPCI handler.
+ */
+typedef MPCI_Control rtems_mpci_table;
+
+#endif
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/asr.inl b/cpukit/rtems/inline/rtems/rtems/asr.inl
new file mode 100644
index 0000000000..93587a312c
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/asr.inl
@@ -0,0 +1,119 @@
+/**
+ * @file rtems/rtems/asr.inl
+ *
+ * This include file contains the implemenation of all routines
+ * associated with the asynchronous signal handler which are inlined.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_ASR_H
+# error "Never use <rtems/rtems/asr.inl> directly; include <rtems/rtems/asr.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_ASR_INL
+#define _RTEMS_RTEMS_ASR_INL
+
+#include <rtems/score/isr.h>
+
+/**
+ * @addtogroup ClassicASR
+ * @{
+ */
+
+/**
+ * @brief ASR_Initialize
+ *
+ * This routine initializes the given RTEMS_ASR information record.
+ */
+RTEMS_INLINE_ROUTINE void _ASR_Initialize (
+ ASR_Information *information
+)
+{
+ information->is_enabled = false;
+ information->handler = NULL;
+ information->mode_set = RTEMS_DEFAULT_MODES;
+ information->signals_posted = 0;
+ information->signals_pending = 0;
+ information->nest_level = 0;
+}
+
+/**
+ * @brief ASR_Swap_signals
+ *
+ * This routine atomically swaps the pending and posted signal
+ * sets. This is done when the thread alters its mode in such a
+ * way that the RTEMS_ASR disable/enable flag changes.
+ */
+RTEMS_INLINE_ROUTINE void _ASR_Swap_signals (
+ ASR_Information *information
+)
+{
+ rtems_signal_set _signals;
+ ISR_Level _level;
+
+ _ISR_Disable( _level );
+ _signals = information->signals_pending;
+ information->signals_pending = information->signals_posted;
+ information->signals_posted = _signals;
+ _ISR_Enable( _level );
+}
+
+/**
+ * @brief ASR_Is_null_handler
+ *
+ * This function returns TRUE if the given asr_handler is NULL and
+ * FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _ASR_Is_null_handler (
+ rtems_asr_entry asr_handler
+)
+{
+ return asr_handler == NULL;
+}
+
+/**
+ * @brief ASR_Are_signals_pending
+ *
+ * This function returns TRUE if there are signals pending in the
+ * given RTEMS_ASR information record and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _ASR_Are_signals_pending (
+ ASR_Information *information
+)
+{
+ return information->signals_posted != 0;
+}
+
+/**
+ * @brief ASR_Post_signals
+ *
+ * This routine posts the given signals into the signal_set
+ * passed in. The result is returned to the user in signal_set.
+ *
+ * NOTE: This must be implemented as a macro.
+ */
+RTEMS_INLINE_ROUTINE void _ASR_Post_signals(
+ rtems_signal_set signals,
+ rtems_signal_set *signal_set
+)
+{
+ ISR_Level _level;
+
+ _ISR_Disable( _level );
+ *signal_set |= signals;
+ _ISR_Enable( _level );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/attr.inl b/cpukit/rtems/inline/rtems/rtems/attr.inl
new file mode 100644
index 0000000000..7a697588da
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/attr.inl
@@ -0,0 +1,197 @@
+/**
+ * @file rtems/rtems/attr.inl
+ *
+ * This include file contains all of the inlined routines associated
+ * with attributes.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_ATTR_H
+# error "Never use <rtems/rtems/attr.inl> directly; include <rtems/rtems/attr.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_ATTR_INL
+#define _RTEMS_RTEMS_ATTR_INL
+
+#include <rtems/score/basedefs.h> /* RTEMS_INLINE_ROUTINE */
+
+/**
+ * @addtogroup ClassicAttributes
+ * @{
+ */
+
+/**
+ * @brief Attributes_Set
+ *
+ * This function sets the requested new_attributes in the attribute_set
+ * passed in. The result is returned to the user.
+ */
+RTEMS_INLINE_ROUTINE rtems_attribute _Attributes_Set (
+ rtems_attribute new_attributes,
+ rtems_attribute attribute_set
+)
+{
+ return attribute_set | new_attributes;
+}
+
+/**
+ * @brief Attributes_Clear
+ *
+ * This function clears the requested new_attributes in the attribute_set
+ * passed in. The result is returned to the user.
+ */
+RTEMS_INLINE_ROUTINE rtems_attribute _Attributes_Clear (
+ rtems_attribute attribute_set,
+ rtems_attribute mask
+)
+{
+ return attribute_set & ~mask;
+}
+
+/**
+ * @brief Attributes_Is_floating_point
+ *
+ * This function returns TRUE if the floating point attribute is
+ * enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_floating_point(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_FLOATING_POINT ) ? true : false;
+}
+
+#if defined(RTEMS_MULTIPROCESSING)
+/**
+ * @brief Attributes_Is_global
+ *
+ * This function returns TRUE if the global object attribute is
+ * enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_global(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_GLOBAL ) ? true : false;
+}
+#endif
+
+/**
+ * @brief Attributes_Is_priority
+ *
+ * This function returns TRUE if the priority attribute is
+ * enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_priority(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_PRIORITY ) ? true : false;
+}
+
+/**
+ * @brief Attributes_Is_binary_semaphore
+ *
+ * This function returns TRUE if the binary semaphore attribute is
+ * enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_binary_semaphore(
+ rtems_attribute attribute_set
+)
+{
+ return ((attribute_set & RTEMS_SEMAPHORE_CLASS) == RTEMS_BINARY_SEMAPHORE);
+}
+
+/**
+ * @brief Attributes_Is_simple_binary_semaphore
+ *
+ * This function returns TRUE if the simple binary semaphore attribute is
+ * enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_simple_binary_semaphore(
+ rtems_attribute attribute_set
+)
+{
+ return
+ ((attribute_set & RTEMS_SEMAPHORE_CLASS) == RTEMS_SIMPLE_BINARY_SEMAPHORE);
+}
+
+/**
+ * @brief Attributes_Is_counting_semaphore
+ *
+ * This function returns TRUE if the counting semaphore attribute is
+ * enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_counting_semaphore(
+ rtems_attribute attribute_set
+)
+{
+ return ((attribute_set & RTEMS_SEMAPHORE_CLASS) == RTEMS_COUNTING_SEMAPHORE);
+}
+
+/**
+ * @brief Attributes_Is_inherit_priority
+ *
+ * This function returns TRUE if the priority inheritance attribute
+ * is enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_inherit_priority(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_INHERIT_PRIORITY ) ? true : false;
+}
+
+/**
+ * @brief Attributes_Is_priority_ceiling
+ *
+ * This function returns TRUE if the priority ceiling attribute
+ * is enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_priority_ceiling(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_PRIORITY_CEILING ) ? true : false;
+}
+
+/**
+ * @brief Attributes_Is_barrier_automatic
+ *
+ * This function returns TRUE if the barrier automatic release
+ * attribute is enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_barrier_automatic(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_BARRIER_AUTOMATIC_RELEASE ) ? true : false;
+}
+
+/**
+ * @brief Attributes_Is_system_task
+ *
+ * This function returns TRUE if the system task attribute
+ * is enabled in the attribute_set and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Attributes_Is_system_task(
+ rtems_attribute attribute_set
+)
+{
+ return ( attribute_set & RTEMS_SYSTEM_TASK ) ? true : false;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/barrier.inl b/cpukit/rtems/inline/rtems/rtems/barrier.inl
new file mode 100644
index 0000000000..3bec0f2075
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/barrier.inl
@@ -0,0 +1,89 @@
+/**
+ * @file rtems/rtems/barrier.inl
+ *
+ * This file contains the static inlin implementation of the inlined
+ * routines from the Barrier Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_BARRIER_H
+# error "Never use <rtems/rtems/barrier.inl> directly; include <rtems/rtems/barrier.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_BARRIER_INL
+#define _RTEMS_RTEMS_BARRIER_INL
+
+/**
+ * @addtogroup ClassicBarrier
+ * @{
+ */
+
+/**
+ * @brief _Barrier_Allocate
+ *
+ * This function allocates a barrier control block from
+ * the inactive chain of free barrier control blocks.
+ */
+RTEMS_INLINE_ROUTINE Barrier_Control *_Barrier_Allocate( void )
+{
+ return (Barrier_Control *) _Objects_Allocate( &_Barrier_Information );
+}
+
+/**
+ * @brief _Barrier_Free
+ *
+ * This routine frees a barrier control block to the
+ * inactive chain of free barrier control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Barrier_Free (
+ Barrier_Control *the_barrier
+)
+{
+ _Objects_Free( &_Barrier_Information, &the_barrier->Object );
+}
+
+/**
+ * @brief _Barrier_Get
+ *
+ * This function maps barrier IDs to barrier control blocks.
+ * If ID corresponds to a local barrier, then it returns
+ * the_barrier control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the barrier ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_barrier is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_barrier is undefined.
+ */
+RTEMS_INLINE_ROUTINE Barrier_Control *_Barrier_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Barrier_Control *)
+ _Objects_Get( &_Barrier_Information, id, location );
+}
+
+/**
+ * @brief _Barrier_Is_null
+ *
+ * This function returns TRUE if the_barrier is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Barrier_Is_null (
+ Barrier_Control *the_barrier
+)
+{
+ return ( the_barrier == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/dpmem.inl b/cpukit/rtems/inline/rtems/rtems/dpmem.inl
new file mode 100644
index 0000000000..5b944484b5
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/dpmem.inl
@@ -0,0 +1,90 @@
+/**
+ * @file rtems/rtems/dpmem.inl
+ *
+ * This include file contains the inline routine used in conjunction
+ * with the Dual Ported Memory Manager
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_DPMEM_H
+# error "Never use <rtems/rtems/dpmem.inl> directly; include <rtems/rtems/dpmem.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_DPMEM_INL
+#define _RTEMS_RTEMS_DPMEM_INL
+
+/**
+ * @addtogroup ClassicDPMEM
+ * @{
+ */
+
+/**
+ * @brief Dual_ported_memory_Allocate
+ *
+ * This routine allocates a port control block from the inactive chain
+ * of free port control blocks.
+ */
+RTEMS_INLINE_ROUTINE Dual_ported_memory_Control
+ *_Dual_ported_memory_Allocate ( void )
+{
+ return (Dual_ported_memory_Control *)
+ _Objects_Allocate( &_Dual_ported_memory_Information );
+}
+
+/**
+ * @brief Dual_ported_memory_Free
+ *
+ * This routine frees a port control block to the inactive chain
+ * of free port control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Dual_ported_memory_Free (
+ Dual_ported_memory_Control *the_port
+)
+{
+ _Objects_Free( &_Dual_ported_memory_Information, &the_port->Object );
+}
+
+/**
+ * @brief Dual_ported_memory_Get
+ *
+ * This function maps port IDs to port control blocks. If ID
+ * corresponds to a local port, then it returns the_port control
+ * pointer which maps to ID and location is set to OBJECTS_LOCAL.
+ * Global ports are not supported, thus if ID does not map to a
+ * local port, location is set to OBJECTS_ERROR and the_port is
+ * undefined.
+ */
+RTEMS_INLINE_ROUTINE Dual_ported_memory_Control *_Dual_ported_memory_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Dual_ported_memory_Control *)
+ _Objects_Get( &_Dual_ported_memory_Information, id, location );
+}
+
+/**
+ * @brief Dual_ported_memory_Is_null
+ *
+ * This function returns true if the_port is NULL and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Dual_ported_memory_Is_null(
+ Dual_ported_memory_Control *the_port
+)
+{
+ return ( the_port == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/event.inl b/cpukit/rtems/inline/rtems/rtems/event.inl
new file mode 100644
index 0000000000..8ea83e2176
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/event.inl
@@ -0,0 +1,33 @@
+/**
+ * @file rtems/rtems/event.inl
+ *
+ * This include file contains the static inline implementation of
+ * macros for the Event Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_EVENT_H
+# error "Never use <rtems/rtems/event.inl> directly; include <rtems/rtems/event.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_EVENT_INL
+#define _RTEMS_RTEMS_EVENT_INL
+
+/**
+ * @addtogroup ClassicEvent
+ * @{
+ */
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/eventset.inl b/cpukit/rtems/inline/rtems/rtems/eventset.inl
new file mode 100644
index 0000000000..dbe869c85d
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/eventset.inl
@@ -0,0 +1,94 @@
+/**
+ * @file rtems/rtems/eventset.inl
+ *
+ * This include file contains the information pertaining to event sets.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_EVENTSET_H
+# error "Never use <rtems/rtems/eventset.inl> directly; include <rtems/rtems/eventset.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_EVENTSET_INL
+#define _RTEMS_RTEMS_EVENTSET_INL
+
+#include <rtems/score/basedefs.h> /* RTEMS_INLINE_ROUTINE */
+#include <rtems/score/isr.h> /* ISR_Level */
+
+/**
+ * @addtogroup ClassicEventSet
+ * @{
+ */
+
+/**
+ * @brief Event_sets_Is_empty
+ *
+ * This function returns TRUE if on events are posted in the event_set,
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Event_sets_Is_empty(
+ rtems_event_set the_event_set
+)
+{
+ return ( the_event_set == 0 );
+}
+
+/**
+ * @brief Event_sets_Post
+ *
+ * This routine posts the given new_events into the event_set
+ * passed in. The result is returned to the user in event_set.
+ */
+RTEMS_INLINE_ROUTINE void _Event_sets_Post(
+ rtems_event_set the_new_events,
+ rtems_event_set *the_event_set
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ *the_event_set |= the_new_events;
+ _ISR_Enable( level );
+}
+
+/**
+ * @brief Event_sets_Get
+ *
+ * This function returns the events in event_condition which are
+ * set in event_set.
+ */
+RTEMS_INLINE_ROUTINE rtems_event_set _Event_sets_Get(
+ rtems_event_set the_event_set,
+ rtems_event_set the_event_condition
+)
+{
+ return ( the_event_set & the_event_condition );
+}
+
+/**
+ * @brief Event_sets_Clear
+ *
+ * This function removes the events in mask from the event_set
+ * passed in. The result is returned to the user in event_set.
+ */
+RTEMS_INLINE_ROUTINE rtems_event_set _Event_sets_Clear(
+ rtems_event_set the_event_set,
+ rtems_event_set the_mask
+)
+{
+ return ( the_event_set & ~(the_mask) );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/message.inl b/cpukit/rtems/inline/rtems/rtems/message.inl
new file mode 100644
index 0000000000..dfaeb25fb3
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/message.inl
@@ -0,0 +1,83 @@
+/**
+ * @file rtems/rtems/message.inl
+ *
+ * This include file contains the static inline implementation of all
+ * inlined routines in the Message Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_MESSAGE_H
+# error "Never use <rtems/rtems/message.inl> directly; include <rtems/rtems/message.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_MESSAGE_INL
+#define _RTEMS_RTEMS_MESSAGE_INL
+
+#include <rtems/score/wkspace.h>
+
+/**
+ * @addtogroup ClassicMessageQueue
+ * @{
+ */
+
+/**
+ * @brief Message_queue_Is_null
+ *
+ * This function places the_message at the rear of the outstanding
+ * messages on the_message_queue.
+ */
+RTEMS_INLINE_ROUTINE bool _Message_queue_Is_null (
+ Message_queue_Control *the_message_queue
+)
+{
+ return ( the_message_queue == NULL );
+}
+
+
+/**
+ * @brief Message_queue_Free
+ *
+ * This routine deallocates a message queue control block into
+ * the inactive chain of free message queue control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Message_queue_Free (
+ Message_queue_Control *the_message_queue
+)
+{
+ _Objects_Free( &_Message_queue_Information, &the_message_queue->Object );
+}
+
+/**
+ * @brief Message_queue_Get
+ *
+ * This function maps message queue IDs to message queue control
+ * blocks. If ID corresponds to a local message queue, then it
+ * returns the_message_queue control pointer which maps to ID
+ * and location is set to OBJECTS_LOCAL. If the message queue ID is
+ * global and resides on a remote node, then location is set
+ * to OBJECTS_REMOTE, and the_message_queue is undefined.
+ * Otherwise, location is set to OBJECTS_ERROR and
+ * the_message_queue is undefined.
+ */
+RTEMS_INLINE_ROUTINE Message_queue_Control *_Message_queue_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Message_queue_Control *)
+ _Objects_Get( &_Message_queue_Information, id, location );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/modes.inl b/cpukit/rtems/inline/rtems/rtems/modes.inl
new file mode 100644
index 0000000000..d0dfe4932b
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/modes.inl
@@ -0,0 +1,136 @@
+/**
+ * @file rtems/rtems/modes.inl
+ *
+ * This include file contains the static inline implementation of the
+ * inlined routines in the Mode Handler
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_MODES_H
+# error "Never use <rtems/rtems/modes.inl> directly; include <rtems/rtems/modes.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_MODES_INL
+#define _RTEMS_RTEMS_MODES_INL
+
+/**
+ * @addtogroup ClassicModes
+ * @{
+ */
+
+/**
+ * @brief Modes_Mask_changed
+ *
+ * This function returns TRUE if any of the mode flags in mask
+ * are set in mode_set, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Modes_Mask_changed (
+ Modes_Control mode_set,
+ Modes_Control masks
+)
+{
+ return ( mode_set & masks ) ? true : false;
+}
+
+/**
+ * @brief Modes_Is_asr_disabled
+ *
+ * This function returns TRUE if mode_set indicates that Asynchronous
+ * Signal Processing is disabled, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Modes_Is_asr_disabled (
+ Modes_Control mode_set
+)
+{
+ return (mode_set & RTEMS_ASR_MASK) == RTEMS_NO_ASR;
+}
+
+/**
+ * @brief Modes_Is_preempt
+ *
+ * This function returns TRUE if mode_set indicates that preemption
+ * is enabled, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Modes_Is_preempt (
+ Modes_Control mode_set
+)
+{
+ return (mode_set & RTEMS_PREEMPT_MASK) == RTEMS_PREEMPT;
+}
+
+/**
+ * @brief Modes_Is_timeslice
+ *
+ * This function returns TRUE if mode_set indicates that timeslicing
+ * is enabled, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Modes_Is_timeslice (
+ Modes_Control mode_set
+)
+{
+ return (mode_set & RTEMS_TIMESLICE_MASK) == RTEMS_TIMESLICE;
+}
+
+/**
+ * @brief Modes_Get_interrupt_level
+ *
+ * This function returns the interrupt level portion of the mode_set.
+ */
+RTEMS_INLINE_ROUTINE ISR_Level _Modes_Get_interrupt_level (
+ Modes_Control mode_set
+)
+{
+ return ( mode_set & RTEMS_INTERRUPT_MASK );
+}
+
+/**
+ * @brief Modes_Set_interrupt_level
+ *
+ * This routine sets the current interrupt level to that specified
+ * in the mode_set.
+ */
+RTEMS_INLINE_ROUTINE void _Modes_Set_interrupt_level (
+ Modes_Control mode_set
+)
+{
+ _ISR_Set_level( _Modes_Get_interrupt_level( mode_set ) );
+}
+
+/**
+ * @brief Modes_Change
+ *
+ * This routine changes the modes in old_mode_set indicated by
+ * mask to the requested values in new_mode_set. The resulting
+ * mode set is returned in out_mode_set and the modes that changed
+ * is returned in changed.
+ */
+RTEMS_INLINE_ROUTINE void _Modes_Change (
+ Modes_Control old_mode_set,
+ Modes_Control new_mode_set,
+ Modes_Control mask,
+ Modes_Control *out_mode_set,
+ Modes_Control *changed
+)
+{
+ Modes_Control _out_mode;
+
+ _out_mode = old_mode_set;
+ _out_mode &= ~mask;
+ _out_mode |= new_mode_set & mask;
+ *changed = _out_mode ^ old_mode_set;
+ *out_mode_set = _out_mode;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/options.inl b/cpukit/rtems/inline/rtems/rtems/options.inl
new file mode 100644
index 0000000000..8d2b406f33
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/options.inl
@@ -0,0 +1,61 @@
+/**
+ * @file rtems/rtems/options.inl
+ *
+ * This file contains the static inline implementation of the inlined
+ * routines from the Options Handler.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_OPTIONS_H
+# error "Never use <rtems/rtems/options.inl> directly; include <rtems/rtems/options.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_OPTIONS_INL
+#define _RTEMS_RTEMS_OPTIONS_INL
+
+#include <rtems/score/basedefs.h> /* RTEMS_INLINE_ROUTINE */
+
+/**
+ * @addtogroup ClassicOptions
+ * @{
+ */
+
+/**
+ * @brief Options_Is_no_wait
+ *
+ * This function returns TRUE if the RTEMS_NO_WAIT option is enabled in
+ * option_set, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Options_Is_no_wait (
+ rtems_option option_set
+)
+{
+ return (option_set & RTEMS_NO_WAIT) ? true : false;
+}
+
+/**
+ * @brief Options_Is_any
+ *
+ * This function returns TRUE if the RTEMS_EVENT_ANY option is enabled in
+ * OPTION_SET, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Options_Is_any (
+ rtems_option option_set
+)
+{
+ return (option_set & RTEMS_EVENT_ANY) ? true : false;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/part.inl b/cpukit/rtems/inline/rtems/rtems/part.inl
new file mode 100644
index 0000000000..eb10dc4e58
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/part.inl
@@ -0,0 +1,175 @@
+/**
+ * @file rtems/rtems/part.inl
+ *
+ * This file contains the macro implementation of all inlined routines
+ * in the Partition Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_PART_H
+# error "Never use <rtems/rtems/part.inl> directly; include <rtems/rtems/part.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_PART_INL
+#define _RTEMS_RTEMS_PART_INL
+
+/**
+ * @addtogroup ClassicPart
+ * @{
+ */
+
+/**
+ * @brief Partition_Allocate_buffer
+ *
+ * This function attempts to allocate a buffer from the_partition.
+ * If successful, it returns the address of the allocated buffer.
+ * Otherwise, it returns NULL.
+ */
+RTEMS_INLINE_ROUTINE void *_Partition_Allocate_buffer (
+ Partition_Control *the_partition
+)
+{
+ return _Chain_Get( &the_partition->Memory );
+}
+
+/**
+ * @brief Partition_Free_buffer
+ *
+ * This routine frees the_buffer to the_partition.
+ */
+RTEMS_INLINE_ROUTINE void _Partition_Free_buffer (
+ Partition_Control *the_partition,
+ Chain_Node *the_buffer
+)
+{
+ _Chain_Append( &the_partition->Memory, the_buffer );
+}
+
+/**
+ * @brief Partition_Is_buffer_on_boundary
+ *
+ * This function returns TRUE if the_buffer is on a valid buffer
+ * boundary for the_partition, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_on_boundary (
+ void *the_buffer,
+ Partition_Control *the_partition
+)
+{
+ uint32_t offset;
+
+ offset = (uint32_t) _Addresses_Subtract(
+ the_buffer,
+ the_partition->starting_address
+ );
+
+ return ((offset % the_partition->buffer_size) == 0);
+}
+
+/**
+ * @brief Partition_Is_buffer_valid
+ *
+ * This function returns TRUE if the_buffer is a valid buffer from
+ * the_partition, otherwise FALSE is returned.
+ */
+RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_valid (
+ Chain_Node *the_buffer,
+ Partition_Control *the_partition
+)
+{
+ void *starting;
+ void *ending;
+
+ starting = the_partition->starting_address;
+ ending = _Addresses_Add_offset( starting, the_partition->length );
+
+ return (
+ _Addresses_Is_in_range( the_buffer, starting, ending ) &&
+ _Partition_Is_buffer_on_boundary( the_buffer, the_partition )
+ );
+}
+
+/**
+ * @brief Partition_Is_buffer_size_aligned
+ *
+ * This function returns TRUE if the use of the specified buffer_size
+ * will result in the allocation of buffers whose first byte is
+ * properly aligned, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_size_aligned (
+ uint32_t buffer_size
+)
+{
+ return ((buffer_size % CPU_PARTITION_ALIGNMENT) == 0);
+}
+
+/**
+ * @brief Partition_Allocate
+ *
+ * This function allocates a partition control block from
+ * the inactive chain of free partition control blocks.
+ */
+RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate ( void )
+{
+ return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
+}
+
+/**
+ * @brief Partition_Free
+ *
+ * This routine frees a partition control block to the
+ * inactive chain of free partition control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Partition_Free (
+ Partition_Control *the_partition
+)
+{
+ _Objects_Free( &_Partition_Information, &the_partition->Object );
+}
+
+/**
+ * @brief Partition_Get
+ *
+ * This function maps partition IDs to partition control blocks.
+ * If ID corresponds to a local partition, then it returns
+ * the_partition control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. If the partition ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_partition is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_partition is undefined.
+ */
+RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Partition_Control *)
+ _Objects_Get( &_Partition_Information, id, location );
+}
+
+/**
+ * @brief Partition_Is_null
+ *
+ * This function returns TRUE if the_partition is NULL
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Partition_Is_null (
+ Partition_Control *the_partition
+)
+{
+ return ( the_partition == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/ratemon.inl b/cpukit/rtems/inline/rtems/rtems/ratemon.inl
new file mode 100644
index 0000000000..2e8964faa1
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/ratemon.inl
@@ -0,0 +1,127 @@
+/**
+ * @file rtems/rtems/ratemon.inl
+ *
+ * This file contains the static inline implementation of the inlined
+ * routines in the Rate Monotonic Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_RATEMON_H
+# error "Never use <rtems/rtems/ratemon.inl> directly; include <rtems/rtems/ratemon.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_RATEMON_INL
+#define _RTEMS_RTEMS_RATEMON_INL
+
+/**
+ * @addtogroup ClassicRateMon
+ * @{
+ */
+
+/**
+ * @brief Rate_monotonic_Allocate
+ *
+ * This function allocates a period control block from
+ * the inactive chain of free period control blocks.
+ */
+RTEMS_INLINE_ROUTINE Rate_monotonic_Control *_Rate_monotonic_Allocate( void )
+{
+ return (Rate_monotonic_Control *)
+ _Objects_Allocate( &_Rate_monotonic_Information );
+}
+
+/**
+ * @brief Rate_monotonic_Free
+ *
+ * This routine allocates a period control block from
+ * the inactive chain of free period control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Rate_monotonic_Free (
+ Rate_monotonic_Control *the_period
+)
+{
+ _Objects_Free( &_Rate_monotonic_Information, &the_period->Object );
+}
+
+/**
+ * @brief Rate_monotonic_Get
+ *
+ * This function maps period IDs to period control blocks.
+ * If ID corresponds to a local period, then it returns
+ * the_period control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. Otherwise, location is set
+ * to OBJECTS_ERROR and the_period is undefined.
+ */
+RTEMS_INLINE_ROUTINE Rate_monotonic_Control *_Rate_monotonic_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Rate_monotonic_Control *)
+ _Objects_Get( &_Rate_monotonic_Information, id, location );
+}
+
+/**
+ * @brief Rate_monotonic_Is_active
+ *
+ * This function returns TRUE if the_period is in the ACTIVE state,
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Rate_monotonic_Is_active (
+ Rate_monotonic_Control *the_period
+)
+{
+ return (the_period->state == RATE_MONOTONIC_ACTIVE);
+}
+
+/**
+ * @brief Rate_monotonic_Is_inactive
+ *
+ * This function returns TRUE if the_period is in the ACTIVE state,
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Rate_monotonic_Is_inactive (
+ Rate_monotonic_Control *the_period
+)
+{
+ return (the_period->state == RATE_MONOTONIC_INACTIVE);
+}
+
+/**
+ * @brief Rate_monotonic_Is_expired
+ *
+ * This function returns TRUE if the_period is in the EXPIRED state,
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Rate_monotonic_Is_expired (
+ Rate_monotonic_Control *the_period
+)
+{
+ return (the_period->state == RATE_MONOTONIC_EXPIRED);
+}
+
+/**
+ * @brief Rate_monotonic_Is_null
+ *
+ * This function returns TRUE if the_period is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Rate_monotonic_Is_null (
+ Rate_monotonic_Control *the_period
+)
+{
+ return (the_period == NULL);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/region.inl b/cpukit/rtems/inline/rtems/rtems/region.inl
new file mode 100644
index 0000000000..e70891378d
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/region.inl
@@ -0,0 +1,115 @@
+/**
+ * @file rtems/rtems/region.inl
+ *
+ * This file contains the macro implementation of the inlined
+ * routines from the Region Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_REGION_H
+# error "Never use <rtems/rtems/region.inl> directly; include <rtems/rtems/region.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_REGION_INL
+#define _RTEMS_RTEMS_REGION_INL
+
+/**
+ * @addtogroup ClassicRegion
+ * @{
+ */
+
+/**
+ * @brief Region_Allocate
+ *
+ * This function allocates a region control block from
+ * the inactive chain of free region control blocks.
+ */
+RTEMS_INLINE_ROUTINE Region_Control *_Region_Allocate( void )
+{
+ return (Region_Control *) _Objects_Allocate( &_Region_Information );
+}
+
+/**
+ * @brief Region_Free
+ *
+ * This routine frees a region control block to the
+ * inactive chain of free region control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Region_Free (
+ Region_Control *the_region
+)
+{
+ _Objects_Free( &_Region_Information, &the_region->Object );
+}
+
+/**
+ * @brief Region_Get
+ *
+ * This function maps region IDs to region control blocks.
+ * If ID corresponds to a local region, then it returns
+ * the_region control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. Otherwise, location is set
+ * to OBJECTS_ERROR and the_region is undefined.
+ */
+RTEMS_INLINE_ROUTINE Region_Control *_Region_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Region_Control *)
+ _Objects_Get_no_protection( &_Region_Information, id, location );
+}
+
+/**
+ * @brief Region_Allocate_segment
+ *
+ * This function attempts to allocate a segment from the_region.
+ * If successful, it returns the address of the allocated segment.
+ * Otherwise, it returns NULL.
+ */
+RTEMS_INLINE_ROUTINE void *_Region_Allocate_segment (
+ Region_Control *the_region,
+ uintptr_t size
+)
+{
+ return _Heap_Allocate( &the_region->Memory, size );
+}
+
+/**
+ * @brief Region_Free_segment
+ *
+ * This function frees the_segment to the_region.
+ */
+RTEMS_INLINE_ROUTINE bool _Region_Free_segment (
+ Region_Control *the_region,
+ void *the_segment
+)
+{
+ return _Heap_Free( &the_region->Memory, the_segment );
+}
+
+/**
+ * @brief Region_Is_null
+ *
+ * This function returns TRUE if the_region is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Region_Is_null (
+ Region_Control *the_region
+)
+{
+ return ( the_region == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/sem.inl b/cpukit/rtems/inline/rtems/rtems/sem.inl
new file mode 100644
index 0000000000..de876d896a
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/sem.inl
@@ -0,0 +1,110 @@
+/**
+ * @file rtems/rtems/sem.inl
+ *
+ * This file contains the static inlin implementation of the inlined
+ * routines from the Semaphore Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SEM_H
+# error "Never use <rtems/rtems/sem.inl> directly; include <rtems/rtems/sem.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_SEM_INL
+#define _RTEMS_RTEMS_SEM_INL
+
+/**
+ * @addtogroup ClassicSem
+ * @{
+ */
+
+/**
+ * @brief Semaphore_Allocate
+ *
+ * This function allocates a semaphore control block from
+ * the inactive chain of free semaphore control blocks.
+ */
+RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Allocate( void )
+{
+ return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information );
+}
+
+/**
+ * @brief Semaphore_Free
+ *
+ * This routine frees a semaphore control block to the
+ * inactive chain of free semaphore control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Semaphore_Free (
+ Semaphore_Control *the_semaphore
+)
+{
+ _Objects_Free( &_Semaphore_Information, &the_semaphore->Object );
+}
+
+/**
+ * @brief Semaphore_Get
+ *
+ * This function maps semaphore IDs to semaphore control blocks.
+ * If ID corresponds to a local semaphore, then it returns
+ * the_semaphore control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the semaphore ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_semaphore is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_semaphore is undefined.
+ */
+RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Semaphore_Control *)
+ _Objects_Get( &_Semaphore_Information, id, location );
+}
+
+/**
+ * @brief Semaphore_Get (Interrupts disabled)
+ *
+ * This function maps semaphore IDs to semaphore control blocks.
+ * If ID corresponds to a local semaphore, then it returns
+ * the_semaphore control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. if the semaphore ID is global and
+ * resides on a remote node, then location is set to OBJECTS_REMOTE,
+ * and the_semaphore is undefined. Otherwise, location is set
+ * to OBJECTS_ERROR and the_semaphore is undefined.
+ */
+RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get_interrupt_disable (
+ Objects_Id id,
+ Objects_Locations *location,
+ ISR_Level *level
+)
+{
+ return (Semaphore_Control *)
+ _Objects_Get_isr_disable( &_Semaphore_Information, id, location, level );
+}
+
+/**
+ * @brief Semaphore_Is_null
+ *
+ * This function returns TRUE if the_semaphore is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Semaphore_Is_null (
+ Semaphore_Control *the_semaphore
+)
+{
+ return ( the_semaphore == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/status.inl b/cpukit/rtems/inline/rtems/rtems/status.inl
new file mode 100644
index 0000000000..a518c102f3
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/status.inl
@@ -0,0 +1,62 @@
+/**
+ * @file rtems/rtems/status.inl
+ *
+ * This include file contains the implementations of the inlined
+ * routines for the status package.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_STATUS_H
+# error "Never use <rtems/rtems/status.inl> directly; include <rtems/rtems/status.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_STATUS_INL
+#define _RTEMS_RTEMS_STATUS_INL
+
+#include <rtems/score/basedefs.h>
+
+/**
+ * @addtogroup ClassicStatus
+ * @{
+ */
+
+/**
+ * @brief rtems_is_status_successful
+ *
+ * This function returns TRUE if the status code is equal to RTEMS_SUCCESSFUL,
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_is_status_successful(
+ rtems_status_code code
+)
+{
+ return (code == RTEMS_SUCCESSFUL);
+}
+
+/**
+ * @brief rtems_are_statuses_equal
+ *
+ * This function returns TRUE if the status code1 is equal to code2,
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_are_statuses_equal(
+ rtems_status_code code1,
+ rtems_status_code code2
+)
+{
+ return (code1 == code2);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/support.inl b/cpukit/rtems/inline/rtems/rtems/support.inl
new file mode 100644
index 0000000000..bd79300e8a
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/support.inl
@@ -0,0 +1,63 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief Classic API support.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_SUPPORT_H
+# error "Never use <rtems/rtems/support.inl> directly; include <rtems/rtems/support.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_SUPPORT_INL
+#define _RTEMS_RTEMS_SUPPORT_INL
+
+/**
+ * @addtogroup ClassicRTEMS
+ *
+ * @{
+ */
+
+/**
+ * @brief Returns @c true if the name is valid, and @c false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_is_name_valid (
+ rtems_name name
+)
+{
+ return ( name != 0 );
+}
+
+/**
+ * @brief Breaks the object name into the four component characters @a c1,
+ * @a c2, @a c3, and @a c4.
+ */
+RTEMS_INLINE_ROUTINE void rtems_name_to_characters(
+ rtems_name name,
+ char *c1,
+ char *c2,
+ char *c3,
+ char *c4
+)
+{
+ *c1 = (char) ((name >> 24) & 0xff);
+ *c2 = (char) ((name >> 16) & 0xff);
+ *c3 = (char) ((name >> 8) & 0xff);
+ *c4 = (char) ( name & 0xff);
+}
+
+/** @} */
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/tasks.inl b/cpukit/rtems/inline/rtems/rtems/tasks.inl
new file mode 100644
index 0000000000..e0fe241d45
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/tasks.inl
@@ -0,0 +1,86 @@
+/**
+ * @file rtems/rtems/tasks.inl
+ *
+ * This file contains the static inline implementation of all inlined
+ * routines in the with RTEMS Tasks Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_TASKS_H
+# error "Never use <rtems/rtems/tasks.inl> directly; include <rtems/rtems/tasks.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_TASKS_INL
+#define _RTEMS_RTEMS_TASKS_INL
+
+/**
+ * @addtogroup ClassicTasks
+ * @{
+ */
+
+/**
+ * @brief RTEMS_tasks_Allocate
+ *
+ * This function allocates a task control block from
+ * the inactive chain of free task control blocks.
+ */
+RTEMS_INLINE_ROUTINE Thread_Control *_RTEMS_tasks_Allocate( void )
+{
+ return (Thread_Control *) _Objects_Allocate( &_RTEMS_tasks_Information );
+}
+
+/**
+ * @brief RTEMS_tasks_Free
+ *
+ * This routine frees a task control block to the
+ * inactive chain of free task control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _RTEMS_tasks_Free (
+ Thread_Control *the_task
+)
+{
+ _Objects_Free(
+ _Objects_Get_information_id( the_task->Object.id ),
+ &the_task->Object
+ );
+}
+
+/**
+ * @brief RTEMS_tasks_Priority_to_Core
+ *
+ * This function converts an RTEMS API priority into a core priority.
+ */
+RTEMS_INLINE_ROUTINE Priority_Control _RTEMS_tasks_Priority_to_Core(
+ rtems_task_priority priority
+)
+{
+ return (Priority_Control) priority;
+}
+
+/**
+ * @brief RTEMS_tasks_Priority_is_valid
+ *
+ * This function returns TRUE if the_priority is a valid user task priority
+ * and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _RTEMS_tasks_Priority_is_valid (
+ rtems_task_priority the_priority
+)
+{
+ return ( ( the_priority >= RTEMS_MINIMUM_PRIORITY ) &&
+ ( the_priority <= RTEMS_MAXIMUM_PRIORITY ) );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/inline/rtems/rtems/timer.inl b/cpukit/rtems/inline/rtems/rtems/timer.inl
new file mode 100644
index 0000000000..10cae3f67d
--- /dev/null
+++ b/cpukit/rtems/inline/rtems/rtems/timer.inl
@@ -0,0 +1,126 @@
+/**
+ * @file rtems/rtems/timer.inl
+ *
+ * This file contains the static inline implementation of the inlined routines
+ * from the Timer Manager.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_RTEMS_TIMER_H
+# error "Never use <rtems/rtems/timer.inl> directly; include <rtems/rtems/timer.h> instead."
+#endif
+
+#ifndef _RTEMS_RTEMS_TIMER_INL
+#define _RTEMS_RTEMS_TIMER_INL
+
+/**
+ * @addtogroup ClassicTimer
+ * @{
+ */
+
+/**
+ * @brief Timer_Allocate
+ *
+ * This function allocates a timer control block from
+ * the inactive chain of free timer control blocks.
+ */
+RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate( void )
+{
+ return (Timer_Control *) _Objects_Allocate( &_Timer_Information );
+}
+
+/**
+ * @brief Timer_Free
+ *
+ * This routine frees a timer control block to the
+ * inactive chain of free timer control blocks.
+ */
+RTEMS_INLINE_ROUTINE void _Timer_Free (
+ Timer_Control *the_timer
+)
+{
+ _Objects_Free( &_Timer_Information, &the_timer->Object );
+}
+
+/**
+ * @brief Timer_Get
+ *
+ * This function maps timer IDs to timer control blocks.
+ * If ID corresponds to a local timer, then it returns
+ * the timer control pointer which maps to ID and location
+ * is set to OBJECTS_LOCAL. Otherwise, location is set
+ * to OBJECTS_ERROR and the returned value is undefined.
+ */
+RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Timer_Control *)
+ _Objects_Get( &_Timer_Information, id, location );
+}
+
+/**
+ * @brief Timer_Is_interval_class
+ *
+ * This function returns TRUE if the class is that of an INTERVAL
+ * timer, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Timer_Is_interval_class (
+ Timer_Classes the_class
+)
+{
+ return (the_class == TIMER_INTERVAL) || (the_class == TIMER_INTERVAL_ON_TASK);
+}
+
+/**
+ * @brief Timer_Is_time_of_day_class
+ *
+ * This function returns TRUE if the class is that of an INTERVAL
+ * timer, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Timer_Is_timer_of_day_class (
+ Timer_Classes the_class
+)
+{
+ return ( the_class == TIMER_TIME_OF_DAY );
+}
+
+/**
+ * @brief Timer_Is_dormant_class
+ *
+ * This function returns TRUE if the class is that of a DORMANT
+ * timer, and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Timer_Is_dormant_class (
+ Timer_Classes the_class
+)
+{
+ return ( the_class == TIMER_DORMANT );
+}
+
+/**
+ * @brief Timer_Is_null
+ *
+ * This function returns TRUE if the_timer is NULL and FALSE otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Timer_Is_null (
+ Timer_Control *the_timer
+)
+{
+ return ( the_timer == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/rtems/mainpage.h b/cpukit/rtems/mainpage.h
new file mode 100644
index 0000000000..fe8f627c36
--- /dev/null
+++ b/cpukit/rtems/mainpage.h
@@ -0,0 +1,950 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/**
+ * @mainpage
+ *
+ * The RTEMS real-time operating systems is a layered system with each of the
+ * public APIs implemented in terms of a common foundation layer called the
+ * SuperCore. This is the Doxygen generated documentation for the RTEMS CPU
+ * Kit including the Classic API, POSIX API and SuperCore.
+ */
+
+/**
+ * @page RTEMSPreface RTEMS History and Introduction
+ *
+ * In recent years, the cost required to develop a software product has
+ * increased significantly while the target hardware costs have decreased. Now
+ * a larger portion of money is expended in developing, using, and maintaining
+ * software. The trend in computing costs is the complete dominance of software
+ * over hardware costs. Because of this, it is necessary that formal
+ * disciplines be established to increase the probability that software is
+ * characterized by a high degree of correctness, maintainability, and
+ * portability. In addition, these disciplines must promote practices that aid
+ * in the consistent and orderly development of a software system within
+ * schedule and budgetary constraints. To be effective, these disciplines must
+ * adopt standards which channel individual software efforts toward a common
+ * goal.
+ *
+ * The push for standards in the software development field has been met with
+ * various degrees of success. The Microprocessor Operating Systems Interfaces
+ * (MOSI) effort has experienced only limited success. As popular as the UNIX
+ * operating system has grown, the attempt to develop a standard interface
+ * definition to allow portable application development has only recently begun
+ * to produce the results needed in this area. Unfortunately, very little
+ * effort has been expended to provide standards addressing the needs of the
+ * real-time community. Several organizations have addressed this need during
+ * recent years.
+ *
+ * The Real Time Executive Interface Definition (RTEID) was developed by
+ * Motorola with technical input from Software Components Group. RTEID was
+ * adopted by the VMEbus International Trade Association (VITA) as a baseline
+ * draft for their proposed standard multiprocessor, real-time executive
+ * interface, Open Real-Time Kernel Interface Definition (ORKID). These two
+ * groups are currently working together with the IEEE P1003.4 committee to
+ * insure that the functionality of their proposed standards is adopted as the
+ * real-time extensions to POSIX.
+ *
+ * This emerging standard defines an interface for the development of real-time
+ * software to ease the writing of real-time application programs that are
+ * directly portable across multiple real-time executive implementations. This
+ * interface includes both the source code interfaces and run-time behavior as
+ * seen by a real-time application. It does not include the details of how a
+ * kernel implements these functions. The standard's goal is to serve as a
+ * complete definition of external interfaces so that application code that
+ * conforms to these interfaces will execute properly in all real-time
+ * executive environments. With the use of a standards compliant executive,
+ * routines that acquire memory blocks, create and manage message queues,
+ * establish and use semaphores, and send and receive signals need not be
+ * redeveloped for a different real-time environment as long as the new
+ * environment is compliant with the standard. Software developers need only
+ * concentrate on the hardware dependencies of the real-time system.
+ * Furthermore, most hardware dependencies for real-time applications can be
+ * localized to the device drivers.
+ *
+ * A compliant executive provides simple and flexible real-time
+ * multiprocessing. It easily lends itself to both tightly-coupled and
+ * loosely-coupled configurations (depending on the system hardware
+ * configuration). Objects such as tasks, queues, events, signals, semaphores,
+ * and memory blocks can be designated as global objects and accessed by any
+ * task regardless of which processor the object and the accessing task reside.
+ *
+ * The acceptance of a standard for real-time executives will produce the same
+ * advantages enjoyed from the push for UNIX standardization by AT&T's System V
+ * Interface Definition and IEEE's POSIX efforts. A compliant multiprocessing
+ * executive will allow close coupling between UNIX systems and real-time
+ * executives to provide the many benefits of the UNIX development environment
+ * to be applied to real-time software development. Together they provide the
+ * necessary laboratory environment to implement real-time, distributed,
+ * embedded systems using a wide variety of computer architectures.
+ *
+ * A study was completed in 1988, within the Research, Development, and
+ * Engineering Center, U.S. Army Missile Command, which compared the various
+ * aspects of the Ada programming language as they related to the application
+ * of Ada code in distributed and/or multiple processing systems. Several
+ * critical conclusions were derived from the study. These conclusions have a
+ * major impact on the way the Army develops application software for embedded
+ * applications. These impacts apply to both in-house software development and
+ * contractor developed software.
+ *
+ * A conclusion of the analysis, which has been previously recognized by other
+ * agencies attempting to utilize Ada in a distributed or multiprocessing
+ * environment, is that the Ada programming language does not adequately
+ * support multiprocessing. Ada does provide a mechanism for multi-tasking,
+ * however, this capability exists only for a single processor system. The
+ * language also does not have inherent capabilities to access global named
+ * variables, flags or program code. These critical features are essential in
+ * order for data to be shared between processors. However, these drawbacks do
+ * have workarounds which are sometimes awkward and defeat the intent of
+ * software maintainability and portability goals.
+ *
+ * Another conclusion drawn from the analysis, was that the run time executives
+ * being delivered with the Ada compilers were too slow and inefficient to be
+ * used in modern missile systems. A run time executive is the core part of the
+ * run time system code, or operating system code, that controls task
+ * scheduling, input/output management and memory management. Traditionally,
+ * whenever efficient executive (also known as kernel) code was required by the
+ * application, the user developed in-house software. This software was usually
+ * written in assembly language for optimization.
+ *
+ * Because of this shortcoming in the Ada programming language, software
+ * developers in research and development and contractors for project managed
+ * systems, are mandated by technology to purchase and utilize off-the-shelf
+ * third party kernel code. The contractor, and eventually the Government, must
+ * pay a licensing fee for every copy of the kernel code used in an embedded
+ * system.
+ *
+ * The main drawback to this development environment is that the Government
+ * does not own, nor has the right to modify code contained within the kernel.
+ * V&V techniques in this situation are more difficult than if the complete
+ * source code were available. Responsibility for system failures due to faulty
+ * software is yet another area to be resolved under this environment.
+ *
+ * The Guidance and Control Directorate began a software development effort to
+ * address these problems. A project to develop an experimental run time kernel
+ * was begun that will eliminate the major drawbacks of the Ada programming
+ * language mentioned above. The Real Time Executive for Multiprocessor Systems
+ * (RTEMS) provides full capabilities for management of tasks, interrupts,
+ * time, and multiple processors in addition to those features typical of
+ * generic operating systems. The code is Government owned, so no licensing
+ * fees are necessary. RTEMS has been implemented in both the Ada and C
+ * programming languages. It has been ported to the following processor
+ * families:
+ *
+ * - Altera NIOS II
+ * - Analog Devices Blackfin
+ * - ARM
+ * - Freescale (formerly Motorola) MC68xxx
+ * - Freescale (formerly Motorola) MC683xx
+ * - Freescale (formerly Motorola) ColdFire
+ * - Intel i386 and above
+ * - Lattice Semiconductor LM32
+ * - MIPS
+ * - PowerPC
+ * - Renesas (formerly Hitachi) SuperH
+ * - Renesas (formerly Hitachi) H8/300
+ * - SPARC
+ * - Texas Instruments C3x/C4x
+ * - UNIX
+ *
+ * Support for other processor families, including RISC, CISC, and DSP, is
+ * planned. Since almost all of RTEMS is written in a high level language,
+ * ports to additional processor families require minimal effort.
+ *
+ * RTEMS multiprocessor support is capable of handling either homogeneous or
+ * heterogeneous systems. The kernel automatically compensates for
+ * architectural differences (byte swapping, etc.) between processors. This
+ * allows a much easier transition from one processor family to another without
+ * a major system redesign.
+ *
+ * Since the proposed standards are still in draft form, RTEMS cannot and does
+ * not claim compliance. However, the status of the standard is being carefully
+ * monitored to guarantee that RTEMS provides the functionality specified in
+ * the standard. Once approved, RTEMS will be made compliant.
+ */
+
+/**
+ * @page RTEMSOverview RTEMS Overview
+ *
+ * @section RTEMSOverviewSecIntroduction Introduction
+ *
+ * RTEMS, Real-Time Executive for Multiprocessor Systems, is a real-time
+ * executive (kernel) which provides a high performance environment for
+ * embedded military applications including the following features:
+ *
+ * - multitasking capabilities
+ * - homogeneous and heterogeneous multiprocessor systems
+ * - event-driven, priority-based, preemptive scheduling
+ * - optional rate monotonic scheduling
+ * - intertask communication and synchronization
+ * - priority inheritance
+ * - responsive interrupt management
+ * - dynamic memory allocation
+ * - high level of user configurability
+ *
+ * This manual describes the usage of RTEMS for applications written in the C
+ * programming language. Those implementation details that are processor
+ * dependent are provided in the Applications Supplement documents. A
+ * supplement document which addresses specific architectural issues that
+ * affect RTEMS is provided for each processor type that is supported.
+ *
+ * @section RTEMSOverviewSecRealtimeApplicationSystems Real-time Application Systems
+ *
+ * Real-time application systems are a special class of computer applications.
+ * They have a complex set of characteristics that distinguish them from other
+ * software problems. Generally, they must adhere to more rigorous
+ * requirements. The correctness of the system depends not only on the results
+ * of computations, but also on the time at which the results are produced. The
+ * most important and complex characteristic of real-time application systems
+ * is that they must receive and respond to a set of external stimuli within
+ * rigid and critical time constraints referred to as deadlines. Systems can be
+ * buried by an avalanche of interdependent, asynchronous or cyclical event
+ * streams.
+ *
+ * Deadlines can be further characterized as either hard or soft based upon the
+ * value of the results when produced after the deadline has passed. A deadline
+ * is hard if the results have no value or if their use will result in a
+ * catastrophic event. In contrast, results which are produced after a soft
+ * deadline may have some value.
+ *
+ * Another distinguishing requirement of real-time application systems is the
+ * ability to coordinate or manage a large number of concurrent activities.
+ * Since software is a synchronous entity, this presents special problems. One
+ * instruction follows another in a repeating synchronous cycle. Even though
+ * mechanisms have been developed to allow for the processing of external
+ * asynchronous events, the software design efforts required to process and
+ * manage these events and tasks are growing more complicated.
+ *
+ * The design process is complicated further by spreading this activity over a
+ * set of processors instead of a single processor. The challenges associated
+ * with designing and building real-time application systems become very
+ * complex when multiple processors are involved. New requirements such as
+ * interprocessor communication channels and global resources that must be
+ * shared between competing processors are introduced. The ramifications of
+ * multiple processors complicate each and every characteristic of a real-time
+ * system.
+ *
+ * @section RTEMSOverviewSecRealtimeExecutive Real-time Executive
+ *
+ * Fortunately, real-time operating systems or real-time executives serve as a
+ * cornerstone on which to build the application system. A real-time
+ * multitasking executive allows an application to be cast into a set of
+ * logical, autonomous processes or tasks which become quite manageable. Each
+ * task is internally synchronous, but different tasks execute independently,
+ * resulting in an asynchronous processing stream. Tasks can be dynamically
+ * paused for many reasons resulting in a different task being allowed to
+ * execute for a period of time. The executive also provides an interface to
+ * other system components such as interrupt handlers and device drivers.
+ * System components may request the executive to allocate and coordinate
+ * resources, and to wait for and trigger synchronizing conditions. The
+ * executive system calls effectively extend the CPU instruction set to support
+ * efficient multitasking. By causing tasks to travel through well-defined
+ * state transitions, system calls permit an application to demand-switch
+ * between tasks in response to real-time events.
+ *
+ * By proper grouping of responses to stimuli into separate tasks, a system can
+ * now asynchronously switch between independent streams of execution, directly
+ * responding to external stimuli as they occur. This allows the system design
+ * to meet critical performance specifications which are typically measured by
+ * guaranteed response time and transaction throughput. The multiprocessor
+ * extensions of RTEMS provide the features necessary to manage the extra
+ * requirements introduced by a system distributed across several processors.
+ * It removes the physical barriers of processor boundaries from the world of
+ * the system designer, enabling more critical aspects of the system to receive
+ * the required attention. Such a system, based on an efficient real-time,
+ * multiprocessor executive, is a more realistic model of the outside world or
+ * environment for which it is designed. As a result, the system will always be
+ * more logical, efficient, and reliable.
+ *
+ * By using the directives provided by RTEMS, the real-time applications
+ * developer is freed from the problem of controlling and synchronizing
+ * multiple tasks and processors. In addition, one need not develop, test,
+ * debug, and document routines to manage memory, pass messages, or provide
+ * mutual exclusion. The developer is then able to concentrate solely on the
+ * application. By using standard software components, the time and cost
+ * required to develop sophisticated real-time applications is significantly
+ * reduced.
+ *
+ * @section RTEMSOverviewSecApplicationArchitecture RTEMS Application Architecture
+ *
+ * One important design goal of RTEMS was to provide a bridge between two
+ * critical layers of typical real-time systems. As shown in the following
+ * figure, RTEMS serves as a buffer between the project dependent application
+ * code and the target hardware. Most hardware dependencies for real-time
+ * applications can be localized to the low level device drivers.
+ *
+ * @todo Image RTEMS Application Architecture
+ *
+ * The RTEMS I/O interface manager provides an efficient tool for incorporating
+ * these hardware dependencies into the system while simultaneously providing a
+ * general mechanism to the application code that accesses them. A well
+ * designed real-time system can benefit from this architecture by building a
+ * rich library of standard application components which can be used repeatedly
+ * in other real-time projects.
+ *
+ * @section RTEMSOverviewSecInternalArchitecture RTEMS Internal Architecture
+ *
+ * RTEMS can be viewed as a set of layered components that work in harmony to
+ * provide a set of services to a real-time application system. The executive
+ * interface presented to the application is formed by grouping directives into
+ * logical sets called resource managers. Functions utilized by multiple
+ * managers such as scheduling, dispatching, and object management are provided
+ * in the executive core. The executive core depends on a small set of CPU
+ * dependent routines. Together these components provide a powerful run time
+ * environment that promotes the development of efficient real-time application
+ * systems. The following figure illustrates this organization:
+ *
+ * @todo Image RTEMS Architecture
+ *
+ * Subsequent chapters present a detailed description of the capabilities
+ * provided by each of the following RTEMS managers:
+ *
+ * - initialization
+ * - task
+ * - interrupt
+ * - clock
+ * - timer
+ * - semaphore
+ * - message
+ * - event
+ * - signal
+ * - partition
+ * - region
+ * - dual ported memory
+ * - I/O
+ * - fatal error
+ * - rate monotonic
+ * - user extensions
+ * - multiprocessing
+ *
+ * @section RTEMSOverviewSecUserCustomization User Customization and Extensibility
+ *
+ * As 32-bit microprocessors have decreased in cost, they have become
+ * increasingly common in a variety of embedded systems. A wide range of custom
+ * and general-purpose processor boards are based on various 32-bit
+ * processors. RTEMS was designed to make no assumptions concerning the
+ * characteristics of individual microprocessor families or of specific support
+ * hardware. In addition, RTEMS allows the system developer a high degree of
+ * freedom in customizing and extending its features.
+ *
+ * RTEMS assumes the existence of a supported microprocessor and sufficient
+ * memory for both RTEMS and the real-time application. Board dependent
+ * components such as clocks, interrupt controllers, or I/O devices can be
+ * easily integrated with RTEMS. The customization and extensibility features
+ * allow RTEMS to efficiently support as many environments as possible.
+ *
+ * @section RTEMSOverviewSecPortability Portability
+ *
+ * The issue of portability was the major factor in the creation of RTEMS.
+ * Since RTEMS is designed to isolate the hardware dependencies in the specific
+ * board support packages, the real-time application should be easily ported to
+ * any other processor. The use of RTEMS allows the development of real-time
+ * applications which can be completely independent of a particular
+ * microprocessor architecture.
+ *
+ * @section RTEMSOverviewSecMemoryRequirements Memory Requirements
+ *
+ * Since memory is a critical resource in many real-time embedded systems,
+ * RTEMS was specifically designed to automatically leave out all services that
+ * are not required from the run-time environment. Features such as networking,
+ * various fileystems, and many other features are completely optional. This
+ * allows the application designer the flexibility to tailor RTEMS to most
+ * efficiently meet system requirements while still satisfying even the most
+ * stringent memory constraints. As a result, the size of the RTEMS executive
+ * is application dependent.
+ *
+ * RTEMS requires RAM to manage each instance of an RTEMS object that is
+ * created. Thus the more RTEMS objects an application needs, the more memory
+ * that must be reserved. See Configuring a System Determining Memory
+ * Requirements for more details.
+ *
+ * @todo Link to Configuring a SystemDetermining Memory Requirements
+ *
+ * RTEMS utilizes memory for both code and data space. Although RTEMS' data
+ * space must be in RAM, its code space can be located in either ROM or RAM.
+ *
+ * @section RTEMSOverviewSecAudience Audience
+ *
+ * This manual was written for experienced real-time software developers.
+ * Although some background is provided, it is assumed that the reader is
+ * familiar with the concepts of task management as well as intertask
+ * communication and synchronization. Since directives, user related data
+ * structures, and examples are presented in C, a basic understanding of the C
+ * programming language is required to fully understand the material presented.
+ * However, because of the similarity of the Ada and C RTEMS implementations,
+ * users will find that the use and behavior of the two implementations is very
+ * similar. A working knowledge of the target processor is helpful in
+ * understanding some of RTEMS' features. A thorough understanding of the
+ * executive cannot be obtained without studying the entire manual because many
+ * of RTEMS' concepts and features are interrelated. Experienced RTEMS users
+ * will find that the manual organization facilitates its use as a reference
+ * document.
+ *
+ */
+
+/**
+ * @addtogroup ClassicRTEMS
+ *
+ * The facilities provided by RTEMS are built upon a foundation of very
+ * powerful concepts. These concepts must be understood before the application
+ * developer can efficiently utilize RTEMS. The purpose of this chapter is to
+ * familiarize one with these concepts.
+ *
+ * @section ClassicRTEMSSecObjects Objects
+ *
+ * RTEMS provides directives which can be used to dynamically create, delete,
+ * and manipulate a set of predefined object types. These types include tasks,
+ * message queues, semaphores, memory regions, memory partitions, timers,
+ * ports, and rate monotonic periods. The object-oriented nature of RTEMS
+ * encourages the creation of modular applications built upon re-usable
+ * "building block" routines.
+ *
+ * All objects are created on the local node as required by the application and
+ * have an RTEMS assigned ID. All objects have a user-assigned name. Although a
+ * relationship exists between an object's name and its RTEMS assigned ID, the
+ * name and ID are not identical. Object names are completely arbitrary and
+ * selected by the user as a meaningful "tag" which may commonly reflect the
+ * object's use in the application. Conversely, object IDs are designed to
+ * facilitate efficient object manipulation by the executive.
+ *
+ * @subsection ClassicRTEMSSubSecObjectNames Object Names
+ *
+ * An object name is an unsigned 32-bit entity associated with the
+ * object by the user. The data type @ref rtems_name is used to store object names.
+ *
+ * Although not required by RTEMS, object names are often composed of four
+ * ASCII characters which help identify that object. For example, a task which
+ * causes a light to blink might be called "LITE". The rtems_build_name()
+ * routine is provided to build an object name from four ASCII characters. The
+ * following example illustrates this:
+ *
+ * @code
+ * rtems_name my_name = rtems_build_name('L', 'I', 'T', 'E');
+ * @endcode
+ *
+ * However, it is not required that the application use ASCII characters to
+ * build object names. For example, if an application requires one-hundred
+ * tasks, it would be difficult to assign meaningful ASCII names to each task.
+ * A more convenient approach would be to name them the binary values one
+ * through one-hundred, respectively.
+ *
+ * RTEMS provides a helper routine, rtems_object_get_name(), which can be used to
+ * obtain the name of any RTEMS object using just its ID. This routine attempts
+ * to convert the name into a printable string.
+ *
+ * @subsection ClassicRTEMSSubSecObjectIdentifiers Object Identifiers
+ *
+ * An object ID is a unique unsigned integer value which uniquely identifies an
+ * object instance. Object IDs are passed as arguments to many directives in
+ * RTEMS and RTEMS translates the ID to an internal object pointer. The
+ * efficient manipulation of object IDs is critical to the performance of RTEMS
+ * services. Because of this, there are two object ID formats defined. Each
+ * target architecture specifies which format it will use. There is a 32-bit
+ * format which is used for most of the supported architectures and supports
+ * multiprocessor configurations. There is also a simpler 16-bit format which
+ * is appropriate for smaller target architectures and does not support
+ * multiprocessor configurations.
+ *
+ * @subsubsection ClassicRTEMSSubSec32BitObjectIdentifierFormat 32-Bit Object Identifier Format
+ *
+ * The 32-bit format for an object ID is composed of four parts: API,
+ * object class, node, and index. The data type @ref rtems_id is used to store
+ * object IDs.
+ *
+ * <table>
+ * <tr>
+ * <th>Bits</th>
+ * <td>31</td><td>30</td><td>29</td><td>28</td><td>27</td><td>26</td><td>25</td><td>24</td>
+ * <td>23</td><td>22</td><td>21</td><td>20</td><td>19</td><td>18</td><td>17</td><td>16</td>
+ * <td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>09</td><td>08</td>
+ * <td>07</td><td>06</td><td>05</td><td>04</td><td>03</td><td>02</td><td>01</td><td>00</td>
+ * </tr>
+ * <tr>
+ * <th>Contents</th>
+ * <td colspan=5>Class</td><td colspan=3>API</td><td colspan=8>Node</td><td colspan=16>Object Index</td>
+ * </tr>
+ * </table>
+ *
+ * The most significant five bits are the object class. The next three bits
+ * indicate the API to which the object class belongs. The next eight bits
+ * (16 .. 23) are the number of the node on which this object was created. The
+ * node number is always one (1) in a single processor system. The least
+ * significant 16-bits form an identifier within a particular object type.
+ * This identifier, called the object index, ranges in value from one to the
+ * maximum number of objects configured for this object type.
+ *
+ * @subsubsection ClassicRTEMSSubSec16BitObjectIdentifierFormat 16-Bit Object Identifier Format
+ *
+ * The 16-bit format for an object ID is composed of three parts: API, object
+ * class, and index. The data type @ref rtems_id is used to store object IDs.
+ *
+ * <table>
+ * <tr>
+ * <th>Bits</th>
+ * <td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>09</td><td>08</td>
+ * <td>07</td><td>06</td><td>05</td><td>04</td><td>03</td><td>02</td><td>01</td><td>00</td>
+ * </tr>
+ * <tr>
+ * <th>Contents</th>
+ * <td colspan=5>Class</td><td colspan=3>API</td><td colspan=8>Object Index</td>
+ * </tr>
+ * </table>
+ *
+ * The 16-bit format is designed to be as similar as possible to the 32-bit
+ * format. The differences are limited to the eliminatation of the node field
+ * and reduction of the index field from 16-bits to 8-bits. Thus the 16-bit
+ * format only supports up to 255 object instances per API/Class combination
+ * and single processor systems. As this format is typically utilized by 16-bit
+ * processors with limited address space, this is more than enough object
+ * instances.
+ *
+ * @subsection ClassicRTEMSSubSecObjectIdentiferDescription Object Identifer Description
+ *
+ * The components of an object ID make it possible to quickly locate any object
+ * in even the most complicated multiprocessor system. Object ID's are
+ * associated with an object by RTEMS when the object is created and the
+ * corresponding ID is returned by the appropriate object create directive. The
+ * object ID is required as input to all directives involving objects, except
+ * those which create an object or obtain the ID of an object.
+ *
+ * The object identification directives can be used to dynamically obtain a
+ * particular object's ID given its name. This mapping is accomplished by
+ * searching the name table associated with this object type. If the name is
+ * non-unique, then the ID associated with the first occurrence of the name
+ * will be returned to the application. Since object IDs are returned when the
+ * object is created, the object identification directives are not necessary in
+ * a properly designed single processor application.
+ *
+ * In addition, services are provided to portably examine the subcomponents of
+ * an RTEMS ID. These services are described in detail later in this manual but
+ * are prototyped as follows:
+ *
+ * - rtems_object_id_get_api()
+ * - rtems_object_id_get_class()
+ * - rtems_object_id_get_node()
+ * - rtems_object_id_get_index()
+ *
+ * An object control block is a data structure defined by RTEMS which contains
+ * the information necessary to manage a particular object type. For efficiency
+ * reasons, the format of each object type's control block is different.
+ * However, many of the fields are similar in function. The number of each type
+ * of control block is application dependent and determined by the values
+ * specified in the user's Configuration Table. An object control block is
+ * allocated at object create time and freed when the object is deleted. With
+ * the exception of user extension routines, object control blocks are not
+ * directly manipulated by user applications.
+ *
+ * @section ClassicRTEMSSecComSync Communication and Synchronization
+ *
+ * In real-time multitasking applications, the ability for cooperating
+ * execution threads to communicate and synchronize with each other is
+ * imperative. A real-time executive should provide an application with the
+ * following capabilities
+ *
+ * - data transfer between cooperating tasks,
+ * - data transfer between tasks and ISRs,
+ * - synchronization of cooperating tasks, and
+ * - synchronization of tasks and ISRs.
+ *
+ * Most RTEMS managers can be used to provide some form of communication and/or
+ * synchronization. However, managers dedicated specifically to communication
+ * and synchronization provide well established mechanisms which directly map
+ * to the application's varying needs. This level of flexibility allows the
+ * application designer to match the features of a particular manager with the
+ * complexity of communication and synchronization required. The following
+ * managers were specifically designed for communication and synchronization:
+ *
+ * - @ref ClassicSem
+ * - @ref ClassicMessageQueue
+ * - @ref ClassicEvent
+ * - @ref ClassicSignal
+ *
+ * The semaphore manager supports mutual exclusion involving the
+ * synchronization of access to one or more shared user resources. Binary
+ * semaphores may utilize the optional priority inheritance algorithm to avoid
+ * the problem of priority inversion. The message manager supports both
+ * communication and synchronization, while the event manager primarily
+ * provides a high performance synchronization mechanism. The signal manager
+ * supports only asynchronous communication and is typically used for exception
+ * handling.
+ *
+ * @section ClassicRTEMSSecTime Time
+ *
+ * The development of responsive real-time applications requires an
+ * understanding of how RTEMS maintains and supports time-related operations.
+ * The basic unit of time in RTEMS is known as a tick. The frequency of clock
+ * ticks is completely application dependent and determines the granularity and
+ * accuracy of all interval and calendar time operations.
+ *
+ * By tracking time in units of ticks, RTEMS is capable of supporting interval
+ * timing functions such as task delays, timeouts, timeslicing, the delayed
+ * execution of timer service routines, and the rate monotonic scheduling of
+ * tasks. An interval is defined as a number of ticks relative to the current
+ * time. For example, when a task delays for an interval of ten ticks, it is
+ * implied that the task will not execute until ten clock ticks have occurred.
+ * All intervals are specified using data type @ref rtems_interval.
+ *
+ * A characteristic of interval timing is that the actual interval period may
+ * be a fraction of a tick less than the interval requested. This occurs
+ * because the time at which the delay timer is set up occurs at some time
+ * between two clock ticks. Therefore, the first countdown tick occurs in less
+ * than the complete time interval for a tick. This can be a problem if the
+ * clock granularity is large.
+ *
+ * The rate monotonic scheduling algorithm is a hard real-time scheduling
+ * methodology. This methodology provides rules which allows one to guarantee
+ * that a set of independent periodic tasks will always meet their deadlines --
+ * even under transient overload conditions. The rate monotonic manager
+ * provides directives built upon the Clock Manager's interval timer support
+ * routines.
+ *
+ * Interval timing is not sufficient for the many applications which require
+ * that time be kept in wall time or true calendar form. Consequently, RTEMS
+ * maintains the current date and time. This allows selected time operations to
+ * be scheduled at an actual calendar date and time. For example, a task could
+ * request to delay until midnight on New Year's Eve before lowering the ball
+ * at Times Square. The data type @ref rtems_time_of_day is used to specify
+ * calendar time in RTEMS services. See Clock Manager Time and Date Data
+ * Structures.
+ *
+ * @todo Link to Clock Manager Time and Date Data Structures
+ *
+ * Obviously, the directives which use intervals or wall time cannot operate
+ * without some external mechanism which provides a periodic clock tick. This
+ * clock tick is typically provided by a real time clock or counter/timer
+ * device.
+ *
+ * @section ClassicRTEMSSecMemoryManagement Memory Management
+ *
+ * RTEMS memory management facilities can be grouped into two classes: dynamic
+ * memory allocation and address translation. Dynamic memory allocation is
+ * required by applications whose memory requirements vary through the
+ * application's course of execution. Address translation is needed by
+ * applications which share memory with another CPU or an intelligent
+ * Input/Output processor. The following RTEMS managers provide facilities to
+ * manage memory:
+ *
+ * - @ref ClassicRegion
+ * - @ref ClassicPart
+ * - @ref ClassicDPMEM
+ *
+ * RTEMS memory management features allow an application to create simple
+ * memory pools of fixed size buffers and/or more complex memory pools of
+ * variable size segments. The partition manager provides directives to manage
+ * and maintain pools of fixed size entities such as resource control blocks.
+ * Alternatively, the region manager provides a more general purpose memory
+ * allocation scheme that supports variable size blocks of memory which are
+ * dynamically obtained and freed by the application. The dual-ported memory
+ * manager provides executive support for address translation between internal
+ * and external dual-ported RAM address space.
+ */
+
+/**
+ * @addtogroup ClassicTasks
+ *
+ * @section ClassicTasksSecTaskDefinition Task Definition
+ *
+ * Many definitions of a task have been proposed in computer literature.
+ * Unfortunately, none of these definitions encompasses all facets of the
+ * concept in a manner which is operating system independent. Several of the
+ * more common definitions are provided to enable each user to select a
+ * definition which best matches their own experience and understanding of the
+ * task concept:
+ *
+ * - a "dispatchable" unit.
+ * - an entity to which the processor is allocated.
+ * - an atomic unit of a real-time, multiprocessor system.
+ * - single threads of execution which concurrently compete for resources.
+ * - a sequence of closely related computations which can execute concurrently
+ * with other computational sequences.
+ *
+ * From RTEMS' perspective, a task is the smallest thread of execution which
+ * can compete on its own for system resources. A task is manifested by the
+ * existence of a task control block (TCB).
+ *
+ * @section ClassicTasksSecTaskControlBlock Task Control Block
+ *
+ * The Task Control Block (TCB) is an RTEMS defined data structure which
+ * contains all the information that is pertinent to the execution of a task.
+ * During system initialization, RTEMS reserves a TCB for each task configured.
+ * A TCB is allocated upon creation of the task and is returned to the TCB free
+ * list upon deletion of the task.
+ *
+ * The TCB's elements are modified as a result of system calls made by the
+ * application in response to external and internal stimuli. TCBs are the only
+ * RTEMS internal data structure that can be accessed by an application via
+ * user extension routines. The TCB contains a task's name, ID, current
+ * priority, current and starting states, execution mode, set of notepad
+ * locations, TCB user extension pointer, scheduling control structures, as
+ * well as data required by a blocked task.
+ *
+ * A task's context is stored in the TCB when a task switch occurs. When the
+ * task regains control of the processor, its context is restored from the TCB.
+ * When a task is restarted, the initial state of the task is restored from the
+ * starting context area in the task's TCB.
+ *
+ * @section ClassicTasksSecTaskStates Task States
+ *
+ * A task may exist in one of the following five states:
+ *
+ * - executing - Currently scheduled to the CPU
+ * - ready - May be scheduled to the CPU
+ * - blocked - Unable to be scheduled to the CPU
+ * - dormant - Created task that is not started
+ * - non-existent - Uncreated or deleted task
+ *
+ * An active task may occupy the executing, ready, blocked or dormant state,
+ * otherwise the task is considered non-existent. One or more tasks may be
+ * active in the system simultaneously. Multiple tasks communicate,
+ * synchronize, and compete for system resources with each other via system
+ * calls. The multiple tasks appear to execute in parallel, but actually each
+ * is dispatched to the CPU for periods of time determined by the RTEMS
+ * scheduling algorithm. The scheduling of a task is based on its current state
+ * and priority.
+ *
+ * @section ClassicTasksSecTaskPriority Task Priority
+ *
+ * A task's priority determines its importance in relation to the other tasks
+ * executing on the same processor. RTEMS supports 255 levels of priority
+ * ranging from 1 to 255. The data type rtems_task_priority() is used to store
+ * task priorities.
+ *
+ * Tasks of numerically smaller priority values are more important tasks than
+ * tasks of numerically larger priority values. For example, a task at priority
+ * level 5 is of higher privilege than a task at priority level 10. There is no
+ * limit to the number of tasks assigned to the same priority.
+ *
+ * Each task has a priority associated with it at all times. The initial value
+ * of this priority is assigned at task creation time. The priority of a task
+ * may be changed at any subsequent time.
+ *
+ * Priorities are used by the scheduler to determine which ready task will be
+ * allowed to execute. In general, the higher the logical priority of a task,
+ * the more likely it is to receive processor execution time.
+ *
+ * @section ClassicTasksSecTaskMode Task Mode
+ *
+ * A task's execution mode is a combination of the following four components:
+ *
+ * - preemption
+ * - ASR processing
+ * - timeslicing
+ * - interrupt level
+ *
+ * It is used to modify RTEMS' scheduling process and to alter the execution
+ * environment of the task. The data type rtems_task_mode() is used to manage
+ * the task execution mode.
+ *
+ * The preemption component allows a task to determine when control of the
+ * processor is relinquished. If preemption is disabled (@c
+ * RTEMS_NO_PREEMPT), the task will retain control of the
+ * processor as long as it is in the executing state -- even if a higher
+ * priority task is made ready. If preemption is enabled (@c RTEMS_PREEMPT)
+ * and a higher priority task is made ready, then the processor will be
+ * taken away from the current task immediately and given to the higher
+ * priority task.
+ *
+ * The timeslicing component is used by the RTEMS scheduler to determine how
+ * the processor is allocated to tasks of equal priority. If timeslicing is
+ * enabled (@c RTEMS_TIMESLICE), then RTEMS will limit the amount of time the
+ * task can execute before the processor is allocated to another ready task of
+ * equal priority. The length of the timeslice is application dependent and
+ * specified in the Configuration Table. If timeslicing is disabled (@c
+ * RTEMS_NO_TIMESLICE), then the task will be allowed to
+ * execute until a task of higher priority is made ready. If @c
+ * RTEMS_NO_PREEMPT is selected, then the timeslicing component is ignored by
+ * the scheduler.
+ *
+ * The asynchronous signal processing component is used to determine when
+ * received signals are to be processed by the task. If signal processing is
+ * enabled (@c RTEMS_ASR), then signals sent to the task will be processed
+ * the next time the task executes. If signal processing is disabled (@c
+ * RTEMS_NO_ASR), then all signals received by the task will
+ * remain posted until signal processing is enabled. This component affects
+ * only tasks which have established a routine to process asynchronous signals.
+ *
+ * The interrupt level component is used to determine which interrupts will be
+ * enabled when the task is executing. @c RTEMS_INTERRUPT_LEVEL(n) specifies
+ * that the task will execute at interrupt level n.
+ *
+ * - @ref RTEMS_PREEMPT - enable preemption (default)
+ * - @ref RTEMS_NO_PREEMPT - disable preemption
+ * - @ref RTEMS_NO_TIMESLICE - disable timeslicing (default)
+ * - @ref RTEMS_TIMESLICE - enable timeslicing
+ * - @ref RTEMS_ASR - enable ASR processing (default)
+ * - @ref RTEMS_NO_ASR - disable ASR processing
+ * - @ref RTEMS_INTERRUPT_LEVEL(0) - enable all interrupts (default)
+ * - @ref RTEMS_INTERRUPT_LEVEL(n) - execute at interrupt level n
+ *
+ * The set of default modes may be selected by specifying the @ref
+ * RTEMS_DEFAULT_MODES constant.
+ *
+ * @section ClassicTasksSecAccessingTaskArguments Accessing Task Arguments
+ *
+ * All RTEMS tasks are invoked with a single argument which is specified when
+ * they are started or restarted. The argument is commonly used to communicate
+ * startup information to the task. The simplest manner in which to define a
+ * task which accesses it argument is:
+ *
+ * @code
+ * rtems_task user_task(
+ * rtems_task_argument argument
+ * );
+ * @endcode
+ *
+ * Application tasks requiring more information may view this single argument
+ * as an index into an array of parameter blocks.
+ *
+ * @section ClassicTasksSecFloatingPointConsiderations Floating Point Considerations
+ *
+ * Creating a task with the @ref RTEMS_FLOATING_POINT attribute flag results in
+ * additional memory being allocated for the TCB to store the state of the
+ * numeric coprocessor during task switches. This additional memory is NOT
+ * allocated for @ref RTEMS_NO_FLOATING_POINT tasks. Saving and restoring the
+ * context of a @c RTEMS_FLOATING_POINT task takes longer than that of a @c
+ * RTEMS_NO_FLOATING_POINT task because of the relatively large amount of time
+ * required for the numeric coprocessor to save or restore its computational
+ * state.
+ *
+ * Since RTEMS was designed specifically for embedded military applications
+ * which are floating point intensive, the executive is optimized to avoid
+ * unnecessarily saving and restoring the state of the numeric coprocessor. The
+ * state of the numeric coprocessor is only saved when a @c
+ * RTEMS_FLOATING_POINT task is dispatched and that task was not the last task
+ * to utilize the coprocessor. In a system with only one @c
+ * RTEMS_FLOATING_POINT task, the state of the numeric coprocessor will never
+ * be saved or restored.
+ *
+ * Although the overhead imposed by @c RTEMS_FLOATING_POINT tasks is minimal,
+ * some applications may wish to completely avoid the overhead associated with
+ * @c RTEMS_FLOATING_POINT tasks and still utilize a numeric coprocessor. By
+ * preventing a task from being preempted while performing a sequence of
+ * floating point operations, a @c RTEMS_NO_FLOATING_POINT task can utilize
+ * the numeric coprocessor without incurring the overhead of a @c
+ * RTEMS_FLOATING_POINT context switch. This approach also avoids the
+ * allocation of a floating point context area. However, if this approach is
+ * taken by the application designer, NO tasks should be created as @c
+ * RTEMS_FLOATING_POINT tasks. Otherwise, the floating point context will not
+ * be correctly maintained because RTEMS assumes that the state of the numeric
+ * coprocessor will not be altered by @c RTEMS_NO_FLOATING_POINT tasks.
+ *
+ * If the supported processor type does not have hardware floating capabilities
+ * or a standard numeric coprocessor, RTEMS will not provide built-in support
+ * for hardware floating point on that processor. In this case, all tasks are
+ * considered @c RTEMS_NO_FLOATING_POINT whether created as @c
+ * RTEMS_FLOATING_POINT or @c RTEMS_NO_FLOATING_POINT tasks. A floating point
+ * emulation software library must be utilized for floating point operations.
+ *
+ * On some processors, it is possible to disable the floating point unit
+ * dynamically. If this capability is supported by the target processor, then
+ * RTEMS will utilize this capability to enable the floating point unit only
+ * for tasks which are created with the @c RTEMS_FLOATING_POINT attribute.
+ * The consequence of a @c RTEMS_NO_FLOATING_POINT task attempting to access
+ * the floating point unit is CPU dependent but will generally result in an
+ * exception condition.
+ *
+ * @section ClassicTasksSecPerTaskVariables Per Task Variables
+ *
+ * Per task variables are used to support global variables whose value may be
+ * unique to a task. After indicating that a variable should be treated as
+ * private (i.e. per-task) the task can access and modify the variable, but the
+ * modifications will not appear to other tasks, and other tasks' modifications
+ * to that variable will not affect the value seen by the task. This is
+ * accomplished by saving and restoring the variable's value each time a task
+ * switch occurs to or from the calling task.
+ *
+ * The value seen by other tasks, including those which have not added the
+ * variable to their set and are thus accessing the variable as a common
+ * location shared among tasks, can not be affected by a task once it has added
+ * a variable to its local set. Changes made to the variable by other tasks
+ * will not affect the value seen by a task which has added the variable to its
+ * private set.
+ *
+ * This feature can be used when a routine is to be spawned repeatedly as
+ * several independent tasks. Although each task will have its own stack, and
+ * thus separate stack variables, they will all share the same static and
+ * global variables. To make a variable not shareable (i.e. a "global" variable
+ * that is specific to a single task), the tasks can call
+ * rtems_task_variable_add() to make a separate copy of the variable for each
+ * task, but all at the same physical address.
+ *
+ * Task variables increase the context switch time to and from the tasks that
+ * own them so it is desirable to minimize the number of task variables. One
+ * efficient method is to have a single task variable that is a pointer to a
+ * dynamically allocated structure containing the task's private "global" data.
+ *
+ * A critical point with per-task variables is that each task must separately
+ * request that the same global variable is per-task private.
+ *
+ * @section ClassicTasksSecBuildingTaskAttributeSet Building a Task Attribute Set
+ *
+ * In general, an attribute set is built by a bitwise OR of the desired
+ * components. The set of valid task attribute components is listed below:
+ *
+ * - @ref RTEMS_NO_FLOATING_POINT - does not use coprocessor (default)
+ * - @ref RTEMS_FLOATING_POINT - uses numeric coprocessor
+ * - @ref RTEMS_LOCAL - local task (default)
+ * - @ref RTEMS_GLOBAL - global task
+ *
+ * Attribute values are specifically designed to be mutually exclusive,
+ * therefore bitwise OR and addition operations are equivalent as long as each
+ * attribute appears exactly once in the component list. A component listed as
+ * a default is not required to appear in the component list, although it is a
+ * good programming practice to specify default components. If all defaults are
+ * desired, then @ref RTEMS_DEFAULT_ATTRIBUTES should be used. This example
+ * demonstrates the attribute_set parameter needed to create a local task which
+ * utilizes the numeric coprocessor. The attribute_set parameter could be @c
+ * RTEMS_FLOATING_POINT or @c RTEMS_LOCAL | @c RTEMS_FLOATING_POINT. The
+ * attribute_set parameter can be set to @c RTEMS_FLOATING_POINT because @c
+ * RTEMS_LOCAL is the default for all created tasks. If the task were global
+ * and used the numeric coprocessor, then the attribute_set parameter would be
+ * @c RTEMS_GLOBAL | @c RTEMS_FLOATING_POINT.
+ *
+ * @section ClassicTasksSecBuildingModeAndMask Building a Mode and Mask
+ *
+ * In general, a mode and its corresponding mask is built by a bitwise OR of
+ * the desired components. The set of valid mode constants and each mode's
+ * corresponding mask constant is listed below:
+ *
+ * <table>
+ * <tr><th>Mode Constant</th><th>Mask Constant</th><th>Description</th></tr>
+ * <tr><td>@ref RTEMS_PREEMPT</td><td>@ref RTEMS_PREEMPT_MASK</td><td>enables preemption</td></tr>
+ * <tr><td>@ref RTEMS_NO_PREEMPT</td><td>@ref RTEMS_PREEMPT_MASK</td><td>disables preemption</td></tr>
+ * <tr><td>@ref RTEMS_NO_TIMESLICE</td><td>@ref RTEMS_TIMESLICE_MASK</td><td>disables timeslicing</td></tr>
+ * <tr><td>@ref RTEMS_TIMESLICE</td><td>@ref RTEMS_TIMESLICE_MASK</td><td>enables timeslicing</td></tr>
+ * <tr><td>@ref RTEMS_ASR</td><td>@ref RTEMS_ASR_MASK</td><td>enables ASR processing</td></tr>
+ * <tr><td>@ref RTEMS_NO_ASR</td><td>@ref RTEMS_ASR_MASK</td><td>disables ASR processing</td></tr>
+ * <tr><td>@ref RTEMS_INTERRUPT_LEVEL(0)</td><td>@ref RTEMS_INTERRUPT_MASK</td><td>enables all interrupts</td></tr>
+ * <tr><td>@ref RTEMS_INTERRUPT_LEVEL(n)</td><td>@ref RTEMS_INTERRUPT_MASK</td><td>sets interrupts level n</td></tr>
+ * </table>
+ *
+ * Mode values are specifically designed to be mutually exclusive, therefore
+ * bitwise OR and addition operations are equivalent as long as each mode
+ * appears exactly once in the component list. A mode component listed as a
+ * default is not required to appear in the mode component list, although it is
+ * a good programming practice to specify default components. If all defaults
+ * are desired, the mode @ref RTEMS_DEFAULT_MODES and the mask @ref
+ * RTEMS_ALL_MODE_MASKS should be used.
+ *
+ * The following example demonstrates the mode and mask parameters used with
+ * the rtems_task_mode() directive to place a task at interrupt level 3 and
+ * make it non-preemptible. The mode should be set to @c
+ * RTEMS_INTERRUPT_LEVEL(3) | @c RTEMS_NO_PREEMPT to indicate the desired
+ * preemption mode and interrupt level, while the mask parameter should be set
+ * to @c RTEMS_INTERRUPT_MASK | @c RTEMS_PREEMPT_MASK to indicate that
+ * the calling task's interrupt level and preemption mode are being altered.
+ */
+
+ /**
+ * @defgroup LocalPackages Local Packages
+ *
+ * @brief Local packages.
+ */
diff --git a/cpukit/rtems/preinstall.am b/cpukit/rtems/preinstall.am
new file mode 100644
index 0000000000..5d32ad7413
--- /dev/null
+++ b/cpukit/rtems/preinstall.am
@@ -0,0 +1,234 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems.h: include/rtems.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/rtems/asr.h: include/rtems/rtems/asr.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/asr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/asr.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/attr.h: include/rtems/rtems/attr.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/attr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/attr.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/barrier.h: include/rtems/rtems/barrier.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/barrier.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/barrier.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/cache.h: include/rtems/rtems/cache.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/cache.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/cache.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/clock.h: include/rtems/rtems/clock.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/clock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/clock.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/config.h: include/rtems/rtems/config.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/config.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/config.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/dpmem.h: include/rtems/rtems/dpmem.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/dpmem.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/dpmem.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/event.h: include/rtems/rtems/event.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/event.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/event.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/eventset.h: include/rtems/rtems/eventset.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/eventset.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/eventset.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/intr.h: include/rtems/rtems/intr.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/intr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/intr.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/message.h: include/rtems/rtems/message.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/message.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/message.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/modes.h: include/rtems/rtems/modes.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/modes.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/modes.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/object.h: include/rtems/rtems/object.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/object.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/object.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/options.h: include/rtems/rtems/options.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/options.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/options.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/part.h: include/rtems/rtems/part.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/part.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/part.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/ratemon.h: include/rtems/rtems/ratemon.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/ratemon.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/ratemon.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/region.h: include/rtems/rtems/region.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/region.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/region.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/rtemsapi.h: include/rtems/rtems/rtemsapi.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/rtemsapi.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/rtemsapi.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/sem.h: include/rtems/rtems/sem.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/sem.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/sem.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/signal.h: include/rtems/rtems/signal.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/signal.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/signal.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/status.h: include/rtems/rtems/status.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/status.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/status.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/support.h: include/rtems/rtems/support.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/support.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/support.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/tasks.h: include/rtems/rtems/tasks.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/tasks.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/tasks.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/timer.h: include/rtems/rtems/timer.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/timer.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/timer.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/types.h: include/rtems/rtems/types.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/types.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/mainpage.h: mainpage.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/mainpage.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/mainpage.h
+
+if HAS_MP
+$(PROJECT_INCLUDE)/rtems/rtems/eventmp.h: include/rtems/rtems/eventmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/eventmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/eventmp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/mp.h: include/rtems/rtems/mp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/mp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/mp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/msgmp.h: include/rtems/rtems/msgmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/msgmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/msgmp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/partmp.h: include/rtems/rtems/partmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/partmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/partmp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/regionmp.h: include/rtems/rtems/regionmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/regionmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/regionmp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/semmp.h: include/rtems/rtems/semmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/semmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/semmp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/signalmp.h: include/rtems/rtems/signalmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/signalmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/signalmp.h
+
+$(PROJECT_INCLUDE)/rtems/rtems/taskmp.h: include/rtems/rtems/taskmp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/taskmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/taskmp.h
+endif
+$(PROJECT_INCLUDE)/rtems/rtems/asr.inl: inline/rtems/rtems/asr.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/asr.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/asr.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/attr.inl: inline/rtems/rtems/attr.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/attr.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/attr.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/barrier.inl: inline/rtems/rtems/barrier.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/barrier.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/barrier.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/dpmem.inl: inline/rtems/rtems/dpmem.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/dpmem.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/dpmem.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/event.inl: inline/rtems/rtems/event.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/event.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/event.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/eventset.inl: inline/rtems/rtems/eventset.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/eventset.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/eventset.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/message.inl: inline/rtems/rtems/message.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/message.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/message.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/modes.inl: inline/rtems/rtems/modes.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/modes.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/modes.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/options.inl: inline/rtems/rtems/options.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/options.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/options.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/part.inl: inline/rtems/rtems/part.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/part.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/part.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/ratemon.inl: inline/rtems/rtems/ratemon.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/ratemon.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/ratemon.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/region.inl: inline/rtems/rtems/region.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/region.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/region.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/sem.inl: inline/rtems/rtems/sem.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/sem.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/sem.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/status.inl: inline/rtems/rtems/status.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/status.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/status.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/support.inl: inline/rtems/rtems/support.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/support.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/support.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/tasks.inl: inline/rtems/rtems/tasks.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/tasks.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/tasks.inl
+
+$(PROJECT_INCLUDE)/rtems/rtems/timer.inl: inline/rtems/rtems/timer.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/timer.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/timer.inl
+
diff --git a/cpukit/rtems/src/attr.c b/cpukit/rtems/src/attr.c
new file mode 100644
index 0000000000..2312d36bb5
--- /dev/null
+++ b/cpukit/rtems/src/attr.c
@@ -0,0 +1,31 @@
+/*
+ * Body for Attribute Routines
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/stack.h>
+#include <rtems/rtems/modes.h>
+
+uint32_t rtems_interrupt_mask = RTEMS_INTERRUPT_MASK;
+
+rtems_attribute rtems_interrupt_level_attribute(
+ uint32_t level
+)
+{
+ return RTEMS_INTERRUPT_LEVEL(level);
+}
diff --git a/cpukit/rtems/src/barrier.c b/cpukit/rtems/src/barrier.c
new file mode 100644
index 0000000000..b35b5e3415
--- /dev/null
+++ b/cpukit/rtems/src/barrier.c
@@ -0,0 +1,65 @@
+/*
+ * Barrier Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Barrier Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a barrier
+ * + get an ID of a barrier
+ * + delete a barrier
+ * + acquire a barrier
+ * + release a barrier
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/barrier.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+
+/**
+ * @brief _Barrier_Manager_initialization
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Barrier_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Barrier_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_BARRIERS, /* object class */
+ Configuration_RTEMS_API.maximum_barriers,
+ /* maximum objects of this class */
+ sizeof( Barrier_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/rtems/src/barriercreate.c b/cpukit/rtems/src/barriercreate.c
new file mode 100644
index 0000000000..89c4b55ec9
--- /dev/null
+++ b/cpukit/rtems/src/barriercreate.c
@@ -0,0 +1,92 @@
+/*
+ * Barrier Manager -- Create a Barrier Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/barrier.h>
+
+/*
+ * rtems_barrier_create
+ *
+ * This directive creates a barrier. A barrier id is returned.
+ *
+ * Input parameters:
+ * name - user defined barrier name
+ * attribute_set - barrier attributes
+ * maximum_waiters - number of threads before automatic release
+ * priority_ceiling - barrier's ceiling priority
+ * id - pointer to barrier id
+ *
+ * Output parameters:
+ * id - barrier id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_barrier_create(
+ rtems_name name,
+ rtems_attribute attribute_set,
+ uint32_t maximum_waiters,
+ rtems_id *id
+)
+{
+ Barrier_Control *the_barrier;
+ CORE_barrier_Attributes the_attributes;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ /* Initialize core barrier attributes */
+ if ( _Attributes_Is_barrier_automatic( attribute_set ) ) {
+ the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
+ if ( maximum_waiters == 0 )
+ return RTEMS_INVALID_NUMBER;
+ } else
+ the_attributes.discipline = CORE_BARRIER_MANUAL_RELEASE;
+ the_attributes.maximum_count = maximum_waiters;
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_barrier = _Barrier_Allocate();
+
+ if ( !the_barrier ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+ the_barrier->attribute_set = attribute_set;
+
+ _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
+
+ _Objects_Open(
+ &_Barrier_Information,
+ &the_barrier->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_barrier->Object.id;
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/barrierdata.c b/cpukit/rtems/src/barrierdata.c
new file mode 100644
index 0000000000..6e4af5a4c8
--- /dev/null
+++ b/cpukit/rtems/src/barrierdata.c
@@ -0,0 +1,23 @@
+/*
+ * Barrier Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate barrier data */
+#define RTEMS_BARRIER_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/barrier.h>
+
diff --git a/cpukit/rtems/src/barrierdelete.c b/cpukit/rtems/src/barrierdelete.c
new file mode 100644
index 0000000000..6843a1bc00
--- /dev/null
+++ b/cpukit/rtems/src/barrierdelete.c
@@ -0,0 +1,73 @@
+/*
+ * Barrier Manager -- Delete a Barrier
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/barrier.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*
+ * rtems_barrier_delete
+ *
+ * This directive allows a thread to delete a barrier specified by
+ * the barrier id. The barrier is freed back to the inactive
+ * barrier chain.
+ *
+ * Input parameters:
+ * id - barrier id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_barrier_delete(
+ rtems_id id
+)
+{
+ Barrier_Control *the_barrier;
+ Objects_Locations location;
+
+ the_barrier = _Barrier_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _CORE_barrier_Flush(
+ &the_barrier->Barrier,
+ NULL,
+ CORE_BARRIER_WAS_DELETED
+ );
+
+ _Objects_Close( &_Barrier_Information, &the_barrier->Object );
+
+ _Barrier_Free( the_barrier );
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/barrierident.c b/cpukit/rtems/src/barrierident.c
new file mode 100644
index 0000000000..6b90dacf70
--- /dev/null
+++ b/cpukit/rtems/src/barrierident.c
@@ -0,0 +1,56 @@
+/*
+ * Barrier Manager Name to ID
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/barrier.h>
+
+/*
+ * rtems_barrier_ident
+ *
+ * This directive returns the system ID associated with
+ * the barrier name.
+ *
+ * Input parameters:
+ * name - user defined barrier name
+ * id - pointer to barrier id
+ *
+ * Output parameters:
+ * *id - barrier id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_barrier_ident(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Barrier_Information,
+ name,
+ OBJECTS_SEARCH_LOCAL_NODE,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/barrierrelease.c b/cpukit/rtems/src/barrierrelease.c
new file mode 100644
index 0000000000..8bb53b8664
--- /dev/null
+++ b/cpukit/rtems/src/barrierrelease.c
@@ -0,0 +1,67 @@
+/*
+ * Barrier Manager -- Release Tasks Waitng at a Barrier
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/barrier.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*
+ * rtems_barrier_release
+ *
+ * This directive releases all threads waiting at a barrier.
+ *
+ * Input parameters:
+ * id - barrier id
+ * released - pointer to number of threads unblocked
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ * *released - number of threads unblocked
+ */
+
+rtems_status_code rtems_barrier_release(
+ rtems_id id,
+ uint32_t *released
+)
+{
+ Barrier_Control *the_barrier;
+ Objects_Locations location;
+
+ if ( !released )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_barrier = _Barrier_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ *released = _CORE_barrier_Release( &the_barrier->Barrier, id, NULL );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/barriertranslatereturncode.c b/cpukit/rtems/src/barriertranslatereturncode.c
new file mode 100644
index 0000000000..97d7feb911
--- /dev/null
+++ b/cpukit/rtems/src/barriertranslatereturncode.c
@@ -0,0 +1,53 @@
+/*
+ * Barrier Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/barrier.h>
+
+/*
+ * _Barrier_Translate_core_barrier_return_code
+ *
+ * Input parameters:
+ * the_barrier_status - barrier status code to translate
+ *
+ * Output parameters:
+ * rtems status code - translated RTEMS status code
+ *
+ */
+
+rtems_status_code _Barrier_Translate_core_barrier_return_code_[] = {
+ RTEMS_SUCCESSFUL, /* CORE_BARRIER_STATUS_SUCCESSFUL */
+ RTEMS_SUCCESSFUL, /* CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED */
+ RTEMS_OBJECT_WAS_DELETED, /* CORE_BARRIER_WAS_DELETED */
+ RTEMS_TIMEOUT /* CORE_BARRIER_TIMEOUT */
+};
+
+rtems_status_code _Barrier_Translate_core_barrier_return_code (
+ CORE_barrier_Status the_barrier_status
+)
+{
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( the_barrier_status > CORE_BARRIER_STATUS_LAST )
+ return RTEMS_INTERNAL_ERROR;
+ #endif
+ return _Barrier_Translate_core_barrier_return_code_[the_barrier_status];
+}
diff --git a/cpukit/rtems/src/barrierwait.c b/cpukit/rtems/src/barrierwait.c
new file mode 100644
index 0000000000..04b2389051
--- /dev/null
+++ b/cpukit/rtems/src/barrierwait.c
@@ -0,0 +1,70 @@
+/*
+ * Barrier Manager -- Wait at a Barrier
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/barrier.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*
+ * rtems_barrier_wait
+ *
+ * This directive allows a thread to wait at a barrier.
+ *
+ * Input parameters:
+ * id - barrier id
+ * timeout - number of ticks to wait (0 means wait forever)
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_barrier_wait(
+ rtems_id id,
+ rtems_interval timeout
+)
+{
+ Barrier_Control *the_barrier;
+ Objects_Locations location;
+
+ the_barrier = _Barrier_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _CORE_barrier_Wait(
+ &the_barrier->Barrier,
+ id,
+ true,
+ timeout,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+ return _Barrier_Translate_core_barrier_return_code(
+ _Thread_Executing->Wait.return_code );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/clockget.c b/cpukit/rtems/src/clockget.c
new file mode 100644
index 0000000000..03d8ec453f
--- /dev/null
+++ b/cpukit/rtems/src/clockget.c
@@ -0,0 +1,76 @@
+/*
+ * Clock Manager
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*
+ * rtems_clock_get
+ *
+ * This directive returns the current date and time. If the time has
+ * not been set by a tm_set then an error is returned.
+ *
+ * Input parameters:
+ * option - which value to return
+ * time_buffer - pointer to output buffer (a time and date structure
+ * or an interval)
+ *
+ * Output parameters:
+ * time_buffer - output filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_clock_get(
+ rtems_clock_get_options option,
+ void *time_buffer
+)
+{
+ if ( !time_buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( option == RTEMS_CLOCK_GET_TOD )
+ return rtems_clock_get_tod( (rtems_time_of_day *)time_buffer );
+
+ if ( option == RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH )
+ return rtems_clock_get_seconds_since_epoch((rtems_interval *)time_buffer);
+
+ if ( option == RTEMS_CLOCK_GET_TICKS_SINCE_BOOT ) {
+ rtems_interval *interval = (rtems_interval *)time_buffer;
+
+ *interval = rtems_clock_get_ticks_since_boot();
+ return RTEMS_SUCCESSFUL;
+ }
+
+ if ( option == RTEMS_CLOCK_GET_TICKS_PER_SECOND ) {
+ rtems_interval *interval = (rtems_interval *)time_buffer;
+
+ *interval = rtems_clock_get_ticks_per_second();
+ return RTEMS_SUCCESSFUL;
+ }
+
+ if ( option == RTEMS_CLOCK_GET_TIME_VALUE )
+ return rtems_clock_get_tod_timeval( (struct timeval *)time_buffer );
+
+ return RTEMS_INVALID_NUMBER;
+
+}
diff --git a/cpukit/rtems/src/clockgetsecondssinceepoch.c b/cpukit/rtems/src/clockgetsecondssinceepoch.c
new file mode 100644
index 0000000000..c8fcdc3183
--- /dev/null
+++ b/cpukit/rtems/src/clockgetsecondssinceepoch.c
@@ -0,0 +1,38 @@
+/*
+ * Clock Manager - Get Seconds Since Epoch
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+rtems_status_code rtems_clock_get_seconds_since_epoch(
+ rtems_interval *the_interval
+)
+{
+ if ( !the_interval )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !_TOD_Is_set )
+ return RTEMS_NOT_DEFINED;
+
+ *the_interval = _TOD_Seconds_since_epoch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clockgettickspersecond.c b/cpukit/rtems/src/clockgettickspersecond.c
new file mode 100644
index 0000000000..23e2dd7c39
--- /dev/null
+++ b/cpukit/rtems/src/clockgettickspersecond.c
@@ -0,0 +1,31 @@
+/*
+ * Clock Manager - Get Ticks Per Second
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+rtems_interval rtems_clock_get_ticks_per_second(void)
+{
+ return TOD_MICROSECONDS_PER_SECOND /
+ rtems_configuration_get_microseconds_per_tick();
+}
diff --git a/cpukit/rtems/src/clockgettickssinceboot.c b/cpukit/rtems/src/clockgettickssinceboot.c
new file mode 100644
index 0000000000..a97e40106e
--- /dev/null
+++ b/cpukit/rtems/src/clockgettickssinceboot.c
@@ -0,0 +1,29 @@
+/*
+ * Clock Manager - Get Ticks Since Boot
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+rtems_interval rtems_clock_get_ticks_since_boot(void)
+{
+ return _Watchdog_Ticks_since_boot;
+}
diff --git a/cpukit/rtems/src/clockgettod.c b/cpukit/rtems/src/clockgettod.c
new file mode 100644
index 0000000000..4c4e77c2ae
--- /dev/null
+++ b/cpukit/rtems/src/clockgettod.c
@@ -0,0 +1,58 @@
+/*
+ * Clock Manager - rtems_clock_get_tod
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+rtems_status_code rtems_clock_get_tod(
+ rtems_time_of_day *time_buffer
+)
+{
+ rtems_time_of_day *tmbuf = time_buffer;
+ struct tm time;
+ struct timeval now;
+
+ if ( !time_buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !_TOD_Is_set )
+ return RTEMS_NOT_DEFINED;
+
+ /* Obtain the current time */
+ _TOD_Get_timeval( &now );
+
+ /* Split it into a closer format */
+ gmtime_r( &now.tv_sec, &time );
+
+ /* Now adjust it to the RTEMS format */
+ tmbuf->year = time.tm_year + 1900;
+ tmbuf->month = time.tm_mon + 1;
+ tmbuf->day = time.tm_mday;
+ tmbuf->hour = time.tm_hour;
+ tmbuf->minute = time.tm_min;
+ tmbuf->second = time.tm_sec;
+ tmbuf->ticks = now.tv_usec /
+ rtems_configuration_get_microseconds_per_tick();
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clockgettodtimeval.c b/cpukit/rtems/src/clockgettodtimeval.c
new file mode 100644
index 0000000000..71e53ffd24
--- /dev/null
+++ b/cpukit/rtems/src/clockgettodtimeval.c
@@ -0,0 +1,39 @@
+/*
+ * Clock Manager - Get TOD in Time Value Format
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+rtems_status_code rtems_clock_get_tod_timeval(
+ struct timeval *time
+)
+{
+ if ( !time )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !_TOD_Is_set )
+ return RTEMS_NOT_DEFINED;
+
+ _TOD_Get_timeval( time );
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clockgetuptime.c b/cpukit/rtems/src/clockgetuptime.c
new file mode 100644
index 0000000000..b6ea0e5448
--- /dev/null
+++ b/cpukit/rtems/src/clockgetuptime.c
@@ -0,0 +1,51 @@
+/*
+ * Clock Manager - get uptime
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_clock_get_uptime
+ *
+ * This directive obtains the system uptime. A timestamp is the seconds
+ * and nanoseconds since boot.
+ *
+ * Input parameters:
+ * timestamp - pointer to the timestamp
+ *
+ * Output parameters:
+ * *uptime - filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+rtems_status_code rtems_clock_get_uptime(
+ struct timespec *uptime
+)
+{
+ if ( !uptime )
+ return RTEMS_INVALID_ADDRESS;
+
+ _TOD_Get_uptime_as_timespec( uptime );
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c
new file mode 100644
index 0000000000..bb27697829
--- /dev/null
+++ b/cpukit/rtems/src/clockset.c
@@ -0,0 +1,61 @@
+/*
+ * Clock Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_clock_set
+ *
+ * This directive sets the date and time for this node.
+ *
+ * Input parameters:
+ * time_buffer - pointer to the time and date structure
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_clock_set(
+ rtems_time_of_day *time_buffer
+)
+{
+ struct timespec newtime;
+
+ if ( !time_buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( _TOD_Validate( time_buffer ) ) {
+ newtime.tv_sec = _TOD_To_seconds( time_buffer );
+ newtime.tv_nsec = time_buffer->ticks *
+ rtems_configuration_get_nanoseconds_per_tick();
+
+ _Thread_Disable_dispatch();
+ _TOD_Set( &newtime );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ return RTEMS_INVALID_CLOCK;
+}
diff --git a/cpukit/rtems/src/clocksetnsecshandler.c b/cpukit/rtems/src/clocksetnsecshandler.c
new file mode 100644
index 0000000000..8e4d0b113e
--- /dev/null
+++ b/cpukit/rtems/src/clocksetnsecshandler.c
@@ -0,0 +1,49 @@
+/*
+ * Clock Manager
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_clock_set_nanoseconds_extension
+ *
+ * This directive sets the BSP provided nanoseconds since last tick
+ * extension.
+ *
+ * Input parameters:
+ * routine - pointer to the extension routine
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+rtems_status_code rtems_clock_set_nanoseconds_extension(
+ rtems_nanoseconds_extension_routine routine
+)
+{
+ if ( !routine )
+ return RTEMS_INVALID_ADDRESS;
+
+ _Watchdog_Nanoseconds_since_tick_handler = routine;
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clocktick.c b/cpukit/rtems/src/clocktick.c
new file mode 100644
index 0000000000..f02f48fb45
--- /dev/null
+++ b/cpukit/rtems/src/clocktick.c
@@ -0,0 +1,55 @@
+/*
+ * Clock Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_clock_tick
+ *
+ * This directive notifies the executve that a tick has occurred.
+ * When the tick occurs the time manager updates and maintains
+ * the calendar time, timeslicing, and any timeout delays.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - always succeeds
+ *
+ * NOTE: This routine only works for leap-years through 2099.
+ */
+
+rtems_status_code rtems_clock_tick( void )
+{
+ _TOD_Tickle_ticks();
+
+ _Watchdog_Tickle_ticks();
+
+ _Thread_Tickle_timeslice();
+
+ if ( _Thread_Is_context_switch_necessary() &&
+ _Thread_Is_dispatching_enabled() )
+ _Thread_Dispatch();
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clocktodtoseconds.c b/cpukit/rtems/src/clocktodtoseconds.c
new file mode 100644
index 0000000000..c5093e180d
--- /dev/null
+++ b/cpukit/rtems/src/clocktodtoseconds.c
@@ -0,0 +1,85 @@
+/*
+ * Time of Day (TOD) Handler - Classic TOD to Seconds
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/clock.h>
+
+/*
+ * The following array contains the number of days in all months
+ * up to the month indicated by the index of the second dimension.
+ * The first dimension should be 1 for leap years, and 0 otherwise.
+ */
+const uint16_t _TOD_Days_to_date[2][13] = {
+ { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
+ { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
+};
+
+/*
+ * The following array contains the number of days in the years
+ * since the last leap year. The index should be 0 for leap
+ * years, and the number of years since the beginning of a leap
+ * year otherwise.
+ */
+const uint16_t _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
+
+
+
+/*PAGE
+ *
+ * _TOD_To_seconds
+ *
+ * This routine returns the seconds from the epoch until the
+ * current date and time.
+ *
+ * Input parameters:
+ * the_tod - pointer to the time and date structure
+ *
+ * Output parameters:
+ * returns - seconds since epoch until the_tod
+ */
+
+uint32_t _TOD_To_seconds(
+ const rtems_time_of_day *the_tod
+)
+{
+ uint32_t time;
+ uint32_t year_mod_4;
+
+ time = the_tod->day - 1;
+ year_mod_4 = the_tod->year & 3;
+
+ if ( year_mod_4 == 0 )
+ time += _TOD_Days_to_date[ 1 ][ the_tod->month ];
+ else
+ time += _TOD_Days_to_date[ 0 ][ the_tod->month ];
+
+ time += ( (the_tod->year - TOD_BASE_YEAR) / 4 ) *
+ ( (TOD_DAYS_PER_YEAR * 4) + 1);
+
+ time += _TOD_Days_since_last_leap_year[ year_mod_4 ];
+
+ time *= TOD_SECONDS_PER_DAY;
+
+ time += ((the_tod->hour * TOD_MINUTES_PER_HOUR) + the_tod->minute)
+ * TOD_SECONDS_PER_MINUTE;
+
+ time += the_tod->second;
+
+ time += TOD_SECONDS_1970_THROUGH_1988;
+
+ return( time );
+}
diff --git a/cpukit/rtems/src/clocktodvalidate.c b/cpukit/rtems/src/clocktodvalidate.c
new file mode 100644
index 0000000000..1dac1dc6b1
--- /dev/null
+++ b/cpukit/rtems/src/clocktodvalidate.c
@@ -0,0 +1,79 @@
+/*
+ * Time of Day (TOD) Handler -- Validate Classic TOD
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/clock.h>
+
+/*
+ * The following array contains the number of days in all months.
+ * The first dimension should be 1 for leap years, and 0 otherwise.
+ * The second dimension should range from 1 to 12 for January to
+ * February, respectively.
+ */
+const uint32_t _TOD_Days_per_month[ 2 ][ 13 ] = {
+ { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
+
+/*PAGE
+ *
+ * _TOD_Validate
+ *
+ * This kernel routine checks the validity of a date and time structure.
+ *
+ * Input parameters:
+ * the_tod - pointer to a time and date structure
+ *
+ * Output parameters:
+ * true - if the date, time, and tick are valid
+ * false - if the the_tod is invalid
+ *
+ * NOTE: This routine only works for leap-years through 2099.
+ */
+
+bool _TOD_Validate(
+ const rtems_time_of_day *the_tod
+)
+{
+ uint32_t days_in_month;
+ uint32_t ticks_per_second;
+
+ ticks_per_second = TOD_MICROSECONDS_PER_SECOND /
+ rtems_configuration_get_microseconds_per_tick();
+ if ((!the_tod) ||
+ (the_tod->ticks >= ticks_per_second) ||
+ (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
+ (the_tod->minute >= TOD_MINUTES_PER_HOUR) ||
+ (the_tod->hour >= TOD_HOURS_PER_DAY) ||
+ (the_tod->month == 0) ||
+ (the_tod->month > TOD_MONTHS_PER_YEAR) ||
+ (the_tod->year < TOD_BASE_YEAR) ||
+ (the_tod->day == 0) )
+ return false;
+
+ if ( (the_tod->year % 4) == 0 )
+ days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ];
+ else
+ days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ];
+
+ if ( the_tod->day > days_in_month )
+ return false;
+
+ return true;
+}
diff --git a/cpukit/rtems/src/dpmem.c b/cpukit/rtems/src/dpmem.c
new file mode 100644
index 0000000000..9cc58914b8
--- /dev/null
+++ b/cpukit/rtems/src/dpmem.c
@@ -0,0 +1,57 @@
+/*
+ * Dual Port Memory Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * _Dual_ported_memory_Manager_initialization
+ *
+ * This routine initializes all dual-ported memory manager related
+ * data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Dual_ported_memory_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Dual_ported_memory_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_PORTS, /* object class */
+ Configuration_RTEMS_API.maximum_ports,
+ /* maximum objects of this class */
+ sizeof( Dual_ported_memory_Control ),
+ /* size of this object's control block */
+ false, /* true if names of this object are strings */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/rtems/src/dpmemcreate.c b/cpukit/rtems/src/dpmemcreate.c
new file mode 100644
index 0000000000..69df430dd8
--- /dev/null
+++ b/cpukit/rtems/src/dpmemcreate.c
@@ -0,0 +1,88 @@
+/*
+ * Dual Port Memory Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/dpmem.h>
+
+/*PAGE
+ *
+ * rtems_port_create
+ *
+ * This directive creates a port into a dual-ported memory area.
+ *
+ * Input parameters:
+ * name - user defined port name
+ * internal_start - internal start address of port
+ * external_start - external start address of port
+ * length - physical length in bytes
+ * id - address of port id to set
+ *
+ * Output parameters:
+ * id - port id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_port_create(
+ rtems_name name,
+ void *internal_start,
+ void *external_start,
+ uint32_t length,
+ rtems_id *id
+)
+{
+ register Dual_ported_memory_Control *the_port;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !_Addresses_Is_aligned( internal_start ) ||
+ !_Addresses_Is_aligned( external_start ) )
+ return RTEMS_INVALID_ADDRESS;
+
+ _Thread_Disable_dispatch(); /* to prevent deletion */
+
+ the_port = _Dual_ported_memory_Allocate();
+
+ if ( !the_port ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+ the_port->internal_base = internal_start;
+ the_port->external_base = external_start;
+ the_port->length = length - 1;
+
+ _Objects_Open(
+ &_Dual_ported_memory_Information,
+ &the_port->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_port->Object.id;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/dpmemdata.c b/cpukit/rtems/src/dpmemdata.c
new file mode 100644
index 0000000000..cc2285c1f6
--- /dev/null
+++ b/cpukit/rtems/src/dpmemdata.c
@@ -0,0 +1,22 @@
+/*
+ * Dual Port Memory Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate semaphore data */
+#define RTEMS_DPMEM_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/dpmem.h>
diff --git a/cpukit/rtems/src/dpmemdelete.c b/cpukit/rtems/src/dpmemdelete.c
new file mode 100644
index 0000000000..003c27fecb
--- /dev/null
+++ b/cpukit/rtems/src/dpmemdelete.c
@@ -0,0 +1,66 @@
+/*
+ * Dual Port Memory Manager
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/dpmem.h>
+
+/*PAGE
+ *
+ * rtems_port_delete
+ *
+ * This directive allows a thread to delete a dual-ported memory area
+ * specified by the dual-ported memory identifier.
+ *
+ * Input parameters:
+ * id - dual-ported memory area id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_port_delete(
+ rtems_id id
+)
+{
+ register Dual_ported_memory_Control *the_port;
+ Objects_Locations location;
+
+ the_port = _Dual_ported_memory_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Close( &_Dual_ported_memory_Information, &the_port->Object );
+ _Dual_ported_memory_Free( the_port );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/dpmemexternal2internal.c b/cpukit/rtems/src/dpmemexternal2internal.c
new file mode 100644
index 0000000000..45c8344588
--- /dev/null
+++ b/cpukit/rtems/src/dpmemexternal2internal.c
@@ -0,0 +1,79 @@
+/*
+ * Dual Port Memory Manager
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/dpmem.h>
+
+/*PAGE
+ *
+ * rtems_port_external_to_internal
+ *
+ * This directive converts an external dual-ported memory address to an
+ * internal dual-ported memory address. If the given external address
+ * is an invalid dual-ported address, then the internal address is set
+ * to the given external address.
+ *
+ * Input parameters:
+ * id - id of dp memory object
+ * external - external address
+ * internal - pointer of internal address to set
+ *
+ * Output parameters:
+ * internal - internal address
+ * RTEMS_SUCCESSFUL - always succeeds
+ */
+
+rtems_status_code rtems_port_external_to_internal(
+ rtems_id id,
+ void *external,
+ void **internal
+)
+{
+ register Dual_ported_memory_Control *the_port;
+ Objects_Locations location;
+ uint32_t ending;
+
+ if ( !internal )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_port = _Dual_ported_memory_Get( id, &location );
+ switch ( location ) {
+ case OBJECTS_LOCAL:
+ ending = _Addresses_Subtract( external, the_port->external_base );
+ if ( ending > the_port->length )
+ *internal = external;
+ else
+ *internal = _Addresses_Add_offset( the_port->internal_base,
+ ending );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/dpmemident.c b/cpukit/rtems/src/dpmemident.c
new file mode 100644
index 0000000000..f41aef293b
--- /dev/null
+++ b/cpukit/rtems/src/dpmemident.c
@@ -0,0 +1,59 @@
+/*
+ * Dual Port Memory Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/dpmem.h>
+
+/*PAGE
+ *
+ * rtems_port_ident
+ *
+ * This directive returns the system ID associated with
+ * the port name.
+ *
+ * Input parameters:
+ * name - user defined port name
+ * id - pointer to port id
+ *
+ * Output parameters:
+ * *id - port id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_port_ident(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Dual_ported_memory_Information,
+ name,
+ OBJECTS_SEARCH_ALL_NODES,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/dpmeminternal2external.c b/cpukit/rtems/src/dpmeminternal2external.c
new file mode 100644
index 0000000000..5bf4d4fe93
--- /dev/null
+++ b/cpukit/rtems/src/dpmeminternal2external.c
@@ -0,0 +1,80 @@
+/*
+ * Dual Port Memory Manager
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/dpmem.h>
+
+/*PAGE
+ *
+ * rtems_port_internal_to_external
+ *
+ * This directive converts an internal dual-ported memory address to an
+ * external dual-ported memory address. If the given internal address
+ * is an invalid dual-ported address, then the external address is set
+ * to the given internal address.
+ *
+ * Input parameters:
+ * id - id of dual-ported memory object
+ * internal - internal address to set
+ * external - pointer to external address
+ *
+ * Output parameters:
+ * external - external address
+ * RTEMS_SUCCESSFUL - always succeeds
+ */
+
+rtems_status_code rtems_port_internal_to_external(
+ rtems_id id,
+ void *internal,
+ void **external
+)
+{
+ register Dual_ported_memory_Control *the_port;
+ Objects_Locations location;
+ uint32_t ending;
+
+ if ( !external )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_port = _Dual_ported_memory_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ ending = _Addresses_Subtract( internal, the_port->internal_base );
+ if ( ending > the_port->length )
+ *external = internal;
+ else
+ *external = _Addresses_Add_offset( the_port->external_base,
+ ending );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/event.c b/cpukit/rtems/src/event.c
new file mode 100644
index 0000000000..85d35829c2
--- /dev/null
+++ b/cpukit/rtems/src/event.c
@@ -0,0 +1,48 @@
+/*
+ * Event Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * _Event_Manager_initialization
+ *
+ * DESCRIPTION:
+ *
+ * This routine performs the initialization necessary for this manager.
+ */
+
+void _Event_Manager_initialization( void )
+{
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
+#endif
+}
diff --git a/cpukit/rtems/src/eventdata.c b/cpukit/rtems/src/eventdata.c
new file mode 100644
index 0000000000..bc7eb466c1
--- /dev/null
+++ b/cpukit/rtems/src/eventdata.c
@@ -0,0 +1,22 @@
+/*
+ * Event Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS event data */
+#define RTEMS_EVENT_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/event.h>
diff --git a/cpukit/rtems/src/eventmp.c b/cpukit/rtems/src/eventmp.c
new file mode 100644
index 0000000000..552d283994
--- /dev/null
+++ b/cpukit/rtems/src/eventmp.c
@@ -0,0 +1,193 @@
+/*
+ * Multiprocessing Support for the Event Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Event_MP_Send_process_packet
+ *
+ * This subprogram is not needed since there are no process
+ * packets to be sent by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _Event_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _Event_MP_Send_request_packet (
+ Event_MP_Remote_operations operation,
+ Objects_Id event_id,
+ rtems_event_set event_in
+)
+{
+ Event_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case EVENT_MP_SEND_REQUEST:
+
+ the_packet = _Event_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_EVENT;
+ the_packet->Prefix.length = sizeof ( Event_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Event_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = event_id;
+ the_packet->event_in = event_in;
+
+ return (rtems_status_code)
+ _MPCI_Send_request_packet(
+ _Objects_Get_node( event_id ),
+ &the_packet->Prefix,
+ STATES_READY
+ );
+
+ break;
+
+ case EVENT_MP_SEND_RESPONSE:
+ break;
+
+ }
+ /*
+ * The following line is included to satisfy compilers which
+ * produce warnings when a function does not end with a return.
+ */
+ return RTEMS_SUCCESSFUL;
+}
+
+/*PAGE
+ *
+ * _Event_MP_Send_response_packet
+ *
+ */
+
+void _Event_MP_Send_response_packet (
+ Event_MP_Remote_operations operation,
+ Thread_Control *the_thread
+)
+{
+ Event_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case EVENT_MP_SEND_RESPONSE:
+
+ the_packet = ( Event_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case EVENT_MP_SEND_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _Event_MP_Process_packet
+ *
+ */
+
+void _Event_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ Event_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+
+ the_packet = (Event_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case EVENT_MP_SEND_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_event_send(
+ the_packet->Prefix.id,
+ the_packet->event_in
+ );
+
+ _Event_MP_Send_response_packet(
+ EVENT_MP_SEND_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+
+ case EVENT_MP_SEND_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ * _Event_MP_Send_object_was_deleted
+ *
+ * This subprogram is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _Event_MP_Send_extract_proxy
+ *
+ * This subprogram is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _Event_MP_Get_packet
+ *
+ */
+
+Event_MP_Packet *_Event_MP_Get_packet ( void )
+{
+ return ( (Event_MP_Packet *) _MPCI_Get_packet() );
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/eventreceive.c b/cpukit/rtems/src/eventreceive.c
new file mode 100644
index 0000000000..54bb7ef54c
--- /dev/null
+++ b/cpukit/rtems/src/eventreceive.c
@@ -0,0 +1,69 @@
+/*
+ * Event Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * rtems_event_receive
+ *
+ * This directive allows a thread to receive a set of events.
+ *
+ * Input parameters:
+ * event_in - input event condition
+ * option_set - options
+ * ticks - number of ticks to wait (0 means wait forever)
+ * event_out - pointer to output event set
+ *
+ * Output parameters:
+ * event out - event set
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_event_receive(
+ rtems_event_set event_in,
+ rtems_option option_set,
+ rtems_interval ticks,
+ rtems_event_set *event_out
+)
+{
+ RTEMS_API_Control *api;
+
+ if ( !event_out )
+ return RTEMS_INVALID_ADDRESS;
+
+ api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ];
+
+ if ( _Event_sets_Is_empty( event_in ) ) {
+ *event_out = api->pending_events;
+ return RTEMS_SUCCESSFUL;
+ }
+
+ _Thread_Disable_dispatch();
+ _Event_Seize( event_in, option_set, ticks, event_out );
+ _Thread_Enable_dispatch();
+ return( _Thread_Executing->Wait.return_code );
+}
diff --git a/cpukit/rtems/src/eventseize.c b/cpukit/rtems/src/eventseize.c
new file mode 100644
index 0000000000..0b6bf2d623
--- /dev/null
+++ b/cpukit/rtems/src/eventseize.c
@@ -0,0 +1,133 @@
+/*
+ * Event Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * _Event_Seize
+ *
+ * This routine attempts to satisfy the requested event condition
+ * for the running thread.
+ *
+ * Input parameters:
+ * event_in - the event condition to satisfy
+ * option_set - acquire event options
+ * ticks - interval to wait
+ * event_out - pointer to event set output area
+ *
+ * Output parameters: NONE
+ * *event_out - event set output area filled in
+ *
+ * INTERRUPT LATENCY:
+ * available
+ * wait
+ * check sync
+ */
+
+void _Event_Seize(
+ rtems_event_set event_in,
+ rtems_option option_set,
+ rtems_interval ticks,
+ rtems_event_set *event_out
+)
+{
+ Thread_Control *executing;
+ rtems_event_set seized_events;
+ rtems_event_set pending_events;
+ ISR_Level level;
+ RTEMS_API_Control *api;
+ Thread_blocking_operation_States sync_state;
+
+ executing = _Thread_Executing;
+ executing->Wait.return_code = RTEMS_SUCCESSFUL;
+
+ api = executing->API_Extensions[ THREAD_API_RTEMS ];
+
+ _ISR_Disable( level );
+ pending_events = api->pending_events;
+ seized_events = _Event_sets_Get( pending_events, event_in );
+
+ if ( !_Event_sets_Is_empty( seized_events ) &&
+ (seized_events == event_in || _Options_Is_any( option_set )) ) {
+ api->pending_events =
+ _Event_sets_Clear( pending_events, seized_events );
+ _ISR_Enable( level );
+ *event_out = seized_events;
+ return;
+ }
+
+ if ( _Options_Is_no_wait( option_set ) ) {
+ _ISR_Enable( level );
+ executing->Wait.return_code = RTEMS_UNSATISFIED;
+ *event_out = seized_events;
+ return;
+ }
+
+ /*
+ * Note what we are waiting for BEFORE we enter the critical section.
+ * The interrupt critical section management code needs this to be
+ * set properly when we are marked as in the event critical section.
+ *
+ * NOTE: Since interrupts are disabled, this isn't that much of an
+ * issue but better safe than sorry.
+ */
+ executing->Wait.option = (uint32_t) option_set;
+ executing->Wait.count = (uint32_t) event_in;
+ executing->Wait.return_argument = event_out;
+
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
+
+ _ISR_Enable( level );
+
+ if ( ticks ) {
+ _Watchdog_Initialize(
+ &executing->Timer,
+ _Event_Timeout,
+ executing->Object.id,
+ NULL
+ );
+ _Watchdog_Insert_ticks( &executing->Timer, ticks );
+ }
+
+ _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT );
+
+ _ISR_Disable( level );
+
+ sync_state = _Event_Sync_state;
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+ if ( sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
+ _ISR_Enable( level );
+ return;
+ }
+
+ /*
+ * An interrupt completed the thread's blocking request.
+ * The blocking thread was satisfied by an ISR or timed out.
+ *
+ * WARNING! Returning with interrupts disabled!
+ */
+ _Thread_blocking_operation_Cancel( sync_state, executing, level );
+}
diff --git a/cpukit/rtems/src/eventsend.c b/cpukit/rtems/src/eventsend.c
new file mode 100644
index 0000000000..412d52a7f1
--- /dev/null
+++ b/cpukit/rtems/src/eventsend.c
@@ -0,0 +1,78 @@
+/*
+ * Event Manager
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * rtems_event_send
+ *
+ * This directive allows a thread send an event set to another thread.
+ *
+ * Input parameters:
+ * id - thread id
+ * event - event set
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_event_send(
+ rtems_id id,
+ rtems_event_set event_in
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+ RTEMS_API_Control *api;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
+ _Event_sets_Post( event_in, &api->pending_events );
+ _Event_Surrender( the_thread );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return(
+ _Event_MP_Send_request_packet(
+ EVENT_MP_SEND_REQUEST,
+ id,
+ event_in
+ )
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/eventsurrender.c b/cpukit/rtems/src/eventsurrender.c
new file mode 100644
index 0000000000..179727f523
--- /dev/null
+++ b/cpukit/rtems/src/eventsurrender.c
@@ -0,0 +1,116 @@
+/*
+ * Event Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * _Event_Surrender
+ *
+ * This routines remove a thread from the specified threadq.
+ *
+ * Input parameters:
+ * the_thread - pointer to thread to be dequeued
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * before flash
+ * after flash
+ * check sync
+ */
+
+void _Event_Surrender(
+ Thread_Control *the_thread
+)
+{
+ ISR_Level level;
+ rtems_event_set pending_events;
+ rtems_event_set event_condition;
+ rtems_event_set seized_events;
+ rtems_option option_set;
+ RTEMS_API_Control *api;
+
+ api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
+
+ option_set = (rtems_option) the_thread->Wait.option;
+
+ _ISR_Disable( level );
+ pending_events = api->pending_events;
+ event_condition = (rtems_event_set) the_thread->Wait.count;
+
+ seized_events = _Event_sets_Get( pending_events, event_condition );
+
+ /*
+ * No events were seized in this operation
+ */
+ if ( _Event_sets_Is_empty( seized_events ) ) {
+ _ISR_Enable( level );
+ return;
+ }
+
+ /*
+ * If we are in an ISR and sending to the current thread, then
+ * we have a critical section issue to deal with.
+ */
+ if ( _ISR_Is_in_progress() &&
+ _Thread_Is_executing( the_thread ) &&
+ ((_Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT) ||
+ (_Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED)) ) {
+ if ( seized_events == event_condition || _Options_Is_any(option_set) ) {
+ api->pending_events = _Event_sets_Clear( pending_events,seized_events );
+ the_thread->Wait.count = 0;
+ *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_SATISFIED;
+ }
+ _ISR_Enable( level );
+ return;
+ }
+
+ /*
+ * Otherwise, this is a normal send to another thread
+ */
+ if ( _States_Is_waiting_for_event( the_thread->current_state ) ) {
+ if ( seized_events == event_condition || _Options_Is_any( option_set ) ) {
+ api->pending_events = _Event_sets_Clear( pending_events, seized_events );
+ the_thread->Wait.count = 0;
+ *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
+
+ _ISR_Flash( level );
+
+ if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
+ _ISR_Enable( level );
+ _Thread_Unblock( the_thread );
+ } else {
+ _Watchdog_Deactivate( &the_thread->Timer );
+ _ISR_Enable( level );
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ _Thread_Unblock( the_thread );
+ }
+ return;
+ }
+ }
+ _ISR_Enable( level );
+}
diff --git a/cpukit/rtems/src/eventtimeout.c b/cpukit/rtems/src/eventtimeout.c
new file mode 100644
index 0000000000..c1eef71f9e
--- /dev/null
+++ b/cpukit/rtems/src/eventtimeout.c
@@ -0,0 +1,93 @@
+/*
+ * Event Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/event.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * _Event_Timeout
+ *
+ * This routine processes a thread which timeouts while waiting to
+ * receive an event_set. It is called by the watchdog handler.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters: NONE
+ */
+
+void _Event_Timeout(
+ Objects_Id id,
+ void *ignored
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+ ISR_Level level;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ /*
+ * If the event manager is not synchronized, then it is either
+ * "nothing happened", "timeout", or "satisfied". If the_thread
+ * is the executing thread, then it is in the process of blocking
+ * and it is the thread which is responsible for the synchronization
+ * process.
+ *
+ * If it is not satisfied, then it is "nothing happened" and
+ * this is the "timeout" transition. After a request is satisfied,
+ * a timeout is not allowed to occur.
+ */
+ _ISR_Disable( level );
+ #if defined(RTEMS_DEBUG)
+ if ( !the_thread->Wait.count ) { /* verify thread is waiting */
+ _Thread_Unnest_dispatch();
+ _ISR_Enable( level );
+ return;
+ }
+ #endif
+
+ the_thread->Wait.count = 0;
+ if ( _Thread_Is_executing( the_thread ) ) {
+ if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED )
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_TIMEOUT;
+ }
+
+ the_thread->Wait.return_code = RTEMS_TIMEOUT;
+ _ISR_Enable( level );
+ _Thread_Unblock( the_thread );
+ _Thread_Unnest_dispatch();
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* impossible */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+}
diff --git a/cpukit/rtems/src/intrbody.c b/cpukit/rtems/src/intrbody.c
new file mode 100644
index 0000000000..aac994229d
--- /dev/null
+++ b/cpukit/rtems/src/intrbody.c
@@ -0,0 +1,74 @@
+/*
+ * Bodies for Inlined Interrupt Manager Routines
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/intr.h>
+
+/*
+ * Real body for rtems_interrupt_disable
+ */
+
+#undef rtems_interrupt_disable
+
+rtems_interrupt_level rtems_interrupt_disable( void )
+{
+ rtems_interrupt_level previous_level;
+
+ _ISR_Disable( previous_level );
+
+ return previous_level;
+}
+
+/*
+ * Real body for rtems_interrupt_enable
+ */
+
+#undef rtems_interrupt_enable
+
+void rtems_interrupt_enable(
+ rtems_interrupt_level previous_level
+)
+{
+ _ISR_Enable( previous_level );
+}
+
+/*
+ * Real body for rtems_interrupt_flash
+ */
+
+#undef rtems_interrupt_flash
+
+void rtems_interrupt_flash(
+ rtems_interrupt_level previous_level
+)
+{
+ _ISR_Flash( previous_level );
+}
+
+/*
+ * Real body for rtems_interrupt_is_in_progress
+ */
+
+#undef rtems_interrupt_is_in_progress
+
+bool rtems_interrupt_is_in_progress( void )
+{
+ return _ISR_Is_in_progress();
+}
diff --git a/cpukit/rtems/src/intrcatch.c b/cpukit/rtems/src/intrcatch.c
new file mode 100644
index 0000000000..dc3f1d4684
--- /dev/null
+++ b/cpukit/rtems/src/intrcatch.c
@@ -0,0 +1,61 @@
+/*
+ * Interrupt Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/intr.h>
+
+#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
+
+/* rtems_interrupt_catch
+ *
+ * This directive allows a thread to specify what action to take when
+ * catching signals.
+ *
+ * Input parameters:
+ * new_isr_handler - address of interrupt service routine (isr)
+ * vector - interrupt vector number
+ * old_isr_handler - address at which to store previous ISR address
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - always succeeds
+ * *old_isr_handler - previous ISR address
+ */
+
+rtems_status_code rtems_interrupt_catch(
+ rtems_isr_entry new_isr_handler,
+ rtems_vector_number vector,
+ rtems_isr_entry *old_isr_handler
+)
+{
+ if ( !_ISR_Is_vector_number_valid( vector ) )
+ return RTEMS_INVALID_NUMBER;
+
+ if ( !_ISR_Is_valid_user_handler( (void *) new_isr_handler ) )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !_ISR_Is_valid_user_handler( (void *) old_isr_handler ) )
+ return RTEMS_INVALID_ADDRESS;
+
+ _ISR_Install_vector(
+ vector, (proc_ptr)new_isr_handler, (proc_ptr *)old_isr_handler );
+
+ return RTEMS_SUCCESSFUL;
+}
+#endif
diff --git a/cpukit/rtems/src/mp.c b/cpukit/rtems/src/mp.c
new file mode 100644
index 0000000000..5749dddb4a
--- /dev/null
+++ b/cpukit/rtems/src/mp.c
@@ -0,0 +1,45 @@
+/*
+ * Multiprocessing Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/mp.h>
+#include <rtems/score/mpci.h>
+
+/*PAGE
+ *
+ * _Multiprocessing_Manager_initialization
+ *
+ */
+
+void _Multiprocessing_Manager_initialization ( void )
+{
+}
+
+/*PAGE
+ *
+ * rtems_multiprocessing_announce
+ *
+ */
+
+void rtems_multiprocessing_announce ( void )
+{
+ _MPCI_Announce();
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/msg.c b/cpukit/rtems/src/msg.c
new file mode 100644
index 0000000000..25e65aaaa5
--- /dev/null
+++ b/cpukit/rtems/src/msg.c
@@ -0,0 +1,81 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Message_queue_Manager_initialization
+ *
+ * This routine initializes all message queue manager related
+ * data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Message_queue_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Message_queue_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_MESSAGE_QUEUES, /* object class */
+ Configuration_RTEMS_API.maximum_message_queues,
+ /* maximum objects of this class */
+ sizeof( Message_queue_Control ),
+ /* size of this object's control block */
+ false, /* true if names of this object are strings */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of each object's name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ true, /* true if this is a global object class */
+ _Message_queue_MP_Send_extract_proxy
+ /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor(
+ MP_PACKET_MESSAGE_QUEUE,
+ _Message_queue_MP_Process_packet
+ );
+#endif
+
+}
diff --git a/cpukit/rtems/src/msgdata.c b/cpukit/rtems/src/msgdata.c
new file mode 100644
index 0000000000..70baa35723
--- /dev/null
+++ b/cpukit/rtems/src/msgdata.c
@@ -0,0 +1,23 @@
+/*
+ * Barrier Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate message queue data */
+#define RTEMS_MESSAGE_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/message.h>
+
diff --git a/cpukit/rtems/src/msgmp.c b/cpukit/rtems/src/msgmp.c
new file mode 100644
index 0000000000..9f033a8bbb
--- /dev/null
+++ b/cpukit/rtems/src/msgmp.c
@@ -0,0 +1,510 @@
+/*
+ * Multiprocessing Support for the Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/message.h>
+#include <rtems/score/mpci.h>
+#include <rtems/rtems/msgmp.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Message_queue_MP_Send_process_packet
+ *
+ */
+
+void _Message_queue_MP_Send_process_packet (
+ Message_queue_MP_Remote_operations operation,
+ Objects_Id message_queue_id,
+ rtems_name name,
+ Objects_Id proxy_id
+)
+{
+ Message_queue_MP_Packet *the_packet;
+ uint32_t node;
+
+ switch ( operation ) {
+
+ case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
+ case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
+ case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
+
+ the_packet = _Message_queue_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE;
+ the_packet->Prefix.length = sizeof ( Message_queue_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Message_queue_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = message_queue_id;
+ the_packet->name = name;
+ the_packet->proxy_id = proxy_id;
+
+ if ( operation == MESSAGE_QUEUE_MP_EXTRACT_PROXY )
+ node = _Objects_Get_node( message_queue_id );
+ else
+ node = MPCI_ALL_NODES;
+
+ _MPCI_Send_process_packet( node, &the_packet->Prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
+ case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
+ case MESSAGE_QUEUE_MP_SEND_REQUEST:
+ case MESSAGE_QUEUE_MP_SEND_RESPONSE:
+ case MESSAGE_QUEUE_MP_URGENT_REQUEST:
+ case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
+ case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
+ case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
+ case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+ case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ * _Message_queue_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _Message_queue_MP_Send_request_packet (
+ Message_queue_MP_Remote_operations operation,
+ Objects_Id message_queue_id,
+ const void *buffer,
+ size_t *size_p,
+ rtems_option option_set,
+ rtems_interval timeout
+)
+{
+ Message_queue_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case MESSAGE_QUEUE_MP_SEND_REQUEST:
+ case MESSAGE_QUEUE_MP_URGENT_REQUEST:
+ case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
+ case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+
+ the_packet = _Message_queue_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE;
+ the_packet->Prefix.length = sizeof(Message_queue_MP_Packet);
+ if ( size_p )
+ the_packet->Prefix.length += *size_p;
+ the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet);
+
+ /*
+ * make sure message is not too big for our MPCI driver
+ * We have to check it here instead of waiting for MPCI because
+ * we are about to slam in the payload
+ */
+
+ if (the_packet->Prefix.length > _MPCI_table->maximum_packet_size) {
+ _Thread_Enable_dispatch();
+ return RTEMS_INVALID_SIZE;
+ }
+
+ if (! _Options_Is_no_wait(option_set))
+ the_packet->Prefix.timeout = timeout;
+
+ the_packet->operation = operation;
+ the_packet->Prefix.id = message_queue_id;
+ the_packet->option_set = option_set;
+
+ /*
+ * Copy the data into place if needed
+ */
+
+ if (buffer) {
+ the_packet->Buffer.size = *size_p;
+ _CORE_message_queue_Copy_buffer(
+ buffer,
+ the_packet->Buffer.buffer,
+ *size_p
+ );
+ }
+
+ return (rtems_status_code) _MPCI_Send_request_packet(
+ _Objects_Get_node(message_queue_id),
+ &the_packet->Prefix,
+ STATES_WAITING_FOR_MESSAGE
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
+
+ the_packet = _Message_queue_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE;
+ the_packet->Prefix.length = sizeof(Message_queue_MP_Packet);
+ the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet);
+
+ if (! _Options_Is_no_wait(option_set))
+ the_packet->Prefix.timeout = timeout;
+
+ the_packet->operation = MESSAGE_QUEUE_MP_RECEIVE_REQUEST;
+ the_packet->Prefix.id = message_queue_id;
+ the_packet->option_set = option_set;
+ the_packet->size = 0; /* just in case of an error */
+
+ _Thread_Executing->Wait.return_argument_second.immutable_object = buffer;
+ _Thread_Executing->Wait.return_argument = size_p;
+
+ return (rtems_status_code) _MPCI_Send_request_packet(
+ _Objects_Get_node(message_queue_id),
+ &the_packet->Prefix,
+ STATES_WAITING_FOR_MESSAGE
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
+ case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
+ case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
+ case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
+ case MESSAGE_QUEUE_MP_SEND_RESPONSE:
+ case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
+ case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
+ case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
+ break;
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*PAGE
+ *
+ * _Message_queue_MP_Send_response_packet
+ *
+ */
+
+void _Message_queue_MP_Send_response_packet (
+ Message_queue_MP_Remote_operations operation,
+ Objects_Id message_queue_id,
+ Thread_Control *the_thread
+)
+{
+ Message_queue_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
+ case MESSAGE_QUEUE_MP_SEND_RESPONSE:
+ case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
+ case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
+ case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
+
+ the_packet = ( Message_queue_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ *
+ * Exception: MESSAGE_QUEUE_MP_RECEIVE_RESPONSE needs payload length
+ * added to 'length'
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ if (operation == MESSAGE_QUEUE_MP_RECEIVE_RESPONSE)
+ the_packet->Prefix.length += the_packet->size;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
+ case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
+ case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
+ case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
+ case MESSAGE_QUEUE_MP_SEND_REQUEST:
+ case MESSAGE_QUEUE_MP_URGENT_REQUEST:
+ case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
+ case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _Message_queue_MP_Process_packet
+ *
+ */
+
+void _Message_queue_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ Message_queue_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+ bool ignored;
+
+ the_packet = (Message_queue_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
+
+ ignored = _Objects_MP_Allocate_and_open(
+ &_Message_queue_Information,
+ the_packet->name,
+ the_packet->Prefix.id,
+ true
+ );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
+
+ _Objects_MP_Close( &_Message_queue_Information, the_packet->Prefix.id );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
+
+ the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
+
+ if (! _Thread_Is_null( the_thread ) )
+ _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_message_queue_receive(
+ the_packet->Prefix.id,
+ the_packet->Buffer.buffer,
+ &the_packet->size,
+ the_packet->option_set,
+ the_packet->Prefix.timeout
+ );
+
+ if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING )
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ if (the_packet->Prefix.return_code == RTEMS_SUCCESSFUL) {
+ *(size_t *) the_thread->Wait.return_argument =
+ the_packet->size;
+
+ _CORE_message_queue_Copy_buffer(
+ the_packet->Buffer.buffer,
+ the_thread->Wait.return_argument_second.mutable_object,
+ the_packet->size
+ );
+ }
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_SEND_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_message_queue_send(
+ the_packet->Prefix.id,
+ the_packet->Buffer.buffer,
+ the_packet->Buffer.size
+ );
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_SEND_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_SEND_RESPONSE:
+ case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_URGENT_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_message_queue_urgent(
+ the_packet->Prefix.id,
+ the_packet->Buffer.buffer,
+ the_packet->Buffer.size
+ );
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_URGENT_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_message_queue_broadcast(
+ the_packet->Prefix.id,
+ the_packet->Buffer.buffer,
+ the_packet->Buffer.size,
+ &the_packet->count
+ );
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_BROADCAST_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
+ case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ *(uint32_t *) the_thread->Wait.return_argument = the_packet->count;
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_message_queue_flush(
+ the_packet->Prefix.id,
+ &the_packet->count
+ );
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_FLUSH_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_message_queue_get_number_pending(
+ the_packet->Prefix.id,
+ &the_packet->count
+ );
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ * _Message_queue_MP_Send_object_was_deleted
+ *
+ */
+
+void _Message_queue_MP_Send_object_was_deleted (
+ Thread_Control *the_proxy
+)
+{
+ the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED;
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
+ the_proxy->Wait.id,
+ the_proxy
+ );
+}
+
+/*PAGE
+ *
+ * _Message_queue_MP_Send_extract_proxy
+ *
+ */
+
+void _Message_queue_MP_Send_extract_proxy (
+ void *argument
+)
+{
+ Thread_Control *the_thread = (Thread_Control *)argument;
+
+ _Message_queue_MP_Send_process_packet(
+ MESSAGE_QUEUE_MP_EXTRACT_PROXY,
+ the_thread->Wait.id,
+ (rtems_name) 0,
+ the_thread->Object.id
+ );
+}
+
+/*PAGE
+ *
+ * _Message_queue_MP_Get_packet
+ *
+ */
+
+Message_queue_MP_Packet *_Message_queue_MP_Get_packet ( void )
+{
+ return ( (Message_queue_MP_Packet *) _MPCI_Get_packet() );
+}
+
+
+/*PAGE
+ *
+ * _Message_queue_Core_message_queue_mp_support
+ *
+ * Input parameters:
+ * the_thread - the remote thread the message was submitted to
+ * id - id of the message queue
+ *
+ * Output parameters: NONE
+ */
+
+void _Message_queue_Core_message_queue_mp_support (
+ Thread_Control *the_thread,
+ Objects_Id id
+)
+{
+ the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
+
+ _Message_queue_MP_Send_response_packet(
+ MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
+ id,
+ the_thread
+ );
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/msgqallocate.c b/cpukit/rtems/src/msgqallocate.c
new file mode 100644
index 0000000000..e5603dd9d8
--- /dev/null
+++ b/cpukit/rtems/src/msgqallocate.c
@@ -0,0 +1,56 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Message_queue_Allocate
+ *
+ * Allocate a message queue and the space for its messages
+ *
+ * Input parameters:
+ * the_message_queue - the message queue to allocate message buffers
+ * count - maximum message and reserved buffer count
+ * max_message_size - maximum size of each message
+ *
+ * Output parameters:
+ * the_message_queue - set if successful, NULL otherwise
+ */
+
+Message_queue_Control *_Message_queue_Allocate(void)
+{
+ return (Message_queue_Control *)
+ _Objects_Allocate(&_Message_queue_Information);
+}
diff --git a/cpukit/rtems/src/msgqbroadcast.c b/cpukit/rtems/src/msgqbroadcast.c
new file mode 100644
index 0000000000..96389b8d23
--- /dev/null
+++ b/cpukit/rtems/src/msgqbroadcast.c
@@ -0,0 +1,113 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_broadcast
+ *
+ * This directive sends a message for every thread waiting on the queue
+ * designated by id.
+ *
+ * Input parameters:
+ * id - pointer to message queue
+ * buffer - pointer to message buffer
+ * size - size of message to broadcast
+ * count - pointer to area to store number of threads made ready
+ *
+ * Output parameters:
+ * count - number of threads made ready
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_broadcast(
+ rtems_id id,
+ const void *buffer,
+ size_t size,
+ uint32_t *count
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+ CORE_message_queue_Status core_status;
+
+ if ( !buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !count )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ core_status = _CORE_message_queue_Broadcast(
+ &the_message_queue->message_queue,
+ buffer,
+ size,
+ id,
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Message_queue_Core_message_queue_mp_support,
+ #else
+ NULL,
+ #endif
+ count
+ );
+
+ _Thread_Enable_dispatch();
+ return
+ _Message_queue_Translate_core_message_queue_return_code( core_status );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Executing->Wait.return_argument = count;
+
+ return
+ _Message_queue_MP_Send_request_packet(
+ MESSAGE_QUEUE_MP_BROADCAST_REQUEST,
+ id,
+ buffer,
+ &size,
+ 0, /* option_set not used */
+ MPCI_DEFAULT_TIMEOUT
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/msgqcreate.c b/cpukit/rtems/src/msgqcreate.c
new file mode 100644
index 0000000000..77af8eac95
--- /dev/null
+++ b/cpukit/rtems/src/msgqcreate.c
@@ -0,0 +1,165 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_create
+ *
+ * This directive creates a message queue by allocating and initializing
+ * a message queue data structure.
+ *
+ * Input parameters:
+ * name - user defined queue name
+ * count - maximum message and reserved buffer count
+ * max_message_size - maximum size of each message
+ * attribute_set - process method
+ * id - pointer to queue
+ *
+ * Output parameters:
+ * id - queue id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_create(
+ rtems_name name,
+ uint32_t count,
+ size_t max_message_size,
+ rtems_attribute attribute_set,
+ rtems_id *id
+)
+{
+ register Message_queue_Control *the_message_queue;
+ CORE_message_queue_Attributes the_msgq_attributes;
+#if defined(RTEMS_MULTIPROCESSING)
+ bool is_global;
+#endif
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
+ !_System_state_Is_multiprocessing )
+ return RTEMS_MP_NOT_CONFIGURED;
+#endif
+
+ if ( count == 0 )
+ return RTEMS_INVALID_NUMBER;
+
+ if ( max_message_size == 0 )
+ return RTEMS_INVALID_SIZE;
+
+#if defined(RTEMS_MULTIPROCESSING)
+#if 1
+ /*
+ * I am not 100% sure this should be an error.
+ * It seems reasonable to create a que with a large max size,
+ * and then just send smaller msgs from remote (or all) nodes.
+ */
+
+ if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) )
+ return RTEMS_INVALID_SIZE;
+#endif
+#endif
+
+ _Thread_Disable_dispatch(); /* protects object pointer */
+
+ the_message_queue = _Message_queue_Allocate();
+
+ if ( !the_message_queue ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global &&
+ !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
+ name, the_message_queue->Object.id, false ) ) ) {
+ _Message_queue_Free( the_message_queue );
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+#endif
+
+ the_message_queue->attribute_set = attribute_set;
+
+ if (_Attributes_Is_priority( attribute_set ) )
+ the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
+ else
+ the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
+
+ if ( ! _CORE_message_queue_Initialize(
+ &the_message_queue->message_queue,
+ &the_msgq_attributes,
+ count,
+ max_message_size
+ ) ) {
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global )
+ _Objects_MP_Close(
+ &_Message_queue_Information, the_message_queue->Object.id);
+#endif
+
+ _Message_queue_Free( the_message_queue );
+ _Thread_Enable_dispatch();
+ return RTEMS_UNSATISFIED;
+ }
+
+ _Objects_Open(
+ &_Message_queue_Information,
+ &the_message_queue->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_message_queue->Object.id;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global )
+ _Message_queue_MP_Send_process_packet(
+ MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
+ the_message_queue->Object.id,
+ name,
+ 0
+ );
+#endif
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/msgqdelete.c b/cpukit/rtems/src/msgqdelete.c
new file mode 100644
index 0000000000..8834886e38
--- /dev/null
+++ b/cpukit/rtems/src/msgqdelete.c
@@ -0,0 +1,107 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_delete
+ *
+ * This directive allows a thread to delete the message queue specified
+ * by the given queue identifier.
+ *
+ * Input parameters:
+ * id - queue id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_delete(
+ rtems_id id
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Close( &_Message_queue_Information,
+ &the_message_queue->Object );
+
+ _CORE_message_queue_Close(
+ &the_message_queue->message_queue,
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Message_queue_MP_Send_object_was_deleted,
+ #else
+ NULL,
+ #endif
+ CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED
+ );
+
+ _Message_queue_Free( the_message_queue );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) {
+ _Objects_MP_Close(
+ &_Message_queue_Information,
+ the_message_queue->Object.id
+ );
+
+ _Message_queue_MP_Send_process_packet(
+ MESSAGE_QUEUE_MP_ANNOUNCE_DELETE,
+ the_message_queue->Object.id,
+ 0, /* Not used */
+ 0
+ );
+ }
+#endif
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/msgqflush.c b/cpukit/rtems/src/msgqflush.c
new file mode 100644
index 0000000000..deee3b80ae
--- /dev/null
+++ b/cpukit/rtems/src/msgqflush.c
@@ -0,0 +1,94 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_flush
+ *
+ * This directive removes all pending messages from a queue and returns
+ * the number of messages removed. If no messages were present then
+ * a count of zero is returned.
+ *
+ * Input parameters:
+ * id - queue id
+ * count - return area for count
+ *
+ * Output parameters:
+ * count - number of messages removed ( 0 = empty queue )
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_flush(
+ rtems_id id,
+ uint32_t *count
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+
+ if ( !count )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ *count = _CORE_message_queue_Flush( &the_message_queue->message_queue );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Executing->Wait.return_argument = count;
+
+ return
+ _Message_queue_MP_Send_request_packet(
+ MESSAGE_QUEUE_MP_FLUSH_REQUEST,
+ id,
+ 0, /* buffer not used */
+ 0, /* size */
+ 0, /* option_set not used */
+ MPCI_DEFAULT_TIMEOUT
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/msgqgetnumberpending.c b/cpukit/rtems/src/msgqgetnumberpending.c
new file mode 100644
index 0000000000..cedb2b23d3
--- /dev/null
+++ b/cpukit/rtems/src/msgqgetnumberpending.c
@@ -0,0 +1,91 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_get_number_pending
+ *
+ * This directive returns the number of messages pending.
+ *
+ * Input parameters:
+ * id - queue id
+ * count - return area for count
+ *
+ * Output parameters:
+ * count - number of messages removed ( 0 = empty queue )
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_get_number_pending(
+ rtems_id id,
+ uint32_t *count
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+
+ if ( !count )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ *count = the_message_queue->message_queue.number_of_pending_messages;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Executing->Wait.return_argument = count;
+
+ return _Message_queue_MP_Send_request_packet(
+ MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST,
+ id,
+ 0, /* buffer not used */
+ 0, /* size */
+ 0, /* option_set not used */
+ MPCI_DEFAULT_TIMEOUT
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/msgqident.c b/cpukit/rtems/src/msgqident.c
new file mode 100644
index 0000000000..9030d5df3f
--- /dev/null
+++ b/cpukit/rtems/src/msgqident.c
@@ -0,0 +1,71 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_ident
+ *
+ * This directive returns the system ID associated with
+ * the message queue name.
+ *
+ * Input parameters:
+ * name - user defined message queue name
+ * node - node(s) to be searched
+ * id - pointer to message queue id
+ *
+ * Output parameters:
+ * *id - message queue id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Message_queue_Information,
+ name,
+ node,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/msgqreceive.c b/cpukit/rtems/src/msgqreceive.c
new file mode 100644
index 0000000000..f7f0db1605
--- /dev/null
+++ b/cpukit/rtems/src/msgqreceive.c
@@ -0,0 +1,113 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_receive
+ *
+ * This directive dequeues a message from the designated message queue
+ * and copies it into the requesting thread's buffer.
+ *
+ * Input parameters:
+ * id - queue id
+ * buffer - pointer to message buffer
+ * size - size of message receive
+ * option_set - options on receive
+ * timeout - number of ticks to wait
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_receive(
+ rtems_id id,
+ void *buffer,
+ size_t *size,
+ rtems_option option_set,
+ rtems_interval timeout
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+ bool wait;
+
+ if ( !buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !size )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( _Options_Is_no_wait( option_set ) )
+ wait = false;
+ else
+ wait = true;
+
+ _CORE_message_queue_Seize(
+ &the_message_queue->message_queue,
+ the_message_queue->Object.id,
+ buffer,
+ size,
+ wait,
+ timeout
+ );
+ _Thread_Enable_dispatch();
+ return _Message_queue_Translate_core_message_queue_return_code(
+ _Thread_Executing->Wait.return_code
+ );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Message_queue_MP_Send_request_packet(
+ MESSAGE_QUEUE_MP_RECEIVE_REQUEST,
+ id,
+ buffer,
+ size,
+ option_set,
+ timeout
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/msgqsend.c b/cpukit/rtems/src/msgqsend.c
new file mode 100644
index 0000000000..9c2c251cfd
--- /dev/null
+++ b/cpukit/rtems/src/msgqsend.c
@@ -0,0 +1,112 @@
+/*
+ * Message Queue Manager - rtems_message_queue_send
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*
+ *
+ * rtems_message_queue_send
+ *
+ * This routine implements the directive rtems_message_queue_send. It sends a
+ * message to the specified message queue.
+ *
+ * Input parameters:
+ * id - pointer to message queue
+ * buffer - pointer to message buffer
+ * size - size of message to send
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+#define MESSAGE_QUEUE_MP_HANDLER _Message_queue_Core_message_queue_mp_support
+#else
+#define MESSAGE_QUEUE_MP_HANDLER NULL
+#endif
+
+rtems_status_code rtems_message_queue_send(
+ rtems_id id,
+ const void *buffer,
+ size_t size
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+ CORE_message_queue_Status status;
+
+ if ( !buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_message_queue_Send(
+ &the_message_queue->message_queue,
+ buffer,
+ size,
+ id,
+ MESSAGE_QUEUE_MP_HANDLER,
+ false, /* sender does not block */
+ 0 /* no timeout */
+ );
+
+ _Thread_Enable_dispatch();
+
+ /*
+ * Since this API does not allow for blocking sends, we can directly
+ * return the returned status.
+ */
+
+ return _Message_queue_Translate_core_message_queue_return_code(status);
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Message_queue_MP_Send_request_packet(
+ MESSAGE_QUEUE_MP_SEND_REQUEST,
+ id,
+ buffer,
+ &size,
+ 0, /* option_set */
+ MPCI_DEFAULT_TIMEOUT
+ );
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/msgqtranslatereturncode.c b/cpukit/rtems/src/msgqtranslatereturncode.c
new file mode 100644
index 0000000000..8a554cb7cc
--- /dev/null
+++ b/cpukit/rtems/src/msgqtranslatereturncode.c
@@ -0,0 +1,81 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Message_queue_Translate_core_message_queue_return_code
+ *
+ * Input parameters:
+ * the_message_queue_status - message_queue status code to translate
+ *
+ * Output parameters:
+ * rtems status code - translated RTEMS status code
+ *
+ */
+
+rtems_status_code _Message_queue_Translate_core_return_code_[] = {
+ RTEMS_SUCCESSFUL, /* CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL */
+ RTEMS_INVALID_SIZE, /* CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE */
+ RTEMS_TOO_MANY, /* CORE_MESSAGE_QUEUE_STATUS_TOO_MANY */
+ RTEMS_UNSATISFIED, /* CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED */
+ RTEMS_UNSATISFIED, /* CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT */
+ RTEMS_OBJECT_WAS_DELETED, /* CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED */
+ RTEMS_TIMEOUT /* CORE_MESSAGE_QUEUE_STATUS_TIMEOUT */
+};
+
+rtems_status_code _Message_queue_Translate_core_message_queue_return_code (
+ uint32_t status
+)
+{
+ /*
+ * Check for proxy blocking first since it is out of range
+ * from the external status codes.
+ */
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _Thread_Is_proxy_blocking(status) )
+ return RTEMS_PROXY_BLOCKING;
+ #endif
+
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( status > CORE_MESSAGE_QUEUE_STATUS_TIMEOUT )
+ return RTEMS_INTERNAL_ERROR;
+ #endif
+
+ return _Message_queue_Translate_core_return_code_[status];
+}
diff --git a/cpukit/rtems/src/msgqurgent.c b/cpukit/rtems/src/msgqurgent.c
new file mode 100644
index 0000000000..ddb66a8488
--- /dev/null
+++ b/cpukit/rtems/src/msgqurgent.c
@@ -0,0 +1,111 @@
+/*
+ * Message Queue Manager - rtems_message_queue_urgent
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_urgent
+ *
+ * This routine implements the directives rtems_message_queue_urgent. It
+ * prepends a message to the specified message queue.
+ *
+ * Input parameters:
+ * id - pointer to message queue
+ * buffer - pointer to message buffer
+ * size - size of message to send urgently
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+#define MESSAGE_QUEUE_MP_HANDLER _Message_queue_Core_message_queue_mp_support
+#else
+#define MESSAGE_QUEUE_MP_HANDLER NULL
+#endif
+
+rtems_status_code rtems_message_queue_urgent(
+ rtems_id id,
+ const void *buffer,
+ size_t size
+)
+{
+ register Message_queue_Control *the_message_queue;
+ Objects_Locations location;
+ CORE_message_queue_Status status;
+
+ if ( !buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_message_queue = _Message_queue_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status = _CORE_message_queue_Urgent(
+ &the_message_queue->message_queue,
+ buffer,
+ size,
+ id,
+ MESSAGE_QUEUE_MP_HANDLER,
+ false, /* sender does not block */
+ 0 /* no timeout */
+ );
+ _Thread_Enable_dispatch();
+
+ /*
+ * Since this API does not allow for blocking sends, we can directly
+ * return the returned status.
+ */
+
+ return _Message_queue_Translate_core_message_queue_return_code(status);
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Message_queue_MP_Send_request_packet(
+ MESSAGE_QUEUE_MP_URGENT_REQUEST,
+ id,
+ buffer,
+ &size,
+ 0, /* option_set */
+ MPCI_DEFAULT_TIMEOUT
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/part.c b/cpukit/rtems/src/part.c
new file mode 100644
index 0000000000..a5c12e5fb9
--- /dev/null
+++ b/cpukit/rtems/src/part.c
@@ -0,0 +1,69 @@
+/*
+ * Partition Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * _Partition_Manager_initialization
+ *
+ * This routine initializes all partition manager related
+ * data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Partition_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Partition_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_PARTITIONS, /* object class */
+ Configuration_RTEMS_API.maximum_partitions,
+ /* maximum objects of this class */
+ sizeof( Partition_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ true, /* true if this is a global object class */
+ _Partition_MP_Send_extract_proxy /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor(
+ MP_PACKET_PARTITION,
+ _Partition_MP_Process_packet
+ );
+#endif
+
+}
diff --git a/cpukit/rtems/src/partcreate.c b/cpukit/rtems/src/partcreate.c
new file mode 100644
index 0000000000..6b3d819ea5
--- /dev/null
+++ b/cpukit/rtems/src/partcreate.c
@@ -0,0 +1,129 @@
+/*
+ * Partition Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_partition_create
+ *
+ * This directive creates a partiton of fixed sized buffers from the
+ * given contiguous memory area.
+ *
+ * Input parameters:
+ * name - user defined partition name
+ * starting_address - physical start address of partition
+ * length - physical length in bytes
+ * buffer_size - size of buffers in bytes
+ * attribute_set - partition attributes
+ * id - pointer to partition id
+ *
+ * Output parameters:
+ * id - partition id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_partition_create(
+ rtems_name name,
+ void *starting_address,
+ uint32_t length,
+ uint32_t buffer_size,
+ rtems_attribute attribute_set,
+ rtems_id *id
+)
+{
+ register Partition_Control *the_partition;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !starting_address )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( length == 0 || buffer_size == 0 || length < buffer_size ||
+ !_Partition_Is_buffer_size_aligned( buffer_size ) )
+ return RTEMS_INVALID_SIZE;
+
+ if ( !_Addresses_Is_aligned( starting_address ) )
+ return RTEMS_INVALID_ADDRESS;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( attribute_set ) &&
+ !_System_state_Is_multiprocessing )
+ return RTEMS_MP_NOT_CONFIGURED;
+#endif
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_partition = _Partition_Allocate();
+
+ if ( !the_partition ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( attribute_set ) &&
+ !( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
+ the_partition->Object.id, false ) ) ) {
+ _Partition_Free( the_partition );
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+#endif
+
+ the_partition->starting_address = starting_address;
+ the_partition->length = length;
+ the_partition->buffer_size = buffer_size;
+ the_partition->attribute_set = attribute_set;
+ the_partition->number_of_used_blocks = 0;
+
+ _Chain_Initialize( &the_partition->Memory, starting_address,
+ length / buffer_size, buffer_size );
+
+ _Objects_Open(
+ &_Partition_Information,
+ &the_partition->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_partition->Object.id;
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( attribute_set ) )
+ _Partition_MP_Send_process_packet(
+ PARTITION_MP_ANNOUNCE_CREATE,
+ the_partition->Object.id,
+ name,
+ 0 /* Not used */
+ );
+#endif
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/partdata.c b/cpukit/rtems/src/partdata.c
new file mode 100644
index 0000000000..8f6c5b4531
--- /dev/null
+++ b/cpukit/rtems/src/partdata.c
@@ -0,0 +1,22 @@
+/*
+ * Partition Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS partition data */
+#define RTEMS_PART_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/part.h>
diff --git a/cpukit/rtems/src/partdelete.c b/cpukit/rtems/src/partdelete.c
new file mode 100644
index 0000000000..871e198f3f
--- /dev/null
+++ b/cpukit/rtems/src/partdelete.c
@@ -0,0 +1,92 @@
+/*
+ * Partition Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_partition_delete
+ *
+ * This directive allows a thread to delete a partition specified by
+ * the partition identifier, provided that none of its buffers are
+ * still allocated.
+ *
+ * Input parameters:
+ * id - partition id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_partition_delete(
+ rtems_id id
+)
+{
+ register Partition_Control *the_partition;
+ Objects_Locations location;
+
+ the_partition = _Partition_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( the_partition->number_of_used_blocks == 0 ) {
+ _Objects_Close( &_Partition_Information, &the_partition->Object );
+ _Partition_Free( the_partition );
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( the_partition->attribute_set ) ) {
+
+ _Objects_MP_Close(
+ &_Partition_Information,
+ the_partition->Object.id
+ );
+
+ _Partition_MP_Send_process_packet(
+ PARTITION_MP_ANNOUNCE_DELETE,
+ the_partition->Object.id,
+ 0, /* Not used */
+ 0 /* Not used */
+ );
+ }
+#endif
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_RESOURCE_IN_USE;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/partgetbuffer.c b/cpukit/rtems/src/partgetbuffer.c
new file mode 100644
index 0000000000..56d58a1103
--- /dev/null
+++ b/cpukit/rtems/src/partgetbuffer.c
@@ -0,0 +1,87 @@
+/*
+ * Partition Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_partition_get_buffer
+ *
+ * This directive will obtain a buffer from a buffer partition.
+ *
+ * Input parameters:
+ * id - partition id
+ * buffer - pointer to buffer address
+ *
+ * Output parameters:
+ * buffer - pointer to buffer address filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_partition_get_buffer(
+ rtems_id id,
+ void **buffer
+)
+{
+ register Partition_Control *the_partition;
+ Objects_Locations location;
+ void *the_buffer;
+
+ if ( !buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_partition = _Partition_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_buffer = _Partition_Allocate_buffer( the_partition );
+ if ( the_buffer ) {
+ the_partition->number_of_used_blocks += 1;
+ _Thread_Enable_dispatch();
+ *buffer = the_buffer;
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_UNSATISFIED;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Executing->Wait.return_argument = buffer;
+ return(
+ _Partition_MP_Send_request_packet(
+ PARTITION_MP_GET_BUFFER_REQUEST,
+ id,
+ 0 /* Not used */
+ )
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/partident.c b/cpukit/rtems/src/partident.c
new file mode 100644
index 0000000000..8f9004ea8e
--- /dev/null
+++ b/cpukit/rtems/src/partident.c
@@ -0,0 +1,57 @@
+/*
+ * Partition Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_partition_ident
+ *
+ * This directive returns the system ID associated with
+ * the partition name.
+ *
+ * Input parameters:
+ * name - user defined partition name
+ * node - node(s) to be searched
+ * id - pointer to partition id
+ *
+ * Output parameters:
+ * *id - partition id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_partition_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32( &_Partition_Information, name, node, id );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/partmp.c b/cpukit/rtems/src/partmp.c
new file mode 100644
index 0000000000..da6e2ca8d6
--- /dev/null
+++ b/cpukit/rtems/src/partmp.c
@@ -0,0 +1,307 @@
+/*
+ * Multiprocessing Support for the Partition Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Partition_MP_Send_process_packet
+ *
+ */
+
+void _Partition_MP_Send_process_packet (
+ Partition_MP_Remote_operations operation,
+ Objects_Id partition_id,
+ rtems_name name,
+ Objects_Id proxy_id
+)
+{
+ Partition_MP_Packet *the_packet;
+ uint32_t node;
+
+ switch ( operation ) {
+
+ case PARTITION_MP_ANNOUNCE_CREATE:
+ case PARTITION_MP_ANNOUNCE_DELETE:
+ case PARTITION_MP_EXTRACT_PROXY:
+
+ the_packet = _Partition_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_PARTITION;
+ the_packet->Prefix.length = sizeof ( Partition_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Partition_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = partition_id;
+ the_packet->name = name;
+ the_packet->proxy_id = proxy_id;
+
+ if ( operation == PARTITION_MP_EXTRACT_PROXY )
+ node = _Objects_Get_node( partition_id );
+ else
+ node = MPCI_ALL_NODES;
+
+ _MPCI_Send_process_packet( node, &the_packet->Prefix );
+ break;
+
+ case PARTITION_MP_GET_BUFFER_REQUEST:
+ case PARTITION_MP_GET_BUFFER_RESPONSE:
+ case PARTITION_MP_RETURN_BUFFER_REQUEST:
+ case PARTITION_MP_RETURN_BUFFER_RESPONSE:
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _Partition_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _Partition_MP_Send_request_packet (
+ Partition_MP_Remote_operations operation,
+ Objects_Id partition_id,
+ void *buffer
+)
+{
+ Partition_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case PARTITION_MP_GET_BUFFER_REQUEST:
+ case PARTITION_MP_RETURN_BUFFER_REQUEST:
+
+ the_packet = _Partition_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_PARTITION;
+ the_packet->Prefix.length = sizeof ( Partition_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Partition_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = partition_id;
+ the_packet->buffer = buffer;
+
+ return
+ _MPCI_Send_request_packet(
+ _Objects_Get_node( partition_id ),
+ &the_packet->Prefix,
+ STATES_READY /* Not used */
+ );
+
+ break;
+
+ case PARTITION_MP_ANNOUNCE_CREATE:
+ case PARTITION_MP_ANNOUNCE_DELETE:
+ case PARTITION_MP_EXTRACT_PROXY:
+ case PARTITION_MP_GET_BUFFER_RESPONSE:
+ case PARTITION_MP_RETURN_BUFFER_RESPONSE:
+ break;
+
+ }
+ /*
+ * The following line is included to satisfy compilers which
+ * produce warnings when a function does not end with a return.
+ */
+ return RTEMS_SUCCESSFUL;
+}
+
+/*PAGE
+ *
+ * _Partition_MP_Send_response_packet
+ *
+ */
+
+void _Partition_MP_Send_response_packet (
+ Partition_MP_Remote_operations operation,
+ Objects_Id partition_id,
+ Thread_Control *the_thread
+)
+{
+ Partition_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case PARTITION_MP_GET_BUFFER_RESPONSE:
+ case PARTITION_MP_RETURN_BUFFER_RESPONSE:
+
+ the_packet = ( Partition_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case PARTITION_MP_ANNOUNCE_CREATE:
+ case PARTITION_MP_ANNOUNCE_DELETE:
+ case PARTITION_MP_EXTRACT_PROXY:
+ case PARTITION_MP_GET_BUFFER_REQUEST:
+ case PARTITION_MP_RETURN_BUFFER_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _Partition_MP_Process_packet
+ *
+ */
+
+void _Partition_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ Partition_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+ bool ignored;
+
+ the_packet = (Partition_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case PARTITION_MP_ANNOUNCE_CREATE:
+
+ ignored = _Objects_MP_Allocate_and_open(
+ &_Partition_Information,
+ the_packet->name,
+ the_packet->Prefix.id,
+ true
+ );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case PARTITION_MP_ANNOUNCE_DELETE:
+
+ _Objects_MP_Close( &_Partition_Information, the_packet->Prefix.id );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case PARTITION_MP_EXTRACT_PROXY:
+
+ the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
+
+ if ( ! _Thread_Is_null( the_thread ) )
+ _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case PARTITION_MP_GET_BUFFER_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_partition_get_buffer(
+ the_packet->Prefix.id,
+ &the_packet->buffer
+ );
+
+ _Partition_MP_Send_response_packet(
+ PARTITION_MP_GET_BUFFER_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case PARTITION_MP_GET_BUFFER_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ *(void **)the_thread->Wait.return_argument = the_packet->buffer;
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case PARTITION_MP_RETURN_BUFFER_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_partition_return_buffer(
+ the_packet->Prefix.id,
+ the_packet->buffer
+ );
+
+ _Partition_MP_Send_response_packet(
+ PARTITION_MP_RETURN_BUFFER_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case PARTITION_MP_RETURN_BUFFER_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ * _Partition_MP_Send_object_was_deleted
+ *
+ * This routine is not needed by the Partition since a partition
+ * cannot be deleted when buffers are in use.
+ *
+ */
+
+/*PAGE
+ *
+ * _Partition_MP_Send_extract_proxy
+ *
+ */
+
+void _Partition_MP_Send_extract_proxy (
+ void *argument
+)
+{
+ Thread_Control *the_thread = (Thread_Control *)argument;
+
+ _Partition_MP_Send_process_packet(
+ PARTITION_MP_EXTRACT_PROXY,
+ the_thread->Wait.id,
+ (rtems_name) 0,
+ the_thread->Object.id
+ );
+
+}
+
+/*PAGE
+ *
+ * _Partition_MP_Get_packet
+ *
+ */
+
+Partition_MP_Packet *_Partition_MP_Get_packet ( void )
+{
+ return ( (Partition_MP_Packet *) _MPCI_Get_packet() );
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/partreturnbuffer.c b/cpukit/rtems/src/partreturnbuffer.c
new file mode 100644
index 0000000000..8b83ab3cec
--- /dev/null
+++ b/cpukit/rtems/src/partreturnbuffer.c
@@ -0,0 +1,79 @@
+/*
+ * Partition Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/address.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/part.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_partition_return_buffer
+ *
+ * This directive will return the given buffer to the specified
+ * buffer partition.
+ *
+ * Input parameters:
+ * id - partition id
+ * buffer - pointer to buffer address
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_partition_return_buffer(
+ rtems_id id,
+ void *buffer
+)
+{
+ register Partition_Control *the_partition;
+ Objects_Locations location;
+
+ the_partition = _Partition_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( _Partition_Is_buffer_valid( buffer, the_partition ) ) {
+ _Partition_Free_buffer( the_partition, buffer );
+ the_partition->number_of_used_blocks -= 1;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_INVALID_ADDRESS;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Partition_MP_Send_request_packet(
+ PARTITION_MP_RETURN_BUFFER_REQUEST,
+ id,
+ buffer
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemon.c b/cpukit/rtems/src/ratemon.c
new file mode 100644
index 0000000000..9f17a777b8
--- /dev/null
+++ b/cpukit/rtems/src/ratemon.c
@@ -0,0 +1,60 @@
+/*
+ * Rate Monotonic Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * _Rate_monotonic_Manager_initialization
+ *
+ * This routine initializes all Rate Monotonic Manager related
+ * data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ *
+ * NOTE: The Rate Monotonic Manager is built on top of the Watchdog
+ * Handler.
+ */
+
+void _Rate_monotonic_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Rate_monotonic_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_PERIODS, /* object class */
+ Configuration_RTEMS_API.maximum_periods,
+ /* maximum objects of this class */
+ sizeof( Rate_monotonic_Control ),/* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/rtems/src/ratemoncancel.c b/cpukit/rtems/src/ratemoncancel.c
new file mode 100644
index 0000000000..7950fe58d1
--- /dev/null
+++ b/cpukit/rtems/src/ratemoncancel.c
@@ -0,0 +1,68 @@
+/*
+ * Rate Monotonic Manager -- Cancel a Period
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_cancel
+ *
+ * This directive allows a thread to cancel a rate monotonic timer.
+ *
+ * Input parameters:
+ * id - rate monotonic id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful and caller is not the owning thread
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_rate_monotonic_cancel(
+ rtems_id id
+)
+{
+ Rate_monotonic_Control *the_period;
+ Objects_Locations location;
+
+ the_period = _Rate_monotonic_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Thread_Is_executing( the_period->owner ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_NOT_OWNER_OF_RESOURCE;
+ }
+ (void) _Watchdog_Remove( &the_period->Timer );
+ the_period->state = RATE_MONOTONIC_INACTIVE;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemoncreate.c b/cpukit/rtems/src/ratemoncreate.c
new file mode 100644
index 0000000000..9fb16aa56c
--- /dev/null
+++ b/cpukit/rtems/src/ratemoncreate.c
@@ -0,0 +1,81 @@
+/*
+ * Rate Monotonic Manager -- Create a Period
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_create
+ *
+ * This directive creates a rate monotonic timer and performs
+ * some initialization.
+ *
+ * Input parameters:
+ * name - name of period
+ * id - pointer to rate monotonic id
+ *
+ * Output parameters:
+ * id - rate monotonic id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_rate_monotonic_create(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Rate_monotonic_Control *the_period;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ _Thread_Disable_dispatch(); /* to prevent deletion */
+
+ the_period = _Rate_monotonic_Allocate();
+
+ if ( !the_period ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+ the_period->owner = _Thread_Executing;
+ the_period->state = RATE_MONOTONIC_INACTIVE;
+
+ _Watchdog_Initialize( &the_period->Timer, NULL, 0, NULL );
+
+ _Rate_monotonic_Reset_statistics( the_period );
+
+ _Objects_Open(
+ &_Rate_monotonic_Information,
+ &the_period->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_period->Object.id;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/ratemondata.c b/cpukit/rtems/src/ratemondata.c
new file mode 100644
index 0000000000..efd461fa02
--- /dev/null
+++ b/cpukit/rtems/src/ratemondata.c
@@ -0,0 +1,22 @@
+/*
+ * Rate Monotonic Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS period data */
+#define RTEMS_RATEMON_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/ratemon.h>
diff --git a/cpukit/rtems/src/ratemondelete.c b/cpukit/rtems/src/ratemondelete.c
new file mode 100644
index 0000000000..8149233079
--- /dev/null
+++ b/cpukit/rtems/src/ratemondelete.c
@@ -0,0 +1,66 @@
+/*
+ * Rate Monotonic Manager -- Delete a Period
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_delete
+ *
+ * This directive allows a thread to delete a rate monotonic timer.
+ *
+ * Input parameters:
+ * id - rate monotonic id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_rate_monotonic_delete(
+ rtems_id id
+)
+{
+ Rate_monotonic_Control *the_period;
+ Objects_Locations location;
+
+ the_period = _Rate_monotonic_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Close( &_Rate_monotonic_Information, &the_period->Object );
+ (void) _Watchdog_Remove( &the_period->Timer );
+ the_period->state = RATE_MONOTONIC_INACTIVE;
+ _Rate_monotonic_Free( the_period );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemongetstatistics.c b/cpukit/rtems/src/ratemongetstatistics.c
new file mode 100644
index 0000000000..0ecd5515f1
--- /dev/null
+++ b/cpukit/rtems/src/ratemongetstatistics.c
@@ -0,0 +1,91 @@
+/*
+ * Rate Monotonic Manager -- Get Statistics
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_get_statistics
+ *
+ * This directive allows a thread to obtain statistics information on a
+ * period.
+ *
+ * Input parameters:
+ * id - rate monotonic id
+ * statistics - pointer to statistics control block
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ *
+ */
+
+rtems_status_code rtems_rate_monotonic_get_statistics(
+ rtems_id id,
+ rtems_rate_monotonic_period_statistics *statistics
+)
+{
+ Objects_Locations location;
+ Rate_monotonic_Control *the_period;
+ rtems_rate_monotonic_period_statistics *dst;
+ Rate_monotonic_Statistics *src;
+
+ if ( !statistics )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_period = _Rate_monotonic_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ dst = statistics;
+ src = &the_period->Statistics;
+ dst->count = src->count;
+ dst->missed_count = src->missed_count;
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_To_timespec( &src->min_cpu_time, &dst->min_cpu_time );
+ _Timestamp_To_timespec( &src->max_cpu_time, &dst->max_cpu_time );
+ _Timestamp_To_timespec( &src->total_cpu_time, &dst->total_cpu_time );
+ _Timestamp_To_timespec( &src->min_wall_time, &dst->min_wall_time );
+ _Timestamp_To_timespec( &src->max_wall_time, &dst->max_wall_time );
+ _Timestamp_To_timespec( &src->total_wall_time, &dst->total_wall_time );
+ #else
+ dst->min_cpu_time = src->min_cpu_time;
+ dst->max_cpu_time = src->max_cpu_time;
+ dst->total_cpu_time = src->total_cpu_time;
+ dst->min_wall_time = src->min_wall_time;
+ dst->max_wall_time = src->max_wall_time;
+ dst->total_wall_time = src->total_wall_time;
+ #endif
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemongetstatus.c b/cpukit/rtems/src/ratemongetstatus.c
new file mode 100644
index 0000000000..c18b5b57ba
--- /dev/null
+++ b/cpukit/rtems/src/ratemongetstatus.c
@@ -0,0 +1,118 @@
+/*
+ * Rate Monotonic Manager -- Get Status
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timespec.h>
+#endif
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_get_status
+ *
+ * This directive allows a thread to obtain status information on a
+ * period.
+ *
+ * Input parameters:
+ * id - rate monotonic id
+ * status - pointer to status control block
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ *
+ */
+
+rtems_status_code rtems_rate_monotonic_get_status(
+ rtems_id id,
+ rtems_rate_monotonic_period_status *status
+)
+{
+ Thread_CPU_usage_t executed;
+ Objects_Locations location;
+ Rate_monotonic_Period_time_t since_last_period;
+ Rate_monotonic_Control *the_period;
+ bool valid_status;
+
+ if ( !status )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_period = _Rate_monotonic_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ status->owner = the_period->owner->Object.id;
+ status->state = the_period->state;
+
+ /*
+ * If the period is inactive, there is no information.
+ */
+ if ( status->state == RATE_MONOTONIC_INACTIVE ) {
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timespec_Set_to_zero( &status->since_last_period );
+ _Timespec_Set_to_zero( &status->executed_since_last_period );
+ #else
+ status->since_last_period = 0;
+ status->executed_since_last_period = 0;
+ #endif
+
+ } else {
+
+ /*
+ * Grab the current status.
+ */
+ valid_status =
+ _Rate_monotonic_Get_status(
+ the_period, &since_last_period, &executed
+ );
+ if (!valid_status) {
+ _Thread_Enable_dispatch();
+ return RTEMS_NOT_DEFINED;
+ }
+
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_To_timespec(
+ &since_last_period, &status->since_last_period
+ );
+ _Timestamp_To_timespec(
+ &executed, &status->executed_since_last_period
+ );
+ #else
+ status->since_last_period = since_last_period;
+ status->executed_since_last_period = executed;
+ #endif
+ }
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemonident.c b/cpukit/rtems/src/ratemonident.c
new file mode 100644
index 0000000000..68df076cbb
--- /dev/null
+++ b/cpukit/rtems/src/ratemonident.c
@@ -0,0 +1,58 @@
+/*
+ * Rate Monotonic Manager -- Name to Id Lookup
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_ident
+ *
+ * This directive returns the system ID associated with
+ * the rate monotonic period name.
+ *
+ * Input parameters:
+ * name - user defined period name
+ * id - pointer to period id
+ *
+ * Output parameters:
+ * *id - region id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_rate_monotonic_ident(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Rate_monotonic_Information,
+ name,
+ OBJECTS_SEARCH_LOCAL_NODE,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c
new file mode 100644
index 0000000000..e244fd5778
--- /dev/null
+++ b/cpukit/rtems/src/ratemonperiod.c
@@ -0,0 +1,374 @@
+/*
+ * Rate Monotonic Manager - Period Blocking and Status
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+bool _Rate_monotonic_Get_status(
+ Rate_monotonic_Control *the_period,
+ Rate_monotonic_Period_time_t *wall_since_last_period,
+ Thread_CPU_usage_t *cpu_since_last_period
+)
+{
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ Timestamp_Control uptime;
+ #endif
+ Thread_Control *owning_thread = the_period->owner;
+ Thread_CPU_usage_t used;
+
+ /*
+ * Determine elapsed wall time since period initiated.
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _TOD_Get_uptime( &uptime );
+ _Timestamp_Subtract(
+ &the_period->time_period_initiated, &uptime, wall_since_last_period
+ );
+ #else
+ *wall_since_last_period =
+ _Watchdog_Ticks_since_boot - the_period->time_period_initiated;
+ #endif
+
+ /*
+ * Determine cpu usage since period initiated.
+ */
+ used = owning_thread->cpu_time_used;
+
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ if (owning_thread == _Thread_Executing) {
+
+ Thread_CPU_usage_t ran;
+
+ /* How much time time since last context switch */
+ _Timestamp_Subtract(
+ &_Thread_Time_of_last_context_switch, &uptime, &ran
+ );
+
+ /* cpu usage += ran */
+ _Timestamp_Add_to( &used, &ran );
+
+ /*
+ * The cpu usage info was reset while executing. Can't
+ * determine a status.
+ */
+ if (_Timestamp_Less_than(&used, &the_period->cpu_usage_period_initiated))
+ return false;
+
+ /* used = current cpu usage - cpu usage at start of period */
+ _Timestamp_Subtract(
+ &the_period->cpu_usage_period_initiated,
+ &used,
+ cpu_since_last_period
+ );
+ }
+ #else
+ /*
+ * The cpu usage info was reset while executing. Can't
+ * determine a status.
+ */
+ if (used < the_period->cpu_usage_period_initiated)
+ return false;
+
+ *cpu_since_last_period = used - the_period->cpu_usage_period_initiated;
+ #endif
+ return true;
+}
+
+void _Rate_monotonic_Initiate_statistics(
+ Rate_monotonic_Control *the_period
+)
+{
+ Thread_Control *owning_thread = the_period->owner;
+
+ /*
+ * If using nanosecond statistics, we need to obtain the uptime.
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ Timestamp_Control uptime;
+
+ _TOD_Get_uptime( &uptime );
+ #endif
+
+ /*
+ * Set the starting point and the CPU time used for the statistics.
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ the_period->time_period_initiated = uptime;
+ #else
+ the_period->time_period_initiated = _Watchdog_Ticks_since_boot;
+ #endif
+
+ the_period->cpu_usage_period_initiated = owning_thread->cpu_time_used;
+
+ /*
+ * If using nanosecond statistics and the period's thread is currently
+ * executing, then we need to take into account how much time the
+ * executing thread has run since the last context switch. When this
+ * routine is invoked from rtems_rate_monotonic_period, the owner will
+ * be the executing thread. When this routine is invoked from
+ * _Rate_monotonic_Timeout, it will not.
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ if (owning_thread == _Thread_Executing) {
+
+ rtems_thread_cpu_usage_t ran;
+
+ /*
+ * Adjust the CPU time used to account for the time since last
+ * context switch.
+ */
+ _Timespec_Subtract(
+ &_Thread_Time_of_last_context_switch, &uptime, &ran
+ );
+
+ _Timespec_Add_to( &the_period->cpu_usage_period_initiated, &ran );
+ }
+ #endif
+}
+
+void _Rate_monotonic_Update_statistics(
+ Rate_monotonic_Control *the_period
+)
+{
+ Thread_CPU_usage_t executed;
+ Rate_monotonic_Period_time_t since_last_period;
+ Rate_monotonic_Statistics *stats;
+ bool valid_status;
+
+ /*
+ * Assume we are only called in states where it is appropriate
+ * to update the statistics. This should only be RATE_MONOTONIC_ACTIVE
+ * and RATE_MONOTONIC_EXPIRED.
+ */
+
+ /*
+ * Update the counts.
+ */
+ stats = &the_period->Statistics;
+ stats->count++;
+
+ if ( the_period->state == RATE_MONOTONIC_EXPIRED )
+ stats->missed_count++;
+
+ /*
+ * Grab status for time statistics.
+ */
+ valid_status =
+ _Rate_monotonic_Get_status( the_period, &since_last_period, &executed );
+ if (!valid_status)
+ return;
+
+ /*
+ * Update CPU time
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_Add_to( &stats->total_cpu_time, &executed );
+
+ if ( _Timestamp_Less_than( &executed, &stats->min_cpu_time ) )
+ stats->min_cpu_time = executed;
+
+ if ( _Timestamp_Greater_than( &executed, &stats->max_cpu_time ) )
+ stats->max_cpu_time = executed;
+ #else
+ stats->total_cpu_time += executed;
+
+ if ( executed < stats->min_cpu_time )
+ stats->min_cpu_time = executed;
+
+ if ( executed > stats->max_cpu_time )
+ stats->max_cpu_time = executed;
+ #endif
+
+ /*
+ * Update Wall time
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_Add_to( &stats->total_wall_time, &since_last_period );
+
+ if ( _Timestamp_Less_than( &since_last_period, &stats->min_wall_time ) )
+ stats->min_wall_time = since_last_period;
+
+ if ( _Timestamp_Greater_than( &since_last_period, &stats->max_wall_time ) )
+ stats->max_wall_time = since_last_period;
+ #else
+
+ /* Sanity check wall time */
+ if ( since_last_period < executed )
+ since_last_period = executed;
+
+ stats->total_wall_time += since_last_period;
+
+ if ( since_last_period < stats->min_wall_time )
+ stats->min_wall_time = since_last_period;
+
+ if ( since_last_period > stats->max_wall_time )
+ stats->max_wall_time = since_last_period;
+ #endif
+}
+
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_period
+ *
+ * This directive allows a thread to manipulate a rate monotonic timer.
+ *
+ * Input parameters:
+ * id - rate monotonic id
+ * length - length of period (in ticks)
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_rate_monotonic_period(
+ rtems_id id,
+ rtems_interval length
+)
+{
+ Rate_monotonic_Control *the_period;
+ Objects_Locations location;
+ rtems_status_code return_value;
+ rtems_rate_monotonic_period_states local_state;
+ ISR_Level level;
+
+ the_period = _Rate_monotonic_Get( id, &location );
+
+ switch ( location ) {
+ case OBJECTS_LOCAL:
+ if ( !_Thread_Is_executing( the_period->owner ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_NOT_OWNER_OF_RESOURCE;
+ }
+
+ if ( length == RTEMS_PERIOD_STATUS ) {
+ switch ( the_period->state ) {
+ case RATE_MONOTONIC_INACTIVE:
+ return_value = RTEMS_NOT_DEFINED;
+ break;
+ case RATE_MONOTONIC_EXPIRED:
+ case RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING:
+ return_value = RTEMS_TIMEOUT;
+ break;
+ case RATE_MONOTONIC_ACTIVE:
+ default: /* unreached -- only to remove warnings */
+ return_value = RTEMS_SUCCESSFUL;
+ break;
+ }
+ _Thread_Enable_dispatch();
+ return( return_value );
+ }
+
+ _ISR_Disable( level );
+ if ( the_period->state == RATE_MONOTONIC_INACTIVE ) {
+ _ISR_Enable( level );
+
+ /*
+ * Baseline statistics information for the beginning of a period.
+ */
+ _Rate_monotonic_Initiate_statistics( the_period );
+
+ the_period->state = RATE_MONOTONIC_ACTIVE;
+ _Watchdog_Initialize(
+ &the_period->Timer,
+ _Rate_monotonic_Timeout,
+ id,
+ NULL
+ );
+
+ the_period->next_length = length;
+
+ _Watchdog_Insert_ticks( &the_period->Timer, length );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+
+ if ( the_period->state == RATE_MONOTONIC_ACTIVE ) {
+ /*
+ * Update statistics from the concluding period.
+ */
+ _Rate_monotonic_Update_statistics( the_period );
+
+ /*
+ * This tells the _Rate_monotonic_Timeout that this task is
+ * in the process of blocking on the period and that we
+ * may be changing the length of the next period.
+ */
+ the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING;
+ the_period->next_length = length;
+
+ _ISR_Enable( level );
+
+ _Thread_Executing->Wait.id = the_period->Object.id;
+ _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
+
+ /*
+ * Did the watchdog timer expire while we were actually blocking
+ * on it?
+ */
+ _ISR_Disable( level );
+ local_state = the_period->state;
+ the_period->state = RATE_MONOTONIC_ACTIVE;
+ _ISR_Enable( level );
+
+ /*
+ * If it did, then we want to unblock ourself and continue as
+ * if nothing happen. The period was reset in the timeout routine.
+ */
+ if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING )
+ _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+
+ if ( the_period->state == RATE_MONOTONIC_EXPIRED ) {
+ /*
+ * Update statistics from the concluding period
+ */
+ _Rate_monotonic_Update_statistics( the_period );
+
+ _ISR_Enable( level );
+
+ the_period->state = RATE_MONOTONIC_ACTIVE;
+ the_period->next_length = length;
+
+ _Watchdog_Insert_ticks( &the_period->Timer, length );
+ _Thread_Enable_dispatch();
+ return RTEMS_TIMEOUT;
+ }
+
+ /*
+ * These should never happen so just return invalid Id.
+ * - RATE_MONOTONIC_OWNER_IS_BLOCKING:
+ * - RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING:
+ */
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemonreportstatistics.c b/cpukit/rtems/src/ratemonreportstatistics.c
new file mode 100644
index 0000000000..fe65151d04
--- /dev/null
+++ b/cpukit/rtems/src/ratemonreportstatistics.c
@@ -0,0 +1,209 @@
+/*
+ * Rate Monotonic Manager -- Report Statistics for All Periods
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include <rtems/bspIo.h>
+#include <rtems/score/timespec.h>
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ /* We print to 1/10's of milliseconds */
+ #define NANOSECONDS_DIVIDER 1000
+ #define PERCENT_FMT "%04" PRId32
+ #define NANOSECONDS_FMT "%06" PRId32
+#endif
+
+/*
+ * This directive allows a thread to print the statistics information
+ * on ALL period instances which have non-zero counts using printk.
+ *
+ * The implementation of this directive straddles the fence between
+ * inside and outside of RTEMS. It is presented as part of the Manager
+ * but actually uses other services of the Manager.
+ */
+void rtems_rate_monotonic_report_statistics_with_plugin(
+ void *context,
+ rtems_printk_plugin_t print
+)
+{
+ rtems_status_code status;
+ rtems_id id;
+ rtems_rate_monotonic_period_statistics the_stats;
+ rtems_rate_monotonic_period_status the_status;
+ char name[5];
+
+ if ( !print )
+ return;
+
+ (*print)( context, "Period information by period\n" );
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ (*print)( context, "--- CPU times are in seconds ---\n" );
+ (*print)( context, "--- Wall times are in seconds ---\n" );
+ #endif
+/*
+Layout by columns -- in memory of Hollerith :)
+
+1234567890123456789012345678901234567890123456789012345678901234567890123456789\
+ ID OWNER COUNT MISSED X
+ididididid NNNN ccccc mmmmmm X
+
+ Uncomment the following if you are tinkering with the formatting.
+ Be sure to test the various cases.
+ (*print)( context,"\
+1234567890123456789012345678901234567890123456789012345678901234567890123456789\
+\n");
+*/
+ (*print)( context, " ID OWNER COUNT MISSED "
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ " "
+ #endif
+ "CPU TIME "
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ " "
+ #endif
+ " WALL TIME\n"
+ );
+ (*print)( context, " "
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ " "
+ #endif
+ "MIN/MAX/AVG "
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ " "
+ #endif
+ " MIN/MAX/AVG\n"
+ );
+
+ /*
+ * Cycle through all possible ids and try to report on each one. If it
+ * is a period that is inactive, we just get an error back. No big deal.
+ */
+ for ( id=_Rate_monotonic_Information.minimum_id ;
+ id <= _Rate_monotonic_Information.maximum_id ;
+ id++ ) {
+ status = rtems_rate_monotonic_get_statistics( id, &the_stats );
+ if ( status != RTEMS_SUCCESSFUL )
+ continue;
+
+ /* If the above passed, so should this but check it anyway */
+ #if defined(RTEMS_DEBUG)
+ status = rtems_rate_monotonic_get_status( id, &the_status );
+ if ( status != RTEMS_SUCCESSFUL )
+ continue;
+ #else
+ (void) rtems_rate_monotonic_get_status( id, &the_status );
+ #endif
+
+ rtems_object_get_name( the_status.owner, sizeof(name), name );
+
+ /*
+ * Print part of report line that is not dependent on granularity
+ */
+ (*print)( context,
+ "0x%08" PRIx32 " %4s %5" PRId32 " %6" PRId32 " ",
+ id, name,
+ the_stats.count, the_stats.missed_count
+ );
+
+ /*
+ * If the count is zero, don't print statistics
+ */
+ if (the_stats.count == 0) {
+ (*print)( context, "\n" );
+ continue;
+ }
+
+ /*
+ * print CPU Usage part of statistics
+ */
+ {
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ struct timespec cpu_average;
+ struct timespec *min_cpu = &the_stats.min_cpu_time;
+ struct timespec *max_cpu = &the_stats.max_cpu_time;
+ struct timespec *total_cpu = &the_stats.total_cpu_time;
+
+ _Timespec_Divide_by_integer( total_cpu, the_stats.count, &cpu_average );
+ (*print)( context,
+ "%" PRId32 "." NANOSECONDS_FMT "/" /* min cpu time */
+ "%" PRId32 "." NANOSECONDS_FMT "/" /* max cpu time */
+ "%" PRId32 "." NANOSECONDS_FMT " ", /* avg cpu time */
+ _Timespec_Get_seconds( min_cpu ),
+ _Timespec_Get_nanoseconds( min_cpu ) / NANOSECONDS_DIVIDER,
+ _Timespec_Get_seconds( max_cpu ),
+ _Timespec_Get_nanoseconds( max_cpu ) / NANOSECONDS_DIVIDER,
+ _Timespec_Get_seconds( &cpu_average ),
+ _Timespec_Get_nanoseconds( &cpu_average ) / NANOSECONDS_DIVIDER
+ );
+ #else
+ uint32_t ival_cpu, fval_cpu;
+
+ ival_cpu = the_stats.total_cpu_time * 100 / the_stats.count;
+ fval_cpu = ival_cpu % 100;
+ ival_cpu /= 100;
+
+ (*print)( context,
+ "%3" PRId32 "/%4" PRId32 "/%3" PRId32 ".%02" PRId32 " ",
+ the_stats.min_cpu_time, the_stats.max_cpu_time, ival_cpu, fval_cpu
+ );
+ #endif
+ }
+
+ /*
+ * print wall time part of statistics
+ */
+ {
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ struct timespec wall_average;
+ struct timespec *min_wall = &the_stats.min_wall_time;
+ struct timespec *max_wall = &the_stats.max_wall_time;
+ struct timespec *total_wall = &the_stats.total_wall_time;
+
+ _Timespec_Divide_by_integer(total_wall, the_stats.count, &wall_average);
+ (*print)( context,
+ "%" PRId32 "." NANOSECONDS_FMT "/" /* min wall time */
+ "%" PRId32 "." NANOSECONDS_FMT "/" /* max wall time */
+ "%" PRId32 "." NANOSECONDS_FMT "\n", /* avg wall time */
+ _Timespec_Get_seconds( min_wall ),
+ _Timespec_Get_nanoseconds( min_wall ) / NANOSECONDS_DIVIDER,
+ _Timespec_Get_seconds( max_wall ),
+ _Timespec_Get_nanoseconds( max_wall ) / NANOSECONDS_DIVIDER,
+ _Timespec_Get_seconds( &wall_average ),
+ _Timespec_Get_nanoseconds( &wall_average ) / NANOSECONDS_DIVIDER
+ );
+ #else
+ uint32_t ival_wall, fval_wall;
+
+ ival_wall = the_stats.total_wall_time * 100 / the_stats.count;
+ fval_wall = ival_wall % 100;
+ ival_wall /= 100;
+ (*print)( context,
+ "%3" PRId32 "/%4" PRId32 "/%3" PRId32 ".%02" PRId32 "\n",
+ the_stats.min_wall_time, the_stats.max_wall_time, ival_wall, fval_wall
+ );
+ #endif
+ }
+ }
+}
+
+void rtems_rate_monotonic_report_statistics( void )
+{
+ rtems_rate_monotonic_report_statistics_with_plugin( NULL, printk_plugin );
+}
diff --git a/cpukit/rtems/src/ratemonresetall.c b/cpukit/rtems/src/ratemonresetall.c
new file mode 100644
index 0000000000..39a2ec91e7
--- /dev/null
+++ b/cpukit/rtems/src/ratemonresetall.c
@@ -0,0 +1,55 @@
+/*
+ * Rate Monotonic Manager -- Reset Statistics for All Periods
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*
+ * rtems_rate_monotonic_reset_all_statistics
+ */
+void rtems_rate_monotonic_reset_all_statistics( void )
+{
+ Objects_Id id;
+
+ /*
+ * Prevent allocation or deallocation of any of the periods while
+ * we are cycling. Also this is an optimization which ensures that
+ * we only disable/enable once. The call to
+ * rtems_rate_monotonic_reset_statistics will be in a nested dispatch
+ * disabled critical section.
+ */
+ _Thread_Disable_dispatch();
+
+ /*
+ * Cycle through all possible ids and try to reset each one. If it
+ * is a period that is inactive, we just get an error back. No big deal.
+ */
+ for ( id=_Rate_monotonic_Information.minimum_id ;
+ id <= _Rate_monotonic_Information.maximum_id ;
+ id++ ) {
+ (void) rtems_rate_monotonic_reset_statistics( id );
+ }
+
+ /*
+ * Done so exit thread dispatching disabled critical section.
+ */
+ _Thread_Enable_dispatch();
+}
diff --git a/cpukit/rtems/src/ratemonresetstatistics.c b/cpukit/rtems/src/ratemonresetstatistics.c
new file mode 100644
index 0000000000..065c31aec2
--- /dev/null
+++ b/cpukit/rtems/src/ratemonresetstatistics.c
@@ -0,0 +1,65 @@
+/*
+ * Rate Monotonic Manager -- Reset Statistics
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_rate_monotonic_reset_statistics
+ *
+ * This directive allows a thread to reset the statistics information
+ * on a specific period instance.
+ *
+ * Input parameters:
+ * id - rate monotonic id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ *
+ */
+
+rtems_status_code rtems_rate_monotonic_reset_statistics(
+ rtems_id id
+)
+{
+ Objects_Locations location;
+ Rate_monotonic_Control *the_period;
+
+ the_period = _Rate_monotonic_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Rate_monotonic_Reset_statistics( the_period );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/ratemontimeout.c b/cpukit/rtems/src/ratemontimeout.c
new file mode 100644
index 0000000000..de1674636c
--- /dev/null
+++ b/cpukit/rtems/src/ratemontimeout.c
@@ -0,0 +1,83 @@
+/*
+ * Rate Monotonic Manager -- Period End Timeout Handler
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * _Rate_monotonic_Timeout
+ *
+ * This routine processes a period ending. If the owning thread
+ * is waiting for the period, that thread is unblocked and the
+ * period reinitiated. Otherwise, the period is expired.
+ * This routine is called by the watchdog handler.
+ *
+ * Input parameters:
+ * id - period id
+ *
+ * Output parameters: NONE
+ */
+
+void _Rate_monotonic_Timeout(
+ Objects_Id id,
+ void *ignored
+)
+{
+ Rate_monotonic_Control *the_period;
+ Objects_Locations location;
+ Thread_Control *the_thread;
+
+ /*
+ * When we get here, the Timer is already off the chain so we do not
+ * have to worry about that -- hence no _Watchdog_Remove().
+ */
+ the_period = _Rate_monotonic_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_thread = the_period->owner;
+ if ( _States_Is_waiting_for_period( the_thread->current_state ) &&
+ the_thread->Wait.id == the_period->Object.id ) {
+ _Thread_Unblock( the_thread );
+
+ _Rate_monotonic_Initiate_statistics( the_period );
+
+ _Watchdog_Insert_ticks( &the_period->Timer, the_period->next_length );
+ } else if ( the_period->state == RATE_MONOTONIC_OWNER_IS_BLOCKING ) {
+ the_period->state = RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING;
+
+ _Rate_monotonic_Initiate_statistics( the_period );
+
+ _Watchdog_Insert_ticks( &the_period->Timer, the_period->next_length );
+ } else
+ the_period->state = RATE_MONOTONIC_EXPIRED;
+ _Thread_Unnest_dispatch();
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* impossible */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+}
diff --git a/cpukit/rtems/src/region.c b/cpukit/rtems/src/region.c
new file mode 100644
index 0000000000..1b06ee60b5
--- /dev/null
+++ b/cpukit/rtems/src/region.c
@@ -0,0 +1,70 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * _Region_Manager_initialization
+ *
+ * This routine initializes all region manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Region_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Region_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_REGIONS, /* object class */
+ Configuration_RTEMS_API.maximum_regions,
+ /* maximum objects of this class */
+ sizeof( Region_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor(
+ MP_PACKET_REGION,
+ 0 /* XXX _Region_MP_Process_packet */
+ );
+#endif
+
+}
diff --git a/cpukit/rtems/src/regioncreate.c b/cpukit/rtems/src/regioncreate.c
new file mode 100644
index 0000000000..90aca79ea7
--- /dev/null
+++ b/cpukit/rtems/src/regioncreate.c
@@ -0,0 +1,118 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_create
+ *
+ * This directive creates a region of physical contiguous memory area
+ * from which variable sized segments can be allocated.
+ *
+ * Input parameters:
+ * name - user defined region name
+ * starting_address - physical start address of region
+ * length - physical length in bytes
+ * page_size - page size in bytes
+ * attribute_set - region attributes
+ * id - address of region id to set
+ *
+ * Output parameters:
+ * id - region id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_create(
+ rtems_name name,
+ void *starting_address,
+ uintptr_t length,
+ uintptr_t page_size,
+ rtems_attribute attribute_set,
+ rtems_id *id
+)
+{
+ rtems_status_code return_status;
+ Region_Control *the_region;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !starting_address )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ _RTEMS_Lock_allocator(); /* to prevent deletion */
+
+ the_region = _Region_Allocate();
+
+ if ( !the_region )
+ return_status = RTEMS_TOO_MANY;
+
+ else {
+
+ the_region->maximum_segment_size = _Heap_Initialize(
+ &the_region->Memory, starting_address, length, page_size
+ );
+
+ if ( !the_region->maximum_segment_size ) {
+ _Region_Free( the_region );
+ return_status = RTEMS_INVALID_SIZE;
+ }
+
+ else {
+
+ the_region->starting_address = starting_address;
+ the_region->length = length;
+ the_region->page_size = page_size;
+ the_region->attribute_set = attribute_set;
+ the_region->number_of_used_blocks = 0;
+
+ _Thread_queue_Initialize(
+ &the_region->Wait_queue,
+ _Attributes_Is_priority( attribute_set ) ?
+ THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_SEGMENT,
+ RTEMS_TIMEOUT
+ );
+
+ _Objects_Open(
+ &_Region_Information,
+ &the_region->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_region->Object.id;
+ return_status = RTEMS_SUCCESSFUL;
+ }
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regiondata.c b/cpukit/rtems/src/regiondata.c
new file mode 100644
index 0000000000..9ecce9e7bb
--- /dev/null
+++ b/cpukit/rtems/src/regiondata.c
@@ -0,0 +1,22 @@
+/*
+ * Region Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS Region data */
+#define RTEMS_REGION_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/region.h>
diff --git a/cpukit/rtems/src/regiondelete.c b/cpukit/rtems/src/regiondelete.c
new file mode 100644
index 0000000000..8217e68f71
--- /dev/null
+++ b/cpukit/rtems/src/regiondelete.c
@@ -0,0 +1,82 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_delete
+ *
+ * This directive allows a thread to delete a region specified by
+ * the region identifier, provided that none of its segments are
+ * still allocated.
+ *
+ * Input parameters:
+ * id - region id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_delete(
+ rtems_id id
+)
+{
+ Objects_Locations location;
+ rtems_status_code return_status;
+ Region_Control *the_region;
+
+ _RTEMS_Lock_allocator();
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Region_Debug_Walk( the_region, 5 );
+ if ( the_region->number_of_used_blocks != 0 )
+ return_status = RTEMS_RESOURCE_IN_USE;
+ else {
+ _Objects_Close( &_Region_Information, &the_region->Object );
+ _Region_Free( the_region );
+ return_status = RTEMS_SUCCESSFUL;
+ }
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regionextend.c b/cpukit/rtems/src/regionextend.c
new file mode 100644
index 0000000000..f4b6c93c2d
--- /dev/null
+++ b/cpukit/rtems/src/regionextend.c
@@ -0,0 +1,96 @@
+/*
+ * Region Manager - Extend (add memory to) a Region
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_extend
+ *
+ * This directive attempts to grow a region of physical contiguous memory area
+ * from which variable sized segments can be allocated.
+ *
+ * Input parameters:
+ * id - id of region to grow
+ * start - starting address of memory area for extension
+ * length - physical length in bytes to grow the region
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_extend(
+ rtems_id id,
+ void *starting_address,
+ uintptr_t length
+)
+{
+ uintptr_t amount_extended;
+ bool extend_ok;
+ Objects_Locations location;
+ rtems_status_code return_status;
+ Region_Control *the_region;
+
+ if ( !starting_address )
+ return RTEMS_INVALID_ADDRESS;
+
+ _RTEMS_Lock_allocator(); /* to prevent deletion */
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ extend_ok = _Heap_Extend(
+ &the_region->Memory,
+ starting_address,
+ length,
+ &amount_extended
+ );
+
+ if ( extend_ok ) {
+ the_region->length += amount_extended;
+ the_region->maximum_segment_size += amount_extended;
+ return_status = RTEMS_SUCCESSFUL;
+ } else {
+ return_status = RTEMS_INVALID_ADDRESS;
+ }
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regiongetfreeinfo.c b/cpukit/rtems/src/regiongetfreeinfo.c
new file mode 100644
index 0000000000..fcfa3bc8b2
--- /dev/null
+++ b/cpukit/rtems/src/regiongetfreeinfo.c
@@ -0,0 +1,88 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/apimutex.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_region_get_free_information
+ *
+ * This directive will return information about the free blocks
+ * in the region specified. Information about the used blocks
+ * will be returned as zero.
+ *
+ * Input parameters:
+ * id - region id
+ * the_info - pointer to region information block
+ *
+ * Output parameters:
+ * *the_info - region information block filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_get_free_information(
+ rtems_id id,
+ Heap_Information_block *the_info
+)
+{
+ Objects_Locations location;
+ rtems_status_code return_status;
+ register Region_Control *the_region;
+
+ if ( !the_info )
+ return RTEMS_INVALID_ADDRESS;
+
+ _RTEMS_Lock_allocator();
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ the_info->Used.number = 0;
+ the_info->Used.total = 0;
+ the_info->Used.largest = 0;
+
+ _Heap_Get_free_information( &the_region->Memory, &the_info->Free );
+
+ return_status = RTEMS_SUCCESSFUL;
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regiongetinfo.c b/cpukit/rtems/src/regiongetinfo.c
new file mode 100644
index 0000000000..306f3da947
--- /dev/null
+++ b/cpukit/rtems/src/regiongetinfo.c
@@ -0,0 +1,80 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/apimutex.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * rtems_region_get_information
+ *
+ * This directive will return information about the region specified.
+ *
+ * Input parameters:
+ * id - region id
+ * the_info - pointer to region information block
+ *
+ * Output parameters:
+ * *the_info - region information block filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_get_information(
+ rtems_id id,
+ Heap_Information_block *the_info
+)
+{
+ Objects_Locations location;
+ rtems_status_code return_status;
+ register Region_Control *the_region;
+
+ if ( !the_info )
+ return RTEMS_INVALID_ADDRESS;
+
+ _RTEMS_Lock_allocator();
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Heap_Get_information( &the_region->Memory, the_info );
+ return_status = RTEMS_SUCCESSFUL;
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regiongetsegment.c b/cpukit/rtems/src/regiongetsegment.c
new file mode 100644
index 0000000000..c8c8cfa0fb
--- /dev/null
+++ b/cpukit/rtems/src/regiongetsegment.c
@@ -0,0 +1,131 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_get_segment
+ *
+ * This directive will obtain a segment from the given region.
+ *
+ * Input parameters:
+ * id - region id
+ * size - segment size in bytes
+ * option_set - wait option
+ * timeout - number of ticks to wait (0 means wait forever)
+ * segment - pointer to segment address
+ *
+ * Output parameters:
+ * segment - pointer to segment address filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_get_segment(
+ rtems_id id,
+ uintptr_t size,
+ rtems_option option_set,
+ rtems_interval timeout,
+ void **segment
+)
+{
+ Thread_Control *executing;
+ Objects_Locations location;
+ rtems_status_code return_status;
+ Region_Control *the_region;
+ void *the_segment;
+
+ if ( !segment )
+ return RTEMS_INVALID_ADDRESS;
+
+ *segment = NULL;
+
+ if ( size == 0 )
+ return RTEMS_INVALID_SIZE;
+
+ _RTEMS_Lock_allocator();
+
+ executing = _Thread_Executing;
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( size > the_region->maximum_segment_size )
+ return_status = RTEMS_INVALID_SIZE;
+
+ else {
+ _Region_Debug_Walk( the_region, 1 );
+
+ the_segment = _Region_Allocate_segment( the_region, size );
+
+ _Region_Debug_Walk( the_region, 2 );
+
+ if ( the_segment ) {
+ the_region->number_of_used_blocks += 1;
+ *segment = the_segment;
+ return_status = RTEMS_SUCCESSFUL;
+ } else if ( _Options_Is_no_wait( option_set ) ) {
+ return_status = RTEMS_UNSATISFIED;
+ } else {
+ /*
+ * Switch from using the memory allocation mutex to using a
+ * dispatching disabled critical section. We have to do this
+ * because this thread is going to block.
+ */
+ _Thread_Disable_dispatch();
+ _RTEMS_Unlock_allocator();
+
+ executing->Wait.queue = &the_region->Wait_queue;
+ executing->Wait.id = id;
+ executing->Wait.count = size;
+ executing->Wait.return_argument = segment;
+
+ _Thread_queue_Enter_critical_section( &the_region->Wait_queue );
+
+ _Thread_queue_Enqueue( &the_region->Wait_queue, timeout );
+
+ _Thread_Enable_dispatch();
+
+ return (rtems_status_code) executing->Wait.return_code;
+ }
+ }
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regiongetsegmentsize.c b/cpukit/rtems/src/regiongetsegmentsize.c
new file mode 100644
index 0000000000..601145128a
--- /dev/null
+++ b/cpukit/rtems/src/regiongetsegmentsize.c
@@ -0,0 +1,83 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_get_segment_size
+ *
+ * This directive will return the size of the segment indicated
+ *
+ * Input parameters:
+ * id - region id
+ * segment - segment address
+ * size - pointer to segment size in bytes
+ *
+ * Output parameters:
+ * size - segment size in bytes filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_get_segment_size(
+ rtems_id id,
+ void *segment,
+ uintptr_t *size
+)
+{
+ Objects_Locations location;
+ rtems_status_code return_status = RTEMS_SUCCESSFUL;
+ register Region_Control *the_region;
+
+ if ( !segment )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !size )
+ return RTEMS_INVALID_ADDRESS;
+
+ _RTEMS_Lock_allocator();
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Heap_Size_of_alloc_area( &the_region->Memory, segment, size ) )
+ return_status = RTEMS_INVALID_ADDRESS;
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regionident.c b/cpukit/rtems/src/regionident.c
new file mode 100644
index 0000000000..55df94d48c
--- /dev/null
+++ b/cpukit/rtems/src/regionident.c
@@ -0,0 +1,61 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_ident
+ *
+ * This directive returns the system ID associated with
+ * the region name.
+ *
+ * Input parameters:
+ * name - user defined region name
+ * id - pointer to region id
+ *
+ * Output parameters:
+ * *id - region id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_ident(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Region_Information,
+ name,
+ OBJECTS_SEARCH_LOCAL_NODE,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/regionmp.c b/cpukit/rtems/src/regionmp.c
new file mode 100644
index 0000000000..a978c2d288
--- /dev/null
+++ b/cpukit/rtems/src/regionmp.c
@@ -0,0 +1,315 @@
+/*
+ * Multiprocessing Support for the Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Region_MP_Send_process_packet
+ *
+ */
+
+void _Region_MP_Send_process_packet (
+ Region_MP_Remote_operations operation,
+ Objects_Id region_id,
+ rtems_name name,
+ Objects_Id proxy_id
+)
+{
+ Region_MP_Packet *the_packet;
+ uint32_t node;
+
+ switch ( operation ) {
+
+ case REGION_MP_ANNOUNCE_CREATE:
+ case REGION_MP_ANNOUNCE_DELETE:
+ case REGION_MP_EXTRACT_PROXY:
+
+ the_packet = _Region_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_REGION;
+ the_packet->Prefix.length = sizeof ( Region_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Region_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = region_id;
+ the_packet->name = name;
+ the_packet->proxy_id = proxy_id;
+
+ if ( operation == REGION_MP_EXTRACT_PROXY )
+ node = _Objects_Get_node( region_id );
+ else
+ node = MPCI_ALL_NODES;
+
+ _MPCI_Send_process_packet( node, &the_packet->Prefix );
+ break;
+
+ case REGION_MP_GET_SEGMENT_REQUEST:
+ case REGION_MP_GET_SEGMENT_RESPONSE:
+ case REGION_MP_RETURN_SEGMENT_REQUEST:
+ case REGION_MP_RETURN_SEGMENT_RESPONSE:
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _Region_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _Region_MP_Send_request_packet (
+ Region_MP_Remote_operations operation,
+ Objects_Id region_id,
+ void *segment,
+ intptr_t size,
+ rtems_option option_set,
+ rtems_interval timeout
+)
+{
+ Region_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case REGION_MP_GET_SEGMENT_REQUEST:
+ case REGION_MP_RETURN_SEGMENT_REQUEST:
+
+ the_packet = _Region_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_REGION;
+ the_packet->Prefix.length = sizeof ( Region_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Region_MP_Packet );
+ if ( ! _Options_Is_no_wait(option_set))
+ the_packet->Prefix.timeout = timeout;
+
+ the_packet->operation = operation;
+ the_packet->Prefix.id = region_id;
+ the_packet->segment = segment;
+ the_packet->size = size;
+ the_packet->option_set = option_set;
+
+ return (rtems_status_code) _MPCI_Send_request_packet(
+ _Objects_Get_node( region_id ),
+ &the_packet->Prefix,
+ STATES_READY /* Not used */
+ );
+ break;
+
+ case REGION_MP_ANNOUNCE_CREATE:
+ case REGION_MP_ANNOUNCE_DELETE:
+ case REGION_MP_EXTRACT_PROXY:
+ case REGION_MP_GET_SEGMENT_RESPONSE:
+ case REGION_MP_RETURN_SEGMENT_RESPONSE:
+ break;
+
+ }
+ /*
+ * The following line is included to satisfy compilers which
+ * produce warnings when a function does not end with a return.
+ */
+ return RTEMS_INTERNAL_ERROR;
+}
+
+/*PAGE
+ *
+ * _Region_MP_Send_response_packet
+ *
+ */
+
+void _Region_MP_Send_response_packet (
+ Region_MP_Remote_operations operation,
+ Objects_Id region_id,
+ Thread_Control *the_thread
+)
+{
+ Region_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case REGION_MP_GET_SEGMENT_RESPONSE:
+ case REGION_MP_RETURN_SEGMENT_RESPONSE:
+
+ the_packet = ( Region_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case REGION_MP_ANNOUNCE_CREATE:
+ case REGION_MP_ANNOUNCE_DELETE:
+ case REGION_MP_EXTRACT_PROXY:
+ case REGION_MP_GET_SEGMENT_REQUEST:
+ case REGION_MP_RETURN_SEGMENT_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _Region_MP_Process_packet
+ *
+ */
+
+void _Region_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ Region_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+ bool ignored;
+
+ the_packet = (Region_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case REGION_MP_ANNOUNCE_CREATE:
+
+ ignored = _Objects_MP_Allocate_and_open(
+ &_Region_Information,
+ the_packet->name,
+ the_packet->Prefix.id,
+ true
+ );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case REGION_MP_ANNOUNCE_DELETE:
+
+ _Objects_MP_Close( &_Region_Information, the_packet->Prefix.id );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case REGION_MP_EXTRACT_PROXY:
+
+ the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
+
+ if ( ! _Thread_Is_null( the_thread ) )
+ _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case REGION_MP_GET_SEGMENT_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_region_get_segment(
+ the_packet->Prefix.id,
+ the_packet->size,
+ the_packet->option_set,
+ the_packet->Prefix.timeout,
+ &the_packet->segment
+ );
+
+ _Region_MP_Send_response_packet(
+ REGION_MP_GET_SEGMENT_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case REGION_MP_GET_SEGMENT_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ *(void **)the_thread->Wait.return_argument = the_packet->segment;
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case REGION_MP_RETURN_SEGMENT_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_region_return_segment(
+ the_packet->Prefix.id,
+ the_packet->segment
+ );
+
+ _Region_MP_Send_response_packet(
+ REGION_MP_RETURN_SEGMENT_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case REGION_MP_RETURN_SEGMENT_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ * _Region_MP_Send_object_was_deleted
+ *
+ * This routine is not needed by the Region since a region
+ * cannot be deleted when segments are in use.
+ *
+ */
+
+/*PAGE
+ *
+ * _Region_MP_Send_extract_proxy
+ *
+ */
+
+void _Region_MP_Send_extract_proxy (
+ void *argument
+)
+{
+ Thread_Control *the_thread = (Thread_Control *)argument;
+
+ _Region_MP_Send_process_packet(
+ REGION_MP_EXTRACT_PROXY,
+ the_thread->Wait.id,
+ (rtems_name) 0,
+ the_thread->Object.id
+ );
+}
+
+/*PAGE
+ *
+ * _Region_MP_Get_packet
+ *
+ */
+
+Region_MP_Packet *_Region_MP_Get_packet ( void )
+{
+ return ( (Region_MP_Packet *) _MPCI_Get_packet() );
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/regionprocessqueue.c b/cpukit/rtems/src/regionprocessqueue.c
new file mode 100644
index 0000000000..011e646a6c
--- /dev/null
+++ b/cpukit/rtems/src/regionprocessqueue.c
@@ -0,0 +1,87 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * _Region_Process_queue
+ *
+ * If enough memory is available to satisfy the rtems_region_get_segment of
+ * the first blocked task, then that task and as many subsequent tasks as
+ * possible will be unblocked with their requests satisfied.
+ *
+ * Input parameters:
+ * the_region - the region
+ *
+ * Output parameters:
+ * none
+ */
+
+void _Region_Process_queue(
+ Region_Control *the_region
+)
+{
+ Thread_Control *the_thread;
+ void *the_segment;
+ /*
+ * Switch from using the memory allocation mutex to using a
+ * dispatching disabled critical section. We have to do this
+ * because this thread may unblock one or more threads that were
+ * waiting on memory.
+ *
+ * NOTE: Be sure to disable dispatching before unlocking the mutex
+ * since we do not want to open a window where a context
+ * switch could occur.
+ */
+ _Thread_Disable_dispatch();
+ _RTEMS_Unlock_allocator();
+
+ /*
+ * NOTE: The following loop is O(n) where n is the number of
+ * threads whose memory request is satisfied.
+ */
+ for ( ; ; ) {
+ the_thread = _Thread_queue_First( &the_region->Wait_queue );
+
+ if ( the_thread == NULL )
+ break;
+
+ the_segment = (void **) _Region_Allocate_segment(
+ the_region,
+ the_thread->Wait.count
+ );
+
+ if ( the_segment == NULL )
+ break;
+
+ *(void **)the_thread->Wait.return_argument = the_segment;
+ the_region->number_of_used_blocks += 1;
+ _Thread_queue_Extract( &the_region->Wait_queue, the_thread );
+ the_thread->Wait.return_code = RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+}
diff --git a/cpukit/rtems/src/regionresizesegment.c b/cpukit/rtems/src/regionresizesegment.c
new file mode 100644
index 0000000000..737e31436e
--- /dev/null
+++ b/cpukit/rtems/src/regionresizesegment.c
@@ -0,0 +1,109 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_resize_segment
+ *
+ * This directive will try to resize segment to the new size 'size'
+ * "in place".
+ *
+ * Input parameters:
+ * id - region id
+ * segment - pointer to segment address
+ * size - new required size
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_resize_segment(
+ rtems_id id,
+ void *segment,
+ uintptr_t size,
+ uintptr_t *old_size
+)
+{
+ uintptr_t avail_size;
+ Objects_Locations location;
+ uintptr_t osize;
+ rtems_status_code return_status;
+ Heap_Resize_status status;
+ register Region_Control *the_region;
+
+ if ( !old_size )
+ return RTEMS_INVALID_ADDRESS;
+
+ _RTEMS_Lock_allocator();
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _Region_Debug_Walk( the_region, 7 );
+
+ status = _Heap_Resize_block(
+ &the_region->Memory,
+ segment,
+ (uint32_t) size,
+ &osize,
+ &avail_size
+ );
+ *old_size = (uint32_t) osize;
+
+ _Region_Debug_Walk( the_region, 8 );
+
+ if ( status == HEAP_RESIZE_SUCCESSFUL )
+ _Region_Process_queue( the_region ); /* unlocks allocator */
+ else
+ _RTEMS_Unlock_allocator();
+
+
+ if (status == HEAP_RESIZE_SUCCESSFUL)
+ return RTEMS_SUCCESSFUL;
+ if (status == HEAP_RESIZE_UNSATISFIED)
+ return RTEMS_UNSATISFIED;
+ return RTEMS_INVALID_ADDRESS;
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/regionreturnsegment.c b/cpukit/rtems/src/regionreturnsegment.c
new file mode 100644
index 0000000000..b98ff1d486
--- /dev/null
+++ b/cpukit/rtems/src/regionreturnsegment.c
@@ -0,0 +1,111 @@
+/*
+ * Region Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef RTEMS_REGION_SHRED_ON_FREE
+#include <string.h>
+
+#ifndef RTEMS_REGION_FREE_SHRED_PATTERN
+#define RTEMS_REGION_FREE_SHRED_PATTERN 0x00
+#endif
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/region.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_region_return_segment
+ *
+ * This directive will return a segment to its region.
+ *
+ * Input parameters:
+ * id - region id
+ * segment - pointer to segment address
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_region_return_segment(
+ rtems_id id,
+ void *segment
+)
+{
+ Objects_Locations location;
+ rtems_status_code return_status;
+#ifdef RTEMS_REGION_FREE_SHRED_PATTERN
+ uint32_t size;
+#endif
+ int status;
+ register Region_Control *the_region;
+
+ _RTEMS_Lock_allocator();
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ _Region_Debug_Walk( the_region, 3 );
+
+#ifdef RTEMS_REGION_FREE_SHRED_PATTERN
+ if ( !_Heap_Size_of_alloc_area( &the_region->Memory, segment, &size ) )
+ return_status = RTEMS_INVALID_ADDRESS;
+ else {
+ memset( segment, (RTEMS_REGION_FREE_SHRED_PATTERN & 0xFF), size );
+#endif
+ status = _Region_Free_segment( the_region, segment );
+
+ _Region_Debug_Walk( the_region, 4 );
+
+ if ( !status )
+ return_status = RTEMS_INVALID_ADDRESS;
+ else {
+ the_region->number_of_used_blocks -= 1;
+
+ _Region_Process_queue(the_region); /* unlocks allocator */
+
+ return RTEMS_SUCCESSFUL;
+ }
+#ifdef RTEMS_REGION_FREE_SHRED_PATTERN
+ }
+#endif
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
+
+ case OBJECTS_ERROR:
+ default:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return return_status;
+}
diff --git a/cpukit/rtems/src/rtclock.c b/cpukit/rtems/src/rtclock.c
new file mode 100644
index 0000000000..652f443677
--- /dev/null
+++ b/cpukit/rtems/src/rtclock.c
@@ -0,0 +1,26 @@
+/*
+ * Clock Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/* No initialization routine */
diff --git a/cpukit/rtems/src/rtemsbuildid.c b/cpukit/rtems/src/rtemsbuildid.c
new file mode 100644
index 0000000000..916d1dfab5
--- /dev/null
+++ b/cpukit/rtems/src/rtemsbuildid.c
@@ -0,0 +1,31 @@
+/*
+ * RTEMS Object Helper -- Build an Object Id
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_build_id
+rtems_id rtems_build_id(
+ uint32_t api,
+ uint32_t class,
+ uint32_t node,
+ uint32_t index
+)
+{
+ return _Objects_Build_id( api, class, node, index );
+}
diff --git a/cpukit/rtems/src/rtemsbuildname.c b/cpukit/rtems/src/rtemsbuildname.c
new file mode 100644
index 0000000000..1fbd727297
--- /dev/null
+++ b/cpukit/rtems/src/rtemsbuildname.c
@@ -0,0 +1,31 @@
+/*
+ * RTEMS Object Helper -- Build an Object Name
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_build_name
+rtems_name rtems_build_name(
+ char C1,
+ char C2,
+ char C3,
+ char C4
+)
+{
+ return _Objects_Build_name( C1, C2, C3, C4 );
+}
diff --git a/cpukit/rtems/src/rtemsobjectapimaximumclass.c b/cpukit/rtems/src/rtemsobjectapimaximumclass.c
new file mode 100644
index 0000000000..16133084d2
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectapimaximumclass.c
@@ -0,0 +1,27 @@
+/*
+ * RTEMS Object Helper -- Get Greatest Valid Class for an API
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+int rtems_object_api_maximum_class(
+ int api
+)
+{
+ return _Objects_API_maximum_class(api);
+}
diff --git a/cpukit/rtems/src/rtemsobjectapiminimumclass.c b/cpukit/rtems/src/rtemsobjectapiminimumclass.c
new file mode 100644
index 0000000000..a3995eb32a
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectapiminimumclass.c
@@ -0,0 +1,29 @@
+/*
+ * RTEMS Object Helper -- Get Least Valid Class for an API
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+uint32_t rtems_object_api_minimum_class(
+ uint32_t api
+)
+{
+ if ( _Objects_Is_api_valid( api ) )
+ return 1;
+ return -1;
+}
diff --git a/cpukit/rtems/src/rtemsobjectgetapiclassname.c b/cpukit/rtems/src/rtemsobjectgetapiclassname.c
new file mode 100644
index 0000000000..2ea697bc37
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectgetapiclassname.c
@@ -0,0 +1,81 @@
+/*
+ * RTEMS Object Helper -- Obtain Name of API
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/object.h>
+
+#include <rtems/assoc.h>
+
+rtems_assoc_t rtems_object_api_internal_assoc[] = {
+ { "Thread", OBJECTS_INTERNAL_THREADS, 0},
+ { "Mutex", OBJECTS_INTERNAL_MUTEXES, 0},
+};
+
+rtems_assoc_t rtems_object_api_classic_assoc[] = {
+ { "Task", OBJECTS_RTEMS_TASKS, 0},
+ { "Timer", OBJECTS_RTEMS_TIMERS, 0},
+ { "Semaphore", OBJECTS_RTEMS_SEMAPHORES, 0},
+ { "Message Queue", OBJECTS_RTEMS_MESSAGE_QUEUES, 0},
+ { "Partition", OBJECTS_RTEMS_PARTITIONS, 0},
+ { "Region", OBJECTS_RTEMS_REGIONS, 0},
+ { "Port", OBJECTS_RTEMS_PORTS, 0},
+ { "Period", OBJECTS_RTEMS_PERIODS, 0},
+ { "Extension", OBJECTS_RTEMS_EXTENSIONS, 0},
+ { "Barrier", OBJECTS_RTEMS_BARRIERS, 0},
+};
+
+#ifdef RTEMS_POSIX_API
+rtems_assoc_t rtems_object_api_posix_assoc[] = {
+ { "Thread", OBJECTS_POSIX_THREADS, 0},
+ { "Key", OBJECTS_POSIX_KEYS, 0},
+ { "Interrupt", OBJECTS_POSIX_INTERRUPTS, 0},
+ { "Queued fd", OBJECTS_POSIX_MESSAGE_QUEUE_FDS, 0},
+ { "Message Queue", OBJECTS_POSIX_MESSAGE_QUEUES, 0},
+ { "Mutex", OBJECTS_POSIX_MUTEXES, 0},
+ { "Semaphore", OBJECTS_POSIX_SEMAPHORES, 0},
+ { "Condition Variable", OBJECTS_POSIX_CONDITION_VARIABLES, 0},
+ { "Timer", OBJECTS_POSIX_TIMERS, 0},
+ { "Barrier", OBJECTS_POSIX_BARRIERS, 0},
+ { "Spinlock", OBJECTS_POSIX_SPINLOCKS, 0},
+ { "RWLock", OBJECTS_POSIX_RWLOCKS, 0},
+};
+#endif
+
+const char *rtems_object_get_api_class_name(
+ int the_api,
+ int the_class
+)
+{
+ const rtems_assoc_t *api_assoc;
+ const rtems_assoc_t *class_assoc;
+
+ if ( the_api == OBJECTS_INTERNAL_API )
+ api_assoc = rtems_object_api_internal_assoc;
+ else if ( the_api == OBJECTS_CLASSIC_API )
+ api_assoc = rtems_object_api_classic_assoc;
+#ifdef RTEMS_POSIX_API
+ else if ( the_api == OBJECTS_POSIX_API )
+ api_assoc = rtems_object_api_posix_assoc;
+#endif
+ else
+ return "BAD API";
+ class_assoc = rtems_assoc_ptr_by_local( api_assoc, the_class );
+ if ( class_assoc )
+ return class_assoc->name;
+ return "BAD CLASS";
+}
diff --git a/cpukit/rtems/src/rtemsobjectgetapiname.c b/cpukit/rtems/src/rtemsobjectgetapiname.c
new file mode 100644
index 0000000000..90a6afa198
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectgetapiname.c
@@ -0,0 +1,42 @@
+/*
+ * RTEMS Object Helper -- Obtain Name of API
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/object.h>
+
+#include <rtems/assoc.h>
+
+rtems_assoc_t rtems_objects_api_assoc[] = {
+ { "Internal", OBJECTS_INTERNAL_API, 0},
+ { "Classic", OBJECTS_CLASSIC_API, 0},
+ { "POSIX", OBJECTS_POSIX_API, 0},
+ { 0, 0, 0 }
+};
+
+const char *rtems_object_get_api_name(
+ int api
+)
+{
+ const rtems_assoc_t *api_assoc;
+
+ api_assoc = rtems_assoc_ptr_by_local( rtems_objects_api_assoc, api );
+ if ( api_assoc )
+ return api_assoc->name;
+ return "BAD CLASS";
+}
+
diff --git a/cpukit/rtems/src/rtemsobjectgetclassicname.c b/cpukit/rtems/src/rtemsobjectgetclassicname.c
new file mode 100644
index 0000000000..7a78d59e7e
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectgetclassicname.c
@@ -0,0 +1,55 @@
+/*
+ * RTEMS ID To Name Lookup
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+/*PAGE
+ *
+ * rtems_object_get_classic_name
+ *
+ * This directive returns the name associated with the specified
+ * object ID.
+ *
+ * Input parameters:
+ * id - message queue id
+ *
+ * Output parameters:
+ * *name - user defined object name
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_object_get_classic_name(
+ rtems_id id,
+ rtems_name *name
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+ Objects_Name name_u;
+
+ if ( !name )
+ return RTEMS_INVALID_ADDRESS;
+
+ status = _Objects_Id_to_name( id, &name_u );
+
+ *name = name_u.name_u32;
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/rtemsobjectgetclassinfo.c b/cpukit/rtems/src/rtemsobjectgetclassinfo.c
new file mode 100644
index 0000000000..4f20a6f61f
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectgetclassinfo.c
@@ -0,0 +1,59 @@
+/*
+ * RTEMS Object Helper -- Get Information on Class
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/object.h>
+
+rtems_status_code rtems_object_get_class_information(
+ int the_api,
+ int the_class,
+ rtems_object_api_class_information *info
+)
+{
+ Objects_Information *obj_info;
+ int unallocated;
+ int i;
+
+ /*
+ * Validate parameters and look up information structure.
+ */
+ if ( !info )
+ return RTEMS_INVALID_ADDRESS;
+
+ obj_info = _Objects_Get_information( the_api, the_class );
+ if ( !obj_info )
+ return RTEMS_INVALID_NUMBER;
+
+ /*
+ * Return information about this object class to the user.
+ */
+ info->minimum_id = obj_info->minimum_id;
+ info->maximum_id = obj_info->maximum_id;
+ info->auto_extend = obj_info->auto_extend;
+ info->maximum = obj_info->maximum;
+
+ for ( unallocated=0, i=1 ; i <= info->maximum ; i++ )
+ if ( !obj_info->local_table[i] )
+ unallocated++;
+
+ info->unallocated = unallocated;
+
+ return RTEMS_SUCCESSFUL;
+}
+
diff --git a/cpukit/rtems/src/rtemsobjectgetname.c b/cpukit/rtems/src/rtemsobjectgetname.c
new file mode 100644
index 0000000000..c414d2e478
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectgetname.c
@@ -0,0 +1,33 @@
+/*
+ * RTEMS Object Helper -- Obtain Name of Object as String
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+
+/*
+ * This method obtain the name of an object and returns its name
+ * in the form of a C string. It attempts to be careful about
+ * overflowing the user's string and about returning unprintable characters.
+ */
+char *rtems_object_get_name(
+ Objects_Id id,
+ size_t length,
+ char *name
+)
+{
+ return _Objects_Get_name_as_string( id, length, name );
+}
diff --git a/cpukit/rtems/src/rtemsobjectidapimaximum.c b/cpukit/rtems/src/rtemsobjectidapimaximum.c
new file mode 100644
index 0000000000..fbf6c19d02
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectidapimaximum.c
@@ -0,0 +1,26 @@
+/*
+ * RTEMS Object Helper -- Get Greatest Valid API Number
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_object_id_api_maximum
+int rtems_object_id_api_maximum(void)
+{
+ return OBJECTS_APIS_LAST;
+}
diff --git a/cpukit/rtems/src/rtemsobjectidapiminimum.c b/cpukit/rtems/src/rtemsobjectidapiminimum.c
new file mode 100644
index 0000000000..057fa09d70
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectidapiminimum.c
@@ -0,0 +1,26 @@
+/*
+ * RTEMS Object Helper -- Get Least Valid API Number
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_object_id_api_minimum
+int rtems_object_id_api_minimum(void)
+{
+ return OBJECTS_INTERNAL_API;
+}
diff --git a/cpukit/rtems/src/rtemsobjectidgetapi.c b/cpukit/rtems/src/rtemsobjectidgetapi.c
new file mode 100644
index 0000000000..859e4b5bc6
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectidgetapi.c
@@ -0,0 +1,28 @@
+/*
+ * RTEMS Object Helper -- Extract API From Id
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_object_id_get_api
+int rtems_object_id_get_api(
+ rtems_id id
+)
+{
+ return _Objects_Get_API( id );
+}
diff --git a/cpukit/rtems/src/rtemsobjectidgetclass.c b/cpukit/rtems/src/rtemsobjectidgetclass.c
new file mode 100644
index 0000000000..fe85050c4a
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectidgetclass.c
@@ -0,0 +1,28 @@
+/*
+ * RTEMS Object Helper -- Extract Class From Id
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_object_id_get_class
+int rtems_object_id_get_class(
+ rtems_id id
+)
+{
+ return _Objects_Get_class( id );
+}
diff --git a/cpukit/rtems/src/rtemsobjectidgetindex.c b/cpukit/rtems/src/rtemsobjectidgetindex.c
new file mode 100644
index 0000000000..67f795be8d
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectidgetindex.c
@@ -0,0 +1,28 @@
+/*
+ * RTEMS Object Helper -- Extract Index From Id
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_object_id_get_index
+int rtems_object_id_get_index(
+ rtems_id id
+)
+{
+ return _Objects_Get_index( id );
+}
diff --git a/cpukit/rtems/src/rtemsobjectidgetnode.c b/cpukit/rtems/src/rtemsobjectidgetnode.c
new file mode 100644
index 0000000000..5dfae4b1f9
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectidgetnode.c
@@ -0,0 +1,28 @@
+/*
+ * RTEMS Object Helper -- Extract Node From Id
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/types.h>
+
+#undef rtems_object_id_get_node
+int rtems_object_id_get_node(
+ rtems_id id
+)
+{
+ return _Objects_Get_node( id );
+}
diff --git a/cpukit/rtems/src/rtemsobjectsetname.c b/cpukit/rtems/src/rtemsobjectsetname.c
new file mode 100644
index 0000000000..91fac13e7c
--- /dev/null
+++ b/cpukit/rtems/src/rtemsobjectsetname.c
@@ -0,0 +1,64 @@
+/*
+ * RTEMS Object Helper -- Set Name of Object as String
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+/*
+ * This method will set the object name based upon the user string.
+ * If the object class uses 32-bit names, then only the first 4 bytes
+ * of the string will be used.
+ */
+rtems_status_code rtems_object_set_name(
+ rtems_id id,
+ const char *name
+)
+{
+ Objects_Information *information;
+ Objects_Locations location;
+ Objects_Control *the_object;
+ Objects_Id tmpId;
+
+ if ( !name )
+ return RTEMS_INVALID_ADDRESS;
+
+ tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id;
+
+ information = _Objects_Get_information_id( tmpId );
+ if ( !information )
+ return RTEMS_INVALID_ID;
+
+ the_object = _Objects_Get( information, tmpId, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Set_name( information, the_object, name );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/rtemstimer.c b/cpukit/rtems/src/rtemstimer.c
new file mode 100644
index 0000000000..3cff1f3bf7
--- /dev/null
+++ b/cpukit/rtems/src/rtemstimer.c
@@ -0,0 +1,64 @@
+/*
+ * Timer Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _Timer_Manager_initialization
+ *
+ * This routine initializes all timer manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Timer_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Timer_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_TIMERS, /* object class */
+ Configuration_RTEMS_API.maximum_timers ,
+ /* maximum objects of this class */
+ sizeof( Timer_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Initialize the pointer to the default timer server control block to NULL
+ * indicating that task-based timer support is not initialized.
+ */
+
+ _Timer_server = NULL;
+}
diff --git a/cpukit/rtems/src/rtemstimerdata.c b/cpukit/rtems/src/rtemstimerdata.c
new file mode 100644
index 0000000000..b817c2f788
--- /dev/null
+++ b/cpukit/rtems/src/rtemstimerdata.c
@@ -0,0 +1,22 @@
+/*
+ * Timer Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS timer data */
+#define RTEMS_TIMER_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/timer.h>
diff --git a/cpukit/rtems/src/sem.c b/cpukit/rtems/src/sem.c
new file mode 100644
index 0000000000..ecf070e44d
--- /dev/null
+++ b/cpukit/rtems/src/sem.c
@@ -0,0 +1,93 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * _Semaphore_Manager_initialization
+ *
+ * This routine initializes all semaphore manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Semaphore_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Semaphore_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_SEMAPHORES, /* object class */
+ Configuration_RTEMS_API.maximum_semaphores,
+ /* maximum objects of this class */
+ sizeof( Semaphore_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ true, /* true if this is a global object class */
+ _Semaphore_MP_Send_extract_proxy /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor(
+ MP_PACKET_SEMAPHORE,
+ _Semaphore_MP_Process_packet
+ );
+#endif
+
+}
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
new file mode 100644
index 0000000000..49cffc8e10
--- /dev/null
+++ b/cpukit/rtems/src/semcreate.c
@@ -0,0 +1,231 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * rtems_semaphore_create
+ *
+ * This directive creates a semaphore and sets the initial value based
+ * on the given count. A semaphore id is returned.
+ *
+ * Input parameters:
+ * name - user defined semaphore name
+ * count - initial count of semaphore
+ * attribute_set - semaphore attributes
+ * priority_ceiling - semaphore's ceiling priority
+ * id - pointer to semaphore id
+ *
+ * Output parameters:
+ * id - semaphore id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_semaphore_create(
+ rtems_name name,
+ uint32_t count,
+ rtems_attribute attribute_set,
+ rtems_task_priority priority_ceiling,
+ rtems_id *id
+)
+{
+ register Semaphore_Control *the_semaphore;
+ CORE_mutex_Attributes the_mutex_attr;
+ CORE_semaphore_Attributes the_semaphore_attr;
+ CORE_mutex_Status mutex_status;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( attribute_set ) ) {
+
+ if ( !_System_state_Is_multiprocessing )
+ return RTEMS_MP_NOT_CONFIGURED;
+
+ if ( _Attributes_Is_inherit_priority( attribute_set ) ||
+ _Attributes_Is_priority_ceiling( attribute_set ) )
+ return RTEMS_NOT_DEFINED;
+
+ } else
+#endif
+
+ if ( _Attributes_Is_inherit_priority( attribute_set ) ||
+ _Attributes_Is_priority_ceiling( attribute_set ) ) {
+
+ if ( ! (_Attributes_Is_binary_semaphore( attribute_set ) &&
+ _Attributes_Is_priority( attribute_set ) ) )
+ return RTEMS_NOT_DEFINED;
+
+ }
+
+ if ( _Attributes_Is_inherit_priority( attribute_set ) &&
+ _Attributes_Is_priority_ceiling( attribute_set ) )
+ return RTEMS_NOT_DEFINED;
+
+ if ( !_Attributes_Is_counting_semaphore( attribute_set ) && ( count > 1 ) )
+ return RTEMS_INVALID_NUMBER;
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_semaphore = _Semaphore_Allocate();
+
+ if ( !the_semaphore ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( attribute_set ) &&
+ ! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name,
+ the_semaphore->Object.id, false ) ) ) {
+ _Semaphore_Free( the_semaphore );
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+#endif
+
+ the_semaphore->attribute_set = attribute_set;
+
+ /*
+ * Initialize it as a counting semaphore.
+ */
+ if ( _Attributes_Is_counting_semaphore( attribute_set ) ) {
+ /*
+ * This effectively disables limit checking.
+ */
+ the_semaphore_attr.maximum_count = 0xFFFFFFFF;
+
+ if ( _Attributes_Is_priority( attribute_set ) )
+ the_semaphore_attr.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY;
+ else
+ the_semaphore_attr.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
+
+ /*
+ * The following are just to make Purify happy.
+ */
+ the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
+ the_mutex_attr.priority_ceiling = PRIORITY_MINIMUM;
+
+ _CORE_semaphore_Initialize(
+ &the_semaphore->Core_control.semaphore,
+ &the_semaphore_attr,
+ count
+ );
+ } else {
+ /*
+ * It is either simple binary semaphore or a more powerful mutex
+ * style binary semaphore. This is the mutex style.
+ */
+ if ( _Attributes_Is_priority( attribute_set ) )
+ the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY;
+ else
+ the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
+
+ if ( _Attributes_Is_binary_semaphore( attribute_set ) ) {
+ the_mutex_attr.priority_ceiling = priority_ceiling;
+ the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
+ the_mutex_attr.only_owner_release = false;
+
+ if ( the_mutex_attr.discipline == CORE_MUTEX_DISCIPLINES_PRIORITY ) {
+ if ( _Attributes_Is_inherit_priority( attribute_set ) ) {
+ the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
+ the_mutex_attr.only_owner_release = true;
+ } else if ( _Attributes_Is_priority_ceiling( attribute_set ) ) {
+ the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
+ the_mutex_attr.only_owner_release = true;
+ }
+ }
+ } else /* must be simple binary semaphore */ {
+ the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_BLOCKS;
+ the_mutex_attr.only_owner_release = false;
+ }
+
+ mutex_status = _CORE_mutex_Initialize(
+ &the_semaphore->Core_control.mutex,
+ &the_mutex_attr,
+ (count == 1) ? CORE_MUTEX_UNLOCKED : CORE_MUTEX_LOCKED
+ );
+
+ if ( mutex_status == CORE_MUTEX_STATUS_CEILING_VIOLATED ) {
+ _Semaphore_Free( the_semaphore );
+ _Thread_Enable_dispatch();
+ return RTEMS_INVALID_PRIORITY;
+ }
+ }
+
+ /*
+ * Whether we initialized it as a mutex or counting semaphore, it is
+ * now ready to be "offered" for use as a Classic API Semaphore.
+ */
+ _Objects_Open(
+ &_Semaphore_Information,
+ &the_semaphore->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_semaphore->Object.id;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( attribute_set ) )
+ _Semaphore_MP_Send_process_packet(
+ SEMAPHORE_MP_ANNOUNCE_CREATE,
+ the_semaphore->Object.id,
+ name,
+ 0 /* Not used */
+ );
+#endif
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/semdata.c b/cpukit/rtems/src/semdata.c
new file mode 100644
index 0000000000..cc4126db15
--- /dev/null
+++ b/cpukit/rtems/src/semdata.c
@@ -0,0 +1,22 @@
+/*
+ * Semaphore Manager -- Data Instantiation
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate semaphore data */
+#define RTEMS_SEM_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/sem.h>
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
new file mode 100644
index 0000000000..d9c81fc56b
--- /dev/null
+++ b/cpukit/rtems/src/semdelete.c
@@ -0,0 +1,136 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * rtems_semaphore_delete
+ *
+ * This directive allows a thread to delete a semaphore specified by
+ * the semaphore id. The semaphore is freed back to the inactive
+ * semaphore chain.
+ *
+ * Input parameters:
+ * id - semaphore id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+#define SEMAPHORE_MP_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted
+#else
+#define SEMAPHORE_MP_OBJECT_WAS_DELETED NULL
+#endif
+
+rtems_status_code rtems_semaphore_delete(
+ rtems_id id
+)
+{
+ register Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _Semaphore_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
+ if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) &&
+ !_Attributes_Is_simple_binary_semaphore(
+ the_semaphore->attribute_set ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_RESOURCE_IN_USE;
+ }
+ _CORE_mutex_Flush(
+ &the_semaphore->Core_control.mutex,
+ SEMAPHORE_MP_OBJECT_WAS_DELETED,
+ CORE_MUTEX_WAS_DELETED
+ );
+ } else {
+ _CORE_semaphore_Flush(
+ &the_semaphore->Core_control.semaphore,
+ SEMAPHORE_MP_OBJECT_WAS_DELETED,
+ CORE_SEMAPHORE_WAS_DELETED
+ );
+ }
+
+ _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
+
+ _Semaphore_Free( the_semaphore );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
+
+ _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
+
+ _Semaphore_MP_Send_process_packet(
+ SEMAPHORE_MP_ANNOUNCE_DELETE,
+ the_semaphore->Object.id,
+ 0, /* Not used */
+ 0 /* Not used */
+ );
+ }
+#endif
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
new file mode 100644
index 0000000000..120b83e0fe
--- /dev/null
+++ b/cpukit/rtems/src/semflush.c
@@ -0,0 +1,102 @@
+/*
+ * rtems_semaphore_flush
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the flush directive
+ * of the Semaphore Manager.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * rtems_semaphore_flush
+ *
+ * This directive allows a thread to flush the threads
+ * pending on the semaphore.
+ *
+ * Input parameters:
+ * id - semaphore id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+#define SEND_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted
+#else
+#define SEND_OBJECT_WAS_DELETED NULL
+#endif
+
+rtems_status_code rtems_semaphore_flush(
+ rtems_id id
+)
+{
+ register Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+
+ the_semaphore = _Semaphore_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
+ _CORE_mutex_Flush(
+ &the_semaphore->Core_control.mutex,
+ SEND_OBJECT_WAS_DELETED,
+ CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT
+ );
+ } else {
+ _CORE_semaphore_Flush(
+ &the_semaphore->Core_control.semaphore,
+ SEND_OBJECT_WAS_DELETED,
+ CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT
+ );
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/semident.c b/cpukit/rtems/src/semident.c
new file mode 100644
index 0000000000..56f8856da7
--- /dev/null
+++ b/cpukit/rtems/src/semident.c
@@ -0,0 +1,81 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * rtems_semaphore_ident
+ *
+ * This directive returns the system ID associated with
+ * the semaphore name.
+ *
+ * Input parameters:
+ * name - user defined semaphore name
+ * node - node(s) to be searched
+ * id - pointer to semaphore id
+ *
+ * Output parameters:
+ * *id - semaphore id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_semaphore_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32( &_Semaphore_Information, name, node, id );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/semmp.c b/cpukit/rtems/src/semmp.c
new file mode 100644
index 0000000000..06bed8a52c
--- /dev/null
+++ b/cpukit/rtems/src/semmp.c
@@ -0,0 +1,367 @@
+/*
+ * Multiprocessing Support for the Semaphore Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Semaphore_MP_Send_process_packet
+ *
+ */
+
+void _Semaphore_MP_Send_process_packet (
+ Semaphore_MP_Remote_operations operation,
+ Objects_Id semaphore_id,
+ rtems_name name,
+ Objects_Id proxy_id
+)
+{
+ Semaphore_MP_Packet *the_packet;
+ uint32_t node;
+
+ switch ( operation ) {
+
+ case SEMAPHORE_MP_ANNOUNCE_CREATE:
+ case SEMAPHORE_MP_ANNOUNCE_DELETE:
+ case SEMAPHORE_MP_EXTRACT_PROXY:
+
+ the_packet = _Semaphore_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_SEMAPHORE;
+ the_packet->Prefix.length = sizeof ( Semaphore_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = semaphore_id;
+ the_packet->name = name;
+ the_packet->proxy_id = proxy_id;
+
+ if ( operation == SEMAPHORE_MP_EXTRACT_PROXY )
+ node = _Objects_Get_node( semaphore_id );
+ else
+ node = MPCI_ALL_NODES;
+
+ _MPCI_Send_process_packet( node, &the_packet->Prefix );
+ break;
+
+ case SEMAPHORE_MP_OBTAIN_REQUEST:
+ case SEMAPHORE_MP_OBTAIN_RESPONSE:
+ case SEMAPHORE_MP_RELEASE_REQUEST:
+ case SEMAPHORE_MP_RELEASE_RESPONSE:
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _Semaphore_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _Semaphore_MP_Send_request_packet (
+ Semaphore_MP_Remote_operations operation,
+ Objects_Id semaphore_id,
+ rtems_option option_set,
+ rtems_interval timeout
+)
+{
+ Semaphore_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case SEMAPHORE_MP_OBTAIN_REQUEST:
+ case SEMAPHORE_MP_RELEASE_REQUEST:
+
+ the_packet = _Semaphore_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_SEMAPHORE;
+ the_packet->Prefix.length = sizeof ( Semaphore_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet );
+ if ( ! _Options_Is_no_wait(option_set))
+ the_packet->Prefix.timeout = timeout;
+
+ the_packet->operation = operation;
+ the_packet->Prefix.id = semaphore_id;
+ the_packet->option_set = option_set;
+
+ return _MPCI_Send_request_packet(
+ _Objects_Get_node( semaphore_id ),
+ &the_packet->Prefix,
+ STATES_WAITING_FOR_SEMAPHORE
+ );
+ break;
+
+ case SEMAPHORE_MP_ANNOUNCE_CREATE:
+ case SEMAPHORE_MP_ANNOUNCE_DELETE:
+ case SEMAPHORE_MP_EXTRACT_PROXY:
+ case SEMAPHORE_MP_OBTAIN_RESPONSE:
+ case SEMAPHORE_MP_RELEASE_RESPONSE:
+ break;
+
+ }
+ /*
+ * The following line is included to satisfy compilers which
+ * produce warnings when a function does not end with a return.
+ */
+ return RTEMS_SUCCESSFUL;
+}
+
+/*PAGE
+ *
+ * _Semaphore_MP_Send_response_packet
+ *
+ */
+
+void _Semaphore_MP_Send_response_packet (
+ Semaphore_MP_Remote_operations operation,
+ Objects_Id semaphore_id,
+ Thread_Control *the_thread
+)
+{
+ Semaphore_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case SEMAPHORE_MP_OBTAIN_RESPONSE:
+ case SEMAPHORE_MP_RELEASE_RESPONSE:
+
+ the_packet = ( Semaphore_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case SEMAPHORE_MP_ANNOUNCE_CREATE:
+ case SEMAPHORE_MP_ANNOUNCE_DELETE:
+ case SEMAPHORE_MP_EXTRACT_PROXY:
+ case SEMAPHORE_MP_OBTAIN_REQUEST:
+ case SEMAPHORE_MP_RELEASE_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _Semaphore_MP_Process_packet
+ *
+ */
+
+void _Semaphore_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ Semaphore_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+ bool ignored;
+
+ the_packet = (Semaphore_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case SEMAPHORE_MP_ANNOUNCE_CREATE:
+
+ ignored = _Objects_MP_Allocate_and_open(
+ &_Semaphore_Information,
+ the_packet->name,
+ the_packet->Prefix.id,
+ true
+ );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case SEMAPHORE_MP_ANNOUNCE_DELETE:
+
+ _Objects_MP_Close( &_Semaphore_Information, the_packet->Prefix.id );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case SEMAPHORE_MP_EXTRACT_PROXY:
+
+ the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
+
+ if ( ! _Thread_Is_null( the_thread ) )
+ _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case SEMAPHORE_MP_OBTAIN_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_semaphore_obtain(
+ the_packet->Prefix.id,
+ the_packet->option_set,
+ the_packet->Prefix.timeout
+ );
+
+ if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING )
+ _Semaphore_MP_Send_response_packet(
+ SEMAPHORE_MP_OBTAIN_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+
+ case SEMAPHORE_MP_OBTAIN_RESPONSE:
+ case SEMAPHORE_MP_RELEASE_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case SEMAPHORE_MP_RELEASE_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_semaphore_release(
+ the_packet->Prefix.id
+ );
+
+ _Semaphore_MP_Send_response_packet(
+ SEMAPHORE_MP_RELEASE_RESPONSE,
+ the_packet->Prefix.id,
+ _Thread_Executing
+ );
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _Semaphore_MP_Send_object_was_deleted
+ *
+ */
+
+void _Semaphore_MP_Send_object_was_deleted (
+ Thread_Control *the_proxy
+)
+{
+ the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED;
+
+ _Semaphore_MP_Send_response_packet(
+ SEMAPHORE_MP_OBTAIN_RESPONSE,
+ the_proxy->Wait.id,
+ the_proxy
+ );
+
+}
+
+/*PAGE
+ *
+ * _Semaphore_MP_Send_extract_proxy
+ *
+ */
+
+void _Semaphore_MP_Send_extract_proxy (
+ void *argument
+)
+{
+ Thread_Control *the_thread = (Thread_Control *)argument;
+
+ _Semaphore_MP_Send_process_packet(
+ SEMAPHORE_MP_EXTRACT_PROXY,
+ the_thread->Wait.id,
+ (rtems_name) 0,
+ the_thread->Object.id
+ );
+
+}
+
+/*PAGE
+ *
+ * _Semaphore_MP_Get_packet
+ *
+ */
+
+Semaphore_MP_Packet *_Semaphore_MP_Get_packet ( void )
+{
+ return ( (Semaphore_MP_Packet *) _MPCI_Get_packet() );
+}
+
+/*PAGE
+ *
+ * _Semaphore_Core_mutex_mp_support
+ *
+ * Input parameters:
+ * the_thread - the remote thread the semaphore was surrendered to
+ * id - id of the surrendered semaphore
+ *
+ * Output parameters: NONE
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+void _Semaphore_Core_mutex_mp_support (
+ Thread_Control *the_thread,
+ Objects_Id id
+)
+{
+ the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
+
+ _Semaphore_MP_Send_response_packet(
+ SEMAPHORE_MP_OBTAIN_RESPONSE,
+ id,
+ the_thread
+ );
+}
+#endif
+
+
+/*PAGE
+ *
+ * _Semaphore_Core_semaphore_mp_support
+ *
+ * Input parameters:
+ * the_thread - the remote thread the semaphore was surrendered to
+ * id - id of the surrendered semaphore
+ *
+ * Output parameters: NONE
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+void _Semaphore_Core_semaphore_mp_support (
+ Thread_Control *the_thread,
+ Objects_Id id
+)
+{
+ the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
+
+ _Semaphore_MP_Send_response_packet(
+ SEMAPHORE_MP_OBTAIN_RESPONSE,
+ id,
+ the_thread
+ );
+}
+#endif
+/* end of file */
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
new file mode 100644
index 0000000000..e3f3af1b10
--- /dev/null
+++ b/cpukit/rtems/src/semobtain.c
@@ -0,0 +1,121 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * rtems_semaphore_obtain
+ *
+ * This directive allows a thread to acquire a semaphore.
+ *
+ * Input parameters:
+ * id - semaphore id
+ * option_set - wait option
+ * timeout - number of ticks to wait (0 means wait forever)
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_semaphore_obtain(
+ rtems_id id,
+ rtems_option option_set,
+ rtems_interval timeout
+)
+{
+ register Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+ ISR_Level level;
+
+ the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
+ _CORE_mutex_Seize(
+ &the_semaphore->Core_control.mutex,
+ id,
+ ((_Options_Is_no_wait( option_set )) ? false : true),
+ timeout,
+ level
+ );
+ return _Semaphore_Translate_core_mutex_return_code(
+ _Thread_Executing->Wait.return_code );
+ }
+
+ /* must be a counting semaphore */
+ _CORE_semaphore_Seize_isr_disable(
+ &the_semaphore->Core_control.semaphore,
+ id,
+ ((_Options_Is_no_wait( option_set )) ? false : true),
+ timeout,
+ &level
+ );
+ return _Semaphore_Translate_core_semaphore_return_code(
+ _Thread_Executing->Wait.return_code );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Semaphore_MP_Send_request_packet(
+ SEMAPHORE_MP_OBTAIN_REQUEST,
+ id,
+ option_set,
+ timeout
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
new file mode 100644
index 0000000000..6ccf0cfbbe
--- /dev/null
+++ b/cpukit/rtems/src/semrelease.c
@@ -0,0 +1,119 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * rtems_semaphore_release
+ *
+ * This directive allows a thread to release a semaphore.
+ *
+ * Input parameters:
+ * id - semaphore id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+#define MUTEX_MP_SUPPORT _Semaphore_Core_mutex_mp_support
+#else
+#define MUTEX_MP_SUPPORT NULL
+#endif
+
+rtems_status_code rtems_semaphore_release(
+ rtems_id id
+)
+{
+ register Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+ CORE_mutex_Status mutex_status;
+ CORE_semaphore_Status semaphore_status;
+
+ the_semaphore = _Semaphore_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
+ mutex_status = _CORE_mutex_Surrender(
+ &the_semaphore->Core_control.mutex,
+ id,
+ MUTEX_MP_SUPPORT
+ );
+ _Thread_Enable_dispatch();
+ return _Semaphore_Translate_core_mutex_return_code( mutex_status );
+ } else {
+ semaphore_status = _CORE_semaphore_Surrender(
+ &the_semaphore->Core_control.semaphore,
+ id,
+ MUTEX_MP_SUPPORT
+ );
+ _Thread_Enable_dispatch();
+ return
+ _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Semaphore_MP_Send_request_packet(
+ SEMAPHORE_MP_RELEASE_REQUEST,
+ id,
+ 0, /* Not used */
+ MPCI_DEFAULT_TIMEOUT
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/semtranslatereturncode.c b/cpukit/rtems/src/semtranslatereturncode.c
new file mode 100644
index 0000000000..02b665e5f6
--- /dev/null
+++ b/cpukit/rtems/src/semtranslatereturncode.c
@@ -0,0 +1,137 @@
+/*
+ * Semaphore Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Semaphore Manager.
+ * This manager utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * Directives provided are:
+ *
+ * + create a semaphore
+ * + get an ID of a semaphore
+ * + delete a semaphore
+ * + acquire a semaphore
+ * + release a semaphore
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/interr.h>
+
+/*PAGE
+ *
+ * _Semaphore_Translate_core_mutex_return_code
+ *
+ * Input parameters:
+ * status - mutex status code to translate
+ *
+ * Output parameters:
+ * rtems status code - translated RTEMS status code
+ *
+ */
+
+const rtems_status_code _Semaphore_Translate_core_mutex_return_code_[] = {
+ RTEMS_SUCCESSFUL, /* CORE_MUTEX_STATUS_SUCCESSFUL */
+ RTEMS_UNSATISFIED, /* CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT */
+#if defined(RTEMS_POSIX_API)
+ RTEMS_UNSATISFIED, /* CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED */
+#endif
+ RTEMS_NOT_OWNER_OF_RESOURCE, /* CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE */
+ RTEMS_OBJECT_WAS_DELETED, /* CORE_MUTEX_WAS_DELETED */
+ RTEMS_TIMEOUT, /* CORE_MUTEX_TIMEOUT */
+#if defined(__RTEMS_STRICT_ORDER_MUTEX__)
+ CORE_MUTEX_RELEASE_NOT_ORDER,
+#endif
+ RTEMS_INVALID_PRIORITY /* CORE_MUTEX_STATUS_CEILING_VIOLATED */
+};
+
+rtems_status_code _Semaphore_Translate_core_mutex_return_code (
+ uint32_t status
+)
+{
+ /*
+ * If this thread is blocking waiting for a result on a remote operation.
+ */
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _Thread_Is_proxy_blocking(status) )
+ return RTEMS_PROXY_BLOCKING;
+ #endif
+
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( status > CORE_MUTEX_STATUS_LAST )
+ return RTEMS_INTERNAL_ERROR;
+ #endif
+ return _Semaphore_Translate_core_mutex_return_code_[status];
+}
+
+/*PAGE
+ *
+ * _Semaphore_Translate_core_semaphore_return_code
+ *
+ * Input parameters:
+ * status - semaphore status code to translate
+ *
+ * Output parameters:
+ * rtems status code - translated RTEMS status code
+ *
+ */
+
+const rtems_status_code _Semaphore_Translate_core_semaphore_return_code_[] = {
+ RTEMS_SUCCESSFUL, /* CORE_SEMAPHORE_STATUS_SUCCESSFUL */
+ RTEMS_UNSATISFIED, /* CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT */
+ RTEMS_OBJECT_WAS_DELETED, /* CORE_SEMAPHORE_WAS_DELETED */
+ RTEMS_TIMEOUT, /* CORE_SEMAPHORE_TIMEOUT */
+ RTEMS_INTERNAL_ERROR, /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */
+};
+
+rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
+ uint32_t status
+)
+{
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _Thread_Is_proxy_blocking(status) )
+ return RTEMS_PROXY_BLOCKING;
+ #endif
+ /*
+ * Internal consistency check for bad status from SuperCore
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( status > CORE_SEMAPHORE_STATUS_LAST )
+ return RTEMS_INTERNAL_ERROR;
+ #endif
+ return _Semaphore_Translate_core_semaphore_return_code_[status];
+}
diff --git a/cpukit/rtems/src/signal.c b/cpukit/rtems/src/signal.c
new file mode 100644
index 0000000000..d54d1e2491
--- /dev/null
+++ b/cpukit/rtems/src/signal.c
@@ -0,0 +1,51 @@
+/*
+ * Signal Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/asr.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * _Signal_Manager_initialization
+ *
+ * This routine initializes all signal manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Signal_Manager_initialization( void )
+{
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor(
+ MP_PACKET_SIGNAL,
+ _Signal_MP_Process_packet
+ );
+#endif
+}
diff --git a/cpukit/rtems/src/signalcatch.c b/cpukit/rtems/src/signalcatch.c
new file mode 100644
index 0000000000..fd38e06e2f
--- /dev/null
+++ b/cpukit/rtems/src/signalcatch.c
@@ -0,0 +1,69 @@
+/*
+ * Signal Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/asr.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * rtems_signal_catch
+ *
+ * This directive allows a thread to specify what action to take when
+ * catching signals.
+ *
+ * Input parameters:
+ * handler - address of asynchronous signal routine (asr)
+ * ( NULL indicates asr is invalid )
+ * mode_set - mode value for asr
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - always succeeds
+ */
+
+rtems_status_code rtems_signal_catch(
+ rtems_asr_entry asr_handler,
+ rtems_mode mode_set
+)
+{
+ Thread_Control *executing;
+ RTEMS_API_Control *api;
+ ASR_Information *asr;
+
+/* XXX normalize mode */
+ executing = _Thread_Executing;
+ api = (RTEMS_API_Control*)executing->API_Extensions[ THREAD_API_RTEMS ];
+ asr = &api->Signal;
+
+ _Thread_Disable_dispatch(); /* cannot reschedule while */
+ /* the thread is inconsistent */
+
+ if ( !_ASR_Is_null_handler( asr_handler ) ) {
+ asr->mode_set = mode_set;
+ asr->handler = asr_handler;
+ }
+ else
+ _ASR_Initialize( asr );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/signalmp.c b/cpukit/rtems/src/signalmp.c
new file mode 100644
index 0000000000..2311e9e4a0
--- /dev/null
+++ b/cpukit/rtems/src/signalmp.c
@@ -0,0 +1,192 @@
+/*
+ * Multiprocessing Support for the Signal Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _Signal_MP_Send_process_packet
+ *
+ * This subprogram is not needed since there are no process
+ * packets to be sent by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _Signal_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _Signal_MP_Send_request_packet (
+ Signal_MP_Remote_operations operation,
+ Objects_Id task_id,
+ rtems_signal_set signal_in
+)
+{
+ Signal_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case SIGNAL_MP_SEND_REQUEST:
+
+ the_packet = _Signal_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_SIGNAL;
+ the_packet->Prefix.length = sizeof ( Signal_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( Signal_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = task_id;
+ the_packet->signal_in = signal_in;
+
+ return _MPCI_Send_request_packet(
+ _Objects_Get_node( task_id ),
+ &the_packet->Prefix,
+ STATES_READY /* Not used */
+ );
+ break;
+
+ case SIGNAL_MP_SEND_RESPONSE:
+ break;
+
+ }
+ /*
+ * The following line is included to satisfy compilers which
+ * produce warnings when a function does not end with a return.
+ */
+ return RTEMS_INTERNAL_ERROR;
+}
+
+/*PAGE
+ *
+ * _Signal_MP_Send_response_packet
+ *
+ */
+
+void _Signal_MP_Send_response_packet (
+ Signal_MP_Remote_operations operation,
+ Thread_Control *the_thread
+)
+{
+ Signal_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case SIGNAL_MP_SEND_RESPONSE:
+
+ the_packet = ( Signal_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case SIGNAL_MP_SEND_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _Signal_MP_Process_packet
+ *
+ */
+
+void _Signal_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ Signal_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+
+ the_packet = (Signal_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case SIGNAL_MP_SEND_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_signal_send(
+ the_packet->Prefix.id,
+ the_packet->signal_in
+ );
+
+ _Signal_MP_Send_response_packet(
+ SIGNAL_MP_SEND_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+
+ case SIGNAL_MP_SEND_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ * _Signal_MP_Send_object_was_deleted
+ *
+ * This subprogram is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _Signal_MP_Send_extract_proxy
+ *
+ * This subprogram is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _Signal_MP_Get_packet
+ *
+ */
+
+Signal_MP_Packet *_Signal_MP_Get_packet ( void )
+{
+ return ( (Signal_MP_Packet *) _MPCI_Get_packet() );
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/signalsend.c b/cpukit/rtems/src/signalsend.c
new file mode 100644
index 0000000000..031a18979e
--- /dev/null
+++ b/cpukit/rtems/src/signalsend.c
@@ -0,0 +1,92 @@
+/*
+ * Signal Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/asr.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/tasks.h>
+
+/*PAGE
+ *
+ * rtems_signal_send
+ *
+ * This directive allows a thread to send signals to a thread.
+ *
+ * Input parameters:
+ * id - thread id
+ * signal_set - signal set
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_signal_send(
+ rtems_id id,
+ rtems_signal_set signal_set
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+ RTEMS_API_Control *api;
+ ASR_Information *asr;
+
+ if ( !signal_set )
+ return RTEMS_INVALID_NUMBER;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
+ asr = &api->Signal;
+
+ if ( ! _ASR_Is_null_handler( asr->handler ) ) {
+ if ( asr->is_enabled ) {
+ _ASR_Post_signals( signal_set, &asr->signals_posted );
+
+ if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) )
+ _Thread_Dispatch_necessary = true;
+ } else {
+ _ASR_Post_signals( signal_set, &asr->signals_pending );
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_NOT_DEFINED;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _Signal_MP_Send_request_packet(
+ SIGNAL_MP_SEND_REQUEST,
+ id,
+ signal_set
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskcreate.c b/cpukit/rtems/src/taskcreate.c
new file mode 100644
index 0000000000..c173eced29
--- /dev/null
+++ b/cpukit/rtems/src/taskcreate.c
@@ -0,0 +1,229 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_task_create
+ *
+ * This directive creates a thread by allocating and initializing a
+ * thread control block and a stack. The newly created thread is
+ * placed in the dormant state.
+ *
+ * Input parameters:
+ * name - user defined thread name
+ * initial_priority - thread priority
+ * stack_size - stack size in bytes
+ * initial_modes - initial thread mode
+ * attribute_set - thread attributes
+ * id - pointer to thread id
+ *
+ * Output parameters:
+ * id - thread id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_create(
+ rtems_name name,
+ rtems_task_priority initial_priority,
+ size_t stack_size,
+ rtems_mode initial_modes,
+ rtems_attribute attribute_set,
+ rtems_id *id
+)
+{
+ register Thread_Control *the_thread;
+ bool is_fp;
+#if defined(RTEMS_MULTIPROCESSING)
+ Objects_MP_Control *the_global_object = NULL;
+ bool is_global;
+#endif
+ bool status;
+ rtems_attribute the_attribute_set;
+ Priority_Control core_priority;
+ RTEMS_API_Control *api;
+ ASR_Information *asr;
+
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ /*
+ * Core Thread Initialize insures we get the minimum amount of
+ * stack space.
+ */
+
+ /*
+ * Fix the attribute set to match the attributes which
+ * this processor (1) requires and (2) is able to support.
+ * First add in the required flags for attribute_set
+ * Typically this might include FP if the platform
+ * or application required all tasks to be fp aware.
+ * Then turn off the requested bits which are not supported.
+ */
+
+ the_attribute_set = _Attributes_Set( attribute_set, ATTRIBUTES_REQUIRED );
+ the_attribute_set =
+ _Attributes_Clear( the_attribute_set, ATTRIBUTES_NOT_SUPPORTED );
+
+ if ( _Attributes_Is_floating_point( the_attribute_set ) )
+ is_fp = true;
+ else
+ is_fp = false;
+
+ /*
+ * Validate the RTEMS API priority and convert it to the core priority range.
+ */
+
+ if ( !_Attributes_Is_system_task( the_attribute_set ) ) {
+ if ( !_RTEMS_tasks_Priority_is_valid( initial_priority ) )
+ return RTEMS_INVALID_PRIORITY;
+ }
+
+ core_priority = _RTEMS_tasks_Priority_to_Core( initial_priority );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Attributes_Is_global( the_attribute_set ) ) {
+
+ is_global = true;
+
+ if ( !_System_state_Is_multiprocessing )
+ return RTEMS_MP_NOT_CONFIGURED;
+
+ } else
+ is_global = false;
+#endif
+
+ /*
+ * Make sure system is MP if this task is global
+ */
+
+ /*
+ * Lock the allocator mutex for protection
+ */
+ _RTEMS_Lock_allocator();
+
+ /*
+ * Allocate the thread control block and -- if the task is global --
+ * allocate a global object control block.
+ *
+ * NOTE: This routine does not use the combined allocate and open
+ * global object routine because this results in a lack of
+ * control over when memory is allocated and can be freed in
+ * the event of an error.
+ */
+
+ the_thread = _RTEMS_tasks_Allocate();
+
+ if ( !the_thread ) {
+ _RTEMS_Unlock_allocator();
+ return RTEMS_TOO_MANY;
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global ) {
+ the_global_object = _Objects_MP_Allocate_global_object();
+
+ if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
+ _RTEMS_tasks_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return RTEMS_TOO_MANY;
+ }
+ }
+#endif
+
+ /*
+ * Initialize the core thread for this task.
+ */
+
+ status = _Thread_Initialize(
+ &_RTEMS_tasks_Information,
+ the_thread,
+ NULL,
+ stack_size,
+ is_fp,
+ core_priority,
+ _Modes_Is_preempt(initial_modes) ? true : false,
+ _Modes_Is_timeslice(initial_modes) ?
+ THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE :
+ THREAD_CPU_BUDGET_ALGORITHM_NONE,
+ NULL, /* no budget algorithm callout */
+ _Modes_Get_interrupt_level(initial_modes),
+ (Objects_Name) name
+ );
+
+ if ( !status ) {
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global )
+ _Objects_MP_Free_global_object( the_global_object );
+#endif
+ _RTEMS_tasks_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return RTEMS_UNSATISFIED;
+ }
+
+ api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
+ asr = &api->Signal;
+
+ asr->is_enabled = _Modes_Is_asr_disabled(initial_modes) ? false : true;
+
+ *id = the_thread->Object.id;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ the_thread->is_global = is_global;
+ if ( is_global ) {
+
+ _Objects_MP_Open(
+ &_RTEMS_tasks_Information,
+ the_global_object,
+ name,
+ the_thread->Object.id
+ );
+
+ _RTEMS_tasks_MP_Send_process_packet(
+ RTEMS_TASKS_MP_ANNOUNCE_CREATE,
+ the_thread->Object.id,
+ name
+ );
+
+ }
+#endif
+
+ _RTEMS_Unlock_allocator();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/taskdata.c b/cpukit/rtems/src/taskdata.c
new file mode 100644
index 0000000000..13c0a1f6e1
--- /dev/null
+++ b/cpukit/rtems/src/taskdata.c
@@ -0,0 +1,22 @@
+/*
+ * RTEMS Task Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS Classic API tasks data */
+#define RTEMS_TASKS_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
diff --git a/cpukit/rtems/src/taskdelete.c b/cpukit/rtems/src/taskdelete.c
new file mode 100644
index 0000000000..a29ea77ac4
--- /dev/null
+++ b/cpukit/rtems/src/taskdelete.c
@@ -0,0 +1,110 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/apimutex.h>
+
+/*PAGE
+ *
+ * rtems_task_delete
+ *
+ * This directive allows a thread to delete itself or the thread
+ * identified in the id field. The executive halts execution
+ * of the thread and frees the thread control block.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters:
+ * nothing - if id is the requesting thread (always succeeds)
+ * RTEMS_SUCCESSFUL - if successful and id is
+ * not the requesting thread
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_delete(
+ rtems_id id
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+ Objects_Information *the_information;
+
+ _RTEMS_Lock_allocator();
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_information = _Objects_Get_information_id( the_thread->Object.id );
+
+ #if defined(RTEMS_DEBUG)
+ if ( !the_information ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_INVALID_ID;
+ /* This should never happen if _Thread_Get() works right */
+ }
+ #endif
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( the_thread->is_global ) {
+ _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id );
+ _RTEMS_tasks_MP_Send_process_packet(
+ RTEMS_TASKS_MP_ANNOUNCE_DELETE,
+ the_thread->Object.id,
+ 0 /* Not used */
+ );
+ }
+ #endif
+
+ _Thread_Close( the_information, the_thread );
+
+ _RTEMS_tasks_Free( the_thread );
+
+ _RTEMS_Unlock_allocator();
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _RTEMS_Unlock_allocator();
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ _RTEMS_Unlock_allocator();
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskgetnote.c b/cpukit/rtems/src/taskgetnote.c
new file mode 100644
index 0000000000..46c28460a5
--- /dev/null
+++ b/cpukit/rtems/src/taskgetnote.c
@@ -0,0 +1,116 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_get_note
+ *
+ * This directive obtains the note from the specified notepad
+ * of the specified thread.
+ *
+ * Input parameters:
+ * id - thread id
+ * notepad - notepad number
+ * note - pointer to note
+ *
+ * Output parameters:
+ * note - filled in if successful
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_get_note(
+ rtems_id id,
+ uint32_t notepad,
+ uint32_t *note
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+ RTEMS_API_Control *api;
+
+ if ( !rtems_configuration_get_notepads_enabled() )
+ return RTEMS_NOT_CONFIGURED;
+
+ if ( !note )
+ return RTEMS_INVALID_ADDRESS;
+
+ /*
+ * NOTE: There is no check for < RTEMS_NOTEPAD_FIRST because that would
+ * be checking an unsigned number for being negative.
+ */
+
+ if ( notepad > RTEMS_NOTEPAD_LAST )
+ return RTEMS_INVALID_NUMBER;
+
+ /*
+ * Optimize the most likely case to avoid the Thread_Dispatch.
+ */
+
+ if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ||
+ _Objects_Are_ids_equal( id, _Thread_Executing->Object.id ) ) {
+ api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ];
+ *note = api->Notepads[ notepad ];
+ return RTEMS_SUCCESSFUL;
+ }
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
+ *note = api->Notepads[ notepad ];
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Executing->Wait.return_argument = note;
+
+ return _RTEMS_tasks_MP_Send_request_packet(
+ RTEMS_TASKS_MP_GET_NOTE_REQUEST,
+ id,
+ 0, /* Not used */
+ notepad,
+ 0 /* Not used */
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskident.c b/cpukit/rtems/src/taskident.c
new file mode 100644
index 0000000000..8888c77ee2
--- /dev/null
+++ b/cpukit/rtems/src/taskident.c
@@ -0,0 +1,72 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_ident
+ *
+ * This directive returns the system ID associated with
+ * the thread name.
+ *
+ * Input parameters:
+ * name - user defined thread name
+ * node - node(s) to be searched
+ * id - pointer to thread id
+ *
+ * Output parameters:
+ * *id - thread id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_ident(
+ rtems_name name,
+ uint32_t node,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( name == OBJECTS_ID_OF_SELF ) {
+ *id = _Thread_Executing->Object.id;
+ return RTEMS_SUCCESSFUL;
+ }
+
+ status = _Objects_Name_to_id_u32( &_RTEMS_tasks_Information, name, node, id );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/taskinitusers.c b/cpukit/rtems/src/taskinitusers.c
new file mode 100644
index 0000000000..b0c1198421
--- /dev/null
+++ b/cpukit/rtems/src/taskinitusers.c
@@ -0,0 +1,92 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/rtemsapi.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Initialize_user_tasks_body
+ *
+ * This routine creates and starts all configured user
+ * initialzation threads.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _RTEMS_tasks_Initialize_user_tasks_body( void )
+{
+ uint32_t index;
+ uint32_t maximum;
+ rtems_id id;
+ rtems_status_code return_value;
+ rtems_initialization_tasks_table *user_tasks;
+
+ /*
+ * Move information into local variables
+ */
+ user_tasks = Configuration_RTEMS_API.User_initialization_tasks_table;
+ maximum = Configuration_RTEMS_API.number_of_initialization_tasks;
+
+ /*
+ * Verify that we have a set of user tasks to iterate
+ */
+ if ( !user_tasks )
+ return;
+
+ /*
+ * Now iterate over the initialization tasks and create/start them.
+ */
+ for ( index=0 ; index < maximum ; index++ ) {
+ return_value = rtems_task_create(
+ user_tasks[ index ].name,
+ user_tasks[ index ].initial_priority,
+ user_tasks[ index ].stack_size,
+ user_tasks[ index ].mode_set,
+ user_tasks[ index ].attribute_set,
+ &id
+ );
+ if ( !rtems_is_status_successful( return_value ) )
+ _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, true, return_value );
+
+ return_value = rtems_task_start(
+ id,
+ user_tasks[ index ].entry_point,
+ user_tasks[ index ].argument
+ );
+ if ( !rtems_is_status_successful( return_value ) )
+ _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, true, return_value );
+ }
+}
diff --git a/cpukit/rtems/src/taskissuspended.c b/cpukit/rtems/src/taskissuspended.c
new file mode 100644
index 0000000000..eaea72160d
--- /dev/null
+++ b/cpukit/rtems/src/taskissuspended.c
@@ -0,0 +1,80 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_is_suspended
+ *
+ * This directive returns a status indicating whether or not
+ * the specified task is suspended.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful and not suspended
+ * RTEMS_ALREADY_SUSPENDED - if successful and suspended
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_is_suspended(
+ rtems_id id
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_States_Is_suspended( the_thread->current_state ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_ALREADY_SUSPENDED;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskmode.c b/cpukit/rtems/src/taskmode.c
new file mode 100644
index 0000000000..40a456f2be
--- /dev/null
+++ b/cpukit/rtems/src/taskmode.c
@@ -0,0 +1,125 @@
+/*
+ * RTEMS Task Manager - Change Task Mode
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*
+ * rtems_task_mode
+ *
+ * This directive enables and disables several modes of
+ * execution for the requesting thread.
+ *
+ * Input parameters:
+ * mode_set - new mode
+ * mask - mask
+ * previous_mode_set - address of previous mode set
+ *
+ * Output:
+ * *previous_mode_set - previous mode set
+ * always return RTEMS_SUCCESSFUL;
+ */
+
+rtems_status_code rtems_task_mode(
+ rtems_mode mode_set,
+ rtems_mode mask,
+ rtems_mode *previous_mode_set
+)
+{
+ Thread_Control *executing;
+ RTEMS_API_Control *api;
+ ASR_Information *asr;
+ bool is_asr_enabled = false;
+ bool needs_asr_dispatching = false;
+ rtems_mode old_mode;
+
+ if ( !previous_mode_set )
+ return RTEMS_INVALID_ADDRESS;
+
+ executing = _Thread_Executing;
+ api = executing->API_Extensions[ THREAD_API_RTEMS ];
+ asr = &api->Signal;
+
+ old_mode = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT;
+
+ if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE )
+ old_mode |= RTEMS_NO_TIMESLICE;
+ else
+ old_mode |= RTEMS_TIMESLICE;
+
+ old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR;
+ old_mode |= _ISR_Get_level();
+
+ *previous_mode_set = old_mode;
+
+ /*
+ * These are generic thread scheduling characteristics.
+ */
+ if ( mask & RTEMS_PREEMPT_MASK )
+ executing->is_preemptible = _Modes_Is_preempt(mode_set) ? true : false;
+
+ if ( mask & RTEMS_TIMESLICE_MASK ) {
+ if ( _Modes_Is_timeslice(mode_set) ) {
+ executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
+ executing->cpu_time_budget = _Thread_Ticks_per_timeslice;
+ } else
+ executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
+ }
+
+ /*
+ * Set the new interrupt level
+ */
+ if ( mask & RTEMS_INTERRUPT_MASK )
+ _Modes_Set_interrupt_level( mode_set );
+
+ /*
+ * This is specific to the RTEMS API
+ */
+ is_asr_enabled = false;
+ needs_asr_dispatching = false;
+
+ if ( mask & RTEMS_ASR_MASK ) {
+ is_asr_enabled = _Modes_Is_asr_disabled( mode_set ) ? false : true;
+ if ( is_asr_enabled != asr->is_enabled ) {
+ asr->is_enabled = is_asr_enabled;
+ _ASR_Swap_signals( asr );
+ if ( _ASR_Are_signals_pending( asr ) ) {
+ needs_asr_dispatching = true;
+ }
+ }
+ }
+
+ if ( _System_state_Is_up( _System_state_Get() ) ) {
+ if (_Thread_Evaluate_is_dispatch_needed( needs_asr_dispatching ) )
+ _Thread_Dispatch();
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/taskmp.c b/cpukit/rtems/src/taskmp.c
new file mode 100644
index 0000000000..5f13860492
--- /dev/null
+++ b/cpukit/rtems/src/taskmp.c
@@ -0,0 +1,343 @@
+/*
+ * Multiprocessing Support for the RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#include <rtems/score/object.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * _RTEMS_tasks_MP_Send_process_packet
+ *
+ */
+
+void _RTEMS_tasks_MP_Send_process_packet (
+ RTEMS_tasks_MP_Remote_operations operation,
+ Objects_Id task_id,
+ rtems_name name
+)
+{
+ RTEMS_tasks_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
+ case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
+
+ the_packet = _RTEMS_tasks_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_TASKS;
+ the_packet->Prefix.length = sizeof ( RTEMS_tasks_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( RTEMS_tasks_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = task_id;
+ the_packet->name = name;
+
+ _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
+ break;
+
+ case RTEMS_TASKS_MP_SUSPEND_REQUEST:
+ case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
+ case RTEMS_TASKS_MP_RESUME_REQUEST:
+ case RTEMS_TASKS_MP_RESUME_RESPONSE:
+ case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
+ case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
+ case RTEMS_TASKS_MP_GET_NOTE_REQUEST:
+ case RTEMS_TASKS_MP_GET_NOTE_RESPONSE:
+ case RTEMS_TASKS_MP_SET_NOTE_REQUEST:
+ case RTEMS_TASKS_MP_SET_NOTE_RESPONSE:
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_MP_Send_request_packet
+ *
+ */
+
+rtems_status_code _RTEMS_tasks_MP_Send_request_packet (
+ RTEMS_tasks_MP_Remote_operations operation,
+ Objects_Id task_id,
+ rtems_task_priority new_priority,
+ uint32_t notepad,
+ uint32_t note
+)
+{
+ RTEMS_tasks_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case RTEMS_TASKS_MP_SUSPEND_REQUEST:
+ case RTEMS_TASKS_MP_RESUME_REQUEST:
+ case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
+ case RTEMS_TASKS_MP_GET_NOTE_REQUEST:
+ case RTEMS_TASKS_MP_SET_NOTE_REQUEST:
+
+ the_packet = _RTEMS_tasks_MP_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_TASKS;
+ the_packet->Prefix.length = sizeof ( RTEMS_tasks_MP_Packet );
+ the_packet->Prefix.to_convert = sizeof ( RTEMS_tasks_MP_Packet );
+ the_packet->operation = operation;
+ the_packet->Prefix.id = task_id;
+ the_packet->the_priority = new_priority;
+ the_packet->notepad = notepad;
+ the_packet->note = note;
+
+ return _MPCI_Send_request_packet(
+ _Objects_Get_node( task_id ),
+ &the_packet->Prefix,
+ STATES_READY /* Not used */
+ );
+ break;
+
+ case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
+ case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
+ case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
+ case RTEMS_TASKS_MP_RESUME_RESPONSE:
+ case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
+ case RTEMS_TASKS_MP_GET_NOTE_RESPONSE:
+ case RTEMS_TASKS_MP_SET_NOTE_RESPONSE:
+ break;
+
+ }
+ /*
+ * The following line is included to satisfy compilers which
+ * produce warnings when a function does not end with a return.
+ */
+ return RTEMS_SUCCESSFUL;
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_MP_Send_response_packet
+ *
+ */
+
+void _RTEMS_tasks_MP_Send_response_packet (
+ RTEMS_tasks_MP_Remote_operations operation,
+ Thread_Control *the_thread
+)
+{
+ RTEMS_tasks_MP_Packet *the_packet;
+
+ switch ( operation ) {
+
+ case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
+ case RTEMS_TASKS_MP_RESUME_RESPONSE:
+ case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
+ case RTEMS_TASKS_MP_GET_NOTE_RESPONSE:
+ case RTEMS_TASKS_MP_SET_NOTE_RESPONSE:
+
+ the_packet = (RTEMS_tasks_MP_Packet *) the_thread->receive_packet;
+
+/*
+ * The packet being returned already contains the class, length, and
+ * to_convert fields, therefore they are not set in this routine.
+ */
+ the_packet->operation = operation;
+ the_packet->Prefix.id = the_packet->Prefix.source_tid;
+
+ _MPCI_Send_response_packet(
+ _Objects_Get_node( the_packet->Prefix.source_tid ),
+ &the_packet->Prefix
+ );
+ break;
+
+ case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
+ case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
+ case RTEMS_TASKS_MP_SUSPEND_REQUEST:
+ case RTEMS_TASKS_MP_RESUME_REQUEST:
+ case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
+ case RTEMS_TASKS_MP_GET_NOTE_REQUEST:
+ case RTEMS_TASKS_MP_SET_NOTE_REQUEST:
+ break;
+
+ }
+}
+
+/*PAGE
+ *
+ *
+ * _RTEMS_tasks_MP_Process_packet
+ *
+ */
+
+void _RTEMS_tasks_MP_Process_packet (
+ rtems_packet_prefix *the_packet_prefix
+)
+{
+ RTEMS_tasks_MP_Packet *the_packet;
+ Thread_Control *the_thread;
+ bool ignored;
+
+ the_packet = (RTEMS_tasks_MP_Packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
+
+ ignored = _Objects_MP_Allocate_and_open(
+ &_RTEMS_tasks_Information,
+ the_packet->name,
+ the_packet->Prefix.id,
+ true
+ );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
+
+ _Objects_MP_Close( &_RTEMS_tasks_Information, the_packet->Prefix.id );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case RTEMS_TASKS_MP_SUSPEND_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_task_suspend(
+ the_packet->Prefix.id
+ );
+
+ _RTEMS_tasks_MP_Send_response_packet(
+ RTEMS_TASKS_MP_SUSPEND_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+
+ case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
+ case RTEMS_TASKS_MP_RESUME_RESPONSE:
+ case RTEMS_TASKS_MP_SET_NOTE_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case RTEMS_TASKS_MP_RESUME_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_task_resume(
+ the_packet->Prefix.id
+ );
+
+ _RTEMS_tasks_MP_Send_response_packet(
+ RTEMS_TASKS_MP_RESUME_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+
+ case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_task_set_priority(
+ the_packet->Prefix.id,
+ the_packet->the_priority,
+ &the_packet->the_priority
+ );
+
+ _RTEMS_tasks_MP_Send_response_packet(
+ RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+
+ case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ *(rtems_task_priority *)the_thread->Wait.return_argument =
+ the_packet->the_priority;
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case RTEMS_TASKS_MP_GET_NOTE_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_task_get_note(
+ the_packet->Prefix.id,
+ the_packet->notepad,
+ &the_packet->note
+ );
+
+ _RTEMS_tasks_MP_Send_response_packet(
+ RTEMS_TASKS_MP_GET_NOTE_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+
+ case RTEMS_TASKS_MP_GET_NOTE_RESPONSE:
+
+ the_thread = _MPCI_Process_response( the_packet_prefix );
+
+ *(uint32_t *)the_thread->Wait.return_argument = the_packet->note;
+
+ _MPCI_Return_packet( the_packet_prefix );
+ break;
+
+ case RTEMS_TASKS_MP_SET_NOTE_REQUEST:
+
+ the_packet->Prefix.return_code = rtems_task_set_note(
+ the_packet->Prefix.id,
+ the_packet->notepad,
+ the_packet->note
+ );
+
+ _RTEMS_tasks_MP_Send_response_packet(
+ RTEMS_TASKS_MP_SET_NOTE_RESPONSE,
+ _Thread_Executing
+ );
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_MP_Send_object_was_deleted
+ *
+ * This routine is not neededby the Tasks since a task
+ * cannot be globally deleted.
+ *
+ */
+
+/*PAGE
+ *
+ * _RTEMS_tasks_MP_Send_extract_proxy
+ *
+ * This routine is not neededby the Tasks since a task
+ * cannot be globally deleted.
+ *
+ */
+
+/*PAGE
+ *
+ * _RTEMS_tasks_MP_Get_packet
+ *
+ */
+
+RTEMS_tasks_MP_Packet *_RTEMS_tasks_MP_Get_packet ( void )
+{
+ return (RTEMS_tasks_MP_Packet *) _MPCI_Get_packet();
+}
+
+/* end of file */
diff --git a/cpukit/rtems/src/taskrestart.c b/cpukit/rtems/src/taskrestart.c
new file mode 100644
index 0000000000..bc85137b23
--- /dev/null
+++ b/cpukit/rtems/src/taskrestart.c
@@ -0,0 +1,83 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_restart
+ *
+ * This directive readies the specified thread. It restores
+ * the thread environment to the original values established
+ * at thread creation and start time. A thread can be restarted
+ * from any state except the dormant state.
+ *
+ * Input parameters:
+ * id - thread id
+ * argument - thread argument
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_restart(
+ rtems_id id,
+ uint32_t argument
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( _Thread_Restart( the_thread, NULL, argument ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_INCORRECT_STATE;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskresume.c b/cpukit/rtems/src/taskresume.c
new file mode 100644
index 0000000000..1c6ef490b7
--- /dev/null
+++ b/cpukit/rtems/src/taskresume.c
@@ -0,0 +1,85 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_resume
+ *
+ * This directive will remove the specified thread
+ * from the suspended state.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_resume(
+ rtems_id id
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( _States_Is_suspended( the_thread->current_state ) ) {
+ _Thread_Resume( the_thread );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_INCORRECT_STATE;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _RTEMS_tasks_MP_Send_request_packet(
+ RTEMS_TASKS_MP_RESUME_REQUEST,
+ id,
+ 0, /* Not used */
+ 0, /* Not used */
+ 0 /* Not used */
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/tasks.c b/cpukit/rtems/src/tasks.c
new file mode 100644
index 0000000000..e81bf72167
--- /dev/null
+++ b/cpukit/rtems/src/tasks.c
@@ -0,0 +1,305 @@
+/*
+ * RTEMS Task Manager -- Initialize Manager
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Create_extension
+ *
+ * This routine is an extension routine that is invoked as part
+ * of creating any type of task or thread in the system. If the
+ * task is created via another API, then this routine is invoked
+ * and this API given the opportunity to initialize its extension
+ * area.
+ */
+
+bool _RTEMS_tasks_Create_extension(
+ Thread_Control *executing,
+ Thread_Control *created
+)
+{
+ RTEMS_API_Control *api;
+ int i;
+ size_t to_allocate;
+
+ /*
+ * Notepads must be the last entry in the structure and they
+ * can be left off if disabled in the configuration.
+ */
+ to_allocate = sizeof( RTEMS_API_Control );
+ if ( !rtems_configuration_get_notepads_enabled() )
+ to_allocate -= (RTEMS_NUMBER_NOTEPADS * sizeof(uint32_t));
+
+ api = _Workspace_Allocate( to_allocate );
+
+ if ( !api )
+ return false;
+
+ created->API_Extensions[ THREAD_API_RTEMS ] = api;
+
+ api->pending_events = EVENT_SETS_NONE_PENDING;
+ api->event_condition = 0;
+ _ASR_Initialize( &api->Signal );
+ created->task_variables = NULL;
+
+ if ( rtems_configuration_get_notepads_enabled() ) {
+ for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
+ api->Notepads[i] = 0;
+ }
+
+ return true;
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Start_extension
+ *
+ * This extension routine is invoked when a task is started for the
+ * first time.
+ */
+
+void _RTEMS_tasks_Start_extension(
+ Thread_Control *executing,
+ Thread_Control *started
+)
+{
+ RTEMS_API_Control *api;
+
+ api = started->API_Extensions[ THREAD_API_RTEMS ];
+
+ api->pending_events = EVENT_SETS_NONE_PENDING;
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Delete_extension
+ *
+ * This extension routine is invoked when a task is deleted.
+ */
+
+void _RTEMS_tasks_Delete_extension(
+ Thread_Control *executing,
+ Thread_Control *deleted
+)
+{
+ rtems_task_variable_t *tvp, *next;
+
+ /*
+ * Free per task variable memory
+ */
+
+ tvp = deleted->task_variables;
+ deleted->task_variables = NULL;
+ while (tvp) {
+ next = (rtems_task_variable_t *)tvp->next;
+ _RTEMS_Tasks_Invoke_task_variable_dtor( deleted, tvp );
+ tvp = next;
+ }
+
+ /*
+ * Free API specific memory
+ */
+
+ (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
+ deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Switch_extension
+ *
+ * This extension routine is invoked at each context switch.
+ */
+
+void _RTEMS_tasks_Switch_extension(
+ Thread_Control *executing,
+ Thread_Control *heir
+)
+{
+ rtems_task_variable_t *tvp;
+
+ /*
+ * Per Task Variables
+ */
+
+ tvp = executing->task_variables;
+ while (tvp) {
+ tvp->tval = *tvp->ptr;
+ *tvp->ptr = tvp->gval;
+ tvp = (rtems_task_variable_t *)tvp->next;
+ }
+
+ tvp = heir->task_variables;
+ while (tvp) {
+ tvp->gval = *tvp->ptr;
+ *tvp->ptr = tvp->tval;
+ tvp = (rtems_task_variable_t *)tvp->next;
+ }
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Post_switch_extension
+ *
+ * This extension routine is invoked at each context switch.
+ */
+
+void _RTEMS_tasks_Post_switch_extension(
+ Thread_Control *executing
+)
+{
+ ISR_Level level;
+ RTEMS_API_Control *api;
+ ASR_Information *asr;
+ rtems_signal_set signal_set;
+ Modes_Control prev_mode;
+
+ api = executing->API_Extensions[ THREAD_API_RTEMS ];
+ if ( !api )
+ return;
+
+ /*
+ * Signal Processing
+ */
+
+ asr = &api->Signal;
+
+ _ISR_Disable( level );
+ signal_set = asr->signals_posted;
+ asr->signals_posted = 0;
+ _ISR_Enable( level );
+
+
+ if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
+ return;
+
+ asr->nest_level += 1;
+ rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
+
+ (*asr->handler)( signal_set );
+
+ asr->nest_level -= 1;
+ rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
+
+}
+
+API_extensions_Control _RTEMS_tasks_API_extensions = {
+ { NULL, NULL },
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ NULL, /* predriver */
+ #endif
+ _RTEMS_tasks_Initialize_user_tasks, /* postdriver */
+ _RTEMS_tasks_Post_switch_extension /* post switch */
+};
+
+User_extensions_Control _RTEMS_tasks_User_extensions = {
+ { NULL, NULL },
+ { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
+ { _RTEMS_tasks_Create_extension, /* create */
+ _RTEMS_tasks_Start_extension, /* start */
+ _RTEMS_tasks_Start_extension, /* restart */
+ _RTEMS_tasks_Delete_extension, /* delete */
+ _RTEMS_tasks_Switch_extension, /* switch */
+ NULL, /* begin */
+ NULL, /* exitted */
+ NULL /* fatal */
+ }
+};
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Manager_initialization
+ *
+ * This routine initializes all Task Manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _RTEMS_tasks_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_RTEMS_tasks_Information, /* object information table */
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_TASKS, /* object class */
+ Configuration_RTEMS_API.maximum_tasks,
+ /* maximum objects of this class */
+ sizeof( Thread_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ true, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+
+ /*
+ * Add all the extensions for this API
+ */
+
+ _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
+
+ _API_extensions_Add( &_RTEMS_tasks_API_extensions );
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Register_packet_processor(
+ MP_PACKET_TASKS,
+ _RTEMS_tasks_MP_Process_packet
+ );
+#endif
+
+}
+
+/*PAGE
+ *
+ * _RTEMS_tasks_Initialize_user_tasks
+ *
+ * This routine creates and starts all configured user
+ * initialzation threads.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _RTEMS_tasks_Initialize_user_tasks( void )
+{
+ if ( _RTEMS_tasks_Initialize_user_tasks_p )
+ (*_RTEMS_tasks_Initialize_user_tasks_p)();
+}
diff --git a/cpukit/rtems/src/taskself.c b/cpukit/rtems/src/taskself.c
new file mode 100644
index 0000000000..e596c15c60
--- /dev/null
+++ b/cpukit/rtems/src/taskself.c
@@ -0,0 +1,24 @@
+/*
+ * RTEMS Task Manager - Get ID of Self
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+
+rtems_id rtems_task_self(void)
+{
+ return _Thread_Executing->Object.id;
+}
diff --git a/cpukit/rtems/src/tasksetnote.c b/cpukit/rtems/src/tasksetnote.c
new file mode 100644
index 0000000000..cd2bfb6dd1
--- /dev/null
+++ b/cpukit/rtems/src/tasksetnote.c
@@ -0,0 +1,109 @@
+/*
+ * RTEMS Task Manager
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_set_note
+ *
+ * This directive sets the specified notepad contents to the given
+ * note.
+ *
+ * Input parameters:
+ * id - thread id
+ * notepad - notepad number
+ * note - note value
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_set_note(
+ rtems_id id,
+ uint32_t notepad,
+ uint32_t note
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+ RTEMS_API_Control *api;
+
+ if ( !rtems_configuration_get_notepads_enabled() )
+ return RTEMS_NOT_CONFIGURED;
+
+ /*
+ * NOTE: There is no check for < RTEMS_NOTEPAD_FIRST because that would
+ * be checking an unsigned number for being negative.
+ */
+
+ if ( notepad > RTEMS_NOTEPAD_LAST )
+ return RTEMS_INVALID_NUMBER;
+
+ /*
+ * Optimize the most likely case to avoid the Thread_Dispatch.
+ */
+
+ if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ||
+ _Objects_Are_ids_equal( id, _Thread_Executing->Object.id ) ) {
+ api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ];
+ api->Notepads[ notepad ] = note;
+ return RTEMS_SUCCESSFUL;
+ }
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
+ api->Notepads[ notepad ] = note;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _RTEMS_tasks_MP_Send_request_packet(
+ RTEMS_TASKS_MP_SET_NOTE_REQUEST,
+ id,
+ 0, /* Not used */
+ notepad,
+ note
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/tasksetpriority.c b/cpukit/rtems/src/tasksetpriority.c
new file mode 100644
index 0000000000..4e85e56533
--- /dev/null
+++ b/cpukit/rtems/src/tasksetpriority.c
@@ -0,0 +1,102 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_set_priority
+ *
+ * This directive changes the priority of the specified thread.
+ * The specified thread can be any thread in the system including
+ * the requesting thread.
+ *
+ * Input parameters:
+ * id - thread id (0 indicates requesting thread)
+ * new_priority - thread priority (0 indicates current priority)
+ * old_priority - pointer to previous priority
+ *
+ * Output parameters:
+ * old_priority - previous priority
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_set_priority(
+ rtems_id id,
+ rtems_task_priority new_priority,
+ rtems_task_priority *old_priority
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+
+ if ( new_priority != RTEMS_CURRENT_PRIORITY &&
+ !_RTEMS_tasks_Priority_is_valid( new_priority ) )
+ return RTEMS_INVALID_PRIORITY;
+
+ if ( !old_priority )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ /* XXX need helper to "convert" from core priority */
+ *old_priority = the_thread->current_priority;
+ if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
+ the_thread->real_priority = new_priority;
+ if ( the_thread->resource_count == 0 ||
+ the_thread->current_priority > new_priority )
+ _Thread_Change_priority( the_thread, new_priority, false );
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Executing->Wait.return_argument = old_priority;
+ return _RTEMS_tasks_MP_Send_request_packet(
+ RTEMS_TASKS_MP_SET_PRIORITY_REQUEST,
+ id,
+ new_priority,
+ 0, /* Not used */
+ 0 /* Not used */
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskstart.c b/cpukit/rtems/src/taskstart.c
new file mode 100644
index 0000000000..9d2ce0cec4
--- /dev/null
+++ b/cpukit/rtems/src/taskstart.c
@@ -0,0 +1,88 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_start
+ *
+ * This directive readies the thread identified by the "id"
+ * based on its current priorty, to await execution. A thread
+ * can be started only from the dormant state.
+ *
+ * Input parameters:
+ * id - thread id
+ * entry_point - start execution address of thread
+ * argument - thread argument
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_start(
+ rtems_id id,
+ rtems_task_entry entry_point,
+ rtems_task_argument argument
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+
+ if ( entry_point == NULL )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( _Thread_Start(
+ the_thread, THREAD_START_NUMERIC, entry_point, NULL, argument ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_INCORRECT_STATE;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/tasksuspend.c b/cpukit/rtems/src/tasksuspend.c
new file mode 100644
index 0000000000..3f7e8b7d03
--- /dev/null
+++ b/cpukit/rtems/src/tasksuspend.c
@@ -0,0 +1,86 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_suspend
+ *
+ * This directive will place the specified thread in the "suspended"
+ * state. Note that the suspended state can be in addition to
+ * other waiting states.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_suspend(
+ rtems_id id
+)
+{
+ register Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_States_Is_suspended( the_thread->current_state ) ) {
+ _Thread_Suspend( the_thread );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_ALREADY_SUSPENDED;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ return _RTEMS_tasks_MP_Send_request_packet(
+ RTEMS_TASKS_MP_SUSPEND_REQUEST,
+ id,
+ 0, /* Not used */
+ 0, /* Not used */
+ 0 /* Not used */
+ );
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskvariable_invoke_dtor.c b/cpukit/rtems/src/taskvariable_invoke_dtor.c
new file mode 100644
index 0000000000..d348c6d90e
--- /dev/null
+++ b/cpukit/rtems/src/taskvariable_invoke_dtor.c
@@ -0,0 +1,43 @@
+/*
+ * Invoke the destructor on a per-task variable
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/wkspace.h>
+
+void _RTEMS_Tasks_Invoke_task_variable_dtor(
+ Thread_Control *the_thread,
+ rtems_task_variable_t *tvp
+)
+{
+ void (*dtor)(void *);
+ void *value;
+
+ dtor = tvp->dtor;
+ if (_Thread_Is_executing(the_thread)) {
+ value = *tvp->ptr;
+ *tvp->ptr = tvp->gval;
+ } else {
+ value = tvp->tval;
+ }
+
+ if ( dtor )
+ (*dtor)(value);
+
+ _Workspace_Free(tvp);
+}
diff --git a/cpukit/rtems/src/taskvariableadd.c b/cpukit/rtems/src/taskvariableadd.c
new file mode 100644
index 0000000000..41d6bed57c
--- /dev/null
+++ b/cpukit/rtems/src/taskvariableadd.c
@@ -0,0 +1,87 @@
+/*
+ * rtems_task_variable_add - Add a per-task variable
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * rtems_task_variable_add
+ *
+ * This directive registers a task variable.
+ */
+
+rtems_status_code rtems_task_variable_add(
+ rtems_id tid,
+ void **ptr,
+ void (*dtor)(void *)
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+ rtems_task_variable_t *tvp, *new;
+
+ if ( !ptr )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_thread = _Thread_Get (tid, &location);
+ switch (location) {
+
+ case OBJECTS_LOCAL:
+ /*
+ * Figure out if the variable is already in this task's list.
+ */
+ tvp = the_thread->task_variables;
+ while (tvp) {
+ if (tvp->ptr == ptr) {
+ tvp->dtor = dtor;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ tvp = (rtems_task_variable_t *)tvp->next;
+ }
+
+ /*
+ * Now allocate memory for this task variable.
+ */
+ new = (rtems_task_variable_t *)
+ _Workspace_Allocate(sizeof(rtems_task_variable_t));
+ if (new == NULL) {
+ _Thread_Enable_dispatch();
+ return RTEMS_NO_MEMORY;
+ }
+ new->gval = *ptr;
+ new->ptr = ptr;
+ new->dtor = dtor;
+
+ new->next = (struct rtems_task_variable_tt *)the_thread->task_variables;
+ the_thread->task_variables = new;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskvariabledelete.c b/cpukit/rtems/src/taskvariabledelete.c
new file mode 100644
index 0000000000..fe34732f57
--- /dev/null
+++ b/cpukit/rtems/src/taskvariabledelete.c
@@ -0,0 +1,76 @@
+/*
+ * rtems_task_variable_delete - Delete a per-task variable
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * rtems_task_variable_delete
+ *
+ * This directive removes a task variable.
+ */
+
+rtems_status_code rtems_task_variable_delete(
+ rtems_id tid,
+ void **ptr
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+ rtems_task_variable_t *tvp, *prev;
+
+ if ( !ptr )
+ return RTEMS_INVALID_ADDRESS;
+
+ prev = NULL;
+
+ the_thread = _Thread_Get (tid, &location);
+ switch (location) {
+
+ case OBJECTS_LOCAL:
+ tvp = the_thread->task_variables;
+ while (tvp) {
+ if (tvp->ptr == ptr) {
+ if (prev)
+ prev->next = tvp->next;
+ else
+ the_thread->task_variables = (rtems_task_variable_t *)tvp->next;
+
+ _RTEMS_Tasks_Invoke_task_variable_dtor( the_thread, tvp );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ prev = tvp;
+ tvp = (rtems_task_variable_t *)tvp->next;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_INVALID_ADDRESS;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskvariableget.c b/cpukit/rtems/src/taskvariableget.c
new file mode 100644
index 0000000000..fbe3b10d7f
--- /dev/null
+++ b/cpukit/rtems/src/taskvariableget.c
@@ -0,0 +1,78 @@
+/*
+ * rtems_task_variable_get - Get a per-task variable
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * rtems_task_variable_get
+ *
+ * This directive gets the value of a task variable.
+ */
+
+rtems_status_code rtems_task_variable_get(
+ rtems_id tid,
+ void **ptr,
+ void **result
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+ rtems_task_variable_t *tvp;
+
+ if ( !ptr )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !result )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_thread = _Thread_Get (tid, &location);
+ switch (location) {
+
+ case OBJECTS_LOCAL:
+ /*
+ * Figure out if the variable is in this task's list.
+ */
+ tvp = the_thread->task_variables;
+ while (tvp) {
+ if (tvp->ptr == ptr) {
+ /*
+ * Should this return the current (i.e not the
+ * saved) value if `tid' is the current task?
+ */
+ *result = tvp->tval;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+ tvp = (rtems_task_variable_t *)tvp->next;
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_INVALID_ADDRESS;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ _Thread_Dispatch();
+ return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+#endif
+
+ case OBJECTS_ERROR:
+ break;
+ }
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/taskwakeafter.c b/cpukit/rtems/src/taskwakeafter.c
new file mode 100644
index 0000000000..2f6fecfe5d
--- /dev/null
+++ b/cpukit/rtems/src/taskwakeafter.c
@@ -0,0 +1,69 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/score/object.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_wake_after
+ *
+ * This directive suspends the requesting thread for the given amount
+ * of ticks.
+ *
+ * Input parameters:
+ * ticks - number of ticks to wait
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - always successful
+ */
+
+rtems_status_code rtems_task_wake_after(
+ rtems_interval ticks
+)
+{
+ _Thread_Disable_dispatch();
+ if ( ticks == 0 ) {
+ _Scheduler_Yield();
+ } else {
+ _Thread_Set_state( _Thread_Executing, STATES_DELAYING );
+ _Watchdog_Initialize(
+ &_Thread_Executing->Timer,
+ _Thread_Delay_ended,
+ _Thread_Executing->Object.id,
+ NULL
+ );
+ _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks );
+ }
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/taskwakewhen.c b/cpukit/rtems/src/taskwakewhen.c
new file mode 100644
index 0000000000..5496f55a73
--- /dev/null
+++ b/cpukit/rtems/src/taskwakewhen.c
@@ -0,0 +1,87 @@
+/*
+ * RTEMS Task Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/rtems/modes.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/object.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/sysstate.h>
+
+/*PAGE
+ *
+ * rtems_task_wake_when
+ *
+ * This directive blocks the requesting thread until the given date and
+ * time is reached.
+ *
+ * Input parameters:
+ * time_buffer - pointer to the time and date structure
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_task_wake_when(
+ rtems_time_of_day *time_buffer
+)
+{
+ Watchdog_Interval seconds;
+
+ if ( !_TOD_Is_set )
+ return RTEMS_NOT_DEFINED;
+
+ if ( !time_buffer )
+ return RTEMS_INVALID_ADDRESS;
+
+ time_buffer->ticks = 0;
+
+ if ( !_TOD_Validate( time_buffer ) )
+ return RTEMS_INVALID_CLOCK;
+
+ seconds = _TOD_To_seconds( time_buffer );
+
+ if ( seconds <= _TOD_Seconds_since_epoch() )
+ return RTEMS_INVALID_CLOCK;
+
+ _Thread_Disable_dispatch();
+ _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME );
+ _Watchdog_Initialize(
+ &_Thread_Executing->Timer,
+ _Thread_Delay_ended,
+ _Thread_Executing->Object.id,
+ NULL
+ );
+ _Watchdog_Insert_seconds(
+ &_Thread_Executing->Timer,
+ seconds - _TOD_Seconds_since_epoch()
+ );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/timercancel.c b/cpukit/rtems/src/timercancel.c
new file mode 100644
index 0000000000..abab3f424c
--- /dev/null
+++ b/cpukit/rtems/src/timercancel.c
@@ -0,0 +1,66 @@
+/*
+ * Timer Manager - rtems_timer_cancel directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_cancel
+ *
+ * This directive allows a thread to cancel a timer.
+ *
+ * Input parameters:
+ * id - timer id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_cancel(
+ rtems_id id
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( !_Timer_Is_dormant_class( the_timer->the_class ) )
+ (void) _Watchdog_Remove( &the_timer->Ticker );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timercreate.c b/cpukit/rtems/src/timercreate.c
new file mode 100644
index 0000000000..e277768933
--- /dev/null
+++ b/cpukit/rtems/src/timercreate.c
@@ -0,0 +1,78 @@
+/*
+ * Timer Manager - rtems_timer_create directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2002.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_create
+ *
+ * This directive creates a timer and performs some initialization.
+ *
+ * Input parameters:
+ * name - timer name
+ * id - pointer to timer id
+ *
+ * Output parameters:
+ * id - timer id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_create(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Timer_Control *the_timer;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ _Thread_Disable_dispatch(); /* to prevent deletion */
+
+ the_timer = _Timer_Allocate();
+
+ if ( !the_timer ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+ the_timer->the_class = TIMER_DORMANT;
+ _Watchdog_Initialize( &the_timer->Ticker, NULL, 0, NULL );
+
+ _Objects_Open(
+ &_Timer_Information,
+ &the_timer->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_timer->Object.id;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/timerdelete.c b/cpukit/rtems/src/timerdelete.c
new file mode 100644
index 0000000000..7dbc812a2e
--- /dev/null
+++ b/cpukit/rtems/src/timerdelete.c
@@ -0,0 +1,67 @@
+/*
+ * Timer Manager - rtems_timer_delete directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_delete
+ *
+ * This directive allows a thread to delete a timer.
+ *
+ * Input parameters:
+ * id - timer id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_delete(
+ rtems_id id
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Objects_Close( &_Timer_Information, &the_timer->Object );
+ (void) _Watchdog_Remove( &the_timer->Ticker );
+ _Timer_Free( the_timer );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timerfireafter.c b/cpukit/rtems/src/timerfireafter.c
new file mode 100644
index 0000000000..540ede38ad
--- /dev/null
+++ b/cpukit/rtems/src/timerfireafter.c
@@ -0,0 +1,103 @@
+/*
+ * Timer Manager - rtems_timer_fire_after directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_fire_after
+ *
+ * This directive allows a thread to start a timer.
+ *
+ * Input parameters:
+ * id - timer id
+ * ticks - interval until routine is fired
+ * routine - routine to schedule
+ * user_data - passed as argument to routine when it is fired
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_fire_after(
+ rtems_id id,
+ rtems_interval ticks,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+ ISR_Level level;
+
+ if ( ticks == 0 )
+ return RTEMS_INVALID_NUMBER;
+
+ if ( !routine )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ (void) _Watchdog_Remove( &the_timer->Ticker );
+
+ _ISR_Disable( level );
+
+ /*
+ * Check to see if the watchdog has just been inserted by a
+ * higher priority interrupt. If so, abandon this insert.
+ */
+
+ if ( the_timer->Ticker.state != WATCHDOG_INACTIVE ) {
+ _ISR_Enable( level );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+
+ /*
+ * OK. Now we now the timer was not rescheduled by an interrupt
+ * so we can atomically initialize it as in use.
+ */
+
+ the_timer->the_class = TIMER_INTERVAL;
+ _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
+ _ISR_Enable( level );
+
+
+ _Watchdog_Insert_ticks( &the_timer->Ticker, ticks );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timerfirewhen.c b/cpukit/rtems/src/timerfirewhen.c
new file mode 100644
index 0000000000..670b39ec1b
--- /dev/null
+++ b/cpukit/rtems/src/timerfirewhen.c
@@ -0,0 +1,91 @@
+/*
+ * Timer Manager - rtems_timer_fire_when directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_fire_when
+ *
+ * This directive allows a thread to start a timer.
+ *
+ * Input parameters:
+ * id - timer id
+ * wall_time - time of day to fire timer
+ * routine - routine to schedule
+ * user_data - passed as argument to routine when it is fired
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_fire_when(
+ rtems_id id,
+ rtems_time_of_day *wall_time,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+ rtems_interval seconds;
+
+ if ( !_TOD_Is_set )
+ return RTEMS_NOT_DEFINED;
+
+ if ( !_TOD_Validate( wall_time ) )
+ return RTEMS_INVALID_CLOCK;
+
+ if ( !routine )
+ return RTEMS_INVALID_ADDRESS;
+
+ seconds = _TOD_To_seconds( wall_time );
+ if ( seconds <= _TOD_Seconds_since_epoch() )
+ return RTEMS_INVALID_CLOCK;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ (void) _Watchdog_Remove( &the_timer->Ticker );
+ the_timer->the_class = TIMER_TIME_OF_DAY;
+ _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
+ _Watchdog_Insert_seconds(
+ &the_timer->Ticker,
+ seconds - _TOD_Seconds_since_epoch()
+ );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timergetinfo.c b/cpukit/rtems/src/timergetinfo.c
new file mode 100644
index 0000000000..2b648597fe
--- /dev/null
+++ b/cpukit/rtems/src/timergetinfo.c
@@ -0,0 +1,75 @@
+/*
+ * Timer Manager - rtems_timer_get_information directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_get_information
+ *
+ * This directive allows a thread to obtain information about a timer.
+ *
+ * Input parameters:
+ * id - timer id
+ * the_info - pointer to timer information block
+ *
+ * Output parameters:
+ * *the_info - region information block filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ *
+ */
+
+rtems_status_code rtems_timer_get_information(
+ rtems_id id,
+ rtems_timer_information *the_info
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+
+ if ( !the_info )
+ return RTEMS_INVALID_ADDRESS;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ the_info->the_class = the_timer->the_class;
+ the_info->initial = the_timer->Ticker.initial;
+ the_info->start_time = the_timer->Ticker.start_time;
+ the_info->stop_time = the_timer->Ticker.stop_time;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timerident.c b/cpukit/rtems/src/timerident.c
new file mode 100644
index 0000000000..1f1ebbcd7d
--- /dev/null
+++ b/cpukit/rtems/src/timerident.c
@@ -0,0 +1,60 @@
+/*
+ * Timer Manager - rtems_timer_ident directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2002.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_ident
+ *
+ * This directive returns the system ID associated with
+ * the timer name.
+ *
+ * Input parameters:
+ * name - user defined message queue name
+ * id - pointer to timer id
+ *
+ * Output parameters:
+ * *id - message queue id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_ident(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Timer_Information,
+ name,
+ OBJECTS_SEARCH_LOCAL_NODE,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/rtems/src/timerreset.c b/cpukit/rtems/src/timerreset.c
new file mode 100644
index 0000000000..4a3e094a08
--- /dev/null
+++ b/cpukit/rtems/src/timerreset.c
@@ -0,0 +1,93 @@
+/*
+ * Timer Manager - rtems_timer_reset directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_reset
+ *
+ * This directive allows a thread to reset a timer.
+ *
+ * Input parameters:
+ * id - timer id
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_reset(
+ rtems_id id
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+ rtems_status_code status = RTEMS_SUCCESSFUL;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ if ( the_timer->the_class == TIMER_INTERVAL ) {
+ _Watchdog_Remove( &the_timer->Ticker );
+ _Watchdog_Insert( &_Watchdog_Ticks_chain, &the_timer->Ticker );
+ } else if ( the_timer->the_class == TIMER_INTERVAL_ON_TASK ) {
+ Timer_server_Control *timer_server = _Timer_server;
+
+ /*
+ * There is no way for a timer to have this class unless
+ * it was scheduled as a server fire. That requires that
+ * the Timer Server be initiated. So this error cannot
+ * occur unless something is internally wrong.
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( !timer_server ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_INCORRECT_STATE;
+ }
+ #endif
+ _Watchdog_Remove( &the_timer->Ticker );
+ (*timer_server->schedule_operation)( timer_server, the_timer );
+ } else {
+ /*
+ * Must be dormant or time of day timer (e.g. TIMER_DORMANT,
+ * TIMER_TIME_OF_DAY, or TIMER_TIME_OF_DAY_ON_TASK). We
+ * can only reset active interval timers.
+ */
+ status = RTEMS_NOT_DEFINED;
+ }
+ _Thread_Enable_dispatch();
+ return status;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timerserver.c b/cpukit/rtems/src/timerserver.c
new file mode 100644
index 0000000000..9f8da0d5c3
--- /dev/null
+++ b/cpukit/rtems/src/timerserver.c
@@ -0,0 +1,583 @@
+/**
+ * @file timerserver.c
+ *
+ * Timer Manager - rtems_timer_initiate_server directive along with
+ * the Timer Server Body and support routines
+ *
+ * @note Data specific to the Timer Server is declared in this
+ * file as the Timer Server so it does not have to be in the
+ * minimum footprint. It is only really required when
+ * task-based timers are used. Since task-based timers can
+ * not be started until the server is initiated, this structure
+ * does not have to be initialized until then.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+#include <rtems/rtems/tasks.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/thread.h>
+
+static Timer_server_Control _Timer_server_Default;
+
+static void _Timer_server_Stop_interval_system_watchdog(
+ Timer_server_Control *ts
+)
+{
+ _Watchdog_Remove( &ts->Interval_watchdogs.System_watchdog );
+}
+
+static void _Timer_server_Reset_interval_system_watchdog(
+ Timer_server_Control *ts
+)
+{
+ ISR_Level level;
+
+ _Timer_server_Stop_interval_system_watchdog( ts );
+
+ _ISR_Disable( level );
+ if ( !_Chain_Is_empty( &ts->Interval_watchdogs.Chain ) ) {
+ Watchdog_Interval delta_interval =
+ _Watchdog_First( &ts->Interval_watchdogs.Chain )->delta_interval;
+ _ISR_Enable( level );
+
+ /*
+ * The unit is TICKS here.
+ */
+ _Watchdog_Insert_ticks(
+ &ts->Interval_watchdogs.System_watchdog,
+ delta_interval
+ );
+ } else {
+ _ISR_Enable( level );
+ }
+}
+
+static void _Timer_server_Stop_tod_system_watchdog(
+ Timer_server_Control *ts
+)
+{
+ _Watchdog_Remove( &ts->TOD_watchdogs.System_watchdog );
+}
+
+static void _Timer_server_Reset_tod_system_watchdog(
+ Timer_server_Control *ts
+)
+{
+ ISR_Level level;
+
+ _Timer_server_Stop_tod_system_watchdog( ts );
+
+ _ISR_Disable( level );
+ if ( !_Chain_Is_empty( &ts->TOD_watchdogs.Chain ) ) {
+ Watchdog_Interval delta_interval =
+ _Watchdog_First( &ts->TOD_watchdogs.Chain )->delta_interval;
+ _ISR_Enable( level );
+
+ /*
+ * The unit is SECONDS here.
+ */
+ _Watchdog_Insert_seconds(
+ &ts->TOD_watchdogs.System_watchdog,
+ delta_interval
+ );
+ } else {
+ _ISR_Enable( level );
+ }
+}
+
+static void _Timer_server_Insert_timer(
+ Timer_server_Control *ts,
+ Timer_Control *timer
+)
+{
+ if ( timer->the_class == TIMER_INTERVAL_ON_TASK ) {
+ _Watchdog_Insert( &ts->Interval_watchdogs.Chain, &timer->Ticker );
+ } else if ( timer->the_class == TIMER_TIME_OF_DAY_ON_TASK ) {
+ _Watchdog_Insert( &ts->TOD_watchdogs.Chain, &timer->Ticker );
+ }
+}
+
+static void _Timer_server_Insert_timer_and_make_snapshot(
+ Timer_server_Control *ts,
+ Timer_Control *timer
+)
+{
+ Watchdog_Control *first_watchdog;
+ Watchdog_Interval delta_interval;
+ Watchdog_Interval last_snapshot;
+ Watchdog_Interval snapshot;
+ Watchdog_Interval delta;
+ ISR_Level level;
+
+ /*
+ * We have to update the time snapshots here, because otherwise we may have
+ * problems with the integer range of the delta values. The time delta DT
+ * from the last snapshot to now may be arbitrarily long. The last snapshot
+ * is the reference point for the delta chain. Thus if we do not update the
+ * reference point we have to add DT to the initial delta of the watchdog
+ * being inserted. This could result in an integer overflow.
+ */
+
+ _Thread_Disable_dispatch();
+
+ if ( timer->the_class == TIMER_INTERVAL_ON_TASK ) {
+ /*
+ * We have to advance the last known ticks value of the server and update
+ * the watchdog chain accordingly.
+ */
+ _ISR_Disable( level );
+ snapshot = _Watchdog_Ticks_since_boot;
+ last_snapshot = ts->Interval_watchdogs.last_snapshot;
+ if ( !_Chain_Is_empty( &ts->Interval_watchdogs.Chain ) ) {
+ first_watchdog = _Watchdog_First( &ts->Interval_watchdogs.Chain );
+
+ /*
+ * We assume adequate unsigned arithmetic here.
+ */
+ delta = snapshot - last_snapshot;
+
+ delta_interval = first_watchdog->delta_interval;
+ if (delta_interval > delta) {
+ delta_interval -= delta;
+ } else {
+ delta_interval = 0;
+ }
+ first_watchdog->delta_interval = delta_interval;
+ }
+ ts->Interval_watchdogs.last_snapshot = snapshot;
+ _ISR_Enable( level );
+
+ _Watchdog_Insert( &ts->Interval_watchdogs.Chain, &timer->Ticker );
+
+ if ( !ts->active ) {
+ _Timer_server_Reset_interval_system_watchdog( ts );
+ }
+ } else if ( timer->the_class == TIMER_TIME_OF_DAY_ON_TASK ) {
+ /*
+ * We have to advance the last known seconds value of the server and update
+ * the watchdog chain accordingly.
+ */
+ _ISR_Disable( level );
+ snapshot = (Watchdog_Interval) _TOD_Seconds_since_epoch();
+ last_snapshot = ts->TOD_watchdogs.last_snapshot;
+ if ( !_Chain_Is_empty( &ts->TOD_watchdogs.Chain ) ) {
+ first_watchdog = _Watchdog_First( &ts->TOD_watchdogs.Chain );
+ delta_interval = first_watchdog->delta_interval;
+ if ( snapshot > last_snapshot ) {
+ /*
+ * We advanced in time.
+ */
+ delta = snapshot - last_snapshot;
+ if (delta_interval > delta) {
+ delta_interval -= delta;
+ } else {
+ delta_interval = 0;
+ }
+ } else {
+ /*
+ * Someone put us in the past.
+ */
+ delta = last_snapshot - snapshot;
+ delta_interval += delta;
+ }
+ first_watchdog->delta_interval = delta_interval;
+ }
+ ts->TOD_watchdogs.last_snapshot = snapshot;
+ _ISR_Enable( level );
+
+ _Watchdog_Insert( &ts->TOD_watchdogs.Chain, &timer->Ticker );
+
+ if ( !ts->active ) {
+ _Timer_server_Reset_tod_system_watchdog( ts );
+ }
+ }
+
+ _Thread_Enable_dispatch();
+}
+
+static void _Timer_server_Schedule_operation_method(
+ Timer_server_Control *ts,
+ Timer_Control *timer
+)
+{
+ if ( ts->insert_chain == NULL ) {
+ _Timer_server_Insert_timer_and_make_snapshot( ts, timer );
+ } else {
+ /*
+ * We interrupted a critical section of the timer server. The timer
+ * server is not preemptible, so we must be in interrupt context here. No
+ * thread dispatch will happen until the timer server finishes its
+ * critical section. We have to use the protected chain methods because
+ * we may be interrupted by a higher priority interrupt.
+ */
+ _Chain_Append( ts->insert_chain, &timer->Object.Node );
+ }
+}
+
+static void _Timer_server_Process_interval_watchdogs(
+ Timer_server_Watchdogs *watchdogs,
+ Chain_Control *fire_chain
+)
+{
+ Watchdog_Interval snapshot = _Watchdog_Ticks_since_boot;
+
+ /*
+ * We assume adequate unsigned arithmetic here.
+ */
+ Watchdog_Interval delta = snapshot - watchdogs->last_snapshot;
+
+ watchdogs->last_snapshot = snapshot;
+
+ _Watchdog_Adjust_to_chain( &watchdogs->Chain, delta, fire_chain );
+}
+
+static void _Timer_server_Process_tod_watchdogs(
+ Timer_server_Watchdogs *watchdogs,
+ Chain_Control *fire_chain
+)
+{
+ Watchdog_Interval snapshot = (Watchdog_Interval) _TOD_Seconds_since_epoch();
+ Watchdog_Interval last_snapshot = watchdogs->last_snapshot;
+ Watchdog_Interval delta;
+
+ /*
+ * Process the seconds chain. Start by checking that the Time
+ * of Day (TOD) has not been set backwards. If it has then
+ * we want to adjust the watchdogs->Chain to indicate this.
+ */
+ if ( snapshot > last_snapshot ) {
+ /*
+ * This path is for normal forward movement and cases where the
+ * TOD has been set forward.
+ */
+ delta = snapshot - last_snapshot;
+ _Watchdog_Adjust_to_chain( &watchdogs->Chain, delta, fire_chain );
+
+ } else if ( snapshot < last_snapshot ) {
+ /*
+ * The current TOD is before the last TOD which indicates that
+ * TOD has been set backwards.
+ */
+ delta = last_snapshot - snapshot;
+ _Watchdog_Adjust( &watchdogs->Chain, WATCHDOG_BACKWARD, delta );
+ }
+
+ watchdogs->last_snapshot = snapshot;
+}
+
+static void _Timer_server_Process_insertions( Timer_server_Control *ts )
+{
+ while ( true ) {
+ Timer_Control *timer = (Timer_Control *) _Chain_Get( ts->insert_chain );
+
+ if ( timer == NULL ) {
+ break;
+ }
+
+ _Timer_server_Insert_timer( ts, timer );
+ }
+}
+
+static void _Timer_server_Get_watchdogs_that_fire_now(
+ Timer_server_Control *ts,
+ Chain_Control *insert_chain,
+ Chain_Control *fire_chain
+)
+{
+ /*
+ * Afterwards all timer inserts are directed to this chain and the interval
+ * and TOD chains will be no more modified by other parties.
+ */
+ ts->insert_chain = insert_chain;
+
+ while ( true ) {
+ ISR_Level level;
+
+ /*
+ * Remove all the watchdogs that need to fire so we can invoke them.
+ */
+ _Timer_server_Process_interval_watchdogs(
+ &ts->Interval_watchdogs,
+ fire_chain
+ );
+ _Timer_server_Process_tod_watchdogs( &ts->TOD_watchdogs, fire_chain );
+
+ /*
+ * The insertions have to take place here, because they reference the
+ * current time. The previous process methods take a snapshot of the
+ * current time. In case someone inserts a watchdog with an initial value
+ * of zero it will be processed in the next iteration of the timer server
+ * body loop.
+ */
+ _Timer_server_Process_insertions( ts );
+
+ _ISR_Disable( level );
+ if ( _Chain_Is_empty( insert_chain ) ) {
+ ts->insert_chain = NULL;
+ _ISR_Enable( level );
+
+ break;
+ } else {
+ _ISR_Enable( level );
+ }
+ }
+}
+
+/**
+ * @brief Timer server body.
+ *
+ * This is the server for task based timers. This task executes whenever a
+ * task-based timer should fire. It services both "after" and "when" timers.
+ * It is not created automatically but must be created explicitly by the
+ * application before task-based timers may be initiated. The parameter
+ * @a arg points to the corresponding timer server control block.
+ */
+static rtems_task _Timer_server_Body(
+ rtems_task_argument arg
+)
+{
+ Timer_server_Control *ts = (Timer_server_Control *) arg;
+ Chain_Control insert_chain;
+ Chain_Control fire_chain;
+
+ _Chain_Initialize_empty( &insert_chain );
+ _Chain_Initialize_empty( &fire_chain );
+
+ while ( true ) {
+ _Timer_server_Get_watchdogs_that_fire_now( ts, &insert_chain, &fire_chain );
+
+ if ( !_Chain_Is_empty( &fire_chain ) ) {
+ /*
+ * Fire the watchdogs.
+ */
+ while ( true ) {
+ Watchdog_Control *watchdog;
+ ISR_Level level;
+
+ /*
+ * It is essential that interrupts are disable here since an interrupt
+ * service routine may remove a watchdog from the chain.
+ */
+ _ISR_Disable( level );
+ watchdog = (Watchdog_Control *) _Chain_Get_unprotected( &fire_chain );
+ if ( watchdog != NULL ) {
+ watchdog->state = WATCHDOG_INACTIVE;
+ _ISR_Enable( level );
+ } else {
+ _ISR_Enable( level );
+
+ break;
+ }
+
+ /*
+ * The timer server may block here and wait for resources or time.
+ * The system watchdogs are inactive and will remain inactive since
+ * the active flag of the timer server is true.
+ */
+ (*watchdog->routine)( watchdog->id, watchdog->user_data );
+ }
+ } else {
+ ts->active = false;
+
+ /*
+ * Block until there is something to do.
+ */
+ _Thread_Disable_dispatch();
+ _Thread_Set_state( ts->thread, STATES_DELAYING );
+ _Timer_server_Reset_interval_system_watchdog( ts );
+ _Timer_server_Reset_tod_system_watchdog( ts );
+ _Thread_Enable_dispatch();
+
+ ts->active = true;
+
+ /*
+ * Maybe an interrupt did reset the system timers, so we have to stop
+ * them here. Since we are active now, there will be no more resets
+ * until we are inactive again.
+ */
+ _Timer_server_Stop_interval_system_watchdog( ts );
+ _Timer_server_Stop_tod_system_watchdog( ts );
+ }
+ }
+}
+
+/**
+ * @brief rtems_timer_initiate_server
+ *
+ * This directive creates and starts the server for task-based timers.
+ * It must be invoked before any task-based timers can be initiated.
+ *
+ * @param[in] priority is the timer server priority
+ * @param[in] stack_size is the stack size in bytes
+ * @param[in] attribute_set is the timer server attributes
+ *
+ * @return This method returns RTEMS_SUCCESSFUL if successful and an
+ * error code otherwise.
+ */
+rtems_status_code rtems_timer_initiate_server(
+ uint32_t priority,
+ uint32_t stack_size,
+ rtems_attribute attribute_set
+)
+{
+ rtems_id id;
+ rtems_status_code status;
+ rtems_task_priority _priority;
+ static bool initialized = false;
+ bool tmpInitialized;
+ Timer_server_Control *ts = &_Timer_server_Default;
+
+ /*
+ * Make sure the requested priority is valid. The if is
+ * structured so we check it is invalid before looking for
+ * a specific invalid value as the default.
+ */
+ _priority = priority;
+ if ( !_RTEMS_tasks_Priority_is_valid( priority ) ) {
+ if ( priority != RTEMS_TIMER_SERVER_DEFAULT_PRIORITY )
+ return RTEMS_INVALID_PRIORITY;
+ _priority = 0;
+ }
+
+ /*
+ * Just to make sure this is only called once.
+ */
+ _Thread_Disable_dispatch();
+ tmpInitialized = initialized;
+ initialized = true;
+ _Thread_Enable_dispatch();
+
+ if ( tmpInitialized )
+ return RTEMS_INCORRECT_STATE;
+
+ /*
+ * Create the Timer Server with the name the name of "TIME". The attribute
+ * RTEMS_SYSTEM_TASK allows us to set a priority to 0 which will makes it
+ * higher than any other task in the system. It can be viewed as a low
+ * priority interrupt. It is also always NO_PREEMPT so it looks like
+ * an interrupt to other tasks.
+ *
+ * We allow the user to override the default priority because the Timer
+ * Server can invoke TSRs which must adhere to language run-time or
+ * other library rules. For example, if using a TSR written in Ada the
+ * Server should run at the same priority as the priority Ada task.
+ * Otherwise, the priority ceiling for the mutex used to protect the
+ * GNAT run-time is violated.
+ */
+ status = rtems_task_create(
+ _Objects_Build_name('T','I','M','E'), /* "TIME" */
+ _priority, /* create with priority 1 since 0 is illegal */
+ stack_size, /* let user specify stack size */
+ RTEMS_NO_PREEMPT, /* no preempt is like an interrupt */
+ /* user may want floating point but we need */
+ /* system task specified for 0 priority */
+ attribute_set | RTEMS_SYSTEM_TASK,
+ &id /* get the id back */
+ );
+ if (status) {
+ initialized = false;
+ return status;
+ }
+
+ /*
+ * Do all the data structure initialization before starting the
+ * Timer Server so we do not have to have a critical section.
+ */
+
+ /*
+ * We work with the TCB pointer, not the ID, so we need to convert
+ * to a TCB pointer from here out.
+ */
+ ts->thread = (Thread_Control *)_Objects_Get_local_object(
+ &_RTEMS_tasks_Information,
+ _Objects_Get_index(id)
+ );
+
+ /*
+ * Initialize the timer lists that the server will manage.
+ */
+ _Chain_Initialize_empty( &ts->Interval_watchdogs.Chain );
+ _Chain_Initialize_empty( &ts->TOD_watchdogs.Chain );
+
+ /*
+ * Initialize the timers that will be used to control when the
+ * Timer Server wakes up and services the task-based timers.
+ */
+ _Watchdog_Initialize(
+ &ts->Interval_watchdogs.System_watchdog,
+ _Thread_Delay_ended,
+ id,
+ NULL
+ );
+ _Watchdog_Initialize(
+ &ts->TOD_watchdogs.System_watchdog,
+ _Thread_Delay_ended,
+ id,
+ NULL
+ );
+
+ /*
+ * Initialize the pointer to the timer schedule method so applications that
+ * do not use the Timer Server do not have to pull it in.
+ */
+ ts->schedule_operation = _Timer_server_Schedule_operation_method;
+
+ ts->Interval_watchdogs.last_snapshot = _Watchdog_Ticks_since_boot;
+ ts->TOD_watchdogs.last_snapshot = (Watchdog_Interval) _TOD_Seconds_since_epoch();
+
+ ts->insert_chain = NULL;
+ ts->active = false;
+
+ /*
+ * The default timer server is now available.
+ */
+ _Timer_server = ts;
+
+ /*
+ * Start the timer server
+ */
+ status = rtems_task_start(
+ id,
+ _Timer_server_Body,
+ (rtems_task_argument) ts
+ );
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * One would expect a call to rtems_task_delete() here to clean up
+ * but there is actually no way (in normal circumstances) that the
+ * start can fail. The id and starting address are known to be
+ * be good. If this service fails, something is weirdly wrong on the
+ * target such as a stray write in an ISR or incorrect memory layout.
+ */
+ if (status) {
+ initialized = false;
+ }
+ #endif
+
+ return status;
+}
diff --git a/cpukit/rtems/src/timerserverfireafter.c b/cpukit/rtems/src/timerserverfireafter.c
new file mode 100644
index 0000000000..a0af568865
--- /dev/null
+++ b/cpukit/rtems/src/timerserverfireafter.c
@@ -0,0 +1,109 @@
+/*
+ * Timer Manager - rtems_timer_server fire_after directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_server_fire_after
+ *
+ * This directive allows a thread to start a timer which will by
+ * executed by the Timer Server when it fires.
+ *
+ * Input parameters:
+ * id - timer id
+ * ticks - interval until routine is fired
+ * routine - routine to schedule
+ * user_data - passed as argument to routine when it is fired
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_server_fire_after(
+ rtems_id id,
+ rtems_interval ticks,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+ ISR_Level level;
+ Timer_server_Control *timer_server = _Timer_server;
+
+ if ( !timer_server )
+ return RTEMS_INCORRECT_STATE;
+
+ if ( !routine )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( ticks == 0 )
+ return RTEMS_INVALID_NUMBER;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ (void) _Watchdog_Remove( &the_timer->Ticker );
+
+ _ISR_Disable( level );
+
+ /*
+ * Check to see if the watchdog has just been inserted by a
+ * higher priority interrupt. If so, abandon this insert.
+ */
+
+ if ( the_timer->Ticker.state != WATCHDOG_INACTIVE ) {
+ _ISR_Enable( level );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+ }
+
+ /*
+ * OK. Now we now the timer was not rescheduled by an interrupt
+ * so we can atomically initialize it as in use.
+ */
+
+ the_timer->the_class = TIMER_INTERVAL_ON_TASK;
+ _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
+ the_timer->Ticker.initial = ticks;
+ _ISR_Enable( level );
+
+ (*timer_server->schedule_operation)( timer_server, the_timer );
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/timerserverfirewhen.c b/cpukit/rtems/src/timerserverfirewhen.c
new file mode 100644
index 0000000000..d5e6c472a1
--- /dev/null
+++ b/cpukit/rtems/src/timerserverfirewhen.c
@@ -0,0 +1,96 @@
+/*
+ * Timer Manager - rtems_timer_server fire_when directive
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/rtems/timer.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_timer_server_fire_when
+ *
+ * This directive allows a thread to start a timer which will by
+ * executed by the Timer Server when it fires.
+ *
+ * Input parameters:
+ * id - timer id
+ * wall_time - time of day to fire timer
+ * routine - routine to schedule
+ * user_data - passed as argument to routine when it is fired
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_timer_server_fire_when(
+ rtems_id id,
+ rtems_time_of_day *wall_time,
+ rtems_timer_service_routine_entry routine,
+ void *user_data
+)
+{
+ Timer_Control *the_timer;
+ Objects_Locations location;
+ rtems_interval seconds;
+ Timer_server_Control *timer_server = _Timer_server;
+
+ if ( !timer_server )
+ return RTEMS_INCORRECT_STATE;
+
+ if ( !_TOD_Is_set )
+ return RTEMS_NOT_DEFINED;
+
+ if ( !routine )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !_TOD_Validate( wall_time ) )
+ return RTEMS_INVALID_CLOCK;
+
+ seconds = _TOD_To_seconds( wall_time );
+ if ( seconds <= _TOD_Seconds_since_epoch() )
+ return RTEMS_INVALID_CLOCK;
+
+ the_timer = _Timer_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ (void) _Watchdog_Remove( &the_timer->Ticker );
+ the_timer->the_class = TIMER_TIME_OF_DAY_ON_TASK;
+ _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
+ the_timer->Ticker.initial = seconds - _TOD_Seconds_since_epoch();
+
+ (*timer_server->schedule_operation)( timer_server, the_timer );
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/rtems/src/workspace.c b/cpukit/rtems/src/workspace.c
new file mode 100644
index 0000000000..e6394aca86
--- /dev/null
+++ b/cpukit/rtems/src/workspace.c
@@ -0,0 +1,75 @@
+/*
+ * Workspace Handler
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/protectedheap.h>
+#include <rtems/score/interr.h>
+#include <rtems/config.h>
+
+#include <string.h> /* for memset */
+
+bool rtems_workspace_get_information(
+ Heap_Information_block *the_info
+)
+{
+ if ( !the_info )
+ return false;
+
+ return _Protected_heap_Get_information( &_Workspace_Area, the_info );
+}
+
+/*
+ * _Workspace_Allocate
+ */
+bool rtems_workspace_allocate(
+ uintptr_t bytes,
+ void **pointer
+)
+{
+ void *ptr;
+
+ /*
+ * check the arguments
+ */
+ if ( !pointer )
+ return false;
+
+ if ( !bytes )
+ return false;
+
+ /*
+ * Allocate the memory
+ */
+ ptr = _Protected_heap_Allocate( &_Workspace_Area, (intptr_t) bytes );
+ if (!ptr)
+ return false;
+
+ *pointer = ptr;
+ return true;
+}
+
+/*
+ * _Workspace_Allocate
+ */
+bool rtems_workspace_free(
+ void *pointer
+)
+{
+ return _Protected_heap_Free( &_Workspace_Area, pointer );
+}
+
diff --git a/cpukit/sapi/.cvsignore b/cpukit/sapi/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/sapi/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
new file mode 100644
index 0000000000..fb35b914f0
--- /dev/null
+++ b/cpukit/sapi/Makefile.am
@@ -0,0 +1,36 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+
+include_rtems_HEADERS = include/confdefs.h
+include_rtems_HEADERS += include/rtems/chain.h include/rtems/config.h \
+ include/rtems/extension.h include/rtems/fatal.h include/rtems/init.h \
+ include/rtems/io.h include/rtems/mptables.h include/rtems/sptables.h
+
+EXTRA_DIST = include/rtems/README
+
+include_rtems_HEADERS += inline/rtems/chain.inl \
+ inline/rtems/extension.inl
+
+## src
+AM_CPPFLAGS += -D__RTEMS_INSIDE__
+
+noinst_LIBRARIES = libsapi.a
+project_lib_LIBRARIES = libsapi.a
+libsapi_a_SOURCES = src/debug.c src/extension.c src/extensioncreate.c \
+ src/extensiondelete.c src/extensionident.c src/fatal.c src/exinit.c \
+ src/exshutdown.c src/io.c src/ioclose.c src/iocontrol.c src/iodata.c \
+ src/ioinitialize.c src/ioopen.c src/ioread.c src/ioregisterdriver.c \
+ src/iounregisterdriver.c src/iowrite.c src/posixapi.c \
+ src/rtemsapi.c src/extensiondata.c src/getversionstring.c \
+ src/chainappendnotify.c src/chaingetnotify.c src/chaingetwait.c \
+ src/chainprependnotify.c
+libsapi_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
new file mode 100644
index 0000000000..ad81403430
--- /dev/null
+++ b/cpukit/sapi/include/confdefs.h
@@ -0,0 +1,2342 @@
+/**
+ * @file rtems/confdefs.h
+ *
+ * This include file contains the configuration table template that will
+ * be instantiated by an application based on the setting of a number
+ * of macros. The macros are documented in the Configuring a System
+ * chapter of the Classic API User's Guide
+ *
+ * The model is to estimate the memory required for each configured item
+ * and sum those estimates. The estimate can be too high or too low for
+ * a variety of reasons:
+ *
+ * Reasons estimate is too high:
+ * + FP contexts (not all tasks are FP)
+ *
+ * Reasons estimate is too low:
+ * + stacks greater than minimum size
+ * + messages
+ * + application must account for device driver resources
+ * + application must account for add-on library resource requirements
+ *
+ * NOTE: Eventually this may be able to take into account some of
+ * the above. This procedure has evolved from just enough to
+ * support the RTEMS Test Suites into something that can be
+ * used remarkably reliably by most applications.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __CONFIGURATION_TEMPLATE_h
+#define __CONFIGURATION_TEMPLATE_h
+
+/*
+ * Include the executive's configuration
+ */
+#include <rtems.h>
+#include <rtems/score/apimutex.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern rtems_initialization_tasks_table Initialization_tasks[];
+extern rtems_driver_address_table Device_drivers[];
+extern rtems_configuration_table Configuration;
+#if defined(RTEMS_MULTIPROCESSING)
+ extern rtems_multiprocessing_table Multiprocessing_configuration;
+#endif
+#ifdef RTEMS_POSIX_API
+ extern posix_api_configuration_table Configuration_POSIX_API;
+#endif
+
+/**
+ * This macro determines whether the RTEMS reentrancy support for
+ * the Newlib C Library is enabled.
+ */
+#ifdef RTEMS_SCHEDSIM
+ #undef RTEMS_NEWLIB
+#endif
+
+#if (defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))
+ #define CONFIGURE_NEWLIB_EXTENSION 1
+#else
+ #define CONFIGURE_NEWLIB_EXTENSION 0
+#endif
+
+#ifndef RTEMS_SCHEDSIM
+#include <rtems/libio.h>
+
+#ifdef CONFIGURE_INIT
+rtems_libio_init_functions_t rtems_libio_init_helper =
+ #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
+ NULL;
+ #else
+ rtems_libio_init;
+ #endif
+
+rtems_libio_supp_functions_t rtems_libio_supp_helper =
+ #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
+ NULL;
+ #else
+ open_dev_console;
+ #endif
+
+rtems_fs_init_functions_t rtems_fs_init_helper =
+ #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
+ NULL;
+ #else
+ rtems_filesystem_initialize;
+ #endif
+#endif
+#endif
+
+/*
+ * If the application disables the filesystem, they will not need
+ * a mount table, so do not produce one.
+ */
+#ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
+ #define CONFIGURE_HAS_OWN_MOUNT_TABLE
+#endif
+
+/**
+ * This macro defines the number of POSIX file descriptors allocated
+ * and managed by libio. These are the "integer" file descriptors that
+ * are used by calls like open(2) and read(2).
+ */
+#ifndef CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS
+ #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 3
+#endif
+
+/**
+ * From the number of file descriptors, we can determine how many
+ * semaphores the implementation will require.
+ */
+#define CONFIGURE_LIBIO_SEMAPHORES \
+ (CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS + 1)
+
+#ifdef CONFIGURE_INIT
+ /**
+ * When instantiating the configuration tables, this variable is
+ * initialized to specify the maximum number of file descriptors.
+ */
+ uint32_t rtems_libio_number_iops = CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS;
+#endif
+
+/**
+ * This macro determines if termios is disabled by this application.
+ * This only means that resources will not be reserved. If you end
+ * up using termios, it will fail.
+ */
+#ifdef CONFIGURE_TERMIOS_DISABLED
+ #define CONFIGURE_TERMIOS_SEMAPHORES 0
+#else
+ /**
+ * This macro specifies the number of serial or PTY ports that will
+ * use termios.
+ */
+ #ifndef CONFIGURE_NUMBER_OF_TERMIOS_PORTS
+ #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 1
+ #endif
+
+ /**
+ * This macro reserves the number of semaphores required by termios
+ * based upon the number of communication ports that will use it.
+ */
+ #define CONFIGURE_TERMIOS_SEMAPHORES \
+ ((CONFIGURE_NUMBER_OF_TERMIOS_PORTS * 4) + 1)
+#endif
+
+/**
+ * This macro specifies the number of PTYs that can be concurrently
+ * active.
+ */
+#ifndef CONFIGURE_MAXIMUM_PTYS
+ #define CONFIGURE_MAXIMUM_PTYS 0
+#endif
+
+/**
+ * This variable contains the maximum number of PTYs that can be
+ * concurrently active.
+ */
+#ifdef CONFIGURE_INIT
+ int rtems_telnetd_maximum_ptys = CONFIGURE_MAXIMUM_PTYS;
+#else
+ extern int rtems_telnetd_maximum_ptys;
+#endif
+
+#if defined(RTEMS_SMP)
+ /*
+ * If configured for SMP, then we need to know the maximum CPU cores.
+ */
+ #if !defined(CONFIGURE_SMP_APPLICATION)
+ #if !defined(CONFIGURE_SMP_MAXIMUM_PROCESSORS)
+ #define CONFIGURE_SMP_MAXIMUM_PROCESSORS 1
+ #endif
+ #else
+ #if !defined(CONFIGURE_SMP_MAXIMUM_PROCESSORS)
+ #error "CONFIGURE_SMP_MAXIMUM_PROCESSORS not specified for SMP Application"
+ #endif
+ #endif
+#endif
+
+/*
+ * Filesystems and Mount Table Configuration.
+ *
+ * Defines to control the file system:
+ *
+ * CONFIGURE_APPLICATION_DISABLE_FILESYSTEM:
+ * Disable the RTEMS filesystems. You get an empty DEVFS.
+ *
+ * CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM:
+ * Use the DEVFS as the root file system. Limited functions are
+ * provided when this is used.
+ *
+ * CONFIGURE_FILESYSTEM_ALL:
+ * Add file filesystems to the default filesystem table.
+ *
+ * List of available file systems. You can define as many as you like:
+ * CONFIGURE_FILESYSTEM_MINIIMFS - MiniIMFS, use DEVFS now
+ * CONFIGURE_FILESYSTEM_IMFS - In Memory File System (IMFS)
+ * CONFIGURE_FILESYSTEM_DEVFS - Device File System (DSVFS)
+ * CONFIGURE_FILESYSTEM_TFTPFS - TFTP File System, networking enabled
+ * CONFIGURE_FILESYSTEM_FTPFS - FTP File System, networking enabled
+ * CONFIGURE_FILESYSTEM_NFS - Network File System, networking enabled
+ * CONFIGURE_FILESYSTEM_DOSFS - DOS File System, uses libblock
+ * CONFIGURE_FILESYSTEM_RFS - RTEMS File System (RFS), uses libblock
+ *
+ * Combinations:
+ *
+ * - If nothing is defined the base file system is the IMFS.
+ *
+ * - If CONFIGURE_APPLICATION_DISABLE_FILESYSTEM is defined all filesystem
+ * are disabled by force and an empty DEVFS is created.
+ *
+ * - If CONFIGURE_USE_DEV_AS_BASE_FILESYSTEM is defined all filesystem
+ * are disabled by force and DEVFS is defined.
+ */
+
+#ifdef CONFIGURE_INIT
+
+ /*
+ * Include all file systems. Do this before checking if the filesystem has
+ * been disabled.
+ */
+ #ifdef CONFIGURE_FILESYSTEM_ALL
+ #define CONFIGURE_FILESYSTEM_MINIIMFS
+ #define CONFIGURE_FILESYSTEM_IMFS
+ #define CONFIGURE_FILESYSTEM_DEVFS
+ #define CONFIGURE_FILESYSTEM_TFTPFS
+ #define CONFIGURE_FILESYSTEM_FTPFS
+ #define CONFIGURE_FILESYSTEM_NFS
+ #define CONFIGURE_FILESYSTEM_DOSFS
+ #define CONFIGURE_FILESYSTEM_RFS
+ #endif
+
+ /*
+ * If disabling the file system, give a compile error if the user has
+ * configured other filesystem parameters.
+ */
+ #if defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM)
+ #if defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM) || \
+ defined(CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM)
+ #error "Filesystem disabled but a base filesystem configured."
+ #endif
+
+ #if defined(CONFIGURE_FILESYSTEM_MINIIMFS) || \
+ defined(CONFIGURE_FILESYSTEM_IMFS) || \
+ defined(CONFIGURE_FILESYSTEM_DEVFS) || \
+ defined(CONFIGURE_FILESYSTEM_TFTPFS) || \
+ defined(CONFIGURE_FILESYSTEM_FTPFS) || \
+ defined(CONFIGURE_FILESYSTEM_NFS) || \
+ defined(CONFIGURE_FILESYSTEM_DOSFS) || \
+ defined(CONFIGURE_FILESYSTEM_RFS)
+ #error "Configured filesystems but root filesystem was not IMFS!"
+ #error "Filesystems could be disabled, DEVFS is root, or"
+ #error " miniIMFS is root!"
+ #endif
+ #endif
+
+ /*
+ * If the base filesystem is DEVFS define it else define IMFS.
+ * We will have either DEVFS or IMFS defined after this.
+ */
+ #if !defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM)
+ #if defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM)
+ #define CONFIGURE_FILESYSTEM_DEVFS
+ #elif defined(CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM)
+ #define CONFIGURE_FILESYSTEM_MINIIMFS
+ #elif !defined(CONFIGURE_FILESYSTEM_IMFS)
+ #define CONFIGURE_FILESYSTEM_IMFS
+ #endif
+ #endif
+
+#endif
+
+#ifndef RTEMS_SCHEDSIM
+/**
+ * IMFS
+ */
+#include <rtems/imfs.h>
+
+/**
+ * This specifies the number of bytes per block for files within the IMFS.
+ * There are a maximum number of blocks per file so this dictates the maximum
+ * size of a file. This has to be balanced with the unused portion of each
+ * block that might be wasted.
+ */
+#ifndef CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK
+ #define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK \
+ IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
+#endif
+
+/**
+ * This defines the miniIMFS file system table entry.
+ */
+#if !defined(CONFIGURE_FILESYSTEM_ENTRY_miniIMFS) && \
+ defined(CONFIGURE_FILESYSTEM_MINIIMFS)
+ #define CONFIGURE_FILESYSTEM_ENTRY_miniIMFS \
+ { RTEMS_FILESYSTEM_TYPE_MINIIMFS, miniIMFS_initialize }
+#endif
+#endif
+
+/**
+ * Internall it is called FIFOs not pipes
+ */
+#if defined(CONFIGURE_PIPES_ENABLED)
+ #define CONFIGURE_FIFOS_ENABLED
+#endif
+
+#ifndef RTEMS_SCHEDSIM
+/**
+ * This defines the IMFS file system table entry.
+ */
+#if !defined(CONFIGURE_FILESYSTEM_ENTRY_IMFS) && \
+ defined(CONFIGURE_FILESYSTEM_IMFS)
+ #if defined(CONFIGURE_FIFOS_ENABLED)
+ #define CONFIGURE_FILESYSTEM_ENTRY_IMFS \
+ { RTEMS_FILESYSTEM_TYPE_IMFS, fifoIMFS_initialize }
+ #else
+ #define CONFIGURE_FILESYSTEM_ENTRY_IMFS \
+ { RTEMS_FILESYSTEM_TYPE_IMFS, IMFS_initialize }
+ #endif
+#endif
+#endif
+
+/**
+ * This sets up the resources for the PIPES/FIFOs
+ */
+#if defined(CONFIGURE_FIFOS_ENABLED)
+ #if !defined(CONFIGURE_MAXIMUM_FIFOS) && !defined(CONFIGURE_MAXIMUM_PIPES)
+ #error "No FIFOs or PIPES configured"
+ #endif
+ #if !defined(CONFIGURE_MAXIMUM_FIFOS)
+ #define CONFIGURE_MAXIMUM_FIFOS 0
+ #endif
+ #if !defined(CONFIGURE_MAXIMUM_PIPES)
+ #define CONFIGURE_MAXIMUM_PIPES 0
+ #endif
+ #define CONFIGURE_BARRIERS_FOR_FIFOS \
+ (2 * (CONFIGURE_MAXIMUM_FIFOS + CONFIGURE_MAXIMUM_PIPES))
+ #define CONFIGURE_SEMAPHORES_FOR_FIFOS \
+ (1 + (CONFIGURE_MAXIMUM_FIFOS + CONFIGURE_MAXIMUM_PIPES))
+#else
+ #define CONFIGURE_BARRIERS_FOR_FIFOS 0
+ #define CONFIGURE_SEMAPHORES_FOR_FIFOS 0
+#endif
+
+/**
+ * DEVFS
+ */
+#if !defined(CONFIGURE_FILESYSTEM_ENTRY_DEVFS) && \
+ defined(CONFIGURE_FILESYSTEM_DEVFS)
+#include <rtems/devfs.h>
+ #define CONFIGURE_FILESYSTEM_ENTRY_DEVFS \
+ { RTEMS_FILESYSTEM_TYPE_DEVFS, devFS_initialize }
+#endif
+
+#ifdef RTEMS_NETWORKING
+ /**
+ * FTPFS
+ */
+ #if !defined(CONFIGURE_FILESYSTEM_ENTRY_FTPFS) && \
+ defined(CONFIGURE_FILESYSTEM_FTPFS)
+ #include <rtems/ftpfs.h>
+ #define CONFIGURE_FILESYSTEM_ENTRY_FTPFS \
+ { RTEMS_FILESYSTEM_TYPE_FTPFS, rtems_ftpfs_initialize }
+ #endif
+
+ /**
+ * TFTPFS
+ */
+ #if !defined(CONFIGURE_FILESYSTEM_ENTRY_TFTPFS) && \
+ defined(CONFIGURE_FILESYSTEM_TFTPFS)
+ #include <rtems/tftp.h>
+ #define CONFIGURE_FILESYSTEM_ENTRY_TFTPFS \
+ { RTEMS_FILESYSTEM_TYPE_TFTPFS, rtems_tftpfs_initialize }
+ #endif
+
+ /**
+ * NFS
+ */
+ #if !defined(CONFIGURE_FILESYSTEM_ENTRY_NFS) && \
+ defined(CONFIGURE_FILESYSTEM_NFS)
+ #include <librtemsNfs.h>
+ #define CONFIGURE_FILESYSTEM_ENTRY_NFS \
+ { RTEMS_FILESYSTEM_TYPE_NFS, rtems_nfs_initialize }
+ #endif
+#endif
+
+/**
+ * DOSFS
+ */
+#if !defined(CONFIGURE_FILESYSTEM_ENTRY_DOSFS) && \
+ defined(CONFIGURE_FILESYSTEM_DOSFS)
+ #include <rtems/dosfs.h>
+ #define CONFIGURE_FILESYSTEM_ENTRY_DOSFS \
+ { RTEMS_FILESYSTEM_TYPE_DOSFS, rtems_dosfs_initialize }
+#endif
+
+/**
+ * RFS
+ */
+#if !defined(CONFIGURE_FILESYSTEM_ENTRY_RFS) && \
+ defined(CONFIGURE_FILESYSTEM_RFS)
+ #include <rtems/rtems-rfs.h>
+ #define CONFIGURE_FILESYSTEM_ENTRY_RFS \
+ { RTEMS_FILESYSTEM_TYPE_RFS, rtems_rfs_rtems_initialise }
+#endif
+
+#ifdef CONFIGURE_INIT
+
+ /*
+ * DEVFS variables.
+ */
+ #if defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM)
+ #define CONFIGURE_MEMORY_FOR_DEVFS 0
+ #elif defined(CONFIGURE_FILESYSTEM_DEVFS)
+ #ifndef CONFIGURE_MAXIMUM_DEVICES
+ #define CONFIGURE_MAXIMUM_DEVICES 4
+ #endif
+ #include <rtems/devfs.h>
+ uint32_t rtems_device_table_size = CONFIGURE_MAXIMUM_DEVICES;
+ #define CONFIGURE_MEMORY_FOR_DEVFS \
+ _Configure_Object_RAM(CONFIGURE_MAXIMUM_DEVICES, \
+ sizeof (rtems_device_name_t))
+ #else
+ #define CONFIGURE_MEMORY_FOR_DEVFS 0
+ #endif
+
+#ifndef RTEMS_SCHEDSIM
+ #if defined(CONFIGURE_FILESYSTEM_IMFS) || \
+ defined(CONFIGURE_FILESYSTEM_MINIIMFS)
+ int imfs_rq_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
+ #endif
+#endif
+
+ /**
+ * Table termination record.
+ */
+ #define CONFIGURE_FILESYSTEM_NULL { NULL, NULL }
+
+#ifndef RTEMS_SCHEDSIM
+ /**
+ * The default file system table. Must be terminated with the NULL entry if
+ * you provide your own.
+ */
+ #ifndef CONFIGURE_HAS_OWN_FILESYSTEM_TABLE
+ const rtems_filesystem_table_t rtems_filesystem_table[] = {
+ #if defined(CONFIGURE_FILESYSTEM_MINIIMFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_miniIMFS)
+ CONFIGURE_FILESYSTEM_ENTRY_miniIMFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_IMFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_IMFS)
+ CONFIGURE_FILESYSTEM_ENTRY_IMFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_DEVFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_DEVFS)
+ CONFIGURE_FILESYSTEM_ENTRY_DEVFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_TFTPFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_TFTPFS)
+ CONFIGURE_FILESYSTEM_ENTRY_TFTPFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_FTPFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_FTPFS)
+ CONFIGURE_FILESYSTEM_ENTRY_FTPFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_NFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_NFS)
+ CONFIGURE_FILESYSTEM_ENTRY_NFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_DOSFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_DOSFS)
+ CONFIGURE_FILESYSTEM_ENTRY_DOSFS,
+ #endif
+ #if defined(CONFIGURE_FILESYSTEM_RFS) && \
+ defined(CONFIGURE_FILESYSTEM_ENTRY_RFS)
+ CONFIGURE_FILESYSTEM_ENTRY_RFS,
+ #endif
+ CONFIGURE_FILESYSTEM_NULL
+ };
+ #endif
+
+ #ifndef CONFIGURE_HAS_OWN_MOUNT_TABLE
+ const rtems_filesystem_mount_table_t configuration_mount_table = {
+ #if defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM)
+ RTEMS_FILESYSTEM_TYPE_DEVFS,
+ #elif defined(CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM)
+ RTEMS_FILESYSTEM_TYPE_MINIIMFS,
+ #else /* using IMFS as base filesystem */
+ RTEMS_FILESYSTEM_TYPE_IMFS,
+ #endif
+ RTEMS_FILESYSTEM_READ_WRITE,
+ NULL,
+ NULL
+ };
+
+ const rtems_filesystem_mount_table_t
+ *rtems_filesystem_mount_table = &configuration_mount_table;
+ const int rtems_filesystem_mount_table_size = 1;
+ #endif
+
+#endif
+#endif
+
+/*
+ * STACK_CHECKER_ON was still available in 4.9 so give a warning for now.
+ */
+#if defined(STACK_CHECKER_ON)
+ #define CONFIGURE_STACK_CHECKER_ENABLED
+ #warning "STACK_CHECKER_ON deprecated -- use CONFIGURE_STACK_CHECKER_ENABLED"
+#endif
+
+/**
+ * This configures the stack checker user extension.
+ */
+#ifdef CONFIGURE_STACK_CHECKER_ENABLED
+ #define CONFIGURE_STACK_CHECKER_EXTENSION 1
+#else
+ #define CONFIGURE_STACK_CHECKER_EXTENSION 0
+#endif
+
+/**
+ * @brief Maximum Priority configuration
+ *
+ * This configures the maximum priority value that
+ * a task may have.
+ *
+ * The following applies to the data space requirements
+ * of the Priority Scheduler.
+ *
+ * By reducing the number of priorities in a system,
+ * the amount of RAM required by RTEMS can be significantly
+ * reduced. RTEMS allocates a Chain_Control structure per
+ * priority and this structure contains 3 pointers. So
+ * the default is (256 * 12) = 3K on 32-bit architectures.
+ *
+ * This must be one less than a power of 2 between
+ * 4 and 256. Valid values along with the application
+ * priority levels and memory saved when pointers are
+ * 32-bits in size are:
+ *
+ * + 3, 2 application priorities, 3024 bytes saved
+ * + 7, 5 application priorities, 2976 bytes saved
+ * + 15, 13 application priorities, 2880 bytes saved
+ * + 31, 29 application priorities, 2688 bytes saved
+ * + 63, 61 application priorities, 2304 bytes saved
+ * + 127, 125 application priorities, 1536 bytes saved
+ * + 255, 253 application priorities, 0 bytes saved
+ *
+ * It is specified in terms of Classic API priority values.
+ */
+#ifndef CONFIGURE_MAXIMUM_PRIORITY
+ #define CONFIGURE_MAXIMUM_PRIORITY PRIORITY_DEFAULT_MAXIMUM
+#endif
+
+/*
+ * Scheduler configuration.
+ *
+ * The scheduler configuration allows an application to select the
+ * scheduling policy to use. The supported configurations are:
+ * CONFIGURE_SCHEDULER_USER - user provided scheduler
+ * CONFIGURE_SCHEDULER_PRIORITY - Deterministic Priority Scheduler
+ * CONFIGURE_SCHEDULER_SIMPLE - Light-weight Priority Scheduler
+ *
+ * If no configuration is specified by the application, then
+ * CONFIGURE_SCHEDULER_PRIORITY is assumed to be the default.
+ *
+ * An application can define its own scheduling policy by defining
+ * CONFIGURE_SCHEDULER_USER and the following:
+ * - CONFIGURE_SCHEDULER_ENTRY_POINTS
+ * - CONFIGURE_MEMORY_FOR_SCHEDULER - base memory
+ * - CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER - per task memory
+ */
+#include <rtems/score/scheduler.h>
+
+#if defined(CONFIGURE_SCHEDULER_USER) && \
+ !defined(CONFIGURE_SCHEDULER_USER_ENTRY_POINTS)
+ #error "CONFIGURE_ERROR: CONFIGURE_SCHEDULER_USER requires CONFIGURE_SCHEDULER_USER_ENTRY_POINTS"
+#endif
+
+/* If no scheduler is specified, the priority scheduler is default. */
+#if !defined(CONFIGURE_SCHEDULER_USER) && \
+ !defined(CONFIGURE_SCHEDULER_PRIORITY) && \
+ !defined(CONFIGURE_SCHEDULER_SIMPLE)
+ #define CONFIGURE_SCHEDULER_PRIORITY
+#endif
+
+/*
+ * If the Priority Scheduler is selected, then configure for it.
+ */
+#if defined(CONFIGURE_SCHEDULER_PRIORITY)
+ #include <rtems/score/schedulerpriority.h>
+ #define SCHEDULER_ENTRY_POINTS SCHEDULER_PRIORITY_ENTRY_POINTS
+
+ /**
+ * This defines the memory used by the priority scheduler.
+ */
+ #define CONFIGURE_MEMORY_FOR_SCHEDULER ( \
+ _Configure_From_workspace( \
+ ((CONFIGURE_MAXIMUM_PRIORITY+1) * sizeof(Chain_Control)) ) \
+ )
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
+ _Configure_From_workspace(sizeof(Scheduler_priority_Per_thread)) )
+#endif
+
+/*
+ * If the Simple Priority Scheduler is selected, then configure for it.
+ */
+#if defined(CONFIGURE_SCHEDULER_SIMPLE)
+ #include <rtems/score/schedulersimple.h>
+ #define SCHEDULER_ENTRY_POINTS SCHEDULER_SIMPLE_ENTRY_POINTS
+
+ /**
+ * define the memory used by the simple scheduler
+ */
+ #define CONFIGURE_MEMORY_FOR_SCHEDULER ( \
+ _Configure_From_workspace( sizeof(Chain_Control) ) \
+ )
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (0)
+#endif
+
+/*
+ * Set up the scheduler entry points table. The scheduling code uses
+ * this code to know which scheduler is configured by the user.
+ */
+#ifdef CONFIGURE_INIT
+ Scheduler_Control _Scheduler = {
+ NULL, /* Scheduler Specific Data Pointer */
+ SCHEDULER_ENTRY_POINTS /* Scheduler Operations */
+ };
+#endif
+
+/*
+ * If you said the IDLE task was going to do application initialization
+ * and didn't override the IDLE body, then something is amiss.
+ */
+#if (defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION) && \
+ !defined(CONFIGURE_IDLE_TASK_BODY))
+ #error "CONFIGURE_ERROR: You did not override the IDLE task body."
+#endif
+
+/**
+ * @brief Idle task body configuration
+ *
+ * There is a default IDLE thread body provided by RTEMS which
+ * has the possibility of being CPU specific. There may be a
+ * BSP specific override of the RTEMS default body and in turn,
+ * the application may override and provide its own.
+ */
+#ifndef CONFIGURE_IDLE_TASK_BODY
+ #if defined(BSP_IDLE_TASK_BODY)
+ #define CONFIGURE_IDLE_TASK_BODY BSP_IDLE_TASK_BODY
+ #elif (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
+ #define CONFIGURE_IDLE_TASK_BODY _CPU_Thread_Idle_body
+ #else
+ /* only instantiate and compile if used */
+ #ifdef CONFIGURE_INIT
+ void *_Thread_Idle_body(uintptr_t ignored)
+ {
+ for( ; ; ) ;
+ return 0; /* to avoid warning */
+ }
+ #endif
+ #define CONFIGURE_IDLE_TASK_BODY _Thread_Idle_body
+ #endif
+#endif
+
+/**
+ * By default, use the minimum stack size requested by this port.
+ */
+#ifndef CONFIGURE_MINIMUM_TASK_STACK_SIZE
+ #define CONFIGURE_MINIMUM_TASK_STACK_SIZE CPU_STACK_MINIMUM_SIZE
+#endif
+
+/**
+ * @brief Idle task stack size configuration
+ *
+ * By default, the IDLE task will have a stack of minimum size.
+ * The BSP or application may override this value.
+ */
+#ifndef CONFIGURE_IDLE_TASK_STACK_SIZE
+ #ifdef BSP_IDLE_TASK_STACK_SIZE
+ #define CONFIGURE_IDLE_TASK_STACK_SIZE BSP_IDLE_TASK_STACK_SIZE
+ #else
+ #define CONFIGURE_IDLE_TASK_STACK_SIZE CONFIGURE_MINIMUM_TASK_STACK_SIZE
+ #endif
+#endif
+
+/**
+ * @brief Interrupt stack size configuration
+ *
+ * By default, the interrupt stack will be of minimum size.
+ * The BSP or application may override this value.
+ */
+#ifndef CONFIGURE_INTERRUPT_STACK_SIZE
+ #ifdef BSP_INTERRUPT_STACK_SIZE
+ #define CONFIGURE_INTERRUPT_STACK_SIZE BSP_INTERRUPT_STACK_SIZE
+ #else
+ #define CONFIGURE_INTERRUPT_STACK_SIZE CONFIGURE_MINIMUM_TASK_STACK_SIZE
+ #endif
+#endif
+
+/**
+ * This reserves memory for the interrupt stack if it is to be allocated
+ * by RTEMS rather than the BSP.
+ *
+ * @todo Try to get to the point where all BSPs support allocating the
+ * memory from the Workspace.
+ */
+#if (CPU_ALLOCATE_INTERRUPT_STACK == 0)
+ #define CONFIGURE_INTERRUPT_STACK_MEMORY 0
+#else
+ #define CONFIGURE_INTERRUPT_STACK_MEMORY \
+ _Configure_From_workspace( CONFIGURE_INTERRUPT_STACK_SIZE )
+#endif
+
+/**
+ * Configure the very much optional task stack allocator
+ */
+#ifndef CONFIGURE_TASK_STACK_ALLOCATOR
+ #define CONFIGURE_TASK_STACK_ALLOCATOR NULL
+#endif
+
+/**
+ * Configure the very much optional task stack deallocator
+ */
+#ifndef CONFIGURE_TASK_STACK_DEALLOCATOR
+ #define CONFIGURE_TASK_STACK_DEALLOCATOR NULL
+#endif
+
+/**
+ * Should the RTEMS Workspace and C Program Heap be cleared automatically
+ * at system start up?
+ */
+#ifndef CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY
+ #ifdef BSP_ZERO_WORKSPACE_AUTOMATICALLY
+ #define CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY \
+ BSP_ZERO_WORKSPACE_AUTOMATICALLY
+ #else
+ #define CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY FALSE
+ #endif
+#endif
+
+/*
+ * RTEMS Malloc configuration
+ */
+
+#include <rtems/malloc.h>
+
+#ifdef CONFIGURE_INIT
+ /**
+ * By default, RTEMS uses separate heaps for the RTEMS Workspace and
+ * the C Program Heap. On many BSPs, these can be optionally
+ * combined provided one larger memory pool. This is particularly
+ * useful in combination with the unlimited objects configuration.
+ */
+ #ifdef CONFIGURE_UNIFIED_WORK_AREAS
+ #include <rtems/score/wkspace.h>
+ Heap_Control *RTEMS_Malloc_Heap = &_Workspace_Area;
+ bool rtems_unified_work_area = true;
+ #else
+ Heap_Control RTEMS_Malloc_Area;
+ Heap_Control *RTEMS_Malloc_Heap = &RTEMS_Malloc_Area;
+ bool rtems_unified_work_area = false;
+ #endif
+#endif
+
+#ifdef CONFIGURE_INIT
+ /**
+ * This configures the malloc family statistics to be available.
+ * By default only function call counts are kept.
+ */
+ rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers =
+ #ifndef CONFIGURE_MALLOC_STATISTICS
+ NULL;
+ #else
+ &rtems_malloc_statistics_helpers_table;
+ #endif
+#endif
+
+#ifdef CONFIGURE_INIT
+ /**
+ * This configures the sbrk() support for the malloc family.
+ * By default it is assumed that the BSP provides all available
+ * RAM to the malloc family implementation so sbrk()'ing to get
+ * more memory would always fail anyway.
+ */
+ rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers =
+ #ifndef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
+ NULL;
+ #else
+ &rtems_malloc_sbrk_helpers_table;
+ #endif
+#endif
+
+#ifdef CONFIGURE_INIT
+ /**
+ * This configures the malloc family plugin which dirties memory
+ * allocated. This is helpful for finding unitialized data structure
+ * problems.
+ */
+ rtems_malloc_dirtier_t rtems_malloc_dirty_helper =
+ #if defined(CONFIGURE_MALLOC_DIRTY)
+ rtems_malloc_dirty_memory;
+ #else
+ NULL;
+ #endif
+#endif
+
+/**
+ * This is a helper macro used in calculations in this file. It is used
+ * to noted when an element is allocated from the RTEMS Workspace and adds
+ * a factor to account for heap overhead plus an alignment factor that
+ * may be applied.
+ */
+#define _Configure_From_workspace(_size) \
+ (ssize_t)((_size) + (2 * sizeof(uint32_t)) + CPU_ALIGNMENT)
+
+/**
+ * Do not use the unlimited bit as part of the multiplication
+ * for memory usage.
+ */
+#define _Configure_Max_Objects(_max) \
+ ((_max) & ~RTEMS_UNLIMITED_OBJECTS)
+
+/**
+ * This macro accounts for how memory for a set of configured objects is
+ * allocated from the Executive Workspace.
+ *
+ * NOTE: It does NOT attempt to address the more complex case of unlimited
+ * objects.
+ */
+#define _Configure_Object_RAM(_number, _size) \
+ ( _Configure_From_workspace(_Configure_Max_Objects(_number) * (_size)) + \
+ _Configure_From_workspace( \
+ ((_Configure_Max_Objects(_number) + 1) * sizeof(Objects_Control *)) + \
+ (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) \
+ ) \
+ )
+
+/*
+ * Default User Initialization Task Table. This table guarantees that
+ * one user initialization table is defined.
+ */
+
+#ifdef CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#ifdef CONFIGURE_HAS_OWN_INIT_TASK_TABLE
+
+/*
+ * The user is defining their own table information and setting the
+ * appropriate variables.
+ */
+
+#else
+
+#ifndef CONFIGURE_INIT_TASK_NAME
+ #define CONFIGURE_INIT_TASK_NAME rtems_build_name('U', 'I', '1', ' ')
+#endif
+
+#ifndef CONFIGURE_INIT_TASK_STACK_SIZE
+ #define CONFIGURE_INIT_TASK_STACK_SIZE CONFIGURE_MINIMUM_TASK_STACK_SIZE
+#endif
+
+#ifndef CONFIGURE_INIT_TASK_PRIORITY
+ #define CONFIGURE_INIT_TASK_PRIORITY 1
+#endif
+
+#ifndef CONFIGURE_INIT_TASK_ATTRIBUTES
+ #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
+#endif
+
+#ifndef CONFIGURE_INIT_TASK_ENTRY_POINT
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ rtems_task Init (rtems_task_argument );
+ #ifdef __cplusplus
+ }
+ #endif
+ #define CONFIGURE_INIT_TASK_ENTRY_POINT Init
+ extern const char* bsp_boot_cmdline;
+ #define CONFIGURE_INIT_TASK_ARGUMENTS ((rtems_task_argument) &bsp_boot_cmdline)
+#endif
+
+#ifndef CONFIGURE_INIT_TASK_INITIAL_MODES
+ #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_NO_PREEMPT
+#endif
+
+#ifndef CONFIGURE_INIT_TASK_ARGUMENTS
+ #define CONFIGURE_INIT_TASK_ARGUMENTS 0
+#endif
+
+#ifdef CONFIGURE_INIT
+ rtems_initialization_tasks_table Initialization_tasks[] = {
+ { CONFIGURE_INIT_TASK_NAME,
+ CONFIGURE_INIT_TASK_STACK_SIZE,
+ CONFIGURE_INIT_TASK_PRIORITY,
+ CONFIGURE_INIT_TASK_ATTRIBUTES,
+ CONFIGURE_INIT_TASK_ENTRY_POINT,
+ CONFIGURE_INIT_TASK_INITIAL_MODES,
+ CONFIGURE_INIT_TASK_ARGUMENTS
+ }
+ };
+#endif
+
+#define CONFIGURE_INIT_TASK_TABLE Initialization_tasks
+
+#define CONFIGURE_INIT_TASK_TABLE_SIZE \
+ sizeof(CONFIGURE_INIT_TASK_TABLE) / sizeof(rtems_initialization_tasks_table)
+
+#endif /* CONFIGURE_HAS_OWN_INIT_TASK_TABLE */
+
+#else /* CONFIGURE_RTEMS_INIT_TASKS_TABLE */
+
+#define CONFIGURE_INIT_TASK_TABLE NULL
+#define CONFIGURE_INIT_TASK_TABLE_SIZE 0
+#define CONFIGURE_INIT_TASK_STACK_SIZE 0
+
+#endif
+
+/*
+ * Default Device Driver Table. Each driver needed by the test is explicitly
+ * choosen by that test. There is always a null driver entry.
+ */
+
+#define NULL_DRIVER_TABLE_ENTRY \
+ { NULL, NULL, NULL, NULL, NULL, NULL }
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+ #include <rtems/console.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+ #include <rtems/clockdrv.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
+ #include <rtems/timerdrv.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_RTC_DRIVER
+ #include <rtems/rtc.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_WATCHDOG_DRIVER
+ #include <rtems/watchdogdrv.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_FRAME_BUFFER_DRIVER
+ #include <rtems/framebuffer.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
+ #include <rtems/devnull.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
+ /* the ide driver needs the ATA driver */
+ #ifndef CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
+ #define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
+ #endif
+ #include <libchip/ide_ctrl.h>
+#endif
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
+ #include <libchip/ata.h>
+#endif
+
+#ifndef CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE
+
+#ifdef CONFIGURE_INIT
+ rtems_driver_address_table Device_drivers[] = {
+ #ifdef CONFIGURE_BSP_PREREQUISITE_DRIVERS
+ CONFIGURE_BSP_PREREQUISITE_DRIVERS,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS
+ CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+ CONSOLE_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+ CLOCK_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_RTC_DRIVER
+ RTC_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_WATCHDOG_DRIVER
+ WATCHDOG_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
+ DEVNULL_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
+ IDE_CONTROLLER_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
+ ATA_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_FRAME_BUFFER_DRIVER
+ FRAME_BUFFER_DRIVER_TABLE_ENTRY,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_EXTRA_DRIVERS
+ CONFIGURE_APPLICATION_EXTRA_DRIVERS,
+ #endif
+ #ifdef CONFIGURE_APPLICATION_NEEDS_NULL_DRIVER
+ NULL_DRIVER_TABLE_ENTRY
+ #elif !defined(CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_RTC_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_FRAME_BUFFER_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_EXTRA_DRIVERS)
+ NULL_DRIVER_TABLE_ENTRY
+ #endif
+ };
+#endif
+
+#endif /* CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE */
+
+/*
+ * Default the number of drivers per node. This value may be
+ * overridden by the user.
+ */
+
+#define CONFIGURE_NUMBER_OF_DRIVERS \
+ ((sizeof(Device_drivers) / sizeof(rtems_driver_address_table)))
+
+/**
+ * This specifies the maximum number of device drivers that
+ * can be installed in the system at one time. It must account
+ * for both the statically and dynamically installed drivers.
+ */
+#ifndef CONFIGURE_MAXIMUM_DRIVERS
+ #define CONFIGURE_MAXIMUM_DRIVERS CONFIGURE_NUMBER_OF_DRIVERS
+#endif
+
+
+#ifdef CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
+ /*
+ * configure the priority of the ATA driver task
+ */
+ #ifndef CONFIGURE_ATA_DRIVER_TASK_PRIORITY
+ #define CONFIGURE_ATA_DRIVER_TASK_PRIORITY ATA_DRIVER_TASK_DEFAULT_PRIORITY
+ #endif
+ #ifdef CONFIGURE_INIT
+ rtems_task_priority rtems_ata_driver_task_priority
+ = CONFIGURE_ATA_DRIVER_TASK_PRIORITY;
+ #endif /* CONFIGURE_INIT */
+#endif
+
+/*
+ * add bdbuf configuration and values for swapout task priority
+ */
+#ifdef CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+ #include <rtems/bdbuf.h>
+ /*
+ * configure the bdbuf cache parameters
+ */
+ #ifndef CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS
+ #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS \
+ RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT
+ #endif
+ #ifndef CONFIGURE_BDBUF_MAX_WRITE_BLOCKS
+ #define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS \
+ RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT
+ #endif
+ #ifndef CONFIGURE_SWAPOUT_TASK_PRIORITY
+ #define CONFIGURE_SWAPOUT_TASK_PRIORITY \
+ RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
+ #endif
+ #ifndef CONFIGURE_SWAPOUT_SWAP_PERIOD
+ #define CONFIGURE_SWAPOUT_SWAP_PERIOD \
+ RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT
+ #endif
+ #ifndef CONFIGURE_SWAPOUT_BLOCK_HOLD
+ #define CONFIGURE_SWAPOUT_BLOCK_HOLD \
+ RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT
+ #endif
+ #ifndef CONFIGURE_SWAPOUT_WORKER_TASKS
+ #define CONFIGURE_SWAPOUT_WORKER_TASKS \
+ RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT
+ #endif
+ #ifndef CONFIGURE_SWAPOUT_WORKER_TASK_PRIORITY
+ #define CONFIGURE_SWAPOUT_WORKER_TASK_PRIORITY \
+ RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT
+ #endif
+ #ifndef CONFIGURE_BDBUF_CACHE_MEMORY_SIZE
+ #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE \
+ RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT
+ #endif
+ #ifndef CONFIGURE_BDBUF_BUFFER_MIN_SIZE
+ #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE \
+ RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT
+ #endif
+ #ifndef CONFIGURE_BDBUF_BUFFER_MAX_SIZE
+ #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE \
+ RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT
+ #endif
+ #ifdef CONFIGURE_INIT
+ const rtems_bdbuf_config rtems_bdbuf_configuration = {
+ CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS,
+ CONFIGURE_BDBUF_MAX_WRITE_BLOCKS,
+ CONFIGURE_SWAPOUT_TASK_PRIORITY,
+ CONFIGURE_SWAPOUT_SWAP_PERIOD,
+ CONFIGURE_SWAPOUT_BLOCK_HOLD,
+ CONFIGURE_SWAPOUT_WORKER_TASKS,
+ CONFIGURE_SWAPOUT_WORKER_TASK_PRIORITY,
+ CONFIGURE_BDBUF_CACHE_MEMORY_SIZE,
+ CONFIGURE_BDBUF_BUFFER_MIN_SIZE,
+ CONFIGURE_BDBUF_BUFFER_MAX_SIZE
+ };
+ #endif
+
+ /*
+ * Semaphores:
+ * o disk lock
+ * o bdbuf lock
+ * o bdbuf sync lock
+ * o bdbuf access condition
+ * o bdbuf transfer condition
+ * o bdbuf buffer condition
+ */
+ #define CONFIGURE_LIBBLOCK_SEMAPHORES 6
+
+ #if defined(CONFIGURE_HAS_OWN_BDBUF_TABLE) || \
+ defined(CONFIGURE_BDBUF_BUFFER_SIZE) || \
+ defined(CONFIGURE_BDBUF_BUFFER_COUNT)
+ #error BDBUF Cache does not use a buffer configuration table. Please remove.
+ #endif
+#else
+ #define CONFIGURE_LIBBLOCK_SEMAPHORES 0
+#endif /* CONFIGURE_APPLICATION_NEEDS_LIBBLOCK */
+
+#if defined(RTEMS_MULTIPROCESSING)
+ /*
+ * Default Multiprocessing Configuration Table. The defaults are
+ * appropriate for most of the RTEMS Multiprocessor Test Suite. Each
+ * value may be overridden within each test to customize the environment.
+ */
+
+ #ifdef CONFIGURE_MP_APPLICATION
+ #define CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER 1
+
+ #ifndef CONFIGURE_HAS_OWN_MULTIPROCESSING_TABLE
+
+ #ifndef CONFIGURE_MP_NODE_NUMBER
+ #define CONFIGURE_MP_NODE_NUMBER NODE_NUMBER
+ #endif
+
+ #ifndef CONFIGURE_MP_MAXIMUM_NODES
+ #define CONFIGURE_MP_MAXIMUM_NODES 2
+ #endif
+
+ #ifndef CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS
+ #define CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS 32
+ #endif
+ #define CONFIGURE_MEMORY_FOR_GLOBAL_OBJECTS(_global_objects) \
+ _Configure_Object_RAM((_global_objects), sizeof(Objects_MP_Control))
+
+ #ifndef CONFIGURE_MP_MAXIMUM_PROXIES
+ #define CONFIGURE_MP_MAXIMUM_PROXIES 32
+ #endif
+ #define CONFIGURE_MEMORY_FOR_PROXIES(_proxies) \
+ _Configure_Object_RAM((_proxies) + 1, sizeof(Thread_Proxy_control) )
+
+ #ifndef CONFIGURE_EXTRA_MPCI_RECEIVE_SERVER_STACK
+ #define CONFIGURE_EXTRA_MPCI_RECEIVE_SERVER_STACK 0
+ #endif
+
+ #ifndef CONFIGURE_MP_MPCI_TABLE_POINTER
+ #include <mpci.h>
+ #define CONFIGURE_MP_MPCI_TABLE_POINTER &MPCI_table
+ #endif
+
+ #ifdef CONFIGURE_INIT
+ rtems_multiprocessing_table Multiprocessing_configuration = {
+ CONFIGURE_MP_NODE_NUMBER, /* local node number */
+ CONFIGURE_MP_MAXIMUM_NODES, /* maximum # nodes */
+ CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS, /* maximum # global objects */
+ CONFIGURE_MP_MAXIMUM_PROXIES, /* maximum # proxies */
+ CONFIGURE_EXTRA_MPCI_RECEIVE_SERVER_STACK, /* MPCI stack > minimum */
+ CONFIGURE_MP_MPCI_TABLE_POINTER /* ptr to MPCI config table */
+ };
+ #endif
+
+ #define CONFIGURE_MULTIPROCESSING_TABLE &Multiprocessing_configuration
+
+ #endif /* CONFIGURE_HAS_OWN_MULTIPROCESSING_TABLE */
+
+ #else
+
+ #define CONFIGURE_MULTIPROCESSING_TABLE NULL
+
+ #endif /* CONFIGURE_MP_APPLICATION */
+#endif /* RTEMS_MULTIPROCESSING */
+
+#ifndef CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER
+ #define CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER 0
+#endif
+
+
+/*
+ * Default Configuration Table.
+ */
+
+#ifndef CONFIGURE_HAS_OWN_CONFIGURATION_TABLE
+
+ #ifndef CONFIGURE_MAXIMUM_TASKS
+ #define CONFIGURE_MAXIMUM_TASKS 0
+ #endif
+
+ #ifndef CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS
+ #define CONFIGURE_NOTEPADS_ENABLED TRUE
+ #else
+ #define CONFIGURE_NOTEPADS_ENABLED FALSE
+ #endif
+
+ #ifndef CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API \
+ _Configure_From_workspace( sizeof(RTEMS_API_Control) )
+ #else
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API \
+ _Configure_From_workspace( sizeof(RTEMS_API_Control) - \
+ (RTEMS_NUMBER_NOTEPADS * sizeof(uint32_t)))
+ #endif
+
+ /**
+ * This macro calculates the memory required for task variables.
+ *
+ * @note Each task variable is individually allocated from the Workspace.
+ * Hence, we do the multiplication on the configured size.
+ */
+ #ifndef CONFIGURE_MAXIMUM_TASK_VARIABLES
+ #define CONFIGURE_MAXIMUM_TASK_VARIABLES 0
+ #define CONFIGURE_MEMORY_FOR_TASK_VARIABLES(_task_variables) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_TASK_VARIABLES(_task_variables) \
+ (_task_variables) * \
+ _Configure_From_workspace(sizeof(rtems_task_variable_t))
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_TIMERS
+ #define CONFIGURE_MAXIMUM_TIMERS 0
+ #define CONFIGURE_MEMORY_FOR_TIMERS(_timers) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_TIMERS(_timers) \
+ _Configure_Object_RAM(_timers, sizeof(Timer_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_SEMAPHORES
+ #define CONFIGURE_MAXIMUM_SEMAPHORES 0
+ #endif
+
+ #define CONFIGURE_SEMAPHORES \
+ (CONFIGURE_MAXIMUM_SEMAPHORES + CONFIGURE_LIBIO_SEMAPHORES + \
+ CONFIGURE_TERMIOS_SEMAPHORES + CONFIGURE_LIBBLOCK_SEMAPHORES + \
+ CONFIGURE_SEMAPHORES_FOR_FIFOS)
+
+ /*
+ * If there are no user or support semaphores defined, then we can assume
+ * that no memory need be allocated at all for semaphores.
+ */
+ #if CONFIGURE_SEMAPHORES == 0
+ #define CONFIGURE_MEMORY_FOR_SEMAPHORES(_semaphores) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_SEMAPHORES(_semaphores) \
+ _Configure_Object_RAM(_semaphores, sizeof(Semaphore_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_MESSAGE_QUEUES
+ #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 0
+ #define CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(_queues) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(_queues) \
+ _Configure_Object_RAM(_queues, sizeof(Message_queue_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_PARTITIONS
+ #define CONFIGURE_MAXIMUM_PARTITIONS 0
+ #define CONFIGURE_MEMORY_FOR_PARTITIONS(_partitions) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_PARTITIONS(_partitions) \
+ _Configure_Object_RAM(_partitions, sizeof(Partition_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_REGIONS
+ #define CONFIGURE_MAXIMUM_REGIONS 0
+ #define CONFIGURE_MEMORY_FOR_REGIONS(_regions) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_REGIONS(_regions) \
+ _Configure_Object_RAM(_regions, sizeof(Region_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_PORTS
+ #define CONFIGURE_MAXIMUM_PORTS 0
+ #define CONFIGURE_MEMORY_FOR_PORTS(_ports) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_PORTS(_ports) \
+ _Configure_Object_RAM(_ports, sizeof(Dual_ported_memory_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_PERIODS
+ #define CONFIGURE_MAXIMUM_PERIODS 0
+ #define CONFIGURE_MEMORY_FOR_PERIODS(_periods) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_PERIODS(_periods) \
+ _Configure_Object_RAM(_periods, sizeof(Rate_monotonic_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_BARRIERS
+ #define CONFIGURE_MAXIMUM_BARRIERS 0
+ #endif
+
+ #define CONFIGURE_BARRIERS \
+ (CONFIGURE_MAXIMUM_BARRIERS + CONFIGURE_BARRIERS_FOR_FIFOS)
+
+ #if CONFIGURE_BARRIERS == 0
+ #define CONFIGURE_MEMORY_FOR_BARRIERS(_barriers) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_BARRIERS(_barriers) \
+ _Configure_Object_RAM(_barriers, sizeof(Barrier_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_USER_EXTENSIONS
+ #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 0
+ #define CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(_extensions) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(_extensions) \
+ _Configure_Object_RAM(_extensions, sizeof(Extension_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MICROSECONDS_PER_TICK
+ #define CONFIGURE_MICROSECONDS_PER_TICK \
+ RTEMS_MILLISECONDS_TO_MICROSECONDS(10)
+ #endif
+
+ #ifndef CONFIGURE_TICKS_PER_TIMESLICE
+ #define CONFIGURE_TICKS_PER_TIMESLICE 50
+ #endif
+
+/*
+ * Initial Extension Set
+ */
+
+#ifdef CONFIGURE_INIT
+#ifdef CONFIGURE_STACK_CHECKER_ENABLED
+#include <rtems/stackchk.h>
+#endif
+#include <rtems/libcsupport.h>
+
+#if defined(CONFIGURE_INITIAL_EXTENSIONS) || \
+ defined(CONFIGURE_STACK_CHECKER_ENABLED) || \
+ (defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))
+ rtems_extensions_table Configuration_Initial_Extensions[] = {
+ #if !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY)
+ RTEMS_NEWLIB_EXTENSION,
+ #endif
+ #if defined(CONFIGURE_STACK_CHECKER_ENABLED)
+ RTEMS_STACK_CHECKER_EXTENSION,
+ #endif
+ #if defined(CONFIGURE_INITIAL_EXTENSIONS)
+ CONFIGURE_INITIAL_EXTENSIONS,
+ #endif
+ };
+
+ #define CONFIGURE_INITIAL_EXTENSION_TABLE Configuration_Initial_Extensions
+ #define CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS \
+ ((sizeof(Configuration_Initial_Extensions) / \
+ sizeof(rtems_extensions_table)))
+#else
+ #define CONFIGURE_INITIAL_EXTENSION_TABLE NULL
+ #define CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS 0
+#endif
+
+
+#endif
+
+/*
+ * POSIX API Configuration Parameters
+ */
+
+#ifdef RTEMS_POSIX_API
+
+ #include <sys/types.h>
+ #include <signal.h>
+ #include <limits.h>
+ #include <mqueue.h>
+ #include <rtems/posix/barrier.h>
+ #include <rtems/posix/cond.h>
+ #include <rtems/posix/mqueue.h>
+ #include <rtems/posix/mutex.h>
+ #include <rtems/posix/key.h>
+ #include <rtems/posix/psignal.h>
+ #include <rtems/posix/rwlock.h>
+ #include <rtems/posix/semaphore.h>
+ #include <rtems/posix/spinlock.h>
+ #include <rtems/posix/threadsup.h>
+ #include <rtems/posix/timer.h>
+
+ /**
+ * Account for the object control structures plus the name
+ * of the object to be duplicated.
+ */
+ #define _Configure_POSIX_Named_Object_RAM(_number, _size) \
+ _Configure_Object_RAM( (_number), _size ) + \
+ ((_number) + _Configure_From_workspace(NAME_MAX) )
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_THREADS
+ #define CONFIGURE_MAXIMUM_POSIX_THREADS 0
+ #endif
+
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_POSIX_API \
+ _Configure_From_workspace( \
+ CONFIGURE_MINIMUM_TASK_STACK_SIZE + \
+ sizeof (POSIX_API_Control) + \
+ (sizeof (void *) * (CONFIGURE_MAXIMUM_POSIX_KEYS)) \
+ )
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_MUTEXES
+ #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_mutexes) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_mutexes) \
+ _Configure_Object_RAM(_mutexes, sizeof(POSIX_Mutex_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES
+ #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(_condvars) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(_condvars) \
+ _Configure_Object_RAM(_condvars, \
+ sizeof(POSIX_Condition_variables_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_KEYS
+ #define CONFIGURE_MAXIMUM_POSIX_KEYS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_KEYS(_keys) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_KEYS(_keys) \
+ _Configure_Object_RAM(_keys, sizeof(POSIX_Keys_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_TIMERS
+ #define CONFIGURE_MAXIMUM_POSIX_TIMERS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers) \
+ _Configure_Object_RAM(_timers, sizeof(POSIX_Timer_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS
+ #define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS(_queued_signals) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS(_queued_signals) \
+ _Configure_From_workspace( \
+ (_queued_signals) * (sizeof(POSIX_signals_Siginfo_node)) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES
+ #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(_message_queues) 0
+ #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUE_DESCRIPTORS(_fds) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(_message_queues) \
+ _Configure_POSIX_Named_Object_RAM( \
+ _message_queues, sizeof(POSIX_Message_queue_Control) )
+
+ /* default to same number */
+ #ifndef CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS
+ #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS \
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES
+ #endif
+
+ #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUE_DESCRIPTORS(_mqueue_fds) \
+ _Configure_POSIX_Named_Object_RAM( \
+ _mqueue_fds, sizeof(POSIX_Message_queue_Control_fd) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_SEMAPHORES
+ #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES(_semaphores) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES(_semaphores) \
+ _Configure_POSIX_Named_Object_RAM( \
+ _semaphores, sizeof(POSIX_Semaphore_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_BARRIERS
+ #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(_barriers) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(_barriers) \
+ _Configure_Object_RAM(_barriers, sizeof(POSIX_Barrier_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_SPINLOCKS
+ #define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS(_spinlocks) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS(_spinlocks) \
+ _Configure_Object_RAM(_spinlocks, sizeof(POSIX_Spinlock_Control) )
+ #endif
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_RWLOCKS
+ #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 0
+ #define CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) 0
+ #else
+ #define CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) \
+ _Configure_Object_RAM(_rwlocks, sizeof(POSIX_RWLock_Control) )
+ #endif
+
+ #ifdef CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+ #ifdef CONFIGURE_POSIX_HAS_OWN_INIT_THREAD_TABLE
+
+ /*
+ * The user is defining their own table information and setting the
+ * appropriate variables for the POSIX Initialization Thread Table.
+ */
+
+ #else
+
+ #ifndef CONFIGURE_POSIX_INIT_THREAD_ENTRY_POINT
+ #define CONFIGURE_POSIX_INIT_THREAD_ENTRY_POINT POSIX_Init
+ #endif
+
+ #ifndef CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE
+ #define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE \
+ (CONFIGURE_MINIMUM_TASK_STACK_SIZE * 2)
+ #endif
+
+ #ifdef CONFIGURE_INIT
+ posix_initialization_threads_table POSIX_Initialization_threads[] = {
+ { CONFIGURE_POSIX_INIT_THREAD_ENTRY_POINT, \
+ CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE }
+ };
+ #endif
+
+ #define CONFIGURE_POSIX_INIT_THREAD_TABLE_NAME \
+ POSIX_Initialization_threads
+
+ #define CONFIGURE_POSIX_INIT_THREAD_TABLE_SIZE \
+ sizeof(CONFIGURE_POSIX_INIT_THREAD_TABLE_NAME) / \
+ sizeof(posix_initialization_threads_table)
+
+ #endif /* CONFIGURE_POSIX_HAS_OWN_INIT_TASK_TABLE */
+
+ #else /* CONFIGURE_POSIX_INIT_THREAD_TABLE */
+
+ #define CONFIGURE_POSIX_INIT_THREAD_TABLE_NAME NULL
+ #define CONFIGURE_POSIX_INIT_THREAD_TABLE_SIZE 0
+
+ #endif
+
+ #define CONFIGURE_MEMORY_FOR_POSIX \
+ ( CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES + \
+ CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES) + \
+ CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( \
+ CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES + \
+ CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_CONDITION_VARIABLES) + \
+ CONFIGURE_MEMORY_FOR_POSIX_KEYS( CONFIGURE_MAXIMUM_POSIX_KEYS ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS( \
+ CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES( \
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUE_DESCRIPTORS( \
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( \
+ CONFIGURE_MAXIMUM_POSIX_SEMAPHORES ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(CONFIGURE_MAXIMUM_POSIX_BARRIERS) + \
+ CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS( \
+ CONFIGURE_MAXIMUM_POSIX_SPINLOCKS ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( \
+ CONFIGURE_MAXIMUM_POSIX_RWLOCKS ) + \
+ CONFIGURE_MEMORY_FOR_POSIX_TIMERS( CONFIGURE_MAXIMUM_POSIX_TIMERS ) + \
+ (CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE) \
+ )
+#else
+
+ #define CONFIGURE_MAXIMUM_POSIX_THREADS 0
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_POSIX_API 0
+ #define CONFIGURE_MEMORY_FOR_POSIX 0
+
+#endif /* RTEMS_POSIX_API */
+
+#ifndef CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE
+ #define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE 0
+#endif
+
+/*
+ * This block of defines are for applications which use GNAT/RTEMS.
+ * GNAT implements each Ada task as a POSIX thread.
+ */
+#ifdef CONFIGURE_GNAT_RTEMS
+
+ /**
+ * The GNAT run-time needs something less than (10) POSIX mutexes.
+ * We may be able to get by with less but why bother.
+ */
+ #define CONFIGURE_GNAT_MUTEXES 10
+
+ /**
+ * This is the maximum number of Ada tasks which can be concurrently
+ * in existence. Twenty (20) are required to run all tests in the
+ * ACATS (formerly ACVC).
+ */
+ #ifndef CONFIGURE_MAXIMUM_ADA_TASKS
+ #define CONFIGURE_MAXIMUM_ADA_TASKS 20
+ #endif
+
+ /**
+ * This is the number of non-Ada tasks which invoked Ada code.
+ */
+ #ifndef CONFIGURE_MAXIMUM_FAKE_ADA_TASKS
+ #define CONFIGURE_MAXIMUM_FAKE_ADA_TASKS 0
+ #endif
+
+ /**
+ * Ada tasks are allocated twice the minimum stack space.
+ */
+ #define CONFIGURE_ADA_TASKS_STACK \
+ (CONFIGURE_MAXIMUM_ADA_TASKS * \
+ (CONFIGURE_MINIMUM_TASK_STACK_SIZE + (6 * 1024)))
+
+#else
+ #define CONFIGURE_GNAT_MUTEXES 0
+ #define CONFIGURE_MAXIMUM_ADA_TASKS 0
+ #define CONFIGURE_MAXIMUM_FAKE_ADA_TASKS 0
+ #define CONFIGURE_ADA_TASKS_STACK 0
+#endif
+
+#ifdef CONFIGURE_ENABLE_GO
+
+ #ifndef CONFIGURE_MAXIMUM_POSIX_THREADS
+ #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
+ #endif
+ #ifndef CONFIGURE_MAXIMUM_POSIX_MUTEXES
+ #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1
+ #endif
+ #ifndef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES
+ #define CONFIGURE_MAXIMUM_CONDITION_VARIABLES 1
+ #endif
+
+ #define CONFIGURE_GO_INIT_MUTEXES 77
+ #define CONFIGURE_GO_INIT_CONDITION_VARIABLES 4
+
+ #ifndef CONFIGURE_MAXIMUM_GOROUTINES
+ #define CONFIGURE_MAXIMUM_GOROUTINES 400
+ #endif
+
+ #define CONFIGURE_GOROUTINES_TASK_VARIABLES \
+ (2 * CONFIGURE_MAXIMUM_GOROUTINES)
+
+ #ifndef CONFIGURE_MAXIMUM_GO_CHANNELS
+ #define CONFIGURE_MAXIMUM_GO_CHANNELS 500
+ #endif
+
+#else
+ #define CONFIGURE_GO_INIT_MUTEXES 0
+ #define CONFIGURE_GO_INIT_CONDITION_VARIABLES 0
+ #define CONFIGURE_MAXIMUM_GOROUTINES 0
+ #define CONFIGURE_GOROUTINES_TASK_VARIABLES 0
+ #define CONFIGURE_MAXIMUM_GO_CHANNELS 0
+#endif
+
+#ifndef RTEMS_SCHEDSIM
+/**
+ * This macro specifies the amount of memory to be reserved for the
+ * Newlib C Library reentrancy structure -- if we are using newlib.
+ */
+
+#if (defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))
+ #include <reent.h>
+
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB \
+ _Configure_From_workspace(sizeof(struct _reent))
+#else
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB 0
+#endif
+
+#else
+ #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB 0
+#endif
+
+
+/*
+ * Calculate the RAM size based on the maximum number of objects configured.
+ */
+
+#ifndef CONFIGURE_EXECUTIVE_RAM_SIZE
+
+/**
+ * Account for allocating the following per object
+ * + array of object control structures
+ * + local pointer table -- pointer per object plus a zero'th
+ * entry in the local pointer table.
+ */
+
+#define CONFIGURE_MEMORY_FOR_TASKS(_tasks, _number_FP_tasks) \
+ ( \
+ _Configure_Object_RAM(_tasks, sizeof(Thread_Control)) + \
+ (_Configure_Max_Objects(_tasks) * \
+ (_Configure_From_workspace(CONFIGURE_MINIMUM_TASK_STACK_SIZE) + \
+ CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API + \
+ CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB + \
+ CONFIGURE_MEMORY_PER_TASK_FOR_POSIX_API + \
+ CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER)) + \
+ _Configure_From_workspace( \
+ _Configure_Max_Objects(_number_FP_tasks) * CONTEXT_FP_SIZE) + \
+ _Configure_From_workspace( \
+ (CONFIGURE_MAXIMUM_USER_EXTENSIONS + 1) * sizeof(void *)) \
+ )
+
+/**
+ * This defines the amount of memory configured for the multiprocessing
+ * support required by this application.
+ */
+#ifdef CONFIGURE_MP_APPLICATION
+ #define CONFIGURE_MEMORY_FOR_MP \
+ (CONFIGURE_MEMORY_FOR_PROXIES(CONFIGURE_MP_MAXIMUM_PROXIES) + \
+ CONFIGURE_MEMORY_FOR_GLOBAL_OBJECTS( \
+ CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS) + \
+ CONFIGURE_MEMORY_FOR_TASKS(1, 1) + \
+ CONFIGURE_EXTRA_MPCI_RECEIVE_SERVER_STACK \
+ )
+#else
+ #define CONFIGURE_MEMORY_FOR_MP 0
+#endif
+
+/**
+ * This is so we can account for tasks with stacks greater than minimum
+ * size. This is in bytes.
+ */
+#ifndef CONFIGURE_EXTRA_TASK_STACKS
+ #define CONFIGURE_EXTRA_TASK_STACKS 0
+#endif
+
+/**
+ * The following macro is used to calculate the memory allocated by RTEMS
+ * for the message buffers associated with a particular message queue.
+ * There is a fixed amount of overhead per message.
+ */
+#define CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(_messages, _size) \
+ _Configure_From_workspace( \
+ (_messages) * ((_size) + sizeof(CORE_message_queue_Buffer_control)))
+
+/**
+ * This macros is set to the amount of memory required for pending message
+ * buffers in bytes. It should be constructed by adding together a
+ * set of values determined by CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE.
+ */
+#ifndef CONFIGURE_MESSAGE_BUFFER_MEMORY
+ #define CONFIGURE_MESSAGE_BUFFER_MEMORY 0
+#endif
+
+/**
+ * This macro is available just in case the confdefs.h file underallocates
+ * memory for a particular application. This lets the user add some extra
+ * memory in case something broken and underestimates.
+ *
+ * It is also possible for cases where confdefs.h overallocates memory,
+ * you could substract memory from the allocated. The estimate is just
+ * that, an estimate, and assumes worst case alignment and padding on
+ * each allocated element. So in some cases it could be too conservative.
+ *
+ * @note Historically this was used for message buffers.
+ */
+#ifndef CONFIGURE_MEMORY_OVERHEAD
+ #define CONFIGURE_MEMORY_OVERHEAD 0
+#endif
+
+/**
+ * On architectures that use Simple Vectored Interrupts, it is RTEMS
+ * responsibility to allocate the vector table. This avoids reserving
+ * the memory on architectures that use the Programmable Interrupt
+ * Controller Vectored Interrupts.
+ */
+#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
+ /*
+ * This is a (hopefully) temporary hack. On the mips, the number of
+ * vectors is NOT statically defined. But it has to be statically
+ * defined for this to work. This is an issue looking for a nice
+ * solution.
+ */
+ #if defined(__mips__)
+ #define CONFIGURE_INTERRUPT_VECTOR_TABLE \
+ _Configure_From_workspace( (sizeof(ISR_Handler_entry) * 256))
+ #else
+ #define CONFIGURE_INTERRUPT_VECTOR_TABLE \
+ _Configure_From_workspace( \
+ (sizeof(ISR_Handler_entry) * ISR_NUMBER_OF_VECTORS))
+ #endif
+#else
+ #define CONFIGURE_INTERRUPT_VECTOR_TABLE 0
+#endif
+
+/**
+ * RTEMS uses one instance of an internal mutex class. This accounts
+ * for that mutex
+ */
+#define CONFIGURE_API_MUTEX_MEMORY \
+ _Configure_Object_RAM(1, sizeof(API_Mutex_Control))
+
+/**
+ * This defines the formula used to compute the amount of memory
+ * reserved for IDLE task control structures and stacks.
+ */
+#define CONFIGURE_IDLE_TASKS(_count) \
+ (CONFIGURE_MEMORY_FOR_TASKS(_count, 0) + \
+ _count * _Configure_From_workspace( \
+ (CONFIGURE_IDLE_TASK_STACK_SIZE - CONFIGURE_MINIMUM_TASK_STACK_SIZE)))
+
+/**
+ * This calculates the amount of memory reserved for the IDLE tasks.
+ * In an SMP system, each CPU core has its own idle task.
+ */
+#if defined(RTEMS_SMP)
+ #define CONFIGURE_MEMORY_FOR_IDLE_TASK \
+ CONFIGURE_IDLE_TASKS(CONFIGURE_SMP_MAXIMUM_PROCESSORS)
+#else
+ #define CONFIGURE_MEMORY_FOR_IDLE_TASK \
+ CONFIGURE_IDLE_TASKS(1)
+#endif
+
+/**
+ * This macro accounts for general RTEMS system overhead.
+ */
+#define CONFIGURE_MEMORY_FOR_SYSTEM_OVERHEAD \
+ ( CONFIGURE_MEMORY_FOR_IDLE_TASK + /* IDLE and stack */ \
+ CONFIGURE_MEMORY_FOR_SCHEDULER + /* Scheduler */ \
+ CONFIGURE_INTERRUPT_VECTOR_TABLE + /* interrupt vectors */ \
+ CONFIGURE_INTERRUPT_STACK_MEMORY + /* interrupt stack */ \
+ CONFIGURE_API_MUTEX_MEMORY /* allocation mutex */ \
+ )
+
+/*
+ * Now account for any extra memory that initialization tasks or threads
+ * may have requested.
+ */
+
+/**
+ * This accounts for any extra memory required by the Classic API
+ * Initialization Task.
+ */
+#if (CONFIGURE_INIT_TASK_STACK_SIZE > CONFIGURE_MINIMUM_TASK_STACK_SIZE)
+ #define CONFIGURE_INITIALIZATION_THREADS_STACKS_CLASSIC_PART \
+ (CONFIGURE_INIT_TASK_STACK_SIZE - CONFIGURE_MINIMUM_TASK_STACK_SIZE)
+#else
+ #define CONFIGURE_INITIALIZATION_THREADS_STACKS_CLASSIC_PART 0
+#endif
+
+/**
+ * This accounts for any extra memory required by the POSIX API
+ * Initialization Thread.
+ */
+#if defined(RTEMS_POSIX_API) && \
+ (CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE > CONFIGURE_MINIMUM_TASK_STACK_SIZE)
+ #define CONFIGURE_INITIALIZATION_THREADS_STACKS_POSIX_PART \
+ (CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE - CONFIGURE_MINIMUM_TASK_STACK_SIZE)
+#else
+ #define CONFIGURE_INITIALIZATION_THREADS_STACKS_POSIX_PART 0
+#endif
+
+/**
+ * This macro provides a summation of the various initialization task
+ * and thread stack requirements.
+ */
+#define CONFIGURE_INITIALIZATION_THREADS_STACKS \
+ (CONFIGURE_INITIALIZATION_THREADS_STACKS_CLASSIC_PART + \
+ CONFIGURE_INITIALIZATION_THREADS_STACKS_POSIX_PART)
+
+/**
+ * This macro provides a summation of the various task and thread
+ * requirements.
+ */
+#define CONFIGURE_TOTAL_TASKS_AND_THREADS \
+ (CONFIGURE_MAXIMUM_TASKS + \
+ CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_ADA_TASKS + \
+ CONFIGURE_MAXIMUM_GOROUTINES)
+
+/**
+ * This macro reserves the memory required by the statically configured
+ * user extensions.
+ */
+#define CONFIGURE_MEMORY_FOR_STATIC_EXTENSIONS \
+ ((CONFIGURE_NEWLIB_EXTENSION * \
+ _Configure_From_workspace( sizeof(User_extensions_Control))) + \
+ (CONFIGURE_STACK_CHECKER_EXTENSION * \
+ _Configure_From_workspace( sizeof(User_extensions_Control))) \
+ )
+
+/**
+ * This macro provides a summation of the memory required by the
+ * Classic API as configured.
+ */
+#define CONFIGURE_MEMORY_FOR_CLASSIC \
+ (CONFIGURE_MEMORY_FOR_TASK_VARIABLES(CONFIGURE_MAXIMUM_TASK_VARIABLES + \
+ CONFIGURE_GOROUTINES_TASK_VARIABLES) + \
+ CONFIGURE_MEMORY_FOR_TIMERS(CONFIGURE_MAXIMUM_TIMERS + \
+ CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER ) + \
+ CONFIGURE_MEMORY_FOR_SEMAPHORES(CONFIGURE_SEMAPHORES) + \
+ CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(CONFIGURE_MAXIMUM_MESSAGE_QUEUES) + \
+ CONFIGURE_MEMORY_FOR_PARTITIONS(CONFIGURE_MAXIMUM_PARTITIONS) + \
+ CONFIGURE_MEMORY_FOR_REGIONS( CONFIGURE_MAXIMUM_REGIONS ) + \
+ CONFIGURE_MEMORY_FOR_PORTS(CONFIGURE_MAXIMUM_PORTS) + \
+ CONFIGURE_MEMORY_FOR_PERIODS(CONFIGURE_MAXIMUM_PERIODS) + \
+ CONFIGURE_MEMORY_FOR_BARRIERS(CONFIGURE_BARRIERS) + \
+ CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(CONFIGURE_MAXIMUM_USER_EXTENSIONS) \
+ )
+
+#if defined(RTEMS_SMP)
+ #define CONFIGURE_MEMORY_FOR_SMP \
+ (CONFIGURE_SMP_MAXIMUM_PROCESSORS * \
+ _Configure_From_workspace( CONFIGURE_INTERRUPT_STACK_SIZE ) \
+ )
+#else
+ #define CONFIGURE_MEMORY_FOR_SMP 0
+#endif
+
+#if defined(CONFIGURE_CONFDEFS_DEBUG) && defined(CONFIGURE_INIT)
+ /**
+ * This is a debug mechanism, so if you need to, the executable will
+ * have a structure with various partial values. Add to this as you
+ * need to. Viewing this structure in gdb combined with dumping
+ * the Configuration structures generated should help a lot in tracing
+ * down errors and analyzing where over and under allocations are.
+ */
+ typedef struct {
+ uint32_t SYSTEM_OVERHEAD;
+ uint32_t STATIC_EXTENSIONS;
+ uint32_t INITIALIZATION_THREADS_STACKS;
+
+ uint32_t PER_INTEGER_TASK;
+ uint32_t FP_OVERHEAD;
+ uint32_t CLASSIC;
+ uint32_t POSIX;
+
+ /* System overhead pieces */
+ uint32_t INTERRUPT_VECTOR_TABLE;
+ uint32_t INTERRUPT_STACK_MEMORY;
+ uint32_t THREAD_READY_CHAINS;
+ uint32_t MEMORY_FOR_IDLE_TASK;
+
+ /* Classic API Pieces */
+ uint32_t CLASSIC_TASKS;
+ uint32_t TASK_VARIABLES;
+ uint32_t TIMERS;
+ uint32_t SEMAPHORES;
+ uint32_t MESSAGE_QUEUES;
+ uint32_t PARTITIONS;
+ uint32_t REGIONS;
+ uint32_t PORTS;
+ uint32_t PERIODS;
+ uint32_t BARRIERS;
+ uint32_t USER_EXTENSIONS;
+#ifdef RTEMS_POSIX_API
+ /* POSIX API Pieces */
+ uint32_t POSIX_MUTEXES;
+ uint32_t POSIX_CONDITION_VARIABLES;
+ uint32_t POSIX_KEYS;
+ uint32_t POSIX_TIMERS;
+ uint32_t POSIX_QUEUED_SIGNALS;
+ uint32_t POSIX_MESSAGE_QUEUES;
+ uint32_t POSIX_SEMAPHORES;
+ uint32_t POSIX_BARRIERS;
+ uint32_t POSIX_SPINLOCKS;
+ uint32_t POSIX_RWLOCKS;
+#endif
+ } Configuration_Debug_t;
+
+ Configuration_Debug_t Configuration_Memory_Debug = {
+ /* General Information */
+ CONFIGURE_MEMORY_FOR_SYSTEM_OVERHEAD,
+ CONFIGURE_MEMORY_FOR_STATIC_EXTENSIONS,
+ CONFIGURE_INITIALIZATION_THREADS_STACKS,
+ CONFIGURE_MEMORY_FOR_TASKS(1, 0),
+ CONFIGURE_MEMORY_FOR_TASKS(0, 1),
+ CONFIGURE_MEMORY_FOR_CLASSIC,
+ CONFIGURE_MEMORY_FOR_POSIX,
+
+ /* System overhead pieces */
+ CONFIGURE_INTERRUPT_VECTOR_TABLE,
+ CONFIGURE_INTERRUPT_STACK_MEMORY,
+ CONFIGURE_MEMORY_FOR_THREAD_READY_CHAINS,
+ CONFIGURE_MEMORY_FOR_IDLE_TASK,
+
+ /* Classic API Pieces */
+ CONFIGURE_MEMORY_FOR_TASKS(CONFIGURE_MAXIMUM_TASKS, 0),
+ CONFIGURE_MEMORY_FOR_TASK_VARIABLES(CONFIGURE_MAXIMUM_TASK_VARIABLES +
+ CONFIGURE_GOROUTINES_TASK_VARIABLES),
+ CONFIGURE_MEMORY_FOR_TIMERS(CONFIGURE_MAXIMUM_TIMERS),
+ CONFIGURE_MEMORY_FOR_SEMAPHORES(CONFIGURE_SEMAPHORES),
+ CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(CONFIGURE_MAXIMUM_MESSAGE_QUEUES),
+ CONFIGURE_MEMORY_FOR_PARTITIONS(CONFIGURE_MAXIMUM_PARTITIONS),
+ CONFIGURE_MEMORY_FOR_REGIONS( CONFIGURE_MAXIMUM_REGIONS ),
+ CONFIGURE_MEMORY_FOR_PORTS(CONFIGURE_MAXIMUM_PORTS),
+ CONFIGURE_MEMORY_FOR_PERIODS(CONFIGURE_MAXIMUM_PERIODS),
+ CONFIGURE_MEMORY_FOR_BARRIERS(CONFIGURE_BARRIERS),
+ CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(CONFIGURE_MAXIMUM_USER_EXTENSIONS),
+
+#ifdef RTEMS_POSIX_API
+ /* POSIX API Pieces */
+ CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES +
+ CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES),
+ CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(
+ CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES +
+ CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_CONDITION_VARIABLES),
+ CONFIGURE_MEMORY_FOR_POSIX_KEYS( CONFIGURE_MAXIMUM_POSIX_KEYS ),
+ CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS(
+ CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS ),
+ CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES ),
+ CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( CONFIGURE_MAXIMUM_POSIX_SEMAPHORES ),
+ CONFIGURE_MEMORY_FOR_POSIX_BARRIERS( CONFIGURE_MAXIMUM_POSIX_BARRIERS ),
+ CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS( CONFIGURE_MAXIMUM_POSIX_SPINLOCKS ),
+ CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( CONFIGURE_MAXIMUM_POSIX_RWLOCKS ),
+ CONFIGURE_MEMORY_FOR_POSIX_TIMERS( CONFIGURE_MAXIMUM_POSIX_TIMERS ),
+#endif
+ };
+#endif
+
+/**
+ * This calculates the memory required for the executive workspace.
+ */
+#define CONFIGURE_EXECUTIVE_RAM_SIZE \
+(( \
+ CONFIGURE_MEMORY_FOR_SYSTEM_OVERHEAD + \
+ CONFIGURE_MEMORY_FOR_DEVFS + \
+ CONFIGURE_MEMORY_FOR_TASKS( \
+ CONFIGURE_TOTAL_TASKS_AND_THREADS, CONFIGURE_TOTAL_TASKS_AND_THREADS) + \
+ CONFIGURE_MEMORY_FOR_CLASSIC + \
+ CONFIGURE_MEMORY_FOR_POSIX + \
+ (CONFIGURE_MAXIMUM_POSIX_THREADS * CONFIGURE_MINIMUM_TASK_STACK_SIZE ) + \
+ (CONFIGURE_MAXIMUM_GOROUTINES * CONFIGURE_MINIMUM_TASK_STACK_SIZE) + \
+ CONFIGURE_INITIALIZATION_THREADS_STACKS + \
+ CONFIGURE_MEMORY_FOR_STATIC_EXTENSIONS + \
+ CONFIGURE_MEMORY_FOR_MP + \
+ CONFIGURE_MEMORY_FOR_SMP + \
+ CONFIGURE_MESSAGE_BUFFER_MEMORY + \
+ (CONFIGURE_MEMORY_OVERHEAD * 1024) + \
+ (CONFIGURE_EXTRA_TASK_STACKS) + (CONFIGURE_ADA_TASKS_STACK) \
+) & ~0x7)
+#endif
+
+#ifdef CONFIGURE_INIT
+ /**
+ * This is the Classic API Configuration Table.
+ */
+ rtems_api_configuration_table Configuration_RTEMS_API = {
+ CONFIGURE_MAXIMUM_TASKS,
+ CONFIGURE_NOTEPADS_ENABLED,
+ CONFIGURE_MAXIMUM_TIMERS + CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER,
+ CONFIGURE_SEMAPHORES,
+ CONFIGURE_MAXIMUM_MESSAGE_QUEUES,
+ CONFIGURE_MAXIMUM_PARTITIONS,
+ CONFIGURE_MAXIMUM_REGIONS,
+ CONFIGURE_MAXIMUM_PORTS,
+ CONFIGURE_MAXIMUM_PERIODS,
+ CONFIGURE_BARRIERS,
+ CONFIGURE_INIT_TASK_TABLE_SIZE,
+ CONFIGURE_INIT_TASK_TABLE
+ };
+
+ #ifdef RTEMS_POSIX_API
+ /**
+ * This is the POSIX API Configuration Table.
+ */
+ posix_api_configuration_table Configuration_POSIX_API = {
+ CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_ADA_TASKS +
+ CONFIGURE_MAXIMUM_GOROUTINES,
+ CONFIGURE_MAXIMUM_POSIX_MUTEXES + CONFIGURE_GNAT_MUTEXES +
+ CONFIGURE_MAXIMUM_ADA_TASKS + CONFIGURE_MAXIMUM_FAKE_ADA_TASKS +
+ CONFIGURE_GO_INIT_MUTEXES + CONFIGURE_MAXIMUM_GO_CHANNELS,
+ CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES +
+ CONFIGURE_MAXIMUM_ADA_TASKS + CONFIGURE_MAXIMUM_FAKE_ADA_TASKS +
+ CONFIGURE_GO_INIT_CONDITION_VARIABLES + CONFIGURE_MAXIMUM_GO_CHANNELS,
+ CONFIGURE_MAXIMUM_POSIX_KEYS,
+ CONFIGURE_MAXIMUM_POSIX_TIMERS,
+ CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS,
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES,
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS,
+ CONFIGURE_MAXIMUM_POSIX_SEMAPHORES,
+ CONFIGURE_MAXIMUM_POSIX_BARRIERS,
+ CONFIGURE_MAXIMUM_POSIX_RWLOCKS,
+ CONFIGURE_MAXIMUM_POSIX_SPINLOCKS,
+ CONFIGURE_POSIX_INIT_THREAD_TABLE_SIZE,
+ CONFIGURE_POSIX_INIT_THREAD_TABLE_NAME
+ };
+ #endif
+
+ /** This variable specifies the minimum stack size for tasks in an RTEMS
+ * application.
+ *
+ * @note This is left as a simple uint32_t so it can be externed as
+ * needed without requring being high enough logical to
+ * include the full configuration table.
+ */
+ uint32_t rtems_minimum_stack_size =
+ CONFIGURE_MINIMUM_TASK_STACK_SIZE;
+
+ /** This variable specifies the maximum priority value that
+ * a task may have. This must be a power of 2 between 4
+ * and 256 and is specified in terms of Classic API
+ * priority values.
+ *
+ * @note This is left as a simple uint8_t so it can be externed as
+ * needed without requring being high enough logical to
+ * include the full configuration table.
+ */
+ uint8_t rtems_maximum_priority = CONFIGURE_MAXIMUM_PRIORITY;
+
+ /**
+ * This is the primary Configuration Table for this application.
+ */
+ rtems_configuration_table Configuration = {
+ NULL, /* filled in by BSP */
+ CONFIGURE_EXECUTIVE_RAM_SIZE, /* required RTEMS workspace */
+ CONFIGURE_MAXIMUM_USER_EXTENSIONS, /* maximum dynamic extensions */
+ CONFIGURE_MICROSECONDS_PER_TICK, /* microseconds per clock tick */
+ CONFIGURE_TICKS_PER_TIMESLICE, /* ticks per timeslice quantum */
+ CONFIGURE_IDLE_TASK_BODY, /* user's IDLE task */
+ CONFIGURE_IDLE_TASK_STACK_SIZE, /* IDLE task stack size */
+ CONFIGURE_INTERRUPT_STACK_SIZE, /* interrupt stack size */
+ CONFIGURE_TASK_STACK_ALLOCATOR, /* stack allocator */
+ CONFIGURE_TASK_STACK_DEALLOCATOR, /* stack deallocator */
+ CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY, /* true to clear memory */
+ CONFIGURE_MAXIMUM_DRIVERS, /* maximum device drivers */
+ CONFIGURE_NUMBER_OF_DRIVERS, /* static device drivers */
+ Device_drivers, /* pointer to driver table */
+ CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS, /* number of static extensions */
+ CONFIGURE_INITIAL_EXTENSION_TABLE, /* pointer to static extensions */
+ #if defined(RTEMS_MULTIPROCESSING)
+ CONFIGURE_MULTIPROCESSING_TABLE, /* pointer to MP config table */
+ #endif
+ };
+#endif
+
+#endif /* CONFIGURE_HAS_OWN_CONFIGURATION_TABLE */
+
+#if defined(RTEMS_SMP)
+ /**
+ * Instantiate the variable which specifies the number of CPUs
+ * in an SMP configuration.
+ */
+ #if defined(CONFIGURE_INIT)
+ uint32_t rtems_smp_maximum_processors = CONFIGURE_SMP_MAXIMUM_PROCESSORS;
+ #else
+ extern uint32_t rtems_smp_maximum_processors;
+ #endif
+ /*
+ * Instantiate the Per CPU information based upon the user configuration.
+ */
+ #if defined(CONFIGURE_INIT)
+ Per_CPU_Control _Per_CPU_Information[CONFIGURE_SMP_MAXIMUM_PROCESSORS];
+ Per_CPU_Control *_Per_CPU_Information_p[CONFIGURE_SMP_MAXIMUM_PROCESSORS];
+ #endif
+
+#endif
+
+/*
+ * If the user has configured a set of Classic API Initialization Tasks,
+ * then we need to install the code that runs that loop.
+ */
+#ifdef CONFIGURE_INIT
+ #if defined(CONFIGURE_RTEMS_INIT_TASKS_TABLE) || \
+ defined(CONFIGURE_HAS_OWN_INIT_TASK_TABLE)
+ void (_RTEMS_tasks_Initialize_user_tasks_body)(void);
+ void (*_RTEMS_tasks_Initialize_user_tasks_p)(void) =
+ _RTEMS_tasks_Initialize_user_tasks_body;
+ #else
+ void (*_RTEMS_tasks_Initialize_user_tasks_p)(void) = NULL;
+ #endif
+#endif
+
+/*
+ * If the user has configured a set of POSIX Initialization Threads,
+ * then we need to install the code that runs that loop.
+ */
+#ifdef RTEMS_POSIX_API
+ #ifdef CONFIGURE_INIT
+ #if defined(CONFIGURE_POSIX_INIT_THREAD_TABLE) || \
+ defined(CONFIGURE_POSIX_HAS_OWN_INIT_THREAD_TABLE)
+ void _POSIX_Threads_Initialize_user_threads_body(void);
+ void (*_POSIX_Threads_Initialize_user_threads_p)(void) =
+ _POSIX_Threads_Initialize_user_threads_body;
+ #else
+ void (*_POSIX_Threads_Initialize_user_threads_p)(void) = NULL;
+ #endif
+ #endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/******************************************************************
+ ******************************************************************
+ ******************************************************************
+ * CONFIGURATION WARNINGS AND ERROR CHECKING *
+ ******************************************************************
+ ******************************************************************
+ ******************************************************************
+ */
+
+/*
+ * Make sure a task/thread of some sort is configured.
+ *
+ * When analyzing RTEMS to find the smallest possible of memory
+ * that must be allocated, you probably do want to configure 0
+ * tasks/threads so there is a smaller set of calls to _Workspace_Allocate
+ * to analyze.
+ */
+#if !defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION)
+ #if (CONFIGURE_MAXIMUM_TASKS == 0) && \
+ (CONFIGURE_MAXIMUM_POSIX_THREADS == 0) && \
+ (CONFIGURE_MAXIMUM_ADA_TASKS == 0) && \
+ (CONFIGURE_MAXIMUM_GOROUTINES == 0)
+ #error "CONFIGURATION ERROR: No tasks or threads configured!!"
+ #endif
+#endif
+
+#ifndef RTEMS_SCHEDSIM
+/*
+ * Make sure at least one of the initialization task/thread
+ * tables was defined.
+ */
+#if !defined(CONFIGURE_RTEMS_INIT_TASKS_TABLE) && \
+ !defined(CONFIGURE_POSIX_INIT_THREAD_TABLE) && \
+ !defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION)
+#error "CONFIGURATION ERROR: No initialization tasks or threads configured!!"
+#endif
+#endif
+
+/*
+ * If the user is trying to configure a multiprocessing application and
+ * RTEMS was not configured and built multiprocessing, then error out.
+ */
+#if defined(CONFIGURE_MP_APPLICATION) && \
+ !defined(RTEMS_MULTIPROCESSING)
+#error "CONFIGURATION ERROR: RTEMS not configured for multiprocessing!!"
+#endif
+
+/*
+ * If an attempt was made to configure POSIX objects and
+ * the POSIX API was not configured into RTEMS, error out.
+ */
+#if !defined(RTEMS_POSIX_API)
+ #if ((CONFIGURE_MAXIMUM_POSIX_THREADS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_MUTEXES != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_KEYS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_TIMERS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_SEMAPHORES != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_BARRIERS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_SPINLOCKS != 0) || \
+ (CONFIGURE_MAXIMUM_POSIX_RWLOCKS != 0) || \
+ defined(CONFIGURE_POSIX_INIT_THREAD_TABLE))
+ #error "CONFIGURATION ERROR: POSIX API support not configured!!"
+ #endif
+#endif
+
+#ifndef RTEMS_SCHEDSIM
+/*
+ * You must either explicity include or exclude the clock driver.
+ * It is such a common newbie error to leave it out. Maybe this
+ * will put an end to it.
+ *
+ * NOTE: If you are using the timer driver, it is considered
+ * mutually exclusive with the clock driver because the
+ * drivers are assumed to use the same "timer" hardware
+ * on many boards.
+ */
+#if !defined(CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE)
+ #if !defined(CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER) && \
+ !defined(CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER)
+ #error "CONFIGURATION ERROR: Do you want the clock driver or not?!?"
+ #endif
+#endif
+#endif
+
+/*
+ * These names have been obsoleted so make the user application stop compiling
+ */
+#if defined(CONFIGURE_TEST_NEEDS_TIMER_DRIVER) || \
+ defined(CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER) || \
+ defined(CONFIGURE_TEST_NEEDS_CLOCK_DRIVER) || \
+ defined(CONFIGURE_TEST_NEEDS_RTC_DRIVER) || \
+ defined(CONFIGURE_TEST_NEEDS_STUB_DRIVER)
+#error "CONFIGURATION ERROR: CONFIGURE_TEST_XXX constants are obsolete"
+#endif
+
+/*
+ * Validate the configured maximum priority
+ */
+#if ((CONFIGURE_MAXIMUM_PRIORITY != 3) && \
+ (CONFIGURE_MAXIMUM_PRIORITY != 7) && \
+ (CONFIGURE_MAXIMUM_PRIORITY != 15) && \
+ (CONFIGURE_MAXIMUM_PRIORITY != 31) && \
+ (CONFIGURE_MAXIMUM_PRIORITY != 63) && \
+ (CONFIGURE_MAXIMUM_PRIORITY != 127) && \
+ (CONFIGURE_MAXIMUM_PRIORITY != 255))
+ #error "Maximum priority is not 1 less than a power of 2 between 4 and 256"
+#endif
+
+#if (CONFIGURE_MAXIMUM_PRIORITY > PRIORITY_DEFAULT_MAXIMUM)
+ #error "Maximum priority configured higher than supported by target."
+#endif
+
+/*
+ * If you have fewer POSIX Message Queue Descriptors than actual
+ * POSIX Message Queues, then you will not be able to open all the
+ * queues.
+ */
+#if (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS < \
+ CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES)
+ #error "Fewer POSIX Message Queue descriptors than Queues!"
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/README b/cpukit/sapi/include/rtems/README
new file mode 100644
index 0000000000..f29bdb45b7
--- /dev/null
+++ b/cpukit/sapi/include/rtems/README
@@ -0,0 +1,133 @@
+#
+# $Id$
+#
+
+Configuring a System Using the Template in confdefs.h
+=====================================================
+
+The file confdefs.h is a Configuration Template file which can be
+used to greatly simplify the creation and maintenance of RTEMS
+Configuration Tables. The basic concepts are:
+
+ + confdefs.h provides defaults for all configuration parameters
+
+ + applications specify only those values they wish to override
+
+ + confdefs.h can be the only file which knows the precise layout
+ of the RTEMS Configuration Tables.
+
+The Configuration Template setup is used by all RTEMS tests to
+simplify the maintenance of the tests.
+
+Here is the section from the system.h file from test tm21 from
+the Timing Test Suite:
+
+ /* configuration information */
+
+ #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+ #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
+
+ #define CONFIGURE_MAXIMUM_TASKS 102
+ #define CONFIGURE_MAXIMUM_TIMERS 100
+ #define CONFIGURE_MAXIMUM_SEMAPHORES 100
+ #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 100
+ #define CONFIGURE_MAXIMUM_PARTITIONS 100
+ #define CONFIGURE_MAXIMUM_REGIONS 100
+ #define CONFIGURE_MAXIMUM_PORTS 100
+ #define CONFIGURE_MAXIMUM_PERIODS 100
+
+ #define CONFIGURE_TICKS_PER_TIMESLICE 0
+
+ #include <confdefs.h>
+
+
+The above example overrides a number of the configuration parameters.
+It informs the template that it is a member of the Timing Suite,
+requires a console and timer driver, and that it needs 102 tasks,
+100 timers, 100 semaphores, 100 message queues, 100 partitions,
+100 regions, 100 ports, and 100 periods. By default, the test
+would have gotten no drivers, 10 tasks, and no other RTEMS objects.
+
+The following shows the configuration tables generated by the
+template by default.
+
+
+#include <bsp.h>
+
+#define NULL_DRIVER_TABLE_ENTRY \
+ { NULL, NULL, NULL, NULL, NULL, NULL }
+
+rtems_driver_address_table Device_drivers[] = {
+#ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+ CONSOLE_DRIVER_TABLE_ENTRY,
+#endif
+#ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+ CLOCK_DRIVER_TABLE_ENTRY,
+#endif
+#ifdef CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
+ STUB_DRIVER_TABLE_ENTRY,
+#endif
+ NULL_DRIVER_TABLE_ENTRY,
+};
+
+rtems_initialization_tasks_table Initialization_tasks[] = {
+ { rtems_build_name( 'U', 'I', '1', ' ' ), /* init task name */
+ RTEMS_MINIMUM_STACK_SIZE, /* init task stack size */
+ 1, /* init task priority */
+ RTEMS_DEFAULT_ATTRIBUTES, /* init task attributes */
+ Init, /* init task entry point */
+ RTEMS_NO_PREEMPT, /* init task initial mode */
+ 0 /* init task argument list */
+ }
+};
+
+#ifdef CONFIGURE_MP_APPLICATION
+/*
+ * NODE_NUMBER is assumed to be set on the compile line.
+ */
+
+rtems_multiprocessing_table Multiprocessing_configuration = {
+ NODE_NUMBER, /* local node number */
+ 2, /* maximum # nodes in system */
+ 32, /* maximum # global objects */
+ 32, /* maximum # proxies */
+ &MPCI_table /* pointer to MPCI config table */
+};
+#endif
+
+/*
+ * CONFIGURE_EXECUTIVE_RAM_SIZE is a rough guess based on the number of
+ * tasks in the system plus enough extra to get a whole 64K extra.
+ *
+ * The NULL address for the workspace area is assumed to be assigned
+ * at startup time by the BSP.
+ */
+
+rtems_configuration_table Configuration = {
+ NULL, /* executive RAM work area */
+ CONFIGURE_EXECUTIVE_RAM_SIZE, /* executive RAM size */
+ 10, /* maximum # tasks */
+ 0, /* maximum # timers */
+ 0, /* maximum # semaphores */
+ 0, /* maximum # message queues */
+ 0, /* maximum # messages */
+ 0, /* maximum # partitions */
+ 0, /* maximum # regions */
+ 0, /* maximum # dp memory areas */
+ 0, /* maximum # periods */
+ 0, /* maximum # user extensions */
+ RTEMS_MILLISECONDS_TO_MICROSECONDS(10), /* # us in a tick */
+ 50, /* # ticks in a timeslice */
+ sizeof (Initialization_tasks) / sizeof(rtems_initialization_tasks_table),
+ /* number of init tasks */
+ Initialization_tasks, /* init task(s) table */
+ sizeof (Device_drivers) / sizeof(rtems_driver_address_table),
+ /* number of device drivers */
+ Device_drivers, /* pointer to driver address table */
+ NULL, /* pointer to initial extensions */
+#ifdef CONFIGURE_MP_APPLICATION
+ &Multiprocessing_configuration
+#else
+ NULL /* ptr to MP config table */
+#endif
+};
diff --git a/cpukit/sapi/include/rtems/chain.h b/cpukit/sapi/include/rtems/chain.h
new file mode 100644
index 0000000000..a80bb9c1e2
--- /dev/null
+++ b/cpukit/sapi/include/rtems/chain.h
@@ -0,0 +1,140 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicChains
+ *
+ * @brief Chain API.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_CHAIN_H
+#define _RTEMS_CHAIN_H
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/rtems/event.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicChains Chains
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief Chain API.
+ *
+ * @{
+ */
+
+typedef Chain_Node rtems_chain_node;
+
+typedef Chain_Control rtems_chain_control;
+
+/**
+ * @brief Chain initializer for an empty chain with designator @a name.
+ */
+#define RTEMS_CHAIN_INITIALIZER_EMPTY(name) \
+ CHAIN_INITIALIZER_EMPTY(name)
+
+/**
+ * @brief Chain definition for an empty chain with designator @a name.
+ */
+#define RTEMS_CHAIN_DEFINE_EMPTY(name) \
+ CHAIN_DEFINE_EMPTY(name)
+
+/** @} */
+
+#include <rtems/chain.inl>
+
+/**
+ * @addtogroup ClassicChains
+ *
+ * @{
+ */
+
+/**
+ * @brief Appends the @a node to the @a chain and sends the @a events to the
+ * @a task if the @a chain was empty before the append.
+ *
+ * @see rtems_chain_append_with_empty_check() and rtems_event_send().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ID No such task.
+ */
+rtems_status_code rtems_chain_append_with_notification(
+ rtems_chain_control *chain,
+ rtems_chain_node *node,
+ rtems_id task,
+ rtems_event_set events
+);
+
+/**
+ * @brief Prepends the @a node to the @a chain and sends the @a events to the
+ * @a task if the @a chain was empty before the prepend.
+ *
+ * @see rtems_chain_prepend_with_empty_check() and rtems_event_send().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ID No such task.
+ */
+rtems_status_code rtems_chain_prepend_with_notification(
+ rtems_chain_control *chain,
+ rtems_chain_node *node,
+ rtems_id task,
+ rtems_event_set events
+);
+
+/**
+ * @brief Gets the first @a node of the @a chain and sends the @a events to the
+ * @a task if the @a chain is empty after the get.
+ *
+ * @see rtems_chain_get_with_empty_check() and rtems_event_send().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ID No such task.
+ */
+rtems_status_code rtems_chain_get_with_notification(
+ rtems_chain_control *chain,
+ rtems_id task,
+ rtems_event_set events,
+ rtems_chain_node **node
+);
+
+/**
+ * @brief Gets the first @a node of the @a chain and sends the @a events to the
+ * @a task if the @a chain is empty afterwards.
+ *
+ * @see rtems_chain_get() and rtems_event_receive().
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_TIMEOUT Timeout.
+ */
+rtems_status_code rtems_chain_get_with_wait(
+ rtems_chain_control *chain,
+ rtems_event_set events,
+ rtems_interval timeout,
+ rtems_chain_node **node
+);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/config.h b/cpukit/sapi/include/rtems/config.h
new file mode 100644
index 0000000000..cdf33874d7
--- /dev/null
+++ b/cpukit/sapi/include/rtems/config.h
@@ -0,0 +1,273 @@
+/**
+ * @file rtems/config.h
+ */
+
+/*
+ * This include file contains the table of user defined configuration
+ * parameters.
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_CONFIG_H
+#define _RTEMS_CONFIG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Unlimited object support. Changes the configuration table entry for POSIX
+ * or RTEMS APIs to bounded only by the memory of the work-space.
+ *
+ * Use the macro to define the resource unlimited before placing in
+ * the configuration table.
+ */
+
+#include <rtems/score/object.h>
+#define RTEMS_UNLIMITED_OBJECTS OBJECTS_UNLIMITED_OBJECTS
+
+#define rtems_resource_unlimited(resource) \
+ ( resource | RTEMS_UNLIMITED_OBJECTS )
+
+/*
+ * This is kind of kludgy but it allows targets to totally ignore the
+ * optional APIs like POSIX safely.
+ */
+
+#ifdef RTEMS_POSIX_API
+#include <rtems/posix/config.h>
+#else
+typedef void *posix_api_configuration_table;
+#endif
+
+#include <rtems/rtems/config.h>
+
+#include <rtems/extension.h>
+#include <rtems/io.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+
+#if defined(RTEMS_MULTIPROCESSING)
+/*
+ * The following records define the Multiprocessor Configuration
+ * Table. This table defines the multiprocessor system
+ * characteristics which must be known by RTEMS in a multiprocessor
+ * system.
+ */
+typedef struct {
+ /** This is the local node number. */
+ uint32_t node;
+ /** This is the maximum number of nodes in system. */
+ uint32_t maximum_nodes;
+ /** This is the maximum number of global objects. */
+ uint32_t maximum_global_objects;
+ /** This is the maximum number of proxies. */
+ uint32_t maximum_proxies;
+
+ /** The MPCI Receive server is assumed to have a stack of at least
+ * minimum stack size. This field specifies the amount of extra
+ * stack this task will be given in bytes.
+ */
+ uint32_t extra_mpci_receive_server_stack;
+
+ /** This is a pointer to User/BSP provided MPCI Table. */
+ rtems_mpci_table *User_mpci_table;
+} rtems_multiprocessing_table;
+#endif
+
+/*
+ * The following records define the Configuration Table. The
+ * information contained in this table is required in all
+ * RTEMS systems, whether single or multiprocessor. This
+ * table primarily defines the following:
+ *
+ * + location and size of the RTEMS Workspace
+ * + microseconds per clock tick
+ * + clock ticks per task timeslice
+ * + required number of each object type for each API configured
+ */
+typedef struct {
+ /** This field specifies the base address of the RTEMS Workspace.
+ */
+ void *work_space_start;
+
+ /** This field specifies the size in bytes of the RTEMS Workspace.
+ */
+ uintptr_t work_space_size;
+
+ /** This field specifies the maximum number of dynamically installed
+ * used extensions.
+ */
+ uint32_t maximum_extensions;
+
+ /** This field specifies the number of microseconds which elapse
+ * between clock ticks. This is the basis for RTEMS timing.
+ */
+ uint32_t microseconds_per_tick;
+
+ /** This field specifies the number of ticks in each task's timeslice.
+ */
+ uint32_t ticks_per_timeslice;
+
+ /** This element points to the BSP's optional idle task which may override
+ * the default one provided with RTEMS.
+ */
+ Thread (*idle_task)( uintptr_t );
+
+ /** This field specifies the size of the IDLE task's stack. If less than or
+ * equal to the minimum stack size, then the IDLE task will have the minimum
+ * stack size.
+ */
+ uint32_t idle_task_stack_size;
+
+ /** This field specifies the size of the interrupt stack. If less than or
+ * equal to the minimum stack size, then the interrupt stack will be of
+ * minimum stack size.
+ */
+ uint32_t interrupt_stack_size;
+
+ /** The BSP may want to provide it's own stack allocation routines.
+ * In this case, the BSP will provide this stack allocation hook.
+ */
+ void * (*stack_allocate_hook)( size_t );
+
+ /** The BSP may want to provide it's own stack free routines.
+ * In this case, the BSP will provide this stack free hook.
+ */
+ void (*stack_free_hook)( void *);
+
+ /** If this element is TRUE, then RTEMS will zero the Executive Workspace.
+ * When this element is FALSE, it is assumed that the BSP or invoking
+ * environment has ensured that memory was cleared before RTEMS was
+ * invoked.
+ */
+ bool do_zero_of_workspace;
+
+ uint32_t maximum_drivers;
+ uint32_t number_of_device_drivers;
+ rtems_driver_address_table *Device_driver_table;
+ uint32_t number_of_initial_extensions;
+ rtems_extensions_table *User_extension_table;
+ #if defined(RTEMS_MULTIPROCESSING)
+ rtems_multiprocessing_table *User_multiprocessing_table;
+ #endif
+} rtems_configuration_table;
+
+/**
+ * This is the configuration table generated by confdefs.h.
+ */
+extern rtems_configuration_table Configuration;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ /**
+ * This points to the multiprocessing configuration table.
+ */
+ SAPI_EXTERN rtems_multiprocessing_table *_Configuration_MP_table;
+#endif
+
+#if defined(RTEMS_MULTIPROCESSING)
+ /**
+ * @brief RTEMS Multiprocessing Configuration Table
+ *
+ * This is the RTEMS Multiprocessing Configuration Table expected to
+ * be generated by confdefs.h.
+ */
+ extern rtems_multiprocessing_table Multiprocessing_configuration;
+#endif
+
+
+/*
+ * Some handy macros to avoid dependencies on either the BSP
+ * or the exact format of the configuration table.
+ */
+
+#define rtems_configuration_get_table() \
+ (&Configuration)
+
+#define rtems_configuration_get_work_space_start() \
+ (Configuration.work_space_start)
+
+#define rtems_configuration_get_work_space_size() \
+ (Configuration.work_space_size)
+
+#define rtems_configuration_get_maximum_extensions() \
+ (Configuration.maximum_extensions)
+
+#define rtems_configuration_get_microseconds_per_tick() \
+ (Configuration.microseconds_per_tick)
+#define rtems_configuration_get_milliseconds_per_tick() \
+ (Configuration.microseconds_per_tick / 1000)
+#define rtems_configuration_get_nanoseconds_per_tick() \
+ (Configuration.microseconds_per_tick * 1000)
+
+#define rtems_configuration_get_ticks_per_timeslice() \
+ (Configuration.ticks_per_timeslice)
+
+#define rtems_configuration_get_idle_task() \
+ (Configuration.idle_task)
+
+#define rtems_configuration_get_idle_task_stack_size() \
+ (Configuration.idle_task_stack_size)
+
+/* XXX We need to get this from the generated table
+ * since BSPs need it before the pointer is set.
+ * Eventually all should be done this way.
+ */
+extern rtems_configuration_table Configuration;
+
+#define rtems_configuration_get_interrupt_stack_size() \
+ (Configuration.interrupt_stack_size)
+
+#define rtems_configuration_get_stack_allocate_hook() \
+ (Configuration.stack_allocate_hook)
+
+#define rtems_configuration_get_stack_free_hook() \
+ (Configuration.stack_free_hook)
+
+/**
+ * This macro assists in accessing the field which indicates whether
+ * RTEMS is responsible for zeroing the Executive Workspace.
+ */
+#define rtems_configuration_get_do_zero_of_workspace() \
+ (Configuration.do_zero_of_workspace)
+
+#define rtems_configuration_get_number_of_device_drivers() \
+ (Configuration.number_of_device_drivers)
+
+#define rtems_configuration_get_device_driver_table() \
+ (Configuration.Device_driver_table)
+
+#define rtems_configuration_get_number_of_initial_extensions() \
+ (Configuration.number_of_initial_extensions)
+
+#define rtems_configuration_get_user_extension_table() \
+ (Configuration.User_extension_table)
+
+#if defined(RTEMS_MULTIPROCESSING)
+ #define rtems_configuration_get_user_multiprocessing_table() \
+ (Configuration.User_multiprocessing_table)
+#else
+ #define rtems_configuration_get_user_multiprocessing_table() NULL
+#endif
+
+#define rtems_configuration_get_rtems_api_configuration() \
+ (&Configuration_RTEMS_API)
+
+#define rtems_configuration_get_posix_api_configuration() \
+ (&Configuration_POSIX_API)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/extension.h b/cpukit/sapi/include/rtems/extension.h
new file mode 100644
index 0000000000..4a7e258818
--- /dev/null
+++ b/cpukit/sapi/include/rtems/extension.h
@@ -0,0 +1,259 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicUserExtensions
+ *
+ * @brief User Extensions API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_EXTENSION_H
+#define _RTEMS_EXTENSION_H
+
+#ifndef SAPI_EXT_EXTERN
+#define SAPI_EXT_EXTERN extern
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/userext.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/types.h>
+
+SAPI_EXT_EXTERN Objects_Information _Extension_Information;
+
+typedef struct {
+ Objects_Control Object;
+ User_extensions_Control Extension;
+} Extension_Control;
+
+void _Extension_Manager_initialization(void);
+
+typedef User_extensions_routine
+ rtems_extension RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
+
+/**
+ * @defgroup ClassicUserExtensions User Extensions
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief The User Extensions Manager allows the application developer to
+ * augment the executive by allowing them to supply extension routines which
+ * are invoked at critical system events.
+ *
+ * @section ClassicUserExtensionsSets Extension Sets
+ *
+ * An @ref User_extensions_Table "extension set" is defined as a set of
+ * routines which are invoked at each of the critical system events at which
+ * user extension routines are invoked. Together a set of these routines
+ * typically perform a specific functionality such as performance monitoring or
+ * debugger support.
+ *
+ * RTEMS allows the user to have multiple extension sets active at the same
+ * time. First, a single static extension set may be defined as the
+ * application's User Extension Table which is included as part of the
+ * Configuration Table. This extension set is active for the entire life of the
+ * system and may not be deleted. This extension set is especially important
+ * because it is the only way the application can provided a fatal error
+ * extension which is invoked if RTEMS fails during the
+ * rtems_initialize_data_structures() directive. The static extension set is
+ * optional and may be configured as @c NULL if no static extension set is
+ * required.
+ *
+ * Second, the user can install dynamic extensions using the
+ * rtems_extension_create() directive. These extensions are RTEMS objects in
+ * that they have a name, an ID, and can be dynamically created and deleted. In
+ * contrast to the static extension set, these extensions can only be created
+ * and installed after the rtems_initialize_data_structures() directive
+ * successfully completes execution. Dynamic extensions are useful for
+ * encapsulating the functionality of an extension set. For example, the
+ * application could use extensions to manage a special coprocessor, do
+ * performance monitoring, and to do stack bounds checking. Each of these
+ * extension sets could be written and installed independently of the others.
+ *
+ * All user extensions are optional and RTEMS places no naming restrictions on
+ * the user. The user extension entry points are copied into an internal RTEMS
+ * structure. This means the user does not need to keep the table after
+ * creating it, and changing the handler entry points dynamically in a table
+ * once created has no effect. Creating a table local to a function can save
+ * space in space limited applications.
+ *
+ * Extension switches do not effect the context switch overhead if no switch
+ * handler is installed.
+ *
+ * @section ClassicUserExtensionsTCB Task Control Block Area
+ *
+ * RTEMS provides for a pointer to a user-defined data area for each extension
+ * set to be linked to each task's control block (TCB). This area is only
+ * available for the dynamic extensions. This set of pointers is an extension
+ * of the TCB and can be used to store additional data required by the user's
+ * extension functions. It is also possible for a user extension to utilize the
+ * notepad locations associated with each task although this may conflict with
+ * application usage of those particular notepads.
+ *
+ * The TCB extension is an array of pointers in the TCB. The index into the
+ * table can be obtained from the extension identifier returned when the
+ * extension is created:
+ *
+ * @code
+ * rtems_tcb *task = some_task;
+ * size_t index = rtems_object_id_get_index(extension_id);
+ * void *extension_data = task->extensions [index];
+ * @endcode
+ *
+ * The number of pointers in the area is the same as the number of user
+ * extension sets configured. This allows an application to augment the TCB
+ * with user-defined information. For example, an application could implement
+ * task profiling by storing timing statistics in the TCB's extended memory
+ * area. When a task context switch is being executed, the task switch
+ * extension could read a real-time clock to calculate how long the task being
+ * swapped out has run as well as timestamp the starting time for the task
+ * being swapped in.
+ *
+ * If used, the extended memory area for the TCB should be allocated and the
+ * TCB extension pointer should be set at the time the task is created or
+ * started by either the task create or task start extension. The application
+ * is responsible for managing this extended memory area for the TCBs. The
+ * memory may be reinitialized by the task restart extension and should be
+ * deallocated by the task delete extension when the task is deleted. Since the
+ * TCB extension buffers would most likely be of a fixed size, the RTEMS
+ * partition manager could be used to manage the application's extended memory
+ * area. The application could create a partition of fixed size TCB extension
+ * buffers and use the partition manager's allocation and deallocation
+ * directives to obtain and release the extension buffers.
+ *
+ * @section ClassicUserExtensionsOrder Order of Invokation
+ *
+ * When one of the critical system events occur, the user extensions are
+ * invoked in either @a forward or @a reverse order. Forward order indicates
+ * that the static extension set is invoked followed by the dynamic extension
+ * sets in the order in which they were created. Reverse order means that the
+ * dynamic extension sets are invoked in the opposite of the order in which
+ * they were created followed by the static extension set. By invoking the
+ * extension sets in this order, extensions can be built upon one another. At
+ * the following system events, the extensions are invoked in forward order:
+ *
+ * - Task creation
+ * - Task start
+ * - Task restart
+ * - Task context switch
+ * - Post task context switch
+ * - Task begins to execute
+ *
+ * At the following system events, the extensions are invoked in reverse order:
+ *
+ * - Task exit
+ * - Task deletion
+ * - Fatal error detection
+ *
+ * At these system events, the extensions are invoked in reverse order to
+ * insure that if an extension set is built upon another, the more complicated
+ * extension is invoked before the extension set it is built upon. For example,
+ * by invoking the static extension set last it is known that the "system"
+ * fatal error extension will be the last fatal error extension executed.
+ * Another example is use of the task delete extension by the Standard C
+ * Library. Extension sets which are installed after the Standard C Library
+ * will operate correctly even if they utilize the C Library because the C
+ * Library's task delete extension is invoked after that of the other
+ * extensions.
+ *
+ * @{
+ */
+
+typedef User_extensions_thread_create_extension rtems_task_create_extension;
+typedef User_extensions_thread_delete_extension rtems_task_delete_extension;
+typedef User_extensions_thread_start_extension rtems_task_start_extension;
+typedef User_extensions_thread_restart_extension rtems_task_restart_extension;
+typedef User_extensions_thread_switch_extension rtems_task_switch_extension;
+typedef User_extensions_thread_begin_extension rtems_task_begin_extension;
+typedef User_extensions_thread_exitted_extension rtems_task_exitted_extension;
+typedef User_extensions_fatal_extension rtems_fatal_extension;
+
+typedef User_extensions_Table rtems_extensions_table;
+
+/**
+ * @brief Creates an extension set object.
+ *
+ * This directive creates a extension set object from the extension table
+ * @a extension_table. The assigned extension set identifier is returned in
+ * @a id. The identifier is used to access this extension set in other
+ * extension set related directives. The name @a name will be assigned to the
+ * extension set object.
+ *
+ * Newly created extension sets are immediately installed and are invoked upon
+ * the next system event supporting an extension.
+ *
+ * This directive will not cause the calling task to be preempted.
+ *
+ * @retval RTEMS_SUCCESSFUL Extension set created successfully.
+ * @retval RTEMS_INVALID_ADDRESS Identifier pointer is @c NULL.
+ * @retval RTEMS_INVALID_NAME Invalid extension set name.
+ * @retval RTEMS_TOO_MANY Too many extension sets created.
+ */
+rtems_status_code rtems_extension_create(
+ rtems_name name,
+ const rtems_extensions_table *extension_table,
+ rtems_id *id
+);
+
+/**
+ * @brief Identifies an extension set object by a name.
+ *
+ * This directive obtains an extension set identifier in @a id associated with
+ * the extension set name @a name. If the extension set name is not unique,
+ * then the extension set identifier will match one of the extension sets with
+ * that name. However, this extension set identifier is not guaranteed to
+ * correspond to the desired extension set. The extension set identifier is
+ * used to access this extension set in other extension set related directives.
+ *
+ * This directive will not cause the calling task to be preempted.
+ *
+ * @retval RTEMS_SUCCESSFUL Extension set identified successfully.
+ * @retval RTEMS_INVALID_ADDRESS Identifier pointer is @c NULL.
+ * @retval RTEMS_INVALID_NAME Extension set name not found or invalid name.
+ */
+rtems_status_code rtems_extension_ident(
+ rtems_name name,
+ rtems_id *id
+);
+
+/**
+ * @brief Deletes an extension set object specified by the identifier @a id.
+ *
+ * Any subsequent references to the extension's name and identifier are
+ * invalid.
+ *
+ * This directive will not cause the calling task to be preempted.
+ *
+ * @retval RTEMS_SUCCESSFUL Extension set deleted successfully.
+ * @retval RTEMS_INVALID_ID Invalid extension set identifier.
+ */
+rtems_status_code rtems_extension_delete(
+ rtems_id id
+);
+
+/** @} */
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/extension.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/fatal.h b/cpukit/sapi/include/rtems/fatal.h
new file mode 100644
index 0000000000..63942aad97
--- /dev/null
+++ b/cpukit/sapi/include/rtems/fatal.h
@@ -0,0 +1,53 @@
+/**
+ * @file rtems/fatal.h
+ */
+
+/*
+ * This include file contains constants and prototypes related
+ * to the Fatal Error Manager. This manager processes all fatal or
+ * irrecoverable errors.
+ *
+ * This manager provides directives to:
+ *
+ * + announce a fatal error has occurred
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_FATAL_H
+#define _RTEMS_FATAL_H
+
+#include <rtems/score/basedefs.h> /* RTEMS_COMPILER_NO_RETURN_ATTRIBUTE */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * rtems_fatal_error_occurred
+ *
+ * DESCRIPTION:
+ *
+ * This is the routine which implements the rtems_fatal_error_occurred
+ * directive. It is invoked when the application or RTEMS
+ * determines that a fatal error has occurred.
+ */
+
+void rtems_fatal_error_occurred(
+ uint32_t the_error
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/init.h b/cpukit/sapi/include/rtems/init.h
new file mode 100644
index 0000000000..8cc7aa5c31
--- /dev/null
+++ b/cpukit/sapi/include/rtems/init.h
@@ -0,0 +1,100 @@
+/**
+ * @file rtems/init.h
+ *
+ *
+ * This include file contains all the constants and structures associated
+ * with the Initialization Manager. This manager is responsible for
+ * initializing RTEMS, creating and starting all configured initialization
+ * tasks, invoking the initialization routine for each user-supplied device
+ * driver, and initializing the optional multiprocessor layer.
+ *
+ * This manager provides directives to:
+ *
+ * + initialize the RTEMS executive
+ * + shutdown the RTEMS executive
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_INIT_H
+#define _RTEMS_INIT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/rtems/types.h>
+#include <rtems/config.h>
+#include <rtems/rtems/intr.h>
+
+#if defined(RTEMS_MULTIPROCESSING)
+/**
+ * The following defines the default Multiprocessing Configuration
+ * Table. This table is used in a single processor system.
+ */
+extern const rtems_multiprocessing_table
+ _Initialization_Default_multiprocessing_table;
+#endif
+
+/**
+ * @brief rtems_initialize_data_structures
+ *
+ * This routine implements the portion of the RTEMS initializatin process
+ * that involves initializing data structures to a state that scheduling
+ * can occur in a consistent manner.
+ */
+void rtems_initialize_data_structures(void);
+
+/**
+ * @brief rtems_initialize_before_drivers
+ *
+ * This routine implements the portion of RTEMS initialization that
+ * is done immediately before device drivers are initialized.
+ */
+void rtems_initialize_before_drivers(void);
+
+/**
+ * @brief rtems_initialize_device_drivers
+ *
+ * This routine implements the portion of RTEMS initialization that
+ * initializes all device drivers.
+ */
+void rtems_initialize_device_drivers(void);
+
+/**
+ * @brief rtems_initialize_start_multitasking
+ *
+ * This routine implements the early portion of rtems_initialize_executive
+ * directive up to the pretasking hook. This directive is invoked at system
+ * startup to initialize the RTEMS multitasking environment.
+ */
+void rtems_initialize_start_multitasking(void);
+
+/**
+ * @brief rtems_shutdown_executive
+ *
+ * This routine implements the rtems_shutdown_executive directive. The
+ * invocation of this directive results in the RTEMS environment being
+ * shutdown and multitasking halted. From the application's perspective,
+ * invocation of this directive results in the rtems_initialize_executive
+ * directive exitting to the startup code which invoked it.
+ */
+void rtems_shutdown_executive(
+ uint32_t result
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/io.h b/cpukit/sapi/include/rtems/io.h
new file mode 100644
index 0000000000..e47d66556d
--- /dev/null
+++ b/cpukit/sapi/include/rtems/io.h
@@ -0,0 +1,204 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicIO
+ *
+ * @brief Classic Input/Output Manager API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_IO_H
+#define _RTEMS_IO_H
+
+#ifndef SAPI_IO_EXTERN
+#define SAPI_IO_EXTERN extern
+#endif
+
+#include <rtems/rtems/status.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicIO Input/Output
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @{
+ */
+
+typedef uint32_t rtems_device_major_number;
+
+typedef uint32_t rtems_device_minor_number;
+
+typedef rtems_status_code rtems_device_driver;
+
+typedef rtems_device_driver (*rtems_device_driver_entry)(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+typedef struct {
+ rtems_device_driver_entry initialization_entry;
+ rtems_device_driver_entry open_entry;
+ rtems_device_driver_entry close_entry;
+ rtems_device_driver_entry read_entry;
+ rtems_device_driver_entry write_entry;
+ rtems_device_driver_entry control_entry;
+} rtems_driver_address_table;
+
+/**
+ * @name Device Driver Maintainance
+ *
+ * @{
+ */
+
+/**
+ * @brief Returns @c RTEMS_IO_ERROR.
+ *
+ * @retval RTEMS_IO_ERROR Only this one.
+ */
+rtems_status_code rtems_io_driver_io_error(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Registers and initializes the device with the device driver table
+ * @a driver_table and major number @a major.
+ *
+ * If the major number equals zero a major number will be obtained. The major
+ * number of the registered driver will be returned in @a registered_major.
+ *
+ * After a successful registration rtems_io_initialize() will be called to
+ * initialize the device.
+ *
+ * @retval RTEMS_SUCCESSFUL Device successfully registered and initialized.
+ * @retval RTEMS_INVALID_ADDRESS Pointer to driver table or to registered
+ * major number are invalid. Device driver table is empty.
+ * @retval RTEMS_INVALID_NUMBER Invalid major number.
+ * @retval RTEMS_TOO_MANY No major number available.
+ * @retval RTEMS_RESOURCE_IN_USE Major number in use.
+ * @retval RTEMS_CALLED_FROM_ISR Called from interrupt context.
+ * @retval * Status code depends on rtems_io_initialize().
+ */
+rtems_status_code rtems_io_register_driver(
+ rtems_device_major_number major,
+ const rtems_driver_address_table *driver_table,
+ rtems_device_major_number *registered_major
+);
+
+/**
+ * @brief Unregisters the device driver with number @a major.
+ *
+ * @retval RTEMS_SUCCESSFUL Device driver successfully unregistered.
+ * @retval RTEMS_UNSATISFIED Invalid major number.
+ * @retval RTEMS_CALLED_FROM_ISR Called from interrupt context.
+ */
+rtems_status_code rtems_io_unregister_driver(
+ rtems_device_major_number major
+);
+
+/**
+ * @brief Registers the name @a device_name in the file system for the device
+ * with number tuple @a major and @a minor.
+ *
+ * @retval RTEMS_SUCCESSFUL Name successfully registered.
+ * @retval RTEMS_TOO_MANY Name already in use or other errors.
+ */
+rtems_status_code rtems_io_register_name(
+ const char *device_name,
+ rtems_device_major_number major,
+ rtems_device_minor_number minor
+);
+
+/** @} */
+
+/**
+ * @name Device Driver Invocation
+ *
+ * @{
+ */
+
+rtems_status_code rtems_io_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+);
+
+rtems_status_code rtems_io_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+);
+
+rtems_status_code rtems_io_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+);
+
+rtems_status_code rtems_io_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+);
+
+rtems_status_code rtems_io_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+);
+
+rtems_status_code rtems_io_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+);
+
+/** @} */
+
+/** @} */
+
+typedef struct {
+ char *device_name;
+ size_t device_name_length;
+ rtems_device_major_number major;
+ rtems_device_minor_number minor;
+} rtems_driver_name_t;
+
+/**
+ * @deprecated Use stat() instead.
+ */
+rtems_status_code rtems_io_lookup_name(
+ const char *name,
+ rtems_driver_name_t *device_info
+) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
+
+SAPI_IO_EXTERN uint32_t _IO_Number_of_drivers;
+
+SAPI_IO_EXTERN rtems_driver_address_table *_IO_Driver_address_table;
+
+void _IO_Manager_initialization( void );
+
+void _IO_Initialize_all_drivers( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/mptables.h b/cpukit/sapi/include/rtems/mptables.h
new file mode 100644
index 0000000000..bcb51c5e96
--- /dev/null
+++ b/cpukit/sapi/include/rtems/mptables.h
@@ -0,0 +1,28 @@
+/* mptables.h
+ *
+ * This include file contains the executive's pre-initialized tables
+ * used in a multiprocessor configuration.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_MPTABLES_H
+#define _RTEMS_MPTABLES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/include/rtems/sptables.h b/cpukit/sapi/include/rtems/sptables.h
new file mode 100644
index 0000000000..e4fbd226bf
--- /dev/null
+++ b/cpukit/sapi/include/rtems/sptables.h
@@ -0,0 +1,75 @@
+/**
+ * @file rtems/sptables.h
+ *
+ * This include file contains the executive's pre-initialized tables
+ * used when in a single processor configuration.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SPTABLES_H
+#define _RTEMS_SPTABLES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/config.h>
+
+#include <rtems/debug.h>
+#include <rtems/fatal.h>
+#include <rtems/init.h>
+#include <rtems/io.h>
+#include <rtems/score/sysstate.h>
+
+#include <rtems/rtems/intr.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/rtems/event.h>
+#include <rtems/rtems/message.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/mp.h>
+#endif
+#include <rtems/rtems/part.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/rtems/region.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/rtems/timer.h>
+
+#if defined(RTEMS_MULTIPROCESSING)
+/*
+ * This is the default Multiprocessing Configuration Table.
+ * It is used in single processor configurations.
+ */
+ #if defined(SAPI_INIT)
+ const rtems_multiprocessing_table
+ _Initialization_Default_multiprocessing_table = {
+ 1, /* local node number */
+ 1, /* maximum number nodes in system */
+ 0, /* maximum number global objects */
+ 0, /* maximum number proxies */
+ STACK_MINIMUM_SIZE, /* MPCI receive server stack size */
+ NULL, /* pointer to MPCI address table */
+ };
+ #else
+ extern const rtems_multiprocessing_table
+ _Initialization_Default_multiprocessing_table;
+ #endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/sapi/inline/rtems/chain.inl b/cpukit/sapi/inline/rtems/chain.inl
new file mode 100644
index 0000000000..2816e81b41
--- /dev/null
+++ b/cpukit/sapi/inline/rtems/chain.inl
@@ -0,0 +1,561 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicChains
+ *
+ * @brief Chain API.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_CHAIN_H
+# error "Never use <rtems/chain.inl> directly; include <rtems/chain.h> instead."
+#endif
+
+#ifndef _RTEMS_CHAIN_INL
+#define _RTEMS_CHAIN_INL
+
+#include <rtems/score/chain.inl>
+
+/**
+ * @addtogroup ClassicChains
+ *
+ * @{
+ */
+
+/**
+ * @brief Initialize a Chain Header
+ *
+ * This routine initializes @a the_chain structure to manage the
+ * contiguous array of @a number_nodes nodes which starts at
+ * @a starting_address. Each node is of @a node_size bytes.
+ *
+ * @param[in] the_chain specifies the chain to initialize
+ * @param[in] starting_address is the starting address of the array
+ * of elements
+ * @param[in] number_nodes is the number of nodes that will be in the chain
+ * @param[in] node_size is the size of each node
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_initialize(
+ rtems_chain_control *the_chain,
+ void *starting_address,
+ size_t number_nodes,
+ size_t node_size
+)
+{
+ _Chain_Initialize( the_chain, starting_address, number_nodes, node_size );
+}
+
+/**
+ * @brief Initialize this Chain as Empty
+ *
+ * This routine initializes the specified chain to contain zero nodes.
+ *
+ * @param[in] the_chain is the chain to be initialized.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_initialize_empty(
+ rtems_chain_control *the_chain
+)
+{
+ _Chain_Initialize_empty( the_chain );
+}
+
+/**
+ * @brief Set off chain
+ *
+ * This function sets the next and previous fields of the @a node to NULL
+ * indicating the @a node is not part of a chain.
+ *
+ * @param[in] node the node set to off chain.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_set_off_chain(
+ rtems_chain_node *node
+)
+{
+ _Chain_Set_off_chain( node );
+}
+
+/**
+ * @brief Is the Node off Chain
+ *
+ * This function returns true if the @a node is not on a chain. A @a node is
+ * off chain if the next and previous fields are set to NULL.
+ *
+ * @param[in] node is the node off chain.
+ *
+ * @return This function returns true if the @a node is off chain.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_node_off_chain(
+ const rtems_chain_node *node
+)
+{
+ return _Chain_Is_node_off_chain( node );
+}
+
+/**
+ * @brief Is the Chain Node Pointer NULL
+ *
+ * This function returns true if the_node is NULL and false otherwise.
+ *
+ * @param[in] the_node is the node pointer to check.
+ *
+ * @return This method returns true if the_node is NULL and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_null_node(
+ const rtems_chain_node *the_node
+)
+{
+ return _Chain_Is_null_node( the_node );
+}
+
+/**
+ * @brief Return pointer to Chain Head
+ *
+ * This function returns a pointer to the first node on the chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the permanent node of the chain.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_head(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_Head( the_chain );
+}
+
+/**
+ * @brief Return pointer to Chain Tail
+ *
+ * This function returns a pointer to the last node on the chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the permanent tail node of the chain.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_tail(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_Tail( the_chain );
+}
+
+/**
+ * @brief Return pointer to Chain's First node after the permanent head.
+ *
+ * This function returns a pointer to the first node on the chain after the
+ * head.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the first node of the chain.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_first(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_First( the_chain );
+}
+
+/**
+ * @brief Return pointer to Chain's Last node before the permanent tail.
+ *
+ * This function returns a pointer to the last node on the chain just before
+ * the tail.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the last node of the chain.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_last(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_Last( the_chain );
+}
+
+/**
+ * @brief Return pointer the next node from this node
+ *
+ * This function returns a pointer to the next node after this node.
+ *
+ * @param[in] the_node is the node to be operated upon.
+ *
+ * @return This method returns the next node on the chain.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_next(
+ rtems_chain_node *the_node
+)
+{
+ return _Chain_Next( the_node );
+}
+
+/**
+ * @brief Return pointer the previous node from this node
+ *
+ * This function returns a pointer to the previous node on this chain.
+ *
+ * @param[in] the_node is the node to be operated upon.
+ *
+ * @return This method returns the previous node on the chain.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_previous(
+ rtems_chain_node *the_node
+)
+{
+ return _Chain_Previous( the_node );
+}
+
+/**
+ * @brief Are Two Nodes Equal
+ *
+ * This function returns true if @a left and @a right are equal,
+ * and false otherwise.
+ *
+ * @param[in] left is the node on the left hand side of the comparison.
+ * @param[in] right is the node on the left hand side of the comparison.
+ *
+ * @return This function returns true if @a left and @a right are equal,
+ * and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_are_nodes_equal(
+ const rtems_chain_node *left,
+ const rtems_chain_node *right
+)
+{
+ return _Chain_Are_nodes_equal( left, right );
+}
+
+/**
+ * @brief Is the Chain Empty
+ *
+ * This function returns true if there a no nodes on @a the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This function returns true if there a no nodes on @a the_chain and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_empty(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_Is_empty( the_chain );
+}
+
+/**
+ * @brief Is this the First Node on the Chain
+ *
+ * This function returns true if the_node is the first node on a chain and
+ * false otherwise.
+ *
+ * @param[in] the_node is the node the caller wants to know if it is
+ * the first node on a chain.
+ *
+ * @return This function returns true if @a the_node is the first node on
+ * a chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_first(
+ const rtems_chain_node *the_node
+)
+{
+ return _Chain_Is_first( the_node );
+}
+
+/**
+ * @brief Is this the Last Node on the Chain
+ *
+ * This function returns true if @a the_node is the last node on a chain and
+ * false otherwise.
+ *
+ * @param[in] the_node is the node to check as the last node.
+ *
+ * @return This function returns true if @a the_node is the last node on
+ * a chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_last(
+ const rtems_chain_node *the_node
+)
+{
+ return _Chain_Is_last( the_node );
+}
+
+/**
+ * @brief Does this Chain have only One Node
+ *
+ * This function returns true if there is only one node on @a the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This function returns true if there is only one node on
+ * @a the_chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_has_only_one_node(
+ const rtems_chain_control *the_chain
+)
+{
+ return _Chain_Has_only_one_node( the_chain );
+}
+
+/**
+ * @brief Is this Node the Chain Head
+ *
+ * This function returns true if @a the_node is the head of the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to check for being the Chain Head.
+ *
+ * @return This function returns true if @a the_node is the head of
+ * @a the_chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_head(
+ rtems_chain_control *the_chain,
+ const rtems_chain_node *the_node
+)
+{
+ return _Chain_Is_head( the_chain, the_node );
+}
+
+/**
+ * @brief Is this Node the Chail Tail
+ *
+ * This function returns true if the_node is the tail of the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to check for being the Chain Tail.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_is_tail(
+ rtems_chain_control *the_chain,
+ const rtems_chain_node *the_node
+)
+{
+ return _Chain_Is_tail( the_chain, the_node );
+}
+
+/**
+ * @brief Extract the specified node from a chain
+ *
+ * This routine extracts @a the_node from the chain on which it resides.
+ * It disables interrupts to ensure the atomicity of the
+ * extract operation.
+ *
+ * @arg the_node specifies the node to extract
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_extract(
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Extract( the_node );
+}
+
+/**
+ * @brief Extract the specified node from a chain (unprotected).
+ *
+ * This routine extracts @a the_node from the chain on which it resides.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * append operation.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_extract_unprotected(
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Extract_unprotected( the_node );
+}
+
+/**
+ * @brief Obtain the first node on a chain
+ *
+ * This function removes the first node from @a the_chain and returns
+ * a pointer to that node. If @a the_chain is empty, then NULL is returned.
+ *
+ * @return This method returns a pointer a node. If a node was removed,
+ * then a pointer to that node is returned. If @a the_chain was
+ * empty, then NULL is returned.
+ *
+ * @note It disables interrupts to ensure the atomicity of the get operation.
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_get(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_Get( the_chain );
+}
+
+/**
+ * @brief See _Chain_Get_unprotected().
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_get_unprotected(
+ rtems_chain_control *the_chain
+)
+{
+ return _Chain_Get_unprotected( the_chain );
+}
+
+/**
+ * @brief Insert a node on a chain
+ *
+ * This routine inserts @a the_node on a chain immediately following
+ * @a after_node.
+ *
+ * @note It disables interrupts to ensure the atomicity
+ * of the extract operation.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_insert(
+ rtems_chain_node *after_node,
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Insert( after_node, the_node );
+}
+
+/**
+ * @brief See _Chain_Insert_unprotected().
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_insert_unprotected(
+ rtems_chain_node *after_node,
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Insert_unprotected( after_node, the_node );
+}
+
+/**
+ * @brief Append a node on the end of a chain
+ *
+ * This routine appends @a the_node onto the end of @a the_chain.
+ *
+ * @note It disables interrupts to ensure the atomicity of the
+ * append operation.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_append(
+ rtems_chain_control *the_chain,
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Append( the_chain, the_node );
+}
+
+/**
+ * @brief Append a node on the end of a chain (unprotected)
+ *
+ * This routine appends @a the_node onto the end of @a the_chain.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * append operation.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_append_unprotected(
+ rtems_chain_control *the_chain,
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Append_unprotected( the_chain, the_node );
+}
+
+/** @brief Prepend a Node
+ *
+ * This routine prepends the_node onto the front of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be prepended.
+ *
+ * @note It disables interrupts to ensure the atomicity of the
+ * prepend operation.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_prepend(
+ rtems_chain_control *the_chain,
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Prepend( the_chain, the_node );
+}
+
+/** @brief Prepend a Node (unprotected)
+ *
+ * This routine prepends the_node onto the front of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be prepended.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * prepend operation.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_prepend_unprotected(
+ rtems_chain_control *the_chain,
+ rtems_chain_node *the_node
+)
+{
+ _Chain_Prepend_unprotected( the_chain, the_node );
+}
+
+/**
+ * @brief Checks if the @a chain is empty and appends the @a node.
+ *
+ * Interrupts are disabled to ensure the atomicity of the operation.
+ *
+ * @retval true The chain was empty before the append.
+ * @retval false The chain contained at least one node before the append.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_append_with_empty_check(
+ rtems_chain_control *chain,
+ rtems_chain_node *node
+)
+{
+ return _Chain_Append_with_empty_check( chain, node );
+}
+
+/**
+ * @brief Checks if the @a chain is empty and prepends the @a node.
+ *
+ * Interrupts are disabled to ensure the atomicity of the operation.
+ *
+ * @retval true The chain was empty before the prepend.
+ * @retval false The chain contained at least one node before the prepend.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_prepend_with_empty_check(
+ rtems_chain_control *chain,
+ rtems_chain_node *node
+)
+{
+ return _Chain_Prepend_with_empty_check( chain, node );
+}
+
+/**
+ * @brief Tries to get the first @a node and check if the @a chain is empty
+ * afterwards.
+ *
+ * This function removes the first node from the @a chain and returns a pointer
+ * to that node in @a node. If the @a chain is empty, then @c NULL is returned.
+ *
+ * Interrupts are disabled to ensure the atomicity of the operation.
+ *
+ * @retval true The chain is empty after the node removal.
+ * @retval false The chain contained at least one node after the node removal.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_chain_get_with_empty_check(
+ rtems_chain_control *chain,
+ rtems_chain_node **node
+)
+{
+ return _Chain_Get_with_empty_check( chain, node );
+}
+
+/** @} */
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/inline/rtems/extension.inl b/cpukit/sapi/inline/rtems/extension.inl
new file mode 100644
index 0000000000..36005b7d7f
--- /dev/null
+++ b/cpukit/sapi/inline/rtems/extension.inl
@@ -0,0 +1,52 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicUserExtensions
+ *
+ * @brief User Extensions API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __EXTENSION_MANAGER_inl
+#define __EXTENSION_MANAGER_inl
+
+RTEMS_INLINE_ROUTINE Extension_Control *_Extension_Allocate( void )
+{
+ return (Extension_Control *) _Objects_Allocate( &_Extension_Information );
+}
+
+RTEMS_INLINE_ROUTINE void _Extension_Free (
+ Extension_Control *the_extension
+)
+{
+ _Objects_Free( &_Extension_Information, &the_extension->Object );
+}
+
+RTEMS_INLINE_ROUTINE Extension_Control *_Extension_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ return (Extension_Control *)
+ _Objects_Get( &_Extension_Information, id, location );
+}
+
+RTEMS_INLINE_ROUTINE bool _Extension_Is_null (
+ Extension_Control *the_extension
+)
+{
+ return ( the_extension == NULL );
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
new file mode 100644
index 0000000000..975828246c
--- /dev/null
+++ b/cpukit/sapi/preinstall.am
@@ -0,0 +1,78 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/confdefs.h: include/confdefs.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/confdefs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/confdefs.h
+
+$(PROJECT_INCLUDE)/rtems/chain.h: include/rtems/chain.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/chain.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/chain.h
+
+$(PROJECT_INCLUDE)/rtems/config.h: include/rtems/config.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/config.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/config.h
+
+$(PROJECT_INCLUDE)/rtems/extension.h: include/rtems/extension.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/extension.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/extension.h
+
+$(PROJECT_INCLUDE)/rtems/fatal.h: include/rtems/fatal.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/fatal.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/fatal.h
+
+$(PROJECT_INCLUDE)/rtems/init.h: include/rtems/init.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/init.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/init.h
+
+$(PROJECT_INCLUDE)/rtems/io.h: include/rtems/io.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/io.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/io.h
+
+$(PROJECT_INCLUDE)/rtems/mptables.h: include/rtems/mptables.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mptables.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mptables.h
+
+$(PROJECT_INCLUDE)/rtems/sptables.h: include/rtems/sptables.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/sptables.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/sptables.h
+
+$(PROJECT_INCLUDE)/rtems/chain.inl: inline/rtems/chain.inl $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/chain.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/chain.inl
+
+$(PROJECT_INCLUDE)/rtems/extension.inl: inline/rtems/extension.inl $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/extension.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/extension.inl
+
+$(PROJECT_LIB)/libsapi.a: libsapi.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libsapi.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libsapi.a
+
diff --git a/cpukit/sapi/src/chainappendnotify.c b/cpukit/sapi/src/chainappendnotify.c
new file mode 100644
index 0000000000..df89d74b48
--- /dev/null
+++ b/cpukit/sapi/src/chainappendnotify.c
@@ -0,0 +1,44 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicChains
+ *
+ * @brief rtems_chain_append_with_notification() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/chain.h>
+
+rtems_status_code rtems_chain_append_with_notification(
+ rtems_chain_control *chain,
+ rtems_chain_node *node,
+ rtems_id task,
+ rtems_event_set events
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ bool was_empty = rtems_chain_append_with_empty_check( chain, node );
+
+ if ( was_empty ) {
+ sc = rtems_event_send( task, events );
+ }
+
+ return sc;
+}
diff --git a/cpukit/sapi/src/chaingetnotify.c b/cpukit/sapi/src/chaingetnotify.c
new file mode 100644
index 0000000000..88f411b4f9
--- /dev/null
+++ b/cpukit/sapi/src/chaingetnotify.c
@@ -0,0 +1,44 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicChains
+ *
+ * @brief rtems_chain_get_with_notification() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/chain.h>
+
+rtems_status_code rtems_chain_get_with_notification(
+ rtems_chain_control *chain,
+ rtems_id task,
+ rtems_event_set events,
+ rtems_chain_node **node
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ bool is_empty = rtems_chain_get_with_empty_check( chain, node );
+
+ if ( is_empty ) {
+ sc = rtems_event_send( task, events );
+ }
+
+ return sc;
+}
diff --git a/cpukit/sapi/src/chaingetwait.c b/cpukit/sapi/src/chaingetwait.c
new file mode 100644
index 0000000000..38986bc9c1
--- /dev/null
+++ b/cpukit/sapi/src/chaingetwait.c
@@ -0,0 +1,55 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicChains
+ *
+ * @brief rtems_chain_get_with_wait() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/chain.h>
+
+rtems_status_code rtems_chain_get_with_wait(
+ rtems_chain_control *chain,
+ rtems_event_set events,
+ rtems_interval timeout,
+ rtems_chain_node **node_ptr
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_chain_node *node = NULL;
+
+ while (
+ sc == RTEMS_SUCCESSFUL
+ && (node = rtems_chain_get( chain )) == NULL
+ ) {
+ rtems_event_set out;
+ sc = rtems_event_receive(
+ events,
+ RTEMS_EVENT_ALL | RTEMS_WAIT,
+ timeout,
+ &out
+ );
+ }
+
+ *node_ptr = node;
+
+ return sc;
+}
diff --git a/cpukit/sapi/src/chainprependnotify.c b/cpukit/sapi/src/chainprependnotify.c
new file mode 100644
index 0000000000..057e4fbde6
--- /dev/null
+++ b/cpukit/sapi/src/chainprependnotify.c
@@ -0,0 +1,44 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicChains
+ *
+ * @brief rtems_chain_prepend_with_notification() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/chain.h>
+
+rtems_status_code rtems_chain_prepend_with_notification(
+ rtems_chain_control *chain,
+ rtems_chain_node *node,
+ rtems_id task,
+ rtems_event_set events
+)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ bool was_empty = rtems_chain_prepend_with_empty_check( chain, node );
+
+ if (was_empty) {
+ sc = rtems_event_send( task, events );
+ }
+
+ return sc;
+}
diff --git a/cpukit/sapi/src/debug.c b/cpukit/sapi/src/debug.c
new file mode 100644
index 0000000000..fc9d57d874
--- /dev/null
+++ b/cpukit/sapi/src/debug.c
@@ -0,0 +1,59 @@
+/*
+ * Debug Manager
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/debug.h>
+
+/*
+ *
+ * _Debug_Manager_initialization
+ */
+void _Debug_Manager_initialization( void )
+{
+ rtems_debug_disable( RTEMS_DEBUG_ALL_MASK );
+}
+
+/*PAGE
+ *
+ * rtems_debug_enable
+ */
+void rtems_debug_enable (
+ rtems_debug_control to_be_enabled
+)
+{
+ _Debug_Level |= to_be_enabled;
+}
+
+/*
+ * rtems_debug_disable
+ */
+void rtems_debug_disable (
+ rtems_debug_control to_be_disabled
+)
+{
+ _Debug_Level &= ~to_be_disabled;
+}
+
+/*
+ * rtems_debug_is_enabled
+ */
+bool rtems_debug_is_enabled(
+ rtems_debug_control level
+)
+{
+ return (_Debug_Level & level) ? true : false;
+}
diff --git a/cpukit/sapi/src/exinit.c b/cpukit/sapi/src/exinit.c
new file mode 100644
index 0000000000..a431669641
--- /dev/null
+++ b/cpukit/sapi/src/exinit.c
@@ -0,0 +1,242 @@
+/*
+ * Initialization Manager
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * SCORE_INIT and SAPI_INIT are defined so all of the super core and
+ * super API data will be included in this object file.
+ */
+
+#define SAPI_INIT
+#define SCORE_INIT
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/debug.h>
+#include <rtems/extension.h>
+#include <rtems/fatal.h>
+#include <rtems/init.h>
+#include <rtems/io.h>
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/apiext.h>
+#include <rtems/score/apimutex.h>
+#include <rtems/score/copyrt.h>
+#include <rtems/score/heap.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
+
+#include <rtems/sptables.h>
+
+
+#include <rtems/rtems/rtemsapi.h>
+#ifdef RTEMS_POSIX_API
+ #include <rtems/posix/posixapi.h>
+#endif
+
+#if defined(RTEMS_SMP)
+ #include <rtems/bspsmp.h>
+ #include <rtems/score/percpu.h>
+#endif
+
+Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
+
+void rtems_initialize_data_structures(void)
+{
+ /*
+ * Dispatching and interrupts are disabled until the end of the
+ * initialization sequence. This prevents an inadvertent context
+ * switch before the executive is initialized.
+ *
+ * WARNING: Interrupts should have been disabled by the BSP and
+ * are disabled by boot_card().
+ */
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ /*
+ * Initialize the system state based on whether this is an MP system.
+ * In an MP configuration, internally we view single processor
+ * systems as a very restricted multiprocessor system.
+ */
+ _Configuration_MP_table = Configuration.User_multiprocessing_table;
+
+ if ( _Configuration_MP_table == NULL ) {
+ _Configuration_MP_table =
+ (void *)&_Initialization_Default_multiprocessing_table;
+ _System_state_Handler_initialization( FALSE );
+ } else {
+ _System_state_Handler_initialization( TRUE );
+ }
+ #else
+ _System_state_Handler_initialization( FALSE );
+ #endif
+
+ /*
+ * Initialize any target architecture specific support as early as possible
+ */
+ _CPU_Initialize();
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Objects_MP_Handler_early_initialization();
+ #endif
+
+ /*
+ * Do this as early as possible to ensure no debugging output
+ * is even attempted to be printed.
+ */
+ _Debug_Manager_initialization();
+
+ _API_extensions_Initialization();
+
+ _Thread_Dispatch_initialization();
+
+ /*
+ * Before this is called, we are not allowed to allocate memory
+ * from the Workspace because it is not initialized.
+ */
+ _Workspace_Handler_initialization();
+
+ #if defined(RTEMS_SMP)
+ _SMP_Handler_initialize();
+ #endif
+
+ _User_extensions_Handler_initialization();
+ _ISR_Handler_initialization();
+
+ /*
+ * Initialize the internal support API and allocator Mutex
+ */
+ _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
+
+ _API_Mutex_Initialization( 1 );
+ _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
+
+ _Priority_bit_map_Handler_initialization();
+ _Watchdog_Handler_initialization();
+ _TOD_Handler_initialization();
+
+ _Thread_Handler_initialization();
+
+ _Scheduler_Handler_initialization();
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Objects_MP_Handler_initialization();
+ _MPCI_Handler_initialization( RTEMS_TIMEOUT );
+ #endif
+
+/* MANAGERS */
+
+ _RTEMS_API_Initialize();
+
+ _Extension_Manager_initialization();
+
+ _IO_Manager_initialization();
+
+ #ifdef RTEMS_POSIX_API
+ _POSIX_API_Initialize();
+ #endif
+
+ /*
+ * Discover and initialize the secondary cores in an SMP system.
+ */
+ #if defined(RTEMS_SMP)
+ _SMP_Processor_count = bsp_smp_initialize( rtems_smp_maximum_processors );
+ #endif
+
+ _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
+
+ /*
+ * No threads should be created before this point!!!
+ * _Thread_Executing and _Thread_Heir are not set.
+ *
+ * At this point all API extensions are in place. After the call to
+ * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
+ */
+ _Thread_Create_idle();
+
+ /*
+ * Scheduling can properly occur now as long as we avoid dispatching.
+ */
+}
+
+void rtems_initialize_before_drivers(void)
+{
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ _MPCI_Create_server();
+ #endif
+
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /*
+ * Run the API and BSPs predriver hook.
+ */
+ _API_extensions_Run_predriver();
+ #endif
+}
+
+void rtems_initialize_device_drivers(void)
+{
+ /*
+ * Initialize all the device drivers and initialize the MPCI layer.
+ *
+ * NOTE: The MPCI may be build upon a device driver.
+ */
+
+ _IO_Initialize_all_drivers();
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _System_state_Is_multiprocessing ) {
+ _MPCI_Initialization();
+ _MPCI_Internal_packets_Send_process_packet(
+ MPCI_PACKETS_SYSTEM_VERIFY
+ );
+ }
+ #endif
+
+ /*
+ * Run the APIs and BSPs postdriver hooks.
+ *
+ * The API extensions are supposed to create user initialization tasks.
+ */
+ _API_extensions_Run_postdriver();
+}
+
+void rtems_initialize_start_multitasking(void)
+{
+
+ _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING );
+
+ _Thread_Start_multitasking();
+
+ /*******************************************************************
+ *******************************************************************
+ *******************************************************************
+ ****** APPLICATION RUNS HERE ******
+ ****** RETURNS WHEN SYSTEM IS SHUT DOWN ******
+ *******************************************************************
+ *******************************************************************
+ *******************************************************************/
+}
diff --git a/cpukit/sapi/src/exshutdown.c b/cpukit/sapi/src/exshutdown.c
new file mode 100644
index 0000000000..5b0a5a1de1
--- /dev/null
+++ b/cpukit/sapi/src/exshutdown.c
@@ -0,0 +1,49 @@
+/*
+ * Initialization Manager
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/interr.h>
+
+/*
+ * rtems_shutdown_executive
+ *
+ * This kernel routine shutdowns the executive. It halts multitasking
+ * and returns control to the application execution "thread" which
+ * initialially invoked the rtems_initialize_executive directive.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void rtems_shutdown_executive(
+ uint32_t result
+)
+{
+ if ( _System_state_Is_up( _System_state_Get() ) ) {
+ _System_state_Set( SYSTEM_STATE_SHUTDOWN );
+ _Thread_Stop_multitasking();
+ }
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP
+ );
+
+}
diff --git a/cpukit/sapi/src/extension.c b/cpukit/sapi/src/extension.c
new file mode 100644
index 0000000000..993f415fd8
--- /dev/null
+++ b/cpukit/sapi/src/extension.c
@@ -0,0 +1,52 @@
+/*
+ * Extension Manager
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/extension.h>
+
+/*PAGE
+ *
+ * _Extension_Manager_initialization
+ *
+ * This routine initializes all extension manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Extension_Manager_initialization(void)
+{
+ _Objects_Initialize_information(
+ &_Extension_Information,
+ OBJECTS_CLASSIC_API, /* object API */
+ OBJECTS_RTEMS_EXTENSIONS,
+ Configuration.maximum_extensions,
+ sizeof( Extension_Control ),
+ false, /* true if the name is a string */
+ RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/sapi/src/extensioncreate.c b/cpukit/sapi/src/extensioncreate.c
new file mode 100644
index 0000000000..bb8647e7b9
--- /dev/null
+++ b/cpukit/sapi/src/extensioncreate.c
@@ -0,0 +1,64 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicUserExtensions
+ *
+ * @brief User Extensions Implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/extension.h>
+
+rtems_status_code rtems_extension_create(
+ rtems_name name,
+ const rtems_extensions_table *extension_table,
+ rtems_id *id
+)
+{
+ Extension_Control *the_extension;
+
+ if ( !id )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+ _Thread_Disable_dispatch(); /* to prevent deletion */
+
+ the_extension = _Extension_Allocate();
+
+ if ( !the_extension ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+ _User_extensions_Add_set_with_table( &the_extension->Extension, extension_table );
+
+ _Objects_Open(
+ &_Extension_Information,
+ &the_extension->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_extension->Object.id;
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/extensiondata.c b/cpukit/sapi/src/extensiondata.c
new file mode 100644
index 0000000000..6057db5ee6
--- /dev/null
+++ b/cpukit/sapi/src/extensiondata.c
@@ -0,0 +1,23 @@
+/*
+ * Extension Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate extension data */
+#define SAPI_EXT_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/extension.h>
+
diff --git a/cpukit/sapi/src/extensiondelete.c b/cpukit/sapi/src/extensiondelete.c
new file mode 100644
index 0000000000..4f5be6337b
--- /dev/null
+++ b/cpukit/sapi/src/extensiondelete.c
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicUserExtensions
+ *
+ * @brief User Extensions Implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/extension.h>
+
+rtems_status_code rtems_extension_delete(
+ rtems_id id
+)
+{
+ Extension_Control *the_extension;
+ Objects_Locations location;
+
+ the_extension = _Extension_Get( id, &location );
+ switch ( location ) {
+ case OBJECTS_LOCAL:
+ _User_extensions_Remove_set( &the_extension->Extension );
+ _Objects_Close( &_Extension_Information, &the_extension->Object );
+ _Extension_Free( the_extension );
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* should never return this */
+#endif
+ case OBJECTS_ERROR:
+ break;
+ }
+
+ return RTEMS_INVALID_ID;
+}
diff --git a/cpukit/sapi/src/extensionident.c b/cpukit/sapi/src/extensionident.c
new file mode 100644
index 0000000000..e59f39d7dc
--- /dev/null
+++ b/cpukit/sapi/src/extensionident.c
@@ -0,0 +1,45 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicUserExtensions
+ *
+ * @brief User Extensions Implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/support.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/extension.h>
+
+rtems_status_code rtems_extension_ident(
+ rtems_name name,
+ rtems_id *id
+)
+{
+ Objects_Name_or_id_lookup_errors status;
+
+ status = _Objects_Name_to_id_u32(
+ &_Extension_Information,
+ name,
+ OBJECTS_SEARCH_LOCAL_NODE,
+ id
+ );
+
+ return _Status_Object_name_errors_to_status[ status ];
+}
diff --git a/cpukit/sapi/src/fatal.c b/cpukit/sapi/src/fatal.c
new file mode 100644
index 0000000000..80abde253a
--- /dev/null
+++ b/cpukit/sapi/src/fatal.c
@@ -0,0 +1,40 @@
+/*
+ * Fatal Error Manager
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/fatal.h>
+#include <rtems/score/interr.h>
+
+/*
+ * rtems_fatal_error_occurred
+ *
+ * This directive will invoke the internal fatal error handler.
+ *
+ * Input parameters:
+ * the_error - fatal error status code
+ *
+ * Output parameters: NONE
+ */
+
+void rtems_fatal_error_occurred(
+ uint32_t the_error
+)
+{
+ _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, FALSE, the_error );
+
+/* will not return from this routine */
+}
diff --git a/cpukit/sapi/src/getversionstring.c b/cpukit/sapi/src/getversionstring.c
new file mode 100644
index 0000000000..4295be56dc
--- /dev/null
+++ b/cpukit/sapi/src/getversionstring.c
@@ -0,0 +1,21 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+
+const char *rtems_get_version_string(void)
+{
+ return _RTEMS_version;
+}
diff --git a/cpukit/sapi/src/io.c b/cpukit/sapi/src/io.c
new file mode 100644
index 0000000000..6a752cd527
--- /dev/null
+++ b/cpukit/sapi/src/io.c
@@ -0,0 +1,101 @@
+/*
+ * Input/Output Manager - Initialize Device Driver Subsystem
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/io.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+#include <string.h>
+
+/*
+ * _IO_Manager_initialization
+ *
+ * The IO manager has been extended to support runtime driver
+ * registration. The driver table is now allocated in the
+ * workspace.
+ *
+ */
+
+void _IO_Manager_initialization(void)
+{
+ uint32_t index;
+ rtems_driver_address_table *driver_table;
+ uint32_t drivers_in_table;
+ uint32_t number_of_drivers;
+
+ driver_table = Configuration.Device_driver_table;
+ drivers_in_table = Configuration.number_of_device_drivers;
+ number_of_drivers = Configuration.maximum_drivers;
+
+ /*
+ * If the user claims there are less drivers than are actually in
+ * the table, then let's just go with the table's count.
+ */
+ if ( number_of_drivers <= drivers_in_table )
+ number_of_drivers = drivers_in_table;
+
+ /*
+ * If the maximum number of driver is the same as the number in the
+ * table, then we do not have to copy the driver table. They can't
+ * register any dynamically.
+ */
+ if ( number_of_drivers == drivers_in_table ) {
+ _IO_Driver_address_table = driver_table;
+ _IO_Number_of_drivers = number_of_drivers;
+ return;
+ }
+
+ /*
+ * The application requested extra slots in the driver table, so we
+ * have to allocate a new driver table and copy theirs to it.
+ */
+
+ _IO_Driver_address_table = (rtems_driver_address_table *)
+ _Workspace_Allocate_or_fatal_error(
+ sizeof( rtems_driver_address_table ) * ( number_of_drivers )
+ );
+ _IO_Number_of_drivers = number_of_drivers;
+
+ memset(
+ _IO_Driver_address_table, 0,
+ sizeof( rtems_driver_address_table ) * ( number_of_drivers )
+ );
+
+ for ( index = 0 ; index < drivers_in_table ; index++ )
+ _IO_Driver_address_table[index] = driver_table[index];
+}
+
+/*
+ * _IO_Initialize_all_drivers
+ *
+ * This routine initializes all device drivers
+ *
+ * Input Paramters: NONE
+ *
+ * Output Parameters: NONE
+ */
+
+void _IO_Initialize_all_drivers( void )
+{
+ rtems_device_major_number major;
+
+ for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
+ (void) rtems_io_initialize( major, 0, NULL );
+}
diff --git a/cpukit/sapi/src/ioclose.c b/cpukit/sapi/src/ioclose.c
new file mode 100644
index 0000000000..65d43f55ec
--- /dev/null
+++ b/cpukit/sapi/src/ioclose.c
@@ -0,0 +1,48 @@
+/*
+ * Input/Output Manager -- Close Device
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+
+/*
+ * rtems_io_close
+ *
+ * This routine is the close directive of the IO manager.
+ *
+ * Input Paramters:
+ * major - device driver number
+ * minor - device number
+ * argument - pointer to argument(s)
+ *
+ * Output Parameters:
+ * returns - return code
+ */
+
+rtems_status_code rtems_io_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+)
+{
+ rtems_device_driver_entry callout;
+
+ if ( major >= _IO_Number_of_drivers )
+ return RTEMS_INVALID_NUMBER;
+
+ callout = _IO_Driver_address_table[major].close_entry;
+ return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/iocontrol.c b/cpukit/sapi/src/iocontrol.c
new file mode 100644
index 0000000000..1f1d0d38ea
--- /dev/null
+++ b/cpukit/sapi/src/iocontrol.c
@@ -0,0 +1,48 @@
+/*
+ * Input/Output Manager - Device Control
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+
+/*
+ * rtems_io_control
+ *
+ * This routine is the control directive of the IO manager.
+ *
+ * Input Paramters:
+ * major - device driver number
+ * minor - device number
+ * argument - pointer to argument(s)
+ *
+ * Output Parameters:
+ * returns - return code
+ */
+
+rtems_status_code rtems_io_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+)
+{
+ rtems_device_driver_entry callout;
+
+ if ( major >= _IO_Number_of_drivers )
+ return RTEMS_INVALID_NUMBER;
+
+ callout = _IO_Driver_address_table[major].control_entry;
+ return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/iodata.c b/cpukit/sapi/src/iodata.c
new file mode 100644
index 0000000000..f15de6979d
--- /dev/null
+++ b/cpukit/sapi/src/iodata.c
@@ -0,0 +1,22 @@
+/*
+ * RTEMS Task Manager -- Instantiate Data
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* instantiate RTEMS IO manager data */
+#define SAPI_IO_EXTERN
+
+#include <rtems/system.h>
+#include <rtems/io.h>
diff --git a/cpukit/sapi/src/ioinitialize.c b/cpukit/sapi/src/ioinitialize.c
new file mode 100644
index 0000000000..998edbb6b2
--- /dev/null
+++ b/cpukit/sapi/src/ioinitialize.c
@@ -0,0 +1,48 @@
+/*
+ * Input/Output Manager - Initialize Device
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+
+/*
+ * rtems_io_initialize
+ *
+ * This routine is the initialization directive of the IO manager.
+ *
+ * Input Paramters:
+ * major - device driver number
+ * minor - device number
+ * argument - pointer to argument(s)
+ *
+ * Output Parameters:
+ * returns - return code
+ */
+
+rtems_status_code rtems_io_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+)
+{
+ rtems_device_driver_entry callout;
+
+ if ( major >= _IO_Number_of_drivers )
+ return RTEMS_INVALID_NUMBER;
+
+ callout = _IO_Driver_address_table[major].initialization_entry;
+ return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/ioopen.c b/cpukit/sapi/src/ioopen.c
new file mode 100644
index 0000000000..f8f1c84a86
--- /dev/null
+++ b/cpukit/sapi/src/ioopen.c
@@ -0,0 +1,48 @@
+/*
+ * Input/Output Manager - Open Device
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+
+/*
+ * rtems_io_open
+ *
+ * This routine is the open directive of the IO manager.
+ *
+ * Input Paramters:
+ * major - device driver number
+ * minor - device number
+ * argument - pointer to argument(s)
+ *
+ * Output Parameters:
+ * returns - return code
+ */
+
+rtems_status_code rtems_io_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+)
+{
+ rtems_device_driver_entry callout;
+
+ if ( major >= _IO_Number_of_drivers )
+ return RTEMS_INVALID_NUMBER;
+
+ callout = _IO_Driver_address_table[major].open_entry;
+ return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/ioread.c b/cpukit/sapi/src/ioread.c
new file mode 100644
index 0000000000..3b090ef764
--- /dev/null
+++ b/cpukit/sapi/src/ioread.c
@@ -0,0 +1,48 @@
+/*
+ * Input/Output Manager - Device Read
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+
+/*
+ * rtems_io_read
+ *
+ * This routine is the read directive of the IO manager.
+ *
+ * Input Paramters:
+ * major - device driver number
+ * minor - device number
+ * argument - pointer to argument(s)
+ *
+ * Output Parameters:
+ * returns - return code
+ */
+
+rtems_status_code rtems_io_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+)
+{
+ rtems_device_driver_entry callout;
+
+ if ( major >= _IO_Number_of_drivers )
+ return RTEMS_INVALID_NUMBER;
+
+ callout = _IO_Driver_address_table[major].read_entry;
+ return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/ioregisterdriver.c b/cpukit/sapi/src/ioregisterdriver.c
new file mode 100644
index 0000000000..30d10eb808
--- /dev/null
+++ b/cpukit/sapi/src/ioregisterdriver.c
@@ -0,0 +1,115 @@
+/**
+ * @file
+ *
+ * @ingroup ClassicIO
+ *
+ * @brief Classic Input/Output Manager implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+#include <rtems/rtems/intr.h>
+#include <rtems/score/thread.h>
+
+static inline bool rtems_io_is_empty_table(
+ const rtems_driver_address_table *table
+)
+{
+ return table->initialization_entry == NULL && table->open_entry == NULL;
+}
+
+static rtems_status_code rtems_io_obtain_major_number(
+ rtems_device_major_number *major
+)
+{
+ rtems_device_major_number n = _IO_Number_of_drivers;
+ rtems_device_major_number m = 0;
+
+ /* major is error checked by caller */
+
+ for ( m = 0; m < n; ++m ) {
+ rtems_driver_address_table *const table = _IO_Driver_address_table + m;
+
+ if ( rtems_io_is_empty_table( table ) )
+ break;
+ }
+
+ /* Assigns invalid value in case of failure */
+ *major = m;
+
+ if ( m != n )
+ return RTEMS_SUCCESSFUL;
+
+ return RTEMS_TOO_MANY;
+}
+
+rtems_status_code rtems_io_register_driver(
+ rtems_device_major_number major,
+ const rtems_driver_address_table *driver_table,
+ rtems_device_major_number *registered_major
+)
+{
+ rtems_device_major_number major_limit = _IO_Number_of_drivers;
+
+ if ( rtems_interrupt_is_in_progress() )
+ return RTEMS_CALLED_FROM_ISR;
+
+ if ( registered_major == NULL )
+ return RTEMS_INVALID_ADDRESS;
+
+ /* Set it to an invalid value */
+ *registered_major = major_limit;
+
+ if ( driver_table == NULL )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( rtems_io_is_empty_table( driver_table ) )
+ return RTEMS_INVALID_ADDRESS;
+
+ if ( major >= major_limit )
+ return RTEMS_INVALID_NUMBER;
+
+ _Thread_Disable_dispatch();
+
+ if ( major == 0 ) {
+ rtems_status_code sc = rtems_io_obtain_major_number( registered_major );
+
+ if ( sc != RTEMS_SUCCESSFUL ) {
+ _Thread_Enable_dispatch();
+ return sc;
+ }
+ major = *registered_major;
+ } else {
+ rtems_driver_address_table *const table = _IO_Driver_address_table + major;
+
+ if ( !rtems_io_is_empty_table( table ) ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_RESOURCE_IN_USE;
+ }
+
+ *registered_major = major;
+ }
+
+ _IO_Driver_address_table [major] = *driver_table;
+
+ _Thread_Enable_dispatch();
+
+ return rtems_io_initialize( major, 0, NULL );
+}
diff --git a/cpukit/sapi/src/iounregisterdriver.c b/cpukit/sapi/src/iounregisterdriver.c
new file mode 100644
index 0000000000..631ffbfd82
--- /dev/null
+++ b/cpukit/sapi/src/iounregisterdriver.c
@@ -0,0 +1,57 @@
+/*
+ * Input/Output Manager - Dynamically Unregister Device Driver
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+#include <rtems/rtems/intr.h>
+#include <rtems/score/thread.h>
+#include <string.h>
+
+/*
+ * rtems_io_unregister_driver
+ *
+ * Unregister a driver from the device driver table.
+ *
+ * Input Paramters:
+ * major - device major number
+ *
+ * Output Parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_io_unregister_driver(
+ rtems_device_major_number major
+)
+{
+ if ( rtems_interrupt_is_in_progress() )
+ return RTEMS_CALLED_FROM_ISR;
+
+ if ( major < _IO_Number_of_drivers ) {
+ _Thread_Disable_dispatch();
+ memset(
+ &_IO_Driver_address_table[major],
+ 0,
+ sizeof( rtems_driver_address_table )
+ );
+ _Thread_Enable_dispatch();
+
+ return RTEMS_SUCCESSFUL;
+ }
+
+ return RTEMS_UNSATISFIED;
+}
diff --git a/cpukit/sapi/src/iowrite.c b/cpukit/sapi/src/iowrite.c
new file mode 100644
index 0000000000..9283404e73
--- /dev/null
+++ b/cpukit/sapi/src/iowrite.c
@@ -0,0 +1,48 @@
+/*
+ * Input/Output Manager - Device Write
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/io.h>
+
+/*
+ * rtems_io_write
+ *
+ * This routine is the write directive of the IO manager.
+ *
+ * Input Paramters:
+ * major - device driver number
+ * minor - device number
+ * argument - pointer to argument(s)
+ *
+ * Output Parameters:
+ * returns - return code
+ */
+
+rtems_status_code rtems_io_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *argument
+)
+{
+ rtems_device_driver_entry callout;
+
+ if ( major >= _IO_Number_of_drivers )
+ return RTEMS_INVALID_NUMBER;
+
+ callout = _IO_Driver_address_table[major].write_entry;
+ return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/sapi/src/posixapi.c b/cpukit/sapi/src/posixapi.c
new file mode 100644
index 0000000000..37cbbae8a6
--- /dev/null
+++ b/cpukit/sapi/src/posixapi.c
@@ -0,0 +1,88 @@
+/*
+ * RTEMS API Initialization Support
+ *
+ * NOTE:
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * POSIX_API_INIT is defined so all of the POSIX API
+ * data will be included in this object file.
+ */
+
+#define POSIX_API_INIT
+
+#include <rtems/system.h> /* include this before checking RTEMS_POSIX_API */
+#ifdef RTEMS_POSIX_API
+
+#include <sys/types.h>
+#include <mqueue.h>
+#include <rtems/config.h>
+#include <rtems/score/object.h>
+#include <rtems/posix/barrier.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/config.h>
+#include <rtems/posix/key.h>
+#include <rtems/posix/mqueue.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/posixapi.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/psignal.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/rwlock.h>
+#include <rtems/posix/timer.h>
+#include <rtems/posix/semaphore.h>
+#include <rtems/posix/spinlock.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_API_Initialize
+ *
+ * XXX
+ */
+
+Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
+
+void _POSIX_API_Initialize(void)
+{
+ /*
+ * If there are any type size assumptions in the POSIX API, this is
+ * the appropriate place to place them.
+ *
+ * Currently, there are no none type size assumptions.
+ */
+
+ /*
+ * Install our API Object Management Table and initialize the
+ * various managers.
+ */
+ _Objects_Information_table[OBJECTS_POSIX_API] = _POSIX_Objects;
+
+ _POSIX_signals_Manager_Initialization();
+ _POSIX_Threads_Manager_initialization();
+ _POSIX_Condition_variables_Manager_initialization();
+ _POSIX_Key_Manager_initialization();
+ _POSIX_Mutex_Manager_initialization();
+ _POSIX_Message_queue_Manager_initialization();
+ _POSIX_Semaphore_Manager_initialization();
+ _POSIX_Timer_Manager_initialization();
+ _POSIX_Barrier_Manager_initialization();
+ _POSIX_RWLock_Manager_initialization();
+ _POSIX_Spinlock_Manager_initialization();
+}
+
+#endif
+/* end of file */
diff --git a/cpukit/sapi/src/rtemsapi.c b/cpukit/sapi/src/rtemsapi.c
new file mode 100644
index 0000000000..fa76c2a966
--- /dev/null
+++ b/cpukit/sapi/src/rtemsapi.c
@@ -0,0 +1,82 @@
+/*
+ * POSIX API Initialization Support
+ *
+ * NOTE:
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * RTEMS_API_INIT is defined so all of the RTEMS API
+ * data will be included in this object file.
+ */
+
+#define RTEMS_API_INIT
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/rtemsapi.h>
+
+#include <rtems/rtems/intr.h>
+#include <rtems/rtems/barrier.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/rtems/tasks.h>
+#include <rtems/rtems/dpmem.h>
+#include <rtems/rtems/event.h>
+#include <rtems/rtems/message.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/rtems/mp.h>
+#endif
+#include <rtems/rtems/part.h>
+#include <rtems/rtems/ratemon.h>
+#include <rtems/rtems/region.h>
+#include <rtems/rtems/sem.h>
+#include <rtems/rtems/signal.h>
+#include <rtems/rtems/timer.h>
+
+Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ];
+
+/*PAGE
+ *
+ * _RTEMS_API_Initialize
+ *
+ * XXX
+ */
+
+void _RTEMS_API_Initialize(void)
+{
+ /*
+ * Install our API Object Management Table and initialize the
+ * various managers.
+ */
+ _Objects_Information_table[OBJECTS_CLASSIC_API] = _RTEMS_Objects;
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Multiprocessing_Manager_initialization();
+ #endif
+
+ _RTEMS_tasks_Manager_initialization();
+ _Timer_Manager_initialization();
+ _Signal_Manager_initialization();
+ _Event_Manager_initialization();
+ _Message_queue_Manager_initialization();
+ _Semaphore_Manager_initialization();
+ _Partition_Manager_initialization();
+ _Region_Manager_initialization();
+ _Dual_ported_memory_Manager_initialization();
+ _Rate_monotonic_Manager_initialization();
+ _Barrier_Manager_initialization();
+}
+
+/* end of file */
diff --git a/cpukit/score/.cvsignore b/cpukit/score/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
new file mode 100644
index 0000000000..9d3d97f593
--- /dev/null
+++ b/cpukit/score/Makefile.am
@@ -0,0 +1,247 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+SUBDIRS = cpu
+
+## include
+
+include_rtemsdir = $(includedir)/rtems
+
+include_rtems_HEADERS = include/rtems/debug.h include/rtems/system.h \
+ include/rtems/seterr.h include/rtems/bspsmp.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+
+include_rtems_score_HEADERS = include/rtems/score/address.h \
+ include/rtems/score/apiext.h include/rtems/score/apimutex.h \
+ include/rtems/score/bitfield.h include/rtems/score/chain.h \
+ include/rtems/score/context.h include/rtems/score/copyrt.h \
+ include/rtems/score/corebarrier.h include/rtems/score/coremsg.h \
+ include/rtems/score/coremutex.h include/rtems/score/coresem.h \
+ include/rtems/score/heap.h include/rtems/score/protectedheap.h \
+ include/rtems/score/interr.h include/rtems/score/isr.h \
+ include/rtems/score/object.h include/rtems/score/percpu.h \
+ include/rtems/score/priority.h include/rtems/score/prioritybitmap.h \
+ include/rtems/score/scheduler.h include/rtems/score/schedulerpriority.h \
+ include/rtems/score/schedulersimple.h \
+ include/rtems/score/stack.h include/rtems/score/states.h \
+ include/rtems/score/sysstate.h include/rtems/score/thread.h \
+ include/rtems/score/threadq.h include/rtems/score/threadsync.h \
+ include/rtems/score/timespec.h include/rtems/score/timestamp.h \
+ include/rtems/score/timestamp64.h include/rtems/score/tod.h \
+ include/rtems/score/tqdata.h include/rtems/score/userext.h \
+ include/rtems/score/watchdog.h include/rtems/score/wkspace.h \
+ include/rtems/score/cpuopts.h include/rtems/score/basedefs.h \
+ include/rtems/score/smplock.h
+
+if HAS_PTHREADS
+include_rtems_score_HEADERS += include/rtems/score/corespinlock.h \
+ include/rtems/score/corerwlock.h
+endif
+
+if HAS_MP
+# We only build multiprocessing related files if HAS_MP was defined
+include_rtems_score_HEADERS += include/rtems/score/mpci.h \
+ include/rtems/score/mppkt.h include/rtems/score/objectmp.h \
+ include/rtems/score/threadmp.h
+endif
+
+## inline
+include_rtems_score_HEADERS += inline/rtems/score/address.inl \
+ inline/rtems/score/chain.inl inline/rtems/score/corebarrier.inl \
+ inline/rtems/score/coremsg.inl inline/rtems/score/coremutex.inl \
+ inline/rtems/score/coresem.inl inline/rtems/score/heap.inl \
+ inline/rtems/score/isr.inl inline/rtems/score/object.inl \
+ inline/rtems/score/priority.inl inline/rtems/score/prioritybitmap.inl \
+ inline/rtems/score/scheduler.inl inline/rtems/score/schedulerpriority.inl \
+ inline/rtems/score/schedulersimple.inl \
+ inline/rtems/score/stack.inl inline/rtems/score/states.inl \
+ inline/rtems/score/sysstate.inl inline/rtems/score/thread.inl \
+ inline/rtems/score/threadq.inl inline/rtems/score/tod.inl \
+ inline/rtems/score/tqdata.inl inline/rtems/score/watchdog.inl \
+ inline/rtems/score/wkspace.inl
+
+if HAS_PTHREADS
+include_rtems_score_HEADERS += inline/rtems/score/corespinlock.inl \
+ inline/rtems/score/corerwlock.inl
+endif
+
+if HAS_MP
+## We only build multiprocessing related files if HAS_MP was defined
+include_rtems_score_HEADERS += inline/rtems/score/mppkt.inl \
+ inline/rtems/score/objectmp.inl inline/rtems/score/threadmp.inl
+endif
+
+## src
+
+AM_CPPFLAGS += -D__RTEMS_INSIDE__
+
+noinst_LIBRARIES = libscore.a
+libscore_a_SOURCES =
+libscore_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+# We only build multiprocessing related files if HAS_MP was defined
+if HAS_MP
+libscore_a_SOURCES += src/mpci.c src/objectmp.c src/threadmp.c
+endif
+
+libscore_a_SOURCES += src/smp.c src/smplock.c
+
+## CORE_APIMUTEX_C_FILES
+libscore_a_SOURCES += src/apimutex.c src/apimutexallocate.c \
+ src/apimutexlock.c src/apimutexunlock.c
+
+## CORE_BARRIER_C_FILES
+libscore_a_SOURCES += src/corebarrier.c src/corebarrierrelease.c \
+ src/corebarrierwait.c
+
+## CORE_MESSAGE_QUEUE_C_FILES
+libscore_a_SOURCES += src/coremsg.c src/coremsgbroadcast.c \
+ src/coremsgclose.c src/coremsgflush.c src/coremsgflushwait.c \
+ src/coremsginsert.c src/coremsgflushsupp.c src/coremsgseize.c \
+ src/coremsgsubmit.c
+
+## CORE_MUTEX_C_FILES
+libscore_a_SOURCES += src/coremutex.c src/coremutexflush.c \
+ src/coremutexseize.c src/coremutexsurrender.c \
+ src/coremutexseizeintr.c
+
+## CORE_PERCPU_C_FILES
+libscore_a_SOURCES += src/percpu.c
+
+## CORE_RWLOCK_C_FILES
+if HAS_PTHREADS
+libscore_a_SOURCES += src/corerwlock.c src/corerwlockobtainread.c \
+ src/corerwlockobtainwrite.c src/corerwlockrelease.c src/corerwlocktimeout.c
+endif
+
+## CORE_SEMAPHORE_C_FILES
+libscore_a_SOURCES += src/coresem.c src/coresemflush.c src/coresemseize.c \
+ src/coresemsurrender.c
+
+## CORE_SPINLOCK_C_FILES
+if HAS_PTHREADS
+libscore_a_SOURCES += src/corespinlock.c src/corespinlockrelease.c \
+ src/corespinlockwait.c
+endif
+
+## HEAP_C_FILES
+libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c \
+ src/heapfree.c src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \
+ src/heapgetfreeinfo.c src/heapresizeblock.c
+
+## OBJECT_C_FILES
+libscore_a_SOURCES += src/objectallocate.c src/objectclose.c \
+ src/objectextendinformation.c src/objectfree.c src/objectget.c \
+ src/objectgetisr.c src/objectgetnext.c src/objectinitializeinformation.c \
+ src/objectnametoid.c src/objectnametoidstring.c \
+ src/objectshrinkinformation.c src/objectgetnoprotection.c \
+ src/objectidtoname.c src/objectgetnameasstring.c src/objectsetname.c \
+ src/objectgetinfo.c src/objectgetinfoid.c src/objectapimaximumclass.c \
+ src/objectnamespaceremove.c
+
+## SCHEDULER_C_FILES
+libscore_a_SOURCES += src/scheduler.c
+
+## SCHEDULERPRIORITY_C_FILES
+libscore_a_SOURCES += src/schedulerpriority.c \
+ src/schedulerpriorityallocate.c \
+ src/schedulerpriorityblock.c \
+ src/schedulerpriorityenqueue.c \
+ src/schedulerpriorityenqueuefirst.c \
+ src/schedulerpriorityextract.c \
+ src/schedulerpriorityfree.c \
+ src/schedulerpriorityschedule.c \
+ src/schedulerpriorityunblock.c \
+ src/schedulerpriorityupdate.c \
+ src/schedulerpriorityyield.c
+
+## SCHEDULERSIMPLE_C_FILES
+libscore_a_SOURCES += src/schedulersimple.c \
+ src/schedulersimpleblock.c \
+ src/schedulersimpleenqueue.c \
+ src/schedulersimpleenqueuefirst.c \
+ src/schedulersimpleextract.c \
+ src/schedulersimplereadyqueueenqueue.c \
+ src/schedulersimplereadyqueueenqueuefirst.c \
+ src/schedulersimpleschedule.c \
+ src/schedulersimpleunblock.c \
+ src/schedulersimpleyield.c
+
+## PROTECTED_HEAP_C_FILES
+libscore_a_SOURCES += src/pheapallocate.c \
+ src/pheapextend.c src/pheapfree.c src/pheapgetsize.c \
+ src/pheapgetblocksize.c src/pheapgetfreeinfo.c src/pheapgetinfo.c \
+ src/pheapinit.c src/pheapresizeblock.c src/pheapwalk.c
+
+## THREAD_C_FILES
+libscore_a_SOURCES += src/thread.c src/threadchangepriority.c \
+ src/threadclearstate.c src/threadclose.c src/threadcreateidle.c \
+ src/threaddelayended.c src/threaddispatch.c \
+ src/threadget.c src/threadhandler.c src/threadinitialize.c \
+ src/threadloadenv.c src/threadready.c src/threadreset.c \
+ src/threadrestart.c src/threadsetpriority.c \
+ src/threadsetstate.c src/threadsettransient.c \
+ src/threadstackallocate.c src/threadstackfree.c src/threadstart.c \
+ src/threadstartmultitasking.c src/threadtickletimeslice.c \
+ src/iterateoverthreads.c src/threadblockingoperationcancel.c
+
+## THREADQ_C_FILES
+libscore_a_SOURCES += src/threadq.c src/threadqdequeue.c \
+ src/threadqdequeuefifo.c src/threadqdequeuepriority.c \
+ src/threadqenqueue.c src/threadqenqueuefifo.c \
+ src/threadqenqueuepriority.c src/threadqextract.c \
+ src/threadqextractfifo.c src/threadqextractpriority.c \
+ src/threadqextractwithproxy.c src/threadqfirst.c src/threadqfirstfifo.c \
+ src/threadqfirstpriority.c src/threadqflush.c src/threadqrequeue.c \
+ src/threadqprocesstimeout.c src/threadqtimeout.c
+
+## TIMESPEC_C_FILES
+libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \
+ src/timespecisvalid.c src/timespeclessthan.c src/timespecgreaterthan.c \
+ src/timespecsubtract.c src/timespectoticks.c src/timespecdivide.c \
+ src/timespecdividebyinteger.c
+
+## TIMESTAMP_INT64_C_FILES
+libscore_a_SOURCES += src/ts64addto.c src/ts64dividebyinteger.c \
+ src/ts64divide.c src/ts64equalto.c \
+ src/ts64getnanoseconds.c src/ts64getseconds.c \
+ src/ts64greaterthan.c src/ts64lessthan.c \
+ src/ts64set.c src/ts64settozero.c src/ts64subtract.c \
+ src/ts64toticks.c src/ts64totimespec.c
+
+## TOD_C_FILES
+libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
+ src/coretodgetuptime.c src/coretodgetuptimetimespec.c src/coretodtickle.c \
+ src/coretodmsecstoticks.c src/coretodtickspersec.c src/coretodusectoticks.c
+
+## WATCHDOG_C_FILES
+libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \
+ src/watchdogadjusttochain.c src/watchdoginsert.c src/watchdogremove.c \
+ src/watchdogtickle.c src/watchdogreport.c src/watchdogreportchain.c \
+ src/watchdognanoseconds.c
+
+## USEREXT_C_FILES
+libscore_a_SOURCES += src/userextaddset.c \
+ src/userext.c src/userextremoveset.c src/userextthreadbegin.c \
+ src/userextthreadcreate.c src/userextthreaddelete.c \
+ src/userextthreadrestart.c src/userextthreadstart.c \
+ src/userextthreadswitch.c
+
+## STD_C_FILES
+libscore_a_SOURCES += src/apiext.c src/chain.c src/chainappend.c \
+ src/chainextract.c src/chainget.c src/chaininsert.c \
+ src/chainappendempty.c src/chainprependempty.c src/chaingetempty.c \
+ src/interr.c src/isr.c src/wkspace.c
+
+EXTRA_DIST = src/Unlimited.txt
+
+DISTCLEANFILES = include/rtems/score/cpuopts.h
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/subdirs.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/.cvsignore b/cpukit/score/cpu/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/Makefile.am b/cpukit/score/cpu/Makefile.am
new file mode 100644
index 0000000000..569afb8cd5
--- /dev/null
+++ b/cpukit/score/cpu/Makefile.am
@@ -0,0 +1,26 @@
+##
+## $Id$
+##
+
+SUBDIRS = @RTEMS_CPU@
+
+DIST_SUBDIRS =
+DIST_SUBDIRS += arm
+DIST_SUBDIRS += avr
+DIST_SUBDIRS += bfin
+DIST_SUBDIRS += h8300
+DIST_SUBDIRS += i386
+DIST_SUBDIRS += lm32
+DIST_SUBDIRS += m32c
+DIST_SUBDIRS += m32r
+DIST_SUBDIRS += m68k
+DIST_SUBDIRS += mips
+DIST_SUBDIRS += nios2
+DIST_SUBDIRS += no_cpu
+DIST_SUBDIRS += powerpc
+DIST_SUBDIRS += sh
+DIST_SUBDIRS += sparc
+DIST_SUBDIRS += sparc64
+
+include $(top_srcdir)/automake/subdirs.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/arm/.cvsignore b/cpukit/score/cpu/arm/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/arm/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/arm/ChangeLog b/cpukit/score/cpu/arm/ChangeLog
new file mode 100644
index 0000000000..7edf0ce295
--- /dev/null
+++ b/cpukit/score/cpu/arm/ChangeLog
@@ -0,0 +1,655 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-11-23 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1719/cpukit
+ * arm_exc_abort.S: Avoid "bx" instruction to support ARMv4 and below.
+
+2010-11-22 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Set alignment requirements according to AAPCS.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/types.h: Refactoring of priority handling, to isolate the
+ bitmap implementation of priorities in the supercore so that priority
+ management is a little more modular. This change is in anticipation
+ of scheduler implementations that can select how they manage tracking
+ priority levels / finding the highest priority ready task. Note that
+ most of the changes here are simple renaming, to clarify the use of
+ the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-07-06 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Removed CPU_ENABLE_C_ISR_DISPATCH_IMPLEMENTATION
+ define.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * arm_exc_interrupt.S: Add a per cpu data structure which contains the
+ information required by RTEMS for each CPU core. This encapsulates
+ information such as thread executing, heir, idle and dispatch needed.
+
+2010-05-10 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * rtems/score/arm.h: Make it a warning not error that the FPU multilib
+ is not supported yet.
+
+2010-04-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * arm_exc_abort.S, arm_exc_handler_high.c, arm_exc_handler_low.S,
+ arm_exc_interrupt.S, cpu.c, cpu_asm.S, rtems/asm.h, rtems/score/arm.h,
+ rtems/score/cpu.h, rtems/score/cpu_asm.h, rtems/score/types.h:
+ Documentation.
+
+2010-04-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * arm_exc_abort.S: Fix warnings about TRUE/FALSE not defined.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * arm_exc_abort.S, arm_exc_handler_high.c, arm_exc_handler_low.S,
+ arm_exc_interrupt.S, cpu.c, cpu_asm.S: Add include of config.h
+
+2010-01-12 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * arm_exc_abort.S: New file.
+ * Makefile.am: Update for new file.
+ * arm_exc_interrupt.S, cpu.c, rtems/asm.h, rtems/score/cpu.h: Changed
+ macros which switch from and to THUMB mode. Added a default prefetch
+ and data abort handler which reports the complete processor context.
+ Added PSR defines.
+
+2009-12-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/arm.h: Recognize ARMv5TEJ.
+ * arm_exc_interrupt.S: The previous implementation was broken. In
+ case of a nested interrupt the link register of the INT mode was not
+ properly restored. This lead to a major rewrite. Interrupt
+ processing is now done in SVC mode.
+
+2009-10-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/arm.h: Recognize ARMv7A.
+
+2009-10-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/arm.h: Recognize ARMv6J as needed by arm1136 variants.
+
+2009-09-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Fix for inline asm in _CPU_Fatal_halt().
+ * rtems/asm.h: Added macro to define ARM functions.
+ * cpu_asm.S, arm_exc_handler_low.S: Use macro from above.
+
+2009-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Mark _CPU_Context_restore() as noreturn so the
+ compiler will not generate code thinking it returns.
+
+2009-07-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * arm_exc_handler_high.c, arm_exc_handler_low.S, arm_exc_interrupt.S:
+ New files.
+ * Makefile.am: Update.
+ * rtems/score/cpu.h: Removed all generic comments. Changed inline
+ assembler of interrupt support functions. Removed operating system
+ support for fast interrupts (FIQ). Overall cleanup.
+ * cpu.c: Changed type of arm_cpu_mode to uint32_t to match the type in
+ _CPU_Context_Initialize(). Moved exception handler code into
+ 'arm_exc_handler_high.c'. _CPU_ISR_install_vector() writes now only
+ if necessary.
+ * cpu_asm.S: Moved exception handler code into 'arm_exc_handler_low.S'.
+ * rtems/score/types.h: Removed superfluous defines.
+ * ChangeLog, thumb_isr.c: Removed files.
+
+2009-05-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Remove warnings.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Remove extraneous spaces.
+
+2008-09-07 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Merge thumb/Makefile.am.
+ * thumb/Makefile.am: Remove (superfluous).
+
+2008-09-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h: Convert to "bool".
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-18 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Add void.
+
+2008-04-18 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c: Add comment.
+
+2008-04-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Add arm_cpu_mode so ARM BSP can overrid default value for
+ cpsr.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu_asm.h: Sweep to make sure grep for COPYRIGHT passes.
+
+2007-12-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Temporarily use C implementation of swap u32 for
+ thumb mode.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-11-27 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Do not inline _Thread_Enable_dispatch for Thumb to
+ save space.
+
+2007-11-26 Ray Xu <rayx.cn@gmail.com>
+
+ * cpu.c, score/cpu.h: Fix headers. Remove extra inline definition.
+ * cpu_asm.S: Note origin of Thumb support.
+
+2007-11-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c: Fix headers.
+
+2007-11-03 Ray Xu <rayx.cn@gmail.com>
+
+ * cpu.c, cpu_asm.S, score/cpu.h : add support for ARM<->THUMB veneer
+ thumb new dir to controll CPSR/SPRS in thumb mode
+
+2007-05-09 Ray Xu <rayx.cn@gmail.com>
+
+ * cpu.c: move do_data_abort() to libbsp/arm/shared/abort/
+ implement a compact do_data_abort() in simple_abort.c
+
+2007-05-09 Ray Xu <rayx@gmail.com>
+
+ * cpu.c: move do_data_abort() to libbsp/arm/shared/abort/
+ implement a compact do_data_abort() in simple_abort.c
+
+2007-05-09 Ray Xu <rayx@gmail.com>
+
+ * cpu.c: move do_data_abort() to libbsp/arm/shared/abort/
+ implement a compact do_data_abort() in simple_abort.c
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-09-11 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Remove warning.
+
+2006-06-02 Jay Monkman <jtm@lopingdog.com>
+
+ * cpu.c, cpu_asm.S: Fixed ARM Data Abort handling.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-09-15 Jay Monkman <jtm@lopingdog.com>
+
+ PR 365/rtems
+ * rtems/score/arm.h, rtems/score/cpu.h: Removed unused ARM_HAS_CLZ
+ macro.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/arm.h, rtems/score/cpu.h,
+ rtems/score/cpu_asm.h, rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/arm.h: Add doxygen preamble.
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/cpu_asm.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: i960 obsoleted and all references removed.
+
+2004-08-19 Jay Monkman <jtm@lopingdog.com>
+
+ PR 671/bsps
+ * rtems/score/cpu.h: Fixed bug in _CPU_ISR_Set_level, where input param
+ was always ignored.
+
+2004-04-09 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Fix typo.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into $(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu_asm.S: Include <rtems/asm.h> instead of <asm.h>.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h: Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-26 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Obsoleting HP PA-RISC port and removing all
+ references.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * asm.h, cpu.c, cpu_asm.S, rtems/score/arm.h, rtems/score/cpu.h,
+ rtems/score/cpu_asm.h, rtems/score/types.h: URL for license changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-04-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use "all-local:" instead of "all:".
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2003-03-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/arm.h: Remove ARM_HAS_THUMB (Unused).
+
+2003-03-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/cpu.h: Set up CPU_*_ENDIAN based on -D__ARMEL__ and
+ -D__ARMEB__. Fix minor typo in comment.
+
+2003-02-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/arm.h: Set up ARM_HAS_FPU based on -D__SOFTFP__.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-11-04 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Removed warning.
+
+2002-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Removed warnings.
+
+2002-10-31 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Removed warning.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-10-04 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * rtems/score/cpu.h: Fix u16 and u32 swap routines.
+
+2002-08-05 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h, rtems/score/types.h: Updated to fix some typos.
+
+2002-07-30 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/arm.h, rtems/score/cpu.h,
+ rtems/score/cpu_asm.h, rtems/score/types.h: ARM port works
+ well enough to run all sptests, tmtests, and ttcp.
+ In addition to general cleanup, there has been considerable
+ optimization to interrupt disable/enable, endian swapping,
+ and context switching.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use . instead of .o.
+
+2002-07-17 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * rtems/score/cpu_asm.h: Enhanced to include register offsets.
+ * Makefile.am: Install rtems/score/cpu_asm.h.
+ * cpu.c: Significantly enhanced including the implementation of
+ _CPU_ISR_Get_level.
+ * cpu_asm.S: Improved behavior of context switch and interrupt
+ dispatching.
+ * rtems/score/arm.h: Improved the CPU model name determination.
+ * rtems/score/cpu.h: Improved interrupt disable/enable functions.
+
+2002-07-05 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Filled in something that was marked XXX.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.c: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2002-04-18 Jay Monkman <jtm@smoothsmoothie.com>
+
+ * rtems/score/cpu.h (CPU_ISR_Disable and CPU_ISR_Enable): Correct them
+ where they correctly inform the compiler about the register they
+ are modifying.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/a29ktypes.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2001-02-04 Joel Sherrill <joel@OARcorp.com>
+
+ * configure.ac: Removed references to rtems/Makefile and
+ rtems/score/Makefile.
+
+2002-01-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ * Makefile.am: Reflect changes above.
+
+2002-02-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CUSTOM_BSP.
+
+2002-01-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * cpu.c: Include rtems/bspIo.h instead of bspIo.h.
+
+2001-12-20 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use RTEMS_ENV_RTEMSCPU.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-12-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * asm.h: include cpuopts.h instead of targopts.h
+ * rtems/score/arm.h: Use __arm__.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, formatting.
+ * rtems/Makefile.am: Formatting.
+ * rtems/score/Makefile.am: Formatting.
+
+2000-08-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c: Spacing issues.
+ * rtems/score/cpu.h: Removed warning by setting _level.
+
+2000-08-29 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * Makefile.am: Added S_O_FILES to list of objects.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/arm/Makefile.am b/cpukit/score/cpu/arm/Makefile.am
new file mode 100644
index 0000000000..57f2b70642
--- /dev/null
+++ b/cpukit/score/cpu/arm/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+include $(top_srcdir)/automake/compile.am
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/cpu_asm.h \
+ rtems/score/arm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+libscorecpu_a_SOURCES = cpu.c \
+ cpu_asm.S \
+ arm_exc_abort.S \
+ arm_exc_interrupt.S \
+ arm_exc_handler_low.S \
+ arm_exc_handler_high.c
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/arm/arm_exc_abort.S b/cpukit/score/cpu/arm/arm_exc_abort.S
new file mode 100644
index 0000000000..cd2491fb14
--- /dev/null
+++ b/cpukit/score/cpu/arm/arm_exc_abort.S
@@ -0,0 +1,135 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM data and prefetch abort exception prologue and epilogue.
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/system.h>
+
+.extern rtems_fatal_error_occurred
+
+.globl arm_exc_data_abort_set_handler
+.globl arm_exc_data_abort
+
+.globl arm_exc_prefetch_abort_set_handler
+.globl arm_exc_prefetch_abort
+
+.section ".bss"
+
+data_abort_handler:
+.long 0
+
+prefetch_abort_handler:
+.long 0
+
+.section ".text"
+
+#ifdef __thumb__
+ .thumb_func
+#endif
+
+arm_exc_data_abort_set_handler:
+ ldr r1, =data_abort_handler
+ str r0, [r1]
+#ifdef __thumb__
+ bx lr
+#else
+ mov pc, lr
+#endif
+
+#ifdef __thumb__
+ .thumb_func
+#endif
+
+arm_exc_prefetch_abort_set_handler:
+ ldr r1, =prefetch_abort_handler
+ str r0, [r1]
+#ifdef __thumb__
+ bx lr
+#else
+ mov pc, lr
+#endif
+
+.arm
+
+arm_exc_prefetch_abort:
+
+ /* Save context and load handler */
+ sub sp, #16
+ stmdb sp!, {r0-r12}
+ ldr r6, =prefetch_abort_handler
+
+ b save_more_context
+
+arm_exc_data_abort:
+
+ /* Save context and load handler */
+ sub sp, #16
+ stmdb sp!, {r0-r12}
+ ldr r6, =data_abort_handler
+
+save_more_context:
+
+ /* Save more context */
+ mov r2, lr
+ mrs r3, spsr
+ mrs r4, cpsr
+ orr r5, r3, #ARM_PSR_I
+ bic r5, #ARM_PSR_T
+ msr cpsr, r5
+ mov r0, sp
+ mov r1, lr
+ msr cpsr, r4
+ add r5, sp, #68
+ stmdb r5!, {r0-r3}
+
+ /* Call high level handler */
+ ldr r2, [r6]
+ cmp r2, #0
+ ldreq r2, =rtems_fatal_error_occurred
+ movne r0, sp
+ moveq r0, #0xaa
+#ifndef __thumb__
+ mov lr, pc
+ mov pc, r2
+#else /* __thumb__ */
+ SWITCH_FROM_ARM_TO_THUMB r1
+ bl call_handler
+ SWITCH_FROM_THUMB_TO_ARM
+#endif /* __thumb__ */
+
+ /* Restore context */
+ ldmia r5!, {r0-r3}
+ mov lr, r2
+ msr spsr, r3
+ ldmia sp!, {r0-r12}
+ add sp, #16
+
+ /* Return from interrupt */
+ subs pc, lr, #8
+
+#ifdef __thumb__
+.thumb
+call_handler:
+ bx r2
+#endif /* __thumb__ */
diff --git a/cpukit/score/cpu/arm/arm_exc_handler_high.c b/cpukit/score/cpu/arm/arm_exc_handler_high.c
new file mode 100644
index 0000000000..176c1b4561
--- /dev/null
+++ b/cpukit/score/cpu/arm/arm_exc_handler_high.c
@@ -0,0 +1,121 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM exception support implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * Copyright (c) 2002 Advent Networks, Inc
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * Copyright (c) 2007 Ray xu <rayx.cn@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * Moved from file 'cpukit/score/cpu/arm/cpu.c'.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems.h>
+#include <rtems/bspIo.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/cpu.h>
+
+static void _defaultExcHandler (CPU_Exception_frame *ctx)
+{
+ printk("\n\r");
+ printk("----------------------------------------------------------\n\r");
+#if 1
+ printk("Exception 0x%x caught at PC 0x%x by thread %d\n",
+ ctx->register_ip, ctx->register_lr - 4,
+ _Thread_Executing->Object.id);
+#endif
+ printk("----------------------------------------------------------\n\r");
+ printk("Processor execution context at time of the fault was :\n\r");
+ printk("----------------------------------------------------------\n\r");
+#if 0
+ printk(" r0 = %8x r1 = %8x r2 = %8x r3 = %8x\n\r",
+ ctx->register_r0, ctx->register_r1,
+ ctx->register_r2, ctx->register_r3);
+ printk(" r4 = %8x r5 = %8x r6 = %8x r7 = %8x\n\r",
+ ctx->register_r4, ctx->register_r5,
+ ctx->register_r6, ctx->register_r7);
+ printk(" r8 = %8x r9 = %8x r10 = %8x\n\r",
+ ctx->register_r8, ctx->register_r9, ctx->register_r10);
+ printk(" fp = %8x ip = %8x sp = %8x pc = %8x\n\r",
+ ctx->register_fp, ctx->register_ip,
+ ctx->register_sp, ctx->register_lr - 4);
+ printk("----------------------------------------------------------\n\r");
+#endif
+ if (_ISR_Nest_level > 0) {
+ /*
+ * In this case we shall not delete the task interrupted as
+ * it has nothing to do with the fault. We cannot return either
+ * because the eip points to the faulty instruction so...
+ */
+ printk("Exception while executing ISR!!!. System locked\n\r");
+ while(1);
+ }
+ else {
+ printk("*********** FAULTY THREAD WILL BE DELETED **************\n\r");
+ rtems_task_delete(_Thread_Executing->Object.id);
+ }
+}
+
+typedef void (*cpuExcHandlerType) (CPU_Exception_frame*);
+
+cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
+
+extern void _Exception_Handler_Undef_Swi(void);
+extern void _Exception_Handler_Abort(void);
+extern void _exc_data_abort(void);
+
+
+
+/* FIXME: put comments here */
+void rtems_exception_init_mngt(void)
+{
+ ISR_Level level;
+
+ _CPU_ISR_Disable(level);
+ _CPU_ISR_install_vector(ARM_EXCEPTION_UNDEF,
+ _Exception_Handler_Undef_Swi,
+ NULL);
+
+ _CPU_ISR_install_vector(ARM_EXCEPTION_SWI,
+ _Exception_Handler_Undef_Swi,
+ NULL);
+
+ _CPU_ISR_install_vector(ARM_EXCEPTION_PREF_ABORT,
+ _Exception_Handler_Abort,
+ NULL);
+
+ _CPU_ISR_install_vector(ARM_EXCEPTION_DATA_ABORT,
+ _exc_data_abort,
+ NULL);
+
+ _CPU_ISR_install_vector(ARM_EXCEPTION_FIQ,
+ _Exception_Handler_Abort,
+ NULL);
+
+ _CPU_ISR_install_vector(ARM_EXCEPTION_IRQ,
+ _Exception_Handler_Abort,
+ NULL);
+
+ _CPU_ISR_Enable(level);
+}
diff --git a/cpukit/score/cpu/arm/arm_exc_handler_low.S b/cpukit/score/cpu/arm/arm_exc_handler_low.S
new file mode 100644
index 0000000000..c43d430e2f
--- /dev/null
+++ b/cpukit/score/cpu/arm/arm_exc_handler_low.S
@@ -0,0 +1,164 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM exception support implementation.
+ */
+
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007 by Ray Xu, <Rayx.cn@gmail.com>
+ * Thumb support added.
+ *
+ * Copyright (c) 2002 by Advent Networks, Inc.
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * Moved from file 'cpukit/score/cpu/arm/cpu_asm.S'.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/cpu_asm.h>
+
+ .text
+
+/* FIXME: _Exception_Handler_Undef_Swi is untested */
+DEFINE_FUNCTION_ARM(_Exception_Handler_Undef_Swi)
+/* FIXME: This should use load and store multiple instructions */
+ sub r13,r13,#SIZE_REGS
+ str r4, [r13, #REG_R4]
+ str r5, [r13, #REG_R5]
+ str r6, [r13, #REG_R6]
+ str r7, [r13, #REG_R7]
+ str r8, [r13, #REG_R8]
+ str r9, [r13, #REG_R9]
+ str r10, [r13, #REG_R10]
+ str r11, [r13, #REG_R11]
+ str sp, [r13, #REG_SP]
+ str lr, [r13, #REG_LR]
+ mrs r0, cpsr /* read the status */
+ and r0, r0,#0x1f /* we keep the mode as exception number */
+ str r0, [r13, #REG_PC] /* we store it in a free place */
+ mov r0, r13 /* put frame address in r0 (C arg 1) */
+
+ ldr r1, =SWI_Handler
+ ldr lr, =_go_back_1
+ ldr pc,[r1] /* call handler */
+_go_back_1:
+ ldr r4, [r13, #REG_R4]
+ ldr r5, [r13, #REG_R5]
+ ldr r6, [r13, #REG_R6]
+ ldr r7, [r13, #REG_R7]
+ ldr r8, [r13, #REG_R8]
+ ldr r9, [r13, #REG_R9]
+ ldr r10, [r13, #REG_R10]
+ ldr r11, [r13, #REG_R11]
+ ldr sp, [r13, #REG_SP]
+ ldr lr, [r13, #REG_LR]
+ add r13,r13,#SIZE_REGS
+ movs pc,r14 /* return */
+
+/* FIXME: _Exception_Handler_Abort is untested */
+DEFINE_FUNCTION_ARM(_Exception_Handler_Abort)
+/* FIXME: This should use load and store multiple instructions */
+ sub r13,r13,#SIZE_REGS
+ str r4, [r13, #REG_R4]
+ str r5, [r13, #REG_R5]
+ str r6, [r13, #REG_R6]
+ str r7, [r13, #REG_R7]
+ str r8, [r13, #REG_R8]
+ str r9, [r13, #REG_R9]
+ str sp, [r13, #REG_R11]
+ str lr, [r13, #REG_SP]
+ str lr, [r13, #REG_LR]
+ mrs r0, cpsr /* read the status */
+ and r0, r0,#0x1f /* we keep the mode as exception number */
+ str r0, [r13, #REG_PC] /* we store it in a free place */
+ mov r0, r13 /* put frame address in ro (C arg 1) */
+
+ ldr r1, =_currentExcHandler
+ ldr lr, =_go_back_2
+ ldr pc,[r1] /* call handler */
+_go_back_2:
+ ldr r4, [r13, #REG_R4]
+ ldr r5, [r13, #REG_R5]
+ ldr r6, [r13, #REG_R6]
+ ldr r7, [r13, #REG_R7]
+ ldr r8, [r13, #REG_R8]
+ ldr r9, [r13, #REG_R9]
+ ldr r10, [r13, #REG_R10]
+ ldr sp, [r13, #REG_R11]
+ ldr lr, [r13, #REG_SP]
+ ldr lr, [r13, #REG_LR]
+ add r13,r13,#SIZE_REGS
+#ifdef __thumb__
+ subs r11, r14,#4
+ bx r11
+ nop
+#else
+ subs pc,r14,#4 /* return */
+#endif
+
+#define ABORT_REGS_OFFS 32-REG_R4
+#define ABORT_SIZE_REGS SIZE_REGS+ABORT_REGS_OFFS
+
+DEFINE_FUNCTION_ARM(_exc_data_abort)
+ sub sp, sp, #ABORT_SIZE_REGS /* reserve register frame */
+ stmia sp, {r0-r11}
+ add sp, sp, #ABORT_REGS_OFFS /* the Context_Control structure starts by CPSR, R4, ... */
+
+ str ip, [sp, #REG_PC] /* store R12 (ip) somewhere, oh hackery, hackery, hack */
+ str lr, [sp, #REG_LR]
+
+ mov r1, lr
+ ldr r0, [r1, #-8] /* r0 = bad instruction */
+ mrs r1, spsr /* r1 = spsr */
+ mov r2, r13 /* r2 = exception frame of Context_Control type */
+#if defined(__thumb__)
+ .code 32
+ /*arm to thumb*/
+ adr r5, to_thumb + 1
+ bx r5
+ .code 16
+to_thumb:
+#endif
+ bl do_data_abort
+#if defined(__thumb__)
+/*back to arm*/
+ .code 16
+thumb_to_arm:
+ .align 2
+ adr r5, arm_code
+ bx r5
+ nop
+ .code 32
+arm_code:
+#endif
+
+ ldr lr, [sp, #REG_LR]
+ ldr ip, [sp, #REG_PC] /* restore R12 (ip) */
+
+ sub sp, sp, #ABORT_REGS_OFFS
+ ldmia sp, {r0-r11}
+ add sp, sp, #ABORT_SIZE_REGS
+#ifdef __thumb__
+ subs r11, r14, #4 /* return to the instruction */
+ bx r11
+ nop
+#else
+ subs pc, r14, #4
+#endif
+ /* _AFTER_ the aborted one */
diff --git a/cpukit/score/cpu/arm/arm_exc_interrupt.S b/cpukit/score/cpu/arm/arm_exc_interrupt.S
new file mode 100644
index 0000000000..e269e13455
--- /dev/null
+++ b/cpukit/score/cpu/arm/arm_exc_interrupt.S
@@ -0,0 +1,177 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM interrupt exception prologue and epilogue.
+ */
+
+/*
+ * Copyright (c) 2009
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+/*
+ * The upper EXCHANGE_SIZE bytes of the INT stack area are used for data
+ * exchange between INT and SVC mode. Below of this is the actual INT stack.
+ * The exchange area is only accessed if INT is disabled.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/percpu.h>
+
+#define EXCHANGE_LR r4
+#define EXCHANGE_SPSR r5
+#define EXCHANGE_CPSR r6
+#define EXCHANGE_INT_SP r7
+
+#define EXCHANGE_LIST {EXCHANGE_LR, EXCHANGE_SPSR, EXCHANGE_CPSR, EXCHANGE_INT_SP}
+#define EXCHANGE_SIZE 16
+
+#define CONTEXT_LIST {r0, r1, r2, r3, EXCHANGE_LR, EXCHANGE_SPSR, r12}
+#define CONTEXT_SIZE 28
+
+.extern _Thread_Dispatch_disable_level
+
+.extern bsp_interrupt_dispatch
+
+.arm
+.globl arm_exc_interrupt
+arm_exc_interrupt:
+
+ /* Save exchange registers to exchange area */
+ stmdb sp, EXCHANGE_LIST
+
+ /* Set exchange registers */
+ mov EXCHANGE_LR, lr
+ mrs EXCHANGE_SPSR, spsr
+ mrs EXCHANGE_CPSR, cpsr
+ sub EXCHANGE_INT_SP, sp, #EXCHANGE_SIZE
+
+ /* Switch to SVC mode */
+ orr EXCHANGE_CPSR, EXCHANGE_CPSR, #0x1
+ msr cpsr, EXCHANGE_CPSR
+
+ /*
+ * Save context. We save the LR separately because it has to be
+ * restored in SVC mode. The other registers can be restored in INT
+ * mode.
+ */
+ stmdb sp!, CONTEXT_LIST
+ stmdb sp!, {lr}
+
+ /* Remember INT stack pointer */
+ mov r1, EXCHANGE_INT_SP
+
+ /* Restore exchange registers from exchange area */
+ ldmia r1, EXCHANGE_LIST
+
+ /* Get interrupt nest level */
+ ldr r0, =ISR_NEST_LEVEL
+ ldr r2, [r0]
+
+ /* Switch stack if necessary and save original stack pointer */
+ mov r3, sp
+ cmp r2, #0
+ moveq sp, r1
+ stmdb sp!, {r3}
+
+ /* Switch to THUMB instructions if necessary */
+ SWITCH_FROM_ARM_TO_THUMB r1
+
+ /* Increment interrupt nest and thread dispatch disable level */
+ ldr r1, =_Thread_Dispatch_disable_level
+ ldr r3, [r1]
+ add r2, #1
+ add r3, #1
+ str r2, [r0]
+ str r3, [r1]
+
+ /* Call BSP dependent interrupt dispatcher */
+ bl bsp_interrupt_dispatch
+
+ /* Decrement interrupt nest and thread dispatch disable level */
+ ldr r0, =ISR_NEST_LEVEL
+ ldr r1, =_Thread_Dispatch_disable_level
+ ldr r2, [r0]
+ ldr r3, [r1]
+ sub r2, #1
+ sub r3, #1
+ str r2, [r0]
+ str r3, [r1]
+
+ /* Restore stack pointer */
+ SWITCH_FROM_THUMB_TO_ARM
+ ldr sp, [sp]
+ SWITCH_FROM_ARM_TO_THUMB r0
+
+ /* Check thread dispatch disable level */
+ cmp r3, #0
+ bne thread_dispatch_done
+
+ /* Check context switch necessary */
+ ldr r0, =DISPATCH_NEEDED
+ ldrb r1, [r0]
+ cmp r1, #0
+ beq thread_dispatch_done
+
+ /* This aligns thread_dispatch_done on a 4 byte boundary */
+#ifdef __thumb__
+ nop
+#endif /* __thumb__ */
+
+do_thread_dispatch:
+
+ /* Thread dispatch */
+ bl _Thread_Dispatch
+
+thread_dispatch_done:
+
+ /* Switch to ARM instructions if necessary */
+ SWITCH_FROM_THUMB_TO_ARM
+
+ /* Restore link register */
+ ldmia sp!, {lr}
+
+ /*
+ * XXX: Remember and restore stack pointer. The data on the stack is
+ * still in use. So the stack is now in an inconsistent state. The
+ * FIQ handler implementation must not use this area.
+ */
+ mov r0, sp
+ add sp, #CONTEXT_SIZE
+
+ /* Get INT mode program status register */
+ mrs r1, cpsr
+ bic r1, r1, #0x1
+
+ /* Switch to INT mode */
+ msr cpsr, r1
+
+ /* Save EXCHANGE_LR and EXCHANGE_SPSR registers to exchange area */
+ stmdb sp!, {EXCHANGE_LR, EXCHANGE_SPSR}
+
+ /* Restore context */
+ ldmia r0, CONTEXT_LIST
+
+ /* Set return address and program status */
+ mov lr, EXCHANGE_LR
+ msr spsr, EXCHANGE_SPSR
+
+ /* Restore EXCHANGE_LR and EXCHANGE_SPSR registers from exchange area */
+ ldmia sp!, {EXCHANGE_LR, EXCHANGE_SPSR}
+
+ /* Return from interrupt */
+ subs pc, lr, #4
diff --git a/cpukit/score/cpu/arm/cpu.c b/cpukit/score/cpu/arm/cpu.c
new file mode 100644
index 0000000000..00ff4aabcd
--- /dev/null
+++ b/cpukit/score/cpu/arm/cpu.c
@@ -0,0 +1,125 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM architecture support implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * Copyright (c) 2002 Advent Networks, Inc
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * Copyright (c) 2007 Ray xu <rayx.cn@gmail.com>
+ *
+ * Copyright (c) 2009 embedded brains GmbH
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems.h>
+#include <rtems/bspIo.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/cpu.h>
+
+/*
+ * This variable can be used to change the running mode of the execution
+ * contexts.
+ */
+uint32_t arm_cpu_mode = 0x13;
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ the_context->register_sp = (uint32_t) stack_base + size ;
+ the_context->register_lr = (uint32_t) entry_point;
+ the_context->register_cpsr = new_level | arm_cpu_mode;
+}
+
+/* Preprocessor magic for stringification of x */
+#define _CPU_ISR_LEVEL_DO_STRINGOF( x) #x
+#define _CPU_ISR_LEVEL_STRINGOF( x) _CPU_ISR_LEVEL_DO_STRINGOF( x)
+
+void _CPU_ISR_Set_level( uint32_t level )
+{
+ uint32_t arm_switch_reg;
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "mrs %[arm_switch_reg], cpsr\n"
+ "bic %[arm_switch_reg], #" _CPU_ISR_LEVEL_STRINGOF( CPU_MODES_INTERRUPT_MASK ) "\n"
+ "orr %[arm_switch_reg], %[level]\n"
+ "msr cpsr, %0\n"
+ ARM_SWITCH_BACK
+ : [arm_switch_reg] "=&r" (arm_switch_reg)
+ : [level] "r" (level)
+ );
+}
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ ARM_SWITCH_REGISTERS;
+ uint32_t level;
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "mrs %[level], cpsr\n"
+ "and %[level], #" _CPU_ISR_LEVEL_STRINGOF( CPU_MODES_INTERRUPT_MASK ) "\n"
+ ARM_SWITCH_BACK
+ : [level] "=&r" (level) ARM_SWITCH_ADDITIONAL_OUTPUT
+ );
+
+ return level;
+}
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /* Redirection table starts at the end of the vector table */
+ volatile uint32_t *table = (volatile uint32_t *) (MAX_EXCEPTIONS * 4);
+
+ uint32_t current_handler = table [vector];
+
+ /* The current handler is now the old one */
+ if (old_handler != NULL) {
+ *old_handler = (proc_ptr) current_handler;
+ }
+
+ /* Write only if necessary to avoid writes to a maybe read-only memory */
+ if (current_handler != (uint32_t) new_handler) {
+ table [vector] = (uint32_t) new_handler;
+ }
+}
+
+void _CPU_Install_interrupt_stack( void )
+{
+ /* This function is empty since the BSP must set up the interrupt stacks */
+}
+
+void _CPU_Initialize( void )
+{
+ /* Do nothing */
+}
diff --git a/cpukit/score/cpu/arm/cpu_asm.S b/cpukit/score/cpu/arm/cpu_asm.S
new file mode 100644
index 0000000000..9eebabae38
--- /dev/null
+++ b/cpukit/score/cpu/arm/cpu_asm.S
@@ -0,0 +1,80 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM architecture support implementation.
+ */
+
+/*
+ * $Id$
+ *
+ * This file contains all assembly code for the ARM implementation
+ * of RTEMS.
+ *
+ * Copyright (c) 2007 by Ray Xu, <Rayx.cn@gmail.com>
+ * Thumb support added.
+ *
+ * Copyright (c) 2002 by Advent Networks, Inc.
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/cpu_asm.h>
+
+ .text
+
+/*
+ * void _CPU_Context_switch( run_context, heir_context )
+ * void _CPU_Context_restore( run_context, heir_context )
+ *
+ * This routine performs a normal non-FP context.
+ *
+ * R0 = run_context R1 = heir_context
+ *
+ * This function copies the current registers to where r0 points, then
+ * restores the ones from where r1 points.
+ *
+ * Using the ldm/stm opcodes save 2-3 us on 100 MHz ARM9TDMI with
+ * a 16 bit data bus.
+ *
+ */
+
+DEFINE_FUNCTION_ARM(_CPU_Context_switch)
+/* Start saving context */
+ mrs r2, cpsr
+ stmia r0, {r2, r4, r5, r6, r7, r8, r9, r10, r11, r13, r14}
+
+
+/* Start restoring context */
+_restore:
+ ldmia r1, {r2, r4, r5, r6, r7, r8, r9, r10, r11, r13, r14}
+ msr cpsr, r2
+#ifdef __thumb__
+ bx lr
+ nop
+#else
+ mov pc, lr
+#endif
+/*
+ * void _CPU_Context_restore( new_context )
+ *
+ * This function copies the restores the registers from where r0 points.
+ * It must match _CPU_Context_switch()
+ *
+ */
+DEFINE_FUNCTION_ARM(_CPU_Context_restore)
+ mov r1, r0
+ b _restore
diff --git a/cpukit/score/cpu/arm/preinstall.am b/cpukit/score/cpu/arm/preinstall.am
new file mode 100644
index 0000000000..90ac37443e
--- /dev/null
+++ b/cpukit/score/cpu/arm/preinstall.am
@@ -0,0 +1,45 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/arm.h: rtems/score/arm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/arm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/arm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/arm/rtems/asm.h b/cpukit/score/cpu/arm/rtems/asm.h
new file mode 100644
index 0000000000..9d56c514a6
--- /dev/null
+++ b/cpukit/score/cpu/arm/rtems/asm.h
@@ -0,0 +1,178 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM assembler support API.
+ */
+
+/*
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ *
+ *
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ */
+
+/*
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/arm.h>
+
+/**
+ * @defgroup ScoreCPUARMASM ARM Assembler Support
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM assembler support.
+ *
+ * @{
+ */
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+#define r0 REG(r0)
+#define r1 REG(r1)
+#define r2 REG(r2)
+#define r3 REG(r3)
+#define r4 REG(r4)
+#define r5 REG(r5)
+#define r6 REG(r6)
+#define r7 REG(r7)
+#define r8 REG(r8)
+#define r9 REG(r9)
+#define r10 REG(r10)
+#define r11 REG(r11)
+#define r12 REG(r12)
+#define r13 REG(r13)
+#define r14 REG(r14)
+#define r15 REG(r15)
+
+#define CPSR REG(CPSR)
+
+#define SPSR REG(SPSR)
+
+#define NUM_IRQ_VECTOR 6 // IRQ number
+#define NUM_FIQ_VECTOR 7 // IRQ number
+ // //
+#define CPSR_IRQ_DISABLE 0x80 // FIQ disabled when =1
+#define CPSR_FIQ_DISABLE 0x40 // FIQ disabled when =1
+#define CPSR_THUMB_ENABLE 0x20 // Thumb mode when =1
+#define CPSR_FIQ_MODE 0x11
+#define CPSR_IRQ_MODE 0x12
+#define CPSR_SUPERVISOR_MODE 0x13
+#define CPSR_UNDEF_MODE 0x1B
+
+#define CPSR_MODE_BITS 0x1F
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+#ifdef __thumb__
+ #define DEFINE_FUNCTION_ARM(name) \
+ .thumb_func ; .globl name ; name: ; bx pc ; \
+ .arm ; .globl name ## _arm ; name ## _arm:
+#else
+ #define DEFINE_FUNCTION_ARM(name) \
+ .globl name ; name: ; .globl name ## _arm ; name ## _arm:
+#endif
+
+.macro SWITCH_FROM_THUMB_TO_ARM
+#ifdef __thumb__
+.align 2
+ bx pc
+.arm
+#endif /* __thumb__ */
+.endm
+
+.macro SWITCH_FROM_ARM_TO_THUMB REG
+#ifdef __thumb__
+ add \REG, pc, #1
+ bx \REG
+.thumb
+#endif /* __thumb__ */
+.endm
+
+/** @} */
+
+#endif /* _RTEMS_ASM_H */
diff --git a/cpukit/score/cpu/arm/rtems/score/arm.h b/cpukit/score/cpu/arm/rtems/score/arm.h
new file mode 100644
index 0000000000..d74765c5f7
--- /dev/null
+++ b/cpukit/score/cpu/arm/rtems/score/arm.h
@@ -0,0 +1,98 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM assembler support API.
+ */
+
+/*
+ * $Id$
+ *
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * Copyright (c) 2002 Advent Networks, Inc.
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#ifndef _RTEMS_SCORE_ARM_H
+#define _RTEMS_SCORE_ARM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup ScoreCPU
+ *
+ * @{
+ */
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the "arm"
+ * family when executing in protected mode. It does
+ * this by setting variables to indicate which implementation
+ * dependent features are present in a particular member
+ * of the family.
+ */
+#if defined(__ARM_ARCH_4__)
+# define CPU_MODEL_NAME "ARMv4"
+
+#elif defined(__ARM_ARCH_4T__)
+# define CPU_MODEL_NAME "ARMv4T"
+
+#elif defined(__ARM_ARCH_5__)
+# define CPU_MODEL_NAME "ARMv5"
+
+#elif defined(__ARM_ARCH_5T__)
+# define CPU_MODEL_NAME "ARMv5T"
+
+#elif defined(__ARM_ARCH_5E__)
+# define CPU_MODEL_NAME "ARMv5E"
+
+#elif defined(__ARM_ARCH_5TE__)
+# define CPU_MODEL_NAME "ARMv5TE"
+
+#elif defined(__ARM_ARCH_5TEJ__)
+# define CPU_MODEL_NAME "ARMv5TEJ"
+
+#elif defined(__ARM_ARCH_6J__)
+# define CPU_MODEL_NAME "ARMv6J"
+
+#elif defined(__ARM_ARCH_7A__)
+# define CPU_MODEL_NAME "ARMv7A"
+
+#else
+# error "Unsupported CPU Model"
+
+#endif
+
+/* All ARM CPUs are assumed to not have floating point units */
+#if defined(__SOFTFP__)
+#define ARM_HAS_FPU 0
+#else
+#define ARM_HAS_FPU 1
+#warning "FPU-support not yet implemented for the arm"
+#endif
+
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "ARM"
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_ARM_H */
diff --git a/cpukit/score/cpu/arm/rtems/score/cpu.h b/cpukit/score/cpu/arm/rtems/score/cpu.h
new file mode 100644
index 0000000000..405ccb79bb
--- /dev/null
+++ b/cpukit/score/cpu/arm/rtems/score/cpu.h
@@ -0,0 +1,495 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM architecture support API.
+ */
+
+/*
+ * $Id$
+ *
+ * This include file contains information pertaining to the ARM
+ * processor.
+ *
+ * Copyright (c) 2009-2010 embedded brains GmbH.
+ *
+ * Copyright (c) 2007 Ray Xu <Rayx.cn@gmail.com>
+ *
+ * Copyright (c) 2006 OAR Corporation
+ *
+ * Copyright (c) 2002 Advent Networks, Inc.
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#include <rtems/score/types.h>
+#include <rtems/score/arm.h>
+
+/**
+ * @defgroup ScoreCPUARM ARM Specific Support
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM specific support.
+ *
+ * @{
+ */
+
+#ifdef __thumb__
+ #define ARM_SWITCH_REGISTERS uint32_t arm_switch_reg
+ #define ARM_SWITCH_TO_ARM ".align 2\nbx pc\n.arm\n"
+ #define ARM_SWITCH_BACK "add %[arm_switch_reg], pc, #1\nbx %[arm_switch_reg]\n.thumb\n"
+ #define ARM_SWITCH_OUTPUT [arm_switch_reg] "=&r" (arm_switch_reg)
+ #define ARM_SWITCH_ADDITIONAL_OUTPUT , ARM_SWITCH_OUTPUT
+#else
+ #define ARM_SWITCH_REGISTERS
+ #define ARM_SWITCH_TO_ARM
+ #define ARM_SWITCH_BACK
+ #define ARM_SWITCH_OUTPUT
+ #define ARM_SWITCH_ADDITIONAL_OUTPUT
+#endif
+
+/**
+ * @name Program Status Register
+ *
+ * @{
+ */
+
+#define ARM_PSR_N (1 << 31)
+#define ARM_PSR_Z (1 << 30)
+#define ARM_PSR_C (1 << 29)
+#define ARM_PSR_V (1 << 28)
+#define ARM_PSR_Q (1 << 27)
+#define ARM_PSR_J (1 << 24)
+#define ARM_PSR_GE_SHIFT 16
+#define ARM_PSR_GE_MASK (0xf << ARM_PSR_GE_SHIFT)
+#define ARM_PSR_E (1 << 9)
+#define ARM_PSR_A (1 << 8)
+#define ARM_PSR_I (1 << 7)
+#define ARM_PSR_F (1 << 6)
+#define ARM_PSR_T (1 << 5)
+#define ARM_PSR_M_SHIFT 0
+#define ARM_PSR_M_MASK (0x1f << ARM_PSR_M_SHIFT)
+#define ARM_PSR_M_USR 0x10
+#define ARM_PSR_M_FIQ 0x11
+#define ARM_PSR_M_IRQ 0x12
+#define ARM_PSR_M_SVC 0x13
+#define ARM_PSR_M_ABT 0x17
+#define ARM_PSR_M_UND 0x1b
+#define ARM_PSR_M_SYS 0x1f
+
+/** @} */
+
+/** @} */
+
+/**
+ * @addtogroup ScoreCPU
+ *
+ * @{
+ */
+
+/* If someone uses THUMB we assume she wants minimal code size */
+#ifdef __thumb__
+ #define CPU_INLINE_ENABLE_DISPATCH FALSE
+#else
+ #define CPU_INLINE_ENABLE_DISPATCH TRUE
+#endif
+
+#if defined(__ARMEL__)
+ #define CPU_BIG_ENDIAN FALSE
+ #define CPU_LITTLE_ENDIAN TRUE
+#elif defined(__ARMEB__)
+ #define CPU_BIG_ENDIAN TRUE
+ #define CPU_LITTLE_ENDIAN FALSE
+#else
+ #error "unknown endianness"
+#endif
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
+
+#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+#if ( ARM_HAS_FPU == 1 )
+ #define CPU_HARDWARE_FP TRUE
+#else
+ #define CPU_HARDWARE_FP FALSE
+#endif
+
+#define CPU_SOFTWARE_FP FALSE
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+#define CPU_USE_DEFERRED_FP_SWITCH FALSE
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/* XXX Why 32? */
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (32)))
+
+/*
+ * The interrupt mask disables only normal interrupts (IRQ).
+ *
+ * In order to support fast interrupts (FIQ) such that they can do something
+ * useful, we have to disable the operating system support for FIQs. Having
+ * operating system support for them would require that FIQs are disabled
+ * during critical sections of the operating system and application. At this
+ * level IRQs and FIQs would be equal. It is true that FIQs could interrupt
+ * the non critical sections of IRQs, so here they would have a small
+ * advantage. Without operating system support, the FIQs can execute at any
+ * time (of course not during the service of another FIQ). If someone needs
+ * operating system support for a FIQ, she can trigger a software interrupt and
+ * service the request in a two-step process.
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x80
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 8
+
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+#define CPU_STACK_MINIMUM_SIZE (1024 * 4)
+
+/* AAPCS, section 4.1, Fundamental Data Types */
+#define CPU_ALIGNMENT 8
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/* AAPCS, section 5.2.1.2, Stack constraints at a public interface */
+#define CPU_STACK_ALIGNMENT 8
+
+/*
+ * Bitfield handler macros.
+ *
+ * If we had a particularly fast function for finding the first
+ * bit set in a word, it would go here. Since we don't (*), we'll
+ * just use the universal macros.
+ *
+ * (*) On ARM V5 and later, there's a CLZ function which could be
+ * used to implement much quicker than the default macro.
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/** @} */
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup ScoreCPU
+ *
+ * @{
+ */
+
+typedef struct {
+ uint32_t register_cpsr;
+ uint32_t register_r4;
+ uint32_t register_r5;
+ uint32_t register_r6;
+ uint32_t register_r7;
+ uint32_t register_r8;
+ uint32_t register_r9;
+ uint32_t register_r10;
+ uint32_t register_fp;
+ uint32_t register_sp;
+ uint32_t register_lr;
+ uint32_t register_pc;
+} Context_Control;
+
+typedef struct {
+ /* Not supported */
+} Context_Control_fp;
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+extern uint32_t arm_cpu_mode;
+
+static inline uint32_t arm_interrupt_disable( void )
+{
+ uint32_t arm_switch_reg;
+ uint32_t level;
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "mrs %[level], cpsr\n"
+ "orr %[arm_switch_reg], %[level], #0x80\n"
+ "msr cpsr, %[arm_switch_reg]\n"
+ ARM_SWITCH_BACK
+ : [arm_switch_reg] "=&r" (arm_switch_reg), [level] "=&r" (level)
+ );
+
+ return level;
+}
+
+static inline void arm_interrupt_enable( uint32_t level )
+{
+ ARM_SWITCH_REGISTERS;
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "msr cpsr, %[level]\n"
+ ARM_SWITCH_BACK
+ : ARM_SWITCH_OUTPUT
+ : [level] "r" (level)
+ );
+}
+
+static inline void arm_interrupt_flash( uint32_t level )
+{
+ uint32_t arm_switch_reg;
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "mrs %[arm_switch_reg], cpsr\n"
+ "msr cpsr, %[level]\n"
+ "msr cpsr, %[arm_switch_reg]\n"
+ ARM_SWITCH_BACK
+ : [arm_switch_reg] "=&r" (arm_switch_reg)
+ : [level] "r" (level)
+ );
+}
+
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ do { \
+ _isr_cookie = arm_interrupt_disable(); \
+ } while (0)
+
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ arm_interrupt_enable( _isr_cookie )
+
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ arm_interrupt_flash( _isr_cookie )
+
+void _CPU_ISR_Set_level( uint32_t level );
+
+uint32_t _CPU_ISR_Get_level( void );
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->register_sp
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+#define _CPU_Context_Initialize_fp( _destination ) \
+ do { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ } while (0)
+
+#define _CPU_Fatal_halt( _err ) \
+ do { \
+ uint32_t _level; \
+ uint32_t _error = _err; \
+ _CPU_ISR_Disable( _level ); \
+ __asm__ volatile ("mov r0, %0\n" \
+ : "=r" (_error) \
+ : "0" (_error) \
+ : "r0" ); \
+ while (1); \
+ } while (0);
+
+void _CPU_Initialize( void );
+
+#define _CPU_Initialize_vectors()
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+void _CPU_Install_interrupt_stack( void );
+
+void _CPU_Context_switch( Context_Control *run, Context_Control *heir );
+
+void _CPU_Context_restore( Context_Control *new_context )
+ RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+void _CPU_Context_save_fp( Context_Control_fp **fp_context_ptr );
+
+void _CPU_Context_restore_fp( Context_Control_fp **fp_context_ptr );
+
+static inline uint32_t CPU_swap_u32( uint32_t value )
+{
+#if defined(__thumb__)
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return swapped;
+#else
+ uint32_t tmp = value; /* make compiler warnings go away */
+ __asm__ volatile ("EOR %1, %0, %0, ROR #16\n"
+ "BIC %1, %1, #0xff0000\n"
+ "MOV %0, %0, ROR #8\n"
+ "EOR %0, %0, %1, LSR #8\n"
+ : "=r" (value), "=r" (tmp)
+ : "0" (value), "1" (tmp));
+ return value;
+#endif
+}
+
+static inline uint16_t CPU_swap_u16( uint16_t value )
+{
+ return (uint16_t) (((value & 0xffU) << 8) | ((value >> 8) & 0xffU));
+}
+
+/** @} */
+
+/**
+ * @addtogroup ScoreCPUARM
+ *
+ * @{
+ */
+
+typedef struct {
+ uint32_t r0;
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t r11;
+ uint32_t r12;
+ uint32_t sp;
+ uint32_t lr;
+ uint32_t pc;
+ uint32_t cpsr;
+} arm_cpu_context;
+
+typedef void arm_exc_abort_handler( arm_cpu_context *context );
+
+typedef enum {
+ ARM_EXCEPTION_RESET = 0,
+ ARM_EXCEPTION_UNDEF = 1,
+ ARM_EXCEPTION_SWI = 2,
+ ARM_EXCEPTION_PREF_ABORT = 3,
+ ARM_EXCEPTION_DATA_ABORT = 4,
+ ARM_EXCEPTION_RESERVED = 5,
+ ARM_EXCEPTION_IRQ = 6,
+ ARM_EXCEPTION_FIQ = 7,
+ MAX_EXCEPTIONS = 8
+} Arm_symbolic_exception_name;
+
+static inline uint32_t arm_status_irq_enable( void )
+{
+ uint32_t arm_switch_reg;
+ uint32_t psr;
+
+ RTEMS_COMPILER_MEMORY_BARRIER();
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "mrs %[psr], cpsr\n"
+ "bic %[arm_switch_reg], %[psr], #0x80\n"
+ "msr cpsr, %[arm_switch_reg]\n"
+ ARM_SWITCH_BACK
+ : [arm_switch_reg] "=&r" (arm_switch_reg), [psr] "=&r" (psr)
+ );
+
+ return psr;
+}
+
+static inline void arm_status_restore( uint32_t psr )
+{
+ ARM_SWITCH_REGISTERS;
+
+ __asm__ volatile (
+ ARM_SWITCH_TO_ARM
+ "msr cpsr, %[psr]\n"
+ ARM_SWITCH_BACK
+ : ARM_SWITCH_OUTPUT
+ : [psr] "r" (psr)
+ );
+
+ RTEMS_COMPILER_MEMORY_BARRIER();
+}
+
+void arm_exc_data_abort_set_handler( arm_exc_abort_handler handler );
+
+void arm_exc_data_abort( void );
+
+void arm_exc_prefetch_abort_set_handler( arm_exc_abort_handler handler );
+
+void arm_exc_prefetch_abort( void );
+
+void bsp_interrupt_dispatch( void );
+
+void arm_exc_interrupt( void );
+
+void arm_exc_undefined( void );
+
+/** @} */
+
+/* XXX This is out of date */
+typedef struct {
+ uint32_t register_r0;
+ uint32_t register_r1;
+ uint32_t register_r2;
+ uint32_t register_r3;
+ uint32_t register_ip;
+ uint32_t register_lr;
+} CPU_Exception_frame;
+
+typedef CPU_Exception_frame CPU_Interrupt_frame;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ASM */
+
+#endif /* _RTEMS_SCORE_CPU_H */
diff --git a/cpukit/score/cpu/arm/rtems/score/cpu_asm.h b/cpukit/score/cpu/arm/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..ac93112c30
--- /dev/null
+++ b/cpukit/score/cpu/arm/rtems/score/cpu_asm.h
@@ -0,0 +1,41 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM assembler support API.
+ */
+
+/*
+ * $Id$
+ *
+ * COPYRIGHT (c) 2002 by Advent Networks, Inc.
+ * Jay Monkman <jmonkman@adventnetworks.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * This file is the include file for cpu_asm.S
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+
+/* Registers saved in context switch: */
+.set REG_CPSR, 0
+.set REG_R4, 4
+.set REG_R5, 8
+.set REG_R6, 12
+.set REG_R7, 16
+.set REG_R8, 20
+.set REG_R9, 24
+.set REG_R10, 28
+.set REG_R11, 32
+.set REG_SP, 36
+.set REG_LR, 40
+.set REG_PC, 44
+.set SIZE_REGS, REG_PC + 4
+
+#endif
diff --git a/cpukit/score/cpu/arm/rtems/score/types.h b/cpukit/score/cpu/arm/rtems/score/types.h
new file mode 100644
index 0000000000..5eb1bf7765
--- /dev/null
+++ b/cpukit/score/cpu/arm/rtems/score/types.h
@@ -0,0 +1,55 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreCPU
+ *
+ * @brief ARM architecture types API.
+ */
+
+/*
+ * $Id$
+ *
+ * This include file contains type definitions pertaining to the
+ * arm processor family.
+ *
+ * COPYRIGHT (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup ScoreCPU
+ *
+ * @{
+ */
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/avr/.cvsignore b/cpukit/score/cpu/avr/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/avr/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/avr/ChangeLog b/cpukit/score/cpu/avr/ChangeLog
new file mode 100644
index 0000000000..4abccfdc3f
--- /dev/null
+++ b/cpukit/score/cpu/avr/ChangeLog
@@ -0,0 +1,349 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * avr/power.h: Revert previous patch.
+
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, avr/interrupt.h, avr/power.h, rtems/score/cpu.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-11-06 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ PR 1715/cpukit
+ * rtems/score/cpu.h: Fix typo on _CPU_Context_Restart_self.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * cpu_asm.S: Rename _Context_Switch_necessary to
+ _Thread_Dispatch_necessary to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/asm.h: Fixed header guard.
+ * rtems/score/cpu.h: Assembler compatibility fixes.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.S, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-05-10 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * Makefile.am, cpu_asm.S, avr/boot.h, avr/common.h, avr/crc16.h,
+ avr/delay.h, avr/eeprom.h, avr/fuse.h, avr/interrupt.h, avr/io.h,
+ avr/io1200.h, avr/io2313.h, avr/io2323.h, avr/io2333.h, avr/io2343.h,
+ avr/io43u32x.h, avr/io43u35x.h, avr/io4414.h, avr/io4433.h,
+ avr/io4434.h, avr/io76c711.h, avr/io8515.h, avr/io8534.h,
+ avr/io8535.h, avr/io86r401.h, avr/io90pwm1.h, avr/io90pwm216.h,
+ avr/io90pwm2b.h, avr/io90pwm316.h, avr/io90pwm3b.h, avr/io90pwm81.h,
+ avr/io90pwmx.h, avr/io90scr100.h, avr/ioa6289.h, avr/ioat94k.h,
+ avr/iocan128.h, avr/iocan32.h, avr/iocan64.h, avr/iocanxx.h,
+ avr/iom103.h, avr/iom128.h, avr/iom1280.h, avr/iom1281.h,
+ avr/iom1284p.h, avr/iom128rfa1.h, avr/iom16.h, avr/iom161.h,
+ avr/iom162.h, avr/iom163.h, avr/iom164.h, avr/iom165.h,
+ avr/iom165p.h, avr/iom168.h, avr/iom168p.h, avr/iom169.h,
+ avr/iom169p.h, avr/iom16hva.h, avr/iom16m1.h, avr/iom16u4.h,
+ avr/iom2560.h, avr/iom2561.h, avr/iom32.h, avr/iom323.h,
+ avr/iom324.h, avr/iom325.h, avr/iom3250.h, avr/iom328p.h,
+ avr/iom329.h, avr/iom3290.h, avr/iom32c1.h, avr/iom32hvb.h,
+ avr/iom32m1.h, avr/iom32u4.h, avr/iom32u6.h, avr/iom406.h,
+ avr/iom48.h, avr/iom48p.h, avr/iom64.h, avr/iom640.h, avr/iom644.h,
+ avr/iom645.h, avr/iom6450.h, avr/iom649.h, avr/iom6490.h,
+ avr/iom64c1.h, avr/iom64m1.h, avr/iom8.h, avr/iom8515.h,
+ avr/iom8535.h, avr/iom88.h, avr/iom88p.h, avr/iom8hva.h, avr/iomx8.h,
+ avr/iomxx0_1.h, avr/iomxx4.h, avr/iomxxhva.h, avr/iotn11.h,
+ avr/iotn12.h, avr/iotn13.h, avr/iotn13a.h, avr/iotn15.h,
+ avr/iotn167.h, avr/iotn22.h, avr/iotn2313.h, avr/iotn24.h,
+ avr/iotn25.h, avr/iotn26.h, avr/iotn261.h, avr/iotn28.h,
+ avr/iotn43u.h, avr/iotn44.h, avr/iotn45.h, avr/iotn461.h,
+ avr/iotn48.h, avr/iotn84.h, avr/iotn85.h, avr/iotn861.h,
+ avr/iotn87.h, avr/iotn88.h, avr/iotnx4.h, avr/iotnx5.h,
+ avr/iotnx61.h, avr/iousb1286.h, avr/iousb1287.h, avr/iousb162.h,
+ avr/iousb646.h, avr/iousb647.h, avr/iousb82.h, avr/iousbxx2.h,
+ avr/iousbxx6_7.h, avr/iox128a1.h, avr/iox128a3.h, avr/iox16a4.h,
+ avr/iox16d4.h, avr/iox256a3.h, avr/iox256a3b.h, avr/iox32a4.h,
+ avr/iox32d4.h, avr/iox64a1.h, avr/iox64a3.h, avr/lock.h,
+ avr/parity.h, avr/pgmspace.h, avr/portpins.h, avr/power.h,
+ avr/sfr_defs.h, avr/signal.h, avr/sleep.h, avr/version.h, avr/wdt.h,
+ rtems/asm.h, rtems/score/cpu.h: Update to avr .h files from avr-libc
+ 1.6.8. Tinker with code and includes to eliminate warnings. Now
+ builds multilib.
+ * avr/iom169pa.h, avr/iom16a.h, avr/iom16hva2.h, avr/iom16hvb.h,
+ avr/iom16u2.h, avr/iom324pa.h, avr/iom32u2.h, avr/iom644p.h,
+ avr/iom644pa.h, avr/iom649p.h, avr/iom64hve.h, avr/iom88pa.h,
+ avr/iom8u2.h, avr/iotn2313a.h, avr/iotn24a.h, avr/iotn261a.h,
+ avr/iotn4313.h, avr/iotn44a.h, avr/iotn461a.h, avr/iotn861a.h,
+ avr/iox128d3.h, avr/iox192a3.h, avr/iox192d3.h, avr/iox256d3.h,
+ avr/iox64d3.h, avr/signature.h: New files.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S: Add include of config.h
+
+2009-12-02 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/avr.h: Add avr6.
+
+2009-08-11 Josh Switnicki <josh.switnicki@utoronto.ca>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h: Fix bug in
+ _CPU_Context_Initialize.
+
+2009-08-05 Josh Switnicki <josh.switnicki@utoronto.ca>
+
+ * Makefile.am: added AVR specific Header files to score/cpu/avr/avr.
+ These are from avr-libc 1.6 and assumed to exist by AVR applications.
+ * preinstall.am: Regenerated.
+
+2009-07-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h: Context switch now works well
+ enough to run ticker to completion with the simulator clock idle
+ task. But if you comment out the printk's in _CPU_Context_Initialize,
+ it hangs. This remains to be investigated.
+
+2009-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S: Unsuccessful attempt to fix.
+
+2009-07-17 Josh Switnicki <josh.switnicki@utoronto.ca>
+
+ *cpu_asm.S: implemented _CPU_Context_Restore by adding tags to
+ restore section of context switch.
+ Fixed bug in _CPU_Context_Switch. The wrong registers were being
+ used for pointer to running task Context_Control struct.
+
+2009-07-09 Josh Switnicki <josh.switnicki@utoronto.ca>
+
+ * cpu_asm.S: Fixed bug in _CPU_Context_Switch. The wrong registers
+ were being used for pointer to running task Context_Control
+ struct.
+
+2009-07-03 Josh Switnicki <josh.switnicki@utoronto.ca>
+
+ * cpu.c: Implemented _CPU_Context_Initialize as a C function instead
+ of a macro. It works with limited functionality. Implemented
+ _CPU_Thread_Idle_body to use sleep instruction.
+ * Makefile.am: Changed cpu_asm.c -> cpu_asm.S
+ * cpu_asm.S: renamed from cpu_asm.c and implemented functions is asm
+ * rtems/asm.h: Appended "macros.inc" to the end of "asm.h"
+ * rtems/score/cpu.h:
+ + Included "avr/io.h".
+ + Added use 16 bit object definition.
+ + Modified Context_Control struct to relect the registers
+ that need to be saved.
+ + Implemented _CPU_ISR_Disable, _CPU_ISR_Enable, and _CPU_ISR_Flash.
+ Added function definitions for _CPU_Context_Initialize and
+ _CPU_Push.
+
+2009-05-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Lower number of priorities and do not inline as
+ much.
+
+2009-05-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Lower minimum stack size to 512 and CPU alignment
+ to 4.
+
+2009-05-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.c: Add stub for setjmp/longjmp. Remove when in newlib.
+
+2009-02-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: AVR stack grows down.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.c: Remove warnings -- even if code is just temporary.
+
+2008-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.c: Add debug printk() calls until the BSP/port can
+ initialize and shutdown completely cleanly. When this works,
+ implement context switch. Testing on avrtest and simulavr.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/avr.h: Add avr25, avr31, avr35, avr51 to
+ CPU_NAME cascade.
+ * rtems/score/cpu.h: Add missing prototypes.h.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/avr.h: Sweep to make sure grep for COPYRIGHT passes.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu_asm.c:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-02-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove traces from NO_CPU.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/avr.h, rtems/score/cpu.h,
+ rtems/score/cpu_asm.h, rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: *_swap_u32( uint32_t ).
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/avr.h: Add doxygen preamble.
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/cpu_asm.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-11-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/types.h: s/no_cpu/avr/g.
+ Use POSIX types from rtems/stdint.h.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: i960 obsoleted and all references removed.
+
+2004-09-23 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/types.h, rtems/score/cpu.h, rtems/score/cpu_asm.h,
+ rtems/score/avr.h, Makefile.am, asm.h, cpu.c, cpu_asm.c, README:
+ New.
+
diff --git a/cpukit/score/cpu/avr/Makefile.am b/cpukit/score/cpu/avr/Makefile.am
new file mode 100644
index 0000000000..cd026461ce
--- /dev/null
+++ b/cpukit/score/cpu/avr/Makefile.am
@@ -0,0 +1,58 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/avr.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+include_rtems_avrdir = $(includedir)/avr
+include_rtems_avr_HEADERS = \
+ avr/boot.h avr/common.h avr/crc16.h avr/delay.h avr/eeprom.h \
+ avr/fuse.h avr/interrupt.h avr/io1200.h avr/io2313.h \
+ avr/io2323.h avr/io2333.h avr/io2343.h avr/io43u32x.h \
+ avr/io43u35x.h avr/io4414.h avr/io4433.h avr/io4434.h \
+ avr/io76c711.h avr/io8515.h avr/io8534.h avr/io8535.h \
+ avr/io86r401.h avr/io90pwm1.h avr/io90pwm216.h avr/io90pwm2b.h \
+ avr/io90pwm316.h avr/io90pwm3b.h avr/io90pwm81.h avr/io90pwmx.h \
+ avr/io90scr100.h avr/ioa6289.h avr/ioat94k.h avr/iocan128.h \
+ avr/iocan32.h avr/iocan64.h avr/iocanxx.h avr/io.h avr/iom103.h \
+ avr/iom1280.h avr/iom1281.h avr/iom1284p.h avr/iom128.h \
+ avr/iom128rfa1.h avr/iom161.h avr/iom162.h avr/iom163.h \
+ avr/iom164.h avr/iom165.h avr/iom165p.h avr/iom168.h \
+ avr/iom168p.h avr/iom169.h avr/iom169p.h avr/iom16.h \
+ avr/iom16hva.h avr/iom16m1.h avr/iom16u4.h avr/iom2560.h \
+ avr/iom2561.h avr/iom323.h avr/iom324.h avr/iom3250.h \
+ avr/iom325.h avr/iom328p.h avr/iom3290.h avr/iom329.h \
+ avr/iom32c1.h avr/iom32.h avr/iom32hvb.h avr/iom32m1.h \
+ avr/iom32u4.h avr/iom32u6.h avr/iom406.h avr/iom48.h \
+ avr/iom48p.h avr/iom640.h avr/iom644.h avr/iom6450.h \
+ avr/iom645.h avr/iom6490.h avr/iom649.h avr/iom64c1.h \
+ avr/iom64.h avr/iom64m1.h avr/iom8515.h avr/iom8535.h \
+ avr/iom88.h avr/iom88p.h avr/iom8.h avr/iom8hva.h avr/iomx8.h \
+ avr/iomxx0_1.h avr/iomxx4.h avr/iomxxhva.h avr/iotn11.h \
+ avr/iotn12.h avr/iotn13a.h avr/iotn13.h avr/iotn15.h \
+ avr/iotn167.h avr/iotn22.h avr/iotn2313.h avr/iotn24.h \
+ avr/iotn25.h avr/iotn261.h avr/iotn26.h avr/iotn28.h \
+ avr/iotn43u.h avr/iotn44.h avr/iotn45.h avr/iotn461.h \
+ avr/iotn48.h avr/iotn84.h avr/iotn85.h avr/iotn861.h \
+ avr/iotn87.h avr/iotn88.h avr/iotnx4.h avr/iotnx5.h \
+ avr/iotnx61.h avr/iousb1286.h avr/iousb1287.h avr/iousb162.h \
+ avr/iousb646.h avr/iousb647.h avr/iousb82.h avr/iousbxx2.h \
+ avr/iousbxx6_7.h avr/iox128a1.h avr/iox128a3.h avr/iox16a4.h \
+ avr/iox16d4.h avr/iox256a3b.h avr/iox256a3.h avr/iox32a4.h \
+ avr/iox32d4.h avr/iox64a1.h avr/iox64a3.h avr/lock.h \
+ avr/parity.h avr/pgmspace.h avr/portpins.h avr/power.h \
+ avr/sfr_defs.h avr/signal.h avr/sleep.h avr/version.h avr/wdt.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/avr/README b/cpukit/score/cpu/avr/README
new file mode 100644
index 0000000000..20ac7cc023
--- /dev/null
+++ b/cpukit/score/cpu/avr/README
@@ -0,0 +1,5 @@
+WARNING
+=======
+
+This is just a stub and not a complete and functional port.
+
diff --git a/cpukit/score/cpu/avr/avr/boot.h b/cpukit/score/cpu/avr/avr/boot.h
new file mode 100644
index 0000000000..a2ef9910ce
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/boot.h
@@ -0,0 +1,677 @@
+/* Copyright (c) 2002,2003,2004,2005,2006,2007,2008,2009 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_BOOT_H_
+#define _AVR_BOOT_H_ 1
+
+/** \file */
+/** \defgroup avr_boot <avr/boot.h>: Bootloader Support Utilities
+ \code
+ #include <avr/io.h>
+ #include <avr/boot.h>
+ \endcode
+
+ The macros in this module provide a C language interface to the
+ bootloader support functionality of certain AVR processors. These
+ macros are designed to work with all sizes of flash memory.
+
+ Global interrupts are not automatically disabled for these macros. It
+ is left up to the programmer to do this. See the code example below.
+ Also see the processor datasheet for caveats on having global interrupts
+ enabled during writing of the Flash.
+
+ \note Not all AVR processors provide bootloader support. See your
+ processor datasheet to see if it provides bootloader support.
+
+ \todo From email with Marek: On smaller devices (all except ATmega64/128),
+ __SPM_REG is in the I/O space, accessible with the shorter "in" and "out"
+ instructions - since the boot loader has a limited size, this could be an
+ important optimization.
+
+ \par API Usage Example
+ The following code shows typical usage of the boot API.
+
+ \code
+ #include <inttypes.h>
+ #include <avr/interrupt.h>
+ #include <avr/pgmspace.h>
+
+ void boot_program_page (uint32_t page, uint8_t *buf)
+ {
+ uint16_t i;
+ uint8_t sreg;
+
+ // Disable interrupts.
+
+ sreg = SREG;
+ cli();
+
+ eeprom_busy_wait ();
+
+ boot_page_erase (page);
+ boot_spm_busy_wait (); // Wait until the memory is erased.
+
+ for (i=0; i<SPM_PAGESIZE; i+=2)
+ {
+ // Set up little-endian word.
+
+ uint16_t w = *buf++;
+ w += (*buf++) << 8;
+
+ boot_page_fill (page + i, w);
+ }
+
+ boot_page_write (page); // Store buffer in flash page.
+ boot_spm_busy_wait(); // Wait until the memory is written.
+
+ // Reenable RWW-section again. We need this if we want to jump back
+ // to the application after bootloading.
+
+ boot_rww_enable ();
+
+ // Re-enable interrupts (if they were ever enabled).
+
+ SREG = sreg;
+ }\endcode */
+
+#include <avr/eeprom.h>
+#include <avr/io.h>
+#include <inttypes.h>
+#include <limits.h>
+
+/* Check for SPM Control Register in processor. */
+#if defined (SPMCSR)
+# define __SPM_REG SPMCSR
+#elif defined (SPMCR)
+# define __SPM_REG SPMCR
+#else
+# error AVR processor does not provide bootloader support!
+#endif
+
+
+/* Check for SPM Enable bit. */
+#if defined(SPMEN)
+# define __SPM_ENABLE SPMEN
+#elif defined(SELFPRGEN)
+# define __SPM_ENABLE SELFPRGEN
+#else
+# error Cannot find SPM Enable bit definition!
+#endif
+
+/** \ingroup avr_boot
+ \def BOOTLOADER_SECTION
+
+ Used to declare a function or variable to be placed into a
+ new section called .bootloader. This section and its contents
+ can then be relocated to any address (such as the bootloader
+ NRWW area) at link-time. */
+
+#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))
+
+/* Create common bit definitions. */
+#ifdef ASB
+#define __COMMON_ASB ASB
+#else
+#define __COMMON_ASB RWWSB
+#endif
+
+#ifdef ASRE
+#define __COMMON_ASRE ASRE
+#else
+#define __COMMON_ASRE RWWSRE
+#endif
+
+/* Define the bit positions of the Boot Lock Bits. */
+
+#define BLB12 5
+#define BLB11 4
+#define BLB02 3
+#define BLB01 2
+
+/** \ingroup avr_boot
+ \def boot_spm_interrupt_enable()
+ Enable the SPM interrupt. */
+
+#define boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE))
+
+/** \ingroup avr_boot
+ \def boot_spm_interrupt_disable()
+ Disable the SPM interrupt. */
+
+#define boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE))
+
+/** \ingroup avr_boot
+ \def boot_is_spm_interrupt()
+ Check if the SPM interrupt is enabled. */
+
+#define boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE))
+
+/** \ingroup avr_boot
+ \def boot_rww_busy()
+ Check if the RWW section is busy. */
+
+#define boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB))
+
+/** \ingroup avr_boot
+ \def boot_spm_busy()
+ Check if the SPM instruction is busy. */
+
+#define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(__SPM_ENABLE))
+
+/** \ingroup avr_boot
+ \def boot_spm_busy_wait()
+ Wait while the SPM instruction is busy. */
+
+#define boot_spm_busy_wait() do{}while(boot_spm_busy())
+
+#define __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS))
+#define __BOOT_PAGE_WRITE (_BV(__SPM_ENABLE) | _BV(PGWRT))
+#define __BOOT_PAGE_FILL _BV(__SPM_ENABLE)
+#define __BOOT_RWW_ENABLE (_BV(__SPM_ENABLE) | _BV(__COMMON_ASRE))
+#if defined(BLBSET)
+#define __BOOT_LOCK_BITS_SET (_BV(__SPM_ENABLE) | _BV(BLBSET))
+#elif defined(RFLB) /* Some devices have RFLB defined instead of BLBSET. */
+#define __BOOT_LOCK_BITS_SET (_BV(__SPM_ENABLE) | _BV(RFLB))
+#endif
+
+#define __boot_page_fill_normal(address, data) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "movw r0, %3\n\t" \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ "clr r1\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_PAGE_FILL)), \
+ "z" ((uint16_t)(address)), \
+ "r" ((uint16_t)(data)) \
+ : "r0" \
+ ); \
+}))
+
+#define __boot_page_fill_alternate(address, data)\
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "movw r0, %3\n\t" \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ ".word 0xffff\n\t" \
+ "nop\n\t" \
+ "clr r1\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_PAGE_FILL)), \
+ "z" ((uint16_t)(address)), \
+ "r" ((uint16_t)(data)) \
+ : "r0" \
+ ); \
+}))
+
+#define __boot_page_fill_extended(address, data) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "movw r0, %4\n\t" \
+ "movw r30, %A3\n\t" \
+ "sts %1, %C3\n\t" \
+ "sts %0, %2\n\t" \
+ "spm\n\t" \
+ "clr r1\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "i" (_SFR_MEM_ADDR(RAMPZ)), \
+ "r" ((uint8_t)(__BOOT_PAGE_FILL)), \
+ "r" ((uint32_t)(address)), \
+ "r" ((uint16_t)(data)) \
+ : "r0", "r30", "r31" \
+ ); \
+}))
+
+#define __boot_page_erase_normal(address) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_PAGE_ERASE)), \
+ "z" ((uint16_t)(address)) \
+ ); \
+}))
+
+#define __boot_page_erase_alternate(address) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ ".word 0xffff\n\t" \
+ "nop\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_PAGE_ERASE)), \
+ "z" ((uint16_t)(address)) \
+ ); \
+}))
+
+#define __boot_page_erase_extended(address) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "movw r30, %A3\n\t" \
+ "sts %1, %C3\n\t" \
+ "sts %0, %2\n\t" \
+ "spm\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "i" (_SFR_MEM_ADDR(RAMPZ)), \
+ "r" ((uint8_t)(__BOOT_PAGE_ERASE)), \
+ "r" ((uint32_t)(address)) \
+ : "r30", "r31" \
+ ); \
+}))
+
+#define __boot_page_write_normal(address) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_PAGE_WRITE)), \
+ "z" ((uint16_t)(address)) \
+ ); \
+}))
+
+#define __boot_page_write_alternate(address) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ ".word 0xffff\n\t" \
+ "nop\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_PAGE_WRITE)), \
+ "z" ((uint16_t)(address)) \
+ ); \
+}))
+
+#define __boot_page_write_extended(address) \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "movw r30, %A3\n\t" \
+ "sts %1, %C3\n\t" \
+ "sts %0, %2\n\t" \
+ "spm\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "i" (_SFR_MEM_ADDR(RAMPZ)), \
+ "r" ((uint8_t)(__BOOT_PAGE_WRITE)), \
+ "r" ((uint32_t)(address)) \
+ : "r30", "r31" \
+ ); \
+}))
+
+#define __boot_rww_enable() \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_RWW_ENABLE)) \
+ ); \
+}))
+
+#define __boot_rww_enable_alternate() \
+(__extension__({ \
+ __asm__ __volatile__ \
+ ( \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ ".word 0xffff\n\t" \
+ "nop\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_RWW_ENABLE)) \
+ ); \
+}))
+
+/* From the mega16/mega128 data sheets (maybe others):
+
+ Bits by SPM To set the Boot Loader Lock bits, write the desired data to
+ R0, write "X0001001" to SPMCR and execute SPM within four clock cycles
+ after writing SPMCR. The only accessible Lock bits are the Boot Lock bits
+ that may prevent the Application and Boot Loader section from any
+ software update by the MCU.
+
+ If bits 5..2 in R0 are cleared (zero), the corresponding Boot Lock bit
+ will be programmed if an SPM instruction is executed within four cycles
+ after BLBSET and SPMEN (or SELFPRGEN) are set in SPMCR. The Z-pointer is
+ don't care during this operation, but for future compatibility it is
+ recommended to load the Z-pointer with $0001 (same as used for reading the
+ Lock bits). For future compatibility It is also recommended to set bits 7,
+ 6, 1, and 0 in R0 to 1 when writing the Lock bits. When programming the
+ Lock bits the entire Flash can be read during the operation. */
+
+#define __boot_lock_bits_set(lock_bits) \
+(__extension__({ \
+ uint8_t value = (uint8_t)(~(lock_bits)); \
+ __asm__ __volatile__ \
+ ( \
+ "ldi r30, 1\n\t" \
+ "ldi r31, 0\n\t" \
+ "mov r0, %2\n\t" \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \
+ "r" (value) \
+ : "r0", "r30", "r31" \
+ ); \
+}))
+
+#define __boot_lock_bits_set_alternate(lock_bits) \
+(__extension__({ \
+ uint8_t value = (uint8_t)(~(lock_bits)); \
+ __asm__ __volatile__ \
+ ( \
+ "ldi r30, 1\n\t" \
+ "ldi r31, 0\n\t" \
+ "mov r0, %2\n\t" \
+ "sts %0, %1\n\t" \
+ "spm\n\t" \
+ ".word 0xffff\n\t" \
+ "nop\n\t" \
+ : \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \
+ "r" (value) \
+ : "r0", "r30", "r31" \
+ ); \
+}))
+
+/*
+ Reading lock and fuse bits:
+
+ Similarly to writing the lock bits above, set BLBSET and SPMEN (or
+ SELFPRGEN) bits in __SPMREG, and then (within four clock cycles) issue an
+ LPM instruction.
+
+ Z address: contents:
+ 0x0000 low fuse bits
+ 0x0001 lock bits
+ 0x0002 extended fuse bits
+ 0x0003 high fuse bits
+
+ Sounds confusing, doesn't it?
+
+ Unlike the macros in pgmspace.h, no need to care for non-enhanced
+ cores here as these old cores do not provide SPM support anyway.
+ */
+
+/** \ingroup avr_boot
+ \def GET_LOW_FUSE_BITS
+ address to read the low fuse bits, using boot_lock_fuse_bits_get
+ */
+#define GET_LOW_FUSE_BITS (0x0000)
+/** \ingroup avr_boot
+ \def GET_LOCK_BITS
+ address to read the lock bits, using boot_lock_fuse_bits_get
+ */
+#define GET_LOCK_BITS (0x0001)
+/** \ingroup avr_boot
+ \def GET_EXTENDED_FUSE_BITS
+ address to read the extended fuse bits, using boot_lock_fuse_bits_get
+ */
+#define GET_EXTENDED_FUSE_BITS (0x0002)
+/** \ingroup avr_boot
+ \def GET_HIGH_FUSE_BITS
+ address to read the high fuse bits, using boot_lock_fuse_bits_get
+ */
+#define GET_HIGH_FUSE_BITS (0x0003)
+
+/** \ingroup avr_boot
+ \def boot_lock_fuse_bits_get(address)
+
+ Read the lock or fuse bits at \c address.
+
+ Parameter \c address can be any of GET_LOW_FUSE_BITS,
+ GET_LOCK_BITS, GET_EXTENDED_FUSE_BITS, or GET_HIGH_FUSE_BITS.
+
+ \note The lock and fuse bits returned are the physical values,
+ i.e. a bit returned as 0 means the corresponding fuse or lock bit
+ is programmed.
+ */
+#define boot_lock_fuse_bits_get(address) \
+(__extension__({ \
+ uint8_t __result; \
+ __asm__ __volatile__ \
+ ( \
+ "sts %1, %2\n\t" \
+ "lpm %0, Z\n\t" \
+ : "=r" (__result) \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \
+ "z" ((uint16_t)(address)) \
+ ); \
+ __result; \
+}))
+
+/** \ingroup avr_boot
+ \def boot_signature_byte_get(address)
+
+ Read the Signature Row byte at \c address. For some MCU types,
+ this function can also retrieve the factory-stored oscillator
+ calibration bytes.
+
+ Parameter \c address can be 0-0x1f as documented by the datasheet.
+ \note The values are MCU type dependent.
+*/
+
+#define __BOOT_SIGROW_READ (_BV(__SPM_ENABLE) | _BV(SIGRD))
+
+#define boot_signature_byte_get(addr) \
+(__extension__({ \
+ uint8_t __result; \
+ __asm__ __volatile__ \
+ ( \
+ "sts %1, %2\n\t" \
+ "lpm %0, Z" "\n\t" \
+ : "=r" (__result) \
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
+ "r" ((uint8_t)(__BOOT_SIGROW_READ)), \
+ "z" ((uint16_t)(addr)) \
+ ); \
+ __result; \
+}))
+
+/** \ingroup avr_boot
+ \def boot_page_fill(address, data)
+
+ Fill the bootloader temporary page buffer for flash
+ address with data word.
+
+ \note The address is a byte address. The data is a word. The AVR
+ writes data to the buffer a word at a time, but addresses the buffer
+ per byte! So, increment your address by 2 between calls, and send 2
+ data bytes in a word format! The LSB of the data is written to the lower
+ address; the MSB of the data is written to the higher address.*/
+
+/** \ingroup avr_boot
+ \def boot_page_erase(address)
+
+ Erase the flash page that contains address.
+
+ \note address is a byte address in flash, not a word address. */
+
+/** \ingroup avr_boot
+ \def boot_page_write(address)
+
+ Write the bootloader temporary page buffer
+ to flash page that contains address.
+
+ \note address is a byte address in flash, not a word address. */
+
+/** \ingroup avr_boot
+ \def boot_rww_enable()
+
+ Enable the Read-While-Write memory section. */
+
+/** \ingroup avr_boot
+ \def boot_lock_bits_set(lock_bits)
+
+ Set the bootloader lock bits.
+
+ \param lock_bits A mask of which Boot Loader Lock Bits to set.
+
+ \note In this context, a 'set bit' will be written to a zero value.
+ Note also that only BLBxx bits can be programmed by this command.
+
+ For example, to disallow the SPM instruction from writing to the Boot
+ Loader memory section of flash, you would use this macro as such:
+
+ \code
+ boot_lock_bits_set (_BV (BLB11));
+ \endcode
+
+ \note Like any lock bits, the Boot Loader Lock Bits, once set,
+ cannot be cleared again except by a chip erase which will in turn
+ also erase the boot loader itself. */
+
+/* Normal versions of the macros use 16-bit addresses.
+ Extended versions of the macros use 32-bit addresses.
+ Alternate versions of the macros use 16-bit addresses and require special
+ instruction sequences after LPM.
+
+ FLASHEND is defined in the ioXXXX.h file.
+ USHRT_MAX is defined in <limits.h>. */
+
+#if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \
+ || defined(__AVR_ATmega323__)
+
+/* Alternate: ATmega161/163/323 and 16 bit address */
+#define boot_page_fill(address, data) __boot_page_fill_alternate(address, data)
+#define boot_page_erase(address) __boot_page_erase_alternate(address)
+#define boot_page_write(address) __boot_page_write_alternate(address)
+#define boot_rww_enable() __boot_rww_enable_alternate()
+#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_alternate(lock_bits)
+
+#elif (FLASHEND > USHRT_MAX)
+
+/* Extended: >16 bit address */
+#define boot_page_fill(address, data) __boot_page_fill_extended(address, data)
+#define boot_page_erase(address) __boot_page_erase_extended(address)
+#define boot_page_write(address) __boot_page_write_extended(address)
+#define boot_rww_enable() __boot_rww_enable()
+#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)
+
+#else
+
+/* Normal: 16 bit address */
+#define boot_page_fill(address, data) __boot_page_fill_normal(address, data)
+#define boot_page_erase(address) __boot_page_erase_normal(address)
+#define boot_page_write(address) __boot_page_write_normal(address)
+#define boot_rww_enable() __boot_rww_enable()
+#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)
+
+#endif
+
+/** \ingroup avr_boot
+
+ Same as boot_page_fill() except it waits for eeprom and spm operations to
+ complete before filling the page. */
+
+#define boot_page_fill_safe(address, data) \
+do { \
+ boot_spm_busy_wait(); \
+ eeprom_busy_wait(); \
+ boot_page_fill(address, data); \
+} while (0)
+
+/** \ingroup avr_boot
+
+ Same as boot_page_erase() except it waits for eeprom and spm operations to
+ complete before erasing the page. */
+
+#define boot_page_erase_safe(address) \
+do { \
+ boot_spm_busy_wait(); \
+ eeprom_busy_wait(); \
+ boot_page_erase (address); \
+} while (0)
+
+/** \ingroup avr_boot
+
+ Same as boot_page_write() except it waits for eeprom and spm operations to
+ complete before writing the page. */
+
+#define boot_page_write_safe(address) \
+do { \
+ boot_spm_busy_wait(); \
+ eeprom_busy_wait(); \
+ boot_page_write (address); \
+} while (0)
+
+/** \ingroup avr_boot
+
+ Same as boot_rww_enable() except waits for eeprom and spm operations to
+ complete before enabling the RWW mameory. */
+
+#define boot_rww_enable_safe() \
+do { \
+ boot_spm_busy_wait(); \
+ eeprom_busy_wait(); \
+ boot_rww_enable(); \
+} while (0)
+
+/** \ingroup avr_boot
+
+ Same as boot_lock_bits_set() except waits for eeprom and spm operations to
+ complete before setting the lock bits. */
+
+#define boot_lock_bits_set_safe(lock_bits) \
+do { \
+ boot_spm_busy_wait(); \
+ eeprom_busy_wait(); \
+ boot_lock_bits_set (lock_bits); \
+} while (0)
+
+#endif /* _AVR_BOOT_H_ */
diff --git a/cpukit/score/cpu/avr/avr/common.h b/cpukit/score/cpu/avr/avr/common.h
new file mode 100644
index 0000000000..1df2bf7e72
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/common.h
@@ -0,0 +1,323 @@
+/* Copyright (c) 2007 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+
+#ifndef _AVR_COMMON_H
+#define _AVR_COMMON_H
+
+#include <avr/sfr_defs.h>
+
+/*
+This purpose of this header is to define registers that have not been
+previously defined in the individual device IO header files, and to define
+other symbols that are common across AVR device families.
+
+This file is designed to be included in <avr/io.h> after the individual
+device IO header files, and after <avr/sfr_defs.h>
+
+*/
+
+/*------------ Registers Not Previously Defined ------------*/
+
+/*
+These are registers that are not previously defined in the individual
+IO header files, OR they are defined here because they are used in parts of
+avr-libc even if a device is not selected but a general architecture has
+been selected.
+*/
+
+
+/*
+Stack pointer register.
+
+AVR architecture 1 has no RAM, thus no stack pointer.
+
+All other architectures do have a stack pointer. Some devices have only
+less than 256 bytes of possible RAM locations (128 Bytes of SRAM
+and no option for external RAM), thus SPH is officially "reserved"
+for them.
+*/
+#if __AVR_ARCH__ >= 100
+# ifndef SPL
+# define SPL _SFR_MEM8(0x3D)
+# endif
+# ifndef SPH
+# define SPH _SFR_MEM8(0x3E)
+# endif
+# ifndef SP
+# define SP _SFR_MEM16(0x3D)
+# endif
+#elif __AVR_ARCH__ != 1
+# ifndef SPL
+# define SPL _SFR_IO8(0x3D)
+# endif
+# if XRAMEND < 0x100 && !defined(__COMPILING_AVR_LIBC__)
+# ifndef SP
+# define SP _SFR_IO8(0x3D)
+# endif
+# else
+# ifndef SP
+# define SP _SFR_IO16(0x3D)
+# endif
+# ifndef SPH
+# define SPH _SFR_IO8(0x3E)
+# endif
+# endif /* XRAMEND < 0x100 && !defined(__COMPILING_AVR_LIBC__) */
+#endif /* __AVR_ARCH__ != 1 */
+
+
+/* Status Register */
+#ifndef SREG
+# if __AVR_ARCH__ >= 100
+# define SREG _SFR_MEM8(0x3F)
+# else
+# define SREG _SFR_IO8(0x3F)
+# endif
+#endif
+
+
+/* SREG bit definitions */
+#ifndef SREG_C
+# define SREG_C (0)
+#endif
+#ifndef SREG_Z
+# define SREG_Z (1)
+#endif
+#ifndef SREG_N
+# define SREG_N (2)
+#endif
+#ifndef SREG_V
+# define SREG_V (3)
+#endif
+#ifndef SREG_S
+# define SREG_S (4)
+#endif
+#ifndef SREG_H
+# define SREG_H (5)
+#endif
+#ifndef SREG_T
+# define SREG_T (6)
+#endif
+#ifndef SREG_I
+# define SREG_I (7)
+#endif
+
+
+#if defined(__COMPILING_AVR_LIBC__)
+
+/* AVR 6 Architecture */
+# if __AVR_ARCH__ == 6
+# ifndef EIND
+# define EIND _SFR_IO8(0X3C)
+# endif
+/* XMEGA Architectures */
+# elif __AVR_ARCH__ >= 100
+# ifndef EIND
+# define EIND _SFR_MEM8(0x3C)
+# endif
+# endif
+
+/*
+Only few devices come without EEPROM. In order to assemble the
+EEPROM library components without defining a specific device, we
+keep the EEPROM-related definitions here.
+*/
+
+/* EEPROM Control Register */
+# ifndef EECR
+# define EECR _SFR_IO8(0x1C)
+# endif
+
+/* EEPROM Data Register */
+# ifndef EEDR
+# define EEDR _SFR_IO8(0x1D)
+# endif
+
+/* EEPROM Address Register */
+# ifndef EEAR
+# define EEAR _SFR_IO16(0x1E)
+# endif
+# ifndef EEARL
+# define EEARL _SFR_IO8(0x1E)
+# endif
+# ifndef EEARH
+# define EEARH _SFR_IO8(0x1F)
+# endif
+
+/* EEPROM Control Register bits */
+# ifndef EERE
+# define EERE (0)
+# endif
+# ifndef EEWE
+# define EEWE (1)
+# endif
+# ifndef EEMWE
+# define EEMWE (2)
+# endif
+# ifndef EERIE
+# define EERIE (3)
+# endif
+
+#endif /* __COMPILING_AVR_LIBC__ */
+
+
+
+/*------------ Common Symbols ------------*/
+
+/*
+Generic definitions for registers that are common across multiple AVR devices
+and families.
+*/
+
+/* Pointer registers definitions */
+#if __AVR_ARCH__ != 1 /* avr1 does not have X and Y pointers */
+# define XL r26
+# define XH r27
+# define YL r28
+# define YH r29
+#endif /* #if __AVR_ARCH__ != 1 */
+#define ZL r30
+#define ZH r31
+
+
+/* Status Register */
+#if defined(SREG)
+# define AVR_STATUS_REG SREG
+# if __AVR_ARCH__ >= 100
+# define AVR_STATUS_ADDR _SFR_MEM_ADDR(SREG)
+# else
+# define AVR_STATUS_ADDR _SFR_IO_ADDR(SREG)
+# endif
+#endif
+
+/* Stack Pointer (combined) Register */
+#if defined(SP)
+# define AVR_STACK_POINTER_REG SP
+# if __AVR_ARCH__ >= 100
+# define AVR_STACK_POINTER_ADDR _SFR_MEM_ADDR(SP)
+# else
+# define AVR_STACK_POINTER_ADDR _SFR_IO_ADDR(SP)
+# endif
+#endif
+
+/* Stack Pointer High Register */
+#if defined(SPH)
+# define _HAVE_AVR_STACK_POINTER_HI 1
+# define AVR_STACK_POINTER_HI_REG SPH
+# if __AVR_ARCH__ >= 100
+# define AVR_STACK_POINTER_HI_ADDR _SFR_MEM_ADDR(SPH)
+# else
+# define AVR_STACK_POINTER_HI_ADDR _SFR_IO_ADDR(SPH)
+# endif
+#endif
+
+/* Stack Pointer Low Register */
+#if defined(SPL)
+# define AVR_STACK_POINTER_LO_REG SPL
+# if __AVR_ARCH__ >= 100
+# define AVR_STACK_POINTER_LO_ADDR _SFR_MEM_ADDR(SPL)
+# else
+# define AVR_STACK_POINTER_LO_ADDR _SFR_IO_ADDR(SPL)
+# endif
+#endif
+
+/* RAMPD Register */
+#if defined(RAMPD)
+# define AVR_RAMPD_REG RAMPD
+# if __AVR_ARCH__ >= 100
+# define AVR_RAMPD_ADDR _SFR_MEM_ADDR(RAMPD)
+# else
+# define AVR_RAMPD_ADDR _SFR_IO_ADDR(RAMPD)
+# endif
+#endif
+
+/* RAMPX Register */
+#if defined(RAMPX)
+# define AVR_RAMPX_REG RAMPX
+# if __AVR_ARCH__ >= 100
+# define AVR_RAMPX_ADDR _SFR_MEM_ADDR(RAMPX)
+# else
+# define AVR_RAMPX_ADDR _SFR_IO_ADDR(RAMPX)
+# endif
+#endif
+
+/* RAMPY Register */
+#if defined(RAMPY)
+# define AVR_RAMPY_REG RAMPY
+# if __AVR_ARCH__ >= 100
+# define AVR_RAMPY_ADDR _SFR_MEM_ADDR(RAMPY)
+# else
+# define AVR_RAMPY_ADDR _SFR_IO_ADDR(RAMPY)
+# endif
+#endif
+
+/* RAMPZ Register */
+#if defined(RAMPZ)
+# define AVR_RAMPZ_REG RAMPZ
+# if __AVR_ARCH__ >= 100
+# define AVR_RAMPZ_ADDR _SFR_MEM_ADDR(RAMPZ)
+# else
+# define AVR_RAMPZ_ADDR _SFR_IO_ADDR(RAMPZ)
+# endif
+#endif
+
+/* Extended Indirect Register */
+#if defined(EIND)
+# define AVR_EXTENDED_INDIRECT_REG EIND
+# if __AVR_ARCH__ >= 100
+# define AVR_EXTENDED_INDIRECT_ADDR _SFR_MEM_ADDR(EIND)
+# else
+# define AVR_EXTENDED_INDIRECT_ADDR _SFR_IO_ADDR(EIND)
+# endif
+#endif
+
+/*------------ Workaround to old compilers (4.1.2 and earlier) ------------*/
+
+#ifndef __AVR_HAVE_MOVW__
+# if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
+# define __AVR_HAVE_MOVW__ 1
+# endif
+#endif
+
+#ifndef __AVR_HAVE_LPMX__
+# if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
+# define __AVR_HAVE_LPMX__ 1
+# endif
+#endif
+
+#ifndef __AVR_HAVE_MUL__
+# if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
+# define __AVR_HAVE_MUL__ 1
+# endif
+#endif
+
+#endif /* _AVR_COMMON_H */
diff --git a/cpukit/score/cpu/avr/avr/crc16.h b/cpukit/score/cpu/avr/avr/crc16.h
new file mode 100644
index 0000000000..6c8de25ea0
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/crc16.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 2005 Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_CRC16_H_
+#define _AVR_CRC16_H_
+
+#warning "This file has been moved to <util/crc16.h>."
+#include <util/crc16.h>
+
+#endif /* _AVR_CRC16_H_ */
diff --git a/cpukit/score/cpu/avr/avr/delay.h b/cpukit/score/cpu/avr/avr/delay.h
new file mode 100644
index 0000000000..2847cebb97
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/delay.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 2005 Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_DELAY_H_
+#define _AVR_DELAY_H_
+
+#warning "This file has been moved to <util/delay.h>."
+#include <util/delay.h>
+
+#endif /* _AVR_DELAY_H_ */
diff --git a/cpukit/score/cpu/avr/avr/eeprom.h b/cpukit/score/cpu/avr/avr/eeprom.h
new file mode 100644
index 0000000000..e590a04a51
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/eeprom.h
@@ -0,0 +1,606 @@
+/* Copyright (c) 2002, 2003, 2004, 2007 Marek Michalkiewicz
+ Copyright (c) 2005, 2006 Bjoern Haase
+ Copyright (c) 2008 Atmel Corporation
+ Copyright (c) 2008 Wouter van Gulik
+ Copyright (c) 2009 Dmitry Xmelkov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_EEPROM_H_
+#define _AVR_EEPROM_H_ 1
+
+#include <avr/io.h>
+
+#if !E2END && !defined(__DOXYGEN__) && !defined(__COMPILING_AVR_LIBC__)
+# warning "Device does not have EEPROM available."
+#else
+
+#ifndef __DOXYGEN__
+
+#if defined (__AVR_AT94K__)
+# define _EEPROM_SUFFIX _at94k
+#elif defined (__AVR_AT43USB320__)
+# define _EEPROM_SUFFIX _43u320
+#elif defined (__AVR_AT43USB355__)
+# define _EEPROM_SUFFIX _43u355
+#elif defined (__AVR_AT76C711__)
+# define _EEPROM_SUFFIX _76c711
+#elif defined (__AVR_AT86RF401__)
+# define _EEPROM_SUFFIX _86r401
+#elif defined (__AVR_AT90PWM1__)
+# define _EEPROM_SUFFIX _90pwm1
+#elif defined (__AVR_AT90PWM2__)
+# define _EEPROM_SUFFIX _90pwm2
+#elif defined (__AVR_AT90PWM2B__)
+# define _EEPROM_SUFFIX _90pwm2b
+#elif defined (__AVR_AT90PWM3__)
+# define _EEPROM_SUFFIX _90pwm3
+#elif defined (__AVR_AT90PWM3B__)
+# define _EEPROM_SUFFIX _90pwm3b
+#elif defined (__AVR_AT90PWM216__)
+# define _EEPROM_SUFFIX _90pwm216
+#elif defined (__AVR_AT90PWM316__)
+# define _EEPROM_SUFFIX _90pwm316
+#elif defined (__AVR_AT90PWM81__)
+# define _EEPROM_SUFFIX _90pwm81
+#elif defined (__AVR_ATmega16M1__)
+# define _EEPROM_SUFFIX _m16m1
+#elif defined (__AVR_ATmega8U2__)
+# define _EEPROM_SUFFIX _m8u2
+#elif defined (__AVR_ATmega16U2__)
+# define _EEPROM_SUFFIX _m16u2
+#elif defined (__AVR_ATmega16U4__)
+# define _EEPROM_SUFFIX _m16u4
+#elif defined (__AVR_ATmega32C1__)
+# define _EEPROM_SUFFIX _m32c1
+#elif defined (__AVR_ATmega32M1__)
+# define _EEPROM_SUFFIX _m32m1
+#elif defined (__AVR_ATmega32U2__)
+# define _EEPROM_SUFFIX _m32u2
+#elif defined (__AVR_ATmega32U4__)
+# define _EEPROM_SUFFIX _m32u4
+#elif defined (__AVR_ATmega32U6__)
+# define _EEPROM_SUFFIX _m32u6
+#elif defined (__AVR_ATmega64C1__)
+# define _EEPROM_SUFFIX _m64c1
+#elif defined (__AVR_ATmega64M1__)
+# define _EEPROM_SUFFIX _m64m1
+#elif defined (__AVR_ATmega128__)
+# define _EEPROM_SUFFIX _m128
+#elif defined (__AVR_ATmega1280__)
+# define _EEPROM_SUFFIX _m1280
+#elif defined (__AVR_ATmega1281__)
+# define _EEPROM_SUFFIX _m1281
+#elif defined (__AVR_ATmega1284P__)
+# define _EEPROM_SUFFIX _m1284p
+#elif defined (__AVR_ATmega128RFA1__)
+# define _EEPROM_SUFFIX _m128rfa1
+#elif defined (__AVR_ATmega2560__)
+# define _EEPROM_SUFFIX _m2560
+#elif defined (__AVR_ATmega2561__)
+# define _EEPROM_SUFFIX _m2561
+#elif defined (__AVR_AT90CAN32__)
+# define _EEPROM_SUFFIX _can32
+#elif defined (__AVR_AT90CAN64__)
+# define _EEPROM_SUFFIX _can64
+#elif defined (__AVR_AT90CAN128__)
+# define _EEPROM_SUFFIX _can128
+#elif defined (__AVR_AT90USB82__)
+# define _EEPROM_SUFFIX _usb82
+#elif defined (__AVR_AT90USB162__)
+# define _EEPROM_SUFFIX _usb162
+#elif defined (__AVR_AT90USB646__)
+# define _EEPROM_SUFFIX _usb646
+#elif defined (__AVR_AT90USB647__)
+# define _EEPROM_SUFFIX _usb647
+#elif defined (__AVR_AT90USB1286__)
+# define _EEPROM_SUFFIX _usb1286
+#elif defined (__AVR_AT90USB1287__)
+# define _EEPROM_SUFFIX _usb1287
+#elif defined (__AVR_ATmega64__)
+# define _EEPROM_SUFFIX _m64
+#elif defined (__AVR_ATmega640__)
+# define _EEPROM_SUFFIX _m640
+#elif defined (__AVR_ATmega644__)
+# define _EEPROM_SUFFIX _m644
+#elif defined (__AVR_ATmega644A__)
+# define _EEPROM_SUFFIX _m644a
+#elif defined (__AVR_ATmega644P__)
+# define _EEPROM_SUFFIX _m644p
+#elif defined (__AVR_ATmega644PA__)
+# define _EEPROM_SUFFIX _m644pa
+#elif defined (__AVR_ATmega645__)
+# define _EEPROM_SUFFIX _m645
+#elif defined (__AVR_ATmega645A__)
+# define _EEPROM_SUFFIX _m645a
+#elif defined (__AVR_ATmega645P__)
+# define _EEPROM_SUFFIX _m645p
+#elif defined (__AVR_ATmega6450__)
+# define _EEPROM_SUFFIX _m6450
+#elif defined (__AVR_ATmega6450A__)
+# define _EEPROM_SUFFIX _m6450a
+#elif defined (__AVR_ATmega6450P__)
+# define _EEPROM_SUFFIX _m6450p
+#elif defined (__AVR_ATmega649__)
+# define _EEPROM_SUFFIX _m649
+#elif defined (__AVR_ATmega649A__)
+# define _EEPROM_SUFFIX _m649a
+#elif defined (__AVR_ATmega649P__)
+# define _EEPROM_SUFFIX _m649p
+#elif defined (__AVR_ATmega6490__)
+# define _EEPROM_SUFFIX _m6490
+#elif defined (__AVR_ATmega6490A__)
+# define _EEPROM_SUFFIX _m6490a
+#elif defined (__AVR_ATmega6490P__)
+# define _EEPROM_SUFFIX _m6490p
+#elif defined (__AVR_ATmega103__)
+# define _EEPROM_SUFFIX _m103
+#elif defined (__AVR_ATmega32__)
+# define _EEPROM_SUFFIX _m32
+#elif defined (__AVR_ATmega323__)
+# define _EEPROM_SUFFIX _m323
+#elif defined (__AVR_ATmega324A__)
+# define _EEPROM_SUFFIX _m324a
+#elif defined (__AVR_ATmega324P__)
+# define _EEPROM_SUFFIX _m324p
+#elif defined (__AVR_ATmega324PA__)
+# define _EEPROM_SUFFIX _m324pa
+#elif defined (__AVR_ATmega325__)
+# define _EEPROM_SUFFIX _m325
+#elif defined (__AVR_ATmega325P__)
+# define _EEPROM_SUFFIX _m325p
+#elif defined (__AVR_ATmega3250__)
+# define _EEPROM_SUFFIX _m3250
+#elif defined (__AVR_ATmega3250P__)
+# define _EEPROM_SUFFIX _m3250p
+#elif defined (__AVR_ATmega328__)
+# define _EEPROM_SUFFIX _m328
+#elif defined (__AVR_ATmega328P__)
+# define _EEPROM_SUFFIX _m328p
+#elif defined (__AVR_ATmega329__)
+# define _EEPROM_SUFFIX _m329
+#elif defined (__AVR_ATmega329P__)
+# define _EEPROM_SUFFIX _m329p
+#elif defined (__AVR_ATmega329PA__)
+# define _EEPROM_SUFFIX _m329pa
+#elif defined (__AVR_ATmega3290__)
+# define _EEPROM_SUFFIX _m3290
+#elif defined (__AVR_ATmega3290P__)
+# define _EEPROM_SUFFIX _m3290p
+#elif defined (__AVR_ATmega32HVB__)
+# define _EEPROM_SUFFIX _m32hvb
+#elif defined (__AVR_ATmega64HVE__)
+# define _EEPROM_SUFFIX _m64hve
+#elif defined (__AVR_ATmega406__)
+# define _EEPROM_SUFFIX _m406
+#elif defined (__AVR_ATmega16__)
+# define _EEPROM_SUFFIX _m16
+#elif defined (__AVR_ATmega16A__)
+# define _EEPROM_SUFFIX _m16a
+#elif defined (__AVR_ATmega161__)
+# define _EEPROM_SUFFIX _m161
+#elif defined (__AVR_ATmega162__)
+# define _EEPROM_SUFFIX _m162
+#elif defined (__AVR_ATmega163__)
+# define _EEPROM_SUFFIX _m163
+#elif defined (__AVR_ATmega164__)
+# define _EEPROM_SUFFIX _m164
+#elif defined (__AVR_ATmega164P__)
+# define _EEPROM_SUFFIX _m164p
+#elif defined (__AVR_ATmega165__)
+# define _EEPROM_SUFFIX _m165
+#elif defined (__AVR_ATmega165A__)
+# define _EEPROM_SUFFIX _m165a
+#elif defined (__AVR_ATmega165P__)
+# define _EEPROM_SUFFIX _m165p
+#elif defined (__AVR_ATmega168__)
+# define _EEPROM_SUFFIX _m168
+#elif defined (__AVR_ATmega168A__)
+# define _EEPROM_SUFFIX _m168a
+#elif defined (__AVR_ATmega168P__)
+# define _EEPROM_SUFFIX _m168p
+#elif defined (__AVR_ATmega169__)
+# define _EEPROM_SUFFIX _m169
+#elif defined (__AVR_ATmega169A__)
+# define _EEPROM_SUFFIX _m169a
+#elif defined (__AVR_ATmega169P__)
+# define _EEPROM_SUFFIX _m169p
+#elif defined (__AVR_ATmega169PA__)
+# define _EEPROM_SUFFIX _m169pa
+#elif defined (__AVR_ATmega8HVA__)
+# define _EEPROM_SUFFIX _m8hva
+#elif defined (__AVR_ATmega16HVA__)
+# define _EEPROM_SUFFIX _m16hva
+#elif defined (__AVR_ATmega16HVA2__)
+# define _EEPROM_SUFFIX _m16hva2
+#elif defined (__AVR_ATmega16HVB__)
+# define _EEPROM_SUFFIX _m16hvb
+#elif defined (__AVR_ATmega8__)
+# define _EEPROM_SUFFIX _m8
+#elif defined (__AVR_ATmega48__)
+# define _EEPROM_SUFFIX _m48
+#elif defined (__AVR_ATmega48A__)
+# define _EEPROM_SUFFIX _m48a
+#elif defined (__AVR_ATmega48P__)
+# define _EEPROM_SUFFIX _m48p
+#elif defined (__AVR_ATmega88__)
+# define _EEPROM_SUFFIX _m88
+#elif defined (__AVR_ATmega88A__)
+# define _EEPROM_SUFFIX _m88a
+#elif defined (__AVR_ATmega88P__)
+# define _EEPROM_SUFFIX _m88p
+#elif defined (__AVR_ATmega88PA__)
+# define _EEPROM_SUFFIX _m88pa
+#elif defined (__AVR_ATmega8515__)
+# define _EEPROM_SUFFIX _m8515
+#elif defined (__AVR_ATmega8535__)
+# define _EEPROM_SUFFIX _m8535
+#elif defined (__AVR_AT90S8535__)
+# define _EEPROM_SUFFIX _8535
+#elif defined (__AVR_AT90C8534__)
+# define _EEPROM_SUFFIX _8534
+#elif defined (__AVR_AT90S8515__)
+# define _EEPROM_SUFFIX _8515
+#elif defined (__AVR_AT90S4434__)
+# define _EEPROM_SUFFIX _4434
+#elif defined (__AVR_AT90S4433__)
+# define _EEPROM_SUFFIX _4433
+#elif defined (__AVR_AT90S4414__)
+# define _EEPROM_SUFFIX _4414
+#elif defined (__AVR_ATtiny22__)
+# define _EEPROM_SUFFIX _tn22
+#elif defined (__AVR_ATtiny26__)
+# define _EEPROM_SUFFIX _tn26
+#elif defined (__AVR_AT90S2343__)
+# define _EEPROM_SUFFIX _2343
+#elif defined (__AVR_AT90S2333__)
+# define _EEPROM_SUFFIX _2333
+#elif defined (__AVR_AT90S2323__)
+# define _EEPROM_SUFFIX _2323
+#elif defined (__AVR_AT90S2313__)
+# define _EEPROM_SUFFIX _2313
+#elif defined (__AVR_ATtiny2313__)
+# define _EEPROM_SUFFIX _tn2313
+#elif defined (__AVR_ATtiny2313A__)
+# define _EEPROM_SUFFIX _tn2313a
+#elif defined (__AVR_ATtiny4313__)
+# define _EEPROM_SUFFIX _tn4313
+#elif defined (__AVR_ATtiny13__)
+# define _EEPROM_SUFFIX _tn13
+#elif defined (__AVR_ATtiny13A__)
+# define _EEPROM_SUFFIX _tn13a
+#elif defined (__AVR_ATtiny25__)
+# define _EEPROM_SUFFIX _tn25
+#elif defined (__AVR_ATtiny45__)
+# define _EEPROM_SUFFIX _tn45
+#elif defined (__AVR_ATtiny85__)
+# define _EEPROM_SUFFIX _tn85
+#elif defined (__AVR_ATtiny24__)
+# define _EEPROM_SUFFIX _tn24
+#elif defined (__AVR_ATtiny24A__)
+# define _EEPROM_SUFFIX _tn24a
+#elif defined (__AVR_ATtiny44__)
+# define _EEPROM_SUFFIX _tn44
+#elif defined (__AVR_ATtiny44A__)
+# define _EEPROM_SUFFIX _tn44a
+#elif defined (__AVR_ATtiny84__)
+# define _EEPROM_SUFFIX _tn84
+#elif defined (__AVR_ATtiny261__)
+# define _EEPROM_SUFFIX _tn261
+#elif defined (__AVR_ATtiny261A__)
+# define _EEPROM_SUFFIX _tn261a
+#elif defined (__AVR_ATtiny461__)
+# define _EEPROM_SUFFIX _tn461
+#elif defined (__AVR_ATtiny461A__)
+# define _EEPROM_SUFFIX _tn461a
+#elif defined (__AVR_ATtiny861__)
+# define _EEPROM_SUFFIX _tn861
+#elif defined (__AVR_ATtiny861A__)
+# define _EEPROM_SUFFIX _tn861a
+#elif defined (__AVR_ATtiny43U__)
+# define _EEPROM_SUFFIX _tn43u
+#elif defined (__AVR_ATtiny48__)
+# define _EEPROM_SUFFIX _tn48
+#elif defined (__AVR_ATtiny88__)
+# define _EEPROM_SUFFIX _tn88
+#elif defined (__AVR_ATtiny87__)
+# define _EEPROM_SUFFIX _tn87
+#elif defined (__AVR_ATtiny167__)
+# define _EEPROM_SUFFIX _tn167
+#elif defined (__AVR_AT90SCR100__)
+# define _EEPROM_SUFFIX _90scr100
+#elif defined (__AVR_ATxmega16A4__)
+# define _EEPROM_SUFFIX _x16a4
+#elif defined (__AVR_ATxmega16D4__)
+# define _EEPROM_SUFFIX _x16d4
+#elif defined (__AVR_ATxmega32A4__)
+# define _EEPROM_SUFFIX _x32a4
+#elif defined (__AVR_ATxmega32D4__)
+# define _EEPROM_SUFFIX _x32d4
+#elif defined (__AVR_ATxmega64A1__)
+# define _EEPROM_SUFFIX _x64a1
+#elif defined (__AVR_ATxmega64A3__)
+# define _EEPROM_SUFFIX _x64a3
+#elif defined (__AVR_ATxmega64D3__)
+# define _EEPROM_SUFFIX _x64d3
+#elif defined (__AVR_ATxmega128A1__)
+# define _EEPROM_SUFFIX _x128a1
+#elif defined (__AVR_ATxmega128A3__)
+# define _EEPROM_SUFFIX _x128a3
+#elif defined (__AVR_ATxmega128D3__)
+# define _EEPROM_SUFFIX _x128d3
+#elif defined (__AVR_ATxmega192A3__)
+# define _EEPROM_SUFFIX _x192a3
+#elif defined (__AVR_ATxmega192D3__)
+# define _EEPROM_SUFFIX _x192d3
+#elif defined (__AVR_ATxmega256A3__)
+# define _EEPROM_SUFFIX _x256a3
+#elif defined (__AVR_ATxmega256A3B__)
+# define _EEPROM_SUFFIX _x256a3b
+#elif defined (__AVR_ATxmega256D3__)
+# define _EEPROM_SUFFIX _x256d3
+#elif defined (__AVR_ATA6289__)
+# define _EEPROM_SUFFIX _a6289
+/* avr1: the following only supported for assembler programs */
+#elif defined (__AVR_ATtiny28__)
+# define _EEPROM_SUFFIX _tn28
+#elif defined (__AVR_AT90S1200__)
+# define _EEPROM_SUFFIX _1200
+#elif defined (__AVR_ATtiny15__)
+# define _EEPROM_SUFFIX _tn15
+#elif defined (__AVR_ATtiny12__)
+# define _EEPROM_SUFFIX _tn12
+#elif defined (__AVR_ATtiny11__)
+# define _EEPROM_SUFFIX _tn11
+#else
+# define _EEPROM_SUFFIX _UNKNOWN
+#endif
+
+#define _EEPROM_CONCAT1(s1, s2) s1 ## s2
+#define _EEPROM_CONCAT2(s1, s2) _EEPROM_CONCAT1 (s1, s2)
+
+#define eeprom_read_byte _EEPROM_CONCAT2 (__eerd_byte, _EEPROM_SUFFIX)
+#define eeprom_read_word _EEPROM_CONCAT2 (__eerd_word, _EEPROM_SUFFIX)
+#define eeprom_read_dword _EEPROM_CONCAT2 (__eerd_dword, _EEPROM_SUFFIX)
+#define eeprom_read_float _EEPROM_CONCAT2 (__eerd_float, _EEPROM_SUFFIX)
+#define eeprom_read_block _EEPROM_CONCAT2 (__eerd_block, _EEPROM_SUFFIX)
+
+#define eeprom_write_byte _EEPROM_CONCAT2 (__eewr_byte, _EEPROM_SUFFIX)
+#define eeprom_write_word _EEPROM_CONCAT2 (__eewr_word, _EEPROM_SUFFIX)
+#define eeprom_write_dword _EEPROM_CONCAT2 (__eewr_dword, _EEPROM_SUFFIX)
+#define eeprom_write_float _EEPROM_CONCAT2 (__eewr_float, _EEPROM_SUFFIX)
+#define eeprom_write_block _EEPROM_CONCAT2 (__eewr_block, _EEPROM_SUFFIX)
+
+#define eeprom_update_byte _EEPROM_CONCAT2 (__eeupd_byte, _EEPROM_SUFFIX)
+#define eeprom_update_word _EEPROM_CONCAT2 (__eeupd_word, _EEPROM_SUFFIX)
+#define eeprom_update_dword _EEPROM_CONCAT2 (__eeupd_dword, _EEPROM_SUFFIX)
+#define eeprom_update_float _EEPROM_CONCAT2 (__eeupd_float, _EEPROM_SUFFIX)
+#define eeprom_update_block _EEPROM_CONCAT2 (__eeupd_block, _EEPROM_SUFFIX)
+
+#endif /* !__DOXYGEN__ */
+
+#ifndef __ASSEMBLER__
+
+#include <stddef.h> /* size_t */
+#include <stdint.h>
+
+/** \defgroup avr_eeprom <avr/eeprom.h>: EEPROM handling
+ \code #include <avr/eeprom.h> \endcode
+
+ This header file declares the interface to some simple library
+ routines suitable for handling the data EEPROM contained in the
+ AVR microcontrollers. The implementation uses a simple polled
+ mode interface. Applications that require interrupt-controlled
+ EEPROM access to ensure that no time will be wasted in spinloops
+ will have to deploy their own implementation.
+
+ \par Notes:
+
+ - In addition to the write functions there is a set of update ones.
+ This functions read each byte first and skip the burning if the
+ old value is the same with new. The scaning direction is from
+ high address to low, to obtain quick return in common cases.
+
+ - All of the read/write functions first make sure the EEPROM is
+ ready to be accessed. Since this may cause long delays if a
+ write operation is still pending, time-critical applications
+ should first poll the EEPROM e. g. using eeprom_is_ready() before
+ attempting any actual I/O. But this functions are not wait until
+ SELFPRGEN in SPMCSR becomes zero. Do this manually, if your
+ softwate contains the Flash burning.
+
+ - As these functions modify IO registers, they are known to be
+ non-reentrant. If any of these functions are used from both,
+ standard and interrupt context, the applications must ensure
+ proper protection (e.g. by disabling interrupts before accessing
+ them).
+
+ - All write functions force erase_and_write programming mode.
+
+ - For Xmega the EEPROM start address is 0, like other architectures.
+ The reading functions add the 0x2000 value to use EEPROM mapping into
+ data space.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __ATTR_PURE__
+# ifdef __DOXYGEN__
+# define __ATTR_PURE__
+# else
+# define __ATTR_PURE__ __attribute__((__pure__))
+# endif
+#endif
+
+/** \def EEMEM
+ \ingroup avr_eeprom
+ Attribute expression causing a variable to be allocated within the
+ .eeprom section. */
+#define EEMEM __attribute__((section(".eeprom")))
+
+/** \def eeprom_is_ready
+ \ingroup avr_eeprom
+ \returns 1 if EEPROM is ready for a new read/write operation, 0 if not.
+ */
+#if defined (__DOXYGEN__)
+# define eeprom_is_ready()
+#elif defined (__AVR_XMEGA__) && __AVR_XMEGA__
+# define eeprom_is_ready() bit_is_clear (NVM_STATUS, NVM_NVMBUSY_bp)
+#elif defined (DEECR)
+# define eeprom_is_ready() bit_is_clear (DEECR, BSY)
+#elif defined (EEPE)
+# define eeprom_is_ready() bit_is_clear (EECR, EEPE)
+#else
+# define eeprom_is_ready() bit_is_clear (EECR, EEWE)
+#endif
+
+
+/** \def eeprom_busy_wait
+ \ingroup avr_eeprom
+ Loops until the eeprom is no longer busy.
+ \returns Nothing.
+ */
+#define eeprom_busy_wait() do {} while (!eeprom_is_ready())
+
+
+/** \ingroup avr_eeprom
+ Read one byte from EEPROM address \a __p.
+ */
+uint8_t eeprom_read_byte (const uint8_t *__p) __ATTR_PURE__;
+
+/** \ingroup avr_eeprom
+ Read one 16-bit word (little endian) from EEPROM address \a __p.
+ */
+uint16_t eeprom_read_word (const uint16_t *__p) __ATTR_PURE__;
+
+/** \ingroup avr_eeprom
+ Read one 32-bit double word (little endian) from EEPROM address \a __p.
+ */
+uint32_t eeprom_read_dword (const uint32_t *__p) __ATTR_PURE__;
+
+/** \ingroup avr_eeprom
+ Read one float value (little endian) from EEPROM address \a __p.
+ */
+float eeprom_read_float (const float *__p) __ATTR_PURE__;
+
+/** \ingroup avr_eeprom
+ Read a block of \a __n bytes from EEPROM address \a __src to SRAM
+ \a __dst.
+ */
+void eeprom_read_block (void *__dst, const void *__src, size_t __n);
+
+
+/** \ingroup avr_eeprom
+ Write a byte \a __value to EEPROM address \a __p.
+ */
+void eeprom_write_byte (uint8_t *__p, uint8_t __value);
+
+/** \ingroup avr_eeprom
+ Write a word \a __value to EEPROM address \a __p.
+ */
+void eeprom_write_word (uint16_t *__p, uint16_t __value);
+
+/** \ingroup avr_eeprom
+ Write a 32-bit double word \a __value to EEPROM address \a __p.
+ */
+void eeprom_write_dword (uint32_t *__p, uint32_t __value);
+
+/** \ingroup avr_eeprom
+ Write a float \a __value to EEPROM address \a __p.
+ */
+void eeprom_write_float (float *__p, float __value);
+
+/** \ingroup avr_eeprom
+ Write a block of \a __n bytes to EEPROM address \a __dst from \a __src.
+ \note The argument order is mismatch with common functions like strcpy().
+ */
+void eeprom_write_block (const void *__src, void *__dst, size_t __n);
+
+
+/** \ingroup avr_eeprom
+ Update a byte \a __value to EEPROM address \a __p.
+ */
+void eeprom_update_byte (uint8_t *__p, uint8_t __value);
+
+/** \ingroup avr_eeprom
+ Update a word \a __value to EEPROM address \a __p.
+ */
+void eeprom_update_word (uint16_t *__p, uint16_t __value);
+
+/** \ingroup avr_eeprom
+ Update a 32-bit double word \a __value to EEPROM address \a __p.
+ */
+void eeprom_update_dword (uint32_t *__p, uint32_t __value);
+
+/** \ingroup avr_eeprom
+ Update a float \a __value to EEPROM address \a __p.
+ */
+void eeprom_update_float (float *__p, float __value);
+
+/** \ingroup avr_eeprom
+ Update a block of \a __n bytes to EEPROM address \a __dst from \a __src.
+ \note The argument order is mismatch with common functions like strcpy().
+ */
+void eeprom_update_block (const void *__src, void *__dst, size_t __n);
+
+
+/** \name IAR C compatibility defines */
+/*@{*/
+
+/** \def _EEPUT
+ \ingroup avr_eeprom
+ Write a byte to EEPROM. Compatibility define for IAR C. */
+#define _EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
+
+/** \def __EEPUT
+ \ingroup avr_eeprom
+ Write a byte to EEPROM. Compatibility define for IAR C. */
+#define __EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
+
+/** \def _EEGET
+ \ingroup avr_eeprom
+ Read a byte from EEPROM. Compatibility define for IAR C. */
+#define _EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr))
+
+/** \def __EEGET
+ \ingroup avr_eeprom
+ Read a byte from EEPROM. Compatibility define for IAR C. */
+#define __EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr))
+
+/*@}*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__ASSEMBLER__ */
+#endif /* E2END || defined(__DOXYGEN__) || defined(__COMPILING_AVR_LIBC__) */
+#endif /* !_AVR_EEPROM_H_ */
diff --git a/cpukit/score/cpu/avr/avr/fuse.h b/cpukit/score/cpu/avr/avr/fuse.h
new file mode 100644
index 0000000000..7aa4f92a18
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/fuse.h
@@ -0,0 +1,269 @@
+/* Copyright (c) 2007, Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/fuse.h - Fuse API */
+
+#ifndef _AVR_FUSE_H_
+#define _AVR_FUSE_H_ 1
+
+/* This file must be explicitly included by <avr/io.h>. */
+#if !defined(_AVR_IO_H_)
+#error "You must #include <avr/io.h> and not <avr/fuse.h> by itself."
+#endif
+
+
+/** \file */
+/** \defgroup avr_fuse <avr/fuse.h>: Fuse Support
+
+ \par Introduction
+
+ The Fuse API allows a user to specify the fuse settings for the specific
+ AVR device they are compiling for. These fuse settings will be placed
+ in a special section in the ELF output file, after linking.
+
+ Programming tools can take advantage of the fuse information embedded in
+ the ELF file, by extracting this information and determining if the fuses
+ need to be programmed before programming the Flash and EEPROM memories.
+ This also allows a single ELF file to contain all the
+ information needed to program an AVR.
+
+ To use the Fuse API, include the <avr/io.h> header file, which in turn
+ automatically includes the individual I/O header file and the <avr/fuse.h>
+ file. These other two files provides everything necessary to set the AVR
+ fuses.
+
+ \par Fuse API
+
+ Each I/O header file must define the FUSE_MEMORY_SIZE macro which is
+ defined to the number of fuse bytes that exist in the AVR device.
+
+ A new type, __fuse_t, is defined as a structure. The number of fields in
+ this structure are determined by the number of fuse bytes in the
+ FUSE_MEMORY_SIZE macro.
+
+ If FUSE_MEMORY_SIZE == 1, there is only a single field: byte, of type
+ unsigned char.
+
+ If FUSE_MEMORY_SIZE == 2, there are two fields: low, and high, of type
+ unsigned char.
+
+ If FUSE_MEMORY_SIZE == 3, there are three fields: low, high, and extended,
+ of type unsigned char.
+
+ If FUSE_MEMORY_SIZE > 3, there is a single field: byte, which is an array
+ of unsigned char with the size of the array being FUSE_MEMORY_SIZE.
+
+ A convenience macro, FUSEMEM, is defined as a GCC attribute for a
+ custom-named section of ".fuse".
+
+ A convenience macro, FUSES, is defined that declares a variable, __fuse, of
+ type __fuse_t with the attribute defined by FUSEMEM. This variable
+ allows the end user to easily set the fuse data.
+
+ \note If a device-specific I/O header file has previously defined FUSEMEM,
+ then FUSEMEM is not redefined. If a device-specific I/O header file has
+ previously defined FUSES, then FUSES is not redefined.
+
+ Each AVR device I/O header file has a set of defined macros which specify the
+ actual fuse bits available on that device. The AVR fuses have inverted
+ values, logical 1 for an unprogrammed (disabled) bit and logical 0 for a
+ programmed (enabled) bit. The defined macros for each individual fuse
+ bit represent this in their definition by a bit-wise inversion of a mask.
+ For example, the FUSE_EESAVE fuse in the ATmega128 is defined as:
+ \code
+ #define FUSE_EESAVE ~_BV(3)
+ \endcode
+ \note The _BV macro creates a bit mask from a bit number. It is then
+ inverted to represent logical values for a fuse memory byte.
+
+ To combine the fuse bits macros together to represent a whole fuse byte,
+ use the bitwise AND operator, like so:
+ \code
+ (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN)
+ \endcode
+
+ Each device I/O header file also defines macros that provide default values
+ for each fuse byte that is available. LFUSE_DEFAULT is defined for a Low
+ Fuse byte. HFUSE_DEFAULT is defined for a High Fuse byte. EFUSE_DEFAULT
+ is defined for an Extended Fuse byte.
+
+ If FUSE_MEMORY_SIZE > 3, then the I/O header file defines macros that
+ provide default values for each fuse byte like so:
+ FUSE0_DEFAULT
+ FUSE1_DEFAULT
+ FUSE2_DEFAULT
+ FUSE3_DEFAULT
+ FUSE4_DEFAULT
+ ....
+
+ \par API Usage Example
+
+ Putting all of this together is easy. Using C99's designated initializers:
+
+ \code
+ #include <avr/io.h>
+
+ FUSES =
+ {
+ .low = LFUSE_DEFAULT,
+ .high = (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
+ .extended = EFUSE_DEFAULT,
+ };
+
+ int main(void)
+ {
+ return 0;
+ }
+ \endcode
+
+ Or, using the variable directly instead of the FUSES macro,
+
+ \code
+ #include <avr/io.h>
+
+ __fuse_t __fuse __attribute__((section (".fuse"))) =
+ {
+ .low = LFUSE_DEFAULT,
+ .high = (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
+ .extended = EFUSE_DEFAULT,
+ };
+
+ int main(void)
+ {
+ return 0;
+ }
+ \endcode
+
+ If you are compiling in C++, you cannot use the designated intializers so
+ you must do:
+
+ \code
+ #include <avr/io.h>
+
+ FUSES =
+ {
+ LFUSE_DEFAULT, // .low
+ (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN), // .high
+ EFUSE_DEFAULT, // .extended
+ };
+
+ int main(void)
+ {
+ return 0;
+ }
+ \endcode
+
+
+ However there are a number of caveats that you need to be aware of to
+ use this API properly.
+
+ Be sure to include <avr/io.h> to get all of the definitions for the API.
+ The FUSES macro defines a global variable to store the fuse data. This
+ variable is assigned to its own linker section. Assign the desired fuse
+ values immediately in the variable initialization.
+
+ The .fuse section in the ELF file will get its values from the initial
+ variable assignment ONLY. This means that you can NOT assign values to
+ this variable in functions and the new values will not be put into the
+ ELF .fuse section.
+
+ The global variable is declared in the FUSES macro has two leading
+ underscores, which means that it is reserved for the "implementation",
+ meaning the library, so it will not conflict with a user-named variable.
+
+ You must initialize ALL fields in the __fuse_t structure. This is because
+ the fuse bits in all bytes default to a logical 1, meaning unprogrammed.
+ Normal uninitialized data defaults to all locgial zeros. So it is vital that
+ all fuse bytes are initialized, even with default data. If they are not,
+ then the fuse bits may not programmed to the desired settings.
+
+ Be sure to have the -mmcu=<em>device</em> flag in your compile command line and
+ your linker command line to have the correct device selected and to have
+ the correct I/O header file included when you include <avr/io.h>.
+
+ You can print out the contents of the .fuse section in the ELF file by
+ using this command line:
+ \code
+ avr-objdump -s -j .fuse <ELF file>
+ \endcode
+ The section contents shows the address on the left, then the data going from
+ lower address to a higher address, left to right.
+
+*/
+
+#ifndef __ASSEMBLER__
+
+#ifndef FUSEMEM
+#define FUSEMEM __attribute__((section (".fuse")))
+#endif
+
+#if FUSE_MEMORY_SIZE > 3
+
+typedef struct
+{
+ unsigned char byte[FUSE_MEMORY_SIZE];
+} __fuse_t;
+
+
+#elif FUSE_MEMORY_SIZE == 3
+
+typedef struct
+{
+ unsigned char low;
+ unsigned char high;
+ unsigned char extended;
+} __fuse_t;
+
+#elif FUSE_MEMORY_SIZE == 2
+
+typedef struct
+{
+ unsigned char low;
+ unsigned char high;
+} __fuse_t;
+
+#elif FUSE_MEMORY_SIZE == 1
+
+typedef struct
+{
+ unsigned char byte;
+} __fuse_t;
+
+#endif
+
+#ifndef FUSES
+#define FUSES __fuse_t __fuse FUSEMEM
+#endif
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* _AVR_FUSE_H_ */
diff --git a/cpukit/score/cpu/avr/avr/interrupt.h b/cpukit/score/cpu/avr/avr/interrupt.h
new file mode 100644
index 0000000000..e4077c16bc
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/interrupt.h
@@ -0,0 +1,344 @@
+/* Copyright (c) 2002,2005,2007 Marek Michalkiewicz
+ Copyright (c) 2007, Dean Camera
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_INTERRUPT_H_
+#define _AVR_INTERRUPT_H_
+
+#include <avr/io.h>
+
+#if !defined(__DOXYGEN__) && !defined(__STRINGIFY)
+/* Auxiliary macro for ISR_ALIAS(). */
+#define __STRINGIFY(x) #x
+#endif /* !defined(__DOXYGEN__) */
+
+/**
+\file
+\@{
+*/
+
+
+/** \name Global manipulation of the interrupt flag
+
+ The global interrupt flag is maintained in the I bit of the status
+ register (SREG).
+*/
+
+#if defined(__DOXYGEN__)
+/** \def sei()
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Enables interrupts by setting the global interrupt mask. This function
+ actually compiles into a single line of assembly, so there is no function
+ call overhead. */
+#define sei()
+#else /* !DOXYGEN */
+# define sei() __asm__ __volatile__ ("sei" ::)
+#endif /* DOXYGEN */
+
+#if defined(__DOXYGEN__)
+/** \def cli()
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Disables all interrupts by clearing the global interrupt mask. This function
+ actually compiles into a single line of assembly, so there is no function
+ call overhead. */
+#define cli()
+#else /* !DOXYGEN */
+# define cli() __asm__ __volatile__ ("cli" ::)
+#endif /* DOXYGEN */
+
+
+/** \name Macros for writing interrupt handler functions */
+
+
+#if defined(__DOXYGEN__)
+/** \def ISR(vector [, attributes])
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Introduces an interrupt handler function (interrupt service
+ routine) that runs with global interrupts initially disabled
+ by default with no attributes specified.
+
+ The attributes are optional and alter the behaviour and resultant
+ generated code of the interrupt routine. Multiple attributes may
+ be used for a single function, with a space seperating each
+ attribute.
+
+ Valid attributes are ISR_BLOCK, ISR_NOBLOCK, ISR_NAKED and
+ ISR_ALIASOF(vect).
+
+ \c vector must be one of the interrupt vector names that are
+ valid for the particular MCU type.
+*/
+# define ISR(vector, [attributes])
+#else /* real code */
+
+#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
+# define __INTR_ATTRS used, externally_visible
+#else /* GCC < 4.1 */
+# define __INTR_ATTRS used
+#endif
+
+#ifdef __cplusplus
+# define ISR(vector, ...) \
+ extern "C" void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
+ void vector (void)
+#else
+# define ISR(vector, ...) \
+ void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
+ void vector (void)
+#endif
+
+#endif /* DOXYGEN */
+
+#if defined(__DOXYGEN__)
+/** \def SIGNAL(vector)
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Introduces an interrupt handler function that runs with global interrupts
+ initially disabled.
+
+ This is the same as the ISR macro without optional attributes.
+ \deprecated Do not use SIGNAL() in new code. Use ISR() instead.
+*/
+# define SIGNAL(vector)
+#else /* real code */
+
+#ifdef __cplusplus
+# define SIGNAL(vector) \
+ extern "C" void vector(void) __attribute__ ((signal, __INTR_ATTRS)); \
+ void vector (void)
+#else
+# define SIGNAL(vector) \
+ void vector (void) __attribute__ ((signal, __INTR_ATTRS)); \
+ void vector (void)
+#endif
+
+#endif /* DOXYGEN */
+
+#if defined(__DOXYGEN__)
+/** \def EMPTY_INTERRUPT(vector)
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Defines an empty interrupt handler function. This will not generate
+ any prolog or epilog code and will only return from the ISR. Do not
+ define a function body as this will define it for you.
+ Example:
+ \code EMPTY_INTERRUPT(ADC_vect);\endcode */
+# define EMPTY_INTERRUPT(vector)
+#else /* real code */
+
+#ifdef __cplusplus
+# define EMPTY_INTERRUPT(vector) \
+ extern "C" void vector(void) __attribute__ ((signal,naked,__INTR_ATTRS)); \
+ void vector (void) { __asm__ __volatile__ ("reti" ::); }
+#else
+# define EMPTY_INTERRUPT(vector) \
+ void vector (void) __attribute__ ((signal,naked,__INTR_ATTRS)); \
+ void vector (void) { __asm__ __volatile__ ("reti" ::); }
+#endif
+
+#endif /* DOXYGEN */
+
+#if defined(__DOXYGEN__)
+/** \def ISR_ALIAS(vector, target_vector)
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Aliases a given vector to another one in the same manner as the
+ ISR_ALIASOF attribute for the ISR() macro. Unlike the ISR_ALIASOF
+ attribute macro however, this is compatible for all versions of
+ GCC rather than just GCC version 4.2 onwards.
+
+ \note This macro creates a trampoline function for the aliased
+ macro. This will result in a two cycle penalty for the aliased
+ vector compared to the ISR the vector is aliased to, due to the
+ JMP/RJMP opcode used.
+
+ \deprecated
+ For new code, the use of ISR(..., ISR_ALIASOF(...)) is
+ recommended.
+
+ Example:
+ \code
+ ISR(INT0_vect)
+ {
+ PORTB = 42;
+ }
+
+ ISR_ALIAS(INT1_vect, INT0_vect);
+ \endcode
+*/
+# define ISR_ALIAS(vector, target_vector)
+#else /* real code */
+
+#ifdef __cplusplus
+# if defined(__AVR_MEGA__) && __AVR_MEGA__
+# define ISR_ALIAS(vector, tgt) extern "C" void vector (void) \
+ __attribute__((signal, naked, __INTR_ATTRS)); \
+ void vector (void) { __asm__ volatile ("jmp " __STRINGIFY(tgt) ::); }
+# else /* !__AVR_MEGA */
+# define ISR_ALIAS(vector, tgt) extern "C" void vector (void) \
+ __attribute__((signal, naked, __INTR_ATTRS)); \
+ void vector (void) { __asm__ volatile ("rjmp " __STRINGIFY(tgt) ::); }
+# endif /* __AVR_MEGA__ */
+#else /* !__cplusplus */
+# if defined(__AVR_MEGA__) && __AVR_MEGA__
+# define ISR_ALIAS(vector, tgt) void vector (void) \
+ __attribute__((signal, naked, __INTR_ATTRS)); \
+ void vector (void) { __asm__ volatile ("jmp " __STRINGIFY(tgt) ::); }
+# else /* !__AVR_MEGA */
+# define ISR_ALIAS(vector, tgt) void vector (void) \
+ __attribute__((signal, naked, __INTR_ATTRS)); \
+ void vector (void) { __asm__ volatile ("rjmp " __STRINGIFY(tgt) ::); }
+# endif /* __AVR_MEGA__ */
+#endif /* __cplusplus */
+
+#endif /* DOXYGEN */
+
+#if defined(__DOXYGEN__)
+/** \def reti()
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ Returns from an interrupt routine, enabling global interrupts. This should
+ be the last command executed before leaving an ISR defined with the ISR_NAKED
+ attribute.
+
+ This macro actually compiles into a single line of assembly, so there is
+ no function call overhead.
+*/
+# define reti()
+#else /* !DOXYGEN */
+# define reti() __asm__ __volatile__ ("reti" ::)
+#endif /* DOXYGEN */
+
+#if defined(__DOXYGEN__)
+/** \def BADISR_vect
+ \ingroup avr_interrupts
+
+ \code #include <avr/interrupt.h> \endcode
+
+ This is a vector which is aliased to __vector_default, the vector
+ executed when an ISR fires with no accompanying ISR handler. This
+ may be used along with the ISR() macro to create a catch-all for
+ undefined but used ISRs for debugging purposes.
+*/
+# define BADISR_vect
+#else /* !DOXYGEN */
+# define BADISR_vect __vector_default
+#endif /* DOXYGEN */
+
+/** \name ISR attributes */
+
+#if defined(__DOXYGEN__)
+/** \def ISR_BLOCK
+ \ingroup avr_interrupts
+
+ \code# include <avr/interrupt.h> \endcode
+
+ Identical to an ISR with no attributes specified. Global
+ interrupts are initially disabled by the AVR hardware when
+ entering the ISR, without the compiler modifying this state.
+
+ Use this attribute in the attributes parameter of the ISR macro.
+*/
+# define ISR_BLOCK
+
+/** \def ISR_NOBLOCK
+ \ingroup avr_interrupts
+
+ \code# include <avr/interrupt.h> \endcode
+
+ ISR runs with global interrupts initially enabled. The interrupt
+ enable flag is activated by the compiler as early as possible
+ within the ISR to ensure minimal processing delay for nested
+ interrupts.
+
+ This may be used to create nested ISRs, however care should be
+ taken to avoid stack overflows, or to avoid infinitely entering
+ the ISR for those cases where the AVR hardware does not clear the
+ respective interrupt flag before entering the ISR.
+
+ Use this attribute in the attributes parameter of the ISR macro.
+*/
+# define ISR_NOBLOCK
+
+/** \def ISR_NAKED
+ \ingroup avr_interrupts
+
+ \code# include <avr/interrupt.h> \endcode
+
+ ISR is created with no prologue or epilogue code. The user code is
+ responsible for preservation of the machine state including the
+ SREG register, as well as placing a reti() at the end of the
+ interrupt routine.
+
+ Use this attribute in the attributes parameter of the ISR macro.
+*/
+# define ISR_NAKED
+
+/** \def ISR_ALIASOF(target_vector)
+ \ingroup avr_interrupts
+
+ \code#include <avr/interrupt.h>\endcode
+
+ The ISR is linked to another ISR, specified by the vect parameter.
+ This is compatible with GCC 4.2 and greater only.
+
+ Use this attribute in the attributes parameter of the ISR macro.
+*/
+# define ISR_ALIASOF(target_vector)
+#else /* !DOXYGEN */
+# define ISR_BLOCK
+# define ISR_NOBLOCK __attribute__((interrupt))
+# define ISR_NAKED __attribute__((naked))
+# define ISR_ALIASOF(v) __attribute__((alias(__STRINGIFY(v))))
+#endif /* DOXYGEN */
+
+/* \@} */
+
+#endif
diff --git a/cpukit/score/cpu/avr/avr/io.h b/cpukit/score/cpu/avr/avr/io.h
new file mode 100644
index 0000000000..98e7a18b6b
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io.h
@@ -0,0 +1,420 @@
+/* Copyright (c) 2002,2003,2005,2006,2007 Marek Michalkiewicz, Joerg Wunsch
+ Copyright (c) 2007 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/** \file */
+/** \defgroup avr_io <avr/io.h>: AVR device-specific IO definitions
+ \code #include <avr/io.h> \endcode
+
+ This header file includes the apropriate IO definitions for the
+ device that has been specified by the <tt>-mmcu=</tt> compiler
+ command-line switch. This is done by diverting to the appropriate
+ file <tt>&lt;avr/io</tt><em>XXXX</em><tt>.h&gt;</tt> which should
+ never be included directly. Some register names common to all
+ AVR devices are defined directly within <tt>&lt;avr/common.h&gt;</tt>,
+ which is included in <tt>&lt;avr/io.h&gt;</tt>,
+ but most of the details come from the respective include file.
+
+ Note that this file always includes the following files:
+ \code
+ #include <avr/sfr_defs.h>
+ #include <avr/portpins.h>
+ #include <avr/common.h>
+ #include <avr/version.h>
+ \endcode
+ See \ref avr_sfr for more details about that header file.
+
+ Included are definitions of the IO register set and their
+ respective bit values as specified in the Atmel documentation.
+ Note that inconsistencies in naming conventions,
+ so even identical functions sometimes get different names on
+ different devices.
+
+ Also included are the specific names useable for interrupt
+ function definitions as documented
+ \ref avr_signames "here".
+
+ Finally, the following macros are defined:
+
+ - \b RAMEND
+ <br>
+ The last on-chip RAM address.
+ <br>
+ - \b XRAMEND
+ <br>
+ The last possible RAM location that is addressable. This is equal to
+ RAMEND for devices that do not allow for external RAM. For devices
+ that allow external RAM, this will be larger than RAMEND.
+ <br>
+ - \b E2END
+ <br>
+ The last EEPROM address.
+ <br>
+ - \b FLASHEND
+ <br>
+ The last byte address in the Flash program space.
+ <br>
+ - \b SPM_PAGESIZE
+ <br>
+ For devices with bootloader support, the flash pagesize
+ (in bytes) to be used for the \c SPM instruction.
+ - \b E2PAGESIZE
+ <br>
+ The size of the EEPROM page.
+
+*/
+
+#ifndef _AVR_IO_H_
+#define _AVR_IO_H_
+
+#include <avr/sfr_defs.h>
+
+#if defined (__AVR_AT94K__)
+# include <avr/ioat94k.h>
+#elif defined (__AVR_AT43USB320__)
+# include <avr/io43u32x.h>
+#elif defined (__AVR_AT43USB355__)
+# include <avr/io43u35x.h>
+#elif defined (__AVR_AT76C711__)
+# include <avr/io76c711.h>
+#elif defined (__AVR_AT86RF401__)
+# include <avr/io86r401.h>
+#elif defined (__AVR_AT90PWM1__)
+# include <avr/io90pwm1.h>
+#elif defined (__AVR_AT90PWM2__)
+# include <avr/io90pwmx.h>
+#elif defined (__AVR_AT90PWM2B__)
+# include <avr/io90pwm2b.h>
+#elif defined (__AVR_AT90PWM3__)
+# include <avr/io90pwmx.h>
+#elif defined (__AVR_AT90PWM3B__)
+# include <avr/io90pwm3b.h>
+#elif defined (__AVR_AT90PWM216__)
+# include <avr/io90pwm216.h>
+#elif defined (__AVR_AT90PWM316__)
+# include <avr/io90pwm316.h>
+#elif defined (__AVR_AT90PWM81__)
+# include <avr/io90pwm81.h>
+#elif defined (__AVR_ATmega8U2__)
+# include <avr/iom8u2.h>
+#elif defined (__AVR_ATmega16M1__)
+# include <avr/iom16m1.h>
+#elif defined (__AVR_ATmega16U2__)
+# include <avr/iom16u2.h>
+#elif defined (__AVR_ATmega16U4__)
+# include <avr/iom16u4.h>
+#elif defined (__AVR_ATmega32C1__)
+# include <avr/iom32c1.h>
+#elif defined (__AVR_ATmega32M1__)
+# include <avr/iom32m1.h>
+#elif defined (__AVR_ATmega32U2__)
+# include <avr/iom32u2.h>
+#elif defined (__AVR_ATmega32U4__)
+# include <avr/iom32u4.h>
+#elif defined (__AVR_ATmega32U6__)
+# include <avr/iom32u6.h>
+#elif defined (__AVR_ATmega64C1__)
+# include <avr/iom64c1.h>
+#elif defined (__AVR_ATmega64M1__)
+# include <avr/iom64m1.h>
+#elif defined (__AVR_ATmega128__)
+# include <avr/iom128.h>
+#elif defined (__AVR_ATmega1280__)
+# include <avr/iom1280.h>
+#elif defined (__AVR_ATmega1281__)
+# include <avr/iom1281.h>
+#elif defined (__AVR_ATmega1284P__)
+# include <avr/iom1284p.h>
+#elif defined (__AVR_ATmega128RFA1__)
+# include <avr/iom128rfa1.h>
+#elif defined (__AVR_ATmega2560__)
+# include <avr/iom2560.h>
+#elif defined (__AVR_ATmega2561__)
+# include <avr/iom2561.h>
+#elif defined (__AVR_AT90CAN32__)
+# include <avr/iocan32.h>
+#elif defined (__AVR_AT90CAN64__)
+# include <avr/iocan64.h>
+#elif defined (__AVR_AT90CAN128__)
+# include <avr/iocan128.h>
+#elif defined (__AVR_AT90USB82__)
+# include <avr/iousb82.h>
+#elif defined (__AVR_AT90USB162__)
+# include <avr/iousb162.h>
+#elif defined (__AVR_AT90USB646__)
+# include <avr/iousb646.h>
+#elif defined (__AVR_AT90USB647__)
+# include <avr/iousb647.h>
+#elif defined (__AVR_AT90USB1286__)
+# include <avr/iousb1286.h>
+#elif defined (__AVR_AT90USB1287__)
+# include <avr/iousb1287.h>
+#elif defined (__AVR_ATmega64__)
+# include <avr/iom64.h>
+#elif defined (__AVR_ATmega640__)
+# include <avr/iom640.h>
+#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__)
+# include <avr/iom644.h>
+#elif defined (__AVR_ATmega644P__)
+# include <avr/iom644p.h>
+#elif defined (__AVR_ATmega644PA__)
+# include <avr/iom644pa.h>
+#elif defined (__AVR_ATmega645__) || defined (__AVR_ATmega645A__) || defined (__AVR_ATmega645P__)
+# include <avr/iom645.h>
+#elif defined (__AVR_ATmega6450__) || defined (__AVR_ATmega6450A__) || defined (__AVR_ATmega6450P__)
+# include <avr/iom6450.h>
+#elif defined (__AVR_ATmega649__) || defined (__AVR_ATmega649A__)
+# include <avr/iom649.h>
+#elif defined (__AVR_ATmega6490__) || defined (__AVR_ATmega6490A__) || defined (__AVR_ATmega6490P__)
+# include <avr/iom6490.h>
+#elif defined (__AVR_ATmega649P__)
+# include <avr/iom649p.h>
+#elif defined (__AVR_ATmega64HVE__)
+# include <avr/iom64hve.h>
+#elif defined (__AVR_ATmega103__)
+# include <avr/iom103.h>
+#elif defined (__AVR_ATmega32__)
+# include <avr/iom32.h>
+#elif defined (__AVR_ATmega323__)
+# include <avr/iom323.h>
+#elif defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324A__)
+# include <avr/iom324.h>
+#elif defined (__AVR_ATmega324PA__)
+# include <avr/iom324pa.h>
+#elif defined (__AVR_ATmega325__)
+# include <avr/iom325.h>
+#elif defined (__AVR_ATmega325P__)
+# include <avr/iom325.h>
+#elif defined (__AVR_ATmega3250__)
+# include <avr/iom3250.h>
+#elif defined (__AVR_ATmega3250P__)
+# include <avr/iom3250.h>
+#elif defined (__AVR_ATmega328P__) || defined (__AVR_ATmega328__)
+# include <avr/iom328p.h>
+#elif defined (__AVR_ATmega329__)
+# include <avr/iom329.h>
+#elif defined (__AVR_ATmega329P__) || defined (__AVR_ATmega329PA__)
+# include <avr/iom329.h>
+#elif defined (__AVR_ATmega3290__)
+# include <avr/iom3290.h>
+#elif defined (__AVR_ATmega3290P__)
+# include <avr/iom3290.h>
+#elif defined (__AVR_ATmega32HVB__)
+# include <avr/iom32hvb.h>
+#elif defined (__AVR_ATmega406__)
+# include <avr/iom406.h>
+#elif defined (__AVR_ATmega16__)
+# include <avr/iom16.h>
+#elif defined (__AVR_ATmega16A__)
+# include <avr/iom16a.h>
+#elif defined (__AVR_ATmega161__)
+# include <avr/iom161.h>
+#elif defined (__AVR_ATmega162__)
+# include <avr/iom162.h>
+#elif defined (__AVR_ATmega163__)
+# include <avr/iom163.h>
+#elif defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164A__)
+# include <avr/iom164.h>
+#elif defined (__AVR_ATmega165__) || defined (__AVR_ATmega165A__)
+# include <avr/iom165.h>
+#elif defined (__AVR_ATmega165P__)
+# include <avr/iom165p.h>
+#elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168A__)
+# include <avr/iom168.h>
+#elif defined (__AVR_ATmega168P__)
+# include <avr/iom168p.h>
+#elif defined (__AVR_ATmega169__) || defined (__AVR_ATmega169A__)
+# include <avr/iom169.h>
+#elif defined (__AVR_ATmega169P__)
+# include <avr/iom169p.h>
+#elif defined (__AVR_ATmega169PA__)
+# include <avr/iom169pa.h>
+#elif defined (__AVR_ATmega8HVA__)
+# include <avr/iom8hva.h>
+#elif defined (__AVR_ATmega16HVA__)
+# include <avr/iom16hva.h>
+#elif defined (__AVR_ATmega16HVA2__)
+# include <avr/iom16hva2.h>
+#elif defined (__AVR_ATmega16HVB__)
+# include <avr/iom16hvb.h>
+#elif defined (__AVR_ATmega8__)
+# include <avr/iom8.h>
+#elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega48A__)
+# include <avr/iom48.h>
+#elif defined (__AVR_ATmega48P__)
+# include <avr/iom48p.h>
+#elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega88A__)
+# include <avr/iom88.h>
+#elif defined (__AVR_ATmega88P__)
+# include <avr/iom88p.h>
+#elif defined (__AVR_ATmega88PA__)
+# include <avr/iom88pa.h>
+#elif defined (__AVR_ATmega8515__)
+# include <avr/iom8515.h>
+#elif defined (__AVR_ATmega8535__)
+# include <avr/iom8535.h>
+#elif defined (__AVR_AT90S8535__)
+# include <avr/io8535.h>
+#elif defined (__AVR_AT90C8534__)
+# include <avr/io8534.h>
+#elif defined (__AVR_AT90S8515__)
+# include <avr/io8515.h>
+#elif defined (__AVR_AT90S4434__)
+# include <avr/io4434.h>
+#elif defined (__AVR_AT90S4433__)
+# include <avr/io4433.h>
+#elif defined (__AVR_AT90S4414__)
+# include <avr/io4414.h>
+#elif defined (__AVR_ATtiny22__)
+# include <avr/iotn22.h>
+#elif defined (__AVR_ATtiny26__)
+# include <avr/iotn26.h>
+#elif defined (__AVR_AT90S2343__)
+# include <avr/io2343.h>
+#elif defined (__AVR_AT90S2333__)
+# include <avr/io2333.h>
+#elif defined (__AVR_AT90S2323__)
+# include <avr/io2323.h>
+#elif defined (__AVR_AT90S2313__)
+# include <avr/io2313.h>
+#elif defined (__AVR_ATtiny2313__)
+# include <avr/iotn2313.h>
+#elif defined (__AVR_ATtiny2313A__)
+# include <avr/iotn2313a.h>
+#elif defined (__AVR_ATtiny13__)
+# include <avr/iotn13.h>
+#elif defined (__AVR_ATtiny13A__)
+# include <avr/iotn13a.h>
+#elif defined (__AVR_ATtiny25__)
+# include <avr/iotn25.h>
+#elif defined (__AVR_ATtiny4313__)
+# include <avr/iotn4313.h>
+#elif defined (__AVR_ATtiny45__)
+# include <avr/iotn45.h>
+#elif defined (__AVR_ATtiny85__)
+# include <avr/iotn85.h>
+#elif defined (__AVR_ATtiny24__)
+# include <avr/iotn24.h>
+#elif defined (__AVR_ATtiny24A__)
+# include <avr/iotn24a.h>
+#elif defined (__AVR_ATtiny44__)
+# include <avr/iotn44.h>
+#elif defined (__AVR_ATtiny44A__)
+# include <avr/iotn44a.h>
+#elif defined (__AVR_ATtiny84__)
+# include <avr/iotn84.h>
+#elif defined (__AVR_ATtiny261__)
+# include <avr/iotn261.h>
+#elif defined (__AVR_ATtiny261A__)
+# include <avr/iotn261a.h>
+#elif defined (__AVR_ATtiny461__)
+# include <avr/iotn461.h>
+#elif defined (__AVR_ATtiny461A__)
+# include <avr/iotn461a.h>
+#elif defined (__AVR_ATtiny861__)
+# include <avr/iotn861.h>
+#elif defined (__AVR_ATtiny861A__)
+# include <avr/iotn861a.h>
+#elif defined (__AVR_ATtiny43U__)
+# include <avr/iotn43u.h>
+#elif defined (__AVR_ATtiny48__)
+# include <avr/iotn48.h>
+#elif defined (__AVR_ATtiny88__)
+# include <avr/iotn88.h>
+#elif defined (__AVR_ATtiny87__)
+# include <avr/iotn87.h>
+#elif defined (__AVR_ATtiny167__)
+# include <avr/iotn167.h>
+#elif defined (__AVR_AT90SCR100__)
+# include <avr/io90scr100.h>
+#elif defined (__AVR_ATxmega16A4__)
+# include <avr/iox16a4.h>
+#elif defined (__AVR_ATxmega16D4__)
+# include <avr/iox16d4.h>
+#elif defined (__AVR_ATxmega32A4__)
+# include <avr/iox32a4.h>
+#elif defined (__AVR_ATxmega32D4__)
+# include <avr/iox32d4.h>
+#elif defined (__AVR_ATxmega64A1__)
+# include <avr/iox64a1.h>
+#elif defined (__AVR_ATxmega64A3__)
+# include <avr/iox64a3.h>
+#elif defined (__AVR_ATxmega64D3__)
+# include <avr/iox64d3.h>
+#elif defined (__AVR_ATxmega128A1__)
+# include <avr/iox128a1.h>
+#elif defined (__AVR_ATxmega128A3__)
+# include <avr/iox128a3.h>
+#elif defined (__AVR_ATxmega128D3__)
+# include <avr/iox128d3.h>
+#elif defined (__AVR_ATxmega192A3__)
+# include <avr/iox192a3.h>
+#elif defined (__AVR_ATxmega192D3__)
+# include <avr/iox192d3.h>
+#elif defined (__AVR_ATxmega256A3__)
+# include <avr/iox256a3.h>
+#elif defined (__AVR_ATxmega256A3B__)
+# include <avr/iox256a3b.h>
+#elif defined (__AVR_ATxmega256D3__)
+# include <avr/iox256d3.h>
+#elif defined (__AVR_ATA6289__)
+# include <avr/ioa6289.h>
+/* avr1: the following only supported for assembler programs */
+#elif defined (__AVR_ATtiny28__)
+# include <avr/iotn28.h>
+#elif defined (__AVR_AT90S1200__)
+# include <avr/io1200.h>
+#elif defined (__AVR_ATtiny15__)
+# include <avr/iotn15.h>
+#elif defined (__AVR_ATtiny12__)
+# include <avr/iotn12.h>
+#elif defined (__AVR_ATtiny11__)
+# include <avr/iotn11.h>
+#else
+# if !defined(__COMPILING_AVR_LIBC__)
+# warning "device type not defined"
+# endif
+#endif
+
+#include <avr/portpins.h>
+
+#include <avr/common.h>
+
+#include <avr/version.h>
+
+/* Include fuse.h after individual IO header files. */
+#include <avr/fuse.h>
+
+/* Include lock.h after individual IO header files. */
+#include <avr/lock.h>
+
+#endif /* _AVR_IO_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io1200.h b/cpukit/score/cpu/avr/avr/io1200.h
new file mode 100644
index 0000000000..6268b26fe9
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io1200.h
@@ -0,0 +1,270 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io1200.h - definitions for AT90S1200 */
+
+#ifndef _AVR_IO1200_H_
+#define _AVR_IO1200_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io1200.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef __ASSEMBLER__
+# warning "MCU not supported by the C compiler"
+#endif
+
+/* I/O registers */
+
+/* 0x00..0x07 reserved */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* 0x09..0x0F reserved */
+
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* 0x13..0x15 reserved */
+
+#define PINB _SFR_IO8(0x16)
+#define DDRB _SFR_IO8(0x17)
+#define PORTB _SFR_IO8(0x18)
+
+/* 0x19..0x1B reserved */
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* 0x1F..0x20 reserved */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* 0x22..0x31 reserved */
+
+#define TCNT0 _SFR_IO8(0x32)
+#define TCCR0 _SFR_IO8(0x33)
+
+/* 0x34 reserved */
+
+#define MCUCR _SFR_IO8(0x35)
+
+/* 0x36..0x37 reserved */
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* 0x3A reserved */
+
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C..0x3E reserved */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(2)
+#define SIG_OVERFLOW0 _VECTOR(2)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(3)
+#define SIG_COMPARATOR _VECTOR(3)
+
+#define _VECTORS_SIZE 8
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT0 6
+
+/* TIMSK */
+#define TOIE0 1
+
+/* TIFR */
+#define TOV0 1
+
+/* MCUCR */
+#define SE 5
+#define SM 4
+#define ISC01 1
+#define ISC00 0
+
+/* TCCR0 */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* WDTCR */
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* EECR */
+#undef EEMWE
+
+/*
+ PB7 = SCK
+ PB6 = MISO
+ PB5 = MOSI
+ PB1 = AIN1
+ PB0 = AIN0
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* PORTD */
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* ACSR */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIS1 1
+#define ACIS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+#undef ZH
+
+/* Last memory addresses */
+#define RAMEND 0x1F
+#define XRAMEND 0x0
+#define E2END 0x3F
+#define E2PAGESIZE 0
+#define FLASHEND 0x3FF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_RCEN (unsigned char)~_BV(0)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x90
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IO1200_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io2313.h b/cpukit/score/cpu/avr/avr/io2313.h
new file mode 100644
index 0000000000..4069ff1413
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io2313.h
@@ -0,0 +1,371 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io2313.h - definitions for AT90S2313 */
+
+#ifndef _AVR_IO2313_H_
+#define _AVR_IO2313_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io2313.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Output Compare Register 1 */
+#define OCR1 _SFR_IO16(0x2A)
+#define OCR1L _SFR_IO8(0x2A)
+#define OCR1H _SFR_IO8(0x2B)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C..0x3D SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT1_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+
+/* Timer/Counter1 Compare Match */
+#define TIMER1_COMP1_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF1_vect _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(5)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF0_vect _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(6)
+
+/* UART, Rx Complete */
+#define UART_RX_vect _VECTOR(7)
+#define SIG_UART_RECV _VECTOR(7)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(8)
+#define SIG_UART_DATA _VECTOR(8)
+
+/* UART, Tx Complete */
+#define UART_TX_vect _VECTOR(9)
+#define SIG_UART_TRANS _VECTOR(9)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(10)
+#define SIG_COMPARATOR _VECTOR(10)
+
+#define _VECTORS_SIZE 22
+
+/*
+ * The Register Bit names are represented by their bit number (0-7).
+ */
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define TOIE1 7
+#define OCIE1A 6
+#define TICIE 3 /* old name */
+#define TICIE1 3
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag register */
+#define TOV1 7
+#define OCF1A 6
+#define ICF1 3
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* EEPROM Control Register */
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port D */
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 0
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_FSTRT (unsigned char)~_BV(0)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IO2313_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io2323.h b/cpukit/score/cpu/avr/avr/io2323.h
new file mode 100644
index 0000000000..b0da337466
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io2323.h
@@ -0,0 +1,204 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io2323.h - definitions for AT90S2323 */
+
+#ifndef _AVR_IO2323_H_
+#define _AVR_IO2323_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io2323.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF0_vect _VECTOR(2)
+#define SIG_OVERFLOW0 _VECTOR(2)
+
+#define _VECTORS_SIZE 6
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+ */
+
+/* General Interrupt MaSK register */
+#define INT0 6
+#define INTF0 6
+
+/* General Interrupt Flag Register */
+#define TOIE0 1
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PB2 = SCK/T0
+ PB1 = MISO/INT0
+ PB0 = MOSI
+ */
+
+/* Data Register, Port B */
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 0
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_FSTRT (unsigned char)~_BV(0)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x02
+
+
+#endif /* _AVR_IO2323_H_ */
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x02
+
diff --git a/cpukit/score/cpu/avr/avr/io2333.h b/cpukit/score/cpu/avr/avr/io2333.h
new file mode 100644
index 0000000000..c239144b1d
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io2333.h
@@ -0,0 +1,444 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io2333.h - definitions for AT90S2333 */
+
+#ifndef _AVR_IO2333_H_
+#define _AVR_IO2333_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io2333.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* UART Baud Rate Register high */
+#define UBRRH _SFR_IO8(0x03)
+
+/* ADC Data register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register */
+#define ADCSR _SFR_IO8(0x06)
+
+/* ADC MUX */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control/Status Registers */
+#define UCSRB _SFR_IO8(0x0A)
+#define UCSRA _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1 _SFR_IO16(0x2A)
+#define OCR1L _SFR_IO8(0x2A)
+#define OCR1H _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+
+/* Timer/Counter1 Compare Match */
+#define TIMER1_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(5)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(6)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(7)
+#define SIG_SPI _VECTOR(7)
+
+/* UART, Rx Complete */
+#define UART_RX_vect _VECTOR(8)
+#define SIG_UART_RECV _VECTOR(8)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(9)
+#define SIG_UART_DATA _VECTOR(9)
+
+/* UART, Tx Complete */
+#define UART_TX_vect _VECTOR(10)
+#define SIG_UART_TRANS _VECTOR(10)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(11)
+#define SIG_ADC _VECTOR(11)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(12)
+#define SIG_EEPROM_READY _VECTOR(12)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(13)
+#define SIG_COMPARATOR _VECTOR(13)
+
+#define _VECTORS_SIZE 28
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* MCU general Status Register */
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define TOIE1 7
+#define OCIE1 6
+#define TICIE1 3
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag register */
+#define TOV1 7
+#define OCF1 6
+#define ICF1 3
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM11 7
+#define COM10 6
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define MPCM 0
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define AINBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC MUX */
+#define ACDBG 6
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADC Control and Status Register */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* Data Register, Port B */
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0xDF /*Last On-Chip SRAM location*/
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define FLASHEND 0x7FF
+
+#endif /* _AVR_IO2333_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io2343.h b/cpukit/score/cpu/avr/avr/io2343.h
new file mode 100644
index 0000000000..1e952d3fd9
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io2343.h
@@ -0,0 +1,209 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io2343.h - definitions for AT90S2343 */
+
+#ifndef _AVR_IO2343_H_
+#define _AVR_IO2343_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io2343.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF0_vect _VECTOR(2)
+#define SIG_OVERFLOW0 _VECTOR(2)
+
+#define _VECTORS_SIZE 6
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+ */
+
+/* General Interrupt MaSK register */
+#define INT0 6
+#define INTF0 6
+
+/* General Interrupt Flag Register */
+#define TOIE0 1
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC01 1
+#define ISC00 0
+
+/* MCU Status Register */
+#define PORF 0
+#define EXTRF 1
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PB3 = CLOCK
+ PB2 = SCK/T0
+ PB1 = MISO/INT0
+ PB0 = MOSI
+ */
+
+/* Data Register, Port B */
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 0
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_RCEN (unsigned char)~_BV(0)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IO2343_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io43u32x.h b/cpukit/score/cpu/avr/avr/io43u32x.h
new file mode 100644
index 0000000000..750920f9ae
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io43u32x.h
@@ -0,0 +1,436 @@
+/* Copyright (c) 2003,2005 Keith Gudger
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io43u32x.h - definitions for AT43USB32x */
+
+#ifndef _AVR_IO43U32X_H_
+#define _AVR_IO43U32X_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io43u32x.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* Input Pins, Port E */ // new port for 43324/6
+#define PINE _SFR_IO8(0x01)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x02)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x03)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* 0x1C..0x1F reserved */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Control Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt Mask register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* Interrupt vectors */
+
+#define SIG_INTERRUPT0 _VECTOR(1)
+#define SIG_INTERRUPT1 _VECTOR(2)
+#define SIG_TIMER1_CAPT1 _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(7)
+#define SIG_SPI _VECTOR(8)
+#define SIG_UART_RECV _VECTOR(9)
+#define SIG_UART_DATA _VECTOR(10)
+#define SIG_UART_TRANS _VECTOR(11)
+#define SIG_USB_INT _VECTOR(12)
+
+#define _VECTORS_SIZE 52
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* Timer/Counter Interrupt MaSK register */
+#define TICIE1 3
+#define OCIE1A 6
+#define OCIE1B 5
+#define TOIE1 7
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag Register */
+#define ICF1 3
+#define OCF1A 6
+#define OCF1B 5
+#define TOV1 7
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Data Register, Port E */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Data Direction Register, Port E */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Input Pins, Port E */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Constants */
+#define RAMEND 0x025F /*Last On-Chip SRAM Location*/
+#define XRAMEND RAMEND
+#define E2END 0x0000
+
+/* FIXME: should be 0x1FFFF for max 128K (64K*16) external program memory,
+ but no RAMPZ causes gcrt1.S build to fail, so assume 64K for now... */
+#define FLASHEND 0x0FFFF
+
+#endif /* _AVR_43USB32X_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io43u35x.h b/cpukit/score/cpu/avr/avr/io43u35x.h
new file mode 100644
index 0000000000..364e2776bc
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io43u35x.h
@@ -0,0 +1,428 @@
+/* Copyright (c) 2003,2005 Keith Gudger
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io43u35x.h - definitions for AT43USB35x */
+
+#ifndef _AVR_IO43U35X_H_
+#define _AVR_IO43U35X_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io43u35x.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x02)
+#endif
+#define ADCW _SFR_IO16(0x02)
+#define ADCL _SFR_IO8(0x02)
+#define ADCH _SFR_IO8(0x03)
+
+/* ADC Control and status register */
+#define ADCSR _SFR_IO8(0x07)
+
+/* ADC Multiplexer select */
+#define ADMUX _SFR_IO8(0x08)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* Input Pins, Port F */
+#define PINF _SFR_IO8(0x04)
+
+/* Data Direction Register, Port F */
+#define DDRF _SFR_IO8(0x05)
+
+/* Data Register, Port F */
+#define PORTF _SFR_IO8(0x06)
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x01)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x02)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x03)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* 0x1C..0x1F reserved */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Control Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt Mask register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* Interrupt vectors */
+
+#define SIG_INTERRUPT0 _VECTOR(1) /* suspend/resume */
+#define SIG_INTERRUPT1 _VECTOR(2)
+#define SIG_TIMER1_CAPT1 _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(7)
+#define SIG_SPI _VECTOR(8)
+/* 9, 10: reserved */
+#define SIG_ADC _VECTOR(11)
+#define SIG_USB_INT _VECTOR(12)
+
+#define _VECTORS_SIZE 52
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* Timer/Counter Interrupt MaSK register */
+#define TICIE1 3
+#define OCIE1A 6
+#define OCIE1B 5
+#define TOIE1 7
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag Register */
+#define ICF1 3
+#define OCF1A 6
+#define OCF1B 5
+#define TOV1 7
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Data Register, Port F */
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+/* Data Direction Register, Port F */
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+
+/* Input Pins, Port F */
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* ADC Multiplexer select */
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADC Control and Status Register */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* Constants */
+#define RAMEND 0x045F /*Last On-Chip SRAM Location*/
+#define XRAMEND RAMEND
+#define E2END 0x0000
+#define FLASHEND 0x5FFF
+
+#endif /* _AVR_43USB355_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io4414.h b/cpukit/score/cpu/avr/avr/io4414.h
new file mode 100644
index 0000000000..ec6b8bf5a3
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io4414.h
@@ -0,0 +1,485 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io4414.h - definitions for AT90S4414 */
+
+#ifndef _AVR_IO4414_H_
+#define _AVR_IO4414_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io4414.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C..0x3D SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+
+/* Timer/Counter1 Compare MatchB */
+#define TIMER1_COMPB_vect _VECTOR(5)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(5)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW1 _VECTOR(6)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(7)
+#define SIG_OVERFLOW0 _VECTOR(7)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(8)
+#define SIG_SPI _VECTOR(8)
+
+/* UART, Rx Complete */
+#define UART_RX_vect _VECTOR(9)
+#define SIG_UART_RECV _VECTOR(9)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(10)
+#define SIG_UART_DATA _VECTOR(10)
+
+/* UART, Tx Complete */
+#define UART_TX_vect _VECTOR(11)
+#define SIG_UART_TRANS _VECTOR(11)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(12)
+#define SIG_COMPARATOR _VECTOR(12)
+
+#define _VECTORS_SIZE 26
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define TICIE1 3
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag register */
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define ICF1 3
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SRE 7
+#define SRW 6
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0x15F /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0xFF
+#define E2PAGESIZE 0
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_SPIEN (unsigned char)~_BV(1) /* Serial Program Downloading Enabled */
+#define FUSE_FSTRT (unsigned char)~_BV(2) /* Short Start-up time selected */
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IO4414_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io4433.h b/cpukit/score/cpu/avr/avr/io4433.h
new file mode 100644
index 0000000000..1452e85044
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io4433.h
@@ -0,0 +1,473 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io4433.h - definitions for AT90S4433 */
+
+#ifndef _AVR_IO4433_H_
+#define _AVR_IO4433_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io4433.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* UART Baud Rate Register high */
+#define UBRRH _SFR_IO8(0x03)
+
+/* ADC Data register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register */
+#define ADCSR _SFR_IO8(0x06)
+
+/* ADC MUX */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control/Status Registers */
+#define UCSRB _SFR_IO8(0x0A)
+#define UCSRA _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1 _SFR_IO16(0x2A)
+#define OCR1L _SFR_IO8(0x2A)
+#define OCR1H _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+
+/* Timer/Counter1 Compare Match */
+#define TIMER1_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(5)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(6)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(7)
+#define SIG_SPI _VECTOR(7)
+
+/* UART, Rx Complete */
+#define UART_RX_vect _VECTOR(8)
+#define SIG_UART_RECV _VECTOR(8)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(9)
+#define SIG_UART_DATA _VECTOR(9)
+
+/* UART, Tx Complete */
+#define UART_TX_vect _VECTOR(10)
+#define SIG_UART_TRANS _VECTOR(10)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(11)
+#define SIG_ADC _VECTOR(11)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(12)
+#define SIG_EEPROM_READY _VECTOR(12)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(13)
+#define SIG_COMPARATOR _VECTOR(13)
+
+#define _VECTORS_SIZE 28
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* MCU general Status Register */
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define TOIE1 7
+#define OCIE1 6
+#define TICIE1 3
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag register */
+#define TOV1 7
+#define OCF1 6
+#define ICF1 3
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM11 7
+#define COM10 6
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define MPCM 0
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define AINBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC MUX */
+#define ACDBG 6
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADC Control and Status Register */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* Data Register, Port B */
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0xDF /*Last On-Chip SRAM location*/
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 0
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_BODEN (unsigned char)~_BV(3)
+#define FUSE_BODLEVEL (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IO4433_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io4434.h b/cpukit/score/cpu/avr/avr/io4434.h
new file mode 100644
index 0000000000..e8231f0907
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io4434.h
@@ -0,0 +1,567 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io4434.h - definitions for AT90S4434 */
+
+#ifndef _AVR_IO4434_H_
+#define _AVR_IO4434_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io4434.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* ADC Data register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register */
+#define ADCSR _SFR_IO8(0x06)
+
+/* ADC MUX */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Asynchronous mode Status Register */
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x23)
+
+/* Timer/Counter 2 */
+#define TCNT2 _SFR_IO8(0x24)
+
+/* Timer/Counter 2 Control Register */
+#define TCCR2 _SFR_IO8(0x25)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(3)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW2 _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW0 _VECTOR(9)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(10)
+#define SIG_SPI _VECTOR(10)
+
+/* UART, RX Complete */
+#define UART_RX_vect _VECTOR(11)
+#define SIG_UART_RECV _VECTOR(11)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(12)
+#define SIG_UART_DATA _VECTOR(12)
+
+/* UART, TX Complete */
+#define UART_TX_vect _VECTOR(13)
+#define SIG_UART_TRANS _VECTOR(13)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(14)
+#define SIG_ADC _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(16)
+#define SIG_COMPARATOR _VECTOR(16)
+
+#define _VECTORS_SIZE 34
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* MCU general Status Register */
+#define EXTRF 1
+#define PORF 0
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define TOIE0 0
+
+/* Timer/Counter Interrupt Flag register */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define TOV0 0
+
+/* MCU general Control Register */
+#define SE 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter 2 Control Register */
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Asynchronous mode Status Register */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC MUX */
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADC Control and Status Register */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0x15F /*Last On-Chip SRAM location*/
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 0
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_SPIEN ~_BV(1) /* Serial Program Downloading Enabled */
+#define FUSE_FSTRT ~_BV(2) /* Short Start-up time selected */
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IO4434_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io76c711.h b/cpukit/score/cpu/avr/avr/io76c711.h
new file mode 100644
index 0000000000..dec1d52844
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io76c711.h
@@ -0,0 +1,493 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io76c711.h - definitions for AT76C711 */
+
+#ifndef _AVR_IO76C711_H_
+#define _AVR_IO76C711_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io76c711.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* 0x00-0x0C reserved */
+
+/* SPI */
+#define SPCR _SFR_IO8(0x0D)
+#define SPSR _SFR_IO8(0x0E)
+#define SPDR _SFR_IO8(0x0F)
+
+/* Port D */
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* Peripheral Enable Register */
+#define PERIPHEN _SFR_IO8(0x13)
+
+/* Clock Control Register */
+#define CLK_CNTR _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Port B */
+#define PINB _SFR_IO8(0x16)
+#define DDRB _SFR_IO8(0x17)
+#define PORTB _SFR_IO8(0x18)
+
+/* Port A */
+#define PINA _SFR_IO8(0x19)
+#define DDRA _SFR_IO8(0x1A)
+#define PORTA _SFR_IO8(0x1B)
+
+/* 0x1C-0x1F reserved */
+
+#define IRDAMOD _SFR_IO8(0x20)
+
+#define WDTCR _SFR_IO8(0x21)
+
+/* 0x22-0x25 reserved */
+/* Timer 1 */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCCR1B _SFR_IO8(0x2E)
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* 0x30 reserved */
+
+/* Timer 0 */
+#define PRELD _SFR_IO8(0x31)
+#define TCNT0 _SFR_IO8(0x32)
+#define TCCR0 _SFR_IO8(0x33)
+
+#define MCUSR _SFR_IO8(0x34)
+#define MCUCR _SFR_IO8(0x35)
+
+#define TIFR _SFR_IO8(0x36)
+#define TIMSK _SFR_IO8(0x37)
+
+/* 0x38 reserved */
+
+#define EIMSK _SFR_IO8(0x39)
+
+/* 0x3A-0x3C reserved */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+#define SIG_SUSPEND_RESUME _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(2)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(7)
+#define SIG_SPI _VECTOR(8)
+#define SIG_TDMAC _VECTOR(9)
+#define SIG_UART0 _VECTOR(10)
+#define SIG_RDMAC _VECTOR(11)
+#define SIG_USB_HW _VECTOR(12)
+#define SIG_UART1 _VECTOR(13)
+#define SIG_INTERRUPT1 _VECTOR(14)
+
+#define _VECTORS_SIZE 60
+
+/* Bit numbers */
+
+/* EIMSK */
+/* bits 7-4 reserved */
+#define POL1 3
+#define POL0 2
+#define INT1 1
+#define INT0 0
+
+/* TIMSK */
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+/* bit 4 reserved */
+#define TICIE1 3
+/* bit 2 reserved */
+#define TOIE0 1
+/* bit 0 reserved */
+
+/* TIFR */
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+/* bit 4 reserved */
+#define ICF1 3
+/* bit 2 reserved */
+#define TOV0 1
+/* bit 0 reserved */
+
+/* MCUCR */
+/* bits 7-6 reserved */
+#define SE 5
+#define SM1 4
+#define SM0 3
+/* bits 2-0 reserved */
+
+/* MCUSR */
+/* bits 7-2 reserved */
+#define EXTRF 1
+#define PORF 0
+
+/* TCCR0 */
+/* bits 7-6 reserved */
+#define COM01 5
+#define COM00 4
+#define CTC0 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+/* bits 3-0 reserved */
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+/* bits 5-4 reserved */
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* WDTCR */
+/* bits 7-5 reserved */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* IRDAMOD */
+/* bits 7-3 reserved */
+#define POL 2
+#define MODE 1
+#define EN 0
+
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB7 = SCK
+ PB6 = MISO
+ PB5 = MOSI
+ PB4 = SS#
+ PB2 = ICP
+ PB1 = T1
+ PB0 = T0
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* PORTC */
+/* bits 7-4 reserved */
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/*
+ PD7 = INT1 / OC1B
+ PD6 = INT0 / OC1A
+ PD1 = TXD
+ PD0 = RXD
+ */
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* CLK_CNTR */
+/* bits 7-5 reserved */
+#define UOSC 4
+#define UCK 3
+#define IRCK 2
+/* bits 1-0 reserved */
+
+/* PERIPHEN */
+/* bits 7-3 reserved */
+#define IRDA 2
+#define UART 1
+#define USB 0
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+/* bits 5-0 reserved */
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* Memory mapped registers (XXX - not yet changed to use _SFR_MEM8() macros) */
+
+/* UART */
+#define UART0_BASE 0x2020
+#define UART1_BASE 0x2030
+/* offsets from the base address */
+#define US_RHR 0x00
+#define US_THR 0x00
+#define US_IER 0x01
+#define US_FCR 0x02
+#define US_PMR 0x03
+#define US_MR 0x04
+#define US_CSR 0x05
+#define US_CR 0x06
+#define US_BL 0x07
+#define US_BM 0x08
+#define US_RTO 0x09
+#define US_TTG 0x0A
+
+/* DMA */
+#define DMA_BASE 0x2000
+/* offsets from the base address */
+#define TXTADL 0x01
+#define TXPLL 0x03
+#define TXPLM 0x04
+#define TXTPLL 0x05
+#define TXTPLM 0x06
+#define RXTADL 0x07
+#define RXTADMEN 0x08
+#define RSPLL 0x09
+#define RXPLM 0x0A
+#define RXTPLL 0x0B
+#define RXTPLM 0x0C
+#define INTCST 0x0D
+/* XXX DPORG register mentioned on page 20, but undocumented */
+
+/* XXX Program Memory Control Bit mentioned on page 20, but undocumented */
+#define PROGRAM_MEMORY_CONTROL_BIT 0x2040
+
+/* USB */
+#define USB_BASE 0x1000
+/* offsets from the base address */
+#define FRM_NUM_H 0x0FD
+#define FRM_NUM_L 0x0FC
+#define GLB_STATE 0x0FB
+#define SPRSR 0x0FA
+#define SPRSIE 0x0F9
+#define UISR 0x0F7
+#define UIAR 0x0F5
+#define FADDR 0x0F2
+#define ENDPPGPG 0x0F1
+#define ECR0 0x0EF
+#define ECR1 0x0EE
+#define ECR2 0x0ED
+#define ECR3 0x0EC
+#define ECR4 0x0EB
+#define ECR5 0x0EA
+#define ECR6 0x0E9
+#define ECR7 0x0E8
+#define CSR0 0x0DF
+#define CSR1 0x0DE
+#define CSR2 0x0DD
+#define CSR3 0x0DC
+#define CSR4 0x0DB
+#define CSR5 0x0DA
+#define CSR6 0x0D9
+#define CSR7 0x0D8
+#define FDR0 0x0CF
+#define FDR1 0x0CE
+#define FDR2 0x0CD
+#define FDR3 0x0CC
+#define FDR4 0x0CB
+#define FDR5 0x0CA
+#define FDR6 0x0C9
+#define FDR7 0x0C8
+#define FBYTE_CNT0_L 0x0BF
+#define FBYTE_CNT1_L 0x0BE
+#define FBYTE_CNT2_L 0x0BD
+#define FBYTE_CNT3_L 0x0BC
+#define FBYTE_CNT4_L 0x0BB
+#define FBYTE_CNT5_L 0x0BA
+#define FBYTE_CNT6_L 0x0B9
+#define FBYTE_CNT7_L 0x0B8
+#define FBYTE_CNT0_H 0x0AF
+#define FBYTE_CNT1_H 0x0AE
+#define FBYTE_CNT2_H 0x0AD
+#define FBYTE_CNT3_H 0x0AC
+#define FBYTE_CNT4_H 0x0AB
+#define FBYTE_CNT5_H 0x0AA
+#define FBYTE_CNT6_H 0x0A9
+#define FBYTE_CNT7_H 0x0A8
+#define SLP_MD_EN 0x100
+#define IRQ_EN 0x101
+#define IRQ_STAT 0x102
+#define SUSP_WUP 0x103
+#define PA_EN 0x104
+#define USB_DMA_ADL 0x105
+#define USB_DMA_ADH 0x106
+#define USB_DMA_PLR 0x107
+#define USB_DMA_EAD 0x108
+#define USB_DMA_PLT 0x109
+#define USB_DMA_EN 0x10A
+
+/* Last memory addresses */
+#define RAMEND 0x07FF
+#define XRAMEND RAMEND
+#define E2END 0
+#define FLASHEND 0x3FFF
+
+/*
+ AT76C711 data space memory map (ranges not listed are reserved):
+ 0x0000 - 0x001F - AVR registers
+ 0x0020 - 0x005F - AVR I/O space
+ 0x0060 - 0x07FF - AVR data SRAM
+ 0x1000 - 0x1FFF - USB (not all locations used)
+ 0x2000 - 0x201F - DMA controller
+ 0x2020 - 0x202F - UART0
+ 0x2030 - 0x203F - UART1 (IRDA)
+ 0x2040 - the mysterious Program Memory Control bit (???)
+ 0x3000 - 0x37FF - DPRAM
+ 0x8000 - 0xBFFF - program SRAM (read/write), would be nice if other
+ AVR devices did that as well (no need to use LPM!)
+ */
+#endif /* _AVR_IO76C711_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io8515.h b/cpukit/score/cpu/avr/avr/io8515.h
new file mode 100644
index 0000000000..f9fa50de75
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io8515.h
@@ -0,0 +1,486 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io8515.h - definitions for AT90S8515 */
+
+#ifndef _AVR_IO8515_H_
+#define _AVR_IO8515_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io8515.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+
+/* Timer/Counter1 Compare MatchB */
+#define TIMER1_COMPB_vect _VECTOR(5)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(5)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW1 _VECTOR(6)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(7)
+#define SIG_OVERFLOW0 _VECTOR(7)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(8)
+#define SIG_SPI _VECTOR(8)
+
+/* UART, Rx Complete */
+#define UART_RX_vect _VECTOR(9)
+#define SIG_UART_RECV _VECTOR(9)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(10)
+#define SIG_UART_DATA _VECTOR(10)
+
+/* UART, Tx Complete */
+#define UART_TX_vect _VECTOR(11)
+#define SIG_UART_TRANS _VECTOR(11)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(12)
+#define SIG_COMPARATOR _VECTOR(12)
+
+#define _VECTORS_SIZE 26
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define TICIE1 3
+#define TOIE0 1
+
+/* Timer/Counter Interrupt Flag register */
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define ICF1 3
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SRE 7
+#define SRW 6
+#define SE 5
+#define SM 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0x25F /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x1FF
+#define E2PAGESIZE 0
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_SPIEN ~_BV(1) /* Serial Program Downloading Enabled */
+#define FUSE_FSTRT ~_BV(2) /* Short Start-up time selected */
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IO8515_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io8534.h b/cpukit/score/cpu/avr/avr/io8534.h
new file mode 100644
index 0000000000..d1a88c3f01
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io8534.h
@@ -0,0 +1,216 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io8534.h - definitions for AT90C8534 */
+
+#ifndef _AVR_IO8534_
+#define _AVR_IO8534_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io8534.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* 0x00..0x03 reserved */
+
+/* ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register */
+#define ADCSR _SFR_IO8(0x06)
+
+/* ADC Multiplexer Select Register */
+#define ADMUX _SFR_IO8(0x07)
+
+/* 0x08..0x0F reserved */
+
+/* General Interrupt Pin Register */
+#define GIPR _SFR_IO8(0x10)
+
+/* 0x11..0x19 reserved */
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* 0x20..0x2B reserved */
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter1 Control Register */
+#define TCCR1 _SFR_IO8(0x2E)
+
+/* 0x2F..0x31 reserved */
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* 0x34 reserved */
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* 0x36..0x37 reserved */
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C reserved */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+#define SIG_INTERRUPT0 _VECTOR(1)
+#define SIG_INTERRUPT1 _VECTOR(2)
+#define SIG_OVERFLOW1 _VECTOR(3)
+#define SIG_OVERFLOW0 _VECTOR(4)
+#define SIG_ADC _VECTOR(5)
+#define SIG_EEPROM_READY _VECTOR(6)
+
+#define _VECTORS_SIZE 14
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT1 7
+#define INT0 6
+
+/* GIFR */
+#define INTF1 7
+#define INTF0 6
+
+/* GIPR */
+#define IPIN1 3
+#define IPIN0 2
+
+/* TIMSK */
+#define TOIE1 2
+#define TOIE0 0
+
+/* TIFR */
+#define TOV1 2
+#define TOV0 0
+
+/* MCUCR */
+#define SE 6
+#define SM 5
+#define ISC1 2
+#define ISC0 0
+
+/* TCCR0 */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR1 */
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Last memory addresses */
+#define RAMEND 0x15F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define FLASHEND 0x1FFF
+
+#endif /* _AVR_IO8534_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io8535.h b/cpukit/score/cpu/avr/avr/io8535.h
new file mode 100644
index 0000000000..5a4bf4a175
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io8535.h
@@ -0,0 +1,568 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io8535.h - definitions for AT90S8535 */
+
+#ifndef _AVR_IO8535_H_
+#define _AVR_IO8535_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io8535.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* ADC Data register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register */
+#define ADCSR _SFR_IO8(0x06)
+
+/* ADC MUX */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Asynchronous mode Status Register */
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x23)
+
+/* Timer/Counter 2 */
+#define TCNT2 _SFR_IO8(0x24)
+
+/* Timer/Counter 2 Control Register */
+#define TCCR2 _SFR_IO8(0x25)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(3)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW2 _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW0 _VECTOR(9)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(10)
+#define SIG_SPI _VECTOR(10)
+
+/* UART, RX Complete */
+#define UART_RX_vect _VECTOR(11)
+#define SIG_UART_RECV _VECTOR(11)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(12)
+#define SIG_UART_DATA _VECTOR(12)
+
+/* UART, TX Complete */
+#define UART_TX_vect _VECTOR(13)
+#define SIG_UART_TRANS _VECTOR(13)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(14)
+#define SIG_ADC _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(16)
+#define SIG_COMPARATOR _VECTOR(16)
+
+#define _VECTORS_SIZE 34
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* MCU general Status Register */
+#define EXTRF 1
+#define PORF 0
+
+/* General Interrupt MaSK register */
+#define INT1 7
+#define INT0 6
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+
+/* Timer/Counter Interrupt MaSK register */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define TOIE0 0
+
+/* Timer/Counter Interrupt Flag register */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define TOV0 0
+
+/* MCU general Control Register */
+#define SE 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter 2 Control Register */
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Asynchronous mode Status Register */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC MUX */
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADC Control and Status Register */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0x25F /*Last On-Chip SRAM location*/
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 0
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_SPIEN (unsigned char)~_BV(1) /* Serial Program Downloading Enabled */
+#define FUSE_FSTRT (unsigned char)~_BV(2) /* Short Start-up time selected */
+#define LFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IO8535_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io86r401.h b/cpukit/score/cpu/avr/avr/io86r401.h
new file mode 100644
index 0000000000..5fa29c25b4
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io86r401.h
@@ -0,0 +1,308 @@
+/* Copyright (c) 2002, Colin O'Flynn
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/io86r401.h - definitions for AT86RF401 */
+
+#ifndef _AVR_IO86RF401_H_
+#define _AVR_IO86RF401_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io86r401.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#include <avr/sfr_defs.h>
+
+/* Status REGister */
+#define SREG _SFR_IO8(0x3F)
+
+/* Stack Pointer */
+#define SP _SFR_IO16(0x3D)
+#define SPH _SFR_IO8(0x3E)
+#define SPL _SFR_IO8(0x3D)
+
+/*Battery low configeration register */
+#define BL_CONFIG _SFR_IO8(0x35)
+
+/*Button detect register*/
+#define B_DET _SFR_IO8(0x34)
+
+/*AVR Configeration register*/
+#define AVR_CONFIG _SFR_IO8(0x33)
+
+/* I/O registers */
+
+/*Data in register */
+#define IO_DATIN _SFR_IO8(0x32)
+
+/*Data out register */
+#define IO_DATOUT _SFR_IO8(0x31)
+
+/*IO Enable register */
+#define IO_ENAB _SFR_IO8(0x30)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x22)
+
+/* Bit Timer Control Register */
+#define BTCR _SFR_IO8(0x21)
+
+#define BTCNT _SFR_IO8(0x20)
+
+/*
+NOTE: EEPROM name's changed to have D in front on them, per datasheet, but
+you may want to remove the leading D.
+*/
+/* EEPROM Control Register */
+
+/* EEPROM Address Register */
+#define DEEAR _SFR_IO8(0x1E)
+#define DEEARL _SFR_IO8(0x1E)
+
+/* EEPROM Data Register */
+#define DEEDR _SFR_IO8(0x1D)
+/* EEPROM Control Register */
+#define DEECR _SFR_IO8(0x1C)
+
+/* Lock Detector Configuration Register 2 */
+#define LOCKDET2 _SFR_IO8(0x17)
+
+/* VCO Tuning Register*/
+#define VCOTUNE _SFR_IO8(0x16)
+
+/* Power Attenuation Control Register */
+#define PWR_ATTEN _SFR_IO8(0x14)
+
+/* Transmitter Control Register */
+#define TX_CNTL _SFR_IO8(0x12)
+
+/* Lock Detector Configuration Register 1 */
+#define LOCKDET1 _SFR_IO8(0x10)
+
+
+/* Interrupt vectors */
+
+/* Transmission Done, Bit Timer Flag 2 Interrupt */
+#define TXDONE_vect _VECTOR(1)
+#define SIG_TXDONE _VECTOR(1)
+
+/* Transmit Buffer Empty, Bit Itmer Flag 0 Interrupt */
+#define TXEMPTY_vect _VECTOR(2)
+#define SIG_TXBE _VECTOR(2)
+
+#define _VECTORS_SIZE 12
+
+/*
+ * The Register Bit names are represented by their bit number (0-7).
+ */
+
+/* Lock Detector Configuration Register 1 - LOCKDET1 */
+#define UPOK 4
+#define ENKO 3
+#define BOD 2
+#define CS1 1
+#define CS0 0
+
+/* Transmit Control Register - TX_CNTL */
+#define TXE 5
+#define TXK 4
+#define LOC 2
+
+/* Power Attenuation Control Register - PWR_ATTEN */
+#define PCC2 5
+#define PCC1 4
+#define PCC0 3
+#define PCF2 2
+#define PCF1 1
+#define PCF0 0
+
+/* VCO Tuning Register 6 - VCOTUNE --NOTE: [] removed from names*/
+#define VCOVDET1 7
+#define VCOVDET0 6
+#define VCOTUNE4 4
+#define VCOTUNE3 3
+#define VCOTUNE2 2
+#define VCOTUNE1 1
+#define VCOTUNE0 0
+
+/* Lock Detector Configuration Register 2 - LOCKDET2 --NOTE: [] removed from names*/
+#define EUD 7
+#define LAT 6
+#define ULC2 5
+#define ULC1 4
+#define ULC0 3
+#define LC2 2
+#define LC1 1
+#define LC0 0
+
+/* Data EEPROM Control Register - DEECR */
+#define BSY 3
+#define EEU 2
+#define EEL 1
+#define EER 0
+
+/* Data EEPROM Data Register - DEEDR */
+#define ED7 7
+#define ED6 6
+#define ED5 5
+#define ED4 4
+#define ED3 3
+#define ED2 2
+#define ED1 1
+#define ED0 0
+
+/* Data EEPROM Address Register - DEEAR */
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define BA2 2 /* B is not a typo! */
+#define BA1 1
+#define BA0 0
+
+/* Bit Timer Count Register - BTCNT */
+#define C7 7
+#define C6 6
+#define C5 5
+#define C4 4
+#define C3 3
+#define C2 2
+#define C1 1
+#define C0 0
+
+/* Bit Timer Control Register - BTCR */
+#define C9 7
+#define C8 6
+#define M1 5
+#define M0 4
+#define IE 3
+#define F2 2
+#define DATA 1
+#define F0 0
+
+/* Watchdog Timer Control Register - WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* I/O Enable Register - IO_ENAB */
+#define BOHYST 6
+#define IOE5 5
+#define IOE4 4
+#define IOE3 3
+#define IOE2 2
+#define IOE1 1
+#define IOE0 0
+
+/* Note: No PORTB or whatever, this is the equivalent. */
+/* I/O Data Out Register - IO_DATOUT */
+#define IOO5 5
+#define IOO4 4
+#define IOO3 3
+#define IOO2 2
+#define IOO1 1
+#define IOO0 0
+
+/* Note: No PINB or whatever, this is the equivalent. */
+/* I/O Data In Register - IO_DATIN */
+#define IOI5 5
+#define IOI4 4
+#define IOI3 3
+#define IOI2 2
+#define IOI1 1
+#define IOI0 0
+
+/* AVR Configuration Register - AVR_CONFIG */
+#define ACS1 6
+#define ACS0 5
+#define TM 4
+#define BD 3
+#define BLI 2
+#define SLEEP 1
+#define BBM 0
+
+/* Button Detect Register - B_DET */
+#define BD5 5
+#define BD4 4
+#define BD3 3
+#define BD2 2
+#define BD1 1
+#define BD0 0
+
+/* Battery Low Configuration Register - BL_CONFIG */
+#define BL 7
+#define BLV 6
+#define BL5 5
+#define BL4 4
+#define BL3 3
+#define BL2 2
+#define BL1 1
+#define BL0 0
+
+/* Pointer definition */
+#define XL r26
+#define XH r27
+#define YL r28
+#define YH r29
+#define ZL r30
+#define ZH r31
+
+/* Constants */
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 0
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 0
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x81
+
+
+#endif /* _AVR_IO86RF401_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90pwm1.h b/cpukit/score/cpu/avr/avr/io90pwm1.h
new file mode 100644
index 0000000000..2277154656
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwm1.h
@@ -0,0 +1,1121 @@
+/* Copyright (c) 2005, Andrey Pashchenko
+ Copyright (c) 2007, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iopwm1.h - definitions for AT90PWM1 device */
+
+#ifndef _AVR_IOPWM1_H_
+#define _AVR_IOPWM1_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iopwm1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Reserved [0x00..0x02] */
+
+/* Port B Input Pins Address */
+#define PINB _SFR_IO8(0x03)
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Port B Data Direction Register */
+#define DDRB _SFR_IO8(0x04)
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Port B Data Register */
+#define PORTB _SFR_IO8(0x05)
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Reserved [0x06..0x08] */
+
+/* Port D Input Pins Address */
+#define PIND _SFR_IO8(0x09)
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Port D Data Direction Register */
+#define DDRD _SFR_IO8(0x0A)
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Port D Data Register */
+#define PORTD _SFR_IO8(0x0B)
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Port E Input Pins Address */
+#define PINE _SFR_IO8(0x0C)
+/* PINE */
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* Port E Data Direction Register */
+#define DDRE _SFR_IO8(0x0D)
+/* DDRE */
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Port E Data Register */
+#define PORTE _SFR_IO8(0x0E)
+/* PORTE */
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Reserved [0x0F..0x14] */
+
+/* Timer/Counter 0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+/* TIFR0 */
+#define OCF0B 2 /* Output Compare Flag 0B */
+#define OCF0A 1 /* Output Compare Flag 0A */
+#define TOV0 0 /* Overflow Flag */
+
+/* Timer/Counter1 Interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+/* TIFR1 */
+#define ICF1 5 /* Input Capture Flag 1 */
+#define OCF1B 2 /* Output Compare Flag 1B*/
+#define OCF1A 1 /* Output Compare Flag 1A*/
+#define TOV1 0 /* Overflow Flag */
+
+/* Reserved [0x17..0x18] */
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x19)
+/* GPIOR1 */
+#define GPIOR17 7
+#define GPIOR16 6
+#define GPIOR15 5
+#define GPIOR14 4
+#define GPIOR13 3
+#define GPIOR12 2
+#define GPIOR11 1
+#define GPIOR10 0
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x1A)
+/* GPIOR2 */
+#define GPIOR27 7
+#define GPIOR26 6
+#define GPIOR25 5
+#define GPIOR24 4
+#define GPIOR23 3
+#define GPIOR22 2
+#define GPIOR21 1
+#define GPIOR20 0
+
+/* General Purpose I/O Register 3 */
+#define GPIOR3 _SFR_IO8(0x1B)
+/* GPIOR3 */
+#define GPIOR37 7
+#define GPIOR36 6
+#define GPIOR35 5
+#define GPIOR34 4
+#define GPIOR33 3
+#define GPIOR32 2
+#define GPIOR31 1
+#define GPIOR30 0
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+/* EIFR */
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+/* EIMSK */
+#define INT3 3 /* External Interrupt Request 3 Enable */
+#define INT2 2 /* External Interrupt Request 2 Enable */
+#define INT1 1 /* External Interrupt Request 1 Enable */
+#define INT0 0 /* External Interrupt Request 0 Enable */
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+/* GPIOR0 */
+#define GPIOR07 7
+#define GPIOR06 6
+#define GPIOR05 5
+#define GPIOR04 4
+#define GPIOR03 3
+#define GPIOR02 2
+#define GPIOR01 1
+#define GPIOR00 0
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+/* EECR */
+#define EERIE 3 /* EEPROM Ready Interrupt Enable */
+#define EEMWE 2 /* EEPROM Master Write Enable */
+#define EEWE 1 /* EEPROM Write Enable */
+#define EERE 0 /* EEPROM Read Enable */
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+/* EEDR */
+#define EEDR7 7
+#define EEDR6 6
+#define EEDR5 5
+#define EEDR4 4
+#define EEDR3 3
+#define EEDR2 2
+#define EEDR1 1
+#define EEDR0 0
+
+/* The EEPROM Address Registers */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+/* EEARH */
+#define EEAR11 3
+#define EEAR10 2
+#define EEAR9 1
+#define EEAR8 0
+/* EEARL */
+#define EEAR7 7
+#define EEAR6 6
+#define EEAR5 5
+#define EEAR4 4
+#define EEAR3 3
+#define EEAR2 2
+#define EEAR1 1
+#define EEAR0 0
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+/* GTCCR */
+#define TSM 7 /* Timer/Counter Synchronization Mode */
+#define ICPSEL1 6 /* Timer1 Input Capture Selection Bit */
+#define PSRSYNC 0
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+/* TCCR0A */
+#define COM0A1 7 /* Compare Output Mode, Phase Correct PWM Mode */
+#define COM0A0 6 /* Compare Output Mode, Phase Correct PWM Mode */
+#define COM0B1 5 /* Compare Output Mode, Fast PWm */
+#define COM0B0 4 /* Compare Output Mode, Fast PWm */
+#define WGM01 1 /* Waveform Generation Mode */
+#define WGM00 0 /* Waveform Generation Mode */
+
+/* Timer/Counter Control Register B */
+#define TCCR0B _SFR_IO8(0x25)
+/* TCCR0B */
+#define FOC0A 7 /* Force Output Compare A */
+#define FOC0B 6 /* Force Output Compare B */
+#define WGM02 3 /* Waveform Generation Mode */
+#define CS02 2 /* Clock Select */
+#define CS01 1 /* Clock Select */
+#define CS00 0 /* Clock Select */
+
+/* Timer/Counter0 Register */
+#define TCNT0 _SFR_IO8(0x26)
+/* TCNT0 */
+#define TCNT07 7
+#define TCNT06 6
+#define TCNT05 5
+#define TCNT04 4
+#define TCNT03 3
+#define TCNT02 2
+#define TCNT01 1
+#define TCNT00 0
+
+/* Timer/Counter0 Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+/* OCR0A */
+#define OCR0A7 7
+#define OCR0A6 6
+#define OCR0A5 5
+#define OCR0A4 4
+#define OCR0A3 3
+#define OCR0A2 2
+#define OCR0A1 1
+#define OCR0A0 0
+
+/* Timer/Counter0 Output Compare Register B */
+#define OCR0B _SFR_IO8(0x28)
+/* OCR0B */
+#define OCR0B7 7
+#define OCR0B6 6
+#define OCR0B5 5
+#define OCR0B4 4
+#define OCR0B3 3
+#define OCR0B2 2
+#define OCR0B1 1
+#define OCR0B0 0
+
+/* PLL Control and Status Register */
+#define PLLCSR _SFR_IO8(0x29)
+/* PLLCSR */
+#define PLLF 2
+#define PLLE 1 /* PLL Enable */
+#define PLOCK 0 /* PLL Lock Detector */
+
+/* Reserved [0x2A..0x2B] */
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+/* SPCR */
+#define SPIE 7 /* SPI Interrupt Enable */
+#define SPE 6 /* SPI Enable */
+#define DORD 5 /* Data Order */
+#define MSTR 4 /* Master/Slave Select */
+#define CPOL 3 /* Clock polarity */
+#define CPHA 2 /* Clock Phase */
+#define SPR1 1 /* SPI Clock Rate Select 1 */
+#define SPR0 0 /* SPI Clock Rate Select 0 */
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+/* SPSR */
+#define SPIF 7 /* SPI Interrupt Flag */
+#define WCOL 6 /* Write Collision Flag */
+#define SPI2X 0 /* Double SPI Speed Bit */
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+/* SPDR */
+#define SPD7 7
+#define SPD6 6
+#define SPD5 5
+#define SPD4 4
+#define SPD3 3
+#define SPD2 2
+#define SPD1 1
+#define SPD0 0
+
+/* Reserved [0x2F] */
+
+/* Analog Comparator Status Register */
+#define ACSR _SFR_IO8(0x30)
+/* ACSR */
+#define ACCKDIV 7 /* Analog Comparator Clock Divider */
+#define AC2IF 6 /* Analog Comparator 2 Interrupt Flag Bit */
+#define AC0IF 4 /* Analog Comparator 0 Interrupt Flag Bit */
+#define AC2O 2 /* Analog Comparator 2 Output Bit */
+#define AC0O 0 /* Analog Comparator 0 Output Bit */
+
+/* Monitor Data Register */
+#define MONDR _SFR_IO8(0x31)
+
+/* Monitor Stop Mode Control Register */
+#define MSMCR _SFR_IO8(0x32)
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+/* SMCR */
+#define SM2 3 /* Sleep Mode Select bit2 */
+#define SM1 2 /* Sleep Mode Select bit1 */
+#define SM0 1 /* Sleep Mode Select bit0 */
+#define SE 0 /* Sleep Enable */
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+/* MCUSR */
+#define WDRF 3 /* Watchdog Reset Flag */
+#define BORF 2 /* Brown-out Reset Flag */
+#define EXTRF 1 /* External Reset Flag */
+#define PORF 0 /* Power-on reset flag */
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+/* MCUCR */
+#define SPIPS 7 /* SPI Pin Select */
+#define PUD 4 /* Pull-up disable */
+#define IVSEL 1 /* Interrupt Vector Select */
+#define IVCE 0 /* Interrupt Vector Change Enable */
+
+/* Reserved [0x36] */
+
+/* Store Program Memory Control Register */
+#define SPMCSR _SFR_IO8(0x37)
+/* SPMCSR */
+#define SPMIE 7 /* SPM Interrupt Enable */
+#define RWWSB 6 /* Read While Write Section Busy */
+#define RWWSRE 4 /* Read While Write section read enable */
+#define BLBSET 3 /* Boot Lock Bit Set */
+#define PGWRT 2 /* Page Write */
+#define PGERS 1 /* Page Erase */
+#define SPMEN 0 /* Store Program Memory Enable */
+
+/* Reserved [0x38..0x3C] */
+
+/* 0x3D..0x3E SP [defined in <avr/io.h>] */
+/* 0x3F SREG [defined in <avr/io.h>] */
+
+/* Watchdog Timer Control Register */
+#define WDTCSR _SFR_MEM8(0x60)
+/* WDTCSR */
+#define WDIF 7 /* Watchdog Timeout Interrupt Flag */
+#define WDIE 6 /* Watchdog Timeout Interrupt Enable */
+#define WDP3 5 /* Watchdog Timer Prescaler bit3 */
+#define WDCE 4 /* Watchdog Change Enable */
+#define WDE 3 /* Watchdog Enable */
+#define WDP2 2 /* Watchdog Timer Prescaler bit2 */
+#define WDP1 1 /* Watchdog Timer Prescaler bit1 */
+#define WDP0 0 /* Watchdog Timer Prescaler bit0 */
+
+/* Clock Prescaler Register */
+#define CLKPR _SFR_MEM8(0x61)
+/* CLKPR */
+#define CLKPCE 7 /* Clock Prescaler Change Enable */
+#define CLKPS3 3 /* Clock Prescaler Select bit3 */
+#define CLKPS2 2 /* Clock Prescaler Select bit2 */
+#define CLKPS1 1 /* Clock Prescaler Select bit1 */
+#define CLKPS0 0 /* Clock Prescaler Select bit0 */
+
+/* Reserved [0x62..0x63] */
+
+/* Power Reduction Register */
+#define PRR _SFR_MEM8(0x64)
+/* PRR */
+#define PRPSC2 7 /* Power Reduction PSC2 */
+#define PRPSC1 6 /* Power Reduction PSC1 */
+#define PRPSC0 5 /* Power Reduction PSC0 */
+#define PRTIM1 4 /* Power Reduction Timer/Counter1 */
+#define PRTIM0 3 /* Power Reduction Timer/Counter0 */
+#define PRSPI 2 /* Power Reduction Serial Peripheral Interface */
+#define PRADC 0 /* Power Reduction ADC */
+
+/* Reserved [0x65] */
+
+/* Oscillator Calibration Value */
+#define OSCCAL _SFR_MEM8(0x66)
+/* OSCCAL */
+#define CAL6 6
+#define CAL5 5
+#define CAL4 4
+#define CAL3 3
+#define CAL2 2
+#define CAL1 1
+#define CAL0 0
+
+/* Reserved [0x67..0x68] */
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+/* EICRA */
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Reserved [0x6A..0x6D] */
+
+/* Timer/Counter0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+/* TIMSK0 */
+#define OCIE0B 2 /* Output Compare Match B Interrupt Enable */
+#define OCIE0A 1 /* Output Compare Match A Interrupt Enable */
+#define TOIE0 0 /* Overflow Interrupt Enable */
+
+/* Timer/Counter1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+/* TIMSK1 */
+#define ICIE1 5 /* Input Capture Interrupt Enable */
+#define OCIE1B 2 /* Output Compare Match B Interrupt Enable */
+#define OCIE1A 1 /* Output Compare Match A Interrupt Enable */
+#define TOIE1 0 /* Overflow Interrupt Enable */
+
+/* Reserved [0x70..0x75] */
+
+/* Amplifier 0 Control and Status register */
+#define AMP0CSR _SFR_MEM8(0x76)
+#define AMP0EN 7
+#define AMP0IS 6
+#define AMP0G1 5
+#define AMP0G0 4
+#define AMP0TS1 1
+#define AMP0TS0 0
+
+/* Reserved [0x77] */
+
+/* ADC Result Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+/* ADCSRA */
+#define ADEN 7 /* ADC Enable */
+#define ADSC 6 /* ADC Start Conversion */
+#define ADATE 5 /* ADC Auto Trigger Enable */
+#define ADIF 4 /* ADC Interrupt Flag */
+#define ADIE 3 /* ADC Interrupt Enable */
+#define ADPS2 2 /* ADC Prescaler Select bit2 */
+#define ADPS1 1 /* ADC Prescaler Select bit1 */
+#define ADPS0 0 /* ADC Prescaler Select bit0 */
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+/* ADCSRB */
+#define ADTS3 3 /* ADC Auto Trigger Source 2 */
+#define ADTS2 2 /* ADC Auto Trigger Source 2 */
+#define ADTS1 1 /* ADC Auto Trigger Source 1 */
+#define ADTS0 0 /* ADC Auto Trigger Source 0 */
+
+/* ADC multiplexer Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+/* ADMUX */
+#define REFS1 7 /* Reference Selection bit1 */
+#define REFS0 6 /* Reference Selection bit0 */
+#define ADLAR 5 /* Left Adjust Result */
+#define MUX3 3 /* Analog Channel and Gain Selection bit3 */
+#define MUX2 2 /* Analog Channel and Gain Selection bit2 */
+#define MUX1 1 /* Analog Channel and Gain Selection bit1 */
+#define MUX0 0 /* Analog Channel and Gain Selection bit0 */
+
+/* Reserved [0x7D] */
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+/* DIDR0 */
+#define ADC7D 7 /* ADC7 Digital input Disable */
+#define ADC6D 6 /* ADC6 Digital input Disable */
+#define ADC5D 5 /* ADC5 Digital input Disable */
+#define ADC4D 4 /* ADC4 Digital input Disable */
+#define ADC3D 3 /* ADC3 Digital input Disable */
+#define ADC2D 2 /* ADC2 Digital input Disable */
+#define ADC1D 1 /* ADC1 Digital input Disable */
+#define ADC0D 0 /* ADC0 Digital input Disable */
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+/* DIDR1 */
+#define ACMP0D 5
+#define AMP0PD 4
+#define AMP0ND 3
+#define ADC10D 2 /* ADC10 Digital input Disable */
+#define ADC9D 1 /* ADC9 Digital input Disable */
+#define ADC8D 0 /* ADC8 Digital input Disable */
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+/* TCCR1A */
+#define COM1A1 7 /* Comparet Ouput Mode 1A, bit 1 */
+#define COM1A0 6 /* Comparet Ouput Mode 1A, bit 0 */
+#define COM1B1 5 /* Compare Output Mode 1B, bit 1 */
+#define COM1B0 4 /* Compare Output Mode 1B, bit 0 */
+#define WGM11 1 /* Waveform Generation Mode */
+#define WGM10 0 /* Waveform Generation Mode */
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+/* TCCR1B */
+#define ICNC1 7 /* Input Capture 1 Noise Canceler */
+#define ICES1 6 /* Input Capture 1 Edge Select */
+#define WGM13 4 /* Waveform Generation Mode */
+#define WGM12 3 /* Waveform Generation Mode */
+#define CS12 2 /* Prescaler source of Timer/Counter 1 */
+#define CS11 1 /* Prescaler source of Timer/Counter 1 */
+#define CS10 0 /* Prescaler source of Timer/Counter 1 */
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+/* TCCR1C */
+#define FOC1A 7 /* Force Output Compare for Channel A */
+#define FOC1B 6 /* Force Output Compare for Channel B */
+
+/* Reserved [0x83] */
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+/* TCNT1H */
+#define TCNT115 7
+#define TCNT114 6
+#define TCNT113 5
+#define TCNT112 4
+#define TCNT111 3
+#define TCNT110 2
+#define TCNT19 1
+#define TCNT18 0
+/* TCNT1L */
+#define TCNT17 7
+#define TCNT16 6
+#define TCNT15 5
+#define TCNT14 4
+#define TCNT13 3
+#define TCNT12 2
+#define TCNT11 1
+#define TCNT10 0
+
+/* Input Capture Register 1 */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+/* ICR1H */
+#define ICR115 7
+#define ICR114 6
+#define ICR113 5
+#define ICR112 4
+#define ICR111 3
+#define ICR110 2
+#define ICR19 1
+#define ICR18 0
+/* ICR1L */
+#define ICR17 7
+#define ICR16 6
+#define ICR15 5
+#define ICR14 4
+#define ICR13 3
+#define ICR12 2
+#define ICR11 1
+#define ICR10 0
+
+/* Output Compare Register 1 A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+/* OCR1AH */
+#define OCR1A15 7
+#define OCR1A14 6
+#define OCR1A13 5
+#define OCR1A12 4
+#define OCR1A11 3
+#define OCR1A10 2
+#define OCR1A9 1
+#define OCR1A8 0
+/* OCR1AL */
+#define OCR1A7 7
+#define OCR1A6 6
+#define OCR1A5 5
+#define OCR1A4 4
+#define OCR1A3 3
+#define OCR1A2 2
+#define OCR1A1 1
+#define OCR1A0 0
+
+/* Output Compare Register 1 B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+/* OCR1BH */
+#define OCR1B15 7
+#define OCR1B14 6
+#define OCR1B13 5
+#define OCR1B12 4
+#define OCR1B11 3
+#define OCR1B10 2
+#define OCR1B9 1
+#define OCR1B8 0
+/* OCR1BL */
+#define OCR1B7 7
+#define OCR1B6 6
+#define OCR1B5 5
+#define OCR1B4 4
+#define OCR1B3 3
+#define OCR1B2 2
+#define OCR1B1 1
+#define OCR1B0 0
+
+/* Reserved [0x8C..0x9F] */
+
+/* PSC0 Interrupt Flag Register */
+#define PIFR0 _SFR_MEM8(0xA0)
+/* PIFR0 */
+#define PSEI0 5 /* PSC0 Synchro Error Interrupt */
+#define PEV0B 4 /* PSC0 External Event B Interrupt */
+#define PEV0A 3 /* PSC0 External Event A Interrupt */
+#define PRN01 2 /* PSC0 Ramp Number bit1 */
+#define PRN00 1 /* PSC0 Ramp Number bit0 */
+#define PEOP0 0 /* End Of PSC0 Interrupt */
+
+/* PSC0 Interrupt Mask Register */
+#define PIM0 _SFR_MEM8(0xA1)
+/* PIM0 */
+#define PSEIE0 5 /* PSC0 Synchro Error Interrupt Enable */
+#define PEVE0B 4 /* PSC0 External Event B Interrupt Enable */
+#define PEVE0A 3 /* PSC0 External Event A Interrupt Enable */
+#define PEOPE0 0 /* PSC0 End Of Cycle Interrupt Enable */
+
+/* Reserved [0xA2..0xA3] */
+
+/* PSC2 Interrupt Flag Register */
+#define PIFR2 _SFR_MEM8(0xA4)
+/* PIFR2 */
+#define PSEI2 5 /* PSC2 Synchro Error Interrupt */
+#define PEV2B 4 /* PSC2 External Event B Interrupt */
+#define PEV2A 3 /* PSC2 External Event A Interrupt */
+#define PRN21 2 /* PSC2 Ramp Number bit1 */
+#define PRN20 1 /* PSC2 Ramp Number bit0 */
+#define PEOP2 0 /* End Of PSC2 Interrupt */
+
+/* PSC2 Interrupt Mask Register */
+#define PIM2 _SFR_MEM8(0xA5)
+/* PIM2 */
+#define PSEIE2 5 /* PSC2 Synchro Error Interrupt Enable */
+#define PEVE2B 4 /* PSC2 External Event B Interrupt Enable */
+#define PEVE2A 3 /* PSC2 External Event A Interrupt Enable */
+#define PEOPE2 0 /* PSC2 End Of Cycle Interrupt Enable */
+
+/* Reserved [0xA6..0xAC] */
+
+/* Analog Comparator 0 Control Register */
+#define AC0CON _SFR_MEM8(0xAD)
+/* AC0CON */
+#define AC0EN 7 /* Analog Comparator 0 Enable Bit */
+#define AC0IE 6 /* Analog Comparator 0 Interrupt Enable bit */
+#define AC0IS1 5 /* Analog Comparator 0 Interrupt Select bit1 */
+#define AC0IS0 4 /* Analog Comparator 0 Interrupt Select bit0 */
+#define AC0M2 2 /* Analog Comparator 0 Multiplexer register bit2 */
+#define AC0M1 1 /* Analog Comparator 0 Multiplexer register bit1 */
+#define AC0M0 0 /* Analog Comparator 0 Multiplexer register bit0 */
+
+/* Reserved [0xB0..0xAE] */
+
+/* Analog Comparator 2 Control Register */
+#define AC2CON _SFR_MEM8(0xAF)
+/* AC2CON */
+#define AC2EN 7 /* Analog Comparator 2 Enable Bit */
+#define AC2IE 6 /* Analog Comparator 2 Interrupt Enable bit */
+#define AC2IS1 5 /* Analog Comparator 2 Interrupt Select bit1 */
+#define AC2IS0 4 /* Analog Comparator 2 Interrupt Select bit0 */
+#define AC2M2 2 /* Analog Comparator 2 Multiplexer register bit2 */
+#define AC2M1 1 /* Analog Comparator 2 Multiplexer register bit1 */
+#define AC2M0 0 /* Analog Comparator 2 Multiplexer register bit0 */
+
+/* Reserved [0xB0..0xCF] */
+
+/* PSC 0 Synchro and Output Configuration */
+#define PSOC0 _SFR_MEM8(0xD0)
+/* PSOC0 */
+#define PSYNC01 5 /* Synchronization Out for ADC Selection bit1 */
+#define PSYNC00 4 /* Synchronization Out for ADC Selection bit0 */
+#define POEN0B 2 /* PSC 0 OUT Part B Output Enable */
+#define POEN0A 0 /* PSC 0 OUT Part A Output Enable */
+
+/* Reserved [0xD1] */
+
+/* Output Compare SA Registers */
+#define OCR0SA _SFR_MEM16(0xD2)
+#define OCR0SAL _SFR_MEM8(0xD2)
+#define OCR0SAH _SFR_MEM8(0xD3)
+
+/* Output Compare RA Registers */
+#define OCR0RA _SFR_MEM16(0xD4)
+#define OCR0RAL _SFR_MEM8(0xD4)
+#define OCR0RAH _SFR_MEM8(0xD5)
+
+/* Output Compare SB Registers */
+#define OCR0SB _SFR_MEM16(0xD6)
+#define OCR0SBL _SFR_MEM8(0xD6)
+#define OCR0SBH _SFR_MEM8(0xD7)
+
+/* Output Compare RB Registers */
+#define OCR0RB _SFR_MEM16(0xD8)
+#define OCR0RBL _SFR_MEM8(0xD8)
+#define OCR0RBH _SFR_MEM8(0xD9)
+
+/* PSC 0 Configuration Register */
+#define PCNF0 _SFR_MEM8(0xDA)
+/* PCNF0 */
+#define PFIFTY0 7 /* PSC 0 Fifty */
+#define PALOCK0 6 /* PSC 0 Autolock */
+#define PLOCK0 5 /* PSC 0 Lock */
+#define PMODE01 4 /* PSC 0 Mode bit1 */
+#define PMODE00 3 /* PSC 0 Mode bit0 */
+#define POP0 2 /* PSC 0 Output Polarity */
+#define PCLKSEL0 1 /* PSC 0 Input Clock Select */
+
+/* PSC 0 Control Register */
+#define PCTL0 _SFR_MEM8(0xDB)
+/* PCTL0 */
+#define PPRE01 7 /* PSC 0 Prescaler Select bit1 */
+#define PPRE00 6 /* PSC 0 Prescaler Select bit0 */
+#define PBFM0 5 /* Balance Flank Width Modulation */
+#define PAOC0B 4 /* PSC 0 Asynchronous Output Control B */
+#define PAOC0A 3 /* PSC 0 Asynchronous Output Control A */
+#define PARUN0 2 /* PSC 0 Autorun */
+#define PCCYC0 1 /* PSC 0 Complete Cycle */
+#define PRUN0 0 /* PSC 0 Run */
+
+/* PSC 0 Input A Control Register */
+#define PFRC0A _SFR_MEM8(0xDC)
+/* PFRC0A */
+#define PCAE0A 7 /* PSC 0 Capture Enable Input Part A */
+#define PISEL0A 6 /* PSC 0 Input Select for Part A */
+#define PELEV0A 5 /* PSC 0 Edge Level Selector of Input Part A */
+#define PFLTE0A 4 /* PSC 0 Filter Enable on Input Part A */
+#define PRFM0A3 3 /* PSC 0 Fault Mode bit3 */
+#define PRFM0A2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0A1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0A0 0 /* PSC 0 Fault Mode bit0 */
+
+/* PSC 0 Input B Control Register */
+#define PFRC0B _SFR_MEM8(0xDD)
+/* PFRC0B */
+#define PCAE0B 7 /* PSC 0 Capture Enable Input Part B */
+#define PISEL0B 6 /* PSC 0 Input Select for Part B */
+#define PELEV0B 5 /* PSC 0 Edge Level Selector of Input Part B */
+#define PFLTE0B 4 /* PSC 0 Filter Enable on Input Part B */
+#define PRFM0B3 3 /* PSC 0 Fault Mode bit3 */
+#define PRFM0B2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0B1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0B0 0 /* PSC 0 Fault Mode bit0 */
+
+/* PSC 0 Input Capture Registers */
+#define PICR0 _SFR_MEM16(0xDE)
+
+#define PICR0L _SFR_MEM8(0xDE)
+
+#define PICR0H _SFR_MEM8(0xDF)
+#define PCST0 7 /* PSC Capture Software Trig bit */
+
+/* Reserved [0xE0..0xEF] */
+
+/* PSC 2 Synchro and Output Configuration */
+#define PSOC2 _SFR_MEM8(0xF0)
+/* PSOC2 */
+#define POS23 7 /* PSCOUT23 Selection */
+#define POS22 6 /* PSCOUT22 Selection */
+#define PSYNC21 5 /* Synchronization Out for ADC Selection bit1 */
+#define PSYNC20 4 /* Synchronization Out for ADC Selection bit0 */
+#define POEN2D 3 /* PSCOUT23 Output Enable */
+#define POEN2B 2 /* PSC 2 OUT Part B Output Enable */
+#define POEN2C 1 /* PSCOUT22 Output Enable */
+#define POEN2A 0 /* PSC 2 OUT Part A Output Enable */
+
+/* PSC 2 Output Matrix */
+#define POM2 _SFR_MEM8(0xF1)
+/* POM2 */
+#define POMV2B3 7 /* Output Matrix Output B Ramp 3 */
+#define POMV2B2 6 /* Output Matrix Output B Ramp 2 */
+#define POMV2B1 5 /* Output Matrix Output B Ramp 1 */
+#define POMV2B0 4 /* Output Matrix Output B Ramp 0 */
+#define POMV2A3 3 /* Output Matrix Output A Ramp 3 */
+#define POMV2A2 2 /* Output Matrix Output A Ramp 2 */
+#define POMV2A1 1 /* Output Matrix Output A Ramp 1 */
+#define POMV2A0 0 /* Output Matrix Output A Ramp 0 */
+
+/* Output Compare SA Registers */
+#define OCR2SA _SFR_MEM16(0xF2)
+#define OCR2SAL _SFR_MEM8(0xF2)
+#define OCR2SAH _SFR_MEM8(0xF3)
+
+/* Output Compare RA Registers */
+#define OCR2RA _SFR_MEM16(0xF4)
+#define OCR2RAL _SFR_MEM8(0xF4)
+#define OCR2RAH _SFR_MEM8(0xF5)
+
+/* Output Compare SB Registers */
+#define OCR2SB _SFR_MEM16(0xF6)
+#define OCR2SBL _SFR_MEM8(0xF6)
+#define OCR2SBH _SFR_MEM8(0xF7)
+
+/* Output Compare RB Registers */
+#define OCR2RB _SFR_MEM16(0xF8)
+#define OCR2RBL _SFR_MEM8(0xF8)
+#define OCR2RBH _SFR_MEM8(0xF9)
+
+/* PSC 2 Configuration Register */
+#define PCNF2 _SFR_MEM8(0xFA)
+/* PCNF2 */
+#define PFIFTY2 7 /* PSC 2 Fifty */
+#define PALOCK2 6 /* PSC 2 Autolock */
+#define PLOCK2 5 /* PSC 2 Lock */
+#define PMODE21 4 /* PSC 2 Mode bit1 */
+#define PMODE20 3 /* PSC 2 Mode bit0 */
+#define POP2 2 /* PSC 2 Output Polarity */
+#define PCLKSEL2 1 /* PSC 2 Input Clock Select */
+#define POME2 0 /* PSC 2 Output Matrix Enable */
+
+/* PSC 2 Control Register */
+#define PCTL2 _SFR_MEM8(0xFB)
+/* PCTL2 */
+#define PPRE21 7 /* PSC 2 Prescaler Select bit1 */
+#define PPRE20 6 /* PSC 2 Prescaler Select bit0 */
+#define PBFM2 5 /* Balance Flank Width Modulation */
+#define PAOC2B 4 /* PSC 2 Asynchronous Output Control B */
+#define PAOC2A 3 /* PSC 2 Asynchronous Output Control A */
+#define PARUN2 2 /* PSC 2 Autorun */
+#define PCCYC2 1 /* PSC 2 Complete Cycle */
+#define PRUN2 0 /* PSC 2 Run */
+
+/* PSC 2 Input A Control Register */
+#define PFRC2A _SFR_MEM8(0xFC)
+/* PFRC2A */
+#define PCAE2A 7 /* PSC 2 Capture Enable Input Part A */
+#define PISEL2A 6 /* PSC 2 Input Select for Part A */
+#define PELEV2A 5 /* PSC 2 Edge Level Selector of Input Part A */
+#define PFLTE2A 4 /* PSC 2 Filter Enable on Input Part A */
+#define PRFM2A3 3 /* PSC 2 Fault Mode bit3 */
+#define PRFM2A2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2A1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2A0 0 /* PSC 2 Fault Mode bit0 */
+
+/* PSC 2 Input B Control Register */
+#define PFRC2B _SFR_MEM8(0xFD)
+/* PFRC2B */
+#define PCAE2B 7 /* PSC 2 Capture Enable Input Part B */
+#define PISEL2B 6 /* PSC 2 Input Select for Part B */
+#define PELEV2B 5 /* PSC 2 Edge Level Selector of Input Part B */
+#define PFLTE2B 4 /* PSC 2 Filter Enable on Input Part B */
+#define PRFM2B3 3 /* PSC 2 Fault Mode bit3 */
+#define PRFM2B2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2B1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2B0 0 /* PSC 2 Fault Mode bit0 */
+
+/* PSC 2 Input Capture Registers */
+#define PICR2 _SFR_MEM16(0xFE)
+
+#define PICR2L _SFR_MEM8(0xFE)
+
+#define PICR2H _SFR_MEM8(0xFF)
+#define PCST2 7 /* PSC Capture Software Trig bit */
+ /* not implemented on AT90PWM2/AT90PWM3 */
+
+
+/* Interrupt vectors */
+/* PSC2 Capture Event */
+#define PSC2_CAPT_vect _VECTOR(1)
+#define SIG_PSC2_CAPTURE _VECTOR(1)
+
+/* PSC2 End Cycle */
+#define PSC2_EC_vect _VECTOR(2)
+#define SIG_PSC2_END_CYCLE _VECTOR(2)
+
+/* PSC0 Capture Event */
+#define PSC0_CAPT_vect _VECTOR(5)
+#define SIG_PSC0_CAPTURE _VECTOR(5)
+
+/* PSC0 End Cycle */
+#define PSC0_EC_vect _VECTOR(6)
+#define SIG_PSC0_END_CYCLE _VECTOR(6)
+
+/* Analog Comparator 0 */
+#define ANALOG_COMP_0_vect _VECTOR(7)
+#define SIG_COMPARATOR0 _VECTOR(7)
+
+/* Analog Comparator 2 */
+#define ANALOG_COMP_2_vect _VECTOR(9)
+#define SIG_COMPARATOR2 _VECTOR(9)
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(10)
+#define SIG_INTERRUPT0 _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+#define SIG_INPUT_CAPTURE1 _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1_A _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1_B _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+#define SIG_OVERFLOW1 _VECTOR(15)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMP_A_vect _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0_A _VECTOR(16)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(17)
+#define SIG_OVERFLOW0 _VECTOR(17)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(18)
+#define SIG_ADC _VECTOR(18)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(19)
+#define SIG_INTERRUPT1 _VECTOR(19)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(20)
+#define SIG_SPI _VECTOR(20)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(24)
+#define SIG_INTERRUPT2 _VECTOR(24)
+
+/* Watchdog Timeout Interrupt */
+#define WDT_vect _VECTOR(25)
+#define SIG_WDT _VECTOR(25)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(25)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(26)
+#define SIG_EEPROM_READY _VECTOR(26)
+
+/* Timer Counter 0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(27)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(27)
+#define SIG_OUTPUT_COMPARE0_B _VECTOR(27)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(28)
+#define SIG_INTERRUPT3 _VECTOR(28)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(31)
+#define SIG_SPM_READY _VECTOR(31)
+
+#define _VECTORS_SIZE 64
+
+/* Constants */
+#define SPM_PAGESIZE 64
+
+#define RAMEND 0x02FF
+#define XRAMEND RAMEND
+#define E2END 0x01FF
+#define FLASHEND 0x0FFF
+
+
+/* Fuse Information */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Diasble */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_PSCRV (unsigned char)~_BV(4)
+#define FUSE_PSC0RB (unsigned char)~_BV(5)
+#define FUSE_PSC2RB (unsigned char)~_BV(7)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+#endif /* _AVR_IOPWM1_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90pwm216.h b/cpukit/score/cpu/avr/avr/io90pwm216.h
new file mode 100644
index 0000000000..14ad598dc1
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwm216.h
@@ -0,0 +1,1181 @@
+/* Copyright (c) 2007, Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io90pwm216.h - definitions for AT90PWM216 */
+
+#ifndef _AVR_IO90PWM216_H_
+#define _AVR_IO90PWM216_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90pwm216.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Port B Input Pins Address */
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+/* Port B Data Direction Register */
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+/* Port B Data Register */
+#define PORTB _SFR_IO8(0x05)
+#define PB0 0
+#define PB1 1
+#define PB2 2
+#define PB3 3
+#define PB4 4
+#define PB5 5
+#define PB6 6
+#define PB7 7
+
+/* Port C Input Pins Address */
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+/* Port C Data Direction Register */
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+/* Port C Data Register */
+#define PORTC _SFR_IO8(0x08)
+#define PC0 0
+#define PC1 1
+#define PC2 2
+#define PC3 3
+#define PC4 4
+#define PC5 5
+#define PC6 6
+#define PC7 7
+
+/* Port D Input Pins Address */
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+/* Port D Data Direction Register */
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+/* Port D Data Register */
+#define PORTD _SFR_IO8(0x0B)
+#define PD0 0
+#define PD1 1
+#define PD2 2
+#define PD3 3
+#define PD4 4
+#define PD5 5
+#define PD6 6
+#define PD7 7
+
+/* Port E Input Pins Address */
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+/* Port E Data Direction Register */
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+/* Port E Data Register */
+#define PORTE _SFR_IO8(0x0E)
+#define PE0 0
+#define PE1 1
+#define PE2 2
+
+/* Timer/Counter 0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0 /* Overflow Flag */
+#define OCF0A 1 /* Output Compare Flag 0A */
+#define OCF0B 2 /* Output Compare Flag 0B */
+
+/* Timer/Counter1 Interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0 /* Overflow Flag */
+#define OCF1A 1 /* Output Compare Flag 1A*/
+#define OCF1B 2 /* Output Compare Flag 1B*/
+#define ICF1 5 /* Input Capture Flag 1 */
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+/* General Purpose I/O Register 3 */
+#define GPIOR3 _SFR_IO8(0x1B)
+#define GPIOR30 0
+#define GPIOR31 1
+#define GPIOR32 2
+#define GPIOR33 3
+#define GPIOR34 4
+#define GPIOR35 5
+#define GPIOR36 6
+#define GPIOR37 7
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0 /* External Interrupt Request 0 Enable */
+#define INT1 1 /* External Interrupt Request 1 Enable */
+#define INT2 2 /* External Interrupt Request 2 Enable */
+#define INT3 3 /* External Interrupt Request 3 Enable */
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0 /* EEPROM Read Enable */
+#define EEWE 1 /* EEPROM Write Enable */
+#define EEMWE 2 /* EEPROM Master Write Enable */
+#define EERIE 3 /* EEPROM Ready Interrupt Enable */
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+/* The EEPROM Address Registers */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0 /* Prescaler Reset Timer/Counter1 and Timer/Counter0 */
+#define ICPSEL1 6 /* Timer1 Input Capture Selection Bit */
+#define TSM 7 /* Timer/Counter Synchronization Mode */
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0 /* Waveform Generation Mode */
+#define WGM01 1 /* Waveform Generation Mode */
+#define COM0B0 4 /* Compare Output Mode, Fast PWm */
+#define COM0B1 5 /* Compare Output Mode, Fast PWm */
+#define COM0A0 6 /* Compare Output Mode, Phase Correct PWM Mode */
+#define COM0A1 7 /* Compare Output Mode, Phase Correct PWM Mode */
+
+/* Timer/Counter Control Register B */
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0 /* Clock Select */
+#define CS01 1 /* Clock Select */
+#define CS02 2 /* Clock Select */
+#define WGM02 3 /* Waveform Generation Mode */
+#define FOC0B 6 /* Force Output Compare B */
+#define FOC0A 7 /* Force Output Compare A */
+
+/* Timer/Counter0 Register */
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT00 0
+#define TCNT01 1
+#define TCNT02 2
+#define TCNT03 3
+#define TCNT04 4
+#define TCNT05 5
+#define TCNT06 6
+#define TCNT07 7
+
+/* Timer/Counter0 Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+/* Timer/Counter0 Output Compare Register B */
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B0 0
+#define OCR0B1 1
+#define OCR0B2 2
+#define OCR0B3 3
+#define OCR0B4 4
+#define OCR0B5 5
+#define OCR0B6 6
+#define OCR0B7 7
+
+/* PLL Control and Status Register */
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0 /* PLL Lock Detector */
+#define PLLE 1 /* PLL Enable */
+#define PLLF 2 /* PLL Factor */
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0 /* SPI Clock Rate Select 0 */
+#define SPR1 1 /* SPI Clock Rate Select 1 */
+#define CPHA 2 /* Clock Phase */
+#define CPOL 3 /* Clock polarity */
+#define MSTR 4 /* Master/Slave Select */
+#define DORD 5 /* Data Order */
+#define SPE 6 /* SPI Enable */
+#define SPIE 7 /* SPI Interrupt Enable */
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0 /* Double SPI Speed Bit */
+#define WCOL 6 /* Write Collision Flag */
+#define SPIF 7 /* SPI Interrupt Flag */
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+#define SPD0 0
+#define SPD1 1
+#define SPD2 2
+#define SPD3 3
+#define SPD4 4
+#define SPD5 5
+#define SPD6 6
+#define SPD7 7
+
+/* Analog Comparator Status Register */
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0 /* Analog Comparator 0 Output Bit */
+#define AC1O 1 /* Analog Comparator 1 Output Bit */
+#define AC2O 2 /* Analog Comparator 2 Output Bit */
+#define AC0IF 4 /* Analog Comparator 0 Interrupt Flag Bit */
+#define AC1IF 5 /* Analog Comparator 1 Interrupt Flag Bit */
+#define AC2IF 6 /* Analog Comparator 2 Interrupt Flag Bit */
+#define ACCKDIV 7 /* Analog Comparator Clock Divider */
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+#define SE 0 /* Sleep Enable */
+#define SM0 1 /* Sleep Mode Select bit0 */
+#define SM1 2 /* Sleep Mode Select bit1 */
+#define SM2 3 /* Sleep Mode Select bit2 */
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0 /* Power-on reset flag */
+#define EXTRF 1 /* External Reset Flag */
+#define BORF 2 /* Brown-out Reset Flag */
+#define WDRF 3 /* Watchdog Reset Flag */
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0 /* Interrupt Vector Change Enable */
+#define IVSEL 1 /* Interrupt Vector Select */
+#define PUD 4 /* Pull-up disable */
+#define SPIPS 7 /* SPI Pin Select */
+
+/* Store Program Memory Control Register */
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0 /* Store Program Memory Enable */
+#define PGERS 1 /* Page Erase */
+#define PGWRT 2 /* Page Write */
+#define BLBSET 3 /* Boot Lock Bit Set */
+#define RWWSRE 4 /* Read While Write section read enable */
+#define RWWSB 6 /* Read While Write Section Busy */
+#define SPMIE 7 /* SPM Interrupt Enable */
+
+/* Watchdog Timer Control Register */
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0 /* Watchdog Timer Prescaler bit0 */
+#define WDP1 1 /* Watchdog Timer Prescaler bit1 */
+#define WDP2 2 /* Watchdog Timer Prescaler bit2 */
+#define WDE 3 /* Watchdog Enable */
+#define WDCE 4 /* Watchdog Change Enable */
+#define WDP3 5 /* Watchdog Timer Prescaler bit3 */
+#define WDIE 6 /* Watchdog Timeout Interrupt Enable */
+#define WDIF 7 /* Watchdog Timeout Interrupt Flag */
+
+/* Clock Prescaler Register */
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0 /* Clock Prescaler Select bit0 */
+#define CLKPS1 1 /* Clock Prescaler Select bit1 */
+#define CLKPS2 2 /* Clock Prescaler Select bit2 */
+#define CLKPS3 3 /* Clock Prescaler Select bit3 */
+#define CLKPCE 7 /* Clock Prescaler Change Enable */
+
+/* Power Reduction Register */
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0 /* Power Reduction ADC */
+#define PRUSART 1 /* Power Reduction USART */
+#define PRSPI 2 /* Power Reduction Serial Peripheral Interface */
+#define PRTIM0 3 /* Power Reduction Timer/Counter0 */
+#define PRTIM1 4 /* Power Reduction Timer/Counter1 */
+#define PRPSC0 5 /* Power Reduction PSC0 */
+#define PRPSC1 6 /* Power Reduction PSC1 */
+#define PRPSC2 7 /* Power Reduction PSC2 */
+
+/* Oscillator Calibration Value */
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+/* Timer/Counter0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0 /* Overflow Interrupt Enable */
+#define OCIE0A 1 /* Output Compare Match A Interrupt Enable */
+#define OCIE0B 2 /* Output Compare Match B Interrupt Enable */
+
+/* Timer/Counter1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0 /* Overflow Interrupt Enable */
+#define OCIE1A 1 /* Output Compare Match A Interrupt Enable */
+#define OCIE1B 2 /* Output Compare Match B Interrupt Enable */
+#define ICIE1 5 /* Input Capture Interrupt Enable */
+
+/* Amplifier 0 Control and Status register */
+#define AMP0CSR _SFR_MEM8(0x76)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+/* Amplifier 1 Control and Status register */
+#define AMP1CSR _SFR_MEM8(0x77)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+/* ADC Result Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0 /* ADC Prescaler Select bit0 */
+#define ADPS1 1 /* ADC Prescaler Select bit1 */
+#define ADPS2 2 /* ADC Prescaler Select bit2 */
+#define ADIE 3 /* ADC Interrupt Enable */
+#define ADIF 4 /* ADC Interrupt Flag */
+#define ADATE 5 /* ADC Auto Trigger Enable */
+#define ADSC 6 /* ADC Start Conversion */
+#define ADEN 7 /* ADC Enable */
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0 /* ADC Auto Trigger Source 0 */
+#define ADTS1 1 /* ADC Auto Trigger Source 1 */
+#define ADTS2 2 /* ADC Auto Trigger Source 2 */
+#define ADTS3 3 /* ADC Auto Trigger Source 3 */
+#define ADHSM 7 /* ADC High Speed Mode */
+
+/* ADC multiplexer Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0 /* Analog Channel and Gain Selection bit0 */
+#define MUX1 1 /* Analog Channel and Gain Selection bit1 */
+#define MUX2 2 /* Analog Channel and Gain Selection bit2 */
+#define MUX3 3 /* Analog Channel and Gain Selection bit3 */
+#define ADLAR 5 /* Left Adjust Result */
+#define REFS0 6 /* Reference Selection bit0 */
+#define REFS1 7 /* Reference Selection bit1 */
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0 /* ADC0 Digital input Disable */
+#define ADC1D 1 /* ADC1 Digital input Disable */
+#define ADC2D 2 /* ADC2 Digital input Disable */
+#define ADC3D 3 /* ADC3 Digital input Disable */
+#define ADC4D 4 /* ADC4 Digital input Disable */
+#define ADC5D 5 /* ADC5 Digital input Disable */
+#define ADC6D 6 /* ADC6 Digital input Disable */
+#define ADC7D 7 /* ADC7 Digital input Disable */
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0 /* ADC8 Digital input Disable */
+#define ADC9D 1 /* ADC9 Digital input Disable */
+#define ADC10D 2 /* ADC10 Digital input Disable */
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0 /* Waveform Generation Mode */
+#define WGM11 1 /* Waveform Generation Mode */
+#define COM1B0 4 /* Compare Output Mode 1B, bit 0 */
+#define COM1B1 5 /* Compare Output Mode 1B, bit 1 */
+#define COM1A0 6 /* Comparet Ouput Mode 1A, bit 0 */
+#define COM1A1 7 /* Comparet Ouput Mode 1A, bit 1 */
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0 /* Prescaler source of Timer/Counter 1 */
+#define CS11 1 /* Prescaler source of Timer/Counter 1 */
+#define CS12 2 /* Prescaler source of Timer/Counter 1 */
+#define WGM12 3 /* Waveform Generation Mode */
+#define WGM13 4 /* Waveform Generation Mode */
+#define ICES1 6 /* Input Capture 1 Edge Select */
+#define ICNC1 7 /* Input Capture 1 Noise Canceler */
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6 /* Force Output Compare for Channel B */
+#define FOC1A 7 /* Force Output Compare for Channel A */
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT10 0
+#define TCNT11 1
+#define TCNT12 2
+#define TCNT13 3
+#define TCNT14 4
+#define TCNT15 5
+#define TCNT16 6
+#define TCNT17 7
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT18 0
+#define TCNT19 1
+#define TCNT110 2
+#define TCNT111 3
+#define TCNT112 4
+#define TCNT113 5
+#define TCNT114 6
+#define TCNT115 7
+
+/* Input Capture Register 1 */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR17 7
+#define ICR16 6
+#define ICR15 5
+#define ICR14 4
+#define ICR13 3
+#define ICR12 2
+#define ICR11 1
+#define ICR10 0
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR115 7
+#define ICR114 6
+#define ICR113 5
+#define ICR112 4
+#define ICR111 3
+#define ICR110 2
+#define ICR19 1
+#define ICR18 0
+
+/* Output Compare Register 1 A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1A8 0
+#define OCR1A9 1
+#define OCR1A10 2
+#define OCR1A11 3
+#define OCR1A12 4
+#define OCR1A13 5
+#define OCR1A14 6
+#define OCR1A15 7
+
+/* Output Compare Register 1 B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1B8 0
+#define OCR1B9 1
+#define OCR1B10 2
+#define OCR1B11 3
+#define OCR1B12 4
+#define OCR1B13 5
+#define OCR1B14 6
+#define OCR1B15 7
+
+/* PSC0 Interrupt Flag Register */
+#define PIFR0 _SFR_MEM8(0xA0)
+#define PEOP0 0 /* End Of PSC0 Interrupt */
+#define PRN00 1 /* PSC0 Ramp Number bit0 */
+#define PRN01 2 /* PSC0 Ramp Number bit1 */
+#define PEV0A 3 /* PSC0 External Event A Interrupt */
+#define PEV0B 4 /* PSC0 External Event B Interrupt */
+#define PSEI0 5 /* PSC0 Synchro Error Interrupt */
+#define POAC0A 6 /* PSC0 Output A Activity */
+#define POAC0B 7 /* PSC0 Output B Activity */
+
+/* PSC0 Interrupt Mask Register */
+#define PIM0 _SFR_MEM8(0xA1)
+#define PEOPE0 0 /* PSC0 End Of Cycle Interrupt Enable */
+#define PEVE0A 3 /* PSC0 External Event A Interrupt Enable */
+#define PEVE0B 4 /* PSC0 External Event B Interrupt Enable */
+#define PSEIE0 5 /* PSC0 Synchro Error Interrupt Enable */
+
+/* PSC1 Interrupt Flag Register */
+#define PIFR1 _SFR_MEM8(0xA2)
+
+/* PSC1 Interrupt Mask Register */
+#define PIM1 _SFR_MEM8(0xA3)
+
+/* PSC2 Interrupt Flag Register */
+#define PIFR2 _SFR_MEM8(0xA4)
+#define PEOP2 0 /* End Of PSC2 Interrupt */
+#define PRN20 1 /* PSC2 Ramp Number bit0 */
+#define PRN21 2 /* PSC2 Ramp Number bit1 */
+#define PEV2A 3 /* PSC2 External Event A Interrupt */
+#define PEV2B 4 /* PSC2 External Event B Interrupt */
+#define PSEI2 5 /* PSC2 Synchro Error Interrupt */
+#define POAC2A 6 /* PSC2 Output A Activity */
+#define POAC2B 7 /* PSC2 Output B Activity */
+
+/* PSC2 Interrupt Mask Register */
+#define PIM2 _SFR_MEM8(0xA5)
+#define PEOPE2 0 /* PSC2 End Of Cycle Interrupt Enable */
+#define PEVE2A 3 /* PSC2 External Event A Interrupt Enable */
+#define PEVE2B 4 /* PSC2 External Event B Interrupt Enable */
+#define PSEIE2 5 /* PSC2 Synchro Error Interrupt Enable */
+
+/* Digital to Analog Conversion Control Register */
+#define DACON _SFR_MEM8(0xAA)
+#define DAEN 0 /* Digital to Analog Enable bit */
+#define DAOE 1 /* Digital to Analog Output Enable bit */
+#define DALA 2 /* Digital to Analog Left Adjust */
+#define DATS0 4 /* DAC Trigger Selection bit0 */
+#define DATS1 5 /* DAC Trigger Selection bit1 */
+#define DATS2 6 /* DAC Trigger Selection bit2 */
+#define DAATE 7 /* DAC Auto Trigger Enable bit */
+
+/* Digital to Analog Converter input Register */
+#define DAC _SFR_MEM16(0xAB)
+#define DACL _SFR_MEM8(0xAB)
+#define DACH _SFR_MEM8(0xAC)
+
+/* Analog Comparator 0 Control Register */
+#define AC0CON _SFR_MEM8(0xAD)
+#define AC0M0 0 /* Analog Comparator 0 Multiplexer register bit0 */
+#define AC0M1 1 /* Analog Comparator 0 Multiplexer register bit1 */
+#define AC0M2 2 /* Analog Comparator 0 Multiplexer register bit2 */
+#define AC0IS0 4 /* Analog Comparator 0 Interrupt Select bit0 */
+#define AC0IS1 5 /* Analog Comparator 0 Interrupt Select bit1 */
+#define AC0IE 6 /* Analog Comparator 0 Interrupt Enable bit */
+#define AC0EN 7 /* Analog Comparator 0 Enable Bit */
+
+/* Analog Comparator 1 Control Register */
+#define AC1CON _SFR_MEM8(0xAE)
+#define AC1M0 0 /* Analog Comparator 1 Multiplexer register bit0 */
+#define AC1M1 1 /* Analog Comparator 1 Multiplexer register bit1 */
+#define AC1M2 2 /* Analog Comparator 1 Multiplexer register bit2 */
+#define AC1ICE 3 /* Analog Comparator 1 Interrupt Capture Enable bit */
+#define AC1IS0 4 /* Analog Comparator 1 Interrupt Select bit0 */
+#define AC1IS1 5 /* Analog Comparator 1 Interrupt Select bit1 */
+#define AC1IE 6 /* Analog Comparator 1 Interrupt Enable bit */
+#define AC1EN 7 /* Analog Comparator 1 Enable Bit */
+
+/* Analog Comparator 2 Control Register */
+#define AC2CON _SFR_MEM8(0xAF)
+#define AC2M0 0 /* Analog Comparator 2 Multiplexer register bit0 */
+#define AC2M1 1 /* Analog Comparator 2 Multiplexer register bit1 */
+#define AC2M2 2 /* Analog Comparator 2 Multiplexer register bit2 */
+#define AC2IS0 4 /* Analog Comparator 2 Interrupt Select bit0 */
+#define AC2IS1 5 /* Analog Comparator 2 Interrupt Select bit1 */
+#define AC2IE 6 /* Analog Comparator 2 Interrupt Enable bit */
+#define AC2EN 7 /* Analog Comparator 2 Enable Bit */
+
+/* USART Control and Status Register A */
+#define UCSRA _SFR_MEM8(0xC0)
+#define MPCM 0 /* Multi-processor Communication Mode */
+#define U2X 1 /* Double the USART Transmission Speed */
+#define UPE 2 /* USART Parity Error */
+#define DOR 3 /* Data OverRun */
+#define FE 4 /* Frame Error */
+#define UDRE 5 /* USART Data Register Empty */
+#define TXC 6 /* USART Transmit Complete */
+#define RXC 7 /* USART Receive Complete */
+
+/* USART Control and Status Register B */
+#define UCSRB _SFR_MEM8(0xC1)
+#define TXB8 0 /* Transmit Data Bit 8 */
+#define RXB8 1 /* Receive Data Bit 8 */
+#define UCSZ2 2 /* Character Size */
+#define TXEN 3 /* Transmitter Enable */
+#define RXEN 4 /* Receiver Enable */
+#define UDRIE 5 /* USART Data Register Empty Interrupt Enable */
+#define TXCIE 6 /* TX Complete Interrupt Enable */
+#define RXCIE 7 /* RX Complete Interrupt Enable */
+
+/* USART Control and Status Register C */
+#define UCSRC _SFR_MEM8(0xC2)
+#define UCPOL 0 /* Clock Polarity */
+#define UCSZ0 1 /* Character Size bit0 */
+#define UCSZ1 2 /* Character Size bit1 */
+#define USBS 3 /* Stop Bit Select */
+#define UPM0 4 /* Parity Mode bit0 */
+#define UPM1 5 /* Parity Mode bit1 */
+#define UMSEL 6 /* USART Mode Select */
+
+/* USART Baud Rate Register */
+#define UBRR _SFR_MEM16(0xC4)
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRRH _SFR_MEM8(0xC5)
+
+/* USART I/O Data Register */
+#define UDR _SFR_MEM8(0xC6)
+
+/* EUSART Control and Status Register A */
+#define EUCSRA _SFR_MEM8(0xC8)
+#define URxS0 0 /* EUSART Receive Character Size bit0 */
+#define URxS1 1 /* EUSART Receive Character Size bit1 */
+#define URxS2 2 /* EUSART Receive Character Size bit2 */
+#define URxS3 3 /* EUSART Receive Character Size bit3 */
+#define UTxS0 4 /* EUSART Transmit Character Size bit0 */
+#define UTxS1 5 /* EUSART Transmit Character Size bit1 */
+#define UTxS2 6 /* EUSART Transmit Character Size bit2 */
+#define UTxS3 7 /* EUSART Transmit Character Size bit3 */
+
+/* EUSART Control and Status Register B */
+#define EUCSRB _SFR_MEM8(0xC9)
+#define BODR 0 /* Bit Order */
+#define EMCH 1 /* Manchester mode */
+#define EUSBS 3 /* EUSBS Enable Bit */
+#define EUSART 4 /* EUSART Enable Bit */
+
+/* EUSART Control and Status Register C */
+#define EUCSRC _SFR_MEM8(0xCA)
+#define STP0 0 /* Stop bits values bit0 */
+#define STP1 1 /* Stop bits values bit1 */
+#define F1617 2
+#define FEM 3 /* Frame Error Manchester */
+
+/* Manchester receiver Baud Rate Registers */
+#define MUBRR _SFR_MEM16(0xCC)
+#define MUBRRL _SFR_MEM8(0xCC)
+#define MUBRRH _SFR_MEM8(0xCD)
+
+/* EUSART I/O Data Register */
+#define EUDR _SFR_MEM8(0xCE)
+
+/* PSC 0 Synchro and Output Configuration */
+#define PSOC0 _SFR_MEM8(0xD0)
+#define POEN0A 0 /* PSC 0 OUT Part A Output Enable */
+#define POEN0B 2 /* PSC 0 OUT Part B Output Enable */
+#define PSYNC00 4 /* Synchronization Out for ADC Selection bit0 */
+#define PSYNC01 5 /* Synchronization Out for ADC Selection bit1 */
+
+/* Output Compare SA Registers */
+#define OCR0SA _SFR_MEM16(0xD2)
+#define OCR0SAL _SFR_MEM8(0xD2)
+#define OCR0SAH _SFR_MEM8(0xD3)
+
+/* Output Compare RA Registers */
+#define OCR0RA _SFR_MEM16(0xD4)
+#define OCR0RAL _SFR_MEM8(0xD4)
+#define OCR0RAH _SFR_MEM8(0xD5)
+
+/* Output Compare SB Registers */
+#define OCR0SB _SFR_MEM16(0xD6)
+#define OCR0SBL _SFR_MEM8(0xD6)
+#define OCR0SBH _SFR_MEM8(0xD7)
+
+/* Output Compare RB Registers */
+#define OCR0RB _SFR_MEM16(0xD8)
+#define OCR0RBL _SFR_MEM8(0xD8)
+#define OCR0RBH _SFR_MEM8(0xD9)
+
+/* PSC 0 Configuration Register */
+#define PCNF0 _SFR_MEM8(0xDA)
+#define PCLKSEL0 1 /* PSC 0 Input Clock Select */
+#define POP0 2 /* PSC 0 Output Polarity */
+#define PMODE00 3 /* PSC 0 Mode bit0 */
+#define PMODE01 4 /* PSC 0 Mode bit1 */
+#define PLOCK0 5 /* PSC 0 Lock */
+#define PALOCK0 6 /* PSC 0 Autolock */
+#define PFIFTY0 7 /* PSC 0 Fifty */
+
+/* PSC 0 Control Register */
+#define PCTL0 _SFR_MEM8(0xDB)
+#define PRUN0 0 /* PSC 0 Run */
+#define PCCYC0 1 /* PSC 0 Complete Cycle */
+#define PARUN0 2 /* PSC 0 Autorun */
+#define PAOC0A 3 /* PSC 0 Asynchronous Output Control A */
+#define PAOC0B 4 /* PSC 0 Asynchronous Output Control B */
+#define PBFM0 5 /* Balance Flank Width Modulation */
+#define PPRE00 6 /* PSC 0 Prescaler Select bit0 */
+#define PPRE01 7 /* PSC 0 Prescaler Select bit1 */
+
+/* PSC 0 Input A Control Register */
+#define PFRC0A _SFR_MEM8(0xDC)
+#define PRFM0A0 0 /* PSC 0 Fault Mode bit0 */
+#define PRFM0A1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0A2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0A3 3 /* PSC 0 Fault Mode bit3 */
+#define PFLTE0A 4 /* PSC 0 Filter Enable on Input Part A */
+#define PELEV0A 5 /* PSC 0 Edge Level Selector of Input Part A */
+#define PISEL0A 6 /* PSC 0 Input Select for Part A */
+#define PCAE0A 7 /* PSC 0 Capture Enable Input Part A */
+
+/* PSC 0 Input B Control Register */
+#define PFRC0B _SFR_MEM8(0xDD)
+#define PRFM0B0 0 /* PSC 0 Fault Mode bit0 */
+#define PRFM0B1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0B2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0B3 3 /* PSC 0 Fault Mode bit3 */
+#define PFLTE0B 4 /* PSC 0 Filter Enable on Input Part B */
+#define PELEV0B 5 /* PSC 0 Edge Level Selector of Input Part B */
+#define PISEL0B 6 /* PSC 0 Input Select for Part B */
+#define PCAE0B 7 /* PSC 0 Capture Enable Input Part B */
+
+/* PSC 0 Input Capture Registers */
+#define PICR0 _SFR_MEM16(0xDE)
+#define PICR0L _SFR_MEM8(0xDE)
+#define PICR0H _SFR_MEM8(0xDF)
+#define PCST0 7 /* PSC Capture Software Trig bit */
+
+/* PSC 1 Synchro and Output Configuration */
+#define PSOC1 _SFR_MEM8(0xE0)
+
+/* Output Compare SA Registers */
+#define OCR1SA _SFR_MEM16(0xE2)
+#define OCR1SAL _SFR_MEM8(0xE2)
+#define OCR1SAH _SFR_MEM8(0xE3)
+
+/* Output Compare RA Registers */
+#define OCR1RA _SFR_MEM16(0xE4)
+#define OCR1RAL _SFR_MEM8(0xE4)
+#define OCR1RAH _SFR_MEM8(0xE5)
+
+/* Output Compare SB Registers */
+#define OCR1SB _SFR_MEM16(0xE6)
+#define OCR1SBL _SFR_MEM8(0xE6)
+#define OCR1SBH _SFR_MEM8(0xE7)
+
+/* Output Compare RB Registers */
+#define OCR1RB _SFR_MEM16(0xE8)
+#define OCR1RBL _SFR_MEM8(0xE8)
+#define OCR1RBH _SFR_MEM8(0xE9)
+
+/* PSC 1 Configuration Register */
+#define PCNF1 _SFR_MEM8(0xEA)
+
+/* PSC 1 Control Register */
+#define PCTL1 _SFR_MEM8(0xEB)
+
+/* PSC 1 Input A Control Register */
+#define PFRC1A _SFR_MEM8(0xEC)
+
+/* PSC 1 Input B Control Register */
+#define PFRC1B _SFR_MEM8(0xED)
+
+/* PSC 1 Input Capture Registers */
+#define PICR1 _SFR_MEM16(0xEE)
+#define PICR1L _SFR_MEM8(0xEE)
+#define PICR1H _SFR_MEM8(0xEF)
+
+/* PSC 2 Synchro and Output Configuration */
+#define PSOC2 _SFR_MEM8(0xF0)
+#define POEN2A 0 /* PSC 2 OUT Part A Output Enable */
+#define POEN2C 1 /* PSCOUT22 Output Enable */
+#define POEN2B 2 /* PSC 2 OUT Part B Output Enable */
+#define POEN2D 3 /* PSCOUT23 Output Enable */
+#define PSYNC20 4 /* Synchronization Out for ADC Selection bit0 */
+#define PSYNC21 5 /* Synchronization Out for ADC Selection bit1 */
+#define POS22 6 /* PSCOUT22 Selection */
+#define POS23 7 /* PSCOUT23 Selection */
+
+/* PSC 2 Output Matrix */
+#define POM2 _SFR_MEM8(0xF1)
+#define POMV2A0 0 /* Output Matrix Output A Ramp 0 */
+#define POMV2A1 1 /* Output Matrix Output A Ramp 1 */
+#define POMV2A2 2 /* Output Matrix Output A Ramp 2 */
+#define POMV2A3 3 /* Output Matrix Output A Ramp 3 */
+#define POMV2B0 4 /* Output Matrix Output B Ramp 0 */
+#define POMV2B1 5 /* Output Matrix Output B Ramp 1 */
+#define POMV2B2 6 /* Output Matrix Output B Ramp 2 */
+#define POMV2B3 7 /* Output Matrix Output B Ramp 3 */
+
+/* Output Compare SA Registers */
+#define OCR2SA _SFR_MEM16(0xF2)
+#define OCR2SAL _SFR_MEM8(0xF2)
+#define OCR2SAH _SFR_MEM8(0xF3)
+
+/* Output Compare RA Registers */
+#define OCR2RA _SFR_MEM16(0xF4)
+#define OCR2RAL _SFR_MEM8(0xF4)
+#define OCR2RAH _SFR_MEM8(0xF5)
+
+/* Output Compare SB Registers */
+#define OCR2SB _SFR_MEM16(0xF6)
+#define OCR2SBL _SFR_MEM8(0xF6)
+#define OCR2SBH _SFR_MEM8(0xF7)
+
+/* Output Compare RB Registers */
+#define OCR2RB _SFR_MEM16(0xF8)
+#define OCR2RBL _SFR_MEM8(0xF8)
+#define OCR2RBH _SFR_MEM8(0xF9)
+
+/* PSC 2 Configuration Register */
+#define PCNF2 _SFR_MEM8(0xFA)
+#define POME2 0 /* PSC 2 Output Matrix Enable */
+#define PCLKSEL2 1 /* PSC 2 Input Clock Select */
+#define POP2 2 /* PSC 2 Output Polarity */
+#define PMODE20 3 /* PSC 2 Mode bit0 */
+#define PMODE21 4 /* PSC 2 Mode bit1 */
+#define PLOCK2 5 /* PSC 2 Lock */
+#define PALOCK2 6 /* PSC 2 Autolock */
+#define PFIFTY2 7 /* PSC 2 Fifty */
+
+/* PSC 2 Control Register */
+#define PCTL2 _SFR_MEM8(0xFB)
+#define PRUN2 0 /* PSC 2 Run */
+#define PCCYC2 1 /* PSC 2 Complete Cycle */
+#define PARUN2 2 /* PSC 2 Autorun */
+#define PAOC2A 3 /* PSC 2 Asynchronous Output Control A */
+#define PAOC2B 4 /* PSC 2 Asynchronous Output Control B */
+#define PBFM2 5 /* Balance Flank Width Modulation */
+#define PPRE20 6 /* PSC 2 Prescaler Select bit0 */
+#define PPRE21 7 /* PSC 2 Prescaler Select bit1 */
+
+/* PSC 2 Input A Control Register */
+#define PFRC2A _SFR_MEM8(0xFC)
+#define PRFM2A0 0 /* PSC 2 Fault Mode bit0 */
+#define PRFM2A1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2A2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2A3 3 /* PSC 2 Fault Mode bit3 */
+#define PFLTE2A 4 /* PSC 2 Filter Enable on Input Part A */
+#define PELEV2A 5 /* PSC 2 Edge Level Selector of Input Part A */
+#define PISEL2A 6 /* PSC 2 Input Select for Part A */
+#define PCAE2A 7 /* PSC 2 Capture Enable Input Part A */
+
+/* PSC 2 Input B Control Register */
+#define PFRC2B _SFR_MEM8(0xFD)
+#define PRFM2B0 0 /* PSC 2 Fault Mode bit0 */
+#define PRFM2B1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2B2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2B3 3 /* PSC 2 Fault Mode bit3 */
+#define PFLTE2B 4 /* PSC 2 Filter Enable on Input Part B */
+#define PELEV2B 5 /* PSC 2 Edge Level Selector of Input Part B */
+#define PISEL2B 6 /* PSC 2 Input Select for Part B */
+#define PCAE2B 7 /* PSC 2 Capture Enable Input Part B */
+
+/* PSC 2 Input Capture Registers */
+#define PICR2 _SFR_MEM16(0xFE)
+#define PICR2L _SFR_MEM8(0xFE)
+#define PICR2H _SFR_MEM8(0xFF)
+#define PCST2 7 /* PSC Capture Software Trig bit */
+
+
+/* Interrupt Vectors */
+/* Interrupt 0 is the reset vector. */
+
+/* PSC2 Capture Event */
+#define PSC2_CAPT_vect _VECTOR(1)
+
+/* PSC2 End Cycle */
+#define PSC2_EC_vect _VECTOR(2)
+
+/* PSC1 Capture Event */
+#define PSC1_CAPT_vect _VECTOR(3)
+
+/* PSC1 End Cycle */
+#define PSC1_EC_vect _VECTOR(4)
+
+/* PSC0 Capture Event */
+#define PSC0_CAPT_vect _VECTOR(5)
+
+/* PSC0 End Cycle */
+#define PSC0_EC_vect _VECTOR(6)
+
+/* Analog Comparator 0 */
+#define ANALOG_COMP_0_vect _VECTOR(7)
+
+/* Analog Comparator 1 */
+#define ANALOG_COMP_1_vect _VECTOR(8)
+
+/* Analog Comparator 2 */
+#define ANALOG_COMP_2_vect _VECTOR(9)
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMP_A_vect _VECTOR(16)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(17)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(18)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(19)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(20)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(21)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(22)
+
+/* USART, Tx Complete */
+#define USART_TX_vect _VECTOR(23)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(24)
+
+/* Watchdog Timeout Interrupt */
+#define WDT_vect _VECTOR(25)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(26)
+
+/* Timer Counter 0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(27)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(28)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(31)
+
+#define _VECTORS_SIZE (4 * 32)
+
+/* Constants */
+
+#define RAMEND 0x4FF
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+#define SPM_PAGESIZE 128
+
+
+/* Fuse Information */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Diasble */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_PSCRV (unsigned char)~_BV(4)
+#define FUSE_PSC0RB (unsigned char)~_BV(5)
+#define FUSE_PSC1RB (unsigned char)~_BV(6)
+#define FUSE_PSC2RB (unsigned char)~_BV(7)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x83
+
+
+#endif /* _AVR_IO90PWM216_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90pwm2b.h b/cpukit/score/cpu/avr/avr/io90pwm2b.h
new file mode 100644
index 0000000000..9f8fc2fbe1
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwm2b.h
@@ -0,0 +1,1392 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/io90pwm2b.h - definitions for AT90PWM2B */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90pwm2b.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IO90PWM2B_H_
+#define _AVR_IO90PWM2B_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define GPIOR3 _SFR_IO8(0x1B)
+#define GPIOR30 0
+#define GPIOR31 1
+#define GPIOR32 2
+#define GPIOR33 3
+#define GPIOR34 4
+#define GPIOR35 5
+#define GPIOR36 6
+#define GPIOR37 7
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEARL0 0
+#define EEARL1 1
+#define EEARL2 2
+#define EEARL3 3
+#define EEARL4 4
+#define EEARL5 5
+#define EEARL6 6
+#define EEARL7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 2
+#define TSM 3
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define OCR0_0 0 /* Deprecated */
+#define OCR0_1 1 /* Deprecated */
+#define OCR0_2 2 /* Deprecated */
+#define OCR0_3 3 /* Deprecated */
+#define OCR0_4 4 /* Deprecated */
+#define OCR0_5 5 /* Deprecated */
+#define OCR0_6 6 /* Deprecated */
+#define OCR0_7 7 /* Deprecated */
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define ACCKDIV 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC0 5
+#define PRPSC1 6
+#define PRPSC2 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x76)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x77)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define ADASCR 4
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define PIFR0 _SFR_MEM8(0xA0)
+#define PEOP0 0
+#define PRN00 1
+#define PRN01 2
+#define PEV0A 3
+#define PEV0B 4
+#define PSEI0 5
+#define POAC0A 6
+#define POAC0B 7
+
+#define PIM0 _SFR_MEM8(0xA1)
+#define PEOPE0 0
+#define PEVE0A 3
+#define PEVE0B 4
+#define PSEIE0 5
+
+#define PIFR1 _SFR_MEM8(0xA2)
+#define PEOP1 0
+#define PRN10 1
+#define PRN11 2
+#define PEV1A 3
+#define PEV1B 4
+#define PSEI1 5
+#define POAC1A 6
+#define POAC1B 7
+
+#define PIM1 _SFR_MEM8(0xA3)
+#define PEOPE1 0
+#define PEVE1A 3
+#define PEVE1B 4
+#define PSEIE1 5
+
+#define PIFR2 _SFR_MEM8(0xA4)
+#define PEOP2 0
+#define PRN20 1
+#define PRN21 2
+#define PEV2A 3
+#define PEV2B 4
+#define PSEI2 5
+#define POAC2A 6
+#define POAC2B 7
+
+#define PIM2 _SFR_MEM8(0xA5)
+#define PEOPE2 0
+#define PEVE2A 3
+#define PEVE2B 4
+#define PSEIE2 5
+
+#define DACON _SFR_MEM8(0xAA)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0xAB)
+
+#define DACL _SFR_MEM8(0xAB)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0xAC)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0xAD)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0xAE)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0xAF)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define UCSRA _SFR_MEM8(0xC0)
+#define MPCM 0
+#define U2X 1
+#define UPE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UCSRB _SFR_MEM8(0xC1)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRC _SFR_MEM8(0xC2)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL0 6
+
+#define UBRR _SFR_MEM16(0xC4)
+
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRR0 0
+#define UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UBRRH _SFR_MEM8(0xC5)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UDR _SFR_MEM8(0xC6)
+#define UDR0 0
+#define UDR1 1
+#define UDR2 2
+#define UDR3 3
+#define UDR4 4
+#define UDR5 5
+#define UDR6 6
+#define UDR7 7
+
+#define EUCSRA _SFR_MEM8(0xC8)
+#define URxS0 0
+#define URxS1 1
+#define URxS2 2
+#define URxS3 3
+#define UTxS0 4
+#define UTxS1 5
+#define UTxS2 6
+#define UTxS3 7
+
+#define EUCSRB _SFR_MEM8(0xC9)
+#define BODR 0
+#define EMCH 1
+#define EUSBS 3
+#define EUSART 4
+
+#define EUCSRC _SFR_MEM8(0xCA)
+#define STP0 0
+#define STP1 1
+#define F1617 2
+#define FEM 3
+
+#define MUBRR _SFR_MEM16(0xCC)
+
+#define MUBRRL _SFR_MEM8(0xCC)
+#define MUBRR0 0
+#define MUBRR1 1
+#define MUBRR2 2
+#define MUBRR3 3
+#define MUBRR4 4
+#define MUBRR5 5
+#define MUBRR6 6
+#define MUBRR7 7
+
+#define MUBRRH _SFR_MEM8(0xCD)
+#define MUBRR8 0
+#define MUBRR9 1
+#define MUBRR10 2
+#define MUBRR11 3
+#define MUBRR12 4
+#define MUBRR13 5
+#define MUBRR14 6
+#define MUBRR15 7
+
+#define EUDR _SFR_MEM8(0xCE)
+#define EUDR0 0
+#define EUDR1 1
+#define EUDR2 2
+#define EUDR3 3
+#define EUDR4 4
+#define EUDR5 5
+#define EUDR6 6
+#define EUDR7 7
+
+#define PSOC0 _SFR_MEM8(0xD0)
+#define POEN0A 0
+#define POEN0B 2
+#define PSYNC00 4
+#define PSYNC01 5
+
+#define OCR0SA _SFR_MEM16(0xD2)
+
+#define OCR0SAL _SFR_MEM8(0xD2)
+#define OCR0SA_0 0
+#define OCR0SA_1 1
+#define OCR0SA_2 2
+#define OCR0SA_3 3
+#define OCR0SA_4 4
+#define OCR0SA_5 5
+#define OCR0SA_6 6
+#define OCR0SA_7 7
+
+#define OCR0SAH _SFR_MEM8(0xD3)
+#define OCR0SA_8 0
+#define OCR0SA_9 1
+#define OCR0SA_00 2
+#define OCR0SA_01 3
+
+#define OCR0RA _SFR_MEM16(0xD4)
+
+#define OCR0RAL _SFR_MEM8(0xD4)
+#define OCR0RA_0 0
+#define OCR0RA_1 1
+#define OCR0RA_2 2
+#define OCR0RA_3 3
+#define OCR0RA_4 4
+#define OCR0RA_5 5
+#define OCR0RA_6 6
+#define OCR0RA_7 7
+
+#define OCR0RAH _SFR_MEM8(0xD5)
+#define OCR0RA_8 0
+#define OCR0RA_9 1
+#define OCR0RA_00 2
+#define OCR0RA_01 3
+
+#define OCR0SB _SFR_MEM16(0xD6)
+
+#define OCR0SBL _SFR_MEM8(0xD6)
+#define OCR0SB_0 0
+#define OCR0SB_1 1
+#define OCR0SB_2 2
+#define OCR0SB_3 3
+#define OCR0SB_4 4
+#define OCR0SB_5 5
+#define OCR0SB_6 6
+#define OCR0SB_7 7
+
+#define OCR0SBH _SFR_MEM8(0xD7)
+#define OCR0SB_8 0
+#define OCR0SB_9 1
+#define OCR0SB_00 2
+#define OCR0SB_01 3
+
+#define OCR0RB _SFR_MEM16(0xD8)
+
+#define OCR0RBL _SFR_MEM8(0xD8)
+#define OCR0RB_0 0
+#define OCR0RB_1 1
+#define OCR0RB_2 2
+#define OCR0RB_3 3
+#define OCR0RB_4 4
+#define OCR0RB_5 5
+#define OCR0RB_6 6
+#define OCR0RB_7 7
+
+#define OCR0RBH _SFR_MEM8(0xD9)
+#define OCR0RB_8 0
+#define OCR0RB_9 1
+#define OCR0RB_00 2
+#define OCR0RB_01 3
+#define OCR0RB_02 4
+#define OCR0RB_03 5
+#define OCR0RB_04 6
+#define OCR0RB_05 7
+
+#define PCNF0 _SFR_MEM8(0xDA)
+#define PCLKSEL0 1
+#define POP0 2
+#define PMODE00 3
+#define PMODE01 4
+#define PLOCK0 5
+#define PALOCK0 6
+#define PFIFTY0 7
+
+#define PCTL0 _SFR_MEM8(0xDB)
+#define PRUN0 0
+#define PCCYC0 1
+#define PARUN0 2
+#define PAOC0A 3
+#define PAOC0B 4
+#define PBFM0 5
+#define PPRE00 6
+#define PPRE01 7
+
+#define PFRC0A _SFR_MEM8(0xDC)
+#define PRFM0A0 0
+#define PRFM0A1 1
+#define PRFM0A2 2
+#define PRFM0A3 3
+#define PFLTE0A 4
+#define PELEV0A 5
+#define PISEL0A 6
+#define PCAE0A 7
+
+#define PFRC0B _SFR_MEM8(0xDD)
+#define PRFM0B0 0
+#define PRFM0B1 1
+#define PRFM0B2 2
+#define PRFM0B3 3
+#define PFLTE0B 4
+#define PELEV0B 5
+#define PISEL0B 6
+#define PCAE0B 7
+
+#define PICR0 _SFR_MEM16(0xDE)
+
+#define PICR0L _SFR_MEM8(0xDE)
+#define PICR0_0 0
+#define PICR0_1 1
+#define PICR0_2 2
+#define PICR0_3 3
+#define PICR0_4 4
+#define PICR0_5 5
+#define PICR0_6 6
+#define PICR0_7 7
+
+#define PICR0H _SFR_MEM8(0xDF)
+#define PICR0_8 0
+#define PICR0_9 1
+#define PICR0_10 2
+#define PICR0_11 3
+#define PCST0 7
+
+#define PSOC1 _SFR_MEM8(0xE0)
+#define POEN1A 0
+#define POEN1B 2
+#define PSYNC1_0 4
+#define PSYNC1_1 5
+
+#define OCR1SA _SFR_MEM16(0xE2)
+
+#define OCR1SAL _SFR_MEM8(0xE2)
+#define OCR1SA_0 0
+#define OCR1SA_1 1
+#define OCR1SA_2 2
+#define OCR1SA_3 3
+#define OCR1SA_4 4
+#define OCR1SA_5 5
+#define OCR1SA_6 6
+#define OCR1SA_7 7
+
+#define OCR1SAH _SFR_MEM8(0xE3)
+#define OCR1SA_8 0
+#define OCR1SA_9 1
+#define OCR1SA_10 2
+#define OCR1SA_11 3
+
+#define OCR1RA _SFR_MEM16(0xE4)
+
+#define OCR1RAL _SFR_MEM8(0xE4)
+#define OCR1RA_0 0
+#define OCR1RA_1 1
+#define OCR1RA_2 2
+#define OCR1RA_3 3
+#define OCR1RA_4 4
+#define OCR1RA_5 5
+#define OCR1RA_6 6
+#define OCR1RA_7 7
+
+#define OCR1RAH _SFR_MEM8(0xE5)
+#define OCR1RA_8 0
+#define OCR1RA_9 1
+#define OCR1RA_10 2
+#define OCR1RA_11 3
+
+#define OCR1SB _SFR_MEM16(0xE6)
+
+#define OCR1SBL _SFR_MEM8(0xE6)
+#define OCR1SB_0 0
+#define OCR1SB_1 1
+#define OCR1SB_2 2
+#define OCR1SB_3 3
+#define OCR1SB_4 4
+#define OCR1SB_5 5
+#define OCR1SB_6 6
+#define OCR1SB_7 7
+
+#define OCR1SBH _SFR_MEM8(0xE7)
+#define OCR1SB_8 0
+#define OCR1SB_9 1
+#define OCR1SB_10 2
+#define OCR1SB_11 3
+
+#define OCR1RB _SFR_MEM16(0xE8)
+
+#define OCR1RBL _SFR_MEM8(0xE8)
+#define OCR1RB_0 0
+#define OCR1RB_1 1
+#define OCR1RB_2 2
+#define OCR1RB_3 3
+#define OCR1RB_4 4
+#define OCR1RB_5 5
+#define OCR1RB_6 6
+#define OCR1RB_7 7
+
+#define OCR1RBH _SFR_MEM8(0xE9)
+#define OCR1RB_8 0
+#define OCR1RB_9 1
+#define OCR1RB_10 2
+#define OCR1RB_11 3
+#define OCR1RB_12 4
+#define OCR1RB_13 5
+#define OCR1RB_14 6
+#define OCR1RB_15 7
+
+#define PCNF1 _SFR_MEM8(0xEA)
+#define PCLKSEL1 1
+#define POP1 2
+#define PMODE10 3
+#define PMODE11 4
+#define PLOCK1 5
+#define PALOCK1 6
+#define PFIFTY1 7
+
+#define PCTL1 _SFR_MEM8(0xEB)
+#define PRUN1 0
+#define PCCYC1 1
+#define PARUN1 2
+#define PAOC1A 3
+#define PAOC1B 4
+#define PBFM1 5
+#define PPRE10 6
+#define PPRE11 7
+
+#define PFRC1A _SFR_MEM8(0xEC)
+#define PRFM1A0 0
+#define PRFM1A1 1
+#define PRFM1A2 2
+#define PRFM1A3 3
+#define PFLTE1A 4
+#define PELEV1A 5
+#define PISEL1A 6
+#define PCAE1A 7
+
+#define PFRC1B _SFR_MEM8(0xED)
+#define PRFM1B0 0
+#define PRFM1B1 1
+#define PRFM1B2 2
+#define PRFM1B3 3
+#define PFLTE1B 4
+#define PELEV1B 5
+#define PISEL1B 6
+#define PCAE1B 7
+
+#define PICR1 _SFR_MEM16(0xEE)
+
+#define PICR1L _SFR_MEM8(0xEE)
+#define PICR1_0 0
+#define PICR1_1 1
+#define PICR1_2 2
+#define PICR1_3 3
+#define PICR1_4 4
+#define PICR1_5 5
+#define PICR1_6 6
+#define PICR1_7 7
+
+#define PICR1H _SFR_MEM8(0xEF)
+#define PICR1_8 0
+#define PICR1_9 1
+#define PICR1_10 2
+#define PICR1_11 3
+#define PCST1 7
+
+#define PSOC2 _SFR_MEM8(0xF0)
+#define POEN2A 0
+#define POEN2C 1
+#define POEN2B 2
+#define POEN2D 3
+#define PSYNC2_0 4
+#define PSYNC2_1 5
+#define POS22 6
+#define POS23 7
+
+#define POM2 _SFR_MEM8(0xF1)
+#define POMV2A0 0
+#define POMV2A1 1
+#define POMV2A2 2
+#define POMV2A3 3
+#define POMV2B0 4
+#define POMV2B1 5
+#define POMV2B2 6
+#define POMV2B3 7
+
+#define OCR2SA _SFR_MEM16(0xF2)
+
+#define OCR2SAL _SFR_MEM8(0xF2)
+#define OCR2SA_0 0
+#define OCR2SA_1 1
+#define OCR2SA_2 2
+#define OCR2SA_3 3
+#define OCR2SA_4 4
+#define OCR2SA_5 5
+#define OCR2SA_6 6
+#define OCR2SA_7 7
+
+#define OCR2SAH _SFR_MEM8(0xF3)
+#define OCR2SA_8 0
+#define OCR2SA_9 1
+#define OCR2SA_10 2
+#define OCR2SA_11 3
+
+#define OCR2RA _SFR_MEM16(0xF4)
+
+#define OCR2RAL _SFR_MEM8(0xF4)
+#define OCR2RA_0 0
+#define OCR2RA_1 1
+#define OCR2RA_2 2
+#define OCR2RA_3 3
+#define OCR2RA_4 4
+#define OCR2RA_5 5
+#define OCR2RA_6 6
+#define OCR2RA_7 7
+
+#define OCR2RAH _SFR_MEM8(0xF5)
+#define OCR2RA_8 0
+#define OCR2RA_9 1
+#define OCR2RA_10 2
+#define OCR2RA_11 3
+
+#define OCR2SB _SFR_MEM16(0xF6)
+
+#define OCR2SBL _SFR_MEM8(0xF6)
+#define OCR2SB_0 0
+#define OCR2SB_1 1
+#define OCR2SB_2 2
+#define OCR2SB_3 3
+#define OCR2SB_4 4
+#define OCR2SB_5 5
+#define OCR2SB_6 6
+#define OCR2SB_7 7
+
+#define OCR2SBH _SFR_MEM8(0xF7)
+#define OCR2SB_8 0
+#define OCR2SB_9 1
+#define OCR2SB_10 2
+#define OCR2SB_11 3
+
+#define OCR2RB _SFR_MEM16(0xF8)
+
+#define OCR2RBL _SFR_MEM8(0xF8)
+#define OCR2RB_0 0
+#define OCR2RB_1 1
+#define OCR2RB_2 2
+#define OCR2RB_3 3
+#define OCR2RB_4 4
+#define OCR2RB_5 5
+#define OCR2RB_6 6
+#define OCR2RB_7 7
+
+#define OCR2RBH _SFR_MEM8(0xF9)
+#define OCR2RB_8 0
+#define OCR2RB_9 1
+#define OCR2RB_10 2
+#define OCR2RB_11 3
+#define OCR2RB_12 4
+#define OCR2RB_13 5
+#define OCR2RB_14 6
+#define OCR2RB_15 7
+
+#define PCNF2 _SFR_MEM8(0xFA)
+#define POME2 0
+#define PCLKSEL2 1
+#define POP2 2
+#define PMODE20 3
+#define PMODE21 4
+#define PLOCK2 5
+#define PALOCK2 6
+#define PFIFTY2 7
+
+#define PCTL2 _SFR_MEM8(0xFB)
+#define PRUN2 0
+#define PCCYC2 1
+#define PARUN2 2
+#define PAOC2A 3
+#define PAOC2B 4
+#define PBFM2 5
+#define PPRE20 6
+#define PPRE21 7
+
+#define PFRC2A _SFR_MEM8(0xFC)
+#define PRFM2A0 0
+#define PRFM2A1 1
+#define PRFM2A2 2
+#define PRFM2A3 3
+#define PFLTE2A 4
+#define PELEV2A 5
+#define PISEL2A 6
+#define PCAE2A 7
+
+#define PFRC2B _SFR_MEM8(0xFD)
+#define PRFM2B0 0
+#define PRFM2B1 1
+#define PRFM2B2 2
+#define PRFM2B3 3
+#define PFLTE2B 4
+#define PELEV2B 5
+#define PISEL2B 6
+#define PCAE2B 7
+
+#define PICR2 _SFR_MEM16(0xFE)
+
+#define PICR2L _SFR_MEM8(0xFE)
+#define PICR2_0 0
+#define PICR2_1 1
+#define PICR2_2 2
+#define PICR2_3 3
+#define PICR2_4 4
+#define PICR2_5 5
+#define PICR2_6 6
+#define PICR2_7 7
+
+#define PICR2H _SFR_MEM8(0xFF)
+#define PICR2_8 0
+#define PICR2_9 1
+#define PICR2_10 2
+#define PICR2_11 3
+#define PCST2 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt vector 0 is the reset vector. */
+#define PSC2_CAPT_vect _VECTOR(1) /* PSC2 Capture Event */
+#define PSC2_EC_vect _VECTOR(2) /* PSC2 End Cycle */
+#define PSC1_CAPT_vect _VECTOR(3) /* PSC1 Capture Event */
+#define PSC1_EC_vect _VECTOR(4) /* PSC1 End Cycle */
+#define PSC0_CAPT_vect _VECTOR(5) /* PSC0 Capture Event */
+#define PSC0_EC_vect _VECTOR(6) /* PSC0 End Cycle */
+#define ANALOG_COMP_0_vect _VECTOR(7) /* Analog Comparator 0 */
+#define ANALOG_COMP_1_vect _VECTOR(8) /* Analog Comparator 1 */
+#define ANALOG_COMP_2_vect _VECTOR(9) /* Analog Comparator 2 */
+#define INT0_vect _VECTOR(10) /* External Interrupt Request 0 */
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter Compare Match B */
+/* Vector 14, Reserved */
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(16) /* Timer/Counter0 Compare Match A */
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define ADC_vect _VECTOR(18) /* ADC Conversion Complete */
+#define INT1_vect _VECTOR(19) /* External Interrupt Request 1 */
+#define SPI_STC_vect _VECTOR(20) /* SPI Serial Transfer Complete */
+#define USART_RX_vect _VECTOR(21) /* USART, Rx Complete */
+#define USART_UDRE_vect _VECTOR(22) /* USART Data Register Empty */
+#define USART_TX_vect _VECTOR(23) /* USART, Tx Complete */
+#define INT2_vect _VECTOR(24) /* External Interrupt Request 2 */
+#define WDT_vect _VECTOR(25) /* Watchdog Timeout Interrupt */
+#define EE_READY_vect _VECTOR(26) /* EEPROM Ready */
+#define TIMER0_COMPB_vect _VECTOR(27) /* Timer Counter 0 Compare Match B */
+#define INT3_vect _VECTOR(28) /* External Interrupt Request 3 */
+/* Vector 29, Reserved */
+/* Vector 30, Reserved */
+#define SPM_READY_vect _VECTOR(31) /* Store Program Memory Read */
+
+#define _VECTORS_SIZE 64
+
+
+
+/* Memory Sizes */
+#define RAMEND 0x2FF
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+#define SPM_PAGESIZE 32
+
+
+
+/* Fuse Information */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown out detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_PSCRV (unsigned char)~_BV(4) /* PSCOUT Reset Value */
+#define FUSE_PSC0RB (unsigned char)~_BV(5) /* PSC0 Reset Behaviour */
+#define FUSE_PSC1RB (unsigned char)~_BV(6) /* PSC1 Reset Behaviour */
+#define FUSE_PSC2RB (unsigned char)~_BV(7) /* PSC2 Reset Behaviour */
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x83
+
+
+#endif /* _AVR_IO90PWM2B_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90pwm316.h b/cpukit/score/cpu/avr/avr/io90pwm316.h
new file mode 100644
index 0000000000..f4f27f3ee3
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwm316.h
@@ -0,0 +1,1224 @@
+/* Copyright (c) 2007, Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io90pwm316.h - definitions for AT90PWM316 */
+
+#ifndef _AVR_IO90PWM316_H_
+#define _AVR_IO90PWM316_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90pwm316.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Port B Input Pins Address */
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+/* Port B Data Direction Register */
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+/* Port B Data Register */
+#define PORTB _SFR_IO8(0x05)
+#define PB0 0
+#define PB1 1
+#define PB2 2
+#define PB3 3
+#define PB4 4
+#define PB5 5
+#define PB6 6
+#define PB7 7
+
+/* Port C Input Pins Address */
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+/* Port C Data Direction Register */
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+/* Port C Data Register */
+#define PORTC _SFR_IO8(0x08)
+#define PC0 0
+#define PC1 1
+#define PC2 2
+#define PC3 3
+#define PC4 4
+#define PC5 5
+#define PC6 6
+#define PC7 7
+
+/* Port D Input Pins Address */
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+/* Port D Data Direction Register */
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+/* Port D Data Register */
+#define PORTD _SFR_IO8(0x0B)
+#define PD0 0
+#define PD1 1
+#define PD2 2
+#define PD3 3
+#define PD4 4
+#define PD5 5
+#define PD6 6
+#define PD7 7
+
+/* Port E Input Pins Address */
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+/* Port E Data Direction Register */
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+/* Port E Data Register */
+#define PORTE _SFR_IO8(0x0E)
+#define PE0 0
+#define PE1 1
+#define PE2 2
+
+/* Timer/Counter 0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0 /* Overflow Flag */
+#define OCF0A 1 /* Output Compare Flag 0A */
+#define OCF0B 2 /* Output Compare Flag 0B */
+
+/* Timer/Counter1 Interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0 /* Overflow Flag */
+#define OCF1A 1 /* Output Compare Flag 1A*/
+#define OCF1B 2 /* Output Compare Flag 1B*/
+#define ICF1 5 /* Input Capture Flag 1 */
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+/* General Purpose I/O Register 3 */
+#define GPIOR3 _SFR_IO8(0x1B)
+#define GPIOR30 0
+#define GPIOR31 1
+#define GPIOR32 2
+#define GPIOR33 3
+#define GPIOR34 4
+#define GPIOR35 5
+#define GPIOR36 6
+#define GPIOR37 7
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0 /* External Interrupt Request 0 Enable */
+#define INT1 1 /* External Interrupt Request 1 Enable */
+#define INT2 2 /* External Interrupt Request 2 Enable */
+#define INT3 3 /* External Interrupt Request 3 Enable */
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0 /* EEPROM Read Enable */
+#define EEWE 1 /* EEPROM Write Enable */
+#define EEMWE 2 /* EEPROM Master Write Enable */
+#define EERIE 3 /* EEPROM Ready Interrupt Enable */
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+/* The EEPROM Address Registers */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0 /* Prescaler Reset Timer/Counter1 and Timer/Counter0 */
+#define ICPSEL1 6 /* Timer1 Input Capture Selection Bit */
+#define TSM 7 /* Timer/Counter Synchronization Mode */
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0 /* Waveform Generation Mode */
+#define WGM01 1 /* Waveform Generation Mode */
+#define COM0B0 4 /* Compare Output Mode, Fast PWm */
+#define COM0B1 5 /* Compare Output Mode, Fast PWm */
+#define COM0A0 6 /* Compare Output Mode, Phase Correct PWM Mode */
+#define COM0A1 7 /* Compare Output Mode, Phase Correct PWM Mode */
+
+/* Timer/Counter Control Register B */
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0 /* Clock Select */
+#define CS01 1 /* Clock Select */
+#define CS02 2 /* Clock Select */
+#define WGM02 3 /* Waveform Generation Mode */
+#define FOC0B 6 /* Force Output Compare B */
+#define FOC0A 7 /* Force Output Compare A */
+
+/* Timer/Counter0 Register */
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT00 0
+#define TCNT01 1
+#define TCNT02 2
+#define TCNT03 3
+#define TCNT04 4
+#define TCNT05 5
+#define TCNT06 6
+#define TCNT07 7
+
+/* Timer/Counter0 Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+/* Timer/Counter0 Output Compare Register B */
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B0 0
+#define OCR0B1 1
+#define OCR0B2 2
+#define OCR0B3 3
+#define OCR0B4 4
+#define OCR0B5 5
+#define OCR0B6 6
+#define OCR0B7 7
+
+/* PLL Control and Status Register */
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0 /* PLL Lock Detector */
+#define PLLE 1 /* PLL Enable */
+#define PLLF 2 /* PLL Factor */
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0 /* SPI Clock Rate Select 0 */
+#define SPR1 1 /* SPI Clock Rate Select 1 */
+#define CPHA 2 /* Clock Phase */
+#define CPOL 3 /* Clock polarity */
+#define MSTR 4 /* Master/Slave Select */
+#define DORD 5 /* Data Order */
+#define SPE 6 /* SPI Enable */
+#define SPIE 7 /* SPI Interrupt Enable */
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0 /* Double SPI Speed Bit */
+#define WCOL 6 /* Write Collision Flag */
+#define SPIF 7 /* SPI Interrupt Flag */
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+#define SPD0 0
+#define SPD1 1
+#define SPD2 2
+#define SPD3 3
+#define SPD4 4
+#define SPD5 5
+#define SPD6 6
+#define SPD7 7
+
+/* Analog Comparator Status Register */
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0 /* Analog Comparator 0 Output Bit */
+#define AC1O 1 /* Analog Comparator 1 Output Bit */
+#define AC2O 2 /* Analog Comparator 2 Output Bit */
+#define AC0IF 4 /* Analog Comparator 0 Interrupt Flag Bit */
+#define AC1IF 5 /* Analog Comparator 1 Interrupt Flag Bit */
+#define AC2IF 6 /* Analog Comparator 2 Interrupt Flag Bit */
+#define ACCKDIV 7 /* Analog Comparator Clock Divider */
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+#define SE 0 /* Sleep Enable */
+#define SM0 1 /* Sleep Mode Select bit0 */
+#define SM1 2 /* Sleep Mode Select bit1 */
+#define SM2 3 /* Sleep Mode Select bit2 */
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0 /* Power-on reset flag */
+#define EXTRF 1 /* External Reset Flag */
+#define BORF 2 /* Brown-out Reset Flag */
+#define WDRF 3 /* Watchdog Reset Flag */
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0 /* Interrupt Vector Change Enable */
+#define IVSEL 1 /* Interrupt Vector Select */
+#define PUD 4 /* Pull-up disable */
+#define SPIPS 7 /* SPI Pin Select */
+
+/* Store Program Memory Control Register */
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0 /* Store Program Memory Enable */
+#define PGERS 1 /* Page Erase */
+#define PGWRT 2 /* Page Write */
+#define BLBSET 3 /* Boot Lock Bit Set */
+#define RWWSRE 4 /* Read While Write section read enable */
+#define RWWSB 6 /* Read While Write Section Busy */
+#define SPMIE 7 /* SPM Interrupt Enable */
+
+/* Watchdog Timer Control Register */
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0 /* Watchdog Timer Prescaler bit0 */
+#define WDP1 1 /* Watchdog Timer Prescaler bit1 */
+#define WDP2 2 /* Watchdog Timer Prescaler bit2 */
+#define WDE 3 /* Watchdog Enable */
+#define WDCE 4 /* Watchdog Change Enable */
+#define WDP3 5 /* Watchdog Timer Prescaler bit3 */
+#define WDIE 6 /* Watchdog Timeout Interrupt Enable */
+#define WDIF 7 /* Watchdog Timeout Interrupt Flag */
+
+/* Clock Prescaler Register */
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0 /* Clock Prescaler Select bit0 */
+#define CLKPS1 1 /* Clock Prescaler Select bit1 */
+#define CLKPS2 2 /* Clock Prescaler Select bit2 */
+#define CLKPS3 3 /* Clock Prescaler Select bit3 */
+#define CLKPCE 7 /* Clock Prescaler Change Enable */
+
+/* Power Reduction Register */
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0 /* Power Reduction ADC */
+#define PRUSART 1 /* Power Reduction USART */
+#define PRSPI 2 /* Power Reduction Serial Peripheral Interface */
+#define PRTIM0 3 /* Power Reduction Timer/Counter0 */
+#define PRTIM1 4 /* Power Reduction Timer/Counter1 */
+#define PRPSC0 5 /* Power Reduction PSC0 */
+#define PRPSC1 6 /* Power Reduction PSC1 */
+#define PRPSC2 7 /* Power Reduction PSC2 */
+
+/* Oscillator Calibration Value */
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+/* Timer/Counter0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0 /* Overflow Interrupt Enable */
+#define OCIE0A 1 /* Output Compare Match A Interrupt Enable */
+#define OCIE0B 2 /* Output Compare Match B Interrupt Enable */
+
+/* Timer/Counter1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0 /* Overflow Interrupt Enable */
+#define OCIE1A 1 /* Output Compare Match A Interrupt Enable */
+#define OCIE1B 2 /* Output Compare Match B Interrupt Enable */
+#define ICIE1 5 /* Input Capture Interrupt Enable */
+
+/* Amplifier 0 Control and Status register */
+#define AMP0CSR _SFR_MEM8(0x76)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+/* Amplifier 1 Control and Status register */
+#define AMP1CSR _SFR_MEM8(0x77)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+/* ADC Result Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0 /* ADC Prescaler Select bit0 */
+#define ADPS1 1 /* ADC Prescaler Select bit1 */
+#define ADPS2 2 /* ADC Prescaler Select bit2 */
+#define ADIE 3 /* ADC Interrupt Enable */
+#define ADIF 4 /* ADC Interrupt Flag */
+#define ADATE 5 /* ADC Auto Trigger Enable */
+#define ADSC 6 /* ADC Start Conversion */
+#define ADEN 7 /* ADC Enable */
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0 /* ADC Auto Trigger Source 0 */
+#define ADTS1 1 /* ADC Auto Trigger Source 1 */
+#define ADTS2 2 /* ADC Auto Trigger Source 2 */
+#define ADTS3 3 /* ADC Auto Trigger Source 3 */
+#define ADHSM 7 /* ADC High Speed Mode */
+
+/* ADC multiplexer Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0 /* Analog Channel and Gain Selection bit0 */
+#define MUX1 1 /* Analog Channel and Gain Selection bit1 */
+#define MUX2 2 /* Analog Channel and Gain Selection bit2 */
+#define MUX3 3 /* Analog Channel and Gain Selection bit3 */
+#define ADLAR 5 /* Left Adjust Result */
+#define REFS0 6 /* Reference Selection bit0 */
+#define REFS1 7 /* Reference Selection bit1 */
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0 /* ADC0 Digital input Disable */
+#define ADC1D 1 /* ADC1 Digital input Disable */
+#define ADC2D 2 /* ADC2 Digital input Disable */
+#define ADC3D 3 /* ADC3 Digital input Disable */
+#define ADC4D 4 /* ADC4 Digital input Disable */
+#define ADC5D 5 /* ADC5 Digital input Disable */
+#define ADC6D 6 /* ADC6 Digital input Disable */
+#define ADC7D 7 /* ADC7 Digital input Disable */
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0 /* ADC8 Digital input Disable */
+#define ADC9D 1 /* ADC9 Digital input Disable */
+#define ADC10D 2 /* ADC10 Digital input Disable */
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0 /* Waveform Generation Mode */
+#define WGM11 1 /* Waveform Generation Mode */
+#define COM1B0 4 /* Compare Output Mode 1B, bit 0 */
+#define COM1B1 5 /* Compare Output Mode 1B, bit 1 */
+#define COM1A0 6 /* Comparet Ouput Mode 1A, bit 0 */
+#define COM1A1 7 /* Comparet Ouput Mode 1A, bit 1 */
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0 /* Prescaler source of Timer/Counter 1 */
+#define CS11 1 /* Prescaler source of Timer/Counter 1 */
+#define CS12 2 /* Prescaler source of Timer/Counter 1 */
+#define WGM12 3 /* Waveform Generation Mode */
+#define WGM13 4 /* Waveform Generation Mode */
+#define ICES1 6 /* Input Capture 1 Edge Select */
+#define ICNC1 7 /* Input Capture 1 Noise Canceler */
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6 /* Force Output Compare for Channel B */
+#define FOC1A 7 /* Force Output Compare for Channel A */
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT10 0
+#define TCNT11 1
+#define TCNT12 2
+#define TCNT13 3
+#define TCNT14 4
+#define TCNT15 5
+#define TCNT16 6
+#define TCNT17 7
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT18 0
+#define TCNT19 1
+#define TCNT110 2
+#define TCNT111 3
+#define TCNT112 4
+#define TCNT113 5
+#define TCNT114 6
+#define TCNT115 7
+
+/* Input Capture Register 1 */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR17 7
+#define ICR16 6
+#define ICR15 5
+#define ICR14 4
+#define ICR13 3
+#define ICR12 2
+#define ICR11 1
+#define ICR10 0
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR115 7
+#define ICR114 6
+#define ICR113 5
+#define ICR112 4
+#define ICR111 3
+#define ICR110 2
+#define ICR19 1
+#define ICR18 0
+
+/* Output Compare Register 1 A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1A8 0
+#define OCR1A9 1
+#define OCR1A10 2
+#define OCR1A11 3
+#define OCR1A12 4
+#define OCR1A13 5
+#define OCR1A14 6
+#define OCR1A15 7
+
+/* Output Compare Register 1 B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1B8 0
+#define OCR1B9 1
+#define OCR1B10 2
+#define OCR1B11 3
+#define OCR1B12 4
+#define OCR1B13 5
+#define OCR1B14 6
+#define OCR1B15 7
+
+/* PSC0 Interrupt Flag Register */
+#define PIFR0 _SFR_MEM8(0xA0)
+#define PEOP0 0 /* End Of PSC0 Interrupt */
+#define PRN00 1 /* PSC0 Ramp Number bit0 */
+#define PRN01 2 /* PSC0 Ramp Number bit1 */
+#define PEV0A 3 /* PSC0 External Event A Interrupt */
+#define PEV0B 4 /* PSC0 External Event B Interrupt */
+#define PSEI0 5 /* PSC0 Synchro Error Interrupt */
+#define POAC0A 6 /* PSC0 Output A Activity */
+#define POAC0B 7 /* PSC0 Output B Activity */
+
+/* PSC0 Interrupt Mask Register */
+#define PIM0 _SFR_MEM8(0xA1)
+#define PEOPE0 0 /* PSC0 End Of Cycle Interrupt Enable */
+#define PEVE0A 3 /* PSC0 External Event A Interrupt Enable */
+#define PEVE0B 4 /* PSC0 External Event B Interrupt Enable */
+#define PSEIE0 5 /* PSC0 Synchro Error Interrupt Enable */
+
+/* PSC1 Interrupt Flag Register */
+#define PIFR1 _SFR_MEM8(0xA2)
+#define PEOP1 0
+#define PRN10 1
+#define PRN11 2
+#define PEV1A 3
+#define PEV1B 4
+#define PSEI1 5
+#define POAC1A 6
+#define POAC1B 7
+
+/* PSC1 Interrupt Mask Register */
+#define PIM1 _SFR_MEM8(0xA3)
+
+/* PSC2 Interrupt Flag Register */
+#define PIFR2 _SFR_MEM8(0xA4)
+#define PEOP2 0 /* End Of PSC2 Interrupt */
+#define PRN20 1 /* PSC2 Ramp Number bit0 */
+#define PRN21 2 /* PSC2 Ramp Number bit1 */
+#define PEV2A 3 /* PSC2 External Event A Interrupt */
+#define PEV2B 4 /* PSC2 External Event B Interrupt */
+#define PSEI2 5 /* PSC2 Synchro Error Interrupt */
+#define POAC2A 6 /* PSC2 Output A Activity */
+#define POAC2B 7 /* PSC2 Output B Activity */
+
+/* PSC2 Interrupt Mask Register */
+#define PIM2 _SFR_MEM8(0xA5)
+#define PEOPE2 0 /* PSC2 End Of Cycle Interrupt Enable */
+#define PEVE2A 3 /* PSC2 External Event A Interrupt Enable */
+#define PEVE2B 4 /* PSC2 External Event B Interrupt Enable */
+#define PSEIE2 5 /* PSC2 Synchro Error Interrupt Enable */
+
+/* Digital to Analog Conversion Control Register */
+#define DACON _SFR_MEM8(0xAA)
+#define DAEN 0 /* Digital to Analog Enable bit */
+#define DAOE 1 /* Digital to Analog Output Enable bit */
+#define DALA 2 /* Digital to Analog Left Adjust */
+#define DATS0 4 /* DAC Trigger Selection bit0 */
+#define DATS1 5 /* DAC Trigger Selection bit1 */
+#define DATS2 6 /* DAC Trigger Selection bit2 */
+#define DAATE 7 /* DAC Auto Trigger Enable bit */
+
+/* Digital to Analog Converter input Register */
+#define DAC _SFR_MEM16(0xAB)
+#define DACL _SFR_MEM8(0xAB)
+#define DACH _SFR_MEM8(0xAC)
+
+/* Analog Comparator 0 Control Register */
+#define AC0CON _SFR_MEM8(0xAD)
+#define AC0M0 0 /* Analog Comparator 0 Multiplexer register bit0 */
+#define AC0M1 1 /* Analog Comparator 0 Multiplexer register bit1 */
+#define AC0M2 2 /* Analog Comparator 0 Multiplexer register bit2 */
+#define AC0IS0 4 /* Analog Comparator 0 Interrupt Select bit0 */
+#define AC0IS1 5 /* Analog Comparator 0 Interrupt Select bit1 */
+#define AC0IE 6 /* Analog Comparator 0 Interrupt Enable bit */
+#define AC0EN 7 /* Analog Comparator 0 Enable Bit */
+
+/* Analog Comparator 1 Control Register */
+#define AC1CON _SFR_MEM8(0xAE)
+#define AC1M0 0 /* Analog Comparator 1 Multiplexer register bit0 */
+#define AC1M1 1 /* Analog Comparator 1 Multiplexer register bit1 */
+#define AC1M2 2 /* Analog Comparator 1 Multiplexer register bit2 */
+#define AC1ICE 3 /* Analog Comparator 1 Interrupt Capture Enable bit */
+#define AC1IS0 4 /* Analog Comparator 1 Interrupt Select bit0 */
+#define AC1IS1 5 /* Analog Comparator 1 Interrupt Select bit1 */
+#define AC1IE 6 /* Analog Comparator 1 Interrupt Enable bit */
+#define AC1EN 7 /* Analog Comparator 1 Enable Bit */
+
+/* Analog Comparator 2 Control Register */
+#define AC2CON _SFR_MEM8(0xAF)
+#define AC2M0 0 /* Analog Comparator 2 Multiplexer register bit0 */
+#define AC2M1 1 /* Analog Comparator 2 Multiplexer register bit1 */
+#define AC2M2 2 /* Analog Comparator 2 Multiplexer register bit2 */
+#define AC2IS0 4 /* Analog Comparator 2 Interrupt Select bit0 */
+#define AC2IS1 5 /* Analog Comparator 2 Interrupt Select bit1 */
+#define AC2IE 6 /* Analog Comparator 2 Interrupt Enable bit */
+#define AC2EN 7 /* Analog Comparator 2 Enable Bit */
+
+/* USART Control and Status Register A */
+#define UCSRA _SFR_MEM8(0xC0)
+#define MPCM 0 /* Multi-processor Communication Mode */
+#define U2X 1 /* Double the USART Transmission Speed */
+#define UPE 2 /* USART Parity Error */
+#define DOR 3 /* Data OverRun */
+#define FE 4 /* Frame Error */
+#define UDRE 5 /* USART Data Register Empty */
+#define TXC 6 /* USART Transmit Complete */
+#define RXC 7 /* USART Receive Complete */
+
+/* USART Control and Status Register B */
+#define UCSRB _SFR_MEM8(0xC1)
+#define TXB8 0 /* Transmit Data Bit 8 */
+#define RXB8 1 /* Receive Data Bit 8 */
+#define UCSZ2 2 /* Character Size */
+#define TXEN 3 /* Transmitter Enable */
+#define RXEN 4 /* Receiver Enable */
+#define UDRIE 5 /* USART Data Register Empty Interrupt Enable */
+#define TXCIE 6 /* TX Complete Interrupt Enable */
+#define RXCIE 7 /* RX Complete Interrupt Enable */
+
+/* USART Control and Status Register C */
+#define UCSRC _SFR_MEM8(0xC2)
+#define UCPOL 0 /* Clock Polarity */
+#define UCSZ0 1 /* Character Size bit0 */
+#define UCSZ1 2 /* Character Size bit1 */
+#define USBS 3 /* Stop Bit Select */
+#define UPM0 4 /* Parity Mode bit0 */
+#define UPM1 5 /* Parity Mode bit1 */
+#define UMSEL 6 /* USART Mode Select */
+
+/* USART Baud Rate Register */
+#define UBRR _SFR_MEM16(0xC4)
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRRH _SFR_MEM8(0xC5)
+
+/* USART I/O Data Register */
+#define UDR _SFR_MEM8(0xC6)
+
+/* EUSART Control and Status Register A */
+#define EUCSRA _SFR_MEM8(0xC8)
+#define URxS0 0 /* EUSART Receive Character Size bit0 */
+#define URxS1 1 /* EUSART Receive Character Size bit1 */
+#define URxS2 2 /* EUSART Receive Character Size bit2 */
+#define URxS3 3 /* EUSART Receive Character Size bit3 */
+#define UTxS0 4 /* EUSART Transmit Character Size bit0 */
+#define UTxS1 5 /* EUSART Transmit Character Size bit1 */
+#define UTxS2 6 /* EUSART Transmit Character Size bit2 */
+#define UTxS3 7 /* EUSART Transmit Character Size bit3 */
+
+/* EUSART Control and Status Register B */
+#define EUCSRB _SFR_MEM8(0xC9)
+#define BODR 0 /* Bit Order */
+#define EMCH 1 /* Manchester mode */
+#define EUSBS 3 /* EUSBS Enable Bit */
+#define EUSART 4 /* EUSART Enable Bit */
+
+/* EUSART Control and Status Register C */
+#define EUCSRC _SFR_MEM8(0xCA)
+#define STP0 0 /* Stop bits values bit0 */
+#define STP1 1 /* Stop bits values bit1 */
+#define F1617 2
+#define FEM 3 /* Frame Error Manchester */
+
+/* Manchester receiver Baud Rate Registers */
+#define MUBRR _SFR_MEM16(0xCC)
+#define MUBRRL _SFR_MEM8(0xCC)
+#define MUBRRH _SFR_MEM8(0xCD)
+
+/* EUSART I/O Data Register */
+#define EUDR _SFR_MEM8(0xCE)
+
+/* PSC 0 Synchro and Output Configuration */
+#define PSOC0 _SFR_MEM8(0xD0)
+#define POEN0A 0 /* PSC 0 OUT Part A Output Enable */
+#define POEN0B 2 /* PSC 0 OUT Part B Output Enable */
+#define PSYNC00 4 /* Synchronization Out for ADC Selection bit0 */
+#define PSYNC01 5 /* Synchronization Out for ADC Selection bit1 */
+
+/* Output Compare SA Registers */
+#define OCR0SA _SFR_MEM16(0xD2)
+#define OCR0SAL _SFR_MEM8(0xD2)
+#define OCR0SAH _SFR_MEM8(0xD3)
+
+/* Output Compare RA Registers */
+#define OCR0RA _SFR_MEM16(0xD4)
+#define OCR0RAL _SFR_MEM8(0xD4)
+#define OCR0RAH _SFR_MEM8(0xD5)
+
+/* Output Compare SB Registers */
+#define OCR0SB _SFR_MEM16(0xD6)
+#define OCR0SBL _SFR_MEM8(0xD6)
+#define OCR0SBH _SFR_MEM8(0xD7)
+
+/* Output Compare RB Registers */
+#define OCR0RB _SFR_MEM16(0xD8)
+#define OCR0RBL _SFR_MEM8(0xD8)
+#define OCR0RBH _SFR_MEM8(0xD9)
+
+/* PSC 0 Configuration Register */
+#define PCNF0 _SFR_MEM8(0xDA)
+#define PCLKSEL0 1 /* PSC 0 Input Clock Select */
+#define POP0 2 /* PSC 0 Output Polarity */
+#define PMODE00 3 /* PSC 0 Mode bit0 */
+#define PMODE01 4 /* PSC 0 Mode bit1 */
+#define PLOCK0 5 /* PSC 0 Lock */
+#define PALOCK0 6 /* PSC 0 Autolock */
+#define PFIFTY0 7 /* PSC 0 Fifty */
+
+/* PSC 0 Control Register */
+#define PCTL0 _SFR_MEM8(0xDB)
+#define PRUN0 0 /* PSC 0 Run */
+#define PCCYC0 1 /* PSC 0 Complete Cycle */
+#define PARUN0 2 /* PSC 0 Autorun */
+#define PAOC0A 3 /* PSC 0 Asynchronous Output Control A */
+#define PAOC0B 4 /* PSC 0 Asynchronous Output Control B */
+#define PBFM0 5 /* Balance Flank Width Modulation */
+#define PPRE00 6 /* PSC 0 Prescaler Select bit0 */
+#define PPRE01 7 /* PSC 0 Prescaler Select bit1 */
+
+/* PSC 0 Input A Control Register */
+#define PFRC0A _SFR_MEM8(0xDC)
+#define PRFM0A0 0 /* PSC 0 Fault Mode bit0 */
+#define PRFM0A1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0A2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0A3 3 /* PSC 0 Fault Mode bit3 */
+#define PFLTE0A 4 /* PSC 0 Filter Enable on Input Part A */
+#define PELEV0A 5 /* PSC 0 Edge Level Selector of Input Part A */
+#define PISEL0A 6 /* PSC 0 Input Select for Part A */
+#define PCAE0A 7 /* PSC 0 Capture Enable Input Part A */
+
+/* PSC 0 Input B Control Register */
+#define PFRC0B _SFR_MEM8(0xDD)
+#define PRFM0B0 0 /* PSC 0 Fault Mode bit0 */
+#define PRFM0B1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0B2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0B3 3 /* PSC 0 Fault Mode bit3 */
+#define PFLTE0B 4 /* PSC 0 Filter Enable on Input Part B */
+#define PELEV0B 5 /* PSC 0 Edge Level Selector of Input Part B */
+#define PISEL0B 6 /* PSC 0 Input Select for Part B */
+#define PCAE0B 7 /* PSC 0 Capture Enable Input Part B */
+
+/* PSC 0 Input Capture Registers */
+#define PICR0 _SFR_MEM16(0xDE)
+#define PICR0L _SFR_MEM8(0xDE)
+#define PICR0H _SFR_MEM8(0xDF)
+#define PCST0 7 /* PSC Capture Software Trig bit */
+
+/* PSC 1 Synchro and Output Configuration */
+#define PSOC1 _SFR_MEM8(0xE0)
+#define POEN1A 0
+#define POEN1B 2
+#define PSYNC1_0 4
+#define PSYNC1_1 5
+
+/* Output Compare SA Registers */
+#define OCR1SA _SFR_MEM16(0xE2)
+#define OCR1SAL _SFR_MEM8(0xE2)
+#define OCR1SAH _SFR_MEM8(0xE3)
+
+/* Output Compare RA Registers */
+#define OCR1RA _SFR_MEM16(0xE4)
+#define OCR1RAL _SFR_MEM8(0xE4)
+#define OCR1RAH _SFR_MEM8(0xE5)
+
+/* Output Compare SB Registers */
+#define OCR1SB _SFR_MEM16(0xE6)
+#define OCR1SBL _SFR_MEM8(0xE6)
+#define OCR1SBH _SFR_MEM8(0xE7)
+
+/* Output Compare RB Registers */
+#define OCR1RB _SFR_MEM16(0xE8)
+#define OCR1RBL _SFR_MEM8(0xE8)
+#define OCR1RBH _SFR_MEM8(0xE9)
+
+/* PSC 1 Configuration Register */
+#define PCNF1 _SFR_MEM8(0xEA)
+#define PCLKSEL1 1
+#define POP1 2
+#define PMODE10 3
+#define PMODE11 4
+#define PLOCK1 5
+#define PALOCK1 6
+#define PFIFTY1 7
+
+/* PSC 1 Control Register */
+#define PCTL1 _SFR_MEM8(0xEB)
+#define PRUN1 0
+#define PCCYC1 1
+#define PARUN1 2
+#define PAOC1A 3
+#define PAOC1B 4
+#define PBFM1 5
+#define PPRE10 6
+#define PPRE11 7
+
+/* PSC 1 Input A Control Register */
+#define PFRC1A _SFR_MEM8(0xEC)
+#define PRFM1A0 0
+#define PRFM1A1 1
+#define PRFM1A2 2
+#define PRFM1A3 3
+#define PFLTE1A 4
+#define PELEV1A 5
+#define PISEL1A 6
+#define PCAE1A 7
+
+/* PSC 1 Input B Control Register */
+#define PFRC1B _SFR_MEM8(0xED)
+#define PRFM1B0 0
+#define PRFM1B1 1
+#define PRFM1B2 2
+#define PRFM1B3 3
+#define PFLTE1B 4
+#define PELEV1B 5
+#define PISEL1B 6
+#define PCAE1B 7
+
+/* PSC 1 Input Capture Registers */
+#define PICR1 _SFR_MEM16(0xEE)
+#define PICR1L _SFR_MEM8(0xEE)
+#define PICR1H _SFR_MEM8(0xEF)
+
+/* PSC 2 Synchro and Output Configuration */
+#define PSOC2 _SFR_MEM8(0xF0)
+#define POEN2A 0 /* PSC 2 OUT Part A Output Enable */
+#define POEN2C 1 /* PSCOUT22 Output Enable */
+#define POEN2B 2 /* PSC 2 OUT Part B Output Enable */
+#define POEN2D 3 /* PSCOUT23 Output Enable */
+#define PSYNC20 4 /* Synchronization Out for ADC Selection bit0 */
+#define PSYNC21 5 /* Synchronization Out for ADC Selection bit1 */
+#define POS22 6 /* PSCOUT22 Selection */
+#define POS23 7 /* PSCOUT23 Selection */
+
+/* PSC 2 Output Matrix */
+#define POM2 _SFR_MEM8(0xF1)
+#define POMV2A0 0 /* Output Matrix Output A Ramp 0 */
+#define POMV2A1 1 /* Output Matrix Output A Ramp 1 */
+#define POMV2A2 2 /* Output Matrix Output A Ramp 2 */
+#define POMV2A3 3 /* Output Matrix Output A Ramp 3 */
+#define POMV2B0 4 /* Output Matrix Output B Ramp 0 */
+#define POMV2B1 5 /* Output Matrix Output B Ramp 1 */
+#define POMV2B2 6 /* Output Matrix Output B Ramp 2 */
+#define POMV2B3 7 /* Output Matrix Output B Ramp 3 */
+
+/* Output Compare SA Registers */
+#define OCR2SA _SFR_MEM16(0xF2)
+#define OCR2SAL _SFR_MEM8(0xF2)
+#define OCR2SAH _SFR_MEM8(0xF3)
+
+/* Output Compare RA Registers */
+#define OCR2RA _SFR_MEM16(0xF4)
+#define OCR2RAL _SFR_MEM8(0xF4)
+#define OCR2RAH _SFR_MEM8(0xF5)
+
+/* Output Compare SB Registers */
+#define OCR2SB _SFR_MEM16(0xF6)
+#define OCR2SBL _SFR_MEM8(0xF6)
+#define OCR2SBH _SFR_MEM8(0xF7)
+
+/* Output Compare RB Registers */
+#define OCR2RB _SFR_MEM16(0xF8)
+#define OCR2RBL _SFR_MEM8(0xF8)
+#define OCR2RBH _SFR_MEM8(0xF9)
+
+/* PSC 2 Configuration Register */
+#define PCNF2 _SFR_MEM8(0xFA)
+#define POME2 0 /* PSC 2 Output Matrix Enable */
+#define PCLKSEL2 1 /* PSC 2 Input Clock Select */
+#define POP2 2 /* PSC 2 Output Polarity */
+#define PMODE20 3 /* PSC 2 Mode bit0 */
+#define PMODE21 4 /* PSC 2 Mode bit1 */
+#define PLOCK2 5 /* PSC 2 Lock */
+#define PALOCK2 6 /* PSC 2 Autolock */
+#define PFIFTY2 7 /* PSC 2 Fifty */
+
+/* PSC 2 Control Register */
+#define PCTL2 _SFR_MEM8(0xFB)
+#define PRUN2 0 /* PSC 2 Run */
+#define PCCYC2 1 /* PSC 2 Complete Cycle */
+#define PARUN2 2 /* PSC 2 Autorun */
+#define PAOC2A 3 /* PSC 2 Asynchronous Output Control A */
+#define PAOC2B 4 /* PSC 2 Asynchronous Output Control B */
+#define PBFM2 5 /* Balance Flank Width Modulation */
+#define PPRE20 6 /* PSC 2 Prescaler Select bit0 */
+#define PPRE21 7 /* PSC 2 Prescaler Select bit1 */
+
+/* PSC 2 Input A Control Register */
+#define PFRC2A _SFR_MEM8(0xFC)
+#define PRFM2A0 0 /* PSC 2 Fault Mode bit0 */
+#define PRFM2A1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2A2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2A3 3 /* PSC 2 Fault Mode bit3 */
+#define PFLTE2A 4 /* PSC 2 Filter Enable on Input Part A */
+#define PELEV2A 5 /* PSC 2 Edge Level Selector of Input Part A */
+#define PISEL2A 6 /* PSC 2 Input Select for Part A */
+#define PCAE2A 7 /* PSC 2 Capture Enable Input Part A */
+
+/* PSC 2 Input B Control Register */
+#define PFRC2B _SFR_MEM8(0xFD)
+#define PRFM2B0 0 /* PSC 2 Fault Mode bit0 */
+#define PRFM2B1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2B2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2B3 3 /* PSC 2 Fault Mode bit3 */
+#define PFLTE2B 4 /* PSC 2 Filter Enable on Input Part B */
+#define PELEV2B 5 /* PSC 2 Edge Level Selector of Input Part B */
+#define PISEL2B 6 /* PSC 2 Input Select for Part B */
+#define PCAE2B 7 /* PSC 2 Capture Enable Input Part B */
+
+/* PSC 2 Input Capture Registers */
+#define PICR2 _SFR_MEM16(0xFE)
+#define PICR2L _SFR_MEM8(0xFE)
+#define PICR2H _SFR_MEM8(0xFF)
+#define PCST2 7 /* PSC Capture Software Trig bit */
+
+
+/* Interrupt Vectors */
+/* Interrupt 0 is the reset vector. */
+
+/* PSC2 Capture Event */
+#define PSC2_CAPT_vect _VECTOR(1)
+
+/* PSC2 End Cycle */
+#define PSC2_EC_vect _VECTOR(2)
+
+/* PSC1 Capture Event */
+#define PSC1_CAPT_vect _VECTOR(3)
+
+/* PSC1 End Cycle */
+#define PSC1_EC_vect _VECTOR(4)
+
+/* PSC0 Capture Event */
+#define PSC0_CAPT_vect _VECTOR(5)
+
+/* PSC0 End Cycle */
+#define PSC0_EC_vect _VECTOR(6)
+
+/* Analog Comparator 0 */
+#define ANALOG_COMP_0_vect _VECTOR(7)
+
+/* Analog Comparator 1 */
+#define ANALOG_COMP_1_vect _VECTOR(8)
+
+/* Analog Comparator 2 */
+#define ANALOG_COMP_2_vect _VECTOR(9)
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMP_A_vect _VECTOR(16)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(17)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(18)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(19)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(20)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(21)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(22)
+
+/* USART, Tx Complete */
+#define USART_TX_vect _VECTOR(23)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(24)
+
+/* Watchdog Timeout Interrupt */
+#define WDT_vect _VECTOR(25)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(26)
+
+/* Timer Counter 0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(27)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(28)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(31)
+
+#define _VECTORS_SIZE (4 * 32)
+
+/* Constants */
+
+#define RAMEND 0x4FF
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+#define SPM_PAGESIZE 128
+
+
+/* Fuse Information */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Diasble */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_PSCRV (unsigned char)~_BV(4)
+#define FUSE_PSC0RB (unsigned char)~_BV(5)
+#define FUSE_PSC1RB (unsigned char)~_BV(6)
+#define FUSE_PSC2RB (unsigned char)~_BV(7)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x83
+
+
+#endif /* _AVR_IO90PWM316_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90pwm3b.h b/cpukit/score/cpu/avr/avr/io90pwm3b.h
new file mode 100644
index 0000000000..74eb90ee97
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwm3b.h
@@ -0,0 +1,1392 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/io90pwm3b.h - definitions for AT90PWM3B */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90pwm3b.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IO90PWM3B_H_
+#define _AVR_IO90PWM3B_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define GPIOR3 _SFR_IO8(0x1B)
+#define GPIOR30 0
+#define GPIOR31 1
+#define GPIOR32 2
+#define GPIOR33 3
+#define GPIOR34 4
+#define GPIOR35 5
+#define GPIOR36 6
+#define GPIOR37 7
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEARL0 0
+#define EEARL1 1
+#define EEARL2 2
+#define EEARL3 3
+#define EEARL4 4
+#define EEARL5 5
+#define EEARL6 6
+#define EEARL7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 2
+#define TSM 3
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define OCR0_0 0 /* Deprecated */
+#define OCR0_1 1 /* Deprecated */
+#define OCR0_2 2 /* Deprecated */
+#define OCR0_3 3 /* Deprecated */
+#define OCR0_4 4 /* Deprecated */
+#define OCR0_5 5 /* Deprecated */
+#define OCR0_6 6 /* Deprecated */
+#define OCR0_7 7 /* Deprecated */
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define ACCKDIV 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC0 5
+#define PRPSC1 6
+#define PRPSC2 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x76)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x77)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define ADASCR 4
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define PIFR0 _SFR_MEM8(0xA0)
+#define PEOP0 0
+#define PRN00 1
+#define PRN01 2
+#define PEV0A 3
+#define PEV0B 4
+#define PSEI0 5
+#define POAC0A 6
+#define POAC0B 7
+
+#define PIM0 _SFR_MEM8(0xA1)
+#define PEOPE0 0
+#define PEVE0A 3
+#define PEVE0B 4
+#define PSEIE0 5
+
+#define PIFR1 _SFR_MEM8(0xA2)
+#define PEOP1 0
+#define PRN10 1
+#define PRN11 2
+#define PEV1A 3
+#define PEV1B 4
+#define PSEI1 5
+#define POAC1A 6
+#define POAC1B 7
+
+#define PIM1 _SFR_MEM8(0xA3)
+#define PEOPE1 0
+#define PEVE1A 3
+#define PEVE1B 4
+#define PSEIE1 5
+
+#define PIFR2 _SFR_MEM8(0xA4)
+#define PEOP2 0
+#define PRN20 1
+#define PRN21 2
+#define PEV2A 3
+#define PEV2B 4
+#define PSEI2 5
+#define POAC2A 6
+#define POAC2B 7
+
+#define PIM2 _SFR_MEM8(0xA5)
+#define PEOPE2 0
+#define PEVE2A 3
+#define PEVE2B 4
+#define PSEIE2 5
+
+#define DACON _SFR_MEM8(0xAA)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0xAB)
+
+#define DACL _SFR_MEM8(0xAB)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0xAC)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0xAD)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0xAE)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0xAF)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define UCSRA _SFR_MEM8(0xC0)
+#define MPCM 0
+#define U2X 1
+#define UPE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UCSRB _SFR_MEM8(0xC1)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRC _SFR_MEM8(0xC2)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL0 6
+
+#define UBRR _SFR_MEM16(0xC4)
+
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRR0 0
+#define UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UBRRH _SFR_MEM8(0xC5)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UDR _SFR_MEM8(0xC6)
+#define UDR0 0
+#define UDR1 1
+#define UDR2 2
+#define UDR3 3
+#define UDR4 4
+#define UDR5 5
+#define UDR6 6
+#define UDR7 7
+
+#define EUCSRA _SFR_MEM8(0xC8)
+#define URxS0 0
+#define URxS1 1
+#define URxS2 2
+#define URxS3 3
+#define UTxS0 4
+#define UTxS1 5
+#define UTxS2 6
+#define UTxS3 7
+
+#define EUCSRB _SFR_MEM8(0xC9)
+#define BODR 0
+#define EMCH 1
+#define EUSBS 3
+#define EUSART 4
+
+#define EUCSRC _SFR_MEM8(0xCA)
+#define STP0 0
+#define STP1 1
+#define F1617 2
+#define FEM 3
+
+#define MUBRR _SFR_MEM16(0xCC)
+
+#define MUBRRL _SFR_MEM8(0xCC)
+#define MUBRR0 0
+#define MUBRR1 1
+#define MUBRR2 2
+#define MUBRR3 3
+#define MUBRR4 4
+#define MUBRR5 5
+#define MUBRR6 6
+#define MUBRR7 7
+
+#define MUBRRH _SFR_MEM8(0xCD)
+#define MUBRR8 0
+#define MUBRR9 1
+#define MUBRR10 2
+#define MUBRR11 3
+#define MUBRR12 4
+#define MUBRR13 5
+#define MUBRR14 6
+#define MUBRR15 7
+
+#define EUDR _SFR_MEM8(0xCE)
+#define EUDR0 0
+#define EUDR1 1
+#define EUDR2 2
+#define EUDR3 3
+#define EUDR4 4
+#define EUDR5 5
+#define EUDR6 6
+#define EUDR7 7
+
+#define PSOC0 _SFR_MEM8(0xD0)
+#define POEN0A 0
+#define POEN0B 2
+#define PSYNC00 4
+#define PSYNC01 5
+
+#define OCR0SA _SFR_MEM16(0xD2)
+
+#define OCR0SAL _SFR_MEM8(0xD2)
+#define OCR0SA_0 0
+#define OCR0SA_1 1
+#define OCR0SA_2 2
+#define OCR0SA_3 3
+#define OCR0SA_4 4
+#define OCR0SA_5 5
+#define OCR0SA_6 6
+#define OCR0SA_7 7
+
+#define OCR0SAH _SFR_MEM8(0xD3)
+#define OCR0SA_8 0
+#define OCR0SA_9 1
+#define OCR0SA_00 2
+#define OCR0SA_01 3
+
+#define OCR0RA _SFR_MEM16(0xD4)
+
+#define OCR0RAL _SFR_MEM8(0xD4)
+#define OCR0RA_0 0
+#define OCR0RA_1 1
+#define OCR0RA_2 2
+#define OCR0RA_3 3
+#define OCR0RA_4 4
+#define OCR0RA_5 5
+#define OCR0RA_6 6
+#define OCR0RA_7 7
+
+#define OCR0RAH _SFR_MEM8(0xD5)
+#define OCR0RA_8 0
+#define OCR0RA_9 1
+#define OCR0RA_00 2
+#define OCR0RA_01 3
+
+#define OCR0SB _SFR_MEM16(0xD6)
+
+#define OCR0SBL _SFR_MEM8(0xD6)
+#define OCR0SB_0 0
+#define OCR0SB_1 1
+#define OCR0SB_2 2
+#define OCR0SB_3 3
+#define OCR0SB_4 4
+#define OCR0SB_5 5
+#define OCR0SB_6 6
+#define OCR0SB_7 7
+
+#define OCR0SBH _SFR_MEM8(0xD7)
+#define OCR0SB_8 0
+#define OCR0SB_9 1
+#define OCR0SB_00 2
+#define OCR0SB_01 3
+
+#define OCR0RB _SFR_MEM16(0xD8)
+
+#define OCR0RBL _SFR_MEM8(0xD8)
+#define OCR0RB_0 0
+#define OCR0RB_1 1
+#define OCR0RB_2 2
+#define OCR0RB_3 3
+#define OCR0RB_4 4
+#define OCR0RB_5 5
+#define OCR0RB_6 6
+#define OCR0RB_7 7
+
+#define OCR0RBH _SFR_MEM8(0xD9)
+#define OCR0RB_8 0
+#define OCR0RB_9 1
+#define OCR0RB_00 2
+#define OCR0RB_01 3
+#define OCR0RB_02 4
+#define OCR0RB_03 5
+#define OCR0RB_04 6
+#define OCR0RB_05 7
+
+#define PCNF0 _SFR_MEM8(0xDA)
+#define PCLKSEL0 1
+#define POP0 2
+#define PMODE00 3
+#define PMODE01 4
+#define PLOCK0 5
+#define PALOCK0 6
+#define PFIFTY0 7
+
+#define PCTL0 _SFR_MEM8(0xDB)
+#define PRUN0 0
+#define PCCYC0 1
+#define PARUN0 2
+#define PAOC0A 3
+#define PAOC0B 4
+#define PBFM0 5
+#define PPRE00 6
+#define PPRE01 7
+
+#define PFRC0A _SFR_MEM8(0xDC)
+#define PRFM0A0 0
+#define PRFM0A1 1
+#define PRFM0A2 2
+#define PRFM0A3 3
+#define PFLTE0A 4
+#define PELEV0A 5
+#define PISEL0A 6
+#define PCAE0A 7
+
+#define PFRC0B _SFR_MEM8(0xDD)
+#define PRFM0B0 0
+#define PRFM0B1 1
+#define PRFM0B2 2
+#define PRFM0B3 3
+#define PFLTE0B 4
+#define PELEV0B 5
+#define PISEL0B 6
+#define PCAE0B 7
+
+#define PICR0 _SFR_MEM16(0xDE)
+
+#define PICR0L _SFR_MEM8(0xDE)
+#define PICR0_0 0
+#define PICR0_1 1
+#define PICR0_2 2
+#define PICR0_3 3
+#define PICR0_4 4
+#define PICR0_5 5
+#define PICR0_6 6
+#define PICR0_7 7
+
+#define PICR0H _SFR_MEM8(0xDF)
+#define PICR0_8 0
+#define PICR0_9 1
+#define PICR0_10 2
+#define PICR0_11 3
+#define PCST0 7
+
+#define PSOC1 _SFR_MEM8(0xE0)
+#define POEN1A 0
+#define POEN1B 2
+#define PSYNC1_0 4
+#define PSYNC1_1 5
+
+#define OCR1SA _SFR_MEM16(0xE2)
+
+#define OCR1SAL _SFR_MEM8(0xE2)
+#define OCR1SA_0 0
+#define OCR1SA_1 1
+#define OCR1SA_2 2
+#define OCR1SA_3 3
+#define OCR1SA_4 4
+#define OCR1SA_5 5
+#define OCR1SA_6 6
+#define OCR1SA_7 7
+
+#define OCR1SAH _SFR_MEM8(0xE3)
+#define OCR1SA_8 0
+#define OCR1SA_9 1
+#define OCR1SA_10 2
+#define OCR1SA_11 3
+
+#define OCR1RA _SFR_MEM16(0xE4)
+
+#define OCR1RAL _SFR_MEM8(0xE4)
+#define OCR1RA_0 0
+#define OCR1RA_1 1
+#define OCR1RA_2 2
+#define OCR1RA_3 3
+#define OCR1RA_4 4
+#define OCR1RA_5 5
+#define OCR1RA_6 6
+#define OCR1RA_7 7
+
+#define OCR1RAH _SFR_MEM8(0xE5)
+#define OCR1RA_8 0
+#define OCR1RA_9 1
+#define OCR1RA_10 2
+#define OCR1RA_11 3
+
+#define OCR1SB _SFR_MEM16(0xE6)
+
+#define OCR1SBL _SFR_MEM8(0xE6)
+#define OCR1SB_0 0
+#define OCR1SB_1 1
+#define OCR1SB_2 2
+#define OCR1SB_3 3
+#define OCR1SB_4 4
+#define OCR1SB_5 5
+#define OCR1SB_6 6
+#define OCR1SB_7 7
+
+#define OCR1SBH _SFR_MEM8(0xE7)
+#define OCR1SB_8 0
+#define OCR1SB_9 1
+#define OCR1SB_10 2
+#define OCR1SB_11 3
+
+#define OCR1RB _SFR_MEM16(0xE8)
+
+#define OCR1RBL _SFR_MEM8(0xE8)
+#define OCR1RB_0 0
+#define OCR1RB_1 1
+#define OCR1RB_2 2
+#define OCR1RB_3 3
+#define OCR1RB_4 4
+#define OCR1RB_5 5
+#define OCR1RB_6 6
+#define OCR1RB_7 7
+
+#define OCR1RBH _SFR_MEM8(0xE9)
+#define OCR1RB_8 0
+#define OCR1RB_9 1
+#define OCR1RB_10 2
+#define OCR1RB_11 3
+#define OCR1RB_12 4
+#define OCR1RB_13 5
+#define OCR1RB_14 6
+#define OCR1RB_15 7
+
+#define PCNF1 _SFR_MEM8(0xEA)
+#define PCLKSEL1 1
+#define POP1 2
+#define PMODE10 3
+#define PMODE11 4
+#define PLOCK1 5
+#define PALOCK1 6
+#define PFIFTY1 7
+
+#define PCTL1 _SFR_MEM8(0xEB)
+#define PRUN1 0
+#define PCCYC1 1
+#define PARUN1 2
+#define PAOC1A 3
+#define PAOC1B 4
+#define PBFM1 5
+#define PPRE10 6
+#define PPRE11 7
+
+#define PFRC1A _SFR_MEM8(0xEC)
+#define PRFM1A0 0
+#define PRFM1A1 1
+#define PRFM1A2 2
+#define PRFM1A3 3
+#define PFLTE1A 4
+#define PELEV1A 5
+#define PISEL1A 6
+#define PCAE1A 7
+
+#define PFRC1B _SFR_MEM8(0xED)
+#define PRFM1B0 0
+#define PRFM1B1 1
+#define PRFM1B2 2
+#define PRFM1B3 3
+#define PFLTE1B 4
+#define PELEV1B 5
+#define PISEL1B 6
+#define PCAE1B 7
+
+#define PICR1 _SFR_MEM16(0xEE)
+
+#define PICR1L _SFR_MEM8(0xEE)
+#define PICR1_0 0
+#define PICR1_1 1
+#define PICR1_2 2
+#define PICR1_3 3
+#define PICR1_4 4
+#define PICR1_5 5
+#define PICR1_6 6
+#define PICR1_7 7
+
+#define PICR1H _SFR_MEM8(0xEF)
+#define PICR1_8 0
+#define PICR1_9 1
+#define PICR1_10 2
+#define PICR1_11 3
+#define PCST1 7
+
+#define PSOC2 _SFR_MEM8(0xF0)
+#define POEN2A 0
+#define POEN2C 1
+#define POEN2B 2
+#define POEN2D 3
+#define PSYNC2_0 4
+#define PSYNC2_1 5
+#define POS22 6
+#define POS23 7
+
+#define POM2 _SFR_MEM8(0xF1)
+#define POMV2A0 0
+#define POMV2A1 1
+#define POMV2A2 2
+#define POMV2A3 3
+#define POMV2B0 4
+#define POMV2B1 5
+#define POMV2B2 6
+#define POMV2B3 7
+
+#define OCR2SA _SFR_MEM16(0xF2)
+
+#define OCR2SAL _SFR_MEM8(0xF2)
+#define OCR2SA_0 0
+#define OCR2SA_1 1
+#define OCR2SA_2 2
+#define OCR2SA_3 3
+#define OCR2SA_4 4
+#define OCR2SA_5 5
+#define OCR2SA_6 6
+#define OCR2SA_7 7
+
+#define OCR2SAH _SFR_MEM8(0xF3)
+#define OCR2SA_8 0
+#define OCR2SA_9 1
+#define OCR2SA_10 2
+#define OCR2SA_11 3
+
+#define OCR2RA _SFR_MEM16(0xF4)
+
+#define OCR2RAL _SFR_MEM8(0xF4)
+#define OCR2RA_0 0
+#define OCR2RA_1 1
+#define OCR2RA_2 2
+#define OCR2RA_3 3
+#define OCR2RA_4 4
+#define OCR2RA_5 5
+#define OCR2RA_6 6
+#define OCR2RA_7 7
+
+#define OCR2RAH _SFR_MEM8(0xF5)
+#define OCR2RA_8 0
+#define OCR2RA_9 1
+#define OCR2RA_10 2
+#define OCR2RA_11 3
+
+#define OCR2SB _SFR_MEM16(0xF6)
+
+#define OCR2SBL _SFR_MEM8(0xF6)
+#define OCR2SB_0 0
+#define OCR2SB_1 1
+#define OCR2SB_2 2
+#define OCR2SB_3 3
+#define OCR2SB_4 4
+#define OCR2SB_5 5
+#define OCR2SB_6 6
+#define OCR2SB_7 7
+
+#define OCR2SBH _SFR_MEM8(0xF7)
+#define OCR2SB_8 0
+#define OCR2SB_9 1
+#define OCR2SB_10 2
+#define OCR2SB_11 3
+
+#define OCR2RB _SFR_MEM16(0xF8)
+
+#define OCR2RBL _SFR_MEM8(0xF8)
+#define OCR2RB_0 0
+#define OCR2RB_1 1
+#define OCR2RB_2 2
+#define OCR2RB_3 3
+#define OCR2RB_4 4
+#define OCR2RB_5 5
+#define OCR2RB_6 6
+#define OCR2RB_7 7
+
+#define OCR2RBH _SFR_MEM8(0xF9)
+#define OCR2RB_8 0
+#define OCR2RB_9 1
+#define OCR2RB_10 2
+#define OCR2RB_11 3
+#define OCR2RB_12 4
+#define OCR2RB_13 5
+#define OCR2RB_14 6
+#define OCR2RB_15 7
+
+#define PCNF2 _SFR_MEM8(0xFA)
+#define POME2 0
+#define PCLKSEL2 1
+#define POP2 2
+#define PMODE20 3
+#define PMODE21 4
+#define PLOCK2 5
+#define PALOCK2 6
+#define PFIFTY2 7
+
+#define PCTL2 _SFR_MEM8(0xFB)
+#define PRUN2 0
+#define PCCYC2 1
+#define PARUN2 2
+#define PAOC2A 3
+#define PAOC2B 4
+#define PBFM2 5
+#define PPRE20 6
+#define PPRE21 7
+
+#define PFRC2A _SFR_MEM8(0xFC)
+#define PRFM2A0 0
+#define PRFM2A1 1
+#define PRFM2A2 2
+#define PRFM2A3 3
+#define PFLTE2A 4
+#define PELEV2A 5
+#define PISEL2A 6
+#define PCAE2A 7
+
+#define PFRC2B _SFR_MEM8(0xFD)
+#define PRFM2B0 0
+#define PRFM2B1 1
+#define PRFM2B2 2
+#define PRFM2B3 3
+#define PFLTE2B 4
+#define PELEV2B 5
+#define PISEL2B 6
+#define PCAE2B 7
+
+#define PICR2 _SFR_MEM16(0xFE)
+
+#define PICR2L _SFR_MEM8(0xFE)
+#define PICR2_0 0
+#define PICR2_1 1
+#define PICR2_2 2
+#define PICR2_3 3
+#define PICR2_4 4
+#define PICR2_5 5
+#define PICR2_6 6
+#define PICR2_7 7
+
+#define PICR2H _SFR_MEM8(0xFF)
+#define PICR2_8 0
+#define PICR2_9 1
+#define PICR2_10 2
+#define PICR2_11 3
+#define PCST2 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt vector 0 is the reset vector. */
+#define PSC2_CAPT_vect _VECTOR(1) /* PSC2 Capture Event */
+#define PSC2_EC_vect _VECTOR(2) /* PSC2 End Cycle */
+#define PSC1_CAPT_vect _VECTOR(3) /* PSC1 Capture Event */
+#define PSC1_EC_vect _VECTOR(4) /* PSC1 End Cycle */
+#define PSC0_CAPT_vect _VECTOR(5) /* PSC0 Capture Event */
+#define PSC0_EC_vect _VECTOR(6) /* PSC0 End Cycle */
+#define ANALOG_COMP_0_vect _VECTOR(7) /* Analog Comparator 0 */
+#define ANALOG_COMP_1_vect _VECTOR(8) /* Analog Comparator 1 */
+#define ANALOG_COMP_2_vect _VECTOR(9) /* Analog Comparator 2 */
+#define INT0_vect _VECTOR(10) /* External Interrupt Request 0 */
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter Compare Match B */
+/* Vector 14, Reserved */
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(16) /* Timer/Counter0 Compare Match A */
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define ADC_vect _VECTOR(18) /* ADC Conversion Complete */
+#define INT1_vect _VECTOR(19) /* External Interrupt Request 1 */
+#define SPI_STC_vect _VECTOR(20) /* SPI Serial Transfer Complete */
+#define USART_RX_vect _VECTOR(21) /* USART, Rx Complete */
+#define USART_UDRE_vect _VECTOR(22) /* USART Data Register Empty */
+#define USART_TX_vect _VECTOR(23) /* USART, Tx Complete */
+#define INT2_vect _VECTOR(24) /* External Interrupt Request 2 */
+#define WDT_vect _VECTOR(25) /* Watchdog Timeout Interrupt */
+#define EE_READY_vect _VECTOR(26) /* EEPROM Ready */
+#define TIMER0_COMPB_vect _VECTOR(27) /* Timer Counter 0 Compare Match B */
+#define INT3_vect _VECTOR(28) /* External Interrupt Request 3 */
+/* Vector 29, Reserved */
+/* Vector 30, Reserved */
+#define SPM_READY_vect _VECTOR(31) /* Store Program Memory Read */
+
+#define _VECTORS_SIZE 64
+
+
+
+/* Memory Sizes */
+#define RAMEND 0x2FF
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+#define SPM_PAGESIZE 32
+
+
+
+/* Fuse Information */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown out detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_PSCRV (unsigned char)~_BV(4) /* PSCOUT Reset Value */
+#define FUSE_PSC0RB (unsigned char)~_BV(5) /* PSC0 Reset Behaviour */
+#define FUSE_PSC1RB (unsigned char)~_BV(6) /* PSC1 Reset Behaviour */
+#define FUSE_PSC2RB (unsigned char)~_BV(7) /* PSC2 Reset Behaviour */
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x83
+
+
+#endif /* _AVR_IO90PWM3B_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90pwm81.h b/cpukit/score/cpu/avr/avr/io90pwm81.h
new file mode 100644
index 0000000000..0844a4ef8c
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwm81.h
@@ -0,0 +1,1025 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io90pwm81.h - definitions for AT90PWM81 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90pwm81.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_AT90PWM81_H_
+#define _AVR_AT90PWM81_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define ACSR _SFR_IO8(0x00)
+#define AC1O 1
+#define AC2O 2
+#define AC3O 3
+#define AC1IF 5
+#define AC2IF 6
+#define AC3IF 7
+
+#define TIMSK1 _SFR_IO8(0x01)
+#define TOIE1 0
+#define ICIE1 5
+
+#define TIFR1 _SFR_IO8(0x02)
+#define TOV1 0
+#define ICF1 5
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_IO8(0x07)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define ADSSEN 4
+#define ADNCDIS 6
+#define ADHSM 7
+
+#define ADMUX _SFR_IO8(0x08)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define PIM0 _SFR_IO8(0x0F)
+#define PEOPE0 0
+#define PEOEPE0 1
+#define PEVE0A 3
+#define PEVE0B 4
+
+#define PIFR0 _SFR_IO8(0x10)
+#define PEOP0 0
+#define PRN00 1
+#define PRN01 2
+#define PEV0A 3
+#define PEV0B 4
+#define POAC0A 6
+#define POAC0B 7
+
+#define PCNF0 _SFR_IO8(0x11)
+#define PCLKSEL0 1
+#define POP0 2
+#define PMODE00 3
+#define PMODE01 4
+#define PLOCK0 5
+#define PALOCK0 6
+#define PFIFTY0 7
+
+#define PCTL0 _SFR_IO8(0x12)
+#define PRUN0 0
+#define PCCYC0 1
+#define PBFM00 2
+#define PAOC0A 3
+#define PAOC0B 4
+#define PBFM01 5
+#define PPRE00 6
+#define PPRE01 7
+
+#define PIM2 _SFR_IO8(0x13)
+#define PEOPE2 0
+#define PEOEPE2 1
+#define PEVE2A 3
+#define PEVE2B 4
+#define PSEIE2 5
+
+#define PIFR2 _SFR_IO8(0x14)
+#define PEOP2 0
+#define PRN20 1
+#define PRN21 2
+#define PEV2A 3
+#define PEV2B 4
+#define PSEI2 5
+#define POAC2A 6
+#define POAC2B 7
+
+#define PCNF2 _SFR_IO8(0x15)
+#define POME2 0
+#define PCLKSEL2 1
+#define POP2 2
+#define PMODE20 3
+#define PMODE21 4
+#define PLOCK2 5
+#define PALOCK2 6
+#define PFIFTY2 7
+
+#define PCTL2 _SFR_IO8(0x16)
+#define PRUN2 0
+#define PCCYC2 1
+#define PARUN2 2
+#define PAOC2A 3
+#define PAOC2B 4
+#define PBFM2 5
+#define PPRE20 6
+#define PPRE21 7
+
+#define SPCR _SFR_IO8(0x17)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x18)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define GPIOR0 _SFR_IO8(0x19)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x1A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+#define EEPAGE 6
+#define NVMBSY 7
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEARL0 0
+#define EEARL1 1
+#define EEARL2 2
+#define EEARL3 3
+#define EEARL4 4
+#define EEARL5 5
+#define EEARL6 6
+#define EEARL7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define EIFR _SFR_IO8(0x20)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+
+#define EIMSK _SFR_IO8(0x21)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+
+#define OCR0SB _SFR_IO16(0x22)
+
+#define OCR0SBL _SFR_IO8(0x22)
+#define OCR0SB_0 0
+#define OCR0SB_1 1
+#define OCR0SB_2 2
+#define OCR0SB_3 3
+#define OCR0SB_4 4
+#define OCR0SB_5 5
+#define OCR0SB_6 6
+#define OCR0SB_7 7
+
+#define OCR0SBH _SFR_IO8(0x23)
+#define OCR0SB_8 0
+#define OCR0SB_9 1
+#define OCR0SB_00 2
+#define OCR0SB_01 3
+
+#define OCR0RB _SFR_IO16(0x24)
+
+#define OCR0RBL _SFR_IO8(0x24)
+#define OCR0RB_0 0
+#define OCR0RB_1 1
+#define OCR0RB_2 2
+#define OCR0RB_3 3
+#define OCR0RB_4 4
+#define OCR0RB_5 5
+#define OCR0RB_6 6
+#define OCR0RB_7 7
+
+#define OCR0RBH _SFR_IO8(0x25)
+#define OCR0RB_8 0
+#define OCR0RB_9 1
+#define OCR0RB_00 2
+#define OCR0RB_01 3
+#define OCR0RB_02 4
+#define OCR0RB_03 5
+#define OCR0RB_04 6
+#define OCR0RB_05 7
+
+#define OCR2SB _SFR_IO16(0x26)
+
+#define OCR2SBL _SFR_IO8(0x26)
+#define OCR2SB_0 0
+#define OCR2SB_1 1
+#define OCR2SB_2 2
+#define OCR2SB_3 3
+#define OCR2SB_4 4
+#define OCR2SB_5 5
+#define OCR2SB_6 6
+#define OCR2SB_7 7
+
+#define OCR2SBH _SFR_IO8(0x27)
+#define OCR2SB_8 0
+#define OCR2SB_9 1
+#define OCR2SB_10 2
+#define OCR2SB_11 3
+
+#define OCR2RB _SFR_IO16(0x28)
+
+#define OCR2RBL _SFR_IO8(0x28)
+#define OCR2RB_0 0
+#define OCR2RB_1 1
+#define OCR2RB_2 2
+#define OCR2RB_3 3
+#define OCR2RB_4 4
+#define OCR2RB_5 5
+#define OCR2RB_6 6
+#define OCR2RB_7 7
+
+#define OCR2RBH _SFR_IO8(0x29)
+#define OCR2RB_8 0
+#define OCR2RB_9 1
+#define OCR2RB_10 2
+#define OCR2RB_11 3
+#define OCR2RB_12 4
+#define OCR2RB_13 5
+#define OCR2RB_14 6
+#define OCR2RB_15 7
+
+#define OCR0RA _SFR_IO16(0x2A)
+
+#define OCR0RAL _SFR_IO8(0x2A)
+#define OCR0RA_0 0
+#define OCR0RA_1 1
+#define OCR0RA_2 2
+#define OCR0RA_3 3
+#define OCR0RA_4 4
+#define OCR0RA_5 5
+#define OCR0RA_6 6
+#define OCR0RA_7 7
+
+#define OCR0RAH _SFR_IO8(0x2B)
+#define OCR0RA_8 0
+#define OCR0RA_9 1
+#define OCR0RA_00 2
+#define OCR0RA_01 3
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x2C)
+#endif
+#define ADCW _SFR_IO16(0x2C)
+
+#define ADCL _SFR_IO8(0x2C)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x2D)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define OCR2RA _SFR_IO16(0x2E)
+
+#define OCR2RAL _SFR_IO8(0x2E)
+#define OCR2RA_0 0
+#define OCR2RA_1 1
+#define OCR2RA_2 2
+#define OCR2RA_3 3
+#define OCR2RA_4 4
+#define OCR2RA_5 5
+#define OCR2RA_6 6
+#define OCR2RA_7 7
+
+#define OCR2RAH _SFR_IO8(0x2F)
+#define OCR2RA_8 0
+#define OCR2RA_9 1
+#define OCR2RA_10 2
+#define OCR2RA_11 3
+
+#define DWDR _SFR_IO8(0x31)
+
+#define MSMCR _SFR_IO8(0x32)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define CKRC81 2
+#define RSTDIS 3
+#define PUD 4
+
+#define SPDR _SFR_IO8(0x36)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define DAC _SFR_IO16(0x38)
+
+#define DACL _SFR_IO8(0x38)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_IO8(0x39)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define TCNT1 _SFR_IO16(0x3A)
+
+#define TCNT1L _SFR_IO8(0x3A)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_IO8(0x3B)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define OCR0SA _SFR_MEM16(0x60)
+
+#define OCR0SAL _SFR_MEM8(0x60)
+#define OCR0SA_0 0
+#define OCR0SA_1 1
+#define OCR0SA_2 2
+#define OCR0SA_3 3
+#define OCR0SA_4 4
+#define OCR0SA_5 5
+#define OCR0SA_6 6
+#define OCR0SA_7 7
+
+#define OCR0SAH _SFR_MEM8(0x61)
+#define OCR0SA_8 0
+#define OCR0SA_9 1
+#define OCR0SA_00 2
+#define OCR0SA_01 3
+
+#define PFRC0A _SFR_MEM8(0x62)
+#define PRFM0A0 0
+#define PRFM0A1 1
+#define PRFM0A2 2
+#define PRFM0A3 3
+#define PFLTE0A 4
+#define PELEV0A 5
+#define PISEL0A 6
+#define PCAE0A 7
+
+#define PFRC0B _SFR_MEM8(0x63)
+#define PRFM0B0 0
+#define PRFM0B1 1
+#define PRFM0B2 2
+#define PRFM0B3 3
+#define PFLTE0B 4
+#define PELEV0B 5
+#define PISEL0B 6
+#define PCAE0B 7
+
+#define OCR2SA _SFR_MEM16(0x64)
+
+#define OCR2SAL _SFR_MEM8(0x64)
+#define OCR2SA_0 0
+#define OCR2SA_1 1
+#define OCR2SA_2 2
+#define OCR2SA_3 3
+#define OCR2SA_4 4
+#define OCR2SA_5 5
+#define OCR2SA_6 6
+#define OCR2SA_7 7
+
+#define OCR2SAH _SFR_MEM8(0x65)
+#define OCR2SA_8 0
+#define OCR2SA_9 1
+#define OCR2SA_10 2
+#define OCR2SA_11 3
+
+#define PFRC2A _SFR_MEM8(0x66)
+#define PRFM2A0 0
+#define PRFM2A1 1
+#define PRFM2A2 2
+#define PRFM2A3 3
+#define PFLTE2A 4
+#define PELEV2A 5
+#define PISEL2A 6
+#define PCAE2A 7
+
+#define PFRC2B _SFR_MEM8(0x67)
+#define PRFM2B0 0
+#define PRFM2B1 1
+#define PRFM2B2 2
+#define PRFM2B3 3
+#define PFLTE2B 4
+#define PELEV2B 5
+#define PISEL2B 6
+#define PCAE2B 7
+
+#define PICR0 _SFR_MEM16(0x68)
+
+#define PICR0L _SFR_MEM8(0x68)
+#define PICR0_0 0
+#define PICR0_1 1
+#define PICR0_2 2
+#define PICR0_3 3
+#define PICR0_4 4
+#define PICR0_5 5
+#define PICR0_6 6
+#define PICR0_7 7
+
+#define PICR0H _SFR_MEM8(0x69)
+#define PICR0_8 0
+#define PICR0_9 1
+#define PICR0_10 2
+#define PICR0_11 3
+#define PCST0 7
+
+#define PSOC0 _SFR_MEM8(0x6A)
+#define POEN0A 0
+#define POEN0B 2
+#define PSYNC00 4
+#define PSYNC01 5
+#define PISEL0B1 6
+#define PISEL0A1 7
+
+#define PICR2 _SFR_MEM16(0x6C)
+
+#define PICR2L _SFR_MEM8(0x6C)
+#define PICR2_0 0
+#define PICR2_1 1
+#define PICR2_2 2
+#define PICR2_3 3
+#define PICR2_4 4
+#define PICR2_5 5
+#define PICR2_6 6
+#define PICR2_7 7
+
+#define PICR2H _SFR_MEM8(0x6D)
+#define PICR2_8 0
+#define PICR2_9 1
+#define PICR2_10 2
+#define PICR2_11 3
+#define PCST2 7
+
+#define PSOC2 _SFR_MEM8(0x6E)
+#define POEN2A 0
+#define POEN2C 1
+#define POEN2B 2
+#define POEN2D 3
+#define PSYNC2_0 4
+#define PSYNC2_1 5
+#define POS22 6
+#define POS23 7
+
+#define POM2 _SFR_MEM8(0x6F)
+#define POMV2A0 0
+#define POMV2A1 1
+#define POMV2A2 2
+#define POMV2A3 3
+#define POMV2B0 4
+#define POMV2B1 5
+#define POMV2B2 6
+#define POMV2B3 7
+
+#define PCNFE2 _SFR_MEM8(0x70)
+#define PISEL2B1 0
+#define PISEL2A1 1
+#define PELEV2B1 2
+#define PELEV2A1 3
+#define PBFM21 4
+#define PASDLK20 5
+#define PASDLK21 6
+#define PASDLK22 7
+
+#define PASDLY2 _SFR_MEM8(0x71)
+#define PASDLY2_0 0
+#define PASDLY2_1 1
+#define PASDLY2_2 2
+#define PASDLY2_3 3
+#define PASDLY2_4 4
+#define PASDLY2_5 5
+#define PASDLY2_6 6
+#define PASDLY2_7 7
+
+#define DACON _SFR_MEM8(0x76)
+#define DAEN 0
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DIDR0 _SFR_MEM8(0x77)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC7D 6
+#define ADC8D 7
+
+#define DIDR1 _SFR_MEM8(0x78)
+#define ADC9D 0
+#define ADC10D 1
+#define AMP0PD 2
+#define ACMP1MD 3
+
+#define AMP0CSR _SFR_MEM8(0x79)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0GS 3
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AC1ECON _SFR_MEM8(0x7A)
+#define AC1H0 0
+#define AC1H1 1
+#define AC1H2 2
+#define AC1ICE 3
+#define AC1OE 4
+#define AC1OI 5
+
+#define AC2ECON _SFR_MEM8(0x7B)
+#define AC2H0 0
+#define AC2H1 1
+#define AC2H2 2
+#define AC2OE 4
+#define AC2OI 5
+
+#define AC3ECON _SFR_MEM8(0x7C)
+#define AC3H0 0
+#define AC3H1 1
+#define AC3H2 2
+#define AC3OE 4
+#define AC3OI 5
+
+#define AC1CON _SFR_MEM8(0x7D)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0x7E)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define AC3CON _SFR_MEM8(0x7F)
+#define AC3M0 0
+#define AC3M1 1
+#define AC3M2 2
+#define AC3OEA 3
+#define AC3IS0 4
+#define AC3IS1 5
+#define AC3IE 6
+#define AC3EN 7
+
+#define BGCRR _SFR_MEM8(0x80)
+#define BGCR0 0
+#define BGCR1 1
+#define BGCR2 2
+#define BGCR3 3
+
+#define BGCCR _SFR_MEM8(0x81)
+#define BGCC0 0
+#define BGCC1 1
+#define BGCC2 2
+#define BGCC3 3
+
+#define WDTCSR _SFR_MEM8(0x82)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x83)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define CLKCSR _SFR_MEM8(0x84)
+#define CLKC0 0
+#define CLKC1 1
+#define CLKC2 2
+#define CLKC3 3
+#define CLKRDY 4
+#define CLKCCE 7
+
+#define CLKSELR _SFR_MEM8(0x85)
+#define CKSEL0 0
+#define CKSEL1 1
+#define CKSEL2 2
+#define CKSEL3 3
+#define CSUT0 4
+#define CSUT1 5
+#define COUT 6
+
+#define PRR _SFR_MEM8(0x86)
+#define PRADC 0
+#define PRSPI 2
+#define PRTIM1 4
+#define PRPSC0 5
+#define PRPSC2 7
+
+#define PLLCSR _SFR_MEM8(0x87)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF0 2
+#define PLLF1 3
+#define PLLF2 4
+#define PLLF3 5
+
+#define OSCCAL _SFR_MEM8(0x88)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define EICRA _SFR_MEM8(0x89)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+
+#define TCCR1B _SFR_MEM8(0x8A)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define ICR1 _SFR_MEM16(0x8C)
+
+#define ICR1L _SFR_MEM8(0x8C)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x8D)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define PSC2_CAPT_vect_num 1
+#define PSC2_CAPT_vect _VECTOR(1) /* PSC2 Capture Event */
+#define PSC2_EC_vect_num 2
+#define PSC2_EC_vect _VECTOR(2) /* PSC2 End Cycle */
+#define PSC2_EEC_vect_num 3
+#define PSC2_EEC_vect _VECTOR(3) /* PSC2 End Of Enhanced Cycle */
+#define PSC0_CAPT_vect_num 4
+#define PSC0_CAPT_vect _VECTOR(4) /* PSC0 Capture Event */
+#define PSC0_EC_vect_num 5
+#define PSC0_EC_vect _VECTOR(5) /* PSC0 End Cycle */
+#define PSC0_EEC_vect_num 6
+#define PSC0_EEC_vect _VECTOR(6) /* PSC0 End Of Enhanced Cycle */
+#define ANALOG_COMP_1_vect_num 7
+#define ANALOG_COMP_1_vect _VECTOR(7) /* Analog Comparator 1 */
+#define ANALOG_COMP_2_vect_num 8
+#define ANALOG_COMP_2_vect _VECTOR(8) /* Analog Comparator 2 */
+#define ANALOG_COMP_3_vect_num 9
+#define ANALOG_COMP_3_vect _VECTOR(9) /* Analog Comparator 3 */
+#define INT0_vect_num 10
+#define INT0_vect _VECTOR(10) /* External Interrupt Request 0 */
+#define TIMER1_CAPT_vect_num 11
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_OVF_vect_num 12
+#define TIMER1_OVF_vect _VECTOR(12) /* Timer/Counter1 Overflow */
+#define ADC_vect_num 13
+#define ADC_vect _VECTOR(13) /* ADC Conversion Complete */
+#define INT1_vect_num 14
+#define INT1_vect _VECTOR(14) /* External Interrupt Request 1 */
+#define SPI_STC_vect_num 15
+#define SPI_STC_vect _VECTOR(15) /* SPI Serial Transfer Complet */
+#define INT2_vect_num 16
+#define INT2_vect _VECTOR(16) /* External Interrupt Request 2 */
+#define WDT_vect_num 17
+#define WDT_vect _VECTOR(17) /* Watchdog Timeout Interrupt */
+#define EE_READY_vect_num 18
+#define EE_READY_vect _VECTOR(18) /* EEPROM Ready */
+#define SPM_READY_vect_num 19
+#define SPM_READY_vect _VECTOR(19) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (20 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x0100)
+#define RAMSIZE (256)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x1FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown out detector trigger level */
+#define FUSE_PSCINRB (unsigned char)~_BV(3) /* PSC2 & PSC0 Input Reset Behavior */
+#define FUSE_PSCRV (unsigned char)~_BV(4) /* PSCOUT Reset Value */
+#define FUSE_PSC0RB (unsigned char)~_BV(5) /* PSC0 Reset Behaviour */
+#define FUSE_PSC2RBA (unsigned char)~_BV(6) /* PSC2 Rest Behavior for out OUT22 & 23 */
+#define FUSE_PSC2RB (unsigned char)~_BV(7) /* PSC2 Reset Behaviour */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x88
+
+
+#endif /* _AVR_AT90PWM81_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/io90pwmx.h b/cpukit/score/cpu/avr/avr/io90pwmx.h
new file mode 100644
index 0000000000..40bf324727
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90pwmx.h
@@ -0,0 +1,1371 @@
+/* Copyright (c) 2005, Andrey Pashchenko
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io90pwmx.h - definitions for AT90PWM2(B) and AT90PWM3(B) */
+
+#ifndef _AVR_IO90PWMX_H_
+#define _AVR_IO90PWMX_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90pwmX.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Port B Input Pins Address */
+#define PINB _SFR_IO8(0x03)
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Port B Data Direction Register */
+#define DDRB _SFR_IO8(0x04)
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Port B Data Register */
+#define PORTB _SFR_IO8(0x05)
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Port C Input Pins Address */
+#define PINC _SFR_IO8(0x06)
+/* PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Port C Data Direction Register */
+#define DDRC _SFR_IO8(0x07)
+/* DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Port C Data Register */
+#define PORTC _SFR_IO8(0x08)
+/* PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Port D Input Pins Address */
+#define PIND _SFR_IO8(0x09)
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Port D Data Direction Register */
+#define DDRD _SFR_IO8(0x0A)
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Port D Data Register */
+#define PORTD _SFR_IO8(0x0B)
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Port E Input Pins Address */
+#define PINE _SFR_IO8(0x0C)
+/* PINE */
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* Port E Data Direction Register */
+#define DDRE _SFR_IO8(0x0D)
+/* DDRE */
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Port E Data Register */
+#define PORTE _SFR_IO8(0x0E)
+/* PORTE */
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Timer/Counter 0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+/* TIFR0 */
+#define OCF0B 2 /* Output Compare Flag 0B */
+#define OCF0A 1 /* Output Compare Flag 0A */
+#define TOV0 0 /* Overflow Flag */
+
+/* Timer/Counter1 Interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+/* TIFR1 */
+#define ICF1 5 /* Input Capture Flag 1 */
+#define OCF1B 2 /* Output Compare Flag 1B*/
+#define OCF1A 1 /* Output Compare Flag 1A*/
+#define TOV1 0 /* Overflow Flag */
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x19)
+/* GPIOR1 */
+#define GPIOR17 7
+#define GPIOR16 6
+#define GPIOR15 5
+#define GPIOR14 4
+#define GPIOR13 3
+#define GPIOR12 2
+#define GPIOR11 1
+#define GPIOR10 0
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x1A)
+/* GPIOR2 */
+#define GPIOR27 7
+#define GPIOR26 6
+#define GPIOR25 5
+#define GPIOR24 4
+#define GPIOR23 3
+#define GPIOR22 2
+#define GPIOR21 1
+#define GPIOR20 0
+
+/* General Purpose I/O Register 3 */
+#define GPIOR3 _SFR_IO8(0x1B)
+/* GPIOR3 */
+#define GPIOR37 7
+#define GPIOR36 6
+#define GPIOR35 5
+#define GPIOR34 4
+#define GPIOR33 3
+#define GPIOR32 2
+#define GPIOR31 1
+#define GPIOR30 0
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+/* EIFR */
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+/* EIMSK */
+#define INT3 3 /* External Interrupt Request 3 Enable */
+#define INT2 2 /* External Interrupt Request 2 Enable */
+#define INT1 1 /* External Interrupt Request 1 Enable */
+#define INT0 0 /* External Interrupt Request 0 Enable */
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+/* GPIOR0 */
+#define GPIOR07 7
+#define GPIOR06 6
+#define GPIOR05 5
+#define GPIOR04 4
+#define GPIOR03 3
+#define GPIOR02 2
+#define GPIOR01 1
+#define GPIOR00 0
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+/* EECR */
+#define EERIE 3 /* EEPROM Ready Interrupt Enable */
+#define EEMWE 2 /* EEPROM Master Write Enable */
+#define EEWE 1 /* EEPROM Write Enable */
+#define EERE 0 /* EEPROM Read Enable */
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+/* EEDR */
+#define EEDR7 7
+#define EEDR6 6
+#define EEDR5 5
+#define EEDR4 4
+#define EEDR3 3
+#define EEDR2 2
+#define EEDR1 1
+#define EEDR0 0
+
+/* The EEPROM Address Registers */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+/* EEARH */
+#define EEAR11 3
+#define EEAR10 2
+#define EEAR9 1
+#define EEAR8 0
+/* EEARL */
+#define EEAR7 7
+#define EEAR6 6
+#define EEAR5 5
+#define EEAR4 4
+#define EEAR3 3
+#define EEAR2 2
+#define EEAR1 1
+#define EEAR0 0
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+/* GTCCR */
+#define TSM 7 /* Timer/Counter Synchronization Mode */
+#define ICPSEL1 6 /* Timer1 Input Capture Selection Bit */
+#define PSR10 0 /* Prescaler Reset Timer/Counter1 and Timer/Counter0 */
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+/* TCCR0A */
+#define COM0A1 7 /* Compare Output Mode, Phase Correct PWM Mode */
+#define COM0A0 6 /* Compare Output Mode, Phase Correct PWM Mode */
+#define COM0B1 5 /* Compare Output Mode, Fast PWm */
+#define COM0B0 4 /* Compare Output Mode, Fast PWm */
+#define WGM01 1 /* Waveform Generation Mode */
+#define WGM00 0 /* Waveform Generation Mode */
+
+/* Timer/Counter Control Register B */
+#define TCCR0B _SFR_IO8(0x25)
+/* TCCR0B */
+#define FOC0A 7 /* Force Output Compare A */
+#define FOC0B 6 /* Force Output Compare B */
+#define WGM02 3 /* Waveform Generation Mode */
+#define CS02 2 /* Clock Select */
+#define CS01 1 /* Clock Select */
+#define CS00 0 /* Clock Select */
+
+/* Timer/Counter0 Register */
+#define TCNT0 _SFR_IO8(0x26)
+/* TCNT0 */
+#define TCNT07 7
+#define TCNT06 6
+#define TCNT05 5
+#define TCNT04 4
+#define TCNT03 3
+#define TCNT02 2
+#define TCNT01 1
+#define TCNT00 0
+
+/* Timer/Counter0 Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+/* OCR0A */
+#define OCR0A7 7
+#define OCR0A6 6
+#define OCR0A5 5
+#define OCR0A4 4
+#define OCR0A3 3
+#define OCR0A2 2
+#define OCR0A1 1
+#define OCR0A0 0
+
+/* Timer/Counter0 Output Compare Register B */
+#define OCR0B _SFR_IO8(0x28)
+/* OCR0B */
+#define OCR0B7 7
+#define OCR0B6 6
+#define OCR0B5 5
+#define OCR0B4 4
+#define OCR0B3 3
+#define OCR0B2 2
+#define OCR0B1 1
+#define OCR0B0 0
+
+/* PLL Control and Status Register */
+#define PLLCSR _SFR_IO8(0x29)
+/* PLLCSR */
+#define PCKE 2 /* PCK Enable */
+/* Bit 2 has been renamed in later versions of the datasheet. */
+#define PLLF 2 /* PLL Factor */
+#define PLLE 1 /* PLL Enable */
+#define PLOCK 0 /* PLL Lock Detector */
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+/* SPCR */
+#define SPIE 7 /* SPI Interrupt Enable */
+#define SPE 6 /* SPI Enable */
+#define DORD 5 /* Data Order */
+#define MSTR 4 /* Master/Slave Select */
+#define CPOL 3 /* Clock polarity */
+#define CPHA 2 /* Clock Phase */
+#define SPR1 1 /* SPI Clock Rate Select 1 */
+#define SPR0 0 /* SPI Clock Rate Select 0 */
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+/* SPSR */
+#define SPIF 7 /* SPI Interrupt Flag */
+#define WCOL 6 /* Write Collision Flag */
+#define SPI2X 0 /* Double SPI Speed Bit */
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+/* SPDR */
+#define SPD7 7
+#define SPD6 6
+#define SPD5 5
+#define SPD4 4
+#define SPD3 3
+#define SPD2 2
+#define SPD1 1
+#define SPD0 0
+
+/* Analog Comparator Status Register */
+#define ACSR _SFR_IO8(0x30)
+/* ACSR */
+#define ACCKDIV 7 /* Analog Comparator Clock Divider */
+#define AC2IF 6 /* Analog Comparator 2 Interrupt Flag Bit */
+#define AC1IF 5 /* Analog Comparator 1 Interrupt Flag Bit */
+#define AC0IF 4 /* Analog Comparator 0 Interrupt Flag Bit */
+#define AC2O 2 /* Analog Comparator 2 Output Bit */
+#define AC1O 1 /* Analog Comparator 1 Output Bit */
+#define AC0O 0 /* Analog Comparator 0 Output Bit */
+
+/* Monitor Data Register */
+#define MONDR _SFR_IO8(0x31)
+
+/* Monitor Stop Mode Control Register */
+#define MSMCR _SFR_IO8(0x32)
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+/* SMCR */
+#define SM2 3 /* Sleep Mode Select bit2 */
+#define SM1 2 /* Sleep Mode Select bit1 */
+#define SM0 1 /* Sleep Mode Select bit0 */
+#define SE 0 /* Sleep Enable */
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+/* MCUSR */
+#define WDRF 3 /* Watchdog Reset Flag */
+#define BORF 2 /* Brown-out Reset Flag */
+#define EXTRF 1 /* External Reset Flag */
+#define PORF 0 /* Power-on reset flag */
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+/* MCUCR */
+#define SPIPS 7 /* SPI Pin Select */
+#define PUD 4 /* Pull-up disable */
+#define IVSEL 1 /* Interrupt Vector Select */
+#define IVCE 0 /* Interrupt Vector Change Enable */
+
+/* Store Program Memory Control Register */
+#define SPMCSR _SFR_IO8(0x37)
+/* SPMCSR */
+#define SPMIE 7 /* SPM Interrupt Enable */
+#define RWWSB 6 /* Read While Write Section Busy */
+#define RWWSRE 4 /* Read While Write section read enable */
+#define BLBSET 3 /* Boot Lock Bit Set */
+#define PGWRT 2 /* Page Write */
+#define PGERS 1 /* Page Erase */
+#define SPMEN 0 /* Store Program Memory Enable */
+
+/* 0x3D..0x3E SP [defined in <avr/io.h>] */
+/* 0x3F SREG [defined in <avr/io.h>] */
+
+/* Watchdog Timer Control Register */
+#define WDTCSR _SFR_MEM8(0x60)
+/* WDTCSR */
+#define WDIF 7 /* Watchdog Timeout Interrupt Flag */
+#define WDIE 6 /* Watchdog Timeout Interrupt Enable */
+#define WDP3 5 /* Watchdog Timer Prescaler bit3 */
+#define WDCE 4 /* Watchdog Change Enable */
+#define WDE 3 /* Watchdog Enable */
+#define WDP2 2 /* Watchdog Timer Prescaler bit2 */
+#define WDP1 1 /* Watchdog Timer Prescaler bit1 */
+#define WDP0 0 /* Watchdog Timer Prescaler bit0 */
+
+/* Clock Prescaler Register */
+#define CLKPR _SFR_MEM8(0x61)
+/* CLKPR */
+#define CLKPCE 7 /* Clock Prescaler Change Enable */
+#define CLKPS3 3 /* Clock Prescaler Select bit3 */
+#define CLKPS2 2 /* Clock Prescaler Select bit2 */
+#define CLKPS1 1 /* Clock Prescaler Select bit1 */
+#define CLKPS0 0 /* Clock Prescaler Select bit0 */
+
+/* Power Reduction Register */
+#define PRR _SFR_MEM8(0x64)
+/* PRR */
+#define PRPSC2 7 /* Power Reduction PSC2 */
+#define PRPSC1 6 /* Power Reduction PSC1 */
+#define PRPSC0 5 /* Power Reduction PSC0 */
+#define PRTIM1 4 /* Power Reduction Timer/Counter1 */
+#define PRTIM0 3 /* Power Reduction Timer/Counter0 */
+#define PRSPI 2 /* Power Reduction Serial Peripheral Interface */
+#define PRUSART 1 /* Power Reduction USART */
+#define PRADC 0 /* Power Reduction ADC */
+
+/* Oscillator Calibration Value */
+#define OSCCAL _SFR_MEM8(0x66)
+/* OSCCAL */
+#define CAL6 6
+#define CAL5 5
+#define CAL4 4
+#define CAL3 3
+#define CAL2 2
+#define CAL1 1
+#define CAL0 0
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+/* EICRA */
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+/* TIMSK0 */
+#define OCIE0B 2 /* Output Compare Match B Interrupt Enable */
+#define OCIE0A 1 /* Output Compare Match A Interrupt Enable */
+#define TOIE0 0 /* Overflow Interrupt Enable */
+
+/* Timer/Counter1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+/* TIMSK1 */
+#define ICIE1 5 /* Input Capture Interrupt Enable */
+#define OCIE1B 2 /* Output Compare Match B Interrupt Enable */
+#define OCIE1A 1 /* Output Compare Match A Interrupt Enable */
+#define TOIE1 0 /* Overflow Interrupt Enable */
+
+/* Amplifier 0 Control and Status register */
+#define AMP0CSR _SFR_MEM8(0x76)
+#define AMP0EN 7
+#define AMP0IS 6
+#define AMP0G1 5
+#define AMP0G0 4
+#define AMP0TS1 1
+#define AMP0TS0 0
+
+/* Amplifier 1 Control and Status register */
+#define AMP1CSR _SFR_MEM8(0x77)
+#define AMP1EN 7
+#define AMP1IS 6
+#define AMP1G1 5
+#define AMP1G0 4
+#define AMP1TS1 1
+#define AMP1TS0 0
+
+/* ADC Result Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+/* ADCSRA */
+#define ADEN 7 /* ADC Enable */
+#define ADSC 6 /* ADC Start Conversion */
+#define ADATE 5 /* ADC Auto Trigger Enable */
+#define ADIF 4 /* ADC Interrupt Flag */
+#define ADIE 3 /* ADC Interrupt Enable */
+#define ADPS2 2 /* ADC Prescaler Select bit2 */
+#define ADPS1 1 /* ADC Prescaler Select bit1 */
+#define ADPS0 0 /* ADC Prescaler Select bit0 */
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+/* ADCSRB */
+#define ADHSM 7 /* ADC High Speed Mode */
+#define ADASCR 4
+#define ADTS3 3 /* ADC Auto Trigger Source 3 */
+#define ADTS2 2 /* ADC Auto Trigger Source 2 */
+#define ADTS1 1 /* ADC Auto Trigger Source 1 */
+#define ADTS0 0 /* ADC Auto Trigger Source 0 */
+
+/* ADC multiplexer Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+/* ADMUX */
+#define REFS1 7 /* Reference Selection bit1 */
+#define REFS0 6 /* Reference Selection bit0 */
+#define ADLAR 5 /* Left Adjust Result */
+#define MUX3 3 /* Analog Channel and Gain Selection bit3 */
+#define MUX2 2 /* Analog Channel and Gain Selection bit2 */
+#define MUX1 1 /* Analog Channel and Gain Selection bit1 */
+#define MUX0 0 /* Analog Channel and Gain Selection bit0 */
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+/* DIDR0 */
+#define ADC7D 7 /* ADC7 Digital input Disable */
+#define ADC6D 6 /* ADC6 Digital input Disable */
+#define ADC5D 5 /* ADC5 Digital input Disable */
+#define ADC4D 4 /* ADC4 Digital input Disable */
+#define ADC3D 3 /* ADC3 Digital input Disable */
+#define ADC2D 2 /* ADC2 Digital input Disable */
+#define ADC1D 1 /* ADC1 Digital input Disable */
+#define ADC0D 0 /* ADC0 Digital input Disable */
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+/* DIDR1 */
+#define ACMP0D 5
+#define AMP0PD 4
+#define AMP0ND 3
+#define ADC10D 2 /* ADC10 Digital input Disable */
+#define ADC9D 1 /* ADC9 Digital input Disable */
+#define ADC8D 0 /* ADC8 Digital input Disable */
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+/* TCCR1A */
+#define COM1A1 7 /* Comparet Ouput Mode 1A, bit 1 */
+#define COM1A0 6 /* Comparet Ouput Mode 1A, bit 0 */
+#define COM1B1 5 /* Compare Output Mode 1B, bit 1 */
+#define COM1B0 4 /* Compare Output Mode 1B, bit 0 */
+#define WGM11 1 /* Waveform Generation Mode */
+#define WGM10 0 /* Waveform Generation Mode */
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+/* TCCR1B */
+#define ICNC1 7 /* Input Capture 1 Noise Canceler */
+#define ICES1 6 /* Input Capture 1 Edge Select */
+#define WGM13 4 /* Waveform Generation Mode */
+#define WGM12 3 /* Waveform Generation Mode */
+#define CS12 2 /* Prescaler source of Timer/Counter 1 */
+#define CS11 1 /* Prescaler source of Timer/Counter 1 */
+#define CS10 0 /* Prescaler source of Timer/Counter 1 */
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+/* TCCR1C */
+#define FOC1A 7 /* Force Output Compare for Channel A */
+#define FOC1B 6 /* Force Output Compare for Channel B */
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+/* TCNT1H */
+#define TCNT115 7
+#define TCNT114 6
+#define TCNT113 5
+#define TCNT112 4
+#define TCNT111 3
+#define TCNT110 2
+#define TCNT19 1
+#define TCNT18 0
+/* TCNT1L */
+#define TCNT17 7
+#define TCNT16 6
+#define TCNT15 5
+#define TCNT14 4
+#define TCNT13 3
+#define TCNT12 2
+#define TCNT11 1
+#define TCNT10 0
+
+/* Input Capture Register 1 */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+/* ICR1H */
+#define ICR115 7
+#define ICR114 6
+#define ICR113 5
+#define ICR112 4
+#define ICR111 3
+#define ICR110 2
+#define ICR19 1
+#define ICR18 0
+/* ICR1L */
+#define ICR17 7
+#define ICR16 6
+#define ICR15 5
+#define ICR14 4
+#define ICR13 3
+#define ICR12 2
+#define ICR11 1
+#define ICR10 0
+
+/* Output Compare Register 1 A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+/* OCR1AH */
+#define OCR1A15 7
+#define OCR1A14 6
+#define OCR1A13 5
+#define OCR1A12 4
+#define OCR1A11 3
+#define OCR1A10 2
+#define OCR1A9 1
+#define OCR1A8 0
+/* OCR1AL */
+#define OCR1A7 7
+#define OCR1A6 6
+#define OCR1A5 5
+#define OCR1A4 4
+#define OCR1A3 3
+#define OCR1A2 2
+#define OCR1A1 1
+#define OCR1A0 0
+
+/* Output Compare Register 1 B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+/* OCR1BH */
+#define OCR1B15 7
+#define OCR1B14 6
+#define OCR1B13 5
+#define OCR1B12 4
+#define OCR1B11 3
+#define OCR1B10 2
+#define OCR1B9 1
+#define OCR1B8 0
+/* OCR1BL */
+#define OCR1B7 7
+#define OCR1B6 6
+#define OCR1B5 5
+#define OCR1B4 4
+#define OCR1B3 3
+#define OCR1B2 2
+#define OCR1B1 1
+#define OCR1B0 0
+
+/* PSC0 Interrupt Flag Register */
+#define PIFR0 _SFR_MEM8(0xA0)
+/* PIFR0 */
+#define POAC0B 7 /* PSC0 Output B Activity */
+#define POAC0A 6 /* PSC0 Output A Activity */
+#define PSEI0 5 /* PSC0 Synchro Error Interrupt */
+#define PEV0B 4 /* PSC0 External Event B Interrupt */
+#define PEV0A 3 /* PSC0 External Event A Interrupt */
+#define PRN01 2 /* PSC0 Ramp Number bit1 */
+#define PRN00 1 /* PSC0 Ramp Number bit0 */
+#define PEOP0 0 /* End Of PSC0 Interrupt */
+
+/* PSC0 Interrupt Mask Register */
+#define PIM0 _SFR_MEM8(0xA1)
+/* PIM0 */
+#define PSEIE0 5 /* PSC0 Synchro Error Interrupt Enable */
+#define PEVE0B 4 /* PSC0 External Event B Interrupt Enable */
+#define PEVE0A 3 /* PSC0 External Event A Interrupt Enable */
+#define PEOPE0 0 /* PSC0 End Of Cycle Interrupt Enable */
+
+/* PSC1 Interrupt Flag Register */
+#define PIFR1 _SFR_MEM8(0xA2)
+/* PIFR1 */
+#define POAC1B 7 /* PSC1 Output B Activity */
+#define POAC1A 6 /* PSC1 Output A Activity */
+#define PSEI1 5 /* PSC1 Synchro Error Interrupt */
+#define PEV1B 4 /* PSC1 External Event B Interrupt */
+#define PEV1A 3 /* PSC1 External Event A Interrupt */
+#define PRN11 2 /* PSC1 Ramp Number bit1 */
+#define PRN10 1 /* PSC1 Ramp Number bit0 */
+#define PEOP1 0 /* End Of PSC1 Interrupt */
+
+/* PSC1 Interrupt Mask Register */
+#define PIM1 _SFR_MEM8(0xA3)
+/* PIM1 */
+#define PSEIE1 5 /* PSC1 Synchro Error Interrupt Enable */
+#define PEVE1B 4 /* PSC1 External Event B Interrupt Enable */
+#define PEVE1A 3 /* PSC1 External Event A Interrupt Enable */
+#define PEOPE1 0 /* PSC1 End Of Cycle Interrupt Enable */
+
+/* PSC2 Interrupt Flag Register */
+#define PIFR2 _SFR_MEM8(0xA4)
+/* PIFR2 */
+#define POAC2B 7 /* PSC2 Output B Activity */
+#define POAC2A 6 /* PSC2 Output A Activity */
+#define PSEI2 5 /* PSC2 Synchro Error Interrupt */
+#define PEV2B 4 /* PSC2 External Event B Interrupt */
+#define PEV2A 3 /* PSC2 External Event A Interrupt */
+#define PRN21 2 /* PSC2 Ramp Number bit1 */
+#define PRN20 1 /* PSC2 Ramp Number bit0 */
+#define PEOP2 0 /* End Of PSC2 Interrupt */
+
+/* PSC2 Interrupt Mask Register */
+#define PIM2 _SFR_MEM8(0xA5)
+/* PIM2 */
+#define PSEIE2 5 /* PSC2 Synchro Error Interrupt Enable */
+#define PEVE2B 4 /* PSC2 External Event B Interrupt Enable */
+#define PEVE2A 3 /* PSC2 External Event A Interrupt Enable */
+#define PEOPE2 0 /* PSC2 End Of Cycle Interrupt Enable */
+
+/* Digital to Analog Conversion Control Register */
+#define DACON _SFR_MEM8(0xAA)
+/* DACON */
+#define DAATE 7 /* DAC Auto Trigger Enable bit */
+#define DATS2 6 /* DAC Trigger Selection bit2 */
+#define DATS1 5 /* DAC Trigger Selection bit1 */
+#define DATS0 4 /* DAC Trigger Selection bit0 */
+#define DALA 2 /* Digital to Analog Left Adjust */
+#define DAOE 1 /* Digital to Analog Output Enable bit */
+#define DAEN 0 /* Digital to Analog Enable bit */
+
+/* Digital to Analog Converter input Register */
+#define DAC _SFR_MEM16(0xAB)
+#define DACL _SFR_MEM8(0xAB)
+#define DACH _SFR_MEM8(0xAC)
+
+/* Analog Comparator 0 Control Register */
+#define AC0CON _SFR_MEM8(0xAD)
+/* AC0CON */
+#define AC0EN 7 /* Analog Comparator 0 Enable Bit */
+#define AC0IE 6 /* Analog Comparator 0 Interrupt Enable bit */
+#define AC0IS1 5 /* Analog Comparator 0 Interrupt Select bit1 */
+#define AC0IS0 4 /* Analog Comparator 0 Interrupt Select bit0 */
+#define AC0M2 2 /* Analog Comparator 0 Multiplexer register bit2 */
+#define AC0M1 1 /* Analog Comparator 0 Multiplexer register bit1 */
+#define AC0M0 0 /* Analog Comparator 0 Multiplexer register bit0 */
+
+/* Analog Comparator 1 Control Register */
+#define AC1CON _SFR_MEM8(0xAE)
+/* AC1CON */
+#define AC1EN 7 /* Analog Comparator 1 Enable Bit */
+#define AC1IE 6 /* Analog Comparator 1 Interrupt Enable bit */
+#define AC1IS1 5 /* Analog Comparator 1 Interrupt Select bit1 */
+#define AC1IS0 4 /* Analog Comparator 1 Interrupt Select bit0 */
+#define AC1ICE 3 /* Analog Comparator 1 Interrupt Capture Enable bit */
+#define AC1M2 2 /* Analog Comparator 1 Multiplexer register bit2 */
+#define AC1M1 1 /* Analog Comparator 1 Multiplexer register bit1 */
+#define AC1M0 0 /* Analog Comparator 1 Multiplexer register bit0 */
+
+/* Analog Comparator 2 Control Register */
+#define AC2CON _SFR_MEM8(0xAF)
+/* AC2CON */
+#define AC2EN 7 /* Analog Comparator 2 Enable Bit */
+#define AC2IE 6 /* Analog Comparator 2 Interrupt Enable bit */
+#define AC2IS1 5 /* Analog Comparator 2 Interrupt Select bit1 */
+#define AC2IS0 4 /* Analog Comparator 2 Interrupt Select bit0 */
+#define AC2M2 2 /* Analog Comparator 2 Multiplexer register bit2 */
+#define AC2M1 1 /* Analog Comparator 2 Multiplexer register bit1 */
+#define AC2M0 0 /* Analog Comparator 2 Multiplexer register bit0 */
+
+/* USART Control and Status Register A */
+#define UCSRA _SFR_MEM8(0xC0)
+/* UCSRA */
+#define RXC 7 /* USART Receive Complete */
+#define TXC 6 /* USART Transmit Complete */
+#define UDRE 5 /* USART Data Register Empty */
+#define FE 4 /* Frame Error */
+#define DOR 3 /* Data OverRun */
+#define UPE 2 /* USART Parity Error */
+#define U2X 1 /* Double the USART Transmission Speed */
+#define MPCM 0 /* Multi-processor Communication Mode */
+
+/* USART Control and Status Register B */
+#define UCSRB _SFR_MEM8(0xC1)
+/* UCSRB */
+#define RXCIE 7 /* RX Complete Interrupt Enable */
+#define TXCIE 6 /* TX Complete Interrupt Enable */
+#define UDRIE 5 /* USART Data Register Empty Interrupt Enable */
+#define RXEN 4 /* Receiver Enable */
+#define TXEN 3 /* Transmitter Enable */
+#define UCSZ2 2 /* Character Size */
+#define RXB8 1 /* Receive Data Bit 8 */
+#define TXB8 0 /* Transmit Data Bit 8 */
+
+/* USART Control and Status Register C */
+#define UCSRC _SFR_MEM8(0xC2)
+/* UCSRC */
+#define UMSEL 6 /* USART Mode Select */
+#define UPM1 5 /* Parity Mode bit1 */
+#define UPM0 4 /* Parity Mode bit0 */
+#define USBS 3 /* Stop Bit Select */
+#define UCSZ1 2 /* Character Size bit1 */
+#define UCSZ0 1 /* Character Size bit0 */
+#define UCPOL 0 /* Clock Polarity */
+
+/* USART Baud Rate Register */
+#define UBRR _SFR_MEM16(0xC4)
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRRH _SFR_MEM8(0xC5)
+
+/* USART I/O Data Register */
+#define UDR _SFR_MEM8(0xC6)
+
+/* EUSART Control and Status Register A */
+#define EUCSRA _SFR_MEM8(0xC8)
+/* EUCSRA */
+#define UTxS3 7 /* EUSART Transmit Character Size bit3 */
+#define UTxS2 6 /* EUSART Transmit Character Size bit2 */
+#define UTxS1 5 /* EUSART Transmit Character Size bit1 */
+#define UTxS0 4 /* EUSART Transmit Character Size bit0 */
+#define URxS3 3 /* EUSART Receive Character Size bit3 */
+#define URxS2 2 /* EUSART Receive Character Size bit2 */
+#define URxS1 1 /* EUSART Receive Character Size bit1 */
+#define URxS0 0 /* EUSART Receive Character Size bit0 */
+
+/* EUSART Control and Status Register B */
+#define EUCSRB _SFR_MEM8(0xC9)
+/* EUCSRB */
+#define EUSART 4 /* EUSART Enable Bit */
+#define EUSBS 3 /* EUSBS Enable Bit */
+#define EMCH 1 /* Manchester mode */
+#define BODR 0 /* Bit Order */
+
+/* EUSART Control and Status Register C */
+#define EUCSRC _SFR_MEM8(0xCA)
+/* EUCSRC */
+#define FEM 3 /* Frame Error Manchester */
+#define F1617 2
+#define STP1 1 /* Stop bits values bit1 */
+#define STP0 0 /* Stop bits values bit0 */
+
+/* Manchester receiver Baud Rate Registers */
+#define MUBRR _SFR_MEM16(0xCC)
+#define MUBRRL _SFR_MEM8(0xCC)
+#define MUBRRH _SFR_MEM8(0xCD)
+
+/* EUSART I/O Data Register */
+#define EUDR _SFR_MEM8(0xCE)
+
+/* PSC 0 Synchro and Output Configuration */
+#define PSOC0 _SFR_MEM8(0xD0)
+/* PSOC0 */
+#define PSYNC01 5 /* Synchronization Out for ADC Selection bit1 */
+#define PSYNC00 4 /* Synchronization Out for ADC Selection bit0 */
+#define POEN0B 2 /* PSC 0 OUT Part B Output Enable */
+#define POEN0A 0 /* PSC 0 OUT Part A Output Enable */
+
+/* Output Compare SA Registers */
+#define OCR0SA _SFR_MEM16(0xD2)
+#define OCR0SAL _SFR_MEM8(0xD2)
+#define OCR0SAH _SFR_MEM8(0xD3)
+
+/* Output Compare RA Registers */
+#define OCR0RA _SFR_MEM16(0xD4)
+#define OCR0RAL _SFR_MEM8(0xD4)
+#define OCR0RAH _SFR_MEM8(0xD5)
+
+/* Output Compare SB Registers */
+#define OCR0SB _SFR_MEM16(0xD6)
+#define OCR0SBL _SFR_MEM8(0xD6)
+#define OCR0SBH _SFR_MEM8(0xD7)
+
+/* Output Compare RB Registers */
+#define OCR0RB _SFR_MEM16(0xD8)
+#define OCR0RBL _SFR_MEM8(0xD8)
+#define OCR0RBH _SFR_MEM8(0xD9)
+
+/* PSC 0 Configuration Register */
+#define PCNF0 _SFR_MEM8(0xDA)
+/* PCNF0 */
+#define PFIFTY0 7 /* PSC 0 Fifty */
+#define PALOCK0 6 /* PSC 0 Autolock */
+#define PLOCK0 5 /* PSC 0 Lock */
+#define PMODE01 4 /* PSC 0 Mode bit1 */
+#define PMODE00 3 /* PSC 0 Mode bit0 */
+#define POP0 2 /* PSC 0 Output Polarity */
+#define PCLKSEL0 1 /* PSC 0 Input Clock Select */
+
+/* PSC 0 Control Register */
+#define PCTL0 _SFR_MEM8(0xDB)
+/* PCTL0 */
+#define PPRE01 7 /* PSC 0 Prescaler Select bit1 */
+#define PPRE00 6 /* PSC 0 Prescaler Select bit0 */
+#define PBFM0 5 /* Balance Flank Width Modulation */
+#define PAOC0B 4 /* PSC 0 Asynchronous Output Control B */
+#define PAOC0A 3 /* PSC 0 Asynchronous Output Control A */
+#define PARUN0 2 /* PSC 0 Autorun */
+#define PCCYC0 1 /* PSC 0 Complete Cycle */
+#define PRUN0 0 /* PSC 0 Run */
+
+/* PSC 0 Input A Control Register */
+#define PFRC0A _SFR_MEM8(0xDC)
+/* PFRC0A */
+#define PCAE0A 7 /* PSC 0 Capture Enable Input Part A */
+#define PISEL0A 6 /* PSC 0 Input Select for Part A */
+#define PELEV0A 5 /* PSC 0 Edge Level Selector of Input Part A */
+#define PFLTE0A 4 /* PSC 0 Filter Enable on Input Part A */
+#define PRFM0A3 3 /* PSC 0 Fault Mode bit3 */
+#define PRFM0A2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0A1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0A0 0 /* PSC 0 Fault Mode bit0 */
+
+/* PSC 0 Input B Control Register */
+#define PFRC0B _SFR_MEM8(0xDD)
+/* PFRC0B */
+#define PCAE0B 7 /* PSC 0 Capture Enable Input Part B */
+#define PISEL0B 6 /* PSC 0 Input Select for Part B */
+#define PELEV0B 5 /* PSC 0 Edge Level Selector of Input Part B */
+#define PFLTE0B 4 /* PSC 0 Filter Enable on Input Part B */
+#define PRFM0B3 3 /* PSC 0 Fault Mode bit3 */
+#define PRFM0B2 2 /* PSC 0 Fault Mode bit2 */
+#define PRFM0B1 1 /* PSC 0 Fault Mode bit1 */
+#define PRFM0B0 0 /* PSC 0 Fault Mode bit0 */
+
+/* PSC 0 Input Capture Registers */
+#define PICR0 _SFR_MEM16(0xDE)
+
+#define PICR0L _SFR_MEM8(0xDE)
+
+#define PICR0H _SFR_MEM8(0xDF)
+#define PCST0 7 /* PSC Capture Software Trig bit */
+ /* not implemented on AT90PWM2/AT90PWM3 */
+
+/* PSC 1 Synchro and Output Configuration */
+#define PSOC1 _SFR_MEM8(0xE0)
+/* PSOC1 */
+#define PSYNC11 5 /* Synchronization Out for ADC Selection bit1 */
+#define PSYNC10 4 /* Synchronization Out for ADC Selection bit0 */
+#define POEN1B 2 /* PSC 1 OUT Part B Output Enable */
+#define POEN1A 0 /* PSC 1 OUT Part A Output Enable */
+
+/* Output Compare SA Registers */
+#define OCR1SA _SFR_MEM16(0xE2)
+#define OCR1SAL _SFR_MEM8(0xE2)
+#define OCR1SAH _SFR_MEM8(0xE3)
+
+/* Output Compare RA Registers */
+#define OCR1RA _SFR_MEM16(0xE4)
+#define OCR1RAL _SFR_MEM8(0xE4)
+#define OCR1RAH _SFR_MEM8(0xE5)
+
+/* Output Compare SB Registers */
+#define OCR1SB _SFR_MEM16(0xE6)
+#define OCR1SBL _SFR_MEM8(0xE6)
+#define OCR1SBH _SFR_MEM8(0xE7)
+
+/* Output Compare RB Registers */
+#define OCR1RB _SFR_MEM16(0xE8)
+#define OCR1RBL _SFR_MEM8(0xE8)
+#define OCR1RBH _SFR_MEM8(0xE9)
+
+/* PSC 1 Configuration Register */
+#define PCNF1 _SFR_MEM8(0xEA)
+/* PCNF1 */
+#define PFIFTY1 7 /* PSC 1 Fifty */
+#define PALOCK1 6 /* PSC 1 Autolock */
+#define PLOCK1 5 /* PSC 1 Lock */
+#define PMODE11 4 /* PSC 1 Mode bit1 */
+#define PMODE10 3 /* PSC 1 Mode bit0 */
+#define POP1 2 /* PSC 1 Output Polarity */
+#define PCLKSEL1 1 /* PSC 1 Input Clock Select */
+
+/* PSC 1 Control Register */
+#define PCTL1 _SFR_MEM8(0xEB)
+/* PCTL1 */
+#define PPRE11 7 /* PSC 1 Prescaler Select bit1 */
+#define PPRE10 6 /* PSC 1 Prescaler Select bit0 */
+#define PBFM1 5 /* Balance Flank Width Modulation */
+#define PAOC1B 4 /* PSC 1 Asynchronous Output Control B */
+#define PAOC1A 3 /* PSC 1 Asynchronous Output Control A */
+#define PARUN1 2 /* PSC 1 Autorun */
+#define PCCYC1 1 /* PSC 1 Complete Cycle */
+#define PRUN1 0 /* PSC 1 Run */
+
+/* PSC 1 Input A Control Register */
+#define PFRC1A _SFR_MEM8(0xEC)
+/* PFRC1A */
+#define PCAE1A 7 /* PSC 1 Capture Enable Input Part A */
+#define PISEL1A 6 /* PSC 1 Input Select for Part A */
+#define PELEV1A 5 /* PSC 1 Edge Level Selector of Input Part A */
+#define PFLTE1A 4 /* PSC 1 Filter Enable on Input Part A */
+#define PRFM1A3 3 /* PSC 1 Fault Mode bit3 */
+#define PRFM1A2 2 /* PSC 1 Fault Mode bit2 */
+#define PRFM1A1 1 /* PSC 1 Fault Mode bit1 */
+#define PRFM1A0 0 /* PSC 1 Fault Mode bit0 */
+
+/* PSC 1 Input B Control Register */
+#define PFRC1B _SFR_MEM8(0xED)
+/* PFRC1B */
+#define PCAE1B 7 /* PSC 1 Capture Enable Input Part B */
+#define PISEL1B 6 /* PSC 1 Input Select for Part B */
+#define PELEV1B 5 /* PSC 1 Edge Level Selector of Input Part B */
+#define PFLTE1B 4 /* PSC 1 Filter Enable on Input Part B */
+#define PRFM1B3 3 /* PSC 1 Fault Mode bit3 */
+#define PRFM1B2 2 /* PSC 1 Fault Mode bit2 */
+#define PRFM1B1 1 /* PSC 1 Fault Mode bit1 */
+#define PRFM1B0 0 /* PSC 1 Fault Mode bit0 */
+
+/* PSC 1 Input Capture Registers */
+#define PICR1 _SFR_MEM16(0xEE)
+
+#define PICR1L _SFR_MEM8(0xEE)
+
+#define PICR1H _SFR_MEM8(0xEF)
+#define PCST1 7 /* PSC Capture Software Trig bit */
+ /* not implemented on AT90PWM2/AT90PWM3 */
+
+/* PSC 2 Synchro and Output Configuration */
+#define PSOC2 _SFR_MEM8(0xF0)
+/* PSOC2 */
+#define POS23 7 /* PSCOUT23 Selection */
+#define POS22 6 /* PSCOUT22 Selection */
+#define PSYNC21 5 /* Synchronization Out for ADC Selection bit1 */
+#define PSYNC20 4 /* Synchronization Out for ADC Selection bit0 */
+#define POEN2D 3 /* PSCOUT23 Output Enable */
+#define POEN2B 2 /* PSC 2 OUT Part B Output Enable */
+#define POEN2C 1 /* PSCOUT22 Output Enable */
+#define POEN2A 0 /* PSC 2 OUT Part A Output Enable */
+
+/* PSC 2 Output Matrix */
+#define POM2 _SFR_MEM8(0xF1)
+/* POM2 */
+#define POMV2B3 7 /* Output Matrix Output B Ramp 3 */
+#define POMV2B2 6 /* Output Matrix Output B Ramp 2 */
+#define POMV2B1 5 /* Output Matrix Output B Ramp 1 */
+#define POMV2B0 4 /* Output Matrix Output B Ramp 0 */
+#define POMV2A3 3 /* Output Matrix Output A Ramp 3 */
+#define POMV2A2 2 /* Output Matrix Output A Ramp 2 */
+#define POMV2A1 1 /* Output Matrix Output A Ramp 1 */
+#define POMV2A0 0 /* Output Matrix Output A Ramp 0 */
+
+/* Output Compare SA Registers */
+#define OCR2SA _SFR_MEM16(0xF2)
+#define OCR2SAL _SFR_MEM8(0xF2)
+#define OCR2SAH _SFR_MEM8(0xF3)
+
+/* Output Compare RA Registers */
+#define OCR2RA _SFR_MEM16(0xF4)
+#define OCR2RAL _SFR_MEM8(0xF4)
+#define OCR2RAH _SFR_MEM8(0xF5)
+
+/* Output Compare SB Registers */
+#define OCR2SB _SFR_MEM16(0xF6)
+#define OCR2SBL _SFR_MEM8(0xF6)
+#define OCR2SBH _SFR_MEM8(0xF7)
+
+/* Output Compare RB Registers */
+#define OCR2RB _SFR_MEM16(0xF8)
+#define OCR2RBL _SFR_MEM8(0xF8)
+#define OCR2RBH _SFR_MEM8(0xF9)
+
+/* PSC 2 Configuration Register */
+#define PCNF2 _SFR_MEM8(0xFA)
+/* PCNF2 */
+#define PFIFTY2 7 /* PSC 2 Fifty */
+#define PALOCK2 6 /* PSC 2 Autolock */
+#define PLOCK2 5 /* PSC 2 Lock */
+#define PMODE21 4 /* PSC 2 Mode bit1 */
+#define PMODE20 3 /* PSC 2 Mode bit0 */
+#define POP2 2 /* PSC 2 Output Polarity */
+#define PCLKSEL2 1 /* PSC 2 Input Clock Select */
+#define POME2 0 /* PSC 2 Output Matrix Enable */
+
+/* PSC 2 Control Register */
+#define PCTL2 _SFR_MEM8(0xFB)
+/* PCTL2 */
+#define PPRE21 7 /* PSC 2 Prescaler Select bit1 */
+#define PPRE20 6 /* PSC 2 Prescaler Select bit0 */
+#define PBFM2 5 /* Balance Flank Width Modulation */
+#define PAOC2B 4 /* PSC 2 Asynchronous Output Control B */
+#define PAOC2A 3 /* PSC 2 Asynchronous Output Control A */
+#define PARUN2 2 /* PSC 2 Autorun */
+#define PCCYC2 1 /* PSC 2 Complete Cycle */
+#define PRUN2 0 /* PSC 2 Run */
+
+/* PSC 2 Input A Control Register */
+#define PFRC2A _SFR_MEM8(0xFC)
+/* PFRC2A */
+#define PCAE2A 7 /* PSC 2 Capture Enable Input Part A */
+#define PISEL2A 6 /* PSC 2 Input Select for Part A */
+#define PELEV2A 5 /* PSC 2 Edge Level Selector of Input Part A */
+#define PFLTE2A 4 /* PSC 2 Filter Enable on Input Part A */
+#define PRFM2A3 3 /* PSC 2 Fault Mode bit3 */
+#define PRFM2A2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2A1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2A0 0 /* PSC 2 Fault Mode bit0 */
+
+/* PSC 2 Input B Control Register */
+#define PFRC2B _SFR_MEM8(0xFD)
+/* PFRC2B */
+#define PCAE2B 7 /* PSC 2 Capture Enable Input Part B */
+#define PISEL2B 6 /* PSC 2 Input Select for Part B */
+#define PELEV2B 5 /* PSC 2 Edge Level Selector of Input Part B */
+#define PFLTE2B 4 /* PSC 2 Filter Enable on Input Part B */
+#define PRFM2B3 3 /* PSC 2 Fault Mode bit3 */
+#define PRFM2B2 2 /* PSC 2 Fault Mode bit2 */
+#define PRFM2B1 1 /* PSC 2 Fault Mode bit1 */
+#define PRFM2B0 0 /* PSC 2 Fault Mode bit0 */
+
+/* PSC 2 Input Capture Registers */
+#define PICR2 _SFR_MEM16(0xFE)
+
+#define PICR2L _SFR_MEM8(0xFE)
+
+#define PICR2H _SFR_MEM8(0xFF)
+#define PCST2 7 /* PSC Capture Software Trig bit */
+ /* not implemented on AT90PWM2/AT90PWM3 */
+
+
+/* Interrupt vectors */
+/* PSC2 Capture Event */
+#define PSC2_CAPT_vect _VECTOR(1)
+#define SIG_PSC2_CAPTURE _VECTOR(1)
+
+/* PSC2 End Cycle */
+#define PSC2_EC_vect _VECTOR(2)
+#define SIG_PSC2_END_CYCLE _VECTOR(2)
+
+/* PSC1 Capture Event */
+#define PSC1_CAPT_vect _VECTOR(3)
+#define SIG_PSC1_CAPTURE _VECTOR(3)
+
+/* PSC1 End Cycle */
+#define PSC1_EC_vect _VECTOR(4)
+#define SIG_PSC1_END_CYCLE _VECTOR(4)
+
+/* PSC0 Capture Event */
+#define PSC0_CAPT_vect _VECTOR(5)
+#define SIG_PSC0_CAPTURE _VECTOR(5)
+
+/* PSC0 End Cycle */
+#define PSC0_EC_vect _VECTOR(6)
+#define SIG_PSC0_END_CYCLE _VECTOR(6)
+
+/* Analog Comparator 0 */
+#define ANALOG_COMP_0_vect _VECTOR(7)
+#define SIG_COMPARATOR0 _VECTOR(7)
+
+/* Analog Comparator 1 */
+#define ANALOG_COMP_1_vect _VECTOR(8)
+#define SIG_COMPARATOR1 _VECTOR(8)
+
+/* Analog Comparator 2 */
+#define ANALOG_COMP_2_vect _VECTOR(9)
+#define SIG_COMPARATOR2 _VECTOR(9)
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(10)
+#define SIG_INTERRUPT0 _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+#define SIG_INPUT_CAPTURE1 _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1_A _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1_B _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+#define SIG_OVERFLOW1 _VECTOR(15)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMP_A_vect _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0_A _VECTOR(16)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(17)
+#define SIG_OVERFLOW0 _VECTOR(17)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(18)
+#define SIG_ADC _VECTOR(18)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(19)
+#define SIG_INTERRUPT1 _VECTOR(19)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(20)
+#define SIG_SPI _VECTOR(20)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(21)
+#define SIG_USART_RECV _VECTOR(21)
+#define SIG_UART_RECV _VECTOR(21)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(22)
+#define SIG_USART_DATA _VECTOR(22)
+#define SIG_UART_DATA _VECTOR(22)
+
+/* USART, Tx Complete */
+#define USART_TX_vect _VECTOR(23)
+#define SIG_USART_TRANS _VECTOR(23)
+#define SIG_UART_TRANS _VECTOR(23)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(24)
+#define SIG_INTERRUPT2 _VECTOR(24)
+
+/* Watchdog Timeout Interrupt */
+#define WDT_vect _VECTOR(25)
+#define SIG_WDT _VECTOR(25)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(25)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(26)
+#define SIG_EEPROM_READY _VECTOR(26)
+
+/* Timer Counter 0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(27)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(27)
+#define SIG_OUTPUT_COMPARE0_B _VECTOR(27)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(28)
+#define SIG_INTERRUPT3 _VECTOR(28)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(31)
+#define SIG_SPM_READY _VECTOR(31)
+
+#define _VECTORS_SIZE 64
+
+/* Constants */
+#define SPM_PAGESIZE 64
+
+#define RAMEND 0x02FF
+#define XRAMEND RAMEND
+#define E2END 0x01FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x0FFF
+
+
+/* Fuse Information */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Diasble */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_PSCRV (unsigned char)~_BV(4)
+#define FUSE_PSC0RB (unsigned char)~_BV(5)
+#define FUSE_PSC1RB (unsigned char)~_BV(6)
+#define FUSE_PSC2RB (unsigned char)~_BV(7)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+#endif /* _AVR_IO90PWMX_H_ */
diff --git a/cpukit/score/cpu/avr/avr/io90scr100.h b/cpukit/score/cpu/avr/avr/io90scr100.h
new file mode 100644
index 0000000000..c863b391ac
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/io90scr100.h
@@ -0,0 +1,1698 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/io90scr100.h - definitions for AT90SCR100 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "io90scr100.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_AT90SCR100_H_
+#define _AVR_AT90SCR100_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+#define PINE3 3
+#define PINE4 4
+#define PINE5 5
+#define PINE6 6
+#define PINE7 7
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+#define DDE3 3
+#define DDE4 4
+#define DDE5 5
+#define DDE6 6
+#define DDE7 7
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+#define PORTE3 3
+#define PORTE4 4
+#define PORTE5 5
+#define PORTE6 6
+#define PORTE7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define EIRR _SFR_IO8(0x1A)
+#define INTD2 2
+#define INTD3 3
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define RAMPZ _SFR_IO8(0x3B)
+#define RAMPZ0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PLLCR _SFR_MEM8(0x62)
+#define ON 0
+#define LOCK 1
+#define PLLMUX 7
+
+#define SMONCR _SFR_MEM8(0x63)
+#define SMONEN 0
+#define SMONIE 1
+#define SMONIF 4
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSBH 0
+#define PRUSB 1
+#define PRHSSPI 2
+#define PRSCI 3
+#define PRAES 4
+#define PRKB 5
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#define PCMSK3 _SFR_MEM8(0x73)
+
+#define LEDCR _SFR_MEM8(0x75)
+#define LED00 0
+#define LED01 1
+#define LED10 2
+#define LED11 3
+#define LED20 4
+#define LED21 5
+#define lED30 6
+#define LED31 7
+
+#define AESCR _SFR_MEM8(0x78)
+#define AESGO 0
+#define ENCRYPT 1
+#define KS 3
+#define KEYGN 4
+#define AUTOKEY 5
+#define AESIF 6
+#define AESIE 7
+
+#define AESACR _SFR_MEM8(0x79)
+#define KD 0
+#define AUTOINC 1
+#define MANINC 2
+#define XOR 3
+
+#define AESADDR _SFR_MEM8(0x7A)
+#define ADDR0 0
+#define ADDR1 1
+#define ADDR2 2
+#define ADDR3 3
+#define ADDR4 4
+#define ADDR5 5
+#define ADDR6 6
+#define ADDR7 7
+
+#define AESDR _SFR_MEM8(0x7B)
+#define DATA0 0
+#define DATA1 1
+#define DATA2 2
+#define DATA3 3
+#define DATA4 4
+#define DATA5 5
+#define DATA6 6
+#define DATA7 7
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define KBLSR _SFR_MEM8(0x8D)
+#define KBLS0 0
+#define KBLS1 1
+#define KBLS2 2
+#define KBLS3 3
+#define KBLS4 4
+#define KBLS5 5
+#define KBLS6 6
+#define KBLS7 7
+
+#define KBER _SFR_MEM8(0x8E)
+#define KBE0 0
+#define KBE1 1
+#define KBE2 2
+#define KBE3 3
+#define KBE4 4
+#define KBE5 5
+#define KBE6 6
+#define KBE7 7
+
+#define KBFR _SFR_MEM8(0x8F)
+#define KBF0 0
+#define KBF1 1
+#define KBF2 2
+#define KBF3 3
+#define KBF4 4
+#define KBF5 5
+#define KBF6 6
+#define KBF7 7
+
+#define RDWDR _SFR_MEM8(0x90)
+#define RDD0 0
+#define RDD1 1
+#define RDD2 2
+#define RDD3 3
+#define RDD4 4
+#define RDD5 5
+#define RDD6 6
+#define RDD7 7
+
+#define LFSR0 _SFR_MEM8(0x91)
+#define LFSD0 0
+#define LFSD1 1
+#define LFSD2 2
+#define LFSD3 3
+#define LFSD4 4
+#define LFSD5 5
+#define LFSD6 6
+#define LFSD7 7
+
+#define LFSR1 _SFR_MEM8(0x92)
+#define LFSD8 0
+#define LFSD9 1
+#define LFSD10 2
+#define LFSD11 3
+#define LFSD12 4
+#define LFSD13 5
+#define LFSD14 6
+#define LFSD15 7
+
+#define LFSR2 _SFR_MEM8(0x93)
+#define LFSD16 0
+#define LFSD17 1
+#define LFSD18 2
+#define LFSD19 3
+#define LFSD20 4
+#define LFSD21 5
+#define LFSD22 6
+#define LFSD23 7
+
+#define LFSR3 _SFR_MEM8(0x94)
+#define LFSD24 0
+#define LFSD25 1
+#define LFSD26 2
+#define LFSD27 3
+#define LFSD28 4
+#define LFSD29 5
+#define LFSD30 6
+#define LFSD31 7
+
+#define RNGCR _SFR_MEM8(0x95)
+#define ROSCE 0
+
+#define UHSR _SFR_MEM8(0x99)
+#define SPEED 3
+
+#define UPINT _SFR_MEM8(0x9A)
+#define PINT0 0
+#define PINT1 1
+#define PINT2 2
+#define PINT3 3
+
+#define UPBCX _SFR_MEM16(0x9B)
+
+#define UPBCXL _SFR_MEM8(0x9B)
+#define PBYTCT0 0
+#define PBYTCT1 1
+#define PBYTCT2 2
+#define PBYTCT3 3
+#define PBYTCT4 4
+#define PBYTCT5 5
+#define PBYTCT6 6
+#define PBYTCT7 7
+
+#define UPBCXH _SFR_MEM8(0x9C)
+#define PBYTCT8 0
+#define PBYTCT9 1
+#define PBYTCT10 2
+
+#define UPERRX _SFR_MEM8(0x9D)
+#define DATATGL 0
+#define DATAPID 1
+#define PID 2
+#define PTIMEOUT 3
+#define CRC16 4
+#define COUNTER0 5
+#define COUNTER1 6
+
+#define UHCR _SFR_MEM8(0x9E)
+#define SOFEN 0
+#define RESET 1
+#define RESUME 2
+#define FRZCLK 4
+#define PAD0 5
+#define PAD1 6
+#define UHEN 7
+
+#define UHINT _SFR_MEM8(0x9F)
+#define DCONNI 0
+#define DDISCI 1
+#define RSTI 2
+#define RSMEDI 3
+#define RXRSMI 4
+#define HSOFI 5
+#define HWUPI 6
+
+#define UHIEN _SFR_MEM8(0xA0)
+#define DCONNE 0
+#define DDISCE 1
+#define RSTE 2
+#define RSMEDE 3
+#define RXRSME 4
+#define HSOFE 5
+#define HWUPE 6
+
+#define UHADDR _SFR_MEM8(0xA1)
+#define HADDR0 0
+#define HADDR1 1
+#define HADDR2 2
+#define HADDR3 3
+#define HADDR4 4
+#define HADDR5 5
+#define HADDR6 6
+
+#define UHFNUM _SFR_MEM16(0xA2)
+
+#define UHFNUML _SFR_MEM8(0xA2)
+#define FNUM0 0
+#define FNUM1 1
+#define FNUM2 2
+#define FNUM3 3
+#define FNUM4 4
+#define FNUM5 5
+#define FNUM6 6
+#define FNUM7 7
+
+#define UHFNUMH _SFR_MEM8(0xA3)
+#define FNUM8 0
+#define FNUM9 1
+#define FNUM10 2
+
+#define UHFLEN _SFR_MEM8(0xA4)
+#define FLEN0 0
+#define FLEN1 1
+#define FLEN2 2
+#define FLEN3 3
+#define FLEN4 4
+#define FLEN5 5
+#define FLEN6 6
+#define FLEN7 7
+
+#define UPINRQX _SFR_MEM8(0xA5)
+#define INRQ0 0
+#define INRQ1 1
+#define INRQ2 2
+#define INRQ3 3
+#define INRQ4 4
+#define INRQ5 5
+#define INRQ6 6
+#define INRQ7 7
+
+#define UPINTX _SFR_MEM8(0xA6)
+#define RXINI 0
+#define RXSTALLI 1
+#define TXOUTI 2
+#define TXSTPI 3
+#define PERRI 4
+#define RWAL 5
+#define NAKEDI 6
+#define FIFOCON 7
+
+#define UPNUM _SFR_MEM8(0xA7)
+#define PNUM0 0
+#define PNUM1 1
+
+#define UPRST _SFR_MEM8(0xA8)
+#define P0RST 0
+#define P1RST 1
+#define P2RST 2
+#define P3RST 3
+
+#define UPCRX _SFR_MEM8(0xA9)
+#define PEN 0
+#define RSTDT 3
+#define INMODE 5
+#define PFREEZE 6
+
+#define UPCFG0X _SFR_MEM8(0xAA)
+#define PEPNUM0 0
+#define PEPNUM1 1
+#define PEPNUM2 2
+#define PEPNUM3 3
+#define PTOKEN0 4
+#define PTOKEN1 5
+#define PTYPE0 6
+#define PTYPE1 7
+
+#define UPCFG1X _SFR_MEM8(0xAB)
+#define ALLOC 1
+#define PBK0 2
+#define PBK1 3
+#define PSIZE0 4
+#define PSIZE1 5
+#define PSIZE2 6
+
+#define UPSTAX _SFR_MEM8(0xAC)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UPCFG2X _SFR_MEM8(0xAD)
+#define INTFRQ0 0
+#define INTFRQ1 1
+#define INTFRQ2 2
+#define INTFRQ3 3
+#define INTFRQ4 4
+#define INTFRQ5 5
+#define INTFRQ6 6
+#define INTFRQ7 7
+
+#define UPIENX _SFR_MEM8(0xAE)
+#define RXINE 0
+#define RXSTALLE 1
+#define TXOUTE 2
+#define TXSTPE 3
+#define PERRE 4
+#define NAKEDE 6
+#define FLERRE 7
+
+#define UPDATX _SFR_MEM8(0xAF)
+#define PDAT0 0
+#define PDAT1 1
+#define PDAT2 2
+#define PDAT3 3
+#define PDAT4 4
+#define PDAT5 5
+#define PDAT6 6
+#define PDAT7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A0 0
+#define OCR2A1 1
+#define OCR2A2 2
+#define OCR2A3 3
+#define OCR2A4 4
+#define OCR2A5 5
+#define OCR2A6 6
+#define OCR2A7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2B0 0
+#define OCR2B1 1
+#define OCR2B2 2
+#define OCR2B3 3
+#define OCR2B4 4
+#define OCR2B5 5
+#define OCR2B6 6
+#define OCR2B7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR00 0
+#define UBRR01 1
+#define UBRR02 2
+#define UBRR03 3
+#define UBRR04 4
+#define UBRR05 5
+#define UBRR06 6
+#define UBRR07 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR08 0
+#define UBRR09 1
+#define UBRR010 2
+#define UBRR011 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR00 0
+#define UDR01 1
+#define UDR02 2
+#define UDR03 3
+#define UDR04 4
+#define UDR05 5
+#define UDR06 6
+#define UDR07 7
+
+#define USBENUM _SFR_MEM8(0xCA)
+#define USBENUM0 0
+#define USBENUM1 1
+#define USBENUM2 2
+
+#define USBCSEX _SFR_MEM8(0xCB)
+#define TXC 0
+#define RCVD 1
+#define RXSETUP 2
+#define STSENT 3
+#define TXPB 4
+#define FSTALL 5
+#define IERR 6
+
+#define USBDBCEX _SFR_MEM8(0xCC)
+#define BCT0 0
+#define BCT1 1
+#define BCT2 2
+#define BCT3 3
+#define BCT4 4
+#define BCT5 5
+#define BCT6 6
+#define BCT7 7
+
+#define USBFCEX _SFR_MEM8(0xCD)
+#define EPTYP0 0
+#define EPTYP1 1
+#define EPDIR 2
+#define EPE 7
+
+#define HSSPITO _SFR_MEM16(0xD1)
+
+#define HSSPITOL _SFR_MEM8(0xD1)
+#define HSSPITOD0 0
+#define HSSPITOD1 1
+#define HSSPITOD2 2
+#define HSSPITOD3 3
+#define HSSPITOD4 4
+#define HSSPITOD5 5
+#define HSSPITOD6 6
+#define HSSPITOD7 7
+
+#define HSSPITOH _SFR_MEM8(0xD2)
+#define HSSPITOD8 0
+#define HSSPITOD9 1
+#define HSSPITOD10 2
+#define HSSPITOD11 3
+#define HSSPITOD12 4
+#define HSSPITOD13 5
+#define HSSPITOD14 6
+#define HSSPITOD15 7
+
+#define HSSPICNT _SFR_MEM8(0xD3)
+#define HSSPICNTD0 0
+#define HSSPICNTD1 1
+#define HSSPICNTD2 2
+#define HSSPICNTD3 3
+#define HSSPICNTD4 4
+
+#define HSSPIIER _SFR_MEM8(0xD4)
+#define NSSIE 4
+#define RCVOFIE 5
+#define BTDIE 6
+#define TIMEOUTIE 7
+
+#define HSSPIGTR _SFR_MEM8(0xD5)
+#define HSSPIGTD0 0
+#define HSSPIGTD1 1
+#define HSSPIGTD2 2
+#define HSSPIGTD3 3
+#define HSSPIGTD4 4
+#define HSSPIGTD5 5
+#define HSSPIGTD6 6
+#define HSSPIGTD7 7
+
+#define HSSPIRDR _SFR_MEM8(0xD6)
+#define HSSPIRDD0 0
+#define HSSPIRDD1 1
+#define HSSPIRDD2 2
+#define HSSPIRDD3 3
+#define HSSPIRDD4 4
+#define HSSPIRDD5 5
+#define HSSPIRDD6 6
+#define HSSPIRDD7 7
+
+#define HSSPITDR _SFR_MEM8(0xD7)
+#define HSSPITDD0 0
+#define HSSPITDD1 1
+#define HSSPITDD2 2
+#define HSSPITDD3 3
+#define HSSPITDD4 4
+#define HSSPITDD5 5
+#define HSSPITDD6 6
+#define HSSPITDD7 7
+
+#define HSSPISR _SFR_MEM8(0xD8)
+#define SPICKRDY 0
+#define TXBUFE 1
+#define RXBUFF 2
+#define NSS 3
+#define DPRAMRDY 4
+
+#define HSSPICFG _SFR_MEM8(0xD9)
+#define HSSPIEN 0
+#define HSMSTR 1
+#define HSCPOL 2
+#define HSCPHA 3
+#define DPRAM 4
+#define SPICKDIV0 5
+#define SPICKDIV1 6
+#define SPICKDIV2 7
+
+#define HSSPIIR _SFR_MEM8(0xDA)
+#define NSSFE 3
+#define NSSRE 4
+#define RCVOF 5
+#define BTD 6
+#define TIMEOUT 7
+
+#define HSSPICR _SFR_MEM8(0xDB)
+#define CS 0
+#define RETTO 1
+#define STTTO 2
+
+#define HSSPIDMACS _SFR_MEM8(0xDC)
+#define HSSPIDMAR 0
+#define HSSPIDMADIR 1
+#define HSSPIDMAERR 2
+
+#define HSSPIDMAD _SFR_MEM16(0xDD)
+
+#define HSSPIDMADL _SFR_MEM8(0xDD)
+#define HSSPIDMAD0 0
+#define HSSPIDMAD1 1
+#define HSSPIDMAD2 2
+#define HSSPIDMAD3 3
+#define HSSPIDMAD4 4
+#define HSSPIDMAD5 5
+#define HSSPIDMAD6 6
+#define HSSPIDMAD7 7
+
+#define HSSPIDMADH _SFR_MEM8(0xDE)
+#define HSSPIDMAD8 0
+#define HSSPIDMAD9 1
+#define HSSPIDMAD10 2
+#define HSSPIDMAD11 3
+#define HSSPIDMAD12 4
+#define HSSPIDMAD13 5
+
+#define HSSPIDMAB _SFR_MEM8(0xDF)
+#define HSSPIDMAB0 0
+#define HSSPIDMAB1 1
+#define HSSPIDMAB2 2
+#define HSSPIDMAB3 3
+#define HSSPIDMAB4 4
+
+#define USBCR _SFR_MEM8(0xE0)
+#define USBE 1
+#define UPUC 5
+#define URMWU 7
+
+#define USBPI _SFR_MEM8(0xE1)
+#define SUSI 0
+#define RESI 1
+#define RMWUI 2
+#define SOFI 3
+#define FEURI 4
+
+#define USBPIM _SFR_MEM8(0xE2)
+#define SUSIM 0
+#define RESIM 1
+#define RMWUIM 2
+#define SOFIM 3
+
+#define USBEI _SFR_MEM8(0xE3)
+#define EP0I 0
+#define EP1I 1
+#define EP2I 2
+#define EP3I 3
+#define EP4I 4
+#define EP5I 5
+#define EP6I 6
+#define EP7I 7
+
+#define USBEIM _SFR_MEM8(0xE4)
+#define EP0IM 0
+#define EP1IM 1
+#define EP2IM 2
+#define EP3IM 3
+#define EP4IM 4
+#define EP5IM 5
+#define EP6IM 6
+#define EP7IM 7
+
+#define USBRSTE _SFR_MEM8(0xE5)
+#define RSTE0 0
+#define RSTE1 1
+#define RSTE2 2
+#define RSTE3 3
+#define RSTE4 4
+#define RSTE5 5
+#define RSTE6 6
+#define RST7 7
+
+#define USBGS _SFR_MEM8(0xE6)
+#define FAF 0
+#define FCF 1
+#define RMWUE 2
+#define RSMON 3
+
+#define USBFA _SFR_MEM8(0xE7)
+#define FADD0 0
+#define FADD1 1
+#define FADD2 2
+#define FADD3 3
+#define FADD4 4
+#define FADD5 5
+#define FADD6 6
+
+#define USBFN _SFR_MEM16(0xE8)
+
+#define USBFNL _SFR_MEM8(0xE8)
+#define FN0 0
+#define FN1 1
+#define FN2 2
+#define FN3 3
+#define FN4 4
+#define FN5 5
+#define FN6 6
+#define FN7 7
+
+#define USBFNH _SFR_MEM8(0xE9)
+#define FN8 0
+#define FN9 1
+#define FN10 2
+#define FNERR 3
+#define FNEND 4
+
+#define USBDMACS _SFR_MEM8(0xEA)
+#define USBDMAR 0
+#define USBDMADIR 1
+#define USBDMAERR 2
+#define EPS0 4
+#define EPS1 5
+#define EPS2 6
+
+#define USBDMAD _SFR_MEM16(0xEB)
+
+#define USBDMADL _SFR_MEM8(0xEB)
+#define USBDMAD0 0
+#define USBDMAD1 1
+#define USBDMAD2 2
+#define USBDMAD3 3
+#define USBDMAD4 4
+#define USBDMAD5 5
+#define USBDMAD6 6
+#define USBDMAD7 7
+
+#define USBDMADH _SFR_MEM8(0xEC)
+#define USBDMAD8 0
+#define USBDMAD9 1
+#define USBDMAD10 2
+#define USBDMAD11 3
+#define USBDMAD12 4
+#define USBDMAD13 5
+
+#define USBDMAB _SFR_MEM8(0xED)
+#define USBDMAB0 0
+#define USBDMAB1 1
+#define USBDMAB2 2
+#define USBDMAB3 3
+#define USBDMAB4 4
+#define USBDMAB5 5
+#define USBDMAB6 6
+
+#define DCCR _SFR_MEM8(0xEF)
+#define DCBUSY 5
+#define DCRDY 6
+#define DCON 7
+
+#define SCICLK _SFR_MEM8(0xF0)
+#define SCICLK0 0
+#define SCICLK1 1
+#define SCICLK2 2
+#define SCICLK3 3
+#define SCICLK4 4
+#define SCICLK5 5
+
+#define SCWT0 _SFR_MEM8(0xF1)
+#define WT0 0
+#define WT1 1
+#define WT2 2
+#define WT3 3
+#define WT4 4
+#define WT5 5
+#define WT6 6
+#define WT7 7
+
+#define SCWT1 _SFR_MEM8(0xF2)
+#define WT8 0
+#define WT9 1
+#define WT10 2
+#define WT11 3
+#define WT12 4
+#define WT13 5
+#define WT14 6
+#define WT15 7
+
+#define SCWT2 _SFR_MEM8(0xF3)
+#define WT16 0
+#define WT17 1
+#define WT18 2
+#define WT19 3
+#define WT20 4
+#define WT21 5
+#define WT22 6
+#define WT23 7
+
+#define SCWT3 _SFR_MEM8(0xF4)
+#define WT24 0
+#define WT25 1
+#define WT26 2
+#define WT27 3
+#define WT28 4
+#define WT29 5
+#define WT30 6
+#define WT31 7
+
+#define SCGT _SFR_MEM16(0xF5)
+
+#define SCGTL _SFR_MEM8(0xF5)
+#define GT0 0
+#define GT1 1
+#define GT2 2
+#define GT3 3
+#define GT4 4
+#define GT5 5
+#define GT6 6
+#define GT7 7
+
+#define SCGTH _SFR_MEM8(0xF6)
+#define GT8 0
+
+#define SCETU _SFR_MEM16(0xF7)
+
+#define SCETUL _SFR_MEM8(0xF7)
+#define ETU0 0
+#define ETU1 1
+#define ETU2 2
+#define ETU3 3
+#define ETU4 4
+#define ETU5 5
+#define ETU6 6
+#define ETU7 7
+
+#define SCETUH _SFR_MEM8(0xF8)
+#define ETU8 0
+#define ETU9 1
+#define ETU10 2
+#define COMP 7
+
+#define SCIBUF _SFR_MEM8(0xF9)
+#define SCIBUFD0 0
+#define SCIBUFD1 1
+#define SCIBUFD2 2
+#define SCIBUFD3 3
+#define SCIBUFD4 4
+#define SCIBUFD5 5
+#define SCIBUFD6 6
+#define SCIBUFD7 7
+
+#define SCSR _SFR_MEM8(0xFA)
+#define CPRESRES 3
+#define CREPSEL 4
+#define BGTEN 6
+
+#define SCIER _SFR_MEM8(0xFB)
+#define ESCPI 0
+#define ESCRI 1
+#define ESCTI 2
+#define ESCWTI 3
+#define EVCARDER 4
+#define CARDINE 6
+#define ESCTBI 7
+
+#define SCIIR _SFR_MEM8(0xFC)
+#define SCPI 0
+#define SCRI 1
+#define SCTI 2
+#define SCWTI 3
+#define VCARDERR 4
+#define SCTBI 7
+
+#define SCISR _SFR_MEM8(0xFD)
+#define SCPE 0
+#define SCRC 1
+#define SCTC 2
+#define SCWTO 3
+#define VCARDOK 4
+#define CARDIN 6
+#define SCTBE 7
+
+#define SCCON _SFR_MEM8(0xFE)
+#define CARDVCC 0
+#define CARDRST 1
+#define CARDCLK 2
+#define CARDIO 3
+#define CARDC4 4
+#define CARDC8 5
+#define CLK 7
+
+#define SCICR _SFR_MEM8(0xFF)
+#define CONV 0
+#define CREP 1
+#define WTEN 2
+#define UART 3
+#define VCARD0 4
+#define VCARD1 5
+#define CARDDET 6
+#define SCIRESET 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect_num 4
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define PCINT0_vect_num 5
+#define PCINT0_vect _VECTOR(5) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 6
+#define PCINT1_vect _VECTOR(6) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 7
+#define PCINT2_vect _VECTOR(7) /* Pin Change Interrupt Request 2 */
+#define WDT_vect_num 8
+#define WDT_vect _VECTOR(8) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect_num 9
+#define TIMER2_COMPA_vect _VECTOR(9) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect_num 10
+#define TIMER2_COMPB_vect _VECTOR(10) /* Timer/Counter2 Compare Match B */
+#define TIMER2_OVF_vect_num 11
+#define TIMER2_OVF_vect _VECTOR(11) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 12
+#define TIMER1_CAPT_vect _VECTOR(12) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 13
+#define TIMER1_COMPA_vect _VECTOR(13) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 14
+#define TIMER1_COMPB_vect _VECTOR(14) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 15
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 16
+#define TIMER0_COMPA_vect _VECTOR(16) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 17
+#define TIMER0_COMPB_vect _VECTOR(17) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 18
+#define TIMER0_OVF_vect _VECTOR(18) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 19
+#define SPI_STC_vect _VECTOR(19) /* SPI Serial Transfer Complete */
+#define USART0_RX_vect_num 20
+#define USART0_RX_vect _VECTOR(20) /* USART0, Rx Complete */
+#define USART0_UDRE_vect_num 21
+#define USART0_UDRE_vect _VECTOR(21) /* USART0 Data register Empty */
+#define USART0_TX_vect_num 22
+#define USART0_TX_vect _VECTOR(22) /* USART0, Tx Complete */
+#define SUPPLY_MON_vect_num 23
+#define SUPPLY_MON_vect _VECTOR(23) /* Supply Monitor Interruption */
+#define RFU_vect_num 24
+#define RFU_vect _VECTOR(24) /* Reserved for Future Use */
+#define EE_READY_vect_num 25
+#define EE_READY_vect _VECTOR(25) /* EEPROM Ready */
+#define TWI_vect_num 26
+#define TWI_vect _VECTOR(26) /* 2-wire Serial Interface */
+#define SPM_READY_vect_num 27
+#define SPM_READY_vect _VECTOR(27) /* Store Program Memory Read */
+#define KEYBOARD_vect_num 28
+#define KEYBOARD_vect _VECTOR(28) /* Keyboard Input Changed */
+#define AES_Operation_vect_num 29
+#define AES_Operation_vect _VECTOR(29) /* AES Block Operation Ended */
+#define HSSPI_vect_num 30
+#define HSSPI_vect _VECTOR(30) /* High-Speed SPI Interruption */
+#define USB_Endpoint_vect_num 31
+#define USB_Endpoint_vect _VECTOR(31) /* USB Endpoint Related Interruption */
+#define USB_Protocol_vect_num 32
+#define USB_Protocol_vect _VECTOR(32) /* USB Protocol Related Interruption */
+#define SCIB_vect_num 33
+#define SCIB_vect _VECTOR(33) /* Smart Card Reader Interface */
+#define USBHost_Control_vect_num 34
+#define USBHost_Control_vect _VECTOR(34) /* USB Host Controller Interrupt */
+#define USBHost_Pipe_vect_num 35
+#define USBHost_Pipe_vect _VECTOR(35) /* USB Host Pipe Interrupt */
+#define CPRES_vect_num 36
+#define CPRES_vect _VECTOR(36) /* Card Presence Detection */
+#define PCINT3_vect_num 37
+#define PCINT3_vect _VECTOR(37) /* Pin Change Interrupt Request 3 */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (38 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (256)
+#define RAMSTART (0x100)
+#define RAMSIZE (4096)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0xFFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Clock Selection */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Clock Selection */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define LFUSE_DEFAULT (FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODENABLE (unsigned char)~_BV(0) /* Brown-out Detector Enable Signal */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0xC1
+
+
+#endif /* _AVR_AT90SCR100_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/ioa6289.h b/cpukit/score/cpu/avr/avr/ioa6289.h
new file mode 100644
index 0000000000..9ac279cbe2
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/ioa6289.h
@@ -0,0 +1,844 @@
+/* Copyright (c) 2008 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/ioa6289.h - definitions for ATA6289 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "ioa6289.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATA6289_H_
+#define _AVR_ATA6289_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+
+#define DDRC _SFR_IO8(0x07)
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define CMCR _SFR_IO8(0x0F)
+#define CMM0 0
+#define CMM1 1
+#define SRCD 2
+#define CMONEN 3
+#define CCS 4
+#define ECINS 5
+#define CMCCE 7
+
+#define CMSR _SFR_IO8(0x10)
+#define ECF 0
+
+#define T2CRA _SFR_IO8(0x11)
+#define T2OTM 0
+#define T2CTM 1
+#define T2CR 2
+#define T2CRM 3
+#define T2CPRM 4
+#define T2ICS 5
+#define T2TS 6
+#define T2E 7
+
+#define T2CRB _SFR_IO8(0x12)
+#define T2SCE 0
+
+#define T3CRA _SFR_IO8(0x14)
+#define T3AC 0
+#define T3SCE 1
+#define T3CR 2
+#define T3TS 6
+#define T3E 7
+
+#define VMCSR _SFR_IO8(0x16)
+#define VMEN 0
+#define VMLS0 1
+#define VMLS1 2
+#define VMLS2 3
+#define VMIM 4
+#define VMF 5
+#define BODPD 6
+#define BODLS 7
+
+#define PCIFR _SFR_IO8(0x17)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+#define LFFR _SFR_IO8(0x18)
+#define LFWPF 0
+#define LFBF 1
+#define LFEDF 2
+#define LFRF 3
+
+#define SSFR _SFR_IO8(0x19)
+#define MSENF 0
+#define MSENO 1
+
+#define T10IFR _SFR_IO8(0x1A)
+#define T0F 0
+#define T1F 1
+
+#define T2IFR _SFR_IO8(0x1B)
+#define T2OFF 0
+#define T2COF 1
+#define T2ICF 2
+#define T2RXF 3
+#define T2TXF 4
+#define T2TCF 5
+
+#define T3IFR _SFR_IO8(0x1C)
+#define T3OFF 0
+#define T3COAF 1
+#define T3COBF 2
+#define T3ICF 3
+
+#define EIFR _SFR_IO8(0x1D)
+#define INTF0 0
+#define INTF1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define PCICR _SFR_IO8(0x23)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+#define EIMSK _SFR_IO8(0x24)
+#define INT0 0
+#define INT1 1
+
+#define SVCR _SFR_IO8(0x27)
+#define SVCS0 0
+#define SVCS1 1
+#define SVCS2 2
+#define SVCS3 3
+#define SVCS4 4
+
+#define SCR _SFR_IO8(0x28)
+#define SMS 0
+#define SEN0 1
+#define SEN1 2
+#define SMEN 3
+
+#define SCCR _SFR_IO8(0x29)
+#define SRCC0 0
+#define SRCC1 1
+#define SCCS0 2
+#define SCCS1 3
+#define SCCS2 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define T2MDR _SFR_IO8(0x2F)
+#define T2MDR0 0
+#define T2MDR1 1
+#define T2MDR2 2
+#define T2MDR3 3
+#define T2MDR4 4
+#define T2MDR5 5
+#define T2MDR6 6
+#define T2MDR7 7
+
+#define LFRR _SFR_IO8(0x30)
+#define LFRR0 0
+#define LFRR1 1
+#define LFRR2 2
+#define LFRR3 3
+#define LFRR4 4
+#define LFRR5 5
+#define LFRR6 6
+
+#define LFCDR _SFR_IO8(0x32)
+#define LFDO 0
+#define LFRST 6
+#define LFSCE 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define TSRF 5
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+
+#define LFRB _SFR_IO8(0x36)
+#define LFRB0 0
+#define LFRB1 1
+#define LFRB2 2
+#define LFRB3 3
+#define LFRB4 4
+#define LFRB5 5
+#define LFRB6 6
+#define LFRB7 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define T1CR _SFR_IO8(0x38)
+#define T1PS0 0
+#define T1PS1 1
+#define T1PS2 2
+#define T1CS0 3
+#define T1CS1 4
+#define T1CS2 5
+#define T1IE 7
+
+#define T0CR _SFR_IO8(0x39)
+#define T0PAS0 0
+#define T0PAS1 1
+#define T0PAS2 2
+#define T0IE 3
+#define T0PR 4
+#define T0PBS0 5
+#define T0PBS1 6
+#define T0PBS2 7
+
+#define CMIMR _SFR_IO8(0x3B)
+#define ECIE 0
+
+#define CLKPR _SFR_IO8(0x3C)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLTPS0 3
+#define CLTPS1 4
+#define CLTPS2 5
+#define CLPCE 7
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDPS0 0
+#define WDPS1 1
+#define WDPS2 2
+#define WDE 3
+#define WDCE 4
+
+#define SIMSK _SFR_MEM8(0x61)
+#define MSIE 0
+
+#define TSCR _SFR_MEM8(0x64)
+#define TSSD 0
+
+#define SRCCAL _SFR_MEM8(0x65)
+#define SCAL0 0
+#define SCAL1 1
+#define SCAL2 2
+#define SCAL3 3
+#define SCAL4 4
+#define SCAL5 5
+#define SCAL6 6
+#define SCAL7 7
+
+#define FRCCAL _SFR_MEM8(0x66)
+#define FCAL0 0
+#define FCAL1 1
+#define FCAL2 2
+#define FCAL3 3
+#define FCAL4 4
+#define FCAL5 5
+#define FCAL6 6
+#define FCAL7 7
+
+#define MSVCAL _SFR_MEM8(0x67)
+#define VRCAL0 0
+#define VRCAL1 1
+#define VRCAL2 2
+#define VRCAL3 3
+#define VRCAL4 4
+#define VRCAL5 5
+#define VRCAL6 6
+#define VRCAL7 7
+
+#define BGCAL _SFR_MEM8(0x68)
+#define BGCAL0 0
+#define BGCAL1 1
+#define BGCAL2 2
+#define BGCAL3 3
+#define BGCAL4 4
+#define BGCAL5 5
+#define BGCAL6 6
+#define BGCAL7 7
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6A)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6B)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+
+#define PCMSK2 _SFR_MEM8(0x6C)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define T2ICR _SFR_MEM16(0x6E)
+
+#define T2ICRL _SFR_MEM8(0x6E)
+#define T2ICRL0 0
+#define T2ICRL1 1
+#define T2ICRL2 2
+#define T2ICRL3 3
+#define T2ICRL4 4
+#define T2ICRL5 5
+#define T2ICRL6 6
+#define T2ICRL7 7
+
+#define T2ICRH _SFR_MEM8(0x6F)
+#define T2ICRH0 0
+#define T2ICRH1 1
+#define T2ICRH2 2
+#define T2ICRH3 3
+#define T2ICRH4 4
+#define T2ICRH5 5
+#define T2ICRH6 6
+#define T2ICRH7 7
+
+#define T2COR _SFR_MEM16(0x70)
+
+#define T2CORL _SFR_MEM8(0x70)
+#define T2CORL0 0
+#define T2CORL1 1
+#define T2CORL2 2
+#define T2CORL3 3
+#define T2CORL4 4
+#define T2CORL5 5
+#define T2CORL6 6
+#define T2CORL7 7
+
+#define T2CORH _SFR_MEM8(0x71)
+#define T2CORH0 0
+#define T2CORH1 1
+#define T2CORH2 2
+#define T2CORH3 3
+#define T2CORH4 4
+#define T2CORH5 5
+#define T2CORH6 6
+#define T2CORH7 7
+
+#define T2MRA _SFR_MEM8(0x72)
+#define T2CS0 0
+#define T2CS1 1
+#define T2CS2 2
+#define T2CE0 3
+#define T2CE1 4
+#define T2CNC 5
+#define T2TP0 6
+#define T2TP1 7
+
+#define T2MRB _SFR_MEM8(0x73)
+#define T2M0 0
+#define T2M1 1
+#define T2M2 2
+#define T2M3 3
+#define T2TOP 4
+#define T2CPOL 6
+#define T2SSIE 7
+
+#define T2IMR _SFR_MEM8(0x74)
+#define T2OIM 0
+#define T2CIM 1
+#define T2CPIM 2
+#define T2RXIM 3
+#define T2TXIM 4
+#define T2TCIM 5
+
+#define T3ICR _SFR_MEM16(0x76)
+
+#define T3ICRL _SFR_MEM8(0x76)
+#define T3ICRL0 0
+#define T3ICRL1 1
+#define T3ICRL2 2
+#define T3ICRL3 3
+#define T3ICRL4 4
+#define T3ICRL5 5
+#define T3ICRL6 6
+#define T3ICRL7 7
+
+#define T3ICRH _SFR_MEM8(0x77)
+#define T3ICRH0 0
+#define T3ICRH1 1
+#define T3ICRH2 2
+#define T3ICRH3 3
+#define T3ICRH4 4
+#define T3ICRH5 5
+#define T3ICRH6 6
+#define T3ICRH7 7
+
+#define T3CORA _SFR_MEM16(0x78)
+
+#define T3CORAL _SFR_MEM8(0x78)
+#define T3CORAL0 0
+#define T3CORAL1 1
+#define T3CORAL2 2
+#define T3CORAL3 3
+#define T3CORAL4 4
+#define T3CORAL5 5
+#define T3CORAL6 6
+#define T3CORAL7 7
+
+#define T3CORAH _SFR_MEM8(0x79)
+#define T3CORAH0 0
+#define T3CORAH1 1
+#define T3CORAH2 2
+#define T3CORAH3 3
+#define T3CORAH4 4
+#define T3CORAH5 5
+#define T3CORAH6 6
+#define T3CORAH7 7
+
+#define T3CORB _SFR_MEM16(0x7A)
+
+#define T3CORBL _SFR_MEM8(0x7A)
+#define T3CORBL0 0
+#define T3CORBL1 1
+#define T3CORBL2 2
+#define T3CORBL3 3
+#define T3CORBL4 4
+#define T3CORBL5 5
+#define T3CORBL6 6
+#define T3CORBL7 7
+
+#define T3CORBH _SFR_MEM8(0x7B)
+#define T3CORBH0 0
+#define T3CORBH1 1
+#define T3CORBH2 2
+#define T3CORBH3 3
+#define T3CORBH4 4
+#define T3CORBH5 5
+#define T3CORBH6 6
+#define T3CORBH7 7
+
+#define T3MRA _SFR_MEM8(0x7C)
+#define T3CS0 0
+#define T3CS1 1
+#define T3CS2 2
+#define T3CE0 3
+#define T3CE1 4
+#define T3CNC 5
+#define T3ICS0 6
+#define T3ICS1 7
+
+#define T3MRB _SFR_MEM8(0x7D)
+#define T3M0 0
+#define T3M1 1
+#define T3M2 2
+#define T3TOP 4
+
+#define T3CRB _SFR_MEM8(0x7E)
+#define T3CTMA 0
+#define T3SAMA 1
+#define T3CRMA 2
+#define T3CTMB 3
+#define T3SAMB 4
+#define T3CRMB 5
+#define T3CPRM 6
+
+#define T3IMR _SFR_MEM8(0x7F)
+#define T3OIM 0
+#define T3CAIM 1
+#define T3CBIM 2
+#define T3CPIM 3
+
+#define LFIMR _SFR_MEM8(0x81)
+#define LFWIM 0
+#define LFBIM 1
+#define LFEIM 2
+
+#define LFRCR _SFR_MEM8(0x82)
+#define LFEN 0
+#define LFBM 1
+#define LFWM0 2
+#define LFWM1 3
+#define LFRSS 4
+#define LFCS0 5
+#define LFCS1 6
+#define LFCS2 7
+
+#define LFHCR _SFR_MEM8(0x83)
+#define LFHCR0 0
+#define LFHCR1 1
+#define LFHCR2 2
+#define LFHCR3 3
+#define LFHCR4 4
+#define LFHCR5 5
+#define LFHCR6 6
+
+#define LFIDC _SFR_MEM16(0x84)
+
+#define LFIDCL _SFR_MEM8(0x84)
+#define LFIDCL_0 0
+#define LFIDCL_1 1
+#define LFIDCL_2 2
+#define LFIDCL_3 3
+#define LFIDCL_4 4
+#define LFIDCL_5 5
+#define LFIDCL_6 6
+#define LFIDCL_7 7
+
+#define LFIDCH _SFR_MEM8(0x85)
+#define LFIDCH_8 0
+#define LFIDCH_9 1
+#define LFIDCH_10 2
+#define LFIDCH_11 3
+#define LFIDCH_12 4
+#define LFIDCH_13 5
+#define LFIDCH_14 6
+#define LFIDCH_15 7
+
+#define LFCAL _SFR_MEM16(0x86)
+
+#define LFCALL _SFR_MEM8(0x86)
+#define LFCAL_00 0
+#define LFCAL_01 1
+#define LFCAL_02 2
+#define LFCAL_03 3
+#define LFCAL_04 4
+#define LFCAL_05 5
+#define LFCAL_06 6
+#define LFCAL_07 7
+
+#define LFCALH _SFR_MEM8(0x87)
+#define LFCAL_08 0
+#define LFCAL_09 1
+#define LFCAL_10 2
+#define LFCAL_11 3
+#define LFCAL_12 4
+#define LFCAL_13 5
+#define LFCAL_14 6
+#define LFCAL_15 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect_num 3
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 4
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 5
+#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 2 */
+#define INTVM_vect_num 6
+#define INTVM_vect _VECTOR(6) /* Voltage Monitor Interrupt */
+#define SENINT_vect_num 7
+#define SENINT_vect _VECTOR(7) /* Sensor Interface Interrupt */
+#define INTT0_vect_num 8
+#define INTT0_vect _VECTOR(8) /* Timer0 Interval Interrupt */
+#define LFWP_vect_num 9
+#define LFWP_vect _VECTOR(9) /* LF-Receiver Wake-up Interrupt */
+#define T3CAP_vect_num 10
+#define T3CAP_vect _VECTOR(10) /* Timer/Counter3 Capture Event */
+#define T3COMA_vect_num 11
+#define T3COMA_vect _VECTOR(11) /* Timer/Counter3 Compare Match A */
+#define T3COMB_vect_num 12
+#define T3COMB_vect _VECTOR(12) /* Timer/Counter3 Compare Match B */
+#define T3OVF_vect_num 13
+#define T3OVF_vect _VECTOR(13) /* Timer/Counter3 Overflow */
+#define T2CAP_vect_num 14
+#define T2CAP_vect _VECTOR(14) /* Timer/Counter2 Capture Event */
+#define T2COM_vect_num 15
+#define T2COM_vect _VECTOR(15) /* Timer/Counter2 Compare Match */
+#define T2OVF_vect_num 16
+#define T2OVF_vect _VECTOR(16) /* Timer/Counter2 Overflow */
+#define SPISTC_vect_num 17
+#define SPISTC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
+#define LFRXB_vect_num 18
+#define LFRXB_vect _VECTOR(18) /* LF Receive Buffer Interrupt */
+#define INTT1_vect_num 19
+#define INTT1_vect _VECTOR(19) /* Timer1 Interval Interrupt */
+#define T2RXB_vect_num 20
+#define T2RXB_vect _VECTOR(20) /* Timer2 SSI Receive Buffer Interrupt */
+#define T2TXB_vect_num 21
+#define T2TXB_vect _VECTOR(21) /* Timer2 SSI Transmit Buffer Interrupt */
+#define T2TXC_vect_num 22
+#define T2TXC_vect _VECTOR(22) /* Timer2 SSI Transmit Complete Interrupt */
+#define LFREOB_vect_num 23
+#define LFREOB_vect _VECTOR(23) /* LF-Receiver End of Burst Interrupt */
+#define EXCM_vect_num 24
+#define EXCM_vect _VECTOR(24) /* External Input Clock break down Interrupt */
+#define EEREADY_vect_num 25
+#define EEREADY_vect _VECTOR(25) /* EEPROM Ready Interrupt */
+#define SPM_RDY_vect_num 26
+#define SPM_RDY_vect _VECTOR(26) /* Store Program Memory Ready */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (27 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x100)
+#define RAMSIZE (512)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND RAMEND
+#define E2END (320 - 1)
+#define E2PAGESIZE (4)
+#define FLASHEND (8192 - 1)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_TSRDI ~_BV(0) /* Disable Temperature shutdown Reset */
+#define FUSE_BODEN ~_BV(1) /* Enable Brown-out detection */
+#define FUSE_FRCFS ~_BV(2) /* Fast RC-Oscillator Frequency select */
+#define FUSE_WDRCON ~_BV(3) /* Enable Watchdog RC-Oscillator */
+#define FUSE_SUT0 ~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 ~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT ~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 ~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_WDRCON & FUSE_BODEN)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST ~_BV(0) /* Select reset vector */
+#define FUSE_BOOTSZ0 ~_BV(1) /* Boot size select */
+#define FUSE_BOOTSZ1 ~_BV(2) /* Boot size select */
+#define FUSE_EESAVE ~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON ~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN ~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN ~_BV(6) /* debugWIRE Enable */
+#define FUSE_EELOCK ~_BV(7) /* Upper EEPROM Locked (disabled) */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x82
+
+
+#endif /* _AVR_ATA6289_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/ioat94k.h b/cpukit/score/cpu/avr/avr/ioat94k.h
new file mode 100644
index 0000000000..40d19dd695
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/ioat94k.h
@@ -0,0 +1,557 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/ioat94k.h - definitions for AT94K series FPSLIC(tm) */
+
+#ifndef _AVR_IOAT94K_H_
+#define _AVR_IOAT94K_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "ioat94k.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* UART1 Baud Rate Register */
+#define UBRR1 _SFR_IO8(0x00)
+
+/* UART1 Control and Status Registers */
+#define UCSR1B _SFR_IO8(0x01)
+#define UCSR1A _SFR_IO8(0x02)
+
+/* UART1 I/O Data Register */
+#define UDR1 _SFR_IO8(0x03)
+
+/* 0x04 reserved */
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x05)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x06)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x07)
+
+/* On Chip Debug Register (reserved) */
+#define OCDR _SFR_IO8(0x08)
+
+/* UART0 Baud Rate Register */
+#define UBRR0 _SFR_IO8(0x09)
+
+/* UART0 Control and Status Registers */
+#define UCSR0B _SFR_IO8(0x0A)
+#define UCSR0A _SFR_IO8(0x0B)
+
+/* UART0 I/O Data Register */
+#define UDR0 _SFR_IO8(0x0C)
+
+/* 0x0D..0x0F reserved */
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* FPGA I/O Select Control Register */
+#define FISCR _SFR_IO8(0x13)
+
+/* FPGA I/O Select Registers A, B, C, D */
+#define FISUA _SFR_IO8(0x14)
+#define FISUB _SFR_IO8(0x15)
+#define FISUC _SFR_IO8(0x16)
+#define FISUD _SFR_IO8(0x17)
+
+/* FPGA Cache Logic(R) registers (top secret, under NDA) */
+#define FPGAX _SFR_IO8(0x18)
+#define FPGAY _SFR_IO8(0x19)
+#define FPGAZ _SFR_IO8(0x1A)
+#define FPGAD _SFR_IO8(0x1B)
+
+/* TWI stands for "Two Wire Interface" or "TWI Was I2C(tm)" */
+
+/* 2-wire Serial Bit Rate Register */
+#define TWBR _SFR_IO8(0x1C)
+
+/* 2-wire Serial Status Register */
+#define TWSR _SFR_IO8(0x1D)
+
+/* 2-wire Serial (Slave) Address Register */
+#define TWAR _SFR_IO8(0x1E)
+
+/* 2-wire Serial Data Register */
+#define TWDR _SFR_IO8(0x1F)
+
+/* UART Baud Register High */
+#define UBRRH _SFR_IO8(0x20)
+#define UBRRHI UBRRH /* New name in datasheet (1138F-FPSLI-06/02) */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x22)
+
+/* Timer/Counter2 (8-bit) */
+#define TCNT2 _SFR_IO8(0x23)
+
+/* Timer/Counter1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Asynchronous mode StatuS Register */
+#define ASSR _SFR_IO8(0x26)
+
+/* Timer/Counter2 Control Register */
+#define TCCR2 _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare RegisterB */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare RegisterA */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Special Function IO Register */
+#define SFIOR _SFR_IO8(0x30)
+
+/* Timer/Counter0 Output Compare Register */
+#define OCR0 _SFR_IO8(0x31)
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* 0x34 reserved */
+
+/* MCU Control/Status Register */
+#define MCUR _SFR_IO8(0x35)
+
+/* 2-wire Serial Control Register */
+#define TWCR _SFR_IO8(0x36)
+
+/* 0x37 reserved */
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* Software Control Register */
+#define SFTCR _SFR_IO8(0x3A)
+
+/* External Interrupt Mask/Flag Register */
+#define EIMF _SFR_IO8(0x3B)
+
+/* 0x3C reserved */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+#define SIG_FPGA_INTERRUPT0 _VECTOR(1) /* FPGA_INT0 */
+#define SIG_INTERRUPT0 _VECTOR(2) /* EXT_INT0 */
+#define SIG_FPGA_INTERRUPT1 _VECTOR(3) /* FPGA_INT1 */
+#define SIG_INTERRUPT1 _VECTOR(4) /* EXT_INT1 */
+#define SIG_FPGA_INTERRUPT2 _VECTOR(5) /* FPGA_INT2 */
+#define SIG_INTERRUPT2 _VECTOR(6) /* EXT_INT2 */
+#define SIG_FPGA_INTERRUPT3 _VECTOR(7) /* FPGA_INT3 */
+#define SIG_INTERRUPT3 _VECTOR(8) /* EXT_INT3 */
+#define SIG_OUTPUT_COMPARE2 _VECTOR(9) /* TIM2_COMP */
+#define SIG_OVERFLOW2 _VECTOR(10) /* TIM2_OVF */
+#define SIG_INPUT_CAPTURE1 _VECTOR(11) /* TIM1_CAPT */
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12) /* TIM1_COMPA */
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13) /* TIM1_COMPB */
+#define SIG_OVERFLOW1 _VECTOR(14) /* TIM1_OVF */
+#define SIG_OUTPUT_COMPARE0 _VECTOR(15) /* TIM0_COMP */
+#define SIG_OVERFLOW0 _VECTOR(16) /* TIM0_OVF */
+#define SIG_FPGA_INTERRUPT4 _VECTOR(17) /* FPGA_INT4 */
+#define SIG_FPGA_INTERRUPT5 _VECTOR(18) /* FPGA_INT5 */
+#define SIG_FPGA_INTERRUPT6 _VECTOR(19) /* FPGA_INT6 */
+#define SIG_FPGA_INTERRUPT7 _VECTOR(20) /* FPGA_INT7 */
+#define SIG_UART0_RECV _VECTOR(21) /* UART0_RXC */
+#define SIG_UART0_DATA _VECTOR(22) /* UART0_DRE */
+#define SIG_UART0_TRANS _VECTOR(23) /* UART0_TXC */
+#define SIG_FPGA_INTERRUPT8 _VECTOR(24) /* FPGA_INT8 */
+#define SIG_FPGA_INTERRUPT9 _VECTOR(25) /* FPGA_INT9 */
+#define SIG_FPGA_INTERRUPT10 _VECTOR(26) /* FPGA_INT10 */
+#define SIG_FPGA_INTERRUPT11 _VECTOR(27) /* FPGA_INT11 */
+#define SIG_UART1_RECV _VECTOR(28) /* UART1_RXC */
+#define SIG_UART1_DATA _VECTOR(29) /* UART1_DRE */
+#define SIG_UART1_TRANS _VECTOR(30) /* UART1_TXC */
+#define SIG_FPGA_INTERRUPT12 _VECTOR(31) /* FPGA_INT12 */
+#define SIG_FPGA_INTERRUPT13 _VECTOR(32) /* FPGA_INT13 */
+#define SIG_FPGA_INTERRUPT14 _VECTOR(33) /* FPGA_INT14 */
+#define SIG_FPGA_INTERRUPT15 _VECTOR(34) /* FPGA_INT15 */
+#define SIG_2WIRE_SERIAL _VECTOR(35) /* TWS_INT */
+
+#define _VECTORS_SIZE 144
+
+/* Bit numbers (SFRs alphabetically sorted) */
+
+/* ASSR */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* DDRE */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* EIMF */
+#define INTF3 7
+#define INTF2 6
+#define INTF1 5
+#define INTF0 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+/* FISCR */
+#define FIADR 7
+#define XFIS1 1
+#define XFIS0 0
+
+/* FISUA */
+#define FIF3 7
+#define FIF2 6
+#define FIF1 5
+#define FIF0 4
+#define FINT3 3
+#define FINT2 2
+#define FINT1 1
+#define FINT0 0
+
+/* FISUB */
+#define FIF7 7
+#define FIF6 6
+#define FIF5 5
+#define FIF4 4
+#define FINT7 3
+#define FINT6 2
+#define FINT5 1
+#define FINT4 0
+
+/* FISUC */
+#define FIF11 7
+#define FIF10 6
+#define FIF9 5
+#define FIF8 4
+#define FINT11 3
+#define FINT10 2
+#define FINT9 1
+#define FINT8 0
+
+/* FISUD */
+#define FIF15 7
+#define FIF14 6
+#define FIF13 5
+#define FIF12 4
+#define FINT15 3
+#define FINT14 2
+#define FINT13 1
+#define FINT12 0
+
+/* MCUR */
+#define JTRF 7
+#define JTD 6
+#define SE 5
+#define SM1 4
+#define SM0 3
+#define PORF 2
+#define WDRF 1
+#define EXTRF 0
+
+/* OCDR (reserved) */
+#define IDRD 7
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* PINE */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* PORTE */
+/*
+ PE7 = IC1 / INT3 (alternate)
+ PE6 = OC1A / INT2 (alternate)
+ PE5 = OC1B / INT1 (alternate)
+ PE4 = ET11 / INT0 (alternate)
+ PE3 = OC2 / RX1 (alternate)
+ PE2 = / TX1 (alternate)
+ PE1 = OC0 / RX0 (alternate)
+ PE0 = ET0 / TX0 (alternate)
+ */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* SFIOR */
+#define PSR2 1
+#define PSR10 0
+
+/* SFTCR */
+#define FMXOR 3
+#define WDTS 2
+#define DBG 1
+#define SRST 0
+
+/* TCCR0 */
+#define FOC0 7
+#define PWM0 6
+#define COM01 5
+#define COM00 4
+#define CTC0 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define PWM11 1
+#define PWM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define ICPE 5
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* TCCR2 */
+#define FOC2 7
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* TIFR */
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define TOV2 4
+#define ICF1 3
+#define OCF2 2
+#define TOV0 1
+#define OCF0 0
+
+/* TIMSK */
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define TOIE2 4
+#define TICIE1 3
+#define OCIE2 2
+#define TOIE0 1
+#define OCIE0 0
+
+/* TWAR */
+/* #define TWA 1 */ /* TWA is bits 7:1 */
+#define TWGCE 0
+
+/* TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+/* TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+
+/* UBRRHI
+ Bits 11..8 of UART1 are bits 7..4 of UBRRHI.
+ Bits 11..8 of UART0 are bits 3..0 of UBRRHI. */
+/* #define UBRRHI1 4 */
+/* #define UBRRHI0 0 */
+
+/* UCSR0A */
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define OR0 3
+#define U2X0 1
+#define MPCM0 0
+
+/* UCSR0B */
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define CHR90 2
+#define RXB80 1
+#define TXB80 0
+
+/* UCSR1A */
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define OR1 3
+#define U2X1 1
+#define MPCM1 0
+
+/* UCSR1B */
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define CHR91 2
+#define RXB81 1
+#define TXB81 0
+
+/* WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ Last memory addresses - depending on configuration, it is possible
+ to have 20K-32K of program memory and 4K-16K of data memory
+ (all in the same 36K total of SRAM, loaded from external EEPROM).
+ */
+
+#ifndef RAMEND
+#define RAMEND 0x0FFF
+#endif
+
+#ifndef XRAMEND
+#define XRAMEND RAMEND
+#endif
+
+#define E2END 0
+
+#ifndef FLASHEND
+#define FLASHEND 0x7FFF
+#endif
+
+#endif /* _AVR_IOAT94K_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iocan128.h b/cpukit/score/cpu/avr/avr/iocan128.h
new file mode 100644
index 0000000000..3d9f5a2372
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iocan128.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2004,2005, Colin O'Flynn <coflynn@newae.com>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iocan128.h - definitions for CAN128 */
+
+#ifndef _AVR_IOCAN128_H_
+#define _AVR_IOCAN128_H_ 1
+
+#include <avr/iocanxx.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x0FFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x81
+
+
+#endif /* _AVR_IOCAN128_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iocan32.h b/cpukit/score/cpu/avr/avr/iocan32.h
new file mode 100644
index 0000000000..69f9d63973
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iocan32.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2004,2005, Anatoly Sokolov <aesok@pautinka.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iocan32.h - definitions for CAN32 */
+
+#ifndef _AVR_IOCAN32_H_
+#define _AVR_IOCAN32_H_ 1
+
+#include <avr/iocanxx.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x08FF /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x03FF
+#define E2PAGESIZE 8
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x81
+
+
+#endif /* _AVR_IOCAN32_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iocan64.h b/cpukit/score/cpu/avr/avr/iocan64.h
new file mode 100644
index 0000000000..efd2279049
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iocan64.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2004,2005, Anatoly Sokolov <aesok@pautinka.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iocan64.h - definitions for CAN64 */
+
+#ifndef _AVR_IOCAN64_H_
+#define _AVR_IOCAN64_H_ 1
+
+#include <avr/iocanxx.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x07FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x81
+
+
+#endif /* _AVR_IOCAN64_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iocanxx.h b/cpukit/score/cpu/avr/avr/iocanxx.h
new file mode 100644
index 0000000000..bace79ea77
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iocanxx.h
@@ -0,0 +1,1978 @@
+/* Copyright (c) 2004,2005,2006 Colin O'Flynn <coflynn@newae.com>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* This file is based largely on:
+ - iom128.h by Peter Jansen (bit defines)
+ - iom169.h by Juergen Schilling <juergen.schilling@honeywell.com>
+ (register addresses)
+ - AT90CAN128 Datasheet (bit defines and register addresses)
+ - Appnote on Mega128 --> AT90Can128 Conversion (for what registers I need
+ to change) */
+
+/* iocanxx.h - definitions for AT90CAN32, AT90CAN64 and AT90CAN128 */
+
+#ifndef _AVR_IOCANXX_H_
+#define _AVR_IOCANXX_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iocanxx.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers and bit definitions. */
+
+/* RegDef: Port A */
+#define PINA _SFR_IO8(0x00)
+#define DDRA _SFR_IO8(0x01)
+#define PORTA _SFR_IO8(0x02)
+
+/* RegDef: Port B */
+#define PINB _SFR_IO8(0x03)
+#define DDRB _SFR_IO8(0x04)
+#define PORTB _SFR_IO8(0x05)
+
+/* RegDef: Port C */
+#define PINC _SFR_IO8(0x06)
+#define DDRC _SFR_IO8(0x07)
+#define PORTC _SFR_IO8(0x08)
+
+/* RegDef: Port D */
+#define PIND _SFR_IO8(0x09)
+#define DDRD _SFR_IO8(0x0A)
+#define PORTD _SFR_IO8(0x0B)
+
+/* RegDef: Port E */
+#define PINE _SFR_IO8(0x0C)
+#define DDRE _SFR_IO8(0x0D)
+#define PORTE _SFR_IO8(0x0E)
+
+/* RegDef: Port F */
+#define PINF _SFR_IO8(0x0F)
+#define DDRF _SFR_IO8(0x10)
+#define PORTF _SFR_IO8(0x11)
+
+/* RegDef: Port G */
+#define PING _SFR_IO8(0x12)
+#define DDRG _SFR_IO8(0x13)
+#define PORTG _SFR_IO8(0x14)
+
+/* RegDef: Timer/Counter 0 interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+
+/* RegDef: Timer/Counter 1 interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+
+/* RegDef: Timer/Counter 2 interrupt Flag Register */
+#define TIFR2 _SFR_IO8(0x17)
+
+/* RegDef: Timer/Counter 3 interrupt Flag Register */
+#define TIFR3 _SFR_IO8(0x18)
+
+/* RegDef: External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+
+/* RegDef: External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+
+/* RegDef: General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+
+/* RegDef: EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+
+/* RegDef: EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+
+/* RegDef: EEPROM Address Register */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* RegDef: General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+
+/* RegDef: Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+
+/* RegDef: Timer/Counter Register */
+#define TCNT0 _SFR_IO8(0x26)
+
+/* RegDef: Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+
+/* RegDef: General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x2A)
+
+/* RegDef: General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x2B)
+
+/* RegDef: SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+
+/* RegDef: SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+
+/* RegDef: SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+
+/* RegDef: Analog Comperator Control and Status Register */
+#define ACSR _SFR_IO8(0x30)
+
+/* RegDef: On-chip Debug Register */
+#define OCDR _SFR_IO8(0x31)
+
+/* RegDef: Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+
+/* RegDef: MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* RegDef: MCU Control Rgeister */
+#define MCUCR _SFR_IO8(0x35)
+
+/* RegDef: Store Program Memory Control and Status Register */
+#define SPMCSR _SFR_IO8(0x37)
+
+/* RegDef: RAMPZ register. */
+#define RAMPZ _SFR_IO8(0x3B)
+
+/* RegDef: Watchdog Timer Control Register */
+#define WDTCR _SFR_MEM8(0x60)
+
+/* RegDef: Clock Prescale Register */
+#define CLKPR _SFR_MEM8(0x61)
+
+/* RegDef: Oscillator Calibration Register */
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* RegDef: External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+
+/* RegDef: External Interrupt Control Register B */
+#define EICRB _SFR_MEM8(0x6A)
+
+/* RegDef: Timer/Counter 0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+
+/* RegDef: Timer/Counter 1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+
+/* RegDef: Timer/Counter 2 Interrupt Mask Register */
+#define TIMSK2 _SFR_MEM8(0x70)
+
+/* RegDef: Timer/Counter 3 Interrupt Mask Register */
+#define TIMSK3 _SFR_MEM8(0x71)
+
+/* RegDef: External Memory Control Register A */
+#define XMCRA _SFR_MEM8(0x74)
+
+/* RegDef: External Memory Control Register A */
+#define XMCRB _SFR_MEM8(0x75)
+
+/* RegDef: ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* RegDef: ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+
+/* RegDef: ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+
+/* RegDef: ADC Multiplex Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+
+/* RegDef: Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+
+/* RegDef: Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+
+/* RegDef: Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+
+/* RegDef: Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+
+/* RegDef: Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+
+/* RegDef: Timer/Counter1 Register */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* RegDef: Timer/Counter1 Input Capture Register */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* RegDef: Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* RegDef: Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* RegDef: Timer/Counter1 Output Compare Register C */
+#define OCR1C _SFR_MEM16(0x8C)
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CH _SFR_MEM8(0x8D)
+
+/* RegDef: Timer/Counter3 Control Register A */
+#define TCCR3A _SFR_MEM8(0x90)
+
+/* RegDef: Timer/Counter3 Control Register B */
+#define TCCR3B _SFR_MEM8(0x91)
+
+/* RegDef: Timer/Counter3 Control Register C */
+#define TCCR3C _SFR_MEM8(0x92)
+
+/* RegDef: Timer/Counter3 Register */
+#define TCNT3 _SFR_MEM16(0x94)
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3H _SFR_MEM8(0x95)
+
+/* RegDef: Timer/Counter3 Input Capture Register */
+#define ICR3 _SFR_MEM16(0x96)
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3H _SFR_MEM8(0x97)
+
+/* RegDef: Timer/Counter3 Output Compare Register A */
+#define OCR3A _SFR_MEM16(0x98)
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AH _SFR_MEM8(0x99)
+
+/* RegDef: Timer/Counter3 Output Compare Register B */
+#define OCR3B _SFR_MEM16(0x9A)
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BH _SFR_MEM8(0x9B)
+
+/* RegDef: Timer/Counter3 Output Compare Register C */
+#define OCR3C _SFR_MEM16(0x9C)
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CH _SFR_MEM8(0x9D)
+
+/* RegDef: Timer/Counter2 Control Register A */
+#define TCCR2A _SFR_MEM8(0xB0)
+
+/* RegDef: Timer/Counter2 Register */
+#define TCNT2 _SFR_MEM8(0xB2)
+
+/* RegDef: Timer/Counter2 Output Compare Register */
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* RegDef: Asynchronous Status Register */
+#define ASSR _SFR_MEM8(0xB6)
+
+/* RegDef: TWI Bit Rate Register */
+#define TWBR _SFR_MEM8(0xB8)
+
+/* RegDef: TWI Status Register */
+#define TWSR _SFR_MEM8(0xB9)
+
+/* RegDef: TWI (Slave) Address Register */
+#define TWAR _SFR_MEM8(0xBA)
+
+/* RegDef: TWI Data Register */
+#define TWDR _SFR_MEM8(0xBB)
+
+/* RegDef: TWI Control Register */
+#define TWCR _SFR_MEM8(0xBC)
+
+/* RegDef: USART0 Control and Status Register A */
+#define UCSR0A _SFR_MEM8(0xC0)
+
+/* RegDef: USART0 Control and Status Register B */
+#define UCSR0B _SFR_MEM8(0xC1)
+
+/* RegDef: USART0 Control and Status Register C */
+#define UCSR0C _SFR_MEM8(0xC2)
+
+/* RegDef: USART0 Baud Rate Register */
+#define UBRR0 _SFR_MEM16(0xC4)
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+/* RegDef: USART0 I/O Data Register */
+#define UDR0 _SFR_MEM8(0xC6)
+
+/* RegDef: USART1 Control and Status Register A */
+#define UCSR1A _SFR_MEM8(0xC8)
+
+/* RegDef: USART1 Control and Status Register B */
+#define UCSR1B _SFR_MEM8(0xC9)
+
+/* RegDef: USART1 Control and Status Register C */
+#define UCSR1C _SFR_MEM8(0xCA)
+
+/* RegDef: USART1 Baud Rate Register */
+#define UBRR1 _SFR_MEM16(0xCC)
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1H _SFR_MEM8(0xCD)
+
+/* RegDef: USART1 I/O Data Register */
+#define UDR1 _SFR_MEM8(0xCE)
+
+/* RegDef: CAN General Control Register*/
+#define CANGCON _SFR_MEM8(0xD8)
+
+/* RegDef: CAN General Status Register*/
+#define CANGSTA _SFR_MEM8(0xD9)
+
+/* RegDef: CAN General Interrupt Register*/
+#define CANGIT _SFR_MEM8(0xDA)
+
+/* RegDef: CAN General Interrupt Enable Register*/
+#define CANGIE _SFR_MEM8(0xDB)
+
+/* RegDef: CAN Enable MOb Register*/
+#define CANEN2 _SFR_MEM8(0xDC)
+
+/* RegDef: CAN Enable MOb Register*/
+#define CANEN1 _SFR_MEM8(0xDD)
+
+/* RegDef: CAN Enable Interrupt MOb Register*/
+#define CANIE2 _SFR_MEM8(0xDE)
+
+/* RegDef: CAN Enable Interrupt MOb Register*/
+#define CANIE1 _SFR_MEM8(0xDF)
+
+/* RegDef: CAN Status Interrupt MOb Register*/
+/*
+ * WARNING: Do not apply the SIT8...SIT14 constants to bits in the CANSIT
+ * register.
+ */
+#define CANSIT _SFR_MEM16(0xE0)
+#define CANSIT2 _SFR_MEM8(0xE0)
+#define CANSIT1 _SFR_MEM8(0xE1)
+
+/* RegDef: CAN Bit Timing Register 1*/
+#define CANBT1 _SFR_MEM8(0xE2)
+
+/* RegDef: CAN Bit Timing Register 2*/
+#define CANBT2 _SFR_MEM8(0xE3)
+
+/* RegDef: CAN Bit Timing Register 3*/
+#define CANBT3 _SFR_MEM8(0xE4)
+
+/* RegDef: CAN Timer Control Register*/
+#define CANTCON _SFR_MEM8(0xE5)
+
+/* RegDef: CAN Timer Register*/
+#define CANTIM _SFR_MEM16(0xE6)
+#define CANTIML _SFR_MEM8(0xE6)
+#define CANTIMH _SFR_MEM8(0xE7)
+
+/* RegDef: CAN TTC Timer Register*/
+#define CANTTC _SFR_MEM16(0xE8)
+#define CANTTCL _SFR_MEM8(0xE8)
+#define CANTTCH _SFR_MEM8(0xE9)
+
+/* RegDef: CAN Transmitt Error Counter Register*/
+#define CANTEC _SFR_MEM8(0xEA)
+
+/* RegDef: CAN Receive Error Counter Register*/
+#define CANREC _SFR_MEM8(0xEB)
+
+/* RegDef: CAN Highest Priority MOb Register*/
+#define CANHPMOB _SFR_MEM8(0xEC)
+
+/* RegDef: CAN Page MOb Register*/
+#define CANPAGE _SFR_MEM8(0xED)
+
+/* RegDef: CAN MOb Status Register*/
+#define CANSTMOB _SFR_MEM8(0xEE)
+
+/* RegDef: CAN MOb Control and DLC Register*/
+#define CANCDMOB _SFR_MEM8(0xEF)
+
+/* RegDef: CAN Identifier Tag Registers*/
+#define CANIDT _SFR_MEM32(0xF0)
+
+#define CANIDT4 _SFR_MEM8(0xF0)
+#define CANIDT3 _SFR_MEM8(0xF1)
+#define CANIDT2 _SFR_MEM8(0xF2)
+#define CANIDT1 _SFR_MEM8(0xF3)
+
+/* RegDef: CAN Identifier Mask Registers */
+#define CANIDM _SFR_MEM32(0xF4)
+
+#define CANIDM4 _SFR_MEM8(0xF4)
+#define CANIDM3 _SFR_MEM8(0xF5)
+#define CANIDM2 _SFR_MEM8(0xF6)
+#define CANIDM1 _SFR_MEM8(0xF7)
+
+/* RegDef: CAN TTC Timer Register*/
+#define CANSTM _SFR_MEM16(0xF8)
+#define CANSTML _SFR_MEM8(0xF8)
+#define CANSTMH _SFR_MEM8(0xF9)
+
+/* RegDef: CAN Message Register*/
+#define CANMSG _SFR_MEM8(0xFA)
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+#define SIG_INTERRUPT3 _VECTOR(4)
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+#define SIG_INTERRUPT4 _VECTOR(5)
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+#define SIG_INTERRUPT5 _VECTOR(6)
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+#define SIG_INTERRUPT6 _VECTOR(7)
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+#define SIG_INTERRUPT7 _VECTOR(8)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(9)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(10)
+#define SIG_OVERFLOW2 _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+#define SIG_INPUT_CAPTURE1 _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13)
+
+/* Timer/Counter1 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE1C _VECTOR(14)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+#define SIG_OVERFLOW1 _VECTOR(15)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(16)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(17)
+#define SIG_OVERFLOW0 _VECTOR(17)
+
+/* CAN Transfer Complete or Error */
+#define CANIT_vect _VECTOR(18)
+#define SIG_CAN_INTERRUPT1 _VECTOR(18)
+
+/* CAN Timer Overrun */
+#define OVRIT_vect _VECTOR(19)
+#define SIG_CAN_OVERFLOW1 _VECTOR(19)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(20)
+#define SIG_SPI _VECTOR(20)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(21)
+#define SIG_UART0_RECV _VECTOR(21)
+#define SIG_USART0_RECV _VECTOR(21)
+
+/* USART0 Data Register Empty */
+#define USART0_UDRE_vect _VECTOR(22)
+#define SIG_UART0_DATA _VECTOR(22)
+#define SIG_USART0_DATA _VECTOR(22)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(23)
+#define SIG_UART0_TRANS _VECTOR(23)
+#define SIG_USART0_TRANS _VECTOR(23)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(24)
+#define SIG_COMPARATOR _VECTOR(24)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(25)
+#define SIG_ADC _VECTOR(25)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(26)
+#define SIG_EEPROM_READY _VECTOR(26)
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(27)
+#define SIG_INPUT_CAPTURE3 _VECTOR(27)
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(28)
+#define SIG_OUTPUT_COMPARE3A _VECTOR(28)
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(29)
+#define SIG_OUTPUT_COMPARE3B _VECTOR(29)
+
+/* Timer/Counter3 Compare Match C */
+#define TIMER3_COMPC_vect _VECTOR(30)
+#define SIG_OUTPUT_COMPARE3C _VECTOR(30)
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(31)
+#define SIG_OVERFLOW3 _VECTOR(31)
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(32)
+#define SIG_UART1_RECV _VECTOR(32)
+#define SIG_USART1_RECV _VECTOR(32)
+
+/* USART1, Data Register Empty */
+#define USART1_UDRE_vect _VECTOR(33)
+#define SIG_UART1_DATA _VECTOR(33)
+#define SIG_USART1_DATA _VECTOR(33)
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(34)
+#define SIG_UART1_TRANS _VECTOR(34)
+#define SIG_USART1_TRANS _VECTOR(34)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(35)
+#define SIG_2WIRE_SERIAL _VECTOR(35)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(36)
+#define SIG_SPM_READY _VECTOR(36)
+
+#define _VECTORS_SIZE 148
+
+/* The Register Bit names are represented by their bit number (0-7). */
+
+/* Register Bits [ASSR] */
+/* Asynchronous Status Register */
+#define EXCLK 4
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+/* End Register Bits */
+
+/* Register Bits [TWCR] */
+/* 2-wire Control Register - TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+/* End Register Bits */
+
+/* Register Bits [TWAR] */
+/* 2-wire Address Register - TWAR */
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+/* End Register Bits */
+
+/* Register Bits [TWSR] */
+/* 2-wire Status Register - TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+/* End Register Bits */
+
+/* Register Bits [XMCRB] */
+/* External Memory Control Register B - XMCRB */
+#define XMBK 7
+#define XMM2 2
+#define XMM1 1
+#define XMM0 0
+/* End Register Bits */
+
+/* Register Bits [XMCRA] */
+/* External Memory Control Register A - XMCRA */
+#define SRE 7
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW11 3
+#define SRW10 2
+#define SRW01 1
+#define SRW00 0
+/* End Register Bits */
+
+/* Register Bits [RAMPZ] */
+/* RAM Page Z select register - RAMPZ */
+#define RAMPZ0 0
+/* End Register Bits */
+
+/* Register Bits [EICRA] */
+/* External Interrupt Control Register A - EICRA */
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+/* End Register Bits */
+
+/* Register Bits [EICRB] */
+/* External Interrupt Control Register B - EICRB */
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+/* End Register Bits */
+
+/* Register Bits [SPMCSR] */
+/* Store Program Memory Control Register - SPMCSR, SPMCR */
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+/* End Register Bits */
+
+/* Register Bits [EIMSK] */
+/* External Interrupt MaSK register - EIMSK */
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+/* End Register Bits */
+
+/* Register Bits [EIFR] */
+/* External Interrupt Flag Register - EIFR */
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+/* End Register Bits */
+
+/* Register Bits [TCCR2] */
+/* Timer/Counter 2 Control Register - TCCR2 */
+#define FOC2A 7
+#define WGM20 6
+#define COM2A1 5
+#define COM2A0 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+/* End Register Bits */
+
+/* Register Bits [TCCR1A] */
+/* Timer/Counter 1 Control and Status Register A - TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define COM1C1 3
+#define COM1C0 2
+#define WGM11 1
+#define WGM10 0
+/* End Register Bits */
+
+/* Register Bits [TCCR3A] */
+/* Timer/Counter 3 Control and Status Register A - TCCR3A */
+#define COM3A1 7
+#define COM3A0 6
+#define COM3B1 5
+#define COM3B0 4
+#define COM3C1 3
+#define COM3C0 2
+#define WGM31 1
+#define WGM30 0
+/* End Register Bits */
+
+/* Register Bits [TCCR1B] */
+/* Timer/Counter 1 Control and Status Register B - TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+/* End Register Bits */
+
+/* Register Bits [TCCR3B] */
+/* Timer/Counter 3 Control and Status Register B - TCCR3B */
+#define ICNC3 7
+#define ICES3 6
+#define WGM33 4
+#define WGM32 3
+#define CS32 2
+#define CS31 1
+#define CS30 0
+/* End Register Bits */
+
+/* Register Bits [TCCR3C] */
+/* Timer/Counter 3 Control Register C - TCCR3C */
+#define FOC3A 7
+#define FOC3B 6
+#define FOC3C 5
+/* End Register Bits */
+
+/* Register Bits [TCCR1C] */
+/* Timer/Counter 1 Control Register C - TCCR1C */
+#define FOC1A 7
+#define FOC1B 6
+#define FOC1C 5
+/* End Register Bits */
+
+/* Register Bits [OCDR] */
+/* On-chip Debug Register - OCDR */
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+/* End Register Bits */
+
+/* Register Bits [WDTCR] */
+/* Watchdog Timer Control Register - WDTCR */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+/* End Register Bits */
+
+/* Register Bits [SPSR] */
+/* SPI Status Register - SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+/* End Register Bits */
+
+/* Register Bits [SPCR] */
+/* SPI Control Register - SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+/* End Register Bits */
+
+/* Register Bits [UCSR1C] */
+/* USART1 Register C - UCSR1C */
+#define UMSEL1 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+/* End Register Bits */
+
+/* Register Bits [UCSR0C] */
+/* USART0 Register C - UCSR0C */
+#define UMSEL0 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPOL0 0
+/* End Register Bits */
+
+/* Register Bits [UCSR1A] */
+/* USART1 Status Register A - UCSR1A */
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+/* End Register Bits */
+
+/* Register Bits [UCSR0A] */
+/* USART0 Status Register A - UCSR0A */
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+/* End Register Bits */
+
+/* Register Bits [UCSR1B] */
+/* USART1 Control Register B - UCSR1B */
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+/* End Register Bits */
+
+/* Register Bits [UCSR0B] */
+/* USART0 Control Register B - UCSR0B */
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+/* End Register Bits */
+
+/* Register Bits [ACSR] */
+/* Analog Comparator Control and Status Register - ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+/* End Register Bits */
+
+/* Register Bits [ADCSRA] */
+/* ADC Control and status register - ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+/* End Register Bits */
+
+/*
+ The ADHSM bit has been removed from all documentation,
+ as being not needed at all since the comparator has proven
+ to be fast enough even without feeding it more power.
+*/
+
+/* Register Bits [ADCSRB] */
+/* ADC Control and status register - ADCSRB */
+#define ACME 6
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+/* End Register Bits */
+
+/* Register Bits [ADMUX] */
+/* ADC Multiplexer select - ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+/* End Register Bits */
+
+/* Register Bits [DIDR0] */
+/* Digital Input Disable Register 0 */
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+/* End Register Bits */
+
+/* Register Bits [DIDR1] */
+/* Digital Input Disable Register 1 */
+#define AIN1D 1
+#define AIN0D 0
+/* End Register Bits */
+
+/* Register Bits [PORTA] */
+/* Port A Data Register - PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+/* End Register Bits */
+
+/* Register Bits [DDRA] */
+/* Port A Data Direction Register - DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+/* End Register Bits */
+
+/* Register Bits [PINA] */
+/* Port A Input Pins - PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+/* End Register Bits */
+
+/* Register Bits [PORTB] */
+/* Port B Data Register - PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+/* End Register Bits */
+
+/* Register Bits [DDRB] */
+/* Port B Data Direction Register - DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+/* End Register Bits */
+
+/* Register Bits [PINB] */
+/* Port B Input Pins - PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+/* End Register Bits */
+
+/* Register Bits [PORTC] */
+/* Port C Data Register - PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+/* End Register Bits */
+
+/* Register Bits [DDRC] */
+/* Port C Data Direction Register - DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+/* End Register Bits */
+
+/* Register Bits [PINC] */
+/* Port C Input Pins - PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+/* End Register Bits */
+
+/* Register Bits [PORTD] */
+/* Port D Data Register - PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+/* End Register Bits */
+
+/* Register Bits [DDRD] */
+/* Port D Data Direction Register - DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+/* End Register Bits */
+
+/* Register Bits [PIND] */
+/* Port D Input Pins - PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+/* End Register Bits */
+
+/* Register Bits [PORTE] */
+/* Port E Data Register - PORTE */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+/* End Register Bits */
+
+/* Register Bits [DDRE] */
+/* Port E Data Direction Register - DDRE */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+/* End Register Bits */
+
+/* Register Bits [PINE] */
+/* Port E Input Pins - PINE */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+/* End Register Bits */
+
+/* Register Bits [PORTF] */
+/* Port F Data Register - PORTF */
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+/* End Register Bits */
+
+/* Register Bits [DDRF] */
+/* Port F Data Direction Register - DDRF */
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+/* End Register Bits */
+
+/* Register Bits [PINF] */
+/* Port F Input Pins - PINF */
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+/* End Register Bits */
+
+/* Register Bits [PORTG] */
+/* Port G Data Register - PORTG */
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+/* End Register Bits */
+
+/* Register Bits [DDRG] */
+/* Port G Data Direction Register - DDRG */
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+/* End Register Bits */
+
+/* Register Bits [PING] */
+/* Port G Input Pins - PING */
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+/* End Register Bits */
+
+
+/* Register Bits [TIFR0] */
+/* Timer/Counter 0 interrupt Flag Register */
+#define OCF0A 1
+#define TOV0 0
+/* End Register Bits */
+
+/* Register Bits [TIFR1] */
+/* Timer/Counter 1 interrupt Flag Register */
+#define ICF1 5
+#define OCF1C 3
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+/* End Register Bits */
+
+/* Register Bits [TIFR2] */
+/* Timer/Counter 2 interrupt Flag Register */
+#define OCF2A 1
+#define TOV2 0
+/* End Register Bits */
+
+/* Register Bits [TIFR3] */
+/* Timer/Counter 3 interrupt Flag Register */
+#define ICF3 5
+#define OCF3C 3
+#define OCF3B 2
+#define OCF3A 1
+#define TOV3 0
+/* End Register Bits */
+
+/* Register Bits [GPIOR0] */
+/* General Purpose I/O Register 0 */
+#define GPIOR07 7
+#define GPIOR06 6
+#define GPIOR05 5
+#define GPIOR04 4
+#define GPIOR03 3
+#define GPIOR02 2
+#define GPIOR01 1
+#define GPIOR00 0
+/* End Register Bits */
+
+/* Register Bits [GPIOR1] */
+/* General Purpose I/O Register 1 */
+#define GPIOR17 7
+#define GPIOR16 6
+#define GPIOR15 5
+#define GPIOR14 4
+#define GPIOR13 3
+#define GPIOR12 2
+#define GPIOR11 1
+#define GPIOR10 0
+/* End Register Bits */
+
+/* Register Bits [GPIOR2] */
+/* General Purpose I/O Register 2 */
+#define GPIOR27 7
+#define GPIOR26 6
+#define GPIOR25 5
+#define GPIOR24 4
+#define GPIOR23 3
+#define GPIOR22 2
+#define GPIOR21 1
+#define GPIOR20 0
+/* End Register Bits */
+
+/* Register Bits [EECR] */
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+/* End Register Bits */
+
+/* Register Bits [EEDR] */
+/* EEPROM Data Register */
+#define EEDR7 7
+#define EEDR6 6
+#define EEDR5 5
+#define EEDR4 4
+#define EEDR3 3
+#define EEDR2 2
+#define EEDR1 1
+#define EEDR0 0
+/* End Register Bits */
+
+/* Register Bits [EEARL] */
+/* EEPROM Address Register */
+#define EEAR7 7
+#define EEAR6 6
+#define EEAR5 5
+#define EEAR4 4
+#define EEAR3 3
+#define EEAR2 2
+#define EEAR1 1
+#define EEAR0 0
+/* End Register Bits */
+
+/* Register Bits [EEARH] */
+/* EEPROM Address Register */
+#define EEAR11 3
+#define EEAR10 2
+#define EEAR9 1
+#define EEAR8 0
+/* End Register Bits */
+
+/* Register Bits [GTCCR] */
+/* General Timer/Counter Control Register */
+#define TSM 7
+#define PSR2 1
+#define PSR310 0
+/* End Register Bits */
+
+/* Register Bits [TCCR0A] */
+/* Timer/Counter Control Register A */
+/* ALSO COVERED IN GENERIC SECTION */
+#define FOC0A 7
+#define WGM00 6
+#define COM0A1 5
+#define COM0A0 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+/* End Register Bits */
+
+/* Register Bits [OCR0A] */
+/* Output Compare Register A */
+#define OCR0A7 7
+#define OCR0A6 6
+#define OCR0A5 5
+#define OCR0A4 4
+#define OCR0A3 3
+#define OCR0A2 2
+#define OCR0A1 1
+#define OCR0A0 0
+/* End Register Bits */
+
+
+/* Register Bits [SPIDR] */
+/* SPI Data Register */
+#define SPD7 7
+#define SPD6 6
+#define SPD5 5
+#define SPD4 4
+#define SPD3 3
+#define SPD2 2
+#define SPD1 1
+#define SPD0 0
+/* End Register Bits */
+
+/* Register Bits [SMCR] */
+/* Sleep Mode Control Register */
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+/* End Register Bits */
+
+/* Register Bits [MCUSR] */
+/* MCU Status Register */
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+/* End Register Bits */
+
+/* Register Bits [MCUCR] */
+/* MCU Control Register */
+#define JTD 7
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+/* End Register Bits */
+
+/* Register Bits [CLKPR] */
+/* Clock Prescale Register */
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+/* End Register Bits */
+
+/* Register Bits [OSCCAL] */
+/* Oscillator Calibration Register */
+#define CAL6 6
+#define CAL5 5
+#define CAL4 4
+#define CAL3 3
+#define CAL2 2
+#define CAL1 1
+#define CAL0 0
+/* End Register Bits */
+
+/* Register Bits [TIMSK0] */
+/* Timer/Counter 0 interrupt mask Register */
+#define OCIE0A 1
+#define TOIE0 0
+/* End Register Bits */
+
+/* Register Bits [TIMSK1] */
+/* Timer/Counter 1 interrupt mask Register */
+#define ICIE1 5
+#define OCIE1C 3
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+/* End Register Bits */
+
+/* Register Bits [TIMSK2] */
+/* Timer/Counter 2 interrupt mask Register */
+#define OCIE2A 1
+#define TOIE2 0
+/* End Register Bits */
+
+/* Register Bits [TIMSK3] */
+/* Timer/Counter 3 interrupt mask Register */
+#define ICIE3 5
+#define OCIE3C 3
+#define OCIE3B 2
+#define OCIE3A 1
+#define TOIE3 0
+/* End Register Bits */
+
+//Begin CAN specific parts
+
+/* Register Bits [CANGCON] */
+/* CAN General Control Register */
+#define ABRQ 7
+#define OVRQ 6
+#define TTC 5
+#define SYNTTC 4
+#define LISTEN 3
+#define TEST 2
+#define ENASTB 1
+#define SWRES 0
+/* End Register Bits */
+
+/* Register Bits [CANGSTA] */
+/* CAN General Status Register */
+#define OVFG 6
+#define OVRG 6
+#define TXBSY 4
+#define RXBSY 3
+#define ENFG 2
+#define BOFF 1
+#define ERRP 0
+/* End Register Bits */
+
+/* Register Bits [CANGIT] */
+/* CAN General Interrupt Register */
+#define CANIT 7
+#define BOFFIT 6
+#define OVRTIM 5
+#define BXOK 4
+#define SERG 3
+#define CERG 2
+#define FERG 1
+#define AERG 0
+/* End Register Bits */
+
+/* Register Bits [CANGIE] */
+/* CAN General Interrupt Enable */
+#define ENIT 7
+#define ENBOFF 6
+#define ENRX 5
+#define ENTX 4
+#define ENERR 3
+#define ENBX 2
+#define ENERG 1
+#define ENOVRT 0
+/* End Register Bits */
+
+/* Register Bits [CANEN2] */
+/* CAN Enable MOb Register */
+#define ENMOB7 7
+#define ENMOB6 6
+#define ENMOB5 5
+#define ENMOB4 4
+#define ENMOB3 3
+#define ENMOB2 2
+#define ENMOB1 1
+#define ENMOB0 0
+/* End Register Bits */
+
+/* Register Bits [CANEN1] */
+/* CAN Enable MOb Register */
+#define ENMOB14 6
+#define ENMOB13 5
+#define ENMOB12 4
+#define ENMOB11 3
+#define ENMOB10 2
+#define ENMOB9 1
+#define ENMOB8 0
+/* End Register Bits */
+
+/* Register Bits [CANIE2] */
+/* CAN Interrupt Enable MOb Register */
+#define IEMOB7 7
+#define IEMOB6 6
+#define IEMOB5 5
+#define IEMOB4 4
+#define IEMOB3 3
+#define IEMOB2 2
+#define IEMOB1 1
+#define IEMOB0 0
+/* End Register Bits */
+
+/* Register Bits [CANIE1] */
+/* CAN Interrupt Enable MOb Register */
+#define IEMOB14 6
+#define IEMOB13 5
+#define IEMOB12 4
+#define IEMOB11 3
+#define IEMOB10 2
+#define IEMOB9 1
+#define IEMOB8 0
+/* End Register Bits */
+
+/* Register Bits [CANSIT2] */
+/* CAN Status Interrupt MOb Register */
+#define SIT7 7
+#define SIT6 6
+#define SIT5 5
+#define SIT4 4
+#define SIT3 3
+#define SIT2 2
+#define SIT1 1
+#define SIT0 0
+/* End Register Bits */
+
+/* Register Bits [CANSIT1] */
+/* CAN Status Interrupt MOb Register */
+#define SIT14 6
+#define SIT13 5
+#define SIT12 4
+#define SIT11 3
+#define SIT10 2
+#define SIT9 1
+#define SIT8 0
+/* End Register Bits */
+
+/* Register Bits [CANBT1] */
+/* Bit Timing Register 1 */
+#define BRP5 6
+#define BRP4 5
+#define BRP3 4
+#define BRP2 3
+#define BRP1 2
+#define BRP0 1
+/* End Register Bits */
+
+/* Register Bits [CANBT2] */
+/* Bit Timing Register 2 */
+#define SJW1 6
+#define SJW0 5
+#define PRS2 3
+#define PRS1 2
+#define PRS0 1
+/* End Register Bits */
+
+/* Register Bits [CANBT3] */
+/* Bit Timing Register 3 */
+#define PHS22 6
+#define PHS21 5
+#define PHS20 4
+#define PHS12 3
+#define PHS11 2
+#define PHS10 1
+#define SMP 0
+/* End Register Bits */
+
+/* Register Bits [CANTCON] */
+/* CAN Timer Control Register */
+#define TPRSC7 7
+#define TPRSC6 6
+#define TPRSC5 5
+#define TPRSC4 4
+#define TPRSC3 3
+#define TPRSC2 2
+#define TPRSC1 1
+#define TPRSC0 0
+/* End Register Bits */
+
+/* Register Bits [CANTIML] */
+/* CAN Timer Register Low */
+#define CANTIM7 7
+#define CANTIM6 6
+#define CANTIM5 5
+#define CANTIM4 4
+#define CANTIM3 3
+#define CANTIM2 2
+#define CANTIM1 1
+#define CANTIM0 0
+/* End Register Bits */
+
+/* Register Bits [CANTIMH] */
+/* CAN Timer Register High */
+#define CANTIM15 7
+#define CANTIM14 6
+#define CANTIM13 5
+#define CANTIM12 4
+#define CANTIM11 3
+#define CANTIM10 2
+#define CANTIM9 1
+#define CANTIM8 0
+/* End Register Bits */
+
+/* Register Bits [CANTTCL] */
+/* CAN TTC Timer Register Low */
+#define TIMTTC7 7
+#define TIMTTC6 6
+#define TIMTTC5 5
+#define TIMTTC4 4
+#define TIMTTC3 3
+#define TIMTTC2 2
+#define TIMTTC1 1
+#define TIMTTC0 0
+/* End Register Bits */
+
+/* Register Bits [CANTTCH] */
+/* CAN TTC Timer Register High */
+#define TIMTTC15 7
+#define TIMTTC14 6
+#define TIMTTC13 5
+#define TIMTTC12 4
+#define TIMTTC11 3
+#define TIMTTC10 2
+#define TIMTTC9 1
+#define TIMTTC8 0
+/* End Register Bits */
+
+/* Register Bits [CANTEC] */
+/* CAN Transmitt Error Counter */
+#define TEC7 7
+#define TEC6 6
+#define TEC5 5
+#define TEC4 4
+#define TEC3 3
+#define TEC2 2
+#define TEC1 1
+#define TEC0 0
+/* End Register Bits */
+
+/* Register Bits [CANREC] */
+/* CAN Receive Error Counter */
+#define REC7 7
+#define REC6 6
+#define REC5 5
+#define REC4 4
+#define REC3 3
+#define REC2 2
+#define REC1 1
+#define REC0 0
+/* End Register Bits */
+
+/* Register Bits [CANHPMOB] */
+/* Highest Priority MOb */
+#define HPMOB3 7
+#define HPMOB2 6
+#define HPMOB1 5
+#define HPMOB0 4
+#define CGP3 3
+#define CGP2 2
+#define CGP1 1
+#define CGP0 0
+/* End Register Bits */
+
+/* Register Bits [CANPAGE] */
+/* CAN Page MOb Register */
+#define MOBNB3 7
+#define MOBNB2 6
+#define MOBNB1 5
+#define MOBNB0 4
+#define AINC 3
+#define INDX2 2
+#define INDX1 1
+#define INDX0 0
+/* End Register Bits */
+
+/* Register Bits [CANSTMOB] */
+/* CAN MOb Status Register */
+#define DLCW 7
+#define TXOK 6
+#define RXOK 5
+#define BERR 4
+#define SERR 3
+#define CERR 2
+#define FERR 1
+#define AERR 0
+/* End Register Bits */
+
+/* Register Bits [CANCDMOB] */
+/* CAN MOb Control and DLC Register */
+#define CONMOB1 7
+#define CONMOB0 6
+#define RPLV 5
+#define IDE 4
+#define DLC3 3
+#define DLC2 2
+#define DLC1 1
+#define DLC0 0
+/* End Register Bits */
+
+/* Register Bits [CANIDT4] */
+/* CAN Identifier Tag Register 4 */
+#define IDT4 7
+#define IDT3 6
+#define IDT2 5
+#define IDT1 4
+#define IDT0 3
+#define RTRTAG 2
+#define RB1TAG 1
+#define RB0TAG 0
+/* End Register Bits */
+
+/* Register Bits [CANIDT3] */
+/* CAN Identifier Tag Register 3 */
+#define IDT12 7
+#define IDT11 6
+#define IDT10 5
+#define IDT9 4
+#define IDT8 3
+#define IDT7 2
+#define IDT6 1
+#define IDT5 0
+/* End Register Bits */
+
+/* Register Bits [CANIDT2] */
+/* CAN Identifier Tag Register 2 */
+#define IDT20 7
+#define IDT19 6
+#define IDT18 5
+#define IDT17 4
+#define IDT16 3
+#define IDT15 2
+#define IDT14 1
+#define IDT13 0
+/* End Register Bits */
+
+/* Register Bits [CANIDT1] */
+/* CAN Identifier Tag Register 1 */
+#define IDT28 7
+#define IDT27 6
+#define IDT26 5
+#define IDT25 4
+#define IDT24 3
+#define IDT23 2
+#define IDT22 1
+#define IDT21 0
+/* End Register Bits */
+
+/* Register Bits [CANIDM4] */
+/* CAN Identifier Mask Register 4 */
+#define IDMSK4 7
+#define IDMSK3 6
+#define IDMSK2 5
+#define IDMSK1 4
+#define IDMSK0 3
+#define RTRMSK 2
+#define IDEMSK 0
+/* End Register Bits */
+
+/* Register Bits [CANIDM3] */
+/* CAN Identifier Mask Register 3 */
+#define IDMSK12 7
+#define IDMSK11 6
+#define IDMSK10 5
+#define IDMSK9 4
+#define IDMSK8 3
+#define IDMSK7 2
+#define IDMSK6 1
+#define IDMSK5 0
+/* End Register Bits */
+
+/* Register Bits [CANIDM2] */
+/* CAN Identifier Mask Register 2 */
+#define IDMSK20 7
+#define IDMSK19 6
+#define IDMSK18 5
+#define IDMSK17 4
+#define IDMSK16 3
+#define IDMSK15 2
+#define IDMSK14 1
+#define IDMSK13 0
+/* End Register Bits */
+
+/* Register Bits [CANIDM1] */
+/* CAN Identifier Mask Register 1 */
+#define IDMSK28 7
+#define IDMSK27 6
+#define IDMSK26 5
+#define IDMSK25 4
+#define IDMSK24 3
+#define IDMSK23 2
+#define IDMSK22 1
+#define IDMSK21 0
+/* End Register Bits */
+
+/* Register Bits [CANSTML] */
+/* CAN Timer Register of some sort, low*/
+#define TIMSTM7 7
+#define TIMSTM6 6
+#define TIMSTM5 5
+#define TIMSTM4 4
+#define TIMSTM3 3
+#define TIMSTM2 2
+#define TIMSTM1 1
+#define TIMSTM0 0
+/* End Register Bits */
+
+/* Register Bits [CANSTMH] */
+/* CAN Timer Register of some sort, high */
+#define TIMSTM15 7
+#define TIMSTM14 6
+#define TIMSTM13 5
+#define TIMSTM12 4
+#define TIMSTM11 3
+#define TIMSTM10 2
+#define TIMSTM9 1
+#define TIMSTM8 0
+/* End Register Bits */
+
+/* Register Bits [CANMSG] */
+/* CAN Message Register */
+#define MSG7 7
+#define MSG6 6
+#define MSG5 5
+#define MSG4 4
+#define MSG3 3
+#define MSG2 2
+#define MSG1 1
+#define MSG0 0
+/* End Register Bits */
+
+/* Begin Verbatim */
+
+/* Timer/Counter Control Register (generic) */
+#define FOC 7
+#define WGM0 6
+#define COM1 5
+#define COM0 4
+#define WGM1 3
+#define CS2 2
+#define CS1 1
+#define CS0 0
+
+/* Timer/Counter Control Register A (generic) */
+#define COMA1 7
+#define COMA0 6
+#define COMB1 5
+#define COMB0 4
+#define COMC1 3
+#define COMC0 2
+#define WGMA1 1
+#define WGMA0 0
+
+/* Timer/Counter Control and Status Register B (generic) */
+#define ICNC 7
+#define ICES 6
+#define WGMB3 4
+#define WGMB2 3
+#define CSB2 2
+#define CSB1 1
+#define CSB0 0
+
+/* Timer/Counter Control Register C (generic) */
+#define FOCA 7
+#define FOCB 6
+#define FOCC 5
+
+/* Port Data Register (generic) */
+#define PORT7 7
+#define PORT6 6
+#define PORT5 5
+#define PORT4 4
+#define PORT3 3
+#define PORT2 2
+#define PORT1 1
+#define PORT0 0
+
+/* Port Data Direction Register (generic) */
+#define DD7 7
+#define DD6 6
+#define DD5 5
+#define DD4 4
+#define DD3 3
+#define DD2 2
+#define DD1 1
+#define DD0 0
+
+/* Port Input Pins (generic) */
+#define PIN7 7
+#define PIN6 6
+#define PIN5 5
+#define PIN4 4
+#define PIN3 3
+#define PIN2 2
+#define PIN1 1
+#define PIN0 0
+
+/* USART Status Register A (generic) */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define UPE 2
+#define U2X 1
+#define MPCM 0
+
+/* USART Control Register B (generic) */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ 2
+#define UCSZ2 2 /* new name in datasheet (2467E-AVR-05/02) */
+#define RXB8 1
+#define TXB8 0
+
+/* USART Register C (generic) */
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* End Verbatim */
+
+#endif /* _AVR_IOCANXX_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom103.h b/cpukit/score/cpu/avr/avr/iom103.h
new file mode 100644
index 0000000000..89af7f561e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom103.h
@@ -0,0 +1,675 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom103.h - definitions for ATmega103 */
+
+#ifndef _AVR_IOM103_H_
+#define _AVR_IOM103_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom103.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Input Pins, Port F */
+#define PINF _SFR_IO8(0x00)
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x01)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x02)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x03)
+
+/* ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and status register */
+#define ADCSR _SFR_IO8(0x06)
+
+/* ADC Multiplexer select */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART Baud Rate Register */
+#define UBRR _SFR_IO8(0x09)
+
+/* UART Control Register */
+#define UCR _SFR_IO8(0x0A)
+
+/* UART Status Register */
+#define USR _SFR_IO8(0x0B)
+
+/* UART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Timer2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x23)
+
+/* Timer/Counter 2 */
+#define TCNT2 _SFR_IO8(0x24)
+
+/* Timer/Counter 2 Control register */
+#define TCCR2 _SFR_IO8(0x25)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 Asynchronous Control & Status Register */
+#define ASSR _SFR_IO8(0x30)
+
+/* Output Compare Register 0 */
+#define OCR0 _SFR_IO8(0x31)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x36)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x37)
+
+/* Èxternal Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x38)
+
+/* External Interrupt MaSK register */
+#define EIMSK _SFR_IO8(0x39)
+
+/* External Interrupt Control Register */
+#define EICR _SFR_IO8(0x3A)
+
+/* RAM Page Z select register */
+#define RAMPZ _SFR_IO8(0x3B)
+
+/* XDIV Divide control register */
+#define XDIV _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* External Interrupt 3 */
+#define INT3_vect _VECTOR(4)
+#define SIG_INTERRUPT3 _VECTOR(4)
+
+/* External Interrupt 4 */
+#define INT4_vect _VECTOR(5)
+#define SIG_INTERRUPT4 _VECTOR(5)
+
+/* External Interrupt 5 */
+#define INT5_vect _VECTOR(6)
+#define SIG_INTERRUPT5 _VECTOR(6)
+
+/* External Interrupt 6 */
+#define INT6_vect _VECTOR(7)
+#define SIG_INTERRUPT6 _VECTOR(7)
+
+/* External Interrupt 7 */
+#define INT7_vect _VECTOR(8)
+#define SIG_INTERRUPT7 _VECTOR(8)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(9)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(10)
+#define SIG_OVERFLOW2 _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+#define SIG_INPUT_CAPTURE1 _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(14)
+#define SIG_OVERFLOW1 _VECTOR(14)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(15)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(15)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(16)
+#define SIG_OVERFLOW0 _VECTOR(16)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(17)
+#define SIG_SPI _VECTOR(17)
+
+/* UART, Rx Complete */
+#define UART_RX_vect _VECTOR(18)
+#define SIG_UART_RECV _VECTOR(18)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(19)
+#define SIG_UART_DATA _VECTOR(19)
+
+/* UART, Tx Complete */
+#define UART_TX_vect _VECTOR(20)
+#define SIG_UART_TRANS _VECTOR(20)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(21)
+#define SIG_ADC _VECTOR(21)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(22)
+#define SIG_EEPROM_READY _VECTOR(22)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(23)
+#define SIG_COMPARATOR _VECTOR(23)
+
+#define _VECTORS_SIZE 96
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* XDIV Divide control register*/
+#define XDIVEN 7
+#define XDIV6 6
+#define XDIV5 5
+#define XDIV4 4
+#define XDIV3 3
+#define XDIV2 2
+#define XDIV1 1
+#define XDIV0 0
+
+/* RAM Page Z select register */
+#define RAMPZ0 0
+
+/* External Interrupt Control Register */
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+
+/* External Interrupt MaSK register */
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+/* Èxternal Interrupt Flag Register */
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+
+/* Timer/Counter Interrupt MaSK register */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define OCIE0 1
+#define TOIE0 0
+
+/* Timer/Counter Interrupt Flag Register */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define OCF0 1
+#define TOV0 0
+
+/* MCU general Control Register */
+#define SRE 7
+#define SRW 6
+#define SE 5
+#define SM1 4
+#define SM0 3
+
+/* MCU Status Register */
+#define EXTRF 1
+#define PORF 0
+
+/* Timer/Counter 0 Control Register */
+#define PWM0 6
+#define COM01 5
+#define COM00 4
+#define CTC0 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 0 Asynchronous Control & Status Register */
+#define AS0 3
+#define TCN0UB 2
+#define OCR0UB 1
+#define TCR0UB 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define PWM11 1
+#define PWM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter 2 Control register */
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Data Register, Port E */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Data Direction Register, Port E */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Input Pins, Port E */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* Input Pins, Port F */
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UART Status Register */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+
+/* UART Control Register */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC Control and status register */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADC Multiplexer select */
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0x0FFF /*Last On-Chip SRAM Location*/
+#define XRAMEND 0xFFFF
+#define E2END 0x0FFF
+#define E2PAGESIZE 0
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_BODEN (unsigned char)~_BV(6) /* Brown out detector enable */
+#define FUSE_BODLEVEL (unsigned char)~_BV(7) /* Brown out detector trigger level */
+#define LFUSE_DEFAULT (FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IOM103_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom128.h b/cpukit/score/cpu/avr/avr/iom128.h
new file mode 100644
index 0000000000..088c068a16
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom128.h
@@ -0,0 +1,1203 @@
+/* Copyright (c) 2002, Peter Jansen
+ Copyright (c) 2007, Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom128.h - defines for ATmega128
+
+ As of 2002-08-27:
+ - This should be up to date with data sheet 2467E-AVR-05/02 */
+
+#ifndef _AVR_IOM128_H_
+#define _AVR_IOM128_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom128.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Input Pins, Port F */
+#define PINF _SFR_IO8(0x00)
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x01)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x02)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x03)
+
+/* ADC Data Register */
+#define ADCW _SFR_IO16(0x04) /* for backwards compatibility */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and status register */
+#define ADCSR _SFR_IO8(0x06)
+#define ADCSRA _SFR_IO8(0x06) /* new name in datasheet (2467E-AVR-05/02) */
+
+/* ADC Multiplexer select */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* USART0 Baud Rate Register Low */
+#define UBRR0L _SFR_IO8(0x09)
+
+/* USART0 Control and Status Register B */
+#define UCSR0B _SFR_IO8(0x0A)
+
+/* USART0 Control and Status Register A */
+#define UCSR0A _SFR_IO8(0x0B)
+
+/* USART0 I/O Data Register */
+#define UDR0 _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* Special Function I/O Register */
+#define SFIOR _SFR_IO8(0x20)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* On-chip Debug Register */
+#define OCDR _SFR_IO8(0x22)
+
+/* Timer2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x23)
+
+/* Timer/Counter 2 */
+#define TCNT2 _SFR_IO8(0x24)
+
+/* Timer/Counter 2 Control register */
+#define TCCR2 _SFR_IO8(0x25)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 Asynchronous Control & Status Register */
+#define ASSR _SFR_IO8(0x30)
+
+/* Output Compare Register 0 */
+#define OCR0 _SFR_IO8(0x31)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+#define MCUCSR _SFR_IO8(0x34) /* new name in datasheet (2467E-AVR-05/02) */
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x36)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x37)
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x38)
+
+/* External Interrupt MaSK register */
+#define EIMSK _SFR_IO8(0x39)
+
+/* External Interrupt Control Register B */
+#define EICRB _SFR_IO8(0x3A)
+
+/* RAM Page Z select register */
+#define RAMPZ _SFR_IO8(0x3B)
+
+/* XDIV Divide control register */
+#define XDIV _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Extended I/O registers */
+
+/* Data Direction Register, Port F */
+#define DDRF _SFR_MEM8(0x61)
+
+/* Data Register, Port F */
+#define PORTF _SFR_MEM8(0x62)
+
+/* Input Pins, Port G */
+#define PING _SFR_MEM8(0x63)
+
+/* Data Direction Register, Port G */
+#define DDRG _SFR_MEM8(0x64)
+
+/* Data Register, Port G */
+#define PORTG _SFR_MEM8(0x65)
+
+/* Store Program Memory Control and Status Register */
+#define SPMCR _SFR_MEM8(0x68)
+#define SPMCSR _SFR_MEM8(0x68) /* new name in datasheet (2467E-AVR-05/02) */
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x6A)
+
+/* External Memory Control Register B */
+#define XMCRB _SFR_MEM8(0x6C)
+
+/* External Memory Control Register A */
+#define XMCRA _SFR_MEM8(0x6D)
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_MEM8(0x6F)
+
+/* 2-wire Serial Interface Bit Rate Register */
+#define TWBR _SFR_MEM8(0x70)
+
+/* 2-wire Serial Interface Status Register */
+#define TWSR _SFR_MEM8(0x71)
+
+/* 2-wire Serial Interface Address Register */
+#define TWAR _SFR_MEM8(0x72)
+
+/* 2-wire Serial Interface Data Register */
+#define TWDR _SFR_MEM8(0x73)
+
+/* 2-wire Serial Interface Control Register */
+#define TWCR _SFR_MEM8(0x74)
+
+/* Time Counter 1 Output Compare Register C */
+#define OCR1C _SFR_MEM16(0x78)
+#define OCR1CL _SFR_MEM8(0x78)
+#define OCR1CH _SFR_MEM8(0x79)
+
+/* Timer/Counter 1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x7A)
+
+/* Extended Timer Interrupt Flag Register */
+#define ETIFR _SFR_MEM8(0x7C)
+
+/* Extended Timer Interrupt Mask Register */
+#define ETIMSK _SFR_MEM8(0x7D)
+
+/* Timer/Counter 3 Input Capture Register */
+#define ICR3 _SFR_MEM16(0x80)
+#define ICR3L _SFR_MEM8(0x80)
+#define ICR3H _SFR_MEM8(0x81)
+
+/* Timer/Counter 3 Output Compare Register C */
+#define OCR3C _SFR_MEM16(0x82)
+#define OCR3CL _SFR_MEM8(0x82)
+#define OCR3CH _SFR_MEM8(0x83)
+
+/* Timer/Counter 3 Output Compare Register B */
+#define OCR3B _SFR_MEM16(0x84)
+#define OCR3BL _SFR_MEM8(0x84)
+#define OCR3BH _SFR_MEM8(0x85)
+
+/* Timer/Counter 3 Output Compare Register A */
+#define OCR3A _SFR_MEM16(0x86)
+#define OCR3AL _SFR_MEM8(0x86)
+#define OCR3AH _SFR_MEM8(0x87)
+
+/* Timer/Counter 3 Counter Register */
+#define TCNT3 _SFR_MEM16(0x88)
+#define TCNT3L _SFR_MEM8(0x88)
+#define TCNT3H _SFR_MEM8(0x89)
+
+/* Timer/Counter 3 Control Register B */
+#define TCCR3B _SFR_MEM8(0x8A)
+
+/* Timer/Counter 3 Control Register A */
+#define TCCR3A _SFR_MEM8(0x8B)
+
+/* Timer/Counter 3 Control Register C */
+#define TCCR3C _SFR_MEM8(0x8C)
+
+/* USART0 Baud Rate Register High */
+#define UBRR0H _SFR_MEM8(0x90)
+
+/* USART0 Control and Status Register C */
+#define UCSR0C _SFR_MEM8(0x95)
+
+/* USART1 Baud Rate Register High */
+#define UBRR1H _SFR_MEM8(0x98)
+
+/* USART1 Baud Rate Register Low*/
+#define UBRR1L _SFR_MEM8(0x99)
+
+/* USART1 Control and Status Register B */
+#define UCSR1B _SFR_MEM8(0x9A)
+
+/* USART1 Control and Status Register A */
+#define UCSR1A _SFR_MEM8(0x9B)
+
+/* USART1 I/O Data Register */
+#define UDR1 _SFR_MEM8(0x9C)
+
+/* USART1 Control and Status Register C */
+#define UCSR1C _SFR_MEM8(0x9D)
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+#define SIG_INTERRUPT3 _VECTOR(4)
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+#define SIG_INTERRUPT4 _VECTOR(5)
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+#define SIG_INTERRUPT5 _VECTOR(6)
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+#define SIG_INTERRUPT6 _VECTOR(7)
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+#define SIG_INTERRUPT7 _VECTOR(8)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(9)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(10)
+#define SIG_OVERFLOW2 _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+#define SIG_INPUT_CAPTURE1 _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(14)
+#define SIG_OVERFLOW1 _VECTOR(14)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(15)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(15)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(16)
+#define SIG_OVERFLOW0 _VECTOR(16)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(17)
+#define SIG_SPI _VECTOR(17)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(18)
+#define SIG_USART0_RECV _VECTOR(18)
+#define SIG_UART0_RECV _VECTOR(18)
+
+/* USART0 Data Register Empty */
+#define USART0_UDRE_vect _VECTOR(19)
+#define SIG_USART0_DATA _VECTOR(19)
+#define SIG_UART0_DATA _VECTOR(19)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(20)
+#define SIG_USART0_TRANS _VECTOR(20)
+#define SIG_UART0_TRANS _VECTOR(20)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(21)
+#define SIG_ADC _VECTOR(21)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(22)
+#define SIG_EEPROM_READY _VECTOR(22)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(23)
+#define SIG_COMPARATOR _VECTOR(23)
+
+/* Timer/Counter1 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(24)
+#define SIG_OUTPUT_COMPARE1C _VECTOR(24)
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(25)
+#define SIG_INPUT_CAPTURE3 _VECTOR(25)
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(26)
+#define SIG_OUTPUT_COMPARE3A _VECTOR(26)
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(27)
+#define SIG_OUTPUT_COMPARE3B _VECTOR(27)
+
+/* Timer/Counter3 Compare Match C */
+#define TIMER3_COMPC_vect _VECTOR(28)
+#define SIG_OUTPUT_COMPARE3C _VECTOR(28)
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(29)
+#define SIG_OVERFLOW3 _VECTOR(29)
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(30)
+#define SIG_USART1_RECV _VECTOR(30)
+#define SIG_UART1_RECV _VECTOR(30)
+
+/* USART1, Data Register Empty */
+#define USART1_UDRE_vect _VECTOR(31)
+#define SIG_USART1_DATA _VECTOR(31)
+#define SIG_UART1_DATA _VECTOR(31)
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(32)
+#define SIG_USART1_TRANS _VECTOR(32)
+#define SIG_UART1_TRANS _VECTOR(32)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(33)
+#define SIG_2WIRE_SERIAL _VECTOR(33)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(34)
+#define SIG_SPM_READY _VECTOR(34)
+
+#define _VECTORS_SIZE 140
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* 2-wire Control Register - TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+/* 2-wire Address Register - TWAR */
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+/* 2-wire Status Register - TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+/* External Memory Control Register A - XMCRA */
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW01 3
+#define SRW00 2
+#define SRW11 1
+
+/* External Memory Control Register B - XMCRA */
+#define XMBK 7
+#define XMM2 2
+#define XMM1 1
+#define XMM0 0
+
+/* XDIV Divide control register - XDIV */
+#define XDIVEN 7
+#define XDIV6 6
+#define XDIV5 5
+#define XDIV4 4
+#define XDIV3 3
+#define XDIV2 2
+#define XDIV1 1
+#define XDIV0 0
+
+/* RAM Page Z select register - RAMPZ */
+#define RAMPZ0 0
+
+/* External Interrupt Control Register A - EICRA */
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* External Interrupt Control Register B - EICRB */
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+
+/* Store Program Memory Control Register - SPMCSR, SPMCR */
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* External Interrupt MaSK register - EIMSK */
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+/* External Interrupt Flag Register - EIFR */
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+/* Timer/Counter Interrupt MaSK register - TIMSK */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define OCIE0 1
+#define TOIE0 0
+
+/* Timer/Counter Interrupt Flag Register - TIFR */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define OCF0 1
+#define TOV0 0
+
+/* Extended Timer Interrupt MaSK register - ETIMSK */
+#define TICIE3 5
+#define OCIE3A 4
+#define OCIE3B 3
+#define TOIE3 2
+#define OCIE3C 1
+#define OCIE1C 0
+
+/* Extended Timer Interrupt Flag Register - ETIFR */
+#define ICF3 5
+#define OCF3A 4
+#define OCF3B 3
+#define TOV3 2
+#define OCF3C 1
+#define OCF1C 0
+
+/* MCU general Control Register - MCUCR */
+#define SRE 7
+#define SRW 6
+#define SRW10 6 /* new name in datasheet (2467E-AVR-05/02) */
+#define SE 5
+#define SM1 4
+#define SM0 3
+#define SM2 2
+#define IVSEL 1
+#define IVCE 0
+
+/* MCU Status Register - MCUSR, MCUCSR */
+#define JTD 7
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* Timer/Counter Control Register (generic) */
+#define FOC 7
+#define WGM0 6
+#define COM1 5
+#define COM0 4
+#define WGM1 3
+#define CS2 2
+#define CS1 1
+#define CS0 0
+
+/* Timer/Counter 0 Control Register - TCCR0 */
+#define FOC0 7
+#define WGM00 6
+#define COM01 5
+#define COM00 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 2 Control Register - TCCR2 */
+#define FOC2 7
+#define WGM20 6
+#define COM21 5
+#define COM20 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Timer/Counter 0 Asynchronous Control & Status Register - ASSR */
+#define AS0 3
+#define TCN0UB 2
+#define OCR0UB 1
+#define TCR0UB 0
+
+/* Timer/Counter Control Register A (generic) */
+#define COMA1 7
+#define COMA0 6
+#define COMB1 5
+#define COMB0 4
+#define COMC1 3
+#define COMC0 2
+#define WGMA1 1
+#define WGMA0 0
+
+/* Timer/Counter 1 Control and Status Register A - TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define COM1C1 3
+#define COM1C0 2
+#define WGM11 1
+#define WGM10 0
+
+/* Timer/Counter 3 Control and Status Register A - TCCR3A */
+#define COM3A1 7
+#define COM3A0 6
+#define COM3B1 5
+#define COM3B0 4
+#define COM3C1 3
+#define COM3C0 2
+#define WGM31 1
+#define WGM30 0
+
+/* Timer/Counter Control and Status Register B (generic) */
+#define ICNC 7
+#define ICES 6
+#define WGMB3 4
+#define WGMB2 3
+#define CSB2 2
+#define CSB1 1
+#define CSB0 0
+
+/* Timer/Counter 1 Control and Status Register B - TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter 3 Control and Status Register B - TCCR3B */
+#define ICNC3 7
+#define ICES3 6
+#define WGM33 4
+#define WGM32 3
+#define CS32 2
+#define CS31 1
+#define CS30 0
+
+/* Timer/Counter Control Register C (generic) */
+#define FOCA 7
+#define FOCB 6
+#define FOCC 5
+
+/* Timer/Counter 3 Control Register C - TCCR3C */
+#define FOC3A 7
+#define FOC3B 6
+#define FOC3C 5
+
+/* Timer/Counter 1 Control Register C - TCCR1C */
+#define FOC1A 7
+#define FOC1B 6
+#define FOC1C 5
+
+/* On-chip Debug Register - OCDR */
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* Watchdog Timer Control Register - WDTCR */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ The ADHSM bit has been removed from all documentation,
+ as being not needed at all since the comparator has proven
+ to be fast enough even without feeding it more power.
+*/
+
+/* Special Function I/O Register - SFIOR */
+#define TSM 7
+#define ACME 3
+#define PUD 2
+#define PSR0 1
+#define PSR321 0
+
+/* SPI Status Register - SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPI Control Register - SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* USART Register C (generic) */
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* USART1 Register C - UCSR1C */
+#define UMSEL1 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+
+/* USART0 Register C - UCSR0C */
+#define UMSEL0 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPOL0 0
+
+/* USART Status Register A (generic) */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define UPE 2
+#define U2X 1
+#define MPCM 0
+
+/* USART1 Status Register A - UCSR1A */
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+/* USART0 Status Register A - UCSR0A */
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+/* USART Control Register B (generic) */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ 2
+#define UCSZ2 2 /* new name in datasheet (2467E-AVR-05/02) */
+#define RXB8 1
+#define TXB8 0
+
+/* USART1 Control Register B - UCSR1B */
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+/* USART0 Control Register B - UCSR0B */
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+/* Analog Comparator Control and Status Register - ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC Control and status register - ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADC Multiplexer select - ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* Port A Data Register - PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Port A Data Direction Register - DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Port A Input Pins - PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Port B Data Register - PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Port B Data Direction Register - DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Port B Input Pins - PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Port C Data Register - PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Port C Data Direction Register - DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Port C Input Pins - PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Port D Data Register - PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Port D Data Direction Register - DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Port D Input Pins - PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Port E Data Register - PORTE */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Port E Data Direction Register - DDRE */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Port E Input Pins - PINE */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* Port F Data Register - PORTF */
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+/* Port F Data Direction Register - DDRF */
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+/* Port F Input Pins - PINF */
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+/* Port G Data Register - PORTG */
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+/* Port G Data Direction Register - DDRG */
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+/* Port G Input Pins - PING */
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x0FFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_WDTON (unsigned char)~_BV(0)
+#define FUSE_M103C (unsigned char)~_BV(1)
+#define EFUSE_DEFAULT (FUSE_M103C)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x02
+
+
+#endif /* _AVR_IOM128_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom1280.h b/cpukit/score/cpu/avr/avr/iom1280.h
new file mode 100644
index 0000000000..9daff97fc5
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom1280.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom1280.h - definitions for ATmega1280 */
+
+#ifndef _AVR_IOM1280_H_
+#define _AVR_IOM1280_H_ 1
+
+#include <avr/iomxx0_1.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x21FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IOM1280_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom1281.h b/cpukit/score/cpu/avr/avr/iom1281.h
new file mode 100644
index 0000000000..ef277df5a3
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom1281.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom1281.h - definitions for ATmega1281 */
+
+#ifndef _AVR_IOM1281_H_
+#define _AVR_IOM1281_H_ 1
+
+#include <avr/iomxx0_1.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x21FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x04
+
+
+#endif /* _AVR_IOM1281_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom1284p.h b/cpukit/score/cpu/avr/avr/iom1284p.h
new file mode 100644
index 0000000000..7eeb17ddec
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom1284p.h
@@ -0,0 +1,1132 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom1284p.h - definitions for ATmega1284P. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom1284p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM1284P_H_
+#define _AVR_IOM1284P_H_ 1
+
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define TIFR3 _SFR_IO8(0x18)
+#define TOV3 0
+#define OCF3A 1
+#define OCF3B 2
+#define ICF3 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define RAMPZ _SFR_IO8(0x3B)
+#define RAMPZ0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRUSART1 4
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRTIM3 0
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#define TIMSK3 _SFR_MEM8(0x71)
+#define TOIE3 0
+#define OCIE3A 1
+#define OCIE3B 2
+#define ICIE3 5
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+#define PCINT31 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define TCCR3A _SFR_MEM8(0x90)
+#define WGM30 0
+#define WGM31 1
+#define COM3B0 4
+#define COM3B1 5
+#define COM3A0 6
+#define COM3A1 7
+
+#define TCCR3B _SFR_MEM8(0x91)
+#define CS30 0
+#define CS31 1
+#define CS32 2
+#define WGM32 3
+#define WGM33 4
+#define ICES3 6
+#define ICNC3 7
+
+#define TCCR3C _SFR_MEM8(0x92)
+#define FOC3B 6
+#define FOC3A 7
+
+#define TCNT3 _SFR_MEM16(0x94)
+
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3L0 0
+#define TCNT3L1 1
+#define TCNT3L2 2
+#define TCNT3L3 3
+#define TCNT3L4 4
+#define TCNT3L5 5
+#define TCNT3L6 6
+#define TCNT3L7 7
+
+#define TCNT3H _SFR_MEM8(0x95)
+#define TCNT3H0 0
+#define TCNT3H1 1
+#define TCNT3H2 2
+#define TCNT3H3 3
+#define TCNT3H4 4
+#define TCNT3H5 5
+#define TCNT3H6 6
+#define TCNT3H7 7
+
+#define ICR3 _SFR_MEM16(0x96)
+
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3L0 0
+#define ICR3L1 1
+#define ICR3L2 2
+#define ICR3L3 3
+#define ICR3L4 4
+#define ICR3L5 5
+#define ICR3L6 6
+#define ICR3L7 7
+
+#define ICR3H _SFR_MEM8(0x97)
+#define ICR3H0 0
+#define ICR3H1 1
+#define ICR3H2 2
+#define ICR3H3 3
+#define ICR3H4 4
+#define ICR3H5 5
+#define ICR3H6 6
+#define ICR3H7 7
+
+#define OCR3A _SFR_MEM16(0x98)
+
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AL0 0
+#define OCR3AL1 1
+#define OCR3AL2 2
+#define OCR3AL3 3
+#define OCR3AL4 4
+#define OCR3AL5 5
+#define OCR3AL6 6
+#define OCR3AL7 7
+
+#define OCR3AH _SFR_MEM8(0x99)
+#define OCR3AH0 0
+#define OCR3AH1 1
+#define OCR3AH2 2
+#define OCR3AH3 3
+#define OCR3AH4 4
+#define OCR3AH5 5
+#define OCR3AH6 6
+#define OCR3AH7 7
+
+#define OCR3B _SFR_MEM16(0x9A)
+
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3AL0 0
+#define OCR3AL1 1
+#define OCR3AL2 2
+#define OCR3AL3 3
+#define OCR3AL4 4
+#define OCR3AL5 5
+#define OCR3AL6 6
+#define OCR3AL7 7
+
+#define OCR3BH _SFR_MEM8(0x9B)
+#define OCR3AH0 0
+#define OCR3AH1 1
+#define OCR3AH2 2
+#define OCR3AH3 3
+#define OCR3AH4 4
+#define OCR3AH5 5
+#define OCR3AH6 6
+#define OCR3AH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0_0 0
+#define UBRR0_1 1
+#define UBRR0_2 2
+#define UBRR0_3 3
+#define UBRR0_4 4
+#define UBRR0_5 5
+#define UBRR0_6 6
+#define UBRR0_7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR0_8 0
+#define UBRR0_9 1
+#define UBRR0_10 2
+#define UBRR0_11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1_0 0
+#define UBRR1_1 1
+#define UBRR1_2 2
+#define UBRR1_3 3
+#define UBRR1_4 4
+#define UBRR1_5 5
+#define UBRR1_6 6
+#define UBRR1_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR1_8 0
+#define UBRR1_9 1
+#define UBRR1_10 2
+#define UBRR1_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define PCINT0_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect _VECTOR(6) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect _VECTOR(7) /* Pin Change Interrupt Request 3 */
+#define WDT_vect _VECTOR(8) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect _VECTOR(9) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect _VECTOR(10) /* Timer/Counter2 Compare Match B */
+#define TIMER2_OVF_vect _VECTOR(11) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect _VECTOR(12) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(13) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(14) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(16) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect _VECTOR(17) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(18) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect _VECTOR(19) /* SPI Serial Transfer Complete */
+#define USART0_RX_vect _VECTOR(20) /* USART0, Rx Complete */
+#define USART0_UDRE_vect _VECTOR(21) /* USART0 Data register Empty */
+#define USART0_TX_vect _VECTOR(22) /* USART0, Tx Complete */
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define ADC_vect _VECTOR(24) /* ADC Conversion Complete */
+#define EE_READY_vect _VECTOR(25) /* EEPROM Ready */
+#define TWI_vect _VECTOR(26) /* 2-wire Serial Interface */
+#define SPM_READY_vect _VECTOR(27) /* Store Program Memory Read */
+#define USART1_RX_vect _VECTOR(28) /* USART1 RX complete */
+#define USART1_UDRE_vect _VECTOR(29) /* USART1 Data Register Empty */
+#define USART1_TX_vect _VECTOR(30) /* USART1 TX complete */
+#define TIMER3_CAPT_vect _VECTOR(31) /* Timer/Counter3 Capture Event */
+#define TIMER3_COMPA_vect _VECTOR(32) /* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPB_vect _VECTOR(33) /* Timer/Counter3 Compare Match B */
+#define TIMER3_OVF_vect _VECTOR(34) /* Timer/Counter3 Overflow */
+
+#define _VECTORS_SIZE (35 * 4)
+
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x40FF /* Last On-Chip SRAM Location */
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOM1284P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom128rfa1.h b/cpukit/score/cpu/avr/avr/iom128rfa1.h
new file mode 100644
index 0000000000..bc3f8ab647
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom128rfa1.h
@@ -0,0 +1,5373 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom128rfa1.h - definitions for ATmega128RFA1 */
+
+#ifndef _AVR_IOM128RFA1_H_
+#define _AVR_IOM128RFA1_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom128rfa1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#include <avr/sfr_defs.h>
+
+#ifndef __ASSEMBLER__
+# define _MMIO_BYTE_STRUCT(mem_addr,type) (*(volatile type *)(mem_addr))
+# define _SFR_IO8_STRUCT(io_addr,type) _MMIO_BYTE_STRUCT((io_addr) + 0x20, type)
+# define _SFR_MEM8_STRUCT(io_addr,type) _MMIO_BYTE_STRUCT((io_addr), type)
+#endif /* __ASSEMBLER__ */
+
+/*
+ * USAGE:
+ *
+ * simple register assignment:
+ * TIFR1 = 0x17
+ * subregister assignment:
+ * TIFR1_struct.ocf1a = 1
+ * (subregister names are converted to small letters)
+ */
+
+
+/* Port A Input Pins Address */
+#define PINA _SFR_IO8(0x00)
+
+ /* PINA */
+
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+/* Port A Data Direction Register */
+#define DDRA _SFR_IO8(0x01)
+
+ /* DDRA */
+
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+/* Port A Data Register */
+#define PORTA _SFR_IO8(0x02)
+
+ /* PORTA */
+
+#define PORTA0 0
+#define PA0 0
+#define PORTA1 1
+#define PA1 1
+#define PORTA2 2
+#define PA2 2
+#define PORTA3 3
+#define PA3 3
+#define PORTA4 4
+#define PA4 4
+#define PORTA5 5
+#define PA5 5
+#define PORTA6 6
+#define PA6 6
+#define PORTA7 7
+#define PA7 7
+
+/* Port B Input Pins Address */
+#define PINB _SFR_IO8(0x03)
+
+ /* PINB */
+
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+/* Port B Data Direction Register */
+#define DDRB _SFR_IO8(0x04)
+
+ /* DDRB */
+
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+/* Port B Data Register */
+#define PORTB _SFR_IO8(0x05)
+
+ /* PORTB */
+
+#define PORTB0 0
+#define PB0 0
+#define PORTB1 1
+#define PB1 1
+#define PORTB2 2
+#define PB2 2
+#define PORTB3 3
+#define PB3 3
+#define PORTB4 4
+#define PB4 4
+#define PORTB5 5
+#define PB5 5
+#define PORTB6 6
+#define PB6 6
+#define PORTB7 7
+#define PB7 7
+
+/* Port C Input Pins Address */
+#define PINC _SFR_IO8(0x06)
+
+ /* PINC */
+
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+/* Port C Data Direction Register */
+#define DDRC _SFR_IO8(0x07)
+
+ /* DDRC */
+
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+/* Port C Data Register */
+#define PORTC _SFR_IO8(0x08)
+
+ /* PORTC */
+
+#define PORTC0 0
+#define PC0 0
+#define PORTC1 1
+#define PC1 1
+#define PORTC2 2
+#define PC2 2
+#define PORTC3 3
+#define PC3 3
+#define PORTC4 4
+#define PC4 4
+#define PORTC5 5
+#define PC5 5
+#define PORTC6 6
+#define PC6 6
+#define PORTC7 7
+#define PC7 7
+
+/* Port D Input Pins Address */
+#define PIND _SFR_IO8(0x09)
+
+ /* PIND */
+
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+/* Port D Data Direction Register */
+#define DDRD _SFR_IO8(0x0A)
+
+ /* DDRD */
+
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+/* Port D Data Register */
+#define PORTD _SFR_IO8(0x0B)
+
+ /* PORTD */
+
+#define PORTD0 0
+#define PD0 0
+#define PORTD1 1
+#define PD1 1
+#define PORTD2 2
+#define PD2 2
+#define PORTD3 3
+#define PD3 3
+#define PORTD4 4
+#define PD4 4
+#define PORTD5 5
+#define PD5 5
+#define PORTD6 6
+#define PD6 6
+#define PORTD7 7
+#define PD7 7
+
+/* Port E Input Pins Address */
+#define PINE _SFR_IO8(0x0C)
+
+ /* PINE */
+
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+#define PINE3 3
+#define PINE4 4
+#define PINE5 5
+#define PINE6 6
+#define PINE7 7
+
+/* Port E Data Direction Register */
+#define DDRE _SFR_IO8(0x0D)
+
+ /* DDRE */
+
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+#define DDE3 3
+#define DDE4 4
+#define DDE5 5
+#define DDE6 6
+#define DDE7 7
+
+/* Port E Data Register */
+#define PORTE _SFR_IO8(0x0E)
+
+ /* PORTE */
+
+#define PORTE0 0
+#define PE0 0
+#define PORTE1 1
+#define PE1 1
+#define PORTE2 2
+#define PE2 2
+#define PORTE3 3
+#define PE3 3
+#define PORTE4 4
+#define PE4 4
+#define PORTE5 5
+#define PE5 5
+#define PORTE6 6
+#define PE6 6
+#define PORTE7 7
+#define PE7 7
+
+/* Port F Input Pins Address */
+#define PINF _SFR_IO8(0x0F)
+
+ /* PINF */
+
+#define PINF0 0
+#define PINF1 1
+#define PINF2 2
+#define PINF3 3
+#define PINF4 4
+#define PINF5 5
+#define PINF6 6
+#define PINF7 7
+
+/* Port F Data Direction Register */
+#define DDRF _SFR_IO8(0x10)
+
+ /* DDRF */
+
+#define DDF0 0
+#define DDF1 1
+#define DDF2 2
+#define DDF3 3
+#define DDF4 4
+#define DDF5 5
+#define DDF6 6
+#define DDF7 7
+
+/* Port F Data Register */
+#define PORTF _SFR_IO8(0x11)
+
+ /* PORTF */
+
+#define PORTF0 0
+#define PF0 0
+#define PORTF1 1
+#define PF1 1
+#define PORTF2 2
+#define PF2 2
+#define PORTF3 3
+#define PF3 3
+#define PORTF4 4
+#define PF4 4
+#define PORTF5 5
+#define PF5 5
+#define PORTF6 6
+#define PF6 6
+#define PORTF7 7
+#define PF7 7
+
+/* Port G Input Pins Address */
+#define PING _SFR_IO8(0x12)
+
+ /* PING */
+
+#define PING0 0
+#define PING1 1
+#define PING2 2
+#define PING3 3
+#define PING4 4
+#define PING5 5
+
+/* Port G Data Direction Register */
+#define DDRG _SFR_IO8(0x13)
+
+ /* DDRG */
+
+#define DDG0 0
+#define DDG1 1
+#define DDG2 2
+#define DDG3 3
+#define DDG4 4
+#define DDG5 5
+
+/* Port G Data Register */
+#define PORTG _SFR_IO8(0x14)
+
+ /* PORTG */
+
+#define PORTG0 0
+#define PG0 0
+#define PORTG1 1
+#define PG1 1
+#define PORTG2 2
+#define PG2 2
+#define PORTG3 3
+#define PG3 3
+#define PORTG4 4
+#define PG4 4
+#define PORTG5 5
+#define PG5 5
+
+/* Timer/Counter0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIFR0 {
+ unsigned int tov0 : 1; /* Timer/Counter0 Overflow Flag */
+ unsigned int ocf0a : 1; /* Timer/Counter0 Output Compare A Match Flag */
+ unsigned int ocf0b : 1; /* Timer/Counter0 Output Compare B Match Flag */
+ unsigned int : 5;
+};
+
+#define TIFR0_struct _SFR_IO8_STRUCT(0x15, struct __reg_TIFR0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIFR0 */
+
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+/* Timer/Counter1 Interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIFR1 {
+ unsigned int tov1 : 1; /* Timer/Counter1 Overflow Flag */
+ unsigned int ocf1a : 1; /* Timer/Counter1 Output Compare A Match Flag */
+ unsigned int ocf1b : 1; /* Timer/Counter1 Output Compare B Match Flag */
+ unsigned int ocf1c : 1; /* Timer/Counter1 Output Compare C Match Flag */
+ unsigned int : 1;
+ unsigned int icf1 : 1; /* Timer/Counter1 Input Capture Flag */
+ unsigned int : 2;
+};
+
+#define TIFR1_struct _SFR_IO8_STRUCT(0x16, struct __reg_TIFR1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIFR1 */
+
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR2 _SFR_IO8(0x17)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIFR2 {
+ unsigned int tov2 : 1; /* Timer/Counter2 Overflow Flag */
+ unsigned int ocf2a : 1; /* Output Compare Flag 2 A */
+ unsigned int ocf2b : 1; /* Output Compare Flag 2 B */
+ unsigned int : 5;
+};
+
+#define TIFR2_struct _SFR_IO8_STRUCT(0x17, struct __reg_TIFR2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIFR2 */
+
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+/* Timer/Counter3 Interrupt Flag Register */
+#define TIFR3 _SFR_IO8(0x18)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIFR3 {
+ unsigned int tov3 : 1; /* Timer/Counter3 Overflow Flag */
+ unsigned int ocf3a : 1; /* Timer/Counter3 Output Compare A Match Flag */
+ unsigned int ocf3b : 1; /* Timer/Counter3 Output Compare B Match Flag */
+ unsigned int ocf3c : 1; /* Timer/Counter3 Output Compare C Match Flag */
+ unsigned int : 1;
+ unsigned int icf3 : 1; /* Timer/Counter3 Input Capture Flag */
+ unsigned int : 2;
+};
+
+#define TIFR3_struct _SFR_IO8_STRUCT(0x18, struct __reg_TIFR3)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIFR3 */
+
+#define TOV3 0
+#define OCF3A 1
+#define OCF3B 2
+#define OCF3C 3
+#define ICF3 5
+
+/* Timer/Counter4 Interrupt Flag Register */
+#define TIFR4 _SFR_IO8(0x19)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIFR4 {
+ unsigned int tov4 : 1; /* Timer/Counter4 Overflow Flag */
+ unsigned int ocf4a : 1; /* Timer/Counter4 Output Compare A Match Flag */
+ unsigned int ocf4b : 1; /* Timer/Counter4 Output Compare B Match Flag */
+ unsigned int ocf4c : 1; /* Timer/Counter4 Output Compare C Match Flag */
+ unsigned int : 1;
+ unsigned int icf4 : 1; /* Timer/Counter4 Input Capture Flag */
+ unsigned int : 2;
+};
+
+#define TIFR4_struct _SFR_IO8_STRUCT(0x19, struct __reg_TIFR4)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIFR4 */
+
+#define TOV4 0
+#define OCF4A 1
+#define OCF4B 2
+#define OCF4C 3
+#define ICF4 5
+
+/* Timer/Counter5 Interrupt Flag Register */
+#define TIFR5 _SFR_IO8(0x1A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIFR5 {
+ unsigned int tov5 : 1; /* Timer/Counter5 Overflow Flag */
+ unsigned int ocf5a : 1; /* Timer/Counter5 Output Compare A Match Flag */
+ unsigned int ocf5b : 1; /* Timer/Counter5 Output Compare B Match Flag */
+ unsigned int ocf5c : 1; /* Timer/Counter5 Output Compare C Match Flag */
+ unsigned int : 1;
+ unsigned int icf5 : 1; /* Timer/Counter5 Input Capture Flag */
+ unsigned int : 2;
+};
+
+#define TIFR5_struct _SFR_IO8_STRUCT(0x1a, struct __reg_TIFR5)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIFR5 */
+
+#define TOV5 0
+#define OCF5A 1
+#define OCF5B 2
+#define OCF5C 3
+#define ICF5 5
+
+/* Pin Change Interrupt Flag Register */
+#define PCIFR _SFR_IO8(0x1B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PCIFR {
+ unsigned int pcif : 3; /* Pin Change Interrupt Flag 2 */
+ unsigned int : 5;
+};
+
+#define PCIFR_struct _SFR_IO8_STRUCT(0x1b, struct __reg_PCIFR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PCIFR */
+
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_EIFR {
+ unsigned int intf : 8; /* External Interrupt Flag */
+};
+
+#define EIFR_struct _SFR_IO8_STRUCT(0x1c, struct __reg_EIFR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* EIFR */
+
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_EIMSK {
+ unsigned int intm : 8; /* External Interrupt Request Enable */
+};
+
+#define EIMSK_struct _SFR_IO8_STRUCT(0x1d, struct __reg_EIMSK)
+
+#endif /* __ASSEMBLER__ */
+
+ /* EIMSK */
+
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+/* General Purpose IO Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_GPIOR0 {
+ unsigned int gpior0 : 8; /* General Purpose I/O Register 0 Value */
+};
+
+#define GPIOR0_struct _SFR_IO8_STRUCT(0x1e, struct __reg_GPIOR0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* GPIOR0 */
+
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_EECR {
+ unsigned int eere : 1; /* EEPROM Read Enable */
+ unsigned int eepe : 1; /* EEPROM Programming Enable */
+ unsigned int eempe : 1; /* EEPROM Master Write Enable */
+ unsigned int eerie : 1; /* EEPROM Ready Interrupt Enable */
+ unsigned int eepm : 2; /* EEPROM Programming Mode */
+ unsigned int : 2;
+};
+
+#define EECR_struct _SFR_IO8_STRUCT(0x1f, struct __reg_EECR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* EECR */
+
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+
+ /* EEDR */
+
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+/* EEPROM Address Register Bytes */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_GTCCR {
+ unsigned int psrsync : 1; /* Prescaler Reset for Synchronous Timer/Counters */
+ unsigned int psrasy : 1; /* Prescaler Reset Timer/Counter2 */
+ unsigned int : 5;
+ unsigned int tsm : 1; /* Timer/Counter Synchronization Mode */
+};
+
+#define GTCCR_struct _SFR_IO8_STRUCT(0x23, struct __reg_GTCCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* GTCCR */
+
+#define PSRSYNC 0
+#define PSR10 0
+#define PSRASY 1
+#define PSR2 1
+#define TSM 7
+
+/* Timer/Counter0 Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR0A {
+ unsigned int wgm0 : 2; /* Waveform Generation Mode */
+ unsigned int : 2;
+ unsigned int com0b : 2; /* Compare Match Output B Mode */
+ unsigned int com0a : 2; /* Compare Match Output A Mode */
+};
+
+#define TCCR0A_struct _SFR_IO8_STRUCT(0x24, struct __reg_TCCR0A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR0A */
+
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+/* Timer/Counter0 Control Register B */
+#define TCCR0B _SFR_IO8(0x25)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR0B {
+ unsigned int cs0 : 3; /* Clock Select */
+ unsigned int wgm02 : 1; /* */
+ unsigned int : 2;
+ unsigned int foc0b : 1; /* Force Output Compare B */
+ unsigned int foc0a : 1; /* Force Output Compare A */
+};
+
+#define TCCR0B_struct _SFR_IO8_STRUCT(0x25, struct __reg_TCCR0B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR0B */
+
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+/* Timer/Counter0 Register */
+#define TCNT0 _SFR_IO8(0x26)
+
+ /* TCNT0 */
+
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+/* Timer/Counter0 Output Compare Register */
+#define OCR0A _SFR_IO8(0x27)
+
+ /* OCR0A */
+
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+/* Timer/Counter0 Output Compare Register B */
+#define OCR0B _SFR_IO8(0x28)
+
+ /* OCR0B */
+
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+/* General Purpose IO Register 1 */
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_GPIOR1 {
+ unsigned int gpior1 : 8; /* General Purpose I/O Register 1 Value */
+};
+
+#define GPIOR1_struct _SFR_IO8_STRUCT(0x2a, struct __reg_GPIOR1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* GPIOR1 */
+
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_GPIOR2 {
+ unsigned int gpior2 : 8; /* General Purpose I/O Register 2 Value */
+};
+
+#define GPIOR2_struct _SFR_IO8_STRUCT(0x2b, struct __reg_GPIOR2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* GPIOR2 */
+
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SPCR {
+ unsigned int spr : 2; /* SPI Clock Rate Select 1 and 0 */
+ unsigned int cpha : 1; /* Clock Phase */
+ unsigned int cpol : 1; /* Clock polarity */
+ unsigned int mstr : 1; /* Master/Slave Select */
+ unsigned int dord : 1; /* Data Order */
+ unsigned int spe : 1; /* SPI Enable */
+ unsigned int spie : 1; /* SPI Interrupt Enable */
+};
+
+#define SPCR_struct _SFR_IO8_STRUCT(0x2c, struct __reg_SPCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SPCR */
+
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SPSR {
+ unsigned int spi2x : 1; /* Double SPI Speed Bit */
+ unsigned int : 5;
+ unsigned int wcol : 1; /* Write Collision Flag */
+ unsigned int spif : 1; /* SPI Interrupt Flag */
+};
+
+#define SPSR_struct _SFR_IO8_STRUCT(0x2d, struct __reg_SPSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SPSR */
+
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+
+ /* SPDR */
+
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+/* Analog Comparator Control And Status Register */
+#define ACSR _SFR_IO8(0x30)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ACSR {
+ unsigned int acis : 2; /* Analog Comparator Interrupt Mode Select */
+ unsigned int acic : 1; /* Analog Comparator Input Capture Enable */
+ unsigned int acie : 1; /* Analog Comparator Interrupt Enable */
+ unsigned int aci : 1; /* Analog Comparator Interrupt Flag */
+ unsigned int aco : 1; /* Analog Compare Output */
+ unsigned int acbg : 1; /* Analog Comparator Bandgap Select */
+ unsigned int acd : 1; /* Analog Comparator Disable */
+};
+
+#define ACSR_struct _SFR_IO8_STRUCT(0x30, struct __reg_ACSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* ACSR */
+
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+/* On-Chip Debug Register */
+#define OCDR _SFR_IO8(0x31)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_OCDR {
+ unsigned int ocdr : 8; /* On-Chip Debug Register Data */
+};
+
+#define OCDR_struct _SFR_IO8_STRUCT(0x31, struct __reg_OCDR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* OCDR */
+
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SMCR {
+ unsigned int se : 1; /* Sleep Enable */
+ unsigned int sm : 3; /* Sleep Mode Select bits */
+ unsigned int : 4;
+};
+
+#define SMCR_struct _SFR_IO8_STRUCT(0x33, struct __reg_SMCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SMCR */
+
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_MCUSR {
+ unsigned int porf : 1; /* Power-on Reset Flag */
+ unsigned int extrf : 1; /* External Reset Flag */
+ unsigned int borf : 1; /* Brown-out Reset Flag */
+ unsigned int wdrf : 1; /* Watchdog Reset Flag */
+ unsigned int jtrf : 1; /* JTAG Reset Flag */
+ unsigned int : 3;
+};
+
+#define MCUSR_struct _SFR_IO8_STRUCT(0x34, struct __reg_MCUSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* MCUSR */
+
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_MCUCR {
+ unsigned int ivce : 1; /* Interrupt Vector Change Enable */
+ unsigned int ivsel : 1; /* Interrupt Vector Select */
+ unsigned int : 2;
+ unsigned int pud : 1; /* Pull-up Disable */
+ unsigned int : 2;
+ unsigned int jtd : 1; /* JTAG Interface Disable */
+};
+
+#define MCUCR_struct _SFR_IO8_STRUCT(0x35, struct __reg_MCUCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* MCUCR */
+
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Store Program Memory Control Register */
+#define SPMCSR _SFR_IO8(0x37)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SPMCSR {
+ unsigned int spmen : 1; /* Store Program Memory Enable */
+ unsigned int pgers : 1; /* Page Erase */
+ unsigned int pgwrt : 1; /* Page Write */
+ unsigned int blbset : 1; /* Boot Lock Bit Set */
+ unsigned int rwwsre : 1; /* Read While Write Section Read Enable */
+ unsigned int sigrd : 1; /* Signature Row Read */
+ unsigned int rwwsb : 1; /* Read While Write Section Busy */
+ unsigned int spmie : 1; /* SPM Interrupt Enable */
+};
+
+#define SPMCSR_struct _SFR_IO8_STRUCT(0x37, struct __reg_SPMCSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SPMCSR */
+
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+/* Extended Z-pointer Register for ELPM/SPM */
+#define RAMPZ _SFR_IO8(0x3B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_RAMPZ {
+ unsigned int rampz : 2; /* Extended Z-Pointer Value */
+ unsigned int : 6;
+};
+
+#define RAMPZ_struct _SFR_IO8_STRUCT(0x3b, struct __reg_RAMPZ)
+
+#endif /* __ASSEMBLER__ */
+
+ /* RAMPZ */
+
+#define RAMPZ0 0
+#define RAMPZ1 1
+
+/* Stack Pointer */
+#define SP _SFR_IO16(0x3D)
+#define SPL _SFR_IO8(0x3D)
+#define SPH _SFR_IO8(0x3E)
+
+/* Status Register */
+#define SREG _SFR_IO8(0x3F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SREG {
+ unsigned int c : 1; /* Carry Flag */
+ unsigned int z : 1; /* Zero Flag */
+ unsigned int n : 1; /* Negative Flag */
+ unsigned int v : 1; /* Two's Complement Overflow Flag */
+ unsigned int s : 1; /* Sign Bit */
+ unsigned int h : 1; /* Half Carry Flag */
+ unsigned int t : 1; /* Bit Copy Storage */
+ unsigned int i : 1; /* Global Interrupt Enable */
+};
+
+#define SREG_struct _SFR_IO8_STRUCT(0x3f, struct __reg_SREG)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SREG */
+
+#define SREG_C 0
+#define SREG_Z 1
+#define SREG_N 2
+#define SREG_V 3
+#define SREG_S 4
+#define SREG_H 5
+#define SREG_T 6
+#define SREG_I 7
+
+/* Watchdog Timer Control Register */
+#define WDTCSR _SFR_MEM8(0x60)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_WDTCSR {
+ unsigned int wdp : 3; /* Watchdog Timer Prescaler bits */
+ unsigned int wde : 1; /* Watch Dog Enable */
+ unsigned int wdce : 1; /* Watchdog Change Enable */
+ unsigned int : 1;
+ unsigned int wdie : 1; /* Watchdog Timeout Interrupt Enable */
+ unsigned int wdif : 1; /* Watchdog Timeout Interrupt Flag */
+};
+
+#define WDTCSR_struct _SFR_MEM8_STRUCT(0x60, struct __reg_WDTCSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* WDTCSR */
+
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+/* Clock Prescale Register */
+#define CLKPR _SFR_MEM8(0x61)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_CLKPR {
+ unsigned int clkps : 4; /* Clock Prescaler Select Bits */
+ unsigned int : 3;
+ unsigned int clkpce : 1; /* Clock Prescaler Change Enable */
+};
+
+#define CLKPR_struct _SFR_MEM8_STRUCT(0x61, struct __reg_CLKPR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* CLKPR */
+
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Power Reduction Register 2 */
+#define PRR2 _SFR_MEM8(0x63)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PRR2 {
+ unsigned int prram : 4; /* Power Reduction SRAM 3 */
+ unsigned int : 4;
+};
+
+#define PRR2_struct _SFR_MEM8_STRUCT(0x63, struct __reg_PRR2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PRR2 */
+
+#define PRRAM0 0
+#define PRRAM1 1
+#define PRRAM2 2
+#define PRRAM3 3
+
+/* Power Reduction Register0 */
+#define PRR0 _SFR_MEM8(0x64)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PRR0 {
+ unsigned int pradc : 1; /* Power Reduction ADC */
+ unsigned int prusart0 : 1; /* Power Reduction USART */
+ unsigned int prspi : 1; /* Power Reduction Serial Peripheral Interface */
+ unsigned int prtim1 : 1; /* Power Reduction Timer/Counter1 */
+ unsigned int prpga : 1; /* Power Reduction PGA */
+ unsigned int prtim0 : 1; /* Power Reduction Timer/Counter0 */
+ unsigned int prtim2 : 1; /* Power Reduction Timer/Counter2 */
+ unsigned int prtwi : 1; /* Power Reduction TWI */
+};
+
+#define PRR0_struct _SFR_MEM8_STRUCT(0x64, struct __reg_PRR0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PRR0 */
+
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRPGA 4
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+/* Power Reduction Register 1 */
+#define PRR1 _SFR_MEM8(0x65)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PRR1 {
+ unsigned int prusart : 3; /* Reserved */
+ unsigned int prtim3 : 1; /* Power Reduction Timer/Counter3 */
+ unsigned int prtim4 : 1; /* Power Reduction Timer/Counter4 */
+ unsigned int prtim5 : 1; /* Power Reduction Timer/Counter5 */
+ unsigned int prtrx24 : 1; /* Power Reduction Transceiver */
+ unsigned int : 1;
+};
+
+#define PRR1_struct _SFR_MEM8_STRUCT(0x65, struct __reg_PRR1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PRR1 */
+
+#define PRUSART1 0
+#define PRUSART2 1
+#define PRUSART3 2
+#define PRTIM3 3
+#define PRTIM4 4
+#define PRTIM5 5
+#define PRTRX24 6
+
+/* Oscillator Calibration Value */
+#define OSCCAL _SFR_MEM8(0x66)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_OSCCAL {
+ unsigned int cal : 8; /* Oscillator Calibration Tuning Value */
+};
+
+#define OSCCAL_struct _SFR_MEM8_STRUCT(0x66, struct __reg_OSCCAL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* OSCCAL */
+
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+/* Reference Voltage Calibration Register */
+#define BGCR _SFR_MEM8(0x67)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_BGCR {
+ unsigned int bgcal : 3; /* Coarse Calibration Bits */
+ unsigned int bgcal_fine : 4; /* Fine Calibration Bits */
+ unsigned int : 1;
+};
+
+#define BGCR_struct _SFR_MEM8_STRUCT(0x67, struct __reg_BGCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* BGCR */
+
+#define BGCAL0 0
+#define BGCAL1 1
+#define BGCAL2 2
+#define BGCAL_FINE0 3
+#define BGCAL_FINE1 4
+#define BGCAL_FINE2 5
+#define BGCAL_FINE3 6
+
+/* Pin Change Interrupt Control Register */
+#define PCICR _SFR_MEM8(0x68)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PCICR {
+ unsigned int pcie : 3; /* Pin Change Interrupt Enable 2 */
+ unsigned int : 5;
+};
+
+#define PCICR_struct _SFR_MEM8_STRUCT(0x68, struct __reg_PCICR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PCICR */
+
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_EICRA {
+ unsigned int isc0 : 2; /* External Interrupt 0 Sense Control Bit */
+ unsigned int isc1 : 2; /* External Interrupt 1 Sense Control Bit */
+ unsigned int isc2 : 2; /* External Interrupt 2 Sense Control Bit */
+ unsigned int isc3 : 2; /* External Interrupt 3 Sense Control Bit */
+};
+
+#define EICRA_struct _SFR_MEM8_STRUCT(0x69, struct __reg_EICRA)
+
+#endif /* __ASSEMBLER__ */
+
+ /* EICRA */
+
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+/* External Interrupt Control Register B */
+#define EICRB _SFR_MEM8(0x6A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_EICRB {
+ unsigned int isc4 : 2; /* External Interrupt 4 Sense Control Bit */
+ unsigned int isc5 : 2; /* External Interrupt 5 Sense Control Bit */
+ unsigned int isc6 : 2; /* External Interrupt 6 Sense Control Bit */
+ unsigned int isc7 : 2; /* External Interrupt 7 Sense Control Bit */
+};
+
+#define EICRB_struct _SFR_MEM8_STRUCT(0x6a, struct __reg_EICRB)
+
+#endif /* __ASSEMBLER__ */
+
+ /* EICRB */
+
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+/* Pin Change Mask Register 0 */
+#define PCMSK0 _SFR_MEM8(0x6B)
+
+ /* PCMSK0 */
+
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+/* Pin Change Mask Register 1 */
+#define PCMSK1 _SFR_MEM8(0x6C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PCMSK1 {
+ unsigned int pcint : 2; /* Pin Change Enable Mask */
+ unsigned int pcint1 : 6; /* Pin Change Enable Mask */
+};
+
+#define PCMSK1_struct _SFR_MEM8_STRUCT(0x6c, struct __reg_PCMSK1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PCMSK1 */
+
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Pin Change Mask Register 2 */
+#define PCMSK2 _SFR_MEM8(0x6D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PCMSK2 {
+ unsigned int pcint1 : 4; /* Pin Change Enable Mask */
+ unsigned int pcint2 : 4; /* Pin Change Enable Mask */
+};
+
+#define PCMSK2_struct _SFR_MEM8_STRUCT(0x6d, struct __reg_PCMSK2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PCMSK2 */
+
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+/* Timer/Counter0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIMSK0 {
+ unsigned int toie0 : 1; /* Timer/Counter0 Overflow Interrupt Enable */
+ unsigned int ocie0a : 1; /* Timer/Counter0 Output Compare Match A Interrupt Enable */
+ unsigned int ocie0b : 1; /* Timer/Counter0 Output Compare Match B Interrupt Enable */
+ unsigned int : 5;
+};
+
+#define TIMSK0_struct _SFR_MEM8_STRUCT(0x6e, struct __reg_TIMSK0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIMSK0 */
+
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+/* Timer/Counter1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIMSK1 {
+ unsigned int toie1 : 1; /* Timer/Counter1 Overflow Interrupt Enable */
+ unsigned int ocie1a : 1; /* Timer/Counter1 Output Compare A Match Interrupt Enable */
+ unsigned int ocie1b : 1; /* Timer/Counter1 Output Compare B Match Interrupt Enable */
+ unsigned int ocie1c : 1; /* Timer/Counter1 Output Compare C Match Interrupt Enable */
+ unsigned int : 1;
+ unsigned int icie1 : 1; /* Timer/Counter1 Input Capture Interrupt Enable */
+ unsigned int : 2;
+};
+
+#define TIMSK1_struct _SFR_MEM8_STRUCT(0x6f, struct __reg_TIMSK1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIMSK1 */
+
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+/* Timer/Counter Interrupt Mask register */
+#define TIMSK2 _SFR_MEM8(0x70)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIMSK2 {
+ unsigned int toie2 : 1; /* Timer/Counter2 Overflow Interrupt Enable */
+ unsigned int ocie2a : 1; /* Timer/Counter2 Output Compare Match A Interrupt Enable */
+ unsigned int ocie2b : 1; /* Timer/Counter2 Output Compare Match B Interrupt Enable */
+ unsigned int : 5;
+};
+
+#define TIMSK2_struct _SFR_MEM8_STRUCT(0x70, struct __reg_TIMSK2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIMSK2 */
+
+#define TOIE2 0
+#define TOIE2A 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+/* Timer/Counter3 Interrupt Mask Register */
+#define TIMSK3 _SFR_MEM8(0x71)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIMSK3 {
+ unsigned int toie3 : 1; /* Timer/Counter3 Overflow Interrupt Enable */
+ unsigned int ocie3a : 1; /* Timer/Counter3 Output Compare A Match Interrupt Enable */
+ unsigned int ocie3b : 1; /* Timer/Counter3 Output Compare B Match Interrupt Enable */
+ unsigned int ocie3c : 1; /* Timer/Counter3 Output Compare C Match Interrupt Enable */
+ unsigned int : 1;
+ unsigned int icie3 : 1; /* Timer/Counter3 Input Capture Interrupt Enable */
+ unsigned int : 2;
+};
+
+#define TIMSK3_struct _SFR_MEM8_STRUCT(0x71, struct __reg_TIMSK3)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIMSK3 */
+
+#define TOIE3 0
+#define OCIE3A 1
+#define OCIE3B 2
+#define OCIE3C 3
+#define ICIE3 5
+
+/* Timer/Counter4 Interrupt Mask Register */
+#define TIMSK4 _SFR_MEM8(0x72)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIMSK4 {
+ unsigned int toie4 : 1; /* Timer/Counter4 Overflow Interrupt Enable */
+ unsigned int ocie4a : 1; /* Timer/Counter4 Output Compare A Match Interrupt Enable */
+ unsigned int ocie4b : 1; /* Timer/Counter4 Output Compare B Match Interrupt Enable */
+ unsigned int ocie4c : 1; /* Timer/Counter4 Output Compare C Match Interrupt Enable */
+ unsigned int : 1;
+ unsigned int icie4 : 1; /* Timer/Counter4 Input Capture Interrupt Enable */
+ unsigned int : 2;
+};
+
+#define TIMSK4_struct _SFR_MEM8_STRUCT(0x72, struct __reg_TIMSK4)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIMSK4 */
+
+#define TOIE4 0
+#define OCIE4A 1
+#define OCIE4B 2
+#define OCIE4C 3
+#define ICIE4 5
+
+/* Timer/Counter5 Interrupt Mask Register */
+#define TIMSK5 _SFR_MEM8(0x73)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TIMSK5 {
+ unsigned int toie5 : 1; /* Timer/Counter5 Overflow Interrupt Enable */
+ unsigned int ocie5a : 1; /* Timer/Counter5 Output Compare A Match Interrupt Enable */
+ unsigned int ocie5b : 1; /* Timer/Counter5 Output Compare B Match Interrupt Enable */
+ unsigned int ocie5c : 1; /* Timer/Counter5 Output Compare C Match Interrupt Enable */
+ unsigned int : 1;
+ unsigned int icie5 : 1; /* Timer/Counter5 Input Capture Interrupt Enable */
+ unsigned int : 2;
+};
+
+#define TIMSK5_struct _SFR_MEM8_STRUCT(0x73, struct __reg_TIMSK5)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TIMSK5 */
+
+#define TOIE5 0
+#define OCIE5A 1
+#define OCIE5B 2
+#define OCIE5C 3
+#define ICIE5 5
+
+/* Flash Extended-Mode Control-Register */
+#define NEMCR _SFR_MEM8(0x75)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_NEMCR {
+ unsigned int : 4;
+ unsigned int aeam : 2; /* Address for Extended Address Mode of Extra Rows */
+ unsigned int eneam : 1; /* Enable Extended Address Mode for Extra Rows */
+ unsigned int : 1;
+};
+
+#define NEMCR_struct _SFR_MEM8_STRUCT(0x75, struct __reg_NEMCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* NEMCR */
+
+#define AEAM0 4
+#define AEAM1 5
+#define ENEAM 6
+
+/* The ADC Control and Status Register C */
+#define ADCSRC _SFR_MEM8(0x77)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ADCSRC {
+ unsigned int adsut : 5; /* ADC Start-up Time */
+ unsigned int res0 : 1; /* Reserved */
+ unsigned int adtht : 2; /* ADC Track-and-Hold Time */
+};
+
+#define ADCSRC_struct _SFR_MEM8_STRUCT(0x77, struct __reg_ADCSRC)
+
+#endif /* __ASSEMBLER__ */
+
+ /* ADCSRC */
+
+#define ADSUT0 0
+#define ADSUT1 1
+#define ADSUT2 2
+#define ADSUT3 3
+#define ADSUT4 4
+#define ADTHT0 6
+#define ADTHT1 7
+
+/* ADC Data Register Bytes */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+#endif /* __ASSEMBLER__ */
+#define ADCW _SFR_MEM16(0x78)
+#define ADCWL _SFR_MEM8(0x78)
+#define ADCWH _SFR_MEM8(0x79)
+
+/* The ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ADCSRA {
+ unsigned int adps : 3; /* ADC Prescaler Select Bits */
+ unsigned int adie : 1; /* ADC Interrupt Enable */
+ unsigned int adif : 1; /* ADC Interrupt Flag */
+ unsigned int adate : 1; /* ADC Auto Trigger Enable */
+ unsigned int adsc : 1; /* ADC Start Conversion */
+ unsigned int aden : 1; /* ADC Enable */
+};
+
+#define ADCSRA_struct _SFR_MEM8_STRUCT(0x7a, struct __reg_ADCSRA)
+
+#endif /* __ASSEMBLER__ */
+
+ /* ADCSRA */
+
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ADCSRB {
+ unsigned int adts : 3; /* ADC Auto Trigger Source */
+ unsigned int mux5 : 1; /* Analog Channel and Gain Selection Bits */
+ unsigned int acch : 1; /* Analog Channel Change */
+ unsigned int refok : 1; /* Reference Voltage OK */
+ unsigned int acme : 1; /* Analog Comparator Multiplexer Enable */
+ unsigned int avddok : 1; /* AVDD Supply Voltage OK */
+};
+
+#define ADCSRB_struct _SFR_MEM8_STRUCT(0x7b, struct __reg_ADCSRB)
+
+#endif /* __ASSEMBLER__ */
+
+ /* ADCSRB */
+
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define MUX5 3
+#define ACCH 4
+#define REFOK 5
+#define ACME 6
+#define AVDDOK 7
+
+/* The ADC Multiplexer Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ADMUX {
+ unsigned int mux : 5; /* Analog Channel and Gain Selection Bits */
+ unsigned int adlar : 1; /* ADC Left Adjust Result */
+ unsigned int refs : 2; /* Reference Selection Bits */
+};
+
+#define ADMUX_struct _SFR_MEM8_STRUCT(0x7c, struct __reg_ADMUX)
+
+#endif /* __ASSEMBLER__ */
+
+ /* ADMUX */
+
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Digital Input Disable Register 2 */
+#define DIDR2 _SFR_MEM8(0x7D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DIDR2 {
+ unsigned int adc8d : 1; /* Reserved Bits */
+ unsigned int adc9d : 1; /* Reserved Bits */
+ unsigned int adc10d : 1; /* Reserved Bits */
+ unsigned int adc11d : 1; /* Reserved Bits */
+ unsigned int adc12d : 1; /* Reserved Bits */
+ unsigned int adc13d : 1; /* Reserved Bits */
+ unsigned int adc14d : 1; /* Reserved Bits */
+ unsigned int adc15d : 1; /* Reserved Bits */
+};
+
+#define DIDR2_struct _SFR_MEM8_STRUCT(0x7d, struct __reg_DIDR2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DIDR2 */
+
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define ADC11D 3
+#define ADC12D 4
+#define ADC13D 5
+#define ADC14D 6
+#define ADC15D 7
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DIDR0 {
+ unsigned int adc0d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc1d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc2d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc3d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc4d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc5d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc6d : 1; /* Disable ADC7:0 Digital Input */
+ unsigned int adc7d : 1; /* Disable ADC7:0 Digital Input */
+};
+
+#define DIDR0_struct _SFR_MEM8_STRUCT(0x7e, struct __reg_DIDR0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DIDR0 */
+
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DIDR1 {
+ unsigned int ain0d : 1; /* AIN0 Digital Input Disable */
+ unsigned int ain1d : 1; /* AIN1 Digital Input Disable */
+ unsigned int : 6;
+};
+
+#define DIDR1_struct _SFR_MEM8_STRUCT(0x7f, struct __reg_DIDR1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DIDR1 */
+
+#define AIN0D 0
+#define AIN1D 1
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR1A {
+ unsigned int wgm1 : 2; /* Waveform Generation Mode */
+ unsigned int com1c : 2; /* Compare Output Mode for Channel C */
+ unsigned int com1b : 2; /* Compare Output Mode for Channel B */
+ unsigned int com1a : 2; /* Compare Output Mode for Channel A */
+};
+
+#define TCCR1A_struct _SFR_MEM8_STRUCT(0x80, struct __reg_TCCR1A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR1A */
+
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR1B {
+ unsigned int cs1 : 3; /* Clock Select */
+ unsigned int wgm1 : 2; /* Waveform Generation Mode */
+ unsigned int : 1;
+ unsigned int ices1 : 1; /* Input Capture 1 Edge Select */
+ unsigned int icnc1 : 1; /* Input Capture 1 Noise Canceller */
+};
+
+#define TCCR1B_struct _SFR_MEM8_STRUCT(0x81, struct __reg_TCCR1B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR1B */
+
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR1C {
+ unsigned int : 5;
+ unsigned int foc1c : 1; /* Force Output Compare for Channel C */
+ unsigned int foc1b : 1; /* Force Output Compare for Channel B */
+ unsigned int foc1a : 1; /* Force Output Compare for Channel A */
+};
+
+#define TCCR1C_struct _SFR_MEM8_STRUCT(0x82, struct __reg_TCCR1C)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR1C */
+
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+/* Timer/Counter1 Bytes */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Timer/Counter1 Input Capture Register Bytes */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Timer/Counter1 Output Compare Register A Bytes */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Timer/Counter1 Output Compare Register B Bytes */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Timer/Counter1 Output Compare Register C Bytes */
+#define OCR1C _SFR_MEM16(0x8C)
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CH _SFR_MEM8(0x8D)
+
+/* Timer/Counter3 Control Register A */
+#define TCCR3A _SFR_MEM8(0x90)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR3A {
+ unsigned int wgm3 : 2; /* Waveform Generation Mode */
+ unsigned int com3c : 2; /* Compare Output Mode for Channel C */
+ unsigned int com3b : 2; /* Compare Output Mode for Channel B */
+ unsigned int com3a : 2; /* Compare Output Mode for Channel A */
+};
+
+#define TCCR3A_struct _SFR_MEM8_STRUCT(0x90, struct __reg_TCCR3A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR3A */
+
+#define WGM30 0
+#define WGM31 1
+#define COM3C0 2
+#define COM3C1 3
+#define COM3B0 4
+#define COM3B1 5
+#define COM3A0 6
+#define COM3A1 7
+
+/* Timer/Counter3 Control Register B */
+#define TCCR3B _SFR_MEM8(0x91)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR3B {
+ unsigned int cs3 : 3; /* Clock Select */
+ unsigned int wgm3 : 2; /* Waveform Generation Mode */
+ unsigned int : 1;
+ unsigned int ices3 : 1; /* Input Capture 3 Edge Select */
+ unsigned int icnc3 : 1; /* Input Capture 3 Noise Canceller */
+};
+
+#define TCCR3B_struct _SFR_MEM8_STRUCT(0x91, struct __reg_TCCR3B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR3B */
+
+#define CS30 0
+#define CS31 1
+#define CS32 2
+#define WGM32 3
+#define WGM33 4
+#define ICES3 6
+#define ICNC3 7
+
+/* Timer/Counter3 Control Register C */
+#define TCCR3C _SFR_MEM8(0x92)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR3C {
+ unsigned int : 5;
+ unsigned int foc3c : 1; /* Force Output Compare for Channel C */
+ unsigned int foc3b : 1; /* Force Output Compare for Channel B */
+ unsigned int foc3a : 1; /* Force Output Compare for Channel A */
+};
+
+#define TCCR3C_struct _SFR_MEM8_STRUCT(0x92, struct __reg_TCCR3C)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR3C */
+
+#define FOC3C 5
+#define FOC3B 6
+#define FOC3A 7
+
+/* Timer/Counter3 Bytes */
+#define TCNT3 _SFR_MEM16(0x94)
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3H _SFR_MEM8(0x95)
+
+/* Timer/Counter3 Input Capture Register Bytes */
+#define ICR3 _SFR_MEM16(0x96)
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3H _SFR_MEM8(0x97)
+
+/* Timer/Counter3 Output Compare Register A Bytes */
+#define OCR3A _SFR_MEM16(0x98)
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AH _SFR_MEM8(0x99)
+
+/* Timer/Counter3 Output Compare Register B Bytes */
+#define OCR3B _SFR_MEM16(0x9A)
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BH _SFR_MEM8(0x9B)
+
+/* Timer/Counter3 Output Compare Register C Bytes */
+#define OCR3C _SFR_MEM16(0x9C)
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CH _SFR_MEM8(0x9D)
+
+/* Timer/Counter4 Control Register A */
+#define TCCR4A _SFR_MEM8(0xA0)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR4A {
+ unsigned int wgm4 : 2; /* Waveform Generation Mode */
+ unsigned int com4c : 2; /* Compare Output Mode for Channel C */
+ unsigned int com4b : 2; /* Compare Output Mode for Channel B */
+ unsigned int com4a : 2; /* Compare Output Mode for Channel A */
+};
+
+#define TCCR4A_struct _SFR_MEM8_STRUCT(0xa0, struct __reg_TCCR4A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR4A */
+
+#define WGM40 0
+#define WGM41 1
+#define COM4C0 2
+#define COM4C1 3
+#define COM4B0 4
+#define COM4B1 5
+#define COM4A0 6
+#define COM4A1 7
+
+/* Timer/Counter4 Control Register B */
+#define TCCR4B _SFR_MEM8(0xA1)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR4B {
+ unsigned int cs4 : 3; /* Clock Select */
+ unsigned int wgm4 : 2; /* Waveform Generation Mode */
+ unsigned int : 1;
+ unsigned int ices4 : 1; /* Input Capture 4 Edge Select */
+ unsigned int icnc4 : 1; /* Input Capture 4 Noise Canceller */
+};
+
+#define TCCR4B_struct _SFR_MEM8_STRUCT(0xa1, struct __reg_TCCR4B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR4B */
+
+#define CS40 0
+#define CS41 1
+#define CS42 2
+#define WGM42 3
+#define WGM43 4
+#define ICES4 6
+#define ICNC4 7
+
+/* Timer/Counter4 Control Register C */
+#define TCCR4C _SFR_MEM8(0xA2)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR4C {
+ unsigned int : 5;
+ unsigned int foc4c : 1; /* Force Output Compare for Channel C */
+ unsigned int foc4b : 1; /* Force Output Compare for Channel B */
+ unsigned int foc4a : 1; /* Force Output Compare for Channel A */
+};
+
+#define TCCR4C_struct _SFR_MEM8_STRUCT(0xa2, struct __reg_TCCR4C)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR4C */
+
+#define FOC4C 5
+#define FOC4B 6
+#define FOC4A 7
+
+/* Timer/Counter4 Bytes */
+#define TCNT4 _SFR_MEM16(0xA4)
+#define TCNT4L _SFR_MEM8(0xA4)
+#define TCNT4H _SFR_MEM8(0xA5)
+
+/* Timer/Counter4 Input Capture Register Bytes */
+#define ICR4 _SFR_MEM16(0xA6)
+#define ICR4L _SFR_MEM8(0xA6)
+#define ICR4H _SFR_MEM8(0xA7)
+
+/* Timer/Counter4 Output Compare Register A Bytes */
+#define OCR4A _SFR_MEM16(0xA8)
+#define OCR4AL _SFR_MEM8(0xA8)
+#define OCR4AH _SFR_MEM8(0xA9)
+
+/* Timer/Counter4 Output Compare Register B Bytes */
+#define OCR4B _SFR_MEM16(0xAA)
+#define OCR4BL _SFR_MEM8(0xAA)
+#define OCR4BH _SFR_MEM8(0xAB)
+
+/* Timer/Counter4 Output Compare Register C Bytes */
+#define OCR4C _SFR_MEM16(0xAC)
+#define OCR4CL _SFR_MEM8(0xAC)
+#define OCR4CH _SFR_MEM8(0xAD)
+
+/* Timer/Counter2 Control Register A */
+#define TCCR2A _SFR_MEM8(0xB0)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR2A {
+ unsigned int wgm2 : 2; /* Waveform Generation Mode */
+ unsigned int : 2;
+ unsigned int com2b : 2; /* Compare Match Output B Mode */
+ unsigned int com2a : 2; /* Compare Match Output A Mode */
+};
+
+#define TCCR2A_struct _SFR_MEM8_STRUCT(0xb0, struct __reg_TCCR2A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR2A */
+
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+/* Timer/Counter2 Control Register B */
+#define TCCR2B _SFR_MEM8(0xB1)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR2B {
+ unsigned int cs2 : 3; /* Clock Select */
+ unsigned int wgm22 : 1; /* Waveform Generation Mode */
+ unsigned int : 2;
+ unsigned int foc2b : 1; /* Force Output Compare B */
+ unsigned int foc2a : 1; /* Force Output Compare A */
+};
+
+#define TCCR2B_struct _SFR_MEM8_STRUCT(0xb1, struct __reg_TCCR2B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR2B */
+
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+/* Timer/Counter2 */
+#define TCNT2 _SFR_MEM8(0xB2)
+
+ /* TCNT2 */
+
+#define TCNT20 0
+#define TCNT21 1
+#define TCNT22 2
+#define TCNT23 3
+#define TCNT24 4
+#define TCNT25 5
+#define TCNT26 6
+#define TCNT27 7
+
+/* Timer/Counter2 Output Compare Register A */
+#define OCR2A _SFR_MEM8(0xB3)
+
+ /* OCR2A */
+
+#define OCR2A0 0
+#define OCR2A1 1
+#define OCR2A2 2
+#define OCR2A3 3
+#define OCR2A4 4
+#define OCR2A5 5
+#define OCR2A6 6
+#define OCR2A7 7
+
+/* Timer/Counter2 Output Compare Register B */
+#define OCR2B _SFR_MEM8(0xB4)
+
+ /* OCR2B */
+
+#define OCR2B0 0
+#define OCR2B1 1
+#define OCR2B2 2
+#define OCR2B3 3
+#define OCR2B4 4
+#define OCR2B5 5
+#define OCR2B6 6
+#define OCR2B7 7
+
+/* Asynchronous Status Register */
+#define ASSR _SFR_MEM8(0xB6)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ASSR {
+ unsigned int tcr2bub : 1; /* Timer/Counter2 Control Register B Update Busy */
+ unsigned int tcr2aub : 1; /* Timer/Counter2 Control Register A Update Busy */
+ unsigned int ocr2bub : 1; /* Timer/Counter2 Output Compare Register B Update Busy */
+ unsigned int ocr2aub : 1; /* Timer/Counter2 Output Compare Register A Update Busy */
+ unsigned int tcn2ub : 1; /* Timer/Counter2 Update Busy */
+ unsigned int as2 : 1; /* Timer/Counter2 Asynchronous Mode */
+ unsigned int exclk : 1; /* Enable External Clock Input */
+ unsigned int exclkamr : 1; /* Enable External Clock Input for AMR */
+};
+
+#define ASSR_struct _SFR_MEM8_STRUCT(0xb6, struct __reg_ASSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* ASSR */
+
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+#define EXCLKAMR 7
+
+/* TWI Bit Rate Register */
+#define TWBR _SFR_MEM8(0xB8)
+
+ /* TWBR */
+
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+/* TWI Status Register */
+#define TWSR _SFR_MEM8(0xB9)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TWSR {
+ unsigned int twps : 2; /* TWI Prescaler Bits */
+ unsigned int : 1;
+ unsigned int tws : 5; /* TWI Status */
+};
+
+#define TWSR_struct _SFR_MEM8_STRUCT(0xb9, struct __reg_TWSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TWSR */
+
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+/* TWI (Slave) Address Register */
+#define TWAR _SFR_MEM8(0xBA)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TWAR {
+ unsigned int twgce : 1; /* TWI General Call Recognition Enable Bit */
+ unsigned int twa : 7; /* TWI (Slave) Address */
+};
+
+#define TWAR_struct _SFR_MEM8_STRUCT(0xba, struct __reg_TWAR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TWAR */
+
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+/* TWI Data Register */
+#define TWDR _SFR_MEM8(0xBB)
+
+ /* TWDR */
+
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+/* TWI Control Register */
+#define TWCR _SFR_MEM8(0xBC)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TWCR {
+ unsigned int twie : 1; /* TWI Interrupt Enable */
+ unsigned int : 1;
+ unsigned int twen : 1; /* TWI Enable Bit */
+ unsigned int twwc : 1; /* TWI Write Collision Flag */
+ unsigned int twsto : 1; /* TWI STOP Condition Bit */
+ unsigned int twsta : 1; /* TWI START Condition Bit */
+ unsigned int twea : 1; /* TWI Enable Acknowledge Bit */
+ unsigned int twint : 1; /* TWI Interrupt Flag */
+};
+
+#define TWCR_struct _SFR_MEM8_STRUCT(0xbc, struct __reg_TWCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TWCR */
+
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+/* TWI (Slave) Address Mask Register */
+#define TWAMR _SFR_MEM8(0xBD)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TWAMR {
+ unsigned int : 1;
+ unsigned int twam : 7; /* TWI Address Mask */
+};
+
+#define TWAMR_struct _SFR_MEM8_STRUCT(0xbd, struct __reg_TWAMR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TWAMR */
+
+#define TWAM0 1
+#define TWAMR0 1
+#define TWAM1 2
+#define TWAMR1 2
+#define TWAM2 3
+#define TWAMR2 3
+#define TWAM3 4
+#define TWAMR3 4
+#define TWAM4 5
+#define TWAMR4 5
+#define TWAM5 6
+#define TWAMR5 6
+#define TWAM6 7
+#define TWAMR6 7
+
+/* USART0 Control and Status Register A */
+#define UCSR0A _SFR_MEM8(0xC0)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_UCSR0A {
+ unsigned int mpcm0 : 1; /* Multi-processor Communication Mode */
+ unsigned int u2x0 : 1; /* Double the USART Transmission Speed */
+ unsigned int upe0 : 1; /* USART Parity Error */
+ unsigned int dor0 : 1; /* Data OverRun */
+ unsigned int fe0 : 1; /* Frame Error */
+ unsigned int udre0 : 1; /* USART Data Register Empty */
+ unsigned int txc0 : 1; /* USART Transmit Complete */
+ unsigned int rxc0 : 1; /* USART Receive Complete */
+};
+
+#define UCSR0A_struct _SFR_MEM8_STRUCT(0xc0, struct __reg_UCSR0A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* UCSR0A */
+
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+/* USART0 Control and Status Register B */
+#define UCSR0B _SFR_MEM8(0xC1)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_UCSR0B {
+ unsigned int txb80 : 1; /* Transmit Data Bit 8 */
+ unsigned int rxb80 : 1; /* Receive Data Bit 8 */
+ unsigned int ucsz02 : 1; /* Character Size */
+ unsigned int txen0 : 1; /* Transmitter Enable */
+ unsigned int rxen0 : 1; /* Receiver Enable */
+ unsigned int udrie0 : 1; /* USART Data Register Empty Interrupt Enable */
+ unsigned int txcie0 : 1; /* TX Complete Interrupt Enable */
+ unsigned int rxcie0 : 1; /* RX Complete Interrupt Enable */
+};
+
+#define UCSR0B_struct _SFR_MEM8_STRUCT(0xc1, struct __reg_UCSR0B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* UCSR0B */
+
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+/* USART0 Control and Status Register C */
+#define UCSR0C _SFR_MEM8(0xC2)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_UCSR0C {
+ unsigned int ucpol0 : 1; /* Clock Polarity */
+ unsigned int ucsz0 : 2; /* Character Size */
+ unsigned int ucpha0 : 1; /* Clock Phase */
+ unsigned int udord0 : 1; /* Data Order */
+ unsigned int usbs0 : 1; /* Stop Bit Select */
+ unsigned int upm0 : 2; /* Parity Mode */
+ unsigned int umsel0 : 2; /* USART Mode Select */
+};
+
+#define UCSR0C_struct _SFR_MEM8_STRUCT(0xc2, struct __reg_UCSR0C)
+
+#endif /* __ASSEMBLER__ */
+
+ /* UCSR0C */
+
+#define UCPOL0 0
+#define UCPHA0 1
+#define UCPHA0 1
+#define UCSZ00 1
+#define UDORD0 2
+#define UDORD0 2
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL0 6
+#define UMSEL01 7
+#define UMSEL1 7
+
+/* USART0 Baud Rate Register Bytes */
+#define UBRR0 _SFR_MEM16(0xC4)
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+/* USART0 I/O Data Register */
+#define UDR0 _SFR_MEM8(0xC6)
+
+ /* UDR0 */
+
+#define UDR00 0
+#define UDR01 1
+#define UDR02 2
+#define UDR03 3
+#define UDR04 4
+#define UDR05 5
+#define UDR06 6
+#define UDR07 7
+
+/* USART1 Control and Status Register A */
+#define UCSR1A _SFR_MEM8(0xC8)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_UCSR1A {
+ unsigned int mpcm1 : 1; /* Multi-processor Communication Mode */
+ unsigned int u2x1 : 1; /* Double the USART Transmission Speed */
+ unsigned int upe1 : 1; /* USART Parity Error */
+ unsigned int dor1 : 1; /* Data OverRun */
+ unsigned int fe1 : 1; /* Frame Error */
+ unsigned int udre1 : 1; /* USART Data Register Empty */
+ unsigned int txc1 : 1; /* USART Transmit Complete */
+ unsigned int rxc1 : 1; /* USART Receive Complete */
+};
+
+#define UCSR1A_struct _SFR_MEM8_STRUCT(0xc8, struct __reg_UCSR1A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* UCSR1A */
+
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+/* USART1 Control and Status Register B */
+#define UCSR1B _SFR_MEM8(0xC9)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_UCSR1B {
+ unsigned int txb81 : 1; /* Transmit Data Bit 8 */
+ unsigned int rxb81 : 1; /* Receive Data Bit 8 */
+ unsigned int ucsz12 : 1; /* Character Size */
+ unsigned int txen1 : 1; /* Transmitter Enable */
+ unsigned int rxen1 : 1; /* Receiver Enable */
+ unsigned int udrie1 : 1; /* USART Data Register Empty Interrupt Enable */
+ unsigned int txcie1 : 1; /* TX Complete Interrupt Enable */
+ unsigned int rxcie1 : 1; /* RX Complete Interrupt Enable */
+};
+
+#define UCSR1B_struct _SFR_MEM8_STRUCT(0xc9, struct __reg_UCSR1B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* UCSR1B */
+
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+/* USART1 Control and Status Register C */
+#define UCSR1C _SFR_MEM8(0xCA)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_UCSR1C {
+ unsigned int ucpol1 : 1; /* Clock Polarity */
+ unsigned int ucsz1 : 2; /* Character Size */
+ unsigned int ucpha1 : 1; /* Clock Phase */
+ unsigned int udord1 : 1; /* Data Order */
+ unsigned int usbs1 : 1; /* Stop Bit Select */
+ unsigned int upm1 : 2; /* Parity Mode */
+ unsigned int umsel1 : 2; /* USART Mode Select */
+};
+
+#define UCSR1C_struct _SFR_MEM8_STRUCT(0xca, struct __reg_UCSR1C)
+
+#endif /* __ASSEMBLER__ */
+
+ /* UCSR1C */
+
+#define UCPOL1 0
+#define UCPHA1 1
+#define UCPHA1 1
+#define UCSZ10 1
+#define UDORD1 2
+#define UDORD1 2
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+/* USART1 Baud Rate Register Bytes */
+#define UBRR1 _SFR_MEM16(0xCC)
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1H _SFR_MEM8(0xCD)
+
+/* USART1 I/O Data Register */
+#define UDR1 _SFR_MEM8(0xCE)
+
+ /* UDR1 */
+
+#define UDR10 0
+#define UDR11 1
+#define UDR12 2
+#define UDR13 3
+#define UDR14 4
+#define UDR15 5
+#define UDR16 6
+#define UDR17 7
+
+/* Symbol Counter Control Register 0 */
+#define SCCR0 _SFR_MEM8(0xDC)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCCR0 {
+ unsigned int sccmp : 3; /* Symbol Counter Compare Unit 3 Mode select */
+ unsigned int sctse : 1; /* Symbol Counter Automatic Timestamping enable */
+ unsigned int sccksel : 1; /* Symbol Counter Clock Source select */
+ unsigned int scen : 1; /* Symbol Counter enable */
+ unsigned int scmbts : 1; /* Manual Beacon Timestamp */
+ unsigned int scres : 1; /* Symbol Counter Synchronization */
+};
+
+#define SCCR0_struct _SFR_MEM8_STRUCT(0xdc, struct __reg_SCCR0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCCR0 */
+
+#define SCCMP1 0
+#define SCCMP2 1
+#define SCCMP3 2
+#define SCTSE 3
+#define SCCKSEL 4
+#define SCEN 5
+#define SCMBTS 6
+#define SCRES 7
+
+/* Symbol Counter Control Register 1 */
+#define SCCR1 _SFR_MEM8(0xDD)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCCR1 {
+ unsigned int scenbo : 1; /* Backoff Slot Counter enable */
+ unsigned int : 7;
+};
+
+#define SCCR1_struct _SFR_MEM8_STRUCT(0xdd, struct __reg_SCCR1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCCR1 */
+
+#define SCENBO 0
+
+/* Symbol Counter Status Register */
+#define SCSR _SFR_MEM8(0xDE)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCSR {
+ unsigned int scbsy : 1; /* Symbol Counter busy */
+ unsigned int : 7;
+};
+
+#define SCSR_struct _SFR_MEM8_STRUCT(0xde, struct __reg_SCSR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCSR */
+
+#define SCBSY 0
+
+/* Symbol Counter Interrupt Mask Register */
+#define SCIRQM _SFR_MEM8(0xDF)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCIRQM {
+ unsigned int irqmcp : 3; /* Symbol Counter Compare Match 3 IRQ enable */
+ unsigned int irqmof : 1; /* Symbol Counter Overflow IRQ enable */
+ unsigned int irqmbo : 1; /* Backoff Slot Counter IRQ enable */
+ unsigned int : 3;
+};
+
+#define SCIRQM_struct _SFR_MEM8_STRUCT(0xdf, struct __reg_SCIRQM)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCIRQM */
+
+#define IRQMCP1 0
+#define IRQMCP2 1
+#define IRQMCP3 2
+#define IRQMOF 3
+#define IRQMBO 4
+
+/* Symbol Counter Interrupt Status Register */
+#define SCIRQS _SFR_MEM8(0xE0)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCIRQS {
+ unsigned int irqscp : 3; /* Compare Unit 3 Compare Match IRQ */
+ unsigned int irqsof : 1; /* Symbol Counter Overflow IRQ */
+ unsigned int irqsbo : 1; /* Backoff Slot Counter IRQ */
+ unsigned int : 3;
+};
+
+#define SCIRQS_struct _SFR_MEM8_STRUCT(0xe0, struct __reg_SCIRQS)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCIRQS */
+
+#define IRQSCP1 0
+#define IRQSCP2 1
+#define IRQSCP3 2
+#define IRQSOF 3
+#define IRQSBO 4
+
+/* Symbol Counter Register LL-Byte */
+#define SCCNTLL _SFR_MEM8(0xE1)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCCNTLL {
+ unsigned int sccntll : 8; /* Symbol Counter Register LL-Byte */
+};
+
+#define SCCNTLL_struct _SFR_MEM8_STRUCT(0xe1, struct __reg_SCCNTLL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCCNTLL */
+
+#define SCCNTLL0 0
+#define SCCNTLL1 1
+#define SCCNTLL2 2
+#define SCCNTLL3 3
+#define SCCNTLL4 4
+#define SCCNTLL5 5
+#define SCCNTLL6 6
+#define SCCNTLL7 7
+
+/* Symbol Counter Register LH-Byte */
+#define SCCNTLH _SFR_MEM8(0xE2)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCCNTLH {
+ unsigned int sccntlh : 8; /* Symbol Counter Register LH-Byte */
+};
+
+#define SCCNTLH_struct _SFR_MEM8_STRUCT(0xe2, struct __reg_SCCNTLH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCCNTLH */
+
+#define SCCNTLH0 0
+#define SCCNTLH1 1
+#define SCCNTLH2 2
+#define SCCNTLH3 3
+#define SCCNTLH4 4
+#define SCCNTLH5 5
+#define SCCNTLH6 6
+#define SCCNTLH7 7
+
+/* Symbol Counter Register HL-Byte */
+#define SCCNTHL _SFR_MEM8(0xE3)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCCNTHL {
+ unsigned int sccnthl : 8; /* Symbol Counter Register HL-Byte */
+};
+
+#define SCCNTHL_struct _SFR_MEM8_STRUCT(0xe3, struct __reg_SCCNTHL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCCNTHL */
+
+#define SCCNTHL0 0
+#define SCCNTHL1 1
+#define SCCNTHL2 2
+#define SCCNTHL3 3
+#define SCCNTHL4 4
+#define SCCNTHL5 5
+#define SCCNTHL6 6
+#define SCCNTHL7 7
+
+/* Symbol Counter Register HH-Byte */
+#define SCCNTHH _SFR_MEM8(0xE4)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCCNTHH {
+ unsigned int sccnthh : 8; /* Symbol Counter Register HH-Byte */
+};
+
+#define SCCNTHH_struct _SFR_MEM8_STRUCT(0xe4, struct __reg_SCCNTHH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCCNTHH */
+
+#define SCCNTHH0 0
+#define SCCNTHH1 1
+#define SCCNTHH2 2
+#define SCCNTHH3 3
+#define SCCNTHH4 4
+#define SCCNTHH5 5
+#define SCCNTHH6 6
+#define SCCNTHH7 7
+
+/* Symbol Counter Beacon Timestamp Register LL-Byte */
+#define SCBTSRLL _SFR_MEM8(0xE5)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCBTSRLL {
+ unsigned int scbtsrll : 8; /* Symbol Counter Beacon Timestamp Register LL-Byte */
+};
+
+#define SCBTSRLL_struct _SFR_MEM8_STRUCT(0xe5, struct __reg_SCBTSRLL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCBTSRLL */
+
+#define SCBTSRLL0 0
+#define SCBTSRLL1 1
+#define SCBTSRLL2 2
+#define SCBTSRLL3 3
+#define SCBTSRLL4 4
+#define SCBTSRLL5 5
+#define SCBTSRLL6 6
+#define SCBTSRLL7 7
+
+/* Symbol Counter Beacon Timestamp Register LH-Byte */
+#define SCBTSRLH _SFR_MEM8(0xE6)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCBTSRLH {
+ unsigned int scbtsrlh : 8; /* Symbol Counter Beacon Timestamp Register LH-Byte */
+};
+
+#define SCBTSRLH_struct _SFR_MEM8_STRUCT(0xe6, struct __reg_SCBTSRLH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCBTSRLH */
+
+#define SCBTSRLH0 0
+#define SCBTSRLH1 1
+#define SCBTSRLH2 2
+#define SCBTSRLH3 3
+#define SCBTSRLH4 4
+#define SCBTSRLH5 5
+#define SCBTSRLH6 6
+#define SCBTSRLH7 7
+
+/* Symbol Counter Beacon Timestamp Register HL-Byte */
+#define SCBTSRHL _SFR_MEM8(0xE7)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCBTSRHL {
+ unsigned int scbtsrhl : 8; /* Symbol Counter Beacon Timestamp Register HL-Byte */
+};
+
+#define SCBTSRHL_struct _SFR_MEM8_STRUCT(0xe7, struct __reg_SCBTSRHL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCBTSRHL */
+
+#define SCBTSRHL0 0
+#define SCBTSRHL1 1
+#define SCBTSRHL2 2
+#define SCBTSRHL3 3
+#define SCBTSRHL4 4
+#define SCBTSRHL5 5
+#define SCBTSRHL6 6
+#define SCBTSRHL7 7
+
+/* Symbol Counter Beacon Timestamp Register HH-Byte */
+#define SCBTSRHH _SFR_MEM8(0xE8)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCBTSRHH {
+ unsigned int scbtsrhh : 8; /* Symbol Counter Beacon Timestamp Register HH-Byte */
+};
+
+#define SCBTSRHH_struct _SFR_MEM8_STRUCT(0xe8, struct __reg_SCBTSRHH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCBTSRHH */
+
+#define SCBTSRHH0 0
+#define SCBTSRHH1 1
+#define SCBTSRHH2 2
+#define SCBTSRHH3 3
+#define SCBTSRHH4 4
+#define SCBTSRHH5 5
+#define SCBTSRHH6 6
+#define SCBTSRHH7 7
+
+/* Symbol Counter Frame Timestamp Register LL-Byte */
+#define SCTSRLL _SFR_MEM8(0xE9)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCTSRLL {
+ unsigned int sctsrll : 8; /* Symbol Counter Frame Timestamp Register LL-Byte */
+};
+
+#define SCTSRLL_struct _SFR_MEM8_STRUCT(0xe9, struct __reg_SCTSRLL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCTSRLL */
+
+#define SCTSRLL0 0
+#define SCTSRLL1 1
+#define SCTSRLL2 2
+#define SCTSRLL3 3
+#define SCTSRLL4 4
+#define SCTSRLL5 5
+#define SCTSRLL6 6
+#define SCTSRLL7 7
+
+/* Symbol Counter Frame Timestamp Register LH-Byte */
+#define SCTSRLH _SFR_MEM8(0xEA)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCTSRLH {
+ unsigned int sctsrlh : 8; /* Symbol Counter Frame Timestamp Register LH-Byte */
+};
+
+#define SCTSRLH_struct _SFR_MEM8_STRUCT(0xea, struct __reg_SCTSRLH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCTSRLH */
+
+#define SCTSRLH0 0
+#define SCTSRLH1 1
+#define SCTSRLH2 2
+#define SCTSRLH3 3
+#define SCTSRLH4 4
+#define SCTSRLH5 5
+#define SCTSRLH6 6
+#define SCTSRLH7 7
+
+/* Symbol Counter Frame Timestamp Register HL-Byte */
+#define SCTSRHL _SFR_MEM8(0xEB)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCTSRHL {
+ unsigned int sctsrhl : 8; /* Symbol Counter Frame Timestamp Register HL-Byte */
+};
+
+#define SCTSRHL_struct _SFR_MEM8_STRUCT(0xeb, struct __reg_SCTSRHL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCTSRHL */
+
+#define SCTSRHL0 0
+#define SCTSRHL1 1
+#define SCTSRHL2 2
+#define SCTSRHL3 3
+#define SCTSRHL4 4
+#define SCTSRHL5 5
+#define SCTSRHL6 6
+#define SCTSRHL7 7
+
+/* Symbol Counter Frame Timestamp Register HH-Byte */
+#define SCTSRHH _SFR_MEM8(0xEC)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCTSRHH {
+ unsigned int sctsrhh : 8; /* Symbol Counter Frame Timestamp Register HH-Byte */
+};
+
+#define SCTSRHH_struct _SFR_MEM8_STRUCT(0xec, struct __reg_SCTSRHH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCTSRHH */
+
+#define SCTSRHH0 0
+#define SCTSRHH1 1
+#define SCTSRHH2 2
+#define SCTSRHH3 3
+#define SCTSRHH4 4
+#define SCTSRHH5 5
+#define SCTSRHH6 6
+#define SCTSRHH7 7
+
+/* Symbol Counter Output Compare Register 3 LL-Byte */
+#define SCOCR3LL _SFR_MEM8(0xED)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR3LL {
+ unsigned int scocr3ll : 8; /* Symbol Counter Output Compare Register 3 LL-Byte */
+};
+
+#define SCOCR3LL_struct _SFR_MEM8_STRUCT(0xed, struct __reg_SCOCR3LL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR3LL */
+
+#define SCOCR3LL0 0
+#define SCOCR3LL1 1
+#define SCOCR3LL2 2
+#define SCOCR3LL3 3
+#define SCOCR3LL4 4
+#define SCOCR3LL5 5
+#define SCOCR3LL6 6
+#define SCOCR3LL7 7
+
+/* Symbol Counter Output Compare Register 3 LH-Byte */
+#define SCOCR3LH _SFR_MEM8(0xEE)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR3LH {
+ unsigned int scocr3lh : 8; /* Symbol Counter Output Compare Register 3 LH-Byte */
+};
+
+#define SCOCR3LH_struct _SFR_MEM8_STRUCT(0xee, struct __reg_SCOCR3LH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR3LH */
+
+#define SCOCR3LH0 0
+#define SCOCR3LH1 1
+#define SCOCR3LH2 2
+#define SCOCR3LH3 3
+#define SCOCR3LH4 4
+#define SCOCR3LH5 5
+#define SCOCR3LH6 6
+#define SCOCR3LH7 7
+
+/* Symbol Counter Output Compare Register 3 HL-Byte */
+#define SCOCR3HL _SFR_MEM8(0xEF)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR3HL {
+ unsigned int scocr3hl : 8; /* Symbol Counter Output Compare Register 3 HL-Byte */
+};
+
+#define SCOCR3HL_struct _SFR_MEM8_STRUCT(0xef, struct __reg_SCOCR3HL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR3HL */
+
+#define SCOCR3HL0 0
+#define SCOCR3HL1 1
+#define SCOCR3HL2 2
+#define SCOCR3HL3 3
+#define SCOCR3HL4 4
+#define SCOCR3HL5 5
+#define SCOCR3HL6 6
+#define SCOCR3HL7 7
+
+/* Symbol Counter Output Compare Register 3 HH-Byte */
+#define SCOCR3HH _SFR_MEM8(0xF0)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR3HH {
+ unsigned int scocr3hh : 8; /* Symbol Counter Output Compare Register 3 HH-Byte */
+};
+
+#define SCOCR3HH_struct _SFR_MEM8_STRUCT(0xf0, struct __reg_SCOCR3HH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR3HH */
+
+#define SCOCR3HH0 0
+#define SCOCR3HH1 1
+#define SCOCR3HH2 2
+#define SCOCR3HH3 3
+#define SCOCR3HH4 4
+#define SCOCR3HH5 5
+#define SCOCR3HH6 6
+#define SCOCR3HH7 7
+
+/* Symbol Counter Output Compare Register 2 LL-Byte */
+#define SCOCR2LL _SFR_MEM8(0xF1)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR2LL {
+ unsigned int scocr2ll : 8; /* Symbol Counter Output Compare Register 2 LL-Byte */
+};
+
+#define SCOCR2LL_struct _SFR_MEM8_STRUCT(0xf1, struct __reg_SCOCR2LL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR2LL */
+
+#define SCOCR2LL0 0
+#define SCOCR2LL1 1
+#define SCOCR2LL2 2
+#define SCOCR2LL3 3
+#define SCOCR2LL4 4
+#define SCOCR2LL5 5
+#define SCOCR2LL6 6
+#define SCOCR2LL7 7
+
+/* Symbol Counter Output Compare Register 2 LH-Byte */
+#define SCOCR2LH _SFR_MEM8(0xF2)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR2LH {
+ unsigned int scocr2lh : 8; /* Symbol Counter Output Compare Register 2 LH-Byte */
+};
+
+#define SCOCR2LH_struct _SFR_MEM8_STRUCT(0xf2, struct __reg_SCOCR2LH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR2LH */
+
+#define SCOCR2LH0 0
+#define SCOCR2LH1 1
+#define SCOCR2LH2 2
+#define SCOCR2LH3 3
+#define SCOCR2LH4 4
+#define SCOCR2LH5 5
+#define SCOCR2LH6 6
+#define SCOCR2LH7 7
+
+/* Symbol Counter Output Compare Register 2 HL-Byte */
+#define SCOCR2HL _SFR_MEM8(0xF3)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR2HL {
+ unsigned int scocr2hl : 8; /* Symbol Counter Output Compare Register 2 HL-Byte */
+};
+
+#define SCOCR2HL_struct _SFR_MEM8_STRUCT(0xf3, struct __reg_SCOCR2HL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR2HL */
+
+#define SCOCR2HL0 0
+#define SCOCR2HL1 1
+#define SCOCR2HL2 2
+#define SCOCR2HL3 3
+#define SCOCR2HL4 4
+#define SCOCR2HL5 5
+#define SCOCR2HL6 6
+#define SCOCR2HL7 7
+
+/* Symbol Counter Output Compare Register 2 HH-Byte */
+#define SCOCR2HH _SFR_MEM8(0xF4)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR2HH {
+ unsigned int scocr2hh : 8; /* Symbol Counter Output Compare Register 2 HH-Byte */
+};
+
+#define SCOCR2HH_struct _SFR_MEM8_STRUCT(0xf4, struct __reg_SCOCR2HH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR2HH */
+
+#define SCOCR2HH0 0
+#define SCOCR2HH1 1
+#define SCOCR2HH2 2
+#define SCOCR2HH3 3
+#define SCOCR2HH4 4
+#define SCOCR2HH5 5
+#define SCOCR2HH6 6
+#define SCOCR2HH7 7
+
+/* Symbol Counter Output Compare Register 1 LL-Byte */
+#define SCOCR1LL _SFR_MEM8(0xF5)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR1LL {
+ unsigned int scocr1ll : 8; /* Symbol Counter Output Compare Register 1 LL-Byte */
+};
+
+#define SCOCR1LL_struct _SFR_MEM8_STRUCT(0xf5, struct __reg_SCOCR1LL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR1LL */
+
+#define SCOCR1LL0 0
+#define SCOCR1LL1 1
+#define SCOCR1LL2 2
+#define SCOCR1LL3 3
+#define SCOCR1LL4 4
+#define SCOCR1LL5 5
+#define SCOCR1LL6 6
+#define SCOCR1LL7 7
+
+/* Symbol Counter Output Compare Register 1 LH-Byte */
+#define SCOCR1LH _SFR_MEM8(0xF6)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR1LH {
+ unsigned int scocr1lh : 8; /* Symbol Counter Output Compare Register 1 LH-Byte */
+};
+
+#define SCOCR1LH_struct _SFR_MEM8_STRUCT(0xf6, struct __reg_SCOCR1LH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR1LH */
+
+#define SCOCR1LH0 0
+#define SCOCR1LH1 1
+#define SCOCR1LH2 2
+#define SCOCR1LH3 3
+#define SCOCR1LH4 4
+#define SCOCR1LH5 5
+#define SCOCR1LH6 6
+#define SCOCR1LH7 7
+
+/* Symbol Counter Output Compare Register 1 HL-Byte */
+#define SCOCR1HL _SFR_MEM8(0xF7)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR1HL {
+ unsigned int scocr1hl : 8; /* Symbol Counter Output Compare Register 1 HL-Byte */
+};
+
+#define SCOCR1HL_struct _SFR_MEM8_STRUCT(0xf7, struct __reg_SCOCR1HL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR1HL */
+
+#define SCOCR1HL0 0
+#define SCOCR1HL1 1
+#define SCOCR1HL2 2
+#define SCOCR1HL3 3
+#define SCOCR1HL4 4
+#define SCOCR1HL5 5
+#define SCOCR1HL6 6
+#define SCOCR1HL7 7
+
+/* Symbol Counter Output Compare Register 1 HH-Byte */
+#define SCOCR1HH _SFR_MEM8(0xF8)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SCOCR1HH {
+ unsigned int scocr1hh : 8; /* Symbol Counter Output Compare Register 1 HH-Byte */
+};
+
+#define SCOCR1HH_struct _SFR_MEM8_STRUCT(0xf8, struct __reg_SCOCR1HH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SCOCR1HH */
+
+#define SCOCR1HH0 0
+#define SCOCR1HH1 1
+#define SCOCR1HH2 2
+#define SCOCR1HH3 3
+#define SCOCR1HH4 4
+#define SCOCR1HH5 5
+#define SCOCR1HH6 6
+#define SCOCR1HH7 7
+
+/* Timer/Counter5 Control Register A */
+#define TCCR5A _SFR_MEM8(0x120)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR5A {
+ unsigned int wgm5 : 2; /* Waveform Generation Mode */
+ unsigned int com5c : 2; /* Compare Output Mode for Channel C */
+ unsigned int com5b : 2; /* Compare Output Mode for Channel B */
+ unsigned int com5a : 2; /* Compare Output Mode for Channel A */
+};
+
+#define TCCR5A_struct _SFR_MEM8_STRUCT(0x120, struct __reg_TCCR5A)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR5A */
+
+#define WGM50 0
+#define WGM51 1
+#define COM5C0 2
+#define COM5C1 3
+#define COM5B0 4
+#define COM5B1 5
+#define COM5A0 6
+#define COM5A1 7
+
+/* Timer/Counter5 Control Register B */
+#define TCCR5B _SFR_MEM8(0x121)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR5B {
+ unsigned int cs5 : 3; /* Clock Select */
+ unsigned int wgm5 : 2; /* Waveform Generation Mode */
+ unsigned int : 1;
+ unsigned int ices5 : 1; /* Input Capture 5 Edge Select */
+ unsigned int icnc5 : 1; /* Input Capture 5 Noise Canceller */
+};
+
+#define TCCR5B_struct _SFR_MEM8_STRUCT(0x121, struct __reg_TCCR5B)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR5B */
+
+#define CS50 0
+#define CS51 1
+#define CS52 2
+#define WGM52 3
+#define WGM53 4
+#define ICES5 6
+#define ICNC5 7
+
+/* Timer/Counter5 Control Register C */
+#define TCCR5C _SFR_MEM8(0x122)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TCCR5C {
+ unsigned int : 5;
+ unsigned int foc5c : 1; /* Force Output Compare for Channel C */
+ unsigned int foc5b : 1; /* Force Output Compare for Channel B */
+ unsigned int foc5a : 1; /* Force Output Compare for Channel A */
+};
+
+#define TCCR5C_struct _SFR_MEM8_STRUCT(0x122, struct __reg_TCCR5C)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TCCR5C */
+
+#define FOC5C 5
+#define FOC5B 6
+#define FOC5A 7
+
+/* Timer/Counter5 Bytes */
+#define TCNT5 _SFR_MEM16(0x124)
+#define TCNT5L _SFR_MEM8(0x124)
+#define TCNT5H _SFR_MEM8(0x125)
+
+/* Timer/Counter5 Input Capture Register Bytes */
+#define ICR5 _SFR_MEM16(0x126)
+#define ICR5L _SFR_MEM8(0x126)
+#define ICR5H _SFR_MEM8(0x127)
+
+/* Timer/Counter5 Output Compare Register A Bytes */
+#define OCR5A _SFR_MEM16(0x128)
+#define OCR5AL _SFR_MEM8(0x128)
+#define OCR5AH _SFR_MEM8(0x129)
+
+/* Timer/Counter5 Output Compare Register B Bytes */
+#define OCR5B _SFR_MEM16(0x12A)
+#define OCR5BL _SFR_MEM8(0x12A)
+#define OCR5BH _SFR_MEM8(0x12B)
+
+/* Timer/Counter5 Output Compare Register C Bytes */
+#define OCR5C _SFR_MEM16(0x12C)
+#define OCR5CL _SFR_MEM8(0x12C)
+#define OCR5CH _SFR_MEM8(0x12D)
+
+/* Low Leakage Voltage Regulator Control Register */
+#define LLCR _SFR_MEM8(0x12F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_LLCR {
+ unsigned int llencal : 1; /* Enable Automatic Calibration */
+ unsigned int llshort : 1; /* Short Lower Calibration Circuit */
+ unsigned int lltco : 1; /* Temperature Coefficient of Current Source */
+ unsigned int llcal : 1; /* Calibration Active */
+ unsigned int llcomp : 1; /* Comparator Output */
+ unsigned int lldone : 1; /* Calibration Done */
+ unsigned int : 2;
+};
+
+#define LLCR_struct _SFR_MEM8_STRUCT(0x12f, struct __reg_LLCR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* LLCR */
+
+#define LLENCAL 0
+#define LLSHORT 1
+#define LLTCO 2
+#define LLCAL 3
+#define LLCOMP 4
+#define LLDONE 5
+
+/* Low Leakage Voltage Regulator Data Register (Low-Byte) */
+#define LLDRL _SFR_MEM8(0x130)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_LLDRL {
+ unsigned int lldrl : 4; /* Low-Byte Data Register Bits */
+ unsigned int : 4;
+};
+
+#define LLDRL_struct _SFR_MEM8_STRUCT(0x130, struct __reg_LLDRL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* LLDRL */
+
+#define LLDRL0 0
+#define LLDRL1 1
+#define LLDRL2 2
+#define LLDRL3 3
+
+/* Low Leakage Voltage Regulator Data Register (High-Byte) */
+#define LLDRH _SFR_MEM8(0x131)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_LLDRH {
+ unsigned int lldrh : 5; /* High-Byte Data Register Bits */
+ unsigned int : 3;
+};
+
+#define LLDRH_struct _SFR_MEM8_STRUCT(0x131, struct __reg_LLDRH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* LLDRH */
+
+#define LLDRH0 0
+#define LLDRH1 1
+#define LLDRH2 2
+#define LLDRH3 3
+#define LLDRH4 4
+
+/* Data Retention Configuration Register of SRAM 3 */
+#define DRTRAM3 _SFR_MEM8(0x132)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DRTRAM3 {
+ unsigned int : 4;
+ unsigned int endrt : 1; /* Enable SRAM Data Retention */
+ unsigned int drtswok : 1; /* DRT Switch OK */
+ unsigned int : 2;
+};
+
+#define DRTRAM3_struct _SFR_MEM8_STRUCT(0x132, struct __reg_DRTRAM3)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DRTRAM3 */
+
+#define ENDRT 4
+#define DRTSWOK 5
+
+/* Data Retention Configuration Register of SRAM 2 */
+#define DRTRAM2 _SFR_MEM8(0x133)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DRTRAM2 {
+ unsigned int : 4;
+ unsigned int endrt : 1; /* Enable SRAM Data Retention */
+ unsigned int drtswok : 1; /* DRT Switch OK */
+ unsigned int : 2;
+};
+
+#define DRTRAM2_struct _SFR_MEM8_STRUCT(0x133, struct __reg_DRTRAM2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DRTRAM2 */
+
+#define ENDRT 4
+#define DRTSWOK 5
+
+/* Data Retention Configuration Register of SRAM 1 */
+#define DRTRAM1 _SFR_MEM8(0x134)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DRTRAM1 {
+ unsigned int : 4;
+ unsigned int endrt : 1; /* Enable SRAM Data Retention */
+ unsigned int drtswok : 1; /* DRT Switch OK */
+ unsigned int : 2;
+};
+
+#define DRTRAM1_struct _SFR_MEM8_STRUCT(0x134, struct __reg_DRTRAM1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DRTRAM1 */
+
+#define ENDRT 4
+#define DRTSWOK 5
+
+/* Data Retention Configuration Register of SRAM 0 */
+#define DRTRAM0 _SFR_MEM8(0x135)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DRTRAM0 {
+ unsigned int : 4;
+ unsigned int endrt : 1; /* Enable SRAM Data Retention */
+ unsigned int drtswok : 1; /* DRT Switch OK */
+ unsigned int : 2;
+};
+
+#define DRTRAM0_struct _SFR_MEM8_STRUCT(0x135, struct __reg_DRTRAM0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DRTRAM0 */
+
+#define ENDRT 4
+#define DRTSWOK 5
+
+/* Port Driver Strength Register 0 */
+#define DPDS0 _SFR_MEM8(0x136)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DPDS0 {
+ unsigned int pbdrv : 2; /* Driver Strength Port B */
+ unsigned int pddrv : 2; /* Driver Strength Port D */
+ unsigned int pedrv : 2; /* Driver Strength Port E */
+ unsigned int pfdrv : 2; /* Driver Strength Port F */
+};
+
+#define DPDS0_struct _SFR_MEM8_STRUCT(0x136, struct __reg_DPDS0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DPDS0 */
+
+#define PBDRV0 0
+#define PBDRV1 1
+#define PDDRV0 2
+#define PDDRV1 3
+#define PEDRV0 4
+#define PEDRV1 5
+#define PFDRV0 6
+#define PFDRV1 7
+
+/* Port Driver Strength Register 1 */
+#define DPDS1 _SFR_MEM8(0x137)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_DPDS1 {
+ unsigned int pgdrv : 2; /* Driver Strength Port G */
+ unsigned int : 6;
+};
+
+#define DPDS1_struct _SFR_MEM8_STRUCT(0x137, struct __reg_DPDS1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* DPDS1 */
+
+#define PGDRV0 0
+#define PGDRV1 1
+
+/* Transceiver Pin Register */
+#define TRXPR _SFR_MEM8(0x139)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TRXPR {
+ unsigned int trxrst : 1; /* Force Transceiver Reset */
+ unsigned int slptr : 1; /* Multi-purpose Transceiver Control Bit */
+ unsigned int : 6;
+};
+
+#define TRXPR_struct _SFR_MEM8_STRUCT(0x139, struct __reg_TRXPR)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TRXPR */
+
+#define TRXRST 0
+#define SLPTR 1
+
+/* AES Control Register */
+#define AES_CTRL _SFR_MEM8(0x13C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_AES_CTRL {
+ unsigned int : 2;
+ unsigned int aes_im : 1; /* AES Interrupt Enable */
+ unsigned int aes_dir : 1; /* Set AES Operation Direction */
+ unsigned int : 1;
+ unsigned int aes_mode : 1; /* Set AES Operation Mode */
+ unsigned int : 1;
+ unsigned int aes_request : 1; /* Request AES Operation. */
+};
+
+#define AES_CTRL_struct _SFR_MEM8_STRUCT(0x13c, struct __reg_AES_CTRL)
+
+/* symbolic names */
+
+#define AES_DIR_ENC 0
+#define AES_DIR_DEC 1
+#define AES_MODE_ECB 0
+#define AES_MODE_CBC 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* AES_CTRL */
+
+#define AES_IM 2
+#define AES_DIR 3
+#define AES_MODE 5
+#define AES_REQUEST 7
+
+/* AES Status Register */
+#define AES_STATUS _SFR_MEM8(0x13D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_AES_STATUS {
+ unsigned int aes_done : 1; /* AES Operation Finished with Success */
+ unsigned int : 6;
+ unsigned int aes_er : 1; /* AES Operation Finished with Error */
+};
+
+#define AES_STATUS_struct _SFR_MEM8_STRUCT(0x13d, struct __reg_AES_STATUS)
+
+#endif /* __ASSEMBLER__ */
+
+ /* AES_STATUS */
+
+#define AES_DONE 0
+#define AES_ER 7
+
+/* AES Plain and Cipher Text Buffer Register */
+#define AES_STATE _SFR_MEM8(0x13E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_AES_STATE {
+ unsigned int aes_state : 8; /* AES Plain and Cipher Text Buffer */
+};
+
+#define AES_STATE_struct _SFR_MEM8_STRUCT(0x13e, struct __reg_AES_STATE)
+
+#endif /* __ASSEMBLER__ */
+
+ /* AES_STATE */
+
+#define AES_STATE0 0
+#define AES_STATE1 1
+#define AES_STATE2 2
+#define AES_STATE3 3
+#define AES_STATE4 4
+#define AES_STATE5 5
+#define AES_STATE6 6
+#define AES_STATE7 7
+
+/* AES Encryption and Decryption Key Buffer Register */
+#define AES_KEY _SFR_MEM8(0x13F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_AES_KEY {
+ unsigned int aes_key : 8; /* AES Encryption/Decryption Key Buffer */
+};
+
+#define AES_KEY_struct _SFR_MEM8_STRUCT(0x13f, struct __reg_AES_KEY)
+
+#endif /* __ASSEMBLER__ */
+
+ /* AES_KEY */
+
+#define AES_KEY0 0
+#define AES_KEY1 1
+#define AES_KEY2 2
+#define AES_KEY3 3
+#define AES_KEY4 4
+#define AES_KEY5 5
+#define AES_KEY6 6
+#define AES_KEY7 7
+
+/* Transceiver Status Register */
+#define TRX_STATUS _SFR_MEM8(0x141)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TRX_STATUS {
+ unsigned int trx_status : 5; /* Transceiver Main Status */
+ unsigned int tst_status : 1; /* Test mode status */
+ unsigned int cca_status : 1; /* CCA Status Result */
+ unsigned int cca_done : 1; /* CCA Algorithm Status */
+};
+
+#define TRX_STATUS_struct _SFR_MEM8_STRUCT(0x141, struct __reg_TRX_STATUS)
+
+/* symbolic names */
+
+#define P_ON 0
+#define BUSY_RX 1
+#define BUSY_TX 2
+#define RX_ON 6
+#define TRX_OFF 8
+#define PLL_ON 9
+#define SLEEP 15
+#define BUSY_RX_AACK 17
+#define BUSY_TX_ARET 18
+#define RX_AACK_ON 22
+#define TX_ARET_ON 25
+#define STATE_TRANSITION_IN_PROGRESS 31
+#define TST_DISABLED 0
+#define TST_ENABLED 1
+#define CCA_BUSY 0
+#define CCA_IDLE 1
+#define CCA_NOT_FIN 0
+#define CCA_FIN 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* TRX_STATUS */
+
+#define TRX_STATUS0 0
+#define TRX_STATUS1 1
+#define TRX_STATUS2 2
+#define TRX_STATUS3 3
+#define TRX_STATUS4 4
+#define TST_STATUS 5
+#define CCA_STATUS 6
+#define CCA_DONE 7
+
+/* Transceiver State Control Register */
+#define TRX_STATE _SFR_MEM8(0x142)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TRX_STATE {
+ unsigned int trx_cmd : 5; /* State Control Command */
+ unsigned int trac_status : 3; /* Transaction Status */
+};
+
+#define TRX_STATE_struct _SFR_MEM8_STRUCT(0x142, struct __reg_TRX_STATE)
+
+/* symbolic names */
+
+#define CMD_NOP 0
+#define CMD_TX_START 2
+#define CMD_FORCE_TRX_OFF 3
+#define CMD_FORCE_PLL_ON 4
+#define CMD_RX_ON 6
+#define CMD_TRX_OFF 8
+#define CMD_PLL_ON 9
+#define CMD_RX_AACK_ON 22
+#define CMD_TX_ARET_ON 25
+#define TRAC_SUCCESS 0
+#define TRAC_SUCCESS_DATA_PENDING 1
+#define TRAC_SUCCESS_WAIT_FOR_ACK 2
+#define TRAC_CHANNEL_ACCESS_FAILURE 3
+#define TRAC_NO_ACK 5
+#define TRAC_INVALID 7
+
+#endif /* __ASSEMBLER__ */
+
+ /* TRX_STATE */
+
+#define TRX_CMD0 0
+#define TRX_CMD1 1
+#define TRX_CMD2 2
+#define TRX_CMD3 3
+#define TRX_CMD4 4
+#define TRAC_STATUS0 5
+#define TRAC_STATUS1 6
+#define TRAC_STATUS2 7
+
+/* Reserved */
+#define TRX_CTRL_0 _SFR_MEM8(0x143)
+
+/* Transceiver Control Register 1 */
+#define TRX_CTRL_1 _SFR_MEM8(0x144)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TRX_CTRL_1 {
+ unsigned int : 5;
+ unsigned int tx_auto_crc_on : 1; /* Enable Automatic CRC Calculation */
+ unsigned int irq_2_ext_en : 1; /* Connect Frame Start IRQ to TC1 */
+ unsigned int pa_ext_en : 1; /* External PA support enable */
+};
+
+#define TRX_CTRL_1_struct _SFR_MEM8_STRUCT(0x144, struct __reg_TRX_CTRL_1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TRX_CTRL_1 */
+
+#define TX_AUTO_CRC_ON 5
+#define IRQ_2_EXT_EN 6
+#define PA_EXT_EN 7
+
+/* Transceiver Transmit Power Control Register */
+#define PHY_TX_PWR _SFR_MEM8(0x145)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PHY_TX_PWR {
+ unsigned int tx_pwr : 4; /* Transmit Power Setting */
+ unsigned int pa_lt : 2; /* Power Amplifier Lead Time */
+ unsigned int pa_buf_lt : 2; /* Power Amplifier Buffer Lead Time */
+};
+
+#define PHY_TX_PWR_struct _SFR_MEM8_STRUCT(0x145, struct __reg_PHY_TX_PWR)
+
+/* symbolic names */
+
+#define PA_LT_2US 0
+#define PA_LT_4US 1
+#define PA_LT_6US 2
+#define PA_LT_8US 3
+#define PA_BUF_LT_0US 0
+#define PA_BUF_LT_2US 1
+#define PA_BUF_LT_4US 2
+#define PA_BUF_LT_6US 3
+
+#endif /* __ASSEMBLER__ */
+
+ /* PHY_TX_PWR */
+
+#define TX_PWR0 0
+#define TX_PWR1 1
+#define TX_PWR2 2
+#define TX_PWR3 3
+#define PA_LT0 4
+#define PA_LT1 5
+#define PA_BUF_LT0 6
+#define PA_BUF_LT1 7
+
+/* Receiver Signal Strength Indicator Register */
+#define PHY_RSSI _SFR_MEM8(0x146)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PHY_RSSI {
+ unsigned int rssi : 5; /* Receiver Signal Strength Indicator */
+ unsigned int rnd_value : 2; /* Random Value */
+ unsigned int rx_crc_valid : 1; /* Received Frame CRC Status */
+};
+
+#define PHY_RSSI_struct _SFR_MEM8_STRUCT(0x146, struct __reg_PHY_RSSI)
+
+/* symbolic names */
+
+#define RSSI_MIN 0
+#define RSSI_MIN_PLUS_3dB 1
+#define RSSI_MAX 28
+#define CRC_INVALID 0
+#define CRC_VALID 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* PHY_RSSI */
+
+#define RSSI0 0
+#define RSSI1 1
+#define RSSI2 2
+#define RSSI3 3
+#define RSSI4 4
+#define RND_VALUE0 5
+#define RND_VALUE1 6
+#define RX_CRC_VALID 7
+
+/* Transceiver Energy Detection Level Register */
+#define PHY_ED_LEVEL _SFR_MEM8(0x147)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PHY_ED_LEVEL {
+ unsigned int ed_level : 8; /* Energy Detection Level */
+};
+
+#define PHY_ED_LEVEL_struct _SFR_MEM8_STRUCT(0x147, struct __reg_PHY_ED_LEVEL)
+
+/* symbolic names */
+
+#define ED_MIN 0
+#define ED_MIN_PLUS_1dB 1
+#define ED_MAX 84
+#define ED_RESET 255
+
+#endif /* __ASSEMBLER__ */
+
+ /* PHY_ED_LEVEL */
+
+#define ED_LEVEL0 0
+#define ED_LEVEL1 1
+#define ED_LEVEL2 2
+#define ED_LEVEL3 3
+#define ED_LEVEL4 4
+#define ED_LEVEL5 5
+#define ED_LEVEL6 6
+#define ED_LEVEL7 7
+
+/* Transceiver Clear Channel Assessment (CCA) Control Register */
+#define PHY_CC_CCA _SFR_MEM8(0x148)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PHY_CC_CCA {
+ unsigned int channel : 5; /* RX/TX Channel Selection */
+ unsigned int cca_mode : 2; /* Select CCA Measurement Mode */
+ unsigned int cca_request : 1; /* Manual CCA Measurement Request */
+};
+
+#define PHY_CC_CCA_struct _SFR_MEM8_STRUCT(0x148, struct __reg_PHY_CC_CCA)
+
+/* symbolic names */
+
+#define F_2405MHZ 11
+#define F_2410MHZ 12
+#define F_2415MHZ 13
+#define F_2420MHZ 14
+#define F_2425MHZ 15
+#define F_2430MHZ 16
+#define F_2435MHZ 17
+#define F_2440MHZ 18
+#define F_2445MHZ 19
+#define F_2450MHZ 20
+#define F_2455MHZ 21
+#define F_2460MHZ 22
+#define F_2465MHZ 23
+#define F_2470MHZ 24
+#define F_2475MHZ 25
+#define F_2480MHZ 26
+#define CCA_CS_OR_ED 0
+#define CCA_ED 1
+#define CCA_CS 2
+#define CCA_CS_AND_ED 3
+
+#endif /* __ASSEMBLER__ */
+
+ /* PHY_CC_CCA */
+
+#define CHANNEL0 0
+#define CHANNEL1 1
+#define CHANNEL2 2
+#define CHANNEL3 3
+#define CHANNEL4 4
+#define CCA_MODE0 5
+#define CCA_MODE1 6
+#define CCA_REQUEST 7
+
+/* Transceiver CCA Threshold Setting Register */
+#define CCA_THRES _SFR_MEM8(0x149)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_CCA_THRES {
+ unsigned int cca_ed_thres : 4; /* ED Threshold Level for CCA Measurement */
+ unsigned int cca_cs_thres : 4; /* CS Threshold Level for CCA Measurement */
+};
+
+#define CCA_THRES_struct _SFR_MEM8_STRUCT(0x149, struct __reg_CCA_THRES)
+
+#endif /* __ASSEMBLER__ */
+
+ /* CCA_THRES */
+
+#define CCA_ED_THRES0 0
+#define CCA_ED_THRES1 1
+#define CCA_ED_THRES2 2
+#define CCA_ED_THRES3 3
+#define CCA_CS_THRES0 4
+#define CCA_CS_THRES1 5
+#define CCA_CS_THRES2 6
+#define CCA_CS_THRES3 7
+
+/* Transceiver Receive Control Register */
+#define RX_CTRL _SFR_MEM8(0x14A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_RX_CTRL {
+ unsigned int pdt_thres : 4; /* Receiver Sensitivity Control */
+ unsigned int : 4;
+};
+
+#define RX_CTRL_struct _SFR_MEM8_STRUCT(0x14a, struct __reg_RX_CTRL)
+
+/* symbolic names */
+
+#define PDT_THRES_ANT_DIV_OFF 7
+#define PDT_THRES_ANT_DIV_ON 3
+
+#endif /* __ASSEMBLER__ */
+
+ /* RX_CTRL */
+
+#define PDT_THRES0 0
+#define PDT_THRES1 1
+#define PDT_THRES2 2
+#define PDT_THRES3 3
+
+/* Start of Frame Delimiter Value Register */
+#define SFD_VALUE _SFR_MEM8(0x14B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SFD_VALUE {
+ unsigned int sfd_value : 8; /* Start of Frame Delimiter Value */
+};
+
+#define SFD_VALUE_struct _SFR_MEM8_STRUCT(0x14b, struct __reg_SFD_VALUE)
+
+/* symbolic names */
+
+#define IEEE_SFD 167
+
+#endif /* __ASSEMBLER__ */
+
+ /* SFD_VALUE */
+
+#define SFD_VALUE0 0
+#define SFD_VALUE1 1
+#define SFD_VALUE2 2
+#define SFD_VALUE3 3
+#define SFD_VALUE4 4
+#define SFD_VALUE5 5
+#define SFD_VALUE6 6
+#define SFD_VALUE7 7
+
+/* Transceiver Control Register 2 */
+#define TRX_CTRL_2 _SFR_MEM8(0x14C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TRX_CTRL_2 {
+ unsigned int oqpsk_data_rate : 2; /* Data Rate Selection */
+ unsigned int : 5;
+ unsigned int rx_safe_mode : 1; /* RX Safe Mode */
+};
+
+#define TRX_CTRL_2_struct _SFR_MEM8_STRUCT(0x14c, struct __reg_TRX_CTRL_2)
+
+/* symbolic names */
+
+#define RATE_250KB 0
+#define RATE_500KB 1
+#define RATE_1000KB 2
+#define RATE_2000KB 3
+
+#endif /* __ASSEMBLER__ */
+
+ /* TRX_CTRL_2 */
+
+#define OQPSK_DATA_RATE0 0
+#define OQPSK_DATA_RATE1 1
+#define RX_SAFE_MODE 7
+
+/* Antenna Diversity Control Register */
+#define ANT_DIV _SFR_MEM8(0x14D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_ANT_DIV {
+ unsigned int ant_ctrl : 2; /* Static Antenna Diversity Switch Control */
+ unsigned int ant_ext_sw_en : 1; /* Enable External Antenna Switch Control */
+ unsigned int ant_div_en : 1; /* Enable Antenna Diversity */
+ unsigned int : 3;
+ unsigned int ant_sel : 1; /* Antenna Diversity Antenna Status */
+};
+
+#define ANT_DIV_struct _SFR_MEM8_STRUCT(0x14d, struct __reg_ANT_DIV)
+
+/* symbolic names */
+
+#define ANT_1 1
+#define ANT_0 2
+#define ANT_RESET 3
+#define ANT_DIV_EXT_SW_DIS 0
+#define ANT_DIV_EXT_SW_EN 1
+#define ANTENNA_0 0
+#define ANTENNA_1 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* ANT_DIV */
+
+#define ANT_CTRL0 0
+#define ANT_CTRL1 1
+#define ANT_EXT_SW_EN 2
+#define ANT_DIV_EN 3
+#define ANT_SEL 7
+
+/* Transceiver Interrupt Enable Register */
+#define IRQ_MASK _SFR_MEM8(0x14E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IRQ_MASK {
+ unsigned int pll_lock_en : 1; /* PLL Lock Interrupt Enable */
+ unsigned int pll_unlock_en : 1; /* PLL Unlock Interrupt Enable */
+ unsigned int rx_start_en : 1; /* RX_START Interrupt Enable */
+ unsigned int rx_end_en : 1; /* RX_END Interrupt Enable */
+ unsigned int cca_ed_done_en : 1; /* End of ED Measurement Interrupt Enable */
+ unsigned int ami_en : 1; /* Address Match Interrupt Enable */
+ unsigned int tx_end_en : 1; /* TX_END Interrupt Enable */
+ unsigned int awake_en : 1; /* Awake Interrupt Enable */
+};
+
+#define IRQ_MASK_struct _SFR_MEM8_STRUCT(0x14e, struct __reg_IRQ_MASK)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IRQ_MASK */
+
+#define PLL_LOCK_EN 0
+#define PLL_UNLOCK_EN 1
+#define RX_START_EN 2
+#define RX_END_EN 3
+#define CCA_ED_DONE_EN 4
+#define AMI_EN 5
+#define TX_END_EN 6
+#define AWAKE_EN 7
+
+/* Transceiver Interrupt Status Register */
+#define IRQ_STATUS _SFR_MEM8(0x14F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IRQ_STATUS {
+ unsigned int pll_lock : 1; /* PLL Lock Interrupt Status */
+ unsigned int pll_unlock : 1; /* PLL Unlock Interrupt Status */
+ unsigned int rx_start : 1; /* RX_START Interrupt Status */
+ unsigned int rx_end : 1; /* RX_END Interrupt Status */
+ unsigned int cca_ed_done : 1; /* End of ED Measurement Interrupt Status */
+ unsigned int ami : 1; /* Address Match Interrupt Status */
+ unsigned int tx_end : 1; /* TX_END Interrupt Status */
+ unsigned int awake : 1; /* Awake Interrupt Status */
+};
+
+#define IRQ_STATUS_struct _SFR_MEM8_STRUCT(0x14f, struct __reg_IRQ_STATUS)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IRQ_STATUS */
+
+#define PLL_LOCK 0
+#define PLL_UNLOCK 1
+#define RX_START 2
+#define RX_END 3
+#define CCA_ED_DONE 4
+#define AMI 5
+#define TX_END 6
+#define AWAKE 7
+
+/* Voltage Regulator Control and Status Register */
+#define VREG_CTRL _SFR_MEM8(0x150)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_VREG_CTRL {
+ unsigned int : 2;
+ unsigned int dvdd_ok : 1; /* DVDD Supply Voltage Valid */
+ unsigned int dvreg_ext : 1; /* Use External DVDD Regulator */
+ unsigned int : 2;
+ unsigned int avdd_ok : 1; /* AVDD Supply Voltage Valid */
+ unsigned int avreg_ext : 1; /* Use External AVDD Regulator */
+};
+
+#define VREG_CTRL_struct _SFR_MEM8_STRUCT(0x150, struct __reg_VREG_CTRL)
+
+/* symbolic names */
+
+#define DVDD_INT 0
+#define DVDD_EXT 1
+#define AVDD_INT 0
+#define AVDD_EXT 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* VREG_CTRL */
+
+#define DVDD_OK 2
+#define DVREG_EXT 3
+#define AVDD_OK 6
+#define AVREG_EXT 7
+
+/* Battery Monitor Control and Status Register */
+#define BATMON _SFR_MEM8(0x151)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_BATMON {
+ unsigned int batmon_vth : 4; /* Battery Monitor Threshold Voltage */
+ unsigned int batmon_hr : 1; /* Battery Monitor Voltage Range */
+ unsigned int batmon_ok : 1; /* Battery Monitor Status */
+ unsigned int bat_low_en : 1; /* Battery Monitor Interrupt Enable */
+ unsigned int bat_low : 1; /* Battery Monitor Interrupt Status */
+};
+
+#define BATMON_struct _SFR_MEM8_STRUCT(0x151, struct __reg_BATMON)
+
+/* symbolic names */
+
+#define BATMON_HR_DIS 0
+#define BATMON_HR_EN 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* BATMON */
+
+#define BATMON_VTH0 0
+#define BATMON_VTH1 1
+#define BATMON_VTH2 2
+#define BATMON_VTH3 3
+#define BATMON_HR 4
+#define BATMON_OK 5
+#define BAT_LOW_EN 6
+#define BAT_LOW 7
+
+/* Crystal Oscillator Control Register */
+#define XOSC_CTRL _SFR_MEM8(0x152)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_XOSC_CTRL {
+ unsigned int xtal_trim : 4; /* Crystal Oscillator Load Capacitance Trimming */
+ unsigned int xtal_mode : 4; /* Crystal Oscillator Operating Mode */
+};
+
+#define XOSC_CTRL_struct _SFR_MEM8_STRUCT(0x152, struct __reg_XOSC_CTRL)
+
+/* symbolic names */
+
+#define XTAL_TRIM_MIN 0
+#define XTAL_TRIM_MAX 15
+
+#endif /* __ASSEMBLER__ */
+
+ /* XOSC_CTRL */
+
+#define XTAL_TRIM0 0
+#define XTAL_TRIM1 1
+#define XTAL_TRIM2 2
+#define XTAL_TRIM3 3
+#define XTAL_MODE0 4
+#define XTAL_MODE1 5
+#define XTAL_MODE2 6
+#define XTAL_MODE3 7
+
+/* Transceiver Receiver Sensitivity Control Register */
+#define RX_SYN _SFR_MEM8(0x155)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_RX_SYN {
+ unsigned int rx_pdt_level : 4; /* Reduce Receiver Sensitivity */
+ unsigned int : 3;
+ unsigned int rx_pdt_dis : 1; /* Prevent Frame Reception */
+};
+
+#define RX_SYN_struct _SFR_MEM8_STRUCT(0x155, struct __reg_RX_SYN)
+
+/* symbolic names */
+
+#define RX_PDT_LEVEL_MIN 0
+#define RX_PDT_LEVEL_MAX 15
+
+#endif /* __ASSEMBLER__ */
+
+ /* RX_SYN */
+
+#define RX_PDT_LEVEL0 0
+#define RX_PDT_LEVEL1 1
+#define RX_PDT_LEVEL2 2
+#define RX_PDT_LEVEL3 3
+#define RX_PDT_DIS 7
+
+/* Transceiver Acknowledgment Frame Control Register 1 */
+#define XAH_CTRL_1 _SFR_MEM8(0x157)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_XAH_CTRL_1 {
+ unsigned int : 1;
+ unsigned int aack_prom_mode : 1; /* Enable Promiscuous Mode */
+ unsigned int aack_ack_time : 1; /* Reduce Acknowledgment Time */
+ unsigned int : 1;
+ unsigned int aack_upld_res_ft : 1; /* Process Reserved Frames */
+ unsigned int aack_fltr_res_ft : 1; /* Filter Reserved Frames */
+ unsigned int : 2;
+};
+
+#define XAH_CTRL_1_struct _SFR_MEM8_STRUCT(0x157, struct __reg_XAH_CTRL_1)
+
+/* symbolic names */
+
+#define AACK_ACK_TIME_12_SYM 0
+#define AACK_ACK_TIME_2_SYM 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* XAH_CTRL_1 */
+
+#define AACK_PROM_MODE 1
+#define AACK_ACK_TIME 2
+#define AACK_UPLD_RES_FT 4
+#define AACK_FLTR_RES_FT 5
+
+/* Transceiver Filter Tuning Control Register */
+#define FTN_CTRL _SFR_MEM8(0x158)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_FTN_CTRL {
+ unsigned int : 7;
+ unsigned int ftn_start : 1; /* Start Calibration Loop of Filter Tuning Network */
+};
+
+#define FTN_CTRL_struct _SFR_MEM8_STRUCT(0x158, struct __reg_FTN_CTRL)
+
+#endif /* __ASSEMBLER__ */
+
+ /* FTN_CTRL */
+
+#define FTN_START 7
+
+/* Transceiver Center Frequency Calibration Control Register */
+#define PLL_CF _SFR_MEM8(0x15A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PLL_CF {
+ unsigned int : 7;
+ unsigned int pll_cf_start : 1; /* Start Center Frequency Calibration */
+};
+
+#define PLL_CF_struct _SFR_MEM8_STRUCT(0x15a, struct __reg_PLL_CF)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PLL_CF */
+
+#define PLL_CF_START 7
+
+/* Transceiver Delay Cell Calibration Control Register */
+#define PLL_DCU _SFR_MEM8(0x15B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PLL_DCU {
+ unsigned int : 7;
+ unsigned int pll_dcu_start : 1; /* Start Delay Cell Calibration */
+};
+
+#define PLL_DCU_struct _SFR_MEM8_STRUCT(0x15b, struct __reg_PLL_DCU)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PLL_DCU */
+
+#define PLL_DCU_START 7
+
+/* Device Identification Register (Part Number) */
+#define PART_NUM _SFR_MEM8(0x15C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PART_NUM {
+ unsigned int part_num : 8; /* Part Number */
+};
+
+#define PART_NUM_struct _SFR_MEM8_STRUCT(0x15c, struct __reg_PART_NUM)
+
+/* symbolic names */
+
+#define P_ATmega128RFA1 131
+
+#endif /* __ASSEMBLER__ */
+
+ /* PART_NUM */
+
+#define PART_NUM0 0
+#define PART_NUM1 1
+#define PART_NUM2 2
+#define PART_NUM3 3
+#define PART_NUM4 4
+#define PART_NUM5 5
+#define PART_NUM6 6
+#define PART_NUM7 7
+
+/* Device Identification Register (Version Number) */
+#define VERSION_NUM _SFR_MEM8(0x15D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_VERSION_NUM {
+ unsigned int version_num : 8; /* Version Number */
+};
+
+#define VERSION_NUM_struct _SFR_MEM8_STRUCT(0x15d, struct __reg_VERSION_NUM)
+
+/* symbolic names */
+
+#define REV_A 2
+#define REV_B 3
+
+#endif /* __ASSEMBLER__ */
+
+ /* VERSION_NUM */
+
+#define VERSION_NUM0 0
+#define VERSION_NUM1 1
+#define VERSION_NUM2 2
+#define VERSION_NUM3 3
+#define VERSION_NUM4 4
+#define VERSION_NUM5 5
+#define VERSION_NUM6 6
+#define VERSION_NUM7 7
+
+/* Device Identification Register (Manufacture ID Low Byte) */
+#define MAN_ID_0 _SFR_MEM8(0x15E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_MAN_ID_0 {
+ unsigned int man_id_0 : 8; /* Manufacturer ID (Low Byte) */
+};
+
+#define MAN_ID_0_struct _SFR_MEM8_STRUCT(0x15e, struct __reg_MAN_ID_0)
+
+/* symbolic names */
+
+#define ATMEL_BYTE_0 31
+
+#endif /* __ASSEMBLER__ */
+
+ /* MAN_ID_0 */
+
+#define MAN_ID_00 0
+#define MAN_ID_01 1
+#define MAN_ID_02 2
+#define MAN_ID_03 3
+#define MAN_ID_04 4
+#define MAN_ID_05 5
+#define MAN_ID_06 6
+#define MAN_ID_07 7
+
+/* Device Identification Register (Manufacture ID High Byte) */
+#define MAN_ID_1 _SFR_MEM8(0x15F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_MAN_ID_1 {
+ unsigned int man_id_1 : 8; /* Manufacturer ID (High Byte) */
+};
+
+#define MAN_ID_1_struct _SFR_MEM8_STRUCT(0x15f, struct __reg_MAN_ID_1)
+
+/* symbolic names */
+
+#define ATMEL_BYTE_1 0
+
+#endif /* __ASSEMBLER__ */
+
+ /* MAN_ID_1 */
+
+#define MAN_ID_10 0
+#define MAN_ID_11 1
+#define MAN_ID_12 2
+#define MAN_ID_13 3
+#define MAN_ID_14 4
+#define MAN_ID_15 5
+#define MAN_ID_16 6
+#define MAN_ID_17 7
+
+/* Transceiver MAC Short Address Register (Low Byte) */
+#define SHORT_ADDR_0 _SFR_MEM8(0x160)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SHORT_ADDR_0 {
+ unsigned int short_addr_0 : 8; /* MAC Short Address */
+};
+
+#define SHORT_ADDR_0_struct _SFR_MEM8_STRUCT(0x160, struct __reg_SHORT_ADDR_0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SHORT_ADDR_0 */
+
+#define SHORT_ADDR_00 0
+#define SHORT_ADDR_01 1
+#define SHORT_ADDR_02 2
+#define SHORT_ADDR_03 3
+#define SHORT_ADDR_04 4
+#define SHORT_ADDR_05 5
+#define SHORT_ADDR_06 6
+#define SHORT_ADDR_07 7
+
+/* Transceiver MAC Short Address Register (High Byte) */
+#define SHORT_ADDR_1 _SFR_MEM8(0x161)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_SHORT_ADDR_1 {
+ unsigned int short_addr_1 : 8; /* MAC Short Address */
+};
+
+#define SHORT_ADDR_1_struct _SFR_MEM8_STRUCT(0x161, struct __reg_SHORT_ADDR_1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* SHORT_ADDR_1 */
+
+#define SHORT_ADDR_10 0
+#define SHORT_ADDR_11 1
+#define SHORT_ADDR_12 2
+#define SHORT_ADDR_13 3
+#define SHORT_ADDR_14 4
+#define SHORT_ADDR_15 5
+#define SHORT_ADDR_16 6
+#define SHORT_ADDR_17 7
+
+/* Transceiver Personal Area Network ID Register (Low Byte) */
+#define PAN_ID_0 _SFR_MEM8(0x162)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PAN_ID_0 {
+ unsigned int pan_id_0 : 8; /* MAC Personal Area Network ID */
+};
+
+#define PAN_ID_0_struct _SFR_MEM8_STRUCT(0x162, struct __reg_PAN_ID_0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PAN_ID_0 */
+
+#define PAN_ID_00 0
+#define PAN_ID_01 1
+#define PAN_ID_02 2
+#define PAN_ID_03 3
+#define PAN_ID_04 4
+#define PAN_ID_05 5
+#define PAN_ID_06 6
+#define PAN_ID_07 7
+
+/* Transceiver Personal Area Network ID Register (High Byte) */
+#define PAN_ID_1 _SFR_MEM8(0x163)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_PAN_ID_1 {
+ unsigned int pan_id_1 : 8; /* MAC Personal Area Network ID */
+};
+
+#define PAN_ID_1_struct _SFR_MEM8_STRUCT(0x163, struct __reg_PAN_ID_1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* PAN_ID_1 */
+
+#define PAN_ID_10 0
+#define PAN_ID_11 1
+#define PAN_ID_12 2
+#define PAN_ID_13 3
+#define PAN_ID_14 4
+#define PAN_ID_15 5
+#define PAN_ID_16 6
+#define PAN_ID_17 7
+
+/* Transceiver MAC IEEE Address Register 0 */
+#define IEEE_ADDR_0 _SFR_MEM8(0x164)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_0 {
+ unsigned int ieee_addr_0 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_0_struct _SFR_MEM8_STRUCT(0x164, struct __reg_IEEE_ADDR_0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_0 */
+
+#define IEEE_ADDR_00 0
+#define IEEE_ADDR_01 1
+#define IEEE_ADDR_02 2
+#define IEEE_ADDR_03 3
+#define IEEE_ADDR_04 4
+#define IEEE_ADDR_05 5
+#define IEEE_ADDR_06 6
+#define IEEE_ADDR_07 7
+
+/* Transceiver MAC IEEE Address Register 1 */
+#define IEEE_ADDR_1 _SFR_MEM8(0x165)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_1 {
+ unsigned int ieee_addr_1 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_1_struct _SFR_MEM8_STRUCT(0x165, struct __reg_IEEE_ADDR_1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_1 */
+
+#define IEEE_ADDR_10 0
+#define IEEE_ADDR_11 1
+#define IEEE_ADDR_12 2
+#define IEEE_ADDR_13 3
+#define IEEE_ADDR_14 4
+#define IEEE_ADDR_15 5
+#define IEEE_ADDR_16 6
+#define IEEE_ADDR_17 7
+
+/* Transceiver MAC IEEE Address Register 2 */
+#define IEEE_ADDR_2 _SFR_MEM8(0x166)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_2 {
+ unsigned int ieee_addr_2 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_2_struct _SFR_MEM8_STRUCT(0x166, struct __reg_IEEE_ADDR_2)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_2 */
+
+#define IEEE_ADDR_20 0
+#define IEEE_ADDR_21 1
+#define IEEE_ADDR_22 2
+#define IEEE_ADDR_23 3
+#define IEEE_ADDR_24 4
+#define IEEE_ADDR_25 5
+#define IEEE_ADDR_26 6
+#define IEEE_ADDR_27 7
+
+/* Transceiver MAC IEEE Address Register 3 */
+#define IEEE_ADDR_3 _SFR_MEM8(0x167)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_3 {
+ unsigned int ieee_addr_3 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_3_struct _SFR_MEM8_STRUCT(0x167, struct __reg_IEEE_ADDR_3)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_3 */
+
+#define IEEE_ADDR_30 0
+#define IEEE_ADDR_31 1
+#define IEEE_ADDR_32 2
+#define IEEE_ADDR_33 3
+#define IEEE_ADDR_34 4
+#define IEEE_ADDR_35 5
+#define IEEE_ADDR_36 6
+#define IEEE_ADDR_37 7
+
+/* Transceiver MAC IEEE Address Register 4 */
+#define IEEE_ADDR_4 _SFR_MEM8(0x168)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_4 {
+ unsigned int ieee_addr_4 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_4_struct _SFR_MEM8_STRUCT(0x168, struct __reg_IEEE_ADDR_4)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_4 */
+
+#define IEEE_ADDR_40 0
+#define IEEE_ADDR_41 1
+#define IEEE_ADDR_42 2
+#define IEEE_ADDR_43 3
+#define IEEE_ADDR_44 4
+#define IEEE_ADDR_45 5
+#define IEEE_ADDR_46 6
+#define IEEE_ADDR_47 7
+
+/* Transceiver MAC IEEE Address Register 5 */
+#define IEEE_ADDR_5 _SFR_MEM8(0x169)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_5 {
+ unsigned int ieee_addr_5 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_5_struct _SFR_MEM8_STRUCT(0x169, struct __reg_IEEE_ADDR_5)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_5 */
+
+#define IEEE_ADDR_50 0
+#define IEEE_ADDR_51 1
+#define IEEE_ADDR_52 2
+#define IEEE_ADDR_53 3
+#define IEEE_ADDR_54 4
+#define IEEE_ADDR_55 5
+#define IEEE_ADDR_56 6
+#define IEEE_ADDR_57 7
+
+/* Transceiver MAC IEEE Address Register 6 */
+#define IEEE_ADDR_6 _SFR_MEM8(0x16A)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_6 {
+ unsigned int ieee_addr_6 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_6_struct _SFR_MEM8_STRUCT(0x16a, struct __reg_IEEE_ADDR_6)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_6 */
+
+#define IEEE_ADDR_60 0
+#define IEEE_ADDR_61 1
+#define IEEE_ADDR_62 2
+#define IEEE_ADDR_63 3
+#define IEEE_ADDR_64 4
+#define IEEE_ADDR_65 5
+#define IEEE_ADDR_66 6
+#define IEEE_ADDR_67 7
+
+/* Transceiver MAC IEEE Address Register 7 */
+#define IEEE_ADDR_7 _SFR_MEM8(0x16B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_IEEE_ADDR_7 {
+ unsigned int ieee_addr_7 : 8; /* MAC IEEE Address */
+};
+
+#define IEEE_ADDR_7_struct _SFR_MEM8_STRUCT(0x16b, struct __reg_IEEE_ADDR_7)
+
+#endif /* __ASSEMBLER__ */
+
+ /* IEEE_ADDR_7 */
+
+#define IEEE_ADDR_70 0
+#define IEEE_ADDR_71 1
+#define IEEE_ADDR_72 2
+#define IEEE_ADDR_73 3
+#define IEEE_ADDR_74 4
+#define IEEE_ADDR_75 5
+#define IEEE_ADDR_76 6
+#define IEEE_ADDR_77 7
+
+/* Transceiver Extended Operating Mode Control Register */
+#define XAH_CTRL_0 _SFR_MEM8(0x16C)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_XAH_CTRL_0 {
+ unsigned int slotted_operation : 1; /* Set Slotted Acknowledgment */
+ unsigned int max_csma_retries : 3; /* Maximum Number of CSMA-CA Procedure Repetition Attempts */
+ unsigned int max_frame_retries : 4; /* Maximum Number of Frame Re-transmission Attempts */
+};
+
+#define XAH_CTRL_0_struct _SFR_MEM8_STRUCT(0x16c, struct __reg_XAH_CTRL_0)
+
+/* symbolic names */
+
+#define SLOTTED_OP_DIS 0
+#define SLOTTED_OP_EN 1
+
+#endif /* __ASSEMBLER__ */
+
+ /* XAH_CTRL_0 */
+
+#define SLOTTED_OPERATION 0
+#define MAX_CSMA_RETRIES0 1
+#define MAX_CSMA_RETRIES1 2
+#define MAX_CSMA_RETRIES2 3
+#define MAX_FRAME_RETRIES0 4
+#define MAX_FRAME_RETRIES1 5
+#define MAX_FRAME_RETRIES2 6
+#define MAX_FRAME_RETRIES3 7
+
+/* Transceiver CSMA-CA Random Number Generator Seed Register */
+#define CSMA_SEED_0 _SFR_MEM8(0x16D)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_CSMA_SEED_0 {
+ unsigned int csma_seed_0 : 8; /* Seed Value for CSMA Random Number Generator */
+};
+
+#define CSMA_SEED_0_struct _SFR_MEM8_STRUCT(0x16d, struct __reg_CSMA_SEED_0)
+
+#endif /* __ASSEMBLER__ */
+
+ /* CSMA_SEED_0 */
+
+#define CSMA_SEED_00 0
+#define CSMA_SEED_01 1
+#define CSMA_SEED_02 2
+#define CSMA_SEED_03 3
+#define CSMA_SEED_04 4
+#define CSMA_SEED_05 5
+#define CSMA_SEED_06 6
+#define CSMA_SEED_07 7
+
+/* Transceiver Acknowledgment Frame Control Register 2 */
+#define CSMA_SEED_1 _SFR_MEM8(0x16E)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_CSMA_SEED_1 {
+ unsigned int csma_seed_1 : 3; /* Seed Value for CSMA Random Number Generator */
+ unsigned int aack_i_am_coord : 1; /* Set Personal Area Network Coordinator */
+ unsigned int aack_dis_ack : 1; /* Disable Acknowledgment Frame Transmission */
+ unsigned int aack_set_pd : 1; /* Set Frame Pending Sub-field */
+ unsigned int aack_fvn_mode : 2; /* Acknowledgment Frame Filter Mode */
+};
+
+#define CSMA_SEED_1_struct _SFR_MEM8_STRUCT(0x16e, struct __reg_CSMA_SEED_1)
+
+#endif /* __ASSEMBLER__ */
+
+ /* CSMA_SEED_1 */
+
+#define CSMA_SEED_10 0
+#define CSMA_SEED_11 1
+#define CSMA_SEED_12 2
+#define AACK_I_AM_COORD 3
+#define AACK_DIS_ACK 4
+#define AACK_SET_PD 5
+#define AACK_FVN_MODE0 6
+#define AACK_FVN_MODE1 7
+
+/* Transceiver CSMA-CA Back-off Exponent Control Register */
+#define CSMA_BE _SFR_MEM8(0x16F)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_CSMA_BE {
+ unsigned int min_be : 4; /* Minimum Back-off Exponent */
+ unsigned int max_be : 4; /* Maximum Back-off Exponent */
+};
+
+#define CSMA_BE_struct _SFR_MEM8_STRUCT(0x16f, struct __reg_CSMA_BE)
+
+#endif /* __ASSEMBLER__ */
+
+ /* CSMA_BE */
+
+#define MIN_BE0 0
+#define MIN_BE1 1
+#define MIN_BE2 2
+#define MIN_BE3 3
+#define MAX_BE0 4
+#define MAX_BE1 5
+#define MAX_BE2 6
+#define MAX_BE3 7
+
+/* Transceiver Digital Test Control Register */
+#define TST_CTRL_DIGI _SFR_MEM8(0x176)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TST_CTRL_DIGI {
+ unsigned int tst_ctrl_dig : 4; /* Digital Test Controller Register */
+ unsigned int : 4;
+};
+
+#define TST_CTRL_DIGI_struct _SFR_MEM8_STRUCT(0x176, struct __reg_TST_CTRL_DIGI)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TST_CTRL_DIGI */
+
+#define TST_CTRL_DIG0 0
+#define TST_CTRL_DIG1 1
+#define TST_CTRL_DIG2 2
+#define TST_CTRL_DIG3 3
+
+/* Transceiver Received Frame Length Register */
+#define TST_RX_LENGTH _SFR_MEM8(0x17B)
+
+#if !(defined(__ASSEMBLER__) || defined(__NOSTRUCT__))
+
+struct __reg_TST_RX_LENGTH {
+ unsigned int rx_length : 8; /* Received Frame Length */
+};
+
+#define TST_RX_LENGTH_struct _SFR_MEM8_STRUCT(0x17b, struct __reg_TST_RX_LENGTH)
+
+#endif /* __ASSEMBLER__ */
+
+ /* TST_RX_LENGTH */
+
+#define RX_LENGTH0 0
+#define RX_LENGTH1 1
+#define RX_LENGTH2 2
+#define RX_LENGTH3 3
+#define RX_LENGTH4 4
+#define RX_LENGTH5 5
+#define RX_LENGTH6 6
+#define RX_LENGTH7 7
+
+/* Start of frame buffer */
+#define TRXFBST _SFR_MEM8(0x180)
+
+ /* TRXFBST */
+
+#define TRXFBST0 0
+#define TRXFBST1 1
+#define TRXFBST2 2
+#define TRXFBST3 3
+#define TRXFBST4 4
+#define TRXFBST5 5
+#define TRXFBST6 6
+#define TRXFBST7 7
+
+/* End of frame buffer */
+#define TRXFBEND _SFR_MEM8(0x1FF)
+
+ /* TRXFBEND */
+
+#define TRXFBEND0 0
+#define TRXFBEND1 1
+#define TRXFBEND2 2
+#define TRXFBEND3 3
+#define TRXFBEND4 4
+#define TRXFBEND5 5
+#define TRXFBEND6 6
+#define TRXFBEND7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+
+#define _VECTORS_SIZE 288
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define INT0_vect_num 1
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define INT1_vect_num 2
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define INT2_vect_num 3
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+#define INT3_vect_num 4
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+#define INT4_vect_num 5
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+#define INT5_vect_num 6
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+#define INT6_vect_num 7
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+#define INT7_vect_num 8
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(9)
+#define PCINT0_vect_num 9
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(10)
+#define PCINT1_vect_num 10
+
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(11)
+#define PCINT2_vect_num 11
+
+/* Watchdog Time-out Interrupt */
+#define WDT_vect _VECTOR(12)
+#define WDT_vect_num 12
+
+/* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPA_vect _VECTOR(13)
+#define TIMER2_COMPA_vect_num 13
+
+/* Timer/Counter2 Compare Match B */
+#define TIMER2_COMPB_vect _VECTOR(14)
+#define TIMER2_COMPB_vect_num 14
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(15)
+#define TIMER2_OVF_vect_num 15
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(16)
+#define TIMER1_CAPT_vect_num 16
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(17)
+#define TIMER1_COMPA_vect_num 17
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(18)
+#define TIMER1_COMPB_vect_num 18
+
+/* Timer/Counter1 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(19)
+#define TIMER1_COMPC_vect_num 19
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(20)
+#define TIMER1_OVF_vect_num 20
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(21)
+#define TIMER0_COMPA_vect_num 21
+
+/* Timer/Counter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(22)
+#define TIMER0_COMPB_vect_num 22
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(23)
+#define TIMER0_OVF_vect_num 23
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(24)
+#define SPI_STC_vect_num 24
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(25)
+#define USART0_RX_vect_num 25
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(26)
+#define USART0_UDRE_vect_num 26
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(27)
+#define USART0_TX_vect_num 27
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(28)
+#define ANALOG_COMP_vect_num 28
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(29)
+#define ADC_vect_num 29
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(30)
+#define EE_READY_vect_num 30
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(31)
+#define TIMER3_CAPT_vect_num 31
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(32)
+#define TIMER3_COMPA_vect_num 32
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(33)
+#define TIMER3_COMPB_vect_num 33
+
+/* Timer/Counter3 Compare Match C */
+#define TIMER3_COMPC_vect _VECTOR(34)
+#define TIMER3_COMPC_vect_num 34
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(35)
+#define TIMER3_OVF_vect_num 35
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(36)
+#define USART1_RX_vect_num 36
+
+/* USART1 Data register Empty */
+#define USART1_UDRE_vect _VECTOR(37)
+#define USART1_UDRE_vect_num 37
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(38)
+#define USART1_TX_vect_num 38
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(39)
+#define TWI_vect_num 39
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(40)
+#define SPM_READY_vect_num 40
+
+/* Timer/Counter4 Capture Event */
+#define TIMER4_CAPT_vect _VECTOR(41)
+#define TIMER4_CAPT_vect_num 41
+
+/* Timer/Counter4 Compare Match A */
+#define TIMER4_COMPA_vect _VECTOR(42)
+#define TIMER4_COMPA_vect_num 42
+
+/* Timer/Counter4 Compare Match B */
+#define TIMER4_COMPB_vect _VECTOR(43)
+#define TIMER4_COMPB_vect_num 43
+
+/* Timer/Counter4 Compare Match C */
+#define TIMER4_COMPC_vect _VECTOR(44)
+#define TIMER4_COMPC_vect_num 44
+
+/* Timer/Counter4 Overflow */
+#define TIMER4_OVF_vect _VECTOR(45)
+#define TIMER4_OVF_vect_num 45
+
+/* Timer/Counter5 Capture Event */
+#define TIMER5_CAPT_vect _VECTOR(46)
+#define TIMER5_CAPT_vect_num 46
+
+/* Timer/Counter5 Compare Match A */
+#define TIMER5_COMPA_vect _VECTOR(47)
+#define TIMER5_COMPA_vect_num 47
+
+/* Timer/Counter5 Compare Match B */
+#define TIMER5_COMPB_vect _VECTOR(48)
+#define TIMER5_COMPB_vect_num 48
+
+/* Timer/Counter5 Compare Match C */
+#define TIMER5_COMPC_vect _VECTOR(49)
+#define TIMER5_COMPC_vect_num 49
+
+/* Timer/Counter5 Overflow */
+#define TIMER5_OVF_vect _VECTOR(50)
+#define TIMER5_OVF_vect_num 50
+
+/* USART2, Rx Complete */
+#define USART2_RX_vect _VECTOR(51)
+#define USART2_RX_vect_num 51
+
+/* USART2 Data register Empty */
+#define USART2_UDRE_vect _VECTOR(52)
+#define USART2_UDRE_vect_num 52
+
+/* USART2, Tx Complete */
+#define USART2_TX_vect _VECTOR(53)
+#define USART2_TX_vect_num 53
+
+/* USART3, Rx Complete */
+#define USART3_RX_vect _VECTOR(54)
+#define USART3_RX_vect_num 54
+
+/* USART3 Data register Empty */
+#define USART3_UDRE_vect _VECTOR(55)
+#define USART3_UDRE_vect_num 55
+
+/* USART3, Tx Complete */
+#define USART3_TX_vect _VECTOR(56)
+#define USART3_TX_vect_num 56
+
+/* TRX24 - PLL lock interrupt */
+#define TRX24_PLL_LOCK_vect _VECTOR(57)
+#define TRX24_PLL_LOCK_vect_num 57
+
+/* TRX24 - PLL unlock interrupt */
+#define TRX24_PLL_UNLOCK_vect _VECTOR(58)
+#define TRX24_PLL_UNLOCK_vect_num 58
+
+/* TRX24 - Receive start interrupt */
+#define TRX24_RX_START_vect _VECTOR(59)
+#define TRX24_RX_START_vect_num 59
+
+/* TRX24 - RX_END interrupt */
+#define TRX24_RX_END_vect _VECTOR(60)
+#define TRX24_RX_END_vect_num 60
+
+/* TRX24 - CCA/ED done interrupt */
+#define TRX24_CCA_ED_DONE_vect _VECTOR(61)
+#define TRX24_CCA_ED_DONE_vect_num 61
+
+/* TRX24 - XAH - AMI */
+#define TRX24_XAH_AMI_vect _VECTOR(62)
+#define TRX24_XAH_AMI_vect_num 62
+
+/* TRX24 - TX_END interrupt */
+#define TRX24_TX_END_vect _VECTOR(63)
+#define TRX24_TX_END_vect_num 63
+
+/* TRX24 AWAKE - tranceiver is reaching state TRX_OFF */
+#define TRX24_AWAKE_vect _VECTOR(64)
+#define TRX24_AWAKE_vect_num 64
+
+/* Symbol counter - compare match 1 interrupt */
+#define SCNT_CMP1_vect _VECTOR(65)
+#define SCNT_CMP1_vect_num 65
+
+/* Symbol counter - compare match 2 interrupt */
+#define SCNT_CMP2_vect _VECTOR(66)
+#define SCNT_CMP2_vect_num 66
+
+/* Symbol counter - compare match 3 interrupt */
+#define SCNT_CMP3_vect _VECTOR(67)
+#define SCNT_CMP3_vect_num 67
+
+/* Symbol counter - overflow interrupt */
+#define SCNT_OVFL_vect _VECTOR(68)
+#define SCNT_OVFL_vect_num 68
+
+/* Symbol counter - backoff interrupt */
+#define SCNT_BACKOFF_vect _VECTOR(69)
+#define SCNT_BACKOFF_vect_num 69
+
+/* AES engine ready interrupt */
+#define AES_READY_vect _VECTOR(70)
+#define AES_READY_vect_num 70
+
+/* Battery monitor indicates supply voltage below threshold */
+#define BAT_LOW_vect _VECTOR(71)
+#define BAT_LOW_vect_num 71
+
+
+/* memory parameters */
+
+#define SPM_PAGESIZE (256)
+#define RAMSTART (0x200)
+#define RAMSIZE (0x4000)
+#define RAMEND (0x41FF)
+#define XRAMSTART (0x0000)
+#define XRAMSIZE (0x0000)
+#define XRAMEND RAMEND
+#define E2END (0xFFF)
+#define E2PAGESIZE (0x08)
+#define FLASHEND (0x1ffff)
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* LFUSE Byte */
+#define FUSE_CKSEL0 ~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 ~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 ~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 ~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 ~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 ~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT ~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 ~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* HFUSE Byte */
+#define FUSE_BOOTRST ~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 ~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 ~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE ~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON ~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN ~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN ~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN ~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* EFUSE Byte */
+#define FUSE_BODLEVEL0 ~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 ~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 ~_BV(2) /* Brown-out Detector trigger level */
+#define EFUSE_DEFAULT (0xFF)
+
+
+
+/* Lock Bits */
+
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0xA7
+#define SIGNATURE_2 0x01
+
+#endif /* _AVR_IOM128RFA1_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom16.h b/cpukit/score/cpu/avr/avr/iom16.h
new file mode 100644
index 0000000000..789f08a2e4
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16.h
@@ -0,0 +1,614 @@
+/* Copyright (c) 2004 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16.h - definitions for ATmega16 */
+
+#ifndef _AVR_IOM16_H_
+#define _AVR_IOM16_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define TWBR _SFR_IO8(0x00)
+
+#define TWSR _SFR_IO8(0x01)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_IO8(0x02)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_IO8(0x03)
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define UBRRL _SFR_IO8(0x09)
+
+#define UCSRB _SFR_IO8(0x0A)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRA _SFR_IO8(0x0B)
+#define MPCM 0
+#define U2X 1
+#define PE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UDR _SFR_IO8(0x0C)
+
+#define SPCR _SFR_IO8(0x0D)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x0E)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x0F)
+
+#define PIND _SFR_IO8(0x10)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x11)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x12)
+#define PD0 0
+#define PD1 1
+#define PD2 2
+#define PD3 3
+#define PD4 4
+#define PD5 5
+#define PD6 6
+#define PD7 7
+
+#define PINC _SFR_IO8(0x13)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x14)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x15)
+#define PC0 0
+#define PC1 1
+#define PC2 2
+#define PC3 3
+#define PC4 4
+#define PC5 5
+#define PC6 6
+#define PC7 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PB0 0
+#define PB1 1
+#define PB2 2
+#define PB3 3
+#define PB4 4
+#define PB5 5
+#define PB6 6
+#define PB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PA0 0
+#define PA1 1
+#define PA2 2
+#define PA3 3
+#define PA4 4
+#define PA5 5
+#define PA6 6
+#define PA7 7
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define UCSRC _SFR_IO8(0x20)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL 6
+#define URSEL 7
+
+#define UBRRH _SFR_IO8(0x20)
+#define URSEL 7
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDTOE 4
+
+#define ASSR _SFR_IO8(0x22)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+
+#define OCR2 _SFR_IO8(0x23)
+
+#define TCNT2 _SFR_IO8(0x24)
+
+#define TCCR2 _SFR_IO8(0x25)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM20 4
+#define COM21 5
+#define WGM20 6
+#define FOC2 7
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_IO16(0x26)
+
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_IO16(0x28)
+
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_IO16(0x2A)
+
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_IO16(0x2C)
+
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+#define TCCR1B _SFR_IO8(0x2E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1A _SFR_IO8(0x2F)
+#define WGM10 0
+#define WGM11 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+/*
+ The ADHSM bit has been removed from all documentation,
+ as being not needed at all since the comparator has proven
+ to be fast enough even without feeding it more power.
+*/
+
+#define SFIOR _SFR_IO8(0x30)
+#define PSR10 0
+#define PSR2 1
+#define PUD 2
+#define ACME 3
+#define ADTS0 5
+#define ADTS1 6
+#define ADTS2 7
+
+#define OSCCAL _SFR_IO8(0x31)
+
+#define OCDR _SFR_IO8(0x31)
+
+#define TCNT0 _SFR_IO8(0x32)
+
+#define TCCR0 _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM00 4
+#define COM01 5
+#define WGM00 6
+#define FOC0 7
+
+#define MCUCSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+#define ISC2 6
+#define JTD 7
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define SM0 4
+#define SM1 5
+#define SE 6
+#define SM2 7
+
+#define TWCR _SFR_IO8(0x36)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define SPMCR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define TIFR _SFR_IO8(0x38)
+#define TOV0 0
+#define OCF0 1
+#define TOV1 2
+#define OCF1B 3
+#define OCF1A 4
+#define ICF1 5
+#define TOV2 6
+#define OCF2 7
+
+#define TIMSK _SFR_IO8(0x39)
+#define TOIE0 0
+#define OCIE0 1
+#define TOIE1 2
+#define OCIE1B 3
+#define OCIE1A 4
+#define TICIE1 5
+#define TOIE2 6
+#define OCIE2 7
+
+#define GIFR _SFR_IO8(0x3A)
+#define INTF2 5
+#define INTF0 6
+#define INTF1 7
+
+#define GICR _SFR_IO8(0x3B)
+#define IVCE 0
+#define IVSEL 1
+#define INT2 5
+#define INT0 6
+#define INT1 7
+
+#define OCR0 _SFR_IO8(0x3C)
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector. */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(3)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW2 _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW0 _VECTOR(9)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(10)
+#define SIG_SPI _VECTOR(10)
+
+/* USART, Rx Complete */
+#define USART_RXC_vect _VECTOR(11)
+#define SIG_USART_RECV _VECTOR(11)
+#define SIG_UART_RECV _VECTOR(11)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(12)
+#define SIG_USART_DATA _VECTOR(12)
+#define SIG_UART_DATA _VECTOR(12)
+
+/* USART, Tx Complete */
+#define USART_TXC_vect _VECTOR(13)
+#define SIG_USART_TRANS _VECTOR(13)
+#define SIG_UART_TRANS _VECTOR(13)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(14)
+#define SIG_ADC _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(16)
+#define SIG_COMPARATOR _VECTOR(16)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(17)
+#define SIG_2WIRE_SERIAL _VECTOR(17)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(18)
+#define SIG_INTERRUPT2 _VECTOR(18)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(19)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(19)
+
+/* Store Program Memory Ready */
+#define SPM_RDY_vect _VECTOR(20)
+#define SIG_SPM_READY _VECTOR(20)
+
+#define _VECTORS_SIZE 84
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x45F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IOM16_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom161.h b/cpukit/score/cpu/avr/avr/iom161.h
new file mode 100644
index 0000000000..fc1d87ab81
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom161.h
@@ -0,0 +1,673 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom161.h - definitions for ATmega161 */
+
+#ifndef _AVR_IOM161_H_
+#define _AVR_IOM161_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom161.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* UART1 Baud Rate Register */
+#define UBRR1 _SFR_IO8(0x00)
+
+/* UART1 Control and Status Registers */
+#define UCSR1B _SFR_IO8(0x01)
+#define UCSR1A _SFR_IO8(0x02)
+
+/* UART1 I/O Data Register */
+#define UDR1 _SFR_IO8(0x03)
+
+/* 0x04 reserved */
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x05)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x06)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART0 Baud Rate Register */
+#define UBRR0 _SFR_IO8(0x09)
+
+/* UART0 Control and Status Registers */
+#define UCSR0B _SFR_IO8(0x0A)
+#define UCSR0A _SFR_IO8(0x0B)
+
+/* UART0 I/O Data Register */
+#define UDR0 _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* UART Baud Register HIgh */
+#define UBRRH _SFR_IO8(0x20)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x22)
+
+/* Timer/Counter2 (8-bit) */
+#define TCNT2 _SFR_IO8(0x23)
+
+/* Timer/Counter1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* ASynchronous mode Status Register */
+#define ASSR _SFR_IO8(0x26)
+
+/* Timer/Counter2 Control Register */
+#define TCCR2 _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare RegisterB */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare RegisterA */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Special Function IO Register */
+#define SFIOR _SFR_IO8(0x30)
+
+/* Timer/Counter0 Output Compare Register */
+#define OCR0 _SFR_IO8(0x31)
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Extended MCU general Control Register */
+#define EMCUCR _SFR_IO8(0x36)
+
+/* Store Program Memory Control Register */
+#define SPMCR _SFR_IO8(0x37)
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C reserved */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* UART0, Rx Complete */
+#define UART0_RX_vect _VECTOR(13)
+#define SIG_UART0_RECV _VECTOR(13)
+
+/* UART1, Rx Complete */
+#define UART1_RX_vect _VECTOR(14)
+#define SIG_UART1_RECV _VECTOR(14)
+
+/* UART0 Data Register Empty */
+#define UART0_UDRE_vect _VECTOR(15)
+#define SIG_UART0_DATA _VECTOR(15)
+
+/* UART1 Data Register Empty */
+#define UART1_UDRE_vect _VECTOR(16)
+#define SIG_UART1_DATA _VECTOR(16)
+
+/* UART0, Tx Complete */
+#define UART0_TX_vect _VECTOR(17)
+#define SIG_UART0_TRANS _VECTOR(17)
+
+/* UART1, Tx Complete */
+#define UART1_TX_vect _VECTOR(18)
+#define SIG_UART1_TRANS _VECTOR(18)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(19)
+#define SIG_EEPROM_READY _VECTOR(19)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(20)
+#define SIG_COMPARATOR _VECTOR(20)
+
+#define _VECTORS_SIZE 84
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT1 7
+#define INT0 6
+#define INT2 5
+
+/* GIFR */
+#define INTF1 7
+#define INTF0 6
+#define INTF2 5
+
+/* TIMSK */
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define TOIE2 4
+#define TICIE1 3
+#define OCIE2 2
+#define TOIE0 1
+#define OCIE0 0
+
+/* TIFR */
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define TOV2 4
+#define ICF1 3
+#define OCF2 2
+#define TOV0 1
+#define OCF0 0
+
+/* MCUCR */
+#define SRE 7
+#define SRW10 6
+#define SE 5
+#define SM1 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* EMCUCR */
+#define SM0 7
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW01 3
+#define SRW00 2
+#define SRW11 1
+#define ISC2 0
+
+/* SPMCR */
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* SFIOR */
+#define PSR2 1
+#define PSR10 0
+
+/* TCCR0 */
+#define FOC0 7
+#define PWM0 6
+#define COM01 5
+#define COM00 4
+#define CTC0 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR2 */
+#define FOC2 7
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* ASSR */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define PWM11 1
+#define PWM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB7 = SCK
+ PB6 = MISO
+ PB5 = MOSI
+ PB4 = SS#
+ PB3 = TXD1 / AIN1
+ PB2 = RXD1 / AIN0
+ PB1 = OC2 / T1
+ PB0 = OC0 / T0
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/*
+ PD7 = RD#
+ PD6 = WR#
+ PD5 = TOSC2 / OC1A
+ PD4 = TOSC1
+ PD3 = INT1
+ PD2 = INT0
+ PD1 = TXD0
+ PD0 = RXD0
+ */
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/*
+ PE2 = ALE
+ PE1 = OC1B
+ PE0 = ICP / INT2
+ */
+
+/* PORTE */
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* DDRE */
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* PINE */
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UCSR0A, UCSR1A */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define U2X 1
+#define MPCM 0
+
+/* UCSR0B, UCSR1B */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* ACSR */
+#define ACD 7
+#define AINBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x45F
+#define XRAMEND 0xFFFF
+#define E2END 0x1FF
+#define E2PAGESIZE 0
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_SUT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_BOOTRST (unsigned char)~_BV(6)
+#define FUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IOM161_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom162.h b/cpukit/score/cpu/avr/avr/iom162.h
new file mode 100644
index 0000000000..1ce468c925
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom162.h
@@ -0,0 +1,952 @@
+/* Copyright (c) 2002, Nils Kristian Strom <nilsst@omegav.ntnu.no>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iom162.h - definitions for ATmega162 */
+
+#ifndef _AVR_IOM162_H_
+#define _AVR_IOM162_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom162.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Memory mapped I/O registers */
+
+/* Timer/Counter3 Control Register A */
+#define TCCR3A _SFR_MEM8(0x8B)
+
+/* Timer/Counter3 Control Register B */
+#define TCCR3B _SFR_MEM8(0x8A)
+
+/* Timer/Counter3 - Counter Register */
+#define TCNT3H _SFR_MEM8(0x89)
+#define TCNT3L _SFR_MEM8(0x88)
+#define TCNT3 _SFR_MEM16(0x88)
+
+/* Timer/Counter3 - Output Compare Register A */
+#define OCR3AH _SFR_MEM8(0x87)
+#define OCR3AL _SFR_MEM8(0x86)
+#define OCR3A _SFR_MEM16(0x86)
+
+/* Timer/Counter3 - Output Compare Register B */
+#define OCR3BH _SFR_MEM8(0x85)
+#define OCR3BL _SFR_MEM8(0x84)
+#define OCR3B _SFR_MEM16(0x84)
+
+/* Timer/Counter3 - Input Capture Register */
+#define ICR3H _SFR_MEM8(0x81)
+#define ICR3L _SFR_MEM8(0x80)
+#define ICR3 _SFR_MEM16(0x80)
+
+/* Extended Timer/Counter Interrupt Mask */
+#define ETIMSK _SFR_MEM8(0x7D)
+
+/* Extended Timer/Counter Interrupt Flag Register */
+#define ETIFR _SFR_MEM8(0x7C)
+
+/* Pin Change Mask Register 1 */
+#define PCMSK1 _SFR_MEM8(0x6C)
+
+/* Pin Change Mask Register 0 */
+#define PCMSK0 _SFR_MEM8(0x6B)
+
+/* Clock PRescale */
+#define CLKPR _SFR_MEM8(0x61)
+
+
+/* Standard I/O registers */
+
+/* 0x3F SREG */
+/* 0x3D..0x3E SP */
+#define UBRR1H _SFR_IO8(0x3C) /* USART 1 Baud Rate Register High Byte, Shared with UCSR1C */
+#define UCSR1C _SFR_IO8(0x3C) /* USART 1 Control and Status Register, Shared with UBRR1H */
+#define GICR _SFR_IO8(0x3B) /* General Interrupt Control Register */
+#define GIFR _SFR_IO8(0x3A) /* General Interrupt Flag Register */
+#define TIMSK _SFR_IO8(0x39) /* Timer Interrupt Mask */
+#define TIFR _SFR_IO8(0x38) /* Timer Interrupt Flag Register */
+#define SPMCR _SFR_IO8(0x37) /* Store Program Memory Control Register */
+#define EMCUCR _SFR_IO8(0x36) /* Extended MCU Control Register */
+#define MCUCR _SFR_IO8(0x35) /* MCU Control Register */
+#define MCUCSR _SFR_IO8(0x34) /* MCU Control and Status Register */
+#define TCCR0 _SFR_IO8(0x33) /* Timer/Counter 0 Control Register */
+#define TCNT0 _SFR_IO8(0x32) /* TImer/Counter 0 */
+#define OCR0 _SFR_IO8(0x31) /* Output Compare Register 0 */
+#define SFIOR _SFR_IO8(0x30) /* Special Function I/O Register */
+#define TCCR1A _SFR_IO8(0x2F) /* Timer/Counter 1 Control Register A */
+#define TCCR1B _SFR_IO8(0x2E) /* Timer/Counter 1 Control Register A */
+#define TCNT1H _SFR_IO8(0x2D) /* Timer/Counter 1 High Byte */
+#define TCNT1L _SFR_IO8(0x2C) /* Timer/Counter 1 Low Byte */
+#define TCNT1 _SFR_IO16(0x2C) /* Timer/Counter 1 */
+#define OCR1AH _SFR_IO8(0x2B) /* Timer/Counter 1 Output Compare Register A High Byte */
+#define OCR1AL _SFR_IO8(0x2A) /* Timer/Counter 1 Output Compare Register A Low Byte */
+#define OCR1A _SFR_IO16(0x2A) /* Timer/Counter 1 Output Compare Register A */
+#define OCR1BH _SFR_IO8(0x29) /* Timer/Counter 1 Output Compare Register B High Byte */
+#define OCR1BL _SFR_IO8(0x28) /* Timer/Counter 1 Output Compare Register B Low Byte */
+#define OCR1B _SFR_IO16(0x28) /* Timer/Counter 1 Output Compare Register B */
+#define TCCR2 _SFR_IO8(0x27) /* Timer/Counter 2 Control Register */
+#define ASSR _SFR_IO8(0x26) /* Asynchronous Status Register */
+#define ICR1H _SFR_IO8(0x25) /* Input Capture Register 1 High Byte */
+#define ICR1L _SFR_IO8(0x24) /* Input Capture Register 1 Low Byte */
+#define ICR1 _SFR_IO16(0x24) /* Input Capture Register 1 */
+#define TCNT2 _SFR_IO8(0x23) /* Timer/Counter 2 */
+#define OCR2 _SFR_IO8(0x22) /* Timer/Counter 2 Output Compare Register */
+#define WDTCR _SFR_IO8(0x21) /* Watchdow Timer Control Register */
+#define UBRR0H _SFR_IO8(0x20) /* USART 0 Baud-Rate Register High Byte, Shared with UCSR0C */
+#define UCSR0C _SFR_IO8(0x20) /* USART 0 Control and Status Register C, Shared with UBRR0H */
+#define EEARH _SFR_IO8(0x1F) /* EEPROM Address Register High Byte */
+#define EEARL _SFR_IO8(0x1E) /* EEPROM Address Register Low Byte */
+#define EEAR _SFR_IO16(0x1E) /* EEPROM Address Register */
+#define EEDR _SFR_IO8(0x1D) /* EEPROM Data Register */
+#define EECR _SFR_IO8(0x1C) /* EEPROM Control Register */
+#define PORTA _SFR_IO8(0x1B) /* Port A */
+#define DDRA _SFR_IO8(0x1A) /* Port A Data Direction Register */
+#define PINA _SFR_IO8(0x19) /* Port A Pin Register */
+#define PORTB _SFR_IO8(0x18) /* Port B */
+#define DDRB _SFR_IO8(0x17) /* Port B Data Direction Register */
+#define PINB _SFR_IO8(0x16) /* Port B Pin Register */
+#define PORTC _SFR_IO8(0x15) /* Port C */
+#define DDRC _SFR_IO8(0x14) /* Port C Data Direction Register */
+#define PINC _SFR_IO8(0x13) /* Port C Pin Register */
+#define PORTD _SFR_IO8(0x12) /* Port D */
+#define DDRD _SFR_IO8(0x11) /* Port D Data Direction Register */
+#define PIND _SFR_IO8(0x10) /* Port D Pin Register */
+#define SPDR _SFR_IO8(0x0F) /* SPI Data Register */
+#define SPSR _SFR_IO8(0x0E) /* SPI Status Register */
+#define SPCR _SFR_IO8(0x0D) /* SPI Control Register */
+#define UDR0 _SFR_IO8(0x0C) /* USART 0 Data Register */
+#define UCSR0A _SFR_IO8(0x0B) /* USART 0 Control and Status Register A */
+#define UCSR0B _SFR_IO8(0x0A) /* USART 0 Control and Status Register B */
+#define UBRR0L _SFR_IO8(0x09) /* USART 0 Baud-Rate Register Low Byte */
+#define ACSR _SFR_IO8(0x08) /* Analog Comparator Status Register */
+#define PORTE _SFR_IO8(0x07) /* Port E */
+#define DDRE _SFR_IO8(0x06) /* Port E Data Direction Register */
+#define PINE _SFR_IO8(0x05) /* Port E Pin Register */
+#define OSCCAL _SFR_IO8(0x04) /* Oscillator Calibration, Shared with OCDR */
+#define OCDR _SFR_IO8(0x04) /* On-Chip Debug Register, Shared with OSCCAL */
+#define UDR1 _SFR_IO8(0x03) /* USART 1 Data Register */
+#define UCSR1A _SFR_IO8(0x02) /* USART 1 Control and Status Register A */
+#define UCSR1B _SFR_IO8(0x01) /* USART 1 Control and Status Register B */
+#define UBRR1L _SFR_IO8(0x00) /* USART 0 Baud Rate Register High Byte */
+
+
+/* Interrupt vectors (byte addresses) */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(4)
+#define SIG_PIN_CHANGE0 _VECTOR(4)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(5)
+#define SIG_PIN_CHANGE1 _VECTOR(5)
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE3 _VECTOR(6)
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE3A _VECTOR(7)
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE3B _VECTOR(8)
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW3 _VECTOR(9)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(10)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW2 _VECTOR(11)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(12)
+#define SIG_INPUT_CAPTURE1 _VECTOR(12)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(13)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(14)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+#define SIG_OVERFLOW1 _VECTOR(15)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(16)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(17)
+#define SIG_OVERFLOW0 _VECTOR(17)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(18)
+#define SIG_SPI _VECTOR(18)
+
+/* USART0, Rx Complete */
+#define USART0_RXC_vect _VECTOR(19)
+#define SIG_USART0_RECV _VECTOR(19)
+
+/* USART1, Rx Complete */
+#define USART1_RXC_vect _VECTOR(20)
+#define SIG_USART1_RECV _VECTOR(20)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(21)
+#define SIG_USART0_DATA _VECTOR(21)
+
+/* USART1, Data register Empty */
+#define USART1_UDRE_vect _VECTOR(22)
+#define SIG_USART1_DATA _VECTOR(22)
+
+/* USART0, Tx Complete */
+#define USART0_TXC_vect _VECTOR(23)
+#define SIG_USART0_TRANS _VECTOR(23)
+
+/* USART1, Tx Complete */
+#define USART1_TXC_vect _VECTOR(24)
+#define SIG_USART1_TRANS _VECTOR(24)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(25)
+#define SIG_EEPROM_READY _VECTOR(25)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(26)
+#define SIG_COMPARATOR _VECTOR(26)
+
+/* Store Program Memory Read */
+#define SPM_RDY_vect _VECTOR(27)
+#define SIG_SPM_READY _VECTOR(27)
+
+#define _VECTORS_SIZE 112 /* = (num vec+1) * 4 */
+
+
+
+
+
+/* TCCR3B bit definitions, memory mapped I/O */
+
+#define ICNC3 7
+#define ICES3 6
+#define WGM33 4
+#define WGM32 3
+#define CS32 2
+#define CS31 1
+#define CS30 0
+
+
+
+/* TCCR3A bit definitions, memory mapped I/O */
+
+#define COM3A1 7
+#define COM3A0 6
+#define COM3B1 5
+#define COM3B0 4
+#define FOC3A 3
+#define FOC3B 2
+#define WGM31 1
+#define WGM30 0
+
+
+
+/* ETIMSK bit definitions, memory mapped I/O */
+
+#define TICIE3 5
+#define OCIE3A 4
+#define OCIE3B 3
+#define TOIE3 2
+
+
+
+/* ETIFR bit definitions, memory mapped I/O */
+
+#define ICF3 5
+#define OCF3A 4
+#define OCF3B 3
+#define TOV3 2
+
+
+
+/* PCMSK1 bit definitions, memory mapped I/O */
+#define PCINT15 7
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+
+
+/* PCMSK0 bit definitions, memory mapped I/O */
+
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+
+
+/* CLKPR bit definitions, memory mapped I/O */
+
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+
+
+/* SPH bit definitions */
+
+#define SP15 15
+#define SP14 14
+#define SP13 13
+#define SP12 12
+#define SP11 11
+#define SP10 10
+#define SP9 9
+#define SP8 8
+
+
+
+/* SPL bit definitions */
+
+#define SP7 7
+#define SP6 6
+#define SP5 5
+#define SP4 4
+#define SP3 3
+#define SP2 2
+#define SP1 1
+#define SP0 0
+
+
+
+/* UBRR1H bit definitions */
+
+#define URSEL1 7
+#define UBRR111 3
+#define UBRR110 2
+#define UBRR19 1
+#define UBRR18 0
+
+
+
+/* UCSR1C bit definitions */
+
+#define URSEL1 7
+#define UMSEL1 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+
+
+
+/* GICR bit definitions */
+
+#define INT1 7
+#define INT0 6
+#define INT2 5
+#define PCIE1 4
+#define PCIE0 3
+#define IVSEL 1
+#define IVCE 0
+
+
+
+/* GIFR bit definitions */
+
+#define INTF1 7
+#define INTF0 6
+#define INTF2 5
+#define PCIF1 4
+#define PCIF0 3
+
+
+
+/* TIMSK bit definitions */
+
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define OCIE2 4
+#define TICIE1 3
+#define TOIE2 2
+#define TOIE0 1
+#define OCIE0 0
+
+
+
+/* TIFR bit definitions */
+
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define OCF2 4
+#define ICF1 3
+#define TOV2 2
+#define TOV0 1
+#define OCF0 0
+
+
+
+/* SPMCR bit definitions */
+
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+
+
+/* EMCUCR bit definitions */
+
+#define SM0 7
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW01 3
+#define SRW00 2
+#define SRW11 1
+#define ISC2 0
+
+
+
+/* MCUCR bit definitions */
+
+#define SRE 7
+#define SRW10 6
+#define SE 5
+#define SM1 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+
+
+/* MCUCSR bit definitions */
+
+#define JTD 7
+#define SM2 5
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+
+
+/* TCCR0 bit definitions */
+
+#define FOC0 7
+#define WGM00 6
+#define COM01 5
+#define COM00 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+
+
+/* SFIOR bit definitions */
+
+#define TSM 7
+#define XMBK 6
+#define XMM2 5
+#define XMM1 4
+#define XMM0 3
+#define PUD 2
+#define PSR2 1
+#define PSR310 0
+
+
+
+/* TCCR1A bit definitions */
+
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define WGM11 1
+#define WGM10 0
+
+
+
+
+/* TCCR1B bit definitions */
+
+#define ICNC1 7 /* Input Capture Noise Canceler */
+#define ICES1 6 /* Input Capture Edge Select */
+#define WGM13 4 /* Waveform Generation Mode 3 */
+#define WGM12 3 /* Waveform Generation Mode 2 */
+#define CS12 2 /* Clock Select 2 */
+#define CS11 1 /* Clock Select 1 */
+#define CS10 0 /* Clock Select 0 */
+
+
+
+/* TCCR2 bit definitions */
+
+#define FOC2 7
+#define WGM20 6
+#define COM21 5
+#define COM20 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+
+
+/* ASSR bit definitions */
+
+#define AS2 3
+#define TCN2UB 2
+#define TCON2UB 2 /* Kept for backwards compatibility. */
+#define OCR2UB 1
+#define TCR2UB 0
+
+
+
+/* WDTCR bit definitions */
+
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+
+
+/* UBRR0H bif definitions */
+
+#define URSEL0 7
+#define UBRR011 3
+#define UBRR010 2
+#define UBRR09 1
+#define UBRR08 0
+
+
+
+/* UCSR0C bit definitions */
+
+#define URSEL0 7
+#define UMSEL0 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPOL0 0
+
+
+
+/* EEARH bit definitions */
+
+#define EEAR8 0
+
+
+
+/* EECR bit definitions */
+
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+
+
+/* PORTA bit definitions */
+
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+
+
+/* DDRA bit definitions */
+
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+
+
+/* PINA bit definitions */
+
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+
+/* PORTB bit definitions */
+
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+
+
+/* DDRB bit definitions */
+
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+
+
+/* PINB bit definitions */
+
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+
+
+/* PORTC bit definitions */
+
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+
+
+/* DDRC bit definitions */
+
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+
+
+/* PINC bit definitions */
+
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+
+
+/* PORTD bit definitions */
+
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+
+
+/* DDRD bit definitions */
+
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+
+
+/* PIND bit definitions */
+
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+
+
+/* SPSR bit definitions */
+
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+
+
+/* SPCR bit definitions */
+
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+
+
+/* UCSR0A bit definitions */
+
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+
+
+/* UCSR0B bit definitions */
+
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+
+
+/* ACSR bit definitions */
+
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+
+
+/* PORTE bit definitions */
+
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+
+
+/* DDRE bit definitions */
+
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+
+
+/* PINE bit definitions */
+
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+
+
+/* UCSR1A bit definitions */
+
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+
+
+/* UCSR1B bit definitions */
+
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF
+#define XRAMEND 0xFFFF
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define FUSE_M161C (unsigned char)~_BV(4)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x04
+
+
+#endif /* _AVR_IOM162_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom163.h b/cpukit/score/cpu/avr/avr/iom163.h
new file mode 100644
index 0000000000..2725dc72f7
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom163.h
@@ -0,0 +1,639 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom163.h - definitions for ATmega163 */
+
+#ifndef _AVR_IOM163_H_
+#define _AVR_IOM163_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom163.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+#define TWBR _SFR_IO8(0x00)
+#define TWSR _SFR_IO8(0x01)
+#define TWAR _SFR_IO8(0x02)
+#define TWDR _SFR_IO8(0x03)
+
+/* ADC */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+#define ADCSR _SFR_IO8(0x06)
+#define ADMUX _SFR_IO8(0x07)
+
+/* analog comparator */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART */
+#define UBRR _SFR_IO8(0x09)
+#define UCSRB _SFR_IO8(0x0A)
+#define UCSRA _SFR_IO8(0x0B)
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI */
+#define SPCR _SFR_IO8(0x0D)
+#define SPSR _SFR_IO8(0x0E)
+#define SPDR _SFR_IO8(0x0F)
+
+/* Port D */
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* Port C */
+#define PINC _SFR_IO8(0x13)
+#define DDRC _SFR_IO8(0x14)
+#define PORTC _SFR_IO8(0x15)
+
+/* Port B */
+#define PINB _SFR_IO8(0x16)
+#define DDRB _SFR_IO8(0x17)
+#define PORTB _SFR_IO8(0x18)
+
+/* Port A */
+#define PINA _SFR_IO8(0x19)
+#define DDRA _SFR_IO8(0x1A)
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define UBRRHI _SFR_IO8(0x20)
+
+#define WDTCR _SFR_IO8(0x21)
+
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer 2 */
+#define OCR2 _SFR_IO8(0x23)
+#define TCNT2 _SFR_IO8(0x24)
+#define TCCR2 _SFR_IO8(0x25)
+
+/* Timer 1 */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCCR1B _SFR_IO8(0x2E)
+#define TCCR1A _SFR_IO8(0x2F)
+
+#define SFIOR _SFR_IO8(0x30)
+
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer 0 */
+#define TCNT0 _SFR_IO8(0x32)
+#define TCCR0 _SFR_IO8(0x33)
+
+#define MCUSR _SFR_IO8(0x34)
+#define MCUCR _SFR_IO8(0x35)
+
+#define TWCR _SFR_IO8(0x36)
+
+#define SPMCR _SFR_IO8(0x37)
+
+#define TIFR _SFR_IO8(0x38)
+#define TIMSK _SFR_IO8(0x39)
+
+#define GIFR _SFR_IO8(0x3A)
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C reserved */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(3)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW2 _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW0 _VECTOR(9)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(10)
+#define SIG_SPI _VECTOR(10)
+
+/* UART, RX Complete */
+#define UART_RX_vect _VECTOR(11)
+#define SIG_UART_RECV _VECTOR(11)
+
+/* UART Data Register Empty */
+#define UART_UDRE_vect _VECTOR(12)
+#define SIG_UART_DATA _VECTOR(12)
+
+/* UART, TX Complete */
+#define UART_TX_vect _VECTOR(13)
+#define SIG_UART_TRANS _VECTOR(13)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(14)
+#define SIG_ADC _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(16)
+#define SIG_COMPARATOR _VECTOR(16)
+
+/* 2-Wire Serial Interface */
+#define TWI_vect _VECTOR(17)
+#define SIG_2WIRE_SERIAL _VECTOR(17)
+
+#define _VECTORS_SIZE 72
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT1 7
+#define INT0 6
+/* bit 5 reserved, undefined */
+/* bits 4-0 reserved */
+
+/* GIFR */
+#define INTF1 7
+#define INTF0 6
+/* bits 5-0 reserved */
+
+/* TIMSK */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+/* bit 1 reserved */
+#define TOIE0 0
+
+/* TIFR */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+/* bit 1 reserved, undefined */
+#define TOV0 0
+
+/* SPMCR */
+/* bit 7 reserved */
+#define ASB 6
+/* bit 5 reserved */
+#define ASRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+/* bit 1 reserved */
+#define TWIE 0
+
+/* TWAR */
+#define TWGCE 0
+
+/* TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+/* bits 2-0 reserved */
+
+/* MCUCR */
+/* bit 7 reserved */
+#define SE 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* MCUSR */
+/* bits 7-4 reserved */
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* SFIOR */
+/* bits 7-4 reserved */
+#define ACME 3
+#define PUD 2
+#define PSR2 1
+#define PSR10 0
+
+/* TCCR0 */
+/* bits 7-3 reserved */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR2 */
+#define FOC2 7
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* ASSR */
+/* bits 7-4 reserved */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define PWM11 1
+#define PWM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+/* bits 5-4 reserved */
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* WDTCR */
+/* bits 7-5 reserved */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* PA7-PA0 = ADC7-ADC0 */
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB7 = SCK
+ PB6 = MISO
+ PB5 = MOSI
+ PB4 = SS#
+ PB3 = AIN1
+ PB2 = AIN0
+ PB1 = T1
+ PB0 = T0
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/*
+ PC7 = TOSC2
+ PC6 = TOSC1
+ PC1 = SDA
+ PC0 = SCL
+ */
+/* PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/*
+ PD7 = OC2
+ PD6 = ICP
+ PD5 = OC1A
+ PD4 = OC1B
+ PD3 = INT1
+ PD2 = INT0
+ PD1 = TXD
+ PD0 = RXD
+ */
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+/* bits 5-1 reserved */
+#define SPI2X 0
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UCSRA */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+/* bit 2 reserved */
+#define U2X 1
+#define MPCM 0
+
+/* UCSRB */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* ACSR */
+#define ACD 7
+#define AINBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADCSR */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x45F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 0
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SPIEN)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define HFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x02
+
+
+#endif /* _AVR_IOM163_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom164.h b/cpukit/score/cpu/avr/avr/iom164.h
new file mode 100644
index 0000000000..97bfc661c4
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom164.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005, 2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom164.h - definitions for ATmega164 */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM164_H_
+#define _AVR_IOM164_H_ 1
+
+#include <avr/iomxx4.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x04FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature (ATmega164P) */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x0A
+
+
+#endif /* _AVR_IOM164_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom165.h b/cpukit/score/cpu/avr/avr/iom165.h
new file mode 100644
index 0000000000..513a2ad87a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom165.h
@@ -0,0 +1,820 @@
+/* Copyright (c) 2004,2005,2006 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom165.h - definitions for ATmega165 */
+
+#ifndef _AVR_IOM165_H_
+#define _AVR_IOM165_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom165.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 6
+#define PCIF1 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 6
+#define PCIE1 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCD 7 // The datasheet defines this but IMO it should be OCDR7.
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+/* Combine PCMSK0 and PCMSK1 */
+#define PCMSK _SFR_MEM16(0x6B)
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSRA _SFR_MEM8(0xC0)
+#define MPCM 0
+#define U2X 1
+#define UPE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UCSRB _SFR_MEM8(0XC1)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRC _SFR_MEM8(0xC2)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRRL and UBRRH */
+#define UBRR _SFR_MEM16(0xC4)
+
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRRH _SFR_MEM8(0xC5)
+
+#define UDR _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xFF] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define USART_RX_vect _VECTOR(13) /* Alias */
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define USART_UDRE_vect _VECTOR(14) /* Alias */
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define USART_TX_vect _VECTOR(15) /* Alias */
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+#define _VECTORS_SIZE 88
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOM165_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom165p.h b/cpukit/score/cpu/avr/avr/iom165p.h
new file mode 100644
index 0000000000..feac415e85
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom165p.h
@@ -0,0 +1,822 @@
+/* Copyright (c) 2004,2005,2006 Eric B. Weddington
+ Copyright (c) 2006 Anatoly Sokolov <aesok@post.ru>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom165p.h - definitions for ATmega165P */
+
+#ifndef _AVR_IOM165P_H_
+#define _AVR_IOM165P_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom165p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 6
+#define PCIF1 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 6
+#define PCIE1 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCD 7 // The datasheet defines this but IMO it should be OCDR7.
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+/* Combine PCMSK0 and PCMSK1 */
+#define PCMSK _SFR_MEM16(0x6B)
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRRL and UBRRH */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xFF] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define USART_RX_vect _VECTOR(13) /* Alias */
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define USART_UDRE_vect _VECTOR(14) /* Alias */
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define USART_TX_vect _VECTOR(15) /* Alias */
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+#define _VECTORS_SIZE 88
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOM165P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom168.h b/cpukit/score/cpu/avr/avr/iom168.h
new file mode 100644
index 0000000000..575c8b4a93
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom168.h
@@ -0,0 +1,91 @@
+/* Copyright (c) 2004, Theodore A. Roth
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM168_H_
+#define _AVR_IOM168_H_ 1
+
+#include <avr/iomx8.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOM168_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom168p.h b/cpukit/score/cpu/avr/avr/iom168p.h
new file mode 100644
index 0000000000..c44d409792
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom168p.h
@@ -0,0 +1,874 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom168p.h - definitions for ATmega168P. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom168p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM168P_H_
+#define _AVR_IOM168P_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define EEPROM_REG_LOCATIONS 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 0
+#define TWAM1 1
+#define TWAM2 2
+#define TWAM3 3
+#define TWAM4 4
+#define TWAM5 5
+#define TWAM6 6
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCPHA0 1
+#define UCSZ01 2
+#define UDORD0 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0_0 0
+#define UBRR0_1 1
+#define UBRR0_2 2
+#define UBRR0_3 3
+#define UBRR0_4 4
+#define UBRR0_5 5
+#define UBRR0_6 6
+#define UBRR0_7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR0_8 0
+#define UBRR0_9 1
+#define UBRR0_10 2
+#define UBRR0_11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
+#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
+#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
+#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
+#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
+#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
+#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
+#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
+#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
+#define SPM_READY_vect _VECTOR(25) /* Store Program Memory Read */
+
+#define _VECTORS_SIZE (26 * 4)
+
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF /* Last On-Chip SRAM Location */
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x0B
+
+
+#endif /* _AVR_IOM168P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom169.h b/cpukit/score/cpu/avr/avr/iom169.h
new file mode 100644
index 0000000000..315a45bbe7
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom169.h
@@ -0,0 +1,1107 @@
+/* Copyright (c) 2002, 2003, 2004, 2005
+ Juergen Schilling <juergen.schilling@honeywell.com>
+ Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iom169.h - definitions for ATmega169 */
+
+/* This should be up to date with data sheet version 2514J-AVR-12/03. */
+
+#ifndef _AVR_IOM169_H_
+#define _AVR_IOM169_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom169.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Port A */
+#define PINA _SFR_IO8(0x00)
+#define DDRA _SFR_IO8(0x01)
+#define PORTA _SFR_IO8(0x02)
+
+/* Port B */
+#define PINB _SFR_IO8(0x03)
+#define DDRB _SFR_IO8(0x04)
+#define PORTB _SFR_IO8(0x05)
+
+/* Port C */
+#define PINC _SFR_IO8(0x06)
+#define DDRC _SFR_IO8(0x07)
+#define PORTC _SFR_IO8(0x08)
+
+/* Port D */
+#define PIND _SFR_IO8(0x09)
+#define DDRD _SFR_IO8(0x0A)
+#define PORTD _SFR_IO8(0x0B)
+
+/* Port E */
+#define PINE _SFR_IO8(0x0C)
+#define DDRE _SFR_IO8(0x0D)
+#define PORTE _SFR_IO8(0x0E)
+
+/* Port F */
+#define PINF _SFR_IO8(0x0F)
+#define DDRF _SFR_IO8(0x10)
+#define PORTF _SFR_IO8(0x11)
+
+/* Port G */
+#define PING _SFR_IO8(0x12)
+#define DDRG _SFR_IO8(0x13)
+#define PORTG _SFR_IO8(0x14)
+
+/* Timer/Counter 0 interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+
+/* Timer/Counter 1 interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+
+/* Timer/Counter 2 interrupt Flag Register */
+#define TIFR2 _SFR_IO8(0x17)
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+
+/* Timer/Counter Register */
+#define TCNT0 _SFR_IO8(0x26)
+
+/* Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x2A)
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x2B)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+
+/* Analog Comperator Control and Status Register */
+#define ACSR _SFR_IO8(0x30)
+
+/* On-chip Debug Register */
+#define OCDR _SFR_IO8(0x31)
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU Control Rgeister */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Store Program Memory Control and Status Register */
+#define SPMCSR _SFR_IO8(0x37)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_MEM8(0x60)
+
+/* Clock Prescale Register */
+#define CLKPR _SFR_MEM8(0x61)
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+
+/* Pin Change Mask Register */
+#define PCMSK _SFR_MEM16(0x6B)
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCMSK1 _SFR_MEM8(0x6C)
+
+/* Timer/Counter 0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+
+/* Timer/Counter 1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+
+/* Timer/Counter 2 Interrupt Mask Register */
+#define TIMSK2 _SFR_MEM8(0x70)
+
+/* ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+
+/* ADC Multiplex Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+
+/* NOTE: DIDR0 and DIDR1 are swapped in the register summary of the data sheet
+ (2514D-AVR-01/03), but seem to be correct in the discussions of the
+ registers. */
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+
+/* Timer/Counter1 Register */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Timer/Counter1 Input Capture Register */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Timer/Counter1 Output Compare Registare B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Timer/Counter2 Control Register A */
+#define TCCR2A _SFR_MEM8(0xB0)
+
+/* Timer/Counter2 Register */
+#define TCNT2 _SFR_MEM8(0xB2)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Asynchronous Status Register */
+#define ASSR _SFR_MEM8(0xB6)
+
+/* USI Control Register */
+#define USICR _SFR_MEM8(0xB8)
+
+/* USI Status Register */
+#define USISR _SFR_MEM8(0xB9)
+
+/* USI Data Register */
+#define USIDR _SFR_MEM8(0xBA)
+
+/* USART0 Control and Status Register A */
+#define UCSRA _SFR_MEM8(0xC0)
+
+/* USART0 Control and Status Register B */
+#define UCSRB _SFR_MEM8(0xC1)
+
+/* USART0 Control and Status Register C */
+#define UCSRC _SFR_MEM8(0xC2)
+
+/* USART0 Baud Rate Register */
+#define UBRR _SFR_MEM16(0xC4)
+#define UBRRL _SFR_MEM8(0xC4)
+#define UBRRH _SFR_MEM8(0xC5)
+
+/* USART0 I/O Data Register */
+#define UDR _SFR_MEM8(0xC6)
+
+/* LCD Control and Status Register A */
+#define LCDCRA _SFR_MEM8(0xE4)
+
+/* LCD Control and Status Register B */
+#define LCDCRB _SFR_MEM8(0xE5)
+
+/* LCD Frame Rate Register */
+#define LCDFRR _SFR_MEM8(0xE6)
+
+/* LCD Contrast Control Register */
+#define LCDCCR _SFR_MEM8(0xE7)
+
+/* LCD Memory mapping */
+#define LCDDR0 _SFR_MEM8(0xEC)
+#define LCDDR1 _SFR_MEM8(0xED)
+#define LCDDR2 _SFR_MEM8(0xEE)
+#define LCDDR3 _SFR_MEM8(0xEF)
+#define LCDDR5 _SFR_MEM8(0xF1)
+#define LCDDR6 _SFR_MEM8(0xF2)
+#define LCDDR7 _SFR_MEM8(0xF3)
+#define LCDDR8 _SFR_MEM8(0xF4)
+#define LCDDR10 _SFR_MEM8(0xF6)
+#define LCDDR11 _SFR_MEM8(0xF7)
+#define LCDDR12 _SFR_MEM8(0xF8)
+#define LCDDR13 _SFR_MEM8(0xF9)
+#define LCDDR15 _SFR_MEM8(0xFB)
+#define LCDDR16 _SFR_MEM8(0xFC)
+#define LCDDR17 _SFR_MEM8(0xFD)
+#define LCDDR18 _SFR_MEM8(0xFE)
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define SIG_USART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define SIG_USART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_USART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* LCD Start of Frame */
+#define LCD_vect _VECTOR(22)
+#define SIG_LCD _VECTOR(22)
+
+#define _VECTORS_SIZE 92
+
+/* Bit numbers */
+
+/*
+ PA7 = SEG3
+ PA6 = SEG2
+ PA5 = SEG1
+ PA4 = SEG0
+ PA3 = COM3
+ PA2 = COM2
+ PA1 = COM1
+ PA0 = COM0
+*/
+
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB7 = OC2A / PCINT15
+ PB6 = OC1B / PCINT14
+ PB5 = OC1A / PCINT13
+ PB4 = OC0A / PCINT12
+ PB3 = MISO / PCINT11
+ PB2 = MOSI / PCINT10
+ PB1 = SCK / PCINT9
+ PB0 = SS# / PCINT8
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/*
+ PC7 = SEG5
+ PC6 = SEG6
+ PC5 = SEG7
+ PC4 = SEG8
+ PC3 = SEG9
+ PC2 = SEG10
+ PC1 = SEG11
+ PC0 = SEG12
+*/
+
+/* PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/*
+ PD7 = SEG15
+ PD6 = SEG16
+ PD5 = SEG17
+ PD4 = SEG18
+ PD3 = SEG19
+ PD2 = SEG20
+ PD1 = INT0 / SEG21
+ PD0 = ICP / SEG22
+ */
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/*
+ PE7 = CLK0 / PCINT7
+ PE6 = DO / PCINT6
+ PE5 = DI / SDA / PCINT5
+ PE4 = USCK / SCL / PCINT4
+ PE3 = AIN1 / PCINT3
+ PE2 = XCK / AIN0 / PCINT2
+ PE1 = TXD / PCINT1
+ PE0 = RXD / PCINT0
+ */
+
+/* PORTE */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* DDRE */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* PINE */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/*
+ PF7 = ADC7 / TDI
+ PF6 = ADC6 / TDO
+ PF5 = ADC5 / TMS
+ PF4 = ADC4 / TCK
+ PF3 = ADC3
+ PF2 = ADC2
+ PF1 = ADC1
+ PF0 = ADC0
+ */
+
+/* PORTF */
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+/* DDRF */
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+/* PINF */
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+/*
+ PG5 = RESET#
+ PG4 = T0 / SEG23
+ PG3 = T1 / SEG24
+ PG2 = SEG4
+ PG1 = SEG13
+ PG0 = SEG14
+ */
+
+/* PORTG */
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+/* DDRG */
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+/* PING */
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+/* TIFR0 */
+#define OCF0A 1
+#define TOV0 0
+
+/* TIFR1 */
+#define ICF1 5
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+/* TIFR2 */
+#define OCF2A 1
+#define TOV2 0
+
+/* EIFR */
+#define PCIF1 7
+#define PCIF0 6
+#define INTF0 0
+
+/* EIMSK */
+#define PCIE1 7
+#define PCIE0 6
+#define INT0 0
+
+/* EECR */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* GTCCR */
+#define TSM 7
+#define PSR2 1
+#define PSR10 0
+
+/* TCCR0A */
+#define FOC0A 7
+#define WGM00 6
+#define COM0A1 5
+#define COM0A0 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* OCDR */
+#define IDRD 7
+#define OCD 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* SMCR */
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+/* MCUSR */
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* MCUCR */
+#define JTD 7
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+
+/* SPMCSR */
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* WDTCR */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* CLKPR */
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+/* EICRA */
+#define ISC01 1
+#define ISC00 0
+
+/* PCMSK0 */
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+/* PCMSK1 */
+#define PCINT15 7
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+/* TIMSK0 */
+#define OCIE0A 1
+#define TOIE0 0
+
+/* TIMSK1 */
+#define ICIE1 5
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+/* TIMSK2 */
+#define OCIE2A 1
+#define TOIE2 0
+
+/* ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADCSRB */
+#define ACME 6
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* DIDR1 */
+#define AIN1D 1
+#define AIN0D 0
+
+/* DIDR0 */
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define WGM11 1
+#define WGM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* TCCR1C */
+#define FOC1A 7
+#define FOC1B 6
+
+/* TCCR2A */
+#define FOC2A 7
+#define WGM20 6
+#define COM2A1 5
+#define COM2A0 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* ASSR */
+#define EXCLK 4
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* USICR */
+#define USISIE 7
+#define USIOIE 6
+#define USIWM1 5
+#define USIWM0 4
+#define USICS1 3
+#define USICS0 2
+#define USICLK 1
+#define USITC 0
+
+/* USISR */
+#define USISIF 7
+#define USIOIF 6
+#define USIPF 5
+#define USIDC 4
+#define USICNT3 3
+#define USICNT2 2
+#define USICNT1 1
+#define USICNT0 0
+
+/* UCSRA */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define UPE 2
+#define U2X 1
+#define MPCM 0
+
+/* UCSRB */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define RXB8 1
+#define TXB8 0
+
+/* UCSRC */
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* LCDCRA */
+#define LCDEN 7
+#define LCDAB 6
+#define LCDIF 4
+#define LCDIE 3
+#define LCDBD 2 /* Only in Rev. F */
+#define LCDCCD 1 /* Only in Rev. F */
+#define LCDBL 0
+
+/* LCDCRB */
+#define LCDCS 7
+#define LCD2B 6
+#define LCDMUX1 5
+#define LCDMUX0 4
+#define LCDPM2 2
+#define LCDPM1 1
+#define LCDPM0 0
+
+/* LCDFRR */
+#define LCDPS2 6
+#define LCDPS1 5
+#define LCDPS0 4
+#define LCDCD2 2
+#define LCDCD1 1
+#define LCDCD0 0
+
+/* LCDCCR */
+#define LCDDC2 7
+#define LCDDC1 6
+#define LCDDC0 5
+#define LCDMDT 4 /* Only in Rev. F */
+#define LCDCC3 3
+#define LCDCC2 2
+#define LCDCC1 1
+#define LCDCC0 0
+
+/* LCDDR0-18 */
+#define SEG24 0
+
+#define SEG23 7
+#define SEG22 6
+#define SEG21 5
+#define SEG20 4
+#define SEG19 3
+#define SEG18 2
+#define SEG17 1
+#define SEG16 0
+
+#define SEG15 7
+#define SEG14 6
+#define SEG13 5
+#define SEG12 4
+#define SEG11 3
+#define SEG10 2
+#define SEG9 1
+#define SEG8 0
+
+#define SEG7 7
+#define SEG6 6
+#define SEG5 5
+#define SEG4 4
+#define SEG3 3
+#define SEG2 2
+#define SEG1 1
+#define SEG0 0
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOM169_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom169p.h b/cpukit/score/cpu/avr/avr/iom169p.h
new file mode 100644
index 0000000000..5083a71ea4
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom169p.h
@@ -0,0 +1,1030 @@
+/* Copyright (c) 2002, 2003, 2004, 2005, 2006
+ Juergen Schilling <juergen.schilling@honeywell.com>
+ Eric B. Weddington <ericw@evcohs.com>
+ Anatoly Sokolov <aesok@post.ru>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iom169p.h - definitions for ATmega169P */
+
+#ifndef _AVR_IOM169P_H_
+#define _AVR_IOM169P_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom169p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Port A */
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Port B */
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Port C */
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Port D */
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Port E */
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Port F */
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+/* Port G */
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+/* Timer/Counter 0 interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+#define OCF0A 1
+#define TOV0 0
+
+/* Timer/Counter 1 interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+#define ICF1 5
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+/* Timer/Counter 2 interrupt Flag Register */
+#define TIFR2 _SFR_IO8(0x17)
+#define OCF2A 1
+#define TOV2 0
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+#define PCIF1 7
+#define PCIF0 6
+#define INTF0 0
+
+/* External Interrupt Mask Register */
+#define EIMSK _SFR_IO8(0x1D)
+#define PCIE1 7
+#define PCIE0 6
+#define INT0 0
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSR2 1
+#define PSR10 0
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+#define FOC0A 7
+#define WGM00 6
+#define COM0A1 5
+#define COM0A0 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter Register */
+#define TCNT0 _SFR_IO8(0x26)
+
+/* Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x2A)
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x2B)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x2C)
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x2D)
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPI Data Register */
+#define SPDR _SFR_IO8(0x2E)
+
+/* Analog Comperator Control and Status Register */
+#define ACSR _SFR_IO8(0x30)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* On-chip Debug Register */
+#define OCDR _SFR_IO8(0x31)
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* MCU Control Rgeister */
+#define MCUCR _SFR_IO8(0x35)
+#define JTD 7
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+
+/* Store Program Memory Control and Status Register */
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_MEM8(0x60)
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Clock Prescale Register */
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+#define ISC01 1
+#define ISC00 0
+
+/* Pin Change Mask Register */
+#define PCMSK _SFR_MEM16(0x6B)
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT15 7
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+/* Timer/Counter 0 Interrupt Mask Register */
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define OCIE0A 1
+#define TOIE0 0
+
+/* Timer/Counter 1 Interrupt Mask Register */
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define ICIE1 5
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+/* Timer/Counter 2 Interrupt Mask Register */
+#define TIMSK2 _SFR_MEM8(0x70)
+#define OCIE2A 1
+#define TOIE2 0
+
+/* ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ACME 6
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+/* ADC Multiplex Selection Register */
+#define ADMUX _SFR_MEM8(0x7C)
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+/* Digital Input Disable Register 1 */
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN1D 1
+#define AIN0D 0
+
+/* Timer/Counter1 Control Register A */
+#define TCCR1A _SFR_MEM8(0x80)
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define WGM11 1
+#define WGM10 0
+
+/* Timer/Counter1 Control Register B */
+#define TCCR1B _SFR_MEM8(0x81)
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1A 7
+#define FOC1B 6
+
+/* Timer/Counter1 Register */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Timer/Counter1 Input Capture Register */
+#define ICR1 _SFR_MEM16(0x86)
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Timer/Counter1 Output Compare Registare B */
+#define OCR1B _SFR_MEM16(0x8A)
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Timer/Counter2 Control Register A */
+#define TCCR2A _SFR_MEM8(0xB0)
+#define FOC2A 7
+#define WGM20 6
+#define COM2A1 5
+#define COM2A0 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Timer/Counter2 Register */
+#define TCNT2 _SFR_MEM8(0xB2)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Asynchronous Status Register */
+#define ASSR _SFR_MEM8(0xB6)
+#define EXCLK 4
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* USI Control Register */
+#define USICR _SFR_MEM8(0xB8)
+#define USISIE 7
+#define USIOIE 6
+#define USIWM1 5
+#define USIWM0 4
+#define USICS1 3
+#define USICS0 2
+#define USICLK 1
+#define USITC 0
+
+/* USI Status Register */
+#define USISR _SFR_MEM8(0xB9)
+#define USISIF 7
+#define USIOIF 6
+#define USIPF 5
+#define USIDC 4
+#define USICNT3 3
+#define USICNT2 2
+#define USICNT1 1
+#define USICNT0 0
+
+/* USI Data Register */
+#define USIDR _SFR_MEM8(0xBA)
+
+/* USART0 Control and Status Register A */
+#define UCSR0A _SFR_MEM8(0xC0)
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+/* USART0 Control and Status Register B */
+#define UCSR0B _SFR_MEM8(0xC1)
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+/* USART0 Control and Status Register C */
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UMSEL0 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPOL0 0
+
+/* USART0 Baud Rate Register */
+#define UBRR0 _SFR_MEM16(0xC4)
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+/* USART0 I/O Data Register */
+#define UDR0 _SFR_MEM8(0xC6)
+
+/* LCD Control and Status Register A */
+#define LCDCRA _SFR_MEM8(0xE4)
+#define LCDEN 7
+#define LCDAB 6
+#define LCDIF 4
+#define LCDIE 3
+#define LCDBD 2
+#define LCDCCD 1
+#define LCDBL 0
+
+/* LCD Control and Status Register B */
+#define LCDCRB _SFR_MEM8(0xE5)
+#define LCDCS 7
+#define LCD2B 6
+#define LCDMUX1 5
+#define LCDMUX0 4
+#define LCDPM2 2
+#define LCDPM1 1
+#define LCDPM0 0
+
+/* LCD Frame Rate Register */
+#define LCDFRR _SFR_MEM8(0xE6)
+#define LCDPS2 6
+#define LCDPS1 5
+#define LCDPS0 4
+#define LCDCD2 2
+#define LCDCD1 1
+#define LCDCD0 0
+
+/* LCD Contrast Control Register */
+#define LCDCCR _SFR_MEM8(0xE7)
+#define LCDDC2 7
+#define LCDDC1 6
+#define LCDDC0 5
+#define LCDMDT 4
+#define LCDCC3 3
+#define LCDCC2 2
+#define LCDCC1 1
+#define LCDCC0 0
+
+/* LCD Memory mapping */
+#define LCDDR0 _SFR_MEM8(0xEC)
+#define SEG007 7
+#define SEG006 6
+#define SEG005 5
+#define SEG004 4
+#define SEG003 3
+#define SEG002 2
+#define SEG001 1
+#define SEG000 0
+
+#define LCDDR1 _SFR_MEM8(0xED)
+#define SEG015 7
+#define SEG014 6
+#define SEG013 5
+#define SEG012 4
+#define SEG011 3
+#define SEG010 2
+#define SEG009 1
+#define SEG008 0
+
+#define LCDDR2 _SFR_MEM8(0xEE)
+#define SEG023 7
+#define SEG022 6
+#define SEG021 5
+#define SEG020 4
+#define SEG019 3
+#define SEG018 2
+#define SEG017 1
+#define SEG016 0
+
+#define LCDDR3 _SFR_MEM8(0xEF)
+#define SEG024 0
+
+#define LCDDR5 _SFR_MEM8(0xF1)
+#define SEG107 7
+#define SEG106 6
+#define SEG105 5
+#define SEG104 4
+#define SEG103 3
+#define SEG102 2
+#define SEG101 1
+#define SEG100 0
+
+#define LCDDR6 _SFR_MEM8(0xF2)
+#define SEG115 7
+#define SEG114 6
+#define SEG113 5
+#define SEG112 4
+#define SEG111 3
+#define SEG110 2
+#define SEG109 1
+#define SEG108 0
+
+#define LCDDR7 _SFR_MEM8(0xF3)
+#define SEG123 7
+#define SEG122 6
+#define SEG121 5
+#define SEG120 4
+#define SEG119 3
+#define SEG118 2
+#define SEG117 1
+#define SEG116 0
+
+#define LCDDR8 _SFR_MEM8(0xF4)
+#define SEG124 0
+
+#define LCDDR10 _SFR_MEM8(0xF6)
+#define SEG207 7
+#define SEG206 6
+#define SEG205 5
+#define SEG204 4
+#define SEG203 3
+#define SEG202 2
+#define SEG201 1
+#define SEG200 0
+
+#define LCDDR11 _SFR_MEM8(0xF7)
+#define SEG215 7
+#define SEG214 6
+#define SEG213 5
+#define SEG212 4
+#define SEG211 3
+#define SEG210 2
+#define SEG209 1
+#define SEG208 0
+
+#define LCDDR12 _SFR_MEM8(0xF8)
+#define SEG223 7
+#define SEG222 6
+#define SEG221 5
+#define SEG220 4
+#define SEG219 3
+#define SEG218 2
+#define SEG217 1
+#define SEG216 0
+
+#define LCDDR13 _SFR_MEM8(0xF9)
+#define SEG224 0
+
+#define LCDDR15 _SFR_MEM8(0xFB)
+#define SEG307 7
+#define SEG306 6
+#define SEG305 5
+#define SEG304 4
+#define SEG303 3
+#define SEG302 2
+#define SEG301 1
+#define SEG300 0
+
+#define LCDDR16 _SFR_MEM8(0xFC)
+#define SEG315 7
+#define SEG314 6
+#define SEG313 5
+#define SEG312 4
+#define SEG311 3
+#define SEG310 2
+#define SEG309 1
+#define SEG308 0
+
+#define LCDDR17 _SFR_MEM8(0xFD)
+#define SEG323 7
+#define SEG322 6
+#define SEG321 5
+#define SEG320 4
+#define SEG319 3
+#define SEG318 2
+#define SEG317 1
+#define SEG316 0
+
+#define LCDDR18 _SFR_MEM8(0xFE)
+#define SEG324 0
+
+/* LCDDR0-18 */
+#define SEG24 0
+
+#define SEG23 7
+#define SEG22 6
+#define SEG21 5
+#define SEG20 4
+#define SEG19 3
+#define SEG18 2
+#define SEG17 1
+#define SEG16 0
+
+#define SEG15 7
+#define SEG14 6
+#define SEG13 5
+#define SEG12 4
+#define SEG11 3
+#define SEG10 2
+#define SEG9 1
+#define SEG8 0
+
+#define SEG7 7
+#define SEG6 6
+#define SEG5 5
+#define SEG4 4
+#define SEG3 3
+#define SEG2 2
+#define SEG1 1
+#define SEG0 0
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define SIG_USART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define SIG_USART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_USART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* LCD Start of Frame */
+#define LCD_vect _VECTOR(22)
+#define SIG_LCD _VECTOR(22)
+
+#define _VECTORS_SIZE 92
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x4FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOM169P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom169pa.h b/cpukit/score/cpu/avr/avr/iom169pa.h
new file mode 100644
index 0000000000..61cf002b83
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom169pa.h
@@ -0,0 +1,1472 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom169pa.h - definitions for ATmega169PA */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom169pa.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega169PA_H_
+#define _AVR_ATmega169PA_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+#define PINE3 3
+#define PINE4 4
+#define PINE5 5
+#define PINE6 6
+#define PINE7 7
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+#define DDE3 3
+#define DDE4 4
+#define DDE5 5
+#define DDE6 6
+#define DDE7 7
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+#define PORTE3 3
+#define PORTE4 4
+#define PORTE5 5
+#define PORTE6 6
+#define PORTE7 7
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF0 0
+#define PINF1 1
+#define PINF2 2
+#define PINF3 3
+#define PINF4 4
+#define PINF5 5
+#define PINF6 6
+#define PINF7 7
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF0 0
+#define DDF1 1
+#define DDF2 2
+#define DDF3 3
+#define DDF4 4
+#define DDF5 5
+#define DDF6 6
+#define DDF7 7
+
+#define PORTF _SFR_IO8(0x11)
+#define PORTF0 0
+#define PORTF1 1
+#define PORTF2 2
+#define PORTF3 3
+#define PORTF4 4
+#define PORTF5 5
+#define PORTF6 6
+#define PORTF7 7
+
+#define PING _SFR_IO8(0x12)
+#define PING0 0
+#define PING1 1
+#define PING2 2
+#define PING3 3
+#define PING4 4
+#define PING5 5
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG0 0
+#define DDG1 1
+#define DDG2 2
+#define DDG3 3
+#define DDG4 4
+#define DDG5 5
+
+#define PORTG _SFR_IO8(0x14)
+#define PORTG0 0
+#define PORTG1 1
+#define PORTG2 2
+#define PORTG3 3
+#define PORTG4 4
+#define PORTG5 5
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR310 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A0 0
+#define OCR2A1 1
+#define OCR2A2 2
+#define OCR2A3 3
+#define OCR2A4 4
+#define OCR2A5 5
+#define OCR2A6 6
+#define OCR2A7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0 0
+#define UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR00 0
+#define UDR01 1
+#define UDR02 2
+#define UDR03 3
+#define UDR04 4
+#define UDR05 5
+#define UDR06 6
+#define UDR07 7
+
+#define LCDCRA _SFR_MEM8(0xE4)
+#define LCDBL 0
+#define LCDCCD 1
+#define LCDBD 2
+#define LCDIE 3
+#define LCDIF 4
+#define LCDAB 6
+#define LCDEN 7
+
+#define LCDCRB _SFR_MEM8(0xE5)
+#define LCDPM0 0
+#define LCDPM1 1
+#define LCDPM2 2
+#define LCDMUX0 4
+#define LCDMUX1 5
+#define LCD2B 6
+#define LCDCS 7
+
+#define LCDFRR _SFR_MEM8(0xE6)
+#define LCDCD0 0
+#define LCDCD1 1
+#define LCDCD2 2
+#define LCDPS0 4
+#define LCDPS1 5
+#define LCDPS2 6
+
+#define LCDCCR _SFR_MEM8(0xE7)
+#define LCDCC0 0
+#define LCDCC1 1
+#define LCDCC2 2
+#define LCDCC3 3
+#define LCDMDT 4
+#define LCDDC0 5
+#define LCDDC1 6
+#define LCDDC2 7
+
+#define LCDDR0 _SFR_MEM8(0xEC)
+#define SEG000 0
+#define SEG001 1
+#define SEG002 2
+#define SEG003 3
+#define SEG004 4
+#define SEG005 5
+#define SEG006 6
+#define SEG007 7
+
+#define LCDDR1 _SFR_MEM8(0xED)
+#define SEG008 0
+#define SEG009 1
+#define SEG010 2
+#define SEG011 3
+#define SEG012 4
+#define SEG013 5
+#define SEG014 6
+#define SEG015 7
+
+#define LCDDR2 _SFR_MEM8(0xEE)
+#define SEG016 0
+#define SEG017 1
+#define SEG018 2
+#define SEG019 3
+#define SEG020 4
+#define SEG021 5
+#define SEG022 6
+#define SEG023 7
+
+#define LCDDR3 _SFR_MEM8(0xEF)
+#define SEG024 0
+
+#define LCDDR5 _SFR_MEM8(0xF1)
+#define SEG100 0
+#define SEG101 1
+#define SEG102 2
+#define SEG103 3
+#define SEG104 4
+#define SEG105 5
+#define SEG106 6
+#define SEG107 7
+
+#define LCDDR6 _SFR_MEM8(0xF2)
+#define SEG108 0
+#define SEG109 1
+#define SEG110 2
+#define SEG111 3
+#define SEG112 4
+#define SEG113 5
+#define SEG114 6
+#define SEG115 7
+
+#define LCDDR7 _SFR_MEM8(0xF3)
+#define SEG116 0
+#define SEG117 1
+#define SEG118 2
+#define SEG119 3
+#define SEG120 4
+#define SEG121 5
+#define SEG122 6
+#define SEG123 7
+
+#define LCDDR8 _SFR_MEM8(0xF4)
+#define SEG124 0
+
+#define LCDDR10 _SFR_MEM8(0xF6)
+#define SEG200 0
+#define SEG201 1
+#define SEG202 2
+#define SEG203 3
+#define SEG204 4
+#define SEG205 5
+#define SEG206 6
+#define SEG207 7
+
+#define LCDDR11 _SFR_MEM8(0xF7)
+#define SEG208 0
+#define SEG209 1
+#define SEG210 2
+#define SEG211 3
+#define SEG212 4
+#define SEG213 5
+#define SEG214 6
+#define SEG215 7
+
+#define LCDDR12 _SFR_MEM8(0xF8)
+#define SEG216 0
+#define SEG217 1
+#define SEG218 2
+#define SEG219 3
+#define SEG220 4
+#define SEG221 5
+#define SEG222 6
+#define SEG223 7
+
+#define LCDDR13 _SFR_MEM8(0xF9)
+#define SEG224 0
+
+#define LCDDR15 _SFR_MEM8(0xFB)
+#define SEG300 0
+#define SEG301 1
+#define SEG302 2
+#define SEG303 3
+#define SEG304 4
+#define SEG305 5
+#define SEG306 6
+#define SEG307 7
+
+#define LCDDR16 _SFR_MEM8(0xFC)
+#define SEG308 0
+#define SEG309 1
+#define SEG310 2
+#define SEG311 3
+#define SEG312 4
+#define SEG313 5
+#define SEG314 6
+#define SEG315 7
+
+#define LCDDR17 _SFR_MEM8(0xFD)
+#define SEG316 0
+#define SEG317 1
+#define SEG318 2
+#define SEG319 3
+#define SEG320 4
+#define SEG321 5
+#define SEG322 6
+#define SEG323 7
+
+#define LCDDR18 _SFR_MEM8(0xFE)
+#define SEG324 0
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define PCINT0_vect_num 2
+#define PCINT0_vect _VECTOR(2) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 3
+#define PCINT1_vect _VECTOR(3) /* Pin Change Interrupt Request 1 */
+#define TIMER2_COMP_vect_num 4
+#define TIMER2_COMP_vect _VECTOR(4) /* Timer/Counter2 Compare Match */
+#define TIMER2_OVF_vect_num 5
+#define TIMER2_OVF_vect _VECTOR(5) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 6
+#define TIMER1_CAPT_vect _VECTOR(6) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 7
+#define TIMER1_COMPA_vect _VECTOR(7) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 8
+#define TIMER1_COMPB_vect _VECTOR(8) /* Timer/Counter Compare Match B */
+#define TIMER1_OVF_vect_num 9
+#define TIMER1_OVF_vect _VECTOR(9) /* Timer/Counter1 Overflow */
+#define TIMER0_COMP_vect_num 10
+#define TIMER0_COMP_vect _VECTOR(10) /* Timer/Counter0 Compare Match */
+#define TIMER0_OVF_vect_num 11
+#define TIMER0_OVF_vect _VECTOR(11) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 12
+#define SPI_STC_vect _VECTOR(12) /* SPI Serial Transfer Complete */
+#define USART0_RX_vect_num 13
+#define USART0_RX_vect _VECTOR(13) /* USART0, Rx Complete */
+#define USART0_UDRE_vect_num 14
+#define USART0_UDRE_vect _VECTOR(14) /* USART0 Data register Empty */
+#define USART0_TX_vect_num 15
+#define USART0_TX_vect _VECTOR(15) /* USART0, Tx Complete */
+#define USI_START_vect_num 16
+#define USI_START_vect _VECTOR(16) /* USI Start Condition */
+#define USI_OVERFLOW_vect_num 17
+#define USI_OVERFLOW_vect _VECTOR(17) /* USI Overflow */
+#define ANALOG_COMP_vect_num 18
+#define ANALOG_COMP_vect _VECTOR(18) /* Analog Comparator */
+#define ADC_vect_num 19
+#define ADC_vect _VECTOR(19) /* ADC Conversion Complete */
+#define EE_READY_vect_num 20
+#define EE_READY_vect _VECTOR(20) /* EEPROM Ready */
+#define SPM_READY_vect_num 21
+#define SPM_READY_vect _VECTOR(21) /* Store Program Memory Read */
+#define LCD_vect_num 22
+#define LCD_vect _VECTOR(22) /* LCD Start of Frame */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (23 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0) /* Disable external reset */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3) /* Brown out detector trigger level */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x05
+
+
+/* Device Pin Definitions */
+#define RXD_DDR DDRE
+#define RXD_PORT PORTE
+#define RXD_PIN PINE
+#define RXD_BIT 0
+
+#define PCINT0_DDR DDRE
+#define PCINT0_PORT PORTE
+#define PCINT0_PIN PINE
+#define PCINT0_BIT 0
+
+#define TXD_DDR DDRE
+#define TXD_PORT PORTE
+#define TXD_PIN PINE
+#define TXD_BIT 1
+
+#define PCINT1_DDR DDRE
+#define PCINT1_PORT PORTE
+#define PCINT1_PIN PINE
+#define PCINT1_BIT 1
+
+#define XCK_DDR DDRE
+#define XCK_PORT PORTE
+#define XCK_PIN PINE
+#define XCK_BIT 2
+
+#define AIN0_DDR DDRE
+#define AIN0_PORT PORTE
+#define AIN0_PIN PINE
+#define AIN0_BIT 2
+
+#define PCINT2_DDR DDRE
+#define PCINT2_PORT PORTE
+#define PCINT2_PIN PINE
+#define PCINT2_BIT 2
+
+#define AIN1_DDR DDRE
+#define AIN1_PORT PORTE
+#define AIN1_PIN PINE
+#define AIN1_BIT 3
+
+#define PCINT3_DDR DDRE
+#define PCINT3_PORT PORTE
+#define PCINT3_PIN PINE
+#define PCINT3_BIT 3
+
+#define USCK_DDR DDRE
+#define USCK_PORT PORTE
+#define USCK_PIN PINE
+#define USCK_BIT 4
+
+#define SCL_DDR DDRE
+#define SCL_PORT PORTE
+#define SCL_PIN PINE
+#define SCL_BIT 4
+
+#define PCINT4_DDR DDRE
+#define PCINT4_PORT PORTE
+#define PCINT4_PIN PINE
+#define PCINT4_BIT 4
+
+#define DI_DDR DDRE
+#define DI_PORT PORTE
+#define DI_PIN PINE
+#define DI_BIT 5
+
+#define SDA_DDR DDRE
+#define SDA_PORT PORTE
+#define SDA_PIN PINE
+#define SDA_BIT 5
+
+#define PCINT5_DDR DDRE
+#define PCINT5_PORT PORTE
+#define PCINT5_PIN PINE
+#define PCINT5_BIT 5
+
+#define DO_DDR DDRE
+#define DO_PORT PORTE
+#define DO_PIN PINE
+#define DO_BIT 6
+
+#define PCINT6_DDR DDRE
+#define PCINT6_PORT PORTE
+#define PCINT6_PIN PINE
+#define PCINT6_BIT 6
+
+#define PCINT7_DDR DDRE
+#define PCINT7_PORT PORTE
+#define PCINT7_PIN PINE
+#define PCINT7_BIT 7
+
+#define SS_DDR DDRB
+#define SS_PORT PORTB
+#define SS_PIN PINB
+#define SS_BIT 0
+
+#define PCINT8_DDR DDRB
+#define PCINT8_PORT PORTB
+#define PCINT8_PIN PINB
+#define PCINT8_BIT 0
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 1
+
+#define PCINT9_DDR DDRB
+#define PCINT9_PORT PORTB
+#define PCINT9_PIN PINB
+#define PCINT9_BIT 1
+
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 2
+
+#define PCINT10_DDR DDRB
+#define PCINT10_PORT PORTB
+#define PCINT10_PIN PINB
+#define PCINT10_BIT 2
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 3
+
+#define PCINT11_DDR DDRB
+#define PCINT11_PORT PORTB
+#define PCINT11_PIN PINB
+#define PCINT11_BIT 3
+
+#define OC0_DDR DDRB
+#define OC0_PORT PORTB
+#define OC0_PIN PINB
+#define OC0_BIT 4
+
+#define PCINT12_DDR DDRB
+#define PCINT12_PORT PORTB
+#define PCINT12_PIN PINB
+#define PCINT12_BIT 4
+
+#define OC1A_DDR DDRB
+#define OC1A_PORT PORTB
+#define OC1A_PIN PINB
+#define OC1A_BIT 5
+
+#define PCINT13_DDR DDRB
+#define PCINT13_PORT PORTB
+#define PCINT13_PIN PINB
+#define PCINT13_BIT 5
+
+#define OC1B_DDR DDRB
+#define OC1B_PORT PORTB
+#define OC1B_PIN PINB
+#define OC1B_BIT 6
+
+#define PCINT14_DDR DDRB
+#define PCINT14_PORT PORTB
+#define PCINT14_PIN PINB
+#define PCINT14_BIT 6
+
+#define OC2_DDR DDRB
+#define OC2_PORT PORTB
+#define OC2_PIN PINB
+#define OC2_BIT 7
+
+#define PCINT15_DDR DDRB
+#define PCINT15_PORT PORTB
+#define PCINT15_PIN PINB
+#define PCINT15_BIT 7
+
+#define T1_DDR DDRG
+#define T1_PORT PORTG
+#define T1_PIN PING
+#define T1_BIT 3
+
+#define SEG24_DDR DDRG
+#define SEG24_PORT PORTG
+#define SEG24_PIN PING
+#define SEG24_BIT 3
+
+#define T0_DDR DDRG
+#define T0_PORT PORTG
+#define T0_PIN PING
+#define T0_BIT 4
+
+#define SEG23_DDR DDRG
+#define SEG23_PORT PORTG
+#define SEG23_PIN PING
+#define SEG23_BIT 4
+
+#define ICP/SEG22_DDR DDRD
+#define ICP/SEG22_PORT PORTD
+#define ICP/SEG22_PIN PIND
+#define ICP/SEG22_BIT 0
+
+#define INT0/SEG21_DDR DDRD
+#define INT0/SEG21_PORT PORTD
+#define INT0/SEG21_PIN PIND
+#define INT0/SEG21_BIT 1
+
+#define SEG20_DDR DDRD
+#define SEG20_PORT PORTD
+#define SEG20_PIN PIND
+#define SEG20_BIT 2
+
+#define SEG19_DDR DDRD
+#define SEG19_PORT PORTD
+#define SEG19_PIN PIND
+#define SEG19_BIT 3
+
+#define SEG18_DDR DDRD
+#define SEG18_PORT PORTD
+#define SEG18_PIN PIND
+#define SEG18_BIT 4
+
+#define SEG17_DDR DDRD
+#define SEG17_PORT PORTD
+#define SEG17_PIN PIND
+#define SEG17_BIT 5
+
+#define SEG16_DDR DDRD
+#define SEG16_PORT PORTD
+#define SEG16_PIN PIND
+#define SEG16_BIT 6
+
+#define SEG15_DDR DDRD
+#define SEG15_PORT PORTD
+#define SEG15_PIN PIND
+#define SEG15_BIT 7
+
+#define SEG14_DDR DDRG
+#define SEG14_PORT PORTG
+#define SEG14_PIN PING
+#define SEG14_BIT 0
+
+#define SEG13_DDR DDRG
+#define SEG13_PORT PORTG
+#define SEG13_PIN PING
+#define SEG13_BIT 1
+
+#define SEG12_DDR DDRC
+#define SEG12_PORT PORTC
+#define SEG12_PIN PINC
+#define SEG12_BIT 0
+
+#define SEG11_DDR DDRC
+#define SEG11_PORT PORTC
+#define SEG11_PIN PINC
+#define SEG11_BIT 1
+
+#define SEG10_DDR DDRC
+#define SEG10_PORT PORTC
+#define SEG10_PIN PINC
+#define SEG10_BIT 2
+
+#define SEG9_DDR DDRC
+#define SEG9_PORT PORTC
+#define SEG9_PIN PINC
+#define SEG9_BIT 3
+
+#define SEG8_DDR DDRC
+#define SEG8_PORT PORTC
+#define SEG8_PIN PINC
+#define SEG8_BIT 4
+
+#define SEG7_DDR DDRC
+#define SEG7_PORT PORTC
+#define SEG7_PIN PINC
+#define SEG7_BIT 5
+
+#define SEG6_DDR DDRC
+#define SEG6_PORT PORTC
+#define SEG6_PIN PINC
+#define SEG6_BIT 6
+
+#define SEG5_DDR DDRC
+#define SEG5_PORT PORTC
+#define SEG5_PIN PINC
+#define SEG5_BIT 7
+
+#define SEG4_DDR DDRG
+#define SEG4_PORT PORTG
+#define SEG4_PIN PING
+#define SEG4_BIT 2
+
+#define SEG3_DDR DDRA
+#define SEG3_PORT PORTA
+#define SEG3_PIN PINA
+#define SEG3_BIT 7
+
+#define SEG2_DDR DDRA
+#define SEG2_PORT PORTA
+#define SEG2_PIN PINA
+#define SEG2_BIT 6
+
+#define SEG1_DDR DDRA
+#define SEG1_PORT PORTA
+#define SEG1_PIN PINA
+#define SEG1_BIT 5
+
+#define SEG0_DDR DDRA
+#define SEG0_PORT PORTA
+#define SEG0_PIN PINA
+#define SEG0_BIT 4
+
+#define COM3_DDR DDRA
+#define COM3_PORT PORTA
+#define COM3_PIN PINA
+#define COM3_BIT 3
+
+#define COM2_DDR DDRA
+#define COM2_PORT PORTA
+#define COM2_PIN PINA
+#define COM2_BIT 2
+
+#define COM1_DDR DDRA
+#define COM1_PORT PORTA
+#define COM1_PIN PINA
+#define COM1_BIT 1
+
+#define COM0_DDR DDRA
+#define COM0_PORT PORTA
+#define COM0_PIN PINA
+#define COM0_BIT 0
+
+#define ADC7_DDR DDRF
+#define ADC7_PORT PORTF
+#define ADC7_PIN PINF
+#define ADC7_BIT 7
+
+#define ADC6_DDR DDRF
+#define ADC6_PORT PORTF
+#define ADC6_PIN PINF
+#define ADC6_BIT 6
+
+#define TD0_DDR DDRF
+#define TD0_PORT PORTF
+#define TD0_PIN PINF
+#define TD0_BIT 6
+
+#define ADC5_DDR DDRF
+#define ADC5_PORT PORTF
+#define ADC5_PIN PINF
+#define ADC5_BIT 5
+
+#define ADC4_DDR DDRF
+#define ADC4_PORT PORTF
+#define ADC4_PIN PINF
+#define ADC4_BIT 4
+
+#define ADC3_DDR DDRF
+#define ADC3_PORT PORTF
+#define ADC3_PIN PINF
+#define ADC3_BIT 3
+
+#define ADC2_DDR DDRF
+#define ADC2_PORT PORTF
+#define ADC2_PIN PINF
+#define ADC2_BIT 2
+
+#define ADC1_DDR DDRF
+#define ADC1_PORT PORTF
+#define ADC1_PIN PINF
+#define ADC1_BIT 1
+
+#define ADC0_DDR DDRF
+#define ADC0_PORT PORTF
+#define ADC0_PIN PINF
+#define ADC0_BIT 0
+
+#endif /* _AVR_ATmega169PA_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom16a.h b/cpukit/score/cpu/avr/avr/iom16a.h
new file mode 100644
index 0000000000..55255a294d
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16a.h
@@ -0,0 +1,904 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16a.h - definitions for ATmega16A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega16A_H_
+#define _AVR_ATmega16A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define TWBR _SFR_IO8(0x00)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_IO8(0x01)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_IO8(0x02)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_IO8(0x03)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define UBRRL _SFR_IO8(0x09)
+#define UBRR0 0
+#define UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UCSRB _SFR_IO8(0x0A)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRA _SFR_IO8(0x0B)
+#define MPCM 0
+#define U2X 1
+#define UPE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UDR _SFR_IO8(0x0C)
+#define UDR0 0
+#define UDR1 1
+#define UDR2 2
+#define UDR3 3
+#define UDR4 4
+#define UDR5 5
+#define UDR6 6
+#define UDR7 7
+
+#define SPCR _SFR_IO8(0x0D)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x0E)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x0F)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define PIND _SFR_IO8(0x10)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x11)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x12)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINC _SFR_IO8(0x13)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x14)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x15)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define UBRRH _SFR_IO8(0x20)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UCSRC _SFR_IO8(0x20)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL 6
+#define URSEL 7
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDTOE 4
+
+#define ASSR _SFR_IO8(0x22)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+
+#define OCR2 _SFR_IO8(0x23)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define TCNT2 _SFR_IO8(0x24)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define TCCR2 _SFR_IO8(0x25)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM20 4
+#define COM21 5
+#define WGM20 6
+#define FOC2 7
+
+#define ICR1 _SFR_IO16(0x26)
+
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_IO8(0x27)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1B _SFR_IO16(0x28)
+
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1A _SFR_IO16(0x2A)
+
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_IO8(0x2B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define TCNT1 _SFR_IO16(0x2C)
+
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define TCCR1B _SFR_IO8(0x2E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1A _SFR_IO8(0x2F)
+#define WGM10 0
+#define WGM11 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define SFIOR _SFR_IO8(0x30)
+#define PSR10 0
+#define PSR2 1
+#define PUD 2
+#define ACME 3
+#define ADTS0 5
+#define ADTS1 6
+#define ADTS2 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define TCNT0 _SFR_IO8(0x32)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0 _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM00 4
+#define COM01 5
+#define WGM00 6
+#define FOC0 7
+
+#define MCUCSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+#define ISC2 6
+#define JTD 7
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define SM0 4
+#define SM1 5
+#define SE 6
+#define SM2 7
+
+#define TWCR _SFR_IO8(0x36)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define TIFR _SFR_IO8(0x38)
+#define TOV0 0
+#define OCF0 1
+#define TOV1 2
+#define OCF1B 3
+#define OCF1A 4
+#define ICF1 5
+#define TOV2 6
+#define OCF2 7
+
+#define TIMSK _SFR_IO8(0x39)
+#define TOIE0 0
+#define OCIE0 1
+#define TOIE1 2
+#define OCIE1B 3
+#define OCIE1A 4
+#define TICIE1 5
+#define TOIE2 6
+#define OCIE2 7
+
+#define GIFR _SFR_IO8(0x3A)
+#define INTF2 5
+#define INTF0 6
+#define INTF1 7
+
+#define GICR _SFR_IO8(0x3B)
+#define IVCE 0
+#define IVSEL 1
+#define INT2 5
+#define INT0 6
+#define INT1 7
+
+#define OCR0 _SFR_IO8(0x3C)
+#define OCR0_0 0
+#define OCR0_1 1
+#define OCR0_2 2
+#define OCR0_3 3
+#define OCR0_4 4
+#define OCR0_5 5
+#define OCR0_6 6
+#define OCR0_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define TIMER2_COMP_vect_num 3
+#define TIMER2_COMP_vect _VECTOR(3) /* Timer/Counter2 Compare Match */
+#define TIMER2_OVF_vect_num 4
+#define TIMER2_OVF_vect _VECTOR(4) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 5
+#define TIMER1_CAPT_vect _VECTOR(5) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 6
+#define TIMER1_COMPA_vect _VECTOR(6) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 7
+#define TIMER1_COMPB_vect _VECTOR(7) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 8
+#define TIMER1_OVF_vect _VECTOR(8) /* Timer/Counter1 Overflow */
+#define TIMER0_OVF_vect_num 9
+#define TIMER0_OVF_vect _VECTOR(9) /* Timer/Counter0 Overflow */
+#define SPISTC_vect_num 10
+#define SPISTC_vect _VECTOR(10) /* Serial Transfer Complete */
+#define USARTRXC_vect_num 11
+#define USARTRXC_vect _VECTOR(11) /* USART, Rx Complete */
+#define USARTUDRE_vect_num 12
+#define USARTUDRE_vect _VECTOR(12) /* USART Data Register Empty */
+#define USARTTXC_vect_num 13
+#define USARTTXC_vect _VECTOR(13) /* USART, Tx Complete */
+#define ADC_vect_num 14
+#define ADC_vect _VECTOR(14) /* ADC Conversion Complete */
+#define EE_RDY_vect_num 15
+#define EE_RDY_vect _VECTOR(15) /* EEPROM Ready */
+#define ANA_COMP_vect_num 16
+#define ANA_COMP_vect _VECTOR(16) /* Analog Comparator */
+#define TWI_vect_num 17
+#define TWI_vect _VECTOR(17) /* 2-wire Serial Interface */
+#define INT2_vect_num 18
+#define INT2_vect _VECTOR(18) /* External Interrupt Request 2 */
+#define TIMER0_COMP_vect_num 19
+#define TIMER0_COMP_vect _VECTOR(19) /* Timer/Counter0 Compare Match */
+#define SPM_RDY_vect_num 20
+#define SPM_RDY_vect _VECTOR(20) /* Store Program Memory Ready */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (21 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x60)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_BODEN (unsigned char)~_BV(6) /* Brown out detector enable */
+#define FUSE_BODLEVEL (unsigned char)~_BV(7) /* Brown out detector trigger level */
+#define LFUSE_DEFAULT (FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_CKOPT (unsigned char)~_BV(4) /* Oscillator Options */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x03
+
+
+/* Device Pin Definitions */
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 5
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 6
+
+#define PB7_SCK_DDR DDRB7_SCK
+#define PB7_SCK_PORT PORTB7_SCK
+#define PB7_SCK_PIN PINB7_SCK
+#define PB7_SCK_BIT 7_SCK
+
+#define RXD_DDR DDRD
+#define RXD_PORT PORTD
+#define RXD_PIN PIND
+#define RXD_BIT 0
+
+#define TXD_DDR DDRD
+#define TXD_PORT PORTD
+#define TXD_PIN PIND
+#define TXD_BIT 1
+
+#define INT0_DDR DDRD
+#define INT0_PORT PORTD
+#define INT0_PIN PIND
+#define INT0_BIT 2
+
+#define INT1_DDR DDRD
+#define INT1_PORT PORTD
+#define INT1_PIN PIND
+#define INT1_BIT 3
+
+#define OC1B_DDR DDRD
+#define OC1B_PORT PORTD
+#define OC1B_PIN PIND
+#define OC1B_BIT 4
+
+#define OC1A_DDR DDRD
+#define OC1A_PORT PORTD
+#define OC1A_PIN PIND
+#define OC1A_BIT 5
+
+#define ICP_DDR DDRD
+#define ICP_PORT PORTD
+#define ICP_PIN PIND
+#define ICP_BIT 6
+
+#define OC2_DDR DDRD
+#define OC2_PORT PORTD
+#define OC2_PIN PIND
+#define OC2_BIT 7
+
+#define SCL_DDR DDRC
+#define SCL_PORT PORTC
+#define SCL_PIN PINC
+#define SCL_BIT 0
+
+#define SDA_DDR DDRC
+#define SDA_PORT PORTC
+#define SDA_PIN PINC
+#define SDA_BIT 1
+
+#define PC3_DDR DDRC
+#define PC3_PORT PORTC
+#define PC3_PIN PINC
+#define PC3_BIT 3
+
+#define PC4_DDR DDRC
+#define PC4_PORT PORTC
+#define PC4_PIN PINC
+#define PC4_BIT 4
+
+#define PC5_DDR DDRC
+#define PC5_PORT PORTC
+#define PC5_PIN PINC
+#define PC5_BIT 5
+
+#define ADC7_DDR DDRA
+#define ADC7_PORT PORTA
+#define ADC7_PIN PINA
+#define ADC7_BIT 7
+
+#define ADC6_DDR DDRA
+#define ADC6_PORT PORTA
+#define ADC6_PIN PINA
+#define ADC6_BIT 6
+
+#define ADc5_DDR DDRA
+#define ADc5_PORT PORTA
+#define ADc5_PIN PINA
+#define ADc5_BIT 5
+
+#define ADC4_DDR DDRA
+#define ADC4_PORT PORTA
+#define ADC4_PIN PINA
+#define ADC4_BIT 4
+
+#define ADC3_DDR DDRA
+#define ADC3_PORT PORTA
+#define ADC3_PIN PINA
+#define ADC3_BIT 3
+
+#define ADC2_DDR DDRA
+#define ADC2_PORT PORTA
+#define ADC2_PIN PINA
+#define ADC2_BIT 2
+
+#define ADC1_DDR DDRA
+#define ADC1_PORT PORTA
+#define ADC1_PIN PINA
+#define ADC1_BIT 1
+
+#define ADC0_DDR DDRA
+#define ADC0_PORT PORTA
+#define ADC0_PIN PINA
+#define ADC0_BIT 0
+
+#define T0_DDR DDRB
+#define T0_PORT PORTB
+#define T0_PIN PINB
+#define T0_BIT 0
+
+#define T1_DDR DDRB
+#define T1_PORT PORTB
+#define T1_PIN PINB
+#define T1_BIT 1
+
+#define AIN0_DDR DDRB
+#define AIN0_PORT PORTB
+#define AIN0_PIN PINB
+#define AIN0_BIT 2
+
+#define AIN1_DDR DDRB
+#define AIN1_PORT PORTB
+#define AIN1_PIN PINB
+#define AIN1_BIT 3
+
+#define SS_DDR DDRB
+#define SS_PORT PORTB
+#define SS_PIN PINB
+#define SS_BIT 4
+
+#endif /* _AVR_ATmega16A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom16hva.h b/cpukit/score/cpu/avr/avr/iom16hva.h
new file mode 100644
index 0000000000..674e65bfb8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16hva.h
@@ -0,0 +1,75 @@
+/* Copyright (c) 2007, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iom16hva.h - definitions for ATmega16HVA. */
+
+#ifndef _AVR_IOM16HVA_H_
+#define _AVR_IOM16HVA_H_ 1
+
+#include <avr/iomxxhva.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x2FF
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_SUT0 (unsigned char)~_BV(0)
+#define FUSE_SUT1 (unsigned char)~_BV(1)
+#define FUSE_SUT2 (unsigned char)~_BV(2)
+#define FUSE_SELFPRGEN (unsigned char)~_BV(3)
+#define FUSE_DWEN (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_EESAVE (unsigned char)~_BV(6)
+#define FUSE_WDTON (unsigned char)~_BV(7)
+#define FUSE_DEFAULT (FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x0C
+
+
+#endif /* _AVR_IOM16HVA_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom16hva2.h b/cpukit/score/cpu/avr/avr/iom16hva2.h
new file mode 100644
index 0000000000..9a0d2af4d6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16hva2.h
@@ -0,0 +1,871 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16hva2.h - definitions for ATmega16HVA2 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16hva2.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega16HVA2_H_
+#define _AVR_ATmega16HVA2_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+#define ICF0 3
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 3
+
+#define OSICSR _SFR_IO8(0x17)
+#define OSIEN 0
+#define OSIST 1
+#define OSISEL0 4
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define ICS0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+
+#define TCNT0 _SFR_IO16(0x26)
+
+#define TCNT0L _SFR_IO8(0x26)
+#define TCNT0L0 0
+#define TCNT0L1 1
+#define TCNT0L2 2
+#define TCNT0L3 3
+#define TCNT0L4 4
+#define TCNT0L5 5
+#define TCNT0L6 6
+#define TCNT0L7 7
+
+#define TCNT0H _SFR_IO8(0x27)
+#define TCNT0H0 0
+#define TCNT0H1 1
+#define TCNT0H2 2
+#define TCNT0H3 3
+#define TCNT0H4 4
+#define TCNT0H5 5
+#define TCNT0H6 6
+#define TCNT0H7 7
+
+#define OCR0A _SFR_IO8(0x28)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+#define OCR0B _SFR_IO8(0x29)
+#define OCR0B0 0
+#define OCR0B1 1
+#define OCR0B2 2
+#define OCR0B3 3
+#define OCR0B4 4
+#define OCR0B5 5
+#define OCR0B6 6
+#define OCR0B7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BODRF 2
+#define WDRF 3
+#define OCDRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define PUD 4
+#define CKOE 5
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+#define SIGRD 5
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRVADC 0
+#define PRTIM0 1
+#define PRTIM1 2
+#define PRSPI 3
+#define PRVRM 5
+
+#define FOSCCAL _SFR_MEM8(0x66)
+#define FCAL0 0
+#define FCAL1 1
+#define FCAL2 2
+#define FCAL3 3
+#define FCAL4 4
+#define FCAL5 5
+#define FCAL6 6
+#define FCAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+#define ICIE0 3
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 3
+
+#define VADC _SFR_MEM16(0x78)
+
+#define VADCL _SFR_MEM8(0x78)
+#define VADC0 0
+#define VADC1 1
+#define VADC2 2
+#define VADC3 3
+#define VADC4 4
+#define VADC5 5
+#define VADC6 6
+#define VADC7 7
+
+#define VADCH _SFR_MEM8(0x79)
+#define VADC8 0
+#define VADC9 1
+#define VADC10 2
+#define VADC11 3
+
+#define VADCSR _SFR_MEM8(0x7A)
+#define VADCCIE 0
+#define VADCCIF 1
+#define VADSC 2
+#define VADEN 3
+
+#define VADMUX _SFR_MEM8(0x7C)
+#define VADMUX0 0
+#define VADMUX1 1
+#define VADMUX2 2
+#define VADMUX3 3
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define PA0DID 0
+#define PA1DID 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define ICS1 3
+#define ICES1 4
+#define ICNC1 5
+#define ICEN1 6
+#define TCW1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define OCR1A _SFR_MEM8(0x88)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define OCR1B _SFR_MEM8(0x89)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define ROCR _SFR_MEM8(0xC8)
+#define ROCWIE 0
+#define ROCWIF 1
+#define ROCS 7
+
+#define BGCCR _SFR_MEM8(0xD0)
+#define BGCC0 0
+#define BGCC1 1
+#define BGCC2 2
+#define BGCC3 3
+#define BGCC4 4
+#define BGCC5 5
+#define BGD 7
+
+#define BGCRR _SFR_MEM8(0xD1)
+#define BGCR0 0
+#define BGCR1 1
+#define BGCR2 2
+#define BGCR3 3
+#define BGCR4 4
+#define BGCR5 5
+#define BGCR6 6
+#define BGCR7 7
+
+#define CADAC0 _SFR_MEM8(0xE0)
+#define CADAC00 0
+#define CADAC01 1
+#define CADAC02 2
+#define CADAC03 3
+#define CADAC04 4
+#define CADAC05 5
+#define CADAC06 6
+#define CADAC07 7
+
+#define CADAC1 _SFR_MEM8(0xE1)
+#define CADAC08 0
+#define CADAC09 1
+#define CADAC10 2
+#define CADAC11 3
+#define CADAC12 4
+#define CADAC13 5
+#define CADAC14 6
+#define CADAC15 7
+
+#define CADAC2 _SFR_MEM8(0xE2)
+#define CADAC16 0
+#define CADAC17 1
+#define CADAC18 2
+#define CADAC19 3
+#define CADAC20 4
+#define CADAC21 5
+#define CADAC22 6
+#define CADAC23 7
+
+#define CADAC3 _SFR_MEM8(0xE3)
+#define CADAC24 0
+#define CADAC25 1
+#define CADAC26 2
+#define CADAC27 3
+#define CADAC28 4
+#define CADAC29 5
+#define CADAC30 6
+#define CADAC31 7
+
+#define CADCSRA _SFR_MEM8(0xE4)
+#define CADSE 0
+#define CADSI0 1
+#define CADSI1 2
+#define CADAS0 3
+#define CADAS1 4
+#define CADUB 5
+#define CADPOL 6
+#define CADEN 7
+
+#define CADCSRB _SFR_MEM8(0xE5)
+#define CADICIF 0
+#define CADRCIF 1
+#define CADACIF 2
+#define CADICIE 4
+#define CADRCIE 5
+#define CADACIE 6
+
+#define CADRC _SFR_MEM8(0xE6)
+#define CADRC0 0
+#define CADRC1 1
+#define CADRC2 2
+#define CADRC3 3
+#define CADRC4 4
+#define CADRC5 5
+#define CADRC6 6
+#define CADRC7 7
+
+#define CADIC _SFR_MEM16(0xE8)
+
+#define CADICL _SFR_MEM8(0xE8)
+#define CADICL0 0
+#define CADICL1 1
+#define CADICL2 2
+#define CADICL3 3
+#define CADICL4 4
+#define CADICL5 5
+#define CADICL6 6
+#define CADICL7 7
+
+#define CADICH _SFR_MEM8(0xE9)
+#define CADICH0 0
+#define CADICH1 1
+#define CADICH2 2
+#define CADICH3 3
+#define CADICH4 4
+#define CADICH5 5
+#define CADICH6 6
+#define CADICH7 7
+
+#define FCSR _SFR_MEM8(0xF0)
+#define CFE 0
+#define DFE 1
+#define CPS 2
+#define DUVRD 3
+
+#define BPIMSK _SFR_MEM8(0xF2)
+#define CHCIE 0
+#define DHCIE 1
+#define COCIE 2
+#define DOCIE 3
+#define SCIE 4
+
+#define BPIFR _SFR_MEM8(0xF3)
+#define CHCIF 0
+#define DHCIF 1
+#define COCIF 2
+#define DOCIF 3
+#define SCIF 4
+
+#define BPSCD _SFR_MEM8(0xF5)
+#define SCDL0 0
+#define SCDL1 1
+#define SCDL2 2
+#define SCDL3 3
+#define SCDL4 4
+#define SCDL5 5
+#define SCDL6 6
+#define SCDL7 7
+
+#define BPDOCD _SFR_MEM8(0xF6)
+#define DOCDL0 0
+#define DOCDL1 1
+#define DOCDL2 2
+#define DOCDL3 3
+#define DOCDL4 4
+#define DOCDL5 5
+#define DOCDL6 6
+#define DOCDL7 7
+
+#define BPCOCD _SFR_MEM8(0xF7)
+#define COCDL0 0
+#define COCDL1 1
+#define COCDL2 2
+#define COCDL3 3
+#define COCDL4 4
+#define COCDL5 5
+#define COCDL6 6
+#define COCDL7 7
+
+#define BPDHCD _SFR_MEM8(0xF8)
+#define DHCDL0 0
+#define DHCDL1 1
+#define DHCDL2 2
+#define DHCDL3 3
+#define DHCDL4 4
+#define DHCDL5 5
+#define DHCDL6 6
+#define DHCDL7 7
+
+#define BPCHCD _SFR_MEM8(0xF9)
+#define CHCDL0 0
+#define CHCDL1 1
+#define CHCDL2 2
+#define CHCDL3 3
+#define CHCDL4 4
+#define CHCDL5 5
+#define CHCDL6 6
+#define CHCDL7 7
+
+#define BPSCTR _SFR_MEM8(0xFA)
+#define SCPT0 0
+#define SCPT1 1
+#define SCPT2 2
+#define SCPT3 3
+#define SCPT4 4
+#define SCPT5 5
+#define SCPT6 6
+
+#define BPOCTR _SFR_MEM8(0xFB)
+#define OCPT0 0
+#define OCPT1 1
+#define OCPT2 2
+#define OCPT3 3
+#define OCPT4 4
+#define OCPT5 5
+
+#define BPHCTR _SFR_MEM8(0xFC)
+#define HCPT0 0
+#define HCPT1 1
+#define HCPT2 2
+#define HCPT3 3
+#define HCPT4 4
+#define HCPT5 5
+
+#define BPCR _SFR_MEM8(0xFD)
+#define CHCD 0
+#define DHCD 1
+#define COCD 2
+#define DOCD 3
+#define SCD 4
+#define PRMD 7
+
+#define BPPLR _SFR_MEM8(0xFE)
+#define BPPL 0
+#define BPPLE 1
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define BPINT_vect_num 1
+#define BPINT_vect _VECTOR(1) /* Battery Protection Interrupt */
+#define VREGMON_vect_num 2
+#define VREGMON_vect _VECTOR(2) /* Voltage regulator monitor interrupt */
+#define INT0_vect_num 3
+#define INT0_vect _VECTOR(3) /* External Interrupt Request 0 */
+#define INT1_vect_num 4
+#define INT1_vect _VECTOR(4) /* External Interrupt Request 1 */
+#define INT2_vect_num 5
+#define INT2_vect _VECTOR(5) /* External Interrupt Request 2 */
+#define PCINT0_vect_num 6
+#define PCINT0_vect _VECTOR(6) /* Pin Change Interrupt Request 0 */
+#define WDT_vect_num 7
+#define WDT_vect _VECTOR(7) /* Watchdog Timeout Interrupt */
+#define TIMER1_IC_vect_num 8
+#define TIMER1_IC_vect _VECTOR(8) /* Timer 1 Input capture */
+#define TIMER1_COMPA_vect_num 9
+#define TIMER1_COMPA_vect _VECTOR(9) /* Timer 1 Compare Match A */
+#define TIMER1_COMPB_vect_num 10
+#define TIMER1_COMPB_vect _VECTOR(10) /* Timer 1 Compare Match B */
+#define TIMER1_OVF_vect_num 11
+#define TIMER1_OVF_vect _VECTOR(11) /* Timer 1 overflow */
+#define TIMER0_IC_vect_num 12
+#define TIMER0_IC_vect _VECTOR(12) /* Timer 0 Input Capture */
+#define TIMER0_COMPA_vect_num 13
+#define TIMER0_COMPA_vect _VECTOR(13) /* Timer 0 Comapre Match A */
+#define TIMER0_COMPB_vect_num 14
+#define TIMER0_COMPB_vect _VECTOR(14) /* Timer 0 Compare Match B */
+#define TIMER0_OVF_vect_num 15
+#define TIMER0_OVF_vect _VECTOR(15) /* Timer 0 Overflow */
+#define SPI;STC_vect_num 16
+#define SPI;STC_vect _VECTOR(16) /* SPI Serial transfer complete */
+#define VADC_vect_num 17
+#define VADC_vect _VECTOR(17) /* Voltage ADC Conversion Complete */
+#define CCADC_CONV_vect_num 18
+#define CCADC_CONV_vect _VECTOR(18) /* Coulomb Counter ADC Conversion Complete */
+#define CCADC_REG_CUR_vect_num 19
+#define CCADC_REG_CUR_vect _VECTOR(19) /* Coloumb Counter ADC Regular Current */
+#define CCADC_ACC_vect_num 20
+#define CCADC_ACC_vect _VECTOR(20) /* Coloumb Counter ADC Accumulator */
+#define EE_READY_vect_num 21
+#define EE_READY_vect _VECTOR(21) /* EEPROM Ready */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (22 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (NA)
+#define XRAMEND (RAMEND)
+#define E2END (0xFF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_SUT0 (unsigned char)~_BV(0) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(1) /* Select start-up time */
+#define FUSE_SUT2 (unsigned char)~_BV(2) /* Select start-up time */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(3) /* Enable self programming */
+#define FUSE_DWEN (unsigned char)~_BV(4) /* Enable debugWIRE */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_EESAVE (unsigned char)~_BV(6) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(7) /* Watchdog Timer Always On */
+#define LFUSE_DEFAULT (FUSE_SPIEN)
+
+/* High Fuse Byte */
+#define FUSE_OSCSEL0 (unsigned char)~_BV(0) /* Oscillator Select 0 */
+#define FUSE_OSCSEL1 (unsigned char)~_BV(1) /* Oscillator Select 1 */
+#define FUSE_COMPMODE (unsigned char)~_BV(2) /* Compatibility mode */
+#define HFUSE_DEFAULT (FUSE_COMPMODE & FUSE_OSCSEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x0E
+
+
+/* Device Pin Definitions */
+#define PV2_DDR DDRV
+#define PV2_PORT PORTV
+#define PV2_PIN PINV
+#define PV2_BIT 2
+
+#define PV1_DDR DDRV
+#define PV1_PORT PORTV
+#define PV1_PIN PINV
+#define PV1_BIT 1
+
+#define NV_DDR DDRNV
+#define NV_PORT PORTNV
+#define NV_PIN PINNV
+#define NV_BIT NV
+
+#define VFET_DDR DDRVFET
+#define VFET_PORT PORTVFET
+#define VFET_PIN PINVFET
+#define VFET_BIT VFET
+
+#define CF1P_DDR DDRCF1P
+#define CF1P_PORT PORTCF1P
+#define CF1P_PIN PINCF1P
+#define CF1P_BIT CF1P
+
+#define CF1N_DDR DDRCF1N
+#define CF1N_PORT PORTCF1N
+#define CF1N_PIN PINCF1N
+#define CF1N_BIT CF1N
+
+#define CF2P_DDR DDRCF2P
+#define CF2P_PORT PORTCF2P
+#define CF2P_PIN PINCF2P
+#define CF2P_BIT CF2P
+
+#define CF2N_DDR DDRCF2N
+#define CF2N_PORT PORTCF2N
+#define CF2N_PIN PINCF2N
+#define CF2N_BIT CF2N
+
+#define VREG_DDR DDRVREG
+#define VREG_PORT PORTVREG
+#define VREG_PIN PINVREG
+#define VREG_BIT VREG
+
+#define VREF_DDR DDRVREF
+#define VREF_PORT PORTVREF
+#define VREF_PIN PINVREF
+#define VREF_BIT VREF
+
+#define VREFGND_DDR DDRVREFGND
+#define VREFGND_PORT PORTVREFGND
+#define VREFGND_PIN PINVREFGND
+#define VREFGND_BIT VREFGND
+
+#define PI_DDR DDRI
+#define PI_PORT PORTI
+#define PI_PIN PINI
+#define PI_BIT
+
+#define NI_DDR DDRNI
+#define NI_PORT PORTNI
+#define NI_PIN PINNI
+#define NI_BIT NI
+
+#define PA0_DDR DDRA
+#define PA0_PORT PORTA
+#define PA0_PIN PINA
+#define PA0_BIT 0
+
+#define PA1_DDR DDRA
+#define PA1_PORT PORTA
+#define PA1_PIN PINA
+#define PA1_BIT 1
+
+#define PA2_DDR DDRA
+#define PA2_PORT PORTA
+#define PA2_PIN PINA
+#define PA2_BIT 2
+
+#define PB0_DDR DDRB
+#define PB0_PORT PORTB
+#define PB0_PIN PINB
+#define PB0_BIT 0
+
+#define PB1_DDR DDRB
+#define PB1_PORT PORTB
+#define PB1_PIN PINB
+#define PB1_BIT 1
+
+#define PB2_DDR DDRB
+#define PB2_PORT PORTB
+#define PB2_PIN PINB
+#define PB2_BIT 2
+
+#define PB3_DDR DDRB
+#define PB3_PORT PORTB
+#define PB3_PIN PINB
+#define PB3_BIT 3
+
+#define PC0_DDR DDRC
+#define PC0_PORT PORTC
+#define PC0_PIN PINC
+#define PC0_BIT 0
+
+#define BATT_DDR DDRBATT
+#define BATT_PORT PORTBATT
+#define BATT_PIN PINBATT
+#define BATT_BIT BATT
+
+#define OC_DDR DDROC
+#define OC_PORT PORTOC
+#define OC_PIN PINOC
+#define OC_BIT OC
+
+#endif /* _AVR_ATmega16HVA2_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom16hvb.h b/cpukit/score/cpu/avr/avr/iom16hvb.h
new file mode 100644
index 0000000000..94e95a57c1
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16hvb.h
@@ -0,0 +1,1039 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16hvb.h - definitions for ATmega16HVB */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16hvb.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega16HVB_H_
+#define _AVR_ATmega16HVB_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+#define ICF0 3
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 3
+
+#define OSICSR _SFR_IO8(0x17)
+#define OSIEN 0
+#define OSIST 1
+#define OSISEL0 4
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define ICS0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+
+#define TCNT0 _SFR_IO16(0x26)
+
+#define TCNT0L _SFR_IO8(0x26)
+#define TCNT0L0 0
+#define TCNT0L1 1
+#define TCNT0L2 2
+#define TCNT0L3 3
+#define TCNT0L4 4
+#define TCNT0L5 5
+#define TCNT0L6 6
+#define TCNT0L7 7
+
+#define TCNT0H _SFR_IO8(0x27)
+#define TCNT0H0 0
+#define TCNT0H1 1
+#define TCNT0H2 2
+#define TCNT0H3 3
+#define TCNT0H4 4
+#define TCNT0H5 5
+#define TCNT0H6 6
+#define TCNT0H7 7
+
+#define OCR0A _SFR_IO8(0x28)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+#define OCR0B _SFR_IO8(0x29)
+#define OCR0B0 0
+#define OCR0B1 1
+#define OCR0B2 2
+#define OCR0B3 3
+#define OCR0B4 4
+#define OCR0B5 5
+#define OCR0B6 6
+#define OCR0B7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BODRF 2
+#define WDRF 3
+#define OCDRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define CKOE 5
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define LBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRVADC 0
+#define PRTIM0 1
+#define PRTIM1 2
+#define PRSPI 3
+#define PRVRM 5
+#define PRTWI 6
+
+#define FOSCCAL _SFR_MEM8(0x66)
+#define FCAL0 0
+#define FCAL1 1
+#define FCAL2 2
+#define FCAL3 3
+#define FCAL4 4
+#define FCAL5 5
+#define FCAL6 6
+#define FCAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT4 0
+#define PCINT5 1
+#define PCINT6 2
+#define PCINT7 3
+#define PCINT8 4
+#define PCINT9 5
+#define PCINT10 6
+#define PCINT11 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+#define ICIE0 3
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 3
+
+#define VADC _SFR_MEM16(0x78)
+
+#define VADCL _SFR_MEM8(0x78)
+#define VADC0 0
+#define VADC1 1
+#define VADC2 2
+#define VADC3 3
+#define VADC4 4
+#define VADC5 5
+#define VADC6 6
+#define VADC7 7
+
+#define VADCH _SFR_MEM8(0x79)
+#define VADC8 0
+#define VADC9 1
+#define VADC10 2
+#define VADC11 3
+
+#define VADCSR _SFR_MEM8(0x7A)
+#define VADCCIE 0
+#define VADCCIF 1
+#define VADSC 2
+#define VADEN 3
+
+#define VADMUX _SFR_MEM8(0x7C)
+#define VADMUX0 0
+#define VADMUX1 1
+#define VADMUX2 2
+#define VADMUX3 3
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define PA0DID 0
+#define PA1DID 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define ICS1 3
+#define ICES1 4
+#define ICNC1 5
+#define ICEN1 6
+#define TCW1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define OCR1A _SFR_MEM8(0x88)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define OCR1B _SFR_MEM8(0x89)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define TWBCSR _SFR_MEM8(0xBE)
+#define TWBCIP 0
+#define TWBDT0 1
+#define TWBDT1 2
+#define TWBCIE 6
+#define TWBCIF 7
+
+#define ROCR _SFR_MEM8(0xC8)
+#define ROCWIE 0
+#define ROCWIF 1
+#define ROCD 4
+#define ROCS 7
+
+#define BGCCR _SFR_MEM8(0xD0)
+#define BGCC0 0
+#define BGCC1 1
+#define BGCC2 2
+#define BGCC3 3
+#define BGCC4 4
+#define BGCC5 5
+
+#define BGCRR _SFR_MEM8(0xD1)
+#define BGCR0 0
+#define BGCR1 1
+#define BGCR2 2
+#define BGCR3 3
+#define BGCR4 4
+#define BGCR5 5
+#define BGCR6 6
+#define BGCR7 7
+
+#define BGCSR _SFR_MEM8(0xD2)
+#define BGSCDIE 0
+#define BGSCDIF 1
+#define BGSCDE 4
+#define BGD 5
+
+#define CHGDCSR _SFR_MEM8(0xD4)
+#define CHGDIE 0
+#define CHGDIF 1
+#define CHGDISC0 2
+#define CHGDISC1 3
+#define BATTPVL 4
+
+#define CADAC0 _SFR_MEM8(0xE0)
+#define CADAC00 0
+#define CADAC01 1
+#define CADAC02 2
+#define CADAC03 3
+#define CADAC04 4
+#define CADAC05 5
+#define CADAC06 6
+#define CADAC07 7
+
+#define CADAC1 _SFR_MEM8(0xE1)
+#define CADAC08 0
+#define CADAC09 1
+#define CADAC10 2
+#define CADAC11 3
+#define CADAC12 4
+#define CADAC13 5
+#define CADAC14 6
+#define CADAC15 7
+
+#define CADAC2 _SFR_MEM8(0xE2)
+#define CADAC16 0
+#define CADAC17 1
+#define CADAC18 2
+#define CADAC19 3
+#define CADAC20 4
+#define CADAC21 5
+#define CADAC22 6
+#define CADAC23 7
+
+#define CADAC3 _SFR_MEM8(0xE3)
+#define CADAC24 0
+#define CADAC25 1
+#define CADAC26 2
+#define CADAC27 3
+#define CADAC28 4
+#define CADAC29 5
+#define CADAC30 6
+#define CADAC31 7
+
+#define CADIC _SFR_MEM16(0xE4)
+
+#define CADICL _SFR_MEM8(0xE4)
+#define CADICL0 0
+#define CADICL1 1
+#define CADICL2 2
+#define CADICL3 3
+#define CADICL4 4
+#define CADICL5 5
+#define CADICL6 6
+#define CADICL7 7
+
+#define CADICH _SFR_MEM8(0xE5)
+#define CADICH0 0
+#define CADICH1 1
+#define CADICH2 2
+#define CADICH3 3
+#define CADICH4 4
+#define CADICH5 5
+#define CADICH6 6
+#define CADICH7 7
+
+#define CADCSRA _SFR_MEM8(0xE6)
+#define CADSE 0
+#define CADSI0 1
+#define CADSI1 2
+#define CADAS0 3
+#define CADAS1 4
+#define CADUB 5
+#define CADPOL 6
+#define CADEN 7
+
+#define CADCSRB _SFR_MEM8(0xE7)
+#define CADICIF 0
+#define CADRCIF 1
+#define CADACIF 2
+#define CADICIE 4
+#define CADRCIE 5
+#define CADACIE 6
+
+#define CADCSRC _SFR_MEM8(0xE8)
+#define CADVSE 0
+
+#define CADRCC _SFR_MEM8(0xE9)
+#define CADRCC0 0
+#define CADRCC1 1
+#define CADRCC2 2
+#define CADRCC3 3
+#define CADRCC4 4
+#define CADRCC5 5
+#define CADRCC6 6
+#define CADRCC7 7
+
+#define CADRDC _SFR_MEM8(0xEA)
+#define CADRDC0 0
+#define CADRDC1 1
+#define CADRDC2 2
+#define CADRDC3 3
+#define CADRDC4 4
+#define CADRDC5 5
+#define CADRDC6 6
+#define CADRDC7 7
+
+#define FCSR _SFR_MEM8(0xF0)
+#define CFE 0
+#define DFE 1
+#define CPS 2
+#define DUVRD 3
+
+#define CBCR _SFR_MEM8(0xF1)
+#define CBE1 0
+#define CBE2 1
+#define CBE3 2
+#define CBE4 3
+
+#define BPIMSK _SFR_MEM8(0xF2)
+#define CHCIE 0
+#define DHCIE 1
+#define COCIE 2
+#define DOCIE 3
+#define SCIE 4
+
+#define BPIFR _SFR_MEM8(0xF3)
+#define CHCIF 0
+#define DHCIF 1
+#define COCIF 2
+#define DOCIF 3
+#define SCIF 4
+
+#define BPSCD _SFR_MEM8(0xF5)
+#define SCDL0 0
+#define SCDL1 1
+#define SCDL2 2
+#define SCDL3 3
+#define SCDL4 4
+#define SCDL5 5
+#define SCDL6 6
+#define SCDL7 7
+
+#define BPDOCD _SFR_MEM8(0xF6)
+#define DOCDL0 0
+#define DOCDL1 1
+#define DOCDL2 2
+#define DOCDL3 3
+#define DOCDL4 4
+#define DOCDL5 5
+#define DOCDL6 6
+#define DOCDL7 7
+
+#define BPCOCD _SFR_MEM8(0xF7)
+#define COCDL0 0
+#define COCDL1 1
+#define COCDL2 2
+#define COCDL3 3
+#define COCDL4 4
+#define COCDL5 5
+#define COCDL6 6
+#define COCDL7 7
+
+#define BPDHCD _SFR_MEM8(0xF8)
+#define DHCDL0 0
+#define DHCDL1 1
+#define DHCDL2 2
+#define DHCDL3 3
+#define DHCDL4 4
+#define DHCDL5 5
+#define DHCDL6 6
+#define DHCDL7 7
+
+#define BPCHCD _SFR_MEM8(0xF9)
+#define CHCDL0 0
+#define CHCDL1 1
+#define CHCDL2 2
+#define CHCDL3 3
+#define CHCDL4 4
+#define CHCDL5 5
+#define CHCDL6 6
+#define CHCDL7 7
+
+#define BPSCTR _SFR_MEM8(0xFA)
+#define SCPT0 0
+#define SCPT1 1
+#define SCPT2 2
+#define SCPT3 3
+#define SCPT4 4
+#define SCPT5 5
+#define SCPT6 6
+
+#define BPOCTR _SFR_MEM8(0xFB)
+#define OCPT0 0
+#define OCPT1 1
+#define OCPT2 2
+#define OCPT3 3
+#define OCPT4 4
+#define OCPT5 5
+
+#define BPHCTR _SFR_MEM8(0xFC)
+#define HCPT0 0
+#define HCPT1 1
+#define HCPT2 2
+#define HCPT3 3
+#define HCPT4 4
+#define HCPT5 5
+
+#define BPCR _SFR_MEM8(0xFD)
+#define CHCD 0
+#define DHCD 1
+#define COCD 2
+#define DOCD 3
+#define SCD 4
+#define EPID 5
+
+#define BPPLR _SFR_MEM8(0xFE)
+#define BPPL 0
+#define BPPLE 1
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define BPINT_vect_num 1
+#define BPINT_vect _VECTOR(1) /* Battery Protection Interrupt */
+#define VREGMON_vect_num 2
+#define VREGMON_vect _VECTOR(2) /* Voltage regulator monitor interrupt */
+#define INT0_vect_num 3
+#define INT0_vect _VECTOR(3) /* External Interrupt Request 0 */
+#define INT1_vect_num 4
+#define INT1_vect _VECTOR(4) /* External Interrupt Request 1 */
+#define INT2_vect_num 5
+#define INT2_vect _VECTOR(5) /* External Interrupt Request 2 */
+#define INT3_vect_num 6
+#define INT3_vect _VECTOR(6) /* External Interrupt Request 3 */
+#define PCINT0_vect_num 7
+#define PCINT0_vect _VECTOR(7) /* Pin Change Interrupt 0 */
+#define PCINT1_vect_num 8
+#define PCINT1_vect _VECTOR(8) /* Pin Change Interrupt 1 */
+#define WDT_vect_num 9
+#define WDT_vect _VECTOR(9) /* Watchdog Timeout Interrupt */
+#define BGSCD_vect_num 10
+#define BGSCD_vect _VECTOR(10) /* Bandgap Buffer Short Circuit Detected */
+#define CHDET_vect_num 11
+#define CHDET_vect _VECTOR(11) /* Charger Detect */
+#define TIMER1_IC_vect_num 12
+#define TIMER1_IC_vect _VECTOR(12) /* Timer 1 Input capture */
+#define TIMER1_COMPA_vect_num 13
+#define TIMER1_COMPA_vect _VECTOR(13) /* Timer 1 Compare Match A */
+#define TIMER1_COMPB_vect_num 14
+#define TIMER1_COMPB_vect _VECTOR(14) /* Timer 1 Compare Match B */
+#define TIMER1_OVF_vect_num 15
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer 1 overflow */
+#define TIMER0_IC_vect_num 16
+#define TIMER0_IC_vect _VECTOR(16) /* Timer 0 Input Capture */
+#define TIMER0_COMPA_vect_num 17
+#define TIMER0_COMPA_vect _VECTOR(17) /* Timer 0 Comapre Match A */
+#define TIMER0_COMPB_vect_num 18
+#define TIMER0_COMPB_vect _VECTOR(18) /* Timer 0 Compare Match B */
+#define TIMER0_OVF_vect_num 19
+#define TIMER0_OVF_vect _VECTOR(19) /* Timer 0 Overflow */
+#define TWIBUSCD_vect_num 20
+#define TWIBUSCD_vect _VECTOR(20) /* Two-Wire Bus Connect/Disconnect */
+#define TWI_vect_num 21
+#define TWI_vect _VECTOR(21) /* Two-Wire Serial Interface */
+#define SPI_STC_vect_num 22
+#define SPI_STC_vect _VECTOR(22) /* SPI Serial transfer complete */
+#define VADC_vect_num 23
+#define VADC_vect _VECTOR(23) /* Voltage ADC Conversion Complete */
+#define CCADC_CONV_vect_num 24
+#define CCADC_CONV_vect _VECTOR(24) /* Coulomb Counter ADC Conversion Complete */
+#define CCADC_REG_CUR_vect_num 25
+#define CCADC_REG_CUR_vect _VECTOR(25) /* Coloumb Counter ADC Regular Current */
+#define CCADC_ACC_vect_num 26
+#define CCADC_ACC_vect _VECTOR(26) /* Coloumb Counter ADC Accumulator */
+#define EE_READY_vect_num 27
+#define EE_READY_vect _VECTOR(27) /* EEPROM Ready */
+#define SPM_vect_num 28
+#define SPM_vect _VECTOR(28) /* SPM Ready */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (29 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (NA)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_OSCSEL0 (unsigned char)~_BV(0) /* Oscillator Select */
+#define FUSE_OSCSEL1 (unsigned char)~_BV(1) /* Oscillator Select */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Select start-up time */
+#define FUSE_SUT2 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_EESAVE (unsigned char)~_BV(6) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(7) /* Watchdog Timer Always On */
+#define LFUSE_DEFAULT (FUSE_SPIEN & FUSE_OSCSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_DWEN (unsigned char)~_BV(3) /* Enable debugWire */
+#define FUSE_DUVRDINIT (unsigned char)~_BV(4) /* Reset Value of DUVRDRegister */
+#define HFUSE_DEFAULT (FUSE_DUVRDINIT & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x0D
+
+
+/* Device Pin Definitions */
+#define PV2_DDR DDRV
+#define PV2_PORT PORTV
+#define PV2_PIN PINV
+#define PV2_BIT 2
+
+#define PV1_DDR DDRV
+#define PV1_PORT PORTV
+#define PV1_PIN PINV
+#define PV1_BIT 1
+
+#define NV_DDR DDRNV
+#define NV_PORT PORTNV
+#define NV_PIN PINNV
+#define NV_BIT NV
+
+#define VFET_DDR DDRVFET
+#define VFET_PORT PORTVFET
+#define VFET_PIN PINVFET
+#define VFET_BIT VFET
+
+#define CF1P_DDR DDRCF1P
+#define CF1P_PORT PORTCF1P
+#define CF1P_PIN PINCF1P
+#define CF1P_BIT CF1P
+
+#define CF1N_DDR DDRCF1N
+#define CF1N_PORT PORTCF1N
+#define CF1N_PIN PINCF1N
+#define CF1N_BIT CF1N
+
+#define CF2P_DDR DDRCF2P
+#define CF2P_PORT PORTCF2P
+#define CF2P_PIN PINCF2P
+#define CF2P_BIT CF2P
+
+#define CF2N_DDR DDRCF2N
+#define CF2N_PORT PORTCF2N
+#define CF2N_PIN PINCF2N
+#define CF2N_BIT CF2N
+
+#define VREG_DDR DDRVREG
+#define VREG_PORT PORTVREG
+#define VREG_PIN PINVREG
+#define VREG_BIT VREG
+
+#define VREF_DDR DDRVREF
+#define VREF_PORT PORTVREF
+#define VREF_PIN PINVREF
+#define VREF_BIT VREF
+
+#define VREFGND_DDR DDRVREFGND
+#define VREFGND_PORT PORTVREFGND
+#define VREFGND_PIN PINVREFGND
+#define VREFGND_BIT VREFGND
+
+#define PI_DDR DDRI
+#define PI_PORT PORTI
+#define PI_PIN PINI
+#define PI_BIT
+
+#define NI_DDR DDRNI
+#define NI_PORT PORTNI
+#define NI_PIN PINNI
+#define NI_BIT NI
+
+#define PA0_DDR DDRA
+#define PA0_PORT PORTA
+#define PA0_PIN PINA
+#define PA0_BIT 0
+
+#define PA1_DDR DDRA
+#define PA1_PORT PORTA
+#define PA1_PIN PINA
+#define PA1_BIT 1
+
+#define PA2_DDR DDRA
+#define PA2_PORT PORTA
+#define PA2_PIN PINA
+#define PA2_BIT 2
+
+#define PB0_DDR DDRB
+#define PB0_PORT PORTB
+#define PB0_PIN PINB
+#define PB0_BIT 0
+
+#define PB1_DDR DDRB
+#define PB1_PORT PORTB
+#define PB1_PIN PINB
+#define PB1_BIT 1
+
+#define PB2_DDR DDRB
+#define PB2_PORT PORTB
+#define PB2_PIN PINB
+#define PB2_BIT 2
+
+#define PB3_DDR DDRB
+#define PB3_PORT PORTB
+#define PB3_PIN PINB
+#define PB3_BIT 3
+
+#define PC0_DDR DDRC
+#define PC0_PORT PORTC
+#define PC0_PIN PINC
+#define PC0_BIT 0
+
+#define BATT_DDR DDRBATT
+#define BATT_PORT PORTBATT
+#define BATT_PIN PINBATT
+#define BATT_BIT BATT
+
+#define OC_DDR DDROC
+#define OC_PORT PORTOC
+#define OC_PIN PINOC
+#define OC_BIT OC
+
+#endif /* _AVR_ATmega16HVB_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom16m1.h b/cpukit/score/cpu/avr/avr/iom16m1.h
new file mode 100644
index 0000000000..5e073b6d9c
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16m1.h
@@ -0,0 +1,1548 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16m1.h - definitions for ATmega16M1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16m1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega16M1_H_
+#define _AVR_ATmega16M1_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 6
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC3O 3
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define AC3IF 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRLIN 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC 5
+#define PRCAN 6
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6A)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6B)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6C)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define PCMSK3 _SFR_MEM8(0x6D)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x75)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0TS2 2
+#define AMPCMP0 3
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x76)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1TS2 2
+#define AMPCMP1 3
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#define AMP2CSR _SFR_MEM8(0x77)
+#define AMP2TS0 0
+#define AMP2TS1 1
+#define AMP2TS2 2
+#define AMPCMP2 3
+#define AMP2G0 4
+#define AMP2G1 5
+#define AMP2IS 6
+#define AMP2EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define AREFEN 5
+#define ISRCEN 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+#define AMP2PD 6
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define DACON _SFR_MEM8(0x90)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0x91)
+
+#define DACL _SFR_MEM8(0x91)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0x92)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0x94)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define ACCKSEL 3
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0x95)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0x96)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define AC3CON _SFR_MEM8(0x97)
+#define AC3M0 0
+#define AC3M1 1
+#define AC3M2 2
+#define AC3IS0 4
+#define AC3IS1 5
+#define AC3IE 6
+#define AC3EN 7
+
+#define POCR0SA _SFR_MEM16(0xA0)
+
+#define POCR0SAL _SFR_MEM8(0xA0)
+#define POCR0SA_0 0
+#define POCR0SA_1 1
+#define POCR0SA_2 2
+#define POCR0SA_3 3
+#define POCR0SA_4 4
+#define POCR0SA_5 5
+#define POCR0SA_6 6
+#define POCR0SA_7 7
+
+#define POCR0SAH _SFR_MEM8(0xA1)
+#define POCR0SA_8 0
+#define POCR0SA_9 1
+#define POCR0SA_10 2
+#define POCR0SA_11 3
+
+#define POCR0RA _SFR_MEM16(0xA2)
+
+#define POCR0RAL _SFR_MEM8(0xA2)
+#define POCR0RA_0 0
+#define POCR0RA_1 1
+#define POCR0RA_2 2
+#define POCR0RA_3 3
+#define POCR0RA_4 4
+#define POCR0RA_5 5
+#define POCR0RA_6 6
+#define POCR0RA_7 7
+
+#define POCR0RAH _SFR_MEM8(0xA3)
+#define POCR0RA_8 0
+#define POCR0RA_9 1
+#define POCR0RA_10 2
+#define POCR0RA_11 3
+
+#define POCR0SB _SFR_MEM16(0xA4)
+
+#define POCR0SBL _SFR_MEM8(0xA4)
+#define POCR0SB_0 0
+#define POCR0SB_1 1
+#define POCR0SB_2 2
+#define POCR0SB_3 3
+#define POCR0SB_4 4
+#define POCR0SB_5 5
+#define POCR0SB_6 6
+#define POCR0SB_7 7
+
+#define POCR0SBH _SFR_MEM8(0xA5)
+#define POCR0SB_8 0
+#define POCR0SB_9 1
+#define POCR0SB_10 2
+#define POCR0SB_11 3
+
+#define POCR1SA _SFR_MEM16(0xA6)
+
+#define POCR1SAL _SFR_MEM8(0xA6)
+#define POCR1SA_0 0
+#define POCR1SA_1 1
+#define POCR1SA_2 2
+#define POCR1SA_3 3
+#define POCR1SA_4 4
+#define POCR1SA_5 5
+#define POCR1SA_6 6
+#define POCR1SA_7 7
+
+#define POCR1SAH _SFR_MEM8(0xA7)
+#define POCR1SA_8 0
+#define POCR1SA_9 1
+#define POCR1SA_10 2
+#define POCR1SA_11 3
+
+#define POCR1RA _SFR_MEM16(0xA8)
+
+#define POCR1RAL _SFR_MEM8(0xA8)
+#define POCR1RA_0 0
+#define POCR1RA_1 1
+#define POCR1RA_2 2
+#define POCR1RA_3 3
+#define POCR1RA_4 4
+#define POCR1RA_5 5
+#define POCR1RA_6 6
+#define POCR1RA_7 7
+
+#define POCR1RAH _SFR_MEM8(0xA9)
+#define POCR1RA_8 0
+#define POCR1RA_9 1
+#define POCR1RA_10 2
+#define POCR1RA_11 3
+
+#define POCR1SB _SFR_MEM16(0xAA)
+
+#define POCR1SBL _SFR_MEM8(0xAA)
+#define POCR1SB_0 0
+#define POCR1SB_1 1
+#define POCR1SB_2 2
+#define POCR1SB_3 3
+#define POCR1SB_4 4
+#define POCR1SB_5 5
+#define POCR1SB_6 6
+#define POCR1SB_7 7
+
+#define POCR1SBH _SFR_MEM8(0xAB)
+#define POCR1SB_8 0
+#define POCR1SB_9 1
+#define POCR1SB_10 2
+#define POCR1SB_11 3
+
+#define POCR2SA _SFR_MEM16(0xAC)
+
+#define POCR2SAL _SFR_MEM8(0xAC)
+#define POCR2SA_0 0
+#define POCR2SA_1 1
+#define POCR2SA_2 2
+#define POCR2SA_3 3
+#define POCR2SA_4 4
+#define POCR2SA_5 5
+#define POCR2SA_6 6
+#define POCR2SA_7 7
+
+#define POCR2SAH _SFR_MEM8(0xAD)
+#define POCR2SA_8 0
+#define POCR2SA_9 1
+#define POCR2SA_10 2
+#define POCR2SA_11 3
+
+#define POCR2RA _SFR_MEM16(0xAE)
+
+#define POCR2RAL _SFR_MEM8(0xAE)
+#define POCR2RA_0 0
+#define POCR2RA_1 1
+#define POCR2RA_2 2
+#define POCR2RA_3 3
+#define POCR2RA_4 4
+#define POCR2RA_5 5
+#define POCR2RA_6 6
+#define POCR2RA_7 7
+
+#define POCR2RAH _SFR_MEM8(0xAF)
+#define POCR2RA_8 0
+#define POCR2RA_9 1
+#define POCR2RA_10 2
+#define POCR2RA_11 3
+
+#define POCR2SB _SFR_MEM16(0xB0)
+
+#define POCR2SBL _SFR_MEM8(0xB0)
+#define POCR2SB_0 0
+#define POCR2SB_1 1
+#define POCR2SB_2 2
+#define POCR2SB_3 3
+#define POCR2SB_4 4
+#define POCR2SB_5 5
+#define POCR2SB_6 6
+#define POCR2SB_7 7
+
+#define POCR2SBH _SFR_MEM8(0xB1)
+#define POCR2SB_8 0
+#define POCR2SB_9 1
+#define POCR2SB_10 2
+#define POCR2SB_11 3
+
+#define POCR_RB _SFR_MEM16(0xB2)
+
+#define POCR_RBL _SFR_MEM8(0xB2)
+#define POCR_RB_0 0
+#define POCR_RB_1 1
+#define POCR_RB_2 2
+#define POCR_RB_3 3
+#define POCR_RB_4 4
+#define POCR_RB_5 5
+#define POCR_RB_6 6
+#define POCR_RB_7 7
+
+#define POCR_RBH _SFR_MEM8(0xB3)
+#define POCR_RB_8 0
+#define POCR_RB_9 1
+#define POCR_RB_10 2
+#define POCR_RB_11 3
+
+#define PSYNC _SFR_MEM8(0xB4)
+#define PSYNC00 0
+#define PSYNC01 1
+#define PSYNC10 2
+#define PSYNC11 3
+#define PSYNC20 4
+#define PSYNC21 5
+
+#define PCNF _SFR_MEM8(0xB5)
+#define POPA 2
+#define POPB 3
+#define PMODE 4
+#define PULOCK 5
+
+#define POC _SFR_MEM8(0xB6)
+#define POEN0A 0
+#define POEN0B 1
+#define POEN1A 2
+#define POEN1B 3
+#define POEN2A 4
+#define POEN2B 5
+
+#define PCTL _SFR_MEM8(0xB7)
+#define PRUN 0
+#define PCCYC 1
+#define PCLKSEL 5
+#define PPRE0 6
+#define PPRE1 7
+
+#define PMIC0 _SFR_MEM8(0xB8)
+#define PRFM00 0
+#define PRFM01 1
+#define PRFM02 2
+#define PAOC0 3
+#define PFLTE0 4
+#define PELEV0 5
+#define PISEL0 6
+#define POVEN0 7
+
+#define PMIC1 _SFR_MEM8(0xB9)
+#define PRFM10 0
+#define PRFM11 1
+#define PRFM12 2
+#define PAOC1 3
+#define PFLTE1 4
+#define PELEV1 5
+#define PISEL1 6
+#define POVEN1 7
+
+#define PMIC2 _SFR_MEM8(0xBA)
+#define PRFM20 0
+#define PRFM21 1
+#define PRFM22 2
+#define PAOC2 3
+#define PFLTE2 4
+#define PELEV2 5
+#define PISEL2 6
+#define POVEN2 7
+
+#define PIM _SFR_MEM8(0xBB)
+#define PEOPE 0
+#define PEVE0 1
+#define PEVE1 2
+#define PEVE2 3
+
+#define PIFR _SFR_MEM8(0xBC)
+#define PEOP 0
+#define PEV0 1
+#define PEV1 2
+#define PEV2 3
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+#define CANGCON _SFR_MEM8(0xD8)
+#define SWRES 0
+#define ENASTB 1
+#define TEST 2
+#define LISTEN 3
+#define SYNTTC 4
+#define TTC 5
+#define OVRQ 6
+#define ABRQ 7
+
+#define CANGSTA _SFR_MEM8(0xD9)
+#define ERRP 0
+#define BOFF 1
+#define ENFG 2
+#define RXBSY 3
+#define TXBSY 4
+#define OVFG 6
+
+#define CANGIT _SFR_MEM8(0xDA)
+#define AERG 0
+#define FERG 1
+#define CERG 2
+#define SERG 3
+#define BXOK 4
+#define OVRTIM 5
+#define BOFFIT 6
+#define CANIT 7
+
+#define CANGIE _SFR_MEM8(0xDB)
+#define ENOVRT 0
+#define ENERG 1
+#define ENBX 2
+#define ENERR 3
+#define ENTX 4
+#define ENRX 5
+#define ENBOFF 6
+#define ENIT 7
+
+#define CANEN2 _SFR_MEM8(0xDC)
+#define ENMOB0 0
+#define ENMOB1 1
+#define ENMOB2 2
+#define ENMOB3 3
+#define ENMOB4 4
+#define ENMOB5 5
+
+#define CANEN1 _SFR_MEM8(0xDD)
+
+#define CANIE2 _SFR_MEM8(0xDE)
+#define IEMOB0 0
+#define IEMOB1 1
+#define IEMOB2 2
+#define IEMOB3 3
+#define IEMOB4 4
+#define IEMOB5 5
+
+#define CANIE1 _SFR_MEM8(0xDF)
+
+#define CANSIT2 _SFR_MEM8(0xE0)
+#define SIT0 0
+#define SIT1 1
+#define SIT2 2
+#define SIT3 3
+#define SIT4 4
+#define SIT5 5
+
+#define CANSIT1 _SFR_MEM8(0xE1)
+
+#define CANBT1 _SFR_MEM8(0xE2)
+#define BRP0 1
+#define BRP1 2
+#define BRP2 3
+#define BRP3 4
+#define BRP4 5
+#define BRP5 6
+
+#define CANBT2 _SFR_MEM8(0xE3)
+#define PRS0 1
+#define PRS1 2
+#define PRS2 3
+#define SJW0 5
+#define SJW1 6
+
+#define CANBT3 _SFR_MEM8(0xE4)
+#define SMP 0
+#define PHS10 1
+#define PHS11 2
+#define PHS12 3
+#define PHS20 4
+#define PHS21 5
+#define PHS22 6
+
+#define CANTCON _SFR_MEM8(0xE5)
+#define TPRSC0 0
+#define TPRSC1 1
+#define TPRSC2 2
+#define TPRSC3 3
+#define TPRSC4 4
+#define TPRSC5 5
+#define TPRSC6 6
+#define TPRSC7 7
+
+#define CANTIM _SFR_MEM16(0xE6)
+
+#define CANTIML _SFR_MEM8(0xE6)
+#define CANTIM0 0
+#define CANTIM1 1
+#define CANTIM2 2
+#define CANTIM3 3
+#define CANTIM4 4
+#define CANTIM5 5
+#define CANTIM6 6
+#define CANTIM7 7
+
+#define CANTIMH _SFR_MEM8(0xE7)
+#define CANTIM8 0
+#define CANTIM9 1
+#define CANTIM10 2
+#define CANTIM11 3
+#define CANTIM12 4
+#define CANTIM13 5
+#define CANTIM14 6
+#define CANTIM15 7
+
+#define CANTTC _SFR_MEM16(0xE8)
+
+#define CANTTCL _SFR_MEM8(0xE8)
+#define TIMTCC0 0
+#define TIMTCC1 1
+#define TIMTCC2 2
+#define TIMTCC3 3
+#define TIMTCC4 4
+#define TIMTCC5 5
+#define TIMTCC6 6
+#define TIMTCC7 7
+
+#define CANTTCH _SFR_MEM8(0xE9)
+#define TIMTCC8 0
+#define TIMTCC9 1
+#define TIMTCC10 2
+#define TIMTCC11 3
+#define TIMTCC12 4
+#define TIMTCC13 5
+#define TIMTCC14 6
+#define TIMTCC15 7
+
+#define CANTEC _SFR_MEM8(0xEA)
+#define TEC0 0
+#define TEC1 1
+#define TEC2 2
+#define TEC3 3
+#define TEC4 4
+#define TEC5 5
+#define TEC6 6
+#define TEC7 7
+
+#define CANREC _SFR_MEM8(0xEB)
+#define REC0 0
+#define REC1 1
+#define REC2 2
+#define REC3 3
+#define REC4 4
+#define REC5 5
+#define REC6 6
+#define REC7 7
+
+#define CANHPMOB _SFR_MEM8(0xEC)
+#define CGP0 0
+#define CGP1 1
+#define CGP2 2
+#define CGP3 3
+#define HPMOB0 4
+#define HPMOB1 5
+#define HPMOB2 6
+#define HPMOB3 7
+
+#define CANPAGE _SFR_MEM8(0xED)
+#define INDX0 0
+#define INDX1 1
+#define INDX2 2
+#define AINC 3
+#define MOBNB0 4
+#define MOBNB1 5
+#define MOBNB2 6
+#define MOBNB3 7
+
+#define CANSTMOB _SFR_MEM8(0xEE)
+#define AERR 0
+#define FERR 1
+#define CERR 2
+#define SERR 3
+#define BERR 4
+#define RXOK 5
+#define TXOK 6
+#define DLCW 7
+
+#define CANCDMOB _SFR_MEM8(0xEF)
+#define DLC0 0
+#define DLC1 1
+#define DLC2 2
+#define DLC3 3
+#define IDE 4
+#define RPLV 5
+#define CONMOB0 6
+#define CONMOB1 7
+
+#define CANIDT4 _SFR_MEM8(0xF0)
+#define RB0TAG 0
+#define RB1TAG 1
+#define RTRTAG 2
+#define IDT0 3
+#define IDT1 4
+#define IDT2 5
+#define IDT3 6
+#define IDT4 7
+
+#define CANIDT3 _SFR_MEM8(0xF1)
+#define IDT5 0
+#define IDT6 1
+#define IDT7 2
+#define IDT8 3
+#define IDT9 4
+#define IDT10 5
+#define IDT11 6
+#define IDT12 7
+
+#define CANIDT2 _SFR_MEM8(0xF2)
+#define IDT13 0
+#define IDT14 1
+#define IDT15 2
+#define IDT16 3
+#define IDT17 4
+#define IDT18 5
+#define IDT19 6
+#define IDT20 7
+
+#define CANIDT1 _SFR_MEM8(0xF3)
+#define IDT21 0
+#define IDT22 1
+#define IDT23 2
+#define IDT24 3
+#define IDT25 4
+#define IDT26 5
+#define IDT27 6
+#define IDT28 7
+
+#define CANIDM4 _SFR_MEM8(0xF4)
+#define IDEMSK 0
+#define RTRMSK 2
+#define IDMSK0 3
+#define IDMSK1 4
+#define IDMSK2 5
+#define IDMSK3 6
+#define IDMSK4 7
+
+#define CANIDM3 _SFR_MEM8(0xF5)
+#define IDMSK5 0
+#define IDMSK6 1
+#define IDMSK7 2
+#define IDMSK8 3
+#define IDMSK9 4
+#define IDMSK10 5
+#define IDMSK11 6
+#define IDMSK12 7
+
+#define CANIDM2 _SFR_MEM8(0xF6)
+#define IDMSK13 0
+#define IDMSK14 1
+#define IDMSK15 2
+#define IDMSK16 3
+#define IDMSK17 4
+#define IDMSK18 5
+#define IDMSK19 6
+#define IDMSK20 7
+
+#define CANIDM1 _SFR_MEM8(0xF7)
+#define IDMSK21 0
+#define IDMSK22 1
+#define IDMSK23 2
+#define IDMSK24 3
+#define IDMSK25 4
+#define IDMSK26 5
+#define IDMSK27 6
+#define IDMSK28 7
+
+#define CANSTM _SFR_MEM16(0xF8)
+
+#define CANSTML _SFR_MEM8(0xF8)
+#define TIMSTM0 0
+#define TIMSTM1 1
+#define TIMSTM2 2
+#define TIMSTM3 3
+#define TIMSTM4 4
+#define TIMSTM5 5
+#define TIMSTM6 6
+#define TIMSTM7 7
+
+#define CANSTMH _SFR_MEM8(0xF9)
+#define TIMSTM8 0
+#define TIMSTM9 1
+#define TIMSTM10 2
+#define TIMSTM11 3
+#define TIMSTM12 4
+#define TIMSTM13 5
+#define TIMSTM14 6
+#define TIMSTM15 7
+
+#define CANMSG _SFR_MEM8(0xFA)
+#define MSG0 0
+#define MSG1 1
+#define MSG2 2
+#define MSG3 3
+#define MSG4 4
+#define MSG5 5
+#define MSG6 6
+#define MSG7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define ANACOMP0_vect_num 1
+#define ANACOMP0_vect _VECTOR(1) /* Analog Comparator 0 */
+#define ANACOMP1_vect_num 2
+#define ANACOMP1_vect _VECTOR(2) /* Analog Comparator 1 */
+#define ANACOMP2_vect_num 3
+#define ANACOMP2_vect _VECTOR(3) /* Analog Comparator 2 */
+#define ANACOMP3_vect_num 4
+#define ANACOMP3_vect _VECTOR(4) /* Analog Comparator 3 */
+#define PSC_FAULT_vect_num 5
+#define PSC_FAULT_vect _VECTOR(5) /* PSC Fault */
+#define PSC_EC_vect_num 6
+#define PSC_EC_vect _VECTOR(6) /* PSC End of Cycle */
+#define INT0_vect_num 7
+#define INT0_vect _VECTOR(7) /* External Interrupt Request 0 */
+#define INT1_vect_num 8
+#define INT1_vect _VECTOR(8) /* External Interrupt Request 1 */
+#define INT2_vect_num 9
+#define INT2_vect _VECTOR(9) /* External Interrupt Request 2 */
+#define INT3_vect_num 10
+#define INT3_vect _VECTOR(10) /* External Interrupt Request 3 */
+#define TIMER1_CAPT_vect_num 11
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 12
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 13
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 14
+#define TIMER1_OVF_vect _VECTOR(14) /* Timer1/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 15
+#define TIMER0_COMPA_vect _VECTOR(15) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 16
+#define TIMER0_COMPB_vect _VECTOR(16) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 17
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define CAN_INT_vect_num 18
+#define CAN_INT_vect _VECTOR(18) /* CAN MOB, Burst, General Errors */
+#define CAN_TOVF_vect_num 19
+#define CAN_TOVF_vect _VECTOR(19) /* CAN Timer Overflow */
+#define LIN_TC_vect_num 20
+#define LIN_TC_vect _VECTOR(20) /* LIN Transfer Complete */
+#define LIN_ERR_vect_num 21
+#define LIN_ERR_vect _VECTOR(21) /* LIN Error */
+#define PCINT0_vect_num 22
+#define PCINT0_vect _VECTOR(22) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 23
+#define PCINT1_vect _VECTOR(23) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 24
+#define PCINT2_vect _VECTOR(24) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 25
+#define PCINT3_vect _VECTOR(25) /* Pin Change Interrupt Request 3 */
+#define SPI_STC_vect_num 26
+#define SPI_STC_vect _VECTOR(26) /* SPI Serial Transfer Complete */
+#define ADC_vect_num 27
+#define ADC_vect _VECTOR(27) /* ADC Conversion Complete */
+#define WDT_vect_num 28
+#define WDT_vect _VECTOR(28) /* Watchdog Time-Out Interrupt */
+#define EE_READY_vect_num 29
+#define EE_READY_vect _VECTOR(29) /* EEPROM Ready */
+#define SPM_READY_vect_num 30
+#define SPM_READY_vect _VECTOR(30) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x0100)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector Trigger Level */
+#define FUSE_PSCRVB (unsigned char)~_BV(3) /* PSC Outputs xB Reset Value */
+#define FUSE_PSCRVA (unsigned char)~_BV(4) /* PSC Outputs xA Reset Value */
+#define FUSE_PSCRB (unsigned char)~_BV(5) /* PSC Reset Behavior */
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_BODLEVEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x84
+
+
+#endif /* _AVR_ATmega16M1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom16u2.h b/cpukit/score/cpu/avr/avr/iom16u2.h
new file mode 100644
index 0000000000..d49bcfe3e6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16u2.h
@@ -0,0 +1,980 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16u2.h - definitions for ATmega16U2 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16u2.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega16U2_H_
+#define _AVR_ATmega16U2_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLP0 2
+#define PLLP1 3
+#define PLLP2 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define DWDR _SFR_IO8(0x31)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define USBRF 5
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define EIND _SFR_IO8(0x3C)
+#define EIND0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define WDTCKD _SFR_MEM8(0x62)
+#define WCLKD0 0
+#define WCLKD1 1
+#define WDEWIE 2
+#define WDEWIF 3
+
+#define REGCR _SFR_MEM8(0x63)
+#define REGDIS 0
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSART1 0
+#define PRUSB 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CL0 0
+#define OCR1CL1 1
+#define OCR1CL2 2
+#define OCR1CL3 3
+#define OCR1CL4 4
+#define OCR1CL5 5
+#define OCR1CL6 6
+#define OCR1CL7 7
+
+#define OCR1CH _SFR_MEM8(0x8D)
+#define OCR1CH0 0
+#define OCR1CH1 1
+#define OCR1CH2 2
+#define OCR1CH3 3
+#define OCR1CH4 4
+#define OCR1CH5 5
+#define OCR1CH6 6
+#define OCR1CH7 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UCSR1D _SFR_MEM8(0xCB)
+#define RTSEN 0
+#define CTSEN 1
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1_0 0
+#define UBRR1_1 1
+#define UBRR1_2 2
+#define UBRR1_3 3
+#define UBRR1_4 4
+#define UBRR1_5 5
+#define UBRR1_6 6
+#define UBRR1_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR1_8 0
+#define UBRR1_9 1
+#define UBRR1_10 2
+#define UBRR1_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+#define CLKSEL0 _SFR_MEM8(0xD0)
+#define CLKS 0
+#define EXTE 2
+#define RCE 3
+#define EXSUT0 4
+#define EXSUT1 5
+#define RCSUT0 6
+#define RCSUT1 7
+
+#define CLKSEL1 _SFR_MEM8(0xD1)
+#define EXCKSEL0 0
+#define EXCKSEL1 1
+#define EXCKSEL2 2
+#define EXCKSEL3 3
+#define RCCKSEL0 4
+#define RCCKSEL1 5
+#define RCCKSEL2 6
+#define RCCKSEL3 7
+
+#define CLKSTA _SFR_MEM8(0xD2)
+#define EXTON 0
+#define RCON 1
+
+#define USBCON _SFR_MEM8(0xD8)
+#define FRZCLK 5
+#define USBE 7
+
+#define UDCON _SFR_MEM8(0xE0)
+#define DETACH 0
+#define RMWKUP 1
+#define RSTCPU 2
+
+#define UDINT _SFR_MEM8(0xE1)
+#define SUSPI 0
+#define SOFI 2
+#define EORSTI 3
+#define WAKEUPI 4
+#define EORSMI 5
+#define UPRSMI 6
+
+#define UDIEN _SFR_MEM8(0xE2)
+#define SUSPE 0
+#define SOFE 2
+#define EORSTE 3
+#define WAKEUPE 4
+#define EORSME 5
+#define UPRSME 6
+
+#define UDADDR _SFR_MEM8(0xE3)
+#define UADD0 0
+#define UADD1 1
+#define UADD2 2
+#define UADD3 3
+#define UADD4 4
+#define UADD5 5
+#define UADD6 6
+#define ADDEN 7
+
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define FNUM0 0
+#define FNUM1 1
+#define FNUM2 2
+#define FNUM3 3
+#define FNUM4 4
+#define FNUM5 5
+#define FNUM6 6
+#define FNUM7 7
+
+#define UDFNUMH _SFR_MEM8(0xE5)
+#define FNUM8 0
+#define FNUM9 1
+#define FNUM10 2
+
+#define UDMFN _SFR_MEM8(0xE6)
+#define FNCERR 4
+
+#define UEINTX _SFR_MEM8(0xE8)
+#define TXINI 0
+#define STALLEDI 1
+#define RXOUTI 2
+#define RXSTPI 3
+#define NAKOUTI 4
+#define RWAL 5
+#define NAKINI 6
+#define FIFOCON 7
+
+#define UENUM _SFR_MEM8(0xE9)
+#define EPNUM0 0
+#define EPNUM1 1
+#define EPNUM2 2
+
+#define UERST _SFR_MEM8(0xEA)
+#define EPRST0 0
+#define EPRST1 1
+#define EPRST2 2
+#define EPRST3 3
+#define EPRST4 4
+
+#define UECONX _SFR_MEM8(0xEB)
+#define EPEN 0
+#define RSTDT 3
+#define STALLRQC 4
+#define STALLRQ 5
+
+#define UECFG0X _SFR_MEM8(0xEC)
+#define EPDIR 0
+#define EPTYPE0 6
+#define EPTYPE1 7
+
+#define UECFG1X _SFR_MEM8(0xED)
+#define ALLOC 1
+#define EPBK0 2
+#define EPBK1 3
+#define EPSIZE0 4
+#define EPSIZE1 5
+#define EPSIZE2 6
+
+#define UESTA0X _SFR_MEM8(0xEE)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UESTA1X _SFR_MEM8(0xEF)
+#define CURRBK0 0
+#define CURRBK1 1
+#define CTRLDIR 2
+
+#define UEIENX _SFR_MEM8(0xF0)
+#define TXINE 0
+#define STALLEDE 1
+#define RXOUTE 2
+#define RXSTPE 3
+#define NAKOUTE 4
+#define NAKINE 6
+#define FLERRE 7
+
+#define UEDATX _SFR_MEM8(0xF1)
+#define DAT0 0
+#define DAT1 1
+#define DAT2 2
+#define DAT3 3
+#define DAT4 4
+#define DAT5 5
+#define DAT6 6
+#define DAT7 7
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define BYCT0 0
+#define BYCT1 1
+#define BYCT2 2
+#define BYCT3 3
+#define BYCT4 4
+#define BYCT5 5
+#define BYCT6 6
+#define BYCT7 7
+
+#define UEINT _SFR_MEM8(0xF4)
+#define EPINT0 0
+#define EPINT1 1
+#define EPINT2 2
+#define EPINT3 3
+#define EPINT4 4
+
+#define PS2CON _SFR_MEM8(0xFA)
+#define PS2EN 0
+
+#define UPOE _SFR_MEM8(0xFB)
+#define DMI 0
+#define DPI 1
+#define DATAI 2
+#define SCKI 3
+#define UPDRV0 4
+#define UPDRV1 5
+#define UPWE0 6
+#define UPWE1 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect_num 4
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define INT4_vect_num 5
+#define INT4_vect _VECTOR(5) /* External Interrupt Request 4 */
+#define INT5_vect_num 6
+#define INT5_vect _VECTOR(6) /* External Interrupt Request 5 */
+#define INT6_vect_num 7
+#define INT6_vect _VECTOR(7) /* External Interrupt Request 6 */
+#define INT7_vect_num 8
+#define INT7_vect _VECTOR(8) /* External Interrupt Request 7 */
+#define PCINT0_vect_num 9
+#define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 10
+#define PCINT1_vect _VECTOR(10) /* Pin Change Interrupt Request 1 */
+#define USB_GEN_vect_num 11
+#define USB_GEN_vect _VECTOR(11) /* USB General Interrupt Request */
+#define USB_COM_vect_num 12
+#define USB_COM_vect _VECTOR(12) /* USB Endpoint/Pipe Interrupt Communication Request */
+#define WDT_vect_num 13
+#define WDT_vect _VECTOR(13) /* Watchdog Time-out Interrupt */
+#define TIMER1_CAPT_vect_num 14
+#define TIMER1_CAPT_vect _VECTOR(14) /* Timer/Counter2 Capture Event */
+#define TIMER1_COMPA_vect_num 15
+#define TIMER1_COMPA_vect _VECTOR(15) /* Timer/Counter2 Compare Match B */
+#define TIMER0_COMPA_vect_num 19
+#define TIMER0_COMPA_vect _VECTOR(19) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 20
+#define TIMER0_COMPB_vect _VECTOR(20) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 21
+#define TIMER0_OVF_vect _VECTOR(21) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 22
+#define SPI_STC_vect _VECTOR(22) /* SPI Serial Transfer Complete */
+#define USART1_RX_vect_num 23
+#define USART1_RX_vect _VECTOR(23) /* USART1, Rx Complete */
+#define USART1_UDRE_vect_num 24
+#define USART1_UDRE_vect _VECTOR(24) /* USART1 Data register Empty */
+#define USART1_TX_vect_num 25
+#define USART1_TX_vect _VECTOR(25) /* USART1, Tx Complete */
+#define ANALOG_COMP_vect_num 26
+#define ANALOG_COMP_vect _VECTOR(26) /* Analog Comparator */
+#define EE_READY_vect_num 27
+#define EE_READY_vect _VECTOR(27) /* EEPROM Ready */
+#define SPM_READY_vect_num 28
+#define SPM_READY_vect _VECTOR(28) /* Store Program Memory Read */
+#define TIMER1_COMPB_vect_num 16
+#define TIMER1_COMPB_vect _VECTOR(16) /* Timer/Counter2 Compare Match B */
+#define TIMER1_COMPC_vect_num 17
+#define TIMER1_COMPC_vect _VECTOR(17) /* Timer/Counter2 Compare Match C */
+#define TIMER1_OVF_vect_num 18
+#define TIMER1_OVF_vect _VECTOR(18) /* Timer/Counter1 Overflow */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (38 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (512)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_RSTDISBL (unsigned char)~_BV(6) /* External Reset Disable */
+#define FUSE_DWEN (unsigned char)~_BV(7) /* dwbugWIRE Enable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_HWBE (unsigned char)~_BV(3) /* Hardware Boot Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x89
+
+
+/* Device Pin Definitions */
+#endif /* _AVR_ATmega16U2_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom16u4.h b/cpukit/score/cpu/avr/avr/iom16u4.h
new file mode 100644
index 0000000000..7b144665a6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom16u4.h
@@ -0,0 +1,1357 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom16u4.h - definitions for ATmega16U4 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom16u4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega16U4_H_
+#define _AVR_ATmega16U4_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE2 2
+#define PINE6 6
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE2 2
+#define DDE6 6
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE2 2
+#define PORTE6 6
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF0 0
+#define PINF1 1
+#define PINF4 4
+#define PINF5 5
+#define PINF6 6
+#define PINF7 7
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF0 0
+#define DDF1 1
+#define DDF4 4
+#define DDF5 5
+#define DDF6 6
+#define DDF7 7
+
+#define PORTF _SFR_IO8(0x11)
+#define PORTF0 0
+#define PORTF1 1
+#define PORTF4 4
+#define PORTF5 5
+#define PORTF6 6
+#define PORTF7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+
+#define TIFR3 _SFR_IO8(0x18)
+#define TOV3 0
+#define OCF3A 1
+#define OCF3B 2
+#define OCF3C 3
+#define ICF3 5
+
+#define TIFR4 _SFR_IO8(0x19)
+#define TOV4 2
+#define OCF4B 5
+#define OCF4A 6
+#define OCF4D 7
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCROA_0 0
+#define OCROA_1 1
+#define OCROA_2 2
+#define OCROA_3 3
+#define OCROA_4 4
+#define OCROA_5 5
+#define OCROA_6 6
+#define OCROA_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PINDIV 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define PLLFRQ _SFR_IO8(0x32)
+#define PDIV0 0
+#define PDIV1 1
+#define PDIV2 2
+#define PDIV3 3
+#define PLLTM0 4
+#define PLLTM1 5
+#define PLLUSB 6
+#define PINMUX 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define RAMPZ _SFR_IO8(0x3B)
+#define RAMPZ0 0
+
+#define EIND _SFR_IO8(0x3C)
+#define EIND0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSART1 0
+#define PRTIM3 3
+#define PRUSB 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define RCCTRL _SFR_MEM8(0x67)
+#define RCFREQ 0
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+#define TIMSK3 _SFR_MEM8(0x71)
+#define TOIE3 0
+#define OCIE3A 1
+#define OCIE3B 2
+#define OCIE3C 3
+#define ICIE3 5
+
+#define TIMSK4 _SFR_MEM8(0x72)
+#define TOIE4 2
+#define OCIE4B 5
+#define OCIE4A 6
+#define OCIE4D 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 4
+#define MUX5 5
+#define ACME 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR2 _SFR_MEM8(0x7D)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define ADC11D 3
+#define ADC12D 4
+#define ADC13D 5
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CL0 0
+#define OCR1CL1 1
+#define OCR1CL2 2
+#define OCR1CL3 3
+#define OCR1CL4 4
+#define OCR1CL5 5
+#define OCR1CL6 6
+#define OCR1CL7 7
+
+#define OCR1CH _SFR_MEM8(0x8D)
+#define OCR1CH0 0
+#define OCR1CH1 1
+#define OCR1CH2 2
+#define OCR1CH3 3
+#define OCR1CH4 4
+#define OCR1CH5 5
+#define OCR1CH6 6
+#define OCR1CH7 7
+
+#define TCCR3A _SFR_MEM8(0x90)
+#define WGM30 0
+#define WGM31 1
+#define COM3C0 2
+#define COM3C1 3
+#define COM3B0 4
+#define COM3B1 5
+#define COM3A0 6
+#define COM3A1 7
+
+#define TCCR3B _SFR_MEM8(0x91)
+#define CS30 0
+#define CS31 1
+#define CS32 2
+#define WGM32 3
+#define WGM33 4
+#define ICES3 6
+#define ICNC3 7
+
+#define TCCR3C _SFR_MEM8(0x92)
+#define FOC3C 5
+#define FOC3B 6
+#define FOC3A 7
+
+#define TCNT3 _SFR_MEM16(0x94)
+
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3L0 0
+#define TCNT3L1 1
+#define TCNT3L2 2
+#define TCNT3L3 3
+#define TCNT3L4 4
+#define TCNT3L5 5
+#define TCNT3L6 6
+#define TCNT3L7 7
+
+#define TCNT3H _SFR_MEM8(0x95)
+#define TCNT3H0 0
+#define TCNT3H1 1
+#define TCNT3H2 2
+#define TCNT3H3 3
+#define TCNT3H4 4
+#define TCNT3H5 5
+#define TCNT3H6 6
+#define TCNT3H7 7
+
+#define ICR3 _SFR_MEM16(0x96)
+
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3L0 0
+#define ICR3L1 1
+#define ICR3L2 2
+#define ICR3L3 3
+#define ICR3L4 4
+#define ICR3L5 5
+#define ICR3L6 6
+#define ICR3L7 7
+
+#define ICR3H _SFR_MEM8(0x97)
+#define ICR3H0 0
+#define ICR3H1 1
+#define ICR3H2 2
+#define ICR3H3 3
+#define ICR3H4 4
+#define ICR3H5 5
+#define ICR3H6 6
+#define ICR3H7 7
+
+#define OCR3A _SFR_MEM16(0x98)
+
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AL0 0
+#define OCR3AL1 1
+#define OCR3AL2 2
+#define OCR3AL3 3
+#define OCR3AL4 4
+#define OCR3AL5 5
+#define OCR3AL6 6
+#define OCR3AL7 7
+
+#define OCR3AH _SFR_MEM8(0x99)
+#define OCR3AH0 0
+#define OCR3AH1 1
+#define OCR3AH2 2
+#define OCR3AH3 3
+#define OCR3AH4 4
+#define OCR3AH5 5
+#define OCR3AH6 6
+#define OCR3AH7 7
+
+#define OCR3B _SFR_MEM16(0x9A)
+
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BL0 0
+#define OCR3BL1 1
+#define OCR3BL2 2
+#define OCR3BL3 3
+#define OCR3BL4 4
+#define OCR3BL5 5
+#define OCR3BL6 6
+#define OCR3BL7 7
+
+#define OCR3BH _SFR_MEM8(0x9B)
+#define OCR3BH0 0
+#define OCR3BH1 1
+#define OCR3BH2 2
+#define OCR3BH3 3
+#define OCR3BH4 4
+#define OCR3BH5 5
+#define OCR3BH6 6
+#define OCR3BH7 7
+
+#define OCR3C _SFR_MEM16(0x9C)
+
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CL0 0
+#define OCR3CL1 1
+#define OCR3CL2 2
+#define OCR3CL3 3
+#define OCR3CL4 4
+#define OCR3CL5 5
+#define OCR3CL6 6
+#define OCR3CL7 7
+
+#define OCR3CH _SFR_MEM8(0x9D)
+#define OCR3CH0 0
+#define OCR3CH1 1
+#define OCR3CH2 2
+#define OCR3CH3 3
+#define OCR3CH4 4
+#define OCR3CH5 5
+#define OCR3CH6 6
+#define OCR3CH7 7
+
+#define TCNT4 _SFR_MEM8(0xBE)
+#define TC40 0
+#define TC41 1
+#define TC42 2
+#define TC43 3
+#define TC44 4
+#define TC45 5
+#define TC46 6
+#define TC47 7
+
+#define TC4H _SFR_MEM8(0xBF)
+#define TC48 0
+#define TC49 1
+#define TC410 2
+
+#define TCCR4A _SFR_MEM8(0xC0)
+#define PWM4B 0
+#define PWM4A 1
+#define FOC4B 2
+#define FOC4A 3
+#define COM4B0 4
+#define COM4B1 5
+#define COM4A0 6
+#define COM4A1 7
+
+#define TCCR4B _SFR_MEM8(0xC1)
+#define CS40 0
+#define CS41 1
+#define CS42 2
+#define CS43 3
+#define DTPS40 4
+#define DTPS41 5
+#define PSR4 6
+#define PWM4X 7
+
+#define TCCR4C _SFR_MEM8(0xC2)
+#define PWM4D 0
+#define FOC4D 1
+#define COM4D0 2
+#define COM4D1 3
+#define COM4B0S 4
+#define COM4B1S 5
+#define COM4A0S 6
+#define COM4A1S 7
+
+#define TCCR4D _SFR_MEM8(0xC3)
+#define WGM40 0
+#define WGM41 1
+#define FPF4 2
+#define FPAC4 3
+#define FPES4 4
+#define FPNC4 5
+#define FPEN4 6
+#define FPIE4 7
+
+#define TCCR4E _SFR_MEM8(0xC4)
+#define OC4OE0 0
+#define OC4OE1 1
+#define OC4OE2 2
+#define OC4OE3 3
+#define OC4OE4 4
+#define OC4OE5 5
+#define ENHC4 6
+#define TLOCK4 7
+
+#define CLKSEL0 _SFR_MEM8(0xC5)
+#define CLKS 0
+#define EXTE 2
+#define RCE 3
+#define EXSUT0 4
+#define EXSUT1 5
+#define RCSUT0 6
+#define RCSUT1 7
+
+#define CLKSEL1 _SFR_MEM8(0xC6)
+#define EXCKSEL0 0
+#define EXCKSEL1 1
+#define EXCKSEL2 2
+#define EXCKSEL3 3
+#define RCCKSEL0 4
+#define RCCKSEL1 5
+#define RCCKSEL2 6
+#define RCCKSEL3 7
+
+#define CLKSTA _SFR_MEM8(0xC7)
+#define EXTON 0
+#define RCON 1
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+
+#define UBRR1H _SFR_MEM8(0xCD)
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+#define OCR4A _SFR_MEM8(0xCF)
+#define OCR4A0 0
+#define OCR4A1 1
+#define OCR4A2 2
+#define OCR4A3 3
+#define OCR4A4 4
+#define OCR4A5 5
+#define OCR4A6 6
+#define OCR4A7 7
+
+#define OCR4B _SFR_MEM8(0xD0)
+#define OCR4B0 0
+#define OCR4B1 1
+#define OCR4B2 2
+#define OCR4B3 3
+#define OCR4B4 4
+#define OCR4B5 5
+#define OCR4B6 6
+#define OCR4B7 7
+
+#define OCR4C _SFR_MEM8(0xD1)
+#define OCR4C0 0
+#define OCR4C1 1
+#define OCR4C2 2
+#define OCR4C3 3
+#define OCR4C4 4
+#define OCR4C5 5
+#define OCR4C6 6
+#define OCR4C7 7
+
+#define OCR4D _SFR_MEM8(0xD2)
+#define OCR4D0 0
+#define OCR4D1 1
+#define OCR4D2 2
+#define OCR4D3 3
+#define OCR4D4 4
+#define OCR4D5 5
+#define OCR4D6 6
+#define OCR4D7 7
+
+#define DT4 _SFR_MEM8(0xD4)
+#define DT4L0 0
+#define DT4L1 1
+#define DT4L2 2
+#define DT4L3 3
+#define DT4L4 4
+#define DT4L5 5
+#define DT4L6 6
+#define DT4L7 7
+
+#define UHWCON _SFR_MEM8(0xD7)
+#define UVREGE 0
+
+#define USBCON _SFR_MEM8(0xD8)
+#define VBUSTE 0
+#define OTGPADE 4
+#define FRZCLK 5
+#define USBE 7
+
+#define USBSTA _SFR_MEM8(0xD9)
+#define VBUS 0
+#define SPEED 3
+
+#define USBINT _SFR_MEM8(0xDA)
+#define VBUSTI 0
+
+#define UDCON _SFR_MEM8(0xE0)
+#define DETACH 0
+#define RMWKUP 1
+#define LSM 2
+#define RSTCPU 3
+
+#define UDINT _SFR_MEM8(0xE1)
+#define SUSPI 0
+#define SOFI 2
+#define EORSTI 3
+#define WAKEUPI 4
+#define EORSMI 5
+#define UPRSMI 6
+
+#define UDIEN _SFR_MEM8(0xE2)
+#define SUSPE 0
+#define SOFE 2
+#define EORSTE 3
+#define WAKEUPE 4
+#define EORSME 5
+#define UPRSME 6
+
+#define UDADDR _SFR_MEM8(0xE3)
+#define UADD0 0
+#define UADD1 1
+#define UADD2 2
+#define UADD3 3
+#define UADD4 4
+#define UADD5 5
+#define UADD6 6
+#define ADDEN 7
+
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define FNUM0 0
+#define FNUM1 1
+#define FNUM2 2
+#define FNUM3 3
+#define FNUM4 4
+#define FNUM5 5
+#define FNUM6 6
+#define FNUM7 7
+
+#define UDFNUMH _SFR_MEM8(0xE5)
+#define FNUM8 0
+#define FNUM9 1
+#define FNUM10 2
+
+#define UDMFN _SFR_MEM8(0xE6)
+#define FNCERR 4
+
+#define UEINTX _SFR_MEM8(0xE8)
+#define TXINI 0
+#define STALLEDI 1
+#define RXOUTI 2
+#define RXSTPI 3
+#define NAKOUTI 4
+#define RWAL 5
+#define NAKINI 6
+#define FIFOCON 7
+
+#define UENUM _SFR_MEM8(0xE9)
+#define UENUM_0 0
+#define UENUM_1 1
+#define UENUM_2 2
+
+#define UERST _SFR_MEM8(0xEA)
+#define EPRST0 0
+#define EPRST1 1
+#define EPRST2 2
+#define EPRST3 3
+#define EPRST4 4
+#define EPRST5 5
+#define EPRST6 6
+
+#define UECONX _SFR_MEM8(0xEB)
+#define EPEN 0
+#define RSTDT 3
+#define STALLRQC 4
+#define STALLRQ 5
+
+#define UECFG0X _SFR_MEM8(0xEC)
+#define EPDIR 0
+#define EPTYPE0 6
+#define EPTYPE1 7
+
+#define UECFG1X _SFR_MEM8(0xED)
+#define ALLOC 1
+#define EPBK0 2
+#define EPBK1 3
+#define EPSIZE0 4
+#define EPSIZE1 5
+#define EPSIZE2 6
+
+#define UESTA0X _SFR_MEM8(0xEE)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UESTA1X _SFR_MEM8(0xEF)
+#define CURRBK0 0
+#define CURRBK1 1
+#define CTRLDIR 2
+
+#define UEIENX _SFR_MEM8(0xF0)
+#define TXINE 0
+#define STALLEDE 1
+#define RXOUTE 2
+#define RXSTPE 3
+#define NAKOUTE 4
+#define NAKINE 6
+#define FLERRE 7
+
+#define UEDATX _SFR_MEM8(0xF1)
+#define DAT0 0
+#define DAT1 1
+#define DAT2 2
+#define DAT3 3
+#define DAT4 4
+#define DAT5 5
+#define DAT6 6
+#define DAT7 7
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define BYCT0 0
+#define BYCT1 1
+#define BYCT2 2
+#define BYCT3 3
+#define BYCT4 4
+#define BYCT5 5
+#define BYCT6 6
+#define BYCT7 7
+
+#define UEBCHX _SFR_MEM8(0xF3)
+
+#define UEINT _SFR_MEM8(0xF4)
+#define EPINT0 0
+#define EPINT1 1
+#define EPINT2 2
+#define EPINT3 3
+#define EPINT4 4
+#define EPINT5 5
+#define EPINT6 6
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect_num 4
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define INT6_vect_num 7
+#define INT6_vect _VECTOR(7) /* External Interrupt Request 6 */
+#define PCINT0_vect_num 9
+#define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0 */
+#define USB_GEN_vect_num 10
+#define USB_GEN_vect _VECTOR(10) /* USB General Interrupt Request */
+#define USB_COM_vect_num 11
+#define USB_COM_vect _VECTOR(11) /* USB Endpoint/Pipe Interrupt Communication Request */
+#define WDT_vect_num 12
+#define WDT_vect _VECTOR(12) /* Watchdog Time-out Interrupt */
+#define TIMER1_CAPT_vect_num 16
+#define TIMER1_CAPT_vect _VECTOR(16) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 17
+#define TIMER1_COMPA_vect _VECTOR(17) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 18
+#define TIMER1_COMPB_vect _VECTOR(18) /* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPC_vect_num 19
+#define TIMER1_COMPC_vect _VECTOR(19) /* Timer/Counter1 Compare Match C */
+#define TIMER1_OVF_vect_num 20
+#define TIMER1_OVF_vect _VECTOR(20) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 21
+#define TIMER0_COMPA_vect _VECTOR(21) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 22
+#define TIMER0_COMPB_vect _VECTOR(22) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 23
+#define TIMER0_OVF_vect _VECTOR(23) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 24
+#define SPI_STC_vect _VECTOR(24) /* SPI Serial Transfer Complete */
+#define USART1_RX_vect_num 25
+#define USART1_RX_vect _VECTOR(25) /* USART1, Rx Complete */
+#define USART1_UDRE_vect_num 26
+#define USART1_UDRE_vect _VECTOR(26) /* USART1 Data register Empty */
+#define USART1_TX_vect_num 27
+#define USART1_TX_vect _VECTOR(27) /* USART1, Tx Complete */
+#define ANALOG_COMP_vect_num 28
+#define ANALOG_COMP_vect _VECTOR(28) /* Analog Comparator */
+#define ADC_vect_num 29
+#define ADC_vect _VECTOR(29) /* ADC Conversion Complete */
+#define EE_READY_vect_num 30
+#define EE_READY_vect _VECTOR(30) /* EEPROM Ready */
+#define TIMER3_CAPT_vect_num 31
+#define TIMER3_CAPT_vect _VECTOR(31) /* Timer/Counter3 Capture Event */
+#define TIMER3_COMPA_vect_num 32
+#define TIMER3_COMPA_vect _VECTOR(32) /* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPB_vect_num 33
+#define TIMER3_COMPB_vect _VECTOR(33) /* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPC_vect_num 34
+#define TIMER3_COMPC_vect _VECTOR(34) /* Timer/Counter3 Compare Match C */
+#define TIMER3_OVF_vect_num 35
+#define TIMER3_OVF_vect _VECTOR(35) /* Timer/Counter3 Overflow */
+#define TWI_vect_num 36
+#define TWI_vect _VECTOR(36) /* 2-wire Serial Interface */
+#define SPM_READY_vect_num 37
+#define SPM_READY_vect _VECTOR(37) /* Store Program Memory Read */
+#define TIMER4_COMPA_vect_num 38
+#define TIMER4_COMPA_vect _VECTOR(38) /* Timer/Counter4 Compare Match A */
+#define TIMER4_COMPB_vect_num 39
+#define TIMER4_COMPB_vect _VECTOR(39) /* Timer/Counter4 Compare Match B */
+#define TIMER4_COMPD_vect_num 40
+#define TIMER4_COMPD_vect _VECTOR(40) /* Timer/Counter4 Compare Match D */
+#define TIMER4_OVF_vect_num 41
+#define TIMER4_OVF_vect _VECTOR(41) /* Timer/Counter4 Overflow */
+#define TIMER4_FPF_vect_num 42
+#define TIMER4_FPF_vect _VECTOR(42) /* Timer/Counter4 Fault Protection Interrupt */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (43 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (1280)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_HWBE (unsigned char)~_BV(3) /* Hardware Boot Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x88
+
+
+#endif /* _AVR_ATmega16U4_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom2560.h b/cpukit/score/cpu/avr/avr/iom2560.h
new file mode 100644
index 0000000000..07039ad7e8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom2560.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id */
+
+/* avr/iom2560.h - definitions for ATmega2560 */
+
+#ifndef _AVR_IOM2560_H_
+#define _AVR_IOM2560_H_ 1
+
+#include <avr/iomxx0_1.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x21FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x3FFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x98
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IOM2560_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom2561.h b/cpukit/score/cpu/avr/avr/iom2561.h
new file mode 100644
index 0000000000..fd379a2599
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom2561.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id */
+
+/* avr/iom2561.h - definitions for ATmega2561 */
+
+#ifndef _AVR_IOM2561_H_
+#define _AVR_IOM2561_H_ 1
+
+#include <avr/iomxx0_1.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x21FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x3FFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x98
+#define SIGNATURE_2 0x02
+
+
+#endif /* _AVR_IOM2561_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom32.h b/cpukit/score/cpu/avr/avr/iom32.h
new file mode 100644
index 0000000000..b0eba1511e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32.h
@@ -0,0 +1,696 @@
+/* Copyright (c) 2002, Steinar Haugen
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom32.h - definitions for ATmega32 */
+
+#ifndef _AVR_IOM32_H_
+#define _AVR_IOM32_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* TWI stands for "Two Wire Interface" or "TWI Was I2C(tm)" */
+#define TWBR _SFR_IO8(0x00)
+#define TWSR _SFR_IO8(0x01)
+#define TWAR _SFR_IO8(0x02)
+#define TWDR _SFR_IO8(0x03)
+
+/* ADC */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+#define ADCSRA _SFR_IO8(0x06)
+#define ADMUX _SFR_IO8(0x07)
+
+/* analog comparator */
+#define ACSR _SFR_IO8(0x08)
+
+/* USART */
+#define UBRRL _SFR_IO8(0x09)
+#define UCSRB _SFR_IO8(0x0A)
+#define UCSRA _SFR_IO8(0x0B)
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI */
+#define SPCR _SFR_IO8(0x0D)
+#define SPSR _SFR_IO8(0x0E)
+#define SPDR _SFR_IO8(0x0F)
+
+/* Port D */
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* Port C */
+#define PINC _SFR_IO8(0x13)
+#define DDRC _SFR_IO8(0x14)
+#define PORTC _SFR_IO8(0x15)
+
+/* Port B */
+#define PINB _SFR_IO8(0x16)
+#define DDRB _SFR_IO8(0x17)
+#define PORTB _SFR_IO8(0x18)
+
+/* Port A */
+#define PINA _SFR_IO8(0x19)
+#define DDRA _SFR_IO8(0x1A)
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define UBRRH _SFR_IO8(0x20)
+#define UCSRC UBRRH
+
+#define WDTCR _SFR_IO8(0x21)
+
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer 2 */
+#define OCR2 _SFR_IO8(0x23)
+#define TCNT2 _SFR_IO8(0x24)
+#define TCCR2 _SFR_IO8(0x25)
+
+/* Timer 1 */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCCR1B _SFR_IO8(0x2E)
+#define TCCR1A _SFR_IO8(0x2F)
+
+#define SFIOR _SFR_IO8(0x30)
+
+#define OSCCAL _SFR_IO8(0x31)
+#define OCDR OSCCAL
+
+/* Timer 0 */
+#define TCNT0 _SFR_IO8(0x32)
+#define TCCR0 _SFR_IO8(0x33)
+
+#define MCUSR _SFR_IO8(0x34)
+#define MCUCSR MCUSR
+#define MCUCR _SFR_IO8(0x35)
+
+#define TWCR _SFR_IO8(0x36)
+
+#define SPMCR _SFR_IO8(0x37)
+
+#define TIFR _SFR_IO8(0x38)
+#define TIMSK _SFR_IO8(0x39)
+
+#define GIFR _SFR_IO8(0x3A)
+#define GIMSK _SFR_IO8(0x3B)
+#define GICR GIMSK
+
+#define OCR0 _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART, Rx Complete */
+#define USART_RXC_vect _VECTOR(13)
+#define SIG_USART_RECV _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(14)
+#define SIG_USART_DATA _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART, Tx Complete */
+#define USART_TXC_vect _VECTOR(15)
+#define SIG_USART_TRANS _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(16)
+#define SIG_ADC _VECTOR(16)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(17)
+#define SIG_EEPROM_READY _VECTOR(17)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(19)
+#define SIG_2WIRE_SERIAL _VECTOR(19)
+
+/* Store Program Memory Ready */
+#define SPM_RDY_vect _VECTOR(20)
+#define SIG_SPM_READY _VECTOR(20)
+
+#define _VECTORS_SIZE 84
+
+/* Bit numbers */
+
+/* GICR */
+#define INT1 7
+#define INT0 6
+#define INT2 5
+#define IVSEL 1
+#define IVCE 0
+
+/* GIFR */
+#define INTF1 7
+#define INTF0 6
+#define INTF2 5
+
+/* TIMSK */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define OCIE0 1
+#define TOIE0 0
+
+/* TIFR */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define OCF0 1
+#define TOV0 0
+
+/* SPMCR */
+#define SPMIE 7
+#define RWWSB 6
+/* bit 5 reserved */
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+/* bit 1 reserved */
+#define TWIE 0
+
+/* TWAR */
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+/* TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+/* bit 2 reserved */
+#define TWPS1 1
+#define TWPS0 0
+
+/* MCUCR */
+#define SE 7
+#define SM2 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* MCUCSR */
+#define JTD 7
+#define ISC2 6
+/* bit 5 reserved */
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* SFIOR */
+#define ADTS2 7
+#define ADTS1 6
+#define ADTS0 5
+/* bit 4 reserved */
+#define ACME 3
+#define PUD 2
+#define PSR2 1
+#define PSR10 0
+
+/* TCCR0 */
+#define FOC0 7
+#define WGM00 6
+#define COM01 5
+#define COM00 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR2 */
+#define FOC2 7
+#define WGM20 6
+#define COM21 5
+#define COM20 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* ASSR */
+/* bits 7-4 reserved */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define WGM11 1
+#define WGM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+/* bit 5 reserved */
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* WDTCR */
+/* bits 7-5 reserved */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* PA7-PA0 = ADC7-ADC0 */
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB7 = SCK
+ PB6 = MISO
+ PB5 = MOSI
+ PB4 = SS#
+ PB3 = OC0/AIN1
+ PB2 = INT2/AIN0
+ PB1 = T1
+ PB0 = XCK/T0
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/*
+ PC7 = TOSC2
+ PC6 = TOSC1
+ PC1 = SDA
+ PC0 = SCL
+ */
+/* PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/*
+ PD7 = OC2
+ PD6 = ICP
+ PD5 = OC1A
+ PD4 = OC1B
+ PD3 = INT1
+ PD2 = INT0
+ PD1 = TXD
+ PD0 = RXD
+ */
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+/* bits 5-1 reserved */
+#define SPI2X 0
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UCSRA */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define PE 2
+#define U2X 1
+#define MPCM 0
+
+/* UCSRB */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define RXB8 1
+#define TXB8 0
+
+/* UCSRC */
+#define URSEL 7
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x85F
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x02
+
+
+#endif /* _AVR_IOM32_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom323.h b/cpukit/score/cpu/avr/avr/iom323.h
new file mode 100644
index 0000000000..865d6a210b
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom323.h
@@ -0,0 +1,688 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom323.h - definitions for ATmega323 */
+
+#ifndef _AVR_IOM323_H_
+#define _AVR_IOM323_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom323.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* TWI stands for "Two Wire Interface" or "TWI Was I2C(tm)" */
+#define TWBR _SFR_IO8(0x00)
+#define TWSR _SFR_IO8(0x01)
+#define TWAR _SFR_IO8(0x02)
+#define TWDR _SFR_IO8(0x03)
+
+/* ADC */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+#define ADCSR _SFR_IO8(0x06)
+#define ADMUX _SFR_IO8(0x07)
+
+/* analog comparator */
+#define ACSR _SFR_IO8(0x08)
+
+/* UART */
+#define UBRR _SFR_IO8(0x09)
+#define UBRRL UBRR
+#define UCSRB _SFR_IO8(0x0A)
+#define UCSRA _SFR_IO8(0x0B)
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI */
+#define SPCR _SFR_IO8(0x0D)
+#define SPSR _SFR_IO8(0x0E)
+#define SPDR _SFR_IO8(0x0F)
+
+/* Port D */
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* Port C */
+#define PINC _SFR_IO8(0x13)
+#define DDRC _SFR_IO8(0x14)
+#define PORTC _SFR_IO8(0x15)
+
+/* Port B */
+#define PINB _SFR_IO8(0x16)
+#define DDRB _SFR_IO8(0x17)
+#define PORTB _SFR_IO8(0x18)
+
+/* Port A */
+#define PINA _SFR_IO8(0x19)
+#define DDRA _SFR_IO8(0x1A)
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define UBRRH _SFR_IO8(0x20)
+#define UCSRC UBRRH
+
+#define WDTCR _SFR_IO8(0x21)
+
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer 2 */
+#define OCR2 _SFR_IO8(0x23)
+#define TCNT2 _SFR_IO8(0x24)
+#define TCCR2 _SFR_IO8(0x25)
+
+/* Timer 1 */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCCR1B _SFR_IO8(0x2E)
+#define TCCR1A _SFR_IO8(0x2F)
+
+#define SFIOR _SFR_IO8(0x30)
+
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer 0 */
+#define TCNT0 _SFR_IO8(0x32)
+#define TCCR0 _SFR_IO8(0x33)
+
+#define MCUSR _SFR_IO8(0x34)
+#define MCUCSR MCUSR
+#define MCUCR _SFR_IO8(0x35)
+
+#define TWCR _SFR_IO8(0x36)
+
+#define SPMCR _SFR_IO8(0x37)
+
+#define TIFR _SFR_IO8(0x38)
+#define TIMSK _SFR_IO8(0x39)
+
+#define GIFR _SFR_IO8(0x3A)
+#define GIMSK _SFR_IO8(0x3B)
+#define GICR GIMSK
+
+#define OCR0 _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART, Rx Complete */
+#define USART_RXC_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART, Tx Complete */
+#define USART_TXC_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(16)
+#define SIG_ADC _VECTOR(16)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(17)
+#define SIG_EEPROM_READY _VECTOR(17)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(19)
+#define SIG_2WIRE_SERIAL _VECTOR(19)
+
+/* Store Program Memory Ready */
+#define SPM_RDY_vect _VECTOR(20)
+
+#define _VECTORS_SIZE 80
+
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT1 7
+#define INT0 6
+#define INT2 5
+#define IVSEL 1
+#define IVCE 0
+
+/* GIFR */
+#define INTF1 7
+#define INTF0 6
+#define INTF2 5
+
+/* TIMSK */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define OCIE0 1
+#define TOIE0 0
+
+/* TIFR */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define OCF0 1
+#define TOV0 0
+
+/* SPMCR */
+#define SPMIE 7
+#define ASB 6
+/* bit 5 reserved */
+#define ASRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWI_TST 1
+#define TWIE 0
+
+/* TWAR */
+#define TWGCE 0
+
+/* TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+/* bits 2-0 reserved */
+
+/* MCUCR */
+/* bit 7 reserved (SM2?) */
+#define SE 7
+#define SM2 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* MCUCSR */
+#define JTD 7
+#define ISC2 6
+#define EIH 5
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* SFIOR */
+#define RPDD 7
+#define RPDC 6
+#define RPDB 5
+#define RPDA 4
+#define ACME 3
+#define PUD 2
+#define PSR2 1
+#define PSR10 0
+
+/* TCCR0 */
+#define FOC0 7
+#define PWM0 6
+#define COM01 5
+#define COM00 4
+#define CTC0 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR2 */
+#define FOC2 7
+#define PWM2 6
+#define COM21 5
+#define COM20 4
+#define CTC2 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* ASSR */
+/* bits 7-4 reserved */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define PWM11 1
+#define PWM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+/* bit 5 reserved */
+#define CTC11 4
+#define CTC10 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* WDTCR */
+/* bits 7-5 reserved */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* PA7-PA0 = ADC7-ADC0 */
+/* PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB7 = SCK
+ PB6 = MISO
+ PB5 = MOSI
+ PB4 = SS#
+ PB3 = AIN1
+ PB2 = AIN0
+ PB1 = T1
+ PB0 = T0
+ */
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/*
+ PC7 = TOSC2
+ PC6 = TOSC1
+ PC1 = SDA
+ PC0 = SCL
+ */
+/* PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/*
+ PD7 = OC2
+ PD6 = ICP
+ PD5 = OC1A
+ PD4 = OC1B
+ PD3 = INT1
+ PD2 = INT0
+ PD1 = TXD
+ PD0 = RXD
+ */
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/*
+ PE2 = ALE
+ PE1 = OC1B
+ PE0 = ICP / INT2
+ */
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UCSRA */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define PE 2
+#define U2X 1
+#define MPCM 0
+
+/* UCSRB */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define CHR9 2
+#define RXB8 1
+#define TXB8 0
+
+/* UCSRC */
+#define URSEL 7
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* ACSR */
+#define ACD 7
+#define AINBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADCSR */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x85F
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 0
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_JTAGEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x01
+
+
+#endif /* _AVR_IOM323_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom324.h b/cpukit/score/cpu/avr/avr/iom324.h
new file mode 100644
index 0000000000..a798b9e98a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom324.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005, 2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom324.h - definitions for ATmega324 */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM324_H_
+#define _AVR_IOM324_H_ 1
+
+#include <avr/iomxx4.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x08FF
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature (ATmega324P) */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x08
+
+
+#endif /* _AVR_IOM324_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom324pa.h b/cpukit/score/cpu/avr/avr/iom324pa.h
new file mode 100644
index 0000000000..8231a9bb87
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom324pa.h
@@ -0,0 +1,1355 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom324pa.h - definitions for ATmega324PA */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom324pa.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega324PA_H_
+#define _AVR_ATmega324PA_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR0 _SFR_IO8(0x2C)
+#define SPR00 0
+#define SPR10 1
+#define CPHA0 2
+#define CPOL0 3
+#define MSTR0 4
+#define DORD0 5
+#define SPE0 6
+#define SPIE0 7
+
+#define SPSR0 _SFR_IO8(0x2D)
+#define SPI2X0 0
+#define WCOL0 6
+#define SPIF0 7
+
+#define SPDR0 _SFR_IO8(0x2E)
+#define SPDRB0 0
+#define SPDRB1 1
+#define SPDRB2 2
+#define SPDRB3 3
+#define SPDRB4 4
+#define SPDRB5 5
+#define SPDRB6 6
+#define SPDRB7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRUSART1 4
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+#define PCINT31 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A_0 0
+#define OCR2A_1 1
+#define OCR2A_2 2
+#define OCR2A_3 3
+#define OCR2A_4 4
+#define OCR2A_5 5
+#define OCR2A_6 6
+#define OCR2A_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2B_0 0
+#define OCR2B_1 1
+#define OCR2B_2 2
+#define OCR2B_3 3
+#define OCR2B_4 4
+#define OCR2B_5 5
+#define OCR2B_6 6
+#define OCR2B_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define _UBRR0 0
+#define _UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR_0 0
+#define UBRR_1 1
+#define UBRR_2 2
+#define UBRR_3 3
+#define UBRR_4 4
+#define UBRR_5 5
+#define UBRR_6 6
+#define UBRR_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR_8 0
+#define UBRR_9 1
+#define UBRR_10 2
+#define UBRR_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define PCINT0_vect_num 4
+#define PCINT0_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 5
+#define PCINT1_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 6
+#define PCINT2_vect _VECTOR(6) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 7
+#define PCINT3_vect _VECTOR(7) /* Pin Change Interrupt Request 3 */
+#define WDT_vect_num 8
+#define WDT_vect _VECTOR(8) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect_num 9
+#define TIMER2_COMPA_vect _VECTOR(9) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect_num 10
+#define TIMER2_COMPB_vect _VECTOR(10) /* Timer/Counter2 Compare Match B */
+#define TIMER2_OVF_vect_num 11
+#define TIMER2_OVF_vect _VECTOR(11) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 12
+#define TIMER1_CAPT_vect _VECTOR(12) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 13
+#define TIMER1_COMPA_vect _VECTOR(13) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 14
+#define TIMER1_COMPB_vect _VECTOR(14) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 15
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 16
+#define TIMER0_COMPA_vect _VECTOR(16) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 17
+#define TIMER0_COMPB_vect _VECTOR(17) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 18
+#define TIMER0_OVF_vect _VECTOR(18) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 19
+#define SPI_STC_vect _VECTOR(19) /* SPI Serial Transfer Complete */
+#define USART0_RX_vect_num 20
+#define USART0_RX_vect _VECTOR(20) /* USART0, Rx Complete */
+#define USART0_UDRE_vect_num 21
+#define USART0_UDRE_vect _VECTOR(21) /* USART0 Data register Empty */
+#define USART0_TX_vect_num 22
+#define USART0_TX_vect _VECTOR(22) /* USART0, Tx Complete */
+#define ANALOG_COMP_vect_num 23
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define ADC_vect_num 24
+#define ADC_vect _VECTOR(24) /* ADC Conversion Complete */
+#define EE_READY_vect_num 25
+#define EE_READY_vect _VECTOR(25) /* EEPROM Ready */
+#define TWI_vect_num 26
+#define TWI_vect _VECTOR(26) /* 2-wire Serial Interface */
+#define SPM_READY_vect_num 27
+#define SPM_READY_vect _VECTOR(27) /* Store Program Memory Read */
+#define USART1_RX_vect_num 28
+#define USART1_RX_vect _VECTOR(28) /* USART1 RX complete */
+#define USART1_UDRE_vect_num 29
+#define USART1_UDRE_vect _VECTOR(29) /* USART1 Data Register Empty */
+#define USART1_TX_vect_num 30
+#define USART1_TX_vect _VECTOR(30) /* USART1 TX complete */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (2048)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x11
+
+
+/* Device Pin Definitions */
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 5
+
+#define PCINT13_DDR DDRB
+#define PCINT13_PORT PORTB
+#define PCINT13_PIN PINB
+#define PCINT13_BIT 5
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 6
+
+#define PCINT14_DDR DDRB
+#define PCINT14_PORT PORTB
+#define PCINT14_PIN PINB
+#define PCINT14_BIT 6
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 7
+
+#define PCINT15_DDR DDRB
+#define PCINT15_PORT PORTB
+#define PCINT15_PIN PINB
+#define PCINT15_BIT 7
+
+#define RXD_DDR DDRD
+#define RXD_PORT PORTD
+#define RXD_PIN PIND
+#define RXD_BIT 0
+
+#define PCINT24_DDR DDRD
+#define PCINT24_PORT PORTD
+#define PCINT24_PIN PIND
+#define PCINT24_BIT 0
+
+#define TXD_DDR DDRD
+#define TXD_PORT PORTD
+#define TXD_PIN PIND
+#define TXD_BIT 1
+
+#define PCINT25_DDR DDRD
+#define PCINT25_PORT PORTD
+#define PCINT25_PIN PIND
+#define PCINT25_BIT 1
+
+#define INT0_DDR DDRD
+#define INT0_PORT PORTD
+#define INT0_PIN PIND
+#define INT0_BIT 2
+
+#define PCINT26_DDR DDRD
+#define PCINT26_PORT PORTD
+#define PCINT26_PIN PIND
+#define PCINT26_BIT 2
+
+#define INT1_DDR DDRD
+#define INT1_PORT PORTD
+#define INT1_PIN PIND
+#define INT1_BIT 3
+
+#define PCINT27_DDR DDRD
+#define PCINT27_PORT PORTD
+#define PCINT27_PIN PIND
+#define PCINT27_BIT 3
+
+#define OC1B_DDR DDRD
+#define OC1B_PORT PORTD
+#define OC1B_PIN PIND
+#define OC1B_BIT 4
+
+#define PCINT28_DDR DDRD
+#define PCINT28_PORT PORTD
+#define PCINT28_PIN PIND
+#define PCINT28_BIT 4
+
+#define OC1A_DDR DDRD
+#define OC1A_PORT PORTD
+#define OC1A_PIN PIND
+#define OC1A_BIT 5
+
+#define PCINT29_DDR DDRD
+#define PCINT29_PORT PORTD
+#define PCINT29_PIN PIND
+#define PCINT29_BIT 5
+
+#define ICP_DDR DDRD
+#define ICP_PORT PORTD
+#define ICP_PIN PIND
+#define ICP_BIT 6
+
+#define OC2B_DDR DDRD
+#define OC2B_PORT PORTD
+#define OC2B_PIN PIND
+#define OC2B_BIT 6
+
+#define PCINT30_DDR DDRD
+#define PCINT30_PORT PORTD
+#define PCINT30_PIN PIND
+#define PCINT30_BIT 6
+
+#define OC2A_DDR DDRD
+#define OC2A_PORT PORTD
+#define OC2A_PIN PIND
+#define OC2A_BIT 7
+
+#define PCINT31_DDR DDRD
+#define PCINT31_PORT PORTD
+#define PCINT31_PIN PIND
+#define PCINT31_BIT 7
+
+#define SCL_DDR DDRC
+#define SCL_PORT PORTC
+#define SCL_PIN PINC
+#define SCL_BIT 0
+
+#define PCINT16_DDR DDRC
+#define PCINT16_PORT PORTC
+#define PCINT16_PIN PINC
+#define PCINT16_BIT 0
+
+#define SDA_DDR DDRC
+#define SDA_PORT PORTC
+#define SDA_PIN PINC
+#define SDA_BIT 1
+
+#define PCINT17_DDR DDRC
+#define PCINT17_PORT PORTC
+#define PCINT17_PIN PINC
+#define PCINT17_BIT 1
+
+#define PCINT18_DDR DDRC
+#define PCINT18_PORT PORTC
+#define PCINT18_PIN PINC
+#define PCINT18_BIT 2
+
+#define PCINT19_DDR DDRC
+#define PCINT19_PORT PORTC
+#define PCINT19_PIN PINC
+#define PCINT19_BIT 3
+
+#define PCINT20_DDR DDRC
+#define PCINT20_PORT PORTC
+#define PCINT20_PIN PINC
+#define PCINT20_BIT 4
+
+#define PCINT21_DDR DDRC
+#define PCINT21_PORT PORTC
+#define PCINT21_PIN PINC
+#define PCINT21_BIT 5
+
+#define PCINT22_DDR DDRC
+#define PCINT22_PORT PORTC
+#define PCINT22_PIN PINC
+#define PCINT22_BIT 6
+
+#define PCINT23_DDR DDRC
+#define PCINT23_PORT PORTC
+#define PCINT23_PIN PINC
+#define PCINT23_BIT 7
+
+#define ADC7_DDR DDRA
+#define ADC7_PORT PORTA
+#define ADC7_PIN PINA
+#define ADC7_BIT 7
+
+#define PCINT7_DDR DDRA
+#define PCINT7_PORT PORTA
+#define PCINT7_PIN PINA
+#define PCINT7_BIT 7
+
+#define ADC6_DDR DDRA
+#define ADC6_PORT PORTA
+#define ADC6_PIN PINA
+#define ADC6_BIT 6
+
+#define PCINT6_DDR DDRA
+#define PCINT6_PORT PORTA
+#define PCINT6_PIN PINA
+#define PCINT6_BIT 6
+
+#define ADC5_DDR DDRA
+#define ADC5_PORT PORTA
+#define ADC5_PIN PINA
+#define ADC5_BIT 5
+
+#define PCINT5_DDR DDRA
+#define PCINT5_PORT PORTA
+#define PCINT5_PIN PINA
+#define PCINT5_BIT 5
+
+#define ADC4_DDR DDRA
+#define ADC4_PORT PORTA
+#define ADC4_PIN PINA
+#define ADC4_BIT 4
+
+#define PCINT4_DDR DDRA
+#define PCINT4_PORT PORTA
+#define PCINT4_PIN PINA
+#define PCINT4_BIT 4
+
+#define ADC3_DDR DDRA
+#define ADC3_PORT PORTA
+#define ADC3_PIN PINA
+#define ADC3_BIT 3
+
+#define PCINT3_DDR DDRA
+#define PCINT3_PORT PORTA
+#define PCINT3_PIN PINA
+#define PCINT3_BIT 3
+
+#define ADC2_DDR DDRA
+#define ADC2_PORT PORTA
+#define ADC2_PIN PINA
+#define ADC2_BIT 2
+
+#define PCINT2_DDR DDRA
+#define PCINT2_PORT PORTA
+#define PCINT2_PIN PINA
+#define PCINT2_BIT 2
+
+#define ADC1_DDR DDRA
+#define ADC1_PORT PORTA
+#define ADC1_PIN PINA
+#define ADC1_BIT 1
+
+#define PCINT1_DDR DDRA
+#define PCINT1_PORT PORTA
+#define PCINT1_PIN PINA
+#define PCINT1_BIT 1
+
+#define ADC0_DDR DDRA
+#define ADC0_PORT PORTA
+#define ADC0_PIN PINA
+#define ADC0_BIT 0
+
+#define PCINT0_DDR DDRA
+#define PCINT0_PORT PORTA
+#define PCINT0_PIN PINA
+#define PCINT0_BIT 0
+
+#define XCK_DDR DDRB
+#define XCK_PORT PORTB
+#define XCK_PIN PINB
+#define XCK_BIT 0
+
+#define T0_DDR DDRB
+#define T0_PORT PORTB
+#define T0_PIN PINB
+#define T0_BIT 0
+
+#define PCINT8_DDR DDRB
+#define PCINT8_PORT PORTB
+#define PCINT8_PIN PINB
+#define PCINT8_BIT 0
+
+#define T1_DDR DDRB
+#define T1_PORT PORTB
+#define T1_PIN PINB
+#define T1_BIT 1
+
+#define CLKO_DDR DDRB
+#define CLKO_PORT PORTB
+#define CLKO_PIN PINB
+#define CLKO_BIT 1
+
+#define PCINT9_DDR DDRB
+#define PCINT9_PORT PORTB
+#define PCINT9_PIN PINB
+#define PCINT9_BIT 1
+
+#define AIN0_DDR DDRB
+#define AIN0_PORT PORTB
+#define AIN0_PIN PINB
+#define AIN0_BIT 2
+
+#define INT2_DDR DDRB
+#define INT2_PORT PORTB
+#define INT2_PIN PINB
+#define INT2_BIT 2
+
+#define PCINT10_DDR DDRB
+#define PCINT10_PORT PORTB
+#define PCINT10_PIN PINB
+#define PCINT10_BIT 2
+
+#define AIN1_DDR DDRB
+#define AIN1_PORT PORTB
+#define AIN1_PIN PINB
+#define AIN1_BIT 3
+
+#define OC0A_DDR DDRB
+#define OC0A_PORT PORTB
+#define OC0A_PIN PINB
+#define OC0A_BIT 3
+
+#define PCINT11_DDR DDRB
+#define PCINT11_PORT PORTB
+#define PCINT11_PIN PINB
+#define PCINT11_BIT 3
+
+#define SS_DDR DDRB
+#define SS_PORT PORTB
+#define SS_PIN PINB
+#define SS_BIT 4
+
+#define OC0B_DDR DDRB
+#define OC0B_PORT PORTB
+#define OC0B_PIN PINB
+#define OC0B_BIT 4
+
+#define PCINT12_DDR DDRB
+#define PCINT12_PORT PORTB
+#define PCINT12_PIN PINB
+#define PCINT12_BIT 4
+
+#endif /* _AVR_ATmega324PA_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom325.h b/cpukit/score/cpu/avr/avr/iom325.h
new file mode 100644
index 0000000000..d624872e5f
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom325.h
@@ -0,0 +1,821 @@
+/* Copyright (c) 2004, 2005, 2006, 2007 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom325.h - definitions for ATmega325 and ATmega325P. */
+
+#ifndef _AVR_IOM325_H_
+#define _AVR_IOM325_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom325.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#if defined(__AVR_ATmega325P__)
+#define BODSE 5
+#define BODS 6
+#endif
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xFF] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* Vector 22 is Reserved */
+
+#define _VECTORS_SIZE 92
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x8FF
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOM325_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom3250.h b/cpukit/score/cpu/avr/avr/iom3250.h
new file mode 100644
index 0000000000..3499e6584a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom3250.h
@@ -0,0 +1,911 @@
+/* Copyright (c) 2004, 2005, 2006, 2007 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom3250.h - definitions for ATmega3250 and ATmega3250P. */
+
+#ifndef _AVR_IOM3250_H_
+#define _AVR_IOM3250_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom3250.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+#define PCIF2 6
+#define PCIF3 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+#define PCIE2 6
+#define PCIE3 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#if defined(__AVR_ATmega3250P__)
+#define BODSE 5
+#define BODS 6
+#endif
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x72] */
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+
+/* Reserved [0x74..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xD7] */
+
+#define PINH _SFR_MEM8(0xD8)
+#define PINH7 7
+#define PINH6 6
+#define PINH5 5
+#define PINH4 4
+#define PINH3 3
+#define PINH2 2
+#define PINH1 1
+#define PINH0 0
+
+#define DDRH _SFR_MEM8(0xD9)
+#define DDH7 7
+#define DDH6 6
+#define DDH5 5
+#define DDH4 4
+#define DDH3 3
+#define DDH2 2
+#define DDH1 1
+#define DDH0 0
+
+#define PORTH _SFR_MEM8(0xDA)
+#define PH7 7
+#define PH6 6
+#define PH5 5
+#define PH4 4
+#define PH3 3
+#define PH2 2
+#define PH1 1
+#define PH0 0
+
+#define PINJ _SFR_MEM8(0xDB)
+#define PINJ6 6
+#define PINJ5 5
+#define PINJ4 4
+#define PINJ3 3
+#define PINJ2 2
+#define PINJ1 1
+#define PINJ0 0
+
+#define DDRJ _SFR_MEM8(0xDC)
+#define DDJ6 6
+#define DDJ5 5
+#define DDJ4 4
+#define DDJ3 3
+#define DDJ2 2
+#define DDJ1 1
+#define DDJ0 0
+
+#define PORTJ _SFR_MEM8(0xDD)
+#define PJ6 6
+#define PJ5 5
+#define PJ4 4
+#define PJ3 3
+#define PJ2 2
+#define PJ1 1
+#define PJ0 0
+
+/* Reserved [0xDE..0xFF] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(13)
+#define USART0_RX_vect _VECTOR(13) /* Alias */
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART Data register Empty */
+#define USART_UDRE_vect _VECTOR(14)
+#define USART0_UDRE_vect _VECTOR(14) /* Alias */
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define USART_TX_vect _VECTOR(15) /* Alias */
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(23)
+#define SIG_PIN_CHANGE2 _VECTOR(23)
+
+/* Pin Change Interrupt Request 3 */
+#define PCINT3_vect _VECTOR(24)
+#define SIG_PIN_CHANGE3 _VECTOR(24)
+
+#define _VECTORS_SIZE 100
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x8FF
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOM3250_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom328p.h b/cpukit/score/cpu/avr/avr/iom328p.h
new file mode 100644
index 0000000000..a9e41e6ca3
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom328p.h
@@ -0,0 +1,875 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom328p.h - definitions for ATmega328P. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom328p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM328P_H_
+#define _AVR_IOM328P_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define _EEPROM_REG_LOCATIONS_ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 0
+#define TWAM1 1
+#define TWAM2 2
+#define TWAM3 3
+#define TWAM4 4
+#define TWAM5 5
+#define TWAM6 6
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCPHA0 1
+#define UCSZ01 2
+#define UDORD0 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0_0 0
+#define UBRR0_1 1
+#define UBRR0_2 2
+#define UBRR0_3 3
+#define UBRR0_4 4
+#define UBRR0_5 5
+#define UBRR0_6 6
+#define UBRR0_7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR0_8 0
+#define UBRR0_9 1
+#define UBRR0_10 2
+#define UBRR0_11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
+#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
+#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
+#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
+#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
+#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
+#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
+#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
+#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
+#define SPM_READY_vect _VECTOR(25) /* Store Program Memory Read */
+
+#define _VECTORS_SIZE (26 * 4)
+
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x8FF /* Last On-Chip SRAM Location */
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x0F
+
+
+#endif /* _AVR_IOM328P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom329.h b/cpukit/score/cpu/avr/avr/iom329.h
new file mode 100644
index 0000000000..fc96d00a7e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom329.h
@@ -0,0 +1,1003 @@
+/* Copyright (c) 2004 Eric B. Weddington
+ Copyright (c) 2005, 2006, 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom329.h - definitions for ATmega329 and ATmega329P. */
+
+#ifndef _AVR_IOM329_H_
+#define _AVR_IOM329_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom329.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#if defined(__AVR_ATmega329P__)
+#define BODSE 5
+#define BODS 6
+#endif
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xE3] */
+
+#define LCDCRA _SFR_MEM8(0XE4)
+#define LCDBL 0
+#if defined(__AVR_ATmega329P__)
+#define LCDCCD 1
+#define LCDBD 2
+#endif
+#define LCDIE 3
+#define LCDIF 4
+#define LCDAB 6
+#define LCDEN 7
+
+#define LCDCRB _SFR_MEM8(0XE5)
+#define LCDPM0 0
+#define LCDPM1 1
+#define LCDPM2 2
+#define LCDMUX0 4
+#define LCDMUX1 5
+#define LCD2B 6
+#define LCDCS 7
+
+#define LCDFRR _SFR_MEM8(0XE6)
+#define LCDCD0 0
+#define LCDCD1 1
+#define LCDCD2 2
+#define LCDPS0 4
+#define LCDPS1 5
+#define LCDPS2 6
+
+#define LCDCCR _SFR_MEM8(0XE7)
+#define LCDCC0 0
+#define LCDCC1 1
+#define LCDCC2 2
+#define LCDCC3 3
+#if defined(__AVR_ATmega329P__)
+#define LCDMDT 4
+#endif
+#define LCDDC0 5
+#define LCDDC1 6
+#define LCDDC2 7
+
+/* Reserved [0xE8..0xEB] */
+
+#define LCDDR00 _SFR_MEM8(0XEC)
+#define SEG000 0
+#define SEG001 1
+#define SEG002 2
+#define SEG003 3
+#define SEG004 4
+#define SEG005 5
+#define SEG006 6
+#define SEG007 7
+
+#define LCDDR01 _SFR_MEM8(0XED)
+#define SEG008 0
+#define SEG009 1
+#define SEG010 2
+#define SEG011 3
+#define SEG012 4
+#define SEG013 5
+#define SEG014 6
+#define SEG015 7
+
+#define LCDDR02 _SFR_MEM8(0XEE)
+#define SEG016 0
+#define SEG017 1
+#define SEG018 2
+#define SEG019 3
+#define SEG020 4
+#define SEG021 5
+#define SEG022 6
+#define SEG023 7
+
+#define LCDDR03 _SFR_MEM8(0XEF)
+#define SEG024 0
+
+/* Reserved [0xF0] */
+
+#define LCDDR05 _SFR_MEM8(0XF1)
+#define SEG100 0
+#define SEG101 1
+#define SEG102 2
+#define SEG103 3
+#define SEG104 4
+#define SEG105 5
+#define SEG106 6
+#define SEG107 7
+
+#define LCDDR06 _SFR_MEM8(0XF2)
+#define SEG108 0
+#define SEG109 1
+#define SEG110 2
+#define SEG111 3
+#define SEG112 4
+#define SEG113 5
+#define SEG114 6
+#define SEG115 7
+
+#define LCDDR07 _SFR_MEM8(0XF3)
+#define SEG116 0
+#define SEG117 1
+#define SEG118 2
+#define SEG119 3
+#define SEG120 4
+#define SEG121 5
+#define SEG122 6
+#define SEG123 7
+
+#define LCDDR08 _SFR_MEM8(0XF4)
+#define SEG124 0
+
+/* Reserved [0xF5] */
+
+#define LCDDR10 _SFR_MEM8(0XF6)
+#define SEG200 0
+#define SEG201 1
+#define SEG202 2
+#define SEG203 3
+#define SEG204 4
+#define SEG205 5
+#define SEG206 6
+#define SEG207 7
+
+#define LCDDR11 _SFR_MEM8(0XF7)
+#define SEG208 0
+#define SEG209 1
+#define SEG210 2
+#define SEG211 3
+#define SEG212 4
+#define SEG213 5
+#define SEG214 6
+#define SEG215 7
+
+#define LCDDR12 _SFR_MEM8(0XF8)
+#define SEG216 0
+#define SEG217 1
+#define SEG218 2
+#define SEG219 3
+#define SEG220 4
+#define SEG221 5
+#define SEG222 6
+#define SEG223 7
+
+#define LCDDR13 _SFR_MEM8(0XF9)
+#define SEG224 0
+
+/* Reserved [0xFA] */
+
+#define LCDDR15 _SFR_MEM8(0XFB)
+#define SEG300 0
+#define SEG301 1
+#define SEG302 2
+#define SEG303 3
+#define SEG304 4
+#define SEG305 5
+#define SEG306 6
+#define SEG307 7
+
+#define LCDDR16 _SFR_MEM8(0XFC)
+#define SEG308 0
+#define SEG309 1
+#define SEG310 2
+#define SEG311 3
+#define SEG312 4
+#define SEG313 5
+#define SEG314 6
+#define SEG315 7
+
+#define LCDDR17 _SFR_MEM8(0XFD)
+#define SEG316 0
+#define SEG217 1
+#define SEG318 2
+#define SEG319 3
+#define SEG320 4
+#define SEG321 5
+#define SEG322 6
+#define SEG323 7
+
+#define LCDDR18 _SFR_MEM8(0XFE)
+#define SEG324 0
+
+/* Reserved [0xFF] */
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* LCD Start of Frame */
+#define LCD_vect _VECTOR(22)
+#define SIG_LCD _VECTOR(22)
+
+#define _VECTORS_SIZE 92
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x8FF
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IOM329_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom3290.h b/cpukit/score/cpu/avr/avr/iom3290.h
new file mode 100644
index 0000000000..b8ddf19cc6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom3290.h
@@ -0,0 +1,1155 @@
+/* Copyright (c) 2004 Eric B. Weddington
+ Copyright (c) 2005, 2006, 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom3290.h - definitions for ATmega3290 and ATmega3290P. */
+
+#ifndef _AVR_IOM3290_H_
+#define _AVR_IOM3290_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom3290.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+#define PCIF2 6
+#define PCIF3 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+#define PCIE2 6
+#define PCIE3 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#if defined(__AVR_ATmega3290P__)
+#define BODSE 5
+#define BODS 6
+#endif
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x72] */
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+
+/* Reserved [0x74..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xD7] */
+
+#define PINH _SFR_MEM8(0xD8)
+#define PINH7 7
+#define PINH6 6
+#define PINH5 5
+#define PINH4 4
+#define PINH3 3
+#define PINH2 2
+#define PINH1 1
+#define PINH0 0
+
+#define DDRH _SFR_MEM8(0xD9)
+#define DDH7 7
+#define DDH6 6
+#define DDH5 5
+#define DDH4 4
+#define DDH3 3
+#define DDH2 2
+#define DDH1 1
+#define DDH0 0
+
+#define PORTH _SFR_MEM8(0xDA)
+#define PH7 7
+#define PH6 6
+#define PH5 5
+#define PH4 4
+#define PH3 3
+#define PH2 2
+#define PH1 1
+#define PH0 0
+
+#define PINJ _SFR_MEM8(0xDB)
+#define PINJ6 6
+#define PINJ5 5
+#define PINJ4 4
+#define PINJ3 3
+#define PINJ2 2
+#define PINJ1 1
+#define PINJ0 0
+
+#define DDRJ _SFR_MEM8(0xDC)
+#define DDJ6 6
+#define DDJ5 5
+#define DDJ4 4
+#define DDJ3 3
+#define DDJ2 2
+#define DDJ1 1
+#define DDJ0 0
+
+#define PORTJ _SFR_MEM8(0xDD)
+#define PJ6 6
+#define PJ5 5
+#define PJ4 4
+#define PJ3 3
+#define PJ2 2
+#define PJ1 1
+#define PJ0 0
+
+/* Reserved [0xDE..0xE3] */
+
+#define LCDCRA _SFR_MEM8(0XE4)
+#define LCDBL 0
+#if defined(__AVR_ATmega3290P__)
+#define LCDCCD 1
+#define LCDBD 2
+#endif
+#define LCDIE 3
+#define LCDIF 4
+#define LCDAB 6
+#define LCDEN 7
+
+#define LCDCRB _SFR_MEM8(0XE5)
+#define LCDPM0 0
+#define LCDPM1 1
+#define LCDPM2 2
+#define LCDPM3 3
+#define LCDMUX0 4
+#define LCDMUX1 5
+#define LCD2B 6
+#define LCDCS 7
+
+#define LCDFRR _SFR_MEM8(0XE6)
+#define LCDCD0 0
+#define LCDCD1 1
+#define LCDCD2 2
+#define LCDPS0 4
+#define LCDPS1 5
+#define LCDPS2 6
+
+#define LCDCCR _SFR_MEM8(0XE7)
+#define LCDCC0 0
+#define LCDCC1 1
+#define LCDCC2 2
+#define LCDCC3 3
+#if defined(__AVR_ATmega3290P__)
+#define LCDMDT 4
+#endif
+#define LCDDC0 5
+#define LCDDC1 6
+#define LCDDC2 7
+
+/* Reserved [0xE8..0xEB] */
+
+#define LCDDR00 _SFR_MEM8(0XEC)
+#define SEG000 0
+#define SEG001 1
+#define SEG002 2
+#define SEG003 3
+#define SEG004 4
+#define SEG005 5
+#define SEG006 6
+#define SEG007 7
+
+#define LCDDR01 _SFR_MEM8(0XED)
+#define SEG008 0
+#define SEG009 1
+#define SEG010 2
+#define SEG011 3
+#define SEG012 4
+#define SEG013 5
+#define SEG014 6
+#define SEG015 7
+
+#define LCDDR02 _SFR_MEM8(0XEE)
+#define SEG016 0
+#define SEG017 1
+#define SEG018 2
+#define SEG019 3
+#define SEG020 4
+#define SEG021 5
+#define SEG022 6
+#define SEG023 7
+
+#define LCDDR03 _SFR_MEM8(0XEF)
+#define SEG024 0
+#define SEG025 1
+#define SEG026 2
+#define SEG027 3
+#define SEG028 4
+#define SEG029 5
+#define SEG030 6
+#define SEG031 7
+
+#define LCDDR04 _SFR_MEM8(0XF0)
+#define SEG032 0
+#define SEG033 1
+#define SEG034 2
+#define SEG035 3
+#define SEG036 4
+#define SEG037 5
+#define SEG038 6
+#define SEG039 7
+
+#define LCDDR05 _SFR_MEM8(0XF1)
+#define SEG100 0
+#define SEG101 1
+#define SEG102 2
+#define SEG103 3
+#define SEG104 4
+#define SEG105 5
+#define SEG106 6
+#define SEG107 7
+
+#define LCDDR06 _SFR_MEM8(0XF2)
+#define SEG108 0
+#define SEG109 1
+#define SEG110 2
+#define SEG111 3
+#define SEG112 4
+#define SEG113 5
+#define SEG114 6
+#define SEG115 7
+
+#define LCDDR07 _SFR_MEM8(0XF3)
+#define SEG116 0
+#define SEG117 1
+#define SEG118 2
+#define SEG119 3
+#define SEG120 4
+#define SEG121 5
+#define SEG122 6
+#define SEG123 7
+
+#define LCDDR08 _SFR_MEM8(0XF4)
+#define SEG124 0
+#define SEG125 1
+#define SEG126 2
+#define SEG127 3
+#define SEG128 4
+#define SEG129 5
+#define SEG130 6
+#define SEG131 7
+
+#define LCDDR09 _SFR_MEM8(0XF5)
+#define SEG132 0
+#define SEG133 1
+#define SEG134 2
+#define SEG135 3
+#define SEG136 4
+#define SEG137 5
+#define SEG138 6
+#define SEG139 7
+
+#define LCDDR10 _SFR_MEM8(0XF6)
+#define SEG200 0
+#define SEG201 1
+#define SEG202 2
+#define SEG203 3
+#define SEG204 4
+#define SEG205 5
+#define SEG206 6
+#define SEG207 7
+
+#define LCDDR11 _SFR_MEM8(0XF7)
+#define SEG208 0
+#define SEG209 1
+#define SEG210 2
+#define SEG211 3
+#define SEG212 4
+#define SEG213 5
+#define SEG214 6
+#define SEG215 7
+
+#define LCDDR12 _SFR_MEM8(0XF8)
+#define SEG216 0
+#define SEG217 1
+#define SEG218 2
+#define SEG219 3
+#define SEG220 4
+#define SEG221 5
+#define SEG222 6
+#define SEG223 7
+
+#define LCDDR13 _SFR_MEM8(0XF9)
+#define SEG224 0
+#define SEG225 1
+#define SEG226 2
+#define SEG227 3
+#define SEG228 4
+#define SEG229 5
+#define SEG230 6
+#define SEG231 7
+
+#define LCDDR14 _SFR_MEM8(0XFA)
+#define SEG232 0
+#define SEG233 1
+#define SEG234 2
+#define SEG235 3
+#define SEG236 4
+#define SEG237 5
+#define SEG238 6
+#define SEG239 7
+
+#define LCDDR15 _SFR_MEM8(0XFB)
+#define SEG300 0
+#define SEG301 1
+#define SEG302 2
+#define SEG303 3
+#define SEG304 4
+#define SEG305 5
+#define SEG306 6
+#define SEG307 7
+
+#define LCDDR16 _SFR_MEM8(0XFC)
+#define SEG308 0
+#define SEG309 1
+#define SEG310 2
+#define SEG311 3
+#define SEG312 4
+#define SEG313 5
+#define SEG314 6
+#define SEG315 7
+
+#define LCDDR17 _SFR_MEM8(0XFD)
+#define SEG316 0
+#define SEG217 1
+#define SEG318 2
+#define SEG319 3
+#define SEG320 4
+#define SEG321 5
+#define SEG322 6
+#define SEG323 7
+
+#define LCDDR18 _SFR_MEM8(0XFE)
+#define SEG324 0
+#define SEG325 1
+#define SEG326 2
+#define SEG327 3
+#define SEG328 4
+#define SEG329 5
+#define SEG330 6
+#define SEG331 7
+
+#define LCDDR19 _SFR_MEM8(0XFF)
+#define SEG332 0
+#define SEG333 1
+#define SEG334 2
+#define SEG335 3
+#define SEG336 4
+#define SEG337 5
+#define SEG338 6
+#define SEG339 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART Data register Empty */
+#define USART_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* LCD Start of Frame */
+#define LCD_vect _VECTOR(22)
+#define SIG_LCD _VECTOR(22)
+
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(23)
+#define SIG_PIN_CHANGE2 _VECTOR(23)
+
+/* Pin Change Interrupt Request 3 */
+#define PCINT3_vect _VECTOR(24)
+#define SIG_PIN_CHANGE3 _VECTOR(24)
+
+#define _VECTORS_SIZE 100
+
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x8FF
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x04
+
+
+#endif /* _AVR_IOM3290_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom32c1.h b/cpukit/score/cpu/avr/avr/iom32c1.h
new file mode 100644
index 0000000000..1539c5564e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32c1.h
@@ -0,0 +1,1297 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom32c1.h - definitions for ATmega32C1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32c1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega32C1_H_
+#define _AVR_ATmega32C1_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 6
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC3O 3
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define AC3IF 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRLIN 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC 5
+#define PRCAN 6
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6A)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6B)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6C)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define PCMSK3 _SFR_MEM8(0x6D)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x75)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0TS2 2
+#define AMPCMP0 3
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x76)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1TS2 2
+#define AMPCMP1 3
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#define AMP2CSR _SFR_MEM8(0x77)
+#define AMP2TS0 0
+#define AMP2TS1 1
+#define AMP2TS2 2
+#define AMPCMP2 3
+#define AMP2G0 4
+#define AMP2G1 5
+#define AMP2IS 6
+#define AMP2EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define AREFEN 5
+#define ISRCEN 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+#define AMP2PD 6
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define DACON _SFR_MEM8(0x90)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0x91)
+
+#define DACL _SFR_MEM8(0x91)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0x92)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0x94)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define ACCKSEL 3
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0x95)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0x96)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define AC3CON _SFR_MEM8(0x97)
+#define AC3M0 0
+#define AC3M1 1
+#define AC3M2 2
+#define AC3IS0 4
+#define AC3IS1 5
+#define AC3IE 6
+#define AC3EN 7
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+#define CANGCON _SFR_MEM8(0xD8)
+#define SWRES 0
+#define ENASTB 1
+#define TEST 2
+#define LISTEN 3
+#define SYNTTC 4
+#define TTC 5
+#define OVRQ 6
+#define ABRQ 7
+
+#define CANGSTA _SFR_MEM8(0xD9)
+#define ERRP 0
+#define BOFF 1
+#define ENFG 2
+#define RXBSY 3
+#define TXBSY 4
+#define OVFG 6
+
+#define CANGIT _SFR_MEM8(0xDA)
+#define AERG 0
+#define FERG 1
+#define CERG 2
+#define SERG 3
+#define BXOK 4
+#define OVRTIM 5
+#define BOFFIT 6
+#define CANIT 7
+
+#define CANGIE _SFR_MEM8(0xDB)
+#define ENOVRT 0
+#define ENERG 1
+#define ENBX 2
+#define ENERR 3
+#define ENTX 4
+#define ENRX 5
+#define ENBOFF 6
+#define ENIT 7
+
+#define CANEN2 _SFR_MEM8(0xDC)
+#define ENMOB0 0
+#define ENMOB1 1
+#define ENMOB2 2
+#define ENMOB3 3
+#define ENMOB4 4
+#define ENMOB5 5
+
+#define CANEN1 _SFR_MEM8(0xDD)
+
+#define CANIE2 _SFR_MEM8(0xDE)
+#define IEMOB0 0
+#define IEMOB1 1
+#define IEMOB2 2
+#define IEMOB3 3
+#define IEMOB4 4
+#define IEMOB5 5
+
+#define CANIE1 _SFR_MEM8(0xDF)
+
+#define CANSIT2 _SFR_MEM8(0xE0)
+#define SIT0 0
+#define SIT1 1
+#define SIT2 2
+#define SIT3 3
+#define SIT4 4
+#define SIT5 5
+
+#define CANSIT1 _SFR_MEM8(0xE1)
+
+#define CANBT1 _SFR_MEM8(0xE2)
+#define BRP0 1
+#define BRP1 2
+#define BRP2 3
+#define BRP3 4
+#define BRP4 5
+#define BRP5 6
+
+#define CANBT2 _SFR_MEM8(0xE3)
+#define PRS0 1
+#define PRS1 2
+#define PRS2 3
+#define SJW0 5
+#define SJW1 6
+
+#define CANBT3 _SFR_MEM8(0xE4)
+#define SMP 0
+#define PHS10 1
+#define PHS11 2
+#define PHS12 3
+#define PHS20 4
+#define PHS21 5
+#define PHS22 6
+
+#define CANTCON _SFR_MEM8(0xE5)
+#define TPRSC0 0
+#define TPRSC1 1
+#define TPRSC2 2
+#define TPRSC3 3
+#define TPRSC4 4
+#define TPRSC5 5
+#define TPRSC6 6
+#define TPRSC7 7
+
+#define CANTIM _SFR_MEM16(0xE6)
+
+#define CANTIML _SFR_MEM8(0xE6)
+#define CANTIM0 0
+#define CANTIM1 1
+#define CANTIM2 2
+#define CANTIM3 3
+#define CANTIM4 4
+#define CANTIM5 5
+#define CANTIM6 6
+#define CANTIM7 7
+
+#define CANTIMH _SFR_MEM8(0xE7)
+#define CANTIM8 0
+#define CANTIM9 1
+#define CANTIM10 2
+#define CANTIM11 3
+#define CANTIM12 4
+#define CANTIM13 5
+#define CANTIM14 6
+#define CANTIM15 7
+
+#define CANTTC _SFR_MEM16(0xE8)
+
+#define CANTTCL _SFR_MEM8(0xE8)
+#define TIMTCC0 0
+#define TIMTCC1 1
+#define TIMTCC2 2
+#define TIMTCC3 3
+#define TIMTCC4 4
+#define TIMTCC5 5
+#define TIMTCC6 6
+#define TIMTCC7 7
+
+#define CANTTCH _SFR_MEM8(0xE9)
+#define TIMTCC8 0
+#define TIMTCC9 1
+#define TIMTCC10 2
+#define TIMTCC11 3
+#define TIMTCC12 4
+#define TIMTCC13 5
+#define TIMTCC14 6
+#define TIMTCC15 7
+
+#define CANTEC _SFR_MEM8(0xEA)
+#define TEC0 0
+#define TEC1 1
+#define TEC2 2
+#define TEC3 3
+#define TEC4 4
+#define TEC5 5
+#define TEC6 6
+#define TEC7 7
+
+#define CANREC _SFR_MEM8(0xEB)
+#define REC0 0
+#define REC1 1
+#define REC2 2
+#define REC3 3
+#define REC4 4
+#define REC5 5
+#define REC6 6
+#define REC7 7
+
+#define CANHPMOB _SFR_MEM8(0xEC)
+#define CGP0 0
+#define CGP1 1
+#define CGP2 2
+#define CGP3 3
+#define HPMOB0 4
+#define HPMOB1 5
+#define HPMOB2 6
+#define HPMOB3 7
+
+#define CANPAGE _SFR_MEM8(0xED)
+#define INDX0 0
+#define INDX1 1
+#define INDX2 2
+#define AINC 3
+#define MOBNB0 4
+#define MOBNB1 5
+#define MOBNB2 6
+#define MOBNB3 7
+
+#define CANSTMOB _SFR_MEM8(0xEE)
+#define AERR 0
+#define FERR 1
+#define CERR 2
+#define SERR 3
+#define BERR 4
+#define RXOK 5
+#define TXOK 6
+#define DLCW 7
+
+#define CANCDMOB _SFR_MEM8(0xEF)
+#define DLC0 0
+#define DLC1 1
+#define DLC2 2
+#define DLC3 3
+#define IDE 4
+#define RPLV 5
+#define CONMOB0 6
+#define CONMOB1 7
+
+#define CANIDT4 _SFR_MEM8(0xF0)
+#define RB0TAG 0
+#define RB1TAG 1
+#define RTRTAG 2
+#define IDT0 3
+#define IDT1 4
+#define IDT2 5
+#define IDT3 6
+#define IDT4 7
+
+#define CANIDT3 _SFR_MEM8(0xF1)
+#define IDT5 0
+#define IDT6 1
+#define IDT7 2
+#define IDT8 3
+#define IDT9 4
+#define IDT10 5
+#define IDT11 6
+#define IDT12 7
+
+#define CANIDT2 _SFR_MEM8(0xF2)
+#define IDT13 0
+#define IDT14 1
+#define IDT15 2
+#define IDT16 3
+#define IDT17 4
+#define IDT18 5
+#define IDT19 6
+#define IDT20 7
+
+#define CANIDT1 _SFR_MEM8(0xF3)
+#define IDT21 0
+#define IDT22 1
+#define IDT23 2
+#define IDT24 3
+#define IDT25 4
+#define IDT26 5
+#define IDT27 6
+#define IDT28 7
+
+#define CANIDM4 _SFR_MEM8(0xF4)
+#define IDEMSK 0
+#define RTRMSK 2
+#define IDMSK0 3
+#define IDMSK1 4
+#define IDMSK2 5
+#define IDMSK3 6
+#define IDMSK4 7
+
+#define CANIDM3 _SFR_MEM8(0xF5)
+#define IDMSK5 0
+#define IDMSK6 1
+#define IDMSK7 2
+#define IDMSK8 3
+#define IDMSK9 4
+#define IDMSK10 5
+#define IDMSK11 6
+#define IDMSK12 7
+
+#define CANIDM2 _SFR_MEM8(0xF6)
+#define IDMSK13 0
+#define IDMSK14 1
+#define IDMSK15 2
+#define IDMSK16 3
+#define IDMSK17 4
+#define IDMSK18 5
+#define IDMSK19 6
+#define IDMSK20 7
+
+#define CANIDM1 _SFR_MEM8(0xF7)
+#define IDMSK21 0
+#define IDMSK22 1
+#define IDMSK23 2
+#define IDMSK24 3
+#define IDMSK25 4
+#define IDMSK26 5
+#define IDMSK27 6
+#define IDMSK28 7
+
+#define CANSTM _SFR_MEM16(0xF8)
+
+#define CANSTML _SFR_MEM8(0xF8)
+#define TIMSTM0 0
+#define TIMSTM1 1
+#define TIMSTM2 2
+#define TIMSTM3 3
+#define TIMSTM4 4
+#define TIMSTM5 5
+#define TIMSTM6 6
+#define TIMSTM7 7
+
+#define CANSTMH _SFR_MEM8(0xF9)
+#define TIMSTM8 0
+#define TIMSTM9 1
+#define TIMSTM10 2
+#define TIMSTM11 3
+#define TIMSTM12 4
+#define TIMSTM13 5
+#define TIMSTM14 6
+#define TIMSTM15 7
+
+#define CANMSG _SFR_MEM8(0xFA)
+#define MSG0 0
+#define MSG1 1
+#define MSG2 2
+#define MSG3 3
+#define MSG4 4
+#define MSG5 5
+#define MSG6 6
+#define MSG7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define ANACOMP0_vect_num 1
+#define ANACOMP0_vect _VECTOR(1) /* Analog Comparator 0 */
+#define ANACOMP1_vect_num 2
+#define ANACOMP1_vect _VECTOR(2) /* Analog Comparator 1 */
+#define ANACOMP2_vect_num 3
+#define ANACOMP2_vect _VECTOR(3) /* Analog Comparator 2 */
+#define ANACOMP3_vect_num 4
+#define ANACOMP3_vect _VECTOR(4) /* Analog Comparator 3 */
+#define PSC_FAULT_vect_num 5
+#define PSC_FAULT_vect _VECTOR(5) /* PSC Fault */
+#define PSC_EC_vect_num 6
+#define PSC_EC_vect _VECTOR(6) /* PSC End of Cycle */
+#define INT0_vect_num 7
+#define INT0_vect _VECTOR(7) /* External Interrupt Request 0 */
+#define INT1_vect_num 8
+#define INT1_vect _VECTOR(8) /* External Interrupt Request 1 */
+#define INT2_vect_num 9
+#define INT2_vect _VECTOR(9) /* External Interrupt Request 2 */
+#define INT3_vect_num 10
+#define INT3_vect _VECTOR(10) /* External Interrupt Request 3 */
+#define TIMER1_CAPT_vect_num 11
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 12
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 13
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 14
+#define TIMER1_OVF_vect _VECTOR(14) /* Timer1/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 15
+#define TIMER0_COMPA_vect _VECTOR(15) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 16
+#define TIMER0_COMPB_vect _VECTOR(16) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 17
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define CAN_INT_vect_num 18
+#define CAN_INT_vect _VECTOR(18) /* CAN MOB, Burst, General Errors */
+#define CAN_TOVF_vect_num 19
+#define CAN_TOVF_vect _VECTOR(19) /* CAN Timer Overflow */
+#define LIN_TC_vect_num 20
+#define LIN_TC_vect _VECTOR(20) /* LIN Transfer Complete */
+#define LIN_ERR_vect_num 21
+#define LIN_ERR_vect _VECTOR(21) /* LIN Error */
+#define PCINT0_vect_num 22
+#define PCINT0_vect _VECTOR(22) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 23
+#define PCINT1_vect _VECTOR(23) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 24
+#define PCINT2_vect _VECTOR(24) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 25
+#define PCINT3_vect _VECTOR(25) /* Pin Change Interrupt Request 3 */
+#define SPI_STC_vect_num 26
+#define SPI_STC_vect _VECTOR(26) /* SPI Serial Transfer Complete */
+#define ADC_vect_num 27
+#define ADC_vect _VECTOR(27) /* ADC Conversion Complete */
+#define WDT_vect_num 28
+#define WDT_vect _VECTOR(28) /* Watchdog Time-Out Interrupt */
+#define EE_READY_vect_num 29
+#define EE_READY_vect _VECTOR(29) /* EEPROM Ready */
+#define SPM_READY_vect_num 30
+#define SPM_READY_vect _VECTOR(30) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x0100)
+#define RAMSIZE (2048)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector Trigger Level */
+#define FUSE_PSCRVB (unsigned char)~_BV(3) /* PSC Outputs xB Reset Value */
+#define FUSE_PSCRVA (unsigned char)~_BV(4) /* PSC Outputs xA Reset Value */
+#define FUSE_PSCRB (unsigned char)~_BV(5) /* PSC Reset Behavior */
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_BODLEVEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x86
+
+
+#endif /* _AVR_ATmega32C1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom32hvb.h b/cpukit/score/cpu/avr/avr/iom32hvb.h
new file mode 100644
index 0000000000..c732387c7b
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32hvb.h
@@ -0,0 +1,885 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom32hvb.h - definitions for ATmega32HVB. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32hvb.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM32HVB_H_
+#define _AVR_IOM32HVB_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+#define ICF0 3
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 3
+
+#define OSICSR _SFR_IO8(0x17)
+#define OSIEN 0
+#define OSIST 1
+#define OSISEL0 4
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define ICS0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+
+#define TCNT0 _SFR_IO16(0x26)
+
+#define TCNT0L _SFR_IO8(0x26)
+#define TCNT0L0 0
+#define TCNT0L1 1
+#define TCNT0L2 2
+#define TCNT0L3 3
+#define TCNT0L4 4
+#define TCNT0L5 5
+#define TCNT0L6 6
+#define TCNT0L7 7
+
+#define TCNT0H _SFR_IO8(0x27)
+#define TCNT0H0 0
+#define TCNT0H1 1
+#define TCNT0H2 2
+#define TCNT0H3 3
+#define TCNT0H4 4
+#define TCNT0H5 5
+#define TCNT0H6 6
+#define TCNT0H7 7
+
+#define OCR0A _SFR_IO8(0x28)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+#define OCR0B _SFR_IO8(0x29)
+#define OCR0B0 0
+#define OCR0B1 1
+#define OCR0B2 2
+#define OCR0B3 3
+#define OCR0B4 4
+#define OCR0B5 5
+#define OCR0B6 6
+#define OCR0B7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BODRF 2
+#define WDRF 3
+#define OCDRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define CKOE 5
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define LBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRVADC 0
+#define PRTIM0 1
+#define PRTIM1 2
+#define PRSPI 3
+#define PRVRM 5
+#define PRTWI 6
+
+#define FOSCCAL _SFR_MEM8(0x66)
+#define FCAL0 0
+#define FCAL1 1
+#define FCAL2 2
+#define FCAL3 3
+#define FCAL4 4
+#define FCAL5 5
+#define FCAL6 6
+#define FCAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT4 0
+#define PCINT5 1
+#define PCINT6 2
+#define PCINT7 3
+#define PCINT8 4
+#define PCINT9 5
+#define PCINT10 6
+#define PCINT11 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+#define ICIE0 3
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 3
+
+#define VADC _SFR_MEM16(0x78)
+
+#define VADCL _SFR_MEM8(0x78)
+#define VADC0 0
+#define VADC1 1
+#define VADC2 2
+#define VADC3 3
+#define VADC4 4
+#define VADC5 5
+#define VADC6 6
+#define VADC7 7
+
+#define VADCH _SFR_MEM8(0x79)
+#define VADC8 0
+#define VADC9 1
+#define VADC10 2
+#define VADC11 3
+
+#define VADCSR _SFR_MEM8(0x7A)
+#define VADCCIE 0
+#define VADCCIF 1
+#define VADSC 2
+#define VADEN 3
+
+#define VADMUX _SFR_MEM8(0x7C)
+#define VADMUX0 0
+#define VADMUX1 1
+#define VADMUX2 2
+#define VADMUX3 3
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define PA0DID 0
+#define PA1DID 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define ICS1 3
+#define ICES1 4
+#define ICNC1 5
+#define ICEN1 6
+#define TCW1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define OCR1A _SFR_MEM8(0x88)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define OCR1B _SFR_MEM8(0x89)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 0
+#define TWAM1 1
+#define TWAM2 2
+#define TWAM3 3
+#define TWAM4 4
+#define TWAM5 5
+#define TWAM6 6
+
+#define TWBCSR _SFR_MEM8(0xBE)
+#define TWBCIP 0
+#define TWBDT0 1
+#define TWBDT1 2
+#define TWBCIE 6
+#define TWBCIF 7
+
+#define ROCR _SFR_MEM8(0xC8)
+#define ROCWIE 0
+#define ROCWIF 1
+#define ROCD 4
+#define ROCS 7
+
+#define BGCCR _SFR_MEM8(0xD0)
+#define BGCC0 0
+#define BGCC1 1
+#define BGCC2 2
+#define BGCC3 3
+#define BGCC4 4
+#define BGCC5 5
+
+#define BGCRR _SFR_MEM8(0xD1)
+#define BGCR0 0
+#define BGCR1 1
+#define BGCR2 2
+#define BGCR3 3
+#define BGCR4 4
+#define BGCR5 5
+#define BGCR6 6
+#define BGCR7 7
+
+#define BGCSR _SFR_MEM8(0xD2)
+#define BGSCDIE 0
+#define BGSCDIF 1
+#define BGSCDE 4
+#define BGD 5
+
+#define CHGDCSR _SFR_MEM8(0xD4)
+#define CHGDIE 0
+#define CHGDIF 1
+#define CHGDISC0 2
+#define CHGDISC1 3
+#define BATTPVL 4
+
+#define CADAC _SFR_MEM32(0xE0)
+
+#define CADAC0 _SFR_MEM8(0xE0)
+#define CADAC00 0
+#define CADAC01 1
+#define CADAC02 2
+#define CADAC03 3
+#define CADAC04 4
+#define CADAC05 5
+#define CADAC06 6
+#define CADAC07 7
+
+#define CADAC1 _SFR_MEM8(0xE1)
+#define CADAC08 0
+#define CADAC09 1
+#define CADAC10 2
+#define CADAC11 3
+#define CADAC12 4
+#define CADAC13 5
+#define CADAC14 6
+#define CADAC15 7
+
+#define CADAC2 _SFR_MEM8(0xE2)
+#define CADAC16 0
+#define CADAC17 1
+#define CADAC18 2
+#define CADAC19 3
+#define CADAC20 4
+#define CADAC21 5
+#define CADAC22 6
+#define CADAC23 7
+
+#define CADAC3 _SFR_MEM8(0xE3)
+#define CADAC24 0
+#define CADAC25 1
+#define CADAC26 2
+#define CADAC27 3
+#define CADAC28 4
+#define CADAC29 5
+#define CADAC30 6
+#define CADAC31 7
+
+#define CADIC _SFR_MEM16(0xE4)
+
+#define CADICL _SFR_MEM8(0xE4)
+#define CADICL0 0
+#define CADICL1 1
+#define CADICL2 2
+#define CADICL3 3
+#define CADICL4 4
+#define CADICL5 5
+#define CADICL6 6
+#define CADICL7 7
+
+#define CADICH _SFR_MEM8(0xE5)
+#define CADICH0 0
+#define CADICH1 1
+#define CADICH2 2
+#define CADICH3 3
+#define CADICH4 4
+#define CADICH5 5
+#define CADICH6 6
+#define CADICH7 7
+
+#define CADCSRA _SFR_MEM8(0xE6)
+#define CADSE 0
+#define CADSI0 1
+#define CADSI1 2
+#define CADAS0 3
+#define CADAS1 4
+#define CADUB 5
+#define CADPOL 6
+#define CADEN 7
+
+#define CADCSRB _SFR_MEM8(0xE7)
+#define CADICIF 0
+#define CADRCIF 1
+#define CADACIF 2
+#define CADICIE 4
+#define CADRCIE 5
+#define CADACIE 6
+
+#define CADCSRC _SFR_MEM8(0xE8)
+#define CADVSE 0
+
+#define CADRCC _SFR_MEM8(0xE9)
+#define CADRCC0 0
+#define CADRCC1 1
+#define CADRCC2 2
+#define CADRCC3 3
+#define CADRCC4 4
+#define CADRCC5 5
+#define CADRCC6 6
+#define CADRCC7 7
+
+#define CADRDC _SFR_MEM8(0xEA)
+#define CADRDC0 0
+#define CADRDC1 1
+#define CADRDC2 2
+#define CADRDC3 3
+#define CADRDC4 4
+#define CADRDC5 5
+#define CADRDC6 6
+#define CADRDC7 7
+
+#define FCSR _SFR_MEM8(0xF0)
+#define CFE 0
+#define DFE 1
+#define CPS 2
+#define DUVRD 3
+
+#define CBCR _SFR_MEM8(0xF1)
+#define CBE1 0
+#define CBE2 1
+#define CBE3 2
+#define CBE4 3
+
+#define BPIMSK _SFR_MEM8(0xF2)
+#define CHCIE 0
+#define DHCIE 1
+#define COCIE 2
+#define DOCIE 3
+#define SCIE 4
+
+#define BPIFR _SFR_MEM8(0xF3)
+#define CHCIF 0
+#define DHCIF 1
+#define COCIF 2
+#define DOCIF 3
+#define SCIF 4
+
+#define BPSCD _SFR_MEM8(0xF5)
+#define SCDL0 0
+#define SCDL1 1
+#define SCDL2 2
+#define SCDL3 3
+#define SCDL4 4
+#define SCDL5 5
+#define SCDL6 6
+#define SCDL7 7
+
+#define BPDOCD _SFR_MEM8(0xF6)
+#define DOCDL0 0
+#define DOCDL1 1
+#define DOCDL2 2
+#define DOCDL3 3
+#define DOCDL4 4
+#define DOCDL5 5
+#define DOCDL6 6
+#define DOCDL7 7
+
+#define BPCOCD _SFR_MEM8(0xF7)
+#define COCDL0 0
+#define COCDL1 1
+#define COCDL2 2
+#define COCDL3 3
+#define COCDL4 4
+#define COCDL5 5
+#define COCDL6 6
+#define COCDL7 7
+
+#define BPDHCD _SFR_MEM8(0xF8)
+#define DHCDL0 0
+#define DHCDL1 1
+#define DHCDL2 2
+#define DHCDL3 3
+#define DHCDL4 4
+#define DHCDL5 5
+#define DHCDL6 6
+#define DHCDL7 7
+
+#define BPCHCD _SFR_MEM8(0xF9)
+#define CHCDL0 0
+#define CHCDL1 1
+#define CHCDL2 2
+#define CHCDL3 3
+#define CHCDL4 4
+#define CHCDL5 5
+#define CHCDL6 6
+#define CHCDL7 7
+
+#define BPSCTR _SFR_MEM8(0xFA)
+#define SCPT0 0
+#define SCPT1 1
+#define SCPT2 2
+#define SCPT3 3
+#define SCPT4 4
+#define SCPT5 5
+#define SCPT6 6
+
+#define BPOCTR _SFR_MEM8(0xFB)
+#define OCPT0 0
+#define OCPT1 1
+#define OCPT2 2
+#define OCPT3 3
+#define OCPT4 4
+#define OCPT5 5
+
+#define BPHCTR _SFR_MEM8(0xFC)
+#define HCPT0 0
+#define HCPT1 1
+#define HCPT2 2
+#define HCPT3 3
+#define HCPT4 4
+#define HCPT5 5
+
+#define BPCR _SFR_MEM8(0xFD)
+#define CHCD 0
+#define DHCD 1
+#define COCD 2
+#define DOCD 3
+#define SCD 4
+#define EPID 5
+
+#define BPPLR _SFR_MEM8(0xFE)
+#define BPPL 0
+#define BPPLE 1
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+
+#define BPINT_vect _VECTOR(1) /* Battery Protection Interrupt */
+#define VREGMON_vect _VECTOR(2) /* Voltage regulator monitor interrupt */
+#define INT0_vect _VECTOR(3) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(4) /* External Interrupt Request 1 */
+#define INT2_vect _VECTOR(5) /* External Interrupt Request 2 */
+#define INT3_vect _VECTOR(6) /* External Interrupt Request 3 */
+#define PCINT0_vect _VECTOR(7) /* Pin Change Interrupt 0 */
+#define PCINT1_vect _VECTOR(8) /* Pin Change Interrupt 1 */
+#define WDT_vect _VECTOR(9) /* Watchdog Timeout Interrupt */
+#define BGSCD_vect _VECTOR(10) /* Bandgap Buffer Short Circuit Detected */
+#define CHDET_vect _VECTOR(11) /* Charger Detect */
+#define TIMER1_IC_vect _VECTOR(12) /* Timer 1 Input capture */
+#define TIMER1_COMPA_vect _VECTOR(13) /* Timer 1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(14) /* Timer 1 Compare Match B */
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer 1 overflow */
+#define TIMER0_IC_vect _VECTOR(16) /* Timer 0 Input Capture */
+#define TIMER0_COMPA_vect _VECTOR(17) /* Timer 0 Comapre Match A */
+#define TIMER0_COMPB_vect _VECTOR(18) /* Timer 0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(19) /* Timer 0 Overflow */
+#define TWIBUSCD_vect _VECTOR(20) /* Two-Wire Bus Connect/Disconnect */
+#define TWI_vect _VECTOR(21) /* Two-Wire Serial Interface */
+#define SPI_STC_vect _VECTOR(22) /* SPI Serial transfer complete */
+#define VADC_vect _VECTOR(23) /* Voltage ADC Conversion Complete */
+#define CCADC_CONV_vect _VECTOR(24) /* Coulomb Counter ADC Conversion Complete */
+#define CCADC_REG_CUR_vect _VECTOR(25) /* Coloumb Counter ADC Regular Current */
+#define CCADC_ACC_vect _VECTOR(26) /* Coloumb Counter ADC Accumulator */
+#define EE_READY_vect _VECTOR(27) /* EEPROM Ready */
+#define SPM_vect _VECTOR(28) /* SPM Ready */
+
+#define _VECTORS_SIZE (29 * 4)
+
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x8FF /* Last On-Chip SRAM Location */
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x3FF
+#define FLASHEND 0x7FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_WDTON (unsigned char)~_BV(7) /* Watchdog Timer Always On */
+#define FUSE_EESAVE (unsigned char)~_BV(6) /* EEPROM memory is preserved through chip erase */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_SUT2 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Select start-up time */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Select start-up time */
+#define FUSE_OSCSEL1 (unsigned char)~_BV(1) /* Oscillator Select */
+#define FUSE_OSCSEL0 (unsigned char)~_BV(0) /* Oscillator Select */
+#define LFUSE_DEFAULT (FUSE_OSCSEL0 & FUSE_SPIEN)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_DWEN (unsigned char)~_BV(3) /* Enable debugWire */
+#define FUSE_DUVRDINIT (unsigned char)~_BV(4) /* Reset Value of DUVRDRegister */
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_DUVRDINIT)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+#endif /* _AVR_IOM32HVB_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom32m1.h b/cpukit/score/cpu/avr/avr/iom32m1.h
new file mode 100644
index 0000000000..2a97ba31e8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32m1.h
@@ -0,0 +1,1571 @@
+/* Copyright (c) 2008-2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom32m1.h - definitions for ATmega32M1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32m1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega32M1_H_
+#define _AVR_ATmega32M1_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 6
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC3O 3
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define AC3IF 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRLIN 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC 5
+#define PRCAN 6
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6A)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6B)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6C)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define PCMSK3 _SFR_MEM8(0x6D)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x75)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0TS2 2
+#define AMPCMP0 3
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x76)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1TS2 2
+#define AMPCMP1 3
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#define AMP2CSR _SFR_MEM8(0x77)
+#define AMP2TS0 0
+#define AMP2TS1 1
+#define AMP2TS2 2
+#define AMPCMP2 3
+#define AMP2G0 4
+#define AMP2G1 5
+#define AMP2IS 6
+#define AMP2EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define AREFEN 5
+#define ISRCEN 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+#define AMP2PD 6
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define DACON _SFR_MEM8(0x90)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0x91)
+
+#define DACL _SFR_MEM8(0x91)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0x92)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0x94)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define ACCKSEL 3
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0x95)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0x96)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define AC3CON _SFR_MEM8(0x97)
+#define AC3M0 0
+#define AC3M1 1
+#define AC3M2 2
+#define AC3IS0 4
+#define AC3IS1 5
+#define AC3IE 6
+#define AC3EN 7
+
+#define POCR0SA _SFR_MEM16(0xA0)
+
+#define POCR0SAL _SFR_MEM8(0xA0)
+#define POCR0SA_0 0
+#define POCR0SA_1 1
+#define POCR0SA_2 2
+#define POCR0SA_3 3
+#define POCR0SA_4 4
+#define POCR0SA_5 5
+#define POCR0SA_6 6
+#define POCR0SA_7 7
+
+#define POCR0SAH _SFR_MEM8(0xA1)
+#define POCR0SA_8 0
+#define POCR0SA_9 1
+#define POCR0SA_10 2
+#define POCR0SA_11 3
+#define POCR0SA_00 2 /* Deprecated */
+#define POCR0SA_01 3 /* Deprecated */
+
+#define POCR0RA _SFR_MEM16(0xA2)
+
+#define POCR0RAL _SFR_MEM8(0xA2)
+#define POCR0RA_0 0
+#define POCR0RA_1 1
+#define POCR0RA_2 2
+#define POCR0RA_3 3
+#define POCR0RA_4 4
+#define POCR0RA_5 5
+#define POCR0RA_6 6
+#define POCR0RA_7 7
+
+#define POCR0RAH _SFR_MEM8(0xA3)
+#define POCR0RA_8 0
+#define POCR0RA_9 1
+#define POCR0RA_10 2
+#define POCR0RA_11 3
+#define POCR0RA_00 2 /* Deprecated */
+#define POCR0RA_01 3 /* Deprecated */
+
+#define POCR0SB _SFR_MEM16(0xA4)
+
+#define POCR0SBL _SFR_MEM8(0xA4)
+#define POCR0SB_0 0
+#define POCR0SB_1 1
+#define POCR0SB_2 2
+#define POCR0SB_3 3
+#define POCR0SB_4 4
+#define POCR0SB_5 5
+#define POCR0SB_6 6
+#define POCR0SB_7 7
+
+#define POCR0SBH _SFR_MEM8(0xA5)
+#define POCR0SB_8 0
+#define POCR0SB_9 1
+#define POCR0SB_10 2
+#define POCR0SB_11 3
+#define POCR0SB_00 2 /* Deprecated */
+#define POCR0SB_01 3 /* Deprecated */
+
+#define POCR1SA _SFR_MEM16(0xA6)
+
+#define POCR1SAL _SFR_MEM8(0xA6)
+#define POCR1SA_0 0
+#define POCR1SA_1 1
+#define POCR1SA_2 2
+#define POCR1SA_3 3
+#define POCR1SA_4 4
+#define POCR1SA_5 5
+#define POCR1SA_6 6
+#define POCR1SA_7 7
+
+#define POCR1SAH _SFR_MEM8(0xA7)
+#define POCR1SA_8 0
+#define POCR1SA_9 1
+#define POCR1SA_10 2
+#define POCR1SA_11 3
+#define POCR1SA_00 2 /* Deprecated */
+#define POCR1SA_01 3 /* Deprecated */
+
+#define POCR1RA _SFR_MEM16(0xA8)
+
+#define POCR1RAL _SFR_MEM8(0xA8)
+#define POCR1RA_0 0
+#define POCR1RA_1 1
+#define POCR1RA_2 2
+#define POCR1RA_3 3
+#define POCR1RA_4 4
+#define POCR1RA_5 5
+#define POCR1RA_6 6
+#define POCR1RA_7 7
+
+#define POCR1RAH _SFR_MEM8(0xA9)
+#define POCR1RA_8 0
+#define POCR1RA_9 1
+#define POCR1RA_10 2
+#define POCR1RA_11 3
+#define POCR1RA_00 2 /* Deprecated */
+
+#define POCR1SB _SFR_MEM16(0xAA)
+
+#define POCR1SBL _SFR_MEM8(0xAA)
+#define POCR1SB_0 0
+#define POCR1SB_1 1
+#define POCR1SB_2 2
+#define POCR1SB_3 3
+#define POCR1SB_4 4
+#define POCR1SB_5 5
+#define POCR1SB_6 6
+#define POCR1SB_7 7
+
+#define POCR1SBH _SFR_MEM8(0xAB)
+#define POCR1SB_8 0
+#define POCR1SB_9 1
+#define POCR1SB_10 2
+#define POCR1SB_11 3
+#define POCR1SB_00 2 /* Deprecated */
+#define POCR1SB_01 3 /* Deprecated */
+
+#define POCR2SA _SFR_MEM16(0xAC)
+
+#define POCR2SAL _SFR_MEM8(0xAC)
+#define POCR2SA_0 0
+#define POCR2SA_1 1
+#define POCR2SA_2 2
+#define POCR2SA_3 3
+#define POCR2SA_4 4
+#define POCR2SA_5 5
+#define POCR2SA_6 6
+#define POCR2SA_7 7
+
+#define POCR2SAH _SFR_MEM8(0xAD)
+#define POCR2SA_8 0
+#define POCR2SA_9 1
+#define POCR2SA_10 2
+#define POCR2SA_11 3
+#define POCR2SA_00 2 /* Deprecated */
+#define POCR2SA_01 3 /* Deprecated */
+
+#define POCR2RA _SFR_MEM16(0xAE)
+
+#define POCR2RAL _SFR_MEM8(0xAE)
+#define POCR2RA_0 0
+#define POCR2RA_1 1
+#define POCR2RA_2 2
+#define POCR2RA_3 3
+#define POCR2RA_4 4
+#define POCR2RA_5 5
+#define POCR2RA_6 6
+#define POCR2RA_7 7
+
+#define POCR2RAH _SFR_MEM8(0xAF)
+#define POCR2RA_8 0
+#define POCR2RA_9 1
+#define POCR2RA_10 2
+#define POCR2RA_11 3
+#define POCR2RA_00 2 /* Deprecated */
+#define POCR2RA_01 3 /* Deprecated */
+
+#define POCR2SB _SFR_MEM16(0xB0)
+
+#define POCR2SBL _SFR_MEM8(0xB0)
+#define POCR2SB_0 0
+#define POCR2SB_1 1
+#define POCR2SB_2 2
+#define POCR2SB_3 3
+#define POCR2SB_4 4
+#define POCR2SB_5 5
+#define POCR2SB_6 6
+#define POCR2SB_7 7
+
+#define POCR2SBH _SFR_MEM8(0xB1)
+#define POCR2SB_8 0
+#define POCR2SB_9 1
+#define POCR2SB_10 2
+#define POCR2SB_11 3
+#define POCR2SB_00 2 /* Deprecated */
+#define POCR2SB_01 3 /* Deprecated */
+
+
+#define POCRxRB _SFR_MEM16(0xB2) /* Deprecated */
+#define POCR_RB _SFR_MEM16(0xB2)
+
+#define POCRxRBL _SFR_MEM8(0xB2) /* Deprecated */
+#define POCR_RBL _SFR_MEM8(0xB2)
+#define POCR_RB_0 0
+#define POCR_RB_1 1
+#define POCR_RB_2 2
+#define POCR_RB_3 3
+#define POCR_RB_4 4
+#define POCR_RB_5 5
+#define POCR_RB_6 6
+#define POCR_RB_7 7
+
+#define POCRxRBH _SFR_MEM8(0xB3) /* Deprecated */
+#define POCR_RBH _SFR_MEM8(0xB3)
+#define POCR_RB_8 0
+#define POCR_RB_9 1
+#define POCR_RB_10 2
+#define POCR_RB_11 3
+#define POCR_RB_00 2 /* Deprecated */
+#define POCR_RB_01 3 /* Deprecated */
+
+#define PSYNC _SFR_MEM8(0xB4)
+#define PSYNC00 0
+#define PSYNC01 1
+#define PSYNC10 2
+#define PSYNC11 3
+#define PSYNC20 4
+#define PSYNC21 5
+
+#define PCNF _SFR_MEM8(0xB5)
+#define POPA 2
+#define POPB 3
+#define PMODE 4
+#define PULOCK 5
+
+#define POC _SFR_MEM8(0xB6)
+#define POEN0A 0
+#define POEN0B 1
+#define POEN1A 2
+#define POEN1B 3
+#define POEN2A 4
+#define POEN2B 5
+
+#define PCTL _SFR_MEM8(0xB7)
+#define PRUN 0
+#define PCCYC 1
+#define PCLKSEL 5
+#define PPRE0 6
+#define PPRE1 7
+
+#define PMIC0 _SFR_MEM8(0xB8)
+#define PRFM00 0
+#define PRFM01 1
+#define PRFM02 2
+#define PAOC0 3
+#define PFLTE0 4
+#define PELEV0 5
+#define PISEL0 6
+#define POVEN0 7
+
+#define PMIC1 _SFR_MEM8(0xB9)
+#define PRFM10 0
+#define PRFM11 1
+#define PRFM12 2
+#define PAOC1 3
+#define PFLTE1 4
+#define PELEV1 5
+#define PISEL1 6
+#define POVEN1 7
+
+#define PMIC2 _SFR_MEM8(0xBA)
+#define PRFM20 0
+#define PRFM21 1
+#define PRFM22 2
+#define PAOC2 3
+#define PFLTE2 4
+#define PELEV2 5
+#define PISEL2 6
+#define POVEN2 7
+
+#define PIM _SFR_MEM8(0xBB)
+#define PEOPE 0
+#define PEVE0 1
+#define PEVE1 2
+#define PEVE2 3
+
+#define PIFR _SFR_MEM8(0xBC)
+#define PEOP 0
+#define PEV0 1
+#define PEV1 2
+#define PEV2 3
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+#define CANGCON _SFR_MEM8(0xD8)
+#define SWRES 0
+#define ENASTB 1
+#define TEST 2
+#define LISTEN 3
+#define SYNTTC 4
+#define TTC 5
+#define OVRQ 6
+#define ABRQ 7
+
+#define CANGSTA _SFR_MEM8(0xD9)
+#define ERRP 0
+#define BOFF 1
+#define ENFG 2
+#define RXBSY 3
+#define TXBSY 4
+#define OVFG 6
+
+#define CANGIT _SFR_MEM8(0xDA)
+#define AERG 0
+#define FERG 1
+#define CERG 2
+#define SERG 3
+#define BXOK 4
+#define OVRTIM 5
+#define BOFFIT 6
+#define CANIT 7
+
+#define CANGIE _SFR_MEM8(0xDB)
+#define ENOVRT 0
+#define ENERG 1
+#define ENBX 2
+#define ENERR 3
+#define ENTX 4
+#define ENRX 5
+#define ENBOFF 6
+#define ENIT 7
+
+#define CANEN2 _SFR_MEM8(0xDC)
+#define ENMOB0 0
+#define ENMOB1 1
+#define ENMOB2 2
+#define ENMOB3 3
+#define ENMOB4 4
+#define ENMOB5 5
+
+#define CANEN1 _SFR_MEM8(0xDD)
+
+#define CANIE2 _SFR_MEM8(0xDE)
+#define IEMOB0 0
+#define IEMOB1 1
+#define IEMOB2 2
+#define IEMOB3 3
+#define IEMOB4 4
+#define IEMOB5 5
+
+#define CANIE1 _SFR_MEM8(0xDF)
+
+#define CANSIT2 _SFR_MEM8(0xE0)
+#define SIT0 0
+#define SIT1 1
+#define SIT2 2
+#define SIT3 3
+#define SIT4 4
+#define SIT5 5
+
+#define CANSIT1 _SFR_MEM8(0xE1)
+
+#define CANBT1 _SFR_MEM8(0xE2)
+#define BRP0 1
+#define BRP1 2
+#define BRP2 3
+#define BRP3 4
+#define BRP4 5
+#define BRP5 6
+
+#define CANBT2 _SFR_MEM8(0xE3)
+#define PRS0 1
+#define PRS1 2
+#define PRS2 3
+#define SJW0 5
+#define SJW1 6
+
+#define CANBT3 _SFR_MEM8(0xE4)
+#define SMP 0
+#define PHS10 1
+#define PHS11 2
+#define PHS12 3
+#define PHS20 4
+#define PHS21 5
+#define PHS22 6
+
+#define CANTCON _SFR_MEM8(0xE5)
+#define TPRSC0 0
+#define TPRSC1 1
+#define TPRSC2 2
+#define TPRSC3 3
+#define TPRSC4 4
+#define TPRSC5 5
+#define TPRSC6 6
+#define TPRSC7 7
+
+#define CANTIM _SFR_MEM16(0xE6)
+
+#define CANTIML _SFR_MEM8(0xE6)
+#define CANTIM0 0
+#define CANTIM1 1
+#define CANTIM2 2
+#define CANTIM3 3
+#define CANTIM4 4
+#define CANTIM5 5
+#define CANTIM6 6
+#define CANTIM7 7
+
+#define CANTIMH _SFR_MEM8(0xE7)
+#define CANTIM8 0
+#define CANTIM9 1
+#define CANTIM10 2
+#define CANTIM11 3
+#define CANTIM12 4
+#define CANTIM13 5
+#define CANTIM14 6
+#define CANTIM15 7
+
+#define CANTTC _SFR_MEM16(0xE8)
+
+#define CANTTCL _SFR_MEM8(0xE8)
+#define TIMTCC0 0
+#define TIMTCC1 1
+#define TIMTCC2 2
+#define TIMTCC3 3
+#define TIMTCC4 4
+#define TIMTCC5 5
+#define TIMTCC6 6
+#define TIMTCC7 7
+
+#define CANTTCH _SFR_MEM8(0xE9)
+#define TIMTCC8 0
+#define TIMTCC9 1
+#define TIMTCC10 2
+#define TIMTCC11 3
+#define TIMTCC12 4
+#define TIMTCC13 5
+#define TIMTCC14 6
+#define TIMTCC15 7
+
+#define CANTEC _SFR_MEM8(0xEA)
+#define TEC0 0
+#define TEC1 1
+#define TEC2 2
+#define TEC3 3
+#define TEC4 4
+#define TEC5 5
+#define TEC6 6
+#define TEC7 7
+
+#define CANREC _SFR_MEM8(0xEB)
+#define REC0 0
+#define REC1 1
+#define REC2 2
+#define REC3 3
+#define REC4 4
+#define REC5 5
+#define REC6 6
+#define REC7 7
+
+#define CANHPMOB _SFR_MEM8(0xEC)
+#define CGP0 0
+#define CGP1 1
+#define CGP2 2
+#define CGP3 3
+#define HPMOB0 4
+#define HPMOB1 5
+#define HPMOB2 6
+#define HPMOB3 7
+
+#define CANPAGE _SFR_MEM8(0xED)
+#define INDX0 0
+#define INDX1 1
+#define INDX2 2
+#define AINC 3
+#define MOBNB0 4
+#define MOBNB1 5
+#define MOBNB2 6
+#define MOBNB3 7
+
+#define CANSTMOB _SFR_MEM8(0xEE)
+#define AERR 0
+#define FERR 1
+#define CERR 2
+#define SERR 3
+#define BERR 4
+#define RXOK 5
+#define TXOK 6
+#define DLCW 7
+
+#define CANCDMOB _SFR_MEM8(0xEF)
+#define DLC0 0
+#define DLC1 1
+#define DLC2 2
+#define DLC3 3
+#define IDE 4
+#define RPLV 5
+#define CONMOB0 6
+#define CONMOB1 7
+
+#define CANIDT4 _SFR_MEM8(0xF0)
+#define RB0TAG 0
+#define RB1TAG 1
+#define RTRTAG 2
+#define IDT0 3
+#define IDT1 4
+#define IDT2 5
+#define IDT3 6
+#define IDT4 7
+
+#define CANIDT3 _SFR_MEM8(0xF1)
+#define IDT5 0
+#define IDT6 1
+#define IDT7 2
+#define IDT8 3
+#define IDT9 4
+#define IDT10 5
+#define IDT11 6
+#define IDT12 7
+
+#define CANIDT2 _SFR_MEM8(0xF2)
+#define IDT13 0
+#define IDT14 1
+#define IDT15 2
+#define IDT16 3
+#define IDT17 4
+#define IDT18 5
+#define IDT19 6
+#define IDT20 7
+
+#define CANIDT1 _SFR_MEM8(0xF3)
+#define IDT21 0
+#define IDT22 1
+#define IDT23 2
+#define IDT24 3
+#define IDT25 4
+#define IDT26 5
+#define IDT27 6
+#define IDT28 7
+
+#define CANIDM4 _SFR_MEM8(0xF4)
+#define IDEMSK 0
+#define RTRMSK 2
+#define IDMSK0 3
+#define IDMSK1 4
+#define IDMSK2 5
+#define IDMSK3 6
+#define IDMSK4 7
+
+#define CANIDM3 _SFR_MEM8(0xF5)
+#define IDMSK5 0
+#define IDMSK6 1
+#define IDMSK7 2
+#define IDMSK8 3
+#define IDMSK9 4
+#define IDMSK10 5
+#define IDMSK11 6
+#define IDMSK12 7
+
+#define CANIDM2 _SFR_MEM8(0xF6)
+#define IDMSK13 0
+#define IDMSK14 1
+#define IDMSK15 2
+#define IDMSK16 3
+#define IDMSK17 4
+#define IDMSK18 5
+#define IDMSK19 6
+#define IDMSK20 7
+
+#define CANIDM1 _SFR_MEM8(0xF7)
+#define IDMSK21 0
+#define IDMSK22 1
+#define IDMSK23 2
+#define IDMSK24 3
+#define IDMSK25 4
+#define IDMSK26 5
+#define IDMSK27 6
+#define IDMSK28 7
+
+#define CANSTM _SFR_MEM16(0xF8)
+
+#define CANSTML _SFR_MEM8(0xF8)
+#define TIMSTM0 0
+#define TIMSTM1 1
+#define TIMSTM2 2
+#define TIMSTM3 3
+#define TIMSTM4 4
+#define TIMSTM5 5
+#define TIMSTM6 6
+#define TIMSTM7 7
+
+#define CANSTMH _SFR_MEM8(0xF9)
+#define TIMSTM8 0
+#define TIMSTM9 1
+#define TIMSTM10 2
+#define TIMSTM11 3
+#define TIMSTM12 4
+#define TIMSTM13 5
+#define TIMSTM14 6
+#define TIMSTM15 7
+
+#define CANMSG _SFR_MEM8(0xFA)
+#define MSG0 0
+#define MSG1 1
+#define MSG2 2
+#define MSG3 3
+#define MSG4 4
+#define MSG5 5
+#define MSG6 6
+#define MSG7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define ANACOMP0_vect_num 1
+#define ANACOMP0_vect _VECTOR(1) /* Analog Comparator 0 */
+#define ANACOMP1_vect_num 2
+#define ANACOMP1_vect _VECTOR(2) /* Analog Comparator 1 */
+#define ANACOMP2_vect_num 3
+#define ANACOMP2_vect _VECTOR(3) /* Analog Comparator 2 */
+#define ANACOMP3_vect_num 4
+#define ANACOMP3_vect _VECTOR(4) /* Analog Comparator 3 */
+#define PSC_FAULT_vect_num 5
+#define PSC_FAULT_vect _VECTOR(5) /* PSC Fault */
+#define PSC_EC_vect_num 6
+#define PSC_EC_vect _VECTOR(6) /* PSC End of Cycle */
+#define INT0_vect_num 7
+#define INT0_vect _VECTOR(7) /* External Interrupt Request 0 */
+#define INT1_vect_num 8
+#define INT1_vect _VECTOR(8) /* External Interrupt Request 1 */
+#define INT2_vect_num 9
+#define INT2_vect _VECTOR(9) /* External Interrupt Request 2 */
+#define INT3_vect_num 10
+#define INT3_vect _VECTOR(10) /* External Interrupt Request 3 */
+#define TIMER1_CAPT_vect_num 11
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 12
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 13
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 14
+#define TIMER1_OVF_vect _VECTOR(14) /* Timer1/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 15
+#define TIMER0_COMPA_vect _VECTOR(15) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 16
+#define TIMER0_COMPB_vect _VECTOR(16) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 17
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define CAN_INT_vect_num 18
+#define CAN_INT_vect _VECTOR(18) /* CAN MOB, Burst, General Errors */
+#define CAN_TOVF_vect_num 19
+#define CAN_TOVF_vect _VECTOR(19) /* CAN Timer Overflow */
+#define LIN_TC_vect_num 20
+#define LIN_TC_vect _VECTOR(20) /* LIN Transfer Complete */
+#define LIN_ERR_vect_num 21
+#define LIN_ERR_vect _VECTOR(21) /* LIN Error */
+#define PCINT0_vect_num 22
+#define PCINT0_vect _VECTOR(22) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 23
+#define PCINT1_vect _VECTOR(23) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 24
+#define PCINT2_vect _VECTOR(24) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 25
+#define PCINT3_vect _VECTOR(25) /* Pin Change Interrupt Request 3 */
+#define SPI_STC_vect_num 26
+#define SPI_STC_vect _VECTOR(26) /* SPI Serial Transfer Complete */
+#define ADC_vect_num 27
+#define ADC_vect _VECTOR(27) /* ADC Conversion Complete */
+#define WDT_vect_num 28
+#define WDT_vect _VECTOR(28) /* Watchdog Time-Out Interrupt */
+#define EE_READY_vect_num 29
+#define EE_READY_vect _VECTOR(29) /* EEPROM Ready */
+#define SPM_READY_vect_num 30
+#define SPM_READY_vect _VECTOR(30) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x0100)
+#define RAMSIZE (2048)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector Trigger Level */
+#define FUSE_PSCRVB (unsigned char)~_BV(3) /* PSC Outputs xB Reset Value */
+#define FUSE_PSCRVA (unsigned char)~_BV(4) /* PSC Outputs xA Reset Value */
+#define FUSE_PSCRB (unsigned char)~_BV(5) /* PSC Reset Behavior */
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_BODLEVEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x84
+
+
+#endif /* _AVR_ATmega32M1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom32u2.h b/cpukit/score/cpu/avr/avr/iom32u2.h
new file mode 100644
index 0000000000..a46eb6fa7f
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32u2.h
@@ -0,0 +1,980 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom32u2.h - definitions for ATmega32U2 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32u2.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega32U2_H_
+#define _AVR_ATmega32U2_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLP0 2
+#define PLLP1 3
+#define PLLP2 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define DWDR _SFR_IO8(0x31)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define USBRF 5
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define EIND _SFR_IO8(0x3C)
+#define EIND0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define WDTCKD _SFR_MEM8(0x62)
+#define WCLKD0 0
+#define WCLKD1 1
+#define WDEWIE 2
+#define WDEWIF 3
+
+#define REGCR _SFR_MEM8(0x63)
+#define REGDIS 0
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSART1 0
+#define PRUSB 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CL0 0
+#define OCR1CL1 1
+#define OCR1CL2 2
+#define OCR1CL3 3
+#define OCR1CL4 4
+#define OCR1CL5 5
+#define OCR1CL6 6
+#define OCR1CL7 7
+
+#define OCR1CH _SFR_MEM8(0x8D)
+#define OCR1CH0 0
+#define OCR1CH1 1
+#define OCR1CH2 2
+#define OCR1CH3 3
+#define OCR1CH4 4
+#define OCR1CH5 5
+#define OCR1CH6 6
+#define OCR1CH7 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UCSR1D _SFR_MEM8(0xCB)
+#define RTSEN 0
+#define CTSEN 1
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1_0 0
+#define UBRR1_1 1
+#define UBRR1_2 2
+#define UBRR1_3 3
+#define UBRR1_4 4
+#define UBRR1_5 5
+#define UBRR1_6 6
+#define UBRR1_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR1_8 0
+#define UBRR1_9 1
+#define UBRR1_10 2
+#define UBRR1_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+#define CLKSEL0 _SFR_MEM8(0xD0)
+#define CLKS 0
+#define EXTE 2
+#define RCE 3
+#define EXSUT0 4
+#define EXSUT1 5
+#define RCSUT0 6
+#define RCSUT1 7
+
+#define CLKSEL1 _SFR_MEM8(0xD1)
+#define EXCKSEL0 0
+#define EXCKSEL1 1
+#define EXCKSEL2 2
+#define EXCKSEL3 3
+#define RCCKSEL0 4
+#define RCCKSEL1 5
+#define RCCKSEL2 6
+#define RCCKSEL3 7
+
+#define CLKSTA _SFR_MEM8(0xD2)
+#define EXTON 0
+#define RCON 1
+
+#define USBCON _SFR_MEM8(0xD8)
+#define FRZCLK 5
+#define USBE 7
+
+#define UDCON _SFR_MEM8(0xE0)
+#define DETACH 0
+#define RMWKUP 1
+#define RSTCPU 2
+
+#define UDINT _SFR_MEM8(0xE1)
+#define SUSPI 0
+#define SOFI 2
+#define EORSTI 3
+#define WAKEUPI 4
+#define EORSMI 5
+#define UPRSMI 6
+
+#define UDIEN _SFR_MEM8(0xE2)
+#define SUSPE 0
+#define SOFE 2
+#define EORSTE 3
+#define WAKEUPE 4
+#define EORSME 5
+#define UPRSME 6
+
+#define UDADDR _SFR_MEM8(0xE3)
+#define UADD0 0
+#define UADD1 1
+#define UADD2 2
+#define UADD3 3
+#define UADD4 4
+#define UADD5 5
+#define UADD6 6
+#define ADDEN 7
+
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define FNUM0 0
+#define FNUM1 1
+#define FNUM2 2
+#define FNUM3 3
+#define FNUM4 4
+#define FNUM5 5
+#define FNUM6 6
+#define FNUM7 7
+
+#define UDFNUMH _SFR_MEM8(0xE5)
+#define FNUM8 0
+#define FNUM9 1
+#define FNUM10 2
+
+#define UDMFN _SFR_MEM8(0xE6)
+#define FNCERR 4
+
+#define UEINTX _SFR_MEM8(0xE8)
+#define TXINI 0
+#define STALLEDI 1
+#define RXOUTI 2
+#define RXSTPI 3
+#define NAKOUTI 4
+#define RWAL 5
+#define NAKINI 6
+#define FIFOCON 7
+
+#define UENUM _SFR_MEM8(0xE9)
+#define EPNUM0 0
+#define EPNUM1 1
+#define EPNUM2 2
+
+#define UERST _SFR_MEM8(0xEA)
+#define EPRST0 0
+#define EPRST1 1
+#define EPRST2 2
+#define EPRST3 3
+#define EPRST4 4
+
+#define UECONX _SFR_MEM8(0xEB)
+#define EPEN 0
+#define RSTDT 3
+#define STALLRQC 4
+#define STALLRQ 5
+
+#define UECFG0X _SFR_MEM8(0xEC)
+#define EPDIR 0
+#define EPTYPE0 6
+#define EPTYPE1 7
+
+#define UECFG1X _SFR_MEM8(0xED)
+#define ALLOC 1
+#define EPBK0 2
+#define EPBK1 3
+#define EPSIZE0 4
+#define EPSIZE1 5
+#define EPSIZE2 6
+
+#define UESTA0X _SFR_MEM8(0xEE)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UESTA1X _SFR_MEM8(0xEF)
+#define CURRBK0 0
+#define CURRBK1 1
+#define CTRLDIR 2
+
+#define UEIENX _SFR_MEM8(0xF0)
+#define TXINE 0
+#define STALLEDE 1
+#define RXOUTE 2
+#define RXSTPE 3
+#define NAKOUTE 4
+#define NAKINE 6
+#define FLERRE 7
+
+#define UEDATX _SFR_MEM8(0xF1)
+#define DAT0 0
+#define DAT1 1
+#define DAT2 2
+#define DAT3 3
+#define DAT4 4
+#define DAT5 5
+#define DAT6 6
+#define DAT7 7
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define BYCT0 0
+#define BYCT1 1
+#define BYCT2 2
+#define BYCT3 3
+#define BYCT4 4
+#define BYCT5 5
+#define BYCT6 6
+#define BYCT7 7
+
+#define UEINT _SFR_MEM8(0xF4)
+#define EPINT0 0
+#define EPINT1 1
+#define EPINT2 2
+#define EPINT3 3
+#define EPINT4 4
+
+#define PS2CON _SFR_MEM8(0xFA)
+#define PS2EN 0
+
+#define UPOE _SFR_MEM8(0xFB)
+#define DMI 0
+#define DPI 1
+#define DATAI 2
+#define SCKI 3
+#define UPDRV0 4
+#define UPDRV1 5
+#define UPWE0 6
+#define UPWE1 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect_num 4
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define INT4_vect_num 5
+#define INT4_vect _VECTOR(5) /* External Interrupt Request 4 */
+#define INT5_vect_num 6
+#define INT5_vect _VECTOR(6) /* External Interrupt Request 5 */
+#define INT6_vect_num 7
+#define INT6_vect _VECTOR(7) /* External Interrupt Request 6 */
+#define INT7_vect_num 8
+#define INT7_vect _VECTOR(8) /* External Interrupt Request 7 */
+#define PCINT0_vect_num 9
+#define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 10
+#define PCINT1_vect _VECTOR(10) /* Pin Change Interrupt Request 1 */
+#define USB_GEN_vect_num 11
+#define USB_GEN_vect _VECTOR(11) /* USB General Interrupt Request */
+#define USB_COM_vect_num 12
+#define USB_COM_vect _VECTOR(12) /* USB Endpoint/Pipe Interrupt Communication Request */
+#define WDT_vect_num 13
+#define WDT_vect _VECTOR(13) /* Watchdog Time-out Interrupt */
+#define TIMER1_CAPT_vect_num 14
+#define TIMER1_CAPT_vect _VECTOR(14) /* Timer/Counter2 Capture Event */
+#define TIMER1_COMPA_vect_num 15
+#define TIMER1_COMPA_vect _VECTOR(15) /* Timer/Counter2 Compare Match B */
+#define TIMER0_COMPA_vect_num 19
+#define TIMER0_COMPA_vect _VECTOR(19) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 20
+#define TIMER0_COMPB_vect _VECTOR(20) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 21
+#define TIMER0_OVF_vect _VECTOR(21) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 22
+#define SPI_STC_vect _VECTOR(22) /* SPI Serial Transfer Complete */
+#define USART1_RX_vect_num 23
+#define USART1_RX_vect _VECTOR(23) /* USART1, Rx Complete */
+#define USART1_UDRE_vect_num 24
+#define USART1_UDRE_vect _VECTOR(24) /* USART1 Data register Empty */
+#define USART1_TX_vect_num 25
+#define USART1_TX_vect _VECTOR(25) /* USART1, Tx Complete */
+#define ANALOG_COMP_vect_num 26
+#define ANALOG_COMP_vect _VECTOR(26) /* Analog Comparator */
+#define EE_READY_vect_num 27
+#define EE_READY_vect _VECTOR(27) /* EEPROM Ready */
+#define SPM_READY_vect_num 28
+#define SPM_READY_vect _VECTOR(28) /* Store Program Memory Read */
+#define TIMER1_COMPB_vect_num 16
+#define TIMER1_COMPB_vect _VECTOR(16) /* Timer/Counter2 Compare Match B */
+#define TIMER1_COMPC_vect_num 17
+#define TIMER1_COMPC_vect _VECTOR(17) /* Timer/Counter2 Compare Match C */
+#define TIMER1_OVF_vect_num 18
+#define TIMER1_OVF_vect _VECTOR(18) /* Timer/Counter1 Overflow */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (38 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_RSTDISBL (unsigned char)~_BV(6) /* External Reset Disable */
+#define FUSE_DWEN (unsigned char)~_BV(7) /* dwbugWIRE Enable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_HWBE (unsigned char)~_BV(3) /* Hardware Boot Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x8A
+
+
+/* Device Pin Definitions */
+#endif /* _AVR_ATmega32U2_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom32u4.h b/cpukit/score/cpu/avr/avr/iom32u4.h
new file mode 100644
index 0000000000..f7c465118e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32u4.h
@@ -0,0 +1,1504 @@
+/* Copyright (c) 2008 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom32u4.h - definitions for ATmega32U4. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32u4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM32U4_H_
+#define _AVR_IOM32U4_H_ 1
+
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE2 2
+#define PINE6 6
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE2 2
+#define DDE6 6
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE2 2
+#define PORTE6 6
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF0 0
+#define PINF1 1
+#define PINF4 4
+#define PINF5 5
+#define PINF6 6
+#define PINF7 7
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF0 0
+#define DDF1 1
+#define DDF4 4
+#define DDF5 5
+#define DDF6 6
+#define DDF7 7
+
+#define PORTF _SFR_IO8(0x11)
+#define PORTF0 0
+#define PORTF1 1
+#define PORTF4 4
+#define PORTF5 5
+#define PORTF6 6
+#define PORTF7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define TIFR3 _SFR_IO8(0x18)
+#define TOV3 0
+#define OCF3A 1
+#define OCF3B 2
+#define OCF3C 3
+#define ICF3 5
+
+#define TIFR4 _SFR_IO8(0x19)
+#define TOV4 2
+#define OCF4B 5
+#define OCF4A 6
+#define OCF4D 7
+
+#define TIFR5 _SFR_IO8(0x1A)
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PINDIV 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define PLLFRQ _SFR_IO8(0x32)
+#define PDIV0 0
+#define PDIV1 1
+#define PDIV2 2
+#define PDIV3 3
+#define PLLTM0 4
+#define PLLTM1 5
+#define PLLUSB 6
+#define PINMUX 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define RAMPZ _SFR_IO8(0x3B)
+#define RAMPZ0 0
+
+#define EIND _SFR_IO8(0x3C)
+#define EIND0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSART1 0
+#define PRTIM3 3
+#define PRUSB 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define RCCTRL _SFR_MEM8(0x67)
+#define RCFREQ 0
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#define TIMSK3 _SFR_MEM8(0x71)
+#define TOIE3 0
+#define OCIE3A 1
+#define OCIE3B 2
+#define OCIE3C 3
+#define ICIE3 5
+
+#define TIMSK4 _SFR_MEM8(0x72)
+#define TOIE4 2
+#define OCIE4B 5
+#define OCIE4A 6
+#define OCIE4D 7
+
+#define TIMSK5 _SFR_MEM8(0x73)
+
+#define ADC _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 4
+#define MUX5 5
+#define ACME 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR2 _SFR_MEM8(0x7D)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define ADC11D 3
+#define ADC12D 4
+#define ADC13D 5
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CL0 0
+#define OCR1CL1 1
+#define OCR1CL2 2
+#define OCR1CL3 3
+#define OCR1CL4 4
+#define OCR1CL5 5
+#define OCR1CL6 6
+#define OCR1CL7 7
+
+#define OCR1CH _SFR_MEM8(0x8D)
+#define OCR1CH0 0
+#define OCR1CH1 1
+#define OCR1CH2 2
+#define OCR1CH3 3
+#define OCR1CH4 4
+#define OCR1CH5 5
+#define OCR1CH6 6
+#define OCR1CH7 7
+
+#define TCCR3A _SFR_MEM8(0x90)
+#define WGM30 0
+#define WGM31 1
+#define COM3C0 2
+#define COM3C1 3
+#define COM3B0 4
+#define COM3B1 5
+#define COM3A0 6
+#define COM3A1 7
+
+#define TCCR3B _SFR_MEM8(0x91)
+#define CS30 0
+#define CS31 1
+#define CS32 2
+#define WGM32 3
+#define WGM33 4
+#define ICES3 6
+#define ICNC3 7
+
+#define TCCR3C _SFR_MEM8(0x92)
+#define FOC3C 5
+#define FOC3B 6
+#define FOC3A 7
+
+#define TCNT3 _SFR_MEM16(0x94)
+
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3L0 0
+#define TCNT3L1 1
+#define TCNT3L2 2
+#define TCNT3L3 3
+#define TCNT3L4 4
+#define TCNT3L5 5
+#define TCNT3L6 6
+#define TCNT3L7 7
+
+#define TCNT3H _SFR_MEM8(0x95)
+#define TCNT3H0 0
+#define TCNT3H1 1
+#define TCNT3H2 2
+#define TCNT3H3 3
+#define TCNT3H4 4
+#define TCNT3H5 5
+#define TCNT3H6 6
+#define TCNT3H7 7
+
+#define ICR3 _SFR_MEM16(0x96)
+
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3L0 0
+#define ICR3L1 1
+#define ICR3L2 2
+#define ICR3L3 3
+#define ICR3L4 4
+#define ICR3L5 5
+#define ICR3L6 6
+#define ICR3L7 7
+
+#define ICR3H _SFR_MEM8(0x97)
+#define ICR3H0 0
+#define ICR3H1 1
+#define ICR3H2 2
+#define ICR3H3 3
+#define ICR3H4 4
+#define ICR3H5 5
+#define ICR3H6 6
+#define ICR3H7 7
+
+#define OCR3A _SFR_MEM16(0x98)
+
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AL0 0
+#define OCR3AL1 1
+#define OCR3AL2 2
+#define OCR3AL3 3
+#define OCR3AL4 4
+#define OCR3AL5 5
+#define OCR3AL6 6
+#define OCR3AL7 7
+
+#define OCR3AH _SFR_MEM8(0x99)
+#define OCR3AH0 0
+#define OCR3AH1 1
+#define OCR3AH2 2
+#define OCR3AH3 3
+#define OCR3AH4 4
+#define OCR3AH5 5
+#define OCR3AH6 6
+#define OCR3AH7 7
+
+#define OCR3B _SFR_MEM16(0x9A)
+
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BL0 0
+#define OCR3BL1 1
+#define OCR3BL2 2
+#define OCR3BL3 3
+#define OCR3BL4 4
+#define OCR3BL5 5
+#define OCR3BL6 6
+#define OCR3BL7 7
+
+#define OCR3BH _SFR_MEM8(0x9B)
+#define OCR3BH0 0
+#define OCR3BH1 1
+#define OCR3BH2 2
+#define OCR3BH3 3
+#define OCR3BH4 4
+#define OCR3BH5 5
+#define OCR3BH6 6
+#define OCR3BH7 7
+
+#define OCR3C _SFR_MEM16(0x9C)
+
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CL0 0
+#define OCR3CL1 1
+#define OCR3CL2 2
+#define OCR3CL3 3
+#define OCR3CL4 4
+#define OCR3CL5 5
+#define OCR3CL6 6
+#define OCR3CL7 7
+
+#define OCR3CH _SFR_MEM8(0x9D)
+#define OCR3CH0 0
+#define OCR3CH1 1
+#define OCR3CH2 2
+#define OCR3CH3 3
+#define OCR3CH4 4
+#define OCR3CH5 5
+#define OCR3CH6 6
+#define OCR3CH7 7
+
+#define UHCON _SFR_MEM8(0x9E)
+
+#define UHINT _SFR_MEM8(0x9F)
+
+#define UHIEN _SFR_MEM8(0xA0)
+
+#define UHADDR _SFR_MEM8(0xA1)
+
+#define UHFNUM _SFR_MEM16(0xA2)
+
+#define UHFNUML _SFR_MEM8(0xA2)
+
+#define UHFNUMH _SFR_MEM8(0xA3)
+
+#define UHFLEN _SFR_MEM8(0xA4)
+
+#define UPINRQX _SFR_MEM8(0xA5)
+
+#define UPINTX _SFR_MEM8(0xA6)
+
+#define UPNUM _SFR_MEM8(0xA7)
+
+#define UPRST _SFR_MEM8(0xA8)
+
+#define UPCONX _SFR_MEM8(0xA9)
+
+#define UPCFG0X _SFR_MEM8(0xAA)
+
+#define UPCFG1X _SFR_MEM8(0xAB)
+
+#define UPSTAX _SFR_MEM8(0xAC)
+
+#define UPCFG2X _SFR_MEM8(0xAD)
+
+#define UPIENX _SFR_MEM8(0xAE)
+
+#define UPDATX _SFR_MEM8(0xAF)
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define TCNT4 _SFR_MEM16(0xBE)
+
+#define TCNT4L _SFR_MEM8(0xBE)
+#define TC40 0
+#define TC41 1
+#define TC42 2
+#define TC43 3
+#define TC44 4
+#define TC45 5
+#define TC46 6
+#define TC47 7
+
+#define TCNT4H _SFR_MEM8(0xBF) /* Alias for naming consistency. */
+#define TC4H _SFR_MEM8(0xBF) /* Per XML device file. */
+#define TC48 0
+#define TC49 1
+#define TC410 2
+
+#define TCCR4A _SFR_MEM8(0xC0)
+#define PWM4B 0
+#define PWM4A 1
+#define FOC4B 2
+#define FOC4A 3
+#define COM4B0 4
+#define COM4B1 5
+#define COM4A0 6
+#define COM4A1 7
+
+#define TCCR4B _SFR_MEM8(0xC1)
+#define CS40 0
+#define CS41 1
+#define CS42 2
+#define CS43 3
+#define DTPS40 4
+#define DTPS41 5
+#define PSR4 6
+#define PWM4X 7
+
+#define TCCR4C _SFR_MEM8(0xC2)
+#define PWM4D 0
+#define FOC4D 1
+#define COM4D0 2
+#define COM4D1 3
+#define COM4B0S 4
+#define COM4B1S 5
+#define COM4A0S 6
+#define COM4A1S 7
+
+#define TCCR4D _SFR_MEM8(0xC3)
+#define WGM40 0
+#define WGM41 1
+#define FPF4 2
+#define FPAC4 3
+#define FPES4 4
+#define FPNC4 5
+#define FPEN4 6
+#define FPIE4 7
+
+#define TCCR4E _SFR_MEM8(0xC4)
+#define OC4OE0 0
+#define OC4OE1 1
+#define OC4OE2 2
+#define OC4OE3 3
+#define OC4OE4 4
+#define OC4OE5 5
+#define ENHC4 6
+#define TLOCK4 7
+
+#define CLKSEL0 _SFR_MEM8(0xC5)
+#define CLKS 0
+#define EXTE 2
+#define RCE 3
+#define EXSUT0 4
+#define EXSUT1 5
+#define RCSUT0 6
+#define RCSUT1 7
+
+#define CLKSEL1 _SFR_MEM8(0xC6)
+#define EXCKSEL0 0
+#define EXCKSEL1 1
+#define EXCKSEL2 2
+#define EXCKSEL3 3
+#define RCCKSEL0 4
+#define RCCKSEL1 5
+#define RCCKSEL2 6
+#define RCCKSEL3 7
+
+#define CLKSTA _SFR_MEM8(0xC7)
+#define EXTON 0
+#define RCON 1
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+
+#define UBRR1H _SFR_MEM8(0xCD)
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+#define OCR4A _SFR_MEM8(0xCF)
+#define OCR4A0 0
+#define OCR4A1 1
+#define OCR4A2 2
+#define OCR4A3 3
+#define OCR4A4 4
+#define OCR4A5 5
+#define OCR4A6 6
+#define OCR4A7 7
+
+#define OCR4B _SFR_MEM8(0xD0)
+#define OCR4B0 0
+#define OCR4B1 1
+#define OCR4B2 2
+#define OCR4B3 3
+#define OCR4B4 4
+#define OCR4B5 5
+#define OCR4B6 6
+#define OCR4B7 7
+
+#define OCR4C _SFR_MEM8(0xD1)
+#define OCR4C0 0
+#define OCR4C1 1
+#define OCR4C2 2
+#define OCR4C3 3
+#define OCR4C4 4
+#define OCR4C5 5
+#define OCR4C6 6
+#define OCR4C7 7
+
+#define OCR4D _SFR_MEM8(0xD2)
+#define OCR4D0 0
+#define OCR4D1 1
+#define OCR4D2 2
+#define OCR4D3 3
+#define OCR4D4 4
+#define OCR4D5 5
+#define OCR4D6 6
+#define OCR4D7 7
+
+#define DT4 _SFR_MEM8(0xD4)
+#define DT4L0 0
+#define DT4L1 1
+#define DT4L2 2
+#define DT4L3 3
+#define DT4L4 4
+#define DT4L5 5
+#define DT4L6 6
+#define DT4L7 7
+
+#define UHWCON _SFR_MEM8(0xD7)
+#define UVREGE 0
+
+#define USBCON _SFR_MEM8(0xD8)
+#define VBUSTE 0
+#define OTGPADE 4
+#define FRZCLK 5
+#define USBE 7
+
+#define USBSTA _SFR_MEM8(0xD9)
+#define VBUS 0
+#define SPEED 3
+
+#define USBINT _SFR_MEM8(0xDA)
+#define VBUSTI 0
+
+#define OTGCON _SFR_MEM8(0xDD)
+
+#define OTGIEN _SFR_MEM8(0xDE)
+
+#define OTGINT _SFR_MEM8(0xDF)
+
+#define UDCON _SFR_MEM8(0xE0)
+#define DETACH 0
+#define RMWKUP 1
+#define LSM 2
+#define RSTCPU 3
+
+#define UDINT _SFR_MEM8(0xE1)
+#define SUSPI 0
+#define SOFI 2
+#define EORSTI 3
+#define WAKEUPI 4
+#define EORSMI 5
+#define UPRSMI 6
+
+#define UDIEN _SFR_MEM8(0xE2)
+#define SUSPE 0
+#define SOFE 2
+#define EORSTE 3
+#define WAKEUPE 4
+#define EORSME 5
+#define UPRSME 6
+
+#define UDADDR _SFR_MEM8(0xE3)
+#define UADD0 0
+#define UADD1 1
+#define UADD2 2
+#define UADD3 3
+#define UADD4 4
+#define UADD5 5
+#define UADD6 6
+#define ADDEN 7
+
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define FNUM0 0
+#define FNUM1 1
+#define FNUM2 2
+#define FNUM3 3
+#define FNUM4 4
+#define FNUM5 5
+#define FNUM6 6
+#define FNUM7 7
+
+#define UDFNUMH _SFR_MEM8(0xE5)
+#define FNUM8 0
+#define FNUM9 1
+#define FNUM10 2
+
+#define UDMFN _SFR_MEM8(0xE6)
+#define FNCERR 4
+
+#define UDTST _SFR_MEM8(0xE7)
+
+#define UEINTX _SFR_MEM8(0xE8)
+#define TXINI 0
+#define STALLEDI 1
+#define RXOUTI 2
+#define RXSTPI 3
+#define NAKOUTI 4
+#define RWAL 5
+#define NAKINI 6
+#define FIFOCON 7
+
+#define UENUM _SFR_MEM8(0xE9)
+#define UENUM_0 0
+#define UENUM_1 1
+#define UENUM_2 2
+
+#define UERST _SFR_MEM8(0xEA)
+#define EPRST0 0
+#define EPRST1 1
+#define EPRST2 2
+#define EPRST3 3
+#define EPRST4 4
+#define EPRST5 5
+#define EPRST6 6
+
+#define UECONX _SFR_MEM8(0xEB)
+#define EPEN 0
+#define RSTDT 3
+#define STALLRQC 4
+#define STALLRQ 5
+
+#define UECFG0X _SFR_MEM8(0xEC)
+#define EPDIR 0
+#define EPTYPE0 6
+#define EPTYPE1 7
+
+#define UECFG1X _SFR_MEM8(0xED)
+#define ALLOC 1
+#define EPBK0 2
+#define EPBK1 3
+#define EPSIZE0 4
+#define EPSIZE1 5
+#define EPSIZE2 6
+
+#define UESTA0X _SFR_MEM8(0xEE)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UESTA1X _SFR_MEM8(0xEF)
+#define CURRBK0 0
+#define CURRBK1 1
+#define CTRLDIR 2
+
+#define UEIENX _SFR_MEM8(0xF0)
+#define TXINE 0
+#define STALLEDE 1
+#define RXOUTE 2
+#define RXSTPE 3
+#define NAKOUTE 4
+#define NAKINE 6
+#define FLERRE 7
+
+#define UEDATX _SFR_MEM8(0xF1)
+#define DAT0 0
+#define DAT1 1
+#define DAT2 2
+#define DAT3 3
+#define DAT4 4
+#define DAT5 5
+#define DAT6 6
+#define DAT7 7
+
+#define UEBCX _SFR_MEM16(0xF2)
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define BYCT0 0
+#define BYCT1 1
+#define BYCT2 2
+#define BYCT3 3
+#define BYCT4 4
+#define BYCT5 5
+#define BYCT6 6
+#define BYCT7 7
+
+#define UEBCHX _SFR_MEM8(0xF3)
+
+#define UEINT _SFR_MEM8(0xF4)
+#define EPINT0 0
+#define EPINT1 1
+#define EPINT2 2
+#define EPINT3 3
+#define EPINT4 4
+#define EPINT5 5
+#define EPINT6 6
+
+#define UPERRX _SFR_MEM8(0xF5)
+
+#define UPBCLX _SFR_MEM8(0xF6)
+
+#define UPBCHX _SFR_MEM8(0xF7)
+
+#define UPINT _SFR_MEM8(0xF8)
+
+#define OTGTCON _SFR_MEM8(0xF9)
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define INT6_vect _VECTOR(7) /* External Interrupt Request 6 */
+#define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0 */
+#define USB_GEN_vect _VECTOR(10) /* USB General Interrupt Request */
+#define USB_COM_vect _VECTOR(11) /* USB Endpoint/Pipe Interrupt Communication Request */
+#define WDT_vect _VECTOR(12) /* Watchdog Time-out Interrupt */
+#define TIMER1_CAPT_vect _VECTOR(16) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(17) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(18) /* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPC_vect _VECTOR(19) /* Timer/Counter1 Compare Match C */
+#define TIMER1_OVF_vect _VECTOR(20) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(21) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect _VECTOR(22) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(23) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect _VECTOR(24) /* SPI Serial Transfer Complete */
+#define USART1_RX_vect _VECTOR(25) /* USART1, Rx Complete */
+#define USART1_UDRE_vect _VECTOR(26) /* USART1 Data register Empty */
+#define USART1_TX_vect _VECTOR(27) /* USART1, Tx Complete */
+#define ANALOG_COMP_vect _VECTOR(28) /* Analog Comparator */
+#define ADC_vect _VECTOR(29) /* ADC Conversion Complete */
+#define EE_READY_vect _VECTOR(30) /* EEPROM Ready */
+#define TIMER3_CAPT_vect _VECTOR(31) /* Timer/Counter3 Capture Event */
+#define TIMER3_COMPA_vect _VECTOR(32) /* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPB_vect _VECTOR(33) /* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPC_vect _VECTOR(34) /* Timer/Counter3 Compare Match C */
+#define TIMER3_OVF_vect _VECTOR(35) /* Timer/Counter3 Overflow */
+#define TWI_vect _VECTOR(36) /* 2-wire Serial Interface */
+#define SPM_READY_vect _VECTOR(37) /* Store Program Memory Read */
+#define TIMER4_COMPA_vect _VECTOR(38) /* Timer/Counter4 Compare Match A */
+#define TIMER4_COMPB_vect _VECTOR(39) /* Timer/Counter4 Compare Match B */
+#define TIMER4_COMPD_vect _VECTOR(40) /* Timer/Counter4 Compare Match D */
+#define TIMER4_OVF_vect _VECTOR(41) /* Timer/Counter4 Overflow */
+#define TIMER4_FPF_vect _VECTOR(42) /* Timer/Counter4 Fault Protection Interrupt */
+
+#define _VECTORS_SIZE (43 * 4)
+
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (0xA00)
+#define RAMEND (RAMSTART + RAMSIZE - 1) /* Last On-Chip SRAM Location */
+#define XRAMSTART (0x2200)
+#define XRAMSIZE (0x10000)
+#define XRAMEND (XRAMSIZE - 1)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FFF)
+
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_HWBE (unsigned char)~_BV(3) /* Hardware Boot Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x87
+
+
+
+#endif /* _AVR_IOM32U4_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom32u6.h b/cpukit/score/cpu/avr/avr/iom32u6.h
new file mode 100644
index 0000000000..667b166446
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom32u6.h
@@ -0,0 +1,1411 @@
+/* Copyright (c) 2008 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom32u6.h - definitions for ATmega32U6 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom32u6.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega32U6_H_
+#define _AVR_ATmega32U6_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+#define PINE3 3
+#define PINE4 4
+#define PINE5 5
+#define PINE6 6
+#define PINE7 7
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+#define DDE3 3
+#define DDE4 4
+#define DDE5 5
+#define DDE6 6
+#define DDE7 7
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+#define PORTE3 3
+#define PORTE4 4
+#define PORTE5 5
+#define PORTE6 6
+#define PORTE7 7
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF0 0
+#define PINF1 1
+#define PINF2 2
+#define PINF3 3
+#define PINF4 4
+#define PINF5 5
+#define PINF6 6
+#define PINF7 7
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF0 0
+#define DDF1 1
+#define DDF2 2
+#define DDF3 3
+#define DDF4 4
+#define DDF5 5
+#define DDF6 6
+#define DDF7 7
+
+#define PORTF _SFR_IO8(0x11)
+#define PORTF0 0
+#define PORTF1 1
+#define PORTF2 2
+#define PORTF3 3
+#define PORTF4 4
+#define PORTF5 5
+#define PORTF6 6
+#define PORTF7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define TIFR3 _SFR_IO8(0x18)
+#define TOV3 0
+#define OCF3A 1
+#define OCF3B 2
+#define OCF3C 3
+#define ICF3 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLP0 2
+#define PLLP1 3
+#define PLLP2 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSART1 0
+#define PRTIM3 3
+#define PRUSB 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#define TIMSK3 _SFR_MEM8(0x71)
+#define TOIE3 0
+#define OCIE3A 1
+#define OCIE3B 2
+#define OCIE3C 3
+#define ICIE3 5
+
+#define XMCRA _SFR_MEM8(0x74)
+#define SRW00 0
+#define SRW01 1
+#define SRW10 2
+#define SRW11 3
+#define SRL0 4
+#define SRL1 5
+#define SRL2 6
+#define SRE 7
+
+#define XMCRB _SFR_MEM8(0x75)
+#define XMM0 0
+#define XMM1 1
+#define XMM2 2
+#define XMBK 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CL0 0
+#define OCR1CL1 1
+#define OCR1CL2 2
+#define OCR1CL3 3
+#define OCR1CL4 4
+#define OCR1CL5 5
+#define OCR1CL6 6
+#define OCR1CL7 7
+
+#define OCR1CH _SFR_MEM8(0x8D)
+#define OCR1CH0 0
+#define OCR1CH1 1
+#define OCR1CH2 2
+#define OCR1CH3 3
+#define OCR1CH4 4
+#define OCR1CH5 5
+#define OCR1CH6 6
+#define OCR1CH7 7
+
+#define TCCR3A _SFR_MEM8(0x90)
+#define WGM30 0
+#define WGM31 1
+#define COM3C0 2
+#define COM3C1 3
+#define COM3B0 4
+#define COM3B1 5
+#define COM3A0 6
+#define COM3A1 7
+
+#define TCCR3B _SFR_MEM8(0x91)
+#define CS30 0
+#define CS31 1
+#define CS32 2
+#define WGM32 3
+#define WGM33 4
+#define ICES3 6
+#define ICNC3 7
+
+#define TCCR3C _SFR_MEM8(0x92)
+#define FOC3C 5
+#define FOC3B 6
+#define FOC3A 7
+
+#define TCNT3 _SFR_MEM16(0x94)
+
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3L0 0
+#define TCNT3L1 1
+#define TCNT3L2 2
+#define TCNT3L3 3
+#define TCNT3L4 4
+#define TCNT3L5 5
+#define TCNT3L6 6
+#define TCNT3L7 7
+
+#define TCNT3H _SFR_MEM8(0x95)
+#define TCNT3H0 0
+#define TCNT3H1 1
+#define TCNT3H2 2
+#define TCNT3H3 3
+#define TCNT3H4 4
+#define TCNT3H5 5
+#define TCNT3H6 6
+#define TCNT3H7 7
+
+#define ICR3 _SFR_MEM16(0x96)
+
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3L0 0
+#define ICR3L1 1
+#define ICR3L2 2
+#define ICR3L3 3
+#define ICR3L4 4
+#define ICR3L5 5
+#define ICR3L6 6
+#define ICR3L7 7
+
+#define ICR3H _SFR_MEM8(0x97)
+#define ICR3H0 0
+#define ICR3H1 1
+#define ICR3H2 2
+#define ICR3H3 3
+#define ICR3H4 4
+#define ICR3H5 5
+#define ICR3H6 6
+#define ICR3H7 7
+
+#define OCR3A _SFR_MEM16(0x98)
+
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AL0 0
+#define OCR3AL1 1
+#define OCR3AL2 2
+#define OCR3AL3 3
+#define OCR3AL4 4
+#define OCR3AL5 5
+#define OCR3AL6 6
+#define OCR3AL7 7
+
+#define OCR3AH _SFR_MEM8(0x99)
+#define OCR3AH0 0
+#define OCR3AH1 1
+#define OCR3AH2 2
+#define OCR3AH3 3
+#define OCR3AH4 4
+#define OCR3AH5 5
+#define OCR3AH6 6
+#define OCR3AH7 7
+
+#define OCR3B _SFR_MEM16(0x9A)
+
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BL0 0
+#define OCR3BL1 1
+#define OCR3BL2 2
+#define OCR3BL3 3
+#define OCR3BL4 4
+#define OCR3BL5 5
+#define OCR3BL6 6
+#define OCR3BL7 7
+
+#define OCR3BH _SFR_MEM8(0x9B)
+#define OCR3BH0 0
+#define OCR3BH1 1
+#define OCR3BH2 2
+#define OCR3BH3 3
+#define OCR3BH4 4
+#define OCR3BH5 5
+#define OCR3BH6 6
+#define OCR3BH7 7
+
+#define OCR3C _SFR_MEM16(0x9C)
+
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CL0 0
+#define OCR3CL1 1
+#define OCR3CL2 2
+#define OCR3CL3 3
+#define OCR3CL4 4
+#define OCR3CL5 5
+#define OCR3CL6 6
+#define OCR3CL7 7
+
+#define OCR3CH _SFR_MEM8(0x9D)
+#define OCR3CH0 0
+#define OCR3CH1 1
+#define OCR3CH2 2
+#define OCR3CH3 3
+#define OCR3CH4 4
+#define OCR3CH5 5
+#define OCR3CH6 6
+#define OCR3CH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A_0 0
+#define OCR2A_1 1
+#define OCR2A_2 2
+#define OCR2A_3 3
+#define OCR2A_4 4
+#define OCR2A_5 5
+#define OCR2A_6 6
+#define OCR2A_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2B_0 0
+#define OCR2B_1 1
+#define OCR2B_2 2
+#define OCR2B_3 3
+#define OCR2B_4 4
+#define OCR2B_5 5
+#define OCR2B_6 6
+#define OCR2B_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR_0 0
+#define UBRR_1 1
+#define UBRR_2 2
+#define UBRR_3 3
+#define UBRR_4 4
+#define UBRR_5 5
+#define UBRR_6 6
+#define UBRR_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR_8 0
+#define UBRR_9 1
+#define UBRR_10 2
+#define UBRR_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+#define UHWCON _SFR_MEM8(0xD7)
+#define UVREGE 0
+#define UVCONE 4
+#define UIDE 6
+#define UIMOD 7
+
+#define USBCON _SFR_MEM8(0xD8)
+#define VBUSTE 0
+#define IDTE 1
+#define OTGPADE 4
+#define FRZCLK 5
+#define HOST 6
+#define USBE 7
+
+#define USBSTA _SFR_MEM8(0xD9)
+#define VBUS 0
+#define ID 1
+#define SPEED 3
+
+#define USBINT _SFR_MEM8(0xDA)
+#define VBUSTI 0
+#define IDTI 1
+
+#define UDCON _SFR_MEM8(0xE0)
+#define DETACH 0
+#define RMWKUP 1
+#define LSM 2
+
+#define UDINT _SFR_MEM8(0xE1)
+#define SUSPI 0
+#define SOFI 2
+#define EORSTI 3
+#define WAKEUPI 4
+#define EORSMI 5
+#define UPRSMI 6
+
+#define UDIEN _SFR_MEM8(0xE2)
+#define SUSPE 0
+#define SOFE 2
+#define EORSTE 3
+#define WAKEUPE 4
+#define EORSME 5
+#define UPRSME 6
+
+#define UDADDR _SFR_MEM8(0xE3)
+#define UADD0 0
+#define UADD1 1
+#define UADD2 2
+#define UADD3 3
+#define UADD4 4
+#define UADD5 5
+#define UADD6 6
+#define ADDEN 7
+
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define UDFNUML_0 0
+#define UDFNUML_1 1
+#define UDFNUML_2 2
+#define UDFNUML_3 3
+#define UDFNUML_4 4
+#define UDFNUML_5 5
+#define UDFNUML_6 6
+#define UDFNUML_7 7
+
+#define UDFNUMH _SFR_MEM8(0xE5)
+#define UDFNUMH_0 0
+#define UDFNUMH_1 1
+#define UDFNUMH_2 2
+
+#define UDMFN _SFR_MEM8(0xE6)
+#define FNCERR 4
+
+#define UEINTX _SFR_MEM8(0xE8)
+#define TXINI 0
+#define STALLEDI 1
+#define RXOUTI 2
+#define RXSTPI 3
+#define NAKOUTI 4
+#define RWAL 5
+#define NAKINI 6
+#define FIFOCON 7
+
+#define UENUM _SFR_MEM8(0xE9)
+#define UENUM_0 0
+#define UENUM_1 1
+#define UENUM_2 2
+
+#define UERST _SFR_MEM8(0xEA)
+#define EPRST0 0
+#define EPRST1 1
+#define EPRST2 2
+#define EPRST3 3
+#define EPRST4 4
+#define EPRST5 5
+#define EPRST6 6
+
+#define UECONX _SFR_MEM8(0xEB)
+#define EPEN 0
+#define RSTDT 3
+#define STALLRQC 4
+#define STALLRQ 5
+
+#define UECFG0X _SFR_MEM8(0xEC)
+#define EPDIR 0
+#define EPTYPE0 6
+#define EPTYPE1 7
+
+#define UECFG1X _SFR_MEM8(0xED)
+#define ALLOC 1
+#define EPBK0 2
+#define EPBK1 3
+#define EPSIZE0 4
+#define EPSIZE1 5
+#define EPSIZE2 6
+
+#define UESTA0X _SFR_MEM8(0xEE)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UESTA1X _SFR_MEM8(0xEF)
+#define CURRBK0 0
+#define CURRBK1 1
+#define CTRLDIR 2
+
+#define UEIENX _SFR_MEM8(0xF0)
+#define TXINE 0
+#define STALLEDE 1
+#define RXOUTE 2
+#define RXSTPE 3
+#define NAKOUTE 4
+#define NAKINE 6
+#define FLERRE 7
+
+#define UEDATX _SFR_MEM8(0xF1)
+#define UEDATX_0 0
+#define UEDATX_1 1
+#define UEDATX_2 2
+#define UEDATX_3 3
+#define UEDATX_4 4
+#define UEDATX_5 5
+#define UEDATX_6 6
+#define UEDATX_7 7
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define UEBCLX_0 0
+#define UEBCLX_1 1
+#define UEBCLX_2 2
+#define UEBCLX_3 3
+#define UEBCLX_4 4
+#define UEBCLX_5 5
+#define UEBCLX_6 6
+#define UEBCLX_7 7
+
+#define UEBCHX _SFR_MEM8(0xF3)
+#define UEBCHX_0 0
+#define UEBCHX_1 1
+#define UEBCHX_2 2
+
+#define UEINT _SFR_MEM8(0xF4)
+#define EPINT0 0
+#define EPINT1 1
+#define EPINT2 2
+#define EPINT3 3
+#define EPINT4 4
+#define EPINT5 5
+#define EPINT6 6
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect_num 4
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define INT4_vect_num 5
+#define INT4_vect _VECTOR(5) /* External Interrupt Request 4 */
+#define INT5_vect_num 6
+#define INT5_vect _VECTOR(6) /* External Interrupt Request 5 */
+#define INT6_vect_num 7
+#define INT6_vect _VECTOR(7) /* External Interrupt Request 6 */
+#define INT7_vect_num 8
+#define INT7_vect _VECTOR(8) /* External Interrupt Request 7 */
+#define PCINT0_vect_num 9
+#define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0 */
+#define USB_GEN_vect_num 10
+#define USB_GEN_vect _VECTOR(10) /* USB General Interrupt Request */
+#define USB_COM_vect_num 11
+#define USB_COM_vect _VECTOR(11) /* USB Endpoint/Pipe Interrupt Communication Request */
+#define WDT_vect_num 12
+#define WDT_vect _VECTOR(12) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect_num 13
+#define TIMER2_COMPA_vect _VECTOR(13) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect_num 14
+#define TIMER2_COMPB_vect _VECTOR(14) /* Timer/Counter2 Compare Match B */
+#define TIMER2_OVF_vect_num 15
+#define TIMER2_OVF_vect _VECTOR(15) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 16
+#define TIMER1_CAPT_vect _VECTOR(16) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 17
+#define TIMER1_COMPA_vect _VECTOR(17) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 18
+#define TIMER1_COMPB_vect _VECTOR(18) /* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPC_vect_num 19
+#define TIMER1_COMPC_vect _VECTOR(19) /* Timer/Counter1 Compare Match C */
+#define TIMER1_OVF_vect_num 20
+#define TIMER1_OVF_vect _VECTOR(20) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 21
+#define TIMER0_COMPA_vect _VECTOR(21) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 22
+#define TIMER0_COMPB_vect _VECTOR(22) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 23
+#define TIMER0_OVF_vect _VECTOR(23) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 24
+#define SPI_STC_vect _VECTOR(24) /* SPI Serial Transfer Complete */
+#define USART1_RX_vect_num 25
+#define USART1_RX_vect _VECTOR(25) /* USART1, Rx Complete */
+#define USART1_UDRE_vect_num 26
+#define USART1_UDRE_vect _VECTOR(26) /* USART1 Data register Empty */
+#define USART1_TX_vect_num 27
+#define USART1_TX_vect _VECTOR(27) /* USART1, Tx Complete */
+#define ANALOG_COMP_vect_num 28
+#define ANALOG_COMP_vect _VECTOR(28) /* Analog Comparator */
+#define ADC_vect_num 29
+#define ADC_vect _VECTOR(29) /* ADC Conversion Complete */
+#define EE_READY_vect_num 30
+#define EE_READY_vect _VECTOR(30) /* EEPROM Ready */
+#define TIMER3_CAPT_vect_num 31
+#define TIMER3_CAPT_vect _VECTOR(31) /* Timer/Counter3 Capture Event */
+#define TIMER3_COMPA_vect_num 32
+#define TIMER3_COMPA_vect _VECTOR(32) /* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPB_vect_num 33
+#define TIMER3_COMPB_vect _VECTOR(33) /* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPC_vect_num 34
+#define TIMER3_COMPC_vect _VECTOR(34) /* Timer/Counter3 Compare Match C */
+#define TIMER3_OVF_vect_num 35
+#define TIMER3_OVF_vect _VECTOR(35) /* Timer/Counter3 Overflow */
+#define TWI_vect_num 36
+#define TWI_vect _VECTOR(36) /* 2-wire Serial Interface */
+#define SPM_READY_vect_num 37
+#define SPM_READY_vect _VECTOR(37) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (38 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (2560)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x2200)
+#define XRAMSIZE (65536)
+#define XRAMEND (XRAMSIZE - 1)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_HWBE (unsigned char)~_BV(3) /* Hardware Boot Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x88
+
+
+#endif /* _AVR_ATmega32U6_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom406.h b/cpukit/score/cpu/avr/avr/iom406.h
new file mode 100644
index 0000000000..466e6478ca
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom406.h
@@ -0,0 +1,768 @@
+/* Copyright (c) 2006, Pieter Conradie
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom406.h - definitions for ATmega406 */
+
+#ifndef _AVR_IOM406_H_
+#define _AVR_IOM406_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom406.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Reserved [0x06..0x07] */
+
+#define PORTC _SFR_IO8(0x08)
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD1 1
+#define PD0 0
+
+/* Reserved [0x0C..0x14] */
+
+/* Timer/Counter0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x15)
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+/* Timer/Counter1 Interrupt Flag Register */
+#define TIFR1 _SFR_IO8(0x16)
+#define OCF1A 1
+#define TOV1 0
+
+/* Reserved [0x17..0x1A] */
+
+/* Pin Change Interrupt Control Register */
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF1 1
+#define PCIF0 0
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x1C)
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+/* External Interrupt MaSK register */
+#define EIMSK _SFR_IO8(0x1D)
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+/* General Purpose I/O Register 0 */
+#define GPIOR0 _SFR_IO8(0x1E)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1F)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x20)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSRSYNC 0
+
+/* Timer/Counter Control Register A */
+#define TCCR0A _SFR_IO8(0x24)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+/* Timer/Counter Control Register B */
+#define TCCR0B _SFR_IO8(0x25)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x26)
+
+/* Output Compare Register A */
+#define OCR0A _SFR_IO8(0x27)
+
+/* Output Compare Register B */
+#define OCR0B _SFR_IO8(0x28)
+
+/* Reserved [0x29] */
+
+/* General Purpose I/O Register 1 */
+#define GPIOR1 _SFR_IO8(0x2A)
+
+/* General Purpose I/O Register 2 */
+#define GPIOR2 _SFR_IO8(0x2B)
+
+/* Reserved [0x2C..0x30] */
+
+/* On-chip Debug Register */
+#define OCDR _SFR_IO8(0x31)
+
+/* Reserved [0x32] */
+
+/* Sleep Mode Control Register */
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+#define JTRF 4
+#define WDRF 3
+#define BODRF 2
+#define EXTRF 1
+#define PORF 0
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+#define JTD 7
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+
+/* Reserved [0x36] */
+
+/* Store Program Memory Control and Status Register */
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMIE 7
+#define RWWSB 6
+#define SIGRD 5
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Reserved [0x36..0x3C] */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Extended I/O registers */
+
+/* Watchdog Timer Control Register */
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* Reserved [0x61] */
+
+/* Wake-up Timer Control and Status Register */
+#define WUTCSR _SFR_MEM8(0x62)
+#define WUTIF 7
+#define WUTIE 6
+#define WUTCF 5
+#define WUTR 4
+#define WUTE 3
+#define WUTP2 2
+#define WUTP1 1
+#define WUTP0 0
+
+/* Reserved [0x63] */
+
+/* Power Reduction Register 0 */
+#define PRR0 _SFR_MEM8(0x64)
+#define PRTWI 3
+#define PRTIM1 2
+#define PRTIM0 1
+#define PRVADC 0
+
+/* Reserved [0x65] */
+
+/* Fast Oscillator Calibration Register */
+#define FOSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67] */
+
+/* Pin Change Interrupt Control Register */
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE1 1
+#define PCIE0 0
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x69)
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Reserved [0x6A] */
+
+/* Pin Change Mask Register 0 */
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+/* Pin Change Mask Register 1 */
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT15 7
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+/* Reserved [0x6D] */
+
+/* Timer/Counter Interrupt MaSK register 0 */
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+/* Timer/Counter Interrupt MaSK register 1 */
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define OCIE1A 1
+#define TOIE1 0
+
+/* Reserved [0x70..0x77] */
+
+/* V-ADC Data Register */
+#define VADC _SFR_MEM16(0x78)
+#define VADCL _SFR_MEM8(0x78)
+#define VADCH _SFR_MEM8(0x79)
+
+/* V-ADC Control and Status Register */
+#define VADCSR _SFR_MEM8(0x7A)
+#define VADEN 3
+#define VADSC 2
+#define VADCCIF 1
+#define VADCCIE 0
+
+/* Reserved [0x7B] */
+
+/* V-ADC Multiplexer Selection Register */
+#define VADMUX _SFR_MEM8(0x7C)
+#define VADMUX3 3
+#define VADMUX2 2
+#define VADMUX1 1
+#define VADMUX0 0
+
+/* Reserved [0x7D] */
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_MEM8(0x7E)
+#define VADC3D 3
+#define VADC2D 2
+#define VADC1D 1
+#define VADC0D 0
+
+/* Reserved [0x82..0x83] */
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_MEM8(0x81)
+#define CTC1 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Reserved [0x82..0x83] */
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Reserved [0x86..0x87] */
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_MEM16(0x88)
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Reserved [0x8A..0xB7] */
+
+/* 2-wire Serial Interface Bit Rate Register */
+#define TWBR _SFR_MEM8(0xB8)
+
+/* 2-wire Serial Interface Status Register */
+#define TWSR _SFR_MEM8(0xB9)
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+/* 2-wire Serial Interface Address Register */
+#define TWAR _SFR_MEM8(0xBA)
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+/* 2-wire Serial Interface Data Register */
+#define TWDR _SFR_MEM8(0xBB)
+
+/* 2-wire Serial Interface Control Register */
+#define TWCR _SFR_MEM8(0xBC)
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+/* 2-wire Serial (Slave) Address Mask Register */
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM6 7
+#define TWAM5 6
+#define TWAM4 5
+#define TWAM3 4
+#define TWAM2 3
+#define TWAM1 2
+#define TWAM0 1
+
+/* 2-wire Serial Bus Control and Status Register */
+#define TWBCSR _SFR_MEM8(0xBE)
+#define TWBCIF 7
+#define TWBCIE 6
+#define TWBDT1 2
+#define TWBDT0 1
+#define TWBCIP 0
+
+/* Reserved [0xBF] */
+
+/* Clock Control Status Register */
+#define CCSR _SFR_MEM8(0xC0)
+#define XOE 1
+#define ACS 0
+
+/* Reserved [0xC1..0xCF] */
+
+/* Bandgap Calibration C Register */
+#define BGCCR _SFR_MEM8(0xD0)
+#define BGEN 7
+#define BGCC5 5
+#define BGCC4 4
+#define BGCC3 3
+#define BGCC2 2
+#define BGCC1 1
+#define BGCC0 0
+
+/* Bandgap Calibration R Register */
+#define BGCRR _SFR_MEM8(0xD1)
+#define BGCR7 7
+#define BGCR6 6
+#define BGCR5 5
+#define BGCR4 4
+#define BGCR3 3
+#define BGCR2 2
+#define BGCR1 1
+#define BGCR0 0
+
+/* Reserved [0xD2..0xDF] */
+
+/* CC-ADC Accumulate Current */
+/* TODO: Add _SFR_MEM32 */
+/* #define CADAC _SFR_MEM32(0xE0) */
+#define CADAC0 _SFR_MEM8(0xE0)
+#define CADAC1 _SFR_MEM8(0xE1)
+#define CADAC2 _SFR_MEM8(0xE2)
+#define CADAC3 _SFR_MEM8(0xE3)
+
+/* CC-ADC Control and Status Register A */
+#define CADCSRA _SFR_MEM8(0xE4)
+#define CADEN 7
+#define CADUB 5
+#define CADAS1 4
+#define CADAS0 3
+#define CADSI1 2
+#define CADSI0 1
+#define CADSE 0
+
+/* CC-ADC Control and Status Register B */
+#define CADCSRB _SFR_MEM8(0xE5)
+#define CADACIE 6
+#define CADRCIE 5
+#define CADICIE 4
+#define CADACIF 2
+#define CADRCIF 1
+#define CADICIF 0
+
+/* CC-ADC Regular Charge Current */
+#define CADRCC _SFR_MEM8(0xE6)
+
+/* CC-ADC Regular Discharge Current */
+#define CADRDC _SFR_MEM8(0xE7)
+
+/* CC-ADC Instantaneous Current */
+#define CADIC _SFR_MEM16(0xE8)
+#define CADICL _SFR_MEM8(0xE8)
+#define CADICH _SFR_MEM8(0xE9)
+
+/* Reserved [0xEA..0xEF] */
+
+/* FET Control and Status Register */
+#define FCSR _SFR_MEM8(0xF0)
+#define PWMOC 5
+#define PWMOPC 4
+#define CPS 3
+#define DFE 2
+#define CFE 1
+#define PFD 0
+
+/* Cell Balancing Control Register */
+#define CBCR _SFR_MEM8(0xF1)
+#define CBE4 3
+#define CBE3 2
+#define CBE2 1
+#define CBE1 0
+
+/* Battery Protection Interrupt Register */
+#define BPIR _SFR_MEM8(0xF2)
+#define DUVIF 7
+#define COCIF 6
+#define DOCIF 5
+#define SCIF 4
+#define DUVIE 3
+#define COCIE 2
+#define DOCIE 1
+#define SCIE 0
+
+/* Battery Protection Deep Under Voltage Register */
+#define BPDUV _SFR_MEM8(0xF3)
+#define DUVT1 5
+#define DUVT0 4
+#define DUDL3 3
+#define DUDL2 2
+#define DUDL1 1
+#define DUDL0 0
+
+/* Battery Protection Short-circuit Detection Level Register */
+#define BPSCD _SFR_MEM8(0xF4)
+#define SCDL3 3
+#define SCDL2 2
+#define SCDL1 1
+#define SCDL0 0
+
+/* Battery Protection Over-current Detection Level Register */
+#define BPOCD _SFR_MEM8(0xF5)
+#define DCDL3 7
+#define DCDL2 6
+#define DCDL1 5
+#define DCDL0 4
+#define CCDL3 3
+#define CCDL2 2
+#define CCDL1 1
+#define CCDL0 0
+
+/* Current Battery Protection Timing Register */
+#define CBPTR _SFR_MEM8(0xF6)
+#define SCPT3 7
+#define SCPT2 6
+#define SCPT1 5
+#define SCPT0 4
+#define OCPT3 3
+#define OCPT2 2
+#define OCPT1 1
+#define OCPT0 0
+
+/* Battery Protection Control Register */
+#define BPCR _SFR_MEM8(0xF7)
+#define DUVD 3
+#define SCD 2
+#define DCD 1
+#define CCD 0
+
+/* Battery Protection Parameter Lock Register */
+#define BPPLR _SFR_MEM8(0xF8)
+#define BPPLE 1
+#define BPPL 0
+
+/* Reserved [0xF9..0xFF] */
+
+/* Interrupt vectors */
+/* Battery Protection Interrupt */
+#define BPINT_vect _VECTOR(1)
+
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(2)
+
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(3)
+
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(4)
+
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(5)
+
+
+/* Pin Change Interrupt 0 */
+#define PCINT0_vect _VECTOR(6)
+
+
+/* Pin Change Interrupt 1 */
+#define PCINT1_vect _VECTOR(7)
+
+
+/* Watchdog Timeout Interrupt */
+#define WDT_vect _VECTOR(8)
+
+
+/* Wakeup timer overflow */
+#define WAKE_UP_vect _VECTOR(9)
+
+
+/* Timer/Counter 1 Compare Match */
+#define TIM1_COMP_vect _VECTOR(10)
+
+
+/* Timer/Counter 1 Overflow */
+#define TIM1_OVF_vect _VECTOR(11)
+
+
+/* Timer/Counter0 Compare A Match */
+#define TIM0_COMPA_vect _VECTOR(12)
+
+
+/* Timer/Counter0 Compare B Match */
+#define TIM0_COMPB_vect _VECTOR(13)
+
+
+/* Timer/Counter0 Overflow */
+#define TIM0_OVF_vect _VECTOR(14)
+
+
+/* Two-Wire Bus Connect/Disconnect */
+#define TWI_BUS_CD_vect _VECTOR(15)
+
+
+/* Two-Wire Serial Interface */
+#define TWI_vect _VECTOR(16)
+
+
+/* Voltage ADC Conversion Complete */
+#define VADC_vect _VECTOR(17)
+
+
+/* Coulomb Counter ADC Conversion Complete */
+#define CCADC_CONV_vect _VECTOR(18)
+
+/* Coloumb Counter ADC Regular Current */
+#define CCADC_REG_CUR_vect _VECTOR(19)
+
+
+/* Coloumb Counter ADC Accumulator */
+#define CCADC_ACC_vect _VECTOR(20)
+
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(21)
+
+
+/* Store Program Memory Ready */
+#define SPM_READY_vect _VECTOR(22)
+
+#define _VECTORS_SIZE 92
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x8FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x9FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL (unsigned char)~_BV(0)
+#define FUSE_SUT0 (unsigned char)~_BV(1)
+#define FUSE_SUT1 (unsigned char)~_BV(2)
+#define FUSE_BOOTRST (unsigned char)~_BV(3)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(4)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(5)
+#define FUSE_EESAVE (unsigned char)~_BV(6)
+#define FUSE_WDTON (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_SUT0 & FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+/* High Fuse Byte */
+#define FUSE_JTAGEN (unsigned char)~_BV(0)
+#define FUSE_OCDEN (unsigned char)~_BV(1)
+#define HFUSE_DEFAULT (FUSE_JTAGEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOM406_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom48.h b/cpukit/score/cpu/avr/avr/iom48.h
new file mode 100644
index 0000000000..4c8aab117e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom48.h
@@ -0,0 +1,87 @@
+/* Copyright (c) 2004, Theodore A. Roth
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM48_H_
+#define _AVR_IOM48_H_ 1
+
+#include <avr/iomx8.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x2FF
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOM48_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom48p.h b/cpukit/score/cpu/avr/avr/iom48p.h
new file mode 100644
index 0000000000..cdd6d4291e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom48p.h
@@ -0,0 +1,868 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom48p.h - definitions for ATmega48P. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom48p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM48P_H_
+#define _AVR_IOM48P_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+/* Only valid for ATmega88P-168P-328P */
+/* EEARH _SFR_IO8(0x22) */
+
+#define EEPROM_REG_LOCATIONS 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 0
+#define TWAM1 1
+#define TWAM2 2
+#define TWAM3 3
+#define TWAM4 4
+#define TWAM5 5
+#define TWAM6 6
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCPHA0 1
+#define UCSZ01 2
+#define UDORD0 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0_0 0
+#define UBRR0_1 1
+#define UBRR0_2 2
+#define UBRR0_3 3
+#define UBRR0_4 4
+#define UBRR0_5 5
+#define UBRR0_6 6
+#define UBRR0_7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR0_8 0
+#define UBRR0_9 1
+#define UBRR0_10 2
+#define UBRR0_11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
+#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
+#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
+#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
+#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
+#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
+#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
+#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
+#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
+#define SPM_READY_vect _VECTOR(25) /* Store Program Memory Read */
+
+#define _VECTORS_SIZE (26 * 2)
+
+
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x2FF /* Last On-Chip SRAM Location */
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x0A
+
+
+#endif /* _AVR_IOM48P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom64.h b/cpukit/score/cpu/avr/avr/iom64.h
new file mode 100644
index 0000000000..e960f4c937
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom64.h
@@ -0,0 +1,1227 @@
+/* Copyright (c) 2002, Steinar Haugen
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom64.h - defines for ATmega64
+
+ As of 2002-11-23:
+ - This should be up to date with data sheet Rev. 2490C-AVR-09/02 */
+
+#ifndef _AVR_IOM64_H_
+#define _AVR_IOM64_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom64.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Input Pins, Port F */
+#define PINF _SFR_IO8(0x00)
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x01)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x02)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x03)
+
+/* ADC Data Register */
+#define ADCW _SFR_IO16(0x04) /* for backwards compatibility */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register A */
+#define ADCSR _SFR_IO8(0x06) /* for backwards compatibility */
+#define ADCSRA _SFR_IO8(0x06)
+
+/* ADC Multiplexer select */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* USART0 Baud Rate Register Low */
+#define UBRR0L _SFR_IO8(0x09)
+
+/* USART0 Control and Status Register B */
+#define UCSR0B _SFR_IO8(0x0A)
+
+/* USART0 Control and Status Register A */
+#define UCSR0A _SFR_IO8(0x0B)
+
+/* USART0 I/O Data Register */
+#define UDR0 _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* Special Function I/O Register */
+#define SFIOR _SFR_IO8(0x20)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* On-chip Debug Register */
+#define OCDR _SFR_IO8(0x22)
+
+/* Timer2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x23)
+
+/* Timer/Counter 2 */
+#define TCNT2 _SFR_IO8(0x24)
+
+/* Timer/Counter 2 Control register */
+#define TCCR2 _SFR_IO8(0x25)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Timer/Counter 0 Asynchronous Control & Status Register */
+#define ASSR _SFR_IO8(0x30)
+
+/* Output Compare Register 0 */
+#define OCR0 _SFR_IO8(0x31)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34) /* for backwards compatibility */
+#define MCUCSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x36)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x37)
+
+/* External Interrupt Flag Register */
+#define EIFR _SFR_IO8(0x38)
+
+/* External Interrupt MaSK register */
+#define EIMSK _SFR_IO8(0x39)
+
+/* External Interrupt Control Register B */
+#define EICRB _SFR_IO8(0x3A)
+
+/* XDIV Divide control register */
+#define XDIV _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Extended I/O registers */
+
+/* Data Direction Register, Port F */
+#define DDRF _SFR_MEM8(0x61)
+
+/* Data Register, Port F */
+#define PORTF _SFR_MEM8(0x62)
+
+/* Input Pins, Port G */
+#define PING _SFR_MEM8(0x63)
+
+/* Data Direction Register, Port G */
+#define DDRG _SFR_MEM8(0x64)
+
+/* Data Register, Port G */
+#define PORTG _SFR_MEM8(0x65)
+
+/* Store Program Memory Control and Status Register */
+#define SPMCR _SFR_MEM8(0x68)
+#define SPMCSR _SFR_MEM8(0x68) /* for backwards compatibility with m128*/
+
+/* External Interrupt Control Register A */
+#define EICRA _SFR_MEM8(0x6A)
+
+/* External Memory Control Register B */
+#define XMCRB _SFR_MEM8(0x6C)
+
+/* External Memory Control Register A */
+#define XMCRA _SFR_MEM8(0x6D)
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_MEM8(0x6F)
+
+/* 2-wire Serial Interface Bit Rate Register */
+#define TWBR _SFR_MEM8(0x70)
+
+/* 2-wire Serial Interface Status Register */
+#define TWSR _SFR_MEM8(0x71)
+
+/* 2-wire Serial Interface Address Register */
+#define TWAR _SFR_MEM8(0x72)
+
+/* 2-wire Serial Interface Data Register */
+#define TWDR _SFR_MEM8(0x73)
+
+/* 2-wire Serial Interface Control Register */
+#define TWCR _SFR_MEM8(0x74)
+
+/* Time Counter 1 Output Compare Register C */
+#define OCR1C _SFR_MEM16(0x78)
+#define OCR1CL _SFR_MEM8(0x78)
+#define OCR1CH _SFR_MEM8(0x79)
+
+/* Timer/Counter 1 Control Register C */
+#define TCCR1C _SFR_MEM8(0x7A)
+
+/* Extended Timer Interrupt Flag Register */
+#define ETIFR _SFR_MEM8(0x7C)
+
+/* Extended Timer Interrupt Mask Register */
+#define ETIMSK _SFR_MEM8(0x7D)
+
+/* Timer/Counter 3 Input Capture Register */
+#define ICR3 _SFR_MEM16(0x80)
+#define ICR3L _SFR_MEM8(0x80)
+#define ICR3H _SFR_MEM8(0x81)
+
+/* Timer/Counter 3 Output Compare Register C */
+#define OCR3C _SFR_MEM16(0x82)
+#define OCR3CL _SFR_MEM8(0x82)
+#define OCR3CH _SFR_MEM8(0x83)
+
+/* Timer/Counter 3 Output Compare Register B */
+#define OCR3B _SFR_MEM16(0x84)
+#define OCR3BL _SFR_MEM8(0x84)
+#define OCR3BH _SFR_MEM8(0x85)
+
+/* Timer/Counter 3 Output Compare Register A */
+#define OCR3A _SFR_MEM16(0x86)
+#define OCR3AL _SFR_MEM8(0x86)
+#define OCR3AH _SFR_MEM8(0x87)
+
+/* Timer/Counter 3 Counter Register */
+#define TCNT3 _SFR_MEM16(0x88)
+#define TCNT3L _SFR_MEM8(0x88)
+#define TCNT3H _SFR_MEM8(0x89)
+
+/* Timer/Counter 3 Control Register B */
+#define TCCR3B _SFR_MEM8(0x8A)
+
+/* Timer/Counter 3 Control Register A */
+#define TCCR3A _SFR_MEM8(0x8B)
+
+/* Timer/Counter 3 Control Register C */
+#define TCCR3C _SFR_MEM8(0x8C)
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_MEM8(0x8E)
+
+/* USART0 Baud Rate Register High */
+#define UBRR0H _SFR_MEM8(0x90)
+
+/* USART0 Control and Status Register C */
+#define UCSR0C _SFR_MEM8(0x95)
+
+/* USART1 Baud Rate Register High */
+#define UBRR1H _SFR_MEM8(0x98)
+
+/* USART1 Baud Rate Register Low*/
+#define UBRR1L _SFR_MEM8(0x99)
+
+/* USART1 Control and Status Register B */
+#define UCSR1B _SFR_MEM8(0x9A)
+
+/* USART1 Control and Status Register A */
+#define UCSR1A _SFR_MEM8(0x9B)
+
+/* USART1 I/O Data Register */
+#define UDR1 _SFR_MEM8(0x9C)
+
+/* USART1 Control and Status Register C */
+#define UCSR1C _SFR_MEM8(0x9D)
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+#define SIG_INTERRUPT3 _VECTOR(4)
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+#define SIG_INTERRUPT4 _VECTOR(5)
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+#define SIG_INTERRUPT5 _VECTOR(6)
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+#define SIG_INTERRUPT6 _VECTOR(7)
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+#define SIG_INTERRUPT7 _VECTOR(8)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(9)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(10)
+#define SIG_OVERFLOW2 _VECTOR(10)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(11)
+#define SIG_INPUT_CAPTURE1 _VECTOR(11)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(12)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(13)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(14)
+#define SIG_OVERFLOW1 _VECTOR(14)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(15)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(15)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(16)
+#define SIG_OVERFLOW0 _VECTOR(16)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(17)
+#define SIG_SPI _VECTOR(17)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(18)
+#define SIG_UART0_RECV _VECTOR(18)
+
+/* USART0 Data Register Empty */
+#define USART0_UDRE_vect _VECTOR(19)
+#define SIG_UART0_DATA _VECTOR(19)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(20)
+#define SIG_UART0_TRANS _VECTOR(20)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(21)
+#define SIG_ADC _VECTOR(21)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(22)
+#define SIG_EEPROM_READY _VECTOR(22)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(23)
+#define SIG_COMPARATOR _VECTOR(23)
+
+/* Timer/Counter1 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(24)
+#define SIG_OUTPUT_COMPARE1C _VECTOR(24)
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(25)
+#define SIG_INPUT_CAPTURE3 _VECTOR(25)
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(26)
+#define SIG_OUTPUT_COMPARE3A _VECTOR(26)
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(27)
+#define SIG_OUTPUT_COMPARE3B _VECTOR(27)
+
+/* Timer/Counter3 Compare Match C */
+#define TIMER3_COMPC_vect _VECTOR(28)
+#define SIG_OUTPUT_COMPARE3C _VECTOR(28)
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(29)
+#define SIG_OVERFLOW3 _VECTOR(29)
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(30)
+#define SIG_UART1_RECV _VECTOR(30)
+
+/* USART1, Data Register Empty */
+#define USART1_UDRE_vect _VECTOR(31)
+#define SIG_UART1_DATA _VECTOR(31)
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(32)
+#define SIG_UART1_TRANS _VECTOR(32)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(33)
+#define SIG_2WIRE_SERIAL _VECTOR(33)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(34)
+#define SIG_SPM_READY _VECTOR(34)
+
+#define _VECTORS_SIZE 140
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* 2-wire Control Register - TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+/* 2-wire Address Register - TWAR */
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+/* 2-wire Status Register - TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+/* External Memory Control Register A - XMCRA */
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW01 3
+#define SRW00 2
+#define SRW11 1
+
+/* External Memory Control Register B - XMCRA */
+#define XMBK 7
+#define XMM2 2
+#define XMM1 1
+#define XMM0 0
+
+/* XDIV Divide control register - XDIV */
+#define XDIVEN 7
+#define XDIV6 6
+#define XDIV5 5
+#define XDIV4 4
+#define XDIV3 3
+#define XDIV2 2
+#define XDIV1 1
+#define XDIV0 0
+
+/* External Interrupt Control Register A - EICRA */
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* External Interrupt Control Register B - EICRB */
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+
+/* Store Program Memory Control Register - SPMCSR, SPMCR */
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* External Interrupt MaSK register - EIMSK */
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+/* External Interrupt Flag Register - EIFR */
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+/* Timer/Counter Interrupt MaSK register - TIMSK */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define OCIE0 1
+#define TOIE0 0
+
+/* Timer/Counter Interrupt Flag Register - TIFR */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define OCF0 1
+#define TOV0 0
+
+/* Extended Timer Interrupt MaSK register - ETIMSK */
+#define TICIE3 5
+#define OCIE3A 4
+#define OCIE3B 3
+#define TOIE3 2
+#define OCIE3C 1
+#define OCIE1C 0
+
+/* Extended Timer Interrupt Flag Register - ETIFR */
+#define ICF3 5
+#define OCF3A 4
+#define OCF3B 3
+#define TOV3 2
+#define OCF3C 1
+#define OCF1C 0
+
+/* MCU Control Register - MCUCR */
+#define SRE 7
+#define SRW10 6
+#define SE 5
+#define SM1 4
+#define SM0 3
+#define SM2 2
+#define IVSEL 1
+#define IVCE 0
+
+/* MCU Control And Status Register - MCUCSR */
+#define JTD 7
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* Timer/Counter Control Register (generic) */
+#define FOC 7
+#define WGM0 6
+#define COM1 5
+#define COM0 4
+#define WGM1 3
+#define CS2 2
+#define CS1 1
+#define CS0 0
+
+/* Timer/Counter 0 Control Register - TCCR0 */
+#define FOC0 7
+#define WGM00 6
+#define COM01 5
+#define COM00 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Timer/Counter 2 Control Register - TCCR2 */
+#define FOC2 7
+#define WGM20 6
+#define COM21 5
+#define COM20 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Timer/Counter 0 Asynchronous Control & Status Register - ASSR */
+#define AS0 3
+#define TCN0UB 2
+#define OCR0UB 1
+#define TCR0UB 0
+
+/* Timer/Counter Control Register A (generic) */
+#define COMA1 7
+#define COMA0 6
+#define COMB1 5
+#define COMB0 4
+#define COMC1 3
+#define COMC0 2
+#define WGMA1 1
+#define WGMA0 0
+
+/* Timer/Counter 1 Control and Status Register A - TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define COM1C1 3
+#define COM1C0 2
+#define WGM11 1
+#define WGM10 0
+
+/* Timer/Counter 3 Control and Status Register A - TCCR3A */
+#define COM3A1 7
+#define COM3A0 6
+#define COM3B1 5
+#define COM3B0 4
+#define COM3C1 3
+#define COM3C0 2
+#define WGM31 1
+#define WGM30 0
+
+/* Timer/Counter Control and Status Register B (generic) */
+#define ICNC 7
+#define ICES 6
+#define WGMB3 4
+#define WGMB2 3
+#define CSB2 2
+#define CSB1 1
+#define CSB0 0
+
+/* Timer/Counter 1 Control and Status Register B - TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter 3 Control and Status Register B - TCCR3B */
+#define ICNC3 7
+#define ICES3 6
+#define WGM33 4
+#define WGM32 3
+#define CS32 2
+#define CS31 1
+#define CS30 0
+
+/* Timer/Counter Control Register C (generic) */
+#define FOCA 7
+#define FOCB 6
+#define FOCC 5
+
+/* Timer/Counter 3 Control Register C - TCCR3C */
+#define FOC3A 7
+#define FOC3B 6
+#define FOC3C 5
+
+/* Timer/Counter 1 Control Register C - TCCR1C */
+#define FOC1A 7
+#define FOC1B 6
+#define FOC1C 5
+
+/* On-chip Debug Register - OCDR */
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* Watchdog Timer Control Register - WDTCR */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ The ADHSM bit has been removed from all documentation,
+ as being not needed at all since the comparator has proven
+ to be fast enough even without feeding it more power.
+*/
+
+/* Special Function I/O Register - SFIOR */
+#define TSM 7
+#define ACME 3
+#define PUD 2
+#define PSR0 1
+#define PSR321 0
+
+/* Port Data Register (generic) */
+#define PORT7 7
+#define PORT6 6
+#define PORT5 5
+#define PORT4 4
+#define PORT3 3
+#define PORT2 2
+#define PORT1 1
+#define PORT0 0
+
+/* Port Data Direction Register (generic) */
+#define DD7 7
+#define DD6 6
+#define DD5 5
+#define DD4 4
+#define DD3 3
+#define DD2 2
+#define DD1 1
+#define DD0 0
+
+/* Port Input Pins (generic) */
+#define PIN7 7
+#define PIN6 6
+#define PIN5 5
+#define PIN4 4
+#define PIN3 3
+#define PIN2 2
+#define PIN1 1
+#define PIN0 0
+
+/* SPI Status Register - SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPI Control Register - SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* USART Register C (generic) */
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* USART1 Register C - UCSR1C */
+#define UMSEL1 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+
+/* USART0 Register C - UCSR0C */
+#define UMSEL0 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPOL0 0
+
+/* USART Status Register A (generic) */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define UPE 2
+#define U2X 1
+#define MPCM 0
+
+/* USART1 Status Register A - UCSR1A */
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+/* USART0 Status Register A - UCSR0A */
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+/* USART Control Register B (generic) */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ 2
+#define UCSZ2 2 /* new name in datasheet (2467E-AVR-05/02) */
+#define RXB8 1
+#define TXB8 0
+
+/* USART1 Control Register B - UCSR1B */
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+/* USART0 Control Register B - UCSR0B */
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+/* Analog Comparator Control and Status Register - ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC Control and Status Register B - ADCSRB */
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+/* ADC Control and status Register A - ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADC Multiplexer select - ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* Port A Data Register - PORTA */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Port A Data Direction Register - DDRA */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Port A Input Pins - PINA */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Port B Data Register - PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Port B Data Direction Register - DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Port B Input Pins - PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Port C Data Register - PORTC */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Port C Data Direction Register - DDRC */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Port C Input Pins - PINC */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Port D Data Register - PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Port D Data Direction Register - DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Port D Input Pins - PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Port E Data Register - PORTE */
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Port E Data Direction Register - DDRE */
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Port E Input Pins - PINE */
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* Port F Data Register - PORTF */
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+/* Port F Data Direction Register - DDRF */
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+/* Port F Input Pins - PINF */
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+/* Port G Data Register - PORTG */
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+/* Port G Data Direction Register - DDRG */
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+/* Port G Input Pins - PING */
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x07FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_WDTON (unsigned char)~_BV(0)
+#define FUSE_M103C (unsigned char)~_BV(1)
+#define EFUSE_DEFAULT (FUSE_M103C)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x02
+
+
+#endif /* _AVR_IOM64_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom640.h b/cpukit/score/cpu/avr/avr/iom640.h
new file mode 100644
index 0000000000..39b21ca9f0
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom640.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom640.h - definitions for ATmega640 */
+
+#ifndef _AVR_IOM640_H_
+#define _AVR_IOM640_H_ 1
+
+#include <avr/iomxx0_1.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x21FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x08
+
+
+#endif /* _AVR_IOM640_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom644.h b/cpukit/score/cpu/avr/avr/iom644.h
new file mode 100644
index 0000000000..9d10921653
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom644.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom644.h - definitions for ATmega644 */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM644_H_
+#define _AVR_IOM644_H_ 1
+
+#include <avr/iomxx4.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND RAMEND
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x09
+
+
+#endif /* _AVR_IOM644_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom644p.h b/cpukit/score/cpu/avr/avr/iom644p.h
new file mode 100644
index 0000000000..8bc94b299a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom644p.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom644p.h - definitions for ATmega644P */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM644P_H_
+#define _AVR_IOM644P_H_ 1
+
+#include <avr/iomxx4.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND RAMEND
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x0A
+
+
+#endif /* _AVR_IOM644P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom644pa.h b/cpukit/score/cpu/avr/avr/iom644pa.h
new file mode 100644
index 0000000000..da68676671
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom644pa.h
@@ -0,0 +1,1370 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom644PA.h - definitions for ATmega644PA */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom644PA.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega644PA_H_
+#define _AVR_ATmega644PA_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRUSART1 4
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+#define PCINT31 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A_0 0
+#define OCR2A_1 1
+#define OCR2A_2 2
+#define OCR2A_3 3
+#define OCR2A_4 4
+#define OCR2A_5 5
+#define OCR2A_6 6
+#define OCR2A_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2B_0 0
+#define OCR2B_1 1
+#define OCR2B_2 2
+#define OCR2B_3 3
+#define OCR2B_4 4
+#define OCR2B_5 5
+#define OCR2B_6 6
+#define OCR2B_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define _UBRR0 0
+#define _UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR_0 0
+#define UBRR_1 1
+#define UBRR_2 2
+#define UBRR_3 3
+#define UBRR_4 4
+#define UBRR_5 5
+#define UBRR_6 6
+#define UBRR_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR_8 0
+#define UBRR_9 1
+#define UBRR_10 2
+#define UBRR_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define PCINT0_vect_num 4
+#define PCINT0_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 5
+#define PCINT1_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 6
+#define PCINT2_vect _VECTOR(6) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 7
+#define PCINT3_vect _VECTOR(7) /* Pin Change Interrupt Request 3 */
+#define WDT_vect_num 8
+#define WDT_vect _VECTOR(8) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect_num 9
+#define TIMER2_COMPA_vect _VECTOR(9) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect_num 10
+#define TIMER2_COMPB_vect _VECTOR(10) /* Timer/Counter2 Compare Match B */
+#define TIMER2_OVF_vect_num 11
+#define TIMER2_OVF_vect _VECTOR(11) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 12
+#define TIMER1_CAPT_vect _VECTOR(12) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 13
+#define TIMER1_COMPA_vect _VECTOR(13) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 14
+#define TIMER1_COMPB_vect _VECTOR(14) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 15
+#define TIMER1_OVF_vect _VECTOR(15) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 16
+#define TIMER0_COMPA_vect _VECTOR(16) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 17
+#define TIMER0_COMPB_vect _VECTOR(17) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 18
+#define TIMER0_OVF_vect _VECTOR(18) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 19
+#define SPI_STC_vect _VECTOR(19) /* SPI Serial Transfer Complete */
+#define USART0_RX_vect_num 20
+#define USART0_RX_vect _VECTOR(20) /* USART0, Rx Complete */
+#define USART0_UDRE_vect_num 21
+#define USART0_UDRE_vect _VECTOR(21) /* USART0 Data register Empty */
+#define USART0_TX_vect_num 22
+#define USART0_TX_vect _VECTOR(22) /* USART0, Tx Complete */
+#define ANALOG_COMP_vect_num 23
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define ADC_vect_num 24
+#define ADC_vect _VECTOR(24) /* ADC Conversion Complete */
+#define EE_READY_vect_num 25
+#define EE_READY_vect _VECTOR(25) /* EEPROM Ready */
+#define TWI_vect_num 26
+#define TWI_vect _VECTOR(26) /* 2-wire Serial Interface */
+#define SPM_READY_vect_num 27
+#define SPM_READY_vect _VECTOR(27) /* Store Program Memory Read */
+#define USART1_RX_vect_num 28
+#define USART1_RX_vect _VECTOR(28) /* USART1 RX complete */
+#define USART1_UDRE_vect_num 29
+#define USART1_UDRE_vect _VECTOR(29) /* USART1 Data Register Empty */
+#define USART1_TX_vect_num 30
+#define USART1_TX_vect _VECTOR(30) /* USART1 TX complete */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (256)
+#define RAMSTART (0x100)
+#define RAMSIZE (4096)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7FF)
+#define E2PAGESIZE (8)
+#define FLASHEND (0xFFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x0A
+
+
+/* Device Pin Definitions */
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 5
+
+#define PCINT13_DDR DDRB
+#define PCINT13_PORT PORTB
+#define PCINT13_PIN PINB
+#define PCINT13_BIT 5
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 6
+
+#define PCINT14_DDR DDRB
+#define PCINT14_PORT PORTB
+#define PCINT14_PIN PINB
+#define PCINT14_BIT 6
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 7
+
+#define PCINT15_DDR DDRB
+#define PCINT15_PORT PORTB
+#define PCINT15_PIN PINB
+#define PCINT15_BIT 7
+
+#define RXD_DDR DDRD
+#define RXD_PORT PORTD
+#define RXD_PIN PIND
+#define RXD_BIT 0
+
+#define PCINT24_DDR DDRD
+#define PCINT24_PORT PORTD
+#define PCINT24_PIN PIND
+#define PCINT24_BIT 0
+
+#define TXD_DDR DDRD
+#define TXD_PORT PORTD
+#define TXD_PIN PIND
+#define TXD_BIT 1
+
+#define PCINT25_DDR DDRD
+#define PCINT25_PORT PORTD
+#define PCINT25_PIN PIND
+#define PCINT25_BIT 1
+
+#define INT0_DDR DDRD
+#define INT0_PORT PORTD
+#define INT0_PIN PIND
+#define INT0_BIT 2
+
+#define RDX1_DDR DDRD
+#define RDX1_PORT PORTD
+#define RDX1_PIN PIND
+#define RDX1_BIT 2
+
+#define PCINT26_DDR DDRD
+#define PCINT26_PORT PORTD
+#define PCINT26_PIN PIND
+#define PCINT26_BIT 2
+
+#define INT1_DDR DDRD
+#define INT1_PORT PORTD
+#define INT1_PIN PIND
+#define INT1_BIT 3
+
+#define TXD1_DDR DDRD
+#define TXD1_PORT PORTD
+#define TXD1_PIN PIND
+#define TXD1_BIT 3
+
+#define PCINT27_DDR DDRD
+#define PCINT27_PORT PORTD
+#define PCINT27_PIN PIND
+#define PCINT27_BIT 3
+
+#define OC1B_DDR DDRD
+#define OC1B_PORT PORTD
+#define OC1B_PIN PIND
+#define OC1B_BIT 4
+
+#define XCK1_DDR DDRD
+#define XCK1_PORT PORTD
+#define XCK1_PIN PIND
+#define XCK1_BIT 4
+
+#define PCINT28_DDR DDRD
+#define PCINT28_PORT PORTD
+#define PCINT28_PIN PIND
+#define PCINT28_BIT 4
+
+#define OC1A_DDR DDRD
+#define OC1A_PORT PORTD
+#define OC1A_PIN PIND
+#define OC1A_BIT 5
+
+#define PCINT29_DDR DDRD
+#define PCINT29_PORT PORTD
+#define PCINT29_PIN PIND
+#define PCINT29_BIT 5
+
+#define ICP_DDR DDRD
+#define ICP_PORT PORTD
+#define ICP_PIN PIND
+#define ICP_BIT 6
+
+#define OC2B_DDR DDRD
+#define OC2B_PORT PORTD
+#define OC2B_PIN PIND
+#define OC2B_BIT 6
+
+#define PCINT30_DDR DDRD
+#define PCINT30_PORT PORTD
+#define PCINT30_PIN PIND
+#define PCINT30_BIT 6
+
+#define OC2A_DDR DDRD
+#define OC2A_PORT PORTD
+#define OC2A_PIN PIND
+#define OC2A_BIT 7
+
+#define PCINT31_DDR DDRD
+#define PCINT31_PORT PORTD
+#define PCINT31_PIN PIND
+#define PCINT31_BIT 7
+
+#define SCL_DDR DDRC
+#define SCL_PORT PORTC
+#define SCL_PIN PINC
+#define SCL_BIT 0
+
+#define PCINT16_DDR DDRC
+#define PCINT16_PORT PORTC
+#define PCINT16_PIN PINC
+#define PCINT16_BIT 0
+
+#define SDA_DDR DDRC
+#define SDA_PORT PORTC
+#define SDA_PIN PINC
+#define SDA_BIT 1
+
+#define PCINT17_DDR DDRC
+#define PCINT17_PORT PORTC
+#define PCINT17_PIN PINC
+#define PCINT17_BIT 1
+
+#define PCINT18_DDR DDRC
+#define PCINT18_PORT PORTC
+#define PCINT18_PIN PINC
+#define PCINT18_BIT 2
+
+#define PCINT19_DDR DDRC
+#define PCINT19_PORT PORTC
+#define PCINT19_PIN PINC
+#define PCINT19_BIT 3
+
+#define PCINT20_DDR DDRC
+#define PCINT20_PORT PORTC
+#define PCINT20_PIN PINC
+#define PCINT20_BIT 4
+
+#define PCINT21_DDR DDRC
+#define PCINT21_PORT PORTC
+#define PCINT21_PIN PINC
+#define PCINT21_BIT 5
+
+#define PCINT22_DDR DDRC
+#define PCINT22_PORT PORTC
+#define PCINT22_PIN PINC
+#define PCINT22_BIT 6
+
+#define PCINT23_DDR DDRC
+#define PCINT23_PORT PORTC
+#define PCINT23_PIN PINC
+#define PCINT23_BIT 7
+
+#define ADC7_DDR DDRA
+#define ADC7_PORT PORTA
+#define ADC7_PIN PINA
+#define ADC7_BIT 7
+
+#define PCINT7_DDR DDRA
+#define PCINT7_PORT PORTA
+#define PCINT7_PIN PINA
+#define PCINT7_BIT 7
+
+#define ADC6_DDR DDRA
+#define ADC6_PORT PORTA
+#define ADC6_PIN PINA
+#define ADC6_BIT 6
+
+#define PCINT6_DDR DDRA
+#define PCINT6_PORT PORTA
+#define PCINT6_PIN PINA
+#define PCINT6_BIT 6
+
+#define ADC5_DDR DDRA
+#define ADC5_PORT PORTA
+#define ADC5_PIN PINA
+#define ADC5_BIT 5
+
+#define PCINT5_DDR DDRA
+#define PCINT5_PORT PORTA
+#define PCINT5_PIN PINA
+#define PCINT5_BIT 5
+
+#define ADC4_DDR DDRA
+#define ADC4_PORT PORTA
+#define ADC4_PIN PINA
+#define ADC4_BIT 4
+
+#define PCINT4_DDR DDRA
+#define PCINT4_PORT PORTA
+#define PCINT4_PIN PINA
+#define PCINT4_BIT 4
+
+#define ADC3_DDR DDRA
+#define ADC3_PORT PORTA
+#define ADC3_PIN PINA
+#define ADC3_BIT 3
+
+#define PCINT3_DDR DDRA
+#define PCINT3_PORT PORTA
+#define PCINT3_PIN PINA
+#define PCINT3_BIT 3
+
+#define ADC2_DDR DDRA
+#define ADC2_PORT PORTA
+#define ADC2_PIN PINA
+#define ADC2_BIT 2
+
+#define PCINT2_DDR DDRA
+#define PCINT2_PORT PORTA
+#define PCINT2_PIN PINA
+#define PCINT2_BIT 2
+
+#define ADC1_DDR DDRA
+#define ADC1_PORT PORTA
+#define ADC1_PIN PINA
+#define ADC1_BIT 1
+
+#define PCINT1_DDR DDRA
+#define PCINT1_PORT PORTA
+#define PCINT1_PIN PINA
+#define PCINT1_BIT 1
+
+#define ADC0_DDR DDRA
+#define ADC0_PORT PORTA
+#define ADC0_PIN PINA
+#define ADC0_BIT 0
+
+#define PCINT0_DDR DDRA
+#define PCINT0_PORT PORTA
+#define PCINT0_PIN PINA
+#define PCINT0_BIT 0
+
+#define XCK_DDR DDRB
+#define XCK_PORT PORTB
+#define XCK_PIN PINB
+#define XCK_BIT 0
+
+#define T0_DDR DDRB
+#define T0_PORT PORTB
+#define T0_PIN PINB
+#define T0_BIT 0
+
+#define PCINT8_DDR DDRB
+#define PCINT8_PORT PORTB
+#define PCINT8_PIN PINB
+#define PCINT8_BIT 0
+
+#define T1_DDR DDRB
+#define T1_PORT PORTB
+#define T1_PIN PINB
+#define T1_BIT 1
+
+#define CLKO_DDR DDRB
+#define CLKO_PORT PORTB
+#define CLKO_PIN PINB
+#define CLKO_BIT 1
+
+#define PCINT9_DDR DDRB
+#define PCINT9_PORT PORTB
+#define PCINT9_PIN PINB
+#define PCINT9_BIT 1
+
+#define AIN0_DDR DDRB
+#define AIN0_PORT PORTB
+#define AIN0_PIN PINB
+#define AIN0_BIT 2
+
+#define INT2_DDR DDRB
+#define INT2_PORT PORTB
+#define INT2_PIN PINB
+#define INT2_BIT 2
+
+#define PCINT10_DDR DDRB
+#define PCINT10_PORT PORTB
+#define PCINT10_PIN PINB
+#define PCINT10_BIT 2
+
+#define AIN1_DDR DDRB
+#define AIN1_PORT PORTB
+#define AIN1_PIN PINB
+#define AIN1_BIT 3
+
+#define OC0A_DDR DDRB
+#define OC0A_PORT PORTB
+#define OC0A_PIN PINB
+#define OC0A_BIT 3
+
+#define PCINT11_DDR DDRB
+#define PCINT11_PORT PORTB
+#define PCINT11_PIN PINB
+#define PCINT11_BIT 3
+
+#define SS_DDR DDRB
+#define SS_PORT PORTB
+#define SS_PIN PINB
+#define SS_BIT 4
+
+#define OC0B_DDR DDRB
+#define OC0B_PORT PORTB
+#define OC0B_PIN PINB
+#define OC0B_BIT 4
+
+#define PCINT12_DDR DDRB
+#define PCINT12_PORT PORTB
+#define PCINT12_PIN PINB
+#define PCINT12_BIT 4
+
+#endif /* _AVR_ATmega644PA_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom645.h b/cpukit/score/cpu/avr/avr/iom645.h
new file mode 100644
index 0000000000..32c9f3d326
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom645.h
@@ -0,0 +1,816 @@
+/* Copyright (c) 2004,2005,2006 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom645.h - definitions for ATmega645 */
+
+#ifndef _AVR_IOM645_H_
+#define _AVR_IOM645_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom645.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xFF] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* Vector 22 is Reserved */
+
+#define _VECTORS_SIZE 92
+
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND RAMEND
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOM645_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom6450.h b/cpukit/score/cpu/avr/avr/iom6450.h
new file mode 100644
index 0000000000..7a0de66401
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom6450.h
@@ -0,0 +1,907 @@
+/* Copyright (c) 2004,2005,2006 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom6450.h - definitions for ATmega6450 */
+
+#ifndef _AVR_IOM6450_H_
+#define _AVR_IOM6450_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom6450.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+#define PCIF2 6
+#define PCIF3 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+#define PCIE2 6
+#define PCIE3 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x72] */
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+
+/* Reserved [0x74..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xD7] */
+
+#define PINH _SFR_MEM8(0xD8)
+#define PINH7 7
+#define PINH6 6
+#define PINH5 5
+#define PINH4 4
+#define PINH3 3
+#define PINH2 2
+#define PINH1 1
+#define PINH0 0
+
+#define DDRH _SFR_MEM8(0xD9)
+#define DDH7 7
+#define DDH6 6
+#define DDH5 5
+#define DDH4 4
+#define DDH3 3
+#define DDH2 2
+#define DDH1 1
+#define DDH0 0
+
+#define PORTH _SFR_MEM8(0xDA)
+#define PH7 7
+#define PH6 6
+#define PH5 5
+#define PH4 4
+#define PH3 3
+#define PH2 2
+#define PH1 1
+#define PH0 0
+
+#define PINJ _SFR_MEM8(0xDB)
+#define PINJ6 6
+#define PINJ5 5
+#define PINJ4 4
+#define PINJ3 3
+#define PINJ2 2
+#define PINJ1 1
+#define PINJ0 0
+
+#define DDRJ _SFR_MEM8(0xDC)
+#define DDJ6 6
+#define DDJ5 5
+#define DDJ4 4
+#define DDJ3 3
+#define DDJ2 2
+#define DDJ1 1
+#define DDJ0 0
+
+#define PORTJ _SFR_MEM8(0xDD)
+#define PJ6 6
+#define PJ5 5
+#define PJ4 4
+#define PJ3 3
+#define PJ2 2
+#define PJ1 1
+#define PJ0 0
+
+/* Reserved [0xDE..0xFF] */
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(13)
+#define USART0_RX_vect _VECTOR(13) /* Alias */
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART Data register Empty */
+#define USART_UDRE_vect _VECTOR(14)
+#define USART0_UDRE_vect _VECTOR(14) /* Alias */
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define USART_TX_vect _VECTOR(15) /* Alias */
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(23)
+#define SIG_PIN_CHANGE2 _VECTOR(23)
+
+/* Pin Change Interrupt Request 3 */
+#define PCINT3_vect _VECTOR(24)
+#define SIG_PIN_CHANGE3 _VECTOR(24)
+
+#define _VECTORS_SIZE 100
+
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND RAMEND
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOM6450_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom649.h b/cpukit/score/cpu/avr/avr/iom649.h
new file mode 100644
index 0000000000..c9d5058a24
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom649.h
@@ -0,0 +1,992 @@
+/* Copyright (c) 2004 Eric B. Weddington
+ Copyright (c) 2005,2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom649.h - definitions for ATmega649 */
+
+#ifndef _AVR_IOM649_H_
+#define _AVR_IOM649_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom649.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xE3] */
+
+#define LCDCRA _SFR_MEM8(0XE4)
+#define LCDBL 0
+#define LCDIE 3
+#define LCDIF 4
+#define LCDAB 6
+#define LCDEN 7
+
+#define LCDCRB _SFR_MEM8(0XE5)
+#define LCDPM0 0
+#define LCDPM1 1
+#define LCDPM2 2
+#define LCDMUX0 4
+#define LCDMUX1 5
+#define LCD2B 6
+#define LCDCS 7
+
+#define LCDFRR _SFR_MEM8(0XE6)
+#define LCDCD0 0
+#define LCDCD1 1
+#define LCDCD2 2
+#define LCDPS0 4
+#define LCDPS1 5
+#define LCDPS2 6
+
+#define LCDCCR _SFR_MEM8(0XE7)
+#define LCDCC0 0
+#define LCDCC1 1
+#define LCDCC2 2
+#define LCDCC3 3
+#define LCDDC0 5
+#define LCDDC1 6
+#define LCDDC2 7
+
+/* Reserved [0xE8..0xEB] */
+
+#define LCDDR00 _SFR_MEM8(0XEC)
+#define SEG000 0
+#define SEG001 1
+#define SEG002 2
+#define SEG003 3
+#define SEG004 4
+#define SEG005 5
+#define SEG006 6
+#define SEG007 7
+
+#define LCDDR01 _SFR_MEM8(0XED)
+#define SEG008 0
+#define SEG009 1
+#define SEG010 2
+#define SEG011 3
+#define SEG012 4
+#define SEG013 5
+#define SEG014 6
+#define SEG015 7
+
+#define LCDDR02 _SFR_MEM8(0XEE)
+#define SEG016 0
+#define SEG017 1
+#define SEG018 2
+#define SEG019 3
+#define SEG020 4
+#define SEG021 5
+#define SEG022 6
+#define SEG023 7
+
+#define LCDDR03 _SFR_MEM8(0XEF)
+#define SEG024 0
+
+/* Reserved [0xF0] */
+
+#define LCDDR05 _SFR_MEM8(0XF1)
+#define SEG100 0
+#define SEG101 1
+#define SEG102 2
+#define SEG103 3
+#define SEG104 4
+#define SEG105 5
+#define SEG106 6
+#define SEG107 7
+
+#define LCDDR06 _SFR_MEM8(0XF2)
+#define SEG108 0
+#define SEG109 1
+#define SEG110 2
+#define SEG111 3
+#define SEG112 4
+#define SEG113 5
+#define SEG114 6
+#define SEG115 7
+
+#define LCDDR07 _SFR_MEM8(0XF3)
+#define SEG116 0
+#define SEG117 1
+#define SEG118 2
+#define SEG119 3
+#define SEG120 4
+#define SEG121 5
+#define SEG122 6
+#define SEG123 7
+
+#define LCDDR08 _SFR_MEM8(0XF4)
+#define SEG124 0
+
+/* Reserved [0xF5] */
+
+#define LCDDR10 _SFR_MEM8(0XF6)
+#define SEG200 0
+#define SEG201 1
+#define SEG202 2
+#define SEG203 3
+#define SEG204 4
+#define SEG205 5
+#define SEG206 6
+#define SEG207 7
+
+#define LCDDR11 _SFR_MEM8(0XF7)
+#define SEG208 0
+#define SEG209 1
+#define SEG210 2
+#define SEG211 3
+#define SEG212 4
+#define SEG213 5
+#define SEG214 6
+#define SEG215 7
+
+#define LCDDR12 _SFR_MEM8(0XF8)
+#define SEG216 0
+#define SEG217 1
+#define SEG218 2
+#define SEG219 3
+#define SEG220 4
+#define SEG221 5
+#define SEG222 6
+#define SEG223 7
+
+#define LCDDR13 _SFR_MEM8(0XF9)
+#define SEG224 0
+
+/* Reserved [0xFA] */
+
+#define LCDDR15 _SFR_MEM8(0XFB)
+#define SEG300 0
+#define SEG301 1
+#define SEG302 2
+#define SEG303 3
+#define SEG304 4
+#define SEG305 5
+#define SEG306 6
+#define SEG307 7
+
+#define LCDDR16 _SFR_MEM8(0XFC)
+#define SEG308 0
+#define SEG309 1
+#define SEG310 2
+#define SEG311 3
+#define SEG312 4
+#define SEG313 5
+#define SEG314 6
+#define SEG315 7
+
+#define LCDDR17 _SFR_MEM8(0XFD)
+#define SEG316 0
+#define SEG217 1
+#define SEG318 2
+#define SEG319 3
+#define SEG320 4
+#define SEG321 5
+#define SEG322 6
+#define SEG323 7
+
+#define LCDDR18 _SFR_MEM8(0XFE)
+#define SEG324 0
+
+/* Reserved [0xFF] */
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* LCD Start of Frame */
+#define LCD_vect _VECTOR(22)
+#define SIG_LCD _VECTOR(22)
+
+#define _VECTORS_SIZE 92
+
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND RAMEND
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x03
+
+
+#endif /* _AVR_IOM649_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom6490.h b/cpukit/score/cpu/avr/avr/iom6490.h
new file mode 100644
index 0000000000..f678acf30f
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom6490.h
@@ -0,0 +1,1144 @@
+/* Copyright (c) 2004 Eric B. Weddington
+ Copyright (c) 2005,2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iom6490.h - definitions for ATmega6490 */
+
+#ifndef _AVR_IOM6490_H_
+#define _AVR_IOM6490_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom6490.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0x03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+#define PCIF2 6
+#define PCIF3 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+#define PCIE2 6
+#define PCIE3 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+/* Reserved [0x25] */
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+/* Reserved [0x28..0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0X35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+/* Reserved [0x71..0x72] */
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+#define PCINT28 4
+#define PCINT29 5
+#define PCINT30 6
+
+/* Reserved [0x74..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0X80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0X81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+/* Reserved [0xB1] */
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+/* Reserved [0xB4..0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+/* Reserved [0xB7] */
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+
+/* Reserved [0xBB..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7..0xD7] */
+
+#define PINH _SFR_MEM8(0xD8)
+#define PINH7 7
+#define PINH6 6
+#define PINH5 5
+#define PINH4 4
+#define PINH3 3
+#define PINH2 2
+#define PINH1 1
+#define PINH0 0
+
+#define DDRH _SFR_MEM8(0xD9)
+#define DDH7 7
+#define DDH6 6
+#define DDH5 5
+#define DDH4 4
+#define DDH3 3
+#define DDH2 2
+#define DDH1 1
+#define DDH0 0
+
+#define PORTH _SFR_MEM8(0xDA)
+#define PH7 7
+#define PH6 6
+#define PH5 5
+#define PH4 4
+#define PH3 3
+#define PH2 2
+#define PH1 1
+#define PH0 0
+
+#define PINJ _SFR_MEM8(0xDB)
+#define PINJ6 6
+#define PINJ5 5
+#define PINJ4 4
+#define PINJ3 3
+#define PINJ2 2
+#define PINJ1 1
+#define PINJ0 0
+
+#define DDRJ _SFR_MEM8(0xDC)
+#define DDJ6 6
+#define DDJ5 5
+#define DDJ4 4
+#define DDJ3 3
+#define DDJ2 2
+#define DDJ1 1
+#define DDJ0 0
+
+#define PORTJ _SFR_MEM8(0xDD)
+#define PJ6 6
+#define PJ5 5
+#define PJ4 4
+#define PJ3 3
+#define PJ2 2
+#define PJ1 1
+#define PJ0 0
+
+/* Reserved [0xDE..0xE3] */
+
+#define LCDCRA _SFR_MEM8(0XE4)
+#define LCDBL 0
+#define LCDIE 3
+#define LCDIF 4
+#define LCDAB 6
+#define LCDEN 7
+
+#define LCDCRB _SFR_MEM8(0XE5)
+#define LCDPM0 0
+#define LCDPM1 1
+#define LCDPM2 2
+#define LCDPM3 3
+#define LCDMUX0 4
+#define LCDMUX1 5
+#define LCD2B 6
+#define LCDCS 7
+
+#define LCDFRR _SFR_MEM8(0XE6)
+#define LCDCD0 0
+#define LCDCD1 1
+#define LCDCD2 2
+#define LCDPS0 4
+#define LCDPS1 5
+#define LCDPS2 6
+
+#define LCDCCR _SFR_MEM8(0XE7)
+#define LCDCC0 0
+#define LCDCC1 1
+#define LCDCC2 2
+#define LCDCC3 3
+#define LCDDC0 5
+#define LCDDC1 6
+#define LCDDC2 7
+
+/* Reserved [0xE8..0xEB] */
+
+#define LCDDR00 _SFR_MEM8(0XEC)
+#define SEG000 0
+#define SEG001 1
+#define SEG002 2
+#define SEG003 3
+#define SEG004 4
+#define SEG005 5
+#define SEG006 6
+#define SEG007 7
+
+#define LCDDR01 _SFR_MEM8(0XED)
+#define SEG008 0
+#define SEG009 1
+#define SEG010 2
+#define SEG011 3
+#define SEG012 4
+#define SEG013 5
+#define SEG014 6
+#define SEG015 7
+
+#define LCDDR02 _SFR_MEM8(0XEE)
+#define SEG016 0
+#define SEG017 1
+#define SEG018 2
+#define SEG019 3
+#define SEG020 4
+#define SEG021 5
+#define SEG022 6
+#define SEG023 7
+
+#define LCDDR03 _SFR_MEM8(0XEF)
+#define SEG024 0
+#define SEG025 1
+#define SEG026 2
+#define SEG027 3
+#define SEG028 4
+#define SEG029 5
+#define SEG030 6
+#define SEG031 7
+
+#define LCDDR04 _SFR_MEM8(0XF0)
+#define SEG032 0
+#define SEG033 1
+#define SEG034 2
+#define SEG035 3
+#define SEG036 4
+#define SEG037 5
+#define SEG038 6
+#define SEG039 7
+
+#define LCDDR05 _SFR_MEM8(0XF1)
+#define SEG100 0
+#define SEG101 1
+#define SEG102 2
+#define SEG103 3
+#define SEG104 4
+#define SEG105 5
+#define SEG106 6
+#define SEG107 7
+
+#define LCDDR06 _SFR_MEM8(0XF2)
+#define SEG108 0
+#define SEG109 1
+#define SEG110 2
+#define SEG111 3
+#define SEG112 4
+#define SEG113 5
+#define SEG114 6
+#define SEG115 7
+
+#define LCDDR07 _SFR_MEM8(0XF3)
+#define SEG116 0
+#define SEG117 1
+#define SEG118 2
+#define SEG119 3
+#define SEG120 4
+#define SEG121 5
+#define SEG122 6
+#define SEG123 7
+
+#define LCDDR08 _SFR_MEM8(0XF4)
+#define SEG124 0
+#define SEG125 1
+#define SEG126 2
+#define SEG127 3
+#define SEG128 4
+#define SEG129 5
+#define SEG130 6
+#define SEG131 7
+
+#define LCDDR09 _SFR_MEM8(0XF5)
+#define SEG132 0
+#define SEG133 1
+#define SEG134 2
+#define SEG135 3
+#define SEG136 4
+#define SEG137 5
+#define SEG138 6
+#define SEG139 7
+
+#define LCDDR10 _SFR_MEM8(0XF6)
+#define SEG200 0
+#define SEG201 1
+#define SEG202 2
+#define SEG203 3
+#define SEG204 4
+#define SEG205 5
+#define SEG206 6
+#define SEG207 7
+
+#define LCDDR11 _SFR_MEM8(0XF7)
+#define SEG208 0
+#define SEG209 1
+#define SEG210 2
+#define SEG211 3
+#define SEG212 4
+#define SEG213 5
+#define SEG214 6
+#define SEG215 7
+
+#define LCDDR12 _SFR_MEM8(0XF8)
+#define SEG216 0
+#define SEG217 1
+#define SEG218 2
+#define SEG219 3
+#define SEG220 4
+#define SEG221 5
+#define SEG222 6
+#define SEG223 7
+
+#define LCDDR13 _SFR_MEM8(0XF9)
+#define SEG224 0
+#define SEG225 1
+#define SEG226 2
+#define SEG227 3
+#define SEG228 4
+#define SEG229 5
+#define SEG230 6
+#define SEG231 7
+
+#define LCDDR14 _SFR_MEM8(0XFA)
+#define SEG232 0
+#define SEG233 1
+#define SEG234 2
+#define SEG235 3
+#define SEG236 4
+#define SEG237 5
+#define SEG238 6
+#define SEG239 7
+
+#define LCDDR15 _SFR_MEM8(0XFB)
+#define SEG300 0
+#define SEG301 1
+#define SEG302 2
+#define SEG303 3
+#define SEG304 4
+#define SEG305 5
+#define SEG306 6
+#define SEG307 7
+
+#define LCDDR16 _SFR_MEM8(0XFC)
+#define SEG308 0
+#define SEG309 1
+#define SEG310 2
+#define SEG311 3
+#define SEG312 4
+#define SEG313 5
+#define SEG314 6
+#define SEG315 7
+
+#define LCDDR17 _SFR_MEM8(0XFD)
+#define SEG316 0
+#define SEG217 1
+#define SEG318 2
+#define SEG319 3
+#define SEG320 4
+#define SEG321 5
+#define SEG322 6
+#define SEG323 7
+
+#define LCDDR18 _SFR_MEM8(0XFE)
+#define SEG324 0
+#define SEG325 1
+#define SEG326 2
+#define SEG327 3
+#define SEG328 4
+#define SEG329 5
+#define SEG330 6
+#define SEG331 7
+
+#define LCDDR19 _SFR_MEM8(0XFF)
+#define SEG332 0
+#define SEG333 1
+#define SEG334 2
+#define SEG335 3
+#define SEG336 4
+#define SEG337 5
+#define SEG338 6
+#define SEG339 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(4)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW2 _VECTOR(5)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(6)
+#define SIG_INPUT_CAPTURE1 _VECTOR(6)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(7)
+
+/* Timer/Counter Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(8)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW1 _VECTOR(9)
+
+/* Timer/Counter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(12)
+#define SIG_SPI _VECTOR(12)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(13)
+#define SIG_UART_RECV _VECTOR(13)
+
+/* USART Data register Empty */
+#define USART_UDRE_vect _VECTOR(14)
+#define SIG_UART_DATA _VECTOR(14)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(15)
+#define SIG_UART_TRANS _VECTOR(15)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(16)
+#define SIG_USI_START _VECTOR(16)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(17)
+#define SIG_USI_OVERFLOW _VECTOR(17)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(18)
+#define SIG_COMPARATOR _VECTOR(18)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(19)
+#define SIG_ADC _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+#define SIG_EEPROM_READY _VECTOR(20)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(21)
+#define SIG_SPM_READY _VECTOR(21)
+
+/* LCD Start of Frame */
+#define LCD_vect _VECTOR(22)
+#define SIG_LCD _VECTOR(22)
+
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(23)
+#define SIG_PIN_CHANGE2 _VECTOR(23)
+
+/* Pin Change Interrupt Request 3 */
+#define PCINT3_vect _VECTOR(24)
+#define SIG_PIN_CHANGE3 _VECTOR(24)
+
+#define _VECTORS_SIZE 100
+
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND RAMEND
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x04
+
+
+#endif /* _AVR_IOM6490_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom649p.h b/cpukit/score/cpu/avr/avr/iom649p.h
new file mode 100644
index 0000000000..9cddb7477f
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom649p.h
@@ -0,0 +1,1477 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom649p.h - definitions for ATmega649 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom649p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega649_H_
+#define _AVR_ATmega649_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+#define PINE3 3
+#define PINE4 4
+#define PINE5 5
+#define PINE6 6
+#define PINE7 7
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+#define DDE3 3
+#define DDE4 4
+#define DDE5 5
+#define DDE6 6
+#define DDE7 7
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+#define PORTE3 3
+#define PORTE4 4
+#define PORTE5 5
+#define PORTE6 6
+#define PORTE7 7
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF0 0
+#define PINF1 1
+#define PINF2 2
+#define PINF3 3
+#define PINF4 4
+#define PINF5 5
+#define PINF6 6
+#define PINF7 7
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF0 0
+#define DDF1 1
+#define DDF2 2
+#define DDF3 3
+#define DDF4 4
+#define DDF5 5
+#define DDF6 6
+#define DDF7 7
+
+#define PORTF _SFR_IO8(0x11)
+#define PORTF0 0
+#define PORTF1 1
+#define PORTF2 2
+#define PORTF3 3
+#define PORTF4 4
+#define PORTF5 5
+#define PORTF6 6
+#define PORTF7 7
+
+#define PING _SFR_IO8(0x12)
+#define PING0 0
+#define PING1 1
+#define PING2 2
+#define PING3 3
+#define PING4 4
+#define PING5 5
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG0 0
+#define DDG1 1
+#define DDG2 2
+#define DDG3 3
+#define DDG4 4
+
+#define PORTG _SFR_IO8(0x14)
+#define PORTG0 0
+#define PORTG1 1
+#define PORTG2 2
+#define PORTG3 3
+#define PORTG4 4
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define PCIF0 4
+#define PCIF1 5
+#define PCIF2 6
+#define PCIF3 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define PCIE0 4
+#define PCIE1 5
+#define PCIE2 6
+#define PCIE3 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEARL0 0
+#define EEARL1 1
+#define EEARL2 2
+#define EEARL3 3
+#define EEARL4 4
+#define EEARL5 5
+#define EEARL6 6
+#define EEARL7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR310 0
+#define PSR2 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM01 3
+#define COM0A0 4
+#define COM0A1 5
+#define WGM00 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define OCDR _SFR_IO8(0x31)
+#define OCDR0 0
+#define OCDR1 1
+#define OCDR2 2
+#define OCDR3 3
+#define OCDR4 4
+#define OCDR5 5
+#define OCDR6 6
+#define OCDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define JTRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define JTD 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRLCD 4
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM21 3
+#define COM2A0 4
+#define COM2A1 5
+#define WGM20 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A0 0
+#define OCR2A1 1
+#define OCR2A2 2
+#define OCR2A3 3
+#define OCR2A4 4
+#define OCR2A5 5
+#define OCR2A6 6
+#define OCR2A7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2UB 0
+#define OCR2UB 1
+#define TCN2UB 2
+#define AS2 3
+#define EXCLK 4
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL0 6
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0_0 0
+#define UBRR0_1 1
+#define UBRR0_2 2
+#define UBRR0_3 3
+#define UBRR0_4 4
+#define UBRR0_5 5
+#define UBRR0_6 6
+#define UBRR0_7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR0_8 0
+#define UBRR0_9 1
+#define UBRR0_10 2
+#define UBRR0_11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR00 0
+#define UDR01 1
+#define UDR02 2
+#define UDR03 3
+#define UDR04 4
+#define UDR05 5
+#define UDR06 6
+#define UDR07 7
+
+#define LCDCRA _SFR_MEM8(0xE4)
+#define LCDBL 0
+#define LCDIE 3
+#define LCDIF 4
+#define LCDAB 6
+#define LCDEN 7
+
+#define LCDCRB _SFR_MEM8(0xE5)
+#define LCDPM0 0
+#define LCDPM1 1
+#define LCDPM2 2
+#define LCDPM3 3
+#define LCDMUX0 4
+#define LCDMUX1 5
+#define LCD2B 6
+#define LCDCS 7
+
+#define LCDFRR _SFR_MEM8(0xE6)
+#define LCDCD0 0
+#define LCDCD1 1
+#define LCDCD2 2
+#define LCDPS0 4
+#define LCDPS1 5
+#define LCDPS2 6
+
+#define LCDCCR _SFR_MEM8(0xE7)
+#define LCDCC0 0
+#define LCDCC1 1
+#define LCDCC2 2
+#define LCDCC3 3
+#define LCDDC0 5
+#define LCDDC1 6
+#define LCDDC2 7
+
+#define LCDDR0 _SFR_MEM8(0xEC)
+#define SEG000 0
+#define SEG001 1
+#define SEG002 2
+#define SEG003 3
+#define SEG004 4
+#define SEG005 5
+#define SEG006 6
+#define SEG007 7
+
+#define LCDDR1 _SFR_MEM8(0xED)
+#define SEG008 0
+#define SEG009 1
+#define SEG010 2
+#define SEG011 3
+#define SEG012 4
+#define SEG013 5
+#define SEG014 6
+#define SEG015 7
+
+#define LCDDR2 _SFR_MEM8(0xEE)
+#define SEG016 0
+#define SEG017 1
+#define SEG018 2
+#define SEG019 3
+#define SEG020 4
+#define SEG021 5
+#define SEG022 6
+#define SEG023 7
+
+#define LCDDR3 _SFR_MEM8(0xEF)
+#define SEG024 0
+
+#define LCDDR4 _SFR_MEM8(0xF0)
+
+#define LCDDR5 _SFR_MEM8(0xF1)
+#define SEG100 0
+#define SEG101 1
+#define SEG102 2
+#define SEG103 3
+#define SEG104 4
+#define SEG105 5
+#define SEG106 6
+#define SEG107 7
+
+#define LCDDR6 _SFR_MEM8(0xF2)
+#define SEG108 0
+#define SEG109 1
+#define SEG110 2
+#define SEG111 3
+#define SEG112 4
+#define SEG113 5
+#define SEG114 6
+#define SEG115 7
+
+#define LCDDR7 _SFR_MEM8(0xF3)
+#define SEG116 0
+#define SEG117 1
+#define SEG118 2
+#define SEG119 3
+#define SEG120 4
+#define SEG121 5
+#define SEG122 6
+#define SEG123 7
+
+#define LCDDR8 _SFR_MEM8(0xF4)
+#define SEG124 0
+
+#define LCDDR9 _SFR_MEM8(0xF5)
+
+#define LCDDR10 _SFR_MEM8(0xF6)
+#define SEG200 0
+#define SEG201 1
+#define SEG202 2
+#define SEG203 3
+#define SEG204 4
+#define SEG205 5
+#define SEG206 6
+#define SEG207 7
+
+#define LCDDR11 _SFR_MEM8(0xF7)
+#define SEG208 0
+#define SEG209 1
+#define SEG210 2
+#define SEG211 3
+#define SEG212 4
+#define SEG213 5
+#define SEG214 6
+#define SEG215 7
+
+#define LCDDR12 _SFR_MEM8(0xF8)
+#define SEG216 0
+#define SEG217 1
+#define SEG218 2
+#define SEG219 3
+#define SEG220 4
+#define SEG221 5
+#define SEG222 6
+#define SEG223 7
+
+#define LCDDR13 _SFR_MEM8(0xF9)
+#define SEG224 0
+
+#define LCDDR14 _SFR_MEM8(0xFA)
+
+#define LCDDR15 _SFR_MEM8(0xFB)
+#define SEG300 0
+#define SEG301 1
+#define SEG302 2
+#define SEG303 3
+#define SEG304 4
+#define SEG305 5
+#define SEG306 6
+#define SEG307 7
+
+#define LCDDR16 _SFR_MEM8(0xFC)
+#define SEG308 0
+#define SEG309 1
+#define SEG310 2
+#define SEG311 3
+#define SEG312 4
+#define SEG313 5
+#define SEG314 6
+#define SEG315 7
+
+#define LCDDR17 _SFR_MEM8(0xFD)
+#define SEG316 0
+#define SEG317 1
+#define SEG318 2
+#define SEG319 3
+#define SEG320 4
+#define SEG321 5
+#define SEG322 6
+#define SEG323 7
+
+#define LCDDR18 _SFR_MEM8(0xFE)
+#define SEG324 0
+
+#define LCDDR19 _SFR_MEM8(0xFF)
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define PCINT0_vect_num 2
+#define PCINT0_vect _VECTOR(2) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 3
+#define PCINT1_vect _VECTOR(3) /* Pin Change Interrupt Request 1 */
+#define TIMER2_COMP_vect_num 4
+#define TIMER2_COMP_vect _VECTOR(4) /* Timer/Counter2 Compare Match */
+#define TIMER2_OVF_vect_num 5
+#define TIMER2_OVF_vect _VECTOR(5) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 6
+#define TIMER1_CAPT_vect _VECTOR(6) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 7
+#define TIMER1_COMPA_vect _VECTOR(7) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 8
+#define TIMER1_COMPB_vect _VECTOR(8) /* Timer/Counter Compare Match B */
+#define TIMER1_OVF_vect_num 9
+#define TIMER1_OVF_vect _VECTOR(9) /* Timer/Counter1 Overflow */
+#define TIMER0_COMP_vect_num 10
+#define TIMER0_COMP_vect _VECTOR(10) /* Timer/Counter0 Compare Match */
+#define TIMER0_OVF_vect_num 11
+#define TIMER0_OVF_vect _VECTOR(11) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 12
+#define SPI_STC_vect _VECTOR(12) /* SPI Serial Transfer Complete */
+#define USART0_RX_vect_num 13
+#define USART0_RX_vect _VECTOR(13) /* USART0, Rx Complete */
+#define USART0_UDRE_vect_num 14
+#define USART0_UDRE_vect _VECTOR(14) /* USART0 Data register Empty */
+#define USART0_TX_vect_num 15
+#define USART0_TX_vect _VECTOR(15) /* USART0, Tx Complete */
+#define USI_START_vect_num 16
+#define USI_START_vect _VECTOR(16) /* USI Start Condition */
+#define USI_OVERFLOW_vect_num 17
+#define USI_OVERFLOW_vect _VECTOR(17) /* USI Overflow */
+#define ANALOG_COMP_vect_num 18
+#define ANALOG_COMP_vect _VECTOR(18) /* Analog Comparator */
+#define ADC_vect_num 19
+#define ADC_vect _VECTOR(19) /* ADC Conversion Complete */
+#define EE_READY_vect_num 20
+#define EE_READY_vect _VECTOR(20) /* EEPROM Ready */
+#define SPM_READY_vect_num 21
+#define SPM_READY_vect _VECTOR(21) /* Store Program Memory Read */
+#define LCD_vect_num 22
+#define LCD_vect _VECTOR(22) /* LCD Start of Frame */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (23 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (256)
+#define RAMSTART (0x100)
+#define RAMSIZE (4096)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7FF)
+#define E2PAGESIZE (8)
+#define FLASHEND (0xFFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_JTAGEN (unsigned char)~_BV(6) /* Enable JTAG */
+#define FUSE_OCDEN (unsigned char)~_BV(7) /* Enable OCD */
+#define HFUSE_DEFAULT (FUSE_JTAGEN & FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_RESERVED (unsigned char)~_BV(0) /* Reserved fuse bit, do not program */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x0B
+
+
+/* Device Pin Definitions */
+#define RXD_DDR DDRE
+#define RXD_PORT PORTE
+#define RXD_PIN PINE
+#define RXD_BIT 0
+
+#define PCINT0_DDR DDRE
+#define PCINT0_PORT PORTE
+#define PCINT0_PIN PINE
+#define PCINT0_BIT 0
+
+#define TXD_DDR DDRE
+#define TXD_PORT PORTE
+#define TXD_PIN PINE
+#define TXD_BIT 1
+
+#define PCINT1_DDR DDRE
+#define PCINT1_PORT PORTE
+#define PCINT1_PIN PINE
+#define PCINT1_BIT 1
+
+#define XCK_DDR DDRE
+#define XCK_PORT PORTE
+#define XCK_PIN PINE
+#define XCK_BIT 2
+
+#define AIN0_DDR DDRE
+#define AIN0_PORT PORTE
+#define AIN0_PIN PINE
+#define AIN0_BIT 2
+
+#define PCINT2_DDR DDRE
+#define PCINT2_PORT PORTE
+#define PCINT2_PIN PINE
+#define PCINT2_BIT 2
+
+#define AIN1_DDR DDRE
+#define AIN1_PORT PORTE
+#define AIN1_PIN PINE
+#define AIN1_BIT 3
+
+#define PCINT3_DDR DDRE
+#define PCINT3_PORT PORTE
+#define PCINT3_PIN PINE
+#define PCINT3_BIT 3
+
+#define USCK_DDR DDRE
+#define USCK_PORT PORTE
+#define USCK_PIN PINE
+#define USCK_BIT 4
+
+#define SCL_DDR DDRE
+#define SCL_PORT PORTE
+#define SCL_PIN PINE
+#define SCL_BIT 4
+
+#define PCINT4_DDR DDRE
+#define PCINT4_PORT PORTE
+#define PCINT4_PIN PINE
+#define PCINT4_BIT 4
+
+#define DI_DDR DDRE
+#define DI_PORT PORTE
+#define DI_PIN PINE
+#define DI_BIT 5
+
+#define SDA_DDR DDRE
+#define SDA_PORT PORTE
+#define SDA_PIN PINE
+#define SDA_BIT 5
+
+#define PCINT5_DDR DDRE
+#define PCINT5_PORT PORTE
+#define PCINT5_PIN PINE
+#define PCINT5_BIT 5
+
+#define DO_DDR DDRE
+#define DO_PORT PORTE
+#define DO_PIN PINE
+#define DO_BIT 6
+
+#define PCINT6_DDR DDRE
+#define PCINT6_PORT PORTE
+#define PCINT6_PIN PINE
+#define PCINT6_BIT 6
+
+#define PCINT7_DDR DDRE
+#define PCINT7_PORT PORTE
+#define PCINT7_PIN PINE
+#define PCINT7_BIT 7
+
+#define SS_DDR DDRB
+#define SS_PORT PORTB
+#define SS_PIN PINB
+#define SS_BIT 0
+
+#define PCINT8_DDR DDRB
+#define PCINT8_PORT PORTB
+#define PCINT8_PIN PINB
+#define PCINT8_BIT 0
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 1
+
+#define PCINT9_DDR DDRB
+#define PCINT9_PORT PORTB
+#define PCINT9_PIN PINB
+#define PCINT9_BIT 1
+
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 2
+
+#define PCINT10_DDR DDRB
+#define PCINT10_PORT PORTB
+#define PCINT10_PIN PINB
+#define PCINT10_BIT 2
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 3
+
+#define PCINT11_DDR DDRB
+#define PCINT11_PORT PORTB
+#define PCINT11_PIN PINB
+#define PCINT11_BIT 3
+
+#define OC0_DDR DDRB
+#define OC0_PORT PORTB
+#define OC0_PIN PINB
+#define OC0_BIT 4
+
+#define PCINT12_DDR DDRB
+#define PCINT12_PORT PORTB
+#define PCINT12_PIN PINB
+#define PCINT12_BIT 4
+
+#define OC1A_DDR DDRB
+#define OC1A_PORT PORTB
+#define OC1A_PIN PINB
+#define OC1A_BIT 5
+
+#define PCINT13_DDR DDRB
+#define PCINT13_PORT PORTB
+#define PCINT13_PIN PINB
+#define PCINT13_BIT 5
+
+#define OC1B_DDR DDRB
+#define OC1B_PORT PORTB
+#define OC1B_PIN PINB
+#define OC1B_BIT 6
+
+#define PCINT14_DDR DDRB
+#define PCINT14_PORT PORTB
+#define PCINT14_PIN PINB
+#define PCINT14_BIT 6
+
+#define OC2_DDR DDRB
+#define OC2_PORT PORTB
+#define OC2_PIN PINB
+#define OC2_BIT 7
+
+#define PCINT15_DDR DDRB
+#define PCINT15_PORT PORTB
+#define PCINT15_PIN PINB
+#define PCINT15_BIT 7
+
+#define T1_DDR DDRG
+#define T1_PORT PORTG
+#define T1_PIN PING
+#define T1_BIT 3
+
+#define SEG24_DDR DDRG
+#define SEG24_PORT PORTG
+#define SEG24_PIN PING
+#define SEG24_BIT 3
+
+#define T0_DDR DDRG
+#define T0_PORT PORTG
+#define T0_PIN PING
+#define T0_BIT 4
+
+#define SEG23_DDR DDRG
+#define SEG23_PORT PORTG
+#define SEG23_PIN PING
+#define SEG23_BIT 4
+
+#define ICP/SEG22_DDR DDRD
+#define ICP/SEG22_PORT PORTD
+#define ICP/SEG22_PIN PIND
+#define ICP/SEG22_BIT 0
+
+#define INT0/SEG21_DDR DDRD
+#define INT0/SEG21_PORT PORTD
+#define INT0/SEG21_PIN PIND
+#define INT0/SEG21_BIT 1
+
+#define SEG20_DDR DDRD
+#define SEG20_PORT PORTD
+#define SEG20_PIN PIND
+#define SEG20_BIT 2
+
+#define SEG19_DDR DDRD
+#define SEG19_PORT PORTD
+#define SEG19_PIN PIND
+#define SEG19_BIT 3
+
+#define SEG18_DDR DDRD
+#define SEG18_PORT PORTD
+#define SEG18_PIN PIND
+#define SEG18_BIT 4
+
+#define SEG17_DDR DDRD
+#define SEG17_PORT PORTD
+#define SEG17_PIN PIND
+#define SEG17_BIT 5
+
+#define SEG16_DDR DDRD
+#define SEG16_PORT PORTD
+#define SEG16_PIN PIND
+#define SEG16_BIT 6
+
+#define SEG15_DDR DDRD
+#define SEG15_PORT PORTD
+#define SEG15_PIN PIND
+#define SEG15_BIT 7
+
+#define SEG14_DDR DDRG
+#define SEG14_PORT PORTG
+#define SEG14_PIN PING
+#define SEG14_BIT 0
+
+#define SEG13_DDR DDRG
+#define SEG13_PORT PORTG
+#define SEG13_PIN PING
+#define SEG13_BIT 1
+
+#define SEG12_DDR DDRC
+#define SEG12_PORT PORTC
+#define SEG12_PIN PINC
+#define SEG12_BIT 0
+
+#define SEG11_DDR DDRC
+#define SEG11_PORT PORTC
+#define SEG11_PIN PINC
+#define SEG11_BIT 1
+
+#define SEG10_DDR DDRC
+#define SEG10_PORT PORTC
+#define SEG10_PIN PINC
+#define SEG10_BIT 2
+
+#define SEG9_DDR DDRC
+#define SEG9_PORT PORTC
+#define SEG9_PIN PINC
+#define SEG9_BIT 3
+
+#define SEG8_DDR DDRC
+#define SEG8_PORT PORTC
+#define SEG8_PIN PINC
+#define SEG8_BIT 4
+
+#define SEG7_DDR DDRC
+#define SEG7_PORT PORTC
+#define SEG7_PIN PINC
+#define SEG7_BIT 5
+
+#define SEG6_DDR DDRC
+#define SEG6_PORT PORTC
+#define SEG6_PIN PINC
+#define SEG6_BIT 6
+
+#define SEG5_DDR DDRC
+#define SEG5_PORT PORTC
+#define SEG5_PIN PINC
+#define SEG5_BIT 7
+
+#define SEG4_DDR DDRG
+#define SEG4_PORT PORTG
+#define SEG4_PIN PING
+#define SEG4_BIT 2
+
+#define SEG3_DDR DDRA
+#define SEG3_PORT PORTA
+#define SEG3_PIN PINA
+#define SEG3_BIT 7
+
+#define SEG2_DDR DDRA
+#define SEG2_PORT PORTA
+#define SEG2_PIN PINA
+#define SEG2_BIT 6
+
+#define SEG1_DDR DDRA
+#define SEG1_PORT PORTA
+#define SEG1_PIN PINA
+#define SEG1_BIT 5
+
+#define SEG0_DDR DDRA
+#define SEG0_PORT PORTA
+#define SEG0_PIN PINA
+#define SEG0_BIT 4
+
+#define COM3_DDR DDRA
+#define COM3_PORT PORTA
+#define COM3_PIN PINA
+#define COM3_BIT 3
+
+#define COM2_DDR DDRA
+#define COM2_PORT PORTA
+#define COM2_PIN PINA
+#define COM2_BIT 2
+
+#define COM1_DDR DDRA
+#define COM1_PORT PORTA
+#define COM1_PIN PINA
+#define COM1_BIT 1
+
+#define COM0_DDR DDRA
+#define COM0_PORT PORTA
+#define COM0_PIN PINA
+#define COM0_BIT 0
+
+#define ADC7_DDR DDRF
+#define ADC7_PORT PORTF
+#define ADC7_PIN PINF
+#define ADC7_BIT 7
+
+#define ADC6_DDR DDRF
+#define ADC6_PORT PORTF
+#define ADC6_PIN PINF
+#define ADC6_BIT 6
+
+#define TD0_DDR DDRF
+#define TD0_PORT PORTF
+#define TD0_PIN PINF
+#define TD0_BIT 6
+
+#define ADC5_DDR DDRF
+#define ADC5_PORT PORTF
+#define ADC5_PIN PINF
+#define ADC5_BIT 5
+
+#define ADC4_DDR DDRF
+#define ADC4_PORT PORTF
+#define ADC4_PIN PINF
+#define ADC4_BIT 4
+
+#define ADC3_DDR DDRF
+#define ADC3_PORT PORTF
+#define ADC3_PIN PINF
+#define ADC3_BIT 3
+
+#define ADC2_DDR DDRF
+#define ADC2_PORT PORTF
+#define ADC2_PIN PINF
+#define ADC2_BIT 2
+
+#define ADC1_DDR DDRF
+#define ADC1_PORT PORTF
+#define ADC1_PIN PINF
+#define ADC1_BIT 1
+
+#define ADC0_DDR DDRF
+#define ADC0_PORT PORTF
+#define ADC0_PIN PINF
+#define ADC0_BIT 0
+
+#endif /* _AVR_ATmega649_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom64c1.h b/cpukit/score/cpu/avr/avr/iom64c1.h
new file mode 100644
index 0000000000..ea9450b0a6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom64c1.h
@@ -0,0 +1,1298 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom64c1.h - definitions for ATmega64C1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom64c1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega64C1_H_
+#define _AVR_ATmega64C1_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 6
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC3O 3
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define AC3IF 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRLIN 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC 5
+#define PRCAN 6
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6A)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6B)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6C)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define PCMSK3 _SFR_MEM8(0x6D)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x75)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0TS2 2
+#define AMPCMP0 3
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x76)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1TS2 2
+#define AMPCMP1 3
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#define AMP2CSR _SFR_MEM8(0x77)
+#define AMP2TS0 0
+#define AMP2TS1 1
+#define AMP2TS2 2
+#define AMPCMP2 3
+#define AMP2G0 4
+#define AMP2G1 5
+#define AMP2IS 6
+#define AMP2EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define AREFEN 5
+#define ISRCEN 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+#define AMP2PD 6
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define DACON _SFR_MEM8(0x90)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0x91)
+
+#define DACL _SFR_MEM8(0x91)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0x92)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0x94)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define ACCKSEL 3
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0x95)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0x96)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define AC3CON _SFR_MEM8(0x97)
+#define AC3M0 0
+#define AC3M1 1
+#define AC3M2 2
+#define AC3IS0 4
+#define AC3IS1 5
+#define AC3IE 6
+#define AC3EN 7
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+#define CANGCON _SFR_MEM8(0xD8)
+#define SWRES 0
+#define ENASTB 1
+#define TEST 2
+#define LISTEN 3
+#define SYNTTC 4
+#define TTC 5
+#define OVRQ 6
+#define ABRQ 7
+
+#define CANGSTA _SFR_MEM8(0xD9)
+#define ERRP 0
+#define BOFF 1
+#define ENFG 2
+#define RXBSY 3
+#define TXBSY 4
+#define OVFG 6
+
+#define CANGIT _SFR_MEM8(0xDA)
+#define AERG 0
+#define FERG 1
+#define CERG 2
+#define SERG 3
+#define BXOK 4
+#define OVRTIM 5
+#define BOFFIT 6
+#define CANIT 7
+
+#define CANGIE _SFR_MEM8(0xDB)
+#define ENOVRT 0
+#define ENERG 1
+#define ENBX 2
+#define ENERR 3
+#define ENTX 4
+#define ENRX 5
+#define ENBOFF 6
+#define ENIT 7
+
+#define CANEN2 _SFR_MEM8(0xDC)
+#define ENMOB0 0
+#define ENMOB1 1
+#define ENMOB2 2
+#define ENMOB3 3
+#define ENMOB4 4
+#define ENMOB5 5
+
+#define CANEN1 _SFR_MEM8(0xDD)
+
+#define CANIE2 _SFR_MEM8(0xDE)
+#define IEMOB0 0
+#define IEMOB1 1
+#define IEMOB2 2
+#define IEMOB3 3
+#define IEMOB4 4
+#define IEMOB5 5
+
+#define CANIE1 _SFR_MEM8(0xDF)
+
+#define CANSIT2 _SFR_MEM8(0xE0)
+#define SIT0 0
+#define SIT1 1
+#define SIT2 2
+#define SIT3 3
+#define SIT4 4
+#define SIT5 5
+
+#define CANSIT1 _SFR_MEM8(0xE1)
+
+#define CANBT1 _SFR_MEM8(0xE2)
+#define BRP0 1
+#define BRP1 2
+#define BRP2 3
+#define BRP3 4
+#define BRP4 5
+#define BRP5 6
+
+#define CANBT2 _SFR_MEM8(0xE3)
+#define PRS0 1
+#define PRS1 2
+#define PRS2 3
+#define SJW0 5
+#define SJW1 6
+
+#define CANBT3 _SFR_MEM8(0xE4)
+#define SMP 0
+#define PHS10 1
+#define PHS11 2
+#define PHS12 3
+#define PHS20 4
+#define PHS21 5
+#define PHS22 6
+
+#define CANTCON _SFR_MEM8(0xE5)
+#define TPRSC0 0
+#define TPRSC1 1
+#define TPRSC2 2
+#define TPRSC3 3
+#define TPRSC4 4
+#define TPRSC5 5
+#define TPRSC6 6
+#define TPRSC7 7
+
+#define CANTIM _SFR_MEM16(0xE6)
+
+#define CANTIML _SFR_MEM8(0xE6)
+#define CANTIM0 0
+#define CANTIM1 1
+#define CANTIM2 2
+#define CANTIM3 3
+#define CANTIM4 4
+#define CANTIM5 5
+#define CANTIM6 6
+#define CANTIM7 7
+
+#define CANTIMH _SFR_MEM8(0xE7)
+#define CANTIM8 0
+#define CANTIM9 1
+#define CANTIM10 2
+#define CANTIM11 3
+#define CANTIM12 4
+#define CANTIM13 5
+#define CANTIM14 6
+#define CANTIM15 7
+
+#define CANTTC _SFR_MEM16(0xE8)
+
+#define CANTTCL _SFR_MEM8(0xE8)
+#define TIMTCC0 0
+#define TIMTCC1 1
+#define TIMTCC2 2
+#define TIMTCC3 3
+#define TIMTCC4 4
+#define TIMTCC5 5
+#define TIMTCC6 6
+#define TIMTCC7 7
+
+#define CANTTCH _SFR_MEM8(0xE9)
+#define TIMTCC8 0
+#define TIMTCC9 1
+#define TIMTCC10 2
+#define TIMTCC11 3
+#define TIMTCC12 4
+#define TIMTCC13 5
+#define TIMTCC14 6
+#define TIMTCC15 7
+
+#define CANTEC _SFR_MEM8(0xEA)
+#define TEC0 0
+#define TEC1 1
+#define TEC2 2
+#define TEC3 3
+#define TEC4 4
+#define TEC5 5
+#define TEC6 6
+#define TEC7 7
+
+#define CANREC _SFR_MEM8(0xEB)
+#define REC0 0
+#define REC1 1
+#define REC2 2
+#define REC3 3
+#define REC4 4
+#define REC5 5
+#define REC6 6
+#define REC7 7
+
+#define CANHPMOB _SFR_MEM8(0xEC)
+#define CGP0 0
+#define CGP1 1
+#define CGP2 2
+#define CGP3 3
+#define HPMOB0 4
+#define HPMOB1 5
+#define HPMOB2 6
+#define HPMOB3 7
+
+#define CANPAGE _SFR_MEM8(0xED)
+#define INDX0 0
+#define INDX1 1
+#define INDX2 2
+#define AINC 3
+#define MOBNB0 4
+#define MOBNB1 5
+#define MOBNB2 6
+#define MOBNB3 7
+
+#define CANSTMOB _SFR_MEM8(0xEE)
+#define AERR 0
+#define FERR 1
+#define CERR 2
+#define SERR 3
+#define BERR 4
+#define RXOK 5
+#define TXOK 6
+#define DLCW 7
+
+#define CANCDMOB _SFR_MEM8(0xEF)
+#define DLC0 0
+#define DLC1 1
+#define DLC2 2
+#define DLC3 3
+#define IDE 4
+#define RPLV 5
+#define CONMOB0 6
+#define CONMOB1 7
+
+#define CANIDT4 _SFR_MEM8(0xF0)
+#define RB0TAG 0
+#define RB1TAG 1
+#define RTRTAG 2
+#define IDT0 3
+#define IDT1 4
+#define IDT2 5
+#define IDT3 6
+#define IDT4 7
+
+#define CANIDT3 _SFR_MEM8(0xF1)
+#define IDT5 0
+#define IDT6 1
+#define IDT7 2
+#define IDT8 3
+#define IDT9 4
+#define IDT10 5
+#define IDT11 6
+#define IDT12 7
+
+#define CANIDT2 _SFR_MEM8(0xF2)
+#define IDT13 0
+#define IDT14 1
+#define IDT15 2
+#define IDT16 3
+#define IDT17 4
+#define IDT18 5
+#define IDT19 6
+#define IDT20 7
+
+#define CANIDT1 _SFR_MEM8(0xF3)
+#define IDT21 0
+#define IDT22 1
+#define IDT23 2
+#define IDT24 3
+#define IDT25 4
+#define IDT26 5
+#define IDT27 6
+#define IDT28 7
+
+#define CANIDM4 _SFR_MEM8(0xF4)
+#define IDEMSK 0
+#define RTRMSK 2
+#define IDMSK0 3
+#define IDMSK1 4
+#define IDMSK2 5
+#define IDMSK3 6
+#define IDMSK4 7
+
+#define CANIDM3 _SFR_MEM8(0xF5)
+#define IDMSK5 0
+#define IDMSK6 1
+#define IDMSK7 2
+#define IDMSK8 3
+#define IDMSK9 4
+#define IDMSK10 5
+#define IDMSK11 6
+#define IDMSK12 7
+
+#define CANIDM2 _SFR_MEM8(0xF6)
+#define IDMSK13 0
+#define IDMSK14 1
+#define IDMSK15 2
+#define IDMSK16 3
+#define IDMSK17 4
+#define IDMSK18 5
+#define IDMSK19 6
+#define IDMSK20 7
+
+#define CANIDM1 _SFR_MEM8(0xF7)
+#define IDMSK21 0
+#define IDMSK22 1
+#define IDMSK23 2
+#define IDMSK24 3
+#define IDMSK25 4
+#define IDMSK26 5
+#define IDMSK27 6
+#define IDMSK28 7
+
+#define CANSTM _SFR_MEM16(0xF8)
+
+#define CANSTML _SFR_MEM8(0xF8)
+#define TIMSTM0 0
+#define TIMSTM1 1
+#define TIMSTM2 2
+#define TIMSTM3 3
+#define TIMSTM4 4
+#define TIMSTM5 5
+#define TIMSTM6 6
+#define TIMSTM7 7
+
+#define CANSTMH _SFR_MEM8(0xF9)
+#define TIMSTM8 0
+#define TIMSTM9 1
+#define TIMSTM10 2
+#define TIMSTM11 3
+#define TIMSTM12 4
+#define TIMSTM13 5
+#define TIMSTM14 6
+#define TIMSTM15 7
+
+#define CANMSG _SFR_MEM8(0xFA)
+#define MSG0 0
+#define MSG1 1
+#define MSG2 2
+#define MSG3 3
+#define MSG4 4
+#define MSG5 5
+#define MSG6 6
+#define MSG7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define ANACOMP0_vect_num 1
+#define ANACOMP0_vect _VECTOR(1) /* Analog Comparator 0 */
+#define ANACOMP1_vect_num 2
+#define ANACOMP1_vect _VECTOR(2) /* Analog Comparator 1 */
+#define ANACOMP2_vect_num 3
+#define ANACOMP2_vect _VECTOR(3) /* Analog Comparator 2 */
+#define ANACOMP3_vect_num 4
+#define ANACOMP3_vect _VECTOR(4) /* Analog Comparator 3 */
+#define PSC_FAULT_vect_num 5
+#define PSC_FAULT_vect _VECTOR(5) /* PSC Fault */
+#define PSC_EC_vect_num 6
+#define PSC_EC_vect _VECTOR(6) /* PSC End of Cycle */
+#define INT0_vect_num 7
+#define INT0_vect _VECTOR(7) /* External Interrupt Request 0 */
+#define INT1_vect_num 8
+#define INT1_vect _VECTOR(8) /* External Interrupt Request 1 */
+#define INT2_vect_num 9
+#define INT2_vect _VECTOR(9) /* External Interrupt Request 2 */
+#define INT3_vect_num 10
+#define INT3_vect _VECTOR(10) /* External Interrupt Request 3 */
+#define TIMER1_CAPT_vect_num 11
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 12
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 13
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 14
+#define TIMER1_OVF_vect _VECTOR(14) /* Timer1/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 15
+#define TIMER0_COMPA_vect _VECTOR(15) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 16
+#define TIMER0_COMPB_vect _VECTOR(16) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 17
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define CAN_INT_vect_num 18
+#define CAN_INT_vect _VECTOR(18) /* CAN MOB, Burst, General Errors */
+#define CAN_TOVF_vect_num 19
+#define CAN_TOVF_vect _VECTOR(19) /* CAN Timer Overflow */
+#define LIN_TC_vect_num 20
+#define LIN_TC_vect _VECTOR(20) /* LIN Transfer Complete */
+#define LIN_ERR_vect_num 21
+#define LIN_ERR_vect _VECTOR(21) /* LIN Error */
+#define PCINT0_vect_num 22
+#define PCINT0_vect _VECTOR(22) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 23
+#define PCINT1_vect _VECTOR(23) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 24
+#define PCINT2_vect _VECTOR(24) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 25
+#define PCINT3_vect _VECTOR(25) /* Pin Change Interrupt Request 3 */
+#define SPI_STC_vect_num 26
+#define SPI_STC_vect _VECTOR(26) /* SPI Serial Transfer Complete */
+#define ADC_vect_num 27
+#define ADC_vect _VECTOR(27) /* ADC Conversion Complete */
+#define WDT_vect_num 28
+#define WDT_vect _VECTOR(28) /* Watchdog Time-Out Interrupt */
+#define EE_READY_vect_num 29
+#define EE_READY_vect _VECTOR(29) /* EEPROM Ready */
+#define SPM_READY_vect_num 30
+#define SPM_READY_vect _VECTOR(30) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (256)
+#define RAMSTART (0x0100)
+#define RAMSIZE (4096)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7FF)
+#define E2PAGESIZE (8)
+#define FLASHEND (0xFFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector Trigger Level */
+#define FUSE_PSCRVB (unsigned char)~_BV(3) /* PSC Outputs xB Reset Value */
+#define FUSE_PSCRVA (unsigned char)~_BV(4) /* PSC Outputs xA Reset Value */
+#define FUSE_PSCRB (unsigned char)~_BV(5) /* PSC Reset Behavior */
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_BODLEVEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x86
+
+
+#endif /* _AVR_ATmega64C1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom64hve.h b/cpukit/score/cpu/avr/avr/iom64hve.h
new file mode 100644
index 0000000000..b1429e63b8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom64hve.h
@@ -0,0 +1,1020 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom64hve.h - definitions for ATmega64HVE */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom64hve.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega64HVE_H_
+#define _AVR_ATmega64HVE_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+#define ICF0 3
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 3
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define ICS0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+
+#define TCNT0 _SFR_IO16(0x26)
+
+#define TCNT0L _SFR_IO8(0x26)
+#define TCNT0L0 0
+#define TCNT0L1 1
+#define TCNT0L2 2
+#define TCNT0L3 3
+#define TCNT0L4 4
+#define TCNT0L5 5
+#define TCNT0L6 6
+#define TCNT0L7 7
+
+#define TCNT0H _SFR_IO8(0x27)
+#define TCNT0H0 0
+#define TCNT0H1 1
+#define TCNT0H2 2
+#define TCNT0H3 3
+#define TCNT0H4 4
+#define TCNT0H5 5
+#define TCNT0H6 6
+#define TCNT0H7 7
+
+#define OCR0A _SFR_IO8(0x28)
+#define OCR0A0 0
+#define OCR0A1 1
+#define OCR0A2 2
+#define OCR0A3 3
+#define OCR0A4 4
+#define OCR0A5 5
+#define OCR0A6 6
+#define OCR0A7 7
+
+#define OCR0B _SFR_IO8(0x29)
+#define OCR0B0 0
+#define OCR0B1 1
+#define OCR0B2 2
+#define OCR0B3 3
+#define OCR0B4 4
+#define OCR0B5 5
+#define OCR0B6 6
+#define OCR0B7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define TCCR0C _SFR_IO8(0x2F)
+
+#define OCDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BODRF 2
+#define WDRF 3
+#define OCDRF 4
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define CKOE 5
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define LBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPCE 7
+
+#define WUTCSR _SFR_MEM8(0x62)
+#define WUTP0 0
+#define WUTP1 1
+#define WUTP2 2
+#define WUTE 3
+#define WUTR 4
+#define WUTIE 6
+#define WUTIF 7
+
+#define WDTCLR _SFR_MEM8(0x63)
+#define WDCLE 0
+#define WDCL0 1
+#define WDCL1 2
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRTIM0 0
+#define PRTIM1 1
+#define PRSPI 2
+#define PRLIN 3
+
+#define SOSCCALA _SFR_MEM8(0x66)
+#define SCALA0 0
+#define SCALA1 1
+#define SCALA2 2
+#define SCALA3 3
+#define SCALA4 4
+#define SCALA5 5
+#define SCALA6 6
+#define SCALA7 7
+
+#define SOSCCALB _SFR_MEM8(0x67)
+#define SCALB0 0
+#define SCALB1 1
+#define SCALB2 2
+#define SCALB3 3
+#define SCALB4 4
+#define SCALB5 5
+#define SCALB6 6
+#define SCALB7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT2 0
+#define PCINT3 1
+#define PCINT4 2
+#define PCINT5 3
+#define PCINT6 4
+#define PCINT7 5
+#define PCINT8 6
+#define PCINT9 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+#define ICIE0 3
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 3
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define PA0DID 0
+#define PA1DID 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define ICS1 3
+#define ICES1 4
+#define ICNC1 5
+#define ICEN1 6
+#define TCW1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+
+#define TCCR1C _SFR_MEM8(0x82)
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define OCR1A _SFR_MEM8(0x88)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define OCR1B _SFR_MEM8(0x89)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define LINCR _SFR_MEM8(0xC0)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC1)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xC2)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xC3)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xC4)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xC5)
+
+#define LINBRRL _SFR_MEM8(0xC5)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xC6)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xC7)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xC8)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xC9)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xCA)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+#define BGCSRA _SFR_MEM8(0xD1)
+#define BGSC0 0
+#define BGSC1 1
+#define BGSC2 2
+
+#define BGCRB _SFR_MEM8(0xD2)
+#define BGCL0 0
+#define BGCL1 1
+#define BGCL2 2
+#define BGCL3 3
+#define BGCL4 4
+#define BGCL5 5
+#define BGCL6 6
+#define BGCL7 7
+
+#define BGCRA _SFR_MEM8(0xD3)
+#define BGCN0 0
+#define BGCN1 1
+#define BGCN2 2
+#define BGCN3 3
+#define BGCN4 4
+#define BGCN5 5
+#define BGCN6 6
+#define BGCN7 7
+
+#define BGLR _SFR_MEM8(0xD4)
+#define BGPL 0
+#define BGPLE 1
+
+#define PLLCSR _SFR_MEM8(0xD8)
+#define PLLCIE 0
+#define PLLCIF 1
+#define LOCK 4
+#define SWEN 5
+
+#define PBOV _SFR_MEM8(0xDC)
+#define PBOE0 0
+#define PBOE3 3
+#define PBOVCE 7
+
+#define ADSCSRA _SFR_MEM8(0xE0)
+#define SCMD0 0
+#define SCMD1 1
+#define SBSY 2
+
+#define ADSCSRB _SFR_MEM8(0xE1)
+#define CADICRB 0
+#define CADACRB 1
+#define CADICPS 2
+#define VADICRB 4
+#define VADACRB 5
+#define VADICPS 6
+
+#define ADCRA _SFR_MEM8(0xE2)
+#define CKSEL 0
+#define ADCMS0 1
+#define ADCMS1 2
+#define ADPSEL 3
+
+#define ADCRB _SFR_MEM8(0xE3)
+#define ADADES0 0
+#define ADADES1 1
+#define ADADES2 2
+#define ADIDES0 3
+#define ADIDES1 4
+
+#define ADCRC _SFR_MEM8(0xE4)
+#define CADRCT0 0
+#define CADRCT1 1
+#define CADRCT2 2
+#define CADRCT3 3
+#define CADRCM0 4
+#define CADRCM1 5
+#define CADEN 7
+
+#define ADCRD _SFR_MEM8(0xE5)
+#define CADDSEL 0
+#define CADPDM0 1
+#define CADPDM1 2
+#define CADG0 3
+#define CADG1 4
+#define CADG2 5
+
+#define ADCRE _SFR_MEM8(0xE6)
+#define VADMUX0 0
+#define VADMUX1 1
+#define VADMUX2 2
+#define VADPDM0 3
+#define VADPDM1 4
+#define VADREFS 5
+#define VADEN 7
+
+#define ADIFR _SFR_MEM8(0xE7)
+#define CADICIF 0
+#define CADACIF 1
+#define CADRCIF 2
+#define VADICIF 4
+#define VADACIF 5
+
+#define ADIMR _SFR_MEM8(0xE8)
+#define CADICIE 0
+#define CADACIE 1
+#define CADRCIE 2
+#define VADICIE 4
+#define VADACIE 5
+
+#define CADRCL _SFR_MEM16(0xE9)
+
+#define CADRCLL _SFR_MEM8(0xE9)
+#define CADRCL0 0
+#define CADRCL1 1
+#define CADRCL2 2
+#define CADRCL3 3
+#define CADRCL4 4
+#define CADRCL5 5
+#define CADRCL6 6
+#define CADRCL7 7
+
+#define CADRCLH _SFR_MEM8(0xEA)
+#define CADRCL8 0
+#define CADRCL9 1
+#define CADRCL10 2
+#define CADRCL11 3
+#define CADRCL12 4
+#define CADRCL13 5
+#define CADRCL14 6
+#define CADRCL15 7
+
+#define CADIC _SFR_MEM16(0xEB)
+
+#define CADICL _SFR_MEM8(0xEB)
+#define CADIC0 0
+#define CADIC1 1
+#define CADIC2 2
+#define CADIC3 3
+#define CADIC4 4
+#define CADIC5 5
+#define CADIC6 6
+#define CADIC7 7
+
+#define CADICH _SFR_MEM8(0xEC)
+#define CADIC8 0
+#define CADIC9 1
+#define CADIC10 2
+#define CADIC11 3
+#define CADIC12 4
+#define CADIC13 5
+#define CADIC14 6
+#define CADIC15 7
+
+#define CADAC0 _SFR_MEM8(0xED)
+#define CADAC00 0
+#define CADAC01 1
+#define CADAC02 2
+#define CADAC03 3
+#define CADAC04 4
+#define CADAC05 5
+#define CADAC06 6
+#define CADAC07 7
+
+#define CADAC1 _SFR_MEM8(0xEE)
+#define CADAC08 0
+#define CADAC09 1
+#define CADAC10 2
+#define CADAC11 3
+#define CADAC12 4
+#define CADAC13 5
+#define CADAC14 6
+#define CADAC15 7
+
+#define CADAC2 _SFR_MEM8(0xEF)
+#define CADAC16 0
+#define CADAC17 1
+#define CADAC18 2
+#define CADAC19 3
+#define CADAC20 4
+#define CADAC21 5
+#define CADAC22 6
+#define CADAC23 7
+
+#define CADAC3 _SFR_MEM8(0xF0)
+#define CADAC24 0
+#define CADAC25 1
+#define CADAC26 2
+#define CADAC27 3
+#define CADAC28 4
+#define CADAC29 5
+#define CADAC30 6
+#define CADAC31 7
+
+#define VADIC _SFR_MEM16(0xF1)
+
+#define VADICL _SFR_MEM8(0xF1)
+#define VADIC0 0
+#define VADIC1 1
+#define VADIC2 2
+#define VADIC3 3
+#define VADIC4 4
+#define VADIC5 5
+#define VADIC6 6
+#define VADIC7 7
+
+#define VADICH _SFR_MEM8(0xF2)
+#define VADIC8 0
+#define VADIC9 1
+#define VADIC10 2
+#define VADIC11 3
+#define VADIC12 4
+#define VADIC13 5
+#define VADIC14 6
+#define VADIC15 7
+
+#define VADAC0 _SFR_MEM8(0xF3)
+#define VADAC00 0
+#define VADAC01 1
+#define VADAC02 2
+#define VADAC03 3
+#define VADAC04 4
+#define VADAC05 5
+#define VADAC06 6
+#define VADAC07 7
+
+#define VADAC1 _SFR_MEM8(0xF4)
+#define VADAC08 0
+#define VADAC09 1
+#define VADAC10 2
+#define VADAC11 3
+#define VADAC12 4
+#define VADAC13 5
+#define VADAC14 6
+#define VADAC15 7
+
+#define VADAC2 _SFR_MEM8(0xF5)
+#define VADAC16 0
+#define VADAC17 1
+#define VADAC18 2
+#define VADAC19 3
+#define VADAC20 4
+#define VADAC21 5
+#define VADAC22 6
+#define VADAC23 7
+
+#define VADAC3 _SFR_MEM8(0xF6)
+#define VADAC24 0
+#define VADAC25 1
+#define VADAC26 2
+#define VADAC27 3
+#define VADAC28 4
+#define VADAC29 5
+#define VADAC30 6
+#define VADAC31 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt 0 */
+#define PCINT0_vect_num 2
+#define PCINT0_vect _VECTOR(2) /* Pin Change Interrupt 0 */
+#define PCINT1_vect_num 3
+#define PCINT1_vect _VECTOR(3) /* Pin Change Interrupt 1 */
+#define WDT_vect_num 4
+#define WDT_vect _VECTOR(4) /* Watchdog Timeout Interrupt */
+#define WAKEUP_vect_num 5
+#define WAKEUP_vect _VECTOR(5) /* Wakeup Timer Overflow */
+#define TIMER1_IC_vect_num 6
+#define TIMER1_IC_vect _VECTOR(6) /* Timer 1 Input capture */
+#define TIMER1_COMPA_vect_num 7
+#define TIMER1_COMPA_vect _VECTOR(7) /* Timer 1 Compare Match A */
+#define TIMER1_COMPB_vect_num 8
+#define TIMER1_COMPB_vect _VECTOR(8) /* Timer 1 Compare Match B */
+#define TIMER1_OVF_vect_num 9
+#define TIMER1_OVF_vect _VECTOR(9) /* Timer 1 overflow */
+#define TIMER0_IC_vect_num 10
+#define TIMER0_IC_vect _VECTOR(10) /* Timer 0 Input Capture */
+#define TIMER0_COMPA_vect_num 11
+#define TIMER0_COMPA_vect _VECTOR(11) /* Timer 0 Comapre Match A */
+#define TIMER0_COMPB_vect_num 12
+#define TIMER0_COMPB_vect _VECTOR(12) /* Timer 0 Compare Match B */
+#define TIMER0_OVF_vect_num 13
+#define TIMER0_OVF_vect _VECTOR(13) /* Timer 0 Overflow */
+#define LIN_STATUS_vect_num 14
+#define LIN_STATUS_vect _VECTOR(14) /* LIN Status Interrupt */
+#define LIN_ERROR_vect_num 15
+#define LIN_ERROR_vect _VECTOR(15) /* LIN Error Interrupt */
+#define SPI_STC_vect_num 16
+#define SPI_STC_vect _VECTOR(16) /* SPI Serial transfer complete */
+#define VADC_CONV_vect_num 17
+#define VADC_CONV_vect _VECTOR(17) /* Voltage ADC Instantaneous Conversion Complete */
+#define VADC_ACC_vect_num 18
+#define VADC_ACC_vect _VECTOR(18) /* Voltage ADC Accumulated Conversion Complete */
+#define CADC_CONV_vect_num 19
+#define CADC_CONV_vect _VECTOR(19) /* C-ADC Instantaneous Conversion Complete */
+#define CADC_REG_CUR_vect_num 20
+#define CADC_REG_CUR_vect _VECTOR(20) /* C-ADC Regular Current */
+#define CADC_ACC_vect_num 21
+#define CADC_ACC_vect _VECTOR(21) /* C-ADC Accumulated Conversion Complete */
+#define EE_READY_vect_num 22
+#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
+#define SPM_vect_num 23
+#define SPM_vect _VECTOR(23) /* SPM Ready */
+#define PLL_vect_num 24
+#define PLL_vect _VECTOR(24) /* PLL Lock Change Interrupt */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (25 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (4096)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (NA)
+#define XRAMEND (RAMEND)
+#define E2END (0x3FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0xFFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_OSCSEL0 (unsigned char)~_BV(0) /* Oscillator Select */
+#define FUSE_SUT0 (unsigned char)~_BV(1) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(2) /* Select start-up time */
+#define FUSE_CKDIV8 (unsigned char)~_BV(3) /* Divide clock by 8 */
+#define FUSE_BODEN (unsigned char)~_BV(4) /* Enable BOD */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_EESAVE (unsigned char)~_BV(6) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(7) /* Watchdog Timer Always On */
+#define LFUSE_DEFAULT (FUSE_SPIEN & FUSE_CKDIV8 & FUSE_OSCSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_DWEN (unsigned char)~_BV(3) /* Enable debugWire */
+#define HFUSE_DEFAULT (FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x10
+
+
+/* Device Pin Definitions */
+#define PV2_DDR DDRV
+#define PV2_PORT PORTV
+#define PV2_PIN PINV
+#define PV2_BIT 2
+
+#define PV1_DDR DDRV
+#define PV1_PORT PORTV
+#define PV1_PIN PINV
+#define PV1_BIT 1
+
+#define NV_DDR DDRNV
+#define NV_PORT PORTNV
+#define NV_PIN PINNV
+#define NV_BIT NV
+
+#define VFET_DDR DDRVFET
+#define VFET_PORT PORTVFET
+#define VFET_PIN PINVFET
+#define VFET_BIT VFET
+
+#define CF1P_DDR DDRCF1P
+#define CF1P_PORT PORTCF1P
+#define CF1P_PIN PINCF1P
+#define CF1P_BIT CF1P
+
+#define CF1N_DDR DDRCF1N
+#define CF1N_PORT PORTCF1N
+#define CF1N_PIN PINCF1N
+#define CF1N_BIT CF1N
+
+#define CF2P_DDR DDRCF2P
+#define CF2P_PORT PORTCF2P
+#define CF2P_PIN PINCF2P
+#define CF2P_BIT CF2P
+
+#define CF2N_DDR DDRCF2N
+#define CF2N_PORT PORTCF2N
+#define CF2N_PIN PINCF2N
+#define CF2N_BIT CF2N
+
+#define VREG_DDR DDRVREG
+#define VREG_PORT PORTVREG
+#define VREG_PIN PINVREG
+#define VREG_BIT VREG
+
+#define VREF_DDR DDRVREF
+#define VREF_PORT PORTVREF
+#define VREF_PIN PINVREF
+#define VREF_BIT VREF
+
+#define VREFGND_DDR DDRVREFGND
+#define VREFGND_PORT PORTVREFGND
+#define VREFGND_PIN PINVREFGND
+#define VREFGND_BIT VREFGND
+
+#define PI_DDR DDRI
+#define PI_PORT PORTI
+#define PI_PIN PINI
+#define PI_BIT
+
+#define NI_DDR DDRNI
+#define NI_PORT PORTNI
+#define NI_PIN PINNI
+#define NI_BIT NI
+
+#define PA0_DDR DDRA
+#define PA0_PORT PORTA
+#define PA0_PIN PINA
+#define PA0_BIT 0
+
+#define PA1_DDR DDRA
+#define PA1_PORT PORTA
+#define PA1_PIN PINA
+#define PA1_BIT 1
+
+#define PA2_DDR DDRA
+#define PA2_PORT PORTA
+#define PA2_PIN PINA
+#define PA2_BIT 2
+
+#define PB0_DDR DDRB
+#define PB0_PORT PORTB
+#define PB0_PIN PINB
+#define PB0_BIT 0
+
+#define PB1_DDR DDRB
+#define PB1_PORT PORTB
+#define PB1_PIN PINB
+#define PB1_BIT 1
+
+#define PB2_DDR DDRB
+#define PB2_PORT PORTB
+#define PB2_PIN PINB
+#define PB2_BIT 2
+
+#define PB3_DDR DDRB
+#define PB3_PORT PORTB
+#define PB3_PIN PINB
+#define PB3_BIT 3
+
+#define PC0_DDR DDRC
+#define PC0_PORT PORTC
+#define PC0_PIN PINC
+#define PC0_BIT 0
+
+#define BATT_DDR DDRBATT
+#define BATT_PORT PORTBATT
+#define BATT_PIN PINBATT
+#define BATT_BIT BATT
+
+#define OC_DDR DDROC
+#define OC_PORT PORTOC
+#define OC_PIN PINOC
+#define OC_BIT OC
+
+#endif /* _AVR_ATmega64HVE_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom64m1.h b/cpukit/score/cpu/avr/avr/iom64m1.h
new file mode 100644
index 0000000000..1da9cbb618
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom64m1.h
@@ -0,0 +1,1549 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom64m1.h - definitions for ATmega64M1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom64m1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega64M1_H_
+#define _AVR_ATmega64M1_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE0 0
+#define PINE1 1
+#define PINE2 2
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE0 0
+#define DDE1 1
+#define DDE2 2
+
+#define PORTE _SFR_IO8(0x0E)
+#define PORTE0 0
+#define PORTE1 1
+#define PORTE2 2
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define GPIOR1 _SFR_IO8(0x19)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x1A)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define PSRSYNC 0
+#define ICPSEL1 6
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLF 2
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define AC0O 0
+#define AC1O 1
+#define AC2O 2
+#define AC3O 3
+#define AC0IF 4
+#define AC1IF 5
+#define AC2IF 6
+#define AC3IF 7
+
+#define DWDR _SFR_IO8(0x31)
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define SPIPS 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRLIN 1
+#define PRSPI 2
+#define PRTIM0 3
+#define PRTIM1 4
+#define PRPSC 5
+#define PRCAN 6
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define PCMSK0 _SFR_MEM8(0x6A)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6B)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6C)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define PCMSK3 _SFR_MEM8(0x6D)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMP0CSR _SFR_MEM8(0x75)
+#define AMP0TS0 0
+#define AMP0TS1 1
+#define AMP0TS2 2
+#define AMPCMP0 3
+#define AMP0G0 4
+#define AMP0G1 5
+#define AMP0IS 6
+#define AMP0EN 7
+
+#define AMP1CSR _SFR_MEM8(0x76)
+#define AMP1TS0 0
+#define AMP1TS1 1
+#define AMP1TS2 2
+#define AMPCMP1 3
+#define AMP1G0 4
+#define AMP1G1 5
+#define AMP1IS 6
+#define AMP1EN 7
+
+#define AMP2CSR _SFR_MEM8(0x77)
+#define AMP2TS0 0
+#define AMP2TS1 1
+#define AMP2TS2 2
+#define AMPCMP2 3
+#define AMP2G0 4
+#define AMP2G1 5
+#define AMP2IS 6
+#define AMP2EN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADTS3 3
+#define AREFEN 5
+#define ISRCEN 6
+#define ADHSM 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+#define AMP0ND 3
+#define AMP0PD 4
+#define ACMP0D 5
+#define AMP2PD 6
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define DACON _SFR_MEM8(0x90)
+#define DAEN 0
+#define DAOE 1
+#define DALA 2
+#define DATS0 4
+#define DATS1 5
+#define DATS2 6
+#define DAATE 7
+
+#define DAC _SFR_MEM16(0x91)
+
+#define DACL _SFR_MEM8(0x91)
+#define DACL0 0
+#define DACL1 1
+#define DACL2 2
+#define DACL3 3
+#define DACL4 4
+#define DACL5 5
+#define DACL6 6
+#define DACL7 7
+
+#define DACH _SFR_MEM8(0x92)
+#define DACH0 0
+#define DACH1 1
+#define DACH2 2
+#define DACH3 3
+#define DACH4 4
+#define DACH5 5
+#define DACH6 6
+#define DACH7 7
+
+#define AC0CON _SFR_MEM8(0x94)
+#define AC0M0 0
+#define AC0M1 1
+#define AC0M2 2
+#define ACCKSEL 3
+#define AC0IS0 4
+#define AC0IS1 5
+#define AC0IE 6
+#define AC0EN 7
+
+#define AC1CON _SFR_MEM8(0x95)
+#define AC1M0 0
+#define AC1M1 1
+#define AC1M2 2
+#define AC1ICE 3
+#define AC1IS0 4
+#define AC1IS1 5
+#define AC1IE 6
+#define AC1EN 7
+
+#define AC2CON _SFR_MEM8(0x96)
+#define AC2M0 0
+#define AC2M1 1
+#define AC2M2 2
+#define AC2IS0 4
+#define AC2IS1 5
+#define AC2IE 6
+#define AC2EN 7
+
+#define AC3CON _SFR_MEM8(0x97)
+#define AC3M0 0
+#define AC3M1 1
+#define AC3M2 2
+#define AC3IS0 4
+#define AC3IS1 5
+#define AC3IE 6
+#define AC3EN 7
+
+#define POCR0SA _SFR_MEM16(0xA0)
+
+#define POCR0SAL _SFR_MEM8(0xA0)
+#define POCR0SA_0 0
+#define POCR0SA_1 1
+#define POCR0SA_2 2
+#define POCR0SA_3 3
+#define POCR0SA_4 4
+#define POCR0SA_5 5
+#define POCR0SA_6 6
+#define POCR0SA_7 7
+
+#define POCR0SAH _SFR_MEM8(0xA1)
+#define POCR0SA_8 0
+#define POCR0SA_9 1
+#define POCR0SA_10 2
+#define POCR0SA_11 3
+
+#define POCR0RA _SFR_MEM16(0xA2)
+
+#define POCR0RAL _SFR_MEM8(0xA2)
+#define POCR0RA_0 0
+#define POCR0RA_1 1
+#define POCR0RA_2 2
+#define POCR0RA_3 3
+#define POCR0RA_4 4
+#define POCR0RA_5 5
+#define POCR0RA_6 6
+#define POCR0RA_7 7
+
+#define POCR0RAH _SFR_MEM8(0xA3)
+#define POCR0RA_8 0
+#define POCR0RA_9 1
+#define POCR0RA_10 2
+#define POCR0RA_11 3
+
+#define POCR0SB _SFR_MEM16(0xA4)
+
+#define POCR0SBL _SFR_MEM8(0xA4)
+#define POCR0SB_0 0
+#define POCR0SB_1 1
+#define POCR0SB_2 2
+#define POCR0SB_3 3
+#define POCR0SB_4 4
+#define POCR0SB_5 5
+#define POCR0SB_6 6
+#define POCR0SB_7 7
+
+#define POCR0SBH _SFR_MEM8(0xA5)
+#define POCR0SB_8 0
+#define POCR0SB_9 1
+#define POCR0SB_10 2
+#define POCR0SB_11 3
+
+#define POCR1SA _SFR_MEM16(0xA6)
+
+#define POCR1SAL _SFR_MEM8(0xA6)
+#define POCR1SA_0 0
+#define POCR1SA_1 1
+#define POCR1SA_2 2
+#define POCR1SA_3 3
+#define POCR1SA_4 4
+#define POCR1SA_5 5
+#define POCR1SA_6 6
+#define POCR1SA_7 7
+
+#define POCR1SAH _SFR_MEM8(0xA7)
+#define POCR1SA_8 0
+#define POCR1SA_9 1
+#define POCR1SA_10 2
+#define POCR1SA_11 3
+
+#define POCR1RA _SFR_MEM16(0xA8)
+
+#define POCR1RAL _SFR_MEM8(0xA8)
+#define POCR1RA_0 0
+#define POCR1RA_1 1
+#define POCR1RA_2 2
+#define POCR1RA_3 3
+#define POCR1RA_4 4
+#define POCR1RA_5 5
+#define POCR1RA_6 6
+#define POCR1RA_7 7
+
+#define POCR1RAH _SFR_MEM8(0xA9)
+#define POCR1RA_8 0
+#define POCR1RA_9 1
+#define POCR1RA_10 2
+#define POCR1RA_11 3
+
+#define POCR1SB _SFR_MEM16(0xAA)
+
+#define POCR1SBL _SFR_MEM8(0xAA)
+#define POCR1SB_0 0
+#define POCR1SB_1 1
+#define POCR1SB_2 2
+#define POCR1SB_3 3
+#define POCR1SB_4 4
+#define POCR1SB_5 5
+#define POCR1SB_6 6
+#define POCR1SB_7 7
+
+#define POCR1SBH _SFR_MEM8(0xAB)
+#define POCR1SB_8 0
+#define POCR1SB_9 1
+#define POCR1SB_10 2
+#define POCR1SB_11 3
+
+#define POCR2SA _SFR_MEM16(0xAC)
+
+#define POCR2SAL _SFR_MEM8(0xAC)
+#define POCR2SA_0 0
+#define POCR2SA_1 1
+#define POCR2SA_2 2
+#define POCR2SA_3 3
+#define POCR2SA_4 4
+#define POCR2SA_5 5
+#define POCR2SA_6 6
+#define POCR2SA_7 7
+
+#define POCR2SAH _SFR_MEM8(0xAD)
+#define POCR2SA_8 0
+#define POCR2SA_9 1
+#define POCR2SA_10 2
+#define POCR2SA_11 3
+
+#define POCR2RA _SFR_MEM16(0xAE)
+
+#define POCR2RAL _SFR_MEM8(0xAE)
+#define POCR2RA_0 0
+#define POCR2RA_1 1
+#define POCR2RA_2 2
+#define POCR2RA_3 3
+#define POCR2RA_4 4
+#define POCR2RA_5 5
+#define POCR2RA_6 6
+#define POCR2RA_7 7
+
+#define POCR2RAH _SFR_MEM8(0xAF)
+#define POCR2RA_8 0
+#define POCR2RA_9 1
+#define POCR2RA_10 2
+#define POCR2RA_11 3
+
+#define POCR2SB _SFR_MEM16(0xB0)
+
+#define POCR2SBL _SFR_MEM8(0xB0)
+#define POCR2SB_0 0
+#define POCR2SB_1 1
+#define POCR2SB_2 2
+#define POCR2SB_3 3
+#define POCR2SB_4 4
+#define POCR2SB_5 5
+#define POCR2SB_6 6
+#define POCR2SB_7 7
+
+#define POCR2SBH _SFR_MEM8(0xB1)
+#define POCR2SB_8 0
+#define POCR2SB_9 1
+#define POCR2SB_10 2
+#define POCR2SB_11 3
+
+#define POCR_RB _SFR_MEM16(0xB2)
+
+#define POCR_RBL _SFR_MEM8(0xB2)
+#define POCR_RB_0 0
+#define POCR_RB_1 1
+#define POCR_RB_2 2
+#define POCR_RB_3 3
+#define POCR_RB_4 4
+#define POCR_RB_5 5
+#define POCR_RB_6 6
+#define POCR_RB_7 7
+
+#define POCR_RBH _SFR_MEM8(0xB3)
+#define POCR_RB_8 0
+#define POCR_RB_9 1
+#define POCR_RB_10 2
+#define POCR_RB_11 3
+
+#define PSYNC _SFR_MEM8(0xB4)
+#define PSYNC00 0
+#define PSYNC01 1
+#define PSYNC10 2
+#define PSYNC11 3
+#define PSYNC20 4
+#define PSYNC21 5
+
+#define PCNF _SFR_MEM8(0xB5)
+#define POPA 2
+#define POPB 3
+#define PMODE 4
+#define PULOCK 5
+
+#define POC _SFR_MEM8(0xB6)
+#define POEN0A 0
+#define POEN0B 1
+#define POEN1A 2
+#define POEN1B 3
+#define POEN2A 4
+#define POEN2B 5
+
+#define PCTL _SFR_MEM8(0xB7)
+#define PRUN 0
+#define PCCYC 1
+#define PCLKSEL 5
+#define PPRE0 6
+#define PPRE1 7
+
+#define PMIC0 _SFR_MEM8(0xB8)
+#define PRFM00 0
+#define PRFM01 1
+#define PRFM02 2
+#define PAOC0 3
+#define PFLTE0 4
+#define PELEV0 5
+#define PISEL0 6
+#define POVEN0 7
+
+#define PMIC1 _SFR_MEM8(0xB9)
+#define PRFM10 0
+#define PRFM11 1
+#define PRFM12 2
+#define PAOC1 3
+#define PFLTE1 4
+#define PELEV1 5
+#define PISEL1 6
+#define POVEN1 7
+
+#define PMIC2 _SFR_MEM8(0xBA)
+#define PRFM20 0
+#define PRFM21 1
+#define PRFM22 2
+#define PAOC2 3
+#define PFLTE2 4
+#define PELEV2 5
+#define PISEL2 6
+#define POVEN2 7
+
+#define PIM _SFR_MEM8(0xBB)
+#define PEOPE 0
+#define PEVE0 1
+#define PEVE1 2
+#define PEVE2 3
+
+#define PIFR _SFR_MEM8(0xBC)
+#define PEOP 0
+#define PEV0 1
+#define PEV1 2
+#define PEV2 3
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+#define CANGCON _SFR_MEM8(0xD8)
+#define SWRES 0
+#define ENASTB 1
+#define TEST 2
+#define LISTEN 3
+#define SYNTTC 4
+#define TTC 5
+#define OVRQ 6
+#define ABRQ 7
+
+#define CANGSTA _SFR_MEM8(0xD9)
+#define ERRP 0
+#define BOFF 1
+#define ENFG 2
+#define RXBSY 3
+#define TXBSY 4
+#define OVFG 6
+
+#define CANGIT _SFR_MEM8(0xDA)
+#define AERG 0
+#define FERG 1
+#define CERG 2
+#define SERG 3
+#define BXOK 4
+#define OVRTIM 5
+#define BOFFIT 6
+#define CANIT 7
+
+#define CANGIE _SFR_MEM8(0xDB)
+#define ENOVRT 0
+#define ENERG 1
+#define ENBX 2
+#define ENERR 3
+#define ENTX 4
+#define ENRX 5
+#define ENBOFF 6
+#define ENIT 7
+
+#define CANEN2 _SFR_MEM8(0xDC)
+#define ENMOB0 0
+#define ENMOB1 1
+#define ENMOB2 2
+#define ENMOB3 3
+#define ENMOB4 4
+#define ENMOB5 5
+
+#define CANEN1 _SFR_MEM8(0xDD)
+
+#define CANIE2 _SFR_MEM8(0xDE)
+#define IEMOB0 0
+#define IEMOB1 1
+#define IEMOB2 2
+#define IEMOB3 3
+#define IEMOB4 4
+#define IEMOB5 5
+
+#define CANIE1 _SFR_MEM8(0xDF)
+
+#define CANSIT2 _SFR_MEM8(0xE0)
+#define SIT0 0
+#define SIT1 1
+#define SIT2 2
+#define SIT3 3
+#define SIT4 4
+#define SIT5 5
+
+#define CANSIT1 _SFR_MEM8(0xE1)
+
+#define CANBT1 _SFR_MEM8(0xE2)
+#define BRP0 1
+#define BRP1 2
+#define BRP2 3
+#define BRP3 4
+#define BRP4 5
+#define BRP5 6
+
+#define CANBT2 _SFR_MEM8(0xE3)
+#define PRS0 1
+#define PRS1 2
+#define PRS2 3
+#define SJW0 5
+#define SJW1 6
+
+#define CANBT3 _SFR_MEM8(0xE4)
+#define SMP 0
+#define PHS10 1
+#define PHS11 2
+#define PHS12 3
+#define PHS20 4
+#define PHS21 5
+#define PHS22 6
+
+#define CANTCON _SFR_MEM8(0xE5)
+#define TPRSC0 0
+#define TPRSC1 1
+#define TPRSC2 2
+#define TPRSC3 3
+#define TPRSC4 4
+#define TPRSC5 5
+#define TPRSC6 6
+#define TPRSC7 7
+
+#define CANTIM _SFR_MEM16(0xE6)
+
+#define CANTIML _SFR_MEM8(0xE6)
+#define CANTIM0 0
+#define CANTIM1 1
+#define CANTIM2 2
+#define CANTIM3 3
+#define CANTIM4 4
+#define CANTIM5 5
+#define CANTIM6 6
+#define CANTIM7 7
+
+#define CANTIMH _SFR_MEM8(0xE7)
+#define CANTIM8 0
+#define CANTIM9 1
+#define CANTIM10 2
+#define CANTIM11 3
+#define CANTIM12 4
+#define CANTIM13 5
+#define CANTIM14 6
+#define CANTIM15 7
+
+#define CANTTC _SFR_MEM16(0xE8)
+
+#define CANTTCL _SFR_MEM8(0xE8)
+#define TIMTCC0 0
+#define TIMTCC1 1
+#define TIMTCC2 2
+#define TIMTCC3 3
+#define TIMTCC4 4
+#define TIMTCC5 5
+#define TIMTCC6 6
+#define TIMTCC7 7
+
+#define CANTTCH _SFR_MEM8(0xE9)
+#define TIMTCC8 0
+#define TIMTCC9 1
+#define TIMTCC10 2
+#define TIMTCC11 3
+#define TIMTCC12 4
+#define TIMTCC13 5
+#define TIMTCC14 6
+#define TIMTCC15 7
+
+#define CANTEC _SFR_MEM8(0xEA)
+#define TEC0 0
+#define TEC1 1
+#define TEC2 2
+#define TEC3 3
+#define TEC4 4
+#define TEC5 5
+#define TEC6 6
+#define TEC7 7
+
+#define CANREC _SFR_MEM8(0xEB)
+#define REC0 0
+#define REC1 1
+#define REC2 2
+#define REC3 3
+#define REC4 4
+#define REC5 5
+#define REC6 6
+#define REC7 7
+
+#define CANHPMOB _SFR_MEM8(0xEC)
+#define CGP0 0
+#define CGP1 1
+#define CGP2 2
+#define CGP3 3
+#define HPMOB0 4
+#define HPMOB1 5
+#define HPMOB2 6
+#define HPMOB3 7
+
+#define CANPAGE _SFR_MEM8(0xED)
+#define INDX0 0
+#define INDX1 1
+#define INDX2 2
+#define AINC 3
+#define MOBNB0 4
+#define MOBNB1 5
+#define MOBNB2 6
+#define MOBNB3 7
+
+#define CANSTMOB _SFR_MEM8(0xEE)
+#define AERR 0
+#define FERR 1
+#define CERR 2
+#define SERR 3
+#define BERR 4
+#define RXOK 5
+#define TXOK 6
+#define DLCW 7
+
+#define CANCDMOB _SFR_MEM8(0xEF)
+#define DLC0 0
+#define DLC1 1
+#define DLC2 2
+#define DLC3 3
+#define IDE 4
+#define RPLV 5
+#define CONMOB0 6
+#define CONMOB1 7
+
+#define CANIDT4 _SFR_MEM8(0xF0)
+#define RB0TAG 0
+#define RB1TAG 1
+#define RTRTAG 2
+#define IDT0 3
+#define IDT1 4
+#define IDT2 5
+#define IDT3 6
+#define IDT4 7
+
+#define CANIDT3 _SFR_MEM8(0xF1)
+#define IDT5 0
+#define IDT6 1
+#define IDT7 2
+#define IDT8 3
+#define IDT9 4
+#define IDT10 5
+#define IDT11 6
+#define IDT12 7
+
+#define CANIDT2 _SFR_MEM8(0xF2)
+#define IDT13 0
+#define IDT14 1
+#define IDT15 2
+#define IDT16 3
+#define IDT17 4
+#define IDT18 5
+#define IDT19 6
+#define IDT20 7
+
+#define CANIDT1 _SFR_MEM8(0xF3)
+#define IDT21 0
+#define IDT22 1
+#define IDT23 2
+#define IDT24 3
+#define IDT25 4
+#define IDT26 5
+#define IDT27 6
+#define IDT28 7
+
+#define CANIDM4 _SFR_MEM8(0xF4)
+#define IDEMSK 0
+#define RTRMSK 2
+#define IDMSK0 3
+#define IDMSK1 4
+#define IDMSK2 5
+#define IDMSK3 6
+#define IDMSK4 7
+
+#define CANIDM3 _SFR_MEM8(0xF5)
+#define IDMSK5 0
+#define IDMSK6 1
+#define IDMSK7 2
+#define IDMSK8 3
+#define IDMSK9 4
+#define IDMSK10 5
+#define IDMSK11 6
+#define IDMSK12 7
+
+#define CANIDM2 _SFR_MEM8(0xF6)
+#define IDMSK13 0
+#define IDMSK14 1
+#define IDMSK15 2
+#define IDMSK16 3
+#define IDMSK17 4
+#define IDMSK18 5
+#define IDMSK19 6
+#define IDMSK20 7
+
+#define CANIDM1 _SFR_MEM8(0xF7)
+#define IDMSK21 0
+#define IDMSK22 1
+#define IDMSK23 2
+#define IDMSK24 3
+#define IDMSK25 4
+#define IDMSK26 5
+#define IDMSK27 6
+#define IDMSK28 7
+
+#define CANSTM _SFR_MEM16(0xF8)
+
+#define CANSTML _SFR_MEM8(0xF8)
+#define TIMSTM0 0
+#define TIMSTM1 1
+#define TIMSTM2 2
+#define TIMSTM3 3
+#define TIMSTM4 4
+#define TIMSTM5 5
+#define TIMSTM6 6
+#define TIMSTM7 7
+
+#define CANSTMH _SFR_MEM8(0xF9)
+#define TIMSTM8 0
+#define TIMSTM9 1
+#define TIMSTM10 2
+#define TIMSTM11 3
+#define TIMSTM12 4
+#define TIMSTM13 5
+#define TIMSTM14 6
+#define TIMSTM15 7
+
+#define CANMSG _SFR_MEM8(0xFA)
+#define MSG0 0
+#define MSG1 1
+#define MSG2 2
+#define MSG3 3
+#define MSG4 4
+#define MSG5 5
+#define MSG6 6
+#define MSG7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define ANACOMP0_vect_num 1
+#define ANACOMP0_vect _VECTOR(1) /* Analog Comparator 0 */
+#define ANACOMP1_vect_num 2
+#define ANACOMP1_vect _VECTOR(2) /* Analog Comparator 1 */
+#define ANACOMP2_vect_num 3
+#define ANACOMP2_vect _VECTOR(3) /* Analog Comparator 2 */
+#define ANACOMP3_vect_num 4
+#define ANACOMP3_vect _VECTOR(4) /* Analog Comparator 3 */
+#define PSC_FAULT_vect_num 5
+#define PSC_FAULT_vect _VECTOR(5) /* PSC Fault */
+#define PSC_EC_vect_num 6
+#define PSC_EC_vect _VECTOR(6) /* PSC End of Cycle */
+#define INT0_vect_num 7
+#define INT0_vect _VECTOR(7) /* External Interrupt Request 0 */
+#define INT1_vect_num 8
+#define INT1_vect _VECTOR(8) /* External Interrupt Request 1 */
+#define INT2_vect_num 9
+#define INT2_vect _VECTOR(9) /* External Interrupt Request 2 */
+#define INT3_vect_num 10
+#define INT3_vect _VECTOR(10) /* External Interrupt Request 3 */
+#define TIMER1_CAPT_vect_num 11
+#define TIMER1_CAPT_vect _VECTOR(11) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 12
+#define TIMER1_COMPA_vect _VECTOR(12) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 13
+#define TIMER1_COMPB_vect _VECTOR(13) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 14
+#define TIMER1_OVF_vect _VECTOR(14) /* Timer1/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 15
+#define TIMER0_COMPA_vect _VECTOR(15) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 16
+#define TIMER0_COMPB_vect _VECTOR(16) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 17
+#define TIMER0_OVF_vect _VECTOR(17) /* Timer/Counter0 Overflow */
+#define CAN_INT_vect_num 18
+#define CAN_INT_vect _VECTOR(18) /* CAN MOB, Burst, General Errors */
+#define CAN_TOVF_vect_num 19
+#define CAN_TOVF_vect _VECTOR(19) /* CAN Timer Overflow */
+#define LIN_TC_vect_num 20
+#define LIN_TC_vect _VECTOR(20) /* LIN Transfer Complete */
+#define LIN_ERR_vect_num 21
+#define LIN_ERR_vect _VECTOR(21) /* LIN Error */
+#define PCINT0_vect_num 22
+#define PCINT0_vect _VECTOR(22) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 23
+#define PCINT1_vect _VECTOR(23) /* Pin Change Interrupt Request 1 */
+#define PCINT2_vect_num 24
+#define PCINT2_vect _VECTOR(24) /* Pin Change Interrupt Request 2 */
+#define PCINT3_vect_num 25
+#define PCINT3_vect _VECTOR(25) /* Pin Change Interrupt Request 3 */
+#define SPI_STC_vect_num 26
+#define SPI_STC_vect _VECTOR(26) /* SPI Serial Transfer Complete */
+#define ADC_vect_num 27
+#define ADC_vect _VECTOR(27) /* ADC Conversion Complete */
+#define WDT_vect_num 28
+#define WDT_vect _VECTOR(28) /* Watchdog Time-Out Interrupt */
+#define EE_READY_vect_num 29
+#define EE_READY_vect _VECTOR(29) /* EEPROM Ready */
+#define SPM_READY_vect_num 30
+#define SPM_READY_vect _VECTOR(30) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (31 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (256)
+#define RAMSTART (0x0100)
+#define RAMSIZE (4096)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (0x0)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7FF)
+#define E2PAGESIZE (8)
+#define FLASHEND (0xFFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator output option */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset Disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector Trigger Level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector Trigger Level */
+#define FUSE_PSCRVB (unsigned char)~_BV(3) /* PSC Outputs xB Reset Value */
+#define FUSE_PSCRVA (unsigned char)~_BV(4) /* PSC Outputs xA Reset Value */
+#define FUSE_PSCRB (unsigned char)~_BV(5) /* PSC Reset Behavior */
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_BODLEVEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x84
+
+
+#endif /* _AVR_ATmega64M1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom8.h b/cpukit/score/cpu/avr/avr/iom8.h
new file mode 100644
index 0000000000..632598b6c9
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom8.h
@@ -0,0 +1,614 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom8.h - definitions for ATmega8 */
+
+#ifndef _AVR_IOM8_H_
+#define _AVR_IOM8_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom8.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* TWI stands for "Two Wire Interface" or "TWI Was I2C(tm)" */
+#define TWBR _SFR_IO8(0x00)
+#define TWSR _SFR_IO8(0x01)
+#define TWAR _SFR_IO8(0x02)
+#define TWDR _SFR_IO8(0x03)
+
+/* ADC */
+#define ADCW _SFR_IO16(0x04)
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+#define ADCSR _SFR_IO8(0x06)
+#define ADCSRA _SFR_IO8(0x06) /* Changed in 2486H-AVR-09/02 */
+#define ADMUX _SFR_IO8(0x07)
+
+/* analog comparator */
+#define ACSR _SFR_IO8(0x08)
+
+/* USART */
+#define UBRRL _SFR_IO8(0x09)
+#define UCSRB _SFR_IO8(0x0A)
+#define UCSRA _SFR_IO8(0x0B)
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI */
+#define SPCR _SFR_IO8(0x0D)
+#define SPSR _SFR_IO8(0x0E)
+#define SPDR _SFR_IO8(0x0F)
+
+/* Port D */
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* Port C */
+#define PINC _SFR_IO8(0x13)
+#define DDRC _SFR_IO8(0x14)
+#define PORTC _SFR_IO8(0x15)
+
+/* Port B */
+#define PINB _SFR_IO8(0x16)
+#define DDRB _SFR_IO8(0x17)
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define UCSRC _SFR_IO8(0x20)
+#define UBRRH _SFR_IO8(0x20)
+
+#define WDTCR _SFR_IO8(0x21)
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer 2 */
+#define OCR2 _SFR_IO8(0x23)
+#define TCNT2 _SFR_IO8(0x24)
+#define TCCR2 _SFR_IO8(0x25)
+
+/* Timer 1 */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCCR1B _SFR_IO8(0x2E)
+#define TCCR1A _SFR_IO8(0x2F)
+
+#define SFIOR _SFR_IO8(0x30)
+
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer 0 */
+#define TCNT0 _SFR_IO8(0x32)
+#define TCCR0 _SFR_IO8(0x33)
+
+#define MCUCSR _SFR_IO8(0x34)
+#define MCUSR _SFR_IO8(0x34) /* Defined as an alias for MCUCSR. */
+
+#define MCUCR _SFR_IO8(0x35)
+
+#define TWCR _SFR_IO8(0x36)
+
+#define SPMCR _SFR_IO8(0x37)
+
+#define TIFR _SFR_IO8(0x38)
+#define TIMSK _SFR_IO8(0x39)
+
+#define GIFR _SFR_IO8(0x3A)
+#define GIMSK _SFR_IO8(0x3B)
+#define GICR _SFR_IO8(0x3B) /* Changed in 2486H-AVR-09/02 */
+
+/* 0x3C reserved (OCR0?) */
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(3)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW2 _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW0 _VECTOR(9)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(10)
+#define SIG_SPI _VECTOR(10)
+
+/* USART, Rx Complete */
+#define USART_RXC_vect _VECTOR(11)
+#define SIG_UART_RECV _VECTOR(11)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(12)
+#define SIG_UART_DATA _VECTOR(12)
+
+/* USART, Tx Complete */
+#define USART_TXC_vect _VECTOR(13)
+#define SIG_UART_TRANS _VECTOR(13)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(14)
+#define SIG_ADC _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(16)
+#define SIG_COMPARATOR _VECTOR(16)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(17)
+#define SIG_2WIRE_SERIAL _VECTOR(17)
+
+/* Store Program Memory Ready */
+#define SPM_RDY_vect _VECTOR(18)
+#define SIG_SPM_READY _VECTOR(18)
+
+#define _VECTORS_SIZE 38
+
+/* Bit numbers */
+
+/* GIMSK / GICR */
+#define INT1 7
+#define INT0 6
+#define IVSEL 1
+#define IVCE 0
+
+/* GIFR */
+#define INTF1 7
+#define INTF0 6
+
+/* TIMSK */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+/* bit 1 reserved (OCIE0?) */
+#define TOIE0 0
+
+/* TIFR */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+/* bit 1 reserved (OCF0?) */
+#define TOV0 0
+
+/* SPMCR */
+#define SPMIE 7
+#define RWWSB 6
+/* bit 5 reserved */
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+/* bit 1 reserved (TWI_TST?) */
+#define TWIE 0
+
+/* TWAR */
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+/* TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+/* bit 2 reserved */
+#define TWPS1 1
+#define TWPS0 0
+
+/* MCUCR */
+#define SE 7
+#define SM2 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* MCUCSR */
+/* bits 7-4 reserved */
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/*
+ The ADHSM bit has been removed from all documentation,
+ as being not needed at all since the comparator has proven
+ to be fast enough even without feeding it more power.
+*/
+
+/* SFIOR */
+/* bits 7-5 reserved */
+#define ACME 3
+#define PUD 2
+#define PSR2 1
+#define PSR10 0
+
+/* TCCR0 */
+/* bits 7-3 reserved */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR2 */
+#define FOC2 7
+#define WGM20 6
+#define COM21 5
+#define COM20 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* ASSR */
+/* bits 7-4 reserved */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define WGM11 1
+#define WGM10 0
+
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+/* bit 5 reserved */
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* WDTCR */
+/* bits 7-5 reserved */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* UBRRH */
+#define URSEL 7
+
+/* UCSRC */
+#define URSEL 7
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* PORTC */
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* DDRC */
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* PINC */
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* UCSRA */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define PE 2
+#define U2X 1
+#define MPCM 0
+
+/* UCSRB */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define RXB8 1
+#define TXB8 0
+
+/* ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADCSR / ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+/* bit 4 reserved */
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x45F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_WDTON (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOM8_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom8515.h b/cpukit/score/cpu/avr/avr/iom8515.h
new file mode 100644
index 0000000000..66d6601983
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom8515.h
@@ -0,0 +1,636 @@
+/* Copyright (c) 2002, Steinar Haugen
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom8515.h - definitions for ATmega8515 */
+
+#ifndef _AVR_IOM8515_H_
+#define _AVR_IOM8515_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom8515.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_IO8(0x04)
+
+/* Input Pins, Port E */
+#define PINE _SFR_IO8(0x05)
+
+/* Data Direction Register, Port E */
+#define DDRE _SFR_IO8(0x06)
+
+/* Data Register, Port E */
+#define PORTE _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* USART Baud Rate Register */
+#define UBRRL _SFR_IO8(0x09)
+
+/* USART Control and Status Register B */
+#define UCSRB _SFR_IO8(0x0A)
+
+/* USART Control and Status Register A */
+#define UCSRA _SFR_IO8(0x0B)
+
+/* USART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* USART Baud Rate Register HI */
+/* USART Control and Status Register C */
+#define UBRRH _SFR_IO8(0x20)
+#define UCSRC UBRRH
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Special Function IO Register */
+#define SFIOR _SFR_IO8(0x30)
+
+/* Timer/Counter 0 Output Compare Register */
+#define OCR0 _SFR_IO8(0x31)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Control and Status Register */
+#define MCUCSR _SFR_IO8(0x34)
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Extended MCU Control Register */
+#define EMCUCR _SFR_IO8(0x36)
+
+/* Store Program Memory Control Register */
+#define SPMCR _SFR_IO8(0x37)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt Control Register */
+#define GICR _SFR_IO8(0x3B)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+
+/* Timer/Counter1 Compare MatchB */
+#define TIMER1_COMPB_vect _VECTOR(5)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(5)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW1 _VECTOR(6)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(7)
+#define SIG_OVERFLOW0 _VECTOR(7)
+
+/* Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(8)
+#define SIG_SPI _VECTOR(8)
+
+/* UART, Rx Complete */
+#define USART_RX_vect _VECTOR(9)
+#define UART_RX_vect _VECTOR(9) /* For compatability only */
+#define SIG_UART_RECV _VECTOR(9) /* For compatability only */
+
+/* UART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(10)
+#define UART_UDRE_vect _VECTOR(10) /* For compatability only */
+#define SIG_UART_DATA _VECTOR(10) /* For compatability only */
+
+/* UART, Tx Complete */
+#define USART_TX_vect _VECTOR(11)
+#define UART_TX_vect _VECTOR(11) /* For compatability only */
+#define SIG_UART_TRANS _VECTOR(11) /* For compatability only */
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(12)
+#define SIG_COMPARATOR _VECTOR(12)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(13)
+#define SIG_INTERRUPT2 _VECTOR(13)
+
+/* Timer 0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Store Program Memory Ready */
+#define SPM_RDY_vect _VECTOR(16)
+#define SIG_SPM_READY _VECTOR(16)
+
+#define _VECTORS_SIZE 34
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* General Interrupt Control Register */
+#define INT1 7
+#define INT0 6
+#define INT2 5
+#define IVSEL 1
+#define IVCE 0
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+#define INTF2 5
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define TICIE1 3
+#define TOIE0 1
+#define OCIE0 0
+
+/* Timer/Counter Interrupt Flag Register */
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define ICF1 3
+#define TOV0 1
+#define OCF0 0
+
+/* Store Program Memory Control Register */
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Extended MCU Control Register */
+#define SM0 7
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW01 3
+#define SRW00 2
+#define SRW11 1
+#define ISC2 0
+
+/* MCU Control Register */
+#define SRE 7
+#define SRW10 6
+#define SE 5
+#define SM1 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* MCU Control and Status Register */
+#define SM2 5
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* Timer/Counter 0 Control Register */
+#define FOC0 7
+#define WGM00 6
+#define COM01 5
+#define COM00 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Special Function IO Register */
+#define XMBK 6
+#define XMM2 5
+#define XMM1 4
+#define XMM0 3
+#define PUD 2
+#define PSR10 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define WGM11 1
+#define WGM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Watchdog Timer Control Register */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* USART Control and Status Register C */
+#define URSEL 7
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* USART Control and Status Register A */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define PE 2
+#define U2X 1
+#define MPCM 0
+
+/* USART Control and Status Register B */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* Data Register, Port E */
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+/* Data Direction Register, Port E */
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+/* Input Pins, Port E */
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x25F /* Last On-Chip SRAM Location */
+#define XRAMEND 0xFFFF
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_WDTON (unsigned char)~_BV(6)
+#define FUSE_S8515C (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOM8515_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom8535.h b/cpukit/score/cpu/avr/avr/iom8535.h
new file mode 100644
index 0000000000..f92a3eba26
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom8535.h
@@ -0,0 +1,715 @@
+/* Copyright (c) 2002, Steinar Haugen
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom8535.h - definitions for ATmega8535 */
+
+#ifndef _AVR_IOM8535_H_
+#define _AVR_IOM8535_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom8535.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* TWI stands for "Two Wire Interface" or "TWI Was I2C(tm)" */
+#define TWBR _SFR_IO8(0x00)
+#define TWSR _SFR_IO8(0x01)
+#define TWAR _SFR_IO8(0x02)
+#define TWDR _SFR_IO8(0x03)
+
+/* ADC Data register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register */
+#define ADCSRA _SFR_IO8(0x06)
+
+/* ADC MUX */
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* USART Baud Rate Register */
+#define UBRRL _SFR_IO8(0x09)
+
+/* USART Control and Status Register B */
+#define UCSRB _SFR_IO8(0x0A)
+
+/* USART Control and Status Register A */
+#define UCSRA _SFR_IO8(0x0B)
+
+/* USART I/O Data Register */
+#define UDR _SFR_IO8(0x0C)
+
+/* SPI Control Register */
+#define SPCR _SFR_IO8(0x0D)
+
+/* SPI Status Register */
+#define SPSR _SFR_IO8(0x0E)
+
+/* SPI I/O Data Register */
+#define SPDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D */
+#define PIND _SFR_IO8(0x10)
+
+/* Data Direction Register, Port D */
+#define DDRD _SFR_IO8(0x11)
+
+/* Data Register, Port D */
+#define PORTD _SFR_IO8(0x12)
+
+/* Input Pins, Port C */
+#define PINC _SFR_IO8(0x13)
+
+/* Data Direction Register, Port C */
+#define DDRC _SFR_IO8(0x14)
+
+/* Data Register, Port C */
+#define PORTC _SFR_IO8(0x15)
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* Input Pins, Port A */
+#define PINA _SFR_IO8(0x19)
+
+/* Data Direction Register, Port A */
+#define DDRA _SFR_IO8(0x1A)
+
+/* Data Register, Port A */
+#define PORTA _SFR_IO8(0x1B)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+/* USART Baud Rate Register HI */
+/* USART Control and Status Register C */
+#define UBRRH _SFR_IO8(0x20)
+#define UCSRC UBRRH
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Asynchronous mode Status Register */
+#define ASSR _SFR_IO8(0x22)
+
+/* Timer/Counter2 Output Compare Register */
+#define OCR2 _SFR_IO8(0x23)
+
+/* Timer/Counter 2 */
+#define TCNT2 _SFR_IO8(0x24)
+
+/* Timer/Counter 2 Control Register */
+#define TCCR2 _SFR_IO8(0x25)
+
+/* T/C 1 Input Capture Register */
+#define ICR1 _SFR_IO16(0x26)
+#define ICR1L _SFR_IO8(0x26)
+#define ICR1H _SFR_IO8(0x27)
+
+/* Timer/Counter1 Output Compare Register B */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Timer/Counter1 Output Compare Register A */
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* Timer/Counter 1 Control and Status Register */
+#define TCCR1B _SFR_IO8(0x2E)
+
+/* Timer/Counter 1 Control Register */
+#define TCCR1A _SFR_IO8(0x2F)
+
+/* Special Function IO Register */
+#define SFIOR _SFR_IO8(0x30)
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Control and Status Register */
+#define MCUCSR _SFR_IO8(0x34)
+
+/* MCU Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* TWI Control Register */
+#define TWCR _SFR_IO8(0x36)
+
+/* Store Program Memory Control Register */
+#define SPMCR _SFR_IO8(0x37)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GICR _SFR_IO8(0x3B)
+
+/* Timer/Counter 0 Output Compare Register */
+#define OCR0 _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Timer/Counter2 Compare Match */
+#define TIMER2_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE2 _VECTOR(3)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW2 _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW0 _VECTOR(9)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(10)
+#define SIG_SPI _VECTOR(10)
+
+/* USART, RX Complete */
+#define USART_RX_vect _VECTOR(11)
+#define SIG_UART_RECV _VECTOR(11)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(12)
+#define SIG_UART_DATA _VECTOR(12)
+
+/* USART, TX Complete */
+#define USART_TX_vect _VECTOR(13)
+#define SIG_UART_TRANS _VECTOR(13)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(14)
+#define SIG_ADC _VECTOR(14)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(15)
+#define SIG_EEPROM_READY _VECTOR(15)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(16)
+#define SIG_COMPARATOR _VECTOR(16)
+
+/* Two-wire Serial Interface */
+#define TWI_vect _VECTOR(17)
+#define SIG_2WIRE_SERIAL _VECTOR(17)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(18)
+#define SIG_INTERRUPT2 _VECTOR(18)
+
+/* TimerCounter0 Compare Match */
+#define TIMER0_COMP_vect _VECTOR(19)
+#define SIG_OUTPUT_COMPARE0 _VECTOR(19)
+
+/* Store Program Memory Read */
+#define SPM_RDY_vect _VECTOR(20)
+#define SIG_SPM_READY _VECTOR(20)
+
+#define _VECTORS_SIZE 42
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+*/
+
+/* General Interrupt Control Register */
+#define INT1 7
+#define INT0 6
+#define INT2 5
+#define IVSEL 1
+#define IVCE 0
+
+/* General Interrupt Flag Register */
+#define INTF1 7
+#define INTF0 6
+#define INTF2 5
+
+/* Timer/Counter Interrupt MaSK register */
+#define OCIE2 7
+#define TOIE2 6
+#define TICIE1 5
+#define OCIE1A 4
+#define OCIE1B 3
+#define TOIE1 2
+#define OCIE0 1
+#define TOIE0 0
+
+/* Timer/Counter Interrupt Flag register */
+#define OCF2 7
+#define TOV2 6
+#define ICF1 5
+#define OCF1A 4
+#define OCF1B 3
+#define TOV1 2
+#define OCF0 1
+#define TOV0 0
+
+/* Store Program Memory Control Register */
+#define SPMIE 7
+#define RWWSB 6
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* TWI Control Register */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+/* MCU Control Register */
+#define SM2 7
+#define SE 6
+#define SM1 5
+#define SM0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* MCU Control and Status Register */
+#define ISC2 6
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* Timer/Counter 0 Control Register */
+#define FOC0 7
+#define WGM00 6
+#define COM01 5
+#define COM00 4
+#define WGM01 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/*
+ The ADHSM bit has been removed from all documentation,
+ as being not needed at all since the comparator has proven
+ to be fast enough even without feeding it more power.
+*/
+
+/* Special Function IO Register */
+#define ADTS2 7
+#define ADTS1 6
+#define ADTS0 5
+#define ACME 3
+#define PUD 2
+#define PSR2 1
+#define PSR10 0
+
+/* Timer/Counter 1 Control Register */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1A 3
+#define FOC1B 2
+#define WGM11 1
+#define WGM10 0
+
+/* Timer/Counter 1 Control and Status Register */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Timer/Counter 2 Control Register */
+#define FOC2 7
+#define WGM20 6
+#define COM21 5
+#define COM20 4
+#define WGM21 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+/* Asynchronous mode Status Register */
+#define AS2 3
+#define TCN2UB 2
+#define OCR2UB 1
+#define TCR2UB 0
+
+/* Watchdog Timer Control Register */
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* USART Control and Status Register C */
+#define URSEL 7
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* Data Register, Port A */
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* Data Direction Register, Port A */
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+/* Input Pins, Port A */
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Data Register, Port B */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Register, Port C */
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Data Direction Register, Port C */
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+/* Input Pins, Port C */
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+/* Data Register, Port D */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Data Direction Register, Port D */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Input Pins, Port D */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* SPI Status Register */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+/* SPI Control Register */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+/* USART Control and Status Register A */
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define PE 2
+#define U2X 1
+#define MPCM 0
+
+/* USART Control and Status Register B */
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define RXB8 1
+#define TXB8 0
+
+/* Analog Comparator Control and Status Register */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADC Multiplexer Selection Register */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADC Control and Status Register */
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* TWI (Slave) Address Register */
+#define TWGCE 0
+
+/* TWI Status Register */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x25F /* Last On-Chip SRAM Location */
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_CKOPT (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_WDTON (unsigned char)~_BV(6)
+#define FUSE_S8535C (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x08
+
+
+#endif /* _AVR_IOM8535_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom88.h b/cpukit/score/cpu/avr/avr/iom88.h
new file mode 100644
index 0000000000..712434f973
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom88.h
@@ -0,0 +1,91 @@
+/* Copyright (c) 2004, Theodore A. Roth
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_IOM88_H_
+#define _AVR_IOM88_H_ 1
+
+#include <avr/iomx8.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x4FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0A
+
+
+#endif /* _AVR_IOM88_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom88p.h b/cpukit/score/cpu/avr/avr/iom88p.h
new file mode 100644
index 0000000000..88210f2430
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom88p.h
@@ -0,0 +1,874 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iom88p.h - definitions for ATmega88P. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom88p.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOM88P_H_
+#define _AVR_IOM88P_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define EEPROM_REG_LOCATIONS 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2_0 0
+#define OCR2_1 1
+#define OCR2_2 2
+#define OCR2_3 3
+#define OCR2_4 4
+#define OCR2_5 5
+#define OCR2_6 6
+#define OCR2_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 0
+#define TWAM1 1
+#define TWAM2 2
+#define TWAM3 3
+#define TWAM4 4
+#define TWAM5 5
+#define TWAM6 6
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCPHA0 1
+#define UCSZ01 2
+#define UDORD0 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0_0 0
+#define UBRR0_1 1
+#define UBRR0_2 2
+#define UBRR0_3 3
+#define UBRR0_4 4
+#define UBRR0_5 5
+#define UBRR0_6 6
+#define UBRR0_7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR0_8 0
+#define UBRR0_9 1
+#define UBRR0_10 2
+#define UBRR0_11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
+#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
+#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
+#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
+#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
+#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
+#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
+#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
+#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
+#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
+#define SPM_READY_vect _VECTOR(25) /* Store Program Memory Read */
+
+#define _VECTORS_SIZE (26 * 2)
+
+
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x4FF /* Last On-Chip SRAM Location */
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define EFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0F
+
+
+#endif /* _AVR_IOM88P_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iom88pa.h b/cpukit/score/cpu/avr/avr/iom88pa.h
new file mode 100644
index 0000000000..476e0ddec7
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom88pa.h
@@ -0,0 +1,1167 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom88pa.h - definitions for ATmega88PA */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom88pa.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega88PA_H_
+#define _AVR_ATmega88PA_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIFR2 _SFR_IO8(0x17)
+#define TOV2 0
+#define OCF2A 1
+#define OCF2B 2
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define PSRASY 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define RWWSB 6
+#define SPMIE 7
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSART0 1
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTIM2 6
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define TOIE2 0
+#define OCIE2A 1
+#define OCIE2B 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define WGM20 0
+#define WGM21 1
+#define COM2B0 4
+#define COM2B1 5
+#define COM2A0 6
+#define COM2A1 7
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define CS20 0
+#define CS21 1
+#define CS22 2
+#define WGM22 3
+#define FOC2B 6
+#define FOC2A 7
+
+#define TCNT2 _SFR_MEM8(0xB2)
+#define TCNT2_0 0
+#define TCNT2_1 1
+#define TCNT2_2 2
+#define TCNT2_3 3
+#define TCNT2_4 4
+#define TCNT2_5 5
+#define TCNT2_6 6
+#define TCNT2_7 7
+
+#define OCR2A _SFR_MEM8(0xB3)
+#define OCR2A_0 0
+#define OCR2A_1 1
+#define OCR2A_2 2
+#define OCR2A_3 3
+#define OCR2A_4 4
+#define OCR2A_5 5
+#define OCR2A_6 6
+#define OCR2A_7 7
+
+#define OCR2B _SFR_MEM8(0xB4)
+#define OCR2B_0 0
+#define OCR2B_1 1
+#define OCR2B_2 2
+#define OCR2B_3 3
+#define OCR2B_4 4
+#define OCR2B_5 5
+#define OCR2B_6 6
+#define OCR2B_7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR2BUB 0
+#define TCR2AUB 1
+#define OCR2BUB 2
+#define OCR2AUB 3
+#define TCN2UB 4
+#define AS2 5
+#define EXCLK 6
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define MPCM0 0
+#define U2X0 1
+#define UPE0 2
+#define DOR0 3
+#define FE0 4
+#define UDRE0 5
+#define TXC0 6
+#define RXC0 7
+
+#define UCSR0B _SFR_MEM8(0xC1)
+#define TXB80 0
+#define RXB80 1
+#define UCSZ02 2
+#define TXEN0 3
+#define RXEN0 4
+#define UDRIE0 5
+#define TXCIE0 6
+#define RXCIE0 7
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UCPOL0 0
+#define UCSZ00 1
+#define UCSZ01 2
+#define USBS0 3
+#define UPM00 4
+#define UPM01 5
+#define UMSEL00 6
+#define UMSEL01 7
+
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define _UBRR0 0
+#define _UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UBRR0H _SFR_MEM8(0xC5)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UDR0 _SFR_MEM8(0xC6)
+#define UDR0_0 0
+#define UDR0_1 1
+#define UDR0_2 2
+#define UDR0_3 3
+#define UDR0_4 4
+#define UDR0_5 5
+#define UDR0_6 6
+#define UDR0_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect_num 3
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 4
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
+#define PCINT2_vect_num 5
+#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
+#define WDT_vect_num 6
+#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
+#define TIMER2_COMPA_vect_num 7
+#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect_num 8
+#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
+#define TIMER2_OVF_vect_num 9
+#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
+#define TIMER1_CAPT_vect_num 10
+#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 11
+#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPB_vect_num 12
+#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
+#define TIMER1_OVF_vect_num 13
+#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 14
+#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 15
+#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
+#define TIMER0_OVF_vect_num 16
+#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
+#define SPI_STC_vect_num 17
+#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
+#define USART_RX_vect_num 18
+#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
+#define USART_UDRE_vect_num 19
+#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
+#define USART_TX_vect_num 20
+#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
+#define ADC_vect_num 21
+#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
+#define EE_READY_vect_num 22
+#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
+#define ANALOG_COMP_vect_num 23
+#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
+#define TWI_vect_num 24
+#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
+#define SPM_Ready_vect_num 25
+#define SPM_Ready_vect _VECTOR(25) /* Store Program Memory Read */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (26 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x100)
+#define RAMSIZE (1024)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x1FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select reset vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select boot size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select boot size */
+#define EFUSE_DEFAULT (FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0F
+
+
+/* Device Pin Definitions */
+#define PCINT19_DDR DDRD
+#define PCINT19_PORT PORTD
+#define PCINT19_PIN PIND
+#define PCINT19_BIT 3
+
+#define OC2B_DDR DDRD
+#define OC2B_PORT PORTD
+#define OC2B_PIN PIND
+#define OC2B_BIT 3
+
+#define INT1_DDR DDRD
+#define INT1_PORT PORTD
+#define INT1_PIN PIND
+#define INT1_BIT 3
+
+#define XCK_DDR DDRD
+#define XCK_PORT PORTD
+#define XCK_PIN PIND
+#define XCK_BIT 4
+
+#define T0_DDR DDRD
+#define T0_PORT PORTD
+#define T0_PIN PIND
+#define T0_BIT 4
+
+#define PCINT20_DDR DDRD
+#define PCINT20_PORT PORTD
+#define PCINT20_PIN PIND
+#define PCINT20_BIT 4
+
+#define PCINT6_DDR DDRB
+#define PCINT6_PORT PORTB
+#define PCINT6_PIN PINB
+#define PCINT6_BIT 6
+
+#define PCINT7_DDR DDRB
+#define PCINT7_PORT PORTB
+#define PCINT7_PIN PINB
+#define PCINT7_BIT 7
+
+#define T1_DDR DDRD
+#define T1_PORT PORTD
+#define T1_PIN PIND
+#define T1_BIT 5
+
+#define OC0B_DDR DDRD
+#define OC0B_PORT PORTD
+#define OC0B_PIN PIND
+#define OC0B_BIT 5
+
+#define PCINT21_DDR DDRD
+#define PCINT21_PORT PORTD
+#define PCINT21_PIN PIND
+#define PCINT21_BIT 5
+
+#define AIN0_DDR DDRD
+#define AIN0_PORT PORTD
+#define AIN0_PIN PIND
+#define AIN0_BIT 6
+
+#define OC0A_DDR DDRD
+#define OC0A_PORT PORTD
+#define OC0A_PIN PIND
+#define OC0A_BIT 6
+
+#define PCINT22_DDR DDRD
+#define PCINT22_PORT PORTD
+#define PCINT22_PIN PIND
+#define PCINT22_BIT 6
+
+#define AIN1_DDR DDRD
+#define AIN1_PORT PORTD
+#define AIN1_PIN PIND
+#define AIN1_BIT 7
+
+#define PCINT23_DDR DDRD
+#define PCINT23_PORT PORTD
+#define PCINT23_PIN PIND
+#define PCINT23_BIT 7
+
+#define ICP1_DDR DDRB
+#define ICP1_PORT PORTB
+#define ICP1_PIN PINB
+#define ICP1_BIT 0
+
+#define CLKO_DDR DDRB
+#define CLKO_PORT PORTB
+#define CLKO_PIN PINB
+#define CLKO_BIT 0
+
+#define PCINT0_DDR DDRB
+#define PCINT0_PORT PORTB
+#define PCINT0_PIN PINB
+#define PCINT0_BIT 0
+
+#define OC1A_DDR DDRB
+#define OC1A_PORT PORTB
+#define OC1A_PIN PINB
+#define OC1A_BIT 1
+
+#define PCINT1_DDR DDRB
+#define PCINT1_PORT PORTB
+#define PCINT1_PIN PINB
+#define PCINT1_BIT 1
+
+#define SS_DDR DDRB
+#define SS_PORT PORTB
+#define SS_PIN PINB
+#define SS_BIT 2
+
+#define OC1B_DDR DDRB
+#define OC1B_PORT PORTB
+#define OC1B_PIN PINB
+#define OC1B_BIT 2
+
+#define PCINT2_DDR DDRB
+#define PCINT2_PORT PORTB
+#define PCINT2_PIN PINB
+#define PCINT2_BIT 2
+
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 3
+
+#define OC2A_DDR DDRB
+#define OC2A_PORT PORTB
+#define OC2A_PIN PINB
+#define OC2A_BIT 3
+
+#define PCINT3_DDR DDRB
+#define PCINT3_PORT PORTB
+#define PCINT3_PIN PINB
+#define PCINT3_BIT 3
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 4
+
+#define PCINT4_DDR DDRB
+#define PCINT4_PORT PORTB
+#define PCINT4_PIN PINB
+#define PCINT4_BIT 4
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 5
+
+#define PCINT5_DDR DDRB
+#define PCINT5_PORT PORTB
+#define PCINT5_PIN PINB
+#define PCINT5_BIT 5
+
+#define ADC6_DDR DDRADC
+#define ADC6_PORT PORTADC
+#define ADC6_PIN PINADC
+#define ADC6_BIT ADC6
+
+#define ADC7_DDR DDRADC
+#define ADC7_PORT PORTADC
+#define ADC7_PIN PINADC
+#define ADC7_BIT ADC7
+
+#define ADC0_DDR DDRC
+#define ADC0_PORT PORTC
+#define ADC0_PIN PINC
+#define ADC0_BIT 0
+
+#define PCINT8_DDR DDRC
+#define PCINT8_PORT PORTC
+#define PCINT8_PIN PINC
+#define PCINT8_BIT 0
+
+#define ADC1_DDR DDRC
+#define ADC1_PORT PORTC
+#define ADC1_PIN PINC
+#define ADC1_BIT 1
+
+#define PCINT9_DDR DDRC
+#define PCINT9_PORT PORTC
+#define PCINT9_PIN PINC
+#define PCINT9_BIT 1
+
+#define ADC2_DDR DDRC
+#define ADC2_PORT PORTC
+#define ADC2_PIN PINC
+#define ADC2_BIT 2
+
+#define PCINT10_DDR DDRC
+#define PCINT10_PORT PORTC
+#define PCINT10_PIN PINC
+#define PCINT10_BIT 2
+
+#define ADC3_DDR DDRC
+#define ADC3_PORT PORTC
+#define ADC3_PIN PINC
+#define ADC3_BIT 3
+
+#define PCINT11_DDR DDRC
+#define PCINT11_PORT PORTC
+#define PCINT11_PIN PINC
+#define PCINT11_BIT 3
+
+#define ADC4_DDR DDRC
+#define ADC4_PORT PORTC
+#define ADC4_PIN PINC
+#define ADC4_BIT 4
+
+#define SDA_DDR DDRC
+#define SDA_PORT PORTC
+#define SDA_PIN PINC
+#define SDA_BIT 4
+
+#define PCINT12_DDR DDRC
+#define PCINT12_PORT PORTC
+#define PCINT12_PIN PINC
+#define PCINT12_BIT 4
+
+#define ADC5_DDR DDRC
+#define ADC5_PORT PORTC
+#define ADC5_PIN PINC
+#define ADC5_BIT 5
+
+#define SCL_DDR DDRC
+#define SCL_PORT PORTC
+#define SCL_PIN PINC
+#define SCL_BIT 5
+
+#define PCINT13_DDR DDRC
+#define PCINT13_PORT PORTC
+#define PCINT13_PIN PINC
+#define PCINT13_BIT 5
+
+#define PCINT14_DDR DDRC
+#define PCINT14_PORT PORTC
+#define PCINT14_PIN PINC
+#define PCINT14_BIT 6
+
+#define RXD_DDR DDRD
+#define RXD_PORT PORTD
+#define RXD_PIN PIND
+#define RXD_BIT 0
+
+#define PCINT16_DDR DDRD
+#define PCINT16_PORT PORTD
+#define PCINT16_PIN PIND
+#define PCINT16_BIT 0
+
+#define TXD_DDR DDRD
+#define TXD_PORT PORTD
+#define TXD_PIN PIND
+#define TXD_BIT 1
+
+#define PCINT17_DDR DDRD
+#define PCINT17_PORT PORTD
+#define PCINT17_PIN PIND
+#define PCINT17_BIT 1
+
+#define INT0_DDR DDRD
+#define INT0_PORT PORTD
+#define INT0_PIN PIND
+#define INT0_BIT 2
+
+#define PCINT18_DDR DDRD
+#define PCINT18_PORT PORTD
+#define PCINT18_PIN PIND
+#define PCINT18_BIT 2
+
+#endif /* _AVR_ATmega88PA_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom8hva.h b/cpukit/score/cpu/avr/avr/iom8hva.h
new file mode 100644
index 0000000000..ac323b038a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom8hva.h
@@ -0,0 +1,70 @@
+/* Copyright (c) 2007, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iom8hva.h - definitions for ATmega8HVA. */
+
+#ifndef _AVR_IOM8HVA_H_
+#define _AVR_IOM8HVA_H_ 1
+
+#include <avr/iomxxhva.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x2FF
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_SUT0 (unsigned char)~_BV(0)
+#define FUSE_SUT1 (unsigned char)~_BV(1)
+#define FUSE_SUT2 (unsigned char)~_BV(2)
+#define FUSE_SELFPRGEN (unsigned char)~_BV(3)
+#define FUSE_DWEN (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_EESAVE (unsigned char)~_BV(6)
+#define FUSE_WDTON (unsigned char)~_BV(7)
+#define FUSE_DEFAULT (FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+#endif /* _AVR_IOM8HVA_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iom8u2.h b/cpukit/score/cpu/avr/avr/iom8u2.h
new file mode 100644
index 0000000000..b6009a34d9
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iom8u2.h
@@ -0,0 +1,967 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iom8u2.h - definitions for ATmega8U2 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom8u2.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATmega8U2_H_
+#define _AVR_ATmega8U2_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define OCF1C 3
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+#define INTF2 2
+#define INTF3 3
+#define INTF4 4
+#define INTF5 5
+#define INTF6 6
+#define INTF7 7
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+#define INT2 2
+#define INT3 3
+#define INT4 4
+#define INT5 5
+#define INT6 6
+#define INT7 7
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+#define EEAR9 1
+#define EEAR10 2
+#define EEAR11 3
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x24)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PLLP0 2
+#define PLLP1 3
+#define PLLP2 4
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define DWDR _SFR_IO8(0x31)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+#define SM2 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+#define USBRF 5
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVCE 0
+#define IVSEL 1
+#define PUD 4
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define BLBSET 3
+#define RWWSRE 4
+#define SIGRD 5
+#define RWWSB 6
+#define SPMIE 7
+
+#define EIND _SFR_IO8(0x3C)
+#define EIND0 0
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define WDTCKD _SFR_MEM8(0x62)
+#define WCLKD0 0
+#define WCLKD1 1
+#define WDEWIE 2
+#define WDEWIF 3
+
+#define REGCR _SFR_MEM8(0x63)
+#define REGDIS 0
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSART1 0
+#define PRUSB 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define ISC20 4
+#define ISC21 5
+#define ISC30 6
+#define ISC31 7
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC40 0
+#define ISC41 1
+#define ISC50 2
+#define ISC51 3
+#define ISC60 4
+#define ISC61 5
+#define ISC70 6
+#define ISC71 7
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define OCIE1C 3
+#define ICIE1 5
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1C0 2
+#define COM1C1 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1C 5
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CL0 0
+#define OCR1CL1 1
+#define OCR1CL2 2
+#define OCR1CL3 3
+#define OCR1CL4 4
+#define OCR1CL5 5
+#define OCR1CL6 6
+#define OCR1CL7 7
+
+#define OCR1CH _SFR_MEM8(0x8D)
+#define OCR1CH0 0
+#define OCR1CH1 1
+#define OCR1CH2 2
+#define OCR1CH3 3
+#define OCR1CH4 4
+#define OCR1CH5 5
+#define OCR1CH6 6
+#define OCR1CH7 7
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define MPCM1 0
+#define U2X1 1
+#define UPE1 2
+#define DOR1 3
+#define FE1 4
+#define UDRE1 5
+#define TXC1 6
+#define RXC1 7
+
+#define UCSR1B _SFR_MEM8(0xC9)
+#define TXB81 0
+#define RXB81 1
+#define UCSZ12 2
+#define TXEN1 3
+#define RXEN1 4
+#define UDRIE1 5
+#define TXCIE1 6
+#define RXCIE1 7
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UCPOL1 0
+#define UCSZ10 1
+#define UCSZ11 2
+#define USBS1 3
+#define UPM10 4
+#define UPM11 5
+#define UMSEL10 6
+#define UMSEL11 7
+
+#define UCSR1D _SFR_MEM8(0xCB)
+#define RTSEN 0
+#define CTSEN 1
+
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1_0 0
+#define UBRR1_1 1
+#define UBRR1_2 2
+#define UBRR1_3 3
+#define UBRR1_4 4
+#define UBRR1_5 5
+#define UBRR1_6 6
+#define UBRR1_7 7
+
+#define UBRR1H _SFR_MEM8(0xCD)
+#define UBRR1_8 0
+#define UBRR1_9 1
+#define UBRR1_10 2
+#define UBRR1_11 3
+
+#define UDR1 _SFR_MEM8(0xCE)
+#define UDR1_0 0
+#define UDR1_1 1
+#define UDR1_2 2
+#define UDR1_3 3
+#define UDR1_4 4
+#define UDR1_5 5
+#define UDR1_6 6
+#define UDR1_7 7
+
+#define CLKSEL0 _SFR_MEM8(0xD0)
+#define CLKS 0
+#define EXTE 2
+#define RCE 3
+#define EXSUT0 4
+#define EXSUT1 5
+#define RCSUT0 6
+#define RCSUT1 7
+
+#define CLKSEL1 _SFR_MEM8(0xD1)
+#define EXCKSEL0 0
+#define EXCKSEL1 1
+#define EXCKSEL2 2
+#define EXCKSEL3 3
+#define RCCKSEL0 4
+#define RCCKSEL1 5
+#define RCCKSEL2 6
+#define RCCKSEL3 7
+
+#define CLKSTA _SFR_MEM8(0xD2)
+#define EXTON 0
+#define RCON 1
+
+#define USBCON _SFR_MEM8(0xD8)
+#define FRZCLK 5
+#define USBE 7
+
+#define UDCON _SFR_MEM8(0xE0)
+#define DETACH 0
+#define RMWKUP 1
+#define RSTCPU 2
+
+#define UDINT _SFR_MEM8(0xE1)
+#define SUSPI 0
+#define SOFI 2
+#define EORSTI 3
+#define WAKEUPI 4
+#define EORSMI 5
+#define UPRSMI 6
+
+#define UDIEN _SFR_MEM8(0xE2)
+#define SUSPE 0
+#define SOFE 2
+#define EORSTE 3
+#define WAKEUPE 4
+#define EORSME 5
+#define UPRSME 6
+
+#define UDADDR _SFR_MEM8(0xE3)
+#define UADD0 0
+#define UADD1 1
+#define UADD2 2
+#define UADD3 3
+#define UADD4 4
+#define UADD5 5
+#define UADD6 6
+#define ADDEN 7
+
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define FNUM0 0
+#define FNUM1 1
+#define FNUM2 2
+#define FNUM3 3
+#define FNUM4 4
+#define FNUM5 5
+#define FNUM6 6
+#define FNUM7 7
+
+#define UDFNUMH _SFR_MEM8(0xE5)
+#define FNUM8 0
+#define FNUM9 1
+#define FNUM10 2
+
+#define UDMFN _SFR_MEM8(0xE6)
+#define FNCERR 4
+
+#define UEINTX _SFR_MEM8(0xE8)
+#define TXINI 0
+#define STALLEDI 1
+#define RXOUTI 2
+#define RXSTPI 3
+#define NAKOUTI 4
+#define RWAL 5
+#define NAKINI 6
+#define FIFOCON 7
+
+#define UENUM _SFR_MEM8(0xE9)
+#define EPNUM0 0
+#define EPNUM1 1
+#define EPNUM2 2
+
+#define UERST _SFR_MEM8(0xEA)
+#define EPRST0 0
+#define EPRST1 1
+#define EPRST2 2
+#define EPRST3 3
+#define EPRST4 4
+
+#define UECONX _SFR_MEM8(0xEB)
+#define EPEN 0
+#define RSTDT 3
+#define STALLRQC 4
+#define STALLRQ 5
+
+#define UECFG0X _SFR_MEM8(0xEC)
+#define EPDIR 0
+#define EPTYPE0 6
+#define EPTYPE1 7
+
+#define UECFG1X _SFR_MEM8(0xED)
+#define ALLOC 1
+#define EPBK0 2
+#define EPBK1 3
+#define EPSIZE0 4
+#define EPSIZE1 5
+#define EPSIZE2 6
+
+#define UESTA0X _SFR_MEM8(0xEE)
+#define NBUSYBK0 0
+#define NBUSYBK1 1
+#define DTSEQ0 2
+#define DTSEQ1 3
+#define UNDERFI 5
+#define OVERFI 6
+#define CFGOK 7
+
+#define UESTA1X _SFR_MEM8(0xEF)
+#define CURRBK0 0
+#define CURRBK1 1
+#define CTRLDIR 2
+
+#define UEIENX _SFR_MEM8(0xF0)
+#define TXINE 0
+#define STALLEDE 1
+#define RXOUTE 2
+#define RXSTPE 3
+#define NAKOUTE 4
+#define NAKINE 6
+#define FLERRE 7
+
+#define UEDATX _SFR_MEM8(0xF1)
+#define DAT0 0
+#define DAT1 1
+#define DAT2 2
+#define DAT3 3
+#define DAT4 4
+#define DAT5 5
+#define DAT6 6
+#define DAT7 7
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define BYCT0 0
+#define BYCT1 1
+#define BYCT2 2
+#define BYCT3 3
+#define BYCT4 4
+#define BYCT5 5
+#define BYCT6 6
+#define BYCT7 7
+
+#define UEINT _SFR_MEM8(0xF4)
+#define EPINT0 0
+#define EPINT1 1
+#define EPINT2 2
+#define EPINT3 3
+#define EPINT4 4
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define INT2_vect_num 3
+#define INT2_vect _VECTOR(3) /* External Interrupt Request 2 */
+#define INT3_vect_num 4
+#define INT3_vect _VECTOR(4) /* External Interrupt Request 3 */
+#define INT4_vect_num 5
+#define INT4_vect _VECTOR(5) /* External Interrupt Request 4 */
+#define INT5_vect_num 6
+#define INT5_vect _VECTOR(6) /* External Interrupt Request 5 */
+#define INT6_vect_num 7
+#define INT6_vect _VECTOR(7) /* External Interrupt Request 6 */
+#define INT7_vect_num 8
+#define INT7_vect _VECTOR(8) /* External Interrupt Request 7 */
+#define PCINT0_vect_num 9
+#define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 10
+#define PCINT1_vect _VECTOR(10) /* Pin Change Interrupt Request 1 */
+#define USB_GEN_vect_num 11
+#define USB_GEN_vect _VECTOR(11) /* USB General Interrupt Request */
+#define USB_COM_vect_num 12
+#define USB_COM_vect _VECTOR(12) /* USB Endpoint/Pipe Interrupt Communication Request */
+#define WDT_vect_num 13
+#define WDT_vect _VECTOR(13) /* Watchdog Time-out Interrupt */
+#define TIMER1_CAPT_vect_num 14
+#define TIMER1_CAPT_vect _VECTOR(14) /* Timer/Counter2 Capture Event */
+#define TIMER1_COMPA_vect_num 15
+#define TIMER1_COMPA_vect _VECTOR(15) /* Timer/Counter2 Compare Match B */
+#define TIMER0_COMPA_vect_num 19
+#define TIMER0_COMPA_vect _VECTOR(19) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 20
+#define TIMER0_COMPB_vect _VECTOR(20) /* Timer/Counter0 Compare Match B */
+#define TIMER0_OVF_vect_num 21
+#define TIMER0_OVF_vect _VECTOR(21) /* Timer/Counter0 Overflow */
+#define SPI_STC_vect_num 22
+#define SPI_STC_vect _VECTOR(22) /* SPI Serial Transfer Complete */
+#define USART1_RX_vect_num 23
+#define USART1_RX_vect _VECTOR(23) /* USART1, Rx Complete */
+#define USART1_UDRE_vect_num 24
+#define USART1_UDRE_vect _VECTOR(24) /* USART1 Data register Empty */
+#define USART1_TX_vect_num 25
+#define USART1_TX_vect _VECTOR(25) /* USART1, Tx Complete */
+#define ANALOG_COMP_vect_num 26
+#define ANALOG_COMP_vect _VECTOR(26) /* Analog Comparator */
+#define EE_READY_vect_num 27
+#define EE_READY_vect _VECTOR(27) /* EEPROM Ready */
+#define SPM_READY_vect_num 28
+#define SPM_READY_vect _VECTOR(28) /* Store Program Memory Read */
+#define TIMER1_COMPB_vect_num 16
+#define TIMER1_COMPB_vect _VECTOR(16) /* Timer/Counter2 Compare Match B */
+#define TIMER1_COMPC_vect_num 17
+#define TIMER1_COMPC_vect _VECTOR(17) /* Timer/Counter2 Compare Match C */
+#define TIMER1_OVF_vect_num 18
+#define TIMER1_OVF_vect _VECTOR(18) /* Timer/Counter1 Overflow */
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (38 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x100)
+#define RAMSIZE (512)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x1FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Oscillator options */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT1 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL1)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0) /* Select Reset Vector */
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1) /* Select Boot Size */
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2) /* Select Boot Size */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_RSTDISBL (unsigned char)~_BV(6) /* External Reset Disable */
+#define FUSE_DWEN (unsigned char)~_BV(7) /* dwbugWIRE Enable */
+#define HFUSE_DEFAULT (FUSE_SPIEN & FUSE_BOOTSZ1 & FUSE_BOOTSZ0)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_HWBE (unsigned char)~_BV(3) /* Hardware Boot Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x89
+
+
+/* Device Pin Definitions */
+#endif /* _AVR_ATmega8U2_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iomx8.h b/cpukit/score/cpu/avr/avr/iomx8.h
new file mode 100644
index 0000000000..7e6baa04ef
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iomx8.h
@@ -0,0 +1,735 @@
+/* Copyright (c) 2004,2005, Theodore A. Roth
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iomx8.h - definitions for ATmega48, ATmega88 and ATmega168 */
+
+#ifndef _AVR_IOMX8_H_
+#define _AVR_IOMX8_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iomx8.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Port B */
+
+#define PINB _SFR_IO8 (0x03)
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8 (0x04)
+/* DDRB */
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8 (0x05)
+/* PORTB */
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Port C */
+
+#define PINC _SFR_IO8 (0x06)
+/* PINC */
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8 (0x07)
+/* DDRC */
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8 (0x08)
+/* PORTC */
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+/* Port D */
+
+#define PIND _SFR_IO8 (0x09)
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8 (0x0A)
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8 (0x0B)
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define TIFR0 _SFR_IO8 (0x15)
+/* TIFR0 */
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIFR1 _SFR_IO8 (0x16)
+/* TIFR1 */
+#define ICF1 5
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+#define TIFR2 _SFR_IO8 (0x17)
+/* TIFR2 */
+#define OCF2B 2
+#define OCF2A 1
+#define TOV2 0
+
+#define PCIFR _SFR_IO8 (0x1B)
+/* PCIFR */
+#define PCIF2 2
+#define PCIF1 1
+#define PCIF0 0
+
+#define EIFR _SFR_IO8 (0x1C)
+/* EIFR */
+#define INTF1 1
+#define INTF0 0
+
+#define EIMSK _SFR_IO8 (0x1D)
+/* EIMSK */
+#define INT1 1
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8 (0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+/* EECT - EEPROM Control Register */
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+/*
+Even though EEARH is not used by the mega48, the EEAR8 bit in the register
+must be written to 0, according to the datasheet, hence the EEARH register
+must be defined for the mega48.
+*/
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+
+#define GTCCR _SFR_IO8 (0x23)
+/* GTCCR */
+#define TSM 7
+#define PSRASY 1
+#define PSRSYNC 0
+
+#define TCCR0A _SFR_IO8 (0x24)
+/* TCCR0A */
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define TCCR0B _SFR_IO8 (0x25)
+/* TCCR0A */
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define TCNT0 _SFR_IO8 (0x26)
+#define OCR0A _SFR_IO8 (0x27)
+#define OCR0B _SFR_IO8 (0x28)
+
+#define GPIOR1 _SFR_IO8 (0x2A)
+#define GPIOR2 _SFR_IO8 (0x2B)
+
+#define SPCR _SFR_IO8 (0x2C)
+/* SPCR */
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+#define SPSR _SFR_IO8 (0x2D)
+/* SPSR */
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+#define SPDR _SFR_IO8 (0x2E)
+
+#define ACSR _SFR_IO8 (0x30)
+/* ACSR */
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+#define MONDR _SFR_IO8 (0x31)
+
+#define SMCR _SFR_IO8 (0x33)
+/* SMCR */
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+#define MCUSR _SFR_IO8 (0x34)
+/* MCUSR */
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8 (0x35)
+/* MCUCR */
+#define PUD 4
+#if defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__)
+#define IVSEL 1
+#define IVCE 0
+#endif
+
+#define SPMCSR _SFR_IO8 (0x37)
+/* SPMCSR */
+#define SPMIE 7
+#if defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__)
+# define RWWSB 6
+# define RWWSRE 4
+#endif
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SELFPRGEN 0
+#define SPMEN 0
+
+/* 0x3D..0x3E SP [defined in <avr/io.h>] */
+/* 0x3F SREG [defined in <avr/io.h>] */
+
+#define WDTCSR _SFR_MEM8 (0x60)
+/* WDTCSR */
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define CLKPR _SFR_MEM8 (0x61)
+/* CLKPR */
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+#define PRR _SFR_MEM8 (0x64)
+/* PRR */
+#define PRTWI 7
+#define PRTIM2 6
+#define PRTIM0 5
+#define PRTIM1 3
+#define PRSPI 2
+#define PRUSART0 1
+#define PRADC 0
+
+#define OSCCAL _SFR_MEM8 (0x66)
+
+#define PCICR _SFR_MEM8 (0x68)
+/* PCICR */
+#define PCIE2 2
+#define PCIE1 1
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8 (0x69)
+/* EICRA */
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+#define PCMSK0 _SFR_MEM8 (0x6B)
+/* PCMSK0 */
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define PCMSK1 _SFR_MEM8 (0x6C)
+/* PCMSK1 */
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+#define PCMSK2 _SFR_MEM8 (0x6D)
+/* PCMSK2 */
+#define PCINT23 7
+#define PCINT22 6
+#define PCINT21 5
+#define PCINT20 4
+#define PCINT19 3
+#define PCINT18 2
+#define PCINT17 1
+#define PCINT16 0
+
+#define TIMSK0 _SFR_MEM8 (0x6E)
+/* TIMSK0 */
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define TIMSK1 _SFR_MEM8 (0x6F)
+/* TIMSK1 */
+#define ICIE1 5
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+#define TIMSK2 _SFR_MEM8 (0x70)
+/* TIMSK2 */
+#define OCIE2B 2
+#define OCIE2A 1
+#define TOIE2 0
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16 (0x78)
+#endif
+#define ADCW _SFR_MEM16 (0x78)
+#define ADCL _SFR_MEM8 (0x78)
+#define ADCH _SFR_MEM8 (0x79)
+
+#define ADCSRA _SFR_MEM8 (0x7A)
+/* ADCSRA */
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+#define ADCSRB _SFR_MEM8 (0x7B)
+/* ADCSRB */
+#define ACME 6
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+#define ADMUX _SFR_MEM8 (0x7C)
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+#define DIDR0 _SFR_MEM8 (0x7E)
+/* DIDR0 */
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+#define DIDR1 _SFR_MEM8 (0x7F)
+/* DIDR1 */
+#define AIN1D 1
+#define AIN0D 0
+
+#define TCCR1A _SFR_MEM8 (0x80)
+/* TCCR1A */
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define WGM11 1
+#define WGM10 0
+
+#define TCCR1B _SFR_MEM8 (0x81)
+/* TCCR1B */
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define TCCR1C _SFR_MEM8 (0x82)
+/* TCCR1C */
+#define FOC1A 7
+#define FOC1B 6
+
+#define TCNT1 _SFR_MEM16 (0x84)
+#define TCNT1L _SFR_MEM8 (0x84)
+#define TCNT1H _SFR_MEM8 (0x85)
+
+#define ICR1 _SFR_MEM16 (0x86)
+#define ICR1L _SFR_MEM8 (0x86)
+#define ICR1H _SFR_MEM8 (0x87)
+
+#define OCR1A _SFR_MEM16 (0x88)
+#define OCR1AL _SFR_MEM8 (0x88)
+#define OCR1AH _SFR_MEM8 (0x89)
+
+#define OCR1B _SFR_MEM16 (0x8A)
+#define OCR1BL _SFR_MEM8 (0x8A)
+#define OCR1BH _SFR_MEM8 (0x8B)
+
+#define TCCR2A _SFR_MEM8 (0xB0)
+/* TCCR2A */
+#define COM2A1 7
+#define COM2A0 6
+#define COM2B1 5
+#define COM2B0 4
+#define WGM21 1
+#define WGM20 0
+
+#define TCCR2B _SFR_MEM8 (0xB1)
+/* TCCR2B */
+#define FOC2A 7
+#define FOC2B 6
+#define WGM22 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+#define TCNT2 _SFR_MEM8 (0xB2)
+#define OCR2A _SFR_MEM8 (0xB3)
+#define OCR2B _SFR_MEM8 (0xB4)
+
+#define ASSR _SFR_MEM8 (0xB6)
+/* ASSR */
+#define EXCLK 6
+#define AS2 5
+#define TCN2UB 4
+#define OCR2AUB 3
+#define OCR2BUB 2
+#define TCR2AUB 1
+#define TCR2BUB 0
+
+#define TWBR _SFR_MEM8 (0xB8)
+
+#define TWSR _SFR_MEM8 (0xB9)
+/* TWSR */
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+#define TWAR _SFR_MEM8 (0xBA)
+/* TWAR */
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+#define TWDR _SFR_MEM8 (0xBB)
+
+#define TWCR _SFR_MEM8 (0xBC)
+/* TWCR */
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+#define TWAMR _SFR_MEM8 (0xBD)
+/* TWAMR */
+#define TWAM6 7
+#define TWAM5 6
+#define TWAM4 5
+#define TWAM3 4
+#define TWAM2 3
+#define TWAM1 2
+#define TWAM0 1
+
+#define UCSR0A _SFR_MEM8 (0xC0)
+/* UCSR0A */
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+#define UCSR0B _SFR_MEM8 (0xC1)
+/* UCSR0B */
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+#define UCSR0C _SFR_MEM8 (0xC2)
+/* UCSR0C */
+#define UMSEL01 7
+#define UMSEL00 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UDORD0 2
+#define UCSZ00 1
+#define UCPHA0 1
+#define UCPOL0 0
+
+#define UBRR0 _SFR_MEM16 (0xC4)
+#define UBRR0L _SFR_MEM8 (0xC4)
+#define UBRR0H _SFR_MEM8 (0xC5)
+#define UDR0 _SFR_MEM8 (0xC6)
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(3)
+#define SIG_PIN_CHANGE0 _VECTOR(3)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(4)
+#define SIG_PIN_CHANGE1 _VECTOR(4)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT2_vect _VECTOR(5)
+#define SIG_PIN_CHANGE2 _VECTOR(5)
+
+/* Watchdog Time-out Interrupt */
+#define WDT_vect _VECTOR(6)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(6)
+
+/* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPA_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE2A _VECTOR(7)
+
+/* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPB_vect _VECTOR(8)
+#define SIG_OUTPUT_COMPARE2B _VECTOR(8)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(9)
+#define SIG_OVERFLOW2 _VECTOR(9)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(10)
+#define SIG_INPUT_CAPTURE1 _VECTOR(10)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(11)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(11)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(12)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(13)
+#define SIG_OVERFLOW1 _VECTOR(13)
+
+/* TimerCounter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(14)
+
+/* TimerCounter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(15)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(15)
+
+/* Timer/Couner0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(16)
+#define SIG_OVERFLOW0 _VECTOR(16)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(17)
+#define SIG_SPI _VECTOR(17)
+
+/* USART Rx Complete */
+#define USART_RX_vect _VECTOR(18)
+#define SIG_USART_RECV _VECTOR(18)
+
+/* USART, Data Register Empty */
+#define USART_UDRE_vect _VECTOR(19)
+#define SIG_USART_DATA _VECTOR(19)
+
+/* USART Tx Complete */
+#define USART_TX_vect _VECTOR(20)
+#define SIG_USART_TRANS _VECTOR(20)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(21)
+#define SIG_ADC _VECTOR(21)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(22)
+#define SIG_EEPROM_READY _VECTOR(22)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(23)
+#define SIG_COMPARATOR _VECTOR(23)
+
+/* Two-wire Serial Interface */
+#define TWI_vect _VECTOR(24)
+#define SIG_TWI _VECTOR(24)
+#define SIG_2WIRE_SERIAL _VECTOR(24)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(25)
+#define SIG_SPM_READY _VECTOR(25)
+
+/* The mega48 and mega88 vector tables are single instruction entries (16 bits
+ per entry for an RJMP) while the mega168 table has double instruction
+ entries (32 bits per entry for a JMP). */
+
+#if defined (__AVR_ATmega168__)
+# define _VECTORS_SIZE 104
+#else
+# define _VECTORS_SIZE 52
+#endif
+
+#endif /* _AVR_IOM8_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iomxx0_1.h b/cpukit/score/cpu/avr/avr/iomxx0_1.h
new file mode 100644
index 0000000000..e982cd6022
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iomxx0_1.h
@@ -0,0 +1,1553 @@
+/* Copyright (c) 2005 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iomxx0_1.h - definitions for ATmega640, Atmega1280, ATmega1281,
+ ATmega2560 and ATmega2561. */
+
+#ifndef _AVR_IOMXX0_1_H_
+#define _AVR_IOMXX0_1_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iomxx0_1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
+# define __ATmegaxx0__
+#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
+# define __ATmegaxx1__
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0X00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0X01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0X02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0X03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+#define PING _SFR_IO8(0x12)
+#define PING5 5
+#define PING4 4
+#define PING3 3
+#define PING2 2
+#define PING1 1
+#define PING0 0
+
+#define DDRG _SFR_IO8(0x13)
+#define DDG5 5
+#define DDG4 4
+#define DDG3 3
+#define DDG2 2
+#define DDG1 1
+#define DDG0 0
+
+#define PORTG _SFR_IO8(0x14)
+#define PG5 5
+#define PG4 4
+#define PG3 3
+#define PG2 2
+#define PG1 1
+#define PG0 0
+
+#define TIFR0 _SFR_IO8(0x15)
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIFR1 _SFR_IO8(0x16)
+#define ICF1 5
+#define OCF1C 3
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+#define TIFR2 _SFR_IO8(0x17)
+#define OCF2B 2
+#define OCF2A 1
+#define TOV2 0
+
+#define TIFR3 _SFR_IO8(0x18)
+#define ICF3 5
+#define OCF3C 3
+#define OCF3B 2
+#define OCF3A 1
+#define TOV3 0
+
+#define TIFR4 _SFR_IO8(0x19)
+#define ICF4 5
+#define OCF4C 3
+#define OCF4B 2
+#define OCF4A 1
+#define TOV4 0
+
+#define TIFR5 _SFR_IO8(0x1A)
+#define ICF5 5
+#define OCF5C 3
+#define OCF5B 2
+#define OCF5A 1
+#define TOV5 0
+
+#define PCIFR _SFR_IO8(0x1B)
+#if defined(__ATmegaxx0__)
+# define PCIF2 2
+#endif /* __ATmegaxx0__ */
+#define PCIF1 1
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSRASY 1
+#define PSRSYNC 0
+
+#define TCCR0A _SFR_IO8(0x24)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define TCCR0B _SFR_IO8(0x25)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+#define OCR0B _SFR_IO8(0X28)
+
+/* Reserved [0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+#define SPDR _SFR_IO8(0X2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+#define MONDR _SFR_IO8(0x31)
+#define OCDR _SFR_IO8(0x31)
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0X35)
+#define JTD 7
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMIE 7
+#define RWWSB 6
+#define SIGRD 5
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Reserved [0x38..0x3A] */
+
+#define RAMPZ _SFR_IO8(0X3B)
+#define RAMPZ0 0
+
+#define EIND _SFR_IO8(0X3C)
+#define EIND0 0
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+/* Reserved [0x62..0x63] */
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRTWI 7
+#define PRTIM2 6
+#define PRTIM0 5
+#define PRTIM1 3
+#define PRSPI 2
+#define PRUSART0 1
+#define PRADC 0
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRTIM5 5
+#define PRTIM4 4
+#define PRTIM3 3
+#define PRUSART3 2
+#define PRUSART2 1
+#define PRUSART1 0
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67] */
+
+#define PCICR _SFR_MEM8(0x68)
+#if defined(__ATmegaxx0__)
+# define PCIE2 2
+#endif /* __ATmegaxx0__ */
+#define PCIE1 1
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT15 7
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+#if defined(__ATmegaxx0__)
+# define PCMSK2 _SFR_MEM8(0x6D)
+# define PCINT23 7
+# define PCINT22 6
+# define PCINT21 5
+# define PCINT20 4
+# define PCINT19 3
+# define PCINT18 2
+# define PCINT17 1
+# define PCINT16 0
+#endif /* __ATmegaxx0__ */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define ICIE1 5
+#define OCIE1C 3
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define OCIE2B 2
+#define OCIE2A 1
+#define TOIE2 0
+
+#define TIMSK3 _SFR_MEM8(0x71)
+#define ICIE3 5
+#define OCIE3C 3
+#define OCIE3B 2
+#define OCIE3A 1
+#define TOIE3 0
+
+#define TIMSK4 _SFR_MEM8(0x72)
+#define ICIE4 5
+#define OCIE4C 3
+#define OCIE4B 2
+#define OCIE4A 1
+#define TOIE4 0
+
+#define TIMSK5 _SFR_MEM8(0x73)
+#define ICIE5 5
+#define OCIE5C 3
+#define OCIE5B 2
+#define OCIE5A 1
+#define TOIE5 0
+
+#define XMCRA _SFR_MEM8(0x74)
+#define SRE 7
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW11 3
+#define SRW10 2
+#define SRW01 1
+#define SRW00 0
+
+#define XMCRB _SFR_MEM8(0x75)
+#define XMBK 7
+#define XMM2 2
+#define XMM1 1
+#define XMM0 0
+
+/* Reserved [0x76..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ACME 6
+#if defined(__ATmegaxx0__)
+# define MUX5 3
+#endif /* __ATmegaxx0__ */
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+#define DIDR2 _SFR_MEM8(0x7D)
+#define ADC15D 7
+#define ADC14D 6
+#define ADC13D 5
+#define ADC12D 4
+#define ADC11D 3
+#define ADC10D 2
+#define ADC9D 1
+#define ADC8D 0
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN1D 1
+#define AIN0D 0
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define COM1C1 3
+#define COM1C0 2
+#define WGM11 1
+#define WGM10 0
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1A 7
+#define FOC1B 6
+#define FOC1C 5
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Combine OCR1CL and OCR1CH */
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CH _SFR_MEM8(0x8D)
+
+/* Reserved [0x8E..0x8F] */
+
+#define TCCR3A _SFR_MEM8(0x90)
+#define COM3A1 7
+#define COM3A0 6
+#define COM3B1 5
+#define COM3B0 4
+#define COM3C1 3
+#define COM3C0 2
+#define WGM31 1
+#define WGM30 0
+
+#define TCCR3B _SFR_MEM8(0x91)
+#define ICNC3 7
+#define ICES3 6
+#define WGM33 4
+#define WGM32 3
+#define CS32 2
+#define CS31 1
+#define CS30 0
+
+#define TCCR3C _SFR_MEM8(0x92)
+#define FOC3A 7
+#define FOC3B 6
+#define FOC3C 5
+
+/* Reserved [0x93] */
+
+/* Combine TCNT3L and TCNT3H */
+#define TCNT3 _SFR_MEM16(0x94)
+
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3H _SFR_MEM8(0x95)
+
+/* Combine ICR3L and ICR3H */
+#define ICR3 _SFR_MEM16(0x96)
+
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3H _SFR_MEM8(0x97)
+
+/* Combine OCR3AL and OCR3AH */
+#define OCR3A _SFR_MEM16(0x98)
+
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AH _SFR_MEM8(0x99)
+
+/* Combine OCR3BL and OCR3BH */
+#define OCR3B _SFR_MEM16(0x9A)
+
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BH _SFR_MEM8(0x9B)
+
+/* Combine OCR3CL and OCR3CH */
+#define OCR3C _SFR_MEM16(0x9C)
+
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CH _SFR_MEM8(0x9D)
+
+/* Reserved [0x9E..0x9F] */
+
+#define TCCR4A _SFR_MEM8(0xA0)
+#define COM4A1 7
+#define COM4A0 6
+#define COM4B1 5
+#define COM4B0 4
+#define COM4C1 3
+#define COM4C0 2
+#define WGM41 1
+#define WGM40 0
+
+#define TCCR4B _SFR_MEM8(0xA1)
+#define ICNC4 7
+#define ICES4 6
+#define WGM43 4
+#define WGM42 3
+#define CS42 2
+#define CS41 1
+#define CS40 0
+
+#define TCCR4C _SFR_MEM8(0xA2)
+#define FOC4A 7
+#define FOC4B 6
+#define FOC4C 5
+
+/* Reserved [0xA3] */
+
+/* Combine TCNT4L and TCNT4H */
+#define TCNT4 _SFR_MEM16(0xA4)
+
+#define TCNT4L _SFR_MEM8(0xA4)
+#define TCNT4H _SFR_MEM8(0xA5)
+
+/* Combine ICR4L and ICR4H */
+#define ICR4 _SFR_MEM16(0xA6)
+
+#define ICR4L _SFR_MEM8(0xA6)
+#define ICR4H _SFR_MEM8(0xA7)
+
+/* Combine OCR4AL and OCR4AH */
+#define OCR4A _SFR_MEM16(0xA8)
+
+#define OCR4AL _SFR_MEM8(0xA8)
+#define OCR4AH _SFR_MEM8(0xA9)
+
+/* Combine OCR4BL and OCR4BH */
+#define OCR4B _SFR_MEM16(0xAA)
+
+#define OCR4BL _SFR_MEM8(0xAA)
+#define OCR4BH _SFR_MEM8(0xAB)
+
+/* Combine OCR4CL and OCR4CH */
+#define OCR4C _SFR_MEM16(0xAC)
+
+#define OCR4CL _SFR_MEM8(0xAC)
+#define OCR4CH _SFR_MEM8(0xAD)
+
+/* Reserved [0xAE..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define COM2A1 7
+#define COM2A0 6
+#define COM2B1 5
+#define COM2B0 4
+#define WGM21 1
+#define WGM20 0
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define FOC2A 7
+#define FOC2B 6
+#define WGM22 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+#define OCR2B _SFR_MEM8(0xB4)
+
+/* Reserved [0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define EXCLK 6
+#define AS2 5
+#define TCN2UB 4
+#define OCR2AUB 3
+#define OCR2BUB 2
+#define TCR2AUB 1
+#define TCR2BUB 0
+
+/* Reserved [0xB7] */
+
+#define TWBR _SFR_MEM8(0xB8)
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+#define TWDR _SFR_MEM8(0xBB)
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM6 7
+#define TWAM5 6
+#define TWAM4 5
+#define TWAM3 4
+#define TWAM2 3
+#define TWAM1 2
+#define TWAM0 1
+
+/* Reserved [0xBE..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UMSEL01 7
+#define UMSEL00 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPOL0 0
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+/* Reserved [0xC7] */
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+#define UCSR1B _SFR_MEM8(0XC9)
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UMSEL11 7
+#define UMSEL10 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+
+/* Reserved [0xCB] */
+
+/* Combine UBRR1L and UBRR1H */
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1H _SFR_MEM8(0xCD)
+
+#define UDR1 _SFR_MEM8(0XCE)
+
+/* Reserved [0xCF] */
+
+#if defined(__ATmegaxx0__)
+
+# define UCSR2A _SFR_MEM8(0xD0)
+# define RXC2 7
+# define TXC2 6
+# define UDRE2 5
+# define FE2 4
+# define DOR2 3
+# define UPE2 2
+# define U2X2 1
+# define MPCM2 0
+
+# define UCSR2B _SFR_MEM8(0XD1)
+# define RXCIE2 7
+# define TXCIE2 6
+# define UDRIE2 5
+# define RXEN2 4
+# define TXEN2 3
+# define UCSZ22 2
+# define RXB82 1
+# define TXB82 0
+
+# define UCSR2C _SFR_MEM8(0xD2)
+# define UMSEL21 7
+# define UMSEL20 6
+# define UPM21 5
+# define UPM20 4
+# define USBS2 3
+# define UCSZ21 2
+# define UCSZ20 1
+# define UCPOL2 0
+
+/* Reserved [0xD3] */
+
+/* Combine UBRR2L and UBRR2H */
+# define UBRR2 _SFR_MEM16(0xD4)
+
+# define UBRR2L _SFR_MEM8(0xD4)
+# define UBRR2H _SFR_MEM8(0xD5)
+
+# define UDR2 _SFR_MEM8(0XD6)
+
+#endif /* __ATmegaxx0__ */
+
+/* Reserved [0xD7..0xFF] */
+
+#if defined(__ATmegaxx0__)
+
+# define PINH _SFR_MEM8(0x100)
+# define PINH7 7
+# define PINH6 6
+# define PINH5 5
+# define PINH4 4
+# define PINH3 3
+# define PINH2 2
+# define PINH1 1
+# define PINH0 0
+
+# define DDRH _SFR_MEM8(0x101)
+# define DDH7 7
+# define DDH6 6
+# define DDH5 5
+# define DDH4 4
+# define DDH3 3
+# define DDH2 2
+# define DDH1 1
+# define DDH0 0
+
+# define PORTH _SFR_MEM8(0x102)
+# define PH7 7
+# define PH6 6
+# define PH5 5
+# define PH4 4
+# define PH3 3
+# define PH2 2
+# define PH1 1
+# define PH0 0
+
+# define PINJ _SFR_MEM8(0x103)
+# define PINJ7 7
+# define PINJ6 6
+# define PINJ5 5
+# define PINJ4 4
+# define PINJ3 3
+# define PINJ2 2
+# define PINJ1 1
+# define PINJ0 0
+
+# define DDRJ _SFR_MEM8(0x104)
+# define DDJ7 7
+# define DDJ6 6
+# define DDJ5 5
+# define DDJ4 4
+# define DDJ3 3
+# define DDJ2 2
+# define DDJ1 1
+# define DDJ0 0
+
+# define PORTJ _SFR_MEM8(0x105)
+# define PJ7 7
+# define PJ6 6
+# define PJ5 5
+# define PJ4 4
+# define PJ3 3
+# define PJ2 2
+# define PJ1 1
+# define PJ0 0
+
+# define PINK _SFR_MEM8(0x106)
+# define PINK7 7
+# define PINK6 6
+# define PINK5 5
+# define PINK4 4
+# define PINK3 3
+# define PINK2 2
+# define PINK1 1
+# define PINK0 0
+
+# define DDRK _SFR_MEM8(0x107)
+# define DDK7 7
+# define DDK6 6
+# define DDK5 5
+# define DDK4 4
+# define DDK3 3
+# define DDK2 2
+# define DDK1 1
+# define DDK0 0
+
+# define PORTK _SFR_MEM8(0x108)
+# define PK7 7
+# define PK6 6
+# define PK5 5
+# define PK4 4
+# define PK3 3
+# define PK2 2
+# define PK1 1
+# define PK0 0
+
+# define PINL _SFR_MEM8(0x109)
+# define PINL7 7
+# define PINL6 6
+# define PINL5 5
+# define PINL4 4
+# define PINL3 3
+# define PINL2 2
+# define PINL1 1
+# define PINL0 0
+
+# define DDRL _SFR_MEM8(0x10A)
+# define DDL7 7
+# define DDL6 6
+# define DDL5 5
+# define DDL4 4
+# define DDL3 3
+# define DDL2 2
+# define DDL1 1
+# define DDL0 0
+
+# define PORTL _SFR_MEM8(0x10B)
+# define PL7 7
+# define PL6 6
+# define PL5 5
+# define PL4 4
+# define PL3 3
+# define PL2 2
+# define PL1 1
+# define PL0 0
+
+#endif /* __ATmegaxx0__ */
+
+/* Reserved [0x10C..0x11F] */
+
+#define TCCR5A _SFR_MEM8(0x120)
+#define COM5A1 7
+#define COM5A0 6
+#define COM5B1 5
+#define COM5B0 4
+#define COM5C1 3
+#define COM5C0 2
+#define WGM51 1
+#define WGM50 0
+
+#define TCCR5B _SFR_MEM8(0x121)
+#define ICNC5 7
+#define ICES5 6
+#define WGM53 4
+#define WGM52 3
+#define CS52 2
+#define CS51 1
+#define CS50 0
+
+#define TCCR5C _SFR_MEM8(0x122)
+#define FOC5A 7
+#define FOC5B 6
+#define FOC5C 5
+
+/* Reserved [0x123] */
+
+/* Combine TCNT5L and TCNT5H */
+#define TCNT5 _SFR_MEM16(0x124)
+
+#define TCNT5L _SFR_MEM8(0x124)
+#define TCNT5H _SFR_MEM8(0x125)
+
+/* Combine ICR5L and ICR5H */
+#define ICR5 _SFR_MEM16(0x126)
+
+#define ICR5L _SFR_MEM8(0x126)
+#define ICR5H _SFR_MEM8(0x127)
+
+/* Combine OCR5AL and OCR5AH */
+#define OCR5A _SFR_MEM16(0x128)
+
+#define OCR5AL _SFR_MEM8(0x128)
+#define OCR5AH _SFR_MEM8(0x129)
+
+/* Combine OCR5BL and OCR5BH */
+#define OCR5B _SFR_MEM16(0x12A)
+
+#define OCR5BL _SFR_MEM8(0x12A)
+#define OCR5BH _SFR_MEM8(0x12B)
+
+/* Combine OCR5CL and OCR5CH */
+#define OCR5C _SFR_MEM16(0x12C)
+
+#define OCR5CL _SFR_MEM8(0x12C)
+#define OCR5CH _SFR_MEM8(0x12D)
+
+/* Reserved [0x12E..0x12F] */
+
+#if defined(__ATmegaxx0__)
+
+# define UCSR3A _SFR_MEM8(0x130)
+# define RXC3 7
+# define TXC3 6
+# define UDRE3 5
+# define FE3 4
+# define DOR3 3
+# define UPE3 2
+# define U2X3 1
+# define MPCM3 0
+
+# define UCSR3B _SFR_MEM8(0X131)
+# define RXCIE3 7
+# define TXCIE3 6
+# define UDRIE3 5
+# define RXEN3 4
+# define TXEN3 3
+# define UCSZ32 2
+# define RXB83 1
+# define TXB83 0
+
+# define UCSR3C _SFR_MEM8(0x132)
+# define UMSEL31 7
+# define UMSEL30 6
+# define UPM31 5
+# define UPM30 4
+# define USBS3 3
+# define UCSZ31 2
+# define UCSZ30 1
+# define UCPOL3 0
+
+/* Reserved [0x133] */
+
+/* Combine UBRR3L and UBRR3H */
+# define UBRR3 _SFR_MEM16(0x134)
+
+# define UBRR3L _SFR_MEM8(0x134)
+# define UBRR3H _SFR_MEM8(0x135)
+
+# define UDR3 _SFR_MEM8(0X136)
+
+#endif /* __ATmegaxx0__ */
+
+/* Reserved [0x137..1FF] */
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+#define SIG_INTERRUPT3 _VECTOR(4)
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+#define SIG_INTERRUPT4 _VECTOR(5)
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+#define SIG_INTERRUPT5 _VECTOR(6)
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+#define SIG_INTERRUPT6 _VECTOR(7)
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+#define SIG_INTERRUPT7 _VECTOR(8)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(9)
+#define SIG_PIN_CHANGE0 _VECTOR(9)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(10)
+#define SIG_PIN_CHANGE1 _VECTOR(10)
+
+#if defined(__ATmegaxx0__)
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(11)
+#define SIG_PIN_CHANGE2 _VECTOR(11)
+
+#endif /* __ATmegaxx0__ */
+
+/* Watchdog Time-out Interrupt */
+#define WDT_vect _VECTOR(12)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(12)
+
+/* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPA_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE2A _VECTOR(13)
+
+/* Timer/Counter2 Compare Match B */
+#define TIMER2_COMPB_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE2B _VECTOR(14)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(15)
+#define SIG_OVERFLOW2 _VECTOR(15)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(16)
+#define SIG_INPUT_CAPTURE1 _VECTOR(16)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(17)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(17)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(18)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(18)
+
+/* Timer/Counter1 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(19)
+#define SIG_OUTPUT_COMPARE1C _VECTOR(19)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(20)
+#define SIG_OVERFLOW1 _VECTOR(20)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(21)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(21)
+
+/* Timer/Counter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(22)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(22)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(23)
+#define SIG_OVERFLOW0 _VECTOR(23)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(24)
+#define SIG_SPI _VECTOR(24)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(25)
+#define SIG_USART0_RECV _VECTOR(25)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(26)
+#define SIG_USART0_DATA _VECTOR(26)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(27)
+#define SIG_USART0_TRANS _VECTOR(27)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(28)
+#define SIG_COMPARATOR _VECTOR(28)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(29)
+#define SIG_ADC _VECTOR(29)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(30)
+#define SIG_EEPROM_READY _VECTOR(30)
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(31)
+#define SIG_INPUT_CAPTURE3 _VECTOR(31)
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(32)
+#define SIG_OUTPUT_COMPARE3A _VECTOR(32)
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(33)
+#define SIG_OUTPUT_COMPARE3B _VECTOR(33)
+
+/* Timer/Counter3 Compare Match C */
+#define TIMER3_COMPC_vect _VECTOR(34)
+#define SIG_OUTPUT_COMPARE3C _VECTOR(34)
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(35)
+#define SIG_OVERFLOW3 _VECTOR(35)
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(36)
+#define SIG_USART1_RECV _VECTOR(36)
+
+/* USART1 Data register Empty */
+#define USART1_UDRE_vect _VECTOR(37)
+#define SIG_USART1_DATA _VECTOR(37)
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(38)
+#define SIG_USART1_TRANS _VECTOR(38)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(39)
+#define SIG_2WIRE_SERIAL _VECTOR(39)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(40)
+#define SIG_SPM_READY _VECTOR(40)
+
+#if defined(__ATmegaxx0__)
+/* Timer/Counter4 Capture Event */
+#define TIMER4_CAPT_vect _VECTOR(41)
+#define SIG_INPUT_CAPTURE4 _VECTOR(41)
+
+#endif /* __ATmegaxx0__ */
+
+/* Timer/Counter4 Compare Match A */
+#define TIMER4_COMPA_vect _VECTOR(42)
+#define SIG_OUTPUT_COMPARE4A _VECTOR(42)
+
+/* Timer/Counter4 Compare Match B */
+#define TIMER4_COMPB_vect _VECTOR(43)
+#define SIG_OUTPUT_COMPARE4B _VECTOR(43)
+
+/* Timer/Counter4 Compare Match C */
+#define TIMER4_COMPC_vect _VECTOR(44)
+#define SIG_OUTPUT_COMPARE4C _VECTOR(44)
+
+/* Timer/Counter4 Overflow */
+#define TIMER4_OVF_vect _VECTOR(45)
+#define SIG_OVERFLOW4 _VECTOR(45)
+
+#if defined(__ATmegaxx0__)
+/* Timer/Counter5 Capture Event */
+#define TIMER5_CAPT_vect _VECTOR(46)
+#define SIG_INPUT_CAPTURE5 _VECTOR(46)
+
+#endif /* __ATmegaxx0__ */
+
+/* Timer/Counter5 Compare Match A */
+#define TIMER5_COMPA_vect _VECTOR(47)
+#define SIG_OUTPUT_COMPARE5A _VECTOR(47)
+
+/* Timer/Counter5 Compare Match B */
+#define TIMER5_COMPB_vect _VECTOR(48)
+#define SIG_OUTPUT_COMPARE5B _VECTOR(48)
+
+/* Timer/Counter5 Compare Match C */
+#define TIMER5_COMPC_vect _VECTOR(49)
+#define SIG_OUTPUT_COMPARE5C _VECTOR(49)
+
+/* Timer/Counter5 Overflow */
+#define TIMER5_OVF_vect _VECTOR(50)
+#define SIG_OVERFLOW5 _VECTOR(50)
+
+#if defined(__ATmegaxx1__)
+
+# define _VECTORS_SIZE 204
+
+#else
+
+/* USART2, Rx Complete */
+#define USART2_RX_vect _VECTOR(51)
+#define SIG_USART2_RECV _VECTOR(51)
+
+/* USART2 Data register Empty */
+#define USART2_UDRE_vect _VECTOR(52)
+#define SIG_USART2_DATA _VECTOR(52)
+
+/* USART2, Tx Complete */
+#define USART2_TX_vect _VECTOR(53)
+#define SIG_USART2_TRANS _VECTOR(53)
+
+/* USART3, Rx Complete */
+#define USART3_RX_vect _VECTOR(54)
+#define SIG_USART3_RECV _VECTOR(54)
+
+/* USART3 Data register Empty */
+#define USART3_UDRE_vect _VECTOR(55)
+#define SIG_USART3_DATA _VECTOR(55)
+
+/* USART3, Tx Complete */
+#define USART3_TX_vect _VECTOR(56)
+#define SIG_USART3_TRANS _VECTOR(56)
+
+# define _VECTORS_SIZE 228
+
+#endif /* __ATmegaxx1__ */
+
+#if defined(__ATmegaxx0__)
+# undef __ATmegaxx0__
+#endif
+
+#if defined(__ATmegaxx1__)
+# undef __ATmegaxx1__
+#endif
+
+#endif /* _AVR_IOMXX0_1_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iomxx4.h b/cpukit/score/cpu/avr/avr/iomxx4.h
new file mode 100644
index 0000000000..8f61345f64
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iomxx4.h
@@ -0,0 +1,869 @@
+/* Copyright (c) 2005, 2006, 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/iomXX4.h - definitions for ATmega164P/324P/644P and ATmega644 */
+
+/* $Id$ */
+
+#ifndef _AVR_IOMXX4_H_
+#define _AVR_IOMXX4_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iom164.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0X00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0X01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0X02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0X03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Reserved [0x0C..0x14] */
+
+#define TIFR0 _SFR_IO8(0x15)
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIFR1 _SFR_IO8(0x16)
+#define ICF1 5
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+#define TIFR2 _SFR_IO8(0x17)
+#define OCF2B 2
+#define OCF2A 1
+#define TOV2 0
+
+/* Reserved [0x18..0x1A] */
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF3 3
+#define PCIF2 2
+#define PCIF1 1
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+/* EECR - EEPROM Control Register */
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0X20)
+
+/* Combine EEARL and EEARH */
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0X22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSRASY 1
+#define PSRSYNC 0
+
+#define TCCR0A _SFR_IO8(0x24)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define TCCR0B _SFR_IO8(0x25)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0X27)
+
+#define OCR0B _SFR_IO8(0X28)
+
+/* Reserved [0x29] */
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+#define SPDR _SFR_IO8(0x2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+#define MONDR _SFR_IO8(0x31)
+#define OCDR _SFR_IO8(0x31)
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0X35)
+#define JTD 7
+#if !defined(__AVR_ATmega644__)
+#define BODS 6
+#define BODSE 5
+#endif
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMIE 7
+#define RWWSB 6
+#define SIGRD 5
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+/* Reserved [0x62..0x63] */
+
+#define PRR _SFR_MEM8(0x64) /* Datasheets: ATmega164P/324P/644P 8011D–AVR–02/07
+ and ATmega644 2593L–AVR–02/07. */
+#define PRR0 _SFR_MEM8(0x64) /* AVR Studio 4.13, build 524. */
+#define PRTWI 7
+#define PRTIM2 6
+#define PRTIM0 5
+#if !defined(__AVR_ATmega644__)
+# define PRUSART1 4
+#endif
+#define PRTIM1 3
+#define PRSPI 2
+#define PRUSART0 1
+#define PRADC 0
+
+/* Reserved [0x65] */
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67] */
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE3 3
+#define PCIE2 2
+#define PCIE1 1
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Reserved [0x6A] */
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT15 7
+#define PCINT14 6
+#define PCINT13 5
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT23 7
+#define PCINT22 6
+#define PCINT21 5
+#define PCINT20 4
+#define PCINT19 3
+#define PCINT18 2
+#define PCINT17 1
+#define PCINT16 0
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define ICIE1 5
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define OCIE2B 2
+#define OCIE2A 1
+#define TOIE2 0
+
+/* Reserved [0x71..0x72] */
+
+#define PCMSK3 _SFR_MEM8(0x73)
+#define PCINT31 7
+#define PCINT30 6
+#define PCINT29 5
+#define PCINT28 4
+#define PCINT27 3
+#define PCINT26 2
+#define PCINT25 1
+#define PCINT24 0
+
+/* Reserved [0x74..0x77] */
+
+/* Combine ADCL and ADCH */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ACME 6
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN1D 1
+#define AIN0D 0
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define WGM11 1
+#define WGM10 0
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1A 7
+#define FOC1B 6
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Reserved [0x8C..0xAF] */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define COM2A1 7
+#define COM2A0 6
+#define COM2B1 5
+#define COM2B0 4
+#define WGM21 1
+#define WGM20 0
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define FOC2A 7
+#define FOC2B 6
+#define WGM22 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+#define OCR2B _SFR_MEM8(0xB4)
+
+/* Reserved [0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define EXCLK 6
+#define AS2 5
+#define TCN2UB 4
+#define OCR2AUB 3
+#define OCR2BUB 2
+#define TCR2AUB 1
+#define TCR2BUB 0
+
+/* Reserved [0xB7] */
+
+#define TWBR _SFR_MEM8(0xB8)
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+#define TWDR _SFR_MEM8(0xBB)
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM6 7
+#define TWAM5 6
+#define TWAM4 5
+#define TWAM3 4
+#define TWAM2 3
+#define TWAM1 2
+#define TWAM0 1
+
+/* Reserved [0xBE..0xBF] */
+
+#define UCSR0A _SFR_MEM8(0xC0)
+#define RXC0 7
+#define TXC0 6
+#define UDRE0 5
+#define FE0 4
+#define DOR0 3
+#define UPE0 2
+#define U2X0 1
+#define MPCM0 0
+
+#define UCSR0B _SFR_MEM8(0XC1)
+#define RXCIE0 7
+#define TXCIE0 6
+#define UDRIE0 5
+#define RXEN0 4
+#define TXEN0 3
+#define UCSZ02 2
+#define RXB80 1
+#define TXB80 0
+
+#define UCSR0C _SFR_MEM8(0xC2)
+#define UMSEL01 7
+#define UMSEL00 6
+#define UPM01 5
+#define UPM00 4
+#define USBS0 3
+#define UCSZ01 2
+#define UCSZ00 1
+#define UCPHA0 1
+#define UCPOL0 0
+
+/* Reserved [0xC3] */
+
+/* Combine UBRR0L and UBRR0H */
+#define UBRR0 _SFR_MEM16(0xC4)
+
+#define UBRR0L _SFR_MEM8(0xC4)
+#define UBRR0H _SFR_MEM8(0xC5)
+
+#define UDR0 _SFR_MEM8(0XC6)
+
+#if !defined(__AVR_ATmega644__)
+/*
+ * Only ATmega164P/324P/644P have a second USART.
+ */
+/* Reserved [0xC7] */
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+#define UCSR1B _SFR_MEM8(0XC9)
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UMSEL11 7
+#define UMSEL10 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPHA1 1
+#define UCPOL1 0
+
+/* Reserved [0xCB] */
+
+/* Combine UBRR1L and UBRR1H */
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1H _SFR_MEM8(0xCD)
+
+#define UDR1 _SFR_MEM8(0XCE)
+#endif /* !defined(__AVR_ATmega644) */
+
+/* Reserved [0xCF..0xFF] */
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+#define SIG_INTERRUPT2 _VECTOR(3)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(4)
+#define SIG_PIN_CHANGE0 _VECTOR(4)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(5)
+#define SIG_PIN_CHANGE1 _VECTOR(5)
+
+/* Pin Change Interrupt Request 2 */
+#define PCINT2_vect _VECTOR(6)
+#define SIG_PIN_CHANGE2 _VECTOR(6)
+
+/* Pin Change Interrupt Request 3 */
+#define PCINT3_vect _VECTOR(7)
+#define SIG_PIN_CHANGE3 _VECTOR(7)
+
+/* Watchdog Time-out Interrupt */
+#define WDT_vect _VECTOR(8)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(8)
+
+/* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPA_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE2A _VECTOR(9)
+
+/* Timer/Counter2 Compare Match B */
+#define TIMER2_COMPB_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE2B _VECTOR(10)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW2 _VECTOR(11)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(12)
+#define SIG_INPUT_CAPTURE1 _VECTOR(12)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(13)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(14)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(15)
+#define SIG_OVERFLOW1 _VECTOR(15)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(16)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(16)
+
+/* Timer/Counter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(17)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(17)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(18)
+#define SIG_OVERFLOW0 _VECTOR(18)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(19)
+#define SIG_SPI _VECTOR(19)
+
+/* USART0, Rx Complete */
+#define USART0_RX_vect _VECTOR(20)
+#define SIG_USART_RECV _VECTOR(20)
+
+/* USART0 Data register Empty */
+#define USART0_UDRE_vect _VECTOR(21)
+#define SIG_USART_DATA _VECTOR(21)
+
+/* USART0, Tx Complete */
+#define USART0_TX_vect _VECTOR(22)
+#define SIG_USART_TRANS _VECTOR(22)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(23)
+#define SIG_COMPARATOR _VECTOR(23)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(24)
+#define SIG_ADC _VECTOR(24)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(25)
+#define SIG_EEPROM_READY _VECTOR(25)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(26)
+#define SIG_2WIRE_SERIAL _VECTOR(26)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(27)
+#define SIG_SPM_READY _VECTOR(27)
+
+#if defined(__AVR_ATmega644__)
+
+# define _VECTORS_SIZE 112
+
+#else /* !defined(__AVR_ATmega644__) */
+
+/* USART1, Rx Complete */
+/* USART1 RX complete */
+#define USART1_RX_vect _VECTOR(28)
+#define SIG_USART1_RECV _VECTOR(28)
+
+/* USART1 Data register Empty */
+/* USART1 Data Register Empty */
+#define USART1_UDRE_vect _VECTOR(29)
+#define SIG_USART1_DATA _VECTOR(29)
+
+/* USART1, Tx Complete */
+/* USART1 TX complete */
+#define USART1_TX_vect _VECTOR(30)
+#define SIG_USART1_TRANS _VECTOR(30)
+
+# define _VECTORS_SIZE 124
+
+#endif /* defined(__AVR_ATmega644__) */
+
+
+#endif /* _AVR_IOMXX4_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iomxxhva.h b/cpukit/score/cpu/avr/avr/iomxxhva.h
new file mode 100644
index 0000000000..5dfc5bf186
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iomxxhva.h
@@ -0,0 +1,523 @@
+/* Copyright (c) 2007, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iomxxhva.h - definitions for ATmega8HVA and ATmega16HVA. */
+
+#ifndef _AVR_IOMXXHVA_H_
+#define _AVR_IOMXXHVA_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iomxxhva.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0X00)
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x02)
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0X03)
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+
+/* Reserved [0x7] */
+
+#define PORTC _SFR_IO8(0x08)
+#define PC0 0
+
+/* Reserved [0x9..0x14] */
+
+#define TIFR0 _SFR_IO8(0x15)
+#define ICF0 3
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIFR1 _SFR_IO8(0x16)
+#define ICF1 3
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+#define OSICSR _SFR_IO8(0x17)
+#define OSISEL0 4
+#define OSIST 1
+#define OSIEN 0
+
+/* Reserved [0x18..0x1B] */
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0x20)
+
+#define EEAR _SFR_IO8(0x21)
+#define EEARL _SFR_IO8(0x21)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+/* Reserved [0x22] */
+
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSRSYNC 0
+
+#define TCCR0A _SFR_IO8(0x24)
+#define TCW0 7
+#define ICEN0 6
+#define ICNC0 5
+#define ICES0 4
+#define ICS0 3
+#define WGM00 0
+
+#define TCCR0B _SFR_IO8(0x25)
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define TCNT0 _SFR_IO16(0X26)
+#define TCNT0L _SFR_IO8(0X26)
+#define TCNT0H _SFR_IO8(0X27)
+
+#define OCR0A _SFR_IO8(0x28)
+
+#define OCR0B _SFR_IO8(0X29)
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+#define SPDR _SFR_IO8(0x2E)
+
+/* Reserved [0x2F..0x30] */
+
+#define DWDR _SFR_IO8(0x31)
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define OCDRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0x35)
+#define CKOE 5
+#define PUD 4
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SIGRD 5
+#define CTPB 4
+#define RFLB 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPCE 7
+#define CLKPS1 1
+#define CLKPS0 0
+
+/* Reserved [0x62..0x63] */
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRVRM 5
+#define PRSPI 3
+#define PRTIM1 2
+#define PRTIM0 1
+#define PRVADC 0
+
+/* Reserved [0x65] */
+
+#define FOSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67..0x68] */
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* Reserved [0x6A..0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define ICIE0 3
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define ICIE1 3
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+/* Reserved [0x70..0x77] */
+
+#define VADC _SFR_MEM16(0x78)
+#define VADCL _SFR_MEM8(0x78)
+#define VADCH _SFR_MEM8(0x79)
+
+#define VADCSR _SFR_MEM8(0x7A)
+#define VADEN 3
+#define VADSC 2
+#define VADCCIF 1
+#define VADCCIE 0
+
+/* Reserved [0x7B] */
+
+#define VADMUX _SFR_MEM8(0x7C)
+#define VADMUX3 3
+#define VADMUX2 2
+#define VADMUX1 1
+#define VADMUX0 0
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define PA1DID 1
+#define PA0DID 0
+
+/* Reserved [0x7F] */
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define TCW1 7
+#define ICEN1 6
+#define ICNC1 5
+#define ICES1 4
+#define ICS1 3
+#define WGM10 0
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* Reserved [0x82..0x83] */
+
+#define TCNT1 _SFR_MEM16(0x84)
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Reserved [0x86..0x87] */
+
+#define OCR1A _SFR_MEM8(0x88)
+
+#define OCR1B _SFR_MEM8(0x89)
+
+/* Reserved [0x8A..0xC7] */
+
+#define ROCR _SFR_MEM8(0xC8)
+#define ROCS 7
+#define ROCWIF 1
+#define ROCWIE 0
+
+/* Reserved [0xC9..0xCF] */
+
+#define BGCCR _SFR_MEM8(0xD0)
+#define BGD 7
+#define BGCC5 5
+#define BGCC4 4
+#define BGCC3 3
+#define BGCC2 2
+#define BGCC1 1
+#define BGCC0 0
+
+#define BGCRR _SFR_MEM8(0xD1)
+#define BGCR7 7
+#define BGCR6 6
+#define BGCR5 5
+#define BGCR4 4
+#define BGCR3 3
+#define BGCR2 2
+#define BGCR1 1
+#define BGCR0 0
+
+/* Reserved [0xD2..0xDF] */
+
+/* CC-ADC Accumulate Current */
+/* TODO: Add _SFR_MEM32 */
+/* #define CADAC _SFR_MEM32(0xE0) */
+#define CADAC0 _SFR_MEM8(0xE0)
+#define CADAC1 _SFR_MEM8(0xE1)
+#define CADAC2 _SFR_MEM8(0xE2)
+#define CADAC3 _SFR_MEM8(0xE3)
+
+#define CADCSRA _SFR_MEM8(0xE4)
+#define CADEN 7
+#define CADPOL 6
+#define CADUB 5
+#define CADAS1 4
+#define CADAS0 3
+#define CADSI1 2
+#define CADSI0 1
+#define CADSE 0
+
+#define CADCSRB _SFR_MEM8(0xE5)
+#define CADACIE 6
+#define CADRCIE 5
+#define CADICIE 4
+#define CADACIF 2
+#define CADRCIF 1
+#define CADICIF 0
+
+#define CADRC _SFR_MEM8(0xE6)
+
+/* Reserved [0xE7] */
+
+#define CADIC _SFR_MEM16(0xE8)
+#define CADICL _SFR_MEM8(0xE8)
+#define CADICH _SFR_MEM8(0xE9)
+
+/* Reserved [0xEA..0xEF] */
+
+#define FCSR _SFR_MEM8(0xF0)
+#define DUVRD 3
+#define CPS 2
+#define DFE 1
+#define CFE 0
+
+/* Reserved [0xF1] */
+
+#define BPIMSK _SFR_MEM8(0xF2)
+#define SCIE 4
+#define DOCIE 3
+#define COCIE 2
+#define DHCIE 1
+#define CHCIE 0
+
+#define BPIFR _SFR_MEM8(0xF3)
+#define SCIF 4
+#define DOCIF 3
+#define COCIF 2
+#define DHCIF 1
+#define CHCIF 0
+
+/* Reserved [0xF4] */
+
+#define BPSCD _SFR_MEM8(0xF5)
+
+#define BPDOCD _SFR_MEM8(0xF6)
+
+#define BPCOCD _SFR_MEM8(0xF7)
+
+#define BPDHCD _SFR_MEM8(0xF8)
+
+#define BPCHCD _SFR_MEM8(0xF9)
+
+#define BPSCTR _SFR_MEM8(0xFA)
+
+#define BPOCTR _SFR_MEM8(0xFB)
+
+#define BPHCTR _SFR_MEM8(0xFC)
+
+#define BPCR _SFR_MEM8(0xFD)
+#define SCD 4
+#define DOCD 3
+#define COCD 2
+#define DHCD 1
+#define CHCD 0
+
+#define BPPLR _SFR_MEM8(0xFE)
+#define BPPLE 1
+#define BPPL 0
+
+/* Reserved [0xFF] */
+
+/* Interrupt vectors */
+/* Battery Protection Interrupt */
+#define BPINT_vect _VECTOR(1)
+
+/* Voltage Regulator Monitor Interrupt */
+#define VREGMON_vect _VECTOR(2)
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(3)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(4)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(5)
+
+/* Watchdog Timeout Interrupt */
+#define WDT_vect _VECTOR(6)
+
+/* Timer/Counter 1 Input Capture */
+#define TIMER1_IC_vect _VECTOR(7)
+
+/* Timer/Counter 1 Compare A Match */
+#define TIMER1_COMPA_vect _VECTOR(8)
+
+/* Timer/Counter 1 Compare B Match */
+#define TIMER1_COMPB_vect _VECTOR(9)
+
+/* Timer/Counter 1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(10)
+
+/* Timer/Counter 0 Input Capture */
+#define TIMER0_IC_vect _VECTOR(11)
+
+/* Timer/Counter0 Compare A Match */
+#define TIMER0_COMPA_vect _VECTOR(12)
+
+/* Timer/Counter0 Compare B Match */
+#define TIMER0_COMPB_vect _VECTOR(13)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(14)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(15)
+
+/* Voltage ADC Conversion Complete */
+#define VADC_vect _VECTOR(16)
+
+/* Coulomb Counter ADC Conversion Complete */
+#define CCADC_CONV_vect _VECTOR(17)
+
+/* Coloumb Counter ADC Regular Current */
+#define CCADC_REG_CUR_vect _VECTOR(18)
+
+/* Coloumb Counter ADC Accumulator */
+#define CCADC_ACC_vect _VECTOR(19)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(20)
+
+#if defined (__AVR_ATmega16HVA__)
+# define _VECTORS_SIZE 84
+#else
+# define _VECTORS_SIZE 42
+#endif
+
+
+#endif /* _AVR_IOMXXHVA_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn11.h b/cpukit/score/cpu/avr/avr/iotn11.h
new file mode 100644
index 0000000000..fe48d11d9e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn11.h
@@ -0,0 +1,234 @@
+/* Copyright (c) 2002,2005 Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn11.h - definitions for ATtiny10/11 */
+
+#ifndef _AVR_IOTN11_H_
+#define _AVR_IOTN11_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn11.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef __ASSEMBLER__
+# warning "MCU not supported by the C compiler"
+#endif
+
+/* I/O registers */
+
+/* 0x00..0x07 reserved */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* 0x09..0x15 reserved */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* 0x19..0x20 reserved */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* 0x22..0x31 reserved */
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* 0x36..0x37 reserved */
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C..0x3E reserved */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 0 */
+#define IO_PINS_vect _VECTOR(2)
+#define SIG_PIN _VECTOR(2)
+#define SIG_PIN_CHANGE _VECTOR(2)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(3)
+#define SIG_OVERFLOW0 _VECTOR(3)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(4)
+#define SIG_COMPARATOR _VECTOR(4)
+
+#define _VECTORS_SIZE 10
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT0 6
+#define PCIE 5
+
+/* GIFR */
+#define INTF0 6
+#define PCIF 5
+
+/* TIMSK */
+#define TOIE0 1
+
+/* TIFR */
+#define TOV0 1
+
+/* MCUCR */
+#define SE 5
+#define SM 4
+#define ISC01 1
+#define ISC00 0
+
+/* TCCR0 */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PB5 = RESET#
+ PB4 = XTAL2
+ PB3 = XTAL1
+ PB2 = T0
+ PB1 = INT0 / AIN1
+ PB0 = AIN0
+ */
+
+/* PORTB */
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* ACSR */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIS1 1
+#define ACIS0 0
+
+/* Last memory addresses */
+#define RAMEND 0x1F
+#define XRAMEND 0x0
+#define E2END 0x0
+#define E2PAGESIZE 2
+#define FLASHEND 0x3FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_RSTDISBL (unsigned char)~_BV(3)
+#define FUSE_FSTRT (unsigned char)~_BV(4)
+#define FUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL1)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x90
+#define SIGNATURE_2 0x04
+
+
+#endif /* _AVR_IOTN11_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn12.h b/cpukit/score/cpu/avr/avr/iotn12.h
new file mode 100644
index 0000000000..8306a2c297
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn12.h
@@ -0,0 +1,265 @@
+/* Copyright (c) 2002,2005 Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn12.h - definitions for ATtiny12 */
+
+#ifndef _AVR_IOTN12_H_
+#define _AVR_IOTN12_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn12.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef __ASSEMBLER__
+# warning "MCU not supported by the C compiler"
+#endif
+
+/* I/O registers */
+
+/* 0x00..0x07 reserved */
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* 0x09..0x15 reserved */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* 0x19..0x1B reserved */
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* 0x1F..0x20 reserved */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* 0x22..0x30 reserved */
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* 0x36..0x37 reserved */
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C..0x3E reserved */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 0 */
+#define IO_PINS_vect _VECTOR(2)
+#define SIG_PIN _VECTOR(2)
+#define SIG_PIN_CHANGE _VECTOR(2)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(3)
+#define SIG_OVERFLOW0 _VECTOR(3)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(4)
+#define SIG_EEPROM_READY _VECTOR(4)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(5)
+#define SIG_COMPARATOR _VECTOR(5)
+
+#define _VECTORS_SIZE 12
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT0 6
+#define PCIE 5
+
+/* GIFR */
+#define INTF0 6
+#define PCIF 5
+
+/* TIMSK */
+#define TOIE0 1
+
+/* TIFR */
+#define TOV0 1
+
+/* MCUCR */
+#define PUD 6
+#define SE 5
+#define SM 4
+#define ISC01 1
+#define ISC00 0
+
+/* TCCR0 */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PB5 = RESET#
+ PB4 = XTAL2
+ PB3 = XTAL1
+ PB2 = T0 / SCK
+ PB1 = INT0 / AIN1 / MISO
+ PB0 = AIN0 / MOSI
+ */
+
+/* PORTB */
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* ACSR */
+#define ACD 7
+#define AINBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIS1 1
+#define ACIS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Last memory addresses */
+#define RAMEND 0x1F
+#define XRAMEND 0x0
+#define E2END 0x3F
+#define E2PAGESIZE 2
+#define FLASHEND 0x3FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_RSTDISBL (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define FUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SPIEN & FUSE_BODLEVEL)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x90
+#define SIGNATURE_2 0x05
+
+
+#endif /* _AVR_IOTN12_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn13.h b/cpukit/score/cpu/avr/avr/iotn13.h
new file mode 100644
index 0000000000..dde65368b8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn13.h
@@ -0,0 +1,364 @@
+/* Copyright (c) 2004, Theodore A. Roth
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn13.h - definitions for ATtiny13 */
+
+/* Verified 5/20/04 by Bruce Graham */
+
+#ifndef _AVR_IOTN13_H_
+#define _AVR_IOTN13_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn13.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers and bit names */
+
+/* ADC Control and Status Register B */
+#define ADCSRB _SFR_IO8(0x03)
+# define ACME 6
+# define ADTS2 2
+# define ADTS1 1
+# define ADTS0 0
+
+/* ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16 (0x04)
+#endif
+#define ADCW _SFR_IO16 (0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+/* ADC Control and Status Register A */
+#define ADCSRA _SFR_IO8(0x06)
+# define ADEN 7
+# define ADSC 6
+# define ADATE 5
+# define ADIF 4
+# define ADIE 3
+# define ADPS2 2
+# define ADPS1 1
+# define ADPS0 0
+
+/* ADC Multiplex Selection Register */
+#define ADMUX _SFR_IO8(0x07)
+# define REFS0 6
+# define ADLAR 5
+# define MUX1 1
+# define MUX0 0
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+# define ACD 7
+# define ACBG 6
+# define ACO 5
+# define ACI 4
+# define ACIE 3
+# define ACIS1 1
+# define ACIS0 0
+
+/* Digital Input Disable Register 0 */
+#define DIDR0 _SFR_IO8(0x14)
+# define ADC0D 5
+# define ADC2D 4
+# define ADC3D 3
+# define ADC1D 2
+# define AIN1D 1
+# define AIN0D 0
+
+/* PIN Change Mask Register */
+#define PCMSK _SFR_IO8(0x15)
+# define PCINT5 5
+# define PCINT4 4
+# define PCINT3 3
+# define PCINT2 2
+# define PCINT1 1
+# define PCINT0 0
+
+/* Port B Pin Utilization [2535D-AVR-04/04]
+ - PORTB5 = PCINT5/RESET#/ADC0/dW
+ - PORTB4 = PCINT4/ADC2
+ - PORTB3 = PCINT3/CLKI/ADC3
+ - PORTB2 = SCK/ADC1/T0/PCINT2
+ - PORTB1 = MISO/AIN1/OC0B/INT0/PCINT1
+ - PORTB0 = MOSI/AIN0/OC0A/PCINT0 */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+# define PINB5 5
+# define PINB4 4
+# define PINB3 3
+# define PINB2 2
+# define PINB1 1
+# define PINB0 0
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+# define DDB5 5
+# define DDB4 4
+# define DDB3 3
+# define DDB2 2
+# define DDB1 1
+# define DDB0 0
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+# define PB5 5
+# define PB4 4
+# define PB3 3
+# define PB2 2
+# define PB1 1
+# define PB0 0
+
+/* ATtiny EEPROM Control Register EECR */
+#define EECR _SFR_IO8(0x1C)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* The EEPROM Address Register EEAR[6:0] */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+# define WDTIF 7
+# define WDTIE 6
+# define WDP3 5
+# define WDCE 4
+# define WDE 3
+# define WDP2 2
+# define WDP1 1
+# define WDP0 0
+
+/* Clock Prescale Register */
+#define CLKPR _SFR_IO8(0x26)
+# define CLKPCE 7
+# define CLKPS3 3
+# define CLKPS2 2
+# define CLKPS1 1
+# define CLKPS0 0
+
+/* General Timer/Counter Control Register */
+#define GTCCR _SFR_IO8(0x28)
+# define TSM 7
+# define PSR10 0
+
+/* Output Compare 0 Register B */
+#define OCR0B _SFR_IO8(0x29)
+
+/* debugWIRE Data Register */
+#define DWDR _SFR_IO8(0x2e)
+
+/* Timer/Counter 0 Control Register A */
+#define TCCR0A _SFR_IO8(0x2f)
+# define COM0A1 7
+# define COM0A0 6
+# define COM0B1 5
+# define COM0B0 4
+# define WGM01 1
+# define WGM00 0
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register B */
+#define TCCR0B _SFR_IO8(0x33)
+# define FOC0A 7
+# define FOC0B 6
+# define WGM02 3
+# define CS02 2
+# define CS01 1
+# define CS00 0
+
+/* MCU General Status Register */
+#define MCUSR _SFR_IO8(0x34)
+# define WDRF 3
+# define BORF 2
+# define EXTRF 1
+# define PORF 0
+
+/* MCU General Control Register */
+#define MCUCR _SFR_IO8(0x35)
+# define PUD 6
+# define SE 5
+# define SM1 4
+# define SM0 3
+# define ISC01 1
+# define ISC00 0
+
+/* Output Compare 0 REgister A */
+#define OCR0A _SFR_IO8(0x36)
+
+/* Store Program Memory Control and Status Register */
+#define SPMCSR _SFR_IO8(0x37)
+# define CTPB 4
+# define RFLB 3
+# define PGWRT 2
+# define PGERS 1
+# define SPMEN 0
+# define SELFPRGEN 0
+
+/* Timer/Counter 0 Interrupt Flag Register */
+#define TIFR0 _SFR_IO8(0x38)
+# define OCF0B 3
+# define OCF0A 2
+# define TOV0 1
+
+/* Timer/Counter 0 Interrupt MaSK Register */
+#define TIMSK0 _SFR_IO8(0x39)
+# define OCIE0B 3
+# define OCIE0A 2
+# define TOIE0 1
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3a)
+# define INTF0 6
+# define PCIF 5
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3b)
+# define INT0 6
+# define PCIE 5
+
+/* SPL and SREG are defined in <avr/io.h> */
+
+/* From the datasheet:
+ 1 0x0000 RESET External Pin, Power-on Reset, Brown-out Reset, Watchdog Reset
+ 2 0x0001 INT0 External Interrupt Request 0
+ 3 0x0002 PCINT0 Pin Change Interrupt Request 0
+ 4 0x0003 TIM0_OVF Timer/Counter Overflow
+ 5 0x0004 EE_RDY EEPROM Ready
+ 6 0x0005 ANA_COMP Analog Comparator
+ 7 0x0006 TIM0_COMPA Timer/Counter Compare Match A
+ 8 0x0007 TIM0_COMPB Timer/Counter Compare Match B
+ 9 0x0008 WDT Watchdog Time-out
+ 10 0x0009 ADC ADC Conversion Complete */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Timer/Counter0 Overflow */
+#define TIM0_OVF_vect _VECTOR(3)
+#define SIG_OVERFLOW0 _VECTOR(3)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(4)
+#define SIG_EEPROM_READY _VECTOR(4)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(5)
+#define SIG_COMPARATOR _VECTOR(5)
+
+/* Timer/Counter Compare Match A */
+#define TIM0_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(6)
+
+/* Timer/Counter Compare Match B */
+#define TIM0_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(7)
+
+/* Watchdog Time-out */
+#define WDT_vect _VECTOR(8)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(8)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(9)
+#define SIG_ADC _VECTOR(9)
+
+#define _VECTORS_SIZE 20
+
+#define SPM_PAGESIZE 32
+#define RAMEND 0x9F
+#define XRAMEND RAMEND
+#define E2END 0x3F
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_SUT0 (unsigned char)~_BV(2)
+#define FUSE_SUT1 (unsigned char)~_BV(3)
+#define FUSE_CKDIV8 (unsigned char)~_BV(4)
+#define FUSE_WDTON (unsigned char)~_BV(5)
+#define FUSE_EESAVE (unsigned char)~_BV(6)
+#define FUSE_SPIEN (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_SUT0 & FUSE_CKDIV8 & FUSE_SPIEN)
+
+/* High Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_DWEN (unsigned char)~_BV(3)
+#define FUSE_SPMEN (unsigned char)~_BV(4)
+#define HFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x90
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOTN13_H_*/
diff --git a/cpukit/score/cpu/avr/avr/iotn13a.h b/cpukit/score/cpu/avr/avr/iotn13a.h
new file mode 100644
index 0000000000..7f05279436
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn13a.h
@@ -0,0 +1,384 @@
+/* Copyright (c) 2008 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn13a.h - definitions for ATtiny13 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn13a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATTINY13A_H_
+#define _AVR_ATTINY13A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define ADLAR 5
+#define REFS0 6
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define DIDR0 _SFR_IO8(0x14)
+#define AIN0D 0
+#define AIN1D 1
+#define ADC1D 2
+#define ADC3D 3
+#define ADC2D 4
+#define ADC0D 5
+
+#define PCMSK _SFR_IO8(0x15)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEARL _SFR_IO8(0x1E)
+
+#define EEAR _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDTIE 6
+#define WDTIF 7
+
+#define PRR _SFR_IO8(0x25)
+#define PRADC 0
+#define PRTIM0 1
+
+#define CLKPR _SFR_IO8(0x26)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define GTCCR _SFR_IO8(0x28)
+#define PSR10 0
+#define TSM 7
+
+#define OCR0B _SFR_IO8(0x29)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define DWDR _SFR_IO8(0x2E)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define TCCR0A _SFR_IO8(0x2F)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define BODCR _SFR_IO8(0x30)
+#define BPDSE 0
+#define BPDS 1
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define TCNT0 _SFR_IO8(0x32)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+
+#define OCR0A _SFR_IO8(0x36)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR0 _SFR_IO8(0x38)
+#define TOV0 1
+#define OCF0A 2
+#define OCF0B 3
+
+#define TIMSK0 _SFR_IO8(0x39)
+#define TOIE0 1
+#define OCIE0A 2
+#define OCIE0B 3
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF 5
+#define INTF0 6
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE 5
+#define INT0 6
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt 0 */
+#define PCINT0_vect_num 2
+#define PCINT0_vect _VECTOR(2) /* External Interrupt Request 0 */
+#define TIM0_OVF_vect_num 3
+#define TIM0_OVF_vect _VECTOR(3) /* Timer/Counter0 Overflow */
+#define EE_RDY_vect_num 4
+#define EE_RDY_vect _VECTOR(4) /* EEPROM Ready */
+#define ANA_COMP_vect_num 5
+#define ANA_COMP_vect _VECTOR(5) /* Analog Comparator */
+#define TIM0_COMPA_vect_num 6
+#define TIM0_COMPA_vect _VECTOR(6) /* Timer/Counter Compare Match A */
+#define TIM0_COMPB_vect_num 7
+#define TIM0_COMPB_vect _VECTOR(7) /* Timer/Counter Compare Match B */
+#define WDT_vect_num 8
+#define WDT_vect _VECTOR(8) /* Watchdog Time-out */
+#define ADC_vect_num 9
+#define ADC_vect _VECTOR(9) /* ADC Conversion Complete */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (10 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (32)
+#define RAMSTART (0x60)
+#define RAMSIZE (64)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND RAMEND
+#define E2END (64 - 1)
+#define E2PAGESIZE (4)
+#define FLASHEND (1024 - 1)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Select start-up time */
+#define FUSE_CKDIV8 (unsigned char)~_BV(4) /* Start up with system clock divided by 8 */
+#define FUSE_WDTON (unsigned char)~_BV(5) /* Watch dog timer always on */
+#define FUSE_EESAVE (unsigned char)~_BV(6) /* Keep EEprom contents during chip erase */
+#define FUSE_SPIEN (unsigned char)~_BV(7) /* SPI programming enable */
+#define LFUSE_DEFAULT (FUSE_SPIEN & FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0) /* Disable external reset */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1) /* Enable BOD and select level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2) /* Enable BOD and select level */
+#define FUSE_DWEN (unsigned char)~_BV(3) /* DebugWire Enable */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(4) /* Self Programming Enable */
+#define HFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x90
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_ATTINY13A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn15.h b/cpukit/score/cpu/avr/avr/iotn15.h
new file mode 100644
index 0000000000..2acc963ba5
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn15.h
@@ -0,0 +1,333 @@
+/* Copyright (c) 2002,2005 Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn15.h - definitions for ATtiny15 */
+
+#ifndef _AVR_IOTN15_H_
+#define _AVR_IOTN15_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn15.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef __ASSEMBLER__
+# warning "MCU not supported by the C compiler"
+#endif
+
+/* I/O registers */
+
+/* 0x00..0x03 reserved */
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16 (0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+#define ADCSR _SFR_IO8(0x06)
+#define ADMUX _SFR_IO8(0x07)
+
+/* Analog Comparator Control and Status Register */
+#define ACSR _SFR_IO8(0x08)
+
+/* 0x09..0x15 reserved */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* 0x19..0x1B reserved */
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* 0x1F..0x20 reserved */
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* 0x22..0x2B reserved */
+#define SFIOR _SFR_IO8(0x2C)
+
+#define OCR1B _SFR_IO8(0x2D)
+#define OCR1A _SFR_IO8(0x2E)
+#define TCNT1 _SFR_IO8(0x2F)
+#define TCCR1 _SFR_IO8(0x30)
+
+/* Oscillator Calibration Register */
+#define OSCCAL _SFR_IO8(0x31)
+
+/* Timer/Counter0 (8-bit) */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU general Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* 0x36..0x37 reserved */
+
+/* Timer/Counter Interrupt Flag Register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK Register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag Register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3C..0x3E reserved */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 0 */
+#define IO_PINS_vect _VECTOR(2)
+#define SIG_PIN _VECTOR(2)
+#define SIG_PIN_CHANGE _VECTOR(2)
+
+/* Timer/Counter1 Compare Match */
+#define TIMER1_COMP_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(3)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW1 _VECTOR(4)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW0 _VECTOR(5)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(6)
+#define SIG_EEPROM_READY _VECTOR(6)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(7)
+#define SIG_COMPARATOR _VECTOR(7)
+
+/* ADC Conversion Ready */
+#define ADC_vect _VECTOR(8)
+#define SIG_ADC _VECTOR(8)
+
+#define _VECTORS_SIZE 18
+
+/* Bit numbers */
+
+/* GIMSK */
+#define INT0 6
+#define PCIE 5
+
+/* GIFR */
+#define INTF0 6
+#define PCIF 5
+
+/* TIMSK */
+#define OCIE1 6
+#define TOIE1 2
+#define TOIE0 1
+
+/* TIFR */
+#define OCF1 6
+#define TOV1 2
+#define TOV0 1
+
+/* MCUCR */
+#define PUD 6
+#define SE 5
+#define SM1 4
+#define SM0 3
+#define ISC01 1
+#define ISC00 0
+
+/* MCUSR */
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* TCCR0 */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* TCCR1 */
+#define CTC1 7
+#define PWM1 6
+#define COM1A1 5
+#define COM1A0 4
+#define CS13 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* SFIOR */
+#define FOC1A 2
+#define PSR1 1
+#define PSR0 0
+
+/* WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PB5 = RESET# / ADC0
+ PB4 = ADC3
+ PB3 = ADC2
+ PB2 = SCK / ADC1 / T0 / INT0
+ PB1 = MISO / AIN1 / OCP
+ PB0 = MOSI / AIN0 / AREF
+ */
+
+/* PORTB */
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* DDRB */
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* PINB */
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* ACSR */
+#define ACD 7
+#define GREF 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIS1 1
+#define ACIS0 0
+
+/* ADMUX */
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* ADCSR */
+#define ADEN 7
+#define ADSC 6
+#define ADFR 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Last memory addresses */
+#define RAMEND 0x1F
+#define XRAMEND 0x0
+#define E2END 0x3F
+#define E2PAGESIZE 2
+#define FLASHEND 0x3FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_RSTDISBL (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_BODEN (unsigned char)~_BV(6)
+#define FUSE_BODLEVEL (unsigned char)~_BV(7)
+#define FUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL1 & FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x90
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOTN15_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn167.h b/cpukit/score/cpu/avr/avr/iotn167.h
new file mode 100644
index 0000000000..71f5d620b1
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn167.h
@@ -0,0 +1,832 @@
+/* Copyright (c) 2008 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iotn167.h - definitions for ATtiny167. */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn167.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOTN167_H_
+#define _AVR_IOTN167_H_ 1
+
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PORTCR _SFR_IO8(0x12)
+#define PUDA 0
+#define PUDB 2
+#define BBMA 4
+#define BBMB 5
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR1 0
+#define PSR0 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x25)
+#define WGM00 0
+#define WGM01 1
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x26)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x27)
+#define TCNT00 0
+#define TCNT01 1
+#define TCNT02 2
+#define TCNT03 3
+#define TCNT04 4
+#define TCNT05 5
+#define TCNT06 6
+#define TCNT07 7
+
+#define OCR0A _SFR_IO8(0x28)
+#define OCR00 0
+#define OCR01 1
+#define OCR02 2
+#define OCR03 3
+#define OCR04 4
+#define OCR05 5
+#define OCR06 6
+#define OCR07 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACIRS 6
+#define ACD 7
+
+#define DWDR _SFR_IO8(0x31)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define PUD 4
+#define BODS 5
+#define BODSE 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+#define SIGRD 5
+#define RWWSB 6
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define CLKCSR _SFR_MEM8(0x62)
+#define CLKC0 0
+#define CLKC1 1
+#define CLKC2 2
+#define CLKC3 3
+#define CLKRDY 4
+#define CLKCCE 7
+
+#define CLKSELR _SFR_MEM8(0x63)
+#define CSEL0 0
+#define CSEL1 1
+#define CSEL2 2
+#define CSEL3 3
+#define CSUT0 4
+#define CSUT1 5
+#define COUT 6
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+#define PRSPI 4
+#define PRLIN 5
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMISCR _SFR_MEM8(0x77)
+#define ISRCEN 0
+#define XREFEN 1
+#define AREFEN 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACIR0 4
+#define ACIR1 5
+#define ACME 6
+#define BIN 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCCR1D _SFR_MEM8(0x83)
+#define OC1AU 0
+#define OC1AV 1
+#define OC1AW 2
+#define OC1AX 3
+#define OC1BU 4
+#define OC1BV 5
+#define OC1BW 6
+#define OC1BX 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM8(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR0BUB 0
+#define TCR0AUB 1
+#define OCR0AUB 3
+#define TCN0UB 4
+#define AS0 5
+#define EXCLK 6
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_MEM8(0xBB)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define USIPP _SFR_MEM8(0xBC)
+#define USIPOS 0
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt Vector 0 is the reset vector. */
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 1 */
+#define WDT_vect _VECTOR(5) /* Watchdog Time-Out Interrupt */
+#define TIMER1_CAPT_vect _VECTOR(6) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect _VECTOR(7) /* Timer/Counter1 Compare Match 1A */
+#define TIMER1_COMPB_vect _VECTOR(8) /* Timer/Counter1 Compare Match 1B */
+#define TIMER1_OVF_vect _VECTOR(9) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect _VECTOR(10) /* Timer/Counter0 Compare Match 0A */
+#define TIMER0_OVF_vect _VECTOR(11) /* Timer/Counter0 Overflow */
+#define LIN_TC_vect _VECTOR(12) /* LIN Transfer Complete */
+#define LIN_ERR_vect _VECTOR(13) /* LIN Error */
+#define SPI_STC_vect _VECTOR(14) /* SPI Serial Transfer Complete */
+#define ADC_vect _VECTOR(15) /* ADC Conversion Complete */
+#define EE_RDY_vect _VECTOR(16) /* EEPROM Ready */
+#define ANA_COMP_vect _VECTOR(17) /* Analog Comparator */
+#define USI_START_vect _VECTOR(18) /* USI Start */
+#define USI_OVF_vect _VECTOR(19) /* USI Overflow */
+
+#define _VECTORS_SIZE (20 * 4)
+
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x100)
+#define RAMSIZE (0x1FF)
+#define RAMEND (RAMSTART + RAMSIZE - 1) /* Last On-Chip SRAM Location */
+#define XRAMSIZE (0)
+#define XRAMEND RAMEND
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x3FFF)
+
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always ON */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x87
+
+
+
+#endif /* _AVR_IOTN167_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn22.h b/cpukit/score/cpu/avr/avr/iotn22.h
new file mode 100644
index 0000000000..0d58d42978
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn22.h
@@ -0,0 +1,205 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn22.h - definitions for ATtiny22 */
+
+#ifndef _AVR_IOTN22_H_
+#define _AVR_IOTN22_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn22.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Input Pins, Port B */
+#define PINB _SFR_IO8(0x16)
+
+/* Data Direction Register, Port B */
+#define DDRB _SFR_IO8(0x17)
+
+/* Data Register, Port B */
+#define PORTB _SFR_IO8(0x18)
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Watchdog Timer Control Register */
+#define WDTCR _SFR_IO8(0x21)
+
+/* Timer/Counter 0 */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* Timer/Counter 0 Control Register */
+#define TCCR0 _SFR_IO8(0x33)
+
+/* MCU Status Register */
+#define MCUSR _SFR_IO8(0x34)
+
+/* MCU general Control Register */
+#define MCUCR _SFR_IO8(0x35)
+
+/* Timer/Counter Interrupt Flag register */
+#define TIFR _SFR_IO8(0x38)
+
+/* Timer/Counter Interrupt MaSK register */
+#define TIMSK _SFR_IO8(0x39)
+
+/* General Interrupt Flag register */
+#define GIFR _SFR_IO8(0x3A)
+
+/* General Interrupt MaSK register */
+#define GIMSK _SFR_IO8(0x3B)
+
+/* 0x3D SP */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF0_vect _VECTOR(2)
+#define SIG_OVERFLOW0 _VECTOR(2)
+
+#define _VECTORS_SIZE 6
+
+/*
+ The Register Bit names are represented by their bit number (0-7).
+ */
+
+/* General Interrupt MaSK register */
+#define INT0 6
+#define INTF0 6
+
+/* General Interrupt Flag Register */
+#define TOIE0 1
+#define TOV0 1
+
+/* MCU general Control Register */
+#define SE 5
+#define SM 4
+#define ISC01 1
+#define ISC00 0
+
+/* Timer/Counter 0 Control Register */
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* Watchdog Timer Control Register */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PB2 = SCK/T0
+ PB1 = MISO/INT0
+ PB0 = MOSI
+ */
+
+/* Data Register, Port B */
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Data Direction Register, Port B */
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Input Pins, Port B */
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* EEPROM Control Register */
+#define EERIE 3
+#define EEMWE 2
+#define EEWE 1
+#define EERE 0
+
+/* Constants */
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 0
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Fuse Byte */
+#define FUSE_CKSEL (unsigned char)~_BV(0)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DEFAULT (FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOTN22_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn2313.h b/cpukit/score/cpu/avr/avr/iotn2313.h
new file mode 100644
index 0000000000..0e7a32573e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn2313.h
@@ -0,0 +1,633 @@
+/* Copyright (c) 2004, 2005, 2006 Bob Paddock
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iotn2313.h derived from io2313.h by Bob Paddock.
+
+ The changes between the AT90S2313 and the ATtiny2313 are extensive.
+
+ Atmel has renamed several registers, and bits. See Atmel application note
+ AVR091, as well as the errata at the end of the current ATtiny2313 data
+ sheet. Some of the names have changed more than once during the sampling
+ period of the ATtiny2313.
+
+ Where there is no conflict the new and old names are both supported.
+
+ In the case of a new feature in a register, only the new name is used.
+ This intentionally breaks old code, so that there are no silent bugs. The
+ source code must be updated to the new name in this case.
+
+ The hardware interrupt vector table has changed from that of the AT90S2313.
+
+ ATtiny2313 programs in page mode rather than the byte mode of the
+ AT90S2313. Beware of programming the ATtiny2313 as a AT90S2313 device,
+ when programming the Flash.
+
+ ATtiny2313 has Signature Bytes: 0x1E 0x91 0x0A.
+
+ Changes and/or additions are noted by "ATtiny" in the comments below. */
+
+/* avr/iotn2313.h - definitions for ATtiny2313 */
+
+#ifndef _AVR_IOTN2313_H_
+#define _AVR_IOTN2313_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn2313.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/*
+ * The Register Bit names are represented by their bit number (0-7).
+ * Example: PORTB |= _BV(PORTB7); Set MSB of PORTB.
+ */
+
+/* 0x00 Reserved */
+
+/* ATtiny Digital Input Disable Register DIDR */
+#define DIDR _SFR_IO8(0x01)
+
+#define AIN1D 1
+#define AIN0D 0
+
+/* ATtiny USART Baud Rate Register High UBBRH[11:8] */
+#define UBRRH _SFR_IO8(0x02)
+
+/* ATtiny USART Control and Status Register C UCSRC */
+#define UCSRC _SFR_IO8(0x03)
+
+#define UMSEL 6
+#define UPM1 5
+#define UPM0 4
+#define USBS 3
+#define UCSZ1 2
+#define UCSZ0 1
+#define UCPOL 0
+
+/* 0x04 -> 0x07 Reserved */
+
+/* ATtiny Analog Comparator Control and Status Register ACSR */
+#define ACSR _SFR_IO8(0x08)
+
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* USART Baud Rate Register Low UBBRL[7:0] */
+#define UBRRL _SFR_IO8(0x09)
+
+/* ATtiny USART Control Register UCSRB */
+#define UCSRB _SFR_IO8(0x0A)
+
+#define RXCIE 7
+#define TXCIE 6
+#define UDRIE 5
+#define RXEN 4
+#define TXEN 3
+#define UCSZ2 2
+#define RXB8 1
+#define TXB8 0
+
+/* ATtiny USART Status Register UCSRA */
+#define UCSRA _SFR_IO8(0x0B)
+
+#define RXC 7
+#define TXC 6
+#define UDRE 5
+#define FE 4
+#define DOR 3
+#define UPE 2
+#define U2X 1
+#define MPCM 0
+
+/* USART I/O Data Register UBR or RXB[7:0], TXB[7:0] */
+#define UDR _SFR_IO8(0x0C)
+#define RXB _SFR_IO8(0x0C)
+#define TXB _SFR_IO8(0x0C)
+
+/* ATtiny USI Control Register USICR */
+#define USICR _SFR_IO8(0x0D)
+
+#define USISIE 7
+#define USIOIE 6
+#define USIWM1 5
+#define USIWM0 4
+#define USICS1 3
+#define USICS0 2
+#define USICLK 1
+#define USITC 0
+
+/* ATtiny USI Status Register USISR */
+#define USISR _SFR_IO8(0x0E)
+
+#define USISIF 7
+#define USIOIF 6
+#define USIPF 5
+#define USIDC 4
+#define USICNT3 3
+#define USICNT2 2
+#define USICNT1 1
+#define USICNT0 0
+
+/* ATtiny USI Data Register USIDR[7:0] */
+#define USIDR _SFR_IO8(0x0F)
+
+/* Input Pins, Port D PIND[6:0] */
+#define PIND _SFR_IO8(0x10)
+
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* Data Direction Register, Port D DDRD[6:0] */
+#define DDRD _SFR_IO8(0x11)
+
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* Data Register, Port D PORTD[6:0] */
+#define PORTD _SFR_IO8(0x12)
+
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* ATtiny General Purpose I/O Register Zero GPIOR0[7:0] */
+#define GPIOR0 _SFR_IO8(0x13)
+
+/* ATtiny General Purpose I/O Register One GPIOR1[7:0] */
+#define GPIOR1 _SFR_IO8(0x14)
+
+/* ATtiny General Purpose I/O Register Two One GPIOR2[7:0] */
+#define GPIOR2 _SFR_IO8(0x15)
+
+/* Input Pins, Port B PORTB[7:0] */
+#define PINB _SFR_IO8(0x16)
+
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* Data Direction Register, Port B PORTB[7:0] */
+#define DDRB _SFR_IO8(0x17)
+
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+/* Data Register, Port B PORTB[7:0] */
+#define PORTB _SFR_IO8(0x18)
+
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Port A Input Pins Address PINA[2:0] */
+#define PINA _SFR_IO8(0x19)
+
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+/* Port A Data Direction Register DDRA[2:0] */
+#define DDRA _SFR_IO8(0x1A)
+
+#define DDRA2 2
+#define DDRA1 1
+#define DDRA0 0
+
+/* Port A Data Register PORTA[2:0] */
+#define PORTA _SFR_IO8(0x1B)
+
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* ATtiny EEPROM Control Register EECR */
+#define EECR _SFR_IO8(0x1C)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* The EEPROM Address Register EEAR[6:0] */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR6 6
+#define EEAR5 5
+#define EEAR4 4
+#define EEAR3 3
+#define EEAR2 2
+#define EEAR1 1
+#define EEAR0 0
+
+/* 0x1F Reserved */
+
+/* ATtiny Pin Change Mask Register PCMSK PCINT[7:0] */
+#define PCMSK _SFR_IO8(0x20)
+
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+/* ATtiny Watchdog Timer Control Register WDTCSR */
+#define WDTCSR _SFR_IO8(0x21)
+
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/* ATtiny Timer/Counter1 Control Register C TCCR1C */
+#define TCCR1C _SFR_IO8(0x22)
+
+#define FOC1A 7
+#define FOC1B 6
+
+/* General Timer/Counter Control Register GTCCR */
+#define GTCCR _SFR_IO8(0x23)
+
+#define PSR10 0
+
+/* T/C 1 Input Capture Register ICR1[15:0] */
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+/* ATtiny Clock Prescale Register */
+#define CLKPR _SFR_IO8(0x26)
+
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+/* 0x27 Reserved */
+
+/* ATtiny Output Compare Register 1 B OCR1B[15:0] */
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+/* Output Compare Register 1 OCR1A[15:0] */
+#define OCR1 _SFR_IO16(0x2A)
+#define OCR1L _SFR_IO8(0x2A)
+#define OCR1H _SFR_IO8(0x2B)
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* Timer/Counter 1 TCNT1[15:0] */
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+/* ATtiny Timer/Counter 1 Control and Status Register TCCR1B */
+#define TCCR1B _SFR_IO8(0x2E)
+
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3 /* Was CTC1 in AT90S2313 */
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+/* ATtiny Timer/Counter 1 Control Register TCCR1A */
+#define TCCR1A _SFR_IO8(0x2F)
+
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define WGM11 1 /* Was PWM11 in AT90S2313 */
+#define WGM10 0 /* Was PWM10 in AT90S2313 */
+
+/* ATtiny Timer/Counter Control Register A TCCR0A */
+#define TCCR0A _SFR_IO8(0x30)
+
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+/* ATtiny Oscillator Calibration Register OSCCAL[6:0] */
+#define OSCCAL _SFR_IO8(0x31)
+
+#define CAL6 6
+#define CAL5 5
+#define CAL4 4
+#define CAL3 3
+#define CAL2 2
+#define CAL1 1
+#define CAL0 0
+
+/* Timer/Counter 0 TCNT0[7:0] */
+#define TCNT0 _SFR_IO8(0x32)
+
+/* ATtiny Timer/Counter 0 Control Register TCCR0B */
+#define TCCR0B _SFR_IO8(0x33)
+
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* ATtiny MCU Status Register MCUSR */
+#define MCUSR _SFR_IO8(0x34)
+
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+/* ATtiny MCU general Control Register MCUCR */
+#define MCUCR _SFR_IO8(0x35)
+
+#define PUD 7
+#define SM1 6
+#define SE 5
+#define SM0 4 /* Some preliminary ATtiny2313 data sheets incorrectly refer
+ to this bit as SMD; was SM in AT90S2313. */
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+/* ATtiny Output Compare Register A OCR0A[7:0] */
+#define OCR0A _SFR_IO8(0x36)
+
+/* ATtiny Store Program Memory Control and Status Register SPMCSR */
+#define SPMCSR _SFR_IO8(0x37)
+
+#define CTPB 4
+#define RFLB 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0 /* The name is used in ATtiny2313.xml file. */
+#define SELFPRGEN 0 /* The name is used in datasheet. */
+#define SELFPRGE 0 /* The name is left for compatibility. */
+
+/* ATtiny Timer/Counter Interrupt Flag register TIFR */
+#define TIFR _SFR_IO8(0x38)
+
+#define TOV1 7
+#define OCF1A 6
+#define OCF1B 5
+#define ICF1 3
+#define OCF0B 2
+#define TOV0 1
+#define OCF0A 0
+
+/* ATtiny Timer/Counter Interrupt MaSK register TIMSK */
+#define TIMSK _SFR_IO8(0x39)
+
+#define TOIE1 7
+#define OCIE1A 6
+#define OCIE1B 5
+#define ICIE1 3
+#define OCIE0B 2
+#define TOIE0 1
+#define OCIE0A 0
+
+/* ATtiny External Interrupt Flag Register EIFR, was GIFR */
+#define EIFR _SFR_IO8(0x3A)
+
+#define INTF1 7
+#define INTF0 6
+#define PCIF 5
+
+/* ATtiny General Interrupt MaSK register GIMSK */
+#define GIMSK _SFR_IO8(0x3B)
+
+#define INT1 7
+#define INT0 6
+#define PCIE 5
+
+/* ATtiny Output Compare Register B OCR0B[7:0] */
+#define OCR0B _SFR_IO8(0x3C)
+
+/* Interrupt vectors: */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+#define SIG_INT0 _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+#define SIG_INT1 _VECTOR(2)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(3)
+#define SIG_INPUT_CAPTURE1 _VECTOR(3)
+#define SIG_TIMER1_CAPT _VECTOR(3)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(4)
+#define SIG_TIMER1_COMPA _VECTOR(4)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(5)
+#define SIG_TIMER1_OVF _VECTOR(5)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(6)
+#define SIG_TIMER0_OVF _VECTOR(6)
+
+/* USART, Rx Complete */
+#define USART_RX_vect _VECTOR(7)
+#define SIG_USART0_RECV _VECTOR(7)
+#define SIG_USART0_RX _VECTOR(7)
+
+/* USART Data Register Empty */
+#define USART_UDRE_vect _VECTOR(8)
+#define SIG_USART0_DATA _VECTOR(8)
+#define SIG_USART0_UDRE _VECTOR(8)
+
+/* USART, Tx Complete */
+#define USART_TX_vect _VECTOR(9)
+#define SIG_USART0_TRANS _VECTOR(9)
+#define SIG_USART0_TX _VECTOR(9)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(10)
+#define SIG_COMPARATOR _VECTOR(10)
+#define SIG_ANALOG_COMP _VECTOR(10)
+#define PCINT_vect _VECTOR(11)
+#define SIG_PIN_CHANGE _VECTOR(11)
+#define SIG_PCINT _VECTOR(11)
+#define TIMER1_COMPB_vect _VECTOR(12)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(12)
+#define SIG_TIMER1_COMPB _VECTOR(12)
+#define TIMER0_COMPA_vect _VECTOR(13)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(13)
+#define SIG_TIMER0_COMPA _VECTOR(13)
+#define TIMER0_COMPB_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(14)
+#define SIG_TIMER0_COMPB _VECTOR(14)
+
+/* USI Start Condition */
+#define USI_START_vect _VECTOR(15)
+#define SIG_USI_START _VECTOR(15)
+#define SIG_USI_START _VECTOR(15)
+
+/* USI Overflow */
+#define USI_OVERFLOW_vect _VECTOR(16)
+#define SIG_USI_OVERFLOW _VECTOR(16)
+#define SIG_USI_OVERFLOW _VECTOR(16)
+#define EEPROM_READY_vect _VECTOR(17)
+#define SIG_EEPROM_READY _VECTOR(17)
+#define SIG_EE_READY _VECTOR(17)
+
+/* Watchdog Timer Overflow */
+#define WDT_OVERFLOW_vect _VECTOR(18)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(18)
+#define SIG_WDT_OVERFLOW _VECTOR(18)
+
+/* 38 = (18*2)+2: Number of vectors times two, plus the reset vector */
+#define _VECTORS_SIZE 38
+
+/* Constants */
+#define SPM_PAGESIZE 32
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 4
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL1 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_RSTDISBL (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(2)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_EESAVE (unsigned char)~_BV(6)
+#define FUSE_DWEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x0A
+
+
+#endif /* _AVR_IOTN2313_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn2313a.h b/cpukit/score/cpu/avr/avr/iotn2313a.h
new file mode 100644
index 0000000000..7f0e94cdd0
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn2313a.h
@@ -0,0 +1,769 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn2313a.h - definitions for ATtiny2313A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn2313a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny2313A_H_
+#define _AVR_ATtiny2313A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define DIDR _SFR_IO8(0x001)
+#define AIN0D 0
+#define AIN1D 1
+
+#define UBRRH _SFR_IO8(0x002)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UCSRC _SFR_IO8(0x003)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL 6
+
+#define PCMSK1 _SFR_IO8(0x004)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+
+#define PCMSK2 _SFR_IO8(0x005)
+#define PCINT11 0
+#define PCINT12 1
+#define PCINT13 2
+#define PCINT14 3
+#define PCINT15 4
+#define PCINT16 5
+#define PCINT17 6
+
+#define PRR _SFR_IO8(0x006)
+#define PRUSART 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define BODCR _SFR_IO8(0x007)
+#define BPDSE 0
+#define BPDS 1
+
+#define ACSR _SFR_IO8(0x008)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define UBRRL _SFR_IO8(0x009)
+#define UBRR0 0
+#define UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UCSRB _SFR_IO8(0x00A)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRA _SFR_IO8(0x00B)
+#define MPCM 0
+#define U2X 1
+#define UPE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UDR _SFR_IO8(0x00C)
+#define UDR0 0
+#define UDR1 1
+#define UDR2 2
+#define UDR3 3
+#define UDR4 4
+#define UDR5 5
+#define UDR6 6
+#define UDR7 7
+
+#define USICR _SFR_IO8(0x00D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x00E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x00F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define PIND _SFR_IO8(0x010)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+
+#define DDRD _SFR_IO8(0x011)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+
+#define PORTD _SFR_IO8(0x012)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+
+#define GPIOR0 _SFR_IO8(0x013)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x014)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x015)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PINB _SFR_IO8(0x016)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x017)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x018)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x019)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+
+#define DDRA _SFR_IO8(0x01A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+
+#define PORTA _SFR_IO8(0x01B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+
+#define EECR _SFR_IO8(0x01C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x01D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO8(0x01E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+
+#define PCMSK _SFR_IO8(0x020)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define WDTCR _SFR_IO8(0x021)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define TCCR1C _SFR_IO8(0x022)
+#define FOC1B 6
+#define FOC1A 7
+
+#define GTCCR _SFR_IO8(0x023)
+#define PSR10 0
+
+#define ICR1 _SFR_IO16(0x024)
+
+#define ICR1L _SFR_IO8(0x024)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_IO8(0x025)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define CLKPR _SFR_IO8(0x026)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define OCR1B _SFR_IO16(0x028)
+
+#define OCR1BL _SFR_IO8(0x028)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_IO8(0x029)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1A _SFR_IO16(0x02A)
+
+#define OCR1AL _SFR_IO8(0x02A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_IO8(0x02B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define TCNT1 _SFR_IO16(0x02C)
+
+#define TCNT1L _SFR_IO8(0x02C)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_IO8(0x02D)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define TCCR1B _SFR_IO8(0x02E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1A _SFR_IO8(0x02F)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR0A _SFR_IO8(0x030)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define OSCCAL _SFR_IO8(0x031)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define TCNT0 _SFR_IO8(0x032)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0B _SFR_IO8(0x033)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define MCUSR _SFR_IO8(0x034)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x035)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define SM0 4
+#define SE 5
+#define SM1 6
+#define PUD 7
+
+#define OCR0A _SFR_IO8(0x036)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define SPMCSR _SFR_IO8(0x037)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR _SFR_IO8(0x038)
+#define OCF0A 0
+#define TOV0 1
+#define OCF0B 2
+#define ICF1 3
+#define OCF1B 5
+#define OCF1A 6
+#define TOV1 7
+
+#define TIMSK _SFR_IO8(0x039)
+#define OCIE0A 0
+#define TOIE0 1
+#define OCIE0B 2
+#define ICIE1 3
+#define OCIE1B 5
+#define OCIE1A 6
+#define TOIE1 7
+
+#define EIFR _SFR_IO8(0x03A)
+#define PCIF 5
+#define INTF0 6
+#define INTF1 7
+
+#define GIMSK _SFR_IO8(0x03B)
+#define PCIE 5
+#define INT0 6
+#define INT1 7
+
+#define OCR0B _SFR_IO8(0x03C)
+#define OCR0_0 0
+#define OCR0_1 1
+#define OCR0_2 2
+#define OCR0_3 3
+#define OCR0_4 4
+#define OCR0_5 5
+#define OCR0_6 6
+#define OCR0_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define TIMER1_CAPT_vect_num 3
+#define TIMER1_CAPT_vect _VECTOR(3) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 4
+#define TIMER1_COMPA_vect _VECTOR(4) /* Timer/Counter1 Compare Match A */
+#define TIMER1_OVF_vect_num 5
+#define TIMER1_OVF_vect _VECTOR(5) /* Timer/Counter1 Overflow */
+#define TIMER0_OVF_vect_num 6
+#define TIMER0_OVF_vect _VECTOR(6) /* Timer/Counter0 Overflow */
+#define USART_RX_vect_num 7
+#define USART_RX_vect _VECTOR(7) /* USART, Rx Complete */
+#define USART_UDRE_vect_num 8
+#define USART_UDRE_vect _VECTOR(8) /* USART Data Register Empty */
+#define USART_TX_vect_num 9
+#define USART_TX_vect _VECTOR(9) /* USART, Tx Complete */
+#define ANA_COMP_vect_num 10
+#define ANA_COMP_vect _VECTOR(10) /* Analog Comparator */
+#define PCINT_B_vect_num 11
+#define PCINT_B_vect _VECTOR(11) /* Pin Change Interrupt Request B */
+#define TIMER1_COMPB_vect_num 12
+#define TIMER1_COMPB_vect _VECTOR(12) /* */
+#define TIMER0_COMPA_vect_num 13
+#define TIMER0_COMPA_vect _VECTOR(13) /* */
+#define TIMER0_COMPB_vect_num 14
+#define TIMER0_COMPB_vect _VECTOR(14) /* */
+#define USI_START_vect_num 15
+#define USI_START_vect _VECTOR(15) /* USI Start Condition */
+#define USI_OVERFLOW_vect_num 16
+#define USI_OVERFLOW_vect _VECTOR(16) /* USI Overflow */
+#define WDT_OVERFLOW_vect_num 18
+#define WDT_OVERFLOW_vect _VECTOR(18) /* Watchdog Timer Overflow */
+#define PCINT_D_vect_num 20
+#define PCINT_D_vect _VECTOR(20) /* Pin Change Interrupt Request D */
+#define EEPROM_Ready_vect_num 17
+#define EEPROM_Ready_vect _VECTOR(17) /* */
+#define PCINT_A_vect_num 19
+#define PCINT_A_vect _VECTOR(19) /* Pin Change Interrupt Request A */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (21 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (32)
+#define RAMSTART (0x60)
+#define RAMSIZE (128)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7F)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x0A
+
+
+/* Device Pin Definitions */
+#define RXD_DDR DDRD
+#define RXD_PORT PORTD
+#define RXD_PIN PIND
+#define RXD_BIT 0
+
+#define TXD_DDR DDRD
+#define TXD_PORT PORTD
+#define TXD_PIN PIND
+#define TXD_BIT 1
+
+#define PA1_DDR DDRXTAL
+#define PA1_PORT PORTXTAL
+#define PA1_PIN PINXTAL
+#define PA1_BIT XTAL2
+
+#define PA0_DDR DDRXTAL
+#define PA0_PORT PORTXTAL
+#define PA0_PIN PINXTAL
+#define PA0_BIT XTAL1
+
+#define INT0_DDR DDRD
+#define INT0_PORT PORTD
+#define INT0_PIN PIND
+#define INT0_BIT 2
+
+#define XCK_DDR DDRD
+#define XCK_PORT PORTD
+#define XCK_PIN PIND
+#define XCK_BIT 2
+
+#define CKOUT_DDR DDRD
+#define CKOUT_PORT PORTD
+#define CKOUT_PIN PIND
+#define CKOUT_BIT 2
+
+#define INT1_DDR DDRD
+#define INT1_PORT PORTD
+#define INT1_PIN PIND
+#define INT1_BIT 3
+
+#define T0_DDR DDRD
+#define T0_PORT PORTD
+#define T0_PIN PIND
+#define T0_BIT 4
+
+#define T1_DDR DDRD
+#define T1_PORT PORTD
+#define T1_PIN PIND
+#define T1_BIT 5
+
+#define OC0B_DDR DDRD
+#define OC0B_PORT PORTD
+#define OC0B_PIN PIND
+#define OC0B_BIT 5
+
+#define ICP_DDR DDRD
+#define ICP_PORT PORTD
+#define ICP_PIN PIND
+#define ICP_BIT 6
+
+#define AIN0_DDR DDRB
+#define AIN0_PORT PORTB
+#define AIN0_PIN PINB
+#define AIN0_BIT 0
+
+#define AIN1_DDR DDRB
+#define AIN1_PORT PORTB
+#define AIN1_PIN PINB
+#define AIN1_BIT 1
+
+#define OC0A_DDR DDRB
+#define OC0A_PORT PORTB
+#define OC0A_PIN PINB
+#define OC0A_BIT 2
+
+#define OC1A_DDR DDRB
+#define OC1A_PORT PORTB
+#define OC1A_PIN PINB
+#define OC1A_BIT 3
+
+#define OC1B_DDR DDRB
+#define OC1B_PORT PORTB
+#define OC1B_PIN PINB
+#define OC1B_BIT 4
+
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 5
+
+#define DI_DDR DDRB
+#define DI_PORT PORTB
+#define DI_PIN PINB
+#define DI_BIT 5
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 6
+
+#define DO_DDR DDRB
+#define DO_PORT PORTB
+#define DO_PIN PINB
+#define DO_BIT 6
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 7
+
+#define SCL_DDR DDRB
+#define SCL_PORT PORTB
+#define SCL_PIN PINB
+#define SCL_BIT 7
+
+#endif /* _AVR_ATtiny2313A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn24.h b/cpukit/score/cpu/avr/avr/iotn24.h
new file mode 100644
index 0000000000..feb8b40281
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn24.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2005, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn24.h - definitions for ATtiny24 */
+
+#ifndef _AVR_IOTN24_H_
+#define _AVR_IOTN24_H_ 1
+
+#include <avr/iotnx4.h>
+
+#define SPM_PAGESIZE 32
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x0B
+
+
+#endif /* _AVR_IOTN24_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn24a.h b/cpukit/score/cpu/avr/avr/iotn24a.h
new file mode 100644
index 0000000000..d715e3acbd
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn24a.h
@@ -0,0 +1,831 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn24a.h - definitions for ATtiny24A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn24a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny24A_H_
+#define _AVR_ATtiny24A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PRR _SFR_IO8(0x00)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADLAR 4
+#define ACME 6
+#define BIN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define MUX5 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define TIFR1 _SFR_IO8(0x0B)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIMSK1 _SFR_IO8(0x0C)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_IO8(0x10)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define PCMSK0 _SFR_IO8(0x12)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define GPIOR0 _SFR_IO8(0x13)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x14)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x15)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define PCMSK1 _SFR_IO8(0x20)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+
+#define WDTCSR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define TCCR1C _SFR_IO8(0x22)
+#define FOC1B 6
+#define FOC1A 7
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define TSM 7
+
+#define ICR1 _SFR_IO16(0x24)
+
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_IO8(0x25)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define CLKPR _SFR_IO8(0x26)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define DWDR _SFR_IO8(0x27)
+
+#define OCR1B _SFR_IO16(0x28)
+
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1A _SFR_IO16(0x2A)
+
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_IO8(0x2B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define TCNT1 _SFR_IO16(0x2C)
+
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define TCCR1B _SFR_IO8(0x2E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1A _SFR_IO8(0x2F)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR0A _SFR_IO8(0x30)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define TCNT0 _SFR_IO8(0x32)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+
+#define OCR0A _SFR_IO8(0x36)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR0 _SFR_IO8(0x38)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIMSK0 _SFR_IO8(0x39)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF0 4
+#define PCIF1 5
+#define INTF0 6
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+
+#define OCR0B _SFR_IO8(0x3C)
+#define OCR0_0 0
+#define OCR0_1 1
+#define OCR0_2 2
+#define OCR0_3 3
+#define OCR0_4 4
+#define OCR0_5 5
+#define OCR0_6 6
+#define OCR0_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define EXT_INT0_vect_num 1
+#define EXT_INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define PCINT0_vect_num 2
+#define PCINT0_vect _VECTOR(2) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 3
+#define PCINT1_vect _VECTOR(3) /* Pin Change Interrupt Request 1 */
+#define WATCHDOG_vect_num 4
+#define WATCHDOG_vect _VECTOR(4) /* Watchdog Time-out */
+#define TIM1_CAPT_vect_num 5
+#define TIM1_CAPT_vect _VECTOR(5) /* Timer/Counter1 Capture Event */
+#define TIM1_COMPA_vect_num 6
+#define TIM1_COMPA_vect _VECTOR(6) /* Timer/Counter1 Compare Match A */
+#define TIM1_COMPB_vect_num 7
+#define TIM1_COMPB_vect _VECTOR(7) /* Timer/Counter1 Compare Match B */
+#define TIM1_OVF_vect_num 8
+#define TIM1_OVF_vect _VECTOR(8) /* Timer/Counter1 Overflow */
+#define TIM0_COMPA_vect_num 9
+#define TIM0_COMPA_vect _VECTOR(9) /* Timer/Counter0 Compare Match A */
+#define TIM0_COMPB_vect_num 10
+#define TIM0_COMPB_vect _VECTOR(10) /* Timer/Counter0 Compare Match B */
+#define TIM0_OVF_vect_num 11
+#define TIM0_OVF_vect _VECTOR(11) /* Timer/Counter0 Overflow */
+#define ANA_COMP_vect_num 12
+#define ANA_COMP_vect _VECTOR(12) /* Analog Comparator */
+#define ADC_vect_num 13
+#define ADC_vect _VECTOR(13) /* ADC Conversion Complete */
+#define EE_RDY_vect_num 14
+#define EE_RDY_vect _VECTOR(14) /* EEPROM Ready */
+#define USI_STR_vect_num 15
+#define USI_STR_vect _VECTOR(15) /* USI START */
+#define USI_OVF_vect_num 16
+#define USI_OVF_vect _VECTOR(16) /* USI Overflow */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (17 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (32)
+#define RAMSTART (0x60)
+#define RAMSIZE (128)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7F)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x0B
+
+
+/* Device Pin Definitions */
+#define ADC4_DDR DDRA
+#define ADC4_PORT PORTA
+#define ADC4_PIN PINA
+#define ADC4_BIT 4
+
+#define USCK_DDR DDRA
+#define USCK_PORT PORTA
+#define USCK_PIN PINA
+#define USCK_BIT 4
+
+#define SCL_DDR DDRA
+#define SCL_PORT PORTA
+#define SCL_PIN PINA
+#define SCL_BIT 4
+
+#define T1_DDR DDRA
+#define T1_PORT PORTA
+#define T1_PIN PINA
+#define T1_BIT 4
+
+#define PCINT4_DDR DDRA
+#define PCINT4_PORT PORTA
+#define PCINT4_PIN PINA
+#define PCINT4_BIT 4
+
+#define ADC3_DDR DDRA
+#define ADC3_PORT PORTA
+#define ADC3_PIN PINA
+#define ADC3_BIT 3
+
+#define T0_DDR DDRA
+#define T0_PORT PORTA
+#define T0_PIN PINA
+#define T0_BIT 3
+
+#define PCINT3_DDR DDRA
+#define PCINT3_PORT PORTA
+#define PCINT3_PIN PINA
+#define PCINT3_BIT 3
+
+#define ADC2_DDR DDRA
+#define ADC2_PORT PORTA
+#define ADC2_PIN PINA
+#define ADC2_BIT 2
+
+#define AIN1_DDR DDRA
+#define AIN1_PORT PORTA
+#define AIN1_PIN PINA
+#define AIN1_BIT 2
+
+#define PCINT2_DDR DDRA
+#define PCINT2_PORT PORTA
+#define PCINT2_PIN PINA
+#define PCINT2_BIT 2
+
+#define ADC1_DDR DDRA
+#define ADC1_PORT PORTA
+#define ADC1_PIN PINA
+#define ADC1_BIT 1
+
+#define AIN0_DDR DDRA
+#define AIN0_PORT PORTA
+#define AIN0_PIN PINA
+#define AIN0_BIT 1
+
+#define PCINT1_DDR DDRA
+#define PCINT1_PORT PORTA
+#define PCINT1_PIN PINA
+#define PCINT1_BIT 1
+
+#define ADC0_DDR DDRA
+#define ADC0_PORT PORTA
+#define ADC0_PIN PINA
+#define ADC0_BIT 0
+
+#define PCINT0_DDR DDRA
+#define PCINT0_PORT PORTA
+#define PCINT0_PIN PINA
+#define PCINT0_BIT 0
+
+#define PCINT8_DDR DDRB
+#define PCINT8_PORT PORTB
+#define PCINT8_PIN PINB
+#define PCINT8_BIT 0
+
+#define PCINT9_DDR DDRB
+#define PCINT9_PORT PORTB
+#define PCINT9_PIN PINB
+#define PCINT9_BIT 1
+
+#define PCINT11_DDR DDRB
+#define PCINT11_PORT PORTB
+#define PCINT11_PIN PINB
+#define PCINT11_BIT 3
+
+#define dW_DDR DDRB
+#define dW_PORT PORTB
+#define dW_PIN PINB
+#define dW_BIT 3
+
+#define PCINT10_DDR DDRB
+#define PCINT10_PORT PORTB
+#define PCINT10_PIN PINB
+#define PCINT10_BIT 2
+
+#define INT0_DDR DDRB
+#define INT0_PORT PORTB
+#define INT0_PIN PINB
+#define INT0_BIT 2
+
+#define OC0A_DDR DDRB
+#define OC0A_PORT PORTB
+#define OC0A_PIN PINB
+#define OC0A_BIT 2
+
+#define CKOUT_DDR DDRB
+#define CKOUT_PORT PORTB
+#define CKOUT_PIN PINB
+#define CKOUT_BIT 2
+
+#define PCINT7_DDR DDRA
+#define PCINT7_PORT PORTA
+#define PCINT7_PIN PINA
+#define PCINT7_BIT 7
+
+#define ICP1_DDR DDRA
+#define ICP1_PORT PORTA
+#define ICP1_PIN PINA
+#define ICP1_BIT 7
+
+#define OC0B_DDR DDRA
+#define OC0B_PORT PORTA
+#define OC0B_PIN PINA
+#define OC0B_BIT 7
+
+#define ADC7_DDR DDRA
+#define ADC7_PORT PORTA
+#define ADC7_PIN PINA
+#define ADC7_BIT 7
+
+#define PCINT6_DDR DDRA
+#define PCINT6_PORT PORTA
+#define PCINT6_PIN PINA
+#define PCINT6_BIT 6
+
+#define OC1A_DDR DDRA
+#define OC1A_PORT PORTA
+#define OC1A_PIN PINA
+#define OC1A_BIT 6
+
+#define DI_DDR DDRA
+#define DI_PORT PORTA
+#define DI_PIN PINA
+#define DI_BIT 6
+
+#define SDA_DDR DDRA
+#define SDA_PORT PORTA
+#define SDA_PIN PINA
+#define SDA_BIT 6
+
+#define MOSI_DDR DDRA
+#define MOSI_PORT PORTA
+#define MOSI_PIN PINA
+#define MOSI_BIT 6
+
+#define ADC6_DDR DDRA
+#define ADC6_PORT PORTA
+#define ADC6_PIN PINA
+#define ADC6_BIT 6
+
+#define ADC5_DDR DDRA
+#define ADC5_PORT PORTA
+#define ADC5_PIN PINA
+#define ADC5_BIT 5
+
+#define DO_DDR DDRA
+#define DO_PORT PORTA
+#define DO_PIN PINA
+#define DO_BIT 5
+
+#define MISO_DDR DDRA
+#define MISO_PORT PORTA
+#define MISO_PIN PINA
+#define MISO_BIT 5
+
+#define OC1B_DDR DDRA
+#define OC1B_PORT PORTA
+#define OC1B_PIN PINA
+#define OC1B_BIT 5
+
+#define PCINT5_DDR DDRA
+#define PCINT5_PORT PORTA
+#define PCINT5_PIN PINA
+#define PCINT5_BIT 5
+
+#endif /* _AVR_ATtiny24A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn25.h b/cpukit/score/cpu/avr/avr/iotn25.h
new file mode 100644
index 0000000000..11e7a560c8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn25.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2005, Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn25.h - definitions for ATtiny25 */
+
+#ifndef _AVR_IOTN25_H_
+#define _AVR_IOTN25_H_ 1
+
+#include <avr/iotnx5.h>
+
+#define SPM_PAGESIZE 32
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x08
+
+
+#endif /* _AVR_IOTN25_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn26.h b/cpukit/score/cpu/avr/avr/iotn26.h
new file mode 100644
index 0000000000..dae6f0f518
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn26.h
@@ -0,0 +1,385 @@
+/* Copyright (c) 2004,2005 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn26.h - definitions for ATtiny26 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn26.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef _AVR_IOTN26_H_
+#define _AVR_IOTN26_H_ 1
+
+/* Registers and associated bit numbers */
+
+/* Reserved [0x00..0x03] */
+
+#define ADCW _SFR_IO16(0x04)
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+#define ADCSR _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADFR 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACME 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+/* Reserved [0x09..0x0C] */
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+
+/* Reserved [0x10..0x15] */
+
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PB0 0
+#define PB1 1
+#define PB2 2
+#define PB3 3
+#define PB4 4
+#define PB5 5
+#define PB6 6
+#define PB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PA0 0
+#define PA1 1
+#define PA2 2
+#define PA3 3
+#define PA4 4
+#define PA5 5
+#define PA6 6
+#define PA7 7
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEWE 1
+#define EEMWE 2
+#define EERIE 3
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO8(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+
+/* Reserved [0x1F..0x20] */
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+
+/* Reserved [0x22..0x28] */
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PCKE 2
+
+/* Reserved [0x2A] */
+
+#define OCR1C _SFR_IO8(0x2B)
+
+#define OCR1B _SFR_IO8(0x2C)
+
+#define OCR1A _SFR_IO8(0x2D)
+
+#define TCNT1 _SFR_IO8(0x2E)
+
+#define TCCR1B _SFR_IO8(0x2F)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define CS13 3
+#define PSR1 6
+#define CTC1 7
+
+#define TCCR1A _SFR_IO8(0x30)
+#define PWM1B 0
+#define PWM1A 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+
+#define TCNT0 _SFR_IO8(0x32)
+
+#define TCCR0 _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define PSR0 3
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+
+/* Reserved [0x36..0x37] */
+
+#define TIFR _SFR_IO8(0x38)
+#define TOV0 1
+#define TOV1 2
+#define OCF1B 5
+#define OCF1A 6
+
+#define TIMSK _SFR_IO8(0x39)
+#define TOIE0 1
+#define TOIE1 2
+#define OCIE1B 5
+#define OCIE1A 6
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF 5
+#define INTF0 6
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+
+/* Reserved [0x3C] */
+
+/* SP [0x3D] */
+
+/* Reserved [0x3E] */
+
+/* SREG [0x3F] */
+
+
+/* Interrupt vectors */
+/* Interrupt vector 0 is the reset vector. */
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt Request 0 */
+#define IO_PINS_vect _VECTOR(2)
+#define SIG_PIN_CHANGE _VECTOR(2)
+
+/* Timer/Counter1 Compare Match 1A */
+#define TIMER1_CMPA_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(3)
+
+/* Timer/Counter1 Compare Match 1B */
+#define TIMER1_CMPB_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(4)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF1_vect _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(5)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF0_vect _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(6)
+
+/* USI Start */
+#define USI_STRT_vect _VECTOR(7)
+#define SIG_USI_START _VECTOR(7)
+
+/* USI Overflow */
+#define USI_OVF_vect _VECTOR(8)
+#define SIG_USI_OVERFLOW _VECTOR(8)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(9)
+#define SIG_EEPROM_READY _VECTOR(9)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(10)
+#define SIG_ANA_COMP _VECTOR(10)
+#define SIG_COMPARATOR _VECTOR(10)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(11)
+#define SIG_ADC _VECTOR(11)
+
+#define _VECTORS_SIZE 24
+
+
+/* Constants */
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 4
+#define FLASHEND 0x07FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 2
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOPT (unsigned char)~_BV(6)
+#define FUSE_PLLCK (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0)
+
+/* High Fuse Byte */
+#define FUSE_BODEN (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL (unsigned char)~_BV(1)
+#define FUSE_EESAVE (unsigned char)~_BV(2)
+#define FUSE_SPIEN (unsigned char)~_BV(3)
+#define FUSE_RSTDISBL (unsigned char)~_BV(4)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x09
+
+
+#endif /* _AVR_IOTN26_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn261.h b/cpukit/score/cpu/avr/avr/iotn261.h
new file mode 100644
index 0000000000..bc23199ec3
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn261.h
@@ -0,0 +1,88 @@
+/* Copyright (c) 2006, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn261.h - definitions for ATtiny261 */
+
+#ifndef _AVR_IOTN261_H_
+#define _AVR_IOTN261_H_ 1
+
+#include <avr/iotnx61.h>
+
+#define SPM_PAGESIZE 32
+#define RAMEND 0xDF
+#define XRAMEND RAMEND
+#define E2END 0x7F
+#define E2PAGESIZE 4
+#define FLASHEND 0x7FF
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x0C
+
+
+#endif /* _AVR_IOTN261_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn261a.h b/cpukit/score/cpu/avr/avr/iotn261a.h
new file mode 100644
index 0000000000..23fa2f5307
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn261a.h
@@ -0,0 +1,976 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn261a.h - definitions for ATtiny261A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn261a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny261A_H_
+#define _AVR_ATtiny261A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define TCCR1E _SFR_IO8(0x00)
+#define OC1OE0 0
+#define OC1OE1 1
+#define OC1OE2 2
+#define OC1OE3 3
+#define OC1OE4 4
+#define OC1OE5 5
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define AREFD 3
+#define ADC3D 4
+#define ADC4D 5
+#define ADC5D 6
+#define ADC6D 7
+
+#define DIDR1 _SFR_IO8(0x02)
+#define ADC7D 4
+#define ADC8D 5
+#define ADC9D 6
+#define ADC10D 7
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define MUX5 3
+#define REFS2 4
+#define IPR 5
+#define GSEL 6
+#define BIN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSRA _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACME 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define ACSRB _SFR_IO8(0x09)
+#define ACM0 0
+#define ACM1 1
+#define ACM2 2
+#define HLEV 6
+#define HSEL 7
+
+#define GPIOR0 _SFR_IO8(0x0A)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x0B)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x0C)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_IO8(0x10)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define USIPP _SFR_IO8(0x11)
+#define USIPOS 0
+
+#define OCR0B _SFR_IO8(0x12)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define OCR0A _SFR_IO8(0x13)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define TCNT0H _SFR_IO8(0x14)
+#define TCNT0H_0 0
+#define TCNT0H_1 1
+#define TCNT0H_2 2
+#define TCNT0H_3 3
+#define TCNT0H_4 4
+#define TCNT0H_5 5
+#define TCNT0H_6 6
+#define TCNT0H_7 7
+
+#define TCCR0A _SFR_IO8(0x15)
+#define WGM00 0
+#define ACIC0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define DWDR _SFR_IO8(0x20)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define PCMSK1 _SFR_IO8(0x22)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK0 _SFR_IO8(0x23)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define DT1 _SFR_IO8(0x24)
+#define DT1L0 0
+#define DT1L1 1
+#define DT1L2 2
+#define DT1L3 3
+#define DT1H0 4
+#define DT1H1 5
+#define DT1H2 6
+#define DT1H3 7
+
+#define TC1H _SFR_IO8(0x25)
+#define TC18 0
+#define TC19 1
+
+#define TCCR1D _SFR_IO8(0x26)
+#define WGM10 0
+#define WGM11 1
+#define FPF1 2
+#define FPAC1 3
+#define FPES1 4
+#define FPNC1 5
+#define FPEN1 6
+#define FPIE1 7
+
+#define TCCR1C _SFR_IO8(0x27)
+#define PWM1D 0
+#define FOC1D 1
+#define COM1D0 2
+#define COM1D1 3
+#define COM1B0S 4
+#define COM1B1S 5
+#define COM1A0S 6
+#define COM1A1S 7
+
+#define CLKPR _SFR_IO8(0x28)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PCKE 2
+#define LSM 7
+
+#define OCR1D _SFR_IO8(0x2A)
+#define OCR1D0 0
+#define OCR1D1 1
+#define OCR1D2 2
+#define OCR1D3 3
+#define OCR1D4 4
+#define OCR1D5 5
+#define OCR1D6 6
+#define OCR1D7 7
+
+#define OCR1C _SFR_IO8(0x2B)
+#define OCR1C0 0
+#define OCR1C1 1
+#define OCR1C2 2
+#define OCR1C3 3
+#define OCR1C4 4
+#define OCR1C5 5
+#define OCR1C6 6
+#define OCR1C7 7
+
+#define OCR1B _SFR_IO8(0x2C)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define OCR1A _SFR_IO8(0x2D)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define TCNT1 _SFR_IO8(0x2E)
+#define TC1H_0 0
+#define TC1H_1 1
+#define TC1H_2 2
+#define TC1H_3 3
+#define TC1H_4 4
+#define TC1H_5 5
+#define TC1H_6 6
+#define TC1H_7 7
+
+#define TCCR1B _SFR_IO8(0x2F)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define CS13 3
+#define DTPS10 4
+#define DTPS11 5
+#define PSR1 6
+
+#define TCCR1A _SFR_IO8(0x30)
+#define PWM1B 0
+#define PWM1A 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define TCNT0L _SFR_IO8(0x32)
+#define TCNT0L_0 0
+#define TCNT0L_1 1
+#define TCNT0L_2 2
+#define TCNT0L_3 3
+#define TCNT0L_4 4
+#define TCNT0L_5 5
+#define TCNT0L_6 6
+#define TCNT0L_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define PSR0 3
+#define TSM 4
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define BODSE 2
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+#define BODS 7
+
+#define PRR _SFR_IO8(0x36)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR _SFR_IO8(0x38)
+#define ICF0 0
+#define TOV0 1
+#define TOV1 2
+#define OCF0B 3
+#define OCF0A 4
+#define OCF1B 5
+#define OCF1A 6
+#define OCF1D 7
+
+#define TIMSK _SFR_IO8(0x39)
+#define TICIE0 0
+#define TOIE0 1
+#define TOIE1 2
+#define OCIE0B 3
+#define OCIE0A 4
+#define OCIE1B 5
+#define OCIE1A 6
+#define OCIE1D 7
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF 5
+#define INTF0 6
+#define INTF1 7
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+#define INT1 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt 0 */
+#define PCINT_vect_num 2
+#define PCINT_vect _VECTOR(2) /* Pin Change Interrupt */
+#define TIMER1_COMPA_vect_num 3
+#define TIMER1_COMPA_vect _VECTOR(3) /* Timer/Counter1 Compare Match 1A */
+#define TIMER1_COMPB_vect_num 4
+#define TIMER1_COMPB_vect _VECTOR(4) /* Timer/Counter1 Compare Match 1B */
+#define TIMER1_OVF_vect_num 5
+#define TIMER1_OVF_vect _VECTOR(5) /* Timer/Counter1 Overflow */
+#define TIMER0_OVF_vect_num 6
+#define TIMER0_OVF_vect _VECTOR(6) /* Timer/Counter0 Overflow */
+#define USI_START_vect_num 7
+#define USI_START_vect _VECTOR(7) /* USI Start */
+#define USI_OVF_vect_num 8
+#define USI_OVF_vect _VECTOR(8) /* USI Overflow */
+#define EE_RDY_vect_num 9
+#define EE_RDY_vect _VECTOR(9) /* EEPROM Ready */
+#define ANA_COMP_vect_num 10
+#define ANA_COMP_vect _VECTOR(10) /* Analog Comparator */
+#define ADC_vect_num 11
+#define ADC_vect _VECTOR(11) /* ADC Conversion Complete */
+#define WDT_vect_num 12
+#define WDT_vect _VECTOR(12) /* Watchdog Time-Out */
+#define INT1_vect_num 13
+#define INT1_vect _VECTOR(13) /* External Interrupt 1 */
+#define TIMER0_COMPA_vect_num 14
+#define TIMER0_COMPA_vect _VECTOR(14) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 15
+#define TIMER0_COMPB_vect _VECTOR(15) /* Timer/Counter0 Compare Match B */
+#define TIMER0_CAPT_vect_num 16
+#define TIMER0_CAPT_vect _VECTOR(16) /* ADC Conversion Complete */
+#define TIMER1_COMPD_vect_num 17
+#define TIMER1_COMPD_vect _VECTOR(17) /* Timer/Counter1 Compare Match D */
+#define FAULT_PROTECTION_vect_num 18
+#define FAULT_PROTECTION_vect _VECTOR(18) /* Timer/Counter1 Fault Protection */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (19 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (32)
+#define RAMSTART (0x60)
+#define RAMSIZE (128)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x7F)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x7FF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x0C
+
+
+/* Device Pin Definitions */
+#define DI_B_DDR DDRMOSI
+#define DI_B_PORT PORTMOSI
+#define DI_B_PIN PINMOSI
+#define DI_B_BIT MOSI
+
+#define SDA_B_DDR DDRMOSI
+#define SDA_B_PORT PORTMOSI
+#define SDA_B_PIN PINMOSI
+#define SDA_B_BIT MOSI
+
+#define _OC1A_DDR DDRMOSI
+#define _OC1A_PORT PORTMOSI
+#define _OC1A_PIN PINMOSI
+#define _OC1A_BIT MOSI
+
+#define PCINT8_DDR DDRMOSI
+#define PCINT8_PORT PORTMOSI
+#define PCINT8_PIN PINMOSI
+#define PCINT8_BIT MOSI
+
+#define PB0_DDR DDRMOSI
+#define PB0_PORT PORTMOSI
+#define PB0_PIN PINMOSI
+#define PB0_BIT MOSI
+
+#define DO_B_DDR DDRMISO
+#define DO_B_PORT PORTMISO
+#define DO_B_PIN PINMISO
+#define DO_B_BIT MISO
+
+#define OC1A_DDR DDRMISO
+#define OC1A_PORT PORTMISO
+#define OC1A_PIN PINMISO
+#define OC1A_BIT MISO
+
+#define PCINT9_DDR DDRMISO
+#define PCINT9_PORT PORTMISO
+#define PCINT9_PIN PINMISO
+#define PCINT9_BIT MISO
+
+#define PB1_DDR DDRMISO
+#define PB1_PORT PORTMISO
+#define PB1_PIN PINMISO
+#define PB1_BIT MISO
+
+#define USCK_B_DDR DDRSCK
+#define USCK_B_PORT PORTSCK
+#define USCK_B_PIN PINSCK
+#define USCK_B_BIT SCK
+
+#define SCL_B_DDR DDRSCK
+#define SCL_B_PORT PORTSCK
+#define SCL_B_PIN PINSCK
+#define SCL_B_BIT SCK
+
+#define OC1B_DDR DDRSCK
+#define OC1B_PORT PORTSCK
+#define OC1B_PIN PINSCK
+#define OC1B_BIT SCK
+
+#define PCINT10_DDR DDRSCK
+#define PCINT10_PORT PORTSCK
+#define PCINT10_PIN PINSCK
+#define PCINT10_BIT SCK
+
+#define PB2_DDR DDRSCK
+#define PB2_PORT PORTSCK
+#define PB2_PIN PINSCK
+#define PB2_BIT SCK
+
+#define PCINT11_DDR DDROC1B
+#define PCINT11_PORT PORTOC1B
+#define PCINT11_PIN PINOC1B
+#define PCINT11_BIT OC1B
+
+#define PB3_DDR DDROC1B
+#define PB3_PORT PORTOC1B
+#define PB3_PIN PINOC1B
+#define PB3_BIT OC1B
+
+#define PCINT12_DDR DDRADC
+#define PCINT12_PORT PORTADC
+#define PCINT12_PIN PINADC
+#define PCINT12_BIT ADC7
+
+#define _OC1D_DDR DDRADC
+#define _OC1D_PORT PORTADC
+#define _OC1D_PIN PINADC
+#define _OC1D_BIT ADC7
+
+#define CLKI_DDR DDRADC
+#define CLKI_PORT PORTADC
+#define CLKI_PIN PINADC
+#define CLKI_BIT ADC7
+
+#define PB4_DDR DDRADC
+#define PB4_PORT PORTADC
+#define PB4_PIN PINADC
+#define PB4_BIT ADC7
+
+#define PCINT13_DDR DDRADC
+#define PCINT13_PORT PORTADC
+#define PCINT13_PIN PINADC
+#define PCINT13_BIT ADC8
+
+#define OC1D_DDR DDRADC
+#define OC1D_PORT PORTADC
+#define OC1D_PIN PINADC
+#define OC1D_BIT ADC8
+
+#define CKLO_DDR DDRADC
+#define CKLO_PORT PORTADC
+#define CKLO_PIN PINADC
+#define CKLO_BIT ADC8
+
+#define PB5_DDR DDRADC
+#define PB5_PORT PORTADC
+#define PB5_PIN PINADC
+#define PB5_BIT ADC8
+
+#define INT0_DDR DDRADC
+#define INT0_PORT PORTADC
+#define INT0_PIN PINADC
+#define INT0_BIT ADC9
+
+#define T0_DDR DDRADC
+#define T0_PORT PORTADC
+#define T0_PIN PINADC
+#define T0_BIT ADC9
+
+#define PCINT14_DDR DDRADC
+#define PCINT14_PORT PORTADC
+#define PCINT14_PIN PINADC
+#define PCINT14_BIT ADC9
+
+#define PB6_DDR DDRADC
+#define PB6_PORT PORTADC
+#define PB6_PIN PINADC
+#define PB6_BIT ADC9
+
+#define PCINT15_DDR DDRADC1
+#define PCINT15_PORT PORTADC1
+#define PCINT15_PIN PINADC1
+#define PCINT15_BIT ADC10
+
+#define PB7_DDR DDRADC1
+#define PB7_PORT PORTADC1
+#define PB7_PIN PINADC1
+#define PB7_BIT ADC10
+
+#define AIN1_DDR DDRADC
+#define AIN1_PORT PORTADC
+#define AIN1_PIN PINADC
+#define AIN1_BIT ADC6
+
+#define PCINT7_DDR DDRADC
+#define PCINT7_PORT PORTADC
+#define PCINT7_PIN PINADC
+#define PCINT7_BIT ADC6
+
+#define PA7_DDR DDRADC
+#define PA7_PORT PORTADC
+#define PA7_PIN PINADC
+#define PA7_BIT ADC6
+
+#define AIN0_DDR DDRADC
+#define AIN0_PORT PORTADC
+#define AIN0_PIN PINADC
+#define AIN0_BIT ADC5
+
+#define PCINT6_DDR DDRADC
+#define PCINT6_PORT PORTADC
+#define PCINT6_PIN PINADC
+#define PCINT6_BIT ADC5
+
+#define PA6_DDR DDRADC
+#define PA6_PORT PORTADC
+#define PA6_PIN PINADC
+#define PA6_BIT ADC5
+
+#define AIN2_DDR DDRADC
+#define AIN2_PORT PORTADC
+#define AIN2_PIN PINADC
+#define AIN2_BIT ADC4
+
+#define PCINT5_DDR DDRADC
+#define PCINT5_PORT PORTADC
+#define PCINT5_PIN PINADC
+#define PCINT5_BIT ADC4
+
+#define PA5_DDR DDRADC
+#define PA5_PORT PORTADC
+#define PA5_PIN PINADC
+#define PA5_BIT ADC4
+
+#define ICP0_DDR DDRADC
+#define ICP0_PORT PORTADC
+#define ICP0_PIN PINADC
+#define ICP0_BIT ADC3
+
+#define PCINT4_DDR DDRADC
+#define PCINT4_PORT PORTADC
+#define PCINT4_PIN PINADC
+#define PCINT4_BIT ADC3
+
+#define PA4_DDR DDRADC
+#define PA4_PORT PORTADC
+#define PA4_PIN PINADC
+#define PA4_BIT ADC3
+
+#define PCINT3_DDR DDRAREF
+#define PCINT3_PORT PORTAREF
+#define PCINT3_PIN PINAREF
+#define PCINT3_BIT AREF
+
+#define PA3_DDR DDRAREF
+#define PA3_PORT PORTAREF
+#define PA3_PIN PINAREF
+#define PA3_BIT AREF
+
+#define INT1_DDR DDRADC
+#define INT1_PORT PORTADC
+#define INT1_PIN PINADC
+#define INT1_BIT ADC2
+
+#define USCK_A_DDR DDRADC
+#define USCK_A_PORT PORTADC
+#define USCK_A_PIN PINADC
+#define USCK_A_BIT ADC2
+
+#define SCL_A_DDR DDRADC
+#define SCL_A_PORT PORTADC
+#define SCL_A_PIN PINADC
+#define SCL_A_BIT ADC2
+
+#define PCINT2_DDR DDRADC
+#define PCINT2_PORT PORTADC
+#define PCINT2_PIN PINADC
+#define PCINT2_BIT ADC2
+
+#define PA2_DDR DDRADC
+#define PA2_PORT PORTADC
+#define PA2_PIN PINADC
+#define PA2_BIT ADC2
+
+#define DO_A_DDR DDRADC
+#define DO_A_PORT PORTADC
+#define DO_A_PIN PINADC
+#define DO_A_BIT ADC1
+
+#define PCINT1_DDR DDRADC
+#define PCINT1_PORT PORTADC
+#define PCINT1_PIN PINADC
+#define PCINT1_BIT ADC1
+
+#define PA1_DDR DDRADC
+#define PA1_PORT PORTADC
+#define PA1_PIN PINADC
+#define PA1_BIT ADC1
+
+#define DI_A_DDR DDRADC
+#define DI_A_PORT PORTADC
+#define DI_A_PIN PINADC
+#define DI_A_BIT ADC0
+
+#define SDA_A_DDR DDRADC
+#define SDA_A_PORT PORTADC
+#define SDA_A_PIN PINADC
+#define SDA_A_BIT ADC0
+
+#define PCINT0_DDR DDRADC
+#define PCINT0_PORT PORTADC
+#define PCINT0_PIN PINADC
+#define PCINT0_BIT ADC0
+
+#define PA0_DDR DDRADC
+#define PA0_PORT PORTADC
+#define PA0_PIN PINADC
+#define PA0_BIT ADC0
+
+#endif /* _AVR_ATtiny261A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn28.h b/cpukit/score/cpu/avr/avr/iotn28.h
new file mode 100644
index 0000000000..9ecfe984d6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn28.h
@@ -0,0 +1,275 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn28.h - definitions for ATtiny28 */
+
+#ifndef _AVR_IOTN28_H_
+#define _AVR_IOTN28_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn28.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef __ASSEMBLER__
+# warning "MCU not supported by the C compiler"
+#endif
+
+/* I/O registers */
+
+#define OSCCAL _SFR_IO8(0x00)
+
+#define WDTCR _SFR_IO8(0x01)
+
+#define MODCR _SFR_IO8(0x02)
+
+#define TCNT0 _SFR_IO8(0x03)
+#define TCCR0 _SFR_IO8(0x04)
+
+#define IFR _SFR_IO8(0x05)
+#define ICR _SFR_IO8(0x06)
+
+#define MCUCS _SFR_IO8(0x07)
+
+#define ACSR _SFR_IO8(0x08)
+
+/* 0x09..0x0F reserved */
+
+#define PIND _SFR_IO8(0x10)
+#define DDRD _SFR_IO8(0x11)
+#define PORTD _SFR_IO8(0x12)
+
+/* 0x13..0x15 reserved */
+
+#define PINB _SFR_IO8(0x16)
+
+/* 0x17..0x18 reserved */
+
+#define PINA _SFR_IO8(0x19)
+#define PACR _SFR_IO8(0x1A)
+#define PORTA _SFR_IO8(0x1B)
+
+/* 0x1C..0x3E reserved */
+
+/* 0x3F SREG */
+
+/* Interrupt vectors */
+
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(2)
+#define SIG_INTERRUPT1 _VECTOR(2)
+
+/* Low-level Input on Port B */
+#define LOWLEVEL_IO_PINS_vect _VECTOR(3)
+#define SIG_PIN _VECTOR(3)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW0 _VECTOR(4)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(5)
+#define SIG_COMPARATOR _VECTOR(5)
+
+#define _VECTORS_SIZE 12
+
+
+/* Bit numbers */
+
+/* ICR */
+#define INT1 7
+#define INT0 6
+#define LLIE 5
+#define TOIE0 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00
+
+/* IFR */
+#define INTF1 7
+#define INTF0 6
+#define TOV0 4
+
+/* MCUCS */
+#define PLUPB 7
+#define SE 5
+#define SM 4
+#define WDRF 3
+#define EXTRF 1
+#define PORF 0
+
+/* TCCR0 */
+#define FOV0 7
+#define OOM01 4
+#define OOM00 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+/* MODCR */
+#define ONTIM4 7
+#define ONTIM3 6
+#define ONTIM2 5
+#define ONTIM1 4
+#define ONTIM0 3
+#define MCONF2 2
+#define MCONF1 1
+#define MCONF0 0
+
+/* WDTCR */
+#define WDTOE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+/*
+ PA2 = IR
+ */
+
+/* PORTA */
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* PACR */
+#define DDA3 3
+#define PA2HC 2
+#define DDA1 1
+#define DDA0 0
+
+/* PINA */
+#define PINA3 3
+#define PINA1 1
+#define PINA0 0
+
+/*
+ PB4 = INT1
+ PB3 = INT0
+ PB2 = T0
+ PB1 = AIN1
+ PB0 = AIN0
+ */
+
+/* PINB */
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+/* PORTD */
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* DDRD */
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+/* PIND */
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+/* ACSR */
+#define ACD 7
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIS1 1
+#define ACIS0 0
+
+/* Last memory addresses */
+#define RAMEND 0x1F
+#define XRAMEND 0x0
+#define E2END 0x0
+#define E2PAGESIZE 0
+#define FLASHEND 0x7FF
+
+
+/* Fuses */
+
+#define FUSE_MEMORY_SIZE 1
+
+/* Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_INTCAP (unsigned char)~_BV(4)
+#define FUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x91
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOTN28_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn4313.h b/cpukit/score/cpu/avr/avr/iotn4313.h
new file mode 100644
index 0000000000..e5b9a4b3c4
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn4313.h
@@ -0,0 +1,769 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn4313.h - definitions for ATtiny4313 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn4313.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny4313_H_
+#define _AVR_ATtiny4313_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define DIDR _SFR_IO8(0x001)
+#define AIN0D 0
+#define AIN1D 1
+
+#define UBRRH _SFR_IO8(0x002)
+#define UBRR8 0
+#define UBRR9 1
+#define UBRR10 2
+#define UBRR11 3
+
+#define UCSRC _SFR_IO8(0x003)
+#define UCPOL 0
+#define UCSZ0 1
+#define UCSZ1 2
+#define USBS 3
+#define UPM0 4
+#define UPM1 5
+#define UMSEL 6
+
+#define PCMSK1 _SFR_IO8(0x004)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+
+#define PCMSK2 _SFR_IO8(0x005)
+#define PCINT11 0
+#define PCINT12 1
+#define PCINT13 2
+#define PCINT14 3
+#define PCINT15 4
+#define PCINT16 5
+#define PCINT17 6
+
+#define PRR _SFR_IO8(0x006)
+#define PRUSART 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define BODCR _SFR_IO8(0x007)
+#define BPDSE 0
+#define BPDS 1
+
+#define ACSR _SFR_IO8(0x008)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define UBRRL _SFR_IO8(0x009)
+#define UBRR0 0
+#define UBRR1 1
+#define UBRR2 2
+#define UBRR3 3
+#define UBRR4 4
+#define UBRR5 5
+#define UBRR6 6
+#define UBRR7 7
+
+#define UCSRB _SFR_IO8(0x00A)
+#define TXB8 0
+#define RXB8 1
+#define UCSZ2 2
+#define TXEN 3
+#define RXEN 4
+#define UDRIE 5
+#define TXCIE 6
+#define RXCIE 7
+
+#define UCSRA _SFR_IO8(0x00B)
+#define MPCM 0
+#define U2X 1
+#define UPE 2
+#define DOR 3
+#define FE 4
+#define UDRE 5
+#define TXC 6
+#define RXC 7
+
+#define UDR _SFR_IO8(0x00C)
+#define UDR0 0
+#define UDR1 1
+#define UDR2 2
+#define UDR3 3
+#define UDR4 4
+#define UDR5 5
+#define UDR6 6
+#define UDR7 7
+
+#define USICR _SFR_IO8(0x00D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x00E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x00F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define PIND _SFR_IO8(0x010)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+
+#define DDRD _SFR_IO8(0x011)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+
+#define PORTD _SFR_IO8(0x012)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+
+#define GPIOR0 _SFR_IO8(0x013)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x014)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x015)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PINB _SFR_IO8(0x016)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x017)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x018)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x019)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+
+#define DDRA _SFR_IO8(0x01A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+
+#define PORTA _SFR_IO8(0x01B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+
+#define EECR _SFR_IO8(0x01C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x01D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO8(0x01E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+
+#define PCMSK _SFR_IO8(0x020)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define WDTCR _SFR_IO8(0x021)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define TCCR1C _SFR_IO8(0x022)
+#define FOC1B 6
+#define FOC1A 7
+
+#define GTCCR _SFR_IO8(0x023)
+#define PSR10 0
+
+#define ICR1 _SFR_IO16(0x024)
+
+#define ICR1L _SFR_IO8(0x024)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_IO8(0x025)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define CLKPR _SFR_IO8(0x026)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define OCR1B _SFR_IO16(0x028)
+
+#define OCR1BL _SFR_IO8(0x028)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_IO8(0x029)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1A _SFR_IO16(0x02A)
+
+#define OCR1AL _SFR_IO8(0x02A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_IO8(0x02B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define TCNT1 _SFR_IO16(0x02C)
+
+#define TCNT1L _SFR_IO8(0x02C)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_IO8(0x02D)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define TCCR1B _SFR_IO8(0x02E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1A _SFR_IO8(0x02F)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR0A _SFR_IO8(0x030)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define OSCCAL _SFR_IO8(0x031)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+
+#define TCNT0 _SFR_IO8(0x032)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0B _SFR_IO8(0x033)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define MCUSR _SFR_IO8(0x034)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x035)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+#define SM0 4
+#define SE 5
+#define SM1 6
+#define PUD 7
+
+#define OCR0A _SFR_IO8(0x036)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define SPMCSR _SFR_IO8(0x037)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR _SFR_IO8(0x038)
+#define OCF0A 0
+#define TOV0 1
+#define OCF0B 2
+#define ICF1 3
+#define OCF1B 5
+#define OCF1A 6
+#define TOV1 7
+
+#define TIMSK _SFR_IO8(0x039)
+#define OCIE0A 0
+#define TOIE0 1
+#define OCIE0B 2
+#define ICIE1 3
+#define OCIE1B 5
+#define OCIE1A 6
+#define TOIE1 7
+
+#define EIFR _SFR_IO8(0x03A)
+#define PCIF 5
+#define INTF0 6
+#define INTF1 7
+
+#define GIMSK _SFR_IO8(0x03B)
+#define PCIE 5
+#define INT0 6
+#define INT1 7
+
+#define OCR0B _SFR_IO8(0x03C)
+#define OCR0_0 0
+#define OCR0_1 1
+#define OCR0_2 2
+#define OCR0_3 3
+#define OCR0_4 4
+#define OCR0_5 5
+#define OCR0_6 6
+#define OCR0_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define TIMER1_CAPT_vect_num 3
+#define TIMER1_CAPT_vect _VECTOR(3) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 4
+#define TIMER1_COMPA_vect _VECTOR(4) /* Timer/Counter1 Compare Match A */
+#define TIMER1_OVF_vect_num 5
+#define TIMER1_OVF_vect _VECTOR(5) /* Timer/Counter1 Overflow */
+#define TIMER0_OVF_vect_num 6
+#define TIMER0_OVF_vect _VECTOR(6) /* Timer/Counter0 Overflow */
+#define USART_RX_vect_num 7
+#define USART_RX_vect _VECTOR(7) /* USART, Rx Complete */
+#define USART_UDRE_vect_num 8
+#define USART_UDRE_vect _VECTOR(8) /* USART Data Register Empty */
+#define USART_TX_vect_num 9
+#define USART_TX_vect _VECTOR(9) /* USART, Tx Complete */
+#define ANA_COMP_vect_num 10
+#define ANA_COMP_vect _VECTOR(10) /* Analog Comparator */
+#define PCINT_B_vect_num 11
+#define PCINT_B_vect _VECTOR(11) /* Pin Change Interrupt Request B */
+#define TIMER1_COMPB_vect_num 12
+#define TIMER1_COMPB_vect _VECTOR(12) /* */
+#define TIMER0_COMPA_vect_num 13
+#define TIMER0_COMPA_vect _VECTOR(13) /* */
+#define TIMER0_COMPB_vect_num 14
+#define TIMER0_COMPB_vect _VECTOR(14) /* */
+#define USI_START_vect_num 15
+#define USI_START_vect _VECTOR(15) /* USI Start Condition */
+#define USI_OVERFLOW_vect_num 16
+#define USI_OVERFLOW_vect _VECTOR(16) /* USI Overflow */
+#define WDT_OVERFLOW_vect_num 18
+#define WDT_OVERFLOW_vect _VECTOR(18) /* Watchdog Timer Overflow */
+#define PCINT_D_vect_num 20
+#define PCINT_D_vect _VECTOR(20) /* Pin Change Interrupt Request D */
+#define EEPROM_Ready_vect_num 17
+#define EEPROM_Ready_vect _VECTOR(17) /* */
+#define PCINT_A_vect_num 19
+#define PCINT_A_vect _VECTOR(19) /* Pin Change Interrupt Request A */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (21 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x60)
+#define RAMSIZE (256)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0xFF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0xFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x0D
+
+
+/* Device Pin Definitions */
+#define RXD_DDR DDRD
+#define RXD_PORT PORTD
+#define RXD_PIN PIND
+#define RXD_BIT 0
+
+#define TXD_DDR DDRD
+#define TXD_PORT PORTD
+#define TXD_PIN PIND
+#define TXD_BIT 1
+
+#define PA1_DDR DDRXTAL
+#define PA1_PORT PORTXTAL
+#define PA1_PIN PINXTAL
+#define PA1_BIT XTAL2
+
+#define PA0_DDR DDRXTAL
+#define PA0_PORT PORTXTAL
+#define PA0_PIN PINXTAL
+#define PA0_BIT XTAL1
+
+#define INT0_DDR DDRD
+#define INT0_PORT PORTD
+#define INT0_PIN PIND
+#define INT0_BIT 2
+
+#define XCK_DDR DDRD
+#define XCK_PORT PORTD
+#define XCK_PIN PIND
+#define XCK_BIT 2
+
+#define CKOUT_DDR DDRD
+#define CKOUT_PORT PORTD
+#define CKOUT_PIN PIND
+#define CKOUT_BIT 2
+
+#define INT1_DDR DDRD
+#define INT1_PORT PORTD
+#define INT1_PIN PIND
+#define INT1_BIT 3
+
+#define T0_DDR DDRD
+#define T0_PORT PORTD
+#define T0_PIN PIND
+#define T0_BIT 4
+
+#define T1_DDR DDRD
+#define T1_PORT PORTD
+#define T1_PIN PIND
+#define T1_BIT 5
+
+#define OC0B_DDR DDRD
+#define OC0B_PORT PORTD
+#define OC0B_PIN PIND
+#define OC0B_BIT 5
+
+#define ICP_DDR DDRD
+#define ICP_PORT PORTD
+#define ICP_PIN PIND
+#define ICP_BIT 6
+
+#define AIN0_DDR DDRB
+#define AIN0_PORT PORTB
+#define AIN0_PIN PINB
+#define AIN0_BIT 0
+
+#define AIN1_DDR DDRB
+#define AIN1_PORT PORTB
+#define AIN1_PIN PINB
+#define AIN1_BIT 1
+
+#define OC0A_DDR DDRB
+#define OC0A_PORT PORTB
+#define OC0A_PIN PINB
+#define OC0A_BIT 2
+
+#define OC1A_DDR DDRB
+#define OC1A_PORT PORTB
+#define OC1A_PIN PINB
+#define OC1A_BIT 3
+
+#define OC1B_DDR DDRB
+#define OC1B_PORT PORTB
+#define OC1B_PIN PINB
+#define OC1B_BIT 4
+
+#define MOSI_DDR DDRB
+#define MOSI_PORT PORTB
+#define MOSI_PIN PINB
+#define MOSI_BIT 5
+
+#define DI_DDR DDRB
+#define DI_PORT PORTB
+#define DI_PIN PINB
+#define DI_BIT 5
+
+#define MISO_DDR DDRB
+#define MISO_PORT PORTB
+#define MISO_PIN PINB
+#define MISO_BIT 6
+
+#define DO_DDR DDRB
+#define DO_PORT PORTB
+#define DO_PIN PINB
+#define DO_BIT 6
+
+#define SCK_DDR DDRB
+#define SCK_PORT PORTB
+#define SCK_PIN PINB
+#define SCK_BIT 7
+
+#define SCL_DDR DDRB
+#define SCL_PORT PORTB
+#define SCL_PIN PINB
+#define SCL_BIT 7
+
+#endif /* _AVR_ATtiny4313_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn43u.h b/cpukit/score/cpu/avr/avr/iotn43u.h
new file mode 100644
index 0000000000..f9d063101e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn43u.h
@@ -0,0 +1,575 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iotn43u.h - definitions for ATtiny43U */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn43u.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOTN43U_H_
+#define _AVR_IOTN43U_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PRR _SFR_IO8(0x00)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define AIN0D 4
+#define AIN1D 5
+
+/* Reserved [0x02] */
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADLAR 4
+#define ACME 6
+
+#define ADC _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define REFS0 6
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+/* Reserved [0x09], [0x0A] */
+
+#define TIFR1 _SFR_IO8(0x0B)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+
+#define TIMSK1 _SFR_IO8(0x0C)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_IO8(0x10)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+/* Reserved [0x11] */
+
+#define PCMSK0 _SFR_IO8(0x12)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define GPIOR0 _SFR_IO8(0x13)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x14)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x15)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEARL _SFR_IO8(0x1E)
+
+/* Reserved [0x1F] */
+
+#define PCMSK1 _SFR_IO8(0x20)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+
+#define WDTCSR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+/* Reserved [0x22] */
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define TSM 7
+
+/* Reserved [0x24], [0x25] */
+
+#define CLKPR _SFR_IO8(0x26)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+/* Reserved [0x27],[0x28],[0x29],[0x2A] */
+
+#define OCR1B _SFR_IO8(0x2B)
+#define OCR1B_0 0
+#define OCR1B_1 1
+#define OCR1B_2 2
+#define OCR1B_3 3
+#define OCR1B_4 4
+#define OCR1B_5 5
+#define OCR1B_6 6
+#define OCR1B_7 7
+
+#define OCR1A _SFR_IO8(0x2C)
+#define OCR1A_0 0
+#define OCR1A_1 1
+#define OCRA1_2 2
+#define OCRA1_3 3
+#define OCRA1_4 4
+#define OCRA1_5 5
+#define OCRA1_6 6
+#define OCRA1_7 7
+
+#define TCNT1 _SFR_IO8(0x2D)
+#define TCNT1_0 0
+#define TCNT1_1 1
+#define TCNT1_2 2
+#define TCNT1_3 3
+#define TCNT1_4 4
+#define TCNT1_5 5
+#define TCNT1_6 6
+#define TCNT1_7 7
+
+#define TCCR1B _SFR_IO8(0x2E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCCR1A _SFR_IO8(0x2F)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR0A _SFR_IO8(0x30)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define TCNT0 _SFR_IO8(0x32)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define BODSE 2
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+#define BODS 7
+
+#define OCR0A _SFR_IO8(0x36)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR0 _SFR_IO8(0x38)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIMSK0 _SFR_IO8(0x39)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF0 4
+#define PCIF1 5
+#define INTF0 6
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+
+#define OCR0B _SFR_IO8(0x3C)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+
+
+/* Interrupt Vectors */
+/* Interrupt vector 0 is the reset vector. */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+
+/* Watchdog Time-out */
+#define WDT_vect _VECTOR(4)
+
+/* Timer/Counter1 Compare Match A */
+#define TIM1_COMPA_vect _VECTOR(5)
+
+/* Timer/Counter1 Compare Match B */
+#define TIM1_COMPB_vect _VECTOR(6)
+
+/* Timer/Counter1 Overflow */
+#define TIM1_OVF_vect _VECTOR(7)
+
+/* Timer/Counter0 Compare Match A */
+#define TIM0_COMPA_vect _VECTOR(8)
+
+/* Timer/Counter0 Compare Match B */
+#define TIM0_COMPB_vect _VECTOR(9)
+
+/* Timer/Counter0 Overflow */
+#define TIM0_OVF_vect _VECTOR(10)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(11)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(12)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(13)
+
+/* USI START */
+#define USI_START_vect _VECTOR(14)
+
+/* USI Overflow */
+#define USI_OVF_vect _VECTOR(15)
+
+#define _VECTORS_SIZE 32
+
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x15F
+#define XRAMEND RAMEND
+#define E2END 0x3F
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+/* Fuse Information */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x0C
+
+
+#endif /* _AVR_IOTN43U_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn44.h b/cpukit/score/cpu/avr/avr/iotn44.h
new file mode 100644
index 0000000000..2d4cbfc7b4
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn44.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2005, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn44.h - definitions for ATtiny44 */
+
+#ifndef _AVR_IOTN44_H_
+#define _AVR_IOTN44_H_ 1
+
+#include <avr/iotnx4.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x15F
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x07
+
+
+#endif /* _AVR_IOTN44_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn44a.h b/cpukit/score/cpu/avr/avr/iotn44a.h
new file mode 100644
index 0000000000..f073d95006
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn44a.h
@@ -0,0 +1,831 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn44a.h - definitions for ATtiny44A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn44a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny44A_H_
+#define _AVR_ATtiny44A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PRR _SFR_IO8(0x00)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ADLAR 4
+#define ACME 6
+#define BIN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define MUX5 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSR _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define TIFR1 _SFR_IO8(0x0B)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define TIMSK1 _SFR_IO8(0x0C)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_IO8(0x10)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define PCMSK0 _SFR_IO8(0x12)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define GPIOR0 _SFR_IO8(0x13)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x14)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x15)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define PCMSK1 _SFR_IO8(0x20)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+
+#define WDTCSR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define TCCR1C _SFR_IO8(0x22)
+#define FOC1B 6
+#define FOC1A 7
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR10 0
+#define TSM 7
+
+#define ICR1 _SFR_IO16(0x24)
+
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_IO8(0x25)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define CLKPR _SFR_IO8(0x26)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define DWDR _SFR_IO8(0x27)
+
+#define OCR1B _SFR_IO16(0x28)
+
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_IO8(0x29)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define OCR1A _SFR_IO16(0x2A)
+
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_IO8(0x2B)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define TCNT1 _SFR_IO16(0x2C)
+
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_IO8(0x2D)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define TCCR1B _SFR_IO8(0x2E)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1A _SFR_IO8(0x2F)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR0A _SFR_IO8(0x30)
+#define WGM00 0
+#define WGM01 1
+#define COM0B0 4
+#define COM0B1 5
+#define COM0A0 6
+#define COM0A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define TCNT0 _SFR_IO8(0x32)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define WGM02 3
+#define FOC0B 6
+#define FOC0A 7
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+
+#define OCR0A _SFR_IO8(0x36)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR0 _SFR_IO8(0x38)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIMSK0 _SFR_IO8(0x39)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF0 4
+#define PCIF1 5
+#define INTF0 6
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+
+#define OCR0B _SFR_IO8(0x3C)
+#define OCR0_0 0
+#define OCR0_1 1
+#define OCR0_2 2
+#define OCR0_3 3
+#define OCR0_4 4
+#define OCR0_5 5
+#define OCR0_6 6
+#define OCR0_7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define EXT_INT0_vect_num 1
+#define EXT_INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define PCINT0_vect_num 2
+#define PCINT0_vect _VECTOR(2) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 3
+#define PCINT1_vect _VECTOR(3) /* Pin Change Interrupt Request 1 */
+#define WATCHDOG_vect_num 4
+#define WATCHDOG_vect _VECTOR(4) /* Watchdog Time-out */
+#define TIM1_CAPT_vect_num 5
+#define TIM1_CAPT_vect _VECTOR(5) /* Timer/Counter1 Capture Event */
+#define TIM1_COMPA_vect_num 6
+#define TIM1_COMPA_vect _VECTOR(6) /* Timer/Counter1 Compare Match A */
+#define TIM1_COMPB_vect_num 7
+#define TIM1_COMPB_vect _VECTOR(7) /* Timer/Counter1 Compare Match B */
+#define TIM1_OVF_vect_num 8
+#define TIM1_OVF_vect _VECTOR(8) /* Timer/Counter1 Overflow */
+#define TIM0_COMPA_vect_num 9
+#define TIM0_COMPA_vect _VECTOR(9) /* Timer/Counter0 Compare Match A */
+#define TIM0_COMPB_vect_num 10
+#define TIM0_COMPB_vect _VECTOR(10) /* Timer/Counter0 Compare Match B */
+#define TIM0_OVF_vect_num 11
+#define TIM0_OVF_vect _VECTOR(11) /* Timer/Counter0 Overflow */
+#define ANA_COMP_vect_num 12
+#define ANA_COMP_vect _VECTOR(12) /* Analog Comparator */
+#define ADC_vect_num 13
+#define ADC_vect _VECTOR(13) /* ADC Conversion Complete */
+#define EE_RDY_vect_num 14
+#define EE_RDY_vect _VECTOR(14) /* EEPROM Ready */
+#define USI_STR_vect_num 15
+#define USI_STR_vect _VECTOR(15) /* USI START */
+#define USI_OVF_vect_num 16
+#define USI_OVF_vect _VECTOR(16) /* USI Overflow */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (17 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x60)
+#define RAMSIZE (256)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0xFF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0xFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x07
+
+
+/* Device Pin Definitions */
+#define ADC4_DDR DDRA
+#define ADC4_PORT PORTA
+#define ADC4_PIN PINA
+#define ADC4_BIT 4
+
+#define USCK_DDR DDRA
+#define USCK_PORT PORTA
+#define USCK_PIN PINA
+#define USCK_BIT 4
+
+#define SCL_DDR DDRA
+#define SCL_PORT PORTA
+#define SCL_PIN PINA
+#define SCL_BIT 4
+
+#define T1_DDR DDRA
+#define T1_PORT PORTA
+#define T1_PIN PINA
+#define T1_BIT 4
+
+#define PCINT4_DDR DDRA
+#define PCINT4_PORT PORTA
+#define PCINT4_PIN PINA
+#define PCINT4_BIT 4
+
+#define ADC3_DDR DDRA
+#define ADC3_PORT PORTA
+#define ADC3_PIN PINA
+#define ADC3_BIT 3
+
+#define T0_DDR DDRA
+#define T0_PORT PORTA
+#define T0_PIN PINA
+#define T0_BIT 3
+
+#define PCINT3_DDR DDRA
+#define PCINT3_PORT PORTA
+#define PCINT3_PIN PINA
+#define PCINT3_BIT 3
+
+#define ADC2_DDR DDRA
+#define ADC2_PORT PORTA
+#define ADC2_PIN PINA
+#define ADC2_BIT 2
+
+#define AIN1_DDR DDRA
+#define AIN1_PORT PORTA
+#define AIN1_PIN PINA
+#define AIN1_BIT 2
+
+#define PCINT2_DDR DDRA
+#define PCINT2_PORT PORTA
+#define PCINT2_PIN PINA
+#define PCINT2_BIT 2
+
+#define ADC1_DDR DDRA
+#define ADC1_PORT PORTA
+#define ADC1_PIN PINA
+#define ADC1_BIT 1
+
+#define AIN0_DDR DDRA
+#define AIN0_PORT PORTA
+#define AIN0_PIN PINA
+#define AIN0_BIT 1
+
+#define PCINT1_DDR DDRA
+#define PCINT1_PORT PORTA
+#define PCINT1_PIN PINA
+#define PCINT1_BIT 1
+
+#define ADC0_DDR DDRA
+#define ADC0_PORT PORTA
+#define ADC0_PIN PINA
+#define ADC0_BIT 0
+
+#define PCINT0_DDR DDRA
+#define PCINT0_PORT PORTA
+#define PCINT0_PIN PINA
+#define PCINT0_BIT 0
+
+#define PCINT8_DDR DDRB
+#define PCINT8_PORT PORTB
+#define PCINT8_PIN PINB
+#define PCINT8_BIT 0
+
+#define PCINT9_DDR DDRB
+#define PCINT9_PORT PORTB
+#define PCINT9_PIN PINB
+#define PCINT9_BIT 1
+
+#define PCINT11_DDR DDRB
+#define PCINT11_PORT PORTB
+#define PCINT11_PIN PINB
+#define PCINT11_BIT 3
+
+#define dW_DDR DDRB
+#define dW_PORT PORTB
+#define dW_PIN PINB
+#define dW_BIT 3
+
+#define PCINT10_DDR DDRB
+#define PCINT10_PORT PORTB
+#define PCINT10_PIN PINB
+#define PCINT10_BIT 2
+
+#define INT0_DDR DDRB
+#define INT0_PORT PORTB
+#define INT0_PIN PINB
+#define INT0_BIT 2
+
+#define OC0A_DDR DDRB
+#define OC0A_PORT PORTB
+#define OC0A_PIN PINB
+#define OC0A_BIT 2
+
+#define CKOUT_DDR DDRB
+#define CKOUT_PORT PORTB
+#define CKOUT_PIN PINB
+#define CKOUT_BIT 2
+
+#define PCINT7_DDR DDRA
+#define PCINT7_PORT PORTA
+#define PCINT7_PIN PINA
+#define PCINT7_BIT 7
+
+#define ICP1_DDR DDRA
+#define ICP1_PORT PORTA
+#define ICP1_PIN PINA
+#define ICP1_BIT 7
+
+#define OC0B_DDR DDRA
+#define OC0B_PORT PORTA
+#define OC0B_PIN PINA
+#define OC0B_BIT 7
+
+#define ADC7_DDR DDRA
+#define ADC7_PORT PORTA
+#define ADC7_PIN PINA
+#define ADC7_BIT 7
+
+#define PCINT6_DDR DDRA
+#define PCINT6_PORT PORTA
+#define PCINT6_PIN PINA
+#define PCINT6_BIT 6
+
+#define OC1A_DDR DDRA
+#define OC1A_PORT PORTA
+#define OC1A_PIN PINA
+#define OC1A_BIT 6
+
+#define DI_DDR DDRA
+#define DI_PORT PORTA
+#define DI_PIN PINA
+#define DI_BIT 6
+
+#define SDA_DDR DDRA
+#define SDA_PORT PORTA
+#define SDA_PIN PINA
+#define SDA_BIT 6
+
+#define MOSI_DDR DDRA
+#define MOSI_PORT PORTA
+#define MOSI_PIN PINA
+#define MOSI_BIT 6
+
+#define ADC6_DDR DDRA
+#define ADC6_PORT PORTA
+#define ADC6_PIN PINA
+#define ADC6_BIT 6
+
+#define ADC5_DDR DDRA
+#define ADC5_PORT PORTA
+#define ADC5_PIN PINA
+#define ADC5_BIT 5
+
+#define DO_DDR DDRA
+#define DO_PORT PORTA
+#define DO_PIN PINA
+#define DO_BIT 5
+
+#define MISO_DDR DDRA
+#define MISO_PORT PORTA
+#define MISO_PIN PINA
+#define MISO_BIT 5
+
+#define OC1B_DDR DDRA
+#define OC1B_PORT PORTA
+#define OC1B_PIN PINA
+#define OC1B_BIT 5
+
+#define PCINT5_DDR DDRA
+#define PCINT5_PORT PORTA
+#define PCINT5_PIN PINA
+#define PCINT5_BIT 5
+
+#endif /* _AVR_ATtiny44A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn45.h b/cpukit/score/cpu/avr/avr/iotn45.h
new file mode 100644
index 0000000000..f0df864bab
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn45.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2005, Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn45.h - definitions for ATtiny45 */
+
+#ifndef _AVR_IOTN45_H_
+#define _AVR_IOTN45_H_ 1
+
+#include <avr/iotnx5.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x15F
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x06
+
+
+#endif /* _AVR_IOTN45_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn461.h b/cpukit/score/cpu/avr/avr/iotn461.h
new file mode 100644
index 0000000000..1ff2595f16
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn461.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2006, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn461.h - definitions for ATtiny461 */
+
+#ifndef _AVR_IOTN461_H_
+#define _AVR_IOTN461_H_ 1
+
+#include <avr/iotnx61.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x15F
+#define XRAMEND RAMEND
+#define E2END 0xFF
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x08
+
+
+#endif /* _AVR_IOTN461_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn461a.h b/cpukit/score/cpu/avr/avr/iotn461a.h
new file mode 100644
index 0000000000..afae35c659
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn461a.h
@@ -0,0 +1,976 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn461a.h - definitions for ATtiny461A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn461a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny461A_H_
+#define _AVR_ATtiny461A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define TCCR1E _SFR_IO8(0x00)
+#define OC1OE0 0
+#define OC1OE1 1
+#define OC1OE2 2
+#define OC1OE3 3
+#define OC1OE4 4
+#define OC1OE5 5
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define AREFD 3
+#define ADC3D 4
+#define ADC4D 5
+#define ADC5D 6
+#define ADC6D 7
+
+#define DIDR1 _SFR_IO8(0x02)
+#define ADC7D 4
+#define ADC8D 5
+#define ADC9D 6
+#define ADC10D 7
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define MUX5 3
+#define REFS2 4
+#define IPR 5
+#define GSEL 6
+#define BIN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSRA _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACME 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define ACSRB _SFR_IO8(0x09)
+#define ACM0 0
+#define ACM1 1
+#define ACM2 2
+#define HLEV 6
+#define HSEL 7
+
+#define GPIOR0 _SFR_IO8(0x0A)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x0B)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x0C)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_IO8(0x10)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define USIPP _SFR_IO8(0x11)
+#define USIPOS 0
+
+#define OCR0B _SFR_IO8(0x12)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define OCR0A _SFR_IO8(0x13)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define TCNT0H _SFR_IO8(0x14)
+#define TCNT0H_0 0
+#define TCNT0H_1 1
+#define TCNT0H_2 2
+#define TCNT0H_3 3
+#define TCNT0H_4 4
+#define TCNT0H_5 5
+#define TCNT0H_6 6
+#define TCNT0H_7 7
+
+#define TCCR0A _SFR_IO8(0x15)
+#define WGM00 0
+#define ACIC0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define DWDR _SFR_IO8(0x20)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define PCMSK1 _SFR_IO8(0x22)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK0 _SFR_IO8(0x23)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define DT1 _SFR_IO8(0x24)
+#define DT1L0 0
+#define DT1L1 1
+#define DT1L2 2
+#define DT1L3 3
+#define DT1H0 4
+#define DT1H1 5
+#define DT1H2 6
+#define DT1H3 7
+
+#define TC1H _SFR_IO8(0x25)
+#define TC18 0
+#define TC19 1
+
+#define TCCR1D _SFR_IO8(0x26)
+#define WGM10 0
+#define WGM11 1
+#define FPF1 2
+#define FPAC1 3
+#define FPES1 4
+#define FPNC1 5
+#define FPEN1 6
+#define FPIE1 7
+
+#define TCCR1C _SFR_IO8(0x27)
+#define PWM1D 0
+#define FOC1D 1
+#define COM1D0 2
+#define COM1D1 3
+#define COM1B0S 4
+#define COM1B1S 5
+#define COM1A0S 6
+#define COM1A1S 7
+
+#define CLKPR _SFR_IO8(0x28)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PCKE 2
+#define LSM 7
+
+#define OCR1D _SFR_IO8(0x2A)
+#define OCR1D0 0
+#define OCR1D1 1
+#define OCR1D2 2
+#define OCR1D3 3
+#define OCR1D4 4
+#define OCR1D5 5
+#define OCR1D6 6
+#define OCR1D7 7
+
+#define OCR1C _SFR_IO8(0x2B)
+#define OCR1C0 0
+#define OCR1C1 1
+#define OCR1C2 2
+#define OCR1C3 3
+#define OCR1C4 4
+#define OCR1C5 5
+#define OCR1C6 6
+#define OCR1C7 7
+
+#define OCR1B _SFR_IO8(0x2C)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define OCR1A _SFR_IO8(0x2D)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define TCNT1 _SFR_IO8(0x2E)
+#define TC1H_0 0
+#define TC1H_1 1
+#define TC1H_2 2
+#define TC1H_3 3
+#define TC1H_4 4
+#define TC1H_5 5
+#define TC1H_6 6
+#define TC1H_7 7
+
+#define TCCR1B _SFR_IO8(0x2F)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define CS13 3
+#define DTPS10 4
+#define DTPS11 5
+#define PSR1 6
+
+#define TCCR1A _SFR_IO8(0x30)
+#define PWM1B 0
+#define PWM1A 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define TCNT0L _SFR_IO8(0x32)
+#define TCNT0L_0 0
+#define TCNT0L_1 1
+#define TCNT0L_2 2
+#define TCNT0L_3 3
+#define TCNT0L_4 4
+#define TCNT0L_5 5
+#define TCNT0L_6 6
+#define TCNT0L_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define PSR0 3
+#define TSM 4
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define BODSE 2
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+#define BODS 7
+
+#define PRR _SFR_IO8(0x36)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR _SFR_IO8(0x38)
+#define ICF0 0
+#define TOV0 1
+#define TOV1 2
+#define OCF0B 3
+#define OCF0A 4
+#define OCF1B 5
+#define OCF1A 6
+#define OCF1D 7
+
+#define TIMSK _SFR_IO8(0x39)
+#define TICIE0 0
+#define TOIE0 1
+#define TOIE1 2
+#define OCIE0B 3
+#define OCIE0A 4
+#define OCIE1B 5
+#define OCIE1A 6
+#define OCIE1D 7
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF 5
+#define INTF0 6
+#define INTF1 7
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+#define INT1 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt 0 */
+#define PCINT_vect_num 2
+#define PCINT_vect _VECTOR(2) /* Pin Change Interrupt */
+#define TIMER1_COMPA_vect_num 3
+#define TIMER1_COMPA_vect _VECTOR(3) /* Timer/Counter1 Compare Match 1A */
+#define TIMER1_COMPB_vect_num 4
+#define TIMER1_COMPB_vect _VECTOR(4) /* Timer/Counter1 Compare Match 1B */
+#define TIMER1_OVF_vect_num 5
+#define TIMER1_OVF_vect _VECTOR(5) /* Timer/Counter1 Overflow */
+#define TIMER0_OVF_vect_num 6
+#define TIMER0_OVF_vect _VECTOR(6) /* Timer/Counter0 Overflow */
+#define USI_START_vect_num 7
+#define USI_START_vect _VECTOR(7) /* USI Start */
+#define USI_OVF_vect_num 8
+#define USI_OVF_vect _VECTOR(8) /* USI Overflow */
+#define EE_RDY_vect_num 9
+#define EE_RDY_vect _VECTOR(9) /* EEPROM Ready */
+#define ANA_COMP_vect_num 10
+#define ANA_COMP_vect _VECTOR(10) /* Analog Comparator */
+#define ADC_vect_num 11
+#define ADC_vect _VECTOR(11) /* ADC Conversion Complete */
+#define WDT_vect_num 12
+#define WDT_vect _VECTOR(12) /* Watchdog Time-Out */
+#define INT1_vect_num 13
+#define INT1_vect _VECTOR(13) /* External Interrupt 1 */
+#define TIMER0_COMPA_vect_num 14
+#define TIMER0_COMPA_vect _VECTOR(14) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 15
+#define TIMER0_COMPB_vect _VECTOR(15) /* Timer/Counter0 Compare Match B */
+#define TIMER0_CAPT_vect_num 16
+#define TIMER0_CAPT_vect _VECTOR(16) /* ADC Conversion Complete */
+#define TIMER1_COMPD_vect_num 17
+#define TIMER1_COMPD_vect _VECTOR(17) /* Timer/Counter1 Compare Match D */
+#define FAULT_PROTECTION_vect_num 18
+#define FAULT_PROTECTION_vect _VECTOR(18) /* Timer/Counter1 Fault Protection */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (19 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x60)
+#define RAMSIZE (256)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0xFF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0xFFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x08
+
+
+/* Device Pin Definitions */
+#define DI_B_DDR DDRMOSI
+#define DI_B_PORT PORTMOSI
+#define DI_B_PIN PINMOSI
+#define DI_B_BIT MOSI
+
+#define SDA_B_DDR DDRMOSI
+#define SDA_B_PORT PORTMOSI
+#define SDA_B_PIN PINMOSI
+#define SDA_B_BIT MOSI
+
+#define _OC1A_DDR DDRMOSI
+#define _OC1A_PORT PORTMOSI
+#define _OC1A_PIN PINMOSI
+#define _OC1A_BIT MOSI
+
+#define PCINT8_DDR DDRMOSI
+#define PCINT8_PORT PORTMOSI
+#define PCINT8_PIN PINMOSI
+#define PCINT8_BIT MOSI
+
+#define PB0_DDR DDRMOSI
+#define PB0_PORT PORTMOSI
+#define PB0_PIN PINMOSI
+#define PB0_BIT MOSI
+
+#define DO_B_DDR DDRMISO
+#define DO_B_PORT PORTMISO
+#define DO_B_PIN PINMISO
+#define DO_B_BIT MISO
+
+#define OC1A_DDR DDRMISO
+#define OC1A_PORT PORTMISO
+#define OC1A_PIN PINMISO
+#define OC1A_BIT MISO
+
+#define PCINT9_DDR DDRMISO
+#define PCINT9_PORT PORTMISO
+#define PCINT9_PIN PINMISO
+#define PCINT9_BIT MISO
+
+#define PB1_DDR DDRMISO
+#define PB1_PORT PORTMISO
+#define PB1_PIN PINMISO
+#define PB1_BIT MISO
+
+#define USCK_B_DDR DDRSCK
+#define USCK_B_PORT PORTSCK
+#define USCK_B_PIN PINSCK
+#define USCK_B_BIT SCK
+
+#define SCL_B_DDR DDRSCK
+#define SCL_B_PORT PORTSCK
+#define SCL_B_PIN PINSCK
+#define SCL_B_BIT SCK
+
+#define OC1B_DDR DDRSCK
+#define OC1B_PORT PORTSCK
+#define OC1B_PIN PINSCK
+#define OC1B_BIT SCK
+
+#define PCINT10_DDR DDRSCK
+#define PCINT10_PORT PORTSCK
+#define PCINT10_PIN PINSCK
+#define PCINT10_BIT SCK
+
+#define PB2_DDR DDRSCK
+#define PB2_PORT PORTSCK
+#define PB2_PIN PINSCK
+#define PB2_BIT SCK
+
+#define PCINT11_DDR DDROC1B
+#define PCINT11_PORT PORTOC1B
+#define PCINT11_PIN PINOC1B
+#define PCINT11_BIT OC1B
+
+#define PB3_DDR DDROC1B
+#define PB3_PORT PORTOC1B
+#define PB3_PIN PINOC1B
+#define PB3_BIT OC1B
+
+#define PCINT12_DDR DDRADC
+#define PCINT12_PORT PORTADC
+#define PCINT12_PIN PINADC
+#define PCINT12_BIT ADC7
+
+#define _OC1D_DDR DDRADC
+#define _OC1D_PORT PORTADC
+#define _OC1D_PIN PINADC
+#define _OC1D_BIT ADC7
+
+#define CLKI_DDR DDRADC
+#define CLKI_PORT PORTADC
+#define CLKI_PIN PINADC
+#define CLKI_BIT ADC7
+
+#define PB4_DDR DDRADC
+#define PB4_PORT PORTADC
+#define PB4_PIN PINADC
+#define PB4_BIT ADC7
+
+#define PCINT13_DDR DDRADC
+#define PCINT13_PORT PORTADC
+#define PCINT13_PIN PINADC
+#define PCINT13_BIT ADC8
+
+#define OC1D_DDR DDRADC
+#define OC1D_PORT PORTADC
+#define OC1D_PIN PINADC
+#define OC1D_BIT ADC8
+
+#define CKLO_DDR DDRADC
+#define CKLO_PORT PORTADC
+#define CKLO_PIN PINADC
+#define CKLO_BIT ADC8
+
+#define PB5_DDR DDRADC
+#define PB5_PORT PORTADC
+#define PB5_PIN PINADC
+#define PB5_BIT ADC8
+
+#define INT0_DDR DDRADC
+#define INT0_PORT PORTADC
+#define INT0_PIN PINADC
+#define INT0_BIT ADC9
+
+#define T0_DDR DDRADC
+#define T0_PORT PORTADC
+#define T0_PIN PINADC
+#define T0_BIT ADC9
+
+#define PCINT14_DDR DDRADC
+#define PCINT14_PORT PORTADC
+#define PCINT14_PIN PINADC
+#define PCINT14_BIT ADC9
+
+#define PB6_DDR DDRADC
+#define PB6_PORT PORTADC
+#define PB6_PIN PINADC
+#define PB6_BIT ADC9
+
+#define PCINT15_DDR DDRADC1
+#define PCINT15_PORT PORTADC1
+#define PCINT15_PIN PINADC1
+#define PCINT15_BIT ADC10
+
+#define PB7_DDR DDRADC1
+#define PB7_PORT PORTADC1
+#define PB7_PIN PINADC1
+#define PB7_BIT ADC10
+
+#define AIN1_DDR DDRADC
+#define AIN1_PORT PORTADC
+#define AIN1_PIN PINADC
+#define AIN1_BIT ADC6
+
+#define PCINT7_DDR DDRADC
+#define PCINT7_PORT PORTADC
+#define PCINT7_PIN PINADC
+#define PCINT7_BIT ADC6
+
+#define PA7_DDR DDRADC
+#define PA7_PORT PORTADC
+#define PA7_PIN PINADC
+#define PA7_BIT ADC6
+
+#define AIN0_DDR DDRADC
+#define AIN0_PORT PORTADC
+#define AIN0_PIN PINADC
+#define AIN0_BIT ADC5
+
+#define PCINT6_DDR DDRADC
+#define PCINT6_PORT PORTADC
+#define PCINT6_PIN PINADC
+#define PCINT6_BIT ADC5
+
+#define PA6_DDR DDRADC
+#define PA6_PORT PORTADC
+#define PA6_PIN PINADC
+#define PA6_BIT ADC5
+
+#define AIN2_DDR DDRADC
+#define AIN2_PORT PORTADC
+#define AIN2_PIN PINADC
+#define AIN2_BIT ADC4
+
+#define PCINT5_DDR DDRADC
+#define PCINT5_PORT PORTADC
+#define PCINT5_PIN PINADC
+#define PCINT5_BIT ADC4
+
+#define PA5_DDR DDRADC
+#define PA5_PORT PORTADC
+#define PA5_PIN PINADC
+#define PA5_BIT ADC4
+
+#define ICP0_DDR DDRADC
+#define ICP0_PORT PORTADC
+#define ICP0_PIN PINADC
+#define ICP0_BIT ADC3
+
+#define PCINT4_DDR DDRADC
+#define PCINT4_PORT PORTADC
+#define PCINT4_PIN PINADC
+#define PCINT4_BIT ADC3
+
+#define PA4_DDR DDRADC
+#define PA4_PORT PORTADC
+#define PA4_PIN PINADC
+#define PA4_BIT ADC3
+
+#define PCINT3_DDR DDRAREF
+#define PCINT3_PORT PORTAREF
+#define PCINT3_PIN PINAREF
+#define PCINT3_BIT AREF
+
+#define PA3_DDR DDRAREF
+#define PA3_PORT PORTAREF
+#define PA3_PIN PINAREF
+#define PA3_BIT AREF
+
+#define INT1_DDR DDRADC
+#define INT1_PORT PORTADC
+#define INT1_PIN PINADC
+#define INT1_BIT ADC2
+
+#define USCK_A_DDR DDRADC
+#define USCK_A_PORT PORTADC
+#define USCK_A_PIN PINADC
+#define USCK_A_BIT ADC2
+
+#define SCL_A_DDR DDRADC
+#define SCL_A_PORT PORTADC
+#define SCL_A_PIN PINADC
+#define SCL_A_BIT ADC2
+
+#define PCINT2_DDR DDRADC
+#define PCINT2_PORT PORTADC
+#define PCINT2_PIN PINADC
+#define PCINT2_BIT ADC2
+
+#define PA2_DDR DDRADC
+#define PA2_PORT PORTADC
+#define PA2_PIN PINADC
+#define PA2_BIT ADC2
+
+#define DO_A_DDR DDRADC
+#define DO_A_PORT PORTADC
+#define DO_A_PIN PINADC
+#define DO_A_BIT ADC1
+
+#define PCINT1_DDR DDRADC
+#define PCINT1_PORT PORTADC
+#define PCINT1_PIN PINADC
+#define PCINT1_BIT ADC1
+
+#define PA1_DDR DDRADC
+#define PA1_PORT PORTADC
+#define PA1_PIN PINADC
+#define PA1_BIT ADC1
+
+#define DI_A_DDR DDRADC
+#define DI_A_PORT PORTADC
+#define DI_A_PIN PINADC
+#define DI_A_BIT ADC0
+
+#define SDA_A_DDR DDRADC
+#define SDA_A_PORT PORTADC
+#define SDA_A_PIN PINADC
+#define SDA_A_BIT ADC0
+
+#define PCINT0_DDR DDRADC
+#define PCINT0_PORT PORTADC
+#define PCINT0_PIN PINADC
+#define PCINT0_BIT ADC0
+
+#define PA0_DDR DDRADC
+#define PA0_PORT PORTADC
+#define PA0_PIN PINADC
+#define PA0_BIT ADC0
+
+#endif /* _AVR_ATtiny461A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn48.h b/cpukit/score/cpu/avr/avr/iotn48.h
new file mode 100644
index 0000000000..957d8838cb
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn48.h
@@ -0,0 +1,757 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iotn48.h - definitions for ATtiny48 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn48.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOTN48_H_
+#define _AVR_IOTN48_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINA _SFR_IO8(0x0C)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+
+#define DDRA _SFR_IO8(0x0D)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+
+#define PORTA _SFR_IO8(0x0E)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+
+#define PORTCR _SFR_IO8(0x12)
+#define PUDA 0
+#define PUDB 1
+#define PUDC 2
+#define PUDD 3
+#define BBMA 4
+#define BBMB 5
+#define BBMC 6
+#define BBMD 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define CTC0 3
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+#define RWWSB 6
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK3 _SFR_MEM8(0x6A)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 2
+#define TWS4 3
+#define TWS5 4
+#define TWS6 5
+#define TWS7 6
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define TWIHSR _SFR_MEM8(0xBE) /* Deprecated */
+#define TWHSR _SFR_MEM8(0xBE)
+#define TWIHS 0
+
+
+/* Interrupt Vectors */
+/* Interrupt vector 0 is the reset vector. */
+
+#define INT0_vect _VECTOR(1)
+#define INT1_vect _VECTOR(2)
+#define PCINT0_vect _VECTOR(3)
+#define PCINT1_vect _VECTOR(4)
+#define PCINT2_vect _VECTOR(5)
+#define PCINT3_vect _VECTOR(6)
+#define WDT_vect _VECTOR(7)
+#define TIMER1_CAPT_vect _VECTOR(8)
+#define TIMER1_COMPA_vect _VECTOR(9)
+#define TIMER1_COMPB_vect _VECTOR(10)
+#define TIMER1_OVF_vect _VECTOR(11)
+#define TIMER0_COMPA_vect _VECTOR(12)
+#define TIMER0_COMPB_vect _VECTOR(13)
+#define TIMER0_OVF_vect _VECTOR(14)
+#define SPI_STC_vect _VECTOR(15)
+#define ADC_vect _VECTOR(16)
+#define EE_READY_vect _VECTOR(17)
+#define ANALOG_COMP_vect _VECTOR(18)
+#define TWI_vect _VECTOR(19)
+
+#define _VECTORS_SIZE 40
+
+
+/* Constants */
+#define SPM_PAGESIZE 32
+#define RAMEND 0x1FF
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x3F
+#define E2PAGESIZE 4
+#define FLASHEND 0xFFF
+
+
+/* Fuse Information */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x92
+#define SIGNATURE_2 0x09
+
+
+#endif /* _AVR_IOTN48_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn84.h b/cpukit/score/cpu/avr/avr/iotn84.h
new file mode 100644
index 0000000000..8ac6b6d5e8
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn84.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2005, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn84.h - definitions for ATtiny84 */
+
+#ifndef _AVR_IOTN84_H_
+#define _AVR_IOTN84_H_ 1
+
+#include <avr/iotnx4.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x25F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define FUSE_HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0C
+
+
+#endif /* _AVR_IOTN84_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn85.h b/cpukit/score/cpu/avr/avr/iotn85.h
new file mode 100644
index 0000000000..6364aea557
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn85.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2005, Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn85.h - definitions for ATtiny85 */
+
+#ifndef _AVR_IOTN85_H_
+#define _AVR_IOTN85_H_ 1
+
+#include <avr/iotnx5.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x25F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0B
+
+
+#endif /* _AVR_IOTN85_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn861.h b/cpukit/score/cpu/avr/avr/iotn861.h
new file mode 100644
index 0000000000..6934d4ad72
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn861.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2006, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn861.h - definitions for ATtiny861 */
+
+#ifndef _AVR_IOTN861_H_
+#define _AVR_IOTN861_H_ 1
+
+#include <avr/iotnx61.h>
+
+/* Constants */
+#define SPM_PAGESIZE 64
+#define RAMEND 0x25F
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_DWEN (unsigned char)~_BV(6)
+#define FUSE_RSTDISBL (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0)
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0D
+
+
+#endif /* _AVR_IOTN861_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotn861a.h b/cpukit/score/cpu/avr/avr/iotn861a.h
new file mode 100644
index 0000000000..9d123277b9
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn861a.h
@@ -0,0 +1,976 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn861a.h - definitions for ATtiny861A */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn861a.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny861A_H_
+#define _AVR_ATtiny861A_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define TCCR1E _SFR_IO8(0x00)
+#define OC1OE0 0
+#define OC1OE1 1
+#define OC1OE2 2
+#define OC1OE3 3
+#define OC1OE4 4
+#define OC1OE5 5
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define AREFD 3
+#define ADC3D 4
+#define ADC4D 5
+#define ADC5D 6
+#define ADC6D 7
+
+#define DIDR1 _SFR_IO8(0x02)
+#define ADC7D 4
+#define ADC8D 5
+#define ADC9D 6
+#define ADC10D 7
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define MUX5 3
+#define REFS2 4
+#define IPR 5
+#define GSEL 6
+#define BIN 7
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_IO8(0x05)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSRA _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACME 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define ACSRB _SFR_IO8(0x09)
+#define ACM0 0
+#define ACM1 1
+#define ACM2 2
+#define HLEV 6
+#define HSEL 7
+
+#define GPIOR0 _SFR_IO8(0x0A)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define GPIOR1 _SFR_IO8(0x0B)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x0C)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_IO8(0x10)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define USIPP _SFR_IO8(0x11)
+#define USIPOS 0
+
+#define OCR0B _SFR_IO8(0x12)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define OCR0A _SFR_IO8(0x13)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define TCNT0H _SFR_IO8(0x14)
+#define TCNT0H_0 0
+#define TCNT0H_1 1
+#define TCNT0H_2 2
+#define TCNT0H_3 3
+#define TCNT0H_4 4
+#define TCNT0H_5 5
+#define TCNT0H_6 6
+#define TCNT0H_7 7
+
+#define TCCR0A _SFR_IO8(0x15)
+#define WGM00 0
+#define ACIC0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x1D)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x1E)
+
+#define EEARL _SFR_IO8(0x1E)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x1F)
+#define EEAR8 0
+
+#define DWDR _SFR_IO8(0x20)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define PCMSK1 _SFR_IO8(0x22)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK0 _SFR_IO8(0x23)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define DT1 _SFR_IO8(0x24)
+#define DT1L0 0
+#define DT1L1 1
+#define DT1L2 2
+#define DT1L3 3
+#define DT1H0 4
+#define DT1H1 5
+#define DT1H2 6
+#define DT1H3 7
+
+#define TC1H _SFR_IO8(0x25)
+#define TC18 0
+#define TC19 1
+
+#define TCCR1D _SFR_IO8(0x26)
+#define WGM10 0
+#define WGM11 1
+#define FPF1 2
+#define FPAC1 3
+#define FPES1 4
+#define FPNC1 5
+#define FPEN1 6
+#define FPIE1 7
+
+#define TCCR1C _SFR_IO8(0x27)
+#define PWM1D 0
+#define FOC1D 1
+#define COM1D0 2
+#define COM1D1 3
+#define COM1B0S 4
+#define COM1B1S 5
+#define COM1A0S 6
+#define COM1A1S 7
+
+#define CLKPR _SFR_IO8(0x28)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PCKE 2
+#define LSM 7
+
+#define OCR1D _SFR_IO8(0x2A)
+#define OCR1D0 0
+#define OCR1D1 1
+#define OCR1D2 2
+#define OCR1D3 3
+#define OCR1D4 4
+#define OCR1D5 5
+#define OCR1D6 6
+#define OCR1D7 7
+
+#define OCR1C _SFR_IO8(0x2B)
+#define OCR1C0 0
+#define OCR1C1 1
+#define OCR1C2 2
+#define OCR1C3 3
+#define OCR1C4 4
+#define OCR1C5 5
+#define OCR1C6 6
+#define OCR1C7 7
+
+#define OCR1B _SFR_IO8(0x2C)
+#define OCR1B0 0
+#define OCR1B1 1
+#define OCR1B2 2
+#define OCR1B3 3
+#define OCR1B4 4
+#define OCR1B5 5
+#define OCR1B6 6
+#define OCR1B7 7
+
+#define OCR1A _SFR_IO8(0x2D)
+#define OCR1A0 0
+#define OCR1A1 1
+#define OCR1A2 2
+#define OCR1A3 3
+#define OCR1A4 4
+#define OCR1A5 5
+#define OCR1A6 6
+#define OCR1A7 7
+
+#define TCNT1 _SFR_IO8(0x2E)
+#define TC1H_0 0
+#define TC1H_1 1
+#define TC1H_2 2
+#define TC1H_3 3
+#define TC1H_4 4
+#define TC1H_5 5
+#define TC1H_6 6
+#define TC1H_7 7
+
+#define TCCR1B _SFR_IO8(0x2F)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define CS13 3
+#define DTPS10 4
+#define DTPS11 5
+#define PSR1 6
+
+#define TCCR1A _SFR_IO8(0x30)
+#define PWM1B 0
+#define PWM1A 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define TCNT0L _SFR_IO8(0x32)
+#define TCNT0L_0 0
+#define TCNT0L_1 1
+#define TCNT0L_2 2
+#define TCNT0L_3 3
+#define TCNT0L_4 4
+#define TCNT0L_5 5
+#define TCNT0L_6 6
+#define TCNT0L_7 7
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define PSR0 3
+#define TSM 4
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define BODSE 2
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+#define BODS 7
+
+#define PRR _SFR_IO8(0x36)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR _SFR_IO8(0x38)
+#define ICF0 0
+#define TOV0 1
+#define TOV1 2
+#define OCF0B 3
+#define OCF0A 4
+#define OCF1B 5
+#define OCF1A 6
+#define OCF1D 7
+
+#define TIMSK _SFR_IO8(0x39)
+#define TICIE0 0
+#define TOIE0 1
+#define TOIE1 2
+#define OCIE0B 3
+#define OCIE0A 4
+#define OCIE1B 5
+#define OCIE1A 6
+#define OCIE1D 7
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF 5
+#define INTF0 6
+#define INTF1 7
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+#define INT1 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt 0 */
+#define PCINT_vect_num 2
+#define PCINT_vect _VECTOR(2) /* Pin Change Interrupt */
+#define TIMER1_COMPA_vect_num 3
+#define TIMER1_COMPA_vect _VECTOR(3) /* Timer/Counter1 Compare Match 1A */
+#define TIMER1_COMPB_vect_num 4
+#define TIMER1_COMPB_vect _VECTOR(4) /* Timer/Counter1 Compare Match 1B */
+#define TIMER1_OVF_vect_num 5
+#define TIMER1_OVF_vect _VECTOR(5) /* Timer/Counter1 Overflow */
+#define TIMER0_OVF_vect_num 6
+#define TIMER0_OVF_vect _VECTOR(6) /* Timer/Counter0 Overflow */
+#define USI_START_vect_num 7
+#define USI_START_vect _VECTOR(7) /* USI Start */
+#define USI_OVF_vect_num 8
+#define USI_OVF_vect _VECTOR(8) /* USI Overflow */
+#define EE_RDY_vect_num 9
+#define EE_RDY_vect _VECTOR(9) /* EEPROM Ready */
+#define ANA_COMP_vect_num 10
+#define ANA_COMP_vect _VECTOR(10) /* Analog Comparator */
+#define ADC_vect_num 11
+#define ADC_vect _VECTOR(11) /* ADC Conversion Complete */
+#define WDT_vect_num 12
+#define WDT_vect _VECTOR(12) /* Watchdog Time-Out */
+#define INT1_vect_num 13
+#define INT1_vect _VECTOR(13) /* External Interrupt 1 */
+#define TIMER0_COMPA_vect_num 14
+#define TIMER0_COMPA_vect _VECTOR(14) /* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPB_vect_num 15
+#define TIMER0_COMPB_vect _VECTOR(15) /* Timer/Counter0 Compare Match B */
+#define TIMER0_CAPT_vect_num 16
+#define TIMER0_CAPT_vect _VECTOR(16) /* ADC Conversion Complete */
+#define TIMER1_COMPD_vect_num 17
+#define TIMER1_COMPD_vect _VECTOR(17) /* Timer/Counter1 Compare Match D */
+#define FAULT_PROTECTION_vect_num 18
+#define FAULT_PROTECTION_vect _VECTOR(18) /* Timer/Counter1 Fault Protection */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (19 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (64)
+#define RAMSTART (0x60)
+#define RAMSIZE (512)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x1FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always on */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x0D
+
+
+/* Device Pin Definitions */
+#define DI_B_DDR DDRMOSI
+#define DI_B_PORT PORTMOSI
+#define DI_B_PIN PINMOSI
+#define DI_B_BIT MOSI
+
+#define SDA_B_DDR DDRMOSI
+#define SDA_B_PORT PORTMOSI
+#define SDA_B_PIN PINMOSI
+#define SDA_B_BIT MOSI
+
+#define _OC1A_DDR DDRMOSI
+#define _OC1A_PORT PORTMOSI
+#define _OC1A_PIN PINMOSI
+#define _OC1A_BIT MOSI
+
+#define PCINT8_DDR DDRMOSI
+#define PCINT8_PORT PORTMOSI
+#define PCINT8_PIN PINMOSI
+#define PCINT8_BIT MOSI
+
+#define PB0_DDR DDRMOSI
+#define PB0_PORT PORTMOSI
+#define PB0_PIN PINMOSI
+#define PB0_BIT MOSI
+
+#define DO_B_DDR DDRMISO
+#define DO_B_PORT PORTMISO
+#define DO_B_PIN PINMISO
+#define DO_B_BIT MISO
+
+#define OC1A_DDR DDRMISO
+#define OC1A_PORT PORTMISO
+#define OC1A_PIN PINMISO
+#define OC1A_BIT MISO
+
+#define PCINT9_DDR DDRMISO
+#define PCINT9_PORT PORTMISO
+#define PCINT9_PIN PINMISO
+#define PCINT9_BIT MISO
+
+#define PB1_DDR DDRMISO
+#define PB1_PORT PORTMISO
+#define PB1_PIN PINMISO
+#define PB1_BIT MISO
+
+#define USCK_B_DDR DDRSCK
+#define USCK_B_PORT PORTSCK
+#define USCK_B_PIN PINSCK
+#define USCK_B_BIT SCK
+
+#define SCL_B_DDR DDRSCK
+#define SCL_B_PORT PORTSCK
+#define SCL_B_PIN PINSCK
+#define SCL_B_BIT SCK
+
+#define OC1B_DDR DDRSCK
+#define OC1B_PORT PORTSCK
+#define OC1B_PIN PINSCK
+#define OC1B_BIT SCK
+
+#define PCINT10_DDR DDRSCK
+#define PCINT10_PORT PORTSCK
+#define PCINT10_PIN PINSCK
+#define PCINT10_BIT SCK
+
+#define PB2_DDR DDRSCK
+#define PB2_PORT PORTSCK
+#define PB2_PIN PINSCK
+#define PB2_BIT SCK
+
+#define PCINT11_DDR DDROC1B
+#define PCINT11_PORT PORTOC1B
+#define PCINT11_PIN PINOC1B
+#define PCINT11_BIT OC1B
+
+#define PB3_DDR DDROC1B
+#define PB3_PORT PORTOC1B
+#define PB3_PIN PINOC1B
+#define PB3_BIT OC1B
+
+#define PCINT12_DDR DDRADC
+#define PCINT12_PORT PORTADC
+#define PCINT12_PIN PINADC
+#define PCINT12_BIT ADC7
+
+#define _OC1D_DDR DDRADC
+#define _OC1D_PORT PORTADC
+#define _OC1D_PIN PINADC
+#define _OC1D_BIT ADC7
+
+#define CLKI_DDR DDRADC
+#define CLKI_PORT PORTADC
+#define CLKI_PIN PINADC
+#define CLKI_BIT ADC7
+
+#define PB4_DDR DDRADC
+#define PB4_PORT PORTADC
+#define PB4_PIN PINADC
+#define PB4_BIT ADC7
+
+#define PCINT13_DDR DDRADC
+#define PCINT13_PORT PORTADC
+#define PCINT13_PIN PINADC
+#define PCINT13_BIT ADC8
+
+#define OC1D_DDR DDRADC
+#define OC1D_PORT PORTADC
+#define OC1D_PIN PINADC
+#define OC1D_BIT ADC8
+
+#define CKLO_DDR DDRADC
+#define CKLO_PORT PORTADC
+#define CKLO_PIN PINADC
+#define CKLO_BIT ADC8
+
+#define PB5_DDR DDRADC
+#define PB5_PORT PORTADC
+#define PB5_PIN PINADC
+#define PB5_BIT ADC8
+
+#define INT0_DDR DDRADC
+#define INT0_PORT PORTADC
+#define INT0_PIN PINADC
+#define INT0_BIT ADC9
+
+#define T0_DDR DDRADC
+#define T0_PORT PORTADC
+#define T0_PIN PINADC
+#define T0_BIT ADC9
+
+#define PCINT14_DDR DDRADC
+#define PCINT14_PORT PORTADC
+#define PCINT14_PIN PINADC
+#define PCINT14_BIT ADC9
+
+#define PB6_DDR DDRADC
+#define PB6_PORT PORTADC
+#define PB6_PIN PINADC
+#define PB6_BIT ADC9
+
+#define PCINT15_DDR DDRADC1
+#define PCINT15_PORT PORTADC1
+#define PCINT15_PIN PINADC1
+#define PCINT15_BIT ADC10
+
+#define PB7_DDR DDRADC1
+#define PB7_PORT PORTADC1
+#define PB7_PIN PINADC1
+#define PB7_BIT ADC10
+
+#define AIN1_DDR DDRADC
+#define AIN1_PORT PORTADC
+#define AIN1_PIN PINADC
+#define AIN1_BIT ADC6
+
+#define PCINT7_DDR DDRADC
+#define PCINT7_PORT PORTADC
+#define PCINT7_PIN PINADC
+#define PCINT7_BIT ADC6
+
+#define PA7_DDR DDRADC
+#define PA7_PORT PORTADC
+#define PA7_PIN PINADC
+#define PA7_BIT ADC6
+
+#define AIN0_DDR DDRADC
+#define AIN0_PORT PORTADC
+#define AIN0_PIN PINADC
+#define AIN0_BIT ADC5
+
+#define PCINT6_DDR DDRADC
+#define PCINT6_PORT PORTADC
+#define PCINT6_PIN PINADC
+#define PCINT6_BIT ADC5
+
+#define PA6_DDR DDRADC
+#define PA6_PORT PORTADC
+#define PA6_PIN PINADC
+#define PA6_BIT ADC5
+
+#define AIN2_DDR DDRADC
+#define AIN2_PORT PORTADC
+#define AIN2_PIN PINADC
+#define AIN2_BIT ADC4
+
+#define PCINT5_DDR DDRADC
+#define PCINT5_PORT PORTADC
+#define PCINT5_PIN PINADC
+#define PCINT5_BIT ADC4
+
+#define PA5_DDR DDRADC
+#define PA5_PORT PORTADC
+#define PA5_PIN PINADC
+#define PA5_BIT ADC4
+
+#define ICP0_DDR DDRADC
+#define ICP0_PORT PORTADC
+#define ICP0_PIN PINADC
+#define ICP0_BIT ADC3
+
+#define PCINT4_DDR DDRADC
+#define PCINT4_PORT PORTADC
+#define PCINT4_PIN PINADC
+#define PCINT4_BIT ADC3
+
+#define PA4_DDR DDRADC
+#define PA4_PORT PORTADC
+#define PA4_PIN PINADC
+#define PA4_BIT ADC3
+
+#define PCINT3_DDR DDRAREF
+#define PCINT3_PORT PORTAREF
+#define PCINT3_PIN PINAREF
+#define PCINT3_BIT AREF
+
+#define PA3_DDR DDRAREF
+#define PA3_PORT PORTAREF
+#define PA3_PIN PINAREF
+#define PA3_BIT AREF
+
+#define INT1_DDR DDRADC
+#define INT1_PORT PORTADC
+#define INT1_PIN PINADC
+#define INT1_BIT ADC2
+
+#define USCK_A_DDR DDRADC
+#define USCK_A_PORT PORTADC
+#define USCK_A_PIN PINADC
+#define USCK_A_BIT ADC2
+
+#define SCL_A_DDR DDRADC
+#define SCL_A_PORT PORTADC
+#define SCL_A_PIN PINADC
+#define SCL_A_BIT ADC2
+
+#define PCINT2_DDR DDRADC
+#define PCINT2_PORT PORTADC
+#define PCINT2_PIN PINADC
+#define PCINT2_BIT ADC2
+
+#define PA2_DDR DDRADC
+#define PA2_PORT PORTADC
+#define PA2_PIN PINADC
+#define PA2_BIT ADC2
+
+#define DO_A_DDR DDRADC
+#define DO_A_PORT PORTADC
+#define DO_A_PIN PINADC
+#define DO_A_BIT ADC1
+
+#define PCINT1_DDR DDRADC
+#define PCINT1_PORT PORTADC
+#define PCINT1_PIN PINADC
+#define PCINT1_BIT ADC1
+
+#define PA1_DDR DDRADC
+#define PA1_PORT PORTADC
+#define PA1_PIN PINADC
+#define PA1_BIT ADC1
+
+#define DI_A_DDR DDRADC
+#define DI_A_PORT PORTADC
+#define DI_A_PIN PINADC
+#define DI_A_BIT ADC0
+
+#define SDA_A_DDR DDRADC
+#define SDA_A_PORT PORTADC
+#define SDA_A_PIN PINADC
+#define SDA_A_BIT ADC0
+
+#define PCINT0_DDR DDRADC
+#define PCINT0_PORT PORTADC
+#define PCINT0_PIN PINADC
+#define PCINT0_BIT ADC0
+
+#define PA0_DDR DDRADC
+#define PA0_PORT PORTADC
+#define PA0_PIN PINADC
+#define PA0_BIT ADC0
+
+#endif /* _AVR_ATtiny861A_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn87.h b/cpukit/score/cpu/avr/avr/iotn87.h
new file mode 100644
index 0000000000..ead7f335a2
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn87.h
@@ -0,0 +1,847 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotn87.h - definitions for ATtiny87 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn87.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATtiny87_H_
+#define _AVR_ATtiny87_H_ 1
+
+
+/* Registers and associated bit numbers. */
+
+#define PINA _SFR_IO8(0x00)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x01)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x02)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+#define PORTA4 4
+#define PORTA5 5
+#define PORTA6 6
+#define PORTA7 7
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PORTCR _SFR_IO8(0x12)
+#define PUDA 0
+#define PUDB 2
+#define BBMA 4
+#define BBMB 5
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEAR _SFR_IO16(0x21)
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define EEARH _SFR_IO8(0x22)
+#define EEAR8 0
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSR1 0
+#define PSR0 1
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x25)
+#define WGM00 0
+#define WGM01 1
+#define COM0A0 6
+#define COM0A1 7
+
+#define TCCR0B _SFR_IO8(0x26)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define FOC0A 7
+
+#define TCNT0 _SFR_IO8(0x27)
+#define TCNT00 0
+#define TCNT01 1
+#define TCNT02 2
+#define TCNT03 3
+#define TCNT04 4
+#define TCNT05 5
+#define TCNT06 6
+#define TCNT07 7
+
+#define OCR0A _SFR_IO8(0x28)
+#define OCR00 0
+#define OCR01 1
+#define OCR02 2
+#define OCR03 3
+#define OCR04 4
+#define OCR05 5
+#define OCR06 6
+#define OCR07 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACIRS 6
+#define ACD 7
+
+#define DWDR _SFR_IO8(0x31)
+#define DWDR0 0
+#define DWDR1 1
+#define DWDR2 2
+#define DWDR3 3
+#define DWDR4 4
+#define DWDR5 5
+#define DWDR6 6
+#define DWDR7 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define PUD 4
+#define BODS 5
+#define BODSE 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+#define SIGRD 5
+#define RWWSB 6
+
+#define WDTCR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define CLKCSR _SFR_MEM8(0x62)
+#define CLKC0 0
+#define CLKC1 1
+#define CLKC2 2
+#define CLKC3 3
+#define CLKRDY 4
+#define CLKCCE 7
+
+#define CLKSELR _SFR_MEM8(0x63)
+#define CSEL0 0
+#define CSEL1 1
+#define CSEL2 2
+#define CSEL3 3
+#define CSUT0 4
+#define CSUT1 5
+#define COUT 6
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+#define PRSPI 4
+#define PRLIN 5
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#define AMISCR _SFR_MEM8(0x77)
+#define ISRCEN 0
+#define XREFEN 1
+#define AREFEN 2
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACIR0 4
+#define ACIR1 5
+#define ACME 6
+#define BIN 7
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define ADC8D 0
+#define ADC9D 1
+#define ADC10D 2
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCCR1D _SFR_MEM8(0x83)
+#define OC1AU 0
+#define OC1AV 1
+#define OC1AW 2
+#define OC1AX 3
+#define OC1BU 4
+#define OC1BV 5
+#define OC1BW 6
+#define OC1BX 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define ASSR _SFR_MEM8(0xB6)
+#define TCR0BUB 0
+#define TCR0AUB 1
+#define OCR0AUB 3
+#define TCN0UB 4
+#define AS0 5
+#define EXCLK 6
+
+#define USICR _SFR_MEM8(0xB8)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_MEM8(0xB9)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_MEM8(0xBA)
+#define USIDR0 0
+#define USIDR1 1
+#define USIDR2 2
+#define USIDR3 3
+#define USIDR4 4
+#define USIDR5 5
+#define USIDR6 6
+#define USIDR7 7
+
+#define USIBR _SFR_MEM8(0xBB)
+#define USIBR0 0
+#define USIBR1 1
+#define USIBR2 2
+#define USIBR3 3
+#define USIBR4 4
+#define USIBR5 5
+#define USIBR6 6
+#define USIBR7 7
+
+#define USIPP _SFR_MEM8(0xBC)
+#define USIPOS 0
+
+#define LINCR _SFR_MEM8(0xC8)
+#define LCMD0 0
+#define LCMD1 1
+#define LCMD2 2
+#define LENA 3
+#define LCONF0 4
+#define LCONF1 5
+#define LIN13 6
+#define LSWRES 7
+
+#define LINSIR _SFR_MEM8(0xC9)
+#define LRXOK 0
+#define LTXOK 1
+#define LIDOK 2
+#define LERR 3
+#define LBUSY 4
+#define LIDST0 5
+#define LIDST1 6
+#define LIDST2 7
+
+#define LINENIR _SFR_MEM8(0xCA)
+#define LENRXOK 0
+#define LENTXOK 1
+#define LENIDOK 2
+#define LENERR 3
+
+#define LINERR _SFR_MEM8(0xCB)
+#define LBERR 0
+#define LCERR 1
+#define LPERR 2
+#define LSERR 3
+#define LFERR 4
+#define LOVERR 5
+#define LTOERR 6
+#define LABORT 7
+
+#define LINBTR _SFR_MEM8(0xCC)
+#define LBT0 0
+#define LBT1 1
+#define LBT2 2
+#define LBT3 3
+#define LBT4 4
+#define LBT5 5
+#define LDISR 7
+
+#define LINBRR _SFR_MEM16(0xCD)
+
+#define LINBRRL _SFR_MEM8(0xCD)
+#define LDIV0 0
+#define LDIV1 1
+#define LDIV2 2
+#define LDIV3 3
+#define LDIV4 4
+#define LDIV5 5
+#define LDIV6 6
+#define LDIV7 7
+
+#define LINBRRH _SFR_MEM8(0xCE)
+#define LDIV8 0
+#define LDIV9 1
+#define LDIV10 2
+#define LDIV11 3
+
+#define LINDLR _SFR_MEM8(0xCF)
+#define LRXDL0 0
+#define LRXDL1 1
+#define LRXDL2 2
+#define LRXDL3 3
+#define LTXDL0 4
+#define LTXDL1 5
+#define LTXDL2 6
+#define LTXDL3 7
+
+#define LINIDR _SFR_MEM8(0xD0)
+#define LID0 0
+#define LID1 1
+#define LID2 2
+#define LID3 3
+#define LID4 4
+#define LID5 5
+#define LP0 6
+#define LP1 7
+
+#define LINSEL _SFR_MEM8(0xD1)
+#define LINDX0 0
+#define LINDX1 1
+#define LINDX2 2
+#define LAINC 3
+
+#define LINDAT _SFR_MEM8(0xD2)
+#define LDATA0 0
+#define LDATA1 1
+#define LDATA2 2
+#define LDATA3 3
+#define LDATA4 4
+#define LDATA5 5
+#define LDATA6 6
+#define LDATA7 7
+
+
+/* Interrupt vectors */
+/* Vector 0 is the reset vector */
+#define INT0_vect_num 1
+#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
+#define USI_OVF_vect_num 19
+#define USI_OVF_vect _VECTOR(19) /* USI Overflow */
+#define INT1_vect_num 2
+#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
+#define PCINT0_vect_num 3
+#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
+#define PCINT1_vect_num 4
+#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 1 */
+#define WDT_vect_num 5
+#define WDT_vect _VECTOR(5) /* Watchdog Time-Out Interrupt */
+#define TIMER1_CAPT_vect_num 6
+#define TIMER1_CAPT_vect _VECTOR(6) /* Timer/Counter1 Capture Event */
+#define TIMER1_COMPA_vect_num 7
+#define TIMER1_COMPA_vect _VECTOR(7) /* Timer/Counter1 Compare Match 1A */
+#define TIMER1_COMPB_vect_num 8
+#define TIMER1_COMPB_vect _VECTOR(8) /* Timer/Counter1 Compare Match 1B */
+#define TIMER1_OVF_vect_num 9
+#define TIMER1_OVF_vect _VECTOR(9) /* Timer/Counter1 Overflow */
+#define TIMER0_COMPA_vect_num 10
+#define TIMER0_COMPA_vect _VECTOR(10) /* Timer/Counter0 Compare Match 0A */
+#define TIMER0_OVF_vect_num 11
+#define TIMER0_OVF_vect _VECTOR(11) /* Timer/Counter0 Overflow */
+#define LIN_TC_vect_num 12
+#define LIN_TC_vect _VECTOR(12) /* LIN Transfer Complete */
+#define LIN_ERR_vect_num 13
+#define LIN_ERR_vect _VECTOR(13) /* LIN Error */
+#define SPI_STC_vect_num 14
+#define SPI_STC_vect _VECTOR(14) /* SPI Serial Transfer Complete */
+#define ADC_vect_num 15
+#define ADC_vect _VECTOR(15) /* ADC Conversion Complete */
+#define EE_RDY_vect_num 16
+#define EE_RDY_vect _VECTOR(16) /* EEPROM Ready */
+#define ANA_COMP_vect_num 17
+#define ANA_COMP_vect _VECTOR(17) /* Analog Comparator */
+#define USI_START_vect_num 18
+#define USI_START_vect _VECTOR(18) /* USI Start */
+
+#define _VECTOR_SIZE 2 /* Size of individual vector. */
+#define _VECTORS_SIZE (20 * _VECTOR_SIZE)
+
+
+/* Constants */
+#define SPM_PAGESIZE (128)
+#define RAMSTART (0x0100)
+#define RAMSIZE (512)
+#define RAMEND (RAMSTART + RAMSIZE - 1)
+#define XRAMSTART (NA)
+#define XRAMSIZE (0)
+#define XRAMEND (RAMEND)
+#define E2END (0x1FF)
+#define E2PAGESIZE (4)
+#define FLASHEND (0x1FFF)
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock Output Enable */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through the Chip Erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer always ON */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial Program and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* DebugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External Reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN (unsigned char)~_BV(0) /* Self-Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x87
+
+
+#endif /* _AVR_ATtiny87_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iotn88.h b/cpukit/score/cpu/avr/avr/iotn88.h
new file mode 100644
index 0000000000..fd70853ed0
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotn88.h
@@ -0,0 +1,757 @@
+/* Copyright (c) 2007 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id$ */
+
+/* avr/iotn88.h - definitions for ATtiny88 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotn88.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_IOTN88_H_
+#define _AVR_IOTN88_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define PINB _SFR_IO8(0x03)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x05)
+#define PORTB0 0
+#define PORTB1 1
+#define PORTB2 2
+#define PORTB3 3
+#define PORTB4 4
+#define PORTB5 5
+#define PORTB6 6
+#define PORTB7 7
+
+#define PINC _SFR_IO8(0x06)
+#define PINC0 0
+#define PINC1 1
+#define PINC2 2
+#define PINC3 3
+#define PINC4 4
+#define PINC5 5
+#define PINC6 6
+#define PINC7 7
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC0 0
+#define DDC1 1
+#define DDC2 2
+#define DDC3 3
+#define DDC4 4
+#define DDC5 5
+#define DDC6 6
+#define DDC7 7
+
+#define PORTC _SFR_IO8(0x08)
+#define PORTC0 0
+#define PORTC1 1
+#define PORTC2 2
+#define PORTC3 3
+#define PORTC4 4
+#define PORTC5 5
+#define PORTC6 6
+#define PORTC7 7
+
+#define PIND _SFR_IO8(0x09)
+#define PIND0 0
+#define PIND1 1
+#define PIND2 2
+#define PIND3 3
+#define PIND4 4
+#define PIND5 5
+#define PIND6 6
+#define PIND7 7
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD0 0
+#define DDD1 1
+#define DDD2 2
+#define DDD3 3
+#define DDD4 4
+#define DDD5 5
+#define DDD6 6
+#define DDD7 7
+
+#define PORTD _SFR_IO8(0x0B)
+#define PORTD0 0
+#define PORTD1 1
+#define PORTD2 2
+#define PORTD3 3
+#define PORTD4 4
+#define PORTD5 5
+#define PORTD6 6
+#define PORTD7 7
+
+#define PINA _SFR_IO8(0x0C)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+
+#define DDRA _SFR_IO8(0x0D)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+
+#define PORTA _SFR_IO8(0x0E)
+#define PORTA0 0
+#define PORTA1 1
+#define PORTA2 2
+#define PORTA3 3
+
+#define PORTCR _SFR_IO8(0x12)
+#define PUDA 0
+#define PUDB 1
+#define PUDC 2
+#define PUDD 3
+#define BBMA 4
+#define BBMB 5
+#define BBMC 6
+#define BBMD 7
+
+#define TIFR0 _SFR_IO8(0x15)
+#define TOV0 0
+#define OCF0A 1
+#define OCF0B 2
+
+#define TIFR1 _SFR_IO8(0x16)
+#define TOV1 0
+#define OCF1A 1
+#define OCF1B 2
+#define ICF1 5
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+#define PCIF1 1
+#define PCIF2 2
+#define PCIF3 3
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF0 0
+#define INTF1 1
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT0 0
+#define INT1 1
+
+#define GPIOR0 _SFR_IO8(0x1E)
+#define GPIOR00 0
+#define GPIOR01 1
+#define GPIOR02 2
+#define GPIOR03 3
+#define GPIOR04 4
+#define GPIOR05 5
+#define GPIOR06 6
+#define GPIOR07 7
+
+#define EECR _SFR_IO8(0x1F)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+#define EEDR _SFR_IO8(0x20)
+#define EEDR0 0
+#define EEDR1 1
+#define EEDR2 2
+#define EEDR3 3
+#define EEDR4 4
+#define EEDR5 5
+#define EEDR6 6
+#define EEDR7 7
+
+#define EEARL _SFR_IO8(0x21)
+#define EEAR0 0
+#define EEAR1 1
+#define EEAR2 2
+#define EEAR3 3
+#define EEAR4 4
+#define EEAR5 5
+#define EEAR6 6
+#define EEAR7 7
+
+#define GTCCR _SFR_IO8(0x23)
+#define PSRSYNC 0
+#define TSM 7
+
+#define TCCR0A _SFR_IO8(0x25)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define CTC0 3
+
+#define TCNT0 _SFR_IO8(0x26)
+#define TCNT0_0 0
+#define TCNT0_1 1
+#define TCNT0_2 2
+#define TCNT0_3 3
+#define TCNT0_4 4
+#define TCNT0_5 5
+#define TCNT0_6 6
+#define TCNT0_7 7
+
+#define OCR0A _SFR_IO8(0x27)
+#define OCR0A_0 0
+#define OCR0A_1 1
+#define OCR0A_2 2
+#define OCR0A_3 3
+#define OCR0A_4 4
+#define OCR0A_5 5
+#define OCR0A_6 6
+#define OCR0A_7 7
+
+#define OCR0B _SFR_IO8(0x28)
+#define OCR0B_0 0
+#define OCR0B_1 1
+#define OCR0B_2 2
+#define OCR0B_3 3
+#define OCR0B_4 4
+#define OCR0B_5 5
+#define OCR0B_6 6
+#define OCR0B_7 7
+
+#define GPIOR1 _SFR_IO8(0x2A)
+#define GPIOR10 0
+#define GPIOR11 1
+#define GPIOR12 2
+#define GPIOR13 3
+#define GPIOR14 4
+#define GPIOR15 5
+#define GPIOR16 6
+#define GPIOR17 7
+
+#define GPIOR2 _SFR_IO8(0x2B)
+#define GPIOR20 0
+#define GPIOR21 1
+#define GPIOR22 2
+#define GPIOR23 3
+#define GPIOR24 4
+#define GPIOR25 5
+#define GPIOR26 6
+#define GPIOR27 7
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPR0 0
+#define SPR1 1
+#define CPHA 2
+#define CPOL 3
+#define MSTR 4
+#define DORD 5
+#define SPE 6
+#define SPIE 7
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPI2X 0
+#define WCOL 6
+#define SPIF 7
+
+#define SPDR _SFR_IO8(0x2E)
+#define SPDR0 0
+#define SPDR1 1
+#define SPDR2 2
+#define SPDR3 3
+#define SPDR4 4
+#define SPDR5 5
+#define SPDR6 6
+#define SPDR7 7
+
+#define ACSR _SFR_IO8(0x30)
+#define ACIS0 0
+#define ACIS1 1
+#define ACIC 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define SMCR _SFR_IO8(0x33)
+#define SE 0
+#define SM0 1
+#define SM1 2
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define PUD 4
+#define BODSE 5
+#define BODS 6
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SELFPRGEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+#define RWWSB 6
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PRR _SFR_MEM8(0x64)
+#define PRADC 0
+#define PRSPI 2
+#define PRTIM1 3
+#define PRTIM0 5
+#define PRTWI 7
+
+#define OSCCAL _SFR_MEM8(0x66)
+#define CAL0 0
+#define CAL1 1
+#define CAL2 2
+#define CAL3 3
+#define CAL4 4
+#define CAL5 5
+#define CAL6 6
+#define CAL7 7
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+#define PCIE1 1
+#define PCIE2 2
+#define PCIE3 3
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC00 0
+#define ISC01 1
+#define ISC10 2
+#define ISC11 3
+
+#define PCMSK3 _SFR_MEM8(0x6A)
+#define PCINT24 0
+#define PCINT25 1
+#define PCINT26 2
+#define PCINT27 3
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK2 _SFR_MEM8(0x6D)
+#define PCINT16 0
+#define PCINT17 1
+#define PCINT18 2
+#define PCINT19 3
+#define PCINT20 4
+#define PCINT21 5
+#define PCINT22 6
+#define PCINT23 7
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define TOIE0 0
+#define OCIE0A 1
+#define OCIE0B 2
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define TOIE1 0
+#define OCIE1A 1
+#define OCIE1B 2
+#define ICIE1 5
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+
+#define ADCL _SFR_MEM8(0x78)
+#define ADCL0 0
+#define ADCL1 1
+#define ADCL2 2
+#define ADCL3 3
+#define ADCL4 4
+#define ADCL5 5
+#define ADCL6 6
+#define ADCL7 7
+
+#define ADCH _SFR_MEM8(0x79)
+#define ADCH0 0
+#define ADCH1 1
+#define ADCH2 2
+#define ADCH3 3
+#define ADCH4 4
+#define ADCH5 5
+#define ADCH6 6
+#define ADCH7 7
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define ACME 6
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define ADLAR 5
+#define REFS0 6
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define ADC3D 3
+#define ADC4D 4
+#define ADC5D 5
+#define ADC6D 6
+#define ADC7D 7
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN0D 0
+#define AIN1D 1
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define WGM10 0
+#define WGM11 1
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define WGM12 3
+#define WGM13 4
+#define ICES1 6
+#define ICNC1 7
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1B 6
+#define FOC1A 7
+
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1L0 0
+#define TCNT1L1 1
+#define TCNT1L2 2
+#define TCNT1L3 3
+#define TCNT1L4 4
+#define TCNT1L5 5
+#define TCNT1L6 6
+#define TCNT1L7 7
+
+#define TCNT1H _SFR_MEM8(0x85)
+#define TCNT1H0 0
+#define TCNT1H1 1
+#define TCNT1H2 2
+#define TCNT1H3 3
+#define TCNT1H4 4
+#define TCNT1H5 5
+#define TCNT1H6 6
+#define TCNT1H7 7
+
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1L0 0
+#define ICR1L1 1
+#define ICR1L2 2
+#define ICR1L3 3
+#define ICR1L4 4
+#define ICR1L5 5
+#define ICR1L6 6
+#define ICR1L7 7
+
+#define ICR1H _SFR_MEM8(0x87)
+#define ICR1H0 0
+#define ICR1H1 1
+#define ICR1H2 2
+#define ICR1H3 3
+#define ICR1H4 4
+#define ICR1H5 5
+#define ICR1H6 6
+#define ICR1H7 7
+
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AL0 0
+#define OCR1AL1 1
+#define OCR1AL2 2
+#define OCR1AL3 3
+#define OCR1AL4 4
+#define OCR1AL5 5
+#define OCR1AL6 6
+#define OCR1AL7 7
+
+#define OCR1AH _SFR_MEM8(0x89)
+#define OCR1AH0 0
+#define OCR1AH1 1
+#define OCR1AH2 2
+#define OCR1AH3 3
+#define OCR1AH4 4
+#define OCR1AH5 5
+#define OCR1AH6 6
+#define OCR1AH7 7
+
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BL0 0
+#define OCR1BL1 1
+#define OCR1BL2 2
+#define OCR1BL3 3
+#define OCR1BL4 4
+#define OCR1BL5 5
+#define OCR1BL6 6
+#define OCR1BL7 7
+
+#define OCR1BH _SFR_MEM8(0x8B)
+#define OCR1BH0 0
+#define OCR1BH1 1
+#define OCR1BH2 2
+#define OCR1BH3 3
+#define OCR1BH4 4
+#define OCR1BH5 5
+#define OCR1BH6 6
+#define OCR1BH7 7
+
+#define TWBR _SFR_MEM8(0xB8)
+#define TWBR0 0
+#define TWBR1 1
+#define TWBR2 2
+#define TWBR3 3
+#define TWBR4 4
+#define TWBR5 5
+#define TWBR6 6
+#define TWBR7 7
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWPS0 0
+#define TWPS1 1
+#define TWS3 3
+#define TWS4 4
+#define TWS5 5
+#define TWS6 6
+#define TWS7 7
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWGCE 0
+#define TWA0 1
+#define TWA1 2
+#define TWA2 3
+#define TWA3 4
+#define TWA4 5
+#define TWA5 6
+#define TWA6 7
+
+#define TWDR _SFR_MEM8(0xBB)
+#define TWD0 0
+#define TWD1 1
+#define TWD2 2
+#define TWD3 3
+#define TWD4 4
+#define TWD5 5
+#define TWD6 6
+#define TWD7 7
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWIE 0
+#define TWEN 2
+#define TWWC 3
+#define TWSTO 4
+#define TWSTA 5
+#define TWEA 6
+#define TWINT 7
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM0 1
+#define TWAM1 2
+#define TWAM2 3
+#define TWAM3 4
+#define TWAM4 5
+#define TWAM5 6
+#define TWAM6 7
+
+#define TWHSR _SFR_MEM8(0xBE)
+#define TWIHS 0
+
+
+
+/* Interrupt Vectors */
+/* Interrupt vector 0 is the reset vector. */
+
+#define INT0_vect _VECTOR(1)
+#define INT1_vect _VECTOR(2)
+#define PCINT0_vect _VECTOR(3)
+#define PCINT1_vect _VECTOR(4)
+#define PCINT2_vect _VECTOR(5)
+#define PCINT3_vect _VECTOR(6)
+#define WDT_vect _VECTOR(7)
+#define TIMER1_CAPT_vect _VECTOR(8)
+#define TIMER1_COMPA_vect _VECTOR(9)
+#define TIMER1_COMPB_vect _VECTOR(10)
+#define TIMER1_OVF_vect _VECTOR(11)
+#define TIMER0_COMPA_vect _VECTOR(12)
+#define TIMER0_COMPB_vect _VECTOR(13)
+#define TIMER0_OVF_vect _VECTOR(14)
+#define SPI_STC_vect _VECTOR(15)
+#define ADC_vect _VECTOR(16)
+#define EE_READY_vect _VECTOR(17)
+#define ANALOG_COMP_vect _VECTOR(18)
+#define TWI_vect _VECTOR(19)
+
+#define _VECTORS_SIZE 40
+
+
+/* Constants */
+#define RAMEND 0x1FF
+#define XRAMSIZE 0
+#define XRAMEND RAMEND
+#define E2END 0x3F
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+#define SPM_PAGESIZE 32
+
+
+/* Fuse Information */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0) /* Select Clock Source */
+#define FUSE_CKSEL1 (unsigned char)~_BV(1) /* Select Clock Source */
+#define FUSE_CKSEL2 (unsigned char)~_BV(2) /* Select Clock Source */
+#define FUSE_CKSEL3 (unsigned char)~_BV(3) /* Select Clock Source */
+#define FUSE_SUT0 (unsigned char)~_BV(4) /* Select start-up time */
+#define FUSE_SUT1 (unsigned char)~_BV(5) /* Select start-up time */
+#define FUSE_CKOUT (unsigned char)~_BV(6) /* Clock output */
+#define FUSE_CKDIV8 (unsigned char)~_BV(7) /* Divide clock by 8 */
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1) /* Brown-out Detector trigger level */
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2) /* Brown-out Detector trigger level */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* EEPROM memory is preserved through chip erase */
+#define FUSE_WDTON (unsigned char)~_BV(4) /* Watchdog Timer Always On */
+#define FUSE_SPIEN (unsigned char)~_BV(5) /* Enable Serial programming and Data Downloading */
+#define FUSE_DWEN (unsigned char)~_BV(6) /* debugWIRE Enable */
+#define FUSE_RSTDISBL (unsigned char)~_BV(7) /* External reset disable */
+#define HFUSE_DEFAULT (FUSE_SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_SELFPRGEN ~_BV(0) /* Self Programming Enable */
+#define EFUSE_DEFAULT (0xFF)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x93
+#define SIGNATURE_2 0x11
+
+
+#endif /* _AVR_IOTN88_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotnx4.h b/cpukit/score/cpu/avr/avr/iotnx4.h
new file mode 100644
index 0000000000..a02fa6f761
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotnx4.h
@@ -0,0 +1,456 @@
+/* Copyright (c) 2005, 2007, 2009 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotnx4.h - definitions for ATtiny24, ATtiny44 and ATtiny84 */
+
+#ifndef _AVR_IOTNX4_H_
+#define _AVR_IOTNX4_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotnx4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+#define PRR _SFR_IO8 (0x00)
+#define PRTIM1 3
+#define PRTIM0 2
+#define PRUSI 1
+#define PRADC 0
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+/* Reserved [0x02] */
+
+#define ADCSRB _SFR_IO8 (0x03)
+#define BIN 7
+#define ACME 6
+#define ADLAR 4
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+#define ADCSRA _SFR_IO8 (0x06)
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+#define ADMUX _SFR_IO8(0x07)
+#define REFS1 7
+#define REFS0 6
+#define MUX5 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+#define ACSR _SFR_IO8(0x08)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+/* Reserved [0x09..0x0A] */
+
+#define TIFR1 _SFR_IO8(0x0B)
+#define ICF1 5
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+#define TIMSK1 _SFR_IO8(0x0C)
+#define ICIE1 5
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+#define USICR _SFR_IO8(0x0D)
+#define USISIE 7
+#define USIOIE 6
+#define USIWM1 5
+#define USIWM0 4
+#define USICS1 3
+#define USICS0 2
+#define USICLK 1
+#define USITC 0
+
+#define USISR _SFR_IO8(0x0E)
+#define USISIF 7
+#define USIOIF 6
+#define USIPF 5
+#define USIDC 4
+#define USICNT3 3
+#define USICNT2 2
+#define USICNT1 1
+#define USICNT0 0
+
+#define USIDR _SFR_IO8(0x0F)
+
+#define USIBR _SFR_IO8(0x10)
+
+/* Reserved [0x11] */
+
+#define PCMSK0 _SFR_IO8(0x12)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define GPIOR0 _SFR_IO8(0x13)
+
+#define GPIOR1 _SFR_IO8(0x14)
+
+#define GPIOR2 _SFR_IO8(0x15)
+
+#define PINB _SFR_IO8(0x16)
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x18)
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINA _SFR_IO8(0x19)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0x1B)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+/* EEPROM Control Register EECR */
+#define EECR _SFR_IO8(0x1C)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define PCMSK1 _SFR_IO8(0x20)
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+#define WDTCSR _SFR_IO8(0x21)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define TCCR1C _SFR_IO8(0x22)
+#define FOC1A 7
+#define FOC1B 6
+
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSR10 0
+
+#define ICR1 _SFR_IO16(0x24)
+#define ICR1L _SFR_IO8(0x24)
+#define ICR1H _SFR_IO8(0x25)
+
+#define CLKPR _SFR_IO8(0x26)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+#define DWDR _SFR_IO8(0x27)
+
+#define OCR1B _SFR_IO16(0x28)
+#define OCR1BL _SFR_IO8(0x28)
+#define OCR1BH _SFR_IO8(0x29)
+
+#define OCR1A _SFR_IO16(0x2A)
+#define OCR1AL _SFR_IO8(0x2A)
+#define OCR1AH _SFR_IO8(0x2B)
+
+/* keep misspelled names from avr-libc 1.4.[0..1] for compatibility */
+#define OCRB1 _SFR_IO16(0x28)
+#define OCRB1L _SFR_IO8(0x28)
+#define OCRB1H _SFR_IO8(0x29)
+
+#define OCRA1 _SFR_IO16(0x2A)
+#define OCRA1L _SFR_IO8(0x2A)
+#define OCRA1H _SFR_IO8(0x2B)
+
+#define TCNT1 _SFR_IO16(0x2C)
+#define TCNT1L _SFR_IO8(0x2C)
+#define TCNT1H _SFR_IO8(0x2D)
+
+#define TCCR1B _SFR_IO8(0x2E)
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define TCCR1A _SFR_IO8(0x2F)
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define WGM11 1
+#define WGM10 0
+
+#define TCCR0A _SFR_IO8(0x30)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define OSCCAL _SFR_IO8(0x31)
+
+#define TCNT0 _SFR_IO8(0x32)
+
+#define TCCR0B _SFR_IO8(0x33)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0x35)
+#define BODS 7
+#define PUD 6
+#define SE 5
+#define SM1 4
+#define SM0 3
+#define BODSE 2
+#define ISC01 1
+#define ISC00 0
+
+#define OCR0A _SFR_IO8(0x36)
+
+#define SPMCSR _SFR_IO8(0x37)
+#define RSIG 5
+#define CTPB 4
+#define RFLB 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+#define TIFR0 _SFR_IO8(0x38)
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIMSK0 _SFR_IO8(0x39)
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define GIFR _SFR_IO8(0x3A)
+#define INTF0 6
+#define PCIF1 5
+#define PCIF0 4
+
+#define GIMSK _SFR_IO8(0x3B)
+#define INT0 6
+#define PCIE1 5
+#define PCIE0 4
+
+#define OCR0B _SFR_IO8(0x3C)
+
+/* 0x3D..0x3E SP [defined in <avr/io.h>] */
+/* 0x3F SREG [defined in <avr/io.h>] */
+
+///---
+
+/* Interrupt vectors */
+/* Interrupt vector 0 is the reset vector. */
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+#define EXT_INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE0 _VECTOR(2)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(3)
+#define SIG_PIN_CHANGE1 _VECTOR(3)
+
+/* Watchdog Time-out */
+#define WDT_vect _VECTOR(4)
+#define WATCHDOG_vect _VECTOR(4)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(4)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(5)
+#define TIM1_CAPT_vect _VECTOR(5)
+#define SIG_INPUT_CAPTURE1 _VECTOR(5)
+
+/* Timer/Counter1 Compare Match A */
+#define TIM1_COMPA_vect _VECTOR(6)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(6)
+
+/* Timer/Counter1 Compare Match B */
+#define TIM1_COMPB_vect _VECTOR(7)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(7)
+
+/* Timer/Counter1 Overflow */
+#define TIM1_OVF_vect _VECTOR(8)
+#define SIG_OVERFLOW1 _VECTOR(8)
+
+/* Timer/Counter0 Compare Match A */
+#define TIM0_COMPA_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(9)
+
+/* Timer/Counter0 Compare Match B */
+#define TIM0_COMPB_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(10)
+
+/* Timer/Counter0 Overflow */
+#define TIM0_OVF_vect _VECTOR(11)
+#define SIG_OVERFLOW0 _VECTOR(11)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(12)
+#define SIG_COMPARATOR _VECTOR(12)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(13)
+#define SIG_ADC _VECTOR(13)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(14)
+#define SIG_EEPROM_READY _VECTOR(14)
+
+/* USI START */
+#define USI_START_vect _VECTOR(15)
+#define USI_STR_vect _VECTOR(15)
+#define SIG_USI_START _VECTOR(15)
+
+/* USI Overflow */
+#define USI_OVF_vect _VECTOR(16)
+#define SIG_USI_OVERFLOW _VECTOR(16)
+
+#define _VECTORS_SIZE 34
+
+#endif /* _AVR_IOTNX4_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotnx5.h b/cpukit/score/cpu/avr/avr/iotnx5.h
new file mode 100644
index 0000000000..17d4be1586
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotnx5.h
@@ -0,0 +1,416 @@
+/* Copyright (c) 2005, 2007, 2009 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotnx5.h - definitions for ATtiny25, ATtiny45 and ATtiny85 */
+
+#ifndef _AVR_IOTNX5_H_
+#define _AVR_IOTNX5_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotnx5.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* I/O registers */
+
+/* Reserved [0x00..0x02] */
+
+#define ADCSRB _SFR_IO8 (0x03)
+#define BIN 7
+#define ACME 6
+#define IPR 5
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+#define ADCW _SFR_IO16(0x04)
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+#define ADCSRA _SFR_IO8 (0x06)
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+#define ADMUX _SFR_IO8(0x07)
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define REFS2 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+#define ACSR _SFR_IO8(0x08)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIS1 1
+#define ACIS0 0
+
+/* Reserved [0x09..0x0C] */
+
+#define USICR _SFR_IO8(0x0D)
+#define USISIE 7
+#define USIOIE 6
+#define USIWM1 5
+#define USIWM0 4
+#define USICS1 3
+#define USICS0 2
+#define USICLK 1
+#define USITC 0
+
+#define USISR _SFR_IO8(0x0E)
+#define USISIF 7
+#define USIOIF 6
+#define USIPF 5
+#define USIDC 4
+#define USICNT3 3
+#define USICNT2 2
+#define USICNT1 1
+#define USICNT0 0
+
+#define USIDR _SFR_IO8(0x0F)
+#define USIBR _SFR_IO8(0x10)
+
+#define GPIOR0 _SFR_IO8(0x11)
+#define GPIOR1 _SFR_IO8(0x12)
+#define GPIOR2 _SFR_IO8(0x13)
+
+#define DIDR0 _SFR_IO8(0x14)
+#define ADC0D 5
+#define ADC2D 4
+#define ADC3D 3
+#define ADC1D 2
+#define AIN1D 1
+#define AIN0D 0
+
+#define PCMSK _SFR_IO8(0x15)
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define PINB _SFR_IO8(0x16)
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x18)
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+/* Reserved [0x19..0x1B] */
+
+/* EEPROM Control Register EECR */
+#define EECR _SFR_IO8(0x1C)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define PRR _SFR_IO8(0x20)
+#define PRTIM1 3
+#define PRTIM0 2
+#define PRUSI 1
+#define PRADC 0
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define DWDR _SFR_IO8(0x22)
+
+#define DTPS1 _SFR_IO8(0x23)
+#define DTPS11 1
+#define DTPS10 0
+
+#define DT1B _SFR_IO8(0x24)
+#define DT1BH3 7
+#define DT1BH2 6
+#define DT1BH1 5
+#define DT1BH0 4
+#define DT1BL3 3
+#define DT1BL2 2
+#define DT1BL1 1
+#define DT1BL0 0
+
+#define DT1A _SFR_IO8(0x25)
+#define DT1AH3 7
+#define DT1AH2 6
+#define DT1AH1 5
+#define DT1AH0 4
+#define DT1AL3 3
+#define DT1AL2 2
+#define DT1AL1 1
+#define DT1AL0 0
+
+#define CLKPR _SFR_IO8(0x26)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+#define PLLCSR _SFR_IO8(0x27)
+#define LSM 7
+#define PCKE 2
+#define PLLE 1
+#define PLOCK 0
+
+#define OCR0B _SFR_IO8(0x28)
+
+#define OCR0A _SFR_IO8(0x29)
+
+#define TCCR0A _SFR_IO8(0x2A)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define OCR1B _SFR_IO8(0x2B)
+
+#define GTCCR _SFR_IO8(0x2C)
+#define TSM 7
+#define PWM1B 6
+#define COM1B1 5
+#define COM1B0 4
+#define FOC1B 3
+#define FOC1A 2
+#define PSR1 1
+#define PSR0 0
+
+#define OCR1C _SFR_IO8(0x2D)
+
+#define OCR1A _SFR_IO8(0x2E)
+
+#define TCNT1 _SFR_IO8(0x2F)
+
+#define TCCR1 _SFR_IO8(0x30)
+#define CTC1 7
+#define PWM1A 6
+#define COM1A1 5
+#define COM1A0 4
+#define CS13 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define OSCCAL _SFR_IO8(0x31)
+
+#define TCNT0 _SFR_IO8(0x32)
+
+#define TCCR0B _SFR_IO8(0x33)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0x35)
+#define BODS 7
+#define PUD 6
+#define SE 5
+#define SM1 4
+#define SM0 3
+#define BODSE 2
+#define ISC01 1
+#define ISC00 0
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define RSIG 5
+#define CTPB 4
+#define RFLB 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+#define TIFR _SFR_IO8(0x38)
+#define OCF1A 6
+#define OCF1B 5
+#define OCF0A 4
+#define OCF0B 3
+#define TOV1 2
+#define TOV0 1
+
+#define TIMSK _SFR_IO8(0x39)
+#define OCIE1A 6
+#define OCIE1B 5
+#define OCIE0A 4
+#define OCIE0B 3
+#define TOIE1 2
+#define TOIE0 1
+
+#define GIFR _SFR_IO8(0x3A)
+#define INTF0 6
+#define PCIF 5
+
+#define GIMSK _SFR_IO8(0x3B)
+#define INT0 6
+#define PCIE 5
+
+/* Reserved [0x3C] */
+
+/* 0x3D..0x3E SP [defined in <avr/io.h>] */
+/* 0x3F SREG [defined in <avr/io.h>] */
+
+///---
+
+/* Interrupt vectors */
+/* Interrupt vector 0 is the reset vector. */
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(2)
+#define SIG_PIN_CHANGE _VECTOR(2)
+
+/* Timer/Counter1 Compare Match 1A */
+#define TIM1_COMPA_vect _VECTOR(3)
+#define TIMER1_COMPA_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(3)
+
+/* Timer/Counter1 Overflow */
+#define TIM1_OVF_vect _VECTOR(4)
+#define TIMER1_OVF_vect _VECTOR(4)
+#define SIG_OVERFLOW1 _VECTOR(4)
+
+/* Timer/Counter0 Overflow */
+#define TIM0_OVF_vect _VECTOR(5)
+#define TIMER0_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW0 _VECTOR(5)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(6)
+#define SIG_EEPROM_READY _VECTOR(6)
+
+/* Analog comparator */
+#define ANA_COMP_vect _VECTOR(7)
+#define SIG_COMPARATOR _VECTOR(7)
+
+/* ADC Conversion ready */
+#define ADC_vect _VECTOR(8)
+#define SIG_ADC _VECTOR(8)
+
+/* Timer/Counter1 Compare Match B */
+#define TIM1_COMPB_vect _VECTOR(9)
+#define TIMER1_COMPB_vect _VECTOR(9)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(9)
+
+/* Timer/Counter0 Compare Match A */
+#define TIM0_COMPA_vect _VECTOR(10)
+#define TIMER0_COMPA_vect _VECTOR(10)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(10)
+
+/* Timer/Counter0 Compare Match B */
+#define TIM0_COMPB_vect _VECTOR(11)
+#define TIMER0_COMPB_vect _VECTOR(11)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(11)
+
+/* Watchdog Time-out */
+#define WDT_vect _VECTOR(12)
+#define SIG_WATCHDOG_TIMEOUT _VECTOR(12)
+
+/* USI START */
+#define USI_START_vect _VECTOR(13)
+#define SIG_USI_START _VECTOR(13)
+
+/* USI Overflow */
+#define USI_OVF_vect _VECTOR(14)
+#define SIG_USI_OVERFLOW _VECTOR(14)
+
+#define _VECTORS_SIZE 30
+
+#endif /* _AVR_IOTNX5_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iotnx61.h b/cpukit/score/cpu/avr/avr/iotnx61.h
new file mode 100644
index 0000000000..f90a90462e
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iotnx61.h
@@ -0,0 +1,515 @@
+/* Copyright (c) 2006, 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iotnx61.h - definitions for ATtiny261, ATtiny461 and ATtiny861 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iotnx61.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#ifndef _AVR_IOTNx61_H_
+#define _AVR_IOTNx61_H_ 1
+
+/* Registers and associated bit numbers */
+
+#define TCCR1E _SFR_IO8(0x00)
+#define OC1OE0 0
+#define OC1OE1 1
+#define OC1OE2 2
+#define OC1OE3 3
+#define OC1OE4 4
+#define OC1OE5 5
+
+#define DIDR0 _SFR_IO8(0x01)
+#define ADC0D 0
+#define ADC1D 1
+#define ADC2D 2
+#define AREFD 3
+#define ADC3D 4
+#define ADC4D 5
+#define ADC5D 6
+#define ADC6D 7
+
+#define DIDR1 _SFR_IO8(0x02)
+#define ADC7D 4
+#define ADC8D 5
+#define ADC9D 6
+#define ADC10D 7
+
+#define ADCSRB _SFR_IO8(0x03)
+#define ADTS0 0
+#define ADTS1 1
+#define ADTS2 2
+#define MUX5 3
+#define REFS2 4
+#define IRP 5
+#define GSEL 6
+#define BIN 7
+
+#define ADCW _SFR_IO16(0x04)
+#ifndef __ASSEMBLER__
+#define ADC _SFR_IO16(0x04)
+#endif
+
+#define ADCL _SFR_IO8(0x04)
+#define ADCH _SFR_IO8(0x05)
+
+#define ADCSRA _SFR_IO8(0x06)
+#define ADPS0 0
+#define ADPS1 1
+#define ADPS2 2
+#define ADIE 3
+#define ADIF 4
+#define ADATE 5
+#define ADSC 6
+#define ADEN 7
+
+#define ADMUX _SFR_IO8(0x07)
+#define MUX0 0
+#define MUX1 1
+#define MUX2 2
+#define MUX3 3
+#define MUX4 4
+#define ADLAR 5
+#define REFS0 6
+#define REFS1 7
+
+#define ACSRA _SFR_IO8(0x08)
+#define ACIS0 0
+#define ACIS1 1
+#define ACME 2
+#define ACIE 3
+#define ACI 4
+#define ACO 5
+#define ACBG 6
+#define ACD 7
+
+#define ACSRB _SFR_IO8(0x09)
+#define ACM0 0
+#define ACM1 1
+#define ACM2 2
+#define HLEV 6
+#define HSEL 7
+
+#define GPIOR0 _SFR_IO8(0x0A)
+
+#define GPIOR1 _SFR_IO8(0x0B)
+
+#define GPIOR2 _SFR_IO8(0x0C)
+
+#define USICR _SFR_IO8(0x0D)
+#define USITC 0
+#define USICLK 1
+#define USICS0 2
+#define USICS1 3
+#define USIWM0 4
+#define USIWM1 5
+#define USIOIE 6
+#define USISIE 7
+
+#define USISR _SFR_IO8(0x0E)
+#define USICNT0 0
+#define USICNT1 1
+#define USICNT2 2
+#define USICNT3 3
+#define USIDC 4
+#define USIPF 5
+#define USIOIF 6
+#define USISIF 7
+
+#define USIDR _SFR_IO8(0x0F)
+
+#define USIBR _SFR_IO8(0x10)
+
+#define USIPP _SFR_IO8(0x11)
+#define USIPOS 0
+
+#define OCR0B _SFR_IO8(0x12)
+
+#define OCR0A _SFR_IO8(0x13)
+
+#define TCNT0H _SFR_IO8(0x14)
+
+#define TCCR0A _SFR_IO8(0x15)
+#define WGM00 0
+#define ACIC0 3
+#define ICES0 4
+#define ICNC0 5
+#define ICEN0 6
+#define TCW0 7
+
+#define PINB _SFR_IO8(0x16)
+#define PINB0 0
+#define PINB1 1
+#define PINB2 2
+#define PINB3 3
+#define PINB4 4
+#define PINB5 5
+#define PINB6 6
+#define PINB7 7
+
+#define DDRB _SFR_IO8(0x17)
+#define DDB0 0
+#define DDB1 1
+#define DDB2 2
+#define DDB3 3
+#define DDB4 4
+#define DDB5 5
+#define DDB6 6
+#define DDB7 7
+
+#define PORTB _SFR_IO8(0x18)
+#define PB0 0
+#define PB1 1
+#define PB2 2
+#define PB3 3
+#define PB4 4
+#define PB5 5
+#define PB6 6
+#define PB7 7
+
+#define PINA _SFR_IO8(0x19)
+#define PINA0 0
+#define PINA1 1
+#define PINA2 2
+#define PINA3 3
+#define PINA4 4
+#define PINA5 5
+#define PINA6 6
+#define PINA7 7
+
+#define DDRA _SFR_IO8(0x1A)
+#define DDA0 0
+#define DDA1 1
+#define DDA2 2
+#define DDA3 3
+#define DDA4 4
+#define DDA5 5
+#define DDA6 6
+#define DDA7 7
+
+#define PORTA _SFR_IO8(0x1B)
+#define PA0 0
+#define PA1 1
+#define PA2 2
+#define PA3 3
+#define PA4 4
+#define PA5 5
+#define PA6 6
+#define PA7 7
+
+/* EEPROM Control Register */
+#define EECR _SFR_IO8(0x1C)
+#define EERE 0
+#define EEPE 1
+#define EEMPE 2
+#define EERIE 3
+#define EEPM0 4
+#define EEPM1 5
+
+/* EEPROM Data Register */
+#define EEDR _SFR_IO8(0x1D)
+
+/* EEPROM Address Register */
+#define EEAR _SFR_IO16(0x1E)
+#define EEARL _SFR_IO8(0x1E)
+#define EEARH _SFR_IO8(0x1F)
+
+#define DWDR _SFR_IO8(0x20)
+
+#define WDTCR _SFR_IO8(0x21)
+#define WDP0 0
+#define WDP1 1
+#define WDP2 2
+#define WDE 3
+#define WDCE 4
+#define WDP3 5
+#define WDIE 6
+#define WDIF 7
+
+#define PCMSK1 _SFR_IO8(0x22)
+#define PCINT8 0
+#define PCINT9 1
+#define PCINT10 2
+#define PCINT11 3
+#define PCINT12 4
+#define PCINT13 5
+#define PCINT14 6
+#define PCINT15 7
+
+#define PCMSK0 _SFR_IO8(0x23)
+#define PCINT0 0
+#define PCINT1 1
+#define PCINT2 2
+#define PCINT3 3
+#define PCINT4 4
+#define PCINT5 5
+#define PCINT6 6
+#define PCINT7 7
+
+#define DT1 _SFR_IO8(0x24)
+#define DT1L0 0
+#define DT1L1 1
+#define DT1L2 2
+#define DT1L3 3
+#define DT1H0 4
+#define DT1H1 5
+#define DT1H2 6
+#define DT1H3 7
+
+#define TC1H _SFR_IO8(0x25)
+#define TC18 0
+#define TC19 1
+
+#define TCCR1D _SFR_IO8(0x26)
+#define WGM10 0
+#define WGM11 1
+#define FPF1 2
+#define FPAC1 3
+#define FPES1 4
+#define FPNC1 5
+#define FPEN1 6
+#define FPIE1 7
+
+#define TCCR1C _SFR_IO8(0x27)
+#define PWM1D 0
+#define FOC1D 1
+#define COM1D0 2
+#define COM1D1 3
+#define COM1B0S 4
+#define COM1B1S 5
+#define COM1A0S 6
+#define COM1A1S 7
+
+#define CLKPR _SFR_IO8(0x28)
+#define CLKPS0 0
+#define CLKPS1 1
+#define CLKPS2 2
+#define CLKPS3 3
+#define CLKPCE 7
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLOCK 0
+#define PLLE 1
+#define PCKE 2
+#define LSM 7
+
+#define OCR1D _SFR_IO8(0x2A)
+
+#define OCR1C _SFR_IO8(0x2B)
+
+#define OCR1B _SFR_IO8(0x2C)
+
+#define OCR1A _SFR_IO8(0x2D)
+
+#define TCNT1 _SFR_IO8(0x2E)
+
+#define TCCR1B _SFR_IO8(0x2F)
+#define CS10 0
+#define CS11 1
+#define CS12 2
+#define CS13 3
+#define DTPS10 4
+#define DTPS11 5
+#define PSR1 6
+#define PWM1X 7
+
+#define TCCR1A _SFR_IO8(0x30)
+#define PWM1B 0
+#define PWM1A 1
+#define FOC1B 2
+#define FOC1A 3
+#define COM1B0 4
+#define COM1B1 5
+#define COM1A0 6
+#define COM1A1 7
+
+#define OSCCAL _SFR_IO8(0x31)
+
+#define TCNT0L _SFR_IO8(0x32)
+
+#define TCCR0B _SFR_IO8(0x33)
+#define CS00 0
+#define CS01 1
+#define CS02 2
+#define PSR0 3
+#define TSM 4
+
+#define MCUSR _SFR_IO8(0x34)
+#define PORF 0
+#define EXTRF 1
+#define BORF 2
+#define WDRF 3
+
+#define MCUCR _SFR_IO8(0x35)
+#define ISC00 0
+#define ISC01 1
+#define SM0 3
+#define SM1 4
+#define SE 5
+#define PUD 6
+
+#define PRR _SFR_IO8(0x36)
+#define PRADC 0
+#define PRUSI 1
+#define PRTIM0 2
+#define PRTIM1 3
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMEN 0
+#define PGERS 1
+#define PGWRT 2
+#define RFLB 3
+#define CTPB 4
+
+#define TIFR _SFR_IO8(0x38)
+#define ICF0 0
+#define TOV0 1
+#define TOV1 2
+#define OCF0B 3
+#define OCF0A 4
+#define OCF1B 5
+#define OCF1A 6
+#define OCF1D 7
+
+#define TIMSK _SFR_IO8(0x39)
+#define TICIE0 0
+#define TOIE0 1
+#define TOIE1 2
+#define OCIE0B 3
+#define OCIE0A 4
+#define OCIE1B 5
+#define OCIE1A 6
+#define OCIE1D 7
+
+#define GIFR _SFR_IO8(0x3A)
+#define PCIF 5
+#define INTF0 6
+#define INTF1 7
+
+#define GIMSK _SFR_IO8(0x3B)
+#define PCIE0 4
+#define PCIE1 5
+#define INT0 6
+#define INT1 7
+
+/* Reserved [0x3C] */
+
+/* 0x3D..0x3E SP [defined in <avr/io.h>] */
+/* 0x3F SREG [defined in <avr/io.h>] */
+
+
+/* Interrupt vectors */
+/* Interrupt vector 0 is the reset vector. */
+/* External Interrupt 0 */
+#define INT0_vect _VECTOR(1)
+#define SIG_INTERRUPT0 _VECTOR(1)
+
+/* Pin Change Interrupt */
+#define PCINT_vect _VECTOR(2)
+#define SIG_PIN_CHANGE _VECTOR(2)
+
+/* Timer/Counter1 Compare Match 1A */
+#define TIMER1_COMPA_vect _VECTOR(3)
+#define SIG_OUTPUT_COMPARE1A _VECTOR(3)
+
+/* Timer/Counter1 Compare Match 1B */
+#define TIMER1_COMPB_vect _VECTOR(4)
+#define SIG_OUTPUT_COMPARE1B _VECTOR(4)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(5)
+#define SIG_OVERFLOW1 _VECTOR(5)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(6)
+#define SIG_OVERFLOW0 _VECTOR(6)
+
+/* USI Start */
+#define USI_START_vect _VECTOR(7)
+#define SIG_USI_START _VECTOR(7)
+
+/* USI Overflow */
+#define USI_OVF_vect _VECTOR(8)
+#define SIG_USI_OVERFLOW _VECTOR(8)
+
+/* EEPROM Ready */
+#define EE_RDY_vect _VECTOR(9)
+#define SIG_EEPROM_READY _VECTOR(9)
+
+/* Analog Comparator */
+#define ANA_COMP_vect _VECTOR(10)
+#define SIG_ANA_COMP _VECTOR(10)
+#define SIG_COMPARATOR _VECTOR(10)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(11)
+#define SIG_ADC _VECTOR(11)
+
+/* Watchdog Time-Out */
+#define WDT_vect _VECTOR(12)
+#define SIG_WDT _VECTOR(12)
+
+/* External Interrupt 1 */
+#define INT1_vect _VECTOR(13)
+#define SIG_INTERRUPT1 _VECTOR(13)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(14)
+#define SIG_OUTPUT_COMPARE0A _VECTOR(14)
+
+/* Timer/Counter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(15)
+#define SIG_OUTPUT_COMPARE0B _VECTOR(15)
+
+/* ADC Conversion Complete */
+#define TIMER0_CAPT_vect _VECTOR(16)
+#define SIG_INPUT_CAPTURE0 _VECTOR(16)
+
+/* Timer/Counter1 Compare Match D */
+#define TIMER1_COMPD_vect _VECTOR(17)
+#define SIG_OUTPUT_COMPARE0D _VECTOR(17)
+
+/* Timer/Counter1 Fault Protection */
+#define FAULT_PROTECTION_vect _VECTOR(18)
+
+#define _VECTORS_SIZE 38
+
+#endif /* _AVR_IOTNx61_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousb1286.h b/cpukit/score/cpu/avr/avr/iousb1286.h
new file mode 100644
index 0000000000..09e8d7c97d
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousb1286.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iousb1286.h - definitions for AT90USB1286 */
+
+#ifndef _AVR_AT90USB1286_H_
+#define _AVR_AT90USB1286_H_ 1
+
+#include <avr/iousbxx6_7.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x20FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_HWBE (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_HWBE)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x82
+
+
+#endif /* _AVR_AT90USB1286_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousb1287.h b/cpukit/score/cpu/avr/avr/iousb1287.h
new file mode 100644
index 0000000000..3c599a3765
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousb1287.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iousb1287.h - definitions for AT90USB1287 */
+
+#ifndef _AVR_AT90USB1287_H_
+#define _AVR_AT90USB1287_H_ 1
+
+#include <avr/iousbxx6_7.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x20FF
+#define XRAMEND 0xFFFF
+#define E2END 0xFFF
+#define E2PAGESIZE 8
+#define FLASHEND 0x1FFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0 & FUSE_CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (FUSE_BOOTSZ0 & FUSE_BOOTSZ1 & FUSE_SPIEN & FUSE_JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_HWBE (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (FUSE_BODLEVEL2 & FUSE_HWBE)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x82
+
+
+#endif /* _AVR_AT90USB1287_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousb162.h b/cpukit/score/cpu/avr/avr/iousb162.h
new file mode 100644
index 0000000000..55e1664d84
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousb162.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iousb162.h - definitions for AT90USB162 */
+
+#ifndef _AVR_AT90USB162_H_
+#define _AVR_AT90USB162_H_ 1
+
+#include <avr/iousbxx2.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x2FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x3FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (CKSEL0 & SUT1 & CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_RSTDSBL (unsigned char)~_BV(6)
+#define FUSE_DWEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (BOOTSZ0 & BOOTSZ1 & SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_HWBE (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (BODLEVEL0 & BODLEVEL1 & HWBE)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x82
+
+
+#endif /* _AVR_AT90USB162_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousb646.h b/cpukit/score/cpu/avr/avr/iousb646.h
new file mode 100644
index 0000000000..4a22602bfd
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousb646.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iousb646.h - definitions for AT90USB646 */
+
+#ifndef _AVR_AT90USB646_H_
+#define _AVR_AT90USB646_H_ 1
+
+#include <avr/iousbxx6_7.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND 0xFFFF
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (CKSEL0 & CKSEL2 & CKSEL3 & SUT0 & CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (BOOTSZ0 & BOOTSZ1 & SPIEN & JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_HWBE (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (BODLEVEL2 & HWBE)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x82
+
+
+#endif /* _AVR_AT90USB646_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousb647.h b/cpukit/score/cpu/avr/avr/iousb647.h
new file mode 100644
index 0000000000..3120183071
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousb647.h
@@ -0,0 +1,94 @@
+/* Copyright (c) 2006 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iousb647.h - definitions for AT90USB647 */
+
+#ifndef _AVR_AT90USB647_H_
+#define _AVR_AT90USB647_H_ 1
+
+#include <avr/iousbxx6_7.h>
+
+/* Constants */
+#define SPM_PAGESIZE 256
+#define RAMEND 0x10FF
+#define XRAMEND 0xFFFF
+#define E2END 0x7FF
+#define E2PAGESIZE 8
+#define FLASHEND 0xFFFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (CKSEL0 & CKSEL2 & CKSEL3 & SUT0 & CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_JTAGEN (unsigned char)~_BV(6)
+#define FUSE_OCDEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (BOOTSZ0 & BOOTSZ1 & SPIEN & JTAGEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_HWBE (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (BODLEVEL2 & HWBE)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+/* Signature */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x82
+
+
+#endif /* _AVR_AT90USB647_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousb82.h b/cpukit/score/cpu/avr/avr/iousb82.h
new file mode 100644
index 0000000000..8e7d1881b0
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousb82.h
@@ -0,0 +1,88 @@
+/* Copyright (c) 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iousb82.h - definitions for AT90USB82 */
+
+#ifndef _AVR_AT90USB82_H_
+#define _AVR_AT90USB82_H_ 1
+
+#include <avr/iousbxx2.h>
+
+/* Constants */
+#define SPM_PAGESIZE 128
+#define RAMEND 0x2FF
+#define XRAMEND RAMEND
+#define E2END 0x1FF
+#define E2PAGESIZE 4
+#define FLASHEND 0x1FFF
+
+
+/* Fuses */
+#define FUSE_MEMORY_SIZE 3
+
+/* Low Fuse Byte */
+#define FUSE_CKSEL0 (unsigned char)~_BV(0)
+#define FUSE_CKSEL1 (unsigned char)~_BV(1)
+#define FUSE_CKSEL2 (unsigned char)~_BV(2)
+#define FUSE_CKSEL3 (unsigned char)~_BV(3)
+#define FUSE_SUT0 (unsigned char)~_BV(4)
+#define FUSE_SUT1 (unsigned char)~_BV(5)
+#define FUSE_CKOUT (unsigned char)~_BV(6)
+#define FUSE_CKDIV8 (unsigned char)~_BV(7)
+#define LFUSE_DEFAULT (CKSEL0 & SUT1 & CKDIV8)
+
+/* High Fuse Byte */
+#define FUSE_BOOTRST (unsigned char)~_BV(0)
+#define FUSE_BOOTSZ0 (unsigned char)~_BV(1)
+#define FUSE_BOOTSZ1 (unsigned char)~_BV(2)
+#define FUSE_EESAVE (unsigned char)~_BV(3)
+#define FUSE_WDTON (unsigned char)~_BV(4)
+#define FUSE_SPIEN (unsigned char)~_BV(5)
+#define FUSE_RSTDSBL (unsigned char)~_BV(6)
+#define FUSE_DWEN (unsigned char)~_BV(7)
+#define HFUSE_DEFAULT (BOOTSZ0 & BOOTSZ1 & SPIEN)
+
+/* Extended Fuse Byte */
+#define FUSE_BODLEVEL0 (unsigned char)~_BV(0)
+#define FUSE_BODLEVEL1 (unsigned char)~_BV(1)
+#define FUSE_BODLEVEL2 (unsigned char)~_BV(2)
+#define FUSE_HWBE (unsigned char)~_BV(3)
+#define EFUSE_DEFAULT (BODLEVEL0 & BODLEVEL1 & HWBE)
+
+
+/* Lock Bits */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_BITS_0_EXIST
+#define __BOOT_LOCK_BITS_1_EXIST
+
+
+#endif /* _AVR_AT90USB82_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousbxx2.h b/cpukit/score/cpu/avr/avr/iousbxx2.h
new file mode 100644
index 0000000000..b989740261
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousbxx2.h
@@ -0,0 +1,766 @@
+/* Copyright (c) 2007 Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iousbxx2.h - definitions for AT90USB82 and AT90USB162. */
+
+#ifndef _AVR_IOUSBXX2_H_
+#define _AVR_IOUSBXX2_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iousbxx2.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+/* Registers and associated bit numbers */
+
+/* Reserved [0x00..0x02] */
+
+#define PINB _SFR_IO8(0X03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+/* Reserved [0xC..0x14] */
+
+#define TIFR0 _SFR_IO8(0x15)
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIFR1 _SFR_IO8(0x16)
+#define ICF1 5
+#define OCF1C 3
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+/* Reserved [0x17..0x1A] */
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF1 1
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0x20)
+
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSRASY 1
+#define PSRSYNC 0
+
+#define TCCR0A _SFR_IO8(0x24)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define TCCR0B _SFR_IO8(0x25)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0x27)
+
+#define OCR0B _SFR_IO8(0X28)
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLLP2 4
+#define PLLP1 3
+#define PLLP0 2
+#define PLLE 1
+#define PLOCK 0
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+#define SPDR _SFR_IO8(0x2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+#define DWDR _SFR_IO8(0x31)
+#define IDRD 7
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define USBRF 5
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0x35)
+#define IVSEL 1
+#define IVCE 0
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMIE 7
+#define RWWSB 6
+#define SIGRD 5
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Reserved [0x38..0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+#define WDTCKD _SFR_MEM8(0x62)
+#define WDEWIF 3
+#define WDEWIE 2
+#define WCLKD1 1
+#define WCLKD0 0
+
+#define REGCR _SFR_MEM8(0x63)
+#define REGDIS 0
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRTIM0 5
+#define PRTIM1 3
+#define PRSPI 2
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSB 7
+#define PRUSART1 0
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67] */
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE1 1
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+#define PCMSK1 _SFR_MEM8(0x6C)
+#define PCINT12 4
+#define PCINT11 3
+#define PCINT10 2
+#define PCINT9 1
+#define PCINT8 0
+
+/* Reserved [0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define ICIE1 5
+#define OCIE1C 3
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+/* Reserved [0x70..0x7F] */
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define COM1C1 3
+#define COM1C0 2
+#define WGM11 1
+#define WGM10 0
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1A 7
+#define FOC1B 6
+#define FOC1C 5
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Combine OCR1CL and OCR1CH */
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CH _SFR_MEM8(0x8D)
+
+/* Reserved [0x8E..0xC7] */
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+#define UCSR1B _SFR_MEM8(0XC9)
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UMSEL11 7
+#define UMSEL10 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+
+#define UCSR1D _SFR_MEM8(0xCB)
+#define CTSEN 1
+#define RTSEN 0
+
+/* Combine UBRR1L and UBRR1H */
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1H _SFR_MEM8(0xCD)
+
+#define UDR1 _SFR_MEM8(0XCE)
+
+/* Reserved [0xCF] */
+
+#define CKSEL0 _SFR_MEM8(0XD0)
+#define RCSUT1 7
+#define RCSUT0 6
+#define EXSUT1 5
+#define EXSUT0 4
+#define RCE 3
+#define EXTE 2
+#define CLKS 0
+
+#define CKSEL1 _SFR_MEM8(0XD1)
+#define RCCKSEL3 7
+#define RCCKSEL2 6
+#define RCCKSEL1 5
+#define RCCKSEL0 4
+#define EXCKSEL3 3
+#define EXCKSEL2 2
+#define EXCKSEL1 1
+#define EXCKSEL0 0
+
+#define CKSTA _SFR_MEM8(0XD2)
+#define RCON 1
+#define EXTON 0
+
+/* Reserved [0xD3..0xD7] */
+
+#define USBCON _SFR_MEM8(0XD8)
+#define USBE 7
+#define FRZCLK 5
+
+/* Reserved [0xD9..0xDA] */
+
+/* Combine UDPADDL and UDPADDH */
+#define UDPADD _SFR_MEM16(0xDB)
+
+#define UDPADDL _SFR_MEM8(0xDB)
+#define UDPADDH _SFR_MEM8(0xDC)
+#define DPACC 7
+
+/* Reserved [0xDD..0xDF] */
+
+#define UDCON _SFR_MEM8(0XE0)
+#define RSTCPU 2
+#define RMWKUP 1
+#define DETACH 0
+
+#define UDINT _SFR_MEM8(0XE1)
+#define UPRSMI 6
+#define EORSMI 5
+#define WAKEUPI 4
+#define EORSTI 3
+#define SOFI 2
+#define SUSPI 0
+
+#define UDIEN _SFR_MEM8(0XE2)
+#define UPRSME 6
+#define EORSME 5
+#define WAKEUPE 4
+#define EORSTE 3
+#define SOFE 2
+#define SUSPE 0
+
+#define UDADDR _SFR_MEM8(0XE3)
+#define ADDEN 7
+
+/* Combine UDFNUML and UDFNUMH */
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define UDFNUMH _SFR_MEM8(0xE5)
+
+#define UDMFN _SFR_MEM8(0XE6)
+#define FNCERR 4
+
+/* Reserved [0xE7] */
+
+#define UEINTX _SFR_MEM8(0XE8)
+#define FIFOCON 7
+#define NAKINI 6
+#define RWAL 5
+#define NAKOUTI 4
+#define RXSTPI 3
+#define RXOUTI 2
+#define STALLEDI 1
+#define TXINI 0
+
+#define UENUM _SFR_MEM8(0XE9)
+#define EPNUM2 2
+#define EPNUM1 1
+#define EPNUM0 0
+
+#define UERST _SFR_MEM8(0XEA)
+#define EPRST4 4
+#define EPRST3 3
+#define EPRST2 2
+#define EPRST1 1
+#define EPRST0 0
+
+#define UECONX _SFR_MEM8(0XEB)
+#define STALLRQ 5
+#define STALLRQC 4
+#define RSTDT 3
+#define EPEN 0
+
+#define UECFG0X _SFR_MEM8(0XEC)
+#define EPTYPE1 7
+#define EPTYPE0 6
+#define EPDIR 0
+
+#define UECFG1X _SFR_MEM8(0XED)
+#define EPSIZE2 6
+#define EPSIZE1 5
+#define EPSIZE0 4
+#define EPBK1 3
+#define EPBK0 2
+#define ALLOC 1
+
+#define UESTA0X _SFR_MEM8(0XEE)
+#define CFGOK 7
+#define OVERFI 6
+#define UNDERFI 5
+#define DTSEQ1 3
+#define DTSEQ0 2
+#define NBUSYBK1 1
+#define NBUSYBK0 0
+
+#define UESTA1X _SFR_MEM8(0XEF)
+#define CTRLDIR 2
+#define CURRBK1 1
+#define CURRBK0 0
+
+#define UEIENX _SFR_MEM8(0XF0)
+#define FLERRE 7
+#define NAKINE 6
+#define NAKOUTE 4
+#define RXSTPE 3
+#define RXOUTE 2
+#define STALLEDE 1
+#define TXINE 0
+
+#define UEDATX _SFR_MEM8(0XF1)
+
+#define UEBCLX _SFR_MEM8(0xF2)
+
+/* Reserved [0xF3] */
+
+#define UEINT _SFR_MEM8(0XF4)
+#define EPINT4 4
+#define EPINT3 3
+#define EPINT2 2
+#define EPINT1 1
+#define EPINT0 0
+
+/* Reserved [0xF5..0xF9] */
+
+#define PS2CON _SFR_MEM8(0XFA)
+#define PS2EN 0
+
+#define UPOE _SFR_MEM8(0XFB)
+#define UPWE1 7
+#define UPWE0 6
+#define UPDRV1 5
+#define UPDRV0 4
+#define SCKI 3
+#define DATAI 2
+#define DPI 1
+#define DMI 0
+
+/* Reserved [0xFC..0xFF] */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(9)
+
+/* Pin Change Interrupt Request 1 */
+#define PCINT1_vect _VECTOR(10)
+
+/* USB General Interrupt Request */
+#define USB_GEN_vect _VECTOR(11)
+
+/* USB Endpoint/Pipe Interrupt Communication Request */
+#define USB_COM_vect _VECTOR(12)
+
+/* Watchdog Time-out Interrupt */
+#define WDT_vect _VECTOR(13)
+
+/* Timer/Counter2 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(14)
+
+/* Timer/Counter2 Compare Match B */
+#define TIMER1_COMPA_vect _VECTOR(15)
+
+/* Timer/Counter2 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(16)
+
+/* Timer/Counter2 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(17)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(18)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(19)
+
+/* Timer/Counter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(20)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(21)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(22)
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(23)
+
+/* USART1 Data register Empty */
+#define USART1_UDRE_vect _VECTOR(24)
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(25)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(26)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(27)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(28)
+
+#define _VECTORS_SIZE 116
+
+#endif /* _AVR_IOUSBXX2_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iousbxx6_7.h b/cpukit/score/cpu/avr/avr/iousbxx6_7.h
new file mode 100644
index 0000000000..b67dfba053
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iousbxx6_7.h
@@ -0,0 +1,1285 @@
+/* Copyright (c) 2006, Anatoly Sokolov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* iousbxx6_7.h - definitions for AT90USB646, AT90USB647, AT90USB1286
+ and AT90USB1287 */
+
+#ifndef _AVR_IOUSBXX6_7_H_
+#define _AVR_IOUSBXX6_7_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iousbxx6_7.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
+# define __AT90USBxx6__ 1
+#elif defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)
+# define __AT90USBxx7__ 1
+#endif
+
+/* Registers and associated bit numbers */
+
+#define PINA _SFR_IO8(0X00)
+#define PINA7 7
+#define PINA6 6
+#define PINA5 5
+#define PINA4 4
+#define PINA3 3
+#define PINA2 2
+#define PINA1 1
+#define PINA0 0
+
+#define DDRA _SFR_IO8(0X01)
+#define DDA7 7
+#define DDA6 6
+#define DDA5 5
+#define DDA4 4
+#define DDA3 3
+#define DDA2 2
+#define DDA1 1
+#define DDA0 0
+
+#define PORTA _SFR_IO8(0X02)
+#define PA7 7
+#define PA6 6
+#define PA5 5
+#define PA4 4
+#define PA3 3
+#define PA2 2
+#define PA1 1
+#define PA0 0
+
+#define PINB _SFR_IO8(0X03)
+#define PINB7 7
+#define PINB6 6
+#define PINB5 5
+#define PINB4 4
+#define PINB3 3
+#define PINB2 2
+#define PINB1 1
+#define PINB0 0
+
+#define DDRB _SFR_IO8(0x04)
+#define DDB7 7
+#define DDB6 6
+#define DDB5 5
+#define DDB4 4
+#define DDB3 3
+#define DDB2 2
+#define DDB1 1
+#define DDB0 0
+
+#define PORTB _SFR_IO8(0x05)
+#define PB7 7
+#define PB6 6
+#define PB5 5
+#define PB4 4
+#define PB3 3
+#define PB2 2
+#define PB1 1
+#define PB0 0
+
+#define PINC _SFR_IO8(0x06)
+#define PINC7 7
+#define PINC6 6
+#define PINC5 5
+#define PINC4 4
+#define PINC3 3
+#define PINC2 2
+#define PINC1 1
+#define PINC0 0
+
+#define DDRC _SFR_IO8(0x07)
+#define DDC7 7
+#define DDC6 6
+#define DDC5 5
+#define DDC4 4
+#define DDC3 3
+#define DDC2 2
+#define DDC1 1
+#define DDC0 0
+
+#define PORTC _SFR_IO8(0x08)
+#define PC7 7
+#define PC6 6
+#define PC5 5
+#define PC4 4
+#define PC3 3
+#define PC2 2
+#define PC1 1
+#define PC0 0
+
+#define PIND _SFR_IO8(0x09)
+#define PIND7 7
+#define PIND6 6
+#define PIND5 5
+#define PIND4 4
+#define PIND3 3
+#define PIND2 2
+#define PIND1 1
+#define PIND0 0
+
+#define DDRD _SFR_IO8(0x0A)
+#define DDD7 7
+#define DDD6 6
+#define DDD5 5
+#define DDD4 4
+#define DDD3 3
+#define DDD2 2
+#define DDD1 1
+#define DDD0 0
+
+#define PORTD _SFR_IO8(0x0B)
+#define PD7 7
+#define PD6 6
+#define PD5 5
+#define PD4 4
+#define PD3 3
+#define PD2 2
+#define PD1 1
+#define PD0 0
+
+#define PINE _SFR_IO8(0x0C)
+#define PINE7 7
+#define PINE6 6
+#define PINE5 5
+#define PINE4 4
+#define PINE3 3
+#define PINE2 2
+#define PINE1 1
+#define PINE0 0
+
+#define DDRE _SFR_IO8(0x0D)
+#define DDE7 7
+#define DDE6 6
+#define DDE5 5
+#define DDE4 4
+#define DDE3 3
+#define DDE2 2
+#define DDE1 1
+#define DDE0 0
+
+#define PORTE _SFR_IO8(0x0E)
+#define PE7 7
+#define PE6 6
+#define PE5 5
+#define PE4 4
+#define PE3 3
+#define PE2 2
+#define PE1 1
+#define PE0 0
+
+#define PINF _SFR_IO8(0x0F)
+#define PINF7 7
+#define PINF6 6
+#define PINF5 5
+#define PINF4 4
+#define PINF3 3
+#define PINF2 2
+#define PINF1 1
+#define PINF0 0
+
+#define DDRF _SFR_IO8(0x10)
+#define DDF7 7
+#define DDF6 6
+#define DDF5 5
+#define DDF4 4
+#define DDF3 3
+#define DDF2 2
+#define DDF1 1
+#define DDF0 0
+
+#define PORTF _SFR_IO8(0x11)
+#define PF7 7
+#define PF6 6
+#define PF5 5
+#define PF4 4
+#define PF3 3
+#define PF2 2
+#define PF1 1
+#define PF0 0
+
+/* Reserved [0x12..0x14] */
+
+#define TIFR0 _SFR_IO8(0x15)
+#define OCF0B 2
+#define OCF0A 1
+#define TOV0 0
+
+#define TIFR1 _SFR_IO8(0x16)
+#define ICF1 5
+#define OCF1C 3
+#define OCF1B 2
+#define OCF1A 1
+#define TOV1 0
+
+#define TIFR2 _SFR_IO8(0x17)
+#define OCF2B 2
+#define OCF2A 1
+#define TOV2 0
+
+#define TIFR3 _SFR_IO8(0x18)
+#define ICF3 5
+#define OCF3C 3
+#define OCF3B 2
+#define OCF3A 1
+#define TOV3 0
+
+/* Reserved [0x19..0x1A] */
+
+#define PCIFR _SFR_IO8(0x1B)
+#define PCIF0 0
+
+#define EIFR _SFR_IO8(0x1C)
+#define INTF7 7
+#define INTF6 6
+#define INTF5 5
+#define INTF4 4
+#define INTF3 3
+#define INTF2 2
+#define INTF1 1
+#define INTF0 0
+
+#define EIMSK _SFR_IO8(0x1D)
+#define INT7 7
+#define INT6 6
+#define INT5 5
+#define INT4 4
+#define INT3 3
+#define INT2 2
+#define INT1 1
+#define INT0 0
+
+#define GPIOR0 _SFR_IO8(0x1E)
+
+#define EECR _SFR_IO8(0x1F)
+#define EEPM1 5
+#define EEPM0 4
+#define EERIE 3
+#define EEMPE 2
+#define EEPE 1
+#define EERE 0
+
+#define EEDR _SFR_IO8(0x20)
+
+#define EEAR _SFR_IO16(0x21)
+#define EEARL _SFR_IO8(0x21)
+#define EEARH _SFR_IO8(0x22)
+
+/* 6-char sequence denoting where to find the EEPROM registers in memory space.
+ Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM
+ subroutines.
+ First two letters: EECR address.
+ Second two letters: EEDR address.
+ Last two letters: EEAR address. */
+#define __EEPROM_REG_LOCATIONS__ 1F2021
+
+#define GTCCR _SFR_IO8(0x23)
+#define TSM 7
+#define PSRASY 1
+#define PSRSYNC 0
+
+#define TCCR0A _SFR_IO8(0x24)
+#define COM0A1 7
+#define COM0A0 6
+#define COM0B1 5
+#define COM0B0 4
+#define WGM01 1
+#define WGM00 0
+
+#define TCCR0B _SFR_IO8(0x25)
+#define FOC0A 7
+#define FOC0B 6
+#define WGM02 3
+#define CS02 2
+#define CS01 1
+#define CS00 0
+
+#define TCNT0 _SFR_IO8(0X26)
+
+#define OCR0A _SFR_IO8(0x27)
+
+#define OCR0B _SFR_IO8(0X28)
+
+#define PLLCSR _SFR_IO8(0x29)
+#define PLLP2 4
+#define PLLP1 3
+#define PLLP0 2
+#define PLLE 1
+#define PLOCK 0
+
+#define GPIOR1 _SFR_IO8(0x2A)
+
+#define GPIOR2 _SFR_IO8(0x2B)
+
+#define SPCR _SFR_IO8(0x2C)
+#define SPIE 7
+#define SPE 6
+#define DORD 5
+#define MSTR 4
+#define CPOL 3
+#define CPHA 2
+#define SPR1 1
+#define SPR0 0
+
+#define SPSR _SFR_IO8(0x2D)
+#define SPIF 7
+#define WCOL 6
+#define SPI2X 0
+
+#define SPDR _SFR_IO8(0x2E)
+
+/* Reserved [0x2F] */
+
+#define ACSR _SFR_IO8(0x30)
+#define ACD 7
+#define ACBG 6
+#define ACO 5
+#define ACI 4
+#define ACIE 3
+#define ACIC 2
+#define ACIS1 1
+#define ACIS0 0
+
+#define MONDR _SFR_IO8(0x31)
+#define OCDR _SFR_IO8(0x31)
+#define IDRD 7
+#define OCDR7 7
+#define OCDR6 6
+#define OCDR5 5
+#define OCDR4 4
+#define OCDR3 3
+#define OCDR2 2
+#define OCDR1 1
+#define OCDR0 0
+
+/* Reserved [0x32] */
+
+#define SMCR _SFR_IO8(0x33)
+#define SM2 3
+#define SM1 2
+#define SM0 1
+#define SE 0
+
+#define MCUSR _SFR_IO8(0x34)
+#define JTRF 4
+#define WDRF 3
+#define BORF 2
+#define EXTRF 1
+#define PORF 0
+
+#define MCUCR _SFR_IO8(0x35)
+#define JTD 7
+#define PUD 4
+#define IVSEL 1
+#define IVCE 0
+
+/* Reserved [0x36] */
+
+#define SPMCSR _SFR_IO8(0x37)
+#define SPMIE 7
+#define RWWSB 6
+#define SIGRD 5
+#define RWWSRE 4
+#define BLBSET 3
+#define PGWRT 2
+#define PGERS 1
+#define SPMEN 0
+
+/* Reserved [0x38..0x3A] */
+
+#if defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+#define RAMPZ _SFR_IO8(0x3B)
+#endif
+
+/* Reserved [0x3C] */
+
+/* SP [0x3D..0x3E] */
+/* SREG [0x3F] */
+
+#define WDTCSR _SFR_MEM8(0x60)
+#define WDIF 7
+#define WDIE 6
+#define WDP3 5
+#define WDCE 4
+#define WDE 3
+#define WDP2 2
+#define WDP1 1
+#define WDP0 0
+
+#define CLKPR _SFR_MEM8(0x61)
+#define CLKPCE 7
+#define CLKPS3 3
+#define CLKPS2 2
+#define CLKPS1 1
+#define CLKPS0 0
+
+/* Reserved [0x62..0x63] */
+
+#define PRR0 _SFR_MEM8(0x64)
+#define PRTWI 7
+#define PRTIM2 6
+#define PRTIM0 5
+#define PRTIM1 3
+#define PRSPI 2
+#define PRADC 0
+
+#define PRR1 _SFR_MEM8(0x65)
+#define PRUSB 7
+#define PRTIM3 3
+#define PRUSART1 0
+
+#define OSCCAL _SFR_MEM8(0x66)
+
+/* Reserved [0x67] */
+
+#define PCICR _SFR_MEM8(0x68)
+#define PCIE0 0
+
+#define EICRA _SFR_MEM8(0x69)
+#define ISC31 7
+#define ISC30 6
+#define ISC21 5
+#define ISC20 4
+#define ISC11 3
+#define ISC10 2
+#define ISC01 1
+#define ISC00 0
+
+#define EICRB _SFR_MEM8(0x6A)
+#define ISC71 7
+#define ISC70 6
+#define ISC61 5
+#define ISC60 4
+#define ISC51 3
+#define ISC50 2
+#define ISC41 1
+#define ISC40 0
+
+#define PCMSK0 _SFR_MEM8(0x6B)
+#define PCINT7 7
+#define PCINT6 6
+#define PCINT5 5
+#define PCINT4 4
+#define PCINT3 3
+#define PCINT2 2
+#define PCINT1 1
+#define PCINT0 0
+
+/* Reserved [0x6C..0x6D] */
+
+#define TIMSK0 _SFR_MEM8(0x6E)
+#define OCIE0B 2
+#define OCIE0A 1
+#define TOIE0 0
+
+#define TIMSK1 _SFR_MEM8(0x6F)
+#define ICIE1 5
+#define OCIE1C 3
+#define OCIE1B 2
+#define OCIE1A 1
+#define TOIE1 0
+
+#define TIMSK2 _SFR_MEM8(0x70)
+#define OCIE2B 2
+#define OCIE2A 1
+#define TOIE2 0
+
+#define TIMSK3 _SFR_MEM8(0x71)
+#define ICIE3 5
+#define OCIE3C 3
+#define OCIE3B 2
+#define OCIE3A 1
+#define TOIE3 0
+
+/* Reserved [0x72..0x73] */
+
+#define XMCRA _SFR_MEM8(0x74)
+#define SRE 7
+#define SRL2 6
+#define SRL1 5
+#define SRL0 4
+#define SRW11 3
+#define SRW10 2
+#define SRW01 1
+#define SRW00 0
+
+#define XMCRB _SFR_MEM8(0x75)
+#define XMBK 7
+#define XMM2 2
+#define XMM1 1
+#define XMM0 0
+
+/* Reserved [0x76..0x77] */
+
+/* RegDef: ADC Data Register */
+#ifndef __ASSEMBLER__
+#define ADC _SFR_MEM16(0x78)
+#endif
+#define ADCW _SFR_MEM16(0x78)
+#define ADCL _SFR_MEM8(0x78)
+#define ADCH _SFR_MEM8(0x79)
+
+#define ADCSRA _SFR_MEM8(0x7A)
+#define ADEN 7
+#define ADSC 6
+#define ADATE 5
+#define ADIF 4
+#define ADIE 3
+#define ADPS2 2
+#define ADPS1 1
+#define ADPS0 0
+
+#define ADCSRB _SFR_MEM8(0x7B)
+#define ACME 6
+#define ADTS2 2
+#define ADTS1 1
+#define ADTS0 0
+
+#define ADMUX _SFR_MEM8(0x7C)
+#define REFS1 7
+#define REFS0 6
+#define ADLAR 5
+#define MUX4 4
+#define MUX3 3
+#define MUX2 2
+#define MUX1 1
+#define MUX0 0
+
+/* Reserved [0x7D] */
+
+#define DIDR0 _SFR_MEM8(0x7E)
+#define ADC7D 7
+#define ADC6D 6
+#define ADC5D 5
+#define ADC4D 4
+#define ADC3D 3
+#define ADC2D 2
+#define ADC1D 1
+#define ADC0D 0
+
+#define DIDR1 _SFR_MEM8(0x7F)
+#define AIN1D 1
+#define AIN0D 0
+
+#define TCCR1A _SFR_MEM8(0x80)
+#define COM1A1 7
+#define COM1A0 6
+#define COM1B1 5
+#define COM1B0 4
+#define COM1C1 3
+#define COM1C0 2
+#define WGM11 1
+#define WGM10 0
+
+#define TCCR1B _SFR_MEM8(0x81)
+#define ICNC1 7
+#define ICES1 6
+#define WGM13 4
+#define WGM12 3
+#define CS12 2
+#define CS11 1
+#define CS10 0
+
+#define TCCR1C _SFR_MEM8(0x82)
+#define FOC1A 7
+#define FOC1B 6
+#define FOC1C 5
+
+/* Reserved [0x83] */
+
+/* Combine TCNT1L and TCNT1H */
+#define TCNT1 _SFR_MEM16(0x84)
+
+#define TCNT1L _SFR_MEM8(0x84)
+#define TCNT1H _SFR_MEM8(0x85)
+
+/* Combine ICR1L and ICR1H */
+#define ICR1 _SFR_MEM16(0x86)
+
+#define ICR1L _SFR_MEM8(0x86)
+#define ICR1H _SFR_MEM8(0x87)
+
+/* Combine OCR1AL and OCR1AH */
+#define OCR1A _SFR_MEM16(0x88)
+
+#define OCR1AL _SFR_MEM8(0x88)
+#define OCR1AH _SFR_MEM8(0x89)
+
+/* Combine OCR1BL and OCR1BH */
+#define OCR1B _SFR_MEM16(0x8A)
+
+#define OCR1BL _SFR_MEM8(0x8A)
+#define OCR1BH _SFR_MEM8(0x8B)
+
+/* Combine OCR1CL and OCR1CH */
+#define OCR1C _SFR_MEM16(0x8C)
+
+#define OCR1CL _SFR_MEM8(0x8C)
+#define OCR1CH _SFR_MEM8(0x8D)
+
+/* Reserved [0x8E..0x8F] */
+
+#define TCCR3A _SFR_MEM8(0x90)
+#define COM3A1 7
+#define COM3A0 6
+#define COM3B1 5
+#define COM3B0 4
+#define COM3C1 3
+#define COM3C0 2
+#define WGM31 1
+#define WGM30 0
+
+#define TCCR3B _SFR_MEM8(0x91)
+#define ICNC3 7
+#define ICES3 6
+#define WGM33 4
+#define WGM32 3
+#define CS32 2
+#define CS31 1
+#define CS30 0
+
+#define TCCR3C _SFR_MEM8(0x92)
+#define FOC3A 7
+#define FOC3B 6
+#define FOC3C 5
+
+/* Reserved [0x93] */
+
+/* Combine TCNT3L and TCNT3H */
+#define TCNT3 _SFR_MEM16(0x94)
+
+#define TCNT3L _SFR_MEM8(0x94)
+#define TCNT3H _SFR_MEM8(0x95)
+
+/* Combine ICR3L and ICR3H */
+#define ICR3 _SFR_MEM16(0x96)
+
+#define ICR3L _SFR_MEM8(0x96)
+#define ICR3H _SFR_MEM8(0x97)
+
+/* Combine OCR3AL and OCR3AH */
+#define OCR3A _SFR_MEM16(0x98)
+
+#define OCR3AL _SFR_MEM8(0x98)
+#define OCR3AH _SFR_MEM8(0x99)
+
+/* Combine OCR3BL and OCR3BH */
+#define OCR3B _SFR_MEM16(0x9A)
+
+#define OCR3BL _SFR_MEM8(0x9A)
+#define OCR3BH _SFR_MEM8(0x9B)
+
+/* Combine OCR3CL and OCR3CH */
+#define OCR3C _SFR_MEM16(0x9C)
+
+#define OCR3CL _SFR_MEM8(0x9C)
+#define OCR3CH _SFR_MEM8(0x9D)
+
+#if defined(__AT90USBxx7__)
+
+#define UHCON _SFR_MEM8(0x9E)
+#define RESUME 2
+#define RESET 1
+#define SOFEN 0
+
+#define UHINT _SFR_MEM8(0x9F)
+#define HWUPI 6
+#define HSOFI 5
+#define RXRSMI 4
+#define RSMEDI 3
+#define RSTI 2
+#define DDISCI 1
+#define DCONNI 0
+
+#define UHIEN _SFR_MEM8(0xA0)
+#define HWUPE 6
+#define HSOFE 5
+#define RXRSME 4
+#define RSMEDE 3
+#define RSTE 2
+#define DDISCE 1
+#define DCONNE 0
+
+#define UHADDR _SFR_MEM8(0xA1)
+
+/* Combine UHFNUML and UHFNUMH */
+#define UHFNUM _SFR_MEM16(0xA2)
+
+#define UHFNUML _SFR_MEM8(0xA2)
+#define UHFNUMH _SFR_MEM8(0xA3)
+
+#define UHFLEN _SFR_MEM8(0xA4)
+
+#define UPINRQX _SFR_MEM8(0xA5)
+
+#define UPINTX _SFR_MEM8(0xA6)
+#define FIFOCON 7
+#define NAKEDI 6
+#define RWAL 5
+#define PERRI 4
+#define TXSTPI 3
+#define TXOUTI 2
+#define RXSTALLI 1
+#define RXINI 0
+
+#define UPNUM _SFR_MEM8(0xA7)
+
+#define UPRST _SFR_MEM8(0xA8)
+#define PRST6 6
+#define PRST5 5
+#define PRST4 4
+#define PRST3 3
+#define PRST2 2
+#define PRST1 1
+#define PRST0 0
+
+#define UPCONX _SFR_MEM8(0xA9)
+#define PFREEZE 6
+#define INMODE 5
+/* #define AUTOSW 4 */ /* Reserved */
+#define RSTDT 3
+#define PEN 0
+
+#define UPCFG0X _SFR_MEM8(0XAA)
+#define PTYPE1 7
+#define PTYPE0 6
+#define PTOKEN1 5
+#define PTOKEN0 4
+#define PEPNUM3 3
+#define PEPNUM2 2
+#define PEPNUM1 1
+#define PEPNUM0 0
+
+#define UPCFG1X _SFR_MEM8(0XAB)
+#define PSIZE2 6
+#define PSIZE1 5
+#define PSIZE0 4
+#define PBK1 3
+#define PBK0 2
+#define ALLOC 1
+
+#define UPSTAX _SFR_MEM8(0XAC)
+#define CFGOK 7
+#define OVERFI 6
+#define UNDERFI 5
+#define DTSEQ1 3
+#define DTSEQ0 2
+#define NBUSYBK1 1
+#define NBUSYBK0 0
+
+#define UPCFG2X _SFR_MEM8(0XAD)
+
+#define UPIENX _SFR_MEM8(0XAE)
+#define FLERRE 7
+#define NAKEDE 6
+#define PERRE 4
+#define TXSTPE 3
+#define TXOUTE 2
+#define RXSTALLE 1
+#define RXINE 0
+
+#define UPDATX _SFR_MEM8(0XAF)
+
+#endif /* __AT90USBxx7__ */
+
+#define TCCR2A _SFR_MEM8(0xB0)
+#define COM2A1 7
+#define COM2A0 6
+#define COM2B1 5
+#define COM2B0 4
+#define WGM21 1
+#define WGM20 0
+
+#define TCCR2B _SFR_MEM8(0xB1)
+#define FOC2A 7
+#define FOC2B 6
+#define WGM22 3
+#define CS22 2
+#define CS21 1
+#define CS20 0
+
+#define TCNT2 _SFR_MEM8(0xB2)
+
+#define OCR2A _SFR_MEM8(0xB3)
+
+#define OCR2B _SFR_MEM8(0xB4)
+
+/* Reserved [0xB5] */
+
+#define ASSR _SFR_MEM8(0xB6)
+#define EXCLK 6
+#define AS2 5
+#define TCN2UB 4
+#define OCR2AUB 3
+#define OCR2BUB 2
+#define TCR2AUB 1
+#define TCR2BUB 0
+
+/* Reserved [0xB7] */
+
+#define TWBR _SFR_MEM8(0xB8)
+
+#define TWSR _SFR_MEM8(0xB9)
+#define TWS7 7
+#define TWS6 6
+#define TWS5 5
+#define TWS4 4
+#define TWS3 3
+#define TWPS1 1
+#define TWPS0 0
+
+#define TWAR _SFR_MEM8(0xBA)
+#define TWA6 7
+#define TWA5 6
+#define TWA4 5
+#define TWA3 4
+#define TWA2 3
+#define TWA1 2
+#define TWA0 1
+#define TWGCE 0
+
+#define TWDR _SFR_MEM8(0xBB)
+
+#define TWCR _SFR_MEM8(0xBC)
+#define TWINT 7
+#define TWEA 6
+#define TWSTA 5
+#define TWSTO 4
+#define TWWC 3
+#define TWEN 2
+#define TWIE 0
+
+#define TWAMR _SFR_MEM8(0xBD)
+#define TWAM6 7
+#define TWAM5 6
+#define TWAM4 5
+#define TWAM3 4
+#define TWAM2 3
+#define TWAM1 2
+#define TWAM0 1
+
+/* Reserved [0xBE..0xC7] */
+
+#define UCSR1A _SFR_MEM8(0xC8)
+#define RXC1 7
+#define TXC1 6
+#define UDRE1 5
+#define FE1 4
+#define DOR1 3
+#define UPE1 2
+#define U2X1 1
+#define MPCM1 0
+
+#define UCSR1B _SFR_MEM8(0XC9)
+#define RXCIE1 7
+#define TXCIE1 6
+#define UDRIE1 5
+#define RXEN1 4
+#define TXEN1 3
+#define UCSZ12 2
+#define RXB81 1
+#define TXB81 0
+
+#define UCSR1C _SFR_MEM8(0xCA)
+#define UMSEL11 7
+#define UMSEL10 6
+#define UPM11 5
+#define UPM10 4
+#define USBS1 3
+#define UCSZ11 2
+#define UCSZ10 1
+#define UCPOL1 0
+
+/* Reserved [0xCB] */
+
+/* Combine UBRR1L and UBRR1H */
+#define UBRR1 _SFR_MEM16(0xCC)
+
+#define UBRR1L _SFR_MEM8(0xCC)
+#define UBRR1H _SFR_MEM8(0xCD)
+
+#define UDR1 _SFR_MEM8(0XCE)
+
+/* Reserved [0xCF..0xD6] */
+
+#define UHWCON _SFR_MEM8(0XD7)
+#define UIMOD 7
+#define UIDE 6
+#define UVCONE 4
+#define UVREGE 0
+
+#define USBCON _SFR_MEM8(0XD8)
+#define USBE 7
+#define HOST 6
+#define FRZCLK 5
+#define OTGPADE 4
+#define IDTE 1
+#define VBUSTE 0
+
+#define USBSTA _SFR_MEM8(0XD9)
+#define SPEED 3
+#define ID 1
+#define VBUS 0
+
+#define USBINT _SFR_MEM8(0XDA)
+#define IDTI 1
+#define VBUSTI 0
+
+/* Combine UDPADDL and UDPADDH */
+#define UDPADD _SFR_MEM16(0xDB)
+
+#define UDPADDL _SFR_MEM8(0xDB)
+#define UDPADDH _SFR_MEM8(0xDC)
+#define DPACC 7
+
+#if defined(__AT90USBxx7__)
+
+#define OTGCON _SFR_MEM8(0XDD)
+#define HNPREQ 5
+#define SRPREQ 4
+#define SRPSEL 3
+#define VBUSHWC 2
+#define VBUSREQ 1
+#define VBUSRQC 0
+
+#define OTGIEN _SFR_MEM8(0XDE)
+#define STOE 5
+#define HNPERRE 4
+#define ROLEEXE 3
+#define BCERRE 2
+#define VBERRE 1
+#define SRPE 0
+
+#define OTGINT _SFR_MEM8(0XDF)
+#define STOI 5
+#define HNPERRI 4
+#define ROLEEXI 3
+#define BCERRI 2
+#define VBERRI 1
+#define SRPI 0
+
+#endif /* __AT90USBxx7__ */
+
+#define UDCON _SFR_MEM8(0XE0)
+#define LSM 2
+#define RMWKUP 1
+#define DETACH 0
+
+#define UDINT _SFR_MEM8(0XE1)
+#define UPRSMI 6
+#define EORSMI 5
+#define WAKEUPI 4
+#define EORSTI 3
+#define SOFI 2
+/* #define MSOFI 1 */ /* Reserved */
+#define SUSPI 0
+
+#define UDIEN _SFR_MEM8(0XE2)
+#define UPRSME 6
+#define EORSME 5
+#define WAKEUPE 4
+#define EORSTE 3
+#define SOFE 2
+/* #define MSOFE 1 */ /* Reserved */
+#define SUSPE 0
+
+#define UDADDR _SFR_MEM8(0XE3)
+#define ADDEN 7
+
+/* Combine UDFNUML and UDFNUMH */
+#define UDFNUM _SFR_MEM16(0xE4)
+
+#define UDFNUML _SFR_MEM8(0xE4)
+#define UDFNUMH _SFR_MEM8(0xE5)
+
+#define UDMFN _SFR_MEM8(0XE6)
+#define FNCERR 4
+
+#define UDTST _SFR_MEM8(0XE7)
+#define OPMODE2 5
+#define TSTPCKT 4
+#define TSTK 3
+#define TSTJ 2
+
+#define UEINTX _SFR_MEM8(0XE8)
+#define FIFOCON 7
+#define NAKINI 6
+#define RWAL 5
+#define NAKOUTI 4
+#define RXSTPI 3
+#define RXOUTI 2
+#define STALLEDI 1
+#define TXINI 0
+
+#define UENUM _SFR_MEM8(0XE9)
+
+#define UERST _SFR_MEM8(0XEA)
+#define EPRST6 6
+#define EPRST5 5
+#define EPRST4 4
+#define EPRST3 3
+#define EPRST2 2
+#define EPRST1 1
+#define EPRST0 0
+
+#define UECONX _SFR_MEM8(0XEB)
+#define STALLRQ 5
+#define STALLRQC 4
+#define RSTDT 3
+#define EPEN 0
+
+#define UECFG0X _SFR_MEM8(0XEC)
+#define EPTYPE1 7
+#define EPTYPE0 6
+/* #define ISOSW 3 */ /* Reserved */
+/* #define AUTOSW 2 */ /* Reserved */
+/* #define NYETSDIS 1 */ /* Reserved */
+#define EPDIR 0
+
+#define UECFG1X _SFR_MEM8(0XED)
+#define EPSIZE2 6
+#define EPSIZE1 5
+#define EPSIZE0 4
+#define EPBK1 3
+#define EPBK0 2
+#define ALLOC 1
+
+#define UESTA0X _SFR_MEM8(0XEE)
+#define CFGOK 7
+#define OVERFI 6
+#define UNDERFI 5
+#define ZLPSEEN 4
+#define DTSEQ1 3
+#define DTSEQ0 2
+#define NBUSYBK1 1
+#define NBUSYBK0 0
+
+#define UESTA1X _SFR_MEM8(0XEF)
+#define CTRLDIR 2
+#define CURRBK1 1
+#define CURRBK0 0
+
+#define UEIENX _SFR_MEM8(0XF0)
+#define FLERRE 7
+#define NAKINE 6
+#define NAKOUTE 4
+#define RXSTPE 3
+#define RXOUTE 2
+#define STALLEDE 1
+#define TXINE 0
+
+#define UEDATX _SFR_MEM8(0XF1)
+
+/* Combine UEBCLX and UEBCHX */
+#define UEBCX _SFR_MEM16(0xF2)
+
+#define UEBCLX _SFR_MEM8(0xF2)
+#define UEBCHX _SFR_MEM8(0xF3)
+
+#define UEINT _SFR_MEM8(0XF4)
+#define EPINT6 6
+#define EPINT5 5
+#define EPINT4 4
+#define EPINT3 3
+#define EPINT2 2
+#define EPINT1 1
+#define EPINT0 0
+
+#if defined(__AT90USBxx7__)
+
+#define UPERRX _SFR_MEM8(0XF5)
+#define COUNTER1 6
+#define COUNTER0 5
+#define CRC16 4
+#define TIMEOUT 3
+#define PID 2
+#define DATAPID 1
+#define DATATGL 0
+
+/* Combine UPBCLX and UPBCHX */
+#define UPBCX _SFR_MEM16(0xF6)
+
+#define UPBCLX _SFR_MEM8(0xF6)
+#define UPBCHX _SFR_MEM8(0xF7)
+
+#define UPINT _SFR_MEM8(0XF8)
+#define PINT6 6
+#define PINT5 5
+#define PINT4 4
+#define PINT3 3
+#define PINT2 2
+#define PINT1 1
+#define PINT0 0
+
+#define OTGTCON _SFR_MEM8(0XF9)
+#define PAGE1 6
+#define PAGE0 5
+#define VALUE1 1
+#define VALUE0 0
+
+#endif /* __AT90USBxx7__ */
+
+/* Reserved [0xFA..0xFF] */
+
+/* Interrupt vectors */
+
+/* External Interrupt Request 0 */
+#define INT0_vect _VECTOR(1)
+
+/* External Interrupt Request 1 */
+#define INT1_vect _VECTOR(2)
+
+/* External Interrupt Request 2 */
+#define INT2_vect _VECTOR(3)
+
+/* External Interrupt Request 3 */
+#define INT3_vect _VECTOR(4)
+
+/* External Interrupt Request 4 */
+#define INT4_vect _VECTOR(5)
+
+/* External Interrupt Request 5 */
+#define INT5_vect _VECTOR(6)
+
+/* External Interrupt Request 6 */
+#define INT6_vect _VECTOR(7)
+
+/* External Interrupt Request 7 */
+#define INT7_vect _VECTOR(8)
+
+/* Pin Change Interrupt Request 0 */
+#define PCINT0_vect _VECTOR(9)
+
+/* USB General Interrupt Request */
+#define USB_GEN_vect _VECTOR(10)
+
+/* USB Endpoint/Pipe Interrupt Communication Request */
+#define USB_COM_vect _VECTOR(11)
+
+/* Watchdog Time-out Interrupt */
+#define WDT_vect _VECTOR(12)
+
+/* Timer/Counter2 Compare Match A */
+#define TIMER2_COMPA_vect _VECTOR(13)
+
+/* Timer/Counter2 Compare Match B */
+#define TIMER2_COMPB_vect _VECTOR(14)
+
+/* Timer/Counter2 Overflow */
+#define TIMER2_OVF_vect _VECTOR(15)
+
+/* Timer/Counter1 Capture Event */
+#define TIMER1_CAPT_vect _VECTOR(16)
+
+/* Timer/Counter1 Compare Match A */
+#define TIMER1_COMPA_vect _VECTOR(17)
+
+/* Timer/Counter1 Compare Match B */
+#define TIMER1_COMPB_vect _VECTOR(18)
+
+/* Timer/Counter1 Compare Match C */
+#define TIMER1_COMPC_vect _VECTOR(19)
+
+/* Timer/Counter1 Overflow */
+#define TIMER1_OVF_vect _VECTOR(20)
+
+/* Timer/Counter0 Compare Match A */
+#define TIMER0_COMPA_vect _VECTOR(21)
+
+/* Timer/Counter0 Compare Match B */
+#define TIMER0_COMPB_vect _VECTOR(22)
+
+/* Timer/Counter0 Overflow */
+#define TIMER0_OVF_vect _VECTOR(23)
+
+/* SPI Serial Transfer Complete */
+#define SPI_STC_vect _VECTOR(24)
+
+/* USART1, Rx Complete */
+#define USART1_RX_vect _VECTOR(25)
+
+/* USART1 Data register Empty */
+#define USART1_UDRE_vect _VECTOR(26)
+
+/* USART1, Tx Complete */
+#define USART1_TX_vect _VECTOR(27)
+
+/* Analog Comparator */
+#define ANALOG_COMP_vect _VECTOR(28)
+
+/* ADC Conversion Complete */
+#define ADC_vect _VECTOR(29)
+
+/* EEPROM Ready */
+#define EE_READY_vect _VECTOR(30)
+
+/* Timer/Counter3 Capture Event */
+#define TIMER3_CAPT_vect _VECTOR(31)
+
+/* Timer/Counter3 Compare Match A */
+#define TIMER3_COMPA_vect _VECTOR(32)
+
+/* Timer/Counter3 Compare Match B */
+#define TIMER3_COMPB_vect _VECTOR(33)
+
+/* Timer/Counter3 Compare Match C */
+#define TIMER3_COMPC_vect _VECTOR(34)
+
+/* Timer/Counter3 Overflow */
+#define TIMER3_OVF_vect _VECTOR(35)
+
+/* 2-wire Serial Interface */
+#define TWI_vect _VECTOR(36)
+
+/* Store Program Memory Read */
+#define SPM_READY_vect _VECTOR(37)
+
+#define _VECTORS_SIZE 152
+
+#if defined(__AT90USBxx6__)
+# undef __AT90USBxx6__
+#endif /* __AT90USBxx6__ */
+
+#if defined(__AT90USBxx7__)
+# undef __AT90USBxx7__
+#endif /* __AT90USBxx7__ */
+
+#endif /* _AVR_IOUSBXX6_7_H_ */
diff --git a/cpukit/score/cpu/avr/avr/iox128a1.h b/cpukit/score/cpu/avr/avr/iox128a1.h
new file mode 100644
index 0000000000..edf597db6c
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox128a1.h
@@ -0,0 +1,7140 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox128a1.h - definitions for ATxmega128A1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox128a1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega128A1_H_
+#define _AVR_ATxmega128A1_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<2), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<2), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<2), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACA (*(DAC_t *) 0x0300) /* Digital to Analog Converter A */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define EBI (*(EBI_t *) 0x0440) /* External Bus Interface */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWID (*(TWI_t *) 0x0490) /* Two-Wire Interface D */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define TWIF (*(TWI_t *) 0x04B0) /* Two-Wire Interface F */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTH (*(PORT_t *) 0x06E0) /* Port H */
+#define PORTJ (*(PORT_t *) 0x0700) /* Port J */
+#define PORTK (*(PORT_t *) 0x0720) /* Port K */
+#define PORTQ (*(PORT_t *) 0x07C0) /* Port Q */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE1 (*(USART_t *) 0x0AB0) /* Universal Asynchronous Receiver-Transmitter E1 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define TCF1 (*(TC1_t *) 0x0B40) /* Timer/Counter F1 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACA - Digital to Analog Converter A */
+#define DACA_CTRLA _SFR_MEM8(0x0300)
+#define DACA_CTRLB _SFR_MEM8(0x0301)
+#define DACA_CTRLC _SFR_MEM8(0x0302)
+#define DACA_EVCTRL _SFR_MEM8(0x0303)
+#define DACA_TIMCTRL _SFR_MEM8(0x0304)
+#define DACA_STATUS _SFR_MEM8(0x0305)
+#define DACA_GAINCAL _SFR_MEM8(0x0308)
+#define DACA_OFFSETCAL _SFR_MEM8(0x0309)
+#define DACA_CH0DATA _SFR_MEM16(0x0318)
+#define DACA_CH1DATA _SFR_MEM16(0x031A)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* EBI - External Bus Interface */
+#define EBI_CTRL _SFR_MEM8(0x0440)
+#define EBI_SDRAMCTRLA _SFR_MEM8(0x0441)
+#define EBI_REFRESH _SFR_MEM16(0x0444)
+#define EBI_INITDLY _SFR_MEM16(0x0446)
+#define EBI_SDRAMCTRLB _SFR_MEM8(0x0448)
+#define EBI_SDRAMCTRLC _SFR_MEM8(0x0449)
+#define EBI_CS0_CTRLA _SFR_MEM8(0x0450)
+#define EBI_CS0_CTRLB _SFR_MEM8(0x0451)
+#define EBI_CS0_BASEADDR _SFR_MEM16(0x0452)
+#define EBI_CS1_CTRLA _SFR_MEM8(0x0454)
+#define EBI_CS1_CTRLB _SFR_MEM8(0x0455)
+#define EBI_CS1_BASEADDR _SFR_MEM16(0x0456)
+#define EBI_CS2_CTRLA _SFR_MEM8(0x0458)
+#define EBI_CS2_CTRLB _SFR_MEM8(0x0459)
+#define EBI_CS2_BASEADDR _SFR_MEM16(0x045A)
+#define EBI_CS3_CTRLA _SFR_MEM8(0x045C)
+#define EBI_CS3_CTRLB _SFR_MEM8(0x045D)
+#define EBI_CS3_BASEADDR _SFR_MEM16(0x045E)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWID - Two-Wire Interface D */
+#define TWID_CTRL _SFR_MEM8(0x0490)
+#define TWID_MASTER_CTRLA _SFR_MEM8(0x0491)
+#define TWID_MASTER_CTRLB _SFR_MEM8(0x0492)
+#define TWID_MASTER_CTRLC _SFR_MEM8(0x0493)
+#define TWID_MASTER_STATUS _SFR_MEM8(0x0494)
+#define TWID_MASTER_BAUD _SFR_MEM8(0x0495)
+#define TWID_MASTER_ADDR _SFR_MEM8(0x0496)
+#define TWID_MASTER_DATA _SFR_MEM8(0x0497)
+#define TWID_SLAVE_CTRLA _SFR_MEM8(0x0498)
+#define TWID_SLAVE_CTRLB _SFR_MEM8(0x0499)
+#define TWID_SLAVE_STATUS _SFR_MEM8(0x049A)
+#define TWID_SLAVE_ADDR _SFR_MEM8(0x049B)
+#define TWID_SLAVE_DATA _SFR_MEM8(0x049C)
+#define TWID_SLAVE_ADDRMASK _SFR_MEM8(0x049D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* TWIF - Two-Wire Interface F */
+#define TWIF_CTRL _SFR_MEM8(0x04B0)
+#define TWIF_MASTER_CTRLA _SFR_MEM8(0x04B1)
+#define TWIF_MASTER_CTRLB _SFR_MEM8(0x04B2)
+#define TWIF_MASTER_CTRLC _SFR_MEM8(0x04B3)
+#define TWIF_MASTER_STATUS _SFR_MEM8(0x04B4)
+#define TWIF_MASTER_BAUD _SFR_MEM8(0x04B5)
+#define TWIF_MASTER_ADDR _SFR_MEM8(0x04B6)
+#define TWIF_MASTER_DATA _SFR_MEM8(0x04B7)
+#define TWIF_SLAVE_CTRLA _SFR_MEM8(0x04B8)
+#define TWIF_SLAVE_CTRLB _SFR_MEM8(0x04B9)
+#define TWIF_SLAVE_STATUS _SFR_MEM8(0x04BA)
+#define TWIF_SLAVE_ADDR _SFR_MEM8(0x04BB)
+#define TWIF_SLAVE_DATA _SFR_MEM8(0x04BC)
+#define TWIF_SLAVE_ADDRMASK _SFR_MEM8(0x04BD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTH - Port H */
+#define PORTH_DIR _SFR_MEM8(0x06E0)
+#define PORTH_DIRSET _SFR_MEM8(0x06E1)
+#define PORTH_DIRCLR _SFR_MEM8(0x06E2)
+#define PORTH_DIRTGL _SFR_MEM8(0x06E3)
+#define PORTH_OUT _SFR_MEM8(0x06E4)
+#define PORTH_OUTSET _SFR_MEM8(0x06E5)
+#define PORTH_OUTCLR _SFR_MEM8(0x06E6)
+#define PORTH_OUTTGL _SFR_MEM8(0x06E7)
+#define PORTH_IN _SFR_MEM8(0x06E8)
+#define PORTH_INTCTRL _SFR_MEM8(0x06E9)
+#define PORTH_INT0MASK _SFR_MEM8(0x06EA)
+#define PORTH_INT1MASK _SFR_MEM8(0x06EB)
+#define PORTH_INTFLAGS _SFR_MEM8(0x06EC)
+#define PORTH_PIN0CTRL _SFR_MEM8(0x06F0)
+#define PORTH_PIN1CTRL _SFR_MEM8(0x06F1)
+#define PORTH_PIN2CTRL _SFR_MEM8(0x06F2)
+#define PORTH_PIN3CTRL _SFR_MEM8(0x06F3)
+#define PORTH_PIN4CTRL _SFR_MEM8(0x06F4)
+#define PORTH_PIN5CTRL _SFR_MEM8(0x06F5)
+#define PORTH_PIN6CTRL _SFR_MEM8(0x06F6)
+#define PORTH_PIN7CTRL _SFR_MEM8(0x06F7)
+
+/* PORTJ - Port J */
+#define PORTJ_DIR _SFR_MEM8(0x0700)
+#define PORTJ_DIRSET _SFR_MEM8(0x0701)
+#define PORTJ_DIRCLR _SFR_MEM8(0x0702)
+#define PORTJ_DIRTGL _SFR_MEM8(0x0703)
+#define PORTJ_OUT _SFR_MEM8(0x0704)
+#define PORTJ_OUTSET _SFR_MEM8(0x0705)
+#define PORTJ_OUTCLR _SFR_MEM8(0x0706)
+#define PORTJ_OUTTGL _SFR_MEM8(0x0707)
+#define PORTJ_IN _SFR_MEM8(0x0708)
+#define PORTJ_INTCTRL _SFR_MEM8(0x0709)
+#define PORTJ_INT0MASK _SFR_MEM8(0x070A)
+#define PORTJ_INT1MASK _SFR_MEM8(0x070B)
+#define PORTJ_INTFLAGS _SFR_MEM8(0x070C)
+#define PORTJ_PIN0CTRL _SFR_MEM8(0x0710)
+#define PORTJ_PIN1CTRL _SFR_MEM8(0x0711)
+#define PORTJ_PIN2CTRL _SFR_MEM8(0x0712)
+#define PORTJ_PIN3CTRL _SFR_MEM8(0x0713)
+#define PORTJ_PIN4CTRL _SFR_MEM8(0x0714)
+#define PORTJ_PIN5CTRL _SFR_MEM8(0x0715)
+#define PORTJ_PIN6CTRL _SFR_MEM8(0x0716)
+#define PORTJ_PIN7CTRL _SFR_MEM8(0x0717)
+
+/* PORTK - Port K */
+#define PORTK_DIR _SFR_MEM8(0x0720)
+#define PORTK_DIRSET _SFR_MEM8(0x0721)
+#define PORTK_DIRCLR _SFR_MEM8(0x0722)
+#define PORTK_DIRTGL _SFR_MEM8(0x0723)
+#define PORTK_OUT _SFR_MEM8(0x0724)
+#define PORTK_OUTSET _SFR_MEM8(0x0725)
+#define PORTK_OUTCLR _SFR_MEM8(0x0726)
+#define PORTK_OUTTGL _SFR_MEM8(0x0727)
+#define PORTK_IN _SFR_MEM8(0x0728)
+#define PORTK_INTCTRL _SFR_MEM8(0x0729)
+#define PORTK_INT0MASK _SFR_MEM8(0x072A)
+#define PORTK_INT1MASK _SFR_MEM8(0x072B)
+#define PORTK_INTFLAGS _SFR_MEM8(0x072C)
+#define PORTK_PIN0CTRL _SFR_MEM8(0x0730)
+#define PORTK_PIN1CTRL _SFR_MEM8(0x0731)
+#define PORTK_PIN2CTRL _SFR_MEM8(0x0732)
+#define PORTK_PIN3CTRL _SFR_MEM8(0x0733)
+#define PORTK_PIN4CTRL _SFR_MEM8(0x0734)
+#define PORTK_PIN5CTRL _SFR_MEM8(0x0735)
+#define PORTK_PIN6CTRL _SFR_MEM8(0x0736)
+#define PORTK_PIN7CTRL _SFR_MEM8(0x0737)
+
+/* PORTQ - Port Q */
+#define PORTQ_DIR _SFR_MEM8(0x07C0)
+#define PORTQ_DIRSET _SFR_MEM8(0x07C1)
+#define PORTQ_DIRCLR _SFR_MEM8(0x07C2)
+#define PORTQ_DIRTGL _SFR_MEM8(0x07C3)
+#define PORTQ_OUT _SFR_MEM8(0x07C4)
+#define PORTQ_OUTSET _SFR_MEM8(0x07C5)
+#define PORTQ_OUTCLR _SFR_MEM8(0x07C6)
+#define PORTQ_OUTTGL _SFR_MEM8(0x07C7)
+#define PORTQ_IN _SFR_MEM8(0x07C8)
+#define PORTQ_INTCTRL _SFR_MEM8(0x07C9)
+#define PORTQ_INT0MASK _SFR_MEM8(0x07CA)
+#define PORTQ_INT1MASK _SFR_MEM8(0x07CB)
+#define PORTQ_INTFLAGS _SFR_MEM8(0x07CC)
+#define PORTQ_PIN0CTRL _SFR_MEM8(0x07D0)
+#define PORTQ_PIN1CTRL _SFR_MEM8(0x07D1)
+#define PORTQ_PIN2CTRL _SFR_MEM8(0x07D2)
+#define PORTQ_PIN3CTRL _SFR_MEM8(0x07D3)
+#define PORTQ_PIN4CTRL _SFR_MEM8(0x07D4)
+#define PORTQ_PIN5CTRL _SFR_MEM8(0x07D5)
+#define PORTQ_PIN6CTRL _SFR_MEM8(0x07D6)
+#define PORTQ_PIN7CTRL _SFR_MEM8(0x07D7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* USARTE1 - Universal Asynchronous Receiver-Transmitter E1 */
+#define USARTE1_DATA _SFR_MEM8(0x0AB0)
+#define USARTE1_STATUS _SFR_MEM8(0x0AB1)
+#define USARTE1_CTRLA _SFR_MEM8(0x0AB3)
+#define USARTE1_CTRLB _SFR_MEM8(0x0AB4)
+#define USARTE1_CTRLC _SFR_MEM8(0x0AB5)
+#define USARTE1_BAUDCTRLA _SFR_MEM8(0x0AB6)
+#define USARTE1_BAUDCTRLB _SFR_MEM8(0x0AB7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* TCF1 - Timer/Counter F1 */
+#define TCF1_CTRLA _SFR_MEM8(0x0B40)
+#define TCF1_CTRLB _SFR_MEM8(0x0B41)
+#define TCF1_CTRLC _SFR_MEM8(0x0B42)
+#define TCF1_CTRLD _SFR_MEM8(0x0B43)
+#define TCF1_CTRLE _SFR_MEM8(0x0B44)
+#define TCF1_INTCTRLA _SFR_MEM8(0x0B46)
+#define TCF1_INTCTRLB _SFR_MEM8(0x0B47)
+#define TCF1_CTRLFCLR _SFR_MEM8(0x0B48)
+#define TCF1_CTRLFSET _SFR_MEM8(0x0B49)
+#define TCF1_CTRLGCLR _SFR_MEM8(0x0B4A)
+#define TCF1_CTRLGSET _SFR_MEM8(0x0B4B)
+#define TCF1_INTFLAGS _SFR_MEM8(0x0B4C)
+#define TCF1_TEMP _SFR_MEM8(0x0B4F)
+#define TCF1_CNT _SFR_MEM16(0x0B60)
+#define TCF1_PER _SFR_MEM16(0x0B66)
+#define TCF1_CCA _SFR_MEM16(0x0B68)
+#define TCF1_CCB _SFR_MEM16(0x0B6A)
+#define TCF1_PERBUF _SFR_MEM16(0x0B76)
+#define TCF1_CCABUF _SFR_MEM16(0x0B78)
+#define TCF1_CCBBUF _SFR_MEM16(0x0B7A)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODACT_gm 0x0C /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 2 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<2) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 2 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<3) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 3 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* SPIE interrupt vectors */
+#define SPIE_INT_vect_num 57
+#define SPIE_INT_vect _VECTOR(57) /* SPI Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* USARTE1 interrupt vectors */
+#define USARTE1_RXC_vect_num 61
+#define USARTE1_RXC_vect _VECTOR(61) /* Reception Complete Interrupt */
+#define USARTE1_DRE_vect_num 62
+#define USARTE1_DRE_vect _VECTOR(62) /* Data Register Empty Interrupt */
+#define USARTE1_TXC_vect_num 63
+#define USARTE1_TXC_vect _VECTOR(63) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TWID interrupt vectors */
+#define TWID_TWIS_vect_num 75
+#define TWID_TWIS_vect _VECTOR(75) /* TWI Slave Interrupt */
+#define TWID_TWIM_vect_num 76
+#define TWID_TWIM_vect _VECTOR(76) /* TWI Master Interrupt */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTQ interrupt vectors */
+#define PORTQ_INT0_vect_num 94
+#define PORTQ_INT0_vect _VECTOR(94) /* External Interrupt 0 */
+#define PORTQ_INT1_vect_num 95
+#define PORTQ_INT1_vect _VECTOR(95) /* External Interrupt 1 */
+
+/* PORTH interrupt vectors */
+#define PORTH_INT0_vect_num 96
+#define PORTH_INT0_vect _VECTOR(96) /* External Interrupt 0 */
+#define PORTH_INT1_vect_num 97
+#define PORTH_INT1_vect _VECTOR(97) /* External Interrupt 1 */
+
+/* PORTJ interrupt vectors */
+#define PORTJ_INT0_vect_num 98
+#define PORTJ_INT0_vect _VECTOR(98) /* External Interrupt 0 */
+#define PORTJ_INT1_vect_num 99
+#define PORTJ_INT1_vect _VECTOR(99) /* External Interrupt 1 */
+
+/* PORTK interrupt vectors */
+#define PORTK_INT0_vect_num 100
+#define PORTK_INT0_vect _VECTOR(100) /* External Interrupt 0 */
+#define PORTK_INT1_vect_num 101
+#define PORTK_INT1_vect _VECTOR(101) /* External Interrupt 1 */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TWIF interrupt vectors */
+#define TWIF_TWIS_vect_num 106
+#define TWIF_TWIS_vect _VECTOR(106) /* TWI Slave Interrupt */
+#define TWIF_TWIM_vect_num 107
+#define TWIF_TWIM_vect _VECTOR(107) /* TWI Master Interrupt */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* TCF1 interrupt vectors */
+#define TCF1_OVF_vect_num 114
+#define TCF1_OVF_vect _VECTOR(114) /* Overflow Interrupt */
+#define TCF1_ERR_vect_num 115
+#define TCF1_ERR_vect _VECTOR(115) /* Error Interrupt */
+#define TCF1_CCA_vect_num 116
+#define TCF1_CCA_vect _VECTOR(116) /* Compare or Capture A Interrupt */
+#define TCF1_CCB_vect_num 117
+#define TCF1_CCB_vect _VECTOR(117) /* Compare or Capture B Interrupt */
+
+/* SPIF interrupt vectors */
+#define SPIF_INT_vect_num 118
+#define SPIF_INT_vect _VECTOR(118) /* SPI Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+/* USARTF1 interrupt vectors */
+#define USARTF1_RXC_vect_num 122
+#define USARTF1_RXC_vect _VECTOR(122) /* Reception Complete Interrupt */
+#define USARTF1_DRE_vect_num 123
+#define USARTF1_DRE_vect _VECTOR(123) /* Data Register Empty Interrupt */
+#define USARTF1_TXC_vect_num 124
+#define USARTF1_TXC_vect _VECTOR(124) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (125 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (139264)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (131072)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x1E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x20000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (16777216)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (8192)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EXTERNAL_SRAM_START (0x4000)
+#define EXTERNAL_SRAM_SIZE (16760832)
+#define EXTERNAL_SRAM_PAGE_SIZE (0)
+#define EXTERNAL_SRAM_END (EXTERNAL_SRAM_START + EXTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND EXTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BODACT0 (unsigned char)~_BV(2) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(3) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x4C
+
+
+#endif /* _AVR_ATxmega128A1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox128a3.h b/cpukit/score/cpu/avr/avr/iox128a3.h
new file mode 100644
index 0000000000..3087e0182c
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox128a3.h
@@ -0,0 +1,6890 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox128a3.h - definitions for ATxmega128A3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox128a3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega128A3_H_
+#define _AVR_ATxmega128A3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE1 (*(USART_t *) 0x0AB0) /* Universal Asynchronous Receiver-Transmitter E1 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* USARTE1 - Universal Asynchronous Receiver-Transmitter E1 */
+#define USARTE1_DATA _SFR_MEM8(0x0AB0)
+#define USARTE1_STATUS _SFR_MEM8(0x0AB1)
+#define USARTE1_CTRLA _SFR_MEM8(0x0AB3)
+#define USARTE1_CTRLB _SFR_MEM8(0x0AB4)
+#define USARTE1_CTRLC _SFR_MEM8(0x0AB5)
+#define USARTE1_BAUDCTRLA _SFR_MEM8(0x0AB6)
+#define USARTE1_BAUDCTRLB _SFR_MEM8(0x0AB7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* SPIE interrupt vectors */
+#define SPIE_INT_vect_num 57
+#define SPIE_INT_vect _VECTOR(57) /* SPI Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* USARTE1 interrupt vectors */
+#define USARTE1_RXC_vect_num 61
+#define USARTE1_RXC_vect _VECTOR(61) /* Reception Complete Interrupt */
+#define USARTE1_DRE_vect_num 62
+#define USARTE1_DRE_vect _VECTOR(62) /* Data Register Empty Interrupt */
+#define USARTE1_TXC_vect_num 63
+#define USARTE1_TXC_vect _VECTOR(63) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (122 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (139264)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (131072)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x1E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x20000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (16384)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (8192)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x42
+
+
+#endif /* _AVR_ATxmega128A3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox128d3.h b/cpukit/score/cpu/avr/avr/iox128d3.h
new file mode 100644
index 0000000000..da56260e7c
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox128d3.h
@@ -0,0 +1,5646 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox128d3.h - definitions for ATxmega128D3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox128d3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega128D3_H_
+#define _AVR_ATxmega128D3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIOR0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIOR1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIOR2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIOR3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIOR4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIOR5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIOR6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIOR7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIOR8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIOR9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIORA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIORB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIORC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIORD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIORE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIORF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_PER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_PER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_WPER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_WPER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC/1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRLA; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRQ_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+ register8_t CTRL; /* Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIOR0 _SFR_MEM8(0x0000)
+#define GPIO_GPIOR1 _SFR_MEM8(0x0001)
+#define GPIO_GPIOR2 _SFR_MEM8(0x0002)
+#define GPIO_GPIOR3 _SFR_MEM8(0x0003)
+#define GPIO_GPIOR4 _SFR_MEM8(0x0004)
+#define GPIO_GPIOR5 _SFR_MEM8(0x0005)
+#define GPIO_GPIOR6 _SFR_MEM8(0x0006)
+#define GPIO_GPIOR7 _SFR_MEM8(0x0007)
+#define GPIO_GPIOR8 _SFR_MEM8(0x0008)
+#define GPIO_GPIOR9 _SFR_MEM8(0x0009)
+#define GPIO_GPIORA _SFR_MEM8(0x000A)
+#define GPIO_GPIORB _SFR_MEM8(0x000B)
+#define GPIO_GPIORC _SFR_MEM8(0x000C)
+#define GPIO_GPIORD _SFR_MEM8(0x000D)
+#define GPIO_GPIORE _SFR_MEM8(0x000E)
+#define GPIO_GPIORF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0483)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0484)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0485)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0486)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0487)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRLA _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F8)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_CTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRLA bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (114 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (139264)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (131072)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x1E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x20000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (16384)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (8192)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x48
+
+
+#endif /* _AVR_ATxmega128D3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox16a4.h b/cpukit/score/cpu/avr/avr/iox16a4.h
new file mode 100644
index 0000000000..18c1105a09
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox16a4.h
@@ -0,0 +1,6645 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox16a4.h - definitions for ATxmega16A4 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox16a4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega16A4_H_
+#define _AVR_ATxmega16A4_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (94 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (20480)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (16384)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x3000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x4000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (10240)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (1024)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (2048)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (1024)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x41
+
+
+#endif /* _AVR_ATxmega16A4_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox16d4.h b/cpukit/score/cpu/avr/avr/iox16d4.h
new file mode 100644
index 0000000000..04bbb9955f
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox16d4.h
@@ -0,0 +1,5542 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox16d4.h - definitions for ATxmega16D4 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox16d4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega16D4_H_
+#define _AVR_ATxmega16D4_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC/1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (91 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (20480)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (16384)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x3000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x4000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (10240)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (1024)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (2048)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (1024)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x94
+#define SIGNATURE_2 0x42
+
+
+#endif /* _AVR_ATxmega16D4_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox192a3.h b/cpukit/score/cpu/avr/avr/iox192a3.h
new file mode 100644
index 0000000000..d786a379dd
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox192a3.h
@@ -0,0 +1,6890 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox192a3.h - definitions for ATxmega192A3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox192a3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega192A3_H_
+#define _AVR_ATxmega192A3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE1 (*(USART_t *) 0x0AB0) /* Universal Asynchronous Receiver-Transmitter E1 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* USARTE1 - Universal Asynchronous Receiver-Transmitter E1 */
+#define USARTE1_DATA _SFR_MEM8(0x0AB0)
+#define USARTE1_STATUS _SFR_MEM8(0x0AB1)
+#define USARTE1_CTRLA _SFR_MEM8(0x0AB3)
+#define USARTE1_CTRLB _SFR_MEM8(0x0AB4)
+#define USARTE1_CTRLC _SFR_MEM8(0x0AB5)
+#define USARTE1_BAUDCTRLA _SFR_MEM8(0x0AB6)
+#define USARTE1_BAUDCTRLB _SFR_MEM8(0x0AB7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* SPIE interrupt vectors */
+#define SPIE_INT_vect_num 57
+#define SPIE_INT_vect _VECTOR(57) /* SPI Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* USARTE1 interrupt vectors */
+#define USARTE1_RXC_vect_num 61
+#define USARTE1_RXC_vect _VECTOR(61) /* Reception Complete Interrupt */
+#define USARTE1_DRE_vect_num 62
+#define USARTE1_DRE_vect _VECTOR(62) /* Data Register Empty Interrupt */
+#define USARTE1_TXC_vect_num 63
+#define USARTE1_TXC_vect _VECTOR(63) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (122 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (204800)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (196608)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x2E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x30000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (16777216)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (4096)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (16384)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (4096)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x44
+
+
+#endif /* _AVR_ATxmega192A3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox192d3.h b/cpukit/score/cpu/avr/avr/iox192d3.h
new file mode 100644
index 0000000000..2df04cbd40
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox192d3.h
@@ -0,0 +1,5646 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox192d3.h - definitions for ATxmega192D3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox192d3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega192D3_H_
+#define _AVR_ATxmega192D3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIOR0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIOR1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIOR2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIOR3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIOR4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIOR5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIOR6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIOR7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIOR8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIOR9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIORA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIORB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIORC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIORD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIORE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIORF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_PER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_PER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_WPER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_WPER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.9 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.1 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.4 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.6 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.9 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 3.2 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC/1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRLA; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRQ_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIOR0 _SFR_MEM8(0x0000)
+#define GPIO_GPIOR1 _SFR_MEM8(0x0001)
+#define GPIO_GPIOR2 _SFR_MEM8(0x0002)
+#define GPIO_GPIOR3 _SFR_MEM8(0x0003)
+#define GPIO_GPIOR4 _SFR_MEM8(0x0004)
+#define GPIO_GPIOR5 _SFR_MEM8(0x0005)
+#define GPIO_GPIOR6 _SFR_MEM8(0x0006)
+#define GPIO_GPIOR7 _SFR_MEM8(0x0007)
+#define GPIO_GPIOR8 _SFR_MEM8(0x0008)
+#define GPIO_GPIOR9 _SFR_MEM8(0x0009)
+#define GPIO_GPIORA _SFR_MEM8(0x000A)
+#define GPIO_GPIORB _SFR_MEM8(0x000B)
+#define GPIO_GPIORC _SFR_MEM8(0x000C)
+#define GPIO_GPIORD _SFR_MEM8(0x000D)
+#define GPIO_GPIORE _SFR_MEM8(0x000E)
+#define GPIO_GPIORF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0483)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0484)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0485)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0486)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0487)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRLA _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRLA bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (114 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (204800)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (196608)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x2E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x30000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (24576)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (16384)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x97
+#define SIGNATURE_2 0x49
+
+
+#endif /* _AVR_ATxmega192D3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox256a3.h b/cpukit/score/cpu/avr/avr/iox256a3.h
new file mode 100644
index 0000000000..25a0adf4d6
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox256a3.h
@@ -0,0 +1,6890 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox256a3.h - definitions for ATxmega256A3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox256a3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega256A3_H_
+#define _AVR_ATxmega256A3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE1 (*(USART_t *) 0x0AB0) /* Universal Asynchronous Receiver-Transmitter E1 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* USARTE1 - Universal Asynchronous Receiver-Transmitter E1 */
+#define USARTE1_DATA _SFR_MEM8(0x0AB0)
+#define USARTE1_STATUS _SFR_MEM8(0x0AB1)
+#define USARTE1_CTRLA _SFR_MEM8(0x0AB3)
+#define USARTE1_CTRLB _SFR_MEM8(0x0AB4)
+#define USARTE1_CTRLC _SFR_MEM8(0x0AB5)
+#define USARTE1_BAUDCTRLA _SFR_MEM8(0x0AB6)
+#define USARTE1_BAUDCTRLB _SFR_MEM8(0x0AB7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* SPIE interrupt vectors */
+#define SPIE_INT_vect_num 57
+#define SPIE_INT_vect _VECTOR(57) /* SPI Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* USARTE1 interrupt vectors */
+#define USARTE1_RXC_vect_num 61
+#define USARTE1_RXC_vect _VECTOR(61) /* Reception Complete Interrupt */
+#define USARTE1_DRE_vect_num 62
+#define USARTE1_DRE_vect _VECTOR(62) /* Data Register Empty Interrupt */
+#define USARTE1_TXC_vect_num 63
+#define USARTE1_TXC_vect _VECTOR(63) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (122 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (270336)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (262144)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x3E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x40000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (24576)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (4096)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (16384)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (4096)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x98
+#define SIGNATURE_2 0x42
+
+
+#endif /* _AVR_ATxmega256A3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox256a3b.h b/cpukit/score/cpu/avr/avr/iox256a3b.h
new file mode 100644
index 0000000000..3b01db13eb
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox256a3b.h
@@ -0,0 +1,6892 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox256a3b.h - definitions for ATxmega256A3B */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox256a3b.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega256A3B_H_
+#define _AVR_ATxmega256A3B_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC32 - 32-bit Real-Time Counter
+--------------------------------------------------------------------------
+*/
+
+/* 32-bit Real-Time Clounter */
+typedef struct RTC32_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t SYNCCTRL; /* Synchronization Control/Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+} RTC32_t;
+
+/* Compare Interrupt level */
+typedef enum RTC32_COMPINTLVL_enum
+{
+ RTC32_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC32_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC32_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC32_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC32_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC32_OVFINTLVL_enum
+{
+ RTC32_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC32_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC32_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC32_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC32_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+VBAT - VBAT Battery Backup Module
+--------------------------------------------------------------------------
+*/
+
+/* VBAT Battery Backup Module */
+typedef struct VBAT_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t BACKUP0; /* Battery Bacup Register 0 */
+ register8_t BACKUP1; /* Battery Backup Register 1 */
+} VBAT_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define VBAT (*(VBAT_t *) 0x00F0) /* VBAT Battery Backup Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC32 (*(RTC32_t *) 0x0420) /* 32-bit Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* VBAT - VBAT Battery Backup Module */
+#define VBAT_CTRL _SFR_MEM8(0x00F0)
+#define VBAT_STATUS _SFR_MEM8(0x00F1)
+#define VBAT_BACKUP0 _SFR_MEM8(0x00F2)
+#define VBAT_BACKUP1 _SFR_MEM8(0x00F3)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC32 - 32-bit Real-Time Counter */
+#define RTC32_CTRL _SFR_MEM8(0x0420)
+#define RTC32_SYNCCTRL _SFR_MEM8(0x0421)
+#define RTC32_INTCTRL _SFR_MEM8(0x0422)
+#define RTC32_INTFLAGS _SFR_MEM8(0x0423)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC32 - 32-bit Real-Time Counter */
+/* RTC32.CTRL bit masks and bit positions */
+#define RTC32_ENABLE_bm 0x01 /* RTC enable bit mask. */
+#define RTC32_ENABLE_bp 0 /* RTC enable bit position. */
+
+
+/* RTC32.SYNCCTRL bit masks and bit positions */
+#define RTC32_SYNCCNT_bm 0x10 /* Synchronization Busy Flag bit mask. */
+#define RTC32_SYNCCNT_bp 4 /* Synchronization Busy Flag bit position. */
+
+#define RTC32_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC32_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC32.INTCTRL bit masks and bit positions */
+#define RTC32_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC32_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC32_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC32_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC32_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC32_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC32_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC32_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC32_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC32_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC32_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC32_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC32.INTFLAGS bit masks and bit positions */
+#define RTC32_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC32_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC32_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC32_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* VBAT - VBAT Battery Backup Module */
+/* VBAT.CTRL bit masks and bit positions */
+#define VBAT_XOSCSEL_bm 0x10 /* 32-kHz Crystal Oscillator Output Selection bit mask. */
+#define VBAT_XOSCSEL_bp 4 /* 32-kHz Crystal Oscillator Output Selection bit position. */
+
+#define VBAT_XOSCEN_bm 0x08 /* Crystal Oscillator Enable bit mask. */
+#define VBAT_XOSCEN_bp 3 /* Crystal Oscillator Enable bit position. */
+
+#define VBAT_XOSCFDEN_bm 0x04 /* Crystal Oscillator Failure Detection Monitor Enable bit mask. */
+#define VBAT_XOSCFDEN_bp 2 /* Crystal Oscillator Failure Detection Monitor Enable bit position. */
+
+#define VBAT_ACCEN_bm 0x02 /* Battery Backup Access Enable bit mask. */
+#define VBAT_ACCEN_bp 1 /* Battery Backup Access Enable bit position. */
+
+#define VBAT_RESET_bm 0x01 /* Battery Backup Reset bit mask. */
+#define VBAT_RESET_bp 0 /* Battery Backup Reset bit position. */
+
+
+/* VBAT.STATUS bit masks and bit positions */
+#define VBAT_BBPWR_bm 0x80 /* Battery backup Power bit mask. */
+#define VBAT_BBPWR_bp 7 /* Battery backup Power bit position. */
+
+#define VBAT_XOSCRDY_bm 0x08 /* Crystal Oscillator Ready bit mask. */
+#define VBAT_XOSCRDY_bp 3 /* Crystal Oscillator Ready bit position. */
+
+#define VBAT_XOSCFAIL_bm 0x04 /* Crystal Oscillator Failure bit mask. */
+#define VBAT_XOSCFAIL_bp 2 /* Crystal Oscillator Failure bit position. */
+
+#define VBAT_BBBORF_bm 0x02 /* Battery Backup Brown-Out Reset Flag bit mask. */
+#define VBAT_BBBORF_bp 1 /* Battery Backup Brown-Out Reset Flag bit position. */
+
+#define VBAT_BBPORF_bm 0x01 /* Battery Backup Power-On Reset Flag bit mask. */
+#define VBAT_BBPORF_bp 0 /* Battery Backup Power-On Reset Flag bit position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC32 interrupt vectors */
+#define RTC32_OVF_vect_num 10
+#define RTC32_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC32_COMP_vect_num 11
+#define RTC32_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (122 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (270336)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (262144)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x3E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x40000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (24576)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (4096)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (16384)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (4096)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x98
+#define SIGNATURE_2 0x43
+
+
+#endif /* _AVR_ATxmega256A3B_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox256d3.h b/cpukit/score/cpu/avr/avr/iox256d3.h
new file mode 100644
index 0000000000..618fe1033a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox256d3.h
@@ -0,0 +1,5456 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox256d3.h - definitions for ATxmega256D3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox256d3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega256D3_H_
+#define _AVR_ATxmega256D3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIOR0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIOR1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIOR2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIOR3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIOR4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIOR5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIOR6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIOR7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIOR8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIOR9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIORA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIORB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIORC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIORD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIORE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIORF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_PER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_PER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_WPER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_WPER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.9 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.1 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.4 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.6 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.9 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 3.2 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t reserved_0x05;
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* ACD Temporary Register */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC/1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRLA; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRQ_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIOR0 _SFR_MEM8(0x0000)
+#define GPIO_GPIOR1 _SFR_MEM8(0x0001)
+#define GPIO_GPIOR2 _SFR_MEM8(0x0002)
+#define GPIO_GPIOR3 _SFR_MEM8(0x0003)
+#define GPIO_GPIOR4 _SFR_MEM8(0x0004)
+#define GPIO_GPIOR5 _SFR_MEM8(0x0005)
+#define GPIO_GPIOR6 _SFR_MEM8(0x0006)
+#define GPIO_GPIOR7 _SFR_MEM8(0x0007)
+#define GPIO_GPIOR8 _SFR_MEM8(0x0008)
+#define GPIO_GPIOR9 _SFR_MEM8(0x0009)
+#define GPIO_GPIORA _SFR_MEM8(0x000A)
+#define GPIO_GPIORB _SFR_MEM8(0x000B)
+#define GPIO_GPIORC _SFR_MEM8(0x000C)
+#define GPIO_GPIORD _SFR_MEM8(0x000D)
+#define GPIO_GPIORE _SFR_MEM8(0x000E)
+#define GPIO_GPIORF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_TEMP _SFR_MEM8(0x0207)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRLA _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_RSTDISBL_bm 0x10 /* External Reset Disable bit mask. */
+#define NVM_FUSES_RSTDISBL_bp 4 /* External Reset Disable bit position. */
+
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* ADC Flush bit mask. */
+#define ADC_FLUSH_bp 1 /* ADC Flush bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x70 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+#define ADC_REFSEL2_bm (1<<6) /* Reference Selection bit 2 mask. */
+#define ADC_REFSEL2_bp 6 /* Reference Selection bit 2 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_bm 0x01 /* Event Action Select bit mask. */
+#define ADC_EVACT_bp 0 /* Event Action Select bit position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRLA bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (114 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (270336)
+#define PROGMEM_PAGE_SIZE (512)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (262144)
+#define APP_SECTION_PAGE_SIZE (512)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x3E000)
+#define APPTABLE_SECTION_SIZE (8192)
+#define APPTABLE_SECTION_PAGE_SIZE (512)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x40000)
+#define BOOT_SECTION_SIZE (8192)
+#define BOOT_SECTION_PAGE_SIZE (512)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (24576)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (4096)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (16384)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (4096)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (512)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE_RSTDISBL (unsigned char)~_BV(4) /* External Reset Disable */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x98
+#define SIGNATURE_2 0x44
+
+
+#endif /* _AVR_ATxmega256D3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox32a4.h b/cpukit/score/cpu/avr/avr/iox32a4.h
new file mode 100644
index 0000000000..f33b11b0eb
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox32a4.h
@@ -0,0 +1,6645 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox32a4.h - definitions for ATxmega32A4 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox32a4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega32A4_H_
+#define _AVR_ATxmega32A4_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (94 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (36864)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (32768)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x07000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x8000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (12288)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (1024)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (4096)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (1024)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x41
+
+
+#endif /* _AVR_ATxmega32A4_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox32d4.h b/cpukit/score/cpu/avr/avr/iox32d4.h
new file mode 100644
index 0000000000..516ee2f104
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox32d4.h
@@ -0,0 +1,5545 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox32d4.h - definitions for ATxmega32D4 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox32d4.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega32D4_H_
+#define _AVR_ATxmega32D4_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC/1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+
+/* DACB - Digital to Analog Converter B */
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (91 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (36864)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (32768)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x7000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x8000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (12288)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (1024)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (4096)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (1024)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x95
+#define SIGNATURE_2 0x42
+
+
+#endif /* _AVR_ATxmega32D4_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox64a1.h b/cpukit/score/cpu/avr/avr/iox64a1.h
new file mode 100644
index 0000000000..551a941698
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox64a1.h
@@ -0,0 +1,7140 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox64a1.h - definitions for ATxmega64A1 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox64a1.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega64A1_H_
+#define _AVR_ATxmega64A1_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<2), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<2), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<2), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACA (*(DAC_t *) 0x0300) /* Digitalto Analog Converter A */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define EBI (*(EBI_t *) 0x0440) /* External Bus Interface */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWID (*(TWI_t *) 0x0490) /* Two-Wire Interface D */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define TWIF (*(TWI_t *) 0x04B0) /* Two-Wire Interface F */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTH (*(PORT_t *) 0x06E0) /* Port H */
+#define PORTJ (*(PORT_t *) 0x0700) /* Port J */
+#define PORTK (*(PORT_t *) 0x0720) /* Port K */
+#define PORTQ (*(PORT_t *) 0x07C0) /* Port Q */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE1 (*(USART_t *) 0x0AB0) /* Universal Asynchronous Receiver-Transmitter E1 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define TCF1 (*(TC1_t *) 0x0B40) /* Timer/Counter F1 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACA - Digitalto Analog Converter A */
+#define DACA_CTRLA _SFR_MEM8(0x0300)
+#define DACA_CTRLB _SFR_MEM8(0x0301)
+#define DACA_CTRLC _SFR_MEM8(0x0302)
+#define DACA_EVCTRL _SFR_MEM8(0x0303)
+#define DACA_TIMCTRL _SFR_MEM8(0x0304)
+#define DACA_STATUS _SFR_MEM8(0x0305)
+#define DACA_GAINCAL _SFR_MEM8(0x0308)
+#define DACA_OFFSETCAL _SFR_MEM8(0x0309)
+#define DACA_CH0DATA _SFR_MEM16(0x0318)
+#define DACA_CH1DATA _SFR_MEM16(0x031A)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* EBI - External Bus Interface */
+#define EBI_CTRL _SFR_MEM8(0x0440)
+#define EBI_SDRAMCTRLA _SFR_MEM8(0x0441)
+#define EBI_REFRESH _SFR_MEM16(0x0444)
+#define EBI_INITDLY _SFR_MEM16(0x0446)
+#define EBI_SDRAMCTRLB _SFR_MEM8(0x0448)
+#define EBI_SDRAMCTRLC _SFR_MEM8(0x0449)
+#define EBI_CS0_CTRLA _SFR_MEM8(0x0450)
+#define EBI_CS0_CTRLB _SFR_MEM8(0x0451)
+#define EBI_CS0_BASEADDR _SFR_MEM16(0x0452)
+#define EBI_CS1_CTRLA _SFR_MEM8(0x0454)
+#define EBI_CS1_CTRLB _SFR_MEM8(0x0455)
+#define EBI_CS1_BASEADDR _SFR_MEM16(0x0456)
+#define EBI_CS2_CTRLA _SFR_MEM8(0x0458)
+#define EBI_CS2_CTRLB _SFR_MEM8(0x0459)
+#define EBI_CS2_BASEADDR _SFR_MEM16(0x045A)
+#define EBI_CS3_CTRLA _SFR_MEM8(0x045C)
+#define EBI_CS3_CTRLB _SFR_MEM8(0x045D)
+#define EBI_CS3_BASEADDR _SFR_MEM16(0x045E)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWID - Two-Wire Interface D */
+#define TWID_CTRL _SFR_MEM8(0x0490)
+#define TWID_MASTER_CTRLA _SFR_MEM8(0x0491)
+#define TWID_MASTER_CTRLB _SFR_MEM8(0x0492)
+#define TWID_MASTER_CTRLC _SFR_MEM8(0x0493)
+#define TWID_MASTER_STATUS _SFR_MEM8(0x0494)
+#define TWID_MASTER_BAUD _SFR_MEM8(0x0495)
+#define TWID_MASTER_ADDR _SFR_MEM8(0x0496)
+#define TWID_MASTER_DATA _SFR_MEM8(0x0497)
+#define TWID_SLAVE_CTRLA _SFR_MEM8(0x0498)
+#define TWID_SLAVE_CTRLB _SFR_MEM8(0x0499)
+#define TWID_SLAVE_STATUS _SFR_MEM8(0x049A)
+#define TWID_SLAVE_ADDR _SFR_MEM8(0x049B)
+#define TWID_SLAVE_DATA _SFR_MEM8(0x049C)
+#define TWID_SLAVE_ADDRMASK _SFR_MEM8(0x049D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* TWIF - Two-Wire Interface F */
+#define TWIF_CTRL _SFR_MEM8(0x04B0)
+#define TWIF_MASTER_CTRLA _SFR_MEM8(0x04B1)
+#define TWIF_MASTER_CTRLB _SFR_MEM8(0x04B2)
+#define TWIF_MASTER_CTRLC _SFR_MEM8(0x04B3)
+#define TWIF_MASTER_STATUS _SFR_MEM8(0x04B4)
+#define TWIF_MASTER_BAUD _SFR_MEM8(0x04B5)
+#define TWIF_MASTER_ADDR _SFR_MEM8(0x04B6)
+#define TWIF_MASTER_DATA _SFR_MEM8(0x04B7)
+#define TWIF_SLAVE_CTRLA _SFR_MEM8(0x04B8)
+#define TWIF_SLAVE_CTRLB _SFR_MEM8(0x04B9)
+#define TWIF_SLAVE_STATUS _SFR_MEM8(0x04BA)
+#define TWIF_SLAVE_ADDR _SFR_MEM8(0x04BB)
+#define TWIF_SLAVE_DATA _SFR_MEM8(0x04BC)
+#define TWIF_SLAVE_ADDRMASK _SFR_MEM8(0x04BD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTH - Port H */
+#define PORTH_DIR _SFR_MEM8(0x06E0)
+#define PORTH_DIRSET _SFR_MEM8(0x06E1)
+#define PORTH_DIRCLR _SFR_MEM8(0x06E2)
+#define PORTH_DIRTGL _SFR_MEM8(0x06E3)
+#define PORTH_OUT _SFR_MEM8(0x06E4)
+#define PORTH_OUTSET _SFR_MEM8(0x06E5)
+#define PORTH_OUTCLR _SFR_MEM8(0x06E6)
+#define PORTH_OUTTGL _SFR_MEM8(0x06E7)
+#define PORTH_IN _SFR_MEM8(0x06E8)
+#define PORTH_INTCTRL _SFR_MEM8(0x06E9)
+#define PORTH_INT0MASK _SFR_MEM8(0x06EA)
+#define PORTH_INT1MASK _SFR_MEM8(0x06EB)
+#define PORTH_INTFLAGS _SFR_MEM8(0x06EC)
+#define PORTH_PIN0CTRL _SFR_MEM8(0x06F0)
+#define PORTH_PIN1CTRL _SFR_MEM8(0x06F1)
+#define PORTH_PIN2CTRL _SFR_MEM8(0x06F2)
+#define PORTH_PIN3CTRL _SFR_MEM8(0x06F3)
+#define PORTH_PIN4CTRL _SFR_MEM8(0x06F4)
+#define PORTH_PIN5CTRL _SFR_MEM8(0x06F5)
+#define PORTH_PIN6CTRL _SFR_MEM8(0x06F6)
+#define PORTH_PIN7CTRL _SFR_MEM8(0x06F7)
+
+/* PORTJ - Port J */
+#define PORTJ_DIR _SFR_MEM8(0x0700)
+#define PORTJ_DIRSET _SFR_MEM8(0x0701)
+#define PORTJ_DIRCLR _SFR_MEM8(0x0702)
+#define PORTJ_DIRTGL _SFR_MEM8(0x0703)
+#define PORTJ_OUT _SFR_MEM8(0x0704)
+#define PORTJ_OUTSET _SFR_MEM8(0x0705)
+#define PORTJ_OUTCLR _SFR_MEM8(0x0706)
+#define PORTJ_OUTTGL _SFR_MEM8(0x0707)
+#define PORTJ_IN _SFR_MEM8(0x0708)
+#define PORTJ_INTCTRL _SFR_MEM8(0x0709)
+#define PORTJ_INT0MASK _SFR_MEM8(0x070A)
+#define PORTJ_INT1MASK _SFR_MEM8(0x070B)
+#define PORTJ_INTFLAGS _SFR_MEM8(0x070C)
+#define PORTJ_PIN0CTRL _SFR_MEM8(0x0710)
+#define PORTJ_PIN1CTRL _SFR_MEM8(0x0711)
+#define PORTJ_PIN2CTRL _SFR_MEM8(0x0712)
+#define PORTJ_PIN3CTRL _SFR_MEM8(0x0713)
+#define PORTJ_PIN4CTRL _SFR_MEM8(0x0714)
+#define PORTJ_PIN5CTRL _SFR_MEM8(0x0715)
+#define PORTJ_PIN6CTRL _SFR_MEM8(0x0716)
+#define PORTJ_PIN7CTRL _SFR_MEM8(0x0717)
+
+/* PORTK - Port K */
+#define PORTK_DIR _SFR_MEM8(0x0720)
+#define PORTK_DIRSET _SFR_MEM8(0x0721)
+#define PORTK_DIRCLR _SFR_MEM8(0x0722)
+#define PORTK_DIRTGL _SFR_MEM8(0x0723)
+#define PORTK_OUT _SFR_MEM8(0x0724)
+#define PORTK_OUTSET _SFR_MEM8(0x0725)
+#define PORTK_OUTCLR _SFR_MEM8(0x0726)
+#define PORTK_OUTTGL _SFR_MEM8(0x0727)
+#define PORTK_IN _SFR_MEM8(0x0728)
+#define PORTK_INTCTRL _SFR_MEM8(0x0729)
+#define PORTK_INT0MASK _SFR_MEM8(0x072A)
+#define PORTK_INT1MASK _SFR_MEM8(0x072B)
+#define PORTK_INTFLAGS _SFR_MEM8(0x072C)
+#define PORTK_PIN0CTRL _SFR_MEM8(0x0730)
+#define PORTK_PIN1CTRL _SFR_MEM8(0x0731)
+#define PORTK_PIN2CTRL _SFR_MEM8(0x0732)
+#define PORTK_PIN3CTRL _SFR_MEM8(0x0733)
+#define PORTK_PIN4CTRL _SFR_MEM8(0x0734)
+#define PORTK_PIN5CTRL _SFR_MEM8(0x0735)
+#define PORTK_PIN6CTRL _SFR_MEM8(0x0736)
+#define PORTK_PIN7CTRL _SFR_MEM8(0x0737)
+
+/* PORTQ - Port Q */
+#define PORTQ_DIR _SFR_MEM8(0x07C0)
+#define PORTQ_DIRSET _SFR_MEM8(0x07C1)
+#define PORTQ_DIRCLR _SFR_MEM8(0x07C2)
+#define PORTQ_DIRTGL _SFR_MEM8(0x07C3)
+#define PORTQ_OUT _SFR_MEM8(0x07C4)
+#define PORTQ_OUTSET _SFR_MEM8(0x07C5)
+#define PORTQ_OUTCLR _SFR_MEM8(0x07C6)
+#define PORTQ_OUTTGL _SFR_MEM8(0x07C7)
+#define PORTQ_IN _SFR_MEM8(0x07C8)
+#define PORTQ_INTCTRL _SFR_MEM8(0x07C9)
+#define PORTQ_INT0MASK _SFR_MEM8(0x07CA)
+#define PORTQ_INT1MASK _SFR_MEM8(0x07CB)
+#define PORTQ_INTFLAGS _SFR_MEM8(0x07CC)
+#define PORTQ_PIN0CTRL _SFR_MEM8(0x07D0)
+#define PORTQ_PIN1CTRL _SFR_MEM8(0x07D1)
+#define PORTQ_PIN2CTRL _SFR_MEM8(0x07D2)
+#define PORTQ_PIN3CTRL _SFR_MEM8(0x07D3)
+#define PORTQ_PIN4CTRL _SFR_MEM8(0x07D4)
+#define PORTQ_PIN5CTRL _SFR_MEM8(0x07D5)
+#define PORTQ_PIN6CTRL _SFR_MEM8(0x07D6)
+#define PORTQ_PIN7CTRL _SFR_MEM8(0x07D7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* USARTE1 - Universal Asynchronous Receiver-Transmitter E1 */
+#define USARTE1_DATA _SFR_MEM8(0x0AB0)
+#define USARTE1_STATUS _SFR_MEM8(0x0AB1)
+#define USARTE1_CTRLA _SFR_MEM8(0x0AB3)
+#define USARTE1_CTRLB _SFR_MEM8(0x0AB4)
+#define USARTE1_CTRLC _SFR_MEM8(0x0AB5)
+#define USARTE1_BAUDCTRLA _SFR_MEM8(0x0AB6)
+#define USARTE1_BAUDCTRLB _SFR_MEM8(0x0AB7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* TCF1 - Timer/Counter F1 */
+#define TCF1_CTRLA _SFR_MEM8(0x0B40)
+#define TCF1_CTRLB _SFR_MEM8(0x0B41)
+#define TCF1_CTRLC _SFR_MEM8(0x0B42)
+#define TCF1_CTRLD _SFR_MEM8(0x0B43)
+#define TCF1_CTRLE _SFR_MEM8(0x0B44)
+#define TCF1_INTCTRLA _SFR_MEM8(0x0B46)
+#define TCF1_INTCTRLB _SFR_MEM8(0x0B47)
+#define TCF1_CTRLFCLR _SFR_MEM8(0x0B48)
+#define TCF1_CTRLFSET _SFR_MEM8(0x0B49)
+#define TCF1_CTRLGCLR _SFR_MEM8(0x0B4A)
+#define TCF1_CTRLGSET _SFR_MEM8(0x0B4B)
+#define TCF1_INTFLAGS _SFR_MEM8(0x0B4C)
+#define TCF1_TEMP _SFR_MEM8(0x0B4F)
+#define TCF1_CNT _SFR_MEM16(0x0B60)
+#define TCF1_PER _SFR_MEM16(0x0B66)
+#define TCF1_CCA _SFR_MEM16(0x0B68)
+#define TCF1_CCB _SFR_MEM16(0x0B6A)
+#define TCF1_PERBUF _SFR_MEM16(0x0B76)
+#define TCF1_CCABUF _SFR_MEM16(0x0B78)
+#define TCF1_CCBBUF _SFR_MEM16(0x0B7A)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODACT_gm 0x0C /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 2 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<2) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 2 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<3) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 3 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* SPIE interrupt vectors */
+#define SPIE_INT_vect_num 57
+#define SPIE_INT_vect _VECTOR(57) /* SPI Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* USARTE1 interrupt vectors */
+#define USARTE1_RXC_vect_num 61
+#define USARTE1_RXC_vect _VECTOR(61) /* Reception Complete Interrupt */
+#define USARTE1_DRE_vect_num 62
+#define USARTE1_DRE_vect _VECTOR(62) /* Data Register Empty Interrupt */
+#define USARTE1_TXC_vect_num 63
+#define USARTE1_TXC_vect _VECTOR(63) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TWID interrupt vectors */
+#define TWID_TWIS_vect_num 75
+#define TWID_TWIS_vect _VECTOR(75) /* TWI Slave Interrupt */
+#define TWID_TWIM_vect_num 76
+#define TWID_TWIM_vect _VECTOR(76) /* TWI Master Interrupt */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTQ interrupt vectors */
+#define PORTQ_INT0_vect_num 94
+#define PORTQ_INT0_vect _VECTOR(94) /* External Interrupt 0 */
+#define PORTQ_INT1_vect_num 95
+#define PORTQ_INT1_vect _VECTOR(95) /* External Interrupt 1 */
+
+/* PORTH interrupt vectors */
+#define PORTH_INT0_vect_num 96
+#define PORTH_INT0_vect _VECTOR(96) /* External Interrupt 0 */
+#define PORTH_INT1_vect_num 97
+#define PORTH_INT1_vect _VECTOR(97) /* External Interrupt 1 */
+
+/* PORTJ interrupt vectors */
+#define PORTJ_INT0_vect_num 98
+#define PORTJ_INT0_vect _VECTOR(98) /* External Interrupt 0 */
+#define PORTJ_INT1_vect_num 99
+#define PORTJ_INT1_vect _VECTOR(99) /* External Interrupt 1 */
+
+/* PORTK interrupt vectors */
+#define PORTK_INT0_vect_num 100
+#define PORTK_INT0_vect _VECTOR(100) /* External Interrupt 0 */
+#define PORTK_INT1_vect_num 101
+#define PORTK_INT1_vect _VECTOR(101) /* External Interrupt 1 */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TWIF interrupt vectors */
+#define TWIF_TWIS_vect_num 106
+#define TWIF_TWIS_vect _VECTOR(106) /* TWI Slave Interrupt */
+#define TWIF_TWIM_vect_num 107
+#define TWIF_TWIM_vect _VECTOR(107) /* TWI Master Interrupt */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* TCF1 interrupt vectors */
+#define TCF1_OVF_vect_num 114
+#define TCF1_OVF_vect _VECTOR(114) /* Overflow Interrupt */
+#define TCF1_ERR_vect_num 115
+#define TCF1_ERR_vect _VECTOR(115) /* Error Interrupt */
+#define TCF1_CCA_vect_num 116
+#define TCF1_CCA_vect _VECTOR(116) /* Compare or Capture A Interrupt */
+#define TCF1_CCB_vect_num 117
+#define TCF1_CCB_vect _VECTOR(117) /* Compare or Capture B Interrupt */
+
+/* SPIF interrupt vectors */
+#define SPIF_INT_vect_num 118
+#define SPIF_INT_vect _VECTOR(118) /* SPI Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+/* USARTF1 interrupt vectors */
+#define USARTF1_RXC_vect_num 122
+#define USARTF1_RXC_vect _VECTOR(122) /* Reception Complete Interrupt */
+#define USARTF1_DRE_vect_num 123
+#define USARTF1_DRE_vect _VECTOR(123) /* Data Register Empty Interrupt */
+#define USARTF1_TXC_vect_num 124
+#define USARTF1_TXC_vect _VECTOR(124) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (125 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (69632)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (65536)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x0F000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x10000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (16777216)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (4096)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EXTERNAL_SRAM_START (0x3000)
+#define EXTERNAL_SRAM_SIZE (16764928)
+#define EXTERNAL_SRAM_PAGE_SIZE (0)
+#define EXTERNAL_SRAM_END (EXTERNAL_SRAM_START + EXTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND EXTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BODACT0 (unsigned char)~_BV(2) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(3) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x4E
+
+
+#endif /* _AVR_ATxmega64A1_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox64a3.h b/cpukit/score/cpu/avr/avr/iox64a3.h
new file mode 100644
index 0000000000..ca27bcd597
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox64a3.h
@@ -0,0 +1,6890 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox64a3.h - definitions for ATxmega64A3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox64a3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega64A3_H_
+#define _AVR_ATxmega64A3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIO0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIO1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIO2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIO3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIO4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIO5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIO6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIO7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIO8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIO9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIOA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIOB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIOC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIOD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIOE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIOF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_PER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_PER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_128CLK_gc = (0x04<<2), /* 128 cycles (0.125s @ 3.3V) */
+ WDT_WPER_256CLK_gc = (0x05<<2), /* 256 cycles (0.25s @ 3.3V) */
+ WDT_WPER_512CLK_gc = (0x06<<2), /* 512 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Channel */
+typedef struct DMA_CH_struct
+{
+ register8_t CTRLA; /* Channel Control */
+ register8_t CTRLB; /* Channel Control */
+ register8_t ADDRCTRL; /* Address Control */
+ register8_t TRIGSRC; /* Channel Trigger Source */
+ _WORDREGISTER(TRFCNT); /* Channel Block Transfer Count */
+ register8_t REPCNT; /* Channel Repeat Count */
+ register8_t reserved_0x07;
+ register8_t SRCADDR0; /* Channel Source Address 0 */
+ register8_t SRCADDR1; /* Channel Source Address 1 */
+ register8_t SRCADDR2; /* Channel Source Address 2 */
+ register8_t reserved_0x0B;
+ register8_t DESTADDR0; /* Channel Destination Address 0 */
+ register8_t DESTADDR1; /* Channel Destination Address 1 */
+ register8_t DESTADDR2; /* Channel Destination Address 2 */
+ register8_t reserved_0x0F;
+} DMA_CH_t;
+
+/*
+--------------------------------------------------------------------------
+DMA - DMA Controller
+--------------------------------------------------------------------------
+*/
+
+/* DMA Controller */
+typedef struct DMA_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t reserved_0x01;
+ register8_t reserved_0x02;
+ register8_t INTFLAGS; /* Transfer Interrupt Status */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x05;
+ _WORDREGISTER(TEMP); /* Temporary Register For 16/24-bit Access */
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ DMA_CH_t CH0; /* DMA Channel 0 */
+ DMA_CH_t CH1; /* DMA Channel 1 */
+ DMA_CH_t CH2; /* DMA Channel 2 */
+ DMA_CH_t CH3; /* DMA Channel 3 */
+} DMA_t;
+
+/* Burst mode */
+typedef enum DMA_CH_BURSTLEN_enum
+{
+ DMA_CH_BURSTLEN_1BYTE_gc = (0x00<<0), /* 1-byte burst mode */
+ DMA_CH_BURSTLEN_2BYTE_gc = (0x01<<0), /* 2-byte burst mode */
+ DMA_CH_BURSTLEN_4BYTE_gc = (0x02<<0), /* 4-byte burst mode */
+ DMA_CH_BURSTLEN_8BYTE_gc = (0x03<<0), /* 8-byte burst mode */
+} DMA_CH_BURSTLEN_t;
+
+/* Source address reload mode */
+typedef enum DMA_CH_SRCRELOAD_enum
+{
+ DMA_CH_SRCRELOAD_NONE_gc = (0x00<<6), /* No reload */
+ DMA_CH_SRCRELOAD_BLOCK_gc = (0x01<<6), /* Reload at end of block */
+ DMA_CH_SRCRELOAD_BURST_gc = (0x02<<6), /* Reload at end of burst */
+ DMA_CH_SRCRELOAD_TRANSACTION_gc = (0x03<<6), /* Reload at end of transaction */
+} DMA_CH_SRCRELOAD_t;
+
+/* Source addressing mode */
+typedef enum DMA_CH_SRCDIR_enum
+{
+ DMA_CH_SRCDIR_FIXED_gc = (0x00<<4), /* Fixed */
+ DMA_CH_SRCDIR_INC_gc = (0x01<<4), /* Increment */
+ DMA_CH_SRCDIR_DEC_gc = (0x02<<4), /* Decrement */
+} DMA_CH_SRCDIR_t;
+
+/* Destination adress reload mode */
+typedef enum DMA_CH_DESTRELOAD_enum
+{
+ DMA_CH_DESTRELOAD_NONE_gc = (0x00<<2), /* No reload */
+ DMA_CH_DESTRELOAD_BLOCK_gc = (0x01<<2), /* Reload at end of block */
+ DMA_CH_DESTRELOAD_BURST_gc = (0x02<<2), /* Reload at end of burst */
+ DMA_CH_DESTRELOAD_TRANSACTION_gc = (0x03<<2), /* Reload at end of transaction */
+} DMA_CH_DESTRELOAD_t;
+
+/* Destination adressing mode */
+typedef enum DMA_CH_DESTDIR_enum
+{
+ DMA_CH_DESTDIR_FIXED_gc = (0x00<<0), /* Fixed */
+ DMA_CH_DESTDIR_INC_gc = (0x01<<0), /* Increment */
+ DMA_CH_DESTDIR_DEC_gc = (0x02<<0), /* Decrement */
+} DMA_CH_DESTDIR_t;
+
+/* Transfer trigger source */
+typedef enum DMA_CH_TRIGSRC_enum
+{
+ DMA_CH_TRIGSRC_OFF_gc = (0x00<<0), /* Off software triggers only */
+ DMA_CH_TRIGSRC_EVSYS_CH0_gc = (0x01<<0), /* Event System Channel 0 */
+ DMA_CH_TRIGSRC_EVSYS_CH1_gc = (0x02<<0), /* Event System Channel 1 */
+ DMA_CH_TRIGSRC_EVSYS_CH2_gc = (0x03<<0), /* Event System Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH0_gc = (0x10<<0), /* ADCA Channel 0 */
+ DMA_CH_TRIGSRC_ADCA_CH1_gc = (0x11<<0), /* ADCA Channel 1 */
+ DMA_CH_TRIGSRC_ADCA_CH2_gc = (0x12<<0), /* ADCA Channel 2 */
+ DMA_CH_TRIGSRC_ADCA_CH3_gc = (0x13<<0), /* ADCA Channel 3 */
+ DMA_CH_TRIGSRC_ADCA_CH4_gc = (0x14<<0), /* ADCA Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACA_CH0_gc = (0x15<<0), /* DACA Channel 0 */
+ DMA_CH_TRIGSRC_DACA_CH1_gc = (0x16<<0), /* DACA Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH0_gc = (0x20<<0), /* ADCB Channel 0 */
+ DMA_CH_TRIGSRC_ADCB_CH1_gc = (0x21<<0), /* ADCB Channel 1 */
+ DMA_CH_TRIGSRC_ADCB_CH2_gc = (0x22<<0), /* ADCB Channel 2 */
+ DMA_CH_TRIGSRC_ADCB_CH3_gc = (0x23<<0), /* ADCB Channel 3 */
+ DMA_CH_TRIGSRC_ADCB_CH4_gc = (0x24<<0), /* ADCB Channel 0,1,2,3 combined */
+ DMA_CH_TRIGSRC_DACB_CH0_gc = (0x25<<0), /* DACB Channel 0 */
+ DMA_CH_TRIGSRC_DACB_CH1_gc = (0x26<<0), /* DACB Channel 1 */
+ DMA_CH_TRIGSRC_TCC0_OVF_gc = (0x40<<0), /* Timer/Counter C0 Overflow */
+ DMA_CH_TRIGSRC_TCC0_ERR_gc = (0x41<<0), /* Timer/Counter C0 Error */
+ DMA_CH_TRIGSRC_TCC0_CCA_gc = (0x42<<0), /* Timer/Counter C0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC0_CCB_gc = (0x43<<0), /* Timer/Counter C0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCC0_CCC_gc = (0x44<<0), /* Timer/Counter C0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCC0_CCD_gc = (0x45<<0), /* Timer/Counter C0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCC1_OVF_gc = (0x46<<0), /* Timer/Counter C1 Overflow */
+ DMA_CH_TRIGSRC_TCC1_ERR_gc = (0x47<<0), /* Timer/Counter C1 Error */
+ DMA_CH_TRIGSRC_TCC1_CCA_gc = (0x48<<0), /* Timer/Counter C1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCC1_CCB_gc = (0x49<<0), /* Timer/Counter C1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIC_gc = (0x4A<<0), /* SPI C Transfer Complete */
+ DMA_CH_TRIGSRC_USARTC0_RXC_gc = (0x4B<<0), /* USART C0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC0_DRE_gc = (0x4C<<0), /* USART C0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTC1_RXC_gc = (0x4E<<0), /* USART C1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTC1_DRE_gc = (0x4F<<0), /* USART C1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCD0_OVF_gc = (0x60<<0), /* Timer/Counter D0 Overflow */
+ DMA_CH_TRIGSRC_TCD0_ERR_gc = (0x61<<0), /* Timer/Counter D0 Error */
+ DMA_CH_TRIGSRC_TCD0_CCA_gc = (0x62<<0), /* Timer/Counter D0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD0_CCB_gc = (0x63<<0), /* Timer/Counter D0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCD0_CCC_gc = (0x64<<0), /* Timer/Counter D0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCD0_CCD_gc = (0x65<<0), /* Timer/Counter D0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCD1_OVF_gc = (0x66<<0), /* Timer/Counter D1 Overflow */
+ DMA_CH_TRIGSRC_TCD1_ERR_gc = (0x67<<0), /* Timer/Counter D1 Error */
+ DMA_CH_TRIGSRC_TCD1_CCA_gc = (0x68<<0), /* Timer/Counter D1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCD1_CCB_gc = (0x69<<0), /* Timer/Counter D1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPID_gc = (0x6A<<0), /* SPI D Transfer Complete */
+ DMA_CH_TRIGSRC_USARTD0_RXC_gc = (0x6B<<0), /* USART D0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD0_DRE_gc = (0x6C<<0), /* USART D0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTD1_RXC_gc = (0x6E<<0), /* USART D1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTD1_DRE_gc = (0x6F<<0), /* USART D1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCE0_OVF_gc = (0x80<<0), /* Timer/Counter E0 Overflow */
+ DMA_CH_TRIGSRC_TCE0_ERR_gc = (0x81<<0), /* Timer/Counter E0 Error */
+ DMA_CH_TRIGSRC_TCE0_CCA_gc = (0x82<<0), /* Timer/Counter E0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE0_CCB_gc = (0x83<<0), /* Timer/Counter E0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCE0_CCC_gc = (0x84<<0), /* Timer/Counter E0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCE0_CCD_gc = (0x85<<0), /* Timer/Counter E0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCE1_OVF_gc = (0x86<<0), /* Timer/Counter E1 Overflow */
+ DMA_CH_TRIGSRC_TCE1_ERR_gc = (0x87<<0), /* Timer/Counter E1 Error */
+ DMA_CH_TRIGSRC_TCE1_CCA_gc = (0x88<<0), /* Timer/Counter E1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCE1_CCB_gc = (0x89<<0), /* Timer/Counter E1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIE_gc = (0x8A<<0), /* SPI E Transfer Complete */
+ DMA_CH_TRIGSRC_USARTE0_RXC_gc = (0x8B<<0), /* USART E0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE0_DRE_gc = (0x8C<<0), /* USART E0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTE1_RXC_gc = (0x8E<<0), /* USART E1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTE1_DRE_gc = (0x8F<<0), /* USART E1 Data Register Empty */
+ DMA_CH_TRIGSRC_TCF0_OVF_gc = (0xA0<<0), /* Timer/Counter F0 Overflow */
+ DMA_CH_TRIGSRC_TCF0_ERR_gc = (0xA1<<0), /* Timer/Counter F0 Error */
+ DMA_CH_TRIGSRC_TCF0_CCA_gc = (0xA2<<0), /* Timer/Counter F0 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF0_CCB_gc = (0xA3<<0), /* Timer/Counter F0 Compare or Capture B */
+ DMA_CH_TRIGSRC_TCF0_CCC_gc = (0xA4<<0), /* Timer/Counter F0 Compare or Capture C */
+ DMA_CH_TRIGSRC_TCF0_CCD_gc = (0xA5<<0), /* Timer/Counter F0 Compare or Capture D */
+ DMA_CH_TRIGSRC_TCF1_OVF_gc = (0xA6<<0), /* Timer/Counter F1 Overflow */
+ DMA_CH_TRIGSRC_TCF1_ERR_gc = (0xA7<<0), /* Timer/Counter F1 Error */
+ DMA_CH_TRIGSRC_TCF1_CCA_gc = (0xA8<<0), /* Timer/Counter F1 Compare or Capture A */
+ DMA_CH_TRIGSRC_TCF1_CCB_gc = (0xA9<<0), /* Timer/Counter F1 Compare or Capture B */
+ DMA_CH_TRIGSRC_SPIF_gc = (0xAA<<0), /* SPI F Transfer Complete */
+ DMA_CH_TRIGSRC_USARTF0_RXC_gc = (0xAB<<0), /* USART F0 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF0_DRE_gc = (0xAC<<0), /* USART F0 Data Register Empty */
+ DMA_CH_TRIGSRC_USARTF1_RXC_gc = (0xAE<<0), /* USART F1 Receive Complete */
+ DMA_CH_TRIGSRC_USARTF1_DRE_gc = (0xAF<<0), /* USART F1 Data Register Empty */
+} DMA_CH_TRIGSRC_t;
+
+/* Double buffering mode */
+typedef enum DMA_DBUFMODE_enum
+{
+ DMA_DBUFMODE_DISABLED_gc = (0x00<<2), /* Double buffering disabled */
+ DMA_DBUFMODE_CH01_gc = (0x01<<2), /* Double buffering enabled on channel 0/1 */
+ DMA_DBUFMODE_CH23_gc = (0x02<<2), /* Double buffering enabled on channel 2/3 */
+ DMA_DBUFMODE_CH01CH23_gc = (0x03<<2), /* Double buffering enabled on ch. 0/1 and ch. 2/3 */
+} DMA_DBUFMODE_t;
+
+/* Priority mode */
+typedef enum DMA_PRIMODE_enum
+{
+ DMA_PRIMODE_RR0123_gc = (0x00<<0), /* Round Robin */
+ DMA_PRIMODE_CH0RR123_gc = (0x01<<0), /* Channel 0 > Round Robin on channel 1/2/3 */
+ DMA_PRIMODE_CH01RR23_gc = (0x02<<0), /* Channel 0 > channel 1 > Round Robin on channel 2/3 */
+ DMA_PRIMODE_CH0123_gc = (0x03<<0), /* Channel 0 > channel 1 > channel 2 > channel 3 */
+} DMA_PRIMODE_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_ERRINTLVL_enum
+{
+ DMA_CH_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ DMA_CH_ERRINTLVL_LO_gc = (0x01<<2), /* Low level */
+ DMA_CH_ERRINTLVL_MED_gc = (0x02<<2), /* Medium level */
+ DMA_CH_ERRINTLVL_HI_gc = (0x03<<2), /* High level */
+} DMA_CH_ERRINTLVL_t;
+
+/* Interrupt level */
+typedef enum DMA_CH_TRNINTLVL_enum
+{
+ DMA_CH_TRNINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ DMA_CH_TRNINTLVL_LO_gc = (0x01<<0), /* Low level */
+ DMA_CH_TRNINTLVL_MED_gc = (0x02<<0), /* Medium level */
+ DMA_CH_TRNINTLVL_HI_gc = (0x03<<0), /* High level */
+} DMA_CH_TRNINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH4MUX; /* Event Channel 4 Multiplexer */
+ register8_t CH5MUX; /* Event Channel 5 Multiplexer */
+ register8_t CH6MUX; /* Event Channel 6 Multiplexer */
+ register8_t CH7MUX; /* Event Channel 7 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t CH4CTRL; /* Channel 4 Control Register */
+ register8_t CH5CTRL; /* Channel 5 Control Register */
+ register8_t CH6CTRL; /* Channel 6 Control Register */
+ register8_t CH7CTRL; /* Channel 7 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ACB_CH0_gc = (0x13<<0), /* Analog Comparator B Channel 0 */
+ EVSYS_CHMUX_ACB_CH1_gc = (0x14<<0), /* Analog Comparator B Channel 1 */
+ EVSYS_CHMUX_ACB_WIN_gc = (0x15<<0), /* Analog Comparator B Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_ADCA_CH1_gc = (0x21<<0), /* ADC A Channel 1 */
+ EVSYS_CHMUX_ADCA_CH2_gc = (0x22<<0), /* ADC A Channel 2 */
+ EVSYS_CHMUX_ADCA_CH3_gc = (0x23<<0), /* ADC A Channel 3 */
+ EVSYS_CHMUX_ADCB_CH0_gc = (0x24<<0), /* ADC B Channel 0 */
+ EVSYS_CHMUX_ADCB_CH1_gc = (0x25<<0), /* ADC B Channel 1 */
+ EVSYS_CHMUX_ADCB_CH2_gc = (0x26<<0), /* ADC B Channel 2 */
+ EVSYS_CHMUX_ADCB_CH3_gc = (0x27<<0), /* ADC B Channel 3 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* JTAG User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CH1RES); /* Channel 1 Result */
+ _WORDREGISTER(CH2RES); /* Channel 2 Result */
+ _WORDREGISTER(CH3RES); /* Channel 3 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+ ADC_CH_t CH1; /* ADC Channel 1 */
+ ADC_CH_t CH2; /* ADC Channel 2 */
+ ADC_CH_t CH3; /* ADC Channel 3 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC / 1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+ ADC_SWEEP_01_gc = (0x01<<6), /* ADC Channel 0,1 */
+ ADC_SWEEP_012_gc = (0x02<<6), /* ADC Channel 0,1,2 */
+ ADC_SWEEP_0123_gc = (0x03<<6), /* ADC Channel 0,1,2,3 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+ ADC_EVACT_CH01_gc = (0x02<<0), /* First two events trigger channel 0,1 */
+ ADC_EVACT_CH012_gc = (0x03<<0), /* First three events trigger channel 0,1,2 */
+ ADC_EVACT_CH0123_gc = (0x04<<0), /* Events trigger channel 0,1,2,3 */
+ ADC_EVACT_SWEEP_gc = (0x05<<0), /* First event triggers sweep */
+ ADC_EVACT_SYNCHSWEEP_gc = (0x06<<0), /* First event triggers synchronized sweep */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* DMA request selection */
+typedef enum ADC_DMASEL_enum
+{
+ ADC_DMASEL_OFF_gc = (0x00<<6), /* Combined DMA request OFF */
+ ADC_DMASEL_CH01_gc = (0x01<<6), /* ADC Channel 0 or 1 */
+ ADC_DMASEL_CH012_gc = (0x02<<6), /* ADC Channel 0 or 1 or 2 */
+ ADC_DMASEL_CH0123_gc = (0x03<<6), /* ADC Channel 0 or 1 or 2 or 3 */
+} ADC_DMASEL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+DAC - Digital/Analog Converter
+--------------------------------------------------------------------------
+*/
+
+/* Digital-to-Analog Converter */
+typedef struct DAC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t EVCTRL; /* Event Input Control */
+ register8_t TIMCTRL; /* Timing Control */
+ register8_t STATUS; /* Status */
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t GAINCAL; /* Gain Calibration */
+ register8_t OFFSETCAL; /* Offset Calibration */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ _WORDREGISTER(CH0DATA); /* Channel 0 Data */
+ _WORDREGISTER(CH1DATA); /* Channel 1 Data */
+} DAC_t;
+
+/* Output channel selection */
+typedef enum DAC_CHSEL_enum
+{
+ DAC_CHSEL_SINGLE_gc = (0x00<<5), /* Single channel operation (Channel A only) */
+ DAC_CHSEL_DUAL_gc = (0x02<<5), /* Dual channel operation (S/H on both channels) */
+} DAC_CHSEL_t;
+
+/* Reference voltage selection */
+typedef enum DAC_REFSEL_enum
+{
+ DAC_REFSEL_INT1V_gc = (0x00<<3), /* Internal 1V */
+ DAC_REFSEL_AVCC_gc = (0x01<<3), /* Analog supply voltage */
+ DAC_REFSEL_AREFA_gc = (0x02<<3), /* External reference on AREF on PORTA */
+ DAC_REFSEL_AREFB_gc = (0x03<<3), /* External reference on AREF on PORTB */
+} DAC_REFSEL_t;
+
+/* Event channel selection */
+typedef enum DAC_EVSEL_enum
+{
+ DAC_EVSEL_0_gc = (0x00<<0), /* Event Channel 0 */
+ DAC_EVSEL_1_gc = (0x01<<0), /* Event Channel 1 */
+ DAC_EVSEL_2_gc = (0x02<<0), /* Event Channel 2 */
+ DAC_EVSEL_3_gc = (0x03<<0), /* Event Channel 3 */
+ DAC_EVSEL_4_gc = (0x04<<0), /* Event Channel 4 */
+ DAC_EVSEL_5_gc = (0x05<<0), /* Event Channel 5 */
+ DAC_EVSEL_6_gc = (0x06<<0), /* Event Channel 6 */
+ DAC_EVSEL_7_gc = (0x07<<0), /* Event Channel 7 */
+} DAC_EVSEL_t;
+
+/* Conversion interval */
+typedef enum DAC_CONINTVAL_enum
+{
+ DAC_CONINTVAL_1CLK_gc = (0x00<<4), /* 1 CLK / 2 CLK in S/H mode */
+ DAC_CONINTVAL_2CLK_gc = (0x01<<4), /* 2 CLK / 3 CLK in S/H mode */
+ DAC_CONINTVAL_4CLK_gc = (0x02<<4), /* 4 CLK / 6 CLK in S/H mode */
+ DAC_CONINTVAL_8CLK_gc = (0x03<<4), /* 8 CLK / 12 CLK in S/H mode */
+ DAC_CONINTVAL_16CLK_gc = (0x04<<4), /* 16 CLK / 24 CLK in S/H mode */
+ DAC_CONINTVAL_32CLK_gc = (0x05<<4), /* 32 CLK / 48 CLK in S/H mode */
+ DAC_CONINTVAL_64CLK_gc = (0x06<<4), /* 64 CLK / 96 CLK in S/H mode */
+ DAC_CONINTVAL_128CLK_gc = (0x07<<4), /* 128 CLK / 192 CLK in S/H mode */
+} DAC_CONINTVAL_t;
+
+/* Refresh rate */
+typedef enum DAC_REFRESH_enum
+{
+ DAC_REFRESH_16CLK_gc = (0x00<<0), /* 16 CLK */
+ DAC_REFRESH_32CLK_gc = (0x01<<0), /* 32 CLK */
+ DAC_REFRESH_64CLK_gc = (0x02<<0), /* 64 CLK */
+ DAC_REFRESH_128CLK_gc = (0x03<<0), /* 128 CLK */
+ DAC_REFRESH_256CLK_gc = (0x04<<0), /* 256 CLK */
+ DAC_REFRESH_512CLK_gc = (0x05<<0), /* 512 CLK */
+ DAC_REFRESH_1024CLK_gc = (0x06<<0), /* 1024 CLK */
+ DAC_REFRESH_2048CLK_gc = (0x07<<0), /* 2048 CLK */
+ DAC_REFRESH_4086CLK_gc = (0x08<<0), /* 4096 CLK */
+ DAC_REFRESH_8192CLK_gc = (0x09<<0), /* 8192 CLK */
+ DAC_REFRESH_16384CLK_gc = (0x0A<<0), /* 16384 CLK */
+ DAC_REFRESH_32768CLK_gc = (0x0B<<0), /* 32768 CLK */
+ DAC_REFRESH_65536CLK_gc = (0x0C<<0), /* 65536 CLK */
+ DAC_REFRESH_OFF_gc = (0x0F<<0), /* Auto refresh OFF */
+} DAC_REFRESH_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEVMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRL; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRW_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AES - AES Module
+--------------------------------------------------------------------------
+*/
+
+/* AES Module */
+typedef struct AES_struct
+{
+ register8_t CTRL; /* AES Control Register */
+ register8_t STATUS; /* AES Status Register */
+ register8_t STATE; /* AES State Register */
+ register8_t KEY; /* AES Key Register */
+ register8_t INTCTRL; /* AES Interrupt Control Register */
+} AES_t;
+
+/* Interrupt level */
+typedef enum AES_INTLVL_enum
+{
+ AES_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ AES_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ AES_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ AES_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} AES_INTLVL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define AES (*(AES_t *) 0x00C0) /* AES Crypto Module */
+#define DMA (*(DMA_t *) 0x0100) /* DMA Controller */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define ADCB (*(ADC_t *) 0x0240) /* Analog to Digital Converter B */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define TWIE (*(TWI_t *) 0x04A0) /* Two-Wire Interface E */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC1 (*(USART_t *) 0x08B0) /* Universal Asynchronous Receiver-Transmitter C1 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define TCD1 (*(TC1_t *) 0x0940) /* Timer/Counter D1 */
+#define HIRESD (*(HIRES_t *) 0x0990) /* High-Resolution Extension D */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD1 (*(USART_t *) 0x09B0) /* Universal Asynchronous Receiver-Transmitter D1 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define TCE1 (*(TC1_t *) 0x0A40) /* Timer/Counter E1 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define HIRESE (*(HIRES_t *) 0x0A90) /* High-Resolution Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE1 (*(USART_t *) 0x0AB0) /* Universal Asynchronous Receiver-Transmitter E1 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+#define HIRESF (*(HIRES_t *) 0x0B90) /* High-Resolution Extension F */
+#define USARTF0 (*(USART_t *) 0x0BA0) /* Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF1 (*(USART_t *) 0x0BB0) /* Universal Asynchronous Receiver-Transmitter F1 */
+#define SPIF (*(SPI_t *) 0x0BC0) /* Serial Peripheral Interface F */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIO0 _SFR_MEM8(0x0000)
+#define GPIO_GPIO1 _SFR_MEM8(0x0001)
+#define GPIO_GPIO2 _SFR_MEM8(0x0002)
+#define GPIO_GPIO3 _SFR_MEM8(0x0003)
+#define GPIO_GPIO4 _SFR_MEM8(0x0004)
+#define GPIO_GPIO5 _SFR_MEM8(0x0005)
+#define GPIO_GPIO6 _SFR_MEM8(0x0006)
+#define GPIO_GPIO7 _SFR_MEM8(0x0007)
+#define GPIO_GPIO8 _SFR_MEM8(0x0008)
+#define GPIO_GPIO9 _SFR_MEM8(0x0009)
+#define GPIO_GPIOA _SFR_MEM8(0x000A)
+#define GPIO_GPIOB _SFR_MEM8(0x000B)
+#define GPIO_GPIOC _SFR_MEM8(0x000C)
+#define GPIO_GPIOD _SFR_MEM8(0x000D)
+#define GPIO_GPIOE _SFR_MEM8(0x000E)
+#define GPIO_GPIOF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* AES - AES Crypto Module */
+#define AES_CTRL _SFR_MEM8(0x00C0)
+#define AES_STATUS _SFR_MEM8(0x00C1)
+#define AES_STATE _SFR_MEM8(0x00C2)
+#define AES_KEY _SFR_MEM8(0x00C3)
+#define AES_INTCTRL _SFR_MEM8(0x00C4)
+
+/* DMA - DMA Controller */
+#define DMA_CTRL _SFR_MEM8(0x0100)
+#define DMA_INTFLAGS _SFR_MEM8(0x0103)
+#define DMA_STATUS _SFR_MEM8(0x0104)
+#define DMA_TEMP _SFR_MEM16(0x0106)
+#define DMA_CH0_CTRLA _SFR_MEM8(0x0110)
+#define DMA_CH0_CTRLB _SFR_MEM8(0x0111)
+#define DMA_CH0_ADDRCTRL _SFR_MEM8(0x0112)
+#define DMA_CH0_TRIGSRC _SFR_MEM8(0x0113)
+#define DMA_CH0_TRFCNT _SFR_MEM16(0x0114)
+#define DMA_CH0_REPCNT _SFR_MEM8(0x0116)
+#define DMA_CH0_SRCADDR0 _SFR_MEM8(0x0118)
+#define DMA_CH0_SRCADDR1 _SFR_MEM8(0x0119)
+#define DMA_CH0_SRCADDR2 _SFR_MEM8(0x011A)
+#define DMA_CH0_DESTADDR0 _SFR_MEM8(0x011C)
+#define DMA_CH0_DESTADDR1 _SFR_MEM8(0x011D)
+#define DMA_CH0_DESTADDR2 _SFR_MEM8(0x011E)
+#define DMA_CH1_CTRLA _SFR_MEM8(0x0120)
+#define DMA_CH1_CTRLB _SFR_MEM8(0x0121)
+#define DMA_CH1_ADDRCTRL _SFR_MEM8(0x0122)
+#define DMA_CH1_TRIGSRC _SFR_MEM8(0x0123)
+#define DMA_CH1_TRFCNT _SFR_MEM16(0x0124)
+#define DMA_CH1_REPCNT _SFR_MEM8(0x0126)
+#define DMA_CH1_SRCADDR0 _SFR_MEM8(0x0128)
+#define DMA_CH1_SRCADDR1 _SFR_MEM8(0x0129)
+#define DMA_CH1_SRCADDR2 _SFR_MEM8(0x012A)
+#define DMA_CH1_DESTADDR0 _SFR_MEM8(0x012C)
+#define DMA_CH1_DESTADDR1 _SFR_MEM8(0x012D)
+#define DMA_CH1_DESTADDR2 _SFR_MEM8(0x012E)
+#define DMA_CH2_CTRLA _SFR_MEM8(0x0130)
+#define DMA_CH2_CTRLB _SFR_MEM8(0x0131)
+#define DMA_CH2_ADDRCTRL _SFR_MEM8(0x0132)
+#define DMA_CH2_TRIGSRC _SFR_MEM8(0x0133)
+#define DMA_CH2_TRFCNT _SFR_MEM16(0x0134)
+#define DMA_CH2_REPCNT _SFR_MEM8(0x0136)
+#define DMA_CH2_SRCADDR0 _SFR_MEM8(0x0138)
+#define DMA_CH2_SRCADDR1 _SFR_MEM8(0x0139)
+#define DMA_CH2_SRCADDR2 _SFR_MEM8(0x013A)
+#define DMA_CH2_DESTADDR0 _SFR_MEM8(0x013C)
+#define DMA_CH2_DESTADDR1 _SFR_MEM8(0x013D)
+#define DMA_CH2_DESTADDR2 _SFR_MEM8(0x013E)
+#define DMA_CH3_CTRLA _SFR_MEM8(0x0140)
+#define DMA_CH3_CTRLB _SFR_MEM8(0x0141)
+#define DMA_CH3_ADDRCTRL _SFR_MEM8(0x0142)
+#define DMA_CH3_TRIGSRC _SFR_MEM8(0x0143)
+#define DMA_CH3_TRFCNT _SFR_MEM16(0x0144)
+#define DMA_CH3_REPCNT _SFR_MEM8(0x0146)
+#define DMA_CH3_SRCADDR0 _SFR_MEM8(0x0148)
+#define DMA_CH3_SRCADDR1 _SFR_MEM8(0x0149)
+#define DMA_CH3_SRCADDR2 _SFR_MEM8(0x014A)
+#define DMA_CH3_DESTADDR0 _SFR_MEM8(0x014C)
+#define DMA_CH3_DESTADDR1 _SFR_MEM8(0x014D)
+#define DMA_CH3_DESTADDR2 _SFR_MEM8(0x014E)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH4MUX _SFR_MEM8(0x0184)
+#define EVSYS_CH5MUX _SFR_MEM8(0x0185)
+#define EVSYS_CH6MUX _SFR_MEM8(0x0186)
+#define EVSYS_CH7MUX _SFR_MEM8(0x0187)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_CH4CTRL _SFR_MEM8(0x018C)
+#define EVSYS_CH5CTRL _SFR_MEM8(0x018D)
+#define EVSYS_CH6CTRL _SFR_MEM8(0x018E)
+#define EVSYS_CH7CTRL _SFR_MEM8(0x018F)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CH1RES _SFR_MEM16(0x0212)
+#define ADCA_CH2RES _SFR_MEM16(0x0214)
+#define ADCA_CH3RES _SFR_MEM16(0x0216)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+#define ADCA_CH1_CTRL _SFR_MEM8(0x0228)
+#define ADCA_CH1_MUXCTRL _SFR_MEM8(0x0229)
+#define ADCA_CH1_INTCTRL _SFR_MEM8(0x022A)
+#define ADCA_CH1_INTFLAGS _SFR_MEM8(0x022B)
+#define ADCA_CH1_RES _SFR_MEM16(0x022C)
+#define ADCA_CH2_CTRL _SFR_MEM8(0x0230)
+#define ADCA_CH2_MUXCTRL _SFR_MEM8(0x0231)
+#define ADCA_CH2_INTCTRL _SFR_MEM8(0x0232)
+#define ADCA_CH2_INTFLAGS _SFR_MEM8(0x0233)
+#define ADCA_CH2_RES _SFR_MEM16(0x0234)
+#define ADCA_CH3_CTRL _SFR_MEM8(0x0238)
+#define ADCA_CH3_MUXCTRL _SFR_MEM8(0x0239)
+#define ADCA_CH3_INTCTRL _SFR_MEM8(0x023A)
+#define ADCA_CH3_INTFLAGS _SFR_MEM8(0x023B)
+#define ADCA_CH3_RES _SFR_MEM16(0x023C)
+
+/* ADCB - Analog to Digital Converter B */
+#define ADCB_CTRLA _SFR_MEM8(0x0240)
+#define ADCB_CTRLB _SFR_MEM8(0x0241)
+#define ADCB_REFCTRL _SFR_MEM8(0x0242)
+#define ADCB_EVCTRL _SFR_MEM8(0x0243)
+#define ADCB_PRESCALER _SFR_MEM8(0x0244)
+#define ADCB_CALCTRL _SFR_MEM8(0x0245)
+#define ADCB_INTFLAGS _SFR_MEM8(0x0246)
+#define ADCB_CAL _SFR_MEM16(0x024C)
+#define ADCB_CH0RES _SFR_MEM16(0x0250)
+#define ADCB_CH1RES _SFR_MEM16(0x0252)
+#define ADCB_CH2RES _SFR_MEM16(0x0254)
+#define ADCB_CH3RES _SFR_MEM16(0x0256)
+#define ADCB_CMP _SFR_MEM16(0x0258)
+#define ADCB_CH0_CTRL _SFR_MEM8(0x0260)
+#define ADCB_CH0_MUXCTRL _SFR_MEM8(0x0261)
+#define ADCB_CH0_INTCTRL _SFR_MEM8(0x0262)
+#define ADCB_CH0_INTFLAGS _SFR_MEM8(0x0263)
+#define ADCB_CH0_RES _SFR_MEM16(0x0264)
+#define ADCB_CH1_CTRL _SFR_MEM8(0x0268)
+#define ADCB_CH1_MUXCTRL _SFR_MEM8(0x0269)
+#define ADCB_CH1_INTCTRL _SFR_MEM8(0x026A)
+#define ADCB_CH1_INTFLAGS _SFR_MEM8(0x026B)
+#define ADCB_CH1_RES _SFR_MEM16(0x026C)
+#define ADCB_CH2_CTRL _SFR_MEM8(0x0270)
+#define ADCB_CH2_MUXCTRL _SFR_MEM8(0x0271)
+#define ADCB_CH2_INTCTRL _SFR_MEM8(0x0272)
+#define ADCB_CH2_INTFLAGS _SFR_MEM8(0x0273)
+#define ADCB_CH2_RES _SFR_MEM16(0x0274)
+#define ADCB_CH3_CTRL _SFR_MEM8(0x0278)
+#define ADCB_CH3_MUXCTRL _SFR_MEM8(0x0279)
+#define ADCB_CH3_INTCTRL _SFR_MEM8(0x027A)
+#define ADCB_CH3_INTFLAGS _SFR_MEM8(0x027B)
+#define ADCB_CH3_RES _SFR_MEM16(0x027C)
+
+/* DACB - Digital to Analog Converter B */
+#define DACB_CTRLA _SFR_MEM8(0x0320)
+#define DACB_CTRLB _SFR_MEM8(0x0321)
+#define DACB_CTRLC _SFR_MEM8(0x0322)
+#define DACB_EVCTRL _SFR_MEM8(0x0323)
+#define DACB_TIMCTRL _SFR_MEM8(0x0324)
+#define DACB_STATUS _SFR_MEM8(0x0325)
+#define DACB_GAINCAL _SFR_MEM8(0x0328)
+#define DACB_OFFSETCAL _SFR_MEM8(0x0329)
+#define DACB_CH0DATA _SFR_MEM16(0x0338)
+#define DACB_CH1DATA _SFR_MEM16(0x033A)
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0481)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0483)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0484)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0485)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0486)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0487)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* TWIE - Two-Wire Interface E */
+#define TWIE_CTRL _SFR_MEM8(0x04A0)
+#define TWIE_MASTER_CTRLA _SFR_MEM8(0x04A1)
+#define TWIE_MASTER_CTRLB _SFR_MEM8(0x04A2)
+#define TWIE_MASTER_CTRLC _SFR_MEM8(0x04A3)
+#define TWIE_MASTER_STATUS _SFR_MEM8(0x04A4)
+#define TWIE_MASTER_BAUD _SFR_MEM8(0x04A5)
+#define TWIE_MASTER_ADDR _SFR_MEM8(0x04A6)
+#define TWIE_MASTER_DATA _SFR_MEM8(0x04A7)
+#define TWIE_SLAVE_CTRLA _SFR_MEM8(0x04A8)
+#define TWIE_SLAVE_CTRLB _SFR_MEM8(0x04A9)
+#define TWIE_SLAVE_STATUS _SFR_MEM8(0x04AA)
+#define TWIE_SLAVE_ADDR _SFR_MEM8(0x04AB)
+#define TWIE_SLAVE_DATA _SFR_MEM8(0x04AC)
+#define TWIE_SLAVE_ADDRMASK _SFR_MEM8(0x04AD)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEVMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRL _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* USARTC1 - Universal Asynchronous Receiver-Transmitter C1 */
+#define USARTC1_DATA _SFR_MEM8(0x08B0)
+#define USARTC1_STATUS _SFR_MEM8(0x08B1)
+#define USARTC1_CTRLA _SFR_MEM8(0x08B3)
+#define USARTC1_CTRLB _SFR_MEM8(0x08B4)
+#define USARTC1_CTRLC _SFR_MEM8(0x08B5)
+#define USARTC1_BAUDCTRLA _SFR_MEM8(0x08B6)
+#define USARTC1_BAUDCTRLB _SFR_MEM8(0x08B7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_CTRL _SFR_MEM8(0x08F8)
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* TCD1 - Timer/Counter D1 */
+#define TCD1_CTRLA _SFR_MEM8(0x0940)
+#define TCD1_CTRLB _SFR_MEM8(0x0941)
+#define TCD1_CTRLC _SFR_MEM8(0x0942)
+#define TCD1_CTRLD _SFR_MEM8(0x0943)
+#define TCD1_CTRLE _SFR_MEM8(0x0944)
+#define TCD1_INTCTRLA _SFR_MEM8(0x0946)
+#define TCD1_INTCTRLB _SFR_MEM8(0x0947)
+#define TCD1_CTRLFCLR _SFR_MEM8(0x0948)
+#define TCD1_CTRLFSET _SFR_MEM8(0x0949)
+#define TCD1_CTRLGCLR _SFR_MEM8(0x094A)
+#define TCD1_CTRLGSET _SFR_MEM8(0x094B)
+#define TCD1_INTFLAGS _SFR_MEM8(0x094C)
+#define TCD1_TEMP _SFR_MEM8(0x094F)
+#define TCD1_CNT _SFR_MEM16(0x0960)
+#define TCD1_PER _SFR_MEM16(0x0966)
+#define TCD1_CCA _SFR_MEM16(0x0968)
+#define TCD1_CCB _SFR_MEM16(0x096A)
+#define TCD1_PERBUF _SFR_MEM16(0x0976)
+#define TCD1_CCABUF _SFR_MEM16(0x0978)
+#define TCD1_CCBBUF _SFR_MEM16(0x097A)
+
+/* HIRESD - High-Resolution Extension D */
+#define HIRESD_CTRL _SFR_MEM8(0x0990)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* USARTD1 - Universal Asynchronous Receiver-Transmitter D1 */
+#define USARTD1_DATA _SFR_MEM8(0x09B0)
+#define USARTD1_STATUS _SFR_MEM8(0x09B1)
+#define USARTD1_CTRLA _SFR_MEM8(0x09B3)
+#define USARTD1_CTRLB _SFR_MEM8(0x09B4)
+#define USARTD1_CTRLC _SFR_MEM8(0x09B5)
+#define USARTD1_BAUDCTRLA _SFR_MEM8(0x09B6)
+#define USARTD1_BAUDCTRLB _SFR_MEM8(0x09B7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* TCE1 - Timer/Counter E1 */
+#define TCE1_CTRLA _SFR_MEM8(0x0A40)
+#define TCE1_CTRLB _SFR_MEM8(0x0A41)
+#define TCE1_CTRLC _SFR_MEM8(0x0A42)
+#define TCE1_CTRLD _SFR_MEM8(0x0A43)
+#define TCE1_CTRLE _SFR_MEM8(0x0A44)
+#define TCE1_INTCTRLA _SFR_MEM8(0x0A46)
+#define TCE1_INTCTRLB _SFR_MEM8(0x0A47)
+#define TCE1_CTRLFCLR _SFR_MEM8(0x0A48)
+#define TCE1_CTRLFSET _SFR_MEM8(0x0A49)
+#define TCE1_CTRLGCLR _SFR_MEM8(0x0A4A)
+#define TCE1_CTRLGSET _SFR_MEM8(0x0A4B)
+#define TCE1_INTFLAGS _SFR_MEM8(0x0A4C)
+#define TCE1_TEMP _SFR_MEM8(0x0A4F)
+#define TCE1_CNT _SFR_MEM16(0x0A60)
+#define TCE1_PER _SFR_MEM16(0x0A66)
+#define TCE1_CCA _SFR_MEM16(0x0A68)
+#define TCE1_CCB _SFR_MEM16(0x0A6A)
+#define TCE1_PERBUF _SFR_MEM16(0x0A76)
+#define TCE1_CCABUF _SFR_MEM16(0x0A78)
+#define TCE1_CCBBUF _SFR_MEM16(0x0A7A)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEVMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* HIRESE - High-Resolution Extension E */
+#define HIRESE_CTRL _SFR_MEM8(0x0A90)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* USARTE1 - Universal Asynchronous Receiver-Transmitter E1 */
+#define USARTE1_DATA _SFR_MEM8(0x0AB0)
+#define USARTE1_STATUS _SFR_MEM8(0x0AB1)
+#define USARTE1_CTRLA _SFR_MEM8(0x0AB3)
+#define USARTE1_CTRLB _SFR_MEM8(0x0AB4)
+#define USARTE1_CTRLC _SFR_MEM8(0x0AB5)
+#define USARTE1_BAUDCTRLA _SFR_MEM8(0x0AB6)
+#define USARTE1_BAUDCTRLB _SFR_MEM8(0x0AB7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+/* HIRESF - High-Resolution Extension F */
+#define HIRESF_CTRL _SFR_MEM8(0x0B90)
+
+/* USARTF0 - Universal Asynchronous Receiver-Transmitter F0 */
+#define USARTF0_DATA _SFR_MEM8(0x0BA0)
+#define USARTF0_STATUS _SFR_MEM8(0x0BA1)
+#define USARTF0_CTRLA _SFR_MEM8(0x0BA3)
+#define USARTF0_CTRLB _SFR_MEM8(0x0BA4)
+#define USARTF0_CTRLC _SFR_MEM8(0x0BA5)
+#define USARTF0_BAUDCTRLA _SFR_MEM8(0x0BA6)
+#define USARTF0_BAUDCTRLB _SFR_MEM8(0x0BA7)
+
+/* USARTF1 - Universal Asynchronous Receiver-Transmitter F1 */
+#define USARTF1_DATA _SFR_MEM8(0x0BB0)
+#define USARTF1_STATUS _SFR_MEM8(0x0BB1)
+#define USARTF1_CTRLA _SFR_MEM8(0x0BB3)
+#define USARTF1_CTRLB _SFR_MEM8(0x0BB4)
+#define USARTF1_CTRLC _SFR_MEM8(0x0BB5)
+#define USARTF1_BAUDCTRLA _SFR_MEM8(0x0BB6)
+#define USARTF1_BAUDCTRLB _SFR_MEM8(0x0BB7)
+
+/* SPIF - Serial Peripheral Interface F */
+#define SPIF_CTRL _SFR_MEM8(0x0BC0)
+#define SPIF_INTCTRL _SFR_MEM8(0x0BC1)
+#define SPIF_STATUS _SFR_MEM8(0x0BC2)
+#define SPIF_DATA _SFR_MEM8(0x0BC3)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* DMA - DMA Controller */
+/* DMA_CH.CTRLA bit masks and bit positions */
+#define DMA_CH_ENABLE_bm 0x80 /* Channel Enable bit mask. */
+#define DMA_CH_ENABLE_bp 7 /* Channel Enable bit position. */
+
+#define DMA_CH_RESET_bm 0x40 /* Channel Software Reset bit mask. */
+#define DMA_CH_RESET_bp 6 /* Channel Software Reset bit position. */
+
+#define DMA_CH_REPEAT_bm 0x20 /* Channel Repeat Mode bit mask. */
+#define DMA_CH_REPEAT_bp 5 /* Channel Repeat Mode bit position. */
+
+#define DMA_CH_TRFREQ_bm 0x10 /* Channel Transfer Request bit mask. */
+#define DMA_CH_TRFREQ_bp 4 /* Channel Transfer Request bit position. */
+
+#define DMA_CH_SINGLE_bm 0x04 /* Channel Single Shot Data Transfer bit mask. */
+#define DMA_CH_SINGLE_bp 2 /* Channel Single Shot Data Transfer bit position. */
+
+#define DMA_CH_BURSTLEN_gm 0x03 /* Channel Transfer Mode group mask. */
+#define DMA_CH_BURSTLEN_gp 0 /* Channel Transfer Mode group position. */
+#define DMA_CH_BURSTLEN0_bm (1<<0) /* Channel Transfer Mode bit 0 mask. */
+#define DMA_CH_BURSTLEN0_bp 0 /* Channel Transfer Mode bit 0 position. */
+#define DMA_CH_BURSTLEN1_bm (1<<1) /* Channel Transfer Mode bit 1 mask. */
+#define DMA_CH_BURSTLEN1_bp 1 /* Channel Transfer Mode bit 1 position. */
+
+
+/* DMA_CH.CTRLB bit masks and bit positions */
+#define DMA_CH_CHBUSY_bm 0x80 /* Block Transfer Busy bit mask. */
+#define DMA_CH_CHBUSY_bp 7 /* Block Transfer Busy bit position. */
+
+#define DMA_CH_CHPEND_bm 0x40 /* Block Transfer Pending bit mask. */
+#define DMA_CH_CHPEND_bp 6 /* Block Transfer Pending bit position. */
+
+#define DMA_CH_ERRIF_bm 0x20 /* Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH_ERRIF_bp 5 /* Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH_TRNIF_bm 0x10 /* Transaction Complete Interrup Flag bit mask. */
+#define DMA_CH_TRNIF_bp 4 /* Transaction Complete Interrup Flag bit position. */
+
+#define DMA_CH_ERRINTLVL_gm 0x0C /* Transfer Error Interrupt Level group mask. */
+#define DMA_CH_ERRINTLVL_gp 2 /* Transfer Error Interrupt Level group position. */
+#define DMA_CH_ERRINTLVL0_bm (1<<2) /* Transfer Error Interrupt Level bit 0 mask. */
+#define DMA_CH_ERRINTLVL0_bp 2 /* Transfer Error Interrupt Level bit 0 position. */
+#define DMA_CH_ERRINTLVL1_bm (1<<3) /* Transfer Error Interrupt Level bit 1 mask. */
+#define DMA_CH_ERRINTLVL1_bp 3 /* Transfer Error Interrupt Level bit 1 position. */
+
+#define DMA_CH_TRNINTLVL_gm 0x03 /* Transaction Complete Interrupt Level group mask. */
+#define DMA_CH_TRNINTLVL_gp 0 /* Transaction Complete Interrupt Level group position. */
+#define DMA_CH_TRNINTLVL0_bm (1<<0) /* Transaction Complete Interrupt Level bit 0 mask. */
+#define DMA_CH_TRNINTLVL0_bp 0 /* Transaction Complete Interrupt Level bit 0 position. */
+#define DMA_CH_TRNINTLVL1_bm (1<<1) /* Transaction Complete Interrupt Level bit 1 mask. */
+#define DMA_CH_TRNINTLVL1_bp 1 /* Transaction Complete Interrupt Level bit 1 position. */
+
+
+/* DMA_CH.ADDRCTRL bit masks and bit positions */
+#define DMA_CH_SRCRELOAD_gm 0xC0 /* Channel Source Address Reload group mask. */
+#define DMA_CH_SRCRELOAD_gp 6 /* Channel Source Address Reload group position. */
+#define DMA_CH_SRCRELOAD0_bm (1<<6) /* Channel Source Address Reload bit 0 mask. */
+#define DMA_CH_SRCRELOAD0_bp 6 /* Channel Source Address Reload bit 0 position. */
+#define DMA_CH_SRCRELOAD1_bm (1<<7) /* Channel Source Address Reload bit 1 mask. */
+#define DMA_CH_SRCRELOAD1_bp 7 /* Channel Source Address Reload bit 1 position. */
+
+#define DMA_CH_SRCDIR_gm 0x30 /* Channel Source Address Mode group mask. */
+#define DMA_CH_SRCDIR_gp 4 /* Channel Source Address Mode group position. */
+#define DMA_CH_SRCDIR0_bm (1<<4) /* Channel Source Address Mode bit 0 mask. */
+#define DMA_CH_SRCDIR0_bp 4 /* Channel Source Address Mode bit 0 position. */
+#define DMA_CH_SRCDIR1_bm (1<<5) /* Channel Source Address Mode bit 1 mask. */
+#define DMA_CH_SRCDIR1_bp 5 /* Channel Source Address Mode bit 1 position. */
+
+#define DMA_CH_DESTRELOAD_gm 0x0C /* Channel Destination Address Reload group mask. */
+#define DMA_CH_DESTRELOAD_gp 2 /* Channel Destination Address Reload group position. */
+#define DMA_CH_DESTRELOAD0_bm (1<<2) /* Channel Destination Address Reload bit 0 mask. */
+#define DMA_CH_DESTRELOAD0_bp 2 /* Channel Destination Address Reload bit 0 position. */
+#define DMA_CH_DESTRELOAD1_bm (1<<3) /* Channel Destination Address Reload bit 1 mask. */
+#define DMA_CH_DESTRELOAD1_bp 3 /* Channel Destination Address Reload bit 1 position. */
+
+#define DMA_CH_DESTDIR_gm 0x03 /* Channel Destination Address Mode group mask. */
+#define DMA_CH_DESTDIR_gp 0 /* Channel Destination Address Mode group position. */
+#define DMA_CH_DESTDIR0_bm (1<<0) /* Channel Destination Address Mode bit 0 mask. */
+#define DMA_CH_DESTDIR0_bp 0 /* Channel Destination Address Mode bit 0 position. */
+#define DMA_CH_DESTDIR1_bm (1<<1) /* Channel Destination Address Mode bit 1 mask. */
+#define DMA_CH_DESTDIR1_bp 1 /* Channel Destination Address Mode bit 1 position. */
+
+
+/* DMA_CH.TRIGSRC bit masks and bit positions */
+#define DMA_CH_TRIGSRC_gm 0xFF /* Channel Trigger Source group mask. */
+#define DMA_CH_TRIGSRC_gp 0 /* Channel Trigger Source group position. */
+#define DMA_CH_TRIGSRC0_bm (1<<0) /* Channel Trigger Source bit 0 mask. */
+#define DMA_CH_TRIGSRC0_bp 0 /* Channel Trigger Source bit 0 position. */
+#define DMA_CH_TRIGSRC1_bm (1<<1) /* Channel Trigger Source bit 1 mask. */
+#define DMA_CH_TRIGSRC1_bp 1 /* Channel Trigger Source bit 1 position. */
+#define DMA_CH_TRIGSRC2_bm (1<<2) /* Channel Trigger Source bit 2 mask. */
+#define DMA_CH_TRIGSRC2_bp 2 /* Channel Trigger Source bit 2 position. */
+#define DMA_CH_TRIGSRC3_bm (1<<3) /* Channel Trigger Source bit 3 mask. */
+#define DMA_CH_TRIGSRC3_bp 3 /* Channel Trigger Source bit 3 position. */
+#define DMA_CH_TRIGSRC4_bm (1<<4) /* Channel Trigger Source bit 4 mask. */
+#define DMA_CH_TRIGSRC4_bp 4 /* Channel Trigger Source bit 4 position. */
+#define DMA_CH_TRIGSRC5_bm (1<<5) /* Channel Trigger Source bit 5 mask. */
+#define DMA_CH_TRIGSRC5_bp 5 /* Channel Trigger Source bit 5 position. */
+#define DMA_CH_TRIGSRC6_bm (1<<6) /* Channel Trigger Source bit 6 mask. */
+#define DMA_CH_TRIGSRC6_bp 6 /* Channel Trigger Source bit 6 position. */
+#define DMA_CH_TRIGSRC7_bm (1<<7) /* Channel Trigger Source bit 7 mask. */
+#define DMA_CH_TRIGSRC7_bp 7 /* Channel Trigger Source bit 7 position. */
+
+
+/* DMA.CTRL bit masks and bit positions */
+#define DMA_ENABLE_bm 0x80 /* Enable bit mask. */
+#define DMA_ENABLE_bp 7 /* Enable bit position. */
+
+#define DMA_RESET_bm 0x40 /* Software Reset bit mask. */
+#define DMA_RESET_bp 6 /* Software Reset bit position. */
+
+#define DMA_DBUFMODE_gm 0x0C /* Double Buffering Mode group mask. */
+#define DMA_DBUFMODE_gp 2 /* Double Buffering Mode group position. */
+#define DMA_DBUFMODE0_bm (1<<2) /* Double Buffering Mode bit 0 mask. */
+#define DMA_DBUFMODE0_bp 2 /* Double Buffering Mode bit 0 position. */
+#define DMA_DBUFMODE1_bm (1<<3) /* Double Buffering Mode bit 1 mask. */
+#define DMA_DBUFMODE1_bp 3 /* Double Buffering Mode bit 1 position. */
+
+#define DMA_PRIMODE_gm 0x03 /* Channel Priority Mode group mask. */
+#define DMA_PRIMODE_gp 0 /* Channel Priority Mode group position. */
+#define DMA_PRIMODE0_bm (1<<0) /* Channel Priority Mode bit 0 mask. */
+#define DMA_PRIMODE0_bp 0 /* Channel Priority Mode bit 0 position. */
+#define DMA_PRIMODE1_bm (1<<1) /* Channel Priority Mode bit 1 mask. */
+#define DMA_PRIMODE1_bp 1 /* Channel Priority Mode bit 1 position. */
+
+
+/* DMA.INTFLAGS bit masks and bit positions */
+#define DMA_CH3ERRIF_bm 0x80 /* Channel 3 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH3ERRIF_bp 7 /* Channel 3 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH2ERRIF_bm 0x40 /* Channel 2 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH2ERRIF_bp 6 /* Channel 2 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH1ERRIF_bm 0x20 /* Channel 1 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH1ERRIF_bp 5 /* Channel 1 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH0ERRIF_bm 0x10 /* Channel 0 Block Transfer Error Interrupt Flag bit mask. */
+#define DMA_CH0ERRIF_bp 4 /* Channel 0 Block Transfer Error Interrupt Flag bit position. */
+
+#define DMA_CH3TRNIF_bm 0x08 /* Channel 3 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH3TRNIF_bp 3 /* Channel 3 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH2TRNIF_bm 0x04 /* Channel 2 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH2TRNIF_bp 2 /* Channel 2 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH1TRNIF_bm 0x02 /* Channel 1 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH1TRNIF_bp 1 /* Channel 1 Transaction Complete Interrupt Flag bit position. */
+
+#define DMA_CH0TRNIF_bm 0x01 /* Channel 0 Transaction Complete Interrupt Flag bit mask. */
+#define DMA_CH0TRNIF_bp 0 /* Channel 0 Transaction Complete Interrupt Flag bit position. */
+
+
+/* DMA.STATUS bit masks and bit positions */
+#define DMA_CH3BUSY_bm 0x80 /* Channel 3 Block Transfer Busy bit mask. */
+#define DMA_CH3BUSY_bp 7 /* Channel 3 Block Transfer Busy bit position. */
+
+#define DMA_CH2BUSY_bm 0x40 /* Channel 2 Block Transfer Busy bit mask. */
+#define DMA_CH2BUSY_bp 6 /* Channel 2 Block Transfer Busy bit position. */
+
+#define DMA_CH1BUSY_bm 0x20 /* Channel 1 Block Transfer Busy bit mask. */
+#define DMA_CH1BUSY_bp 5 /* Channel 1 Block Transfer Busy bit position. */
+
+#define DMA_CH0BUSY_bm 0x10 /* Channel 0 Block Transfer Busy bit mask. */
+#define DMA_CH0BUSY_bp 4 /* Channel 0 Block Transfer Busy bit position. */
+
+#define DMA_CH3PEND_bm 0x08 /* Channel 3 Block Transfer Pending bit mask. */
+#define DMA_CH3PEND_bp 3 /* Channel 3 Block Transfer Pending bit position. */
+
+#define DMA_CH2PEND_bm 0x04 /* Channel 2 Block Transfer Pending bit mask. */
+#define DMA_CH2PEND_bp 2 /* Channel 2 Block Transfer Pending bit position. */
+
+#define DMA_CH1PEND_bm 0x02 /* Channel 1 Block Transfer Pending bit mask. */
+#define DMA_CH1PEND_bp 1 /* Channel 1 Block Transfer Pending bit position. */
+
+#define DMA_CH0PEND_bm 0x01 /* Channel 0 Block Transfer Pending bit mask. */
+#define DMA_CH0PEND_bp 0 /* Channel 0 Block Transfer Pending bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH4MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH5MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH6MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH7MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH4CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH5CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH6CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH7CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_JTAGUSERID_gm 0xFF /* JTAG User ID group mask. */
+#define NVM_FUSES_JTAGUSERID_gp 0 /* JTAG User ID group position. */
+#define NVM_FUSES_JTAGUSERID0_bm (1<<0) /* JTAG User ID bit 0 mask. */
+#define NVM_FUSES_JTAGUSERID0_bp 0 /* JTAG User ID bit 0 position. */
+#define NVM_FUSES_JTAGUSERID1_bm (1<<1) /* JTAG User ID bit 1 mask. */
+#define NVM_FUSES_JTAGUSERID1_bp 1 /* JTAG User ID bit 1 position. */
+#define NVM_FUSES_JTAGUSERID2_bm (1<<2) /* JTAG User ID bit 2 mask. */
+#define NVM_FUSES_JTAGUSERID2_bp 2 /* JTAG User ID bit 2 position. */
+#define NVM_FUSES_JTAGUSERID3_bm (1<<3) /* JTAG User ID bit 3 mask. */
+#define NVM_FUSES_JTAGUSERID3_bp 3 /* JTAG User ID bit 3 position. */
+#define NVM_FUSES_JTAGUSERID4_bm (1<<4) /* JTAG User ID bit 4 mask. */
+#define NVM_FUSES_JTAGUSERID4_bp 4 /* JTAG User ID bit 4 position. */
+#define NVM_FUSES_JTAGUSERID5_bm (1<<5) /* JTAG User ID bit 5 mask. */
+#define NVM_FUSES_JTAGUSERID5_bp 5 /* JTAG User ID bit 5 position. */
+#define NVM_FUSES_JTAGUSERID6_bm (1<<6) /* JTAG User ID bit 6 mask. */
+#define NVM_FUSES_JTAGUSERID6_bp 6 /* JTAG User ID bit 6 position. */
+#define NVM_FUSES_JTAGUSERID7_bm (1<<7) /* JTAG User ID bit 7 mask. */
+#define NVM_FUSES_JTAGUSERID7_bp 7 /* JTAG User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+#define NVM_FUSES_JTAGEN_bm 0x01 /* JTAG Interface Enable bit mask. */
+#define NVM_FUSES_JTAGEN_bp 0 /* JTAG Interface Enable bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_DMASEL_gm 0xC0 /* DMA Selection group mask. */
+#define ADC_DMASEL_gp 6 /* DMA Selection group position. */
+#define ADC_DMASEL0_bm (1<<6) /* DMA Selection bit 0 mask. */
+#define ADC_DMASEL0_bp 6 /* DMA Selection bit 0 position. */
+#define ADC_DMASEL1_bm (1<<7) /* DMA Selection bit 1 mask. */
+#define ADC_DMASEL1_bp 7 /* DMA Selection bit 1 position. */
+
+#define ADC_CH3START_bm 0x20 /* Channel 3 Start Conversion bit mask. */
+#define ADC_CH3START_bp 5 /* Channel 3 Start Conversion bit position. */
+
+#define ADC_CH2START_bm 0x10 /* Channel 2 Start Conversion bit mask. */
+#define ADC_CH2START_bp 4 /* Channel 2 Start Conversion bit position. */
+
+#define ADC_CH1START_bm 0x08 /* Channel 1 Start Conversion bit mask. */
+#define ADC_CH1START_bp 3 /* Channel 1 Start Conversion bit position. */
+
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_FLUSH_bm 0x02 /* Flush Pipeline bit mask. */
+#define ADC_FLUSH_bp 1 /* Flush Pipeline bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH3IF_bm 0x08 /* Channel 3 Interrupt Flag bit mask. */
+#define ADC_CH3IF_bp 3 /* Channel 3 Interrupt Flag bit position. */
+
+#define ADC_CH2IF_bm 0x04 /* Channel 2 Interrupt Flag bit mask. */
+#define ADC_CH2IF_bp 2 /* Channel 2 Interrupt Flag bit position. */
+
+#define ADC_CH1IF_bm 0x02 /* Channel 1 Interrupt Flag bit mask. */
+#define ADC_CH1IF_bp 1 /* Channel 1 Interrupt Flag bit position. */
+
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* DAC - Digital/Analog Converter */
+/* DAC.CTRLA bit masks and bit positions */
+#define DAC_IDOEN_bm 0x10 /* Internal Output Enable bit mask. */
+#define DAC_IDOEN_bp 4 /* Internal Output Enable bit position. */
+
+#define DAC_CH1EN_bm 0x08 /* Channel 1 Output Enable bit mask. */
+#define DAC_CH1EN_bp 3 /* Channel 1 Output Enable bit position. */
+
+#define DAC_CH0EN_bm 0x04 /* Channel 0 Output Enable bit mask. */
+#define DAC_CH0EN_bp 2 /* Channel 0 Output Enable bit position. */
+
+#define DAC_LPMODE_bm 0x02 /* Low Power Mode bit mask. */
+#define DAC_LPMODE_bp 1 /* Low Power Mode bit position. */
+
+#define DAC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define DAC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* DAC.CTRLB bit masks and bit positions */
+#define DAC_CHSEL_gm 0x60 /* Channel Select group mask. */
+#define DAC_CHSEL_gp 5 /* Channel Select group position. */
+#define DAC_CHSEL0_bm (1<<5) /* Channel Select bit 0 mask. */
+#define DAC_CHSEL0_bp 5 /* Channel Select bit 0 position. */
+#define DAC_CHSEL1_bm (1<<6) /* Channel Select bit 1 mask. */
+#define DAC_CHSEL1_bp 6 /* Channel Select bit 1 position. */
+
+#define DAC_CH1TRIG_bm 0x02 /* Channel 1 Event Trig Enable bit mask. */
+#define DAC_CH1TRIG_bp 1 /* Channel 1 Event Trig Enable bit position. */
+
+#define DAC_CH0TRIG_bm 0x01 /* Channel 0 Event Trig Enable bit mask. */
+#define DAC_CH0TRIG_bp 0 /* Channel 0 Event Trig Enable bit position. */
+
+
+/* DAC.CTRLC bit masks and bit positions */
+#define DAC_REFSEL_gm 0x18 /* Reference Select group mask. */
+#define DAC_REFSEL_gp 3 /* Reference Select group position. */
+#define DAC_REFSEL0_bm (1<<3) /* Reference Select bit 0 mask. */
+#define DAC_REFSEL0_bp 3 /* Reference Select bit 0 position. */
+#define DAC_REFSEL1_bm (1<<4) /* Reference Select bit 1 mask. */
+#define DAC_REFSEL1_bp 4 /* Reference Select bit 1 position. */
+
+#define DAC_LEFTADJ_bm 0x01 /* Left-adjust Result bit mask. */
+#define DAC_LEFTADJ_bp 0 /* Left-adjust Result bit position. */
+
+
+/* DAC.EVCTRL bit masks and bit positions */
+#define DAC_EVSEL_gm 0x07 /* Event Input Selection group mask. */
+#define DAC_EVSEL_gp 0 /* Event Input Selection group position. */
+#define DAC_EVSEL0_bm (1<<0) /* Event Input Selection bit 0 mask. */
+#define DAC_EVSEL0_bp 0 /* Event Input Selection bit 0 position. */
+#define DAC_EVSEL1_bm (1<<1) /* Event Input Selection bit 1 mask. */
+#define DAC_EVSEL1_bp 1 /* Event Input Selection bit 1 position. */
+#define DAC_EVSEL2_bm (1<<2) /* Event Input Selection bit 2 mask. */
+#define DAC_EVSEL2_bp 2 /* Event Input Selection bit 2 position. */
+
+
+/* DAC.TIMCTRL bit masks and bit positions */
+#define DAC_CONINTVAL_gm 0x70 /* Conversion Intercal group mask. */
+#define DAC_CONINTVAL_gp 4 /* Conversion Intercal group position. */
+#define DAC_CONINTVAL0_bm (1<<4) /* Conversion Intercal bit 0 mask. */
+#define DAC_CONINTVAL0_bp 4 /* Conversion Intercal bit 0 position. */
+#define DAC_CONINTVAL1_bm (1<<5) /* Conversion Intercal bit 1 mask. */
+#define DAC_CONINTVAL1_bp 5 /* Conversion Intercal bit 1 position. */
+#define DAC_CONINTVAL2_bm (1<<6) /* Conversion Intercal bit 2 mask. */
+#define DAC_CONINTVAL2_bp 6 /* Conversion Intercal bit 2 position. */
+
+#define DAC_REFRESH_gm 0x0F /* Refresh Timing Control group mask. */
+#define DAC_REFRESH_gp 0 /* Refresh Timing Control group position. */
+#define DAC_REFRESH0_bm (1<<0) /* Refresh Timing Control bit 0 mask. */
+#define DAC_REFRESH0_bp 0 /* Refresh Timing Control bit 0 position. */
+#define DAC_REFRESH1_bm (1<<1) /* Refresh Timing Control bit 1 mask. */
+#define DAC_REFRESH1_bp 1 /* Refresh Timing Control bit 1 position. */
+#define DAC_REFRESH2_bm (1<<2) /* Refresh Timing Control bit 2 mask. */
+#define DAC_REFRESH2_bp 2 /* Refresh Timing Control bit 2 position. */
+#define DAC_REFRESH3_bm (1<<3) /* Refresh Timing Control bit 3 mask. */
+#define DAC_REFRESH3_bp 3 /* Refresh Timing Control bit 3 position. */
+
+
+/* DAC.STATUS bit masks and bit positions */
+#define DAC_CH1DRE_bm 0x02 /* Channel 1 Data Register Empty bit mask. */
+#define DAC_CH1DRE_bp 1 /* Channel 1 Data Register Empty bit position. */
+
+#define DAC_CH0DRE_bm 0x01 /* Channel 0 Data Register Empty bit mask. */
+#define DAC_CH0DRE_bp 0 /* Channel 0 Data Register Empty bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC0_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_DTHM_bm 0x02 /* Dead Time Hold Mode bit mask. */
+#define TC1_DTHM_bp 1 /* Dead Time Hold Mode bit position. */
+
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRL bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+/* AES - AES Module */
+/* AES.CTRL bit masks and bit positions */
+#define AES_START_bm 0x80 /* Start/Run bit mask. */
+#define AES_START_bp 7 /* Start/Run bit position. */
+
+#define AES_AUTO_bm 0x40 /* Auto Start Trigger bit mask. */
+#define AES_AUTO_bp 6 /* Auto Start Trigger bit position. */
+
+#define AES_RESET_bm 0x20 /* AES Software Reset bit mask. */
+#define AES_RESET_bp 5 /* AES Software Reset bit position. */
+
+#define AES_DECRYPT_bm 0x10 /* Decryption / Direction bit mask. */
+#define AES_DECRYPT_bp 4 /* Decryption / Direction bit position. */
+
+#define AES_XOR_bm 0x04 /* State XOR Load Enable bit mask. */
+#define AES_XOR_bp 2 /* State XOR Load Enable bit position. */
+
+
+/* AES.STATUS bit masks and bit positions */
+#define AES_ERROR_bm 0x80 /* AES Error bit mask. */
+#define AES_ERROR_bp 7 /* AES Error bit position. */
+
+#define AES_SRIF_bm 0x01 /* State Ready Interrupt Flag bit mask. */
+#define AES_SRIF_bp 0 /* State Ready Interrupt Flag bit position. */
+
+
+/* AES.INTCTRL bit masks and bit positions */
+#define AES_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define AES_INTLVL_gp 0 /* Interrupt level group position. */
+#define AES_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define AES_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define AES_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define AES_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* DMA interrupt vectors */
+#define DMA_CH0_vect_num 6
+#define DMA_CH0_vect _VECTOR(6) /* Channel 0 Interrupt */
+#define DMA_CH1_vect_num 7
+#define DMA_CH1_vect _VECTOR(7) /* Channel 1 Interrupt */
+#define DMA_CH2_vect_num 8
+#define DMA_CH2_vect _VECTOR(8) /* Channel 2 Interrupt */
+#define DMA_CH3_vect_num 9
+#define DMA_CH3_vect _VECTOR(9) /* Channel 3 Interrupt */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* USARTC1 interrupt vectors */
+#define USARTC1_RXC_vect_num 28
+#define USARTC1_RXC_vect _VECTOR(28) /* Reception Complete Interrupt */
+#define USARTC1_DRE_vect_num 29
+#define USARTC1_DRE_vect _VECTOR(29) /* Data Register Empty Interrupt */
+#define USARTC1_TXC_vect_num 30
+#define USARTC1_TXC_vect _VECTOR(30) /* Transmission Complete Interrupt */
+
+/* AES interrupt vectors */
+#define AES_INT_vect_num 31
+#define AES_INT_vect _VECTOR(31) /* AES Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* ACB interrupt vectors */
+#define ACB_AC0_vect_num 36
+#define ACB_AC0_vect _VECTOR(36) /* AC0 Interrupt */
+#define ACB_AC1_vect_num 37
+#define ACB_AC1_vect _VECTOR(37) /* AC1 Interrupt */
+#define ACB_ACW_vect_num 38
+#define ACB_ACW_vect _VECTOR(38) /* ACW Window Mode Interrupt */
+
+/* ADCB interrupt vectors */
+#define ADCB_CH0_vect_num 39
+#define ADCB_CH0_vect _VECTOR(39) /* Interrupt 0 */
+#define ADCB_CH1_vect_num 40
+#define ADCB_CH1_vect _VECTOR(40) /* Interrupt 1 */
+#define ADCB_CH2_vect_num 41
+#define ADCB_CH2_vect _VECTOR(41) /* Interrupt 2 */
+#define ADCB_CH3_vect_num 42
+#define ADCB_CH3_vect _VECTOR(42) /* Interrupt 3 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TWIE interrupt vectors */
+#define TWIE_TWIS_vect_num 45
+#define TWIE_TWIS_vect _VECTOR(45) /* TWI Slave Interrupt */
+#define TWIE_TWIM_vect_num 46
+#define TWIE_TWIM_vect _VECTOR(46) /* TWI Master Interrupt */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* TCE1 interrupt vectors */
+#define TCE1_OVF_vect_num 53
+#define TCE1_OVF_vect _VECTOR(53) /* Overflow Interrupt */
+#define TCE1_ERR_vect_num 54
+#define TCE1_ERR_vect _VECTOR(54) /* Error Interrupt */
+#define TCE1_CCA_vect_num 55
+#define TCE1_CCA_vect _VECTOR(55) /* Compare or Capture A Interrupt */
+#define TCE1_CCB_vect_num 56
+#define TCE1_CCB_vect _VECTOR(56) /* Compare or Capture B Interrupt */
+
+/* SPIE interrupt vectors */
+#define SPIE_INT_vect_num 57
+#define SPIE_INT_vect _VECTOR(57) /* SPI Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* USARTE1 interrupt vectors */
+#define USARTE1_RXC_vect_num 61
+#define USARTE1_RXC_vect _VECTOR(61) /* Reception Complete Interrupt */
+#define USARTE1_DRE_vect_num 62
+#define USARTE1_DRE_vect _VECTOR(62) /* Data Register Empty Interrupt */
+#define USARTE1_TXC_vect_num 63
+#define USARTE1_TXC_vect _VECTOR(63) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+#define ADCA_CH1_vect_num 72
+#define ADCA_CH1_vect _VECTOR(72) /* Interrupt 1 */
+#define ADCA_CH2_vect_num 73
+#define ADCA_CH2_vect _VECTOR(73) /* Interrupt 2 */
+#define ADCA_CH3_vect_num 74
+#define ADCA_CH3_vect _VECTOR(74) /* Interrupt 3 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* TCD1 interrupt vectors */
+#define TCD1_OVF_vect_num 83
+#define TCD1_OVF_vect _VECTOR(83) /* Overflow Interrupt */
+#define TCD1_ERR_vect_num 84
+#define TCD1_ERR_vect _VECTOR(84) /* Error Interrupt */
+#define TCD1_CCA_vect_num 85
+#define TCD1_CCA_vect _VECTOR(85) /* Compare or Capture A Interrupt */
+#define TCD1_CCB_vect_num 86
+#define TCD1_CCB_vect _VECTOR(86) /* Compare or Capture B Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* USARTD1 interrupt vectors */
+#define USARTD1_RXC_vect_num 91
+#define USARTD1_RXC_vect _VECTOR(91) /* Reception Complete Interrupt */
+#define USARTD1_DRE_vect_num 92
+#define USARTD1_DRE_vect _VECTOR(92) /* Data Register Empty Interrupt */
+#define USARTD1_TXC_vect_num 93
+#define USARTD1_TXC_vect _VECTOR(93) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+/* USARTF0 interrupt vectors */
+#define USARTF0_RXC_vect_num 119
+#define USARTF0_RXC_vect _VECTOR(119) /* Reception Complete Interrupt */
+#define USARTF0_DRE_vect_num 120
+#define USARTF0_DRE_vect _VECTOR(120) /* Data Register Empty Interrupt */
+#define USARTF0_TXC_vect_num 121
+#define USARTF0_TXC_vect _VECTOR(121) /* Transmission Complete Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (122 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (69632)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (65536)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x0F000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x10000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (12288)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (4096)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_JTAGUSERID0 (unsigned char)~_BV(0) /* JTAG User ID Bit 0 */
+#define FUSE_JTAGUSERID1 (unsigned char)~_BV(1) /* JTAG User ID Bit 1 */
+#define FUSE_JTAGUSERID2 (unsigned char)~_BV(2) /* JTAG User ID Bit 2 */
+#define FUSE_JTAGUSERID3 (unsigned char)~_BV(3) /* JTAG User ID Bit 3 */
+#define FUSE_JTAGUSERID4 (unsigned char)~_BV(4) /* JTAG User ID Bit 4 */
+#define FUSE_JTAGUSERID5 (unsigned char)~_BV(5) /* JTAG User ID Bit 5 */
+#define FUSE_JTAGUSERID6 (unsigned char)~_BV(6) /* JTAG User ID Bit 6 */
+#define FUSE_JTAGUSERID7 (unsigned char)~_BV(7) /* JTAG User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_JTAGEN (unsigned char)~_BV(0) /* JTAG Interface Enable */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x42
+
+
+#endif /* _AVR_ATxmega64A3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/iox64d3.h b/cpukit/score/cpu/avr/avr/iox64d3.h
new file mode 100644
index 0000000000..9c9748c059
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/iox64d3.h
@@ -0,0 +1,5660 @@
+/* Copyright (c) 2009 Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/iox64d3.h - definitions for ATxmega64D3 */
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+#ifndef _AVR_IOXXX_H_
+# define _AVR_IOXXX_H_ "iox64d3.h"
+#else
+# error "Attempt to include more than one <avr/ioXXX.h> file."
+#endif
+
+
+#ifndef _AVR_ATxmega64D3_H_
+#define _AVR_ATxmega64D3_H_ 1
+
+
+/* Ungrouped common registers */
+#define GPIOR0 _SFR_MEM8(0x0000) /* General Purpose IO Register 0 */
+#define GPIOR1 _SFR_MEM8(0x0001) /* General Purpose IO Register 1 */
+#define GPIOR2 _SFR_MEM8(0x0002) /* General Purpose IO Register 2 */
+#define GPIOR3 _SFR_MEM8(0x0003) /* General Purpose IO Register 3 */
+#define GPIOR4 _SFR_MEM8(0x0004) /* General Purpose IO Register 4 */
+#define GPIOR5 _SFR_MEM8(0x0005) /* General Purpose IO Register 5 */
+#define GPIOR6 _SFR_MEM8(0x0006) /* General Purpose IO Register 6 */
+#define GPIOR7 _SFR_MEM8(0x0007) /* General Purpose IO Register 7 */
+#define GPIOR8 _SFR_MEM8(0x0008) /* General Purpose IO Register 8 */
+#define GPIOR9 _SFR_MEM8(0x0009) /* General Purpose IO Register 9 */
+#define GPIORA _SFR_MEM8(0x000A) /* General Purpose IO Register 10 */
+#define GPIORB _SFR_MEM8(0x000B) /* General Purpose IO Register 11 */
+#define GPIORC _SFR_MEM8(0x000C) /* General Purpose IO Register 12 */
+#define GPIORD _SFR_MEM8(0x000D) /* General Purpose IO Register 13 */
+#define GPIORE _SFR_MEM8(0x000E) /* General Purpose IO Register 14 */
+#define GPIORF _SFR_MEM8(0x000F) /* General Purpose IO Register 15 */
+
+#define CCP _SFR_MEM8(0x0034) /* Configuration Change Protection */
+#define RAMPD _SFR_MEM8(0x0038) /* Ramp D */
+#define RAMPX _SFR_MEM8(0x0039) /* Ramp X */
+#define RAMPY _SFR_MEM8(0x003A) /* Ramp Y */
+#define RAMPZ _SFR_MEM8(0x003B) /* Ramp Z */
+#define EIND _SFR_MEM8(0x003C) /* Extended Indirect Jump */
+#define SPL _SFR_MEM8(0x003D) /* Stack Pointer Low */
+#define SPH _SFR_MEM8(0x003E) /* Stack Pointer High */
+#define SREG _SFR_MEM8(0x003F) /* Status Register */
+
+
+/* C Language Only */
+#if !defined (__ASSEMBLER__)
+
+#include <stdint.h>
+
+typedef volatile uint8_t register8_t;
+typedef volatile uint16_t register16_t;
+typedef volatile uint32_t register32_t;
+
+
+#ifdef _WORDREGISTER
+#undef _WORDREGISTER
+#endif
+#define _WORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register16_t regname; \
+ struct \
+ { \
+ register8_t regname ## L; \
+ register8_t regname ## H; \
+ }; \
+ }
+
+#ifdef _DWORDREGISTER
+#undef _DWORDREGISTER
+#endif
+#define _DWORDREGISTER(regname) \
+ __extension__ union \
+ { \
+ register32_t regname; \
+ struct \
+ { \
+ register8_t regname ## 0; \
+ register8_t regname ## 1; \
+ register8_t regname ## 2; \
+ register8_t regname ## 3; \
+ }; \
+ }
+
+
+/*
+==========================================================================
+IO Module Structures
+==========================================================================
+*/
+
+
+/*
+--------------------------------------------------------------------------
+XOCD - On-Chip Debug System
+--------------------------------------------------------------------------
+*/
+
+/* On-Chip Debug System */
+typedef struct OCD_struct
+{
+ register8_t OCDR0; /* OCD Register 0 */
+ register8_t OCDR1; /* OCD Register 1 */
+} OCD_t;
+
+
+/* CCP signatures */
+typedef enum CCP_enum
+{
+ CCP_SPM_gc = (0x9D<<0), /* SPM Instruction Protection */
+ CCP_IOREG_gc = (0xD8<<0), /* IO Register Protection */
+} CCP_t;
+
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Clock System */
+typedef struct CLK_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t PSCTRL; /* Prescaler Control Register */
+ register8_t LOCK; /* Lock register */
+ register8_t RTCCTRL; /* RTC Control Register */
+} CLK_t;
+
+/*
+--------------------------------------------------------------------------
+CLK - Clock System
+--------------------------------------------------------------------------
+*/
+
+/* Power Reduction */
+typedef struct PR_struct
+{
+ register8_t PRGEN; /* General Power Reduction */
+ register8_t PRPA; /* Power Reduction Port A */
+ register8_t PRPB; /* Power Reduction Port B */
+ register8_t PRPC; /* Power Reduction Port C */
+ register8_t PRPD; /* Power Reduction Port D */
+ register8_t PRPE; /* Power Reduction Port E */
+ register8_t PRPF; /* Power Reduction Port F */
+} PR_t;
+
+/* System Clock Selection */
+typedef enum CLK_SCLKSEL_enum
+{
+ CLK_SCLKSEL_RC2M_gc = (0x00<<0), /* Internal 2MHz RC Oscillator */
+ CLK_SCLKSEL_RC32M_gc = (0x01<<0), /* Internal 32MHz RC Oscillator */
+ CLK_SCLKSEL_RC32K_gc = (0x02<<0), /* Internal 32kHz RC Oscillator */
+ CLK_SCLKSEL_XOSC_gc = (0x03<<0), /* External Crystal Oscillator or Clock */
+ CLK_SCLKSEL_PLL_gc = (0x04<<0), /* Phase Locked Loop */
+} CLK_SCLKSEL_t;
+
+/* Prescaler A Division Factor */
+typedef enum CLK_PSADIV_enum
+{
+ CLK_PSADIV_1_gc = (0x00<<2), /* Divide by 1 */
+ CLK_PSADIV_2_gc = (0x01<<2), /* Divide by 2 */
+ CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */
+ CLK_PSADIV_8_gc = (0x05<<2), /* Divide by 8 */
+ CLK_PSADIV_16_gc = (0x07<<2), /* Divide by 16 */
+ CLK_PSADIV_32_gc = (0x09<<2), /* Divide by 32 */
+ CLK_PSADIV_64_gc = (0x0B<<2), /* Divide by 64 */
+ CLK_PSADIV_128_gc = (0x0D<<2), /* Divide by 128 */
+ CLK_PSADIV_256_gc = (0x0F<<2), /* Divide by 256 */
+ CLK_PSADIV_512_gc = (0x11<<2), /* Divide by 512 */
+} CLK_PSADIV_t;
+
+/* Prescaler B and C Division Factor */
+typedef enum CLK_PSBCDIV_enum
+{
+ CLK_PSBCDIV_1_1_gc = (0x00<<0), /* Divide B by 1 and C by 1 */
+ CLK_PSBCDIV_1_2_gc = (0x01<<0), /* Divide B by 1 and C by 2 */
+ CLK_PSBCDIV_4_1_gc = (0x02<<0), /* Divide B by 4 and C by 1 */
+ CLK_PSBCDIV_2_2_gc = (0x03<<0), /* Divide B by 2 and C by 2 */
+} CLK_PSBCDIV_t;
+
+/* RTC Clock Source */
+typedef enum CLK_RTCSRC_enum
+{
+ CLK_RTCSRC_ULP_gc = (0x00<<1), /* 1kHz from internal 32kHz ULP */
+ CLK_RTCSRC_TOSC_gc = (0x01<<1), /* 1kHz from 32kHz crystal oscillator on TOSC */
+ CLK_RTCSRC_RCOSC_gc = (0x02<<1), /* 1kHz from internal 32kHz RC oscillator */
+ CLK_RTCSRC_TOSC32_gc = (0x05<<1), /* 32kHz from 32kHz crystal oscillator on TOSC */
+} CLK_RTCSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+SLEEP - Sleep Controller
+--------------------------------------------------------------------------
+*/
+
+/* Sleep Controller */
+typedef struct SLEEP_struct
+{
+ register8_t CTRL; /* Control Register */
+} SLEEP_t;
+
+/* Sleep Mode */
+typedef enum SLEEP_SMODE_enum
+{
+ SLEEP_SMODE_IDLE_gc = (0x00<<1), /* Idle mode */
+ SLEEP_SMODE_PDOWN_gc = (0x02<<1), /* Power-down Mode */
+ SLEEP_SMODE_PSAVE_gc = (0x03<<1), /* Power-save Mode */
+ SLEEP_SMODE_STDBY_gc = (0x06<<1), /* Standby Mode */
+ SLEEP_SMODE_ESTDBY_gc = (0x07<<1), /* Extended Standby Mode */
+} SLEEP_SMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+OSC - Oscillator
+--------------------------------------------------------------------------
+*/
+
+/* Oscillator */
+typedef struct OSC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t XOSCCTRL; /* External Oscillator Control Register */
+ register8_t XOSCFAIL; /* External Oscillator Failure Detection Register */
+ register8_t RC32KCAL; /* 32kHz Internal Oscillator Calibration Register */
+ register8_t PLLCTRL; /* PLL Control REgister */
+ register8_t DFLLCTRL; /* DFLL Control Register */
+} OSC_t;
+
+/* Oscillator Frequency Range */
+typedef enum OSC_FRQRANGE_enum
+{
+ OSC_FRQRANGE_04TO2_gc = (0x00<<6), /* 0.4 - 2 MHz */
+ OSC_FRQRANGE_2TO9_gc = (0x01<<6), /* 2 - 9 MHz */
+ OSC_FRQRANGE_9TO12_gc = (0x02<<6), /* 9 - 12 MHz */
+ OSC_FRQRANGE_12TO16_gc = (0x03<<6), /* 12 - 16 MHz */
+} OSC_FRQRANGE_t;
+
+/* External Oscillator Selection and Startup Time */
+typedef enum OSC_XOSCSEL_enum
+{
+ OSC_XOSCSEL_EXTCLK_gc = (0x00<<0), /* External Clock - 6 CLK */
+ OSC_XOSCSEL_32KHz_gc = (0x02<<0), /* 32kHz TOSC - 32K CLK */
+ OSC_XOSCSEL_XTAL_256CLK_gc = (0x03<<0), /* 0.4-16MHz XTAL - 256 CLK */
+ OSC_XOSCSEL_XTAL_1KCLK_gc = (0x07<<0), /* 0.4-16MHz XTAL - 1K CLK */
+ OSC_XOSCSEL_XTAL_16KCLK_gc = (0x0B<<0), /* 0.4-16MHz XTAL - 16K CLK */
+} OSC_XOSCSEL_t;
+
+/* PLL Clock Source */
+typedef enum OSC_PLLSRC_enum
+{
+ OSC_PLLSRC_RC2M_gc = (0x00<<6), /* Internal 2MHz RC Oscillator */
+ OSC_PLLSRC_RC32M_gc = (0x02<<6), /* Internal 32MHz RC Oscillator */
+ OSC_PLLSRC_XOSC_gc = (0x03<<6), /* External Oscillator */
+} OSC_PLLSRC_t;
+
+
+/*
+--------------------------------------------------------------------------
+DFLL - DFLL
+--------------------------------------------------------------------------
+*/
+
+/* DFLL */
+typedef struct DFLL_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t CALA; /* Calibration Register A */
+ register8_t CALB; /* Calibration Register B */
+ register8_t COMP0; /* Oscillator Compare Register 0 */
+ register8_t COMP1; /* Oscillator Compare Register 1 */
+ register8_t COMP2; /* Oscillator Compare Register 2 */
+ register8_t reserved_0x07;
+} DFLL_t;
+
+
+/*
+--------------------------------------------------------------------------
+RST - Reset
+--------------------------------------------------------------------------
+*/
+
+/* Reset */
+typedef struct RST_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t CTRL; /* Control Register */
+} RST_t;
+
+
+/*
+--------------------------------------------------------------------------
+WDT - Watch-Dog Timer
+--------------------------------------------------------------------------
+*/
+
+/* Watch-Dog Timer */
+typedef struct WDT_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t WINCTRL; /* Windowed Mode Control */
+ register8_t STATUS; /* Status */
+} WDT_t;
+
+/* Period setting */
+typedef enum WDT_PER_enum
+{
+ WDT_PER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_PER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_PER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_PER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_PER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_PER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_PER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_PER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_PER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_PER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_PER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_PER_t;
+
+/* Closed window period */
+typedef enum WDT_WPER_enum
+{
+ WDT_WPER_8CLK_gc = (0x00<<2), /* 8 cycles (8ms @ 3.3V) */
+ WDT_WPER_16CLK_gc = (0x01<<2), /* 16 cycles (16ms @ 3.3V) */
+ WDT_WPER_32CLK_gc = (0x02<<2), /* 32 cycles (32ms @ 3.3V) */
+ WDT_WPER_64CLK_gc = (0x03<<2), /* 64 cycles (64ms @ 3.3V) */
+ WDT_WPER_125CLK_gc = (0x04<<2), /* 125 cycles (0.125s @ 3.3V) */
+ WDT_WPER_250CLK_gc = (0x05<<2), /* 250 cycles (0.25s @ 3.3V) */
+ WDT_WPER_500CLK_gc = (0x06<<2), /* 500 cycles (0.5s @ 3.3V) */
+ WDT_WPER_1KCLK_gc = (0x07<<2), /* 1K cycles (1s @ 3.3V) */
+ WDT_WPER_2KCLK_gc = (0x08<<2), /* 2K cycles (2s @ 3.3V) */
+ WDT_WPER_4KCLK_gc = (0x09<<2), /* 4K cycles (4s @ 3.3V) */
+ WDT_WPER_8KCLK_gc = (0x0A<<2), /* 8K cycles (8s @ 3.3V) */
+} WDT_WPER_t;
+
+
+/*
+--------------------------------------------------------------------------
+MCU - MCU Control
+--------------------------------------------------------------------------
+*/
+
+/* MCU Control */
+typedef struct MCU_struct
+{
+ register8_t DEVID0; /* Device ID byte 0 */
+ register8_t DEVID1; /* Device ID byte 1 */
+ register8_t DEVID2; /* Device ID byte 2 */
+ register8_t REVID; /* Revision ID */
+ register8_t JTAGUID; /* JTAG User ID */
+ register8_t reserved_0x05;
+ register8_t MCUCR; /* MCU Control */
+ register8_t reserved_0x07;
+ register8_t EVSYSLOCK; /* Event System Lock */
+ register8_t AWEXLOCK; /* AWEX Lock */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+} MCU_t;
+
+
+/*
+--------------------------------------------------------------------------
+PMIC - Programmable Multi-level Interrupt Controller
+--------------------------------------------------------------------------
+*/
+
+/* Programmable Multi-level Interrupt Controller */
+typedef struct PMIC_struct
+{
+ register8_t STATUS; /* Status Register */
+ register8_t INTPRI; /* Interrupt Priority */
+ register8_t CTRL; /* Control Register */
+} PMIC_t;
+
+
+/*
+--------------------------------------------------------------------------
+EVSYS - Event System
+--------------------------------------------------------------------------
+*/
+
+/* Event System */
+typedef struct EVSYS_struct
+{
+ register8_t CH0MUX; /* Event Channel 0 Multiplexer */
+ register8_t CH1MUX; /* Event Channel 1 Multiplexer */
+ register8_t CH2MUX; /* Event Channel 2 Multiplexer */
+ register8_t CH3MUX; /* Event Channel 3 Multiplexer */
+ register8_t CH0CTRL; /* Channel 0 Control Register */
+ register8_t CH1CTRL; /* Channel 1 Control Register */
+ register8_t CH2CTRL; /* Channel 2 Control Register */
+ register8_t CH3CTRL; /* Channel 3 Control Register */
+ register8_t STROBE; /* Event Strobe */
+ register8_t DATA; /* Event Data */
+} EVSYS_t;
+
+/* Quadrature Decoder Index Recognition Mode */
+typedef enum EVSYS_QDIRM_enum
+{
+ EVSYS_QDIRM_00_gc = (0x00<<5), /* QDPH0 = 0, QDPH90 = 0 */
+ EVSYS_QDIRM_01_gc = (0x01<<5), /* QDPH0 = 0, QDPH90 = 1 */
+ EVSYS_QDIRM_10_gc = (0x02<<5), /* QDPH0 = 1, QDPH90 = 0 */
+ EVSYS_QDIRM_11_gc = (0x03<<5), /* QDPH0 = 1, QDPH90 = 1 */
+} EVSYS_QDIRM_t;
+
+/* Digital filter coefficient */
+typedef enum EVSYS_DIGFILT_enum
+{
+ EVSYS_DIGFILT_1SAMPLE_gc = (0x00<<0), /* 1 SAMPLE */
+ EVSYS_DIGFILT_2SAMPLES_gc = (0x01<<0), /* 2 SAMPLES */
+ EVSYS_DIGFILT_3SAMPLES_gc = (0x02<<0), /* 3 SAMPLES */
+ EVSYS_DIGFILT_4SAMPLES_gc = (0x03<<0), /* 4 SAMPLES */
+ EVSYS_DIGFILT_5SAMPLES_gc = (0x04<<0), /* 5 SAMPLES */
+ EVSYS_DIGFILT_6SAMPLES_gc = (0x05<<0), /* 6 SAMPLES */
+ EVSYS_DIGFILT_7SAMPLES_gc = (0x06<<0), /* 7 SAMPLES */
+ EVSYS_DIGFILT_8SAMPLES_gc = (0x07<<0), /* 8 SAMPLES */
+} EVSYS_DIGFILT_t;
+
+/* Event Channel multiplexer input selection */
+typedef enum EVSYS_CHMUX_enum
+{
+ EVSYS_CHMUX_OFF_gc = (0x00<<0), /* Off */
+ EVSYS_CHMUX_RTC_OVF_gc = (0x08<<0), /* RTC Overflow */
+ EVSYS_CHMUX_RTC_CMP_gc = (0x09<<0), /* RTC Compare Match */
+ EVSYS_CHMUX_ACA_CH0_gc = (0x10<<0), /* Analog Comparator A Channel 0 */
+ EVSYS_CHMUX_ACA_CH1_gc = (0x11<<0), /* Analog Comparator A Channel 1 */
+ EVSYS_CHMUX_ACA_WIN_gc = (0x12<<0), /* Analog Comparator A Window */
+ EVSYS_CHMUX_ADCA_CH0_gc = (0x20<<0), /* ADC A Channel 0 */
+ EVSYS_CHMUX_PORTA_PIN0_gc = (0x50<<0), /* Port A, Pin0 */
+ EVSYS_CHMUX_PORTA_PIN1_gc = (0x51<<0), /* Port A, Pin1 */
+ EVSYS_CHMUX_PORTA_PIN2_gc = (0x52<<0), /* Port A, Pin2 */
+ EVSYS_CHMUX_PORTA_PIN3_gc = (0x53<<0), /* Port A, Pin3 */
+ EVSYS_CHMUX_PORTA_PIN4_gc = (0x54<<0), /* Port A, Pin4 */
+ EVSYS_CHMUX_PORTA_PIN5_gc = (0x55<<0), /* Port A, Pin5 */
+ EVSYS_CHMUX_PORTA_PIN6_gc = (0x56<<0), /* Port A, Pin6 */
+ EVSYS_CHMUX_PORTA_PIN7_gc = (0x57<<0), /* Port A, Pin7 */
+ EVSYS_CHMUX_PORTB_PIN0_gc = (0x58<<0), /* Port B, Pin0 */
+ EVSYS_CHMUX_PORTB_PIN1_gc = (0x59<<0), /* Port B, Pin1 */
+ EVSYS_CHMUX_PORTB_PIN2_gc = (0x5A<<0), /* Port B, Pin2 */
+ EVSYS_CHMUX_PORTB_PIN3_gc = (0x5B<<0), /* Port B, Pin3 */
+ EVSYS_CHMUX_PORTB_PIN4_gc = (0x5C<<0), /* Port B, Pin4 */
+ EVSYS_CHMUX_PORTB_PIN5_gc = (0x5D<<0), /* Port B, Pin5 */
+ EVSYS_CHMUX_PORTB_PIN6_gc = (0x5E<<0), /* Port B, Pin6 */
+ EVSYS_CHMUX_PORTB_PIN7_gc = (0x5F<<0), /* Port B, Pin7 */
+ EVSYS_CHMUX_PORTC_PIN0_gc = (0x60<<0), /* Port C, Pin0 */
+ EVSYS_CHMUX_PORTC_PIN1_gc = (0x61<<0), /* Port C, Pin1 */
+ EVSYS_CHMUX_PORTC_PIN2_gc = (0x62<<0), /* Port C, Pin2 */
+ EVSYS_CHMUX_PORTC_PIN3_gc = (0x63<<0), /* Port C, Pin3 */
+ EVSYS_CHMUX_PORTC_PIN4_gc = (0x64<<0), /* Port C, Pin4 */
+ EVSYS_CHMUX_PORTC_PIN5_gc = (0x65<<0), /* Port C, Pin5 */
+ EVSYS_CHMUX_PORTC_PIN6_gc = (0x66<<0), /* Port C, Pin6 */
+ EVSYS_CHMUX_PORTC_PIN7_gc = (0x67<<0), /* Port C, Pin7 */
+ EVSYS_CHMUX_PORTD_PIN0_gc = (0x68<<0), /* Port D, Pin0 */
+ EVSYS_CHMUX_PORTD_PIN1_gc = (0x69<<0), /* Port D, Pin1 */
+ EVSYS_CHMUX_PORTD_PIN2_gc = (0x6A<<0), /* Port D, Pin2 */
+ EVSYS_CHMUX_PORTD_PIN3_gc = (0x6B<<0), /* Port D, Pin3 */
+ EVSYS_CHMUX_PORTD_PIN4_gc = (0x6C<<0), /* Port D, Pin4 */
+ EVSYS_CHMUX_PORTD_PIN5_gc = (0x6D<<0), /* Port D, Pin5 */
+ EVSYS_CHMUX_PORTD_PIN6_gc = (0x6E<<0), /* Port D, Pin6 */
+ EVSYS_CHMUX_PORTD_PIN7_gc = (0x6F<<0), /* Port D, Pin7 */
+ EVSYS_CHMUX_PORTE_PIN0_gc = (0x70<<0), /* Port E, Pin0 */
+ EVSYS_CHMUX_PORTE_PIN1_gc = (0x71<<0), /* Port E, Pin1 */
+ EVSYS_CHMUX_PORTE_PIN2_gc = (0x72<<0), /* Port E, Pin2 */
+ EVSYS_CHMUX_PORTE_PIN3_gc = (0x73<<0), /* Port E, Pin3 */
+ EVSYS_CHMUX_PORTE_PIN4_gc = (0x74<<0), /* Port E, Pin4 */
+ EVSYS_CHMUX_PORTE_PIN5_gc = (0x75<<0), /* Port E, Pin5 */
+ EVSYS_CHMUX_PORTE_PIN6_gc = (0x76<<0), /* Port E, Pin6 */
+ EVSYS_CHMUX_PORTE_PIN7_gc = (0x77<<0), /* Port E, Pin7 */
+ EVSYS_CHMUX_PORTF_PIN0_gc = (0x78<<0), /* Port F, Pin0 */
+ EVSYS_CHMUX_PORTF_PIN1_gc = (0x79<<0), /* Port F, Pin1 */
+ EVSYS_CHMUX_PORTF_PIN2_gc = (0x7A<<0), /* Port F, Pin2 */
+ EVSYS_CHMUX_PORTF_PIN3_gc = (0x7B<<0), /* Port F, Pin3 */
+ EVSYS_CHMUX_PORTF_PIN4_gc = (0x7C<<0), /* Port F, Pin4 */
+ EVSYS_CHMUX_PORTF_PIN5_gc = (0x7D<<0), /* Port F, Pin5 */
+ EVSYS_CHMUX_PORTF_PIN6_gc = (0x7E<<0), /* Port F, Pin6 */
+ EVSYS_CHMUX_PORTF_PIN7_gc = (0x7F<<0), /* Port F, Pin7 */
+ EVSYS_CHMUX_PRESCALER_1_gc = (0x80<<0), /* Prescaler, divide by 1 */
+ EVSYS_CHMUX_PRESCALER_2_gc = (0x81<<0), /* Prescaler, divide by 2 */
+ EVSYS_CHMUX_PRESCALER_4_gc = (0x82<<0), /* Prescaler, divide by 4 */
+ EVSYS_CHMUX_PRESCALER_8_gc = (0x83<<0), /* Prescaler, divide by 8 */
+ EVSYS_CHMUX_PRESCALER_16_gc = (0x84<<0), /* Prescaler, divide by 16 */
+ EVSYS_CHMUX_PRESCALER_32_gc = (0x85<<0), /* Prescaler, divide by 32 */
+ EVSYS_CHMUX_PRESCALER_64_gc = (0x86<<0), /* Prescaler, divide by 64 */
+ EVSYS_CHMUX_PRESCALER_128_gc = (0x87<<0), /* Prescaler, divide by 128 */
+ EVSYS_CHMUX_PRESCALER_256_gc = (0x88<<0), /* Prescaler, divide by 256 */
+ EVSYS_CHMUX_PRESCALER_512_gc = (0x89<<0), /* Prescaler, divide by 512 */
+ EVSYS_CHMUX_PRESCALER_1024_gc = (0x8A<<0), /* Prescaler, divide by 1024 */
+ EVSYS_CHMUX_PRESCALER_2048_gc = (0x8B<<0), /* Prescaler, divide by 2048 */
+ EVSYS_CHMUX_PRESCALER_4096_gc = (0x8C<<0), /* Prescaler, divide by 4096 */
+ EVSYS_CHMUX_PRESCALER_8192_gc = (0x8D<<0), /* Prescaler, divide by 8192 */
+ EVSYS_CHMUX_PRESCALER_16384_gc = (0x8E<<0), /* Prescaler, divide by 16384 */
+ EVSYS_CHMUX_PRESCALER_32768_gc = (0x8F<<0), /* Prescaler, divide by 32768 */
+ EVSYS_CHMUX_TCC0_OVF_gc = (0xC0<<0), /* Timer/Counter C0 Overflow */
+ EVSYS_CHMUX_TCC0_ERR_gc = (0xC1<<0), /* Timer/Counter C0 Error */
+ EVSYS_CHMUX_TCC0_CCA_gc = (0xC4<<0), /* Timer/Counter C0 Compare or Capture A */
+ EVSYS_CHMUX_TCC0_CCB_gc = (0xC5<<0), /* Timer/Counter C0 Compare or Capture B */
+ EVSYS_CHMUX_TCC0_CCC_gc = (0xC6<<0), /* Timer/Counter C0 Compare or Capture C */
+ EVSYS_CHMUX_TCC0_CCD_gc = (0xC7<<0), /* Timer/Counter C0 Compare or Capture D */
+ EVSYS_CHMUX_TCC1_OVF_gc = (0xC8<<0), /* Timer/Counter C1 Overflow */
+ EVSYS_CHMUX_TCC1_ERR_gc = (0xC9<<0), /* Timer/Counter C1 Error */
+ EVSYS_CHMUX_TCC1_CCA_gc = (0xCC<<0), /* Timer/Counter C1 Compare or Capture A */
+ EVSYS_CHMUX_TCC1_CCB_gc = (0xCD<<0), /* Timer/Counter C1 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_OVF_gc = (0xD0<<0), /* Timer/Counter D0 Overflow */
+ EVSYS_CHMUX_TCD0_ERR_gc = (0xD1<<0), /* Timer/Counter D0 Error */
+ EVSYS_CHMUX_TCD0_CCA_gc = (0xD4<<0), /* Timer/Counter D0 Compare or Capture A */
+ EVSYS_CHMUX_TCD0_CCB_gc = (0xD5<<0), /* Timer/Counter D0 Compare or Capture B */
+ EVSYS_CHMUX_TCD0_CCC_gc = (0xD6<<0), /* Timer/Counter D0 Compare or Capture C */
+ EVSYS_CHMUX_TCD0_CCD_gc = (0xD7<<0), /* Timer/Counter D0 Compare or Capture D */
+ EVSYS_CHMUX_TCD1_OVF_gc = (0xD8<<0), /* Timer/Counter D1 Overflow */
+ EVSYS_CHMUX_TCD1_ERR_gc = (0xD9<<0), /* Timer/Counter D1 Error */
+ EVSYS_CHMUX_TCD1_CCA_gc = (0xDC<<0), /* Timer/Counter D1 Compare or Capture A */
+ EVSYS_CHMUX_TCD1_CCB_gc = (0xDD<<0), /* Timer/Counter D1 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_OVF_gc = (0xE0<<0), /* Timer/Counter E0 Overflow */
+ EVSYS_CHMUX_TCE0_ERR_gc = (0xE1<<0), /* Timer/Counter E0 Error */
+ EVSYS_CHMUX_TCE0_CCA_gc = (0xE4<<0), /* Timer/Counter E0 Compare or Capture A */
+ EVSYS_CHMUX_TCE0_CCB_gc = (0xE5<<0), /* Timer/Counter E0 Compare or Capture B */
+ EVSYS_CHMUX_TCE0_CCC_gc = (0xE6<<0), /* Timer/Counter E0 Compare or Capture C */
+ EVSYS_CHMUX_TCE0_CCD_gc = (0xE7<<0), /* Timer/Counter E0 Compare or Capture D */
+ EVSYS_CHMUX_TCE1_OVF_gc = (0xE8<<0), /* Timer/Counter E1 Overflow */
+ EVSYS_CHMUX_TCE1_ERR_gc = (0xE9<<0), /* Timer/Counter E1 Error */
+ EVSYS_CHMUX_TCE1_CCA_gc = (0xEC<<0), /* Timer/Counter E1 Compare or Capture A */
+ EVSYS_CHMUX_TCE1_CCB_gc = (0xED<<0), /* Timer/Counter E1 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_OVF_gc = (0xF0<<0), /* Timer/Counter F0 Overflow */
+ EVSYS_CHMUX_TCF0_ERR_gc = (0xF1<<0), /* Timer/Counter F0 Error */
+ EVSYS_CHMUX_TCF0_CCA_gc = (0xF4<<0), /* Timer/Counter F0 Compare or Capture A */
+ EVSYS_CHMUX_TCF0_CCB_gc = (0xF5<<0), /* Timer/Counter F0 Compare or Capture B */
+ EVSYS_CHMUX_TCF0_CCC_gc = (0xF6<<0), /* Timer/Counter F0 Compare or Capture C */
+ EVSYS_CHMUX_TCF0_CCD_gc = (0xF7<<0), /* Timer/Counter F0 Compare or Capture D */
+ EVSYS_CHMUX_TCF1_OVF_gc = (0xF8<<0), /* Timer/Counter F1 Overflow */
+ EVSYS_CHMUX_TCF1_ERR_gc = (0xF9<<0), /* Timer/Counter F1 Error */
+ EVSYS_CHMUX_TCF1_CCA_gc = (0xFC<<0), /* Timer/Counter F1 Compare or Capture A */
+ EVSYS_CHMUX_TCF1_CCB_gc = (0xFD<<0), /* Timer/Counter F1 Compare or Capture B */
+} EVSYS_CHMUX_t;
+
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Non-volatile Memory Controller */
+typedef struct NVM_struct
+{
+ register8_t ADDR0; /* Address Register 0 */
+ register8_t ADDR1; /* Address Register 1 */
+ register8_t ADDR2; /* Address Register 2 */
+ register8_t reserved_0x03;
+ register8_t DATA0; /* Data Register 0 */
+ register8_t DATA1; /* Data Register 1 */
+ register8_t DATA2; /* Data Register 2 */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t CMD; /* Command */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t INTCTRL; /* Interrupt Control */
+ register8_t reserved_0x0E;
+ register8_t STATUS; /* Status */
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Lock Bits */
+typedef struct NVM_LOCKBITS_struct
+{
+ register8_t LOCKBITS; /* Lock Bits */
+} NVM_LOCKBITS_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Fuses */
+typedef struct NVM_FUSES_struct
+{
+ register8_t FUSEBYTE0; /* User ID */
+ register8_t FUSEBYTE1; /* Watchdog Configuration */
+ register8_t FUSEBYTE2; /* Reset Configuration */
+ register8_t reserved_0x03;
+ register8_t FUSEBYTE4; /* Start-up Configuration */
+ register8_t FUSEBYTE5; /* EESAVE and BOD Level */
+} NVM_FUSES_t;
+
+/*
+--------------------------------------------------------------------------
+NVM - Non Volatile Memory Controller
+--------------------------------------------------------------------------
+*/
+
+/* Production Signatures */
+typedef struct NVM_PROD_SIGNATURES_struct
+{
+ register8_t RCOSC2M; /* RCOSC 2MHz Calibration Value */
+ register8_t reserved_0x01;
+ register8_t RCOSC32K; /* RCOSC 32kHz Calibration Value */
+ register8_t RCOSC32M; /* RCOSC 32MHz Calibration Value */
+ register8_t reserved_0x04;
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ register8_t LOTNUM0; /* Lot Number Byte 0, ASCII */
+ register8_t LOTNUM1; /* Lot Number Byte 1, ASCII */
+ register8_t LOTNUM2; /* Lot Number Byte 2, ASCII */
+ register8_t LOTNUM3; /* Lot Number Byte 3, ASCII */
+ register8_t LOTNUM4; /* Lot Number Byte 4, ASCII */
+ register8_t LOTNUM5; /* Lot Number Byte 5, ASCII */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t WAFNUM; /* Wafer Number */
+ register8_t reserved_0x11;
+ register8_t COORDX0; /* Wafer Coordinate X Byte 0 */
+ register8_t COORDX1; /* Wafer Coordinate X Byte 1 */
+ register8_t COORDY0; /* Wafer Coordinate Y Byte 0 */
+ register8_t COORDY1; /* Wafer Coordinate Y Byte 1 */
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ register8_t ADCACAL0; /* ADCA Calibration Byte 0 */
+ register8_t ADCACAL1; /* ADCA Calibration Byte 1 */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t ADCBCAL0; /* ADCB Calibration Byte 0 */
+ register8_t ADCBCAL1; /* ADCB Calibration Byte 1 */
+ register8_t reserved_0x26;
+ register8_t reserved_0x27;
+ register8_t reserved_0x28;
+ register8_t reserved_0x29;
+ register8_t reserved_0x2A;
+ register8_t reserved_0x2B;
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t TEMPSENSE0; /* Temperature Sensor Calibration Byte 0 */
+ register8_t TEMPSENSE1; /* Temperature Sensor Calibration Byte 0 */
+ register8_t DACAOFFCAL; /* DACA Calibration Byte 0 */
+ register8_t DACAGAINCAL; /* DACA Calibration Byte 1 */
+ register8_t DACBOFFCAL; /* DACB Calibration Byte 0 */
+ register8_t DACBGAINCAL; /* DACB Calibration Byte 1 */
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ register8_t reserved_0x36;
+ register8_t reserved_0x37;
+ register8_t reserved_0x38;
+ register8_t reserved_0x39;
+ register8_t reserved_0x3A;
+ register8_t reserved_0x3B;
+ register8_t reserved_0x3C;
+ register8_t reserved_0x3D;
+ register8_t reserved_0x3E;
+} NVM_PROD_SIGNATURES_t;
+
+/* NVM Command */
+typedef enum NVM_CMD_enum
+{
+ NVM_CMD_NO_OPERATION_gc = (0x00<<0), /* Noop/Ordinary LPM */
+ NVM_CMD_READ_CALIB_ROW_gc = (0x02<<0), /* Read calibration row */
+ NVM_CMD_READ_USER_SIG_ROW_gc = (0x01<<0), /* Read user signature row */
+ NVM_CMD_READ_EEPROM_gc = (0x06<<0), /* Read EEPROM */
+ NVM_CMD_READ_FUSES_gc = (0x07<<0), /* Read fuse byte */
+ NVM_CMD_WRITE_LOCK_BITS_gc = (0x08<<0), /* Write lock bits */
+ NVM_CMD_ERASE_USER_SIG_ROW_gc = (0x18<<0), /* Erase user signature row */
+ NVM_CMD_WRITE_USER_SIG_ROW_gc = (0x1A<<0), /* Write user signature row */
+ NVM_CMD_ERASE_APP_gc = (0x20<<0), /* Erase Application Section */
+ NVM_CMD_ERASE_APP_PAGE_gc = (0x22<<0), /* Erase Application Section page */
+ NVM_CMD_LOAD_FLASH_BUFFER_gc = (0x23<<0), /* Load Flash page buffer */
+ NVM_CMD_WRITE_APP_PAGE_gc = (0x24<<0), /* Write Application Section page */
+ NVM_CMD_ERASE_WRITE_APP_PAGE_gc = (0x25<<0), /* Erase-and-write Application Section page */
+ NVM_CMD_ERASE_FLASH_BUFFER_gc = (0x26<<0), /* Erase/flush Flash page buffer */
+ NVM_CMD_ERASE_BOOT_PAGE_gc = (0x2A<<0), /* Erase Boot Section page */
+ NVM_CMD_WRITE_BOOT_PAGE_gc = (0x2C<<0), /* Write Boot Section page */
+ NVM_CMD_ERASE_WRITE_BOOT_PAGE_gc = (0x2D<<0), /* Erase-and-write Boot Section page */
+ NVM_CMD_ERASE_EEPROM_gc = (0x30<<0), /* Erase EEPROM */
+ NVM_CMD_ERASE_EEPROM_PAGE_gc = (0x32<<0), /* Erase EEPROM page */
+ NVM_CMD_LOAD_EEPROM_BUFFER_gc = (0x33<<0), /* Load EEPROM page buffer */
+ NVM_CMD_WRITE_EEPROM_PAGE_gc = (0x34<<0), /* Write EEPROM page */
+ NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc = (0x35<<0), /* Erase-and-write EEPROM page */
+ NVM_CMD_ERASE_EEPROM_BUFFER_gc = (0x36<<0), /* Erase/flush EEPROM page buffer */
+ NVM_CMD_APP_CRC_gc = (0x38<<0), /* Generate Application section CRC */
+ NVM_CMD_BOOT_CRC_gc = (0x39<<0), /* Generate Boot Section CRC */
+ NVM_CMD_FLASH_RANGE_CRC_gc = (0x3A<<0), /* Generate Flash Range CRC */
+} NVM_CMD_t;
+
+/* SPM ready interrupt level */
+typedef enum NVM_SPMLVL_enum
+{
+ NVM_SPMLVL_OFF_gc = (0x00<<2), /* Interrupt disabled */
+ NVM_SPMLVL_LO_gc = (0x01<<2), /* Low level */
+ NVM_SPMLVL_MED_gc = (0x02<<2), /* Medium level */
+ NVM_SPMLVL_HI_gc = (0x03<<2), /* High level */
+} NVM_SPMLVL_t;
+
+/* EEPROM ready interrupt level */
+typedef enum NVM_EELVL_enum
+{
+ NVM_EELVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ NVM_EELVL_LO_gc = (0x01<<0), /* Low level */
+ NVM_EELVL_MED_gc = (0x02<<0), /* Medium level */
+ NVM_EELVL_HI_gc = (0x03<<0), /* High level */
+} NVM_EELVL_t;
+
+/* Boot lock bits - boot setcion */
+typedef enum NVM_BLBB_enum
+{
+ NVM_BLBB_NOLOCK_gc = (0x03<<6), /* No locks */
+ NVM_BLBB_WLOCK_gc = (0x02<<6), /* Write not allowed */
+ NVM_BLBB_RLOCK_gc = (0x01<<6), /* Read not allowed */
+ NVM_BLBB_RWLOCK_gc = (0x00<<6), /* Read and write not allowed */
+} NVM_BLBB_t;
+
+/* Boot lock bits - application section */
+typedef enum NVM_BLBA_enum
+{
+ NVM_BLBA_NOLOCK_gc = (0x03<<4), /* No locks */
+ NVM_BLBA_WLOCK_gc = (0x02<<4), /* Write not allowed */
+ NVM_BLBA_RLOCK_gc = (0x01<<4), /* Read not allowed */
+ NVM_BLBA_RWLOCK_gc = (0x00<<4), /* Read and write not allowed */
+} NVM_BLBA_t;
+
+/* Boot lock bits - application table section */
+typedef enum NVM_BLBAT_enum
+{
+ NVM_BLBAT_NOLOCK_gc = (0x03<<2), /* No locks */
+ NVM_BLBAT_WLOCK_gc = (0x02<<2), /* Write not allowed */
+ NVM_BLBAT_RLOCK_gc = (0x01<<2), /* Read not allowed */
+ NVM_BLBAT_RWLOCK_gc = (0x00<<2), /* Read and write not allowed */
+} NVM_BLBAT_t;
+
+/* Lock bits */
+typedef enum NVM_LB_enum
+{
+ NVM_LB_NOLOCK_gc = (0x03<<0), /* No locks */
+ NVM_LB_WLOCK_gc = (0x02<<0), /* Write not allowed */
+ NVM_LB_RWLOCK_gc = (0x00<<0), /* Read and write not allowed */
+} NVM_LB_t;
+
+/* Boot Loader Section Reset Vector */
+typedef enum BOOTRST_enum
+{
+ BOOTRST_BOOTLDR_gc = (0x00<<6), /* Boot Loader Reset */
+ BOOTRST_APPLICATION_gc = (0x01<<6), /* Application Reset */
+} BOOTRST_t;
+
+/* BOD operation */
+typedef enum BOD_enum
+{
+ BOD_INSAMPLEDMODE_gc = (0x01<<0), /* BOD enabled in sampled mode */
+ BOD_CONTINOUSLY_gc = (0x02<<0), /* BOD enabled continuously */
+ BOD_DISABLED_gc = (0x03<<0), /* BOD Disabled */
+} BOD_t;
+
+/* Watchdog (Window) Timeout Period */
+typedef enum WD_enum
+{
+ WD_8CLK_gc = (0x00<<4), /* 8 cycles (8ms @ 3.3V) */
+ WD_16CLK_gc = (0x01<<4), /* 16 cycles (16ms @ 3.3V) */
+ WD_32CLK_gc = (0x02<<4), /* 32 cycles (32ms @ 3.3V) */
+ WD_64CLK_gc = (0x03<<4), /* 64 cycles (64ms @ 3.3V) */
+ WD_128CLK_gc = (0x04<<4), /* 128 cycles (0.125s @ 3.3V) */
+ WD_256CLK_gc = (0x05<<4), /* 256 cycles (0.25s @ 3.3V) */
+ WD_512CLK_gc = (0x06<<4), /* 512 cycles (0.5s @ 3.3V) */
+ WD_1KCLK_gc = (0x07<<4), /* 1K cycles (1s @ 3.3V) */
+ WD_2KCLK_gc = (0x08<<4), /* 2K cycles (2s @ 3.3V) */
+ WD_4KCLK_gc = (0x09<<4), /* 4K cycles (4s @ 3.3V) */
+ WD_8KCLK_gc = (0x0A<<4), /* 8K cycles (8s @ 3.3V) */
+} WD_t;
+
+/* Start-up Time */
+typedef enum SUT_enum
+{
+ SUT_0MS_gc = (0x03<<2), /* 0 ms */
+ SUT_4MS_gc = (0x01<<2), /* 4 ms */
+ SUT_64MS_gc = (0x00<<2), /* 64 ms */
+} SUT_t;
+
+/* Brown Out Detection Voltage Level */
+typedef enum BODLVL_enum
+{
+ BODLVL_1V6_gc = (0x07<<0), /* 1.6 V */
+ BODLVL_1V9_gc = (0x06<<0), /* 1.8 V */
+ BODLVL_2V1_gc = (0x05<<0), /* 2.0 V */
+ BODLVL_2V4_gc = (0x04<<0), /* 2.2 V */
+ BODLVL_2V6_gc = (0x03<<0), /* 2.4 V */
+ BODLVL_2V9_gc = (0x02<<0), /* 2.7 V */
+ BODLVL_3V2_gc = (0x01<<0), /* 2.9 V */
+} BODLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+AC - Analog Comparator
+--------------------------------------------------------------------------
+*/
+
+/* Analog Comparator */
+typedef struct AC_struct
+{
+ register8_t AC0CTRL; /* Comparator 0 Control */
+ register8_t AC1CTRL; /* Comparator 1 Control */
+ register8_t AC0MUXCTRL; /* Comparator 0 MUX Control */
+ register8_t AC1MUXCTRL; /* Comparator 1 MUX Control */
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t WINCTRL; /* Window Mode Control */
+ register8_t STATUS; /* Status */
+} AC_t;
+
+/* Interrupt mode */
+typedef enum AC_INTMODE_enum
+{
+ AC_INTMODE_BOTHEDGES_gc = (0x00<<6), /* Interrupt on both edges */
+ AC_INTMODE_FALLING_gc = (0x02<<6), /* Interrupt on falling edge */
+ AC_INTMODE_RISING_gc = (0x03<<6), /* Interrupt on rising edge */
+} AC_INTMODE_t;
+
+/* Interrupt level */
+typedef enum AC_INTLVL_enum
+{
+ AC_INTLVL_OFF_gc = (0x00<<4), /* Interrupt disabled */
+ AC_INTLVL_LO_gc = (0x01<<4), /* Low level */
+ AC_INTLVL_MED_gc = (0x02<<4), /* Medium level */
+ AC_INTLVL_HI_gc = (0x03<<4), /* High level */
+} AC_INTLVL_t;
+
+/* Hysteresis mode selection */
+typedef enum AC_HYSMODE_enum
+{
+ AC_HYSMODE_NO_gc = (0x00<<1), /* No hysteresis */
+ AC_HYSMODE_SMALL_gc = (0x01<<1), /* Small hysteresis */
+ AC_HYSMODE_LARGE_gc = (0x02<<1), /* Large hysteresis */
+} AC_HYSMODE_t;
+
+/* Positive input multiplexer selection */
+typedef enum AC_MUXPOS_enum
+{
+ AC_MUXPOS_PIN0_gc = (0x00<<3), /* Pin 0 */
+ AC_MUXPOS_PIN1_gc = (0x01<<3), /* Pin 1 */
+ AC_MUXPOS_PIN2_gc = (0x02<<3), /* Pin 2 */
+ AC_MUXPOS_PIN3_gc = (0x03<<3), /* Pin 3 */
+ AC_MUXPOS_PIN4_gc = (0x04<<3), /* Pin 4 */
+ AC_MUXPOS_PIN5_gc = (0x05<<3), /* Pin 5 */
+ AC_MUXPOS_PIN6_gc = (0x06<<3), /* Pin 6 */
+ AC_MUXPOS_DAC_gc = (0x07<<3), /* DAC output */
+} AC_MUXPOS_t;
+
+/* Negative input multiplexer selection */
+typedef enum AC_MUXNEG_enum
+{
+ AC_MUXNEG_PIN0_gc = (0x00<<0), /* Pin 0 */
+ AC_MUXNEG_PIN1_gc = (0x01<<0), /* Pin 1 */
+ AC_MUXNEG_PIN3_gc = (0x02<<0), /* Pin 3 */
+ AC_MUXNEG_PIN5_gc = (0x03<<0), /* Pin 5 */
+ AC_MUXNEG_PIN7_gc = (0x04<<0), /* Pin 7 */
+ AC_MUXNEG_DAC_gc = (0x05<<0), /* DAC output */
+ AC_MUXNEG_BANDGAP_gc = (0x06<<0), /* Bandgap Reference */
+ AC_MUXNEG_SCALER_gc = (0x07<<0), /* Internal voltage scaler */
+} AC_MUXNEG_t;
+
+/* Windows interrupt mode */
+typedef enum AC_WINTMODE_enum
+{
+ AC_WINTMODE_ABOVE_gc = (0x00<<2), /* Interrupt on above window */
+ AC_WINTMODE_INSIDE_gc = (0x01<<2), /* Interrupt on inside window */
+ AC_WINTMODE_BELOW_gc = (0x02<<2), /* Interrupt on below window */
+ AC_WINTMODE_OUTSIDE_gc = (0x03<<2), /* Interrupt on outside window */
+} AC_WINTMODE_t;
+
+/* Window interrupt level */
+typedef enum AC_WINTLVL_enum
+{
+ AC_WINTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ AC_WINTLVL_LO_gc = (0x01<<0), /* Low priority */
+ AC_WINTLVL_MED_gc = (0x02<<0), /* Medium priority */
+ AC_WINTLVL_HI_gc = (0x03<<0), /* High priority */
+} AC_WINTLVL_t;
+
+/* Window mode state */
+typedef enum AC_WSTATE_enum
+{
+ AC_WSTATE_ABOVE_gc = (0x00<<6), /* Signal above window */
+ AC_WSTATE_INSIDE_gc = (0x01<<6), /* Signal inside window */
+ AC_WSTATE_BELOW_gc = (0x02<<6), /* Signal below window */
+} AC_WSTATE_t;
+
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* ADC Channel */
+typedef struct ADC_CH_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t MUXCTRL; /* MUX Control */
+ register8_t INTCTRL; /* Channel Interrupt Control */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ _WORDREGISTER(RES); /* Channel Result */
+ register8_t reserved_0x6;
+ register8_t reserved_0x7;
+} ADC_CH_t;
+
+/*
+--------------------------------------------------------------------------
+ADC - Analog/Digital Converter
+--------------------------------------------------------------------------
+*/
+
+/* Analog-to-Digital Converter */
+typedef struct ADC_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t REFCTRL; /* Reference Control */
+ register8_t EVCTRL; /* Event Control */
+ register8_t PRESCALER; /* Clock Prescaler */
+ register8_t CALCTRL; /* Calibration Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t reserved_0x07;
+ register8_t reserved_0x08;
+ register8_t reserved_0x09;
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ _WORDREGISTER(CAL); /* Calibration Value */
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ _WORDREGISTER(CH0RES); /* Channel 0 Result */
+ _WORDREGISTER(CMP); /* Compare Value */
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ ADC_CH_t CH0; /* ADC Channel 0 */
+} ADC_t;
+
+/* Positive input multiplexer selection */
+typedef enum ADC_CH_MUXPOS_enum
+{
+ ADC_CH_MUXPOS_PIN0_gc = (0x00<<3), /* Input pin 0 */
+ ADC_CH_MUXPOS_PIN1_gc = (0x01<<3), /* Input pin 1 */
+ ADC_CH_MUXPOS_PIN2_gc = (0x02<<3), /* Input pin 2 */
+ ADC_CH_MUXPOS_PIN3_gc = (0x03<<3), /* Input pin 3 */
+ ADC_CH_MUXPOS_PIN4_gc = (0x04<<3), /* Input pin 4 */
+ ADC_CH_MUXPOS_PIN5_gc = (0x05<<3), /* Input pin 5 */
+ ADC_CH_MUXPOS_PIN6_gc = (0x06<<3), /* Input pin 6 */
+ ADC_CH_MUXPOS_PIN7_gc = (0x07<<3), /* Input pin 7 */
+} ADC_CH_MUXPOS_t;
+
+/* Internal input multiplexer selections */
+typedef enum ADC_CH_MUXINT_enum
+{
+ ADC_CH_MUXINT_TEMP_gc = (0x00<<3), /* Temperature Reference */
+ ADC_CH_MUXINT_BANDGAP_gc = (0x01<<3), /* Bandgap Reference */
+ ADC_CH_MUXINT_SCALEDVCC_gc = (0x02<<3), /* 1/10 scaled VCC */
+ ADC_CH_MUXINT_DAC_gc = (0x03<<3), /* DAC output */
+} ADC_CH_MUXINT_t;
+
+/* Negative input multiplexer selection */
+typedef enum ADC_CH_MUXNEG_enum
+{
+ ADC_CH_MUXNEG_PIN0_gc = (0x00<<0), /* Input pin 0 */
+ ADC_CH_MUXNEG_PIN1_gc = (0x01<<0), /* Input pin 1 */
+ ADC_CH_MUXNEG_PIN2_gc = (0x02<<0), /* Input pin 2 */
+ ADC_CH_MUXNEG_PIN3_gc = (0x03<<0), /* Input pin 3 */
+ ADC_CH_MUXNEG_PIN4_gc = (0x04<<0), /* Input pin 4 */
+ ADC_CH_MUXNEG_PIN5_gc = (0x05<<0), /* Input pin 5 */
+ ADC_CH_MUXNEG_PIN6_gc = (0x06<<0), /* Input pin 6 */
+ ADC_CH_MUXNEG_PIN7_gc = (0x07<<0), /* Input pin 7 */
+} ADC_CH_MUXNEG_t;
+
+/* Input mode */
+typedef enum ADC_CH_INPUTMODE_enum
+{
+ ADC_CH_INPUTMODE_INTERNAL_gc = (0x00<<0), /* Internal inputs, no gain */
+ ADC_CH_INPUTMODE_SINGLEENDED_gc = (0x01<<0), /* Single-ended input, no gain */
+ ADC_CH_INPUTMODE_DIFF_gc = (0x02<<0), /* Differential input, no gain */
+ ADC_CH_INPUTMODE_DIFFWGAIN_gc = (0x03<<0), /* Differential input, with gain */
+} ADC_CH_INPUTMODE_t;
+
+/* Gain factor */
+typedef enum ADC_CH_GAIN_enum
+{
+ ADC_CH_GAIN_1X_gc = (0x00<<2), /* 1x gain */
+ ADC_CH_GAIN_2X_gc = (0x01<<2), /* 2x gain */
+ ADC_CH_GAIN_4X_gc = (0x02<<2), /* 4x gain */
+ ADC_CH_GAIN_8X_gc = (0x03<<2), /* 8x gain */
+ ADC_CH_GAIN_16X_gc = (0x04<<2), /* 16x gain */
+ ADC_CH_GAIN_32X_gc = (0x05<<2), /* 32x gain */
+ ADC_CH_GAIN_64X_gc = (0x06<<2), /* 64x gain */
+} ADC_CH_GAIN_t;
+
+/* Conversion result resolution */
+typedef enum ADC_RESOLUTION_enum
+{
+ ADC_RESOLUTION_12BIT_gc = (0x00<<1), /* 12-bit right-adjusted result */
+ ADC_RESOLUTION_8BIT_gc = (0x02<<1), /* 8-bit right-adjusted result */
+ ADC_RESOLUTION_LEFT12BIT_gc = (0x03<<1), /* 12-bit left-adjusted result */
+} ADC_RESOLUTION_t;
+
+/* Voltage reference selection */
+typedef enum ADC_REFSEL_enum
+{
+ ADC_REFSEL_INT1V_gc = (0x00<<4), /* Internal 1V */
+ ADC_REFSEL_VCC_gc = (0x01<<4), /* Internal VCC/1.6V */
+ ADC_REFSEL_AREFA_gc = (0x02<<4), /* External reference on PORT A */
+ ADC_REFSEL_AREFB_gc = (0x03<<4), /* External reference on PORT B */
+} ADC_REFSEL_t;
+
+/* Channel sweep selection */
+typedef enum ADC_SWEEP_enum
+{
+ ADC_SWEEP_0_gc = (0x00<<6), /* ADC Channel 0 */
+} ADC_SWEEP_t;
+
+/* Event channel input selection */
+typedef enum ADC_EVSEL_enum
+{
+ ADC_EVSEL_0123_gc = (0x00<<3), /* Event Channel 0,1,2,3 */
+ ADC_EVSEL_1234_gc = (0x01<<3), /* Event Channel 1,2,3,4 */
+ ADC_EVSEL_2345_gc = (0x02<<3), /* Event Channel 2,3,4,5 */
+ ADC_EVSEL_3456_gc = (0x03<<3), /* Event Channel 3,4,5,6 */
+ ADC_EVSEL_4567_gc = (0x04<<3), /* Event Channel 4,5,6,7 */
+ ADC_EVSEL_567_gc = (0x05<<3), /* Event Channel 5,6,7 */
+ ADC_EVSEL_67_gc = (0x06<<3), /* Event Channel 6,7 */
+ ADC_EVSEL_7_gc = (0x07<<3), /* Event Channel 7 */
+} ADC_EVSEL_t;
+
+/* Event action selection */
+typedef enum ADC_EVACT_enum
+{
+ ADC_EVACT_NONE_gc = (0x00<<0), /* No event action */
+ ADC_EVACT_CH0_gc = (0x01<<0), /* First event triggers channel 0 */
+} ADC_EVACT_t;
+
+/* Interupt mode */
+typedef enum ADC_CH_INTMODE_enum
+{
+ ADC_CH_INTMODE_COMPLETE_gc = (0x00<<2), /* Interrupt on conversion complete */
+ ADC_CH_INTMODE_BELOW_gc = (0x01<<2), /* Interrupt on result below compare value */
+ ADC_CH_INTMODE_ABOVE_gc = (0x03<<2), /* Interrupt on result above compare value */
+} ADC_CH_INTMODE_t;
+
+/* Interrupt level */
+typedef enum ADC_CH_INTLVL_enum
+{
+ ADC_CH_INTLVL_OFF_gc = (0x00<<0), /* Interrupt disabled */
+ ADC_CH_INTLVL_LO_gc = (0x01<<0), /* Low level */
+ ADC_CH_INTLVL_MED_gc = (0x02<<0), /* Medium level */
+ ADC_CH_INTLVL_HI_gc = (0x03<<0), /* High level */
+} ADC_CH_INTLVL_t;
+
+/* Clock prescaler */
+typedef enum ADC_PRESCALER_enum
+{
+ ADC_PRESCALER_DIV4_gc = (0x00<<0), /* Divide clock by 4 */
+ ADC_PRESCALER_DIV8_gc = (0x01<<0), /* Divide clock by 8 */
+ ADC_PRESCALER_DIV16_gc = (0x02<<0), /* Divide clock by 16 */
+ ADC_PRESCALER_DIV32_gc = (0x03<<0), /* Divide clock by 32 */
+ ADC_PRESCALER_DIV64_gc = (0x04<<0), /* Divide clock by 64 */
+ ADC_PRESCALER_DIV128_gc = (0x05<<0), /* Divide clock by 128 */
+ ADC_PRESCALER_DIV256_gc = (0x06<<0), /* Divide clock by 256 */
+ ADC_PRESCALER_DIV512_gc = (0x07<<0), /* Divide clock by 512 */
+} ADC_PRESCALER_t;
+
+
+/*
+--------------------------------------------------------------------------
+RTC - Real-Time Clounter
+--------------------------------------------------------------------------
+*/
+
+/* Real-Time Counter */
+typedef struct RTC_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INTFLAGS; /* Interrupt Flags */
+ register8_t TEMP; /* Temporary register */
+ register8_t reserved_0x05;
+ register8_t reserved_0x06;
+ register8_t reserved_0x07;
+ _WORDREGISTER(CNT); /* Count Register */
+ _WORDREGISTER(PER); /* Period Register */
+ _WORDREGISTER(COMP); /* Compare Register */
+} RTC_t;
+
+/* Prescaler Factor */
+typedef enum RTC_PRESCALER_enum
+{
+ RTC_PRESCALER_OFF_gc = (0x00<<0), /* RTC Off */
+ RTC_PRESCALER_DIV1_gc = (0x01<<0), /* RTC Clock */
+ RTC_PRESCALER_DIV2_gc = (0x02<<0), /* RTC Clock / 2 */
+ RTC_PRESCALER_DIV8_gc = (0x03<<0), /* RTC Clock / 8 */
+ RTC_PRESCALER_DIV16_gc = (0x04<<0), /* RTC Clock / 16 */
+ RTC_PRESCALER_DIV64_gc = (0x05<<0), /* RTC Clock / 64 */
+ RTC_PRESCALER_DIV256_gc = (0x06<<0), /* RTC Clock / 256 */
+ RTC_PRESCALER_DIV1024_gc = (0x07<<0), /* RTC Clock / 1024 */
+} RTC_PRESCALER_t;
+
+/* Compare Interrupt level */
+typedef enum RTC_COMPINTLVL_enum
+{
+ RTC_COMPINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ RTC_COMPINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ RTC_COMPINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ RTC_COMPINTLVL_HI_gc = (0x03<<2), /* High Level */
+} RTC_COMPINTLVL_t;
+
+/* Overflow Interrupt level */
+typedef enum RTC_OVFINTLVL_enum
+{
+ RTC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ RTC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ RTC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ RTC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} RTC_OVFINTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* EBI Chip Select Module */
+typedef struct EBI_CS_struct
+{
+ register8_t CTRLA; /* Chip Select Control Register A */
+ register8_t CTRLB; /* Chip Select Control Register B */
+ _WORDREGISTER(BASEADDR); /* Chip Select Base Address */
+} EBI_CS_t;
+
+/*
+--------------------------------------------------------------------------
+EBI - External Bus Interface
+--------------------------------------------------------------------------
+*/
+
+/* External Bus Interface */
+typedef struct EBI_struct
+{
+ register8_t CTRL; /* Control */
+ register8_t SDRAMCTRLA; /* SDRAM Control Register A */
+ register8_t reserved_0x02;
+ register8_t reserved_0x03;
+ _WORDREGISTER(REFRESH); /* SDRAM Refresh Period */
+ _WORDREGISTER(INITDLY); /* SDRAM Initialization Delay */
+ register8_t SDRAMCTRLB; /* SDRAM Control Register B */
+ register8_t SDRAMCTRLC; /* SDRAM Control Register C */
+ register8_t reserved_0x0A;
+ register8_t reserved_0x0B;
+ register8_t reserved_0x0C;
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ EBI_CS_t CS0; /* Chip Select 0 */
+ EBI_CS_t CS1; /* Chip Select 1 */
+ EBI_CS_t CS2; /* Chip Select 2 */
+ EBI_CS_t CS3; /* Chip Select 3 */
+} EBI_t;
+
+/* Chip Select adress space */
+typedef enum EBI_CS_ASPACE_enum
+{
+ EBI_CS_ASPACE_256B_gc = (0x00<<2), /* 256 bytes */
+ EBI_CS_ASPACE_512B_gc = (0x01<<2), /* 512 bytes */
+ EBI_CS_ASPACE_1KB_gc = (0x02<<2), /* 1K bytes */
+ EBI_CS_ASPACE_2KB_gc = (0x03<<2), /* 2K bytes */
+ EBI_CS_ASPACE_4KB_gc = (0x04<<2), /* 4K bytes */
+ EBI_CS_ASPACE_8KB_gc = (0x05<<2), /* 8K bytes */
+ EBI_CS_ASPACE_16KB_gc = (0x06<<2), /* 16K bytes */
+ EBI_CS_ASPACE_32KB_gc = (0x07<<2), /* 32K bytes */
+ EBI_CS_ASPACE_64KB_gc = (0x08<<2), /* 64K bytes */
+ EBI_CS_ASPACE_128KB_gc = (0x09<<2), /* 128K bytes */
+ EBI_CS_ASPACE_256KB_gc = (0x0A<<2), /* 256K bytes */
+ EBI_CS_ASPACE_512KB_gc = (0x0B<<2), /* 512K bytes */
+ EBI_CS_ASPACE_1MB_gc = (0x0C<<2), /* 1M bytes */
+ EBI_CS_ASPACE_2MB_gc = (0x0D<<2), /* 2M bytes */
+ EBI_CS_ASPACE_4MB_gc = (0x0E<<2), /* 4M bytes */
+ EBI_CS_ASPACE_8MB_gc = (0x0F<<2), /* 8M bytes */
+ EBI_CS_ASPACE_16M_gc = (0x10<<2), /* 16M bytes */
+} EBI_CS_ASPACE_t;
+
+/* */
+typedef enum EBI_CS_SRWS_enum
+{
+ EBI_CS_SRWS_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_CS_SRWS_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_CS_SRWS_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_CS_SRWS_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_CS_SRWS_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_CS_SRWS_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_CS_SRWS_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_CS_SRWS_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_CS_SRWS_t;
+
+/* Chip Select address mode */
+typedef enum EBI_CS_MODE_enum
+{
+ EBI_CS_MODE_DISABLED_gc = (0x00<<0), /* Chip Select Disabled */
+ EBI_CS_MODE_SRAM_gc = (0x01<<0), /* Chip Select in SRAM mode */
+ EBI_CS_MODE_LPC_gc = (0x02<<0), /* Chip Select in SRAM LPC mode */
+ EBI_CS_MODE_SDRAM_gc = (0x03<<0), /* Chip Select in SDRAM mode */
+} EBI_CS_MODE_t;
+
+/* Chip Select SDRAM mode */
+typedef enum EBI_CS_SDMODE_enum
+{
+ EBI_CS_SDMODE_NORMAL_gc = (0x00<<0), /* Normal mode */
+ EBI_CS_SDMODE_LOAD_gc = (0x01<<0), /* Load Mode Register command mode */
+} EBI_CS_SDMODE_t;
+
+/* */
+typedef enum EBI_SDDATAW_enum
+{
+ EBI_SDDATAW_4BIT_gc = (0x00<<6), /* 4-bit data bus */
+ EBI_SDDATAW_8BIT_gc = (0x01<<6), /* 8-bit data bus */
+} EBI_SDDATAW_t;
+
+/* */
+typedef enum EBI_LPCMODE_enum
+{
+ EBI_LPCMODE_ALE1_gc = (0x00<<4), /* Data muxed with addr byte 0 */
+ EBI_LPCMODE_ALE12_gc = (0x02<<4), /* Data muxed with addr byte 0 and 1 */
+} EBI_LPCMODE_t;
+
+/* */
+typedef enum EBI_SRMODE_enum
+{
+ EBI_SRMODE_ALE1_gc = (0x00<<2), /* Addr byte 0 muxed with 1 */
+ EBI_SRMODE_ALE2_gc = (0x01<<2), /* Addr byte 0 muxed with 2 */
+ EBI_SRMODE_ALE12_gc = (0x02<<2), /* Addr byte 0 muxed with 1 and 2 */
+ EBI_SRMODE_NOALE_gc = (0x03<<2), /* No addr muxing */
+} EBI_SRMODE_t;
+
+/* */
+typedef enum EBI_IFMODE_enum
+{
+ EBI_IFMODE_DISABLED_gc = (0x00<<0), /* EBI Disabled */
+ EBI_IFMODE_3PORT_gc = (0x01<<0), /* 3-port mode */
+ EBI_IFMODE_4PORT_gc = (0x02<<0), /* 4-port mode */
+ EBI_IFMODE_2PORT_gc = (0x03<<0), /* 2-port mode */
+} EBI_IFMODE_t;
+
+/* */
+typedef enum EBI_SDCOL_enum
+{
+ EBI_SDCOL_8BIT_gc = (0x00<<0), /* 8 column bits */
+ EBI_SDCOL_9BIT_gc = (0x01<<0), /* 9 column bits */
+ EBI_SDCOL_10BIT_gc = (0x02<<0), /* 10 column bits */
+ EBI_SDCOL_11BIT_gc = (0x03<<0), /* 11 column bits */
+} EBI_SDCOL_t;
+
+/* */
+typedef enum EBI_MRDLY_enum
+{
+ EBI_MRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_MRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_MRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_MRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_MRDLY_t;
+
+/* */
+typedef enum EBI_ROWCYCDLY_enum
+{
+ EBI_ROWCYCDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ROWCYCDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ROWCYCDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ROWCYCDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ROWCYCDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ROWCYCDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ROWCYCDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ROWCYCDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ROWCYCDLY_t;
+
+/* */
+typedef enum EBI_RPDLY_enum
+{
+ EBI_RPDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_RPDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_RPDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_RPDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_RPDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_RPDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_RPDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_RPDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_RPDLY_t;
+
+/* */
+typedef enum EBI_WRDLY_enum
+{
+ EBI_WRDLY_0CLK_gc = (0x00<<6), /* 0 cycles */
+ EBI_WRDLY_1CLK_gc = (0x01<<6), /* 1 cycle */
+ EBI_WRDLY_2CLK_gc = (0x02<<6), /* 2 cycles */
+ EBI_WRDLY_3CLK_gc = (0x03<<6), /* 3 cycles */
+} EBI_WRDLY_t;
+
+/* */
+typedef enum EBI_ESRDLY_enum
+{
+ EBI_ESRDLY_0CLK_gc = (0x00<<3), /* 0 cycles */
+ EBI_ESRDLY_1CLK_gc = (0x01<<3), /* 1 cycle */
+ EBI_ESRDLY_2CLK_gc = (0x02<<3), /* 2 cycles */
+ EBI_ESRDLY_3CLK_gc = (0x03<<3), /* 3 cycles */
+ EBI_ESRDLY_4CLK_gc = (0x04<<3), /* 4 cycles */
+ EBI_ESRDLY_5CLK_gc = (0x05<<3), /* 5 cycle */
+ EBI_ESRDLY_6CLK_gc = (0x06<<3), /* 6 cycles */
+ EBI_ESRDLY_7CLK_gc = (0x07<<3), /* 7 cycles */
+} EBI_ESRDLY_t;
+
+/* */
+typedef enum EBI_ROWCOLDLY_enum
+{
+ EBI_ROWCOLDLY_0CLK_gc = (0x00<<0), /* 0 cycles */
+ EBI_ROWCOLDLY_1CLK_gc = (0x01<<0), /* 1 cycle */
+ EBI_ROWCOLDLY_2CLK_gc = (0x02<<0), /* 2 cycles */
+ EBI_ROWCOLDLY_3CLK_gc = (0x03<<0), /* 3 cycles */
+ EBI_ROWCOLDLY_4CLK_gc = (0x04<<0), /* 4 cycles */
+ EBI_ROWCOLDLY_5CLK_gc = (0x05<<0), /* 5 cycle */
+ EBI_ROWCOLDLY_6CLK_gc = (0x06<<0), /* 6 cycles */
+ EBI_ROWCOLDLY_7CLK_gc = (0x07<<0), /* 7 cycles */
+} EBI_ROWCOLDLY_t;
+
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_MASTER_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t STATUS; /* Status Register */
+ register8_t BAUD; /* Baurd Rate Control Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+} TWI_MASTER_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* */
+typedef struct TWI_SLAVE_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t STATUS; /* Status Register */
+ register8_t ADDR; /* Address Register */
+ register8_t DATA; /* Data Register */
+ register8_t ADDRMASK; /* Address Mask Register */
+} TWI_SLAVE_t;
+
+/*
+--------------------------------------------------------------------------
+TWI - Two-Wire Interface
+--------------------------------------------------------------------------
+*/
+
+/* Two-Wire Interface */
+typedef struct TWI_struct
+{
+ register8_t CTRL; /* TWI Common Control Register */
+ TWI_MASTER_t MASTER; /* TWI master module */
+ TWI_SLAVE_t SLAVE; /* TWI slave module */
+} TWI_t;
+
+/* Master Interrupt Level */
+typedef enum TWI_MASTER_INTLVL_enum
+{
+ TWI_MASTER_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_MASTER_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_MASTER_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_MASTER_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_MASTER_INTLVL_t;
+
+/* Inactive Timeout */
+typedef enum TWI_MASTER_TIMEOUT_enum
+{
+ TWI_MASTER_TIMEOUT_DISABLED_gc = (0x00<<2), /* Bus Timeout Disabled */
+ TWI_MASTER_TIMEOUT_50US_gc = (0x01<<2), /* 50 Microseconds */
+ TWI_MASTER_TIMEOUT_100US_gc = (0x02<<2), /* 100 Microseconds */
+ TWI_MASTER_TIMEOUT_200US_gc = (0x03<<2), /* 200 Microseconds */
+} TWI_MASTER_TIMEOUT_t;
+
+/* Master Command */
+typedef enum TWI_MASTER_CMD_enum
+{
+ TWI_MASTER_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_MASTER_CMD_REPSTART_gc = (0x01<<0), /* Issue Repeated Start Condition */
+ TWI_MASTER_CMD_RECVTRANS_gc = (0x02<<0), /* Receive or Transmit Data */
+ TWI_MASTER_CMD_STOP_gc = (0x03<<0), /* Issue Stop Condition */
+} TWI_MASTER_CMD_t;
+
+/* Master Bus State */
+typedef enum TWI_MASTER_BUSSTATE_enum
+{
+ TWI_MASTER_BUSSTATE_UNKNOWN_gc = (0x00<<0), /* Unknown Bus State */
+ TWI_MASTER_BUSSTATE_IDLE_gc = (0x01<<0), /* Bus is Idle */
+ TWI_MASTER_BUSSTATE_OWNER_gc = (0x02<<0), /* This Module Controls The Bus */
+ TWI_MASTER_BUSSTATE_BUSY_gc = (0x03<<0), /* The Bus is Busy */
+} TWI_MASTER_BUSSTATE_t;
+
+/* Slave Interrupt Level */
+typedef enum TWI_SLAVE_INTLVL_enum
+{
+ TWI_SLAVE_INTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TWI_SLAVE_INTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TWI_SLAVE_INTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TWI_SLAVE_INTLVL_HI_gc = (0x03<<6), /* High Level */
+} TWI_SLAVE_INTLVL_t;
+
+/* Slave Command */
+typedef enum TWI_SLAVE_CMD_enum
+{
+ TWI_SLAVE_CMD_NOACT_gc = (0x00<<0), /* No Action */
+ TWI_SLAVE_CMD_COMPTRANS_gc = (0x02<<0), /* Used To Complete a Transaction */
+ TWI_SLAVE_CMD_RESPONSE_gc = (0x03<<0), /* Used in Response to Address/Data Interrupt */
+} TWI_SLAVE_CMD_t;
+
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O port Configuration */
+typedef struct PORTCFG_struct
+{
+ register8_t MPCMASK; /* Multi-pin Configuration Mask */
+ register8_t reserved_0x01;
+ register8_t VPCTRLA; /* Virtual Port Control Register A */
+ register8_t VPCTRLB; /* Virtual Port Control Register B */
+ register8_t CLKEVOUT; /* Clock and Event Out Register */
+} PORTCFG_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* Virtual Port */
+typedef struct VPORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t OUT; /* I/O Port Output */
+ register8_t IN; /* I/O Port Input */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+} VPORT_t;
+
+/*
+--------------------------------------------------------------------------
+PORT - Port Configuration
+--------------------------------------------------------------------------
+*/
+
+/* I/O Ports */
+typedef struct PORT_struct
+{
+ register8_t DIR; /* I/O Port Data Direction */
+ register8_t DIRSET; /* I/O Port Data Direction Set */
+ register8_t DIRCLR; /* I/O Port Data Direction Clear */
+ register8_t DIRTGL; /* I/O Port Data Direction Toggle */
+ register8_t OUT; /* I/O Port Output */
+ register8_t OUTSET; /* I/O Port Output Set */
+ register8_t OUTCLR; /* I/O Port Output Clear */
+ register8_t OUTTGL; /* I/O Port Output Toggle */
+ register8_t IN; /* I/O port Input */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t INT0MASK; /* Port Interrupt 0 Mask */
+ register8_t INT1MASK; /* Port Interrupt 1 Mask */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t reserved_0x0F;
+ register8_t PIN0CTRL; /* Pin 0 Control Register */
+ register8_t PIN1CTRL; /* Pin 1 Control Register */
+ register8_t PIN2CTRL; /* Pin 2 Control Register */
+ register8_t PIN3CTRL; /* Pin 3 Control Register */
+ register8_t PIN4CTRL; /* Pin 4 Control Register */
+ register8_t PIN5CTRL; /* Pin 5 Control Register */
+ register8_t PIN6CTRL; /* Pin 6 Control Register */
+ register8_t PIN7CTRL; /* Pin 7 Control Register */
+} PORT_t;
+
+/* Virtual Port 0 Mapping */
+typedef enum PORTCFG_VP0MAP_enum
+{
+ PORTCFG_VP0MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP0MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP0MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP0MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP0MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP0MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP0MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP0MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP0MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP0MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP0MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP0MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP0MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP0MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP0MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP0MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP0MAP_t;
+
+/* Virtual Port 1 Mapping */
+typedef enum PORTCFG_VP1MAP_enum
+{
+ PORTCFG_VP1MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP1MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP1MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP1MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP1MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP1MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP1MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP1MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP1MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP1MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP1MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP1MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP1MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP1MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP1MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP1MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP1MAP_t;
+
+/* Virtual Port 2 Mapping */
+typedef enum PORTCFG_VP2MAP_enum
+{
+ PORTCFG_VP2MAP_PORTA_gc = (0x00<<0), /* Mapped To PORTA */
+ PORTCFG_VP2MAP_PORTB_gc = (0x01<<0), /* Mapped To PORTB */
+ PORTCFG_VP2MAP_PORTC_gc = (0x02<<0), /* Mapped To PORTC */
+ PORTCFG_VP2MAP_PORTD_gc = (0x03<<0), /* Mapped To PORTD */
+ PORTCFG_VP2MAP_PORTE_gc = (0x04<<0), /* Mapped To PORTE */
+ PORTCFG_VP2MAP_PORTF_gc = (0x05<<0), /* Mapped To PORTF */
+ PORTCFG_VP2MAP_PORTG_gc = (0x06<<0), /* Mapped To PORTG */
+ PORTCFG_VP2MAP_PORTH_gc = (0x07<<0), /* Mapped To PORTH */
+ PORTCFG_VP2MAP_PORTJ_gc = (0x08<<0), /* Mapped To PORTJ */
+ PORTCFG_VP2MAP_PORTK_gc = (0x09<<0), /* Mapped To PORTK */
+ PORTCFG_VP2MAP_PORTL_gc = (0x0A<<0), /* Mapped To PORTL */
+ PORTCFG_VP2MAP_PORTM_gc = (0x0B<<0), /* Mapped To PORTM */
+ PORTCFG_VP2MAP_PORTN_gc = (0x0C<<0), /* Mapped To PORTN */
+ PORTCFG_VP2MAP_PORTP_gc = (0x0D<<0), /* Mapped To PORTP */
+ PORTCFG_VP2MAP_PORTQ_gc = (0x0E<<0), /* Mapped To PORTQ */
+ PORTCFG_VP2MAP_PORTR_gc = (0x0F<<0), /* Mapped To PORTR */
+} PORTCFG_VP2MAP_t;
+
+/* Virtual Port 3 Mapping */
+typedef enum PORTCFG_VP3MAP_enum
+{
+ PORTCFG_VP3MAP_PORTA_gc = (0x00<<4), /* Mapped To PORTA */
+ PORTCFG_VP3MAP_PORTB_gc = (0x01<<4), /* Mapped To PORTB */
+ PORTCFG_VP3MAP_PORTC_gc = (0x02<<4), /* Mapped To PORTC */
+ PORTCFG_VP3MAP_PORTD_gc = (0x03<<4), /* Mapped To PORTD */
+ PORTCFG_VP3MAP_PORTE_gc = (0x04<<4), /* Mapped To PORTE */
+ PORTCFG_VP3MAP_PORTF_gc = (0x05<<4), /* Mapped To PORTF */
+ PORTCFG_VP3MAP_PORTG_gc = (0x06<<4), /* Mapped To PORTG */
+ PORTCFG_VP3MAP_PORTH_gc = (0x07<<4), /* Mapped To PORTH */
+ PORTCFG_VP3MAP_PORTJ_gc = (0x08<<4), /* Mapped To PORTJ */
+ PORTCFG_VP3MAP_PORTK_gc = (0x09<<4), /* Mapped To PORTK */
+ PORTCFG_VP3MAP_PORTL_gc = (0x0A<<4), /* Mapped To PORTL */
+ PORTCFG_VP3MAP_PORTM_gc = (0x0B<<4), /* Mapped To PORTM */
+ PORTCFG_VP3MAP_PORTN_gc = (0x0C<<4), /* Mapped To PORTN */
+ PORTCFG_VP3MAP_PORTP_gc = (0x0D<<4), /* Mapped To PORTP */
+ PORTCFG_VP3MAP_PORTQ_gc = (0x0E<<4), /* Mapped To PORTQ */
+ PORTCFG_VP3MAP_PORTR_gc = (0x0F<<4), /* Mapped To PORTR */
+} PORTCFG_VP3MAP_t;
+
+/* Clock Output Port */
+typedef enum PORTCFG_CLKOUT_enum
+{
+ PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* Clock Output Disabled */
+ PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* Clock Output on Port C pin 7 */
+ PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* Clock Output on Port D pin 7 */
+ PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* Clock Output on Port E pin 7 */
+} PORTCFG_CLKOUT_t;
+
+/* Event Output Port */
+typedef enum PORTCFG_EVOUT_enum
+{
+ PORTCFG_EVOUT_OFF_gc = (0x00<<4), /* Event Output Disabled */
+ PORTCFG_EVOUT_PC7_gc = (0x01<<4), /* Event Channel 7 Output on Port C pin 7 */
+ PORTCFG_EVOUT_PD7_gc = (0x02<<4), /* Event Channel 7 Output on Port D pin 7 */
+ PORTCFG_EVOUT_PE7_gc = (0x03<<4), /* Event Channel 7 Output on Port E pin 7 */
+} PORTCFG_EVOUT_t;
+
+/* Port Interrupt 0 Level */
+typedef enum PORT_INT0LVL_enum
+{
+ PORT_INT0LVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ PORT_INT0LVL_LO_gc = (0x01<<0), /* Low Level */
+ PORT_INT0LVL_MED_gc = (0x02<<0), /* Medium Level */
+ PORT_INT0LVL_HI_gc = (0x03<<0), /* High Level */
+} PORT_INT0LVL_t;
+
+/* Port Interrupt 1 Level */
+typedef enum PORT_INT1LVL_enum
+{
+ PORT_INT1LVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ PORT_INT1LVL_LO_gc = (0x01<<2), /* Low Level */
+ PORT_INT1LVL_MED_gc = (0x02<<2), /* Medium Level */
+ PORT_INT1LVL_HI_gc = (0x03<<2), /* High Level */
+} PORT_INT1LVL_t;
+
+/* Output/Pull Configuration */
+typedef enum PORT_OPC_enum
+{
+ PORT_OPC_TOTEM_gc = (0x00<<3), /* Totempole */
+ PORT_OPC_BUSKEEPER_gc = (0x01<<3), /* Totempole w/ Bus keeper on Input and Output */
+ PORT_OPC_PULLDOWN_gc = (0x02<<3), /* Totempole w/ Pull-down on Input */
+ PORT_OPC_PULLUP_gc = (0x03<<3), /* Totempole w/ Pull-up on Input */
+ PORT_OPC_WIREDOR_gc = (0x04<<3), /* Wired OR */
+ PORT_OPC_WIREDAND_gc = (0x05<<3), /* Wired AND */
+ PORT_OPC_WIREDORPULL_gc = (0x06<<3), /* Wired OR w/ Pull-down */
+ PORT_OPC_WIREDANDPULL_gc = (0x07<<3), /* Wired AND w/ Pull-up */
+} PORT_OPC_t;
+
+/* Input/Sense Configuration */
+typedef enum PORT_ISC_enum
+{
+ PORT_ISC_BOTHEDGES_gc = (0x00<<0), /* Sense Both Edges */
+ PORT_ISC_RISING_gc = (0x01<<0), /* Sense Rising Edge */
+ PORT_ISC_FALLING_gc = (0x02<<0), /* Sense Falling Edge */
+ PORT_ISC_LEVEL_gc = (0x03<<0), /* Sense Level (Transparent For Events) */
+ PORT_ISC_INPUT_DISABLE_gc = (0x07<<0), /* Disable Digital Input Buffer */
+} PORT_ISC_t;
+
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 0 */
+typedef struct TC0_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ _WORDREGISTER(CCC); /* Compare or Capture C */
+ _WORDREGISTER(CCD); /* Compare or Capture D */
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+ _WORDREGISTER(CCCBUF); /* Compare Or Capture C Buffer */
+ _WORDREGISTER(CCDBUF); /* Compare Or Capture D Buffer */
+} TC0_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* 16-bit Timer/Counter 1 */
+typedef struct TC1_struct
+{
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control register C */
+ register8_t CTRLD; /* Control Register D */
+ register8_t CTRLE; /* Control Register E */
+ register8_t reserved_0x05;
+ register8_t INTCTRLA; /* Interrupt Control Register A */
+ register8_t INTCTRLB; /* Interrupt Control Register B */
+ register8_t CTRLFCLR; /* Control Register F Clear */
+ register8_t CTRLFSET; /* Control Register F Set */
+ register8_t CTRLGCLR; /* Control Register G Clear */
+ register8_t CTRLGSET; /* Control Register G Set */
+ register8_t INTFLAGS; /* Interrupt Flag Register */
+ register8_t reserved_0x0D;
+ register8_t reserved_0x0E;
+ register8_t TEMP; /* Temporary Register For 16-bit Access */
+ register8_t reserved_0x10;
+ register8_t reserved_0x11;
+ register8_t reserved_0x12;
+ register8_t reserved_0x13;
+ register8_t reserved_0x14;
+ register8_t reserved_0x15;
+ register8_t reserved_0x16;
+ register8_t reserved_0x17;
+ register8_t reserved_0x18;
+ register8_t reserved_0x19;
+ register8_t reserved_0x1A;
+ register8_t reserved_0x1B;
+ register8_t reserved_0x1C;
+ register8_t reserved_0x1D;
+ register8_t reserved_0x1E;
+ register8_t reserved_0x1F;
+ _WORDREGISTER(CNT); /* Count */
+ register8_t reserved_0x22;
+ register8_t reserved_0x23;
+ register8_t reserved_0x24;
+ register8_t reserved_0x25;
+ _WORDREGISTER(PER); /* Period */
+ _WORDREGISTER(CCA); /* Compare or Capture A */
+ _WORDREGISTER(CCB); /* Compare or Capture B */
+ register8_t reserved_0x2C;
+ register8_t reserved_0x2D;
+ register8_t reserved_0x2E;
+ register8_t reserved_0x2F;
+ register8_t reserved_0x30;
+ register8_t reserved_0x31;
+ register8_t reserved_0x32;
+ register8_t reserved_0x33;
+ register8_t reserved_0x34;
+ register8_t reserved_0x35;
+ _WORDREGISTER(PERBUF); /* Period Buffer */
+ _WORDREGISTER(CCABUF); /* Compare Or Capture A Buffer */
+ _WORDREGISTER(CCBBUF); /* Compare Or Capture B Buffer */
+} TC1_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* Advanced Waveform Extension */
+typedef struct AWEX_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t reserved_0x01;
+ register8_t FDEMASK; /* Fault Detection Event Mask */
+ register8_t FDCTRL; /* Fault Detection Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x05;
+ register8_t DTBOTH; /* Dead Time Both Sides */
+ register8_t DTBOTHBUF; /* Dead Time Both Sides Buffer */
+ register8_t DTLS; /* Dead Time Low Side */
+ register8_t DTHS; /* Dead Time High Side */
+ register8_t DTLSBUF; /* Dead Time Low Side Buffer */
+ register8_t DTHSBUF; /* Dead Time High Side Buffer */
+ register8_t OUTOVEN; /* Output Override Enable */
+} AWEX_t;
+
+/*
+--------------------------------------------------------------------------
+TC - 16-bit Timer/Counter With PWM
+--------------------------------------------------------------------------
+*/
+
+/* High-Resolution Extension */
+typedef struct HIRES_struct
+{
+ register8_t CTRLA; /* Control Register */
+} HIRES_t;
+
+/* Clock Selection */
+typedef enum TC_CLKSEL_enum
+{
+ TC_CLKSEL_OFF_gc = (0x00<<0), /* Timer Off */
+ TC_CLKSEL_DIV1_gc = (0x01<<0), /* System Clock */
+ TC_CLKSEL_DIV2_gc = (0x02<<0), /* System Clock / 2 */
+ TC_CLKSEL_DIV4_gc = (0x03<<0), /* System Clock / 4 */
+ TC_CLKSEL_DIV8_gc = (0x04<<0), /* System Clock / 8 */
+ TC_CLKSEL_DIV64_gc = (0x05<<0), /* System Clock / 64 */
+ TC_CLKSEL_DIV256_gc = (0x06<<0), /* System Clock / 256 */
+ TC_CLKSEL_DIV1024_gc = (0x07<<0), /* System Clock / 1024 */
+ TC_CLKSEL_EVCH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_CLKSEL_EVCH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_CLKSEL_EVCH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_CLKSEL_EVCH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_CLKSEL_EVCH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_CLKSEL_EVCH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_CLKSEL_EVCH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_CLKSEL_EVCH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_CLKSEL_t;
+
+/* Waveform Generation Mode */
+typedef enum TC_WGMODE_enum
+{
+ TC_WGMODE_NORMAL_gc = (0x00<<0), /* Normal Mode */
+ TC_WGMODE_FRQ_gc = (0x01<<0), /* Frequency Generation Mode */
+ TC_WGMODE_SS_gc = (0x03<<0), /* Single Slope */
+ TC_WGMODE_DS_T_gc = (0x05<<0), /* Dual Slope, Update on TOP */
+ TC_WGMODE_DS_TB_gc = (0x06<<0), /* Dual Slope, Update on TOP and BOTTOM */
+ TC_WGMODE_DS_B_gc = (0x07<<0), /* Dual Slope, Update on BOTTOM */
+} TC_WGMODE_t;
+
+/* Event Action */
+typedef enum TC_EVACT_enum
+{
+ TC_EVACT_OFF_gc = (0x00<<5), /* No Event Action */
+ TC_EVACT_CAPT_gc = (0x01<<5), /* Input Capture */
+ TC_EVACT_UPDOWN_gc = (0x02<<5), /* Externally Controlled Up/Down Count */
+ TC_EVACT_QDEC_gc = (0x03<<5), /* Quadrature Decode */
+ TC_EVACT_RESTART_gc = (0x04<<5), /* Restart */
+ TC_EVACT_FRQ_gc = (0x05<<5), /* Frequency Capture */
+ TC_EVACT_PW_gc = (0x06<<5), /* Pulse-width Capture */
+} TC_EVACT_t;
+
+/* Event Selection */
+typedef enum TC_EVSEL_enum
+{
+ TC_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ TC_EVSEL_CH0_gc = (0x08<<0), /* Event Channel 0 */
+ TC_EVSEL_CH1_gc = (0x09<<0), /* Event Channel 1 */
+ TC_EVSEL_CH2_gc = (0x0A<<0), /* Event Channel 2 */
+ TC_EVSEL_CH3_gc = (0x0B<<0), /* Event Channel 3 */
+ TC_EVSEL_CH4_gc = (0x0C<<0), /* Event Channel 4 */
+ TC_EVSEL_CH5_gc = (0x0D<<0), /* Event Channel 5 */
+ TC_EVSEL_CH6_gc = (0x0E<<0), /* Event Channel 6 */
+ TC_EVSEL_CH7_gc = (0x0F<<0), /* Event Channel 7 */
+} TC_EVSEL_t;
+
+/* Error Interrupt Level */
+typedef enum TC_ERRINTLVL_enum
+{
+ TC_ERRINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_ERRINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_ERRINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_ERRINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_ERRINTLVL_t;
+
+/* Overflow Interrupt Level */
+typedef enum TC_OVFINTLVL_enum
+{
+ TC_OVFINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_OVFINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_OVFINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_OVFINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_OVFINTLVL_t;
+
+/* Compare or Capture D Interrupt Level */
+typedef enum TC_CCDINTLVL_enum
+{
+ TC_CCDINTLVL_OFF_gc = (0x00<<6), /* Interrupt Disabled */
+ TC_CCDINTLVL_LO_gc = (0x01<<6), /* Low Level */
+ TC_CCDINTLVL_MED_gc = (0x02<<6), /* Medium Level */
+ TC_CCDINTLVL_HI_gc = (0x03<<6), /* High Level */
+} TC_CCDINTLVL_t;
+
+/* Compare or Capture C Interrupt Level */
+typedef enum TC_CCCINTLVL_enum
+{
+ TC_CCCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ TC_CCCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ TC_CCCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ TC_CCCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} TC_CCCINTLVL_t;
+
+/* Compare or Capture B Interrupt Level */
+typedef enum TC_CCBINTLVL_enum
+{
+ TC_CCBINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ TC_CCBINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ TC_CCBINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ TC_CCBINTLVL_HI_gc = (0x03<<2), /* High Level */
+} TC_CCBINTLVL_t;
+
+/* Compare or Capture A Interrupt Level */
+typedef enum TC_CCAINTLVL_enum
+{
+ TC_CCAINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ TC_CCAINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ TC_CCAINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ TC_CCAINTLVL_HI_gc = (0x03<<0), /* High Level */
+} TC_CCAINTLVL_t;
+
+/* Timer/Counter Command */
+typedef enum TC_CMD_enum
+{
+ TC_CMD_NONE_gc = (0x00<<2), /* No Command */
+ TC_CMD_UPDATE_gc = (0x01<<2), /* Force Update */
+ TC_CMD_RESTART_gc = (0x02<<2), /* Force Restart */
+ TC_CMD_RESET_gc = (0x03<<2), /* Force Hard Reset */
+} TC_CMD_t;
+
+/* Fault Detect Action */
+typedef enum AWEX_FDACT_enum
+{
+ AWEX_FDACT_NONE_gc = (0x00<<0), /* No Fault Protection */
+ AWEX_FDACT_CLEAROE_gc = (0x01<<0), /* Clear Output Enable Bits */
+ AWEX_FDACT_CLEARDIR_gc = (0x03<<0), /* Clear I/O Port Direction Bits */
+} AWEX_FDACT_t;
+
+/* High Resolution Enable */
+typedef enum HIRES_HREN_enum
+{
+ HIRES_HREN_NONE_gc = (0x00<<0), /* No Fault Protection */
+ HIRES_HREN_TC0_gc = (0x01<<0), /* Enable High Resolution on Timer/Counter 0 */
+ HIRES_HREN_TC1_gc = (0x02<<0), /* Enable High Resolution on Timer/Counter 1 */
+ HIRES_HREN_BOTH_gc = (0x03<<0), /* Enable High Resolution both Timer/Counters */
+} HIRES_HREN_t;
+
+
+/*
+--------------------------------------------------------------------------
+USART - Universal Asynchronous Receiver-Transmitter
+--------------------------------------------------------------------------
+*/
+
+/* Universal Synchronous/Asynchronous Receiver/Transmitter */
+typedef struct USART_struct
+{
+ register8_t DATA; /* Data Register */
+ register8_t STATUS; /* Status Register */
+ register8_t reserved_0x02;
+ register8_t CTRLA; /* Control Register A */
+ register8_t CTRLB; /* Control Register B */
+ register8_t CTRLC; /* Control Register C */
+ register8_t BAUDCTRLA; /* Baud Rate Control Register A */
+ register8_t BAUDCTRLB; /* Baud Rate Control Register B */
+} USART_t;
+
+/* Receive Complete Interrupt level */
+typedef enum USART_RXCINTLVL_enum
+{
+ USART_RXCINTLVL_OFF_gc = (0x00<<4), /* Interrupt Disabled */
+ USART_RXCINTLVL_LO_gc = (0x01<<4), /* Low Level */
+ USART_RXCINTLVL_MED_gc = (0x02<<4), /* Medium Level */
+ USART_RXCINTLVL_HI_gc = (0x03<<4), /* High Level */
+} USART_RXCINTLVL_t;
+
+/* Transmit Complete Interrupt level */
+typedef enum USART_TXCINTLVL_enum
+{
+ USART_TXCINTLVL_OFF_gc = (0x00<<2), /* Interrupt Disabled */
+ USART_TXCINTLVL_LO_gc = (0x01<<2), /* Low Level */
+ USART_TXCINTLVL_MED_gc = (0x02<<2), /* Medium Level */
+ USART_TXCINTLVL_HI_gc = (0x03<<2), /* High Level */
+} USART_TXCINTLVL_t;
+
+/* Data Register Empty Interrupt level */
+typedef enum USART_DREINTLVL_enum
+{
+ USART_DREINTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ USART_DREINTLVL_LO_gc = (0x01<<0), /* Low Level */
+ USART_DREINTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ USART_DREINTLVL_HI_gc = (0x03<<0), /* High Level */
+} USART_DREINTLVL_t;
+
+/* Character Size */
+typedef enum USART_CHSIZE_enum
+{
+ USART_CHSIZE_5BIT_gc = (0x00<<0), /* Character size: 5 bit */
+ USART_CHSIZE_6BIT_gc = (0x01<<0), /* Character size: 6 bit */
+ USART_CHSIZE_7BIT_gc = (0x02<<0), /* Character size: 7 bit */
+ USART_CHSIZE_8BIT_gc = (0x03<<0), /* Character size: 8 bit */
+ USART_CHSIZE_9BIT_gc = (0x07<<0), /* Character size: 9 bit */
+} USART_CHSIZE_t;
+
+/* Communication Mode */
+typedef enum USART_CMODE_enum
+{
+ USART_CMODE_ASYNCHRONOUS_gc = (0x00<<6), /* Asynchronous Mode */
+ USART_CMODE_SYNCHRONOUS_gc = (0x01<<6), /* Synchronous Mode */
+ USART_CMODE_IRDA_gc = (0x02<<6), /* IrDA Mode */
+ USART_CMODE_MSPI_gc = (0x03<<6), /* Master SPI Mode */
+} USART_CMODE_t;
+
+/* Parity Mode */
+typedef enum USART_PMODE_enum
+{
+ USART_PMODE_DISABLED_gc = (0x00<<4), /* No Parity */
+ USART_PMODE_EVEN_gc = (0x02<<4), /* Even Parity */
+ USART_PMODE_ODD_gc = (0x03<<4), /* Odd Parity */
+} USART_PMODE_t;
+
+
+/*
+--------------------------------------------------------------------------
+SPI - Serial Peripheral Interface
+--------------------------------------------------------------------------
+*/
+
+/* Serial Peripheral Interface */
+typedef struct SPI_struct
+{
+ register8_t CTRL; /* Control Register */
+ register8_t INTCTRL; /* Interrupt Control Register */
+ register8_t STATUS; /* Status Register */
+ register8_t DATA; /* Data Register */
+} SPI_t;
+
+/* SPI Mode */
+typedef enum SPI_MODE_enum
+{
+ SPI_MODE_0_gc = (0x00<<2), /* SPI Mode 0 */
+ SPI_MODE_1_gc = (0x01<<2), /* SPI Mode 1 */
+ SPI_MODE_2_gc = (0x02<<2), /* SPI Mode 2 */
+ SPI_MODE_3_gc = (0x03<<2), /* SPI Mode 3 */
+} SPI_MODE_t;
+
+/* Prescaler setting */
+typedef enum SPI_PRESCALER_enum
+{
+ SPI_PRESCALER_DIV4_gc = (0x00<<0), /* System Clock / 4 */
+ SPI_PRESCALER_DIV16_gc = (0x01<<0), /* System Clock / 16 */
+ SPI_PRESCALER_DIV64_gc = (0x02<<0), /* System Clock / 64 */
+ SPI_PRESCALER_DIV128_gc = (0x03<<0), /* System Clock / 128 */
+} SPI_PRESCALER_t;
+
+/* Interrupt level */
+typedef enum SPI_INTLVL_enum
+{
+ SPI_INTLVL_OFF_gc = (0x00<<0), /* Interrupt Disabled */
+ SPI_INTLVL_LO_gc = (0x01<<0), /* Low Level */
+ SPI_INTLVL_MED_gc = (0x02<<0), /* Medium Level */
+ SPI_INTLVL_HI_gc = (0x03<<0), /* High Level */
+} SPI_INTLVL_t;
+
+
+/*
+--------------------------------------------------------------------------
+IRCOM - IR Communication Module
+--------------------------------------------------------------------------
+*/
+
+/* IR Communication Module */
+typedef struct IRCOM_struct
+{
+ register8_t TXPLCTRL; /* IrDA Transmitter Pulse Length Control Register */
+ register8_t RXPLCTRL; /* IrDA Receiver Pulse Length Control Register */
+ register8_t CTRL; /* Control Register */
+} IRCOM_t;
+
+/* Event channel selection */
+typedef enum IRDA_EVSEL_enum
+{
+ IRDA_EVSEL_OFF_gc = (0x00<<0), /* No Event Source */
+ IRDA_EVSEL_0_gc = (0x08<<0), /* Event Channel 0 */
+ IRDA_EVSEL_1_gc = (0x09<<0), /* Event Channel 1 */
+ IRDA_EVSEL_2_gc = (0x0A<<0), /* Event Channel 2 */
+ IRDA_EVSEL_3_gc = (0x0B<<0), /* Event Channel 3 */
+ IRDA_EVSEL_4_gc = (0x0C<<0), /* Event Channel 4 */
+ IRDA_EVSEL_5_gc = (0x0D<<0), /* Event Channel 5 */
+ IRDA_EVSEL_6_gc = (0x0E<<0), /* Event Channel 6 */
+ IRDA_EVSEL_7_gc = (0x0F<<0), /* Event Channel 7 */
+} IRDA_EVSEL_t;
+
+
+
+/*
+==========================================================================
+IO Module Instances. Mapped to memory.
+==========================================================================
+*/
+
+#define GPIO (*(GPIO_t *) 0x0000) /* General Purpose IO Registers */
+#define VPORT0 (*(VPORT_t *) 0x0010) /* Virtual Port 0 */
+#define VPORT1 (*(VPORT_t *) 0x0014) /* Virtual Port 1 */
+#define VPORT2 (*(VPORT_t *) 0x0018) /* Virtual Port 2 */
+#define VPORT3 (*(VPORT_t *) 0x001C) /* Virtual Port 3 */
+#define OCD (*(OCD_t *) 0x002E) /* On-Chip Debug System */
+#define CPU (*(CPU_t *) 0x0030) /* CPU Registers */
+#define CLK (*(CLK_t *) 0x0040) /* Clock System */
+#define SLEEP (*(SLEEP_t *) 0x0048) /* Sleep Controller */
+#define OSC (*(OSC_t *) 0x0050) /* Oscillator Control */
+#define DFLLRC32M (*(DFLL_t *) 0x0060) /* DFLL for 32MHz RC Oscillator */
+#define DFLLRC2M (*(DFLL_t *) 0x0068) /* DFLL for 2MHz RC Oscillator */
+#define PR (*(PR_t *) 0x0070) /* Power Reduction */
+#define RST (*(RST_t *) 0x0078) /* Reset Controller */
+#define WDT (*(WDT_t *) 0x0080) /* Watch-Dog Timer */
+#define MCU (*(MCU_t *) 0x0090) /* MCU Control */
+#define PMIC (*(PMIC_t *) 0x00A0) /* Programmable Interrupt Controller */
+#define PORTCFG (*(PORTCFG_t *) 0x00B0) /* Port Configuration */
+#define EVSYS (*(EVSYS_t *) 0x0180) /* Event System */
+#define NVM (*(NVM_t *) 0x01C0) /* Non Volatile Memory Controller */
+#define ADCA (*(ADC_t *) 0x0200) /* Analog to Digital Converter A */
+#define DACB (*(DAC_t *) 0x0320) /* Digital to Analog Converter B */
+#define ACA (*(AC_t *) 0x0380) /* Analog Comparator A */
+#define ACB (*(AC_t *) 0x0390) /* Analog Comparator B */
+#define RTC (*(RTC_t *) 0x0400) /* Real-Time Counter */
+#define TWIC (*(TWI_t *) 0x0480) /* Two-Wire Interface C */
+#define PORTA (*(PORT_t *) 0x0600) /* Port A */
+#define PORTB (*(PORT_t *) 0x0620) /* Port B */
+#define PORTC (*(PORT_t *) 0x0640) /* Port C */
+#define PORTD (*(PORT_t *) 0x0660) /* Port D */
+#define PORTE (*(PORT_t *) 0x0680) /* Port E */
+#define PORTF (*(PORT_t *) 0x06A0) /* Port F */
+#define PORTR (*(PORT_t *) 0x07E0) /* Port R */
+#define TCC0 (*(TC0_t *) 0x0800) /* Timer/Counter C0 */
+#define TCC1 (*(TC1_t *) 0x0840) /* Timer/Counter C1 */
+#define AWEXC (*(AWEX_t *) 0x0880) /* Advanced Waveform Extension C */
+#define HIRESC (*(HIRES_t *) 0x0890) /* High-Resolution Extension C */
+#define USARTC0 (*(USART_t *) 0x08A0) /* Universal Asynchronous Receiver-Transmitter C0 */
+#define SPIC (*(SPI_t *) 0x08C0) /* Serial Peripheral Interface C */
+#define IRCOM (*(IRCOM_t *) 0x08F8) /* IR Communication Module */
+#define TCD0 (*(TC0_t *) 0x0900) /* Timer/Counter D0 */
+#define USARTD0 (*(USART_t *) 0x09A0) /* Universal Asynchronous Receiver-Transmitter D0 */
+#define SPID (*(SPI_t *) 0x09C0) /* Serial Peripheral Interface D */
+#define TCE0 (*(TC0_t *) 0x0A00) /* Timer/Counter E0 */
+#define AWEXE (*(AWEX_t *) 0x0A80) /* Advanced Waveform Extension E */
+#define USARTE0 (*(USART_t *) 0x0AA0) /* Universal Asynchronous Receiver-Transmitter E0 */
+#define SPIE (*(SPI_t *) 0x0AC0) /* Serial Peripheral Interface E */
+#define TCF0 (*(TC0_t *) 0x0B00) /* Timer/Counter F0 */
+
+
+#endif /* !defined (__ASSEMBLER__) */
+
+
+/* ========== Flattened fully qualified IO register names ========== */
+
+/* GPIO - General Purpose IO Registers */
+#define GPIO_GPIOR0 _SFR_MEM8(0x0000)
+#define GPIO_GPIOR1 _SFR_MEM8(0x0001)
+#define GPIO_GPIOR2 _SFR_MEM8(0x0002)
+#define GPIO_GPIOR3 _SFR_MEM8(0x0003)
+#define GPIO_GPIOR4 _SFR_MEM8(0x0004)
+#define GPIO_GPIOR5 _SFR_MEM8(0x0005)
+#define GPIO_GPIOR6 _SFR_MEM8(0x0006)
+#define GPIO_GPIOR7 _SFR_MEM8(0x0007)
+#define GPIO_GPIOR8 _SFR_MEM8(0x0008)
+#define GPIO_GPIOR9 _SFR_MEM8(0x0009)
+#define GPIO_GPIORA _SFR_MEM8(0x000A)
+#define GPIO_GPIORB _SFR_MEM8(0x000B)
+#define GPIO_GPIORC _SFR_MEM8(0x000C)
+#define GPIO_GPIORD _SFR_MEM8(0x000D)
+#define GPIO_GPIORE _SFR_MEM8(0x000E)
+#define GPIO_GPIORF _SFR_MEM8(0x000F)
+
+/* VPORT0 - Virtual Port 0 */
+#define VPORT0_DIR _SFR_MEM8(0x0010)
+#define VPORT0_OUT _SFR_MEM8(0x0011)
+#define VPORT0_IN _SFR_MEM8(0x0012)
+#define VPORT0_INTFLAGS _SFR_MEM8(0x0013)
+
+/* VPORT1 - Virtual Port 1 */
+#define VPORT1_DIR _SFR_MEM8(0x0014)
+#define VPORT1_OUT _SFR_MEM8(0x0015)
+#define VPORT1_IN _SFR_MEM8(0x0016)
+#define VPORT1_INTFLAGS _SFR_MEM8(0x0017)
+
+/* VPORT2 - Virtual Port 2 */
+#define VPORT2_DIR _SFR_MEM8(0x0018)
+#define VPORT2_OUT _SFR_MEM8(0x0019)
+#define VPORT2_IN _SFR_MEM8(0x001A)
+#define VPORT2_INTFLAGS _SFR_MEM8(0x001B)
+
+/* VPORT3 - Virtual Port 3 */
+#define VPORT3_DIR _SFR_MEM8(0x001C)
+#define VPORT3_OUT _SFR_MEM8(0x001D)
+#define VPORT3_IN _SFR_MEM8(0x001E)
+#define VPORT3_INTFLAGS _SFR_MEM8(0x001F)
+
+/* OCD - On-Chip Debug System */
+#define OCD_OCDR0 _SFR_MEM8(0x002E)
+#define OCD_OCDR1 _SFR_MEM8(0x002F)
+
+/* CPU - CPU Registers */
+#define CPU_CCP _SFR_MEM8(0x0034)
+#define CPU_RAMPD _SFR_MEM8(0x0038)
+#define CPU_RAMPX _SFR_MEM8(0x0039)
+#define CPU_RAMPY _SFR_MEM8(0x003A)
+#define CPU_RAMPZ _SFR_MEM8(0x003B)
+#define CPU_EIND _SFR_MEM8(0x003C)
+#define CPU_SPL _SFR_MEM8(0x003D)
+#define CPU_SPH _SFR_MEM8(0x003E)
+#define CPU_SREG _SFR_MEM8(0x003F)
+
+/* CLK - Clock System */
+#define CLK_CTRL _SFR_MEM8(0x0040)
+#define CLK_PSCTRL _SFR_MEM8(0x0041)
+#define CLK_LOCK _SFR_MEM8(0x0042)
+#define CLK_RTCCTRL _SFR_MEM8(0x0043)
+
+/* SLEEP - Sleep Controller */
+#define SLEEP_CTRL _SFR_MEM8(0x0048)
+
+/* OSC - Oscillator Control */
+#define OSC_CTRL _SFR_MEM8(0x0050)
+#define OSC_STATUS _SFR_MEM8(0x0051)
+#define OSC_XOSCCTRL _SFR_MEM8(0x0052)
+#define OSC_XOSCFAIL _SFR_MEM8(0x0053)
+#define OSC_RC32KCAL _SFR_MEM8(0x0054)
+#define OSC_PLLCTRL _SFR_MEM8(0x0055)
+#define OSC_DFLLCTRL _SFR_MEM8(0x0056)
+
+/* DFLLRC32M - DFLL for 32MHz RC Oscillator */
+#define DFLLRC32M_CTRL _SFR_MEM8(0x0060)
+#define DFLLRC32M_CALA _SFR_MEM8(0x0062)
+#define DFLLRC32M_CALB _SFR_MEM8(0x0063)
+#define DFLLRC32M_COMP0 _SFR_MEM8(0x0064)
+#define DFLLRC32M_COMP1 _SFR_MEM8(0x0065)
+#define DFLLRC32M_COMP2 _SFR_MEM8(0x0066)
+
+/* DFLLRC2M - DFLL for 2MHz RC Oscillator */
+#define DFLLRC2M_CTRL _SFR_MEM8(0x0068)
+#define DFLLRC2M_CALA _SFR_MEM8(0x006A)
+#define DFLLRC2M_CALB _SFR_MEM8(0x006B)
+#define DFLLRC2M_COMP0 _SFR_MEM8(0x006C)
+#define DFLLRC2M_COMP1 _SFR_MEM8(0x006D)
+#define DFLLRC2M_COMP2 _SFR_MEM8(0x006E)
+
+/* PR - Power Reduction */
+#define PR_PRGEN _SFR_MEM8(0x0070)
+#define PR_PRPA _SFR_MEM8(0x0071)
+#define PR_PRPB _SFR_MEM8(0x0072)
+#define PR_PRPC _SFR_MEM8(0x0073)
+#define PR_PRPD _SFR_MEM8(0x0074)
+#define PR_PRPE _SFR_MEM8(0x0075)
+#define PR_PRPF _SFR_MEM8(0x0076)
+
+/* RST - Reset Controller */
+#define RST_STATUS _SFR_MEM8(0x0078)
+#define RST_CTRL _SFR_MEM8(0x0079)
+
+/* WDT - Watch-Dog Timer */
+#define WDT_CTRL _SFR_MEM8(0x0080)
+#define WDT_WINCTRL _SFR_MEM8(0x0081)
+#define WDT_STATUS _SFR_MEM8(0x0082)
+
+/* MCU - MCU Control */
+#define MCU_DEVID0 _SFR_MEM8(0x0090)
+#define MCU_DEVID1 _SFR_MEM8(0x0091)
+#define MCU_DEVID2 _SFR_MEM8(0x0092)
+#define MCU_REVID _SFR_MEM8(0x0093)
+#define MCU_JTAGUID _SFR_MEM8(0x0094)
+#define MCU_MCUCR _SFR_MEM8(0x0096)
+#define MCU_EVSYSLOCK _SFR_MEM8(0x0098)
+#define MCU_AWEXLOCK _SFR_MEM8(0x0099)
+
+/* PMIC - Programmable Interrupt Controller */
+#define PMIC_STATUS _SFR_MEM8(0x00A0)
+#define PMIC_INTPRI _SFR_MEM8(0x00A1)
+#define PMIC_CTRL _SFR_MEM8(0x00A2)
+
+/* PORTCFG - Port Configuration */
+#define PORTCFG_MPCMASK _SFR_MEM8(0x00B0)
+#define PORTCFG_VPCTRLA _SFR_MEM8(0x00B2)
+#define PORTCFG_VPCTRLB _SFR_MEM8(0x00B3)
+#define PORTCFG_CLKEVOUT _SFR_MEM8(0x00B4)
+
+/* EVSYS - Event System */
+#define EVSYS_CH0MUX _SFR_MEM8(0x0180)
+#define EVSYS_CH1MUX _SFR_MEM8(0x0181)
+#define EVSYS_CH2MUX _SFR_MEM8(0x0182)
+#define EVSYS_CH3MUX _SFR_MEM8(0x0183)
+#define EVSYS_CH0CTRL _SFR_MEM8(0x0188)
+#define EVSYS_CH1CTRL _SFR_MEM8(0x0189)
+#define EVSYS_CH2CTRL _SFR_MEM8(0x018A)
+#define EVSYS_CH3CTRL _SFR_MEM8(0x018B)
+#define EVSYS_STROBE _SFR_MEM8(0x0190)
+#define EVSYS_DATA _SFR_MEM8(0x0191)
+
+/* NVM - Non Volatile Memory Controller */
+#define NVM_ADDR0 _SFR_MEM8(0x01C0)
+#define NVM_ADDR1 _SFR_MEM8(0x01C1)
+#define NVM_ADDR2 _SFR_MEM8(0x01C2)
+#define NVM_DATA0 _SFR_MEM8(0x01C4)
+#define NVM_DATA1 _SFR_MEM8(0x01C5)
+#define NVM_DATA2 _SFR_MEM8(0x01C6)
+#define NVM_CMD _SFR_MEM8(0x01CA)
+#define NVM_CTRLA _SFR_MEM8(0x01CB)
+#define NVM_CTRLB _SFR_MEM8(0x01CC)
+#define NVM_INTCTRL _SFR_MEM8(0x01CD)
+#define NVM_STATUS _SFR_MEM8(0x01CF)
+#define NVM_LOCKBITS _SFR_MEM8(0x01D0)
+
+/* ADCA - Analog to Digital Converter A */
+#define ADCA_CTRLA _SFR_MEM8(0x0200)
+#define ADCA_CTRLB _SFR_MEM8(0x0201)
+#define ADCA_REFCTRL _SFR_MEM8(0x0202)
+#define ADCA_EVCTRL _SFR_MEM8(0x0203)
+#define ADCA_PRESCALER _SFR_MEM8(0x0204)
+#define ADCA_CALCTRL _SFR_MEM8(0x0205)
+#define ADCA_INTFLAGS _SFR_MEM8(0x0206)
+#define ADCA_CAL _SFR_MEM16(0x020C)
+#define ADCA_CH0RES _SFR_MEM16(0x0210)
+#define ADCA_CMP _SFR_MEM16(0x0218)
+#define ADCA_CH0_CTRL _SFR_MEM8(0x0220)
+#define ADCA_CH0_MUXCTRL _SFR_MEM8(0x0221)
+#define ADCA_CH0_INTCTRL _SFR_MEM8(0x0222)
+#define ADCA_CH0_INTFLAGS _SFR_MEM8(0x0223)
+#define ADCA_CH0_RES _SFR_MEM16(0x0224)
+
+/* DACB - Digital to Analog Converter B */
+
+/* ACA - Analog Comparator A */
+#define ACA_AC0CTRL _SFR_MEM8(0x0380)
+#define ACA_AC1CTRL _SFR_MEM8(0x0381)
+#define ACA_AC0MUXCTRL _SFR_MEM8(0x0382)
+#define ACA_AC1MUXCTRL _SFR_MEM8(0x0383)
+#define ACA_CTRLA _SFR_MEM8(0x0384)
+#define ACA_CTRLB _SFR_MEM8(0x0385)
+#define ACA_WINCTRL _SFR_MEM8(0x0386)
+#define ACA_STATUS _SFR_MEM8(0x0387)
+
+/* ACB - Analog Comparator B */
+#define ACB_AC0CTRL _SFR_MEM8(0x0390)
+#define ACB_AC1CTRL _SFR_MEM8(0x0391)
+#define ACB_AC0MUXCTRL _SFR_MEM8(0x0392)
+#define ACB_AC1MUXCTRL _SFR_MEM8(0x0393)
+#define ACB_CTRLA _SFR_MEM8(0x0394)
+#define ACB_CTRLB _SFR_MEM8(0x0395)
+#define ACB_WINCTRL _SFR_MEM8(0x0396)
+#define ACB_STATUS _SFR_MEM8(0x0397)
+
+/* RTC - Real-Time Counter */
+#define RTC_CTRL _SFR_MEM8(0x0400)
+#define RTC_STATUS _SFR_MEM8(0x0401)
+#define RTC_INTCTRL _SFR_MEM8(0x0402)
+#define RTC_INTFLAGS _SFR_MEM8(0x0403)
+#define RTC_TEMP _SFR_MEM8(0x0404)
+#define RTC_CNT _SFR_MEM16(0x0408)
+#define RTC_PER _SFR_MEM16(0x040A)
+#define RTC_COMP _SFR_MEM16(0x040C)
+
+/* TWIC - Two-Wire Interface C */
+#define TWIC_CTRL _SFR_MEM8(0x0480)
+#define TWIC_MASTER_CTRLA _SFR_MEM8(0x0482)
+#define TWIC_MASTER_CTRLB _SFR_MEM8(0x0483)
+#define TWIC_MASTER_CTRLC _SFR_MEM8(0x0484)
+#define TWIC_MASTER_STATUS _SFR_MEM8(0x0485)
+#define TWIC_MASTER_BAUD _SFR_MEM8(0x0486)
+#define TWIC_MASTER_ADDR _SFR_MEM8(0x0487)
+#define TWIC_MASTER_DATA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLA _SFR_MEM8(0x0488)
+#define TWIC_SLAVE_CTRLB _SFR_MEM8(0x0489)
+#define TWIC_SLAVE_STATUS _SFR_MEM8(0x048A)
+#define TWIC_SLAVE_ADDR _SFR_MEM8(0x048B)
+#define TWIC_SLAVE_DATA _SFR_MEM8(0x048C)
+#define TWIC_SLAVE_ADDRMASK _SFR_MEM8(0x048D)
+
+/* PORTA - Port A */
+#define PORTA_DIR _SFR_MEM8(0x0600)
+#define PORTA_DIRSET _SFR_MEM8(0x0601)
+#define PORTA_DIRCLR _SFR_MEM8(0x0602)
+#define PORTA_DIRTGL _SFR_MEM8(0x0603)
+#define PORTA_OUT _SFR_MEM8(0x0604)
+#define PORTA_OUTSET _SFR_MEM8(0x0605)
+#define PORTA_OUTCLR _SFR_MEM8(0x0606)
+#define PORTA_OUTTGL _SFR_MEM8(0x0607)
+#define PORTA_IN _SFR_MEM8(0x0608)
+#define PORTA_INTCTRL _SFR_MEM8(0x0609)
+#define PORTA_INT0MASK _SFR_MEM8(0x060A)
+#define PORTA_INT1MASK _SFR_MEM8(0x060B)
+#define PORTA_INTFLAGS _SFR_MEM8(0x060C)
+#define PORTA_PIN0CTRL _SFR_MEM8(0x0610)
+#define PORTA_PIN1CTRL _SFR_MEM8(0x0611)
+#define PORTA_PIN2CTRL _SFR_MEM8(0x0612)
+#define PORTA_PIN3CTRL _SFR_MEM8(0x0613)
+#define PORTA_PIN4CTRL _SFR_MEM8(0x0614)
+#define PORTA_PIN5CTRL _SFR_MEM8(0x0615)
+#define PORTA_PIN6CTRL _SFR_MEM8(0x0616)
+#define PORTA_PIN7CTRL _SFR_MEM8(0x0617)
+
+/* PORTB - Port B */
+#define PORTB_DIR _SFR_MEM8(0x0620)
+#define PORTB_DIRSET _SFR_MEM8(0x0621)
+#define PORTB_DIRCLR _SFR_MEM8(0x0622)
+#define PORTB_DIRTGL _SFR_MEM8(0x0623)
+#define PORTB_OUT _SFR_MEM8(0x0624)
+#define PORTB_OUTSET _SFR_MEM8(0x0625)
+#define PORTB_OUTCLR _SFR_MEM8(0x0626)
+#define PORTB_OUTTGL _SFR_MEM8(0x0627)
+#define PORTB_IN _SFR_MEM8(0x0628)
+#define PORTB_INTCTRL _SFR_MEM8(0x0629)
+#define PORTB_INT0MASK _SFR_MEM8(0x062A)
+#define PORTB_INT1MASK _SFR_MEM8(0x062B)
+#define PORTB_INTFLAGS _SFR_MEM8(0x062C)
+#define PORTB_PIN0CTRL _SFR_MEM8(0x0630)
+#define PORTB_PIN1CTRL _SFR_MEM8(0x0631)
+#define PORTB_PIN2CTRL _SFR_MEM8(0x0632)
+#define PORTB_PIN3CTRL _SFR_MEM8(0x0633)
+#define PORTB_PIN4CTRL _SFR_MEM8(0x0634)
+#define PORTB_PIN5CTRL _SFR_MEM8(0x0635)
+#define PORTB_PIN6CTRL _SFR_MEM8(0x0636)
+#define PORTB_PIN7CTRL _SFR_MEM8(0x0637)
+
+/* PORTC - Port C */
+#define PORTC_DIR _SFR_MEM8(0x0640)
+#define PORTC_DIRSET _SFR_MEM8(0x0641)
+#define PORTC_DIRCLR _SFR_MEM8(0x0642)
+#define PORTC_DIRTGL _SFR_MEM8(0x0643)
+#define PORTC_OUT _SFR_MEM8(0x0644)
+#define PORTC_OUTSET _SFR_MEM8(0x0645)
+#define PORTC_OUTCLR _SFR_MEM8(0x0646)
+#define PORTC_OUTTGL _SFR_MEM8(0x0647)
+#define PORTC_IN _SFR_MEM8(0x0648)
+#define PORTC_INTCTRL _SFR_MEM8(0x0649)
+#define PORTC_INT0MASK _SFR_MEM8(0x064A)
+#define PORTC_INT1MASK _SFR_MEM8(0x064B)
+#define PORTC_INTFLAGS _SFR_MEM8(0x064C)
+#define PORTC_PIN0CTRL _SFR_MEM8(0x0650)
+#define PORTC_PIN1CTRL _SFR_MEM8(0x0651)
+#define PORTC_PIN2CTRL _SFR_MEM8(0x0652)
+#define PORTC_PIN3CTRL _SFR_MEM8(0x0653)
+#define PORTC_PIN4CTRL _SFR_MEM8(0x0654)
+#define PORTC_PIN5CTRL _SFR_MEM8(0x0655)
+#define PORTC_PIN6CTRL _SFR_MEM8(0x0656)
+#define PORTC_PIN7CTRL _SFR_MEM8(0x0657)
+
+/* PORTD - Port D */
+#define PORTD_DIR _SFR_MEM8(0x0660)
+#define PORTD_DIRSET _SFR_MEM8(0x0661)
+#define PORTD_DIRCLR _SFR_MEM8(0x0662)
+#define PORTD_DIRTGL _SFR_MEM8(0x0663)
+#define PORTD_OUT _SFR_MEM8(0x0664)
+#define PORTD_OUTSET _SFR_MEM8(0x0665)
+#define PORTD_OUTCLR _SFR_MEM8(0x0666)
+#define PORTD_OUTTGL _SFR_MEM8(0x0667)
+#define PORTD_IN _SFR_MEM8(0x0668)
+#define PORTD_INTCTRL _SFR_MEM8(0x0669)
+#define PORTD_INT0MASK _SFR_MEM8(0x066A)
+#define PORTD_INT1MASK _SFR_MEM8(0x066B)
+#define PORTD_INTFLAGS _SFR_MEM8(0x066C)
+#define PORTD_PIN0CTRL _SFR_MEM8(0x0670)
+#define PORTD_PIN1CTRL _SFR_MEM8(0x0671)
+#define PORTD_PIN2CTRL _SFR_MEM8(0x0672)
+#define PORTD_PIN3CTRL _SFR_MEM8(0x0673)
+#define PORTD_PIN4CTRL _SFR_MEM8(0x0674)
+#define PORTD_PIN5CTRL _SFR_MEM8(0x0675)
+#define PORTD_PIN6CTRL _SFR_MEM8(0x0676)
+#define PORTD_PIN7CTRL _SFR_MEM8(0x0677)
+
+/* PORTE - Port E */
+#define PORTE_DIR _SFR_MEM8(0x0680)
+#define PORTE_DIRSET _SFR_MEM8(0x0681)
+#define PORTE_DIRCLR _SFR_MEM8(0x0682)
+#define PORTE_DIRTGL _SFR_MEM8(0x0683)
+#define PORTE_OUT _SFR_MEM8(0x0684)
+#define PORTE_OUTSET _SFR_MEM8(0x0685)
+#define PORTE_OUTCLR _SFR_MEM8(0x0686)
+#define PORTE_OUTTGL _SFR_MEM8(0x0687)
+#define PORTE_IN _SFR_MEM8(0x0688)
+#define PORTE_INTCTRL _SFR_MEM8(0x0689)
+#define PORTE_INT0MASK _SFR_MEM8(0x068A)
+#define PORTE_INT1MASK _SFR_MEM8(0x068B)
+#define PORTE_INTFLAGS _SFR_MEM8(0x068C)
+#define PORTE_PIN0CTRL _SFR_MEM8(0x0690)
+#define PORTE_PIN1CTRL _SFR_MEM8(0x0691)
+#define PORTE_PIN2CTRL _SFR_MEM8(0x0692)
+#define PORTE_PIN3CTRL _SFR_MEM8(0x0693)
+#define PORTE_PIN4CTRL _SFR_MEM8(0x0694)
+#define PORTE_PIN5CTRL _SFR_MEM8(0x0695)
+#define PORTE_PIN6CTRL _SFR_MEM8(0x0696)
+#define PORTE_PIN7CTRL _SFR_MEM8(0x0697)
+
+/* PORTF - Port F */
+#define PORTF_DIR _SFR_MEM8(0x06A0)
+#define PORTF_DIRSET _SFR_MEM8(0x06A1)
+#define PORTF_DIRCLR _SFR_MEM8(0x06A2)
+#define PORTF_DIRTGL _SFR_MEM8(0x06A3)
+#define PORTF_OUT _SFR_MEM8(0x06A4)
+#define PORTF_OUTSET _SFR_MEM8(0x06A5)
+#define PORTF_OUTCLR _SFR_MEM8(0x06A6)
+#define PORTF_OUTTGL _SFR_MEM8(0x06A7)
+#define PORTF_IN _SFR_MEM8(0x06A8)
+#define PORTF_INTCTRL _SFR_MEM8(0x06A9)
+#define PORTF_INT0MASK _SFR_MEM8(0x06AA)
+#define PORTF_INT1MASK _SFR_MEM8(0x06AB)
+#define PORTF_INTFLAGS _SFR_MEM8(0x06AC)
+#define PORTF_PIN0CTRL _SFR_MEM8(0x06B0)
+#define PORTF_PIN1CTRL _SFR_MEM8(0x06B1)
+#define PORTF_PIN2CTRL _SFR_MEM8(0x06B2)
+#define PORTF_PIN3CTRL _SFR_MEM8(0x06B3)
+#define PORTF_PIN4CTRL _SFR_MEM8(0x06B4)
+#define PORTF_PIN5CTRL _SFR_MEM8(0x06B5)
+#define PORTF_PIN6CTRL _SFR_MEM8(0x06B6)
+#define PORTF_PIN7CTRL _SFR_MEM8(0x06B7)
+
+/* PORTR - Port R */
+#define PORTR_DIR _SFR_MEM8(0x07E0)
+#define PORTR_DIRSET _SFR_MEM8(0x07E1)
+#define PORTR_DIRCLR _SFR_MEM8(0x07E2)
+#define PORTR_DIRTGL _SFR_MEM8(0x07E3)
+#define PORTR_OUT _SFR_MEM8(0x07E4)
+#define PORTR_OUTSET _SFR_MEM8(0x07E5)
+#define PORTR_OUTCLR _SFR_MEM8(0x07E6)
+#define PORTR_OUTTGL _SFR_MEM8(0x07E7)
+#define PORTR_IN _SFR_MEM8(0x07E8)
+#define PORTR_INTCTRL _SFR_MEM8(0x07E9)
+#define PORTR_INT0MASK _SFR_MEM8(0x07EA)
+#define PORTR_INT1MASK _SFR_MEM8(0x07EB)
+#define PORTR_INTFLAGS _SFR_MEM8(0x07EC)
+#define PORTR_PIN0CTRL _SFR_MEM8(0x07F0)
+#define PORTR_PIN1CTRL _SFR_MEM8(0x07F1)
+#define PORTR_PIN2CTRL _SFR_MEM8(0x07F2)
+#define PORTR_PIN3CTRL _SFR_MEM8(0x07F3)
+#define PORTR_PIN4CTRL _SFR_MEM8(0x07F4)
+#define PORTR_PIN5CTRL _SFR_MEM8(0x07F5)
+#define PORTR_PIN6CTRL _SFR_MEM8(0x07F6)
+#define PORTR_PIN7CTRL _SFR_MEM8(0x07F7)
+
+/* TCC0 - Timer/Counter C0 */
+#define TCC0_CTRLA _SFR_MEM8(0x0800)
+#define TCC0_CTRLB _SFR_MEM8(0x0801)
+#define TCC0_CTRLC _SFR_MEM8(0x0802)
+#define TCC0_CTRLD _SFR_MEM8(0x0803)
+#define TCC0_CTRLE _SFR_MEM8(0x0804)
+#define TCC0_INTCTRLA _SFR_MEM8(0x0806)
+#define TCC0_INTCTRLB _SFR_MEM8(0x0807)
+#define TCC0_CTRLFCLR _SFR_MEM8(0x0808)
+#define TCC0_CTRLFSET _SFR_MEM8(0x0809)
+#define TCC0_CTRLGCLR _SFR_MEM8(0x080A)
+#define TCC0_CTRLGSET _SFR_MEM8(0x080B)
+#define TCC0_INTFLAGS _SFR_MEM8(0x080C)
+#define TCC0_TEMP _SFR_MEM8(0x080F)
+#define TCC0_CNT _SFR_MEM16(0x0820)
+#define TCC0_PER _SFR_MEM16(0x0826)
+#define TCC0_CCA _SFR_MEM16(0x0828)
+#define TCC0_CCB _SFR_MEM16(0x082A)
+#define TCC0_CCC _SFR_MEM16(0x082C)
+#define TCC0_CCD _SFR_MEM16(0x082E)
+#define TCC0_PERBUF _SFR_MEM16(0x0836)
+#define TCC0_CCABUF _SFR_MEM16(0x0838)
+#define TCC0_CCBBUF _SFR_MEM16(0x083A)
+#define TCC0_CCCBUF _SFR_MEM16(0x083C)
+#define TCC0_CCDBUF _SFR_MEM16(0x083E)
+
+/* TCC1 - Timer/Counter C1 */
+#define TCC1_CTRLA _SFR_MEM8(0x0840)
+#define TCC1_CTRLB _SFR_MEM8(0x0841)
+#define TCC1_CTRLC _SFR_MEM8(0x0842)
+#define TCC1_CTRLD _SFR_MEM8(0x0843)
+#define TCC1_CTRLE _SFR_MEM8(0x0844)
+#define TCC1_INTCTRLA _SFR_MEM8(0x0846)
+#define TCC1_INTCTRLB _SFR_MEM8(0x0847)
+#define TCC1_CTRLFCLR _SFR_MEM8(0x0848)
+#define TCC1_CTRLFSET _SFR_MEM8(0x0849)
+#define TCC1_CTRLGCLR _SFR_MEM8(0x084A)
+#define TCC1_CTRLGSET _SFR_MEM8(0x084B)
+#define TCC1_INTFLAGS _SFR_MEM8(0x084C)
+#define TCC1_TEMP _SFR_MEM8(0x084F)
+#define TCC1_CNT _SFR_MEM16(0x0860)
+#define TCC1_PER _SFR_MEM16(0x0866)
+#define TCC1_CCA _SFR_MEM16(0x0868)
+#define TCC1_CCB _SFR_MEM16(0x086A)
+#define TCC1_PERBUF _SFR_MEM16(0x0876)
+#define TCC1_CCABUF _SFR_MEM16(0x0878)
+#define TCC1_CCBBUF _SFR_MEM16(0x087A)
+
+/* AWEXC - Advanced Waveform Extension C */
+#define AWEXC_CTRL _SFR_MEM8(0x0880)
+#define AWEXC_FDEMASK _SFR_MEM8(0x0882)
+#define AWEXC_FDCTRL _SFR_MEM8(0x0883)
+#define AWEXC_STATUS _SFR_MEM8(0x0884)
+#define AWEXC_DTBOTH _SFR_MEM8(0x0886)
+#define AWEXC_DTBOTHBUF _SFR_MEM8(0x0887)
+#define AWEXC_DTLS _SFR_MEM8(0x0888)
+#define AWEXC_DTHS _SFR_MEM8(0x0889)
+#define AWEXC_DTLSBUF _SFR_MEM8(0x088A)
+#define AWEXC_DTHSBUF _SFR_MEM8(0x088B)
+#define AWEXC_OUTOVEN _SFR_MEM8(0x088C)
+
+/* HIRESC - High-Resolution Extension C */
+#define HIRESC_CTRLA _SFR_MEM8(0x0890)
+
+/* USARTC0 - Universal Asynchronous Receiver-Transmitter C0 */
+#define USARTC0_DATA _SFR_MEM8(0x08A0)
+#define USARTC0_STATUS _SFR_MEM8(0x08A1)
+#define USARTC0_CTRLA _SFR_MEM8(0x08A3)
+#define USARTC0_CTRLB _SFR_MEM8(0x08A4)
+#define USARTC0_CTRLC _SFR_MEM8(0x08A5)
+#define USARTC0_BAUDCTRLA _SFR_MEM8(0x08A6)
+#define USARTC0_BAUDCTRLB _SFR_MEM8(0x08A7)
+
+/* SPIC - Serial Peripheral Interface C */
+#define SPIC_CTRL _SFR_MEM8(0x08C0)
+#define SPIC_INTCTRL _SFR_MEM8(0x08C1)
+#define SPIC_STATUS _SFR_MEM8(0x08C2)
+#define SPIC_DATA _SFR_MEM8(0x08C3)
+
+/* IRCOM - IR Communication Module */
+#define IRCOM_TXPLCTRL _SFR_MEM8(0x08F8)
+#define IRCOM_RXPLCTRL _SFR_MEM8(0x08F9)
+#define IRCOM_CTRL _SFR_MEM8(0x08FA)
+
+/* TCD0 - Timer/Counter D0 */
+#define TCD0_CTRLA _SFR_MEM8(0x0900)
+#define TCD0_CTRLB _SFR_MEM8(0x0901)
+#define TCD0_CTRLC _SFR_MEM8(0x0902)
+#define TCD0_CTRLD _SFR_MEM8(0x0903)
+#define TCD0_CTRLE _SFR_MEM8(0x0904)
+#define TCD0_INTCTRLA _SFR_MEM8(0x0906)
+#define TCD0_INTCTRLB _SFR_MEM8(0x0907)
+#define TCD0_CTRLFCLR _SFR_MEM8(0x0908)
+#define TCD0_CTRLFSET _SFR_MEM8(0x0909)
+#define TCD0_CTRLGCLR _SFR_MEM8(0x090A)
+#define TCD0_CTRLGSET _SFR_MEM8(0x090B)
+#define TCD0_INTFLAGS _SFR_MEM8(0x090C)
+#define TCD0_TEMP _SFR_MEM8(0x090F)
+#define TCD0_CNT _SFR_MEM16(0x0920)
+#define TCD0_PER _SFR_MEM16(0x0926)
+#define TCD0_CCA _SFR_MEM16(0x0928)
+#define TCD0_CCB _SFR_MEM16(0x092A)
+#define TCD0_CCC _SFR_MEM16(0x092C)
+#define TCD0_CCD _SFR_MEM16(0x092E)
+#define TCD0_PERBUF _SFR_MEM16(0x0936)
+#define TCD0_CCABUF _SFR_MEM16(0x0938)
+#define TCD0_CCBBUF _SFR_MEM16(0x093A)
+#define TCD0_CCCBUF _SFR_MEM16(0x093C)
+#define TCD0_CCDBUF _SFR_MEM16(0x093E)
+
+/* USARTD0 - Universal Asynchronous Receiver-Transmitter D0 */
+#define USARTD0_DATA _SFR_MEM8(0x09A0)
+#define USARTD0_STATUS _SFR_MEM8(0x09A1)
+#define USARTD0_CTRLA _SFR_MEM8(0x09A3)
+#define USARTD0_CTRLB _SFR_MEM8(0x09A4)
+#define USARTD0_CTRLC _SFR_MEM8(0x09A5)
+#define USARTD0_BAUDCTRLA _SFR_MEM8(0x09A6)
+#define USARTD0_BAUDCTRLB _SFR_MEM8(0x09A7)
+
+/* SPID - Serial Peripheral Interface D */
+#define SPID_CTRL _SFR_MEM8(0x09C0)
+#define SPID_INTCTRL _SFR_MEM8(0x09C1)
+#define SPID_STATUS _SFR_MEM8(0x09C2)
+#define SPID_DATA _SFR_MEM8(0x09C3)
+
+/* TCE0 - Timer/Counter E0 */
+#define TCE0_CTRLA _SFR_MEM8(0x0A00)
+#define TCE0_CTRLB _SFR_MEM8(0x0A01)
+#define TCE0_CTRLC _SFR_MEM8(0x0A02)
+#define TCE0_CTRLD _SFR_MEM8(0x0A03)
+#define TCE0_CTRLE _SFR_MEM8(0x0A04)
+#define TCE0_INTCTRLA _SFR_MEM8(0x0A06)
+#define TCE0_INTCTRLB _SFR_MEM8(0x0A07)
+#define TCE0_CTRLFCLR _SFR_MEM8(0x0A08)
+#define TCE0_CTRLFSET _SFR_MEM8(0x0A09)
+#define TCE0_CTRLGCLR _SFR_MEM8(0x0A0A)
+#define TCE0_CTRLGSET _SFR_MEM8(0x0A0B)
+#define TCE0_INTFLAGS _SFR_MEM8(0x0A0C)
+#define TCE0_TEMP _SFR_MEM8(0x0A0F)
+#define TCE0_CNT _SFR_MEM16(0x0A20)
+#define TCE0_PER _SFR_MEM16(0x0A26)
+#define TCE0_CCA _SFR_MEM16(0x0A28)
+#define TCE0_CCB _SFR_MEM16(0x0A2A)
+#define TCE0_CCC _SFR_MEM16(0x0A2C)
+#define TCE0_CCD _SFR_MEM16(0x0A2E)
+#define TCE0_PERBUF _SFR_MEM16(0x0A36)
+#define TCE0_CCABUF _SFR_MEM16(0x0A38)
+#define TCE0_CCBBUF _SFR_MEM16(0x0A3A)
+#define TCE0_CCCBUF _SFR_MEM16(0x0A3C)
+#define TCE0_CCDBUF _SFR_MEM16(0x0A3E)
+
+/* AWEXE - Advanced Waveform Extension E */
+#define AWEXE_CTRL _SFR_MEM8(0x0A80)
+#define AWEXE_FDEMASK _SFR_MEM8(0x0A82)
+#define AWEXE_FDCTRL _SFR_MEM8(0x0A83)
+#define AWEXE_STATUS _SFR_MEM8(0x0A84)
+#define AWEXE_DTBOTH _SFR_MEM8(0x0A86)
+#define AWEXE_DTBOTHBUF _SFR_MEM8(0x0A87)
+#define AWEXE_DTLS _SFR_MEM8(0x0A88)
+#define AWEXE_DTHS _SFR_MEM8(0x0A89)
+#define AWEXE_DTLSBUF _SFR_MEM8(0x0A8A)
+#define AWEXE_DTHSBUF _SFR_MEM8(0x0A8B)
+#define AWEXE_OUTOVEN _SFR_MEM8(0x0A8C)
+
+/* USARTE0 - Universal Asynchronous Receiver-Transmitter E0 */
+#define USARTE0_DATA _SFR_MEM8(0x0AA0)
+#define USARTE0_STATUS _SFR_MEM8(0x0AA1)
+#define USARTE0_CTRLA _SFR_MEM8(0x0AA3)
+#define USARTE0_CTRLB _SFR_MEM8(0x0AA4)
+#define USARTE0_CTRLC _SFR_MEM8(0x0AA5)
+#define USARTE0_BAUDCTRLA _SFR_MEM8(0x0AA6)
+#define USARTE0_BAUDCTRLB _SFR_MEM8(0x0AA7)
+
+/* SPIE - Serial Peripheral Interface E */
+#define SPIE_CTRL _SFR_MEM8(0x0AC0)
+#define SPIE_INTCTRL _SFR_MEM8(0x0AC1)
+#define SPIE_STATUS _SFR_MEM8(0x0AC2)
+#define SPIE_DATA _SFR_MEM8(0x0AC3)
+
+/* TCF0 - Timer/Counter F0 */
+#define TCF0_CTRLA _SFR_MEM8(0x0B00)
+#define TCF0_CTRLB _SFR_MEM8(0x0B01)
+#define TCF0_CTRLC _SFR_MEM8(0x0B02)
+#define TCF0_CTRLD _SFR_MEM8(0x0B03)
+#define TCF0_CTRLE _SFR_MEM8(0x0B04)
+#define TCF0_INTCTRLA _SFR_MEM8(0x0B06)
+#define TCF0_INTCTRLB _SFR_MEM8(0x0B07)
+#define TCF0_CTRLFCLR _SFR_MEM8(0x0B08)
+#define TCF0_CTRLFSET _SFR_MEM8(0x0B09)
+#define TCF0_CTRLGCLR _SFR_MEM8(0x0B0A)
+#define TCF0_CTRLGSET _SFR_MEM8(0x0B0B)
+#define TCF0_INTFLAGS _SFR_MEM8(0x0B0C)
+#define TCF0_TEMP _SFR_MEM8(0x0B0F)
+#define TCF0_CNT _SFR_MEM16(0x0B20)
+#define TCF0_PER _SFR_MEM16(0x0B26)
+#define TCF0_CCA _SFR_MEM16(0x0B28)
+#define TCF0_CCB _SFR_MEM16(0x0B2A)
+#define TCF0_CCC _SFR_MEM16(0x0B2C)
+#define TCF0_CCD _SFR_MEM16(0x0B2E)
+#define TCF0_PERBUF _SFR_MEM16(0x0B36)
+#define TCF0_CCABUF _SFR_MEM16(0x0B38)
+#define TCF0_CCBBUF _SFR_MEM16(0x0B3A)
+#define TCF0_CCCBUF _SFR_MEM16(0x0B3C)
+#define TCF0_CCDBUF _SFR_MEM16(0x0B3E)
+
+
+
+/*================== Bitfield Definitions ================== */
+
+/* XOCD - On-Chip Debug System */
+/* OCD.OCDR1 bit masks and bit positions */
+#define OCD_OCDRD_bm 0x01 /* OCDR Dirty bit mask. */
+#define OCD_OCDRD_bp 0 /* OCDR Dirty bit position. */
+
+
+/* CPU - CPU */
+/* CPU.CCP bit masks and bit positions */
+#define CPU_CCP_gm 0xFF /* CCP signature group mask. */
+#define CPU_CCP_gp 0 /* CCP signature group position. */
+#define CPU_CCP0_bm (1<<0) /* CCP signature bit 0 mask. */
+#define CPU_CCP0_bp 0 /* CCP signature bit 0 position. */
+#define CPU_CCP1_bm (1<<1) /* CCP signature bit 1 mask. */
+#define CPU_CCP1_bp 1 /* CCP signature bit 1 position. */
+#define CPU_CCP2_bm (1<<2) /* CCP signature bit 2 mask. */
+#define CPU_CCP2_bp 2 /* CCP signature bit 2 position. */
+#define CPU_CCP3_bm (1<<3) /* CCP signature bit 3 mask. */
+#define CPU_CCP3_bp 3 /* CCP signature bit 3 position. */
+#define CPU_CCP4_bm (1<<4) /* CCP signature bit 4 mask. */
+#define CPU_CCP4_bp 4 /* CCP signature bit 4 position. */
+#define CPU_CCP5_bm (1<<5) /* CCP signature bit 5 mask. */
+#define CPU_CCP5_bp 5 /* CCP signature bit 5 position. */
+#define CPU_CCP6_bm (1<<6) /* CCP signature bit 6 mask. */
+#define CPU_CCP6_bp 6 /* CCP signature bit 6 position. */
+#define CPU_CCP7_bm (1<<7) /* CCP signature bit 7 mask. */
+#define CPU_CCP7_bp 7 /* CCP signature bit 7 position. */
+
+
+/* CPU.SREG bit masks and bit positions */
+#define CPU_I_bm 0x80 /* Global Interrupt Enable Flag bit mask. */
+#define CPU_I_bp 7 /* Global Interrupt Enable Flag bit position. */
+
+#define CPU_T_bm 0x40 /* Transfer Bit bit mask. */
+#define CPU_T_bp 6 /* Transfer Bit bit position. */
+
+#define CPU_H_bm 0x20 /* Half Carry Flag bit mask. */
+#define CPU_H_bp 5 /* Half Carry Flag bit position. */
+
+#define CPU_S_bm 0x10 /* N Exclusive Or V Flag bit mask. */
+#define CPU_S_bp 4 /* N Exclusive Or V Flag bit position. */
+
+#define CPU_V_bm 0x08 /* Two's Complement Overflow Flag bit mask. */
+#define CPU_V_bp 3 /* Two's Complement Overflow Flag bit position. */
+
+#define CPU_N_bm 0x04 /* Negative Flag bit mask. */
+#define CPU_N_bp 2 /* Negative Flag bit position. */
+
+#define CPU_Z_bm 0x02 /* Zero Flag bit mask. */
+#define CPU_Z_bp 1 /* Zero Flag bit position. */
+
+#define CPU_C_bm 0x01 /* Carry Flag bit mask. */
+#define CPU_C_bp 0 /* Carry Flag bit position. */
+
+
+/* CLK - Clock System */
+/* CLK.CTRL bit masks and bit positions */
+#define CLK_SCLKSEL_gm 0x07 /* System Clock Selection group mask. */
+#define CLK_SCLKSEL_gp 0 /* System Clock Selection group position. */
+#define CLK_SCLKSEL0_bm (1<<0) /* System Clock Selection bit 0 mask. */
+#define CLK_SCLKSEL0_bp 0 /* System Clock Selection bit 0 position. */
+#define CLK_SCLKSEL1_bm (1<<1) /* System Clock Selection bit 1 mask. */
+#define CLK_SCLKSEL1_bp 1 /* System Clock Selection bit 1 position. */
+#define CLK_SCLKSEL2_bm (1<<2) /* System Clock Selection bit 2 mask. */
+#define CLK_SCLKSEL2_bp 2 /* System Clock Selection bit 2 position. */
+
+
+/* CLK.PSCTRL bit masks and bit positions */
+#define CLK_PSADIV_gm 0x7C /* Prescaler A Division Factor group mask. */
+#define CLK_PSADIV_gp 2 /* Prescaler A Division Factor group position. */
+#define CLK_PSADIV0_bm (1<<2) /* Prescaler A Division Factor bit 0 mask. */
+#define CLK_PSADIV0_bp 2 /* Prescaler A Division Factor bit 0 position. */
+#define CLK_PSADIV1_bm (1<<3) /* Prescaler A Division Factor bit 1 mask. */
+#define CLK_PSADIV1_bp 3 /* Prescaler A Division Factor bit 1 position. */
+#define CLK_PSADIV2_bm (1<<4) /* Prescaler A Division Factor bit 2 mask. */
+#define CLK_PSADIV2_bp 4 /* Prescaler A Division Factor bit 2 position. */
+#define CLK_PSADIV3_bm (1<<5) /* Prescaler A Division Factor bit 3 mask. */
+#define CLK_PSADIV3_bp 5 /* Prescaler A Division Factor bit 3 position. */
+#define CLK_PSADIV4_bm (1<<6) /* Prescaler A Division Factor bit 4 mask. */
+#define CLK_PSADIV4_bp 6 /* Prescaler A Division Factor bit 4 position. */
+
+#define CLK_PSBCDIV_gm 0x03 /* Prescaler B and C Division factor group mask. */
+#define CLK_PSBCDIV_gp 0 /* Prescaler B and C Division factor group position. */
+#define CLK_PSBCDIV0_bm (1<<0) /* Prescaler B and C Division factor bit 0 mask. */
+#define CLK_PSBCDIV0_bp 0 /* Prescaler B and C Division factor bit 0 position. */
+#define CLK_PSBCDIV1_bm (1<<1) /* Prescaler B and C Division factor bit 1 mask. */
+#define CLK_PSBCDIV1_bp 1 /* Prescaler B and C Division factor bit 1 position. */
+
+
+/* CLK.LOCK bit masks and bit positions */
+#define CLK_LOCK_bm 0x01 /* Clock System Lock bit mask. */
+#define CLK_LOCK_bp 0 /* Clock System Lock bit position. */
+
+
+/* CLK.RTCCTRL bit masks and bit positions */
+#define CLK_RTCSRC_gm 0x0E /* Clock Source group mask. */
+#define CLK_RTCSRC_gp 1 /* Clock Source group position. */
+#define CLK_RTCSRC0_bm (1<<1) /* Clock Source bit 0 mask. */
+#define CLK_RTCSRC0_bp 1 /* Clock Source bit 0 position. */
+#define CLK_RTCSRC1_bm (1<<2) /* Clock Source bit 1 mask. */
+#define CLK_RTCSRC1_bp 2 /* Clock Source bit 1 position. */
+#define CLK_RTCSRC2_bm (1<<3) /* Clock Source bit 2 mask. */
+#define CLK_RTCSRC2_bp 3 /* Clock Source bit 2 position. */
+
+#define CLK_RTCEN_bm 0x01 /* RTC Clock Source Enable bit mask. */
+#define CLK_RTCEN_bp 0 /* RTC Clock Source Enable bit position. */
+
+
+/* PR.PRGEN bit masks and bit positions */
+#define PR_AES_bm 0x10 /* AES bit mask. */
+#define PR_AES_bp 4 /* AES bit position. */
+
+#define PR_EBI_bm 0x08 /* External Bus Interface bit mask. */
+#define PR_EBI_bp 3 /* External Bus Interface bit position. */
+
+#define PR_RTC_bm 0x04 /* Real-time Counter bit mask. */
+#define PR_RTC_bp 2 /* Real-time Counter bit position. */
+
+#define PR_EVSYS_bm 0x02 /* Event System bit mask. */
+#define PR_EVSYS_bp 1 /* Event System bit position. */
+
+#define PR_DMA_bm 0x01 /* DMA-Controller bit mask. */
+#define PR_DMA_bp 0 /* DMA-Controller bit position. */
+
+
+/* PR.PRPA bit masks and bit positions */
+#define PR_DAC_bm 0x04 /* Port A DAC bit mask. */
+#define PR_DAC_bp 2 /* Port A DAC bit position. */
+
+#define PR_ADC_bm 0x02 /* Port A ADC bit mask. */
+#define PR_ADC_bp 1 /* Port A ADC bit position. */
+
+#define PR_AC_bm 0x01 /* Port A Analog Comparator bit mask. */
+#define PR_AC_bp 0 /* Port A Analog Comparator bit position. */
+
+
+/* PR.PRPB bit masks and bit positions */
+/* PR_DAC_bm Predefined. */
+/* PR_DAC_bp Predefined. */
+
+/* PR_ADC_bm Predefined. */
+/* PR_ADC_bp Predefined. */
+
+/* PR_AC_bm Predefined. */
+/* PR_AC_bp Predefined. */
+
+
+/* PR.PRPC bit masks and bit positions */
+#define PR_TWI_bm 0x40 /* Port C Two-wire Interface bit mask. */
+#define PR_TWI_bp 6 /* Port C Two-wire Interface bit position. */
+
+#define PR_USART1_bm 0x20 /* Port C USART1 bit mask. */
+#define PR_USART1_bp 5 /* Port C USART1 bit position. */
+
+#define PR_USART0_bm 0x10 /* Port C USART0 bit mask. */
+#define PR_USART0_bp 4 /* Port C USART0 bit position. */
+
+#define PR_SPI_bm 0x08 /* Port C SPI bit mask. */
+#define PR_SPI_bp 3 /* Port C SPI bit position. */
+
+#define PR_HIRES_bm 0x04 /* Port C AWEX bit mask. */
+#define PR_HIRES_bp 2 /* Port C AWEX bit position. */
+
+#define PR_TC1_bm 0x02 /* Port C Timer/Counter1 bit mask. */
+#define PR_TC1_bp 1 /* Port C Timer/Counter1 bit position. */
+
+#define PR_TC0_bm 0x01 /* Port C Timer/Counter0 bit mask. */
+#define PR_TC0_bp 0 /* Port C Timer/Counter0 bit position. */
+
+
+/* PR.PRPD bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPE bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* PR.PRPF bit masks and bit positions */
+/* PR_TWI_bm Predefined. */
+/* PR_TWI_bp Predefined. */
+
+/* PR_USART1_bm Predefined. */
+/* PR_USART1_bp Predefined. */
+
+/* PR_USART0_bm Predefined. */
+/* PR_USART0_bp Predefined. */
+
+/* PR_SPI_bm Predefined. */
+/* PR_SPI_bp Predefined. */
+
+/* PR_HIRES_bm Predefined. */
+/* PR_HIRES_bp Predefined. */
+
+/* PR_TC1_bm Predefined. */
+/* PR_TC1_bp Predefined. */
+
+/* PR_TC0_bm Predefined. */
+/* PR_TC0_bp Predefined. */
+
+
+/* SLEEP - Sleep Controller */
+/* SLEEP.CTRL bit masks and bit positions */
+#define SLEEP_SMODE_gm 0x0E /* Sleep Mode group mask. */
+#define SLEEP_SMODE_gp 1 /* Sleep Mode group position. */
+#define SLEEP_SMODE0_bm (1<<1) /* Sleep Mode bit 0 mask. */
+#define SLEEP_SMODE0_bp 1 /* Sleep Mode bit 0 position. */
+#define SLEEP_SMODE1_bm (1<<2) /* Sleep Mode bit 1 mask. */
+#define SLEEP_SMODE1_bp 2 /* Sleep Mode bit 1 position. */
+#define SLEEP_SMODE2_bm (1<<3) /* Sleep Mode bit 2 mask. */
+#define SLEEP_SMODE2_bp 3 /* Sleep Mode bit 2 position. */
+
+#define SLEEP_SEN_bm 0x01 /* Sleep Enable bit mask. */
+#define SLEEP_SEN_bp 0 /* Sleep Enable bit position. */
+
+
+/* OSC - Oscillator */
+/* OSC.CTRL bit masks and bit positions */
+#define OSC_PLLEN_bm 0x10 /* PLL Enable bit mask. */
+#define OSC_PLLEN_bp 4 /* PLL Enable bit position. */
+
+#define OSC_XOSCEN_bm 0x08 /* External Oscillator Enable bit mask. */
+#define OSC_XOSCEN_bp 3 /* External Oscillator Enable bit position. */
+
+#define OSC_RC32KEN_bm 0x04 /* Internal 32kHz RC Oscillator Enable bit mask. */
+#define OSC_RC32KEN_bp 2 /* Internal 32kHz RC Oscillator Enable bit position. */
+
+#define OSC_RC32MEN_bm 0x02 /* Internal 32MHz RC Oscillator Enable bit mask. */
+#define OSC_RC32MEN_bp 1 /* Internal 32MHz RC Oscillator Enable bit position. */
+
+#define OSC_RC2MEN_bm 0x01 /* Internal 2MHz RC Oscillator Enable bit mask. */
+#define OSC_RC2MEN_bp 0 /* Internal 2MHz RC Oscillator Enable bit position. */
+
+
+/* OSC.STATUS bit masks and bit positions */
+#define OSC_PLLRDY_bm 0x10 /* PLL Ready bit mask. */
+#define OSC_PLLRDY_bp 4 /* PLL Ready bit position. */
+
+#define OSC_XOSCRDY_bm 0x08 /* External Oscillator Ready bit mask. */
+#define OSC_XOSCRDY_bp 3 /* External Oscillator Ready bit position. */
+
+#define OSC_RC32KRDY_bm 0x04 /* Internal 32kHz RC Oscillator Ready bit mask. */
+#define OSC_RC32KRDY_bp 2 /* Internal 32kHz RC Oscillator Ready bit position. */
+
+#define OSC_RC32MRDY_bm 0x02 /* Internal 32MHz RC Oscillator Ready bit mask. */
+#define OSC_RC32MRDY_bp 1 /* Internal 32MHz RC Oscillator Ready bit position. */
+
+#define OSC_RC2MRDY_bm 0x01 /* Internal 2MHz RC Oscillator Ready bit mask. */
+#define OSC_RC2MRDY_bp 0 /* Internal 2MHz RC Oscillator Ready bit position. */
+
+
+/* OSC.XOSCCTRL bit masks and bit positions */
+#define OSC_FRQRANGE_gm 0xC0 /* Frequency Range group mask. */
+#define OSC_FRQRANGE_gp 6 /* Frequency Range group position. */
+#define OSC_FRQRANGE0_bm (1<<6) /* Frequency Range bit 0 mask. */
+#define OSC_FRQRANGE0_bp 6 /* Frequency Range bit 0 position. */
+#define OSC_FRQRANGE1_bm (1<<7) /* Frequency Range bit 1 mask. */
+#define OSC_FRQRANGE1_bp 7 /* Frequency Range bit 1 position. */
+
+#define OSC_X32KLPM_bm 0x20 /* 32kHz XTAL OSC Low-power Mode bit mask. */
+#define OSC_X32KLPM_bp 5 /* 32kHz XTAL OSC Low-power Mode bit position. */
+
+#define OSC_XOSCSEL_gm 0x0F /* External Oscillator Selection and Startup Time group mask. */
+#define OSC_XOSCSEL_gp 0 /* External Oscillator Selection and Startup Time group position. */
+#define OSC_XOSCSEL0_bm (1<<0) /* External Oscillator Selection and Startup Time bit 0 mask. */
+#define OSC_XOSCSEL0_bp 0 /* External Oscillator Selection and Startup Time bit 0 position. */
+#define OSC_XOSCSEL1_bm (1<<1) /* External Oscillator Selection and Startup Time bit 1 mask. */
+#define OSC_XOSCSEL1_bp 1 /* External Oscillator Selection and Startup Time bit 1 position. */
+#define OSC_XOSCSEL2_bm (1<<2) /* External Oscillator Selection and Startup Time bit 2 mask. */
+#define OSC_XOSCSEL2_bp 2 /* External Oscillator Selection and Startup Time bit 2 position. */
+#define OSC_XOSCSEL3_bm (1<<3) /* External Oscillator Selection and Startup Time bit 3 mask. */
+#define OSC_XOSCSEL3_bp 3 /* External Oscillator Selection and Startup Time bit 3 position. */
+
+
+/* OSC.XOSCFAIL bit masks and bit positions */
+#define OSC_XOSCFDIF_bm 0x02 /* Failure Detection Interrupt Flag bit mask. */
+#define OSC_XOSCFDIF_bp 1 /* Failure Detection Interrupt Flag bit position. */
+
+#define OSC_XOSCFDEN_bm 0x01 /* Failure Detection Enable bit mask. */
+#define OSC_XOSCFDEN_bp 0 /* Failure Detection Enable bit position. */
+
+
+/* OSC.PLLCTRL bit masks and bit positions */
+#define OSC_PLLSRC_gm 0xC0 /* Clock Source group mask. */
+#define OSC_PLLSRC_gp 6 /* Clock Source group position. */
+#define OSC_PLLSRC0_bm (1<<6) /* Clock Source bit 0 mask. */
+#define OSC_PLLSRC0_bp 6 /* Clock Source bit 0 position. */
+#define OSC_PLLSRC1_bm (1<<7) /* Clock Source bit 1 mask. */
+#define OSC_PLLSRC1_bp 7 /* Clock Source bit 1 position. */
+
+#define OSC_PLLFAC_gm 0x1F /* Multiplication Factor group mask. */
+#define OSC_PLLFAC_gp 0 /* Multiplication Factor group position. */
+#define OSC_PLLFAC0_bm (1<<0) /* Multiplication Factor bit 0 mask. */
+#define OSC_PLLFAC0_bp 0 /* Multiplication Factor bit 0 position. */
+#define OSC_PLLFAC1_bm (1<<1) /* Multiplication Factor bit 1 mask. */
+#define OSC_PLLFAC1_bp 1 /* Multiplication Factor bit 1 position. */
+#define OSC_PLLFAC2_bm (1<<2) /* Multiplication Factor bit 2 mask. */
+#define OSC_PLLFAC2_bp 2 /* Multiplication Factor bit 2 position. */
+#define OSC_PLLFAC3_bm (1<<3) /* Multiplication Factor bit 3 mask. */
+#define OSC_PLLFAC3_bp 3 /* Multiplication Factor bit 3 position. */
+#define OSC_PLLFAC4_bm (1<<4) /* Multiplication Factor bit 4 mask. */
+#define OSC_PLLFAC4_bp 4 /* Multiplication Factor bit 4 position. */
+
+
+/* OSC.DFLLCTRL bit masks and bit positions */
+#define OSC_RC32MCREF_bm 0x02 /* 32MHz Calibration Reference bit mask. */
+#define OSC_RC32MCREF_bp 1 /* 32MHz Calibration Reference bit position. */
+
+#define OSC_RC2MCREF_bm 0x01 /* 2MHz Calibration Reference bit mask. */
+#define OSC_RC2MCREF_bp 0 /* 2MHz Calibration Reference bit position. */
+
+
+/* DFLL - DFLL */
+/* DFLL.CTRL bit masks and bit positions */
+#define DFLL_ENABLE_bm 0x01 /* DFLL Enable bit mask. */
+#define DFLL_ENABLE_bp 0 /* DFLL Enable bit position. */
+
+
+/* DFLL.CALA bit masks and bit positions */
+#define DFLL_CALL_gm 0x7F /* DFLL Calibration bits [6:0] group mask. */
+#define DFLL_CALL_gp 0 /* DFLL Calibration bits [6:0] group position. */
+#define DFLL_CALL0_bm (1<<0) /* DFLL Calibration bits [6:0] bit 0 mask. */
+#define DFLL_CALL0_bp 0 /* DFLL Calibration bits [6:0] bit 0 position. */
+#define DFLL_CALL1_bm (1<<1) /* DFLL Calibration bits [6:0] bit 1 mask. */
+#define DFLL_CALL1_bp 1 /* DFLL Calibration bits [6:0] bit 1 position. */
+#define DFLL_CALL2_bm (1<<2) /* DFLL Calibration bits [6:0] bit 2 mask. */
+#define DFLL_CALL2_bp 2 /* DFLL Calibration bits [6:0] bit 2 position. */
+#define DFLL_CALL3_bm (1<<3) /* DFLL Calibration bits [6:0] bit 3 mask. */
+#define DFLL_CALL3_bp 3 /* DFLL Calibration bits [6:0] bit 3 position. */
+#define DFLL_CALL4_bm (1<<4) /* DFLL Calibration bits [6:0] bit 4 mask. */
+#define DFLL_CALL4_bp 4 /* DFLL Calibration bits [6:0] bit 4 position. */
+#define DFLL_CALL5_bm (1<<5) /* DFLL Calibration bits [6:0] bit 5 mask. */
+#define DFLL_CALL5_bp 5 /* DFLL Calibration bits [6:0] bit 5 position. */
+#define DFLL_CALL6_bm (1<<6) /* DFLL Calibration bits [6:0] bit 6 mask. */
+#define DFLL_CALL6_bp 6 /* DFLL Calibration bits [6:0] bit 6 position. */
+
+
+/* DFLL.CALB bit masks and bit positions */
+#define DFLL_CALH_gm 0x3F /* DFLL Calibration bits [12:7] group mask. */
+#define DFLL_CALH_gp 0 /* DFLL Calibration bits [12:7] group position. */
+#define DFLL_CALH0_bm (1<<0) /* DFLL Calibration bits [12:7] bit 0 mask. */
+#define DFLL_CALH0_bp 0 /* DFLL Calibration bits [12:7] bit 0 position. */
+#define DFLL_CALH1_bm (1<<1) /* DFLL Calibration bits [12:7] bit 1 mask. */
+#define DFLL_CALH1_bp 1 /* DFLL Calibration bits [12:7] bit 1 position. */
+#define DFLL_CALH2_bm (1<<2) /* DFLL Calibration bits [12:7] bit 2 mask. */
+#define DFLL_CALH2_bp 2 /* DFLL Calibration bits [12:7] bit 2 position. */
+#define DFLL_CALH3_bm (1<<3) /* DFLL Calibration bits [12:7] bit 3 mask. */
+#define DFLL_CALH3_bp 3 /* DFLL Calibration bits [12:7] bit 3 position. */
+#define DFLL_CALH4_bm (1<<4) /* DFLL Calibration bits [12:7] bit 4 mask. */
+#define DFLL_CALH4_bp 4 /* DFLL Calibration bits [12:7] bit 4 position. */
+#define DFLL_CALH5_bm (1<<5) /* DFLL Calibration bits [12:7] bit 5 mask. */
+#define DFLL_CALH5_bp 5 /* DFLL Calibration bits [12:7] bit 5 position. */
+
+
+/* RST - Reset */
+/* RST.STATUS bit masks and bit positions */
+#define RST_SDRF_bm 0x40 /* Spike Detection Reset Flag bit mask. */
+#define RST_SDRF_bp 6 /* Spike Detection Reset Flag bit position. */
+
+#define RST_SRF_bm 0x20 /* Software Reset Flag bit mask. */
+#define RST_SRF_bp 5 /* Software Reset Flag bit position. */
+
+#define RST_PDIRF_bm 0x10 /* Programming and Debug Interface Interface Reset Flag bit mask. */
+#define RST_PDIRF_bp 4 /* Programming and Debug Interface Interface Reset Flag bit position. */
+
+#define RST_WDRF_bm 0x08 /* Watchdog Reset Flag bit mask. */
+#define RST_WDRF_bp 3 /* Watchdog Reset Flag bit position. */
+
+#define RST_BORF_bm 0x04 /* Brown-out Reset Flag bit mask. */
+#define RST_BORF_bp 2 /* Brown-out Reset Flag bit position. */
+
+#define RST_EXTRF_bm 0x02 /* External Reset Flag bit mask. */
+#define RST_EXTRF_bp 1 /* External Reset Flag bit position. */
+
+#define RST_PORF_bm 0x01 /* Power-on Reset Flag bit mask. */
+#define RST_PORF_bp 0 /* Power-on Reset Flag bit position. */
+
+
+/* RST.CTRL bit masks and bit positions */
+#define RST_SWRST_bm 0x01 /* Software Reset bit mask. */
+#define RST_SWRST_bp 0 /* Software Reset bit position. */
+
+
+/* WDT - Watch-Dog Timer */
+/* WDT.CTRL bit masks and bit positions */
+#define WDT_PER_gm 0x3C /* Period group mask. */
+#define WDT_PER_gp 2 /* Period group position. */
+#define WDT_PER0_bm (1<<2) /* Period bit 0 mask. */
+#define WDT_PER0_bp 2 /* Period bit 0 position. */
+#define WDT_PER1_bm (1<<3) /* Period bit 1 mask. */
+#define WDT_PER1_bp 3 /* Period bit 1 position. */
+#define WDT_PER2_bm (1<<4) /* Period bit 2 mask. */
+#define WDT_PER2_bp 4 /* Period bit 2 position. */
+#define WDT_PER3_bm (1<<5) /* Period bit 3 mask. */
+#define WDT_PER3_bp 5 /* Period bit 3 position. */
+
+#define WDT_ENABLE_bm 0x02 /* Enable bit mask. */
+#define WDT_ENABLE_bp 1 /* Enable bit position. */
+
+#define WDT_CEN_bm 0x01 /* Change Enable bit mask. */
+#define WDT_CEN_bp 0 /* Change Enable bit position. */
+
+
+/* WDT.WINCTRL bit masks and bit positions */
+#define WDT_WPER_gm 0x3C /* Windowed Mode Period group mask. */
+#define WDT_WPER_gp 2 /* Windowed Mode Period group position. */
+#define WDT_WPER0_bm (1<<2) /* Windowed Mode Period bit 0 mask. */
+#define WDT_WPER0_bp 2 /* Windowed Mode Period bit 0 position. */
+#define WDT_WPER1_bm (1<<3) /* Windowed Mode Period bit 1 mask. */
+#define WDT_WPER1_bp 3 /* Windowed Mode Period bit 1 position. */
+#define WDT_WPER2_bm (1<<4) /* Windowed Mode Period bit 2 mask. */
+#define WDT_WPER2_bp 4 /* Windowed Mode Period bit 2 position. */
+#define WDT_WPER3_bm (1<<5) /* Windowed Mode Period bit 3 mask. */
+#define WDT_WPER3_bp 5 /* Windowed Mode Period bit 3 position. */
+
+#define WDT_WEN_bm 0x02 /* Windowed Mode Enable bit mask. */
+#define WDT_WEN_bp 1 /* Windowed Mode Enable bit position. */
+
+#define WDT_WCEN_bm 0x01 /* Windowed Mode Change Enable bit mask. */
+#define WDT_WCEN_bp 0 /* Windowed Mode Change Enable bit position. */
+
+
+/* WDT.STATUS bit masks and bit positions */
+#define WDT_SYNCBUSY_bm 0x01 /* Syncronization busy bit mask. */
+#define WDT_SYNCBUSY_bp 0 /* Syncronization busy bit position. */
+
+
+/* MCU - MCU Control */
+/* MCU.MCUCR bit masks and bit positions */
+#define MCU_JTAGD_bm 0x01 /* JTAG Disable bit mask. */
+#define MCU_JTAGD_bp 0 /* JTAG Disable bit position. */
+
+
+/* MCU.EVSYSLOCK bit masks and bit positions */
+#define MCU_EVSYS1LOCK_bm 0x10 /* Event Channel 4-7 Lock bit mask. */
+#define MCU_EVSYS1LOCK_bp 4 /* Event Channel 4-7 Lock bit position. */
+
+#define MCU_EVSYS0LOCK_bm 0x01 /* Event Channel 0-3 Lock bit mask. */
+#define MCU_EVSYS0LOCK_bp 0 /* Event Channel 0-3 Lock bit position. */
+
+
+/* MCU.AWEXLOCK bit masks and bit positions */
+#define MCU_AWEXELOCK_bm 0x04 /* AWeX on T/C E0 Lock bit mask. */
+#define MCU_AWEXELOCK_bp 2 /* AWeX on T/C E0 Lock bit position. */
+
+#define MCU_AWEXCLOCK_bm 0x01 /* AWeX on T/C C0 Lock bit mask. */
+#define MCU_AWEXCLOCK_bp 0 /* AWeX on T/C C0 Lock bit position. */
+
+
+/* PMIC - Programmable Multi-level Interrupt Controller */
+/* PMIC.STATUS bit masks and bit positions */
+#define PMIC_NMIEX_bm 0x80 /* Non-maskable Interrupt Executing bit mask. */
+#define PMIC_NMIEX_bp 7 /* Non-maskable Interrupt Executing bit position. */
+
+#define PMIC_HILVLEX_bm 0x04 /* High Level Interrupt Executing bit mask. */
+#define PMIC_HILVLEX_bp 2 /* High Level Interrupt Executing bit position. */
+
+#define PMIC_MEDLVLEX_bm 0x02 /* Medium Level Interrupt Executing bit mask. */
+#define PMIC_MEDLVLEX_bp 1 /* Medium Level Interrupt Executing bit position. */
+
+#define PMIC_LOLVLEX_bm 0x01 /* Low Level Interrupt Executing bit mask. */
+#define PMIC_LOLVLEX_bp 0 /* Low Level Interrupt Executing bit position. */
+
+
+/* PMIC.CTRL bit masks and bit positions */
+#define PMIC_RREN_bm 0x80 /* Round-Robin Priority Enable bit mask. */
+#define PMIC_RREN_bp 7 /* Round-Robin Priority Enable bit position. */
+
+#define PMIC_IVSEL_bm 0x40 /* Interrupt Vector Select bit mask. */
+#define PMIC_IVSEL_bp 6 /* Interrupt Vector Select bit position. */
+
+#define PMIC_HILVLEN_bm 0x04 /* High Level Enable bit mask. */
+#define PMIC_HILVLEN_bp 2 /* High Level Enable bit position. */
+
+#define PMIC_MEDLVLEN_bm 0x02 /* Medium Level Enable bit mask. */
+#define PMIC_MEDLVLEN_bp 1 /* Medium Level Enable bit position. */
+
+#define PMIC_LOLVLEN_bm 0x01 /* Low Level Enable bit mask. */
+#define PMIC_LOLVLEN_bp 0 /* Low Level Enable bit position. */
+
+
+/* EVSYS - Event System */
+/* EVSYS.CH0MUX bit masks and bit positions */
+#define EVSYS_CHMUX_gm 0xFF /* Event Channel 0 Multiplexer group mask. */
+#define EVSYS_CHMUX_gp 0 /* Event Channel 0 Multiplexer group position. */
+#define EVSYS_CHMUX0_bm (1<<0) /* Event Channel 0 Multiplexer bit 0 mask. */
+#define EVSYS_CHMUX0_bp 0 /* Event Channel 0 Multiplexer bit 0 position. */
+#define EVSYS_CHMUX1_bm (1<<1) /* Event Channel 0 Multiplexer bit 1 mask. */
+#define EVSYS_CHMUX1_bp 1 /* Event Channel 0 Multiplexer bit 1 position. */
+#define EVSYS_CHMUX2_bm (1<<2) /* Event Channel 0 Multiplexer bit 2 mask. */
+#define EVSYS_CHMUX2_bp 2 /* Event Channel 0 Multiplexer bit 2 position. */
+#define EVSYS_CHMUX3_bm (1<<3) /* Event Channel 0 Multiplexer bit 3 mask. */
+#define EVSYS_CHMUX3_bp 3 /* Event Channel 0 Multiplexer bit 3 position. */
+#define EVSYS_CHMUX4_bm (1<<4) /* Event Channel 0 Multiplexer bit 4 mask. */
+#define EVSYS_CHMUX4_bp 4 /* Event Channel 0 Multiplexer bit 4 position. */
+#define EVSYS_CHMUX5_bm (1<<5) /* Event Channel 0 Multiplexer bit 5 mask. */
+#define EVSYS_CHMUX5_bp 5 /* Event Channel 0 Multiplexer bit 5 position. */
+#define EVSYS_CHMUX6_bm (1<<6) /* Event Channel 0 Multiplexer bit 6 mask. */
+#define EVSYS_CHMUX6_bp 6 /* Event Channel 0 Multiplexer bit 6 position. */
+#define EVSYS_CHMUX7_bm (1<<7) /* Event Channel 0 Multiplexer bit 7 mask. */
+#define EVSYS_CHMUX7_bp 7 /* Event Channel 0 Multiplexer bit 7 position. */
+
+
+/* EVSYS.CH1MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH2MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH3MUX bit masks and bit positions */
+/* EVSYS_CHMUX_gm Predefined. */
+/* EVSYS_CHMUX_gp Predefined. */
+/* EVSYS_CHMUX0_bm Predefined. */
+/* EVSYS_CHMUX0_bp Predefined. */
+/* EVSYS_CHMUX1_bm Predefined. */
+/* EVSYS_CHMUX1_bp Predefined. */
+/* EVSYS_CHMUX2_bm Predefined. */
+/* EVSYS_CHMUX2_bp Predefined. */
+/* EVSYS_CHMUX3_bm Predefined. */
+/* EVSYS_CHMUX3_bp Predefined. */
+/* EVSYS_CHMUX4_bm Predefined. */
+/* EVSYS_CHMUX4_bp Predefined. */
+/* EVSYS_CHMUX5_bm Predefined. */
+/* EVSYS_CHMUX5_bp Predefined. */
+/* EVSYS_CHMUX6_bm Predefined. */
+/* EVSYS_CHMUX6_bp Predefined. */
+/* EVSYS_CHMUX7_bm Predefined. */
+/* EVSYS_CHMUX7_bp Predefined. */
+
+
+/* EVSYS.CH0CTRL bit masks and bit positions */
+#define EVSYS_QDIRM_gm 0x60 /* Quadrature Decoder Index Recognition Mode group mask. */
+#define EVSYS_QDIRM_gp 5 /* Quadrature Decoder Index Recognition Mode group position. */
+#define EVSYS_QDIRM0_bm (1<<5) /* Quadrature Decoder Index Recognition Mode bit 0 mask. */
+#define EVSYS_QDIRM0_bp 5 /* Quadrature Decoder Index Recognition Mode bit 0 position. */
+#define EVSYS_QDIRM1_bm (1<<6) /* Quadrature Decoder Index Recognition Mode bit 1 mask. */
+#define EVSYS_QDIRM1_bp 6 /* Quadrature Decoder Index Recognition Mode bit 1 position. */
+
+#define EVSYS_QDIEN_bm 0x10 /* Quadrature Decoder Index Enable bit mask. */
+#define EVSYS_QDIEN_bp 4 /* Quadrature Decoder Index Enable bit position. */
+
+#define EVSYS_QDEN_bm 0x08 /* Quadrature Decoder Enable bit mask. */
+#define EVSYS_QDEN_bp 3 /* Quadrature Decoder Enable bit position. */
+
+#define EVSYS_DIGFILT_gm 0x07 /* Digital Filter group mask. */
+#define EVSYS_DIGFILT_gp 0 /* Digital Filter group position. */
+#define EVSYS_DIGFILT0_bm (1<<0) /* Digital Filter bit 0 mask. */
+#define EVSYS_DIGFILT0_bp 0 /* Digital Filter bit 0 position. */
+#define EVSYS_DIGFILT1_bm (1<<1) /* Digital Filter bit 1 mask. */
+#define EVSYS_DIGFILT1_bp 1 /* Digital Filter bit 1 position. */
+#define EVSYS_DIGFILT2_bm (1<<2) /* Digital Filter bit 2 mask. */
+#define EVSYS_DIGFILT2_bp 2 /* Digital Filter bit 2 position. */
+
+
+/* EVSYS.CH1CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH2CTRL bit masks and bit positions */
+/* EVSYS_QDIRM_gm Predefined. */
+/* EVSYS_QDIRM_gp Predefined. */
+/* EVSYS_QDIRM0_bm Predefined. */
+/* EVSYS_QDIRM0_bp Predefined. */
+/* EVSYS_QDIRM1_bm Predefined. */
+/* EVSYS_QDIRM1_bp Predefined. */
+
+/* EVSYS_QDIEN_bm Predefined. */
+/* EVSYS_QDIEN_bp Predefined. */
+
+/* EVSYS_QDEN_bm Predefined. */
+/* EVSYS_QDEN_bp Predefined. */
+
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* EVSYS.CH3CTRL bit masks and bit positions */
+/* EVSYS_DIGFILT_gm Predefined. */
+/* EVSYS_DIGFILT_gp Predefined. */
+/* EVSYS_DIGFILT0_bm Predefined. */
+/* EVSYS_DIGFILT0_bp Predefined. */
+/* EVSYS_DIGFILT1_bm Predefined. */
+/* EVSYS_DIGFILT1_bp Predefined. */
+/* EVSYS_DIGFILT2_bm Predefined. */
+/* EVSYS_DIGFILT2_bp Predefined. */
+
+
+/* NVM - Non Volatile Memory Controller */
+/* NVM.CMD bit masks and bit positions */
+#define NVM_CMD_gm 0xFF /* Command group mask. */
+#define NVM_CMD_gp 0 /* Command group position. */
+#define NVM_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define NVM_CMD0_bp 0 /* Command bit 0 position. */
+#define NVM_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define NVM_CMD1_bp 1 /* Command bit 1 position. */
+#define NVM_CMD2_bm (1<<2) /* Command bit 2 mask. */
+#define NVM_CMD2_bp 2 /* Command bit 2 position. */
+#define NVM_CMD3_bm (1<<3) /* Command bit 3 mask. */
+#define NVM_CMD3_bp 3 /* Command bit 3 position. */
+#define NVM_CMD4_bm (1<<4) /* Command bit 4 mask. */
+#define NVM_CMD4_bp 4 /* Command bit 4 position. */
+#define NVM_CMD5_bm (1<<5) /* Command bit 5 mask. */
+#define NVM_CMD5_bp 5 /* Command bit 5 position. */
+#define NVM_CMD6_bm (1<<6) /* Command bit 6 mask. */
+#define NVM_CMD6_bp 6 /* Command bit 6 position. */
+#define NVM_CMD7_bm (1<<7) /* Command bit 7 mask. */
+#define NVM_CMD7_bp 7 /* Command bit 7 position. */
+
+
+/* NVM.CTRLA bit masks and bit positions */
+#define NVM_CMDEX_bm 0x01 /* Command Execute bit mask. */
+#define NVM_CMDEX_bp 0 /* Command Execute bit position. */
+
+
+/* NVM.CTRLB bit masks and bit positions */
+#define NVM_EEMAPEN_bm 0x08 /* EEPROM Mapping Enable bit mask. */
+#define NVM_EEMAPEN_bp 3 /* EEPROM Mapping Enable bit position. */
+
+#define NVM_FPRM_bm 0x04 /* Flash Power Reduction Enable bit mask. */
+#define NVM_FPRM_bp 2 /* Flash Power Reduction Enable bit position. */
+
+#define NVM_EPRM_bm 0x02 /* EEPROM Power Reduction Enable bit mask. */
+#define NVM_EPRM_bp 1 /* EEPROM Power Reduction Enable bit position. */
+
+#define NVM_SPMLOCK_bm 0x01 /* SPM Lock bit mask. */
+#define NVM_SPMLOCK_bp 0 /* SPM Lock bit position. */
+
+
+/* NVM.INTCTRL bit masks and bit positions */
+#define NVM_SPMLVL_gm 0x0C /* SPM Interrupt Level group mask. */
+#define NVM_SPMLVL_gp 2 /* SPM Interrupt Level group position. */
+#define NVM_SPMLVL0_bm (1<<2) /* SPM Interrupt Level bit 0 mask. */
+#define NVM_SPMLVL0_bp 2 /* SPM Interrupt Level bit 0 position. */
+#define NVM_SPMLVL1_bm (1<<3) /* SPM Interrupt Level bit 1 mask. */
+#define NVM_SPMLVL1_bp 3 /* SPM Interrupt Level bit 1 position. */
+
+#define NVM_EELVL_gm 0x03 /* EEPROM Interrupt Level group mask. */
+#define NVM_EELVL_gp 0 /* EEPROM Interrupt Level group position. */
+#define NVM_EELVL0_bm (1<<0) /* EEPROM Interrupt Level bit 0 mask. */
+#define NVM_EELVL0_bp 0 /* EEPROM Interrupt Level bit 0 position. */
+#define NVM_EELVL1_bm (1<<1) /* EEPROM Interrupt Level bit 1 mask. */
+#define NVM_EELVL1_bp 1 /* EEPROM Interrupt Level bit 1 position. */
+
+
+/* NVM.STATUS bit masks and bit positions */
+#define NVM_NVMBUSY_bm 0x80 /* Non-volatile Memory Busy bit mask. */
+#define NVM_NVMBUSY_bp 7 /* Non-volatile Memory Busy bit position. */
+
+#define NVM_FBUSY_bm 0x40 /* Flash Memory Busy bit mask. */
+#define NVM_FBUSY_bp 6 /* Flash Memory Busy bit position. */
+
+#define NVM_EELOAD_bm 0x02 /* EEPROM Page Buffer Active Loading bit mask. */
+#define NVM_EELOAD_bp 1 /* EEPROM Page Buffer Active Loading bit position. */
+
+#define NVM_FLOAD_bm 0x01 /* Flash Page Buffer Active Loading bit mask. */
+#define NVM_FLOAD_bp 0 /* Flash Page Buffer Active Loading bit position. */
+
+
+/* NVM.LOCKBITS bit masks and bit positions */
+#define NVM_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_LOCKBITS.LOCKBITS bit masks and bit positions */
+#define NVM_LOCKBITS_BLBB_gm 0xC0 /* Boot Lock Bits - Boot Section group mask. */
+#define NVM_LOCKBITS_BLBB_gp 6 /* Boot Lock Bits - Boot Section group position. */
+#define NVM_LOCKBITS_BLBB0_bm (1<<6) /* Boot Lock Bits - Boot Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBB0_bp 6 /* Boot Lock Bits - Boot Section bit 0 position. */
+#define NVM_LOCKBITS_BLBB1_bm (1<<7) /* Boot Lock Bits - Boot Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBB1_bp 7 /* Boot Lock Bits - Boot Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBA_gm 0x30 /* Boot Lock Bits - Application Section group mask. */
+#define NVM_LOCKBITS_BLBA_gp 4 /* Boot Lock Bits - Application Section group position. */
+#define NVM_LOCKBITS_BLBA0_bm (1<<4) /* Boot Lock Bits - Application Section bit 0 mask. */
+#define NVM_LOCKBITS_BLBA0_bp 4 /* Boot Lock Bits - Application Section bit 0 position. */
+#define NVM_LOCKBITS_BLBA1_bm (1<<5) /* Boot Lock Bits - Application Section bit 1 mask. */
+#define NVM_LOCKBITS_BLBA1_bp 5 /* Boot Lock Bits - Application Section bit 1 position. */
+
+#define NVM_LOCKBITS_BLBAT_gm 0x0C /* Boot Lock Bits - Application Table group mask. */
+#define NVM_LOCKBITS_BLBAT_gp 2 /* Boot Lock Bits - Application Table group position. */
+#define NVM_LOCKBITS_BLBAT0_bm (1<<2) /* Boot Lock Bits - Application Table bit 0 mask. */
+#define NVM_LOCKBITS_BLBAT0_bp 2 /* Boot Lock Bits - Application Table bit 0 position. */
+#define NVM_LOCKBITS_BLBAT1_bm (1<<3) /* Boot Lock Bits - Application Table bit 1 mask. */
+#define NVM_LOCKBITS_BLBAT1_bp 3 /* Boot Lock Bits - Application Table bit 1 position. */
+
+#define NVM_LOCKBITS_LB_gm 0x03 /* Lock Bits group mask. */
+#define NVM_LOCKBITS_LB_gp 0 /* Lock Bits group position. */
+#define NVM_LOCKBITS_LB0_bm (1<<0) /* Lock Bits bit 0 mask. */
+#define NVM_LOCKBITS_LB0_bp 0 /* Lock Bits bit 0 position. */
+#define NVM_LOCKBITS_LB1_bm (1<<1) /* Lock Bits bit 1 mask. */
+#define NVM_LOCKBITS_LB1_bp 1 /* Lock Bits bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE0 bit masks and bit positions */
+#define NVM_FUSES_USERID_gm 0xFF /* User ID group mask. */
+#define NVM_FUSES_USERID_gp 0 /* User ID group position. */
+#define NVM_FUSES_USERID0_bm (1<<0) /* User ID bit 0 mask. */
+#define NVM_FUSES_USERID0_bp 0 /* User ID bit 0 position. */
+#define NVM_FUSES_USERID1_bm (1<<1) /* User ID bit 1 mask. */
+#define NVM_FUSES_USERID1_bp 1 /* User ID bit 1 position. */
+#define NVM_FUSES_USERID2_bm (1<<2) /* User ID bit 2 mask. */
+#define NVM_FUSES_USERID2_bp 2 /* User ID bit 2 position. */
+#define NVM_FUSES_USERID3_bm (1<<3) /* User ID bit 3 mask. */
+#define NVM_FUSES_USERID3_bp 3 /* User ID bit 3 position. */
+#define NVM_FUSES_USERID4_bm (1<<4) /* User ID bit 4 mask. */
+#define NVM_FUSES_USERID4_bp 4 /* User ID bit 4 position. */
+#define NVM_FUSES_USERID5_bm (1<<5) /* User ID bit 5 mask. */
+#define NVM_FUSES_USERID5_bp 5 /* User ID bit 5 position. */
+#define NVM_FUSES_USERID6_bm (1<<6) /* User ID bit 6 mask. */
+#define NVM_FUSES_USERID6_bp 6 /* User ID bit 6 position. */
+#define NVM_FUSES_USERID7_bm (1<<7) /* User ID bit 7 mask. */
+#define NVM_FUSES_USERID7_bp 7 /* User ID bit 7 position. */
+
+
+/* NVM_FUSES.FUSEBYTE1 bit masks and bit positions */
+#define NVM_FUSES_WDWP_gm 0xF0 /* Watchdog Window Timeout Period group mask. */
+#define NVM_FUSES_WDWP_gp 4 /* Watchdog Window Timeout Period group position. */
+#define NVM_FUSES_WDWP0_bm (1<<4) /* Watchdog Window Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDWP0_bp 4 /* Watchdog Window Timeout Period bit 0 position. */
+#define NVM_FUSES_WDWP1_bm (1<<5) /* Watchdog Window Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDWP1_bp 5 /* Watchdog Window Timeout Period bit 1 position. */
+#define NVM_FUSES_WDWP2_bm (1<<6) /* Watchdog Window Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDWP2_bp 6 /* Watchdog Window Timeout Period bit 2 position. */
+#define NVM_FUSES_WDWP3_bm (1<<7) /* Watchdog Window Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDWP3_bp 7 /* Watchdog Window Timeout Period bit 3 position. */
+
+#define NVM_FUSES_WDP_gm 0x0F /* Watchdog Timeout Period group mask. */
+#define NVM_FUSES_WDP_gp 0 /* Watchdog Timeout Period group position. */
+#define NVM_FUSES_WDP0_bm (1<<0) /* Watchdog Timeout Period bit 0 mask. */
+#define NVM_FUSES_WDP0_bp 0 /* Watchdog Timeout Period bit 0 position. */
+#define NVM_FUSES_WDP1_bm (1<<1) /* Watchdog Timeout Period bit 1 mask. */
+#define NVM_FUSES_WDP1_bp 1 /* Watchdog Timeout Period bit 1 position. */
+#define NVM_FUSES_WDP2_bm (1<<2) /* Watchdog Timeout Period bit 2 mask. */
+#define NVM_FUSES_WDP2_bp 2 /* Watchdog Timeout Period bit 2 position. */
+#define NVM_FUSES_WDP3_bm (1<<3) /* Watchdog Timeout Period bit 3 mask. */
+#define NVM_FUSES_WDP3_bp 3 /* Watchdog Timeout Period bit 3 position. */
+
+
+/* NVM_FUSES.FUSEBYTE2 bit masks and bit positions */
+#define NVM_FUSES_DVSDON_bm 0x80 /* Spike Detector Enable bit mask. */
+#define NVM_FUSES_DVSDON_bp 7 /* Spike Detector Enable bit position. */
+
+#define NVM_FUSES_BOOTRST_bm 0x40 /* Boot Loader Section Reset Vector bit mask. */
+#define NVM_FUSES_BOOTRST_bp 6 /* Boot Loader Section Reset Vector bit position. */
+
+#define NVM_FUSES_BODPD_gm 0x03 /* BOD Operation in Power-Down Mode group mask. */
+#define NVM_FUSES_BODPD_gp 0 /* BOD Operation in Power-Down Mode group position. */
+#define NVM_FUSES_BODPD0_bm (1<<0) /* BOD Operation in Power-Down Mode bit 0 mask. */
+#define NVM_FUSES_BODPD0_bp 0 /* BOD Operation in Power-Down Mode bit 0 position. */
+#define NVM_FUSES_BODPD1_bm (1<<1) /* BOD Operation in Power-Down Mode bit 1 mask. */
+#define NVM_FUSES_BODPD1_bp 1 /* BOD Operation in Power-Down Mode bit 1 position. */
+
+
+/* NVM_FUSES.FUSEBYTE4 bit masks and bit positions */
+#define NVM_FUSES_SUT_gm 0x0C /* Start-up Time group mask. */
+#define NVM_FUSES_SUT_gp 2 /* Start-up Time group position. */
+#define NVM_FUSES_SUT0_bm (1<<2) /* Start-up Time bit 0 mask. */
+#define NVM_FUSES_SUT0_bp 2 /* Start-up Time bit 0 position. */
+#define NVM_FUSES_SUT1_bm (1<<3) /* Start-up Time bit 1 mask. */
+#define NVM_FUSES_SUT1_bp 3 /* Start-up Time bit 1 position. */
+
+#define NVM_FUSES_WDLOCK_bm 0x02 /* Watchdog Timer Lock bit mask. */
+#define NVM_FUSES_WDLOCK_bp 1 /* Watchdog Timer Lock bit position. */
+
+
+/* NVM_FUSES.FUSEBYTE5 bit masks and bit positions */
+#define NVM_FUSES_BODACT_gm 0x30 /* BOD Operation in Active Mode group mask. */
+#define NVM_FUSES_BODACT_gp 4 /* BOD Operation in Active Mode group position. */
+#define NVM_FUSES_BODACT0_bm (1<<4) /* BOD Operation in Active Mode bit 0 mask. */
+#define NVM_FUSES_BODACT0_bp 4 /* BOD Operation in Active Mode bit 0 position. */
+#define NVM_FUSES_BODACT1_bm (1<<5) /* BOD Operation in Active Mode bit 1 mask. */
+#define NVM_FUSES_BODACT1_bp 5 /* BOD Operation in Active Mode bit 1 position. */
+
+#define NVM_FUSES_EESAVE_bm 0x08 /* Preserve EEPROM Through Chip Erase bit mask. */
+#define NVM_FUSES_EESAVE_bp 3 /* Preserve EEPROM Through Chip Erase bit position. */
+
+#define NVM_FUSES_BODLVL_gm 0x07 /* Brown Out Detection Voltage Level group mask. */
+#define NVM_FUSES_BODLVL_gp 0 /* Brown Out Detection Voltage Level group position. */
+#define NVM_FUSES_BODLVL0_bm (1<<0) /* Brown Out Detection Voltage Level bit 0 mask. */
+#define NVM_FUSES_BODLVL0_bp 0 /* Brown Out Detection Voltage Level bit 0 position. */
+#define NVM_FUSES_BODLVL1_bm (1<<1) /* Brown Out Detection Voltage Level bit 1 mask. */
+#define NVM_FUSES_BODLVL1_bp 1 /* Brown Out Detection Voltage Level bit 1 position. */
+#define NVM_FUSES_BODLVL2_bm (1<<2) /* Brown Out Detection Voltage Level bit 2 mask. */
+#define NVM_FUSES_BODLVL2_bp 2 /* Brown Out Detection Voltage Level bit 2 position. */
+
+
+/* AC - Analog Comparator */
+/* AC.AC0CTRL bit masks and bit positions */
+#define AC_INTMODE_gm 0xC0 /* Interrupt Mode group mask. */
+#define AC_INTMODE_gp 6 /* Interrupt Mode group position. */
+#define AC_INTMODE0_bm (1<<6) /* Interrupt Mode bit 0 mask. */
+#define AC_INTMODE0_bp 6 /* Interrupt Mode bit 0 position. */
+#define AC_INTMODE1_bm (1<<7) /* Interrupt Mode bit 1 mask. */
+#define AC_INTMODE1_bp 7 /* Interrupt Mode bit 1 position. */
+
+#define AC_INTLVL_gm 0x30 /* Interrupt Level group mask. */
+#define AC_INTLVL_gp 4 /* Interrupt Level group position. */
+#define AC_INTLVL0_bm (1<<4) /* Interrupt Level bit 0 mask. */
+#define AC_INTLVL0_bp 4 /* Interrupt Level bit 0 position. */
+#define AC_INTLVL1_bm (1<<5) /* Interrupt Level bit 1 mask. */
+#define AC_INTLVL1_bp 5 /* Interrupt Level bit 1 position. */
+
+#define AC_HSMODE_bm 0x08 /* High-speed Mode bit mask. */
+#define AC_HSMODE_bp 3 /* High-speed Mode bit position. */
+
+#define AC_HYSMODE_gm 0x06 /* Hysteresis Mode group mask. */
+#define AC_HYSMODE_gp 1 /* Hysteresis Mode group position. */
+#define AC_HYSMODE0_bm (1<<1) /* Hysteresis Mode bit 0 mask. */
+#define AC_HYSMODE0_bp 1 /* Hysteresis Mode bit 0 position. */
+#define AC_HYSMODE1_bm (1<<2) /* Hysteresis Mode bit 1 mask. */
+#define AC_HYSMODE1_bp 2 /* Hysteresis Mode bit 1 position. */
+
+#define AC_ENABLE_bm 0x01 /* Enable bit mask. */
+#define AC_ENABLE_bp 0 /* Enable bit position. */
+
+
+/* AC.AC1CTRL bit masks and bit positions */
+/* AC_INTMODE_gm Predefined. */
+/* AC_INTMODE_gp Predefined. */
+/* AC_INTMODE0_bm Predefined. */
+/* AC_INTMODE0_bp Predefined. */
+/* AC_INTMODE1_bm Predefined. */
+/* AC_INTMODE1_bp Predefined. */
+
+/* AC_INTLVL_gm Predefined. */
+/* AC_INTLVL_gp Predefined. */
+/* AC_INTLVL0_bm Predefined. */
+/* AC_INTLVL0_bp Predefined. */
+/* AC_INTLVL1_bm Predefined. */
+/* AC_INTLVL1_bp Predefined. */
+
+/* AC_HSMODE_bm Predefined. */
+/* AC_HSMODE_bp Predefined. */
+
+/* AC_HYSMODE_gm Predefined. */
+/* AC_HYSMODE_gp Predefined. */
+/* AC_HYSMODE0_bm Predefined. */
+/* AC_HYSMODE0_bp Predefined. */
+/* AC_HYSMODE1_bm Predefined. */
+/* AC_HYSMODE1_bp Predefined. */
+
+/* AC_ENABLE_bm Predefined. */
+/* AC_ENABLE_bp Predefined. */
+
+
+/* AC.AC0MUXCTRL bit masks and bit positions */
+#define AC_MUXPOS_gm 0x38 /* MUX Positive Input group mask. */
+#define AC_MUXPOS_gp 3 /* MUX Positive Input group position. */
+#define AC_MUXPOS0_bm (1<<3) /* MUX Positive Input bit 0 mask. */
+#define AC_MUXPOS0_bp 3 /* MUX Positive Input bit 0 position. */
+#define AC_MUXPOS1_bm (1<<4) /* MUX Positive Input bit 1 mask. */
+#define AC_MUXPOS1_bp 4 /* MUX Positive Input bit 1 position. */
+#define AC_MUXPOS2_bm (1<<5) /* MUX Positive Input bit 2 mask. */
+#define AC_MUXPOS2_bp 5 /* MUX Positive Input bit 2 position. */
+
+#define AC_MUXNEG_gm 0x07 /* MUX Negative Input group mask. */
+#define AC_MUXNEG_gp 0 /* MUX Negative Input group position. */
+#define AC_MUXNEG0_bm (1<<0) /* MUX Negative Input bit 0 mask. */
+#define AC_MUXNEG0_bp 0 /* MUX Negative Input bit 0 position. */
+#define AC_MUXNEG1_bm (1<<1) /* MUX Negative Input bit 1 mask. */
+#define AC_MUXNEG1_bp 1 /* MUX Negative Input bit 1 position. */
+#define AC_MUXNEG2_bm (1<<2) /* MUX Negative Input bit 2 mask. */
+#define AC_MUXNEG2_bp 2 /* MUX Negative Input bit 2 position. */
+
+
+/* AC.AC1MUXCTRL bit masks and bit positions */
+/* AC_MUXPOS_gm Predefined. */
+/* AC_MUXPOS_gp Predefined. */
+/* AC_MUXPOS0_bm Predefined. */
+/* AC_MUXPOS0_bp Predefined. */
+/* AC_MUXPOS1_bm Predefined. */
+/* AC_MUXPOS1_bp Predefined. */
+/* AC_MUXPOS2_bm Predefined. */
+/* AC_MUXPOS2_bp Predefined. */
+
+/* AC_MUXNEG_gm Predefined. */
+/* AC_MUXNEG_gp Predefined. */
+/* AC_MUXNEG0_bm Predefined. */
+/* AC_MUXNEG0_bp Predefined. */
+/* AC_MUXNEG1_bm Predefined. */
+/* AC_MUXNEG1_bp Predefined. */
+/* AC_MUXNEG2_bm Predefined. */
+/* AC_MUXNEG2_bp Predefined. */
+
+
+/* AC.CTRLA bit masks and bit positions */
+#define AC_AC0OUT_bm 0x01 /* Comparator 0 Output Enable bit mask. */
+#define AC_AC0OUT_bp 0 /* Comparator 0 Output Enable bit position. */
+
+
+/* AC.CTRLB bit masks and bit positions */
+#define AC_SCALEFAC_gm 0x3F /* VCC Voltage Scaler Factor group mask. */
+#define AC_SCALEFAC_gp 0 /* VCC Voltage Scaler Factor group position. */
+#define AC_SCALEFAC0_bm (1<<0) /* VCC Voltage Scaler Factor bit 0 mask. */
+#define AC_SCALEFAC0_bp 0 /* VCC Voltage Scaler Factor bit 0 position. */
+#define AC_SCALEFAC1_bm (1<<1) /* VCC Voltage Scaler Factor bit 1 mask. */
+#define AC_SCALEFAC1_bp 1 /* VCC Voltage Scaler Factor bit 1 position. */
+#define AC_SCALEFAC2_bm (1<<2) /* VCC Voltage Scaler Factor bit 2 mask. */
+#define AC_SCALEFAC2_bp 2 /* VCC Voltage Scaler Factor bit 2 position. */
+#define AC_SCALEFAC3_bm (1<<3) /* VCC Voltage Scaler Factor bit 3 mask. */
+#define AC_SCALEFAC3_bp 3 /* VCC Voltage Scaler Factor bit 3 position. */
+#define AC_SCALEFAC4_bm (1<<4) /* VCC Voltage Scaler Factor bit 4 mask. */
+#define AC_SCALEFAC4_bp 4 /* VCC Voltage Scaler Factor bit 4 position. */
+#define AC_SCALEFAC5_bm (1<<5) /* VCC Voltage Scaler Factor bit 5 mask. */
+#define AC_SCALEFAC5_bp 5 /* VCC Voltage Scaler Factor bit 5 position. */
+
+
+/* AC.WINCTRL bit masks and bit positions */
+#define AC_WEN_bm 0x10 /* Window Mode Enable bit mask. */
+#define AC_WEN_bp 4 /* Window Mode Enable bit position. */
+
+#define AC_WINTMODE_gm 0x0C /* Window Interrupt Mode group mask. */
+#define AC_WINTMODE_gp 2 /* Window Interrupt Mode group position. */
+#define AC_WINTMODE0_bm (1<<2) /* Window Interrupt Mode bit 0 mask. */
+#define AC_WINTMODE0_bp 2 /* Window Interrupt Mode bit 0 position. */
+#define AC_WINTMODE1_bm (1<<3) /* Window Interrupt Mode bit 1 mask. */
+#define AC_WINTMODE1_bp 3 /* Window Interrupt Mode bit 1 position. */
+
+#define AC_WINTLVL_gm 0x03 /* Window Interrupt Level group mask. */
+#define AC_WINTLVL_gp 0 /* Window Interrupt Level group position. */
+#define AC_WINTLVL0_bm (1<<0) /* Window Interrupt Level bit 0 mask. */
+#define AC_WINTLVL0_bp 0 /* Window Interrupt Level bit 0 position. */
+#define AC_WINTLVL1_bm (1<<1) /* Window Interrupt Level bit 1 mask. */
+#define AC_WINTLVL1_bp 1 /* Window Interrupt Level bit 1 position. */
+
+
+/* AC.STATUS bit masks and bit positions */
+#define AC_WSTATE_gm 0xC0 /* Window Mode State group mask. */
+#define AC_WSTATE_gp 6 /* Window Mode State group position. */
+#define AC_WSTATE0_bm (1<<6) /* Window Mode State bit 0 mask. */
+#define AC_WSTATE0_bp 6 /* Window Mode State bit 0 position. */
+#define AC_WSTATE1_bm (1<<7) /* Window Mode State bit 1 mask. */
+#define AC_WSTATE1_bp 7 /* Window Mode State bit 1 position. */
+
+#define AC_AC1STATE_bm 0x20 /* Comparator 1 State bit mask. */
+#define AC_AC1STATE_bp 5 /* Comparator 1 State bit position. */
+
+#define AC_AC0STATE_bm 0x10 /* Comparator 0 State bit mask. */
+#define AC_AC0STATE_bp 4 /* Comparator 0 State bit position. */
+
+#define AC_WIF_bm 0x04 /* Window Mode Interrupt Flag bit mask. */
+#define AC_WIF_bp 2 /* Window Mode Interrupt Flag bit position. */
+
+#define AC_AC1IF_bm 0x02 /* Comparator 1 Interrupt Flag bit mask. */
+#define AC_AC1IF_bp 1 /* Comparator 1 Interrupt Flag bit position. */
+
+#define AC_AC0IF_bm 0x01 /* Comparator 0 Interrupt Flag bit mask. */
+#define AC_AC0IF_bp 0 /* Comparator 0 Interrupt Flag bit position. */
+
+
+/* ADC - Analog/Digital Converter */
+/* ADC_CH.CTRL bit masks and bit positions */
+#define ADC_CH_START_bm 0x80 /* Channel Start Conversion bit mask. */
+#define ADC_CH_START_bp 7 /* Channel Start Conversion bit position. */
+
+#define ADC_CH_GAINFAC_gm 0x1C /* Gain Factor group mask. */
+#define ADC_CH_GAINFAC_gp 2 /* Gain Factor group position. */
+#define ADC_CH_GAINFAC0_bm (1<<2) /* Gain Factor bit 0 mask. */
+#define ADC_CH_GAINFAC0_bp 2 /* Gain Factor bit 0 position. */
+#define ADC_CH_GAINFAC1_bm (1<<3) /* Gain Factor bit 1 mask. */
+#define ADC_CH_GAINFAC1_bp 3 /* Gain Factor bit 1 position. */
+#define ADC_CH_GAINFAC2_bm (1<<4) /* Gain Factor bit 2 mask. */
+#define ADC_CH_GAINFAC2_bp 4 /* Gain Factor bit 2 position. */
+
+#define ADC_CH_INPUTMODE_gm 0x03 /* Input Mode Select group mask. */
+#define ADC_CH_INPUTMODE_gp 0 /* Input Mode Select group position. */
+#define ADC_CH_INPUTMODE0_bm (1<<0) /* Input Mode Select bit 0 mask. */
+#define ADC_CH_INPUTMODE0_bp 0 /* Input Mode Select bit 0 position. */
+#define ADC_CH_INPUTMODE1_bm (1<<1) /* Input Mode Select bit 1 mask. */
+#define ADC_CH_INPUTMODE1_bp 1 /* Input Mode Select bit 1 position. */
+
+
+/* ADC_CH.MUXCTRL bit masks and bit positions */
+#define ADC_CH_MUXPOS_gm 0x78 /* Positive Input Select group mask. */
+#define ADC_CH_MUXPOS_gp 3 /* Positive Input Select group position. */
+#define ADC_CH_MUXPOS0_bm (1<<3) /* Positive Input Select bit 0 mask. */
+#define ADC_CH_MUXPOS0_bp 3 /* Positive Input Select bit 0 position. */
+#define ADC_CH_MUXPOS1_bm (1<<4) /* Positive Input Select bit 1 mask. */
+#define ADC_CH_MUXPOS1_bp 4 /* Positive Input Select bit 1 position. */
+#define ADC_CH_MUXPOS2_bm (1<<5) /* Positive Input Select bit 2 mask. */
+#define ADC_CH_MUXPOS2_bp 5 /* Positive Input Select bit 2 position. */
+#define ADC_CH_MUXPOS3_bm (1<<6) /* Positive Input Select bit 3 mask. */
+#define ADC_CH_MUXPOS3_bp 6 /* Positive Input Select bit 3 position. */
+
+#define ADC_CH_MUXINT_gm 0x78 /* Internal Input Select group mask. */
+#define ADC_CH_MUXINT_gp 3 /* Internal Input Select group position. */
+#define ADC_CH_MUXINT0_bm (1<<3) /* Internal Input Select bit 0 mask. */
+#define ADC_CH_MUXINT0_bp 3 /* Internal Input Select bit 0 position. */
+#define ADC_CH_MUXINT1_bm (1<<4) /* Internal Input Select bit 1 mask. */
+#define ADC_CH_MUXINT1_bp 4 /* Internal Input Select bit 1 position. */
+#define ADC_CH_MUXINT2_bm (1<<5) /* Internal Input Select bit 2 mask. */
+#define ADC_CH_MUXINT2_bp 5 /* Internal Input Select bit 2 position. */
+#define ADC_CH_MUXINT3_bm (1<<6) /* Internal Input Select bit 3 mask. */
+#define ADC_CH_MUXINT3_bp 6 /* Internal Input Select bit 3 position. */
+
+#define ADC_CH_MUXNEG_gm 0x03 /* Negative Input Select group mask. */
+#define ADC_CH_MUXNEG_gp 0 /* Negative Input Select group position. */
+#define ADC_CH_MUXNEG0_bm (1<<0) /* Negative Input Select bit 0 mask. */
+#define ADC_CH_MUXNEG0_bp 0 /* Negative Input Select bit 0 position. */
+#define ADC_CH_MUXNEG1_bm (1<<1) /* Negative Input Select bit 1 mask. */
+#define ADC_CH_MUXNEG1_bp 1 /* Negative Input Select bit 1 position. */
+
+
+/* ADC_CH.INTCTRL bit masks and bit positions */
+#define ADC_CH_INTMODE_gm 0x0C /* Interrupt Mode group mask. */
+#define ADC_CH_INTMODE_gp 2 /* Interrupt Mode group position. */
+#define ADC_CH_INTMODE0_bm (1<<2) /* Interrupt Mode bit 0 mask. */
+#define ADC_CH_INTMODE0_bp 2 /* Interrupt Mode bit 0 position. */
+#define ADC_CH_INTMODE1_bm (1<<3) /* Interrupt Mode bit 1 mask. */
+#define ADC_CH_INTMODE1_bp 3 /* Interrupt Mode bit 1 position. */
+
+#define ADC_CH_INTLVL_gm 0x03 /* Interrupt Level group mask. */
+#define ADC_CH_INTLVL_gp 0 /* Interrupt Level group position. */
+#define ADC_CH_INTLVL0_bm (1<<0) /* Interrupt Level bit 0 mask. */
+#define ADC_CH_INTLVL0_bp 0 /* Interrupt Level bit 0 position. */
+#define ADC_CH_INTLVL1_bm (1<<1) /* Interrupt Level bit 1 mask. */
+#define ADC_CH_INTLVL1_bp 1 /* Interrupt Level bit 1 position. */
+
+
+/* ADC_CH.INTFLAGS bit masks and bit positions */
+#define ADC_CH_CHIF_bm 0x01 /* Channel Interrupt Flag bit mask. */
+#define ADC_CH_CHIF_bp 0 /* Channel Interrupt Flag bit position. */
+
+
+/* ADC.CTRLA bit masks and bit positions */
+#define ADC_CH0START_bm 0x04 /* Channel 0 Start Conversion bit mask. */
+#define ADC_CH0START_bp 2 /* Channel 0 Start Conversion bit position. */
+
+#define ADC_ENABLE_bm 0x01 /* Enable ADC bit mask. */
+#define ADC_ENABLE_bp 0 /* Enable ADC bit position. */
+
+
+/* ADC.CTRLB bit masks and bit positions */
+#define ADC_CONMODE_bm 0x10 /* Conversion Mode bit mask. */
+#define ADC_CONMODE_bp 4 /* Conversion Mode bit position. */
+
+#define ADC_FREERUN_bm 0x08 /* Free Running Mode Enable bit mask. */
+#define ADC_FREERUN_bp 3 /* Free Running Mode Enable bit position. */
+
+#define ADC_RESOLUTION_gm 0x06 /* Result Resolution group mask. */
+#define ADC_RESOLUTION_gp 1 /* Result Resolution group position. */
+#define ADC_RESOLUTION0_bm (1<<1) /* Result Resolution bit 0 mask. */
+#define ADC_RESOLUTION0_bp 1 /* Result Resolution bit 0 position. */
+#define ADC_RESOLUTION1_bm (1<<2) /* Result Resolution bit 1 mask. */
+#define ADC_RESOLUTION1_bp 2 /* Result Resolution bit 1 position. */
+
+
+/* ADC.REFCTRL bit masks and bit positions */
+#define ADC_REFSEL_gm 0x30 /* Reference Selection group mask. */
+#define ADC_REFSEL_gp 4 /* Reference Selection group position. */
+#define ADC_REFSEL0_bm (1<<4) /* Reference Selection bit 0 mask. */
+#define ADC_REFSEL0_bp 4 /* Reference Selection bit 0 position. */
+#define ADC_REFSEL1_bm (1<<5) /* Reference Selection bit 1 mask. */
+#define ADC_REFSEL1_bp 5 /* Reference Selection bit 1 position. */
+
+#define ADC_BANDGAP_bm 0x02 /* Bandgap enable bit mask. */
+#define ADC_BANDGAP_bp 1 /* Bandgap enable bit position. */
+
+#define ADC_TEMPREF_bm 0x01 /* Temperature Reference Enable bit mask. */
+#define ADC_TEMPREF_bp 0 /* Temperature Reference Enable bit position. */
+
+
+/* ADC.EVCTRL bit masks and bit positions */
+#define ADC_SWEEP_gm 0xC0 /* Channel Sweep Selection group mask. */
+#define ADC_SWEEP_gp 6 /* Channel Sweep Selection group position. */
+#define ADC_SWEEP0_bm (1<<6) /* Channel Sweep Selection bit 0 mask. */
+#define ADC_SWEEP0_bp 6 /* Channel Sweep Selection bit 0 position. */
+#define ADC_SWEEP1_bm (1<<7) /* Channel Sweep Selection bit 1 mask. */
+#define ADC_SWEEP1_bp 7 /* Channel Sweep Selection bit 1 position. */
+
+#define ADC_EVSEL_gm 0x38 /* Event Input Select group mask. */
+#define ADC_EVSEL_gp 3 /* Event Input Select group position. */
+#define ADC_EVSEL0_bm (1<<3) /* Event Input Select bit 0 mask. */
+#define ADC_EVSEL0_bp 3 /* Event Input Select bit 0 position. */
+#define ADC_EVSEL1_bm (1<<4) /* Event Input Select bit 1 mask. */
+#define ADC_EVSEL1_bp 4 /* Event Input Select bit 1 position. */
+#define ADC_EVSEL2_bm (1<<5) /* Event Input Select bit 2 mask. */
+#define ADC_EVSEL2_bp 5 /* Event Input Select bit 2 position. */
+
+#define ADC_EVACT_gm 0x07 /* Event Action Select group mask. */
+#define ADC_EVACT_gp 0 /* Event Action Select group position. */
+#define ADC_EVACT0_bm (1<<0) /* Event Action Select bit 0 mask. */
+#define ADC_EVACT0_bp 0 /* Event Action Select bit 0 position. */
+#define ADC_EVACT1_bm (1<<1) /* Event Action Select bit 1 mask. */
+#define ADC_EVACT1_bp 1 /* Event Action Select bit 1 position. */
+#define ADC_EVACT2_bm (1<<2) /* Event Action Select bit 2 mask. */
+#define ADC_EVACT2_bp 2 /* Event Action Select bit 2 position. */
+
+
+/* ADC.PRESCALER bit masks and bit positions */
+#define ADC_PRESCALER_gm 0x07 /* Clock Prescaler Selection group mask. */
+#define ADC_PRESCALER_gp 0 /* Clock Prescaler Selection group position. */
+#define ADC_PRESCALER0_bm (1<<0) /* Clock Prescaler Selection bit 0 mask. */
+#define ADC_PRESCALER0_bp 0 /* Clock Prescaler Selection bit 0 position. */
+#define ADC_PRESCALER1_bm (1<<1) /* Clock Prescaler Selection bit 1 mask. */
+#define ADC_PRESCALER1_bp 1 /* Clock Prescaler Selection bit 1 position. */
+#define ADC_PRESCALER2_bm (1<<2) /* Clock Prescaler Selection bit 2 mask. */
+#define ADC_PRESCALER2_bp 2 /* Clock Prescaler Selection bit 2 position. */
+
+
+/* ADC.CALCTRL bit masks and bit positions */
+#define ADC_CAL_bm 0x01 /* ADC Calibration Start bit mask. */
+#define ADC_CAL_bp 0 /* ADC Calibration Start bit position. */
+
+
+/* ADC.INTFLAGS bit masks and bit positions */
+#define ADC_CH0IF_bm 0x01 /* Channel 0 Interrupt Flag bit mask. */
+#define ADC_CH0IF_bp 0 /* Channel 0 Interrupt Flag bit position. */
+
+
+/* RTC - Real-Time Clounter */
+/* RTC.CTRL bit masks and bit positions */
+#define RTC_PRESCALER_gm 0x07 /* Prescaling Factor group mask. */
+#define RTC_PRESCALER_gp 0 /* Prescaling Factor group position. */
+#define RTC_PRESCALER0_bm (1<<0) /* Prescaling Factor bit 0 mask. */
+#define RTC_PRESCALER0_bp 0 /* Prescaling Factor bit 0 position. */
+#define RTC_PRESCALER1_bm (1<<1) /* Prescaling Factor bit 1 mask. */
+#define RTC_PRESCALER1_bp 1 /* Prescaling Factor bit 1 position. */
+#define RTC_PRESCALER2_bm (1<<2) /* Prescaling Factor bit 2 mask. */
+#define RTC_PRESCALER2_bp 2 /* Prescaling Factor bit 2 position. */
+
+
+/* RTC.STATUS bit masks and bit positions */
+#define RTC_SYNCBUSY_bm 0x01 /* Synchronization Busy Flag bit mask. */
+#define RTC_SYNCBUSY_bp 0 /* Synchronization Busy Flag bit position. */
+
+
+/* RTC.INTCTRL bit masks and bit positions */
+#define RTC_COMPINTLVL_gm 0x0C /* Compare Match Interrupt Level group mask. */
+#define RTC_COMPINTLVL_gp 2 /* Compare Match Interrupt Level group position. */
+#define RTC_COMPINTLVL0_bm (1<<2) /* Compare Match Interrupt Level bit 0 mask. */
+#define RTC_COMPINTLVL0_bp 2 /* Compare Match Interrupt Level bit 0 position. */
+#define RTC_COMPINTLVL1_bm (1<<3) /* Compare Match Interrupt Level bit 1 mask. */
+#define RTC_COMPINTLVL1_bp 3 /* Compare Match Interrupt Level bit 1 position. */
+
+#define RTC_OVFINTLVL_gm 0x03 /* Overflow Interrupt Level group mask. */
+#define RTC_OVFINTLVL_gp 0 /* Overflow Interrupt Level group position. */
+#define RTC_OVFINTLVL0_bm (1<<0) /* Overflow Interrupt Level bit 0 mask. */
+#define RTC_OVFINTLVL0_bp 0 /* Overflow Interrupt Level bit 0 position. */
+#define RTC_OVFINTLVL1_bm (1<<1) /* Overflow Interrupt Level bit 1 mask. */
+#define RTC_OVFINTLVL1_bp 1 /* Overflow Interrupt Level bit 1 position. */
+
+
+/* RTC.INTFLAGS bit masks and bit positions */
+#define RTC_COMPIF_bm 0x02 /* Compare Match Interrupt Flag bit mask. */
+#define RTC_COMPIF_bp 1 /* Compare Match Interrupt Flag bit position. */
+
+#define RTC_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define RTC_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* EBI - External Bus Interface */
+/* EBI_CS.CTRLA bit masks and bit positions */
+#define EBI_CS_ASPACE_gm 0x7C /* Address Space group mask. */
+#define EBI_CS_ASPACE_gp 2 /* Address Space group position. */
+#define EBI_CS_ASPACE0_bm (1<<2) /* Address Space bit 0 mask. */
+#define EBI_CS_ASPACE0_bp 2 /* Address Space bit 0 position. */
+#define EBI_CS_ASPACE1_bm (1<<3) /* Address Space bit 1 mask. */
+#define EBI_CS_ASPACE1_bp 3 /* Address Space bit 1 position. */
+#define EBI_CS_ASPACE2_bm (1<<4) /* Address Space bit 2 mask. */
+#define EBI_CS_ASPACE2_bp 4 /* Address Space bit 2 position. */
+#define EBI_CS_ASPACE3_bm (1<<5) /* Address Space bit 3 mask. */
+#define EBI_CS_ASPACE3_bp 5 /* Address Space bit 3 position. */
+#define EBI_CS_ASPACE4_bm (1<<6) /* Address Space bit 4 mask. */
+#define EBI_CS_ASPACE4_bp 6 /* Address Space bit 4 position. */
+
+#define EBI_CS_MODE_gm 0x03 /* Memory Mode group mask. */
+#define EBI_CS_MODE_gp 0 /* Memory Mode group position. */
+#define EBI_CS_MODE0_bm (1<<0) /* Memory Mode bit 0 mask. */
+#define EBI_CS_MODE0_bp 0 /* Memory Mode bit 0 position. */
+#define EBI_CS_MODE1_bm (1<<1) /* Memory Mode bit 1 mask. */
+#define EBI_CS_MODE1_bp 1 /* Memory Mode bit 1 position. */
+
+
+/* EBI_CS.CTRLB bit masks and bit positions */
+#define EBI_CS_SRWS_gm 0x07 /* SRAM Wait State Cycles group mask. */
+#define EBI_CS_SRWS_gp 0 /* SRAM Wait State Cycles group position. */
+#define EBI_CS_SRWS0_bm (1<<0) /* SRAM Wait State Cycles bit 0 mask. */
+#define EBI_CS_SRWS0_bp 0 /* SRAM Wait State Cycles bit 0 position. */
+#define EBI_CS_SRWS1_bm (1<<1) /* SRAM Wait State Cycles bit 1 mask. */
+#define EBI_CS_SRWS1_bp 1 /* SRAM Wait State Cycles bit 1 position. */
+#define EBI_CS_SRWS2_bm (1<<2) /* SRAM Wait State Cycles bit 2 mask. */
+#define EBI_CS_SRWS2_bp 2 /* SRAM Wait State Cycles bit 2 position. */
+
+#define EBI_CS_SDINITDONE_bm 0x80 /* SDRAM Initialization Done bit mask. */
+#define EBI_CS_SDINITDONE_bp 7 /* SDRAM Initialization Done bit position. */
+
+#define EBI_CS_SDSREN_bm 0x04 /* SDRAM Self-refresh Enable bit mask. */
+#define EBI_CS_SDSREN_bp 2 /* SDRAM Self-refresh Enable bit position. */
+
+#define EBI_CS_SDMODE_gm 0x03 /* SDRAM Mode group mask. */
+#define EBI_CS_SDMODE_gp 0 /* SDRAM Mode group position. */
+#define EBI_CS_SDMODE0_bm (1<<0) /* SDRAM Mode bit 0 mask. */
+#define EBI_CS_SDMODE0_bp 0 /* SDRAM Mode bit 0 position. */
+#define EBI_CS_SDMODE1_bm (1<<1) /* SDRAM Mode bit 1 mask. */
+#define EBI_CS_SDMODE1_bp 1 /* SDRAM Mode bit 1 position. */
+
+
+/* EBI.CTRL bit masks and bit positions */
+#define EBI_SDDATAW_gm 0xC0 /* SDRAM Data Width Setting group mask. */
+#define EBI_SDDATAW_gp 6 /* SDRAM Data Width Setting group position. */
+#define EBI_SDDATAW0_bm (1<<6) /* SDRAM Data Width Setting bit 0 mask. */
+#define EBI_SDDATAW0_bp 6 /* SDRAM Data Width Setting bit 0 position. */
+#define EBI_SDDATAW1_bm (1<<7) /* SDRAM Data Width Setting bit 1 mask. */
+#define EBI_SDDATAW1_bp 7 /* SDRAM Data Width Setting bit 1 position. */
+
+#define EBI_LPCMODE_gm 0x30 /* SRAM LPC Mode group mask. */
+#define EBI_LPCMODE_gp 4 /* SRAM LPC Mode group position. */
+#define EBI_LPCMODE0_bm (1<<4) /* SRAM LPC Mode bit 0 mask. */
+#define EBI_LPCMODE0_bp 4 /* SRAM LPC Mode bit 0 position. */
+#define EBI_LPCMODE1_bm (1<<5) /* SRAM LPC Mode bit 1 mask. */
+#define EBI_LPCMODE1_bp 5 /* SRAM LPC Mode bit 1 position. */
+
+#define EBI_SRMODE_gm 0x0C /* SRAM Mode group mask. */
+#define EBI_SRMODE_gp 2 /* SRAM Mode group position. */
+#define EBI_SRMODE0_bm (1<<2) /* SRAM Mode bit 0 mask. */
+#define EBI_SRMODE0_bp 2 /* SRAM Mode bit 0 position. */
+#define EBI_SRMODE1_bm (1<<3) /* SRAM Mode bit 1 mask. */
+#define EBI_SRMODE1_bp 3 /* SRAM Mode bit 1 position. */
+
+#define EBI_IFMODE_gm 0x03 /* Interface Mode group mask. */
+#define EBI_IFMODE_gp 0 /* Interface Mode group position. */
+#define EBI_IFMODE0_bm (1<<0) /* Interface Mode bit 0 mask. */
+#define EBI_IFMODE0_bp 0 /* Interface Mode bit 0 position. */
+#define EBI_IFMODE1_bm (1<<1) /* Interface Mode bit 1 mask. */
+#define EBI_IFMODE1_bp 1 /* Interface Mode bit 1 position. */
+
+
+/* EBI.SDRAMCTRLA bit masks and bit positions */
+#define EBI_SDCAS_bm 0x08 /* SDRAM CAS Latency Setting bit mask. */
+#define EBI_SDCAS_bp 3 /* SDRAM CAS Latency Setting bit position. */
+
+#define EBI_SDROW_bm 0x04 /* SDRAM ROW Bits Setting bit mask. */
+#define EBI_SDROW_bp 2 /* SDRAM ROW Bits Setting bit position. */
+
+#define EBI_SDCOL_gm 0x03 /* SDRAM Column Bits Setting group mask. */
+#define EBI_SDCOL_gp 0 /* SDRAM Column Bits Setting group position. */
+#define EBI_SDCOL0_bm (1<<0) /* SDRAM Column Bits Setting bit 0 mask. */
+#define EBI_SDCOL0_bp 0 /* SDRAM Column Bits Setting bit 0 position. */
+#define EBI_SDCOL1_bm (1<<1) /* SDRAM Column Bits Setting bit 1 mask. */
+#define EBI_SDCOL1_bp 1 /* SDRAM Column Bits Setting bit 1 position. */
+
+
+/* EBI.SDRAMCTRLB bit masks and bit positions */
+#define EBI_MRDLY_gm 0xC0 /* SDRAM Mode Register Delay group mask. */
+#define EBI_MRDLY_gp 6 /* SDRAM Mode Register Delay group position. */
+#define EBI_MRDLY0_bm (1<<6) /* SDRAM Mode Register Delay bit 0 mask. */
+#define EBI_MRDLY0_bp 6 /* SDRAM Mode Register Delay bit 0 position. */
+#define EBI_MRDLY1_bm (1<<7) /* SDRAM Mode Register Delay bit 1 mask. */
+#define EBI_MRDLY1_bp 7 /* SDRAM Mode Register Delay bit 1 position. */
+
+#define EBI_ROWCYCDLY_gm 0x38 /* SDRAM Row Cycle Delay group mask. */
+#define EBI_ROWCYCDLY_gp 3 /* SDRAM Row Cycle Delay group position. */
+#define EBI_ROWCYCDLY0_bm (1<<3) /* SDRAM Row Cycle Delay bit 0 mask. */
+#define EBI_ROWCYCDLY0_bp 3 /* SDRAM Row Cycle Delay bit 0 position. */
+#define EBI_ROWCYCDLY1_bm (1<<4) /* SDRAM Row Cycle Delay bit 1 mask. */
+#define EBI_ROWCYCDLY1_bp 4 /* SDRAM Row Cycle Delay bit 1 position. */
+#define EBI_ROWCYCDLY2_bm (1<<5) /* SDRAM Row Cycle Delay bit 2 mask. */
+#define EBI_ROWCYCDLY2_bp 5 /* SDRAM Row Cycle Delay bit 2 position. */
+
+#define EBI_RPDLY_gm 0x07 /* SDRAM Row-to-Precharge Delay group mask. */
+#define EBI_RPDLY_gp 0 /* SDRAM Row-to-Precharge Delay group position. */
+#define EBI_RPDLY0_bm (1<<0) /* SDRAM Row-to-Precharge Delay bit 0 mask. */
+#define EBI_RPDLY0_bp 0 /* SDRAM Row-to-Precharge Delay bit 0 position. */
+#define EBI_RPDLY1_bm (1<<1) /* SDRAM Row-to-Precharge Delay bit 1 mask. */
+#define EBI_RPDLY1_bp 1 /* SDRAM Row-to-Precharge Delay bit 1 position. */
+#define EBI_RPDLY2_bm (1<<2) /* SDRAM Row-to-Precharge Delay bit 2 mask. */
+#define EBI_RPDLY2_bp 2 /* SDRAM Row-to-Precharge Delay bit 2 position. */
+
+
+/* EBI.SDRAMCTRLC bit masks and bit positions */
+#define EBI_WRDLY_gm 0xC0 /* SDRAM Write Recovery Delay group mask. */
+#define EBI_WRDLY_gp 6 /* SDRAM Write Recovery Delay group position. */
+#define EBI_WRDLY0_bm (1<<6) /* SDRAM Write Recovery Delay bit 0 mask. */
+#define EBI_WRDLY0_bp 6 /* SDRAM Write Recovery Delay bit 0 position. */
+#define EBI_WRDLY1_bm (1<<7) /* SDRAM Write Recovery Delay bit 1 mask. */
+#define EBI_WRDLY1_bp 7 /* SDRAM Write Recovery Delay bit 1 position. */
+
+#define EBI_ESRDLY_gm 0x38 /* SDRAM Exit-Self-refresh-to-Active Delay group mask. */
+#define EBI_ESRDLY_gp 3 /* SDRAM Exit-Self-refresh-to-Active Delay group position. */
+#define EBI_ESRDLY0_bm (1<<3) /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 mask. */
+#define EBI_ESRDLY0_bp 3 /* SDRAM Exit-Self-refresh-to-Active Delay bit 0 position. */
+#define EBI_ESRDLY1_bm (1<<4) /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 mask. */
+#define EBI_ESRDLY1_bp 4 /* SDRAM Exit-Self-refresh-to-Active Delay bit 1 position. */
+#define EBI_ESRDLY2_bm (1<<5) /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 mask. */
+#define EBI_ESRDLY2_bp 5 /* SDRAM Exit-Self-refresh-to-Active Delay bit 2 position. */
+
+#define EBI_ROWCOLDLY_gm 0x07 /* SDRAM Row-to-Column Delay group mask. */
+#define EBI_ROWCOLDLY_gp 0 /* SDRAM Row-to-Column Delay group position. */
+#define EBI_ROWCOLDLY0_bm (1<<0) /* SDRAM Row-to-Column Delay bit 0 mask. */
+#define EBI_ROWCOLDLY0_bp 0 /* SDRAM Row-to-Column Delay bit 0 position. */
+#define EBI_ROWCOLDLY1_bm (1<<1) /* SDRAM Row-to-Column Delay bit 1 mask. */
+#define EBI_ROWCOLDLY1_bp 1 /* SDRAM Row-to-Column Delay bit 1 position. */
+#define EBI_ROWCOLDLY2_bm (1<<2) /* SDRAM Row-to-Column Delay bit 2 mask. */
+#define EBI_ROWCOLDLY2_bp 2 /* SDRAM Row-to-Column Delay bit 2 position. */
+
+
+/* TWI - Two-Wire Interface */
+/* TWI_MASTER.CTRLA bit masks and bit positions */
+#define TWI_MASTER_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_MASTER_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_MASTER_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_MASTER_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_MASTER_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_MASTER_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_MASTER_RIEN_bm 0x20 /* Read Interrupt Enable bit mask. */
+#define TWI_MASTER_RIEN_bp 5 /* Read Interrupt Enable bit position. */
+
+#define TWI_MASTER_WIEN_bm 0x10 /* Write Interrupt Enable bit mask. */
+#define TWI_MASTER_WIEN_bp 4 /* Write Interrupt Enable bit position. */
+
+#define TWI_MASTER_ENABLE_bm 0x08 /* Enable TWI Master bit mask. */
+#define TWI_MASTER_ENABLE_bp 3 /* Enable TWI Master bit position. */
+
+
+/* TWI_MASTER.CTRLB bit masks and bit positions */
+#define TWI_MASTER_TIMEOUT_gm 0x0C /* Inactive Bus Timeout group mask. */
+#define TWI_MASTER_TIMEOUT_gp 2 /* Inactive Bus Timeout group position. */
+#define TWI_MASTER_TIMEOUT0_bm (1<<2) /* Inactive Bus Timeout bit 0 mask. */
+#define TWI_MASTER_TIMEOUT0_bp 2 /* Inactive Bus Timeout bit 0 position. */
+#define TWI_MASTER_TIMEOUT1_bm (1<<3) /* Inactive Bus Timeout bit 1 mask. */
+#define TWI_MASTER_TIMEOUT1_bp 3 /* Inactive Bus Timeout bit 1 position. */
+
+#define TWI_MASTER_QCEN_bm 0x02 /* Quick Command Enable bit mask. */
+#define TWI_MASTER_QCEN_bp 1 /* Quick Command Enable bit position. */
+
+#define TWI_MASTER_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_MASTER_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_MASTER.CTRLC bit masks and bit positions */
+#define TWI_MASTER_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_MASTER_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_MASTER_CMD_gm 0x03 /* Command group mask. */
+#define TWI_MASTER_CMD_gp 0 /* Command group position. */
+#define TWI_MASTER_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_MASTER_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_MASTER_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_MASTER_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_MASTER.STATUS bit masks and bit positions */
+#define TWI_MASTER_RIF_bm 0x80 /* Read Interrupt Flag bit mask. */
+#define TWI_MASTER_RIF_bp 7 /* Read Interrupt Flag bit position. */
+
+#define TWI_MASTER_WIF_bm 0x40 /* Write Interrupt Flag bit mask. */
+#define TWI_MASTER_WIF_bp 6 /* Write Interrupt Flag bit position. */
+
+#define TWI_MASTER_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_MASTER_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_MASTER_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_MASTER_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_MASTER_ARBLOST_bm 0x08 /* Arbitration Lost bit mask. */
+#define TWI_MASTER_ARBLOST_bp 3 /* Arbitration Lost bit position. */
+
+#define TWI_MASTER_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_MASTER_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_MASTER_BUSSTATE_gm 0x03 /* Bus State group mask. */
+#define TWI_MASTER_BUSSTATE_gp 0 /* Bus State group position. */
+#define TWI_MASTER_BUSSTATE0_bm (1<<0) /* Bus State bit 0 mask. */
+#define TWI_MASTER_BUSSTATE0_bp 0 /* Bus State bit 0 position. */
+#define TWI_MASTER_BUSSTATE1_bm (1<<1) /* Bus State bit 1 mask. */
+#define TWI_MASTER_BUSSTATE1_bp 1 /* Bus State bit 1 position. */
+
+
+/* TWI_SLAVE.CTRLA bit masks and bit positions */
+#define TWI_SLAVE_INTLVL_gm 0xC0 /* Interrupt Level group mask. */
+#define TWI_SLAVE_INTLVL_gp 6 /* Interrupt Level group position. */
+#define TWI_SLAVE_INTLVL0_bm (1<<6) /* Interrupt Level bit 0 mask. */
+#define TWI_SLAVE_INTLVL0_bp 6 /* Interrupt Level bit 0 position. */
+#define TWI_SLAVE_INTLVL1_bm (1<<7) /* Interrupt Level bit 1 mask. */
+#define TWI_SLAVE_INTLVL1_bp 7 /* Interrupt Level bit 1 position. */
+
+#define TWI_SLAVE_DIEN_bm 0x20 /* Data Interrupt Enable bit mask. */
+#define TWI_SLAVE_DIEN_bp 5 /* Data Interrupt Enable bit position. */
+
+#define TWI_SLAVE_APIEN_bm 0x10 /* Address/Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_APIEN_bp 4 /* Address/Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_ENABLE_bm 0x08 /* Enable TWI Slave bit mask. */
+#define TWI_SLAVE_ENABLE_bp 3 /* Enable TWI Slave bit position. */
+
+#define TWI_SLAVE_PIEN_bm 0x04 /* Stop Interrupt Enable bit mask. */
+#define TWI_SLAVE_PIEN_bp 2 /* Stop Interrupt Enable bit position. */
+
+#define TWI_SLAVE_PMEN_bm 0x02 /* Promiscuous Mode Enable bit mask. */
+#define TWI_SLAVE_PMEN_bp 1 /* Promiscuous Mode Enable bit position. */
+
+#define TWI_SLAVE_SMEN_bm 0x01 /* Smart Mode Enable bit mask. */
+#define TWI_SLAVE_SMEN_bp 0 /* Smart Mode Enable bit position. */
+
+
+/* TWI_SLAVE.CTRLB bit masks and bit positions */
+#define TWI_SLAVE_ACKACT_bm 0x04 /* Acknowledge Action bit mask. */
+#define TWI_SLAVE_ACKACT_bp 2 /* Acknowledge Action bit position. */
+
+#define TWI_SLAVE_CMD_gm 0x03 /* Command group mask. */
+#define TWI_SLAVE_CMD_gp 0 /* Command group position. */
+#define TWI_SLAVE_CMD0_bm (1<<0) /* Command bit 0 mask. */
+#define TWI_SLAVE_CMD0_bp 0 /* Command bit 0 position. */
+#define TWI_SLAVE_CMD1_bm (1<<1) /* Command bit 1 mask. */
+#define TWI_SLAVE_CMD1_bp 1 /* Command bit 1 position. */
+
+
+/* TWI_SLAVE.STATUS bit masks and bit positions */
+#define TWI_SLAVE_DIF_bm 0x80 /* Data Interrupt Flag bit mask. */
+#define TWI_SLAVE_DIF_bp 7 /* Data Interrupt Flag bit position. */
+
+#define TWI_SLAVE_APIF_bm 0x40 /* Address/Stop Interrupt Flag bit mask. */
+#define TWI_SLAVE_APIF_bp 6 /* Address/Stop Interrupt Flag bit position. */
+
+#define TWI_SLAVE_CLKHOLD_bm 0x20 /* Clock Hold bit mask. */
+#define TWI_SLAVE_CLKHOLD_bp 5 /* Clock Hold bit position. */
+
+#define TWI_SLAVE_RXACK_bm 0x10 /* Received Acknowledge bit mask. */
+#define TWI_SLAVE_RXACK_bp 4 /* Received Acknowledge bit position. */
+
+#define TWI_SLAVE_COLL_bm 0x08 /* Collision bit mask. */
+#define TWI_SLAVE_COLL_bp 3 /* Collision bit position. */
+
+#define TWI_SLAVE_BUSERR_bm 0x04 /* Bus Error bit mask. */
+#define TWI_SLAVE_BUSERR_bp 2 /* Bus Error bit position. */
+
+#define TWI_SLAVE_DIR_bm 0x02 /* Read/Write Direction bit mask. */
+#define TWI_SLAVE_DIR_bp 1 /* Read/Write Direction bit position. */
+
+#define TWI_SLAVE_AP_bm 0x01 /* Slave Address or Stop bit mask. */
+#define TWI_SLAVE_AP_bp 0 /* Slave Address or Stop bit position. */
+
+
+/* TWI_SLAVE.ADDRMASK bit masks and bit positions */
+#define TWI_SLAVE_ADDRMASK_gm 0xFE /* Address Mask group mask. */
+#define TWI_SLAVE_ADDRMASK_gp 1 /* Address Mask group position. */
+#define TWI_SLAVE_ADDRMASK0_bm (1<<1) /* Address Mask bit 0 mask. */
+#define TWI_SLAVE_ADDRMASK0_bp 1 /* Address Mask bit 0 position. */
+#define TWI_SLAVE_ADDRMASK1_bm (1<<2) /* Address Mask bit 1 mask. */
+#define TWI_SLAVE_ADDRMASK1_bp 2 /* Address Mask bit 1 position. */
+#define TWI_SLAVE_ADDRMASK2_bm (1<<3) /* Address Mask bit 2 mask. */
+#define TWI_SLAVE_ADDRMASK2_bp 3 /* Address Mask bit 2 position. */
+#define TWI_SLAVE_ADDRMASK3_bm (1<<4) /* Address Mask bit 3 mask. */
+#define TWI_SLAVE_ADDRMASK3_bp 4 /* Address Mask bit 3 position. */
+#define TWI_SLAVE_ADDRMASK4_bm (1<<5) /* Address Mask bit 4 mask. */
+#define TWI_SLAVE_ADDRMASK4_bp 5 /* Address Mask bit 4 position. */
+#define TWI_SLAVE_ADDRMASK5_bm (1<<6) /* Address Mask bit 5 mask. */
+#define TWI_SLAVE_ADDRMASK5_bp 6 /* Address Mask bit 5 position. */
+#define TWI_SLAVE_ADDRMASK6_bm (1<<7) /* Address Mask bit 6 mask. */
+#define TWI_SLAVE_ADDRMASK6_bp 7 /* Address Mask bit 6 position. */
+
+#define TWI_SLAVE_ADDREN_bm 0x01 /* Address Enable bit mask. */
+#define TWI_SLAVE_ADDREN_bp 0 /* Address Enable bit position. */
+
+
+/* TWI.CTRL bit masks and bit positions */
+#define TWI_SDAHOLD_bm 0x02 /* SDA Hold Time Enable bit mask. */
+#define TWI_SDAHOLD_bp 1 /* SDA Hold Time Enable bit position. */
+
+#define TWI_EDIEN_bm 0x01 /* External Driver Interface Enable bit mask. */
+#define TWI_EDIEN_bp 0 /* External Driver Interface Enable bit position. */
+
+
+/* PORT - Port Configuration */
+/* PORTCFG.VPCTRLA bit masks and bit positions */
+#define PORTCFG_VP1MAP_gm 0xF0 /* Virtual Port 1 Mapping group mask. */
+#define PORTCFG_VP1MAP_gp 4 /* Virtual Port 1 Mapping group position. */
+#define PORTCFG_VP1MAP0_bm (1<<4) /* Virtual Port 1 Mapping bit 0 mask. */
+#define PORTCFG_VP1MAP0_bp 4 /* Virtual Port 1 Mapping bit 0 position. */
+#define PORTCFG_VP1MAP1_bm (1<<5) /* Virtual Port 1 Mapping bit 1 mask. */
+#define PORTCFG_VP1MAP1_bp 5 /* Virtual Port 1 Mapping bit 1 position. */
+#define PORTCFG_VP1MAP2_bm (1<<6) /* Virtual Port 1 Mapping bit 2 mask. */
+#define PORTCFG_VP1MAP2_bp 6 /* Virtual Port 1 Mapping bit 2 position. */
+#define PORTCFG_VP1MAP3_bm (1<<7) /* Virtual Port 1 Mapping bit 3 mask. */
+#define PORTCFG_VP1MAP3_bp 7 /* Virtual Port 1 Mapping bit 3 position. */
+
+#define PORTCFG_VP0MAP_gm 0x0F /* Virtual Port 0 Mapping group mask. */
+#define PORTCFG_VP0MAP_gp 0 /* Virtual Port 0 Mapping group position. */
+#define PORTCFG_VP0MAP0_bm (1<<0) /* Virtual Port 0 Mapping bit 0 mask. */
+#define PORTCFG_VP0MAP0_bp 0 /* Virtual Port 0 Mapping bit 0 position. */
+#define PORTCFG_VP0MAP1_bm (1<<1) /* Virtual Port 0 Mapping bit 1 mask. */
+#define PORTCFG_VP0MAP1_bp 1 /* Virtual Port 0 Mapping bit 1 position. */
+#define PORTCFG_VP0MAP2_bm (1<<2) /* Virtual Port 0 Mapping bit 2 mask. */
+#define PORTCFG_VP0MAP2_bp 2 /* Virtual Port 0 Mapping bit 2 position. */
+#define PORTCFG_VP0MAP3_bm (1<<3) /* Virtual Port 0 Mapping bit 3 mask. */
+#define PORTCFG_VP0MAP3_bp 3 /* Virtual Port 0 Mapping bit 3 position. */
+
+
+/* PORTCFG.VPCTRLB bit masks and bit positions */
+#define PORTCFG_VP3MAP_gm 0xF0 /* Virtual Port 3 Mapping group mask. */
+#define PORTCFG_VP3MAP_gp 4 /* Virtual Port 3 Mapping group position. */
+#define PORTCFG_VP3MAP0_bm (1<<4) /* Virtual Port 3 Mapping bit 0 mask. */
+#define PORTCFG_VP3MAP0_bp 4 /* Virtual Port 3 Mapping bit 0 position. */
+#define PORTCFG_VP3MAP1_bm (1<<5) /* Virtual Port 3 Mapping bit 1 mask. */
+#define PORTCFG_VP3MAP1_bp 5 /* Virtual Port 3 Mapping bit 1 position. */
+#define PORTCFG_VP3MAP2_bm (1<<6) /* Virtual Port 3 Mapping bit 2 mask. */
+#define PORTCFG_VP3MAP2_bp 6 /* Virtual Port 3 Mapping bit 2 position. */
+#define PORTCFG_VP3MAP3_bm (1<<7) /* Virtual Port 3 Mapping bit 3 mask. */
+#define PORTCFG_VP3MAP3_bp 7 /* Virtual Port 3 Mapping bit 3 position. */
+
+#define PORTCFG_VP2MAP_gm 0x0F /* Virtual Port 2 Mapping group mask. */
+#define PORTCFG_VP2MAP_gp 0 /* Virtual Port 2 Mapping group position. */
+#define PORTCFG_VP2MAP0_bm (1<<0) /* Virtual Port 2 Mapping bit 0 mask. */
+#define PORTCFG_VP2MAP0_bp 0 /* Virtual Port 2 Mapping bit 0 position. */
+#define PORTCFG_VP2MAP1_bm (1<<1) /* Virtual Port 2 Mapping bit 1 mask. */
+#define PORTCFG_VP2MAP1_bp 1 /* Virtual Port 2 Mapping bit 1 position. */
+#define PORTCFG_VP2MAP2_bm (1<<2) /* Virtual Port 2 Mapping bit 2 mask. */
+#define PORTCFG_VP2MAP2_bp 2 /* Virtual Port 2 Mapping bit 2 position. */
+#define PORTCFG_VP2MAP3_bm (1<<3) /* Virtual Port 2 Mapping bit 3 mask. */
+#define PORTCFG_VP2MAP3_bp 3 /* Virtual Port 2 Mapping bit 3 position. */
+
+
+/* PORTCFG.CLKEVOUT bit masks and bit positions */
+#define PORTCFG_CLKOUT_gm 0x03 /* Clock Output Port group mask. */
+#define PORTCFG_CLKOUT_gp 0 /* Clock Output Port group position. */
+#define PORTCFG_CLKOUT0_bm (1<<0) /* Clock Output Port bit 0 mask. */
+#define PORTCFG_CLKOUT0_bp 0 /* Clock Output Port bit 0 position. */
+#define PORTCFG_CLKOUT1_bm (1<<1) /* Clock Output Port bit 1 mask. */
+#define PORTCFG_CLKOUT1_bp 1 /* Clock Output Port bit 1 position. */
+
+#define PORTCFG_EVOUT_gm 0x30 /* Event Output Port group mask. */
+#define PORTCFG_EVOUT_gp 4 /* Event Output Port group position. */
+#define PORTCFG_EVOUT0_bm (1<<4) /* Event Output Port bit 0 mask. */
+#define PORTCFG_EVOUT0_bp 4 /* Event Output Port bit 0 position. */
+#define PORTCFG_EVOUT1_bm (1<<5) /* Event Output Port bit 1 mask. */
+#define PORTCFG_EVOUT1_bp 5 /* Event Output Port bit 1 position. */
+
+
+/* VPORT.INTFLAGS bit masks and bit positions */
+#define VPORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define VPORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define VPORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define VPORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.INTCTRL bit masks and bit positions */
+#define PORT_INT1LVL_gm 0x0C /* Port Interrupt 1 Level group mask. */
+#define PORT_INT1LVL_gp 2 /* Port Interrupt 1 Level group position. */
+#define PORT_INT1LVL0_bm (1<<2) /* Port Interrupt 1 Level bit 0 mask. */
+#define PORT_INT1LVL0_bp 2 /* Port Interrupt 1 Level bit 0 position. */
+#define PORT_INT1LVL1_bm (1<<3) /* Port Interrupt 1 Level bit 1 mask. */
+#define PORT_INT1LVL1_bp 3 /* Port Interrupt 1 Level bit 1 position. */
+
+#define PORT_INT0LVL_gm 0x03 /* Port Interrupt 0 Level group mask. */
+#define PORT_INT0LVL_gp 0 /* Port Interrupt 0 Level group position. */
+#define PORT_INT0LVL0_bm (1<<0) /* Port Interrupt 0 Level bit 0 mask. */
+#define PORT_INT0LVL0_bp 0 /* Port Interrupt 0 Level bit 0 position. */
+#define PORT_INT0LVL1_bm (1<<1) /* Port Interrupt 0 Level bit 1 mask. */
+#define PORT_INT0LVL1_bp 1 /* Port Interrupt 0 Level bit 1 position. */
+
+
+/* PORT.INTFLAGS bit masks and bit positions */
+#define PORT_INT1IF_bm 0x02 /* Port Interrupt 1 Flag bit mask. */
+#define PORT_INT1IF_bp 1 /* Port Interrupt 1 Flag bit position. */
+
+#define PORT_INT0IF_bm 0x01 /* Port Interrupt 0 Flag bit mask. */
+#define PORT_INT0IF_bp 0 /* Port Interrupt 0 Flag bit position. */
+
+
+/* PORT.PIN0CTRL bit masks and bit positions */
+#define PORT_SRLEN_bm 0x80 /* Slew Rate Enable bit mask. */
+#define PORT_SRLEN_bp 7 /* Slew Rate Enable bit position. */
+
+#define PORT_INVEN_bm 0x40 /* Inverted I/O Enable bit mask. */
+#define PORT_INVEN_bp 6 /* Inverted I/O Enable bit position. */
+
+#define PORT_OPC_gm 0x38 /* Output/Pull Configuration group mask. */
+#define PORT_OPC_gp 3 /* Output/Pull Configuration group position. */
+#define PORT_OPC0_bm (1<<3) /* Output/Pull Configuration bit 0 mask. */
+#define PORT_OPC0_bp 3 /* Output/Pull Configuration bit 0 position. */
+#define PORT_OPC1_bm (1<<4) /* Output/Pull Configuration bit 1 mask. */
+#define PORT_OPC1_bp 4 /* Output/Pull Configuration bit 1 position. */
+#define PORT_OPC2_bm (1<<5) /* Output/Pull Configuration bit 2 mask. */
+#define PORT_OPC2_bp 5 /* Output/Pull Configuration bit 2 position. */
+
+#define PORT_ISC_gm 0x07 /* Input/Sense Configuration group mask. */
+#define PORT_ISC_gp 0 /* Input/Sense Configuration group position. */
+#define PORT_ISC0_bm (1<<0) /* Input/Sense Configuration bit 0 mask. */
+#define PORT_ISC0_bp 0 /* Input/Sense Configuration bit 0 position. */
+#define PORT_ISC1_bm (1<<1) /* Input/Sense Configuration bit 1 mask. */
+#define PORT_ISC1_bp 1 /* Input/Sense Configuration bit 1 position. */
+#define PORT_ISC2_bm (1<<2) /* Input/Sense Configuration bit 2 mask. */
+#define PORT_ISC2_bp 2 /* Input/Sense Configuration bit 2 position. */
+
+
+/* PORT.PIN1CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN2CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN3CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN4CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN5CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN6CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* PORT.PIN7CTRL bit masks and bit positions */
+/* PORT_SRLEN_bm Predefined. */
+/* PORT_SRLEN_bp Predefined. */
+
+/* PORT_INVEN_bm Predefined. */
+/* PORT_INVEN_bp Predefined. */
+
+/* PORT_OPC_gm Predefined. */
+/* PORT_OPC_gp Predefined. */
+/* PORT_OPC0_bm Predefined. */
+/* PORT_OPC0_bp Predefined. */
+/* PORT_OPC1_bm Predefined. */
+/* PORT_OPC1_bp Predefined. */
+/* PORT_OPC2_bm Predefined. */
+/* PORT_OPC2_bp Predefined. */
+
+/* PORT_ISC_gm Predefined. */
+/* PORT_ISC_gp Predefined. */
+/* PORT_ISC0_bm Predefined. */
+/* PORT_ISC0_bp Predefined. */
+/* PORT_ISC1_bm Predefined. */
+/* PORT_ISC1_bp Predefined. */
+/* PORT_ISC2_bm Predefined. */
+/* PORT_ISC2_bp Predefined. */
+
+
+/* TC - 16-bit Timer/Counter With PWM */
+/* TC0.CTRLA bit masks and bit positions */
+#define TC0_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC0_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC0_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC0_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC0_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC0_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC0_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC0_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC0_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC0_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC0.CTRLB bit masks and bit positions */
+#define TC0_CCDEN_bm 0x80 /* Compare or Capture D Enable bit mask. */
+#define TC0_CCDEN_bp 7 /* Compare or Capture D Enable bit position. */
+
+#define TC0_CCCEN_bm 0x40 /* Compare or Capture C Enable bit mask. */
+#define TC0_CCCEN_bp 6 /* Compare or Capture C Enable bit position. */
+
+#define TC0_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC0_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC0_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC0_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC0_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC0_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC0_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC0_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC0_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC0_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC0_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC0_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC0.CTRLC bit masks and bit positions */
+#define TC0_CMPD_bm 0x08 /* Compare D Output Value bit mask. */
+#define TC0_CMPD_bp 3 /* Compare D Output Value bit position. */
+
+#define TC0_CMPC_bm 0x04 /* Compare C Output Value bit mask. */
+#define TC0_CMPC_bp 2 /* Compare C Output Value bit position. */
+
+#define TC0_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC0_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC0_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC0_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC0.CTRLD bit masks and bit positions */
+#define TC0_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC0_EVACT_gp 5 /* Event Action group position. */
+#define TC0_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC0_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC0_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC0_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC0_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC0_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC0_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC0_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC0_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC0_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC0_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC0_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC0_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC0_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC0_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC0_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC0_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC0_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC0.CTRLE bit masks and bit positions */
+#define TC0_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC0_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC0.INTCTRLA bit masks and bit positions */
+#define TC0_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC0_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC0_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC0_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC0_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC0_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC0_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC0_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC0_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC0_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC0_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC0_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC0.INTCTRLB bit masks and bit positions */
+#define TC0_CCDINTLVL_gm 0xC0 /* Compare or Capture D Interrupt Level group mask. */
+#define TC0_CCDINTLVL_gp 6 /* Compare or Capture D Interrupt Level group position. */
+#define TC0_CCDINTLVL0_bm (1<<6) /* Compare or Capture D Interrupt Level bit 0 mask. */
+#define TC0_CCDINTLVL0_bp 6 /* Compare or Capture D Interrupt Level bit 0 position. */
+#define TC0_CCDINTLVL1_bm (1<<7) /* Compare or Capture D Interrupt Level bit 1 mask. */
+#define TC0_CCDINTLVL1_bp 7 /* Compare or Capture D Interrupt Level bit 1 position. */
+
+#define TC0_CCCINTLVL_gm 0x30 /* Compare or Capture C Interrupt Level group mask. */
+#define TC0_CCCINTLVL_gp 4 /* Compare or Capture C Interrupt Level group position. */
+#define TC0_CCCINTLVL0_bm (1<<4) /* Compare or Capture C Interrupt Level bit 0 mask. */
+#define TC0_CCCINTLVL0_bp 4 /* Compare or Capture C Interrupt Level bit 0 position. */
+#define TC0_CCCINTLVL1_bm (1<<5) /* Compare or Capture C Interrupt Level bit 1 mask. */
+#define TC0_CCCINTLVL1_bp 5 /* Compare or Capture C Interrupt Level bit 1 position. */
+
+#define TC0_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC0_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC0_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC0_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC0_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC0_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC0_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC0_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC0_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC0_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC0_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC0_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC0.CTRLFCLR bit masks and bit positions */
+#define TC0_CMD_gm 0x0C /* Command group mask. */
+#define TC0_CMD_gp 2 /* Command group position. */
+#define TC0_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC0_CMD0_bp 2 /* Command bit 0 position. */
+#define TC0_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC0_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC0_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC0_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC0_DIR_bm 0x01 /* Direction bit mask. */
+#define TC0_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC0.CTRLFSET bit masks and bit positions */
+/* TC0_CMD_gm Predefined. */
+/* TC0_CMD_gp Predefined. */
+/* TC0_CMD0_bm Predefined. */
+/* TC0_CMD0_bp Predefined. */
+/* TC0_CMD1_bm Predefined. */
+/* TC0_CMD1_bp Predefined. */
+
+/* TC0_LUPD_bm Predefined. */
+/* TC0_LUPD_bp Predefined. */
+
+/* TC0_DIR_bm Predefined. */
+/* TC0_DIR_bp Predefined. */
+
+
+/* TC0.CTRLGCLR bit masks and bit positions */
+#define TC0_CCDBV_bm 0x10 /* Compare or Capture D Buffer Valid bit mask. */
+#define TC0_CCDBV_bp 4 /* Compare or Capture D Buffer Valid bit position. */
+
+#define TC0_CCCBV_bm 0x08 /* Compare or Capture C Buffer Valid bit mask. */
+#define TC0_CCCBV_bp 3 /* Compare or Capture C Buffer Valid bit position. */
+
+#define TC0_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC0_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC0_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC0_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC0_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC0_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC0.CTRLGSET bit masks and bit positions */
+/* TC0_CCDBV_bm Predefined. */
+/* TC0_CCDBV_bp Predefined. */
+
+/* TC0_CCCBV_bm Predefined. */
+/* TC0_CCCBV_bp Predefined. */
+
+/* TC0_CCBBV_bm Predefined. */
+/* TC0_CCBBV_bp Predefined. */
+
+/* TC0_CCABV_bm Predefined. */
+/* TC0_CCABV_bp Predefined. */
+
+/* TC0_PERBV_bm Predefined. */
+/* TC0_PERBV_bp Predefined. */
+
+
+/* TC0.INTFLAGS bit masks and bit positions */
+#define TC0_CCDIF_bm 0x80 /* Compare or Capture D Interrupt Flag bit mask. */
+#define TC0_CCDIF_bp 7 /* Compare or Capture D Interrupt Flag bit position. */
+
+#define TC0_CCCIF_bm 0x40 /* Compare or Capture C Interrupt Flag bit mask. */
+#define TC0_CCCIF_bp 6 /* Compare or Capture C Interrupt Flag bit position. */
+
+#define TC0_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC0_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC0_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC0_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC0_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC0_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC0_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC0_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* TC1.CTRLA bit masks and bit positions */
+#define TC1_CLKSEL_gm 0x0F /* Clock Selection group mask. */
+#define TC1_CLKSEL_gp 0 /* Clock Selection group position. */
+#define TC1_CLKSEL0_bm (1<<0) /* Clock Selection bit 0 mask. */
+#define TC1_CLKSEL0_bp 0 /* Clock Selection bit 0 position. */
+#define TC1_CLKSEL1_bm (1<<1) /* Clock Selection bit 1 mask. */
+#define TC1_CLKSEL1_bp 1 /* Clock Selection bit 1 position. */
+#define TC1_CLKSEL2_bm (1<<2) /* Clock Selection bit 2 mask. */
+#define TC1_CLKSEL2_bp 2 /* Clock Selection bit 2 position. */
+#define TC1_CLKSEL3_bm (1<<3) /* Clock Selection bit 3 mask. */
+#define TC1_CLKSEL3_bp 3 /* Clock Selection bit 3 position. */
+
+
+/* TC1.CTRLB bit masks and bit positions */
+#define TC1_CCBEN_bm 0x20 /* Compare or Capture B Enable bit mask. */
+#define TC1_CCBEN_bp 5 /* Compare or Capture B Enable bit position. */
+
+#define TC1_CCAEN_bm 0x10 /* Compare or Capture A Enable bit mask. */
+#define TC1_CCAEN_bp 4 /* Compare or Capture A Enable bit position. */
+
+#define TC1_WGMODE_gm 0x07 /* Waveform generation mode group mask. */
+#define TC1_WGMODE_gp 0 /* Waveform generation mode group position. */
+#define TC1_WGMODE0_bm (1<<0) /* Waveform generation mode bit 0 mask. */
+#define TC1_WGMODE0_bp 0 /* Waveform generation mode bit 0 position. */
+#define TC1_WGMODE1_bm (1<<1) /* Waveform generation mode bit 1 mask. */
+#define TC1_WGMODE1_bp 1 /* Waveform generation mode bit 1 position. */
+#define TC1_WGMODE2_bm (1<<2) /* Waveform generation mode bit 2 mask. */
+#define TC1_WGMODE2_bp 2 /* Waveform generation mode bit 2 position. */
+
+
+/* TC1.CTRLC bit masks and bit positions */
+#define TC1_CMPB_bm 0x02 /* Compare B Output Value bit mask. */
+#define TC1_CMPB_bp 1 /* Compare B Output Value bit position. */
+
+#define TC1_CMPA_bm 0x01 /* Compare A Output Value bit mask. */
+#define TC1_CMPA_bp 0 /* Compare A Output Value bit position. */
+
+
+/* TC1.CTRLD bit masks and bit positions */
+#define TC1_EVACT_gm 0xE0 /* Event Action group mask. */
+#define TC1_EVACT_gp 5 /* Event Action group position. */
+#define TC1_EVACT0_bm (1<<5) /* Event Action bit 0 mask. */
+#define TC1_EVACT0_bp 5 /* Event Action bit 0 position. */
+#define TC1_EVACT1_bm (1<<6) /* Event Action bit 1 mask. */
+#define TC1_EVACT1_bp 6 /* Event Action bit 1 position. */
+#define TC1_EVACT2_bm (1<<7) /* Event Action bit 2 mask. */
+#define TC1_EVACT2_bp 7 /* Event Action bit 2 position. */
+
+#define TC1_EVDLY_bm 0x10 /* Event Delay bit mask. */
+#define TC1_EVDLY_bp 4 /* Event Delay bit position. */
+
+#define TC1_EVSEL_gm 0x0F /* Event Source Select group mask. */
+#define TC1_EVSEL_gp 0 /* Event Source Select group position. */
+#define TC1_EVSEL0_bm (1<<0) /* Event Source Select bit 0 mask. */
+#define TC1_EVSEL0_bp 0 /* Event Source Select bit 0 position. */
+#define TC1_EVSEL1_bm (1<<1) /* Event Source Select bit 1 mask. */
+#define TC1_EVSEL1_bp 1 /* Event Source Select bit 1 position. */
+#define TC1_EVSEL2_bm (1<<2) /* Event Source Select bit 2 mask. */
+#define TC1_EVSEL2_bp 2 /* Event Source Select bit 2 position. */
+#define TC1_EVSEL3_bm (1<<3) /* Event Source Select bit 3 mask. */
+#define TC1_EVSEL3_bp 3 /* Event Source Select bit 3 position. */
+
+
+/* TC1.CTRLE bit masks and bit positions */
+#define TC1_BYTEM_bm 0x01 /* Byte Mode bit mask. */
+#define TC1_BYTEM_bp 0 /* Byte Mode bit position. */
+
+
+/* TC1.INTCTRLA bit masks and bit positions */
+#define TC1_ERRINTLVL_gm 0x0C /* Error Interrupt Level group mask. */
+#define TC1_ERRINTLVL_gp 2 /* Error Interrupt Level group position. */
+#define TC1_ERRINTLVL0_bm (1<<2) /* Error Interrupt Level bit 0 mask. */
+#define TC1_ERRINTLVL0_bp 2 /* Error Interrupt Level bit 0 position. */
+#define TC1_ERRINTLVL1_bm (1<<3) /* Error Interrupt Level bit 1 mask. */
+#define TC1_ERRINTLVL1_bp 3 /* Error Interrupt Level bit 1 position. */
+
+#define TC1_OVFINTLVL_gm 0x03 /* Overflow interrupt level group mask. */
+#define TC1_OVFINTLVL_gp 0 /* Overflow interrupt level group position. */
+#define TC1_OVFINTLVL0_bm (1<<0) /* Overflow interrupt level bit 0 mask. */
+#define TC1_OVFINTLVL0_bp 0 /* Overflow interrupt level bit 0 position. */
+#define TC1_OVFINTLVL1_bm (1<<1) /* Overflow interrupt level bit 1 mask. */
+#define TC1_OVFINTLVL1_bp 1 /* Overflow interrupt level bit 1 position. */
+
+
+/* TC1.INTCTRLB bit masks and bit positions */
+#define TC1_CCBINTLVL_gm 0x0C /* Compare or Capture B Interrupt Level group mask. */
+#define TC1_CCBINTLVL_gp 2 /* Compare or Capture B Interrupt Level group position. */
+#define TC1_CCBINTLVL0_bm (1<<2) /* Compare or Capture B Interrupt Level bit 0 mask. */
+#define TC1_CCBINTLVL0_bp 2 /* Compare or Capture B Interrupt Level bit 0 position. */
+#define TC1_CCBINTLVL1_bm (1<<3) /* Compare or Capture B Interrupt Level bit 1 mask. */
+#define TC1_CCBINTLVL1_bp 3 /* Compare or Capture B Interrupt Level bit 1 position. */
+
+#define TC1_CCAINTLVL_gm 0x03 /* Compare or Capture A Interrupt Level group mask. */
+#define TC1_CCAINTLVL_gp 0 /* Compare or Capture A Interrupt Level group position. */
+#define TC1_CCAINTLVL0_bm (1<<0) /* Compare or Capture A Interrupt Level bit 0 mask. */
+#define TC1_CCAINTLVL0_bp 0 /* Compare or Capture A Interrupt Level bit 0 position. */
+#define TC1_CCAINTLVL1_bm (1<<1) /* Compare or Capture A Interrupt Level bit 1 mask. */
+#define TC1_CCAINTLVL1_bp 1 /* Compare or Capture A Interrupt Level bit 1 position. */
+
+
+/* TC1.CTRLFCLR bit masks and bit positions */
+#define TC1_CMD_gm 0x0C /* Command group mask. */
+#define TC1_CMD_gp 2 /* Command group position. */
+#define TC1_CMD0_bm (1<<2) /* Command bit 0 mask. */
+#define TC1_CMD0_bp 2 /* Command bit 0 position. */
+#define TC1_CMD1_bm (1<<3) /* Command bit 1 mask. */
+#define TC1_CMD1_bp 3 /* Command bit 1 position. */
+
+#define TC1_LUPD_bm 0x02 /* Lock Update bit mask. */
+#define TC1_LUPD_bp 1 /* Lock Update bit position. */
+
+#define TC1_DIR_bm 0x01 /* Direction bit mask. */
+#define TC1_DIR_bp 0 /* Direction bit position. */
+
+
+/* TC1.CTRLFSET bit masks and bit positions */
+/* TC1_CMD_gm Predefined. */
+/* TC1_CMD_gp Predefined. */
+/* TC1_CMD0_bm Predefined. */
+/* TC1_CMD0_bp Predefined. */
+/* TC1_CMD1_bm Predefined. */
+/* TC1_CMD1_bp Predefined. */
+
+/* TC1_LUPD_bm Predefined. */
+/* TC1_LUPD_bp Predefined. */
+
+/* TC1_DIR_bm Predefined. */
+/* TC1_DIR_bp Predefined. */
+
+
+/* TC1.CTRLGCLR bit masks and bit positions */
+#define TC1_CCBBV_bm 0x04 /* Compare or Capture B Buffer Valid bit mask. */
+#define TC1_CCBBV_bp 2 /* Compare or Capture B Buffer Valid bit position. */
+
+#define TC1_CCABV_bm 0x02 /* Compare or Capture A Buffer Valid bit mask. */
+#define TC1_CCABV_bp 1 /* Compare or Capture A Buffer Valid bit position. */
+
+#define TC1_PERBV_bm 0x01 /* Period Buffer Valid bit mask. */
+#define TC1_PERBV_bp 0 /* Period Buffer Valid bit position. */
+
+
+/* TC1.CTRLGSET bit masks and bit positions */
+/* TC1_CCBBV_bm Predefined. */
+/* TC1_CCBBV_bp Predefined. */
+
+/* TC1_CCABV_bm Predefined. */
+/* TC1_CCABV_bp Predefined. */
+
+/* TC1_PERBV_bm Predefined. */
+/* TC1_PERBV_bp Predefined. */
+
+
+/* TC1.INTFLAGS bit masks and bit positions */
+#define TC1_CCBIF_bm 0x20 /* Compare or Capture B Interrupt Flag bit mask. */
+#define TC1_CCBIF_bp 5 /* Compare or Capture B Interrupt Flag bit position. */
+
+#define TC1_CCAIF_bm 0x10 /* Compare or Capture A Interrupt Flag bit mask. */
+#define TC1_CCAIF_bp 4 /* Compare or Capture A Interrupt Flag bit position. */
+
+#define TC1_ERRIF_bm 0x02 /* Error Interrupt Flag bit mask. */
+#define TC1_ERRIF_bp 1 /* Error Interrupt Flag bit position. */
+
+#define TC1_OVFIF_bm 0x01 /* Overflow Interrupt Flag bit mask. */
+#define TC1_OVFIF_bp 0 /* Overflow Interrupt Flag bit position. */
+
+
+/* AWEX.CTRL bit masks and bit positions */
+#define AWEX_PGM_bm 0x20 /* Pattern Generation Mode bit mask. */
+#define AWEX_PGM_bp 5 /* Pattern Generation Mode bit position. */
+
+#define AWEX_CWCM_bm 0x10 /* Common Waveform Channel Mode bit mask. */
+#define AWEX_CWCM_bp 4 /* Common Waveform Channel Mode bit position. */
+
+#define AWEX_DTICCDEN_bm 0x08 /* Dead Time Insertion Compare Channel D Enable bit mask. */
+#define AWEX_DTICCDEN_bp 3 /* Dead Time Insertion Compare Channel D Enable bit position. */
+
+#define AWEX_DTICCCEN_bm 0x04 /* Dead Time Insertion Compare Channel C Enable bit mask. */
+#define AWEX_DTICCCEN_bp 2 /* Dead Time Insertion Compare Channel C Enable bit position. */
+
+#define AWEX_DTICCBEN_bm 0x02 /* Dead Time Insertion Compare Channel B Enable bit mask. */
+#define AWEX_DTICCBEN_bp 1 /* Dead Time Insertion Compare Channel B Enable bit position. */
+
+#define AWEX_DTICCAEN_bm 0x01 /* Dead Time Insertion Compare Channel A Enable bit mask. */
+#define AWEX_DTICCAEN_bp 0 /* Dead Time Insertion Compare Channel A Enable bit position. */
+
+
+/* AWEX.FDCTRL bit masks and bit positions */
+#define AWEX_FDDBD_bm 0x10 /* Fault Detect on Disable Break Disable bit mask. */
+#define AWEX_FDDBD_bp 4 /* Fault Detect on Disable Break Disable bit position. */
+
+#define AWEX_FDMODE_bm 0x04 /* Fault Detect Mode bit mask. */
+#define AWEX_FDMODE_bp 2 /* Fault Detect Mode bit position. */
+
+#define AWEX_FDACT_gm 0x03 /* Fault Detect Action group mask. */
+#define AWEX_FDACT_gp 0 /* Fault Detect Action group position. */
+#define AWEX_FDACT0_bm (1<<0) /* Fault Detect Action bit 0 mask. */
+#define AWEX_FDACT0_bp 0 /* Fault Detect Action bit 0 position. */
+#define AWEX_FDACT1_bm (1<<1) /* Fault Detect Action bit 1 mask. */
+#define AWEX_FDACT1_bp 1 /* Fault Detect Action bit 1 position. */
+
+
+/* AWEX.STATUS bit masks and bit positions */
+#define AWEX_FDF_bm 0x04 /* Fault Detect Flag bit mask. */
+#define AWEX_FDF_bp 2 /* Fault Detect Flag bit position. */
+
+#define AWEX_DTHSBUFV_bm 0x02 /* Dead Time High Side Buffer Valid bit mask. */
+#define AWEX_DTHSBUFV_bp 1 /* Dead Time High Side Buffer Valid bit position. */
+
+#define AWEX_DTLSBUFV_bm 0x01 /* Dead Time Low Side Buffer Valid bit mask. */
+#define AWEX_DTLSBUFV_bp 0 /* Dead Time Low Side Buffer Valid bit position. */
+
+
+/* HIRES.CTRLA bit masks and bit positions */
+#define HIRES_HREN_gm 0x03 /* High Resolution Enable group mask. */
+#define HIRES_HREN_gp 0 /* High Resolution Enable group position. */
+#define HIRES_HREN0_bm (1<<0) /* High Resolution Enable bit 0 mask. */
+#define HIRES_HREN0_bp 0 /* High Resolution Enable bit 0 position. */
+#define HIRES_HREN1_bm (1<<1) /* High Resolution Enable bit 1 mask. */
+#define HIRES_HREN1_bp 1 /* High Resolution Enable bit 1 position. */
+
+
+/* USART - Universal Asynchronous Receiver-Transmitter */
+/* USART.STATUS bit masks and bit positions */
+#define USART_RXCIF_bm 0x80 /* Receive Interrupt Flag bit mask. */
+#define USART_RXCIF_bp 7 /* Receive Interrupt Flag bit position. */
+
+#define USART_TXCIF_bm 0x40 /* Transmit Interrupt Flag bit mask. */
+#define USART_TXCIF_bp 6 /* Transmit Interrupt Flag bit position. */
+
+#define USART_DREIF_bm 0x20 /* Data Register Empty Flag bit mask. */
+#define USART_DREIF_bp 5 /* Data Register Empty Flag bit position. */
+
+#define USART_FERR_bm 0x10 /* Frame Error bit mask. */
+#define USART_FERR_bp 4 /* Frame Error bit position. */
+
+#define USART_BUFOVF_bm 0x08 /* Buffer Overflow bit mask. */
+#define USART_BUFOVF_bp 3 /* Buffer Overflow bit position. */
+
+#define USART_PERR_bm 0x04 /* Parity Error bit mask. */
+#define USART_PERR_bp 2 /* Parity Error bit position. */
+
+#define USART_RXB8_bm 0x01 /* Receive Bit 8 bit mask. */
+#define USART_RXB8_bp 0 /* Receive Bit 8 bit position. */
+
+
+/* USART.CTRLA bit masks and bit positions */
+#define USART_RXCINTLVL_gm 0x30 /* Receive Interrupt Level group mask. */
+#define USART_RXCINTLVL_gp 4 /* Receive Interrupt Level group position. */
+#define USART_RXCINTLVL0_bm (1<<4) /* Receive Interrupt Level bit 0 mask. */
+#define USART_RXCINTLVL0_bp 4 /* Receive Interrupt Level bit 0 position. */
+#define USART_RXCINTLVL1_bm (1<<5) /* Receive Interrupt Level bit 1 mask. */
+#define USART_RXCINTLVL1_bp 5 /* Receive Interrupt Level bit 1 position. */
+
+#define USART_TXCINTLVL_gm 0x0C /* Transmit Interrupt Level group mask. */
+#define USART_TXCINTLVL_gp 2 /* Transmit Interrupt Level group position. */
+#define USART_TXCINTLVL0_bm (1<<2) /* Transmit Interrupt Level bit 0 mask. */
+#define USART_TXCINTLVL0_bp 2 /* Transmit Interrupt Level bit 0 position. */
+#define USART_TXCINTLVL1_bm (1<<3) /* Transmit Interrupt Level bit 1 mask. */
+#define USART_TXCINTLVL1_bp 3 /* Transmit Interrupt Level bit 1 position. */
+
+#define USART_DREINTLVL_gm 0x03 /* Data Register Empty Interrupt Level group mask. */
+#define USART_DREINTLVL_gp 0 /* Data Register Empty Interrupt Level group position. */
+#define USART_DREINTLVL0_bm (1<<0) /* Data Register Empty Interrupt Level bit 0 mask. */
+#define USART_DREINTLVL0_bp 0 /* Data Register Empty Interrupt Level bit 0 position. */
+#define USART_DREINTLVL1_bm (1<<1) /* Data Register Empty Interrupt Level bit 1 mask. */
+#define USART_DREINTLVL1_bp 1 /* Data Register Empty Interrupt Level bit 1 position. */
+
+
+/* USART.CTRLB bit masks and bit positions */
+#define USART_RXEN_bm 0x10 /* Receiver Enable bit mask. */
+#define USART_RXEN_bp 4 /* Receiver Enable bit position. */
+
+#define USART_TXEN_bm 0x08 /* Transmitter Enable bit mask. */
+#define USART_TXEN_bp 3 /* Transmitter Enable bit position. */
+
+#define USART_CLK2X_bm 0x04 /* Double transmission speed bit mask. */
+#define USART_CLK2X_bp 2 /* Double transmission speed bit position. */
+
+#define USART_MPCM_bm 0x02 /* Multi-processor Communication Mode bit mask. */
+#define USART_MPCM_bp 1 /* Multi-processor Communication Mode bit position. */
+
+#define USART_TXB8_bm 0x01 /* Transmit bit 8 bit mask. */
+#define USART_TXB8_bp 0 /* Transmit bit 8 bit position. */
+
+
+/* USART.CTRLC bit masks and bit positions */
+#define USART_CMODE_gm 0xC0 /* Communication Mode group mask. */
+#define USART_CMODE_gp 6 /* Communication Mode group position. */
+#define USART_CMODE0_bm (1<<6) /* Communication Mode bit 0 mask. */
+#define USART_CMODE0_bp 6 /* Communication Mode bit 0 position. */
+#define USART_CMODE1_bm (1<<7) /* Communication Mode bit 1 mask. */
+#define USART_CMODE1_bp 7 /* Communication Mode bit 1 position. */
+
+#define USART_PMODE_gm 0x30 /* Parity Mode group mask. */
+#define USART_PMODE_gp 4 /* Parity Mode group position. */
+#define USART_PMODE0_bm (1<<4) /* Parity Mode bit 0 mask. */
+#define USART_PMODE0_bp 4 /* Parity Mode bit 0 position. */
+#define USART_PMODE1_bm (1<<5) /* Parity Mode bit 1 mask. */
+#define USART_PMODE1_bp 5 /* Parity Mode bit 1 position. */
+
+#define USART_SBMODE_bm 0x08 /* Stop Bit Mode bit mask. */
+#define USART_SBMODE_bp 3 /* Stop Bit Mode bit position. */
+
+#define USART_CHSIZE_gm 0x07 /* Character Size group mask. */
+#define USART_CHSIZE_gp 0 /* Character Size group position. */
+#define USART_CHSIZE0_bm (1<<0) /* Character Size bit 0 mask. */
+#define USART_CHSIZE0_bp 0 /* Character Size bit 0 position. */
+#define USART_CHSIZE1_bm (1<<1) /* Character Size bit 1 mask. */
+#define USART_CHSIZE1_bp 1 /* Character Size bit 1 position. */
+#define USART_CHSIZE2_bm (1<<2) /* Character Size bit 2 mask. */
+#define USART_CHSIZE2_bp 2 /* Character Size bit 2 position. */
+
+
+/* USART.BAUDCTRLA bit masks and bit positions */
+#define USART_BSEL_gm 0xFF /* Baud Rate Selection Bits [7:0] group mask. */
+#define USART_BSEL_gp 0 /* Baud Rate Selection Bits [7:0] group position. */
+#define USART_BSEL0_bm (1<<0) /* Baud Rate Selection Bits [7:0] bit 0 mask. */
+#define USART_BSEL0_bp 0 /* Baud Rate Selection Bits [7:0] bit 0 position. */
+#define USART_BSEL1_bm (1<<1) /* Baud Rate Selection Bits [7:0] bit 1 mask. */
+#define USART_BSEL1_bp 1 /* Baud Rate Selection Bits [7:0] bit 1 position. */
+#define USART_BSEL2_bm (1<<2) /* Baud Rate Selection Bits [7:0] bit 2 mask. */
+#define USART_BSEL2_bp 2 /* Baud Rate Selection Bits [7:0] bit 2 position. */
+#define USART_BSEL3_bm (1<<3) /* Baud Rate Selection Bits [7:0] bit 3 mask. */
+#define USART_BSEL3_bp 3 /* Baud Rate Selection Bits [7:0] bit 3 position. */
+#define USART_BSEL4_bm (1<<4) /* Baud Rate Selection Bits [7:0] bit 4 mask. */
+#define USART_BSEL4_bp 4 /* Baud Rate Selection Bits [7:0] bit 4 position. */
+#define USART_BSEL5_bm (1<<5) /* Baud Rate Selection Bits [7:0] bit 5 mask. */
+#define USART_BSEL5_bp 5 /* Baud Rate Selection Bits [7:0] bit 5 position. */
+#define USART_BSEL6_bm (1<<6) /* Baud Rate Selection Bits [7:0] bit 6 mask. */
+#define USART_BSEL6_bp 6 /* Baud Rate Selection Bits [7:0] bit 6 position. */
+#define USART_BSEL7_bm (1<<7) /* Baud Rate Selection Bits [7:0] bit 7 mask. */
+#define USART_BSEL7_bp 7 /* Baud Rate Selection Bits [7:0] bit 7 position. */
+
+
+/* USART.BAUDCTRLB bit masks and bit positions */
+#define USART_BSCALE_gm 0xF0 /* Baud Rate Scale group mask. */
+#define USART_BSCALE_gp 4 /* Baud Rate Scale group position. */
+#define USART_BSCALE0_bm (1<<4) /* Baud Rate Scale bit 0 mask. */
+#define USART_BSCALE0_bp 4 /* Baud Rate Scale bit 0 position. */
+#define USART_BSCALE1_bm (1<<5) /* Baud Rate Scale bit 1 mask. */
+#define USART_BSCALE1_bp 5 /* Baud Rate Scale bit 1 position. */
+#define USART_BSCALE2_bm (1<<6) /* Baud Rate Scale bit 2 mask. */
+#define USART_BSCALE2_bp 6 /* Baud Rate Scale bit 2 position. */
+#define USART_BSCALE3_bm (1<<7) /* Baud Rate Scale bit 3 mask. */
+#define USART_BSCALE3_bp 7 /* Baud Rate Scale bit 3 position. */
+
+/* USART_BSEL_gm Predefined. */
+/* USART_BSEL_gp Predefined. */
+/* USART_BSEL0_bm Predefined. */
+/* USART_BSEL0_bp Predefined. */
+/* USART_BSEL1_bm Predefined. */
+/* USART_BSEL1_bp Predefined. */
+/* USART_BSEL2_bm Predefined. */
+/* USART_BSEL2_bp Predefined. */
+/* USART_BSEL3_bm Predefined. */
+/* USART_BSEL3_bp Predefined. */
+
+
+/* SPI - Serial Peripheral Interface */
+/* SPI.CTRL bit masks and bit positions */
+#define SPI_CLK2X_bm 0x80 /* Enable Double Speed bit mask. */
+#define SPI_CLK2X_bp 7 /* Enable Double Speed bit position. */
+
+#define SPI_ENABLE_bm 0x40 /* Enable Module bit mask. */
+#define SPI_ENABLE_bp 6 /* Enable Module bit position. */
+
+#define SPI_DORD_bm 0x20 /* Data Order Setting bit mask. */
+#define SPI_DORD_bp 5 /* Data Order Setting bit position. */
+
+#define SPI_MASTER_bm 0x10 /* Master Operation Enable bit mask. */
+#define SPI_MASTER_bp 4 /* Master Operation Enable bit position. */
+
+#define SPI_MODE_gm 0x0C /* SPI Mode group mask. */
+#define SPI_MODE_gp 2 /* SPI Mode group position. */
+#define SPI_MODE0_bm (1<<2) /* SPI Mode bit 0 mask. */
+#define SPI_MODE0_bp 2 /* SPI Mode bit 0 position. */
+#define SPI_MODE1_bm (1<<3) /* SPI Mode bit 1 mask. */
+#define SPI_MODE1_bp 3 /* SPI Mode bit 1 position. */
+
+#define SPI_PRESCALER_gm 0x03 /* Prescaler group mask. */
+#define SPI_PRESCALER_gp 0 /* Prescaler group position. */
+#define SPI_PRESCALER0_bm (1<<0) /* Prescaler bit 0 mask. */
+#define SPI_PRESCALER0_bp 0 /* Prescaler bit 0 position. */
+#define SPI_PRESCALER1_bm (1<<1) /* Prescaler bit 1 mask. */
+#define SPI_PRESCALER1_bp 1 /* Prescaler bit 1 position. */
+
+
+/* SPI.INTCTRL bit masks and bit positions */
+#define SPI_INTLVL_gm 0x03 /* Interrupt level group mask. */
+#define SPI_INTLVL_gp 0 /* Interrupt level group position. */
+#define SPI_INTLVL0_bm (1<<0) /* Interrupt level bit 0 mask. */
+#define SPI_INTLVL0_bp 0 /* Interrupt level bit 0 position. */
+#define SPI_INTLVL1_bm (1<<1) /* Interrupt level bit 1 mask. */
+#define SPI_INTLVL1_bp 1 /* Interrupt level bit 1 position. */
+
+
+/* SPI.STATUS bit masks and bit positions */
+#define SPI_IF_bm 0x80 /* Interrupt Flag bit mask. */
+#define SPI_IF_bp 7 /* Interrupt Flag bit position. */
+
+#define SPI_WRCOL_bm 0x40 /* Write Collision bit mask. */
+#define SPI_WRCOL_bp 6 /* Write Collision bit position. */
+
+
+/* IRCOM - IR Communication Module */
+/* IRCOM.CTRL bit masks and bit positions */
+#define IRCOM_EVSEL_gm 0x0F /* Event Channel Select group mask. */
+#define IRCOM_EVSEL_gp 0 /* Event Channel Select group position. */
+#define IRCOM_EVSEL0_bm (1<<0) /* Event Channel Select bit 0 mask. */
+#define IRCOM_EVSEL0_bp 0 /* Event Channel Select bit 0 position. */
+#define IRCOM_EVSEL1_bm (1<<1) /* Event Channel Select bit 1 mask. */
+#define IRCOM_EVSEL1_bp 1 /* Event Channel Select bit 1 position. */
+#define IRCOM_EVSEL2_bm (1<<2) /* Event Channel Select bit 2 mask. */
+#define IRCOM_EVSEL2_bp 2 /* Event Channel Select bit 2 position. */
+#define IRCOM_EVSEL3_bm (1<<3) /* Event Channel Select bit 3 mask. */
+#define IRCOM_EVSEL3_bp 3 /* Event Channel Select bit 3 position. */
+
+
+
+// Generic Port Pins
+
+#define PIN0_bm 0x01
+#define PIN0_bp 0
+#define PIN1_bm 0x02
+#define PIN1_bp 1
+#define PIN2_bm 0x04
+#define PIN2_bp 2
+#define PIN3_bm 0x08
+#define PIN3_bp 3
+#define PIN4_bm 0x10
+#define PIN4_bp 4
+#define PIN5_bm 0x20
+#define PIN5_bp 5
+#define PIN6_bm 0x40
+#define PIN6_bp 6
+#define PIN7_bm 0x80
+#define PIN7_bp 7
+
+
+/* ========== Interrupt Vector Definitions ========== */
+/* Vector 0 is the reset vector */
+
+/* OSC interrupt vectors */
+#define OSC_XOSCF_vect_num 1
+#define OSC_XOSCF_vect _VECTOR(1) /* External Oscillator Failure Interrupt (NMI) */
+
+/* PORTC interrupt vectors */
+#define PORTC_INT0_vect_num 2
+#define PORTC_INT0_vect _VECTOR(2) /* External Interrupt 0 */
+#define PORTC_INT1_vect_num 3
+#define PORTC_INT1_vect _VECTOR(3) /* External Interrupt 1 */
+
+/* PORTR interrupt vectors */
+#define PORTR_INT0_vect_num 4
+#define PORTR_INT0_vect _VECTOR(4) /* External Interrupt 0 */
+#define PORTR_INT1_vect_num 5
+#define PORTR_INT1_vect _VECTOR(5) /* External Interrupt 1 */
+
+/* RTC interrupt vectors */
+#define RTC_OVF_vect_num 10
+#define RTC_OVF_vect _VECTOR(10) /* Overflow Interrupt */
+#define RTC_COMP_vect_num 11
+#define RTC_COMP_vect _VECTOR(11) /* Compare Interrupt */
+
+/* TWIC interrupt vectors */
+#define TWIC_TWIS_vect_num 12
+#define TWIC_TWIS_vect _VECTOR(12) /* TWI Slave Interrupt */
+#define TWIC_TWIM_vect_num 13
+#define TWIC_TWIM_vect _VECTOR(13) /* TWI Master Interrupt */
+
+/* TCC0 interrupt vectors */
+#define TCC0_OVF_vect_num 14
+#define TCC0_OVF_vect _VECTOR(14) /* Overflow Interrupt */
+#define TCC0_ERR_vect_num 15
+#define TCC0_ERR_vect _VECTOR(15) /* Error Interrupt */
+#define TCC0_CCA_vect_num 16
+#define TCC0_CCA_vect _VECTOR(16) /* Compare or Capture A Interrupt */
+#define TCC0_CCB_vect_num 17
+#define TCC0_CCB_vect _VECTOR(17) /* Compare or Capture B Interrupt */
+#define TCC0_CCC_vect_num 18
+#define TCC0_CCC_vect _VECTOR(18) /* Compare or Capture C Interrupt */
+#define TCC0_CCD_vect_num 19
+#define TCC0_CCD_vect _VECTOR(19) /* Compare or Capture D Interrupt */
+
+/* TCC1 interrupt vectors */
+#define TCC1_OVF_vect_num 20
+#define TCC1_OVF_vect _VECTOR(20) /* Overflow Interrupt */
+#define TCC1_ERR_vect_num 21
+#define TCC1_ERR_vect _VECTOR(21) /* Error Interrupt */
+#define TCC1_CCA_vect_num 22
+#define TCC1_CCA_vect _VECTOR(22) /* Compare or Capture A Interrupt */
+#define TCC1_CCB_vect_num 23
+#define TCC1_CCB_vect _VECTOR(23) /* Compare or Capture B Interrupt */
+
+/* SPIC interrupt vectors */
+#define SPIC_INT_vect_num 24
+#define SPIC_INT_vect _VECTOR(24) /* SPI Interrupt */
+
+/* USARTC0 interrupt vectors */
+#define USARTC0_RXC_vect_num 25
+#define USARTC0_RXC_vect _VECTOR(25) /* Reception Complete Interrupt */
+#define USARTC0_DRE_vect_num 26
+#define USARTC0_DRE_vect _VECTOR(26) /* Data Register Empty Interrupt */
+#define USARTC0_TXC_vect_num 27
+#define USARTC0_TXC_vect _VECTOR(27) /* Transmission Complete Interrupt */
+
+/* NVM interrupt vectors */
+#define NVM_EE_vect_num 32
+#define NVM_EE_vect _VECTOR(32) /* EE Interrupt */
+#define NVM_SPM_vect_num 33
+#define NVM_SPM_vect _VECTOR(33) /* SPM Interrupt */
+
+/* PORTB interrupt vectors */
+#define PORTB_INT0_vect_num 34
+#define PORTB_INT0_vect _VECTOR(34) /* External Interrupt 0 */
+#define PORTB_INT1_vect_num 35
+#define PORTB_INT1_vect _VECTOR(35) /* External Interrupt 1 */
+
+/* PORTE interrupt vectors */
+#define PORTE_INT0_vect_num 43
+#define PORTE_INT0_vect _VECTOR(43) /* External Interrupt 0 */
+#define PORTE_INT1_vect_num 44
+#define PORTE_INT1_vect _VECTOR(44) /* External Interrupt 1 */
+
+/* TCE0 interrupt vectors */
+#define TCE0_OVF_vect_num 47
+#define TCE0_OVF_vect _VECTOR(47) /* Overflow Interrupt */
+#define TCE0_ERR_vect_num 48
+#define TCE0_ERR_vect _VECTOR(48) /* Error Interrupt */
+#define TCE0_CCA_vect_num 49
+#define TCE0_CCA_vect _VECTOR(49) /* Compare or Capture A Interrupt */
+#define TCE0_CCB_vect_num 50
+#define TCE0_CCB_vect _VECTOR(50) /* Compare or Capture B Interrupt */
+#define TCE0_CCC_vect_num 51
+#define TCE0_CCC_vect _VECTOR(51) /* Compare or Capture C Interrupt */
+#define TCE0_CCD_vect_num 52
+#define TCE0_CCD_vect _VECTOR(52) /* Compare or Capture D Interrupt */
+
+/* USARTE0 interrupt vectors */
+#define USARTE0_RXC_vect_num 58
+#define USARTE0_RXC_vect _VECTOR(58) /* Reception Complete Interrupt */
+#define USARTE0_DRE_vect_num 59
+#define USARTE0_DRE_vect _VECTOR(59) /* Data Register Empty Interrupt */
+#define USARTE0_TXC_vect_num 60
+#define USARTE0_TXC_vect _VECTOR(60) /* Transmission Complete Interrupt */
+
+/* PORTD interrupt vectors */
+#define PORTD_INT0_vect_num 64
+#define PORTD_INT0_vect _VECTOR(64) /* External Interrupt 0 */
+#define PORTD_INT1_vect_num 65
+#define PORTD_INT1_vect _VECTOR(65) /* External Interrupt 1 */
+
+/* PORTA interrupt vectors */
+#define PORTA_INT0_vect_num 66
+#define PORTA_INT0_vect _VECTOR(66) /* External Interrupt 0 */
+#define PORTA_INT1_vect_num 67
+#define PORTA_INT1_vect _VECTOR(67) /* External Interrupt 1 */
+
+/* ACA interrupt vectors */
+#define ACA_AC0_vect_num 68
+#define ACA_AC0_vect _VECTOR(68) /* AC0 Interrupt */
+#define ACA_AC1_vect_num 69
+#define ACA_AC1_vect _VECTOR(69) /* AC1 Interrupt */
+#define ACA_ACW_vect_num 70
+#define ACA_ACW_vect _VECTOR(70) /* ACW Window Mode Interrupt */
+
+/* ADCA interrupt vectors */
+#define ADCA_CH0_vect_num 71
+#define ADCA_CH0_vect _VECTOR(71) /* Interrupt 0 */
+
+/* TCD0 interrupt vectors */
+#define TCD0_OVF_vect_num 77
+#define TCD0_OVF_vect _VECTOR(77) /* Overflow Interrupt */
+#define TCD0_ERR_vect_num 78
+#define TCD0_ERR_vect _VECTOR(78) /* Error Interrupt */
+#define TCD0_CCA_vect_num 79
+#define TCD0_CCA_vect _VECTOR(79) /* Compare or Capture A Interrupt */
+#define TCD0_CCB_vect_num 80
+#define TCD0_CCB_vect _VECTOR(80) /* Compare or Capture B Interrupt */
+#define TCD0_CCC_vect_num 81
+#define TCD0_CCC_vect _VECTOR(81) /* Compare or Capture C Interrupt */
+#define TCD0_CCD_vect_num 82
+#define TCD0_CCD_vect _VECTOR(82) /* Compare or Capture D Interrupt */
+
+/* SPID interrupt vectors */
+#define SPID_INT_vect_num 87
+#define SPID_INT_vect _VECTOR(87) /* SPI Interrupt */
+
+/* USARTD0 interrupt vectors */
+#define USARTD0_RXC_vect_num 88
+#define USARTD0_RXC_vect _VECTOR(88) /* Reception Complete Interrupt */
+#define USARTD0_DRE_vect_num 89
+#define USARTD0_DRE_vect _VECTOR(89) /* Data Register Empty Interrupt */
+#define USARTD0_TXC_vect_num 90
+#define USARTD0_TXC_vect _VECTOR(90) /* Transmission Complete Interrupt */
+
+/* PORTF interrupt vectors */
+#define PORTF_INT0_vect_num 104
+#define PORTF_INT0_vect _VECTOR(104) /* External Interrupt 0 */
+#define PORTF_INT1_vect_num 105
+#define PORTF_INT1_vect _VECTOR(105) /* External Interrupt 1 */
+
+/* TCF0 interrupt vectors */
+#define TCF0_OVF_vect_num 108
+#define TCF0_OVF_vect _VECTOR(108) /* Overflow Interrupt */
+#define TCF0_ERR_vect_num 109
+#define TCF0_ERR_vect _VECTOR(109) /* Error Interrupt */
+#define TCF0_CCA_vect_num 110
+#define TCF0_CCA_vect _VECTOR(110) /* Compare or Capture A Interrupt */
+#define TCF0_CCB_vect_num 111
+#define TCF0_CCB_vect _VECTOR(111) /* Compare or Capture B Interrupt */
+#define TCF0_CCC_vect_num 112
+#define TCF0_CCC_vect _VECTOR(112) /* Compare or Capture C Interrupt */
+#define TCF0_CCD_vect_num 113
+#define TCF0_CCD_vect _VECTOR(113) /* Compare or Capture D Interrupt */
+
+
+#define _VECTOR_SIZE 4 /* Size of individual vector. */
+#define _VECTORS_SIZE (114 * _VECTOR_SIZE)
+
+
+/* ========== Constants ========== */
+
+#define PROGMEM_START (0x0000)
+#define PROGMEM_SIZE (69632)
+#define PROGMEM_PAGE_SIZE (256)
+#define PROGMEM_END (PROGMEM_START + PROGMEM_SIZE - 1)
+
+#define APP_SECTION_START (0x0000)
+#define APP_SECTION_SIZE (65536)
+#define APP_SECTION_PAGE_SIZE (256)
+#define APP_SECTION_END (APP_SECTION_START + APP_SECTION_SIZE - 1)
+
+#define APPTABLE_SECTION_START (0x0F000)
+#define APPTABLE_SECTION_SIZE (4096)
+#define APPTABLE_SECTION_PAGE_SIZE (256)
+#define APPTABLE_SECTION_END (APPTABLE_SECTION_START + APPTABLE_SECTION_SIZE - 1)
+
+#define BOOT_SECTION_START (0x10000)
+#define BOOT_SECTION_SIZE (4096)
+#define BOOT_SECTION_PAGE_SIZE (256)
+#define BOOT_SECTION_END (BOOT_SECTION_START + BOOT_SECTION_SIZE - 1)
+
+#define DATAMEM_START (0x0000)
+#define DATAMEM_SIZE (12288)
+#define DATAMEM_PAGE_SIZE (0)
+#define DATAMEM_END (DATAMEM_START + DATAMEM_SIZE - 1)
+
+#define IO_START (0x0000)
+#define IO_SIZE (4096)
+#define IO_PAGE_SIZE (0)
+#define IO_END (IO_START + IO_SIZE - 1)
+
+#define MAPPED_EEPROM_START (0x1000)
+#define MAPPED_EEPROM_SIZE (2048)
+#define MAPPED_EEPROM_PAGE_SIZE (0)
+#define MAPPED_EEPROM_END (MAPPED_EEPROM_START + MAPPED_EEPROM_SIZE - 1)
+
+#define INTERNAL_SRAM_START (0x2000)
+#define INTERNAL_SRAM_SIZE (4096)
+#define INTERNAL_SRAM_PAGE_SIZE (0)
+#define INTERNAL_SRAM_END (INTERNAL_SRAM_START + INTERNAL_SRAM_SIZE - 1)
+
+#define EEPROM_START (0x0000)
+#define EEPROM_SIZE (2048)
+#define EEPROM_PAGE_SIZE (32)
+#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
+
+#define FUSE_START (0x0000)
+#define FUSE_SIZE (6)
+#define FUSE_PAGE_SIZE (0)
+#define FUSE_END (FUSE_START + FUSE_SIZE - 1)
+
+#define LOCKBIT_START (0x0000)
+#define LOCKBIT_SIZE (1)
+#define LOCKBIT_PAGE_SIZE (0)
+#define LOCKBIT_END (LOCKBIT_START + LOCKBIT_SIZE - 1)
+
+#define SIGNATURES_START (0x0000)
+#define SIGNATURES_SIZE (3)
+#define SIGNATURES_PAGE_SIZE (0)
+#define SIGNATURES_END (SIGNATURES_START + SIGNATURES_SIZE - 1)
+
+#define USER_SIGNATURES_START (0x0000)
+#define USER_SIGNATURES_SIZE (256)
+#define USER_SIGNATURES_PAGE_SIZE (0)
+#define USER_SIGNATURES_END (USER_SIGNATURES_START + USER_SIGNATURES_SIZE - 1)
+
+#define PROD_SIGNATURES_START (0x0000)
+#define PROD_SIGNATURES_SIZE (52)
+#define PROD_SIGNATURES_PAGE_SIZE (0)
+#define PROD_SIGNATURES_END (PROD_SIGNATURES_START + PROD_SIGNATURES_SIZE - 1)
+
+#define FLASHEND PROGMEM_END
+#define SPM_PAGESIZE PROGMEM_PAGE_SIZE
+#define RAMSTART INTERNAL_SRAM_START
+#define RAMSIZE INTERNAL_SRAM_SIZE
+#define RAMEND INTERNAL_SRAM_END
+#define XRAMSTART EXTERNAL_SRAM_START
+#define XRAMSIZE EXTERNAL_SRAM_SIZE
+#define XRAMEND INTERNAL_SRAM_END
+#define E2END EEPROM_END
+#define E2PAGESIZE EEPROM_PAGE_SIZE
+
+
+/* ========== Fuses ========== */
+#define FUSE_MEMORY_SIZE 6
+
+/* Fuse Byte 0 */
+#define FUSE_USERID0 (unsigned char)~_BV(0) /* User ID Bit 0 */
+#define FUSE_USERID1 (unsigned char)~_BV(1) /* User ID Bit 1 */
+#define FUSE_USERID2 (unsigned char)~_BV(2) /* User ID Bit 2 */
+#define FUSE_USERID3 (unsigned char)~_BV(3) /* User ID Bit 3 */
+#define FUSE_USERID4 (unsigned char)~_BV(4) /* User ID Bit 4 */
+#define FUSE_USERID5 (unsigned char)~_BV(5) /* User ID Bit 5 */
+#define FUSE_USERID6 (unsigned char)~_BV(6) /* User ID Bit 6 */
+#define FUSE_USERID7 (unsigned char)~_BV(7) /* User ID Bit 7 */
+#define FUSE0_DEFAULT (0xFF)
+
+/* Fuse Byte 1 */
+#define FUSE_WDP0 (unsigned char)~_BV(0) /* Watchdog Timeout Period Bit 0 */
+#define FUSE_WDP1 (unsigned char)~_BV(1) /* Watchdog Timeout Period Bit 1 */
+#define FUSE_WDP2 (unsigned char)~_BV(2) /* Watchdog Timeout Period Bit 2 */
+#define FUSE_WDP3 (unsigned char)~_BV(3) /* Watchdog Timeout Period Bit 3 */
+#define FUSE_WDWP0 (unsigned char)~_BV(4) /* Watchdog Window Timeout Period Bit 0 */
+#define FUSE_WDWP1 (unsigned char)~_BV(5) /* Watchdog Window Timeout Period Bit 1 */
+#define FUSE_WDWP2 (unsigned char)~_BV(6) /* Watchdog Window Timeout Period Bit 2 */
+#define FUSE_WDWP3 (unsigned char)~_BV(7) /* Watchdog Window Timeout Period Bit 3 */
+#define FUSE1_DEFAULT (0xFF)
+
+/* Fuse Byte 2 */
+#define FUSE_BODPD0 (unsigned char)~_BV(0) /* BOD Operation in Power-Down Mode Bit 0 */
+#define FUSE_BODPD1 (unsigned char)~_BV(1) /* BOD Operation in Power-Down Mode Bit 1 */
+#define FUSE_BOOTRST (unsigned char)~_BV(6) /* Boot Loader Section Reset Vector */
+#define FUSE_DVSDON (unsigned char)~_BV(7) /* Spike Detector Enable */
+#define FUSE2_DEFAULT (0xFF)
+
+/* Fuse Byte 3 Reserved */
+
+/* Fuse Byte 4 */
+#define FUSE_WDLOCK (unsigned char)~_BV(1) /* Watchdog Timer Lock */
+#define FUSE_SUT0 (unsigned char)~_BV(2) /* Start-up Time Bit 0 */
+#define FUSE_SUT1 (unsigned char)~_BV(3) /* Start-up Time Bit 1 */
+#define FUSE4_DEFAULT (0xFF)
+
+/* Fuse Byte 5 */
+#define FUSE_BODLVL0 (unsigned char)~_BV(0) /* Brown Out Detection Voltage Level Bit 0 */
+#define FUSE_BODLVL1 (unsigned char)~_BV(1) /* Brown Out Detection Voltage Level Bit 1 */
+#define FUSE_BODLVL2 (unsigned char)~_BV(2) /* Brown Out Detection Voltage Level Bit 2 */
+#define FUSE_EESAVE (unsigned char)~_BV(3) /* Preserve EEPROM Through Chip Erase */
+#define FUSE_BODACT0 (unsigned char)~_BV(4) /* BOD Operation in Active Mode Bit 0 */
+#define FUSE_BODACT1 (unsigned char)~_BV(5) /* BOD Operation in Active Mode Bit 1 */
+#define FUSE5_DEFAULT (0xFF)
+
+
+/* ========== Lock Bits ========== */
+#define __LOCK_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST
+#define __BOOT_LOCK_APPLICATION_BITS_EXIST
+#define __BOOT_LOCK_BOOT_BITS_EXIST
+
+
+/* ========== Signature ========== */
+#define SIGNATURE_0 0x1E
+#define SIGNATURE_1 0x96
+#define SIGNATURE_2 0x4A
+
+
+#endif /* _AVR_ATxmega64D3_H_ */
+
diff --git a/cpukit/score/cpu/avr/avr/lock.h b/cpukit/score/cpu/avr/avr/lock.h
new file mode 100644
index 0000000000..7da0c572c3
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/lock.h
@@ -0,0 +1,239 @@
+/* Copyright (c) 2007, Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/lock.h - Lock Bits API */
+
+#ifndef _AVR_LOCK_H_
+#define _AVR_LOCK_H_ 1
+
+
+/** \file */
+/** \defgroup avr_lock <avr/lock.h>: Lockbit Support
+
+ \par Introduction
+
+ The Lockbit API allows a user to specify the lockbit settings for the
+ specific AVR device they are compiling for. These lockbit settings will be
+ placed in a special section in the ELF output file, after linking.
+
+ Programming tools can take advantage of the lockbit information embedded in
+ the ELF file, by extracting this information and determining if the lockbits
+ need to be programmed after programming the Flash and EEPROM memories.
+ This also allows a single ELF file to contain all the
+ information needed to program an AVR.
+
+ To use the Lockbit API, include the <avr/io.h> header file, which in turn
+ automatically includes the individual I/O header file and the <avr/lock.h>
+ file. These other two files provides everything necessary to set the AVR
+ lockbits.
+
+ \par Lockbit API
+
+ Each I/O header file may define up to 3 macros that controls what kinds
+ of lockbits are available to the user.
+
+ If __LOCK_BITS_EXIST is defined, then two lock bits are available to the
+ user and 3 mode settings are defined for these two bits.
+
+ If __BOOT_LOCK_BITS_0_EXIST is defined, then the two BLB0 lock bits are
+ available to the user and 4 mode settings are defined for these two bits.
+
+ If __BOOT_LOCK_BITS_1_EXIST is defined, then the two BLB1 lock bits are
+ available to the user and 4 mode settings are defined for these two bits.
+
+ If __BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST is defined then two lock bits
+ are available to set the locking mode for the Application Table Section
+ (which is used in the XMEGA family).
+
+ If __BOOT_LOCK_APPLICATION_BITS_EXIST is defined then two lock bits are
+ available to set the locking mode for the Application Section (which is used
+ in the XMEGA family).
+
+ If __BOOT_LOCK_BOOT_BITS_EXIST is defined then two lock bits are available
+ to set the locking mode for the Boot Loader Section (which is used in the
+ XMEGA family).
+
+ The AVR lockbit modes have inverted values, logical 1 for an unprogrammed
+ (disabled) bit and logical 0 for a programmed (enabled) bit. The defined
+ macros for each individual lock bit represent this in their definition by a
+ bit-wise inversion of a mask. For example, the LB_MODE_3 macro is defined
+ as:
+ \code
+ #define LB_MODE_3 (0xFC)
+` \endcode
+
+ To combine the lockbit mode macros together to represent a whole byte,
+ use the bitwise AND operator, like so:
+ \code
+ (LB_MODE_3 & BLB0_MODE_2)
+ \endcode
+
+ <avr/lock.h> also defines a macro that provides a default lockbit value:
+ LOCKBITS_DEFAULT which is defined to be 0xFF.
+
+ See the AVR device specific datasheet for more details about these
+ lock bits and the available mode settings.
+
+ A convenience macro, LOCKMEM, is defined as a GCC attribute for a
+ custom-named section of ".lock".
+
+ A convenience macro, LOCKBITS, is defined that declares a variable, __lock,
+ of type unsigned char with the attribute defined by LOCKMEM. This variable
+ allows the end user to easily set the lockbit data.
+
+ \note If a device-specific I/O header file has previously defined LOCKMEM,
+ then LOCKMEM is not redefined. If a device-specific I/O header file has
+ previously defined LOCKBITS, then LOCKBITS is not redefined. LOCKBITS is
+ currently known to be defined in the I/O header files for the XMEGA devices.
+
+ \par API Usage Example
+
+ Putting all of this together is easy:
+
+ \code
+ #include <avr/io.h>
+
+ LOCKBITS = (LB_MODE_1 & BLB0_MODE_3 & BLB1_MODE_4);
+
+ int main(void)
+ {
+ return 0;
+ }
+ \endcode
+
+ Or:
+
+ \code
+ #include <avr/io.h>
+
+ unsigned char __lock __attribute__((section (".lock"))) =
+ (LB_MODE_1 & BLB0_MODE_3 & BLB1_MODE_4);
+
+ int main(void)
+ {
+ return 0;
+ }
+ \endcode
+
+
+
+ However there are a number of caveats that you need to be aware of to
+ use this API properly.
+
+ Be sure to include <avr/io.h> to get all of the definitions for the API.
+ The LOCKBITS macro defines a global variable to store the lockbit data. This
+ variable is assigned to its own linker section. Assign the desired lockbit
+ values immediately in the variable initialization.
+
+ The .lock section in the ELF file will get its values from the initial
+ variable assignment ONLY. This means that you can NOT assign values to
+ this variable in functions and the new values will not be put into the
+ ELF .lock section.
+
+ The global variable is declared in the LOCKBITS macro has two leading
+ underscores, which means that it is reserved for the "implementation",
+ meaning the library, so it will not conflict with a user-named variable.
+
+ You must initialize the lockbit variable to some meaningful value, even
+ if it is the default value. This is because the lockbits default to a
+ logical 1, meaning unprogrammed. Normal uninitialized data defaults to all
+ locgial zeros. So it is vital that all lockbits are initialized, even with
+ default data. If they are not, then the lockbits may not programmed to the
+ desired settings and can possibly put your device into an unrecoverable
+ state.
+
+ Be sure to have the -mmcu=<em>device</em> flag in your compile command line and
+ your linker command line to have the correct device selected and to have
+ the correct I/O header file included when you include <avr/io.h>.
+
+ You can print out the contents of the .lock section in the ELF file by
+ using this command line:
+ \code
+ avr-objdump -s -j .lock <ELF file>
+ \endcode
+
+*/
+
+
+#ifndef __ASSEMBLER__
+
+#ifndef LOCKMEM
+#define LOCKMEM __attribute__((section (".lock")))
+#endif
+
+#ifndef LOCKBITS
+#define LOCKBITS unsigned char __lock LOCKMEM
+#endif
+
+#endif /* !__ASSEMBLER */
+
+
+/* Lock Bit Modes */
+#if defined(__LOCK_BITS_EXIST)
+#define LB_MODE_1 (0xFF)
+#define LB_MODE_2 (0xFE)
+#define LB_MODE_3 (0xFC)
+#endif
+
+#if defined(__BOOT_LOCK_BITS_0_EXIST)
+#define BLB0_MODE_1 (0xFF)
+#define BLB0_MODE_2 (0xFB)
+#define BLB0_MODE_3 (0xF3)
+#define BLB0_MODE_4 (0xF7)
+#endif
+
+#if defined(__BOOT_LOCK_BITS_1_EXIST)
+#define BLB1_MODE_1 (0xFF)
+#define BLB1_MODE_2 (0xEF)
+#define BLB1_MODE_3 (0xCF)
+#define BLB1_MODE_4 (0xDF)
+#endif
+
+#if defined(__BOOT_LOCK_APPLICATION_TABLE_BITS_EXIST)
+#define BLBAT0 ~_BV(2)
+#define BLBAT1 ~_BV(3)
+#endif
+
+#if defined(__BOOT_LOCK_APPLICATION_BITS_EXIST)
+#define BLBA0 ~_BV(4)
+#define BLBA1 ~_BV(5)
+#endif
+
+#if defined(__BOOT_LOCK_BOOT_BITS_EXIST)
+#define BLBB0 ~_BV(6)
+#define BLBB1 ~_BV(7)
+#endif
+
+
+#define LOCKBITS_DEFAULT (0xFF)
+
+#endif /* _AVR_LOCK_H_ */
diff --git a/cpukit/score/cpu/avr/avr/parity.h b/cpukit/score/cpu/avr/avr/parity.h
new file mode 100644
index 0000000000..d7afd34ddd
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/parity.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 2005 Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_PARITY_H_
+#define _AVR_PARITY_H_
+
+#warning "This file has been moved to <util/parity.h>."
+#include <util/parity.h>
+
+#endif /* _AVR_PARITY_H_ */
diff --git a/cpukit/score/cpu/avr/avr/pgmspace.h b/cpukit/score/cpu/avr/avr/pgmspace.h
new file mode 100644
index 0000000000..ec309a8b12
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/pgmspace.h
@@ -0,0 +1,882 @@
+/* Copyright (c) 2002 - 2007 Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/*
+ pgmspace.h
+
+ Contributors:
+ Created by Marek Michalkiewicz <marekm@linux.org.pl>
+ Eric B. Weddington <eric@ecentral.com>
+ Wolfgang Haidinger <wh@vmars.tuwien.ac.at> (pgm_read_dword())
+ Ivanov Anton <anton@arc.com.ru> (pgm_read_float())
+ */
+
+/** \file */
+/** \defgroup avr_pgmspace <avr/pgmspace.h>: Program Space Utilities
+ \code
+ #include <avr/io.h>
+ #include <avr/pgmspace.h>
+ \endcode
+
+ The functions in this module provide interfaces for a program to access
+ data stored in program space (flash memory) of the device. In order to
+ use these functions, the target device must support either the \c LPM or
+ \c ELPM instructions.
+
+ \note These functions are an attempt to provide some compatibility with
+ header files that come with IAR C, to make porting applications between
+ different compilers easier. This is not 100% compatibility though (GCC
+ does not have full support for multiple address spaces yet).
+
+ \note If you are working with strings which are completely based in ram,
+ use the standard string functions described in \ref avr_string.
+
+ \note If possible, put your constant tables in the lower 64 KB and use
+ pgm_read_byte_near() or pgm_read_word_near() instead of
+ pgm_read_byte_far() or pgm_read_word_far() since it is more efficient that
+ way, and you can still use the upper 64K for executable code.
+ All functions that are suffixed with a \c _P \e require their
+ arguments to be in the lower 64 KB of the flash ROM, as they do
+ not use ELPM instructions. This is normally not a big concern as
+ the linker setup arranges any program space constants declared
+ using the macros from this header file so they are placed right after
+ the interrupt vectors, and in front of any executable code. However,
+ it can become a problem if there are too many of these constants, or
+ for bootloaders on devices with more than 64 KB of ROM.
+ <em>All these functions will not work in that situation.</em>
+*/
+
+#ifndef __PGMSPACE_H_
+#define __PGMSPACE_H_ 1
+
+#define __need_size_t
+#include <inttypes.h>
+#include <stddef.h>
+#include <avr/io.h>
+
+#ifndef __ATTR_CONST__
+#define __ATTR_CONST__ __attribute__((__const__))
+#endif
+
+#ifndef __ATTR_PROGMEM__
+#define __ATTR_PROGMEM__ __attribute__((__progmem__))
+#endif
+
+#ifndef __ATTR_PURE__
+#define __ATTR_PURE__ __attribute__((__pure__))
+#endif
+
+/**
+ \ingroup avr_pgmspace
+ \def PROGMEM
+
+ Attribute to use in order to declare an object being located in
+ flash ROM.
+ */
+#define PROGMEM __ATTR_PROGMEM__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(__DOXYGEN__)
+/*
+ * Doxygen doesn't grok the appended attribute syntax of
+ * GCC, and confuses the typedefs with function decls, so
+ * supply a doxygen-friendly view.
+ */
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_void
+
+ Type of a "void" object located in flash ROM. Does not make much
+ sense by itself, but can be used to declare a "void *" object in
+ flash ROM.
+*/
+typedef void PROGMEM prog_void;
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_char
+
+ Type of a "char" object located in flash ROM.
+*/
+typedef char PROGMEM prog_char;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_uchar
+
+ Type of an "unsigned char" object located in flash ROM.
+*/
+typedef unsigned char PROGMEM prog_uchar;
+
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_int8_t
+
+ Type of an "int8_t" object located in flash ROM.
+*/
+typedef int8_t PROGMEM prog_int8_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_uint8_t
+
+ Type of an "uint8_t" object located in flash ROM.
+*/
+typedef uint8_t PROGMEM prog_uint8_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_int16_t
+
+ Type of an "int16_t" object located in flash ROM.
+*/
+typedef int16_t PROGMEM prog_int16_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_uint16_t
+
+ Type of an "uint16_t" object located in flash ROM.
+*/
+typedef uint16_t PROGMEM prog_uint16_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_int32_t
+
+ Type of an "int32_t" object located in flash ROM.
+*/
+typedef int32_t PROGMEM prog_int32_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_uint32_t
+
+ Type of an "uint32_t" object located in flash ROM.
+*/
+typedef uint32_t PROGMEM prog_uint32_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_int64_t
+
+ Type of an "int64_t" object located in flash ROM.
+
+ \note This type is not available when the compiler
+ option -mint8 is in effect.
+*/
+typedef int64_t PROGMEM prog_int64_t;
+
+/**
+ \ingroup avr_pgmspace
+ \typedef prog_uint64_t
+
+ Type of an "uint64_t" object located in flash ROM.
+
+ \note This type is not available when the compiler
+ option -mint8 is in effect.
+*/
+typedef uint64_t PROGMEM prog_uint64_t;
+#else /* !DOXYGEN */
+typedef void prog_void PROGMEM;
+typedef char prog_char PROGMEM;
+typedef unsigned char prog_uchar PROGMEM;
+
+typedef int8_t prog_int8_t PROGMEM;
+typedef uint8_t prog_uint8_t PROGMEM;
+typedef int16_t prog_int16_t PROGMEM;
+typedef uint16_t prog_uint16_t PROGMEM;
+typedef int32_t prog_int32_t PROGMEM;
+typedef uint32_t prog_uint32_t PROGMEM;
+#if !__USING_MINT8
+typedef int64_t prog_int64_t PROGMEM;
+typedef uint64_t prog_uint64_t PROGMEM;
+#endif
+#endif /* defined(__DOXYGEN__) */
+
+/* Although in C, we can get away with just using __c, it does not work in
+ C++. We need to use &__c[0] to avoid the compiler puking. Dave Hylands
+ explaned it thusly,
+
+ Let's suppose that we use PSTR("Test"). In this case, the type returned
+ by __c is a prog_char[5] and not a prog_char *. While these are
+ compatible, they aren't the same thing (especially in C++). The type
+ returned by &__c[0] is a prog_char *, which explains why it works
+ fine. */
+
+#if defined(__DOXYGEN__)
+/*
+ * The #define below is just a dummy that serves documentation
+ * purposes only.
+ */
+/** \ingroup avr_pgmspace
+ \def PSTR(s)
+
+ Used to declare a static pointer to a string in program space. */
+# define PSTR(s) ((const PROGMEM char *)(s))
+#else /* !DOXYGEN */
+/* The real thing. */
+# define PSTR(s) (__extension__({static char __c[] PROGMEM = (s); &__c[0];}))
+#endif /* DOXYGEN */
+
+#define __LPM_classic__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ uint8_t __result; \
+ __asm__ \
+ ( \
+ "lpm" "\n\t" \
+ "mov %0, r0" "\n\t" \
+ : "=r" (__result) \
+ : "z" (__addr16) \
+ : "r0" \
+ ); \
+ __result; \
+}))
+
+#define __LPM_enhanced__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ uint8_t __result; \
+ __asm__ \
+ ( \
+ "lpm %0, Z" "\n\t" \
+ : "=r" (__result) \
+ : "z" (__addr16) \
+ ); \
+ __result; \
+}))
+
+#define __LPM_word_classic__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ uint16_t __result; \
+ __asm__ \
+ ( \
+ "lpm" "\n\t" \
+ "mov %A0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %B0, r0" "\n\t" \
+ : "=r" (__result), "=z" (__addr16) \
+ : "1" (__addr16) \
+ : "r0" \
+ ); \
+ __result; \
+}))
+
+#define __LPM_word_enhanced__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ uint16_t __result; \
+ __asm__ \
+ ( \
+ "lpm %A0, Z+" "\n\t" \
+ "lpm %B0, Z" "\n\t" \
+ : "=r" (__result), "=z" (__addr16) \
+ : "1" (__addr16) \
+ ); \
+ __result; \
+}))
+
+#define __LPM_dword_classic__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ uint32_t __result; \
+ __asm__ \
+ ( \
+ "lpm" "\n\t" \
+ "mov %A0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %B0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %C0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %D0, r0" "\n\t" \
+ : "=r" (__result), "=z" (__addr16) \
+ : "1" (__addr16) \
+ : "r0" \
+ ); \
+ __result; \
+}))
+
+#define __LPM_dword_enhanced__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ uint32_t __result; \
+ __asm__ \
+ ( \
+ "lpm %A0, Z+" "\n\t" \
+ "lpm %B0, Z+" "\n\t" \
+ "lpm %C0, Z+" "\n\t" \
+ "lpm %D0, Z" "\n\t" \
+ : "=r" (__result), "=z" (__addr16) \
+ : "1" (__addr16) \
+ ); \
+ __result; \
+}))
+
+#define __LPM_float_classic__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ float __result; \
+ __asm__ \
+ ( \
+ "lpm" "\n\t" \
+ "mov %A0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %B0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %C0, r0" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "lpm" "\n\t" \
+ "mov %D0, r0" "\n\t" \
+ : "=r" (__result), "=z" (__addr16) \
+ : "1" (__addr16) \
+ : "r0" \
+ ); \
+ __result; \
+}))
+
+#define __LPM_float_enhanced__(addr) \
+(__extension__({ \
+ uint16_t __addr16 = (uint16_t)(addr); \
+ float __result; \
+ __asm__ \
+ ( \
+ "lpm %A0, Z+" "\n\t" \
+ "lpm %B0, Z+" "\n\t" \
+ "lpm %C0, Z+" "\n\t" \
+ "lpm %D0, Z" "\n\t" \
+ : "=r" (__result), "=z" (__addr16) \
+ : "1" (__addr16) \
+ ); \
+ __result; \
+}))
+
+#if defined (__AVR_HAVE_LPMX__)
+#define __LPM(addr) __LPM_enhanced__(addr)
+#define __LPM_word(addr) __LPM_word_enhanced__(addr)
+#define __LPM_dword(addr) __LPM_dword_enhanced__(addr)
+#define __LPM_float(addr) __LPM_float_enhanced__(addr)
+#else
+#define __LPM(addr) __LPM_classic__(addr)
+#define __LPM_word(addr) __LPM_word_classic__(addr)
+#define __LPM_dword(addr) __LPM_dword_classic__(addr)
+#define __LPM_float(addr) __LPM_float_classic__(addr)
+#endif
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_byte_near(address_short)
+ Read a byte from the program space with a 16-bit (near) address.
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_word_near(address_short)
+ Read a word from the program space with a 16-bit (near) address.
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_word_near(address_short) __LPM_word((uint16_t)(address_short))
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_dword_near(address_short)
+ Read a double word from the program space with a 16-bit (near) address.
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_dword_near(address_short) \
+ __LPM_dword((uint16_t)(address_short))
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_float_near(address_short)
+ Read a float from the program space with a 16-bit (near) address.
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_float_near(address_short) \
+ __LPM_float((uint16_t)(address_short))
+
+#if defined(RAMPZ) || defined(__DOXYGEN__)
+
+/* Only for devices with more than 64K of program memory.
+ RAMPZ must be defined (see iom103.h, iom128.h).
+*/
+
+/* The classic functions are needed for ATmega103. */
+
+#define __ELPM_classic__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint8_t __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "mov r31, %B1" "\n\t" \
+ "mov r30, %A1" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %0, r0" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r0", "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_enhanced__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint8_t __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %0, Z+" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_xmega__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint8_t __result; \
+ __asm__ \
+ ( \
+ "in __tmp_reg__, %2" "\n\t" \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %0, Z+" "\n\t" \
+ "out %2, __tmp_reg__" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_word_classic__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint16_t __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "mov r31, %B1" "\n\t" \
+ "mov r30, %A1" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %A0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %B0, r0" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r0", "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_word_enhanced__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint16_t __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %A0, Z+" "\n\t" \
+ "elpm %B0, Z" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_word_xmega__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint16_t __result; \
+ __asm__ \
+ ( \
+ "in __tmp_reg__, %2" "\n\t" \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %A0, Z+" "\n\t" \
+ "elpm %B0, Z" "\n\t" \
+ "out %2, __tmp_reg__" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_dword_classic__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint32_t __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "mov r31, %B1" "\n\t" \
+ "mov r30, %A1" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %A0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %B0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %C0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %D0, r0" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r0", "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_dword_enhanced__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint32_t __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %A0, Z+" "\n\t" \
+ "elpm %B0, Z+" "\n\t" \
+ "elpm %C0, Z+" "\n\t" \
+ "elpm %D0, Z" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_dword_xmega__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ uint32_t __result; \
+ __asm__ \
+ ( \
+ "in __tmp_reg__, %2" "\n\t" \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %A0, Z+" "\n\t" \
+ "elpm %B0, Z+" "\n\t" \
+ "elpm %C0, Z+" "\n\t" \
+ "elpm %D0, Z" "\n\t" \
+ "out %2, __tmp_reg__" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_float_classic__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ float __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "mov r31, %B1" "\n\t" \
+ "mov r30, %A1" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %A0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %B0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %C0, r0" "\n\t" \
+ "in r0, %2" "\n\t" \
+ "adiw r30, 1" "\n\t" \
+ "adc r0, __zero_reg__" "\n\t" \
+ "out %2, r0" "\n\t" \
+ "elpm" "\n\t" \
+ "mov %D0, r0" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r0", "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_float_enhanced__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ float __result; \
+ __asm__ \
+ ( \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %A0, Z+" "\n\t" \
+ "elpm %B0, Z+" "\n\t" \
+ "elpm %C0, Z+" "\n\t" \
+ "elpm %D0, Z" "\n\t" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+#define __ELPM_float_xmega__(addr) \
+(__extension__({ \
+ uint32_t __addr32 = (uint32_t)(addr); \
+ float __result; \
+ __asm__ \
+ ( \
+ "in __tmp_reg__, %2" "\n\t" \
+ "out %2, %C1" "\n\t" \
+ "movw r30, %1" "\n\t" \
+ "elpm %A0, Z+" "\n\t" \
+ "elpm %B0, Z+" "\n\t" \
+ "elpm %C0, Z+" "\n\t" \
+ "elpm %D0, Z" "\n\t" \
+ "out %2, __tmp_reg__" \
+ : "=r" (__result) \
+ : "r" (__addr32), \
+ "I" (_SFR_IO_ADDR(RAMPZ)) \
+ : "r30", "r31" \
+ ); \
+ __result; \
+}))
+
+/*
+Check for architectures that implement RAMPD (avrxmega3, avrxmega5,
+avrxmega7) as they need to save/restore RAMPZ for ELPM macros so it does
+not interfere with data accesses.
+*/
+#if defined (__AVR_HAVE_RAMPD__)
+
+#define __ELPM(addr) __ELPM_xmega__(addr)
+#define __ELPM_word(addr) __ELPM_word_xmega__(addr)
+#define __ELPM_dword(addr) __ELPM_dword_xmega__(addr)
+#define __ELPM_float(addr) __ELPM_float_xmega__(addr)
+
+#else
+
+#if defined (__AVR_HAVE_LPMX__)
+
+#define __ELPM(addr) __ELPM_enhanced__(addr)
+#define __ELPM_word(addr) __ELPM_word_enhanced__(addr)
+#define __ELPM_dword(addr) __ELPM_dword_enhanced__(addr)
+#define __ELPM_float(addr) __ELPM_float_enhanced__(addr)
+
+#else
+
+#define __ELPM(addr) __ELPM_classic__(addr)
+#define __ELPM_word(addr) __ELPM_word_classic__(addr)
+#define __ELPM_dword(addr) __ELPM_dword_classic__(addr)
+#define __ELPM_float(addr) __ELPM_float_classic__(addr)
+
+#endif /* __AVR_HAVE_LPMX__ */
+
+#endif /* __AVR_HAVE_RAMPD__ */
+
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_byte_far(address_long)
+ Read a byte from the program space with a 32-bit (far) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_byte_far(address_long) __ELPM((uint32_t)(address_long))
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_word_far(address_long)
+ Read a word from the program space with a 32-bit (far) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_word_far(address_long) __ELPM_word((uint32_t)(address_long))
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_dword_far(address_long)
+ Read a double word from the program space with a 32-bit (far) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_dword_far(address_long) __ELPM_dword((uint32_t)(address_long))
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_float_far(address_long)
+ Read a float from the program space with a 32-bit (far) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_float_far(address_long) __ELPM_float((uint32_t)(address_long))
+
+#endif /* RAMPZ or __DOXYGEN__ */
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_byte(address_short)
+ Read a byte from the program space with a 16-bit (near) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_word(address_short)
+ Read a word from the program space with a 16-bit (near) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_word(address_short) pgm_read_word_near(address_short)
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_dword(address_short)
+ Read a double word from the program space with a 16-bit (near) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_dword(address_short) pgm_read_dword_near(address_short)
+
+/** \ingroup avr_pgmspace
+ \def pgm_read_float(address_short)
+ Read a float from the program space with a 16-bit (near) address.
+
+ \note The address is a byte address.
+ The address is in the program space. */
+
+#define pgm_read_float(address_short) pgm_read_float_near(address_short)
+
+/** \ingroup avr_pgmspace
+ \def PGM_P
+
+ Used to declare a variable that is a pointer to a string in program
+ space. */
+
+#ifndef PGM_P
+#define PGM_P const prog_char *
+#endif
+
+/** \ingroup avr_pgmspace
+ \def PGM_VOID_P
+
+ Used to declare a generic pointer to an object in program space. */
+
+#ifndef PGM_VOID_P
+#define PGM_VOID_P const prog_void *
+#endif
+
+extern PGM_VOID_P memchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
+extern int memcmp_P(const void *, PGM_VOID_P, size_t) __ATTR_PURE__;
+extern void *memccpy_P(void *, PGM_VOID_P, int __val, size_t);
+extern void *memcpy_P(void *, PGM_VOID_P, size_t);
+extern void *memmem_P(const void *, size_t, PGM_VOID_P, size_t) __ATTR_PURE__;
+extern PGM_VOID_P memrchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
+extern char *strcat_P(char *, PGM_P);
+extern PGM_P strchr_P(PGM_P, int __val) __ATTR_CONST__;
+extern PGM_P strchrnul_P(PGM_P, int __val) __ATTR_CONST__;
+extern int strcmp_P(const char *, PGM_P) __ATTR_PURE__;
+extern char *strcpy_P(char *, PGM_P);
+extern int strcasecmp_P(const char *, PGM_P) __ATTR_PURE__;
+extern char *strcasestr_P(const char *, PGM_P) __ATTR_PURE__;
+extern size_t strcspn_P(const char *__s, PGM_P __reject) __ATTR_PURE__;
+extern size_t strlcat_P (char *, PGM_P, size_t );
+extern size_t strlcpy_P (char *, PGM_P, size_t );
+extern size_t strlen_P(PGM_P) __ATTR_CONST__; /* program memory can't change */
+extern size_t strnlen_P(PGM_P, size_t) __ATTR_CONST__; /* program memory can't change */
+extern int strncmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
+extern int strncasecmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
+extern char *strncat_P(char *, PGM_P, size_t);
+extern char *strncpy_P(char *, PGM_P, size_t);
+extern char *strpbrk_P(const char *__s, PGM_P __accept) __ATTR_PURE__;
+extern PGM_P strrchr_P(PGM_P, int __val) __ATTR_CONST__;
+extern char *strsep_P(char **__sp, PGM_P __delim);
+extern size_t strspn_P(const char *__s, PGM_P __accept) __ATTR_PURE__;
+extern char *strstr_P(const char *, PGM_P) __ATTR_PURE__;
+extern char *strtok_P(char *__s, PGM_P __delim);
+extern char *strtok_rP(char *__s, PGM_P __delim, char **__last);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PGMSPACE_H_ */
diff --git a/cpukit/score/cpu/avr/avr/portpins.h b/cpukit/score/cpu/avr/avr/portpins.h
new file mode 100644
index 0000000000..c179edfabe
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/portpins.h
@@ -0,0 +1,549 @@
+/* Copyright (c) 2003 Theodore A. Roth
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_PORTPINS_H_
+#define _AVR_PORTPINS_H_ 1
+
+/* This file should only be included from <avr/io.h>, never directly. */
+
+#ifndef _AVR_IO_H_
+# error "Include <avr/io.h> instead of this file."
+#endif
+
+/* Define Generic PORTn, DDn, and PINn values. */
+
+/* Port Data Register (generic) */
+#define PORT7 7
+#define PORT6 6
+#define PORT5 5
+#define PORT4 4
+#define PORT3 3
+#define PORT2 2
+#define PORT1 1
+#define PORT0 0
+
+/* Port Data Direction Register (generic) */
+#define DD7 7
+#define DD6 6
+#define DD5 5
+#define DD4 4
+#define DD3 3
+#define DD2 2
+#define DD1 1
+#define DD0 0
+
+/* Port Input Pins (generic) */
+#define PIN7 7
+#define PIN6 6
+#define PIN5 5
+#define PIN4 4
+#define PIN3 3
+#define PIN2 2
+#define PIN1 1
+#define PIN0 0
+
+/* Define PORTxn an Pxn values for all possible port pins if not defined already by io.h. */
+
+/* PORT A */
+
+#if defined(PA0) && !defined(PORTA0)
+# define PORTA0 PA0
+#elif defined(PORTA0) && !defined(PA0)
+# define PA0 PORTA0
+#endif
+#if defined(PA1) && !defined(PORTA1)
+# define PORTA1 PA1
+#elif defined(PORTA1) && !defined(PA1)
+# define PA1 PORTA1
+#endif
+#if defined(PA2) && !defined(PORTA2)
+# define PORTA2 PA2
+#elif defined(PORTA2) && !defined(PA2)
+# define PA2 PORTA2
+#endif
+#if defined(PA3) && !defined(PORTA3)
+# define PORTA3 PA3
+#elif defined(PORTA3) && !defined(PA3)
+# define PA3 PORTA3
+#endif
+#if defined(PA4) && !defined(PORTA4)
+# define PORTA4 PA4
+#elif defined(PORTA4) && !defined(PA4)
+# define PA4 PORTA4
+#endif
+#if defined(PA5) && !defined(PORTA5)
+# define PORTA5 PA5
+#elif defined(PORTA5) && !defined(PA5)
+# define PA5 PORTA5
+#endif
+#if defined(PA6) && !defined(PORTA6)
+# define PORTA6 PA6
+#elif defined(PORTA6) && !defined(PA6)
+# define PA6 PORTA6
+#endif
+#if defined(PA7) && !defined(PORTA7)
+# define PORTA7 PA7
+#elif defined(PORTA7) && !defined(PA7)
+# define PA7 PORTA7
+#endif
+
+/* PORT B */
+
+#if defined(PB0) && !defined(PORTB0)
+# define PORTB0 PB0
+#elif defined(PORTB0) && !defined(PB0)
+# define PB0 PORTB0
+#endif
+#if defined(PB1) && !defined(PORTB1)
+# define PORTB1 PB1
+#elif defined(PORTB1) && !defined(PB1)
+# define PB1 PORTB1
+#endif
+#if defined(PB2) && !defined(PORTB2)
+# define PORTB2 PB2
+#elif defined(PORTB2) && !defined(PB2)
+# define PB2 PORTB2
+#endif
+#if defined(PB3) && !defined(PORTB3)
+# define PORTB3 PB3
+#elif defined(PORTB3) && !defined(PB3)
+# define PB3 PORTB3
+#endif
+#if defined(PB4) && !defined(PORTB4)
+# define PORTB4 PB4
+#elif defined(PORTB4) && !defined(PB4)
+# define PB4 PORTB4
+#endif
+#if defined(PB5) && !defined(PORTB5)
+# define PORTB5 PB5
+#elif defined(PORTB5) && !defined(PB5)
+# define PB5 PORTB5
+#endif
+#if defined(PB6) && !defined(PORTB6)
+# define PORTB6 PB6
+#elif defined(PORTB6) && !defined(PB6)
+# define PB6 PORTB6
+#endif
+#if defined(PB7) && !defined(PORTB7)
+# define PORTB7 PB7
+#elif defined(PORTB7) && !defined(PB7)
+# define PB7 PORTB7
+#endif
+
+/* PORT C */
+
+#if defined(PC0) && !defined(PORTC0)
+# define PORTC0 PC0
+#elif defined(PORTC0) && !defined(PC0)
+# define PC0 PORTC0
+#endif
+#if defined(PC1) && !defined(PORTC1)
+# define PORTC1 PC1
+#elif defined(PORTC1) && !defined(PC1)
+# define PC1 PORTC1
+#endif
+#if defined(PC2) && !defined(PORTC2)
+# define PORTC2 PC2
+#elif defined(PORTC2) && !defined(PC2)
+# define PC2 PORTC2
+#endif
+#if defined(PC3) && !defined(PORTC3)
+# define PORTC3 PC3
+#elif defined(PORTC3) && !defined(PC3)
+# define PC3 PORTC3
+#endif
+#if defined(PC4) && !defined(PORTC4)
+# define PORTC4 PC4
+#elif defined(PORTC4) && !defined(PC4)
+# define PC4 PORTC4
+#endif
+#if defined(PC5) && !defined(PORTC5)
+# define PORTC5 PC5
+#elif defined(PORTC5) && !defined(PC5)
+# define PC5 PORTC5
+#endif
+#if defined(PC6) && !defined(PORTC6)
+# define PORTC6 PC6
+#elif defined(PORTC6) && !defined(PC6)
+# define PC6 PORTC6
+#endif
+#if defined(PC7) && !defined(PORTC7)
+# define PORTC7 PC7
+#elif defined(PORTC7) && !defined(PC7)
+# define PC7 PORTC7
+#endif
+
+/* PORT D */
+
+#if defined(PD0) && !defined(PORTD0)
+# define PORTD0 PD0
+#elif defined(PORTD0) && !defined(PD0)
+# define PD0 PORTD0
+#endif
+#if defined(PD1) && !defined(PORTD1)
+# define PORTD1 PD1
+#elif defined(PORTD1) && !defined(PD1)
+# define PD1 PORTD1
+#endif
+#if defined(PD2) && !defined(PORTD2)
+# define PORTD2 PD2
+#elif defined(PORTD2) && !defined(PD2)
+# define PD2 PORTD2
+#endif
+#if defined(PD3) && !defined(PORTD3)
+# define PORTD3 PD3
+#elif defined(PORTD3) && !defined(PD3)
+# define PD3 PORTD3
+#endif
+#if defined(PD4) && !defined(PORTD4)
+# define PORTD4 PD4
+#elif defined(PORTD4) && !defined(PD4)
+# define PD4 PORTD4
+#endif
+#if defined(PD5) && !defined(PORTD5)
+# define PORTD5 PD5
+#elif defined(PORTD5) && !defined(PD5)
+# define PD5 PORTD5
+#endif
+#if defined(PD6) && !defined(PORTD6)
+# define PORTD6 PD6
+#elif defined(PORTD6) && !defined(PD6)
+# define PD6 PORTD6
+#endif
+#if defined(PD7) && !defined(PORTD7)
+# define PORTD7 PD7
+#elif defined(PORTD7) && !defined(PD7)
+# define PD7 PORTD7
+#endif
+
+/* PORT E */
+
+#if defined(PE0) && !defined(PORTE0)
+# define PORTE0 PE0
+#elif defined(PORTE0) && !defined(PE0)
+# define PE0 PORTE0
+#endif
+#if defined(PE1) && !defined(PORTE1)
+# define PORTE1 PE1
+#elif defined(PORTE1) && !defined(PE1)
+# define PE1 PORTE1
+#endif
+#if defined(PE2) && !defined(PORTE2)
+# define PORTE2 PE2
+#elif defined(PORTE2) && !defined(PE2)
+# define PE2 PORTE2
+#endif
+#if defined(PE3) && !defined(PORTE3)
+# define PORTE3 PE3
+#elif defined(PORTE3) && !defined(PE3)
+# define PE3 PORTE3
+#endif
+#if defined(PE4) && !defined(PORTE4)
+# define PORTE4 PE4
+#elif defined(PORTE4) && !defined(PE4)
+# define PE4 PORTE4
+#endif
+#if defined(PE5) && !defined(PORTE5)
+# define PORTE5 PE5
+#elif defined(PORTE5) && !defined(PE5)
+# define PE5 PORTE5
+#endif
+#if defined(PE6) && !defined(PORTE6)
+# define PORTE6 PE6
+#elif defined(PORTE6) && !defined(PE6)
+# define PE6 PORTE6
+#endif
+#if defined(PE7) && !defined(PORTE7)
+# define PORTE7 PE7
+#elif defined(PORTE7) && !defined(PE7)
+# define PE7 PORTE7
+#endif
+
+/* PORT F */
+
+#if defined(PF0) && !defined(PORTF0)
+# define PORTF0 PF0
+#elif defined(PORTF0) && !defined(PF0)
+# define PF0 PORTF0
+#endif
+#if defined(PF1) && !defined(PORTF1)
+# define PORTF1 PF1
+#elif defined(PORTF1) && !defined(PF1)
+# define PF1 PORTF1
+#endif
+#if defined(PF2) && !defined(PORTF2)
+# define PORTF2 PF2
+#elif defined(PORTF2) && !defined(PF2)
+# define PF2 PORTF2
+#endif
+#if defined(PF3) && !defined(PORTF3)
+# define PORTF3 PF3
+#elif defined(PORTF3) && !defined(PF3)
+# define PF3 PORTF3
+#endif
+#if defined(PF4) && !defined(PORTF4)
+# define PORTF4 PF4
+#elif defined(PORTF4) && !defined(PF4)
+# define PF4 PORTF4
+#endif
+#if defined(PF5) && !defined(PORTF5)
+# define PORTF5 PF5
+#elif defined(PORTF5) && !defined(PF5)
+# define PF5 PORTF5
+#endif
+#if defined(PF6) && !defined(PORTF6)
+# define PORTF6 PF6
+#elif defined(PORTF6) && !defined(PF6)
+# define PF6 PORTF6
+#endif
+#if defined(PF7) && !defined(PORTF7)
+# define PORTF7 PF7
+#elif defined(PORTF7) && !defined(PF7)
+# define PF7 PORTF7
+#endif
+
+/* PORT G */
+
+#if defined(PG0) && !defined(PORTG0)
+# define PORTG0 PG0
+#elif defined(PORTG0) && !defined(PG0)
+# define PG0 PORTG0
+#endif
+#if defined(PG1) && !defined(PORTG1)
+# define PORTG1 PG1
+#elif defined(PORTG1) && !defined(PG1)
+# define PG1 PORTG1
+#endif
+#if defined(PG2) && !defined(PORTG2)
+# define PORTG2 PG2
+#elif defined(PORTG2) && !defined(PG2)
+# define PG2 PORTG2
+#endif
+#if defined(PG3) && !defined(PORTG3)
+# define PORTG3 PG3
+#elif defined(PORTG3) && !defined(PG3)
+# define PG3 PORTG3
+#endif
+#if defined(PG4) && !defined(PORTG4)
+# define PORTG4 PG4
+#elif defined(PORTG4) && !defined(PG4)
+# define PG4 PORTG4
+#endif
+#if defined(PG5) && !defined(PORTG5)
+# define PORTG5 PG5
+#elif defined(PORTG5) && !defined(PG5)
+# define PG5 PORTG5
+#endif
+#if defined(PG6) && !defined(PORTG6)
+# define PORTG6 PG6
+#elif defined(PORTG6) && !defined(PG6)
+# define PG6 PORTG6
+#endif
+#if defined(PG7) && !defined(PORTG7)
+# define PORTG7 PG7
+#elif defined(PORTG7) && !defined(PG7)
+# define PG7 PORTG7
+#endif
+
+/* PORT H */
+
+#if defined(PH0) && !defined(PORTH0)
+# define PORTH0 PH0
+#elif defined(PORTH0) && !defined(PH0)
+# define PH0 PORTH0
+#endif
+#if defined(PH1) && !defined(PORTH1)
+# define PORTH1 PH1
+#elif defined(PORTH1) && !defined(PH1)
+# define PH1 PORTH1
+#endif
+#if defined(PH2) && !defined(PORTH2)
+# define PORTH2 PH2
+#elif defined(PORTH2) && !defined(PH2)
+# define PH2 PORTH2
+#endif
+#if defined(PH3) && !defined(PORTH3)
+# define PORTH3 PH3
+#elif defined(PORTH3) && !defined(PH3)
+# define PH3 PORTH3
+#endif
+#if defined(PH4) && !defined(PORTH4)
+# define PORTH4 PH4
+#elif defined(PORTH4) && !defined(PH4)
+# define PH4 PORTH4
+#endif
+#if defined(PH5) && !defined(PORTH5)
+# define PORTH5 PH5
+#elif defined(PORTH5) && !defined(PH5)
+# define PH5 PORTH5
+#endif
+#if defined(PH6) && !defined(PORTH6)
+# define PORTH6 PH6
+#elif defined(PORTH6) && !defined(PH6)
+# define PH6 PORTH6
+#endif
+#if defined(PH7) && !defined(PORTH7)
+# define PORTH7 PH7
+#elif defined(PORTH7) && !defined(PH7)
+# define PH7 PORTH7
+#endif
+
+/* PORT J */
+
+#if defined(PJ0) && !defined(PORTJ0)
+# define PORTJ0 PJ0
+#elif defined(PORTJ0) && !defined(PJ0)
+# define PJ0 PORTJ0
+#endif
+#if defined(PJ1) && !defined(PORTJ1)
+# define PORTJ1 PJ1
+#elif defined(PORTJ1) && !defined(PJ1)
+# define PJ1 PORTJ1
+#endif
+#if defined(PJ2) && !defined(PORTJ2)
+# define PORTJ2 PJ2
+#elif defined(PORTJ2) && !defined(PJ2)
+# define PJ2 PORTJ2
+#endif
+#if defined(PJ3) && !defined(PORTJ3)
+# define PORTJ3 PJ3
+#elif defined(PORTJ3) && !defined(PJ3)
+# define PJ3 PORTJ3
+#endif
+#if defined(PJ4) && !defined(PORTJ4)
+# define PORTJ4 PJ4
+#elif defined(PORTJ4) && !defined(PJ4)
+# define PJ4 PORTJ4
+#endif
+#if defined(PJ5) && !defined(PORTJ5)
+# define PORTJ5 PJ5
+#elif defined(PORTJ5) && !defined(PJ5)
+# define PJ5 PORTJ5
+#endif
+#if defined(PJ6) && !defined(PORTJ6)
+# define PORTJ6 PJ6
+#elif defined(PORTJ6) && !defined(PJ6)
+# define PJ6 PORTJ6
+#endif
+#if defined(PJ7) && !defined(PORTJ7)
+# define PORTJ7 PJ7
+#elif defined(PORTJ7) && !defined(PJ7)
+# define PJ7 PORTJ7
+#endif
+
+/* PORT K */
+
+#if defined(PK0) && !defined(PORTK0)
+# define PORTK0 PK0
+#elif defined(PORTK0) && !defined(PK0)
+# define PK0 PORTK0
+#endif
+#if defined(PK1) && !defined(PORTK1)
+# define PORTK1 PK1
+#elif defined(PORTK1) && !defined(PK1)
+# define PK1 PORTK1
+#endif
+#if defined(PK2) && !defined(PORTK2)
+# define PORTK2 PK2
+#elif defined(PORTK2) && !defined(PK2)
+# define PK2 PORTK2
+#endif
+#if defined(PK3) && !defined(PORTK3)
+# define PORTK3 PK3
+#elif defined(PORTK3) && !defined(PK3)
+# define PK3 PORTK3
+#endif
+#if defined(PK4) && !defined(PORTK4)
+# define PORTK4 PK4
+#elif defined(PORTK4) && !defined(PK4)
+# define PK4 PORTK4
+#endif
+#if defined(PK5) && !defined(PORTK5)
+# define PORTK5 PK5
+#elif defined(PORTK5) && !defined(PK5)
+# define PK5 PORTK5
+#endif
+#if defined(PK6) && !defined(PORTK6)
+# define PORTK6 PK6
+#elif defined(PORTK6) && !defined(PK6)
+# define PK6 PORTK6
+#endif
+#if defined(PK7) && !defined(PORTK7)
+# define PORTK7 PK7
+#elif defined(PORTK7) && !defined(PK7)
+# define PK7 PORTK7
+#endif
+
+/* PORT L */
+
+#if defined(PL0) && !defined(PORTL0)
+# define PORTL0 PL0
+#elif defined(PORTL0) && !defined(PL0)
+# define PL0 PORTL0
+#endif
+#if defined(PL1) && !defined(PORTL1)
+# define PORTL1 PL1
+#elif defined(PORTL1) && !defined(PL1)
+# define PL1 PORTL1
+#endif
+#if defined(PL2) && !defined(PORTL2)
+# define PORTL2 PL2
+#elif defined(PORTL2) && !defined(PL2)
+# define PL2 PORTL2
+#endif
+#if defined(PL3) && !defined(PORTL3)
+# define PORTL3 PL3
+#elif defined(PORTL3) && !defined(PL3)
+# define PL3 PORTL3
+#endif
+#if defined(PL4) && !defined(PORTL4)
+# define PORTL4 PL4
+#elif defined(PORTL4) && !defined(PL4)
+# define PL4 PORTL4
+#endif
+#if defined(PL5) && !defined(PORTL5)
+# define PORTL5 PL5
+#elif defined(PORTL5) && !defined(PL5)
+# define PL5 PORTL5
+#endif
+#if defined(PL6) && !defined(PORTL6)
+# define PORTL6 PL6
+#elif defined(PORTL6) && !defined(PL6)
+# define PL6 PORTL6
+#endif
+#if defined(PL7) && !defined(PORTL7)
+# define PORTL7 PL7
+#elif defined(PORTL7) && !defined(PL7)
+# define PL7 PORTL7
+#endif
+
+#endif /* _AVR_PORTPINS_H_ */
diff --git a/cpukit/score/cpu/avr/avr/power.h b/cpukit/score/cpu/avr/avr/power.h
new file mode 100644
index 0000000000..f17166142a
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/power.h
@@ -0,0 +1,1475 @@
+/* Copyright (c) 2006, 2007, 2008 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_POWER_H_
+#define _AVR_POWER_H_ 1
+
+#include <avr/io.h>
+#include <stdint.h>
+
+
+/** \file */
+/** \defgroup avr_power <avr/power.h>: Power Reduction Management
+
+\code #include <avr/power.h>\endcode
+
+Many AVRs contain a Power Reduction Register (PRR) or Registers (PRRx) that
+allow you to reduce power consumption by disabling or enabling various on-board
+peripherals as needed.
+
+There are many macros in this header file that provide an easy interface
+to enable or disable on-board peripherals to reduce power. See the table below.
+
+\note Not all AVR devices have a Power Reduction Register (for example
+the ATmega128). On those devices without a Power Reduction Register, these
+macros are not available.
+
+\note Not all AVR devices contain the same peripherals (for example, the LCD
+interface), or they will be named differently (for example, USART and
+USART0). Please consult your device's datasheet, or the header file, to
+find out which macros are applicable to your device.
+
+*/
+
+
+/** \addtogroup avr_power
+
+\anchor avr_powermacros
+<small>
+<center>
+<table border="3">
+ <tr>
+ <td width="10%"><strong>Power Macro</strong></td>
+ <td width="15%"><strong>Description</strong></td>
+ <td width="75%"><strong>Applicable for device</strong></td>
+ </tr>
+
+ <tr>
+ <td>power_adc_enable()</td>
+ <td>Enable the Analog to Digital Converter module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_adc_disable()</td>
+ <td>Disable the Analog to Digital Converter module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_lcd_enable()</td>
+ <td>Enable the LCD module.</td>
+ <td>ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490</td>
+ </tr>
+
+ <tr>
+ <td>power_lcd_disable().</td>
+ <td>Disable the LCD module.</td>
+ <td>ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490</td>
+ </tr>
+
+ <tr>
+ <td>power_psc0_enable()</td>
+ <td>Enable the Power Stage Controller 0 module.</td>
+ <td>AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_psc0_disable()</td>
+ <td>Disable the Power Stage Controller 0 module.</td>
+ <td>AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_psc1_enable()</td>
+ <td>Enable the Power Stage Controller 1 module.</td>
+ <td>AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_psc1_disable()</td>
+ <td>Disable the Power Stage Controller 1 module.</td>
+ <td>AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_psc2_enable()</td>
+ <td>Enable the Power Stage Controller 2 module.</td>
+ <td>AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_psc2_disable()</td>
+ <td>Disable the Power Stage Controller 2 module.</td>
+ <td>AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_spi_enable()</td>
+ <td>Enable the Serial Peripheral Interface module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_spi_disable()</td>
+ <td>Disable the Serial Peripheral Interface module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_timer0_enable()</td>
+ <td>Enable the Timer 0 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM216, AT90PWM316, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_timer0_disable()</td>
+ <td>Disable the Timer 0 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_timer1_enable()</td>
+ <td>Enable the Timer 1 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_timer1_disable()</td>
+ <td>Disable the Timer 1 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_timer2_enable()</td>
+ <td>Enable the Timer 2 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_timer2_disable()</td>
+ <td>Disable the Timer 2 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_timer3_enable()</td>
+ <td>Enable the Timer 3 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287</td>
+ </tr>
+
+ <tr>
+ <td>power_timer3_disable()</td>
+ <td>Disable the Timer 3 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287</td>
+ </tr>
+
+ <tr>
+ <td>power_timer4_enable()</td>
+ <td>Enable the Timer 4 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_timer4_disable()</td>
+ <td>Disable the Timer 4 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_timer5_enable()</td>
+ <td>Enable the Timer 5 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_timer5_disable()</td>
+ <td>Disable the Timer 5 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_twi_enable()</td>
+ <td>Enable the Two Wire Interface module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_twi_disable()</td>
+ <td>Disable the Two Wire Interface module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_usart_enable()</td>
+ <td>Enable the USART module.</td>
+ <td>AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_usart_disable()</td>
+ <td>Disable the USART module.</td>
+ <td>AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B</td>
+ </tr>
+
+ <tr>
+ <td>power_usart0_enable()</td>
+ <td>Enable the USART 0 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_usart0_disable()</td>
+ <td>Disable the USART 0 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega48, ATmega88, ATmega168</td>
+ </tr>
+
+ <tr>
+ <td>power_usart1_enable()</td>
+ <td>Enable the USART 1 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATmega164P, ATmega324P</td>
+ </tr>
+
+ <tr>
+ <td>power_usart1_disable()</td>
+ <td>Disable the USART 1 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATmega164P, ATmega324P</td>
+ </tr>
+
+ <tr>
+ <td>power_usart2_enable()</td>
+ <td>Enable the USART 2 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_usart2_disable()</td>
+ <td>Disable the USART 2 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_usart3_enable()</td>
+ <td>Enable the USART 3 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_usart3_disable()</td>
+ <td>Disable the USART 3 module.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561</td>
+ </tr>
+
+ <tr>
+ <td>power_usb_enable()</td>
+ <td>Enable the USB module.</td>
+ <td>AT90USB646, AT90USB647, AT90USB1286, AT90USB1287</td>
+ </tr>
+
+ <tr>
+ <td>power_usb_disable()</td>
+ <td>Disable the USB module.</td>
+ <td>AT90USB646, AT90USB647, AT90USB1286, AT90USB1287</td>
+ </tr>
+
+ <tr>
+ <td>power_usi_enable()</td>
+ <td>Enable the Universal Serial Interface module.</td>
+ <td>ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_usi_disable()</td>
+ <td>Disable the Universal Serial Interface module.</td>
+ <td>ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_vadc_enable()</td>
+ <td>Enable the Voltage ADC module.</td>
+ <td>ATmega406</td>
+ </tr>
+
+ <tr>
+ <td>power_vadc_disable()</td>
+ <td>Disable the Voltage ADC module.</td>
+ <td>ATmega406</td>
+ </tr>
+
+ <tr>
+ <td>power_all_enable()</td>
+ <td>Enable all modules.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+
+ <tr>
+ <td>power_all_disable()</td>
+ <td>Disable all modules.</td>
+ <td>ATmega640, ATmega1280, ATmega1281, ATmega128RFA1, ATmega2560, ATmega2561, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, ATmega165, ATmega165P, ATmega325, ATmega3250, ATmega645, ATmega6450, ATmega169, ATmega169P, ATmega329, ATmega3290, ATmega649, ATmega6490, ATmega164P, ATmega324P, ATmega644, ATmega406, ATmega48, ATmega88, ATmega168, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861</td>
+ </tr>
+</table>
+</center>
+</small>
+
+@} */
+
+
+#if defined(__AVR_ATxmega16A4__) \
+|| defined(__AVR_ATxmega16D4__) \
+|| defined(__AVR_ATxmega32A4__) \
+|| defined(__AVR_ATxmega32D4__) \
+|| defined(__AVR_ATxmega64A1__) \
+|| defined(__AVR_ATxmega64A3__) \
+|| defined(__AVR_ATxmega64D3__) \
+|| defined(__AVR_ATxmega128A1__) \
+|| defined(__AVR_ATxmega128A3__) \
+|| defined(__AVR_ATxmega128D3__) \
+|| defined(__AVR_ATxmega192A3__) \
+|| defined(__AVR_ATxmega192D3__) \
+|| defined(__AVR_ATxmega256D3__) \
+|| defined(__AVR_ATxmega256A3__) \
+|| defined(__AVR_ATxmega256A3B__)
+
+/*
+#define power_aes_enable() (PR_PR &= (uint8_t)~(PR_AES_bm))
+#define power_aes_disable() (PR_PR |= (uint8_t)PR_AES_bm)
+*/
+
+#define power_ebi_enable() (PR_PR &= (uint8_t)~(PR_EBI_bm))
+#define power_ebi_disable() (PR_PR |= (uint8_t)PR_EBI_bm)
+
+#define power_rtc_enable() (PR_PR &= (uint8_t)~(PR_RTC_bm))
+#define power_rtc_disable() (PR_PR |= (uint8_t)PR_RTC_bm)
+
+#define power_evsys_enable() (PR_PR &= (uint8_t)~(PR_EVSYS_bm))
+#define power_evsys_disable() (PR_PR |= (uint8_t)PR_EVSYS_bm)
+
+#define power_dma_enable() (PR_PR &= (uint8_t)~(PR_DMA_bm))
+#define power_dma_disable() (PR_PR |= (uint8_t)PR_DMA_bm)
+
+#define power_daca_enable() (PR_PRPA &= (uint8_t)~(PR_DAC_bm))
+#define power_daca_disable() (PR_PRPA |= (uint8_t)PR_DAC_bm)
+#define power_dacb_enable() (PR_PRPB &= (uint8_t)~(PR_DAC_bm))
+#define power_dacb_disable() (PR_PRPB |= (uint8_t)PR_DAC_bm)
+
+#define power_adca_enable() (PR_PRPA &= (uint8_t)~(PR_ADC_bm))
+#define power_adca_disable() (PR_PRPA |= (uint8_t)PR_ADC_bm)
+#define power_adcb_enable() (PR_PRPB &= (uint8_t)~(PR_ADC_bm))
+#define power_adcb_disable() (PR_PRPB |= (uint8_t)PR_ADC_bm)
+
+#define power_aca_enable() (PR_PRPA &= (uint8_t)~(PR_AC_bm))
+#define power_aca_disable() (PR_PRPA |= (uint8_t)PR_AC_bm)
+#define power_acb_enable() (PR_PRPB &= (uint8_t)~(PR_AC_bm))
+#define power_acb_disable() (PR_PRPB |= (uint8_t)PR_AC_bm)
+
+#define power_twic_enable() (PR_PRPC &= (uint8_t)~(PR_TWI_bm))
+#define power_twic_disable() (PR_PRPC |= (uint8_t)PR_TWI_bm)
+#define power_twid_enable() (PR_PRPD &= (uint8_t)~(PR_TWI_bm))
+#define power_twid_disable() (PR_PRPD |= (uint8_t)PR_TWI_bm)
+#define power_twie_enable() (PR_PRPE &= (uint8_t)~(PR_TWI_bm))
+#define power_twie_disable() (PR_PRPE |= (uint8_t)PR_TWI_bm)
+#define power_twif_enable() (PR_PRPF &= (uint8_t)~(PR_TWI_bm))
+#define power_twif_disable() (PR_PRPF |= (uint8_t)PR_TWI_bm)
+
+#define power_usartc1_enable() (PR_PRPC &= (uint8_t)~(PR_USART1_bm))
+#define power_usartc1_disable() (PR_PRPC |= (uint8_t)PR_USART1_bm)
+#define power_usartd1_enable() (PR_PRPD &= (uint8_t)~(PR_USART1_bm))
+#define power_usartd1_disable() (PR_PRPD |= (uint8_t)PR_USART1_bm)
+#define power_usarte1_enable() (PR_PRPE &= (uint8_t)~(PR_USART1_bm))
+#define power_usarte1_disable() (PR_PRPE |= (uint8_t)PR_USART1_bm)
+#define power_usartf1_enable() (PR_PRPF &= (uint8_t)~(PR_USART1_bm))
+#define power_usartf1_disable() (PR_PRPF |= (uint8_t)PR_USART1_bm)
+
+#define power_usartc0_enable() (PR_PRPC &= (uint8_t)~(PR_USART0_bm))
+#define power_usartc0_disable() (PR_PRPC |= (uint8_t)PR_USART0_bm)
+#define power_usartd0_enable() (PR_PRPD &= (uint8_t)~(PR_USART0_bm))
+#define power_usartd0_disable() (PR_PRPD |= (uint8_t)PR_USART0_bm)
+#define power_usarte0_enable() (PR_PRPE &= (uint8_t)~(PR_USART0_bm))
+#define power_usarte0_disable() (PR_PRPE |= (uint8_t)PR_USART0_bm)
+#define power_usartf0_enable() (PR_PRPF &= (uint8_t)~(PR_USART0_bm))
+#define power_usartf0_disable() (PR_PRPF |= (uint8_t)PR_USART0_bm)
+
+#define power_spic_enable() (PR_PRPC &= (uint8_t)~(PR_SPI_bm))
+#define power_spic_disable() (PR_PRPC |= (uint8_t)PR_SPI_bm)
+#define power_spid_enable() (PR_PRPD &= (uint8_t)~(PR_SPI_bm))
+#define power_spid_disable() (PR_PRPD |= (uint8_t)PR_SPI_bm)
+#define power_spie_enable() (PR_PRPE &= (uint8_t)~(PR_SPI_bm))
+#define power_spie_disable() (PR_PRPE |= (uint8_t)PR_SPI_bm)
+#define power_spif_enable() (PR_PRPF &= (uint8_t)~(PR_SPI_bm))
+#define power_spif_disable() (PR_PRPF |= (uint8_t)PR_SPI_bm)
+
+#define power_hiresc_enable() (PR_PRPC &= (uint8_t)~(PR_HIRES_bm))
+#define power_hiresc_disable() (PR_PRPC |= (uint8_t)PR_HIRES_bm)
+#define power_hiresd_enable() (PR_PRPD &= (uint8_t)~(PR_HIRES_bm))
+#define power_hiresd_disable() (PR_PRPD |= (uint8_t)PR_HIRES_bm)
+#define power_hirese_enable() (PR_PRPE &= (uint8_t)~(PR_HIRES_bm))
+#define power_hirese_disable() (PR_PRPE |= (uint8_t)PR_HIRES_bm)
+#define power_hiresf_enable() (PR_PRPF &= (uint8_t)~(PR_HIRES_bm))
+#define power_hiresf_disable() (PR_PRPF |= (uint8_t)PR_HIRES_bm)
+
+#define power_tc1c_enable() (PR_PRPC &= (uint8_t)~(PR_TC1_bm))
+#define power_tc1c_disable() (PR_PRPC |= (uint8_t)PR_TC1_bm)
+#define power_tc1d_enable() (PR_PRPD &= (uint8_t)~(PR_TC1_bm))
+#define power_tc1d_disable() (PR_PRPD |= (uint8_t)PR_TC1_bm)
+#define power_tc1e_enable() (PR_PRPE &= (uint8_t)~(PR_TC1_bm))
+#define power_tc1e_disable() (PR_PRPE |= (uint8_t)PR_TC1_bm)
+#define power_tc1f_enable() (PR_PRPF &= (uint8_t)~(PR_TC1_bm))
+#define power_tc1f_disable() (PR_PRPF |= (uint8_t)PR_TC1_bm)
+
+#define power_tc0c_enable() (PR_PRPC &= (uint8_t)~(PR_TC0_bm))
+#define power_tc0c_disable() (PR_PRPC |= (uint8_t)PR_TC0_bm)
+#define power_tc0d_enable() (PR_PRPD &= (uint8_t)~(PR_TC0_bm))
+#define power_tc0d_disable() (PR_PRPD |= (uint8_t)PR_TC0_bm)
+#define power_tc0e_enable() (PR_PRPE &= (uint8_t)~(PR_TC0_bm))
+#define power_tc0e_disable() (PR_PRPE |= (uint8_t)PR_TC0_bm)
+#define power_tc0f_enable() (PR_PRPF &= (uint8_t)~(PR_TC0_bm))
+#define power_tc0f_disable() (PR_PRPF |= (uint8_t)PR_TC0_bm)
+
+#define power_all_enable() \
+do { \
+ /* PR_PR &= (uint8_t)~(PR_AES_bm|PR_EBI_bm|PR_RTC_bm|PR_EVSYS_bm|PR_DMA_bm); */ \
+ PR_PR &= (uint8_t)~(PR_EBI_bm|PR_RTC_bm|PR_EVSYS_bm|PR_DMA_bm); \
+ PR_PRPA &= (uint8_t)~(PR_DAC_bm|PR_ADC_bm|PR_AC_bm); \
+ PR_PRPB &= (uint8_t)~(PR_DAC_bm|PR_ADC_bm|PR_AC_bm); \
+ PR_PRPC &= (uint8_t)~(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+ PR_PRPD &= (uint8_t)~(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+ PR_PRPE &= (uint8_t)~(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+ PR_PRPF &= (uint8_t)~(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+} while(0)
+
+
+#define power_all_disable() \
+do { \
+ /* PM_PR_PR |= (uint8_t)(PR_AES_bm|PR_EBI_bm|PR_RTC_bm|PR_EVSYS_bm|PR_DMA_bm); */ \
+ PR_PR |= (uint8_t)(PR_EBI_bm|PR_RTC_bm|PR_EVSYS_bm|PR_DMA_bm); \
+ PR_PRPA |= (uint8_t)(PR_DAC_bm|PR_ADC_bm|PR_AC_bm); \
+ PR_PRPB |= (uint8_t)(PR_DAC_bm|PR_ADC_bm|PR_AC_bm); \
+ PR_PRPC |= (uint8_t)(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+ PR_PRPD |= (uint8_t)(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+ PR_PRPE |= (uint8_t)(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+ PR_PRPF |= (uint8_t)(PR_TWI_bm|PR_USART1_bm|PR_USART0_bm|PR_SPI_bm|PR_HIRES_bm|PR_TC1_bm|PR_TC0_bm); \
+} while(0)
+
+
+#elif defined(__AVR_ATmega640__) \
+|| defined(__AVR_ATmega1280__) \
+|| defined(__AVR_ATmega1281__) \
+|| defined(__AVR_ATmega2560__) \
+|| defined(__AVR_ATmega2561__)
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
+#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
+
+#define power_timer4_enable() (PRR1 &= (uint8_t)~(1 << PRTIM4))
+#define power_timer4_disable() (PRR1 |= (uint8_t)(1 << PRTIM4))
+
+#define power_timer5_enable() (PRR1 &= (uint8_t)~(1 << PRTIM5))
+#define power_timer5_disable() (PRR1 |= (uint8_t)(1 << PRTIM5))
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
+
+#define power_usart2_enable() (PRR1 &= (uint8_t)~(1 << PRUSART2))
+#define power_usart2_disable() (PRR1 |= (uint8_t)(1 << PRUSART2))
+
+#define power_usart3_enable() (PRR1 &= (uint8_t)~(1 << PRUSART3))
+#define power_usart3_disable() (PRR1 |= (uint8_t)(1 << PRUSART3))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRUSART0)); \
+ PRR1 &= (uint8_t)~((1<<PRTIM3)|(1<<PRTIM4)|(1<<PRTIM5)|(1<<PRTIM5)|(1<<PRUSART1)|(1<<PRUSART2)|(1<<PRUSART3)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRUSART0)); \
+ PRR1 |= (uint8_t)((1<<PRTIM3)|(1<<PRTIM4)|(1<<PRTIM5)|(1<<PRTIM5)|(1<<PRUSART1)|(1<<PRUSART2)|(1<<PRUSART3)); \
+}while(0)
+
+
+#elif defined(__AVR_ATmega128RFA1__)
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
+#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
+
+#define power_timer4_enable() (PRR1 &= (uint8_t)~(1 << PRTIM4))
+#define power_timer4_disable() (PRR1 |= (uint8_t)(1 << PRTIM4))
+
+#define power_timer5_enable() (PRR1 &= (uint8_t)~(1 << PRTIM5))
+#define power_timer5_disable() (PRR1 |= (uint8_t)(1 << PRTIM5))
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRUSART0)); \
+ PRR1 &= (uint8_t)~((1<<PRTIM3)|(1<<PRTIM4)|(1<<PRTIM5)|(1<<PRTIM5)|(1<<PRUSART1)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRUSART0)); \
+ PRR1 |= (uint8_t)((1<<PRTIM3)|(1<<PRTIM4)|(1<<PRTIM5)|(1<<PRTIM5)|(1<<PRUSART1)); \
+}while(0)
+
+
+#elif defined(__AVR_AT90USB646__) \
+|| defined(__AVR_AT90USB647__) \
+|| defined(__AVR_AT90USB1286__) \
+|| defined(__AVR_AT90USB1287__)
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
+#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
+
+#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
+
+#define power_usb_enable() (PRR1 &= (uint8_t)~(1 << PRUSB))
+#define power_usb_disable() (PRR1 |= (uint8_t)(1 << PRUSB))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)); \
+ PRR1 &= (uint8_t)~((1<<PRTIM3)|(1<<PRUSART1)|(1<<PRUSB)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)); \
+ PRR1 |= (uint8_t)((1<<PRTIM3)|(1<<PRUSART1)|(1<<PRUSB)); \
+}while(0)
+
+
+#elif defined(__AVR_ATmega32U4__) \
+|| defined(__AVR_ATmega16U4__)
+
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
+#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
+
+#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
+
+#define power_usb_enable() (PRR1 &= (uint8_t)~(1 << PRUSB))
+#define power_usb_disable() (PRR1 |= (uint8_t)(1 << PRUSB))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRUSART0)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)); \
+ PRR1 &= (uint8_t)~((1<<PRTIM3)|(1<<PRUSART1)|(1<<PRUSB)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRUSART0)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)); \
+ PRR1 |= (uint8_t)((1<<PRTIM3)|(1<<PRUSART1)|(1<<PRUSB)); \
+}while(0)
+
+
+#elif defined(__AVR_ATmega32U6__)
+
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
+#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
+
+#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
+
+#define power_usb_enable() (PRR1 &= (uint8_t)~(1 << PRUSB))
+#define power_usb_disable() (PRR1 |= (uint8_t)(1 << PRUSB))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)); \
+ PRR1 &= (uint8_t)~((1<<PRTIM3)|(1<<PRUSART1)|(1<<PRUSB)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)); \
+ PRR1 |= (uint8_t)((1<<PRTIM3)|(1<<PRUSART1)|(1<<PRUSB)); \
+}while(0)
+
+
+#elif defined(__AVR_AT90PWM1__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+/* Power Stage Controller 0 */
+#define power_psc0_enable() (PRR &= (uint8_t)~(1 << PRPSC0))
+#define power_psc0_disable() (PRR |= (uint8_t)(1 << PRPSC0))
+
+/* Power Stage Controller 1 */
+#define power_psc1_enable() (PRR &= (uint8_t)~(1 << PRPSC1))
+#define power_psc1_disable() (PRR |= (uint8_t)(1 << PRPSC1))
+
+/* Power Stage Controller 2 */
+#define power_psc2_enable() (PRR &= (uint8_t)~(1 << PRPSC2))
+#define power_psc2_disable() (PRR |= (uint8_t)(1 << PRPSC2))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRPSC0)|(1<<PRPSC1)|(1<<PRPSC2)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRPSC0)|(1<<PRPSC1)|(1<<PRPSC2)))
+
+
+#elif defined(__AVR_AT90PWM2__) \
+|| defined(__AVR_AT90PWM2B__) \
+|| defined(__AVR_AT90PWM3__) \
+|| defined(__AVR_AT90PWM3B__) \
+|| defined(__AVR_AT90PWM216__) \
+|| defined(__AVR_AT90PWM316__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_usart_enable() (PRR &= (uint8_t)~(1 << PRUSART))
+#define power_usart_disable() (PRR |= (uint8_t)(1 << PRUSART))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+/* Power Stage Controller 0 */
+#define power_psc0_enable() (PRR &= (uint8_t)~(1 << PRPSC0))
+#define power_psc0_disable() (PRR |= (uint8_t)(1 << PRPSC0))
+
+/* Power Stage Controller 1 */
+#define power_psc1_enable() (PRR &= (uint8_t)~(1 << PRPSC1))
+#define power_psc1_disable() (PRR |= (uint8_t)(1 << PRPSC1))
+
+/* Power Stage Controller 2 */
+#define power_psc2_enable() (PRR &= (uint8_t)~(1 << PRPSC2))
+#define power_psc2_disable() (PRR |= (uint8_t)(1 << PRPSC2))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRPSC0)|(1<<PRPSC1)|(1<<PRPSC2)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRPSC0)|(1<<PRPSC1)|(1<<PRPSC2)))
+
+
+#elif defined(__AVR_AT90PWM81__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+/* Power Stage Controller 0 */
+#define power_psc0_enable() (PRR &= (uint8_t)~(1 << PRPSC0))
+#define power_psc0_disable() (PRR |= (uint8_t)(1 << PRPSC0))
+
+/* Power Stage Controller 2 */
+#define power_psc2_enable() (PRR &= (uint8_t)~(1 << PRPSC2))
+#define power_psc2_disable() (PRR |= (uint8_t)(1 << PRPSC2))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTIM1)|(1<<PRPSC0)|(1<<PRPSC2)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTIM1)|(1<<PRPSC0)|(1<<PRPSC2)))
+
+
+#elif defined(__AVR_ATmega165__) \
+|| defined(__AVR_ATmega165A__) \
+|| defined(__AVR_ATmega165P__) \
+|| defined(__AVR_ATmega325__) \
+|| defined(__AVR_ATmega3250__) \
+|| defined(__AVR_ATmega645__) \
+|| defined(__AVR_ATmega645A__) \
+|| defined(__AVR_ATmega645P__) \
+|| defined(__AVR_ATmega6450__) \
+|| defined(__AVR_ATmega6450A__) \
+|| defined(__AVR_ATmega6450P__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_usart0_enable() (PRR &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR |= (uint8_t)(1 << PRUSART0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM1)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM1)))
+
+
+#elif defined(__AVR_ATmega169__) \
+|| defined(__AVR_ATmega169A__) \
+|| defined(__AVR_ATmega169P__) \
+|| defined(__AVR_ATmega169PA__) \
+|| defined(__AVR_ATmega329__) \
+|| defined(__AVR_ATmega329P__) \
+|| defined(__AVR_ATmega329PA__) \
+|| defined(__AVR_ATmega3290__) \
+|| defined(__AVR_ATmega3290P__) \
+|| defined(__AVR_ATmega649__) \
+|| defined(__AVR_ATmega649A__) \
+|| defined(__AVR_ATmega649P__) \
+|| defined(__AVR_ATmega6490__) \
+|| defined(__AVR_ATmega6490A__) \
+|| defined(__AVR_ATmega6490P__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_usart0_enable() (PRR &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR |= (uint8_t)(1 << PRUSART0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+#define power_lcd_enable() (PRR &= (uint8_t)~(1 << PRLCD))
+#define power_lcd_disable() (PRR |= (uint8_t)(1 << PRLCD))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM1)|(1<<PRLCD)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM1)|(1<<PRLCD)))
+
+
+#elif defined(__AVR_ATmega164A__) \
+|| defined(__AVR_ATmega164P__) \
+|| defined(__AVR_ATmega324A__) \
+|| defined(__AVR_ATmega324P__) \
+|| defined(__AVR_ATmega324PA__)
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR0 |= (uint8_t)(1 << PRUSART1))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_all_enable() (PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRUSART1)|(1<<PRTIM0)|(1<<PRTIM2)|(1<<PRTWI)))
+#define power_all_disable() (PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRUSART1)|(1<<PRTIM0)|(1<<PRTIM2)|(1<<PRTWI)))
+
+
+#elif defined(__AVR_ATmega644__) \
+|| defined(__AVR_ATmega644A__) \
+|| defined(__AVR_ATmega644P__)
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_all_enable() (PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRTWI)))
+#define power_all_disable() (PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRTWI)))
+
+
+#elif defined(__AVR_ATmega406__)
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+/* Voltage ADC */
+#define power_vadc_enable() (PRR0 &= (uint8_t)~(1 << PRVADC))
+#define power_vadc_disable() (PRR0 |= (uint8_t)(1 << PRVADC))
+
+#define power_all_enable() (PRR0 &= (uint8_t)~((1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRVADC)))
+#define power_all_disable() (PRR0 |= (uint8_t)((1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRVADC)))
+
+
+#elif defined(__AVR_ATmega48__) \
+|| defined(__AVR_ATmega48A__) \
+|| defined(__AVR_ATmega48P__) \
+|| defined(__AVR_ATmega88__) \
+|| defined(__AVR_ATmega88A__) \
+|| defined(__AVR_ATmega88P__) \
+|| defined(__AVR_ATmega88PA__) \
+|| defined(__AVR_ATmega168__) \
+|| defined(__AVR_ATmega168A__) \
+|| defined(__AVR_ATmega168P__) \
+|| defined(__AVR_ATmega328__) \
+|| defined(__AVR_ATmega328P__) \
+|| defined(__AVR_ATtiny48__) \
+|| defined(__AVR_ATtiny88__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_usart0_enable() (PRR &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR |= (uint8_t)(1 << PRUSART0))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR |= (uint8_t)(1 << PRTIM2))
+
+#define power_twi_enable() (PRR &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR |= (uint8_t)(1 << PRTWI))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRTWI)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRTWI)))
+
+
+#elif defined(__AVR_ATtiny24__) \
+|| defined(__AVR_ATtiny24A__) \
+|| defined(__AVR_ATtiny44__) \
+|| defined(__AVR_ATtiny44A__) \
+|| defined(__AVR_ATtiny84__) \
+|| defined(__AVR_ATtiny25__) \
+|| defined(__AVR_ATtiny45__) \
+|| defined(__AVR_ATtiny85__) \
+|| defined(__AVR_ATtiny261__) \
+|| defined(__AVR_ATtiny261A__) \
+|| defined(__AVR_ATtiny461__) \
+|| defined(__AVR_ATtiny461A__) \
+|| defined(__AVR_ATtiny861__) \
+|| defined(__AVR_ATtiny861A__) \
+|| defined(__AVR_ATtiny43U__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+/* Universal Serial Interface */
+#define power_usi_enable() (PRR &= (uint8_t)~(1 << PRUSI))
+#define power_usi_disable() (PRR |= (uint8_t)(1 << PRUSI))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRUSI)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRUSI)))
+
+
+#elif defined(__AVR_ATmega1284P__)
+
+
+#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
+#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR0 |= (uint8_t)(1 << PRUSART1))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRUSART0)|(1<<PRUSART1)); \
+ PRR1 &= (uint8_t)~(1<<PRTIM3); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRADC)|(1<<PRSPI)|(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRTIM2)|(1<<PRUSART0)|(1<<PRUSART1)); \
+ PRR1 |= (uint8_t)(1<<PRTIM3); \
+}while(0)
+
+
+#elif defined(__AVR_ATmega32HVB__)
+
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+/* Voltage ADC */
+#define power_vadc_enable() (PRR0 &= (uint8_t)~(1 << PRVADC))
+#define power_vadc_disable() (PRR0 |= (uint8_t)(1 << PRVADC))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_vrm_enable() (PRR0 &= (uint8_t)~(1 << PRVRM))
+#define power_vrm_disable() (PRR0 |= (uint8_t)(1 << PRVRM))
+
+#define power_all_enable() (PRR0 &= (uint8_t)~((1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRVADC)|(1<<PRSPI)|(1<<PRVRM)))
+#define power_all_disable() (PRR0 |= (uint8_t)((1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRVADC)|(1<<PRSPI)|(1<<PRVRM)))
+
+
+#elif defined(__AVR_ATmega16M1__) \
+|| defined(__AVR_ATmega32C1__) \
+|| defined(__AVR_ATmega32M1__) \
+|| defined(__AVR_ATmega64C1__) \
+|| defined(__AVR_ATmega64M1__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_lin_enable() (PRR &= (uint8_t)~(1 << PRLIN))
+#define power_lin_disable() (PRR |= (uint8_t)(1 << PRLIN))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+#define power_psc_enable() (PRR &= (uint8_t)~(1 << PRPSC))
+#define power_psc_disable() (PRR |= (uint8_t)(1 << PRPSC))
+
+#define power_can_enable() (PRR &= (uint8_t)~(1 << PRCAN))
+#define power_can_disable() (PRR |= (uint8_t)(1 << PRCAN))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRLIN)|(1<<PRSPI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRPSC)|(1<<PRCAN)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRLIN)|(1<<PRSPI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRPSC)|(1<<PRCAN)))
+
+
+#elif defined(__AVR_ATtiny167__) \
+|| defined(__AVR_ATtiny87__)
+
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_usi_enable() (PRR &= (uint8_t)~(1 << PRUSI))
+#define power_usi_disable() (PRR |= (uint8_t)(1 << PRUSI))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
+
+#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
+
+#define power_lin_enable() (PRR &= (uint8_t)~(1 << PRLIN))
+#define power_lin_disable() (PRR |= (uint8_t)(1 << PRLIN))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRUSI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRSPI)|(1<<PRLIN)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRUSI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRSPI)|(1<<PRLIN)))
+
+
+#elif defined(__AVR_AT90USB82__) \
+|| defined(__AVR_AT90USB162__) \
+|| defined(__AVR_ATmega8U2__) \
+|| defined(__AVR_ATmega16U2__) \
+|| defined(__AVR_ATmega32U2__)
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_usb_enable() (PRR1 &= (uint8_t)~(1 << PRUSB))
+#define power_usb_disable() (PRR1 |= (uint8_t)(1 << PRUSB))
+
+#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
+#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRSPI)|(1<<PRTIM0)|(1<<PRTIM1)); \
+ PRR1 &= (uint8_t)~((1<<PRUSB)|(1<<PRUSART1)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRSPI)|(1<<PRTIM0)|(1<<PRTIM1)); \
+ PRR1 |= (uint8_t)((1<<PRUSB)|(1<<PRUSART1)); \
+}while(0)
+
+
+#elif defined(__AVR_AT90SCR100__)
+
+#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
+#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
+
+#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
+#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
+
+#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
+#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
+
+#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
+
+#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
+#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
+
+#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
+#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
+
+#define power_usbh_enable() (PRR1 &= (uint8_t)~(1 << PRUSBH))
+#define power_usbh_disable() (PRR1 |= (uint8_t)(1 << PRUSBH))
+
+#define power_usb_enable() (PRR1 &= (uint8_t)~(1 << PRUSB))
+#define power_usb_disable() (PRR1 |= (uint8_t)(1 << PRUSB))
+
+#define power_hsspi_enable() (PRR1 &= (uint8_t)~(1 << PRHSSPI))
+#define power_hsspi_disable() (PRR1 |= (uint8_t)(1 << PRHSSPI))
+
+#define power_sci_enable() (PRR1 &= (uint8_t)~(1 << PRSCI))
+#define power_sci_disable() (PRR1 |= (uint8_t)(1 << PRSCI))
+
+#define power_aes_enable() (PRR1 &= (uint8_t)~(1 << PRAES))
+#define power_aes_disable() (PRR1 |= (uint8_t)(1 << PRAES))
+
+#define power_kb_enable() (PRR1 &= (uint8_t)~(1 << PRKB))
+#define power_kb_disable() (PRR1 |= (uint8_t)(1 << PRKB))
+
+#define power_all_enable() \
+do{ \
+ PRR0 &= (uint8_t)~((1<<PRUSART0)|(1<<PRSPI)|(1<<PRTIM1)|(1<<PRTIM0)|(1<<PRTIM2)|(1<<PRTWI)); \
+ PRR1 &= (uint8_t)~((1<<PRUSBH)|(1<<PRUSB)|(1<<PRHSSPI)|(1<<PRSCI)|(1<<PRAES)|(1<<PRKB)); \
+}while(0)
+
+#define power_all_disable() \
+do{ \
+ PRR0 |= (uint8_t)((1<<PRUSART0)|(1<<PRSPI)|(1<<PRTIM1)|(1<<PRTIM0)|(1<<PRTIM2)|(1<<PRTWI)); \
+ PRR1 |= (uint8_t)((1<<PRUSBH)|(1<<PRUSB)|(1<<PRHSSPI)|(1<<PRSCI)|(1<<PRAES)|(1<<PRKB)); \
+}while(0)
+
+
+#elif defined(__AVR_ATtiny13A__)
+
+#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
+#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
+
+#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
+#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
+
+#define power_all_enable() (PRR &= (uint8_t)~((1<<PRADC)|(1<<PRTIM0)))
+#define power_all_disable() (PRR |= (uint8_t)((1<<PRADC)|(1<<PRTIM0)))
+
+#endif
+
+
+#if defined(__AVR_AT90CAN32__) \
+|| defined(__AVR_AT90CAN64__) \
+|| defined(__AVR_AT90CAN128__) \
+|| defined(__AVR_AT90PWM1__) \
+|| defined(__AVR_AT90PWM2__) \
+|| defined(__AVR_AT90PWM2B__) \
+|| defined(__AVR_AT90PWM3__) \
+|| defined(__AVR_AT90PWM3B__) \
+|| defined(__AVR_AT90PWM216__) \
+|| defined(__AVR_AT90PWM316__) \
+|| defined(__AVR_AT90SCR100__) \
+|| defined(__AVR_AT90USB646__) \
+|| defined(__AVR_AT90USB647__) \
+|| defined(__AVR_AT90USB82__) \
+|| defined(__AVR_AT90USB1286__) \
+|| defined(__AVR_AT90USB1287__) \
+|| defined(__AVR_AT90USB162__) \
+|| defined(__AVR_ATmega1280__) \
+|| defined(__AVR_ATmega1281__) \
+|| defined(__AVR_ATmega128RFA1__) \
+|| defined(__AVR_ATmega1284P__) \
+|| defined(__AVR_ATmega162__) \
+|| defined(__AVR_ATmega164A__) \
+|| defined(__AVR_ATmega164P__) \
+|| defined(__AVR_ATmega165__) \
+|| defined(__AVR_ATmega165A__) \
+|| defined(__AVR_ATmega165P__) \
+|| defined(__AVR_ATmega168__) \
+|| defined(__AVR_ATmega168P__) \
+|| defined(__AVR_ATmega169__) \
+|| defined(__AVR_ATmega169A__) \
+|| defined(__AVR_ATmega169P__) \
+|| defined(__AVR_ATmega169PA__) \
+|| defined(__AVR_ATmega16U4__) \
+|| defined(__AVR_ATmega2560__) \
+|| defined(__AVR_ATmega2561__) \
+|| defined(__AVR_ATmega324A__) \
+|| defined(__AVR_ATmega324P__) \
+|| defined(__AVR_ATmega325__) \
+|| defined(__AVR_ATmega3250__) \
+|| defined(__AVR_ATmega328P__) \
+|| defined(__AVR_ATmega329__) \
+|| defined(__AVR_ATmega329P__) \
+|| defined(__AVR_ATmega329PA__) \
+|| defined(__AVR_ATmega3290__) \
+|| defined(__AVR_ATmega32C1__) \
+|| defined(__AVR_ATmega32HVB__) \
+|| defined(__AVR_ATmega32M1__) \
+|| defined(__AVR_ATmega32U4__) \
+|| defined(__AVR_ATmega32U6__) \
+|| defined(__AVR_ATmega48__) \
+|| defined(__AVR_ATmega48P__) \
+|| defined(__AVR_ATmega640__) \
+|| defined(__AVR_ATmega649P__) \
+|| defined(__AVR_ATmega644__) \
+|| defined(__AVR_ATmega644A__) \
+|| defined(__AVR_ATmega644P__) \
+|| defined(__AVR_ATmega644PA__) \
+|| defined(__AVR_ATmega645__) \
+|| defined(__AVR_ATmega645A__) \
+|| defined(__AVR_ATmega645P__) \
+|| defined(__AVR_ATmega6450__) \
+|| defined(__AVR_ATmega6450A__) \
+|| defined(__AVR_ATmega6450P__) \
+|| defined(__AVR_ATmega649__) \
+|| defined(__AVR_ATmega649A__) \
+|| defined(__AVR_ATmega6490__) \
+|| defined(__AVR_ATmega6490A__) \
+|| defined(__AVR_ATmega6490P__) \
+|| defined(__AVR_ATmega88__) \
+|| defined(__AVR_ATmega88P__) \
+|| defined(__AVR_ATtiny48__) \
+|| defined(__AVR_ATtiny167__) \
+|| defined(__DOXYGEN__)
+
+
+/** \addtogroup avr_power
+
+Some of the newer AVRs contain a System Clock Prescale Register (CLKPR) that
+allows you to decrease the system clock frequency and the power consumption
+when the need for processing power is low. Below are two macros and an
+enumerated type that can be used to interface to the Clock Prescale Register.
+
+\note Not all AVR devices have a Clock Prescale Register. On those devices
+without a Clock Prescale Register, these macros are not available.
+*/
+
+
+/** \addtogroup avr_power
+\code
+typedef enum
+{
+ clock_div_1 = 0,
+ clock_div_2 = 1,
+ clock_div_4 = 2,
+ clock_div_8 = 3,
+ clock_div_16 = 4,
+ clock_div_32 = 5,
+ clock_div_64 = 6,
+ clock_div_128 = 7,
+ clock_div_256 = 8,
+ clock_div_1_rc = 15, // ATmega128RFA1 only
+} clock_div_t;
+\endcode
+Clock prescaler setting enumerations.
+
+*/
+typedef enum
+{
+ clock_div_1 = 0,
+ clock_div_2 = 1,
+ clock_div_4 = 2,
+ clock_div_8 = 3,
+ clock_div_16 = 4,
+ clock_div_32 = 5,
+ clock_div_64 = 6,
+ clock_div_128 = 7,
+ clock_div_256 = 8,
+#if defined(__AVR_ATmega128RFA1__)
+ clock_div_1_rc = 15,
+#endif
+} clock_div_t;
+
+
+static __inline__ void clock_prescale_set(clock_div_t) __attribute__((__always_inline__));
+
+/** \addtogroup avr_power
+\code clock_prescale_set(x) \endcode
+
+Set the clock prescaler register select bits, selecting a system clock
+division setting. This function is inlined, even if compiler
+optimizations are disabled.
+
+The type of x is clock_div_t.
+*/
+void clock_prescale_set(clock_div_t __x)
+{
+ uint8_t __tmp = _BV(CLKPCE);
+ __asm__ __volatile__ (
+ "in __tmp_reg__,__SREG__" "\n\t"
+ "cli" "\n\t"
+ "sts %1, %0" "\n\t"
+ "sts %1, %2" "\n\t"
+ "out __SREG__, __tmp_reg__"
+ : /* no outputs */
+ : "d" (__tmp),
+ "M" (_SFR_MEM_ADDR(CLKPR)),
+ "d" (__x)
+ : "r0");
+}
+
+/** \addtogroup avr_power
+\code clock_prescale_get() \endcode
+Gets and returns the clock prescaler register setting. The return type is clock_div_t.
+
+*/
+#define clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
+
+
+#elif defined(__AVR_ATtiny24__) \
+|| defined(__AVR_ATtiny24A__) \
+|| defined(__AVR_ATtiny44__) \
+|| defined(__AVR_ATtiny44A__) \
+|| defined(__AVR_ATtiny84__) \
+|| defined(__AVR_ATtiny25__) \
+|| defined(__AVR_ATtiny45__) \
+|| defined(__AVR_ATtiny85__) \
+|| defined(__AVR_ATtiny261A__) \
+|| defined(__AVR_ATtiny261__) \
+|| defined(__AVR_ATtiny461__) \
+|| defined(__AVR_ATtiny461A__) \
+|| defined(__AVR_ATtiny861__) \
+|| defined(__AVR_ATtiny861A__) \
+|| defined(__AVR_ATtiny2313__) \
+|| defined(__AVR_ATtiny2313A__) \
+|| defined(__AVR_ATtiny4313__) \
+|| defined(__AVR_ATtiny13__) \
+|| defined(__AVR_ATtiny13A__) \
+|| defined(__AVR_ATtiny43U__) \
+
+typedef enum
+{
+ clock_div_1 = 0,
+ clock_div_2 = 1,
+ clock_div_4 = 2,
+ clock_div_8 = 3,
+ clock_div_16 = 4,
+ clock_div_32 = 5,
+ clock_div_64 = 6,
+ clock_div_128 = 7,
+ clock_div_256 = 8
+} clock_div_t;
+
+
+void clock_prescale_set(clock_div_t __x)
+{
+ uint8_t __tmp = _BV(CLKPCE);
+ __asm__ __volatile__ (
+ "in __tmp_reg__,__SREG__" "\n\t"
+ "cli" "\n\t"
+ "out %1, %0" "\n\t"
+ "out %1, %2" "\n\t"
+ "out __SREG__, __tmp_reg__"
+ : /* no outputs */
+ : "d" (__tmp),
+ "I" (_SFR_IO_ADDR(CLKPR)),
+ "d" (__x)
+ : "r0");
+}
+
+
+#define clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
+
+
+#endif
+
+
+
+
+#endif /* _AVR_POWER_H_ */
diff --git a/cpukit/score/cpu/avr/avr/sfr_defs.h b/cpukit/score/cpu/avr/avr/sfr_defs.h
new file mode 100644
index 0000000000..2f355721fe
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/sfr_defs.h
@@ -0,0 +1,269 @@
+/* Copyright (c) 2002, Marek Michalkiewicz <marekm@amelek.gda.pl>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* avr/sfr_defs.h - macros for accessing AVR special function registers */
+
+/* $Id$ */
+
+#ifndef _AVR_SFR_DEFS_H_
+#define _AVR_SFR_DEFS_H_ 1
+
+/** \defgroup avr_sfr_notes Additional notes from <avr/sfr_defs.h>
+ \ingroup avr_sfr
+
+ The \c <avr/sfr_defs.h> file is included by all of the \c <avr/ioXXXX.h>
+ files, which use macros defined here to make the special function register
+ definitions look like C variables or simple constants, depending on the
+ <tt>_SFR_ASM_COMPAT</tt> define. Some examples from \c <avr/iocanxx.h> to
+ show how to define such macros:
+
+\code
+#define PORTA _SFR_IO8(0x02)
+#define EEAR _SFR_IO16(0x21)
+#define UDR0 _SFR_MEM8(0xC6)
+#define TCNT3 _SFR_MEM16(0x94)
+#define CANIDT _SFR_MEM32(0xF0)
+\endcode
+
+ If \c _SFR_ASM_COMPAT is not defined, C programs can use names like
+ <tt>PORTA</tt> directly in C expressions (also on the left side of
+ assignment operators) and GCC will do the right thing (use short I/O
+ instructions if possible). The \c __SFR_OFFSET definition is not used in
+ any way in this case.
+
+ Define \c _SFR_ASM_COMPAT as 1 to make these names work as simple constants
+ (addresses of the I/O registers). This is necessary when included in
+ preprocessed assembler (*.S) source files, so it is done automatically if
+ \c __ASSEMBLER__ is defined. By default, all addresses are defined as if
+ they were memory addresses (used in \c lds/sts instructions). To use these
+ addresses in \c in/out instructions, you must subtract 0x20 from them.
+
+ For more backwards compatibility, insert the following at the start of your
+ old assembler source file:
+
+\code
+#define __SFR_OFFSET 0
+\endcode
+
+ This automatically subtracts 0x20 from I/O space addresses, but it's a
+ hack, so it is recommended to change your source: wrap such addresses in
+ macros defined here, as shown below. After this is done, the
+ <tt>__SFR_OFFSET</tt> definition is no longer necessary and can be removed.
+
+ Real example - this code could be used in a boot loader that is portable
+ between devices with \c SPMCR at different addresses.
+
+\verbatim
+<avr/iom163.h>: #define SPMCR _SFR_IO8(0x37)
+<avr/iom128.h>: #define SPMCR _SFR_MEM8(0x68)
+\endverbatim
+
+\code
+#if _SFR_IO_REG_P(SPMCR)
+ out _SFR_IO_ADDR(SPMCR), r24
+#else
+ sts _SFR_MEM_ADDR(SPMCR), r24
+#endif
+\endcode
+
+ You can use the \c in/out/cbi/sbi/sbic/sbis instructions, without the
+ <tt>_SFR_IO_REG_P</tt> test, if you know that the register is in the I/O
+ space (as with \c SREG, for example). If it isn't, the assembler will
+ complain (I/O address out of range 0...0x3f), so this should be fairly
+ safe.
+
+ If you do not define \c __SFR_OFFSET (so it will be 0x20 by default), all
+ special register addresses are defined as memory addresses (so \c SREG is
+ 0x5f), and (if code size and speed are not important, and you don't like
+ the ugly \#if above) you can always use lds/sts to access them. But, this
+ will not work if <tt>__SFR_OFFSET</tt> != 0x20, so use a different macro
+ (defined only if <tt>__SFR_OFFSET</tt> == 0x20) for safety:
+
+\code
+ sts _SFR_ADDR(SPMCR), r24
+\endcode
+
+ In C programs, all 3 combinations of \c _SFR_ASM_COMPAT and
+ <tt>__SFR_OFFSET</tt> are supported - the \c _SFR_ADDR(SPMCR) macro can be
+ used to get the address of the \c SPMCR register (0x57 or 0x68 depending on
+ device). */
+
+#ifdef __ASSEMBLER__
+#define _SFR_ASM_COMPAT 1
+#elif !defined(_SFR_ASM_COMPAT)
+#define _SFR_ASM_COMPAT 0
+#endif
+
+#ifndef __ASSEMBLER__
+/* These only work in C programs. */
+#include <inttypes.h>
+
+#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
+#define _MMIO_WORD(mem_addr) (*(volatile uint16_t *)(mem_addr))
+#define _MMIO_DWORD(mem_addr) (*(volatile uint32_t *)(mem_addr))
+#endif
+
+#if _SFR_ASM_COMPAT
+
+#ifndef __SFR_OFFSET
+/* Define as 0 before including this file for compatibility with old asm
+ sources that don't subtract __SFR_OFFSET from symbolic I/O addresses. */
+# if __AVR_ARCH__ >= 100
+# define __SFR_OFFSET 0x00
+# else
+# define __SFR_OFFSET 0x20
+# endif
+#endif
+
+#if (__SFR_OFFSET != 0) && (__SFR_OFFSET != 0x20)
+#error "__SFR_OFFSET must be 0 or 0x20"
+#endif
+
+#define _SFR_MEM8(mem_addr) (mem_addr)
+#define _SFR_MEM16(mem_addr) (mem_addr)
+#define _SFR_MEM32(mem_addr) (mem_addr)
+#define _SFR_IO8(io_addr) ((io_addr) + __SFR_OFFSET)
+#define _SFR_IO16(io_addr) ((io_addr) + __SFR_OFFSET)
+
+#define _SFR_IO_ADDR(sfr) ((sfr) - __SFR_OFFSET)
+#define _SFR_MEM_ADDR(sfr) (sfr)
+#define _SFR_IO_REG_P(sfr) ((sfr) < 0x40 + __SFR_OFFSET)
+
+#if (__SFR_OFFSET == 0x20)
+/* No need to use ?: operator, so works in assembler too. */
+#define _SFR_ADDR(sfr) _SFR_MEM_ADDR(sfr)
+#elif !defined(__ASSEMBLER__)
+#define _SFR_ADDR(sfr) (_SFR_IO_REG_P(sfr) ? (_SFR_IO_ADDR(sfr) + 0x20) : _SFR_MEM_ADDR(sfr))
+#endif
+
+#else /* !_SFR_ASM_COMPAT */
+
+#ifndef __SFR_OFFSET
+# if __AVR_ARCH__ >= 100
+# define __SFR_OFFSET 0x00
+# else
+# define __SFR_OFFSET 0x20
+# endif
+#endif
+
+#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr)
+#define _SFR_MEM16(mem_addr) _MMIO_WORD(mem_addr)
+#define _SFR_MEM32(mem_addr) _MMIO_DWORD(mem_addr)
+#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
+#define _SFR_IO16(io_addr) _MMIO_WORD((io_addr) + __SFR_OFFSET)
+
+#define _SFR_MEM_ADDR(sfr) ((uint16_t) &(sfr))
+#define _SFR_IO_ADDR(sfr) (_SFR_MEM_ADDR(sfr) - __SFR_OFFSET)
+#define _SFR_IO_REG_P(sfr) (_SFR_MEM_ADDR(sfr) < 0x40 + __SFR_OFFSET)
+
+#define _SFR_ADDR(sfr) _SFR_MEM_ADDR(sfr)
+
+#endif /* !_SFR_ASM_COMPAT */
+
+#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))
+#define _SFR_WORD(sfr) _MMIO_WORD(_SFR_ADDR(sfr))
+#define _SFR_DWORD(sfr) _MMIO_DWORD(_SFR_ADDR(sfr))
+
+/** \name Bit manipulation */
+
+/*@{*/
+/** \def _BV
+ \ingroup avr_sfr
+
+ \code #include <avr/io.h>\endcode
+
+ Converts a bit number into a byte value.
+
+ \note The bit shift is performed by the compiler which then inserts the
+ result into the code. Thus, there is no run-time overhead when using
+ _BV(). */
+
+#define _BV(bit) (1 << (bit))
+
+/*@}*/
+
+#ifndef _VECTOR
+#define _VECTOR(N) __vector_ ## N
+#endif
+
+#ifndef __ASSEMBLER__
+
+
+/** \name IO register bit manipulation */
+
+/*@{*/
+
+
+
+/** \def bit_is_set
+ \ingroup avr_sfr
+
+ \code #include <avr/io.h>\endcode
+
+ Test whether bit \c bit in IO register \c sfr is set.
+ This will return a 0 if the bit is clear, and non-zero
+ if the bit is set. */
+
+#define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))
+
+/** \def bit_is_clear
+ \ingroup avr_sfr
+
+ \code #include <avr/io.h>\endcode
+
+ Test whether bit \c bit in IO register \c sfr is clear.
+ This will return non-zero if the bit is clear, and a 0
+ if the bit is set. */
+
+#define bit_is_clear(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit)))
+
+/** \def loop_until_bit_is_set
+ \ingroup avr_sfr
+
+ \code #include <avr/io.h>\endcode
+
+ Wait until bit \c bit in IO register \c sfr is set. */
+
+#define loop_until_bit_is_set(sfr, bit) do { } while (bit_is_clear(sfr, bit))
+
+/** \def loop_until_bit_is_clear
+ \ingroup avr_sfr
+
+ \code #include <avr/io.h>\endcode
+
+ Wait until bit \c bit in IO register \c sfr is clear. */
+
+#define loop_until_bit_is_clear(sfr, bit) do { } while (bit_is_set(sfr, bit))
+
+/*@}*/
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* _SFR_DEFS_H_ */
diff --git a/cpukit/score/cpu/avr/avr/signal.h b/cpukit/score/cpu/avr/avr/signal.h
new file mode 100644
index 0000000000..8f83399b04
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/signal.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 2002,2005,2006 Marek Michalkiewicz
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_SIGNAL_H_
+#define _AVR_SIGNAL_H_
+
+#warning "This header file is obsolete. Use <avr/interrupt.h>."
+#include <avr/interrupt.h>
+
+#endif /* _AVR_SIGNAL_H_ */
diff --git a/cpukit/score/cpu/avr/avr/signature.h b/cpukit/score/cpu/avr/avr/signature.h
new file mode 100644
index 0000000000..ca9568dd28
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/signature.h
@@ -0,0 +1,84 @@
+/* Copyright (c) 2009, Atmel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/* avr/signature.h - Signature API */
+
+#ifndef _AVR_SIGNATURE_H_
+#define _AVR_SIGNATURE_H_ 1
+
+/** \file */
+/** \defgroup avr_signature <avr/signature.h>: Signature Support
+
+ \par Introduction
+
+ The <avr/signature.h> header file allows the user to automatically
+ and easily include the device's signature data in a special section of
+ the final linked ELF file.
+
+ This value can then be used by programming software to compare the on-device
+ signature with the signature recorded in the ELF file to look for a match
+ before programming the device.
+
+ \par API Usage Example
+
+ Usage is very simple; just include the header file:
+
+ \code
+ #include <avr/signature.h>
+ \endcode
+
+ This will declare a constant unsigned char array and it is initialized with
+ the three signature bytes, MSB first, that are defined in the device I/O
+ header file. This array is then placed in the .signature section in the
+ resulting linked ELF file.
+
+ The three signature bytes that are used to initialize the array are
+ these defined macros in the device I/O header file, from MSB to LSB:
+ SIGNATURE_2, SIGNATURE_1, SIGNATURE_0.
+
+ This header file should only be included once in an application.
+*/
+
+#ifndef __ASSEMBLER__
+
+#include <avr/io.h>
+
+#if defined(SIGNATURE_0) && defined(SIGNATURE_1) && defined(SIGNATURE_2)
+
+const unsigned char __signature[3] __attribute__((section (".signature"))) =
+ { SIGNATURE_2, SIGNATURE_1, SIGNATURE_0 };
+
+#endif /* defined(SIGNATURE_0) && defined(SIGNATURE_1) && defined(SIGNATURE_2) */
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* _AVR_SIGNATURE_H_ */
diff --git a/cpukit/score/cpu/avr/avr/sleep.h b/cpukit/score/cpu/avr/avr/sleep.h
new file mode 100644
index 0000000000..718e671512
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/sleep.h
@@ -0,0 +1,588 @@
+/* Copyright (c) 2002, 2004 Theodore A. Roth
+ Copyright (c) 2004, 2007, 2008 Eric B. Weddington
+ Copyright (c) 2005, 2006, 2007 Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _AVR_SLEEP_H_
+#define _AVR_SLEEP_H_ 1
+
+#include <avr/io.h>
+#include <stdint.h>
+
+
+/** \file */
+
+/** \defgroup avr_sleep <avr/sleep.h>: Power Management and Sleep Modes
+
+ \code #include <avr/sleep.h>\endcode
+
+ Use of the \c SLEEP instruction can allow an application to reduce its
+ power comsumption considerably. AVR devices can be put into different
+ sleep modes. Refer to the datasheet for the details relating to the device
+ you are using.
+
+ There are several macros provided in this header file to actually
+ put the device into sleep mode. The simplest way is to optionally
+ set the desired sleep mode using \c set_sleep_mode() (it usually
+ defaults to idle mode where the CPU is put on sleep but all
+ peripheral clocks are still running), and then call
+ \c sleep_mode(). This macro automatically sets the sleep enable bit, goes
+ to sleep, and clears the sleep enable bit.
+
+ Example:
+ \code
+ #include <avr/sleep.h>
+
+ ...
+ set_sleep_mode(<mode>);
+ sleep_mode();
+ \endcode
+
+ Note that unless your purpose is to completely lock the CPU (until a
+ hardware reset), interrupts need to be enabled before going to sleep.
+
+ As the \c sleep_mode() macro might cause race conditions in some
+ situations, the individual steps of manipulating the sleep enable
+ (SE) bit, and actually issuing the \c SLEEP instruction, are provided
+ in the macros \c sleep_enable(), \c sleep_disable(), and
+ \c sleep_cpu(). This also allows for test-and-sleep scenarios that
+ take care of not missing the interrupt that will awake the device
+ from sleep.
+
+ Example:
+ \code
+ #include <avr/interrupt.h>
+ #include <avr/sleep.h>
+
+ ...
+ set_sleep_mode(<mode>);
+ cli();
+ if (some_condition)
+ {
+ sleep_enable();
+ sei();
+ sleep_cpu();
+ sleep_disable();
+ }
+ sei();
+ \endcode
+
+ This sequence ensures an atomic test of \c some_condition with
+ interrupts being disabled. If the condition is met, sleep mode
+ will be prepared, and the \c SLEEP instruction will be scheduled
+ immediately after an \c SEI instruction. As the intruction right
+ after the \c SEI is guaranteed to be executed before an interrupt
+ could trigger, it is sure the device will really be put to sleep.
+
+ Some devices have the ability to disable the Brown Out Detector (BOD) before
+ going to sleep. This will also reduce power while sleeping. If the
+ specific AVR device has this ability then an additional macro is defined:
+ \c sleep_bod_disable(). This macro generates inlined assembly code
+ that will correctly implement the timed sequence for disabling the BOD
+ before sleeping. However, there is a limited number of cycles after the
+ BOD has been disabled that the device can be put into sleep mode, otherwise
+ the BOD will not truly be disabled. Recommended practice is to disable
+ the BOD (\c sleep_bod_disable()), set the interrupts (\c sei()), and then
+ put the device to sleep (\c sleep_cpu()), like so:
+
+ \code
+ #include <avr/interrupt.h>
+ #include <avr/sleep.h>
+
+ ...
+ set_sleep_mode(<mode>);
+ cli();
+ if (some_condition)
+ {
+ sleep_enable();
+ sleep_bod_disable();
+ sei();
+ sleep_cpu();
+ sleep_disable();
+ }
+ sei();
+ \endcode
+*/
+
+
+/* Define an internal sleep control register and an internal sleep enable bit mask. */
+#if defined(SLEEP_CTRL)
+
+ /* XMEGA devices */
+ #define _SLEEP_CONTROL_REG SLEEP_CTRL
+ #define _SLEEP_ENABLE_MASK SLEEP_SEN_bm
+
+#elif defined(SMCR)
+
+ #define _SLEEP_CONTROL_REG SMCR
+ #define _SLEEP_ENABLE_MASK _BV(SE)
+
+#elif defined(__AVR_AT94K__)
+
+ #define _SLEEP_CONTROL_REG MCUR
+ #define _SLEEP_ENABLE_MASK _BV(SE)
+
+#else
+
+ #define _SLEEP_CONTROL_REG MCUCR
+ #define _SLEEP_ENABLE_MASK _BV(SE)
+
+#endif
+
+
+/* Define set_sleep_mode() and sleep mode values per device. */
+#if defined(__AVR_ATmega161__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_PWR_DOWN 1
+ #define SLEEP_MODE_PWR_SAVE 2
+
+ #define set_sleep_mode(mode) \
+ do { \
+ MCUCR = ((MCUCR & ~_BV(SM1)) | ((mode) == SLEEP_MODE_PWR_DOWN || (mode) == SLEEP_MODE_PWR_SAVE ? _BV(SM1) : 0)); \
+ EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE ? _BV(SM0) : 0)); \
+ } while(0)
+
+
+#elif defined(__AVR_ATmega162__) \
+|| defined(__AVR_ATmega8515__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_PWR_DOWN 1
+ #define SLEEP_MODE_PWR_SAVE 2
+ #define SLEEP_MODE_ADC 3
+ #define SLEEP_MODE_STANDBY 4
+ #define SLEEP_MODE_EXT_STANDBY 5
+
+ #define set_sleep_mode(mode) \
+ do { \
+ MCUCR = ((MCUCR & ~_BV(SM1)) | ((mode) == SLEEP_MODE_IDLE ? 0 : _BV(SM1))); \
+ MCUCSR = ((MCUCSR & ~_BV(SM2)) | ((mode) == SLEEP_MODE_STANDBY || (mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM2) : 0)); \
+ EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE || (mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM0) : 0)); \
+ } while(0)
+
+#elif defined(__AVR_AT90S2313__) \
+|| defined(__AVR_AT90S2323__) \
+|| defined(__AVR_AT90S2333__) \
+|| defined(__AVR_AT90S2343__) \
+|| defined(__AVR_AT43USB320__) \
+|| defined(__AVR_AT43USB355__) \
+|| defined(__AVR_AT90S4414__) \
+|| defined(__AVR_AT90S4433__) \
+|| defined(__AVR_AT90S8515__) \
+|| defined(__AVR_ATtiny22__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_PWR_DOWN _BV(SM)
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~__BV(SM)) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_ATtiny167__) \
+|| defined(__AVR_ATtiny87__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_ADC _BV(SM0)
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_AT90S4434__) \
+|| defined(__AVR_AT76C711__) \
+|| defined(__AVR_AT90S8535__) \
+|| defined(__AVR_ATmega103__) \
+|| defined(__AVR_ATmega161__) \
+|| defined(__AVR_ATmega163__) \
+|| defined(__AVR_ATtiny13__) \
+|| defined(__AVR_ATtiny13A__) \
+|| defined(__AVR_ATtiny15__) \
+|| defined(__AVR_ATtiny24__) \
+|| defined(__AVR_ATtiny24A__) \
+|| defined(__AVR_ATtiny44__) \
+|| defined(__AVR_ATtiny44A__) \
+|| defined(__AVR_ATtiny84__) \
+|| defined(__AVR_ATtiny25__) \
+|| defined(__AVR_ATtiny45__) \
+|| defined(__AVR_ATtiny48__) \
+|| defined(__AVR_ATtiny85__) \
+|| defined(__AVR_ATtiny261__) \
+|| defined(__AVR_ATtiny261A__) \
+|| defined(__AVR_ATtiny461__) \
+|| defined(__AVR_ATtiny461A__) \
+|| defined(__AVR_ATtiny861__) \
+|| defined(__AVR_ATtiny861A__) \
+|| defined(__AVR_ATtiny88__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_ADC _BV(SM0)
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+ #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_ATtiny2313__) \
+|| defined(__AVR_ATtiny2313A__) \
+|| defined(__AVR_ATtiny4313__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_PWR_DOWN (_BV(SM0) | _BV(SM1))
+ #define SLEEP_MODE_STANDBY _BV(SM1)
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_AT94K__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+ #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_ATtiny26__) \
+|| defined(__AVR_ATtiny43U__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_ADC _BV(SM0)
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+ #define SLEEP_MODE_STANDBY (_BV(SM0) | _BV(SM1))
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_AT90PWM216__) \
+|| defined(__AVR_AT90PWM316__) \
+|| defined(__AVR_AT90PWM81__)
+
+ #define SLEEP_MODE_IDLE 0
+ #define SLEEP_MODE_ADC _BV(SM0)
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+ #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_AT90CAN128__) \
+|| defined(__AVR_AT90CAN32__) \
+|| defined(__AVR_AT90CAN64__) \
+|| defined(__AVR_AT90PWM1__) \
+|| defined(__AVR_AT90PWM2__) \
+|| defined(__AVR_AT90PWM2B__) \
+|| defined(__AVR_AT90PWM3__) \
+|| defined(__AVR_AT90PWM3B__) \
+|| defined(__AVR_AT90USB162__) \
+|| defined(__AVR_AT90USB82__) \
+|| defined(__AVR_AT90USB1286__) \
+|| defined(__AVR_AT90USB1287__) \
+|| defined(__AVR_AT90USB646__) \
+|| defined(__AVR_AT90USB647__) \
+|| defined(__AVR_ATmega128__) \
+|| defined(__AVR_ATmega1280__) \
+|| defined(__AVR_ATmega1281__) \
+|| defined(__AVR_ATmega1284P__) \
+|| defined(__AVR_ATmega128RFA1__) \
+|| defined(__AVR_ATmega16__) \
+|| defined(__AVR_ATmega16A__) \
+|| defined(__AVR_ATmega162__) \
+|| defined(__AVR_ATmega164A__) \
+|| defined(__AVR_ATmega164P__) \
+|| defined(__AVR_ATmega165__) \
+|| defined(__AVR_ATmega165A__) \
+|| defined(__AVR_ATmega165P__) \
+|| defined(__AVR_ATmega168__) \
+|| defined(__AVR_ATmega168A__) \
+|| defined(__AVR_ATmega168P__) \
+|| defined(__AVR_ATmega169__) \
+|| defined(__AVR_ATmega169A__) \
+|| defined(__AVR_ATmega169P__) \
+|| defined(__AVR_ATmega169PA__) \
+|| defined(__AVR_ATmega16HVA__) \
+|| defined(__AVR_ATmega16HVA2__) \
+|| defined(__AVR_ATmega16HVB__) \
+|| defined(__AVR_ATmega16M1__) \
+|| defined(__AVR_ATmega16U2__) \
+|| defined(__AVR_ATmega16U4__) \
+|| defined(__AVR_ATmega2560__) \
+|| defined(__AVR_ATmega2561__) \
+|| defined(__AVR_ATmega32__) \
+|| defined(__AVR_ATmega323__) \
+|| defined(__AVR_ATmega324A__) \
+|| defined(__AVR_ATmega324P__) \
+|| defined(__AVR_ATmega324PA__) \
+|| defined(__AVR_ATmega325__) \
+|| defined(__AVR_ATmega3250__) \
+|| defined(__AVR_ATmega328__) \
+|| defined(__AVR_ATmega328P__) \
+|| defined(__AVR_ATmega329__) \
+|| defined(__AVR_ATmega329P__) \
+|| defined(__AVR_ATmega329PA__) \
+|| defined(__AVR_ATmega3290__) \
+|| defined(__AVR_ATmega3290P__) \
+|| defined(__AVR_ATmega32C1__) \
+|| defined(__AVR_ATmega32HVB__) \
+|| defined(__AVR_ATmega32M1__) \
+|| defined(__AVR_ATmega32U2__) \
+|| defined(__AVR_ATmega32U4__) \
+|| defined(__AVR_ATmega32U6__) \
+|| defined(__AVR_ATmega406__) \
+|| defined(__AVR_ATmega48__) \
+|| defined(__AVR_ATmega48A__) \
+|| defined(__AVR_ATmega48P__) \
+|| defined(__AVR_ATmega64__) \
+|| defined(__AVR_ATmega640__) \
+|| defined(__AVR_ATmega644__) \
+|| defined(__AVR_ATmega644A__) \
+|| defined(__AVR_ATmega644P__) \
+|| defined(__AVR_ATmega644PA__) \
+|| defined(__AVR_ATmega645__) \
+|| defined(__AVR_ATmega645A__) \
+|| defined(__AVR_ATmega645P__) \
+|| defined(__AVR_ATmega6450__) \
+|| defined(__AVR_ATmega6450A__) \
+|| defined(__AVR_ATmega6450P__) \
+|| defined(__AVR_ATmega649__) \
+|| defined(__AVR_ATmega649A__) \
+|| defined(__AVR_ATmega6490__) \
+|| defined(__AVR_ATmega6490A__) \
+|| defined(__AVR_ATmega6490P__) \
+|| defined(__AVR_ATmega649P__) \
+|| defined(__AVR_ATmega64C1__) \
+|| defined(__AVR_ATmega64HVE__) \
+|| defined(__AVR_ATmega64M1__) \
+|| defined(__AVR_ATmega8__) \
+|| defined(__AVR_ATmega8515__) \
+|| defined(__AVR_ATmega8535__) \
+|| defined(__AVR_ATmega88__) \
+|| defined(__AVR_ATmega88A__) \
+|| defined(__AVR_ATmega88P__) \
+|| defined(__AVR_ATmega88PA__) \
+|| defined(__AVR_ATmega8HVA__) \
+|| defined(__AVR_ATmega8U2__)
+
+
+ #define SLEEP_MODE_IDLE (0)
+ #define SLEEP_MODE_ADC _BV(SM0)
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+ #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
+ #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
+ #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2))
+
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_ATxmega16A4__) \
+|| defined(__AVR_ATxmega16D4__) \
+|| defined(__AVR_ATxmega32A4__) \
+|| defined(__AVR_ATxmega32D4__) \
+|| defined(__AVR_ATxmega64A1__) \
+|| defined(__AVR_ATxmega64A3__) \
+|| defined(__AVR_ATxmega64D3__) \
+|| defined(__AVR_ATxmega128A1__) \
+|| defined(__AVR_ATxmega128A3__) \
+|| defined(__AVR_ATxmega128D3__) \
+|| defined(__AVR_ATxmega192A3__) \
+|| defined(__AVR_ATxmega192D3__) \
+|| defined(__AVR_ATxmega256A3__) \
+|| defined(__AVR_ATxmega256D3__) \
+|| defined(__AVR_ATxmega256A3B__)
+
+ #define SLEEP_MODE_IDLE (0)
+ #define SLEEP_MODE_PWR_DOWN (SLEEP_SMODE1_bm)
+ #define SLEEP_MODE_PWR_SAVE (SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)
+ #define SLEEP_MODE_STANDBY (SLEEP_SMODE2_bm | SLEEP_SMODE1_bm)
+ #define SLEEP_MODE_EXT_STANDBY (SLEEP_SMODE2_bm | SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(SLEEP_SMODE2_bm | SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_AT90SCR100__)
+
+ #define SLEEP_MODE_IDLE (0)
+ #define SLEEP_MODE_PWR_DOWN _BV(SM1)
+ #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
+ #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
+ #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2))
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
+ } while(0)
+
+#elif defined(__AVR_ATA6289__)
+
+ #define SLEEP_MODE_IDLE (0)
+ #define SLEEP_MODE_SENSOR_NOISE_REDUCTION (_BV(SM0))
+ #define SLEEP_MODE_PWR_DOWN (_BV(SM1))
+
+ #define set_sleep_mode(mode) \
+ do { \
+ _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
+ } while(0)
+
+#else
+
+ #error "No SLEEP mode defined for this device."
+
+#endif
+
+
+
+/** \ingroup avr_sleep
+
+ Put the device in sleep mode. How the device is brought out of sleep mode
+ depends on the specific mode selected with the set_sleep_mode() function.
+ See the data sheet for your device for more details. */
+
+
+#if defined(__DOXYGEN__)
+
+/** \ingroup avr_sleep
+
+ Set the SE (sleep enable) bit.
+*/
+extern void sleep_enable (void);
+
+#else
+
+#define sleep_enable() \
+do { \
+ _SLEEP_CONTROL_REG |= (uint8_t)_SLEEP_ENABLE_MASK; \
+} while(0)
+
+#endif
+
+
+#if defined(__DOXYGEN__)
+
+/** \ingroup avr_sleep
+
+ Clear the SE (sleep enable) bit.
+*/
+extern void sleep_disable (void);
+
+#else
+
+#define sleep_disable() \
+do { \
+ _SLEEP_CONTROL_REG &= (uint8_t)(~_SLEEP_ENABLE_MASK); \
+} while(0)
+
+#endif
+
+
+/** \ingroup avr_sleep
+
+ Put the device into sleep mode. The SE bit must be set
+ beforehand, and it is recommended to clear it afterwards.
+*/
+#if defined(__DOXYGEN__)
+
+extern void sleep_cpu (void);
+
+#else
+
+#define sleep_cpu() \
+do { \
+ __asm__ __volatile__ ( "sleep" "\n\t" :: ); \
+} while(0)
+
+#endif
+
+
+#if defined(__DOXYGEN__)
+
+extern void sleep_mode (void);
+
+#else
+
+#define sleep_mode() \
+do { \
+ sleep_enable(); \
+ sleep_cpu(); \
+ sleep_disable(); \
+} while (0)
+
+#endif
+
+
+#if defined(__DOXYGEN__)
+
+extern void sleep_bod_disable (void);
+
+#else
+
+#if defined(BODS) && defined(BODSE)
+
+#define sleep_bod_disable() \
+do { \
+ uint8_t tempreg; \
+ __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \
+ "ori %[tempreg], %[bods_bodse]" "\n\t" \
+ "out %[mcucr], %[tempreg]" "\n\t" \
+ "andi %[tempreg], %[not_bodse]" "\n\t" \
+ "out %[mcucr], %[tempreg]" \
+ : [tempreg] "=&d" (tempreg) \
+ : [mcucr] "I" _SFR_IO_ADDR(MCUCR), \
+ [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \
+ [not_bodse] "i" (~_BV(BODSE))); \
+} while (0)
+
+#endif
+
+#endif
+
+
+/*@}*/
+
+#endif /* _AVR_SLEEP_H_ */
diff --git a/cpukit/score/cpu/avr/avr/version.h b/cpukit/score/cpu/avr/avr/version.h
new file mode 100644
index 0000000000..49d7cbdf46
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/version.h
@@ -0,0 +1,90 @@
+/* Copyright (c) 2005, Joerg Wunsch -*- c -*-
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/** \defgroup avr_version <avr/version.h>: avr-libc version macros
+ \code #include <avr/version.h> \endcode
+
+ This header file defines macros that contain version numbers and
+ strings describing the current version of avr-libc.
+
+ The version number itself basically consists of three pieces that
+ are separated by a dot: the major number, the minor number, and
+ the revision number. For development versions (which use an odd
+ minor number), the string representation additionally gets the
+ date code (YYYYMMDD) appended.
+
+ This file will also be included by \c <avr/io.h>. That way,
+ portable tests can be implemented using \c <avr/io.h> that can be
+ used in code that wants to remain backwards-compatible to library
+ versions prior to the date when the library version API had been
+ added, as referenced but undefined C preprocessor macros
+ automatically evaluate to 0.
+*/
+
+#ifndef _AVR_VERSION_H_
+#define _AVR_VERSION_H_
+
+/** \ingroup avr_version
+ String literal representation of the current library version. */
+#define __AVR_LIBC_VERSION_STRING__ "1.6.8"
+
+/** \ingroup avr_version
+ Numerical representation of the current library version.
+
+ In the numerical representation, the major number is multiplied by
+ 10000, the minor number by 100, and all three parts are then
+ added. It is intented to provide a monotonically increasing
+ numerical value that can easily be used in numerical checks.
+ */
+#define __AVR_LIBC_VERSION__ 10608UL
+
+/** \ingroup avr_version
+ String literal representation of the release date. */
+#define __AVR_LIBC_DATE_STRING__ "20100211"
+
+/** \ingroup avr_version
+ Numerical representation of the release date. */
+#define __AVR_LIBC_DATE_ 20100211UL
+
+/** \ingroup avr_version
+ Library major version number. */
+#define __AVR_LIBC_MAJOR__ 1
+
+/** \ingroup avr_version
+ Library minor version number. */
+#define __AVR_LIBC_MINOR__ 6
+
+/** \ingroup avr_version
+ Library revision number. */
+#define __AVR_LIBC_REVISION__ 8
+
+#endif /* _AVR_VERSION_H_ */
diff --git a/cpukit/score/cpu/avr/avr/wdt.h b/cpukit/score/cpu/avr/avr/wdt.h
new file mode 100644
index 0000000000..10ddf6edf1
--- /dev/null
+++ b/cpukit/score/cpu/avr/avr/wdt.h
@@ -0,0 +1,441 @@
+/* Copyright (c) 2002, 2004 Marek Michalkiewicz
+ Copyright (c) 2005, 2006, 2007 Eric B. Weddington
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/*
+ avr/wdt.h - macros for AVR watchdog timer
+ */
+
+#ifndef _AVR_WDT_H_
+#define _AVR_WDT_H_
+
+#include <avr/io.h>
+#include <stdint.h>
+
+/** \file */
+/** \defgroup avr_watchdog <avr/wdt.h>: Watchdog timer handling
+ \code #include <avr/wdt.h> \endcode
+
+ This header file declares the interface to some inline macros
+ handling the watchdog timer present in many AVR devices. In order
+ to prevent the watchdog timer configuration from being
+ accidentally altered by a crashing application, a special timed
+ sequence is required in order to change it. The macros within
+ this header file handle the required sequence automatically
+ before changing any value. Interrupts will be disabled during
+ the manipulation.
+
+ \note Depending on the fuse configuration of the particular
+ device, further restrictions might apply, in particular it might
+ be disallowed to turn off the watchdog timer.
+
+ Note that for newer devices (ATmega88 and newer, effectively any
+ AVR that has the option to also generate interrupts), the watchdog
+ timer remains active even after a system reset (except a power-on
+ condition), using the fastest prescaler value (approximately 15
+ ms). It is therefore required to turn off the watchdog early
+ during program startup, the datasheet recommends a sequence like
+ the following:
+
+ \code
+ #include <stdint.h>
+ #include <avr/wdt.h>
+
+ uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
+
+ void get_mcusr(void) \
+ __attribute__((naked)) \
+ __attribute__((section(".init3")));
+ void get_mcusr(void)
+ {
+ mcusr_mirror = MCUSR;
+ MCUSR = 0;
+ wdt_disable();
+ }
+ \endcode
+
+ Saving the value of MCUSR in \c mcusr_mirror is only needed if the
+ application later wants to examine the reset source, but in particular,
+ clearing the watchdog reset flag before disabling the
+ watchdog is required, according to the datasheet.
+*/
+
+/**
+ \ingroup avr_watchdog
+ Reset the watchdog timer. When the watchdog timer is enabled,
+ a call to this instruction is required before the timer expires,
+ otherwise a watchdog-initiated device reset will occur.
+*/
+
+#define wdt_reset() __asm__ __volatile__ ("wdr")
+
+
+#if defined(WDP3)
+# define _WD_PS3_MASK _BV(WDP3)
+#else
+# define _WD_PS3_MASK 0x00
+#endif
+
+#if defined(WDTCSR)
+# define _WD_CONTROL_REG WDTCSR
+#else
+# define _WD_CONTROL_REG WDTCR
+#endif
+
+#if defined(WDTOE)
+#define _WD_CHANGE_BIT WDTOE
+#else
+#define _WD_CHANGE_BIT WDCE
+#endif
+
+
+/**
+ \ingroup avr_watchdog
+ Enable the watchdog timer, configuring it for expiry after
+ \c timeout (which is a combination of the \c WDP0 through
+ \c WDP2 bits to write into the \c WDTCR register; For those devices
+ that have a \c WDTCSR register, it uses the combination of the \c WDP0
+ through \c WDP3 bits).
+
+ See also the symbolic constants \c WDTO_15MS et al.
+*/
+
+
+#if defined(__AVR_ATxmega16A4__) \
+|| defined(__AVR_ATxmega16D4__) \
+|| defined(__AVR_ATxmega32A4__) \
+|| defined(__AVR_ATxmega32D4__) \
+|| defined(__AVR_ATxmega64A1__) \
+|| defined(__AVR_ATxmega64A3__) \
+|| defined(__AVR_ATxmega64D3__) \
+|| defined(__AVR_ATxmega128A1__) \
+|| defined(__AVR_ATxmega128A3__) \
+|| defined(__AVR_ATxmega128D3__) \
+|| defined(__AVR_ATxmega192A3__) \
+|| defined(__AVR_ATxmega192D3__) \
+|| defined(__AVR_ATxmega256A3__) \
+|| defined(__AVR_ATxmega256D3__) \
+|| defined(__AVR_ATxmega256A3B__)
+
+/*
+ wdt_enable(WDT_PER_8KCLK_gc);
+*/
+#define wdt_enable(value) \
+__asm__ __volatile__ ( \
+ "in __tmp_reg__, %0" "\n\t" \
+ "out %1, %3" "\n\t" \
+ "sts %2, %4" "\n\t" \
+ "wdr" "\n\t" \
+ "out %0, __tmp_reg__" "\n\t" \
+ : \
+ : "M" (_SFR_MEM_ADDR(RAMPD)), \
+ "M" (_SFR_MEM_ADDR(CCP)), \
+ "M" (_SFR_MEM_ADDR(WDT_CTRL)), \
+ "r" ((uint8_t)0xD8), \
+ "r" ((uint8_t)(WDT_CEN_bm | WDT_ENABLE_bm | value)) \
+ : "r0" \
+)
+
+
+#elif defined(__AVR_AT90CAN32__) \
+|| defined(__AVR_AT90CAN64__) \
+|| defined(__AVR_AT90CAN128__) \
+|| defined(__AVR_AT90PWM1__) \
+|| defined(__AVR_AT90PWM2__) \
+|| defined(__AVR_AT90PWM216__) \
+|| defined(__AVR_AT90PWM2B__) \
+|| defined(__AVR_AT90PWM3__) \
+|| defined(__AVR_AT90PWM316__) \
+|| defined(__AVR_AT90PWM3B__) \
+|| defined(__AVR_AT90PWM81__) \
+|| defined(__AVR_AT90USB1286__) \
+|| defined(__AVR_AT90USB1287__) \
+|| defined(__AVR_AT90USB162__) \
+|| defined(__AVR_AT90USB646__) \
+|| defined(__AVR_AT90USB647__) \
+|| defined(__AVR_AT90USB82__) \
+|| defined(__AVR_ATmega1280__) \
+|| defined(__AVR_ATmega1281__) \
+|| defined(__AVR_ATmega1284P__) \
+|| defined(__AVR_ATmega128RFA1__) \
+|| defined(__AVR_ATmega164__) \
+|| defined(__AVR_ATmega164A__) \
+|| defined(__AVR_ATmega164P__) \
+|| defined(__AVR_ATmega165__) \
+|| defined(__AVR_ATmega165A__) \
+|| defined(__AVR_ATmega165P__) \
+|| defined(__AVR_ATmega168__) \
+|| defined(__AVR_ATmega168A__) \
+|| defined(__AVR_ATmega168P__) \
+|| defined(__AVR_ATmega169__) \
+|| defined(__AVR_ATmega169A__) \
+|| defined(__AVR_ATmega169P__) \
+|| defined(__AVR_ATmega169PA__) \
+|| defined(__AVR_ATmega16HVA__) \
+|| defined(__AVR_ATmega16HVA2__) \
+|| defined(__AVR_ATmega16HVB__) \
+|| defined(__AVR_ATmega16M1__) \
+|| defined(__AVR_ATmega16U2__) \
+|| defined(__AVR_ATmega16U4__) \
+|| defined(__AVR_ATmega2560__) \
+|| defined(__AVR_ATmega2561__) \
+|| defined(__AVR_ATmega324__) \
+|| defined(__AVR_ATmega324A__) \
+|| defined(__AVR_ATmega324P__) \
+|| defined(__AVR_ATmega324PA__) \
+|| defined(__AVR_ATmega325__) \
+|| defined(__AVR_ATmega3250__) \
+|| defined(__AVR_ATmega328__) \
+|| defined(__AVR_ATmega328P__) \
+|| defined(__AVR_ATmega329__) \
+|| defined(__AVR_ATmega329P__) \
+|| defined(__AVR_ATmega329PA__) \
+|| defined(__AVR_ATmega3290__) \
+|| defined(__AVR_ATmega3290P__) \
+|| defined(__AVR_ATmega32C1__) \
+|| defined(__AVR_ATmega32HVB__) \
+|| defined(__AVR_ATmega32M1__) \
+|| defined(__AVR_ATmega32U2__) \
+|| defined(__AVR_ATmega32U4__) \
+|| defined(__AVR_ATmega32U6__) \
+|| defined(__AVR_ATmega406__) \
+|| defined(__AVR_ATmega48__) \
+|| defined(__AVR_ATmega48A__) \
+|| defined(__AVR_ATmega48P__) \
+|| defined(__AVR_ATmega640__) \
+|| defined(__AVR_ATmega644__) \
+|| defined(__AVR_ATmega644A__) \
+|| defined(__AVR_ATmega644P__) \
+|| defined(__AVR_ATmega644PA__) \
+|| defined(__AVR_ATmega645__) \
+|| defined(__AVR_ATmega645A__) \
+|| defined(__AVR_ATmega645P__) \
+|| defined(__AVR_ATmega6450__) \
+|| defined(__AVR_ATmega6450A__) \
+|| defined(__AVR_ATmega6450P__) \
+|| defined(__AVR_ATmega649__) \
+|| defined(__AVR_ATmega649A__) \
+|| defined(__AVR_ATmega6490__) \
+|| defined(__AVR_ATmega6490A__) \
+|| defined(__AVR_ATmega6490P__) \
+|| defined(__AVR_ATmega649P__) \
+|| defined(__AVR_ATmega64C1__) \
+|| defined(__AVR_ATmega64HVE__) \
+|| defined(__AVR_ATmega64M1__) \
+|| defined(__AVR_ATmega88__) \
+|| defined(__AVR_ATmega88A__) \
+|| defined(__AVR_ATmega88P__) \
+|| defined(__AVR_ATmega88PA__) \
+|| defined(__AVR_ATmega8HVA__) \
+|| defined(__AVR_ATmega8U2__) \
+|| defined(__AVR_ATtiny48__) \
+|| defined(__AVR_ATtiny88__) \
+|| defined(__AVR_ATtiny87__) \
+|| defined(__AVR_ATtiny167__) \
+|| defined(__AVR_AT90SCR100__) \
+|| defined(__AVR_ATA6289__)
+
+/* Use STS instruction. */
+
+#define wdt_enable(value) \
+__asm__ __volatile__ ( \
+ "in __tmp_reg__,__SREG__" "\n\t" \
+ "cli" "\n\t" \
+ "wdr" "\n\t" \
+ "sts %0,%1" "\n\t" \
+ "out __SREG__,__tmp_reg__" "\n\t" \
+ "sts %0,%2" "\n\t" \
+ : /* no outputs */ \
+ : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
+ "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
+ "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
+ _BV(WDE) | (value & 0x07)) ) \
+ : "r0" \
+)
+
+#define wdt_disable() \
+__asm__ __volatile__ ( \
+ "in __tmp_reg__, __SREG__" "\n\t" \
+ "cli" "\n\t" \
+ "sts %0, %1" "\n\t" \
+ "sts %0, __zero_reg__" "\n\t" \
+ "out __SREG__,__tmp_reg__" "\n\t" \
+ : /* no outputs */ \
+ : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
+ "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))) \
+ : "r0" \
+)
+
+
+
+#else
+
+/* Use OUT instruction. */
+
+#define wdt_enable(value) \
+ __asm__ __volatile__ ( \
+ "in __tmp_reg__,__SREG__" "\n\t" \
+ "cli" "\n\t" \
+ "wdr" "\n\t" \
+ "out %0,%1" "\n\t" \
+ "out __SREG__,__tmp_reg__" "\n\t" \
+ "out %0,%2" \
+ : /* no outputs */ \
+ : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), \
+ "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
+ "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
+ _BV(WDE) | (value & 0x07)) ) \
+ : "r0" \
+ )
+
+/**
+ \ingroup avr_watchdog
+ Disable the watchdog timer, if possible. This attempts to turn off the
+ Enable bit in the watchdog control register. See the datasheet for
+ details.
+*/
+#define wdt_disable() \
+__asm__ __volatile__ ( \
+ "in __tmp_reg__, __SREG__" "\n\t" \
+ "cli" "\n\t" \
+ "out %0, %1" "\n\t" \
+ "out %0, __zero_reg__" "\n\t" \
+ "out __SREG__,__tmp_reg__" "\n\t" \
+ : /* no outputs */ \
+ : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), \
+ "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))) \
+ : "r0" \
+)
+
+#endif
+
+
+
+/**
+ \ingroup avr_watchdog
+ Symbolic constants for the watchdog timeout. Since the watchdog
+ timer is based on a free-running RC oscillator, the times are
+ approximate only and apply to a supply voltage of 5 V. At lower
+ supply voltages, the times will increase. For older devices, the
+ times will be as large as three times when operating at Vcc = 3 V,
+ while the newer devices (e. g. ATmega128, ATmega8) only experience
+ a negligible change.
+
+ Possible timeout values are: 15 ms, 30 ms, 60 ms, 120 ms, 250 ms,
+ 500 ms, 1 s, 2 s. (Some devices also allow for 4 s and 8 s.)
+ Symbolic constants are formed by the prefix
+ \c WDTO_, followed by the time.
+
+ Example that would select a watchdog timer expiry of approximately
+ 500 ms:
+ \code
+ wdt_enable(WDTO_500MS);
+ \endcode
+*/
+#define WDTO_15MS 0
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS */
+#define WDTO_30MS 1
+
+/** \ingroup avr_watchdog See
+ \c WDT0_15MS */
+#define WDTO_60MS 2
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS */
+#define WDTO_120MS 3
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS */
+#define WDTO_250MS 4
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS */
+#define WDTO_500MS 5
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS */
+#define WDTO_1S 6
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS */
+#define WDTO_2S 7
+
+#if defined(__DOXYGEN__) || defined(WDP3)
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS
+ Note: This is only available on the
+ ATtiny2313,
+ ATtiny24, ATtiny44, ATtiny84,
+ ATtiny25, ATtiny45, ATtiny85,
+ ATtiny261, ATtiny461, ATtiny861,
+ ATmega48, ATmega88, ATmega168,
+ ATmega48P, ATmega88P, ATmega168P, ATmega328P,
+ ATmega164P, ATmega324P, ATmega644P, ATmega644,
+ ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561,
+ ATmega8HVA, ATmega16HVA, ATmega32HVB,
+ ATmega406, ATmega1284P,
+ AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316,
+ AT90PWM81,
+ AT90USB82, AT90USB162,
+ AT90USB646, AT90USB647, AT90USB1286, AT90USB1287,
+ ATtiny48, ATtiny88.
+ */
+#define WDTO_4S 8
+
+/** \ingroup avr_watchdog
+ See \c WDT0_15MS
+ Note: This is only available on the
+ ATtiny2313,
+ ATtiny24, ATtiny44, ATtiny84,
+ ATtiny25, ATtiny45, ATtiny85,
+ ATtiny261, ATtiny461, ATtiny861,
+ ATmega48, ATmega88, ATmega168,
+ ATmega48P, ATmega88P, ATmega168P, ATmega328P,
+ ATmega164P, ATmega324P, ATmega644P, ATmega644,
+ ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561,
+ ATmega8HVA, ATmega16HVA, ATmega32HVB,
+ ATmega406, ATmega1284P,
+ AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316,
+ AT90PWM81,
+ AT90USB82, AT90USB162,
+ AT90USB646, AT90USB647, AT90USB1286, AT90USB1287,
+ ATtiny48, ATtiny88.
+ */
+#define WDTO_8S 9
+
+#endif /* defined(__DOXYGEN__) || defined(WDP3) */
+
+
+#endif /* _AVR_WDT_H_ */
diff --git a/cpukit/score/cpu/avr/cpu.c b/cpukit/score/cpu/avr/cpu.c
new file mode 100644
index 0000000000..32da69776e
--- /dev/null
+++ b/cpukit/score/cpu/avr/cpu.c
@@ -0,0 +1,172 @@
+/*
+ * AVR CPU Dependent Source
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+
+#include <rtems/bspIo.h> /* XXX remove me later */
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void)
+{
+
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ /*
+ * This routine returns the current interrupt level.
+ */
+ if((SREG & 0x80))return 1;
+ else return 0;
+
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+
+ for( ; ; ) __asm__ volatile ("sleep"::);
+ /* insert your "halt" instruction here */ ;
+ return (void *) 0;
+}
diff --git a/cpukit/score/cpu/avr/cpu_asm.S b/cpukit/score/cpu/avr/cpu_asm.S
new file mode 100644
index 0000000000..6ad0f6a729
--- /dev/null
+++ b/cpukit/score/cpu/avr/cpu_asm.S
@@ -0,0 +1,461 @@
+/* cpu_asm.c ===> cpu_asm.S or cpu_asm.s
+ *
+ * This file contains the basic algorithms for all assembly code used
+ * in an specific CPU port of RTEMS. These algorithms must be implemented
+ * in assembly language
+ *
+ * NOTE: This is supposed to be a .S or .s file NOT a C file.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * This is supposed to be an assembly file. This means that system.h
+ * and cpu.h should not be included in a "real" cpu_asm file. An
+ * implementation in assembly should include "cpu_asm.h>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <avr/sfr_defs.h>
+#include <rtems/score/percpu.h>
+
+
+#define jmpb_hi r25
+#define jmpb_lo r24
+#define val_hi r23
+#define val_lo r22
+
+#define ret_lo r24
+#define ret_hi r25
+
+ PUBLIC( setjmp )
+
+SYM( setjmp ):
+ X_movw XL, jmpb_lo
+/*;save call-saved registers and frame pointer*/
+ .irp .L_regno, 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,28,29
+ st X+, r\.L_regno
+ .endr
+/*;get return address*/
+
+ pop ZH
+ pop ZL
+/*save stack pointer (after popping)*/
+
+ in ret_lo, AVR_STACK_POINTER_LO_ADDR
+ st X+, ret_lo
+
+#ifdef _HAVE_AVR_STACK_POINTER_HI
+ in ret_lo, AVR_STACK_POINTER_HI_ADDR
+ st X+, ret_lo
+#else
+ st X+, ret_lo
+#endif
+/*save status reg (I flag)*/
+ in ret_lo, AVR_STATUS_ADDR
+ st X+, ret_lo
+/*save return addr*/
+ st X+, ZL
+ st X+, ZH
+/*return zero*/
+ clr ret_hi
+ clr ret_lo
+ ijmp
+
+ .size _U(setjmp),.-_U(setjmp)
+
+
+ .global _U(longjmp)
+ .type _U(longjmp), @function
+
+_U(longjmp):
+ X_movw XL, jmpb_lo
+/*return value*/
+ X_movw ret_lo, val_lo
+/*if zero, change to 1*/
+ cpi ret_lo, 1
+ cpc ret_hi, __zero_reg__
+ adc ret_lo, __zero_reg__
+/*restore call-saved registers and frame pointer*/
+ .irp .L_regno, 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,28,29
+ ld r\.L_regno, X+
+ .endr
+/*; restore stack pointer (SP value before the setjmp() call) and SREG*/
+ ld ZL, X+
+ ld ZH, X+
+ ld __tmp_reg__, X+
+#if defined (__AVR_XMEGA__) && __AVR_XMEGA__
+ /* A write to SPL will automatically disable interrupts for up to 4
+ instructions or until the next I/O memory write. */
+ out AVR_STATUS_ADDR, __tmp_reg__
+ out AVR_STACK_POINTER_LO_ADDR, ZL
+ out AVR_STACK_POINTER_HI_ADDR, ZH
+#else
+# ifdef _HAVE_AVR_STACK_POINTER_HI
+ /* interrupts disabled for shortest possible time (3 cycles) */
+ cli
+ out AVR_STACK_POINTER_HI_ADDR, ZH
+# endif
+ /* Restore status register (including the interrupt enable flag).
+ Interrupts are re-enabled only after the next instruction. */
+ out AVR_STATUS_ADDR, __tmp_reg__
+ out AVR_STACK_POINTER_LO_ADDR, ZL
+#endif
+ ; get return address and jump
+ ld ZL, X+
+ ld ZH, X+
+#if defined(__AVR_3_BYTE_PC__) && __AVR_3_BYTE_PC__
+ ld __tmp_reg__, X+
+.L_jmp3:
+ push ZL
+ push ZH
+ push __tmp_reg__
+ ret
+#else
+ ijmp
+#endif
+ .size _U(longjmp), . - _U(longjmp)
+
+
+
+/*
+ * _CPU_Context_save_fp_context
+ *
+ * This routine is responsible for saving the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+)
+{
+}
+*/
+
+ PUBLIC(_CPU_Context_save_fp)
+
+SYM(_CPU_Context_save_fp):
+ ret
+
+
+
+
+
+
+
+/*
+ * _CPU_Context_restore_fp_context
+ *
+ * This routine is responsible for restoring the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+)
+{
+}
+*/
+
+
+ PUBLIC(_CPU_Context_restore_fp)
+
+SYM(_CPU_Context_restore_fp):
+ ret
+
+
+
+/* _CPU_Context_switch
+ *
+ * This routine performs a normal non-FP context switch.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+*/
+
+ PUBLIC(_CPU_Context_switch)
+SYM(_CPU_Context_switch):
+ mov r26, r24 /*r26,r27 is X*/
+ mov r27, r25
+ mov r24, r22
+ mov r25, r23
+ /*save registers*/
+#if 1
+/*if this section is removed there is a problem.*/
+/*debug section start*/
+ pop r22
+ pop r23
+ push r22
+ push r23
+/*debug section end*/
+#endif
+
+ push r2
+ push r3
+ push r4
+ push r5
+ push r6
+ push r7
+ push r8
+ push r9
+ push r10
+ push r11
+ push r12
+ push r13
+ push r14
+ push r15
+ push r16
+ push r17
+
+ push r28
+ push r29
+
+ /*load sreg*/
+ lds r23,0x5f /*load sreg*/
+ /*disable interrupts*/
+ cli
+ /*load stack pointer*/
+ lds r22,0x5d /*spl*/
+ lds r21,0x5e /*sph*/
+ /*save sreg and sp to context struct*/
+
+ /*save low then high byte --- verify this delete when verified*/
+ st X+, r22
+ st X+, r21
+ st X, r23
+
+ PUBLIC(_CPU_Context_restore)
+
+SYM(_CPU_Context_restore):
+ mov r26,r24 /* R26/27 are X */
+ mov r27,r25
+
+ /*restore stack pointer*/
+ ld r25, X+
+ ld r24, X+
+ sts 0x5E,r24 /*sph*/
+ sts 0x5D ,r25 /*spl*/
+ /*restore registers from stack*/
+
+
+ pop r29
+ pop r28
+
+
+ pop r17
+ pop r16
+ pop r15
+ pop r14
+ pop r13
+ pop r12
+ pop r11
+ pop r10
+ pop r9
+ pop r8
+ pop r7
+ pop r6
+ pop r5
+ pop r4
+ pop r3
+ pop r2
+
+ /*restore sreg*/
+ ld r25, X
+ sts 0x5f,r25 /*sreg*/
+ pop r30
+ pop r31
+ IJMP
+ ret
+
+
+
+/*PAGE
+ *
+ * _CPU_Context_Initialize
+ *
+ * This kernel routine initializes the basic non-FP context area associated
+ * with each thread.
+ *
+ * Input parameters:
+ * the_context - pointer to the context area
+ * stack_base - address of memory for the SPARC
+ * size - size in bytes of the stack area
+ * new_level - interrupt level for this context area
+ * entry_point - the starting execution point for this this context
+ * is_fp - TRUE if this context is associated with an FP thread
+ *
+ * the_context is in r25,r24
+ * entry point is in r13,r12
+ * stack base is in r23, r22
+ * size is in r21, r20, r19,r18
+ * newleve is in r14,r15, r16, 17
+ *
+ *
+ * Output parameters: NONE
+ */
+
+ PUBLIC(_CPU_Context_Initialize)
+SYM(_CPU_Context_Initialize):
+ //save caller saved regs
+ PUSH R10
+ PUSH R11
+ PUSH R12
+ PUSH R13
+ PUSH R14
+ PUSH R15
+ PUSH R16
+ PUSH R17
+ PUSH R28
+ PUSH R29
+ //calculate new stack pointer
+ ADD R22, R18
+ ADC R23, R19
+ MOV R26, R22
+ MOV R27, R23
+ //Initialize stack with entry point
+ ST -X, R13
+ ST -X, R12
+ //store new stack pointer in context control
+ SBIW R26, 0X13 /*subtract 33 to account for registers*/
+ MOV R28, R24
+ MOV R29, R25
+ STD Y+1, R27 //save stack pointer high to context control
+ ST Y, R26 //save stack pointer low to context control
+ //set interrupt level in new context
+ LDI R18, 0 //set sreg in new context to zero
+ STD Y+2, R18 //interrupts not enabled
+ MOV R18, R14
+ CPI R18, 0
+ BRNE NEW_LEVEL_ZERO
+ LDI R18, 0X80 //set sreg in new context to 0x80
+ STD Y+2, R18 //interupts enabled
+NEW_LEVEL_ZERO:
+ //restore caller saved regs
+ POP R29
+ POP R28
+ POP R17
+ POP R16
+ POP R15
+ POP R14
+ POP R13
+ POP R12
+ POP R11
+ POP R10
+ RET
+
+
+
+/* void __ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+
+
+void _ISR_Handler(void)
+{
+
+*/
+ /*
+ * This discussion ignores a lot of the ugly details in a real
+ * implementation such as saving enough registers/state to be
+ * able to do something real. Keep in mind that the goal is
+ * to invoke a user's ISR handler which is written in C and
+ * uses a certain set of registers.
+ *
+ * Also note that the exact order is to a large extent flexible.
+ * Hardware will dictate a sequence for a certain subset of
+ * _ISR_Handler while requirements for setting
+ */
+
+ /*
+ * At entry to "common" _ISR_Handler, the vector number must be
+ * available. On some CPUs the hardware puts either the vector
+ * number or the offset into the vector table for this ISR in a
+ * known place. If the hardware does not give us this information,
+ * then the assembly portion of RTEMS for this port will contain
+ * a set of distinct interrupt entry points which somehow place
+ * the vector number in a known place (which is safe if another
+ * interrupt nests this one) and branches to _ISR_Handler.
+ *
+ * save some or all context on stack
+ * may need to save some special interrupt information for exit
+ *
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if ( _ISR_Nest_level == 0 )
+ * switch to software interrupt stack
+ * #endif
+ *
+ * _ISR_Nest_level++;
+ *
+ * _Thread_Dispatch_disable_level++;
+ *
+ * (*_ISR_Vector_table[ vector ])( vector );
+ *
+ * _Thread_Dispatch_disable_level--;
+ *
+ * --_ISR_Nest_level;
+ *
+ * if ( _ISR_Nest_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_disable_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_necessary ) {
+ * call _Thread_Dispatch() or prepare to return to _ISR_Dispatch
+ * prepare to get out of interrupt
+ * return from interrupt (maybe to _ISR_Dispatch)
+ *
+ * LABEL "exit interrupt (simple case):
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if outermost interrupt
+ * restore stack
+ * #endif
+ * prepare to get out of interrupt
+ * return from interrupt
+ */
+/*} */
+ PUBLIC(_ISR_Handler)
+
+SYM(_ISR_Handler):
+ ret
diff --git a/cpukit/score/cpu/avr/preinstall.am b/cpukit/score/cpu/avr/preinstall.am
new file mode 100644
index 0000000000..d41e75ffa1
--- /dev/null
+++ b/cpukit/score/cpu/avr/preinstall.am
@@ -0,0 +1,642 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/avr.h: rtems/score/avr.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/avr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/avr.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
+$(PROJECT_INCLUDE)/avr/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/avr
+ @: > $(PROJECT_INCLUDE)/avr/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/avr/$(dirstamp)
+
+$(PROJECT_INCLUDE)/avr/boot.h: avr/boot.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/boot.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/boot.h
+
+$(PROJECT_INCLUDE)/avr/common.h: avr/common.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/common.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/common.h
+
+$(PROJECT_INCLUDE)/avr/crc16.h: avr/crc16.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/crc16.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/crc16.h
+
+$(PROJECT_INCLUDE)/avr/delay.h: avr/delay.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/delay.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/delay.h
+
+$(PROJECT_INCLUDE)/avr/eeprom.h: avr/eeprom.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/eeprom.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/eeprom.h
+
+$(PROJECT_INCLUDE)/avr/fuse.h: avr/fuse.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/fuse.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/fuse.h
+
+$(PROJECT_INCLUDE)/avr/interrupt.h: avr/interrupt.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/interrupt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/interrupt.h
+
+$(PROJECT_INCLUDE)/avr/io1200.h: avr/io1200.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io1200.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io1200.h
+
+$(PROJECT_INCLUDE)/avr/io2313.h: avr/io2313.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io2313.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io2313.h
+
+$(PROJECT_INCLUDE)/avr/io2323.h: avr/io2323.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io2323.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io2323.h
+
+$(PROJECT_INCLUDE)/avr/io2333.h: avr/io2333.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io2333.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io2333.h
+
+$(PROJECT_INCLUDE)/avr/io2343.h: avr/io2343.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io2343.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io2343.h
+
+$(PROJECT_INCLUDE)/avr/io43u32x.h: avr/io43u32x.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io43u32x.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io43u32x.h
+
+$(PROJECT_INCLUDE)/avr/io43u35x.h: avr/io43u35x.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io43u35x.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io43u35x.h
+
+$(PROJECT_INCLUDE)/avr/io4414.h: avr/io4414.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io4414.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io4414.h
+
+$(PROJECT_INCLUDE)/avr/io4433.h: avr/io4433.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io4433.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io4433.h
+
+$(PROJECT_INCLUDE)/avr/io4434.h: avr/io4434.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io4434.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io4434.h
+
+$(PROJECT_INCLUDE)/avr/io76c711.h: avr/io76c711.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io76c711.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io76c711.h
+
+$(PROJECT_INCLUDE)/avr/io8515.h: avr/io8515.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io8515.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io8515.h
+
+$(PROJECT_INCLUDE)/avr/io8534.h: avr/io8534.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io8534.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io8534.h
+
+$(PROJECT_INCLUDE)/avr/io8535.h: avr/io8535.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io8535.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io8535.h
+
+$(PROJECT_INCLUDE)/avr/io86r401.h: avr/io86r401.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io86r401.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io86r401.h
+
+$(PROJECT_INCLUDE)/avr/io90pwm1.h: avr/io90pwm1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwm1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwm1.h
+
+$(PROJECT_INCLUDE)/avr/io90pwm216.h: avr/io90pwm216.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwm216.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwm216.h
+
+$(PROJECT_INCLUDE)/avr/io90pwm2b.h: avr/io90pwm2b.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwm2b.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwm2b.h
+
+$(PROJECT_INCLUDE)/avr/io90pwm316.h: avr/io90pwm316.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwm316.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwm316.h
+
+$(PROJECT_INCLUDE)/avr/io90pwm3b.h: avr/io90pwm3b.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwm3b.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwm3b.h
+
+$(PROJECT_INCLUDE)/avr/io90pwm81.h: avr/io90pwm81.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwm81.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwm81.h
+
+$(PROJECT_INCLUDE)/avr/io90pwmx.h: avr/io90pwmx.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90pwmx.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90pwmx.h
+
+$(PROJECT_INCLUDE)/avr/io90scr100.h: avr/io90scr100.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io90scr100.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io90scr100.h
+
+$(PROJECT_INCLUDE)/avr/ioa6289.h: avr/ioa6289.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/ioa6289.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/ioa6289.h
+
+$(PROJECT_INCLUDE)/avr/ioat94k.h: avr/ioat94k.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/ioat94k.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/ioat94k.h
+
+$(PROJECT_INCLUDE)/avr/iocan128.h: avr/iocan128.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iocan128.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iocan128.h
+
+$(PROJECT_INCLUDE)/avr/iocan32.h: avr/iocan32.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iocan32.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iocan32.h
+
+$(PROJECT_INCLUDE)/avr/iocan64.h: avr/iocan64.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iocan64.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iocan64.h
+
+$(PROJECT_INCLUDE)/avr/iocanxx.h: avr/iocanxx.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iocanxx.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iocanxx.h
+
+$(PROJECT_INCLUDE)/avr/io.h: avr/io.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/io.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/io.h
+
+$(PROJECT_INCLUDE)/avr/iom103.h: avr/iom103.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom103.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom103.h
+
+$(PROJECT_INCLUDE)/avr/iom1280.h: avr/iom1280.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom1280.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom1280.h
+
+$(PROJECT_INCLUDE)/avr/iom1281.h: avr/iom1281.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom1281.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom1281.h
+
+$(PROJECT_INCLUDE)/avr/iom1284p.h: avr/iom1284p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom1284p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom1284p.h
+
+$(PROJECT_INCLUDE)/avr/iom128.h: avr/iom128.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom128.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom128.h
+
+$(PROJECT_INCLUDE)/avr/iom128rfa1.h: avr/iom128rfa1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom128rfa1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom128rfa1.h
+
+$(PROJECT_INCLUDE)/avr/iom161.h: avr/iom161.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom161.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom161.h
+
+$(PROJECT_INCLUDE)/avr/iom162.h: avr/iom162.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom162.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom162.h
+
+$(PROJECT_INCLUDE)/avr/iom163.h: avr/iom163.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom163.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom163.h
+
+$(PROJECT_INCLUDE)/avr/iom164.h: avr/iom164.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom164.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom164.h
+
+$(PROJECT_INCLUDE)/avr/iom165.h: avr/iom165.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom165.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom165.h
+
+$(PROJECT_INCLUDE)/avr/iom165p.h: avr/iom165p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom165p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom165p.h
+
+$(PROJECT_INCLUDE)/avr/iom168.h: avr/iom168.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom168.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom168.h
+
+$(PROJECT_INCLUDE)/avr/iom168p.h: avr/iom168p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom168p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom168p.h
+
+$(PROJECT_INCLUDE)/avr/iom169.h: avr/iom169.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom169.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom169.h
+
+$(PROJECT_INCLUDE)/avr/iom169p.h: avr/iom169p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom169p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom169p.h
+
+$(PROJECT_INCLUDE)/avr/iom16.h: avr/iom16.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom16.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom16.h
+
+$(PROJECT_INCLUDE)/avr/iom16hva.h: avr/iom16hva.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom16hva.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom16hva.h
+
+$(PROJECT_INCLUDE)/avr/iom16m1.h: avr/iom16m1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom16m1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom16m1.h
+
+$(PROJECT_INCLUDE)/avr/iom16u4.h: avr/iom16u4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom16u4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom16u4.h
+
+$(PROJECT_INCLUDE)/avr/iom2560.h: avr/iom2560.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom2560.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom2560.h
+
+$(PROJECT_INCLUDE)/avr/iom2561.h: avr/iom2561.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom2561.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom2561.h
+
+$(PROJECT_INCLUDE)/avr/iom323.h: avr/iom323.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom323.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom323.h
+
+$(PROJECT_INCLUDE)/avr/iom324.h: avr/iom324.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom324.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom324.h
+
+$(PROJECT_INCLUDE)/avr/iom3250.h: avr/iom3250.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom3250.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom3250.h
+
+$(PROJECT_INCLUDE)/avr/iom325.h: avr/iom325.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom325.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom325.h
+
+$(PROJECT_INCLUDE)/avr/iom328p.h: avr/iom328p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom328p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom328p.h
+
+$(PROJECT_INCLUDE)/avr/iom3290.h: avr/iom3290.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom3290.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom3290.h
+
+$(PROJECT_INCLUDE)/avr/iom329.h: avr/iom329.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom329.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom329.h
+
+$(PROJECT_INCLUDE)/avr/iom32c1.h: avr/iom32c1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom32c1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom32c1.h
+
+$(PROJECT_INCLUDE)/avr/iom32.h: avr/iom32.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom32.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom32.h
+
+$(PROJECT_INCLUDE)/avr/iom32hvb.h: avr/iom32hvb.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom32hvb.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom32hvb.h
+
+$(PROJECT_INCLUDE)/avr/iom32m1.h: avr/iom32m1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom32m1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom32m1.h
+
+$(PROJECT_INCLUDE)/avr/iom32u4.h: avr/iom32u4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom32u4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom32u4.h
+
+$(PROJECT_INCLUDE)/avr/iom32u6.h: avr/iom32u6.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom32u6.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom32u6.h
+
+$(PROJECT_INCLUDE)/avr/iom406.h: avr/iom406.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom406.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom406.h
+
+$(PROJECT_INCLUDE)/avr/iom48.h: avr/iom48.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom48.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom48.h
+
+$(PROJECT_INCLUDE)/avr/iom48p.h: avr/iom48p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom48p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom48p.h
+
+$(PROJECT_INCLUDE)/avr/iom640.h: avr/iom640.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom640.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom640.h
+
+$(PROJECT_INCLUDE)/avr/iom644.h: avr/iom644.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom644.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom644.h
+
+$(PROJECT_INCLUDE)/avr/iom6450.h: avr/iom6450.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom6450.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom6450.h
+
+$(PROJECT_INCLUDE)/avr/iom645.h: avr/iom645.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom645.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom645.h
+
+$(PROJECT_INCLUDE)/avr/iom6490.h: avr/iom6490.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom6490.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom6490.h
+
+$(PROJECT_INCLUDE)/avr/iom649.h: avr/iom649.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom649.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom649.h
+
+$(PROJECT_INCLUDE)/avr/iom64c1.h: avr/iom64c1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom64c1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom64c1.h
+
+$(PROJECT_INCLUDE)/avr/iom64.h: avr/iom64.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom64.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom64.h
+
+$(PROJECT_INCLUDE)/avr/iom64m1.h: avr/iom64m1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom64m1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom64m1.h
+
+$(PROJECT_INCLUDE)/avr/iom8515.h: avr/iom8515.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom8515.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom8515.h
+
+$(PROJECT_INCLUDE)/avr/iom8535.h: avr/iom8535.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom8535.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom8535.h
+
+$(PROJECT_INCLUDE)/avr/iom88.h: avr/iom88.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom88.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom88.h
+
+$(PROJECT_INCLUDE)/avr/iom88p.h: avr/iom88p.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom88p.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom88p.h
+
+$(PROJECT_INCLUDE)/avr/iom8.h: avr/iom8.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom8.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom8.h
+
+$(PROJECT_INCLUDE)/avr/iom8hva.h: avr/iom8hva.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iom8hva.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iom8hva.h
+
+$(PROJECT_INCLUDE)/avr/iomx8.h: avr/iomx8.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iomx8.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iomx8.h
+
+$(PROJECT_INCLUDE)/avr/iomxx0_1.h: avr/iomxx0_1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iomxx0_1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iomxx0_1.h
+
+$(PROJECT_INCLUDE)/avr/iomxx4.h: avr/iomxx4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iomxx4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iomxx4.h
+
+$(PROJECT_INCLUDE)/avr/iomxxhva.h: avr/iomxxhva.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iomxxhva.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iomxxhva.h
+
+$(PROJECT_INCLUDE)/avr/iotn11.h: avr/iotn11.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn11.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn11.h
+
+$(PROJECT_INCLUDE)/avr/iotn12.h: avr/iotn12.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn12.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn12.h
+
+$(PROJECT_INCLUDE)/avr/iotn13a.h: avr/iotn13a.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn13a.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn13a.h
+
+$(PROJECT_INCLUDE)/avr/iotn13.h: avr/iotn13.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn13.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn13.h
+
+$(PROJECT_INCLUDE)/avr/iotn15.h: avr/iotn15.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn15.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn15.h
+
+$(PROJECT_INCLUDE)/avr/iotn167.h: avr/iotn167.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn167.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn167.h
+
+$(PROJECT_INCLUDE)/avr/iotn22.h: avr/iotn22.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn22.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn22.h
+
+$(PROJECT_INCLUDE)/avr/iotn2313.h: avr/iotn2313.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn2313.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn2313.h
+
+$(PROJECT_INCLUDE)/avr/iotn24.h: avr/iotn24.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn24.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn24.h
+
+$(PROJECT_INCLUDE)/avr/iotn25.h: avr/iotn25.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn25.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn25.h
+
+$(PROJECT_INCLUDE)/avr/iotn261.h: avr/iotn261.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn261.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn261.h
+
+$(PROJECT_INCLUDE)/avr/iotn26.h: avr/iotn26.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn26.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn26.h
+
+$(PROJECT_INCLUDE)/avr/iotn28.h: avr/iotn28.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn28.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn28.h
+
+$(PROJECT_INCLUDE)/avr/iotn43u.h: avr/iotn43u.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn43u.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn43u.h
+
+$(PROJECT_INCLUDE)/avr/iotn44.h: avr/iotn44.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn44.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn44.h
+
+$(PROJECT_INCLUDE)/avr/iotn45.h: avr/iotn45.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn45.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn45.h
+
+$(PROJECT_INCLUDE)/avr/iotn461.h: avr/iotn461.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn461.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn461.h
+
+$(PROJECT_INCLUDE)/avr/iotn48.h: avr/iotn48.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn48.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn48.h
+
+$(PROJECT_INCLUDE)/avr/iotn84.h: avr/iotn84.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn84.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn84.h
+
+$(PROJECT_INCLUDE)/avr/iotn85.h: avr/iotn85.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn85.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn85.h
+
+$(PROJECT_INCLUDE)/avr/iotn861.h: avr/iotn861.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn861.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn861.h
+
+$(PROJECT_INCLUDE)/avr/iotn87.h: avr/iotn87.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn87.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn87.h
+
+$(PROJECT_INCLUDE)/avr/iotn88.h: avr/iotn88.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotn88.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotn88.h
+
+$(PROJECT_INCLUDE)/avr/iotnx4.h: avr/iotnx4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotnx4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotnx4.h
+
+$(PROJECT_INCLUDE)/avr/iotnx5.h: avr/iotnx5.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotnx5.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotnx5.h
+
+$(PROJECT_INCLUDE)/avr/iotnx61.h: avr/iotnx61.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iotnx61.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iotnx61.h
+
+$(PROJECT_INCLUDE)/avr/iousb1286.h: avr/iousb1286.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousb1286.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousb1286.h
+
+$(PROJECT_INCLUDE)/avr/iousb1287.h: avr/iousb1287.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousb1287.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousb1287.h
+
+$(PROJECT_INCLUDE)/avr/iousb162.h: avr/iousb162.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousb162.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousb162.h
+
+$(PROJECT_INCLUDE)/avr/iousb646.h: avr/iousb646.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousb646.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousb646.h
+
+$(PROJECT_INCLUDE)/avr/iousb647.h: avr/iousb647.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousb647.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousb647.h
+
+$(PROJECT_INCLUDE)/avr/iousb82.h: avr/iousb82.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousb82.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousb82.h
+
+$(PROJECT_INCLUDE)/avr/iousbxx2.h: avr/iousbxx2.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousbxx2.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousbxx2.h
+
+$(PROJECT_INCLUDE)/avr/iousbxx6_7.h: avr/iousbxx6_7.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iousbxx6_7.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iousbxx6_7.h
+
+$(PROJECT_INCLUDE)/avr/iox128a1.h: avr/iox128a1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox128a1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox128a1.h
+
+$(PROJECT_INCLUDE)/avr/iox128a3.h: avr/iox128a3.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox128a3.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox128a3.h
+
+$(PROJECT_INCLUDE)/avr/iox16a4.h: avr/iox16a4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox16a4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox16a4.h
+
+$(PROJECT_INCLUDE)/avr/iox16d4.h: avr/iox16d4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox16d4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox16d4.h
+
+$(PROJECT_INCLUDE)/avr/iox256a3b.h: avr/iox256a3b.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox256a3b.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox256a3b.h
+
+$(PROJECT_INCLUDE)/avr/iox256a3.h: avr/iox256a3.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox256a3.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox256a3.h
+
+$(PROJECT_INCLUDE)/avr/iox32a4.h: avr/iox32a4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox32a4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox32a4.h
+
+$(PROJECT_INCLUDE)/avr/iox32d4.h: avr/iox32d4.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox32d4.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox32d4.h
+
+$(PROJECT_INCLUDE)/avr/iox64a1.h: avr/iox64a1.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox64a1.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox64a1.h
+
+$(PROJECT_INCLUDE)/avr/iox64a3.h: avr/iox64a3.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/iox64a3.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/iox64a3.h
+
+$(PROJECT_INCLUDE)/avr/lock.h: avr/lock.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/lock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/lock.h
+
+$(PROJECT_INCLUDE)/avr/parity.h: avr/parity.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/parity.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/parity.h
+
+$(PROJECT_INCLUDE)/avr/pgmspace.h: avr/pgmspace.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/pgmspace.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/pgmspace.h
+
+$(PROJECT_INCLUDE)/avr/portpins.h: avr/portpins.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/portpins.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/portpins.h
+
+$(PROJECT_INCLUDE)/avr/power.h: avr/power.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/power.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/power.h
+
+$(PROJECT_INCLUDE)/avr/sfr_defs.h: avr/sfr_defs.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/sfr_defs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/sfr_defs.h
+
+$(PROJECT_INCLUDE)/avr/signal.h: avr/signal.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/signal.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/signal.h
+
+$(PROJECT_INCLUDE)/avr/sleep.h: avr/sleep.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/sleep.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/sleep.h
+
+$(PROJECT_INCLUDE)/avr/version.h: avr/version.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/version.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/version.h
+
+$(PROJECT_INCLUDE)/avr/wdt.h: avr/wdt.h $(PROJECT_INCLUDE)/avr/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/avr/wdt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/avr/wdt.h
+
diff --git a/cpukit/score/cpu/avr/rtems/asm.h b/cpukit/score/cpu/avr/rtems/asm.h
new file mode 100644
index 0000000000..80f2197e4a
--- /dev/null
+++ b/cpukit/score/cpu/avr/rtems/asm.h
@@ -0,0 +1,463 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/avr.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+/* Copyright (c) 2002, 2005, 2006, 2007 Marek Michalkiewicz
+ Copyright (c) 2006 Dmitry Xmelkov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/*
+ macros.inc - macros for use in assembler sources
+
+ Contributors:
+ Created by Marek Michalkiewicz <marekm@linux.org.pl>
+ */
+
+#include <avr/common.h>
+
+/* if not defined, assume old version with underscores */
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+/* the assembler line separator (just in case it ever changes) */
+#define _L $
+
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#define _U(x) CONCAT1(__USER_LABEL_PREFIX__, x)
+
+#define _R(x) CONCAT1(__REGISTER_PREFIX__, x)
+
+/* these should help to fix the "can't have function named r1()" bug
+ which may require adding '%' in front of register names. */
+
+#define r0 _R(r0)
+#define r1 _R(r1)
+#define r2 _R(r2)
+#define r3 _R(r3)
+#define r4 _R(r4)
+#define r5 _R(r5)
+#define r6 _R(r6)
+#define r7 _R(r7)
+#define r8 _R(r8)
+#define r9 _R(r9)
+#define r10 _R(r10)
+#define r11 _R(r11)
+#define r12 _R(r12)
+#define r13 _R(r13)
+#define r14 _R(r14)
+#define r15 _R(r15)
+#define r16 _R(r16)
+#define r17 _R(r17)
+#define r18 _R(r18)
+#define r19 _R(r19)
+#define r20 _R(r20)
+#define r21 _R(r21)
+#define r22 _R(r22)
+#define r23 _R(r23)
+#define r24 _R(r24)
+#define r25 _R(r25)
+#define r26 _R(r26)
+#define r27 _R(r27)
+#define r28 _R(r28)
+#define r29 _R(r29)
+#define r30 _R(r30)
+#define r31 _R(r31)
+
+#ifndef __tmp_reg__
+#define __tmp_reg__ r0
+#endif
+
+#ifndef __zero_reg__
+#define __zero_reg__ r1
+#endif
+
+#if __AVR_MEGA__
+ #define XJMP jmp
+ #define XCALL call
+#else
+ #define XJMP rjmp
+ #define XCALL rcall
+#endif
+
+/* used only by fplib/strtod.S - libgcc internal function calls */
+#define PROLOGUE_SAVES(offset) XJMP (__prologue_saves__ + 2 * (offset))
+#define EPILOGUE_RESTORES(offset) XJMP (__epilogue_restores__ + 2 * (offset))
+
+#if FLASHEND > 0x10000 /* ATmega103 */
+ #define BIG_CODE 1
+#else
+ #define BIG_CODE 0
+#endif
+
+#ifndef __AVR_HAVE_MOVW__
+# if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
+# define __AVR_HAVE_MOVW__ 1
+# endif
+#endif
+
+#ifndef __AVR_HAVE_LPMX__
+# if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
+# define __AVR_HAVE_LPMX__ 1
+# endif
+#endif
+
+#ifndef __AVR_HAVE_MUL__
+# if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
+# define __AVR_HAVE_MUL__ 1
+# endif
+#endif
+
+/*
+ Smart version of movw:
+ - uses "movw" if possible (supported by MCU, and both registers even)
+ - handles overlapping register pairs correctly
+ - no instruction generated if source and destination are the same
+ (may expand to 0, 1 or 2 instructions).
+ */
+
+.macro X_movw dst src
+ .L_movw_dst = -1
+ .L_movw_src = -1
+ .L_movw_n = 0
+ .irp reg, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, \
+ r10,r11,r12,r13,r14,r15,r16,r17,r18,r19, \
+ r20,r21,r22,r23,r24,r25,r26,r27,r28,r29, \
+ r30,r31
+ .ifc \reg,\dst
+ .L_movw_dst = .L_movw_n
+ .endif
+ .ifc \reg,\src
+ .L_movw_src = .L_movw_n
+ .endif
+ .L_movw_n = .L_movw_n + 1
+ .endr
+ .L_movw_n = 0
+ .irp reg, R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, \
+ R10,R11,R12,R13,R14,R15,R16,R17,R18,R19, \
+ R20,R21,R22,R23,R24,R25,R26,R27,R28,R29, \
+ R30,R31
+ .ifc \reg,\dst
+ .L_movw_dst = .L_movw_n
+ .endif
+ .ifc \reg,\src
+ .L_movw_src = .L_movw_n
+ .endif
+ .L_movw_n = .L_movw_n + 1
+ .endr
+ .if .L_movw_dst < 0
+ .L_movw_n = 0
+ .rept 32
+ .if \dst == .L_movw_n
+ .L_movw_dst = .L_movw_n
+ .endif
+ .L_movw_n = .L_movw_n + 1
+ .endr
+ .endif
+ .if .L_movw_src < 0
+ .L_movw_n = 0
+ .rept 32
+ .if \src == .L_movw_n
+ .L_movw_src = .L_movw_n
+ .endif
+ .L_movw_n = .L_movw_n + 1
+ .endr
+ .endif
+ .if (.L_movw_dst < 0) || (.L_movw_src < 0)
+ .err ; Invalid 'X_movw' arg.
+ .endif
+
+ .if ((.L_movw_src) - (.L_movw_dst)) /* different registers */
+ .if (((.L_movw_src) | (.L_movw_dst)) & 0x01)
+ .if (((.L_movw_src)-(.L_movw_dst)) & 0x80) /* src < dest */
+ mov (.L_movw_dst)+1, (.L_movw_src)+1
+ mov (.L_movw_dst), (.L_movw_src)
+ .else /* src > dest */
+ mov (.L_movw_dst), (.L_movw_src)
+ mov (.L_movw_dst)+1, (.L_movw_src)+1
+ .endif
+ .else /* both even -> overlap not possible */
+#if defined(__AVR_HAVE_MOVW__) && __AVR_HAVE_MOVW__
+ movw \dst, \src
+#else
+ mov (.L_movw_dst), (.L_movw_src)
+ mov (.L_movw_dst)+1, (.L_movw_src)+1
+#endif
+ .endif
+ .endif
+.endm
+
+/* Macro 'X_lpm' extends enhanced lpm instruction for classic chips.
+ Usage:
+ X_lpm reg, dst
+ where
+ reg is 0..31, r0..r31 or R0..R31
+ dst is z, Z, z+ or Z+
+ It is possible to omit both arguments.
+
+ Possible results for classic chips:
+ lpm
+ lpm / mov Rd,r0
+ lpm / adiw ZL,1
+ lpm / mov Rd,r0 / adiw ZL,1
+
+ For enhanced chips it is one instruction always.
+
+ ATTENTION: unlike enhanced chips SREG (S,V,N,Z,C) flags are
+ changed in case of 'Z+' dst. R0 is scratch.
+ */
+.macro X_lpm dst=r0, src=Z
+
+ /* dst evaluation */
+ .L_lpm_dst = -1
+
+ .L_lpm_n = 0
+ .irp reg, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, \
+ r10,r11,r12,r13,r14,r15,r16,r17,r18,r19, \
+ r20,r21,r22,r23,r24,r25,r26,r27,r28,r29, \
+ r30,r31
+ .ifc \reg,\dst
+ .L_lpm_dst = .L_lpm_n
+ .endif
+ .L_lpm_n = .L_lpm_n + 1
+ .endr
+
+ .L_lpm_n = 0
+ .irp reg, R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, \
+ R10,R11,R12,R13,R14,R15,R16,R17,R18,R19, \
+ R20,R21,R22,R23,R24,R25,R26,R27,R28,R29, \
+ R30,R31
+ .ifc \reg,\dst
+ .L_lpm_dst = .L_lpm_n
+ .endif
+ .L_lpm_n = .L_lpm_n + 1
+ .endr
+
+ .if .L_lpm_dst < 0
+ .L_lpm_n = 0
+ .rept 32
+ .if \dst == .L_lpm_n
+ .L_lpm_dst = .L_lpm_n
+ .endif
+ .L_lpm_n = .L_lpm_n + 1
+ .endr
+ .endif
+
+ .if (.L_lpm_dst < 0)
+ .err ; Invalid dst arg of 'X_lpm' macro.
+ .endif
+
+ /* src evaluation */
+ .L_lpm_src = -1
+ .L_lpm_n = 0
+ .irp reg, z,Z,z+,Z+
+ .ifc \reg,\src
+ .L_lpm_src = .L_lpm_n
+ .endif
+ .L_lpm_n = .L_lpm_n + 1
+ .endr
+
+ .if (.L_lpm_src < 0)
+ .err ; Invalid src arg of 'X_lpm' macro.
+ .endif
+
+ /* instruction(s) */
+ .if .L_lpm_src < 2
+ .if .L_lpm_dst == 0
+ lpm
+ .else
+#if defined(__AVR_HAVE_LPMX__) && __AVR_HAVE_LPMX__
+ lpm .L_lpm_dst, Z
+#else
+ lpm
+ mov .L_lpm_dst, r0
+#endif
+ .endif
+ .else
+ .if (.L_lpm_dst >= 30)
+ .err ; Registers 30 and 31 are inhibited as 'X_lpm *,Z+' dst.
+ .endif
+#if defined(__AVR_HAVE_LPMX__) && __AVR_HAVE_LPMX__
+ lpm .L_lpm_dst, Z+
+#else
+ lpm
+ .if .L_lpm_dst
+ mov .L_lpm_dst, r0
+ .endif
+ adiw r30, 1
+#endif
+ .endif
+.endm
+
+/*
+ LPM_R0_ZPLUS_INIT is used before the loop to initialize RAMPZ
+ for future devices with RAMPZ:Z auto-increment - [e]lpm r0, Z+.
+
+ LPM_R0_ZPLUS_NEXT is used inside the loop to load a byte from
+ the program memory at [RAMPZ:]Z to R0, and increment [RAMPZ:]Z.
+
+ The argument in both macros is a register that contains the
+ high byte (bits 23-16) of the address, bits 15-0 should be in
+ the Z (r31:r30) register. It can be any register except for:
+ r0, r1 (__zero_reg__ - assumed to always contain 0), r30, r31.
+ */
+
+ .macro LPM_R0_ZPLUS_INIT hhi
+#if __AVR_ENHANCED__
+ #if BIG_CODE
+ out AVR_RAMPZ_ADDR, \hhi
+ #endif
+#endif
+ .endm
+
+ .macro LPM_R0_ZPLUS_NEXT hhi
+#if __AVR_ENHANCED__
+ #if BIG_CODE
+ /* ELPM with RAMPZ:Z post-increment, load RAMPZ only once */
+ elpm r0, Z+
+ #else
+ /* LPM with Z post-increment, max 64K, no RAMPZ (ATmega83/161/163/32) */
+ lpm r0, Z+
+ #endif
+#else
+ #if BIG_CODE
+ /* ELPM without post-increment, load RAMPZ each time (ATmega103) */
+ out AVR_RAMPZ_ADDR, \hhi
+ elpm
+ adiw r30,1
+ adc \hhi, __zero_reg__
+ #else
+ /* LPM without post-increment, max 64K, no RAMPZ (AT90S*) */
+ lpm
+ adiw r30,1
+ #endif
+#endif
+ .endm
+
+#endif /* _RTEMS_ASM_H */
diff --git a/cpukit/score/cpu/avr/rtems/score/avr.h b/cpukit/score/cpu/avr/rtems/score/avr.h
new file mode 100644
index 0000000000..299b3f7fe1
--- /dev/null
+++ b/cpukit/score/cpu/avr/rtems/score/avr.h
@@ -0,0 +1,110 @@
+/**
+ * @file rtems/score/avr.h
+ */
+
+/*
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specified to the avr port.
+ *
+ * COPYRIGHT 2004, Ralf Corsepius, Ulm, Germany.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_AVR_H
+#define _RTEMS_SCORE_AVR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the NO CPU family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+#if defined(__AVR__)
+
+#if defined(__AVR_ARCH__)
+#if __AVR_ARCH__ == 1
+#define CPU_MODEL_NAME "avr1"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 2
+#define CPU_MODEL_NAME "avr2"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 3
+#define CPU_MODEL_NAME "avr3"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 4
+#define CPU_MODEL_NAME "avr4"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 5
+#define CPU_MODEL_NAME "avr5"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 25
+#define CPU_MODEL_NAME "avr25"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 31
+#define CPU_MODEL_NAME "avr31"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 35
+#define CPU_MODEL_NAME "avr35"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 51
+#define CPU_MODEL_NAME "avr51"
+#define AVR_HAS_FPU 1
+
+#elif __AVR_ARCH__ == 6
+#define CPU_MODEL_NAME "avr6"
+#define AVR_HAS_FPU 1
+
+#else
+#error "Unsupported __AVR_ARCH__"
+#endif
+#else
+#error "__AVR_ARCH__ undefined"
+#endif
+
+#else
+
+#error "Unsupported CPU Model"
+
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "avr"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_AVR_H */
diff --git a/cpukit/score/cpu/avr/rtems/score/cpu.h b/cpukit/score/cpu/avr/rtems/score/cpu.h
new file mode 100644
index 0000000000..95d5698ed2
--- /dev/null
+++ b/cpukit/score/cpu/avr/rtems/score/cpu.h
@@ -0,0 +1,1162 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the AVR
+ * processor.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/avr.h>
+#include <avr/common.h>
+
+/* conditional compilation parameters */
+
+#ifndef RTEMS_USE_16_BIT_OBJECT
+#define RTEMS_USE_16_BIT_OBJECT
+#endif
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * Basically this is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ * [NOTE: In general, the _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls _Thread_Enable_dispatch which in turns calls
+ * _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.]
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
+
+/*
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
+
+/*
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "AVR_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ *
+ * The CPU_SOFTWARE_FP is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if ( AVR_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+/*
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_ALL_TASKS_ARE_FP TRUE
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * 1. BSP provided
+ * 2. CPU dependent (if provided)
+ * 3. generic (if no BSP and no CPU dependent)
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * NOTE: Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_STRUCTURE_ALIGNMENT
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+
+/*
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+#ifndef ASM
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+typedef struct {
+ uint16_t stack_pointer;
+ uint8_t status; /* SREG */
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->stack_pointer
+
+
+
+
+typedef struct {
+ double some_float_register;
+} Context_Control_fp;
+
+typedef struct {
+ uint32_t special_interrupt_register;
+} CPU_Interrupt_frame;
+
+/*
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * _CPU_Initialize and copied into the task's FP context area during
+ * _CPU_Context_Initialize.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+#endif /* ASM */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/*
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_STACK_MINIMUM_SIZE 512
+
+/*
+ * Maximum priority of a thread. Note based from 0 which is the idle task.
+ */
+#define CPU_PRIORITY_MAXIMUM 15
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_ALIGNMENT 4
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_STACK_ALIGNMENT 0
+
+/*
+ * ISR handler macros
+ */
+
+/*
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_Initialize_vectors()
+
+/*
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in _level.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ do { \
+ (_isr_cookie) = SREG; \
+ __asm__ volatile ("cli"::); \
+ } while (0)
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * _level is not modified.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ do { \
+ SREG = _isr_cookie; \
+ __asm__ volatile ("sei"::); \
+ } while (0)
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ do { \
+ SREG=(_isr_cookie); \
+ __asm__ volatile("sei"::); \
+ (_isr_cookie) = SREG; \
+ __asm__ volatile("cli"::); \
+ } while (0)
+
+/*
+ * Map interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * The get routine usually must be implemented as a subroutine.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_ISR_Set_level( new_level ) \
+ { \
+ }
+
+#ifndef ASM
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * NOTE: This is_fp parameter is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+/*
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ \
+ do { \
+ uint16_t *_stack;\
+ _stack = (uint16_t) (_stack_base) + (uint16_t)(_size);\
+ (_the_context)->stack_pointer = _stack-1; \
+ *(_stack) = *(_entry_point); \
+ printk("the ret address is %x\n", *(uint16_t *)(_stack));\
+ printk("sp = 0x%x\nep = 0x%x\n",_stack, *(_entry_point)); \
+ printk("stack base = 0x%x\n size = 0x%x\n",_stack_base, _size);\
+ printk("struct starting address = 0x%x\n", _the_context);\
+ printk("struct stack pointer address = 0x%x\n",(_the_context)->stack_pointer);\
+ } while ( 0 )
+
+*/
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. Context_Restore should work most of the time. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( _the_context );
+
+/*
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other models include (1) not doing anything, and (2) putting
+ * a "null FP status word" in the correct place in the FP context.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/*
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/*
+ * This routine sets _output to the bit number of the first bit
+ * set in _value. _value is of CPU dependent type Priority_bit_map_Control.
+ * This type may be either 16 or 32 bits wide although only the 16
+ * least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * (1) What happens when run on a value of zero?
+ * (2) Bits may be numbered from MSB to LSB or vice-versa.
+ * (3) The numbering may be zero or one based.
+ * (4) The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
+ * _CPU_Priority_bits_index(). These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by _CPU_Priority_mask().
+ * The basic major and minor values calculated by _Priority_Major()
+ * and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for _Priority_Get_highest() to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+ * - a series of 16 bit test instructions
+ * - a "binary search using if's"
+ * - _number = 0
+ * if _value > 0x00ff
+ * _value >>=8
+ * _number = 8;
+ *
+ * if _value > 0x0000f
+ * _value >=8
+ * _number += 4
+ *
+ * _number += bit_set_table[ _value ]
+ *
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+
+#endif
+
+/* end of Bitfield handler macros */
+
+/*
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by _CPU_Bitfield_Find_first_bit(). See the discussion
+ * for that routine.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/*
+ * This routine translates the bit numbers returned by
+ * _CPU_Bitfield_Find_first_bit() into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*context_initialize asm-function*/
+
+void context_initialize(unsigned short* context,
+ unsigned short stack_add,
+ unsigned short entry_point);
+
+/*PAGE
+ *
+ * _CPU_Context_Initialize
+ *
+ * This kernel routine initializes the basic non-FP context area associated
+ * with each thread.
+ *
+ * Input parameters:
+ * the_context - pointer to the context area
+ * stack_base - address of memory for the SPARC
+ * size - size in bytes of the stack area
+ * new_level - interrupt level for this context area
+ * entry_point - the starting execution point for this this context
+ * is_fp - TRUE if this context is associated with an FP thread
+ *
+ * Output parameters: NONE
+ */
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/*
+*
+* _CPU_Push
+*
+* this routine pushes 2 bytes onto the stack
+*
+*
+*
+*
+*
+*
+*
+*/
+
+void _CPU_Push(uint16_t _SP_, uint16_t entry_point);
+
+
+
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Install_interrupt_stack
+ *
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * NOTE: It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void );
+
+/*
+ * _CPU_Thread_Idle_body
+ *
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * NOTE: It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/* The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * AVR Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/avr/rtems/score/cpu_asm.h b/cpukit/score/cpu/avr/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..a509b36ae6
--- /dev/null
+++ b/cpukit/score/cpu/avr/rtems/score/cpu_asm.h
@@ -0,0 +1,72 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Very loose template for an include file for the cpu_asm.? file
+ * if it is implemented as a ".S" file (preprocessed by cpp) instead
+ * of a ".s" file (preprocessed by gm4 or gasp).
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+/* pull in the generated offsets */
+
+#include <rtems/score/offsets.h>
+
+/*
+ * Hardware General Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Control Registers
+ */
+
+/* put something here */
+
+/*
+ * Calling Convention
+ */
+
+/* put something here */
+
+/*
+ * Temporary registers
+ */
+
+/* put something here */
+
+/*
+ * Floating Point Registers - SW Conventions
+ */
+
+/* put something here */
+
+/*
+ * Temporary floating point registers
+ */
+
+/* put something here */
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/avr/rtems/score/types.h b/cpukit/score/cpu/avr/rtems/score/types.h
new file mode 100644
index 0000000000..64f5343d5a
--- /dev/null
+++ b/cpukit/score/cpu/avr/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Intel
+ * avr processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void avr_isr;
+typedef void ( *avr_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/bfin/.cvsignore b/cpukit/score/cpu/bfin/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/bfin/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/bfin/ChangeLog b/cpukit/score/cpu/bfin/ChangeLog
new file mode 100644
index 0000000000..91b1514a05
--- /dev/null
+++ b/cpukit/score/cpu/bfin/ChangeLog
@@ -0,0 +1,232 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Assembler compatibility fixes.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.S, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-06-16 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * cpu_asm.S: Use SYM macro to be consistent with other ports.
+
+2010-04-20 Allan Hessenflow <allanh@kallisti.com>
+
+ * cpu_asm.S: L0-L3 were part of the interrupt context, but as
+ Mike Frysinger noted they were not being zeroed before calling
+ the C handlers. A patch that corrects this, as well as improving
+ some of the push/pop order to avoid stalls.
+
+2010-04-17 Allan Hessenflow <allanh@kallisti.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h: Fine tune registers saved in the
+ context. The sp and imask registers need to be saved. Also allocated
+ 12 bytes on the stack at thread entry as the abi requires that.
+
+2010-04-17 Mike Frysinger <vapier.adi@gmail.com>
+
+ * cpu.c: Blackfin ABI requires L registers to be 0 upon function entry.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am: Remove unused file.
+ * irq.c: Removed.
+
+2009-05-25 Allan Hessenflow <allanh@kallisti.com>
+
+ PR 1417/cpukit
+ * rtems/score/cpu.h: corrected _CPU_ISR_Flash implementation, added
+ core synchronization after all cli/sti.
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1385/cpukit
+ * cpu_asm.S: When the type rtems_boolean was switched to the C99 bool,
+ the size changed from 4 bytes to 1 byte. The interrupt dispatching
+ code accesses two boolean variables for scheduling purposes and the
+ assembly implementations of this code did not get updated.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Remove extraneous spaces.
+
+2008-09-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h: Convert to "bool".
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-15 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * ChangeLog: Add correct entry.
+
+2008-08-13 Allan Hessenflow <allanh@kallisti.com>
+
+ * cpu.c, cpu_asm.S, irq.c, rtems/score/cpu.h,
+ rtems/score/cpu_asm.h: reworked interrupt handling to fix
+ context switching.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2007-12-20 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Use correct register name.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, irq.c, rtems/score/cpu_asm.h: Sweep to make sure grep for
+ COPYRIGHT passes.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-09-10 Alain Schaefer <alani@easc.ch>
+
+ * cpu_asm.S: Fix two problems:
+ - CC bit has been clobbered and was not correctly restored
+ - bfin hardware does not allow to read instructions from the L1
+
+
+2007-09-10 Alain Schaefer <alani@easc.ch>
+
+ * rtems/bfin/bf533.h: Add more definitions.
+
+2007-05-31 Alain Schaefer <alani@easc.ch>
+
+ * rtems/score/cpu.h: Modifiy inline assembly language
+ constraints to use a data register as the CTL/STI
+ instructions requires. This is not only more correct,
+ it avoids GCC PR31787.
+
+2007-05-24 Alain Schaefer <alani@easc.ch>
+
+ * rtems/score/cpu.h: Fix incorrect interrupt mask.
+
+2007-04-17 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/bfin/bf533.h: Fix warnings about constants being too large.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-11-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/bfin/bf533.h, rtems/bfin/bfin.h: Remove stray whitespaces.
+ * rtems/score/bfin.h: Use __BFIN__ instead of BFIN.
+
+2006-11-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu_asm.S: Re-add HI, LO.
+
+2006-11-08 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * irq.c: Add missing newline.
+ * rtems/score/cpu.h: Eliminate hidden backspaces.
+
+2006-10-24 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/bfin/bfin.h: Eliminate hi, lo, HI, LO, and MK_BMSK.
+
+2006-10-24 Alain Schaefer <alani@easc.ch>
+
+ * Makefile.am, cpu.c, cpu_asm.S, preinstall.am, rtems/score/bfin.h:
+ Clean up rtems/score/bfin.h removing parts that are not needed by
+ RTEMS CPUkit to bfin specific .h files.
+ * rtems/bfin/bf533.h, rtems/bfin/bfin.h: New files.
+
+2006-10-23 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Use the default IDLE thread body.
+
+2006-10-23 Joel Sherrill <joel@OARcorp.com>
+
+ * .cvsignore, ChangeLog, Makefile.am, cpu.c, cpu_asm.S, irq.c,
+ preinstall.am, rtems/asm.h, rtems/score/bfin.h, rtems/score/cpu.h,
+ rtems/score/cpu_asm.h, rtems/score/types.h: New files.
+
+2006-10-20 Alain Schaefer <alani@easc.ch>
+
+ * all files : Initial version
diff --git a/cpukit/score/cpu/bfin/Makefile.am b/cpukit/score/cpu/bfin/Makefile.am
new file mode 100644
index 0000000000..4eebfcc7c6
--- /dev/null
+++ b/cpukit/score/cpu/bfin/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_bfindir = $(includedir)/rtems/bfin
+include_rtems_bfin_HEADERS = rtems/bfin/bfin.h rtems/bfin/bf533.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/bfin.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/bfin/cpu.c b/cpukit/score/cpu/bfin/cpu.c
new file mode 100644
index 0000000000..f342e75e44
--- /dev/null
+++ b/cpukit/score/cpu/bfin/cpu.c
@@ -0,0 +1,214 @@
+/* Blackfin CPU Dependent Source
+ *
+ * COPYRIGHT (c) 2006 by Atos Automacao Industrial Ltda.
+ * written by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/bfin.h>
+#include <rtems/bfin/bfin.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+
+extern void _ISR15_Handler(void);
+extern void _CPU_Emulation_handler(void);
+extern void _CPU_Reset_handler(void);
+extern void _CPU_NMI_handler(void);
+extern void _CPU_Exception_handler(void);
+extern void _CPU_Unhandled_Interrupt_handler(void);
+
+void _CPU_Initialize(void)
+{
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+
+
+
+ proc_ptr ignored;
+
+#if 0
+ /* occassionally useful debug stuff */
+ int i;
+ _CPU_ISR_install_raw_handler(0, _CPU_Emulation_handler, &ignored);
+ _CPU_ISR_install_raw_handler(1, _CPU_Reset_handler, &ignored);
+ _CPU_ISR_install_raw_handler(2, _CPU_NMI_handler, &ignored);
+ _CPU_ISR_install_raw_handler(3, _CPU_Exception_handler, &ignored);
+ for (i = 5; i < 15; i++)
+ _CPU_ISR_install_raw_handler(i, _CPU_Unhandled_Interrupt_handler, &ignored);
+#endif
+
+ /* install handler that will be used to call _Thread_Dispatch */
+ _CPU_ISR_install_raw_handler( 15, _ISR15_Handler, &ignored );
+ /* enable self nesting */
+ __asm__ __volatile__ ("syscfg = %0" : : "d" (0x00000004));
+}
+
+
+
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ /*
+ * This routine returns the current interrupt level.
+ */
+
+ register uint32_t _tmpimask;
+
+ /*read from the IMASK registers*/
+
+ _tmpimask = *((uint32_t*)IMASK);
+
+ return (_tmpimask & 0xffe0) ? 0 : 1;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ proc_ptr *interrupt_table = NULL;
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+
+ /* base of vector table on blackfin architecture */
+ interrupt_table = (void*)0xFFE02000;
+
+ *old_handler = interrupt_table[ vector ];
+ interrupt_table[ vector ] = new_handler;
+
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ proc_ptr ignored;
+
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+
+ _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
+}
+
+#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
+void *_CPU_Thread_Idle_body(uint32_t ignored)
+{
+ while (1) {
+ __asm__ __volatile__("ssync; idle; ssync");
+ }
+}
+#endif
+
+/*
+ * Copied from the arm port.
+ */
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ uint32_t stack_high; /* highest "stack aligned" address */
+ stack_high = ((uint32_t)(stack_base) + size);
+
+ /* blackfin abi requires caller to reserve 12 bytes on stack */
+ the_context->register_sp = stack_high - 12;
+ the_context->register_rets = (uint32_t) entry_point;
+ the_context->imask = new_level ? 0 : 0xffff;
+}
+
+
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
diff --git a/cpukit/score/cpu/bfin/cpu_asm.S b/cpukit/score/cpu/bfin/cpu_asm.S
new file mode 100644
index 0000000000..7944550a3c
--- /dev/null
+++ b/cpukit/score/cpu/bfin/cpu_asm.S
@@ -0,0 +1,582 @@
+/* cpu_asm.S
+ *
+ * This file contains the basic algorithms for all assembly code used
+ * in the Blackfin port of RTEMS. These algorithms must be implemented
+ * in assembly language
+ *
+ * Copyright (c) 2008 Kallisti Labs, Los Gatos, CA, USA
+ * written by Allan Hessenflow <allanh@kallisti.com>
+ *
+ * Based on earlier version:
+ *
+ * Copyright (c) 2006 by Atos Automacao Industrial Ltda.
+ * written by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/cpu_asm.h>
+#include <rtems/score/bfin.h>
+#include <rtems/bfin/bfin.h>
+#include <rtems/score/percpu.h>
+
+#define LO(con32) ((con32) & 0xFFFF)
+#define HI(con32) (((con32) >> 16) & 0xFFFF)
+
+
+#if 0
+/* some debug routines */
+ .globl SYM(_CPU_write_char);
+SYM(_CPU_write_char):
+ p0.h = 0xffc0;
+ p0.l = 0x0400;
+txWaitLoop:
+ r1 = w[p0 + 0x14];
+ cc = bittst(r1, 5);
+ if !cc jump txWaitLoop;
+ w[p0 + 0x00] = r0;
+ rts;
+
+ .globl SYM(_CPU_write_crlf);
+SYM(_CPU_write_crlf):
+ r0 = '\r';
+ [--sp] = rets;
+ call SYM(_CPU_write_char);
+ rets = [sp++];
+ r0 = '\n';
+ jump SYM(_CPU_write_char);
+
+SYM(_CPU_write_space):
+ r0 = ' ';
+ jump SYM(_CPU_write_char);
+
+ .globl SYM(_CPU_write_nybble);
+SYM(_CPU_write_nybble:)
+ r1 = 0x0f;
+ r0 = r0 & r1;
+ r0 += '0';
+ r1 = '9';
+ cc = r0 <= r1;
+ if cc jump SYM(_CPU_write_char);
+ r0 += 'a' - '0' - 10;
+ jump SYM(_CPU_write_char);
+
+ .globl SYM(_CPU_write_byte);
+SYM(_CPU_write_byte):
+ [--sp] = r0;
+ [--sp] = rets;
+ r0 >>= 4;
+ call SYM(_CPU_write_nybble);
+ rets = [sp++];
+ r0 = [sp++];
+ jump SYM(_CPU_write_nybble);
+
+SYM(_CPU_write_chawmp):
+ [--sp] = r0;
+ [--sp] = rets;
+ r0 >>= 8;
+ call SYM(_CPU_write_byte);
+ rets = [sp++];
+ r0 = [sp++];
+ jump SYM(_CPU_write_byte);
+
+SYM(_CPU_write_gawble):
+ [--sp] = r0;
+ [--sp] = rets;
+ r0 >>= 16;
+ call SYM(_CPU_write_chawmp);
+ rets = [sp++];
+ r0 = [sp++];
+ jump SYM(_CPU_write_chawmp);
+
+SYM(_CPU_dump_registers):
+ [--sp] = rets;
+ [--sp] = r0;
+ [--sp] = r1;
+ [--sp] = p0;
+ r0 = [sp + 8];
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = [sp + 4];
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = r2;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = r3;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = r4;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = r5;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = r6;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = r7;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_crlf);
+ r0 = [sp];
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = p1;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = p2;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = p3;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = p4;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = p5;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = fp;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_space);
+ r0 = sp;
+ r0 += 16;
+ call SYM(_CPU_write_gawble);
+ call SYM(_CPU_write_crlf);
+
+ p0 = [sp++];
+ r1 = [sp++];
+ r0 = [sp++];
+ rets = [sp++];
+ rts;
+
+ .globl SYM(_CPU_Exception_handler);
+SYM(_CPU_Exception_handler):
+ usp = sp;
+ sp.h = 0xffb0;
+ sp.l = 0x1000;
+ [--sp] = (r7:0,p5:0);
+
+ r0 = 'x';
+ call SYM(_CPU_write_char);
+ jump hcf;
+
+
+ .globl SYM(_CPU_Emulation_handler);
+SYM(_CPU_Emulation_handler):
+ usp = sp;
+ sp.h = 0xffb0;
+ sp.l = 0x1000;
+ [--sp] = (r7:0,p5:0);
+
+ r0 = 'e';
+ call SYM(_CPU_write_char);
+ jump hcf;
+
+ .globl SYM(_CPU_Reset_handler);
+SYM(_CPU_Reset_handler):
+ usp = sp;
+ sp.h = 0xffb0;
+ sp.l = 0x1000;
+ [--sp] = (r7:0,p5:0);
+
+ r0 = 'r';
+ call SYM(_CPU_write_char);
+ jump hcf;
+
+ .globl SYM(_CPU_NMI_handler);
+SYM(_CPU_NMI_handler):
+ usp = sp;
+ sp.h = 0xffb0;
+ sp.l = 0x1000;
+ [--sp] = (r7:0,p5:0);
+
+ r0 = 'n';
+ call SYM(_CPU_write_char);
+ jump hcf;
+
+ .globl SYM(_CPU_Unhandled_Interrupt_handler);
+SYM(_CPU_Unhandled_Interrupt_handler):
+ usp = sp;
+ sp.h = 0xffb0;
+ sp.l = 0x1000;
+ [--sp] = (r7:0,p5:0);
+
+ call SYM(_CPU_write_crlf);
+ r0 = 'i';
+ call SYM(_CPU_write_char);
+ p0.h = HI(IPEND);
+ p0.l = LO(IPEND);
+ r0 = [p0];
+ call SYM(_CPU_write_chawmp);
+ jump hcf;
+
+hcf:
+ idle;
+ jump hcf;
+
+#endif
+
+
+/* _CPU_Context_switch
+ *
+ * This routine performs a normal non-FP context switch.
+ *
+ * bfin Specific Information:
+ *
+ * For now we simply save all registers.
+ *
+ */
+
+/* make sure this sequence stays in sync with the definition for
+ Context_Control in rtems/score/cpu.h */
+ .globl SYM(_CPU_Context_switch)
+SYM(_CPU_Context_switch):
+ /* Start saving context R0 = current, R1=heir */
+ p0 = r0;
+ [p0++] = r4;
+ [p0++] = r5;
+ [p0++] = r6;
+ [p0++] = r7;
+
+ /* save pointer registers */
+ [p0++] = p3;
+ [p0++] = p4;
+ [p0++] = p5;
+ [p0++] = fp;
+ [p0++] = sp;
+
+ /* save rets */
+ r0 = rets;
+ [p0++] = r0;
+
+ /* save IMASK */
+ p1.h = HI(IMASK);
+ p1.l = LO(IMASK);
+ r0 = [p1];
+ [p0++] = r0;
+
+ p0 = r1;
+restore:
+ /* restore data registers */
+ r4 = [p0++];
+ r5 = [p0++];
+ r6 = [p0++];
+ r7 = [p0++];
+
+ /* restore pointer registers */
+ p3 = [p0++];
+ p4 = [p0++];
+ p5 = [p0++];
+ fp = [p0++];
+ sp = [p0++];
+
+ /* restore rets */
+ r0 = [p0++];
+ rets = r0;
+
+ /* restore IMASK */
+ r0 = [p0++];
+ p1.h = HI(IMASK);
+ p1.l = LO(IMASK);
+ [p1] = r0;
+
+ rts;
+
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ *
+ * Blackfin Specific Information:
+ *
+ * none
+ *
+ */
+ .globl SYM(_CPU_Context_restore)
+SYM(_CPU_Context_restore):
+ p0 = r0;
+ jump restore;
+
+
+ .globl SYM(_ISR_Handler)
+SYM(_ISR_Handler):
+ .extern SYM(_Thread_Dispatch_disable_level)
+ /* all interrupts are disabled at this point */
+ /* the following few items are pushed onto the task stack for at
+ most one interrupt; nested interrupts will be using the interrupt
+ stack for everything. */
+ [--sp] = astat;
+ [--sp] = p1;
+ [--sp] = p0;
+ [--sp] = r1;
+ [--sp] = r0;
+ p0.h = ISR_NEST_LEVEL;
+ p0.l = ISR_NEST_LEVEL;
+ r0 = [p0];
+ r0 += 1;
+ [p0] = r0;
+ cc = r0 <= 1 (iu);
+ if !cc jump noStackSwitch;
+ /* setup interrupt stack */
+ r0 = sp;
+ p0.h = INTERRUPT_STACK_HIGH;
+ p0.l = INTERRUPT_STACK_HIGH;
+ sp = [p0];
+ [--sp] = r0;
+noStackSwitch:
+ /* disable thread dispatch */
+ p0.h = SYM(_Thread_Dispatch_disable_level);
+ p0.l = SYM(_Thread_Dispatch_disable_level);
+ r0 = [p0];
+ r0 += 1;
+ [p0] = r0;
+
+ [--sp] = reti; /* interrupts are now enabled */
+
+ /* figure out what vector we are */
+ p0.h = HI(IPEND);
+ p0.l = LO(IPEND);
+ r1 = [p0];
+ /* we should only get here for events that require RTI to return */
+ r1 = r1 >> 5;
+ r0 = 4;
+ /* at least one bit must be set, so this loop will exit */
+vectorIDLoop:
+ r0 += 1;
+ r1 = rot r1 by -1;
+ if !cc jump vectorIDLoop;
+
+ [--sp] = r2;
+ p0.h = SYM(_ISR_Vector_table);
+ p0.l = SYM(_ISR_Vector_table);
+ r2 = [p0];
+ r1 = r0 << 2;
+ r1 = r1 + r2;
+ p0 = r1;
+ p0 = [p0];
+ cc = p0 == 0;
+ if cc jump noHandler;
+
+ /* r2, r0, r1, p0, p1, astat are already saved */
+ [--sp] = a1.x;
+ [--sp] = a1.w;
+ [--sp] = a0.x;
+ [--sp] = a0.w;
+ [--sp] = r3;
+ [--sp] = p3;
+ [--sp] = p2;
+ [--sp] = lc1;
+ [--sp] = lc0;
+ [--sp] = lt1;
+ [--sp] = lt0;
+ [--sp] = lb1;
+ [--sp] = lb0;
+ [--sp] = i3;
+ [--sp] = i2;
+ [--sp] = i1;
+ [--sp] = i0;
+ [--sp] = m3;
+ [--sp] = m2;
+ [--sp] = m1;
+ [--sp] = m0;
+ [--sp] = l3;
+ [--sp] = l2;
+ [--sp] = l1;
+ [--sp] = l0;
+ [--sp] = b3;
+ [--sp] = b2;
+ [--sp] = b1;
+ [--sp] = b0;
+ [--sp] = rets;
+ /* call user isr; r0 = vector number, r1 = frame pointer */
+ r1 = fp; /* is this really what should be passed here? */
+ r2 = 0;
+ l0 = r2;
+ l1 = r2;
+ l2 = r2;
+ l3 = r2;
+ sp += -12; /* bizarre abi... */
+ call (p0);
+ sp += 12;
+ rets = [sp++];
+ b0 = [sp++];
+ b1 = [sp++];
+ b2 = [sp++];
+ b3 = [sp++];
+ l0 = [sp++];
+ l1 = [sp++];
+ l2 = [sp++];
+ l3 = [sp++];
+ m0 = [sp++];
+ m1 = [sp++];
+ m2 = [sp++];
+ m3 = [sp++];
+ i0 = [sp++];
+ i1 = [sp++];
+ i2 = [sp++];
+ i3 = [sp++];
+ lb0 = [sp++];
+ lb1 = [sp++];
+ lt0 = [sp++];
+ lt1 = [sp++];
+ lc0 = [sp++];
+ lc1 = [sp++];
+ p2 = [sp++];
+ p3 = [sp++];
+ r3 = [sp++];
+ a0.w = [sp++];
+ a0.x = [sp++];
+ a1.w = [sp++];
+ a1.x = [sp++];
+
+noHandler:
+ r2 = [sp++];
+ /* this disables interrupts again */
+ reti = [sp++];
+
+ p0.h = ISR_NEST_LEVEL;
+ p0.l = ISR_NEST_LEVEL;
+ r0 = [p0];
+ r0 += -1;
+ [p0] = r0;
+ cc = r0 == 0;
+ if !cc jump noStackRestore;
+ sp = [sp];
+noStackRestore:
+
+ /* check this stuff to ensure context_switch_necessary and
+ isr_signals_to_thread_executing are being handled appropriately. */
+ p0.h = SYM(_Thread_Dispatch_disable_level);
+ p0.l = SYM(_Thread_Dispatch_disable_level);
+ r0 = [p0];
+ r0 += -1;
+ [p0] = r0;
+ cc = r0 == 0;
+ if !cc jump noDispatch
+
+ /* do thread dispatch if necessary */
+ p0.h = DISPATCH_NEEDED;
+ p0.l = DISPATCH_NEEDED;
+ r0 = B[p0] (Z);
+ cc = r0 == 0;
+ if cc jump noDispatch
+doDispatch:
+ r0 = 0;
+ B[p0] = r0;
+ raise 15;
+noDispatch:
+ r0 = [sp++];
+ r1 = [sp++];
+ p0 = [sp++];
+ p1 = [sp++];
+ astat = [sp++];
+ rti
+
+
+/* the approach here is for the main interrupt handler, when a dispatch is
+ wanted, to do a "raise 15". when the main interrupt handler does its
+ "rti", the "raise 15" takes effect and we end up here. we can now
+ safely call _Thread_Dispatch, and do an "rti" to get back to the
+ original interrupted function. this does require self-nesting to be
+ enabled; the maximum nest depth is the number of tasks. */
+ .global SYM(_ISR15_Handler)
+SYM(_ISR15_Handler):
+ [--sp] = reti;
+ [--sp] = rets;
+ [--sp] = astat;
+ [--sp] = a1.x;
+ [--sp] = a1.w;
+ [--sp] = a0.x;
+ [--sp] = a0.w;
+ [--sp] = r3;
+ [--sp] = r2;
+ [--sp] = r1;
+ [--sp] = r0;
+ [--sp] = p3;
+ [--sp] = p2;
+ [--sp] = p1;
+ [--sp] = p0;
+ [--sp] = lc1;
+ [--sp] = lc0;
+ [--sp] = lt1;
+ [--sp] = lt0;
+ [--sp] = lb1;
+ [--sp] = lb0;
+ [--sp] = i3;
+ [--sp] = i2;
+ [--sp] = i1;
+ [--sp] = i0;
+ [--sp] = m3;
+ [--sp] = m2;
+ [--sp] = m1;
+ [--sp] = m0;
+ [--sp] = l3;
+ [--sp] = l2;
+ [--sp] = l1;
+ [--sp] = l0;
+ [--sp] = b3;
+ [--sp] = b2;
+ [--sp] = b1;
+ [--sp] = b0;
+ r2 = 0;
+ l0 = r2;
+ l1 = r2;
+ l2 = r2;
+ l3 = r2;
+ sp += -12; /* bizarre abi... */
+ call SYM(_Thread_Dispatch);
+ sp += 12;
+ b0 = [sp++];
+ b1 = [sp++];
+ b2 = [sp++];
+ b3 = [sp++];
+ l0 = [sp++];
+ l1 = [sp++];
+ l2 = [sp++];
+ l3 = [sp++];
+ m0 = [sp++];
+ m1 = [sp++];
+ m2 = [sp++];
+ m3 = [sp++];
+ i0 = [sp++];
+ i1 = [sp++];
+ i2 = [sp++];
+ i3 = [sp++];
+ lb0 = [sp++];
+ lb1 = [sp++];
+ lt0 = [sp++];
+ lt1 = [sp++];
+ lc0 = [sp++];
+ lc1 = [sp++];
+ p0 = [sp++];
+ p1 = [sp++];
+ p2 = [sp++];
+ p3 = [sp++];
+ r0 = [sp++];
+ r1 = [sp++];
+ r2 = [sp++];
+ r3 = [sp++];
+ a0.w = [sp++];
+ a0.x = [sp++];
+ a1.w = [sp++];
+ a1.x = [sp++];
+ astat = [sp++];
+ rets = [sp++];
+ reti = [sp++];
+ rti;
+
diff --git a/cpukit/score/cpu/bfin/preinstall.am b/cpukit/score/cpu/bfin/preinstall.am
new file mode 100644
index 0000000000..10a77a59d9
--- /dev/null
+++ b/cpukit/score/cpu/bfin/preinstall.am
@@ -0,0 +1,58 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/bfin/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/bfin
+ @: > $(PROJECT_INCLUDE)/rtems/bfin/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/bfin/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/bfin/bfin.h: rtems/bfin/bfin.h $(PROJECT_INCLUDE)/rtems/bfin/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bfin/bfin.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bfin/bfin.h
+
+$(PROJECT_INCLUDE)/rtems/bfin/bf533.h: rtems/bfin/bf533.h $(PROJECT_INCLUDE)/rtems/bfin/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bfin/bf533.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bfin/bf533.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/bfin.h: rtems/score/bfin.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/bfin.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/bfin.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/bfin/rtems/asm.h b/cpukit/score/cpu/bfin/rtems/asm.h
new file mode 100644
index 0000000000..bca3141cb9
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/asm.h
@@ -0,0 +1,125 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/bfin.h>
+
+#ifndef __USER_LABEL_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all C program symbols.
+ */
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all register names.
+ */
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/** Use the right prefix for global labels. */
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/** Use the right prefix for registers. */
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+/** This macro is used to denote the beginning of a code declaration. */
+#define BEGIN_CODE_DCL .text
+/** This macro is used to denote the end of a code declaration. */
+#define END_CODE_DCL
+/** This macro is used to denote the beginning of a data declaration section. */
+#define BEGIN_DATA_DCL .data
+/** This macro is used to denote the end of a data declaration section. */
+#define END_DATA_DCL
+/** This macro is used to denote the beginning of a code section. */
+#define BEGIN_CODE .text
+/** This macro is used to denote the end of a code section. */
+#define END_CODE
+/** This macro is used to denote the beginning of a data section. */
+#define BEGIN_DATA
+/** This macro is used to denote the end of a data section. */
+#define END_DATA
+/** This macro is used to denote the beginning of the
+ * unitialized data section.
+ */
+#define BEGIN_BSS
+/** This macro is used to denote the end of the unitialized data section. */
+#define END_BSS
+/** This macro is used to denote the end of the assembly file. */
+#define END
+
+/**
+ * This macro is used to declare a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define PUBLIC(sym) .globl SYM (sym)
+
+/**
+ * This macro is used to prototype a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/bfin/rtems/bfin/bf533.h b/cpukit/score/cpu/bfin/rtems/bfin/bf533.h
new file mode 100644
index 0000000000..4a66bc5a38
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/bfin/bf533.h
@@ -0,0 +1,394 @@
+/* bfin.h
+ *
+ * This file defines basic MMR for the Blackfin 531/532/533 CPU.
+ * The MMR have been taken from the ADSP-BF533 Blackfin Processor
+ * Hardware Reference from Analog Devices. Mentioned Chapters
+ * refer to this Documentation.
+ *
+ * The Blackfins MMRs are divided into core MMRs (0xFFE0 0000–0xFFFF FFFF)
+ * and System MMRs (0xFFC0 0000–0xFFE0 0000). The core MMRs are defined
+ * in bfin.h which is included.
+ *
+ * COPYRIGHT (c) 2006.
+ * Atos Automacao Industrial LTDA.
+ * modified by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_BFIN_533_H
+#define _RTEMS_BFIN_533_H
+
+#include <rtems/bfin/bfin.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Clock and System Control Chapter 8 */
+#define PLL_CTL 0xFFC00000L
+#define PLL_DIV 0xFFC00004L
+#define VR_CTL 0xFFC00008L
+#define PLL_STAT 0xFFC0000CL
+#define PLL_LOCKCNT 0xFFC00010L
+#define SWRST 0xFFC00100L
+#define SYSCR 0xFFC00104L
+
+/* SPI Controller Chapter 10 */
+#define SPI_CTL 0xFFC00500L
+#define SPI_FLG 0xFFC00504L
+#define SPI_STAT 0xFFC00508L
+#define SPI_TDBR 0xFFC0050CL
+#define SPI_RDBR 0xFFC00510L
+#define SPI_BAUD 0xFFC00514L
+#define SPI_SHADOW 0xFFC00518L
+
+/* SPORT0 Controller */
+#define SPORT0_TCR1 0xFFC00800L
+#define SPORT0_TCR2 0xFFC00804L
+#define SPORT0_TCLKDIV 0xFFC00808L
+#define SPORT0_TFSDIV 0xFFC0080CL
+#define SPORT0_TX 0xFFC00810L
+#define SPORT0_RX 0xFFC00818L
+#define SPORT0_RCR1 0xFFC00820L
+#define SPORT0_RCR2 0xFFC00824L
+#define SPORT0_RCLKDIV 0xFFC00828L
+#define SPORT0_RFSDIV 0xFFC0082CL
+#define SPORT0_STAT 0xFFC00830L
+#define SPORT0_CHNL 0xFFC00834L
+#define SPORT0_MCMC1 0xFFC00838L
+#define SPORT0_MCMC2 0xFFC0083CL
+#define SPORT0_MTCS0 0xFFC00840L
+#define SPORT0_MTCS1 0xFFC00844L
+#define SPORT0_MTCS2 0xFFC00848L
+#define SPORT0_MTCS3 0xFFC0084CL
+#define SPORT0_MRCS0 0xFFC00850L
+#define SPORT0_MRCS1 0xFFC00854L
+#define SPORT0_MRCS2 0xFFC00858L
+#define SPORT0_MRCS3 0xFFC0085CL
+
+/* Parallel Peripheral Interface (PPI) Chapter 11 */
+
+#define PPI_CONTROL 0xFFC01000L
+#define PPI_STATUS 0xFFC01004L
+#define PPI_COUNT 0xFFC01008L
+#define PPI_DELAY 0xFFC0100CL
+#define PPI_FRAME 0xFFC01010L
+
+/********* PPI MASKS ***********/
+/* PPI_CONTROL Masks */
+#define PORT_EN 0x00000001
+#define PORT_DIR 0x00000002
+#define XFR_TYPE 0x0000000C
+#define PORT_CFG 0x00000030
+#define FLD_SEL 0x00000040
+#define PACK_EN 0x00000080
+#define DMA32 0x00000100
+#define SKIP_EN 0x00000200
+#define SKIP_EO 0x00000400
+#define DLENGTH 0x00003800
+#define DLEN_8 0x0
+#define DLEN(x) (((x-9) & 0x07) << 11)
+#define POL 0x0000C000
+
+/* PPI_STATUS Masks */
+#define FLD 0x00000400
+#define FT_ERR 0x00000800
+#define OVR 0x00001000
+#define UNDR 0x00002000
+#define ERR_DET 0x00004000
+#define ERR_NCOR 0x00008000
+
+/* SPORT1 Controller Chapter 12 */
+#define SPORT1_TCR1 0xFFC00900L
+#define SPORT1_TCR2 0xFFC00904L
+#define SPORT1_TCLKDIV 0xFFC00908L
+#define SPORT1_TFSDIV 0xFFC0090CL
+#define SPORT1_TX 0xFFC00910L
+#define SPORT1_RX 0xFFC00918L
+#define SPORT1_RCR1 0xFFC00920L
+#define SPORT1_RCR2 0xFFC00924L
+#define SPORT1_RCLKDIV 0xFFC00928L
+#define SPORT1_RFSDIV 0xFFC0092CL
+#define SPORT1_STAT 0xFFC00930L
+#define SPORT1_CHNL 0xFFC00934L
+#define SPORT1_MCMC1 0xFFC00938L
+#define SPORT1_MCMC2 0xFFC0093CL
+#define SPORT1_MTCS0 0xFFC00940L
+#define SPORT1_MTCS1 0xFFC00944L
+#define SPORT1_MTCS2 0xFFC00948L
+#define SPORT1_MTCS3 0xFFC0094CL
+#define SPORT1_MRCS0 0xFFC00950L
+#define SPORT1_MRCS1 0xFFC00954L
+#define SPORT1_MRCS2 0xFFC00958L
+#define SPORT1_MRCS3 0xFFC0095CL
+
+/* SPORTx_TCR1 Masks */
+#define TSPEN 0x0001
+#define ITCLK 0x0002
+#define TDTYPE 0x000C
+#define TLSBIT 0x0010
+#define ITFS 0x0200
+#define TFSR 0x0400
+#define DITFS 0x0800
+#define LTFS 0x1000
+#define LATFS 0x2000
+#define TCKFE 0x4000
+
+/* SPORTx_TCR2 Masks */
+#define SLEN 0x001F
+#define TXSE 0x0100
+#define TSFSE 0x0200
+#define TRFST 0x0400
+
+/* SPORTx_RCR1 Masks */
+#define RSPEN 0x0001
+#define IRCLK 0x0002
+#define RDTYPE 0x000C
+#define RULAW 0x0008
+#define RALAW 0x000C
+#define RLSBIT 0x0010
+#define IRFS 0x0200
+#define RFSR 0x0400
+#define LRFS 0x1000
+#define LARFS 0x2000
+#define RCKFE 0x4000
+
+/* SPORTx_RCR2 Masks */
+#define SLEN 0x001F
+#define RXSE 0x0100
+#define RSFSE 0x0200
+#define RRFST 0x0400
+
+/* SPORTx_STAT Masks */
+#define RXNE 0x0001
+#define RUVF 0x0002
+#define ROVF 0x0004
+#define TXF 0x0008
+#define TUVF 0x0010
+#define TOVF 0x0020
+#define TXHRE 0x0040
+
+/* SPORTx_MCMC1 Masks */
+#define WSIZE 0x0000F000
+#define WOFF 0x000003FF
+
+/* SPORTx_MCMC2 Masks */
+#define MCCRM 0x00000003
+#define MCDTXPE 0x00000004
+#define MCDRXPE 0x00000008
+#define MCMEN 0x00000010
+#define FSDR 0x00000080
+#define MFD 0x0000F000
+
+/* UART Controller Chapter 13 */
+#define UART_THR 0xFFC00400L
+#define UART_RBR 0xFFC00400L
+#define UART_DLL 0xFFC00400L
+#define UART_IER 0xFFC00404L
+#define UART_DLH 0xFFC00404L
+#define UART_IIR 0xFFC00408L
+#define UART_LCR 0xFFC0040CL
+#define UART_MCR 0xFFC00410L
+#define UART_LSR 0xFFC00414L
+#define UART_SCR 0xFFC0041CL
+#define UART_GCTL 0xFFC00424L
+
+/*
+ * UART CONTROLLER MASKS
+ */
+
+/* UART_LCR */
+#define DLAB 0x80
+#define SB 0x40
+#define STP 0x20
+#define EPS 0x10
+#define PEN 0x08
+#define STB 0x04
+#define WLS(x) ((x-5) & 0x03)
+
+#define DLAB_P 0x07
+#define SB_P 0x06
+#define STP_P 0x05
+#define EPS_P 0x04
+#define PEN_P 0x03
+#define STB_P 0x02
+#define WLS_P1 0x01
+#define WLS_P0 0x00
+
+/* UART_MCR */
+#define LOOP_ENA 0x10
+#define LOOP_ENA_P 0x04
+
+/* UART_LSR */
+#define TEMT 0x40
+#define THRE 0x20
+#define BI 0x10
+#define FE 0x08
+#define PE 0x04
+#define OE 0x02
+#define DR 0x01
+
+#define TEMP_P 0x06
+#define THRE_P 0x05
+#define BI_P 0x04
+#define FE_P 0x03
+#define PE_P 0x02
+#define OE_P 0x01
+#define DR_P 0x00
+
+/* UART_IER */
+#define ELSI 0x04
+#define ETBEI 0x02
+#define ERBFI 0x01
+
+#define ELSI_P 0x02
+#define ETBEI_P 0x01
+#define ERBFI_P 0x00
+
+/* UART_IIR */
+#define STATUS(x) ((x << 1) & 0x06)
+#define NINT 0x01
+#define STATUS_P1 0x02
+#define STATUS_P0 0x01
+#define NINT_P 0x00
+
+/* UART_GCTL */
+#define FFE 0x20
+#define FPE 0x10
+#define RPOLC 0x08
+#define TPOLC 0x04
+#define IREN 0x02
+#define UCEN 0x01
+
+#define FFE_P 0x05
+#define FPE_P 0x04
+#define RPOLC_P 0x03
+#define TPOLC_P 0x02
+#define IREN_P 0x01
+#define UCEN_P 0x00
+
+/* General Purpose IO Chapter 14*/
+#define FIO_FLAG_D 0xFFC00700L
+#define FIO_FLAG_C 0xFFC00704L
+#define FIO_FLAG_S 0xFFC00708L
+#define FIO_FLAG_T 0xFFC0070CL
+#define FIO_MASKA_D 0xFFC00710L
+#define FIO_MASKA_C 0xFFC00714L
+#define FIO_MASKA_S 0xFFC00718L
+#define FIO_MASKA_T 0xFFC0071CL
+#define FIO_MASKB_D 0xFFC00720L
+#define FIO_MASKB_C 0xFFC00724L
+#define FIO_MASKB_S 0xFFC00728L
+#define FIO_MASKB_T 0xFFC0072CL
+#define FIO_DIR 0xFFC00730L
+#define FIO_POLAR 0xFFC00734L
+#define FIO_EDGE 0xFFC00738L
+#define FIO_BOTH 0xFFC0073CL
+#define FIO_INEN 0xFFC00740L
+
+/* General Purpose IO Masks */
+#define PF0 0x0001
+#define PF1 0x0002
+#define PF2 0x0004
+#define PF3 0x0008
+#define PF4 0x0010
+#define PF5 0x0020
+#define PF6 0x0040
+#define PF7 0x0080
+#define PF8 0x0100
+#define PF9 0x0200
+#define PF10 0x0400
+#define PF11 0x0800
+#define PF12 0x1000
+#define PF13 0x2000
+#define PF14 0x4000
+#define PF15 0x8000
+
+
+/* TIMER 0, 1, 2 Chapter 15 */
+#define TIMER0_CONFIG 0xFFC00600L
+#define TIMER0_COUNTER 0xFFC00604L
+#define TIMER0_PERIOD 0xFFC00608L
+#define TIMER0_WIDTH 0xFFC0060CL
+
+#define TIMER1_CONFIG 0xFFC00610L
+#define TIMER1_COUNTER 0xFFC00614L
+#define TIMER1_PERIOD 0xFFC00618L
+#define TIMER1_WIDTH 0xFFC0061CL
+
+#define TIMER2_CONFIG 0xFFC00620L
+#define TIMER2_COUNTER 0xFFC00624L
+#define TIMER2_PERIOD 0xFFC00628L
+#define TIMER2_WIDTH 0xFFC0062CL
+
+#define TIMER_ENABLE 0xFFC00640L
+#define TIMER_DISABLE 0xFFC00644L
+#define TIMER_STATUS 0xFFC00648L
+
+/* Real Time Clock Chapter 16 */
+#define RTC_STAT 0xFFC00300L
+#define RTC_ICTL 0xFFC00304L
+#define RTC_ISTAT 0xFFC00308L
+#define RTC_SWCNT 0xFFC0030CL
+#define RTC_ALARM 0xFFC00310L
+#define RTC_FAST 0xFFC00314L
+#define RTC_PREN 0xFFC00314L
+
+/* RTC_FAST Mask (RTC_PREN Mask) */
+#define ENABLE_PRESCALE 0x00000001
+#define PREN 0x00000001
+
+/* Asynchronous Memory Controller EBUI, Chapter 17*/
+#define EBIU_AMGCTL 0xFFC00A00L
+#define EBIU_AMBCTL0 0xFFC00A04L
+#define EBIU_AMBCTL1 0xFFC00A08L
+
+/* SDRAM Controller External Bus Interface Unit */
+
+#define EBIU_SDGCTL 0xFFC00A10L
+#define EBIU_SDBCTL 0xFFC00A14L
+#define EBIU_SDRRC 0xFFC00A18L
+#define EBIU_SDSTAT 0xFFC00A1CL
+
+
+
+
+/* DCPLB_DATA and ICPLB_DATA Registers */
+/*** Bit Positions */
+#define CPLB_VALID_P 0x00000000 /* 0=invalid entry, 1=valid entry */
+#define CPLB_LOCK_P 0x00000001 /* 0=entry may be replaced, 1=entry locked */
+#define CPLB_USER_RD_P 0x00000002 /* 0=no read access, 1=read access allowed (user mode) */
+/*** Masks */
+#define CPLB_VALID 0x00000001 /* 0=invalid entry, 1=valid entry */
+#define CPLB_LOCK 0x00000002 /* 0=entry may be replaced, 1=entry locked */
+#define CPLB_USER_RD 0x00000004 /* 0=no read access, 1=read access allowed (user mode) */
+#define PAGE_SIZE_1KB 0x00000000 /* 1 KB page size */
+#define PAGE_SIZE_4KB 0x00010000 /* 4 KB page size */
+#define PAGE_SIZE_1MB 0x00020000 /* 1 MB page size */
+#define PAGE_SIZE_4MB 0x00030000 /* 4 MB page size */
+#define CPLB_PORTPRIO 0x00000200 /* 0=low priority port, 1= high priority port */
+#define CPLB_L1_CHBL 0x00001000 /* 0=non-cacheable in L1, 1=cacheable in L1 */
+/*** ICPLB_DATA only */
+#define CPLB_LRUPRIO 0x00000100 /* 0=can be replaced by any line, 1=priority for non-replacement */
+/*** DCPLB_DATA only */
+#define CPLB_USER_WR 0x00000008 /* 0=no write access, 0=write access allowed (user mode) */
+#define CPLB_SUPV_WR 0x00000010 /* 0=no write access, 0=write access allowed (supervisor mode) */
+#define CPLB_DIRTY 0x00000080 /* 1=dirty, 0=clean */
+#define CPLB_L1_AOW 0x00008000 /* 0=do not allocate cache lines on write-through writes, */
+ /* 1= allocate cache lines on write-through writes. */
+#define CPLB_WT 0x00004000 /* 0=write-back, 1=write-through */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_BFIN_H */
diff --git a/cpukit/score/cpu/bfin/rtems/bfin/bfin.h b/cpukit/score/cpu/bfin/rtems/bfin/bfin.h
new file mode 100644
index 0000000000..2645648bed
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/bfin/bfin.h
@@ -0,0 +1,85 @@
+/* bfin.h
+ *
+ * This file defines Macros for MMR register common to all Blackfin
+ * Processors.
+ *
+ * COPYRIGHT (c) 2006 by Atos Automacao Industrial Ltda.
+ * modified by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_BFIN_BFIN_H
+#define _RTEMS_BFIN_BFIN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Scratchpad SRAM */
+
+#define SCRATCH 0xFFB00000
+#define SCRATCH_SIZE 0x1000
+#define SCRATCH_TOP 0xFFB00ffc
+
+
+/* System Interrupt Controller Chapter 4*/
+#define SIC_RVECT 0xFFC00108
+#define SIC_IMASK 0xFFC0010C
+#define SIC_IAR0 0xFFC00110
+#define SIC_IAR1 0xFFC00114
+#define SIC_IAR2 0xFFC00118
+#define SIC_ISR 0xFFC00120
+#define SIC_IWR 0xFFC00124
+
+/* Event Vector Table Chapter 4 */
+
+#define EVT0 0xFFE02000
+#define EVT1 0xFFE02004
+#define EVT2 0xFFE02008
+#define EVT3 0xFFE0200C
+#define EVT4 0xFFE02010
+#define EVT5 0xFFE02014
+#define EVT6 0xFFE02018
+#define EVT7 0xFFE0201C
+#define EVT8 0xFFE02020
+#define EVT9 0xFFE02024
+#define EVT10 0xFFE02028
+#define EVT11 0xFFE0202C
+#define EVT12 0xFFE02030
+#define EVT13 0xFFE02034
+#define EVT14 0xFFE02038
+#define EVT15 0xFFE0203C
+#define IMASK 0xFFE02104
+#define IPEND 0xFFE02108
+#define ILAT 0xFFE0210C
+#define IPRIO 0xFFE02110
+
+
+#define TCNTL 0xFFE03000
+#define TPERIOD 0xFFE03004
+#define TSCALE 0xFFE03008
+#define TCOUNT 0xFFE0300C
+
+/* Masks for Timer Control */
+#define TMPWR 0x00000001
+#define TMREN 0x00000002
+#define TAUTORLD 0x00000004
+#define TINT 0x00000008
+
+/* Event Bit Positions */
+#define EVT_IVTMR_P 0x00000006
+
+#define EVT_IVTMR (1 << EVT_IVTMR_P)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_BFIN_H */
diff --git a/cpukit/score/cpu/bfin/rtems/score/bfin.h b/cpukit/score/cpu/bfin/rtems/score/bfin.h
new file mode 100644
index 0000000000..7568205ae7
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/score/bfin.h
@@ -0,0 +1,65 @@
+/* bfin.h
+ *
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specified to the Blackfin port.
+ *
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ * modified by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_BFIN_H
+#define _RTEMS_SCORE_BFIN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the Blackfin family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+#if defined(__BFIN__)
+#define CPU_MODEL_NAME "BF533"
+#define BF_HAS_FPU 0
+#else
+
+#error "Unsupported CPU Model"
+
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "BFIN"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_BFIN_H */
diff --git a/cpukit/score/cpu/bfin/rtems/score/cpu.h b/cpukit/score/cpu/bfin/rtems/score/cpu.h
new file mode 100644
index 0000000000..9974212018
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/score/cpu.h
@@ -0,0 +1,1264 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the Blackfin
+ * processor.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ * adapted to Blackfin by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/bfin.h>
+
+/* conditional compilation parameters */
+
+/**
+ * Should the calls to @ref _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * This conditional is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ *
+ * @note In general, the @ref _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls @ref _Thread_Enable_dispatch which in turns calls
+ * @ref _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/**
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/**
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * BFIN Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * BFIN Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/**
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/**
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ISR_PASSES_FRAME_POINTER 1
+
+/**
+ * @def CPU_HARDWARE_FP
+ *
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+/**
+ * @def CPU_SOFTWARE_FP
+ *
+ * Does the CPU have no hardware floating point and GCC provides a
+ * software floating point implementation which must be context
+ * switched?
+ *
+ * This feature conditional is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if ( BLACKFIN_CPU_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+/**
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/**
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/**
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/**
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine @ref _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * @ref _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * -# BSP provided
+ * -# CPU dependent (if provided)
+ * -# generic (if no BSP and no CPU dependent)
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/**
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_GROWS_UP FALSE
+
+/**
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * @note Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STRUCTURE_ALIGNMENT
+
+/**
+ * @defgroup CPUEndian Processor Dependent Endianness Support
+ *
+ * This group assists in issues related to processor endianness.
+ */
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_LITTLE_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_BIG_ENDIAN FALSE
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_BIG_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_LITTLE_ENDIAN TRUE
+
+/**
+ * @ingroup CPUInterrupt
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+/**
+ * @defgroup CPUContext Processor Dependent Context Management
+ *
+ * From the highest level viewpoint, there are 2 types of context to save.
+ *
+ * -# Interrupt registers to save
+ * -# Task level registers to save
+ *
+ * Since RTEMS handles integer and floating point contexts separately, this
+ * means we have the following 3 context items:
+ *
+ * -# task level context stuff:: Context_Control
+ * -# floating point task stuff:: Context_Control_fp
+ * -# special interrupt level context :: CPU_Interrupt_frame
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#ifndef ASM
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the minimal set of integer and processor state registers
+ * that must be saved during a voluntary context switch from one thread
+ * to another.
+ */
+
+/* make sure this stays in sync with the assembly function
+ __CPU_Context_switch in cpu_asm.S */
+typedef struct {
+ uint32_t register_r4;
+ uint32_t register_r5;
+ uint32_t register_r6;
+ uint32_t register_r7;
+
+ uint32_t register_p3;
+ uint32_t register_p4;
+ uint32_t register_p5;
+ uint32_t register_fp;
+ uint32_t register_sp;
+
+ uint32_t register_rets;
+
+ uint32_t imask;
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->register_sp
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the complete set of floating point registers that must
+ * be saved during any context switch from one thread to another.
+ */
+typedef struct {
+ /* FPU registers are listed here */
+ /* Blackfin has no Floating Point */
+} Context_Control_fp;
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that must
+ * be saved during an interrupt. This set does not include any which are
+ * in @ref Context_Control.
+ */
+typedef struct {
+ /** This field is a hint that a port will have a number of integer
+ * registers that need to be saved when an interrupt occurs or
+ * when a context switch occurs at the end of an ISR.
+ */
+ /*uint32_t special_interrupt_register;*/
+} CPU_Interrupt_frame;
+
+/**
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * @ref _CPU_Initialize and copied into the task's FP context area during
+ * @ref _CPU_Context_Initialize.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+/**
+ * @defgroup CPUInterrupt Processor Dependent Interrupt Management
+ *
+ * On some CPUs, RTEMS supports a software managed interrupt stack.
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in @ref _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use.
+ *
+ * @note These two variables are required if the macro
+ * @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/**
+ * @ingroup CPUContext
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+#endif /* ASM */
+
+/**
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the number of entries in the @ref _ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 16
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the highest interrupt vector number for this port.
+ */
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/**
+ * @ingroup CPUInterrupt
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable @a _ISR_Nest_level.
+ */
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/**
+ * @ingroup CPUContext
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_MINIMUM_SIZE (1024*4)
+
+/**
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALIGNMENT 8
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by @ref CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for
+ * the heap, then this should be set to @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * @ref CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is
+ * strict enough for the partition, then this should be set to
+ * @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2. It does have to
+ * be greater or equal to than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by @ref CPU_ALIGNMENT. If the
+ * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
+ * set to 0.
+ *
+ * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_ALIGNMENT 0
+
+/*
+ * ISR handler macros
+ */
+
+/**
+ * @ingroup CPUInterrupt
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Initialize_vectors()
+
+/**
+ * @ingroup CPUInterrupt
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in @a _isr_cookie.
+ *
+ * @param[out] _isr_cookie will contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Disable( _level ) \
+ { \
+ __asm__ volatile ("cli %0; csync \n" : "=d" (_level) ); \
+ }
+
+
+/**
+ * @ingroup CPUInterrupt
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * @a _isr_cookie is not modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Enable( _level ) { \
+ __asm__ __volatile__ ("sti %0; csync \n" : : "d" (_level) ); \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * This temporarily restores the interrupt to @a _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter @a _isr_cookie is not
+ * modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Flash( _level ) { \
+ __asm__ __volatile__ ("sti %0; csync; cli r0; csync" \
+ : : "d"(_level) : "R0" ); \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ *
+ * This routine and @ref _CPU_ISR_Get_level
+ * Map the interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Set_level( _new_level ) \
+ { \
+ __asm__ __volatile__ ( "sti %0; csync" : : "d"(_new_level ? 0 : 0xffff) ); \
+ }
+
+#ifndef ASM
+
+/**
+ * @ingroup CPUInterrupt
+ * Return the current interrupt disable level for this task in
+ * the format used by the interrupt level portion of the task mode.
+ *
+ * @note This routine usually must be implemented as a subroutine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/**
+ * @ingroup CPUContext
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * @param[in] _the_context is the context structure to be initialized
+ * @param[in] _stack_base is the lowest physical address of this task's stack
+ * @param[in] _size is the size of this task's stack
+ * @param[in] _isr is the interrupt disable level
+ * @param[in] _entry_point is the thread's entry point. This is
+ * always @a _Thread_Handler
+ * @param[in] _is_fp is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * Port Specific Information:
+ *
+ * See implementation in cpu.c
+ */
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/**
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. For many ports, simply adding a label to the restore path
+ * of @ref _CPU_Context_switch will work. On other ports, it may be
+ * possibly to load a few arguments and jump to the restore path. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/**
+ * @ingroup CPUContext
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * @param[in] _base is the lowest physical address of the floating point
+ * context area
+ * @param[in] _offset is the offset into the floating point area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/**
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * @a _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other floating point context save/restore models include:
+ * -# not doing anything, and
+ * -# putting a "null FP status word" in the correct place in the FP context.
+ *
+ * @param[in] _destination is the floating point context area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/**
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ __asm__ volatile ( "cli R1; \
+ R1 = %0; \
+ _halt: \
+ idle; \
+ jump _halt;"\
+ : : "r" (_error) ); \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/**
+ * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
+ *
+ * This set of routines are used to implement fast searches for
+ * the most important ready task.
+ */
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the generic bitfield
+ * manipulation implementation.
+ */
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the data tables provided
+ * by the generic bitfield manipulation implementation.
+ * This can occur when actually using the generic bitfield manipulation
+ * implementation or when implementing the same algorithm in assembly
+ * language for improved performance. It is unlikely that a port will use
+ * the data if it has a bitfield scan instruction.
+ */
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This routine sets @a _output to the bit number of the first bit
+ * set in @a _value. @a _value is of CPU dependent type
+ * @a Priority_bit_map_Control. This type may be either 16 or 32 bits
+ * wide although only the 16 least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * -# What happens when run on a value of zero?
+ * -# Bits may be numbered from MSB to LSB or vice-versa.
+ * -# The numbering may be zero or one based.
+ * -# The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
+ * @ref _CPU_Priority_bits_index. These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by @ref _CPU_Priority_Mask.
+ * The basic major and minor values calculated by @ref _Priority_Major
+ * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for @ref _Priority_Get_highest to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+@verbatim
+ - a series of 16 bit test instructions
+ - a "binary search using if's"
+ - _number = 0
+ if _value > 0x00ff
+ _value >>=8
+ _number = 8;
+
+ if _value > 0x0000f
+ _value >=8
+ _number += 4
+
+ _number += bit_set_table[ _value ]
+@endverbatim
+
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * @param[in] _value is the value to be scanned
+ * @param[in] _output is the first bit set
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ __asm__ ("bit(1);"):
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+#endif
+
+/* end of Bitfield handler macros */
+
+/**
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by @ref _CPU_Bitfield_Find_first_bit. See the discussion
+ * for that routine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/**
+ * @ingroup CPUBitfield
+ * This routine translates the bit numbers returned by
+ * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * @param[in] _priority is the major or minor number to translate
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/**
+ * This routine performs CPU dependent initialization.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the raw ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs an interrupt vector.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the RTEMS ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * @note It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Install_interrupt_stack( void );
+
+/**
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * @note It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/**
+ * @ingroup CPUContext
+ * This routine switches from the run context to the heir context.
+ *
+ * @param[in] run points to the context of the currently executing task
+ * @param[in] heir points to the context of the heir task
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in @ref _CPU_Context_switch.
+ *
+ * @param[in] new_context points to the context to be restored.
+ *
+ * @note May be unnecessary to reload some registers.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/**
+ * @ingroup CPUContext
+ * This routine saves the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_restore_fp to restore this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine restores the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area to restore
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_save_fp to save this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUEndian
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+/**
+ * @ingroup CPUEndian
+ * This routine swaps a 16 bir quantity.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ */
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/bfin/rtems/score/cpu_asm.h b/cpukit/score/cpu/bfin/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..a4c7be9a5e
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/score/cpu_asm.h
@@ -0,0 +1,27 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Defines a couple of Macros used in cpu_asm.S
+ *
+ * COPYRIGHT (c) 2006 by Atos Automacao Industrial Ltda.
+ * written by Alain Schaefer <alain.schaefer@easc.ch>
+ * and Antonio Giovanini <antonio@atos.com.br>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/bfin/rtems/score/types.h b/cpukit/score/cpu/bfin/rtems/score/types.h
new file mode 100644
index 0000000000..bf833974ed
--- /dev/null
+++ b/cpukit/score/cpu/bfin/rtems/score/types.h
@@ -0,0 +1,45 @@
+/*
+ * This include file contains type definitions pertaining to the
+ * Blackfin processor family.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+/** This defines the type for a priority bit map entry. */
+typedef uint16_t Priority_bit_map_Control;
+
+/** This defines the return type for an ISR entry point. */
+typedef void blackfin_isr;
+
+/** This defines the prototype for an ISR entry point. */
+typedef blackfin_isr ( *blackfin_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/h8300/.cvsignore b/cpukit/score/cpu/h8300/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/h8300/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/h8300/ChangeLog b/cpukit/score/cpu/h8300/ChangeLog
new file mode 100644
index 0000000000..624846949f
--- /dev/null
+++ b/cpukit/score/cpu/h8300/ChangeLog
@@ -0,0 +1,489 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/asm.h, rtems/score/cpu.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Assembler compatibility fixes.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.S, rtems/asm.h, rtems/score/cpu.h: Add a per cpu data
+ structure which contains the information required by RTEMS for each
+ CPU core. This encapsulates information such as thread executing,
+ heir, idle and dispatch needed.
+
+2010-04-25 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * rtems/score/cpu.h: Remove warning in _CPU_Context_Initialize.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S: Add include of config.h
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1385/cpukit
+ * cpu_asm.S: When the type rtems_boolean was switched to the C99 bool,
+ the size changed from 4 bytes to 1 byte. The interrupt dispatching
+ code accesses two boolean variables for scheduling purposes and the
+ assembly implementations of this code did not get updated.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Change prototype of IDLE thread to consistently return void *
+ and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Do not unroll any code on this target and use a
+ 16-bit object id.
+
+2008-10-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.S: Enable same code paths for SX. Tested on simulator.
+
+2008-10-14 Steven Grunza <grunza@ulticom.com>
+
+ * cpu_asm.S: Use proper diredctive for h8300/sx.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Remove extraneous spaces.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Revert change. It did not appear to correct all
+ warnings.
+
+2006-08-30 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h:
+
+2006-08-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Correct inline assembly constraints.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-02-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove traces from NO_CPU.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/h8300.h,
+ rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/h8300.h: Remove RTEMS_CPU_HAS_16_BIT_ADDRESSES.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-12-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 733/rtems
+ * rtems/score/cpu.h: Remove output arg from inline asm in
+ _CPU_ISR_Disable.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/h8300.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: i960 obsoleted and all references removed.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into $(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h: Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-26 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Obsoleting HP PA-RISC port and removing all
+ references.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * asm.h, cpu.c, cpu_asm.S, rtems/score/cpu.h, rtems/score/h8300.h,
+ rtems/score/types.h: URL for license changed.
+
+2003-08-14 Joel Sherrill <joel@OARcorp.com>
+
+ PR 455/bsps
+ * rtems/score/cpu.h: Added missing CPU_swap_u16().
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-11-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/cpu.h: Add prototype of H8BD_Install_IRQ to eliminate
+ warning.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use . instead of .o.
+
+2002-07-05 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Filled in something that was marked XXX.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-04 Joel Sherrill <joel@OARcorp.com>
+
+ * Makefile.am: Remove reference to deprecated rtems.c.
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.c: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Fixed comments and renamed
+ CPU_SYSTEM_INITIALIZATION_THREAD_EXTRA_STACK to
+ CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK to be consistent with other code.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/h8300types.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-01-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ * Makefile.am: Reflect changes above.
+
+2002-01-07 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/cpu.h: #include <rtems/bspIo.h>.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+ * cpu_asm.S: Modify to properly dereference _ISR_Vector_table
+ now that it is dynamically allocated.
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-10-18 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S, rtems/score/cpu.h: Modified to better support
+ multilibing. These changes result in the code being able to
+ compile with the default gcc settings. It is not functional
+ in this configuration but does compile.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/h8300/Makefile.am b/cpukit/score/cpu/h8300/Makefile.am
new file mode 100644
index 0000000000..e3a0692391
--- /dev/null
+++ b/cpukit/score/cpu/h8300/Makefile.am
@@ -0,0 +1,19 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/h8300.h \
+ rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/h8300/README b/cpukit/score/cpu/h8300/README
new file mode 100644
index 0000000000..a55c61c662
--- /dev/null
+++ b/cpukit/score/cpu/h8300/README
@@ -0,0 +1,31 @@
+#
+# $Id$
+#
+
+
+This port was done by Philip Quaife <philip@qs.co.nz> of Q Solutions
+using RTEMS 3.5.1 under DOS and Hiview. Philip used an H8300H
+to develop and test this port.
+
+It was updated to 4.5 and merged into the main development trunk
+by Joel Sherrill <joel@OARcorp.com>. As part of the merger, the
+port was made to conditionally compile for the H8, H8300H, and H8300S
+series.
+
+The status of each CPU subfamily is as follows.
+
+H8 - Although RTEMS compiles with for these CPUs, it does not
+ truly support them. All code that will not work on these
+ CPUs is conditionally disabled. These CPUs have a 16-bit
+ address space. Thus although a port is technically
+ feasible, some work will to be performed on RTEMS to
+ further minimize its footprint and address pointer
+ manipulation issues.
+
+H8H - Port was developed on this class of H8 so there should be
+ no problems.
+
+H8S - Port should work on this class of H8 but it is untested.
+
+--joel
+28 June 2000
diff --git a/cpukit/score/cpu/h8300/cpu.c b/cpukit/score/cpu/h8300/cpu.c
new file mode 100644
index 0000000000..1c82ee4880
--- /dev/null
+++ b/cpukit/score/cpu/h8300/cpu.c
@@ -0,0 +1,158 @@
+/*
+ * Hitachi H8300 CPU Dependent Source
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ */
+
+
+void _CPU_Initialize(void)
+{
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * This routine returns the current interrupt level.
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ unsigned int _ccr;
+
+#if defined(__H8300__)
+#warning "How do we get ccr on base CPU models"
+#else
+ __asm__ volatile ( "stc ccr, %0" : "=m" (_ccr) : );
+#endif
+
+ if ( _ccr & 0x80 )
+ return 1;
+ return 0;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ * Use Debug level IRQ Handlers
+ */
+ H8BD_Install_IRQ(vector,new_handler,old_handler);
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ */
+
+#if 0
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+
+ for( ; ; )
+ IDLE_Monitor();
+ /* __asm__ (" sleep \n"); */
+ /* insert your "halt" instruction here */ ;
+}
+#endif
diff --git a/cpukit/score/cpu/h8300/cpu_asm.S b/cpukit/score/cpu/h8300/cpu_asm.S
new file mode 100644
index 0000000000..921f9819ef
--- /dev/null
+++ b/cpukit/score/cpu/h8300/cpu_asm.S
@@ -0,0 +1,225 @@
+/*
+ * Hitachi H8 Score CPU functions
+ * Copyright Comnet Technologies Ltd 1999
+ *
+ * Based on example code and other ports with this copyright:
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/percpu.h>
+
+;.equ RUNCONTEXT_ARG, er0
+;.equ HEIRCONTEXT_ARG, er1
+
+/*
+ * Make sure we tell the assembler what type of CPU model we are
+ * being compiled for.
+ */
+
+#if defined(__H8300H__)
+ .h8300h
+#endif
+#if defined(__H8300S__)
+ .h8300s
+#endif
+#if defined(__H8300SX__)
+ .h8300sx
+#endif
+ .text
+
+ .text
+/*
+ GCC Compiled with optimisations and Wimplicit decs to ensure
+ that stack from doesn't change
+
+ Supposedly R2 and R3 do not need to be saved but who knows
+
+ Arg1 = er0 (not on stack)
+ Arg2 = er1 (not on stack)
+*/
+
+ .align 2
+
+ .global SYM(_CPU_Context_switch)
+
+SYM(_CPU_Context_switch):
+ /* Save Context */
+#if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
+ stc.w ccr,@(0:16,er0)
+ mov.l er7,@(2:16,er0)
+ mov.l er6,@(6:16,er0)
+ mov.l er5,@(10:16,er0)
+ mov.l er4,@(14:16,er0)
+ mov.l er3,@(18:16,er0)
+ mov.l er2,@(22:16,er0)
+
+ /* Install New context */
+
+restore:
+ mov.l @(22:16,er1),er2
+ mov.l @(18:16,er1),er3
+ mov.l @(14:16,er1),er4
+ mov.l @(10:16,er1),er5
+ mov.l @(6:16,er1),er6
+ mov.l @(2:16,er1),er7
+ ldc.w @(0:16,er1),ccr
+#endif
+
+ rts
+
+ .align 2
+
+ .global SYM(_CPU_Context_restore)
+
+SYM(_CPU_Context_restore):
+
+#if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
+ mov.l er0,er1
+ jmp @restore:24
+#endif
+
+
+
+/*
+ VHandler for Vectored Interrupts
+
+ All IRQ's are vectored to routine _ISR_#vector_number
+ This routine stacks er0 and loads er0 with vector number
+ before transferring to here
+
+*/
+ .align 2
+ .global SYM(_ISR_Handler)
+ .extern SYM(_Vector_table)
+
+
+SYM(_ISR_Handler):
+#if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
+ mov.l er1,@-er7
+ mov.l er2,@-er7
+ mov.l er3,@-er7
+ mov.l er4,@-er7
+ mov.l er5,@-er7
+ mov.l er6,@-er7
+
+/* Set IRQ Stack */
+ orc #0xc0,ccr
+ mov.l er7,er6 ; save stack pointer
+ mov.l @ISR_NEST_LEVEL,er1
+ bne nested
+ mov.l @INTERRUPT_STACK_HIGH,er7
+
+nested:
+ mov.l er6,@-er7 ; save sp so pop regardless of nest level
+
+;; Inc system counters
+ mov.l @ISR_NEST_LEVEL,er1
+ inc.l #1,er1
+ mov.l er1,@ISR_NEST_LEVEL
+ mov.l @SYM(_Thread_Dispatch_disable_level),er1
+ inc.l #1,er1
+ mov.l er1,@SYM(_Thread_Dispatch_disable_level)
+
+/* Vector to ISR */
+
+ mov.l @SYM(_ISR_Vector_table),er1
+ mov er0,er2 ; copy vector
+ shll.l er2
+ shll.l er2 ; vector = vector * 4 (sizeof(int))
+ add.l er2,er1
+ mov.l @er1,er1
+ jsr @er1 ; er0 = arg1 =vector
+
+ orc #0xc0,ccr
+ mov.l @ISR_NEST_LEVEL,er1
+ dec.l #1,er1
+ mov.l er1,@ISR_NEST_LEVEL
+ mov.l @SYM(_Thread_Dispatch_disable_level),er1
+ dec.l #1,er1
+ mov.l er1,@SYM(_Thread_Dispatch_disable_level)
+ bne exit
+
+ mov.b @DISPATCH_NEEDED,er1
+ beq exit ; If no then exit
+
+ /* Context switch here through ISR_Dispatch */
+bframe:
+ orc #0xc0,ccr
+/* Pop Stack */
+ mov @er7+,er6
+ mov er6,er7
+
+ /* Set up IRQ stack frame and dispatch to _ISR_Dispatch */
+
+ mov.l #0xc0000000,er2 /* Disable IRQ */
+ or.l #SYM(_ISR_Dispatch),er2
+ mov.l er2,@-er7
+ rte
+
+/* Inner IRQ Return, pop flags and return */
+exit:
+/* Pop Stack */
+ orc #0x80,ccr
+ mov @er7+,er6
+ mov er6,er7
+ mov @er7+,er6
+ mov @er7+,er5
+ mov @er7+,er4
+ mov @er7+,er3
+ mov @er7+,er2
+ mov @er7+,er1
+ mov @er7+,er0
+#endif
+ rte
+
+/*
+ Called from ISR_Handler as a way of ending IRQ
+ but allowing dispatch to another task.
+ Must use RTE as CCR is still on stack but IRQ has been serviced.
+ CCR and PC occupy same word so rte can be used.
+ now using task stack
+*/
+
+ .align 2
+ .global SYM(_ISR_Dispatch)
+
+SYM(_ISR_Dispatch):
+
+#if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
+ jsr @SYM(_Thread_Dispatch)
+ mov @er7+,er6
+ mov @er7+,er5
+ mov @er7+,er4
+ mov @er7+,er3
+ mov @er7+,er2
+ mov @er7+,er1
+ mov @er7+,er0
+#endif
+ rte
+
+
+ .align 2
+ .global SYM(_CPU_Context_save_fp)
+
+SYM(_CPU_Context_save_fp):
+ rts
+
+
+ .align 2
+ .global SYM(_CPU_Context_restore_fp)
+
+SYM(_CPU_Context_restore_fp):
+ rts
diff --git a/cpukit/score/cpu/h8300/preinstall.am b/cpukit/score/cpu/h8300/preinstall.am
new file mode 100644
index 0000000000..c3fb644817
--- /dev/null
+++ b/cpukit/score/cpu/h8300/preinstall.am
@@ -0,0 +1,41 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/h8300.h: rtems/score/h8300.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/h8300.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/h8300.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/h8300/rtems/asm.h b/cpukit/score/cpu/h8300/rtems/asm.h
new file mode 100644
index 0000000000..4322bf6ec0
--- /dev/null
+++ b/cpukit/score/cpu/h8300/rtems/asm.h
@@ -0,0 +1,117 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#include <rtems/score/h8300.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+#define r0 REG(r0)
+#define r1 REG(r1)
+#define r2 REG(r2)
+#define r3 REG(r3)
+#define r4 REG(r4)
+#define r5 REG(r5)
+#define r6 REG(r6)
+#define r7 REG(r7)
+
+#define er0 REG(er0)
+#define er1 REG(er1)
+#define er2 REG(er2)
+#define er3 REG(er3)
+#define er4 REG(er4)
+#define er5 REG(er5)
+#define er6 REG(er6)
+#define er7 REG(er7)
+
+#define sp REG(sp)
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE __asm__ ( ".text
+#define END_CODE ");
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/h8300/rtems/score/cpu.h b/cpukit/score/cpu/h8300/rtems/score/cpu.h
new file mode 100644
index 0000000000..cf8a880f32
--- /dev/null
+++ b/cpukit/score/cpu/h8300/rtems/score/cpu.h
@@ -0,0 +1,1146 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the H8300
+ * processor.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/h8300.h>
+#ifndef ASM
+ #include <rtems/bspIo.h>
+#endif
+
+/* conditional compilation parameters */
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * Basically this is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ * [NOTE: In general, the _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls _Thread_Enable_dispatch which in turns calls
+ * _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.]
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
+
+/*
+ * Should this target use 16 or 32 bit object Ids?
+ *
+ */
+#define RTEMS_USE_16_BIT_OBJECT
+
+/*
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * H8300 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "H8300_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_HARDWARE_FP FALSE
+
+/*
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Internal_threads_Idle_thread_body
+ * must be provided and is the default IDLE thread body instead of
+ * _Internal_threads_Idle_thread_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * 1. BSP provided
+ * 2. CPU dependent (if provided)
+ * 3. generic (if no BSP and no CPU dependent)
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ * The port initially called a BSP dependent routine called
+ * IDLE_Monitor. The idle task body can be overridden by
+ * the BSP in newer versions of RTEMS.
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * NOTE: Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_STRUCTURE_ALIGNMENT
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+
+/*
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+/* may need to put some structures here. */
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#ifndef ASM
+
+#define nogap __attribute__ ((packed))
+
+typedef struct {
+ uint16_t ccr nogap;
+ void *er7 nogap;
+ void *er6 nogap;
+ uint32_t er5 nogap;
+ uint32_t er4 nogap;
+ uint32_t er3 nogap;
+ uint32_t er2 nogap;
+ uint32_t er1 nogap;
+ uint32_t er0 nogap;
+ uint32_t xxx nogap;
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->er7
+
+typedef struct {
+ double some_float_register[2];
+} Context_Control_fp;
+
+typedef struct {
+ uint32_t special_interrupt_register;
+} CPU_Interrupt_frame;
+
+/*
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * _CPU_Initialize and copied into the task's FP context area during
+ * _CPU_Context_Initialize.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+/* XXX: if needed, put more variables here */
+
+/*
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+#endif /* ASM */
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * system initialization thread. Remember that in a multiprocessor
+ * system the system intialization thread becomes the MP server thread.
+ *
+ * H8300 Specific Information:
+ *
+ * It is highly unlikely the H8300 will get used in a multiprocessor system.
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 64
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_STACK_MINIMUM_SIZE (1536)
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_ALIGNMENT 8
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_STACK_ALIGNMENT 2
+
+/*
+ * ISR handler macros
+ */
+
+/*
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ */
+
+#define _CPU_Initialize_vectors()
+
+/* COPE With Brain dead version of GCC distributed with Hitachi HIView Tools.
+ Note requires ISR_Level be uint16_t or assembler croaks.
+*/
+
+#if (__GNUC__ == 2 && __GNUC_MINOR__ == 7 )
+
+
+/*
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in _level.
+ */
+
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ do { \
+ __asm__ volatile( "stc.w ccr, @-er7 ;\n orc #0xC0,ccr ;\n mov.w @er7+,%0" : : "r" (_isr_cookie) ); \
+ } while (0)
+
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * _level is not modified.
+ */
+
+
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ do { \
+ __asm__ volatile( "mov.w %0,@-er7 ;\n ldc.w @er7+, ccr" : : "r" (_isr_cookie) ); \
+ } while (0)
+
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ do { \
+ __asm__ volatile( "mov.w %0,@-er7 ;\n ldc.w @er7+, ccr ;\n orc #0xC0,ccr" : : "r" (_isr_cookie) ); \
+ } while (0)
+
+/* end of ISR handler macros */
+
+#else /* modern gcc version */
+
+/*
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in _level.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#if defined(__H8300H__) || defined(__H8300S__)
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ do { \
+ unsigned char __ccr; \
+ __asm__ volatile( "stc ccr, %0 ; orc #0x80,ccr " \
+ : "=m" (__ccr) /* : "0" (__ccr) */ ); \
+ (_isr_cookie) = __ccr; \
+ } while (0)
+#else
+#define _CPU_ISR_Disable( _isr_cookie ) (_isr_cookie) = 0
+#endif
+
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * _level is not modified.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#if defined(__H8300H__) || defined(__H8300S__)
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ do { \
+ unsigned char __ccr = (unsigned char) (_isr_cookie); \
+ __asm__ volatile( "ldc %0, ccr" : : "m" (__ccr) ); \
+ } while (0)
+#else
+#define _CPU_ISR_Enable( _isr_cookie )
+#endif
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#if defined(__H8300H__) || defined(__H8300S__)
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ do { \
+ unsigned char __ccr = (unsigned char) (_isr_cookie); \
+ __asm__ volatile( "ldc %0, ccr ; orc #0x80,ccr " : : "m" (__ccr) ); \
+ } while (0)
+#else
+#define _CPU_ISR_Flash( _isr_cookie )
+#endif
+
+#endif /* end of old gcc */
+
+
+/*
+ * Map interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define _CPU_ISR_Set_level( _new_level ) \
+ { \
+ if ( _new_level ) __asm__ volatile ( "orc #0x80,ccr\n" ); \
+ else __asm__ volatile ( "andc #0x7f,ccr\n" ); \
+ }
+
+#ifndef ASM
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * NOTE: This is_fp parameter is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+
+#define CPU_CCR_INTERRUPTS_ON 0x80
+#define CPU_CCR_INTERRUPTS_OFF 0x00
+
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ /* Locate Me */ \
+ do { \
+ uintptr_t _stack; \
+ \
+ if ( (_isr) ) (_the_context)->ccr = CPU_CCR_INTERRUPTS_OFF; \
+ else (_the_context)->ccr = CPU_CCR_INTERRUPTS_ON; \
+ \
+ _stack = ((uintptr_t)(_stack_base)) + (_size) - 4; \
+ *((proc_ptr *)(_stack)) = (_entry_point); \
+ (_the_context)->er7 = (void *) _stack; \
+ (_the_context)->er6 = (void *) _stack; \
+ (_the_context)->er5 = 0; \
+ (_the_context)->er4 = 1; \
+ (_the_context)->er3 = 2; \
+ } while (0)
+
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. Context_Restore should work most of the time. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/*
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) (_base) + (_offset) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other models include (1) not doing anything, and (2) putting
+ * a "null FP status word" in the correct place in the FP context.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/*
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define _CPU_Fatal_halt( _error ) \
+ printk("Fatal Error %d Halted\n",_error); \
+ for(;;)
+
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/*
+ * This routine sets _output to the bit number of the first bit
+ * set in _value. _value is of CPU dependent type Priority_bit_map_Control.
+ * This type may be either 16 or 32 bits wide although only the 16
+ * least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * (1) What happens when run on a value of zero?
+ * (2) Bits may be numbered from MSB to LSB or vice-versa.
+ * (3) The numbering may be zero or one based.
+ * (4) The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
+ * _CPU_Priority_bits_index(). These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by _CPU_Priority_mask().
+ * The basic major and minor values calculated by _Priority_Major()
+ * and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for _Priority_Get_highest() to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+ * - a series of 16 bit test instructions
+ * - a "binary search using if's"
+ * - _number = 0
+ * if _value > 0x00ff
+ * _value >>=8
+ * _number = 8;
+ *
+ * if _value > 0x0000f
+ * _value >=8
+ * _number += 4
+ *
+ * _number += bit_set_table[ _value ]
+ *
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+
+#endif
+
+/* end of Bitfield handler macros */
+
+/*
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by _CPU_Bitfield_Find_first_bit(). See the discussion
+ * for that routine.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/*
+ * This routine translates the bit numbers returned by
+ * _CPU_Bitfield_Find_first_bit() into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Install_interrupt_stack
+ *
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * NOTE: It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_Install_interrupt_stack( void );
+
+/*
+ * _CPU_Internal_threads_Idle_thread_body
+ *
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * NOTE: It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void *_CPU_Thread_Idle_body( uint32_t );
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generallu used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ *
+ * H8300 Specific Information:
+ *
+ * XXX
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/* The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * H8300 Specific Information:
+ *
+ * This is the generic implementation.
+ */
+
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+/* to be provided by the BSP */
+extern void H8BD_Install_IRQ(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler );
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/h8300/rtems/score/h8300.h b/cpukit/score/cpu/h8300/rtems/score/h8300.h
new file mode 100644
index 0000000000..5a2444b081
--- /dev/null
+++ b/cpukit/score/cpu/h8300/rtems/score/h8300.h
@@ -0,0 +1,43 @@
+/**
+ * @file rtems/score/h8300.h
+ */
+
+/*
+ * This file contains information pertaining to the Hitachi H8/300
+ * processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_H8300_H
+#define _RTEMS_SCORE_H8300_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the "h8300"
+ * family when executing in protected mode. It does
+ * this by setting variables to indicate which implementation
+ * dependent features are present in a particular member
+ * of the family.
+ */
+
+#define CPU_NAME "Hitachi H8300"
+#define CPU_MODEL_NAME "h8300"
+#define H8300_HAS_FPU 0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/h8300/rtems/score/types.h b/cpukit/score/cpu/h8300/rtems/score/types.h
new file mode 100644
index 0000000000..e073ffb312
--- /dev/null
+++ b/cpukit/score/cpu/h8300/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Hitachi
+ * h8300 processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void h8300_isr;
+typedef void ( *h8300_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/i386/.cvsignore b/cpukit/score/cpu/i386/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/i386/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/i386/ChangeLog b/cpukit/score/cpu/i386/ChangeLog
new file mode 100644
index 0000000000..4f78220d02
--- /dev/null
+++ b/cpukit/score/cpu/i386/ChangeLog
@@ -0,0 +1,515 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, sse_test.c, rtems/score/cpu.h, rtems/score/i386.h,
+ rtems/score/interrupts.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/types.h: Refactoring of priority handling, to isolate the
+ bitmap implementation of priorities in the supercore so that priority
+ management is a little more modular. This change is in anticipation
+ of scheduler implementations that can select how they manage tracking
+ priority levels / finding the highest priority ready task. Note that
+ most of the changes here are simple renaming, to clarify the use of
+ the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.S: Formatting.
+
+2010-05-21 Vinu Rajashekhar <vinutheraj@gmail.com>
+
+ * rtems/score/registers.h: Remove structs with bit-fields. Add a mask
+ for cr3 page directory.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S, sse_test.c: Add include of config.h
+
+2009-11-09 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 1469/cpukit
+ * cpu.c: Add dummy entry for (non-existing) exception #15.
+ Otherwise all slots for vectors >= 16 are one element off.
+
+2009-10-29 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/score/cpu.h: Define _CPU_Interrupt_stack_setup() macro
+ which reserves space for the 'vector' arg to _C_dispatch_isr()
+ routine and aligns the irq stack to CPU_STACK_ALIGNMENT.
+
+2009-10-28 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/score/cpu.h: Replaced misleading typedef of
+ CPU_Interrupt_frame by 'void'. The i386 port does not
+ pass any frame info to the interrupt handlers.
+
+2009-10-28 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/score/cpu.h:
+ Added #ifdef ASM constructs so that this header can be
+ included from assembly code.
+
+ Increased CPU_STACK_ALIGNMENT to 16 bytes. Gcc maintains
+ 16-byte alignment and it may be a advantageous to provide
+ initial 16-byte alignment. When using SSE some gcc versions
+ may produce code that crashes if the stack is not 16-byte aligned.
+
+ Make sure _CPU_Context_Initialize() sets the thread stack
+ up so that it is aligned to CPU_CACHE_ALIGNMENT.
+
+ * cpu_asm.S:
+ Align stack to CPU_CACHE_ALIGNMENT before calling C-code.
+
+2009-10-27 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/asm.h: Added definition for cr4 register.
+
+2009-09-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add no return atrribute to _CPU_Context_restore()
+ since it is used for restarting self.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Remove extraneous spaces.
+
+2008-09-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c: Stop using old-style defs.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c: Fix prototypes.
+ * rtems/score/cpu.h: Use memcpy() initialize FP structure and avoid
+ many casts and potential warnings.
+
+2008-08-16 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h, rtems/score/i386.h: Add missing prototypes.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/idtr.h: Sweep to make sure grep for COPYRIGHT passes.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Eliminate the interrupt_table_segment and
+ interrupt_table_offset fields in the i386 CPU Table since they are
+ never read.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-02-01 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Increase default stack size on i386 from 1K to 4K.
+ Most i386 targets are not memory strapped so making this a bit large
+ is not a burden. It lets more tests run. ticker and psxtimer will not
+ even run with 1K of stack.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/i386.h, rtems/score/idtr.h,
+ rtems/score/interrupts.h, rtems/score/registers.h,
+ rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/i386.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/i386.h: *_swap_u16( uint16_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/i386.h: Add doxygen preamble.
+ * rtems/score/idtr.h: Add doxygen preamble.
+ * rtems/score/interrupts.h: Add doxygen preamble.
+ * rtems/score/registers.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-04-16 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/i386.h: Rename i386_swap_U* to i386_swap_u* (API
+ consistency with other ports).
+
+2004-04-09 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu_asm.S: Convert asm comments to C-comments to prevent gcc-3.4.0pre
+ from choking on them.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into $(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu_asm.S: Include <rtems/asm.h> instead of <asm.h>.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h, rtems/score/interrupts.h:
+ Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-02-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 565/rtems
+ * asm.h: Various hacks.
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h, rtems/score/i386.h,
+ rtems/score/idtr.h, rtems/score/interrupts.h,
+ rtems/score/registers.h, rtems/score/types.h: URL for license
+ changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use . instead of .o.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.S: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2002-03-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/idtr.h: New file, extracted from libcpu/cpu.h.
+ * rtems/score/interrupts.h: New file, extracted from libcpu/cpu.h.
+ * rtems/score/registers.h: New file, moved from libcpu.
+ * Makefile.am: Reflect changes above.
+ * cpu.c: Don't include cpuModel.h,
+ #include <rtems.h>,
+ #include <rtems/score/i386types.h>,
+ #include <rtems/score/idtr.h>.
+ * rtems/score/cpu.h: Don't include libcpu/cpu.h.
+ #include <rtems/score/interrupts.h>,
+ #include <rtems/score/registers.h>.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/i386types.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2001-02-05 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/Makefile.am, rtems/score/Makefile.am: Removed again.
+
+2002-01-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ * Makefile.am: Reflect changes above.
+
+2001-01-30 Joel Sherrill <joel@OARcorp.com>
+
+ * Makefile.am: Corrected so .h files from rtems/score/ are installed.
+
+2002-01-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * cpu.c: Include rtems/bspIo.h instead of bspIo.h.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-09-12 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/i386.h: Corrected "#elsif" to be "#elif".
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/i386.h: cpu-variant define handling
+ Rewrite due to introduction of multilib defines.
+ * asm.h: include cpuopts.h instead of targopts.h
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/i386/Makefile.am b/cpukit/score/cpu/i386/Makefile.am
new file mode 100644
index 0000000000..f6c8e7f6d7
--- /dev/null
+++ b/cpukit/score/cpu/i386/Makefile.am
@@ -0,0 +1,20 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS= rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/i386.h \
+ rtems/score/types.h rtems/score/interrupts.h rtems/score/registers.h \
+ rtems/score/idtr.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/i386/cpu.c b/cpukit/score/cpu/i386/cpu.c
new file mode 100644
index 0000000000..56971b63d5
--- /dev/null
+++ b/cpukit/score/cpu/i386/cpu.c
@@ -0,0 +1,244 @@
+/*
+ * Intel i386 Dependent Source
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/system.h>
+#include <rtems/score/types.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/idtr.h>
+
+#include <rtems/bspIo.h>
+#include <rtems/score/thread.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ */
+
+void _CPU_Initialize(void)
+{
+#if CPU_HARDWARE_FP
+ register uint16_t fp_status __asm__ ("ax");
+ register Context_Control_fp *fp_context;
+#endif
+
+ /*
+ * The following code saves a NULL i387 context which is given
+ * to each task at start and restart time. The following code
+ * is based upon that provided in the i386 Programmer's
+ * Manual and should work on any coprocessor greater than
+ * the i80287.
+ *
+ * NOTE: The NO WAIT form of the coprocessor instructions
+ * MUST be used in case there is not a coprocessor
+ * to wait for.
+ */
+
+#if CPU_HARDWARE_FP
+ fp_status = 0xa5a5;
+ __asm__ volatile( "fninit" );
+ __asm__ volatile( "fnstsw %0" : "=a" (fp_status) : "0" (fp_status) );
+
+ if ( fp_status == 0 ) {
+
+ fp_context = &_CPU_Null_fp_context;
+
+#ifdef __SSE__
+ asm volatile( "fstcw %0":"=m"(fp_context->fpucw) );
+#else
+ __asm__ volatile( "fsave (%0)" : "=r" (fp_context)
+ : "0" (fp_context)
+ );
+#endif
+ }
+#endif
+
+#ifdef __SSE__
+
+ __asm__ volatile("stmxcsr %0":"=m"(fp_context->mxcsr));
+
+ /* The BSP must enable the SSE extensions (early).
+ * If any SSE instruction was already attempted
+ * then that crashed the system.
+ * As a courtesy, we double-check here but it
+ * may be too late (which is also why we don't
+ * enable SSE here).
+ */
+ {
+ uint32_t cr4;
+ __asm__ __volatile__("mov %%cr4, %0":"=r"(cr4));
+ if ( 0x600 != (cr4 & 0x600) ) {
+ printk("PANIC: RTEMS was compiled for SSE but BSP did not enable it (CR4: 0x%08x)\n", cr4);
+ while ( 1 ) {
+ __asm__ __volatile__("hlt");
+ }
+ }
+ }
+#endif
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ uint32_t level;
+
+ i386_get_interrupt_level( level );
+
+ return level;
+}
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+ while(1){
+ __asm__ volatile ("hlt");
+ }
+ return NULL;
+}
+
+struct Frame_ {
+ struct Frame_ *up;
+ uintptr_t pc;
+};
+
+void _defaultExcHandler (CPU_Exception_frame *ctx)
+{
+ unsigned int faultAddr = 0;
+ printk("----------------------------------------------------------\n");
+ printk("Exception %d caught at PC %x by thread %d\n",
+ ctx->idtIndex,
+ ctx->eip,
+ _Thread_Executing->Object.id);
+ printk("----------------------------------------------------------\n");
+ printk("Processor execution context at time of the fault was :\n");
+ printk("----------------------------------------------------------\n");
+ printk(" EAX = %x EBX = %x ECX = %x EDX = %x\n",
+ ctx->eax, ctx->ebx, ctx->ecx, ctx->edx);
+ printk(" ESI = %x EDI = %x EBP = %x ESP = %x\n",
+ ctx->esi, ctx->edi, ctx->ebp, ctx->esp0);
+ printk("----------------------------------------------------------\n");
+ printk("Error code pushed by processor itself (if not 0) = %x\n",
+ ctx->faultCode);
+ printk("----------------------------------------------------------\n");
+ if (ctx->idtIndex == I386_EXCEPTION_PAGE_FAULT){
+ faultAddr = i386_get_cr2();
+ printk("Page fault linear address (CR2) = %x\n", faultAddr);
+ printk("----------------------------------------------------------\n\n");
+ }
+ if (_ISR_Nest_level > 0) {
+ /*
+ * In this case we shall not delete the task interrupted as
+ * it has nothing to do with the fault. We cannot return either
+ * because the eip points to the faulty instruction so...
+ */
+ printk("Exception while executing ISR!!!. System locked\n");
+ _CPU_Fatal_halt(faultAddr);
+ }
+ else {
+ struct Frame_ *fp = (struct Frame_*)ctx->ebp;
+ int i;
+
+ printk("Call Stack Trace of EIP:\n");
+ if ( fp ) {
+ for ( i=1; fp->up; fp=fp->up, i++ ) {
+ printk("0x%08x ",fp->pc);
+ if ( ! (i&3) )
+ printk("\n");
+ }
+ }
+ printk("\n");
+ /*
+ * OK I could probably use a simplified version but at least this
+ * should work.
+ */
+ printk(" ************ FAULTY THREAD WILL BE SUSPENDED **************\n");
+ rtems_task_suspend(_Thread_Executing->Object.id);
+ }
+}
+
+cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
+
+extern void rtems_exception_prologue_0(void);
+extern void rtems_exception_prologue_1(void);
+extern void rtems_exception_prologue_2(void);
+extern void rtems_exception_prologue_3(void);
+extern void rtems_exception_prologue_4(void);
+extern void rtems_exception_prologue_5(void);
+extern void rtems_exception_prologue_6(void);
+extern void rtems_exception_prologue_7(void);
+extern void rtems_exception_prologue_8(void);
+extern void rtems_exception_prologue_9(void);
+extern void rtems_exception_prologue_10(void);
+extern void rtems_exception_prologue_11(void);
+extern void rtems_exception_prologue_12(void);
+extern void rtems_exception_prologue_13(void);
+extern void rtems_exception_prologue_14(void);
+extern void rtems_exception_prologue_16(void);
+extern void rtems_exception_prologue_17(void);
+extern void rtems_exception_prologue_18(void);
+#ifdef __SSE__
+extern void rtems_exception_prologue_19(void);
+#endif
+
+static rtems_raw_irq_hdl tbl[] = {
+ rtems_exception_prologue_0,
+ rtems_exception_prologue_1,
+ rtems_exception_prologue_2,
+ rtems_exception_prologue_3,
+ rtems_exception_prologue_4,
+ rtems_exception_prologue_5,
+ rtems_exception_prologue_6,
+ rtems_exception_prologue_7,
+ rtems_exception_prologue_8,
+ rtems_exception_prologue_9,
+ rtems_exception_prologue_10,
+ rtems_exception_prologue_11,
+ rtems_exception_prologue_12,
+ rtems_exception_prologue_13,
+ rtems_exception_prologue_14,
+ 0,
+ rtems_exception_prologue_16,
+ rtems_exception_prologue_17,
+ rtems_exception_prologue_18,
+#ifdef __SSE__
+ rtems_exception_prologue_19,
+#endif
+};
+
+void rtems_exception_init_mngt(void)
+{
+ size_t i,j;
+ interrupt_gate_descriptor *currentIdtEntry;
+ unsigned limit;
+ unsigned level;
+
+ i = sizeof(tbl) / sizeof (rtems_raw_irq_hdl);
+
+ i386_get_info_from_IDTR (&currentIdtEntry, &limit);
+
+ _CPU_ISR_Disable(level);
+ for (j = 0; j < i; j++) {
+ create_interrupt_gate_descriptor (&currentIdtEntry[j], tbl[j]);
+ }
+ _CPU_ISR_Enable(level);
+}
diff --git a/cpukit/score/cpu/i386/cpu_asm.S b/cpukit/score/cpu/i386/cpu_asm.S
new file mode 100644
index 0000000000..418d2bf787
--- /dev/null
+++ b/cpukit/score/cpu/i386/cpu_asm.S
@@ -0,0 +1,320 @@
+/* cpu_asm.s
+ *
+ * This file contains all assembly code for the Intel i386 implementation
+ * of RTEMS.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/cpu.h>
+
+#ifndef CPU_STACK_ALIGNMENT
+#error "Missing header? CPU_STACK_ALIGNMENT not defined"
+#endif
+
+/*
+ * Format of i386 Register structure
+ */
+
+.set REG_EFLAGS, 0
+.set REG_ESP, REG_EFLAGS + 4
+.set REG_EBP, REG_ESP + 4
+.set REG_EBX, REG_EBP + 4
+.set REG_ESI, REG_EBX + 4
+.set REG_EDI, REG_ESI + 4
+.set SIZE_REGS, REG_EDI + 4
+
+ BEGIN_CODE
+
+/*
+ * void _CPU_Context_switch( run_context, heir_context )
+ *
+ * This routine performs a normal non-FP context.
+ */
+
+ .p2align 1
+ PUBLIC (_CPU_Context_switch)
+
+.set RUNCONTEXT_ARG, 4 /* save context argument */
+.set HEIRCONTEXT_ARG, 8 /* restore context argument */
+
+SYM (_CPU_Context_switch):
+ movl RUNCONTEXT_ARG(esp),eax /* eax = running threads context */
+ pushf /* push eflags */
+ popl REG_EFLAGS(eax) /* save eflags */
+ movl esp,REG_ESP(eax) /* save stack pointer */
+ movl ebp,REG_EBP(eax) /* save base pointer */
+ movl ebx,REG_EBX(eax) /* save ebx */
+ movl esi,REG_ESI(eax) /* save source register */
+ movl edi,REG_EDI(eax) /* save destination register */
+
+ movl HEIRCONTEXT_ARG(esp),eax /* eax = heir threads context */
+
+restore:
+ pushl REG_EFLAGS(eax) /* push eflags */
+ popf /* restore eflags */
+ movl REG_ESP(eax),esp /* restore stack pointer */
+ movl REG_EBP(eax),ebp /* restore base pointer */
+ movl REG_EBX(eax),ebx /* restore ebx */
+ movl REG_ESI(eax),esi /* restore source register */
+ movl REG_EDI(eax),edi /* restore destination register */
+ ret
+
+/*
+ * NOTE: May be unnecessary to reload some registers.
+ */
+
+/*
+ * void _CPU_Context_restore( new_context )
+ *
+ * This routine performs a normal non-FP context.
+ */
+
+ PUBLIC (_CPU_Context_restore)
+
+.set NEWCONTEXT_ARG, 4 /* context to restore argument */
+
+SYM (_CPU_Context_restore):
+ movl NEWCONTEXT_ARG(esp),eax /* eax = running threads context */
+ jmp restore
+
+/*PAGE
+ * void _CPU_Context_save_fp_context( &fp_context_ptr )
+ * void _CPU_Context_restore_fp_context( &fp_context_ptr )
+ *
+ * This section is used to context switch an i80287, i80387,
+ * the built-in coprocessor or the i80486 or compatible.
+ */
+
+.set FPCONTEXT_ARG, 4 /* FP context argument */
+
+#ifndef __SSE__
+ .p2align 1
+ PUBLIC (_CPU_Context_save_fp)
+SYM (_CPU_Context_save_fp):
+ movl FPCONTEXT_ARG(esp),eax /* eax = &ptr to FP context area */
+ movl (eax),eax /* eax = FP context area */
+ fsave (eax) /* save FP context */
+ ret
+
+ .p2align 1
+ PUBLIC (_CPU_Context_restore_fp)
+SYM (_CPU_Context_restore_fp):
+ movl FPCONTEXT_ARG(esp),eax /* eax = &ptr to FP context area */
+ movl (eax),eax /* eax = FP context area */
+ frstor (eax) /* restore FP context */
+ ret
+#endif
+
+#ifdef __SSE__
+#define SSE_OFF 16
+#endif
+
+ PUBLIC (_Exception_Handler)
+SYM (_Exception_Handler):
+ pusha /* Push general purpose registers */
+ pushl $0 /* Null pointer to SSE area */
+ movl esp, ebp /* Save original SP */
+#ifndef __SSE__
+ subl $4, esp /* Reserve space for argument */
+ /* Align stack (courtesy for C/gcc) */
+ andl $ - CPU_STACK_ALIGNMENT, esp
+#else
+ subl $512, esp /* Space for SSE area */
+ /* Align stack (courtesy for C/gcc) */
+ andl $ - CPU_STACK_ALIGNMENT, esp
+/* Doing fwait here will re-throw an already pending FP exception!
+ fwait
+ */
+ fxsave 0(esp)
+ fninit /* Clean-slate FPU */
+ movl $0x1f80, 0(ebp)
+ ldmxcsr 0(ebp) /* Clean-slate MXCSR */
+ movl esp, 0(ebp) /* Store pointer to SSE area */
+ subl $SSE_OFF, esp /* Aligned space for argument */
+#endif
+ movl ebp, (esp) /* Store argument */
+ movl _currentExcHandler, eax /* Call function stored in _currentExcHandler */
+ call * eax
+#ifdef __SSE__
+ fwait
+ fxrstor 16(esp)
+#endif
+ movl ebp, esp /* Restore original SP */
+ addl $4, esp /* Skill pointer to SSE area */
+ popa /* Restore general purpose registers */
+ addl $8, esp /* Skill vector number and faultCode */
+ iret
+
+#define DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY(_vector) \
+ .p2align 4 ; \
+ PUBLIC (rtems_exception_prologue_ ## _vector ) ; \
+SYM (rtems_exception_prologue_ ## _vector ): \
+ pushl $ _vector ; \
+ jmp SYM (_Exception_Handler) ;
+
+#define DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY(_vector) \
+ .p2align 4 ; \
+ PUBLIC (rtems_exception_prologue_ ## _vector ) ; \
+SYM (rtems_exception_prologue_ ## _vector ): \
+ pushl $ 0 ; \
+ pushl $ _vector ; \
+ jmp SYM (_Exception_Handler) ;
+
+/*
+ * Divide Error
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (0)
+/*
+ * Debug Exception
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (1)
+/*
+ * NMI
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (2)
+/*
+ * Breakpoint
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (3)
+/*
+ * Overflow
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (4)
+/*
+ * Bound Range Exceeded
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (5)
+/*
+ * Invalid Opcode
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (6)
+/*
+ * No Math Coproc
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (7)
+/*
+ * Double Fault
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (8)
+/*
+ * Coprocessor segment overrun
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (9)
+/*
+ * Invalid TSS
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (10)
+/*
+ * Segment Not Present
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (11)
+/*
+ * Stack segment Fault
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (12)
+/*
+ * General Protection Fault
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (13)
+/*
+ * Page Fault
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (14)
+/*
+ * Floating point error (NB 15 is reserved it is therefor skipped)
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (16)
+/*
+ * Aligment Check
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (17)
+/*
+ * Machine Check
+ */
+DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY (18)
+
+#ifdef __SSE__
+/*
+ * SIMD FP Exception
+ */
+DISTINCT_EXCEPTION_WITHOUT_FAULTCODE_ENTRY (19)
+#endif
+
+
+/*
+ * void *i386_Logical_to_physical(
+ * uint16_t segment,
+ * void *address
+ * );
+ *
+ * Returns thirty-two bit physical address for segment:address.
+ */
+
+.set SEGMENT_ARG, 4
+.set ADDRESS_ARG, 8
+
+ PUBLIC (i386_Logical_to_physical)
+
+SYM (i386_Logical_to_physical):
+
+ xorl eax,eax /* clear eax */
+ movzwl SEGMENT_ARG(esp),ecx /* ecx = segment value */
+ movl $ SYM (_Global_descriptor_table),edx
+ /* edx = address of our GDT */
+ addl ecx,edx /* edx = address of desired entry */
+ movb 7(edx),ah /* ah = base 31:24 */
+ movb 4(edx),al /* al = base 23:16 */
+ shll $16,eax /* move ax into correct bits */
+ movw 2(edx),ax /* ax = base 0:15 */
+ movl ADDRESS_ARG(esp),ecx /* ecx = address to convert */
+ addl eax,ecx /* ecx = physical address equivalent */
+ movl ecx,eax /* eax = ecx */
+ ret
+
+/*
+ * void *i386_Physical_to_logical(
+ * uint16_t segment,
+ * void *address
+ * );
+ *
+ * Returns thirty-two bit physical address for segment:address.
+ */
+
+/*
+ *.set SEGMENT_ARG, 4
+ *.set ADDRESS_ARG, 8 -- use sets from above
+ */
+
+ PUBLIC (i386_Physical_to_logical)
+
+SYM (i386_Physical_to_logical):
+ xorl eax,eax /* clear eax */
+ movzwl SEGMENT_ARG(esp),ecx /* ecx = segment value */
+ movl $ SYM (_Global_descriptor_table),edx
+ /* edx = address of our GDT */
+ addl ecx,edx /* edx = address of desired entry */
+ movb 7(edx),ah /* ah = base 31:24 */
+ movb 4(edx),al /* al = base 23:16 */
+ shll $16,eax /* move ax into correct bits */
+ movw 2(edx),ax /* ax = base 0:15 */
+ movl ADDRESS_ARG(esp),ecx /* ecx = address to convert */
+ subl eax,ecx /* ecx = logical address equivalent */
+ movl ecx,eax /* eax = ecx */
+ ret
+
+END_CODE
+
+END
diff --git a/cpukit/score/cpu/i386/preinstall.am b/cpukit/score/cpu/i386/preinstall.am
new file mode 100644
index 0000000000..7bf7af259a
--- /dev/null
+++ b/cpukit/score/cpu/i386/preinstall.am
@@ -0,0 +1,53 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/i386.h: rtems/score/i386.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/i386.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/i386.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
+$(PROJECT_INCLUDE)/rtems/score/interrupts.h: rtems/score/interrupts.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/interrupts.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/interrupts.h
+
+$(PROJECT_INCLUDE)/rtems/score/registers.h: rtems/score/registers.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/registers.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/registers.h
+
+$(PROJECT_INCLUDE)/rtems/score/idtr.h: rtems/score/idtr.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/idtr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/idtr.h
+
diff --git a/cpukit/score/cpu/i386/rtems/asm.h b/cpukit/score/cpu/i386/rtems/asm.h
new file mode 100644
index 0000000000..f18d54c5b1
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/asm.h
@@ -0,0 +1,139 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/i386.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__
+#endif
+
+/*
+ * Looks like there is a bug in gcc 2.6.2 where this is not
+ * defined correctly when configured as i386-coff and
+ * i386-aout.
+ */
+
+#undef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__ %
+
+/*
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+*/
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT0 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT0 (__REGISTER_PREFIX__, x)
+
+#define eax REG (eax)
+#define ebx REG (ebx)
+#define ecx REG (ecx)
+#define edx REG (edx)
+#define esi REG (esi)
+#define edi REG (edi)
+#define esp REG (esp)
+#define ebp REG (ebp)
+#define cr0 REG (cr0)
+#define cr4 REG (cr4)
+
+#define ax REG (ax)
+#define bx REG (bx)
+#define cx REG (cx)
+#define dx REG (dx)
+#define si REG (si)
+#define di REG (di)
+#define sp REG (sp)
+#define bp REG (bp)
+
+#define ah REG (ah)
+#define bh REG (bh)
+#define ch REG (ch)
+#define dh REG (dh)
+
+#define al REG (al)
+#define bl REG (bl)
+#define cl REG (cl)
+#define dl REG (dl)
+
+#define cs REG (cs)
+#define ds REG (ds)
+#define es REG (es)
+#define fs REG (fs)
+#define gs REG (gs)
+#define ss REG (ss)
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA .data
+#define END_DATA
+#define BEGIN_BSS .bss
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/cpu.h b/cpukit/score/cpu/i386/rtems/score/cpu.h
new file mode 100644
index 0000000000..0e47c285bb
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/cpu.h
@@ -0,0 +1,660 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the Intel
+ * i386 processor.
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifndef ASM
+#include <string.h> /* for memcpy */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/i386.h>
+
+#ifndef ASM
+#include <rtems/score/interrupts.h> /* formerly in libcpu/cpu.h> */
+#include <rtems/score/registers.h> /* formerly part of libcpu */
+#endif
+
+/* conditional compilation parameters */
+
+#define CPU_INLINE_ENABLE_DISPATCH TRUE
+#define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
+
+/*
+ * i386 has an RTEMS allocated and managed interrupt stack.
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Some family members have no FP, some have an FPU such as the i387
+ * for the i386, others have it built in (i486DX, Pentium).
+ */
+
+#ifdef __SSE__
+#define CPU_HARDWARE_FP TRUE
+#define CPU_SOFTWARE_FP FALSE
+
+#define CPU_ALL_TASKS_ARE_FP TRUE
+#define CPU_IDLE_TASK_IS_FP TRUE
+#define CPU_USE_DEFERRED_FP_SWITCH FALSE
+#else /* __SSE__ */
+
+#if ( I386_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE /* i387 for i386 */
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+#define CPU_IDLE_TASK_IS_FP FALSE
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+#endif /* __SSE__ */
+
+#define CPU_STACK_GROWS_UP FALSE
+#define CPU_STRUCTURE_ALIGNMENT
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+#define CPU_BIG_ENDIAN FALSE
+#define CPU_LITTLE_ENDIAN TRUE
+
+/* structures */
+
+#ifndef ASM
+
+/*
+ * Basic integer context for the i386 family.
+ */
+
+typedef struct {
+ uint32_t eflags; /* extended flags register */
+ void *esp; /* extended stack pointer register */
+ void *ebp; /* extended base pointer register */
+ uint32_t ebx; /* extended bx register */
+ uint32_t esi; /* extended source index register */
+ uint32_t edi; /* extended destination index flags register */
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->esp
+
+/*
+ * FP context save area for the i387 numeric coprocessors.
+ */
+#ifdef __SSE__
+/* All FPU and SSE registers are volatile; hence, as long
+ * as we are within normally executing C code (including
+ * a task switch) there is no need for saving/restoring
+ * any of those registers.
+ * We must save/restore the full FPU/SSE context across
+ * interrupts and exceptions, however:
+ * - after ISR execution a _Thread_Dispatch() may happen
+ * and it is therefore necessary to save the FPU/SSE
+ * registers to be restored when control is returned
+ * to the interrupted task.
+ * - gcc may implicitly use FPU/SSE instructions in
+ * an ISR.
+ *
+ * Even though there is no explicit mentioning of the FPU
+ * control word in the SYSV ABI (i386) being non-volatile
+ * we maintain MXCSR and the FPU control-word for each task.
+ */
+typedef struct {
+ uint32_t mxcsr;
+ uint16_t fpucw;
+} Context_Control_fp;
+
+#else
+
+typedef struct {
+ uint8_t fp_save_area[108]; /* context size area for I80387 */
+ /* 28 bytes for environment */
+} Context_Control_fp;
+
+#endif
+
+
+/*
+ * The following structure defines the set of information saved
+ * on the current stack by RTEMS upon receipt of execptions.
+ *
+ * idtIndex is either the interrupt number or the trap/exception number.
+ * faultCode is the code pushed by the processor on some exceptions.
+ *
+ * Since the first registers are directly pushed by the CPU they
+ * may not respect 16-byte stack alignment, which is, however,
+ * mandatory for the SSE register area.
+ * Therefore, these registers are stored at an aligned address
+ * and a pointer is stored in the CPU_Exception_frame.
+ * If the executive was compiled without SSE support then
+ * this pointer is NULL.
+ */
+
+struct Context_Control_sse;
+
+typedef struct {
+ struct Context_Control_sse *fp_ctxt;
+ uint32_t edi;
+ uint32_t esi;
+ uint32_t ebp;
+ uint32_t esp0;
+ uint32_t ebx;
+ uint32_t edx;
+ uint32_t ecx;
+ uint32_t eax;
+ uint32_t idtIndex;
+ uint32_t faultCode;
+ uint32_t eip;
+ uint32_t cs;
+ uint32_t eflags;
+} CPU_Exception_frame;
+
+#ifdef __SSE__
+typedef struct Context_Control_sse {
+ uint16_t fcw;
+ uint16_t fsw;
+ uint8_t ftw;
+ uint8_t res_1;
+ uint16_t fop;
+ uint32_t fpu_ip;
+ uint16_t cs;
+ uint16_t res_2;
+ uint32_t fpu_dp;
+ uint16_t ds;
+ uint16_t res_3;
+ uint32_t mxcsr;
+ uint32_t mxcsr_mask;
+ struct {
+ uint8_t fpreg[10];
+ uint8_t res_4[ 6];
+ } fp_mmregs[8];
+ uint8_t xmmregs[8][16];
+ uint8_t res_5[224];
+} Context_Control_sse
+__attribute__((aligned(16)))
+;
+#endif
+
+typedef void (*cpuExcHandlerType) (CPU_Exception_frame*);
+extern cpuExcHandlerType _currentExcHandler;
+extern void rtems_exception_init_mngt(void);
+
+/*
+ * This port does not pass any frame info to the
+ * interrupt handler.
+ */
+
+typedef void CPU_Interrupt_frame;
+
+typedef enum {
+ I386_EXCEPTION_DIVIDE_BY_ZERO = 0,
+ I386_EXCEPTION_DEBUG = 1,
+ I386_EXCEPTION_NMI = 2,
+ I386_EXCEPTION_BREAKPOINT = 3,
+ I386_EXCEPTION_OVERFLOW = 4,
+ I386_EXCEPTION_BOUND = 5,
+ I386_EXCEPTION_ILLEGAL_INSTR = 6,
+ I386_EXCEPTION_MATH_COPROC_UNAVAIL = 7,
+ I386_EXCEPTION_DOUBLE_FAULT = 8,
+ I386_EXCEPTION_I386_COPROC_SEG_ERR = 9,
+ I386_EXCEPTION_INVALID_TSS = 10,
+ I386_EXCEPTION_SEGMENT_NOT_PRESENT = 11,
+ I386_EXCEPTION_STACK_SEGMENT_FAULT = 12,
+ I386_EXCEPTION_GENERAL_PROT_ERR = 13,
+ I386_EXCEPTION_PAGE_FAULT = 14,
+ I386_EXCEPTION_INTEL_RES15 = 15,
+ I386_EXCEPTION_FLOAT_ERROR = 16,
+ I386_EXCEPTION_ALIGN_CHECK = 17,
+ I386_EXCEPTION_MACHINE_CHECK = 18,
+ I386_EXCEPTION_ENTER_RDBG = 50 /* to enter manually RDBG */
+
+} Intel_symbolic_exception_name;
+
+
+/*
+ * context size area for floating point
+ *
+ * NOTE: This is out of place on the i386 to avoid a forward reference.
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/* variables */
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+#endif /* ASM */
+
+/* constants */
+
+/*
+ * This defines the number of levels and the mask used to pick those
+ * bits out of a thread mode.
+ */
+
+#define CPU_MODES_INTERRUPT_LEVEL 0x00000001 /* interrupt level in mode */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001 /* interrupt level in mode */
+
+/*
+ * extra stack required by the MPCI receive server thread
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
+
+/*
+ * i386 family supports 256 distinct vectors.
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 256
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Minimum size of a thread's stack.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE 4096
+
+/*
+ * i386 is pretty tolerant of alignment. Just put things on 4 byte boundaries.
+ */
+
+#define CPU_ALIGNMENT 4
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * On i386 thread stacks require no further alignment after allocation
+ * from the Workspace. However, since gcc maintains 16-byte alignment
+ * we try to respect that. If you find an option to let gcc squeeze
+ * the stack more tightly then setting CPU_STACK_ALIGNMENT to 16 still
+ * doesn't waste much space since this only determines the *initial*
+ * alignment.
+ */
+
+#define CPU_STACK_ALIGNMENT 16
+
+/* macros */
+
+#ifndef ASM
+/*
+ * ISR handler macros
+ *
+ * These macros perform the following functions:
+ * + initialize the RTEMS vector table
+ * + disable all maskable CPU interrupts
+ * + restore previous interrupt level (enable)
+ * + temporarily restore interrupts (flash)
+ * + set a particular level
+ */
+
+#define _CPU_Initialize_vectors()
+
+#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
+
+#define _CPU_ISR_Enable( _level ) i386_enable_interrupts( _level )
+
+#define _CPU_ISR_Flash( _level ) i386_flash_interrupts( _level )
+
+#define _CPU_ISR_Set_level( _new_level ) \
+ { \
+ if ( _new_level ) __asm__ volatile ( "cli" ); \
+ else __asm__ volatile ( "sti" ); \
+ }
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* Make sure interrupt stack has space for ISR
+ * 'vector' arg at the top and that it is aligned
+ * properly.
+ */
+
+#define _CPU_Interrupt_stack_setup( _lo, _hi ) \
+ do { \
+ _hi = (void*)(((uintptr_t)(_hi) - 4) & ~ (CPU_STACK_ALIGNMENT - 1)); \
+ } while (0)
+
+#endif /* ASM */
+
+/* end of ISR handler macros */
+
+/*
+ * Context handler macros
+ *
+ * These macros perform the following functions:
+ * + initialize a context area
+ * + restart the current thread
+ * + calculate the initial pointer into a FP context area
+ * + initialize an FP context area
+ */
+
+#define CPU_EFLAGS_INTERRUPTS_ON 0x00003202
+#define CPU_EFLAGS_INTERRUPTS_OFF 0x00003002
+
+#ifndef ASM
+
+/*
+ * Stack alignment note:
+ *
+ * We want the stack to look to the '_entry_point' routine
+ * like an ordinary stack frame as if '_entry_point' was
+ * called from C-code.
+ * Note that '_entry_point' is jumped-to by the 'ret'
+ * instruction returning from _CPU_Context_switch() or
+ * _CPU_Context_restore() thus popping the _entry_point
+ * from the stack.
+ * However, _entry_point expects a frame to look like this:
+ *
+ * args [_Thread_Handler expects no args, however]
+ * ------ (alignment boundary)
+ * SP-> return_addr return here when _entry_point returns which (never happens)
+ *
+ *
+ * Hence we must initialize the stack as follows
+ *
+ * [arg1 ]: n/a
+ * [arg0 (aligned)]: n/a
+ * [ret. addr ]: NULL
+ * SP-> [jump-target ]: _entry_point
+ *
+ * When Context_switch returns it pops the _entry_point from
+ * the stack which then finds a standard layout.
+ */
+
+
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ do { \
+ uint32_t _stack; \
+ \
+ if ( (_isr) ) (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_OFF; \
+ else (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_ON; \
+ \
+ _stack = ((uint32_t)(_stack_base)) + (_size); \
+ _stack &= ~ (CPU_STACK_ALIGNMENT - 1); \
+ _stack -= 2*sizeof(proc_ptr*); /* see above for why we need to do this */ \
+ *((proc_ptr *)(_stack)) = (_entry_point); \
+ (_the_context)->ebp = (void *) 0; \
+ (_the_context)->esp = (void *) _stack; \
+ } while (0)
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+#if defined(RTEMS_SMP)
+ #define _CPU_Context_switch_to_first_task_smp( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+ /* address space 1 is uncacheable */
+ #define SMP_CPU_SWAP( _address, _value, _previous ) \
+ do { \
+ asm volatile("lock; xchgl %0, %1" : \
+ "+m" (*_address), "=a" (_previous) : \
+ "1" (_value) : \
+ "cc"); \
+ } while (0)
+#endif
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+#define _CPU_Context_Initialize_fp( _fp_area ) \
+ { \
+ memcpy( *_fp_area, &_CPU_Null_fp_context, CPU_CONTEXT_FP_SIZE ); \
+ }
+
+/* end of Context handler macros */
+
+/*
+ * Fatal Error manager macros
+ *
+ * These macros perform the following functions:
+ * + disable interrupts and halt the CPU
+ */
+
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ __asm__ volatile ( "cli ; \
+ movl %0,%%eax ; \
+ hlt" \
+ : "=r" ((_error)) : "0" ((_error)) \
+ ); \
+ }
+
+#endif /* ASM */
+
+/* end of Fatal Error manager macros */
+
+/*
+ * Bitfield handler macros
+ *
+ * These macros perform the following functions:
+ * + scan for the highest numbered (MSB) set in a 16 bit bitfield
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
+#define CPU_USE_GENERIC_BITFIELD_DATA FALSE
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ register uint16_t __value_in_register = (_value); \
+ \
+ _output = 0; \
+ \
+ __asm__ volatile ( "bsfw %0,%1 " \
+ : "=r" (__value_in_register), "=r" (_output) \
+ : "0" (__value_in_register), "1" (_output) \
+ ); \
+ }
+
+/* end of Bitfield handler macros */
+
+/*
+ * Priority handler macros
+ *
+ * These macros perform the following functions:
+ * + return a mask with the bit for this major/minor portion of
+ * of thread priority set.
+ * + translate the bit number returned by "Bitfield_find_first_bit"
+ * into an index into the thread ready chain bit maps
+ */
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+/* functions */
+
+#ifndef ASM
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Thread_Idle_body
+ *
+ * Use the halt instruction of low power mode of a particular i386 model.
+ */
+
+#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner and avoid stack conflicts.
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+#ifdef __SSE__
+#define _CPU_Context_save_fp(fp_context_pp) \
+ do { \
+ __asm__ __volatile__( \
+ "fstcw %0" \
+ :"=m"((*(fp_context_pp))->fpucw) \
+ ); \
+ __asm__ __volatile__( \
+ "stmxcsr %0" \
+ :"=m"((*(fp_context_pp))->mxcsr) \
+ ); \
+ } while (0)
+#else
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+#endif
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+#ifdef __SSE__
+#define _CPU_Context_restore_fp(fp_context_pp) \
+ do { \
+ __asm__ __volatile__( \
+ "fldcw %0" \
+ ::"m"((*(fp_context_pp))->fpucw) \
+ :"fpcr" \
+ ); \
+ __builtin_ia32_ldmxcsr(_Thread_Executing->fp_context->mxcsr); \
+ } while (0)
+#else
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+#endif
+
+#ifdef __SSE__
+#define _CPU_Context_Initialization_at_thread_begin() \
+ do { \
+ __asm__ __volatile__( \
+ "finit" \
+ : \
+ : \
+ :"st","st(1)","st(2)","st(3)", \
+ "st(4)","st(5)","st(6)","st(7)", \
+ "fpsr","fpcr" \
+ ); \
+ if ( _Thread_Executing->fp_context ) { \
+ _CPU_Context_restore_fp(&_Thread_Executing->fp_context); \
+ } \
+ } while (0)
+#endif
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/i386.h b/cpukit/score/cpu/i386/rtems/score/i386.h
new file mode 100644
index 0000000000..2d8a8969cb
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/i386.h
@@ -0,0 +1,246 @@
+/**
+ * @file rtems/score/i386.h
+ */
+
+/*
+ * This include file contains information pertaining to the Intel
+ * i386 processor.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_I386_H
+#define _RTEMS_SCORE_I386_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section contains the information required to build
+ * RTEMS for a particular member of the Intel i386
+ * family when executing in protected mode. It does
+ * this by setting variables to indicate which implementation
+ * dependent features are present in a particular member
+ * of the family.
+ *
+ * Currently recognized:
+ * i386_fp (i386 DX or SX w/i387)
+ * i386_nofp (i386 DX or SX w/o i387)
+ * i486dx
+ * i486sx
+ * pentium
+ * pentiumpro
+ *
+ * CPU Model Feature Flags:
+ *
+ * I386_HAS_BSWAP: Defined to "1" if the instruction for endian swapping
+ * (bswap) should be used. This instruction appears to
+ * be present in all i486's and above.
+ *
+ * I386_HAS_FPU: Defined to "1" if the CPU has an FPU.
+ *
+ */
+
+#if defined(_SOFT_FLOAT)
+#define I386_HAS_FPU 0
+#else
+#define I386_HAS_FPU 1
+#endif
+
+#if defined(__pentiumpro__)
+
+#define CPU_MODEL_NAME "Pentium Pro"
+
+#elif defined(__i586__)
+
+# if defined(__pentium__)
+# define CPU_MODEL_NAME "Pentium"
+# elif defined(__k6__)
+# define CPU_MODEL_NAME "K6"
+# else
+# define CPU_MODEL_NAME "i586"
+# endif
+
+#elif defined(__i486__)
+
+# if !defined(_SOFT_FLOAT)
+# define CPU_MODEL_NAME "i486dx"
+# else
+# define CPU_MODEL_NAME "i486sx"
+# endif
+
+#elif defined(__i386__)
+
+#define I386_HAS_BSWAP 0
+
+# if !defined(_SOFT_FLOAT)
+# define CPU_MODEL_NAME "i386 with i387"
+# else
+# define CPU_MODEL_NAME "i386 w/o i387"
+# endif
+
+#else
+#error "Unknown CPU Model"
+#endif
+
+/*
+ * Set default values for CPU model feature flags
+ *
+ * NOTE: These settings are chosen to reflect most of the family members.
+ */
+
+#ifndef I386_HAS_FPU
+#define I386_HAS_FPU 1
+#endif
+
+#ifndef I386_HAS_BSWAP
+#define I386_HAS_BSWAP 1
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "Intel i386"
+
+#ifndef ASM
+
+/*
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static so it can be referenced indirectly.
+ */
+
+static inline uint32_t i386_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t lout;
+
+#if (I386_HAS_BSWAP == 0)
+ __asm__ volatile( "rorw $8,%%ax;"
+ "rorl $16,%0;"
+ "rorw $8,%%ax" : "=a" (lout) : "0" (value) );
+#else
+ __asm__ volatile( "bswap %0" : "=r" (lout) : "0" (value));
+#endif
+ return( lout );
+}
+
+static inline uint16_t i386_swap_u16(
+ uint16_t value
+)
+{
+ unsigned short sout;
+
+ __asm__ volatile( "rorw $8,%0" : "=r" (sout) : "0" (value));
+ return (sout);
+}
+
+
+/*
+ * Added for pagination management
+ */
+
+static inline unsigned int i386_get_cr0(void)
+{
+ register unsigned int segment = 0;
+
+ __asm__ volatile ( "movl %%cr0,%0" : "=r" (segment) : "0" (segment) );
+
+ return segment;
+}
+
+static inline void i386_set_cr0(unsigned int segment)
+{
+ __asm__ volatile ( "movl %0,%%cr0" : "=r" (segment) : "0" (segment) );
+}
+
+static inline unsigned int i386_get_cr2(void)
+{
+ register unsigned int segment = 0;
+
+ __asm__ volatile ( "movl %%cr2,%0" : "=r" (segment) : "0" (segment) );
+
+ return segment;
+}
+
+static inline unsigned int i386_get_cr3(void)
+{
+ register unsigned int segment = 0;
+
+ __asm__ volatile ( "movl %%cr3,%0" : "=r" (segment) : "0" (segment) );
+
+ return segment;
+}
+
+static inline void i386_set_cr3(unsigned int segment)
+{
+ __asm__ volatile ( "movl %0,%%cr3" : "=r" (segment) : "0" (segment) );
+}
+
+/* routines */
+
+/*
+ * i386_Logical_to_physical
+ *
+ * Converts logical address to physical address.
+ */
+
+void *i386_Logical_to_physical(
+ unsigned short segment,
+ void *address
+);
+
+/*
+ * i386_Physical_to_logical
+ *
+ * Converts physical address to logical address.
+ */
+
+void *i386_Physical_to_logical(
+ unsigned short segment,
+ void *address
+);
+
+
+/*
+ * "Simpler" names for a lot of the things defined in this file
+ */
+
+/* segment access routines */
+
+#define get_cs() i386_get_cs()
+#define get_ds() i386_get_ds()
+#define get_es() i386_get_es()
+#define get_ss() i386_get_ss()
+#define get_fs() i386_get_fs()
+#define get_gs() i386_get_gs()
+
+#define CPU_swap_u32( _value ) i386_swap_u32( _value )
+#define CPU_swap_u16( _value ) i386_swap_u16( _value )
+
+/* i80x86 I/O instructions */
+
+#define outport_byte( _port, _value ) i386_outport_byte( _port, _value )
+#define outport_word( _port, _value ) i386_outport_word( _port, _value )
+#define outport_long( _port, _value ) i386_outport_long( _port, _value )
+#define inport_byte( _port, _value ) i386_inport_byte( _port, _value )
+#define inport_word( _port, _value ) i386_inport_word( _port, _value )
+#define inport_long( _port, _value ) i386_inport_long( _port, _value )
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/idtr.h b/cpukit/score/cpu/i386/rtems/score/idtr.h
new file mode 100644
index 0000000000..361c8472b9
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/idtr.h
@@ -0,0 +1,66 @@
+/**
+ * @file rtems/score/idtr.h
+ */
+
+/*
+ * This file contains definitions for data structure related
+ * to Intel system programming. More information can be found
+ * on Intel site and more precisely in the following book :
+ *
+ * Pentium Processor familly
+ * Developper's Manual
+ *
+ * Volume 3 : Architecture and Programming Manual
+ *
+ * Formerly contained in and extracted from libcpu/i386/cpu.h.
+ *
+ * COPYRIGHT (C) 1998 Eric Valette (valette@crf.canon.fr)
+ * Canon Centre Recherche France.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ * Applications must not include this file directly.
+ */
+
+#ifndef _RTEMS_SCORE_IDTR_H
+#define _RTEMS_SCORE_IDTR_H
+
+/*
+ * See page 14.9 Figure 14-2.
+ *
+ */
+typedef struct
+{
+ unsigned int low_offsets_bits:16;
+ unsigned int segment_selector:16;
+ unsigned int fixed_value_bits:8;
+ unsigned int gate_type:5;
+ unsigned int privilege:2;
+ unsigned int present:1;
+ unsigned int high_offsets_bits:16;
+} interrupt_gate_descriptor;
+
+/*
+ * C callable function enabling to create a interrupt_gate_descriptor
+ */
+extern void create_interrupt_gate_descriptor (interrupt_gate_descriptor*, rtems_raw_irq_hdl);
+
+/*
+ * C callable function enabling to get easily usable info from
+ * the actual value of IDT register.
+ */
+extern void i386_get_info_from_IDTR (interrupt_gate_descriptor** table,
+ unsigned* limit);
+
+/*
+ * C callable function enabling to change the value of IDT register. Must be called
+ * with interrupts masked at processor level!!!.
+ */
+extern void i386_set_IDTR (interrupt_gate_descriptor* table,
+ unsigned limit);
+
+#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/interrupts.h b/cpukit/score/cpu/i386/rtems/score/interrupts.h
new file mode 100644
index 0000000000..b6b541fb0e
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/interrupts.h
@@ -0,0 +1,79 @@
+/**
+ * @file rtems/score/interrupts.h
+ */
+
+/*
+ * i386 interrupt macros.
+ *
+ * Formerly contained in and extracted from libcpu/i386/cpu.h
+ *
+ * COPYRIGHT (c) 1998 valette@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ * Applications must not include this file directly.
+ */
+
+#ifndef _RTEMS_SCORE_INTERRUPTS_H
+#define _RTEMS_SCORE_INTERRUPTS_H
+
+#ifndef ASM
+
+struct __rtems_raw_irq_connect_data__;
+
+typedef void (*rtems_raw_irq_hdl) (void);
+typedef void (*rtems_raw_irq_enable) (const struct __rtems_raw_irq_connect_data__*);
+typedef void (*rtems_raw_irq_disable) (const struct __rtems_raw_irq_connect_data__*);
+typedef int (*rtems_raw_irq_is_enabled) (const struct __rtems_raw_irq_connect_data__*);
+
+/*
+ * Interrupt Level Macros
+ */
+
+#define i386_disable_interrupts( _level ) \
+ { \
+ __asm__ volatile ( "pushf ; \
+ cli ; \
+ pop %0" \
+ : "=rm" ((_level)) \
+ ); \
+ }
+
+#define i386_enable_interrupts( _level ) \
+ { \
+ __asm__ volatile ( "push %0 ; \
+ popf" \
+ : : "rm" ((_level)) : "cc" \
+ ); \
+ }
+
+#define i386_flash_interrupts( _level ) \
+ { \
+ __asm__ volatile ( "push %0 ; \
+ popf ; \
+ cli" \
+ : : "rm" ((_level)) : "cc" \
+ ); \
+ }
+
+#define i386_get_interrupt_level( _level ) \
+ do { \
+ register uint32_t _eflags; \
+ \
+ __asm__ volatile ( "pushf ; \
+ pop %0" \
+ : "=rm" ((_eflags)) \
+ ); \
+ \
+ _level = (_eflags & EFLAGS_INTR_ENABLE) ? 0 : 1; \
+ } while (0)
+
+#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
+#define _CPU_ISR_Enable( _level ) i386_enable_interrupts( _level )
+
+#endif
+#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/registers.h b/cpukit/score/cpu/i386/rtems/score/registers.h
new file mode 100644
index 0000000000..81c2a65e15
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/registers.h
@@ -0,0 +1,72 @@
+/**
+ * @file rtems/score/registers.h
+ */
+
+/*
+ * This file contains definition and constants related to Intel Cpu
+ *
+ * COPYRIGHT (c) 1998 valette@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_REGISTERS_H
+#define _RTEMS_SCORE_REGISTERS_H
+
+/*
+ * definition related to EFLAGS
+ */
+#define EFLAGS_CARRY 0x1
+#define EFLAGS_PARITY 0x4
+
+#define EFLAGS_AUX_CARRY 0x10
+#define EFLAGS_ZERO 0x40
+#define EFLAGS_SIGN 0x80
+
+#define EFLAGS_TRAP 0x100
+#define EFLAGS_INTR_ENABLE 0x200
+#define EFLAGS_DIRECTION 0x400
+#define EFLAGS_OVERFLOW 0x800
+
+#define EFLAGS_IOPL_MASK 0x3000
+#define EFLAGS_NESTED_TASK 0x8000
+
+#define EFLAGS_RESUME 0x10000
+#define EFLAGS_VIRTUAL_MODE 0x20000
+#define EFLAGS_ALIGN_CHECK 0x40000
+#define EFLAGS_VIRTUAL_INTR 0x80000
+
+#define EFLAGS_VIRTUAL_INTR_PEND 0x100000
+#define EFLAGS_ID 0x200000
+
+/*
+ * definitions related to CR0
+ */
+#define CR0_PROTECTION_ENABLE 0x1
+#define CR0_MONITOR_COPROC 0x2
+#define CR0_COPROC_SOFT_EMUL 0x4
+#define CR0_FLOATING_INSTR_EXCEPTION 0x8
+
+#define CR0_EXTENSION_TYPE 0x10
+#define CR0_NUMERIC_ERROR 0x20
+
+#define CR0_WRITE_PROTECT 0x10000
+#define CR0_ALIGMENT_MASK 0x40000
+
+#define CR0_NO_WRITE_THROUGH 0x20000000
+#define CR0_PAGE_LEVEL_CACHE_DISABLE 0x40000000
+#define CR0_PAGING 0x80000000
+
+/*
+ * definitions related to CR3
+ */
+
+#define CR3_PAGE_CACHE_DISABLE 0x10
+#define CR3_PAGE_WRITE_THROUGH 0x8
+#define CR3_PAGE_DIRECTORY_MASK 0xFFFFF000
+
+#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/types.h b/cpukit/score/cpu/i386/rtems/score/types.h
new file mode 100644
index 0000000000..3a21714a0a
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Intel
+ * i386 processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void i386_isr;
+typedef i386_isr ( *i386_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/i386/sse_test.c b/cpukit/score/cpu/i386/sse_test.c
new file mode 100644
index 0000000000..8b1cbd2658
--- /dev/null
+++ b/cpukit/score/cpu/i386/sse_test.c
@@ -0,0 +1,954 @@
+/* $Id$ */
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2009,
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+
+/* Code for testing FPU/SSE context save/restore across exceptions
+ * (including interrupts).
+ *
+ * There are two tasks and an IRQ/EXC handler involved. One task (LP)
+ * is of lower priority than the other (HP) task.
+ *
+ * 1) LP task sets up a context area in memory (known contents; every
+ * register is loaded with different values)
+ *
+ * 2) LP task
+ * 2a saves original FP/SSE context
+ * 2b loads context from 1) into FPU/SSE
+ * 2c raises an exception or interrupt
+ *
+ * * (2d save FPU/SSE context after irq/exception returns to
+ * separate area for verification
+ * 2e reload original FP/SSE context.)
+ *
+ * * All these five steps are coded in assembly to prevent
+ * gcc from manipulating the FP/SSE state. The last two steps,
+ * however, are effectively executed during 6 when control is
+ * returned to the LP task.
+ *
+ * 3) IRQ/EXC handler OS wrapper saves context, initializes FPU and
+ * MXCSR.
+ *
+ * 4) user (our) irq/exc handler clears exception condition, clobbers
+ * FPU and XMM regs and finally releases a semaphore on which HP
+ * task is waiting.
+ *
+ * 5) context switch to HP task. HP task clobbers FPU and XMM regs.
+ * Then it tries to re-acquire the synchronization semaphore and
+ * blocks.
+ *
+ * 6) task switch back to (interrupted) LP task. Original context is
+ * restored and verified against the context that was setup in 1).
+ *
+ *
+ * Three methods for interrupting the LP task are tested
+ *
+ * a) FP exception (by setting an exception status in the context from 1)
+ * b) SSE exception (by computing the square root of a vector of negative
+ * numbers.
+ * c) IRQ (software IRQ via 'INT xx' instruction)
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef __rtems__
+#include <rtems.h>
+#include <rtems/score/cpu.h>
+#include <rtems/irq.h>
+#include <rtems/error.h>
+#endif
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+/* This is currently hardcoded (int xx opcode requires immediate operand) */
+#define SSE_TEST_IRQ 10
+
+typedef uint8_t __v8 __attribute__((vector_size(16)));
+typedef uint32_t __v32 __attribute__((vector_size(16)));
+typedef float __vf __attribute__((vector_size(16)));
+
+#ifndef __rtems__
+/* Clone of what is defined in rtems/score/cpu.h (for testing under linux) */
+typedef struct Context_Control_sse {
+ uint16_t fcw;
+ uint16_t fsw;
+ uint8_t ftw;
+ uint8_t res_1;
+ uint16_t fop;
+ uint32_t fpu_ip;
+ uint16_t cs;
+ uint16_t res_2;
+ uint32_t fpu_dp;
+ uint16_t ds;
+ uint16_t res_3;
+ uint32_t mxcsr;
+ uint32_t mxcsr_mask;
+ struct {
+ uint8_t fpreg[10];
+ uint8_t res_4[ 6];
+ } fp_mmregs[8];
+ uint8_t xmmregs[8][16];
+ uint8_t res_5[224];
+} Context_Control_sse
+__attribute__((aligned(16)))
+;
+#endif
+
+#define MXCSR_FZ (1<<15) /* Flush to zero */
+#define MXCSR_RC(x) (((x)&3)<<13) /* Rounding ctrl */
+#define MXCSR_PM (1<<12) /* Precision msk */
+#define MXCSR_UM (1<<11) /* Underflow msk */
+#define MXCSR_OM (1<<10) /* Overflow msk */
+#define MXCSR_ZM (1<< 9) /* Divbyzero msk */
+#define MXCSR_DM (1<< 8) /* Denormal msk */
+#define MXCSR_IM (1<< 7) /* Invalidop msk */
+#define MXCSR_DAZ (1<< 6) /* Denorml are 0 */
+#define MXCSR_PE (1<< 5) /* Precision flg */
+#define MXCSR_UE (1<< 4) /* Underflow flg */
+#define MXCSR_OE (1<< 3) /* Overflow flg */
+#define MXCSR_ZE (1<< 2) /* Divbyzero flg */
+#define MXCSR_DE (1<< 1) /* Denormal flg */
+#define MXCSR_IE (1<< 0) /* Invalidop flg */
+
+#define MXCSR_ALLM (MXCSR_PM | MXCSR_UM | MXCSR_OM | MXCSR_ZM | MXCSR_DM | MXCSR_IM)
+#define MXCSR_ALLE (MXCSR_PE | MXCSR_UE | MXCSR_OE | MXCSR_ZE | MXCSR_DE | MXCSR_IE)
+
+#define FPSR_B (1<<15) /* FPU busy */
+#define FPSR_C3 (1<<14) /* Cond code C3 */
+#define FPSR_TOP(x) (((x)&7)<<11) /* TOP */
+#define FPSR_C2 (1<<10) /* Cond code C2 */
+#define FPSR_C1 (1<< 9) /* Cond code C1 */
+#define FPSR_C0 (1<< 8) /* Cond code C0 */
+#define FPSR_ES (1<< 7) /* Error summary */
+#define FPSR_SF (1<< 6) /* Stack fault */
+#define FPSR_PE (1<< 5) /* Precision flg */
+#define FPSR_UE (1<< 4) /* Underflow flg */
+#define FPSR_OE (1<< 3) /* Overflow flg */
+#define FPSR_ZE (1<< 2) /* Divbyzero flg */
+#define FPSR_DE (1<< 1) /* Denormal flg */
+#define FPSR_IE (1<< 0) /* Invalidop flg */
+
+#define FPCW_X (1<<12) /* Infinity ctrl */
+#define FPCW_RC(x) (((x)&3)<<10) /* Rounding ctrl */
+#define FPCW_PC(x) (((x)&3)<< 8) /* Precision ctl */
+#define FPCW_PM (1<< 5) /* Precision msk */
+#define FPCW_UM (1<< 4) /* Underflow msk */
+#define FPCW_OM (1<< 3) /* Overflow msk */
+#define FPCW_ZM (1<< 2) /* Divbyzero msk */
+#define FPCW_DM (1<< 1) /* Denormal msk */
+#define FPCW_IM (1<< 0) /* Invalidop msk */
+
+#define FPCW_ALLM (FPCW_PM | FPCW_UM | FPCW_OM | FPCW_ZM | FPCW_DM | FPCW_IM)
+#define FPSR_ALLE (FPSR_ES | FPSR_SF | FPSR_PE | FPSR_UE | FPSR_OE | FPSR_ZE | FPSR_DE | FPSR_IE)
+
+/* Store 'double' into 80-bit register image */
+void
+fp_st1(uint8_t (*p_dst)[10], double v)
+{
+ asm volatile("fstpt %0":"=m"(*p_dst):"t"(v):"st");
+}
+
+/* Store 'double' into 80-bit register image #i in context */
+void
+fp_st(Context_Control_sse *p_ctxt, int i, double v)
+{
+ fp_st1(&p_ctxt->fp_mmregs[i].fpreg,v);
+}
+
+/* Load 'double' from 80-bit register image */
+double
+fp_ld1(uint8_t (*p_src)[10])
+{
+double v;
+
+ asm volatile("fldt %1":"=t"(v):"m"((*p_src)[0]),"m"(*p_src));
+ return v;
+}
+
+/* Load 'double' from 80-bit register image #i in context */
+double
+fp_ld(Context_Control_sse *p_ctxt, int i)
+{
+ return fp_ld1(&p_ctxt->fp_mmregs[i].fpreg);
+}
+
+#define FPUCLOBBER \
+ "st","st(1)","st(2)","st(3)", \
+ "st(4)","st(5)","st(6)","st(7)",\
+ "fpsr","fpcr"
+
+/* There seems to be no way to say that mxcsr was clobbered */
+
+#define SSECLOBBER \
+ "xmm0","xmm1","xmm2","xmm3", \
+ "xmm4","xmm5","xmm6","xmm7"
+
+static void
+sse_clobber(uint32_t x)
+{
+__v32 v = { x, x, x, x };
+ asm volatile (
+ " movdqa %0, %%xmm0 \n"
+ " movdqa %%xmm0, %%xmm1 \n"
+ " movdqa %%xmm0, %%xmm2 \n"
+ " movdqa %%xmm0, %%xmm3 \n"
+ " movdqa %%xmm0, %%xmm4 \n"
+ " movdqa %%xmm0, %%xmm5 \n"
+ " movdqa %%xmm0, %%xmm6 \n"
+ " movdqa %%xmm0, %%xmm7 \n"
+ :
+ :"m"(v)
+ :SSECLOBBER
+ );
+}
+
+void
+all_clobber(uint32_t v1, uint32_t v2);
+
+__asm__ (
+"all_clobber: \n"
+" finit \n"
+" movq 0(%esp), %xmm0 \n"
+" punpcklqdq %xmm0, %xmm0 \n"
+" movdqa %xmm0, %xmm1 \n"
+" movdqa %xmm0, %xmm2 \n"
+" movdqa %xmm0, %xmm3 \n"
+" movdqa %xmm0, %xmm4 \n"
+" movdqa %xmm0, %xmm5 \n"
+" movdqa %xmm0, %xmm6 \n"
+" movdqa %xmm0, %xmm7 \n"
+" ret \n"
+);
+
+/* Clear FPU and save FPU/SSE registers to context area */
+
+void
+init_ctxt(Context_Control_sse *p_ctxt);
+
+__asm__ (
+"init_ctxt: \n"
+" finit \n"
+" mov 4(%esp), %eax\n"
+" fxsave (%eax) \n"
+" fwait \n"
+" ret \n"
+);
+
+/* Save FPU/SSE registers to context area */
+
+static void
+stor_ctxt(Context_Control_sse *p_ctxt)
+{
+ memset(p_ctxt, 0, sizeof(*p_ctxt));
+ asm volatile(
+/* " finit \n" */
+ " fxsave %0 \n"
+ " fwait \n"
+ : "=m"(*p_ctxt)
+ :
+ : FPUCLOBBER
+ );
+}
+
+#define H08 "0x%02"PRIx8
+#define H16 "0x%04"PRIx16
+#define H32 "0x%08"PRIx32
+
+#define F16 "mismatch ("H16" != "H16")\n"
+
+#define FLDCMP(fld, fmt) \
+ if ( a->fld != b->fld ) { \
+ rval = 1; \
+ if ( !quiet ) \
+ fprintf(stderr,#fld" mismatch ("fmt" != "fmt")\n",a->fld, b->fld); \
+ }
+
+#define FLTCMP(i) \
+ do { \
+ if ( ( (a->ftw ^ b->ftw) & (1<<i)) \
+ || ( (a->ftw & b->ftw & (1<<i)) && \
+ memcmp(a->fp_mmregs[i].fpreg, \
+ b->fp_mmregs[i].fpreg, \
+ sizeof(a->fp_mmregs[i].fpreg)) \
+ ) \
+ ) { \
+ rval = 1; \
+ if ( !quiet ) { \
+ double fa = fp_ld(a, i); \
+ double fb = fp_ld(b, i); \
+ if ( ((a->ftw ^ b->ftw) & (1<<i)) ) \
+ fprintf(stderr,"fpreg[%u] TAG mismatch (%u != %u)\n",i,(a->ftw & (1<<i)) ? 1 : 0,(b->ftw & (1<<i)) ? 1 : 0); \
+ else \
+ fprintf(stderr,"fpreg[%u] mismatch (%g != %g)\n",i,fa,fb); \
+ } \
+ } \
+ } while (0)
+
+#define XMMCMP(i) \
+ do { \
+ if ( memcmp(&a->xmmregs[i], \
+ &b->xmmregs[i], \
+ sizeof(a->xmmregs[i])) \
+ ) { \
+ rval = 1; \
+ if ( !quiet ) { \
+ int _jj; \
+ fprintf(stderr,"xmmreg[%u] mismatch:\n", i); \
+ fprintf(stderr," "); \
+ for (_jj=0; _jj<16; _jj++) \
+ fprintf(stderr,"%02x ",a->xmmregs[i][_jj]); \
+ fprintf(stderr,"\n !=\n"); \
+ fprintf(stderr," "); \
+ for (_jj=0; _jj<16; _jj++) \
+ fprintf(stderr,"%02x ",b->xmmregs[i][_jj]); \
+ fprintf(stderr,"\n"); \
+ } \
+ } \
+ } while (0)
+
+
+/* Compare two FPU/SSE context areas and flag differences;
+ * RETURNS: zero if the contexts match and nonzero otherwise
+ */
+static int
+cmp_ctxt(Context_Control_sse *a, Context_Control_sse *b, int quiet)
+{
+int rval = 0;
+int i;
+ FLDCMP(fcw,H16);
+ FLDCMP(fsw,H16);
+ FLDCMP(ftw,H08);
+ FLDCMP(fop,H16);
+ FLDCMP(fpu_ip,H32);
+ FLDCMP(cs,H16);
+ FLDCMP(fpu_dp,H32);
+ FLDCMP(ds,H16);
+ FLDCMP(mxcsr,H32);
+ FLDCMP(mxcsr_mask,H32);
+ for ( i=0; i<8; i++ ) {
+ FLTCMP(i);
+ }
+ for ( i=0; i<8; i++ ) {
+ XMMCMP(i);
+ }
+ return rval;
+}
+
+/* Possible arguments to exc_raise() */
+
+#define FP_EXC 0
+#define IRQ_EXC 1
+#define SSE_EXC -1
+
+/* Check stack alignment by raising the interrupt from a
+ * non-16-byte aligned section of code. The exception/IRQ
+ * handler must align the stack and SSE context area
+ * properly or it will crash.
+ */
+#define __INTRAISE(x) " int $32+"#x" \n"
+#define INTRAISE(x) __INTRAISE(x)
+
+__asm__ (
+"do_raise: \n"
+" fwait \n"
+" test %eax, %eax \n"
+" je 2f \n"
+" jl 1f \n"
+INTRAISE(SSE_TEST_IRQ)
+" jmp 2f \n"
+"1: sqrtps %xmm0, %xmm0 \n"
+"2: \n"
+" ret \n"
+);
+
+#define SSE_TEST_HP_FAILED 1
+#define SSE_TEST_FSPR_FAILED 2
+#define SSE_TEST_CTXTCMP_FAILED 4
+
+static const char *fail_msgs[] = {
+ "Seems that HP task was not executing",
+ "FPSR 'Invalid-operation' flag should be clear",
+ "Restored context does NOT match the saved one",
+};
+
+static void prstat(int st, const char *where)
+{
+int i,msk;
+ for ( i=0, msk=1; i<sizeof(fail_msgs)/sizeof(fail_msgs[0]); i++, msk<<=1 ) {
+ if ( (st & msk) ) {
+ fprintf(stderr,"sse_test ERROR: %s (testing: %s)\n", fail_msgs[i], where);
+ }
+ }
+}
+
+int sse_test_debug = 0;
+
+static int
+exc_raise(int kind)
+{
+Context_Control_sse nctxt;
+Context_Control_sse octxt;
+Context_Control_sse orig_ctxt;
+int i,j,rval;
+double s2;
+uint16_t fsw;
+__vf f4 = { -1., -2., -3., -4. };
+__vf tmp;
+__v32 sgn = { (1<<31), (1<<31), (1<<31), (1<<31) };
+
+ stor_ctxt(&octxt);
+
+ octxt.fsw &= ~FPSR_ALLE;
+ octxt.mxcsr &= ~MXCSR_ALLE;
+
+ for ( i=0; i<8; i++ ) {
+ fp_st(&octxt, i, (double)i+0.1);
+ for (j=0; j<16; j++) {
+ octxt.xmmregs[i][j]=(i<<4)+j;
+ }
+ }
+
+
+ if ( SSE_EXC == kind ) {
+ memcpy(octxt.xmmregs[0], &f4, sizeof(f4));
+ octxt.mxcsr &= ~MXCSR_IM;
+ }
+
+ /* set tags to 'valid' */
+ octxt.ftw = 0xff;
+
+ /* enable 'invalid arg' exception */
+ octxt.fcw &= ~ ( FPCW_IM );
+
+ if ( FP_EXC == kind ) {
+ octxt.fsw |= ( FPSR_IE | FPSR_ES );
+ }
+
+ if ( sse_test_debug )
+ printk("RAISE (fsw was 0x%04x)\n", orig_ctxt.fsw);
+ asm volatile(
+ " fxsave %2 \n"
+#ifdef __rtems__
+ " movl %4, sse_test_check\n"
+#endif
+ " fxrstor %3 \n"
+ " call do_raise \n"
+#ifdef __rtems__
+ " movl sse_test_check, %1\n"
+#else
+ " movl $0, %1 \n"
+#endif
+#ifdef TEST_MISMATCH
+ " pxor %%xmm0, %%xmm0 \n"
+#endif
+ " fxsave %0 \n"
+ " fxrstor %2 \n"
+ : "=m"(nctxt),"=&r"(rval),"=m"(orig_ctxt)
+ : "m"(octxt), "i"(SSE_TEST_HP_FAILED),"a"(kind)
+ : "xmm0"
+ );
+
+ if ( ( FPSR_IE & nctxt.fsw ) ) {
+ rval |= SSE_TEST_FSPR_FAILED;
+ }
+ if ( FP_EXC == kind )
+ nctxt.fsw |= (FPSR_IE | FPSR_ES);
+ else if ( SSE_EXC == kind ) {
+ tmp = __builtin_ia32_sqrtps( (__vf)(~sgn & (__v32)f4) );
+ /* sqrt raises PE; just clear it */
+ nctxt.mxcsr &= ~MXCSR_PE;
+ memcpy( octxt.xmmregs[0], &tmp, sizeof(tmp) );
+ }
+
+ if ( cmp_ctxt(&nctxt, &octxt, 0) ) {
+ rval |= SSE_TEST_CTXTCMP_FAILED;
+ }
+
+ s2 = sqrt(2.0);
+
+ asm volatile("fstsw %0":"=m"(fsw));
+
+ if ( sse_test_debug )
+ printf("sqrt(2): %f (FSTW: 0x%02"PRIx16")\n", sqrt(2.0), fsw);
+
+ return rval;
+}
+
+#ifdef __rtems__
+static void
+sse_test_ehdl(CPU_Exception_frame *p_f);
+
+rtems_id sse_test_sync = 0;
+cpuExcHandlerType sse_test_ohdl = 0;
+
+CPU_Exception_frame *sse_test_frame = 0;
+volatile int sse_test_check = SSE_TEST_HP_FAILED;
+unsigned sse_tests = 0;
+
+rtems_task
+sse_test_hp_task(rtems_task_argument arg)
+{
+rtems_id sync = (rtems_id)arg;
+
+uint16_t fp_cw;
+uint32_t mxcsr;
+rtems_status_code sc;
+const char * msgs[] = {"FPU_EXC", "SSE_EXC", "IRQ_EXC"};
+int i;
+
+ /* verify that FPU control word is default value */
+ asm volatile("fstcw %0":"=m"(fp_cw));
+ if ( fp_cw != _CPU_Null_fp_context.fpucw ) {
+ fprintf(
+ stderr,
+ "ERROR: FPU CW initialization mismatch: got 0x%04"PRIx16"; expected 0x%04"PRIx16"\n",
+ fp_cw,
+ _CPU_Null_fp_context.fpucw
+ );
+ }
+
+ /* check MXCSR default value */
+ asm volatile("stmxcsr %0":"=m"(mxcsr));
+ if ( mxcsr != _CPU_Null_fp_context.mxcsr ) {
+ fprintf(
+ stderr,
+ "ERROR: MXCSR initialization mismatch: got 0x%08"PRIx32"; expected 0x%08"PRIx32"\n",
+ mxcsr,
+ _CPU_Null_fp_context.mxcsr
+ );
+ }
+
+
+ for (i=0; i<sizeof(msgs)/sizeof(msgs[0]); i++ ) {
+ if ( ( sse_tests & (1<<i) ) ) {
+ if ( sse_test_debug )
+ printk("HP task will now block for %s\n",msgs[i]);
+
+ /* Blocking here lets the low-priority task continue */
+ sc = rtems_semaphore_obtain(sync, RTEMS_WAIT, 500);
+
+ all_clobber(0xaffeaffe, 0xcafecafe);
+
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc,"ERROR: sse_test hp task wasn't notified of exception\n");
+ goto bail;
+ }
+
+ /* set flag indicating that we executed until here */
+ sse_test_check = 0;
+ }
+ }
+
+bail:
+ rtems_task_suspend(RTEMS_SELF);
+}
+
+/* Flags to skip individual tests */
+#define SSE_TEST_FPU_EXC (1<<0)
+#define SSE_TEST_SSE_EXC (1<<1)
+#define SSE_TEST_IRQ_EXC (1<<2)
+
+#define SSE_TEST_ALL 7
+
+/* If this flag is given the executing task is not deleted
+ * when the test finishes. This is useful if you want to
+ * execute from a shell or similar.
+ */
+#define SSE_TEST_NO_DEL (1<<0)
+
+/* Task arg is bitmask of these flags */
+rtems_task
+sse_test_lp_task(rtems_task_argument arg)
+{
+rtems_id hp_task = 0;
+rtems_status_code sc;
+rtems_task_priority pri;
+uint16_t fp_cw,fp_cw_set;
+uint32_t mxcsr, mxcsr_set;
+rtems_irq_connect_data irqd;
+int flags = (int)arg;
+int st;
+int errs = 0;
+
+ sse_tests = SSE_TEST_ALL & ~(flags>>1);
+
+ sse_test_ohdl = 0;
+
+ fp_cw_set = _CPU_Null_fp_context.fpucw | FPCW_RC(3) ;
+ mxcsr_set = _CPU_Null_fp_context.mxcsr | MXCSR_RC(3) ;
+ asm volatile("ldmxcsr %0"::"m"(mxcsr_set));
+ asm volatile("fldcw %0"::"m"(fp_cw_set));
+
+ sc = rtems_semaphore_create(
+ rtems_build_name('s','s','e','S'),
+ 0,
+ RTEMS_SIMPLE_BINARY_SEMAPHORE,
+ 0,
+ &sse_test_sync
+ );
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error(sc, "sse_test ERROR: creation of 'sync' semaphore failed");
+ errs++;
+ goto bail;
+ }
+
+ rtems_task_set_priority( RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &pri );
+
+ sc = rtems_task_create(
+ rtems_build_name('s','s','e','H'),
+ pri - 2,
+ 20000,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_FLOATING_POINT,
+ &hp_task
+ );
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ hp_task = 0;
+ rtems_error( sc, "sse_test ERROR: creation of high-priority task failed");
+ errs++;
+ goto bail;
+ }
+
+ sc = rtems_task_start( hp_task, sse_test_hp_task, (rtems_task_argument)sse_test_sync );
+ if ( RTEMS_SUCCESSFUL != sc ) {
+ rtems_error( sc, "sse_test ERROR: start of high-priority task failed");
+ goto bail;
+ }
+
+ /* Test if FP/SSE context is saved/restored across an exception */
+ sse_test_ohdl = _currentExcHandler;
+ _currentExcHandler = sse_test_ehdl;
+
+ if ( (sse_tests & SSE_TEST_FPU_EXC) ) {
+ if ( (st = exc_raise(FP_EXC)) ) {
+ prstat(st,"FP_EXC");
+ errs++;
+ }
+
+ /* Test modified FPCW/MXCSR */
+ asm volatile("fstcw %0":"=m"(fp_cw));
+ asm volatile("stmxcsr %0":"=m"(mxcsr));
+ mxcsr &= ~(MXCSR_ALLE);
+ if ( fp_cw != fp_cw_set ) {
+ fprintf(stderr,"sse_test ERROR: FPCW mismatch (after FP_EXC): expected 0x%04"PRIx16", got 0x%04"PRIx16"\n", fp_cw_set, fp_cw);
+ errs++;
+ }
+ if ( mxcsr != mxcsr_set ) {
+ fprintf(stderr,"sse_test ERROR: MXCSR mismatch (after FP_EXC): expected 0x%08"PRIx32", got 0x%08"PRIx32"\n", mxcsr_set, mxcsr);
+ errs++;
+ }
+ }
+
+ if ( (sse_tests & SSE_TEST_SSE_EXC) ) {
+ if ( (st = exc_raise(SSE_EXC)) ) {
+ prstat(st, "SSE_EXC");
+ errs++;
+ }
+
+ /* Test modified FPCW/MXCSR */
+ asm volatile("fstcw %0":"=m"(fp_cw));
+ asm volatile("stmxcsr %0":"=m"(mxcsr));
+ mxcsr &= ~(MXCSR_ALLE);
+ if ( fp_cw != fp_cw_set ) {
+ fprintf(stderr,"sse_test ERROR: FPCW mismatch (after SSE_EXC): expected 0x%04"PRIx16", got 0x%04"PRIx16"\n", fp_cw_set, fp_cw);
+ errs++;
+ }
+ if ( mxcsr != mxcsr_set ) {
+ fprintf(stderr,"sse_test ERROR: MXCSR mismatch (after SSE_EXC): expected 0x%08"PRIx32", got 0x%08"PRIx32"\n", mxcsr_set, mxcsr);
+ errs++;
+ }
+ }
+
+
+ if ( (sse_tests & SSE_TEST_IRQ_EXC) ) {
+ memset( &irqd, 0, sizeof(irqd) );
+ irqd.name = SSE_TEST_IRQ;
+ irqd.hdl = (void*)sse_test_ehdl;
+ irqd.handle = 0;
+
+ if ( ! BSP_install_rtems_irq_handler( &irqd ) ) {
+ fprintf(stderr, "sse_test ERROR: Unable to install ISR\n");
+ errs++;
+ goto bail;
+ }
+
+ /* Test if FP/SSE context is saved/restored across an interrupt */
+ if ( (st = exc_raise(IRQ_EXC)) ) {
+ prstat(st, "IRQ");
+ errs++;
+ }
+
+ if ( ! BSP_remove_rtems_irq_handler( &irqd ) ) {
+ fprintf(stderr, "sse_test ERROR: Unable to uninstall ISR\n");
+ }
+
+ /* Test modified FPCW/MXCSR */
+ asm volatile("fstcw %0":"=m"(fp_cw));
+ asm volatile("stmxcsr %0":"=m"(mxcsr));
+ mxcsr &= ~(MXCSR_ALLE);
+ if ( fp_cw != fp_cw_set ) {
+ fprintf(stderr,"sse_test ERROR: FPCW mismatch (after IRQ): expected 0x%04"PRIx16", got 0x%04"PRIx16"\n", fp_cw_set, fp_cw);
+ errs++;
+ }
+ if ( mxcsr != mxcsr_set ) {
+ fprintf(stderr,"sse_test ERROR: MXCSR mismatch (after IRQ): expected 0x%08"PRIx32", got 0x%08"PRIx32"\n", mxcsr_set, mxcsr);
+ errs++;
+ }
+ }
+
+
+bail:
+ /* Wait for console to calm down... */
+ rtems_task_wake_after(5);
+ fprintf(stderr,"SSE/FPU Test %s (%u errors)\n", errs ? "FAILED":"PASSED", errs);
+ if ( sse_test_ohdl ) {
+ _currentExcHandler = sse_test_ohdl;
+ sse_test_ohdl = 0;
+ }
+ if ( sse_test_sync )
+ rtems_semaphore_delete( sse_test_sync );
+ sse_test_sync = 0;
+ if ( hp_task )
+ rtems_task_delete( hp_task );
+
+ if ( ! (flags & SSE_TEST_NO_DEL) )
+ rtems_task_delete( RTEMS_SELF );
+}
+
+static void
+sse_test_ehdl(CPU_Exception_frame *p_f)
+{
+int i,j,start = 0;
+int mismatch;
+__vf f4;
+
+ if ( p_f ) {
+ printk("Got exception #%u\n", p_f->idtIndex);
+ printk("EIP: 0x%08x, ESP: 0x%08x\n", p_f->eip, p_f->esp0);
+ printk("TID: 0x%08x\n", _Thread_Executing->Object.id);
+
+ if ( ! p_f->fp_ctxt ) {
+ printk("ERROR: NO FP/SSE CONTEXT ATTACHED ??\n");
+ sse_test_ohdl(p_f);
+ }
+ if ( 16 == p_f->idtIndex ) {
+ printk("Resetting FP status (0x%04"PRIx16")\n", p_f->fp_ctxt->fsw);
+ p_f->fp_ctxt->fsw = 0;
+ } else if ( 19 == p_f->idtIndex ) {
+ start = 1;
+ memcpy(&f4, p_f->fp_ctxt->xmmregs[0], sizeof(f4));
+ f4 = -f4;
+ memcpy(p_f->fp_ctxt->xmmregs[0], &f4, sizeof(f4));
+ p_f->fp_ctxt->mxcsr &= ~MXCSR_ALLE;
+ } else {
+ printk("(skipping non-FP exception)\n");
+ sse_test_ohdl(p_f);
+ }
+
+ printk("Checking XMM regs -- ");
+ for ( mismatch=0, i=start; i<8; i++ ) {
+ for ( j=0; j<16; j++ ) {
+ if ( p_f->fp_ctxt->xmmregs[i][j] != ((i<<4) | j) )
+ mismatch++;
+ }
+ }
+ if ( mismatch ) {
+ printk("%u mismatches; dump:\n", mismatch);
+ for ( i=0; i<8; i++ ) {
+ for ( j=0; j<16; j++ ) {
+ printk("0x%02x ", p_f->fp_ctxt->xmmregs[i][j]);
+ }
+ printk("\n");
+ }
+ } else {
+ printk("OK\n");
+ }
+ } else {
+ printk("IRQ %u\n", SSE_TEST_IRQ);
+ }
+ printk("Clobbering FPU/SSE state\n");
+ asm volatile("finit");
+ sse_clobber(0xdeadbeef);
+ printk("Notifying task\n");
+ rtems_semaphore_release( sse_test_sync );
+}
+
+#else
+
+/* Code using signals for testing under linux; unfortunately, 32-bit
+ * linux seems to pass no SSE context info to the sigaction...
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+
+#define MKCASE(X) case FPE_##X: msg="FPE_"#X; break;
+
+#define CLRXMM(i) __asm__ volatile("pxor %%xmm"#i", %%xmm"#i:::"xmm"#i)
+
+static void
+fpe_act(int signum, siginfo_t *p_info, void *arg3)
+{
+ucontext_t *p_ctxt = arg3;
+const char *msg = "FPE_UNKNOWN";
+uint16_t *p_fst;
+
+ if ( SIGFPE != signum ) {
+ fprintf(stderr,"WARNING: fpe_act handles SIGFPE\n");
+ return;
+ }
+ switch ( p_info->si_code ) {
+ default:
+ fprintf(stderr,"WARNING: fpe_act got unkown code %u\n", p_info->si_code);
+ return;
+ MKCASE(INTDIV);
+ MKCASE(INTOVF);
+ MKCASE(FLTDIV);
+ MKCASE(FLTOVF);
+ MKCASE(FLTUND);
+ MKCASE(FLTRES);
+ MKCASE(FLTINV);
+ MKCASE(FLTSUB);
+ }
+ fprintf(stderr,"Got SIGFPE (%s) @%p\n", msg, p_info->si_addr);
+#ifdef __linux__
+ fprintf(stderr,"Resetting FP status 0x%02lx\n", p_ctxt->uc_mcontext.fpregs->sw);
+ p_ctxt->uc_mcontext.fpregs->sw = 0;
+#ifdef TEST_MISMATCH
+ fp_st1((void*)&p_ctxt->uc_mcontext.fpregs->_st[3],2.345);
+#endif
+#endif
+
+ /* Clear FPU; if context is properly saved/restored around exception
+ * then this shouldn't disturb the register contents of the interrupted
+ * task/process.
+ */
+ asm volatile("finit");
+ sse_clobber(0xdeadbeef);
+}
+
+static void
+test(void)
+{
+Context_Control_sse ctxt;
+
+ stor_ctxt(&ctxt);
+ printf("FPCW: 0x%"PRIx16"\nFPSW: 0x%"PRIx16"\n", ctxt.fcw, ctxt.fsw);
+ printf("FTAG: 0x%"PRIx8"\n",ctxt.ftw);
+}
+
+int
+main(int argc, char **argv)
+{
+struct sigaction a1, a2;
+uint32_t mxcsr;
+
+ memset(&a1, 0, sizeof(a1));
+
+ a1.sa_sigaction = fpe_act;
+ a1.sa_flags = SA_SIGINFO;
+
+ if ( sigaction(SIGFPE, &a1, &a2) ) {
+ perror("sigaction");
+ return 1;
+ }
+
+ asm volatile("stmxcsr %0":"=m"(mxcsr));
+ printf("MXCSR: 0x%08"PRIx32"\n", mxcsr);
+
+ test();
+ exc_raise(0);
+ return 0;
+}
+#endif
+
+/* Helpers to access CR4 and MXCSR */
+
+uint32_t
+mfcr4()
+{
+uint32_t rval;
+ asm volatile("mov %%cr4, %0":"=r"(rval));
+ return rval;
+}
+
+void
+mtcr4(uint32_t rval)
+{
+ asm volatile("mov %0, %%cr4"::"r"(rval));
+}
+
+uint32_t
+mfmxcsr()
+{
+uint32_t rval;
+ asm volatile("stmxcsr %0":"=m"(rval));
+ return rval;
+}
+
+void
+mtmxcsr(uint32_t rval)
+{
+ asm volatile("ldmxcsr %0"::"m"(rval));
+}
+
+
+float
+sseraise()
+{
+__vf f4={-2., -2., -2. -2.};
+float f;
+ f4 = __builtin_ia32_sqrtps( f4 );
+ memcpy(&f,&f4,sizeof(f));
+ return f;
+}
diff --git a/cpukit/score/cpu/lm32/.cvsignore b/cpukit/score/cpu/lm32/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/lm32/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/lm32/ChangeLog b/cpukit/score/cpu/lm32/ChangeLog
new file mode 100644
index 0000000000..f814148063
--- /dev/null
+++ b/cpukit/score/cpu/lm32/ChangeLog
@@ -0,0 +1,114 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, irq.c, rtems/score/lm32.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-09-26 Yann Sionneau <yann@minet.net>
+
+ PR 1697/cpukit
+ * rtems/score/cpu.h: lm32 really needs aligned stack. Recent changes
+ highlighted that this macro was incorrect.
+
+2010-08-20 <yann.sionneau@telecom-sudparis.eu>
+
+ * rtems/score/lm32.h: Add lm32_read_interrupts().
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * irq.c: Rename _Context_Switch_necessary to _Thread_Dispatch_necessary
+ to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * irq.c, rtems/score/cpu.h: Add a per cpu data structure which contains
+ the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-05-29 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * irq.c: Change _exception_stack_frame into void*.
+
+2010-04-25 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * rtems/score/cpu.h: Remove warning in _CPU_Context_Initialize.
+
+2010-04-15 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Make _gp global.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S, irq.c: Add include of config.h
+
+2010-03-02 Michael Walle <michael@walle.cc>
+
+ * cpu.c: Provide body for CPU specific Idle thread. This halts on qemu
+ but is just a nop on a real cpu.
+
+2009-05-05 Michael Walle <michael@walle.cc>
+
+ * cpu_asm.S, irq.c, rtems/score/cpu.h: Add lm32 gdb stub support.
+
+2009-04-14 Michael Walle <michael@walle.cc>
+
+ * cpu.h: corrected the registers in Context_Control and
+ in CPU_Interrupt_frame to correspond to the saved frame in cpu_asm.S
+ Also switched on CPU_ISR_PASSES_FRAME_POINTER.
+ * cpu_asm.S: Moved the restore part of _CPU_Context_switch for
+ easier reading. Fixed _CPU_Context_restore, it now moves the
+ argument and branches to a label in _CPU_Context_switch. Removed
+ unnecessary saves of registers in context switch and irq handling.
+ Rewrote irq code to call the C helper. Added some documentation
+ * irq.c: New file derived from c4x and nios2.
+
+2009-04-06 Michael Walle <michael@walle.cc>
+
+ * cpu_asm.S: We cannot use any other register than r0 without saving
+ them to the stack. (_ISR_Handler clears r0 right at the beginning)
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-12-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * .cvsignore: New file.
+
+2008-12-04 Jukka Pietarinen <jukka.pietarinen@mrf.fi>
+
+ * ChangeLog, Makefile.am, cpu.c, cpu_asm.S, preinstall.am, rtems/asm.h,
+ rtems/score/cpu.h, rtems/score/cpu_asm.h, rtems/score/lm32.h,
+ rtems/score/types.h: New files.
+
diff --git a/cpukit/score/cpu/lm32/Makefile.am b/cpukit/score/cpu/lm32/Makefile.am
new file mode 100644
index 0000000000..86af92f057
--- /dev/null
+++ b/cpukit/score/cpu/lm32/Makefile.am
@@ -0,0 +1,19 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/lm32.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S irq.c
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/lm32/cpu.c b/cpukit/score/cpu/lm32/cpu.c
new file mode 100644
index 0000000000..1b90d2f561
--- /dev/null
+++ b/cpukit/score/cpu/lm32/cpu.c
@@ -0,0 +1,174 @@
+/*
+ * Lattice Mico32 (lm32) CPU Dependent Source
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ * Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
+ * Micro-Research Finland Oy
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * LM32 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Initialize(void)
+{
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * LM32 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ /*
+ * This routine returns the current interrupt level.
+ */
+
+ return 0;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * LM32 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * LM32 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * LM32 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ *
+ * LM32 Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+ for( ; ; ) {
+ /* The LM32 softcore itself hasn't any HLT instruction. But the
+ * LM32 qemu target interprets this nop instruction as HLT.
+ */
+ __asm__ volatile("and r0, r0, r0");
+ }
+}
diff --git a/cpukit/score/cpu/lm32/cpu_asm.S b/cpukit/score/cpu/lm32/cpu_asm.S
new file mode 100644
index 0000000000..d361c1ccf4
--- /dev/null
+++ b/cpukit/score/cpu/lm32/cpu_asm.S
@@ -0,0 +1,205 @@
+/*
+ * $Id$
+ *
+ * This file contains all assembly code for the
+ * LM32 implementation of RTEMS.
+ *
+ * Derived from no_cpu/cpu_asm.S, copyright (c) 1989-1999,
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
+ * Micro-Research Finland Oy
+ *
+ * Michael Walle <michael@walle.cc>, 2009
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/cpu_asm.h>
+
+/* void _CPU_Context_switch(run_context, heir_context)
+ *
+ * This routine performs a normal non-FP context switch.
+ *
+ * LM32 Specific Information:
+ *
+ * Saves/restores all callee-saved general purpose registers as well as
+ * the stack pointer, return address and interrupt enable status register
+ * to/from the context.
+ *
+ */
+ .globl _CPU_Context_switch
+_CPU_Context_switch:
+ sw (r1+0), r11 /* r1 is the first argument */
+ sw (r1+4), r12
+ sw (r1+8), r13
+ sw (r1+12), r14
+ sw (r1+16), r15
+ sw (r1+20), r16
+ sw (r1+24), r17
+ sw (r1+28), r18
+ sw (r1+32), r19
+ sw (r1+36), r20
+ sw (r1+40), r21
+ sw (r1+44), r22
+ sw (r1+48), r23
+ sw (r1+52), r24
+ sw (r1+56), r25
+ sw (r1+60), gp
+ sw (r1+64), fp
+ sw (r1+68), sp
+ sw (r1+72), ra
+ rcsr r3, IE
+ sw (r1+76), r3
+ .extern _exception_stack_frame
+ mvhi r3, hi(_exception_stack_frame)
+ ori r3, r3, lo(_exception_stack_frame)
+ lw r4, (r3+0)
+ be r4, r0, 2f
+1:
+ lw r5, (r4+44)
+ sw (r3+0), r0
+ bi 3f
+2:
+ mvhi r5, hi(_Thread_Dispatch)
+ ori r5, r5, lo(_Thread_Dispatch)
+3:
+ sw (r1+80), r5
+
+_CPU_Context_switch_restore:
+ lw r11, (r2+0) /* r2 is the second argument */
+ lw r12, (r2+4)
+ lw r13, (r2+8)
+ lw r14, (r2+12)
+ lw r15, (r2+16)
+ lw r16, (r2+20)
+ lw r17, (r2+24)
+ lw r18, (r2+28)
+ lw r19, (r2+32)
+ lw r20, (r2+36)
+ lw r21, (r2+40)
+ lw r22, (r2+44)
+ lw r23, (r2+48)
+ lw r24, (r2+52)
+ lw r25, (r2+56)
+ lw gp, (r2+60)
+ lw fp, (r2+64)
+ lw sp, (r2+68)
+ lw ra, (r2+72)
+ lw r3, (r2+76)
+ wcsr IE, r3
+ ret
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * LM32 Specific Information:
+ *
+ * Moves argument #1 to #2 and branches to the restore part of the
+ * context switch code above.
+ */
+ .globl _CPU_Context_restore
+_CPU_Context_restore:
+ mv r2, r1
+ bi _CPU_Context_switch_restore
+
+/* void _ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * LM32 Specific Information:
+ *
+ * Saves all the caller-saved general purpose registers as well as the
+ * return address, exception return address and breakpoint return address
+ * (the latter may be unnecessary) onto the stack, which is either the task
+ * stack (in case of a interrupted task) or the interrupt stack (if an
+ * interrupt was interrupted).
+ * After that, it figures out the pending interrupt with the highest
+ * priority and calls the main ISR handler written in C, which in turn
+ * handles interrupt nesting, software interrupt stack setup etc and
+ * finally calls the user ISR.
+ * At the end the saved registers are restored.
+ *
+ */
+
+ .globl _ISR_Handler
+_ISR_Handler:
+ xor r0, r0, r0
+ addi sp, sp, -52
+ sw (sp+4), r1
+ sw (sp+8), r2
+ sw (sp+12), r3
+ sw (sp+16), r4
+ sw (sp+20), r5
+ sw (sp+24), r6
+ sw (sp+28), r7
+ sw (sp+32), r8
+ sw (sp+36), r9
+ sw (sp+40), r10
+ sw (sp+44), ra
+ sw (sp+48), ea
+ sw (sp+52), ba
+
+ /*
+ * Scan through IP & IM bits starting from LSB until irq vector is
+ * found. The vector is stored in r1, which is the first argument for
+ * __ISR_Handler.
+ */
+ rcsr r2, IP
+ rcsr r3, IM
+ mv r1, r0 /* r1: counter for the vector number */
+ and r2, r2, r3 /* r2: pending irqs, which are enabled */
+ mvi r3, 1 /* r3: register for the walking 1 */
+ /*
+ * If r2 is zero, there was no interrupt.
+ * This should never happen!
+ */
+ be r2, r0, exit_isr
+find_irq:
+ and r4, r2, r3
+ bne r4, r0, found_irq
+ sli r3, r3, 1
+ addi r1, r1, 1
+ bi find_irq
+
+found_irq:
+ /*
+ * Call __ISR_Handler for further processing.
+ * r1 is the vector number, calculated above
+ * r2 is the pointer to the CPU_Interrupt_frame
+ */
+ addi r2, sp, 4
+
+ .extern __ISR_Handler
+ mvhi r3, hi(__ISR_Handler)
+ ori r3, r3, lo(__ISR_Handler)
+ call r3
+
+exit_isr:
+ /* Restore the saved registers */
+ lw r1, (sp+4)
+ lw r2, (sp+8)
+ lw r3, (sp+12)
+ lw r4, (sp+16)
+ lw r5, (sp+20)
+ lw r6, (sp+24)
+ lw r7, (sp+28)
+ lw r8, (sp+32)
+ lw r9, (sp+36)
+ lw r10, (sp+40)
+ lw ra, (sp+44)
+ lw ea, (sp+48)
+ lw ba, (sp+52)
+ addi sp, sp, 52
+ eret
+
diff --git a/cpukit/score/cpu/lm32/irq.c b/cpukit/score/cpu/lm32/irq.c
new file mode 100644
index 0000000000..a6fe8fd18b
--- /dev/null
+++ b/cpukit/score/cpu/lm32/irq.c
@@ -0,0 +1,93 @@
+/*
+ * lm32 interrupt handler
+ *
+ * Derived from c4x/irq.c and nios2/irq.c
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/percpu.h>
+
+/*
+ * This routine provides the RTEMS interrupt management.
+ *
+ * Upon entry, interrupts are disabled
+ */
+
+#if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ unsigned long *_old_stack_ptr;
+#endif
+
+void *_exception_stack_frame;
+
+register unsigned long *stack_ptr __asm__ ("sp");
+
+void __ISR_Handler(uint32_t vector, CPU_Interrupt_frame *ifr)
+{
+ register uint32_t level;
+ _exception_stack_frame = NULL;
+
+ /* Interrupts are disabled upon entry to this Handler */
+
+ _Thread_Dispatch_disable_level++;
+
+#if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ if ( _ISR_Nest_level == 0 ) {
+ /* Install irq stack */
+ _old_stack_ptr = stack_ptr;
+ stack_ptr = _CPU_Interrupt_stack_high - 4;
+ }
+#endif
+
+ _ISR_Nest_level++;
+
+ if ( _ISR_Vector_table[ vector] )
+ {
+ (*_ISR_Vector_table[ vector ])(vector, ifr);
+ };
+
+ /* Make sure that interrupts are disabled again */
+ _CPU_ISR_Disable( level );
+
+ _ISR_Nest_level--;
+
+#if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ if( _ISR_Nest_level == 0)
+ stack_ptr = _old_stack_ptr;
+#endif
+
+ _Thread_Dispatch_disable_level--;
+
+ _CPU_ISR_Enable( level );
+
+ if ( _ISR_Nest_level )
+ return;
+
+ if ( _Thread_Dispatch_necessary ) {
+
+ /* save off our stack frame so the context switcher can get to it */
+ _exception_stack_frame = ifr;
+
+ _Thread_Dispatch();
+
+ /* and make sure its clear in case we didn't dispatch. if we did, its
+ * already cleared */
+ _exception_stack_frame = NULL;
+ }
+}
+
diff --git a/cpukit/score/cpu/lm32/preinstall.am b/cpukit/score/cpu/lm32/preinstall.am
new file mode 100644
index 0000000000..4ea74cd42e
--- /dev/null
+++ b/cpukit/score/cpu/lm32/preinstall.am
@@ -0,0 +1,45 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/lm32.h: rtems/score/lm32.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/lm32.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/lm32.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/lm32/rtems/asm.h b/cpukit/score/cpu/lm32/rtems/asm.h
new file mode 100644
index 0000000000..9585ba7b03
--- /dev/null
+++ b/cpukit/score/cpu/lm32/rtems/asm.h
@@ -0,0 +1,125 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/lm32.h>
+
+#ifndef __USER_LABEL_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all C program symbols.
+ */
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all register names.
+ */
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/** Use the right prefix for global labels. */
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/** Use the right prefix for registers. */
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+/** This macro is used to denote the beginning of a code declaration. */
+#define BEGIN_CODE_DCL .text
+/** This macro is used to denote the end of a code declaration. */
+#define END_CODE_DCL
+/** This macro is used to denote the beginning of a data declaration section. */
+#define BEGIN_DATA_DCL .data
+/** This macro is used to denote the end of a data declaration section. */
+#define END_DATA_DCL
+/** This macro is used to denote the beginning of a code section. */
+#define BEGIN_CODE .text
+/** This macro is used to denote the end of a code section. */
+#define END_CODE
+/** This macro is used to denote the beginning of a data section. */
+#define BEGIN_DATA
+/** This macro is used to denote the end of a data section. */
+#define END_DATA
+/** This macro is used to denote the beginning of the
+ * unitialized data section.
+ */
+#define BEGIN_BSS
+/** This macro is used to denote the end of the unitialized data section. */
+#define END_BSS
+/** This macro is used to denote the end of the assembly file. */
+#define END
+
+/**
+ * This macro is used to declare a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define PUBLIC(sym) .globl SYM (sym)
+
+/**
+ * This macro is used to prototype a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/lm32/rtems/score/cpu.h b/cpukit/score/cpu/lm32/rtems/score/cpu.h
new file mode 100644
index 0000000000..26a47f1266
--- /dev/null
+++ b/cpukit/score/cpu/lm32/rtems/score/cpu.h
@@ -0,0 +1,1266 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the XXX
+ * processor.
+ *
+ * @note This file is part of a porting template that is intended
+ * to be used as the starting point when porting RTEMS to a new
+ * CPU family. The following needs to be done when using this as
+ * the starting point for a new port:
+ *
+ * + Anywhere there is an XXX, it should be replaced
+ * with information about the CPU family being ported to.
+ *
+ * + At the end of each comment section, there is a heading which
+ * says "Port Specific Information:". When porting to RTEMS,
+ * add CPU family specific information in this section
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/lm32.h>
+
+/* conditional compilation parameters */
+
+/**
+ * Should the calls to @ref _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * This conditional is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ *
+ * @note In general, the @ref _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls @ref _Thread_Enable_dispatch which in turns calls
+ * @ref _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/**
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/**
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/**
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/**
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ISR_PASSES_FRAME_POINTER 1
+
+/**
+ * @def CPU_HARDWARE_FP
+ *
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+/**
+ * @def CPU_SOFTWARE_FP
+ *
+ * Does the CPU have no hardware floating point and GCC provides a
+ * software floating point implementation which must be context
+ * switched?
+ *
+ * This feature conditional is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HARDWARE_FP FALSE
+#define CPU_SOFTWARE_FP FALSE
+
+/**
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/**
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/**
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/**
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine @ref _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * @ref _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * -# BSP provided
+ * -# CPU dependent (if provided)
+ * -# generic (if no BSP and no CPU dependent)
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/**
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_GROWS_UP FALSE
+
+/**
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * @note Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (8)))
+
+/**
+ * @defgroup CPUEndian Processor Dependent Endianness Support
+ *
+ * This group assists in issues related to processor endianness.
+ */
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_LITTLE_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_BIG_ENDIAN TRUE
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_BIG_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_LITTLE_ENDIAN FALSE
+
+/**
+ * @ingroup CPUInterrupt
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+/**
+ * @defgroup CPUContext Processor Dependent Context Management
+ *
+ * From the highest level viewpoint, there are 2 types of context to save.
+ *
+ * -# Interrupt registers to save
+ * -# Task level registers to save
+ *
+ * Since RTEMS handles integer and floating point contexts separately, this
+ * means we have the following 3 context items:
+ *
+ * -# task level context stuff:: Context_Control
+ * -# floating point task stuff:: Context_Control_fp
+ * -# special interrupt level context :: CPU_Interrupt_frame
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the minimal set of integer and processor state registers
+ * that must be saved during a voluntary context switch from one thread
+ * to another.
+ */
+typedef struct {
+ uint32_t r11;
+ uint32_t r12;
+ uint32_t r13;
+ uint32_t r14;
+ uint32_t r15;
+ uint32_t r16;
+ uint32_t r17;
+ uint32_t r18;
+ uint32_t r19;
+ uint32_t r20;
+ uint32_t r21;
+ uint32_t r22;
+ uint32_t r23;
+ uint32_t r24;
+ uint32_t r25;
+ uint32_t gp;
+ uint32_t fp;
+ uint32_t sp;
+ uint32_t ra;
+ uint32_t ie;
+ uint32_t epc;
+} Context_Control;
+
+/**
+ * @ingroup CPUContext Management
+ *
+ * This macro returns the stack pointer associated with @a _context.
+ *
+ * @param[in] _context is the thread context area to access
+ *
+ * @return This method returns the stack pointer.
+ */
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->sp
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the complete set of floating point registers that must
+ * be saved during any context switch from one thread to another.
+ */
+typedef struct {
+} Context_Control_fp;
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that must
+ * be saved during an interrupt. This set does not include any which are
+ * in @ref Context_Control.
+ */
+typedef struct {
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t ra;
+ uint32_t ba;
+ uint32_t ea;
+} CPU_Interrupt_frame;
+
+/**
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * @ref _CPU_Initialize and copied into the task's FP context area during
+ * @ref _CPU_Context_Initialize.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if 0
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+#endif
+
+/**
+ * @defgroup CPUInterrupt Processor Dependent Interrupt Management
+ *
+ * On some CPUs, RTEMS supports a software managed interrupt stack.
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in @ref _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use.
+ *
+ * @note These two variables are required if the macro
+ * @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/**
+ * @ingroup CPUContext
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/**
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the number of entries in the @ref _ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the highest interrupt vector number for this port.
+ */
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/**
+ * @ingroup CPUInterrupt
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable @a _ISR_Nest_level.
+ */
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/**
+ * @ingroup CPUContext
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_MINIMUM_SIZE (1024*4)
+
+/**
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALIGNMENT 8
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by @ref CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for
+ * the heap, then this should be set to @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * @ref CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is
+ * strict enough for the partition, then this should be set to
+ * @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2. It does have to
+ * be greater or equal to than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by @ref CPU_ALIGNMENT. If the
+ * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
+ * set to 0.
+ *
+ * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_ALIGNMENT 4
+
+/*
+ * ISR handler macros
+ */
+
+/**
+ * @ingroup CPUInterrupt
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Initialize_vectors()
+
+/**
+ * @ingroup CPUInterrupt
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in @a _isr_cookie.
+ *
+ * @param[out] _isr_cookie will contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ lm32_disable_interrupts( _isr_cookie );
+
+/**
+ * @ingroup CPUInterrupt
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * @a _isr_cookie is not modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ lm32_enable_interrupts( _isr_cookie );
+
+/**
+ * @ingroup CPUInterrupt
+ * This temporarily restores the interrupt to @a _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter @a _isr_cookie is not
+ * modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ lm32_flash_interrupts( _isr_cookie );
+
+/**
+ * @ingroup CPUInterrupt
+ *
+ * This routine and @ref _CPU_ISR_Get_level
+ * Map the interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Set_level( new_level ) \
+ { \
+ _CPU_ISR_Enable( ( new_level==0 ) ? 1 : 0 ); \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * Return the current interrupt disable level for this task in
+ * the format used by the interrupt level portion of the task mode.
+ *
+ * @note This routine usually must be implemented as a subroutine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/**
+ * @ingroup CPUContext
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * @param[in] _the_context is the context structure to be initialized
+ * @param[in] _stack_base is the lowest physical address of this task's stack
+ * @param[in] _size is the size of this task's stack
+ * @param[in] _isr is the interrupt disable level
+ * @param[in] _entry_point is the thread's entry point. This is
+ * always @a _Thread_Handler
+ * @param[in] _is_fp is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+extern char _gp[];
+
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ do { \
+ uint32_t _stack = (uint32_t)(_stack_base) + (_size) - 4; \
+ (_the_context)->gp = (uint32_t)_gp; \
+ (_the_context)->fp = (uint32_t)_stack; \
+ (_the_context)->sp = (uint32_t)_stack; \
+ (_the_context)->ra = (uint32_t)(_entry_point); \
+ } while ( 0 )
+
+/**
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. For many ports, simply adding a label to the restore path
+ * of @ref _CPU_Context_switch will work. On other ports, it may be
+ * possibly to load a few arguments and jump to the restore path. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/**
+ * @ingroup CPUContext
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * @param[in] _base is the lowest physical address of the floating point
+ * context area
+ * @param[in] _offset is the offset into the floating point area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Fp_start( _base, _offset )
+#if 0
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+#endif
+
+/**
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * @a _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other floating point context save/restore models include:
+ * -# not doing anything, and
+ * -# putting a "null FP status word" in the correct place in the FP context.
+ *
+ * @param[in] _destination is the floating point context area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize_fp( _destination )
+#if 0
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+#endif
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/**
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/**
+ * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
+ *
+ * This set of routines are used to implement fast searches for
+ * the most important ready task.
+ */
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the generic bitfield
+ * manipulation implementation.
+ */
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the data tables provided
+ * by the generic bitfield manipulation implementation.
+ * This can occur when actually using the generic bitfield manipulation
+ * implementation or when implementing the same algorithm in assembly
+ * language for improved performance. It is unlikely that a port will use
+ * the data if it has a bitfield scan instruction.
+ */
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This routine sets @a _output to the bit number of the first bit
+ * set in @a _value. @a _value is of CPU dependent type
+ * @a Priority_bit_map_Control. This type may be either 16 or 32 bits
+ * wide although only the 16 least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * -# What happens when run on a value of zero?
+ * -# Bits may be numbered from MSB to LSB or vice-versa.
+ * -# The numbering may be zero or one based.
+ * -# The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
+ * @ref _CPU_Priority_bits_index. These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by @ref _CPU_Priority_Mask.
+ * The basic major and minor values calculated by @ref _Priority_Major
+ * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for @ref _Priority_Get_highest to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+@verbatim
+ - a series of 16 bit test instructions
+ - a "binary search using if's"
+ - _number = 0
+ if _value > 0x00ff
+ _value >>=8
+ _number = 8;
+
+ if _value > 0x0000f
+ _value >=8
+ _number += 4
+
+ _number += bit_set_table[ _value ]
+@endverbatim
+
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * @param[in] _value is the value to be scanned
+ * @param[in] _output is the first bit set
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+#endif
+
+/* end of Bitfield handler macros */
+
+/**
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by @ref _CPU_Bitfield_Find_first_bit. See the discussion
+ * for that routine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/**
+ * @ingroup CPUBitfield
+ * This routine translates the bit numbers returned by
+ * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * @param[in] _priority is the major or minor number to translate
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/**
+ * This routine performs CPU dependent initialization.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the raw ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs an interrupt vector.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the RTEMS ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * @note It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Install_interrupt_stack( void );
+
+/**
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * @note It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/**
+ * @ingroup CPUContext
+ * This routine switches from the run context to the heir context.
+ *
+ * @param[in] run points to the context of the currently executing task
+ * @param[in] heir points to the context of the heir task
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in @ref _CPU_Context_switch.
+ *
+ * @param[in] new_context points to the context to be restored.
+ *
+ * @note May be unnecessary to reload some registers.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/**
+ * @ingroup CPUContext
+ * This routine saves the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_restore_fp to restore this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine restores the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area to restore
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_save_fp to save this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUEndian
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return swapped;
+}
+
+/**
+ * @ingroup CPUEndian
+ * This routine swaps a 16 bir quantity.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ */
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/lm32/rtems/score/cpu_asm.h b/cpukit/score/cpu/lm32/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..0cfec072c1
--- /dev/null
+++ b/cpukit/score/cpu/lm32/rtems/score/cpu_asm.h
@@ -0,0 +1,74 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Very loose template for an include file for the cpu_asm.? file
+ * if it is implemented as a ".S" file (preprocessed by cpp) instead
+ * of a ".s" file (preprocessed by gm4 or gasp).
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+/* pull in the generated offsets */
+
+/*
+#include <rtems/score/offsets.h>
+*/
+
+/*
+ * Hardware General Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Control Registers
+ */
+
+/* put something here */
+
+/*
+ * Calling Convention
+ */
+
+/* put something here */
+
+/*
+ * Temporary registers
+ */
+
+/* put something here */
+
+/*
+ * Floating Point Registers - SW Conventions
+ */
+
+/* put something here */
+
+/*
+ * Temporary floating point registers
+ */
+
+/* put something here */
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/lm32/rtems/score/lm32.h b/cpukit/score/cpu/lm32/rtems/score/lm32.h
new file mode 100644
index 0000000000..328e6dff59
--- /dev/null
+++ b/cpukit/score/cpu/lm32/rtems/score/lm32.h
@@ -0,0 +1,111 @@
+/* lm32.h
+ *
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specified to the NO CPU port.
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ * Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
+ * Micro-Research Finland Oy
+ */
+
+#ifndef _RTEMS_SCORE_LM32_H
+#define _RTEMS_SCORE_LM32_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the NO CPU family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+#if defined(rtems_multilib)
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+
+#define CPU_MODEL_NAME "rtems_multilib"
+#define LM32_HAS_FPU 0
+
+#elif defined(__lm32__)
+
+#define CPU_MODEL_NAME "lm32"
+#define LM32_HAS_FPU 0
+
+#else
+
+#error "Unsupported CPU Model"
+
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "LM32"
+
+#ifdef __cplusplus
+}
+#endif
+
+#define lm32_read_interrupts( _ip) \
+ __asm__ volatile ("rcsr %0, ip":"=r"(_ip));
+
+#define lm32_disable_interrupts( _level ) \
+ do { register uint32_t ie; \
+ __asm__ volatile ("rcsr %0,ie":"=r"(ie)); \
+ _level = ie; \
+ ie &= (~0x0001); \
+ __asm__ volatile ("wcsr ie,%0"::"r"(ie)); \
+ } while (0)
+
+#define lm32_enable_interrupts( _level ) \
+ __asm__ volatile ("wcsr ie,%0"::"r"(_level));
+
+#define lm32_flash_interrupts( _level ) \
+ do { register uint32_t ie; \
+ __asm__ volatile ("wcsr ie,%0"::"r"(_level)); \
+ ie = _level & (~0x0001); \
+ __asm__ volatile ("wcsr ie,%0"::"r"(ie)); \
+ } while (0)
+
+#define lm32_interrupt_unmask( _mask ) \
+ do { register uint32_t im; \
+ __asm__ volatile ("rcsr %0,im":"=r"(im)); \
+ im |= _mask; \
+ __asm__ volatile ("wcsr im,%0"::"r"(im)); \
+ } while (0)
+
+#define lm32_interrupt_mask( _mask ) \
+ do { register uint32_t im; \
+ __asm__ volatile ("rcsr %0,im":"=r"(im)); \
+ im &= ~_mask; \
+ __asm__ volatile ("wcsr im,%0"::"r"(im)); \
+ } while (0)
+
+#define lm32_interrupt_ack( _mask ) \
+ do { register uint32_t ip = _mask; \
+ __asm__ volatile ("wcsr ip,%0"::"r"(ip)); \
+ } while (0)
+
+#endif /* _RTEMS_SCORE_LM32_H */
diff --git a/cpukit/score/cpu/lm32/rtems/score/types.h b/cpukit/score/cpu/lm32/rtems/score/types.h
new file mode 100644
index 0000000000..a46dd75220
--- /dev/null
+++ b/cpukit/score/cpu/lm32/rtems/score/types.h
@@ -0,0 +1,52 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the
+ * Lattice lm32 processor family.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ * Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
+ * Micro-Research Finland Oy
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+/** This defines the type for a priority bit map entry. */
+typedef uint16_t Priority_bit_map_Control;
+
+/** This defines the return type for an ISR entry point. */
+typedef void lm32_isr;
+
+/** This defines the prototype for an ISR entry point. */
+typedef lm32_isr ( *lm32_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/m32c/.cvsignore b/cpukit/score/cpu/m32c/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/m32c/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/m32c/ChangeLog b/cpukit/score/cpu/m32c/ChangeLog
new file mode 100644
index 0000000000..1c53c04640
--- /dev/null
+++ b/cpukit/score/cpu/m32c/ChangeLog
@@ -0,0 +1,98 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * context_init.c, cpu.c, varvects.h, rtems/score/cpu.h,
+ rtems/score/m32c.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * cpu_asm.c: Rename _Context_Switch_necessary to
+ _Thread_Dispatch_necessary to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.c, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-05-10 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * context_init.c, context_switch.S, cpu.c: Now builds multilib. R8C
+ paths produce warnings for now.
+
+2010-04-25 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * context_init.c: Eliminate warnings.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * context_init.c, context_switch.S, cpu.c, cpu_asm.c, varvects.S: Add
+ include of config.h
+
+2009-09-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Make heap alignment 4 which is greater than
+ CPU_ALIGNMENT but minimum for heap.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Use a 16 bit object id on this target.
+
+2009-01-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * varvects.h: Fix prototype.
+
+2008-10-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * context_init.c, context_switch.S, cpu.c, cpu_asm.c: Correct file
+ headers.
+
+2008-10-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * context_switch.S, cpu_asm.c, rtems/score/cpu.h: Add support for
+ restarting the currently executing thread. Fine tune alignment factor
+ as two-byte aligned and use this for critical structures.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * .cvsignore, ChangeLog, Makefile.am, context_init.c, context_switch.S,
+ cpu.c, cpu_asm.c, preinstall.am, varvects.S, varvects.h, rtems/asm.h,
+ rtems/score/cpu.h, rtems/score/cpu_asm.h, rtems/score/m32c.h,
+ rtems/score/types.h: New files.
+
diff --git a/cpukit/score/cpu/m32c/Makefile.am b/cpukit/score/cpu/m32c/Makefile.am
new file mode 100644
index 0000000000..45be3a490b
--- /dev/null
+++ b/cpukit/score/cpu/m32c/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_HEADERS = varvects.h
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/m32c.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.c context_switch.S context_init.c \
+ varvects.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/m32c/context_init.c b/cpukit/score/cpu/m32c/context_init.c
new file mode 100644
index 0000000000..e79fb0e9c9
--- /dev/null
+++ b/cpukit/score/cpu/m32c/context_init.c
@@ -0,0 +1,81 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <rtems/system.h>
+
+typedef struct {
+ uint16_t sbLow;
+ uint16_t sbHigh; /* push/pop sb */
+ uint16_t flg; /* push/pop flg */
+ uint32_t a1; /* pushm */
+ uint32_t a0;
+ uint32_t r0r2;
+ uint32_t r1r3;
+ uint16_t frameLow; /* exitd */
+ uint16_t frameHigh;
+ uint16_t startLow;
+ uint16_t startHigh;
+ uint16_t zero;
+} Starting_Frame;
+
+#if defined(__r8c_cpu__)
+ #warning "_get_sb: not implemented on R8C"
+ #define _get_sb( _sb )
+#else
+ #define _get_sb( _sb ) \
+ __asm__ volatile( "stc sb, %0" : "=r" (_sb))
+#endif
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ size_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ void *stackEnd = stack_base;
+ register uint32_t sb;
+ Starting_Frame *frame;
+
+ _get_sb( sb );
+ stackEnd += size;
+
+ frame = (Starting_Frame *)stackEnd;
+ frame--;
+
+ frame->zero = 0;
+ frame->sbLow = ((uint32_t)sb) & 0xffff;
+ frame->sbHigh = ((uint32_t)sb >> 16) & 0xffff;
+ frame->flg = 0x80; /* User stack */
+ if ( !new_level ) /* interrupt level 0 --> enabled */
+ frame->flg |= 0x40;
+ frame->a0 = 0x01020304;
+ frame->a1 =0xa1a2a3a4;
+ frame->r0r2 = 0;
+ frame->r1r3 = 0;
+#if defined(__r8c_cpu__)
+ #warning "not implemented on R8C"
+#else
+ frame->frameLow = (uint16_t) (((uint32_t)frame) & 0xffff);
+ frame->frameHigh = (uint16_t) (((uint32_t)frame >> 16) & 0xffff);
+ frame->startLow = (uint16_t) (((uint32_t)entry_point) & 0xffff);
+ frame->startHigh = (uint16_t) (((uint32_t)entry_point >> 16) & 0xffff);
+#endif
+ the_context->sp = (uintptr_t)frame;
+ the_context->fb = (uintptr_t)&frame->frameLow;
+}
diff --git a/cpukit/score/cpu/m32c/context_switch.S b/cpukit/score/cpu/m32c/context_switch.S
new file mode 100644
index 0000000000..e3bb695555
--- /dev/null
+++ b/cpukit/score/cpu/m32c/context_switch.S
@@ -0,0 +1,68 @@
+/*
+ * Context switch for the Reneas M32C
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define ARG_EXECUTING 8
+#define ARG_HEIR 12
+
+#define CTXT_SP 0
+#define CTXT_FB 4
+
+ .file "context_switch.S"
+ .text
+ .global __CPU_Context_switch
+ .type __CPU_Context_switch, @function
+__CPU_Context_switch:
+ enter #0
+ pushm a0,a1,r0,r1,r2,r3
+ pushc flg
+ pushc sb
+
+#if defined(__r8c_cpu__)
+ #warning "not implemented on R8C"
+#else
+ mov.l ARG_EXECUTING[fb],a0 ; a0 = executing
+ stc fb,a1
+ mov.l a1,CTXT_FB[a0] ; save fb
+ stc sp,a1
+ mov.l a1,CTXT_SP[a0] ; save sp
+
+ mov.l ARG_HEIR[fb],a0 ; a0 = heir
+
+restore:
+ mov.l CTXT_SP[a0],a1
+ ldc a1,sp ; restore sp
+ mov.l CTXT_FB[a0],a1
+ ldc a1,fb ; restore fb
+#endif
+ popc sb
+ popc flg
+ popm a0,a1,r0,r1,r2,r3
+ exitd
+ .size __CPU_Context_switch, .-__CPU_Context_switch
+
+#define ARG_RESTART 8
+
+ .global __CPU_Context_Restart_self
+ .type __CPU_Context_Restart_self, @function
+__CPU_Context_Restart_self:
+ enter #0
+#if defined(__r8c_cpu__)
+ #warning "__CPU_Context_Restart_self: not implemented on R8C"
+#else
+ mov.l ARG_RESTART[fb],a0 ; a0 = heir
+ jmp.s restore
+#endif
diff --git a/cpukit/score/cpu/m32c/cpu.c b/cpukit/score/cpu/m32c/cpu.c
new file mode 100644
index 0000000000..b5cb491a4b
--- /dev/null
+++ b/cpukit/score/cpu/m32c/cpu.c
@@ -0,0 +1,165 @@
+/*
+ * XXX CPU Dependent Source
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <varvects.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Initialize(void)
+{
+ #if !defined(__r8c_cpu__)
+ __asm__ volatile( "ldc #__var_vects,intb" );
+ #endif
+}
+
+/*
+ * This routine returns the current interrupt level.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ int flag;
+ m32c_get_flg( flag );
+
+ return ((flag & 0x40) ? 0 : 1);
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+#if defined(__r8c_cpu__)
+ #warning "_CPU_ISR_install_raw_handler not implemented on R8C"
+#else
+ _set_var_vect(new_handler,vector);
+#endif
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+
+ for( ; ; )
+ /* insert your "halt" instruction here */ ;
+}
diff --git a/cpukit/score/cpu/m32c/cpu_asm.c b/cpukit/score/cpu/m32c/cpu_asm.c
new file mode 100644
index 0000000000..81130dadb2
--- /dev/null
+++ b/cpukit/score/cpu/m32c/cpu_asm.c
@@ -0,0 +1,105 @@
+/* cpu_asm.c ===> cpu_asm.S or cpu_asm.s
+ *
+ * This file contains the basic algorithms for all assembly code used
+ * in an specific CPU port of RTEMS. These algorithms must be implemented
+ * in assembly language
+ *
+ * NOTE: This is supposed to be a .S or .s file NOT a C file.
+ *
+ * M32C does not yet have interrupt support. When this functionality
+ * is written, this file should become obsolete.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * This is supposed to be an assembly file. This means that system.h
+ * and cpu.h should not be included in a "real" cpu_asm file. An
+ * implementation in assembly should include "cpu_asm.h>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+
+/* void __ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _ISR_Handler(void)
+{
+ /*
+ * This discussion ignores a lot of the ugly details in a real
+ * implementation such as saving enough registers/state to be
+ * able to do something real. Keep in mind that the goal is
+ * to invoke a user's ISR handler which is written in C and
+ * uses a certain set of registers.
+ *
+ * Also note that the exact order is to a large extent flexible.
+ * Hardware will dictate a sequence for a certain subset of
+ * _ISR_Handler while requirements for setting
+ */
+
+ /*
+ * At entry to "common" _ISR_Handler, the vector number must be
+ * available. On some CPUs the hardware puts either the vector
+ * number or the offset into the vector table for this ISR in a
+ * known place. If the hardware does not give us this information,
+ * then the assembly portion of RTEMS for this port will contain
+ * a set of distinct interrupt entry points which somehow place
+ * the vector number in a known place (which is safe if another
+ * interrupt nests this one) and branches to _ISR_Handler.
+ *
+ * save some or all context on stack
+ * may need to save some special interrupt information for exit
+ *
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if ( _ISR_Nest_level == 0 )
+ * switch to software interrupt stack
+ * #endif
+ *
+ * _ISR_Nest_level++;
+ *
+ * _Thread_Dispatch_disable_level++;
+ *
+ * (*_ISR_Vector_table[ vector ])( vector );
+ *
+ * _Thread_Dispatch_disable_level--;
+ *
+ * --_ISR_Nest_level;
+ *
+ * if ( _ISR_Nest_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_disable_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_necessary ) {
+ * call _Thread_Dispatch() or prepare to return to _ISR_Dispatch
+ * prepare to get out of interrupt
+ * return from interrupt (maybe to _ISR_Dispatch)
+ *
+ * LABEL "exit interrupt (simple case):
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if outermost interrupt
+ * restore stack
+ * #endif
+ * prepare to get out of interrupt
+ * return from interrupt
+ */
+}
diff --git a/cpukit/score/cpu/m32c/preinstall.am b/cpukit/score/cpu/m32c/preinstall.am
new file mode 100644
index 0000000000..14cb358026
--- /dev/null
+++ b/cpukit/score/cpu/m32c/preinstall.am
@@ -0,0 +1,54 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/varvects.h: varvects.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/varvects.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/varvects.h
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/m32c.h: rtems/score/m32c.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/m32c.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/m32c.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/m32c/rtems/asm.h b/cpukit/score/cpu/m32c/rtems/asm.h
new file mode 100644
index 0000000000..35639d2d72
--- /dev/null
+++ b/cpukit/score/cpu/m32c/rtems/asm.h
@@ -0,0 +1,125 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/m32c.h>
+
+#ifndef __USER_LABEL_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all C program symbols.
+ */
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all register names.
+ */
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/** Use the right prefix for global labels. */
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/** Use the right prefix for registers. */
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+/** This macro is used to denote the beginning of a code declaration. */
+#define BEGIN_CODE_DCL .text
+/** This macro is used to denote the end of a code declaration. */
+#define END_CODE_DCL
+/** This macro is used to denote the beginning of a data declaration section. */
+#define BEGIN_DATA_DCL .data
+/** This macro is used to denote the end of a data declaration section. */
+#define END_DATA_DCL
+/** This macro is used to denote the beginning of a code section. */
+#define BEGIN_CODE .text
+/** This macro is used to denote the end of a code section. */
+#define END_CODE
+/** This macro is used to denote the beginning of a data section. */
+#define BEGIN_DATA
+/** This macro is used to denote the end of a data section. */
+#define END_DATA
+/** This macro is used to denote the beginning of the
+ * unitialized data section.
+ */
+#define BEGIN_BSS
+/** This macro is used to denote the end of the unitialized data section. */
+#define END_BSS
+/** This macro is used to denote the end of the assembly file. */
+#define END
+
+/**
+ * This macro is used to declare a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define PUBLIC(sym) .globl SYM (sym)
+
+/**
+ * This macro is used to prototype a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/m32c/rtems/score/cpu.h b/cpukit/score/cpu/m32c/rtems/score/cpu.h
new file mode 100644
index 0000000000..4d75c0a930
--- /dev/null
+++ b/cpukit/score/cpu/m32c/rtems/score/cpu.h
@@ -0,0 +1,1186 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the XXX
+ * processor.
+ *
+ * @note This file is part of a porting template that is intended
+ * to be used as the starting point when porting RTEMS to a new
+ * CPU family. The following needs to be done when using this as
+ * the starting point for a new port:
+ *
+ * + Anywhere there is an XXX, it should be replaced
+ * with information about the CPU family being ported to.
+ *
+ * + At the end of each comment section, there is a heading which
+ * says "Port Specific Information:". When porting to RTEMS,
+ * add CPU family specific information in this section
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/m32c.h>
+
+/* conditional compilation parameters */
+
+#define RTEMS_USE_16_BIT_OBJECT
+
+/**
+ * Should the calls to @ref _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * This conditional is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ *
+ * @note In general, the @ref _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls @ref _Thread_Enable_dispatch which in turns calls
+ * @ref _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/**
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/**
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
+
+/**
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/**
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
+
+/**
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/**
+ * @def CPU_HARDWARE_FP
+ *
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "M32C_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+/**
+ * @def CPU_SOFTWARE_FP
+ *
+ * Does the CPU have no hardware floating point and GCC provides a
+ * software floating point implementation which must be context
+ * switched?
+ *
+ * This feature conditional is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if ( M32C_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+#define CPU_CONTEXT_FP_SIZE 0
+
+/**
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALL_TASKS_ARE_FP TRUE
+
+/**
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/**
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/**
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine @ref _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * @ref _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * -# BSP provided
+ * -# CPU dependent (if provided)
+ * -# generic (if no BSP and no CPU dependent)
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/**
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_GROWS_UP TRUE
+
+/**
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * @note Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (2)))
+
+
+/**
+ * @defgroup CPUEndian Processor Dependent Endianness Support
+ *
+ * This group assists in issues related to processor endianness.
+ */
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_LITTLE_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_BIG_ENDIAN TRUE
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_BIG_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_LITTLE_ENDIAN FALSE
+
+/**
+ * @ingroup CPUInterrupt
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+/**
+ * @defgroup CPUContext Processor Dependent Context Management
+ *
+ * From the highest level viewpoint, there are 2 types of context to save.
+ *
+ * -# Interrupt registers to save
+ * -# Task level registers to save
+ *
+ * Since RTEMS handles integer and floating point contexts separately, this
+ * means we have the following 3 context items:
+ *
+ * -# task level context stuff:: Context_Control
+ * -# floating point task stuff:: Context_Control_fp
+ * -# special interrupt level context :: CPU_Interrupt_frame
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the minimal set of integer and processor state registers
+ * that must be saved during a voluntary context switch from one thread
+ * to another.
+ */
+typedef struct {
+ /** This will contain the stack pointer. */
+ uint32_t sp;
+ /** This will contain the frame base pointer. */
+ uint32_t fb;
+} Context_Control;
+
+/**
+ * @ingroup CPUContext Management
+ *
+ * This macro returns the stack pointer associated with @a _context.
+ *
+ * @param[in] _context is the thread context area to access
+ *
+ * @return This method returns the stack pointer.
+ */
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->sp
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that must
+ * be saved during an interrupt. This set does not include any which are
+ * in @ref Context_Control.
+ */
+typedef struct {
+ /** This field is a hint that a port will have a number of integer
+ * registers that need to be saved when an interrupt occurs or
+ * when a context switch occurs at the end of an ISR.
+ */
+ uint32_t special_interrupt_register;
+} CPU_Interrupt_frame;
+
+/**
+ * @defgroup CPUInterrupt Processor Dependent Interrupt Management
+ *
+ * On some CPUs, RTEMS supports a software managed interrupt stack.
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in @ref _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use.
+ *
+ * @note These two variables are required if the macro
+ * @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/**
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the number of entries in the @ref _ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the highest interrupt vector number for this port.
+ */
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/**
+ * @ingroup CPUInterrupt
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable @a _ISR_Nest_level.
+ */
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/**
+ * @ingroup CPUContext
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_MINIMUM_SIZE (2048L)
+
+/**
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALIGNMENT 2
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by @ref CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for
+ * the heap, then this should be set to @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HEAP_ALIGNMENT 4
+
+/**
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * @ref CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is
+ * strict enough for the partition, then this should be set to
+ * @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2. It does have to
+ * be greater or equal to than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by @ref CPU_ALIGNMENT. If the
+ * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
+ * set to 0.
+ *
+ * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_ALIGNMENT 0
+
+/*
+ * ISR handler macros
+ */
+
+/**
+ * @ingroup CPUInterrupt
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Initialize_vectors()
+
+/**
+ * @ingroup CPUInterrupt
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in @a _isr_cookie.
+ *
+ * @param[out] _isr_cookie will contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ do { \
+ int _flg; \
+ m32c_get_flg( _flg ); \
+ _isr_cookie = _flg; \
+ __asm__ volatile( "fclr I" ); \
+ } while(0)
+
+/**
+ * @ingroup CPUInterrupt
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * @a _isr_cookie is not modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Enable(_isr_cookie) \
+ do { \
+ int _flg = (int) (_isr_cookie); \
+ m32c_set_flg( _flg ); \
+ } while(0)
+
+/**
+ * @ingroup CPUInterrupt
+ * This temporarily restores the interrupt to @a _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter @a _isr_cookie is not
+ * modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ do { \
+ int _flg = (int) (_isr_cookie); \
+ m32c_set_flg( _flg ); \
+ __asm__ volatile( "fclr I" ); \
+ } while(0)
+
+/**
+ * @ingroup CPUInterrupt
+ *
+ * This routine and @ref _CPU_ISR_Get_level
+ * Map the interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Set_level( _new_level ) \
+ do { \
+ if (_new_level) __asm__ volatile( "fclr I" ); \
+ else __asm__ volatile( "fset I" ); \
+ } while(0)
+
+/**
+ * @ingroup CPUInterrupt
+ * Return the current interrupt disable level for this task in
+ * the format used by the interrupt level portion of the task mode.
+ *
+ * @note This routine usually must be implemented as a subroutine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/**
+ * @ingroup CPUContext
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * @param[in] _the_context is the context structure to be initialized
+ * @param[in] _stack_base is the lowest physical address of this task's stack
+ * @param[in] _size is the size of this task's stack
+ * @param[in] _isr is the interrupt disable level
+ * @param[in] _entry_point is the thread's entry point. This is
+ * always @a _Thread_Handler
+ * @param[in] _is_fp is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ size_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/**
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. For many ports, simply adding a label to the restore path
+ * of @ref _CPU_Context_switch will work. On other ports, it may be
+ * possibly to load a few arguments and jump to the restore path. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_Restart_self(
+ Context_Control *the_context
+);
+
+/**
+ * @ingroup CPUContext
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * @param[in] _base is the lowest physical address of the floating point
+ * context area
+ * @param[in] _offset is the offset into the floating point area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/**
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * @a _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other floating point context save/restore models include:
+ * -# not doing anything, and
+ * -# putting a "null FP status word" in the correct place in the FP context.
+ *
+ * @param[in] _destination is the floating point context area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/**
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/**
+ * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
+ *
+ * This set of routines are used to implement fast searches for
+ * the most important ready task.
+ */
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the generic bitfield
+ * manipulation implementation.
+ */
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the data tables provided
+ * by the generic bitfield manipulation implementation.
+ * This can occur when actually using the generic bitfield manipulation
+ * implementation or when implementing the same algorithm in assembly
+ * language for improved performance. It is unlikely that a port will use
+ * the data if it has a bitfield scan instruction.
+ */
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This routine sets @a _output to the bit number of the first bit
+ * set in @a _value. @a _value is of CPU dependent type
+ * @a Priority_bit_map_Control. This type may be either 16 or 32 bits
+ * wide although only the 16 least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * -# What happens when run on a value of zero?
+ * -# Bits may be numbered from MSB to LSB or vice-versa.
+ * -# The numbering may be zero or one based.
+ * -# The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
+ * @ref _CPU_Priority_bits_index. These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by @ref _CPU_Priority_Mask.
+ * The basic major and minor values calculated by @ref _Priority_Major
+ * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for @ref _Priority_Get_highest to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+@verbatim
+ - a series of 16 bit test instructions
+ - a "binary search using if's"
+ - _number = 0
+ if _value > 0x00ff
+ _value >>=8
+ _number = 8;
+
+ if _value > 0x0000f
+ _value >=8
+ _number += 4
+
+ _number += bit_set_table[ _value ]
+@endverbatim
+
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * @param[in] _value is the value to be scanned
+ * @param[in] _output is the first bit set
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+#endif
+
+/* end of Bitfield handler macros */
+
+/**
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by @ref _CPU_Bitfield_Find_first_bit. See the discussion
+ * for that routine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/**
+ * @ingroup CPUBitfield
+ * This routine translates the bit numbers returned by
+ * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * @param[in] _priority is the major or minor number to translate
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/**
+ * This routine performs CPU dependent initialization.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the raw ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs an interrupt vector.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the RTEMS ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * @note It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Install_interrupt_stack( void );
+
+/**
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * @note It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/**
+ * @ingroup CPUContext
+ * This routine switches from the run context to the heir context.
+ *
+ * @param[in] run points to the context of the currently executing task
+ * @param[in] heir points to the context of the heir task
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in @ref _CPU_Context_switch.
+ *
+ * @param[in] new_context points to the context to be restored.
+ *
+ * @note May be unnecessary to reload some registers.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/**
+ * @ingroup CPUEndian
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return swapped;
+}
+
+/**
+ * @ingroup CPUEndian
+ * This routine swaps a 16 bir quantity.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ */
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/m32c/rtems/score/cpu_asm.h b/cpukit/score/cpu/m32c/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..a509b36ae6
--- /dev/null
+++ b/cpukit/score/cpu/m32c/rtems/score/cpu_asm.h
@@ -0,0 +1,72 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Very loose template for an include file for the cpu_asm.? file
+ * if it is implemented as a ".S" file (preprocessed by cpp) instead
+ * of a ".s" file (preprocessed by gm4 or gasp).
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+/* pull in the generated offsets */
+
+#include <rtems/score/offsets.h>
+
+/*
+ * Hardware General Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Control Registers
+ */
+
+/* put something here */
+
+/*
+ * Calling Convention
+ */
+
+/* put something here */
+
+/*
+ * Temporary registers
+ */
+
+/* put something here */
+
+/*
+ * Floating Point Registers - SW Conventions
+ */
+
+/* put something here */
+
+/*
+ * Temporary floating point registers
+ */
+
+/* put something here */
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/m32c/rtems/score/m32c.h b/cpukit/score/cpu/m32c/rtems/score/m32c.h
new file mode 100644
index 0000000000..0c3fe43b7f
--- /dev/null
+++ b/cpukit/score/cpu/m32c/rtems/score/m32c.h
@@ -0,0 +1,72 @@
+/*
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specified to the NO CPU port.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_NO_CPU_H
+#define _RTEMS_SCORE_NO_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the NO CPU family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+#if defined(rtems_multilib)
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+
+#define CPU_MODEL_NAME "rtems_multilib"
+#define NOCPU_HAS_FPU 1
+
+#elif defined(__m32c__)
+
+#define CPU_MODEL_NAME "m32c"
+#define M32C_HAS_FPU 0
+
+#else
+
+#error "Unsupported CPU Model"
+
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "m32c"
+
+#define m32c_get_flg( _flg ) \
+ __asm__ volatile( "stc flg, %0" : "=r" (_flg))
+
+#define m32c_set_flg( _flg ) \
+ __asm__ volatile( "ldc %1, flg" : "=r" (_flg) : "r" (_flg) )
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_NO_CPU_H */
diff --git a/cpukit/score/cpu/m32c/rtems/score/types.h b/cpukit/score/cpu/m32c/rtems/score/types.h
new file mode 100644
index 0000000000..f25f5a61ab
--- /dev/null
+++ b/cpukit/score/cpu/m32c/rtems/score/types.h
@@ -0,0 +1,49 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Intel
+ * m32c processor family.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+/** This defines the type for a priority bit map entry. */
+typedef uint16_t Priority_bit_map_Control;
+
+/** This defines the return type for an ISR entry point. */
+typedef void m32c_isr;
+
+/** This defines the prototype for an ISR entry point. */
+typedef m32c_isr ( *m32c_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/m32c/varvects.S b/cpukit/score/cpu/m32c/varvects.S
new file mode 100644
index 0000000000..c23d364cf8
--- /dev/null
+++ b/cpukit/score/cpu/m32c/varvects.S
@@ -0,0 +1,47 @@
+/*
+
+Copyright (c) 2008 Red Hat Incorporated.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ The name of Red Hat Incorporated may not be used to endorse
+ or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* This works with varvects.h
+*/
+
+ .section ".var_vects","aw",@progbits
+ .global __var_vects
+ .type __var_vects,@object
+ .size __var_vects, 256
+__var_vects:
+ .zero 256
+
+ .text
diff --git a/cpukit/score/cpu/m32c/varvects.h b/cpukit/score/cpu/m32c/varvects.h
new file mode 100644
index 0000000000..30884edbd8
--- /dev/null
+++ b/cpukit/score/cpu/m32c/varvects.h
@@ -0,0 +1,54 @@
+/*
+
+Copyright (c) 2008 Red Hat Incorporated.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ The name of Red Hat Incorporated may not be used to endorse
+ or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+/* This file defines the interface to the built-in variable vector
+ table in R8C/M16C/M32C chips. */
+
+#ifndef _VARVECTS_H_
+#define _VARVECTS_H_
+
+typedef void (*_m32c_interrupt_func)(void) __attribute__((mode(SI)));
+extern _m32c_interrupt_func _var_vects[];
+
+#if defined(__r8c_cpu__) || defined (__m16c_cpu__)
+
+#define _set_var_vect(f,n) \
+ { __asm__ ("mov.w #%%lo16(%d0),__var_vects+%d1" : : "s" (f), "g" (n*4)); \
+ __asm__ ("mov.w #%%hi16(%d0),__var_vects+%d1" : : "s" (f), "g" (n*4+2)); }
+
+#else
+
+#define _set_var_vect(f,n) \
+ _var_vects[n] = f
+
+#endif
+#endif
diff --git a/cpukit/score/cpu/m32r/.cvsignore b/cpukit/score/cpu/m32r/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/m32r/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/m32r/ChangeLog b/cpukit/score/cpu/m32r/ChangeLog
new file mode 100644
index 0000000000..7094941276
--- /dev/null
+++ b/cpukit/score/cpu/m32r/ChangeLog
@@ -0,0 +1,68 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * context_init.c:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2011-01-31 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * context_switch.S: Reverse registers.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * cpu_asm.c: Rename _Context_Switch_necessary to
+ _Thread_Dispatch_necessary to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.c, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * context_init.c, context_switch.S, cpu.c, cpu_asm.c: Add include of
+ config.h
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-10-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am, preinstall.am, rtems/score/cpu.h: Now performs context
+ switches and many tests run.
+ * context_init.c, context_switch.S, cpu.c, cpu_asm.c: New files.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * .cvsignore, ChangeLog, Makefile.am, preinstall.am, rtems/asm.h,
+ rtems/score/cpu.h, rtems/score/cpu_asm.h, rtems/score/m32r.h,
+ rtems/score/types.h: New files.
+
diff --git a/cpukit/score/cpu/m32r/Makefile.am b/cpukit/score/cpu/m32r/Makefile.am
new file mode 100644
index 0000000000..cc0d2cae19
--- /dev/null
+++ b/cpukit/score/cpu/m32r/Makefile.am
@@ -0,0 +1,21 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_HEADERS =
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/m32r.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.c context_switch.S context_init.c
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/m32r/context_init.c b/cpukit/score/cpu/m32r/context_init.c
new file mode 100644
index 0000000000..344bc7cd6a
--- /dev/null
+++ b/cpukit/score/cpu/m32r/context_init.c
@@ -0,0 +1,56 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <rtems/system.h>
+
+typedef struct {
+ uint32_t marker;
+} Starting_Frame;
+
+#define _get_r12( _r12 ) \
+ __asm__ volatile( "mv r12, %0" : "=r" (_r12))
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ void *stackEnd = stack_base;
+ Starting_Frame *frame;
+ uint32_t r12;
+
+ stackEnd += size;
+
+ frame = (Starting_Frame *)stackEnd;
+ frame--;
+ frame->marker = 0xa5a5a5a5;
+
+ _get_r12( r12 );
+
+ the_context->r8 = 0x88888888;
+ the_context->r9 = 0x99999999;
+ the_context->r10 = 0xaaaaaaaa;
+ the_context->r11 = 0xbbbbbbbb;
+ the_context->r12 = r12;
+ the_context->r13_fp = 0;
+ the_context->r14_lr = (uintptr_t) entry_point;
+ the_context->r15_sp = (uintptr_t) frame;
+
+}
diff --git a/cpukit/score/cpu/m32r/context_switch.S b/cpukit/score/cpu/m32r/context_switch.S
new file mode 100644
index 0000000000..dd95a461fb
--- /dev/null
+++ b/cpukit/score/cpu/m32r/context_switch.S
@@ -0,0 +1,69 @@
+/*
+ * Context switch for the Reneas M32C
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define ARG_EXECUTING 8
+#define ARG_HEIR 12
+
+#define CONTEXT_R8 0x00
+#define CONTEXT_R9 0x04
+#define CONTEXT_R10 0x08
+#define CONTEXT_R11 0x0C
+#define CONTEXT_R12 0x10
+#define CONTEXT_R13_FP 0x14
+#define CONTEXT_R14_LR 0x18
+#define CONTEXT_R15_SP 0x1C
+#define CONTEXT_ACC_LOW 0x20
+#define CONTEXT_ACC_HIGH 0x24
+
+ .file "context_switch.S"
+ .text
+ .global _CPU_Context_switch
+ .type _CPU_Context_switch, @function
+_CPU_Context_switch:
+ st r8, @(CONTEXT_R8,r0)
+ st r9, @(CONTEXT_R9,r0)
+ st r10, @(CONTEXT_R10,r0)
+ st r11, @(CONTEXT_R11,r0)
+ st r12, @(CONTEXT_R12,r0)
+ st r13, @(CONTEXT_R13_FP,r0)
+ st r14, @(CONTEXT_R14_LR,r0)
+ st r15, @(CONTEXT_R15_SP,r0)
+ mvfaclo r2
+ st r2, @(CONTEXT_ACC_LOW,r0)
+ mvfachi r2
+ st r2, @(CONTEXT_ACC_HIGH,r0)
+
+restore:
+ ld r8, @(CONTEXT_R8,r1)
+ ld r9, @(CONTEXT_R9,r1)
+ ld r10, @(CONTEXT_R10,r1)
+ ld r11, @(CONTEXT_R11,r1)
+ ld r12, @(CONTEXT_R12,r1)
+ ld r13, @(CONTEXT_R13_FP,r1)
+ ld r14, @(CONTEXT_R14_LR,r1)
+ ld r15, @(CONTEXT_R15_SP,r1)
+ ld r2, @(CONTEXT_ACC_LOW,r1)
+ mvtaclo r2
+ ld r2, @(CONTEXT_ACC_HIGH,r1)
+ mvtachi r2
+ jmp lr
+
+ .global _CPU_Context_Restart_self
+ .type _CPU_Context_Restart_self, @function
+_CPU_Context_Restart_self:
+ mv r1, r0
+ bra restore
diff --git a/cpukit/score/cpu/m32r/cpu.c b/cpukit/score/cpu/m32r/cpu.c
new file mode 100644
index 0000000000..a518005ff3
--- /dev/null
+++ b/cpukit/score/cpu/m32r/cpu.c
@@ -0,0 +1,126 @@
+/*
+ * M32R CPU Dependent Source
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Initialize(void)
+{
+}
+
+/*
+ * This routine returns the current interrupt level.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ return 0;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+ /* _set_var_vect(new_handler,vector); */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
diff --git a/cpukit/score/cpu/m32r/cpu_asm.c b/cpukit/score/cpu/m32r/cpu_asm.c
new file mode 100644
index 0000000000..8ab01849bd
--- /dev/null
+++ b/cpukit/score/cpu/m32r/cpu_asm.c
@@ -0,0 +1,95 @@
+/* cpu_asm.c ===> cpu_asm.S or cpu_asm.s
+ *
+ * NOTE: This is supposed to be a .S or .s file NOT a C file.
+ *
+ * M32R does not yet have interrupt support. When this functionality
+ * is written, this file should become obsolete.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+
+/* void __ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _ISR_Handler(void)
+{
+ /*
+ * This discussion ignores a lot of the ugly details in a real
+ * implementation such as saving enough registers/state to be
+ * able to do something real. Keep in mind that the goal is
+ * to invoke a user's ISR handler which is written in C and
+ * uses a certain set of registers.
+ *
+ * Also note that the exact order is to a large extent flexible.
+ * Hardware will dictate a sequence for a certain subset of
+ * _ISR_Handler while requirements for setting
+ */
+
+ /*
+ * At entry to "common" _ISR_Handler, the vector number must be
+ * available. On some CPUs the hardware puts either the vector
+ * number or the offset into the vector table for this ISR in a
+ * known place. If the hardware does not give us this information,
+ * then the assembly portion of RTEMS for this port will contain
+ * a set of distinct interrupt entry points which somehow place
+ * the vector number in a known place (which is safe if another
+ * interrupt nests this one) and branches to _ISR_Handler.
+ *
+ * save some or all context on stack
+ * may need to save some special interrupt information for exit
+ *
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if ( _ISR_Nest_level == 0 )
+ * switch to software interrupt stack
+ * #endif
+ *
+ * _ISR_Nest_level++;
+ *
+ * _Thread_Dispatch_disable_level++;
+ *
+ * (*_ISR_Vector_table[ vector ])( vector );
+ *
+ * _Thread_Dispatch_disable_level--;
+ *
+ * --_ISR_Nest_level;
+ *
+ * if ( _ISR_Nest_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_disable_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_necessary ) {
+ * call _Thread_Dispatch() or prepare to return to _ISR_Dispatch
+ * prepare to get out of interrupt
+ * return from interrupt (maybe to _ISR_Dispatch)
+ *
+ * LABEL "exit interrupt (simple case):
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if outermost interrupt
+ * restore stack
+ * #endif
+ * prepare to get out of interrupt
+ * return from interrupt
+ */
+}
diff --git a/cpukit/score/cpu/m32r/preinstall.am b/cpukit/score/cpu/m32r/preinstall.am
new file mode 100644
index 0000000000..2759bc9a67
--- /dev/null
+++ b/cpukit/score/cpu/m32r/preinstall.am
@@ -0,0 +1,50 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/m32r.h: rtems/score/m32r.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/m32r.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/m32r.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/m32r/rtems/asm.h b/cpukit/score/cpu/m32r/rtems/asm.h
new file mode 100644
index 0000000000..00177032e9
--- /dev/null
+++ b/cpukit/score/cpu/m32r/rtems/asm.h
@@ -0,0 +1,125 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/m32r.h>
+
+#ifndef __USER_LABEL_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all C program symbols.
+ */
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all register names.
+ */
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/** Use the right prefix for global labels. */
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/** Use the right prefix for registers. */
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+/** This macro is used to denote the beginning of a code declaration. */
+#define BEGIN_CODE_DCL .text
+/** This macro is used to denote the end of a code declaration. */
+#define END_CODE_DCL
+/** This macro is used to denote the beginning of a data declaration section. */
+#define BEGIN_DATA_DCL .data
+/** This macro is used to denote the end of a data declaration section. */
+#define END_DATA_DCL
+/** This macro is used to denote the beginning of a code section. */
+#define BEGIN_CODE .text
+/** This macro is used to denote the end of a code section. */
+#define END_CODE
+/** This macro is used to denote the beginning of a data section. */
+#define BEGIN_DATA
+/** This macro is used to denote the end of a data section. */
+#define END_DATA
+/** This macro is used to denote the beginning of the
+ * unitialized data section.
+ */
+#define BEGIN_BSS
+/** This macro is used to denote the end of the unitialized data section. */
+#define END_BSS
+/** This macro is used to denote the end of the assembly file. */
+#define END
+
+/**
+ * This macro is used to declare a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define PUBLIC(sym) .globl SYM (sym)
+
+/**
+ * This macro is used to prototype a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/m32r/rtems/score/cpu.h b/cpukit/score/cpu/m32r/rtems/score/cpu.h
new file mode 100644
index 0000000000..4cbb3e99d2
--- /dev/null
+++ b/cpukit/score/cpu/m32r/rtems/score/cpu.h
@@ -0,0 +1,1247 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the XXX
+ * processor.
+ *
+ * @note This file is part of a porting template that is intended
+ * to be used as the starting point when porting RTEMS to a new
+ * CPU family. The following needs to be done when using this as
+ * the starting point for a new port:
+ *
+ * + Anywhere there is an XXX, it should be replaced
+ * with information about the CPU family being ported to.
+ *
+ * + At the end of each comment section, there is a heading which
+ * says "Port Specific Information:". When porting to RTEMS,
+ * add CPU family specific information in this section
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/m32r.h>
+
+/* conditional compilation parameters */
+
+/**
+ * Should the calls to @ref _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * This conditional is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ *
+ * @note In general, the @ref _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls @ref _Thread_Enable_dispatch which in turns calls
+ * @ref _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/**
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/**
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
+
+/**
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/**
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
+
+/**
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/**
+ * @def CPU_HARDWARE_FP
+ *
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "M32R_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+/**
+ * @def CPU_SOFTWARE_FP
+ *
+ * Does the CPU have no hardware floating point and GCC provides a
+ * software floating point implementation which must be context
+ * switched?
+ *
+ * This feature conditional is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if ( M32R_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+/**
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALL_TASKS_ARE_FP TRUE
+
+/**
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/**
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/**
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine @ref _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * @ref _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * -# BSP provided
+ * -# CPU dependent (if provided)
+ * -# generic (if no BSP and no CPU dependent)
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
+
+/**
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_GROWS_UP TRUE
+
+/**
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * @note Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STRUCTURE_ALIGNMENT
+
+/**
+ * @defgroup CPUEndian Processor Dependent Endianness Support
+ *
+ * This group assists in issues related to processor endianness.
+ */
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_LITTLE_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_BIG_ENDIAN TRUE
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_BIG_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_LITTLE_ENDIAN FALSE
+
+/**
+ * @ingroup CPUInterrupt
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+/**
+ * @defgroup CPUContext Processor Dependent Context Management
+ *
+ * From the highest level viewpoint, there are 2 types of context to save.
+ *
+ * -# Interrupt registers to save
+ * -# Task level registers to save
+ *
+ * Since RTEMS handles integer and floating point contexts separately, this
+ * means we have the following 3 context items:
+ *
+ * -# task level context stuff:: Context_Control
+ * -# floating point task stuff:: Context_Control_fp
+ * -# special interrupt level context :: CPU_Interrupt_frame
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the minimal set of integer and processor state registers
+ * that must be saved during a voluntary context switch from one thread
+ * to another.
+ */
+typedef struct {
+ /** r8 -- temporary register */
+ uint32_t r8;
+ /** r9 -- temporary register */
+ uint32_t r9;
+ /** r10 -- temporary register */
+ uint32_t r10;
+ /** r11 -- temporary register */
+ uint32_t r11;
+ /** r12 -- may be global pointer */
+ uint32_t r12;
+ /** r13 -- frame pointer */
+ uint32_t r13_fp;
+ /** r14 -- link register (aka return pointer */
+ uint32_t r14_lr;
+ /** r15 -- stack pointer */
+ uint32_t r15_sp;
+ /** dsp accumulator low order 32-bits */
+ uint32_t acc_low;
+ /** dsp accumulator high order 32-bits */
+ uint32_t acc_high;
+} Context_Control;
+
+/**
+ * @ingroup CPUContext Management
+ *
+ * This macro returns the stack pointer associated with @a _context.
+ *
+ * @param[in] _context is the thread context area to access
+ *
+ * @return This method returns the stack pointer.
+ */
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->r15_sp
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the complete set of floating point registers that must
+ * be saved during any context switch from one thread to another.
+ */
+typedef struct {
+ /** FPU registers are listed here */
+ double some_float_register;
+} Context_Control_fp;
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that must
+ * be saved during an interrupt. This set does not include any which are
+ * in @ref Context_Control.
+ */
+typedef struct {
+ /** This field is a hint that a port will have a number of integer
+ * registers that need to be saved when an interrupt occurs or
+ * when a context switch occurs at the end of an ISR.
+ */
+ uint32_t special_interrupt_register;
+} CPU_Interrupt_frame;
+
+/**
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * @ref _CPU_Initialize and copied into the task's FP context area during
+ * @ref _CPU_Context_Initialize.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+/**
+ * @defgroup CPUInterrupt Processor Dependent Interrupt Management
+ *
+ * On some CPUs, RTEMS supports a software managed interrupt stack.
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in @ref _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use.
+ *
+ * @note These two variables are required if the macro
+ * @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/**
+ * @ingroup CPUContext
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/**
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the number of entries in the @ref _ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the highest interrupt vector number for this port.
+ */
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/**
+ * @ingroup CPUInterrupt
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable @a _ISR_Nest_level.
+ */
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/**
+ * @ingroup CPUContext
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_MINIMUM_SIZE (1024)
+
+/**
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALIGNMENT 8
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by @ref CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for
+ * the heap, then this should be set to @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * @ref CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is
+ * strict enough for the partition, then this should be set to
+ * @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2. It does have to
+ * be greater or equal to than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by @ref CPU_ALIGNMENT. If the
+ * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
+ * set to 0.
+ *
+ * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_ALIGNMENT 0
+
+/*
+ * ISR handler macros
+ */
+
+/**
+ * @ingroup CPUInterrupt
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Initialize_vectors()
+
+/**
+ * @ingroup CPUInterrupt
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in @a _isr_cookie.
+ *
+ * @param[out] _isr_cookie will contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ { \
+ (_isr_cookie) = 0; /* do something to prevent warnings */ \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * @a _isr_cookie is not modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ { \
+ (_isr_cookie) = 0; /* do something to prevent warnings */ \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * This temporarily restores the interrupt to @a _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter @a _isr_cookie is not
+ * modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ { \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ *
+ * This routine and @ref _CPU_ISR_Get_level
+ * Map the interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Set_level( new_level ) \
+ { \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * Return the current interrupt disable level for this task in
+ * the format used by the interrupt level portion of the task mode.
+ *
+ * @note This routine usually must be implemented as a subroutine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/**
+ * @ingroup CPUContext
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * @param[in] _the_context is the context structure to be initialized
+ * @param[in] _stack_base is the lowest physical address of this task's stack
+ * @param[in] _size is the size of this task's stack
+ * @param[in] _isr is the interrupt disable level
+ * @param[in] _entry_point is the thread's entry point. This is
+ * always @a _Thread_Handler
+ * @param[in] _is_fp is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ size_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/**
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. For many ports, simply adding a label to the restore path
+ * of @ref _CPU_Context_switch will work. On other ports, it may be
+ * possibly to load a few arguments and jump to the restore path. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_Restart_self(
+ Context_Control *the_context
+);
+
+/**
+ * @ingroup CPUContext
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * @param[in] _base is the lowest physical address of the floating point
+ * context area
+ * @param[in] _offset is the offset into the floating point area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/**
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * @a _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other floating point context save/restore models include:
+ * -# not doing anything, and
+ * -# putting a "null FP status word" in the correct place in the FP context.
+ *
+ * @param[in] _destination is the floating point context area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/**
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/**
+ * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
+ *
+ * This set of routines are used to implement fast searches for
+ * the most important ready task.
+ */
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the generic bitfield
+ * manipulation implementation.
+ */
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the data tables provided
+ * by the generic bitfield manipulation implementation.
+ * This can occur when actually using the generic bitfield manipulation
+ * implementation or when implementing the same algorithm in assembly
+ * language for improved performance. It is unlikely that a port will use
+ * the data if it has a bitfield scan instruction.
+ */
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This routine sets @a _output to the bit number of the first bit
+ * set in @a _value. @a _value is of CPU dependent type
+ * @a Priority_bit_map_Control. This type may be either 16 or 32 bits
+ * wide although only the 16 least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * -# What happens when run on a value of zero?
+ * -# Bits may be numbered from MSB to LSB or vice-versa.
+ * -# The numbering may be zero or one based.
+ * -# The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
+ * @ref _CPU_Priority_bits_index. These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by @ref _CPU_Priority_Mask.
+ * The basic major and minor values calculated by @ref _Priority_Major
+ * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for @ref _Priority_Get_highest to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+@verbatim
+ - a series of 16 bit test instructions
+ - a "binary search using if's"
+ - _number = 0
+ if _value > 0x00ff
+ _value >>=8
+ _number = 8;
+
+ if _value > 0x0000f
+ _value >=8
+ _number += 4
+
+ _number += bit_set_table[ _value ]
+@endverbatim
+
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * @param[in] _value is the value to be scanned
+ * @param[in] _output is the first bit set
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+#endif
+
+/* end of Bitfield handler macros */
+
+/**
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by @ref _CPU_Bitfield_Find_first_bit. See the discussion
+ * for that routine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/**
+ * @ingroup CPUBitfield
+ * This routine translates the bit numbers returned by
+ * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * @param[in] _priority is the major or minor number to translate
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/**
+ * This routine performs CPU dependent initialization.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the raw ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs an interrupt vector.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the RTEMS ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * @note It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Install_interrupt_stack( void );
+
+/**
+ * @ingroup CPUContext
+ * This routine switches from the run context to the heir context.
+ *
+ * @param[in] run points to the context of the currently executing task
+ * @param[in] heir points to the context of the heir task
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in @ref _CPU_Context_switch.
+ *
+ * @param[in] new_context points to the context to be restored.
+ *
+ * @note May be unnecessary to reload some registers.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/**
+ * @ingroup CPUContext
+ * This routine saves the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_restore_fp to restore this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine restores the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area to restore
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_save_fp to save this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUEndian
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return swapped;
+}
+
+/**
+ * @ingroup CPUEndian
+ * This routine swaps a 16 bir quantity.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ */
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/m32r/rtems/score/cpu_asm.h b/cpukit/score/cpu/m32r/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..a509b36ae6
--- /dev/null
+++ b/cpukit/score/cpu/m32r/rtems/score/cpu_asm.h
@@ -0,0 +1,72 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Very loose template for an include file for the cpu_asm.? file
+ * if it is implemented as a ".S" file (preprocessed by cpp) instead
+ * of a ".s" file (preprocessed by gm4 or gasp).
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+/* pull in the generated offsets */
+
+#include <rtems/score/offsets.h>
+
+/*
+ * Hardware General Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Control Registers
+ */
+
+/* put something here */
+
+/*
+ * Calling Convention
+ */
+
+/* put something here */
+
+/*
+ * Temporary registers
+ */
+
+/* put something here */
+
+/*
+ * Floating Point Registers - SW Conventions
+ */
+
+/* put something here */
+
+/*
+ * Temporary floating point registers
+ */
+
+/* put something here */
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/m32r/rtems/score/m32r.h b/cpukit/score/cpu/m32r/rtems/score/m32r.h
new file mode 100644
index 0000000000..47238fc3db
--- /dev/null
+++ b/cpukit/score/cpu/m32r/rtems/score/m32r.h
@@ -0,0 +1,66 @@
+/*
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specified to the NO CPU port.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_NO_CPU_H
+#define _RTEMS_SCORE_NO_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the NO CPU family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+#if defined(rtems_multilib)
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+
+#define CPU_MODEL_NAME "rtems_multilib"
+#define NOCPU_HAS_FPU 1
+
+#elif defined(__m32r__)
+
+#define CPU_MODEL_NAME "m32r"
+#define NOCPU_HAS_FPU 1
+
+#else
+
+#error "Unsupported CPU Model"
+
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "NO CPU"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_NO_CPU_H */
diff --git a/cpukit/score/cpu/m32r/rtems/score/types.h b/cpukit/score/cpu/m32r/rtems/score/types.h
new file mode 100644
index 0000000000..9aa2294fd3
--- /dev/null
+++ b/cpukit/score/cpu/m32r/rtems/score/types.h
@@ -0,0 +1,49 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Intel
+ * m32r processor family.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+/** This defines the type for a priority bit map entry. */
+typedef uint16_t Priority_bit_map_Control;
+
+/** This defines the return type for an ISR entry point. */
+typedef void m32r_isr;
+
+/** This defines the prototype for an ISR entry point. */
+typedef m32r_isr ( *m32r_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/m68k/.cvsignore b/cpukit/score/cpu/m68k/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/m68k/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/m68k/ChangeLog b/cpukit/score/cpu/m68k/ChangeLog
new file mode 100644
index 0000000000..3122dfd030
--- /dev/null
+++ b/cpukit/score/cpu/m68k/ChangeLog
@@ -0,0 +1,641 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h, rtems/score/m68k.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/types.h: Refactoring of priority handling, to isolate the
+ bitmap implementation of priorities in the supercore so that priority
+ management is a little more modular. This change is in anticipation
+ of scheduler implementations that can select how they manage tracking
+ priority levels / finding the highest priority ready task. Note that
+ most of the changes here are simple renaming, to clarify the use of
+ the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.S, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-04-08 Till Straumann <strauman@slac.stanford.edu>
+
+ * cpu_asm.S, rtems/score/cpu.h: On uC5282, the thread restart needed to
+ reload the frame pointer. As part of doing this, the code was moved
+ from inline asm to the .S file.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S: Add include of config.h
+
+2009-09-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Define CPU_STRUCTURE_ALIGNMENT to be on a 4 byte
+ boundary.
+
+2009-08-24 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Define M68K_FP_STATE_SIZE also if used in
+ assembler files.
+
+2009-05-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h: Cleanup of the floating point
+ context initialization, save and restore code.
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1385/cpukit
+ * cpu_asm.S: When the type rtems_boolean was switched to the C99 bool,
+ the size changed from 4 bytes to 1 byte. The interrupt dispatching
+ code accesses two boolean variables for scheduling purposes and the
+ assembly implementations of this code did not get updated.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Change prototype of IDLE thread to consistently
+ return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-12-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/m68k.h: Don't include rtems/score/types.h,
+ rtems/stdint.h.
+
+2008-09-19 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/m68k.h: Move set cacr, acr0, acr1 routines here to get
+ them out of a BSP.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Remove extraneous spaces.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Fix type when initializing FP context.
+
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Add extern for bfffo table and rename it to
+ indicate that it is specific to this architecture.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-07-09 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * rtems/m68k/m68360.h: added port b pin definitions for SPI
+
+2008-06-13 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/m68k.h: There is no point in defining the maximum
+ priorities to 255. priority.h will default it to this.
+
+2008-06-10 Chris Johns <chrisj@rtems.org>
+
+ * cpu_asm.S: Add Coldfire FPU support.
+ * rtems/score/m68k.h: Change the Coldfire CPU defines to be based
+ on the instruction set. Add Tiny RTEMS support to the small memory
+ model RTEMS processors.
+ * rtems/score/cpu.h: Handle the new Tiny RTEMS support.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2008-01-22 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu_asm.S: Spacing and comment alignment.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/m68k/m68302.h, rtems/m68k/m68360.h: Sweep to make sure grep for
+ COPYRIGHT passes.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Eliminate the interrupt_vector_table field in the
+ m68k CPU Table since it is never read.
+
+2007-08-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/m68k.h: Add stubs for mcf5307, mcf5407, mcfv4e.
+
+2007-07-31 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu_asm.S, rtems/score/cpu.h, rtems/score/m68k.h:
+ Replace M68K_COLDFIRE_ARCH with __mcoldfire__.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-06-19 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 1091/patch
+ * cpu_asm.S: Reduce mask from 0xffc to 0x3fc so only the vector
+ bits are used when calculating the exception vector.
+
+2006-02-28 Eric Norum <norume@aps.anl.gov>
+
+ PR 904/patch
+ * rtems/score/m68k.h: Just "cc" in the clobbered register list for
+ interrupt enable/disable/flash operations. The "memory" barrier will
+ move the the generic interrupt enable/disable/flash macros.
+
+2006-02-24 Eric Norum <norume@aps.anl.gov>
+
+ PR 904/patch
+ * rtems/score/m68k.h: Add "memory" to the clobbered register list for
+ interrupt enable/disable/flash operations. This is necessary to prevent
+ the compiler from hoisting/sinking other operations past the interrupt
+ enable/disable/flash operations.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-06-07 Brett Swimley <brett.swimley@aedbozeman.com>
+
+ PR 803/patch
+ * rtems/score/cpu.h, rtems/score/m68k.h: Correct definition of _VBR.
+
+2005-05-20 Chris Johns <chrisj@rtems.org>
+
+ * rtems/score/cpu.h, rtems/score/m68k.h: Change declaration of _VBR.
+
+2005-05-04 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/m68k.h: Change _ColdFire_VBR to _VBR.
+
+2005-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Change definition of _VBR to a simple pointer.
+ * rtems/score/m68k.h: Remove use of _Coldfire_VBR.
+
+2005-05-03 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Remove warning.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/m68k/m68302.h, rtems/m68k/m68360.h, rtems/m68k/qsm.h,
+ rtems/m68k/sim.h, rtems/score/m68k.h: Header guards cleanup.
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2005-01-31 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR rtems/752
+ * rtems/m68k/m68302.h, rtems/m68k/m68360.h, rtems/m68k/qsm.h,
+ rtems/m68k/sim.h: New (relocated from .).
+ * m68302.h, m68360.h, qsm.h, sim.h: Remove.
+ * Makefile.am: Reflect changes above.
+
+2005-01-28 Eric Norum <norume@aps.anl.gov>
+
+ * rtems/score/cpu.h, rtems/score/m68k.h: ColdFire ISA A+ instructions
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/m68k.h, rtems/score/types.h:
+ New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/m68k.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/m68k.h: *_swap_u16( uint16_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-11-19 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/m68k.h: Use (defined(__mc68020__) && !defined(__mcpu32__))
+ instead of defined(__mc68020__) to reflect GCC-3.4's expectations.
+
+2004-11-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/m68k.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-07-25 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/m68k.h: Add include of <stdint.h> for uint32_t used by
+ endian swapping routines.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into $(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-03 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install m68302.h m68360.h qsm.h sim.h
+ to $(includedir)/rtems/m68k.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu_asm.S: Include <rtems/asm.h> instead of <asm.h>.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, m68302.h, rtems/score/cpu.h, rtems/score/m68k.h: Convert to
+ using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-01-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ PR 561/rtems
+ * asm.h: Add CONCAT0, EVAL. Let SYM and REG use CONCAT0 and EVAL.
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2004-01-07 Joel Sherrill <joel@OARcorp.com>
+
+ * qsm.h, sim.h: Remove efi68k and efi332 references as they are no
+ longer in the tree.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h, rtems/score/m68k.h,
+ rtems/score/types.h: URL for license changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2003-02-06 Ilya Alexeev <ilya@continuum.ru>
+
+ * m68360.h: Correct the order of fields in the ethernet structure
+ to account for the typo in MC68360UM (page 7-248).
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Removed warnings.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-08-26 Eric Norum <eric.norum@usask.ca>
+
+ * cpu_asm.S: More PR267 tinkering which eliminates some conditional
+ compilation.
+
+2002-08-14 Brett Swimley <brett.swimley@aedinc.net>
+
+ * cpu_asm.S: Per PR267, the _ISR_Handler() function never was modifying
+ _ISR_Nest_level, and _Watchdog_Insert() requires this variable
+ to be modified to determine if an interrupt may have modified
+ the watchdog chain. Prior to modifying _ISR_Handler(), I had
+ a test that would fail if _ISR_Flash was not commented out in
+ _Watchdog_Insert(). After this modification was made, my test
+ ran flawlessly.
+
+2002-08-05 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR260 eliminate use of make-target-options. This impacted
+ RTEMS allowing a distinction between the CPU32 and CPU32+ in the
+ SuperCore and required that the m68k optimized memcpy be moved
+ to libcpu.
+ * memcpy.c: Moved to libcpu.
+ * Makefile.am: Modified to reflect above.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.S: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2002-05-28 Chris Johns <ccj@acm.org>
+
+ * rtems/score/m68k.h: Per PR227, mc68060 does not require FPSP
+ since it is now multilib'ed.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * include/rtems/score/ispsh7750.h, score/ispsh7750.c: Account for
+ name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-03-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/m68k.h: m68k_swap_u32 fix typo.
+
+2002-03-06 Victor V. Vengerov <vvv@oktet.ru>
+
+ * rtems/score/m68k.h [M68K_COLDFIRE_ARCH] (CPU_swap_u16, CPU_swap_u32):
+ Generic implementation of endian swap primitives added for Coldfire
+ family.
+
+2002-01-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ * Makefile.am: Reflect changes above.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-08-09 Chris Johns <ccj@acm.org>
+
+ * cpu_asm.S: This patch was co-developed with Eric Norum
+ <eric.norum@usask.ca>. It closes a one instruction window
+ on some m68k CPU cores. It fixes symptoms seen as:
+ 1) No more `interrupt handler invoked twice for
+ a single interrupt'.
+ 2) No more `lockup when mc68360 CPM and PIT interrupts
+ are at different levels'.
+ It does insert a little more overhead on machines without hardware
+ interrupt stacks but correctness has a price.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+ * cpu_asm.S: Modify to properly dereference _ISR_Vector_table
+ now that it is dynamically allocated.
+
+2000-12-19 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Do not read or write raw interrupt vector table if
+ we are on a CPU that does not have a %vbr register and the
+ BSP is configured as having the table in ROM.
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-10-19 Antti P Miettinen <anmietti@trshp.ntc.nokia.com>
+
+ * rtems/score/cpu.h: define CPU_Exception_frame for rdbg.
+ * m68302.h: Make buffer pointer in m302_SCC_bd volatile.
+
+2000-10-12 John S Gwynne <jgwynne@mrcday.com>
+
+ * sim.h: These changes enable RTEMS to automatically generate
+ the ram_init file used by gdb with the BDM patches. The 332 has
+ on-board chip select lines (for RAM and FLASH) that must be
+ configured before use of these peripherals. These patches parse
+ data from start.c where the chip select lines are configured in
+ the runtime executable and automatically generates the gdb
+ initialization file using the same settings. A great time saver.
+ A similar file, ram_init_FW (flash writable), is also generated
+ that the flash programming tool uses.
+ * BSP/start/start.c: Must be modified to support above.
+ * BSP/start/ram_init.ld, BSP/start/ram_init.sed: New files.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/m68k/Makefile.am b/cpukit/score/cpu/m68k/Makefile.am
new file mode 100644
index 0000000000..ff7e0d1c2c
--- /dev/null
+++ b/cpukit/score/cpu/m68k/Makefile.am
@@ -0,0 +1,24 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_m68kdir = $(includedir)/rtems/m68k
+include_rtems_m68k_HEADERS = rtems/m68k/m68302.h rtems/m68k/m68360.h \
+ rtems/m68k/qsm.h rtems/m68k/sim.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/m68k.h \
+ rtems/score/types.h
+
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/m68k/cpu.c b/cpukit/score/cpu/m68k/cpu.c
new file mode 100644
index 0000000000..036ca64ea2
--- /dev/null
+++ b/cpukit/score/cpu/m68k/cpu.c
@@ -0,0 +1,213 @@
+/*
+ * Motorola MC68xxx Dependent Source
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+
+#if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
+ uint32_t _CPU_cacr_shadow;
+#endif
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * OUTPUT PARAMETERS: NONE
+ */
+
+void _CPU_Initialize(void)
+{
+#if ( M68K_HAS_VBR == 0 )
+ /* fill the isr redirect table with the code to place the format/id
+ onto the stack */
+
+ uint32_t slot;
+
+ for (slot = 0; slot < CPU_INTERRUPT_NUMBER_OF_VECTORS; slot++)
+ {
+ _CPU_ISR_jump_table[slot].move_a7 = M68K_MOVE_A7;
+ _CPU_ISR_jump_table[slot].format_id = slot << 2;
+ _CPU_ISR_jump_table[slot].jmp = M68K_JMP;
+ _CPU_ISR_jump_table[slot].isr_handler = (uint32_t) 0xDEADDEAD;
+ }
+#endif /* M68K_HAS_VBR */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ uint32_t level;
+
+ m68k_get_interrupt_level( level );
+
+ return level;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ proc_ptr *interrupt_table = NULL;
+
+#if (M68K_HAS_FPSP_PACKAGE == 1)
+ /*
+ * If this vector being installed is one related to FP, then the
+ * FPSP will install the handler itself and handle it completely
+ * with no intervention from RTEMS.
+ */
+
+ if (*_FPSP_install_raw_handler &&
+ (*_FPSP_install_raw_handler)(vector, new_handler, *old_handler))
+ return;
+#endif
+
+
+ /*
+ * On CPU models without a VBR, it is necessary for there to be some
+ * header code for each ISR which saves a register, loads the vector
+ * number, and jumps to _ISR_Handler.
+ */
+
+ m68k_get_vbr( interrupt_table );
+#if ( M68K_HAS_VBR == 1 )
+ *old_handler = interrupt_table[ vector ];
+ interrupt_table[ vector ] = new_handler;
+#else
+
+ /*
+ * Install handler into RTEMS jump table and if VBR table is in
+ * RAM, install the pointer to the appropriate jump table slot.
+ * If the VBR table is in ROM, it is the BSP's responsibility to
+ * load it appropriately to vector to the RTEMS jump table.
+ */
+
+ *old_handler = (proc_ptr) _CPU_ISR_jump_table[vector].isr_handler;
+ _CPU_ISR_jump_table[vector].isr_handler = (uint32_t) new_handler;
+ if ( (uint32_t) interrupt_table != 0xFFFFFFFF )
+ interrupt_table[ vector ] = (proc_ptr) &_CPU_ISR_jump_table[vector];
+#endif /* M68K_HAS_VBR */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * new_handler - replacement ISR for this vector number
+ * old_handler - former ISR for this vector number
+ *
+ * Output parameters: NONE
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ proc_ptr ignored = 0; /* to avoid warning */
+
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+#if ( M68K_HAS_SEPARATE_STACKS == 1 )
+ void *isp = _CPU_Interrupt_stack_high;
+
+ __asm__ volatile ( "movec %0,%%isp" : "=r" (isp) : "0" (isp) );
+#endif
+}
+
+#if ( M68K_HAS_BFFFO != 1 )
+/*
+ * Returns table for duplication of the BFFFO instruction (16 bits only)
+ */
+const unsigned char _CPU_m68k_BFFFO_table[256] = {
+ 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+#endif
+
+/*PAGE
+ *
+ * The following code context switches the software FPU emulation
+ * code provided with GCC.
+ */
+
+#if (CPU_SOFTWARE_FP == TRUE)
+extern Context_Control_fp _fpCCR;
+
+void _CPU_Context_save_fp (Context_Control_fp **fp_context_ptr)
+{
+ Context_Control_fp *fp;
+
+ fp = *fp_context_ptr;
+
+ *fp = _fpCCR;
+}
+
+void _CPU_Context_restore_fp (Context_Control_fp **fp_context_ptr)
+{
+ Context_Control_fp *fp;
+
+ fp = *fp_context_ptr;
+
+ _fpCCR = *fp;
+}
+#endif
diff --git a/cpukit/score/cpu/m68k/cpu_asm.S b/cpukit/score/cpu/m68k/cpu_asm.S
new file mode 100644
index 0000000000..afc6ad2878
--- /dev/null
+++ b/cpukit/score/cpu/m68k/cpu_asm.S
@@ -0,0 +1,386 @@
+/* cpu_asm.s
+ *
+ * This file contains all assembly code for the MC68020 implementation
+ * of RTEMS.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/percpu.h>
+
+/* void _CPU_Context_switch( run_context, heir_context )
+ *
+ * This routine performs a normal non-FP context.
+ */
+
+ .align 4
+ .global SYM (_CPU_Context_switch)
+
+.set RUNCONTEXT_ARG, 4 | save context argument
+.set HEIRCONTEXT_ARG, 8 | restore context argument
+
+SYM (_CPU_Context_switch):
+ moval a7@(RUNCONTEXT_ARG),a0| a0 = running thread context
+ movw sr,d1 | d1 = status register
+ movml d1-d7/a2-a7,a0@ | save context
+
+ moval a7@(HEIRCONTEXT_ARG),a0| a0 = heir thread context
+
+#if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
+ moveb a0@(13*4),d0 | get context specific DF bit info in d0
+ btstb #4,d0 | test context specific DF bit info
+ beq fpu_on | branch if FPU needs to be switched on
+
+fpu_off: movl _CPU_cacr_shadow,d0 | get content of _CPU_cacr_shadow in d0
+ btstl #4,d0 | test DF bit info in d0
+ bne restore | branch if FPU is already switched off
+ bsetl #4,d0 | set DF bit in d0
+ bra cacr_set | branch to set the new FPU setting in cacr and _CPU_cacr_shadow
+
+fpu_on: movl _CPU_cacr_shadow,d0 | get content of _CPU_cacr_shadow in d1
+ btstl #4,d0 | test context specific DF bit info
+ beq restore | branch if FPU is already switched on
+ bclrl #4,d0 | clear DF bit info in d0
+
+cacr_set: movew sr,d1 | get content of sr in d1
+ oril #0x00000700,d1 | mask d1
+ movew d1,sr | disable all interrupts
+ movl d0,_CPU_cacr_shadow | move _CPU_cacr_shadow to d1
+ movec d0,cacr | enable FPU in cacr
+#endif
+
+
+restore: movml a0@,d1-d7/a2-a7 | restore context
+ movw d1,sr | restore status register
+ rts
+
+ .global SYM (_CPU_Context_Restart_self)
+.set CONTEXT_ARG, 4 | context arg
+
+#if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
+/* XXX _CPU_Context_switch maintains FPU context -- do we have to restore
+ * that, too??
+ */
+#warning "_CPU_Context_Restart_self restoring FPU context not implemented"
+#endif
+SYM(_CPU_Context_Restart_self):
+ moval a7@(CONTEXT_ARG),a0
+ bra restore
+/*
+ * Floating point context save and restore.
+ *
+ * The code for the MC68881 or MC68882 is based upon the code shown on pages
+ * 6-38 of the MC68881/68882 Users Manual (rev 1). CPU_FP_CONTEXT_SIZE is
+ * higher than expected to account for the -1 pushed at end of this sequence.
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE )
+
+.set FPCONTEXT_ARG, 4 | save FP context argument
+
+ .align 4
+ .global SYM (_CPU_Context_save_fp)
+SYM (_CPU_Context_save_fp):
+
+ /* Get context save area pointer argument from the stack */
+ moval a7@(FPCONTEXT_ARG), a1
+ moval a1@, a0
+
+ #if defined( __mcoldfire__ )
+ /* Move MACSR to data register and disable rounding */
+ movel macsr, d0
+ clrl d1
+ movl d1, macsr
+
+ /* Save MACSR and ACC0 */
+ movl acc0, d1
+ moveml d0-d1, a0@(0)
+
+ /* Save ACC1 and ACC2 */
+ movl acc1, d0
+ movl acc2, d1
+ moveml d0-d1, a0@(8)
+
+ /* Save ACC3 and ACCEXT01 */
+ movl acc3, d0
+ movl accext01, d1
+ moveml d0-d1, a0@(16)
+
+ /* Save ACCEXT23 and MASK */
+ movl accext23, d0
+ movl mask, d1
+ moveml d0-d1, a0@(24)
+
+ #if ( M68K_HAS_FPU == 1 )
+ /* Save FP state */
+ fsave a0@(32)
+
+ /* Save FP instruction address */
+ fmovel fpi, a0@(48)
+
+ /* Save FP data */
+ fmovem fp0-fp7, a0@(52)
+ #endif
+ #else
+ #if defined( __mc68060__ )
+ lea a0@(-M68K_FP_STATE_SIZE), a0
+ fsave a0@ | save 68060 state frame
+ #else
+ fsave a0@- | save 68881/68882 state frame
+ #endif
+ tstb a0@ | check for a null frame
+ beq.b nosv | Yes, skip save of user model
+ fmovem fp0-fp7, a0@- | save data registers (fp0-fp7)
+ fmovem fpc/fps/fpi, a0@- | and save control registers
+ movl #-1, a0@- | place not-null flag on stack
+nosv:
+ movl a0, a1@ | save pointer to saved context
+ #endif
+
+ /* Return */
+ rts
+
+ .align 4
+ .global SYM (_CPU_Context_restore_fp)
+SYM (_CPU_Context_restore_fp):
+
+ /* Get context save area pointer argument from the stack */
+ moval a7@(FPCONTEXT_ARG), a1
+ moval a1@, a0
+
+ #if defined( __mcoldfire__ )
+ #if ( M68K_HAS_FPU == 1 )
+ /* Restore FP data */
+ fmovem a0@(52), fp0-fp7
+
+ /* Restore FP instruction address */
+ fmovel a0@(48), fpi
+
+ /* Restore FP state */
+ frestore a0@(32)
+ #endif
+
+ /* Disable rounding */
+ clrl d0
+ movl d0, macsr
+
+ /* Restore MASK and ACCEXT23 */
+ moveml a0@(24), d0-d1
+ movl d0, mask
+ movl d1, accext23
+
+ /* Restore ACCEXT01 and ACC3 */
+ moveml a0@(16), d0-d1
+ movl d0, accext01
+ movl d1, acc3
+
+ /* Restore ACC2 and ACC1 */
+ moveml a0@(8), d0-d1
+ movl d0, acc2
+ movl d1, acc1
+
+ /* Restore ACC0 and MACSR */
+ moveml a0@(0), d0-d1
+ movl d0, acc0
+ movl d1, macsr
+ #else
+ tstb a0@ | Null context frame?
+ beq.b norst | Yes, skip fp restore
+ addql #4, a0 | throwaway non-null flag
+ fmovem a0@+, fpc/fps/fpi | restore control registers
+ fmovem a0@+, fp0-fp7 | restore data regs (fp0-fp7)
+norst:
+ #if defined( __mc68060__ )
+ frestore a0@ | restore 68060 state frame
+ lea a0@(M68K_FP_STATE_SIZE), a0
+ #else
+ frestore a0@+ | restore 68881/68882 state frame
+ #endif
+ movl a0, a1@ | save pointer to saved context
+ #endif
+
+ /* Return */
+ rts
+#endif
+
+/*PAGE
+ * void _ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * NOTE:
+ * Upon entry, the master stack will contain an interrupt stack frame
+ * back to the interrupted thread and the interrupt stack will contain
+ * a throwaway interrupt stack frame. If dispatching is enabled, and this
+ * is the outer most interrupt, and a context switch is necessary or
+ * the current thread has pending signals, then set up the master stack to
+ * transfer control to the interrupt dispatcher.
+ */
+
+#if ( defined(__mcoldfire__) )
+.set SR_OFFSET, 2 | Status register offset
+.set PC_OFFSET, 4 | Program Counter offset
+.set FVO_OFFSET, 0 | Format/vector offset
+#elif ( M68K_HAS_VBR == 1)
+.set SR_OFFSET, 0 | Status register offset
+.set PC_OFFSET, 2 | Program Counter offset
+.set FVO_OFFSET, 6 | Format/vector offset
+#else
+.set SR_OFFSET, 2 | Status register offset
+.set PC_OFFSET, 4 | Program Counter offset
+.set FVO_OFFSET, 0 | Format/vector offset placed in the stack
+#endif /* M68K_HAS_VBR */
+
+.set SAVED, 16 | space for saved registers
+
+ .align 4
+ .global SYM (_ISR_Handler)
+
+SYM (_ISR_Handler):
+ | disable multitasking
+ addql #1,SYM (_Thread_Dispatch_disable_level)
+#if ( !defined(__mcoldfire__) )
+ moveml d0-d1/a0-a1,a7@- | save d0-d1,a0-a1
+#else
+ lea a7@(-SAVED),a7
+ movm.l d0-d1/a0-a1,a7@ | save d0-d1,a0-a1
+#endif
+ movew a7@(SAVED+FVO_OFFSET),d0 | d0 = F/VO
+ andl #0x03fc,d0 | d0 = vector offset in vbr
+
+
+#if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 )
+ | Make a0 point just above interrupt stack
+ movel INTERRUPT_STACK_HIGH,a0
+ cmpl INTERRUPT_STACK_LOW,a7 | stack below interrupt stack?
+ bcs.b 1f | yes, switch to interrupt stack
+ cmpl a0,a7 | stack above interrupt stack?
+ bcs.b 2f | no, do not switch stacks
+1:
+ movel a7,a1 | copy task stack pointer
+ movel a0,a7 | switch to interrupt stack
+ movel a1,a7@- | store task stack pointer
+ | on interrupt stack
+2:
+#endif /* CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 */
+
+ addql #1,ISR_NEST_LEVEL | one nest level deeper
+
+ movel SYM (_ISR_Vector_table),a0 | a0= base of RTEMS table
+#if ( M68K_HAS_PREINDEXING == 1 )
+ movel (a0,d0:w:1),a0 | a0 = address of user routine
+#else
+ addal d0,a0 | a0 = address of vector
+ movel (a0),a0 | a0 = address of user routine
+#endif
+
+ lsrl #2,d0 | d0 = vector number
+ movel d0,a7@- | push vector number
+ jbsr a0@ | invoke the user ISR
+ addql #4,a7 | remove vector number
+ subql #1,ISR_NEST_LEVEL | Reduce interrupt-nesting count
+
+#if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 )
+ movel INTERRUPT_STACK_HIGH,a0
+ subql #4,a0
+ cmpl a0,a7 | At top of interrupt stack?
+ bne.b 1f | No, do not restore task stack pointer
+ movel (a7),a7 | Restore task stack pointer
+1:
+#endif /* CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 */
+ subql #1,SYM (_Thread_Dispatch_disable_level)
+ | unnest multitasking
+ bne.b exit | If dispatch disabled, exit
+
+#if ( M68K_HAS_SEPARATE_STACKS == 1 )
+ movew #0xf000,d0 | isolate format nibble
+ andw a7@(SAVED+FVO_OFFSET),d0 | get F/VO
+ cmpiw #0x1000,d0 | is it a throwaway isf?
+ bne.b exit | NOT outer level, so branch
+#else
+/*
+ * If we have a CPU which allows a higher-priority interrupt to preempt a
+ * lower priority handler before the lower-priority handler can increment
+ * _Thread_Dispatch_disable_level then we must check the PC on the stack to
+ * see if it is _ISR_Handler. If it is we have the case of nesting interrupts
+ * without the dispatch level being incremented.
+ */
+ #if ( !defined(__mcoldfire__) && !__mc68060__ )
+ cmpl #_ISR_Handler,a7@(SAVED+PC_OFFSET)
+ beq.b exit
+ #endif
+#endif
+ tstb DISPATCH_NEEDED
+ | Is thread switch necessary?
+ beq.b exit | No, then exit
+
+bframe:
+ | If sent, will be processed
+#if ( M68K_HAS_SEPARATE_STACKS == 1 )
+ movec msp,a0 | a0 = master stack pointer
+ movew #0,a0@- | push format word
+ movel #SYM(_ISR_Dispatch),a0@- | push return addr
+ movew a0@(6),a0@- | push saved sr
+ movec a0,msp | set master stack pointer
+#else
+ jsr SYM (_Thread_Dispatch) | Perform context switch
+#endif
+
+#if ( !defined(__mcoldfire__) )
+exit: moveml a7@+,d0-d1/a0-a1 | restore d0-d1,a0-a1
+#else
+exit: moveml a7@,d0-d1/a0-a1 | restore d0-d1,a0-a1
+ lea a7@(SAVED),a7
+#endif
+
+#if ( M68K_HAS_VBR == 0 )
+ addql #2,a7 | pop format/id
+#endif /* M68K_HAS_VBR */
+ rte | return to thread
+ | OR _Isr_dispatch
+
+/*PAGE
+ * void _ISR_Dispatch()
+ *
+ * Entry point from the outermost interrupt service routine exit.
+ * The current stack is the supervisor mode stack if this processor
+ * has separate stacks.
+ *
+ * 1. save all registers not preserved across C calls.
+ * 2. invoke the _Thread_Dispatch routine to switch tasks
+ * or a signal to the currently executing task.
+ * 3. restore all registers not preserved across C calls.
+ * 4. return from interrupt
+ */
+
+ .global SYM (_ISR_Dispatch)
+SYM (_ISR_Dispatch):
+#if ( !defined(__mcoldfire__) )
+ movml d0-d1/a0-a1,a7@-
+ jsr SYM (_Thread_Dispatch)
+ movml a7@+,d0-d1/a0-a1
+#else
+ lea a7@(-SAVED),a7
+ movml d0-d1/a0-a1,a7@
+ jsr SYM (_Thread_Dispatch)
+ movml a7@,d0-d1/a0-a1
+ lea a7@(SAVED),a7
+#endif
+
+#if ( M68K_HAS_VBR == 0 )
+ addql #2,a7 | pop format/id
+#endif /* M68K_HAS_VBR */
+ rte
diff --git a/cpukit/score/cpu/m68k/preinstall.am b/cpukit/score/cpu/m68k/preinstall.am
new file mode 100644
index 0000000000..a5febe7203
--- /dev/null
+++ b/cpukit/score/cpu/m68k/preinstall.am
@@ -0,0 +1,62 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/m68k
+ @: > $(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/m68k/m68302.h: rtems/m68k/m68302.h $(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/m68k/m68302.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/m68k/m68302.h
+
+$(PROJECT_INCLUDE)/rtems/m68k/m68360.h: rtems/m68k/m68360.h $(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/m68k/m68360.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/m68k/m68360.h
+
+$(PROJECT_INCLUDE)/rtems/m68k/qsm.h: rtems/m68k/qsm.h $(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/m68k/qsm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/m68k/qsm.h
+
+$(PROJECT_INCLUDE)/rtems/m68k/sim.h: rtems/m68k/sim.h $(PROJECT_INCLUDE)/rtems/m68k/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/m68k/sim.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/m68k/sim.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/m68k.h: rtems/score/m68k.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/m68k.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/m68k.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/m68k/rtems/asm.h b/cpukit/score/cpu/m68k/rtems/asm.h
new file mode 100644
index 0000000000..851093480e
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/asm.h
@@ -0,0 +1,151 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/cpu.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT0 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT0 (__REGISTER_PREFIX__, x)
+
+#define d0 REG (d0)
+#define d1 REG (d1)
+#define d2 REG (d2)
+#define d3 REG (d3)
+#define d4 REG (d4)
+#define d5 REG (d5)
+#define d6 REG (d6)
+#define d7 REG (d7)
+#define a0 REG (a0)
+#define a1 REG (a1)
+#define a2 REG (a2)
+#define a3 REG (a3)
+#define a4 REG (a4)
+#define a5 REG (a5)
+#define a6 REG (a6)
+#define a7 REG (a7)
+#define sp REG (sp)
+
+#define msp REG (msp)
+#define usp REG (usp)
+#define isp REG (isp)
+#define sr REG (sr)
+#define vbr REG (vbr)
+#define dfc REG (dfc)
+#define sfc REG (sfc)
+
+/* mcf52xx special regs */
+#define cacr REG (cacr)
+#define acr0 REG (acr0)
+#define acr1 REG (acr1)
+#define rambar0 REG (rambar0)
+#define mbar REG (mbar)
+
+/* additional v4e special regs */
+#define rambar1 REG (rambar1)
+#define macsr REG (macsr)
+#define acc0 REG (acc0)
+#define acc1 REG (acc1)
+#define acc2 REG (acc2)
+#define acc3 REG (acc3)
+#define accext01 REG (accext01)
+#define accext23 REG (accext23)
+#define mask REG (mask)
+
+
+#define fp0 REG (fp0)
+#define fp1 REG (fp1)
+#define fp2 REG (fp2)
+#define fp3 REG (fp3)
+#define fp4 REG (fp4)
+#define fp5 REG (fp5)
+#define fp6 REG (fp6)
+#define fp7 REG (fp7)
+
+#define fpc REG (fpc)
+#define fpi REG (fpi)
+#define fps REG (fps)
+#define fpsr REG (fpsr)
+
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA .data
+#define END_DATA
+#define BEGIN_BSS .bss
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/m68k/rtems/m68k/m68302.h b/cpukit/score/cpu/m68k/rtems/m68k/m68302.h
new file mode 100644
index 0000000000..58abf1bdfc
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/m68k/m68302.h
@@ -0,0 +1,660 @@
+/*
+ *------------------------------------------------------------------
+ *
+ * m68302.h - Definitions for Motorola MC68302 processor.
+ *
+ * Section references in this file refer to revision 2 of Motorola's
+ * "MC68302 Integrated Multiprotocol Processor User's Manual".
+ * (Motorola document MC68302UM/AD REV 2.)
+ *
+ * Based on Don Meyer's cpu68302.h that was posted in comp.sys.m68k
+ * on 17 February, 1993.
+ *
+ * COPYRIGHT 1995 David W. Glessner.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the following conditions are met:
+ * 1. Redistribution of source code and documentation must retain
+ * the above copyright notice, this list of conditions and the
+ * following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * This software is provided "AS IS" without warranty of any kind,
+ * either expressed or implied, including, but not limited to, the
+ * implied warranties of merchantability, title and fitness for a
+ * particular purpose.
+ *
+ *
+ * $Id$
+ *
+ *------------------------------------------------------------------
+ */
+
+#ifndef _RTEMS_M68K_M68302_H
+#define _RTEMS_M68K_M68302_H
+
+/*
+ * BAR - Base Address Register
+ * Section 2.7
+ */
+#define M302_BAR (*((volatile uint16_t *) 0xf2))
+
+/*
+ * SCR - System Control Register
+ * Section 3.8.1
+ */
+#define M302_SCR (*((volatile uint32_t *) 0xf4))
+/*
+ * SCR bits
+ */
+#define RBIT_SCR_IPA 0x08000000
+#define RBIT_SCR_HWT 0x04000000
+#define RBIT_SCR_WPV 0x02000000
+#define RBIT_SCR_ADC 0x01000000
+
+#define RBIT_SCR_ERRE 0x00400000
+#define RBIT_SCR_VGE 0x00200000
+#define RBIT_SCR_WPVE 0x00100000
+#define RBIT_SCR_RMCST 0x00080000
+#define RBIT_SCR_EMWS 0x00040000
+#define RBIT_SCR_ADCE 0x00020000
+#define RBIT_SCR_BCLM 0x00010000
+
+#define RBIT_SCR_FRZW 0x00008000
+#define RBIT_SCR_FRZ2 0x00004000
+#define RBIT_SCR_FRZ1 0x00002000
+#define RBIT_SCR_SAM 0x00001000
+#define RBIT_SCR_HWDEN 0x00000800
+#define RBIT_SCR_HWDCN2 0x00000400
+#define RBIT_SCR_HWDCN1 0x00000200 /* 512 clocks */
+#define RBIT_SCR_HWDCN0 0x00000100 /* 128 clocks */
+
+#define RBIT_SCR_LPREC 0x00000080
+#define RBIT_SCR_LPP16 0x00000040
+#define RBIT_SCR_LPEN 0x00000020
+#define RBIT_SCR_LPCLKDIV 0x0000001f
+
+
+/*
+ * 68000 interrupt and trap vector numbers
+ */
+#define M68K_IVEC_BUS_ERROR 2
+#define M68K_IVEC_ADDRESS_ERROR 3
+#define M68K_IVEC_ILLEGAL_OPCODE 4
+#define M68K_IVEC_ZERO_DIVIDE 5
+#define M68K_IVEC_CHK 6
+#define M68K_IVEC_TRAPV 7
+#define M68K_IVEC_PRIVILEGE 8
+#define M68K_IVEC_TRACE 9
+#define M68K_IVEC_LINE_A 10
+#define M68K_IVEC_LINE_F 11
+/* Unassigned, Reserved 12-14 */
+#define M68K_IVEC_UNINITIALIZED_INT 15
+/* Unassigned, Reserved 16-23 */
+#define M68K_IVEC_SPURIOUS_INT 24
+
+#define M68K_IVEC_LEVEL1_AUTOVECTOR 25
+#define M68K_IVEC_LEVEL2_AUTOVECTOR 26
+#define M68K_IVEC_LEVEL3_AUTOVECTOR 27
+#define M68K_IVEC_LEVEL4_AUTOVECTOR 28
+#define M68K_IVEC_LEVEL5_AUTOVECTOR 29
+#define M68K_IVEC_LEVEL6_AUTOVECTOR 30
+#define M68K_IVEC_LEVEL7_AUTOVECTOR 31
+
+#define M68K_IVEC_TRAP0 32
+#define M68K_IVEC_TRAP1 33
+#define M68K_IVEC_TRAP2 34
+#define M68K_IVEC_TRAP3 35
+#define M68K_IVEC_TRAP4 36
+#define M68K_IVEC_TRAP5 37
+#define M68K_IVEC_TRAP6 38
+#define M68K_IVEC_TRAP7 39
+#define M68K_IVEC_TRAP8 40
+#define M68K_IVEC_TRAP9 41
+#define M68K_IVEC_TRAP10 42
+#define M68K_IVEC_TRAP11 43
+#define M68K_IVEC_TRAP12 44
+#define M68K_IVEC_TRAP13 45
+#define M68K_IVEC_TRAP14 46
+#define M68K_IVEC_TRAP15 47
+/*
+ * Unassigned, Reserved 48-59
+ *
+ * Note: Vectors 60-63 are used by the MC68302 (e.g. BAR, SCR).
+ */
+
+/*
+ * MC68302 Interrupt Vectors
+ * Section 3.2
+ */
+enum m68302_ivec_e {
+ M302_IVEC_ERR =0,
+ M302_IVEC_PB8 =1, /* General-Purpose Interrupt 0 */
+ M302_IVEC_SMC2 =2,
+ M302_IVEC_SMC1 =3,
+ M302_IVEC_TIMER3 =4,
+ M302_IVEC_SCP =5,
+ M302_IVEC_TIMER2 =6,
+ M302_IVEC_PB9 =7, /* General-Purpose Interrupt 1 */
+ M302_IVEC_SCC3 =8,
+ M302_IVEC_TIMER1 =9,
+ M302_IVEC_SCC2 =10,
+ M302_IVEC_IDMA =11,
+ M302_IVEC_SDMA =12, /* SDMA Channels Bus Error */
+ M302_IVEC_SCC1 =13,
+ M302_IVEC_PB10 =14, /* General-Purpose Interrupt 2 */
+ M302_IVEC_PB11 =15, /* General-Purpose Interrupt 3 */
+ M302_IVEC_IRQ1 =17, /* External Device */
+ M302_IVEC_IRQ6 =22, /* External Device */
+ M302_IVEC_IRQ7 =23 /* External Device */
+};
+
+
+/*
+ * GIMR - Global Interrupt Mode Register
+ * Section 3.2.5.1
+ */
+#define RBIT_GIMR_MOD (1<<15)
+#define RBIT_GIMR_IV7 (1<<14)
+#define RBIT_GIMR_IV6 (1<<13)
+#define RBIT_GIMR_IV1 (1<<12)
+#define RBIT_GIMR_ET7 (1<<10)
+#define RBIT_GIMR_ET6 (1<<9)
+#define RBIT_GIMR_ET1 (1<<8)
+#define RBIT_GIMR_VECTOR (7<<5)
+
+/*
+ * IPR - Interrupt Pending Register (Section 3.2.5.2)
+ * IMR - Interrupt Mask Register (Section 3.2.5.3)
+ * ISR - Interrupt In-Service Register (Section 3.2.5.4)
+ */
+#define RBIT_IPR_PB11 (1<<15)
+#define RBIT_IPR_PB10 (1<<14)
+#define RBIT_IPR_SCC1 (1<<13)
+#define RBIT_IPR_SDMA (1<<12)
+#define RBIT_IPR_IDMA (1<<11)
+#define RBIT_IPR_SCC2 (1<<10)
+#define RBIT_IPR_TIMER1 (1<<9)
+#define RBIT_IPR_SCC3 (1<<8)
+#define RBIT_IPR_PB9 (1<<7)
+#define RBIT_IPR_TIMER2 (1<<6)
+#define RBIT_IPR_SCP (1<<5)
+#define RBIT_IPR_TIMER3 (1<<4)
+#define RBIT_IPR_SMC1 (1<<3)
+#define RBIT_IPR_SMC2 (1<<2)
+#define RBIT_IPR_PB8 (1<<1)
+#define RBIT_IPR_ERR (1<<0)
+
+#define RBIT_ISR_PB11 (1<<15)
+#define RBIT_ISR_PB10 (1<<14)
+#define RBIT_ISR_SCC1 (1<<13)
+#define RBIT_ISR_SDMA (1<<12)
+#define RBIT_ISR_IDMA (1<<11)
+#define RBIT_ISR_SCC2 (1<<10)
+#define RBIT_ISR_TIMER1 (1<<9)
+#define RBIT_ISR_SCC3 (1<<8)
+#define RBIT_ISR_PB9 (1<<7)
+#define RBIT_ISR_TIMER2 (1<<6)
+#define RBIT_ISR_SCP (1<<5)
+#define RBIT_ISR_TIMER3 (1<<4)
+#define RBIT_ISR_SMC1 (1<<3)
+#define RBIT_ISR_SMC2 (1<<2)
+#define RBIT_ISR_PB8 (1<<1)
+
+#define RBIT_IMR_PB11 (1<<15) /* PB11 Interrupt Mask */
+#define RBIT_IMR_PB10 (1<<14) /* PB10 Interrupt Mask */
+#define RBIT_IMR_SCC1 (1<<13) /* SCC1 Interrupt Mask */
+#define RBIT_IMR_SDMA (1<<12) /* SDMA Interrupt Mask */
+#define RBIT_IMR_IDMA (1<<11) /* IDMA Interrupt Mask */
+#define RBIT_IMR_SCC2 (1<<10) /* SCC2 Interrupt Mask */
+#define RBIT_IMR_TIMER1 (1<<9) /* TIMER1 Interrupt Mask */
+#define RBIT_IMR_SCC3 (1<<8) /* SCC3 Interrupt Mask */
+#define RBIT_IMR_PB9 (1<<7) /* PB9 Interrupt Mask */
+#define RBIT_IMR_TIMER2 (1<<6) /* TIMER2 Interrupt Mask */
+#define RBIT_IMR_SCP (1<<5) /* SCP Interrupt Mask */
+#define RBIT_IMR_TIMER3 (1<<4) /* TIMER3 Interrupt Mask */
+#define RBIT_IMR_SMC1 (1<<3) /* SMC1 Interrupt Mask */
+#define RBIT_IMR_SMC2 (1<<2) /* SMC2 Interrupt Mask */
+#define RBIT_IMR_PB8 (1<<1) /* PB8 Interrupt Mask */
+
+
+/*
+ * DRAM Refresh
+ * Section 3.9
+ *
+ * The DRAM refresh memory map replaces the SCC2 Tx BD 6 and Tx BD 7
+ * structures in the parameter RAM.
+ *
+ * Access to the DRAM registers can be accomplished by
+ * the following approach:
+ *
+ * volatile m302_DRAM_refresh_t *dram;
+ * dram = (volatile m302_DRAM_refresh_t *) &m302.scc2.bd.tx[6];
+ *
+ * Then simply use pointer references (e.g. dram->count = 3).
+ */
+typedef struct {
+ uint16_t dram_high; /* DRAM high address and FC */
+ uint16_t dram_low; /* DRAM low address */
+ uint16_t increment; /* increment step (bytes/row) */
+ uint16_t count; /* RAM refresh cycle count (#rows) */
+ uint16_t t_ptr_h; /* temporary refresh high addr & FC */
+ uint16_t t_ptr_l; /* temporary refresh low address */
+ uint16_t t_count; /* temporary refresh cycles count */
+ uint16_t res; /* reserved */
+} m302_DRAM_refresh_t;
+
+
+/*
+ * TMR - Timer Mode Register (for timers 1 and 2)
+ * Section 3.5.2.1
+ */
+#define RBIT_TMR_ICLK_STOP (0<<1)
+#define RBIT_TMR_ICLK_MASTER (1<<1)
+#define RBIT_TMR_ICLK_MASTER16 (2<<1)
+#define RBIT_TMR_ICLK_TIN (3<<1)
+
+#define RBIT_TMR_OM (1<<5)
+#define RBIT_TMR_ORI (1<<4)
+#define RBIT_TMR_FRR (1<<3)
+#define RBIT_TMR_RST (1<<0)
+
+
+/*
+ * TER - Timer Event Register (for timers 1 and 2)
+ * Section 3.5.2.5
+ */
+#define RBIT_TER_REF (1<<1) /* Output Reference Event */
+#define RBIT_TER_CAP (1<<0) /* Capture Event */
+
+
+/*
+ * SCC Buffer Descriptors and Buffer Descriptors Table
+ * Section 4.5.5
+ */
+typedef struct m302_SCC_bd {
+ uint16_t status; /* status and control */
+ uint16_t length; /* data length */
+ volatile uint8_t *buffer; /* data buffer pointer */
+} m302_SCC_bd_t;
+
+typedef struct {
+ m302_SCC_bd_t rx[8]; /* receive buffer descriptors */
+ m302_SCC_bd_t tx[8]; /* transmit buffer descriptors */
+} m302_SCC_bd_table_t;
+
+
+/*
+ * SCC Parameter RAM (offset 0x080 from an SCC Base)
+ * Section 4.5.6
+ *
+ * Each SCC parameter RAM area begins at offset 0x80 from each SCC base
+ * area (0x400, 0x500, or 0x600 from the dual-port RAM base).
+ *
+ * Offsets 0x9c-0xbf from each SCC base area compose the protocol-specific
+ * portion of the SCC parameter RAM.
+ */
+typedef struct {
+ uint8_t rfcr; /* Rx Function Code */
+ uint8_t tfcr; /* Tx Function Code */
+ uint16_t mrblr; /* Maximum Rx Buffer Length */
+ uint16_t _rstate; /* Rx Internal State */
+ uint8_t res2;
+ uint8_t rbd; /* Rx Internal Buffer Number */
+ uint32_t _rdptr; /* Rx Internal Data Pointer */
+ uint16_t _rcount; /* Rx Internal Byte Count */
+ uint16_t _rtmp; /* Rx Temp */
+ uint16_t _tstate; /* Tx Internal State */
+ uint8_t res7;
+ uint8_t tbd; /* Tx Internal Buffer Number */
+ uint32_t _tdptr; /* Tx Internal Data Pointer */
+ uint16_t _tcount; /* Tx Internal Byte Count */
+ uint16_t _ttmp; /* Tx Temp */
+} m302_SCC_parameters_t;
+
+/*
+ * UART-Specific SCC Parameter RAM
+ * Section 4.5.11.3
+ */
+typedef struct {
+ uint16_t max_idl; /* Maximum IDLE Characters (rx) */
+ uint16_t idlc; /* Temporary rx IDLE counter */
+ uint16_t brkcr; /* Break Count Register (tx) */
+ uint16_t parec; /* Receive Parity Error Counter */
+ uint16_t frmec; /* Receive Framing Error Counter */
+ uint16_t nosec; /* Receive Noise Counter */
+ uint16_t brkec; /* Receive Break Condition Counter */
+ uint16_t uaddr1; /* UART ADDRESS Character 1 */
+ uint16_t uaddr2; /* UART ADDRESS Character 2 */
+ uint16_t rccr; /* Receive Control Character Register */
+ uint16_t character[8]; /* Control Characters 1 through 8*/
+} m302_SCC_UartSpecific_t;
+/*
+ * This definition allows for the checking of receive buffers
+ * for errors.
+ */
+
+#define RCV_ERR 0x003F
+
+/*
+ * UART receive buffer descriptor bit definitions.
+ * Section 4.5.11.14
+ */
+#define RBIT_UART_CTRL (1<<11) /* buffer contains a control char */
+#define RBIT_UART_ADDR (1<<10) /* first byte contains an address */
+#define RBIT_UART_MATCH (1<<9) /* indicates which addr char matched */
+#define RBIT_UART_IDLE (1<<8) /* buffer closed due to IDLE sequence */
+#define RBIT_UART_BR (1<<5) /* break sequence was received */
+#define RBIT_UART_FR (1<<4) /* framing error was received */
+#define RBIT_UART_PR (1<<3) /* parity error was received */
+#define RBIT_UART_OV (1<<1) /* receiver overrun occurred */
+#define RBIT_UART_CD (1<<0) /* carrier detect lost */
+#define RBIT_UART_STATUS 0x003B /* all status bits */
+
+/*
+ * UART transmit buffer descriptor bit definitions.
+ * Section 4.5.11.15
+ */
+#define RBIT_UART_CR (1<<11) /* clear-to-send report
+ * this results in two idle bits
+ * between back-to-back frames
+ */
+#define RBIT_UART_A (1<<10) /* buffer contains address characters
+ * only valid in multidrop mode (UM0=1)
+ */
+#define RBIT_UART_PREAMBLE (1<<9) /* send preamble before data */
+#define RBIT_UART_CTS_LOST (1<<0) /* CTS lost */
+
+/*
+ * UART event register
+ * Section 4.5.11.16
+ */
+#define M302_UART_EV_CTS (1<<7) /* CTS status changed */
+#define M302_UART_EV_CD (1<<6) /* carrier detect status changed */
+#define M302_UART_EV_IDL (1<<5) /* IDLE sequence status changed */
+#define M302_UART_EV_BRK (1<<4) /* break character was received */
+#define M302_UART_EV_CCR (1<<3) /* control character received */
+#define M302_UART_EV_TX (1<<1) /* buffer has been transmitted */
+#define M302_UART_EV_RX (1<<0) /* buffer has been received */
+
+
+/*
+ * HDLC-Specific SCC Parameter RAM
+ * Section 4.5.12.3
+ *
+ * c_mask_l should be 0xF0B8 for 16-bit CRC, 0xdebb for 32-bit CRC
+ * c_mask_h is a don't care for 16-bit CRC, 0x20E2 for 32-bit CRC
+ */
+typedef struct {
+ uint16_t rcrc_l; /* Temp Receive CRC Low */
+ uint16_t rcrc_h; /* Temp Receive CRC High */
+ uint16_t c_mask_l; /* CRC Mask Low */
+ uint16_t c_mask_h; /* CRC Mask High */
+ uint16_t tcrc_l; /* Temp Transmit CRC Low */
+ uint16_t tcrc_h; /* Temp Transmit CRC High */
+
+ uint16_t disfc; /* Discard Frame Counter */
+ uint16_t crcec; /* CRC Error Counter */
+ uint16_t abtsc; /* Abort Sequence Counter */
+ uint16_t nmarc; /* Nonmatching Address Received Cntr */
+ uint16_t retrc; /* Frame Retransmission Counter */
+
+ uint16_t mflr; /* Maximum Frame Length Register */
+ uint16_t max_cnt; /* Maximum_Length Counter */
+
+ uint16_t hmask; /* User Defined Frame Address Mask */
+ uint16_t haddr1; /* User Defined Frame Address */
+ uint16_t haddr2; /* " */
+ uint16_t haddr3; /* " */
+ uint16_t haddr4; /* " */
+} m302_SCC_HdlcSpecific_t;
+/*
+ * HDLC receiver buffer descriptor bit definitions
+ * Section 4.5.12.10
+ */
+#define RBIT_HDLC_EMPTY_BIT 0x8000 /* buffer associated with BD is empty */
+#define RBIT_HDLC_LAST_BIT 0x0800 /* buffer is last in a frame */
+#define RBIT_HDLC_FIRST_BIT 0x0400 /* buffer is first in a frame */
+#define RBIT_HDLC_FRAME_LEN 0x0020 /* receiver frame length violation */
+#define RBIT_HDLC_NONOCT_Rx 0x0010 /* received non-octet aligned frame */
+#define RBIT_HDLC_ABORT_SEQ 0x0008 /* received abort sequence */
+#define RBIT_HDLC_CRC_ERROR 0x0004 /* frame contains a CRC error */
+#define RBIT_HDLC_OVERRUN 0x0002 /* receiver overrun occurred */
+#define RBIT_HDLC_CD_LOST 0x0001 /* carrier detect lost */
+
+/*
+ * HDLC transmit buffer descriptor bit definitions
+ * Section 4.5.12.11
+ */
+#define RBIT_HDLC_READY_BIT 0x8000 /* buffer is ready to transmit */
+#define RBIT_HDLC_EXT_BUFFER 0x4000 /* buffer is in external memory */
+#define RBIT_HDLC_WRAP_BIT 0x2000 /* last buffer in bd table, so wrap */
+#define RBIT_HDLC_WAKE_UP 0x1000 /* interrupt when buffer serviced */
+#define RBIT_HDLC_LAST_BIT 0x0800 /* buffer is last in the frame */
+#define RBIT_HDLC_TxCRC_BIT 0x0400 /* transmit a CRC sequence */
+#define RBIT_HDLC_UNDERRUN 0x0002 /* transmitter underrun */
+#define RBIT_HDLC_CTS_LOST 0x0001 /* CTS lost */
+
+/*
+ * HDLC event register bit definitions
+ * Section 4.5.12.12
+ */
+#define RBIT_HDLC_CTS 0x80 /* CTS status changed */
+#define RBIT_HDLC_CD 0x40 /* carrier detect status changed */
+#define RBIT_HDLC_IDL 0x20 /* IDLE sequence status changed */
+#define RBIT_HDLC_TXE 0x10 /* transmit error */
+#define RBIT_HDLC_RXF 0x08 /* received frame */
+#define RBIT_HDLC_BSY 0x04 /* frame rcvd and discarded due to
+ * lack of buffers
+ */
+#define RBIT_HDLC_TXB 0x02 /* buffer has been transmitted */
+#define RBIT_HDLC_RXB 0x01 /* received buffer */
+
+
+
+typedef struct {
+ m302_SCC_bd_table_t bd; /* +000 Buffer Descriptor Table */
+ m302_SCC_parameters_t parm; /* +080 Common Parameter RAM */
+ union { /* +09C Protocol-Specific Parm RAM */
+ m302_SCC_UartSpecific_t uart;
+ m302_SCC_HdlcSpecific_t hdlc;
+ } prot;
+ uint8_t res[0x040]; /* +0C0 reserved, (not implemented) */
+} m302_SCC_t;
+
+
+/*
+ * Common SCC Registers
+ */
+typedef struct {
+ uint16_t res1;
+ uint16_t scon; /* SCC Configuration Register 4.5.2 */
+ uint16_t scm; /* SCC Mode Register 4.5.3 */
+ uint16_t dsr; /* SCC Data Synchronization Register 4.5.4 */
+ uint8_t scce; /* SCC Event Register 4.5.8.1 */
+ uint8_t res2;
+ uint8_t sccm; /* SCC Mask Register 4.5.8.2 */
+ uint8_t res3;
+ uint8_t sccs; /* SCC Status Register 4.5.8.3 */
+ uint8_t res4;
+ uint16_t res5;
+} m302_SCC_Registers_t;
+
+/*
+ * SCON - SCC Configuration Register
+ * Section 4.5.2
+ */
+#define RBIT_SCON_WOMS (1<<15) /* Wired-OR Mode Select (NMSI mode only)
+ * When set, the TXD driver is an
+ * open-drain output */
+#define RBIT_SCON_EXTC (1<<14) /* External Clock Source */
+#define RBIT_SCON_TCS (1<<13) /* Transmit Clock Source */
+#define RBIT_SCON_RCS (1<<12) /* Receive Clock Source */
+
+/*
+ * SCM - SCC Mode Register bit definitions
+ * Section 4.5.3
+ * The parameter-specific mode bits occupy bits 15 through 6.
+ */
+#define RBIT_SCM_ENR (1<<3) /* Enable receiver */
+#define RBIT_SCM_ENT (1<<2) /* Enable transmitter */
+
+
+/*
+ * Internal MC68302 Registers
+ * starts at offset 0x800 from dual-port RAM base
+ * Section 2.8
+ */
+typedef struct {
+ /* offset +800 */
+ uint16_t res0;
+ uint16_t cmr; /* IDMA Channel Mode Register */
+ uint32_t sapr; /* IDMA Source Address Pointer */
+ uint32_t dapr; /* IDMA Destination Address Pointer */
+ uint16_t bcr; /* IDMA Byte Count Register */
+ uint8_t csr; /* IDMA Channel Status Register */
+ uint8_t res1;
+ uint8_t fcr; /* IDMA Function Code Register */
+ uint8_t res2;
+
+ /* offset +812 */
+ uint16_t gimr; /* Global Interrupt Mode Register */
+ uint16_t ipr; /* Interrupt Pending Register */
+ uint16_t imr; /* Interrupt Mask Register */
+ uint16_t isr; /* Interrupt In-Service Register */
+ uint16_t res3;
+ uint16_t res4;
+
+ /* offset +81e */
+ uint16_t pacnt; /* Port A Control Register */
+ uint16_t paddr; /* Port A Data Direction Register */
+ uint16_t padat; /* Port A Data Register */
+ uint16_t pbcnt; /* Port B Control Register */
+ uint16_t pbddr; /* Port B Data Direction Register */
+ uint16_t pbdat; /* Port B Data Register */
+ uint16_t res5;
+
+ /* offset +82c */
+ uint16_t res6;
+ uint16_t res7;
+
+ uint16_t br0; /* Base Register (CS0) */
+ uint16_t or0; /* Option Register (CS0) */
+ uint16_t br1; /* Base Register (CS1) */
+ uint16_t or1; /* Option Register (CS1) */
+ uint16_t br2; /* Base Register (CS2) */
+ uint16_t or2; /* Option Register (CS2) */
+ uint16_t br3; /* Base Register (CS3) */
+ uint16_t or3; /* Option Register (CS3) */
+
+ /* offset +840 */
+ uint16_t tmr1; /* Timer Unit 1 Mode Register */
+ uint16_t trr1; /* Timer Unit 1 Reference Register */
+ uint16_t tcr1; /* Timer Unit 1 Capture Register */
+ uint16_t tcn1; /* Timer Unit 1 Counter */
+ uint8_t res8;
+ uint8_t ter1; /* Timer Unit 1 Event Register */
+ uint16_t wrr; /* Watchdog Reference Register */
+ uint16_t wcn; /* Watchdog Counter */
+ uint16_t res9;
+ uint16_t tmr2; /* Timer Unit 2 Mode Register */
+ uint16_t trr2; /* Timer Unit 2 Reference Register */
+ uint16_t tcr2; /* Timer Unit 2 Capture Register */
+ uint16_t tcn2; /* Timer Unit 2 Counter */
+ uint8_t resa;
+ uint8_t ter2; /* Timer Unit 2 Event Register */
+ uint16_t resb;
+ uint16_t resc;
+ uint16_t resd;
+
+ /* offset +860 */
+ uint8_t cr; /* Command Register */
+ uint8_t rese[0x1f];
+
+ /* offset +880, +890, +8a0 */
+ m302_SCC_Registers_t scc[3]; /* SCC1, SCC2, SCC3 Registers */
+
+ /* offset +8b0 */
+ uint16_t spmode; /* SCP,SMC Mode and Clock Cntrl Reg */
+ uint16_t simask; /* Serial Interface Mask Register */
+ uint16_t simode; /* Serial Interface Mode Register */
+} m302_internalReg_t ;
+
+
+/*
+ * MC68302 dual-port RAM structure.
+ * (Includes System RAM, Parameter RAM, and Internal Registers).
+ * Section 2.8
+ */
+typedef struct {
+ uint8_t mem[0x240]; /* +000 User Data Memory */
+ uint8_t res1[0x1c0]; /* +240 reserved, (not implemented) */
+ m302_SCC_t scc1; /* +400 SCC1 */
+ m302_SCC_t scc2; /* +500 SCC2 */
+ m302_SCC_t scc3; /* +600 SCC3 */
+ uint8_t res2[0x100]; /* +700 reserved, (not implemented) */
+ m302_internalReg_t reg; /* +800 68302 Internal Registers */
+} m302_dualPortRAM_t;
+
+/* some useful defines the some of the registers above */
+
+
+/* ----
+ MC68302 Chip Select Registers
+ p3-46 2nd Edition
+
+ */
+#define BR_ENABLED 1
+#define BR_DISABLED 0
+#define BR_FC_NULL 0
+#define BR_READ_ONLY 0
+#define BR_READ_WRITE 2
+#define OR_DTACK_0 0x0000
+#define OR_DTACK_1 0x2000
+#define OR_DTACK_2 0x4000
+#define OR_DTACK_3 0x6000
+#define OR_DTACK_4 0x8000
+#define OR_DTACK_5 0xA000
+#define OR_DTACK_6 0xC000
+#define OR_DTACK_EXT 0xE000
+#define OR_SIZE_64K 0x1FE0
+#define OR_SIZE_128K 0x1FC0
+#define OR_SIZE_256K 0x1F80
+#define OR_SIZE_512K 0x1F00
+#define OR_SIZE_1M 0x1E00
+#define OR_SIZE_2M 0x1C00
+#define OR_MASK_RW 0x0000
+#define OR_NO_MASK_RW 0x0002
+#define OR_MASK_FC 0x0000
+#define OR_NO_MASK_FC 0x0001
+
+#define MAKE_BR(base_address, enable, rw, fc) \
+ ((base_address >> 11) | fc | rw | enable)
+
+#define MAKE_OR(bsize, DtAck, RW_Mask, FC_Mask) \
+ (DtAck | ((~(bsize - 1) & 0x00FFFFFF) >> 11) | FC_Mask | RW_Mask)
+
+#define __REG_CAT(r, n) r ## n
+#define WRITE_BR(csel, base_address, enable, rw, fc) \
+ __REG_CAT(m302.reg.br, csel) = MAKE_BR(base_address, enable, rw, fc)
+#define WRITE_OR(csel, bsize, DtAck, RW_Mask, FC_Mask) \
+ __REG_CAT(m302.reg.or, csel) = MAKE_OR(bsize, DtAck, RW_Mask, FC_Mask)
+
+/* ----
+ MC68302 Watchdog Timer Enable Bit
+
+ */
+#define WATCHDOG_ENABLE (1)
+#define WATCHDOG_TRIGGER() (m302.reg.wrr = 0x10 | WATCHDOG_ENABLE, m302.reg.wcn = 0)
+#define WATCHDOG_TOGGLE() (m302.reg.wcn = WATCHDOG_TIMEOUT_PERIOD)
+#define DISABLE_WATCHDOG() (m302.reg.wrr = 0)
+
+/*
+ * Declare the variable that's used to reference the variables in
+ * the dual-port RAM.
+ */
+extern volatile m302_dualPortRAM_t m302;
+
+#endif
diff --git a/cpukit/score/cpu/m68k/rtems/m68k/m68360.h b/cpukit/score/cpu/m68k/rtems/m68k/m68360.h
new file mode 100644
index 0000000000..006045fdfe
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/m68k/m68360.h
@@ -0,0 +1,896 @@
+/*
+ **************************************************************************
+ **************************************************************************
+ ** **
+ ** MOTOROLA MC68360 QUAD INTEGRATED COMMUNICATIONS CONTROLLER (QUICC) **
+ ** **
+ ** HARDWARE DECLARATIONS **
+ ** **
+ ** **
+ ** Submitted By: **
+ ** **
+ ** W. Eric Norum **
+ ** Saskatchewan Accelerator Laboratory **
+ ** University of Saskatchewan **
+ ** 107 North Road **
+ ** Saskatoon, Saskatchewan, CANADA **
+ ** S7N 5C6 **
+ ** **
+ ** eric@skatter.usask.ca **
+ ** **
+ ** $Id$ **
+ ** **
+ **************************************************************************
+ **************************************************************************
+ */
+
+#ifndef _RTEMS_M68K_M68360_H
+#define _RTEMS_M68K_M68360_H
+
+/*
+ *************************************************************************
+ * REGISTER SUBBLOCKS *
+ *************************************************************************
+ */
+
+/*
+ * Memory controller registers
+ */
+typedef struct m360MEMCRegisters_ {
+ unsigned long br;
+ unsigned long or;
+ unsigned long _pad[2];
+} m360MEMCRegisters_t;
+
+/*
+ * Serial Communications Controller registers
+ */
+typedef struct m360SCCRegisters_ {
+ unsigned long gsmr_l;
+ unsigned long gsmr_h;
+ unsigned short psmr;
+ unsigned short _pad0;
+ unsigned short todr;
+ unsigned short dsr;
+ unsigned short scce;
+ unsigned short _pad1;
+ unsigned short sccm;
+ unsigned char _pad2;
+ unsigned char sccs;
+ unsigned long _pad3[2];
+} m360SCCRegisters_t;
+
+/*
+ * Serial Management Controller registers
+ */
+typedef struct m360SMCRegisters_ {
+ unsigned short _pad0;
+ unsigned short smcmr;
+ unsigned short _pad1;
+ unsigned char smce;
+ unsigned char _pad2;
+ unsigned short _pad3;
+ unsigned char smcm;
+ unsigned char _pad4;
+ unsigned long _pad5;
+} m360SMCRegisters_t;
+
+
+/*
+ *************************************************************************
+ * Miscellaneous Parameters *
+ *************************************************************************
+ */
+typedef struct m360MiscParms_ {
+ unsigned short rev_num;
+ unsigned short _res1;
+ unsigned long _res2;
+ unsigned long _res3;
+} m360MiscParms_t;
+
+/*
+ *************************************************************************
+ * RISC Timers *
+ *************************************************************************
+ */
+typedef struct m360TimerParms_ {
+ unsigned short tm_base;
+ unsigned short _tm_ptr;
+ unsigned short _r_tmr;
+ unsigned short _r_tmv;
+ unsigned long tm_cmd;
+ unsigned long tm_cnt;
+} m360TimerParms_t;
+
+/*
+ * RISC Controller Configuration Register (RCCR)
+ * All other bits in this register are either reserved or
+ * used only with a Motorola-supplied RAM microcode packge.
+ */
+#define M360_RCCR_TIME (1<<15) /* Enable timer */
+#define M360_RCCR_TIMEP(x) ((x)<<8) /* Timer period */
+
+/*
+ * Command register
+ * Set up this register before issuing a M360_CR_OP_SET_TIMER command.
+ */
+#define M360_TM_CMD_V (1<<31) /* Set to enable timer */
+#define M360_TM_CMD_R (1<<30) /* Set for automatic restart */
+#define M360_TM_CMD_TIMER(x) ((x)<<16) /* Select timer */
+#define M360_TM_CMD_PERIOD(x) (x) /* Timer period (16 bits) */
+
+/*
+ *************************************************************************
+ * DMA Controllers *
+ *************************************************************************
+ */
+typedef struct m360IDMAparms_ {
+ unsigned short ibase;
+ unsigned short ibptr;
+ unsigned long _istate;
+ unsigned long _itemp;
+} m360IDMAparms_t;
+
+/*
+ *************************************************************************
+ * Serial Communication Controllers *
+ *************************************************************************
+ */
+typedef struct m360SCCparms_ {
+ unsigned short rbase;
+ unsigned short tbase;
+ unsigned char rfcr;
+ unsigned char tfcr;
+ unsigned short mrblr;
+ unsigned long _rstate;
+ unsigned long _pad0;
+ unsigned short _rbptr;
+ unsigned short _pad1;
+ unsigned long _pad2;
+ unsigned long _tstate;
+ unsigned long _pad3;
+ unsigned short _tbptr;
+ unsigned short _pad4;
+ unsigned long _pad5;
+ unsigned long _rcrc;
+ unsigned long _tcrc;
+ union {
+ struct {
+ unsigned long _res0;
+ unsigned long _res1;
+ unsigned short max_idl;
+ unsigned short _idlc;
+ unsigned short brkcr;
+ unsigned short parec;
+ unsigned short frmec;
+ unsigned short nosec;
+ unsigned short brkec;
+ unsigned short brklen;
+ unsigned short uaddr[2];
+ unsigned short _rtemp;
+ unsigned short toseq;
+ unsigned short character[8];
+ unsigned short rccm;
+ unsigned short rccr;
+ unsigned short rlbc;
+ } uart;
+ struct {
+ unsigned long crc_p;
+ unsigned long crc_c;
+ } transparent;
+
+ } un;
+} m360SCCparms_t;
+
+typedef struct m360SCCENparms_ {
+ unsigned short rbase;
+ unsigned short tbase;
+ unsigned char rfcr;
+ unsigned char tfcr;
+ unsigned short mrblr;
+ unsigned long _rstate;
+ unsigned long _pad0;
+ unsigned short _rbptr;
+ unsigned short _pad1;
+ unsigned long _pad2;
+ unsigned long _tstate;
+ unsigned long _pad3;
+ unsigned short _tbptr;
+ unsigned short _pad4;
+ unsigned long _pad5;
+ unsigned long _rcrc;
+ unsigned long _tcrc;
+ union {
+ struct {
+ unsigned long _res0;
+ unsigned long _res1;
+ unsigned short max_idl;
+ unsigned short _idlc;
+ unsigned short brkcr;
+ unsigned short parec;
+ unsigned short frmec;
+ unsigned short nosec;
+ unsigned short brkec;
+ unsigned short brklen;
+ unsigned short uaddr[2];
+ unsigned short _rtemp;
+ unsigned short toseq;
+ unsigned short character[8];
+ unsigned short rccm;
+ unsigned short rccr;
+ unsigned short rlbc;
+ } uart;
+ struct {
+ unsigned long c_pres;
+ unsigned long c_mask;
+ unsigned long crcec;
+ unsigned long alec;
+ unsigned long disfc;
+ unsigned short pads;
+ unsigned short ret_lim;
+ unsigned short _ret_cnt;
+ unsigned short mflr;
+ unsigned short minflr;
+ unsigned short maxd1;
+ unsigned short maxd2;
+ unsigned short _maxd;
+ unsigned short dma_cnt;
+ unsigned short _max_b;
+ unsigned short gaddr1;
+ unsigned short gaddr2;
+ unsigned short gaddr3;
+ unsigned short gaddr4;
+ unsigned long _tbuf0data0;
+ unsigned long _tbuf0data1;
+ unsigned long _tbuf0rba0;
+ unsigned long _tbuf0crc;
+ unsigned short _tbuf0bcnt;
+ unsigned short paddr_h;
+ unsigned short paddr_m;
+ unsigned short paddr_l;
+ unsigned short p_per;
+ unsigned short _rfbd_ptr;
+ unsigned short _tfbd_ptr;
+ unsigned short _tlbd_ptr;
+ unsigned long _tbuf1data0;
+ unsigned long _tbuf1data1;
+ unsigned long _tbuf1rba0;
+ unsigned long _tbuf1crc;
+ unsigned short _tbuf1bcnt;
+ unsigned short _tx_len;
+ unsigned short iaddr1;
+ unsigned short iaddr2;
+ unsigned short iaddr3;
+ unsigned short iaddr4;
+ unsigned short _boff_cnt;
+ unsigned short taddr_h;
+ unsigned short taddr_m;
+ unsigned short taddr_l;
+ } ethernet;
+ struct {
+ unsigned long crc_p;
+ unsigned long crc_c;
+ } transparent;
+ } un;
+} m360SCCENparms_t;
+
+/*
+ * Receive and transmit function code register bits
+ * These apply to the function code registers of all devices, not just SCC.
+ */
+#define M360_RFCR_MOT (1<<4)
+#define M360_RFCR_DMA_SPACE 0x8
+#define M360_TFCR_MOT (1<<4)
+#define M360_TFCR_DMA_SPACE 0x8
+
+/*
+ *************************************************************************
+ * Serial Management Controllers *
+ *************************************************************************
+ */
+typedef struct m360SMCparms_ {
+ unsigned short rbase;
+ unsigned short tbase;
+ unsigned char rfcr;
+ unsigned char tfcr;
+ unsigned short mrblr;
+ unsigned long _rstate;
+ unsigned long _pad0;
+ unsigned short _rbptr;
+ unsigned short _pad1;
+ unsigned long _pad2;
+ unsigned long _tstate;
+ unsigned long _pad3;
+ unsigned short _tbptr;
+ unsigned short _pad4;
+ unsigned long _pad5;
+ union {
+ struct {
+ unsigned short max_idl;
+ unsigned short _pad0;
+ unsigned short brklen;
+ unsigned short brkec;
+ unsigned short brkcr;
+ unsigned short _r_mask;
+ } uart;
+ struct {
+ unsigned short _pad0[5];
+ } transparent;
+ } un;
+} m360SMCparms_t;
+
+/*
+ * Mode register
+ */
+#define M360_SMCMR_CLEN(x) ((x)<<11) /* Character length */
+#define M360_SMCMR_2STOP (1<<10) /* 2 stop bits */
+#define M360_SMCMR_PARITY (1<<9) /* Enable parity */
+#define M360_SMCMR_EVEN (1<<8) /* Even parity */
+#define M360_SMCMR_SM_GCI (0<<4) /* GCI Mode */
+#define M360_SMCMR_SM_UART (2<<4) /* UART Mode */
+#define M360_SMCMR_SM_TRANSPARENT (3<<4) /* Transparent Mode */
+#define M360_SMCMR_DM_LOOPBACK (1<<2) /* Local loopback mode */
+#define M360_SMCMR_DM_ECHO (2<<2) /* Echo mode */
+#define M360_SMCMR_TEN (1<<1) /* Enable transmitter */
+#define M360_SMCMR_REN (1<<0) /* Enable receiver */
+
+/*
+ * Event and mask registers (SMCE, SMCM)
+ */
+#define M360_SMCE_BRK (1<<4)
+#define M360_SMCE_BSY (1<<2)
+#define M360_SMCE_TX (1<<1)
+#define M360_SMCE_RX (1<<0)
+
+/*
+ *************************************************************************
+ * Serial Peripheral Interface *
+ *************************************************************************
+ */
+typedef struct m360SPIparms_ {
+ unsigned short rbase;
+ unsigned short tbase;
+ unsigned char rfcr;
+ unsigned char tfcr;
+ unsigned short mrblr;
+ unsigned long _rstate;
+ unsigned long _pad0;
+ unsigned short _rbptr;
+ unsigned short _pad1;
+ unsigned long _pad2;
+ unsigned long _tstate;
+ unsigned long _pad3;
+ unsigned short _tbptr;
+ unsigned short _pad4;
+ unsigned long _pad5;
+} m360SPIparms_t;
+
+/*
+ * Mode register (SPMODE)
+ */
+#define M360_SPMODE_LOOP (1<<14) /* Local loopback mode */
+#define M360_SPMODE_CI (1<<13) /* Clock invert */
+#define M360_SPMODE_CP (1<<12) /* Clock phase */
+#define M360_SPMODE_DIV16 (1<<11) /* Divide BRGCLK by 16 */
+#define M360_SPMODE_REV (1<<10) /* Reverse data */
+#define M360_SPMODE_MASTER (1<<9) /* SPI is master */
+#define M360_SPMODE_EN (1<<8) /* Enable SPI */
+#define M360_SPMODE_CLEN(x) ((x)<<4) /* Character length */
+#define M360_SPMODE_PM(x) (x) /* Prescaler modulus */
+
+/*
+ * Mode register (SPCOM)
+ */
+#define M360_SPCOM_STR (1<<7) /* Start transmit */
+
+/*
+ * Event and mask registers (SPIE, SPIM)
+ */
+#define M360_SPIE_MME (1<<5) /* Multi-master error */
+#define M360_SPIE_TXE (1<<4) /* Tx error */
+#define M360_SPIE_BSY (1<<2) /* Busy condition*/
+#define M360_SPIE_TXB (1<<1) /* Tx buffer */
+#define M360_SPIE_RXB (1<<0) /* Rx buffer */
+
+/*
+ *************************************************************************
+ * SDMA (SCC, SMC, SPI) Buffer Descriptors *
+ *************************************************************************
+ */
+typedef struct m360BufferDescriptor_ {
+ unsigned short status;
+ unsigned short length;
+ volatile void *buffer;
+} m360BufferDescriptor_t;
+
+/*
+ * Bits in receive buffer descriptor status word
+ */
+#define M360_BD_EMPTY (1<<15) /* Ethernet, SCC UART, SMC UART, SPI */
+#define M360_BD_WRAP (1<<13) /* Ethernet, SCC UART, SMC UART, SPI */
+#define M360_BD_INTERRUPT (1<<12) /* Ethernet, SCC UART, SMC UART, SPI */
+#define M360_BD_LAST (1<<11) /* Ethernet, SPI */
+#define M360_BD_CONTROL_CHAR (1<<11) /* SCC UART */
+#define M360_BD_FIRST_IN_FRAME (1<<10) /* Ethernet */
+#define M360_BD_ADDRESS (1<<10) /* SCC UART */
+#define M360_BD_CONTINUOUS (1<<9) /* SCC UART, SMC UART, SPI */
+#define M360_BD_MISS (1<<8) /* Ethernet */
+#define M360_BD_IDLE (1<<8) /* SCC UART, SMC UART */
+#define M360_BD_ADDRSS_MATCH (1<<7) /* SCC UART */
+#define M360_BD_LONG (1<<5) /* Ethernet */
+#define M360_BD_BREAK (1<<5) /* SCC UART, SMC UART */
+#define M360_BD_NONALIGNED (1<<4) /* Ethernet */
+#define M360_BD_FRAMING_ERROR (1<<4) /* SCC UART, SMC UART */
+#define M360_BD_SHORT (1<<3) /* Ethernet */
+#define M360_BD_PARITY_ERROR (1<<3) /* SCC UART, SMC UART */
+#define M360_BD_CRC_ERROR (1<<2) /* Ethernet */
+#define M360_BD_OVERRUN (1<<1) /* Ethernet, SCC UART, SMC UART, SPI */
+#define M360_BD_COLLISION (1<<0) /* Ethernet */
+#define M360_BD_CARRIER_LOST (1<<0) /* SCC UART */
+#define M360_BD_MASTER_ERROR (1<<0) /* SPI */
+
+/*
+ * Bits in transmit buffer descriptor status word
+ * Many bits have the same meaning as those in receiver buffer descriptors.
+ */
+#define M360_BD_READY (1<<15) /* Ethernet, SCC UART, SMC UART, SPI */
+#define M360_BD_PAD (1<<14) /* Ethernet */
+#define M360_BD_CTS_REPORT (1<<11) /* SCC UART */
+#define M360_BD_TX_CRC (1<<10) /* Ethernet */
+#define M360_BD_DEFER (1<<9) /* Ethernet */
+#define M360_BD_HEARTBEAT (1<<8) /* Ethernet */
+#define M360_BD_PREAMBLE (1<<8) /* SCC UART, SMC UART */
+#define M360_BD_LATE_COLLISION (1<<7) /* Ethernet */
+#define M360_BD_NO_STOP_BIT (1<<7) /* SCC UART */
+#define M360_BD_RETRY_LIMIT (1<<6) /* Ethernet */
+#define M360_BD_RETRY_COUNT(x) (((x)&0x3C)>>2) /* Ethernet */
+#define M360_BD_UNDERRUN (1<<1) /* Ethernet, SPI */
+#define M360_BD_CARRIER_LOST (1<<0) /* Ethernet */
+#define M360_BD_CTS_LOST (1<<0) /* SCC UART */
+
+/*
+ *************************************************************************
+ * IDMA Buffer Descriptors *
+ *************************************************************************
+ */
+typedef struct m360IDMABufferDescriptor_ {
+ unsigned short status;
+ unsigned short _pad;
+ unsigned long length;
+ void *source;
+ void *destination;
+} m360IDMABufferDescriptor_t;
+
+/*
+ *************************************************************************
+ * RISC Communication Processor Module Command Register (CR) *
+ *************************************************************************
+ */
+#define M360_CR_RST (1<<15) /* Reset communication processor */
+#define M360_CR_OP_INIT_RX_TX (0<<8) /* SCC, SMC UART, SMC GCI, SPI */
+#define M360_CR_OP_INIT_RX (1<<8) /* SCC, SMC UART, SPI */
+#define M360_CR_OP_INIT_TX (2<<8) /* SCC, SMC UART, SPI */
+#define M360_CR_OP_INIT_HUNT (3<<8) /* SCC, SMC UART */
+#define M360_CR_OP_STOP_TX (4<<8) /* SCC, SMC UART */
+#define M360_CR_OP_GR_STOP_TX (5<<8) /* SCC */
+#define M360_CR_OP_INIT_IDMA (5<<8) /* IDMA */
+#define M360_CR_OP_RESTART_TX (6<<8) /* SCC, SMC UART */
+#define M360_CR_OP_CLOSE_RX_BD (7<<8) /* SCC, SMC UART, SPI */
+#define M360_CR_OP_SET_GRP_ADDR (8<<8) /* SCC */
+#define M360_CR_OP_SET_TIMER (8<<8) /* Timer */
+#define M360_CR_OP_GCI_TIMEOUT (9<<8) /* SMC GCI */
+#define M360_CR_OP_RESERT_BCS (10<<8) /* SCC */
+#define M360_CR_OP_GCI_ABORT (10<<8) /* SMC GCI */
+#define M360_CR_CHAN_SCC1 (0<<4) /* Channel selection */
+#define M360_CR_CHAN_SCC2 (4<<4)
+#define M360_CR_CHAN_SPI (5<<4)
+#define M360_CR_CHAN_TIMER (5<<4)
+#define M360_CR_CHAN_SCC3 (8<<4)
+#define M360_CR_CHAN_SMC1 (9<<4)
+#define M360_CR_CHAN_IDMA1 (9<<4)
+#define M360_CR_CHAN_SCC4 (12<<4)
+#define M360_CR_CHAN_SMC2 (13<<4)
+#define M360_CR_CHAN_IDMA2 (13<<4)
+#define M360_CR_FLG (1<<0) /* Command flag */
+
+/*
+ *************************************************************************
+ * System Protection Control Register (SYPCR) *
+ *************************************************************************
+ */
+#define M360_SYPCR_SWE (1<<7) /* Software watchdog enable */
+#define M360_SYPCR_SWRI (1<<6) /* Software watchdog reset select */
+#define M360_SYPCR_SWT1 (1<<5) /* Software watchdog timing bit 1 */
+#define M360_SYPCR_SWT0 (1<<4) /* Software watchdog timing bit 0 */
+#define M360_SYPCR_DBFE (1<<3) /* Double bus fault monitor enable */
+#define M360_SYPCR_BME (1<<2) /* Bus monitor external enable */
+#define M360_SYPCR_BMT1 (1<<1) /* Bus monitor timing bit 1 */
+#define M360_SYPCR_BMT0 (1<<0) /* Bus monitor timing bit 0 */
+
+/*
+ *************************************************************************
+ * Memory Control Registers *
+ *************************************************************************
+ */
+#define M360_GMR_RCNT(x) ((x)<<24) /* Refresh count */
+#define M360_GMR_RFEN (1<<23) /* Refresh enable */
+#define M360_GMR_RCYC(x) ((x)<<21) /* Refresh cycle length */
+#define M360_GMR_PGS(x) ((x)<<18) /* Page size */
+#define M360_GMR_DPS_32BIT (0<<16) /* DRAM port size */
+#define M360_GMR_DPS_16BIT (1<<16)
+#define M360_GMR_DPS_8BIT (2<<16)
+#define M360_GMR_DPS_DSACK (3<<16)
+#define M360_GMR_WBT40 (1<<15) /* Wait between 040 transfers */
+#define M360_GMR_WBTQ (1<<14) /* Wait between 360 transfers */
+#define M360_GMR_SYNC (1<<13) /* Synchronous external access */
+#define M360_GMR_EMWS (1<<12) /* External master wait state */
+#define M360_GMR_OPAR (1<<11) /* Odd parity */
+#define M360_GMR_PBEE (1<<10) /* Parity bus error enable */
+#define M360_GMR_TSS40 (1<<9) /* TS* sample for 040 */
+#define M360_GMR_NCS (1<<8) /* No CPU space */
+#define M360_GMR_DWQ (1<<7) /* Delay write for 360 */
+#define M360_GMR_DW40 (1<<6) /* Delay write for 040 */
+#define M360_GMR_GAMX (1<<5) /* Global address mux enable */
+
+#define M360_MEMC_BR_FC(x) ((x)<<7) /* Function code limit */
+#define M360_MEMC_BR_TRLXQ (1<<6) /* Relax timing requirements */
+#define M360_MEMC_BR_BACK40 (1<<5) /* Burst acknowledge to 040 */
+#define M360_MEMC_BR_CSNT40 (1<<4) /* CS* negate timing for 040 */
+#define M360_MEMC_BR_CSNTQ (1<<3) /* CS* negate timing for 360 */
+#define M360_MEMC_BR_PAREN (1<<2) /* Enable parity checking */
+#define M360_MEMC_BR_WP (1<<1) /* Write Protect */
+#define M360_MEMC_BR_V (1<<0) /* Base/Option register are valid */
+
+#define M360_MEMC_OR_TCYC(x) ((x)<<28) /* Cycle length (clocks) */
+#define M360_MEMC_OR_WAITS(x) M360_MEMC_OR_TCYC((x)+1)
+#define M360_MEMC_OR_2KB 0x0FFFF800 /* Address range */
+#define M360_MEMC_OR_4KB 0x0FFFF000
+#define M360_MEMC_OR_8KB 0x0FFFE000
+#define M360_MEMC_OR_16KB 0x0FFFC000
+#define M360_MEMC_OR_32KB 0x0FFF8000
+#define M360_MEMC_OR_64KB 0x0FFF0000
+#define M360_MEMC_OR_128KB 0x0FFE0000
+#define M360_MEMC_OR_256KB 0x0FFC0000
+#define M360_MEMC_OR_512KB 0x0FF80000
+#define M360_MEMC_OR_1MB 0x0FF00000
+#define M360_MEMC_OR_2MB 0x0FE00000
+#define M360_MEMC_OR_4MB 0x0FC00000
+#define M360_MEMC_OR_8MB 0x0F800000
+#define M360_MEMC_OR_16MB 0x0F000000
+#define M360_MEMC_OR_32MB 0x0E000000
+#define M360_MEMC_OR_64MB 0x0C000000
+#define M360_MEMC_OR_128MB 0x08000000
+#define M360_MEMC_OR_256MB 0x00000000
+#define M360_MEMC_OR_FCMC(x) ((x)<<7) /* Function code mask */
+#define M360_MEMC_OR_BCYC(x) ((x)<<5) /* Burst cycle length (clocks) */
+#define M360_MEMC_OR_PGME (1<<3) /* Page mode enable */
+#define M360_MEMC_OR_32BIT (0<<1) /* Port size */
+#define M360_MEMC_OR_16BIT (1<<1)
+#define M360_MEMC_OR_8BIT (2<<1)
+#define M360_MEMC_OR_DSACK (3<<1)
+#define M360_MEMC_OR_DRAM (1<<0) /* Dynamic RAM select */
+
+/*
+ *************************************************************************
+ * SI Mode Register (SIMODE) *
+ *************************************************************************
+ */
+#define M360_SI_SMC2_BITS 0xFFFF0000 /* All SMC2 bits */
+#define M360_SI_SMC2_TDM (1<<31) /* Multiplexed SMC2 */
+#define M360_SI_SMC2_BRG1 (0<<28) /* SMC2 clock souce */
+#define M360_SI_SMC2_BRG2 (1<<28)
+#define M360_SI_SMC2_BRG3 (2<<28)
+#define M360_SI_SMC2_BRG4 (3<<28)
+#define M360_SI_SMC2_CLK5 (0<<28)
+#define M360_SI_SMC2_CLK6 (1<<28)
+#define M360_SI_SMC2_CLK7 (2<<28)
+#define M360_SI_SMC2_CLK8 (3<<28)
+#define M360_SI_SMC1_BITS 0x0000FFFF /* All SMC1 bits */
+#define M360_SI_SMC1_TDM (1<<15) /* Multiplexed SMC1 */
+#define M360_SI_SMC1_BRG1 (0<<12) /* SMC1 clock souce */
+#define M360_SI_SMC1_BRG2 (1<<12)
+#define M360_SI_SMC1_BRG3 (2<<12)
+#define M360_SI_SMC1_BRG4 (3<<12)
+#define M360_SI_SMC1_CLK1 (0<<12)
+#define M360_SI_SMC1_CLK2 (1<<12)
+#define M360_SI_SMC1_CLK3 (2<<12)
+#define M360_SI_SMC1_CLK4 (3<<12)
+
+/*
+ *************************************************************************
+ * SDMA Configuration Register (SDMA) *
+ *************************************************************************
+ */
+#define M360_SDMA_FREEZE (2<<13) /* Freeze on next bus cycle */
+#define M360_SDMA_SISM_7 (7<<8) /* Normal interrupt service mask */
+#define M360_SDMA_SAID_4 (4<<4) /* Normal arbitration ID */
+#define M360_SDMA_INTE (1<<1) /* SBER interrupt enable */
+#define M360_SDMA_INTB (1<<0) /* SBKP interrupt enable */
+
+/*
+ *************************************************************************
+ * Baud (sic) Rate Generators *
+ *************************************************************************
+ */
+#define M360_BRG_RST (1<<17) /* Reset generator */
+#define M360_BRG_EN (1<<16) /* Enable generator */
+#define M360_BRG_EXTC_BRGCLK (0<<14) /* Source is BRGCLK */
+#define M360_BRG_EXTC_CLK2 (1<<14) /* Source is CLK2 pin */
+#define M360_BRG_EXTC_CLK6 (2<<14) /* Source is CLK6 pin */
+#define M360_BRG_ATB (1<<13) /* Autobaud */
+#define M360_BRG_115200 (13<<1) /* Assume 25 MHz clock */
+#define M360_BRG_57600 (26<<1)
+#define M360_BRG_38400 (40<<1)
+#define M360_BRG_19200 (80<<1)
+#define M360_BRG_9600 (162<<1)
+#define M360_BRG_4800 (324<<1)
+#define M360_BRG_2400 (650<<1)
+#define M360_BRG_1200 (1301<<1)
+#define M360_BRG_600 (2603<<1)
+#define M360_BRG_300 ((324<<1) | 1)
+#define M360_BRG_150 ((650<<1) | 1)
+#define M360_BRG_75 ((1301<<1) | 1)
+
+/*
+ *************************************************************************
+ * MC68360 DUAL-PORT RAM AND REGISTERS *
+ *************************************************************************
+ */
+typedef struct m360_ {
+ /*
+ * Dual-port RAM
+ */
+ unsigned char dpram0[0x400]; /* Microcode program */
+ unsigned char dpram1[0x200];
+ unsigned char dpram2[0x100]; /* Microcode scratch */
+ unsigned char dpram3[0x100]; /* Not on REV A or B masks */
+ unsigned char _rsv0[0xC00-0x800];
+ m360SCCENparms_t scc1p;
+ unsigned char _rsv1[0xCB0-0xC00-sizeof(m360SCCENparms_t)];
+ m360MiscParms_t miscp;
+ unsigned char _rsv2[0xD00-0xCB0-sizeof(m360MiscParms_t)];
+ m360SCCparms_t scc2p;
+ unsigned char _rsv3[0xD80-0xD00-sizeof(m360SCCparms_t)];
+ m360SPIparms_t spip;
+ unsigned char _rsv4[0xDB0-0xD80-sizeof(m360SPIparms_t)];
+ m360TimerParms_t tmp;
+ unsigned char _rsv5[0xE00-0xDB0-sizeof(m360TimerParms_t)];
+ m360SCCparms_t scc3p;
+ unsigned char _rsv6[0xE70-0xE00-sizeof(m360SCCparms_t)];
+ m360IDMAparms_t idma1p;
+ unsigned char _rsv7[0xE80-0xE70-sizeof(m360IDMAparms_t)];
+ m360SMCparms_t smc1p;
+ unsigned char _rsv8[0xF00-0xE80-sizeof(m360SMCparms_t)];
+ m360SCCparms_t scc4p;
+ unsigned char _rsv9[0xF70-0xF00-sizeof(m360SCCparms_t)];
+ m360IDMAparms_t idma2p;
+ unsigned char _rsv10[0xF80-0xF70-sizeof(m360IDMAparms_t)];
+ m360SMCparms_t smc2p;
+ unsigned char _rsv11[0x1000-0xF80-sizeof(m360SMCparms_t)];
+
+ /*
+ * SIM Block
+ */
+ unsigned long mcr;
+ unsigned long _pad00;
+ unsigned char avr;
+ unsigned char rsr;
+ unsigned short _pad01;
+ unsigned char clkocr;
+ unsigned char _pad02;
+ unsigned short _pad03;
+ unsigned short pllcr;
+ unsigned short _pad04;
+ unsigned short cdvcr;
+ unsigned short pepar;
+ unsigned long _pad05[2];
+ unsigned short _pad06;
+ unsigned char sypcr;
+ unsigned char swiv;
+ unsigned short _pad07;
+ unsigned short picr;
+ unsigned short _pad08;
+ unsigned short pitr;
+ unsigned short _pad09;
+ unsigned char _pad10;
+ unsigned char swsr;
+ unsigned long bkar;
+ unsigned long bcar;
+ unsigned long _pad11[2];
+
+ /*
+ * MEMC Block
+ */
+ unsigned long gmr;
+ unsigned short mstat;
+ unsigned short _pad12;
+ unsigned long _pad13[2];
+ m360MEMCRegisters_t memc[8];
+ unsigned char _pad14[0xF0-0xD0];
+ unsigned char _pad15[0x100-0xF0];
+ unsigned char _pad16[0x500-0x100];
+
+ /*
+ * IDMA1 Block
+ */
+ unsigned short iccr;
+ unsigned short _pad17;
+ unsigned short cmr1;
+ unsigned short _pad18;
+ unsigned long sapr1;
+ unsigned long dapr1;
+ unsigned long bcr1;
+ unsigned char fcr1;
+ unsigned char _pad19;
+ unsigned char cmar1;
+ unsigned char _pad20;
+ unsigned char csr1;
+ unsigned char _pad21;
+ unsigned short _pad22;
+
+ /*
+ * SDMA Block
+ */
+ unsigned char sdsr;
+ unsigned char _pad23;
+ unsigned short sdcr;
+ unsigned long sdar;
+
+ /*
+ * IDMA2 Block
+ */
+ unsigned short _pad24;
+ unsigned short cmr2;
+ unsigned long sapr2;
+ unsigned long dapr2;
+ unsigned long bcr2;
+ unsigned char fcr2;
+ unsigned char _pad26;
+ unsigned char cmar2;
+ unsigned char _pad27;
+ unsigned char csr2;
+ unsigned char _pad28;
+ unsigned short _pad29;
+ unsigned long _pad30;
+
+ /*
+ * CPIC Block
+ */
+ unsigned long cicr;
+ unsigned long cipr;
+ unsigned long cimr;
+ unsigned long cisr;
+
+ /*
+ * Parallel I/O Block
+ */
+ unsigned short padir;
+ unsigned short papar;
+ unsigned short paodr;
+ unsigned short padat;
+ unsigned long _pad31[2];
+ unsigned short pcdir;
+ unsigned short pcpar;
+ unsigned short pcso;
+ unsigned short pcdat;
+ unsigned short pcint;
+ unsigned short _pad32;
+ unsigned long _pad33[5];
+
+ /*
+ * TIMER Block
+ */
+ unsigned short tgcr;
+ unsigned short _pad34;
+ unsigned long _pad35[3];
+ unsigned short tmr1;
+ unsigned short tmr2;
+ unsigned short trr1;
+ unsigned short trr2;
+ unsigned short tcr1;
+ unsigned short tcr2;
+ unsigned short tcn1;
+ unsigned short tcn2;
+ unsigned short tmr3;
+ unsigned short tmr4;
+ unsigned short trr3;
+ unsigned short trr4;
+ unsigned short tcr3;
+ unsigned short tcr4;
+ unsigned short tcn3;
+ unsigned short tcn4;
+ unsigned short ter1;
+ unsigned short ter2;
+ unsigned short ter3;
+ unsigned short ter4;
+ unsigned long _pad36[2];
+
+ /*
+ * CP Block
+ */
+ unsigned short cr;
+ unsigned short _pad37;
+ unsigned short rccr;
+ unsigned short _pad38;
+ unsigned long _pad39[3];
+ unsigned short _pad40;
+ unsigned short rter;
+ unsigned short _pad41;
+ unsigned short rtmr;
+ unsigned long _pad42[5];
+
+ /*
+ * BRG Block
+ */
+ unsigned long brgc1;
+ unsigned long brgc2;
+ unsigned long brgc3;
+ unsigned long brgc4;
+
+ /*
+ * SCC Block
+ */
+ m360SCCRegisters_t scc1;
+ m360SCCRegisters_t scc2;
+ m360SCCRegisters_t scc3;
+ m360SCCRegisters_t scc4;
+
+ /*
+ * SMC Block
+ */
+ m360SMCRegisters_t smc1;
+ m360SMCRegisters_t smc2;
+
+ /*
+ * SPI Block
+ */
+ unsigned short spmode;
+ unsigned short _pad43[2];
+ unsigned char spie;
+ unsigned char _pad44;
+ unsigned short _pad45;
+ unsigned char spim;
+ unsigned char _pad46[2];
+ unsigned char spcom;
+ unsigned short _pad47[2];
+
+ /*
+ * PIP Block
+ */
+ unsigned short pipc;
+ unsigned short _pad48;
+ unsigned short ptpr;
+ unsigned long pbdir;
+ unsigned long pbpar;
+ unsigned short _pad49;
+ unsigned short pbodr;
+ unsigned long pbdat;
+ unsigned long _pad50[6];
+
+ /*
+ * SI Block
+ */
+ unsigned long simode;
+ unsigned char sigmr;
+ unsigned char _pad51;
+ unsigned char sistr;
+ unsigned char sicmr;
+ unsigned long _pad52;
+ unsigned long sicr;
+ unsigned short _pad53;
+ unsigned short sirp[2];
+ unsigned short _pad54;
+ unsigned long _pad55[2];
+ unsigned char siram[256];
+} m360_t;
+
+extern volatile m360_t m360;
+
+/*
+ * definitions for the port b SPI pin bits
+ */
+#define M360_PB_SPI_MISO_MSK (1<< 3)
+#define M360_PB_SPI_MOSI_MSK (1<< 2)
+#define M360_PB_SPI_CLK_MSK (1<< 1)
+
+#endif /* _RTEMS_M68K_M68360_H */
diff --git a/cpukit/score/cpu/m68k/rtems/m68k/qsm.h b/cpukit/score/cpu/m68k/rtems/m68k/qsm.h
new file mode 100644
index 0000000000..4ddf2a55ff
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/m68k/qsm.h
@@ -0,0 +1,204 @@
+/*
+ *-------------------------------------------------------------------
+ *
+ * QSM -- Queued Serial Module
+ *
+ * The QSM contains two serial interfaces: (a) the queued serial
+ * peripheral interface (QSPI) and the serial communication interface
+ * (SCI). The QSPI provides peripheral expansion and/or interprocessor
+ * communication through a full-duplex, synchronous, three-wire bus. A
+ * self contained RAM queue permits serial data transfers without CPU
+ * intervention and automatic continuous sampling. The SCI provides a
+ * standard non-return to zero mark/space format with wakeup functions
+ * to allow the CPU to run uninterrupted until woken
+ *
+ * For more information, refer to Motorola's "Modular Microcontroller
+ * Family Queued Serial Module Reference Manual" (Motorola document
+ * QSMRM/AD).
+ *
+ * This file was created by John S. Gwynne to support Motorola's 68332 MCU.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the following conditions are met:
+ * 1. Redistribution of source code and documentation must retain
+ * the above authorship, this list of conditions and the
+ * following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * This software is provided "AS IS" without warranty of any kind,
+ * either expressed or implied, including, but not limited to, the
+ * implied warranties of merchantability, title and fitness for a
+ * particular purpose.
+ *
+ *------------------------------------------------------------------
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_M68K_QSM_H
+#define _RTEMS_M68K_QSM_H
+
+/* SAM-- shift and mask */
+#undef SAM
+#define SAM(a,b,c) ((a << b) & c)
+
+
+/* QSM_CRB (QSM Control Register Block) base address of the QSM
+ control registers */
+#if SIM_MM == 0
+#define QSM_CRB 0x7ffc00
+#else
+#undef SIM_MM
+#define SIM_MM 1
+#define QSM_CRB 0xfffc00
+#endif
+
+
+#define QSMCR (volatile unsigned short int * const)(0x00 + QSM_CRB)
+ /* QSM Configuration Register */
+#define STOP 0x8000 /* Stop Enable */
+#define FRZ 0x6000 /* Freeze Control */
+#define SUPV 0x0080 /* Supervisor/Unrestricted */
+#define IARB 0x000f /* Inerrupt Arbitration */
+
+
+#define QTEST (volatile unsigned short int * const)(0x02 + QSM_CRB)
+ /* QSM Test Register */
+/* Used only for factor testing */
+
+
+#define QILR (volatile unsigned char * const)(0x04 + QSM_CRB)
+ /* QSM Interrupt Level Register */
+#define ILQSPI 0x38 /* Interrupt Level for QSPI */
+#define ILSCI 0x07 /* Interrupt Level for SCI */
+
+
+#define QIVR (volatile unsigned char * const)(0x05 + QSM_CRB)
+ /* QSM Interrupt Vector Register */
+#define INTV 0xff /* Interrupt Vector Number */
+
+
+#define SCCR0 (volatile unsigned short int * const)(0x08 + QSM_CRB)
+ /* SCI Control Register 0 */
+#define SCBR 0x1fff /* SCI Baud Rate */
+
+
+#define SCCR1 (volatile unsigned short int * const)(0x0a + QSM_CRB)
+ /* SCI Control Register 1 */
+#define LOOPS 0x4000 /* Loop Mode */
+#define WOMS 0x2000 /* Wired-OR Mode for SCI Pins */
+#define ILT 0x1000 /* Idle-Line Detect Type */
+#define PT 0x0800 /* Parity Type */
+#define PE 0x0400 /* Parity Enable */
+#define M 0x0200 /* Mode Select */
+#define WAKE 0x0100 /* Wakeup by Address Mark */
+#define TIE 0x0080 /* Transmit Complete Interrupt Enable */
+#define TCIE 0x0040 /* Transmit Complete Interrupt Enable */
+#define RIE 0x0020 /* Receiver Interrupt Enable */
+#define ILIE 0x0010 /* Idle-Line Interrupt Enable */
+#define TE 0x0008 /* Transmitter Enable */
+#define RE 0x0004 /* Receiver Enable */
+#define RWU 0x0002 /* Receiver Wakeup */
+#define SBK 0x0001 /* Send Break */
+
+
+#define SCSR (volatile unsigned short int * const)(0x0c + QSM_CRB)
+ /* SCI Status Register */
+#define TDRE 0x0100 /* Transmit Data Register Empty */
+#define TC 0x0080 /* Transmit Complete */
+#define RDRF 0x0040 /* Receive Data Register Full */
+#define RAF 0x0020 /* Receiver Active */
+#define IDLE 0x0010 /* Idle-Line Detected */
+#define OR 0x0008 /* Overrun Error */
+#define NF 0x0004 /* Noise Error Flag */
+#define FE 0x0002 /* Framing Error */
+#define PF 0x0001 /* Parity Error */
+
+
+#define SCDR (volatile unsigned short int * const)(0x0e + QSM_CRB)
+ /* SCI Data Register */
+
+
+#define PORTQS (volatile unsigned char * const)(0x15 + QSM_CRB)
+ /* Port QS Data Register */
+
+#define PQSPAR (volatile unsigned char * const)(0x16 + QSM_CRB)
+ /* PORT QS Pin Assignment Rgister */
+/* Any bit cleared (zero) defines the corresponding pin to be an I/O
+ pin. Any bit set defines the corresponding pin to be a QSPI
+ signal. */
+/* note: PQS2 is a digital I/O pin unless the SPI is enabled in which
+ case it becomes the SPI serial clock SCK. */
+/* note: PQS7 is a digital I/O pin unless the SCI transmitter is
+ enabled in which case it becomes the SCI serial output TxD. */
+#define QSMFun 0x0
+#define QSMDis 0x1
+/*
+ * PQSPAR Field | QSM Function | Discrete I/O pin
+ *------------------+--------------+------------------ */
+#define PQSPA0 0 /* MISO | PQS0 */
+#define PQSPA1 1 /* MOSI | PQS1 */
+#define PQSPA2 2 /* SCK | PQS2 (see note)*/
+#define PQSPA3 3 /* PCSO/!SS | PQS3 */
+#define PQSPA4 4 /* PCS1 | PQS4 */
+#define PQSPA5 5 /* PCS2 | PQS5 */
+#define PQSPA6 6 /* PCS3 | PQS6 */
+#define PQSPA7 7 /* TxD | PQS7 (see note)*/
+
+
+#define DDRQS (volatile unsigned char * const)(0x17 + QSM_CRB)
+ /* PORT QS Data Direction Register */
+/* Clearing a bit makes the corresponding pin an input; setting a bit
+ makes the pin an output. */
+
+
+#define SPCR0 (volatile unsigned short int * const)(0x18 + QSM_CRB)
+ /* QSPI Control Register 0 */
+#define MSTR 0x8000 /* Master/Slave Mode Select */
+#define WOMQ 0x4000 /* Wired-OR Mode for QSPI Pins */
+#define BITS 0x3c00 /* Bits Per Transfer */
+#define CPOL 0x0200 /* Clock Polarity */
+#define CPHA 0x0100 /* Clock Phase */
+#define SPBR 0x00ff /* Serial Clock Baud Rate */
+
+
+#define SPCR1 (volatile unsigned short int * const)(0x1a + QSM_CRB)
+ /* QSPI Control Register 1 */
+#define SPE 0x8000 /* QSPI Enable */
+#define DSCKL 0x7f00 /* Delay before SCK */
+#define DTL 0x00ff /* Length of Delay after Transfer */
+
+
+#define SPCR2 (volatile unsigned short int * const)(0x1c + QSM_CRB)
+ /* QSPI Control Register 2 */
+#define SPIFIE 0x8000 /* SPI Finished Interrupt Enable */
+#define WREN 0x4000 /* Wrap Enable */
+#define WRTO 0x2000 /* Wrap To */
+#define ENDQP 0x0f00 /* Ending Queue Pointer */
+#define NEWQP 0x000f /* New Queue Pointer Value */
+
+
+#define SPCR3 (volatile unsigned char * const)(0x1e + QSM_CRB)
+ /* QSPI Control Register 3 */
+#define LOOPQ 0x0400 /* QSPI Loop Mode */
+#define HMIE 0x0200 /* HALTA and MODF Interrupt Enable */
+#define HALT 0x0100 /* Halt */
+
+
+#define SPSR (volatile unsigned char * const)(0x1f + QSM_CRB)
+ /* QSPI Status Register */
+#define SPIF 0x0080 /* QSPI Finished Flag */
+#define MODF 0x0040 /* Mode Fault Flag */
+#define HALTA 0x0020 /* Halt Acknowlwdge Flag */
+#define CPTQP x0000f /* Completed Queue Pointer */
+
+#define QSPIRR (volatile unsigned char * const)(0x100 + QSM_CRB)
+ /* QSPI Receive Data RAM */
+#define QSPITR (volatile unsigned char * const)(0x120 + QSM_CRB)
+ /* QSPI Transmit Data RAM */
+#define QSPIcR (volatile unsigned char * const)(0x140 + QSM_CRB)
+ /* QSPI Command RAM */
+
+#endif /* _RTEMS_M68K_QSM_H */
diff --git a/cpukit/score/cpu/m68k/rtems/m68k/sim.h b/cpukit/score/cpu/m68k/rtems/m68k/sim.h
new file mode 100644
index 0000000000..5b60a3cefb
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/m68k/sim.h
@@ -0,0 +1,333 @@
+/*
+ *-------------------------------------------------------------------
+ *
+ * SIM -- System Integration Module
+ *
+ * The system integration module (SIM) is used on many Motorola 16-
+ * and 32-bit MCUs for the following functions:
+ *
+ * () System configuration and protection. Bus and software watchdog
+ * monitors are provided in addition to periodic interrupt generators.
+ *
+ * () Clock signal generation for other intermodule bus (IMB) members
+ * and external devices.
+ *
+ * () The generation of chip-select signals that simplify external
+ * circuitry interface.
+ *
+ * () Data ports that are available for general purpose input and
+ * output.
+ *
+ * () A system test block that is intended only for factory tests.
+ *
+ * For more information, refer to Motorola's "Modular Microcontroller
+ * Family System Integration Module Reference Manual" (Motorola document
+ * SIMRM/AD).
+ *
+ * This file was created by John S. Gwynne to support Motorola's 68332 MCU.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the following conditions are met:
+ * 1. Redistribution of source code and documentation must retain
+ * the above authorship, this list of conditions and the
+ * following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * This software is provided "AS IS" without warranty of any kind,
+ * either expressed or implied, including, but not limited to, the
+ * implied warranties of merchantability, title and fitness for a
+ * particular purpose.
+ *
+ *------------------------------------------------------------------
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_M68K_SIM_H
+#define _RTEMS_M68K_SIM_H
+
+
+/* SAM-- shift and mask */
+#undef SAM
+#define SAM(a,b,c) ((a << b) & c)
+
+/*
+ * These macros make this file usable from assembly.
+ */
+
+#ifdef ASM
+#define SIM_VOLATILE_USHORT_POINTER
+#define SIM_VOLATILE_UCHAR_POINTER
+#else
+#define SIM_VOLATILE_USHORT_POINTER (volatile unsigned short int * const)
+#define SIM_VOLATILE_UCHAR_POINTER (volatile unsigned char * const)
+#endif
+
+/* SIM_CRB (SIM Control Register Block) base address of the SIM
+ control registers */
+#ifndef SIM_CRB
+#if SIM_MM == 0
+#define SIM_CRB 0x7ffa00
+#else /* SIM_MM */
+#undef SIM_MM
+#define SIM_MM 1
+#define SIM_CRB 0xfffa00
+#endif /* SIM_MM */
+#endif /* SIM_CRB */
+
+
+#define SIMCR SIM_VOLATILE_USHORT_POINTER(0x00 + SIM_CRB)
+ /* Module Configuration Register */
+#define EXOFF 0x8000 /* External Clock Off */
+#define FRZSW 0x4000 /* Freeze Software Enable */
+#define FRZBM 0x2000 /* Freeze Bus Monitor Enable */
+#define SLVEN 0x0800 /* Factory Test Model Enabled (ro)*/
+#define SHEN 0x0300 /* Show Cycle Enable */
+#define SUPV 0x0080 /* Supervisor/Unrestricted Data Space */
+#define MM 0x0040 /* Module Mapping */
+#define IARB 0x000f /* Interrupt Arbitration Field */
+
+
+
+#define SIMTR SIM_VOLATILE_USHORT_POINTER(0x02 + SIM_CRB)
+ /* SIM Test Register */
+/* Used only for factor testing */
+
+
+
+#define SYNCR SIM_VOLATILE_USHORT_POINTER(0x04 + SIM_CRB)
+ /* Clock Synthesizer Control Register */
+#define VCO 0x8000 /* Frequency Control (VCO) */
+#define PRESCALE 0x4000 /* Frequency Control Bit (Prescale) */
+#define COUNTER 0x3f00 /* Frequency Control Counter */
+#define EDIV 0x0080 /* ECLK Divide Rate */
+#define SLIMP 0x0010 /* Limp Mode Status */
+#define SLOCK 0x0008 /* Synthesizer Lock */
+#define RSTEN 0x0004 /* Reset Enable */
+#define STSIM 0x0002 /* Stop Mode SIM Clock */
+#define STEXT 0x0001 /* Stop Mode External Clock */
+
+
+
+#define RSR SIM_VOLATILE_UCHAR_POINTER(0x07 + SIM_CRB)
+ /* Reset Status Register */
+#define EXT 0x0080 /* External Reset */
+#define POW 0x0040 /* Power-On Reset */
+#define SW 0x0020 /* Software Watchdog Reset */
+#define DBF 0x0010 /* Double Bus Fault Reset */
+#define LOC 0x0004 /* Loss of Clock Reset */
+#define SYS 0x0002 /* System Reset */
+#define TST 0x0001 /* Test Submodule Reset */
+
+
+
+#define SIMTRE SIM_VOLATILE_USHORT_POINTER(0x08 + SIM_CRB)
+ /* System Integration Test Register */
+/* Used only for factor testing */
+
+
+
+#define PORTE0 SIM_VOLATILE_UCHAR_POINTER(0x11 + SIM_CRB)
+#define PORTE1 SIM_VOLATILE_UCHAR_POINTER(0x13 + SIM_CRB)
+ /* Port E Data Register */
+#define DDRE SIM_VOLATILE_UCHAR_POINTER(0x15 + SIM_CRB)
+ /* Port E Data Direction Register */
+#define PEPAR SIM_VOLATILE_UCHAR_POINTER(0x17 + SIM_CRB)
+ /* Port E Pin Assignment Register */
+/* Any bit cleared (zero) defines the corresponding pin to be an I/O
+ pin. Any bit set defines the corresponding pin to be a bus control
+ signal. */
+
+
+
+#define PORTF0 SIM_VOLATILE_UCHAR_POINTER(0x19 + SIM_CRB)
+#define PORTF1 SIM_VOLATILE_UCHAR_POINTER(0x1b + SIM_CRB)
+ /* Port F Data Register */
+#define DDRF SIM_VOLATILE_UCHAR_POINTER(0x1d + SIM_CRB)
+ /* Port E Data Direction Register */
+#define PFPAR SIM_VOLATILE_UCHAR_POINTER(0x1f + SIM_CRB)
+/* Any bit cleared (zero) defines the corresponding pin to be an I/O
+ pin. Any bit set defines the corresponding pin to be a bus control
+ signal. */
+
+
+
+#define SYPCR SIM_VOLATILE_UCHAR_POINTER(0x21 + SIM_CRB)
+/* !!! can write to only once after reset !!! */
+ /* System Protection Control Register */
+#define SWE 0x80 /* Software Watch Enable */
+#define SWP 0x40 /* Software Watchdog Prescale */
+#define SWT 0x30 /* Software Watchdog Timing */
+#define HME 0x08 /* Halt Monitor Enable */
+#define BME 0x04 /* Bus Monitor External Enable */
+#define BMT 0x03 /* Bus Monitor Timing */
+
+
+
+#define PICR SIM_VOLATILE_USHORT_POINTER(0x22 + SIM_CRB)
+ /* Periodic Interrupt Control Reg. */
+#define PIRQL 0x0700 /* Periodic Interrupt Request Level */
+#define PIV 0x00ff /* Periodic Interrupt Level */
+
+
+
+#define PITR SIM_VOLATILE_USHORT_POINTER(0x24 + SIM_CRB)
+ /* Periodic Interrupt Timer Register */
+#define PTP 0x0100 /* Periodic Timer Prescaler Control */
+#define PITM 0x00ff /* Periodic Interrupt Timing Modulus */
+
+
+
+#define SWSR SIM_VOLATILE_UCHAR_POINTER(0x27 + SIM_CRB)
+ /* Software Service Register */
+/* write 0x55 then 0xaa to service the software watchdog */
+
+
+
+#define TSTMSRA SIM_VOLATILE_USHORT_POINTER(0x30 + SIM_CRB)
+ /* Test Module Master Shift A */
+#define TSTMSRB SIM_VOLATILE_USHORT_POINTER(0x32 + SIM_CRB)
+ /* Test Module Master Shift A */
+#define TSTSC SIM_VOLATILE_USHORT_POINTER(0x34 + SIM_CRB)
+ /* Test Module Shift Count */
+#define TSTRC SIM_VOLATILE_USHORT_POINTER(0x36 + SIM_CRB)
+ /* Test Module Repetition Counter */
+#define CREG SIM_VOLATILE_USHORT_POINTER(0x38 + SIM_CRB)
+ /* Test Module Control */
+#define DREG SIM_VOLATILE_USHORT_POINTER(0x3a + SIM_CRB)
+ /* Test Module Distributed */
+/* Used only for factor testing */
+
+
+
+#define PORTC SIM_VOLATILE_UCHAR_POINTER(0x41 + SIM_CRB)
+ /* Port C Data */
+
+
+
+#define CSPAR0 SIM_VOLATILE_USHORT_POINTER(0x44 + SIM_CRB)
+ /* Chip Select Pin Assignment
+ Resgister 0 */
+/* CSPAR0 contains seven two-bit fields that determine the functions
+ of corresponding chip-select pins. CSPAR0[15:14] are not
+ used. These bits always read zero; write have no effect. CSPAR0 bit
+ 1 always reads one; writes to CSPAR0 bit 1 have no effect. */
+#define CSPAR1 SIM_VOLATILE_USHORT_POINTER(0x46 + SIM_CRB)
+ /* Chip Select Pin Assignment
+ Register 1 */
+/* CSPAR1 contains five two-bit fields that determine the finctions of
+ corresponding chip-select pins. CSPAR1[15:10] are not used. These
+ bits always read zero; writes have no effect. */
+/*
+ *
+ * Bit Field | Description
+ * ------------+---------------
+ * 00 | Discrete Output
+ * 01 | Alternate Function
+ * 10 | Chip Select (8-bit port)
+ * 11 | Chip Select (16-bit port)
+ */
+#define DisOut 0x0
+#define AltFun 0x1
+#define CS8bit 0x2
+#define CS16bit 0x3
+/*
+ *
+ * CSPARx Field |Chip Select Signal | Alternate Signal | Discrete Output
+ *-----------------+--------------------+--------------------+---------------*/
+#define CS_5 12 /* !CS5 | FC2 | PC2 */
+#define CS_4 10 /* !CS4 | FC1 | PC1 */
+#define CS_3 8 /* !CS3 | FC0 | PC0 */
+#define CS_2 6 /* !CS2 | !BGACK | */
+#define CS_1 4 /* !CS1 | !BG | */
+#define CS_0 2 /* !CS0 | !BR | */
+#define CSBOOT 0 /* !CSBOOT | | */
+/* | | | */
+#define CS_10 8 /* !CS10 | ADDR23 | ECLK */
+#define CS_9 6 /* !CS9 | ADDR22 | PC6 */
+#define CS_8 4 /* !CS8 | ADDR21 | PC5 */
+#define CS_7 2 /* !CS7 | ADDR20 | PC4 */
+#define CS_6 0 /* !CS6 | ADDR19 | PC3 */
+
+#define BS_2K 0x0
+#define BS_8K 0x1
+#define BS_16K 0x2
+#define BS_64K 0x3
+#define BS_128K 0x4
+#define BS_256K 0x5
+#define BS_512K 0x6
+#define BS_1M 0x7
+
+#define CSBARBT SIM_VOLATILE_USHORT_POINTER(0x48 + SIM_CRB)
+#define CSBAR0 SIM_VOLATILE_USHORT_POINTER(0x4c + SIM_CRB)
+#define CSBAR1 SIM_VOLATILE_USHORT_POINTER(0x50 + SIM_CRB)
+#define CSBAR2 SIM_VOLATILE_USHORT_POINTER(0x54 + SIM_CRB)
+#define CSBAR3 SIM_VOLATILE_USHORT_POINTER(0x58 + SIM_CRB)
+#define CSBAR4 SIM_VOLATILE_USHORT_POINTER(0x5c + SIM_CRB)
+#define CSBAR5 SIM_VOLATILE_USHORT_POINTER(0x60 + SIM_CRB)
+#define CSBAR6 SIM_VOLATILE_USHORT_POINTER(0x64 + SIM_CRB)
+#define CSBAR7 SIM_VOLATILE_USHORT_POINTER(0x68 + SIM_CRB)
+#define CSBAR8 SIM_VOLATILE_USHORT_POINTER(0x6c + SIM_CRB)
+#define CSBAR9 SIM_VOLATILE_USHORT_POINTER(0x70 + SIM_CRB)
+#define CSBAR10 SIM_VOLATILE_USHORT_POINTER(0x74 + SIM_CRB)
+
+#define MODE 0x8000
+#define Disable 0
+#define LowerByte 0x2000
+#define UpperByte 0x4000
+#define BothBytes 0x6000
+#define ReadOnly 0x0800
+#define WriteOnly 0x1000
+#define ReadWrite 0x1800
+#define SyncAS 0x0
+#define SyncDS 0x0400
+
+#define WaitStates_0 (0x0 << 6)
+#define WaitStates_1 (0x1 << 6)
+#define WaitStates_2 (0x2 << 6)
+#define WaitStates_3 (0x3 << 6)
+#define WaitStates_4 (0x4 << 6)
+#define WaitStates_5 (0x5 << 6)
+#define WaitStates_6 (0x6 << 6)
+#define WaitStates_7 (0x7 << 6)
+#define WaitStates_8 (0x8 << 6)
+#define WaitStates_9 (0x9 << 6)
+#define WaitStates_10 (0xa << 6)
+#define WaitStates_11 (0xb << 6)
+#define WaitStates_12 (0xc << 6)
+#define WaitStates_13 (0xd << 6)
+#define FastTerm (0xe << 6)
+#define External (0xf << 6)
+
+#define CPUSpace (0x0 << 4)
+#define UserSpace (0x1 << 4)
+#define SupSpace (0x2 << 4)
+#define UserSupSpace (0x3 << 4)
+
+#define IPLevel_any 0x0
+#define IPLevel_1 0x2
+#define IPLevel_2 0x4
+#define IPLevel_3 0x6
+#define IPLevel_4 0x8
+#define IPLevel_5 0xa
+#define IPLevel_6 0xc
+#define IPLevel_7 0xe
+
+#define AVEC 1
+
+#define CSORBT SIM_VOLATILE_USHORT_POINTER(0x4a + SIM_CRB)
+#define CSOR0 SIM_VOLATILE_USHORT_POINTER(0x4e + SIM_CRB)
+#define CSOR1 SIM_VOLATILE_USHORT_POINTER(0x52 + SIM_CRB)
+#define CSOR2 SIM_VOLATILE_USHORT_POINTER(0x56 + SIM_CRB)
+#define CSOR3 SIM_VOLATILE_USHORT_POINTER(0x5a + SIM_CRB)
+#define CSOR4 SIM_VOLATILE_USHORT_POINTER(0x5e + SIM_CRB)
+#define CSOR5 SIM_VOLATILE_USHORT_POINTER(0x62 + SIM_CRB)
+#define CSOR6 SIM_VOLATILE_USHORT_POINTER(0x66 + SIM_CRB)
+#define CSOR7 SIM_VOLATILE_USHORT_POINTER(0x6a + SIM_CRB)
+#define CSOR8 SIM_VOLATILE_USHORT_POINTER(0x6e + SIM_CRB)
+#define CSOR9 SIM_VOLATILE_USHORT_POINTER(0x72 + SIM_CRB)
+#define CSOR10 SIM_VOLATILE_USHORT_POINTER(0x76 + SIM_CRB)
+
+#endif /* _RTEMS_M68K_SIM_H */
diff --git a/cpukit/score/cpu/m68k/rtems/score/cpu.h b/cpukit/score/cpu/m68k/rtems/score/cpu.h
new file mode 100644
index 0000000000..8aa06de412
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/score/cpu.h
@@ -0,0 +1,753 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the Motorola
+ * m68xxx processor family.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/m68k.h>
+
+/* conditional compilation parameters */
+
+#define CPU_INLINE_ENABLE_DISPATCH TRUE
+#define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * M68K Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Use the m68k's hardware interrupt stack support and have the
+ * interrupt manager allocate the memory for it.
+ */
+
+#if ( M68K_HAS_SEPARATE_STACKS == 1)
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK 0
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK 1
+#else
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK 1
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK 0
+#endif
+#define CPU_ALLOCATE_INTERRUPT_STACK 1
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Some family members have no FP, some have an FPU such as the
+ * MC68881/MC68882 for the MC68020, others have it built in (MC68030, 040).
+ *
+ * NOTE: If on a CPU without hardware FP, then one can use software
+ * emulation. The gcc software FP emulation code has data which
+ * must be contexted switched on a per task basis.
+ */
+
+#if ( M68K_HAS_FPU == 1 ) || ( M68K_HAS_EMAC == 1 )
+ #define CPU_HARDWARE_FP TRUE
+ #define CPU_SOFTWARE_FP FALSE
+#else
+ #define CPU_HARDWARE_FP FALSE
+ #if defined( __GNUC__ )
+ #define CPU_SOFTWARE_FP TRUE
+ #else
+ #define CPU_SOFTWARE_FP FALSE
+ #endif
+#endif
+
+/*
+ * All tasks are not by default floating point tasks on this CPU.
+ * The IDLE task does not have a floating point context on this CPU.
+ * It is safe to use the deferred floating point context switch
+ * algorithm on this CPU.
+ */
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+#define CPU_IDLE_TASK_IS_FP FALSE
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+#define CPU_STACK_GROWS_UP FALSE
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (4)))
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+
+#if ( CPU_HARDWARE_FP == TRUE ) && !defined( __mcoldfire__ )
+ #if defined( __mc68060__ )
+ #define M68K_FP_STATE_SIZE 16
+ #else
+ #define M68K_FP_STATE_SIZE 216
+ #endif
+#endif
+
+#ifndef ASM
+
+/* structures */
+
+/*
+ * Basic integer context for the m68k family.
+ */
+
+typedef struct {
+ uint32_t sr; /* (sr) status register */
+ uint32_t d2; /* (d2) data register 2 */
+ uint32_t d3; /* (d3) data register 3 */
+ uint32_t d4; /* (d4) data register 4 */
+ uint32_t d5; /* (d5) data register 5 */
+ uint32_t d6; /* (d6) data register 6 */
+ uint32_t d7; /* (d7) data register 7 */
+ void *a2; /* (a2) address register 2 */
+ void *a3; /* (a3) address register 3 */
+ void *a4; /* (a4) address register 4 */
+ void *a5; /* (a5) address register 5 */
+ void *a6; /* (a6) address register 6 */
+ void *a7_msp; /* (a7) master stack pointer */
+ #if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
+ uint8_t fpu_dis;
+ #endif
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->a7_msp
+
+/*
+ * Floating point context areas and support routines
+ */
+
+#if ( CPU_SOFTWARE_FP == TRUE )
+ /*
+ * This is the same as gcc's view of the software FP condition code
+ * register _fpCCR. The implementation of the emulation code is
+ * in the gcc-VERSION/config/m68k directory. This structure is
+ * correct as of gcc 2.7.2.2.
+ */
+ typedef struct {
+ uint16_t _exception_bits;
+ uint16_t _trap_enable_bits;
+ uint16_t _sticky_bits;
+ uint16_t _rounding_mode;
+ uint16_t _format;
+ uint16_t _last_operation;
+ union {
+ float sf;
+ double df;
+ } _operand1;
+ union {
+ float sf;
+ double df;
+ } _operand2;
+ } Context_Control_fp;
+
+ /*
+ * This software FP implementation is only for GCC.
+ */
+ #define _CPU_Context_Fp_start( _base, _offset ) \
+ ((void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+ #define _CPU_Context_Initialize_fp( _fp_area ) \
+ { \
+ Context_Control_fp *_fp; \
+ _fp = *(Context_Control_fp **)_fp_area; \
+ _fp->_exception_bits = 0; \
+ _fp->_trap_enable_bits = 0; \
+ _fp->_sticky_bits = 0; \
+ _fp->_rounding_mode = 0; /* ROUND_TO_NEAREST */ \
+ _fp->_format = 0; /* NIL */ \
+ _fp->_last_operation = 0; /* NOOP */ \
+ _fp->_operand1.df = 0; \
+ _fp->_operand2.df = 0; \
+ }
+#endif
+
+#if ( CPU_HARDWARE_FP == TRUE )
+ #if defined( __mcoldfire__ )
+ /* We need memset() to initialize the FP context */
+ #include <string.h>
+
+ #if ( M68K_HAS_FPU == 1 )
+ /*
+ * The Cache Control Register (CACR) has write-only access. It is also
+ * used to enable and disable the FPU. We need to maintain a copy of
+ * this register to allow per thread values.
+ */
+ extern uint32_t _CPU_cacr_shadow;
+ #endif
+
+ /* We assume that each ColdFire core with a FPU has also an EMAC unit */
+ typedef struct {
+ uint32_t emac_macsr;
+ uint32_t emac_acc0;
+ uint32_t emac_acc1;
+ uint32_t emac_acc2;
+ uint32_t emac_acc3;
+ uint32_t emac_accext01;
+ uint32_t emac_accext23;
+ uint32_t emac_mask;
+ #if ( M68K_HAS_FPU == 1 )
+ uint16_t fp_state_format;
+ uint16_t fp_state_fpcr;
+ double fp_state_op;
+ uint32_t fp_state_fpsr;
+
+ /*
+ * We need to save the FP Instruction Address Register (FPIAR), because
+ * a context switch can occur within a FP exception before the handler
+ * was able to save this register.
+ */
+ uint32_t fp_fpiar;
+
+ double fp_data [8];
+ #endif
+ } Context_Control_fp;
+
+ #define _CPU_Context_Fp_start( _base, _offset ) \
+ ((void *) _Addresses_Add_offset( (_base), (_offset) ))
+
+ /*
+ * The reset value for all context relevant registers except the FP data
+ * registers is zero. The reset value of the FP data register is NAN. The
+ * restore of the reset FP state will reset the FP data registers, so the
+ * initial value of them can be arbitrary here.
+ */
+ #define _CPU_Context_Initialize_fp( _fp_area ) \
+ memset( *(_fp_area), 0, sizeof( Context_Control_fp ) )
+ #else
+ /*
+ * FP context save area for the M68881/M68882 and 68060 numeric coprocessors.
+ */
+
+ typedef struct {
+ /*
+ * M68K_FP_STATE_SIZE bytes for FSAVE/FRESTORE
+ * 96 bytes for FMOVEM FP0-7
+ * 12 bytes for FMOVEM CREGS
+ * 4 bytes for non-null flag
+ */
+ uint8_t fp_save_area [M68K_FP_STATE_SIZE + 112];
+ } Context_Control_fp;
+
+ #define _CPU_Context_Fp_start( _base, _offset ) \
+ ( \
+ (void *) _Addresses_Add_offset( \
+ (_base), \
+ (_offset) + CPU_CONTEXT_FP_SIZE - 4 \
+ ) \
+ )
+
+ #define _CPU_Context_Initialize_fp( _fp_area ) \
+ { \
+ uint32_t *_fp_context = (uint32_t *)*(_fp_area); \
+ *(--(_fp_context)) = 0; \
+ *(_fp_area) = (void *)(_fp_context); \
+ }
+ #endif
+#endif
+
+/*
+ * The following structures define the set of information saved
+ * on the current stack by RTEMS upon receipt of each exc/interrupt.
+ * These are not used by m68k handlers.
+ * The exception frame is for rdbg.
+ */
+
+typedef struct {
+ uint32_t vecnum; /* vector number */
+} CPU_Interrupt_frame;
+
+typedef struct {
+ uint32_t vecnum; /* vector number */
+ uint32_t sr; /* status register */
+ uint32_t pc; /* program counter */
+ uint32_t d0, d1, d2, d3, d4, d5, d6, d7;
+ uint32_t a0, a1, a2, a3, a4, a5, a6, a7;
+} CPU_Exception_frame;
+
+/* variables */
+
+extern void* _VBR;
+
+#if ( M68K_HAS_VBR == 0 )
+
+/*
+ * Table of ISR handler entries that resides in RAM. The FORMAT/ID is
+ * pushed onto the stack. This is not is the same order as VBR processors.
+ * The ISR handler takes the format and uses it for dispatching the user
+ * handler.
+ *
+ * FIXME : should be moved to below CPU_INTERRUPT_NUMBER_OF_VECTORS
+ *
+ */
+
+typedef struct {
+ uint16_t move_a7; /* move #FORMAT_ID,%a7@- */
+ uint16_t format_id;
+ uint16_t jmp; /* jmp _ISR_Handlers */
+ uint32_t isr_handler;
+} _CPU_ISR_handler_entry;
+
+#define M68K_MOVE_A7 0x3F3C
+#define M68K_JMP 0x4EF9
+
+ /* points to jsr-exception-table in targets wo/ VBR register */
+SCORE_EXTERN _CPU_ISR_handler_entry _CPU_ISR_jump_table[256];
+
+#endif /* M68K_HAS_VBR */
+
+#endif /* ASM */
+
+/* constants */
+
+/*
+ * This defines the number of levels and the mask used to pick those
+ * bits out of a thread mode.
+ */
+
+#define CPU_MODES_INTERRUPT_LEVEL 0x00000007 /* interrupt level in mode */
+#define CPU_MODES_INTERRUPT_MASK 0x00000007 /* interrupt level in mode */
+
+/*
+ * context size area for floating point
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/*
+ * extra stack required by the MPCI receive server thread
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
+
+/*
+ * m68k family supports 256 distinct vectors.
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 256
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Minimum size of a thread's stack.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE M68K_CPU_STACK_MINIMUM_SIZE
+
+/*
+ * Maximum priority of a thread. Note based from 0 which is the idle task.
+ */
+#define CPU_PRIORITY_MAXIMUM M68K_CPU_PRIORITY_MAXIMUM
+
+/*
+ * m68k is pretty tolerant of alignment. Just put things on 4 byte boundaries.
+ */
+
+#define CPU_ALIGNMENT 4
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * On m68k thread stacks require no further alignment after allocation
+ * from the Workspace.
+ */
+
+#define CPU_STACK_ALIGNMENT 0
+
+#ifndef ASM
+
+/* macros */
+
+/*
+ * ISR handler macros
+ *
+ * These macros perform the following functions:
+ * + initialize the RTEMS vector table
+ * + disable all maskable CPU interrupts
+ * + restore previous interrupt level (enable)
+ * + temporarily restore interrupts (flash)
+ * + set a particular level
+ */
+
+#define _CPU_Initialize_vectors()
+
+#define _CPU_ISR_Disable( _level ) \
+ m68k_disable_interrupts( _level )
+
+#define _CPU_ISR_Enable( _level ) \
+ m68k_enable_interrupts( _level )
+
+#define _CPU_ISR_Flash( _level ) \
+ m68k_flash_interrupts( _level )
+
+#define _CPU_ISR_Set_level( _newlevel ) \
+ m68k_set_interrupt_level( _newlevel )
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/*
+ * Context handler macros
+ *
+ * These macros perform the following functions:
+ * + initialize a context area
+ * + restart the current thread
+ * + calculate the initial pointer into a FP context area
+ * + initialize an FP context area
+ */
+
+#if (defined(__mcoldfire__) && ( M68K_HAS_FPU == 1 ))
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ do { \
+ uint32_t _stack; \
+ \
+ (_the_context)->sr = 0x3000 | ((_isr) << 8); \
+ _stack = (uint32_t)(_stack_base) + (_size) - 4; \
+ (_the_context)->a7_msp = (void *)_stack; \
+ *(void **)_stack = (void *)(_entry_point); \
+ (_the_context)->fpu_dis = (_is_fp == TRUE) ? 0x00 : 0x10; \
+ } while ( 0 )
+#else
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ do { \
+ uint32_t _stack; \
+ \
+ (_the_context)->sr = 0x3000 | ((_isr) << 8); \
+ _stack = (uint32_t )(_stack_base) + (_size) - 4; \
+ (_the_context)->a7_msp = (void *)_stack; \
+ *(void **)_stack = (void *)(_entry_point); \
+ } while ( 0 )
+#endif
+
+/* end of Context handler macros */
+
+/*
+ * _CPU_Thread_Idle_body
+ *
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * NOTE: It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/*
+ * Fatal Error manager macros
+ *
+ * These macros perform the following functions:
+ * + disable interrupts and halt the CPU
+ */
+
+#if ( defined(__mcoldfire__) )
+#define _CPU_Fatal_halt( _error ) \
+ { __asm__ volatile( "move.w %%sr,%%d0\n\t" \
+ "or.l %2,%%d0\n\t" \
+ "move.w %%d0,%%sr\n\t" \
+ "move.l %1,%%d0\n\t" \
+ "move.l #0xDEADBEEF,%%d1\n\t" \
+ "halt" \
+ : "=g" (_error) \
+ : "0" (_error), "d"(0x0700) \
+ : "d0", "d1" ); \
+ }
+#else
+#define _CPU_Fatal_halt( _error ) \
+ { __asm__ volatile( "movl %0,%%d0; " \
+ "orw #0x0700,%%sr; " \
+ "stop #0x2700" : "=d" ((_error)) : "0" ((_error)) ); \
+ }
+#endif
+
+/* end of Fatal Error manager macros */
+
+/*
+ * Bitfield handler macros
+ *
+ * These macros perform the following functions:
+ * + scan for the highest numbered (MSB) set in a 16 bit bitfield
+ *
+ * NOTE:
+ *
+ * It appears that on the M68020 bitfield are always 32 bits wide
+ * when in a register. This code forces the bitfield to be in
+ * memory (it really always is anyway). This allows us to
+ * have a real 16 bit wide bitfield which operates "correctly."
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
+#define CPU_USE_GENERIC_BITFIELD_DATA FALSE
+
+#if ( M68K_HAS_BFFFO != 1 )
+/*
+ * Lookup table for BFFFO simulation
+ */
+extern const unsigned char _CPU_m68k_BFFFO_table[256];
+#endif
+
+#if ( M68K_HAS_BFFFO == 1 )
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ __asm__ volatile( "bfffo (%1),#0,#16,%0" : "=d" (_output) : "a" (&_value));
+
+#elif ( __mcfisaaplus__ )
+ /* This is simplified by the fact that RTEMS never calls it with _value=0 */
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ __asm__ volatile ( \
+ " swap %0\n" \
+ " ff1.l %0\n" \
+ : "=d" ((_output)) \
+ : "0" ((_value)) \
+ : "cc" ) ;
+
+#else
+/* duplicates BFFFO results for 16 bits (i.e., 15-(_priority) in
+ _CPU_Priority_bits_index is not needed), handles the 0 case, and
+ does not molest _value -- jsg */
+#if ( defined(__mcoldfire__) )
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ register int dumby; \
+ \
+ __asm__ volatile ( \
+ " clr.l %1\n" \
+ " move.w %2,%1\n" \
+ " lsr.l #8,%1\n" \
+ " beq.s 1f\n" \
+ " move.b (%3,%1),%0\n" \
+ " bra.s 0f\n" \
+ "1: move.w %2,%1\n" \
+ " move.b (%3,%1),%0\n" \
+ " addq.l #8,%0\n" \
+ "0: and.l #0xff,%0\n" \
+ : "=&d" ((_output)), "=&d" ((dumby)) \
+ : "d" ((_value)), "ao" ((_CPU_m68k_BFFFO_table)) \
+ : "cc" ) ; \
+ }
+#elif ( M68K_HAS_EXTB_L == 1 )
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ register int dumby; \
+ \
+ __asm__ volatile ( " move.w %2,%1\n" \
+ " lsr.w #8,%1\n" \
+ " beq.s 1f\n" \
+ " move.b (%3,%1.w),%0\n" \
+ " extb.l %0\n" \
+ " bra.s 0f\n" \
+ "1: moveq.l #8,%0\n" \
+ " add.b (%3,%2.w),%0\n" \
+ "0:\n" \
+ : "=&d" ((_output)), "=&d" ((dumby)) \
+ : "d" ((_value)), "ao" ((_CPU_m68k_BFFFO_table)) \
+ : "cc" ) ; \
+ }
+#else
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ register int dumby; \
+ \
+ __asm__ volatile ( " move.w %2,%1\n" \
+ " lsr.w #8,%1\n" \
+ " beq.s 1f\n" \
+ " move.b (%3,%1.w),%0\n" \
+ " and.l #0x000000ff,%0\n"\
+ " bra.s 0f\n" \
+ "1: moveq.l #8,%0\n" \
+ " add.b (%3,%2.w),%0\n" \
+ "0:\n" \
+ : "=&d" ((_output)), "=&d" ((dumby)) \
+ : "d" ((_value)), "ao" ((_CPU_m68k_BFFFO_table)) \
+ : "cc" ) ; \
+ }
+#endif
+
+#endif
+
+/* end of Bitfield handler macros */
+
+/*
+ * Priority handler macros
+ *
+ * These macros perform the following functions:
+ * + return a mask with the bit for this major/minor portion of
+ * of thread priority set.
+ * + translate the bit number returned by "Bitfield_find_first_bit"
+ * into an index into the thread ready chain bit maps
+ */
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 0x8000 >> (_bit_number) )
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Install_interrupt_stack
+ *
+ * This routine installs the hardware interrupt stack pointer.
+ */
+
+void _CPU_Install_interrupt_stack( void );
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+void _CPU_Context_Restart_self(
+ Context_Control *the_context
+);
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+#if (M68K_HAS_FPSP_PACKAGE == 1)
+/*
+ * Hooks for the Floating Point Support Package (FPSP) provided by Motorola
+ *
+ * NOTES:
+ *
+ * Motorola 68k family CPU's before the 68040 used a coprocessor
+ * (68881 or 68882) to handle floating point. The 68040 has internal
+ * floating point support -- but *not* the complete support provided by
+ * the 68881 or 68882. The leftover functions are taken care of by the
+ * M68040 Floating Point Support Package. Quoting from the MC68040
+ * Microprocessors User's Manual, Section 9, Floating-Point Unit (MC68040):
+ *
+ * "When used with the M68040FPSP, the MC68040 FPU is fully
+ * compliant with IEEE floating-point standards."
+ *
+ * M68KFPSPInstallExceptionHandlers is in libcpu/m68k/MODEL/fpsp and
+ * is invoked early in the application code to ensure that proper FP
+ * behavior is installed. This is not left to the BSP to call, since
+ * this would force all applications using that BSP to use FPSP which
+ * is not necessarily desirable.
+ *
+ * There is a similar package for the 68060 but RTEMS does not yet
+ * support the 68060.
+ */
+
+void M68KFPSPInstallExceptionHandlers (void);
+
+SCORE_EXTERN int (*_FPSP_install_raw_handler)(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+#endif
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/m68k/rtems/score/m68k.h b/cpukit/score/cpu/m68k/rtems/score/m68k.h
new file mode 100644
index 0000000000..88c214a992
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/score/m68k.h
@@ -0,0 +1,504 @@
+/**
+ * @file rtems/score/m68k.h
+ */
+
+/*
+ * This include file contains information pertaining to the Motorola
+ * m68xxx processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_M68K_H
+#define _RTEMS_SCORE_M68K_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section contains the information required to build
+ * RTEMS for a particular member of the Motorola MC68xxx
+ * family. It does this by setting variables to indicate
+ * which implementation dependent features are present in
+ * a particular member of the family.
+ *
+ * Currently recognized:
+ * -m68000
+ * -m68000 -msoft-float
+ * -m68020
+ * -m68020 -msoft-float
+ * -m68030
+ * -m68040 -msoft-float
+ * -m68040
+ * -m68040 -msoft-float
+ * -m68060
+ * -m68060 -msoft-float
+ * -m68302 (no FP) (deprecated, use -m68000)
+ * -m68332 (no FP) (deprecated, use -mcpu32)
+ * -mcpu32 (no FP)
+ * -m5200 (no FP)
+ * -m528x (no FP, ISA A+)
+ *
+ * As of gcc 2.8.1 and egcs 1.1, there is no distinction made between
+ * the CPU32 and CPU32+. The option -mcpu32 generates code which can
+ * be run on either core. RTEMS distinguishes between these two cores
+ * because they have different alignment rules which impact performance.
+ * If you are using a CPU32+, then the symbol RTEMS__mcpu32p__ should
+ * be defined in your custom file (see make/custom/gen68360.cfg for an
+ * example of how to do this. If gcc ever distinguishes between these
+ * two cores, then RTEMS__mcpu32p__ usage will be replaced with the
+ * appropriate compiler defined predefine.
+ *
+ * Here is some information on the 040 variants (courtesy of Doug McBride,
+ * mcbride@rodin.colorado.edu):
+ *
+ * "The 68040 is a superset of the 68EC040 and the 68LC040. The
+ * 68EC040 and 68LC040 do not have FPU's. The 68LC040 and the
+ * 68EC040 have renamed the DLE pin as JS0 which must be tied to
+ * Gnd or Vcc. The 68EC040 has renamed the MDIS pin as JS1. The
+ * 68EC040 has access control units instead of memory management units.
+ * The 68EC040 should not have the PFLUSH or PTEST instructions executed
+ * (cause an indeterminate result). The 68EC040 and 68LC040 do not
+ * implement the DLE or multiplexed bus modes. The 68EC040 does not
+ * implement the output buffer impedance selection mode of operation."
+ *
+ * M68K_HAS_EXTB_L is used to enable/disable usage of the extb.l instruction
+ * which is not available for 68000 or 68ec000 cores (68000, 68001, 68008,
+ * 68010, 68302, 68306, 68307). This instruction is available on the 68020
+ * up and the cpu32 based models.
+ *
+ * M68K_HAS_MISALIGNED is non-zero if the CPU allows byte-misaligned
+ * data access (68020, 68030, 68040, 68060, CPU32+).
+ *
+ * NOTE:
+ * Eventually it would be nice to evaluate doing a lot of this section
+ * by having each model specify which core it uses and then go from there.
+ */
+
+/*
+ * Handle the Coldfire family based on the instruction set.
+ */
+#if defined(__mcoldfire__)
+
+# define CPU_NAME "Motorola ColdFire"
+
+# if defined(__mcfisaa__)
+/* Motorola ColdFire ISA A */
+# define CPU_MODEL_NAME "mcfisaa"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_PREINDEXING 0
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+
+# elif defined(__mcfisaaplus__)
+/* Motorola ColdFire ISA A+ */
+# define CPU_MODEL_NAME "mcfisaaplus"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_PREINDEXING 0
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+
+# elif defined(__mcfisab__)
+/* Motorola ColdFire ISA B */
+# define CPU_MODEL_NAME "mcfisab"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_PREINDEXING 0
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+
+# else
+# error "Unsupported Coldfire ISA -- Please notify RTEMS"
+# endif
+
+/*
+ * Assume the FPU support is independent. I think it is just the ISA B
+ * instruction set.
+ */
+# if defined (__mcffpu__)
+# define M68K_HAS_FPU 1
+ /*
+ * td: can we be sure that all CFs with FPU also have an EMAC?
+ */
+# define M68K_HAS_EMAC 1
+# define M68K_HAS_FPSP_PACKAGE 0
+# else
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+# endif
+
+/*
+ * Tiny RTEMS support. Small stack and limited priorities.
+ *
+ * These CPUs have very limited on-CPU memory which cannot
+ * be expanded. We have to be gentle with them or nothing
+ * will every run.
+ */
+# if (defined(__mcf_cpu_52221) || \
+ defined(__mcf_cpu_52223) || \
+ defined(__mcf_cpu_52230) || \
+ defined(__mcf_cpu_52231) || \
+ defined(__mcf_cpu_52232) || \
+ defined(__mcf_cpu_52233) || \
+ defined(__mcf_cpu_52234) || \
+ defined(__mcf_cpu_52235) || \
+ defined(__mcf_cpu_52225) || \
+ defined(__mcf_cpu_52235))
+ #define M68K_CPU_STACK_MINIMUM_SIZE 1024
+ /* Define the lowest priority. Based from 0 to this is 16 levels. */
+ #define M68K_CPU_PRIORITY_MAXIMUM 15
+# else
+ #define M68K_CPU_STACK_MINIMUM_SIZE 4096
+ /* Use the default number of priorities */
+ #define M68K_CPU_PRIORITY_MAXIMUM 255
+# endif
+
+#else
+
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines. Notice the only exception to this is that
+ * gcc does not distinguish between CPU32 and CPU32+. This
+ * feature selection logic is setup such that if RTEMS__mcpu32p__
+ * is defined, then CPU32+ rules are used. Otherwise, the safe
+ * but less efficient CPU32 rules are used for the CPU32+.
+ */
+
+# define CPU_NAME "Motorola MC68xxx"
+
+/*
+ * One stack size fits all 68000 processors.
+ */
+# define M68K_CPU_STACK_MINIMUM_SIZE 4096
+
+# if (defined(__mc68020__) && !defined(__mcpu32__))
+
+# define CPU_MODEL_NAME "m68020"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_SEPARATE_STACKS 1
+# define M68K_HAS_BFFFO 1
+# define M68K_HAS_PREINDEXING 1
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+# if defined (__HAVE_68881__)
+# define M68K_HAS_FPU 1
+# define M68K_HAS_FPSP_PACKAGE 0
+# else
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+# endif
+
+# elif defined(__mc68030__)
+
+# define CPU_MODEL_NAME "m68030"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_SEPARATE_STACKS 1
+# define M68K_HAS_BFFFO 1
+# define M68K_HAS_PREINDEXING 1
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+# if defined (__HAVE_68881__)
+# define M68K_HAS_FPU 1
+# define M68K_HAS_FPSP_PACKAGE 0
+# else
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+# endif
+
+# elif defined(__mc68040__)
+
+# define CPU_MODEL_NAME "m68040"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_SEPARATE_STACKS 1
+# define M68K_HAS_BFFFO 1
+# define M68K_HAS_PREINDEXING 1
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+# if defined (__HAVE_68881__)
+# define M68K_HAS_FPU 1
+# define M68K_HAS_FPSP_PACKAGE 1
+# else
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+# endif
+
+# elif defined(__mc68060__)
+
+# define CPU_MODEL_NAME "m68060"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_BFFFO 1
+# define M68K_HAS_PREINDEXING 1
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+# if defined (__HAVE_68881__)
+# define M68K_HAS_FPU 1
+# define M68K_HAS_FPSP_PACKAGE 0
+# else
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+# endif
+
+# elif defined(__mc68302__)
+
+# define CPU_MODEL_NAME "m68302"
+# define M68K_HAS_VBR 0
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_PREINDEXING 0
+# define M68K_HAS_EXTB_L 0
+# define M68K_HAS_MISALIGNED 0
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+
+ /* gcc and egcs do not distinguish between CPU32 and CPU32+ */
+# elif defined(RTEMS__mcpu32p__)
+
+# define CPU_MODEL_NAME "mcpu32+"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_PREINDEXING 1
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 1
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+
+# elif defined(__mcpu32__)
+
+# define CPU_MODEL_NAME "mcpu32"
+# define M68K_HAS_VBR 1
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_PREINDEXING 1
+# define M68K_HAS_EXTB_L 1
+# define M68K_HAS_MISALIGNED 0
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+
+# elif defined(__mc68000__)
+
+# define CPU_MODEL_NAME "m68000"
+# define M68K_HAS_VBR 0
+# define M68K_HAS_SEPARATE_STACKS 0
+# define M68K_HAS_BFFFO 0
+# define M68K_HAS_PREINDEXING 0
+# define M68K_HAS_EXTB_L 0
+# define M68K_HAS_MISALIGNED 0
+# if defined (__HAVE_68881__)
+# define M68K_HAS_FPU 1
+# define M68K_HAS_FPSP_PACKAGE 0
+# else
+# define M68K_HAS_FPU 0
+# define M68K_HAS_FPSP_PACKAGE 0
+# endif
+
+# else
+
+# error "Unsupported 68000 CPU model -- are you sure you're running a 68k compiler?"
+
+# endif
+
+/*
+ * No Tiny RTEMS support on the standard 68000 family.
+ */
+# define M68K_CPU_STACK_MINIMUM_SIZE 4096
+# define M68K_CPU_PRIORITY_MAXIMUM 255
+
+#endif
+
+/*
+ * OBSOLETE: Backward compatibility only - Don't use.
+ * Use __mcoldfire__ instead.
+ */
+#if defined(__mcoldfire__)
+#define M68K_COLDFIRE_ARCH 1
+#else
+#define M68K_COLDFIRE_ARCH 0
+#endif
+
+#ifndef ASM
+
+#if ( defined(__mcoldfire__) )
+#define m68k_disable_interrupts( _level ) \
+ do { register uint32_t _tmpsr = 0x0700; \
+ __asm__ volatile ( "move.w %%sr,%0\n\t" \
+ "or.l %0,%1\n\t" \
+ "move.w %1,%%sr" \
+ : "=d" (_level), "=d"(_tmpsr) : "1"(_tmpsr) \
+ : "cc" ); \
+ } while( 0 )
+#else
+#define m68k_disable_interrupts( _level ) \
+ __asm__ volatile ( "move.w %%sr,%0\n\t" \
+ "or.w #0x0700,%%sr" \
+ : "=d" (_level) \
+ : : "cc" )
+#endif
+
+#define m68k_enable_interrupts( _level ) \
+ __asm__ volatile ( "move.w %0,%%sr " : : "d" (_level) : "cc");
+
+#if ( defined(__mcoldfire__) )
+#define m68k_flash_interrupts( _level ) \
+ do { register uint32_t _tmpsr = 0x0700; \
+ asm volatile ( "move.w %2,%%sr\n\t" \
+ "or.l %2,%1\n\t" \
+ "move.w %1,%%sr" \
+ : "=d"(_tmpsr) : "0"(_tmpsr), "d"(_level) \
+ : "cc"); \
+ } while( 0 )
+#else
+#define m68k_flash_interrupts( _level ) \
+ __asm__ volatile ( "move.w %0,%%sr\n\t" \
+ "or.w #0x0700,%%sr" \
+ : : "d" (_level) \
+ : "cc" )
+#endif
+
+#define m68k_get_interrupt_level( _level ) \
+ do { \
+ register uint32_t _tmpsr; \
+ \
+ __asm__ volatile( "move.w %%sr,%0" : "=d" (_tmpsr)); \
+ _level = (_tmpsr & 0x0700) >> 8; \
+ } while (0)
+
+#define m68k_set_interrupt_level( _newlevel ) \
+ do { \
+ register uint32_t _tmpsr; \
+ \
+ __asm__ volatile( "move.w %%sr,%0" : "=d" (_tmpsr)); \
+ _tmpsr = (_tmpsr & 0xf8ff) | ((_newlevel) << 8); \
+ __asm__ volatile( "move.w %0,%%sr" : : "d" (_tmpsr)); \
+ } while (0)
+
+#if ( M68K_HAS_VBR == 1 && !defined(__mcoldfire__) )
+#define m68k_get_vbr( vbr ) \
+ __asm__ volatile ( "movec %%vbr,%0 " : "=r" (vbr))
+
+#define m68k_set_vbr( vbr ) \
+ __asm__ volatile ( "movec %0,%%vbr " : : "r" (vbr))
+
+#elif ( defined(__mcoldfire__) )
+extern void* _VBR;
+#define m68k_get_vbr( _vbr ) _vbr = &_VBR
+
+#define m68k_set_vbr( _vbr ) \
+ do { \
+ __asm__ volatile ( "movec %0,%%vbr " : : "r" (_vbr)); \
+ _VBR = (void *)_vbr; \
+ } while(0)
+
+#else
+#define m68k_get_vbr( _vbr ) _vbr = (void *)_VBR
+#define m68k_set_vbr( _vbr )
+#endif
+
+/*
+ * Access Control Registers
+ */
+#define m68k_set_cacr(_cacr) __asm__ volatile ("movec %0,%%cacr" : : "d" (_cacr))
+#define m68k_set_acr0(_acr0) __asm__ volatile ("movec %0,%%acr0" : : "d" (_acr0))
+#define m68k_set_acr1(_acr1) __asm__ volatile ("movec %0,%%acr1" : : "d" (_acr1))
+
+/*
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ */
+#if ( defined(__mcoldfire__) )
+
+/* There are no rotate commands in Coldfire architecture. We will use
+ * generic implementation of endian swapping for Coldfire.
+ */
+static inline uint32_t m68k_swap_u32(
+ uint32_t value
+ )
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+static inline uint16_t m68k_swap_u16(
+ uint16_t value
+)
+{
+ return (((value & 0xff) << 8) | ((value >> 8) & 0xff));
+}
+
+#else
+
+static inline uint32_t m68k_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t swapped = value;
+
+ __asm__ volatile( "rorw #8,%0" : "=d" (swapped) : "0" (swapped) );
+ __asm__ volatile( "swap %0" : "=d" (swapped) : "0" (swapped) );
+ __asm__ volatile( "rorw #8,%0" : "=d" (swapped) : "0" (swapped) );
+
+ return( swapped );
+}
+
+static inline uint16_t m68k_swap_u16(
+ uint16_t value
+)
+{
+ uint16_t swapped = value;
+
+ __asm__ volatile( "rorw #8,%0" : "=d" (swapped) : "0" (swapped) );
+
+ return( swapped );
+}
+#endif
+
+#define CPU_swap_u32( value ) m68k_swap_u32( value )
+#define CPU_swap_u16( value ) m68k_swap_u16( value )
+
+
+/*
+ * _CPU_virtual_to_physical
+ *
+ * DESCRIPTION:
+ *
+ * This function is used to map virtual addresses to physical
+ * addresses.
+ *
+ * FIXME: ASSUMES THAT VIRTUAL ADDRESSES ARE THE SAME AS THE
+ * PHYSICAL ADDRESSES
+ */
+static inline void * _CPU_virtual_to_physical (
+ const void * d_addr )
+{
+ return (void *) d_addr;
+}
+
+
+#endif /* !ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_M68K_H */
diff --git a/cpukit/score/cpu/m68k/rtems/score/types.h b/cpukit/score/cpu/m68k/rtems/score/types.h
new file mode 100644
index 0000000000..0c2442566f
--- /dev/null
+++ b/cpukit/score/cpu/m68k/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Motorola
+ * m68xxx processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void m68k_isr;
+typedef void ( *m68k_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/mips/.cvsignore b/cpukit/score/cpu/mips/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/mips/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/mips/ChangeLog b/cpukit/score/cpu/mips/ChangeLog
new file mode 100644
index 0000000000..a2e2a0e4ee
--- /dev/null
+++ b/cpukit/score/cpu/mips/ChangeLog
@@ -0,0 +1,685 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/mips.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2011-01-04 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.S: _Thread_Executing was not used.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * cpu_asm.S: Rename _Context_Switch_necessary to
+ _Thread_Dispatch_necessary to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-07-01 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/asm.h, rtems/score/cpu.h: cpu.h defines were not available to
+ assembly programs. This resulted in percpu.h (when included from
+ assembly) not being able to detect that the MIPS does not have a
+ dedicated software managed interrupt stack.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.S, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-06-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.S: Remove trailing tabs.
+
+2010-04-25 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move _CPU_Context_Initialize() to cpu.c so
+ it is easier to make warning free.
+
+2010-04-25 Joel Sherrill <joel.sherrilL@OARcorp.com>
+
+ * rtems/score/cpu.h: Remove warning in _CPU_Context_Initialize.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S: Add include of config.h
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1385/cpukit
+ * cpu_asm.S: When the type rtems_boolean was switched to the C99 bool,
+ the size changed from 4 bytes to 1 byte. The interrupt dispatching
+ code accesses two boolean variables for scheduling purposes and the
+ assembly implementations of this code did not get updated.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2008-06-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Use a constant for CPU_STACK_MINIMUM_SIZE so it
+ can be used in cpp expressions. Using sizeof() requires actually
+ compiling the file.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Eliminate the clicks_per_microsecond field in the
+ MIPS CPU Table and define another mechanism for drivers to obtain
+ this information.
+
+2007-08-04 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Use uintptr_t instead of uint32_t.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-06-02 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * cpu.c: Added __mips==32 to fix build problems on those targets
+ caused by the Bruce Robinson.
+
+2006-06-08 Bruce Robinson <brucer@pmccorp.com>
+
+ * cpu.c: Add int64 types for __mips==3 cpus, incorporate
+ mips_interrupt_mask() into mask computations
+ * cpu_asm.S: Add int64 register save/restores for __mips==3 cpus. Adjustment
+ of mips1 vs mips3 macros.
+ * cpu.h: Add int64 types for __mips==3 cpus.
+
+2006-03-17 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * cpu.c (_CPU_Initialize): Add fpu initialization.
+ * rtems/score/cpu.h: Setup CPU_*_ENDIAN from GCC's__MIPS{EL|EB}__.
+ (Partial merger of submission by Bruce Robinson <brucer@pmccorp.com>).
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2005-11-18 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Eliminate use of unsigned32.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-04-26 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/asm.h: Eliminate warnings.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/mips/idtcpu.h, rtems/mips/iregdef.h, rtems/score/mips.h:
+ Header guards cleanup.
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2005-02-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR rtems/752
+ * rtems/mips/idtcpu.h rtems/mips/iregdef.h: New (relocated from .).
+ New header guards.
+ * idtcpu.h, iregdef.h: Remove.
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/mips.h, rtems/score/types.h:
+ New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Remove warnings.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-03 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ PR 739
+ * iregdef.h: Fixes gcc warning about redundant definition of R_SZ
+ when compiling cpu_asm.S. Problem was a #define sneaked in in
+ version 1.11, no ill effects would have only affected R4000
+ builds.
+
+2005-01-03 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ PR 737
+ * cpu_asm.S: Fixes gcc warning about instructions in branch delay
+ slot when compiling cpu_asm.S
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-12-02 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ PR 730
+ * cpu_asm.S: Collected PR 601 changes for commit to cvshead
+ for rtems-4.7.
+
+2004-04-09 Joel Sherrill <joel@OARcorp.com>
+
+ PR 605/bsps
+ * cpu.c: Do not use C++ style comments.
+
+2004-04-07 Greg Menke <gregory.menke@gsfc.nasa.gov>
+ PR 601
+ * cpu_asm.S: Added __mips==32 support for R4000 processors running
+ 32 bit code. Fixed #define problems that caused fpu code to
+ always be included even when no fpu is present.
+
+2004-04-03 Art Ferrer <arturo.b.ferrer@nasa.gov>
+
+ PR 598/bsps
+ * cpu_asm.S, rtems/score/cpu.h: Add save of floating point
+ status/control register on context switches. Missing this register
+ was causing intermittent floating point errors.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h, rtems/score/mips.h,
+ rtems/score/types.h: URL for license changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-11-04 Joel Sherrill <joel@OARcorp.com>
+
+ * idtcpu.h: Removed warning.
+
+2002-11-01 Joel Sherrill <joel@OARcorp.com>
+
+ * idtcpu.h: Removed warnings.
+
+2002-10-28 Joel Sherrill <joel@OARcorp.com>
+
+ * idtcpu.h: Removed warning by turning extra token at the end of
+ an endif into a comment.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-08-14 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * cpu_asm.S: Clarified some comments, removed code that forced
+ SR_IEP on when returning from an interrupt.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-20 Greg Menke <gregory.menke@gsfc.nasa.gov>
+ * cpu_asm.S: Added SR_IEO to context restore to fix isr disabled
+ deadlock caused by interrupt arriving while dispatching.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/mipstypes.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-03-20 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * cpu_asm.S: Now compiles on 4600 and 4650.
+
+2002-03-13 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * cpu_asm.S: Fixed a sneaky return from int w/ ints disabled bug.
+ * rtems/score/cpu.h: Fixed register numbering in comments and made
+ interrupt enable/disable more robust.
+
+2002-03-05 Greg Menke <gregory.menke@gsfc.nasa.gov>
+ * cpu_asm.S: Added support for the debug exception vector, cleaned
+ up the exception processing & exception return stuff. Re-added
+ EPC in the task context structure so the gdb stub will know where
+ a thread is executing. Should've left it there in the first place...
+ * idtcpu.h: Added support for the debug exception vector.
+ * cpu.c: Added ___exceptionTaskStack to hold a pointer to the
+ stack frame in an interrupt so context switch code can get the
+ userspace EPC when scheduling.
+ * rtems/score/cpu.h: Re-added EPC to the task context.
+
+2002-02-27 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * cpu_asm.S: Fixed exception return address, modified FP context
+ switch so FPU is properly enabled and also doesn't screw up the
+ exception FP handling.
+ * idtcpu.h: Added C0_TAR, the MIPS target address register used for
+ returning from exceptions.
+ * iregdef.h: Added R_TAR to the stack frame so the target address
+ can be saved on a per-exception basis. The new entry is past the
+ end of the frame gdb cares about, so doesn't affect gdb or cpu.h
+ stuff.
+ * rtems/score/cpu.h: added an #ifdef so cpu_asm.S can include it
+ to obtain FPU defines without syntax errors generated by the C
+ defintions.
+ * cpu.c: Improved interrupt level saves & restores.
+
+2002-02-08 Joel Sherrill <joel@OARcorp.com>
+
+ * iregdef.h, rtems/score/cpu.h: Reordered register in the
+ exception stack frame to better match gdb's expectations.
+
+2001-02-05 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S: Enhanced to save/restore more registers on
+ exceptions.
+ * rtems/score/cpu.h (CPU_Interrupt_frame): Enhanced to list every
+ register individually and document when it is saved.
+ * idtcpu.h: Added constants for the coprocessor 1 registers
+ revision and status.
+
+2001-02-05 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/Makefile.am, rtems/score/Makefile.am: Removed again.
+
+2001-02-04 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: IDLE task should not be FP. This was a mistake
+ in the previous patch that has now been confirmed.
+
+2001-02-01 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * cpu.c: Enhancements and fixes for modifying the SR when changing
+ the interrupt level.
+ * cpu_asm.S: Fixed handling of FP enable bit so it is properly
+ managed on a per-task basis, improved handling of interrupt levels,
+ and made deferred FP contexts work on the MIPS.
+ * rtems/score/cpu.h: Modified to support above changes.
+
+2002-01-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ * Makefile.am: Reflect changes above.
+
+2002-02-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * asm.h: Remove #include <rtems/score/targopts.h>.
+ Add #include <rtems/score/cpuopts.h>.
+ * configure.ac: Remove RTEMS_CHECK_CUSTOM_BSP(RTEMS_BSP).
+
+
+2001-12-20 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use RTEMS_ENV_RTEMSCPU.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-12 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S: _CPU_Context_save_fp in was incorrectly in conditional
+ compilation block with (CPU_HARDWARE_FP == FALSE). Reported by
+ Wayne Bullaughey <wayne@wmi.com>.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-07-03 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Fixed typo.
+
+2000-05-24 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/mips.h: Added constants for MIPS exception numbers.
+ All exceptions should be given low numbers and thus can be installed
+ and processed in a uniform manner. Variances between various MIPS
+ ISA levels were not accounted for.
+
+2001-05-24 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * Assisted in design and debug by Joel Sherrill <joel@OARcorp.com>.
+ * cpu_asm.S: Now works on Mongoose-V. Missed in previous patch.
+
+2001-05-22 Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+ * rtems/score/cpu.h: Add the interrupt stack structure and enhance
+ the context initialization to account for floating point tasks.
+ * rtems/score/mips.h: Added the routines mips_set_cause(),
+ mips_get_fcr31(), and mips_set_fcr31().
+ * Assisted in design and debug by Joel Sherrill <joel@OARcorp.com>.
+
+2001-05-07 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S: Merged patches from Gregory Menke
+ <Gregory.D.Menke.1@gsfc.nasa.gov> that clean up
+ stack usage and include nops in the delay slots.
+
+2001-04-20 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S: Added code to save and restore SR and EPC to
+ properly support nested interrupts. Note that the ISR
+ (not RTEMS) enables interrupts allowing the nesting to occur.
+
+2001-03-14 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h, rtems/score/mipstypes.h:
+ Removed unused variable _CPU_Thread_dispatch_pointer
+ and cleaned numerous comments.
+
+2001-03-13 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, cpu_asm.S, iregdef.h, rtems/score/cpu.h, rtems/score/mips.h:
+ Merged MIPS1 and MIPS3 code reducing the number of lines of assembly.
+ Also reimplemented some assembly routines in C further reducing
+ the amount of assembly and increasing maintainability.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-12 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/mips.h (mips_get_sr, mips_set_sr): Corrected
+ register constraints from "general" to "register".
+
+2001-01-09 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S: Use SR_INTERRUPT_ENABLE_BITS instead of SR_XXX constants
+ to make it easier to conditionalize the code for various ISA levels.
+
+2001-01-08 Joel Sherrill <joel@OARcorp.com>
+
+ * idtcpu.h: Commented out definition of "wait". It was stupid to
+ use such a common word as a macro.
+ * rtems/score/cpu.h (_CPU_ISR_Disable): Fixed for mips ISA 3.
+ * rtems/score/mips.h: Added include of <idtcpu.h>.
+ * rtems/score/mips.h (mips_enable_in_interrupt_mask): Corrected.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+ * cpu_asm.S: Eliminated warning for duplicate definition of EXTERN.
+
+2000-12-19 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S (_ISR_Handler): Return to the address in the EPC register.
+ Previous code resulting in the interrupted immediately returning
+ to the caller of the routine it was inside.
+
+2000-12-19 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c (_CPU_Initialize): Do not initialize _ISR_Vector_table() here
+ because it has not been allocated yet.
+
+2000-12-13 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Removed duplicate declaration for _ISR_Vector_table.
+ * cpu_asm.S: Removed assembly language to vector ISR handler
+ on MIPS ISA I. Now call mips_vector_isr_handlers() in libcpu or BSP.
+ * rtems/score/cpu.h (CPU_INTERRUPT_NUMBER_OF_VECTORS): No
+ longer a constant -- get the real value from libcpu.
+
+2000-12-13 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.h: Removed.
+ * Makefile.am: Remove cpu_asm.h.
+ * rtems/score/mips64orion.h: Renamed mips.h.
+ * rtems/score/mips.h: New file, formerly mips64orion.h.
+ Header rewritten.
+ (mips_get_sr, mips_set_sr, mips_enable_in_interrupt_mask,
+ mips_disable_in_interrupt_mask): New macros.
+ * rtems/score/Makefile.am: Reflect renaming mips64orion.h.
+ * asm.h: Include <mips.h> not <mips64orion.h>. Now includes the
+ few defines that were in <cpu_asm.h>.
+ * cpu.c (_CPU_ISR_Get_level): Added MIPS ISA I version of this routine.
+ MIPS ISA 3 is still in assembly for now.
+ (_CPU_Thread_Idle_body): Rewrote in C.
+ * cpu_asm.S: Rewrote file header.
+ (FRAME,ENDFRAME) now in asm.h.
+ (_CPU_ISR_Get_level): Removed ISA I version and rewrote in C.
+ (_CPU_ISR_Set_level): Removed ISA I version and rewrote in C.
+ (_CPU_Context_switch): MIPS ISA I now manages preserves SR_IEC and
+ leaves other bits in SR alone on task switch.
+ (mips_enable_interrupts,mips_disable_interrupts,
+ mips_enable_global_interrupts,mips_disable_global_interrupts,
+ disable_int, enable_int): Removed.
+ (mips_get_sr): Rewritten as C macro.
+ (_CPU_Thread_Idle_body): Rewritten in C.
+ (init_exc_vecs): Rewritten in C as mips_install_isr_entries() and
+ placed in libcpu.
+ (exc_tlb_code, exc_xtlb_code, exc_cache_code, exc_norm_code): Moved
+ to libcpu/mips/shared/interrupts.
+ (general): Cleaned up comment blocks and #if 0 areas.
+ * idtcpu.h: Made ifdef report an error.
+ * iregdef.h: Removed warning.
+ * rtems/score/cpu.h (CPU_INTERRUPT_NUMBER_OF_VECTORS): Now a variable
+ number defined by libcpu.
+ (_CPU_ISR_Disable, _CPU_ISR_Enable): Rewritten to use new routines
+ to access SR.
+ (_CPU_ISR_Set_level): Rewritten as macro for ISA I.
+ (_CPU_Context_Initialize): Honor ISR level in task initialization.
+ (_CPU_Fatal_halt): Use new _CPU_ISR_Disable() macro.
+
+2000-12-06 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: When mips ISA level is 1, registers in the
+ context should be 32 not 64 bits.
+
+2000-11-30 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.S: Changed "_CPU_Ccontext_switch_restore: typo to
+ correct name of _CPU_Context_switch_restore. Added dummy
+ version of exc_utlb_code() so applications would link.
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-10-24 Alan Cudmore <alanc@linuxstart.com> and
+ Joel Sherrill <joel@OARcorp.com>
+
+ * This is a major reworking of the mips64orion port to use
+ gcc predefines as much as possible and a big push to multilib
+ the mips port. The mips64orion port was copied/renamed to mips
+ to be more like other GNU tools. Alan did most of the technical
+ work of determining how to map old macro names used by the mips64orion
+ port to standard compiler macro definitions. Joel did the merge
+ with CVS magic to keep individual file history and did the BSP
+ modifications. Details follow:
+ * Makefile.am: idtmon.h in mips64orion port not present.
+ * asm.h: MIPS64ORION replaced with MIPS. Frame setup macros added.
+ * cpu.c: Comments added.
+ * cpu_asm.S: Conditionals changed. MIPS ISA level 1 support added.
+ First attempt at exception/interrupt processing for ISA level 1
+ and minus any use of IDT/MON added.
+ * idtcpu.h: Conditionals changed to use gcc predefines.
+ * iregdef.h: Ditto.
+ * cpu_asm.h: No real change. Merger required commit.
+ * rtems/Makefile.am: Ditto.
+ * rtems/score/Makefile.am: Ditto.
+ * rtems/score/cpu.h: Change MIPS64ORION to MIPS.
+ * rtems/score/mips64orion.h: Change MIPS64ORION to MIPS. Convert
+ from using RTEMS_CPU_MODEL to gcc predefines to figre things out.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/mips/Makefile.am b/cpukit/score/cpu/mips/Makefile.am
new file mode 100644
index 0000000000..bb7d3faf4b
--- /dev/null
+++ b/cpukit/score/cpu/mips/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_mipsdir = $(includedir)/rtems/mips
+include_rtems_mips_HEADERS = rtems/mips/idtcpu.h rtems/mips/iregdef.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/mips.h \
+ rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/mips/cpu.c b/cpukit/score/cpu/mips/cpu.c
new file mode 100644
index 0000000000..e547e4d684
--- /dev/null
+++ b/cpukit/score/cpu/mips/cpu.c
@@ -0,0 +1,325 @@
+/*
+ * Mips CPU Dependent Source
+ *
+ * 2002: Greg Menke (gregory.menke@gsfc.nasa.gov)
+ * Overhauled interrupt level and interrupt enable/disable code
+ * to more exactly support MIPS. Our mods were for MIPS1 processors
+ * MIPS3 ports are affected, though apps written to the old behavior
+ * should still work OK.
+ *
+ * Conversion to MIPS port by Alan Cudmore <alanc@linuxstart.com> and
+ * Joel Sherrill <joel@OARcorp.com>.
+ *
+ * These changes made the code conditional on standard cpp predefines,
+ * merged the mips1 and mips3 code sequences as much as possible,
+ * and moved some of the assembly code to C. Alan did much of the
+ * initial analysis and rework. Joel took over from there and
+ * wrote the JMR3904 BSP so this could be tested. Joel also
+ * added the new interrupt vectoring support in libcpu and
+ * tried to better support the various interrupt controllers.
+ *
+ * Original MIP64ORION port by Craig Lebakken <craigl@transition.com>
+ * COPYRIGHT (c) 1996 by Transition Networks Inc.
+ *
+ * To anyone who acknowledges that this file is provided "AS IS"
+ * without any express or implied warranty:
+ * permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies, and that the name of Transition Networks not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * Transition Networks makes no representations about the
+ * suitability of this software for any purpose.
+ *
+ * COPYRIGHT (c) 1989-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+
+/*
+** Exception stack frame pointer used in cpu_asm to pass the exception stack frame
+** address to the context switch code.
+*/
+#if (__mips == 1) || (__mips == 32)
+typedef uint32_t ESF_PTR_TYPE;
+#elif (__mips == 3)
+typedef uint64_t ESF_PTR_TYPE;
+#else
+#error "unknown MIPS ISA"
+#endif
+
+ESF_PTR_TYPE __exceptionStackFrame = 0;
+
+
+
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * thread_dispatch - address of dispatching routine
+ */
+
+void _CPU_Initialize(void)
+{
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+#if CPU_HARDWARE_FP
+ /* FP context initialization support goes here */
+ _CPU_Null_fp_context.fpcs = 0x1000000; /* Set FS flag in floating point coprocessor
+ control register to prevent underflow and
+ inexact exceptions */
+#endif
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * This routine returns the current interrupt level.
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ unsigned int sr;
+
+ mips_get_sr(sr);
+
+ /* printf("current sr=%08X, ",sr); */
+
+#if (__mips == 3) || (__mips == 32)
+/* IE bit and shift down hardware ints into bits 1 thru 6 */
+ sr = (sr & SR_IE) | ((sr & mips_interrupt_mask()) >> 9);
+
+#elif __mips == 1
+/* IEC bit and shift down hardware ints into bits 1 thru 6 */
+ sr = (sr & SR_IEC) | ((sr & mips_interrupt_mask()) >> 9);
+
+#else
+#error "CPU ISR level: unknown MIPS level for SR handling"
+#endif
+ return sr;
+}
+
+
+void _CPU_ISR_Set_level( uint32_t new_level )
+{
+ unsigned int sr, srbits;
+
+ /*
+ ** mask off the int level bits only so we can
+ ** preserve software int settings and FP enable
+ ** for this thread. Note we don't force software ints
+ ** enabled when changing level, they were turned on
+ ** when this task was created, but may have been turned
+ ** off since, so we'll just leave them alone.
+ */
+
+ new_level &= 0xff;
+
+ mips_get_sr(sr);
+
+#if (__mips == 3) || (__mips == 32)
+ mips_set_sr( (sr & ~SR_IE) ); /* first disable ie bit (recommended) */
+
+ srbits = sr & ~(0xfc00 | SR_IE);
+
+ sr = srbits | ((new_level==0)? (mips_interrupt_mask() | SR_IE): \
+ (((new_level<<9) & mips_interrupt_mask()) | \
+ ((new_level & 1)?SR_IE:0)));
+/*
+ if ( (new_level & SR_EXL) == (sr & SR_EXL) )
+ return;
+
+ if ( (new_level & SR_EXL) == 0 ) {
+ sr &= ~SR_EXL; * clear the EXL bit *
+ mips_set_sr(sr);
+ } else {
+
+ sr |= SR_EXL|SR_IE; * enable exception level *
+ mips_set_sr(sr); * first disable ie bit (recommended) *
+ }
+*/
+
+#elif __mips == 1
+ mips_set_sr( (sr & ~SR_IEC) );
+ srbits = sr & ~(0xfc00 | SR_IEC);
+ sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc00) | \
+ (new_level & SR_IEC)));
+#else
+#error "CPU ISR level: unknown MIPS level for SR handling"
+#endif
+ mips_set_sr( sr );
+}
+
+
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ *
+ * Because all interrupts are vectored through the same exception handler
+ * this is not necessary on thi sport.
+ */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, _ISR_Handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+/* we don't support this yet */
+}
+
+/*
+ * _CPU_Context_Initialize
+ *
+ * This kernel routine initializes the basic non-FP context area associated
+ * with each thread.
+ *
+ * Input parameters:
+ * the_context - pointer to the context area
+ * stack_base - address of memory for the SPARC
+ * size - size in bytes of the stack area
+ * new_level - interrupt level for this context area
+ * entry_point - the starting execution point for this this context
+ * is_fp - TRUE if this context is associated with an FP thread
+ *
+ * Output parameters: NONE
+ */
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uintptr_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ uintptr_t stack_tmp;
+ __MIPS_REGISTER_TYPE intlvl = new_level & 0xff;
+
+ stack_tmp = (uintptr_t)stack_base;
+ stack_tmp += ((size) - CPU_STACK_ALIGNMENT);
+ stack_tmp &= (__MIPS_REGISTER_TYPE) ~(CPU_STACK_ALIGNMENT - 1);
+
+ the_context->sp = (__MIPS_REGISTER_TYPE) stack_tmp;
+ the_context->fp = (__MIPS_REGISTER_TYPE) stack_tmp;
+ the_context->ra = (__MIPS_REGISTER_TYPE) (uintptr_t)entry_point;
+ the_context->c0_sr =
+ ((intlvl==0)? (mips_interrupt_mask() | 0x300 | _INTON):
+ ( ((intlvl<<9) & mips_interrupt_mask()) | 0x300 |
+ ((intlvl & 1)?_INTON:0)) ) |
+ SR_CU0 | ((is_fp)?SR_CU1:0) | _EXTRABITS;
+}
+
+
+/*PAGE
+ *
+ * _CPU_Internal_threads_Idle_thread_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+#if (__mips == 3) || (__mips == 32)
+ for( ; ; )
+ __asm__ volatile("wait"); /* use wait to enter low power mode */
+#elif __mips == 1
+ for( ; ; )
+ ;
+#else
+#error "IDLE: __mips not set to 1 or 3"
+#endif
+}
diff --git a/cpukit/score/cpu/mips/cpu_asm.S b/cpukit/score/cpu/mips/cpu_asm.S
new file mode 100644
index 0000000000..cc52aa81ce
--- /dev/null
+++ b/cpukit/score/cpu/mips/cpu_asm.S
@@ -0,0 +1,1137 @@
+/*
+ * This file contains the basic algorithms for all assembly code used
+ * in an specific CPU port of RTEMS. These algorithms must be implemented
+ * in assembly language
+ *
+ * History:
+ * Baseline: no_cpu
+ * 1996: Ported to MIPS64ORION by Craig Lebakken <craigl@transition.com>
+ * COPYRIGHT (c) 1996 by Transition Networks Inc.
+ * To anyone who acknowledges that the modifications to this file to
+ * port it to the MIPS64ORION are provided "AS IS" without any
+ * express or implied warranty:
+ * permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies, and that the name of Transition Networks not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. Transition
+ * Networks makes no representations about the suitability
+ * of this software for any purpose.
+ * 2000: Reworked by Alan Cudmore <alanc@linuxstart.com> to become
+ * the baseline of the more general MIPS port.
+ * 2001: Joel Sherrill <joel@OARcorp.com> continued this rework,
+ * rewriting as much as possible in C and added the JMR3904 BSP
+ * so testing could be performed on a simulator.
+ * 2001: Greg Menke <gregory.menke@gsfc.nasa.gov>, bench tested ISR
+ * performance, tweaking this code and the isr vectoring routines
+ * to reduce overhead & latencies. Added optional
+ * instrumentation as well.
+ * 2002: Greg Menke <gregory.menke@gsfc.nasa.gov>, overhauled cpu_asm.S,
+ * cpu.c and cpu.h to manage FP vs int only tasks, interrupt levels
+ * and deferred FP contexts.
+ * 2002: Joel Sherrill <joel@OARcorp.com> enhanced the exception processing
+ * by increasing the amount of context saved/restored.
+ * 2004: 24March, Art Ferrer, NASA/GSFC, added save of FP status/control
+ * register to fix intermittent FP error encountered on ST5 mission
+ * implementation on Mongoose V processor.
+ * 2004: April 7, Greg Menke <gregory.menke@gsfc.nasa.gov> Added __mips==32
+ * support for R4000 processors running 32 bit code. Fixed #define
+ * problems that caused fpu code to always be included even when no
+ * fpu is present.
+ *
+ * COPYRIGHT (c) 1989-2002.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/mips/iregdef.h>
+#include <rtems/mips/idtcpu.h>
+#include <rtems/score/percpu.h>
+
+#define ASSEMBLY_ONLY
+#include <rtems/score/cpu.h>
+
+#if TRUE
+#else
+#error TRUE is not true
+#endif
+#if FALSE
+#error FALSE is not false
+#else
+#endif
+
+/*
+#if ( CPU_HARDWARE_FP == TRUE )
+#warning CPU_HARDWARE_FP == TRUE
+#else
+#warning CPU_HARDWARE_FP != TRUE
+#endif
+*/
+
+
+/* enable debugging shadow writes to misc ram, this is a vestigal
+* Mongoose-ism debug tool- but may be handy in the future so we
+* left it in...
+*/
+
+/* #define INSTRUMENT_ISR_VECTORING */
+/* #define INSTRUMENT_EXECUTING_THREAD */
+
+
+
+/* Ifdefs prevent the duplication of code for MIPS ISA Level 3 ( R4xxx )
+ * and MIPS ISA Level 1 (R3xxx).
+ */
+
+#if __mips == 3
+/* 64 bit register operations */
+#define NOP nop
+#define ADD dadd
+#define STREG sd
+#define LDREG ld
+#define MFCO dmfc0 /* Only use this op for coprocessor registers that are 64 bit in R4000 architecture */
+#define MTCO dmtc0 /* Only use this op for coprocessor registers that are 64 bit in R4000 architecture */
+#define ADDU addu
+#define ADDIU addiu
+#if (__mips_fpr==32)
+#define STREGC1 swc1
+#define LDREGC1 lwc1
+#elif (__mips_fpr==64) /* Use these instructions if there are 64 bit floating point registers. This requires FR bit to be set in C0_SR */
+#define STREGC1 sdc1
+#define LDREGC1 ldc1
+#endif
+#define R_SZ 8
+#define F_SZ 8
+#define SZ_INT 8
+#define SZ_INT_POW2 3
+
+/* XXX if we don't always want 64 bit register ops, then another ifdef */
+
+#elif (__mips == 1 ) || (__mips == 32)
+/* 32 bit register operations*/
+#define NOP nop
+#define ADD add
+#define STREG sw
+#define LDREG lw
+#define MFCO mfc0
+#define MTCO mtc0
+#define ADDU add
+#define ADDIU addi
+#define STREGC1 swc1
+#define LDREGC1 lwc1
+#define R_SZ 4
+#define F_SZ 4
+#define SZ_INT 4
+#define SZ_INT_POW2 2
+#else
+#error "mips assembly: what size registers do I deal with?"
+#endif
+
+
+#define ISR_VEC_SIZE 4
+#define EXCP_STACK_SIZE (NREGS*R_SZ)
+
+
+#ifdef __GNUC__
+#define ASM_EXTERN(x,size) .extern x,size
+#else
+#define ASM_EXTERN(x,size)
+#endif
+
+/* NOTE: these constants must match the Context_Control structure in cpu.h */
+#define S0_OFFSET 0
+#define S1_OFFSET 1
+#define S2_OFFSET 2
+#define S3_OFFSET 3
+#define S4_OFFSET 4
+#define S5_OFFSET 5
+#define S6_OFFSET 6
+#define S7_OFFSET 7
+#define SP_OFFSET 8
+#define FP_OFFSET 9
+#define RA_OFFSET 10
+#define C0_SR_OFFSET 11
+#define C0_EPC_OFFSET 12
+
+/* NOTE: these constants must match the Context_Control_fp structure in cpu.h */
+#define FP0_OFFSET 0
+#define FP1_OFFSET 1
+#define FP2_OFFSET 2
+#define FP3_OFFSET 3
+#define FP4_OFFSET 4
+#define FP5_OFFSET 5
+#define FP6_OFFSET 6
+#define FP7_OFFSET 7
+#define FP8_OFFSET 8
+#define FP9_OFFSET 9
+#define FP10_OFFSET 10
+#define FP11_OFFSET 11
+#define FP12_OFFSET 12
+#define FP13_OFFSET 13
+#define FP14_OFFSET 14
+#define FP15_OFFSET 15
+#define FP16_OFFSET 16
+#define FP17_OFFSET 17
+#define FP18_OFFSET 18
+#define FP19_OFFSET 19
+#define FP20_OFFSET 20
+#define FP21_OFFSET 21
+#define FP22_OFFSET 22
+#define FP23_OFFSET 23
+#define FP24_OFFSET 24
+#define FP25_OFFSET 25
+#define FP26_OFFSET 26
+#define FP27_OFFSET 27
+#define FP28_OFFSET 28
+#define FP29_OFFSET 29
+#define FP30_OFFSET 30
+#define FP31_OFFSET 31
+#define FPCS_OFFSET 32
+
+
+ASM_EXTERN(__exceptionStackFrame, SZ_INT)
+
+/*
+ * _CPU_Context_save_fp_context
+ *
+ * This routine is responsible for saving the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ */
+
+/* void _CPU_Context_save_fp(
+ * void **fp_context_ptr
+ * );
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE )
+FRAME(_CPU_Context_save_fp,sp,0,ra)
+ .set noreorder
+ .set noat
+
+ /*
+ ** Make sure the FPU is on before we save state. This code
+ ** is here because the FPU context switch might occur when an
+ ** integer task is switching out with a FP task switching in.
+ */
+ mfc0 t0,C0_SR
+ li t2,SR_CU1
+ move t1,t0
+ or t0,t2 /* turn on the fpu */
+#if (__mips == 3) || (__mips == 32)
+ li t2,SR_IE
+#elif __mips == 1
+ li t2,SR_IEC
+#endif
+ not t2
+ and t0,t2 /* turn off interrupts */
+ mtc0 t0,C0_SR
+
+ lw a1,(a0) /* get address of context storage area */
+ move t0,ra
+ jal _CPU_Context_save_fp_from_exception
+ NOP
+
+ /*
+ ** Reassert the task's state because we've not saved it yet.
+ */
+ mtc0 t1,C0_SR
+ j t0
+ NOP
+
+ .globl _CPU_Context_save_fp_from_exception
+_CPU_Context_save_fp_from_exception:
+ STREGC1 $f0,FP0_OFFSET*F_SZ(a1)
+ STREGC1 $f1,FP1_OFFSET*F_SZ(a1)
+ STREGC1 $f2,FP2_OFFSET*F_SZ(a1)
+ STREGC1 $f3,FP3_OFFSET*F_SZ(a1)
+ STREGC1 $f4,FP4_OFFSET*F_SZ(a1)
+ STREGC1 $f5,FP5_OFFSET*F_SZ(a1)
+ STREGC1 $f6,FP6_OFFSET*F_SZ(a1)
+ STREGC1 $f7,FP7_OFFSET*F_SZ(a1)
+ STREGC1 $f8,FP8_OFFSET*F_SZ(a1)
+ STREGC1 $f9,FP9_OFFSET*F_SZ(a1)
+ STREGC1 $f10,FP10_OFFSET*F_SZ(a1)
+ STREGC1 $f11,FP11_OFFSET*F_SZ(a1)
+ STREGC1 $f12,FP12_OFFSET*F_SZ(a1)
+ STREGC1 $f13,FP13_OFFSET*F_SZ(a1)
+ STREGC1 $f14,FP14_OFFSET*F_SZ(a1)
+ STREGC1 $f15,FP15_OFFSET*F_SZ(a1)
+ STREGC1 $f16,FP16_OFFSET*F_SZ(a1)
+ STREGC1 $f17,FP17_OFFSET*F_SZ(a1)
+ STREGC1 $f18,FP18_OFFSET*F_SZ(a1)
+ STREGC1 $f19,FP19_OFFSET*F_SZ(a1)
+ STREGC1 $f20,FP20_OFFSET*F_SZ(a1)
+ STREGC1 $f21,FP21_OFFSET*F_SZ(a1)
+ STREGC1 $f22,FP22_OFFSET*F_SZ(a1)
+ STREGC1 $f23,FP23_OFFSET*F_SZ(a1)
+ STREGC1 $f24,FP24_OFFSET*F_SZ(a1)
+ STREGC1 $f25,FP25_OFFSET*F_SZ(a1)
+ STREGC1 $f26,FP26_OFFSET*F_SZ(a1)
+ STREGC1 $f27,FP27_OFFSET*F_SZ(a1)
+ STREGC1 $f28,FP28_OFFSET*F_SZ(a1)
+ STREGC1 $f29,FP29_OFFSET*F_SZ(a1)
+ STREGC1 $f30,FP30_OFFSET*F_SZ(a1)
+ STREGC1 $f31,FP31_OFFSET*F_SZ(a1)
+ cfc1 a0,$31 /* Read FP status/conrol reg */
+ cfc1 a0,$31 /* Two reads clear pipeline */
+ NOP
+ NOP
+ sw a0, FPCS_OFFSET*F_SZ(a1) /* Store value to FPCS location */
+ NOP
+ j ra
+ NOP
+ .set at
+ENDFRAME(_CPU_Context_save_fp)
+#endif
+
+/*
+ * _CPU_Context_restore_fp_context
+ *
+ * This routine is responsible for restoring the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ */
+
+/* void _CPU_Context_restore_fp(
+ * void **fp_context_ptr
+ * )
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE )
+FRAME(_CPU_Context_restore_fp,sp,0,ra)
+ .set noat
+ .set noreorder
+
+ /*
+ ** Make sure the FPU is on before we retrieve state. This code
+ ** is here because the FPU context switch might occur when an
+ ** integer task is switching out with a FP task switching in.
+ */
+ mfc0 t0,C0_SR
+ li t2,SR_CU1
+ move t1,t0
+ or t0,t2 /* turn on the fpu */
+#if (__mips == 3) || (__mips == 32)
+ li t2,SR_IE
+#elif __mips == 1
+ li t2,SR_IEC
+#endif
+ not t2
+ and t0,t2 /* turn off interrupts */
+ mtc0 t0,C0_SR
+
+ lw a1,(a0) /* get address of context storage area */
+ move t0,ra
+ jal _CPU_Context_restore_fp_from_exception
+ NOP
+
+ /*
+ ** Reassert the old task's state because we've not restored the
+ ** new one yet.
+ */
+ mtc0 t1,C0_SR
+ j t0
+ NOP
+
+ .globl _CPU_Context_restore_fp_from_exception
+_CPU_Context_restore_fp_from_exception:
+ LDREGC1 $f0,FP0_OFFSET*F_SZ(a1)
+ LDREGC1 $f1,FP1_OFFSET*F_SZ(a1)
+ LDREGC1 $f2,FP2_OFFSET*F_SZ(a1)
+ LDREGC1 $f3,FP3_OFFSET*F_SZ(a1)
+ LDREGC1 $f4,FP4_OFFSET*F_SZ(a1)
+ LDREGC1 $f5,FP5_OFFSET*F_SZ(a1)
+ LDREGC1 $f6,FP6_OFFSET*F_SZ(a1)
+ LDREGC1 $f7,FP7_OFFSET*F_SZ(a1)
+ LDREGC1 $f8,FP8_OFFSET*F_SZ(a1)
+ LDREGC1 $f9,FP9_OFFSET*F_SZ(a1)
+ LDREGC1 $f10,FP10_OFFSET*F_SZ(a1)
+ LDREGC1 $f11,FP11_OFFSET*F_SZ(a1)
+ LDREGC1 $f12,FP12_OFFSET*F_SZ(a1)
+ LDREGC1 $f13,FP13_OFFSET*F_SZ(a1)
+ LDREGC1 $f14,FP14_OFFSET*F_SZ(a1)
+ LDREGC1 $f15,FP15_OFFSET*F_SZ(a1)
+ LDREGC1 $f16,FP16_OFFSET*F_SZ(a1)
+ LDREGC1 $f17,FP17_OFFSET*F_SZ(a1)
+ LDREGC1 $f18,FP18_OFFSET*F_SZ(a1)
+ LDREGC1 $f19,FP19_OFFSET*F_SZ(a1)
+ LDREGC1 $f20,FP20_OFFSET*F_SZ(a1)
+ LDREGC1 $f21,FP21_OFFSET*F_SZ(a1)
+ LDREGC1 $f22,FP22_OFFSET*F_SZ(a1)
+ LDREGC1 $f23,FP23_OFFSET*F_SZ(a1)
+ LDREGC1 $f24,FP24_OFFSET*F_SZ(a1)
+ LDREGC1 $f25,FP25_OFFSET*F_SZ(a1)
+ LDREGC1 $f26,FP26_OFFSET*F_SZ(a1)
+ LDREGC1 $f27,FP27_OFFSET*F_SZ(a1)
+ LDREGC1 $f28,FP28_OFFSET*F_SZ(a1)
+ LDREGC1 $f29,FP29_OFFSET*F_SZ(a1)
+ LDREGC1 $f30,FP30_OFFSET*F_SZ(a1)
+ LDREGC1 $f31,FP31_OFFSET*F_SZ(a1)
+ cfc1 a0,$31 /* Read from FP status/control reg */
+ cfc1 a0,$31 /* Two reads clear pipeline */
+ NOP /* NOPs ensure execution */
+ NOP
+ lw a0,FPCS_OFFSET*F_SZ(a1) /* Load saved FPCS value */
+ NOP
+ ctc1 a0,$31 /* Restore FPCS register */
+ NOP
+ j ra
+ NOP
+ .set at
+ENDFRAME(_CPU_Context_restore_fp)
+#endif
+
+/* _CPU_Context_switch
+ *
+ * This routine performs a normal non-FP context switch.
+ */
+
+/* void _CPU_Context_switch(
+ * Context_Control *run,
+ * Context_Control *heir
+ * )
+ */
+
+FRAME(_CPU_Context_switch,sp,0,ra)
+ .set noreorder
+
+ mfc0 t0,C0_SR
+#if (__mips == 3) || (__mips == 32)
+ li t1,SR_IE
+#elif __mips == 1
+ li t1,SR_IEC
+#endif
+ STREG t0,C0_SR_OFFSET*R_SZ(a0) /* save the task's SR */
+ not t1
+ and t0,t1 /* mask off interrupts while we context switch */
+ mtc0 t0,C0_SR
+ NOP
+
+ STREG ra,RA_OFFSET*R_SZ(a0) /* save current context */
+ STREG sp,SP_OFFSET*R_SZ(a0)
+ STREG fp,FP_OFFSET*R_SZ(a0)
+ STREG s0,S0_OFFSET*R_SZ(a0)
+ STREG s1,S1_OFFSET*R_SZ(a0)
+ STREG s2,S2_OFFSET*R_SZ(a0)
+ STREG s3,S3_OFFSET*R_SZ(a0)
+ STREG s4,S4_OFFSET*R_SZ(a0)
+ STREG s5,S5_OFFSET*R_SZ(a0)
+ STREG s6,S6_OFFSET*R_SZ(a0)
+ STREG s7,S7_OFFSET*R_SZ(a0)
+
+
+ /*
+ ** this code grabs the userspace EPC if we're dispatching from
+ ** an interrupt frame or supplies the address of the dispatch
+ ** routines if not. This is entirely for the gdbstub's benefit so
+ ** it can know where each task is running.
+ **
+ ** Its value is only set when calling threadDispatch from
+ ** the interrupt handler and is cleared immediately when this
+ ** routine gets it.
+ */
+
+ la t0,__exceptionStackFrame /* see if we're coming in from an exception */
+ LDREG t1, (t0)
+ NOP
+ beqz t1,1f
+
+ STREG zero, (t0) /* and clear it */
+ NOP
+ LDREG t0,R_EPC*R_SZ(t1) /* get the userspace EPC from the frame */
+ b 2f
+ NOP
+
+1: la t0,_Thread_Dispatch /* if ==0, we're switched out */
+
+2: STREG t0,C0_EPC_OFFSET*R_SZ(a0)
+
+
+_CPU_Context_switch_restore:
+ LDREG ra,RA_OFFSET*R_SZ(a1) /* restore context */
+ LDREG sp,SP_OFFSET*R_SZ(a1)
+ LDREG fp,FP_OFFSET*R_SZ(a1)
+ LDREG s0,S0_OFFSET*R_SZ(a1)
+ LDREG s1,S1_OFFSET*R_SZ(a1)
+ LDREG s2,S2_OFFSET*R_SZ(a1)
+ LDREG s3,S3_OFFSET*R_SZ(a1)
+ LDREG s4,S4_OFFSET*R_SZ(a1)
+ LDREG s5,S5_OFFSET*R_SZ(a1)
+ LDREG s6,S6_OFFSET*R_SZ(a1)
+ LDREG s7,S7_OFFSET*R_SZ(a1)
+
+ LDREG t0, C0_SR_OFFSET*R_SZ(a1)
+
+/* NOP */
+/*#if (__mips == 3) || (__mips == 32) */
+/* andi t0,SR_EXL */
+/* bnez t0,_CPU_Context_1 */ /* set exception level from restore context */
+/* li t0,~SR_EXL */
+/* MFC0 t1,C0_SR */
+/* NOP */
+/* and t1,t0 */
+/* MTC0 t1,C0_SR */
+/* */
+/*#elif __mips == 1 */
+/* */
+/* andi t0,(SR_INTERRUPT_ENABLE_BITS) */ /* we know 0 disabled */
+/* beq t0,$0,_CPU_Context_1 */ /* set level from restore context */
+/* MFC0 t0,C0_SR */
+/* NOP */
+/* or t0,(SR_INTERRUPT_ENABLE_BITS) */ /* new_sr = old sr with enabled */
+/* MTC0 t0,C0_SR */ /* set with enabled */
+/* NOP */
+
+
+/*
+** Incorporate the incoming task's FP coprocessor state and interrupt mask/enable
+** into the status register. We jump thru the requisite hoops to ensure we
+** maintain all other SR bits as global values.
+**
+** Get the task's FPU enable, int mask & int enable bits. Although we keep the
+** software int enables on a per-task basis, the rtems_task_create
+** Interrupt Level & int level manipulation functions cannot enable/disable them,
+** so they are automatically enabled for all tasks. To turn them off, a task
+** must itself manipulate the SR register.
+**
+** Although something of a hack on this processor, we treat the SR register
+** int enables as the RTEMS interrupt level. We use the int level
+** value as a bitmask, not as any sort of greater than/less than metric.
+** Manipulation of a task's interrupt level corresponds directly to manipulation
+** of that task's SR bits, as seen in cpu.c
+**
+** Note, interrupts are disabled before context is saved, though the task's
+** interrupt enable state is recorded. The task swapping in will apply its
+** specific SR bits, including interrupt enable. If further task-specific
+** SR bits are arranged, it is this code, the cpu.c interrupt level stuff and
+** cpu.h task initialization code that will be affected.
+*/
+
+ li t2,SR_CU1
+ or t2,SR_IMASK
+
+ /* int enable bits */
+#if (__mips == 3) || (__mips == 32)
+ /*
+ ** Save IE
+ */
+ or t2,SR_IE
+#elif __mips == 1
+ /*
+ ** Save current, previous & old int enables. This is key because
+ ** we can dispatch from within the stack frame used by an
+ ** interrupt service. The int enables nest, but not beyond
+ ** previous and old because of the dispatch interlock seen
+ ** in the interrupt processing code.
+ */
+ or t2,SR_IEC + SR_IEP + SR_IEO
+#endif
+ and t0,t2 /* keep only the per-task bits */
+
+ mfc0 t1,C0_SR /* grab the current SR */
+ not t2
+ and t1,t2 /* mask off the old task's per-task bits */
+ or t1,t0 /* or in the new task's bits */
+ mtc0 t1,C0_SR /* and load the new SR */
+ NOP
+
+/* _CPU_Context_1: */
+ j ra
+ NOP
+ENDFRAME(_CPU_Context_switch)
+
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ *
+ * void _CPU_Context_restore(
+ * Context_Control *new_context
+ * );
+ */
+
+FRAME(_CPU_Context_restore,sp,0,ra)
+ .set noreorder
+ move a1,a0
+ j _CPU_Context_switch_restore
+ NOP
+
+ENDFRAME(_CPU_Context_restore)
+
+ASM_EXTERN(_Thread_Dispatch_disable_level,4)
+
+.extern _Thread_Dispatch
+.extern _ISR_Vector_table
+
+/* void _DBG_Handler()
+ *
+ * This routine services the (at least) MIPS1 debug vector,
+ * only used the the hardware debugging features. This code,
+ * while optional, is best located here because its intrinsically
+ * associated with exceptions in general & thus tied pretty
+ * closely to _ISR_Handler.
+ */
+FRAME(_DBG_Handler,sp,0,ra)
+ .set noreorder
+ la k0,_ISR_Handler
+ j k0
+ NOP
+ .set reorder
+ENDFRAME(_DBG_Handler)
+
+/* void __ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * void _ISR_Handler()
+ *
+ *
+ * This discussion ignores a lot of the ugly details in a real
+ * implementation such as saving enough registers/state to be
+ * able to do something real. Keep in mind that the goal is
+ * to invoke a user's ISR handler which is written in C and
+ * uses a certain set of registers.
+ *
+ * Also note that the exact order is to a large extent flexible.
+ * Hardware will dictate a sequence for a certain subset of
+ * _ISR_Handler while requirements for setting
+ *
+ * At entry to "common" _ISR_Handler, the vector number must be
+ * available. On some CPUs the hardware puts either the vector
+ * number or the offset into the vector table for this ISR in a
+ * known place. If the hardware does not give us this information,
+ * then the assembly portion of RTEMS for this port will contain
+ * a set of distinct interrupt entry points which somehow place
+ * the vector number in a known place (which is safe if another
+ * interrupt nests this one) and branches to _ISR_Handler.
+ *
+ */
+
+FRAME(_ISR_Handler,sp,0,ra)
+ .set noreorder
+
+ /* Q: _ISR_Handler, not using IDT/SIM ...save extra regs? */
+
+ /* wastes a lot of stack space for context?? */
+ ADDIU sp,sp,-EXCP_STACK_SIZE
+
+ STREG ra, R_RA*R_SZ(sp) /* store ra on the stack */
+ STREG v0, R_V0*R_SZ(sp)
+ STREG v1, R_V1*R_SZ(sp)
+ STREG a0, R_A0*R_SZ(sp)
+ STREG a1, R_A1*R_SZ(sp)
+ STREG a2, R_A2*R_SZ(sp)
+ STREG a3, R_A3*R_SZ(sp)
+ STREG t0, R_T0*R_SZ(sp)
+ STREG t1, R_T1*R_SZ(sp)
+ STREG t2, R_T2*R_SZ(sp)
+ STREG t3, R_T3*R_SZ(sp)
+ STREG t4, R_T4*R_SZ(sp)
+ STREG t5, R_T5*R_SZ(sp)
+ STREG t6, R_T6*R_SZ(sp)
+ STREG t7, R_T7*R_SZ(sp)
+ mflo t0
+ STREG t8, R_T8*R_SZ(sp)
+ STREG t0, R_MDLO*R_SZ(sp)
+ STREG t9, R_T9*R_SZ(sp)
+ mfhi t0
+ STREG gp, R_GP*R_SZ(sp)
+ STREG t0, R_MDHI*R_SZ(sp)
+ STREG fp, R_FP*R_SZ(sp)
+
+ .set noat
+ STREG AT, R_AT*R_SZ(sp)
+ .set at
+
+ mfc0 t0,C0_SR
+ MFCO t1,C0_EPC
+ STREG t0,R_SR*R_SZ(sp)
+ STREG t1,R_EPC*R_SZ(sp)
+
+
+#ifdef INSTRUMENT_EXECUTING_THREAD
+ lw t2, THREAD_EXECUTING
+ NOP
+ sw t2, 0x8001FFF0
+#endif
+
+ /* determine if an interrupt generated this exception */
+
+ mfc0 t0,C0_CAUSE
+ NOP
+
+ and t1,t0,CAUSE_EXCMASK
+ beq t1, 0, _ISR_Handler_1
+
+_ISR_Handler_Exception:
+
+ /* If we return from the exception, it is assumed nothing
+ * bad is going on and we can continue to run normally.
+ * But we want to save the entire CPU context so exception
+ * handlers can look at it and change it.
+ *
+ * NOTE: This is the path the debugger stub will take.
+ */
+
+ /* already got t0 = cause in the interrupt test above */
+ STREG t0,R_CAUSE*R_SZ(sp)
+
+ STREG sp, R_SP*R_SZ(sp)
+
+ STREG s0,R_S0*R_SZ(sp) /* save s0 - s7 */
+ STREG s1,R_S1*R_SZ(sp)
+ STREG s2,R_S2*R_SZ(sp)
+ STREG s3,R_S3*R_SZ(sp)
+ STREG s4,R_S4*R_SZ(sp)
+ STREG s5,R_S5*R_SZ(sp)
+ STREG s6,R_S6*R_SZ(sp)
+ STREG s7,R_S7*R_SZ(sp)
+
+ /* CP0 special registers */
+
+#if __mips == 1
+ mfc0 t0,C0_TAR
+#endif
+ MFCO t1,C0_BADVADDR
+
+#if __mips == 1
+ STREG t0,R_TAR*R_SZ(sp)
+#else
+ NOP
+#endif
+ STREG t1,R_BADVADDR*R_SZ(sp)
+
+#if ( CPU_HARDWARE_FP == TRUE )
+ mfc0 t0,C0_SR /* FPU is enabled, save state */
+ NOP
+ srl t0,t0,16
+ andi t0,t0,(SR_CU1 >> 16)
+ beqz t0, 1f
+ NOP
+
+ la a1,R_F0*R_SZ(sp)
+ jal _CPU_Context_save_fp_from_exception
+ NOP
+ mfc1 t0,C1_REVISION
+ mfc1 t1,C1_STATUS
+ STREG t0,R_FEIR*R_SZ(sp)
+ STREG t1,R_FCSR*R_SZ(sp)
+
+1:
+#endif
+
+ move a0,sp
+ jal mips_vector_exceptions
+ NOP
+
+
+ /*
+ ** Note, if the exception vector returns, rely on it to have
+ ** adjusted EPC so we will return to some correct address. If
+ ** this is not done, we might get stuck in an infinite loop because
+ ** we'll return to the instruction where the exception occured and
+ ** it could throw again.
+ **
+ ** It is expected the only code using the exception processing is
+ ** either the gdb stub or some user code which is either going to
+ ** panic or do something useful. Regardless, it is up to each
+ ** exception routine to properly adjust EPC, so the code below
+ ** may be helpful for doing just that.
+ */
+
+/* *********************************************************************
+** this code follows the R3000's exception return logic, but is not
+** needed because the gdb stub does it for us. It might be useful
+** for something else at some point...
+**
+ * compute the address of the instruction we'll return to *
+
+ LDREG t1, R_CAUSE*R_SZ(sp)
+ LDREG t0, R_EPC*R_SZ(sp)
+
+ * first see if the exception happened in the delay slot *
+ li t3,CAUSE_BD
+ AND t4,t1,t3
+ beqz t4,excnodelay
+ NOP
+
+ * it did, now see if the branch occured or not *
+ li t3,CAUSE_BT
+ AND t4,t1,t3
+ beqz t4,excnobranch
+ NOP
+
+ * branch was taken, we resume at the branch target *
+ LDREG t0, R_TAR*R_SZ(sp)
+ j excreturn
+ NOP
+
+excnobranch:
+ ADDU t0,R_SZ
+
+excnodelay:
+ ADDU t0,R_SZ
+
+excreturn:
+ STREG t0, R_EPC*R_SZ(sp)
+ NOP
+********************************************************************* */
+
+
+ /* if we're returning into mips_break, move to the next instruction */
+
+ LDREG t0,R_EPC*R_SZ(sp)
+ la t1,mips_break
+ xor t2,t0,t1
+ bnez t2,3f
+
+ addu t0,R_SZ
+ STREG t0,R_EPC*R_SZ(sp)
+ NOP
+3:
+
+
+
+
+#if ( CPU_HARDWARE_FP == TRUE )
+ mfc0 t0,C0_SR /* FPU is enabled, restore state */
+ NOP
+ srl t0,t0,16
+ andi t0,t0,(SR_CU1 >> 16)
+ beqz t0, 2f
+ NOP
+
+ la a1,R_F0*R_SZ(sp)
+ jal _CPU_Context_restore_fp_from_exception
+ NOP
+ LDREG t0,R_FEIR*R_SZ(sp)
+ LDREG t1,R_FCSR*R_SZ(sp)
+ mtc1 t0,C1_REVISION
+ mtc1 t1,C1_STATUS
+2:
+#endif
+ LDREG s0,R_S0*R_SZ(sp) /* restore s0 - s7 */
+ LDREG s1,R_S1*R_SZ(sp)
+ LDREG s2,R_S2*R_SZ(sp)
+ LDREG s3,R_S3*R_SZ(sp)
+ LDREG s4,R_S4*R_SZ(sp)
+ LDREG s5,R_S5*R_SZ(sp)
+ LDREG s6,R_S6*R_SZ(sp)
+ LDREG s7,R_S7*R_SZ(sp)
+
+ /* do NOT restore the sp as this could mess up the world */
+ /* do NOT restore the cause as this could mess up the world */
+
+ /*
+ ** Jump all the way out. If theres a pending interrupt, just
+ ** let it be serviced later. Since we're probably using the
+ ** gdb stub, we've already disrupted the ISR service timing
+ ** anyhow. We oughtn't mix exception and interrupt processing
+ ** in the same exception call in case the exception stuff
+ ** might interfere with the dispatching & timer ticks.
+ */
+ j _ISR_Handler_exit
+ NOP
+
+_ISR_Handler_1:
+
+ mfc0 t1,C0_SR
+ and t0,CAUSE_IPMASK
+ and t0,t1
+
+ /* external interrupt not enabled, ignore */
+ /* but if it's not an exception or an interrupt, */
+ /* Then where did it come from??? */
+
+ beq t0,zero,_ISR_Handler_exit
+ NOP
+
+
+ /*
+ * save some or all context on stack
+ * may need to save some special interrupt information for exit
+ *
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if ( _ISR_Nest_level == 0 )
+ * switch to software interrupt stack
+ * #endif
+ */
+
+
+ /*
+ * _ISR_Nest_level++;
+ */
+ lw t0,ISR_NEST_LEVEL
+ NOP
+ add t0,t0,1
+ sw t0,ISR_NEST_LEVEL
+ /*
+ * _Thread_Dispatch_disable_level++;
+ */
+ lw t1,_Thread_Dispatch_disable_level
+ NOP
+ add t1,t1,1
+ sw t1,_Thread_Dispatch_disable_level
+
+ /*
+ * Call the CPU model or BSP specific routine to decode the
+ * interrupt source and actually vector to device ISR handlers.
+ */
+
+#ifdef INSTRUMENT_ISR_VECTORING
+ NOP
+ li t1, 1
+ sw t1, 0x8001e000
+#endif
+
+ move a0,sp
+ jal mips_vector_isr_handlers
+ NOP
+
+#ifdef INSTRUMENT_ISR_VECTORING
+ li t1, 0
+ sw t1, 0x8001e000
+ NOP
+#endif
+
+ /*
+ * --_ISR_Nest_level;
+ */
+ lw t2,ISR_NEST_LEVEL
+ NOP
+ add t2,t2,-1
+ sw t2,ISR_NEST_LEVEL
+ /*
+ * --_Thread_Dispatch_disable_level;
+ */
+ lw t1,_Thread_Dispatch_disable_level
+ NOP
+ add t1,t1,-1
+ sw t1,_Thread_Dispatch_disable_level
+ /*
+ * if ( _Thread_Dispatch_disable_level || _ISR_Nest_level )
+ * goto the label "exit interrupt (simple case)"
+ */
+ or t0,t2,t1
+ bne t0,zero,_ISR_Handler_exit
+ NOP
+
+
+ /*
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * restore stack
+ * #endif
+ *
+ * if !_Thread_Dispatch_necessary
+ * goto the label "exit interrupt (simple case)"
+ */
+ lbu t0,DISPATCH_NEEDED
+ NOP
+ or t0,t0,t0
+ beq t0,zero,_ISR_Handler_exit
+ NOP
+
+
+
+#ifdef INSTRUMENT_EXECUTING_THREAD
+ lw t0,THREAD_EXECUTING
+ NOP
+ sw t0,0x8001FFF4
+#endif
+
+/*
+** Turn on interrupts before entering Thread_Dispatch which
+** will run for a while, thus allowing new interrupts to
+** be serviced. Observe the Thread_Dispatch_disable_level interlock
+** that prevents recursive entry into Thread_Dispatch.
+*/
+
+ mfc0 t0, C0_SR
+#if __mips == 1
+
+ li t1,SR_IEC
+ or t0, t1
+
+#elif (__mips == 3) || (__mips == 32)
+
+ /*
+ ** clear XL and set IE so we can get interrupts.
+ */
+ li t1, SR_EXL
+ not t1
+ and t0,t1
+ or t0, SR_IE
+
+#endif
+ mtc0 t0, C0_SR
+ NOP
+
+ /* save off our stack frame so the context switcher can get to it */
+ la t0,__exceptionStackFrame
+ STREG sp,(t0)
+
+ jal _Thread_Dispatch
+ NOP
+
+ /*
+ ** And make sure its clear in case we didn't dispatch. if we did, its
+ ** already cleared
+ */
+ la t0,__exceptionStackFrame
+ STREG zero,(t0)
+ NOP
+
+/*
+** turn interrupts back off while we restore context so
+** a badly timed interrupt won't mess things up
+*/
+ mfc0 t0, C0_SR
+
+#if __mips == 1
+
+ /* ints off, current & prev kernel mode on (kernel mode enabled is bit clear..argh!) */
+ li t1,SR_IEC | SR_KUP | SR_KUC
+ not t1
+ and t0, t1
+ mtc0 t0, C0_SR
+ NOP
+
+#elif (__mips == 3) || (__mips == 32)
+
+ /* make sure EXL and IE are set so ints are disabled & we can update EPC for the return */
+ li t1,SR_IE /* Clear IE first (recommended) */
+ not t1
+ and t0,t1
+ mtc0 t0,C0_SR
+ NOP
+
+ /* apply task's SR with EXL set so the eret will return properly */
+ or t0, SR_EXL | SR_IE
+ mtc0 t0, C0_SR
+ NOP
+
+ /* store new EPC value, which we can do since EXL=0 */
+ LDREG t0, R_EPC*R_SZ(sp)
+ NOP
+ MTCO t0, C0_EPC
+ NOP
+
+#endif
+
+
+
+
+
+
+#ifdef INSTRUMENT_EXECUTING_THREAD
+ lw t0,THREAD_EXECUTING
+ NOP
+ sw t0,0x8001FFF8
+#endif
+
+
+ /*
+ * prepare to get out of interrupt
+ * return from interrupt (maybe to _ISR_Dispatch)
+ *
+ * LABEL "exit interrupt (simple case):"
+ * prepare to get out of interrupt
+ * return from interrupt
+ */
+
+_ISR_Handler_exit:
+/*
+** Skip the SR restore because its a global register. _CPU_Context_switch_restore
+** adjusts it according to each task's configuration. If we didn't dispatch, the
+** SR value isn't changed, so all we need to do is return.
+**
+*/
+ /* restore context from stack */
+
+#ifdef INSTRUMENT_EXECUTING_THREAD
+ lw t0,THREAD_EXECUTING
+ NOP
+ sw t0, 0x8001FFFC
+#endif
+
+ LDREG t8, R_MDLO*R_SZ(sp)
+ LDREG t0, R_T0*R_SZ(sp)
+ mtlo t8
+ LDREG t8, R_MDHI*R_SZ(sp)
+ LDREG t1, R_T1*R_SZ(sp)
+ mthi t8
+ LDREG t2, R_T2*R_SZ(sp)
+ LDREG t3, R_T3*R_SZ(sp)
+ LDREG t4, R_T4*R_SZ(sp)
+ LDREG t5, R_T5*R_SZ(sp)
+ LDREG t6, R_T6*R_SZ(sp)
+ LDREG t7, R_T7*R_SZ(sp)
+ LDREG t8, R_T8*R_SZ(sp)
+ LDREG t9, R_T9*R_SZ(sp)
+ LDREG gp, R_GP*R_SZ(sp)
+ LDREG fp, R_FP*R_SZ(sp)
+ LDREG ra, R_RA*R_SZ(sp)
+ LDREG a0, R_A0*R_SZ(sp)
+ LDREG a1, R_A1*R_SZ(sp)
+ LDREG a2, R_A2*R_SZ(sp)
+ LDREG a3, R_A3*R_SZ(sp)
+ LDREG v1, R_V1*R_SZ(sp)
+ LDREG v0, R_V0*R_SZ(sp)
+
+#if __mips == 1
+ LDREG k1, R_EPC*R_SZ(sp)
+#endif
+
+ .set noat
+ LDREG AT, R_AT*R_SZ(sp)
+ .set at
+
+ ADDIU sp,sp,EXCP_STACK_SIZE
+
+#if (__mips == 3) || (__mips == 32)
+ eret
+#elif __mips == 1
+ j k1
+ rfe
+#endif
+ NOP
+
+ .set reorder
+ENDFRAME(_ISR_Handler)
+
+
+FRAME(mips_break,sp,0,ra)
+ .set noreorder
+ break 0x0 /* this statement must be first in this function, assumed so by mips-stub.c */
+ NOP
+ j ra
+ NOP
+ .set reorder
+ENDFRAME(mips_break)
+
diff --git a/cpukit/score/cpu/mips/preinstall.am b/cpukit/score/cpu/mips/preinstall.am
new file mode 100644
index 0000000000..e99c280e1c
--- /dev/null
+++ b/cpukit/score/cpu/mips/preinstall.am
@@ -0,0 +1,54 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/mips/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/mips
+ @: > $(PROJECT_INCLUDE)/rtems/mips/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/mips/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/mips/idtcpu.h: rtems/mips/idtcpu.h $(PROJECT_INCLUDE)/rtems/mips/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mips/idtcpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mips/idtcpu.h
+
+$(PROJECT_INCLUDE)/rtems/mips/iregdef.h: rtems/mips/iregdef.h $(PROJECT_INCLUDE)/rtems/mips/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/mips/iregdef.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/mips/iregdef.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/mips.h: rtems/score/mips.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/mips.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/mips.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/mips/rtems/asm.h b/cpukit/score/cpu/mips/rtems/asm.h
new file mode 100644
index 0000000000..0ef10f8baa
--- /dev/null
+++ b/cpukit/score/cpu/mips/rtems/asm.h
@@ -0,0 +1,159 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+/* @(#)asm.h 03/15/96 1.1 */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/system.h>
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/mips.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+/*
+ * Debugger macros for assembly language routines. Allows the
+ * programmer to set up the necessary stack frame info
+ * required by debuggers to do stack traces.
+ */
+
+#ifndef XDS
+#define FRAME(name,frm_reg,offset,ret_reg) \
+ .globl name; \
+ .ent name; \
+name:; \
+ .frame frm_reg,offset,ret_reg
+#define ENDFRAME(name) \
+ .end name
+#else
+#define FRAME(name,frm_reg,offset,ret_reg) \
+ .globl _##name;\
+_##name:
+#define ENDFRAME(name)
+#endif /* XDS */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+#define R_FP0 0
+#define R_FP1 1
+#define R_FP2 2
+#define R_FP3 3
+#define R_FP4 4
+#define R_FP5 5
+#define R_FP6 6
+#define R_FP7 7
+#define R_FP8 8
+#define R_FP9 9
+#define R_FP10 10
+#define R_FP11 11
+#define R_FP12 12
+#define R_FP13 13
+#define R_FP14 14
+#define R_FP15 15
+#define R_FP16 16
+#define R_FP17 17
+#define R_FP18 18
+#define R_FP19 19
+#define R_FP20 20
+#define R_FP21 21
+#define R_FP22 22
+#define R_FP23 23
+#define R_FP24 24
+#define R_FP25 25
+#define R_FP26 26
+#define R_FP27 27
+#define R_FP28 28
+#define R_FP29 29
+#define R_FP30 30
+#define R_FP31 31
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/score/cpu/mips/rtems/mips/idtcpu.h b/cpukit/score/cpu/mips/rtems/mips/idtcpu.h
new file mode 100644
index 0000000000..c8c8569f4a
--- /dev/null
+++ b/cpukit/score/cpu/mips/rtems/mips/idtcpu.h
@@ -0,0 +1,697 @@
+/*
+
+Based upon IDT provided code with the following release:
+
+This source code has been made available to you by IDT on an AS-IS
+basis. Anyone receiving this source is licensed under IDT copyrights
+to use it in any way he or she deems fit, including copying it,
+modifying it, compiling it, and redistributing it either with or
+without modifications. No license under IDT patents or patent
+applications is to be implied by the copyright license.
+
+Any user of this software should understand that IDT cannot provide
+technical support for this software and will not be responsible for
+any consequences resulting from the use of this software.
+
+Any person who transfers this source code or any derivative work must
+include the IDT copyright notice, this paragraph, and the preceeding
+two paragraphs in the transferred software.
+
+COPYRIGHT IDT CORPORATION 1996
+LICENSED MATERIAL - PROGRAM PROPERTY OF IDT
+
+ $Id$
+*/
+
+/*
+** idtcpu.h -- cpu related defines
+*/
+
+#ifndef _RTEMS_MIPS_IDTCPU_H
+#define _RTEMS_MIPS_IDTCPU_H
+
+/*
+ * 950313: Ketan added Register definition for XContext reg.
+ * added define for WAIT instruction.
+ * 950421: Ketan added Register definition for Config reg (R3081)
+ */
+
+/*
+** memory configuration and mapping
+*/
+#define K0BASE 0x80000000
+#define K0SIZE 0x20000000
+#define K1BASE 0xa0000000
+#define K1SIZE 0x20000000
+#define K2BASE 0xc0000000
+#define K2SIZE 0x20000000
+#if __mips == 3
+#define KSBASE 0xe0000000
+#define KSSIZE 0x20000000
+#endif
+
+#define KUBASE 0
+#define KUSIZE 0x80000000
+
+/*
+** Exception Vectors
+*/
+#if __mips == 1
+#define UT_VEC K0BASE /* utlbmiss vector */
+#define DB_VEC (K0BASE+0x40) /* debug vector */
+#define E_VEC (K0BASE+0x80) /* exception vector */
+#elif __mips == 32
+#define T_VEC (K0BASE+0x000) /* tlbmiss vector */
+#define X_VEC (K0BASE+0x080) /* xtlbmiss vector */
+#define C_VEC (K0BASE+0x100) /* cache error vector */
+#define E_VEC (K0BASE+0x180) /* exception vector */
+#elif __mips == 3
+#define T_VEC (K0BASE+0x000) /* tlbmiss vector */
+#define X_VEC (K0BASE+0x080) /* xtlbmiss vector */
+#define C_VEC (K0BASE+0x100) /* cache error vector */
+#define E_VEC (K0BASE+0x180) /* exception vector */
+#else
+#error "EXCEPTION VECTORS: unknown ISA level"
+#endif
+#define R_VEC (K1BASE+0x1fc00000) /* reset vector */
+
+/*
+** Address conversion macros
+*/
+#ifdef CLANGUAGE
+#define CAST(as) (as)
+#else
+#define CAST(as)
+#endif
+#define K0_TO_K1(x) (CAST(unsigned)(x)|0xA0000000) /* kseg0 to kseg1 */
+#define K1_TO_K0(x) (CAST(unsigned)(x)&0x9FFFFFFF) /* kseg1 to kseg0 */
+#define K0_TO_PHYS(x) (CAST(unsigned)(x)&0x1FFFFFFF) /* kseg0 to physical */
+#define K1_TO_PHYS(x) (CAST(unsigned)(x)&0x1FFFFFFF) /* kseg1 to physical */
+#define PHYS_TO_K0(x) (CAST(unsigned)(x)|0x80000000) /* physical to kseg0 */
+#define PHYS_TO_K1(x) (CAST(unsigned)(x)|0xA0000000) /* physical to kseg1 */
+
+/*
+** Cache size constants
+*/
+#define MINCACHE 0x200 /* 512 For 3041. */
+#define MAXCACHE 0x40000 /* 256*1024 256k */
+
+#if __mips == 32
+/* R4000 configuration register definitions */
+#define CFG_CM 0x80000000 /* Master-Checker mode */
+#define CFG_ECMASK 0x70000000 /* System Clock Ratio */
+#define CFG_ECBY2 0x00000000 /* divide by 2 */
+#define CFG_ECBY3 0x10000000 /* divide by 3 */
+#define CFG_ECBY4 0x20000000 /* divide by 4 */
+#define CFG_EPMASK 0x0f000000 /* Transmit data pattern */
+#define CFG_EPD 0x00000000 /* D */
+#define CFG_EPDDX 0x01000000 /* DDX */
+#define CFG_EPDDXX 0x02000000 /* DDXX */
+#define CFG_EPDXDX 0x03000000 /* DXDX */
+#define CFG_EPDDXXX 0x04000000 /* DDXXX */
+#define CFG_EPDDXXXX 0x05000000 /* DDXXXX */
+#define CFG_EPDXXDXX 0x06000000 /* DXXDXX */
+#define CFG_EPDDXXXXX 0x07000000 /* DDXXXXX */
+#define CFG_EPDXXXDXXX 0x08000000 /* DXXXDXXX */
+#define CFG_SBMASK 0x00c00000 /* Secondary cache block size */
+#define CFG_SBSHIFT 22
+#define CFG_SB4 0x00000000 /* 4 words */
+#define CFG_SB8 0x00400000 /* 8 words */
+#define CFG_SB16 0x00800000 /* 16 words */
+#define CFG_SB32 0x00c00000 /* 32 words */
+#define CFG_SS 0x00200000 /* Split secondary cache */
+#define CFG_SW 0x00100000 /* Secondary cache port width */
+#define CFG_EWMASK 0x000c0000 /* System port width */
+#define CFG_EWSHIFT 18
+#define CFG_EW64 0x00000000 /* 64 bit */
+#define CFG_EW32 0x00010000 /* 32 bit */
+#define CFG_SC 0x00020000 /* Secondary cache absent */
+#define CFG_SM 0x00010000 /* Dirty Shared mode disabled */
+#define CFG_BE 0x00008000 /* Big Endian */
+#define CFG_EM 0x00004000 /* ECC mode enable */
+#define CFG_EB 0x00002000 /* Block ordering */
+#define CFG_ICMASK 0x00000e00 /* Instruction cache size */
+#define CFG_ICSHIFT 9
+#define CFG_DCMASK 0x000001c0 /* Data cache size */
+#define CFG_DCSHIFT 6
+#define CFG_IB 0x00000020 /* Instruction cache block size */
+#define CFG_DB 0x00000010 /* Data cache block size */
+#define CFG_CU 0x00000008 /* Update on Store Conditional */
+#define CFG_K0MASK 0x00000007 /* KSEG0 coherency algorithm */
+
+/*
+ * R4000 primary cache mode
+ */
+#define CFG_C_UNCACHED 2
+#define CFG_C_NONCOHERENT 3
+#define CFG_C_COHERENTXCL 4
+#define CFG_C_COHERENTXCLW 5
+#define CFG_C_COHERENTUPD 6
+
+/*
+ * R4000 cache operations (should be in assembler...?)
+ */
+#define Index_Invalidate_I 0x0 /* 0 0 */
+#define Index_Writeback_Inv_D 0x1 /* 0 1 */
+#define Index_Invalidate_SI 0x2 /* 0 2 */
+#define Index_Writeback_Inv_SD 0x3 /* 0 3 */
+#define Index_Load_Tag_I 0x4 /* 1 0 */
+#define Index_Load_Tag_D 0x5 /* 1 1 */
+#define Index_Load_Tag_SI 0x6 /* 1 2 */
+#define Index_Load_Tag_SD 0x7 /* 1 3 */
+#define Index_Store_Tag_I 0x8 /* 2 0 */
+#define Index_Store_Tag_D 0x9 /* 2 1 */
+#define Index_Store_Tag_SI 0xA /* 2 2 */
+#define Index_Store_Tag_SD 0xB /* 2 3 */
+#define Create_Dirty_Exc_D 0xD /* 3 1 */
+#define Create_Dirty_Exc_SD 0xF /* 3 3 */
+#define Hit_Invalidate_I 0x10 /* 4 0 */
+#define Hit_Invalidate_D 0x11 /* 4 1 */
+#define Hit_Invalidate_SI 0x12 /* 4 2 */
+#define Hit_Invalidate_SD 0x13 /* 4 3 */
+#define Hit_Writeback_Inv_D 0x15 /* 5 1 */
+#define Hit_Writeback_Inv_SD 0x17 /* 5 3 */
+#define Fill_I 0x14 /* 5 0 */
+#define Hit_Writeback_D 0x19 /* 6 1 */
+#define Hit_Writeback_SD 0x1B /* 6 3 */
+#define Hit_Writeback_I 0x18 /* 6 0 */
+#define Hit_Set_Virtual_SI 0x1E /* 7 2 */
+#define Hit_Set_Virtual_SD 0x1F /* 7 3 */
+
+/* Disabled by chris -- horrible overload of common word.
+#ifndef WAIT
+#define WAIT .word 0x42000020
+#endif
+*/
+/* Disabled by joel -- horrible overload of common word.
+#ifndef wait
+#define wait .word 0x42000020
+#endif wait
+*/
+
+#endif
+
+#if __mips == 3
+/* R4000 configuration register definitions */
+#define CFG_CM 0x80000000 /* Master-Checker mode */
+#define CFG_ECMASK 0x70000000 /* System Clock Ratio */
+#define CFG_ECBY2 0x00000000 /* divide by 2 */
+#define CFG_ECBY3 0x10000000 /* divide by 3 */
+#define CFG_ECBY4 0x20000000 /* divide by 4 */
+#define CFG_EPMASK 0x0f000000 /* Transmit data pattern */
+#define CFG_EPD 0x00000000 /* D */
+#define CFG_EPDDX 0x01000000 /* DDX */
+#define CFG_EPDDXX 0x02000000 /* DDXX */
+#define CFG_EPDXDX 0x03000000 /* DXDX */
+#define CFG_EPDDXXX 0x04000000 /* DDXXX */
+#define CFG_EPDDXXXX 0x05000000 /* DDXXXX */
+#define CFG_EPDXXDXX 0x06000000 /* DXXDXX */
+#define CFG_EPDDXXXXX 0x07000000 /* DDXXXXX */
+#define CFG_EPDXXXDXXX 0x08000000 /* DXXXDXXX */
+#define CFG_SBMASK 0x00c00000 /* Secondary cache block size */
+#define CFG_SBSHIFT 22
+#define CFG_SB4 0x00000000 /* 4 words */
+#define CFG_SB8 0x00400000 /* 8 words */
+#define CFG_SB16 0x00800000 /* 16 words */
+#define CFG_SB32 0x00c00000 /* 32 words */
+#define CFG_SS 0x00200000 /* Split secondary cache */
+#define CFG_SW 0x00100000 /* Secondary cache port width */
+#define CFG_EWMASK 0x000c0000 /* System port width */
+#define CFG_EWSHIFT 18
+#define CFG_EW64 0x00000000 /* 64 bit */
+#define CFG_EW32 0x00010000 /* 32 bit */
+#define CFG_SC 0x00020000 /* Secondary cache absent */
+#define CFG_SM 0x00010000 /* Dirty Shared mode disabled */
+#define CFG_BE 0x00008000 /* Big Endian */
+#define CFG_EM 0x00004000 /* ECC mode enable */
+#define CFG_EB 0x00002000 /* Block ordering */
+#define CFG_ICMASK 0x00000e00 /* Instruction cache size */
+#define CFG_ICSHIFT 9
+#define CFG_DCMASK 0x000001c0 /* Data cache size */
+#define CFG_DCSHIFT 6
+#define CFG_IB 0x00000020 /* Instruction cache block size */
+#define CFG_DB 0x00000010 /* Data cache block size */
+#define CFG_CU 0x00000008 /* Update on Store Conditional */
+#define CFG_K0MASK 0x00000007 /* KSEG0 coherency algorithm */
+
+/*
+ * R4000 primary cache mode
+ */
+#define CFG_C_UNCACHED 2
+#define CFG_C_NONCOHERENT 3
+#define CFG_C_COHERENTXCL 4
+#define CFG_C_COHERENTXCLW 5
+#define CFG_C_COHERENTUPD 6
+
+/*
+ * R4000 cache operations (should be in assembler...?)
+ */
+#define Index_Invalidate_I 0x0 /* 0 0 */
+#define Index_Writeback_Inv_D 0x1 /* 0 1 */
+#define Index_Invalidate_SI 0x2 /* 0 2 */
+#define Index_Writeback_Inv_SD 0x3 /* 0 3 */
+#define Index_Load_Tag_I 0x4 /* 1 0 */
+#define Index_Load_Tag_D 0x5 /* 1 1 */
+#define Index_Load_Tag_SI 0x6 /* 1 2 */
+#define Index_Load_Tag_SD 0x7 /* 1 3 */
+#define Index_Store_Tag_I 0x8 /* 2 0 */
+#define Index_Store_Tag_D 0x9 /* 2 1 */
+#define Index_Store_Tag_SI 0xA /* 2 2 */
+#define Index_Store_Tag_SD 0xB /* 2 3 */
+#define Create_Dirty_Exc_D 0xD /* 3 1 */
+#define Create_Dirty_Exc_SD 0xF /* 3 3 */
+#define Hit_Invalidate_I 0x10 /* 4 0 */
+#define Hit_Invalidate_D 0x11 /* 4 1 */
+#define Hit_Invalidate_SI 0x12 /* 4 2 */
+#define Hit_Invalidate_SD 0x13 /* 4 3 */
+#define Hit_Writeback_Inv_D 0x15 /* 5 1 */
+#define Hit_Writeback_Inv_SD 0x17 /* 5 3 */
+#define Fill_I 0x14 /* 5 0 */
+#define Hit_Writeback_D 0x19 /* 6 1 */
+#define Hit_Writeback_SD 0x1B /* 6 3 */
+#define Hit_Writeback_I 0x18 /* 6 0 */
+#define Hit_Set_Virtual_SI 0x1E /* 7 2 */
+#define Hit_Set_Virtual_SD 0x1F /* 7 3 */
+
+/* Disabled by chris -- horrible overload of common word.
+#ifndef WAIT
+#define WAIT .word 0x42000020
+#endif
+*/
+/* Disabled by joel -- horrible overload of common word.
+#ifndef wait
+#define wait .word 0x42000020
+#endif wait
+*/
+
+#endif
+
+/*
+** TLB resource defines
+*/
+#if __mips == 1
+#define N_TLB_ENTRIES 64
+#define TLB_PGSIZE 0x1000
+#define RANDBASE 8
+#define TLBLO_PFNMASK 0xfffff000
+#define TLBLO_PFNSHIFT 12
+#define TLBLO_N 0x800 /* non-cacheable */
+#define TLBLO_D 0x400 /* writeable */
+#define TLBLO_V 0x200 /* valid bit */
+#define TLBLO_G 0x100 /* global access bit */
+
+#define TLBHI_VPNMASK 0xfffff000
+#define TLBHI_VPNSHIFT 12
+#define TLBHI_PIDMASK 0xfc0
+#define TLBHI_PIDSHIFT 6
+#define TLBHI_NPID 64
+
+#define TLBINX_PROBE 0x80000000
+#define TLBINX_INXMASK 0x00003f00
+#define TLBINX_INXSHIFT 8
+
+#define TLBRAND_RANDMASK 0x00003f00
+#define TLBRAND_RANDSHIFT 8
+
+#define TLBCTXT_BASEMASK 0xffe00000
+#define TLBCTXT_BASESHIFT 21
+
+#define TLBCTXT_VPNMASK 0x001ffffc
+#define TLBCTXT_VPNSHIFT 2
+#endif
+#if __mips == 3
+#define N_TLB_ENTRIES 48
+
+#define TLBHI_VPN2MASK 0xffffe000
+#define TLBHI_PIDMASK 0x000000ff
+#define TLBHI_NPID 256
+
+#define TLBLO_PFNMASK 0x3fffffc0
+#define TLBLO_PFNSHIFT 6
+#define TLBLO_D 0x00000004 /* writeable */
+#define TLBLO_V 0x00000002 /* valid bit */
+#define TLBLO_G 0x00000001 /* global access bit */
+#define TLBLO_CMASK 0x00000038 /* cache algorithm mask */
+#define TLBLO_CSHIFT 3
+
+#define TLBLO_UNCACHED (CFG_C_UNCACHED<<TLBLO_CSHIFT)
+#define TLBLO_NONCOHERENT (CFG_C_NONCOHERENT<<TLBLO_CSHIFT)
+#define TLBLO_COHERENTXCL (CFG_C_COHERENTXCL<<TLBLO_CSHIFT)
+#define TLBLO_COHERENTXCLW (CFG_C_COHERENTXCLW<<TLBLO_CSHIFT)
+#define TLBLO_COHERENTUPD (CFG_C_COHERENTUPD<<TLBLO_CSHIFT)
+
+#define TLBINX_PROBE 0x80000000
+#define TLBINX_INXMASK 0x0000003f
+
+#define TLBRAND_RANDMASK 0x0000003f
+
+#define TLBCTXT_BASEMASK 0xff800000
+#define TLBCTXT_BASESHIFT 23
+
+#define TLBCTXT_VPN2MASK 0x007ffff0
+#define TLBCTXT_VPN2SHIFT 4
+
+#define TLBPGMASK_MASK 0x01ffe000
+#endif
+
+#if __mips == 32
+#define N_TLB_ENTRIES 16
+
+#define TLBHI_VPN2MASK 0xffffe000
+#define TLBHI_PIDMASK 0x000000ff
+#define TLBHI_NPID 256
+
+#define TLBLO_PFNMASK 0x3fffffc0
+#define TLBLO_PFNSHIFT 6
+#define TLBLO_D 0x00000004 /* writeable */
+#define TLBLO_V 0x00000002 /* valid bit */
+#define TLBLO_G 0x00000001 /* global access bit */
+#define TLBLO_CMASK 0x00000038 /* cache algorithm mask */
+#define TLBLO_CSHIFT 3
+
+#define TLBLO_UNCACHED (CFG_C_UNCACHED<<TLBLO_CSHIFT)
+#define TLBLO_NONCOHERENT (CFG_C_NONCOHERENT<<TLBLO_CSHIFT)
+#define TLBLO_COHERENTXCL (CFG_C_COHERENTXCL<<TLBLO_CSHIFT)
+#define TLBLO_COHERENTXCLW (CFG_C_COHERENTXCLW<<TLBLO_CSHIFT)
+#define TLBLO_COHERENTUPD (CFG_C_COHERENTUPD<<TLBLO_CSHIFT)
+
+#define TLBINX_PROBE 0x80000000
+#define TLBINX_INXMASK 0x0000003f
+
+#define TLBRAND_RANDMASK 0x0000003f
+
+#define TLBCTXT_BASEMASK 0xff800000
+#define TLBCTXT_BASESHIFT 23
+
+#define TLBCTXT_VPN2MASK 0x007ffff0
+#define TLBCTXT_VPN2SHIFT 4
+
+#define TLBPGMASK_MASK 0x01ffe000
+#endif
+
+#if __mips == 1
+
+
+/* definitions for Debug and Cache Invalidate control (DCIC) register bits */
+#define DCIC_TR 0x80000000 /* Trap enable */
+#define DCIC_UD 0x40000000 /* User debug enable */
+#define DCIC_KD 0x20000000 /* Kernel debug enable */
+#define DCIC_TE 0x10000000 /* Trace enable */
+#define DCIC_DW 0x08000000 /* Enable data breakpoints on write */
+#define DCIC_DR 0x04000000 /* Enable data breakpoints on read */
+#define DCIC_DAE 0x02000000 /* Enable data addresss breakpoints */
+#define DCIC_PCE 0x01000000 /* Enable instruction breakpoints */
+#define DCIC_DE 0x00800000 /* Debug enable */
+#define DCIC_DL 0x00008000 /* Data cache line invalidate */
+#define DCIC_IL 0x00004000 /* Instruction cache line invalidate */
+#define DCIC_D 0x00002000 /* Data cache invalidate enable */
+#define DCIC_I 0x00001000 /* Instr. cache invalidate enable */
+#define DCIC_T 0x00000020 /* Trace, set by CPU */
+#define DCIC_W 0x00000010 /* Write reference, set by CPU */
+#define DCIC_R 0x00000008 /* Read reference, set by CPU */
+#define DCIC_DA 0x00000004 /* Data address, set by CPU */
+#define DCIC_PC 0x00000002 /* Program counter, set by CPU */
+#define DCIC_DB 0x00000001 /* Debug, set by CPU */
+
+
+
+
+#define SR_CUMASK 0xf0000000 /* coproc usable bits */
+#define SR_CU3 0x80000000 /* Coprocessor 3 usable */
+#define SR_CU2 0x40000000 /* Coprocessor 2 usable */
+#define SR_CU1 0x20000000 /* Coprocessor 1 usable */
+#define SR_CU0 0x10000000 /* Coprocessor 0 usable */
+
+#define SR_BEV 0x00400000 /* use boot exception vectors */
+
+/* Cache control bits */
+#define SR_TS 0x00200000 /* TLB shutdown */
+#define SR_PE 0x00100000 /* cache parity error */
+#define SR_CM 0x00080000 /* cache miss */
+#define SR_PZ 0x00040000 /* cache parity zero */
+#define SR_SWC 0x00020000 /* swap cache */
+#define SR_ISC 0x00010000 /* Isolate data cache */
+
+/*
+** status register interrupt masks and bits
+*/
+
+#define SR_IMASK 0x0000ff00 /* Interrupt mask */
+#define SR_IMASK8 0x00000000 /* mask level 8 */
+#define SR_IMASK7 0x00008000 /* mask level 7 */
+#define SR_IMASK6 0x0000c000 /* mask level 6 */
+#define SR_IMASK5 0x0000e000 /* mask level 5 */
+#define SR_IMASK4 0x0000f000 /* mask level 4 */
+#define SR_IMASK3 0x0000f800 /* mask level 3 */
+#define SR_IMASK2 0x0000fc00 /* mask level 2 */
+#define SR_IMASK1 0x0000fe00 /* mask level 1 */
+#define SR_IMASK0 0x0000ff00 /* mask level 0 */
+
+#define SR_IMASKSHIFT 8
+
+#define SR_IBIT8 0x00008000 /* bit level 8 */
+#define SR_IBIT7 0x00004000 /* bit level 7 */
+#define SR_IBIT6 0x00002000 /* bit level 6 */
+#define SR_IBIT5 0x00001000 /* bit level 5 */
+#define SR_IBIT4 0x00000800 /* bit level 4 */
+#define SR_IBIT3 0x00000400 /* bit level 3 */
+#define SR_IBIT2 0x00000200 /* bit level 2 */
+#define SR_IBIT1 0x00000100 /* bit level 1 */
+
+#define SR_KUO 0x00000020 /* old kernel/user, 0 => k, 1 => u */
+#define SR_IEO 0x00000010 /* old interrupt enable, 1 => enable */
+#define SR_KUP 0x00000008 /* prev kernel/user, 0 => k, 1 => u */
+#define SR_IEP 0x00000004 /* prev interrupt enable, 1 => enable */
+#define SR_KUC 0x00000002 /* cur kernel/user, 0 => k, 1 => u */
+#define SR_IEC 0x00000001 /* cur interrupt enable, 1 => enable */
+#endif
+
+#if __mips == 3
+#define SR_CUMASK 0xf0000000 /* coproc usable bits */
+#define SR_CU3 0x80000000 /* Coprocessor 3 usable */
+#define SR_CU2 0x40000000 /* Coprocessor 2 usable */
+#define SR_CU1 0x20000000 /* Coprocessor 1 usable */
+#define SR_CU0 0x10000000 /* Coprocessor 0 usable */
+
+#define SR_RP 0x08000000 /* Reduced power operation */
+#define SR_FR 0x04000000 /* Additional floating point registers */
+#define SR_RE 0x02000000 /* Reverse endian in user mode */
+
+#define SR_BEV 0x00400000 /* Use boot exception vectors */
+#define SR_TS 0x00200000 /* TLB shutdown */
+#define SR_SR 0x00100000 /* Soft reset */
+#define SR_CH 0x00040000 /* Cache hit */
+#define SR_CE 0x00020000 /* Use cache ECC */
+#define SR_DE 0x00010000 /* Disable cache exceptions */
+
+/*
+** status register interrupt masks and bits
+*/
+
+#define SR_IMASK 0x0000ff00 /* Interrupt mask */
+#define SR_IMASK8 0x00000000 /* mask level 8 */
+#define SR_IMASK7 0x00008000 /* mask level 7 */
+#define SR_IMASK6 0x0000c000 /* mask level 6 */
+#define SR_IMASK5 0x0000e000 /* mask level 5 */
+#define SR_IMASK4 0x0000f000 /* mask level 4 */
+#define SR_IMASK3 0x0000f800 /* mask level 3 */
+#define SR_IMASK2 0x0000fc00 /* mask level 2 */
+#define SR_IMASK1 0x0000fe00 /* mask level 1 */
+#define SR_IMASK0 0x0000ff00 /* mask level 0 */
+
+#define SR_IMASKSHIFT 8
+
+#define SR_IBIT8 0x00008000 /* bit level 8 */
+#define SR_IBIT7 0x00004000 /* bit level 7 */
+#define SR_IBIT6 0x00002000 /* bit level 6 */
+#define SR_IBIT5 0x00001000 /* bit level 5 */
+#define SR_IBIT4 0x00000800 /* bit level 4 */
+#define SR_IBIT3 0x00000400 /* bit level 3 */
+#define SR_IBIT2 0x00000200 /* bit level 2 */
+#define SR_IBIT1 0x00000100 /* bit level 1 */
+
+#define SR_KSMASK 0x00000018 /* Kernel mode mask */
+#define SR_KSUSER 0x00000010 /* User mode */
+#define SR_KSSUPER 0x00000008 /* Supervisor mode */
+#define SR_KSKERNEL 0x00000000 /* Kernel mode */
+#define SR_ERL 0x00000004 /* Error level */
+#define SR_EXL 0x00000002 /* Exception level */
+#define SR_IE 0x00000001 /* Interrupts enabled */
+#endif
+
+#if __mips == 32
+#define SR_CUMASK 0xf0000000 /* coproc usable bits */
+#define SR_CU3 0x80000000 /* Coprocessor 3 usable */
+#define SR_CU2 0x40000000 /* Coprocessor 2 usable */
+#define SR_CU1 0x20000000 /* Coprocessor 1 usable */
+#define SR_CU0 0x10000000 /* Coprocessor 0 usable */
+
+#define SR_RP 0x08000000 /* Reduced power operation */
+#define SR_FR 0x04000000 /* Additional floating point registers */
+#define SR_RE 0x02000000 /* Reverse endian in user mode */
+
+#define SR_BEV 0x00400000 /* Use boot exception vectors */
+#define SR_TS 0x00200000 /* TLB shutdown */
+#define SR_SR 0x00100000 /* Soft reset */
+#define SR_CH 0x00040000 /* Cache hit */
+#define SR_CE 0x00020000 /* Use cache ECC */
+#define SR_DE 0x00010000 /* Disable cache exceptions */
+
+/*
+** status register interrupt masks and bits
+*/
+
+#define SR_IMASK 0x0000ff00 /* Interrupt mask */
+#define SR_IMASK8 0x00000000 /* mask level 8 */
+#define SR_IMASK7 0x00008000 /* mask level 7 */
+#define SR_IMASK6 0x0000c000 /* mask level 6 */
+#define SR_IMASK5 0x0000e000 /* mask level 5 */
+#define SR_IMASK4 0x0000f000 /* mask level 4 */
+#define SR_IMASK3 0x0000f800 /* mask level 3 */
+#define SR_IMASK2 0x0000fc00 /* mask level 2 */
+#define SR_IMASK1 0x0000fe00 /* mask level 1 */
+#define SR_IMASK0 0x0000ff00 /* mask level 0 */
+
+#define SR_IMASKSHIFT 8
+
+#define SR_IBIT8 0x00008000 /* bit level 8 */
+#define SR_IBIT7 0x00004000 /* bit level 7 */
+#define SR_IBIT6 0x00002000 /* bit level 6 */
+#define SR_IBIT5 0x00001000 /* bit level 5 */
+#define SR_IBIT4 0x00000800 /* bit level 4 */
+#define SR_IBIT3 0x00000400 /* bit level 3 */
+#define SR_IBIT2 0x00000200 /* bit level 2 */
+#define SR_IBIT1 0x00000100 /* bit level 1 */
+
+#define SR_KSMASK 0x00000018 /* Kernel mode mask */
+#define SR_KSUSER 0x00000010 /* User mode */
+#define SR_KSSUPER 0x00000008 /* Supervisor mode */
+#define SR_KSKERNEL 0x00000000 /* Kernel mode */
+#define SR_ERL 0x00000004 /* Error level */
+#define SR_EXL 0x00000002 /* Exception level */
+#define SR_IE 0x00000001 /* Interrupts enabled */
+#endif
+
+/*
+ * Cause Register
+ */
+#define CAUSE_BD 0x80000000 /* Branch delay slot */
+#define CAUSE_BT 0x40000000 /* Branch Taken */
+#define CAUSE_CEMASK 0x30000000 /* coprocessor error */
+#define CAUSE_CESHIFT 28
+
+
+#define CAUSE_IPMASK 0x0000FF00 /* Pending interrupt mask */
+#define CAUSE_IPSHIFT 8
+
+#define CAUSE_EXCMASK 0x0000003C /* Cause code bits */
+#define CAUSE_EXCSHIFT 2
+
+#ifndef XDS
+/*
+** Coprocessor 0 registers
+*/
+#define C0_INX $0 /* tlb index */
+#define C0_RAND $1 /* tlb random */
+#if __mips == 1
+#define C0_TLBLO $2 /* tlb entry low */
+#endif
+#if __mips == 3
+#define C0_TLBLO0 $2 /* tlb entry low 0 */
+#define C0_TLBLO1 $3 /* tlb entry low 1 */
+#endif
+
+#if __mips == 32
+#define C0_TLBLO0 $2 /* tlb entry low 0 */
+#define C0_TLBLO1 $3 /* tlb entry low 1 */
+#endif
+
+
+#define C0_CTXT $4 /* tlb context */
+
+#if __mips == 3
+#define C0_PAGEMASK $5 /* tlb page mask */
+#define C0_WIRED $6 /* number of wired tlb entries */
+#endif
+
+#if __mips == 32
+#define C0_PAGEMASK $5 /* tlb page mask */
+#define C0_WIRED $6 /* number of wired tlb entries */
+#endif
+
+#if __mips == 1
+#define C0_TAR $6
+#endif
+
+#define C0_BADVADDR $8 /* bad virtual address */
+
+#if __mips == 3
+#define C0_COUNT $9 /* cycle count */
+#endif
+#if __mips == 32
+#define C0_COUNT $9 /* cycle count */
+#endif
+
+#define C0_TLBHI $10 /* tlb entry hi */
+
+#if __mips == 3
+#define C0_COMPARE $11 /* cyccle count comparator */
+#endif
+
+#if __mips == 32
+#define C0_COMPARE $11 /* cyccle count comparator */
+#endif
+
+#define C0_SR $12 /* status register */
+#define C0_CAUSE $13 /* exception cause */
+#define C0_EPC $14 /* exception pc */
+#define C0_PRID $15 /* revision identifier */
+
+#if __mips == 1
+#define C0_CONFIG $3 /* configuration register R3081*/
+#endif
+
+#if __mips == 3
+#define C0_CONFIG $16 /* configuration register */
+#define C0_LLADDR $17 /* linked load address */
+#define C0_WATCHLO $18 /* watchpoint trap register */
+#define C0_WATCHHI $19 /* watchpoint trap register */
+#define C0_XCTXT $20 /* extended tlb context */
+#define C0_ECC $26 /* secondary cache ECC control */
+#define C0_CACHEERR $27 /* cache error status */
+#define C0_TAGLO $28 /* cache tag lo */
+#define C0_TAGHI $29 /* cache tag hi */
+#define C0_ERRPC $30 /* cache error pc */
+#endif
+
+#if __mips == 32
+#define C0_CONFIG $16 /* configuration register */
+#define C0_LLADDR $17 /* linked load address */
+#define C0_WATCHLO $18 /* watchpoint trap register */
+#define C0_WATCHHI $19 /* watchpoint trap register */
+#define C0_XCTXT $20 /* extended tlb context */
+#define C0_ECC $26 /* secondary cache ECC control */
+#define C0_CACHEERR $27 /* cache error status */
+#define C0_TAGLO $28 /* cache tag lo */
+#define C0_TAGHI $29 /* cache tag hi */
+#define C0_ERRPC $30 /* cache error pc */
+#endif
+
+
+#define C1_REVISION $0
+#define C1_STATUS $31
+
+#endif /* XDS */
+
+#ifdef R4650
+#define IWATCH $18
+#define DWATCH $19
+#define IBASE $0
+#define IBOUND $1
+#define DBASE $2
+#define DBOUND $3
+#define CALG $17
+#endif
+
+#endif /* _RTEMS_MIPS_IDTCPU_H */
+
diff --git a/cpukit/score/cpu/mips/rtems/mips/iregdef.h b/cpukit/score/cpu/mips/rtems/mips/iregdef.h
new file mode 100644
index 0000000000..0891c3b825
--- /dev/null
+++ b/cpukit/score/cpu/mips/rtems/mips/iregdef.h
@@ -0,0 +1,332 @@
+/*
+
+Based upon IDT provided code with the following release:
+
+This source code has been made available to you by IDT on an AS-IS
+basis. Anyone receiving this source is licensed under IDT copyrights
+to use it in any way he or she deems fit, including copying it,
+modifying it, compiling it, and redistributing it either with or
+without modifications. No license under IDT patents or patent
+applications is to be implied by the copyright license.
+
+Any user of this software should understand that IDT cannot provide
+technical support for this software and will not be responsible for
+any consequences resulting from the use of this software.
+
+Any person who transfers this source code or any derivative work must
+include the IDT copyright notice, this paragraph, and the preceeding
+two paragraphs in the transferred software.
+
+COPYRIGHT IDT CORPORATION 1996
+LICENSED MATERIAL - PROGRAM PROPERTY OF IDT
+
+ $Id$
+*/
+
+/*
+** iregdef.h - IDT R3000 register structure header file
+**
+** Copyright 1989 Integrated Device Technology, Inc
+** All Rights Reserved
+**
+*/
+#ifndef _RTEMS_MIPS_IREGDEF_H
+#define _RTEMS_MIPS_IREGDEF_H
+
+/*
+ * 950313: Ketan added sreg/lreg and R_SZ for 64-bit saves
+ * added Register definition for XContext reg.
+ * Look towards end of this file.
+ */
+/*
+** register names
+*/
+#define r0 $0
+#define r1 $1
+#define r2 $2
+#define r3 $3
+#define r4 $4
+#define r5 $5
+#define r6 $6
+#define r7 $7
+#define r8 $8
+#define r9 $9
+#define r10 $10
+#define r11 $11
+#define r12 $12
+#define r13 $13
+
+#define r14 $14
+#define r15 $15
+#define r16 $16
+#define r17 $17
+#define r18 $18
+#define r19 $19
+#define r20 $20
+#define r21 $21
+#define r22 $22
+#define r23 $23
+#define r24 $24
+#define r25 $25
+#define r26 $26
+#define r27 $27
+#define r28 $28
+#define r29 $29
+#define r30 $30
+#define r31 $31
+
+#define fp0 $f0
+#define fp1 $f1
+#define fp2 $f2
+#define fp3 $f3
+#define fp4 $f4
+#define fp5 $f5
+#define fp6 $f6
+#define fp7 $f7
+#define fp8 $f8
+#define fp9 $f9
+#define fp10 $f10
+#define fp11 $f11
+#define fp12 $f12
+#define fp13 $f13
+#define fp14 $f14
+#define fp15 $f15
+#define fp16 $f16
+#define fp17 $f17
+#define fp18 $f18
+#define fp19 $f19
+#define fp20 $f20
+#define fp21 $f21
+#define fp22 $f22
+#define fp23 $f23
+#define fp24 $f24
+#define fp25 $f25
+#define fp26 $f26
+#define fp27 $f27
+#define fp28 $f28
+#define fp29 $f29
+#define fp30 $f30
+#define fp31 $f31
+
+#define fcr0 $0
+#define fcr30 $30
+#define fcr31 $31
+
+#define zero $0 /* wired zero */
+#define AT $at /* assembler temp */
+#define v0 $2 /* return value */
+#define v1 $3
+#define a0 $4 /* argument registers a0-a3 */
+#define a1 $5
+#define a2 $6
+#define a3 $7
+#define t0 $8 /* caller saved t0-t9 */
+#define t1 $9
+#define t2 $10
+#define t3 $11
+#define t4 $12
+#define t5 $13
+#define t6 $14
+#define t7 $15
+#define s0 $16 /* callee saved s0-s8 */
+#define s1 $17
+#define s2 $18
+#define s3 $19
+#define s4 $20
+#define s5 $21
+#define s6 $22
+#define s7 $23
+#define t8 $24
+#define t9 $25
+#define k0 $26 /* kernel usage */
+#define k1 $27 /* kernel usage */
+#define gp $28 /* sdata pointer */
+#define sp $29 /* stack pointer */
+#define s8 $30 /* yet another saved reg for the callee */
+#define fp $30 /* frame pointer - this is being phased out by MIPS */
+#define ra $31 /* return address */
+
+
+/*
+** relative position of registers in interrupt/exception frame
+*/
+#define R_R0 0
+#define R_R1 1
+#define R_R2 2
+#define R_R3 3
+#define R_R4 4
+#define R_R5 5
+#define R_R6 6
+#define R_R7 7
+#define R_R8 8
+#define R_R9 9
+#define R_R10 10
+#define R_R11 11
+#define R_R12 12
+#define R_R13 13
+#define R_R14 14
+#define R_R15 15
+#define R_R16 16
+#define R_R17 17
+#define R_R18 18
+#define R_R19 19
+#define R_R20 20
+#define R_R21 21
+#define R_R22 22
+#define R_R23 23
+#define R_R24 24
+#define R_R25 25
+#define R_R26 26
+#define R_R27 27
+#define R_R28 28
+#define R_R29 29
+#define R_R30 30
+#define R_R31 31
+
+#define R_SR 32
+#define R_MDLO 33
+#define R_MDHI 34
+#define R_BADVADDR 35
+#define R_CAUSE 36
+#define R_EPC 37
+
+#define R_F0 38
+#define R_F1 39
+#define R_F2 40
+#define R_F3 41
+#define R_F4 42
+#define R_F5 43
+#define R_F6 44
+#define R_F7 45
+#define R_F8 46
+#define R_F9 47
+#define R_F10 48
+#define R_F11 49
+#define R_F12 50
+#define R_F13 41
+#define R_F14 42
+#define R_F15 43
+#define R_F16 44
+#define R_F17 45
+#define R_F18 56
+#define R_F19 57
+#define R_F20 58
+#define R_F21 59
+#define R_F22 60
+#define R_F23 61
+#define R_F24 62
+#define R_F25 63
+#define R_F26 64
+#define R_F27 65
+#define R_F28 66
+#define R_F29 67
+#define R_F30 68
+#define R_F31 69
+#define R_FCSR 70
+#define R_FEIR 71
+#define R_TLBHI 72
+
+#if __mips == 1
+#define R_TLBLO 73
+#endif
+#if (__mips == 3 ) || ( __mips == 32)
+#define R_TLBLO0 73
+#endif
+
+#define R_INX 74
+#define R_RAND 75
+#define R_CTXT 76
+#define R_EXCTYPE 77
+#define R_MODE 78
+#define R_PRID 79
+#define R_TAR 80
+#if __mips == 1
+#define NREGS 81
+#endif
+#if (__mips == 3 ) || ( __mips == 32)
+#define R_TLBLO1 81
+#define R_PAGEMASK 82
+#define R_WIRED 83
+#define R_COUNT 84
+#define R_COMPARE 85
+#define R_CONFIG 86
+#define R_LLADDR 87
+#define R_WATCHLO 88
+#define R_WATCHHI 89
+#define R_ECC 90
+#define R_CACHEERR 91
+#define R_TAGLO 92
+#define R_TAGHI 93
+#define R_ERRPC 94
+#define R_XCTXT 95 /* Ketan added from SIM64bit */
+
+#define NREGS 96
+#endif
+
+/*
+** For those who like to think in terms of the compiler names for the regs
+*/
+#define R_ZERO R_R0
+#define R_AT R_R1
+#define R_V0 R_R2
+#define R_V1 R_R3
+#define R_A0 R_R4
+#define R_A1 R_R5
+#define R_A2 R_R6
+#define R_A3 R_R7
+#define R_T0 R_R8
+#define R_T1 R_R9
+#define R_T2 R_R10
+#define R_T3 R_R11
+#define R_T4 R_R12
+#define R_T5 R_R13
+#define R_T6 R_R14
+#define R_T7 R_R15
+#define R_S0 R_R16
+#define R_S1 R_R17
+#define R_S2 R_R18
+#define R_S3 R_R19
+#define R_S4 R_R20
+#define R_S5 R_R21
+#define R_S6 R_R22
+#define R_S7 R_R23
+#define R_T8 R_R24
+#define R_T9 R_R25
+#define R_K0 R_R26
+#define R_K1 R_R27
+#define R_GP R_R28
+#define R_SP R_R29
+#define R_FP R_R30
+#define R_RA R_R31
+
+/* disabled for RTEMS */
+#if 0
+/* Ketan added the following */
+#if __mips == 1
+#define sreg sw
+#define lreg lw
+#define rmfc0 mfc0
+#define rmtc0 mtc0
+#define R_SZ 4
+#endif /* __mips == 1 */
+
+/* #ifdef __mips == 3 */
+#if __mips < 3
+#define sreg sw
+#define lreg lw
+#define rmfc0 mfc0
+#define rmtc0 mtc0
+#define R_SZ 4
+#else
+#define sreg sd
+#define lreg ld
+#define rmfc0 dmfc0
+#define rmtc0 dmtc0
+#define R_SZ 8
+#endif
+/* #endif __mips == 3 */
+/* Ketan till here */
+#endif
+
+#endif /* _RTEMS_MIPS_IREGDEF_H */
+
diff --git a/cpukit/score/cpu/mips/rtems/score/cpu.h b/cpukit/score/cpu/mips/rtems/score/cpu.h
new file mode 100644
index 0000000000..8d94aba5f6
--- /dev/null
+++ b/cpukit/score/cpu/mips/rtems/score/cpu.h
@@ -0,0 +1,1156 @@
+/*
+ * Mips CPU Dependent Header File
+ *
+ * Conversion to MIPS port by Alan Cudmore <alanc@linuxstart.com> and
+ * Joel Sherrill <joel@OARcorp.com>.
+ *
+ * These changes made the code conditional on standard cpp predefines,
+ * merged the mips1 and mips3 code sequences as much as possible,
+ * and moved some of the assembly code to C. Alan did much of the
+ * initial analysis and rework. Joel took over from there and
+ * wrote the JMR3904 BSP so this could be tested. Joel also
+ * added the new interrupt vectoring support in libcpu and
+ * tried to better support the various interrupt controllers.
+ *
+ * Original MIP64ORION port by Craig Lebakken <craigl@transition.com>
+ * COPYRIGHT (c) 1996 by Transition Networks Inc.
+ *
+ * To anyone who acknowledges that this file is provided "AS IS"
+ * without any express or implied warranty:
+ * permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies, and that the name of Transition Networks not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * Transition Networks makes no representations about the suitability
+ * of this software for any purpose.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/mips.h>
+
+/* conditional compilation parameters */
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * Basically this is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ * [NOTE: In general, the _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls _Thread_Enable_dispatch which in turns calls
+ * _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.]
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/*
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _Interrupt_Manager_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * MIPS Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ */
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ */
+
+#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 1
+
+
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "MIPS_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+#if ( MIPS_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+
+/*
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPU in which this option has been used is the
+ * HP PA-RISC. The HP C compiler and gcc both implicitly use the
+ * floating point registers to perform integer multiplies. If
+ * a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ */
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ */
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ */
+
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Internal_threads_Idle_thread_body
+ * must be provided and is the default IDLE thread body instead of
+ * _Internal_threads_Idle_thread_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * 1. BSP provided
+ * 2. CPU dependent (if provided)
+ * 3. generic (if no BSP and no CPU dependent)
+ */
+
+/* we can use the low power wait instruction for the IDLE thread */
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ */
+
+/* our stack grows down */
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * NOTE: Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ */
+
+/* our cache line size is 16 bytes */
+#if __GNUC__
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (16)))
+#else
+#define CPU_STRUCTURE_ALIGNMENT
+#endif
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+/* __MIPSEB__ or __MIPSEL__ is defined by GCC based on -EB or -EL command line options */
+#if defined(__MIPSEB__)
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+#elif defined(__MIPSEL__)
+#define CPU_BIG_ENDIAN FALSE
+#define CPU_LITTLE_ENDIAN TRUE
+#else
+#error "Unknown endianness"
+#endif
+
+/*
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
+ */
+
+#define CPU_MODES_INTERRUPT_MASK 0x000000ff
+
+/*
+ * Processor defined structures
+ *
+ * Examples structures include the descriptor tables from the i386
+ * and the processor control structure on the i960ca.
+ */
+
+/* may need to put some structures here. */
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ */
+
+#ifndef ASM
+
+/* WARNING: If this structure is modified, the constants in cpu.h must be updated. */
+#if (__mips == 1) || (__mips == 32)
+#define __MIPS_REGISTER_TYPE uint32_t
+#define __MIPS_FPU_REGISTER_TYPE uint32_t
+#elif __mips == 3
+#define __MIPS_REGISTER_TYPE uint64_t
+#define __MIPS_FPU_REGISTER_TYPE uint64_t
+#else
+#error "mips register size: unknown architecture level!!"
+#endif
+typedef struct {
+ __MIPS_REGISTER_TYPE s0;
+ __MIPS_REGISTER_TYPE s1;
+ __MIPS_REGISTER_TYPE s2;
+ __MIPS_REGISTER_TYPE s3;
+ __MIPS_REGISTER_TYPE s4;
+ __MIPS_REGISTER_TYPE s5;
+ __MIPS_REGISTER_TYPE s6;
+ __MIPS_REGISTER_TYPE s7;
+ __MIPS_REGISTER_TYPE sp;
+ __MIPS_REGISTER_TYPE fp;
+ __MIPS_REGISTER_TYPE ra;
+ __MIPS_REGISTER_TYPE c0_sr;
+ __MIPS_REGISTER_TYPE c0_epc;
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (uintptr_t) (_context)->sp
+
+/* WARNING: If this structure is modified, the constants in cpu.h
+ * must also be updated.
+ */
+
+typedef struct {
+#if ( CPU_HARDWARE_FP == TRUE )
+ __MIPS_FPU_REGISTER_TYPE fp0;
+ __MIPS_FPU_REGISTER_TYPE fp1;
+ __MIPS_FPU_REGISTER_TYPE fp2;
+ __MIPS_FPU_REGISTER_TYPE fp3;
+ __MIPS_FPU_REGISTER_TYPE fp4;
+ __MIPS_FPU_REGISTER_TYPE fp5;
+ __MIPS_FPU_REGISTER_TYPE fp6;
+ __MIPS_FPU_REGISTER_TYPE fp7;
+ __MIPS_FPU_REGISTER_TYPE fp8;
+ __MIPS_FPU_REGISTER_TYPE fp9;
+ __MIPS_FPU_REGISTER_TYPE fp10;
+ __MIPS_FPU_REGISTER_TYPE fp11;
+ __MIPS_FPU_REGISTER_TYPE fp12;
+ __MIPS_FPU_REGISTER_TYPE fp13;
+ __MIPS_FPU_REGISTER_TYPE fp14;
+ __MIPS_FPU_REGISTER_TYPE fp15;
+ __MIPS_FPU_REGISTER_TYPE fp16;
+ __MIPS_FPU_REGISTER_TYPE fp17;
+ __MIPS_FPU_REGISTER_TYPE fp18;
+ __MIPS_FPU_REGISTER_TYPE fp19;
+ __MIPS_FPU_REGISTER_TYPE fp20;
+ __MIPS_FPU_REGISTER_TYPE fp21;
+ __MIPS_FPU_REGISTER_TYPE fp22;
+ __MIPS_FPU_REGISTER_TYPE fp23;
+ __MIPS_FPU_REGISTER_TYPE fp24;
+ __MIPS_FPU_REGISTER_TYPE fp25;
+ __MIPS_FPU_REGISTER_TYPE fp26;
+ __MIPS_FPU_REGISTER_TYPE fp27;
+ __MIPS_FPU_REGISTER_TYPE fp28;
+ __MIPS_FPU_REGISTER_TYPE fp29;
+ __MIPS_FPU_REGISTER_TYPE fp30;
+ __MIPS_FPU_REGISTER_TYPE fp31;
+ uint32_t fpcs;
+#endif
+} Context_Control_fp;
+
+/*
+ * This struct reflects the stack frame employed in ISR_Handler. Note
+ * that the ISR routine save some of the registers to this frame for
+ * all interrupts and exceptions. Other registers are saved only on
+ * exceptions, while others are not touched at all. The untouched
+ * registers are not normally disturbed by high-level language
+ * programs so they can be accessed when required.
+ *
+ * The registers and their ordering in this struct must directly
+ * correspond to the layout and ordering of * shown in iregdef.h,
+ * as cpu_asm.S uses those definitions to fill the stack frame.
+ * This struct provides access to the stack frame for C code.
+ *
+ * Similarly, this structure is used by debugger stubs and exception
+ * processing routines so be careful when changing the format.
+ *
+ * NOTE: The comments with this structure and cpu_asm.S should be kept
+ * in sync. When in doubt, look in the code to see if the
+ * registers you're interested in are actually treated as expected.
+ * The order of the first portion of this structure follows the
+ * order of registers expected by gdb.
+ */
+
+typedef struct
+{
+ __MIPS_REGISTER_TYPE r0; /* 0 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE at; /* 1 -- saved always */
+ __MIPS_REGISTER_TYPE v0; /* 2 -- saved always */
+ __MIPS_REGISTER_TYPE v1; /* 3 -- saved always */
+ __MIPS_REGISTER_TYPE a0; /* 4 -- saved always */
+ __MIPS_REGISTER_TYPE a1; /* 5 -- saved always */
+ __MIPS_REGISTER_TYPE a2; /* 6 -- saved always */
+ __MIPS_REGISTER_TYPE a3; /* 7 -- saved always */
+ __MIPS_REGISTER_TYPE t0; /* 8 -- saved always */
+ __MIPS_REGISTER_TYPE t1; /* 9 -- saved always */
+ __MIPS_REGISTER_TYPE t2; /* 10 -- saved always */
+ __MIPS_REGISTER_TYPE t3; /* 11 -- saved always */
+ __MIPS_REGISTER_TYPE t4; /* 12 -- saved always */
+ __MIPS_REGISTER_TYPE t5; /* 13 -- saved always */
+ __MIPS_REGISTER_TYPE t6; /* 14 -- saved always */
+ __MIPS_REGISTER_TYPE t7; /* 15 -- saved always */
+ __MIPS_REGISTER_TYPE s0; /* 16 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s1; /* 17 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s2; /* 18 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s3; /* 19 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s4; /* 20 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s5; /* 21 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s6; /* 22 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE s7; /* 23 -- saved on exceptions */
+ __MIPS_REGISTER_TYPE t8; /* 24 -- saved always */
+ __MIPS_REGISTER_TYPE t9; /* 25 -- saved always */
+ __MIPS_REGISTER_TYPE k0; /* 26 -- NOT FILLED IN, kernel tmp reg */
+ __MIPS_REGISTER_TYPE k1; /* 27 -- NOT FILLED IN, kernel tmp reg */
+ __MIPS_REGISTER_TYPE gp; /* 28 -- saved always */
+ __MIPS_REGISTER_TYPE sp; /* 29 -- saved on exceptions NOT RESTORED */
+ __MIPS_REGISTER_TYPE fp; /* 30 -- saved always */
+ __MIPS_REGISTER_TYPE ra; /* 31 -- saved always */
+ __MIPS_REGISTER_TYPE c0_sr; /* 32 -- saved always, some bits are */
+ /* manipulated per-thread */
+ __MIPS_REGISTER_TYPE mdlo; /* 33 -- saved always */
+ __MIPS_REGISTER_TYPE mdhi; /* 34 -- saved always */
+ __MIPS_REGISTER_TYPE badvaddr; /* 35 -- saved on exceptions, read-only */
+ __MIPS_REGISTER_TYPE cause; /* 36 -- saved on exceptions NOT restored */
+ __MIPS_REGISTER_TYPE epc; /* 37 -- saved always, read-only register */
+ /* but logically restored */
+ __MIPS_FPU_REGISTER_TYPE f0; /* 38 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f1; /* 39 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f2; /* 40 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f3; /* 41 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f4; /* 42 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f5; /* 43 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f6; /* 44 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f7; /* 45 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f8; /* 46 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f9; /* 47 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f10; /* 48 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f11; /* 49 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f12; /* 50 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f13; /* 51 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f14; /* 52 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f15; /* 53 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f16; /* 54 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f17; /* 55 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f18; /* 56 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f19; /* 57 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f20; /* 58 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f21; /* 59 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f22; /* 60 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f23; /* 61 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f24; /* 62 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f25; /* 63 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f26; /* 64 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f27; /* 65 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f28; /* 66 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f29; /* 67 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f30; /* 68 -- saved if FP enabled */
+ __MIPS_FPU_REGISTER_TYPE f31; /* 69 -- saved if FP enabled */
+ __MIPS_REGISTER_TYPE fcsr; /* 70 -- saved on exceptions */
+ /* (oddly not documented on MGV) */
+ __MIPS_REGISTER_TYPE feir; /* 71 -- saved on exceptions */
+ /* (oddly not documented on MGV) */
+
+ /* GDB does not seem to care about anything past this point */
+
+ __MIPS_REGISTER_TYPE tlbhi; /* 72 - NOT FILLED IN, doesn't exist on */
+ /* all MIPS CPUs (at least MGV) */
+#if __mips == 1
+ __MIPS_REGISTER_TYPE tlblo; /* 73 - NOT FILLED IN, doesn't exist on */
+ /* all MIPS CPUs (at least MGV) */
+#endif
+#if (__mips == 3) || (__mips == 32)
+ __MIPS_REGISTER_TYPE tlblo0; /* 73 - NOT FILLED IN, doesn't exist on */
+ /* all MIPS CPUs (at least MGV) */
+#endif
+
+ __MIPS_REGISTER_TYPE inx; /* 74 -- NOT FILLED IN, doesn't exist on */
+ /* all MIPS CPUs (at least MGV) */
+ __MIPS_REGISTER_TYPE rand; /* 75 -- NOT FILLED IN, doesn't exist on */
+ /* all MIPS CPUs (at least MGV) */
+ __MIPS_REGISTER_TYPE ctxt; /* 76 -- NOT FILLED IN, doesn't exist on */
+ /* all MIPS CPUs (at least MGV) */
+ __MIPS_REGISTER_TYPE exctype; /* 77 -- NOT FILLED IN (not enough info) */
+ __MIPS_REGISTER_TYPE mode; /* 78 -- NOT FILLED IN (not enough info) */
+ __MIPS_REGISTER_TYPE prid; /* 79 -- NOT FILLED IN (not need to do so) */
+ __MIPS_REGISTER_TYPE tar ; /* 80 -- target address register, filled on exceptions */
+ /* end of __mips == 1 so NREGS == 81 */
+#if (__mips == 3) || (__mips == 32)
+ __MIPS_REGISTER_TYPE tlblo1; /* 81 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE pagemask; /* 82 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE wired; /* 83 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE count; /* 84 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE compare; /* 85 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE config; /* 86 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE lladdr; /* 87 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE watchlo; /* 88 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE watchhi; /* 89 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE ecc; /* 90 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE cacheerr; /* 91 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE taglo; /* 92 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE taghi; /* 93 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE errpc; /* 94 -- NOT FILLED IN */
+ __MIPS_REGISTER_TYPE xctxt; /* 95 -- NOT FILLED IN */
+ /* end of __mips == 3 so NREGS == 96 */
+#endif
+
+} CPU_Interrupt_frame;
+
+/*
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * _CPU_Initialize and copied into the task's FP context area during
+ * _CPU_Context_Initialize.
+ */
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ */
+
+/* XXX: if needed, put more variables here */
+
+/*
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * system initialization thread. Remember that in a multiprocessor
+ * system the system intialization thread becomes the MP server thread.
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by RTEMS.
+ */
+
+extern unsigned int mips_interrupt_number_of_vectors;
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS (mips_interrupt_number_of_vectors)
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/*
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE (8 * 1024)
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ */
+
+#define CPU_ALIGNMENT 8
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ */
+
+#define CPU_STACK_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * ISR handler macros
+ */
+
+/*
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ */
+
+#define _CPU_Initialize_vectors()
+
+/*
+ * Declare the function that is present in the shared libcpu directory,
+ * that returns the processor dependent interrupt mask.
+ */
+
+uint32_t mips_interrupt_mask( void );
+
+/*
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in _level.
+ */
+
+#define _CPU_ISR_Disable( _level ) \
+ do { \
+ unsigned int _scratch; \
+ mips_get_sr( _scratch ); \
+ mips_set_sr( _scratch & ~SR_INTERRUPT_ENABLE_BITS ); \
+ _level = _scratch & SR_INTERRUPT_ENABLE_BITS; \
+ } while(0)
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * _level is not modified.
+ */
+
+#define _CPU_ISR_Enable( _level ) \
+ do { \
+ unsigned int _scratch; \
+ mips_get_sr( _scratch ); \
+ mips_set_sr( (_scratch & ~SR_INTERRUPT_ENABLE_BITS) | (_level & SR_INTERRUPT_ENABLE_BITS) ); \
+ } while(0)
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+#define _CPU_ISR_Flash( _xlevel ) \
+ do { \
+ unsigned int _scratch2 = _xlevel; \
+ _CPU_ISR_Enable( _scratch2 ); \
+ _CPU_ISR_Disable( _scratch2 ); \
+ _xlevel = _scratch2; \
+ } while(0)
+
+/*
+ * Map interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * On the MIPS, 0 is all on. Non-zero is all off. This only
+ * manipulates the IEC.
+ */
+
+uint32_t _CPU_ISR_Get_level( void ); /* in cpu.c */
+
+void _CPU_ISR_Set_level( uint32_t ); /* in cpu.c */
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * NOTE: This is_fp parameter is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * The per-thread status register holds the interrupt enable, FP enable
+ * and global interrupt enable for that thread. It means each thread can
+ * enable its own set of interrupts. If interrupts are disabled, RTEMS
+ * can still dispatch via blocking calls. This is the function of the
+ * "Interrupt Level", and on the MIPS, it controls the IEC bit and all
+ * the hardware interrupts as defined in the SR. Software ints
+ * are automatically enabled for all threads, as they will only occur under
+ * program control anyhow. Besides, the interrupt level parm is only 8 bits,
+ * and controlling the software ints plus the others would require 9.
+ *
+ * If the Interrupt Level is 0, all ints are on. Otherwise, the
+ * Interrupt Level should supply a bit pattern to impose on the SR
+ * interrupt bits; bit 0 applies to the mips1 IEC bit/mips3 EXL&IE, bits 1 thru 6
+ * apply to the SR register Intr bits from bit 10 thru bit 15. Bit 7 of
+ * the Interrupt Level parameter is unused at this time.
+ *
+ * These are the only per-thread SR bits, the others are maintained
+ * globally & explicitly preserved by the Context Switch code in cpu_asm.s
+ */
+
+
+#if (__mips == 3) || (__mips == 32)
+#define _INTON SR_IE
+#if __mips_fpr==64
+#define _EXTRABITS SR_FR
+#else
+#define _EXTRABITS 0
+#endif /* __mips_fpr==64 */
+#endif /* __mips == 3 */
+#if __mips == 1
+#define _INTON SR_IEC
+#define _EXTRABITS 0 /* make sure we're in user mode on MIPS1 processors */
+#endif /* __mips == 1 */
+
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uintptr_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. Context_Restore should work most of the time. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/*
+ * The purpose of this macro is to allow the initial pointer into
+ * A floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other models include (1) not doing anything, and (2) putting
+ * a "null FP status word" in the correct place in the FP context.
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE )
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+#endif
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/*
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ */
+
+#define _CPU_Fatal_halt( _error ) \
+ do { \
+ unsigned int _level; \
+ _CPU_ISR_Disable(_level); \
+ loop: goto loop; \
+ } while (0)
+
+
+extern void mips_break( int error );
+
+/* Bitfield handler macros */
+
+/*
+ * This routine sets _output to the bit number of the first bit
+ * set in _value. _value is of CPU dependent type Priority_bit_map_Control.
+ * This type may be either 16 or 32 bits wide although only the 16
+ * least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * (1) What happens when run on a value of zero?
+ * (2) Bits may be numbered from MSB to LSB or vice-versa.
+ * (3) The numbering may be zero or one based.
+ * (4) The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
+ * _CPU_Priority_bits_index(). These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by _CPU_Priority_mask().
+ * The basic major and minor values calculated by _Priority_Major()
+ * and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for _Priority_Get_highest() to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+ * - a series of 16 bit test instructions
+ * - a "binary search using if's"
+ * - _number = 0
+ * if _value > 0x00ff
+ * _value >>=8
+ * _number = 8;
+ *
+ * if _value > 0x0000f
+ * _value >=8
+ * _number += 4
+ *
+ * _number += bit_set_table[ _value ]
+ *
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+
+#endif
+
+/* end of Bitfield handler macros */
+
+/*
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by _CPU_Bitfield_Find_first_bit(). See the discussion
+ * for that routine.
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/*
+ * This routine translates the bit numbers returned by
+ * _CPU_Bitfield_Find_first_bit() into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Install_interrupt_stack
+ *
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * NOTE: It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ */
+
+void _CPU_Install_interrupt_stack( void );
+
+/*
+ * _CPU_Internal_threads_Idle_thread_body
+ *
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * NOTE: It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/* The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ */
+
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+
+#endif
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/mips/rtems/score/mips.h b/cpukit/score/cpu/mips/rtems/score/mips.h
new file mode 100644
index 0000000000..8c4f3ae0f4
--- /dev/null
+++ b/cpukit/score/cpu/mips/rtems/score/mips.h
@@ -0,0 +1,283 @@
+/**
+ * @file rtems/score/mips.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_MIPS_H
+#define _RTEMS_SCORE_MIPS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef ASM
+#include <rtems/mips/idtcpu.h>
+#endif
+
+/*
+ * SR bits that enable/disable interrupts
+ *
+ * NOTE: XXX what about SR_ERL?
+ */
+
+#if (__mips == 3) || (__mips == 32)
+#ifdef ASM
+#define SR_INTERRUPT_ENABLE_BITS 0x01
+#else
+#define SR_INTERRUPT_ENABLE_BITS SR_IE
+#endif
+
+#elif __mips == 1
+#define SR_INTERRUPT_ENABLE_BITS SR_IEC
+
+#else
+#error "mips interrupt enable bits: unknown architecture level!"
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the "no cpu"
+ * family when executing in protected mode. It does
+ * this by setting variables to indicate which implementation
+ * dependent features are present in a particular member
+ * of the family.
+ */
+
+#if defined(__mips_soft_float)
+#define MIPS_HAS_FPU 0
+#else
+#define MIPS_HAS_FPU 1
+#endif
+
+
+#if (__mips == 1)
+#define CPU_MODEL_NAME "ISA Level 1 or 2"
+#elif (__mips == 3) || (__mips == 32)
+#if defined(__mips64)
+#define CPU_MODEL_NAME "ISA Level 4"
+#else
+#define CPU_MODEL_NAME "ISA Level 3"
+#endif
+#else
+#error "Unknown MIPS ISA level"
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "MIPS"
+
+/*
+ * RTEMS Vector numbers for exception conditions. This is a direct
+ * map to the causes.
+ */
+
+#define MIPS_EXCEPTION_BASE 0
+
+#define MIPS_EXCEPTION_INT MIPS_EXCEPTION_BASE+0
+#define MIPS_EXCEPTION_MOD MIPS_EXCEPTION_BASE+1
+#define MIPS_EXCEPTION_TLBL MIPS_EXCEPTION_BASE+2
+#define MIPS_EXCEPTION_TLBS MIPS_EXCEPTION_BASE+3
+#define MIPS_EXCEPTION_ADEL MIPS_EXCEPTION_BASE+4
+#define MIPS_EXCEPTION_ADES MIPS_EXCEPTION_BASE+5
+#define MIPS_EXCEPTION_IBE MIPS_EXCEPTION_BASE+6
+#define MIPS_EXCEPTION_DBE MIPS_EXCEPTION_BASE+7
+#define MIPS_EXCEPTION_SYSCALL MIPS_EXCEPTION_BASE+8
+#define MIPS_EXCEPTION_BREAK MIPS_EXCEPTION_BASE+9
+#define MIPS_EXCEPTION_RI MIPS_EXCEPTION_BASE+10
+#define MIPS_EXCEPTION_CPU MIPS_EXCEPTION_BASE+11
+#define MIPS_EXCEPTION_OVERFLOW MIPS_EXCEPTION_BASE+12
+#define MIPS_EXCEPTION_TRAP MIPS_EXCEPTION_BASE+13
+#define MIPS_EXCEPTION_VCEI MIPS_EXCEPTION_BASE+14
+/* FPE only on mips2 and higher */
+#define MIPS_EXCEPTION_FPE MIPS_EXCEPTION_BASE+15
+#define MIPS_EXCEPTION_C2E MIPS_EXCEPTION_BASE+16
+/* 17-22 reserved */
+#define MIPS_EXCEPTION_WATCH MIPS_EXCEPTION_BASE+23
+/* 24-30 reserved */
+#define MIPS_EXCEPTION_VCED MIPS_EXCEPTION_BASE+31
+
+#define MIPS_INTERRUPT_BASE MIPS_EXCEPTION_BASE+32
+
+/*
+ * Some macros to access registers
+ */
+
+#define mips_get_sr( _x ) \
+ do { \
+ __asm__ volatile( "mfc0 %0, $12; nop" : "=r" (_x) : ); \
+ } while (0)
+
+#define mips_set_sr( _x ) \
+ do { \
+ register unsigned int __x = (_x); \
+ __asm__ volatile( "mtc0 %0, $12; nop" : : "r" (__x) ); \
+ } while (0)
+
+
+/*
+ * Access the Cause register
+ */
+
+#define mips_get_cause( _x ) \
+ do { \
+ __asm__ volatile( "mfc0 %0, $13; nop" : "=r" (_x) : ); \
+ } while (0)
+
+
+#define mips_set_cause( _x ) \
+ do { \
+ register unsigned int __x = (_x); \
+ __asm__ volatile( "mtc0 %0, $13; nop" : : "r" (__x) ); \
+ } while (0)
+
+
+
+
+/*
+ * Access the Debug Cache Invalidate Control register
+ */
+
+#define mips_get_dcic( _x ) \
+ do { \
+ __asm__ volatile( "mfc0 %0, $7; nop" : "=r" (_x) : ); \
+ } while (0)
+
+
+#define mips_set_dcic( _x ) \
+ do { \
+ register unsigned int __x = (_x); \
+ __asm__ volatile( "mtc0 %0, $7; nop" : : "r" (__x) ); \
+ } while (0)
+
+
+
+
+/*
+ * Access the Breakpoint Program Counter & Mask registers
+ * (_x for BPC, _y for mask)
+ */
+
+#define mips_get_bpcrm( _x, _y ) \
+ do { \
+ __asm__ volatile( "mfc0 %0, $3; nop" : "=r" (_x) : ); \
+ __asm__ volatile( "mfc0 %0, $11; nop" : "=r" (_y) : ); \
+ } while (0)
+
+
+#define mips_set_bpcrm( _x, _y ) \
+ do { \
+ register unsigned int __x = (_x); \
+ register unsigned int __y = (_y); \
+ __asm__ volatile( "mtc0 %0, $11; nop" : : "r" (__y) ); \
+ __asm__ volatile( "mtc0 %0, $3; nop" : : "r" (__x) ); \
+ } while (0)
+
+
+
+
+
+
+/*
+ * Access the Breakpoint Data Address & Mask registers
+ * (_x for BDA, _y for mask)
+ */
+
+#define mips_get_bdarm( _x, _y ) \
+ do { \
+ __asm__ volatile( "mfc0 %0, $5; nop" : "=r" (_x) : ); \
+ __asm__ volatile( "mfc0 %0, $9; nop" : "=r" (_y) : ); \
+ } while (0)
+
+
+#define mips_set_bdarm( _x, _y ) \
+ do { \
+ register unsigned int __x = (_x); \
+ register unsigned int __y = (_y); \
+ __asm__ volatile( "mtc0 %0, $9; nop" : : "r" (__y) ); \
+ __asm__ volatile( "mtc0 %0, $5; nop" : : "r" (__x) ); \
+ } while (0)
+
+
+
+
+
+
+
+/*
+ * Access FCR31
+ */
+
+#if ( MIPS_HAS_FPU == 1 )
+
+#define mips_get_fcr31( _x ) \
+ do { \
+ __asm__ volatile( "cfc1 %0, $31; nop" : "=r" (_x) : ); \
+ } while(0)
+
+
+#define mips_set_fcr31( _x ) \
+ do { \
+ register unsigned int __x = (_x); \
+ __asm__ volatile( "ctc1 %0, $31; nop" : : "r" (__x) ); \
+ } while(0)
+
+#else
+
+#define mips_get_fcr31( _x )
+#define mips_set_fcr31( _x )
+
+#endif
+
+/*
+ * Manipulate interrupt mask
+ *
+ * mips_unmask_interrupt( _mask)
+ * enables interrupts - mask is positioned so it only needs to be or'ed
+ * into the status reg. This also does some other things !!!! Caution
+ * should be used if invoking this while in the middle of a debugging
+ * session where the client may have nested interrupts.
+ *
+ * mips_mask_interrupt( _mask )
+ * disable the interrupt - mask is the complement of the bits to be
+ * cleared - i.e. to clear ext int 5 the mask would be - 0xffff7fff
+ *
+ *
+ * NOTE: mips_mask_interrupt() used to be disable_int().
+ * mips_unmask_interrupt() used to be enable_int().
+ *
+ */
+
+#define mips_enable_in_interrupt_mask( _mask ) \
+ do { \
+ unsigned int _sr; \
+ mips_get_sr( _sr ); \
+ _sr |= (_mask); \
+ mips_set_sr( _sr ); \
+ } while (0)
+
+#define mips_disable_in_interrupt_mask( _mask ) \
+ do { \
+ unsigned int _sr; \
+ mips_get_sr( _sr ); \
+ _sr &= ~(_mask); \
+ mips_set_sr( _sr ); \
+ } while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_MIPS_H */
+/* end of include file */
diff --git a/cpukit/score/cpu/mips/rtems/score/types.h b/cpukit/score/cpu/mips/rtems/score/types.h
new file mode 100644
index 0000000000..67b253bcf8
--- /dev/null
+++ b/cpukit/score/cpu/mips/rtems/score/types.h
@@ -0,0 +1,45 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the MIPS
+ * processor family.
+ *
+ * COPYRIGHT (c) 1989-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+/* @(#)mipstypes.h 08/20/96 1.4 */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void mips_isr;
+typedef void ( *mips_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/nios2/.cvsignore b/cpukit/score/cpu/nios2/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/nios2/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/nios2/ChangeLog b/cpukit/score/cpu/nios2/ChangeLog
new file mode 100644
index 0000000000..91a08f2b23
--- /dev/null
+++ b/cpukit/score/cpu/nios2/ChangeLog
@@ -0,0 +1,141 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * irq.c:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * irq.c: Rename _Context_Switch_necessary to _Thread_Dispatch_necessary
+ to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * irq.c, rtems/score/cpu.h: Add a per cpu data structure which contains
+ the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S, irq.c: Add include of config.h
+
+2009-03-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.S: Eliminate extern of unused variables.
+
+2009-03-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Remove stray semi-colon.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Remove extraneous spaces.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * irq.c: Sweep to make sure grep for COPYRIGHT passes.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * .cvsignore: New file.
+
+2006-08-09 Kolja Waschk <waschk@telos.de>
+
+ * rtems/score/cpu.h, rtems/score/cpu_asm.h, rtems/score/nios2.h,
+ rtems/score/types.h: New files.
+
+2006-08-09 Kolja Waschk <waschk@telos.de>
+
+ * ChangeLog, Makefile.am, cpu.c, cpu_asm.S, irq.c, preinstall.am,
+ rtems/asm.h: New files.
+
+2005-12-09 Kolja Waschk <rtemsdev@ixo.de>
+
+ Derived from no_cpu
+
diff --git a/cpukit/score/cpu/nios2/Makefile.am b/cpukit/score/cpu/nios2/Makefile.am
new file mode 100644
index 0000000000..c1680f82fc
--- /dev/null
+++ b/cpukit/score/cpu/nios2/Makefile.am
@@ -0,0 +1,25 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+CLEANFILES =
+DISTCLEANFILES =
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/nios2.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c irq.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+all-local: $(PREINSTALL_FILES)
+
+include $(srcdir)/preinstall.am
+
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/nios2/cpu.c b/cpukit/score/cpu/nios2/cpu.c
new file mode 100644
index 0000000000..ff24be7efd
--- /dev/null
+++ b/cpukit/score/cpu/nios2/cpu.c
@@ -0,0 +1,180 @@
+/*
+ * NIOS2 CPU Dependent Source
+ *
+ * COPYRIGHT (c) 1989-2006
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Initialize(void)
+{
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ /*
+ * This routine returns the current interrupt level.
+ */
+
+ return 0;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+#if 1
+ for(;;);
+#else
+ for(;;)
+ {
+ uint32_t st = __builtin_rdctl(0); /* read status register */
+
+ /* Differentiate between IRQ off and on (for debugging) */
+ if(st & 1)
+ for(;;);
+ else
+ for(;;);
+
+ /* insert your "halt" instruction here */ ;
+ }
+#endif
+}
diff --git a/cpukit/score/cpu/nios2/cpu_asm.S b/cpukit/score/cpu/nios2/cpu_asm.S
new file mode 100644
index 0000000000..206fa262f0
--- /dev/null
+++ b/cpukit/score/cpu/nios2/cpu_asm.S
@@ -0,0 +1,386 @@
+/*
+ * $Id$
+ *
+ * This file contains all assembly code for the
+ * NIOS2 implementation of RTEMS.
+ *
+ * Copyright (c) 2006 Kolja Waschk (rtemsdev/ixo.de)
+ *
+ * Derived from no_cpu/cpu_asm.S, copyright (c) 1989-1999,
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/score/cpu_asm.h>
+
+ .set noat
+
+/* ===================================================================== */
+
+/*
+ * void _CPU_Context_switch( run_context, heir_context )
+ * void _CPU_Context_restore( run_context, heir_context )
+ *
+ * This routine performs a normal non-FP context switch.
+ */
+
+ .globl _CPU_Context_switch
+
+_CPU_Context_switch:
+
+ rdctl r6, status
+ stw r16, 0(r4)
+ stw r17, 4(r4)
+ stw r18, 8(r4)
+ stw r19, 12(r4)
+ stw r20, 16(r4)
+ stw r21, 20(r4)
+ stw r22, 24(r4)
+ stw r23, 28(r4)
+ stw gp, 32(r4)
+ stw fp, 36(r4)
+ stw sp, 40(r4)
+ stw ra, 44(r4)
+ /* r6 saved status */
+ stw r6, 48(r4)
+
+_CPU_Context_switch_restore:
+
+ ldw r16, 0(r5)
+ ldw r17, 4(r5)
+ ldw r18, 8(r5)
+ ldw r19, 12(r5)
+ ldw r20, 16(r5)
+ ldw r21, 20(r5)
+ ldw r22, 24(r5)
+ ldw r23, 28(r5)
+ ldw gp, 32(r5)
+ ldw fp, 36(r5)
+ ldw sp, 40(r5)
+
+ /* Disable interrupts */
+ wrctl status, r0
+
+ ldw ea, 44(r5)
+ ldw at, 48(r5)
+ /* FIXME: Always have interrupts enabled when we return from Context_switch */
+ ori at, at, 1
+ wrctl estatus, at
+
+ eret
+
+ .globl _CPU_Context_restore
+
+_CPU_Context_restore:
+
+ /* Copy first to second arg, then re-use 2nd half of Context_switch */
+ mov r5, r4
+ br _CPU_Context_switch_restore
+
+
+/* ===================================================================== */
+
+ .globl _exception_vector
+
+_exception_vector:
+
+ /*
+ * First, re-wind so we're pointed to the instruction where the exception
+ * occurred.
+ */
+
+ addi ea, ea, -4
+
+ /*
+ * Now test to determine the cause of the exception.
+ */
+
+ /* TODO: Look at [ea] if there was an unknown/trap instruction */
+
+ /* If interrupts are globally disabled, it certainly was no interrupt */
+ rdctl et, estatus
+ andi et, et, 1
+ beq et, zero, _Exception_Handler
+
+ /* If no interrupts are pending, it was a software exception */
+ rdctl et, ipending
+ beq et, zero, _Exception_Handler
+
+ /*
+ * Falling through to here means that this was a hardware interrupt.
+ */
+
+ br _ISR_Handler
+
+/* =====================================================================
+ * Exception handler:
+ * Responsible for unimplemented instructions and other software
+ * exceptions. Not responsible for hardware interrupts. Currently,
+ * software exceptions are regarded as error conditions, and the
+ * handling isn't perfect. */
+
+_Exception_Handler:
+
+ /* stw et, 108(sp') => stw et, -20(sp) */
+ stw et, -20(sp)
+ mov et, sp
+ addi sp, sp, -128
+
+ stw r1, 0(sp)
+ stw r2, 4(sp)
+ stw r3, 8(sp)
+
+ rdctl r1, estatus
+ rdctl r2, ienable
+ rdctl r3, ipending
+
+ stw r4, 12(sp)
+ stw r5, 16(sp)
+ stw r6, 20(sp)
+ stw r7, 24(sp)
+ stw r8, 28(sp)
+ stw r9, 32(sp)
+ stw r10, 36(sp)
+ stw r11, 40(sp)
+ stw r12, 44(sp)
+ stw r13, 48(sp)
+ stw r14, 52(sp)
+ stw r15, 56(sp)
+ stw r16, 60(sp)
+ stw r17, 64(sp)
+ stw r18, 68(sp)
+ stw r19, 72(sp)
+ stw r20, 76(sp)
+ stw r21, 80(sp)
+ stw r22, 84(sp)
+ stw r23, 88(sp)
+ stw gp, 92(sp)
+ stw fp, 96(sp)
+ /* sp */
+ stw et, 100(sp)
+ stw ra, 104(sp)
+ /* stw et, 108(sp) */
+ stw ea, 112(sp)
+
+ /* status */
+ stw r1, 116(sp)
+ /* ienable */
+ stw r2, 120(sp)
+ /* ipending */
+ stw r3, 124(sp)
+
+ /*
+ * Restore the global pointer.
+ */
+
+ movhi gp, %hiadj(_gp)
+ addi gp, gp, %lo(_gp)
+
+ /*
+ * Pass a pointer to the stack frame as the input argument of the
+ * exception handler (CPU_Exception_frame *).
+ */
+
+ mov r4, sp
+
+ /*
+ * Call the exception handler.
+ */
+
+ .extern __Exception_Handler
+ call __Exception_Handler
+
+stuck_in_exception:
+ br stuck_in_exception
+
+ /*
+ * Restore the saved registers, so that all general purpose registers
+ * have been restored to their state at the time the interrupt occured.
+ */
+
+ ldw r1, 0(sp)
+ ldw r2, 4(sp)
+ ldw r3, 8(sp)
+ ldw r4, 12(sp)
+ ldw r5, 16(sp)
+ ldw r6, 20(sp)
+ ldw r7, 24(sp)
+ ldw r8, 28(sp)
+ ldw r9, 32(sp)
+ ldw r10, 36(sp)
+ ldw r11, 40(sp)
+ ldw r12, 44(sp)
+ ldw r13, 48(sp)
+ ldw r14, 52(sp)
+ ldw r15, 56(sp)
+ ldw r16, 60(sp)
+ ldw r17, 64(sp)
+ ldw r18, 68(sp)
+ ldw r19, 72(sp)
+ ldw r20, 76(sp)
+ ldw r21, 80(sp)
+ ldw r22, 84(sp)
+ ldw r23, 88(sp)
+ ldw gp, 92(sp)
+ ldw fp, 96(sp)
+ ldw ra, 104(sp)
+
+ /* Disable interrupts */
+ wrctl status, r0
+
+ ldw ea, 112(sp)
+ ldw et, 116(sp)
+
+ /* FIXME: Enable interrupts after exception processing */
+ ori et, et, 1
+ wrctl estatus, et
+ ldw et, 108(sp)
+
+ /* Restore stack pointer */
+ ldw sp, 100(sp)
+
+ eret
+
+/* ===================================================================== */
+
+ .section .text
+
+_ISR_Handler:
+
+ /*
+ * Process an external hardware interrupt.
+ *
+ * First, preserve all callee saved registers on
+ * the stack. (See the Nios2 ABI documentation for details).
+ *
+ * Do we really need to save all?
+ *
+ * If this is interrupting a task (and not another interrupt),
+ * everything is saved into the task's stack, thus putting us
+ * in a situation similar to when the task calls a subroutine
+ * (and only the CPU_Context_Control subset needs to be changed)
+ */
+
+ rdctl et, estatus
+
+ /* Keep this in the same order as CPU_Interrupt_frame: */
+
+ addi sp, sp, -76
+ stw r1, 0(sp)
+ stw r2, 4(sp)
+ stw r3, 8(sp)
+ stw r4, 12(sp)
+ stw r5, 16(sp)
+ stw r6, 20(sp)
+ stw r7, 24(sp)
+ stw r8, 28(sp)
+ stw r9, 32(sp)
+ stw r10, 36(sp)
+ stw r11, 40(sp)
+ stw r12, 44(sp)
+ stw r13, 48(sp)
+ stw r14, 52(sp)
+ stw r15, 56(sp)
+ stw ra, 60(sp)
+ stw gp, 64(sp)
+ /* et contains status */
+ stw et, 68(sp)
+ stw ea, 72(sp)
+
+ /*
+ * Obtain a bitlist of the pending interrupts.
+ */
+
+ rdctl et, ipending
+
+ /*
+ * Restore the global pointer to the expected value.
+ */
+
+ movhi gp, %hiadj(_gp)
+ addi gp, gp, %lo(_gp)
+
+ /*
+ * Search through the bit list stored in r24(et) to find the first enabled
+ * bit. The offset of this bit is the index of the interrupt that is
+ * to be handled.
+ */
+
+ mov r4, zero
+6:
+ andi r3, r24, 1
+ bne r3, zero, 7f
+ addi r4, r4, 1
+ srli r24, r24, 1
+ br 6b
+7:
+
+ /*
+ * Having located the interrupt source, r4 contains the index of the
+ * interrupt to be handled. r5, the 2nd argument to the function,
+ * will point to the CPU_Interrupt_frame.
+ */
+
+ mov r5, sp
+
+ .extern __ISR_Handler
+ call __ISR_Handler
+
+ /*
+ * Now that the interrupt processing is complete, prepare to return to
+ * the interrupted code.
+ */
+
+ /*
+ * Restore the saved registers, so that all general purpose registers
+ * have been restored to their state at the time the interrupt occured.
+ */
+
+ ldw r1, 0(sp)
+ ldw r2, 4(sp)
+ ldw r3, 8(sp)
+ ldw r4, 12(sp)
+ ldw r5, 16(sp)
+ ldw r6, 20(sp)
+ ldw r7, 24(sp)
+ ldw r8, 28(sp)
+ ldw r9, 32(sp)
+ ldw r10, 36(sp)
+ ldw r11, 40(sp)
+ ldw r12, 44(sp)
+ ldw r13, 48(sp)
+ ldw r14, 52(sp)
+ ldw r15, 56(sp)
+ ldw ra, 60(sp)
+ ldw gp, 64(sp)
+
+ /* Disable interrupts */
+ wrctl status, r0
+
+ /* Restore the exception registers */
+
+ /* load saved ea into ea */
+ ldw ea, 72(sp)
+ /* load saved estatus into et */
+ ldw et, 68(sp)
+ /* Always have interrupts enabled when we return from interrupt */
+ ori et, et, 1
+ wrctl estatus, et
+ /* Restore the stack pointer */
+ addi sp, sp, 76
+
+ /*
+ * Return to the interrupted instruction.
+ */
+ eret
+
+
diff --git a/cpukit/score/cpu/nios2/irq.c b/cpukit/score/cpu/nios2/irq.c
new file mode 100644
index 0000000000..2d4aac820f
--- /dev/null
+++ b/cpukit/score/cpu/nios2/irq.c
@@ -0,0 +1,91 @@
+/*
+ * NIOS2 exception and interrupt handler
+ *
+ * Derived from c4x/irq.c
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+
+/*
+ * This routine provides the RTEMS interrupt management.
+ *
+ * Upon entry, interrupts are disabled
+ */
+
+#if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ unsigned long *_old_stack_ptr;
+#endif
+
+register unsigned long *stack_ptr __asm__ ("sp");
+
+void __ISR_Handler(uint32_t vector, CPU_Interrupt_frame *ifr)
+{
+ register uint32_t level;
+
+ /* Interrupts are disabled upon entry to this Handler */
+
+#if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ if ( _ISR_Nest_level == 0 ) {
+ /* Install irq stack */
+ _old_stack_ptr = stack_ptr;
+ stack_ptr = _CPU_Interrupt_stack_high - 4;
+ }
+#endif
+
+ _ISR_Nest_level++;
+
+ _Thread_Dispatch_disable_level++;
+
+ if ( _ISR_Vector_table[ vector] )
+ {
+ (*_ISR_Vector_table[ vector ])(vector, ifr);
+ };
+
+ /* Make sure that interrupts are disabled again */
+ _CPU_ISR_Disable( level );
+
+ _Thread_Dispatch_disable_level--;
+
+ _ISR_Nest_level--;
+
+ if( _ISR_Nest_level == 0) {
+#if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ stack_ptr = _old_stack_ptr;
+#endif
+
+ if( _Thread_Dispatch_disable_level == 0 )
+ {
+ if ( _Thread_Dispatch_necessary ) {
+ _CPU_ISR_Enable( level );
+ _Thread_Dispatch();
+ /* may have switched to another task and not return here immed. */
+ _CPU_ISR_Disable( level ); /* Keep _pairs_ of Enable/Disable */
+ }
+ }
+ }
+
+ _CPU_ISR_Enable( level );
+}
+
+void __Exception_Handler(CPU_Exception_frame *efr)
+{
+ _CPU_Fatal_halt(0xECC0);
+}
+
+
diff --git a/cpukit/score/cpu/nios2/preinstall.am b/cpukit/score/cpu/nios2/preinstall.am
new file mode 100644
index 0000000000..fd609c0ce8
--- /dev/null
+++ b/cpukit/score/cpu/nios2/preinstall.am
@@ -0,0 +1,45 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES += $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/nios2.h: rtems/score/nios2.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/nios2.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/nios2.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/nios2/rtems/asm.h b/cpukit/score/cpu/nios2/rtems/asm.h
new file mode 100644
index 0000000000..390048d353
--- /dev/null
+++ b/cpukit/score/cpu/nios2/rtems/asm.h
@@ -0,0 +1,97 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/nios2.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/nios2/rtems/score/cpu.h b/cpukit/score/cpu/nios2/rtems/score/cpu.h
new file mode 100644
index 0000000000..810671bb73
--- /dev/null
+++ b/cpukit/score/cpu/nios2/rtems/score/cpu.h
@@ -0,0 +1,1310 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the XXX
+ * processor.
+ *
+ * @note This file is part of a porting template that is intended
+ * to be used as the starting point when porting RTEMS to a new
+ * CPU family. The following needs to be done when using this as
+ * the starting point for a new port:
+ *
+ * + Anywhere there is an XXX, it should be replaced
+ * with information about the CPU family being ported to.
+ *
+ * + At the end of each comment section, there is a heading which
+ * says "Port Specific Information:". When porting to RTEMS,
+ * add CPU family specific information in this section
+ */
+
+/* COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/nios2.h>
+
+/* conditional compilation parameters */
+
+/**
+ * Should the calls to @ref _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * This conditional is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ *
+ * @note In general, the @ref _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls @ref _Thread_Enable_dispatch which in turns calls
+ * @ref _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/**
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/**
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/**
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/**
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE
+ * or @ref CPU_INSTALL_HARDWARE_INTERRUPT_STACK is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ISR_PASSES_FRAME_POINTER 1
+
+/**
+ * @def CPU_HARDWARE_FP
+ *
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the @ref RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the @ref RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+/**
+ * @def CPU_SOFTWARE_FP
+ *
+ * Does the CPU have no hardware floating point and GCC provides a
+ * software floating point implementation which must be context
+ * switched?
+ *
+ * This feature conditional is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HARDWARE_FP FALSE
+#define CPU_SOFTWARE_FP FALSE
+
+/**
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the @ref RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the @ref RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/**
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a @ref RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/**
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/**
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine @ref _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * @ref _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * -# BSP provided
+ * -# CPU dependent (if provided)
+ * -# generic (if no BSP and no CPU dependent)
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/**
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_GROWS_UP FALSE
+
+/**
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * @note Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STRUCTURE_ALIGNMENT
+
+/**
+ * @defgroup CPUEndian Processor Dependent Endianness Support
+ *
+ * This group assists in issues related to processor endianness.
+ */
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_LITTLE_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_BIG_ENDIAN FALSE
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_BIG_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_LITTLE_ENDIAN TRUE
+
+/**
+ * @ingroup CPUInterrupt
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+/**
+ * @defgroup CPUContext Processor Dependent Context Management
+ *
+ * From the highest level viewpoint, there are 2 types of context to save.
+ *
+ * -# Interrupt registers to save
+ * -# Task level registers to save
+ *
+ * Since RTEMS handles integer and floating point contexts separately, this
+ * means we have the following 3 context items:
+ *
+ * -# task level context stuff:: Context_Control
+ * -# floating point task stuff:: Context_Control_fp
+ * -# special interrupt level context :: CPU_Interrupt_frame
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the minimal set of integer and processor state registers
+ * that must be saved during a voluntary context switch from one thread
+ * to another.
+ */
+typedef struct {
+ uint32_t r16;
+ uint32_t r17;
+ uint32_t r18;
+ uint32_t r19;
+ uint32_t r20;
+ uint32_t r21;
+ uint32_t r22;
+ uint32_t r23;
+ uint32_t gp;
+ uint32_t fp;
+ uint32_t sp;
+ uint32_t ra;
+ uint32_t status;
+ /* ienable? */
+ /* ipending? */
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->sp
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the complete set of floating point registers that must
+ * be saved during any context switch from one thread to another.
+ */
+typedef struct {
+} Context_Control_fp;
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that must
+ * be saved during an interrupt. This set does not include any which are
+ * in @ref Context_Control.
+ */
+typedef struct {
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t r11;
+ uint32_t r12;
+ uint32_t r13;
+ uint32_t r14;
+ uint32_t r15;
+ uint32_t ra;
+ uint32_t gp;
+ uint32_t et;
+ uint32_t ea;
+} CPU_Interrupt_frame;
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that are
+ * saved during a software exception.
+ */
+typedef struct {
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t r11;
+ uint32_t r12;
+ uint32_t r13;
+ uint32_t r14;
+ uint32_t r15;
+ uint32_t r16;
+ uint32_t r17;
+ uint32_t r18;
+ uint32_t r19;
+ uint32_t r20;
+ uint32_t r21;
+ uint32_t r22;
+ uint32_t r23;
+ uint32_t gp;
+ uint32_t fp;
+ uint32_t sp;
+ uint32_t ra;
+ uint32_t et;
+ uint32_t ea;
+ uint32_t status;
+ uint32_t ienable;
+ uint32_t ipending;
+} CPU_Exception_frame;
+
+/**
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * @ref _CPU_Initialize and copied into the task's FP context area during
+ * @ref _CPU_Context_Initialize.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if 0
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+#endif
+
+/**
+ * @defgroup CPUInterrupt Processor Dependent Interrupt Management
+ *
+ * On some CPUs, RTEMS supports a software managed interrupt stack.
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in @ref _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use.
+ *
+ * @note These two variables are required if the macro
+ * @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/**
+ * @ingroup CPUContext
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/**
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the number of entries in the @ref _ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the highest interrupt vector number for this port.
+ */
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/**
+ * @ingroup CPUInterrupt
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable @a _ISR_Nest_level.
+ */
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/**
+ * @ingroup CPUContext
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_MINIMUM_SIZE (1024*4)
+/* kawk: was *4 */
+
+/**
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALIGNMENT 4
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by @ref CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for
+ * the heap, then this should be set to @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * @ref CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is
+ * strict enough for the partition, then this should be set to
+ * @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2. It does have to
+ * be greater or equal to than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by @ref CPU_ALIGNMENT. If the
+ * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
+ * set to 0.
+ *
+ * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_ALIGNMENT 0
+
+/*
+ * ISR handler macros
+ */
+
+/**
+ * @ingroup CPUInterrupt
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Initialize_vectors()
+
+/**
+ * @ingroup CPUInterrupt
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in @a _isr_cookie.
+ *
+ * @param _isr_cookie (out) will contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ { \
+ _isr_cookie = __builtin_rdctl(0); /* read status register */ \
+ __builtin_wrctl(0, 0); /* write 0 to status register */ \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * @a _isr_cookie is not modified.
+ *
+ * @param _isr_cookie (in) contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ { \
+ __builtin_wrctl( 0, _isr_cookie ); \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * This temporarily restores the interrupt to @a _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter @a _isr_cookie is not
+ * modified.
+ *
+ * @param _isr_cookie (in) contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ { \
+ __builtin_wrctl( 0, _isr_cookie ); \
+ /* TODO: Does NIOS2 get a chance to \
+ process IRQ between these statements? */ \
+ __builtin_wrctl( 0, 0 ); \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ *
+ * This routine and @ref _CPU_ISR_Get_level
+ * Map the interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Set_level( new_level ) \
+ _CPU_ISR_Enable( ( new_level==0 ) ? 1 : 0 );
+
+/**
+ * @ingroup CPUInterrupt
+ * Return the current interrupt disable level for this task in
+ * the format used by the interrupt level portion of the task mode.
+ *
+ * @note This routine usually must be implemented as a subroutine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/**
+ * @ingroup CPUContext
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * @param _the_context (in) is the context structure to be initialized
+ * @param _stack_base (in) is the lowest physical address of this task's stack
+ * @param _size (in) is the size of this task's stack
+ * @param _isr (in) is the interrupt disable level
+ * @param _entry_point (in) is the thread's entry point. This is
+ * always @a _Thread_Handler
+ * @param _is_fp (in) is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ do { \
+ extern char _gp[]; \
+ uint32_t _stack = (uint32_t)(_stack_base) + (_size) - 4; \
+ (_the_context)->gp = (void *)_gp; \
+ (_the_context)->fp = (void *)_stack; \
+ (_the_context)->sp = (void *)_stack; \
+ (_the_context)->ra = (void *)(_entry_point); \
+ (_the_context)->status = 0x1; /* IRQs enabled */ \
+ } while ( 0 )
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. @ref _CPU_Context_Restore should work most of the time. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/**
+ * @ingroup CPUContext
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * @param _base (in) is the lowest physical address of the floating point
+ * context area
+ * @param _offset (in) is the offset into the floating point area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if 1
+#define _CPU_Context_Fp_start( _base, _offset )
+#else
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+#endif
+
+/**
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * @a _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other floating point context save/restore models include:
+ * -# not doing anything, and
+ * -# putting a "null FP status word" in the correct place in the FP context.
+ *
+ * @param _destination (in) is the floating point context area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if 1
+#define _CPU_Context_Initialize_fp( _destination )
+#else
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+#endif
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/**
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ __builtin_wrctl(0, 0); /* write 0 to status register (disable interrupts) */ \
+ __asm volatile ("mov et, %z0" : : "rM" (_error)); /* write error code to ET register */ \
+ for(;;); \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/**
+ * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
+ *
+ * This set of routines are used to implement fast searches for
+ * the most important ready task.
+ */
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the generic bitfield
+ * manipulation implementation.
+ */
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the data tables provided
+ * by the generic bitfield manipulation implementation.
+ * This can occur when actually using the generic bitfield manipulation
+ * implementation or when implementing the same algorithm in assembly
+ * language for improved performance. It is unlikely that a port will use
+ * the data if it has a bitfield scan instruction.
+ */
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This routine sets @a _output to the bit number of the first bit
+ * set in @a _value. @a _value is of CPU dependent type
+ * @a Priority_bit_map_Control. This type may be either 16 or 32 bits
+ * wide although only the 16 least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * -# What happens when run on a value of zero?
+ * -# Bits may be numbered from MSB to LSB or vice-versa.
+ * -# The numbering may be zero or one based.
+ * -# The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
+ * @ref _CPU_Priority_bits_index. These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by @ref _CPU_Priority_Mask.
+ * The basic major and minor values calculated by @ref _Priority_Major
+ * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for @ref _Priority_Get_highest to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+@verbatim
+ - a series of 16 bit test instructions
+ - a "binary search using if's"
+ - _number = 0
+ if _value > 0x00ff
+ _value >>=8
+ _number = 8;
+
+ if _value > 0x0000f
+ _value >=8
+ _number += 4
+
+ _number += bit_set_table[ _value ]
+@endverbatim
+
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * @param _value (in) is the value to be scanned
+ * @param _output (in) is the first bit set
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+#endif
+
+/* end of Bitfield handler macros */
+
+/**
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by @ref _CPU_Bitfield_Find_first_bit. See the discussion
+ * for that routine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/**
+ * @ingroup CPUBitfield
+ * This routine translates the bit numbers returned by
+ * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * @param _priority (in) is the major or minor number to translate
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/**
+ * This routine performs CPU dependent initialization.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * @param vector (in) is the vector number
+ * @param new_handler (in) is the raw ISR handler to install
+ * @param old_handler (in) is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs an interrupt vector.
+ *
+ * @param vector (in) is the vector number
+ * @param new_handler (in) is the RTEMS ISR handler to install
+ * @param old_handler (in) is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * @note It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Install_interrupt_stack( void );
+
+/**
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * @note It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/**
+ * @ingroup CPUContext
+ * This routine switches from the run context to the heir context.
+ *
+ * @param run (in) points to the context of the currently executing task
+ * @param heir (in) points to the context of the heir task
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in @ref _CPU_Context_switch.
+ *
+ * @param new_context (in) points to the context to be restored.
+ *
+ * @note May be unnecessary to reload some registers.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/**
+ * @ingroup CPUContext
+ * This routine saves the floating point context passed to it.
+ *
+ * @param fp_context_ptr (in) is a pointer to a pointer to a floating
+ * point context area
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_restore_fp to restore this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine restores the floating point context passed to it.
+ *
+ * @param fp_context_ptr (in) is a pointer to a pointer to a floating
+ * point context area to restore
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_save_fp to save this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUEndian
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to insure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * @param value (in) is the value to be swapped
+ * @return the value after being endian swapped
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+/**
+ * @ingroup CPUEndian
+ * This routine swaps a 16 bir quantity.
+ *
+ * @param value (in) is the value to be swapped
+ * @return the value after being endian swapped
+ */
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/nios2/rtems/score/cpu_asm.h b/cpukit/score/cpu/nios2/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..7d6a8fe809
--- /dev/null
+++ b/cpukit/score/cpu/nios2/rtems/score/cpu_asm.h
@@ -0,0 +1,74 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Very loose template for an include file for the cpu_asm.? file
+ * if it is implemented as a ".S" file (preprocessed by cpp) instead
+ * of a ".s" file (preprocessed by gm4 or gasp).
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+/* pull in the generated offsets */
+
+/*
+#include <rtems/score/offsets.h>
+*/
+
+/*
+ * Hardware General Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Control Registers
+ */
+
+/* put something here */
+
+/*
+ * Calling Convention
+ */
+
+/* put something here */
+
+/*
+ * Temporary registers
+ */
+
+/* put something here */
+
+/*
+ * Floating Point Registers - SW Conventions
+ */
+
+/* put something here */
+
+/*
+ * Temporary floating point registers
+ */
+
+/* put something here */
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/nios2/rtems/score/nios2.h b/cpukit/score/cpu/nios2/rtems/score/nios2.h
new file mode 100644
index 0000000000..f35eebbe8e
--- /dev/null
+++ b/cpukit/score/cpu/nios2/rtems/score/nios2.h
@@ -0,0 +1,62 @@
+/* nios2.h
+ *
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specific to the NIOS2 port.
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_NIOS2_H
+#define _RTEMS_SCORE_NIOS2_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the NIOS2 family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+/*
+ * Define the name of the CPU family and specific model.
+ */
+
+#define CPU_NAME "NIOS2"
+#define CPU_MODEL_NAME "nios2"
+
+/*
+ * See also nios2-rtems-gcc -print-multi-lib for all valid combinations of
+ *
+ * -mno-hw-mul
+ * -mhw-mulx
+ * -mstack-check
+ * -pg
+ * -EB
+ * -mcustom-fpu-cfg=60-1
+ * -mcustom-fpu-cfg=60-2
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_NIOS2_H */
diff --git a/cpukit/score/cpu/nios2/rtems/score/types.h b/cpukit/score/cpu/nios2/rtems/score/types.h
new file mode 100644
index 0000000000..7420bd8c18
--- /dev/null
+++ b/cpukit/score/cpu/nios2/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the
+ * Altera Nios II processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void nios2_isr;
+typedef void ( *nios2_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/no_cpu/.cvsignore b/cpukit/score/cpu/no_cpu/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/no_cpu/ChangeLog b/cpukit/score/cpu/no_cpu/ChangeLog
new file mode 100644
index 0000000000..f6c9e4bdd0
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/ChangeLog
@@ -0,0 +1,420 @@
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-30 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1599/cpukit
+ * cpu_asm.c: Rename _Context_Switch_necessary to
+ _Thread_Dispatch_necessary to more properly reflect the intent.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.c, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.c: Add include of config.h
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-10-02 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu_asm.c, rtems/score/cpu.h, rtems/score/types.h: Corrections and
+ updates.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2008-01-29 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Remove most doxygen warnings.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-11 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Style.
+
+2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Fix Doxygen.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/asm.h, rtems/score/cpu.h, rtems/score/types.h: Part of a large
+ patch to improve Doxygen output. As a side-effect, grammar and
+ spelling errors were corrected, spacing errors were address, and some
+ variable names were improved.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/cpu_asm.h,
+ rtems/score/no_cpu.h, rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/cpu_asm.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: i960 obsoleted and all references removed.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into$(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h: Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-26 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Obsoleting HP PA-RISC port and removing all
+ references.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, cpu_asm.c, rtems/score/cpu.h, rtems/score/cpu_asm.h,
+ rtems/score/no_cpu.h, rtems/score/types.h: URL for license changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2003-02-11 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu_asm.c: Rework logic that decides when to call
+ _Thread_Dispatch. Analysis by Sergei Organov <osv@javad.ru>
+ determined that _ISR_Signals_to_thread_executing was not being
+ honored and/or cleared properly.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.c: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/no_cputypes.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-01-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ * Makefile.am: Reflect changes above.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-25 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/no_cpu.h: Modified so there are fewer and
+ more consistent variations on "no cpu" so it is easier
+ to sed the source as the starting point for a new port.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/no_cpu/Makefile.am b/cpukit/score/cpu/no_cpu/Makefile.am
new file mode 100644
index 0000000000..1c74eb72f4
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/Makefile.am
@@ -0,0 +1,19 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/no_cpu.h \
+ rtems/score/cpu_asm.h rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.c
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/no_cpu/cpu.c b/cpukit/score/cpu/no_cpu/cpu.c
new file mode 100644
index 0000000000..86d8852ff3
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/cpu.c
@@ -0,0 +1,168 @@
+/*
+ * XXX CPU Dependent Source
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/wkspace.h>
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Initialize(void)
+{
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ /*
+ * This routine returns the current interrupt level.
+ */
+
+ return 0;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, new_handler, old_handler );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Install_interrupt_stack
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Install_interrupt_stack( void )
+{
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+
+ for( ; ; )
+ /* insert your "halt" instruction here */ ;
+}
diff --git a/cpukit/score/cpu/no_cpu/cpu_asm.c b/cpukit/score/cpu/no_cpu/cpu_asm.c
new file mode 100644
index 0000000000..32c3f1f8c7
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/cpu_asm.c
@@ -0,0 +1,184 @@
+/* cpu_asm.c ===> cpu_asm.S or cpu_asm.s
+ *
+ * This file contains the basic algorithms for all assembly code used
+ * in an specific CPU port of RTEMS. These algorithms must be implemented
+ * in assembly language
+ *
+ * NOTE: This is supposed to be a .S or .s file NOT a C file.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * This is supposed to be an assembly file. This means that system.h
+ * and cpu.h should not be included in a "real" cpu_asm file. An
+ * implementation in assembly should include "cpu_asm.h>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+/* #include "cpu_asm.h> */
+
+/*
+ * _CPU_Context_save_fp_context
+ *
+ * This routine is responsible for saving the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+)
+{
+}
+
+/*
+ * _CPU_Context_restore_fp_context
+ *
+ * This routine is responsible for restoring the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+)
+{
+}
+
+/* _CPU_Context_switch
+ *
+ * This routine performs a normal non-FP context switch.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+)
+{
+}
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+)
+{
+}
+
+/* void __ISR_Handler()
+ *
+ * This routine provides the RTEMS interrupt management.
+ *
+ * NO_CPU Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+void _ISR_Handler(void)
+{
+ /*
+ * This discussion ignores a lot of the ugly details in a real
+ * implementation such as saving enough registers/state to be
+ * able to do something real. Keep in mind that the goal is
+ * to invoke a user's ISR handler which is written in C and
+ * uses a certain set of registers.
+ *
+ * Also note that the exact order is to a large extent flexible.
+ * Hardware will dictate a sequence for a certain subset of
+ * _ISR_Handler while requirements for setting
+ */
+
+ /*
+ * At entry to "common" _ISR_Handler, the vector number must be
+ * available. On some CPUs the hardware puts either the vector
+ * number or the offset into the vector table for this ISR in a
+ * known place. If the hardware does not give us this information,
+ * then the assembly portion of RTEMS for this port will contain
+ * a set of distinct interrupt entry points which somehow place
+ * the vector number in a known place (which is safe if another
+ * interrupt nests this one) and branches to _ISR_Handler.
+ *
+ * save some or all context on stack
+ * may need to save some special interrupt information for exit
+ *
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if ( _ISR_Nest_level == 0 )
+ * switch to software interrupt stack
+ * #endif
+ *
+ * _ISR_Nest_level++;
+ *
+ * _Thread_Dispatch_disable_level++;
+ *
+ * (*_ISR_Vector_table[ vector ])( vector );
+ *
+ * _Thread_Dispatch_disable_level--;
+ *
+ * --_ISR_Nest_level;
+ *
+ * if ( _ISR_Nest_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_disable_level )
+ * goto the label "exit interrupt (simple case)"
+ *
+ * if ( _Thread_Dispatch_necessary ) {
+ * call _Thread_Dispatch() or prepare to return to _ISR_Dispatch
+ * prepare to get out of interrupt
+ * return from interrupt (maybe to _ISR_Dispatch)
+ *
+ * LABEL "exit interrupt (simple case):
+ * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
+ * if outermost interrupt
+ * restore stack
+ * #endif
+ * prepare to get out of interrupt
+ * return from interrupt
+ */
+}
diff --git a/cpukit/score/cpu/no_cpu/preinstall.am b/cpukit/score/cpu/no_cpu/preinstall.am
new file mode 100644
index 0000000000..a56caeafd8
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/preinstall.am
@@ -0,0 +1,45 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/no_cpu.h: rtems/score/no_cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/no_cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/no_cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu_asm.h: rtems/score/cpu_asm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu_asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/no_cpu/rtems/asm.h b/cpukit/score/cpu/no_cpu/rtems/asm.h
new file mode 100644
index 0000000000..7dd89312b7
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/rtems/asm.h
@@ -0,0 +1,125 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1994-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/no_cpu.h>
+
+#ifndef __USER_LABEL_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all C program symbols.
+ */
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+/**
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ *
+ * This symbol is prefixed to all register names.
+ */
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/** Use the right prefix for global labels. */
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/** Use the right prefix for registers. */
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+/** This macro is used to denote the beginning of a code declaration. */
+#define BEGIN_CODE_DCL .text
+/** This macro is used to denote the end of a code declaration. */
+#define END_CODE_DCL
+/** This macro is used to denote the beginning of a data declaration section. */
+#define BEGIN_DATA_DCL .data
+/** This macro is used to denote the end of a data declaration section. */
+#define END_DATA_DCL
+/** This macro is used to denote the beginning of a code section. */
+#define BEGIN_CODE .text
+/** This macro is used to denote the end of a code section. */
+#define END_CODE
+/** This macro is used to denote the beginning of a data section. */
+#define BEGIN_DATA
+/** This macro is used to denote the end of a data section. */
+#define END_DATA
+/** This macro is used to denote the beginning of the
+ * unitialized data section.
+ */
+#define BEGIN_BSS
+/** This macro is used to denote the end of the unitialized data section. */
+#define END_BSS
+/** This macro is used to denote the end of the assembly file. */
+#define END
+
+/**
+ * This macro is used to declare a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define PUBLIC(sym) .globl SYM (sym)
+
+/**
+ * This macro is used to prototype a public global symbol.
+ *
+ * @note This must be tailored for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
new file mode 100644
index 0000000000..82b7ce629e
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
@@ -0,0 +1,1246 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the XXX
+ * processor.
+ *
+ * @note This file is part of a porting template that is intended
+ * to be used as the starting point when porting RTEMS to a new
+ * CPU family. The following needs to be done when using this as
+ * the starting point for a new port:
+ *
+ * + Anywhere there is an XXX, it should be replaced
+ * with information about the CPU family being ported to.
+ *
+ * + At the end of each comment section, there is a heading which
+ * says "Port Specific Information:". When porting to RTEMS,
+ * add CPU family specific information in this section
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/no_cpu.h>
+
+/* conditional compilation parameters */
+
+/**
+ * Should the calls to @ref _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * This conditional is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ *
+ * @note In general, the @ref _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls @ref _Thread_Enable_dispatch which in turns calls
+ * @ref _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/**
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/**
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
+
+/**
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/**
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
+
+/**
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/**
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/**
+ * @def CPU_HARDWARE_FP
+ *
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+/**
+ * @def CPU_SOFTWARE_FP
+ *
+ * Does the CPU have no hardware floating point and GCC provides a
+ * software floating point implementation which must be context
+ * switched?
+ *
+ * This feature conditional is used to indicate whether or not there
+ * is software implemented floating point that must be context
+ * switched. The determination of whether or not this applies
+ * is very tool specific and the state saved/restored is also
+ * compiler specific.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if ( NO_CPU_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+/**
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * So far, the only CPUs in which this option has been used are the
+ * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and
+ * gcc both implicitly used the floating point registers to perform
+ * integer multiplies. Similarly, the PowerPC port of gcc has been
+ * seen to allocate floating point local variables and touch the FPU
+ * even when the flow through a subroutine (like vfprintf()) might
+ * not use floating point formats.
+ *
+ * If a function which you would not think utilize the FP unit DOES,
+ * then one can not easily predict which tasks will use the FP hardware.
+ * In this case, this option should be TRUE.
+ *
+ * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALL_TASKS_ARE_FP TRUE
+
+/**
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/**
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/**
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine @ref _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * @ref _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * -# BSP provided
+ * -# CPU dependent (if provided)
+ * -# generic (if no BSP and no CPU dependent)
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/**
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_GROWS_UP TRUE
+
+/**
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * @note Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STRUCTURE_ALIGNMENT
+
+/**
+ * @defgroup CPUEndian Processor Dependent Endianness Support
+ *
+ * This group assists in issues related to processor endianness.
+ */
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_LITTLE_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_BIG_ENDIAN TRUE
+
+/**
+ * @ingroup CPUEndian
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
+ * same values.
+ *
+ * @see CPU_BIG_ENDIAN
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_LITTLE_ENDIAN FALSE
+
+/**
+ * @ingroup CPUInterrupt
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001
+
+/*
+ * Processor defined structures required for cpukit/score.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* may need to put some structures here. */
+
+/**
+ * @defgroup CPUContext Processor Dependent Context Management
+ *
+ * From the highest level viewpoint, there are 2 types of context to save.
+ *
+ * -# Interrupt registers to save
+ * -# Task level registers to save
+ *
+ * Since RTEMS handles integer and floating point contexts separately, this
+ * means we have the following 3 context items:
+ *
+ * -# task level context stuff:: Context_Control
+ * -# floating point task stuff:: Context_Control_fp
+ * -# special interrupt level context :: CPU_Interrupt_frame
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the minimal set of integer and processor state registers
+ * that must be saved during a voluntary context switch from one thread
+ * to another.
+ */
+typedef struct {
+ /** This field is a hint that a port will have a number of integer
+ * registers that need to be saved at a context switch.
+ */
+ uint32_t some_integer_register;
+ /** This field is a hint that a port will have a number of system
+ * registers that need to be saved at a context switch.
+ */
+ uint32_t some_system_register;
+
+ /** This field is a hint that a port will have a register that
+ * is the stack pointer.
+ */
+ uint32_t stack_pointer;
+} Context_Control;
+
+/**
+ * @ingroup CPUContext Management
+ *
+ * This macro returns the stack pointer associated with @a _context.
+ *
+ * @param[in] _context is the thread context area to access
+ *
+ * @return This method returns the stack pointer.
+ */
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->stack_pointer
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the complete set of floating point registers that must
+ * be saved during any context switch from one thread to another.
+ */
+typedef struct {
+ /** FPU registers are listed here */
+ double some_float_register;
+} Context_Control_fp;
+
+/**
+ * @ingroup CPUContext Management
+ * This defines the set of integer and processor state registers that must
+ * be saved during an interrupt. This set does not include any which are
+ * in @ref Context_Control.
+ */
+typedef struct {
+ /** This field is a hint that a port will have a number of integer
+ * registers that need to be saved when an interrupt occurs or
+ * when a context switch occurs at the end of an ISR.
+ */
+ uint32_t special_interrupt_register;
+} CPU_Interrupt_frame;
+
+/**
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * @ref _CPU_Initialize and copied into the task's FP context area during
+ * @ref _CPU_Context_Initialize.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+
+/**
+ * @defgroup CPUInterrupt Processor Dependent Interrupt Management
+ *
+ * On some CPUs, RTEMS supports a software managed interrupt stack.
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in @ref _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use.
+ *
+ * @note These two variables are required if the macro
+ * @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+/* XXX: if needed, put more variables here */
+
+/**
+ * @ingroup CPUContext
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/**
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the number of entries in the @ref _ISR_Vector_table managed
+ * by RTEMS.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
+
+/**
+ * @ingroup CPUInterrupt
+ * This defines the highest interrupt vector number for this port.
+ */
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/**
+ * @ingroup CPUInterrupt
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable @a _ISR_Nest_level.
+ */
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/**
+ * @ingroup CPUContext
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_MINIMUM_SIZE (1024*4)
+
+/**
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_ALIGNMENT 8
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by @ref CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for
+ * the heap, then this should be set to @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2 although it should be
+ * a multiple of 2 greater than or equal to 2. The requirement
+ * to be a multiple of 2 is because the heap uses the least
+ * significant field of the front and back flags to indicate
+ * that a block is in use or free. So you do not want any odd
+ * length blocks really putting length data in that bit.
+ *
+ * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
+ * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
+ * elements allocated from the heap meet all restrictions.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * @ref CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is
+ * strict enough for the partition, then this should be set to
+ * @ref CPU_ALIGNMENT.
+ *
+ * @note This does not have to be a power of 2. It does have to
+ * be greater or equal to than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/**
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by @ref CPU_ALIGNMENT. If the
+ * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
+ * set to 0.
+ *
+ * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_STACK_ALIGNMENT 0
+
+/*
+ * ISR handler macros
+ */
+
+/**
+ * @ingroup CPUInterrupt
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Initialize_vectors()
+
+/**
+ * @ingroup CPUInterrupt
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in @a _isr_cookie.
+ *
+ * @param[out] _isr_cookie will contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ { \
+ (_isr_cookie) = 0; /* do something to prevent warnings */ \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * @a _isr_cookie is not modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ { \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * This temporarily restores the interrupt to @a _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter @a _isr_cookie is not
+ * modified.
+ *
+ * @param[in] _isr_cookie contain the previous level cookie
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ { \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ *
+ * This routine and @ref _CPU_ISR_Get_level
+ * Map the interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_ISR_Set_level( new_level ) \
+ { \
+ }
+
+/**
+ * @ingroup CPUInterrupt
+ * Return the current interrupt disable level for this task in
+ * the format used by the interrupt level portion of the task mode.
+ *
+ * @note This routine usually must be implemented as a subroutine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/**
+ * @ingroup CPUContext
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * @param[in] _the_context is the context structure to be initialized
+ * @param[in] _stack_base is the lowest physical address of this task's stack
+ * @param[in] _size is the size of this task's stack
+ * @param[in] _isr is the interrupt disable level
+ * @param[in] _entry_point is the thread's entry point. This is
+ * always @a _Thread_Handler
+ * @param[in] _is_fp is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
+ _isr, _entry_point, _is_fp ) \
+ { \
+ }
+
+/**
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. For many ports, simply adding a label to the restore path
+ * of @ref _CPU_Context_switch will work. On other ports, it may be
+ * possibly to load a few arguments and jump to the restore path. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/**
+ * @ingroup CPUContext
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ *
+ * @param[in] _base is the lowest physical address of the floating point
+ * context area
+ * @param[in] _offset is the offset into the floating point area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/**
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * @a _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other floating point context save/restore models include:
+ * -# not doing anything, and
+ * -# putting a "null FP status word" in the correct place in the FP context.
+ *
+ * @param[in] _destination is the floating point context area
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ }
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/**
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define _CPU_Fatal_halt( _error ) \
+ { \
+ }
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/**
+ * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
+ *
+ * This set of routines are used to implement fast searches for
+ * the most important ready task.
+ */
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the generic bitfield
+ * manipulation implementation.
+ */
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This definition is set to TRUE if the port uses the data tables provided
+ * by the generic bitfield manipulation implementation.
+ * This can occur when actually using the generic bitfield manipulation
+ * implementation or when implementing the same algorithm in assembly
+ * language for improved performance. It is unlikely that a port will use
+ * the data if it has a bitfield scan instruction.
+ */
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+/**
+ * @ingroup CPUBitfield
+ * This routine sets @a _output to the bit number of the first bit
+ * set in @a _value. @a _value is of CPU dependent type
+ * @a Priority_bit_map_Control. This type may be either 16 or 32 bits
+ * wide although only the 16 least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * -# What happens when run on a value of zero?
+ * -# Bits may be numbered from MSB to LSB or vice-versa.
+ * -# The numbering may be zero or one based.
+ * -# The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
+ * @ref _CPU_Priority_bits_index. These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by @ref _CPU_Priority_Mask.
+ * The basic major and minor values calculated by @ref _Priority_Major
+ * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for @ref _Priority_Get_highest to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+@verbatim
+ - a series of 16 bit test instructions
+ - a "binary search using if's"
+ - _number = 0
+ if _value > 0x00ff
+ _value >>=8
+ _number = 8;
+
+ if _value > 0x0000f
+ _value >=8
+ _number += 4
+
+ _number += bit_set_table[ _value ]
+@endverbatim
+
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ *
+ * @param[in] _value is the value to be scanned
+ * @param[in] _output is the first bit set
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ (_output) = 0; /* do something to prevent warnings */ \
+ }
+#endif
+
+/* end of Bitfield handler macros */
+
+/**
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by @ref _CPU_Bitfield_Find_first_bit. See the discussion
+ * for that routine.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/**
+ * @ingroup CPUBitfield
+ * This routine translates the bit numbers returned by
+ * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ *
+ * @param[in] _priority is the major or minor number to translate
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/**
+ * This routine performs CPU dependent initialization.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Initialize(void);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the raw ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs an interrupt vector.
+ *
+ * @param[in] vector is the vector number
+ * @param[in] new_handler is the RTEMS ISR handler to install
+ * @param[in] old_handler is the previously installed ISR Handler
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/**
+ * @ingroup CPUInterrupt
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * @note It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Install_interrupt_stack( void );
+
+/**
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * @note It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/**
+ * @ingroup CPUContext
+ * This routine switches from the run context to the heir context.
+ *
+ * @param[in] run points to the context of the currently executing task
+ * @param[in] heir points to the context of the heir task
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in @ref _CPU_Context_switch.
+ *
+ * @param[in] new_context points to the context to be restored.
+ *
+ * @note May be unnecessary to reload some registers.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/**
+ * @ingroup CPUContext
+ * This routine saves the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_restore_fp to restore this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUContext
+ * This routine restores the floating point context passed to it.
+ *
+ * @param[in] fp_context_ptr is a pointer to a pointer to a floating
+ * point context area to restore
+ *
+ * @return on output @a *fp_context_ptr will contain the address that
+ * should be used with @ref _CPU_Context_save_fp to save this context.
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/**
+ * @ingroup CPUEndian
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ *
+ * Port Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return swapped;
+}
+
+/**
+ * @ingroup CPUEndian
+ * This routine swaps a 16 bir quantity.
+ *
+ * @param[in] value is the value to be swapped
+ * @return the value after being endian swapped
+ */
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpu_asm.h b/cpukit/score/cpu/no_cpu/rtems/score/cpu_asm.h
new file mode 100644
index 0000000000..a509b36ae6
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpu_asm.h
@@ -0,0 +1,72 @@
+/**
+ * @file rtems/score/cpu_asm.h
+ */
+
+/*
+ * Very loose template for an include file for the cpu_asm.? file
+ * if it is implemented as a ".S" file (preprocessed by cpp) instead
+ * of a ".s" file (preprocessed by gm4 or gasp).
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_CPU_ASM_H
+#define _RTEMS_SCORE_CPU_ASM_H
+
+/* pull in the generated offsets */
+
+#include <rtems/score/offsets.h>
+
+/*
+ * Hardware General Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Floating Point Registers
+ */
+
+/* put something here */
+
+/*
+ * Hardware Control Registers
+ */
+
+/* put something here */
+
+/*
+ * Calling Convention
+ */
+
+/* put something here */
+
+/*
+ * Temporary registers
+ */
+
+/* put something here */
+
+/*
+ * Floating Point Registers - SW Conventions
+ */
+
+/* put something here */
+
+/*
+ * Temporary floating point registers
+ */
+
+/* put something here */
+
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/no_cpu/rtems/score/no_cpu.h b/cpukit/score/cpu/no_cpu/rtems/score/no_cpu.h
new file mode 100644
index 0000000000..ecb389dc2e
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/rtems/score/no_cpu.h
@@ -0,0 +1,69 @@
+/* no_cpu.h
+ *
+ * This file sets up basic CPU dependency settings based on
+ * compiler settings. For example, it can determine if
+ * floating point is available. This particular implementation
+ * is specified to the NO CPU port.
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _RTEMS_SCORE_NO_CPU_H
+#define _RTEMS_SCORE_NO_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the NO CPU family.
+ * It does this by setting variables to indicate which
+ * implementation dependent features are present in a particular
+ * member of the family.
+ *
+ * This is a good place to list all the known CPU models
+ * that this port supports and which RTEMS CPU model they correspond
+ * to.
+ */
+
+#if defined(rtems_multilib)
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+
+#define CPU_MODEL_NAME "rtems_multilib"
+#define NOCPU_HAS_FPU 1
+
+#elif defined(no_cpu)
+
+#define CPU_MODEL_NAME "no_cpu_model"
+#define NOCPU_HAS_FPU 1
+
+#else
+
+#error "Unsupported CPU Model"
+
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "NO CPU"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_NO_CPU_H */
diff --git a/cpukit/score/cpu/no_cpu/rtems/score/types.h b/cpukit/score/cpu/no_cpu/rtems/score/types.h
new file mode 100644
index 0000000000..c1fdc6d9a4
--- /dev/null
+++ b/cpukit/score/cpu/no_cpu/rtems/score/types.h
@@ -0,0 +1,49 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the Intel
+ * no_cpu processor family.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+/** This defines the type for a priority bit map entry. */
+typedef uint16_t Priority_bit_map_Control;
+
+/** This defines the return type for an ISR entry point. */
+typedef void no_cpu_isr;
+
+/** This defines the prototype for an ISR entry point. */
+typedef no_cpu_isr ( *no_cpu_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/powerpc/.cvsignore b/cpukit/score/cpu/powerpc/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/powerpc/ChangeLog b/cpukit/score/cpu/powerpc/ChangeLog
new file mode 100644
index 0000000000..1d9117764e
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/ChangeLog
@@ -0,0 +1,945 @@
+2011-02-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added FSL_EIS_ATBL, FSL_EIS_ATBL, and
+ FSL_EIS_SPEFSCR defines.
+
+2011-02-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added MSR_UCLE, MSR_SPE, MSR_WE, and
+ MSR_UBLE defines.
+
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/powerpc/registers.h, rtems/score/cpu.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2011-01-31 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Changed Freescale EIS prefix. More
+ Freescale EIS defines. Added MSR_IS, MSR_DS, and MSR_PMM defines.
+
+2011-01-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added BOOKE_PIR define.
+
+2010-10-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added HID2 define. Fixed comments.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/new-exceptions/cpu.h: Removed file.
+ * Makefile.am, preinstall.am: Reflect change above.
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first. Added
+ contents of <rtems/new-exceptions/cpu.h>.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-30 Peter Dufault <dufault@hda.com>
+
+ PR 1588/cpukit
+ * rtems/powerpc/registers.h: Renamed defines SR0 .. SR15 in
+ PPC_SR0 .. PPC_SR15.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * rtems/new-exceptions/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Add include of config.h
+
+2009-12-01 Till Straumann <strauman@slac.stanford.edu>
+
+ * score/cpu/powerpc/rtems/score/cpu.h: Added space for non-
+ volatile AltiVec registers to context struct. Added declaration
+ for AltiVec-related routines to be implemented by CPU/BSP
+ support.
+
+2009-10-21 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>
+
+ * score/cpu/powerpc/rtems/score/cpu.h: moved timebase/decrementer
+ access from cpukit to libcpu
+
+2009-10-21 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added defines DEAR_BOOKE and DEAR_405.
+ * rtems/score/cpu.h: Changed fpscr field to an integer type in
+ Context_Control_fp. Fixed warnings in PPC_Set_timebase_register().
+ Changed _CPU_Context_Initialize_fp() to initialize all fields and
+ avoid floating-point instructions.
+ * rtems/score/powerpc.h: Removed PPC_INIT_FPSCR define.
+
+2009-02-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added Freescale Book E Implementation
+ Standards (EIS) special purpose register definitions for MMU and L1
+ cache.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/score/cpu.h: Eliminate
+ _CPU_Thread_dispatch_pointer and passing address of _Thread_Dispatch
+ to _CPU_Initialize. Clean up comments.
+
+2008-09-14 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Move extern of bsp_clicks_per_usec so it is not
+ nested inside braces.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h, rtems/score/cpu.h: Convert to "bool".
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-14 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Removed obsolete defines MSR_, MSR_KERNEL
+ and MSR_USER. Added missing prototypes.
+
+2008-08-04 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/new-exceptions/cpu.h: Changed define
+ CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER to UINT32_MAX to avoid comparison
+ between signed and unsigned.
+
+2008-07-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/powerpc/registers.h: Added masks for BOOKE_TCR fields.
+
+2008-07-14 Thomas Doerfler <thomas.doerfler@embedded-brains.de>
+ * rtems/powerpc/registers.h:
+
+ Added PPC405EX support contributed by Michael Hamel
+
+2008-07-10 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/asm.h: Added defines for save and restore registers and
+ special purpose registers 4 to 7.
+
+ * rtems/new-exceptions/cpu.h: Changed define PPC_BSP_HAS_FIXED_PR288 to
+ a value that results in a compile time error on usage since SPRG0 is
+ now used for the interrupt disable mask.
+
+ * rtems/powerpc/registers.h: Bugfix: Swapped values of TBWU and TBWL.
+
+ Added defines SPRG4..7 and USPRG0.
+
+ Changed _CPU_ISR_{Disable, Enable, Flush} to use static inline
+ functions. The interrupt disable mask is now stored in SPRG0. Which
+ was previously denoted to indicate a PR288 bugfix. You may now
+ initialize the interrupt disable mask via
+ ppc_interrupt_set_disable_mask() and
+ PPC_INTERRUPT_DISABLE_MASK_DEFAULT. The default value will be set in
+ bootcard.c.
+
+2008-02-20 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h: Remove (Abandoned).
+ * rtems/score/cpu.h: Remove ref to rtems/old-exceptions/cpu.h.
+ * Makefile.am: Remove ref to rtems/old-exceptions/cpu.h.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/powerpc/registers.h, rtems/score/cpu.h: Sweep to make sure grep
+ for COPYRIGHT passes.
+
+2007-12-03 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/powerpc/registers.h: added definitions for MSR_CE,
+ MSR_DE (bookE).
+
+2007-12-06 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/old-exceptions/cpu.h: Remove extra ifndef.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h,
+ rtems/score/cpu.h: Move interrupt_stack_size field from CPU Table to
+ Configuration Table. Eliminate CPU Table from all ports. Delete
+ references to CPU Table in all forms.
+
+2007-12-03 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/score/cpu.h: Added comment that GDB patch sim/2376
+ is needed for reading the time-base with the new (more
+ portable) method.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h: Moved most of
+ the remaining CPU Table fields to the Configuration Table. This
+ included pretasking_hook, predriver_hook, postdriver_hook, idle_task,
+ do_zero_of_workspace, extra_mpci_receive_server_stack,
+ stack_allocate_hook, and stack_free_hook. As a side-effect of this
+ effort some multiprocessing code was made conditional and some style
+ clean up occurred.
+
+2007-11-30 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/score/cpu.h: Wonderful bookE doesn't have mftb/mftbu;
+ ( CPU_Get_timebase_low() ) they only define the TBRU/TBRL SPRs
+ so we use these. Should work on all CPUs.
+
+2007-11-28 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h,
+ rtems/score/cpu.h: Eliminate PowerPC specific elements from the CPU
+ Table. They have been replaced with variables named bsp_XXX as
+ needed.
+
+2007-11-13 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/score/powerpc.h: Added a '__ppc_generic' CPU variant.
+ The goal would be making cpukit and hopefully libcpu work
+ for all (or at least most) CPUs/BSPs with -D__ppc_generic so
+ that eventually all tests [#if defined(<cpu_flavor>)] for CPU
+ flavors can be eliminated.
+
+2007-11-13 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/powerpc/registers.h: Added SPR definitions for BookE
+ DECAR, TCR, TSR.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-12-12 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/ppc.h: Remove (Deprecated in 4.7).
+ * Makefile: Remove rtems/score/ppc.h.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-08-09 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Because gcc implicitly uses floating point turn on
+ floating point for all threads if there is a hardware FPU.
+
+2006-07-12 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/old-exceptions/cpu.h, rtems/powerpc/registers.h:
+ Checked inline assembly; added early-clobber '&' to output operands
+ of multi-instruction asms.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h,
+ rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-11-02 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/powerpc/registers.h: recognize mpc7457 CPU; added definitions
+ for high bats (#4..7) on 7450 CPUs
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-05-06 Jennifer Averett <jennifer.averett@oarcorp.com>
+
+ * rtems/score/powerpc.h: Removed warning
+
+2005-02-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Add "defined(mpc7400) || defined(mpc7450)
+ || defined(mpc7455)" to altivec (gcc-3.2.x compatibility).
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (CPU_HARDWARE_FP, CPU_ALL_TASKS_ARE_FP,
+ CPU_IDLE_TASK_IS_FP): Remove.
+ * rtems/old-exceptions/cpu.h (CPU_HARDWARE_FP, CPU_ALL_TASKS_ARE_FP,
+ CPU_IDLE_TASK_IS_FP): Remove.
+ * rtems/score/cpu.h (CPU_HARDWARE_FP, CPU_ALL_TASKS_ARE_FP,
+ CPU_IDLE_TASK_IS_FP, CPU_SOFTWARE_FP): New.
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Derive CPU_{BIG|LITTLE}_ENDIAN from
+ __BIG_ENDIAN__.
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h (CPU_PROVIDES_IDLE_THREAD_BODY,
+ CPU_STACK_GROWS_UP, CPU_STRUCTURE_ALIGNMENT,
+ CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES, CPU_BIG_ENDIAN,
+ CPU_LITTLE_ENDIAN): Add.
+ * rtems/old-exceptions/cpu.h (CPU_PROVIDES_IDLE_THREAD_BODY,
+ CPU_STACK_GROWS_UP, CPU_STRUCTURE_ALIGNMENT,
+ CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES, CPU_BIG_ENDIAN,
+ CPU_LITTLE_ENDIAN): Remove.
+ * rtems/new-exceptions/cpu.h (CPU_PROVIDES_IDLE_THREAD_BODY,
+ CPU_STACK_GROWS_UP, CPU_STRUCTURE_ALIGNMENT,
+ CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES, CPU_BIG_ENDIAN,
+ CPU_LITTLE_ENDIAN): Remove.
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ (rtems_cpu_configuration_get_serial_per_sec,
+ rtems_cpu_configuration_get_serial_external_clock,
+ rtems_cpu_configuration_get_serial_xon_xoff,
+ rtems_cpu_configuration_get_serial_cts_rts,
+ rtems_cpu_configuration_get_serial_rate,
+ rtems_cpu_configuration_get_timer_average_overhead,
+ rtems_cpu_configuration_get_timer_least_valid,
+ rtems_cpu_configuration_get_timer_internal_clock,
+ rtems_cpu_configuration_get_clock_speed): New.
+ * rtems/old-exceptions/cpu.h:
+ (rtems_cpu_configuration_get_serial_per_sec,
+ rtems_cpu_configuration_get_serial_external_clock,
+ rtems_cpu_configuration_get_serial_xon_xoff,
+ rtems_cpu_configuration_get_serial_cts_rts,
+ rtems_cpu_configuration_get_serial_rate,
+ rtems_cpu_configuration_get_timer_average_overhead,
+ rtems_cpu_configuration_get_timer_least_valid,
+ rtems_cpu_configuration_get_timer_internal_clock,
+ rtems_cpu_configuration_get_clock_speed): Remove.
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h
+ (rtems_cpu_table): Sync defines between {old|new}-exceptions.
+
+2005-02-18 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (Context_Control,
+ Context_Control_fp, CPU_Interrupt_frame): Remove.
+ * rtems/old-exceptions/cpu.h (Context_Control,
+ Context_Control_fp, CPU_Interrupt_frame): Remove.
+ * rtems/score/cpu.h (Context_Control,
+ Context_Control_fp, CPU_Interrupt_frame): Add.
+
+2005-02-16 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (CPU_STACK_MINIMUM_SIZE,
+ CPU_ALIGNMENT, CPU_HEAP_ALIGNMENT,
+ CPU_PARTITION_ALIGNMENT, CPU_STACK_ALIGNMENT): Remove.
+ * rtems/old-exceptions/cpu.h (CPU_STACK_MINIMUM_SIZE,
+ CPU_ALIGNMENT, CPU_HEAP_ALIGNMENT,
+ CPU_PARTITION_ALIGNMENT, CPU_STACK_ALIGNMENT): Remove.
+ * rtems/score/cpu.h (CPU_STACK_MINIMUM_SIZE,
+ CPU_ALIGNMENT, CPU_HEAP_ALIGNMENT,
+ CPU_PARTITION_ALIGNMENT, CPU_STACK_ALIGNMENT): Add.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h: Remove CPU_MINIMUM_STACK_FRAME_SIZE.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (_CPU_Bitfield_Find_first_bit,
+ _CPU_Priority_Mask, _CPU_Priority_bits_index): Remove.
+ * rtems/old-exceptions/cpu.h (_CPU_Bitfield_Find_first_bit,
+ _CPU_Priority_Mask, _CPU_Priority_bits_index): Remove.
+ * rtems/score/cpu.h (_CPU_Bitfield_Find_first_bit,
+ _CPU_Priority_Mask, _CPU_Priority_bits_index): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (_CPU_msrs): Remove (Unused).
+ * rtems/old-exceptions/cpu.h (_CPU_msrs): Remove (Unused).
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (_CPU_ISR_install_vector,
+ _CPU_Initialize, _CPU_Install_interrupt_stack, _CPU_Context_switch,
+ _CPU_Context_restore, _CPU_Context_save_fp, _CPU_Context_restore_fp,
+ _CPU_Fatal_error): Remove.
+ * rtems/old-exceptions/cpu.h (_CPU_ISR_install_vector,
+ _CPU_Initialize, _CPU_Install_interrupt_stack, _CPU_Context_switch,
+ _CPU_Context_restore, _CPU_Context_save_fp, _CPU_Context_restore_fp,
+ _CPU_Fatal_error): Remove.
+ * rtems/score/cpu.h (_CPU_ISR_install_vector,
+ _CPU_Initialize, _CPU_Install_interrupt_stack, _CPU_Context_switch,
+ _CPU_Context_restore, _CPU_Context_save_fp, _CPU_Context_restore_fp,
+ _CPU_Fatal_error): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h (_CPU_Context_Initialize,
+ _CPU_Context_Restart_self, _CPU_Context_Fp_start,
+ _CPU_Context_Initialize_fp): Remove.
+ * rtems/new-exceptions/cpu.h (_CPU_Context_Initialize,
+ _CPU_Context_Restart_self, _CPU_Context_Fp_start,
+ _CPU_Context_Initialize_fp): Remove.
+ * rtems/score/cpu.h (_CPU_Context_Initialize,
+ _CPU_Context_Restart_self, _CPU_Context_Fp_start,
+ _CPU_Context_Initialize_fp): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h (PPC_Get_timebase_register): Remove.
+ * rtems/powerpc/registers.h (PPC_Get_timebase_register,
+ PPC_Set_timebase_register): Remove.
+ * rtems/score/cpu.h (PPC_Get_timebase_register,
+ PPC_Set_timebase_register): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/powerpc/registers.h (PPC_Set_decrementer,
+ PPC_Get_decrementer): Remove.
+ * rtems/old-exceptions/cpu.h (PPC_Set_decrementer): Remove.
+ * rtems/score/cpu.h (PPC_Set_decrementer, PPC_Get_decrementer): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h (CPU_Get_timebase_low, rtems_bsp_delay,
+ rtems_bsp_delay_in_bus_cycles): Remove.
+ * rtems/powerpc/registers.h (CPU_Get_timebase_low, rtems_bsp_delay,
+ rtems_bsp_delay_in_bus_cycles): Remove.
+ * rtems/score/cpu.h (CPU_Get_timebase_low, rtems_bsp_delay,
+ rtems_bsp_delay_in_bus_cycles): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h
+ (rtems_cpu_configuration_get_clicks_per_usec,
+ rtems_cpu_configuration_get_exceptions_in_ram): Remove.
+ * rtems/old-exceptions/cpu.h
+ (rtems_cpu_configuration_get_clicks_per_usec,
+ rtems_cpu_configuration_get_exceptions_in_ram): Remove.
+ * rtems/score/cpu.h
+ (rtems_cpu_configuration_get_clicks_per_usec,
+ rtems_cpu_configuration_get_exceptions_in_ram): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h (CPU_swap_u32, CPU_swap_u16): Remove.
+ * rtems/old-exceptions/cpu.h (CPU_swap_u32, CPU_swap_u16): Remove.
+ * rtems/score/cpu.h (CPU_swap_u32, CPU_swap_u16): New.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h: Add _CPU_MSG_GET
+ (old/new exception processing ABI compatibility).
+ * rtems/powerpc/registers.h: Use C99 fixed size types.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Add __ALTIVEC__ support.
+
+2005-02-15 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Merge ppc603 and ppc603e
+ PPC_IRQ_*/PPC_TLB_* defines.
+
+2005-02-14 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h (mpc8260): PPC_ALIGNMENT 8.
+
+2005-02-14 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_HAS_RFCI (Unused).
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_HAS_EXCEPTION_PREFIX (Unused).
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_CACHE_ALIGN_POWER (Unused).
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_LOW_POWER_MODE* (Unused).
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_HAS_EVPR (Unused).
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_USE_MULTIPLE (Unused).
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_D_CACHE, PPC_I_CACHE defines.
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove PPC_MSR_* defines.
+
+2005-02-13 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h: Add _PPC_MSR_DISABLE_MASK.
+ Use _PPC_MSR_DISABLE_MASK instead of PPC_MSR_DISABLE_MASK to set up
+ _disable_mask.
+
+2005-02-12 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * cpu.c: New (Stub file for consistency with other ports).
+ * Makefile.am: Reflect changes above.
+
+2005-02-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h, rtems/old-exceptions/cpu.h, rtems/score/powerpc.h:
+ Remove PPC_ABI_POWEROPEN.
+
+2005-02-10 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: Remove hard-coded PPC_HAS_FPU.
+ Tie PPC_HAS_FPU to _SOFT_FLOAT.
+
+2005-02-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/old-exceptions/cpu.h, rtems/score/powerpc.h:
+ Remove PPC_ABI_GCC27.
+
+2005-02-09 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h, rtems/score/powerpc.h: Remove XCOFF support.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h,
+ rtems/powerpc/registers.h: New header guards.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/powerpc.h,
+ rtems/score/ppc.h, rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h: *_swap_u32( uint32_t ).
+ * rtems/old-exceptions/cpu.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2004-11-22 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/old-exceptions/cpu.h: Make compile in assembly.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/powerpc.h: Add doxygen preamble.
+ * rtems/score/ppc.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-10-20 Eric Norum <norume@aps.anl.gov>
+
+ Add Kate Feng's MVME5500 BSP
+ * rtems/powerpc/registers.h, rtems/score/powerpc.h
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h: i960
+ obsoleted and all references removed.
+
+2004-04-13 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * asm.h: Include rtems/score/powerpc.h instead of
+ rtems/score/ppc.h.
+
+2004-04-13 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/powerpc.h: New (Copied and renamed from rtems/score/ppc.h)
+ for consistency with other ports.
+ * rtems/score/ppc.h: Deprecation wrapper to rtems/score/powerpc.h.
+ * Makefile.am: Reflect changes above.
+ * rtems/score/cpu.h: Include rtems/score/powerpc.h instead of
+ rtems/score/ppc.h.
+
+2004-04-12 David Querbach <querbach@realtime.bc.ca>
+
+ * asm.h, rtems/new-exceptions/cpu.h, rtems/score/ppc.h: addition of
+ MPC555 support as part of the addition of the SS555 BSP.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into $(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h,
+ rtems/powerpc/registers.h: Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove all LIB-related rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-26 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h: Obsoleting HP
+ PA-RISC port and removing all references.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h, rtems/old-exceptions/cpu.h,
+ rtems/powerpc/registers.h, rtems/score/ppc.h, rtems/score/types.h:
+ URL for license changed.
+
+2003-08-21 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 457/bsps
+ * rtems/powerpc/registers.h: Add a few definitions for the PowerPC
+ thermal assistance unit.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-07-18 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 288/rtems
+ * rtems/new-exceptions/cpu.h: _ISR_Nest_level is now properly
+ maintained and does not reside in SPRG0.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2003-02-20 Till Straumann <strauman@slac.stanford.edu>
+
+ PR 349/bsps
+ * rtems/powerpc/registers.h: Add definitions for HID1 and DABR SPRs.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-11-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/new-exceptions/cpu.h: Remove sections on
+ CPU_INLINE_ENABLE_DISPATCH and CPU_UNROLL_ENQUEUE_PRIORITY.
+ * rtems/old-exceptions/cpu.h: Remove sections on
+ CPU_INLINE_ENABLE_DISPATCH and CPU_UNROLL_ENQUEUE_PRIORITY.
+ * rtems/score/cpu.h: Insert sections on
+ CPU_INLINE_ENABLE_DISPATCH and CPU_UNROLL_ENQUEUE_PRIORITY.
+
+2002-10-31 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h: Removed warnings.
+
+
+2002-10-31 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/new-exceptions/cpu.h: Removed warnings.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2002-05-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/ppc.h: Remove PPC_DEBUG_MODEL.
+
+2001-05-14 Till Straumann <strauman@slac.stanford.edu>
+
+ * rtems/powerpc/registers.h, rtems/score/ppc.h: Per PR213, add
+ support for the MPC74000 (AKA G4); there is no AltiVec support yet,
+ however.
+2002-04-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/ppc.h: Remove rtems_multilib.
+ Add mpc555 (Based on comments from Sergei Organov <osv@javad.ru>).
+ * rtems/old-exceptions/cpu.h: Remove _CPU_Data_Cache_Block_Flush.
+ Remove _CPU_Data_Cache_Block_Invalidate.
+
+2002-04-18 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * asm.h: Include cpuopts.h instead of targopts.h.
+ * rtems/new-exceptions/cpu.h: Relocated from
+ libbsp/powerpc/support/new_exception_processing/rtems/score/cpu.h
+ * rtems/old-exceptions/cpu.h: Relocated from
+ c/src/lib/libbsp/powerpc/support/old_exception_processing/rtems/score/cpu.h
+ * rtems/powerpc/registers.h: Relocated and renamed from
+ libcpu/powerpc/shared/include/cpu.h.
+ * rtems/score/cpu.h: New.
+ * Makefile.am: Reflect changes above.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/ppctypes.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-01-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Reflect changes from 2002-01-23.
+
+2002-01-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+ AC_CONFIG_SRCDIR(asm.h).
+
+2002-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: New.
+ * rtems/.cvsignore: New.
+ * rtems/score/Makefile.am: New.
+ * rtems/score/.cvsignore: New.
+ * rtems/score/ppc.h: Relocated from shared/.
+ * rtems/score/ppctypes.h: Relocated from shared/.
+ * asm.h: Relocated from shared/.
+ * shared/Makefile.am: Removed.
+ * shared/asm.h: Removed.
+ * shared/ppc.h: Removed.
+ * shared/ppctypes.h: Removed.
+ * shared/.cvsignore: Removed.
+ * Makefile.am: Reflect changes above.
+ * configure.ac: Reflect changes above.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-11-14 Joel Sherrill <joel@OARcorp.com>
+
+ * shared/ppc.h: The mpc8260 uses the new exception processing model
+ and thus does not need to define PPC_USE_SPRG.
+
+2001-11-14 Andrew Dachs <A.Dachs@SSTL.co.uk>
+
+ * shared/ppc.h: mpc8260 has double FPU not single FPU.
+
+2001-11-08 Dennis Ehlin (ECS) <Dennis.Ehlin@ecs.ericsson.se>
+
+ This modification is part of the submitted modifications necessary to
+ support the IBM PPC405 family. This submission was reviewed by
+ Thomas Doerfler <Thomas.Doerfler@imd-systems.de> who ensured it did
+ not negatively impact the ppc403 BSPs. The submission and tracking
+ process was captured as PR50.
+ * shared/asm.h, shared/ppc.h: Added PPC405 support.
+
+2001-10-22 Andy Dachs <a.dachs@sstl.co.uk>
+
+ * shared/ppc.h: Added mpc8260 support.
+
+2001-10-12 Joel Sherrill <joel@OARcorp.com>
+
+ * shared/ppctypes.h: Fixed typo.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * shared/Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-10-20 Joel Sherrill <joel@OARcorp.com>
+
+ * shared/ppc.h: For multilibs, derive PPC_HAS_FPU from _SOFT_FLOAT.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/powerpc/Makefile.am b/cpukit/score/cpu/powerpc/Makefile.am
new file mode 100644
index 0000000000..a8b7b61e5b
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/powerpc.h rtems/score/cpu.h \
+ rtems/score/types.h
+
+include_rtems_powerpcdir = $(includedir)/rtems/powerpc
+include_rtems_powerpc_HEADERS = rtems/powerpc/registers.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/powerpc/cpu.c b/cpukit/score/cpu/powerpc/cpu.c
new file mode 100644
index 0000000000..108a7ce45d
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/cpu.c
@@ -0,0 +1,17 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+/*
+ * For now, this file is just a stub to work around
+ * structural deficiencies of the powerpc port.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
diff --git a/cpukit/score/cpu/powerpc/preinstall.am b/cpukit/score/cpu/powerpc/preinstall.am
new file mode 100644
index 0000000000..99e3bd0aaf
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/preinstall.am
@@ -0,0 +1,50 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/powerpc.h: rtems/score/powerpc.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/powerpc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/powerpc.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
+$(PROJECT_INCLUDE)/rtems/powerpc/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/powerpc
+ @: > $(PROJECT_INCLUDE)/rtems/powerpc/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/powerpc/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/powerpc/registers.h: rtems/powerpc/registers.h $(PROJECT_INCLUDE)/rtems/powerpc/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/powerpc/registers.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/powerpc/registers.h
+
diff --git a/cpukit/score/cpu/powerpc/rtems/asm.h b/cpukit/score/cpu/powerpc/rtems/asm.h
new file mode 100644
index 0000000000..d54c0607e2
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/rtems/asm.h
@@ -0,0 +1,271 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ * COPYRIGHT (c) 1995.
+ * i-cubed ltd.
+ *
+ * COPYRIGHT (c) 1994.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/powerpc.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#ifndef __FLOAT_REGISTER_PREFIX__
+#define __FLOAT_REGISTER_PREFIX__ __REGISTER_PREFIX__
+#endif
+
+#ifndef __PROC_LABEL_PREFIX__
+#define __PROC_LABEL_PREFIX__ __USER_LABEL_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for procedure labels. */
+
+#define PROC(x) CONCAT1 (__PROC_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/* Use the right prefix for floating point registers. */
+
+#define FREG(x) CONCAT1 (__FLOAT_REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+#define r0 REG(0)
+#define r1 REG(1)
+#define r2 REG(2)
+#define r3 REG(3)
+#define r4 REG(4)
+#define r5 REG(5)
+#define r6 REG(6)
+#define r7 REG(7)
+#define r8 REG(8)
+#define r9 REG(9)
+#define r10 REG(10)
+#define r11 REG(11)
+#define r12 REG(12)
+#define r13 REG(13)
+#define r14 REG(14)
+#define r15 REG(15)
+#define r16 REG(16)
+#define r17 REG(17)
+#define r18 REG(18)
+#define r19 REG(19)
+#define r20 REG(20)
+#define r21 REG(21)
+#define r22 REG(22)
+#define r23 REG(23)
+#define r24 REG(24)
+#define r25 REG(25)
+#define r26 REG(26)
+#define r27 REG(27)
+#define r28 REG(28)
+#define r29 REG(29)
+#define r30 REG(30)
+#define r31 REG(31)
+#define f0 FREG(0)
+#define f1 FREG(1)
+#define f2 FREG(2)
+#define f3 FREG(3)
+#define f4 FREG(4)
+#define f5 FREG(5)
+#define f6 FREG(6)
+#define f7 FREG(7)
+#define f8 FREG(8)
+#define f9 FREG(9)
+#define f10 FREG(10)
+#define f11 FREG(11)
+#define f12 FREG(12)
+#define f13 FREG(13)
+#define f14 FREG(14)
+#define f15 FREG(15)
+#define f16 FREG(16)
+#define f17 FREG(17)
+#define f18 FREG(18)
+#define f19 FREG(19)
+#define f20 FREG(20)
+#define f21 FREG(21)
+#define f22 FREG(22)
+#define f23 FREG(23)
+#define f24 FREG(24)
+#define f25 FREG(25)
+#define f26 FREG(26)
+#define f27 FREG(27)
+#define f28 FREG(28)
+#define f29 FREG(29)
+#define f30 FREG(30)
+#define f31 FREG(31)
+
+/*
+ * Some special purpose registers (SPRs).
+ */
+#define srr0 0x01a
+#define srr1 0x01b
+#define srr2 0x3de /* IBM 400 series only */
+#define srr3 0x3df /* IBM 400 series only */
+#define csrr0 58 /* Book E */
+#define csrr1 59 /* Book E */
+#define mcsrr0 570 /* e500 */
+#define mcsrr1 571 /* e500 */
+#define dsrr0 574 /* e200 */
+#define dsrr1 575 /* e200 */
+
+#define sprg0 0x110
+#define sprg1 0x111
+#define sprg2 0x112
+#define sprg3 0x113
+#define sprg4 276
+#define sprg5 277
+#define sprg6 278
+#define sprg7 279
+
+#define usprg0 256
+
+#define dar 0x013 /* Data Address Register */
+#define dec 0x016 /* Decrementer Register */
+
+#if defined(ppc403) || defined(ppc405)
+/* the following SPR/DCR registers exist only in IBM 400 series */
+#define dear 0x3d5
+#define evpr 0x3d6 /* SPR: exception vector prefix register */
+#define iccr 0x3fb /* SPR: instruction cache control reg. */
+#define dccr 0x3fa /* SPR: data cache control reg. */
+
+#if defined (ppc403)
+#define exisr 0x040 /* DCR: external interrupt status register */
+#define exier 0x042 /* DCR: external interrupt enable register */
+#endif /* ppc403 */
+#if defined(ppc405)
+#define exisr 0x0C0 /* DCR: external interrupt status register */
+#define exier 0x0C2 /* DCR: external interrupt enable register */
+#endif /* ppc405 */
+
+#define br0 0x080 /* DCR: memory bank register 0 */
+#define br1 0x081 /* DCR: memory bank register 1 */
+#define br2 0x082 /* DCR: memory bank register 2 */
+#define br3 0x083 /* DCR: memory bank register 3 */
+#define br4 0x084 /* DCR: memory bank register 4 */
+#define br5 0x085 /* DCR: memory bank register 5 */
+#define br6 0x086 /* DCR: memory bank register 6 */
+#define br7 0x087 /* DCR: memory bank register 7 */
+/* end of IBM400 series register definitions */
+
+#elif defined(mpc555)
+/* The following registers are for the MPC5xx */
+#define eie 0x050 /* External Interrupt Enable Register */
+#define eid 0x051 /* External Interrupt Disable Register */
+#define nri 0x052 /* Non-Recoverable Interrupt Register */
+
+#elif defined(mpc860) || defined(mpc821)
+/* The following registers are for the MPC8x0 */
+#define der 0x095 /* Debug Enable Register */
+#define ictrl 0x09E /* Instruction Support Control Register */
+#define immr 0x27E /* Internal Memory Map Register */
+/* end of MPC8x0 registers */
+#endif
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC_VAR(sym) .globl SYM (sym)
+#define EXTERN_VAR(sym) .extern SYM (sym)
+#define PUBLIC_PROC(sym) .globl PROC (sym)
+#define EXTERN_PROC(sym) .extern PROC (sym)
+
+/* Other potentially assembler specific operations */
+#if PPC_ASM == PPC_ASM_ELF
+#define ALIGN(n,p) .align p
+#define DESCRIPTOR(x) \
+ .section .descriptors,"aw"; \
+ PUBLIC_VAR (x); \
+SYM (x):; \
+ .long PROC (x); \
+ .long s.got; \
+ .long 0
+
+#define EXT_SYM_REF(x) .long x
+#define EXT_PROC_REF(x) .long x
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA .data
+#define END_DATA
+#define BEGIN_BSS .bss
+#define END_BSS
+#define END
+
+#else
+#error "PPC_ASM_TYPE is not properly defined"
+#endif
+#ifndef PPC_ASM
+#error "PPC_ASM_TYPE is not properly defined"
+#endif
+
+
+#endif
diff --git a/cpukit/score/cpu/powerpc/rtems/powerpc/registers.h b/cpukit/score/cpu/powerpc/rtems/powerpc/registers.h
new file mode 100644
index 0000000000..fa193472dd
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/rtems/powerpc/registers.h
@@ -0,0 +1,541 @@
+/*
+ * This file contains some powerpc MSR and registers access definitions.
+ *
+ * COPYRIGHT (C) 1999 Eric Valette (valette@crf.canon.fr)
+ * Canon Centre Recherche France.
+ *
+ * Added MPC8260 Andy Dachs <a.dachs@sstl.co.uk>
+ * Surrey Satellite Technology Limited
+ *
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_POWERPC_REGISTERS_H
+#define _RTEMS_POWERPC_REGISTERS_H
+
+/* Bit encodings for Machine State Register (MSR) */
+#define MSR_UCLE (1<<26) /* User-mode cache lock enable (e500) */
+#define MSR_VE (1<<25) /* Alti-Vec enable (7400+) */
+#define MSR_SPE (1<<25) /* SPE enable (e500) */
+#define MSR_POW (1<<18) /* Enable Power Management */
+#define MSR_WE (1<<18) /* Wait state enable (e500) */
+#define MSR_TGPR (1<<17) /* TLB Update registers in use */
+#define MSR_CE (1<<17) /* BookE critical interrupt */
+#define MSR_ILE (1<<16) /* Interrupt Little-Endian enable */
+#define MSR_EE (1<<15) /* External Interrupt enable */
+#define MSR_PR (1<<14) /* Supervisor/User privilege */
+#define MSR_FP (1<<13) /* Floating Point enable */
+#define MSR_ME (1<<12) /* Machine Check enable */
+#define MSR_FE0 (1<<11) /* Floating Exception mode 0 */
+#define MSR_SE (1<<10) /* Single Step */
+#define MSR_UBLE (1<<10) /* User-mode BTB lock enable (e500) */
+#define MSR_BE (1<<9) /* Branch Trace */
+#define MSR_DE (1<<9) /* BookE debug exception */
+#define MSR_FE1 (1<<8) /* Floating Exception mode 1 */
+#define MSR_E300_CE (1<<7) /* e300 critical interrupt */
+#define MSR_IP (1<<6) /* Exception prefix 0x000/0xFFF */
+#define MSR_IR (1<<5) /* Instruction MMU enable */
+#define MSR_DR (1<<4) /* Data MMU enable */
+#define MSR_IS (1<<5) /* Instruction address space */
+#define MSR_DS (1<<4) /* Data address space */
+#define MSR_PMM (1<<2) /* Performance monitor mark */
+#define MSR_RI (1<<1) /* Recoverable Exception */
+#define MSR_LE (1<<0) /* Little-Endian enable */
+
+/* Bit encodings for Hardware Implementation Register (HID0)
+ on PowerPC 603, 604, etc. processors (not 601). */
+
+/* WARNING: HID0/HID1 are *truely* implementation dependent!
+ * you *cannot* rely on the same bits to be present,
+ * at the same place or even in the same register
+ * on different CPU familys.
+ * E.g., EMCP isHID0_DOZE is HID0_HI_BAT_EN on the
+ * on the 7450s. IFFT is XBSEN on 7450 and so on...
+ */
+#define HID0_EMCP (1<<31) /* Enable Machine Check pin */
+#define HID0_EBA (1<<29) /* Enable Bus Address Parity */
+#define HID0_EBD (1<<28) /* Enable Bus Data Parity */
+#define HID0_SBCLK (1<<27)
+#define HID0_TBEN (1<<26) /* 7455:this bit must be set
+ * and TBEN signal must be asserted
+ * to enable the time base and
+ * decrementer.
+ */
+#define HID0_EICE (1<<26)
+#define HID0_ECLK (1<<25)
+#define HID0_PAR (1<<24)
+#define HID0_DOZE (1<<23)
+/* this HI_BAT_EN only on 7445, 7447, 7448, 7455 & 7457 !! */
+#define HID0_7455_HIGH_BAT_EN (1<<23)
+
+#define HID0_NAP (1<<22)
+#define HID0_SLEEP (1<<21)
+#define HID0_DPM (1<<20)
+#define HID0_ICE (1<<15) /* Instruction Cache Enable */
+#define HID0_DCE (1<<14) /* Data Cache Enable */
+#define HID0_ILOCK (1<<13) /* Instruction Cache Lock */
+#define HID0_DLOCK (1<<12) /* Data Cache Lock */
+#define HID0_ICFI (1<<11) /* Instruction Cache Flash Invalidate */
+#define HID0_DCI (1<<10) /* Data Cache Invalidate */
+/* this bit is XSBSEN (xtended block size enable) on 7447, 7448, 7455 and 7457 only */
+#define HID0_7455_XBSEN (1<<8)
+#define HID0_SIED (1<<7) /* Serial Instruction Execution [Disable] */
+#define HID0_BTIC (1<<5) /* Branch Target Instruction Cache [Enable] */
+/* S.K. Feng 10/03, added for MPC7455 */
+#define HID0_LRSTK (1<<4) /* Link register stack enable (7455) */
+#define HID0_FOLD (1<<3) /* Branch folding enable (7455) */
+
+#define HID0_BHTE (1<<2) /* Branch History Table Enable */
+#define HID0_BTCD (1<<1) /* Branch target cache disable */
+
+/* fpscr settings */
+#define FPSCR_FX (1<<31)
+#define FPSCR_FEX (1<<30)
+
+#define _MACH_prep 1
+#define _MACH_Pmac 2 /* pmac or pmac clone (non-chrp) */
+#define _MACH_chrp 4 /* chrp machine */
+#define _MACH_mbx 8 /* Motorola MBX board */
+#define _MACH_apus 16 /* amiga with phase5 powerup */
+#define _MACH_fads 32 /* Motorola FADS board */
+
+/* see residual.h for these */
+#define _PREP_Motorola 0x01 /* motorola prep */
+#define _PREP_Firm 0x02 /* firmworks prep */
+#define _PREP_IBM 0x00 /* ibm prep */
+#define _PREP_Bull 0x03 /* bull prep */
+
+/* these are arbitrary */
+#define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
+#define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
+
+#define _GLOBAL(n)\
+ .globl n;\
+n:
+
+#define TBRU 269 /* Time base Upper/Lower (Reading) */
+#define TBRL 268
+#define TBWU 285 /* Time base Upper/Lower (Writing) */
+#define TBWL 284
+#define XER 1
+#define LR 8
+#define CTR 9
+#define HID0 1008 /* Hardware Implementation 0 */
+#define HID1 1009 /* Hardware Implementation 1 */
+#define HID2 1011 /* Hardware Implementation 2 */
+#define DABR 1013 /* Data Access Breakpoint */
+#define PVR 287 /* Processor Version */
+#define IBAT0U 528 /* Instruction BAT #0 Upper/Lower */
+#define IBAT0L 529
+#define IBAT1U 530 /* Instruction BAT #1 Upper/Lower */
+#define IBAT1L 531
+#define IBAT2U 532 /* Instruction BAT #2 Upper/Lower */
+#define IBAT2L 533
+#define IBAT3U 534 /* Instruction BAT #3 Upper/Lower */
+#define IBAT3L 535
+
+/* Only present on 7445, 7447, 7448, 7455 and 7457 (if HID0[HIGH_BAT_EN]) */
+#define IBAT4U 560 /* Instruction BAT #4 Upper/Lower */
+#define IBAT4L 561
+#define IBAT5U 562 /* Instruction BAT #5 Upper/Lower */
+#define IBAT5L 563
+#define IBAT6U 564 /* Instruction BAT #6 Upper/Lower */
+#define IBAT6L 565
+#define IBAT7U 566 /* Instruction BAT #7 Upper/Lower */
+#define IBAT7L 567
+
+#define DBAT0U 536 /* Data BAT #0 Upper/Lower */
+#define DBAT0L 537
+#define DBAT1U 538 /* Data BAT #1 Upper/Lower */
+#define DBAT1L 539
+#define DBAT2U 540 /* Data BAT #2 Upper/Lower */
+#define DBAT2L 541
+#define DBAT3U 542 /* Data BAT #3 Upper/Lower */
+#define DBAT3L 543
+
+/* Only present on 7445, 7447, 7448, 7455 and 7457 (if HID0[HIGH_BAT_EN]) */
+#define DBAT4U 568 /* Instruction BAT #4 Upper/Lower */
+#define DBAT4L 569
+#define DBAT5U 570 /* Instruction BAT #5 Upper/Lower */
+#define DBAT5L 571
+#define DBAT6U 572 /* Instruction BAT #6 Upper/Lower */
+#define DBAT6L 573
+#define DBAT7U 574 /* Instruction BAT #7 Upper/Lower */
+#define DBAT7L 575
+
+#define DMISS 976 /* TLB Lookup/Refresh registers */
+#define DCMP 977
+#define HASH1 978
+#define HASH2 979
+#define IMISS 980
+#define ICMP 981
+#define RPA 982
+#define SDR1 25 /* MMU hash base register */
+#define DAR 19 /* Data Address Register */
+#define DEAR_BOOKE 61
+#define DEAR_405 981
+#define SPR0 272 /* Supervisor Private Registers */
+#define SPRG0 272
+#define SPR1 273
+#define SPRG1 273
+#define SPR2 274
+#define SPRG2 274
+#define SPR3 275
+#define SPRG3 275
+#define SPRG4 276
+#define SPRG5 277
+#define SPRG6 278
+#define SPRG7 279
+#define USPRG0 256
+#define DSISR 18
+#define SRR0 26 /* Saved Registers (exception) */
+#define SRR1 27
+#define IABR 1010 /* Instruction Address Breakpoint */
+#define DEC 22 /* Decrementer */
+#define EAR 282 /* External Address Register */
+
+#define MSSCR0 1014 /* Memory Subsystem Control Register */
+
+#define L2CR 1017 /* PPC 750 and 74xx L2 control register */
+
+#define L2CR_L2E (1<<31) /* enable */
+#define L2CR_L2I (1<<21) /* global invalidate */
+
+/* watch out L2IO and L2DO are different between 745x and 7400/7410 */
+/* Oddly, the following L2CR bit defintions in 745x
+ * is different from that of 7400 and 7410.
+ * Though not used in 7400 and 7410, it is appeded with _745x just
+ * to be clarified.
+ */
+#define L2CR_L2IO_745x 0x100000 /* (1<<20) L2 Instruction-Only */
+#define L2CR_L2DO_745x 0x10000 /* (1<<16) L2 Data-Only */
+#define L2CR_LOCK_745x (L2CR_L2IO_745x|L2CR_L2DO_745x)
+#define L2CR_L3OH0 0x00080000 /* 12:L3 output hold 0 */
+
+#define L3CR 1018 /* PPC 7450/7455 L3 control register */
+#define L3CR_L3IO_745x 0x400000 /* (1<<22) L3 Instruction-Only */
+#define L3CR_L3DO_745x 0x40 /* (1<<6) L3 Data-Only */
+
+#define L3CR_LOCK_745x (L3CR_L3IO_745x|L3CR_L3DO_745x)
+
+#define L3CR_RESERVED 0x0438003a /* Reserved bits in L3CR */
+#define L3CR_L3E 0x80000000 /* 0: L3 enable */
+#define L3CR_L3PE 0x40000000 /* 1: L3 data parity checking enable */
+#define L3CR_L3APE 0x20000000 /* 2: L3 address parity checking enable */
+#define L3CR_L3SIZ 0x10000000 /* 3: L3 size (0=1MB, 1=2MB) */
+#define L3SIZ_1M 0x00000000
+#define L3SIZ_2M 0x10000000
+#define L3CR_L3CLKEN 0x08000000 /* 4: Enables the L3_CLK[0:1] signals */
+#define L3CR_L3CLK 0x03800000 /* 6-8: L3 clock ratio */
+#define L3CLK_60 0x00000000 /* core clock / 6 */
+#define L3CLK_20 0x01000000 /* / 2 */
+#define L3CLK_25 0x01800000 /* / 2.5 */
+#define L3CLK_30 0x02000000 /* / 3 */
+#define L3CLK_35 0x02800000 /* / 3.5 */
+#define L3CLK_40 0x03000000 /* / 4 */
+#define L3CLK_50 0x03800000 /* / 5 */
+#define L3CR_L3IO 0x00400000 /* 9: L3 instruction-only mode */
+#define L3CR_L3SPO 0x00040000 /* 13: L3 sample point override */
+#define L3CR_L3CKSP 0x00030000 /* 14-15: L3 clock sample point */
+#define L3CKSP_2 0x00000000 /* 2 clocks */
+#define L3CKSP_3 0x00010000 /* 3 clocks */
+#define L3CKSP_4 0x00020000 /* 4 clocks */
+#define L3CKSP_5 0x00030000 /* 5 clocks */
+#define L3CR_L3PSP 0x0000e000 /* 16-18: L3 P-clock sample point */
+#define L3PSP_0 0x00000000 /* 0 clocks */
+#define L3PSP_1 0x00002000 /* 1 clocks */
+#define L3PSP_2 0x00004000 /* 2 clocks */
+#define L3PSP_3 0x00006000 /* 3 clocks */
+#define L3PSP_4 0x00008000 /* 4 clocks */
+#define L3PSP_5 0x0000a000 /* 5 clocks */
+#define L3CR_L3REP 0x00001000 /* 19: L3 replacement algorithm (0=default, 1=alternate) */
+#define L3CR_L3HWF 0x00000800 /* 20: L3 hardware flush */
+#define L3CR_L3I 0x00000400 /* 21: L3 global invaregisters.h.orig
+lidate */
+#define L3CR_L3RT 0x00000300 /* 22-23: L3 SRAM type */
+#define L3RT_MSUG2_DDR 0x00000000 /* MSUG2 DDR SRAM */
+#define L3RT_PIPELINE_LATE 0x00000100 /* Pipelined (register-register) synchronous late-write SRAM */
+#define L3RT_PB2_SRAM 0x00000300 /* PB2 SRAM */
+#define L3CR_L3NIRCA 0x00000080 /* 24: L3 non-integer ratios clock adjustment for the SRAM */
+#define L3CR_L3DO 0x00000040 /* 25: L3 data-only mode */
+#define L3CR_PMEN 0x00000004 /* 29: Private memory enable */
+#define L3CR_PMSIZ 0x00000004 /* 31: Private memory size (0=1MB, 1=2MB) */
+
+#define THRM1 1020
+#define THRM2 1021
+#define THRM3 1022
+#define THRM1_TIN (1<<(31-0))
+#define THRM1_TIV (1<<(31-1))
+#define THRM1_THRES (0x7f<<(31-8))
+#define THRM1_TID (1<<(31-29))
+#define THRM1_TIE (1<<(31-30))
+#define THRM1_V (1<<(31-31))
+#define THRM3_SITV (0x1fff << (31-30))
+#define THRM3_E (1<<(31-31))
+
+/* Segment Registers */
+#define PPC_SR0 0
+#define PPC_SR1 1
+#define PPC_SR2 2
+#define PPC_SR3 3
+#define PPC_SR4 4
+#define PPC_SR5 5
+#define PPC_SR6 6
+#define PPC_SR7 7
+#define PPC_SR8 8
+#define PPC_SR9 9
+#define PPC_SR10 10
+#define PPC_SR11 11
+#define PPC_SR12 12
+#define PPC_SR13 13
+#define PPC_SR14 14
+#define PPC_SR15 15
+
+#define BOOKE_DECAR 54
+
+#define PPC405_TSR 0x3D8
+#define BOOKE_TSR 336
+#define BOOKE_TSR_ENW (1<<31)
+#define BOOKE_TSR_WIS (1<<30)
+#define BOOKE_TSR_DIS (1<<27)
+#define BOOKE_TSR_FIS (1<<26)
+
+#define PPC405_TCR 0x3DA
+#define BOOKE_TCR 340
+#define BOOKE_TCR_WP(x) (((x)&3)<<30)
+#define BOOKE_TCR_WP_MASK (3<<30)
+#define BOOKE_TCR_WRC(x) (((x)&3)<<28)
+#define BOOKE_TCR_WRC_MASK (3<<28)
+#define BOOKE_TCR_WIE (1<<27)
+#define BOOKE_TCR_DIE (1<<26)
+#define BOOKE_TCR_FP(x) (((x)&3)<<24)
+#define BOOKE_TCR_FIE (1<<23)
+#define BOOKE_TCR_ARE (1<<22)
+#define BOOKE_TCR_WPEXT(x) (((x)&0xf)<<17)
+#define BOOKE_TCR_WPEXT_MASK (0xf<<17)
+#define BOOKE_TCR_FPEXT(x) (((x)&0xf)<<13)
+#define BOOKE_TCR_FPEXT_MASK (0xf<<13)
+
+#define BOOKE_PID 48
+#define BOOKE_PIR 286
+
+/* Freescale Book E Implementation Standards (EIS): MMU Control and Status */
+
+#define FSL_EIS_MAS0 624
+#define FSL_EIS_MAS0_TLBSEL (1 << (63 - 35))
+#define FSL_EIS_MAS0_ESEL(n) ((0xf & (n)) << (63 - 47))
+#define FSL_EIS_MAS0_ESEL_GET(m) (((m) >> (63 - 47)) & 0xf)
+#define FSL_EIS_MAS0_NV (1 << (63 - 63))
+
+#define FSL_EIS_MAS1 625
+#define FSL_EIS_MAS1_V (1 << (63 - 32))
+#define FSL_EIS_MAS1_IPROT (1 << (63 - 33))
+#define FSL_EIS_MAS1_TID(n) ((0xff & (n)) << (63 - 47))
+#define FSL_EIS_MAS1_TID_GET(n) (((n) >> (63 - 47)) & 0xfff)
+#define FSL_EIS_MAS1_TS (1 << (63 - 51))
+#define FSL_EIS_MAS1_TSIZE(n) ((0xf & (n)) << (63 - 55))
+#define FSL_EIS_MAS1_TSIZE_GET(n) (((n)>>(63 - 55)) & 0xf)
+
+#define FSL_EIS_MAS2 626
+#define FSL_EIS_MAS2_EPN(n) ((((1 << 21) - 1)&(n)) << (63-51))
+#define FSL_EIS_MAS2_EPN_GET(n) (((n) >> (63 - 51)) & 0xfffff)
+#define FSL_EIS_MAS2_EA(n) FSL_EIS_MAS2_EPN((n) >> 12)
+#define FSL_EIS_MAS2_EA_GET(n) (FSL_EIS_MAS2_EPN_GET(n) << 12)
+#define FSL_EIS_MAS2_X0 (1 << (63 - 57))
+#define FSL_EIS_MAS2_X1 (1 << (63 - 58))
+#define FSL_EIS_MAS2_W (1 << (63 - 59))
+#define FSL_EIS_MAS2_I (1 << (63 - 60))
+#define FSL_EIS_MAS2_M (1 << (63 - 61))
+#define FSL_EIS_MAS2_G (1 << (63 - 62))
+#define FSL_EIS_MAS2_E (1 << (63 - 63))
+#define FSL_EIS_MAS2_ATTR(x) ((x) & 0x7f)
+#define FSL_EIS_MAS2_ATTR_GET(x) ((x) & 0x7f)
+
+#define FSL_EIS_MAS3 627
+#define FSL_EIS_MAS3_RPN(n) ((((1 << 21) - 1) & (n)) << (63-51))
+#define FSL_EIS_MAS3_RPN_GET(n) (((n)>>(63 - 51)) & 0xfffff)
+#define FSL_EIS_MAS3_RA(n) FSL_EIS_MAS3_RPN((n) >> 12)
+#define FSL_EIS_MAS3_RA_GET(n) (FSL_EIS_MAS3_RPN_GET(n) << 12)
+#define FSL_EIS_MAS3_U0 (1 << (63 - 54))
+#define FSL_EIS_MAS3_U1 (1 << (63 - 55))
+#define FSL_EIS_MAS3_U2 (1 << (63 - 56))
+#define FSL_EIS_MAS3_U3 (1 << (63 - 57))
+#define FSL_EIS_MAS3_UX (1 << (63 - 58))
+#define FSL_EIS_MAS3_SX (1 << (63 - 59))
+#define FSL_EIS_MAS3_UW (1 << (63 - 60))
+#define FSL_EIS_MAS3_SW (1 << (63 - 61))
+#define FSL_EIS_MAS3_UR (1 << (63 - 62))
+#define FSL_EIS_MAS3_SR (1 << (63 - 63))
+#define FSL_EIS_MAS3_PERM(n) ((n) & 0x3ff)
+#define FSL_EIS_MAS3_PERM_GET(n) ((n) & 0x3ff)
+
+#define FSL_EIS_MAS4 628
+#define FSL_EIS_MAS4_TLBSELD (1 << (63 - 35))
+#define FSL_EIS_MAS4_TIDSELD(n) ((0x3 & (n)) << (63 - 47))
+#define FSL_EIS_MAS4_TSIZED(n) ((0xf & (n)) << (63 - 55))
+#define FSL_EIS_MAS4_X0D FSL_EIS_MAS2_X0
+#define FSL_EIS_MAS4_X1D FSL_EIS_MAS2_X1
+#define FSL_EIS_MAS4_WD FSL_EIS_MAS2_W
+#define FSL_EIS_MAS4_ID FSL_EIS_MAS2_I
+#define FSL_EIS_MAS4_MD FSL_EIS_MAS2_M
+#define FSL_EIS_MAS4_GD FSL_EIS_MAS2_G
+#define FSL_EIS_MAS4_ED FSL_EIS_MAS2_E
+
+#define FSL_EIS_MAS5 629
+
+#define FSL_EIS_MAS6 630
+#define FSL_EIS_MAS6_SPID0(n) ((0xff & (n)) << (63 - 55))
+#define FSL_EIS_MAS6_SAS (1 << (63 - 63))
+
+#define FSL_EIS_MAS7 944
+
+#define FSL_EIS_MMUCFG 1015
+#define FSL_EIS_MMUCSR0 1012
+#define FSL_EIS_PID0 48
+#define FSL_EIS_PID1 633
+#define FSL_EIS_PID2 634
+#define FSL_EIS_TLB0CFG 688
+#define FSL_EIS_TLB1CFG 689
+
+/* Freescale Book E Implementation Standards (EIS): L1 Cache */
+
+#define FSL_EIS_L1CFG0 515
+#define FSL_EIS_L1CFG1 516
+#define FSL_EIS_L1CSR0 1010
+#define FSL_EIS_L1CSR1 1011
+
+/* Freescale Book E Implementation Standards (EIS): Timer */
+
+#define FSL_EIS_ATBL 526
+#define FSL_EIS_ATBU 527
+
+/* Freescale Book E Implementation Standards (EIS): Signal Processing Engine (SPE) */
+
+#define FSL_EIS_SPEFSCR 512
+
+/**
+ * @brief Default value for the interrupt disable mask.
+ *
+ * The interrupt disable mask is stored in the SPRG0 (= special purpose
+ * register 272).
+ */
+#define PPC_INTERRUPT_DISABLE_MASK_DEFAULT MSR_EE
+
+#ifndef ASM
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define _CPU_MSR_GET( _msr_value ) \
+ do { \
+ _msr_value = 0; \
+ __asm__ volatile ("mfmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); \
+ } while (0)
+
+#define _CPU_MSR_SET( _msr_value ) \
+{ __asm__ volatile ("mtmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); }
+
+static inline void ppc_interrupt_set_disable_mask( uint32_t mask )
+{
+ __asm__ volatile (
+ "mtspr 272, %0"
+ :
+ : "r" (mask)
+ );
+}
+
+static inline uint32_t ppc_interrupt_get_disable_mask( void )
+{
+ uint32_t mask;
+
+ __asm__ volatile (
+ "mfspr %0, 272"
+ : "=r" (mask)
+ );
+
+ return mask;
+}
+
+static inline uint32_t ppc_interrupt_disable( void )
+{
+ uint32_t level;
+ uint32_t mask;
+
+ __asm__ volatile (
+ "mfmsr %0;"
+ "mfspr %1, 272;"
+ "andc %1, %0, %1;"
+ "mtmsr %1"
+ : "=r" (level), "=r" (mask)
+ );
+
+ return level;
+}
+
+static inline void ppc_interrupt_enable( uint32_t level )
+{
+ __asm__ volatile (
+ "mtmsr %0"
+ :
+ : "r" (level)
+ );
+}
+
+static inline void ppc_interrupt_flash( uint32_t level )
+{
+ uint32_t current_level;
+
+ __asm__ volatile (
+ "mfmsr %0;"
+ "mtmsr %1;"
+ "mtmsr %0"
+ : "=&r" (current_level)
+ : "r" (level)
+ );
+}
+
+#define _CPU_ISR_Disable( _isr_cookie ) \
+ do { \
+ _isr_cookie = ppc_interrupt_disable(); \
+ } while (0)
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * _isr_cookie is not modified.
+ */
+
+#define _CPU_ISR_Enable( _isr_cookie ) \
+ ppc_interrupt_enable(_isr_cookie)
+
+/*
+ * This temporarily restores the interrupt to _isr_cookie before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _isr_cookie is not
+ * modified.
+ *
+ * NOTE: The version being used is not very optimized but it does
+ * not trip a problem in gcc where the disable mask does not
+ * get loaded. Check this for future (post 10/97 gcc versions.
+ */
+
+#define _CPU_ISR_Flash( _isr_cookie ) \
+ ppc_interrupt_flash(_isr_cookie)
+
+/* end of ISR handler macros */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* ASM */
+
+#endif /* _RTEMS_POWERPC_REGISTERS_H */
diff --git a/cpukit/score/cpu/powerpc/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
new file mode 100644
index 0000000000..b076f7e87d
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
@@ -0,0 +1,979 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * COPYRIGHT (c) 1995 i-cubed ltd.
+ *
+ * To anyone who acknowledges that this file is provided "AS IS"
+ * without any express or implied warranty:
+ * permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies, and that the name of i-cubed limited not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * i-cubed limited makes no representations about the suitability
+ * of this software for any purpose.
+ *
+ * Copyright (c) 2001 Andy Dachs <a.dachs@sstl.co.uk>.
+ *
+ * Copyright (c) 2001 Surrey Satellite Technology Limited (SSTL).
+ *
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#include <rtems/score/types.h>
+#include <rtems/score/powerpc.h>
+#include <rtems/powerpc/registers.h>
+
+#ifndef ASM
+ #include <string.h> /* for memset() */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* conditional compilation parameters */
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * Basically this is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ * [NOTE: In general, the _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls _Thread_Enable_dispatch which in turns calls
+ * _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.]
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * 1. BSP provided
+ * 2. CPU dependent (if provided)
+ * 3. generic (if no BSP and no CPU dependent)
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ */
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * NOTE: Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ */
+
+#define CPU_STRUCTURE_ALIGNMENT \
+ __attribute__ ((aligned (PPC_STRUCTURE_ALIGNMENT)))
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+#else
+#define CPU_BIG_ENDIAN FALSE
+#define CPU_LITTLE_ENDIAN TRUE
+#endif
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * If there is a FP coprocessor such as the i387 or mc68881, then
+ * the answer is TRUE.
+ *
+ * The macro name "PPC_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+#if ( PPC_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#define CPU_SOFTWARE_FP FALSE
+#else
+#define CPU_HARDWARE_FP FALSE
+#define CPU_SOFTWARE_FP FALSE
+#endif
+
+/*
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ *
+ * PowerPC Note: It appears the GCC can implicitly generate FPU
+ * and Altivec instructions when you least expect them. So make
+ * all tasks floating point.
+ */
+
+#define CPU_ALL_TASKS_ARE_FP CPU_HARDWARE_FP
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ */
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/*
+ * Processor defined structures required for cpukit/score.
+ */
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ uint32_t gpr1; /* Stack pointer for all */
+ uint32_t gpr2; /* Reserved SVR4, section ptr EABI + */
+ uint32_t gpr13; /* Section ptr SVR4/EABI */
+ uint32_t gpr14; /* Non volatile for all */
+ uint32_t gpr15; /* Non volatile for all */
+ uint32_t gpr16; /* Non volatile for all */
+ uint32_t gpr17; /* Non volatile for all */
+ uint32_t gpr18; /* Non volatile for all */
+ uint32_t gpr19; /* Non volatile for all */
+ uint32_t gpr20; /* Non volatile for all */
+ uint32_t gpr21; /* Non volatile for all */
+ uint32_t gpr22; /* Non volatile for all */
+ uint32_t gpr23; /* Non volatile for all */
+ uint32_t gpr24; /* Non volatile for all */
+ uint32_t gpr25; /* Non volatile for all */
+ uint32_t gpr26; /* Non volatile for all */
+ uint32_t gpr27; /* Non volatile for all */
+ uint32_t gpr28; /* Non volatile for all */
+ uint32_t gpr29; /* Non volatile for all */
+ uint32_t gpr30; /* Non volatile for all */
+ uint32_t gpr31; /* Non volatile for all */
+ uint32_t cr; /* PART of the CR is non volatile for all */
+ uint32_t pc; /* Program counter/Link register */
+ uint32_t msr; /* Initial interrupt level */
+#ifdef __ALTIVEC__
+ /* 12 non-volatile vector registers, cache-aligned area for vscr/vrsave
+ * and padding to ensure cache-alignment.
+ * Unfortunately, we can't verify the cache line size here
+ * in the cpukit but altivec support code will produce an
+ * error if this is ever different from 32 bytes.
+ *
+ * Note: it is the BSP/CPU-support's responsibility to
+ * save/restore volatile vregs across interrupts
+ * and exceptions.
+ */
+ uint8_t altivec[16*12 + 32 + 32];
+#endif
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->gpr1
+
+typedef struct {
+ /* The ABIs (PowerOpen/SVR4/EABI) only require saving f14-f31 over
+ * procedure calls. However, this would mean that the interrupt
+ * frame had to hold f0-f13, and the fpscr. And as the majority
+ * of tasks will not have an FP context, we will save the whole
+ * context here.
+ */
+#if (PPC_HAS_DOUBLE == 1)
+ double f[32];
+ uint64_t fpscr;
+#else
+ float f[32];
+ uint32_t fpscr;
+#endif
+} Context_Control_fp;
+
+typedef struct CPU_Interrupt_frame {
+ uint32_t stacklink; /* Ensure this is a real frame (also reg1 save) */
+ uint32_t calleeLr; /* link register used by callees: SVR4/EABI */
+
+ /* This is what is left out of the primary contexts */
+ uint32_t gpr0;
+ uint32_t gpr2; /* play safe */
+ uint32_t gpr3;
+ uint32_t gpr4;
+ uint32_t gpr5;
+ uint32_t gpr6;
+ uint32_t gpr7;
+ uint32_t gpr8;
+ uint32_t gpr9;
+ uint32_t gpr10;
+ uint32_t gpr11;
+ uint32_t gpr12;
+ uint32_t gpr13; /* Play safe */
+ uint32_t gpr28; /* For internal use by the IRQ handler */
+ uint32_t gpr29; /* For internal use by the IRQ handler */
+ uint32_t gpr30; /* For internal use by the IRQ handler */
+ uint32_t gpr31; /* For internal use by the IRQ handler */
+ uint32_t cr; /* Bits of this are volatile, so no-one may save */
+ uint32_t ctr;
+ uint32_t xer;
+ uint32_t lr;
+ uint32_t pc;
+ uint32_t msr;
+ uint32_t pad[3];
+} CPU_Interrupt_frame;
+
+#endif /* ASM */
+
+/*
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/*
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ */
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ *
+ * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
+ */
+
+#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ *
+ * Note, however that compilers may use floating point registers/
+ * instructions for optimization or they may save/restore FP registers
+ * on the stack. You must not use deferred switching in these cases
+ * and on the PowerPC attempting to do so will raise a "FP unavailable"
+ * exception.
+ */
+/*
+ * ACB Note: This could make debugging tricky..
+ */
+
+/* conservative setting (FALSE); probably doesn't affect performance too much */
+#define CPU_USE_DEFERRED_FP_SWITCH FALSE
+
+/*
+ * Processor defined structures required for cpukit/score.
+ */
+
+#ifndef ASM
+
+/*
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * _CPU_Initialize and copied into the task's FP context area during
+ * _CPU_Context_Initialize.
+ */
+
+/* EXTERN Context_Control_fp _CPU_Null_fp_context; */
+
+#endif /* ndef ASM */
+
+/*
+ * This defines the number of levels and the mask used to pick those
+ * bits out of a thread mode.
+ */
+
+#define CPU_MODES_INTERRUPT_LEVEL 0x00000001 /* interrupt level in mode */
+#define CPU_MODES_INTERRUPT_MASK 0x00000001 /* interrupt level in mode */
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ */
+
+#ifndef ASM
+
+SCORE_EXTERN struct {
+ uint32_t *Disable_level;
+ void *Stack;
+ volatile bool *Switch_necessary;
+ bool *Signal;
+
+} _CPU_IRQ_info CPU_STRUCTURE_ALIGNMENT;
+
+#endif /* ndef ASM */
+
+/*
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/*
+ * (Optional) # of bytes for libmisc/stackchk to check
+ * If not specifed, then it defaults to something reasonable
+ * for most architectures.
+ */
+
+#define CPU_STACK_CHECK_SIZE (128)
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by RTEMS.
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS (0)
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (UINT32_MAX)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level. Note that
+ * this is not an option - RTEMS/score _relies_ on _ISR_Nest_level
+ * being maintained (e.g. watchdog queues).
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * ISR handler macros
+ */
+
+#define _CPU_Initialize_vectors()
+
+/*
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in _isr_cookie.
+ */
+
+#ifndef ASM
+
+static inline uint32_t _CPU_ISR_Get_level( void )
+{
+ register unsigned int msr;
+ _CPU_MSR_GET(msr);
+ if (msr & MSR_EE) return 0;
+ else return 1;
+}
+
+static inline void _CPU_ISR_Set_level( uint32_t level )
+{
+ register unsigned int msr;
+ _CPU_MSR_GET(msr);
+ if (!(level & CPU_MODES_INTERRUPT_MASK)) {
+ msr |= ppc_interrupt_get_disable_mask();
+ }
+ else {
+ msr &= ~ppc_interrupt_get_disable_mask();
+ }
+ _CPU_MSR_SET(msr);
+}
+
+void BSP_panic(char *);
+
+/* Fatal Error manager macros */
+
+/*
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ */
+
+void _BSP_Fatal_error(unsigned int);
+
+#endif /* ASM */
+
+#define _CPU_Fatal_halt( _error ) \
+ _BSP_Fatal_error(_error)
+
+/* end of Fatal Error manager macros */
+
+/*
+ * SPRG0 was previously used to make sure that the BSP fixed the PR288 bug.
+ * Now SPRG0 is devoted to the interrupt disable mask.
+ */
+
+#define PPC_BSP_HAS_FIXED_PR288 ppc_this_is_now_the_interrupt_disable_mask
+
+/*
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE (1024*8)
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ */
+
+#define CPU_ALIGNMENT (PPC_ALIGNMENT)
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_HEAP_ALIGNMENT (PPC_ALIGNMENT)
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_PARTITION_ALIGNMENT (PPC_ALIGNMENT)
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ */
+
+#define CPU_STACK_ALIGNMENT (PPC_STACK_ALIGNMENT)
+
+#ifndef ASM
+/* The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if there is a better
+ * way for your CPU PLEASE use it. The most common way to do this is to:
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * Some CPUs have special instructions which swap a 32-bit quantity in
+ * a single instruction (e.g. i486). It is probably best to avoid
+ * an "endian swapping control bit" in the CPU. One good reason is
+ * that interrupts would probably have to be disabled to ensure that
+ * an interrupt does not try to access the same "chunk" with the wrong
+ * endian. Another good reason is that on some CPUs, the endian bit
+ * endianness for ALL fetches -- both code and data -- so the code
+ * will be fetched incorrectly.
+ */
+
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t swapped;
+
+ __asm__ volatile("rlwimi %0,%1,8,24,31;"
+ "rlwimi %0,%1,24,16,23;"
+ "rlwimi %0,%1,8,8,15;"
+ "rlwimi %0,%1,24,0,7;" :
+ "=&r" ((swapped)) : "r" ((value)));
+
+ return( swapped );
+}
+
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#endif /* ASM */
+
+
+#ifndef ASM
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ */
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. Context_Restore should work most of the time. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/*
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other models include (1) not doing anything, and (2) putting
+ * a "null FP status word" in the correct place in the FP context.
+ */
+
+#define _CPU_Context_Initialize_fp( _destination ) \
+ memset( *(_destination), 0, sizeof( **(_destination) ) )
+
+/* end of Context handler macros */
+#endif /* ASM */
+
+#ifndef ASM
+/* Bitfield handler macros */
+
+/*
+ * This routine sets _output to the bit number of the first bit
+ * set in _value. _value is of CPU dependent type Priority_bit_map_Control.
+ * This type may be either 16 or 32 bits wide although only the 16
+ * least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * (1) What happens when run on a value of zero?
+ * (2) Bits may be numbered from MSB to LSB or vice-versa.
+ * (3) The numbering may be zero or one based.
+ * (4) The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
+ * _CPU_Priority_Bits_index(). These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by _CPU_Priority_mask().
+ * The basic major and minor values calculated by _Priority_Major()
+ * and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index()
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for _Priority_Get_highest() to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+ * - a series of 16 bit test instructions
+ * - a "binary search using if's"
+ * - _number = 0
+ * if _value > 0x00ff
+ * _value >>=8
+ * _number = 8;
+ *
+ * if _value > 0x0000f
+ * _value >=8
+ * _number += 4
+ *
+ * _number += bit_set_table[ _value ]
+ *
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ */
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ __asm__ volatile ("cntlzw %0, %1" : "=r" ((_output)), "=r" ((_value)) : \
+ "1" ((_value))); \
+ }
+
+/* end of Bitfield handler macros */
+
+/*
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by _CPU_Bitfield_Find_first_bit(). See the discussion
+ * for that routine.
+ */
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 0x80000000 >> (_bit_number) )
+
+/*
+ * This routine translates the bit numbers returned by
+ * _CPU_Bitfield_Find_first_bit() into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ */
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+/* end of Priority handler macros */
+#endif /* ASM */
+
+/* functions */
+
+#ifndef ASM
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Install_interrupt_stack
+ *
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * NOTE: It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ */
+
+void _CPU_Install_interrupt_stack( void );
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generallu used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: May be unnecessary to reload some registers.
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Initialize_altivec()
+ *
+ * Global altivec-related initialization.
+ */
+void
+_CPU_Initialize_altivec(void);
+
+/*
+ * _CPU_Context_switch_altivec
+ *
+ * This routine switches the altivec contexts passed to it.
+ */
+
+void
+_CPU_Context_switch_altivec(
+ Context_Control *from,
+ Context_Control *to
+);
+
+/*
+ * _CPU_Context_restore_altivec
+ *
+ * This routine restores the altivec context passed to it.
+ */
+
+void
+_CPU_Context_restore_altivec(
+ Context_Control *ctxt
+);
+
+/*
+ * _CPU_Context_initialize_altivec
+ *
+ * This routine initializes the altivec context passed to it.
+ */
+
+void
+_CPU_Context_initialize_altivec(
+ Context_Control *ctxt
+);
+
+void _CPU_Fatal_error(
+ uint32_t _error
+);
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_CPU_H */
diff --git a/cpukit/score/cpu/powerpc/rtems/score/powerpc.h b/cpukit/score/cpu/powerpc/rtems/score/powerpc.h
new file mode 100644
index 0000000000..93ab3b6499
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/rtems/score/powerpc.h
@@ -0,0 +1,168 @@
+/**
+ * @file rtems/score/powerpc.h
+ */
+
+/*
+ * This file contains definitions for the IBM/Motorola PowerPC
+ * family members.
+ *
+ * Author: Andrew Bray <andy@i-cubed.co.uk>
+ *
+ * COPYRIGHT (c) 1995 by i-cubed ltd.
+ *
+ * MPC860 support code was added by Jay Monkman <jmonkman@frasca.com>
+ * MPC8260 support added by Andy Dachs <a.dachs@sstl.co.uk>
+ * Surrey Satellite Technology Limited
+ *
+ * To anyone who acknowledges that this file is provided "AS IS"
+ * without any express or implied warranty:
+ * permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies, and that the name of i-cubed limited not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * i-cubed limited makes no representations about the suitability
+ * of this software for any purpose.
+ *
+ * Derived from c/src/exec/cpu/no_cpu/no_cpu.h:
+ *
+ * COPYRIGHT (c) 1989-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ *
+ * Note:
+ * This file is included by both C and assembler code ( -DASM )
+ *
+ * $Id$
+ */
+
+
+#ifndef _RTEMS_SCORE_POWERPC_H
+#define _RTEMS_SCORE_POWERPC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "PowerPC"
+
+/*
+ * This file contains the information required to build
+ * RTEMS for the PowerPC family.
+ */
+
+/* Generic ppc */
+
+#ifdef _SOFT_FLOAT
+#define CPU_MODEL_NAME "Generic (no FPU)"
+#elif defined(__NO_FPRS__) || defined(__SPE__)
+#define CPU_MODEL_NAME "Generic (E500/float-gprs/SPE)"
+#else
+#define CPU_MODEL_NAME "Generic (classic FPU)"
+#endif
+
+#define PPC_ALIGNMENT 8
+#define PPC_STRUCTURE_ALIGNMENT 32
+
+/*
+ * Application binary interfaces.
+ *
+ * PPC_ABI MUST be defined as one of these.
+ * Only big endian is currently supported.
+ */
+
+/*
+ * SVR4 ABI
+ */
+#define PPC_ABI_SVR4 2
+/*
+ * Embedded ABI
+ */
+#define PPC_ABI_EABI 3
+
+/*
+ * Default to the EABI used by current GNU tools
+ */
+
+#ifndef PPC_ABI
+#define PPC_ABI PPC_ABI_EABI
+#endif
+
+#if (PPC_ABI == PPC_ABI_SVR4) || defined(__ALTIVEC__)
+#define PPC_STACK_ALIGNMENT 16
+#elif (PPC_ABI == PPC_ABI_EABI)
+#if 1
+/* Till.S: 2008/07/10; AFAIK, the CPU_STACK_ALIGNMENT is only
+ * used to align the top of the stack. We don't lose much
+ * if we always align TOS to 16-bytes but we then are always
+ * OK, even if the user tells the compiler to generate 16-byte
+ * alignment.
+ */
+#define PPC_STACK_ALIGNMENT 16
+#else
+#define PPC_STACK_ALIGNMENT 8
+#endif
+#else
+#error "PPC_ABI is not properly defined"
+#endif
+
+/*
+ * Assume PPC_HAS_FPU to be a synonym for _SOFT_FLOAT.
+ */
+
+#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) /* e500 has unified integer/FP registers */
+#define PPC_HAS_FPU 0
+#else
+#define PPC_HAS_FPU 1
+#endif
+
+/*
+ * Unless specified above, If the model has FP support, it is assumed to
+ * support doubles (8-byte floating point numbers).
+ *
+ * If the model does NOT have FP support, then the model does
+ * NOT have double length FP registers.
+ */
+
+#if (PPC_HAS_FPU)
+#define PPC_HAS_DOUBLE 1
+#else
+#define PPC_HAS_DOUBLE 0
+#endif
+
+/*
+ * Assemblers.
+ * PPC_ASM MUST be defined as one of these.
+ *
+ * PPC_ASM_ELF: ELF assembler. Currently used for all ABIs.
+ *
+ * NOTE: Only PPC_ABI_ELF is currently fully supported.
+ *
+ * Also NOTE: cpukit doesn't need this but asm.h which is defined
+ * in cpukit for consistency with other ports does.
+ */
+
+#define PPC_ASM_ELF 0
+
+/*
+ * Default to the assembler format used by the current GNU tools.
+ */
+#define PPC_ASM PPC_ASM_ELF
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_POWERPC_H */
diff --git a/cpukit/score/cpu/powerpc/rtems/score/types.h b/cpukit/score/cpu/powerpc/rtems/score/types.h
new file mode 100644
index 0000000000..828a363934
--- /dev/null
+++ b/cpukit/score/cpu/powerpc/rtems/score/types.h
@@ -0,0 +1,59 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the PowerPC
+ * processor family.
+ *
+ * Author: Andrew Bray <andy@i-cubed.co.uk>
+ *
+ * COPYRIGHT (c) 1995 by i-cubed ltd.
+ *
+ * To anyone who acknowledges that this file is provided "AS IS"
+ * without any express or implied warranty:
+ * permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies, and that the name of i-cubed limited not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * i-cubed limited makes no representations about the suitability
+ * of this software for any purpose.
+ *
+ * Derived from c/src/exec/cpu/no_cpu/no_cputypes.h:
+ *
+ * COPYRIGHT (c) 1989-1997.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+typedef uint32_t Priority_bit_map_Control;
+typedef void ppc_isr;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/sh/.cvsignore b/cpukit/score/cpu/sh/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/sh/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/sh/ChangeLog b/cpukit/score/cpu/sh/ChangeLog
new file mode 100644
index 0000000000..40e7e5db9e
--- /dev/null
+++ b/cpukit/score/cpu/sh/ChangeLog
@@ -0,0 +1,478 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * context.c, cpu.c, rtems/score/cpu.h, rtems/score/sh.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/cpu.h, rtems/score/types.h: Refactoring of priority
+ handling, to isolate the bitmap implementation of priorities in the
+ supercore so that priority management is a little more modular. This
+ change is in anticipation of scheduler implementations that can
+ select how they manage tracking priority levels / finding the highest
+ priority ready task. Note that most of the changes here are simple
+ renaming, to clarify the use of the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * rtems/score/cpu.h: Add a per cpu data structure which contains the
+ information required by RTEMS for each CPU core. This encapsulates
+ information such as thread executing, heir, idle and dispatch needed.
+
+2010-05-23 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c: Warning removal.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * context.c, cpu.c: Add include of config.h
+
+2009-02-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/sh.h: SH2E and SH3E have a DSP rather than an FPU. They
+ are not compatible. We currently only support the FPU found on the
+ SH3 and SH4.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Change prototype of IDLE thread to
+ consistently return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-30 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Fine tune conditional so _CPU_ISR_install_vector is in CPU Kit
+ now.
+
+2008-09-25 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * Makefile.am: Move duplicated context switch code to score/cpu. This
+ has been used to run tests on the simulator BSP as SH1, SH2, and SH4.
+ * context.c: New file.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Remove extraneous spaces.
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-19 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add missing prototype.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Eliminate the clicks_per_microsecond field in the
+ SuperH CPU Table and define another mechanism for drivers to obtain
+ this information.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, rtems/score/sh.h: Recognize sh2e variant so multilibs will all
+ compile.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2006-01-11 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-02-19 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove traces from NO_CPU.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/sh.h, rtems/score/sh_io.h,
+ rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/sh.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/sh.h: *_swap_u16( uint16_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/sh.h: Add doxygen preamble.
+ * rtems/score/sh_io.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-09-29 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: i960 obsoleted and all references removed.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into$(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h, rtems/score/sh.h, rtems/score/sh_io.h:
+ Convert to using c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-26 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Obsoleting HP PA-RISC port and removing all
+ references.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * asm.h, cpu.c, rtems/score/cpu.h, rtems/score/sh.h,
+ rtems/score/sh_io.h, rtems/score/types.h: URL for license changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/sh.h: Fix typo in comment (Starus->Status).
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.c: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2002-04-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.c: Adaptation to gcc-3.0.x.
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/shtypes.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-01-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Reflect 2002-01-23 changes.
+
+2002-01-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Reflect 2002-01-23 changes.
+
+2002-01-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-15 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * cpu.c: Fix #ifdefs, add missing #endif.
+
+2001-10-12 Joel Sherrill <joel@OARcorp.com>
+
+ * asm.h, cpu.c, rtems.c, rtems/score/cpu.h, rtems/score/sh.h,
+ rtems/score/sh_io.h, rtems/score/shtypes.h: Consistency changes
+ and made sure there were no includes from the libcpu tree.
+
+2001-10-12 Alexandra Kossovsky <sasha@oktet.ru>
+
+ * cpu.c, rtems/score/cpu.h, rtems/score/sh.h: Modified to
+ support SH4. Reviewed by Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+ who did the original SH port.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+2001-07-25 Radzislaw Galler <rgaller@et.put.poznan.pl>
+
+ * cpu.c (_CPU_ISR_install_vector): Corrected interrupt range
+ checking which was SH1 specific. It didn't work for SH2 (has more
+ interrupt sources).
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/sh/Makefile.am b/cpukit/score/cpu/sh/Makefile.am
new file mode 100644
index 0000000000..02ab7af758
--- /dev/null
+++ b/cpukit/score/cpu/sh/Makefile.am
@@ -0,0 +1,19 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/cpu.h rtems/score/types.h \
+ rtems/score/sh.h rtems/score/sh_io.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c context.c
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/sh/context.c b/cpukit/score/cpu/sh/context.c
new file mode 100644
index 0000000000..ddeb4874d3
--- /dev/null
+++ b/cpukit/score/cpu/sh/context.c
@@ -0,0 +1,230 @@
+/*
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * COPYRIGHT (c) 1998.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/sh.h>
+
+/*
+ * _CPU_Context_save_fp_context
+ *
+ * This routine is responsible for saving the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+)
+{
+#if SH_HAS_FPU
+
+asm volatile("\n\
+ mov.l @%0,r4 \n\
+ add %1,r4\n\
+ sts.l fpscr,@-r4\n\
+ sts.l fpul,@-r4\n\
+ lds %2,fpscr\n\
+ fmov dr14,@-r4\n\
+ fmov dr12,@-r4\n\
+ fmov dr10,@-r4\n\
+ fmov dr8,@-r4\n\
+ fmov dr6,@-r4\n\
+ fmov dr4,@-r4\n\
+ fmov dr2,@-r4\n\
+ fmov dr0,@-r4\n\
+ "
+#ifdef SH4_USE_X_REGISTERS
+ "\
+ lds %3,fpscr\n\
+ fmov xd14,@-r4\n\
+ fmov xd12,@-r4\n\
+ fmov xd10,@-r4\n\
+ fmov xd8,@-r4\n\
+ fmov xd6,@-r4\n\
+ fmov xd4,@-r4\n\
+ fmov xd2,@-r4\n\
+ fmov xd0,@-r4\n\
+ "
+#endif
+ "lds %4,fpscr\n\
+ "
+ :
+ : "r"(fp_context_ptr), "r"(sizeof(Context_Control_fp)),
+ "r"(SH4_FPSCR_SZ), "r"(SH4_FPSCR_PR | SH4_FPSCR_SZ), "r"(SH4_FPSCR_PR)
+ : "r4", "r0");
+
+#endif
+
+}
+
+/*
+ * _CPU_Context_restore_fp_context
+ *
+ * This routine is responsible for restoring the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * Sometimes a macro implementation of this is in cpu.h which dereferences
+ * the ** and a similarly named routine in this file is passed something
+ * like a (Context_Control_fp *). The general rule on making this decision
+ * is to avoid writing assembly language.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+)
+{
+
+#if SH_HAS_FPU
+
+asm volatile("\n\
+ mov.l @%0,r4 \n\
+ "
+#ifdef SH4_USE_X_REGISTERS
+ "\n\
+ lds %1,fpscr\n\
+ fmov @r4+,xd0\n\
+ fmov @r4+,xd2\n\
+ fmov @r4+,xd4\n\
+ fmov @r4+,xd6\n\
+ fmov @r4+,xd8\n\
+ fmov @r4+,xd10\n\
+ fmov @r4+,xd12\n\
+ fmov @r4+,xd14\n\
+ "
+#endif
+ "\n\
+ lds %2,fpscr\n\
+ fmov @r4+,dr0\n\
+ fmov @r4+,dr2\n\
+ fmov @r4+,dr4\n\
+ fmov @r4+,dr6\n\
+ fmov @r4+,dr8\n\
+ fmov @r4+,dr10\n\
+ fmov @r4+,dr12\n\
+ fmov @r4+,dr14\n\
+ lds.l @r4+,fpul\n\
+ lds.l @r4+,fpscr\n\
+ " :
+ : "r"(fp_context_ptr), "r"(SH4_FPSCR_PR | SH4_FPSCR_SZ), "r"(SH4_FPSCR_SZ)
+ : "r4", "r0");
+#endif
+}
+
+/* _CPU_Context_switch
+ *
+ * This routine performs a normal non-FP context switch.
+ */
+
+/* within __CPU_Context_switch:
+ * _CPU_Context_switch
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ *
+ * NOTE: It should be safe not to store r4, r5
+ *
+ * NOTE: It is doubtful if r0 is really needed to be stored
+ *
+ * NOTE: gbr is added, but should not be necessary, as it is
+ * only used globally in this port.
+ */
+
+/*
+ * FIXME: This is an ugly hack, but we wanted to avoid recalculating
+ * the offset each time Context_Control is changed
+ */
+void __CPU_Context_switch(
+ Context_Control *run, /* r4 */
+ Context_Control *heir /* r5 */
+)
+{
+
+asm volatile("\n\
+ .global __CPU_Context_switch\n\
+__CPU_Context_switch:\n\
+\n\
+ add %0,r4\n\
+ \n\
+ stc.l sr,@-r4\n\
+ stc.l gbr,@-r4\n\
+ mov.l r0,@-r4\n\
+ mov.l r1,@-r4\n\
+ mov.l r2,@-r4\n\
+ mov.l r3,@-r4\n\
+\n\
+ mov.l r6,@-r4\n\
+ mov.l r7,@-r4\n\
+ mov.l r8,@-r4\n\
+ mov.l r9,@-r4\n\
+ mov.l r10,@-r4\n\
+ mov.l r11,@-r4\n\
+ mov.l r12,@-r4\n\
+ mov.l r13,@-r4\n\
+ mov.l r14,@-r4\n\
+ sts.l pr,@-r4\n\
+ sts.l mach,@-r4\n\
+ sts.l macl,@-r4\n\
+ mov.l r15,@-r4\n\
+\n\
+ mov r5, r4"
+ :: "i" (sizeof(Context_Control))
+ );
+
+ __asm__ volatile("\n\
+ .global __CPU_Context_restore\n\
+__CPU_Context_restore:\n\
+ mov.l @r4+,r15\n\
+ lds.l @r4+,macl\n\
+ lds.l @r4+,mach\n\
+ lds.l @r4+,pr\n\
+ mov.l @r4+,r14\n\
+ mov.l @r4+,r13\n\
+ mov.l @r4+,r12\n\
+ mov.l @r4+,r11\n\
+ mov.l @r4+,r10\n\
+ mov.l @r4+,r9\n\
+ mov.l @r4+,r8\n\
+ mov.l @r4+,r7\n\
+ mov.l @r4+,r6\n\
+\n\
+ mov.l @r4+,r3\n\
+ mov.l @r4+,r2\n\
+ mov.l @r4+,r1\n\
+ mov.l @r4+,r0\n\
+ ldc.l @r4+,gbr\n\
+ ldc.l @r4+,sr\n\
+\n\
+ rts\n\
+ nop" );
+}
diff --git a/cpukit/score/cpu/sh/cpu.c b/cpukit/score/cpu/sh/cpu.c
new file mode 100644
index 0000000000..f6f85e3c4c
--- /dev/null
+++ b/cpukit/score/cpu/sh/cpu.c
@@ -0,0 +1,230 @@
+/*
+ * This file contains information pertaining to the Hitachi SH
+ * processor.
+ *
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *
+ * COPYRIGHT (c) 1998-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/sh_io.h>
+#include <rtems/score/cpu.h>
+#include <rtems/score/sh.h>
+
+/* referenced in start.S */
+extern proc_ptr vectab[] ;
+
+proc_ptr vectab[256] ;
+
+extern proc_ptr _Hardware_isr_Table[];
+
+/* _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ */
+
+void _CPU_Initialize(void)
+{
+ register uint32_t level = 0;
+
+ /*
+ * If there is not an easy way to initialize the FP context
+ * during Context_Initialize, then it is usually easier to
+ * save an "uninitialized" FP context here and copy it to
+ * the task's during Context_Initialize.
+ */
+
+ /* FP context initialization support goes here */
+ /* FIXME: When not to use SH4_FPSCR_PR ? */
+#ifdef __SH4__
+ _CPU_Null_fp_context.fpscr = SH4_FPSCR_DN | SH4_FPSCR_RM | SH4_FPSCR_PR;
+#endif
+#ifdef __SH3E__
+ /* FIXME: Wild guess :) */
+ _CPU_Null_fp_context.fpscr = SH4_FPSCR_DN | SH4_FPSCR_RM;
+#endif
+
+ /* enable interrupts */
+ _CPU_ISR_Set_level( level ) ;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ /*
+ * This routine returns the current interrupt level.
+ */
+
+ register uint32_t _mask ;
+
+ sh_get_interrupt_level( _mask );
+
+ return ( _mask);
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ /*
+ * This is where we install the interrupt handler into the "raw" interrupt
+ * table used by the CPU to dispatch interrupt handlers.
+ */
+ volatile proc_ptr *vbr ;
+
+#if SH_PARANOID_ISR
+ uint32_t level ;
+
+ sh_disable_interrupts( level );
+#endif
+
+ /* get vbr */
+ __asm__ ( "stc vbr,%0" : "=r" (vbr) );
+
+ *old_handler = vbr[vector] ;
+ vbr[vector] = new_handler ;
+
+#if SH_PARANOID_ISR
+ sh_enable_interrupts( level );
+#endif
+}
+
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * old_handler - former ISR for this vector number
+ * new_handler - replacement ISR for this vector number
+ *
+ * Output parameters: NONE
+ *
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+#if defined(__sh1__) || defined(__sh2__)
+ proc_ptr ignored ;
+#endif
+ *old_handler = _ISR_Vector_table[ vector ];
+
+ /*
+ * If the interrupt vector table is a table of pointer to isr entry
+ * points, then we need to install the appropriate RTEMS interrupt
+ * handler for this vector number.
+ */
+#if defined(__sh1__) || defined(__sh2__)
+ _CPU_ISR_install_raw_handler(vector, _Hardware_isr_Table[vector], &ignored );
+#endif
+
+ /*
+ * We put the actual user ISR address in '_ISR_Vector_table'.
+ * This will be used by __ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Thread_Idle_body
+ *
+ * NOTES:
+ *
+ * 1. This is the same as the regular CPU independent algorithm.
+ *
+ * 2. If you implement this using a "halt", "idle", or "shutdown"
+ * instruction, then don't forget to put it in an infinite loop.
+ *
+ * 3. Be warned. Some processors with onboard DMA have been known
+ * to stop the DMA if the CPU were put in IDLE mode. This might
+ * also be a problem with other on-chip peripherals. So use this
+ * hook with caution.
+ */
+
+#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+
+ for( ; ; )
+ {
+ __asm__ volatile("nop");
+ }
+ /* insert your "halt" instruction here */ ;
+}
+#endif
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+uint8_t _bit_set_table[16] =
+ { 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1,0};
+
+
+#endif
+
+void _CPU_Context_Initialize(
+ Context_Control *_the_context,
+ void *_stack_base,
+ uint32_t _size,
+ uint32_t _isr,
+ void (*_entry_point)(void),
+ int _is_fp )
+{
+ _the_context->r15 = (uint32_t *) ((uint32_t) (_stack_base) + (_size) );
+#if defined(__sh1__) || defined(__sh2__) || defined(__SH2E__)
+ _the_context->sr = (_isr << 4) & 0x00f0 ;
+#else
+ _the_context->sr = SH4_SR_MD | ((_isr << 4) & 0x00f0);
+#endif
+ _the_context->pr = (uint32_t *) _entry_point ;
+
+
+#if 0 && SH_HAS_FPU
+ /* Disable FPU if it is non-fp task */
+ if(!_is_fp)
+ _the_context->sr |= SH4_SR_FD;
+#endif
+}
diff --git a/cpukit/score/cpu/sh/preinstall.am b/cpukit/score/cpu/sh/preinstall.am
new file mode 100644
index 0000000000..b1e45094af
--- /dev/null
+++ b/cpukit/score/cpu/sh/preinstall.am
@@ -0,0 +1,45 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
+$(PROJECT_INCLUDE)/rtems/score/sh.h: rtems/score/sh.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/sh.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/sh.h
+
+$(PROJECT_INCLUDE)/rtems/score/sh_io.h: rtems/score/sh_io.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/sh_io.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/sh_io.h
+
diff --git a/cpukit/score/cpu/sh/rtems/asm.h b/cpukit/score/cpu/sh/rtems/asm.h
new file mode 100644
index 0000000000..56e11313d7
--- /dev/null
+++ b/cpukit/score/cpu/sh/rtems/asm.h
@@ -0,0 +1,136 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted. This file is:
+ *
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *
+ * COPYRIGHT (c) 1998-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/sh.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+#define r0 REG (r0)
+#define r1 REG (r1)
+#define r2 REG (r2)
+#define r3 REG (r3)
+#define r4 REG (r4)
+#define r5 REG (r5)
+#define r6 REG (r6)
+#define r7 REG (r7)
+#define r8 REG (r8)
+#define r9 REG (r9)
+#define r10 REG (r10)
+#define r11 REG (r11)
+#define r12 REG (r12)
+#define r13 REG (r13)
+#define r14 REG (r14)
+#define r15 REG (r15)
+#define vbr REG (vbr)
+#define gbr REG (gbr)
+#define pr REG (pr)
+#define mach REG (mach)
+#define macl REG (macl)
+#define sr REG (sr)
+#define pc REG (pc)
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .global SYM (sym)
+#define EXTERN(sym) .global SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/sh/rtems/score/cpu.h b/cpukit/score/cpu/sh/rtems/score/cpu.h
new file mode 100644
index 0000000000..c5a1596475
--- /dev/null
+++ b/cpukit/score/cpu/sh/rtems/score/cpu.h
@@ -0,0 +1,891 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the Hitachi SH
+ * processor.
+ *
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *
+ * COPYRIGHT (c) 1998-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/sh.h>
+
+/* conditional compilation parameters */
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ *
+ * Basically this is an example of the classic trade-off of size
+ * versus speed. Inlining the call (TRUE) typically increases the
+ * size of RTEMS while speeding up the enabling of dispatching.
+ * [NOTE: In general, the _Thread_Dispatch_disable_level will
+ * only be 0 or 1 unless you are in an interrupt handler and that
+ * interrupt handler invokes the executive.] When not inlined
+ * something calls _Thread_Enable_dispatch which in turns calls
+ * _Thread_Dispatch. If the enable dispatch is inlined, then
+ * one subroutine call is avoided entirely.]
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH FALSE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * The primary factor in making this decision is the cost of disabling
+ * and enabling interrupts (_ISR_Flash) versus the cost of rest of the
+ * body of the loop. On some CPUs, the flash is more expensive than
+ * one iteration of the loop body. In this case, it might be desirable
+ * to unroll the loop. It is important to note that on some CPUs, this
+ * code is the longest interrupt disable period in RTEMS. So it is
+ * necessary to strike a balance when setting this parameter.
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * SH Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does RTEMS manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * If the CPU supports a dedicated interrupt stack in hardware,
+ * then it is generally the responsibility of the BSP to allocate it
+ * and set it up.
+ *
+ * If the CPU does not support a dedicated interrupt stack, then
+ * the porter has two options: (1) execute interrupts on the
+ * stack of the interrupted task, and (2) have RTEMS manage a dedicated
+ * interrupt stack.
+ *
+ * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
+ *
+ * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
+ * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is
+ * possible that both are FALSE for a particular CPU. Although it
+ * is unclear what that would imply about the interrupt processing
+ * procedure on that CPU.
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/*
+ * We define the interrupt stack in the linker script
+ */
+#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
+ *
+ * We currently support sh1 only, which has no FPU, other SHes have an FPU
+ *
+ * The macro name "SH_HAS_FPU" should be made CPU specific.
+ * It indicates whether or not this CPU model has FP support. For
+ * example, it would be possible to have an i386_nofp CPU model
+ * which set this to false to indicate that you have an i386 without
+ * an i387 and wish to leave floating point support out of RTEMS.
+ */
+
+#if SH_HAS_FPU
+#define CPU_HARDWARE_FP TRUE
+#define CPU_SOFTWARE_FP FALSE
+#else
+#define CPU_SOFTWARE_FP FALSE
+#define CPU_HARDWARE_FP FALSE
+#endif
+
+/*
+ * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
+ *
+ * If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
+ */
+
+#if SH_HAS_FPU
+#define CPU_ALL_TASKS_ARE_FP TRUE
+#else
+#define CPU_ALL_TASKS_ARE_FP FALSE
+#endif
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ *
+ * Setting this to TRUE negatively impacts the time required to preempt
+ * the IDLE task from an interrupt because the floating point context
+ * must be saved as part of the preemption.
+ */
+
+#if SH_HAS_FPU
+#define CPU_IDLE_TASK_IS_FP TRUE
+#else
+#define CPU_IDLE_TASK_IS_FP FALSE
+#endif
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ *
+ * If the floating point context does NOT have to be saved as part of
+ * interrupt dispatching, then it should be safe to set this to TRUE.
+ *
+ * Setting this flag to TRUE results in using a different algorithm
+ * for deciding when to save and restore the floating point context.
+ * The deferred FP switch algorithm minimizes the number of times
+ * the FP context is saved and restored. The FP context is not saved
+ * until a context switch is made to another, different FP task.
+ * Thus in a system with only one FP task, the FP context will never
+ * be saved or restored.
+ */
+
+#if SH_HAS_FPU
+#define CPU_USE_DEFERRED_FP_SWITCH FALSE
+#else
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+#endif
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ *
+ * This is intended to allow for supporting processors which have
+ * a low power or idle mode. When the IDLE thread is executed, then
+ * the CPU can be powered down.
+ *
+ * The order of precedence for selecting the IDLE thread body is:
+ *
+ * 1. BSP provided
+ * 2. CPU dependent (if provided)
+ * 3. generic (if no BSP and no CPU dependent)
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY TRUE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ */
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical RTEMS structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The placement of this macro in the declaration of the variables
+ * is based on the syntactically requirements of the GNU C
+ * "__attribute__" extension. For example with GNU C, use
+ * the following to force a structures to a 32 byte boundary.
+ *
+ * __attribute__ ((aligned (32)))
+ *
+ * NOTE: Currently only the Priority Bit Map table uses this feature.
+ * To benefit from using this, the data must be heavily
+ * used so it will stay in the cache and used frequently enough
+ * in the executive to justify turning this on.
+ */
+
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned(16)))
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ *
+ * NOTE: SHes can be big or little endian, the default is big endian
+ */
+
+/* __LITTLE_ENDIAN__ is defined if -ml is given to gcc */
+#if defined(__LITTLE_ENDIAN__)
+#define CPU_BIG_ENDIAN FALSE
+#define CPU_LITTLE_ENDIAN TRUE
+#else
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+#endif
+
+/*
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
+ */
+
+#define CPU_MODES_INTERRUPT_MASK 0x0000000f
+
+/*
+ * Processor defined structures required for cpukit/score.
+ */
+
+/* may need to put some structures here. */
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On some processors, it is cost-effective to save only the callee
+ * preserved registers during a task context switch. This means
+ * that the ISR code needs to save those registers which do not
+ * persist across function calls. It is not mandatory to make this
+ * distinctions between the caller/callee saves registers for the
+ * purpose of minimizing context saved during task switch and on interrupts.
+ * If the cost of saving extra registers is minimal, simplicity is the
+ * choice. Save the same context on interrupt entry as for tasks in
+ * this case.
+ *
+ * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
+ * care should be used in designing the context area.
+ *
+ * On some CPUs with hardware floating point support, the Context_Control_fp
+ * structure will not be used or it simply consist of an array of a
+ * fixed number of bytes. This is done when the floating point context
+ * is dumped by a "FP save context" type instruction and the format
+ * is not really defined by the CPU. In this case, there is no need
+ * to figure out the exact format -- only the size. Of course, although
+ * this is enough information for RTEMS, it is probably not enough for
+ * a debugger such as gdb. But that is another problem.
+ */
+
+typedef struct {
+ uint32_t *r15; /* stack pointer */
+
+ uint32_t macl;
+ uint32_t mach;
+ uint32_t *pr;
+
+ uint32_t *r14; /* frame pointer/call saved */
+
+ uint32_t r13; /* call saved */
+ uint32_t r12; /* call saved */
+ uint32_t r11; /* call saved */
+ uint32_t r10; /* call saved */
+ uint32_t r9; /* call saved */
+ uint32_t r8; /* call saved */
+
+ uint32_t *r7; /* arg in */
+ uint32_t *r6; /* arg in */
+
+#if 0
+ uint32_t *r5; /* arg in */
+ uint32_t *r4; /* arg in */
+#endif
+
+ uint32_t *r3; /* scratch */
+ uint32_t *r2; /* scratch */
+ uint32_t *r1; /* scratch */
+
+ uint32_t *r0; /* arg return */
+
+ uint32_t gbr;
+ uint32_t sr;
+
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->r15
+
+typedef struct {
+#if SH_HAS_FPU
+#ifdef SH4_USE_X_REGISTERS
+ union {
+ float f[16];
+ double d[8];
+ } x;
+#endif
+ union {
+ float f[16];
+ double d[8];
+ } r;
+ float fpul; /* fp communication register */
+ uint32_t fpscr; /* fp control register */
+#endif /* SH_HAS_FPU */
+} Context_Control_fp;
+
+typedef struct {
+} CPU_Interrupt_frame;
+
+/*
+ * This variable is optional. It is used on CPUs on which it is difficult
+ * to generate an "uninitialized" FP context. It is filled in by
+ * _CPU_Initialize and copied into the task's FP context area during
+ * _CPU_Context_Initialize.
+ */
+
+#if SH_HAS_FPU
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
+#endif
+
+/*
+ * Nothing prevents the porter from declaring more CPU specific variables.
+ */
+
+/* XXX: if needed, put more variables here */
+SCORE_EXTERN void CPU_delay( uint32_t microseconds );
+
+/*
+ * The size of the floating point context area. On some CPUs this
+ * will not be a "sizeof" because the format of the floating point
+ * area is not defined -- only the size is. This is usually on
+ * CPUs with a "floating point save context" instruction.
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by RTEMS.
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 256
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Should be large enough to run all RTEMS tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * We have been able to run the sptests with this value, but have not
+ * been able to run the tmtest suite.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE 4096
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ */
+#if defined(__SH4__)
+/* FIXME: sh3 and SH3E? */
+#define CPU_ALIGNMENT 8
+#else
+#define CPU_ALIGNMENT 4
+#endif
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ */
+
+#define CPU_STACK_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * ISR handler macros
+ */
+
+/*
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ *
+ * SH Specific Information: NONE
+ */
+
+#define _CPU_Initialize_vectors()
+
+/*
+ * Disable all interrupts for an RTEMS critical section. The previous
+ * level is returned in _level.
+ */
+
+#define _CPU_ISR_Disable( _level) \
+ sh_disable_interrupts( _level )
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of an RTEMS critical section. The parameter
+ * _level is not modified.
+ */
+
+#define _CPU_ISR_Enable( _level) \
+ sh_enable_interrupts( _level)
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+#define _CPU_ISR_Flash( _level) \
+ sh_flash_interrupts( _level)
+
+/*
+ * Map interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a generic fashion are undefined. Someday,
+ * it would be nice if these were "mapped" by the application
+ * via a callout. For example, m68k has 8 levels 0 - 7, levels
+ * 8 - 255 would be available for bsp/application specific meaning.
+ * This could be used to manage a programmable interrupt controller
+ * via the rtems_task_mode directive.
+ */
+
+#define _CPU_ISR_Set_level( _newlevel) \
+ sh_set_interrupt_level(_newlevel)
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * This routine generally does not set any unnecessary register
+ * in the context. The state of the "general data" registers is
+ * undefined at task start time.
+ *
+ * NOTE: This is_fp parameter is TRUE if the thread is to be a floating
+ * point thread. This is typically only used on CPUs where the
+ * FPU may be easily disabled by software such as on the SPARC
+ * where the PSR contains an enable FPU bit.
+ */
+
+/*
+ * FIXME: defined as a function for debugging - should be a macro
+ */
+SCORE_EXTERN void _CPU_Context_Initialize(
+ Context_Control *_the_context,
+ void *_stack_base,
+ uint32_t _size,
+ uint32_t _isr,
+ void (*_entry_point)(void),
+ int _is_fp );
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task. If you are lucky, then all that is necessary
+ * is restoring the context. Otherwise, there will need to be
+ * a special assembly routine which does something special in this
+ * case. Context_Restore should work most of the time. It will
+ * not work if restarting self conflicts with the stack frame
+ * assumptions of restoring a context.
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/*
+ * The purpose of this macro is to allow the initial pointer into
+ * a floating point context area (used to save the floating point
+ * context) to be at an arbitrary place in the floating point
+ * context area.
+ *
+ * This is necessary because some FP units are designed to have
+ * their context saved as a stack which grows into lower addresses.
+ * Other FP units can be saved by simply moving registers into offsets
+ * from the base of the context area. Finally some FP units provide
+ * a "dump context" instruction which could fill in from high to low
+ * or low to high based on the whim of the CPU designers.
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ * There are a few standard ways in which to initialize the
+ * floating point context. The code included for this macro assumes
+ * that this is a CPU in which a "initial" FP context was saved into
+ * _CPU_Null_fp_context and it simply copies it to the destination
+ * context passed to it.
+ *
+ * Other models include (1) not doing anything, and (2) putting
+ * a "null FP status word" in the correct place in the FP context.
+ * SH1, SH2, SH3 have no FPU, but the SH3e and SH4 have.
+ */
+
+#if SH_HAS_FPU
+#define _CPU_Context_Initialize_fp( _destination ) \
+ do { \
+ *(*(_destination)) = _CPU_Null_fp_context;\
+ } while(0)
+#else
+#define _CPU_Context_Initialize_fp( _destination ) \
+ { }
+#endif
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/*
+ * FIXME: Trap32 ???
+ *
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * invokes a Trap32 Instruction which returns to the breakpoint
+ * routine of cmon.
+ */
+
+#ifdef BSP_FATAL_HALT
+ /* we manage the fatal error in the board support package */
+ void bsp_fatal_halt( uint32_t _error);
+#define _CPU_Fatal_halt( _error ) bsp_fatal_halt( _error)
+#else
+#define _CPU_Fatal_halt( _error)\
+{ \
+ __asm__ volatile("mov.l %0,r0"::"m" (_error)); \
+ __asm__ volatile("mov #1, r4"); \
+ __asm__ volatile("trapa #34"); \
+}
+#endif
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/*
+ * This routine sets _output to the bit number of the first bit
+ * set in _value. _value is of CPU dependent type Priority_bit_map_Control.
+ * This type may be either 16 or 32 bits wide although only the 16
+ * least significant bits will be used.
+ *
+ * There are a number of variables in using a "find first bit" type
+ * instruction.
+ *
+ * (1) What happens when run on a value of zero?
+ * (2) Bits may be numbered from MSB to LSB or vice-versa.
+ * (3) The numbering may be zero or one based.
+ * (4) The "find first bit" instruction may search from MSB or LSB.
+ *
+ * RTEMS guarantees that (1) will never happen so it is not a concern.
+ * (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
+ * _CPU_Priority_bits_index(). These three form a set of routines
+ * which must logically operate together. Bits in the _value are
+ * set and cleared based on masks built by _CPU_Priority_mask().
+ * The basic major and minor values calculated by _Priority_Major()
+ * and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
+ * to properly range between the values returned by the "find first bit"
+ * instruction. This makes it possible for _Priority_Get_highest() to
+ * calculate the major and directly index into the minor table.
+ * This mapping is necessary to ensure that 0 (a high priority major/minor)
+ * is the first bit found.
+ *
+ * This entire "find first bit" and mapping process depends heavily
+ * on the manner in which a priority is broken into a major and minor
+ * components with the major being the 4 MSB of a priority and minor
+ * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
+ * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next
+ * to the lowest priority.
+ *
+ * If your CPU does not have a "find first bit" instruction, then
+ * there are ways to make do without it. Here are a handful of ways
+ * to implement this in software:
+ *
+ * - a series of 16 bit test instructions
+ * - a "binary search using if's"
+ * - _number = 0
+ * if _value > 0x00ff
+ * _value >>=8
+ * _number = 8;
+ *
+ * if _value > 0x0000f
+ * _value >=8
+ * _number += 4
+ *
+ * _number += bit_set_table[ _value ]
+ *
+ * where bit_set_table[ 16 ] has values which indicate the first
+ * bit set
+ */
+
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+extern uint8_t _bit_set_table[];
+
+#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
+ { \
+ _output = 0;\
+ if(_value > 0x00ff) \
+ { _value >>= 8; _output = 8; } \
+ if(_value > 0x000f) \
+ { _output += 4; _value >>= 4; } \
+ _output += _bit_set_table[ _value]; }
+
+#endif
+
+/* end of Bitfield handler macros */
+
+/*
+ * This routine builds the mask which corresponds to the bit fields
+ * as searched by _CPU_Bitfield_Find_first_bit(). See the discussion
+ * for that routine.
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_Mask( _bit_number ) \
+ ( 1 << (_bit_number) )
+
+#endif
+
+/*
+ * This routine translates the bit numbers returned by
+ * _CPU_Bitfield_Find_first_bit() into something suitable for use as
+ * a major or minor component of a priority. See the discussion
+ * for that routine.
+ */
+
+#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
+
+#define _CPU_Priority_bits_index( _priority ) \
+ (_priority)
+
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs a "raw" interrupt handler directly into the
+ * processor's vector table.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_Install_interrupt_stack
+ *
+ * This routine installs the hardware interrupt stack pointer.
+ *
+ * NOTE: It needs only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
+ * is TRUE.
+ */
+
+void _CPU_Install_interrupt_stack( void );
+
+/*
+ * _CPU_Thread_Idle_body
+ *
+ * This routine is the CPU dependent IDLE thread body.
+ *
+ * NOTE: It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
+ * is TRUE.
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner. It may simply be a label in _CPU_Context_switch.
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/sh/rtems/score/sh.h b/cpukit/score/cpu/sh/rtems/score/sh.h
new file mode 100644
index 0000000000..0cd7a5d926
--- /dev/null
+++ b/cpukit/score/cpu/sh/rtems/score/sh.h
@@ -0,0 +1,277 @@
+/**
+ * @file rtems/score/sh.h
+ */
+
+/*
+ * This include file contains information pertaining to the Hitachi SH
+ * processor.
+ *
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
+ *
+ *
+ * COPYRIGHT (c) 1998-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SH_H
+#define _RTEMS_SCORE_SH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the "SH" family.
+ *
+ * It does this by setting variables to indicate which implementation
+ * dependent features are present in a particular member of the family.
+ */
+
+/*
+ * Figure out all CPU Model Feature Flags based upon compiler
+ * predefines.
+ */
+
+#if defined(__SH2E__) || defined(__SH3E__)
+
+/* FIXME: SH-DSP context not currently supported */
+#define SH_HAS_FPU 0
+
+#elif defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
+
+/*
+ * Define this if you want to use XD-registers.
+ * Then this registers will be saved/restored on context switch.
+ * ! They will not be saved/restored on interrupts!
+ */
+#define SH4_USE_X_REGISTERS 0
+
+#if defined(__LITTLE_ENDIAN__)
+#define SH_HAS_FPU 1
+#else
+/* FIXME: Context_Control_fp does not support big endian */
+#warning FPU not supported
+#define SH_HAS_FPU 0
+#endif
+
+#elif defined(__sh1__) || defined(__sh2__) || defined(__sh3__)
+#define SH_HAS_FPU 0
+#else
+#warning Cannot detect FPU support, assuming no FPU
+#define SH_HAS_FPU 0
+#endif
+
+/* this should not be here */
+#ifndef CPU_MODEL_NAME
+#define CPU_MODEL_NAME "SH-Multilib"
+#endif
+
+/*
+ * If the following macro is set to 0 there will be no software irq stack
+ */
+
+#ifndef SH_HAS_SEPARATE_STACKS
+#define SH_HAS_SEPARATE_STACKS 1
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "Hitachi SH"
+
+#ifndef ASM
+
+#if defined(__sh1__) || defined(__sh2__)
+
+/*
+ * Mask for disabling interrupts
+ */
+#define SH_IRQDIS_VALUE 0xf0
+
+#define sh_disable_interrupts( _level ) \
+ __asm__ volatile ( \
+ "stc sr,%0\n\t" \
+ "ldc %1,sr\n\t"\
+ : "=&r" (_level ) \
+ : "r" (SH_IRQDIS_VALUE) );
+
+#define sh_enable_interrupts( _level ) \
+ __asm__ volatile( "ldc %0,sr\n\t" \
+ "nop\n\t" \
+ :: "r" (_level) );
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+#define sh_flash_interrupts( _level ) \
+ __asm__ volatile( \
+ "ldc %1,sr\n\t" \
+ "nop\n\t" \
+ "ldc %0,sr\n\t" \
+ "nop\n\t" \
+ : : "r" (SH_IRQDIS_VALUE), "r" (_level) );
+
+#else
+
+#define SH_IRQDIS_MASK 0xf0
+
+#define sh_disable_interrupts( _level ) \
+ __asm__ volatile ( \
+ "stc sr,%0\n\t" \
+ "mov %0,r5\n\t" \
+ "or %1,r5\n\t" \
+ "ldc r5,sr\n\t"\
+ : "=&r" (_level ) \
+ : "r" (SH_IRQDIS_MASK) \
+ : "r5" );
+
+#define sh_enable_interrupts( _level ) \
+ __asm__ volatile( "ldc %0,sr\n\t" \
+ "nop\n\t" \
+ :: "r" (_level) );
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long RTEMS critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+#define sh_flash_interrupts( _level ) \
+ __asm__ volatile( \
+ "stc sr,r5\n\t" \
+ "ldc %1,sr\n\t" \
+ "nop\n\t" \
+ "or %0,r5\n\t" \
+ "ldc r5,sr\n\t" \
+ "nop\n\t" \
+ : : "r" (SH_IRQDIS_MASK), "r" (_level) : "r5");
+
+#endif
+
+#define sh_get_interrupt_level( _level ) \
+{ \
+ register uint32_t _tmpsr ; \
+ \
+ __asm__ volatile( "stc sr, %0" : "=r" (_tmpsr) ); \
+ _level = (_tmpsr & 0xf0) >> 4 ; \
+}
+
+#define sh_set_interrupt_level( _newlevel ) \
+{ \
+ register uint32_t _tmpsr; \
+ \
+ __asm__ volatile ( "stc sr, %0" : "=r" (_tmpsr) ); \
+ _tmpsr = ( _tmpsr & ~0xf0 ) | ((_newlevel) << 4) ; \
+ __asm__ volatile( "ldc %0,sr" :: "r" (_tmpsr) ); \
+}
+
+/*
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ */
+
+static inline uint32_t sh_swap_u32(
+ uint32_t value
+)
+{
+ register uint32_t swapped;
+
+ __asm__ volatile (
+ "swap.b %1,%0; "
+ "swap.w %0,%0; "
+ "swap.b %0,%0"
+ : "=r" (swapped)
+ : "r" (value) );
+
+ return( swapped );
+}
+
+static inline uint16_t sh_swap_u16(
+ uint16_t value
+)
+{
+ register uint16_t swapped ;
+
+ __asm__ volatile ( "swap.b %1,%0" : "=r" (swapped) : "r" (value) );
+
+ return( swapped );
+}
+
+#define CPU_swap_u32( value ) sh_swap_u32( value )
+#define CPU_swap_u16( value ) sh_swap_u16( value )
+
+extern unsigned int sh_set_irq_priority(
+ unsigned int irq,
+ unsigned int prio );
+
+#endif /* !ASM */
+
+/*
+ * Bits on SH-4 registers.
+ * See SH-4 Programming manual for more details.
+ *
+ * Added by Alexandra Kossovsky <sasha@oktet.ru>
+ */
+
+#if defined(__SH4__)
+#define SH4_SR_MD 0x40000000 /* Priveleged mode */
+#define SH4_SR_RB 0x20000000 /* General register bank specifier */
+#define SH4_SR_BL 0x10000000 /* Exeption/interrupt masking bit */
+#define SH4_SR_FD 0x00008000 /* FPU disable bit */
+#define SH4_SR_M 0x00000200 /* For signed division:
+ divisor (module) is negative */
+#define SH4_SR_Q 0x00000100 /* For signed division:
+ dividend (and quotient) is negative */
+#define SH4_SR_IMASK 0x000000f0 /* Interrupt mask level */
+#define SH4_SR_IMASK_S 4
+#define SH4_SR_S 0x00000002 /* Saturation for MAC instruction:
+ if set, data in MACH/L register
+ is restricted to 48/32 bits
+ for MAC.W/L instructions */
+#define SH4_SR_T 0x00000001 /* 1 if last condiyion was true */
+#define SH4_SR_RESERV 0x8fff7d0d /* Reserved bits, read/write as 0 */
+
+/* FPSCR -- FPU Status/Control Register */
+#define SH4_FPSCR_FR 0x00200000 /* FPU register bank specifier */
+#define SH4_FPSCR_SZ 0x00100000 /* FMOV 64-bit transfer mode */
+#define SH4_FPSCR_PR 0x00080000 /* Double-percision floating-point
+ operations flag */
+ /* SH4_FPSCR_SZ & SH4_FPSCR_PR != 1 */
+#define SH4_FPSCR_DN 0x00040000 /* Treat denormalized number as zero */
+#define SH4_FPSCR_CAUSE 0x0003f000 /* FPU exeption cause field */
+#define SH4_FPSCR_CAUSE_S 12
+#define SH4_FPSCR_ENABLE 0x00000f80 /* FPU exeption enable field */
+#define SH4_FPSCR_ENABLE_s 7
+#define SH4_FPSCR_FLAG 0x0000007d /* FPU exeption flag field */
+#define SH4_FPSCR_FLAG_S 2
+#define SH4_FPSCR_RM 0x00000001 /* Rounding mode:
+ 1/0 -- round to zero/nearest */
+#define SH4_FPSCR_RESERV 0xffd00000 /* Reserved bits, read/write as 0 */
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/sh/rtems/score/sh_io.h b/cpukit/score/cpu/sh/rtems/score/sh_io.h
new file mode 100644
index 0000000000..2b58aae62a
--- /dev/null
+++ b/cpukit/score/cpu/sh/rtems/score/sh_io.h
@@ -0,0 +1,51 @@
+/**
+ * @file rtems/score/sh_io.h
+ */
+
+/*
+ * These are some macros to access memory mapped devices
+ * on the SH7000-architecture.
+ *
+ * Inspired from the linux kernel's include/asm/io.h
+ *
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1996-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *
+ * COPYRIGHT (c) 1998-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SH_IO_H
+#define _RTEMS_SCORE_SH_IO_H
+
+#define readb(addr) (*(volatile unsigned char *) (addr))
+#define readw(addr) (*(volatile unsigned short *) (addr))
+#define readl(addr) (*(volatile unsigned int *) (addr))
+#define read8(addr) (*(volatile uint8_t *) (addr))
+#define read16(addr) (*(volatile uint16_t *) (addr))
+#define read32(addr) (*(volatile uint32_t *) (addr))
+
+#define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
+#define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
+#define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
+#define write8(b,addr) ((*(volatile uint8_t *) (addr)) = (b))
+#define write16(b,addr) ((*(volatile uint16_t *) (addr)) = (b))
+#define write32(b,addr) ((*(volatile uint32_t *) (addr)) = (b))
+
+#define inb(addr) readb(addr)
+#define outb(b,addr) writeb(b,addr)
+
+#endif
diff --git a/cpukit/score/cpu/sh/rtems/score/types.h b/cpukit/score/cpu/sh/rtems/score/types.h
new file mode 100644
index 0000000000..f367422d2b
--- /dev/null
+++ b/cpukit/score/cpu/sh/rtems/score/types.h
@@ -0,0 +1,55 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains information pertaining to the Hitachi SH
+ * processor.
+ *
+ * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
+ * Bernd Becker (becker@faw.uni-ulm.de)
+ *
+ * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *
+ * COPYRIGHT (c) 1998-2001.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+
+typedef void sh_isr;
+typedef void ( *sh_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/sparc/.cvsignore b/cpukit/score/cpu/sparc/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/sparc/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/sparc/ChangeLog b/cpukit/score/cpu/sparc/ChangeLog
new file mode 100644
index 0000000000..7978cfc23c
--- /dev/null
+++ b/cpukit/score/cpu/sparc/ChangeLog
@@ -0,0 +1,496 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h, rtems/score/sparc.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-11-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Remove unused variable reported by clang.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/types.h: Refactoring of priority handling, to isolate the
+ bitmap implementation of priorities in the supercore so that priority
+ management is a little more modular. This change is in anticipation
+ of scheduler implementations that can select how they manage tracking
+ priority levels / finding the highest priority ready task. Note that
+ most of the changes here are simple renaming, to clarify the use of
+ the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1573/cpukit
+ * cpu_asm.S, rtems/score/cpu.h: Add a per cpu data structure which
+ contains the information required by RTEMS for each CPU core. This
+ encapsulates information such as thread executing, heir, idle and
+ dispatch needed.
+
+2010-03-27 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S: Add include of config.h
+
+2009-03-12 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1385/cpukit
+ * cpu_asm.S: When the type rtems_boolean was switched to the C99 bool,
+ the size changed from 4 bytes to 1 byte. The interrupt dispatching
+ code accesses two boolean variables for scheduling purposes and the
+ assembly implementations of this code did not get updated.
+
+2009-02-12 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Change prototype of IDLE thread to consistently
+ return void * and take a uintptr_t argument.
+
+2009-02-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Eliminate _CPU_Thread_dispatch_pointer and
+ passing address of _Thread_Dispatch to _CPU_Initialize. Clean up
+ comments.
+
+2008-09-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Do not define boolean, single_precision,
+ double_precision unless RTEMS_DEPRECATED_TYPES is given.
+
+2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c: Remove extraneous spaces.
+
+2008-09-05 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h: Convert to "bool".
+
+2008-08-21 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Include stdbool.h.
+ Use bool as base-type for boolean.
+
+2008-08-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1294/bsps
+ * rtems/score/cpu.h, rtems/score/sparc.h: Correct prototype and usage
+ of sparc_disable_interrupts.
+
+2008-08-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Spacing.
+
+2008-07-31 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Correct prototype of Idle threads.
+
+2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Add CPU_SIMPLE_VECTORED_INTERRUPTS porting
+ parameter to indicate that the port uses the Simple Vectored
+ Interrupt model or the Programmable Interrupt Controller Model. The
+ PIC model is implemented primarily in the BSP and it is responsible
+ for all memory allocation.
+
+2008-02-20 Alexandru Bugnar <a-bugnar@criticalsoftware.com>
+
+ PR 1278/cpukit
+ * cpu.c: Fix incorrect bit manipulation on returning old address of raw
+ trap handler.
+
+2007-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
+
+2007-12-04 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * cpu.c, rtems/score/cpu.h: Move interrupt_stack_size field from CPU
+ Table to Configuration Table. Eliminate CPU Table from all ports.
+ Delete references to CPU Table in all forms.
+
+2007-12-03 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * rtems/score/cpu.h: Moved most of the remaining CPU Table fields to
+ the Configuration Table. This included pretasking_hook,
+ predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace,
+ extra_mpci_receive_server_stack, stack_allocate_hook, and
+ stack_free_hook. As a side-effect of this effort some multiprocessing
+ code was made conditional and some style clean up occurred.
+
+2007-05-10 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ PR 1237/rtems
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h: Add logic to prevent stack creep
+ when interrupts occur at a sufficient rate that the interrupted
+ thread never gets to clean its stack. This patch ensures that an
+ interrupted thread will not nest ISR dispatches on its stack.
+
+2007-05-09 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Remove CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.
+
+2007-04-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * cpu.c:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ * rtems/score/cpu.h:
+ Use Context_Control_fp* instead of void* for fp_contexts.
+ Eliminate evil casts.
+
+2006-11-17 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove unsigned64, signed64.
+
+2006-11-14 Jiri Gaisler <jiri@gaisler.com>
+
+ * cpu_asm.S: Properly support synchronous traps.
+
+2006-01-16 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Part of a large patch to improve Doxygen output.
+ As a side-effect, grammar and spelling errors were corrected, spacing
+ errors were address, and some variable names were improved.
+
+2005-11-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Eliminate unsigned16, unsigned32.
+
+2005-10-27 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/asm.h: Remove private version of CONCAT macros.
+ Include <rtems/concat.h> instead.
+
+2005-02-08 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Split out preinstallation rules.
+ * preinstall.am: New (Split out from Makefile.am).
+
+2005-02-04 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ PR 754/rtems
+ * rtems/asm.h: New (relocated from .).
+ * asm.h: Remove (moved to rtems/asm.h).
+ * Makefile.am: Reflect changes above.
+
+2004-01-28 Ralf Corsepius <ralf.corsepiu@rtems.org>
+
+ * asm.h, rtems/score/cpu.h, rtems/score/sparc.h,
+ rtems/score/types.h: New header guards.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Remove signed8, signed16, signed32,
+ unsigned8, unsigned16, unsigned32.
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: *_swap_u32( uint32_t ).
+
+2005-01-24 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: #include <rtems/stdint.h>.
+
+2005-01-22 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Fix broken #endif.
+
+2005-01-07 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Eliminate CFLAGS_OPTIMIZE_V.
+
+2005-01-01 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * Makefile.am: Remove build-variant support.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * rtems/score/types.h: Use __rtems_score_types_h as preprocessor
+ guard.
+
+2004-11-21 Ralf Corsepius <ralf.corsepius@rtems.org>
+
+ * asm.h: Add doxygen preamble.
+
+2004-10-02 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * rtems/score/cpu.h: Add doxygen preamble.
+ * rtems/score/sparc.h: Add doxygen preamble.
+ * rtems/score/types.h: Add doxygen preamble.
+
+2004-04-06 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: Remove (Merged into$(top_srcdir)/configure.ac).
+ * Makefile.am: Don't include multilib.am.
+ Reflect merging configure.ac into $(top_srcdir)/configure.ac.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * Makefile.am: Install asm.h to $(includedir)/rtems.
+
+2004-04-01 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu_asm.S: Include <rtems/asm.h> instead of <asm.h>.
+
+2004-03-30 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * cpu.c, rtems/score/cpu.h, rtems/score/sparc.h: Convert to using
+ c99 fixed size types.
+
+2004-03-29 Ralf Corsepius <ralf_corsepius@rtems.org>
+
+ * configure.ac: RTEMS_TOP([../../../..]).
+
+2004-02-26 Andreas Karlsson <andreas.karlsson@space.se>
+
+ 604/bsps
+ * cpu_asm.S: Close window while restoring interrupted task state which
+ resulted in CWP corruption.
+
+2004-01-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Move RTEMS_TOP one subdir down.
+
+2004-01-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add PREINSTALL_DIRS.
+
+2004-01-14 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Re-add dirstamps to PREINSTALL_FILES.
+ Add PREINSTALL_FILES to CLEANFILES.
+
+2004-01-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Requires automake >= 1.8.1.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am, again.
+
+2004-01-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Convert to using automake compilation rules.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use mkdir_p. Remove dirs from PREINSTALL_FILES.
+
+2003-12-12 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require automake >= 1.8, autoconf >= 2.59.
+
+2003-12-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Remove TMPINSTALL_FILES.
+
+2003-11-30 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add $(dirstamp) to preinstallation rules.
+
+2003-11-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Don't use gmake rules for preinstallation.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CANONICAL_HOST.
+
+2003-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_CHECK_CPU.
+
+2003-09-04 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h, rtems/score/sparc.h,
+ rtems/score/types.h: URL for license changed.
+
+2003-08-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use rtems-bugs@rtems.com as bug report email address.
+
+2003-03-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove AC_CONFIG_AUX_DIR.
+
+2002-12-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Require autoconf-2.57 + automake-1.7.2.
+ * Makefile.am: Eliminate C_O_FILES, S_O_FILES, libscorecpu_a_OBJECTS.
+
+2002-11-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Fix package name.
+
+2002-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add nostdinc to AM_INIT_AUTOMAKE.
+
+2002-10-21 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Reformat.
+ Add autom4te*cache.
+ Remove autom4te.cache.
+
+2002-08-08 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * cpu.c: Move pointer into #ifdef to avoid compiler warning.
+
+2002-07-26 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Build libscorecpu.a instead of rtems-cpu.rel.
+
+2002-07-22 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use .$(OBJEXT) instead of .o.
+
+2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: RTEMS_TOP(../../../..).
+
+2002-07-03 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems.S: Remove.
+ * Makefile.am: Reflect changes above.
+
+2002-07-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Remove RTEMS_PROJECT_ROOT.
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Add RTEMS_PROG_CCAS
+
+2002-06-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac: Use AC_CONFIG_AUX_DIR(../../../..).
+ Add AC_PROG_RANLIB.
+
+2002-06-17 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include $(top_srcdir)/../../../automake/*.am.
+ Use ../../../aclocal.
+
+2002-04-01 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * cpu.c: Remove call to sparc_init_tbr/NO_TABLE_MOVE.
+ * rtems/score/cpu.h: Remove NO_TABLE_MOVE conditional code.
+
+
+2001-04-03 Joel Sherrill <joel@OARcorp.com>
+
+ * Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
+ * rtems/score/sparctypes.h: Removed.
+ * rtems/score/types.h: New file via CVS magic.
+ * Makefile.am, rtems/score/cpu.h: Account for name change.
+
+2002-03-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * cpu.c: Replace NO_TABLE_MOVE-support by external function
+ (code moved to libcpu/sparc/tbr/tbr.c).
+ * cpu.h: Replace NO_TABLE_MOVE-support by external function
+ (code moved to libcpu/sparc/tbr/tbr.h).
+ * sparc.h: Add sparc_init_tbr (implemented in libcpu/sparc/tbr/tbr.c).
+
+2002-03-27 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * configure.ac:
+ AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS).
+ AM_INIT_AUTOMAKE([no-define foreign 1.6]).
+ * Makefile.am: Remove AUTOMAKE_OPTIONS.
+
+2002-01-31 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Reflect 2002-01-23 changes.
+
+2001-01-30 Joel Sherrill <joel@OARcorp.com>
+
+ * Makefile.am: Corrected so .h files from rtems/score/ are installed.
+
+2002-01-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/Makefile.am: Removed.
+ * rtems/score/Makefile.am: Removed.
+ * configure.ac: Reflect changes above.
+
+2001-12-19 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Add multilib support.
+
+2001-11-28 Joel Sherrill <joel@OARcorp.com>,
+
+ This was tracked as PR91.
+ * rtems/score/cpu.h: Added CPU_PROVIDES_ISR_IS_IN_PROGRESS macro which
+ is used to specify if the port uses the standard macro for this (FALSE).
+ A TRUE setting indicates the port provides its own implementation.
+
+2001-10-11 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * .cvsignore: Add autom4te.cache for autoconf > 2.52.
+ * configure.in: Remove.
+ * configure.ac: New file, generated from configure.in by autoupdate.
+
+2001-09-27 Jiri Gaisler <jiri@gaisler.com>
+
+ * cpu_asm.S: Small patch to fix a bug in the rtems sparc port. The
+ bug has been there all the time, but only hits the leon bsp since the
+ leon cpu has a 5-stage pipeline (erc32 has 4 stages).
+
+2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * rtems/score/Makefile.am: Use 'PREINSTALL_FILES ='.
+ * Makefile.am: Use 'PREINSTALL_FILES ='.
+
+
+2001-02-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am, rtems/score/Makefile.am:
+ Apply include_*HEADERS instead of H_FILES.
+
+2001-01-03 Joel Sherrill <joel@OARcorp.com>
+
+ * rtems/score/cpu.h: Added _CPU_Initialize_vectors().
+ * cpu_asm.S: Modify to properly dereference _ISR_Vector_table
+ now that it is dynamically allocated.
+
+2000-12-06 Joel Sherrill <joel@OARcorp.com>
+
+ * cpu.c: Added include of <rtems/rtems/cache.h> to eliminate warning.
+
+2000-11-21 Jiri Gaisler <jgais@ws.estec.esa.nl>
+
+ * cpu_asm.S: Fix for CPUs with FPU revision B or C.
+
+2000-11-14 Jiri Gaisler <jgais@ws.estec.esa.nl>
+
+ * cpu.c, rtems/cpu/sparc.h: Make floating point optional based
+ on gcc arguments. Do not initialize FP context if there is
+ no FPU. Flush instruction cache after installing RTEMS trap handler.
+
+2000-11-09 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS.
+
+2000-11-02 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal.
+
+2000-10-25 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: ACLOCAL_AMFLAGS= -I $(RTEMS_TOPdir)/macros.
+ Switch to GNU canonicalization.
+
+2000-09-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+
+ * Makefile.am: Include compile.am.
+
+2000-08-10 Joel Sherrill <joel@OARcorp.com>
+
+ * ChangeLog: New file.
diff --git a/cpukit/score/cpu/sparc/Makefile.am b/cpukit/score/cpu/sparc/Makefile.am
new file mode 100644
index 0000000000..6d4c4aead1
--- /dev/null
+++ b/cpukit/score/cpu/sparc/Makefile.am
@@ -0,0 +1,19 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/sparc.h rtems/score/cpu.h \
+ rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = cpu.c cpu_asm.S
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/sparc/README b/cpukit/score/cpu/sparc/README
new file mode 100644
index 0000000000..c4c2200075
--- /dev/null
+++ b/cpukit/score/cpu/sparc/README
@@ -0,0 +1,110 @@
+#
+# $Id$
+#
+
+This file discusses SPARC specific issues which are important to
+this port. The primary topics in this file are:
+
+ + Global Register Usage
+ + Stack Frame
+ + EF bit in the PSR
+
+
+Global Register Usage
+=====================
+
+This information on register usage is based heavily on a comment in the
+file gcc-2.7.0/config/sparc/sparc.h in the the gcc 2.7.0 source.
+
+ + g0 is hardwired to 0
+ + On non-v9 systems:
+ - g1 is free to use as temporary.
+ - g2-g4 are reserved for applications. Gcc normally uses them as
+ temporaries, but this can be disabled via the -mno-app-regs option.
+ - g5 through g7 are reserved for the operating system.
+ + On v9 systems:
+ - g1 and g5 are free to use as temporaries.
+ - g2-g4 are reserved for applications (the compiler will not normally use
+ them, but they can be used as temporaries with -mapp-regs).
+ - g6-g7 are reserved for the operating system.
+
+ NOTE: As of gcc 2.7.0 register g1 was used in the following scenarios:
+
+ + as a temporary by the 64 bit sethi pattern
+ + when restoring call-preserved registers in large stack frames
+
+RTEMS places no constraints on the usage of the global registers. Although
+gcc assumes that either g5-g7 (non-V9) or g6-g7 (V9) are reserved for the
+operating system, RTEMS does not assume any special use for them.
+
+
+
+Stack Frame
+===========
+
+The stack grows downward (i.e. to lower addresses) on the SPARC architecture.
+
+The following is the organization of the stack frame:
+
+
+
+ | ............... |
+ fp | |
+ +-------------------------------+
+ | |
+ | Local registers, temporaries, |
+ | and saved floats | x bytes
+ | |
+ sp + x +-------------------------------+
+ | |
+ | outgoing parameters past |
+ | the sixth one | x bytes
+ | |
+ sp + 92 +-------------------------------+ *
+ | | *
+ | area for callee to save | *
+ | register arguments | * 24 bytes
+ | | *
+ sp + 68 +-------------------------------+ *
+ | | *
+ | structure return pointer | * 4 bytes
+ | | *
+ sp + 64 +-------------------------------+ *
+ | | *
+ | local register set | * 32 bytes
+ | | *
+ sp + 32 +-------------------------------+ *
+ | | *
+ | input register set | * 32 bytes
+ | | *
+ sp +-------------------------------+ *
+
+
+* = minimal stack frame
+
+x = optional components
+
+EF bit in the PSR
+=================
+
+The EF (enable floating point unit) in the PSR is utilized in this port to
+prevent non-floating point tasks from performing floating point
+operations. This bit is maintained as part of the integer context.
+However, the floating point context is switched BEFORE the integer
+context. Thus the EF bit in place at the time of the FP switch may
+indicate that FP operations are disabled. This occurs on certain task
+switches, when the EF bit will be 0 for the outgoing task and thus a fault
+will be generated on the first FP operation of the FP context save.
+
+The remedy for this is to enable FP access as the first step in both the
+save and restore of the FP context area. This bit will be subsequently
+reloaded by the integer context switch.
+
+Two of the scenarios which demonstrate this problem are outlined below:
+
+1. When the first FP task is switched to. The system tasks are not FP and
+thus would be unable to restore the FP context of the incoming task.
+
+2. On a deferred FP context switch. In this case, the system might switch
+from FP Task A to non-FP Task B and then to FP Task C. In this scenario,
+the floating point state must technically be saved by a non-FP task.
diff --git a/cpukit/score/cpu/sparc/cpu.c b/cpukit/score/cpu/sparc/cpu.c
new file mode 100644
index 0000000000..52ba52f738
--- /dev/null
+++ b/cpukit/score/cpu/sparc/cpu.c
@@ -0,0 +1,333 @@
+/*
+ * SPARC Dependent Source
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/cache.h>
+
+/*
+ * This initializes the set of opcodes placed in each trap
+ * table entry. The routine which installs a handler is responsible
+ * for filling in the fields for the _handler address and the _vector
+ * trap type.
+ *
+ * The constants following this structure are masks for the fields which
+ * must be filled in when the handler is installed.
+ */
+
+const CPU_Trap_table_entry _CPU_Trap_slot_template = {
+ 0xa1480000, /* mov %psr, %l0 */
+ 0x29000000, /* sethi %hi(_handler), %l4 */
+ 0x81c52000, /* jmp %l4 + %lo(_handler) */
+ 0xa6102000 /* mov _vector, %l3 */
+};
+
+/*PAGE
+ *
+ * _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * Output Parameters: NONE
+ *
+ * NOTE: There is no need to save the pointer to the thread dispatch routine.
+ * The SPARC's assembly code can reference it directly with no problems.
+ */
+
+void _CPU_Initialize(void)
+{
+#if (SPARC_HAS_FPU == 1)
+ Context_Control_fp *pointer;
+
+ /*
+ * This seems to be the most appropriate way to obtain an initial
+ * FP context on the SPARC. The NULL fp context is copied it to
+ * the task's FP context during Context_Initialize.
+ */
+
+ pointer = &_CPU_Null_fp_context;
+ _CPU_Context_save_fp( &pointer );
+#endif
+
+ /*
+ * Since no tasks have been created yet and no interrupts have occurred,
+ * there is no way that the currently executing thread can have an
+ * _ISR_Dispatch stack frame on its stack.
+ */
+ _CPU_ISR_Dispatch_disable = 0;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_Get_level
+ *
+ * Input Parameters: NONE
+ *
+ * Output Parameters:
+ * returns the current interrupt level (PIL field of the PSR)
+ */
+
+uint32_t _CPU_ISR_Get_level( void )
+{
+ uint32_t level;
+
+ sparc_get_interrupt_level( level );
+
+ return level;
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs the specified handler as a "raw" non-executive
+ * supported trap handler (a.k.a. interrupt service routine).
+ *
+ * Input Parameters:
+ * vector - trap table entry number plus synchronous
+ * vs. asynchronous information
+ * new_handler - address of the handler to be installed
+ * old_handler - pointer to an address of the handler previously installed
+ *
+ * Output Parameters: NONE
+ * *new_handler - address of the handler previously installed
+ *
+ * NOTE:
+ *
+ * On the SPARC, there are really only 256 vectors. However, the executive
+ * has no easy, fast, reliable way to determine which traps are synchronous
+ * and which are asynchronous. By default, synchronous traps return to the
+ * instruction which caused the interrupt. So if you install a software
+ * trap handler as an executive interrupt handler (which is desirable since
+ * RTEMS takes care of window and register issues), then the executive needs
+ * to know that the return address is to the trap rather than the instruction
+ * following the trap.
+ *
+ * So vectors 0 through 255 are treated as regular asynchronous traps which
+ * provide the "correct" return address. Vectors 256 through 512 are assumed
+ * by the executive to be synchronous and to require that the return address
+ * be fudged.
+ *
+ * If you use this mechanism to install a trap handler which must reexecute
+ * the instruction which caused the trap, then it should be installed as
+ * an asynchronous trap. This will avoid the executive changing the return
+ * address.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ uint32_t real_vector;
+ CPU_Trap_table_entry *tbr;
+ CPU_Trap_table_entry *slot;
+ uint32_t u32_tbr;
+ uint32_t u32_handler;
+
+ /*
+ * Get the "real" trap number for this vector ignoring the synchronous
+ * versus asynchronous indicator included with our vector numbers.
+ */
+
+ real_vector = SPARC_REAL_TRAP_NUMBER( vector );
+
+ /*
+ * Get the current base address of the trap table and calculate a pointer
+ * to the slot we are interested in.
+ */
+
+ sparc_get_tbr( u32_tbr );
+
+ u32_tbr &= 0xfffff000;
+
+ tbr = (CPU_Trap_table_entry *) u32_tbr;
+
+ slot = &tbr[ real_vector ];
+
+ /*
+ * Get the address of the old_handler from the trap table.
+ *
+ * NOTE: The old_handler returned will be bogus if it does not follow
+ * the RTEMS model.
+ */
+
+#define HIGH_BITS_MASK 0xFFFFFC00
+#define HIGH_BITS_SHIFT 10
+#define LOW_BITS_MASK 0x000003FF
+
+ if ( slot->mov_psr_l0 == _CPU_Trap_slot_template.mov_psr_l0 ) {
+ u32_handler =
+ (slot->sethi_of_handler_to_l4 << HIGH_BITS_SHIFT) |
+ (slot->jmp_to_low_of_handler_plus_l4 & LOW_BITS_MASK);
+ *old_handler = (proc_ptr) u32_handler;
+ } else
+ *old_handler = 0;
+
+ /*
+ * Copy the template to the slot and then fix it.
+ */
+
+ *slot = _CPU_Trap_slot_template;
+
+ u32_handler = (uint32_t) new_handler;
+
+ slot->mov_vector_l3 |= vector;
+ slot->sethi_of_handler_to_l4 |=
+ (u32_handler & HIGH_BITS_MASK) >> HIGH_BITS_SHIFT;
+ slot->jmp_to_low_of_handler_plus_l4 |= (u32_handler & LOW_BITS_MASK);
+
+ /* need to flush icache after this !!! */
+
+ rtems_cache_invalidate_entire_instruction();
+
+}
+
+/*PAGE
+ *
+ * _CPU_ISR_install_vector
+ *
+ * This kernel routine installs the RTEMS handler for the
+ * specified vector.
+ *
+ * Input parameters:
+ * vector - interrupt vector number
+ * new_handler - replacement ISR for this vector number
+ * old_handler - pointer to former ISR for this vector number
+ *
+ * Output parameters:
+ * *old_handler - former ISR for this vector number
+ *
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+)
+{
+ uint32_t real_vector;
+ proc_ptr ignored;
+
+ /*
+ * Get the "real" trap number for this vector ignoring the synchronous
+ * versus asynchronous indicator included with our vector numbers.
+ */
+
+ real_vector = SPARC_REAL_TRAP_NUMBER( vector );
+
+ /*
+ * Return the previous ISR handler.
+ */
+
+ *old_handler = _ISR_Vector_table[ real_vector ];
+
+ /*
+ * Install the wrapper so this ISR can be invoked properly.
+ */
+
+ _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
+
+ /*
+ * We put the actual user ISR address in '_ISR_vector_table'. This will
+ * be used by the _ISR_Handler so the user gets control.
+ */
+
+ _ISR_Vector_table[ real_vector ] = new_handler;
+}
+
+/*PAGE
+ *
+ * _CPU_Context_Initialize
+ *
+ * This kernel routine initializes the basic non-FP context area associated
+ * with each thread.
+ *
+ * Input parameters:
+ * the_context - pointer to the context area
+ * stack_base - address of memory for the SPARC
+ * size - size in bytes of the stack area
+ * new_level - interrupt level for this context area
+ * entry_point - the starting execution point for this this context
+ * is_fp - TRUE if this context is associated with an FP thread
+ *
+ * Output parameters: NONE
+ */
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ uint32_t stack_high; /* highest "stack aligned" address */
+ uint32_t tmp_psr;
+
+ /*
+ * On CPUs with stacks which grow down (i.e. SPARC), we build the stack
+ * based on the stack_high address.
+ */
+
+ stack_high = ((uint32_t)(stack_base) + size);
+ stack_high &= ~(CPU_STACK_ALIGNMENT - 1);
+
+ /*
+ * See the README in this directory for a diagram of the stack.
+ */
+
+ the_context->o7 = ((uint32_t) entry_point) - 8;
+ the_context->o6_sp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE;
+ the_context->i6_fp = 0;
+
+ /*
+ * Build the PSR for the task. Most everything can be 0 and the
+ * CWP is corrected during the context switch.
+ *
+ * The EF bit determines if the floating point unit is available.
+ * The FPU is ONLY enabled if the context is associated with an FP task
+ * and this SPARC model has an FPU.
+ */
+
+ sparc_get_psr( tmp_psr );
+ tmp_psr &= ~SPARC_PSR_PIL_MASK;
+ tmp_psr |= (new_level << 8) & SPARC_PSR_PIL_MASK;
+ tmp_psr &= ~SPARC_PSR_EF_MASK; /* disabled by default */
+
+#if (SPARC_HAS_FPU == 1)
+ /*
+ * If this bit is not set, then a task gets a fault when it accesses
+ * a floating point register. This is a nice way to detect floating
+ * point tasks which are not currently declared as such.
+ */
+
+ if ( is_fp )
+ tmp_psr |= SPARC_PSR_EF_MASK;
+#endif
+ the_context->psr = tmp_psr;
+
+ /*
+ * Since THIS thread is being created, there is no way that THIS
+ * thread can have an _ISR_Dispatch stack frame on its stack.
+ */
+ the_context->isr_dispatch_disable = 0;
+}
diff --git a/cpukit/score/cpu/sparc/cpu_asm.S b/cpukit/score/cpu/sparc/cpu_asm.S
new file mode 100644
index 0000000000..fb9835d16a
--- /dev/null
+++ b/cpukit/score/cpu/sparc/cpu_asm.S
@@ -0,0 +1,357 @@
+/* cpu_asm.s
+ *
+ * This file contains the basic algorithms for all assembly code used
+ * in an specific CPU port of RTEMS. These algorithms must be implemented
+ * in assembly language.
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * Ported to ERC32 implementation of the SPARC by On-Line Applications
+ * Research Corporation (OAR) under contract to the European Space
+ * Agency (ESA).
+ *
+ * ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
+ * European Space Agency.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/asm.h>
+#include <rtems/system.h>
+
+#if (SPARC_HAS_FPU == 1)
+
+/*
+ * void _CPU_Context_save_fp(
+ * void **fp_context_ptr
+ * )
+ *
+ * This routine is responsible for saving the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * NOTE: See the README in this directory for information on the
+ * management of the "EF" bit in the PSR.
+ */
+
+ .align 4
+ PUBLIC(_CPU_Context_save_fp)
+SYM(_CPU_Context_save_fp):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE, %sp
+
+ /*
+ * The following enables the floating point unit.
+ */
+
+ mov %psr, %l0
+ sethi %hi(SPARC_PSR_EF_MASK), %l1
+ or %l1, %lo(SPARC_PSR_EF_MASK), %l1
+ or %l0, %l1, %l0
+ mov %l0, %psr ! **** ENABLE FLOAT ACCESS ****
+ nop; nop; nop; ! Need three nops before EF is
+ ld [%i0], %l0 ! active due to pipeline delay!!!
+ std %f0, [%l0 + FO_F1_OFFSET]
+ std %f2, [%l0 + F2_F3_OFFSET]
+ std %f4, [%l0 + F4_F5_OFFSET]
+ std %f6, [%l0 + F6_F7_OFFSET]
+ std %f8, [%l0 + F8_F9_OFFSET]
+ std %f10, [%l0 + F1O_F11_OFFSET]
+ std %f12, [%l0 + F12_F13_OFFSET]
+ std %f14, [%l0 + F14_F15_OFFSET]
+ std %f16, [%l0 + F16_F17_OFFSET]
+ std %f18, [%l0 + F18_F19_OFFSET]
+ std %f20, [%l0 + F2O_F21_OFFSET]
+ std %f22, [%l0 + F22_F23_OFFSET]
+ std %f24, [%l0 + F24_F25_OFFSET]
+ std %f26, [%l0 + F26_F27_OFFSET]
+ std %f28, [%l0 + F28_F29_OFFSET]
+ std %f30, [%l0 + F3O_F31_OFFSET]
+ st %fsr, [%l0 + FSR_OFFSET]
+ ret
+ restore
+
+/*
+ * void _CPU_Context_restore_fp(
+ * void **fp_context_ptr
+ * )
+ *
+ * This routine is responsible for restoring the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ * NOTE: See the README in this directory for information on the
+ * management of the "EF" bit in the PSR.
+ */
+
+ .align 4
+ PUBLIC(_CPU_Context_restore_fp)
+SYM(_CPU_Context_restore_fp):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE , %sp
+
+ /*
+ * The following enables the floating point unit.
+ */
+
+ mov %psr, %l0
+ sethi %hi(SPARC_PSR_EF_MASK), %l1
+ or %l1, %lo(SPARC_PSR_EF_MASK), %l1
+ or %l0, %l1, %l0
+ mov %l0, %psr ! **** ENABLE FLOAT ACCESS ****
+ nop; nop; nop; ! Need three nops before EF is
+ ld [%i0], %l0 ! active due to pipeline delay!!!
+ ldd [%l0 + FO_F1_OFFSET], %f0
+ ldd [%l0 + F2_F3_OFFSET], %f2
+ ldd [%l0 + F4_F5_OFFSET], %f4
+ ldd [%l0 + F6_F7_OFFSET], %f6
+ ldd [%l0 + F8_F9_OFFSET], %f8
+ ldd [%l0 + F1O_F11_OFFSET], %f10
+ ldd [%l0 + F12_F13_OFFSET], %f12
+ ldd [%l0 + F14_F15_OFFSET], %f14
+ ldd [%l0 + F16_F17_OFFSET], %f16
+ ldd [%l0 + F18_F19_OFFSET], %f18
+ ldd [%l0 + F2O_F21_OFFSET], %f20
+ ldd [%l0 + F22_F23_OFFSET], %f22
+ ldd [%l0 + F24_F25_OFFSET], %f24
+ ldd [%l0 + F26_F27_OFFSET], %f26
+ ldd [%l0 + F28_F29_OFFSET], %f28
+ ldd [%l0 + F3O_F31_OFFSET], %f30
+ ld [%l0 + FSR_OFFSET], %fsr
+ ret
+ restore
+
+#endif /* SPARC_HAS_FPU */
+
+/*
+ * void _CPU_Context_switch(
+ * Context_Control *run,
+ * Context_Control *heir
+ * )
+ *
+ * This routine performs a normal non-FP context switch.
+ */
+
+ .align 4
+ PUBLIC(_CPU_Context_switch)
+SYM(_CPU_Context_switch):
+ ! skip g0
+ st %g1, [%o0 + G1_OFFSET] ! save the global registers
+ std %g2, [%o0 + G2_OFFSET]
+ std %g4, [%o0 + G4_OFFSET]
+ std %g6, [%o0 + G6_OFFSET]
+
+ ! load the address of the ISR stack nesting prevention flag
+ sethi %hi(SYM(_CPU_ISR_Dispatch_disable)), %g2
+ ld [%g2 + %lo(SYM(_CPU_ISR_Dispatch_disable))], %g2
+ ! save it a bit later so we do not waste a couple of cycles
+
+ std %l0, [%o0 + L0_OFFSET] ! save the local registers
+ std %l2, [%o0 + L2_OFFSET]
+ std %l4, [%o0 + L4_OFFSET]
+ std %l6, [%o0 + L6_OFFSET]
+
+ ! Now actually save ISR stack nesting prevention flag
+ st %g2, [%o0 + ISR_DISPATCH_DISABLE_STACK_OFFSET]
+
+ std %i0, [%o0 + I0_OFFSET] ! save the input registers
+ std %i2, [%o0 + I2_OFFSET]
+ std %i4, [%o0 + I4_OFFSET]
+ std %i6, [%o0 + I6_FP_OFFSET]
+
+ std %o0, [%o0 + O0_OFFSET] ! save the output registers
+ std %o2, [%o0 + O2_OFFSET]
+ std %o4, [%o0 + O4_OFFSET]
+ std %o6, [%o0 + O6_SP_OFFSET]
+
+ rd %psr, %o2
+ st %o2, [%o0 + PSR_OFFSET] ! save status register
+
+ /*
+ * This is entered from _CPU_Context_restore with:
+ * o1 = context to restore
+ * o2 = psr
+ */
+
+ PUBLIC(_CPU_Context_restore_heir)
+SYM(_CPU_Context_restore_heir):
+ /*
+ * Flush all windows with valid contents except the current one.
+ * In examining the set register windows, one may logically divide
+ * the windows into sets (some of which may be empty) based on their
+ * current status:
+ *
+ * + current (i.e. in use),
+ * + used (i.e. a restore would not trap)
+ * + invalid (i.e. 1 in corresponding bit in WIM)
+ * + unused
+ *
+ * Either the used or unused set of windows may be empty.
+ *
+ * NOTE: We assume only one bit is set in the WIM at a time.
+ *
+ * Given a CWP of 5 and a WIM of 0x1, the registers are divided
+ * into sets as follows:
+ *
+ * + 0 - invalid
+ * + 1-4 - unused
+ * + 5 - current
+ * + 6-7 - used
+ *
+ * In this case, we only would save the used windows -- 6 and 7.
+ *
+ * Traps are disabled for the same logical period as in a
+ * flush all windows trap handler.
+ *
+ * Register Usage while saving the windows:
+ * g1 = current PSR
+ * g2 = current wim
+ * g3 = CWP
+ * g4 = wim scratch
+ * g5 = scratch
+ */
+
+ ld [%o1 + PSR_OFFSET], %g1 ! g1 = saved psr
+
+ and %o2, SPARC_PSR_CWP_MASK, %g3 ! g3 = CWP
+ ! g1 = psr w/o cwp
+ andn %g1, SPARC_PSR_ET_MASK | SPARC_PSR_CWP_MASK, %g1
+ or %g1, %g3, %g1 ! g1 = heirs psr
+ mov %g1, %psr ! restore status register and
+ ! **** DISABLE TRAPS ****
+ mov %wim, %g2 ! g2 = wim
+ mov 1, %g4
+ sll %g4, %g3, %g4 ! g4 = WIM mask for CW invalid
+
+save_frame_loop:
+ sll %g4, 1, %g5 ! rotate the "wim" left 1
+ srl %g4, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g4
+ or %g4, %g5, %g4 ! g4 = wim if we do one restore
+
+ /*
+ * If a restore would not underflow, then continue.
+ */
+
+ andcc %g4, %g2, %g0 ! Any windows to flush?
+ bnz done_flushing ! No, then continue
+ nop
+
+ restore ! back one window
+
+ /*
+ * Now save the window just as if we overflowed to it.
+ */
+
+ std %l0, [%sp + CPU_STACK_FRAME_L0_OFFSET]
+ std %l2, [%sp + CPU_STACK_FRAME_L2_OFFSET]
+ std %l4, [%sp + CPU_STACK_FRAME_L4_OFFSET]
+ std %l6, [%sp + CPU_STACK_FRAME_L6_OFFSET]
+
+ std %i0, [%sp + CPU_STACK_FRAME_I0_OFFSET]
+ std %i2, [%sp + CPU_STACK_FRAME_I2_OFFSET]
+ std %i4, [%sp + CPU_STACK_FRAME_I4_OFFSET]
+ std %i6, [%sp + CPU_STACK_FRAME_I6_FP_OFFSET]
+
+ ba save_frame_loop
+ nop
+
+done_flushing:
+
+ add %g3, 1, %g3 ! calculate desired WIM
+ and %g3, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g3
+ mov 1, %g4
+ sll %g4, %g3, %g4 ! g4 = new WIM
+ mov %g4, %wim
+
+ or %g1, SPARC_PSR_ET_MASK, %g1
+ mov %g1, %psr ! **** ENABLE TRAPS ****
+ ! and restore CWP
+ nop
+ nop
+ nop
+
+ ! skip g0
+ ld [%o1 + G1_OFFSET], %g1 ! restore the global registers
+ ldd [%o1 + G2_OFFSET], %g2
+ ldd [%o1 + G4_OFFSET], %g4
+ ldd [%o1 + G6_OFFSET], %g6
+
+ ! Load thread specific ISR dispatch prevention flag
+ ld [%o1 + ISR_DISPATCH_DISABLE_STACK_OFFSET], %o2
+ sethi %hi(SYM(_CPU_ISR_Dispatch_disable)), %o3
+ ! Store it to memory later to use the cycles
+
+ ldd [%o1 + L0_OFFSET], %l0 ! restore the local registers
+ ldd [%o1 + L2_OFFSET], %l2
+ ldd [%o1 + L4_OFFSET], %l4
+ ldd [%o1 + L6_OFFSET], %l6
+
+ ! Now restore thread specific ISR dispatch prevention flag
+ st %o2,[%o3 + %lo(SYM(_CPU_ISR_Dispatch_disable))]
+
+ ldd [%o1 + I0_OFFSET], %i0 ! restore the output registers
+ ldd [%o1 + I2_OFFSET], %i2
+ ldd [%o1 + I4_OFFSET], %i4
+ ldd [%o1 + I6_FP_OFFSET], %i6
+
+ ldd [%o1 + O2_OFFSET], %o2 ! restore the output registers
+ ldd [%o1 + O4_OFFSET], %o4
+ ldd [%o1 + O6_SP_OFFSET], %o6
+ ! do o0/o1 last to avoid destroying heir context pointer
+ ldd [%o1 + O0_OFFSET], %o0 ! overwrite heir pointer
+
+ jmp %o7 + 8 ! return
+ nop ! delay slot
+
+/*
+ * void _CPU_Context_restore(
+ * Context_Control *new_context
+ * )
+ *
+ * This routine is generally used only to perform restart self.
+ *
+ * NOTE: It is unnecessary to reload some registers.
+ */
+ .align 4
+ PUBLIC(_CPU_Context_restore)
+SYM(_CPU_Context_restore):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE, %sp
+ rd %psr, %o2
+ ba SYM(_CPU_Context_restore_heir)
+ mov %i0, %o1 ! in the delay slot
+ .align 4
+
+#if defined(RTEMS_SMP)
+/*
+ * void _CPU_Context_switch_to_first_task_smp(
+ * Context_Control *new_context
+ * )
+ *
+ * This routine is only used to switch to the first task on a
+ * secondary core in an SMP configuration. We do not need to
+ * flush all the windows and, in fact, this can be dangerous
+ * as they may or may not be initialized properly. So we just
+ * reinitialize the PSR and WIM.
+ */
+ PUBLIC(_CPU_Context_switch_to_first_task_smp)
+SYM(_CPU_Context_switch_to_first_task_smp):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE, %sp
+
+ mov %psr, %g1 ! Initialize WIM
+ add %g1, 1, %g2
+ and %g2, 0x7, %g2
+ set 1, %g3
+ sll %g3, %g2, %g3
+ mov %g3, %wim
+ ba done_flushing
+ mov %i0, %o1 ! in the delay slot
+#endif
+
+/* end of file */
diff --git a/cpukit/score/cpu/sparc/preinstall.am b/cpukit/score/cpu/sparc/preinstall.am
new file mode 100644
index 0000000000..da9dde121f
--- /dev/null
+++ b/cpukit/score/cpu/sparc/preinstall.am
@@ -0,0 +1,41 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/sparc.h: rtems/score/sparc.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/sparc.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/sparc.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/sparc/rtems/asm.h b/cpukit/score/cpu/sparc/rtems/asm.h
new file mode 100644
index 0000000000..1da25f8c26
--- /dev/null
+++ b/cpukit/score/cpu/sparc/rtems/asm.h
@@ -0,0 +1,119 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/cpu.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+/* XXX __USER_LABEL_PREFIX__ and __REGISTER_PREFIX__ do not work on gcc 2.7.0 */
+/* XXX The following ifdef magic fixes the problem but results in a warning */
+/* XXX when compiling assembly code. */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+/*
+ * Entry for traps which jump to a programmer-specified trap handler.
+ */
+
+#define TRAP(_vector, _handler) \
+ mov %psr, %l0 ; \
+ sethi %hi(_handler), %l4 ; \
+ jmp %l4+%lo(_handler); \
+ mov _vector, %l3
+
+/*
+ * Used for the reset trap to avoid a supervisor instruction
+ */
+
+#define RTRAP(_vector, _handler) \
+ mov %g0, %l0 ; \
+ sethi %hi(_handler), %l4 ; \
+ jmp %l4+%lo(_handler); \
+ mov _vector, %l3
+
+#endif
diff --git a/cpukit/score/cpu/sparc/rtems/score/cpu.h b/cpukit/score/cpu/sparc/rtems/score/cpu.h
new file mode 100644
index 0000000000..330f56c6a3
--- /dev/null
+++ b/cpukit/score/cpu/sparc/rtems/score/cpu.h
@@ -0,0 +1,1023 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the port of
+ * the executive to the SPARC processor.
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/sparc.h>
+
+/* conditional compilation parameters */
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH TRUE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * This parameter could go either way on the SPARC. The interrupt flash
+ * code is relatively lengthy given the requirements for nops following
+ * writes to the psr. But if the clock speed were high enough, this would
+ * not represent a great deal of time.
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/*
+ * Does the executive manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * The SPARC does not have a dedicated HW interrupt stack and one has
+ * been implemented in SW.
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * SPARC Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * The SPARC does not have a dedicated HW interrupt stack.
+ */
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Do we allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ */
+
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the FLOATING_POINT task attribute is supported.
+ * If FALSE, then the FLOATING_POINT task attribute is ignored.
+ */
+
+#if ( SPARC_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+/*
+ * Are all tasks FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the FLOATING_POINT task attribute is followed.
+ */
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ */
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ */
+
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * The stack grows to lower addresses on the SPARC.
+ */
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical data structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The SPARC does not appear to have particularly strict alignment
+ * requirements. This value was chosen to take advantages of caches.
+ */
+
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (16)))
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+
+/*
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
+ *
+ * The SPARC has 16 interrupt levels in the PIL field of the PSR.
+ */
+
+#define CPU_MODES_INTERRUPT_MASK 0x0000000F
+
+/*
+ * This structure represents the organization of the minimum stack frame
+ * for the SPARC. More framing information is required in certain situaions
+ * such as when there are a large number of out parameters or when the callee
+ * must save floating point registers.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ uint32_t l0;
+ uint32_t l1;
+ uint32_t l2;
+ uint32_t l3;
+ uint32_t l4;
+ uint32_t l5;
+ uint32_t l6;
+ uint32_t l7;
+ uint32_t i0;
+ uint32_t i1;
+ uint32_t i2;
+ uint32_t i3;
+ uint32_t i4;
+ uint32_t i5;
+ uint32_t i6_fp;
+ uint32_t i7;
+ void *structure_return_address;
+ /*
+ * The following are for the callee to save the register arguments in
+ * should this be necessary.
+ */
+ uint32_t saved_arg0;
+ uint32_t saved_arg1;
+ uint32_t saved_arg2;
+ uint32_t saved_arg3;
+ uint32_t saved_arg4;
+ uint32_t saved_arg5;
+ uint32_t pad0;
+} CPU_Minimum_stack_frame;
+
+#endif /* ASM */
+
+#define CPU_STACK_FRAME_L0_OFFSET 0x00
+#define CPU_STACK_FRAME_L1_OFFSET 0x04
+#define CPU_STACK_FRAME_L2_OFFSET 0x08
+#define CPU_STACK_FRAME_L3_OFFSET 0x0c
+#define CPU_STACK_FRAME_L4_OFFSET 0x10
+#define CPU_STACK_FRAME_L5_OFFSET 0x14
+#define CPU_STACK_FRAME_L6_OFFSET 0x18
+#define CPU_STACK_FRAME_L7_OFFSET 0x1c
+#define CPU_STACK_FRAME_I0_OFFSET 0x20
+#define CPU_STACK_FRAME_I1_OFFSET 0x24
+#define CPU_STACK_FRAME_I2_OFFSET 0x28
+#define CPU_STACK_FRAME_I3_OFFSET 0x2c
+#define CPU_STACK_FRAME_I4_OFFSET 0x30
+#define CPU_STACK_FRAME_I5_OFFSET 0x34
+#define CPU_STACK_FRAME_I6_FP_OFFSET 0x38
+#define CPU_STACK_FRAME_I7_OFFSET 0x3c
+#define CPU_STRUCTURE_RETURN_ADDRESS_OFFSET 0x40
+#define CPU_STACK_FRAME_SAVED_ARG0_OFFSET 0x44
+#define CPU_STACK_FRAME_SAVED_ARG1_OFFSET 0x48
+#define CPU_STACK_FRAME_SAVED_ARG2_OFFSET 0x4c
+#define CPU_STACK_FRAME_SAVED_ARG3_OFFSET 0x50
+#define CPU_STACK_FRAME_SAVED_ARG4_OFFSET 0x54
+#define CPU_STACK_FRAME_SAVED_ARG5_OFFSET 0x58
+#define CPU_STACK_FRAME_PAD0_OFFSET 0x5c
+
+#define CPU_MINIMUM_STACK_FRAME_SIZE 0x60
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On the SPARC, we are relatively conservative in that we save most
+ * of the CPU state in the context area. The ET (enable trap) bit and
+ * the CWP (current window pointer) fields of the PSR are considered
+ * system wide resources and are not maintained on a per-thread basis.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ /*
+ * Using a double g0_g1 will put everything in this structure on a
+ * double word boundary which allows us to use double word loads
+ * and stores safely in the context switch.
+ */
+ double g0_g1;
+ uint32_t g2;
+ uint32_t g3;
+ uint32_t g4;
+ uint32_t g5;
+ uint32_t g6;
+ uint32_t g7;
+
+ uint32_t l0;
+ uint32_t l1;
+ uint32_t l2;
+ uint32_t l3;
+ uint32_t l4;
+ uint32_t l5;
+ uint32_t l6;
+ uint32_t l7;
+
+ uint32_t i0;
+ uint32_t i1;
+ uint32_t i2;
+ uint32_t i3;
+ uint32_t i4;
+ uint32_t i5;
+ uint32_t i6_fp;
+ uint32_t i7;
+
+ uint32_t o0;
+ uint32_t o1;
+ uint32_t o2;
+ uint32_t o3;
+ uint32_t o4;
+ uint32_t o5;
+ uint32_t o6_sp;
+ uint32_t o7;
+
+ uint32_t psr;
+ uint32_t isr_dispatch_disable;
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->o6_sp
+
+#endif /* ASM */
+
+/*
+ * Offsets of fields with Context_Control for assembly routines.
+ */
+
+#define G0_OFFSET 0x00
+#define G1_OFFSET 0x04
+#define G2_OFFSET 0x08
+#define G3_OFFSET 0x0C
+#define G4_OFFSET 0x10
+#define G5_OFFSET 0x14
+#define G6_OFFSET 0x18
+#define G7_OFFSET 0x1C
+
+#define L0_OFFSET 0x20
+#define L1_OFFSET 0x24
+#define L2_OFFSET 0x28
+#define L3_OFFSET 0x2C
+#define L4_OFFSET 0x30
+#define L5_OFFSET 0x34
+#define L6_OFFSET 0x38
+#define L7_OFFSET 0x3C
+
+#define I0_OFFSET 0x40
+#define I1_OFFSET 0x44
+#define I2_OFFSET 0x48
+#define I3_OFFSET 0x4C
+#define I4_OFFSET 0x50
+#define I5_OFFSET 0x54
+#define I6_FP_OFFSET 0x58
+#define I7_OFFSET 0x5C
+
+#define O0_OFFSET 0x60
+#define O1_OFFSET 0x64
+#define O2_OFFSET 0x68
+#define O3_OFFSET 0x6C
+#define O4_OFFSET 0x70
+#define O5_OFFSET 0x74
+#define O6_SP_OFFSET 0x78
+#define O7_OFFSET 0x7C
+
+#define PSR_OFFSET 0x80
+#define ISR_DISPATCH_DISABLE_STACK_OFFSET 0x84
+
+#define CONTEXT_CONTROL_SIZE 0x88
+
+/*
+ * The floating point context area.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ double f0_f1;
+ double f2_f3;
+ double f4_f5;
+ double f6_f7;
+ double f8_f9;
+ double f10_f11;
+ double f12_f13;
+ double f14_f15;
+ double f16_f17;
+ double f18_f19;
+ double f20_f21;
+ double f22_f23;
+ double f24_f25;
+ double f26_f27;
+ double f28_f29;
+ double f30_f31;
+ uint32_t fsr;
+} Context_Control_fp;
+
+#endif /* ASM */
+
+/*
+ * Offsets of fields with Context_Control_fp for assembly routines.
+ */
+
+#define FO_F1_OFFSET 0x00
+#define F2_F3_OFFSET 0x08
+#define F4_F5_OFFSET 0x10
+#define F6_F7_OFFSET 0x18
+#define F8_F9_OFFSET 0x20
+#define F1O_F11_OFFSET 0x28
+#define F12_F13_OFFSET 0x30
+#define F14_F15_OFFSET 0x38
+#define F16_F17_OFFSET 0x40
+#define F18_F19_OFFSET 0x48
+#define F2O_F21_OFFSET 0x50
+#define F22_F23_OFFSET 0x58
+#define F24_F25_OFFSET 0x60
+#define F26_F27_OFFSET 0x68
+#define F28_F29_OFFSET 0x70
+#define F3O_F31_OFFSET 0x78
+#define FSR_OFFSET 0x80
+
+#define CONTEXT_CONTROL_FP_SIZE 0x84
+
+#ifndef ASM
+
+/*
+ * Context saved on stack for an interrupt.
+ *
+ * NOTE: The PSR, PC, and NPC are only saved in this structure for the
+ * benefit of the user's handler.
+ */
+
+typedef struct {
+ CPU_Minimum_stack_frame Stack_frame;
+ uint32_t psr;
+ uint32_t pc;
+ uint32_t npc;
+ uint32_t g1;
+ uint32_t g2;
+ uint32_t g3;
+ uint32_t g4;
+ uint32_t g5;
+ uint32_t g6;
+ uint32_t g7;
+ uint32_t i0;
+ uint32_t i1;
+ uint32_t i2;
+ uint32_t i3;
+ uint32_t i4;
+ uint32_t i5;
+ uint32_t i6_fp;
+ uint32_t i7;
+ uint32_t y;
+ uint32_t tpc;
+} CPU_Interrupt_frame;
+
+#endif /* ASM */
+
+/*
+ * Offsets of fields with CPU_Interrupt_frame for assembly routines.
+ */
+
+#define ISF_STACK_FRAME_OFFSET 0x00
+#define ISF_PSR_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x00
+#define ISF_PC_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x04
+#define ISF_NPC_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x08
+#define ISF_G1_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x0c
+#define ISF_G2_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x10
+#define ISF_G3_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x14
+#define ISF_G4_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x18
+#define ISF_G5_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x1c
+#define ISF_G6_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x20
+#define ISF_G7_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x24
+#define ISF_I0_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x28
+#define ISF_I1_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x2c
+#define ISF_I2_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x30
+#define ISF_I3_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x34
+#define ISF_I4_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x38
+#define ISF_I5_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x3c
+#define ISF_I6_FP_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x40
+#define ISF_I7_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x44
+#define ISF_Y_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x48
+#define ISF_TPC_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x4c
+
+#define CONTEXT_CONTROL_INTERRUPT_FRAME_SIZE CPU_MINIMUM_STACK_FRAME_SIZE + 0x50
+#ifndef ASM
+/*
+ * This variable is contains the initialize context for the FP unit.
+ * It is filled in by _CPU_Initialize and copied into the task's FP
+ * context area during _CPU_Context_Initialize.
+ */
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context CPU_STRUCTURE_ALIGNMENT;
+
+/*
+ * This flag is context switched with each thread. It indicates
+ * that THIS thread has an _ISR_Dispatch stack frame on its stack.
+ * By using this flag, we can avoid nesting more interrupt dispatching
+ * attempts on a previously interrupted thread's stack.
+ */
+
+SCORE_EXTERN volatile uint32_t _CPU_ISR_Dispatch_disable;
+
+/*
+ * The following type defines an entry in the SPARC's trap table.
+ *
+ * NOTE: The instructions chosen are RTEMS dependent although one is
+ * obligated to use two of the four instructions to perform a
+ * long jump. The other instructions load one register with the
+ * trap type (a.k.a. vector) and another with the psr.
+ */
+
+typedef struct {
+ uint32_t mov_psr_l0; /* mov %psr, %l0 */
+ uint32_t sethi_of_handler_to_l4; /* sethi %hi(_handler), %l4 */
+ uint32_t jmp_to_low_of_handler_plus_l4; /* jmp %l4 + %lo(_handler) */
+ uint32_t mov_vector_l3; /* mov _vector, %l3 */
+} CPU_Trap_table_entry;
+
+/*
+ * This is the set of opcodes for the instructions loaded into a trap
+ * table entry. The routine which installs a handler is responsible
+ * for filling in the fields for the _handler address and the _vector
+ * trap type.
+ *
+ * The constants following this structure are masks for the fields which
+ * must be filled in when the handler is installed.
+ */
+
+extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
+
+/*
+ * The size of the floating point context area.
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+#endif
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by the executive.
+ *
+ * On the SPARC, there are really only 256 vectors. However, the executive
+ * has no easy, fast, reliable way to determine which traps are synchronous
+ * and which are asynchronous. By default, synchronous traps return to the
+ * instruction which caused the interrupt. So if you install a software
+ * trap handler as an executive interrupt handler (which is desirable since
+ * RTEMS takes care of window and register issues), then the executive needs
+ * to know that the return address is to the trap rather than the instruction
+ * following the trap.
+ *
+ * So vectors 0 through 255 are treated as regular asynchronous traps which
+ * provide the "correct" return address. Vectors 256 through 512 are assumed
+ * by the executive to be synchronous and to require that the return address
+ * be fudged.
+ *
+ * If you use this mechanism to install a trap handler which must reexecute
+ * the instruction which caused the trap, then it should be installed as
+ * an asynchronous trap. This will avoid the executive changing the return
+ * address.
+ */
+
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 256
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER 511
+
+#define SPARC_SYNCHRONOUS_TRAP_BIT_MASK 0x100
+#define SPARC_ASYNCHRONOUS_TRAP( _trap ) (_trap)
+#define SPARC_SYNCHRONOUS_TRAP( _trap ) ((_trap) + 256 )
+
+#define SPARC_REAL_TRAP_NUMBER( _trap ) ((_trap) % 256)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Should be large enough to run all tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * This appears to be a fairly generous number for the SPARC since
+ * represents a call depth of about 20 routines based on the minimum
+ * stack frame.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE (1024*4)
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * On the SPARC, this is required for double word loads and stores.
+ */
+
+#define CPU_ALIGNMENT 8
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ *
+ * The alignment restrictions for the SPARC are not that strict but this
+ * should unsure that the stack is always sufficiently alignment that the
+ * window overflow, underflow, and flush routines can use double word loads
+ * and stores.
+ */
+
+#define CPU_STACK_ALIGNMENT 16
+
+#ifndef ASM
+
+/*
+ * ISR handler macros
+ */
+
+/*
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ */
+
+#define _CPU_Initialize_vectors()
+
+/*
+ * Disable all interrupts for a critical section. The previous
+ * level is returned in _level.
+ */
+
+#define _CPU_ISR_Disable( _level ) \
+ (_level) = sparc_disable_interrupts()
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of a critical section. The parameter
+ * _level is not modified.
+ */
+
+#define _CPU_ISR_Enable( _level ) \
+ sparc_enable_interrupts( _level )
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+#define _CPU_ISR_Flash( _level ) \
+ sparc_flash_interrupts( _level )
+
+/*
+ * Map interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a straight fashion are undefined.
+ */
+
+#define _CPU_ISR_Set_level( _newlevel ) \
+ sparc_enable_interrupts( _newlevel << 8)
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * NOTE: Implemented as a subroutine for the SPARC port.
+ */
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ uint32_t *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/*
+ * This macro is invoked from _Thread_Handler to do whatever CPU
+ * specific magic is required that must be done in the context of
+ * the thread when it starts.
+ *
+ * On the SPARC, this is setting the frame pointer so GDB is happy.
+ * Make GDB stop unwinding at _Thread_Handler, previous register window
+ * Frame pointer is 0 and calling address must be a function with starting
+ * with a SAVE instruction. If return address is leaf-function (no SAVE)
+ * GDB will not look at prev reg window fp.
+ *
+ * _Thread_Handler is known to start with SAVE.
+ */
+
+#define _CPU_Context_Initialization_at_thread_begin() \
+ do { \
+ __asm__ volatile ("set _Thread_Handler,%%i7\n"::); \
+ } while (0)
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task.
+ *
+ * On the SPARC, this is is relatively painless but requires a small
+ * amount of wrapper code before using the regular restore code in
+ * of the context switch.
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/*
+ * The FP context area for the SPARC is a simple structure and nothing
+ * special is required to find the "starting load point"
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ *
+ * The SPARC allows us to use the simple initialization model
+ * in which an "initial" FP context was saved into _CPU_Null_fp_context
+ * at CPU initialization and it is simply copied into the destination
+ * context.
+ */
+
+#define _CPU_Context_Initialize_fp( _destination ) \
+ do { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ } while (0)
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/*
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ */
+
+#define _CPU_Fatal_halt( _error ) \
+ do { \
+ uint32_t level; \
+ \
+ level = sparc_disable_interrupts(); \
+ __asm__ volatile ( "mov %0, %%g1 " : "=r" (level) : "0" (level) ); \
+ while (1); /* loop forever */ \
+ } while (0)
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/*
+ * The SPARC port uses the generic C algorithm for bitfield scan if the
+ * CPU model does not have a scan instruction.
+ */
+
+#if ( SPARC_HAS_BITSCAN == 0 )
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+#else
+#error "scan instruction not currently supported by RTEMS!!"
+#endif
+
+/* end of Bitfield handler macros */
+
+/* Priority handler handler macros */
+
+/*
+ * The SPARC port uses the generic C algorithm for bitfield scan if the
+ * CPU model does not have a scan instruction.
+ */
+
+#if ( SPARC_HAS_BITSCAN == 1 )
+#error "scan instruction not currently supported by RTEMS!!"
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs new_handler to be directly called from the trap
+ * table.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
+
+/*
+ * _CPU_Thread_Idle_body
+ *
+ * Some SPARC implementations have low power, sleep, or idle modes. This
+ * tries to take advantage of those models.
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner.
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+#if defined(RTEMS_SMP)
+ /*
+ * _CPU_Context_switch_to_first_task_smp
+ *
+ * This routine is only used to switch to the first task on a
+ * secondary core in an SMP configuration. We do not need to
+ * flush all the windows and, in fact, this can be dangerous
+ * as they may or may not be initialized properly.
+ */
+ void _CPU_Context_switch_to_first_task_smp(
+ Context_Control *new_context
+ );
+
+ /* address space 1 is uncacheable */
+ #define SMP_CPU_SWAP( _address, _value, _previous ) \
+ do { \
+ register unsigned int _val = _value; \
+ asm volatile( \
+ "swapa [%2] %3, %0" : \
+ "=r" (_val) : \
+ "0" (_val), \
+ "r" (_address), \
+ "i" (1) \
+ ); \
+ _previous = _val; \
+ } while (0)
+
+#endif
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+
+/*
+ * CPU_swap_u32
+ *
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if you come across a better
+ * way for the SPARC PLEASE use it. The most common way to swap a 32-bit
+ * entity as shown below is not any more efficient on the SPARC.
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * It is not obvious how the SPARC can do significantly better than the
+ * generic code. gcc 2.7.0 only generates about 12 instructions for the
+ * following code at optimization level four (i.e. -O4).
+ */
+
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/sparc/rtems/score/sparc.h b/cpukit/score/cpu/sparc/rtems/score/sparc.h
new file mode 100644
index 0000000000..9aefb20f4a
--- /dev/null
+++ b/cpukit/score/cpu/sparc/rtems/score/sparc.h
@@ -0,0 +1,236 @@
+/**
+ * @file rtems/score/sparc.h
+ */
+
+/*
+ * This include file contains information pertaining to the SPARC
+ * processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SPARC_H
+#define _RTEMS_SCORE_SPARC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the "sparc" family. It does
+ * this by setting variables to indicate which implementation
+ * dependent features are present in a particular member
+ * of the family.
+ *
+ * Currently recognized feature flags:
+ *
+ * + SPARC_HAS_FPU
+ * 0 - no HW FPU
+ * 1 - has HW FPU (assumed to be compatible w/90C602)
+ *
+ * + SPARC_HAS_BITSCAN
+ * 0 - does not have scan instructions
+ * 1 - has scan instruction (not currently implemented)
+ *
+ * + SPARC_NUMBER_OF_REGISTER_WINDOWS
+ * 8 is the most common number supported by SPARC implementations.
+ * SPARC_PSR_CWP_MASK is derived from this value.
+ */
+
+/*
+ * Some higher end SPARCs have a bitscan instructions. It would
+ * be nice to take advantage of them. Right now, there is no
+ * port to a CPU model with this feature and no (untested) code
+ * that is based on this feature flag.
+ */
+
+#define SPARC_HAS_BITSCAN 0
+
+/*
+ * This should be OK until a port to a higher end SPARC processor
+ * is made that has more than 8 register windows. If this cannot
+ * be determined based on multilib settings (v7/v8/v9), then the
+ * cpu_asm.S code that depends on this will have to move to libcpu.
+ */
+
+#define SPARC_NUMBER_OF_REGISTER_WINDOWS 8
+
+/*
+ * This should be determined based on some soft float derived
+ * cpp predefine but gcc does not currently give us that information.
+ */
+
+
+#if defined(_SOFT_FLOAT)
+#define SPARC_HAS_FPU 0
+#else
+#define SPARC_HAS_FPU 1
+#endif
+
+#if SPARC_HAS_FPU
+#define CPU_MODEL_NAME "w/FPU"
+#else
+#define CPU_MODEL_NAME "w/soft-float"
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "SPARC"
+
+/*
+ * Miscellaneous constants
+ */
+
+/*
+ * PSR masks and starting bit positions
+ *
+ * NOTE: Reserved bits are ignored.
+ */
+
+#if (SPARC_NUMBER_OF_REGISTER_WINDOWS == 8)
+#define SPARC_PSR_CWP_MASK 0x07 /* bits 0 - 4 */
+#elif (SPARC_NUMBER_OF_REGISTER_WINDOWS == 16)
+#define SPARC_PSR_CWP_MASK 0x0F /* bits 0 - 4 */
+#elif (SPARC_NUMBER_OF_REGISTER_WINDOWS == 32)
+#define SPARC_PSR_CWP_MASK 0x1F /* bits 0 - 4 */
+#else
+#error "Unsupported number of register windows for this cpu"
+#endif
+
+#define SPARC_PSR_ET_MASK 0x00000020 /* bit 5 */
+#define SPARC_PSR_PS_MASK 0x00000040 /* bit 6 */
+#define SPARC_PSR_S_MASK 0x00000080 /* bit 7 */
+#define SPARC_PSR_PIL_MASK 0x00000F00 /* bits 8 - 11 */
+#define SPARC_PSR_EF_MASK 0x00001000 /* bit 12 */
+#define SPARC_PSR_EC_MASK 0x00002000 /* bit 13 */
+#define SPARC_PSR_ICC_MASK 0x00F00000 /* bits 20 - 23 */
+#define SPARC_PSR_VER_MASK 0x0F000000 /* bits 24 - 27 */
+#define SPARC_PSR_IMPL_MASK 0xF0000000 /* bits 28 - 31 */
+
+#define SPARC_PSR_CWP_BIT_POSITION 0 /* bits 0 - 4 */
+#define SPARC_PSR_ET_BIT_POSITION 5 /* bit 5 */
+#define SPARC_PSR_PS_BIT_POSITION 6 /* bit 6 */
+#define SPARC_PSR_S_BIT_POSITION 7 /* bit 7 */
+#define SPARC_PSR_PIL_BIT_POSITION 8 /* bits 8 - 11 */
+#define SPARC_PSR_EF_BIT_POSITION 12 /* bit 12 */
+#define SPARC_PSR_EC_BIT_POSITION 13 /* bit 13 */
+#define SPARC_PSR_ICC_BIT_POSITION 20 /* bits 20 - 23 */
+#define SPARC_PSR_VER_BIT_POSITION 24 /* bits 24 - 27 */
+#define SPARC_PSR_IMPL_BIT_POSITION 28 /* bits 28 - 31 */
+
+#ifndef ASM
+
+/*
+ * Standard nop
+ */
+
+#define nop() \
+ do { \
+ __asm__ volatile ( "nop" ); \
+ } while ( 0 )
+
+/*
+ * Get and set the PSR
+ */
+
+#define sparc_get_psr( _psr ) \
+ do { \
+ (_psr) = 0; \
+ __asm__ volatile( "rd %%psr, %0" : "=r" (_psr) : "0" (_psr) ); \
+ } while ( 0 )
+
+#define sparc_set_psr( _psr ) \
+ do { \
+ __asm__ volatile ( "mov %0, %%psr " : "=r" ((_psr)) : "0" ((_psr)) ); \
+ nop(); \
+ nop(); \
+ nop(); \
+ } while ( 0 )
+
+/*
+ * Get and set the TBR
+ */
+
+#define sparc_get_tbr( _tbr ) \
+ do { \
+ (_tbr) = 0; /* to avoid unitialized warnings */ \
+ __asm__ volatile( "rd %%tbr, %0" : "=r" (_tbr) : "0" (_tbr) ); \
+ } while ( 0 )
+
+#define sparc_set_tbr( _tbr ) \
+ do { \
+ __asm__ volatile( "wr %0, 0, %%tbr" : "=r" (_tbr) : "0" (_tbr) ); \
+ } while ( 0 )
+
+/*
+ * Get and set the WIM
+ */
+
+#define sparc_get_wim( _wim ) \
+ do { \
+ __asm__ volatile( "rd %%wim, %0" : "=r" (_wim) : "0" (_wim) ); \
+ } while ( 0 )
+
+#define sparc_set_wim( _wim ) \
+ do { \
+ __asm__ volatile( "wr %0, %%wim" : "=r" (_wim) : "0" (_wim) ); \
+ nop(); \
+ nop(); \
+ nop(); \
+ } while ( 0 )
+
+/*
+ * Get and set the Y
+ */
+
+#define sparc_get_y( _y ) \
+ do { \
+ __asm__ volatile( "rd %%y, %0" : "=r" (_y) : "0" (_y) ); \
+ } while ( 0 )
+
+#define sparc_set_y( _y ) \
+ do { \
+ __asm__ volatile( "wr %0, %%y" : "=r" (_y) : "0" (_y) ); \
+ } while ( 0 )
+
+/*
+ * Manipulate the interrupt level in the psr
+ */
+
+uint32_t sparc_disable_interrupts(void);
+void sparc_enable_interrupts(uint32_t);
+
+#define sparc_flash_interrupts( _level ) \
+ do { \
+ register uint32_t _ignored = 0; \
+ \
+ sparc_enable_interrupts( (_level) ); \
+ _ignored = sparc_disable_interrupts(); \
+ } while ( 0 )
+
+#define sparc_get_interrupt_level( _level ) \
+ do { \
+ register uint32_t _psr_level = 0; \
+ \
+ sparc_get_psr( _psr_level ); \
+ (_level) = \
+ (_psr_level & SPARC_PSR_PIL_MASK) >> SPARC_PSR_PIL_BIT_POSITION; \
+ } while ( 0 )
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_SPARC_H */
diff --git a/cpukit/score/cpu/sparc/rtems/score/types.h b/cpukit/score/cpu/sparc/rtems/score/types.h
new file mode 100644
index 0000000000..2e411c87f4
--- /dev/null
+++ b/cpukit/score/cpu/sparc/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the
+ * SPARC processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void sparc_isr;
+typedef void ( *sparc_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/cpu/sparc64/.cvsignore b/cpukit/score/cpu/sparc64/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/score/cpu/sparc64/ChangeLog b/cpukit/score/cpu/sparc64/ChangeLog
new file mode 100644
index 0000000000..ce31be0d58
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/ChangeLog
@@ -0,0 +1,71 @@
+2011-02-11 Ralf Corsépius <ralf.corsepius@rtems.org>
+
+ * rtems/score/cpu.h, rtems/score/sparc64.h:
+ Use "__asm__" instead of "asm" for improved c99-compliance.
+
+2010-11-16 Gedare Bloom <giddyup44@yahoo.com>
+
+ * rtems/score/sparc64.h: Fix typo.
+
+2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * rtems/score/cpu.h: Add RTEMS_COMPILER_NO_RETURN_ATTRIBUTE to
+ _CPU_Context_restore() because it does not return. Telling GCC this
+ avoids generation of dead code.
+
+2010-08-19 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1681/cpukit
+ * rtems/score/cpu.h: With the percpu patch, ASM uses
+ INTERRUPT_STACK_HIGH instead of _CPU_Interrupt_stack_high. The
+ sparc64 was still using the old variable, which was declared in its
+ cpu.h file. This patch comments out the declaration and switch to
+ using INTERRUPT_STACK_HIGH.
+
+2010-07-29 Gedare Bloom <giddyup44@yahoo.com>
+
+ PR 1635/cpukit
+ * rtems/score/types.h: Refactoring of priority handling, to isolate the
+ bitmap implementation of priorities in the supercore so that priority
+ management is a little more modular. This change is in anticipation
+ of scheduler implementations that can select how they manage tracking
+ priority levels / finding the highest priority ready task. Note that
+ most of the changes here are simple renaming, to clarify the use of
+ the bitmap-based priority management.
+
+2010-07-16 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * rtems/score/cpu.h: Include <rtems/score/types.h> first.
+ * rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
+
+2010-06-15 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1561/cpukit
+ * .cvsignore, ChangeLog, Makefile.am, Makefile.in, README, context.S,
+ cpu.c, preinstall.am, rtems/asm.h, rtems/score/cpu.h,
+ rtems/score/sparc64.h, rtems/score/types.h: New files.
+
+2010-05-10 Gedare Bloom <gedare@gwmail.gwu.edu>
+
+ * README: Explain separation of score between here and libcpu.
+
+2010-05-03 Gedare Bloom <gedare@gwmail.gwu.edu>
+
+ * rtems/score/cpu.h, context.S, cpu.c: Remove privileged
+ registers from context.
+
+2010-05-03 Gedare Bloom <gedare@gwmail.gwu.edu>
+
+ * cpu.c: Remove interrupt handling code. Moved to libcpu.
+
+2010-05-03 Gedare Bloom <gedare@gwmail.gwu.edu>
+
+ * context.S: renamed cpu_asm.S to context.S
+
+2010-05-02 Gedare Bloom <gedare@gwmail.gwu.edu>
+
+ * cpu_asm.S: Remove interrupt handling code. Moved to libcpu.
+
+2009-10-19 Eugen Leontie <eugen@gwu.edu>
+
+ Added sparc64 architecture
diff --git a/cpukit/score/cpu/sparc64/Makefile.am b/cpukit/score/cpu/sparc64/Makefile.am
new file mode 100644
index 0000000000..f04c81014b
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/Makefile.am
@@ -0,0 +1,22 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = rtems/asm.h
+
+#include_rtems_sparc64dir = $(includedir)/rtems/sparc64
+#include_rtems_sparc64_HEADERS =
+
+include_rtems_scoredir = $(includedir)/rtems/score
+include_rtems_score_HEADERS = rtems/score/sparc64.h rtems/score/cpu.h \
+ rtems/score/types.h
+
+noinst_LIBRARIES = libscorecpu.a
+libscorecpu_a_SOURCES = context.S cpu.c
+libscorecpu_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/score/cpu/sparc64/README b/cpukit/score/cpu/sparc64/README
new file mode 100644
index 0000000000..9da0c5e0ef
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/README
@@ -0,0 +1,15 @@
+#
+# $Id$
+#
+
+A lot of explanation needed, will do when known.
+
+The score/cpu/sparc64 contains only code that can execute without accessing
+privileged registers or using privileged instructions. This was done because
+the privileged registers differ between the sun4u and sun4v models.
+
+The model specific and privileged code that would normally be found in
+score/cpu/sparc64 resides in libcpu/sparc64/@RTEMS_CPU_MODEL@/score or in
+libcpu/sparc64/shared/score directory. This is primarily the interrupt
+handling code.
+
diff --git a/cpukit/score/cpu/sparc64/context.S b/cpukit/score/cpu/sparc64/context.S
new file mode 100644
index 0000000000..bbf4d4a76e
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/context.S
@@ -0,0 +1,322 @@
+/* context.S
+ *
+ * This file contains the basic algorithms for all assembly code used
+ * in an specific CPU port of RTEMS. These algorithms must be implemented
+ * in assembly language.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * Ported to ERC32 implementation of the SPARC by On-Line Applications
+ * Research Corporation (OAR) under contract to the European Space
+ * Agency (ESA).
+ *
+ * ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
+ * European Space Agency.
+ *
+ * Ported to UltraSPARC T1 Niagara implementation of the SPARC-v9.
+ * Niagara modifications of respective RTEMS file:
+ * COPYRIGHT (c) 2010. Gedare Bloom.
+ *
+ * $Id$
+ */
+
+#include <rtems/asm.h>
+
+
+/*
+ * The assembler needs to be told that we know what to do with
+ * the global registers.
+ */
+.register %g2, #scratch
+.register %g3, #scratch
+.register %g6, #scratch
+.register %g7, #scratch
+
+#if (SPARC_HAS_FPU == 1)
+
+/*
+ * void _CPU_Context_save_fp(
+ * void **fp_context_ptr
+ * )
+ *
+ * This routine is responsible for saving the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ */
+
+ .align 4
+PUBLIC(_CPU_Context_save_fp)
+ SYM(_CPU_Context_save_fp):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE, %sp
+
+ /*
+ * The following enables the floating point unit.
+ */
+
+ sparc64_enable_FPU(%l0)
+
+ /*
+ * Although sun4v supports alternate register names for double-
+ * and quad-word floating point, SPARC v9 only uses f[#]
+ *
+ * Because quad-word fp is not supported by the hardware in
+ * many situations, we stick with double-word fp operations
+ */
+ ldx [%i0], %l0
+ std %f0, [%l0]
+ std %f2, [%l0 + F2_OFFSET]
+ std %f4, [%l0 + F4_OFFSET]
+ std %f6, [%l0 + F6_OFFSET]
+ std %f8, [%l0 + F8_OFFSET]
+ std %f10, [%l0 + F1O_OFFSET]
+ std %f12, [%l0 + F12_OFFSET]
+ std %f14, [%l0 + F14_OFFSET]
+ std %f16, [%l0 + F16_OFFSET]
+ std %f18, [%l0 + F18_OFFSET]
+ std %f20, [%l0 + F2O_OFFSET]
+ std %f22, [%l0 + F22_OFFSET]
+ std %f24, [%l0 + F24_OFFSET]
+ std %f26, [%l0 + F26_OFFSET]
+ std %f28, [%l0 + F28_OFFSET]
+ std %f30, [%l0 + F3O_OFFSET]
+ std %f32, [%l0 + F32_OFFSET]
+ std %f34, [%l0 + F34_OFFSET]
+ std %f36, [%l0 + F36_OFFSET]
+ std %f38, [%l0 + F38_OFFSET]
+ std %f40, [%l0 + F4O_OFFSET]
+ std %f42, [%l0 + F42_OFFSET]
+ std %f44, [%l0 + F44_OFFSET]
+ std %f46, [%l0 + F46_OFFSET]
+ std %f48, [%l0 + F48_OFFSET]
+ std %f50, [%l0 + F5O_OFFSET]
+ std %f52, [%l0 + F52_OFFSET]
+ std %f54, [%l0 + F54_OFFSET]
+ std %f56, [%l0 + F56_OFFSET]
+ std %f58, [%l0 + F58_OFFSET]
+ std %f60, [%l0 + F6O_OFFSET]
+ std %f62, [%l0 + F62_OFFSET]
+ stx %fsr, [%l0 + FSR_OFFSET]
+ ret
+ restore
+
+ /*
+ * void _CPU_Context_restore_fp(
+ * void **fp_context_ptr
+ * )
+ *
+ * This routine is responsible for restoring the FP context
+ * at *fp_context_ptr. If the point to load the FP context
+ * from is changed then the pointer is modified by this routine.
+ *
+ */
+
+ .align 4
+PUBLIC(_CPU_Context_restore_fp)
+ SYM(_CPU_Context_restore_fp):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE , %sp
+
+ /*
+ * The following enables the floating point unit.
+ */
+
+ sparc64_enable_FPU(%l0)
+
+ ldx [%i0], %l0
+ ldd [%l0 + FO_OFFSET], %f0
+ ldd [%l0 + F2_OFFSET], %f2
+ ldd [%l0 + F4_OFFSET], %f4
+ ldd [%l0 + F6_OFFSET], %f6
+ ldd [%l0 + F8_OFFSET], %f8
+ ldd [%l0 + F1O_OFFSET], %f10
+ ldd [%l0 + F12_OFFSET], %f12
+ ldd [%l0 + F14_OFFSET], %f14
+ ldd [%l0 + F16_OFFSET], %f16
+ ldd [%l0 + F18_OFFSET], %f18
+ ldd [%l0 + F2O_OFFSET], %f20
+ ldd [%l0 + F22_OFFSET], %f22
+ ldd [%l0 + F24_OFFSET], %f24
+ ldd [%l0 + F26_OFFSET], %f26
+ ldd [%l0 + F28_OFFSET], %f28
+ ldd [%l0 + F3O_OFFSET], %f30
+ ldd [%l0 + F32_OFFSET], %f32
+ ldd [%l0 + F34_OFFSET], %f34
+ ldd [%l0 + F36_OFFSET], %f36
+ ldd [%l0 + F38_OFFSET], %f38
+ ldd [%l0 + F4O_OFFSET], %f40
+ ldd [%l0 + F42_OFFSET], %f42
+ ldd [%l0 + F44_OFFSET], %f44
+ ldd [%l0 + F46_OFFSET], %f46
+ ldd [%l0 + F48_OFFSET], %f48
+ ldd [%l0 + F5O_OFFSET], %f50
+ ldd [%l0 + F52_OFFSET], %f52
+ ldd [%l0 + F54_OFFSET], %f54
+ ldd [%l0 + F56_OFFSET], %f56
+ ldd [%l0 + F58_OFFSET], %f58
+ ldd [%l0 + F6O_OFFSET], %f60
+ ldd [%l0 + F62_OFFSET], %f62
+ ldx [%l0 + FSR_OFFSET], %fsr
+ ret
+ restore
+
+#endif /* SPARC_HAS_FPU */
+
+ /*
+ * void _CPU_Context_switch(
+ * Context_Control *run,
+ * Context_Control *heir
+ * )
+ *
+ * This routine performs a normal non-FP context switch.
+ */
+
+ .align 4
+PUBLIC(_CPU_Context_switch)
+ SYM(_CPU_Context_switch):
+ ! skip g0
+ stx %g1, [%o0 + G1_OFFSET] ! save the global registers
+ stx %g2, [%o0 + G2_OFFSET]
+ stx %g3, [%o0 + G3_OFFSET]
+ stx %g4, [%o0 + G4_OFFSET]
+ stx %g5, [%o0 + G5_OFFSET]
+ stx %g6, [%o0 + G6_OFFSET]
+ stx %g7, [%o0 + G7_OFFSET]
+
+ ! load the address of the ISR stack nesting prevention flag
+ setx SYM(_CPU_ISR_Dispatch_disable), %g1, %g2
+ lduw [%g2], %g2
+
+ ! save it a bit later so we do not waste a couple of cycles
+
+ stx %l0, [%o0 + L0_OFFSET] ! save the local registers
+ stx %l1, [%o0 + L1_OFFSET]
+ stx %l2, [%o0 + L2_OFFSET]
+ stx %l3, [%o0 + L3_OFFSET]
+ stx %l4, [%o0 + L4_OFFSET]
+ stx %l5, [%o0 + L5_OFFSET]
+ stx %l6, [%o0 + L6_OFFSET]
+ stx %l7, [%o0 + L7_OFFSET]
+
+ ! Now actually save ISR stack nesting prevention flag
+ stuw %g2, [%o0 + ISR_DISPATCH_DISABLE_STACK_OFFSET]
+
+ stx %i0, [%o0 + I0_OFFSET] ! save the input registers
+ stx %i1, [%o0 + I1_OFFSET]
+ stx %i2, [%o0 + I2_OFFSET]
+ stx %i3, [%o0 + I3_OFFSET]
+ stx %i4, [%o0 + I4_OFFSET]
+ stx %i5, [%o0 + I5_OFFSET]
+ stx %i6, [%o0 + I6_FP_OFFSET]
+ stx %i7, [%o0 + I7_OFFSET]
+
+ stx %o0, [%o0 + O0_OFFSET] ! save the output registers
+ stx %o1, [%o0 + O1_OFFSET]
+ stx %o2, [%o0 + O2_OFFSET]
+ stx %o3, [%o0 + O3_OFFSET]
+ stx %o4, [%o0 + O4_OFFSET]
+ stx %o5, [%o0 + O5_OFFSET]
+ stx %o6, [%o0 + O6_SP_OFFSET]
+ stx %o7, [%o0 + O7_OFFSET] ! o7 is the PC
+
+! rdpr %pil, %o2
+! stuw %o2, [%o0 + PIL_OFFSET] ! save pil
+
+! rdpr %pstate, %o2
+! stx %o2, [%o0 + PSTATE_OFFSET] ! save status register
+
+ /*
+ * This is entered from _CPU_Context_restore with:
+ * o1 = context to restore
+! * o2 = pstate
+ *
+ * NOTE: Flushing the register windows is necessary, but it adds
+ * an unpredictable (but bounded) overhead to context switching.
+ */
+
+PUBLIC(_CPU_Context_restore_heir)
+ SYM(_CPU_Context_restore_heir):
+
+ flushw
+
+
+
+ ! skip g0
+ ldx [%o1 + G1_OFFSET], %g1 ! restore the global registers
+ ldx [%o1 + G2_OFFSET], %g2
+ ldx [%o1 + G3_OFFSET], %g3
+ ldx [%o1 + G4_OFFSET], %g4
+ ldx [%o1 + G5_OFFSET], %g5
+ ldx [%o1 + G6_OFFSET], %g6
+ ldx [%o1 + G7_OFFSET], %g7
+
+ ! Load thread specific ISR dispatch prevention flag
+ ldx [%o1 + ISR_DISPATCH_DISABLE_STACK_OFFSET], %o2
+ setx SYM(_CPU_ISR_Dispatch_disable), %o5, %o3
+ ! Store it to memory later to use the cycles
+
+ ldx [%o1 + L0_OFFSET], %l0 ! restore the local registers
+ ldx [%o1 + L1_OFFSET], %l1
+ ldx [%o1 + L2_OFFSET], %l2
+ ldx [%o1 + L3_OFFSET], %l3
+ ldx [%o1 + L4_OFFSET], %l4
+ ldx [%o1 + L5_OFFSET], %l5
+ ldx [%o1 + L6_OFFSET], %l6
+ ldx [%o1 + L7_OFFSET], %l7
+
+ ! Now restore thread specific ISR dispatch prevention flag
+ stuw %o2, [%o3]
+
+ ldx [%o1 + I0_OFFSET], %i0 ! restore the input registers
+ ldx [%o1 + I1_OFFSET], %i1
+ ldx [%o1 + I2_OFFSET], %i2
+ ldx [%o1 + I3_OFFSET], %i3
+ ldx [%o1 + I4_OFFSET], %i4
+ ldx [%o1 + I5_OFFSET], %i5
+ ldx [%o1 + I6_FP_OFFSET], %i6
+ ldx [%o1 + I7_OFFSET], %i7
+
+ ldx [%o1 + O0_OFFSET], %o0
+ ldx [%o1 + O2_OFFSET], %o2 ! restore the output registers
+ ldx [%o1 + O3_OFFSET], %o3
+ ldx [%o1 + O4_OFFSET], %o4
+ ldx [%o1 + O5_OFFSET], %o5
+ ldx [%o1 + O6_SP_OFFSET], %o6
+ ldx [%o1 + O7_OFFSET], %o7 ! PC
+
+ ! on a hunch... we should be able to use some of the %o regs
+! lduw [%o1 + PIL_OFFSET], %o2
+! wrpr %g0, %o2, %pil
+
+! ldx [%o1 + PSTATE_OFFSET], %o2
+
+ ! do o1 last to avoid destroying heir context pointer
+ ldx [%o1 + O1_OFFSET], %o1 ! overwrite heir pointer
+! wrpr %g0, %o2, %pstate
+
+ retl
+ nop
+
+ /*
+ * void _CPU_Context_restore(
+ * Context_Control *new_context
+ * )
+ *
+ * This routine is generally used only to perform restart self.
+ *
+ * NOTE: It is unnecessary to reload some registers.
+ */
+ /* if _CPU_Context_restore_heir does not flushw, then do it here */
+ .align 4
+PUBLIC(_CPU_Context_restore)
+ SYM(_CPU_Context_restore):
+ save %sp, -CPU_MINIMUM_STACK_FRAME_SIZE, %sp
+! rdpr %pstate, %o2
+ ba SYM(_CPU_Context_restore_heir)
+ mov %i0, %o1 ! in the delay slot
+
+/* end of file */
diff --git a/cpukit/score/cpu/sparc64/cpu.c b/cpukit/score/cpu/sparc64/cpu.c
new file mode 100644
index 0000000000..3a415229cc
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/cpu.c
@@ -0,0 +1,116 @@
+/*
+ * SPARC-v9 Dependent Source
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * This file is based on the SPARC cpu.c file. Modifications are made to
+ * provide support for the SPARC-v9.
+ * COPYRIGHT (c) 2010. Gedare Bloom.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <rtems/system.h>
+#include <rtems/asm.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/cache.h>
+
+/*PAGE
+ *
+ * _CPU_Initialize
+ *
+ * This routine performs processor dependent initialization.
+ *
+ * INPUT PARAMETERS: NONE
+ *
+ * Output Parameters: NONE
+ *
+ * NOTE: There is no need to save the pointer to the thread dispatch routine.
+ * The SPARC's assembly code can reference it directly with no problems.
+ */
+
+void _CPU_Initialize(void)
+{
+#if (SPARC_HAS_FPU == 1)
+ Context_Control_fp *pointer;
+
+ /*
+ * This seems to be the most appropriate way to obtain an initial
+ * FP context on the SPARC. The NULL fp context is copied in to
+ * the task's FP context during Context_Initialize_fp.
+ */
+
+ pointer = &_CPU_Null_fp_context;
+ _CPU_Context_save_fp( &pointer );
+
+#endif
+
+ /*
+ * Since no tasks have been created yet and no interrupts have occurred,
+ * there is no way that the currently executing thread can have an
+ * _ISR_Dispatch stack frame on its stack.
+ */
+ _CPU_ISR_Dispatch_disable = 0;
+}
+
+/*PAGE
+ *
+ * _CPU_Context_Initialize
+ *
+ * This kernel routine initializes the basic non-FP context area associated
+ * with each thread.
+ *
+ * Input parameters:
+ * the_context - pointer to the context area
+ * stack_base - address of memory for the SPARC
+ * size - size in bytes of the stack area
+ * new_level - interrupt level for this context area
+ * entry_point - the starting execution point for this this context
+ * is_fp - TRUE if this context is associated with an FP thread
+ *
+ * Output parameters: NONE
+ */
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ void *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+)
+{
+ uint64_t stack_high; /* highest "stack aligned" address */
+ uint32_t the_size;
+
+ /*
+ * On CPUs with stacks which grow down (i.e. SPARC), we build the stack
+ * based on the stack_high address.
+ */
+
+ stack_high = ((uint64_t)(stack_base) + size);
+ stack_high &= ~(CPU_STACK_ALIGNMENT - 1);
+
+ the_size = size & ~(CPU_STACK_ALIGNMENT - 1);
+
+ /*
+ * See the README in this directory for a diagram of the stack.
+ */
+
+ the_context->o7 = ((uint64_t) entry_point) - 8;
+ the_context->o6_sp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE - STACK_BIAS;
+ the_context->i6_fp = 0;
+
+ /* PSTATE used to be built here, but is no longer included in context */
+
+ /*
+ * Since THIS thread is being created, there is no way that THIS
+ * thread can have an _ISR_Dispatch stack frame on its stack.
+ */
+ the_context->isr_dispatch_disable = 0;
+}
diff --git a/cpukit/score/cpu/sparc64/preinstall.am b/cpukit/score/cpu/sparc64/preinstall.am
new file mode 100644
index 0000000000..9c6d5e4296
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/preinstall.am
@@ -0,0 +1,41 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/asm.h: rtems/asm.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/asm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/asm.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/sparc64.h: rtems/score/sparc64.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/sparc64.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/sparc64.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpu.h: rtems/score/cpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/types.h: rtems/score/types.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/types.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/types.h
+
diff --git a/cpukit/score/cpu/sparc64/rtems/asm.h b/cpukit/score/cpu/sparc64/rtems/asm.h
new file mode 100644
index 0000000000..29847ea1d5
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/rtems/asm.h
@@ -0,0 +1,102 @@
+/**
+ * @file rtems/asm.h
+ *
+ * This include file attempts to address the problems
+ * caused by incompatible flavors of assemblers and
+ * toolsets. It primarily addresses variations in the
+ * use of leading underscores on symbols and the requirement
+ * that register names be preceded by a %.
+ */
+
+/*
+ * NOTE: The spacing in the use of these macros
+ * is critical to them working as advertised.
+ *
+ * COPYRIGHT:
+ *
+ * This file is based on similar code found in newlib available
+ * from ftp.cygnus.com. The file which was used had no copyright
+ * notice. This file is freely distributable as long as the source
+ * of the file is noted.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_ASM_H
+#define _RTEMS_ASM_H
+
+/*
+ * Indicate we are in an assembly file and get the basic CPU definitions.
+ */
+
+#ifndef ASM
+#define ASM
+#endif
+#ifndef __ASM__
+#define __ASM__
+#endif
+
+#include <rtems/score/cpuopts.h>
+#include <rtems/score/cpu.h>
+
+/*
+ * Recent versions of GNU cpp define variables which indicate the
+ * need for underscores and percents. If not using GNU cpp or
+ * the version does not support this, then you will obviously
+ * have to define these as appropriate.
+ */
+
+/* XXX __USER_LABEL_PREFIX__ and __REGISTER_PREFIX__ do not work on gcc 2.7.0 */
+/* XXX The following ifdef magic fixes the problem but results in a warning */
+/* XXX when compiling assembly code. */
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__ _
+#endif
+
+#ifndef __REGISTER_PREFIX__
+#define __REGISTER_PREFIX__
+#endif
+
+#include <rtems/concat.h>
+
+/* Use the right prefix for global labels. */
+
+#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+
+/* Use the right prefix for registers. */
+
+#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
+
+/*
+ * define macros for all of the registers on this CPU
+ *
+ * EXAMPLE: #define d0 REG (d0)
+ */
+
+/*
+ * Define macros to handle section beginning and ends.
+ */
+
+
+#define BEGIN_CODE_DCL .text
+#define END_CODE_DCL
+#define BEGIN_DATA_DCL .data
+#define END_DATA_DCL
+#define BEGIN_CODE .text
+#define END_CODE
+#define BEGIN_DATA
+#define END_DATA
+#define BEGIN_BSS
+#define END_BSS
+#define END
+
+/*
+ * Following must be tailor for a particular flavor of the C compiler.
+ * They may need to put underscores in front of the symbols.
+ */
+
+#define PUBLIC(sym) .globl SYM (sym)
+#define EXTERN(sym) .globl SYM (sym)
+
+#endif
diff --git a/cpukit/score/cpu/sparc64/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
new file mode 100644
index 0000000000..3b424f8b74
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
@@ -0,0 +1,1067 @@
+/**
+ * @file rtems/score/cpu.h
+ */
+
+/*
+ * This include file contains information pertaining to the port of
+ * the executive to the SPARC64 processor.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * This file is based on the SPARC cpu.h file. Modifications are made
+ * to support the SPARC64 processor.
+ * COPYRIGHT (c) 2010. Gedare Bloom.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CPU_H
+#define _RTEMS_SCORE_CPU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/types.h>
+#include <rtems/score/sparc64.h>
+
+/* conditional compilation parameters */
+
+/*
+ * Should the calls to _Thread_Enable_dispatch be inlined?
+ *
+ * If TRUE, then they are inlined.
+ * If FALSE, then a subroutine call is made.
+ */
+
+#define CPU_INLINE_ENABLE_DISPATCH TRUE
+
+/*
+ * Should the body of the search loops in _Thread_queue_Enqueue_priority
+ * be unrolled one time? In unrolled each iteration of the loop examines
+ * two "nodes" on the chain being searched. Otherwise, only one node
+ * is examined per iteration.
+ *
+ * If TRUE, then the loops are unrolled.
+ * If FALSE, then the loops are not unrolled.
+ *
+ * This parameter could go either way on the SPARC. The interrupt flash
+ * code is relatively lengthy given the requirements for nops following
+ * writes to the psr. But if the clock speed were high enough, this would
+ * not represent a great deal of time.
+ */
+
+#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
+
+/*
+ * Does the executive manage a dedicated interrupt stack in software?
+ *
+ * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
+ * If FALSE, nothing is done.
+ *
+ * The SPARC does not have a dedicated HW interrupt stack and one has
+ * been implemented in SW.
+ */
+
+#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the CPU follow the simple vectored interrupt model?
+ *
+ * If TRUE, then RTEMS allocates the vector table it internally manages.
+ * If FALSE, then the BSP is assumed to allocate and manage the vector
+ * table
+ *
+ * SPARC Specific Information:
+ *
+ * XXX document implementation including references if appropriate
+ */
+#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
+
+/*
+ * Does this CPU have hardware support for a dedicated interrupt stack?
+ *
+ * If TRUE, then it must be installed during initialization.
+ * If FALSE, then no installation is performed.
+ *
+ * The SPARC does not have a dedicated HW interrupt stack.
+ */
+
+#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
+
+/*
+ * Do we allocate a dedicated interrupt stack in the Interrupt Manager?
+ *
+ * If TRUE, then the memory is allocated during initialization.
+ * If FALSE, then the memory is allocated during initialization.
+ */
+
+#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
+
+/*
+ * Does the RTEMS invoke the user's ISR with the vector number and
+ * a pointer to the saved interrupt frame (1) or just the vector
+ * number (0)?
+ */
+
+#define CPU_ISR_PASSES_FRAME_POINTER 0
+
+/*
+ * Does the CPU have hardware floating point?
+ *
+ * If TRUE, then the FLOATING_POINT task attribute is supported.
+ * If FALSE, then the FLOATING_POINT task attribute is ignored.
+ */
+
+#if ( SPARC_HAS_FPU == 1 )
+#define CPU_HARDWARE_FP TRUE
+#else
+#define CPU_HARDWARE_FP FALSE
+#endif
+#define CPU_SOFTWARE_FP FALSE
+
+/*
+ * Are all tasks FLOATING_POINT tasks implicitly?
+ *
+ * If TRUE, then the FLOATING_POINT task attribute is assumed.
+ * If FALSE, then the FLOATING_POINT task attribute is followed.
+ */
+
+#define CPU_ALL_TASKS_ARE_FP FALSE
+
+/*
+ * Should the IDLE task have a floating point context?
+ *
+ * If TRUE, then the IDLE task is created as a FLOATING_POINT task
+ * and it has a floating point context which is switched in and out.
+ * If FALSE, then the IDLE task does not have a floating point context.
+ */
+
+#define CPU_IDLE_TASK_IS_FP FALSE
+
+/*
+ * Should the saving of the floating point registers be deferred
+ * until a context switch is made to another different floating point
+ * task?
+ *
+ * If TRUE, then the floating point context will not be stored until
+ * necessary. It will remain in the floating point registers and not
+ * disturned until another floating point task is switched to.
+ *
+ * If FALSE, then the floating point context is saved when a floating
+ * point task is switched out and restored when the next floating point
+ * task is restored. The state of the floating point registers between
+ * those two operations is not specified.
+ */
+
+#define CPU_USE_DEFERRED_FP_SWITCH TRUE
+
+/*
+ * Does this port provide a CPU dependent IDLE task implementation?
+ *
+ * If TRUE, then the routine _CPU_Thread_Idle_body
+ * must be provided and is the default IDLE thread body instead of
+ * _CPU_Thread_Idle_body.
+ *
+ * If FALSE, then use the generic IDLE thread body if the BSP does
+ * not provide one.
+ */
+
+#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
+
+/*
+ * Does the stack grow up (toward higher addresses) or down
+ * (toward lower addresses)?
+ *
+ * If TRUE, then the grows upward.
+ * If FALSE, then the grows toward smaller addresses.
+ *
+ * The stack grows to lower addresses on the SPARC.
+ */
+
+#define CPU_STACK_GROWS_UP FALSE
+
+/*
+ * The following is the variable attribute used to force alignment
+ * of critical data structures. On some processors it may make
+ * sense to have these aligned on tighter boundaries than
+ * the minimum requirements of the compiler in order to have as
+ * much of the critical data area as possible in a cache line.
+ *
+ * The SPARC does not appear to have particularly strict alignment
+ * requirements. This value (16) was chosen to take advantages of caches.
+ *
+ * SPARC 64 requirements on floating point alignment is at least 8,
+ * and is 16 if quad-word fp instructions are available (e.g. LDQF).
+ */
+
+#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (16)))
+
+/*
+ * Define what is required to specify how the network to host conversion
+ * routines are handled.
+ */
+
+#define CPU_BIG_ENDIAN TRUE
+#define CPU_LITTLE_ENDIAN FALSE
+
+/*
+ * The following defines the number of bits actually used in the
+ * interrupt field of the task mode. How those bits map to the
+ * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
+ *
+ * The SPARC v9 has 16 interrupt levels in the PIL field of the PSR.
+ */
+
+#define CPU_MODES_INTERRUPT_MASK 0x0000000F
+
+/*
+ * This structure represents the organization of the minimum stack frame
+ * for the SPARC. More framing information is required in certain situaions
+ * such as when there are a large number of out parameters or when the callee
+ * must save floating point registers.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ uint64_t l0;
+ uint64_t l1;
+ uint64_t l2;
+ uint64_t l3;
+ uint64_t l4;
+ uint64_t l5;
+ uint64_t l6;
+ uint64_t l7;
+ uint64_t i0;
+ uint64_t i1;
+ uint64_t i2;
+ uint64_t i3;
+ uint64_t i4;
+ uint64_t i5;
+ uint64_t i6_fp;
+ uint64_t i7;
+ void *structure_return_address;
+ /*
+ * The following are for the callee to save the register arguments in
+ * should this be necessary.
+ */
+ uint64_t saved_arg0;
+ uint64_t saved_arg1;
+ uint64_t saved_arg2;
+ uint64_t saved_arg3;
+ uint64_t saved_arg4;
+ uint64_t saved_arg5;
+ uint64_t pad0;
+} CPU_Minimum_stack_frame;
+
+#endif /* !ASM */
+
+#define CPU_STACK_FRAME_L0_OFFSET 0x00
+#define CPU_STACK_FRAME_L1_OFFSET 0x08
+#define CPU_STACK_FRAME_L2_OFFSET 0x10
+#define CPU_STACK_FRAME_L3_OFFSET 0x18
+#define CPU_STACK_FRAME_L4_OFFSET 0x20
+#define CPU_STACK_FRAME_L5_OFFSET 0x28
+#define CPU_STACK_FRAME_L6_OFFSET 0x30
+#define CPU_STACK_FRAME_L7_OFFSET 0x38
+#define CPU_STACK_FRAME_I0_OFFSET 0x40
+#define CPU_STACK_FRAME_I1_OFFSET 0x48
+#define CPU_STACK_FRAME_I2_OFFSET 0x50
+#define CPU_STACK_FRAME_I3_OFFSET 0x58
+#define CPU_STACK_FRAME_I4_OFFSET 0x60
+#define CPU_STACK_FRAME_I5_OFFSET 0x68
+#define CPU_STACK_FRAME_I6_FP_OFFSET 0x70
+#define CPU_STACK_FRAME_I7_OFFSET 0x78
+#define CPU_STRUCTURE_RETURN_ADDRESS_OFFSET 0x80
+#define CPU_STACK_FRAME_SAVED_ARG0_OFFSET 0x88
+#define CPU_STACK_FRAME_SAVED_ARG1_OFFSET 0x90
+#define CPU_STACK_FRAME_SAVED_ARG2_OFFSET 0x98
+#define CPU_STACK_FRAME_SAVED_ARG3_OFFSET 0xA0
+#define CPU_STACK_FRAME_SAVED_ARG4_OFFSET 0xA8
+#define CPU_STACK_FRAME_SAVED_ARG5_OFFSET 0xB0
+#define CPU_STACK_FRAME_PAD0_OFFSET 0xB8
+
+#define CPU_MINIMUM_STACK_FRAME_SIZE 0xC0
+
+/*
+ * Contexts
+ *
+ * Generally there are 2 types of context to save.
+ * 1. Interrupt registers to save
+ * 2. Task level registers to save
+ *
+ * This means we have the following 3 context items:
+ * 1. task level context stuff:: Context_Control
+ * 2. floating point task stuff:: Context_Control_fp
+ * 3. special interrupt level context :: Context_Control_interrupt
+ *
+ * On the SPARC, we are relatively conservative in that we save most
+ * of the CPU state in the context area. The ET (enable trap) bit and
+ * the CWP (current window pointer) fields of the PSR are considered
+ * system wide resources and are not maintained on a per-thread basis.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ uint64_t g1;
+ uint64_t g2;
+ uint64_t g3;
+ uint64_t g4;
+ uint64_t g5;
+ uint64_t g6;
+ uint64_t g7;
+
+ uint64_t l0;
+ uint64_t l1;
+ uint64_t l2;
+ uint64_t l3;
+ uint64_t l4;
+ uint64_t l5;
+ uint64_t l6;
+ uint64_t l7;
+
+ uint64_t i0;
+ uint64_t i1;
+ uint64_t i2;
+ uint64_t i3;
+ uint64_t i4;
+ uint64_t i5;
+ uint64_t i6_fp;
+ uint64_t i7;
+
+ uint64_t o0;
+ uint64_t o1;
+ uint64_t o2;
+ uint64_t o3;
+ uint64_t o4;
+ uint64_t o5;
+ uint64_t o6_sp;
+ uint64_t o7;
+
+ uint32_t isr_dispatch_disable;
+ uint32_t pad;
+} Context_Control;
+
+#define _CPU_Context_Get_SP( _context ) \
+ (_context)->o6_sp
+
+#endif /* ASM */
+
+/*
+ * Offsets of fields with Context_Control for assembly routines.
+ */
+
+#define G1_OFFSET 0x00
+#define G2_OFFSET 0x08
+#define G3_OFFSET 0x10
+#define G4_OFFSET 0x18
+#define G5_OFFSET 0x20
+#define G6_OFFSET 0x28
+#define G7_OFFSET 0x30
+
+#define L0_OFFSET 0x38
+#define L1_OFFSET 0x40
+#define L2_OFFSET 0x48
+#define L3_OFFSET 0x50
+#define L4_OFFSET 0x58
+#define L5_OFFSET 0x60
+#define L6_OFFSET 0x68
+#define L7_OFFSET 0x70
+
+#define I0_OFFSET 0x78
+#define I1_OFFSET 0x80
+#define I2_OFFSET 0x88
+#define I3_OFFSET 0x90
+#define I4_OFFSET 0x98
+#define I5_OFFSET 0xA0
+#define I6_FP_OFFSET 0xA8
+#define I7_OFFSET 0xB0
+
+#define O0_OFFSET 0xB8
+#define O1_OFFSET 0xC0
+#define O2_OFFSET 0xC8
+#define O3_OFFSET 0xD0
+#define O4_OFFSET 0xD8
+#define O5_OFFSET 0xE0
+#define O6_SP_OFFSET 0xE8
+#define O7_OFFSET 0xF0
+
+#define ISR_DISPATCH_DISABLE_STACK_OFFSET 0xF8
+#define ISR_PAD_OFFSET 0xFC
+
+#define CONTEXT_CONTROL_SIZE 0x100
+
+/*
+ * The floating point context area.
+ */
+
+#ifndef ASM
+
+typedef struct {
+ double f0; /* f0-f1 */
+ double f2; /* f2-f3 */
+ double f4; /* f4-f5 */
+ double f6; /* f6-f7 */
+ double f8; /* f8-f9 */
+ double f10; /* f10-f11 */
+ double f12; /* f12-f13 */
+ double f14; /* f14-f15 */
+ double f16; /* f16-f17 */
+ double f18; /* f18-f19 */
+ double f20; /* f20-f21 */
+ double f22; /* f22-f23 */
+ double f24; /* f24-f25 */
+ double f26; /* f26-f27 */
+ double f28; /* f28-f29 */
+ double f30; /* f30-f31 */
+ double f32;
+ double f34;
+ double f36;
+ double f38;
+ double f40;
+ double f42;
+ double f44;
+ double f46;
+ double f48;
+ double f50;
+ double f52;
+ double f54;
+ double f56;
+ double f58;
+ double f60;
+ double f62;
+ uint64_t fsr;
+} Context_Control_fp;
+
+#endif /* !ASM */
+
+/*
+ * Offsets of fields with Context_Control_fp for assembly routines.
+ */
+
+#define FO_OFFSET 0x00
+#define F2_OFFSET 0x08
+#define F4_OFFSET 0x10
+#define F6_OFFSET 0x18
+#define F8_OFFSET 0x20
+#define F1O_OFFSET 0x28
+#define F12_OFFSET 0x30
+#define F14_OFFSET 0x38
+#define F16_OFFSET 0x40
+#define F18_OFFSET 0x48
+#define F2O_OFFSET 0x50
+#define F22_OFFSET 0x58
+#define F24_OFFSET 0x60
+#define F26_OFFSET 0x68
+#define F28_OFFSET 0x70
+#define F3O_OFFSET 0x78
+#define F32_OFFSET 0x80
+#define F34_OFFSET 0x88
+#define F36_OFFSET 0x90
+#define F38_OFFSET 0x98
+#define F4O_OFFSET 0xA0
+#define F42_OFFSET 0xA8
+#define F44_OFFSET 0xB0
+#define F46_OFFSET 0xB8
+#define F48_OFFSET 0xC0
+#define F5O_OFFSET 0xC8
+#define F52_OFFSET 0xD0
+#define F54_OFFSET 0xD8
+#define F56_OFFSET 0xE0
+#define F58_OFFSET 0xE8
+#define F6O_OFFSET 0xF0
+#define F62_OFFSET 0xF8
+#define FSR_OFFSET 0x100
+
+#define CONTEXT_CONTROL_FP_SIZE 0x108
+
+#ifndef ASM
+
+/*
+ * Context saved on stack for an interrupt.
+ *
+ * NOTE: The tstate, tpc, and tnpc are saved in this structure
+ * to allow resetting the TL while still being able to return
+ * from a trap later. The PIL is saved because
+ * if this is an external interrupt, we will mask lower
+ * priority interrupts until finishing. Even though the y register
+ * is deprecated, gcc still uses it.
+ */
+
+typedef struct {
+ CPU_Minimum_stack_frame Stack_frame;
+ uint64_t tstate;
+ uint64_t tpc;
+ uint64_t tnpc;
+ uint64_t pil;
+ uint64_t y;
+ uint64_t g1;
+ uint64_t g2;
+ uint64_t g3;
+ uint64_t g4;
+ uint64_t g5;
+ uint64_t g6;
+ uint64_t g7;
+ uint64_t o0;
+ uint64_t o1;
+ uint64_t o2;
+ uint64_t o3;
+ uint64_t o4;
+ uint64_t o5;
+ uint64_t o6_sp;
+ uint64_t o7;
+} CPU_Interrupt_frame;
+
+#endif /* ASM */
+
+/*
+ * Offsets of fields with CPU_Interrupt_frame for assembly routines.
+ */
+
+#define ISF_STACK_FRAME_OFFSET 0x00
+#define ISF_TSTATE_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x00
+#define ISF_TPC_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x08
+#define ISF_TNPC_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x10
+#define ISF_PIL_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x18
+#define ISF_Y_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x20
+#define ISF_G1_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x28
+#define ISF_G2_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x30
+#define ISF_G3_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x38
+#define ISF_G4_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x40
+#define ISF_G5_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x48
+#define ISF_G6_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x50
+#define ISF_G7_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x58
+#define ISF_O0_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x60
+#define ISF_O1_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x68
+#define ISF_O2_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x70
+#define ISF_O3_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x78
+#define ISF_O4_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x80
+#define ISF_O5_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x88
+#define ISF_O6_SP_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x90
+#define ISF_O7_OFFSET CPU_MINIMUM_STACK_FRAME_SIZE + 0x98
+#define ISF_TVEC_NUM CPU_MINIMUM_STACK_FRAME_SIZE + 0xA0
+
+#define CONTEXT_CONTROL_INTERRUPT_FRAME_SIZE CPU_MINIMUM_STACK_FRAME_SIZE + 0xA8
+#ifndef ASM
+/*
+ * This variable is contains the initialize context for the FP unit.
+ * It is filled in by _CPU_Initialize and copied into the task's FP
+ * context area during _CPU_Context_Initialize.
+ */
+
+SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context CPU_STRUCTURE_ALIGNMENT;
+
+/*
+ * This stack is allocated by the Interrupt Manager and the switch
+ * is performed in _ISR_Handler. These variables contain pointers
+ * to the lowest and highest addresses in the chunk of memory allocated
+ * for the interrupt stack. Since it is unknown whether the stack
+ * grows up or down (in general), this give the CPU dependent
+ * code the option of picking the version it wants to use. Thus
+ * both must be present if either is.
+ *
+ * The SPARC supports a software based interrupt stack and these
+ * are required.
+ */
+/*
+SCORE_EXTERN void *_CPU_Interrupt_stack_low;
+SCORE_EXTERN void *_CPU_Interrupt_stack_high;
+*/
+/*
+ * This flag is context switched with each thread. It indicates
+ * that THIS thread has an _ISR_Dispatch stack frame on its stack.
+ * By using this flag, we can avoid nesting more interrupt dispatching
+ * attempts on a previously interrupted thread's stack.
+ */
+
+SCORE_EXTERN volatile uint32_t _CPU_ISR_Dispatch_disable;
+
+/*
+ * The following type defines an entry in the SPARC's trap table.
+ *
+ * NOTE: The instructions chosen are RTEMS dependent although one is
+ * obligated to use two of the four instructions to perform a
+ * long jump. The other instructions load one register with the
+ * trap type (a.k.a. vector) and another with the psr.
+ */
+/* For SPARC V9, we must use 6 of these instructions to perform a long
+ * jump, because the _handler value is now 64-bits. We also need to store
+ * temporary values in the global register set at this trap level. Because
+ * the handler runs at TL > 0 with GL > 0, it should be OK to use g2 and g3
+ * to pass parameters to ISR_Handler.
+ *
+ * The instruction sequence is now more like:
+ * rdpr %tstate, %g4
+ * setx _handler, %g2, %g3
+ * jmp %g3+0
+ * mov _vector, %g2
+ */
+typedef struct {
+ uint32_t rdpr_tstate_g4; /* rdpr %tstate, %g4 */
+ uint32_t sethi_of_hh_handler_to_g2; /* sethi %hh(_handler), %g2 */
+ uint32_t or_g2_hm_handler_to_g2; /* or %l3, %hm(_handler), %g2 */
+ uint32_t sllx_g2_by_32_to_g2; /* sllx %g2, 32, %g2 */
+ uint32_t sethi_of_handler_to_g3; /* sethi %hi(_handler), %g3 */
+ uint32_t or_g3_g2_to_g3; /* or %g3, %g2, %g3 */
+ uint32_t jmp_to_low_of_handler_plus_g3; /* jmp %g3 + %lo(_handler) */
+ uint32_t mov_vector_g2; /* mov _vector, %g2 */
+} CPU_Trap_table_entry;
+
+/*
+ * This is the set of opcodes for the instructions loaded into a trap
+ * table entry. The routine which installs a handler is responsible
+ * for filling in the fields for the _handler address and the _vector
+ * trap type.
+ *
+ * The constants following this structure are masks for the fields which
+ * must be filled in when the handler is installed.
+ */
+
+extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
+
+/*
+ * The size of the floating point context area.
+ */
+
+#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
+
+#endif
+
+/*
+ * Amount of extra stack (above minimum stack size) required by
+ * MPCI receive server thread. Remember that in a multiprocessor
+ * system this thread must exist and be able to process all directives.
+ */
+
+#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
+
+/*
+ * This defines the number of entries in the ISR_Vector_table managed
+ * by the executive.
+ *
+ * On the SPARC, there are really only 256 vectors. However, the executive
+ * has no easy, fast, reliable way to determine which traps are synchronous
+ * and which are asynchronous. By default, synchronous traps return to the
+ * instruction which caused the interrupt. So if you install a software
+ * trap handler as an executive interrupt handler (which is desirable since
+ * RTEMS takes care of window and register issues), then the executive needs
+ * to know that the return address is to the trap rather than the instruction
+ * following the trap.
+ *
+ * So vectors 0 through 255 are treated as regular asynchronous traps which
+ * provide the "correct" return address. Vectors 256 through 512 are assumed
+ * by the executive to be synchronous and to require that the return address
+ * be fudged.
+ *
+ * If you use this mechanism to install a trap handler which must reexecute
+ * the instruction which caused the trap, then it should be installed as
+ * an asynchronous trap. This will avoid the executive changing the return
+ * address.
+ */
+/* On SPARC v9, there are 512 vectors. The same philosophy applies to
+ * vector installation and use, we just provide a larger table.
+ */
+#define CPU_INTERRUPT_NUMBER_OF_VECTORS 512
+#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER 1023
+
+#define SPARC_SYNCHRONOUS_TRAP_BIT_MASK 0x200
+#define SPARC_ASYNCHRONOUS_TRAP( _trap ) (_trap)
+#define SPARC_SYNCHRONOUS_TRAP( _trap ) ((_trap) + 512 )
+
+#define SPARC_REAL_TRAP_NUMBER( _trap ) ((_trap) % 512)
+
+/*
+ * This is defined if the port has a special way to report the ISR nesting
+ * level. Most ports maintain the variable _ISR_Nest_level.
+ */
+
+#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
+
+/*
+ * Should be large enough to run all tests. This ensures
+ * that a "reasonable" small application should not have any problems.
+ *
+ * This appears to be a fairly generous number for the SPARC since
+ * represents a call depth of about 20 routines based on the minimum
+ * stack frame.
+ */
+
+#define CPU_STACK_MINIMUM_SIZE (1024*8)
+
+/*
+ * CPU's worst alignment requirement for data types on a byte boundary. This
+ * alignment does not take into account the requirements for the stack.
+ *
+ * On the SPARC, this is required for double word loads and stores.
+ *
+ * Note: quad-word loads/stores need alignment of 16, but currently supported
+ * architectures do not provide HW implemented quad-word operations.
+ */
+
+#define CPU_ALIGNMENT 8
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * heap handler. This alignment requirement may be stricter than that
+ * for the data types alignment specified by CPU_ALIGNMENT. It is
+ * common for the heap to follow the same alignment requirement as
+ * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap,
+ * then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for memory
+ * buffers allocated by the partition manager. This alignment requirement
+ * may be stricter than that for the data types alignment specified by
+ * CPU_ALIGNMENT. It is common for the partition to follow the same
+ * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict
+ * enough for the partition, then this should be set to CPU_ALIGNMENT.
+ *
+ * NOTE: This does not have to be a power of 2. It does have to
+ * be greater or equal to than CPU_ALIGNMENT.
+ */
+
+#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
+
+/*
+ * This number corresponds to the byte alignment requirement for the
+ * stack. This alignment requirement may be stricter than that for the
+ * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT
+ * is strict enough for the stack, then this should be set to 0.
+ *
+ * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
+ *
+ * The alignment restrictions for the SPARC are not that strict but this
+ * should unsure that the stack is always sufficiently alignment that the
+ * window overflow, underflow, and flush routines can use double word loads
+ * and stores.
+ */
+
+#define CPU_STACK_ALIGNMENT 16
+
+#ifndef ASM
+
+/*
+ * ISR handler macros
+ */
+
+/*
+ * Support routine to initialize the RTEMS vector table after it is allocated.
+ */
+
+#define _CPU_Initialize_vectors()
+
+/*
+ * Disable all interrupts for a critical section. The previous
+ * level is returned in _level.
+ */
+
+ #define _CPU_ISR_Disable( _level ) \
+ (_level) = sparc_disable_interrupts()
+
+/*
+ * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
+ * This indicates the end of a critical section. The parameter
+ * _level is not modified.
+ */
+
+#define _CPU_ISR_Enable( _level ) \
+ sparc_enable_interrupts( _level )
+
+/*
+ * This temporarily restores the interrupt to _level before immediately
+ * disabling them again. This is used to divide long critical
+ * sections into two or more parts. The parameter _level is not
+ * modified.
+ */
+
+#define _CPU_ISR_Flash( _level ) \
+ sparc_flash_interrupts( _level )
+
+/*
+ * Map interrupt level in task mode onto the hardware that the CPU
+ * actually provides. Currently, interrupt levels which do not
+ * map onto the CPU in a straight fashion are undefined.
+ */
+
+#define _CPU_ISR_Set_level( _newlevel ) \
+ sparc_enable_interrupts( _newlevel)
+
+uint32_t _CPU_ISR_Get_level( void );
+
+/* end of ISR handler macros */
+
+/* Context handler macros */
+
+/*
+ * Initialize the context to a state suitable for starting a
+ * task after a context restore operation. Generally, this
+ * involves:
+ *
+ * - setting a starting address
+ * - preparing the stack
+ * - preparing the stack and frame pointers
+ * - setting the proper interrupt level in the context
+ * - initializing the floating point context
+ *
+ * NOTE: Implemented as a subroutine for the SPARC port.
+ */
+
+void _CPU_Context_Initialize(
+ Context_Control *the_context,
+ void *stack_base,
+ uint32_t size,
+ uint32_t new_level,
+ void *entry_point,
+ bool is_fp
+);
+
+/*
+ * This macro is invoked from _Thread_Handler to do whatever CPU
+ * specific magic is required that must be done in the context of
+ * the thread when it starts.
+ *
+ * On the SPARC, this is setting the frame pointer so GDB is happy.
+ * Make GDB stop unwinding at _Thread_Handler, previous register window
+ * Frame pointer is 0 and calling address must be a function with starting
+ * with a SAVE instruction. If return address is leaf-function (no SAVE)
+ * GDB will not look at prev reg window fp.
+ *
+ * _Thread_Handler is known to start with SAVE.
+ */
+
+#define _CPU_Context_Initialization_at_thread_begin() \
+ do { \
+ __asm__ volatile ("set _Thread_Handler,%%i7\n"::); \
+ } while (0)
+
+/*
+ * This routine is responsible for somehow restarting the currently
+ * executing task.
+ *
+ * On the SPARC, this is is relatively painless but requires a small
+ * amount of wrapper code before using the regular restore code in
+ * of the context switch.
+ */
+
+#define _CPU_Context_Restart_self( _the_context ) \
+ _CPU_Context_restore( (_the_context) );
+
+/*
+ * The FP context area for the SPARC is a simple structure and nothing
+ * special is required to find the "starting load point"
+ */
+
+#define _CPU_Context_Fp_start( _base, _offset ) \
+ ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
+
+/*
+ * This routine initializes the FP context area passed to it to.
+ *
+ * The SPARC allows us to use the simple initialization model
+ * in which an "initial" FP context was saved into _CPU_Null_fp_context
+ * at CPU initialization and it is simply copied into the destination
+ * context.
+ */
+
+#define _CPU_Context_Initialize_fp( _destination ) \
+ do { \
+ *(*(_destination)) = _CPU_Null_fp_context; \
+ } while (0)
+
+/* end of Context handler macros */
+
+/* Fatal Error manager macros */
+
+/*
+ * This routine copies _error into a known place -- typically a stack
+ * location or a register, optionally disables interrupts, and
+ * halts/stops the CPU.
+ */
+
+#define _CPU_Fatal_halt( _error ) \
+ do { \
+ uint32_t level; \
+ \
+ level = sparc_disable_interrupts(); \
+ __asm__ volatile ( "mov %0, %%g1 " : "=r" (level) : "0" (level) ); \
+ while (1); /* loop forever */ \
+ } while (0)
+
+/* end of Fatal Error manager macros */
+
+/* Bitfield handler macros */
+
+/*
+ * The SPARC port uses the generic C algorithm for bitfield scan if the
+ * CPU model does not have a scan instruction.
+ */
+
+#if ( SPARC_HAS_BITSCAN == 0 )
+#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
+#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
+#else
+#error "scan instruction not currently supported by RTEMS!!"
+#endif
+
+/* end of Bitfield handler macros */
+
+/* Priority handler handler macros */
+
+/*
+ * The SPARC port uses the generic C algorithm for bitfield scan if the
+ * CPU model does not have a scan instruction.
+ */
+
+#if ( SPARC_HAS_BITSCAN == 1 )
+#error "scan instruction not currently supported by RTEMS!!"
+#endif
+
+/* end of Priority handler macros */
+
+/* functions */
+
+/*
+ * _CPU_Initialize
+ *
+ * This routine performs CPU dependent initialization.
+ */
+
+void _CPU_Initialize(void);
+
+/*
+ * _CPU_ISR_install_raw_handler
+ *
+ * This routine installs new_handler to be directly called from the trap
+ * table.
+ */
+
+void _CPU_ISR_install_raw_handler(
+ uint32_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+/*
+ * _CPU_ISR_install_vector
+ *
+ * This routine installs an interrupt vector.
+ */
+
+void _CPU_ISR_install_vector(
+ uint64_t vector,
+ proc_ptr new_handler,
+ proc_ptr *old_handler
+);
+
+#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
+
+/*
+ * _CPU_Thread_Idle_body
+ *
+ * Some SPARC implementations have low power, sleep, or idle modes. This
+ * tries to take advantage of those models.
+ */
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored );
+
+#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
+
+/*
+ * _CPU_Context_switch
+ *
+ * This routine switches from the run context to the heir context.
+ */
+
+void _CPU_Context_switch(
+ Context_Control *run,
+ Context_Control *heir
+);
+
+/*
+ * _CPU_Context_restore
+ *
+ * This routine is generally used only to restart self in an
+ * efficient manner.
+ */
+
+void _CPU_Context_restore(
+ Context_Control *new_context
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+/*
+ * _CPU_Context_save_fp
+ *
+ * This routine saves the floating point context passed to it.
+ */
+
+void _CPU_Context_save_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * _CPU_Context_restore_fp
+ *
+ * This routine restores the floating point context passed to it.
+ */
+
+void _CPU_Context_restore_fp(
+ Context_Control_fp **fp_context_ptr
+);
+
+/*
+ * CPU_swap_u32
+ *
+ * The following routine swaps the endian format of an unsigned int.
+ * It must be static because it is referenced indirectly.
+ *
+ * This version will work on any processor, but if you come across a better
+ * way for the SPARC PLEASE use it. The most common way to swap a 32-bit
+ * entity as shown below is not any more efficient on the SPARC.
+ *
+ * swap least significant two bytes with 16-bit rotate
+ * swap upper and lower 16-bits
+ * swap most significant two bytes with 16-bit rotate
+ *
+ * It is not obvious how the SPARC can do significantly better than the
+ * generic code. gcc 2.7.0 only generates about 12 instructions for the
+ * following code at optimization level four (i.e. -O4).
+ */
+
+static inline uint32_t CPU_swap_u32(
+ uint32_t value
+)
+{
+ uint32_t byte1, byte2, byte3, byte4, swapped;
+
+ byte4 = (value >> 24) & 0xff;
+ byte3 = (value >> 16) & 0xff;
+ byte2 = (value >> 8) & 0xff;
+ byte1 = value & 0xff;
+
+ swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+ return( swapped );
+}
+
+#define CPU_swap_u16( value ) \
+ (((value&0xff) << 8) | ((value >> 8)&0xff))
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/sparc64/rtems/score/sparc64.h b/cpukit/score/cpu/sparc64/rtems/score/sparc64.h
new file mode 100644
index 0000000000..41862c2362
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/rtems/score/sparc64.h
@@ -0,0 +1,341 @@
+/**
+ * @file rtems/score/sparc64.h
+ */
+
+/*
+ * This include file contains information pertaining to the SPARC
+ * processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * This file is based on the SPARC sparc.h file. Modifications are made
+ * to support the SPARC64 processor.
+ * COPYRIGHT (c) 2010. Gedare Bloom.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SPARC_H
+#define _RTEMS_SCORE_SPARC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file contains the information required to build
+ * RTEMS for a particular member of the "sparc" family. It does
+ * this by setting variables to indicate which implementation
+ * dependent features are present in a particular member
+ * of the family.
+ *
+ * Currently recognized feature flags:
+ *
+ * + SPARC_HAS_FPU
+ * 0 - no HW FPU
+ * 1 - has HW FPU (assumed to be compatible w/90C602)
+ *
+ * + SPARC_HAS_BITSCAN
+ * 0 - does not have scan instructions
+ * 1 - has scan instruction (not currently implemented)
+ *
+ * + SPARC_NUMBER_OF_REGISTER_WINDOWS
+ * 8 is the most common number supported by SPARC implementations.
+ * SPARC_PSR_CWP_MASK is derived from this value.
+ */
+
+/*
+ * Some higher end SPARCs have a bitscan instructions. It would
+ * be nice to take advantage of them. Right now, there is no
+ * port to a CPU model with this feature and no (untested) code
+ * that is based on this feature flag.
+ */
+
+#define SPARC_HAS_BITSCAN 0
+
+/*
+ * This should be OK until a port to a higher end SPARC processor
+ * is made that has more than 8 register windows. If this cannot
+ * be determined based on multilib settings (v7/v8/v9), then the
+ * cpu_asm.S code that depends on this will have to move to libcpu.
+ *
+ * SPARC v9 supports from 3 to 32 register windows.
+ * N_REG_WINDOWS = 8 on UltraSPARC T1 (impl. dep. #2-V8).
+ */
+
+#define SPARC_NUMBER_OF_REGISTER_WINDOWS 8
+
+/*
+ * This should be determined based on some soft float derived
+ * cpp predefine but gcc does not currently give us that information.
+ */
+
+
+#if defined(_SOFT_FLOAT)
+#define SPARC_HAS_FPU 0
+#else
+#define SPARC_HAS_FPU 1
+#endif
+
+#if SPARC_HAS_FPU
+#define CPU_MODEL_NAME "w/FPU"
+#else
+#define CPU_MODEL_NAME "w/soft-float"
+#endif
+
+/*
+ * Define the name of the CPU family.
+ */
+
+#define CPU_NAME "SPARC"
+
+/*
+ * Miscellaneous constants
+ */
+
+/*
+ * The PSR is deprecated and deleted.
+ *
+ * The following registers represent fields of the PSR:
+ * PIL - Processor Interrupt Level register
+ * CWP - Current Window Pointer register
+ * VER - Version register
+ * CCR - Condition Codes Register
+ * PSTATE - Processor State register
+ */
+
+/*
+ * PSTATE masks and starting bit positions
+ *
+ * NOTE: Reserved bits are ignored.
+ */
+
+#define SPARC_PSTATE_AG_MASK 0x00000001 /* bit 0 */
+#define SPARC_PSTATE_IE_MASK 0x00000002 /* bit 1 */
+#define SPARC_PSTATE_PRIV_MASK 0x00000004 /* bit 2 */
+#define SPARC_PSTATE_AM_MASK 0x00000008 /* bit 3 */
+#define SPARC_PSTATE_PEF_MASK 0x00000010 /* bit 4 */
+#define SPARC_PSTATE_MM_MASK 0x00000040 /* bit 6 */
+#define SPARC_PSTATE_TLE_MASK 0x00000100 /* bit 8 */
+#define SPARC_PSTATE_CLE_MASK 0x00000200 /* bit 9 */
+
+#define SPARC_PSTATE_AG_BIT_POSITION 0 /* bit 0 */
+#define SPARC_PSTATE_IE_BIT_POSITION 1 /* bit 1 */
+#define SPARC_PSTATE_PRIV_BIT_POSITION 2 /* bit 2 */
+#define SPARC_PSTATE_AM_BIT_POSITION 3 /* bit 3 */
+#define SPARC_PSTATE_PEF_BIT_POSITION 4 /* bit 4 */
+#define SPARC_PSTATE_MM_BIT_POSITION 6 /* bit 6 */
+#define SPARC_PSTATE_TLE_BIT_POSITION 8 /* bit 8 */
+#define SPARC_PSTATE_CLE_BIT_POSITION 9 /* bit 9 */
+
+#define SPARC_FPRS_FEF_MASK 0x0100 /* bit 2 */
+#define SPARC_FPRS_FEF_BIT_POSITION 2 /* bit 2 */
+
+#define SPARC_TSTATE_IE_MASK 0x00000200 /* bit 9 */
+
+#define SPARC_SOFTINT_TM_MASK 0x00000001 /* bit 0 */
+#define SPARC_SOFTINT_SM_MASK 0x00010000 /* bit 16 */
+#define SPARC_SOFTINT_TM_BIT_POSITION 1 /* bit 0 */
+#define SPARC_SOFTINT_SM_BIT_POSITION 17 /* bit 16 */
+
+#define STACK_BIAS (2047)
+
+#ifdef ASM
+
+/*
+ * To enable the FPU we need to set both PSTATE.pef and FPRS.fef
+ */
+
+#define sparc64_enable_FPU(rtmp1) \
+ rdpr %pstate, rtmp1; \
+ or rtmp1, SPARC_PSTATE_PEF_MASK, rtmp1; \
+ wrpr %g0, rtmp1, %pstate; \
+ rd %fprs, rtmp1; \
+ or rtmp1, SPARC_FPRS_FEF_MASK, rtmp1; \
+ wr %g0, rtmp1, %fprs
+
+
+#endif
+
+#ifndef ASM
+
+/*
+ * Standard nop
+ */
+
+#define nop() \
+ do { \
+ __asm__ volatile ( "nop" ); \
+ } while ( 0 )
+
+/*
+ * Get and set the pstate
+ */
+
+#define sparc64_get_pstate( _pstate ) \
+ do { \
+ (_pstate) = 0; \
+ __asm__ volatile( "rdpr %%pstate, %0" : "=r" (_pstate) : "0" (_pstate) ); \
+ } while ( 0 )
+
+#define sparc64_set_pstate( _pstate ) \
+ do { \
+ __asm__ volatile ( \
+ "wrpr %%g0, %0, %%pstate " : "=r" ((_pstate)) : "0" ((_pstate)) ); \
+ } while ( 0 )
+
+/*
+ * Get and set the PIL
+ */
+
+#define sparc64_get_pil( _pil ) \
+ do { \
+ (_pil) = 0; \
+ __asm__ volatile( "rdpr %%pil, %0" : "=r" (_pil) : "0" (_pil) ); \
+ } while ( 0 )
+
+#define sparc64_set_pil( _pil ) \
+ do { \
+ __asm__ volatile ( "wrpr %%g0, %0, %%pil " : "=r" ((_pil)) : "0" ((_pil)) ); \
+ } while ( 0 )
+
+
+/*
+ * Get and set the TBA
+ */
+
+#define sparc64_get_tba( _tba ) \
+ do { \
+ (_tba) = 0; /* to avoid unitialized warnings */ \
+ __asm__ volatile( "rdpr %%tba, %0" : "=r" (_tba) : "0" (_tba) ); \
+ } while ( 0 )
+
+#define sparc64_set_tba( _tba ) \
+ do { \
+ __asm__ volatile( "wrpr %%g0, %0, %%tba" : "=r" (_tba) : "0" (_tba) ); \
+ } while ( 0 )
+
+/*
+ * Get and set the TL (trap level)
+ */
+
+#define sparc64_get_tl( _tl ) \
+ do { \
+ (_tl) = 0; /* to avoid unitialized warnings */ \
+ __asm__ volatile( "rdpr %%tl, %0" : "=r" (_tl) : "0" (_tl) ); \
+ } while ( 0 )
+
+#define sparc64_set_tl( _tl ) \
+ do { \
+ __asm__ volatile( "wrpr %%g0, %0, %%tl" : "=r" (_tl) : "0" (_tl) ); \
+ } while ( 0 )
+
+
+/*
+ * read the stick register
+ *
+ * Note:
+ * stick asr=24, mnemonic=stick
+ * Note: stick does not appear to be a valid ASR for US3, although it is
+ * implemented in US3i.
+ */
+#define sparc64_read_stick( _stick ) \
+ do { \
+ (_stick) = 0; \
+ __asm__ volatile( "rd %%stick, %0" : "=r" (_stick) : "0" (_stick) ); \
+ } while ( 0 )
+
+/*
+ * write the stick_cmpr register
+ *
+ * Note:
+ * stick_cmpr asr=25, mnemonic=stick_cmpr
+ * Note: stick_cmpr does not appear to be a valid ASR for US3, although it is
+ * implemented in US3i.
+ */
+#define sparc64_write_stick_cmpr( _stick_cmpr ) \
+ do { \
+ __asm__ volatile( "wr %%g0, %0, %%stick_cmpr" : "=r" (_stick_cmpr) \
+ : "0" (_stick_cmpr) ); \
+ } while ( 0 )
+
+/*
+ * read the Tick register
+ */
+#define sparc64_read_tick( _tick ) \
+ do { \
+ (_tick) = 0; \
+ __asm__ volatile( "rd %%tick, %0" : "=r" (_tick) : "0" (_tick) ); \
+ } while ( 0 )
+
+/*
+ * write the tick_cmpr register
+ */
+#define sparc64_write_tick_cmpr( _tick_cmpr ) \
+ do { \
+ __asm__ volatile( "wr %%g0, %0, %%tick_cmpr" : "=r" (_tick_cmpr) \
+ : "0" (_tick_cmpr) ); \
+ } while ( 0 )
+
+/*
+ * Clear the softint register.
+ *
+ * sun4u and sun4v: softint_clr asr = 21, with mnemonic clear_softint
+ */
+#define sparc64_clear_interrupt_bits( _bit_mask ) \
+ do { \
+ __asm__ volatile( "wr %%g0, %0, %%clear_softint" : "=r" (_bit_mask) \
+ : "0" (_bit_mask)); \
+ } while ( 0 )
+
+/************* DEPRECATED ****************/
+/* Note: Although the y register is deprecated, gcc still uses it */
+/*
+ * Get and set the Y
+ */
+
+#define sparc_get_y( _y ) \
+ do { \
+ __asm__ volatile( "rd %%y, %0" : "=r" (_y) : "0" (_y) ); \
+ } while ( 0 )
+
+#define sparc_set_y( _y ) \
+ do { \
+ __asm__ volatile( "wr %0, %%y" : "=r" (_y) : "0" (_y) ); \
+ } while ( 0 )
+
+/************* /DEPRECATED ****************/
+
+/*
+ * Manipulate the interrupt level in the pstate
+ */
+
+uint32_t sparc_disable_interrupts(void);
+void sparc_enable_interrupts(uint32_t);
+
+#define sparc_flash_interrupts( _level ) \
+ do { \
+ register uint32_t _ignored = 0; \
+ \
+ sparc_enable_interrupts( (_level) ); \
+ _ignored = sparc_disable_interrupts(); \
+ } while ( 0 )
+
+#define sparc64_get_interrupt_level( _level ) \
+ do { \
+ _level = 0; \
+ sparc64_get_pil( _level ); \
+ } while ( 0 )
+
+#endif /* !ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_SCORE_SPARC_H */
diff --git a/cpukit/score/cpu/sparc64/rtems/score/types.h b/cpukit/score/cpu/sparc64/rtems/score/types.h
new file mode 100644
index 0000000000..92c67cdf61
--- /dev/null
+++ b/cpukit/score/cpu/sparc64/rtems/score/types.h
@@ -0,0 +1,44 @@
+/**
+ * @file rtems/score/types.h
+ */
+
+/*
+ * This include file contains type definitions pertaining to the
+ * SPARC-v9 processor family.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TYPES_H
+#define _RTEMS_SCORE_TYPES_H
+
+#include <rtems/score/basedefs.h>
+
+#ifndef ASM
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This section defines the basic types for this processor.
+ */
+
+typedef uint16_t Priority_bit_map_Control;
+typedef void sparc_isr;
+typedef void ( *sparc_isr_entry )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !ASM */
+
+#endif
diff --git a/cpukit/score/include/rtems/bspsmp.h b/cpukit/score/include/rtems/bspsmp.h
new file mode 100644
index 0000000000..26da0a7614
--- /dev/null
+++ b/cpukit/score/include/rtems/bspsmp.h
@@ -0,0 +1,233 @@
+/**
+ * @file rtems/bspsmp.h
+ *
+ * This include file defines the interface between RTEMS and an
+ * SMP aware BSP. These methods will only be used when RTEMS
+ * is configured with SMP support enabled.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_BSPSMP_H
+#define _RTEMS_BSPSMP_H
+
+#if defined (RTEMS_SMP)
+#include <rtems/score/percpu.h>
+
+/**
+ * @defgroup RTEMS BSP SMP Interface
+ *
+ * This defines the interface between RTEMS and the BSP for
+ * SMP support. The interface uses the term primary
+ * to refer to the "boot" processor and secondary to refer
+ * to the "application" processors. Different architectures
+ * use different terminology.
+ *
+ * It is assumed that when the processor is reset and thus
+ * when RTEMS is initialized, that the primary processor is
+ * the only one executing. The others are assumed to be in
+ * a quiescent or reset state awaiting a command to come online.
+ */
+
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This defines the bit which indicates the interprocessor interrupt
+ * has been requested so that RTEMS will reschedule on this CPU
+ * because the currently executing thread needs to be switched out.
+ */
+#define RTEMS_BSP_SMP_CONTEXT_SWITCH_NECESSARY 0x01
+
+/**
+ * This defines the bit which indicates the interprocessor interrupt
+ * has been requested so that RTEMS will reschedule on this CPU
+ * because the currently executing thread has been sent a signal.
+ */
+#define RTEMS_BSP_SMP_SIGNAL_TO_SELF 0x02
+
+/**
+ * This defines the bit which indicates the interprocessor interrupt
+ * has been requested so that this CPU will be shutdown. This is done
+ * as part of rtems_executive_shutdown().
+ */
+#define RTEMS_BSP_SMP_SHUTDOWN 0x04
+
+/**
+ * This defines the bit which indicates the interprocessor interrupt
+ * has been requested that the receiving CPU needs to perform a context
+ * switch to the first task.
+ */
+#define RTEMS_BSP_SMP_FIRST_TASK 0x08
+
+#ifndef ASM
+/**
+ * @brief Number of CPUs in SMP System
+ *
+ * This variable is set during the SMP initialization sequence to
+ * indicate the number of CPUs in this system.
+ */
+SCORE_EXTERN uint32_t _SMP_Processor_count;
+
+/**
+ * @brief Maximum Number of CPUs in SMP System
+ *
+ * This variable is set during the SMP initialization sequence to
+ * indicate the Maximum number of CPUs in this system.
+ */
+extern uint32_t rtems_smp_maximum_processors;
+
+/**
+ * @brief Initialize Secondary CPUs
+ *
+ * This method is invoked by RTEMS during initialization to bring the
+ * secondary CPUs out of reset.
+ *
+ * @param [in] maximum is the maximum number of CPU cores that RTEMS
+ * can handle
+ *
+ * @return This method returns the number of cores available in the
+ * system.
+ */
+int bsp_smp_initialize(
+ int maximum
+);
+
+/**
+ * @brief Obtain Current CPU Index
+ *
+ * This method is invoked by RTEMS when it needs to know the index
+ * of the CPU it is executing on.
+ *
+ * @return This method returns the current CPU index.
+ */
+int bsp_smp_processor_id(void) RTEMS_COMPILER_PURE_ATTRIBUTE;
+
+/**
+ * @brief Make Request of Another CPU
+ *
+ * This method is invoked by RTEMS when it needs to make a request
+ * of another CPU. It should be implemented using some type of
+ * interprocessor interrupt.
+ *
+ * @param [in] cpu is the target CPU for this request.
+ * @param [in] message is message to send
+ */
+void bsp_smp_send_message(
+ int cpu,
+ uint32_t message
+);
+
+/**
+ * @brief Make Request of Others CPUs
+ *
+ * This method is invoked by RTEMS when it needs to make a request
+ * of the other CPUs. It should be implemented using some type of
+ * interprocessor interrupt. CPUs not including the originating
+ * CPU should receive the message.
+ *
+ * @param [in] message is message to send
+ */
+void bsp_smp_broadcast_message(
+ uint32_t message
+);
+
+/**
+ * @brief Generate a Interprocessor Broadcast Interrupt
+ *
+ * This method is invoked when RTEMS wants to let all of the other
+ * CPUs know that it has sent them message. CPUs not including
+ * the originating CPU should receive the interrupt.
+
+ *
+ * @note On CPUs without the capability to generate a broadcast
+ * to all other CPUs interrupt, this can be implemented by
+ * a loop of sending interrupts to specific CPUs.
+ */
+void bsp_smp_broadcast_interrupt(void);
+
+/**
+ * @brief Generate a Interprocessor Interrupt
+ *
+ * This method is invoked by RTEMS to let @a cpu know that it
+ * has sent it a message.
+ *
+ * @param [in] cpu is the recipient CPU
+ */
+void bsp_smp_interrupt_cpu(
+ int cpu
+);
+
+/**
+ * @brief Obtain CPU Core Number
+ *
+ * This method is invoked by RTEMS when it needs to know which core
+ * number it is executing on. This is used when it needs to perform
+ * some action or bookkeeping and needs to distinguish itself from
+ * the other cores. For example, it may need to realize it needs to
+ * preempt a thread on another node.
+ *
+ * @return This method returns the Id of the current CPU core.
+ */
+int bsp_smp_processor_id( void );
+
+/**
+ * This method is invoked by @ref rtems_smp_secondary_cpu_initialize
+ * to allow the BSP to perform some intialization. The @a cpu
+ * parameter indicates the secondary CPU that the code is executing on
+ * and is currently being initialized.
+ *
+ * @note This is called by @ref rtems_smp_secondary_cpu_initialize.
+ */
+void bsp_smp_secondary_cpu_initialize(int cpu);
+
+/**
+ * This method is the C entry point which secondary CPUs should
+ * arrange to call. It performs OS initialization for the secondary
+ * CPU and coordinates bring it to a useful state.
+ *
+ * @note This is provided by RTEMS.
+ */
+void rtems_smp_secondary_cpu_initialize(void);
+
+/**
+ * This method is invoked by the BSP to initialize the per CPU structure
+ * for the specified @a cpu while it is bringing the secondary CPUs
+ * out of their reset state and into a useful state.
+ *
+ * @param [in] cpu indicates the CPU whose per cpu structure is to
+ * be initialized.
+ */
+void rtems_smp_initialize_per_cpu(int cpu);
+
+/**
+ * This is the method called by the BSP's interrupt handler
+ * to process the incoming interprocessor request.
+ */
+void rtems_smp_process_interrupt(void);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#else
+ #define bsp_smp_processor_id() 0
+#endif
+
+#endif
+
+/* end of include file */
diff --git a/cpukit/score/include/rtems/debug.h b/cpukit/score/include/rtems/debug.h
new file mode 100644
index 0000000000..7a53a4559d
--- /dev/null
+++ b/cpukit/score/include/rtems/debug.h
@@ -0,0 +1,81 @@
+/**
+ * @file rtems/debug.h
+ *
+ * This include file contains the information pertaining to the debug
+ * support within RTEMS. It is currently cast in the form of a
+ * Manager since it is externally accessible.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_DEBUG_H
+#define _RTEMS_DEBUG_H
+
+#include <rtems/score/basedefs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following type is used to manage the debug mask.
+ */
+typedef uint32_t rtems_debug_control;
+
+/*
+ * These constants represent various classes of debugging.
+ */
+
+/** Macro which indicates that all debugging modes are enabled */
+#define RTEMS_DEBUG_ALL_MASK 0xffffffff
+
+/** Macro which indicates that debugging for heaps/regions is enabled */
+#define RTEMS_DEBUG_REGION 0x00000001
+
+/**
+ * This variable contains the current debug level.
+ */
+SCORE_EXTERN rtems_debug_control _Debug_Level;
+
+/**
+ * This routine performs the initialization necessary for this manager.
+ */
+void _Debug_Manager_initialization( void );
+
+/**
+ * This routine enables the specified types of debug checks.
+ */
+void rtems_debug_enable(
+ rtems_debug_control to_be_enabled
+);
+
+/**
+ * This routine disables the specified types of debug checks.
+ */
+void rtems_debug_disable(
+ rtems_debug_control to_be_disabled
+);
+
+/**
+ * This routine returns TRUE if the requested debug level is
+ * enabled, and FALSE otherwise.
+ */
+bool rtems_debug_is_enabled(
+ rtems_debug_control level
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/.cvsignore b/cpukit/score/include/rtems/score/.cvsignore
new file mode 100644
index 0000000000..d9ecd15e8c
--- /dev/null
+++ b/cpukit/score/include/rtems/score/.cvsignore
@@ -0,0 +1 @@
+cpuopts.h
diff --git a/cpukit/score/include/rtems/score/address.h b/cpukit/score/include/rtems/score/address.h
new file mode 100644
index 0000000000..034d905d32
--- /dev/null
+++ b/cpukit/score/include/rtems/score/address.h
@@ -0,0 +1,43 @@
+/**
+ * @file rtems/score/address.h
+ *
+ * This include file contains the information required to manipulate
+ * physical addresses.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_ADDRESS_H
+#define _RTEMS_SCORE_ADDRESS_H
+
+/**
+ * @defgroup ScoreAddress Address Handler
+ *
+ * This handler encapsulates functionality which abstracts address
+ * manipulation in a portable manner.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/address.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/apiext.h b/cpukit/score/include/rtems/score/apiext.h
new file mode 100644
index 0000000000..c51bcc7b6e
--- /dev/null
+++ b/cpukit/score/include/rtems/score/apiext.h
@@ -0,0 +1,133 @@
+/**
+ * @file rtems/score/apiext.h
+ *
+ * This is the API Extensions Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_APIEXT_H
+#define _RTEMS_SCORE_APIEXT_H
+
+/**
+ * @defgroup ScoreAPIExtension API Extension Handler
+ *
+ * This handler encapsulates functionality which provides mechanisms for the
+ * SuperCore to perform API specific actions without there beingg
+ * "up-references" from the SuperCore to APIs. If these referencesg
+ * were allowed in the implementation, the cohesion would be too high
+ * and adding an API would be more difficult. The SuperCore is supposed
+ * to be largely independent of any API.
+ */
+/**@{*/
+
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+
+#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /**
+ * This type defines the prototype of the Predriver Hook.
+ */
+ typedef void (*API_extensions_Predriver_hook)(void);
+#endif
+
+/**
+ * This type defines the prototype of the Postdriver Hook.
+ */
+typedef void (*API_extensions_Postdriver_hook)(void);
+
+/**
+ * This type defines the prototype of the Postswitch Hook.
+ */
+typedef void (*API_extensions_Postswitch_hook)(
+ Thread_Control *
+ );
+
+/**
+ * The control structure which defines the points at which an API
+ * can add an extension to the system initialization thread.
+ */
+typedef struct {
+ /** This field allows this structure to be used with the Chain Handler. */
+ Chain_Node Node;
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /**
+ * This field is the callout invoked during RTEMS initialization after
+ * RTEMS data structures are initialized before device driver initialization
+ * has occurred.
+ *
+ * @note If this field is NULL, no extension is invoked.
+ */
+ API_extensions_Predriver_hook predriver_hook;
+ #endif
+ /**
+ * This field is the callout invoked during RTEMS initialization after
+ * RTEMS data structures and device driver initialization has occurred
+ * but before multitasking is initiated.
+ *
+ * @note If this field is NULL, no extension is invoked.
+ */
+ API_extensions_Postdriver_hook postdriver_hook;
+ /**
+ * This field is the callout invoked during each context switch
+ * in the context of the heir thread.
+ *
+ * @note If this field is NULL, no extension is invoked.
+ */
+ API_extensions_Postswitch_hook postswitch_hook;
+} API_extensions_Control;
+
+/**
+ * This is the list of API extensions to the system initialization.
+ */
+SCORE_EXTERN Chain_Control _API_extensions_List;
+
+/** @brief Initialize the API Extensions Handler
+ *
+ * This routine initializes the API extension handler.
+ */
+void _API_extensions_Initialization( void );
+
+/** @brief Add Extension Set to the Active Set
+ *
+ * This routine adds an extension to the active set of API extensions.
+ *
+ * @param[in] the_extension is the extension set to add.
+ */
+void _API_extensions_Add(
+ API_extensions_Control *the_extension
+);
+
+#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /** @brief Execute all Pre-Driver Extensions
+ *
+ * This routine executes all of the predriver callouts.
+ */
+ void _API_extensions_Run_predriver( void );
+#endif
+
+/** @brief Execute all Post-Driver Extensions
+ *
+ * This routine executes all of the postdriver callouts.
+ */
+void _API_extensions_Run_postdriver( void );
+
+/** @brief Execute all Post Context Switch Extensions
+ *
+ * This routine executes all of the post context switch callouts.
+ */
+void _API_extensions_Run_postswitch( void );
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/apimutex.h b/cpukit/score/include/rtems/score/apimutex.h
new file mode 100644
index 0000000000..691f60b709
--- /dev/null
+++ b/cpukit/score/include/rtems/score/apimutex.h
@@ -0,0 +1,116 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreAPIMutex
+ *
+ * @brief API Mutex Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_APIMUTEX_H
+#define _RTEMS_SCORE_APIMUTEX_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ScoreAPIMutex API Mutex Handler
+ *
+ * @ingroup Score
+ *
+ * @brief Provides routines to ensure mutual exclusion on API level.
+ *
+ * @{
+ */
+
+#include <rtems/score/coremutex.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+
+/**
+ * @brief Control block used to manage each API mutex.
+ */
+typedef struct {
+ /**
+ * @brief Allows each API Mutex to be a full-fledged RTEMS object.
+ */
+ Objects_Control Object;
+
+ /**
+ * Contains the SuperCore mutex information.
+ */
+ CORE_mutex_Control Mutex;
+} API_Mutex_Control;
+
+/**
+ * @brief Information control block used to manage this class of objects.
+ */
+SCORE_EXTERN Objects_Information _API_Mutex_Information;
+
+/**
+ * @brief Performs the initialization necessary for this handler.
+ *
+ * The value @a maximum_mutexes is the maximum number of API mutexes that may
+ * exist at any time.
+ */
+void _API_Mutex_Initialization( uint32_t maximum_mutexes );
+
+/**
+ * @brief Allocates an API mutex from the inactive set and returns it in
+ * @a mutex.
+ */
+void _API_Mutex_Allocate( API_Mutex_Control **mutex );
+
+/**
+ * @brief Acquires the specified API mutex @a mutex.
+ */
+void _API_Mutex_Lock( API_Mutex_Control *mutex );
+
+/**
+ * @brief Releases the specified API mutex @a mutex.
+ */
+void _API_Mutex_Unlock( API_Mutex_Control *mutex );
+
+/** @} */
+
+/**
+ * @defgroup ScoreAllocatorMutex RTEMS Allocator Mutex
+ *
+ * @ingroup ScoreAPIMutex
+ *
+ * @brief Protection for all memory allocations and deallocations in RTEMS.
+ *
+ * When the APIs all use this for allocation and deallocation protection, then
+ * this possibly should be renamed and moved to a higher level in the
+ * hierarchy.
+ *
+ * @{
+ */
+
+SCORE_EXTERN API_Mutex_Control *_RTEMS_Allocator_Mutex;
+
+#define _RTEMS_Lock_allocator() \
+ _API_Mutex_Lock( _RTEMS_Allocator_Mutex )
+
+#define _RTEMS_Unlock_allocator() \
+ _API_Mutex_Unlock( _RTEMS_Allocator_Mutex )
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/basedefs.h b/cpukit/score/include/rtems/score/basedefs.h
new file mode 100644
index 0000000000..b956806313
--- /dev/null
+++ b/cpukit/score/include/rtems/score/basedefs.h
@@ -0,0 +1,175 @@
+/**
+ * @file
+ *
+ * @ingroup Score
+ *
+ * @brief Basic definitions.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_BASEDEFS_H
+#define _RTEMS_BASEDEFS_H
+
+#include <rtems/score/cpuopts.h>
+
+#ifndef ASM
+ #include <stddef.h>
+ #include <stdbool.h>
+ #include <stdint.h>
+#endif
+
+#ifndef TRUE
+ #define TRUE 1
+#endif
+
+#ifndef FALSE
+ #define FALSE 0
+#endif
+
+#if TRUE == FALSE
+ #error "TRUE equals FALSE"
+#endif
+
+/**
+ * The following ensures that all data is declared in the space
+ * of the initialization routine for either the Initialization Manager
+ * or the initialization file for the appropriate API. It is
+ * referenced as "external" in every other file.
+ */
+#ifdef SCORE_INIT
+#undef SCORE_EXTERN
+#define SCORE_EXTERN
+#else
+#undef SCORE_EXTERN
+#define SCORE_EXTERN extern
+#endif
+
+/**
+ * The following ensures that all data is declared in the space
+ * of the initialization routine for either the Initialization Manager
+ * or the initialization file for the appropriate API. It is
+ * referenced as "external" in every other file.
+ */
+#ifdef SAPI_INIT
+#undef SAPI_EXTERN
+#define SAPI_EXTERN
+#else
+#undef SAPI_EXTERN
+#define SAPI_EXTERN extern
+#endif
+
+/**
+ * The following ensures that all data is declared in the space
+ * of the initialization routine for either the Initialization Manager
+ * or the initialization file for the appropriate API. It is
+ * referenced as "external" in every other file.
+ */
+#ifdef RTEMS_API_INIT
+#undef RTEMS_EXTERN
+#define RTEMS_EXTERN
+#else
+#undef RTEMS_EXTERN
+#define RTEMS_EXTERN extern
+#endif
+
+/**
+ * The following ensures that all data is declared in the space
+ * of the initialization routine for either the Initialization Manager
+ * or the initialization file for the appropriate API. It is
+ * referenced as "external" in every other file.
+ */
+#ifdef POSIX_API_INIT
+#undef POSIX_EXTERN
+#define POSIX_EXTERN
+#else
+#undef POSIX_EXTERN
+#define POSIX_EXTERN extern
+#endif
+
+/**
+ * The following (in conjunction with compiler arguments) are used
+ * to choose between the use of static inline functions and macro
+ * functions. The static inline implementation allows better
+ * type checking with no cost in code size or execution speed.
+ */
+#ifdef __GNUC__
+# define RTEMS_INLINE_ROUTINE static __inline__
+#else
+# define RTEMS_INLINE_ROUTINE static inline
+#endif
+
+/**
+ * The following macro is a compiler specific way to ensure that memory
+ * writes are not reordered around certian points. This specifically can
+ * impact interrupt disable and thread dispatching critical sections.
+ */
+#ifdef __GNUC__
+ #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory")
+#else
+ #define RTEMS_COMPILER_MEMORY_BARRIER()
+#endif
+
+/**
+ * The following macro is a compiler specific way to indicate that
+ * the method will NOT return to the caller. This can assist the
+ * compiler in code generation and avoid unreachable paths. This
+ * can impact the code generated following calls to
+ * rtems_fatal_error_occurred and _Internal_error_Occurred.
+ */
+#ifdef __GNUC__
+ #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE \
+ __attribute__ ((noreturn))
+#else
+ #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE
+#endif
+
+/**
+ * The following defines a compiler specific attribute which informs
+ * the compiler that the method has no effect except the return value
+ * and that the return value depends only on parameters and/or global
+ * variables.
+ */
+#ifdef __GNUC__
+ #define RTEMS_COMPILER_PURE_ATTRIBUTE \
+ __attribute__ ((pure))
+#else
+ #define RTEMS_COMPILER_PURE_ATTRIBUTE
+#endif
+
+/**
+ * Instructs the compiler to issue a warning whenever a variable or function
+ * with this attribute will be used.
+ */
+#ifdef __GNUC__
+ #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE \
+ __attribute__ ((deprecated))
+#else
+ #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE
+#endif
+
+#ifndef ASM
+ #ifdef RTEMS_DEPRECATED_TYPES
+ typedef bool boolean;
+ typedef float single_precision;
+ typedef double double_precision;
+ #endif
+
+ /**
+ * XXX: Eventually proc_ptr needs to disappear!!!
+ */
+ typedef void * proc_ptr;
+#endif
+
+#endif /* _RTEMS_BASEDEFS_H */
diff --git a/cpukit/score/include/rtems/score/bitfield.h b/cpukit/score/include/rtems/score/bitfield.h
new file mode 100644
index 0000000000..43f8fd09c4
--- /dev/null
+++ b/cpukit/score/include/rtems/score/bitfield.h
@@ -0,0 +1,106 @@
+/**
+ * @file rtems/score/bitfield.h
+ *
+ * This include file contains all bit field manipulation routines.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_BITFIELD_H
+#define _RTEMS_SCORE_BITFIELD_H
+
+/**
+ * @defgroup ScoreBitfield Bitfield Handler
+ *
+ * This handler encapsulates functionality that is used to manipulate the
+ * priority bitfields used to lookup which priority has the highest
+ * priority ready to execute thread.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if ( CPU_USE_GENERIC_BITFIELD_DATA == TRUE )
+
+/**
+ * This table is used by the generic bitfield routines to perform
+ * a highly optimized bit scan without the use of special CPU
+ * instructions.
+ */
+#ifndef SCORE_INIT
+extern const unsigned char __log2table[256];
+#else
+const unsigned char __log2table[256] = {
+ 7, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+#endif
+
+#endif
+
+/**
+ * This routine returns the @a _bit_number of the first bit set
+ * in the specified value. The correspondence between @a _bit_number
+ * and actual bit position is processor dependent. The search for
+ * the first bit set may run from most to least significant bit
+ * or vice-versa.
+ *
+ * @param[in] _value is the value to bit scan.
+ * @param[in] _bit_number is the position of the first bit set.
+ *
+ * @note This routine is used when the executing thread is removed
+ * from the ready state and, as a result, its performance has a
+ * significant impact on the performance of the executive as a whole.
+ *
+ * @note This routine must be a macro because if a CPU specific version
+ * is used it will most likely use inline assembly.
+ */
+#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
+#define _Bitfield_Find_first_bit( _value, _bit_number ) \
+ _CPU_Bitfield_Find_first_bit( _value, _bit_number )
+#else
+#define _Bitfield_Find_first_bit( _value, _bit_number ) \
+ { \
+ register uint32_t __value = (uint32_t) (_value); \
+ register const unsigned char *__p = __log2table; \
+ \
+ if ( __value < 0x100 ) \
+ (_bit_number) = (Priority_bit_map_Control)( __p[ __value ] + 8 ); \
+ else \
+ (_bit_number) = (Priority_bit_map_Control)( __p[ __value >> 8 ] ); \
+ }
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/chain.h b/cpukit/score/include/rtems/score/chain.h
new file mode 100644
index 0000000000..187a466c90
--- /dev/null
+++ b/cpukit/score/include/rtems/score/chain.h
@@ -0,0 +1,258 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreChain
+ *
+ * @brief Chain Handler API.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CHAIN_H
+#define _RTEMS_SCORE_CHAIN_H
+
+/**
+ * @defgroup ScoreChain Chain Handler
+ *
+ * @ingroup Score
+ *
+ * The Chain Handler is used to manage sets of entities. This handler
+ * provides two data structures. The Chain Node data structure is included
+ * as the first part of every data structure that will be placed on
+ * a chain. The second data structure is Chain Control which is used
+ * to manage a set of Chain Nodes.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/address.h>
+
+/**
+ * @typedef Chain_Node
+ *
+ * This type definition promotes the name for the Chain Node used by
+ * all RTEMS code. It is a separate type definition because a forward
+ * reference is required to define it. See @ref Chain_Node_struct for
+ * detailed information.
+ */
+typedef struct Chain_Node_struct Chain_Node;
+
+/**
+ * @struct Chain_Node_struct
+ *
+ * This is used to manage each element (node) which is placed
+ * on a chain.
+ *
+ * @note Typically, a more complicated structure will use the
+ * chain package. The more complicated structure will
+ * include a chain node as the first element in its
+ * control structure. It will then call the chain package
+ * with a pointer to that node element. The node pointer
+ * and the higher level structure start at the same address
+ * so the user can cast the pointers back and forth.
+ *
+ */
+struct Chain_Node_struct {
+ /** This points to the node after to this one on this chain. */
+ Chain_Node *next;
+ /** This points to the node immediate prior to this one on this chain. */
+ Chain_Node *previous;
+};
+
+/**
+ * @struct Chain_Control
+ *
+ * This is used to manage a chain. A chain consists of a doubly
+ * linked list of zero or more nodes.
+ *
+ * @note This implementation does not require special checks for
+ * manipulating the first and last elements on the chain.
+ * To accomplish this the @a Chain_Control structure is
+ * treated as two overlapping @ref Chain_Node structures.
+ */
+typedef union {
+ struct {
+ Chain_Node Node;
+ Chain_Node *fill;
+ } Head;
+
+ struct {
+ Chain_Node *fill;
+ Chain_Node Node;
+ } Tail;
+} Chain_Control;
+
+/**
+ * @brief Chain initializer for an empty chain with designator @a name.
+ */
+#define CHAIN_INITIALIZER_EMPTY(name) \
+ { { { &(name).Tail.Node, NULL }, &(name).Head.Node } }
+
+/**
+ * @brief Chain definition for an empty chain with designator @a name.
+ */
+#define CHAIN_DEFINE_EMPTY(name) \
+ Chain_Control name = CHAIN_INITIALIZER_EMPTY(name)
+
+/**
+ * @brief Initialize a Chain Header
+ *
+ * This routine initializes @a the_chain structure to manage the
+ * contiguous array of @a number_nodes nodes which starts at
+ * @a starting_address. Each node is of @a node_size bytes.
+ *
+ * @param[in] the_chain specifies the chain to initialize
+ * @param[in] starting_address is the starting address of the array
+ * of elements
+ * @param[in] number_nodes is the numebr of nodes that will be in the chain
+ * @param[in] node_size is the size of each node
+ */
+void _Chain_Initialize(
+ Chain_Control *the_chain,
+ void *starting_address,
+ size_t number_nodes,
+ size_t node_size
+);
+
+/**
+ * @brief Extract the specified node from a chain
+ *
+ * This routine extracts @a the_node from the chain on which it resides.
+ * It disables interrupts to ensure the atomicity of the
+ * extract operation.
+ *
+ * @arg the_node specifies the node to extract
+ */
+void _Chain_Extract(
+ Chain_Node *the_node
+);
+
+/**
+ * @brief Obtain the first node on a chain
+ *
+ * This function removes the first node from @a the_chain and returns
+ * a pointer to that node. If @a the_chain is empty, then NULL is returned.
+ *
+ * @return This method returns a pointer a node. If a node was removed,
+ * then a pointer to that node is returned. If @a the_chain was
+ * empty, then NULL is returned.
+ *
+ * @note It disables interrupts to ensure the atomicity of the get operation.
+ */
+Chain_Node *_Chain_Get(
+ Chain_Control *the_chain
+);
+
+/**
+ * @brief Insert a node on a chain
+ *
+ * This routine inserts @a the_node on a chain immediately following
+ * @a after_node.
+ *
+ * @note It disables interrupts to ensure the atomicity
+ * of the extract operation.
+ */
+void _Chain_Insert(
+ Chain_Node *after_node,
+ Chain_Node *the_node
+);
+
+/**
+ * @brief Append a node on the end of a chain
+ *
+ * This routine appends @a the_node onto the end of @a the_chain.
+ *
+ * @note It disables interrupts to ensure the atomicity of the
+ * append operation.
+ */
+void _Chain_Append(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+);
+
+/**
+ * @brief Append a node and check if the chain was empty before.
+ *
+ * This routine appends the_node onto the end of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be appended.
+ *
+ * @note It disables interrupts to ensure the atomicity of the append
+ * operation.
+ *
+ * @retval true The chain was empty before.
+ * @retval false The chain contained at least one node before.
+ */
+bool _Chain_Append_with_empty_check(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+);
+
+/**
+ * @brief Prepend a node and check if the chain was empty before.
+ *
+ * This routine prepends the_node onto the front of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be prepended.
+ *
+ * @note It disables interrupts to ensure the atomicity of the append
+ * operation.
+ *
+ * @retval true The chain was empty before.
+ * @retval false The chain contained at least one node before.
+ */
+bool _Chain_Prepend_with_empty_check(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+);
+
+/**
+ * @brief Get the first node and check if the chain is empty afterwards.
+ *
+ * This function removes the first node from the_chain and returns
+ * a pointer to that node in @a the_node. If the_chain is empty, then NULL is
+ * returned.
+ *
+ * @param[in] the_chain is the chain to attempt to get the first node from.
+ * @param[out] the_node is the first node on the chain or NULL if the chain is
+ * empty.
+ *
+ * @note It disables interrupts to ensure the atomicity of the append
+ * operation.
+ *
+ * @retval true The chain is empty now.
+ * @retval false The chain contains at least one node now.
+ */
+bool _Chain_Get_with_empty_check(
+ Chain_Control *the_chain,
+ Chain_Node **the_node
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/chain.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/context.h b/cpukit/score/include/rtems/score/context.h
new file mode 100644
index 0000000000..34baf32669
--- /dev/null
+++ b/cpukit/score/include/rtems/score/context.h
@@ -0,0 +1,180 @@
+/**
+ * @file rtems/score/context.h
+ *
+ * This include file contains all information about each thread's context.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CONTEXT_H
+#define _RTEMS_SCORE_CONTEXT_H
+
+/**
+ * @defgroup ScoreContext Context Handler
+ *
+ * This handler encapsulates functionality which abstracts thread context
+ * management in a portable manner.
+ *
+ * The context switch needed variable is contained in the per cpu
+ * data structure.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/cpu.h>
+
+/**
+ * @brief Size of Floating Point Context Area
+ *
+ * This constant defines the number of bytes required
+ * to store a full floating point context.
+ */
+#define CONTEXT_FP_SIZE CPU_CONTEXT_FP_SIZE
+
+/**
+ * @brief Initialize Context Area
+ *
+ * This routine initializes @a _the_context such that the stack
+ * pointer, interrupt level, and entry point are correct for the
+ * thread's initial state.
+ *
+ * @param[in] _the_context will be initialized
+ * @param[in] _stack is the lowest physical address of the thread's
+ * context
+ * @param[in] _size is the size in octets of the thread's context
+ * @param[in] _isr is the ISR enable level for this thread
+ * @param[in] _entry is this thread's entry point
+ * @param[in] _is_fp is set to true if this thread has floating point
+ * enabled
+ */
+#define _Context_Initialize(_the_context, _stack, _size, _isr, _entry, _is_fp) \
+ _CPU_Context_Initialize( _the_context, _stack, _size, _isr, _entry, _is_fp )
+
+/**
+ * This macro is invoked from _Thread_Handler to do whatever CPU
+ * specific magic is required that must be done in the context of
+ * the thread when it starts.
+ *
+ * If the CPU architecture does not require any magic, then this
+ * macro is empty.
+ */
+
+#if defined(_CPU_Context_Initialization_at_thread_begin)
+ #define _Context_Initialization_at_thread_begin() \
+ _CPU_Context_Initialization_at_thread_begin()
+#else
+ #define _Context_Initialization_at_thread_begin()
+#endif
+
+/**
+ * @brief Perform Context Switch
+ *
+ * This routine saves the current context into the @a _executing
+ * context record and restores the context specified by @a _heir.
+ *
+ * @param[in] _executing is the currently executing thread's context
+ * @param[in] _heir is the context of the thread to be switched to
+ */
+#define _Context_Switch( _executing, _heir ) \
+ _CPU_Context_switch( _executing, _heir )
+
+/**
+ * @brief Restart Currently Executing Thread
+ *
+ * This routine restarts the calling thread by restoring its initial
+ * stack pointer and returning to the thread's entry point.
+ *
+ * @param[in] _the_context is the context of the thread to restart
+ */
+#define _Context_Restart_self( _the_context ) \
+ _CPU_Context_Restart_self( _the_context )
+
+#if defined(RTEMS_SMP)
+/*
+ * @brief Switch to First Task on Secondary Core
+ *
+ * This routine is only used to switch to the first task on a
+ * secondary core in an SMP configuration. Since the switch
+ * to the first task is done from an interrupt handler, this
+ * may be different from simply restarting the currently running
+ * task.
+ *
+ * @param[in] _the_context is the context of the first thread to
+ * run on this core
+ */
+#define _Context_Switch_to_first_task_smp( _the_context ) \
+ _CPU_Context_switch_to_first_task_smp( _the_context )
+#endif
+
+/**
+ * @brief Return Starting Address of Floating Point Context
+ *
+ * This function returns the starting address of the floating
+ * point context save area. It is assumed that the are reserved
+ * for the floating point save area is large enough.
+ *
+ * @param[in] _base is lowest physical address of the floating point
+ * context save area.
+ * @param[in] _offset is the offset into the floating point area
+ *
+ * @return the initial FP context pointer
+ */
+#define _Context_Fp_start( _base, _offset ) \
+ _CPU_Context_Fp_start( (_base), (_offset) )
+
+/**
+ * @brief Initialize Floating Point Context Area
+ *
+ * This routine initializes the floating point context save
+ * area to contain an initial known state.
+ *
+ * @param[in] _fp_area is the base address of the floating point
+ * context save area to initialize.
+ */
+#define _Context_Initialize_fp( _fp_area ) \
+ _CPU_Context_Initialize_fp( _fp_area )
+
+/**
+ * @brief Restore Floating Point Context Area
+ *
+ * This routine restores the floating point context contained
+ * in the @a _fp area. It is assumed that the current
+ * floating point context has been saved by a previous invocation
+ * of @a _Context_Save_fp.
+ *
+ * @param[in] _fp points to the floating point context area to restore.
+ */
+#define _Context_Restore_fp( _fp ) \
+ _CPU_Context_restore_fp( _fp )
+
+/**
+ * @brief Save Floating Point Context Area
+ *
+ * This routine saves the current floating point context
+ * in the @a _fp area.
+ *
+ * @param[in] _fp points to the floating point context area to restore.
+ */
+#define _Context_Save_fp( _fp ) \
+ _CPU_Context_save_fp( _fp )
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/copyrt.h b/cpukit/score/include/rtems/score/copyrt.h
new file mode 100644
index 0000000000..8c418abd7c
--- /dev/null
+++ b/cpukit/score/include/rtems/score/copyrt.h
@@ -0,0 +1,42 @@
+/**
+ * @file rtems/score/copyrt.h
+ *
+ * This include file contains the copyright notice for RTEMS
+ * which is included in every binary copy of the executive.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COPYRT_H
+#define _RTEMS_SCORE_COPYRT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is the copyright string for RTEMS.
+ */
+#ifdef SCORE_INIT
+const char _Copyright_Notice[] =
+"COPYRIGHT (c) 1989-2008.\n\
+On-Line Applications Research Corporation (OAR).\n";
+#else
+extern const char _Copyright_Notice[];
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/corebarrier.h b/cpukit/score/include/rtems/score/corebarrier.h
new file mode 100644
index 0000000000..05ec152487
--- /dev/null
+++ b/cpukit/score/include/rtems/score/corebarrier.h
@@ -0,0 +1,202 @@
+/**
+ * @file rtems/score/corebarrier.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Barrier Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COREBARRIER_H
+#define _RTEMS_SCORE_COREBARRIER_H
+
+/**
+ * @defgroup ScoreBarrier Barrier Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * Barrier services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * The following type defines the callout which the API provides
+ * to support global/multiprocessor operations on barriers.
+ */
+typedef void ( *CORE_barrier_API_mp_support_callout )(
+ Thread_Control *,
+ Objects_Id
+ );
+
+/**
+ * Flavors of barriers.
+ */
+typedef enum {
+ /** This specifies that the barrier will automatically release when
+ * the user specified number of threads have arrived at the barrier.
+ */
+ CORE_BARRIER_AUTOMATIC_RELEASE,
+ /** This specifies that the user will have to manually release the barrier
+ * in order to release the waiting threads.
+ */
+ CORE_BARRIER_MANUAL_RELEASE
+} CORE_barrier_Disciplines;
+
+/**
+ * Core Barrier handler return statuses.
+ */
+typedef enum {
+ /** This status indicates that the operation completed successfully. */
+ CORE_BARRIER_STATUS_SUCCESSFUL,
+ /** This status indicates that the barrier is configured for automatic
+ * release and the caller tripped the automatic release. The caller
+ * thus did not block.
+ */
+ CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED,
+ /** This status indicates that the thread was blocked waiting for an
+ * operation to complete and the barrier was deleted.
+ */
+ CORE_BARRIER_WAS_DELETED,
+ /** This status indicates that the calling task was willing to block
+ * but the operation was unable to complete within the time allotted
+ * because the resource never became available.
+ */
+ CORE_BARRIER_TIMEOUT
+} CORE_barrier_Status;
+
+/**
+ * @brief Core Barrier Last Status
+ *
+ * This is the last status value.
+ */
+#define CORE_BARRIER_STATUS_LAST CORE_BARRIER_TIMEOUT
+
+/**
+ * The following defines the control block used to manage the
+ * attributes of each barrier.
+ */
+typedef struct {
+ /** This field indicates whether the barrier is automatic or manual.
+ */
+ CORE_barrier_Disciplines discipline;
+ /** This element indicates the number of threads which must arrive at the
+ * barrier to trip the automatic release.
+ */
+ uint32_t maximum_count;
+} CORE_barrier_Attributes;
+
+/**
+ * The following defines the control block used to manage each
+ * barrier.
+ */
+typedef struct {
+ /** This field is the Waiting Queue used to manage the set of tasks
+ * which are blocked waiting for the barrier to be released.
+ */
+ Thread_queue_Control Wait_queue;
+ /** This element is the set of attributes which define this instance's
+ * behavior.
+ */
+ CORE_barrier_Attributes Attributes;
+ /** This element contains the current number of thread waiting for this
+ * barrier to be released. */
+ uint32_t number_of_waiting_threads;
+} CORE_barrier_Control;
+
+/**
+ * This routine initializes the barrier based on the parameters passed.
+ *
+ * @param[in] the_barrier is the barrier to initialize
+ * @param[in] the_barrier_attributes define the behavior of this instance
+ */
+void _CORE_barrier_Initialize(
+ CORE_barrier_Control *the_barrier,
+ CORE_barrier_Attributes *the_barrier_attributes
+);
+
+/**
+ * This routine wait for the barrier to be released. If the barrier
+ * is set to automatic and this is the appropriate thread, then it returns
+ * immediately. Otherwise, the calling thread is blocked until the barrier
+ * is released.
+ *
+ * @param[in] the_barrier is the barrier to wait for
+ * @param[in] id is the id of the object being waited upon
+ * @param[in] wait is true if the calling thread is willing to wait
+ * @param[in] timeout is the number of ticks the calling thread is willing
+ * to wait if @a wait is true.
+ * @param[in] api_barrier_mp_support is the routine to invoke if the
+ * thread unblocked is remote
+ *
+ * @note Status is returned via the thread control block.
+ */
+void _CORE_barrier_Wait(
+ CORE_barrier_Control *the_barrier,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ CORE_barrier_API_mp_support_callout api_barrier_mp_support
+);
+
+/**
+ * This routine manually releases the barrier. All of the threads waiting
+ * for the barrier will be readied.
+ *
+ * @param[in] the_barrier is the barrier to surrender
+ * @param[in] id is the id of the object for a remote unblock
+ * @param[in] api_barrier_mp_support is the routine to invoke if the
+ * thread unblocked is remote
+ *
+ * @return the number of unblocked threads
+ */
+uint32_t _CORE_barrier_Release(
+ CORE_barrier_Control *the_barrier,
+ Objects_Id id,
+ CORE_barrier_API_mp_support_callout api_barrier_mp_support
+);
+
+/**
+ * This routine assists in the deletion of a barrier by flushing the
+ * associated wait queue.
+ *
+ * @param[in] _the_barrier is the barrier to flush
+ * @param[in] _remote_extract_callout is the routine to invoke if the
+ * thread unblocked is remote
+ * @param[in] _status is the status to be returned to the unblocked thread
+ */
+#define _CORE_barrier_Flush( _the_barrier, _remote_extract_callout, _status) \
+ _Thread_queue_Flush( \
+ &((_the_barrier)->Wait_queue), \
+ (_remote_extract_callout), \
+ (_status) \
+ )
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/corebarrier.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/coremsg.h b/cpukit/score/include/rtems/score/coremsg.h
new file mode 100644
index 0000000000..4a93f6de25
--- /dev/null
+++ b/cpukit/score/include/rtems/score/coremsg.h
@@ -0,0 +1,451 @@
+/**
+ * @file rtems/score/coremsg.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Message queue Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COREMSG_H
+#define _RTEMS_SCORE_COREMSG_H
+
+/**
+ * @defgroup ScoreMessageQueue Message Queue Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * Message Queue services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#include <limits.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/watchdog.h>
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY
+#endif
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION
+#endif
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Message Queue MP Callback Prototype
+ *
+ * The following type defines the callout which the API provides
+ * to support global/multiprocessor operations on message_queues.
+ */
+typedef void ( *CORE_message_queue_API_mp_support_callout )(
+ Thread_Control *,
+ Objects_Id
+ );
+
+/**
+ * @brief Message Buffer Contents Management Structure
+ *
+ * The following defines the data types needed to manipulate
+ * the contents of message buffers.
+ *
+ * @note The buffer field is normally longer than a single uint32_t
+ * but since messages are variable length we just make a ptr to 1.
+ */
+typedef struct {
+ /** This field is the size of this message. */
+ size_t size;
+ /** This field contains the actual message. */
+ uint32_t buffer[1];
+} CORE_message_queue_Buffer;
+
+/**
+ * @brief Message Structure
+ *
+ * The following records define the organization of a message
+ * buffer.
+ */
+typedef struct {
+ /** This element allows this structure to be placed on chains. */
+ Chain_Node Node;
+ #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
+ /** This field is the priority of this message. */
+ int priority;
+ #endif
+ /** This field points to the contents of the message. */
+ CORE_message_queue_Buffer Contents;
+} CORE_message_queue_Buffer_control;
+
+/**
+ * @brief Message Queue Blocking Disciplines
+ *
+ * This enumerated types defines the possible blocking disciplines
+ * for a message queue.
+ */
+typedef enum {
+ /** This value indicates that blocking tasks are in FIFO order. */
+ CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
+ /** This value indicates that blocking tasks are in priority order. */
+ CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY
+} CORE_message_queue_Disciplines;
+
+/**
+ * @brief Message Priority for Appending
+ *
+ * This is the priority constant used when appending messages onto
+ * a message queue.
+ */
+#define CORE_MESSAGE_QUEUE_SEND_REQUEST INT_MAX
+
+/**
+ * @brief Message Priority for Prepending
+ *
+ * This is the priority constant used when prepending messages onto
+ * a message queue.
+ */
+#define CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
+
+/**
+ * @brief Message Insertion Operation Types
+ *
+ * The following type details the modes in which a message
+ * may be submitted to a message queue. The message may be posted
+ * in a send or urgent fashion.
+ *
+ * @note All other values are message priorities. Numerically smaller
+ * priorities indicate higher priority messages.
+ */
+typedef int CORE_message_queue_Submit_types;
+
+/**
+ * @brief Core Message Queue Return Statuses
+ *
+ * This enumerated type defines the possible set of Core Message
+ * Queue handler return statuses.
+ */
+typedef enum {
+ /** This value indicates the operation completed sucessfully. */
+ CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL,
+ /** This value indicates that the message was too large for this queue. */
+ CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE,
+ /** This value indicates that there are too many messages pending. */
+ CORE_MESSAGE_QUEUE_STATUS_TOO_MANY,
+ /** This value indicates that a receive was unsuccessful. */
+ CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED,
+ /** This value indicates that a blocking send was unsuccessful. */
+ CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT,
+ /** This value indicates that the message queue being blocked upon
+ * was deleted while the thread was waiting.
+ */
+ CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED,
+ /** This value indicates that the thread had to timeout while waiting
+ * to receive a message because one did not become available.
+ */
+ CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
+ /** This value indicates that a blocking receive was unsuccessful. */
+ CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
+} CORE_message_queue_Status;
+
+/**
+ * @brief Core Message Queue Last Status
+ *
+ * This is the last status value.
+ */
+#define CORE_MESSAGE_QUEUE_STATUS_LAST CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
+
+/**
+ * @brief Message Queue Attributes Type
+ *
+ * The following defines the control block used to manage the
+ * attributes of each message queue.
+ */
+typedef struct {
+ /** This field specifies the order in which blocking tasks will be ordered. */
+ CORE_message_queue_Disciplines discipline;
+} CORE_message_queue_Attributes;
+
+#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
+ /**
+ * @brief Message Queue Notification Callback Prototype
+ *
+ * The following defines the type for a Notification handler. A
+ * notification handler is invoked when the message queue makes a
+ * 0->1 transition on pending messages.
+ */
+ typedef void (*CORE_message_queue_Notify_Handler)( void * );
+#endif
+
+/**
+ * @brief Core Message Queue Control Structure
+ *
+ * The following defines the control block used to manage each
+ * Message Queue
+ */
+typedef struct {
+ /** This field is the Waiting Queue used to manage the set of tasks
+ * which are blocked waiting to receive a message from this queue.
+ */
+ Thread_queue_Control Wait_queue;
+ /** This element is the set of attributes which define this instance's
+ * behavior.
+ */
+ CORE_message_queue_Attributes Attributes;
+ /** This element is maximum number of messages which may be pending
+ * at any given time.
+ */
+ uint32_t maximum_pending_messages;
+ /** This element is the number of messages which are currently pending.
+ */
+ uint32_t number_of_pending_messages;
+ /** This is the size in bytes of the largest message which may be
+ * sent via this queue.
+ */
+ size_t maximum_message_size;
+ /** This chain is the set of pending messages. It may be ordered by
+ * message priority or in FIFO order.
+ */
+ Chain_Control Pending_messages;
+ /** This is the address of the memory allocated for message buffers.
+ * It is allocated are part of message queue initialization and freed
+ * as part of destroying it.
+ */
+ CORE_message_queue_Buffer *message_buffers;
+ #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
+ /** This is the routine invoked when the message queue transitions
+ * from zero (0) messages pending to one (1) message pending.
+ */
+ CORE_message_queue_Notify_Handler notify_handler;
+ /** This field is the argument passed to the @ref notify_argument. */
+ void *notify_argument;
+ #endif
+ /** This chain is the set of inactive messages. A message is inactive
+ * when it does not contain a pending message.
+ */
+ Chain_Control Inactive_messages;
+} CORE_message_queue_Control;
+
+/**
+ * @brief Initialize a Message Queue
+ *
+ * This routine initializes @a the_message_queue based on the parameters passed.
+ *
+ * @param[in] the_message_queue points to the message queue to initialize
+ * @param[in] the_message_queue_attributes points to the attributes that
+ * will be used with this message queue instance
+ * @param[in] maximum_pending_messages is the maximum number of messages
+ * that will be allowed to pend at any given time
+ * @param[in] maximum_message_size is the size of largest message that
+ * may be sent to this message queue instance
+ *
+ * @return true if the message queue can be initialized. In general,
+ * false will only be returned if memory for the pending
+ * messages cannot be allocated.
+ */
+bool _CORE_message_queue_Initialize(
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Attributes *the_message_queue_attributes,
+ uint32_t maximum_pending_messages,
+ size_t maximum_message_size
+);
+
+/**
+ * @brief Close a Message Queue
+ *
+ * This function closes a message by returning all allocated space and
+ * flushing @a the_message_queue's task wait queue.
+ *
+ * @param[in] the_message_queue points to the message queue to close
+ * @param[in] remote_extract_callout is the routine to call for each thread
+ * that is extracted from the set of waiting threads
+ * @param[in] status is the status that each waiting thread will return
+ * from it's blocking service
+ */
+void _CORE_message_queue_Close(
+ CORE_message_queue_Control *the_message_queue,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+);
+
+/**
+ * @brief Flush Pending Messages
+ *
+ * This function flushes @a the_message_queue's pending message queue. The
+ * number of messages flushed from the queue is returned.
+ *
+ * @param[in] the_message_queue points to the message queue to flush
+ *
+ * @return This method returns the number of message pending messages flushed.
+ */
+uint32_t _CORE_message_queue_Flush(
+ CORE_message_queue_Control *the_message_queue
+);
+
+/**
+ * @brief Flush Messages Support Routine
+ *
+ * This routine flushes all outstanding messages and returns
+ * them to the inactive message chain.
+ *
+ * @param[in] the_message_queue points to the message queue to flush
+ *
+ * @return This method returns the number of message pending messages flushed.
+ */
+uint32_t _CORE_message_queue_Flush_support(
+ CORE_message_queue_Control *the_message_queue
+);
+
+#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /**
+ * @brief Flush Waiting Threads.
+ *
+ * This function flushes the threads which are blocked on
+ * @a the_message_queue's pending message queue. They are
+ * unblocked whether blocked sending or receiving.
+ *
+ * @param[in] the_message_queue points to the message queue to flush
+ */
+ void _CORE_message_queue_Flush_waiting_threads(
+ CORE_message_queue_Control *the_message_queue
+ );
+#endif
+
+/**
+ * @brief Broadcast a Message to the Message Queue
+ *
+ * This function sends a message for every thread waiting on the queue and
+ * returns the number of threads made ready by the message.
+ *
+ * @param[in] the_message_queue points to the message queue
+ * @param[in] buffer is the starting address of the message to broadcast
+ * @param[in] size is the size of the message being broadcast
+ * @param[in] id is the RTEMS object Id associated with this message queue.
+ * It is used when unblocking a remote thread.
+ * @param[in] api_message_queue_mp_support is the routine to invoke if
+ * a thread that is unblocked is actually a remote thread.
+ * @param[out] count points to the variable that will contain the
+ * number of tasks that are sent this message
+ * @return @a *count will contain the number of messages sent
+ * @return indication of the successful completion or reason for failure
+ */
+CORE_message_queue_Status _CORE_message_queue_Broadcast(
+ CORE_message_queue_Control *the_message_queue,
+ const void *buffer,
+ size_t size,
+ Objects_Id id,
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
+ uint32_t *count
+);
+
+/**
+ * @brief Submit a Message to the Message Queue
+ *
+ * This routine implements the send and urgent message functions. It
+ * processes a message that is to be submitted to the designated
+ * message queue. The message will either be processed as a
+ * send message which it will be inserted at the rear of the queue
+ * or it will be processed as an urgent message which will be inserted
+ * at the front of the queue.
+ *
+ * @param[in] the_message_queue points to the message queue
+ * @param[in] buffer is the starting address of the message to send
+ * @param[in] size is the size of the message being send
+ * @param[in] id is the RTEMS object Id associated with this message queue.
+ * It is used when unblocking a remote thread.
+ * @param[in] api_message_queue_mp_support is the routine to invoke if
+ * a thread that is unblocked is actually a remote thread.
+ * @param[in] submit_type determines whether the message is prepended,
+ * appended, or enqueued in priority order.
+ * @param[in] wait indicates whether the calling thread is willing to block
+ * if the message queue is full.
+ * @param[in] timeout is the maximum number of clock ticks that the calling
+ * thread is willing to block if the message queue is full.
+ * @return indication of the successful completion or reason for failure
+ */
+CORE_message_queue_Status _CORE_message_queue_Submit(
+ CORE_message_queue_Control *the_message_queue,
+ const void *buffer,
+ size_t size,
+ Objects_Id id,
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
+ CORE_message_queue_Submit_types submit_type,
+ bool wait,
+ Watchdog_Interval timeout
+);
+
+/**
+ * @brief Size a Message from the Message Queue
+ *
+ * This kernel routine dequeues a message, copies the message buffer to
+ * a given destination buffer, and frees the message buffer to the
+ * inactive message pool. The thread will be blocked if wait is true,
+ * otherwise an error will be given to the thread if no messages are available.
+ *
+ * @param[in] the_message_queue points to the message queue
+ * @param[in] id is the RTEMS object Id associated with this message queue.
+ * It is used when unblocking a remote thread.
+ * @param[in] buffer is the starting address of the message buffer to
+ * to be filled in with a message
+ * @param[in] size is the size of the @a buffer and indicates the maximum
+ * size message that the caller can receive.
+ * @param[in] wait indicates whether the calling thread is willing to block
+ * if the message queue is empty.
+ * @param[in] timeout is the maximum number of clock ticks that the calling
+ * thread is willing to block if the message queue is empty.
+ *
+ * @return indication of the successful completion or reason for failure
+ * @note Returns message priority via return are in TCB.
+ */
+void _CORE_message_queue_Seize(
+ CORE_message_queue_Control *the_message_queue,
+ Objects_Id id,
+ void *buffer,
+ size_t *size_p,
+ bool wait,
+ Watchdog_Interval timeout
+);
+
+/**
+ * This kernel routine inserts the specified message into the
+ * message queue. It is assumed that the message has been filled
+ * in before this routine is called.
+ *
+ * @param[in] the_message_queue points to the message queue
+ * @param[in] the_message is the message to enqueue
+ * @param[in] submit_type determines whether the message is prepended,
+ * appended, or enqueued in priority order.
+ */
+void _CORE_message_queue_Insert_message(
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Buffer_control *the_message,
+ CORE_message_queue_Submit_types submit_type
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/coremsg.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h
new file mode 100644
index 0000000000..084532f36d
--- /dev/null
+++ b/cpukit/score/include/rtems/score/coremutex.h
@@ -0,0 +1,468 @@
+/**
+ * @file rtems/score/coremutex.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Mutex Handler. A mutex is an enhanced version of the standard
+ * Dijkstra binary semaphore used to provide synchronization and mutual
+ * exclusion capabilities.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COREMUTEX_H
+#define _RTEMS_SCORE_COREMUTEX_H
+
+
+/**
+ * @defgroup ScoreMutex Mutex Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * Mutex services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/sysstate.h>
+
+/**
+ * @brief MP Support Callback Prototype
+ *
+ * The following type defines the callout which the API provides
+ * to support global/multiprocessor operations on mutexes.
+ */
+typedef void ( *CORE_mutex_API_mp_support_callout )(
+ Thread_Control *,
+ Objects_Id
+ );
+
+/**
+ * @brief Blocking Disciplines Enumerated Type
+ *
+ * This enumerated type defines the blocking disciplines for a mutex.
+ */
+typedef enum {
+ /** This specifies that threads will wait for the mutex in FIFO order. */
+ CORE_MUTEX_DISCIPLINES_FIFO,
+ /** This specifies that threads will wait for the mutex in priority order. */
+ CORE_MUTEX_DISCIPLINES_PRIORITY,
+ /** This specifies that threads will wait for the mutex in priority order.
+ * Additionally, the Priority Inheritance Protocol will be in effect.
+ */
+ CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT,
+ /** This specifies that threads will wait for the mutex in priority order.
+ * Additionally, the Priority Ceiling Protocol will be in effect.
+ */
+ CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING
+} CORE_mutex_Disciplines;
+
+/**
+ * @brief Mutex method return statuses
+ *
+ * This enumerated type defines the possible Mutex handler return statuses.
+ */
+typedef enum {
+ /** This status indicates that the operation completed successfully. */
+ CORE_MUTEX_STATUS_SUCCESSFUL,
+ /** This status indicates that the calling task did not want to block
+ * and the operation was unable to complete immediately because the
+ * resource was unavailable.
+ */
+ CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT,
+#if defined(RTEMS_POSIX_API)
+ /** This status indicates that an attempt was made to relock a mutex
+ * for which nesting is not configured.
+ */
+ CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED,
+#endif
+ /** This status indicates that an attempt was made to release a mutex
+ * by a thread other than the thread which locked it.
+ */
+ CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE,
+ /** This status indicates that the thread was blocked waiting for an
+ * operation to complete and the mutex was deleted.
+ */
+ CORE_MUTEX_WAS_DELETED,
+ /** This status indicates that the calling task was willing to block
+ * but the operation was unable to complete within the time allotted
+ * because the resource never became available.
+ */
+ CORE_MUTEX_TIMEOUT,
+
+#if defined(__RTEMS_STRICT_ORDER_MUTEX__)
+ /** This status indicates that a thread not release the mutex which has
+ * the priority inheritance property in a right order.
+ */
+ CORE_MUTEX_RELEASE_NOT_ORDER,
+#endif
+
+ /** This status indicates that a thread of logically greater importance
+ * than the ceiling priority attempted to lock this mutex.
+ */
+ CORE_MUTEX_STATUS_CEILING_VIOLATED
+
+} CORE_mutex_Status;
+
+/**
+ * @brief Core Mutex Last Status
+ *
+ * This is the last status value.
+ */
+#define CORE_MUTEX_STATUS_LAST CORE_MUTEX_STATUS_CEILING_VIOLATED
+
+/**
+ * @brief Mutex Lock Nesting Behavior Enumeration
+ *
+ * This enumerated type defines the possible behaviors for
+ * lock nesting.
+ */
+typedef enum {
+ /**
+ * This sequence has no blocking or errors:
+ *
+ * + lock(m)
+ * + lock(m)
+ * + unlock(m)
+ * + unlock(m)
+ */
+ CORE_MUTEX_NESTING_ACQUIRES,
+#if defined(RTEMS_POSIX_API)
+ /**
+ * This sequence returns an error at the indicated point:
+ *
+ * + lock(m)
+ * + lock(m) - already locked error
+ * + unlock(m)
+ */
+ CORE_MUTEX_NESTING_IS_ERROR,
+#endif
+ /**
+ * This sequence performs as indicated:
+ * + lock(m)
+ * + lock(m) - deadlocks or timeouts
+ * + unlock(m) - releases
+ */
+ CORE_MUTEX_NESTING_BLOCKS
+} CORE_mutex_Nesting_behaviors;
+
+/**
+ * This is the value of a mutex when it is unlocked.
+ */
+#define CORE_MUTEX_UNLOCKED 1
+
+/**
+ * This is the value of a mutex when it is locked.
+ */
+#define CORE_MUTEX_LOCKED 0
+
+/**
+ * @brief Core Mutex Attributes
+ *
+ * The following defines the control block used to manage the
+ * attributes of each mutex.
+ */
+typedef struct {
+ /** This field determines what the behavior of this mutex instance will
+ * be when attempting to acquire the mutex when it is already locked.
+ */
+ CORE_mutex_Nesting_behaviors lock_nesting_behavior;
+ /** When this field is true, then only the thread that locked the mutex
+ * is allowed to unlock it.
+ */
+ bool only_owner_release;
+ /** This field indicates whether threads waiting on the mutex block in
+ * FIFO or priority order.
+ */
+ CORE_mutex_Disciplines discipline;
+ /** This field contains the ceiling priority to be used if that protocol
+ * is selected.
+ */
+ Priority_Control priority_ceiling;
+} CORE_mutex_Attributes;
+
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+/*@brief Core Mutex Lock_Chain Struct
+ *
+ * The following defines the control block used to manage lock chain of
+ * priority inheritance mutex.
+ */
+ typedef struct{
+ /** This field is a chian of locked mutex by a thread,new mutex will
+ * be added to the head of queue, and the mutex which will be released
+ * must be the head of queue.
+ */
+ Chain_Node lock_queue;
+ /** This field is the priority of thread before locking this mutex
+ *
+ */
+ Priority_Control priority_before;
+ } CORE_mutex_order_list;
+#endif
+
+/**
+ * @brief Core Mutex Control Structure
+ *
+ * The following defines the control block used to manage each mutex.
+ */
+typedef struct {
+ /** This field is the Waiting Queue used to manage the set of tasks
+ * which are blocked waiting to lock the mutex.
+ */
+ Thread_queue_Control Wait_queue;
+ /** This element is the set of attributes which define this instance's
+ * behavior.
+ */
+ CORE_mutex_Attributes Attributes;
+ /** This element contains the current state of the mutex.
+ */
+ uint32_t lock;
+ /** This element contains the number of times the mutex has been acquired
+ * nested. This must be zero (0) before the mutex is actually unlocked.
+ */
+ uint32_t nest_count;
+ /** This is the number of waiting threads. */
+ uint32_t blocked_count;
+ /** This element points to the thread which is currently holding this mutex.
+ * The holder is the last thread to successfully lock the mutex and which
+ * has not unlocked it. If the thread is not locked, there is no holder.
+ */
+ Thread_Control *holder;
+ /** This element contains the object Id of the holding thread. */
+ Objects_Id holder_id;
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ /** This field is used to manipulate the priority inheritance mutex queue*/
+ CORE_mutex_order_list queue;
+#endif
+
+} CORE_mutex_Control;
+
+/**
+ * @brief Initialize a Core Mutex
+ *
+ * This routine initializes the mutex based on the parameters passed.
+ *
+ * @param[in] the_mutex is the mutex to initalize
+ * @param[in] the_mutex_attributes is the attributes associated with this
+ * mutex instance
+ * @param[in] initial_lock is the initial value of the mutex
+ *
+ * @return This method returns CORE_MUTEX_STATUS_SUCCESSFUL if successful.
+ */
+CORE_mutex_Status _CORE_mutex_Initialize(
+ CORE_mutex_Control *the_mutex,
+ CORE_mutex_Attributes *the_mutex_attributes,
+ uint32_t initial_lock
+);
+
+#ifndef __RTEMS_APPLICATION__
+/**
+ * @brief Seize Mutex with Quick Success Path
+ *
+ * This routine attempts to receive a unit from the_mutex.
+ * If a unit is available or if the wait flag is false, then the routine
+ * returns. Otherwise, the calling task is blocked until a unit becomes
+ * available.
+ *
+ * @param[in] the_mutex is the mutex to attempt to lock
+ * @param[in] level_p is the interrupt level holder
+ *
+ * @return This routine returns 0 if "trylock" can resolve whether or not
+ * the mutex is immediately obtained or there was an error attempting to
+ * get it. It returns 1 to indicate that the caller cannot obtain
+ * the mutex and will have to block to do so.
+ *
+ * @note For performance reasons, this routine is implemented as
+ * a macro that uses two support routines.
+ */
+
+RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
+ CORE_mutex_Control *the_mutex,
+ ISR_Level *level_p
+);
+
+#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
+ /**
+ * When doing test coverage analysis or trying to minimize the code
+ * space for RTEMS, it is often helpful to not inline this method
+ * multiple times. It is fairly large and has a high branch complexity
+ * which makes it harder to get full binary test coverage.
+ *
+ * @param[in] the_mutex will attempt to lock
+ * @param[in] level_p is the interrupt level holder
+ */
+ int _CORE_mutex_Seize_interrupt_trylock(
+ CORE_mutex_Control *the_mutex,
+ ISR_Level *level_p
+ );
+#else
+ /**
+ * The default is to favor speed and inlining this definitely saves
+ * a few instructions. This is very important for mutex performance.
+ *
+ * @param[in] _mutex will attempt to lock
+ * @param[in] _level_p is the interrupt level holder
+ */
+ #define _CORE_mutex_Seize_interrupt_trylock( _mutex, _level_p ) \
+ _CORE_mutex_Seize_interrupt_trylock_body( _mutex, _level_p )
+#endif
+
+/**
+ * @brief Seize Mutex with Blocking
+ *
+ * This routine performs the blocking portion of a mutex obtain.
+ * It is an actual subroutine and is not implemented as something
+ * that may be inlined.
+ *
+ * @param[in] the_mutex is the mutex to attempt to lock
+ * @param[in] timeout is the maximum number of ticks to block
+ */
+void _CORE_mutex_Seize_interrupt_blocking(
+ CORE_mutex_Control *the_mutex,
+ Watchdog_Interval timeout
+);
+
+/**
+ * @brief Sieze Interrupt Wrapper
+ *
+ * This routine attempts to obtain the mutex. If the mutex is available,
+ * then it will return immediately. Otherwise, it will invoke the
+ * support routine @a _Core_mutex_Seize_interrupt_blocking.
+ *
+ * @param[in] _the_mutex is the mutex to attempt to lock
+ * @param[in] _id is the Id of the owning API level Semaphore object
+ * @param[in] _wait is true if the thread is willing to wait
+ * @param[in] _timeout is the maximum number of ticks to block
+ * @param[in] _level is a temporary variable used to contain the ISR
+ * disable level cookie
+ *
+ * @note If the mutex is called from an interrupt service routine,
+ * with context switching disabled, or before multitasking,
+ * then a fatal error is generated.
+ *
+ * The logic on this routine is as follows:
+ *
+ * * If incorrect system state
+ * return an error
+ * * If mutex is available without any contention or blocking
+ * obtain it with interrupts disabled and returned
+ * * If the caller is willing to wait
+ * then they are blocked.
+ */
+
+#define _CORE_mutex_Seize_body( \
+ _the_mutex, _id, _wait, _timeout, _level ) \
+ do { \
+ if ( _Thread_Dispatch_disable_level \
+ && (_wait) \
+ && (_System_state_Get() >= SYSTEM_STATE_BEGIN_MULTITASKING ) \
+ ) { \
+ _Internal_error_Occurred( \
+ INTERNAL_ERROR_CORE, \
+ false, \
+ INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE \
+ ); \
+ } \
+ if ( _CORE_mutex_Seize_interrupt_trylock( _the_mutex, &_level ) ) { \
+ if ( !_wait ) { \
+ _ISR_Enable( _level ); \
+ _Thread_Executing->Wait.return_code = \
+ CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT; \
+ } else { \
+ _Thread_queue_Enter_critical_section( &(_the_mutex)->Wait_queue ); \
+ _Thread_Executing->Wait.queue = &(_the_mutex)->Wait_queue; \
+ _Thread_Executing->Wait.id = _id; \
+ _Thread_Disable_dispatch(); \
+ _ISR_Enable( _level ); \
+ _CORE_mutex_Seize_interrupt_blocking( _the_mutex, _timeout ); \
+ } \
+ } \
+ } while (0)
+
+/**
+ * This method is used to obtain a core mutex.
+ *
+ * @param[in] _the_mutex is the mutex to attempt to lock
+ * @param[in] _id is the Id of the owning API level Semaphore object
+ * @param[in] _wait is true if the thread is willing to wait
+ * @param[in] _timeout is the maximum number of ticks to block
+ * @param[in] _level is a temporary variable used to contain the ISR
+ * disable level cookie
+ */
+#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
+ void _CORE_mutex_Seize(
+ CORE_mutex_Control *_the_mutex,
+ Objects_Id _id,
+ bool _wait,
+ Watchdog_Interval _timeout,
+ ISR_Level _level
+ );
+#else
+ #define _CORE_mutex_Seize( _the_mutex, _id, _wait, _timeout, _level ) \
+ _CORE_mutex_Seize_body( _the_mutex, _id, _wait, _timeout, _level )
+#endif
+
+/**
+ * @brief Surrender the Mutex
+ *
+ * This routine frees a unit to the mutex. If a task was blocked waiting for
+ * a unit from this mutex, then that task will be readied and the unit
+ * given to that task. Otherwise, the unit will be returned to the mutex.
+ *
+ * @param[in] the_mutex is the mutex to surrender
+ * @param[in] id is the id of the RTEMS Object associated with this mutex
+ * @param[in] api_mutex_mp_support is the routine that will be called when
+ * unblocking a remote mutex
+ *
+ * @return an indication of whether the routine succeeded or failed
+ */
+CORE_mutex_Status _CORE_mutex_Surrender(
+ CORE_mutex_Control *the_mutex,
+ Objects_Id id,
+ CORE_mutex_API_mp_support_callout api_mutex_mp_support
+);
+
+/**
+ * @brief Flush all waiting threads
+ *
+ * This routine assists in the deletion of a mutex by flushing the associated
+ * wait queue.
+ *
+ * @param[in] the_mutex is the mutex to flush
+ * @param[in] remote_extract_callout is the routine to invoke when a remote
+ * thread is extracted
+ * @param[in] status is the status value which each unblocked thread will
+ * return to its caller.
+ */
+void _CORE_mutex_Flush(
+ CORE_mutex_Control *the_mutex,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+);
+
+#include <rtems/score/coremutex.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/corerwlock.h b/cpukit/score/include/rtems/score/corerwlock.h
new file mode 100644
index 0000000000..f97e4679b8
--- /dev/null
+++ b/cpukit/score/include/rtems/score/corerwlock.h
@@ -0,0 +1,235 @@
+/**
+ * @file rtems/score/corerwlock.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the RWLock Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CORERWLOCK_H
+#define _RTEMS_SCORE_CORERWLOCK_H
+
+/**
+ * @defgroup ScoreRWLock RWLock Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * RWLock services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * The following type defines the callout which the API provides
+ * to support global/multiprocessor operations on RWLocks.
+ */
+typedef void ( *CORE_RWLock_API_mp_support_callout )(
+ Thread_Control *,
+ Objects_Id
+ );
+
+/**
+ * RWLock State.
+ */
+typedef enum {
+ /** This indicates the the RWLock is not currently locked.
+ */
+ CORE_RWLOCK_UNLOCKED,
+ /** This indicates the the RWLock is currently locked for reading.
+ */
+ CORE_RWLOCK_LOCKED_FOR_READING,
+ /** This indicates the the RWLock is currently locked for reading.
+ */
+ CORE_RWLOCK_LOCKED_FOR_WRITING
+} CORE_RWLock_States;
+
+/**
+ * Core RWLock handler return statuses.
+ */
+typedef enum {
+ /** This status indicates that the operation completed successfully. */
+ CORE_RWLOCK_SUCCESSFUL,
+ /** This status indicates that the thread was blocked waiting for an */
+ CORE_RWLOCK_WAS_DELETED,
+ /** This status indicates that the rwlock was not immediately available. */
+ CORE_RWLOCK_UNAVAILABLE,
+ /** This status indicates that the calling task was willing to block
+ * but the operation was unable to complete within the time allotted
+ * because the resource never became available.
+ */
+ CORE_RWLOCK_TIMEOUT
+} CORE_RWLock_Status;
+
+/** This is the last status value.
+ */
+#define CORE_RWLOCK_STATUS_LAST CORE_RWLOCK_TIMEOUT
+
+/**
+ * This is used to denote that a thread is blocking waiting for
+ * read-only access to the RWLock.
+ */
+#define CORE_RWLOCK_THREAD_WAITING_FOR_READ 0
+
+/**
+ * This is used to denote that a thread is blocking waiting for
+ * write-exclusive access to the RWLock.
+ */
+#define CORE_RWLOCK_THREAD_WAITING_FOR_WRITE 1
+
+/**
+ * The following defines the control block used to manage the
+ * attributes of each RWLock.
+ */
+typedef struct {
+ /** This field indicates XXX.
+ */
+ int XXX;
+} CORE_RWLock_Attributes;
+
+/**
+ * The following defines the control block used to manage each
+ * RWLock.
+ */
+typedef struct {
+ /** This field is the Waiting Queue used to manage the set of tasks
+ * which are blocked waiting for the RWLock to be released.
+ */
+ Thread_queue_Control Wait_queue;
+ /** This element is the set of attributes which define this instance's
+ * behavior.
+ */
+ CORE_RWLock_Attributes Attributes;
+ /** This element is the current state of the RWLock.
+ */
+ CORE_RWLock_States current_state;
+ /** This element contains the current number of thread waiting for this
+ * RWLock to be released. */
+ uint32_t number_of_readers;
+} CORE_RWLock_Control;
+
+/**
+ * This routine initializes the RWLock based on the parameters passed.
+ *
+ * @param[in] the_rwlock is the RWLock to initialize
+ * @param[in] the_rwlock_attributes define the behavior of this instance
+ */
+void _CORE_RWLock_Initialize(
+ CORE_RWLock_Control *the_rwlock,
+ CORE_RWLock_Attributes *the_rwlock_attributes
+);
+
+/**
+ * This routine attempts to obtain the RWLock for read access.
+ *
+ * @param[in] the_rwlock is the RWLock to wait for
+ * @param[in] id is the id of the object being waited upon
+ * @param[in] wait is true if the calling thread is willing to wait
+ * @param[in] timeout is the number of ticks the calling thread is willing
+ * to wait if @a wait is true.
+ * @param[in] api_rwlock_mp_support is the routine to invoke if the
+ * thread unblocked is remote
+ *
+ * @note Status is returned via the thread control block.
+ */
+void _CORE_RWLock_Obtain_for_reading(
+ CORE_RWLock_Control *the_rwlock,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ CORE_RWLock_API_mp_support_callout api_rwlock_mp_support
+);
+
+/**
+ * This routine attempts to obtain the RWLock for write exclusive access.
+ *
+ * @param[in] the_rwlock is the RWLock to wait for
+ * @param[in] id is the id of the object being waited upon
+ * @param[in] wait is true if the calling thread is willing to wait
+ * @param[in] timeout is the number of ticks the calling thread is willing
+ * to wait if @a wait is true.
+ * @param[in] api_rwlock_mp_support is the routine to invoke if the
+ * thread unblocked is remote
+ *
+ * @note Status is returned via the thread control block.
+ */
+void _CORE_RWLock_Obtain_for_writing(
+ CORE_RWLock_Control *the_rwlock,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ CORE_RWLock_API_mp_support_callout api_rwlock_mp_support
+);
+
+/**
+ * This routine manually releases the RWLock. All of the threads waiting
+ * for the RWLock will be readied.
+ *
+ * @param[in] the_rwlock is the RWLock to surrender
+ *
+ * @return Status is returned to indicate successful or failure.
+ */
+CORE_RWLock_Status _CORE_RWLock_Release(
+ CORE_RWLock_Control *the_rwlock
+);
+
+/**
+ * This routine assists in the deletion of a RWLock by flushing the
+ * associated wait queue.
+ *
+ * @param[in] _the_rwlock is the RWLock to flush
+ * @param[in] _remote_extract_callout is the routine to invoke if the
+ * thread unblocked is remote
+ * @param[in] _status is the status to be returned to the unblocked thread
+ */
+#define _CORE_RWLock_Flush( _the_rwlock, _remote_extract_callout, _status) \
+ _Thread_queue_Flush( \
+ &((_the_rwlock)->Wait_queue), \
+ (_remote_extract_callout), \
+ (_status) \
+ )
+
+/**
+ * @brief RWLock Specific Thread Queue Timeout
+ *
+ * This routine processes a thread which timeouts while waiting on
+ * an RWLock's thread queue. It is called by the watchdog handler.
+ *
+ * @param[in] id is the Id of thread to timeout
+ * @param[in] ignored is an unused pointer to a caller defined area
+ */
+
+void _CORE_RWLock_Timeout(
+ Objects_Id id,
+ void *ignored
+);
+
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/corerwlock.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/coresem.h b/cpukit/score/include/rtems/score/coresem.h
new file mode 100644
index 0000000000..cf89e629d7
--- /dev/null
+++ b/cpukit/score/include/rtems/score/coresem.h
@@ -0,0 +1,209 @@
+/**
+ * @file rtems/score/coresem.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Counting Semaphore Handler. A counting semaphore is the
+ * standard Dijkstra binary semaphore used to provide synchronization
+ * and mutual exclusion capabilities.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CORESEM_H
+#define _RTEMS_SCORE_CORESEM_H
+
+/**
+ * @defgroup ScoreSemaphore Semaphore Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * Semaphore services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/watchdog.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY
+#endif
+
+/**
+ * The following type defines the callout which the API provides
+ * to support global/multiprocessor operations on semaphores.
+ */
+typedef void ( *CORE_semaphore_API_mp_support_callout )(
+ Thread_Control *,
+ Objects_Id
+ );
+
+/**
+ * Blocking disciplines for a semaphore.
+ */
+typedef enum {
+ /** This specifies that threads will wait for the semaphore in FIFO order. */
+ CORE_SEMAPHORE_DISCIPLINES_FIFO,
+ /** This specifies that threads will wait for the semaphore in
+ * priority order.
+ */
+ CORE_SEMAPHORE_DISCIPLINES_PRIORITY
+} CORE_semaphore_Disciplines;
+
+/**
+ * Core Semaphore handler return statuses.
+ */
+typedef enum {
+ /** This status indicates that the operation completed successfully. */
+ CORE_SEMAPHORE_STATUS_SUCCESSFUL,
+ /** This status indicates that the calling task did not want to block
+ * and the operation was unable to complete immediately because the
+ * resource was unavailable.
+ */
+ CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT,
+ /** This status indicates that the thread was blocked waiting for an
+ * operation to complete and the semaphore was deleted.
+ */
+ CORE_SEMAPHORE_WAS_DELETED,
+ /** This status indicates that the calling task was willing to block
+ * but the operation was unable to complete within the time allotted
+ * because the resource never became available.
+ */
+ CORE_SEMAPHORE_TIMEOUT,
+ /** This status indicates that an attempt was made to unlock the semaphore
+ * and this would have made its count greater than that allowed.
+ */
+ CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
+} CORE_semaphore_Status;
+
+/**
+ * @brief Core Semaphore Last Status
+ *
+ * This is the last status value.
+ */
+#define CORE_SEMAPHORE_STATUS_LAST CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
+
+/**
+ * The following defines the control block used to manage the
+ * attributes of each semaphore.
+ */
+typedef struct {
+ /** This element indicates the maximum count this semaphore may have. */
+ uint32_t maximum_count;
+ /** This field indicates whether threads waiting on the semaphore block in
+ * FIFO or priority order.
+ */
+ CORE_semaphore_Disciplines discipline;
+} CORE_semaphore_Attributes;
+
+/**
+ * The following defines the control block used to manage each
+ * counting semaphore.
+ */
+typedef struct {
+ /** This field is the Waiting Queue used to manage the set of tasks
+ * which are blocked waiting to obtain the semaphore.
+ */
+ Thread_queue_Control Wait_queue;
+ /** This element is the set of attributes which define this instance's
+ * behavior.
+ */
+ CORE_semaphore_Attributes Attributes;
+ /** This element contains the current count of this semaphore. */
+ uint32_t count;
+} CORE_semaphore_Control;
+
+/**
+ * This routine initializes the semaphore based on the parameters passed.
+ *
+ * @param[in] the_semaphore is the semaphore to initialize
+ * @param[in] the_semaphore_attributes define the behavior of this instance
+ * @param[in] initial_value is the initial count of the semaphore
+ */
+void _CORE_semaphore_Initialize(
+ CORE_semaphore_Control *the_semaphore,
+ CORE_semaphore_Attributes *the_semaphore_attributes,
+ uint32_t initial_value
+);
+
+#if defined(RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY)
+ /**
+ * This routine attempts to receive a unit from @a the_semaphore.
+ * If a unit is available or if the wait flag is false, then the routine
+ * returns. Otherwise, the calling task is blocked until a unit becomes
+ * available.
+ *
+ * @param[in] the_semaphore is the semaphore to seize
+ * @param[in] id is the Id of the API level Semaphore object associated
+ * with this instance of a SuperCore Semaphore
+ * @param[in] wait indicates if the caller is willing to block
+ * @param[in] timeout is the number of ticks the calling thread is willing
+ * to wait if @a wait is true.
+ */
+ void _CORE_semaphore_Seize(
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout
+ );
+#endif
+
+/**
+ * This routine frees a unit to the semaphore. If a task was blocked waiting
+ * for a unit from this semaphore, then that task will be readied and the unit
+ * given to that task. Otherwise, the unit will be returned to the semaphore.
+ *
+ * @param[in] the_semaphore is the semaphore to surrender
+ * @param[in] id is the Id of the API level Semaphore object associated
+ * with this instance of a SuperCore Semaphore
+ * @param[in] api_semaphore_mp_support is the routine to invoke if the
+ * thread unblocked is remote
+ *
+ * @return an indication of whether the routine succeeded or failed
+ */
+CORE_semaphore_Status _CORE_semaphore_Surrender(
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ CORE_semaphore_API_mp_support_callout api_semaphore_mp_support
+);
+
+/**
+ * This routine assists in the deletion of a semaphore by flushing the
+ * associated wait queue.
+ *
+ * @param[in] the_semaphore is the semaphore to flush
+ * @param[in] remote_extract_callout is the routine to invoke if the
+ * thread unblocked is remote
+ * @param[in] status is the status to be returned to the unblocked thread
+ */
+void _CORE_semaphore_Flush(
+ CORE_semaphore_Control *the_semaphore,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/coresem.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/corespinlock.h b/cpukit/score/include/rtems/score/corespinlock.h
new file mode 100644
index 0000000000..e8ba1fde07
--- /dev/null
+++ b/cpukit/score/include/rtems/score/corespinlock.h
@@ -0,0 +1,163 @@
+/**
+ * @file rtems/score/corespinlock.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Spinlock Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CORESPINLOCK_H
+#define _RTEMS_SCORE_CORESPINLOCK_H
+
+/**
+ * @defgroup ScoreSpinlock Spinlock Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * Spinlock services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/thread.h>
+#include <rtems/score/priority.h>
+
+/**
+ * Core Spinlock handler return statuses.
+ */
+typedef enum {
+ /** This status indicates that the operation completed successfully. */
+ CORE_SPINLOCK_SUCCESSFUL,
+ /** This status indicates that the current thread already holds the spinlock.
+ * An attempt to relock it will result in deadlock.
+ */
+ CORE_SPINLOCK_HOLDER_RELOCKING,
+ /** This status indicates that the current thread is attempting to unlock a
+ * spinlock that is held by another thread.
+ */
+ CORE_SPINLOCK_NOT_HOLDER,
+ /** This status indicates that a thread reached the limit of time it
+ * was willing to wait on the spin lock.
+ */
+ CORE_SPINLOCK_TIMEOUT,
+ /** This status indicates that a thread is currently waiting for this
+ * spin lock.
+ */
+ CORE_SPINLOCK_IS_BUSY,
+ /** This status indicates that the spinlock is currently locked and thus
+ * unavailable.
+ */
+ CORE_SPINLOCK_UNAVAILABLE,
+ /** This status indicates that the spinlock is not currently locked and thus
+ * should not be released.
+ */
+ CORE_SPINLOCK_NOT_LOCKED
+} CORE_spinlock_Status;
+
+/** This is a shorthand for the last status code. */
+#define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_NOT_LOCKED
+
+/** This indicates the lock is available. */
+#define CORE_SPINLOCK_UNLOCKED 0
+
+/** This indicates the lock is unavailable. */
+#define CORE_SPINLOCK_LOCKED 1
+
+/**
+ * The following defines the control block used to manage the
+ * attributes of each spinlock.
+ */
+typedef struct {
+ /** This element indicates XXX
+ */
+ uint32_t XXX;
+} CORE_spinlock_Attributes;
+
+/**
+ * The following defines the control block used to manage each
+ * spinlock.
+ */
+typedef struct {
+ /** XXX may not be needed */
+ CORE_spinlock_Attributes Attributes;
+
+ /** This field is the lock.
+ */
+ volatile uint32_t lock;
+
+ /** This field is a count of the current number of threads using
+ * this spinlock. It includes the thread holding the lock as well
+ * as those waiting.
+ */
+ volatile uint32_t users;
+
+ /** This field is the Id of the thread holding the lock. It may or may
+ * not be the thread which acquired it.
+ */
+ volatile Objects_Id holder;
+} CORE_spinlock_Control;
+
+/**
+ * This routine initializes the spinlock based on the parameters passed.
+ *
+ * @param[in] the_spinlock is the spinlock to initialize
+ * @param[in] the_spinlock_attributes define the behavior of this instance
+ */
+void _CORE_spinlock_Initialize(
+ CORE_spinlock_Control *the_spinlock,
+ CORE_spinlock_Attributes *the_spinlock_attributes
+);
+
+/**
+ * This routine wait for the spinlock to be released. If the spinlock
+ * is set to automatic and this is the appropriate thread, then it returns
+ * immediately. Otherwise, the calling thread is blocked until the spinlock
+ * is released.
+ *
+ * @param[in] the_spinlock is the spinlock to wait for
+ * @param[in] wait is true if willing to wait
+ * @param[in] timeout is the maximum number of ticks to spin (0 is forever)
+ *
+ * @return A status is returned which indicates the success or failure of
+ * this operation.
+ */
+CORE_spinlock_Status _CORE_spinlock_Wait(
+ CORE_spinlock_Control *the_spinlock,
+ bool wait,
+ Watchdog_Interval timeout
+);
+
+/**
+ * This routine manually releases the spinlock. All of the threads waiting
+ * for the spinlock will be readied.
+ *
+ * @param[in] the_spinlock is the spinlock to surrender
+ */
+CORE_spinlock_Status _CORE_spinlock_Release(
+ CORE_spinlock_Control *the_spinlock
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/corespinlock.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
new file mode 100644
index 0000000000..6eee1c745b
--- /dev/null
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -0,0 +1,662 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_HEAP_H
+#define _RTEMS_SCORE_HEAP_H
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef RTEMS_DEBUG
+ #define HEAP_PROTECTION
+#endif
+
+/**
+ * @defgroup ScoreHeap Heap Handler
+ *
+ * @ingroup Score
+ *
+ * @brief The Heap Handler provides a heap.
+ *
+ * A heap is a doubly linked list of variable size blocks which are allocated
+ * using the first fit method. Garbage collection is performed each time a
+ * block is returned to the heap by coalescing neighbor blocks. Control
+ * information for both allocated and free blocks is contained in the heap
+ * area. A heap control structure contains control information for the heap.
+ *
+ * The alignment routines could be made faster should we require only powers of
+ * two to be supported for page size, alignment and boundary arguments. The
+ * minimum alignment requirement for pages is currently CPU_ALIGNMENT and this
+ * value is only required to be multiple of two and explicitly not required to
+ * be a power of two.
+ *
+ * There are two kinds of blocks. One sort describes a free block from which
+ * we can allocate memory. The other blocks are used and provide an allocated
+ * memory area. The free blocks are accessible via a list of free blocks.
+ *
+ * Blocks or areas cover a continuous set of memory addresses. They have a
+ * begin and end address. The end address is not part of the set. The size of
+ * a block or area equals the distance between the begin and end address in
+ * units of bytes.
+ *
+ * Free blocks look like:
+ * <table>
+ * <tr>
+ * <td rowspan=4>@ref Heap_Block</td><td>previous block size in case the
+ * previous block is free, <br> otherwise it may contain data used by
+ * the previous block</td>
+ * </tr>
+ * <tr>
+ * <td>block size and a flag which indicates if the previous block is free
+ * or used, <br> this field contains always valid data regardless of the
+ * block usage</td>
+ * </tr>
+ * <tr><td>pointer to next block (this field is page size aligned)</td></tr>
+ * <tr><td>pointer to previous block</td></tr>
+ * <tr><td colspan=2>free space</td></tr>
+ * </table>
+ *
+ * Used blocks look like:
+ * <table>
+ * <tr>
+ * <td rowspan=4>@ref Heap_Block</td><td>previous block size in case the
+ * previous block is free,<br>otherwise it may contain data used by
+ * the previous block</td>
+ * </tr>
+ * <tr>
+ * <td>block size and a flag which indicates if the previous block is free
+ * or used, <br> this field contains always valid data regardless of the
+ * block usage</td>
+ * </tr>
+ * <tr><td>begin of allocated area (this field is page size aligned)</td></tr>
+ * <tr><td>allocated space</td></tr>
+ * <tr><td colspan=2>allocated space</td></tr>
+ * </table>
+ *
+ * The heap area after initialization contains two blocks and looks like:
+ * <table>
+ * <tr><th>Label</th><th colspan=2>Content</th></tr>
+ * <tr><td>heap->area_begin</td><td colspan=2>heap area begin address</td></tr>
+ * <tr>
+ * <td>first_block->prev_size</td>
+ * <td colspan=2>
+ * subordinate heap area end address (this will be used to maintain a
+ * linked list of scattered heap areas)
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>first_block->size</td>
+ * <td colspan=2>size available for allocation
+ * | @c HEAP_PREV_BLOCK_USED</td>
+ * </tr>
+ * <tr>
+ * <td>first_block->next</td><td>_Heap_Free_list_tail(heap)</td>
+ * <td rowspan=3>memory area available for allocation</td>
+ * </tr>
+ * <tr><td>first_block->prev</td><td>_Heap_Free_list_head(heap)</td></tr>
+ * <tr><td>...</td></tr>
+ * <tr>
+ * <td>last_block->prev_size</td><td colspan=2>size of first block</td>
+ * </tr>
+ * <tr>
+ * <td>last_block->size</td>
+ * <td colspan=2>first block begin address - last block begin address</td>
+ * </tr>
+ * <tr><td>heap->area_end</td><td colspan=2>heap area end address</td></tr>
+ * </table>
+ * The next block of the last block is the first block. Since the first
+ * block indicates that the previous block is used, this ensures that the
+ * last block appears as used for the _Heap_Is_used() and _Heap_Is_free()
+ * functions.
+ *
+ * @{
+ */
+
+typedef struct Heap_Control Heap_Control;
+
+typedef struct Heap_Block Heap_Block;
+
+#ifndef HEAP_PROTECTION
+ #define HEAP_PROTECTION_HEADER_SIZE 0
+#else
+ #define HEAP_PROTECTOR_COUNT 2
+
+ #define HEAP_BEGIN_PROTECTOR_0 ((uintptr_t) 0xfd75a98f)
+ #define HEAP_BEGIN_PROTECTOR_1 ((uintptr_t) 0xbfa1f177)
+ #define HEAP_END_PROTECTOR_0 ((uintptr_t) 0xd6b8855e)
+ #define HEAP_END_PROTECTOR_1 ((uintptr_t) 0x13a44a5b)
+
+ #define HEAP_FREE_PATTERN ((uintptr_t) 0xe7093cdf)
+
+ #define HEAP_PROTECTION_OBOLUS ((Heap_Block *) 1)
+
+ typedef void (*_Heap_Protection_handler)(
+ Heap_Control *heap,
+ Heap_Block *block
+ );
+
+ typedef struct {
+ _Heap_Protection_handler block_initialize;
+ _Heap_Protection_handler block_check;
+ _Heap_Protection_handler block_error;
+ void *handler_data;
+ Heap_Block *first_delayed_free_block;
+ Heap_Block *last_delayed_free_block;
+ uintptr_t delayed_free_block_count;
+ } Heap_Protection;
+
+ typedef struct {
+ uintptr_t protector [HEAP_PROTECTOR_COUNT];
+ Heap_Block *next_delayed_free_block;
+ Thread_Control *task;
+ void *tag;
+ } Heap_Protection_block_begin;
+
+ typedef struct {
+ uintptr_t protector [HEAP_PROTECTOR_COUNT];
+ } Heap_Protection_block_end;
+
+ #define HEAP_PROTECTION_HEADER_SIZE \
+ (sizeof(Heap_Protection_block_begin) + sizeof(Heap_Protection_block_end))
+#endif
+
+/**
+ * @brief See also @ref Heap_Block.size_and_flag.
+ */
+#define HEAP_PREV_BLOCK_USED ((uintptr_t) 1)
+
+/**
+ * @brief Size of the part at the block begin which may be used for allocation
+ * in charge of the previous block.
+ */
+#define HEAP_ALLOC_BONUS sizeof(uintptr_t)
+
+/**
+ * @brief The block header consists of the two size fields
+ * (@ref Heap_Block.prev_size and @ref Heap_Block.size_and_flag).
+ */
+#define HEAP_BLOCK_HEADER_SIZE \
+ (2 * sizeof(uintptr_t) + HEAP_PROTECTION_HEADER_SIZE)
+
+/**
+ * @brief Description for free or used blocks.
+ */
+struct Heap_Block {
+ /**
+ * @brief Size of the previous block or part of the allocated area of the
+ * previous block.
+ *
+ * This field is only valid if the previous block is free. This case is
+ * indicated by a cleared @c HEAP_PREV_BLOCK_USED flag in the
+ * @a size_and_flag field of the current block.
+ *
+ * In a used block only the @a size_and_flag field needs to be valid. The
+ * @a prev_size field of the current block is maintained by the previous
+ * block. The current block can use the @a prev_size field in the next block
+ * for allocation.
+ */
+ uintptr_t prev_size;
+
+ #ifdef HEAP_PROTECTION
+ Heap_Protection_block_begin Protection_begin;
+ #endif
+
+ /**
+ * @brief Contains the size of the current block and a flag which indicates
+ * if the previous block is free or used.
+ *
+ * If the flag @c HEAP_PREV_BLOCK_USED is set, then the previous block is
+ * used, otherwise the previous block is free. A used previous block may
+ * claim the @a prev_size field for allocation. This trick allows to
+ * decrease the overhead in the used blocks by the size of the @a prev_size
+ * field. As sizes are required to be multiples of two, the least
+ * significant bits would be always zero. We use this bit to store the flag.
+ *
+ * This field is always valid.
+ */
+ uintptr_t size_and_flag;
+
+ #ifdef HEAP_PROTECTION
+ Heap_Protection_block_end Protection_end;
+ #endif
+
+ /**
+ * @brief Pointer to the next free block or part of the allocated area.
+ *
+ * This field is page size aligned and begins of the allocated area in case
+ * the block is used.
+ *
+ * This field is only valid if the block is free and thus part of the free
+ * block list.
+ */
+ Heap_Block *next;
+
+ /**
+ * @brief Pointer to the previous free block or part of the allocated area.
+ *
+ * This field is only valid if the block is free and thus part of the free
+ * block list.
+ */
+ Heap_Block *prev;
+};
+
+/**
+ * @brief Run-time heap statistics.
+ *
+ * The value @a searches / @a allocs gives the mean number of searches per
+ * allocation, while @a max_search gives maximum number of searches ever
+ * performed on a single allocation call.
+ */
+typedef struct {
+ /**
+ * @brief Instance number of this heap.
+ */
+ uint32_t instance;
+
+ /**
+ * @brief Size of the allocatable area in bytes.
+ *
+ * This value is an integral multiple of the page size.
+ */
+ uintptr_t size;
+
+ /**
+ * @brief Current free size in bytes.
+ *
+ * This value is an integral multiple of the page size.
+ */
+ uintptr_t free_size;
+
+ /**
+ * @brief Minimum free size ever in bytes.
+ *
+ * This value is an integral multiple of the page size.
+ */
+ uintptr_t min_free_size;
+
+ /**
+ * @brief Current number of free blocks.
+ */
+ uint32_t free_blocks;
+
+ /**
+ * @brief Maximum number of free blocks ever.
+ */
+ uint32_t max_free_blocks;
+
+ /**
+ * @brief Current number of used blocks.
+ */
+ uint32_t used_blocks;
+
+ /**
+ * @brief Maximum number of blocks searched ever.
+ */
+ uint32_t max_search;
+
+ /**
+ * @brief Total number of successful allocations.
+ */
+ uint32_t allocs;
+
+ /**
+ * @brief Total number of searches ever.
+ */
+ uint32_t searches;
+
+ /**
+ * @brief Total number of suceessful calls to free.
+ */
+ uint32_t frees;
+
+ /**
+ * @brief Total number of successful resizes.
+ */
+ uint32_t resizes;
+} Heap_Statistics;
+
+/**
+ * @brief Control block used to manage a heap.
+ */
+struct Heap_Control {
+ Heap_Block free_list;
+ uintptr_t page_size;
+ uintptr_t min_block_size;
+ uintptr_t area_begin;
+ uintptr_t area_end;
+ Heap_Block *first_block;
+ Heap_Block *last_block;
+ Heap_Statistics stats;
+ #ifdef HEAP_PROTECTION
+ Heap_Protection Protection;
+ #endif
+};
+
+/**
+ * @brief Information about blocks.
+ */
+typedef struct {
+ /**
+ * @brief Number of blocks of this type.
+ */
+ uint32_t number;
+
+ /**
+ * @brief Largest block of this type.
+ */
+ uint32_t largest;
+
+ /**
+ * @brief Total size of the blocks of this type.
+ */
+ uint32_t total;
+} Heap_Information;
+
+/**
+ * @brief Information block returned by _Heap_Get_information().
+ */
+typedef struct {
+ Heap_Information Free;
+ Heap_Information Used;
+} Heap_Information_block;
+
+/**
+ * @brief See _Heap_Resize_block().
+ */
+typedef enum {
+ HEAP_RESIZE_SUCCESSFUL,
+ HEAP_RESIZE_UNSATISFIED,
+ HEAP_RESIZE_FATAL_ERROR
+} Heap_Resize_status;
+
+/**
+ * @brief Gets the first and last block for the heap area with begin
+ * @a heap_area_begin and size @a heap_area_size.
+ *
+ * A page size of @a page_size and minimal block size of @a min_block_size will
+ * be used for calculation.
+ *
+ * Nothing will be written to this area.
+ *
+ * In case of success the pointers to the first and last block will be returned
+ * via @a first_block_ptr and @a last_block_ptr.
+ *
+ * Returns @c true if the area is big enough, and @c false otherwise.
+ */
+bool _Heap_Get_first_and_last_block(
+ uintptr_t heap_area_begin,
+ uintptr_t heap_area_size,
+ uintptr_t page_size,
+ uintptr_t min_block_size,
+ Heap_Block **first_block_ptr,
+ Heap_Block **last_block_ptr
+);
+
+/**
+ * @brief Initializes the heap control block @a heap to manage the area
+ * starting at @a area_begin of size @a area_size bytes.
+ *
+ * Blocks of memory are allocated from the heap in multiples of @a page_size
+ * byte units. If the @a page_size is equal to zero or is not multiple of
+ * @c CPU_ALIGNMENT, it is aligned up to the nearest @c CPU_ALIGNMENT boundary.
+ *
+ * Returns the maximum memory available, or zero in case of failure.
+ */
+uintptr_t _Heap_Initialize(
+ Heap_Control *heap,
+ void *area_begin,
+ uintptr_t area_size,
+ uintptr_t page_size
+);
+
+/**
+ * @brief Extends the memory available for the heap @a heap using the memory
+ * area starting at @a area_begin of size @a area_size bytes.
+ *
+ * The extended space available for allocation will be returned in
+ * @a amount_extended. This pointer may be @c NULL.
+ *
+ * There are no alignment requirements. The memory area must be big enough to
+ * contain some maintainance blocks. It must not overlap parts of the current
+ * heap areas. Disconnected subordinate heap areas will lead to used blocks
+ * which cover the gaps. Extending with an inappropriate memory area will
+ * corrupt the heap.
+ *
+ * Returns @c true in case of success, and @c false otherwise.
+ */
+bool _Heap_Extend(
+ Heap_Control *heap,
+ void *area_begin,
+ uintptr_t area_size,
+ uintptr_t *amount_extended
+);
+
+/**
+ * @brief Allocates a memory area of size @a size bytes from the heap @a heap.
+ *
+ * If the alignment parameter @a alignment is not equal to zero, the allocated
+ * memory area will begin at an address aligned by this value.
+ *
+ * If the boundary parameter @a boundary is not equal to zero, the allocated
+ * memory area will fulfill a boundary constraint. The boundary value
+ * specifies the set of addresses which are aligned by the boundary value. The
+ * interior of the allocated memory area will not contain an element of this
+ * set. The begin or end address of the area may be a member of the set.
+ *
+ * A size value of zero will return a unique address which may be freed with
+ * _Heap_Free().
+ *
+ * Returns a pointer to the begin of the allocated memory area, or @c NULL if
+ * no memory is available or the parameters are inconsistent.
+ */
+void *_Heap_Allocate_aligned_with_boundary(
+ Heap_Control *heap,
+ uintptr_t size,
+ uintptr_t alignment,
+ uintptr_t boundary
+);
+
+/**
+ * @brief See _Heap_Allocate_aligned_with_boundary() with boundary equals zero.
+ */
+RTEMS_INLINE_ROUTINE void *_Heap_Allocate_aligned(
+ Heap_Control *heap,
+ uintptr_t size,
+ uintptr_t alignment
+)
+{
+ return _Heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 );
+}
+
+/**
+ * @brief See _Heap_Allocate_aligned_with_boundary() with alignment and
+ * boundary equals zero.
+ */
+RTEMS_INLINE_ROUTINE void *_Heap_Allocate( Heap_Control *heap, uintptr_t size )
+{
+ return _Heap_Allocate_aligned_with_boundary( heap, size, 0, 0 );
+}
+
+/**
+ * @brief Frees the allocated memory area starting at @a addr in the heap
+ * @a heap.
+ *
+ * Inappropriate values for @a addr may corrupt the heap.
+ *
+ * Returns @c true in case of success, and @c false otherwise.
+ */
+bool _Heap_Free( Heap_Control *heap, void *addr );
+
+/**
+ * @brief Walks the heap @a heap to verify its integrity.
+ *
+ * If @a dump is @c true, then diagnostic messages will be printed to standard
+ * output. In this case @a source is used to mark the output lines.
+ *
+ * Returns @c true if no errors occured, and @c false if the heap is corrupt.
+ */
+bool _Heap_Walk(
+ Heap_Control *heap,
+ int source,
+ bool dump
+);
+
+/**
+ * @brief Returns information about used and free blocks for the heap @a heap
+ * in @a info.
+ */
+void _Heap_Get_information(
+ Heap_Control *heap,
+ Heap_Information_block *info
+);
+
+/**
+ * @brief Returns information about free blocks for the heap @a heap in
+ * @a info.
+ */
+void _Heap_Get_free_information(
+ Heap_Control *heap,
+ Heap_Information *info
+);
+
+/**
+ * @brief Returns the size of the allocatable memory area starting at @a addr
+ * in @a size.
+ *
+ * The size value may be greater than the initially requested size in
+ * _Heap_Allocate_aligned_with_boundary().
+ *
+ * Inappropriate values for @a addr will not corrupt the heap, but may yield
+ * invalid size values.
+ *
+ * Returns @a true if successful, and @c false otherwise.
+ */
+bool _Heap_Size_of_alloc_area(
+ Heap_Control *heap,
+ void *addr,
+ uintptr_t *size
+);
+
+/**
+ * @brief Resizes the block of the allocated memory area starting at @a addr.
+ *
+ * The new memory area will have a size of at least @a size bytes. A resize
+ * may be impossible and depends on the current heap usage.
+ *
+ * The size available for allocation in the current block before the resize
+ * will be returned in @a old_size. The size available for allocation in
+ * the resized block will be returned in @a new_size. If the resize was not
+ * successful, then a value of zero will be returned in @a new_size.
+ *
+ * Inappropriate values for @a addr may corrupt the heap.
+ */
+Heap_Resize_status _Heap_Resize_block(
+ Heap_Control *heap,
+ void *addr,
+ uintptr_t size,
+ uintptr_t *old_size,
+ uintptr_t *new_size
+);
+
+#if !defined(__RTEMS_APPLICATION__)
+
+#include <rtems/score/heap.inl>
+
+/**
+ * @brief Allocates the memory area starting at @a alloc_begin of size
+ * @a alloc_size bytes in the block @a block.
+ *
+ * The block may be split up into multiple blocks. The previous and next block
+ * may be used or free. Free block parts which form a vaild new block will be
+ * inserted into the free list or merged with an adjacent free block. If the
+ * block is used, they will be inserted after the free list head. If the block
+ * is free, they will be inserted after the previous block in the free list.
+ *
+ * Inappropriate values for @a alloc_begin or @a alloc_size may corrupt the
+ * heap.
+ *
+ * Returns the block containing the allocated memory area.
+ */
+Heap_Block *_Heap_Block_allocate(
+ Heap_Control *heap,
+ Heap_Block *block,
+ uintptr_t alloc_begin,
+ uintptr_t alloc_size
+);
+
+#ifndef HEAP_PROTECTION
+ #define _Heap_Protection_block_initialize( heap, block ) ((void) 0)
+ #define _Heap_Protection_block_check( heap, block ) ((void) 0)
+ #define _Heap_Protection_block_error( heap, block ) ((void) 0)
+#else
+ static inline void _Heap_Protection_block_initialize(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ (*heap->Protection.block_initialize)( heap, block );
+ }
+
+ static inline void _Heap_Protection_block_check(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ (*heap->Protection.block_check)( heap, block );
+ }
+
+ static inline void _Heap_Protection_block_error(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ (*heap->Protection.block_error)( heap, block );
+ }
+#endif
+
+/** @} */
+
+#ifdef RTEMS_DEBUG
+ #define RTEMS_HEAP_DEBUG
+#endif
+
+#ifdef RTEMS_HEAP_DEBUG
+ #include <assert.h>
+ #define _HAssert( cond ) \
+ do { \
+ if ( !(cond) ) { \
+ __assert( __FILE__, __LINE__, #cond ); \
+ } \
+ } while (0)
+#else
+ #define _HAssert( cond ) ((void) 0)
+#endif
+
+#endif /* !defined(__RTEMS_APPLICATION__) */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/interr.h b/cpukit/score/include/rtems/score/interr.h
new file mode 100644
index 0000000000..b98eba8d7a
--- /dev/null
+++ b/cpukit/score/include/rtems/score/interr.h
@@ -0,0 +1,115 @@
+/**
+ * @file rtems/score/interr.h
+ *
+ * This include file contains constants and prototypes related
+ * to the Internal Error Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_INTERR_H
+#define _RTEMS_SCORE_INTERR_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <rtems/system.h>
+
+/**
+ * @defgroup ScoreIntErr Internal Error Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * Semaphore services used in all of the APIs supported by RTEMS.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This type lists the possible sources from which an error
+ * can be reported.
+ */
+typedef enum {
+ INTERNAL_ERROR_CORE,
+ INTERNAL_ERROR_RTEMS_API,
+ INTERNAL_ERROR_POSIX_API
+} Internal_errors_Source;
+
+/**
+ * A list of errors which are generated internally by the executive core.
+ */
+typedef enum {
+ INTERNAL_ERROR_NO_CONFIGURATION_TABLE,
+ INTERNAL_ERROR_NO_CPU_TABLE,
+ INTERNAL_ERROR_TOO_LITTLE_WORKSPACE,
+ INTERNAL_ERROR_WORKSPACE_ALLOCATION,
+ INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL,
+ INTERNAL_ERROR_THREAD_EXITTED,
+ INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION,
+ INTERNAL_ERROR_INVALID_NODE,
+ INTERNAL_ERROR_NO_MPCI,
+ INTERNAL_ERROR_BAD_PACKET,
+ INTERNAL_ERROR_OUT_OF_PACKETS,
+ INTERNAL_ERROR_OUT_OF_GLOBAL_OBJECTS,
+ INTERNAL_ERROR_OUT_OF_PROXIES,
+ INTERNAL_ERROR_INVALID_GLOBAL_ID,
+ INTERNAL_ERROR_BAD_STACK_HOOK,
+ INTERNAL_ERROR_BAD_ATTRIBUTES,
+ INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY,
+ INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL,
+ INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE,
+ INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0,
+ INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP,
+ INTERNAL_ERROR_GXX_KEY_ADD_FAILED,
+ INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED
+} Internal_errors_Core_list;
+
+typedef uint32_t Internal_errors_t;
+
+/**
+ * This type holds the fatal error information.
+ */
+typedef struct {
+ /** This is the source of the error. */
+ Internal_errors_Source the_source;
+ /** This indicates if the error is internal of external. */
+ bool is_internal;
+ /** This is the error code. */
+ Internal_errors_t the_error;
+} Internal_errors_Information;
+
+/**
+ * When a fatal error occurs, the error information is stored here.
+ */
+SCORE_EXTERN Internal_errors_Information _Internal_errors_What_happened;
+
+/** @brief Internal error Occurred
+ *
+ * This routine is invoked when the application or the executive itself
+ * determines that a fatal error has occurred.
+ */
+void _Internal_error_Occurred(
+ Internal_errors_Source the_source,
+ bool is_internal,
+ Internal_errors_t the_error
+) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/isr.h b/cpukit/score/include/rtems/score/isr.h
new file mode 100644
index 0000000000..3da25859ec
--- /dev/null
+++ b/cpukit/score/include/rtems/score/isr.h
@@ -0,0 +1,212 @@
+/**
+ * @file rtems/score/isr.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the management of processor interrupt levels. This handler
+ * supports interrupt critical sections, vectoring of user interrupt
+ * handlers, nesting of interrupts, and manipulating interrupt levels.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_ISR_H
+#define _RTEMS_SCORE_ISR_H
+
+#include <rtems/score/percpu.h>
+
+/**
+ * @defgroup ScoreISR ISR Handler
+ *
+ * This handler encapsulates functionality which provides the foundation
+ * ISR services used in all of the APIs supported by RTEMS.
+ *
+ * The ISR Nest level counter variable is maintained as part of the
+ * per cpu data structure.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following type defines the control block used to manage
+ * the interrupt level portion of the status register.
+ */
+typedef uint32_t ISR_Level;
+
+/**
+ * The following type defines the type used to manage the vectors.
+ */
+typedef uint32_t ISR_Vector_number;
+
+/**
+ * Return type for ISR Handler
+ */
+typedef void ISR_Handler;
+
+/**
+ * Pointer to an ISR Handler
+ */
+#if (CPU_ISR_PASSES_FRAME_POINTER == 1)
+typedef ISR_Handler ( *ISR_Handler_entry )(
+ ISR_Vector_number,
+ CPU_Interrupt_frame *
+ );
+#else
+typedef ISR_Handler ( *ISR_Handler_entry )(
+ ISR_Vector_number
+ );
+#endif
+
+/**
+ * This constant promotes out the number of vectors truly supported by
+ * the current CPU being used. This is usually the number of distinct vectors
+ * the cpu can vector.
+ */
+#define ISR_NUMBER_OF_VECTORS CPU_INTERRUPT_NUMBER_OF_VECTORS
+
+/**
+ * This constant promotes out the highest valid interrupt vector number.
+ */
+#define ISR_INTERRUPT_MAXIMUM_VECTOR_NUMBER CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER
+
+#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
+/**
+ * The following declares the Vector Table. Application
+ * interrupt service routines are vectored by the ISR Handler via this table.
+ */
+SCORE_EXTERN ISR_Handler_entry *_ISR_Vector_table;
+#endif
+
+/**
+ * This routine performs the initialization necessary for this handler.
+ */
+void _ISR_Handler_initialization ( void );
+
+/**
+ * This routine disables all interrupts so that a critical section
+ * of code can be executing without being interrupted. Upon return,
+ * the argument _level will contain the previous interrupt mask level.
+ */
+#define _ISR_Disable( _level ) \
+ do { \
+ _CPU_ISR_Disable( _level ); \
+ RTEMS_COMPILER_MEMORY_BARRIER(); \
+ } while (0)
+
+/**
+ * This routine enables interrupts to the previous interrupt mask
+ * LEVEL. It is used at the end of a critical section of code to
+ * enable interrupts so they can be processed again.
+ */
+#define _ISR_Enable( _level ) \
+ do { \
+ RTEMS_COMPILER_MEMORY_BARRIER(); \
+ _CPU_ISR_Enable( _level ); \
+ } while (0)
+
+/**
+ * This routine temporarily enables interrupts to the previous
+ * interrupt mask level and then disables all interrupts so that
+ * the caller can continue into the second part of a critical
+ * section. This routine is used to temporarily enable interrupts
+ * during a long critical section. It is used in long sections of
+ * critical code when a point is reached at which interrupts can
+ * be temporarily enabled. Deciding where to flash interrupts
+ * in a long critical section is often difficult and the point
+ * must be selected with care to ensure that the critical section
+ * properly protects itself.
+ */
+#define _ISR_Flash( _level ) \
+ do { \
+ RTEMS_COMPILER_MEMORY_BARRIER(); \
+ _CPU_ISR_Flash( _level ); \
+ RTEMS_COMPILER_MEMORY_BARRIER(); \
+ } while (0)
+
+/**
+ * This routine installs new_handler as the interrupt service routine
+ * for the specified vector. The previous interrupt service routine is
+ * returned as old_handler.
+ */
+#define _ISR_Install_vector( _vector, _new_handler, _old_handler ) \
+ _CPU_ISR_install_vector( _vector, _new_handler, _old_handler )
+
+/**
+ * This routine returns the current interrupt level.
+ */
+#define _ISR_Get_level() \
+ _CPU_ISR_Get_level()
+
+/**
+ * This routine sets the current interrupt level to that specified
+ * by new_level. The new interrupt level is effective when the
+ * routine exits.
+ */
+#define _ISR_Set_level( _new_level ) \
+ do { \
+ RTEMS_COMPILER_MEMORY_BARRIER(); \
+ _CPU_ISR_Set_level( _new_level ); \
+ RTEMS_COMPILER_MEMORY_BARRIER(); \
+ } while (0)
+
+
+/**
+ * This routine is the interrupt dispatcher. ALL interrupts
+ * are vectored to this routine so that minimal context can be saved
+ * and setup performed before the application's high-level language
+ * interrupt service routine is invoked. After the application's
+ * interrupt service routine returns control to this routine, it
+ * will determine if a thread dispatch is necessary. If so, it will
+ * ensure that the necessary thread scheduling operations are
+ * performed when the outermost interrupt service routine exits.
+ *
+ * @note Implemented in assembly language.
+ */
+void _ISR_Handler( void );
+
+/**
+ * This routine provides a wrapper so that the routine
+ * @ref _Thread_Dispatch can be invoked when a reschedule is necessary
+ * at the end of the outermost interrupt service routine. This
+ * wrapper is necessary to establish the processor context needed
+ * by _Thread_Dispatch and to save the processor context which is
+ * corrupted by _Thread_Dispatch. This context typically consists
+ * of registers which are not preserved across routine invocations.
+ *
+ * @note Implemented in assembly language.
+ */
+void _ISR_Dispatch( void );
+
+/**
+ * This function returns true if the processor is currently servicing
+ * and interrupt and false otherwise. A return value of true indicates
+ * that the caller is an interrupt service routine, NOT a thread. The
+ */
+#if (CPU_PROVIDES_ISR_IS_IN_PROGRESS == TRUE)
+bool _ISR_Is_in_progress( void );
+#else
+#define _ISR_Is_in_progress() \
+ (_ISR_Nest_level != 0)
+#endif
+
+#include <rtems/score/isr.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/mpci.h b/cpukit/score/include/rtems/score/mpci.h
new file mode 100644
index 0000000000..f763ed89a8
--- /dev/null
+++ b/cpukit/score/include/rtems/score/mpci.h
@@ -0,0 +1,404 @@
+/**
+ * @file rtems/score/mpci.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the MPCI layer. It provides mechanisms to utilize packets.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_MPCI_H
+#define _RTEMS_SCORE_MPCI_H
+
+/**
+ * @defgroup ScoreMPCI MPCI Handler
+ *
+ * The MPCI Handler encapsulates functionality which is related to the
+ * generation, receipt, and processing of remote operations in a
+ * multiprocessor system. This handler contains the message passing
+ * support for making remote service calls as well as the server thread
+ * which processes requests from remote nodes.
+*/
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/mppkt.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * The following defines the node number used when a broadcast is desired.
+ */
+#define MPCI_ALL_NODES 0
+
+/**
+ * For packets associated with requests that don't already have a timeout,
+ * use the one specified by this MPCI driver. The value specified by
+ * the MPCI driver sets an upper limit on how long a remote request
+ * should take to complete.
+ */
+#define MPCI_DEFAULT_TIMEOUT 0xFFFFFFFF
+
+/**
+ * This type is returned by all user provided MPCI routines.
+ */
+typedef void MPCI_Entry;
+
+/**
+ * This type defines the prototype for the initization entry point
+ * in an Multiprocessor Communications Interface.
+ */
+typedef MPCI_Entry ( *MPCI_initialization_entry )( void );
+
+/**
+ * This type defines the prototype for the get packet entry point
+ * in an Multiprocessor Communications Interface. The single
+ * parameter will point to the packet allocated.
+ */
+typedef MPCI_Entry ( *MPCI_get_packet_entry )(
+ MP_packet_Prefix **
+ );
+
+/**
+ * This type defines the prototype for the return packet entry point
+ * in an Multiprocessor Communications Interface. The single
+ * parameter will point to a packet previously allocated by the
+ * get packet MPCI entry.
+ */
+typedef MPCI_Entry ( *MPCI_return_packet_entry )(
+ MP_packet_Prefix *
+ );
+
+/**
+ * This type defines the prototype for send get packet entry point
+ * in an Multiprocessor Communications Interface. The single
+ * parameter will point to a packet previously allocated by the
+ * get packet entry point that has been filled in by the caller.
+ */
+typedef MPCI_Entry ( *MPCI_send_entry )(
+ uint32_t,
+ MP_packet_Prefix *
+ );
+
+/**
+ * This type defines the prototype for the receive packet entry point
+ * in an Multiprocessor Communications Interface. The single
+ * parameter will point to a packet allocated and filled in by the
+ * receive packet handler. The caller will block until a packet is
+ * received.
+ */
+typedef MPCI_Entry ( *MPCI_receive_entry )(
+ MP_packet_Prefix **
+ );
+
+/**
+ * This type defines the Multiprocessor Communications
+ * Interface (MPCI) Table. This table defines the user-provided
+ * MPCI which is a required part of a multiprocessor system.
+ *
+ * For non-blocking local operations that become remote operations,
+ * we need a timeout. This is a per-driver timeout: default_timeout
+ */
+typedef struct {
+ /** This fields contains the timeout for MPCI operations in ticks. */
+ uint32_t default_timeout;
+ /** This field contains the maximum size of a packet supported by this
+ * MPCI layer. This size places a limit on the size of a message
+ * which can be transmitted over this interface.
+ **/
+ size_t maximum_packet_size;
+ /** This field points to the MPCI initialization entry point. */
+ MPCI_initialization_entry initialization;
+ /** This field points to the MPCI get packet entry point. */
+ MPCI_get_packet_entry get_packet;
+ /** This field points to the MPCI return packet entry point. */
+ MPCI_return_packet_entry return_packet;
+ /** This field points to the MPCI send packet entry point. */
+ MPCI_send_entry send_packet;
+ /** This field points to the MPCI receive packet entry point. */
+ MPCI_receive_entry receive_packet;
+} MPCI_Control;
+
+/**
+ * The following defines the type for packet processing routines
+ * invoked by the MPCI Receive server.
+ */
+typedef void (*MPCI_Packet_processor)( MP_packet_Prefix * );
+
+/**
+ * The following enumerated type defines the list of
+ * internal MP operations.
+ */
+typedef enum {
+ MPCI_PACKETS_SYSTEM_VERIFY = 0
+} MPCI_Internal_Remote_operations;
+
+/**
+ * The following data structure defines the packet used to perform
+ * remote event operations.
+ */
+typedef struct {
+ /** This field is the general header for all packets. */
+ MP_packet_Prefix Prefix;
+ /** This value specifies the operation. */
+ MPCI_Internal_Remote_operations operation;
+ /** This is the maximum number of nodes in the system. It must agree
+ * on all nodes.
+ */
+ uint32_t maximum_nodes;
+ /** This field is the maximum number of concurrently existent
+ * globally offered objects.
+ */
+ uint32_t maximum_global_objects;
+} MPCI_Internal_packet;
+
+/**
+ * The following thread queue is used to maintain a list of tasks
+ * which currently have outstanding remote requests.
+ */
+SCORE_EXTERN Thread_queue_Control _MPCI_Remote_blocked_threads;
+
+/**
+ * The following define the internal pointers to the user's
+ * configuration information.
+ */
+SCORE_EXTERN MPCI_Control *_MPCI_table;
+
+/** @brief Pointer to MP Thread Control Block
+ *
+ * The following is used to determine when the multiprocessing receive
+ * thread is executing so that a proxy can be allocated instead of
+ * blocking the multiprocessing receive thread.
+ */
+SCORE_EXTERN Thread_Control *_MPCI_Receive_server_tcb;
+
+/**
+ * The following table contains the process packet routines provided
+ * by each object that supports MP operations.
+ */
+SCORE_EXTERN MPCI_Packet_processor
+ _MPCI_Packet_processors[MP_PACKET_CLASSES_LAST+1];
+
+/**
+ * This routine performs the initialization necessary for this handler.
+ *
+ * @param[in] timeout_status is the value which should be returned to
+ * blocking threads when they timeout on a remote operation.
+ */
+void _MPCI_Handler_initialization(
+ uint32_t timeout_status
+);
+
+/**
+ * This routine creates the packet receive server used in MP systems.
+ */
+void _MPCI_Create_server( void );
+
+/**
+ * This routine initializes the MPCI driver by
+ * invoking the user provided MPCI initialization callout.
+ */
+void _MPCI_Initialization ( void );
+
+/**
+ * This routine registers the MPCI packet processor for the
+ * designated object class.
+ *
+ * @param[in] the_class is the class indicator for packets which will
+ * be processed by @a the_packet_processor method.
+ * @param[in] the_packet_processor is a pointer to a method which is
+ * invoked when packets with @a the_class are received.
+ */
+void _MPCI_Register_packet_processor(
+ MP_packet_Classes the_class,
+ MPCI_Packet_processor the_packet_processor
+
+);
+
+/**
+ * This function obtains a packet by invoking the user provided
+ * MPCI get packet callout.
+ *
+ * @return This method returns a pointer to a MPCI packet which can be
+ * filled in by the caller and used to perform a subsequent
+ * remote operation.
+ */
+MP_packet_Prefix *_MPCI_Get_packet ( void );
+
+/**
+ * This routine deallocates a packet by invoking the user provided
+ * MPCI return packet callout.
+ *
+ * @param[in] the_packet is the MP packet to deallocate.
+ */
+void _MPCI_Return_packet (
+ MP_packet_Prefix *the_packet
+);
+
+/**
+ * This routine sends a process packet by invoking the user provided
+ * MPCI send callout.
+ *
+ * @param[in] destination is the node which should receive this packet.
+ * @param[in] the_packet is the packet to be sent.
+ */
+void _MPCI_Send_process_packet (
+ uint32_t destination,
+ MP_packet_Prefix *the_packet
+);
+
+/**
+ * This routine sends a request packet by invoking the user provided
+ * MPCI send callout.
+ *
+ * @param[in] destination is the node which should receive this packet.
+ * @param[in] the_packet is the packet to be sent.
+ * @param[in] extra_state is the extra thread state bits which should be
+ * set in addition to the remote operation pending state. It
+ * may indicate the caller is blocking on a message queue
+ * operation.
+ *
+ * @return This method returns the operation status from the remote node.
+ */
+uint32_t _MPCI_Send_request_packet (
+ uint32_t destination,
+ MP_packet_Prefix *the_packet,
+ States_Control extra_state
+);
+
+/**
+ * This routine sends a response packet by invoking the user provided
+ * MPCI send callout.
+ *
+ * @param[in] destination is the node which should receive this packet.
+ * @param[in] the_packet is the packet to be sent.
+ */
+void _MPCI_Send_response_packet (
+ uint32_t destination,
+ MP_packet_Prefix *the_packet
+);
+
+/**
+ * This routine receives a packet by invoking the user provided
+ * MPCI receive callout.
+ *
+ * @return This method returns the packet received.
+ */
+MP_packet_Prefix *_MPCI_Receive_packet ( void );
+
+/**
+ * This routine is responsible for passing @a the_packet to the thread
+ * waiting on the remote operation to complete. The unblocked thread is
+ * responsible for eventually freeing @a the_packet.
+ *
+ * @param[in] the_packet is the response packet to be processed.
+ *
+ * @return This method returns a pointer to the thread which was if unblocked
+ * or NULL if the waiting thread no longer exists.
+ */
+Thread_Control *_MPCI_Process_response (
+ MP_packet_Prefix *the_packet
+);
+
+/**
+ * This is the server thread which receives and processes all MCPI packets.
+ *
+ * @param[in] ignored is the thread argument. It is not used.
+ */
+Thread _MPCI_Receive_server(
+ uint32_t ignored
+);
+
+/**
+ * This routine informs RTEMS of the availability of an MPCI packet.
+ */
+void _MPCI_Announce ( void );
+
+/**
+ * This routine performs a remote procedure call so that a
+ * process operation can be performed on another node.
+ *
+ * @param[in] operation is the remote operation to perform.
+ */
+void _MPCI_Internal_packets_Send_process_packet (
+ MPCI_Internal_Remote_operations operation
+);
+
+/**
+ * _MPCI_Internal_packets_Send_request_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive operation can be initiated on another node.
+ *
+ * This routine is not needed since there are no request
+ * packets to be sent by this manager.
+ */
+
+/**
+ * _MPCI_Internal_packets_Send_response_packet
+ *
+ * This routine performs a remote procedure call so that a
+ * directive can be performed on another node.
+ *
+ * This routine is not needed since there are no response
+ * packets to be sent by this manager.
+ */
+
+/**
+ * This routine performs the actions specific to this package for
+ * the request from another node.
+ */
+void _MPCI_Internal_packets_Process_packet (
+ MP_packet_Prefix *the_packet_prefix
+);
+
+/**
+ * _MPCI_Internal_packets_Send_object_was_deleted
+ *
+ * This routine is invoked indirectly by the thread queue
+ * when a proxy has been removed from the thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ */
+
+/**
+ * _MPCI_Internal_packets_Send_extract_proxy
+ *
+ * This routine is invoked when a task is deleted and it
+ * has a proxy which must be removed from a thread queue and
+ * the remote node must be informed of this.
+ *
+ * This routine is not needed since there are no objects
+ * deleted by this manager.
+ */
+
+/**
+ * This routine is used to obtain a internal threads mp packet.
+ */
+MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/mppkt.h b/cpukit/score/include/rtems/score/mppkt.h
new file mode 100644
index 0000000000..db8e60d0df
--- /dev/null
+++ b/cpukit/score/include/rtems/score/mppkt.h
@@ -0,0 +1,123 @@
+/**
+ * @file rtems/score/mppkt.h
+ *
+ * This package is the specification for the Packet Handler.
+ * This handler defines the basic packet and provides
+ * mechanisms to utilize packets based on this prefix.
+ * Packets are the fundamental basis for messages passed between
+ * nodes in an MP system.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_MPPKT_H
+#define _RTEMS_SCORE_MPPKT_H
+
+/**
+ * @defgroup ScoreMPPacket MP Packet Handler
+ *
+ * This handler encapsulates the primary definition of MPCI packets. This
+ * handler defines the part of the packet that is common to all remote
+ * operations.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * The following enumerated type defines the packet classes.
+ *
+ * @note In general, each class corresponds to a manager
+ * which supports global operations. Each manager
+ * defines the set of supported operations.
+ */
+typedef enum {
+ MP_PACKET_MPCI_INTERNAL = 0,
+ MP_PACKET_TASKS = 1,
+ MP_PACKET_MESSAGE_QUEUE = 2,
+ MP_PACKET_SEMAPHORE = 3,
+ MP_PACKET_PARTITION = 4,
+ MP_PACKET_REGION = 5,
+ MP_PACKET_EVENT = 6,
+ MP_PACKET_SIGNAL = 7
+} MP_packet_Classes;
+
+/**
+ * This constant defines the first entry in the MP_packet_Classes enumeration.
+ */
+#define MP_PACKET_CLASSES_FIRST MP_PACKET_MPCI_INTERNAL
+
+/**
+ * This constant defines the last entry in the MP_packet_Classes enumeration.
+ */
+#define MP_PACKET_CLASSES_LAST MP_PACKET_SIGNAL
+
+/**
+ * The following record contains the prefix for every packet
+ * passed between nodes in an MP system.
+ *
+ * @note This structure is padded to ensure that anything following it
+ * is on a 16 byte boundary. This is the most stringent structure
+ * alignment rule encountered yet.
+ */
+typedef struct {
+ /** This field indicates the API class of the operation being performed. */
+ MP_packet_Classes the_class;
+ /** This field is the id of the object to be acted upon. */
+ Objects_Id id;
+ /** This field is the ID of the originating thread. */
+ Objects_Id source_tid;
+ /** This field is the priority of the originating thread. */
+ Priority_Control source_priority;
+ /** This field is where the status of the operation will be returned. */
+ uint32_t return_code;
+ /** This field is the length of the data following the prefix. */
+ uint32_t length;
+ /** This field is the length of the data which required network conversion. */
+ uint32_t to_convert;
+ /** This field is the requested timeout for this operation. */
+ Watchdog_Interval timeout;
+} MP_packet_Prefix;
+
+/**
+ * An MPCI must support packets of at least this size.
+ */
+#define MP_PACKET_MINIMUM_PACKET_SIZE 64
+
+/**
+ * The following constant defines the number of uint32_t 's
+ * in a packet which must be converted to native format in a
+ * heterogeneous system. In packets longer than
+ * MP_PACKET_MINIMUN_HETERO_CONVERSION uint32_t 's, some of the "extra" data
+ * may a user message buffer which is not automatically endian swapped.
+ */
+#define MP_PACKET_MINIMUN_HETERO_CONVERSION \
+ ( sizeof( MP_packet_Prefix ) / sizeof( uint32_t ) )
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/mppkt.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/object.h b/cpukit/score/include/rtems/score/object.h
new file mode 100644
index 0000000000..590d831345
--- /dev/null
+++ b/cpukit/score/include/rtems/score/object.h
@@ -0,0 +1,845 @@
+/**
+ * @file rtems/score/object.h
+ *
+ *
+ * This include file contains all the constants and structures associated
+ * with the Object Handler. This Handler provides mechanisms which
+ * can be used to initialize and manipulate all objects which have
+ * ids.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_OBJECT_H
+#define _RTEMS_SCORE_OBJECT_H
+
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup Score SuperCore
+ *
+ * @brief Provides services for all APIs.
+ */
+
+/**
+ * @defgroup ScoreCPU CPU Architecture Support
+ *
+ * @ingroup Score
+ *
+ * @brief Provides CPU architecture dependent services.
+ */
+
+/**
+ * The following type defines the control block used to manage
+ * object names.
+ */
+typedef union {
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ /** This is a pointer to a string name. */
+ const char *name_p;
+ #endif
+ /** This is the actual 32-bit "raw" integer name. */
+ uint32_t name_u32;
+} Objects_Name;
+
+/**
+ * Space for object names is allocated in multiples of this.
+ *
+ * NOTE: Must be a power of 2. Matches the name manipulation routines.
+ */
+#define OBJECTS_NAME_ALIGNMENT sizeof( uint32_t )
+
+/**
+ * Functions which compare names are prototyped like this.
+ */
+typedef bool (*Objects_Name_comparators)(
+ void * /* name_1 */,
+ void * /* name_2 */,
+ uint16_t /* length */
+);
+
+#if defined(RTEMS_USE_16_BIT_OBJECT)
+/**
+ * The following type defines the control block used to manage
+ * object IDs. The format is as follows (0=LSB):
+ *
+ * Bits 0 .. 7 = index (up to 254 objects of a type)
+ * Bits 8 .. 10 = API (up to 7 API classes)
+ * Bits 11 .. 15 = class (up to 31 object types per API)
+ */
+typedef uint16_t Objects_Id;
+
+/**
+ * This type is used to store the maximum number of allowed objects
+ * of each type.
+ */
+typedef uint8_t Objects_Maximum;
+
+#define OBJECTS_INDEX_START_BIT 0U
+#define OBJECTS_API_START_BIT 8U
+#define OBJECTS_CLASS_START_BIT 11U
+
+#define OBJECTS_INDEX_MASK (Objects_Id)0x00ffU
+#define OBJECTS_API_MASK (Objects_Id)0x0700U
+#define OBJECTS_CLASS_MASK (Objects_Id)0xF800U
+
+#define OBJECTS_INDEX_VALID_BITS (Objects_Id)0x00ffU
+#define OBJECTS_API_VALID_BITS (Objects_Id)0x0007U
+/* OBJECTS_NODE_VALID_BITS should not be used with 16 bit Ids */
+#define OBJECTS_CLASS_VALID_BITS (Objects_Id)0x001fU
+
+#define OBJECTS_UNLIMITED_OBJECTS 0x8000U
+
+#define OBJECTS_ID_INITIAL_INDEX (0)
+#define OBJECTS_ID_FINAL_INDEX (0xff)
+
+#else
+/**
+ * The following type defines the control block used to manage
+ * object IDs. The format is as follows (0=LSB):
+ *
+ * Bits 0 .. 15 = index (up to 65535 objects of a type)
+ * Bits 16 .. 23 = node (up to 255 nodes)
+ * Bits 24 .. 26 = API (up to 7 API classes)
+ * Bits 27 .. 31 = class (up to 31 object types per API)
+ */
+typedef uint32_t Objects_Id;
+
+/**
+ * This type is used to store the maximum number of allowed objects
+ * of each type.
+ */
+typedef uint16_t Objects_Maximum;
+
+/**
+ * This is the bit position of the starting bit of the index portion of
+ * the object Id.
+ */
+#define OBJECTS_INDEX_START_BIT 0U
+
+
+/**
+ * This is the bit position of the starting bit of the node portion of
+ * the object Id.
+ */
+#define OBJECTS_NODE_START_BIT 16U
+
+/**
+ * This is the bit position of the starting bit of the API portion of
+ * the object Id.
+ */
+#define OBJECTS_API_START_BIT 24U
+
+/**
+ * This is the bit position of the starting bit of the class portion of
+ * the object Id.
+ */
+#define OBJECTS_CLASS_START_BIT 27U
+
+/**
+ * This mask is used to extract the index portion of an object Id.
+ */
+#define OBJECTS_INDEX_MASK (Objects_Id)0x0000ffffU
+
+/**
+ * This mask is used to extract the node portion of an object Id.
+ */
+#define OBJECTS_NODE_MASK (Objects_Id)0x00ff0000U
+
+/**
+ * This mask is used to extract the API portion of an object Id.
+ */
+#define OBJECTS_API_MASK (Objects_Id)0x07000000U
+
+/**
+ * This mask is used to extract the class portion of an object Id.
+ */
+#define OBJECTS_CLASS_MASK (Objects_Id)0xf8000000U
+
+/**
+ * This mask represents the bits that is used to ensure no extra bits
+ * are set after shifting to extract the index portion of an object Id.
+ */
+#define OBJECTS_INDEX_VALID_BITS (Objects_Id)0x0000ffffU
+
+/**
+ * This mask represents the bits that is used to ensure no extra bits
+ * are set after shifting to extract the node portion of an object Id.
+ */
+#define OBJECTS_NODE_VALID_BITS (Objects_Id)0x000000ffU
+
+/**
+ * This mask represents the bits that is used to ensure no extra bits
+ * are set after shifting to extract the API portion of an object Id.
+ */
+#define OBJECTS_API_VALID_BITS (Objects_Id)0x00000007U
+
+/**
+ * This mask represents the bits that is used to ensure no extra bits
+ * are set after shifting to extract the class portion of an object Id.
+ */
+#define OBJECTS_CLASS_VALID_BITS (Objects_Id)0x0000001fU
+
+/**
+ * Mask to enable unlimited objects. This is used in the configuration
+ * table when specifying the number of configured objects.
+ */
+#define OBJECTS_UNLIMITED_OBJECTS 0x80000000U
+
+/**
+ * This is the lowest value for the index portion of an object Id.
+ */
+#define OBJECTS_ID_INITIAL_INDEX (0)
+
+/**
+ * This is the highest value for the index portion of an object Id.
+ */
+#define OBJECTS_ID_FINAL_INDEX (0xffffU)
+#endif
+
+/**
+ * This enumerated type is used in the class field of the object ID.
+ */
+typedef enum {
+ OBJECTS_NO_API = 0,
+ OBJECTS_INTERNAL_API = 1,
+ OBJECTS_CLASSIC_API = 2,
+ OBJECTS_POSIX_API = 3
+} Objects_APIs;
+
+/** This macro is used to generically specify the last API index. */
+#define OBJECTS_APIS_LAST OBJECTS_POSIX_API
+
+/**
+ * This enumerated type is used in the class field of the object ID
+ * for RTEMS internal object classes.
+ */
+typedef enum {
+ OBJECTS_INTERNAL_NO_CLASS = 0,
+ OBJECTS_INTERNAL_THREADS = 1,
+ OBJECTS_INTERNAL_MUTEXES = 2
+} Objects_Internal_API;
+
+/** This macro is used to generically specify the last API index. */
+#define OBJECTS_INTERNAL_CLASSES_LAST OBJECTS_INTERNAL_MUTEXES
+
+/**
+ * This enumerated type is used in the class field of the object ID
+ * for the RTEMS Classic API.
+ */
+typedef enum {
+ OBJECTS_CLASSIC_NO_CLASS = 0,
+ OBJECTS_RTEMS_TASKS = 1,
+ OBJECTS_RTEMS_TIMERS = 2,
+ OBJECTS_RTEMS_SEMAPHORES = 3,
+ OBJECTS_RTEMS_MESSAGE_QUEUES = 4,
+ OBJECTS_RTEMS_PARTITIONS = 5,
+ OBJECTS_RTEMS_REGIONS = 6,
+ OBJECTS_RTEMS_PORTS = 7,
+ OBJECTS_RTEMS_PERIODS = 8,
+ OBJECTS_RTEMS_EXTENSIONS = 9,
+ OBJECTS_RTEMS_BARRIERS = 10
+} Objects_Classic_API;
+
+/** This macro is used to generically specify the last API index. */
+#define OBJECTS_RTEMS_CLASSES_LAST OBJECTS_RTEMS_BARRIERS
+
+/**
+ * This enumerated type is used in the class field of the object ID
+ * for the POSIX API.
+ */
+typedef enum {
+ OBJECTS_POSIX_NO_CLASS = 0,
+ OBJECTS_POSIX_THREADS = 1,
+ OBJECTS_POSIX_KEYS = 2,
+ OBJECTS_POSIX_INTERRUPTS = 3,
+ OBJECTS_POSIX_MESSAGE_QUEUE_FDS = 4,
+ OBJECTS_POSIX_MESSAGE_QUEUES = 5,
+ OBJECTS_POSIX_MUTEXES = 6,
+ OBJECTS_POSIX_SEMAPHORES = 7,
+ OBJECTS_POSIX_CONDITION_VARIABLES = 8,
+ OBJECTS_POSIX_TIMERS = 9,
+ OBJECTS_POSIX_BARRIERS = 10,
+ OBJECTS_POSIX_SPINLOCKS = 11,
+ OBJECTS_POSIX_RWLOCKS = 12
+} Objects_POSIX_API;
+
+/** This macro is used to generically specify the last API index. */
+#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_RWLOCKS
+
+/**
+ * This enumerated type lists the locations which may be returned
+ * by _Objects_Get. These codes indicate the success of locating
+ * an object with the specified ID.
+ */
+typedef enum {
+#if defined(RTEMS_MULTIPROCESSING)
+ OBJECTS_REMOTE = 2, /* object is remote */
+#endif
+ OBJECTS_LOCAL = 0, /* object is local */
+ OBJECTS_ERROR = 1 /* id was invalid */
+} Objects_Locations;
+
+/**
+ * The following type defines the callout used when a local task
+ * is extracted from a remote thread queue (i.e. it's proxy must
+ * extracted from the remote queue).
+ */
+typedef void ( *Objects_Thread_queue_Extract_callout )( void * );
+
+/**
+ * The following defines the Object Control Block used to manage
+ * each object local to this node.
+ */
+typedef struct {
+ /** This is the chain node portion of an object. */
+ Chain_Node Node;
+ /** This is the object's ID. */
+ Objects_Id id;
+ /** This is the object's name. */
+ Objects_Name name;
+} Objects_Control;
+
+/**
+ * The following defines the structure for the information used to
+ * manage each class of objects.
+ */
+typedef struct {
+ /** This field indicates the API of this object class. */
+ Objects_APIs the_api;
+ /** This is the class of this object set. */
+ uint16_t the_class;
+ /** This is the minimum valid id of this object class. */
+ Objects_Id minimum_id;
+ /** This is the maximum valid id of this object class. */
+ Objects_Id maximum_id;
+ /** This is the maximum number of objects in this class. */
+ Objects_Maximum maximum;
+ /** This is the true if unlimited objects in this class. */
+ bool auto_extend;
+ /** This is the number of objects in a block. */
+ Objects_Maximum allocation_size;
+ /** This is the size in bytes of each object instance. */
+ size_t size;
+ /** This points to the table of local objects. */
+ Objects_Control **local_table;
+ /** This is the chain of inactive control blocks. */
+ Chain_Control Inactive;
+ /** This is the number of objects on the Inactive list. */
+ Objects_Maximum inactive;
+ /** This is the number of inactive objects per block. */
+ uint32_t *inactive_per_block;
+ /** This is a table to the chain of inactive object memory blocks. */
+ void **object_blocks;
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ /** This is true if names are strings. */
+ bool is_string;
+ #endif
+ /** This is the maximum length of names. */
+ uint16_t name_length;
+ /** This is this object class' method called when extracting a thread. */
+ Objects_Thread_queue_Extract_callout extract;
+ #if defined(RTEMS_MULTIPROCESSING)
+ /** This is this object class' pointer to the global name table */
+ Chain_Control *global_table;
+ #endif
+} Objects_Information;
+
+/**
+ * The following is referenced to the node number of the local node.
+ */
+#if defined(RTEMS_MULTIPROCESSING)
+SCORE_EXTERN uint16_t _Objects_Local_node;
+#else
+#define _Objects_Local_node ((uint16_t)1)
+#endif
+
+/**
+ * The following is referenced to the number of nodes in the system.
+ */
+#if defined(RTEMS_MULTIPROCESSING)
+SCORE_EXTERN uint16_t _Objects_Maximum_nodes;
+#else
+#define _Objects_Maximum_nodes 1
+#endif
+
+/**
+ * The following is the list of information blocks per API for each object
+ * class. From the ID, we can go to one of these information blocks,
+ * and obtain a pointer to the appropriate object control block.
+ */
+SCORE_EXTERN Objects_Information
+ **_Objects_Information_table[OBJECTS_APIS_LAST + 1];
+
+/**
+ * No object can have this ID.
+ */
+#define OBJECTS_ID_NONE 0
+
+/**
+ * The following defines the constant which may be used
+ * with _Objects_Get to manipulate the calling task.
+ */
+#define OBJECTS_ID_OF_SELF ((Objects_Id) 0)
+
+/**
+ * The following constant is used to specify that a name to ID search
+ * should search through all nodes.
+ */
+#define OBJECTS_SEARCH_ALL_NODES 0
+
+/**
+ * The following constant is used to specify that a name to ID search
+ * should search through all nodes except the current node.
+ */
+#define OBJECTS_SEARCH_OTHER_NODES 0x7FFFFFFE
+
+/**
+ * The following constant is used to specify that a name to ID search
+ * should search only on this node.
+ */
+#define OBJECTS_SEARCH_LOCAL_NODE 0x7FFFFFFF
+
+/**
+ * The following constant is used to specify that a name to ID search
+ * is being asked for the ID of the currently executing task.
+ */
+#define OBJECTS_WHO_AM_I 0
+
+/**
+ * This macros calculates the lowest ID for the specified api, class,
+ * and node.
+ */
+#define OBJECTS_ID_INITIAL(_api, _class, _node) \
+ _Objects_Build_id( (_api), (_class), (_node), OBJECTS_ID_INITIAL_INDEX )
+
+/**
+ * This macro specifies the highest object ID value
+ */
+#define OBJECTS_ID_FINAL ((Objects_Id)~0)
+
+/**
+ * This function extends an object class information record.
+ *
+ * @param[in] information points to an object class information block.
+ */
+void _Objects_Extend_information(
+ Objects_Information *information
+);
+
+/**
+ * This function shrink an object class information record.
+ *
+ * @param[in] information points to an object class information block.
+ */
+void _Objects_Shrink_information(
+ Objects_Information *information
+);
+
+/**
+ * This function initializes an object class information record.
+ * SUPPORTS_GLOBAL is true if the object class supports global
+ * objects, and false otherwise. Maximum indicates the number
+ * of objects required in this class and size indicates the size
+ * in bytes of each control block for this object class. The
+ * name length and string designator are also set. In addition,
+ * the class may be a task, therefore this information is also included.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] the_api indicates the API associated with this information block.
+ * @param[in] the_class indicates the class of object being managed
+ * by this information block. It is specific to @a the_api.
+ * @param[in] maximum is the maximum number of instances of this object
+ * class which may be concurrently active.
+ * @param[in] size is the size of the data structure for this class.
+ * @param[in] is_string is true if this object uses string style names.
+ * @param[in] maximum_name_length is the maximum length of object names.
+ */
+void _Objects_Initialize_information (
+ Objects_Information *information,
+ Objects_APIs the_api,
+ uint16_t the_class,
+ uint32_t maximum,
+ uint16_t size,
+ bool is_string,
+ uint32_t maximum_name_length
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ bool supports_global,
+ Objects_Thread_queue_Extract_callout extract
+#endif
+);
+
+/**
+ * This function returns the highest numeric value of a valid
+ * API for the specified @a api.
+ *
+ * @param[in] api is the API of interest
+ *
+ * @return A positive integer on success and 0 otherwise.
+ */
+unsigned int _Objects_API_maximum_class(
+ uint32_t api
+);
+
+/**
+ * This function allocates a object control block from
+ * the inactive chain of free object control blocks.
+ *
+ * @param[in] information points to an object class information block.
+ */
+Objects_Control *_Objects_Allocate(
+ Objects_Information *information
+);
+
+/**
+ *
+ * This function frees a object control block to the
+ * inactive chain of free object control blocks.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] the_object points to the object to deallocate.
+ */
+void _Objects_Free(
+ Objects_Information *information,
+ Objects_Control *the_object
+);
+
+/**
+ * This macro is used to build a thirty-two bit style name from
+ * four characters. The most significant byte will be the
+ * character @a _C1.
+ *
+ * @param[in] _C1 is the first character of the name
+ * @param[in] _C2 is the second character of the name
+ * @param[in] _C3 is the third character of the name
+ * @param[in] _C4 is the fourth character of the name
+ */
+#define _Objects_Build_name( _C1, _C2, _C3, _C4 ) \
+ ( (uint32_t)(_C1) << 24 | \
+ (uint32_t)(_C2) << 16 | \
+ (uint32_t)(_C3) << 8 | \
+ (uint32_t)(_C4) )
+
+/**
+ * This function implements the common portion of the object
+ * identification directives. This directive returns the object
+ * id associated with name. If more than one object of this class
+ * is named name, then the object to which the id belongs is
+ * arbitrary. Node indicates the extent of the search for the
+ * id of the object named name. If the object class supports global
+ * objects, then the search can be limited to a particular node
+ * or allowed to encompass all nodes.
+ */
+typedef enum {
+ OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL,
+ OBJECTS_INVALID_NAME,
+ OBJECTS_INVALID_ADDRESS,
+ OBJECTS_INVALID_ID,
+ OBJECTS_INVALID_NODE
+} Objects_Name_or_id_lookup_errors;
+
+/**
+ * This macro defines the first entry in the
+ * @ref Objects_Name_or_id_lookup_errors enumerated list.
+ */
+#define OBJECTS_NAME_ERRORS_FIRST OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL
+
+/**
+ * This macro defines the last entry in the
+ * @ref Objects_Name_or_id_lookup_errors enumerated list.
+ */
+#define OBJECTS_NAME_ERRORS_LAST OBJECTS_INVALID_NODE
+
+/**
+ * This method converts an object name to an Id. It performs a look up
+ * using the object information block for this object class.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] name is the name of the object to find.
+ * @param[in] node is the set of nodes to search.
+ * @param[in] id will contain the Id if the search is successful.
+ *
+ * @return This method returns one of the values from the
+ * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
+ * successful or failure. On success @a id will contain the Id of
+ * the requested object.
+ */
+Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
+ Objects_Information *information,
+ uint32_t name,
+ uint32_t node,
+ Objects_Id *id
+);
+
+#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+/**
+ * This method converts an object name to an Id. It performs a look up
+ * using the object information block for this object class.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] name is the name of the object to find.
+ * @param[in] id will contain the Id if the search is successful.
+ *
+ * @return This method returns one of the values from the
+ * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
+ * successful or failure. On success @a id will contain the Id of
+ * the requested object.
+ */
+Objects_Name_or_id_lookup_errors _Objects_Name_to_id_string(
+ Objects_Information *information,
+ const char *name,
+ Objects_Id *id
+);
+#endif
+
+/**
+ * This function implements the common portion of the object Id
+ * to name directives. This function returns the name
+ * associated with object id.
+ *
+ * @param[in] id is the Id of the object whose name we are locating.
+ * @param[in] name will contain the name of the object, if found.
+ *
+ * @return This method returns one of the values from the
+ * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
+ * successful or failure. On success @a name will contain the name of
+ * the requested object.
+ *
+ * @note This function currently does not support string names.
+ */
+Objects_Name_or_id_lookup_errors _Objects_Id_to_name (
+ Objects_Id id,
+ Objects_Name *name
+);
+
+/**
+ * This function maps object ids to object control blocks.
+ * If id corresponds to a local object, then it returns
+ * the_object control pointer which maps to id and location
+ * is set to OBJECTS_LOCAL. If the object class supports global
+ * objects and the object id is global and resides on a remote
+ * node, then location is set to OBJECTS_REMOTE, and the_object
+ * is undefined. Otherwise, location is set to OBJECTS_ERROR
+ * and the_object is undefined.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] id is the Id of the object whose name we are locating.
+ * @param[in] location will contain an indication of success or failure.
+ *
+ * @return This method returns one of the values from the
+ * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
+ * successful or failure. On success @a id will contain the Id of
+ * the requested object.
+ *
+ * @note _Objects_Get returns with dispatching disabled for
+ * local and remote objects. _Objects_Get_isr_disable returns with
+ * dispatching disabled for remote objects and interrupts for local
+ * objects.
+ */
+Objects_Control *_Objects_Get (
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location
+);
+
+/**
+ * This function maps object ids to object control blocks.
+ * If id corresponds to a local object, then it returns
+ * the_object control pointer which maps to id and location
+ * is set to OBJECTS_LOCAL. If the object class supports global
+ * objects and the object id is global and resides on a remote
+ * node, then location is set to OBJECTS_REMOTE, and the_object
+ * is undefined. Otherwise, location is set to OBJECTS_ERROR
+ * and the_object is undefined.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] id is the Id of the object whose name we are locating.
+ * @param[in] location will contain an indication of success or failure.
+ * @param[in] level is the interrupt level being turned.
+ *
+ * @return This method returns one of the values from the
+ * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
+ * successful or failure. On success @a name will contain the name of
+ * the requested object.
+ *
+ * @note _Objects_Get returns with dispatching disabled for
+ * local and remote objects. _Objects_Get_isr_disable returns with
+ * dispatchng disabled for remote objects and interrupts for local
+ * objects.
+ */
+Objects_Control *_Objects_Get_isr_disable(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location,
+ ISR_Level *level
+);
+
+/**
+ * This function maps object ids to object control blocks.
+ * If id corresponds to a local object, then it returns
+ * the_object control pointer which maps to id and location
+ * is set to OBJECTS_LOCAL. If the object class supports global
+ * objects and the object id is global and resides on a remote
+ * node, then location is set to OBJECTS_REMOTE, and the_object
+ * is undefined. Otherwise, location is set to OBJECTS_ERROR
+ * and the_object is undefined.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] id is the Id of the object whose name we are locating.
+ * @param[in] location will contain an indication of success or failure.
+ *
+ * @return This method returns one of the values from the
+ * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
+ * successful or failure. On success @a id will contain the Id of
+ * the requested object.
+ *
+ * @note _Objects_Get returns with dispatching disabled for
+ * local and remote objects. _Objects_Get_isr_disable returns with
+ * dispatching disabled for remote objects and interrupts for local
+ * objects.
+ */
+Objects_Control *_Objects_Get_no_protection(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location
+);
+
+/**
+ * Like @ref _Objects_Get, but is used to find "next" open object.
+ *
+ * @param[in] information points to an object class information block.
+ * @param[in] id is the Id of the object whose name we are locating.
+ * @param[in] location_p will contain an indication of success or failure.
+ * @param[in] next_id_p is the Id of the next object we will look at.
+ *
+ * @return This method returns the pointer to the object located or
+ * NULL on error.
+ */
+Objects_Control *_Objects_Get_next(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location_p,
+ Objects_Id *next_id_p
+);
+
+/**
+ * This function return the information structure given
+ * an the API and Class. This can be done independent of
+ * the existence of any objects created by the API.
+ *
+ * @param[in] the_api indicates the API for the information we want
+ * @param[in] the_class indicates the Class for the information we want
+ *
+ * @return This method returns a pointer to the Object Information Table
+ * for the class of objects which corresponds to this object ID.
+ */
+Objects_Information *_Objects_Get_information(
+ Objects_APIs the_api,
+ uint16_t the_class
+);
+
+/**
+ * This function return the information structure given
+ * an id of an object.
+ *
+ * @param[in] id is an object ID
+ *
+ * @return This method returns a pointer to the Object Information Table
+ * for the class of objects which corresponds to this object ID.
+ */
+Objects_Information *_Objects_Get_information_id(
+ Objects_Id id
+);
+
+/**
+ * This method objects the name of an object and returns its name
+ * in the form of a C string. It attempts to be careful about
+ * overflowing the user's string and about returning unprintable characters.
+ *
+ * @param[in] id is the object to obtain the name of
+ * @param[in] length indicates the length of the caller's buffer
+ * @param[in] name points a string which will be filled in.
+ *
+ * @return This method returns @a name or NULL on error. @a *name will
+ * contain the name if successful.
+ */
+char *_Objects_Get_name_as_string(
+ Objects_Id id,
+ size_t length,
+ char *name
+);
+
+/**
+ * This method sets the object name to either a copy of a string
+ * or up to the first four characters of the string based upon
+ * whether this object class uses strings for names.
+ *
+ * @param[in] information points to the object information structure
+ * @param[in] the_object is the object to operate upon
+ * @param[in] name is a pointer to the name to use
+ *
+ * @return If successful, true is returned. Otherwise false is returned.
+ */
+bool _Objects_Set_name(
+ Objects_Information *information,
+ Objects_Control *the_object,
+ const char *name
+);
+
+/**
+ * This function removes the_object from the namespace.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] the_object is a pointer to an object
+ */
+void _Objects_Namespace_remove(
+ Objects_Information *information,
+ Objects_Control *the_object
+);
+
+/**
+ * This function removes the_object control pointer and object name
+ * in the Local Pointer and Local Name Tables.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] the_object is a pointer to an object
+ */
+void _Objects_Close(
+ Objects_Information *information,
+ Objects_Control *the_object
+);
+
+/*
+ * Pieces of object.inl are promoted out to the user
+ */
+
+#include <rtems/score/object.inl>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/objectmp.h b/cpukit/score/include/rtems/score/objectmp.h
new file mode 100644
index 0000000000..318819ffd8
--- /dev/null
+++ b/cpukit/score/include/rtems/score/objectmp.h
@@ -0,0 +1,188 @@
+/**
+ * @file rtems/score/objectmp.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the manipulation of Global RTEMS Objects.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_OBJECTMP_H
+#define _RTEMS_SCORE_OBJECTMP_H
+
+/**
+ * @defgroup ScoreObjectMP Object Handler Multiprocessing Support
+ *
+ * This handler encapsulates functionality which is used to manage
+ * objects which have been declared to be globally visible. This handler
+ * knows objects from all of the nodes in the system.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This defines the Global Object Control Block used to manage
+ * objects resident on other nodes. It is derived from Object.
+ */
+typedef struct {
+ /** This is an object control structure. */
+ Objects_Control Object;
+ /** This is the name of the object. Using an unsigned thirty two
+ * bit value is broken but works. If any API is MP with variable
+ * length names .. BOOM!!!!
+ */
+ uint32_t name;
+} Objects_MP_Control;
+
+/** @brief Objects MP Handler initialization
+ *
+ * This routine intializes the inactive global object chain
+ * based on the maximum number of global objects configured.
+ */
+void _Objects_MP_Handler_initialization(void);
+
+/** @brief Objects MP Handler Early initialization
+ *
+ * This routine intializes the global object node number
+ * used in the ID field of all objects.
+ */
+void _Objects_MP_Handler_early_initialization(void);
+
+/** @brief Objects MP Open
+ *
+ * This routine place the specified global object in the
+ * specified information table.
+ *
+ * @param[in] information points to the object information table for this
+ * object class.
+ * @param[in] the_global_object points to the object being opened.
+ * @param[in] the_name is the name of the object being opened.
+ * @param[in] the_id is the Id of the object being opened.
+ *
+ * @todo This method only works for object types with 4 byte object names.
+ * It does not support variable length object names.
+ */
+void _Objects_MP_Open (
+ Objects_Information *information,
+ Objects_MP_Control *the_global_object,
+ uint32_t the_name,
+ Objects_Id the_id
+);
+
+/** @brief Objects MP Allocate and open
+ *
+ * This routine allocates a global object control block
+ * and places it in the specified information table. If the
+ * allocation fails, then is_fatal_error determines the
+ * error processing actions taken.
+ *
+ * @param[in] information points to the object information table for this
+ * object class.
+ * @param[in] the_name is the name of the object being opened.
+ * @param[in] the_id is the Id of the object being opened.
+ * @param[in] is_fatal_error is true if not being able to allocate the
+ * object is considered a fatal error.
+ *
+ * @todo This method only works for object types with 4 byte object names.
+ * It does not support variable length object names.
+ */
+bool _Objects_MP_Allocate_and_open (
+ Objects_Information *information,
+ uint32_t the_name,
+ Objects_Id the_id,
+ bool is_fatal_error
+);
+
+/** @brief Objects MP Close
+ *
+ * This routine removes a global object from the specified
+ * information table and deallocates the global object control block.
+ */
+void _Objects_MP_Close (
+ Objects_Information *information,
+ Objects_Id the_id
+);
+
+/** @brief Objects MP Global name search
+ *
+ * This routine looks for the object with the_name in the global
+ * object tables indicated by information. It returns the ID of the
+ * object with that name if one is found.
+ *
+ * @param[in] information points to the object information table for this
+ * object class.
+ * @param[in] the_name is the name of the object being searched for.
+ * @param[in] nodes_to_search indicates the set of nodes to search.
+ * @param[in] the_id will contain the Id of the object if found.
+ *
+ * @return This method returns one of the
+ * @ref Objects_Name_or_id_lookup_errors. If successful, @a the_id
+ * will contain the Id of the object.
+ */
+Objects_Name_or_id_lookup_errors _Objects_MP_Global_name_search (
+ Objects_Information *information,
+ Objects_Name the_name,
+ uint32_t nodes_to_search,
+ Objects_Id *the_id
+);
+
+/** @brief Objects MP Is remote
+ *
+ * This function searches the Global Object Table managed
+ * by information for the object indicated by ID. If the object
+ * is found, then location is set to objects_remote, otherwise
+ * location is set to objects_error. In both cases, the_object
+ * is undefined.
+ *
+ * @param[in] information points to the object information table for this
+ * object class.
+ * @param[in] the_id is the Id of the object being opened.
+ * @param[in] location will contain the location of the object.
+ * @param[in] the_object will contain a pointer to the object.
+ *
+ * @return This method fills in @a location to indicate successful location
+ * of the object or error. On success, @a the_object will be
+ * filled in.
+ */
+void _Objects_MP_Is_remote (
+ Objects_Information *information,
+ Objects_Id the_id,
+ Objects_Locations *location,
+ Objects_Control **the_object
+);
+
+/**
+ * This is the maximum number of global objects configured.
+ */
+SCORE_EXTERN uint32_t _Objects_MP_Maximum_global_objects;
+
+/**
+ * The following chain header is used to manage the set of
+ * inactive global object control blocks.
+ */
+SCORE_EXTERN Chain_Control _Objects_MP_Inactive_global_objects;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/objectmp.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h
new file mode 100644
index 0000000000..0c48b50570
--- /dev/null
+++ b/cpukit/score/include/rtems/score/percpu.h
@@ -0,0 +1,257 @@
+/**
+ * @file rtems/score/percpu.h
+ *
+ * This include file defines the per CPU information required
+ * by RTEMS.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_PERCPU_H
+#define _RTEMS_PERCPU_H
+
+#include <rtems/score/cpu.h>
+
+#ifdef ASM
+ #include <rtems/asm.h>
+#else
+ #if defined(RTEMS_SMP)
+ #include <rtems/score/smplock.h>
+ #endif
+ #include <rtems/bspsmp.h>
+#endif
+
+/**
+ * @defgroup PerCPU RTEMS Per CPU Information
+ *
+ * This defines the per CPU state information required by RTEMS
+ * and the BSP. In an SMP configuration, there will be multiple
+ * instances of this data structure -- one per CPU -- and the
+ * current CPU number will be used as the index.
+ */
+
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef ASM
+#ifndef __THREAD_CONTROL_DEFINED__
+#define __THREAD_CONTROL_DEFINED__
+typedef struct Thread_Control_struct Thread_Control;
+#endif
+
+#if (CPU_ALLOCATE_INTERRUPT_STACK == FALSE) && defined(RTEMS_SMP)
+ #error "RTEMS must allocate per CPU interrupt stack for SMP"
+#endif
+
+typedef enum {
+
+ /**
+ * This defines the constant used to indicate that the cpu code is in
+ * its initial powered up start.
+ */
+ RTEMS_BSP_SMP_CPU_INITIAL_STATE = 1,
+
+ /**
+ * This defines the constant used to indicate that the cpu code has
+ * completed basic initialization and awaits further commands.
+ */
+ RTEMS_BSP_SMP_CPU_INITIALIZED = 2,
+
+ /**
+ * This defines the constant used to indicate that the cpu code has
+ * shut itself down.
+ */
+ RTEMS_BSP_SMP_CPU_SHUTDOWN = 3
+} bsp_smp_cpu_state;
+
+/**
+ * @brief Per CPU Core Structure
+ *
+ * This structure is used to hold per core state information.
+ */
+typedef struct {
+ #if defined(RTEMS_SMP)
+ /** This element is used to lock this structure */
+ SMP_lock_Control lock;
+
+ /** This indicates that the CPU is online. */
+ uint32_t state;
+
+ /**
+ * This is the request for the interrupt.
+ *
+ * @note This may become a chain protected by atomic instructions.
+ */
+ uint32_t message;
+
+ #endif
+
+#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) || \
+ (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ /**
+ * This contains a pointer to the lower range of the interrupt stack for
+ * this CPU. This is the address allocated and freed.
+ */
+ void *interrupt_stack_low;
+
+ /**
+ * This contains a pointer to the interrupt stack pointer for this CPU.
+ * It will be loaded at the beginning on an ISR.
+ */
+ void *interrupt_stack_high;
+#endif
+
+ /**
+ * This contains the current interrupt nesting level on this
+ * CPU.
+ */
+ uint32_t isr_nest_level;
+
+ /** This is the thread executing on this CPU. */
+ Thread_Control *executing;
+
+ /** This is the heir thread for this this CPU. */
+ Thread_Control *heir;
+
+ /** This is the idle thread for this CPU. */
+ Thread_Control *idle;
+
+ /** This is set to true when this CPU needs to run the dispatcher. */
+ volatile bool dispatch_necessary;
+
+} Per_CPU_Control;
+#endif
+
+#ifdef ASM
+#if defined(RTEMS_SMP)
+ #define PER_CPU_LOCK 0
+ #define PER_CPU_STATE (1 * __RTEMS_SIZEOF_VOID_P__)
+ #define PER_CPU_MESSAGE (2 * __RTEMS_SIZEOF_VOID_P__)
+ #define PER_CPU_END_SMP (3 * __RTEMS_SIZEOF_VOID_P__)
+#else
+ #define PER_CPU_END_SMP 0
+#endif
+
+#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) || \
+ (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ /*
+ * If this CPU target lets RTEMS allocates the interrupt stack, then
+ * we need to have places in the per cpu table to hold them.
+ */
+ #define PER_CPU_INTERRUPT_STACK_LOW PER_CPU_END_SMP
+ #define PER_CPU_INTERRUPT_STACK_HIGH \
+ PER_CPU_INTERRUPT_STACK_LOW + (1 * __RTEMS_SIZEOF_VOID_P__)
+ #define PER_CPU_END_STACK \
+ PER_CPU_INTERRUPT_STACK_HIGH + (1 * __RTEMS_SIZEOF_VOID_P__)
+#else
+ #define PER_CPU_END_STACK PER_CPU_END_SMP
+#endif
+
+/*
+ * These are the offsets of the required elements in the per CPU table.
+ */
+#define PER_CPU_ISR_NEST_LEVEL \
+ PER_CPU_END_STACK + 0
+#define PER_CPU_EXECUTING \
+ PER_CPU_END_STACK + (1 * __RTEMS_SIZEOF_VOID_P__)
+#define PER_CPU_HEIR \
+ PER_CPU_END_STACK + (2 * __RTEMS_SIZEOF_VOID_P__)
+#define PER_CPU_IDLE \
+ PER_CPU_END_STACK + (3 * __RTEMS_SIZEOF_VOID_P__)
+#define PER_CPU_DISPATCH_NEEDED \
+ PER_CPU_END_STACK + (4 * __RTEMS_SIZEOF_VOID_P__)
+
+#define ISR_NEST_LEVEL \
+ (SYM(_Per_CPU_Information) + PER_CPU_ISR_NEST_LEVEL)
+#define DISPATCH_NEEDED \
+ (SYM(_Per_CPU_Information) + PER_CPU_DISPATCH_NEEDED)
+
+/*
+ * Do not define these offsets if they are not in the table.
+ */
+#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) || \
+ (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
+ #define INTERRUPT_STACK_LOW \
+ (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_LOW)
+ #define INTERRUPT_STACK_HIGH \
+ (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_HIGH)
+#endif
+
+#endif
+
+#ifndef ASM
+
+/**
+ * @brief Set of Per CPU Core Information
+ *
+ * This is an array of per CPU core information.
+ */
+extern Per_CPU_Control _Per_CPU_Information[];
+
+#if defined(RTEMS_SMP)
+/**
+ * @brief Set of Pointers to Per CPU Core Information
+ *
+ * This is an array of pointers to each CPU's per CPU data structure.
+ * It should be simpler to retrieve this pointer in assembly language
+ * that to calculate the array offset.
+ */
+extern Per_CPU_Control *_Per_CPU_Information_p[];
+
+/**
+ * @brief Initialize SMP Handler
+ *
+ * This method initialize the SMP Handler.
+ */
+void _SMP_Handler_initialize(void);
+
+/**
+ * @brief Allocate and Initialize Per CPU Structures
+ *
+ * This method allocates and initialize the per CPU structure.
+ */
+void _Per_CPU_Initialize(void);
+
+#endif
+
+/*
+ * On a non SMP system, the bsp_smp_processor_id is defined to 0.
+ * Thus when built for non-SMP, there should be no performance penalty.
+ */
+#define _Thread_Heir \
+ _Per_CPU_Information[bsp_smp_processor_id()].heir
+#define _Thread_Executing \
+ _Per_CPU_Information[bsp_smp_processor_id()].executing
+#define _Thread_Idle \
+ _Per_CPU_Information[bsp_smp_processor_id()].idle
+#define _ISR_Nest_level \
+ _Per_CPU_Information[bsp_smp_processor_id()].isr_nest_level
+#define _CPU_Interrupt_stack_low \
+ _Per_CPU_Information[bsp_smp_processor_id()].interrupt_stack_low
+#define _CPU_Interrupt_stack_high \
+ _Per_CPU_Information[bsp_smp_processor_id()].interrupt_stack_high
+#define _Thread_Dispatch_necessary \
+ _Per_CPU_Information[bsp_smp_processor_id()].dispatch_necessary
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/priority.h b/cpukit/score/include/rtems/score/priority.h
new file mode 100644
index 0000000000..05dc939d84
--- /dev/null
+++ b/cpukit/score/include/rtems/score/priority.h
@@ -0,0 +1,85 @@
+/**
+ * @file rtems/score/priority.h
+ *
+ * This include file contains all thread priority manipulation routines.
+ * This Handler provides mechanisms which can be used to
+ * initialize and manipulate thread priorities.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_PRIORITY_H
+#define _RTEMS_SCORE_PRIORITY_H
+
+/**
+ * @defgroup ScorePriority Priority Handler
+ *
+ * This handler encapsulates functionality which is used to manage
+ * thread priorities. At the SuperCore level 256 priority levels
+ * are supported with lower numbers representing logically more important
+ * threads. The priority level 0 is reserved for internal RTEMS use.
+ * Typically it is assigned to threads which defer internal RTEMS
+ * actions from an interrupt to thread level to improve interrupt response.
+ * Priority level 255 is assigned to the IDLE thread and really should not
+ * be used by application threads. The default IDLE thread implementation
+ * is an infinite "branch to self" loop which never yields to other threads
+ * at the same priority.
+ */
+/**@{*/
+
+/*
+ * Processor specific information.
+ */
+#include <rtems/score/cpu.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following type defines the control block used to manage
+ * thread priorities.
+ *
+ * @note Priority 0 is reserved for internal threads only.
+ */
+typedef uint32_t Priority_Control;
+
+/** This defines the highest (most important) thread priority. */
+#define PRIORITY_MINIMUM 0
+
+/** This defines the default lowest (least important) thread priority. */
+#if defined (CPU_PRIORITY_MAXIMUM)
+ #define PRIORITY_DEFAULT_MAXIMUM CPU_PRIORITY_MAXIMUM
+#else
+ #define PRIORITY_DEFAULT_MAXIMUM 255
+#endif
+
+/** This defines the lowest (least important) thread priority. */
+#define PRIORITY_MAXIMUM rtems_maximum_priority
+
+/**
+ * This variable contains the configured number of priorities
+ */
+extern uint8_t rtems_maximum_priority;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/priority.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/prioritybitmap.h b/cpukit/score/include/rtems/score/prioritybitmap.h
new file mode 100644
index 0000000000..bba5b428b6
--- /dev/null
+++ b/cpukit/score/include/rtems/score/prioritybitmap.h
@@ -0,0 +1,124 @@
+/**
+ * @file rtems/score/prioritybitmap.h
+ *
+ * This include file contains all thread priority manipulation routines for
+ * the bit map priority queue implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_PRIORITYBITMAP_H
+#define _RTEMS_SCORE_PRIORITYBITMAP_H
+
+/**
+ * @addtogroup ScorePriority
+ *
+ */
+/**@{*/
+
+/*
+ * Processor specific information.
+ */
+#include <rtems/score/cpu.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/priority.h>
+
+
+/*
+ * The Priority_bit_map_Control variables are instantiated only
+ * if using the bit map handler.
+ */
+
+/**
+ * Each sixteen bit entry in this array is associated with one of
+ * the sixteen entries in the Priority Bit map.
+ */
+extern volatile Priority_bit_map_Control _Priority_Major_bit_map;
+
+/** Each bit in the Priority Bitmap indicates whether or not there are
+ * threads ready at a particular priority. The mapping of
+ * individual priority levels to particular bits is processor
+ * dependent as is the value of each bit used to indicate that
+ * threads are ready at that priority.
+ */
+extern Priority_bit_map_Control
+ _Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT;
+
+/*
+ * The definition of the Priority_bit_map_Control type is CPU dependent.
+ *
+ */
+
+/**
+ * The following record defines the information associated with
+ * each thread to manage its interaction with the priority bit maps.
+ */
+typedef struct {
+ /** This is the address of minor bit map slot. */
+ Priority_bit_map_Control *minor;
+ /** This is the priority bit map ready mask. */
+ Priority_bit_map_Control ready_major;
+ /** This is the priority bit map ready mask. */
+ Priority_bit_map_Control ready_minor;
+ /** This is the priority bit map block mask. */
+ Priority_bit_map_Control block_major;
+ /** This is the priority bit map block mask. */
+ Priority_bit_map_Control block_minor;
+} Priority_bit_map_Information;
+
+
+#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
+/**
+ * This method returns the priority bit mask for the specified major
+ * or minor bit number.
+ *
+ * @param[in] _bit_number is the bit number for which we need a mask
+ *
+ * @return the priority bit mask
+ *
+ * @note This may simply be a pass through to a CPU dependent implementation.
+ */
+#define _Priority_Mask( _bit_number ) \
+ _CPU_Priority_Mask( _bit_number )
+#endif
+
+#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
+/**
+ * This method returns the bit index position for the specified priority.
+ *
+ * @param[in] _priority is the priority for which we need the index.
+ *
+ * @return This method returns the array index into the priority bit map.
+ *
+ * @note This may simply be a pass through to a CPU dependent implementation.
+ */
+#define _Priority_Bits_index( _priority ) \
+ _CPU_Priority_bits_index( _priority )
+#endif
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/prioritybitmap.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/protectedheap.h b/cpukit/score/include/rtems/score/protectedheap.h
new file mode 100644
index 0000000000..01c736d6ae
--- /dev/null
+++ b/cpukit/score/include/rtems/score/protectedheap.h
@@ -0,0 +1,165 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_PROTECTED_HEAP_H
+#define _RTEMS_SCORE_PROTECTED_HEAP_H
+
+#include <rtems/score/heap.h>
+#include <rtems/score/apimutex.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ScoreProtHeap Protected Heap Handler
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Provides protected heap services.
+ *
+ * The @ref ScoreAllocatorMutex is used to protect the heap accesses.
+ *
+ * @{
+ */
+
+/**
+ * @brief See _Heap_Initialize().
+ */
+RTEMS_INLINE_ROUTINE uintptr_t _Protected_heap_Initialize(
+ Heap_Control *heap,
+ void *area_begin,
+ uintptr_t area_size,
+ uintptr_t page_size
+)
+{
+ return _Heap_Initialize( heap, area_begin, area_size, page_size );
+}
+
+/**
+ * @brief See _Heap_Extend().
+ *
+ * Returns @a true in case of success, and @a false otherwise.
+ */
+bool _Protected_heap_Extend(
+ Heap_Control *heap,
+ void *area_begin,
+ uintptr_t area_size
+);
+
+/**
+ * @brief See _Heap_Allocate_aligned_with_boundary().
+ */
+void *_Protected_heap_Allocate_aligned_with_boundary(
+ Heap_Control *heap,
+ uintptr_t size,
+ uintptr_t alignment,
+ uintptr_t boundary
+);
+
+/**
+ * @brief See _Heap_Allocate_aligned_with_boundary() with boundary equals zero.
+ */
+RTEMS_INLINE_ROUTINE void *_Protected_heap_Allocate_aligned(
+ Heap_Control *heap,
+ uintptr_t size,
+ uintptr_t alignment
+)
+{
+ return
+ _Protected_heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 );
+}
+
+/**
+ * @brief See _Heap_Allocate_aligned_with_boundary() with alignment and
+ * boundary equals zero.
+ */
+RTEMS_INLINE_ROUTINE void *_Protected_heap_Allocate(
+ Heap_Control *heap,
+ uintptr_t size
+)
+{
+ return _Protected_heap_Allocate_aligned_with_boundary( heap, size, 0, 0 );
+}
+
+/**
+ * @brief See _Heap_Size_of_alloc_area().
+ */
+bool _Protected_heap_Get_block_size(
+ Heap_Control *heap,
+ void *addr,
+ uintptr_t *size
+);
+
+/**
+ * @brief See _Heap_Resize_block().
+ *
+ * Returns @a true in case of success, and @a false otherwise.
+ */
+bool _Protected_heap_Resize_block(
+ Heap_Control *heap,
+ void *addr,
+ uintptr_t size
+);
+
+/**
+ * @brief See _Heap_Free().
+ *
+ * Returns @a true in case of success, and @a false otherwise.
+ */
+bool _Protected_heap_Free( Heap_Control *heap, void *addr );
+
+/**
+ * @brief See _Heap_Walk().
+ */
+bool _Protected_heap_Walk( Heap_Control *heap, int source, bool dump );
+
+/**
+ * @brief See _Heap_Get_information().
+ *
+ * Returns @a true in case of success, and @a false otherwise.
+ */
+bool _Protected_heap_Get_information(
+ Heap_Control *heap,
+ Heap_Information_block *info
+);
+
+/**
+ * @brief See _Heap_Get_free_information().
+ *
+ * Returns @a true in case of success, and @a false otherwise.
+ */
+bool _Protected_heap_Get_free_information(
+ Heap_Control *heap,
+ Heap_Information *info
+);
+
+/**
+ * @brief See _Heap_Get_size().
+ */
+uintptr_t _Protected_heap_Get_size( Heap_Control *heap );
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
new file mode 100644
index 0000000000..c094b9400a
--- /dev/null
+++ b/cpukit/score/include/rtems/score/scheduler.h
@@ -0,0 +1,122 @@
+/**
+ * @file rtems/score/scheduler.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the scheduler.
+ */
+
+/*
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULER_H
+#define _RTEMS_SCORE_SCHEDULER_H
+
+#include <rtems/score/percpu.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/prioritybitmap.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ScoreScheduler Scheduler Handler
+ *
+ * This handler encapsulates functionality related to managing sets of threads
+ * that are ready for execution.
+ */
+/**@{*/
+
+/**
+ * function jump table that holds pointers to the functions that
+ * implement specific schedulers.
+ */
+typedef struct {
+ /** Implements the scheduling decision logic (policy). */
+ void ( *initialize )(void);
+
+ /** Implements the scheduling decision logic (policy). */
+ void ( *schedule )(void);
+
+ /** Voluntarily yields the processor per the scheduling policy. */
+ void ( *yield )(void);
+
+ /** Removes the given thread from scheduling decisions. */
+ void ( *block )(Thread_Control *);
+
+ /** Adds the given thread to scheduling decisions. */
+ void ( *unblock )(Thread_Control *);
+
+ /** allocates the scheduler field of the given thread */
+ void * ( *allocate )(Thread_Control *);
+
+ /** frees the scheduler field of the given thread */
+ void ( *free )(Thread_Control *);
+
+ /** updates the scheduler field of the given thread -- primarily used
+ * when changing the thread's priority. */
+ void ( *update )(Thread_Control *);
+
+ /** enqueue a thread as the last of its priority group */
+ void ( *enqueue )(Thread_Control *);
+
+ /** enqueue a thread as the first of its priority group */
+ void ( *enqueue_first )(Thread_Control *);
+
+ /** extract a thread from the ready set */
+ void ( *extract )(Thread_Control *);
+} Scheduler_Operations;
+
+/**
+ * This is the structure used to manage the scheduler.
+ */
+typedef struct {
+ /**
+ * This points to the data structure used to manage the ready set of
+ * tasks. The pointer varies based upon the type of
+ * ready queue required by the scheduler.
+ */
+ void *information;
+
+ /** The jump table for scheduler-specific functions */
+ Scheduler_Operations Operations;
+} Scheduler_Control;
+
+/**
+ * The _Scheduler holds the structures used to manage the
+ * scheduler.
+ *
+ * @note Can we make this per-cpu? then _Scheduler will be a macro.
+ *
+ * @note This is instantiated and initialized in confdefs.h.
+ */
+extern Scheduler_Control _Scheduler;
+
+/**
+ * This routine initializes the scheduler to the policy chosen by the user
+ * through confdefs, or to the priority scheduler with ready chains by
+ * default.
+ */
+void _Scheduler_Handler_initialization( void );
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/scheduler.inl>
+#endif
+
+/**@}*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/schedulerpriority.h b/cpukit/score/include/rtems/score/schedulerpriority.h
new file mode 100644
index 0000000000..58ccc795e1
--- /dev/null
+++ b/cpukit/score/include/rtems/score/schedulerpriority.h
@@ -0,0 +1,194 @@
+/**
+ * @file rtems/score/schedulerpriority.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the manipulation of threads for the priority-based scheduler.
+ */
+
+/*
+ * Copryight (c) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULERPRIORITY_H
+#define _RTEMS_SCORE_SCHEDULERPRIORITY_H
+
+#include <rtems/score/chain.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup ScoreScheduler
+ *
+ */
+/**@{*/
+
+/**
+ * Entry points for the Deterministic Priority Based Scheduler.
+ */
+#define SCHEDULER_PRIORITY_ENTRY_POINTS \
+ { \
+ _Scheduler_priority_Initialize, /* initialize entry point */ \
+ _Scheduler_priority_Schedule, /* schedule entry point */ \
+ _Scheduler_priority_Yield, /* yield entry point */ \
+ _Scheduler_priority_Block, /* block entry point */ \
+ _Scheduler_priority_Unblock, /* unblock entry point */ \
+ _Scheduler_priority_Allocate, /* allocate entry point */ \
+ _Scheduler_priority_Free, /* free entry point */ \
+ _Scheduler_priority_Update, /* update entry point */ \
+ _Scheduler_priority_Enqueue, /* enqueue entry point */ \
+ _Scheduler_priority_Enqueue_first, /* enqueue_first entry point */ \
+ _Scheduler_priority_Extract /* extract entry point */ \
+ }
+
+/**
+ * Per-thread data related to the _Scheduler_PRIORITY scheduling policy.
+ */
+typedef struct {
+ /** This field points to the Ready FIFO for this thread's priority. */
+ Chain_Control *ready_chain;
+
+ /** This field contains precalculated priority map indices. */
+ Priority_bit_map_Information Priority_map;
+} Scheduler_priority_Per_thread;
+
+/**
+ * This routine initializes the priority scheduler.
+ */
+void _Scheduler_priority_Initialize(void);
+
+/**
+ * This routine removes @a the_thread from the scheduling decision,
+ * that is, removes it from the ready queue. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ *
+ * @param[in] the_thread is the thread to be blocked
+ */
+void _Scheduler_priority_Block(
+ Thread_Control *the_thread
+);
+
+/**
+ * This kernel routine sets the heir thread to be the next ready thread
+ * by invoking the_scheduler->ready_queue->operations->first().
+ */
+void _Scheduler_priority_Schedule(void);
+
+/**
+ * This routine allocates @a the_thread->scheduler.
+ *
+ * @param[in] the_thread is the thread the scheduler is allocating
+ * management memory for
+ */
+void * _Scheduler_priority_Allocate(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine frees @a the_thread->scheduler.
+ *
+ * @param[in] the_thread is the thread whose scheduler specific information
+ * will be deallocated.
+ */
+void _Scheduler_priority_Free(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine updates @a the_thread->scheduler based on @a the_scheduler
+ * structures and thread state.
+ *
+ * @param[in] the_thread will have its scheduler specific information
+ * structure updated.
+ */
+void _Scheduler_priority_Update(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine adds @a the_thread to the scheduling decision,
+ * that is, adds it to the ready queue and
+ * updates any appropriate scheduling variables, for example the heir thread.
+ *
+ * @param[in] the_thread will be unblocked
+ */
+void _Scheduler_priority_Unblock(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine is invoked when a thread wishes to voluntarily
+ * transfer control of the processor to another thread in the queue.
+ *
+ * This routine will remove the running THREAD from the ready queue
+ * and place it immediately at the rear of this chain. Reset timeslice
+ * and yield the processor functions both use this routine, therefore if
+ * reset is true and this is the only thread on the queue then the
+ * timeslice counter is reset. The heir THREAD will be updated if the
+ * running is also the currently the heir.
+ */
+void _Scheduler_priority_Yield( void );
+
+/**
+ * This routine puts @a the_thread on to the priority-based ready queue.
+ *
+ * @param[in] the_thread will be enqueued at the TAIL of its priority.
+ */
+void _Scheduler_priority_Enqueue(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine puts @a the_thread to the head of the ready queue.
+ * For priority-based ready queues, the thread will be the first thread
+ * at its priority level.
+ *
+ * @param[in] the_thread will be enqueued at the HEAD of its priority.
+ */
+void _Scheduler_priority_Enqueue_first(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine removes a specific thread from the scheduler's set
+ * of ready threads.
+ *
+ * @param[in] the_thread will be extracted from the ready set.
+ */
+void _Scheduler_priority_Extract(
+ Thread_Control *the_thread
+);
+
+/**
+ * This is the major bit map.
+ */
+extern volatile Priority_bit_map_Control _Priority_Major_bit_map;
+
+/**
+ * This is the minor bit map.
+ */
+extern Priority_bit_map_Control _Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/schedulerpriority.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/schedulersimple.h b/cpukit/score/include/rtems/score/schedulersimple.h
new file mode 100644
index 0000000000..ea060ea59c
--- /dev/null
+++ b/cpukit/score/include/rtems/score/schedulersimple.h
@@ -0,0 +1,199 @@
+/**
+ * @file rtems/score/schedulersimple.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the manipulation of threads on a simple-priority-based ready queue.
+ *
+ *
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULERSIMPLE_H
+#define _RTEMS_SCORE_SCHEDULERSIMPLE_H
+
+/**
+ * @addtogroup ScoreScheduler
+ *
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/scheduler.h>
+
+/**
+ * Entry points for Scheduler Simple
+ */
+#define SCHEDULER_SIMPLE_ENTRY_POINTS \
+ { \
+ _Scheduler_simple_Initialize, /* initialize entry point */ \
+ _Scheduler_simple_Schedule, /* schedule entry point */ \
+ _Scheduler_simple_Yield, /* yield entry point */ \
+ _Scheduler_simple_Block, /* block entry point */ \
+ _Scheduler_simple_Unblock, /* unblock entry point */ \
+ _Scheduler_simple_Allocate, /* allocate entry point */ \
+ _Scheduler_simple_Free, /* free entry point */ \
+ _Scheduler_simple_Update, /* update entry point */ \
+ _Scheduler_simple_Enqueue, /* enqueue entry point */ \
+ _Scheduler_simple_Enqueue_first, /* enqueue_first entry point */ \
+ _Scheduler_simple_Extract /* extract entry point */ \
+ }
+
+/**
+ * This routine initializes the simple scheduler.
+ */
+void _Scheduler_simple_Initialize( void );
+
+/**
+ * This routine sets the heir thread to be the next ready thread
+ * on the ready queue by getting the first node in the scheduler
+ * information.
+ */
+void _Scheduler_simple_Schedule( void );
+
+/**
+ * This routine is invoked when a thread wishes to voluntarily
+ * transfer control of the processor to another thread in the queue.
+ * It will remove the running THREAD from the scheduler.informaiton
+ * (where the ready queue is stored) and place it immediately at the
+ * between the last entry of its priority and the next priority thread.
+ * Reset timeslice and yield the processor functions both use this routine,
+ * therefore if reset is true and this is the only thread on the queue then
+ * the timeslice counter is reset. The heir THREAD will be updated if the
+ * running is also the currently the heir.
+*/
+void _Scheduler_simple_Yield( void );
+
+/**
+ * This routine removes @a the_thread from the scheduling decision,
+ * that is, removes it from the ready queue. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ *
+ * @param[in] the_thread is the thread that is to be blocked
+ */
+void _Scheduler_simple_Block(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine adds @a the_thread to the scheduling decision,
+ * that is, adds it to the ready queue and
+ * updates any appropriate scheduling variables, for example the heir thread.
+ *
+ * @param[in] the_thread is the thread that is to be unblocked
+ */
+void _Scheduler_simple_Unblock(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine removes a specific thread from the specified
+ * simple-based ready queue.
+ *
+ * @param[in] the_thread is the thread to be blocked
+ */
+void _Scheduler_simple_Extract(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine puts @a the_thread on to the ready queue.
+ *
+ * @param[in] the_thread is the thread to be blocked
+ */
+void _Scheduler_simple_Enqueue(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine puts @a the_thread to the head of the ready queue.
+ * The thread will be the first thread at its priority level.
+ *
+ * @param[in] the_thread is the thread to be blocked
+ */
+void _Scheduler_simple_Enqueue_first(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine is a place holder for any memeory allocation needed
+ * by the scheduler. For the simple scheduler the routine is an empty
+ * place holder.
+ *
+ * @param[in] the_thread is the thread the scheduler is allocating
+ * management memory for
+ *
+ * @return this routine returns -1 since this is just an empty placeholder
+ * and the return value may be defined differently by each scheduler.
+ */
+void *_Scheduler_simple_Allocate(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule update
+ *
+ * The overhead of a function call will still be imposed.
+ *
+ * @param[in] the_thread is the thread to be blocked
+ */
+void _Scheduler_simple_Update(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule free
+ *
+ * The overhead of a function call will still be imposed.
+ *
+ * @param[in] the_thread is the thread to be blocked
+ */
+void _Scheduler_simple_Free(
+ Thread_Control *the_thread
+);
+
+/**
+ * _Scheduler_simple_Ready_queue_Enqueue
+ *
+ * This routine puts @a the_thread on the ready queue
+ * at the end of its priority group.
+ *
+ * @param[in] the_thread - pointer to a thread control block
+ */
+void _Scheduler_simple_Ready_queue_Enqueue(
+ Thread_Control *the_thread
+);
+
+/**
+ * _Scheduler_simple_Ready_queue_Enqueue_first
+ *
+ * This routine puts @a the_thread on to the ready queue
+ * at the beginning of its priority group.
+ *
+ * @param[in] the_thread - pointer to a thread control block
+ */
+void _Scheduler_simple_Ready_queue_Enqueue_first(
+ Thread_Control *the_thread
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/schedulersimple.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/smplock.h b/cpukit/score/include/rtems/score/smplock.h
new file mode 100644
index 0000000000..a20d9260a4
--- /dev/null
+++ b/cpukit/score/include/rtems/score/smplock.h
@@ -0,0 +1,95 @@
+/**
+ * @file rtems/score/smplock.h
+ *
+ * This include file defines the interface for atomic locks
+ * which can be used in multiprocessor configurations.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_LOCK_H
+#define _RTEMS_LOCK_H
+
+#include <rtems/score/isr.h>
+
+/**
+ * @defgroup RTEMS Lock Interface
+ *
+ */
+
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This type is used to lock elements for atomic access.
+ *
+ * @note This type may move to RTEMS.
+ */
+typedef volatile uint32_t SMP_lock_Control;
+
+/**
+ * @brief Initialize a Lock
+ *
+ * This method is used to initialize the lock at @a lock.
+ *
+ * @param [in] lock is the address of the lock to obtain.
+ *
+ * @note This lock may be "too low" here. It may need to move
+ * out of the BSP area.
+ */
+void _SMP_lock_Spinlock_Initialize(
+ SMP_lock_Control *lock
+);
+
+/**
+ * @brief Obtain a Lock
+ *
+ * This method is used to obtain the lock at @a lock.
+ *
+ * @param [in] lock is the address of the lock to obtain.
+ *
+ * @return This method returns with processor interrupts disabled.
+ * The previous level is returned.
+ *
+ * @note This lock may be "too low" here. It may need to move
+ * out of the BSP area.
+ */
+ISR_Level _SMP_lock_Spinlock_Obtain(
+ SMP_lock_Control *lock
+);
+
+/**
+ * @brief Release a Lock
+ *
+ * This method is used to release the lock at @a lock.
+ *
+ * @param [in] lock is the address of the lock to obtain.
+ *
+ * @note This lock may be "too low" here. It may need to move
+ * out of the BSP area.
+ */
+void _SMP_lock_Spinlock_Release(
+ SMP_lock_Control *lock,
+ ISR_Level level
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/stack.h b/cpukit/score/include/rtems/score/stack.h
new file mode 100644
index 0000000000..8f5a0173f3
--- /dev/null
+++ b/cpukit/score/include/rtems/score/stack.h
@@ -0,0 +1,69 @@
+/**
+ * @file rtems/score/stack.h
+ *
+ * This include file contains all information about the thread
+ * Stack Handler. This Handler provides mechanisms which can be used to
+ * initialize and utilize stacks.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_STACK_H
+#define _RTEMS_SCORE_STACK_H
+
+/**
+ * @defgroup ScoreStack Stack Handler
+ *
+ * This handler encapsulates functionality which is used in the management
+ * of thread stacks.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following constant defines the minimum stack size which every
+ * thread must exceed.
+ */
+#define STACK_MINIMUM_SIZE CPU_STACK_MINIMUM_SIZE
+
+/**
+ * The following defines the control block used to manage each stack.
+ */
+typedef struct {
+ /** This is the stack size. */
+ size_t size;
+ /** This is the low memory address of stack. */
+ void *area;
+} Stack_Control;
+
+/**
+ * This variable contains the the minimum stack size;
+ *
+ * @note It is instantiated and set by User Configuration via confdefs.h.
+ */
+extern uint32_t rtems_minimum_stack_size;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/stack.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/states.h b/cpukit/score/include/rtems/score/states.h
new file mode 100644
index 0000000000..fc56924d8a
--- /dev/null
+++ b/cpukit/score/include/rtems/score/states.h
@@ -0,0 +1,127 @@
+/**
+ * @file rtems/score/states.h
+ *
+ * This include file contains thread execution state information.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_STATES_H
+#define _RTEMS_SCORE_STATES_H
+
+/**
+ * @defgroup ScoreStates Thread States Handler
+ *
+ * This handler encapsulates functionality which relates to the management of
+ * the state bitmap associated with each thread.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following type defines the control block used to manage a
+ * thread's state.
+ */
+typedef uint32_t States_Control;
+
+/*
+ * The following constants define the individual states which may be
+ * be used to compose and manipulate a thread's state.
+ */
+
+/** This macro corresponds to all states being set. */
+#define STATES_ALL_SET 0xfffff
+/** This macro corresponds to a task being ready. */
+#define STATES_READY 0x00000
+/** This macro corresponds to a task being created but not yet started. */
+#define STATES_DORMANT 0x00001
+/** This macro corresponds to a task being suspended. */
+#define STATES_SUSPENDED 0x00002
+/** This macro corresponds to a task being in an internal state transition. */
+#define STATES_TRANSIENT 0x00004
+/** This macro corresponds to a task which is waiting for a timeout. */
+#define STATES_DELAYING 0x00008
+/** This macro corresponds to a task waiting until a specific TOD. */
+#define STATES_WAITING_FOR_TIME 0x00010
+/** This macro corresponds to a task waiting for a variable length buffer. */
+#define STATES_WAITING_FOR_BUFFER 0x00020
+/** This macro corresponds to a task waiting for a fixed size segment. */
+#define STATES_WAITING_FOR_SEGMENT 0x00040
+/** This macro corresponds to a task waiting for a message. */
+#define STATES_WAITING_FOR_MESSAGE 0x00080
+/** This macro corresponds to a task waiting for an event. */
+#define STATES_WAITING_FOR_EVENT 0x00100
+/** This macro corresponds to a task waiting for a semaphore. */
+#define STATES_WAITING_FOR_SEMAPHORE 0x00200
+/** This macro corresponds to a task waiting for a mutex. */
+#define STATES_WAITING_FOR_MUTEX 0x00400
+/** This macro corresponds to a task waiting for a condition variable. */
+#define STATES_WAITING_FOR_CONDITION_VARIABLE 0x00800
+/** This macro corresponds to a task waiting for a join while exiting. */
+#define STATES_WAITING_FOR_JOIN_AT_EXIT 0x01000
+/** This macro corresponds to a task waiting for a reply to an MPCI request. */
+#define STATES_WAITING_FOR_RPC_REPLY 0x02000
+/** This macro corresponds to a task waiting for a period. */
+#define STATES_WAITING_FOR_PERIOD 0x04000
+/** This macro corresponds to a task waiting for a signal. */
+#define STATES_WAITING_FOR_SIGNAL 0x08000
+/** This macro corresponds to a task waiting for a barrier. */
+#define STATES_WAITING_FOR_BARRIER 0x10000
+/** This macro corresponds to a task waiting for a RWLock. */
+#define STATES_WAITING_FOR_RWLOCK 0x20000
+
+/** This macro corresponds to a task which is in an interruptible
+ * blocking state.
+ */
+#define STATES_INTERRUPTIBLE_BY_SIGNAL 0x10000000
+
+/** This macro corresponds to a task waiting for a local object operation. */
+#define STATES_LOCALLY_BLOCKED ( STATES_WAITING_FOR_BUFFER | \
+ STATES_WAITING_FOR_SEGMENT | \
+ STATES_WAITING_FOR_MESSAGE | \
+ STATES_WAITING_FOR_SEMAPHORE | \
+ STATES_WAITING_FOR_MUTEX | \
+ STATES_WAITING_FOR_CONDITION_VARIABLE | \
+ STATES_WAITING_FOR_JOIN_AT_EXIT | \
+ STATES_WAITING_FOR_SIGNAL | \
+ STATES_WAITING_FOR_BARRIER | \
+ STATES_WAITING_FOR_RWLOCK )
+
+/** This macro corresponds to a task waiting which is blocked on
+ * a thread queue. */
+#define STATES_WAITING_ON_THREAD_QUEUE \
+ ( STATES_LOCALLY_BLOCKED | \
+ STATES_WAITING_FOR_RPC_REPLY )
+
+/** This macro corresponds to a task waiting which is blocked. */
+#define STATES_BLOCKED ( STATES_DELAYING | \
+ STATES_WAITING_FOR_TIME | \
+ STATES_WAITING_FOR_PERIOD | \
+ STATES_WAITING_FOR_EVENT | \
+ STATES_WAITING_ON_THREAD_QUEUE | \
+ STATES_INTERRUPTIBLE_BY_SIGNAL )
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/states.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/sysstate.h b/cpukit/score/include/rtems/score/sysstate.h
new file mode 100644
index 0000000000..1164367ebb
--- /dev/null
+++ b/cpukit/score/include/rtems/score/sysstate.h
@@ -0,0 +1,98 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreSysState
+ *
+ * @brief System State Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SYSSTATE_H
+#define _RTEMS_SCORE_SYSSTATE_H
+
+#include <rtems/score/basedefs.h> /* SCORE_EXTERN */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ScoreSysState System State Handler
+ *
+ * @ingroup Score
+ *
+ * @brief Management of the internal system state of RTEMS.
+ *
+ * @{
+ */
+
+/**
+ * @brief System states.
+ */
+typedef enum {
+ /**
+ * @brief The system is before the end of the first phase of initialization.
+ */
+ SYSTEM_STATE_BEFORE_INITIALIZATION,
+
+ /**
+ * @brief The system is between end of the first phase of initialization but
+ * before multitasking is started.
+ */
+ SYSTEM_STATE_BEFORE_MULTITASKING,
+
+ /**
+ * @brief The system is attempting to initiate multitasking.
+ */
+ SYSTEM_STATE_BEGIN_MULTITASKING,
+
+ /**
+ * @brief The system is up and operating normally.
+ */
+ SYSTEM_STATE_UP,
+
+ /**
+ * @brief The system is in the midst of a shutdown.
+ */
+ SYSTEM_STATE_SHUTDOWN,
+
+ /**
+ * @brief A fatal error has occurred.
+ */
+ SYSTEM_STATE_FAILED
+} System_state_Codes;
+
+#define SYSTEM_STATE_CODES_FIRST SYSTEM_STATE_BEFORE_INITIALIZATION
+
+#define SYSTEM_STATE_CODES_LAST SYSTEM_STATE_FAILED
+
+#if defined(RTEMS_MULTIPROCESSING)
+SCORE_EXTERN bool _System_state_Is_multiprocessing;
+#endif
+
+SCORE_EXTERN System_state_Codes _System_state_Current;
+
+/*
+ * Make it possible for the application to get the system state information.
+ */
+
+#include <rtems/score/sysstate.inl>
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
new file mode 100644
index 0000000000..8754ee931d
--- /dev/null
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -0,0 +1,790 @@
+/**
+ * @file rtems/score/thread.h
+ *
+ * This include file contains all constants and structures associated
+ * with the thread control block.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREAD_H
+#define _RTEMS_SCORE_THREAD_H
+
+/**
+ * @defgroup ScoreThread Thread Handler
+ *
+ * This handler encapsulates functionality related to the management of
+ * threads. This includes the creation, deletion, and scheduling of threads.
+ *
+ * The following variables are maintained as part of the per cpu data
+ * structure.
+ *
+ * + Idle thread pointer
+ * + Executing thread pointer
+ * + Heir thread pointer
+ */
+/**@{*/
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE
+#endif
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT
+#endif
+
+#if defined(RTEMS_POSIX_API)
+ #define RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * The user can define this at configure time and go back to ticks
+ * resolution.
+ */
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timestamp.h>
+
+ typedef Timestamp_Control Thread_CPU_usage_t;
+#else
+ typedef uint32_t Thread_CPU_usage_t;
+#endif
+
+#include <rtems/score/percpu.h>
+#include <rtems/score/context.h>
+#include <rtems/score/cpu.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mppkt.h>
+#endif
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/states.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ * The following defines the "return type" of a thread.
+ *
+ * @note This cannot always be right. Some APIs have void
+ * tasks/threads, others return pointers, others may
+ * return a numeric value. Hopefully a pointer is
+ * always at least as big as an uint32_t . :)
+ */
+typedef void *Thread;
+
+/**
+ * @brief Type of the numeric argument of a thread entry function with at
+ * least one numeric argument.
+ *
+ * This numeric argument type designates an unsigned integer type with the
+ * property that any valid pointer to void can be converted to this type and
+ * then converted back to a pointer to void. The result will compare equal to
+ * the original pointer.
+ */
+typedef uintptr_t Thread_Entry_numeric_type;
+
+/**
+ * The following defines the ways in which the entry point for a
+ * thread can be invoked. Basically, it can be passed any
+ * combination/permutation of a pointer and an uint32_t value.
+ *
+ * @note For now, we are ignoring the return type.
+ */
+typedef enum {
+ THREAD_START_NUMERIC,
+ THREAD_START_POINTER,
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ THREAD_START_BOTH_POINTER_FIRST,
+ THREAD_START_BOTH_NUMERIC_FIRST
+ #endif
+} Thread_Start_types;
+
+/** This type corresponds to a very simple style thread entry point. */
+typedef Thread ( *Thread_Entry )( void ); /* basic type */
+
+/** This type corresponds to a thread entry point which takes a single
+ * unsigned thirty-two bit integer as an argument.
+ */
+typedef Thread ( *Thread_Entry_numeric )( Thread_Entry_numeric_type );
+
+/** This type corresponds to a thread entry point which takes a single
+ * untyped pointer as an argument.
+ */
+typedef Thread ( *Thread_Entry_pointer )( void * );
+
+/** This type corresponds to a thread entry point which takes a single
+ * untyped pointer and an unsigned thirty-two bit integer as arguments.
+ */
+typedef Thread ( *Thread_Entry_both_pointer_first )( void *, Thread_Entry_numeric_type );
+
+/** This type corresponds to a thread entry point which takes a single
+ * unsigned thirty-two bit integer and an untyped pointer and an
+ * as arguments.
+ */
+typedef Thread ( *Thread_Entry_both_numeric_first )( Thread_Entry_numeric_type, void * );
+
+/**
+ * The following lists the algorithms used to manage the thread cpu budget.
+ *
+ * Reset Timeslice: At each context switch, reset the time quantum.
+ * Exhaust Timeslice: Only reset the quantum once it is consumed.
+ * Callout: Execute routine when budget is consumed.
+ */
+typedef enum {
+ THREAD_CPU_BUDGET_ALGORITHM_NONE,
+ THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
+ THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
+ #endif
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
+ THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
+ #endif
+} Thread_CPU_budget_algorithms;
+
+/** This defines thes the entry point for the thread specific timeslice
+ * budget management algorithm.
+ */
+typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
+
+/** @brief Per Task Variable Manager Structure Forward Reference
+ *
+ * Forward reference to the per task variable structure.
+ */
+struct rtems_task_variable_tt;
+
+/** @brief Per Task Variable Manager Structure
+ *
+ * This is the internal structure used to manager per Task Variables.
+ */
+typedef struct {
+ /** This field points to the next per task variable for this task. */
+ struct rtems_task_variable_tt *next;
+ /** This field points to the physical memory location of this per
+ * task variable.
+ */
+ void **ptr;
+ /** This field is to the global value for this per task variable. */
+ void *gval;
+ /** This field is to this thread's value for this per task variable. */
+ void *tval;
+ /** This field points to the destructor for this per task variable. */
+ void (*dtor)(void *);
+} rtems_task_variable_t;
+
+/**
+ * The following structure contains the information which defines
+ * the starting state of a thread.
+ */
+typedef struct {
+ /** This field is the starting address for the thread. */
+ Thread_Entry entry_point;
+ /** This field indicates the how task is invoked. */
+ Thread_Start_types prototype;
+ /** This field is the pointer argument passed at thread start. */
+ void *pointer_argument;
+ /** This field is the numeric argument passed at thread start. */
+ Thread_Entry_numeric_type numeric_argument;
+ /*-------------- initial execution modes ----------------- */
+ /** This field indicates whether the thread was preemptible when
+ * it started.
+ */
+ bool is_preemptible;
+ /** This field indicates the CPU budget algorith. */
+ Thread_CPU_budget_algorithms budget_algorithm;
+ /** This field is the routine to invoke when the CPU allotment is
+ * consumed.
+ */
+ Thread_CPU_budget_algorithm_callout budget_callout;
+ /** This field is the initial ISR disable level of this thread. */
+ uint32_t isr_level;
+ /** This field is the initial priority. */
+ Priority_Control initial_priority;
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
+ /** This field indicates whether the SuperCore allocated the stack. */
+ bool core_allocated_stack;
+ #endif
+ /** This field is the stack information. */
+ Stack_Control Initial_stack;
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ /** This field is the initial FP context area address. */
+ Context_Control_fp *fp_context;
+ #endif
+ /** This field is the initial stack area address. */
+ void *stack;
+} Thread_Start_information;
+
+/**
+ * The following structure contains the information necessary to manage
+ * a thread which it is waiting for a resource.
+ */
+#define THREAD_STATUS_PROXY_BLOCKING 0x1111111
+
+/**
+ * @brief Union type to hold a pointer to an immutable or a mutable object.
+ *
+ * The main purpose is to enable passing of pointers to read-only send buffers
+ * in the message passing subsystem. This approach is somewhat fragile since
+ * it prevents the compiler to check if the operations on objects are valid
+ * with respect to the constant qualifier. An alternative would be to add a
+ * third pointer argument for immutable objects, but this would increase the
+ * structure size.
+ */
+typedef union {
+ void *mutable_object;
+ const void *immutable_object;
+} Thread_Wait_information_Object_argument_type;
+
+/** @brief Thread Blocking Management Information
+ *
+ * This contains the information required to manage a thread while it is
+ * blocked and to return information to it.
+ */
+typedef struct {
+ /** This field is the Id of the object this thread is waiting upon. */
+ Objects_Id id;
+ /** This field is used to return an integer while when blocked. */
+ uint32_t count;
+ /** This field is for a pointer to a user return argument. */
+ void *return_argument;
+ /** This field is for a pointer to a second user return argument. */
+ Thread_Wait_information_Object_argument_type
+ return_argument_second;
+ /** This field contains any options in effect on this blocking operation. */
+ uint32_t option;
+ /** This field will contain the return status from a blocking operation.
+ *
+ * @note The following assumes that all API return codes can be
+ * treated as an uint32_t.
+ */
+ uint32_t return_code;
+
+ /** This field is the chain header for the second through Nth tasks
+ * of the same priority blocked waiting on the same object.
+ */
+ Chain_Control Block2n;
+ /** This field points to the thread queue on which this thread is blocked. */
+ Thread_queue_Control *queue;
+} Thread_Wait_information;
+
+/**
+ * The following defines the control block used to manage
+ * each thread proxy.
+ *
+ * @note It is critical that proxies and threads have identical
+ * memory images for the shared part.
+ */
+typedef struct {
+ /** This field is the object management structure for each proxy. */
+ Objects_Control Object;
+ /** This field is the current execution state of this proxy. */
+ States_Control current_state;
+ /** This field is the current priority state of this proxy. */
+ Priority_Control current_priority;
+ /** This field is the base priority of this proxy. */
+ Priority_Control real_priority;
+ /** This field is the number of mutexes currently held by this proxy. */
+ uint32_t resource_count;
+
+ /** This field is the blocking information for this proxy. */
+ Thread_Wait_information Wait;
+ /** This field is the Watchdog used to manage proxy delays and timeouts. */
+ Watchdog_Control Timer;
+#if defined(RTEMS_MULTIPROCESSING)
+ /** This field is the received response packet in an MP system. */
+ MP_packet_Prefix *receive_packet;
+#endif
+ /****************** end of common block ********************/
+ /** This field is used to manage the set of proxies in the system. */
+ Chain_Node Active;
+} Thread_Proxy_control;
+
+/**
+ * The following record defines the control block used
+ * to manage each thread.
+ *
+ * @note It is critical that proxies and threads have identical
+ * memory images for the shared part.
+ */
+typedef enum {
+ /** This value is for the Classic RTEMS API. */
+ THREAD_API_RTEMS,
+ /** This value is for the POSIX API. */
+ THREAD_API_POSIX
+} Thread_APIs;
+
+/** This macro defines the first API which has threads. */
+#define THREAD_API_FIRST THREAD_API_RTEMS
+
+/** This macro defines the last API which has threads. */
+#define THREAD_API_LAST THREAD_API_POSIX
+
+/**
+ * This structure defines the Thread Control Block (TCB).
+ */
+struct Thread_Control_struct {
+ /** This field is the object management structure for each thread. */
+ Objects_Control Object;
+ /** This field is the current execution state of this thread. */
+ States_Control current_state;
+ /** This field is the current priority state of this thread. */
+ Priority_Control current_priority;
+ /** This field is the base priority of this thread. */
+ Priority_Control real_priority;
+ /** This field is the number of mutexes currently held by this thread. */
+ uint32_t resource_count;
+ /** This field is the blocking information for this thread. */
+ Thread_Wait_information Wait;
+ /** This field is the Watchdog used to manage thread delays and timeouts. */
+ Watchdog_Control Timer;
+#if defined(RTEMS_MULTIPROCESSING)
+ /** This field is the received response packet in an MP system. */
+ MP_packet_Prefix *receive_packet;
+#endif
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ /** This field is the head of queue of priority inheritance mutex
+ * held by the thread.
+ */
+ Chain_Control lock_mutex;
+#endif
+ /*================= end of common block =================*/
+ /** This field is the number of nested suspend calls. */
+ uint32_t suspend_count;
+#if defined(RTEMS_MULTIPROCESSING)
+ /** This field is true if the thread is offered globally */
+ bool is_global;
+#endif
+ /** This field is true if the thread is preemptible. */
+ bool is_preemptible;
+#if __RTEMS_ADA__
+ /** This field is the GNAT self context pointer. */
+ void *rtems_ada_self;
+#endif
+ /** This field is the length of the time quantum that this thread is
+ * allowed to consume. The algorithm used to manage limits on CPU usage
+ * is specified by budget_algorithm.
+ */
+ uint32_t cpu_time_budget;
+ /** This field is the algorithm used to manage this thread's time
+ * quantum. The algorithm may be specified as none which case,
+ * no limit is in place.
+ */
+ Thread_CPU_budget_algorithms budget_algorithm;
+ /** This field is the method invoked with the budgeted time is consumed. */
+ Thread_CPU_budget_algorithm_callout budget_callout;
+ /** This field is the amount of CPU time consumed by this thread
+ * since it was created.
+ */
+ Thread_CPU_usage_t cpu_time_used;
+
+ /** This pointer holds per-thread data for the scheduler and ready queue. */
+ void *scheduler_info;
+
+ /** This field contains information about the starting state of
+ * this thread.
+ */
+ Thread_Start_information Start;
+ /** This field contains the context of this thread. */
+ Context_Control Registers;
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ /** This field points to the floating point context for this thread.
+ * If NULL, the thread is integer only.
+ */
+ Context_Control_fp *fp_context;
+#endif
+ /** This field points to the newlib reentrancy structure for this thread. */
+ struct _reent *libc_reent;
+ /** This array contains the API extension area pointers. */
+ void *API_Extensions[ THREAD_API_LAST + 1 ];
+ /** This field points to the user extension pointers. */
+ void **extensions;
+ /** This field points to the set of per task variables. */
+ rtems_task_variable_t *task_variables;
+};
+
+/**
+ * Self for the GNU Ada Run-Time
+ */
+SCORE_EXTERN void *rtems_ada_self;
+
+/**
+ * The following defines the information control block used to
+ * manage this class of objects.
+ */
+SCORE_EXTERN Objects_Information _Thread_Internal_information;
+
+/**
+ * The following context area contains the context of the "thread"
+ * which invoked the start multitasking routine. This context is
+ * restored as the last action of the stop multitasking routine. Thus
+ * control of the processor can be returned to the environment
+ * which initiated the system.
+ */
+SCORE_EXTERN Context_Control _Thread_BSP_context;
+
+/**
+ * The following declares the dispatch critical section nesting
+ * counter which is used to prevent context switches at inopportune
+ * moments.
+ */
+SCORE_EXTERN volatile uint32_t _Thread_Dispatch_disable_level;
+
+/**
+ * The following holds how many user extensions are in the system. This
+ * is used to determine how many user extension data areas to allocate
+ * per thread.
+ */
+SCORE_EXTERN uint32_t _Thread_Maximum_extensions;
+
+/**
+ * The following is used to manage the length of a timeslice quantum.
+ */
+SCORE_EXTERN uint32_t _Thread_Ticks_per_timeslice;
+
+/**
+ * The following points to the thread whose floating point
+ * context is currently loaded.
+ */
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
+#endif
+
+/**
+ * The C library re-enter-rant global pointer. Some C library implementations
+ * such as newlib have a single global pointer that changed during a context
+ * switch. The pointer points to that global pointer. The Thread control block
+ * holds a pointer to the task specific data.
+ */
+SCORE_EXTERN struct _reent **_Thread_libc_reent;
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+
+ /**
+ * This contains the time since boot when the last context switch occurred.
+ * By placing it in the BSS, it will automatically be zeroed out at
+ * system initialization and does not need to be known outside this
+ * file.
+ */
+ SCORE_EXTERN Timestamp_Control _Thread_Time_of_last_context_switch;
+#endif
+
+/**
+ * This routine performs the initialization necessary for this handler.
+ */
+void _Thread_Handler_initialization(void);
+
+/**
+ * This routine creates the idle thread.
+ *
+ * @warning No thread should be created before this one.
+ */
+void _Thread_Create_idle(void);
+
+/**
+ * This routine initiates multitasking. It is invoked only as
+ * part of initialization and its invocation is the last act of
+ * the non-multitasking part of the system initialization.
+ */
+void _Thread_Start_multitasking( void );
+
+/**
+ * This routine is responsible for transferring control of the
+ * processor from the executing thread to the heir thread. As part
+ * of this process, it is responsible for the following actions:
+ *
+ * + saving the context of the executing thread
+ * + restoring the context of the heir thread
+ * + dispatching any signals for the resulting executing thread
+ */
+void _Thread_Dispatch( void );
+
+/**
+ * Allocate the requested stack space for the thread.
+ * return the actual size allocated after any adjustment
+ * or return zero if the allocation failed.
+ * Set the Start.stack field to the address of the stack
+ */
+
+size_t _Thread_Stack_Allocate(
+ Thread_Control *the_thread,
+ size_t stack_size
+);
+
+/**
+ * Deallocate the Thread's stack.
+ */
+void _Thread_Stack_Free(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine initializes the specified the thread. It allocates
+ * all memory associated with this thread. It completes by adding
+ * the thread to the local object table so operations on this
+ * thread id are allowed.
+ *
+ * @note If stack_area is NULL, it is allocated from the workspace.
+ *
+ * @note If the stack is allocated from the workspace, then it is
+ * guaranteed to be of at least minimum size.
+ */
+bool _Thread_Initialize(
+ Objects_Information *information,
+ Thread_Control *the_thread,
+ void *stack_area,
+ size_t stack_size,
+ bool is_fp,
+ Priority_Control priority,
+ bool is_preemptible,
+ Thread_CPU_budget_algorithms budget_algorithm,
+ Thread_CPU_budget_algorithm_callout budget_callout,
+ uint32_t isr_level,
+ Objects_Name name
+);
+
+/**
+ * This routine initializes the executable information for a thread
+ * and makes it ready to execute. After this routine executes, the
+ * thread competes with all other threads for CPU time.
+ */
+bool _Thread_Start(
+ Thread_Control *the_thread,
+ Thread_Start_types the_prototype,
+ void *entry_point,
+ void *pointer_argument,
+ Thread_Entry_numeric_type numeric_argument
+);
+
+/**
+ * This support routine restarts the specified task in a way that the
+ * next time this thread executes, it will begin execution at its
+ * original starting point.
+ *
+ * TODO: multiple task arg profiles
+ */
+bool _Thread_Restart(
+ Thread_Control *the_thread,
+ void *pointer_argument,
+ Thread_Entry_numeric_type numeric_argument
+);
+
+/**
+ * This routine resets a thread to its initial state but does
+ * not restart it.
+ */
+void _Thread_Reset(
+ Thread_Control *the_thread,
+ void *pointer_argument,
+ Thread_Entry_numeric_type numeric_argument
+);
+
+/**
+ * This routine frees all memory associated with the specified
+ * thread and removes it from the local object table so no further
+ * operations on this thread are allowed.
+ */
+void _Thread_Close(
+ Objects_Information *information,
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine removes any set states for the_thread. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ */
+void _Thread_Ready(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine clears the indicated STATES for the_thread. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ */
+void _Thread_Clear_state(
+ Thread_Control *the_thread,
+ States_Control state
+);
+
+/**
+ * This routine sets the indicated states for the_thread. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ */
+void _Thread_Set_state(
+ Thread_Control *the_thread,
+ States_Control state
+);
+
+/**
+ * This routine sets the TRANSIENT state for the_thread. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ */
+void _Thread_Set_transient(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine is invoked as part of processing each clock tick.
+ * It is responsible for determining if the current thread allows
+ * timeslicing and, if so, when its timeslice expires.
+ */
+void _Thread_Tickle_timeslice( void );
+
+/**
+ * This routine initializes the context of the_thread to its
+ * appropriate starting state.
+ */
+void _Thread_Load_environment(
+ Thread_Control *the_thread
+);
+
+/**
+ * This routine is the wrapper function for all threads. It is
+ * the starting point for all threads. The user provided thread
+ * entry point is invoked by this routine. Operations
+ * which must be performed immediately before and after the user's
+ * thread executes are found here.
+ */
+void _Thread_Handler( void );
+
+/**
+ * This routine is invoked when a thread must be unblocked at the
+ * end of a time based delay (i.e. wake after or wake when).
+ */
+void _Thread_Delay_ended(
+ Objects_Id id,
+ void *ignored
+);
+
+/**
+ * This routine changes the current priority of the_thread to
+ * new_priority. It performs any necessary scheduling operations
+ * including the selection of a new heir thread.
+ */
+void _Thread_Change_priority (
+ Thread_Control *the_thread,
+ Priority_Control new_priority,
+ bool prepend_it
+);
+
+/**
+ * This routine updates the priority related fields in the_thread
+ * control block to indicate the current priority is now new_priority.
+ */
+void _Thread_Set_priority(
+ Thread_Control *the_thread,
+ Priority_Control new_priority
+);
+
+/**
+ * This routine updates the related suspend fields in the_thread
+ * control block to indicate the current nested level.
+ */
+#define _Thread_Suspend( _the_thread ) \
+ _Thread_Set_state( _the_thread, STATES_SUSPENDED )
+
+/**
+ * This routine updates the related suspend fields in the_thread
+ * control block to indicate the current nested level. A force
+ * parameter of true will force a resume and clear the suspend count.
+ */
+#define _Thread_Resume( _the_thread ) \
+ _Thread_Clear_state( _the_thread, STATES_SUSPENDED )
+
+#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
+/**
+ * This routine is the body of the system idle thread.
+ *
+ * NOTE: This routine is actually instantiated by confdefs.h when needed.
+ */
+void *_Thread_Idle_body(
+ uintptr_t ignored
+);
+#endif
+
+/** This defines the type for a method which operates on a single thread.
+ */
+typedef void (*rtems_per_thread_routine)( Thread_Control * );
+
+/**
+ * This routine iterates over all threads regardless of API and
+ * invokes the specified routine.
+ */
+void rtems_iterate_over_all_threads(
+ rtems_per_thread_routine routine
+);
+
+/**
+ * This function maps thread IDs to thread control
+ * blocks. If ID corresponds to a local thread, then it
+ * returns the_thread control pointer which maps to ID
+ * and location is set to OBJECTS_LOCAL. If the thread ID is
+ * global and resides on a remote node, then location is set
+ * to OBJECTS_REMOTE, and the_thread is undefined.
+ * Otherwise, location is set to OBJECTS_ERROR and
+ * the_thread is undefined.
+ *
+ * @note The performance of many RTEMS services depends upon
+ * the quick execution of the "good object" path in this
+ * routine. If there is a possibility of saving a few
+ * cycles off the execution time, this routine is worth
+ * further optimization attention.
+ */
+Thread_Control *_Thread_Get (
+ Objects_Id id,
+ Objects_Locations *location
+);
+
+/**
+ * @brief Cancel a blocking operation due to ISR
+ *
+ * This method is used to cancel a blocking operation that was
+ * satisfied from an ISR while the thread executing was in the
+ * process of blocking.
+ *
+ * @param[in] sync_state is the synchronization state
+ * @param[in] the_thread is the thread whose blocking is canceled
+ * @param[in] level is the previous ISR disable level
+ *
+ * @note This is a rare routine in RTEMS. It is called with
+ * interrupts disabled and only when an ISR completed
+ * a blocking condition in process.
+ */
+void _Thread_blocking_operation_Cancel(
+ Thread_blocking_operation_States sync_state,
+ Thread_Control *the_thread,
+ ISR_Level level
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/thread.inl>
+#endif
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/threadmp.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/threadmp.h b/cpukit/score/include/rtems/score/threadmp.h
new file mode 100644
index 0000000000..f3a3840f5d
--- /dev/null
+++ b/cpukit/score/include/rtems/score/threadmp.h
@@ -0,0 +1,88 @@
+/**
+ * @file rtems/score/threadmp.h
+ *
+ * This include file contains the specification for all routines
+ * and data specific to the multiprocessing portion of the thread package.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREADMP_H
+#define _RTEMS_SCORE_THREADMP_H
+
+/**
+ * @defgroup ScoreThreadMP Thread Handler Multiprocessing Support
+ *
+ * This handler encapsulates functionality which is related to managing
+ * threads in a multiprocessor system configuration. This handler must
+ * manage proxies which represent remote threads blocking on local
+ * operations.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief _Thread_MP_Handler_initialization
+ *
+ * This routine initializes the multiprocessing portion of the Thread Handler.
+ */
+void _Thread_MP_Handler_initialization (
+ uint32_t maximum_proxies
+);
+
+/** @brief _Thread_MP_Allocate_proxy
+ *
+ * This allocates a proxy control block from
+ * the inactive chain of free proxy control blocks.
+ *
+ * @note This function returns a thread control pointer
+ * because proxies are substitutes for remote threads.
+ */
+Thread_Control *_Thread_MP_Allocate_proxy (
+ States_Control the_state
+);
+
+/** @brief _Thread_MP_Find_proxy
+ *
+ * This function removes the proxy control block for the specified
+ * id from the active chain of proxy control blocks.
+ */
+Thread_Control *_Thread_MP_Find_proxy (
+ Objects_Id the_id
+);
+
+/** @brief Active Proxy Set
+ *
+ * The following chain is used to manage the active set proxies.
+ */
+SCORE_EXTERN Chain_Control _Thread_MP_Active_proxies;
+
+/** @brief Inactive Proxy Set
+ *
+ * The following chain is used to manage the inactive set of proxies.
+ */
+SCORE_EXTERN Chain_Control _Thread_MP_Inactive_proxies;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/threadmp.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/threadq.h b/cpukit/score/include/rtems/score/threadq.h
new file mode 100644
index 0000000000..357bbf713c
--- /dev/null
+++ b/cpukit/score/include/rtems/score/threadq.h
@@ -0,0 +1,300 @@
+/**
+ * @file rtems/score/threadq.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the manipulation of objects.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREADQ_H
+#define _RTEMS_SCORE_THREADQ_H
+
+/**
+ * @defgroup ScoreThreadQ Thread Queue Handler
+ *
+ * This handler encapsulates functionality related to managing sets of threads
+ * blocked waiting for resources.
+ */
+/**@{*/
+
+#include <rtems/score/tqdata.h>
+
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Constant for indefinite wait.
+ */
+#define THREAD_QUEUE_WAIT_FOREVER WATCHDOG_NO_TIMEOUT
+
+/**
+ * The following type defines the callout used when a remote task
+ * is extracted from a local thread queue.
+ */
+typedef void ( *Thread_queue_Flush_callout )(
+ Thread_Control *
+ );
+
+/**
+ *
+ * The following type defines the callout used for timeout processing
+ * methods.
+ */
+typedef void ( *Thread_queue_Timeout_callout )(
+ Objects_Id,
+ void *
+ );
+
+/** @brief Thread queue Dequeue
+ *
+ * This function returns a pointer to a thread waiting on
+ * the_thread_queue. The selection of this thread is based on
+ * the discipline of the_thread_queue. If no threads are waiting
+ * on the_thread_queue, then NULL is returned.
+ */
+Thread_Control *_Thread_queue_Dequeue(
+ Thread_queue_Control *the_thread_queue
+);
+
+/** @brief Thread queue Enqueue Wrapper
+ *
+ * This routine enqueues the currently executing thread on
+ * the_thread_queue with an optional timeout.
+ */
+#define _Thread_queue_Enqueue( _the_thread_queue, _timeout ) \
+ _Thread_queue_Enqueue_with_handler( \
+ _the_thread_queue, \
+ _timeout, \
+ _Thread_queue_Timeout )
+
+
+/** @brief Thread queue Enqueue
+ *
+ * This routine enqueues the currently executing thread on
+ * the_thread_queue with an optional timeout.
+ */
+void _Thread_queue_Enqueue_with_handler(
+ Thread_queue_Control* the_thread_queue,
+ Watchdog_Interval timeout,
+ Thread_queue_Timeout_callout handler
+);
+
+/**
+ * @brief Thread queue Requeue
+ *
+ * This routine is invoked when a thread changes priority and is
+ * blocked on a thread queue. If the queue is priority ordered,
+ * the_thread is removed from the_thread_queue and reinserted using
+ * its new priority. This method has no impact on the state of the_thread
+ * or of any timeouts associated with this blocking.
+ */
+void _Thread_queue_Requeue(
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread
+);
+
+/** @brief Thread queue Extract
+ *
+ * This routine removes the_thread from the_thread_queue
+ * and cancels any timeouts associated with this blocking.
+ */
+void _Thread_queue_Extract(
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread
+);
+
+/** @brief Thread queue Extract with proxy
+ *
+ * This routine extracts the_thread from the_thread_queue
+ * and ensures that if there is a proxy for this task on
+ * another node, it is also dealt with.
+ */
+bool _Thread_queue_Extract_with_proxy(
+ Thread_Control *the_thread
+);
+
+/** @brief Thread queue First
+ *
+ * This function returns a pointer to the "first" thread
+ * on the_thread_queue. The "first" thread is selected
+ * based on the discipline of the_thread_queue.
+ */
+Thread_Control *_Thread_queue_First(
+ Thread_queue_Control *the_thread_queue
+);
+
+/** @brief Thread queue Flush
+ *
+ * This routine unblocks all threads blocked on the_thread_queue
+ * and cancels any associated timeouts.
+ */
+void _Thread_queue_Flush(
+ Thread_queue_Control *the_thread_queue,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+);
+
+/** @brief Thread queue Initialize
+ *
+ * This routine initializes the_thread_queue based on the
+ * discipline indicated in attribute_set. The state set on
+ * threads which block on the_thread_queue is state.
+ */
+void _Thread_queue_Initialize(
+ Thread_queue_Control *the_thread_queue,
+ Thread_queue_Disciplines the_discipline,
+ States_Control state,
+ uint32_t timeout_status
+);
+
+/** @brief Thread queue Dequeue priority
+ *
+ * This function returns a pointer to the highest priority
+ * thread waiting on the_thread_queue. If no threads are waiting
+ * on the_thread_queue, then NULL is returned.
+ */
+Thread_Control *_Thread_queue_Dequeue_priority(
+ Thread_queue_Control *the_thread_queue
+);
+
+/** @brief Thread queue Enqueue priority
+ *
+ * This routine enqueues the currently executing thread on
+ * the_thread_queue with an optional timeout using the
+ * priority discipline.
+ */
+Thread_blocking_operation_States _Thread_queue_Enqueue_priority (
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread,
+ ISR_Level *level_p
+);
+
+/** @brief Thread queue Extract priority Helper
+ *
+ * This routine removes the_thread from the_thread_queue
+ * and cancels any timeouts associated with this blocking.
+ */
+void _Thread_queue_Extract_priority_helper(
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread,
+ bool requeuing
+);
+
+/**
+ * @brief Thread queue Extract priority
+ *
+ * This macro wraps the underlying call and hides the requeuing argument.
+ */
+
+#define _Thread_queue_Extract_priority( _the_thread_queue, _the_thread ) \
+ _Thread_queue_Extract_priority_helper( _the_thread_queue, _the_thread, false )
+
+
+/** @brief Thread queue First priority
+ *
+ * This function returns a pointer to the "first" thread
+ * on the_thread_queue. The "first" thread is the highest
+ * priority thread waiting on the_thread_queue.
+ */
+Thread_Control *_Thread_queue_First_priority(
+ Thread_queue_Control *the_thread_queue
+);
+
+/** @brief Thread queue Dequeue FIFO
+ *
+ * This function returns a pointer to the thread which has
+ * been waiting the longest on the_thread_queue. If no
+ * threads are waiting on the_thread_queue, then NULL is returned.
+ */
+Thread_Control *_Thread_queue_Dequeue_fifo(
+ Thread_queue_Control *the_thread_queue
+);
+
+/** @brief Thread queue Enqueue FIFO
+ *
+ * This routine enqueues the currently executing thread on
+ * the_thread_queue with an optional timeout using the
+ * FIFO discipline.
+ */
+Thread_blocking_operation_States _Thread_queue_Enqueue_fifo (
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread,
+ ISR_Level *level_p
+);
+
+/** @brief Thread queue Extract FIFO
+ *
+ * This routine removes the_thread from the_thread_queue
+ * and cancels any timeouts associated with this blocking.
+ */
+void _Thread_queue_Extract_fifo(
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread
+);
+
+/** @brief Thread queue First FIFO
+ *
+ * This function returns a pointer to the "first" thread
+ * on the_thread_queue. The first thread is the thread
+ * which has been waiting longest on the_thread_queue.
+ */
+Thread_Control *_Thread_queue_First_fifo(
+ Thread_queue_Control *the_thread_queue
+);
+
+/** @brief Thread queue timeout
+ *
+ * This routine is invoked when a task's request has not
+ * been satisfied after the timeout interval specified to
+ * enqueue. The task represented by ID will be unblocked and
+ * its status code will be set in it's control block to indicate
+ * that a timeout has occurred.
+ */
+void _Thread_queue_Timeout (
+ Objects_Id id,
+ void *ignored
+);
+
+/**
+ * @brief Process Thread Queue Timeout
+ *
+ * This is a shared helper routine which makes it easier to have multiple
+ * object class specific timeout routines.
+ *
+ * @param[in] the_thread is the thread to extract
+ *
+ * @note This method assumes thread dispatching is disabled
+ * and is expected to be called via the processing of
+ * a clock tick.
+ */
+void _Thread_queue_Process_timeout(
+ Thread_Control *the_thread
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/threadq.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/threadsync.h b/cpukit/score/include/rtems/score/threadsync.h
new file mode 100644
index 0000000000..9b5e3dee96
--- /dev/null
+++ b/cpukit/score/include/rtems/score/threadsync.h
@@ -0,0 +1,58 @@
+/**
+ * @file rtems/score/threadsync.h
+ *
+ * This include file contains all constants and structures associated
+ * with synchronizing a thread blocking operation with potential
+ * actions in an ISR.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREAD_SYNC_H
+#define _RTEMS_SCORE_THREAD_SYNC_H
+
+/**
+ * @defgroup ScoreThreadSync Thread Blocking Operation Synchronization Handler
+ *
+ * This handler encapsulates functionality related to the management of
+ * synchronization critical sections during blocking operations.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * The following enumerated types indicate what happened while the thread
+ * blocking was in the synchronization window.
+ */
+typedef enum {
+ THREAD_BLOCKING_OPERATION_SYNCHRONIZED,
+ THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED,
+ THREAD_BLOCKING_OPERATION_TIMEOUT,
+ THREAD_BLOCKING_OPERATION_SATISFIED
+} Thread_blocking_operation_States;
+
+/*
+ * Operations require a thread pointer so they are prototyped
+ * in thread.h
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/timespec.h b/cpukit/score/include/rtems/score/timespec.h
new file mode 100644
index 0000000000..06bbf4f373
--- /dev/null
+++ b/cpukit/score/include/rtems/score/timespec.h
@@ -0,0 +1,247 @@
+/**
+ * @file rtems/score/timespec.h
+ *
+ * This include file contains helpers for manipulating timespecs.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TIMESPEC_H
+#define _RTEMS_SCORE_TIMESPEC_H
+
+/**
+ * @defgroup Timespec Helpers
+ *
+ * This handler encapsulates functionality related to manipulating
+ * POSIX struct timespecs.
+ */
+/**@{*/
+
+#include <stdbool.h> /* bool */
+#include <stdint.h> /* uint32_t */
+#include <time.h> /* struct timespec */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief Set Timespec to Seconds Nanosecond
+ *
+ * This method sets the timespec to the specified seconds and nanoseconds
+ * value.
+ *
+ * @param[in] _time points to the timespec instance to validate.
+ * @param[in] _seconds is the seconds portion of the timespec
+ * @param[in] _nanoseconds is the nanoseconds portion of the timespec
+ */
+#define _Timespec_Set( _time, _seconds, _nanoseconds ) \
+ do { \
+ (_time)->tv_sec = (_seconds); \
+ (_time)->tv_nsec = (_nanoseconds); \
+ } while (0)
+
+/** @brief Zero Timespec
+ *
+ * This method sets the timespec to zero.
+ * value.
+ *
+ * @param[in] _time points to the timespec instance to zero.
+ */
+#define _Timespec_Set_to_zero( _time ) \
+ do { \
+ (_time)->tv_sec = 0; \
+ (_time)->tv_nsec = 0; \
+ } while (0)
+
+/** @brief Get Seconds Portion of Timespec
+ *
+ * This method returns the seconds portion of the specified timespec
+ *
+ * @param[in] _time points to the timespec
+ *
+ * @return The seconds portion of @a _time.
+ */
+#define _Timespec_Get_seconds( _time ) \
+ ((_time)->tv_sec)
+
+/** @brief Get Nanoseconds Portion of Timespec
+ *
+ * This method returns the nanoseconds portion of the specified timespec
+ *
+ * @param[in] _time points to the timespec
+ *
+ * @return The nanoseconds portion of @a _time.
+ */
+#define _Timespec_Get_nanoseconds( _time ) \
+ ((_time)->tv_nsec)
+
+/** @brief Is Timespec Valid
+ *
+ * This method determines the validity of a timespec.
+ *
+ * @param[in] time is the timespec instance to validate.
+ *
+ * @return This method returns true if @a time is valid and
+ * false otherwise.
+ */
+bool _Timespec_Is_valid(
+ const struct timespec *time
+);
+
+/** @brief Timespec Less Than Operator
+ *
+ * This method is the less than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the right hand side timespec
+ *
+ * @return This method returns true if @a lhs is less than the @a rhs and
+ * false otherwise.
+ */
+bool _Timespec_Less_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+);
+
+/** @brief Timespec Greater Than Operator
+ *
+ * This method is the greater than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the right hand side timespec
+ *
+ * @return This method returns true if @a lhs is greater than the @a rhs and
+ * false otherwise.
+ */
+bool _Timespec_Greater_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+);
+
+/** @brief Timespec equal to Operator
+ *
+ * This method is the is equal to than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the right hand side timespec
+ *
+ * @return This method returns true if @a lhs is equal to @a rhs and
+ * false otherwise.
+ */
+#define _Timespec_Equal_to( lhs, rhs ) \
+ ( ((lhs)->tv_sec == (rhs)->tv_sec) && \
+ ((lhs)->tv_nsec == (rhs)->tv_nsec) \
+ )
+
+/** @brief Add to a Timespec
+ *
+ * This routine adds two timespecs. The second argument is added
+ * to the first.
+ *
+ * @param[in] time is the base time to be added to
+ * @param[in] add is the timespec to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+uint32_t _Timespec_Add_to(
+ struct timespec *time,
+ const struct timespec *add
+);
+
+/** @brief Convert Timespec to Number of Ticks
+ *
+ * This routine convert the @a time timespec to the corresponding number
+ * of clock ticks.
+ *
+ * @param[in] time is the time to be converted
+ *
+ * @return This method returns the number of ticks computed.
+ */
+uint32_t _Timespec_To_ticks(
+ const struct timespec *time
+);
+
+/** @brief Convert Ticks to Timespec
+ *
+ * This routine converts the @a ticks value to the corresponding
+ * timespec format @a time.
+ *
+ * @param[in] time is the timespec format time result
+ * @param[in] ticks is the number of ticks to convert
+ */
+void _Timespec_From_ticks(
+ uint32_t ticks,
+ struct timespec *time
+);
+
+/** @brief Subtract Two Timespec
+ *
+ * This routine subtracts two timespecs. @a result is set to
+ * @a end - @a start.
+ *
+ * @param[in] start is the starting time
+ * @param[in] end is the ending time
+ * @param[in] result is the difference between starting and ending time.
+ *
+ * @return This method fills in @a result.
+ */
+void _Timespec_Subtract(
+ const struct timespec *start,
+ const struct timespec *end,
+ struct timespec *result
+);
+
+/** @brief Divide Timespec By Integer
+ *
+ * This routine divides a timespec by an integer value. The expected
+ * use is to assist in benchmark calculations where you typically
+ * divide a duration by a number of iterations.
+ *
+ * @param[in] time is the total
+ * @param[in] iterations is the number of iterations
+ * @param[in] result is the average time.
+ *
+ * @return This method fills in @a result.
+ */
+void _Timespec_Divide_by_integer(
+ const struct timespec *time,
+ uint32_t iterations,
+ struct timespec *result
+);
+
+/** @brief Divide Timespec
+ *
+ * This routine divides a timespec by another timespec. The
+ * intended use is for calculating percentages to three decimal points.
+ *
+ * @param[in] lhs is the left hand number
+ * @param[in] rhs is the right hand number
+ * @param[in] ival_percentage is the integer portion of the average
+ * @param[in] fval_percentage is the thousandths of percentage
+ *
+ * @return This method fills in @a result.
+ */
+void _Timespec_Divide(
+ const struct timespec *lhs,
+ const struct timespec *rhs,
+ uint32_t *ival_percentage,
+ uint32_t *fval_percentage
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/timestamp.h b/cpukit/score/include/rtems/score/timestamp.h
new file mode 100644
index 0000000000..6789e83e93
--- /dev/null
+++ b/cpukit/score/include/rtems/score/timestamp.h
@@ -0,0 +1,426 @@
+/**
+ * @file rtems/score/timestamp.h
+ *
+ * This include file contains helpers for manipulating timestamps.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TIMESTAMP_H
+#define _RTEMS_SCORE_TIMESTAMP_H
+
+/**
+ * @defgroup SuperCore Timestamp
+ *
+ * This handler encapsulates functionality related to manipulating
+ * SuperCore Timestamps. SuperCore Timestamps may be used to
+ * represent time of day, uptime, or intervals.
+ *
+ * The key attribute of the SuperCore Timestamp handler is that it
+ * is a completely opaque handler. There can be multiple implementations
+ * of the required functionality and with a recompile, RTEMS can use
+ * any implementation. It is intended to be a simple wrapper.
+ *
+ * This handler can be implemented as either struct timespec or
+ * unsigned64 bit numbers. The use of a wrapper class allows the
+ * the implementation of timestamps to change on a per architecture
+ * basis. This is an important option as the performance of this
+ * handler is critical.
+ */
+/**@{*/
+
+#include <rtems/score/timespec.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * NOTE: Eventually each port should select what it should use!!!
+ *
+ * These control which implementation of SuperCore Timestamp is used.
+ *
+ * if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ * struct timespec is used
+ * else if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
+ * int64_t is used
+ *
+ * When int64_t is used, then
+ * if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ * the methods are inlined
+ * else
+ * the methods are NOT inlined
+ *
+ * Performance of int64_t versus struct timespec
+ * =============================================
+ *
+ * On PowerPC/psim, inlined int64_t saves ~50 instructions on each
+ * _Thread_Dispatch operation which results in a context switch.
+ * This works out to be about 10% faster dispatches and 7.5% faster
+ * blocking semaphore obtains. The following numbers are in instructions
+ * and from tm02 and tm26.
+ *
+ * timespec int64 inlined int64
+ * dispatch: 446 446 400
+ * blocking sem obtain: 627 626 581
+ *
+ * On SPARC/sis, inlined int64_t shows the same percentage gains.
+ * The following numbers are in microseconds and from tm02 and tm26.
+ *
+ * timespec int64 inlined int64
+ * dispatch: 59 61 53
+ * blocking sem obtain: 98 100 92
+ *
+ * Inlining appears to have a tendency to increase the size of
+ * some executables.
+ * Not inlining reduces the execution improvement but does not seem to
+ * be an improvement on the PowerPC and SPARC. The struct timespec
+ * and the executables with int64 not inlined are about the same size.
+ *
+ * Once there has some analysis of which algorithm and configuration
+ * is best suited to each target, these defines should be moved to
+ * the appropriate score/cpu cpu.h file. In the meantime, it is
+ * appropriate to select an implementation here using CPU macros.
+ */
+
+#define CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC
+/*
+#define CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64
+#define CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE
+*/
+
+/*
+ * Verify something is defined.
+ */
+#if !defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
+ #error "No SuperCore Timestamp implementation selected."
+#endif
+
+/*
+ * Verify that more than one is not defined.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC) && \
+ defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
+ #error "Too many SuperCore Timestamp implementations selected."
+#endif
+
+/**
+ * Include any implementation specific header files
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
+ #include <rtems/score/timestamp64.h>
+#endif
+
+/**
+ * Define the Timestamp control type.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ typedef struct timespec Timestamp_Control;
+#else
+ typedef Timestamp64_Control Timestamp_Control;
+#endif
+
+/** @brief Set Timestamp to Seconds Nanosecond
+ *
+ * This method sets the timestamp to the specified seconds and nanoseconds
+ * value.
+ *
+ * @param[in] _time points to the timestamp instance to validate.
+ * @param[in] _seconds is the seconds portion of the timestamp
+ * @param[in] _nanoseconds is the nanoseconds portion of the timestamp
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
+ _Timespec_Set( _time, _seconds, _nanoseconds )
+#else
+ #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
+ _Timestamp64_Set( _time, _seconds, _nanoseconds )
+#endif
+
+/** @brief Zero Timestamp
+ *
+ * This method sets the timestamp to zero.
+ * value.
+ *
+ * @param[in] _time points to the timestamp instance to zero.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Set_to_zero( _time ) \
+ _Timespec_Set_to_zero( _time )
+#else
+ #define _Timestamp_Set_to_zero( _time ) \
+ _Timestamp64_Set_to_zero( _time )
+#endif
+
+/** @brief Is Timestamp Valid
+ *
+ * This method determines the validity of a timestamp.
+ *
+ * @param[in] _time points to the timestamp instance to validate.
+ *
+ * @return This method returns true if @a time is valid and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Is_valid( _time ) \
+ _Timespec_Is_valid( _time )
+#else
+ #define _Timestamp_Is_valid( _time ) \
+ _Timestamp64_Is_valid( _time )
+#endif
+
+/** @brief Timestamp Less Than Operator
+ *
+ * This method is the less than operator for timestamps.
+ *
+ * @param[in] _lhs points to the left hand side timestamp
+ * @param[in] _rhs points to the right hand side timestamp
+ *
+ * @return This method returns true if @a _lhs is less than the @a _rhs and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Less_than( _lhs, _rhs ) \
+ _Timespec_Less_than( _lhs, _rhs )
+#else
+ #define _Timestamp_Less_than( _lhs, _rhs ) \
+ _Timestamp64_Less_than( _lhs, _rhs )
+#endif
+
+/** @brief Timestamp Greater Than Operator
+ *
+ * This method is the greater than operator for timestamps.
+ *
+ * @param[in] _lhs points to the left hand side timestamp
+ * @param[in] _rhs points to the right hand side timestamp
+ *
+ * @return This method returns true if @a _lhs is greater than the @a _rhs and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Greater_than( _lhs, _rhs ) \
+ _Timespec_Greater_than( _lhs, _rhs )
+#else
+ #define _Timestamp_Greater_than( _lhs, _rhs ) \
+ _Timestamp64_Greater_than( _lhs, _rhs )
+#endif
+
+/** @brief Timestamp equal to Operator
+ *
+ * This method is the is equal to than operator for timestamps.
+ *
+ * @param[in] _lhs points to the left hand side timestamp
+ * @param[in] _rhs points to the right hand side timestamp
+ *
+ * @return This method returns true if @a _lhs is equal to @a _rhs and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Equal_to( _lhs, _rhs ) \
+ _Timespec_Equal_to( _lhs, _rhs )
+#else
+ #define _Timestamp_Equal_to( _lhs, _rhs ) \
+ _Timestamp64_Equal_to( _lhs, _rhs )
+#endif
+
+/** @brief Add to a Timestamp
+ *
+ * This routine adds two timestamps. The second argument is added
+ * to the first.
+ *
+ * @param[in] _time points to the base time to be added to
+ * @param[in] _add points to the timestamp to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Add_to( _time, _add ) \
+ _Timespec_Add_to( _time, _add )
+#else
+ #define _Timestamp_Add_to( _time, _add ) \
+ _Timestamp64_Add_to( _time, _add )
+#endif
+
+/** @brief Add to a Timestamp (At Clock Tick)
+ *
+ * This routine adds two timestamps. The second argument is added
+ * to the first.
+ *
+ * @node This routine places a special requirement on the addition
+ * operation. It must return the number of units that the
+ * seconds field changed as the result of the addition. Since this
+ * operation is ONLY used as part of processing a clock tick,
+ * it is generally safe to assume that only one second changed.
+ *
+ * @param[in] _time points to the base time to be added to
+ * @param[in] _add points to the timestamp to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Add_to_at_tick( _time, _add ) \
+ _Timespec_Add_to( _time, _add )
+#else
+ #define _Timestamp_Add_to_at_tick( _time, _add ) \
+ _Timestamp64_Add_to_at_tick( _time, _add )
+#endif
+
+/** @brief Convert Timestamp to Number of Ticks
+ *
+ * This routine convert the @a time timestamp to the corresponding number
+ * of clock ticks.
+ *
+ * @param[in] _time points to the time to be converted
+ *
+ * @return This method returns the number of ticks computed.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_To_ticks( _time ) \
+ _Timespec_To_ticks( _time )
+#else
+ #define _Timestamp_To_ticks( _time ) \
+ _Timestamp64_To_ticks( _time )
+#endif
+
+/** @brief Convert Ticks to Timestamp
+ *
+ * This routine converts the @a _ticks value to the corresponding
+ * timestamp format @a _time.
+ *
+ * @param[in] _time points to the timestamp format time result
+ * @param[in] _ticks points to the number of ticks to be filled in
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_From_ticks( _ticks, _time ) \
+ _Timespec_From_ticks( _ticks, _time )
+#else
+ #define _Timestamp_From_ticks( _ticks, _time ) \
+ _Timestamp64_From_ticks( _ticks, _time )
+#endif
+
+/** @brief Subtract Two Timestamp
+ *
+ * This routine subtracts two timestamps. @a result is set to
+ * @a end - @a start.
+ *
+ * @param[in] _start points to the starting time
+ * @param[in] _end points to the ending time
+ * @param[in] _result points to the difference between
+ * starting and ending time.
+ *
+ * @return This method fills in @a _result.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Subtract( _start, _end, _result ) \
+ _Timespec_Subtract( _start, _end, _result )
+#else
+ #define _Timestamp_Subtract( _start, _end, _result ) \
+ _Timestamp64_Subtract( _start, _end, _result )
+#endif
+
+/** @brief Divide Timestamp By Integer
+ *
+ * This routine divides a timestamp by an integer value. The expected
+ * use is to assist in benchmark calculations where you typically
+ * divide a duration by a number of iterations.
+ *
+ * @param[in] _time points to the total
+ * @param[in] _iterations is the number of iterations
+ * @param[in] _result points to the average time.
+ *
+ * @return This method fills in @a result.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
+ _Timespec_Divide_by_integer(_time, _iterations, _result )
+#else
+ #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
+ _Timestamp64_Divide_by_integer( _time, _iterations, _result )
+#endif
+
+/** @brief Divide Timestamp
+ *
+ * This routine divides a timestamp by another timestamp. The
+ * intended use is for calculating percentages to three decimal points.
+ *
+ * @param[in] _lhs points to the left hand number
+ * @param[in] _rhs points to the right hand number
+ * @param[in] _ival_percentage points to the integer portion of the average
+ * @param[in] _fval_percentage points to the thousandths of percentage
+ *
+ * @return This method fills in @a result.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
+ _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
+#else
+ #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
+ _Timestamp64_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
+#endif
+
+/** @brief Get Seconds Portion of Timestamp
+ *
+ * This method returns the seconds portion of the specified timestamp
+ *
+ * @param[in] _time points to the timestamp
+ *
+ * @return The seconds portion of @a _time.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Get_seconds( _time ) \
+ _Timespec_Get_seconds( _time )
+#else
+ #define _Timestamp_Get_seconds( _time ) \
+ _Timestamp64_Get_seconds( _time )
+#endif
+
+/** @brief Get Nanoseconds Portion of Timestamp
+ *
+ * This method returns the nanoseconds portion of the specified timestamp
+ *
+ * @param[in] _time points to the timestamp
+ *
+ * @return The nanoseconds portion of @a _time.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ #define _Timestamp_Get_nanoseconds( _time ) \
+ _Timespec_Get_nanoseconds( _time )
+#else
+ #define _Timestamp_Get_nanoseconds( _time ) \
+ _Timestamp64_Get_nanoseconds( _time )
+#endif
+
+/** @brief Convert Timestamp to struct timespec
+ *
+ * This method returns the seconds portion of the specified timestamp
+ *
+ * @param[in] _timestamp points to the timestamp
+ * @param[in] _timespec points to the timespec
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
+ /* in this case we know they are the same type so use simple assignment */
+ #define _Timestamp_To_timespec( _timestamp, _timespec ) \
+ *(_timespec) = *(_timestamp)
+#else
+ #define _Timestamp_To_timespec( _timestamp, _timespec ) \
+ _Timestamp64_To_timespec( _timestamp, _timespec )
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/timestamp64.h b/cpukit/score/include/rtems/score/timestamp64.h
new file mode 100644
index 0000000000..3b4300c6fa
--- /dev/null
+++ b/cpukit/score/include/rtems/score/timestamp64.h
@@ -0,0 +1,370 @@
+/**
+ * @file rtems/score/timestamp64.h
+ *
+ * This include file contains helpers for manipulating
+ * 64-bit integer timestamps.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TIMESTAMP64_H
+#define _RTEMS_SCORE_TIMESTAMP64_H
+
+/**
+ * @defgroup SuperCore Timestamp64
+ *
+ * This handler encapsulates functionality related to manipulating
+ * the 64 bit integer implementation of SuperCore Timestamps.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This .h file is not for general use. It is an alternative
+ * implementation of Timestamps and should only be used that way.
+ */
+#ifndef _RTEMS_SCORE_TIMESTAMP_H
+ #error "Should only be included by rtems/score/timestamp.h"
+#endif
+
+/*
+ * Verify something is defined.
+ */
+#if !defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
+ #error "SuperCore Timestamp64 implementation included but not defined."
+#endif
+
+/**
+ * Define the Timestamp control type.
+ */
+typedef int64_t Timestamp64_Control;
+
+/** @brief Set Timestamp to Seconds Nanosecond
+ *
+ * This method sets the timestamp to the specified seconds and nanoseconds
+ * value.
+ *
+ * @param[in] _time points to the timestamp instance to validate.
+ * @param[in] _seconds is the seconds portion of the timestamp
+ * @param[in] _nanoseconds is the nanoseconds portion of the timestamp
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Set( _time, _seconds, _nanoseconds ) \
+ do { \
+ *(_time) = ((int64_t)_seconds * 1000000000); \
+ *(_time) += (int64_t)(_nanoseconds); \
+ } while (0)
+#else
+ void _Timestamp64_Set(
+ Timestamp64_Control *_time,
+ long _seconds,
+ long _nanoseconds
+ );
+#endif
+
+/** @brief Zero Timestamp
+ *
+ * This method sets the timestamp to zero.
+ * value.
+ *
+ * @param[in] _time points to the timestamp instance to zero.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Set_to_zero( _time ) \
+ *(_time) = 0
+#else
+ void _Timestamp64_Set_to_zero(
+ Timestamp64_Control *_time
+ );
+#endif
+
+/** @brief Is Timestamp Valid
+ *
+ * This method determines the validity of a timestamp.
+ *
+ * @param[in] _time points to the timestamp instance to validate.
+ *
+ * @return This method returns true if @a time is valid and
+ * false otherwise.
+ */
+#define _Timestamp64_Is_valid( _time ) \
+ (1)
+
+/** @brief Timestamp Less Than Operator
+ *
+ * This method is the less than operator for timestamps.
+ *
+ * @param[in] _lhs points to the left hand side timestamp
+ * @param[in] _rhs points to the right hand side timestamp
+ *
+ * @return This method returns true if @a _lhs is less than the @a _rhs and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Less_than( _lhs, _rhs ) \
+ (*(_lhs) < *(_rhs))
+#else
+ bool _Timestamp64_Less_than(
+ Timestamp64_Control *_lhs,
+ Timestamp64_Control *_rhs
+ );
+#endif
+
+/** @brief Timestamp Greater Than Operator
+ *
+ * This method is the greater than operator for timestamps.
+ *
+ * @param[in] _lhs points to the left hand side timestamp
+ * @param[in] _rhs points to the right hand side timestamp
+ *
+ * @return This method returns true if @a _lhs is greater than the @a _rhs and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Greater_than( _lhs, _rhs ) \
+ (*(_lhs) > *(_rhs))
+#else
+ bool _Timestamp64_Greater_than(
+ Timestamp64_Control *_lhs,
+ Timestamp64_Control *_rhs
+ );
+#endif
+
+/** @brief Timestamp equal to Operator
+ *
+ * This method is the is equal to than operator for timestamps.
+ *
+ * @param[in] _lhs points to the left hand side timestamp
+ * @param[in] _rhs points to the right hand side timestamp
+ *
+ * @return This method returns true if @a _lhs is equal to @a _rhs and
+ * false otherwise.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Equal_to( _lhs, _rhs ) \
+ (*(_lhs) == *(_rhs))
+#else
+ bool _Timestamp64_Equal_to(
+ Timestamp64_Control *_lhs,
+ Timestamp64_Control *_rhs
+ );
+#endif
+
+/** @brief Add to a Timestamp
+ *
+ * This routine adds two timestamps. The second argument is added
+ * to the first.
+ *
+ * @param[in] _time points to the base time to be added to
+ * @param[in] _add points to the timestamp to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Add_to( _time, _add ) \
+ *(_time) += *(_add)
+#else
+ void _Timestamp64_Add_to(
+ Timestamp64_Control *_time,
+ Timestamp64_Control *_add
+ );
+#endif
+
+/** @brief Add to a Timestamp (At Clock Tick)
+ *
+ * This routine adds two timestamps. The second argument is added
+ * to the first.
+ *
+ * @node This routine places a special requirement on the addition
+ * operation. It must return the number of units that the
+ * seconds field changed as the result of the addition. Since this
+ * operation is ONLY used as part of processing a clock tick,
+ * it is generally safe to assume that only one second changed.
+ *
+ * @param[in] _time points to the base time to be added to
+ * @param[in] _add points to the timestamp to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+static inline uint32_t _Timestamp64_Add_to_at_tick(
+ Timestamp64_Control *_time,
+ Timestamp64_Control *_add
+)
+{
+ Timestamp64_Control start = *_time / 1000000000;
+ *_time += *_add;
+ if ( ((*_time) / 1000000000) != start ) {
+ return 1;
+ }
+ return 0;
+}
+
+/** @brief Convert Timestamp to Number of Ticks
+ *
+ * This routine convert the @a time timestamp to the corresponding number
+ * of clock ticks.
+ *
+ * @param[in] _time points to the time to be converted
+ *
+ * @return This method returns the number of ticks computed.
+ */
+uint32_t _Timestamp64_To_ticks(
+ const Timestamp64_Control *_time
+);
+
+/** @brief Convert Ticks to Timestamp
+ *
+ * This routine converts the @a _ticks value to the corresponding
+ * timestamp format @a _time.
+ *
+ * @param[in] _time points to the timestamp format time result
+ * @param[in] _ticks points to the number of ticks to be filled in
+ */
+void _Timestamp64_From_ticks(
+ uint32_t _ticks,
+ Timestamp64_Control *_time
+);
+
+/** @brief Subtract Two Timestamp
+ *
+ * This routine subtracts two timestamps. @a result is set to
+ * @a end - @a start.
+ *
+ * @param[in] _start points to the starting time
+ * @param[in] _end points to the ending time
+ * @param[in] _result points to the difference between
+ * starting and ending time.
+ *
+ * @return This method fills in @a _result.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Subtract( _start, _end, _result ) \
+ do { \
+ *(_result) = *(_end) - *(_start); \
+ } while (0)
+#else
+ void _Timestamp64_Subtract(
+ Timestamp64_Control *_start,
+ Timestamp64_Control *_end,
+ Timestamp64_Control *_result
+ );
+#endif
+
+/** @brief Divide Timestamp By Integer
+ *
+ * This routine divides a timestamp by an integer value. The expected
+ * use is to assist in benchmark calculations where you typically
+ * divide a duration by a number of iterations.
+ *
+ * @param[in] _time points to the total
+ * @param[in] _iterations is the number of iterations
+ * @param[in] _result points to the average time.
+ *
+ * @return This method fills in @a result.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Divide_by_integer( _time, _iterations, _result ) \
+ do { \
+ *(_result) = *(_time) / (_iterations); \
+ } while (0)
+#else
+ void _Timestamp64_Divide_by_integer(
+ Timestamp64_Control *_time,
+ uint32_t _iterations,
+ Timestamp64_Control *_result
+ );
+#endif
+
+/** @brief Divide Timestamp
+ *
+ * This routine divides a timestamp by another timestamp. The
+ * intended use is for calculating percentages to three decimal points.
+ *
+ * @param[in] _lhs points to the left hand number
+ * @param[in] _rhs points to the right hand number
+ * @param[in] _ival_percentage points to the integer portion of the average
+ * @param[in] _fval_percentage points to the thousandths of percentage
+ *
+ * @return This method fills in @a result.
+ */
+void _Timestamp64_Divide(
+ const Timestamp64_Control *_lhs,
+ const Timestamp64_Control *_rhs,
+ uint32_t *_ival_percentage,
+ uint32_t *_fval_percentage
+);
+
+/** @brief Get Seconds Portion of Timestamp
+ *
+ * This method returns the seconds portion of the specified timestamp
+ *
+ * @param[in] _time points to the timestamp
+ *
+ * @return The seconds portion of @a _time.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Get_seconds( _time ) \
+ (*(_time) / 1000000000)
+#else
+ uint32_t _Timestamp64_Get_seconds(
+ Timestamp64_Control *_time
+ );
+#endif
+
+/** @brief Get Nanoseconds Portion of Timestamp
+ *
+ * This method returns the nanoseconds portion of the specified timestamp
+ *
+ * @param[in] _time points to the timestamp
+ *
+ * @return The nanoseconds portion of @a _time.
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_Get_nanoseconds( _time ) \
+ (*(_time) % 1000000000)
+#else
+ uint32_t _Timestamp64_Get_nanoseconds(
+ Timestamp64_Control *_time
+ );
+#endif
+
+/** @brief Convert Timestamp to struct timespec
+ *
+ * This method returns the seconds portion of the specified timestamp
+ *
+ * @param[in] _timestamp points to the timestamp
+ * @param[in] _timespec points to the timespec
+ */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+ #define _Timestamp64_To_timespec( _timestamp, _timespec ) \
+ do { \
+ (_timespec)->tv_sec = *(_timestamp) / 1000000000; \
+ (_timespec)->tv_nsec = *(_timestamp) % 1000000000; \
+ } while (0)
+#else
+ void _Timestamp64_To_timespec(
+ Timestamp64_Control *_timestamp,
+ struct timespec *_timespec
+ );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
new file mode 100644
index 0000000000..1208975cab
--- /dev/null
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -0,0 +1,255 @@
+/**
+ * @file rtems/score/tod.h
+ *
+ * This include file contains all the constants and structures associated
+ * with the Time of Day Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TOD_H
+#define _RTEMS_SCORE_TOD_H
+
+#include <time.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/basedefs.h> /* SCORE_EXTERN */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @defgroup ScoreTODConstants TOD Constants
+ * The following constants are related to the time of day and are
+ * independent of RTEMS.
+ */
+/**@{*/
+
+/**
+ * This constant represents the number of seconds in a minute.
+ */
+#define TOD_SECONDS_PER_MINUTE (uint32_t)60
+
+/**
+ * This constant represents the number of minutes per hour.
+ */
+#define TOD_MINUTES_PER_HOUR (uint32_t)60
+
+/**
+ * This constant represents the number of months in a year.
+ */
+#define TOD_MONTHS_PER_YEAR (uint32_t)12
+
+/**
+ * This constant represents the number of days in a non-leap year.
+ */
+#define TOD_DAYS_PER_YEAR (uint32_t)365
+
+/**
+ * This constant represents the number of hours per day.
+ */
+#define TOD_HOURS_PER_DAY (uint32_t)24
+
+/**
+ * This constant represents the number of seconds in a day which does
+ * not include a leap second.
+ */
+#define TOD_SECONDS_PER_DAY (uint32_t) (TOD_SECONDS_PER_MINUTE * \
+ TOD_MINUTES_PER_HOUR * \
+ TOD_HOURS_PER_DAY)
+
+/**
+ * This constant represents the number of seconds in a non-leap year.
+ */
+#define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
+
+/**
+ * This constant represents the number of millisecond in a second.
+ */
+#define TOD_MILLISECONDS_PER_SECOND (uint32_t)1000
+
+/**
+ * This constant represents the number of microseconds in a second.
+ */
+#define TOD_MICROSECONDS_PER_SECOND (uint32_t)1000000
+
+/**
+ * This constant represents the number of nanoseconds in a second.
+ */
+#define TOD_NANOSECONDS_PER_SECOND (uint32_t)1000000000
+
+/**
+ * This constant represents the number of nanoseconds in a mircosecond.
+ */
+#define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
+
+/**@}*/
+
+/**
+ * Seconds from January 1, 1970 to January 1, 1988. Used to account for
+ * differences between POSIX API and RTEMS core. The timespec format time
+ * is kept in POSIX compliant form.
+ */
+#define TOD_SECONDS_1970_THROUGH_1988 \
+ (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
+ (4 * TOD_SECONDS_PER_DAY))
+
+/** @brief RTEMS Epoch Year
+ *
+ * The following constant define the earliest year to which an
+ * time of day can be initialized. This is considered the
+ * epoch.
+ */
+#define TOD_BASE_YEAR 1988
+
+/**
+ * @defgroup ScoreTOD Time Of Day (TOD) Handler
+ *
+ * This handler encapsulates functionality used to manage time of day.
+ */
+/**@{*/
+
+/** @brief Is the Time Of Day Set
+ *
+ * This is true if the application has set the current
+ * time of day, and false otherwise.
+ */
+SCORE_EXTERN bool _TOD_Is_set;
+
+/** @brief Current Time of Day (Timespec)
+ * The following contains the current time of day.
+ */
+SCORE_EXTERN Timestamp_Control _TOD_Now;
+
+/** @brief Current Time of Day (Timespec)
+ * The following contains the running uptime.
+ */
+SCORE_EXTERN Timestamp_Control _TOD_Uptime;
+
+/** @brief Seconds Since RTEMS Epoch
+ * The following contains the number of seconds from 00:00:00
+ * January 1, TOD_BASE_YEAR until the current time of day.
+ */
+#define _TOD_Seconds_since_epoch() \
+ _Timestamp_Get_seconds(&_TOD_Now)
+
+/** @brief _TOD_Handler_initialization
+ *
+ * This routine performs the initialization necessary for this handler.
+ */
+void _TOD_Handler_initialization(void);
+
+/** @brief _TOD_Set
+ *
+ * This routine sets the current time of day to @a time and
+ * the equivalent SECONDS_SINCE_EPOCH.
+ */
+void _TOD_Set(
+ const struct timespec *time
+);
+
+/** @brief _TOD_Get
+ *
+ * This routine returns the current time of day with potential accuracy
+ * to the nanosecond.
+ *
+ * @param[in] time is a pointer to the time to be returned
+ */
+void _TOD_Get(
+ struct timespec *time
+);
+
+/** @brief _TOD_Get_uptime
+ *
+ * This routine returns the system uptime with potential accuracy
+ * to the nanosecond.
+ *
+ * @param[in] time is a pointer to the uptime to be returned
+ */
+void _TOD_Get_uptime(
+ Timestamp_Control *time
+);
+
+/** @brief _TOD_Get_uptime_as_timespec
+ *
+ * This routine returns the system uptime with potential accuracy
+ * to the nanosecond.
+ *
+ * @param[in] time is a pointer to the uptime to be returned
+ */
+void _TOD_Get_uptime_as_timespec(
+ struct timespec *time
+);
+
+/**
+ * This routine increments the ticks field of the current time of
+ * day at each clock tick.
+ */
+void _TOD_Tickle_ticks( void );
+
+/** @brief TOD_MILLISECONDS_TO_MICROSECONDS
+ *
+ * This routine converts an interval expressed in milliseconds to microseconds.
+ *
+ * @note This must be a macro so it can be used in "static" tables.
+ */
+#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((uint32_t)(_ms) * 1000L)
+
+/** @brief TOD_MICROSECONDS_TO_TICKS
+ *
+ * This routine converts an interval expressed in microseconds to ticks.
+ *
+ * @note This must be a macro so it can be used in "static" tables.
+ */
+uint32_t TOD_MICROSECONDS_TO_TICKS(
+ uint32_t microseconds
+);
+
+/** @brief TOD_MILLISECONDS_TO_TICKS
+ *
+ * This routine converts an interval expressed in milliseconds to ticks.
+ *
+ * @note This must be a macro so it can be used in "static" tables.
+ */
+uint32_t TOD_MILLISECONDS_TO_TICKS(
+ uint32_t milliseconds
+);
+
+/** @brief How many ticks in a second?
+ *
+ * This method returns the number of ticks in a second.
+ *
+ * @note If the clock tick value does not multiply evenly into a second
+ * then this number of ticks will be slightly shorter than a second.
+ */
+uint32_t TOD_TICKS_PER_SECOND_method(void);
+
+/** @brief Method to return number of ticks in a second
+ *
+ * This method exists to hide the fact that TOD_TICKS_PER_SECOND can not
+ * be implemented as a macro in a .h file due to visibility issues.
+ * The Configuration Table is not available to SuperCore .h files but
+ * is available to their .c files.
+ */
+#define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/tod.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/tqdata.h b/cpukit/score/include/rtems/score/tqdata.h
new file mode 100644
index 0000000000..1531f7cbd8
--- /dev/null
+++ b/cpukit/score/include/rtems/score/tqdata.h
@@ -0,0 +1,116 @@
+/**
+ * @file rtems/score/tqdata.h
+ *
+ * This include file contains all the constants and structures
+ * needed to declare a thread queue.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TQDATA_H
+#define _RTEMS_SCORE_TQDATA_H
+
+/**
+ * @defgroup ScoreThreadQData Thread Queue Handler Data Definition
+ *
+ * This handler defines the data shared between the thread and thread
+ * queue handlers. Having this handler define these data structure
+ * avoids potentially circular references.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/chain.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/threadsync.h>
+
+/**
+ * The following enumerated type details all of the disciplines
+ * supported by the Thread Queue Handler.
+ */
+typedef enum {
+ THREAD_QUEUE_DISCIPLINE_FIFO, /* FIFO queue discipline */
+ THREAD_QUEUE_DISCIPLINE_PRIORITY /* PRIORITY queue discipline */
+} Thread_queue_Disciplines;
+
+/**
+ * This is one of the constants used to manage the priority queues.
+ *
+ * There are four chains used to maintain a priority -- each chain
+ * manages a distinct set of task priorities. The number of chains
+ * is determined by TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS.
+ * The following set must be consistent.
+ *
+ * The set below configures 4 headers -- each contains 64 priorities.
+ * Header x manages priority range (x*64) through ((x*64)+63). If
+ * the priority is more than half way through the priority range it
+ * is in, then the search is performed from the rear of the chain.
+ * This halves the search time to find the insertion point.
+ */
+#define TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS 4
+
+/**
+ * This is one of the constants used to manage the priority queues.
+ * @ref TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS for more details.
+ */
+#define TASK_QUEUE_DATA_PRIORITIES_PER_HEADER 64
+
+/**
+ * This is one of the constants used to manage the priority queues.
+ * @ref TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS for more details.
+ */
+#define TASK_QUEUE_DATA_REVERSE_SEARCH_MASK 0x20
+
+/**
+ * This is the structure used to manage sets of tasks which are blocked
+ * waiting to acquire a resource.
+ */
+typedef struct {
+ /** This union contains the data structures used to manage the blocked
+ * set of tasks which varies based upon the discipline.
+ */
+ union {
+ /** This is the FIFO discipline list. */
+ Chain_Control Fifo;
+ /** This is the set of lists for priority discipline waiting. */
+ Chain_Control Priority[TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS];
+ } Queues;
+ /** This field is used to manage the critical section. */
+ Thread_blocking_operation_States sync_state;
+ /** This field indicates the thread queue's blocking discipline. */
+ Thread_queue_Disciplines discipline;
+ /** This indicates the blocking state for threads waiting on this
+ * thread queue.
+ */
+ States_Control state;
+ /** This is the status value returned to threads which timeout while
+ * waiting on this thread queue.
+ */
+ uint32_t timeout_status;
+} Thread_queue_Control;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/tqdata.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/userext.h b/cpukit/score/include/rtems/score/userext.h
new file mode 100644
index 0000000000..b8604deae9
--- /dev/null
+++ b/cpukit/score/include/rtems/score/userext.h
@@ -0,0 +1,331 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_USEREXT_H
+#define _RTEMS_SCORE_USEREXT_H
+
+#include <rtems/score/interr.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void User_extensions_routine RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
+
+/**
+ * @defgroup ScoreUserExt User Extension Handler
+ *
+ * @ingroup Score
+ *
+ * @brief The User Extension Handler provides invocation of application
+ * dependent routines at critical points in the life of each thread and the
+ * system as a whole.
+ *
+ * @{
+ */
+
+/**
+ * @brief Task create extension.
+ *
+ * It corresponds to _Thread_Initialize() (used by the rtems_task_create()
+ * directive). The first parameter points to the currently executing thread
+ * which created the new thread. The second parameter points to the created
+ * thread.
+ *
+ * It is invoked after the new thread has been completely initialized, but
+ * before it is placed on a ready chain.
+ *
+ * Thread dispatching may be disabled. This depends on the context of the
+ * _Thread_Initialize() call. Thread dispatch is disabled during the creation
+ * of the idle thread and the initialization threads. It can be considered as
+ * an invalid API usage, if the application calls _Thread_Initialize() with
+ * disabled thread dispatching. Disabled thread dispatching is different from
+ * disabled preemption.
+ *
+ * It can be assumed that the executing thread locked the allocator mutex.
+ * The only exception is the creation of the idle thread. In this case the
+ * allocator mutex is not locked. Since the allocator mutex is non-recursive,
+ * it is prohibited to call the normal memory allocation routines. It is
+ * possible to use internal rountines like _Workspace_Allocate() or
+ * _Heap_Allocate() for heaps which are protected by the allocator mutex.
+ *
+ * @retval true The thread create extension was successful.
+ * @retval false A thread create user extension will frequently attempt to
+ * allocate resources. If this allocation fails, then the extension should
+ * return @a false and the entire thread create operation will fail.
+ */
+typedef bool ( *User_extensions_thread_create_extension )(
+ Thread_Control *,
+ Thread_Control *
+);
+
+/**
+ * @brief Task delete extension.
+ *
+ * It corresponds to _Thread_Close() (used by the rtems_task_delete()
+ * directive). The first parameter points to the currently executing thread
+ * which deleted the thread. The second parameter points to the deleted
+ * thread.
+ *
+ * It is invoked before all resources of the thread are deleted.
+ *
+ * Thread dispatching is enabled. The executing thread locked the allocator
+ * mutex.
+ */
+typedef void( *User_extensions_thread_delete_extension )(
+ Thread_Control *,
+ Thread_Control *
+);
+
+/**
+ * @brief Task start extension.
+ *
+ * It corresponds to _Thread_Start() (used by the rtems_task_start()
+ * directive). The first parameter points to the currently executing thread
+ * which started the thread. The second parameter points to the started
+ * thread.
+ *
+ * It is invoked after the environment of the thread has been loaded and the
+ * thread has been made ready.
+ *
+ * Thread dispatching is disabled. The executing thread is not the holder of
+ * the allocator mutex.
+ */
+typedef void( *User_extensions_thread_start_extension )(
+ Thread_Control *,
+ Thread_Control *
+);
+
+/**
+ * @brief Task restart extension.
+ *
+ * It corresponds to _Thread_Restart() (used by the rtems_task_restart()
+ * directive). The first parameter points to the currently executing thread
+ * which restarted the thread. The second parameter points to the restarted
+ * thread.
+ *
+ * It is invoked after the environment of the thread has been loaded and the
+ * thread has been made ready.
+ *
+ * Thread dispatching is disabled. The executing thread is not the holder of
+ * the allocator mutex.
+ */
+typedef void( *User_extensions_thread_restart_extension )(
+ Thread_Control *,
+ Thread_Control *
+);
+
+/**
+ * @brief Task switch extension.
+ *
+ * It corresponds to _Thread_Dispatch(). The first parameter points to the
+ * currently executing thread. The second parameter points to the heir thread.
+ *
+ * It is invoked before the context switch from the executing to the heir
+ * thread.
+ *
+ * Thread dispatching is disabled. The state of the allocator mutex is
+ * arbitrary.
+ *
+ * The context switches initiated through _Thread_Start_multitasking() and
+ * _Thread_Stop_multitasking() are not covered by this extension. The
+ * executing thread may run with a minimal setup, for example with a freed task
+ * stack.
+ */
+typedef void( *User_extensions_thread_switch_extension )(
+ Thread_Control *,
+ Thread_Control *
+);
+
+/**
+ * @brief Task begin extension.
+ *
+ * It corresponds to _Thread_Handler(). The first parameter points to the
+ * currently executing thread which begins now execution.
+ *
+ * Thread dispatching is disabled. The executing thread is not the holder of
+ * the allocator mutex.
+ */
+typedef void( *User_extensions_thread_begin_extension )(
+ Thread_Control *
+);
+
+/**
+ * @brief Task exitted extension.
+ *
+ * It corresponds to _Thread_Handler(). The first parameter points to the
+ * currently executing thread which exitted before.
+ *
+ * Thread dispatching is disabled. The state of the allocator mutex is
+ * arbitrary.
+ */
+typedef void( *User_extensions_thread_exitted_extension )(
+ Thread_Control *
+);
+
+/**
+ * @brief Fatal error extension.
+ *
+ * It corresponds to _Internal_error_Occurred() (used by the
+ * rtems_fatal_error_occurred() directive). The first parameter contains the
+ * error source. The second parameter indicates if it was an internal error.
+ * The third parameter contains the error code.
+ *
+ * This extension should not call any RTEMS directives.
+ */
+typedef void( *User_extensions_fatal_extension )(
+ Internal_errors_Source,
+ bool,
+ Internal_errors_t
+);
+
+/**
+ * @brief User extension table.
+ */
+typedef struct {
+ User_extensions_thread_create_extension thread_create;
+ User_extensions_thread_start_extension thread_start;
+ User_extensions_thread_restart_extension thread_restart;
+ User_extensions_thread_delete_extension thread_delete;
+ User_extensions_thread_switch_extension thread_switch;
+ User_extensions_thread_begin_extension thread_begin;
+ User_extensions_thread_exitted_extension thread_exitted;
+ User_extensions_fatal_extension fatal;
+} User_extensions_Table;
+
+/**
+ * @brief Manages the switch callouts.
+ *
+ * They are managed separately from other extensions for performance reasons.
+ */
+typedef struct {
+ Chain_Node Node;
+ User_extensions_thread_switch_extension thread_switch;
+} User_extensions_Switch_control;
+
+/**
+ * @brief Manages each user extension set.
+ *
+ * The switch control is part of the extensions control even if not used due to
+ * the extension not having a switch handler.
+ */
+typedef struct {
+ Chain_Node Node;
+ User_extensions_Switch_control Switch;
+ User_extensions_Table Callouts;
+} User_extensions_Control;
+
+/**
+ * @brief List of active extensions.
+ */
+SCORE_EXTERN Chain_Control _User_extensions_List;
+
+/**
+ * @brief List of active task switch extensions.
+ */
+SCORE_EXTERN Chain_Control _User_extensions_Switches_list;
+
+/**
+ * @name Extension Maintainance
+ *
+ * @{
+ */
+
+void _User_extensions_Handler_initialization( void );
+
+void _User_extensions_Add_set(
+ User_extensions_Control *extension
+);
+
+RTEMS_INLINE_ROUTINE void _User_extensions_Add_API_set(
+ User_extensions_Control *extension
+)
+{
+ _User_extensions_Add_set( extension );
+}
+
+RTEMS_INLINE_ROUTINE void _User_extensions_Add_set_with_table(
+ User_extensions_Control *extension,
+ const User_extensions_Table *extension_table
+)
+{
+ extension->Callouts = *extension_table;
+
+ _User_extensions_Add_set( extension );
+}
+
+void _User_extensions_Remove_set(
+ User_extensions_Control *extension
+);
+
+/** @} */
+
+/**
+ * @name Extension Callout Dispatcher
+ *
+ * @{
+ */
+
+bool _User_extensions_Thread_create(
+ Thread_Control *created
+);
+
+void _User_extensions_Thread_delete(
+ Thread_Control *deleted
+);
+
+void _User_extensions_Thread_start(
+ Thread_Control *started
+);
+
+void _User_extensions_Thread_restart(
+ Thread_Control *restarted
+);
+
+void _User_extensions_Thread_begin(
+ Thread_Control *executing
+);
+
+void _User_extensions_Thread_switch(
+ Thread_Control *executing,
+ Thread_Control *heir
+);
+
+void _User_extensions_Thread_exitted(
+ Thread_Control *executing
+);
+
+void _User_extensions_Fatal(
+ Internal_errors_Source source,
+ bool is_internal,
+ Internal_errors_t error
+);
+
+/** @} */
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/watchdog.h b/cpukit/score/include/rtems/score/watchdog.h
new file mode 100644
index 0000000000..33c2739633
--- /dev/null
+++ b/cpukit/score/include/rtems/score/watchdog.h
@@ -0,0 +1,323 @@
+/**
+ * @file rtems/score/watchdog.h
+ *
+ * This include file contains all the constants and structures associated
+ * with watchdog timers. This Handler provides mechanisms which can be
+ * used to initialize and manipulate watchdog timers.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_WATCHDOG_H
+#define _RTEMS_SCORE_WATCHDOG_H
+
+/**
+ * @defgroup ScoreWatchdog Watchdog Handler
+ *
+ * This handler encapsulates functionality related to the scheduling of
+ * watchdog functions to be called at specific times in the future.
+ *
+ * @note This handler does not have anything to do with hardware watchdog
+ * timers.
+ */
+/**@{*/
+
+#include <rtems/score/object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief Maximum Interval Length
+ *
+ * The following type defines the control block used to manage
+ * intervals.
+ */
+#define WATCHDOG_MAXIMUM_INTERVAL ((Watchdog_Interval) 0xffffffff)
+
+/** @brief Watchdog Interval Type
+ *
+ * This type is used to specify the length of intervals.
+ */
+typedef uint32_t Watchdog_Interval;
+
+/** @brief Watchdog Nanoseconds Since Last Tick Extension
+ *
+ * This type defines a pointer to the BSP plugin to obtain the number
+ * of nanoseconds since the last clock tick.
+ */
+typedef uint32_t (*Watchdog_Nanoseconds_since_last_tick_routine)(void);
+
+/** @brief Watchdog Service Routine Return Type
+ *
+ * This type defines the return type from a Watchdog Service Routine.
+ */
+typedef void Watchdog_Service_routine;
+
+/** @brief Watchdog Service Routine Pointer Type
+ *
+ * This type define a pointer to a watchdog service routine.
+ */
+typedef Watchdog_Service_routine ( *Watchdog_Service_routine_entry )(
+ Objects_Id,
+ void *
+ );
+
+/** @brief No timeout constant
+ *
+ * This is the constant for indefinite wait. It is actually an
+ * illegal interval.
+ */
+#define WATCHDOG_NO_TIMEOUT 0
+
+/** @brief Watchdog States Type
+ *
+ * This enumerated type is the set of the states in which a
+ * watchdog timer may be at any given time.
+ */
+
+typedef enum {
+ /** This is the state when the watchdog is off all chains */
+ WATCHDOG_INACTIVE,
+ /** This is the state when the watchdog is off all chains, but we are
+ * currently searching for the insertion point.
+ */
+ WATCHDOG_BEING_INSERTED,
+ /** This is the state when the watchdog is on a chain, and allowed to fire. */
+ WATCHDOG_ACTIVE,
+ /** This is the state when the watchdog is on a chain, but we should
+ * remove without firing if it expires.
+ */
+ WATCHDOG_REMOVE_IT
+} Watchdog_States;
+
+/** @brief Watchdog Adjustment Directions Type
+ *
+ * The following enumerated type details the manner in which
+ * a watchdog chain may be adjusted by the @ref _Watchdog_Adjust
+ * routine. The direction indicates a movement FORWARD
+ * or BACKWARD in time.
+ */
+typedef enum {
+ /** adjust delta value forward */
+ WATCHDOG_FORWARD,
+ /** adjust delta value backward */
+ WATCHDOG_BACKWARD
+} Watchdog_Adjust_directions;
+
+/** @brief Watchdog Control Structure
+ *
+ * The following record defines the control block used
+ * to manage each watchdog timer.
+ */
+typedef struct {
+ /** This field is a Chain Node structure and allows this to be placed on
+ * chains for set management.
+ */
+ Chain_Node Node;
+ /** This field is the state of the watchdog. */
+ Watchdog_States state;
+ /** This field is the initially requested interval. */
+ Watchdog_Interval initial;
+ /** This field is the remaining portion of the interval. */
+ Watchdog_Interval delta_interval;
+ /** This field is the number of system clock ticks when this was scheduled. */
+ Watchdog_Interval start_time;
+ /** This field is the number of system clock ticks when this was suspended. */
+ Watchdog_Interval stop_time;
+ /** This field is the function to invoke. */
+ Watchdog_Service_routine_entry routine;
+ /** This field is the Id to pass as an argument to the routine. */
+ Objects_Id id;
+ /** This field is an untyped pointer to user data that is passed to the
+ * watchdog handler routine.
+ */
+ void *user_data;
+} Watchdog_Control;
+
+/** @brief Watchdog Synchronization Level
+ *
+ * This used for synchronization purposes
+ * during an insert on a watchdog delta chain.
+ */
+SCORE_EXTERN volatile uint32_t _Watchdog_Sync_level;
+
+/** @brief Watchdog Synchronization Count
+ *
+ * This used for synchronization purposes
+ * during an insert on a watchdog delta chain.
+ */
+SCORE_EXTERN volatile uint32_t _Watchdog_Sync_count;
+
+/** @brief Ticks Since System Boot
+ *
+ * This contains the number of ticks since the system was booted.
+ */
+
+SCORE_EXTERN volatile Watchdog_Interval _Watchdog_Ticks_since_boot;
+
+/** @brief Watchdog Nanoseconds Since Last Tick Handler
+ *
+ * This is a pointer to the optional BSP plugin to obtain the number
+ * of nanoseconds since the last clock tick.
+ */
+extern Watchdog_Nanoseconds_since_last_tick_routine
+ _Watchdog_Nanoseconds_since_tick_handler;
+
+/** @brief Per Ticks Watchdog List
+ *
+ * This is the watchdog chain which is managed at ticks.
+ */
+SCORE_EXTERN Chain_Control _Watchdog_Ticks_chain;
+
+/** @brief Per Seconds Watchdog List
+ *
+ * This is the watchdog chain which is managed at second boundaries.
+ */
+SCORE_EXTERN Chain_Control _Watchdog_Seconds_chain;
+
+/** @brief Watchdog Handler Initialization
+ *
+ * This routine initializes the watchdog handler. The watchdog
+ * synchronization flag is initialized and the watchdog chains are
+ * initialized and emptied.
+ */
+void _Watchdog_Handler_initialization( void );
+
+/** @brief Remove Watchdog from List
+ *
+ * This routine removes @a the_watchdog from the watchdog chain on which
+ * it resides and returns the state @a the_watchdog timer was in.
+ *
+ * @param[in] the_watchdog will be removed
+ * @return the state in which @a the_watchdog was in when removed
+ */
+Watchdog_States _Watchdog_Remove (
+ Watchdog_Control *the_watchdog
+);
+
+/** @brief Watchdog Adjust
+ *
+ * This routine adjusts the @a header watchdog chain in the forward
+ * or backward @a direction for @a units ticks.
+ *
+ * @param[in] header is the watchdog chain to adjust
+ * @param[in] direction is the direction to adjust @a header
+ * @param[in] units is the number of units to adjust @a header
+ */
+void _Watchdog_Adjust (
+ Chain_Control *header,
+ Watchdog_Adjust_directions direction,
+ Watchdog_Interval units
+);
+
+/** @brief Watchdog Adjust to Chain
+ *
+ * This routine adjusts the @a header watchdog chain in the forward
+ * @a direction for @a units_arg ticks.
+ *
+ * @param[in] header is the watchdog chain to adjust
+ * @param[in] units_arg is the number of units to adjust @a header
+ * @param[in] to_fire is a pointer to an initialized Chain_Control to which
+ * all watchdog instances that are to be fired will be placed.
+ *
+ * @note This always adjusts forward.
+ */
+void _Watchdog_Adjust_to_chain(
+ Chain_Control *header,
+ Watchdog_Interval units_arg,
+ Chain_Control *to_fire
+
+);
+
+/** @brief Watchdog Insert
+ *
+ * This routine inserts @a the_watchdog into the @a header watchdog chain
+ * for a time of @a units.
+ *
+ * @param[in] header is @a the_watchdog list to insert @a the_watchdog on
+ * @param[in] the_watchdog is the watchdog to insert
+ */
+void _Watchdog_Insert (
+ Chain_Control *header,
+ Watchdog_Control *the_watchdog
+);
+
+/** @brief Watchdog Tickle
+ *
+ * This routine is invoked at appropriate intervals to update
+ * the @a header watchdog chain.
+ *
+ * @param[in] header is the watchdog chain to tickle
+ */
+void _Watchdog_Tickle (
+ Chain_Control *header
+);
+
+/**
+ * @brief Report Information on a Single Watchdog Instance
+ *
+ * This method prints a one line report on the watchdog instance
+ * provided. The @a name may be used to identify the watchdog and
+ * a space will be printed after @a name if it is not NULL.
+ *
+ * @param[in] name is a string to prefix the line with. If NULL,
+ * nothing is printed.
+ * @param[in] watch is the watchdog instance to be printed.
+ *
+ * @note This is a debug routine. It uses printk() and prudence should
+ * exercised when using it.
+ */
+void _Watchdog_Report(
+ const char *name,
+ Watchdog_Control *watch
+);
+
+/**
+ * @brief Report Information on a Watchdog Chain
+ *
+ * This method prints report on the watchdog chain provided.
+ * The @a name may be used to identify the watchdog chain and
+ * a space will be printed after @a name if it is not NULL.
+ *
+ * @param[in] name is a string to prefix the line with. If NULL,
+ * nothing is printed.
+ * @param[in] header is the watchdog chain to be printed.
+ *
+ * @note This is a debug routine. It uses printk() and prudence should
+ * exercised when using it. It also disables interrupts so the
+ * chain can be traversed in a single atomic pass.
+ */
+void _Watchdog_Report_chain(
+ const char *name,
+ Chain_Control *header
+);
+
+/**
+ * @brief Default nanoseconds since last tick handler.
+ *
+ * @retval 0 Always.
+ */
+uint32_t _Watchdog_Nanoseconds_since_tick_default_handler( void );
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/watchdog.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/wkspace.h b/cpukit/score/include/rtems/score/wkspace.h
new file mode 100644
index 0000000000..c3a0700a01
--- /dev/null
+++ b/cpukit/score/include/rtems/score/wkspace.h
@@ -0,0 +1,106 @@
+/**
+ * @file rtems/score/wkspace.h
+ *
+ * This include file contains information related to the
+ * RAM Workspace. This Handler provides mechanisms which can be used to
+ * define, initialize and manipulate the workspace.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_WKSPACE_H
+#define _RTEMS_SCORE_WKSPACE_H
+
+/**
+ * @defgroup ScoreWorkspace Workspace Handler
+ *
+ * This handler encapsulates functionality related to the management of
+ * the RTEMS Executive Workspace.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/score/heap.h>
+#include <rtems/score/interr.h>
+
+/** @brief Executive Workspace Control
+ *
+ * The is the heap control structure that used to manage the
+ * RTEMS Executive Workspace.
+ */
+SCORE_EXTERN Heap_Control _Workspace_Area; /* executive heap header */
+
+/** @brief Workspace Handler Initialization
+ *
+ * This routine performs the initialization necessary for this handler.
+ */
+void _Workspace_Handler_initialization(void);
+
+/** @brief Allocate Memory from Workspace
+ *
+ * This routine returns the address of a block of memory of size
+ * bytes. If a block of the appropriate size cannot be allocated
+ * from the workspace, then NULL is returned.
+ *
+ * @param size is the requested size
+ *
+ * @return a pointer to the requested memory or NULL.
+ */
+void *_Workspace_Allocate(
+ size_t size
+);
+
+/** @brief Free Memory to the Workspace
+ *
+ * This function frees the specified block of memory. If the block
+ * belongs to the Workspace and can be successfully freed, then
+ * true is returned. Otherwise false is returned.
+ *
+ * @param block is the memory to free
+ *
+ * @note If @a block is equal to NULL, then the request is ignored.
+ * This allows the caller to not worry about whether or not
+ * a pointer is NULL.
+ */
+
+void _Workspace_Free(
+ void *block
+);
+
+/** @brief Workspace Allocate or Fail with Fatal Error
+ *
+ * This routine returns the address of a block of memory of @a size
+ * bytes. If a block of the appropriate size cannot be allocated
+ * from the workspace, then the internal error handler is invoked.
+ *
+ * @param[in] size is the desired number of bytes to allocate
+ * @return If successful, the starting address of the allocated memory
+ */
+void *_Workspace_Allocate_or_fatal_error(
+ size_t size
+);
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/wkspace.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/seterr.h b/cpukit/score/include/rtems/seterr.h
new file mode 100644
index 0000000000..9eb4295554
--- /dev/null
+++ b/cpukit/score/include/rtems/seterr.h
@@ -0,0 +1,47 @@
+/**
+ * @file rtems/seterr.h
+ *
+ * This file contains macros and definitions which ease the burden
+ * of consistently setting errno and returning -1.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SETERR_H
+#define _RTEMS_SETERR_H
+
+#include <errno.h>
+
+/**
+ * This is a helper macro which will set the variable errno and return
+ * -1 to the caller. This pattern is common to many POSIX methods.
+ *
+ * @param[in] _error is the error code
+ */
+#define rtems_set_errno_and_return_minus_one( _error ) \
+ do { errno = (_error); return -1; } while(0)
+
+/**
+ * This is a helper macro which will set the variable errno and return
+ * -1 to the caller. This pattern is common to many POSIX methods.
+ *
+ * @param[in] _error is the error code
+ * @param[in] _cast is the type to which -1 must be cast
+ *
+ * @note It is similar to @ref rtems_set_errno_and_return_minus_one but
+ * this -1 value is cast to something other than an int.
+ */
+#define rtems_set_errno_and_return_minus_one_cast( _error, _cast ) \
+ do { errno = (_error); return (_cast) -1; } while(0)
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/system.h b/cpukit/score/include/rtems/system.h
new file mode 100644
index 0000000000..7ca6c33a8b
--- /dev/null
+++ b/cpukit/score/include/rtems/system.h
@@ -0,0 +1,64 @@
+/**
+ * @file rtems/system.h
+ *
+ * This include file contains information that is included in every
+ * function in the executive. This must be the first include file
+ * included in all internal RTEMS files.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SYSTEM_H
+#define _RTEMS_SYSTEM_H
+
+#include <rtems/score/percpu.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef ASM
+
+#ifdef RTEMS_POSIX_API
+/** The following is used by the POSIX implementation to catch bad paths. */
+int POSIX_NOT_IMPLEMENTED( void );
+#endif
+
+/**
+ * This macro is used to obtain the offset of a field in a structure.
+ */
+#define RTEMS_offsetof(type, field) \
+ ((uintptr_t) &(((type *) 0)->field))
+
+/**
+ * The following is the extern for the RTEMS version string.
+ *
+ * @note The contents of this string are CPU specific.
+ */
+extern const char _RTEMS_version[];
+
+/**
+ * The following is the extern for the RTEMS copyright string.
+ */
+extern const char _Copyright_Notice[];
+
+/** This macro defines the maximum length of a Classic API name. */
+#define RTEMS_MAXIMUM_NAME_LENGTH sizeof(rtems_name)
+
+#endif /* ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/address.inl b/cpukit/score/inline/rtems/score/address.inl
new file mode 100644
index 0000000000..03aeef3732
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/address.inl
@@ -0,0 +1,143 @@
+/**
+ * @file rtems/score/address.inl
+ *
+ * This include file contains the bodies of the routines
+ * about addresses which are inlined.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_ADDRESS_H
+# error "Never use <rtems/score/address.inl> directly; include <rtems/score/address.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_ADDRESS_INL
+#define _RTEMS_SCORE_ADDRESS_INL
+
+#include <rtems/score/basedefs.h>
+
+/**
+ * @addtogroup ScoreAddress
+ * @{
+ */
+
+/** @brief Add Offset to Address
+ *
+ * This function is used to add an @a offset to a @a base address.
+ * It returns the resulting address. This address is typically
+ * converted to an access type before being used further.
+ *
+ * @param[in] base is the base address.
+ * @param[in] offset is the offset to add to @a base.
+ *
+ * @return This method returns the resulting address.
+ */
+#include <rtems/bspIo.h>
+RTEMS_INLINE_ROUTINE void *_Addresses_Add_offset (
+ const void *base,
+ uintptr_t offset
+)
+{
+ return (void *)((uintptr_t)base + offset);
+}
+
+/** @brief Subtract Offset from Offset
+ *
+ * This function is used to subtract an @a offset from a @a base
+ * address. It returns the resulting address. This address is
+ * typically converted to an access type before being used further.
+ *
+ * @param[in] base is the base address.
+ * @param[in] offset is the offset to subtract to @a base.
+ *
+ * @return This method returns the resulting address.
+ */
+
+RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset (
+ const void *base,
+ uintptr_t offset
+)
+{
+ return (void *)((uintptr_t)base - offset);
+}
+
+/** @brief Subtract Two Offsets
+ *
+ * This function is used to subtract two addresses. It returns the
+ * resulting offset.
+ *
+ * @param[in] left is the address on the left hand side of the subtraction.
+ * @param[in] right is the address on the right hand side of the subtraction.
+ *
+ * @return This method returns the resulting address.
+ *
+ * @note The cast of an address to an uint32_t makes this code
+ * dependent on an addresses being thirty two bits.
+ */
+RTEMS_INLINE_ROUTINE int32_t _Addresses_Subtract (
+ const void *left,
+ const void *right
+)
+{
+ return (int32_t) ((const char *) left - (const char *) right);
+}
+
+/** @brief Is Address Aligned
+ *
+ * This function returns true if the given address is correctly
+ * aligned for this processor and false otherwise. Proper alignment
+ * is based on correctness and efficiency.
+ *
+ * @param[in] address is the address being checked for alignment.
+ *
+ * @return This method returns true if the address is aligned and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Addresses_Is_aligned (
+ const void *address
+)
+{
+#if (CPU_ALIGNMENT == 0)
+ return true;
+#else
+ return (((uintptr_t)address % CPU_ALIGNMENT) == 0);
+#endif
+}
+
+/** @brief Is Address In Range
+ *
+ * This function returns true if the given address is within the
+ * memory range specified and false otherwise. base is the address
+ * of the first byte in the memory range and limit is the address
+ * of the last byte in the memory range. The base address is
+ * assumed to be lower than the limit address.
+ *
+ * @param[in] address is the address to check.
+ * @param[in] base is the lowest address of the range to check against.
+ * @param[in] limit is the highest address of the range to check against.
+ *
+ * @return This method returns true if the given @a address is within the
+ * memory range specified and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Addresses_Is_in_range (
+ const void *address,
+ const void *base,
+ const void *limit
+)
+{
+ return (address >= base && address <= limit);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/chain.inl b/cpukit/score/inline/rtems/score/chain.inl
new file mode 100644
index 0000000000..ae6fd38b43
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/chain.inl
@@ -0,0 +1,647 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreChain
+ *
+ * @brief Chain Handler API.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CHAIN_H
+# error "Never use <rtems/score/chain.inl> directly; include <rtems/score/chain.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_CHAIN_INL
+#define _RTEMS_SCORE_CHAIN_INL
+
+/**
+ * @addtogroup ScoreChain
+ * @{
+ */
+
+/** @brief Set off chain
+ *
+ * This function sets the next and previous fields of the @a node to NULL
+ * indicating the @a node is not part of a chain.
+ *
+ * @param[in] node the node set to off chain.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Set_off_chain(
+ Chain_Node *node
+)
+{
+ node->next = node->previous = NULL;
+}
+
+/** @brief Is the Node off Chain
+ *
+ * This function returns true if the @a node is not on a chain. A @a node is
+ * off chain if the next and previous fields are set to NULL.
+ *
+ * @param[in] node is the node off chain.
+ *
+ * @return This function returns true if the @a node is off chain.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_node_off_chain(
+ const Chain_Node *node
+)
+{
+ return (node->next == NULL) && (node->previous == NULL);
+}
+
+/** @brief Are Two Nodes Equal
+ *
+ * This function returns true if @a left and @a right are equal,
+ * and false otherwise.
+ *
+ * @param[in] left is the node on the left hand side of the comparison.
+ * @param[in] right is the node on the left hand side of the comparison.
+ *
+ * @return This function returns true if @a left and @a right are equal,
+ * and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Are_nodes_equal(
+ const Chain_Node *left,
+ const Chain_Node *right
+)
+{
+ return left == right;
+}
+
+/** @brief Is this Chain Control Pointer Null
+ *
+ * This function returns true if the_chain is NULL and false otherwise.
+ *
+ * @param[in] the_chain is the chain to be checked for empty status.
+ *
+ * @return This method returns true if the_chain is NULL and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_null(
+ const Chain_Control *the_chain
+)
+{
+ return (the_chain == NULL);
+}
+
+/** @brief Is the Chain Node Pointer NULL
+ *
+ * This function returns true if the_node is NULL and false otherwise.
+ *
+ * @param[in] the_node is the node pointer to check.
+ *
+ * @return This method returns true if the_node is NULL and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_null_node(
+ const Chain_Node *the_node
+)
+{
+ return (the_node == NULL);
+}
+
+/** @brief Return pointer to Chain Head
+ *
+ * This function returns a pointer to the head node on the chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the permanent head node of the chain.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Head(
+ Chain_Control *the_chain
+)
+{
+ return &the_chain->Head.Node;
+}
+
+/** @brief Return pointer to immutable Chain Head
+ *
+ * This function returns a pointer to the head node on the chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the permanent head node of the chain.
+ */
+RTEMS_INLINE_ROUTINE const Chain_Node *_Chain_Immutable_head(
+ const Chain_Control *the_chain
+)
+{
+ return &the_chain->Head.Node;
+}
+
+/** @brief Return pointer to Chain Tail
+ *
+ * This function returns a pointer to the last node on the chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the permanent tail node of the chain.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Tail(
+ Chain_Control *the_chain
+)
+{
+ return &the_chain->Tail.Node;
+}
+
+/** @brief Return pointer to immutable Chain Tail
+ *
+ * This function returns a pointer to the last node on the chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the permanent tail node of the chain.
+ */
+RTEMS_INLINE_ROUTINE const Chain_Node *_Chain_Immutable_tail(
+ const Chain_Control *the_chain
+)
+{
+ return &the_chain->Tail.Node;
+}
+
+/** @brief Return pointer to Chain's First node
+ *
+ * This function returns a pointer to the first node on the chain after the
+ * head.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the first node of the chain.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_First(
+ Chain_Control *the_chain
+)
+{
+ return _Chain_Head( the_chain )->next;
+}
+
+/** @brief Return pointer to immutable Chain's First node
+ *
+ * This function returns a pointer to the first node on the chain after the
+ * head.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the first node of the chain.
+ */
+RTEMS_INLINE_ROUTINE const Chain_Node *_Chain_Immutable_first(
+ const Chain_Control *the_chain
+)
+{
+ return _Chain_Immutable_head( the_chain )->next;
+}
+
+/** @brief Return pointer to Chain's Last node
+ *
+ * This function returns a pointer to the last node on the chain just before
+ * the tail.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the last node of the chain.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Last(
+ Chain_Control *the_chain
+)
+{
+ return _Chain_Tail( the_chain )->previous;
+}
+
+/** @brief Return pointer to immutable Chain's Last node
+ *
+ * This function returns a pointer to the last node on the chain just before
+ * the tail.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This method returns the last node of the chain.
+ */
+RTEMS_INLINE_ROUTINE const Chain_Node *_Chain_Immutable_last(
+ const Chain_Control *the_chain
+)
+{
+ return _Chain_Immutable_tail( the_chain )->previous;
+}
+
+/** @brief Return pointer the next node from this node
+ *
+ * This function returns a pointer to the next node after this node.
+ *
+ * @param[in] the_node is the node to be operated upon.
+ *
+ * @return This method returns the next node on the chain.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Next(
+ Chain_Node *the_node
+)
+{
+ return the_node->next;
+}
+
+/** @brief Return pointer the previous node from this node
+ *
+ * This function returns a pointer to the previous node on this chain.
+ *
+ * @param[in] the_node is the node to be operated upon.
+ *
+ * @return This method returns the previous node on the chain.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Previous(
+ Chain_Node *the_node
+)
+{
+ return the_node->previous;
+}
+
+/** @brief Is the Chain Empty
+ *
+ * This function returns true if there a no nodes on @a the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This function returns true if there a no nodes on @a the_chain and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_empty(
+ const Chain_Control *the_chain
+)
+{
+ return _Chain_Immutable_first( the_chain )
+ == _Chain_Immutable_tail( the_chain );
+}
+
+/** @brief Is this the First Node on the Chain
+ *
+ * This function returns true if the_node is the first node on a chain and
+ * false otherwise.
+ *
+ * @param[in] the_node is the node the caller wants to know if it is
+ * the first node on a chain.
+ *
+ * @return This function returns true if @a the_node is the first node on
+ * a chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_first(
+ const Chain_Node *the_node
+)
+{
+ return (the_node->previous == NULL);
+}
+
+/** @brief Is this the Last Node on the Chain
+ *
+ * This function returns true if @a the_node is the last node on a chain and
+ * false otherwise.
+ *
+ * @param[in] the_node is the node to check as the last node.
+ *
+ * @return This function returns true if @a the_node is the last node on
+ * a chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_last(
+ const Chain_Node *the_node
+)
+{
+ return (the_node->next == NULL);
+}
+
+/** @brief Does this Chain have only One Node
+ *
+ * This function returns true if there is only one node on @a the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ *
+ * @return This function returns true if there is only one node on
+ * @a the_chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Has_only_one_node(
+ const Chain_Control *the_chain
+)
+{
+ return _Chain_Immutable_first( the_chain )
+ == _Chain_Immutable_last( the_chain );
+}
+
+/** @brief Is this Node the Chain Head
+ *
+ * This function returns true if @a the_node is the head of the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to check for being the Chain Head.
+ *
+ * @return This function returns true if @a the_node is the head of
+ * @a the_chain and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_head(
+ Chain_Control *the_chain,
+ const Chain_Node *the_node
+)
+{
+ return (the_node == _Chain_Head(the_chain));
+}
+
+/** @brief Is this Node the Chail Tail
+ *
+ * This function returns true if the_node is the tail of the_chain and
+ * false otherwise.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to check for being the Chain Tail.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Is_tail(
+ Chain_Control *the_chain,
+ const Chain_Node *the_node
+)
+{
+ return (the_node == _Chain_Tail(the_chain));
+}
+
+/** @brief Initialize this Chain as Empty
+ *
+ * This routine initializes the specified chain to contain zero nodes.
+ *
+ * @param[in] the_chain is the chain to be initialized.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty(
+ Chain_Control *the_chain
+)
+{
+ Chain_Node *head = _Chain_Head( the_chain );
+ Chain_Node *tail = _Chain_Tail( the_chain );
+
+ head->next = tail;
+ head->previous = NULL;
+ tail->previous = head;
+}
+
+/** @brief Extract this Node (unprotected)
+ *
+ * This routine extracts the_node from the chain on which it resides.
+ * It does NOT disable interrupts to ensure the atomicity of the
+ * extract operation.
+ *
+ * @param[in] the_node is the node to be extracted.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected(
+ Chain_Node *the_node
+)
+{
+ Chain_Node *next;
+ Chain_Node *previous;
+
+ next = the_node->next;
+ previous = the_node->previous;
+ next->previous = previous;
+ previous->next = next;
+}
+
+/** @brief Get the First Node (unprotected)
+ *
+ * This function removes the first node from the_chain and returns
+ * a pointer to that node. It does NOT disable interrupts to ensure
+ * the atomicity of the get operation.
+ *
+ * @param[in] the_chain is the chain to attempt to get the first node from.
+ *
+ * @return This method returns the first node on the chain even if it is
+ * the Chain Tail.
+ *
+ * @note This routine assumes that there is at least one node on the chain
+ * and always returns a node even if it is the Chain Tail.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Get_first_unprotected(
+ Chain_Control *the_chain
+)
+{
+ Chain_Node *head = _Chain_Head( the_chain );
+ Chain_Node *old_first = head->next;
+ Chain_Node *new_first = old_first->next;
+
+ head->next = new_first;
+ new_first->previous = head;
+
+ return old_first;
+}
+
+/** @brief Get the First Node (unprotected)
+ *
+ * This function removes the first node from the_chain and returns
+ * a pointer to that node. If the_chain is empty, then NULL is returned.
+ *
+ * @param[in] the_chain is the chain to attempt to get the first node from.
+ *
+ * @return This method returns the first node on the chain or NULL if the
+ * chain is empty.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * get operation.
+ */
+RTEMS_INLINE_ROUTINE Chain_Node *_Chain_Get_unprotected(
+ Chain_Control *the_chain
+)
+{
+ if ( !_Chain_Is_empty(the_chain))
+ return _Chain_Get_first_unprotected(the_chain);
+ else
+ return NULL;
+}
+
+/** @brief Insert a Node (unprotected)
+ *
+ * This routine inserts the_node on a chain immediately following
+ * after_node.
+ *
+ * @param[in] after_node is the node which will precede @a the_node on the
+ * chain.
+ * @param[in] the_node is the node to be inserted.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity
+ * of the extract operation.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Insert_unprotected(
+ Chain_Node *after_node,
+ Chain_Node *the_node
+)
+{
+ Chain_Node *before_node;
+
+ the_node->previous = after_node;
+ before_node = after_node->next;
+ after_node->next = the_node;
+ the_node->next = before_node;
+ before_node->previous = the_node;
+}
+
+/** @brief Append a Node (unprotected)
+ *
+ * This routine appends the_node onto the end of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be appended.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * append operation.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+)
+{
+ Chain_Node *tail = _Chain_Tail( the_chain );
+ Chain_Node *old_last = tail->previous;
+
+ the_node->next = tail;
+ tail->previous = the_node;
+ old_last->next = the_node;
+ the_node->previous = old_last;
+}
+
+/** @brief Prepend a Node (unprotected)
+ *
+ * This routine prepends the_node onto the front of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be prepended.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * prepend operation.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Prepend_unprotected(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+)
+{
+ _Chain_Insert_unprotected(_Chain_Head(the_chain), the_node);
+}
+
+/** @brief Prepend a Node (protected)
+ *
+ * This routine prepends the_node onto the front of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be prepended.
+ *
+ * @note It disables interrupts to ensure the atomicity of the
+ * prepend operation.
+ */
+RTEMS_INLINE_ROUTINE void _Chain_Prepend(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+)
+{
+ _Chain_Insert(_Chain_Head(the_chain), the_node);
+}
+
+/**
+ * @brief Append a node and check if the chain was empty before (unprotected).
+ *
+ * This routine appends the_node onto the end of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be appended.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * append operation.
+ *
+ * @retval true The chain was empty before.
+ * @retval false The chain contained at least one node before.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Append_with_empty_check_unprotected(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+)
+{
+ bool was_empty = _Chain_Is_empty( the_chain );
+
+ _Chain_Append_unprotected( the_chain, the_node );
+
+ return was_empty;
+}
+
+/**
+ * @brief Prepend a node and check if the chain was empty before (unprotected).
+ *
+ * This routine prepends the_node onto the front of the_chain.
+ *
+ * @param[in] the_chain is the chain to be operated upon.
+ * @param[in] the_node is the node to be prepended.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * prepend operation.
+ *
+ * @retval true The chain was empty before.
+ * @retval false The chain contained at least one node before.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Prepend_with_empty_check_unprotected(
+ Chain_Control *the_chain,
+ Chain_Node *the_node
+)
+{
+ bool was_empty = _Chain_Is_empty( the_chain );
+
+ _Chain_Prepend_unprotected( the_chain, the_node );
+
+ return was_empty;
+}
+
+/**
+ * @brief Get the first node and check if the chain is empty afterwards
+ * (unprotected).
+ *
+ * This function removes the first node from the_chain and returns
+ * a pointer to that node in @a the_node. If the_chain is empty, then NULL is
+ * returned.
+ *
+ * @param[in] the_chain is the chain to attempt to get the first node from.
+ * @param[out] the_node is the first node on the chain or NULL if the chain is
+ * empty.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * get operation.
+ *
+ * @retval true The chain is empty now.
+ * @retval false The chain contains at least one node now.
+ */
+RTEMS_INLINE_ROUTINE bool _Chain_Get_with_empty_check_unprotected(
+ Chain_Control *the_chain,
+ Chain_Node **the_node
+)
+{
+ bool is_empty_now = true;
+ Chain_Node *head = _Chain_Head( the_chain );
+ Chain_Node *tail = _Chain_Tail( the_chain );
+ Chain_Node *old_first = head->next;
+
+ if ( old_first != tail ) {
+ Chain_Node *new_first = old_first->next;
+
+ head->next = new_first;
+ new_first->previous = head;
+
+ *the_node = old_first;
+
+ is_empty_now = new_first == tail;
+ } else
+ *the_node = NULL;
+
+ return is_empty_now;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/corebarrier.inl b/cpukit/score/inline/rtems/score/corebarrier.inl
new file mode 100644
index 0000000000..a1e56fc221
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/corebarrier.inl
@@ -0,0 +1,66 @@
+/**
+ * @file rtems/score/corebarrier.inl
+ *
+ * This include file contains all of the inlined routines associated
+ * with the SuperCore barrier.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COREBARRIER_H
+# error "Never use <rtems/score/corebarrier.inl> directly; include <rtems/score/corebarrier.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_COREBARRIER_INL
+#define _RTEMS_SCORE_COREBARRIER_INL
+
+/**
+ * @addtogroup ScoreBarrier
+ * @{
+ */
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/**
+ * This function returns true if the automatic release attribute is
+ * enabled in the @a attribute_set and false otherwise.
+ *
+ * @param[in] the_attribute is the attribute set to test
+ * @return true if the priority attribute is enabled
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_barrier_Is_automatic(
+ CORE_barrier_Attributes *the_attribute
+)
+{
+ return
+ (the_attribute->discipline == CORE_BARRIER_AUTOMATIC_RELEASE);
+}
+
+/**
+ * This routine returns the number of threads currently waiting at the barrier.
+ *
+ * @param[in] the_barrier is the barrier to obtain the number of blocked
+ * threads for
+ * @return the current count of this barrier
+ */
+RTEMS_INLINE_ROUTINE uint32_t _CORE_barrier_Get_number_of_waiting_threads(
+ CORE_barrier_Control *the_barrier
+)
+{
+ return the_barrier->number_of_waiting_threads;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/coremsg.inl b/cpukit/score/inline/rtems/score/coremsg.inl
new file mode 100644
index 0000000000..5ec313af9a
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/coremsg.inl
@@ -0,0 +1,263 @@
+/**
+ * @file rtems/score/coremsg.inl
+ *
+ * This include file contains the static inline implementation of all
+ * inlined routines in the Core Message Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COREMSG_H
+# error "Never use <rtems/score/coremsg.inl> directly; include <rtems/score/coremsg.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_COREMSG_INL
+#define _RTEMS_SCORE_COREMSG_INL
+
+/**
+ * @addtogroup ScoreMessageQueue
+ * @{
+ */
+
+#include <string.h> /* needed for memcpy */
+
+/**
+ * This routine sends a message to the end of the specified message queue.
+ */
+RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Send(
+ CORE_message_queue_Control *the_message_queue,
+ const void *buffer,
+ size_t size,
+ Objects_Id id,
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ return _CORE_message_queue_Submit(
+ the_message_queue,
+ buffer,
+ size,
+ id,
+#if defined(RTEMS_MULTIPROCESSING)
+ api_message_queue_mp_support,
+#else
+ NULL,
+#endif
+ CORE_MESSAGE_QUEUE_SEND_REQUEST,
+ wait, /* sender may block */
+ timeout /* timeout interval */
+ );
+}
+
+/**
+ * This routine sends a message to the front of the specified message queue.
+ */
+RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Urgent(
+ CORE_message_queue_Control *the_message_queue,
+ const void *buffer,
+ size_t size,
+ Objects_Id id,
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ return _CORE_message_queue_Submit(
+ the_message_queue,
+ buffer,
+ size,
+ id,
+#if defined(RTEMS_MULTIPROCESSING)
+ api_message_queue_mp_support,
+#else
+ NULL,
+#endif
+ CORE_MESSAGE_QUEUE_URGENT_REQUEST,
+ wait, /* sender may block */
+ timeout /* timeout interval */
+ );
+}
+
+/**
+ * This routine copies the contents of the source message buffer
+ * to the destination message buffer.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_message_queue_Copy_buffer (
+ const void *source,
+ void *destination,
+ size_t size
+)
+{
+ memcpy(destination, source, size);
+}
+
+/**
+ * This function allocates a message buffer from the inactive
+ * message buffer chain.
+ */
+RTEMS_INLINE_ROUTINE CORE_message_queue_Buffer_control *
+_CORE_message_queue_Allocate_message_buffer (
+ CORE_message_queue_Control *the_message_queue
+)
+{
+ return (CORE_message_queue_Buffer_control *)
+ _Chain_Get( &the_message_queue->Inactive_messages );
+}
+
+/**
+ * This routine frees a message buffer to the inactive
+ * message buffer chain.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_message_queue_Free_message_buffer (
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Buffer_control *the_message
+)
+{
+ _Chain_Append( &the_message_queue->Inactive_messages, &the_message->Node );
+}
+
+/**
+ * This function returns the priority of @a the_message.
+ *
+ * NOTE: It encapsulates the optional behavior that message priority is
+ * disabled if no API requires it.
+ */
+RTEMS_INLINE_ROUTINE int _CORE_message_queue_Get_message_priority (
+ CORE_message_queue_Buffer_control *the_message
+)
+{
+ #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
+ return the_message->priority;
+ #else
+ return 0;
+ #endif
+}
+
+/**
+ * This function sets the priority of @a the_message.
+ *
+ * NOTE: It encapsulates the optional behavior that message priority is
+ * disabled if no API requires it.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_message_queue_Set_message_priority (
+ CORE_message_queue_Buffer_control *the_message,
+ int priority
+)
+{
+ #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
+ the_message->priority = priority;
+ #endif
+}
+
+/**
+ * This function removes the first message from the_message_queue
+ * and returns a pointer to it.
+ */
+RTEMS_INLINE_ROUTINE
+ CORE_message_queue_Buffer_control *_CORE_message_queue_Get_pending_message (
+ CORE_message_queue_Control *the_message_queue
+)
+{
+ return (CORE_message_queue_Buffer_control *)
+ _Chain_Get_unprotected( &the_message_queue->Pending_messages );
+}
+
+/**
+ * This function returns true if the priority attribute is
+ * enabled in the attribute_set and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_priority(
+ CORE_message_queue_Attributes *the_attribute
+)
+{
+ return
+ (the_attribute->discipline == CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY);
+}
+
+/**
+ * This routine places the_message at the rear of the outstanding
+ * messages on the_message_queue.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_message_queue_Append_unprotected (
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Buffer_control *the_message
+)
+{
+ _Chain_Append_unprotected(
+ &the_message_queue->Pending_messages,
+ &the_message->Node
+ );
+}
+
+/**
+ * This routine places the_message at the front of the outstanding
+ * messages on the_message_queue.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_message_queue_Prepend_unprotected (
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Buffer_control *the_message
+)
+{
+ _Chain_Prepend_unprotected(
+ &the_message_queue->Pending_messages,
+ &the_message->Node
+ );
+}
+
+/**
+ * This function returns true if the_message_queue is true and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_null (
+ CORE_message_queue_Control *the_message_queue
+)
+{
+ return ( the_message_queue == NULL );
+}
+
+#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
+ /**
+ * This function returns true if notification is enabled on this message
+ * queue and false otherwise.
+ */
+ RTEMS_INLINE_ROUTINE bool _CORE_message_queue_Is_notify_enabled (
+ CORE_message_queue_Control *the_message_queue
+ )
+ {
+ return (the_message_queue->notify_handler != NULL);
+ }
+#endif
+
+/**
+ * This routine initializes the notification information for
+ * @a the_message_queue.
+ */
+#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
+ RTEMS_INLINE_ROUTINE void _CORE_message_queue_Set_notify (
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Notify_Handler the_handler,
+ void *the_argument
+ )
+ {
+ the_message_queue->notify_handler = the_handler;
+ the_message_queue->notify_argument = the_argument;
+ }
+#else
+ /* turn it into nothing if not enabled */
+ #define _CORE_message_queue_Set_notify( \
+ the_message_queue, the_handler, the_argument )
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/coremutex.inl b/cpukit/score/inline/rtems/score/coremutex.inl
new file mode 100644
index 0000000000..f6f666159b
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/coremutex.inl
@@ -0,0 +1,229 @@
+/**
+ * @file rtems/score/coremutex.inl
+ *
+ * This include file contains all of the inlined routines associated
+ * with the CORE mutexes.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_COREMUTEX_H
+# error "Never use <rtems/score/coremutex.inl> directly; include <rtems/score/coremutex.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_COREMUTEX_INL
+#define _RTEMS_SCORE_COREMUTEX_INL
+
+/**
+ * @addtogroup ScoreMutex
+ * @{
+ */
+
+/**
+ * @brief Is Mutex Locked
+ *
+ * This routine returns true if the mutex specified is locked and false
+ * otherwise.
+ *
+ * @param[in] the_mutex is the mutex to check
+ *
+ * @return This method returns true if the mutex is locked.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_locked(
+ CORE_mutex_Control *the_mutex
+)
+{
+ return the_mutex->lock == CORE_MUTEX_LOCKED;
+}
+
+/**
+ * @brief Does Core Mutex Use FIFO Blocking
+ *
+ * This routine returns true if the mutex's wait discipline is FIFO and false
+ * otherwise.
+ *
+ * @param[in] the_attribute is the attribute set of the mutex
+ *
+ * @return This method returns true if the mutex is using FIFO blocking order.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_fifo(
+ CORE_mutex_Attributes *the_attribute
+)
+{
+ return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_FIFO;
+}
+
+/**
+ * @brief Doex Core Mutex Use Priority Blocking
+ *
+ * This routine returns true if the mutex's wait discipline is PRIORITY and
+ * false otherwise.
+ *
+ * @param[in] the_attribute is the attribute set of the mutex
+ *
+ * @return This method returns true if the mutex is using
+ * priority blocking order.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_priority(
+ CORE_mutex_Attributes *the_attribute
+)
+{
+ return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY;
+}
+
+/**
+ * @brief Does Mutex Use Priority Inheritance
+ *
+ * This routine returns true if the mutex's wait discipline is
+ * INHERIT_PRIORITY and false otherwise.
+ *
+ * @param[in] the_attribute is the attribute set of the mutex
+ *
+ * @return This method returns true if the mutex is using priority
+ * inheritance.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_inherit_priority(
+ CORE_mutex_Attributes *the_attribute
+)
+{
+ return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
+}
+
+/**
+ * @brief Does Mutex Use Priority Ceiling
+ *
+ * This routine returns true if the mutex's wait discipline is
+ * PRIORITY_CEILING and false otherwise.
+ *
+ * @param[in] the_attribute is the attribute set of the mutex
+ * @return This method returns true if the mutex is using priority
+ * ceiling.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_priority_ceiling(
+ CORE_mutex_Attributes *the_attribute
+)
+{
+ return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
+}
+
+/*
+ * Seize Mutex with Quick Success Path
+ *
+ * NOTE: There is no MACRO version of this routine. A body is in
+ * coremutexseize.c that is duplicated from the .inl by hand.
+ *
+ * NOTE: The Doxygen for this routine is in the .h file.
+ */
+
+RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
+ CORE_mutex_Control *the_mutex,
+ ISR_Level *level_p
+)
+{
+ Thread_Control *executing;
+
+ /* disabled when you get here */
+
+ executing = _Thread_Executing;
+ executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL;
+ if ( !_CORE_mutex_Is_locked( the_mutex ) ) {
+ the_mutex->lock = CORE_MUTEX_LOCKED;
+ the_mutex->holder = executing;
+ the_mutex->holder_id = executing->Object.id;
+ the_mutex->nest_count = 1;
+ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
+ _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ){
+
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ _Chain_Prepend_unprotected( &executing->lock_mutex,
+ &the_mutex->queue.lock_queue );
+ the_mutex->queue.priority_before = executing->current_priority;
+#endif
+
+ executing->resource_count++;
+ }
+
+ if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+ _ISR_Enable( *level_p );
+ return 0;
+ } /* else must be CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING
+ *
+ * we possibly bump the priority of the current holder -- which
+ * happens to be _Thread_Executing.
+ */
+ {
+ Priority_Control ceiling;
+ Priority_Control current;
+
+ ceiling = the_mutex->Attributes.priority_ceiling;
+ current = executing->current_priority;
+ if ( current == ceiling ) {
+ _ISR_Enable( *level_p );
+ return 0;
+ }
+
+ if ( current > ceiling ) {
+ _Thread_Disable_dispatch();
+ _ISR_Enable( *level_p );
+ _Thread_Change_priority(
+ the_mutex->holder,
+ the_mutex->Attributes.priority_ceiling,
+ false
+ );
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+ /* if ( current < ceiling ) */ {
+ executing->Wait.return_code = CORE_MUTEX_STATUS_CEILING_VIOLATED;
+ the_mutex->lock = CORE_MUTEX_UNLOCKED;
+ the_mutex->nest_count = 0; /* undo locking above */
+ executing->resource_count--; /* undo locking above */
+ _ISR_Enable( *level_p );
+ return 0;
+ }
+ }
+ return 0;
+ }
+
+ /*
+ * At this point, we know the mutex was not available. If this thread
+ * is the thread that has locked the mutex, let's see if we are allowed
+ * to nest access.
+ */
+ if ( _Thread_Is_executing( the_mutex->holder ) ) {
+ switch ( the_mutex->Attributes.lock_nesting_behavior ) {
+ case CORE_MUTEX_NESTING_ACQUIRES:
+ the_mutex->nest_count++;
+ _ISR_Enable( *level_p );
+ return 0;
+ #if defined(RTEMS_POSIX_API)
+ case CORE_MUTEX_NESTING_IS_ERROR:
+ executing->Wait.return_code = CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
+ _ISR_Enable( *level_p );
+ return 0;
+ #endif
+ case CORE_MUTEX_NESTING_BLOCKS:
+ break;
+ }
+ }
+
+ /*
+ * The mutex is not available and the caller must deal with the possibility
+ * of blocking.
+ */
+ return 1;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/corerwlock.inl b/cpukit/score/inline/rtems/score/corerwlock.inl
new file mode 100644
index 0000000000..b23ef32015
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/corerwlock.inl
@@ -0,0 +1,51 @@
+/**
+ * @file rtems/score/corerwlock.inl
+ *
+ * This include file contains all of the inlined routines associated
+ * with the SuperCore RWLock.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CORERWLOCK_H
+# error "Never use <rtems/score/corerwlock.inl> directly; include <rtems/score/corerwlock.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_CORERWLOCK_INL
+#define _RTEMS_SCORE_CORERWLOCK_INL
+
+/**
+ * @addtogroup ScoreRWLock
+ * @{
+ */
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/**
+ *
+ * This method is used to initialize core rwlock attributes.
+ *
+ * @param[in] the_attributes pointer to the attributes to initialize.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_RWLock_Initialize_attributes(
+ CORE_RWLock_Attributes *the_attributes
+)
+{
+ the_attributes->XXX = 0;
+}
+
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/coresem.inl b/cpukit/score/inline/rtems/score/coresem.inl
new file mode 100644
index 0000000000..3608b2d91b
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/coresem.inl
@@ -0,0 +1,115 @@
+/**
+ * @file rtems/score/coresem.inl
+ *
+ * This include file contains all of the inlined routines associated
+ * with the SuperCore semaphore.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CORESEM_H
+# error "Never use <rtems/score/coresem.inl> directly; include <rtems/score/coresem.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_CORESEM_INL
+#define _RTEMS_SCORE_CORESEM_INL
+
+/**
+ * @addtogroup ScoreSemaphore
+ * @{
+ */
+
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/**
+ * This function returns true if the priority attribute is
+ * enabled in the @a attribute_set and false otherwise.
+ *
+ * @param[in] the_attribute is the attribute set to test
+ * @return true if the priority attribute is enabled
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_semaphore_Is_priority(
+ CORE_semaphore_Attributes *the_attribute
+)
+{
+ return ( the_attribute->discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY );
+}
+
+/**
+ * This routine returns the current count associated with the semaphore.
+ *
+ * @param[in] the_semaphore is the semaphore to obtain the count of
+ * @return the current count of this semaphore
+ */
+RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count(
+ CORE_semaphore_Control *the_semaphore
+)
+{
+ return the_semaphore->count;
+}
+
+/**
+ * This routine attempts to receive a unit from the_semaphore.
+ * If a unit is available or if the wait flag is false, then the routine
+ * returns. Otherwise, the calling task is blocked until a unit becomes
+ * available.
+ *
+ * @param[in] the_semaphore is the semaphore to obtain
+ * @param[in] id is the Id of the owning API level Semaphore object
+ * @param[in] wait is true if the thread is willing to wait
+ * @param[in] timeout is the maximum number of ticks to block
+ * @param[in] level_p is a temporary variable used to contain the ISR
+ * disable level cookie
+ *
+ * @note There is currently no MACRO version of this routine.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_semaphore_Seize_isr_disable(
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ ISR_Level *level_p
+)
+{
+ Thread_Control *executing;
+
+ /* disabled when you get here */
+
+ executing = _Thread_Executing;
+ executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
+ if ( the_semaphore->count != 0 ) {
+ the_semaphore->count -= 1;
+ _ISR_Enable( *level_p );
+ return;
+ }
+
+ if ( !wait ) {
+ _ISR_Enable( *level_p );
+ executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
+ return;
+ }
+
+ _Thread_Disable_dispatch();
+ _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
+ executing->Wait.queue = &the_semaphore->Wait_queue;
+ executing->Wait.id = id;
+ _ISR_Enable( *level_p );
+
+ _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
+ _Thread_Enable_dispatch();
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/corespinlock.inl b/cpukit/score/inline/rtems/score/corespinlock.inl
new file mode 100644
index 0000000000..05e3408742
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/corespinlock.inl
@@ -0,0 +1,63 @@
+/**
+ * @file rtems/score/corespinlock.inl
+ *
+ * This include file contains all of the inlined routines associated
+ * with the SuperCore spinlock.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_CORESPINLOCK_H
+# error "Never use <rtems/score/corespinlock.inl> directly; include <rtems/score/corespinlock.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_CORESPINLOCK_INL
+#define _RTEMS_SCORE_CORESPINLOCK_INL
+
+/**
+ * @addtogroup ScoreSpinlock
+ * @{
+ */
+
+/**
+ *
+ * This method is used to initialize core spinlock attributes.
+ *
+ * @param[in] the_attributes pointer to the attributes to initialize.
+ */
+RTEMS_INLINE_ROUTINE void _CORE_spinlock_Initialize_attributes(
+ CORE_spinlock_Attributes *the_attributes
+)
+{
+ the_attributes->XXX = 0;
+}
+
+/**
+ *
+ * This method is used to determine if the spinlock is available or not.
+ *
+ * @param[in] the_spinlock will be checked
+ *
+ * @return This method will return true if the spinlock is busy
+ * and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _CORE_spinlock_Is_busy(
+ CORE_spinlock_Control *the_spinlock
+)
+{
+ return (the_spinlock->users != 0);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/heap.inl b/cpukit/score/inline/rtems/score/heap.inl
new file mode 100644
index 0000000000..50fb16a55c
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/heap.inl
@@ -0,0 +1,243 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_HEAP_H
+# error "Never use <rtems/score/heap.inl> directly; include <rtems/score/heap.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_HEAP_INL
+#define _RTEMS_SCORE_HEAP_INL
+
+#include <rtems/score/address.h>
+
+/**
+ * @addtogroup ScoreHeap
+ *
+ * @{
+ */
+
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_head( Heap_Control *heap )
+{
+ return &heap->free_list;
+}
+
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_tail( Heap_Control *heap )
+{
+ return &heap->free_list;
+}
+
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_first( Heap_Control *heap )
+{
+ return _Heap_Free_list_head(heap)->next;
+}
+
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_last( Heap_Control *heap )
+{
+ return _Heap_Free_list_tail(heap)->prev;
+}
+
+RTEMS_INLINE_ROUTINE void _Heap_Free_list_remove( Heap_Block *block )
+{
+ Heap_Block *next = block->next;
+ Heap_Block *prev = block->prev;
+
+ prev->next = next;
+ next->prev = prev;
+}
+
+RTEMS_INLINE_ROUTINE void _Heap_Free_list_replace(
+ Heap_Block *old_block,
+ Heap_Block *new_block
+)
+{
+ Heap_Block *next = old_block->next;
+ Heap_Block *prev = old_block->prev;
+
+ new_block->next = next;
+ new_block->prev = prev;
+
+ next->prev = new_block;
+ prev->next = new_block;
+}
+
+RTEMS_INLINE_ROUTINE void _Heap_Free_list_insert_after(
+ Heap_Block *block_before,
+ Heap_Block *new_block
+)
+{
+ Heap_Block *next = block_before->next;
+
+ new_block->next = next;
+ new_block->prev = block_before;
+ block_before->next = new_block;
+ next->prev = new_block;
+}
+
+RTEMS_INLINE_ROUTINE bool _Heap_Is_aligned(
+ uintptr_t value,
+ uintptr_t alignment
+)
+{
+ return (value % alignment) == 0;
+}
+
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_up(
+ uintptr_t value,
+ uintptr_t alignment
+)
+{
+ uintptr_t remainder = value % alignment;
+
+ if ( remainder != 0 ) {
+ return value - remainder + alignment;
+ } else {
+ return value;
+ }
+}
+
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_down(
+ uintptr_t value,
+ uintptr_t alignment
+)
+{
+ return value - (value % alignment);
+}
+
+/**
+ * @brief Returns the block which is @a offset away from @a block.
+ */
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_at(
+ const Heap_Block *block,
+ uintptr_t offset
+)
+{
+ return (Heap_Block *) ((uintptr_t) block + offset);
+}
+
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Prev_block(
+ const Heap_Block *block
+)
+{
+ return (Heap_Block *) ((uintptr_t) block - block->prev_size);
+}
+
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Alloc_area_of_block(
+ const Heap_Block *block
+)
+{
+ return (uintptr_t) block + HEAP_BLOCK_HEADER_SIZE;
+}
+
+RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_of_alloc_area(
+ uintptr_t alloc_begin,
+ uintptr_t page_size
+)
+{
+ return (Heap_Block *) (_Heap_Align_down( alloc_begin, page_size )
+ - HEAP_BLOCK_HEADER_SIZE);
+}
+
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size( const Heap_Block *block )
+{
+ return block->size_and_flag & ~HEAP_PREV_BLOCK_USED;
+}
+
+RTEMS_INLINE_ROUTINE void _Heap_Block_set_size(
+ Heap_Block *block,
+ uintptr_t size
+)
+{
+ uintptr_t flag = block->size_and_flag & HEAP_PREV_BLOCK_USED;
+
+ block->size_and_flag = size | flag;
+}
+
+RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used( const Heap_Block *block )
+{
+ return block->size_and_flag & HEAP_PREV_BLOCK_USED;
+}
+
+RTEMS_INLINE_ROUTINE bool _Heap_Is_used(
+ const Heap_Block *block
+)
+{
+ const Heap_Block *const next_block =
+ _Heap_Block_at( block, _Heap_Block_size( block ) );
+
+ return _Heap_Is_prev_used( next_block );
+}
+
+RTEMS_INLINE_ROUTINE bool _Heap_Is_free(
+ const Heap_Block *block
+)
+{
+ return !_Heap_Is_used( block );
+}
+
+RTEMS_INLINE_ROUTINE bool _Heap_Is_block_in_heap(
+ const Heap_Control *heap,
+ const Heap_Block *block
+)
+{
+ return (uintptr_t) block >= (uintptr_t) heap->first_block
+ && (uintptr_t) block <= (uintptr_t) heap->last_block;
+}
+
+/**
+ * @brief Sets the size of the last block for heap @a heap.
+ *
+ * The next block of the last block will be the first block. Since the first
+ * block indicates that the previous block is used, this ensures that the last
+ * block appears as used for the _Heap_Is_used() and _Heap_Is_free() functions.
+ *
+ * This feature will be used to terminate the scattered heap area list. See
+ * also _Heap_Extend().
+ */
+RTEMS_INLINE_ROUTINE void _Heap_Set_last_block_size( Heap_Control *heap )
+{
+ _Heap_Block_set_size(
+ heap->last_block,
+ (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
+ );
+}
+
+/**
+ * @brief Returns the size of the allocatable area in bytes.
+ *
+ * This value is an integral multiple of the page size.
+ */
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size( const Heap_Control *heap )
+{
+ return heap->stats.size;
+}
+
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Max( uintptr_t a, uintptr_t b )
+{
+ return a > b ? a : b;
+}
+
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min( uintptr_t a, uintptr_t b )
+{
+ return a < b ? a : b;
+}
+
+/** @} */
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/isr.inl b/cpukit/score/inline/rtems/score/isr.inl
new file mode 100644
index 0000000000..605dfeeab5
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/isr.inl
@@ -0,0 +1,58 @@
+/**
+ * @file rtems/score/isr.inl
+ *
+ * This include file contains the static implementation of all
+ * inlined routines in the Interrupt Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_ISR_H
+# error "Never use <rtems/score/isr.inl> directly; include <rtems/score/isr.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_ISR_INL
+#define _RTEMS_SCORE_ISR_INL
+
+/**
+ * @addtogroup ScoreISR
+ * @{
+ */
+
+/**
+ * This function returns true if the vector is a valid vector number
+ * for this processor and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _ISR_Is_vector_number_valid (
+ uint32_t vector
+)
+{
+ return ( vector <= CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER );
+}
+
+/**
+ * This function returns true if handler is the entry point of a valid
+ * use interrupt service routine and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _ISR_Is_valid_user_handler (
+ void *handler
+)
+{
+ return (handler != NULL);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/mppkt.inl b/cpukit/score/inline/rtems/score/mppkt.inl
new file mode 100644
index 0000000000..593e8eebb1
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/mppkt.inl
@@ -0,0 +1,61 @@
+/**
+ * @file rtems/score/mppkt.inl
+ *
+ * This package is the implementation of the Packet Handler
+ * routines which are inlined.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_MPPKT_H
+# error "Never use <rtems/score/mppkt.inl> directly; include <rtems/score/mppkt.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_MPPKT_INL
+#define _RTEMS_SCORE_MPPKT_INL
+
+/**
+ * @addtogroup ScoreMPPacket
+ * @{
+ */
+
+/**
+ * This function returns true if the the_packet_class is valid,
+ * and false otherwise.
+ *
+ * @note Check for lower bounds (MP_PACKET_CLASSES_FIRST ) is unnecessary
+ * because this enum starts at lower bound of zero.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Mp_packet_Is_valid_packet_class (
+ MP_packet_Classes the_packet_class
+)
+{
+ return ( the_packet_class <= MP_PACKET_CLASSES_LAST );
+}
+
+/**
+ * This function returns true if the the_packet_class is null,
+ * and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Mp_packet_Is_null (
+ MP_packet_Prefix *the_packet
+)
+{
+ return the_packet == NULL;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/object.inl b/cpukit/score/inline/rtems/score/object.inl
new file mode 100644
index 0000000000..d4d39acac6
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/object.inl
@@ -0,0 +1,357 @@
+/**
+ * @file rtems/score/object.inl
+ */
+
+/*
+ *
+ * This include file contains the static inline implementation of all
+ * of the inlined routines in the Object Handler.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_OBJECT_H
+# error "Never use <rtems/score/object.inl> directly; include <rtems/score/object.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_OBJECT_INL
+#define _RTEMS_SCORE_OBJECT_INL
+
+/**
+ * This function builds an object's id from the processor node and index
+ * values specified.
+ *
+ * @param[in] the_api indicates the API associated with this Id.
+ * @param[in] the_class indicates the class of object.
+ * It is specific to @a the_api.
+ * @param[in] node is the node where this object resides.
+ * @param[in] index is the instance number of this object.
+ *
+ * @return This method returns an object Id constructed from the arguments.
+ */
+RTEMS_INLINE_ROUTINE Objects_Id _Objects_Build_id(
+ Objects_APIs the_api,
+ uint32_t the_class,
+ uint32_t node,
+ uint32_t index
+)
+{
+ return (( (Objects_Id) the_api ) << OBJECTS_API_START_BIT) |
+ (( (Objects_Id) the_class ) << OBJECTS_CLASS_START_BIT) |
+ #if !defined(RTEMS_USE_16_BIT_OBJECT)
+ (( (Objects_Id) node ) << OBJECTS_NODE_START_BIT) |
+ #endif
+ (( (Objects_Id) index ) << OBJECTS_INDEX_START_BIT);
+}
+
+/**
+ * This function returns the API portion of the ID.
+ *
+ * @param[in] id is the object Id to be processed.
+ *
+ * @return This method returns an object Id constructed from the arguments.
+ */
+RTEMS_INLINE_ROUTINE Objects_APIs _Objects_Get_API(
+ Objects_Id id
+)
+{
+ return (Objects_APIs) ((id >> OBJECTS_API_START_BIT) & OBJECTS_API_VALID_BITS);
+}
+
+/**
+ * This function returns the class portion of the ID.
+ *
+ * @param[in] id is the object Id to be processed
+ */
+RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_class(
+ Objects_Id id
+)
+{
+ return (uint32_t)
+ ((id >> OBJECTS_CLASS_START_BIT) & OBJECTS_CLASS_VALID_BITS);
+}
+
+/**
+ * This function returns the node portion of the ID.
+ *
+ * @param[in] id is the object Id to be processed
+ *
+ * @return This method returns the node portion of an object ID.
+ */
+RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_node(
+ Objects_Id id
+)
+{
+ /*
+ * If using 16-bit Ids, then there is no node field and it MUST
+ * be a single processor system.
+ */
+ #if defined(RTEMS_USE_16_BIT_OBJECT)
+ return 1;
+ #else
+ return (id >> OBJECTS_NODE_START_BIT) & OBJECTS_NODE_VALID_BITS;
+ #endif
+}
+
+/**
+ * This function returns the index portion of the ID.
+ *
+ * @param[in] id is the Id to be processed
+ *
+ * @return This method returns the class portion of the specified object ID.
+ */
+RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Get_index(
+ Objects_Id id
+)
+{
+ return
+ (Objects_Maximum)((id >> OBJECTS_INDEX_START_BIT) &
+ OBJECTS_INDEX_VALID_BITS);
+}
+
+/**
+ * This function returns true if the api is valid.
+ *
+ * @param[in] the_api is the api portion of an object ID.
+ *
+ * @return This method returns true if the specified api value is valid
+ * and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Objects_Is_api_valid(
+ uint32_t the_api
+)
+{
+ if ( !the_api || the_api > OBJECTS_APIS_LAST )
+ return false;
+ return true;
+}
+
+/**
+ * This function returns true if the node is of the local object, and
+ * false otherwise.
+ *
+ * @param[in] node is the node number and corresponds to the node number
+ * portion of an object ID.
+ *
+ * @return This method returns true if the specified node is the local node
+ * and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Objects_Is_local_node(
+ uint32_t node
+)
+{
+ return ( node == _Objects_Local_node );
+}
+
+/**
+ * This function returns true if the id is of a local object, and
+ * false otherwise.
+ *
+ * @param[in] id is an object ID
+ *
+ * @return This method returns true if the specified object Id is local
+ * and false otherwise.
+ *
+ * @note On a single processor configuration, this always returns true.
+ */
+RTEMS_INLINE_ROUTINE bool _Objects_Is_local_id(
+#if defined(RTEMS_MULTIPROCESSING)
+ Objects_Id id
+#else
+ Objects_Id id __attribute__((unused))
+#endif
+)
+{
+#if defined(RTEMS_MULTIPROCESSING)
+ return _Objects_Is_local_node( _Objects_Get_node(id) );
+#else
+ return true;
+#endif
+}
+
+/**
+ * This function returns true if left and right are equal,
+ * and false otherwise.
+ *
+ * @param[in] left is the Id on the left hand side of the comparison
+ * @param[in] right is the Id on the right hand side of the comparison
+ *
+ * @return This method returns true if the specified object IDs are equal
+ * and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Objects_Are_ids_equal(
+ Objects_Id left,
+ Objects_Id right
+)
+{
+ return ( left == right );
+}
+
+/**
+ * This function returns a pointer to the local_table object
+ * referenced by the index.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] index is the index of the object the caller wants to access
+ *
+ * @return This method returns a pointer to a local object or NULL if the
+ * index is invalid and RTEMS_DEBUG is enabled.
+ */
+RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Get_local_object(
+ Objects_Information *information,
+ uint16_t index
+)
+{
+ /*
+ * This routine is ONLY to be called from places in the code
+ * where the Id is known to be good. Therefore, this should NOT
+ * occur in normal situations.
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( index > information->maximum )
+ return NULL;
+ #endif
+ return information->local_table[ index ];
+}
+
+/**
+ * This function sets the pointer to the local_table object
+ * referenced by the index.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] index is the index of the object the caller wants to access
+ * @param[in] the_object is the local object pointer
+ *
+ * @note This routine is ONLY to be called in places where the
+ * index portion of the Id is known to be good. This is
+ * OK since it is normally called from object create/init
+ * or delete/destroy operations.
+ */
+
+RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
+ Objects_Information *information,
+ uint32_t index,
+ Objects_Control *the_object
+)
+{
+ /*
+ * This routine is ONLY to be called from places in the code
+ * where the Id is known to be good. Therefore, this should NOT
+ * occur in normal situations.
+ */
+ #if defined(RTEMS_DEBUG)
+ if ( index > information->maximum )
+ return;
+ #endif
+
+ information->local_table[ index ] = the_object;
+}
+
+/**
+ * This function sets the pointer to the local_table object
+ * referenced by the index to a NULL so the object Id is invalid
+ * after this call.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] the_object is the local object pointer
+ *
+ * @note This routine is ONLY to be called in places where the
+ * index portion of the Id is known to be good. This is
+ * OK since it is normally called from object create/init
+ * or delete/destroy operations.
+ */
+
+RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ _Objects_Set_local_object(
+ information,
+ _Objects_Get_index( the_object->id ),
+ NULL
+ );
+}
+
+/**
+ * This function places the_object control pointer and object name
+ * in the Local Pointer and Local Name Tables, respectively.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] the_object is a pointer to an object
+ * @param[in] name is the name of the object to make accessible
+ */
+RTEMS_INLINE_ROUTINE void _Objects_Open(
+ Objects_Information *information,
+ Objects_Control *the_object,
+ Objects_Name name
+)
+{
+ _Objects_Set_local_object(
+ information,
+ _Objects_Get_index( the_object->id ),
+ the_object
+ );
+
+ the_object->name = name;
+}
+
+/**
+ * This function places the_object control pointer and object name
+ * in the Local Pointer and Local Name Tables, respectively.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] the_object is a pointer to an object
+ * @param[in] name is the name of the object to make accessible
+ */
+RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
+ Objects_Information *information,
+ Objects_Control *the_object,
+ uint32_t name
+)
+{
+ _Objects_Set_local_object(
+ information,
+ _Objects_Get_index( the_object->id ),
+ the_object
+ );
+
+ /* ASSERT: information->is_string == false */
+ the_object->name.name_u32 = name;
+}
+
+/**
+ * This function places the_object control pointer and object name
+ * in the Local Pointer and Local Name Tables, respectively.
+ *
+ * @param[in] information points to an Object Information Table
+ * @param[in] the_object is a pointer to an object
+ * @param[in] name is the name of the object to make accessible
+ */
+RTEMS_INLINE_ROUTINE void _Objects_Open_string(
+ Objects_Information *information,
+ Objects_Control *the_object,
+ const char *name
+)
+{
+ _Objects_Set_local_object(
+ information,
+ _Objects_Get_index( the_object->id ),
+ the_object
+ );
+
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ /* ASSERT: information->is_string */
+ the_object->name.name_p = name;
+ #endif
+}
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/objectmp.inl b/cpukit/score/inline/rtems/score/objectmp.inl
new file mode 100644
index 0000000000..53db23621a
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/objectmp.inl
@@ -0,0 +1,71 @@
+/**
+ * @file rtems/score/objectmp.inl
+ *
+ * This include file contains the bodies of all inlined routines
+ * which deal with global objects.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_OBJECTMP_H
+# error "Never use <rtems/score/objectmp.inl> directly; include <rtems/score/objectmp.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_OBJECTMP_INL
+#define _RTEMS_SCORE_OBJECTMP_INL
+
+/**
+ * @addtogroup ScoreObjectMP
+ * @{
+ */
+
+/**
+ * This function allocates a Global Object control block.
+ */
+
+RTEMS_INLINE_ROUTINE Objects_MP_Control *_Objects_MP_Allocate_global_object (
+ void
+)
+{
+ return (Objects_MP_Control *)
+ _Chain_Get( &_Objects_MP_Inactive_global_objects );
+}
+
+/**
+ * This routine deallocates a Global Object control block.
+ */
+
+RTEMS_INLINE_ROUTINE void _Objects_MP_Free_global_object (
+ Objects_MP_Control *the_object
+)
+{
+ _Chain_Append(
+ &_Objects_MP_Inactive_global_objects,
+ &the_object->Object.Node
+ );
+}
+
+/**
+ * This function returns whether the global object is NULL or not.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Objects_MP_Is_null_global_object (
+ Objects_MP_Control *the_object
+)
+{
+ return( the_object == NULL );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/priority.inl b/cpukit/score/inline/rtems/score/priority.inl
new file mode 100644
index 0000000000..089a81ebda
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/priority.inl
@@ -0,0 +1,53 @@
+/**
+ * @file rtems/score/priority.inl
+ *
+ * This file contains the static inline implementation of all inlined
+ * routines in the Priority Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_PRIORITY_H
+# error "Never use <rtems/score/priority.inl> directly; include <rtems/score/priority.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_PRIORITY_INL
+#define _RTEMS_SCORE_PRIORITY_INL
+
+/**
+ * @addtogroup ScorePriority
+ * @{
+ */
+
+/**
+ * This function returns true if the_priority if valid for a
+ * user task, and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Priority_Is_valid (
+ Priority_Control the_priority
+)
+{
+ /*
+ * Since PRIORITY_MINIMUM is 0 and priorities are stored unsigned,
+ * then checking for less than 0 is unnecessary.
+ */
+
+ return ( the_priority <= PRIORITY_MAXIMUM );
+}
+
+
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/prioritybitmap.inl b/cpukit/score/inline/rtems/score/prioritybitmap.inl
new file mode 100644
index 0000000000..7938a38afc
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/prioritybitmap.inl
@@ -0,0 +1,193 @@
+/**
+ * @file rtems/score/prioritybitmap.inl
+ *
+ * This file contains the static inline implementation of all inlined
+ * routines in the Priority Handler bit map implementation
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_PRIORITYBITMAP_H
+# error "Never use <rtems/score/prioritybitmap.inl> directly; include <rtems/score/prioritybitmap.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_PRIORITYBITMAP_INL
+#define _RTEMS_SCORE_PRIORITYBITMAP_INL
+
+/**
+ * @addtogroup ScorePriority
+ * @{
+ */
+
+#include <rtems/score/bitfield.h>
+
+/**
+ * This function returns the major portion of the_priority.
+ */
+
+RTEMS_INLINE_ROUTINE Priority_bit_map_Control _Priority_Major (
+ Priority_Control the_priority
+)
+{
+ return (Priority_bit_map_Control)( the_priority / 16 );
+}
+
+/**
+ * This function returns the minor portion of the_priority.
+ */
+
+RTEMS_INLINE_ROUTINE Priority_bit_map_Control _Priority_Minor (
+ Priority_Control the_priority
+)
+{
+ return (Priority_bit_map_Control)( the_priority % 16 );
+}
+
+#if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE )
+
+/**
+ * This function returns the mask associated with the major or minor
+ * number passed to it.
+ */
+
+RTEMS_INLINE_ROUTINE Priority_bit_map_Control _Priority_Mask (
+ uint32_t bit_number
+)
+{
+ return (Priority_bit_map_Control)(0x8000u >> bit_number);
+}
+
+/**
+ * This function returns the mask bit inverted.
+ */
+
+RTEMS_INLINE_ROUTINE Priority_bit_map_Control _Priority_Mask_invert (
+ uint32_t mask
+)
+{
+ return (Priority_bit_map_Control)(~mask);
+}
+
+
+/**
+ * This function translates the bit numbers returned by the bit scan
+ * of a priority bit field into something suitable for use as
+ * a major or minor component of a priority.
+ */
+
+RTEMS_INLINE_ROUTINE uint32_t _Priority_Bits_index (
+ uint32_t bit_number
+)
+{
+ return bit_number;
+}
+
+#endif
+
+/**
+ * Priority Queue implemented by bit map
+ */
+
+/**
+ * This routine performs the initialization necessary for this handler.
+ */
+
+RTEMS_INLINE_ROUTINE void _Priority_bit_map_Handler_initialization( void )
+{
+ int index;
+
+ _Priority_Major_bit_map = 0;
+ for ( index=0 ; index <16 ; index++ )
+ _Priority_Bit_map[ index ] = 0;
+}
+
+/**
+ * This routine uses the_priority_map to update the priority
+ * bit maps to indicate that a thread has been readied.
+ */
+
+RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add (
+ Priority_bit_map_Information *the_priority_map
+)
+{
+ *the_priority_map->minor |= the_priority_map->ready_minor;
+ _Priority_Major_bit_map |= the_priority_map->ready_major;
+}
+
+/**
+ * This routine uses the_priority_map to update the priority
+ * bit maps to indicate that a thread has been removed from the
+ * ready state.
+ */
+
+RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove (
+ Priority_bit_map_Information *the_priority_map
+)
+{
+ *the_priority_map->minor &= the_priority_map->block_minor;
+ if ( *the_priority_map->minor == 0 )
+ _Priority_Major_bit_map &= the_priority_map->block_major;
+}
+
+/**
+ * This function returns the priority of the highest priority
+ * ready thread.
+ */
+
+RTEMS_INLINE_ROUTINE Priority_Control _Priority_bit_map_Get_highest( void )
+{
+ Priority_bit_map_Control minor;
+ Priority_bit_map_Control major;
+
+ _Bitfield_Find_first_bit( _Priority_Major_bit_map, major );
+ _Bitfield_Find_first_bit( _Priority_Bit_map[major], minor );
+
+ return (_Priority_Bits_index( major ) << 4) +
+ _Priority_Bits_index( minor );
+}
+
+/**
+ * This routine initializes the_priority_map so that it
+ * contains the information necessary to manage a thread
+ * at new_priority.
+ */
+
+RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information(
+ Priority_bit_map_Information *the_priority_map,
+ Priority_Control new_priority
+)
+{
+ Priority_bit_map_Control major;
+ Priority_bit_map_Control minor;
+ Priority_bit_map_Control mask;
+
+ major = _Priority_Major( new_priority );
+ minor = _Priority_Minor( new_priority );
+
+ the_priority_map->minor =
+ &_Priority_Bit_map[ _Priority_Bits_index(major) ];
+
+ mask = _Priority_Mask( major );
+ the_priority_map->ready_major = mask;
+ /* Add _Priority_Mask_invert to non-generic bitfield then change this code. */
+ the_priority_map->block_major = (Priority_bit_map_Control)(~((uint32_t)mask));
+
+ mask = _Priority_Mask( minor );
+ the_priority_map->ready_minor = mask;
+ /* Add _Priority_Mask_invert to non-generic bitfield then change this code. */
+ the_priority_map->block_minor = (Priority_bit_map_Control)(~((uint32_t)mask));
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/scheduler.inl b/cpukit/score/inline/rtems/score/scheduler.inl
new file mode 100644
index 0000000000..4a6c74cbf8
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/scheduler.inl
@@ -0,0 +1,165 @@
+/**
+ * @file rtems/score/scheduler.inl
+ *
+ * This inline file contains all of the inlined routines associated with
+ * the manipulation of the scheduler.
+ */
+
+/*
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULER_H
+# error "Never use <rtems/score/scheduler.inl> directly; include <rtems/score/scheduler.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_SCHEDULER_INL
+#define _RTEMS_SCORE_SCHEDULER_INL
+
+/**
+ * @addtogroup ScoreScheduler
+ * @{
+ */
+
+/**
+ * The preferred method to add a new scheduler is to define the jump table
+ * entries and add a case to the _Scheduler_Initialize routine.
+ *
+ * Generic scheduling implementations that rely on the ready queue only can
+ * be found in the _Scheduler_queue_XXX functions.
+ *
+ */
+
+/* Passing the Scheduler_Control* to these functions allows for multiple
+ * scheduler's to exist simultaneously, which could be useful on an SMP
+ * system. Then remote Schedulers may be accessible. How to protect such
+ * accesses remains an open problem.
+ */
+
+/** @brief _Scheduler_Schedule
+ *
+ * This kernel routine implements the scheduling decision logic for
+ * the scheduler. It does NOT dispatch.
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Schedule( void )
+{
+ _Scheduler.Operations.schedule();
+}
+
+/** @brief _Scheduler_Yield
+ *
+ * This routine is invoked when a thread wishes to voluntarily
+ * transfer control of the processor to another thread. This routine
+ * always operates on the scheduler that 'owns' the currently executing
+ * thread.
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Yield( void )
+{
+ _Scheduler.Operations.yield();
+}
+
+/** @brief _Scheduler_Block
+ *
+ * This routine removes @a the_thread from the scheduling decision for
+ * the scheduler. The primary task is to remove the thread from the
+ * ready queue. It performs any necessary schedulering operations
+ * including the selection of a new heir thread.
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Block(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler.Operations.block( the_thread );
+}
+
+/** @brief _Scheduler_Unblock
+ *
+ * This routine adds @a the_thread to the scheduling decision for
+ * the scheduler. The primary task is to add the thread to the
+ * ready queue per the schedulering policy and update any appropriate
+ * scheduling variables, for example the heir thread.
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Unblock(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler.Operations.unblock( the_thread );
+}
+
+/** @brief _Scheduler_Allocate
+ *
+ * This routine allocates @a the_thread->scheduler
+ */
+RTEMS_INLINE_ROUTINE void* _Scheduler_Allocate(
+ Thread_Control *the_thread
+)
+{
+ return _Scheduler.Operations.allocate( the_thread );
+}
+
+/** @brief _Scheduler_Free
+ *
+ * This routine frees @a the_thread->scheduler
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Free(
+ Thread_Control *the_thread
+)
+{
+ return _Scheduler.Operations.free( the_thread );
+}
+
+/** @brief _Scheduler_Update
+ *
+ * This routine updates @a the_thread->scheduler
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Update(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler.Operations.update( the_thread );
+}
+
+/** @brief _Scheduler_Enqueue
+ *
+ * This routine enqueue @a the_thread->scheduler
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Enqueue(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler.Operations.enqueue( the_thread );
+}
+
+/** @brief _Scheduler_Enqueue_first
+ *
+ * This routine enqueue_first @a the_thread->scheduler
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler.Operations.enqueue_first( the_thread );
+}
+
+/** @brief _Scheduler_Extract
+ *
+ * This routine extract @a the_thread->scheduler
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Extract(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler.Operations.extract( the_thread );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/schedulerpriority.inl b/cpukit/score/inline/rtems/score/schedulerpriority.inl
new file mode 100644
index 0000000000..680606ce53
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/schedulerpriority.inl
@@ -0,0 +1,195 @@
+/**
+ * @file rtems/score/schedulerpriority.inl
+ *
+ * This inline file contains all of the inlined routines associated with
+ * the manipulation of the priority-based scheduling structures.
+ */
+
+/*
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULERPRIORITY_H
+# error "Never use <rtems/score/schedulerpriority.inl> directly; include <rtems/score/schedulerpriority.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_SCHEDULERPRIORITY_INL
+#define _RTEMS_SCORE_SCHEDULERPRIORITY_INL
+
+#include <rtems/score/wkspace.h>
+
+/**
+ * @addtogroup ScoreScheduler
+ * @{
+ */
+
+/** @brief Scheduler priority Ready queue initialize
+ *
+ * This routine initializes @a the_ready_queue for priority-based scheduling.
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_initialize(void)
+{
+ size_t index;
+ Chain_Control *ready_queues;
+
+ /* allocate ready queue structures */
+ _Scheduler.information = _Workspace_Allocate_or_fatal_error(
+ ((size_t) PRIORITY_MAXIMUM + 1) * sizeof(Chain_Control)
+ );
+
+ /* initialize ready queue structures */
+ ready_queues = (Chain_Control *) _Scheduler.information;
+ for( index=0; index <= PRIORITY_MAXIMUM; index++)
+ _Chain_Initialize_empty( &ready_queues[index] );
+}
+
+/**
+ * @brief _Scheduler_priority_Ready_queue_enqueue
+ *
+ * This routine puts @a the_thread on to the priority-based ready queue.
+ *
+ * @param[in] the_thread - pointer to thread
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue(
+ Thread_Control *the_thread
+)
+{
+ Scheduler_priority_Per_thread *sched_info;
+ Chain_Control *ready;
+
+ sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
+ ready = sched_info->ready_chain;
+
+ _Priority_bit_map_Add( &sched_info->Priority_map );
+
+ _Chain_Append_unprotected( ready, &the_thread->Object.Node );
+}
+
+/**
+ * @brief _Scheduler_priority_Ready_queue_Enqueue_first
+ *
+ * This routine puts @a the_thread to the head of the ready queue.
+ * For priority-based ready queues, the thread will be the first thread
+ * at its priority level.
+ *
+ * @param[in] the_thread - pointer to thread
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ Scheduler_priority_Per_thread *sched_info;
+ Chain_Control *ready;
+
+ sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
+ ready = sched_info->ready_chain;
+
+ _Priority_bit_map_Add( &sched_info->Priority_map );
+
+ _Chain_Prepend_unprotected(
+ sched_info->ready_chain,
+ &the_thread->Object.Node
+ );
+}
+
+/**
+ * @brief _Scheduler_priority_Ready_queue_extract
+ *
+ * This routine removes a specific thread from the specified
+ * priority-based ready queue.
+ *
+ * @param[in] the_thread - pointer to thread
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_extract(
+ Thread_Control *the_thread
+)
+{
+ Scheduler_priority_Per_thread *sched_info;
+ Chain_Control *ready;
+
+ sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
+ ready = sched_info->ready_chain;
+
+ if ( _Chain_Has_only_one_node( ready ) ) {
+ _Chain_Initialize_empty( ready );
+ _Priority_bit_map_Remove( &sched_info->Priority_map );
+ } else {
+ _Chain_Extract_unprotected( &the_thread->Object.Node );
+ }
+}
+
+/**
+ * @brief _Scheduler_priority_Ready_queue_first
+ *
+ * This routines returns a pointer to the first thread on @a the_ready_queue.
+ *
+ * @param[in] the_ready_queue - pointer to thread queue
+ *
+ * @return This method returns the first thread or NULL
+ */
+RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_priority_Ready_queue_first(
+ Chain_Control *the_ready_queue
+)
+{
+ Priority_Control index = _Priority_bit_map_Get_highest();
+
+ if ( !_Chain_Is_empty( &the_ready_queue[ index ] ) )
+ return (Thread_Control *) _Chain_First( &the_ready_queue[ index ] );
+
+ return NULL;
+}
+
+/**
+ * @brief _Scheduler_priority_Ready_queue_requeue
+ *
+ * This routine is invoked when a thread changes priority and should be
+ * moved to a different position on the ready queue.
+ *
+ * @param[in] the_thread - pointer to thread
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_requeue(
+ Thread_Control *the_thread
+)
+{
+ Scheduler_priority_Per_thread *sched_info;
+ Chain_Control *ready;
+
+ sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
+ ready = sched_info->ready_chain;
+
+ if ( !_Chain_Has_only_one_node( sched_info->ready_chain ) ) {
+ _Chain_Extract_unprotected( &the_thread->Object.Node );
+
+ _Chain_Append_unprotected(
+ sched_info->ready_chain,
+ &the_thread->Object.Node
+ );
+ }
+}
+
+/**
+ * @brief _Scheduler_priority_Schedule_body
+ *
+ * This kernel routine implements scheduling decision logic
+ * for priority-based scheduling.
+ *
+ * @param[in] the_thread - pointer to thread
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body(void)
+{
+ _Thread_Heir = _Scheduler_priority_Ready_queue_first(
+ (Chain_Control *) _Scheduler.information
+ );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/schedulersimple.inl b/cpukit/score/inline/rtems/score/schedulersimple.inl
new file mode 100644
index 0000000000..0996efc896
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/schedulersimple.inl
@@ -0,0 +1,53 @@
+/**
+ * @file rtems/score/schedulersimple.inl
+ *
+ * This inline file contains all of the inlined routines associated with
+ * the manipulation of the priority-based scheduling structures.
+ */
+
+/*
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SCHEDULERSIMPLE_H
+# error "Never use <rtems/score/schedulersimple.inl> directly; include <rtems/score/schedulersimple.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_SCHEDULERSIMPLE_INL
+#define _RTEMS_SCORE_SCHEDULERSIMPLE_INL
+
+#include <rtems/score/thread.h>
+
+/**
+ * @addtogroup ScoreScheduler
+ * @{
+ */
+
+/**
+ * This routine puts @a the_thread on to the ready queue.
+ *
+ * @param[in] the_ready_queue is a pointer to the ready queue head
+ * @param[in] the_thread is the thread to be blocked
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_simple_Ready_queue_Requeue(
+ Scheduler_Control *the_ready_queue,
+ Thread_Control *the_thread
+)
+{
+ /* extract */
+ _Chain_Extract_unprotected( &the_thread->Object.Node );
+
+ /* enqueue */
+ _Scheduler_simple_Ready_queue_Enqueue( the_thread );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/stack.inl b/cpukit/score/inline/rtems/score/stack.inl
new file mode 100644
index 0000000000..c5d809cb81
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/stack.inl
@@ -0,0 +1,113 @@
+/**
+ * @file rtems/score/stack.inl
+ *
+ * This file contains the static inline implementation of the inlined
+ * routines from the Stack Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_STACK_H
+# error "Never use <rtems/score/stack.inl> directly; include <rtems/score/stack.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_STACK_INL
+#define _RTEMS_SCORE_STACK_INL
+
+#include <rtems/score/basedefs.h> /* RTEMS_INLINE_ROUTINE */
+#include <rtems/score/cpu.h> /* CPU_STACK_ALIGNMENT */
+
+/**
+ * @addtogroup ScoreStack
+ * @{
+ */
+
+/**
+ * This routine initializes the_stack record to indicate that
+ * size bytes of memory starting at starting_address have been
+ * reserved for a stack.
+ */
+RTEMS_INLINE_ROUTINE void _Stack_Initialize (
+ Stack_Control *the_stack,
+ void *starting_address,
+ size_t size
+)
+{
+ the_stack->area = starting_address;
+ the_stack->size = size;
+}
+
+/**
+ * This function returns the minimum stack size configured
+ * for this application.
+ *
+ * @return This method returns the minimum stack size;
+ */
+RTEMS_INLINE_ROUTINE uint32_t _Stack_Minimum (void)
+{
+ return rtems_minimum_stack_size;
+}
+
+/**
+ * This function returns true if size bytes is enough memory for
+ * a valid stack area on this processor, and false otherwise.
+ *
+ * @param[in] size is the stack size to check
+ *
+ * @return This method returns true if the stack is large enough.
+ */
+RTEMS_INLINE_ROUTINE bool _Stack_Is_enough (
+ size_t size
+)
+{
+ return ( size >= _Stack_Minimum() );
+}
+
+/**
+ * This function returns the appropriate stack size given the requested
+ * size. If the requested size is below the minimum, then the minimum
+ * configured stack size is returned.
+ *
+ * @param[in] size is the stack size to check
+ *
+ * @return This method returns the appropriate stack size.
+ */
+RTEMS_INLINE_ROUTINE size_t _Stack_Ensure_minimum (
+ size_t size
+)
+{
+ if ( size >= _Stack_Minimum() )
+ return size;
+ return _Stack_Minimum();
+}
+
+/**
+ * This function increases the stack size to ensure that the thread
+ * has the desired amount of stack space after the initial stack
+ * pointer is determined based on alignment restrictions.
+ *
+ * @note
+ *
+ * The amount of adjustment for alignment is CPU dependent.
+ */
+
+RTEMS_INLINE_ROUTINE uint32_t _Stack_Adjust_size (
+ size_t size
+)
+{
+ return size + CPU_STACK_ALIGNMENT;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/states.inl b/cpukit/score/inline/rtems/score/states.inl
new file mode 100644
index 0000000000..5a10985e95
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/states.inl
@@ -0,0 +1,377 @@
+/**
+ * @file rtems/score/states.inl
+ *
+ * This file contains the static inline implementation of the inlined
+ * routines associated with thread state information.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_STATES_H
+# error "Never use <rtems/score/states.inl> directly; include <rtems/score/states.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_STATES_INL
+#define _RTEMS_SCORE_STATES_INL
+
+#include <rtems/score/basedefs.h> /* RTEMS_INLINE_ROUTINE */
+
+/**
+ * @addtogroup ScoreStates
+ * @{
+ */
+
+/**
+ * This function sets the given states_to_set into the current_state
+ * passed in. The result is returned to the user in current_state.
+ *
+ * @param[in] states_to_set is the state bits to set
+ * @param[in] current_state is the state set to add them to
+ *
+ * @return This method returns the updated states value.
+ */
+RTEMS_INLINE_ROUTINE States_Control _States_Set (
+ States_Control states_to_set,
+ States_Control current_state
+)
+{
+ return (current_state | states_to_set);
+}
+
+/**
+ * This function clears the given states_to_clear into the current_state
+ * passed in. The result is returned to the user in current_state.
+ *
+ * @param[in] states_to_set is the state bits to clean
+ * @param[in] current_state is the state set to remove them from
+ *
+ * @return This method returns the updated states value.
+ */
+RTEMS_INLINE_ROUTINE States_Control _States_Clear (
+ States_Control states_to_clear,
+ States_Control current_state
+)
+{
+ return (current_state & ~states_to_clear);
+}
+
+/**
+ * This function returns true if the_states indicates that the
+ * state is READY, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_ready (
+ States_Control the_states
+)
+{
+ return (the_states == STATES_READY);
+}
+
+/**
+ * This function returns true if the DORMANT state is the ONLY state
+ * set in the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_only_dormant (
+ States_Control the_states
+)
+{
+ return (the_states == STATES_DORMANT);
+}
+
+/**
+ * This function returns true if the DORMANT state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_dormant (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_DORMANT);
+}
+
+/**
+ * This function returns true if the SUSPENDED state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_suspended (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_SUSPENDED);
+}
+
+/**
+ * This function returns true if the TRANSIENT state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_transient (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_TRANSIENT);
+}
+
+/**
+ * This function returns true if the DELAYING state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_delaying (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_DELAYING);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_BUFFER state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_buffer (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_BUFFER);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_SEGMENT state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_segment (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_SEGMENT);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_MESSAGE state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_message (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_MESSAGE);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_EVENT state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_event (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_EVENT);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_MUTEX state
+ * is set in the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_mutex (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_MUTEX);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_SEMAPHORE state
+ * is set in the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_semaphore (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_SEMAPHORE);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_TIME state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_time (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_TIME);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_TIME state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_rpc_reply (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_RPC_REPLY);
+}
+
+/**
+ * This function returns true if the WAITING_FOR_PERIOD state is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_for_period (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_FOR_PERIOD);
+}
+
+/**
+ * This function returns true if the task's state is set in
+ * way that allows it to be interrupted by a signal.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_interruptible_by_signal (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_INTERRUPTIBLE_BY_SIGNAL);
+
+}
+/**
+ * This function returns true if one of the states which indicates
+ * that a task is blocked waiting for a local resource is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the desired state condition is set.
+ */
+
+RTEMS_INLINE_ROUTINE bool _States_Is_locally_blocked (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_LOCALLY_BLOCKED);
+}
+
+/**
+ * This function returns true if one of the states which indicates
+ * that a task is blocked waiting for a local resource is set in
+ * the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the state indicates that the
+ * assocated thread is waiting on a thread queue.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_waiting_on_thread_queue (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_WAITING_ON_THREAD_QUEUE);
+}
+
+/**
+ * This function returns true if one of the states which indicates
+ * that a task is blocked is set in the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ *
+ * @return This method returns true if the state indicates that the
+ * assocated thread is blocked.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Is_blocked (
+ States_Control the_states
+)
+{
+ return (the_states & STATES_BLOCKED);
+}
+
+/**
+ * This function returns true if any of the states in the mask
+ * are set in the_states, and false otherwise.
+ *
+ * @param[in] the_states is the task state set to test
+ * @param[in] mask is the state bits to test for
+ *
+ * @return This method returns true if the indicates state condition is set.
+ */
+RTEMS_INLINE_ROUTINE bool _States_Are_set (
+ States_Control the_states,
+ States_Control mask
+)
+{
+ return ( (the_states & mask) != STATES_READY);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/sysstate.inl b/cpukit/score/inline/rtems/score/sysstate.inl
new file mode 100644
index 0000000000..f391badaf3
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/sysstate.inl
@@ -0,0 +1,104 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreSysState
+ *
+ * @brief System State Handler API.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_SYSSTATE_H
+# error "Never use <rtems/score/sysstate.inl> directly; include <rtems/score/sysstate.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_SYSSTATE_INL
+#define _RTEMS_SCORE_SYSSTATE_INL
+
+/**
+ * @addtogroup ScoreSysState
+ *
+ * @{
+ */
+
+RTEMS_INLINE_ROUTINE void _System_state_Set (
+ System_state_Codes state
+)
+{
+ _System_state_Current = state;
+}
+
+RTEMS_INLINE_ROUTINE void _System_state_Handler_initialization (
+#if defined(RTEMS_MULTIPROCESSING)
+ bool is_multiprocessing
+#else
+ bool is_multiprocessing __attribute__((unused))
+#endif
+)
+{
+ _System_state_Set( SYSTEM_STATE_BEFORE_INITIALIZATION );
+#if defined(RTEMS_MULTIPROCESSING)
+ _System_state_Is_multiprocessing = is_multiprocessing;
+#endif
+}
+
+RTEMS_INLINE_ROUTINE System_state_Codes _System_state_Get ( void )
+{
+ return _System_state_Current;
+}
+
+RTEMS_INLINE_ROUTINE bool _System_state_Is_before_initialization (
+ System_state_Codes state
+)
+{
+ return (state == SYSTEM_STATE_BEFORE_INITIALIZATION);
+}
+
+RTEMS_INLINE_ROUTINE bool _System_state_Is_before_multitasking (
+ System_state_Codes state
+)
+{
+ return (state == SYSTEM_STATE_BEFORE_MULTITASKING);
+}
+
+RTEMS_INLINE_ROUTINE bool _System_state_Is_begin_multitasking (
+ System_state_Codes state
+)
+{
+ return (state == SYSTEM_STATE_BEGIN_MULTITASKING);
+}
+
+RTEMS_INLINE_ROUTINE bool _System_state_Is_shutdown (
+ System_state_Codes state
+)
+{
+ return (state == SYSTEM_STATE_SHUTDOWN);
+}
+
+RTEMS_INLINE_ROUTINE bool _System_state_Is_up (
+ System_state_Codes state
+)
+{
+ return (state == SYSTEM_STATE_UP);
+}
+
+RTEMS_INLINE_ROUTINE bool _System_state_Is_failed (
+ System_state_Codes state
+)
+{
+ return (state == SYSTEM_STATE_FAILED);
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/thread.inl b/cpukit/score/inline/rtems/score/thread.inl
new file mode 100644
index 0000000000..e700bdfb53
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/thread.inl
@@ -0,0 +1,353 @@
+/**
+ * @file rtems/score/thread.inl
+ *
+ * This file contains the macro implementation of the inlined
+ * routines from the Thread handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREAD_H
+# error "Never use <rtems/score/thread.inl> directly; include <rtems/score/thread.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_THREAD_INL
+#define _RTEMS_SCORE_THREAD_INL
+
+#include <rtems/score/sysstate.h>
+#include <rtems/score/context.h>
+
+/**
+ * @addtogroup ScoreThread
+ * @{
+ */
+
+/**
+ * This routine halts multitasking and returns control to
+ * the "thread" (i.e. the BSP) which initially invoked the
+ * routine which initialized the system.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void )
+{
+ /*
+ * This may look a bit of an odd but _Context_Restart_self is just
+ * a very careful restore of a specific context which ensures that
+ * if we were running within the same context, it would work.
+ *
+ * And we will not return to this thread, so there is no point of
+ * saving the context.
+ */
+ _Context_Restart_self( &_Thread_BSP_context );
+
+ /***************************************************************
+ ***************************************************************
+ * SYSTEM SHUTS DOWN!!! WE DO NOT RETURN TO THIS POINT!!! *
+ ***************************************************************
+ ***************************************************************
+ */
+}
+
+/**
+ * This function returns true if the_thread is the currently executing
+ * thread, and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
+ const Thread_Control *the_thread
+)
+{
+ return ( the_thread == _Thread_Executing );
+}
+
+/**
+ * This function returns true if the_thread is the heir
+ * thread, and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_Is_heir (
+ const Thread_Control *the_thread
+)
+{
+ return ( the_thread == _Thread_Heir );
+}
+
+/**
+ * This function returns true if the currently executing thread
+ * is also the heir thread, and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_also_the_heir( void )
+{
+ return ( _Thread_Executing == _Thread_Heir );
+}
+
+/**
+ * This routine clears any blocking state for the_thread. It performs
+ * any necessary scheduling operations including the selection of
+ * a new heir thread.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Unblock (
+ Thread_Control *the_thread
+)
+{
+ _Thread_Clear_state( the_thread, STATES_BLOCKED );
+}
+
+/**
+ * This routine resets the current context of the calling thread
+ * to that of its initial state.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void )
+{
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ if ( _Thread_Executing->fp_context != NULL )
+ _Context_Restore_fp( &_Thread_Executing->fp_context );
+#endif
+
+ _CPU_Context_Restart_self( &_Thread_Executing->Registers );
+}
+
+/**
+ * This function returns true if the floating point context of
+ * the_thread is currently loaded in the floating point unit, and
+ * false otherwise.
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp (
+ const Thread_Control *the_thread
+)
+{
+ return ( the_thread == _Thread_Allocated_fp );
+}
+#endif
+
+/**
+ * This routine is invoked when the currently loaded floating
+ * point context is now longer associated with an active thread.
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
+{
+ _Thread_Allocated_fp = NULL;
+}
+#endif
+
+/**
+ * This routine prevents dispatching.
+ */
+
+#if defined(RTEMS_HEAVY_STACK_DEBUG) || defined(RTEMS_HEAVY_MALLOC_DEBUG)
+ #include <rtems/bspIo.h>
+ #include <rtems/fatal.h>
+ #include <rtems/stackchk.h>
+ #include <rtems/score/sysstate.h>
+ #include <rtems/score/heap.h>
+
+ /*
+ * This is currently not defined in any .h file, so we have to
+ * extern it here.
+ */
+ extern Heap_Control *RTEMS_Malloc_Heap;
+#endif
+
+RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
+{
+ /*
+ * This check is very brutal to system performance but is very helpful
+ * at finding blown stack problems. If you have a stack problem and
+ * need help finding it, then uncomment this code. Every system
+ * call will check the stack and since mutexes are used frequently
+ * in most systems, you might get lucky.
+ */
+ #if defined(RTEMS_HEAVY_STACK_DEBUG)
+ if (_System_state_Is_up(_System_state_Get()) && (_ISR_Nest_level == 0)) {
+ if ( rtems_stack_checker_is_blown() ) {
+ printk( "Stack blown!!\n" );
+ rtems_fatal_error_occurred( 99 );
+ }
+ }
+ #endif
+
+ _Thread_Dispatch_disable_level += 1;
+ RTEMS_COMPILER_MEMORY_BARRIER();
+
+ /*
+ * This check is even more brutal than the other one. This enables
+ * malloc heap integrity checking upon entry to every system call.
+ */
+ #if defined(RTEMS_HEAVY_MALLOC_DEBUG)
+ if ( _Thread_Dispatch_disable_level == 1 ) {
+ _Heap_Walk( RTEMS_Malloc_Heap,99, false );
+ }
+ #endif
+}
+
+/**
+ * This routine allows dispatching to occur again. If this is
+ * the outer most dispatching critical section, then a dispatching
+ * operation will be performed and, if necessary, control of the
+ * processor will be transferred to the heir thread.
+ */
+
+#if ( (defined(CPU_INLINE_ENABLE_DISPATCH) && \
+ (CPU_INLINE_ENABLE_DISPATCH == FALSE)) || \
+ (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1) )
+void _Thread_Enable_dispatch( void );
+#else
+/* inlining of enable dispatching must be true */
+RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch( void )
+{
+ RTEMS_COMPILER_MEMORY_BARRIER();
+ if ( (--_Thread_Dispatch_disable_level) == 0 )
+ _Thread_Dispatch();
+}
+#endif
+
+
+/**
+ * This routine allows dispatching to occur again. However,
+ * no dispatching operation is performed even if this is the outer
+ * most dispatching critical section.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
+{
+ RTEMS_COMPILER_MEMORY_BARRIER();
+ _Thread_Dispatch_disable_level -= 1;
+}
+
+/**
+ * This function returns true if dispatching is disabled, and false
+ * otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_Is_dispatching_enabled( void )
+{
+ return ( _Thread_Dispatch_disable_level == 0 );
+}
+
+/**
+ * This function returns true if dispatching is disabled, and false
+ * otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary( void )
+{
+ return ( _Thread_Dispatch_necessary );
+}
+
+/**
+ * This routine initializes the thread dispatching subsystem.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
+{
+ _Thread_Dispatch_disable_level = 1;
+}
+
+/**
+ * This function returns true if the_thread is NULL and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_Is_null (
+ const Thread_Control *the_thread
+)
+{
+ return ( the_thread == NULL );
+}
+
+/** @brief _Thread_Is_proxy_blocking
+ *
+ * status which indicates that a proxy is blocking, and false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking (
+ uint32_t code
+)
+{
+ return (code == THREAD_STATUS_PROXY_BLOCKING);
+}
+
+/**
+ * This routine allocates an internal thread.
+ */
+
+RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
+{
+ return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
+}
+
+/**
+ * This routine frees an internal thread.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
+ Thread_Control *the_task
+)
+{
+ _Objects_Free( &_Thread_Internal_information, &the_task->Object );
+}
+
+/**
+ * This routine returns the C library re-enterant pointer.
+ */
+
+RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void )
+{
+ return _Thread_libc_reent;
+}
+
+/**
+ * This routine set the C library re-enterant pointer.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
+ struct _reent **libc_reent
+)
+{
+ _Thread_libc_reent = libc_reent;
+}
+
+/**
+ * This routine evaluates the current scheduling information for the
+ * system and determines if a context switch is required. This
+ * is usually called after changing an execution mode such as preemptability
+ * for a thread.
+ *
+ * @param[in] are_signals_pending specifies whether or not the API
+ * level signals are pending and a dispatch is needed.
+ */
+RTEMS_INLINE_ROUTINE bool _Thread_Evaluate_is_dispatch_needed(
+ bool are_signals_pending
+)
+{
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+
+ if ( are_signals_pending ||
+ (!_Thread_Is_heir( executing ) && executing->is_preemptible) ) {
+ _Thread_Dispatch_necessary = true;
+ return true;
+ }
+
+ return false;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/threadmp.inl b/cpukit/score/inline/rtems/score/threadmp.inl
new file mode 100644
index 0000000000..648ed0e1d2
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/threadmp.inl
@@ -0,0 +1,64 @@
+/**
+ * @file rtems/score/threadmp.inl
+ *
+ * This include file contains the bodies of all inlined routines
+ * for the multiprocessing part of thread package.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREADMP_H
+# error "Never use <rtems/score/threadmp.inl> directly; include <rtems/score/threadmp.h> instead."
+#endif
+
+#include <rtems/score/mpci.h>
+
+#ifndef _RTEMS_SCORE_THREADMP_INL
+#define _RTEMS_SCORE_THREADMP_INL
+
+/**
+ * @addtogroup ScoreThreadMP
+ * @{
+ */
+
+/**
+ * This function returns true if the thread in question is the
+ * multiprocessing receive thread.
+ *
+ * @note This is a macro to avoid needing a prototype for
+ * _MPCI_Receive_server_tcb until it is used.
+ */
+#define _Thread_MP_Is_receive(_the_thread) \
+ (_the_thread == _MPCI_Receive_server_tcb)
+
+/**
+ * This routine frees a proxy control block to the
+ * inactive chain of free proxy control blocks.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_MP_Free_proxy (
+ Thread_Control *the_thread
+)
+{
+ Thread_Proxy_control *the_proxy;
+
+ the_proxy = (Thread_Proxy_control *) the_thread;
+
+ _Chain_Extract( &the_proxy->Active );
+
+ _Chain_Append( &_Thread_MP_Inactive_proxies, &the_thread->Object.Node );
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/threadq.inl b/cpukit/score/inline/rtems/score/threadq.inl
new file mode 100644
index 0000000000..b8bc99bf20
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/threadq.inl
@@ -0,0 +1,36 @@
+/**
+ * @file rtems/score/threadq.inl
+ *
+ * This inline file contains all of the inlined routines associated with
+ * the manipulation of thread queues.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_THREADQ_H
+# error "Never use <rtems/score/threadq.inl> directly; include <rtems/score/threadq.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_THREADQ_INL
+#define _RTEMS_SCORE_THREADQ_INL
+
+#include <rtems/score/thread.h>
+
+/**
+ * @addtogroup ScoreThreadQ
+ * @{
+ */
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/tod.inl b/cpukit/score/inline/rtems/score/tod.inl
new file mode 100644
index 0000000000..67a37862e9
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/tod.inl
@@ -0,0 +1,79 @@
+/**
+ * @file rtems/score/tod.inl
+ *
+ * This file contains the static inline implementation of the inlined routines
+ * from the Time of Day Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TOD_H
+# error "Never use <rtems/score/tod.inl> directly; include <rtems/score/tod.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_TOD_INL
+#define _RTEMS_SCORE_TOD_INL
+
+#include <sys/time.h> /* struct timeval */
+
+#include <rtems/score/isr.h>
+
+/**
+ * @addtogroup ScoreTOD
+ * @{
+ */
+
+/**
+ * This routine deactivates updating of the current time of day.
+ */
+
+RTEMS_INLINE_ROUTINE void _TOD_Deactivate( void )
+{
+ /* XXX do we need something now that we are using timespec for TOD */
+}
+
+/**
+ * This routine activates updating of the current time of day.
+ */
+
+RTEMS_INLINE_ROUTINE void _TOD_Activate( void )
+{
+ /* XXX do we need something now that we are using timespec for TOD */
+}
+
+/**
+ * This routine returns a timeval based upon the internal timespec format TOD.
+ */
+
+RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
+ struct timeval *time
+)
+{
+ ISR_Level level;
+ struct timespec now;
+ suseconds_t useconds;
+
+ _ISR_Disable(level);
+ _TOD_Get( &now );
+ _ISR_Enable(level);
+
+ useconds = (suseconds_t)now.tv_nsec;
+ useconds /= (suseconds_t)TOD_NANOSECONDS_PER_MICROSECOND;
+
+ time->tv_sec = now.tv_sec;
+ time->tv_usec = useconds;
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/tqdata.inl b/cpukit/score/inline/rtems/score/tqdata.inl
new file mode 100644
index 0000000000..6db7ce2f5a
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/tqdata.inl
@@ -0,0 +1,73 @@
+/**
+ * @file rtems/score/tqdata.inl
+ *
+ * This file contains the static inline implementation of the inlined
+ * routines needed to support the Thread Queue Data.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TQDATA_H
+# error "Never use <rtems/score/tqdata.inl> directly; include <rtems/score/tqdata.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_TQDATA_INL
+#define _RTEMS_SCORE_TQDATA_INL
+
+/**
+ * @addtogroup ScoreThreadQ
+ * @{
+ */
+
+/**
+ * This function returns the index of the priority chain on which
+ * a thread of the_priority should be placed.
+ */
+
+RTEMS_INLINE_ROUTINE uint32_t _Thread_queue_Header_number (
+ Priority_Control the_priority
+)
+{
+ return (the_priority / TASK_QUEUE_DATA_PRIORITIES_PER_HEADER);
+}
+
+/**
+ * This function returns true if the_priority indicates that the
+ * enqueue search should start at the front of this priority
+ * group chain, and false if the search should start at the rear.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Thread_queue_Is_reverse_search (
+ Priority_Control the_priority
+)
+{
+ return ( the_priority & TASK_QUEUE_DATA_REVERSE_SEARCH_MASK );
+}
+
+/**
+ * This routine is invoked to indicate that the specified thread queue is
+ * entering a critical section.
+ */
+
+RTEMS_INLINE_ROUTINE void _Thread_queue_Enter_critical_section (
+ Thread_queue_Control *the_thread_queue
+)
+{
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
+}
+
+/**
+ * @}
+ */
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/watchdog.inl b/cpukit/score/inline/rtems/score/watchdog.inl
new file mode 100644
index 0000000000..14f7759f79
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/watchdog.inl
@@ -0,0 +1,262 @@
+/**
+ * @file rtems/score/watchdog.inl
+ *
+ * This file contains the static inline implementation of all inlined
+ * routines in the Watchdog Handler.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_WATCHDOG_H
+# error "Never use <rtems/score/watchdog.inl> directly; include <rtems/score/watchdog.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_WATCHDOG_INL
+#define _RTEMS_SCORE_WATCHDOG_INL
+
+/**
+ * @addtogroup ScoreWatchdog
+ * @{
+ */
+
+/**
+ * This routine initializes the specified watchdog. The watchdog is
+ * made inactive, the watchdog id and handler routine are set to the
+ * specified values.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Initialize(
+ Watchdog_Control *the_watchdog,
+ Watchdog_Service_routine_entry routine,
+ Objects_Id id,
+ void *user_data
+)
+{
+ the_watchdog->state = WATCHDOG_INACTIVE;
+ the_watchdog->routine = routine;
+ the_watchdog->id = id;
+ the_watchdog->user_data = user_data;
+}
+
+/**
+ * This routine returns true if the watchdog timer is in the ACTIVE
+ * state, and false otherwise.
+ */
+
+RTEMS_INLINE_ROUTINE bool _Watchdog_Is_active(
+ Watchdog_Control *the_watchdog
+)
+{
+
+ return ( the_watchdog->state == WATCHDOG_ACTIVE );
+
+}
+
+/**
+ * This routine activates THE_WATCHDOG timer which is already
+ * on a watchdog chain.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Activate(
+ Watchdog_Control *the_watchdog
+)
+{
+
+ the_watchdog->state = WATCHDOG_ACTIVE;
+
+}
+
+/**
+ * This routine deactivates THE_WATCHDOG timer which will remain
+ * on a watchdog chain.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Deactivate(
+ Watchdog_Control *the_watchdog
+)
+{
+
+ the_watchdog->state = WATCHDOG_REMOVE_IT;
+
+}
+
+/**
+ * This routine is invoked at each clock tick to update the ticks
+ * watchdog chain.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_ticks( void )
+{
+
+ _Watchdog_Tickle( &_Watchdog_Ticks_chain );
+
+}
+
+/**
+ * This routine is invoked at each clock tick to update the seconds
+ * watchdog chain.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_seconds( void )
+{
+
+ _Watchdog_Tickle( &_Watchdog_Seconds_chain );
+
+}
+
+/**
+ * This routine inserts THE_WATCHDOG into the ticks watchdog chain
+ * for a time of UNITS ticks. The INSERT_MODE indicates whether
+ * THE_WATCHDOG is to be activated automatically or later, explicitly
+ * by the caller.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Insert_ticks(
+ Watchdog_Control *the_watchdog,
+ Watchdog_Interval units
+)
+{
+
+ the_watchdog->initial = units;
+
+ _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog );
+
+}
+
+/**
+ * This routine inserts THE_WATCHDOG into the seconds watchdog chain
+ * for a time of UNITS seconds. The INSERT_MODE indicates whether
+ * THE_WATCHDOG is to be activated automatically or later, explicitly
+ * by the caller.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Insert_seconds(
+ Watchdog_Control *the_watchdog,
+ Watchdog_Interval units
+)
+{
+
+ the_watchdog->initial = units;
+
+ _Watchdog_Insert( &_Watchdog_Seconds_chain, the_watchdog );
+
+}
+
+/**
+ * This routine adjusts the seconds watchdog chain in the forward
+ * or backward DIRECTION for UNITS seconds. This is invoked when the
+ * current time of day is changed.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_seconds(
+ Watchdog_Adjust_directions direction,
+ Watchdog_Interval units
+)
+{
+
+ _Watchdog_Adjust( &_Watchdog_Seconds_chain, direction, units );
+
+}
+
+/**
+ * This routine adjusts the ticks watchdog chain in the forward
+ * or backward DIRECTION for UNITS ticks.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_ticks(
+ Watchdog_Adjust_directions direction,
+ Watchdog_Interval units
+)
+{
+
+ _Watchdog_Adjust( &_Watchdog_Ticks_chain, direction, units );
+
+}
+
+/**
+ * This routine resets THE_WATCHDOG timer to its state at INSERT
+ * time. This routine is valid only on interval watchdog timers
+ * and is used to make an interval watchdog timer fire "every" so
+ * many ticks.
+ */
+
+RTEMS_INLINE_ROUTINE void _Watchdog_Reset(
+ Watchdog_Control *the_watchdog
+)
+{
+
+ (void) _Watchdog_Remove( the_watchdog );
+
+ _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog );
+
+}
+
+/**
+ * This routine returns a pointer to the watchdog timer following
+ * THE_WATCHDOG on the watchdog chain.
+ */
+
+RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Next(
+ Watchdog_Control *the_watchdog
+)
+{
+
+ return ( (Watchdog_Control *) the_watchdog->Node.next );
+
+}
+
+/**
+ * This routine returns a pointer to the watchdog timer preceding
+ * THE_WATCHDOG on the watchdog chain.
+ */
+
+RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Previous(
+ Watchdog_Control *the_watchdog
+)
+{
+
+ return ( (Watchdog_Control *) the_watchdog->Node.previous );
+
+}
+
+/**
+ * This routine returns a pointer to the first watchdog timer
+ * on the watchdog chain HEADER.
+ */
+
+RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_First(
+ Chain_Control *header
+)
+{
+
+ return ( (Watchdog_Control *) _Chain_First( header ) );
+
+}
+
+/**
+ * This routine returns a pointer to the last watchdog timer
+ * on the watchdog chain HEADER.
+ */
+
+RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Last(
+ Chain_Control *header
+)
+{
+
+ return ( (Watchdog_Control *) _Chain_Last( header ) );
+
+}
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/inline/rtems/score/wkspace.inl b/cpukit/score/inline/rtems/score/wkspace.inl
new file mode 100644
index 0000000000..4342f2d20f
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/wkspace.inl
@@ -0,0 +1,34 @@
+/**
+ * @file rtems/score/wkspace.inl
+ *
+ * This include file contains the bodies of the routines which contains
+ * information related to the RAM Workspace.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_WKSPACE_H
+# error "Never use <rtems/score/wkspace.inl> directly; include <rtems/score/wkspace.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_WKSPACE_INL
+#define _RTEMS_SCORE_WKSPACE_INL
+
+/**
+ * @addtogroup ScoreWorkspace
+ * @{
+ */
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am
new file mode 100644
index 0000000000..6979313a19
--- /dev/null
+++ b/cpukit/score/preinstall.am
@@ -0,0 +1,337 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES += $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/debug.h: include/rtems/debug.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/debug.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/debug.h
+
+$(PROJECT_INCLUDE)/rtems/system.h: include/rtems/system.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/system.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/system.h
+
+$(PROJECT_INCLUDE)/rtems/seterr.h: include/rtems/seterr.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/seterr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/seterr.h
+
+$(PROJECT_INCLUDE)/rtems/bspsmp.h: include/rtems/bspsmp.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bspsmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bspsmp.h
+
+$(PROJECT_INCLUDE)/rtems/score/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/score
+ @: > $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/score/address.h: include/rtems/score/address.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/address.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/address.h
+
+$(PROJECT_INCLUDE)/rtems/score/apiext.h: include/rtems/score/apiext.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/apiext.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/apiext.h
+
+$(PROJECT_INCLUDE)/rtems/score/apimutex.h: include/rtems/score/apimutex.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/apimutex.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/apimutex.h
+
+$(PROJECT_INCLUDE)/rtems/score/bitfield.h: include/rtems/score/bitfield.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/bitfield.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/bitfield.h
+
+$(PROJECT_INCLUDE)/rtems/score/chain.h: include/rtems/score/chain.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/chain.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/chain.h
+
+$(PROJECT_INCLUDE)/rtems/score/context.h: include/rtems/score/context.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/context.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/context.h
+
+$(PROJECT_INCLUDE)/rtems/score/copyrt.h: include/rtems/score/copyrt.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/copyrt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/copyrt.h
+
+$(PROJECT_INCLUDE)/rtems/score/corebarrier.h: include/rtems/score/corebarrier.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corebarrier.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corebarrier.h
+
+$(PROJECT_INCLUDE)/rtems/score/coremsg.h: include/rtems/score/coremsg.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremsg.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremsg.h
+
+$(PROJECT_INCLUDE)/rtems/score/coremutex.h: include/rtems/score/coremutex.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremutex.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremutex.h
+
+$(PROJECT_INCLUDE)/rtems/score/coresem.h: include/rtems/score/coresem.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coresem.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coresem.h
+
+$(PROJECT_INCLUDE)/rtems/score/heap.h: include/rtems/score/heap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heap.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.h
+
+$(PROJECT_INCLUDE)/rtems/score/protectedheap.h: include/rtems/score/protectedheap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/protectedheap.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/protectedheap.h
+
+$(PROJECT_INCLUDE)/rtems/score/interr.h: include/rtems/score/interr.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/interr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/interr.h
+
+$(PROJECT_INCLUDE)/rtems/score/isr.h: include/rtems/score/isr.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/isr.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/isr.h
+
+$(PROJECT_INCLUDE)/rtems/score/object.h: include/rtems/score/object.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/object.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/object.h
+
+$(PROJECT_INCLUDE)/rtems/score/percpu.h: include/rtems/score/percpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/percpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/percpu.h
+
+$(PROJECT_INCLUDE)/rtems/score/priority.h: include/rtems/score/priority.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/priority.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/priority.h
+
+$(PROJECT_INCLUDE)/rtems/score/prioritybitmap.h: include/rtems/score/prioritybitmap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/prioritybitmap.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/prioritybitmap.h
+
+$(PROJECT_INCLUDE)/rtems/score/scheduler.h: include/rtems/score/scheduler.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/scheduler.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/scheduler.h
+
+$(PROJECT_INCLUDE)/rtems/score/schedulerpriority.h: include/rtems/score/schedulerpriority.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.h
+
+$(PROJECT_INCLUDE)/rtems/score/schedulersimple.h: include/rtems/score/schedulersimple.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h
+
+$(PROJECT_INCLUDE)/rtems/score/stack.h: include/rtems/score/stack.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/stack.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/stack.h
+
+$(PROJECT_INCLUDE)/rtems/score/states.h: include/rtems/score/states.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/states.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/states.h
+
+$(PROJECT_INCLUDE)/rtems/score/sysstate.h: include/rtems/score/sysstate.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/sysstate.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/sysstate.h
+
+$(PROJECT_INCLUDE)/rtems/score/thread.h: include/rtems/score/thread.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/thread.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/thread.h
+
+$(PROJECT_INCLUDE)/rtems/score/threadq.h: include/rtems/score/threadq.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadq.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadq.h
+
+$(PROJECT_INCLUDE)/rtems/score/threadsync.h: include/rtems/score/threadsync.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadsync.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadsync.h
+
+$(PROJECT_INCLUDE)/rtems/score/timespec.h: include/rtems/score/timespec.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timespec.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timespec.h
+
+$(PROJECT_INCLUDE)/rtems/score/timestamp.h: include/rtems/score/timestamp.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timestamp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timestamp.h
+
+$(PROJECT_INCLUDE)/rtems/score/timestamp64.h: include/rtems/score/timestamp64.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timestamp64.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timestamp64.h
+
+$(PROJECT_INCLUDE)/rtems/score/tod.h: include/rtems/score/tod.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.h
+
+$(PROJECT_INCLUDE)/rtems/score/tqdata.h: include/rtems/score/tqdata.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tqdata.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tqdata.h
+
+$(PROJECT_INCLUDE)/rtems/score/userext.h: include/rtems/score/userext.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/userext.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/userext.h
+
+$(PROJECT_INCLUDE)/rtems/score/watchdog.h: include/rtems/score/watchdog.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/watchdog.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/watchdog.h
+
+$(PROJECT_INCLUDE)/rtems/score/wkspace.h: include/rtems/score/wkspace.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/wkspace.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/wkspace.h
+
+$(PROJECT_INCLUDE)/rtems/score/cpuopts.h: include/rtems/score/cpuopts.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpuopts.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpuopts.h
+
+$(PROJECT_INCLUDE)/rtems/score/basedefs.h: include/rtems/score/basedefs.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/basedefs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/basedefs.h
+
+$(PROJECT_INCLUDE)/rtems/score/smplock.h: include/rtems/score/smplock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/smplock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/smplock.h
+
+if HAS_PTHREADS
+$(PROJECT_INCLUDE)/rtems/score/corespinlock.h: include/rtems/score/corespinlock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corespinlock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corespinlock.h
+
+$(PROJECT_INCLUDE)/rtems/score/corerwlock.h: include/rtems/score/corerwlock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlock.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlock.h
+endif
+if HAS_MP
+$(PROJECT_INCLUDE)/rtems/score/mpci.h: include/rtems/score/mpci.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/mpci.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/mpci.h
+
+$(PROJECT_INCLUDE)/rtems/score/mppkt.h: include/rtems/score/mppkt.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/mppkt.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/mppkt.h
+
+$(PROJECT_INCLUDE)/rtems/score/objectmp.h: include/rtems/score/objectmp.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/objectmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/objectmp.h
+
+$(PROJECT_INCLUDE)/rtems/score/threadmp.h: include/rtems/score/threadmp.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadmp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadmp.h
+endif
+$(PROJECT_INCLUDE)/rtems/score/address.inl: inline/rtems/score/address.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/address.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/address.inl
+
+$(PROJECT_INCLUDE)/rtems/score/chain.inl: inline/rtems/score/chain.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/chain.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/chain.inl
+
+$(PROJECT_INCLUDE)/rtems/score/corebarrier.inl: inline/rtems/score/corebarrier.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corebarrier.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corebarrier.inl
+
+$(PROJECT_INCLUDE)/rtems/score/coremsg.inl: inline/rtems/score/coremsg.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremsg.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremsg.inl
+
+$(PROJECT_INCLUDE)/rtems/score/coremutex.inl: inline/rtems/score/coremutex.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremutex.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremutex.inl
+
+$(PROJECT_INCLUDE)/rtems/score/coresem.inl: inline/rtems/score/coresem.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coresem.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coresem.inl
+
+$(PROJECT_INCLUDE)/rtems/score/heap.inl: inline/rtems/score/heap.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heap.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.inl
+
+$(PROJECT_INCLUDE)/rtems/score/isr.inl: inline/rtems/score/isr.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/isr.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/isr.inl
+
+$(PROJECT_INCLUDE)/rtems/score/object.inl: inline/rtems/score/object.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/object.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/object.inl
+
+$(PROJECT_INCLUDE)/rtems/score/priority.inl: inline/rtems/score/priority.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/priority.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/priority.inl
+
+$(PROJECT_INCLUDE)/rtems/score/prioritybitmap.inl: inline/rtems/score/prioritybitmap.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/prioritybitmap.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/prioritybitmap.inl
+
+$(PROJECT_INCLUDE)/rtems/score/scheduler.inl: inline/rtems/score/scheduler.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/scheduler.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/scheduler.inl
+
+$(PROJECT_INCLUDE)/rtems/score/schedulerpriority.inl: inline/rtems/score/schedulerpriority.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulerpriority.inl
+
+$(PROJECT_INCLUDE)/rtems/score/schedulersimple.inl: inline/rtems/score/schedulersimple.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulersimple.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulersimple.inl
+
+$(PROJECT_INCLUDE)/rtems/score/stack.inl: inline/rtems/score/stack.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/stack.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/stack.inl
+
+$(PROJECT_INCLUDE)/rtems/score/states.inl: inline/rtems/score/states.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/states.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/states.inl
+
+$(PROJECT_INCLUDE)/rtems/score/sysstate.inl: inline/rtems/score/sysstate.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/sysstate.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/sysstate.inl
+
+$(PROJECT_INCLUDE)/rtems/score/thread.inl: inline/rtems/score/thread.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/thread.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/thread.inl
+
+$(PROJECT_INCLUDE)/rtems/score/threadq.inl: inline/rtems/score/threadq.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadq.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadq.inl
+
+$(PROJECT_INCLUDE)/rtems/score/tod.inl: inline/rtems/score/tod.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.inl
+
+$(PROJECT_INCLUDE)/rtems/score/tqdata.inl: inline/rtems/score/tqdata.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tqdata.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tqdata.inl
+
+$(PROJECT_INCLUDE)/rtems/score/watchdog.inl: inline/rtems/score/watchdog.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/watchdog.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/watchdog.inl
+
+$(PROJECT_INCLUDE)/rtems/score/wkspace.inl: inline/rtems/score/wkspace.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/wkspace.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/wkspace.inl
+
+if HAS_PTHREADS
+$(PROJECT_INCLUDE)/rtems/score/corespinlock.inl: inline/rtems/score/corespinlock.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corespinlock.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corespinlock.inl
+
+$(PROJECT_INCLUDE)/rtems/score/corerwlock.inl: inline/rtems/score/corerwlock.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlock.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlock.inl
+endif
+if HAS_MP
+$(PROJECT_INCLUDE)/rtems/score/mppkt.inl: inline/rtems/score/mppkt.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/mppkt.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/mppkt.inl
+
+$(PROJECT_INCLUDE)/rtems/score/objectmp.inl: inline/rtems/score/objectmp.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/objectmp.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/objectmp.inl
+
+$(PROJECT_INCLUDE)/rtems/score/threadmp.inl: inline/rtems/score/threadmp.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadmp.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadmp.inl
+endif
diff --git a/cpukit/score/src/Unlimited.txt b/cpukit/score/src/Unlimited.txt
new file mode 100644
index 0000000000..47309c361c
--- /dev/null
+++ b/cpukit/score/src/Unlimited.txt
@@ -0,0 +1,364 @@
+#
+# $Id$
+#
+
+This document explains how the unlimited objects support works. This was
+written by Chris Johns <ccj@acm.org> of Objective Design Systems as a
+design document. This was submitted as part of the patch which added
+this capability.
+
+Unlimited Local Node Objects
+============================
+
+1. Why ?
+
+This patch changes the way RTEMS allocates, frees, and manages the
+'Objects_Control' structure.
+
+The 'Objects_Control' structure is at the root of all objects in
+RTEMS. The RTEMS and POSIX API allows users to create tasks, message
+queues, semaphores and other resources. These are all a type of
+Object. The POSIX API allow similar operations. These also map to
+Objects.
+
+Currently the number of objects that can be created is a static value
+loaded into the Configuration table before starting the kernel. The
+application cannot exceed these limits. Various means are used to tune
+this value. During development the value is usually set large. This
+saves having to change it everytime a developer adds a new
+resource. With a large team of developers the configuration table file
+can cycle through a large number of revisions. The wasted memory is
+only recovered when memory runs short. The issue of the configuration
+table parameters become more important the less memory you have.
+
+The Configuration table requires a calculation to occur at compile
+time to set the size of the Workspace. The calculation is an
+estimate. You need to specify an overhead value for memory that can
+not be calculated. An example of memory that cannot be calculated is
+stack sizes. This issue is not directly related to allowing unlimited
+objects how-ever the need to calculate the memory usage for a system
+in this manner is prone to error.
+
+I would like to see download support added to RTEMS. The kernel
+configuration being set at boot time means a download application can
+be limited. This can defeat one of the purposes of using downloaded
+code, no need to change ROMs. In a system I worked on the cost to
+change ROMS in a complete system was high and could take a week. This
+change is the first phase of supporting downloaded applications.
+
+1.1 How do Objects work ?
+
+All applications interact with the super core (c/src/exec/score) via
+an API. The central structure used in the super core is the
+`object'. Two application interfaces exist. They are RTEMS and
+POSIX. Both map to the super core using objects.
+
+An object in RTEMS is a resource which the user (through the API)
+creates. The different types of objects are referred to as classes of
+objects. An object is referenced by an id. This is of type `rtems_id'
+and is a 32bit unsigned integer. The id is unique for each object no
+matter what class.
+
+Objects are anchored by the `_Object_Information' structure. There is
+one per type or class of object. A global table of pointers to each
+information structure for a class of objects is held in
+`Objects_Information_table'.
+
+Objects consist of 6 main structures. The `_Object_Information' is the
+root structure. It contains pointers to the `local_table',
+`name_table', `global_table', the Inactive chain, and the object
+memory. It also contains the various variables which describe the
+object. We are only concerned with the `local_table', `name_table',
+Inactive chain, and the object memory to support unlimited objects.
+
+The `local_table' holds the pointers to open objects. A `local_table
+entry which is null is free and the object will be sitting on the
+Inactive chain. The index into the table is based on part of the
+id. Given an id the you can find the index into the `local_table', and
+therefore the object. The `local_table' has the entries for the
+indexes below the minimum_id's index. The minimum_id is always set to
+1 (the change allows another value to be selected if require). The
+index of 0 is reserved and never used. This allows any actions using
+an id of zero to fail or map to a special case.
+
+The `name_table' holds the names of the objects. Each entry in this
+table is the maximum size the name of the object can be. The size of
+names is not constrained by the object code (but is by the MP object
+code, and the API and should be fixed).
+
+The `global_table' and code that uses it has not changed. I did not
+look at the this code, and I am not farmilar with it.
+
+The Inactive chain stores objects which are free or not
+allocated. This design saves searching for a free object when
+allocating therefore providing a deterministic allocation scheme. When
+the chain is empty a null is returned.
+
+The change documented below basically extends the `local_table' and
+`name_table' structures at run-time. The memory used be these table
+is not large compared to the memory for the objects, and so are never
+reduced in size once extended. The object's memory grows and shrinks
+depending of the user's usage.
+
+Currently, the user specifies the total number of objects in the
+Configuration table. The change alters the function of the values in
+the Configuration table. A flag can be masked on to the value which
+selects the extending mode. If the user does not set the flag the
+object code operates with an object ceiling. A small performance
+overhead will be incurred as the allocate and free routines are now
+not inlined and a check of the auto_extend flag is made. The remaining
+value field of the Configuration table entry is total number of
+objects that can be allocated when not in unlimited mode.
+
+If the user masks the flag on to a value on the Configuration table
+auto-exdending mode is selected for that class of object. The value
+becomes the allocation unit size. If there are no free objects the
+object's tables are extended by the allocation unit number of
+objects. The object table is shrunk when the user frees objects. The
+table must have one free allocation block, and at least half the
+allocation size of another block before the object memory of the free
+allocation block is returned to the heap. This stops threshold
+thrashing when objects around the allocation unit size and created and
+destroyed.
+
+At least one allocation block size of objects is created and never
+destroyed.
+
+The change to support unlimited objects has extended the object
+information structure.
+
+The flag, `auto_extend' controls if the object can be automatically
+extended. The user masks the flag RTEMS_UNLIMITED_FLAGS onto the
+Configuration table number to select the auto-extend mode. This is
+passed to the `_Objects_Initialize_information' function in the
+parameter maximum. The flag is tested for and the auto_extend flag
+updated to reflect the state of the flag before being stipped from the
+maximum.
+
+The `allocation_size' is set to the parameter maxium in the function
+`_Objects_Initialize_information' if `auto_extend' is true. Making the
+allocation size small causes the memory to be allocated and freed more
+often. This only effects the performance times for creating a resource
+such as a task. It does how-ever give you fine grain memory
+control. If the performance of creating resources is not a problem
+make the size small.
+
+The size of the object is required to be stored. It is used when
+extending the object information.
+
+A count of the object on the Inactive list is maintained. This is used
+during freeing objects. If the count is above 1.5 times the
+`allocation_size' an attempt is made to shrink the object
+informtation. Shrinking might not always succeed as a single
+allocation block might not be free. Random freeing of objects can
+result in some fragmentation. Any further allocations will use the
+free objects before extending the object's information tables.
+
+A table of inactive objects per block is maintained. This table, like
+the `local_table' and `name_table' grows as more blocks are
+allocated. A check is made of a blocks inactive count when an object
+which is part of that block is freed. If the total inactive count
+exceeds 1.5 times the allocation size, and the block's inactive count
+is the allocation_size, the objects data block is returnd to the
+workspace heap.
+
+The `objects_blocks' is a table of pointers. The object_block's pointers
+point to the object's data block. The object's data block is a single
+allocation of the name space and object space. This was two separate
+allocations but is now one. The objects_block's table is use to
+determine if a block is allocated, and the address of the memory block
+to be returned to the workspace heap when the object informtation
+space is shrunk.
+
+2.0 Detail Of the Auto-Extend Patch to rtems-4.0.0, Snapshot 19990302
+
+o Configuration table support.
+
+ Added a flag OBJECTS_UNLIMITED_OBJECTS to score/headers/object.h
+ header file. This is referenced in the file sapi/headers/config.h to
+ create the flag RTEMS_UNLIMITED_OBJECTS. A macro is provided to take
+ a resource count and apply the flag. The macro is called
+ `rtems_resource_unlimited'. The user uses this macro when building a
+ configuration table. It can be used with the condefs.h header file.
+
+o Object Information Structure
+
+ The object information structure, Objects_Information, has been
+ extended with the follow fields :
+
+ boolean auto_extend -
+
+ When true the object's information tables can be extended untill
+ all memory is used. When false the current functionallity is
+ maintained.
+
+ uint32_t allocation_size -
+
+ When auto_extend is true, it is the value in the Configuration
+ table and is the number of objects the object's information
+ tables are extended or shrunk.
+
+ uint32_t size -
+
+ The size of the object. It is used to calculate the size of
+ memory required to be allocated when extending the table.
+
+ uint32_t inactive -
+
+ The number of elements on the Inactive chain.
+
+ uint32_t *inactive_per_block -
+
+ Pointer to a table of counts of the inactive objects from a
+ block on the Inactive chain. It is used to know which blocks are
+ all free and therefore can be returned to the heap.
+
+ void **object_blocks -
+
+ Pointer to a table of pointers to the object data. The table
+ holds the pointer used to return a block to the heap when
+ shrinking the object's information tables.
+
+o Changes to Existing Object Functions
+
+ Two functions prototypes are added. They are :
+
+ _Objects_Extend_information,
+ _Objects_Shrink_information
+ _Object_Allocate, and
+ _Object_Free
+
+ The last were inlined, how-ever now they are not as they are too
+ complex to implement as macros now.
+
+o Object Initialisation
+
+ The function _Objects_Initialize_information has been changed to
+ initialisation of the information structure's fields then call the
+ new function _Objects_Extend_information.
+
+ The first block of objects is always allocated and never
+ released. This means with the auto-extend flag set to true the user
+ still sees the same behaviour expected without this change. That is
+ the number objects specified in the Configuration table is the
+ number of object allocated during RTEMS initialisation. If not
+ enough memory is found during this initial extend a fatal error
+ occurs. The fatal error only occurs for this case of extending the
+ object's information tables.
+
+o Object Information Extend
+
+ The _Object_Information_Extend is a new function. It takes some of
+ the code form the old _Object_Initialize_information function. The
+ function extends an object's information base.
+
+ Extending the first time is a special case. The function assumes the
+ maximum index will be less than the minimum index. This means the
+ minimum index must be greater than 0 at initialisation. The other
+ special case made is coping the tables from the old location to the
+ new location. The first block case is trapped and tables are
+ initialised instead. Workspace allocation for the first block is
+ tested for an if the first block the allocate or fatal error call is
+ made. This traps an RTEMS initialise allocation error.
+
+ The remainder of the code deals with all cases of extending the
+ object's information.
+
+ The current block count is first determined, then a scan of the
+ object_block table is made to locate a free slot. Blocks can be
+ freed in any order. The index base for the block is also determined.
+
+ If the index base is greater than the maximum index, the tables must
+ grow. To grow the tables, a new larger memory block is allocated and
+ the tables copied. The object's information structure is then
+ updated to point to the new tables. The tables are allocated in one
+ memory block from the work-space heap. The single block is then
+ broken down in the required tables.
+
+ Once the tables are copied, and the new extended parts initialised
+ the table pointers in the object's information structure are
+ updated. This is protected by masking interrupts.
+
+ The old table's memory block is returned to the heap.
+
+ The names table and object is allocated. This again is a single
+ block which is divided.
+
+ The objects are initialised onto a local Inactive chain. They are
+ then copied to the object's Inactive chain to complete the
+ initialisation.
+
+o Object Informtation Shrink
+
+ The _Object_Shrink_information function is new. It is required to
+ scan all the blocks to see which one has no objects allocated. The
+ last object freed might not belong to a block which is completely
+ free.
+
+ Once a block is located, the Inactive chain is interated down
+ looking for objects which belong to the block of object being
+ released.
+
+ Once the Inactive chain scan is complete the names table and object
+ memory is returned to the work-space heap and the table references cleared.
+
+ XXX - I am not sure if this should occur if better protection or
+ different code to provide better protection.
+
+ The information tables do not change size. Once extended they never
+ shrink.
+
+o Object Allocation
+
+ The _Objects_Allocate attempts to get an object from the Inactive
+ chain. If auto-extend mode is not enabled no further processing
+ occurs. The extra overhead for this implemetation is the function is
+ not inlined and check of a boolean occurs. It should effect the
+ timing figures.
+
+ If auto-extend is enabled, a further check is made to see if the get
+ from the Inactive chain suceeded in getting an object. If it failed
+ a call is made to extend the object's information tables.
+
+ The get from the Inactive chain is retried. The result of this is
+ returned to the user. A failure here is the users problem.
+
+o Object Free
+
+ The _Objects_Free puts the object back onto the Inactive
+ chain. Again if auto-extend mode is not enabled no further
+ processing occurs and performance overhead will low.
+
+ If auto-extend mode is enabled, a check is to see if the number of
+ Inactive objects is one and a half times the allocation size. If
+ there are that many free objects an attempt is made to shrink the
+ object's information.
+
+o Object Index and the Get Function
+
+ The existing code allocates the number of object specified in the
+ configuration table, how-ever it makes the local_table have one more
+ element. This is the slot for an id of 0. The 0 slot is always a
+ NULL providing a simple check for a 0 id for object classes.
+
+ The existing _Objects_Get code removes the minimum id, which I think
+ could only be 1 from the index, then adds one for the 0 slot.
+
+ This change removes this index adjustment code in _Objects_Get.
+
+ The extend information starts the index count when scanning for free
+ blocks at the minumun index. This means the base index for a block
+ will always be adjusted by the minimum index. The extend information
+ function only ever allocates the allocation size of
+ objects. Finially the object's local_table size is the maximum plus
+ the minumum index size. The maximum is really the maximum index.
+
+ This means the values in the object's information structure and
+ tables do not need the index adjustments which existed before.
+
+o The Test
+
+ A new sample test, unlimited is provided. It attempts to test this
+ change.
+
+
diff --git a/cpukit/score/src/apiext.c b/cpukit/score/src/apiext.c
new file mode 100644
index 0000000000..a08977113e
--- /dev/null
+++ b/cpukit/score/src/apiext.c
@@ -0,0 +1,113 @@
+/* apiext.c
+ *
+ * XXX
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+
+/*PAGE
+ *
+ * _API_extensions_Initialization
+ */
+
+void _API_extensions_Initialization( void )
+{
+ _Chain_Initialize_empty( &_API_extensions_List );
+}
+
+/*PAGE
+ *
+ * _API_extensions_Add
+ */
+
+void _API_extensions_Add(
+ API_extensions_Control *the_extension
+)
+{
+ _Chain_Append( &_API_extensions_List, &the_extension->Node );
+}
+
+#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /*PAGE
+ *
+ * _API_extensions_Run_predriver
+ */
+
+ void _API_extensions_Run_predriver( void )
+ {
+ Chain_Node *the_node;
+ API_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_First( &_API_extensions_List );
+ !_Chain_Is_tail( &_API_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (API_extensions_Control *) the_node;
+
+ if ( the_extension->predriver_hook )
+ (*the_extension->predriver_hook)();
+ }
+ }
+#endif
+
+/*PAGE
+ *
+ * _API_extensions_Run_postdriver
+ */
+
+void _API_extensions_Run_postdriver( void )
+{
+ Chain_Node *the_node;
+ API_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_First( &_API_extensions_List );
+ !_Chain_Is_tail( &_API_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (API_extensions_Control *) the_node;
+
+ /*
+ * Currently all APIs configure this hook so it is always non-NULL.
+ */
+#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ if ( the_extension->postdriver_hook )
+#endif
+ (*the_extension->postdriver_hook)();
+ }
+}
+
+/*PAGE
+ *
+ * _API_extensions_Run_postswitch
+ */
+
+void _API_extensions_Run_postswitch( void )
+{
+ Chain_Node *the_node;
+ API_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_First( &_API_extensions_List );
+ !_Chain_Is_tail( &_API_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (API_extensions_Control *) the_node;
+
+ (*the_extension->postswitch_hook)( _Thread_Executing );
+ }
+}
+
+/* end of file */
diff --git a/cpukit/score/src/apimutex.c b/cpukit/score/src/apimutex.c
new file mode 100644
index 0000000000..93e67eafaf
--- /dev/null
+++ b/cpukit/score/src/apimutex.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apimutex.h>
+
+void _API_Mutex_Initialization(
+ uint32_t maximum_mutexes
+)
+{
+ _Objects_Initialize_information(
+ &_API_Mutex_Information, /* object information table */
+ OBJECTS_INTERNAL_API, /* object API */
+ OBJECTS_INTERNAL_MUTEXES, /* object class */
+ maximum_mutexes, /* maximum objects of this class */
+ sizeof( API_Mutex_Control ), /* size of this object's control block */
+ false, /* true if the name is a string */
+ 0 /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ true, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/score/src/apimutexallocate.c b/cpukit/score/src/apimutexallocate.c
new file mode 100644
index 0000000000..5a2a323315
--- /dev/null
+++ b/cpukit/score/src/apimutexallocate.c
@@ -0,0 +1,39 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apimutex.h>
+
+void _API_Mutex_Allocate(
+ API_Mutex_Control **the_mutex
+)
+{
+ API_Mutex_Control *mutex;
+
+ CORE_mutex_Attributes attr = {
+ CORE_MUTEX_NESTING_ACQUIRES,
+ false,
+ CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT,
+ 0
+ };
+
+ mutex = (API_Mutex_Control *) _Objects_Allocate( &_API_Mutex_Information );
+
+ _CORE_mutex_Initialize( &mutex->Mutex, &attr, CORE_MUTEX_UNLOCKED );
+
+ _Objects_Open_u32( &_API_Mutex_Information, &mutex->Object, 1 );
+
+ *the_mutex = mutex;
+}
diff --git a/cpukit/score/src/apimutexlock.c b/cpukit/score/src/apimutexlock.c
new file mode 100644
index 0000000000..6729478ae4
--- /dev/null
+++ b/cpukit/score/src/apimutexlock.c
@@ -0,0 +1,34 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apimutex.h>
+
+void _API_Mutex_Lock(
+ API_Mutex_Control *the_mutex
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+
+ _CORE_mutex_Seize(
+ &the_mutex->Mutex,
+ the_mutex->Object.id,
+ true,
+ 0,
+ level
+ );
+}
diff --git a/cpukit/score/src/apimutexunlock.c b/cpukit/score/src/apimutexunlock.c
new file mode 100644
index 0000000000..ca824a6e6c
--- /dev/null
+++ b/cpukit/score/src/apimutexunlock.c
@@ -0,0 +1,30 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apimutex.h>
+
+void _API_Mutex_Unlock(
+ API_Mutex_Control *the_mutex
+)
+{
+ _Thread_Disable_dispatch();
+ _CORE_mutex_Surrender(
+ &the_mutex->Mutex,
+ the_mutex->Object.id,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+}
diff --git a/cpukit/score/src/chain.c b/cpukit/score/src/chain.c
new file mode 100644
index 0000000000..85821d4d71
--- /dev/null
+++ b/cpukit/score/src/chain.c
@@ -0,0 +1,61 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Chain_Initialize
+ *
+ * This kernel routine initializes a doubly linked chain.
+ *
+ * Input parameters:
+ * the_chain - pointer to chain header
+ * starting_address - starting address of first node
+ * number_nodes - number of nodes in chain
+ * node_size - size of node in bytes
+ *
+ * Output parameters: NONE
+ */
+
+void _Chain_Initialize(
+ Chain_Control *the_chain,
+ void *starting_address,
+ size_t number_nodes,
+ size_t node_size
+)
+{
+ size_t count = number_nodes;
+ Chain_Node *head = _Chain_Head( the_chain );
+ Chain_Node *tail = _Chain_Tail( the_chain );
+ Chain_Node *current = head;
+ Chain_Node *next = starting_address;
+
+ head->previous = NULL;
+
+ while ( count-- ) {
+ current->next = next;
+ next->previous = current;
+ current = next;
+ next = (Chain_Node *)
+ _Addresses_Add_offset( (void *) next, node_size );
+ }
+
+ current->next = tail;
+ tail->previous = current;
+}
diff --git a/cpukit/score/src/chainappend.c b/cpukit/score/src/chainappend.c
new file mode 100644
index 0000000000..f5287a450f
--- /dev/null
+++ b/cpukit/score/src/chainappend.c
@@ -0,0 +1,46 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+/*
+ * _Chain_Append
+ *
+ * This kernel routine puts a node on the end of the specified chain.
+ *
+ * Input parameters:
+ * the_chain - pointer to chain header
+ * node - address of node to put at rear of chain
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+void _Chain_Append(
+ Chain_Control *the_chain,
+ Chain_Node *node
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ _Chain_Append_unprotected( the_chain, node );
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/chainappendempty.c b/cpukit/score/src/chainappendempty.c
new file mode 100644
index 0000000000..33033df8ed
--- /dev/null
+++ b/cpukit/score/src/chainappendempty.c
@@ -0,0 +1,44 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreChain
+ *
+ * @brief _Chain_Append_with_empty_check() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+bool _Chain_Append_with_empty_check(
+ Chain_Control *chain,
+ Chain_Node *node
+)
+{
+ ISR_Level level;
+ bool was_empty;
+
+ _ISR_Disable( level );
+ was_empty = _Chain_Append_with_empty_check_unprotected( chain, node );
+ _ISR_Enable( level );
+
+ return was_empty;
+}
diff --git a/cpukit/score/src/chainextract.c b/cpukit/score/src/chainextract.c
new file mode 100644
index 0000000000..deb537ed85
--- /dev/null
+++ b/cpukit/score/src/chainextract.c
@@ -0,0 +1,44 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+/*
+ * _Chain_Extract
+ *
+ * This kernel routine deletes the given node from a chain.
+ *
+ * Input parameters:
+ * node - pointer to node in chain to be deleted
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+void _Chain_Extract(
+ Chain_Node *node
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ _Chain_Extract_unprotected( node );
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/chainget.c b/cpukit/score/src/chainget.c
new file mode 100644
index 0000000000..4ec11c112e
--- /dev/null
+++ b/cpukit/score/src/chainget.c
@@ -0,0 +1,51 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+/*
+ * _Chain_Get
+ *
+ * This kernel routine returns a pointer to a node taken from the
+ * given chain.
+ *
+ * Input parameters:
+ * the_chain - pointer to chain header
+ *
+ * Output parameters:
+ * return_node - pointer to node in chain allocated
+ * CHAIN_END - if no nodes available
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+Chain_Node *_Chain_Get(
+ Chain_Control *the_chain
+)
+{
+ ISR_Level level;
+ Chain_Node *return_node;
+
+ return_node = NULL;
+ _ISR_Disable( level );
+ if ( !_Chain_Is_empty( the_chain ) )
+ return_node = _Chain_Get_first_unprotected( the_chain );
+ _ISR_Enable( level );
+ return return_node;
+}
diff --git a/cpukit/score/src/chaingetempty.c b/cpukit/score/src/chaingetempty.c
new file mode 100644
index 0000000000..3f9be4de5b
--- /dev/null
+++ b/cpukit/score/src/chaingetempty.c
@@ -0,0 +1,44 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreChain
+ *
+ * @brief _Chain_Get_with_empty_check() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+bool _Chain_Get_with_empty_check(
+ Chain_Control *chain,
+ Chain_Node **node
+)
+{
+ ISR_Level level;
+ bool is_empty_now;
+
+ _ISR_Disable( level );
+ is_empty_now = _Chain_Get_with_empty_check_unprotected( chain, node );
+ _ISR_Enable( level );
+
+ return is_empty_now;
+}
diff --git a/cpukit/score/src/chaininsert.c b/cpukit/score/src/chaininsert.c
new file mode 100644
index 0000000000..0f5cdd25ab
--- /dev/null
+++ b/cpukit/score/src/chaininsert.c
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+/*
+ * _Chain_Insert
+ *
+ * This kernel routine inserts a given node after a specified node
+ * a requested chain.
+ *
+ * Input parameters:
+ * after_node - pointer to node in chain to be inserted after
+ * node - pointer to node to be inserted
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+void _Chain_Insert(
+ Chain_Node *after_node,
+ Chain_Node *node
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ _Chain_Insert_unprotected( after_node, node );
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/chainprependempty.c b/cpukit/score/src/chainprependempty.c
new file mode 100644
index 0000000000..9dfd9a653f
--- /dev/null
+++ b/cpukit/score/src/chainprependempty.c
@@ -0,0 +1,44 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreChain
+ *
+ * @brief _Chain_Prepend_with_empty_check() implementation.
+ */
+
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+bool _Chain_Prepend_with_empty_check(
+ Chain_Control *chain,
+ Chain_Node *node
+)
+{
+ ISR_Level level;
+ bool was_empty;
+
+ _ISR_Disable( level );
+ was_empty = _Chain_Prepend_with_empty_check_unprotected( chain, node );
+ _ISR_Enable( level );
+
+ return was_empty;
+}
diff --git a/cpukit/score/src/corebarrier.c b/cpukit/score/src/corebarrier.c
new file mode 100644
index 0000000000..55f093ccc3
--- /dev/null
+++ b/cpukit/score/src/corebarrier.c
@@ -0,0 +1,57 @@
+/*
+ * SuperCore Barrier Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is part of the implementation of the SuperCore Barrier Handler.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corebarrier.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_barrier_Initialize
+ *
+ * This function initialize a barrier and sets the initial value based
+ * on the given count.
+ *
+ * Input parameters:
+ * the_barrier - the barrier control block to initialize
+ * the_barrier_attributes - the attributes specified at create time
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_barrier_Initialize(
+ CORE_barrier_Control *the_barrier,
+ CORE_barrier_Attributes *the_barrier_attributes
+)
+{
+
+ the_barrier->Attributes = *the_barrier_attributes;
+ the_barrier->number_of_waiting_threads = 0;
+
+ _Thread_queue_Initialize(
+ &the_barrier->Wait_queue,
+ THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_BARRIER,
+ CORE_BARRIER_TIMEOUT
+ );
+}
diff --git a/cpukit/score/src/corebarrierrelease.c b/cpukit/score/src/corebarrierrelease.c
new file mode 100644
index 0000000000..7bf341d4c7
--- /dev/null
+++ b/cpukit/score/src/corebarrierrelease.c
@@ -0,0 +1,70 @@
+/*
+ * SuperCore Barrier Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is part of the implementation of the SuperCore Barrier Handler.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/corebarrier.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_barrier_Release
+ *
+ * Input parameters:
+ * the_barrier - the barrier to be flushed
+ * id - id of the object for a remote unblock
+ * api_barrier_mp_support - api dependent MP support actions
+ *
+ * Output parameters:
+ * CORE_BARRIER_STATUS_SUCCESSFUL - if successful
+ * core error code - if unsuccessful
+ *
+ * Output parameters:
+ * returns number of threads unblocked
+ */
+
+uint32_t _CORE_barrier_Release(
+ CORE_barrier_Control *the_barrier,
+#if defined(RTEMS_MULTIPROCESSING)
+ Objects_Id id,
+ CORE_barrier_API_mp_support_callout api_barrier_mp_support
+#else
+ Objects_Id id __attribute__((unused)),
+ CORE_barrier_API_mp_support_callout api_barrier_mp_support __attribute__((unused))
+#endif
+)
+{
+ Thread_Control *the_thread;
+ uint32_t count;
+
+ count = 0;
+ while ( (the_thread = _Thread_queue_Dequeue(&the_barrier->Wait_queue)) ) {
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ (*api_barrier_mp_support) ( the_thread, id );
+#endif
+ count++;
+ }
+ the_barrier->number_of_waiting_threads = 0;
+ return count;
+}
diff --git a/cpukit/score/src/corebarrierwait.c b/cpukit/score/src/corebarrierwait.c
new file mode 100644
index 0000000000..4db276f1ce
--- /dev/null
+++ b/cpukit/score/src/corebarrierwait.c
@@ -0,0 +1,78 @@
+/*
+ * SuperCore Barrier Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is part of the implementation of the SuperCore Barrier Handler.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/corebarrier.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_barrier_Wait
+ *
+ * Input parameters:
+ * the_barrier - pointer to barrier control block
+ * id - id of object to wait on
+ * wait - true if wait is allowed, false otherwise
+ * timeout - number of ticks to wait (0 means forever)
+ * api_barrier_mp_support - api dependent MP support actions
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * available
+ * wait
+ */
+
+void _CORE_barrier_Wait(
+ CORE_barrier_Control *the_barrier,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ CORE_barrier_API_mp_support_callout api_barrier_mp_support
+)
+{
+ Thread_Control *executing;
+ ISR_Level level;
+
+ executing = _Thread_Executing;
+ executing->Wait.return_code = CORE_BARRIER_STATUS_SUCCESSFUL;
+ _ISR_Disable( level );
+ the_barrier->number_of_waiting_threads++;
+ if ( _CORE_barrier_Is_automatic( &the_barrier->Attributes ) ) {
+ if ( the_barrier->number_of_waiting_threads ==
+ the_barrier->Attributes.maximum_count) {
+ executing->Wait.return_code = CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED;
+ _ISR_Enable( level );
+ _CORE_barrier_Release( the_barrier, id, api_barrier_mp_support );
+ return;
+ }
+ }
+
+ _Thread_queue_Enter_critical_section( &the_barrier->Wait_queue );
+ executing->Wait.queue = &the_barrier->Wait_queue;
+ executing->Wait.id = id;
+ _ISR_Enable( level );
+
+ _Thread_queue_Enqueue( &the_barrier->Wait_queue, timeout );
+}
diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
new file mode 100644
index 0000000000..4e3b9545e1
--- /dev/null
+++ b/cpukit/score/src/coremsg.c
@@ -0,0 +1,120 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _CORE_message_queue_Initialize
+ *
+ * This routine initializes a newly created message queue based on the
+ * specified data.
+ *
+ * Input parameters:
+ * the_message_queue - the message queue to initialize
+ * the_class - the API specific object class
+ * the_message_queue_attributes - the message queue's attributes
+ * maximum_pending_messages - maximum message and reserved buffer count
+ * maximum_message_size - maximum size of each message
+ *
+ * Output parameters:
+ * true - if the message queue is initialized
+ * false - if the message queue is NOT initialized
+ */
+
+bool _CORE_message_queue_Initialize(
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Attributes *the_message_queue_attributes,
+ uint32_t maximum_pending_messages,
+ size_t maximum_message_size
+)
+{
+ size_t message_buffering_required;
+ size_t allocated_message_size;
+
+ the_message_queue->maximum_pending_messages = maximum_pending_messages;
+ the_message_queue->number_of_pending_messages = 0;
+ the_message_queue->maximum_message_size = maximum_message_size;
+ _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
+
+ /*
+ * Round size up to multiple of a pointer for chain init and
+ * check for overflow on adding overhead to each message.
+ */
+ allocated_message_size = maximum_message_size;
+ if (allocated_message_size & (sizeof(uint32_t) - 1)) {
+ allocated_message_size += sizeof(uint32_t);
+ allocated_message_size &= ~(sizeof(uint32_t) - 1);
+ }
+
+ if (allocated_message_size < maximum_message_size)
+ return false;
+
+ /*
+ * Calculate how much total memory is required for message buffering and
+ * check for overflow on the multiplication.
+ */
+ message_buffering_required = (size_t) maximum_pending_messages *
+ (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
+
+ if (message_buffering_required < allocated_message_size)
+ return false;
+
+ /*
+ * Attempt to allocate the message memory
+ */
+ the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
+ _Workspace_Allocate( message_buffering_required );
+
+ if (the_message_queue->message_buffers == 0)
+ return false;
+
+ /*
+ * Initialize the pool of inactive messages, pending messages,
+ * and set of waiting threads.
+ */
+ _Chain_Initialize (
+ &the_message_queue->Inactive_messages,
+ the_message_queue->message_buffers,
+ (size_t) maximum_pending_messages,
+ allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
+ );
+
+ _Chain_Initialize_empty( &the_message_queue->Pending_messages );
+
+ _Thread_queue_Initialize(
+ &the_message_queue->Wait_queue,
+ _CORE_message_queue_Is_priority( the_message_queue_attributes ) ?
+ THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_MESSAGE,
+ CORE_MESSAGE_QUEUE_STATUS_TIMEOUT
+ );
+
+ return true;
+}
diff --git a/cpukit/score/src/coremsgbroadcast.c b/cpukit/score/src/coremsgbroadcast.c
new file mode 100644
index 0000000000..f8f76b0a38
--- /dev/null
+++ b/cpukit/score/src/coremsgbroadcast.c
@@ -0,0 +1,116 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Broadcast
+ *
+ * This function sends a message for every thread waiting on the queue and
+ * returns the number of threads made ready by the message.
+ *
+ * Input parameters:
+ * the_message_queue - message is submitted to this message queue
+ * buffer - pointer to message buffer
+ * size - size in bytes of message to send
+ * id - id of message queue
+ * api_message_queue_mp_support - api specific mp support callout
+ * count - area to store number of threads made ready
+ *
+ * Output parameters:
+ * count - number of threads made ready
+ * CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+CORE_message_queue_Status _CORE_message_queue_Broadcast(
+ CORE_message_queue_Control *the_message_queue,
+ const void *buffer,
+ size_t size,
+ #if defined(RTEMS_MULTIPROCESSING)
+ Objects_Id id,
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
+ #else
+ Objects_Id id __attribute__((unused)),
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support __attribute__((unused)),
+ #endif
+ uint32_t *count
+)
+{
+ Thread_Control *the_thread;
+ uint32_t number_broadcasted;
+ Thread_Wait_information *waitp;
+
+ if ( size > the_message_queue->maximum_message_size ) {
+ return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
+ }
+
+ /*
+ * If there are pending messages, then there can't be threads
+ * waiting for us to send them a message.
+ *
+ * NOTE: This check is critical because threads can block on
+ * send and receive and this ensures that we are broadcasting
+ * the message to threads waiting to receive -- not to send.
+ */
+
+ if ( the_message_queue->number_of_pending_messages != 0 ) {
+ *count = 0;
+ return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
+ }
+
+ /*
+ * There must be no pending messages if there is a thread waiting to
+ * receive a message.
+ */
+ number_broadcasted = 0;
+ while ((the_thread =
+ _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) {
+ waitp = &the_thread->Wait;
+ number_broadcasted += 1;
+
+ _CORE_message_queue_Copy_buffer(
+ buffer,
+ waitp->return_argument_second.mutable_object,
+ size
+ );
+
+ *(size_t *) the_thread->Wait.return_argument = size;
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ (*api_message_queue_mp_support) ( the_thread, id );
+ #endif
+
+ }
+ *count = number_broadcasted;
+ return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
+}
diff --git a/cpukit/score/src/coremsgclose.c b/cpukit/score/src/coremsgclose.c
new file mode 100644
index 0000000000..b4622598b5
--- /dev/null
+++ b/cpukit/score/src/coremsgclose.c
@@ -0,0 +1,77 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Close
+ *
+ * This function closes a message by returning all allocated space and
+ * flushing the message_queue's task wait queue.
+ *
+ * Input parameters:
+ * the_message_queue - the message_queue to be flushed
+ * remote_extract_callout - function to invoke remotely
+ * status - status to pass to thread
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_message_queue_Close(
+ CORE_message_queue_Control *the_message_queue,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+)
+{
+
+ /*
+ * This will flush blocked threads whether they were blocked on
+ * a send or receive.
+ */
+
+ _Thread_queue_Flush(
+ &the_message_queue->Wait_queue,
+ remote_extract_callout,
+ status
+ );
+
+ /*
+ * This removes all messages from the pending message queue. Since
+ * we just flushed all waiting threads, we don't have to worry about
+ * the flush satisfying any blocked senders as a side-effect.
+ */
+
+ if ( the_message_queue->number_of_pending_messages != 0 )
+ (void) _CORE_message_queue_Flush_support( the_message_queue );
+
+ (void) _Workspace_Free( the_message_queue->message_buffers );
+
+}
diff --git a/cpukit/score/src/coremsgflush.c b/cpukit/score/src/coremsgflush.c
new file mode 100644
index 0000000000..44bf059b89
--- /dev/null
+++ b/cpukit/score/src/coremsgflush.c
@@ -0,0 +1,55 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Flush
+ *
+ * This function flushes the message_queue's pending message queue. The
+ * number of messages flushed from the queue is returned.
+ *
+ * Input parameters:
+ * the_message_queue - the message_queue to be flushed
+ *
+ * Output parameters:
+ * returns - the number of messages flushed from the queue
+ */
+
+uint32_t _CORE_message_queue_Flush(
+ CORE_message_queue_Control *the_message_queue
+)
+{
+ if ( the_message_queue->number_of_pending_messages != 0 )
+ return _CORE_message_queue_Flush_support( the_message_queue );
+ else
+ return 0;
+}
diff --git a/cpukit/score/src/coremsgflushsupp.c b/cpukit/score/src/coremsgflushsupp.c
new file mode 100644
index 0000000000..4e15e1a495
--- /dev/null
+++ b/cpukit/score/src/coremsgflushsupp.c
@@ -0,0 +1,106 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Flush_support
+ *
+ * This message handler routine removes all messages from a message queue
+ * and returns them to the inactive message pool. The number of messages
+ * flushed from the queue is returned
+ *
+ * Input parameters:
+ * the_message_queue - pointer to message queue
+ *
+ * Output parameters:
+ * returns - number of messages placed on inactive chain
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+uint32_t _CORE_message_queue_Flush_support(
+ CORE_message_queue_Control *the_message_queue
+)
+{
+ ISR_Level level;
+ Chain_Node *inactive_head;
+ Chain_Node *inactive_first;
+ Chain_Node *message_queue_first;
+ Chain_Node *message_queue_last;
+ uint32_t count;
+
+ /*
+ * Currently, RTEMS supports no API that has both flush and blocking
+ * sends. Thus, this routine assumes that there are no senders
+ * blocked waiting to send messages. In the event, that an API is
+ * added that can flush a message queue when threads are blocked
+ * waiting to send, there are two basic behaviors envisioned:
+ *
+ * (1) The thread queue of pending senders is a logical extension
+ * of the pending message queue. In this case, it should be
+ * flushed using the _Thread_queue_Flush() service with a status
+ * such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does
+ * not exist). This can be implemented without changing the "big-O"
+ * of the message flushing part of the routine.
+ *
+ * (2) Only the actual messages queued should be purged. In this case,
+ * the blocked sender threads must be allowed to send their messages.
+ * In this case, the implementation will be forced to individually
+ * dequeue the senders and queue their messages. This will force
+ * this routine to have "big O(n)" where n is the number of blocked
+ * senders. If there are more messages pending than senders blocked,
+ * then the existing flush code can be used to dispose of the remaining
+ * pending messages.
+ *
+ * For now, though, we are very happy to have a small routine with
+ * fixed execution time that only deals with pending messages.
+ */
+
+ _ISR_Disable( level );
+ inactive_head = _Chain_Head( &the_message_queue->Inactive_messages );
+ inactive_first = inactive_head->next;;
+ message_queue_first = _Chain_First( &the_message_queue->Pending_messages );
+ message_queue_last = _Chain_Last( &the_message_queue->Pending_messages );
+
+ inactive_head->next = message_queue_first;
+ message_queue_last->next = inactive_first;
+ inactive_first->previous = message_queue_last;
+ message_queue_first->previous = inactive_head;
+
+ _Chain_Initialize_empty( &the_message_queue->Pending_messages );
+
+ count = the_message_queue->number_of_pending_messages;
+ the_message_queue->number_of_pending_messages = 0;
+ _ISR_Enable( level );
+ return count;
+}
diff --git a/cpukit/score/src/coremsgflushwait.c b/cpukit/score/src/coremsgflushwait.c
new file mode 100644
index 0000000000..d7b3c00f5f
--- /dev/null
+++ b/cpukit/score/src/coremsgflushwait.c
@@ -0,0 +1,72 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /*PAGE
+ *
+ * _CORE_message_queue_Flush_waiting_threads
+ *
+ * This function flushes the message_queue's task wait queue. The number
+ * of messages flushed from the queue is returned.
+ *
+ * Input parameters:
+ * the_message_queue - the message_queue to be flushed
+ *
+ * Output parameters:
+ * returns - the number of messages flushed from the queue
+ */
+
+ void _CORE_message_queue_Flush_waiting_threads(
+ CORE_message_queue_Control *the_message_queue
+ )
+ {
+ /* XXX this is not supported for global message queues */
+
+ /*
+ * IF there are no pending messages,
+ * THEN threads may be blocked waiting to RECEIVE a message,
+ *
+ * IF the pending message queue is full
+ * THEN threads may be blocked waiting to SEND a message
+ *
+ * But in either case, we will return "unsatisfied nowait"
+ * to indicate that the blocking condition was not satisfied
+ * and that the blocking state was canceled.
+ */
+
+ _Thread_queue_Flush(
+ &the_message_queue->Wait_queue,
+ NULL,
+ CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT
+ );
+ }
+#endif
diff --git a/cpukit/score/src/coremsginsert.c b/cpukit/score/src/coremsginsert.c
new file mode 100644
index 0000000000..d333a5fb55
--- /dev/null
+++ b/cpukit/score/src/coremsginsert.c
@@ -0,0 +1,133 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-2005.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Insert_message
+ *
+ * This kernel routine inserts the specified message into the
+ * message queue. It is assumed that the message has been filled
+ * in before this routine is called.
+ *
+ * Input parameters:
+ * the_message_queue - pointer to message queue
+ * the_message - message to insert
+ * priority - insert indication
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * insert
+ */
+
+void _CORE_message_queue_Insert_message(
+ CORE_message_queue_Control *the_message_queue,
+ CORE_message_queue_Buffer_control *the_message,
+ CORE_message_queue_Submit_types submit_type
+)
+{
+ ISR_Level level;
+ #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
+ bool notify = false;
+ #define SET_NOTIFY() \
+ do { \
+ if ( the_message_queue->number_of_pending_messages == 0 ) \
+ notify = true; \
+ } while (0)
+ #else
+ #define SET_NOTIFY()
+ #endif
+
+ _CORE_message_queue_Set_message_priority( the_message, submit_type );
+
+ #if !defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
+ _ISR_Disable( level );
+ SET_NOTIFY();
+ the_message_queue->number_of_pending_messages++;
+ if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST )
+ _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
+ else
+ _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
+ _ISR_Enable( level );
+ #else
+ if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) {
+ _ISR_Disable( level );
+ SET_NOTIFY();
+ the_message_queue->number_of_pending_messages++;
+ _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
+ _ISR_Enable( level );
+ } else if ( submit_type == CORE_MESSAGE_QUEUE_URGENT_REQUEST ) {
+ _ISR_Disable( level );
+ SET_NOTIFY();
+ the_message_queue->number_of_pending_messages++;
+ _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
+ _ISR_Enable( level );
+ } else {
+ CORE_message_queue_Buffer_control *this_message;
+ Chain_Node *the_node;
+ Chain_Control *the_header;
+ int the_priority;
+
+ the_priority = _CORE_message_queue_Get_message_priority(the_message);
+ the_header = &the_message_queue->Pending_messages;
+ the_node = _Chain_First( the_header );
+ while ( !_Chain_Is_tail( the_header, the_node ) ) {
+ int this_priority;
+
+ this_message = (CORE_message_queue_Buffer_control *) the_node;
+
+ this_priority = _CORE_message_queue_Get_message_priority(this_message);
+
+ if ( this_priority <= the_priority ) {
+ the_node = the_node->next;
+ continue;
+ }
+ break;
+ }
+ _ISR_Disable( level );
+ SET_NOTIFY();
+ the_message_queue->number_of_pending_messages++;
+ _Chain_Insert_unprotected( the_node->previous, &the_message->Node );
+ _ISR_Enable( level );
+ }
+ #endif
+
+ #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
+ /*
+ * According to POSIX, does this happen before or after the message
+ * is actually enqueued. It is logical to think afterwards, because
+ * the message is actually in the queue at this point.
+ */
+ if ( notify && the_message_queue->notify_handler )
+ (*the_message_queue->notify_handler)(the_message_queue->notify_argument);
+ #endif
+}
diff --git a/cpukit/score/src/coremsgseize.c b/cpukit/score/src/coremsgseize.c
new file mode 100644
index 0000000000..9a9fd75567
--- /dev/null
+++ b/cpukit/score/src/coremsgseize.c
@@ -0,0 +1,157 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Seize
+ *
+ * This kernel routine dequeues a message, copies the message buffer to
+ * a given destination buffer, and frees the message buffer to the
+ * inactive message pool. The thread will be blocked if wait is true,
+ * otherwise an error will be given to the thread if no messages are available.
+ *
+ * Input parameters:
+ * the_message_queue - pointer to message queue
+ * id - id of object we are waitig on
+ * buffer - pointer to message buffer to be filled
+ * size_p - pointer to the size of buffer to be filled
+ * wait - true if wait is allowed, false otherwise
+ * timeout - time to wait for a message
+ *
+ * Output parameters: NONE
+ *
+ * NOTE: Dependent on BUFFER_LENGTH
+ *
+ * INTERRUPT LATENCY:
+ * available
+ * wait
+ */
+
+void _CORE_message_queue_Seize(
+ CORE_message_queue_Control *the_message_queue,
+ Objects_Id id,
+ void *buffer,
+ size_t *size_p,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ ISR_Level level;
+ CORE_message_queue_Buffer_control *the_message;
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+ executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
+ _ISR_Disable( level );
+ the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
+ if ( the_message != NULL ) {
+ the_message_queue->number_of_pending_messages -= 1;
+ _ISR_Enable( level );
+
+ *size_p = the_message->Contents.size;
+ _Thread_Executing->Wait.count =
+ _CORE_message_queue_Get_message_priority( the_message );
+ _CORE_message_queue_Copy_buffer(
+ the_message->Contents.buffer,
+ buffer,
+ *size_p
+ );
+
+ #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
+ /*
+ * There is not an API with blocking sends enabled.
+ * So return immediately.
+ */
+ _CORE_message_queue_Free_message_buffer(the_message_queue, the_message);
+ return;
+ #else
+ {
+ Thread_Control *the_thread;
+
+ /*
+ * There could be a thread waiting to send a message. If there
+ * is not, then we can go ahead and free the buffer.
+ *
+ * NOTE: If we note that the queue was not full before this receive,
+ * then we can avoid this dequeue.
+ */
+ the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
+ if ( !the_thread ) {
+ _CORE_message_queue_Free_message_buffer(
+ the_message_queue,
+ the_message
+ );
+ return;
+ }
+
+ /*
+ * There was a thread waiting to send a message. This code
+ * puts the messages in the message queue on behalf of the
+ * waiting task.
+ */
+ _CORE_message_queue_Set_message_priority(
+ the_message,
+ the_thread->Wait.count
+ );
+ the_message->Contents.size = (size_t) the_thread->Wait.option;
+ _CORE_message_queue_Copy_buffer(
+ the_thread->Wait.return_argument_second.immutable_object,
+ the_message->Contents.buffer,
+ the_message->Contents.size
+ );
+
+ _CORE_message_queue_Insert_message(
+ the_message_queue,
+ the_message,
+ _CORE_message_queue_Get_message_priority( the_message )
+ );
+ return;
+ }
+ #endif
+ }
+
+ if ( !wait ) {
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
+ return;
+ }
+
+ _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
+ executing->Wait.queue = &the_message_queue->Wait_queue;
+ executing->Wait.id = id;
+ executing->Wait.return_argument_second.mutable_object = buffer;
+ executing->Wait.return_argument = size_p;
+ /* Wait.count will be filled in with the message priority */
+ _ISR_Enable( level );
+
+ _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+}
diff --git a/cpukit/score/src/coremsgsubmit.c b/cpukit/score/src/coremsgsubmit.c
new file mode 100644
index 0000000000..c67157dc44
--- /dev/null
+++ b/cpukit/score/src/coremsgsubmit.c
@@ -0,0 +1,180 @@
+/*
+ * CORE Message Queue Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Message Queue Handler.
+ * This core object provides task synchronization and communication functions
+ * via messages passed to queue objects.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _CORE_message_queue_Submit
+ *
+ * This routine implements the send and urgent message functions. It
+ * processes a message that is to be submitted to the designated
+ * message queue. The message will either be processed as a
+ * send message which it will be inserted at the rear of the queue
+ * or it will be processed as an urgent message which will be inserted
+ * at the front of the queue.
+ *
+ * Input parameters:
+ * the_message_queue - message is submitted to this message queue
+ * buffer - pointer to message buffer
+ * size - size in bytes of message to send
+ * id - id of message queue
+ * api_message_queue_mp_support - api specific mp support callout
+ * submit_type - send or urgent message
+ *
+ * Output parameters:
+ * CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+CORE_message_queue_Status _CORE_message_queue_Submit(
+ CORE_message_queue_Control *the_message_queue,
+ const void *buffer,
+ size_t size,
+ Objects_Id id,
+ #if defined(RTEMS_MULTIPROCESSING)
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support,
+ #else
+ CORE_message_queue_API_mp_support_callout api_message_queue_mp_support __attribute__((unused)),
+ #endif
+ CORE_message_queue_Submit_types submit_type,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ CORE_message_queue_Buffer_control *the_message;
+ Thread_Control *the_thread;
+
+ if ( size > the_message_queue->maximum_message_size ) {
+ return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
+ }
+
+ /*
+ * Is there a thread currently waiting on this message queue?
+ */
+ if ( the_message_queue->number_of_pending_messages == 0 ) {
+ the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
+ if ( the_thread ) {
+ _CORE_message_queue_Copy_buffer(
+ buffer,
+ the_thread->Wait.return_argument_second.mutable_object,
+ size
+ );
+ *(size_t *) the_thread->Wait.return_argument = size;
+ the_thread->Wait.count = (uint32_t) submit_type;
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ (*api_message_queue_mp_support) ( the_thread, id );
+ #endif
+ return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
+ }
+ }
+
+ /*
+ * No one waiting on the message queue at this time, so attempt to
+ * queue the message up for a future receive.
+ */
+ if ( the_message_queue->number_of_pending_messages <
+ the_message_queue->maximum_pending_messages ) {
+
+ the_message =
+ _CORE_message_queue_Allocate_message_buffer( the_message_queue );
+
+ #if defined(RTEMS_DEBUG)
+ /*
+ * NOTE: If the system is consistent, this error should never occur.
+ */
+
+ if ( !the_message )
+ return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
+ #endif
+
+ _CORE_message_queue_Copy_buffer(
+ buffer,
+ the_message->Contents.buffer,
+ size
+ );
+ the_message->Contents.size = size;
+ _CORE_message_queue_Set_message_priority( the_message, submit_type );
+
+ _CORE_message_queue_Insert_message(
+ the_message_queue,
+ the_message,
+ submit_type
+ );
+ return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
+ }
+
+ #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
+ return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
+ #else
+ /*
+ * No message buffers were available so we may need to return an
+ * overflow error or block the sender until the message is placed
+ * on the queue.
+ */
+ if ( !wait ) {
+ return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
+ }
+
+ /*
+ * Do NOT block on a send if the caller is in an ISR. It is
+ * deadly to block in an ISR.
+ */
+ if ( _ISR_Is_in_progress() ) {
+ return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
+ }
+
+ /*
+ * WARNING!! executing should NOT be used prior to this point.
+ * Thus the unusual choice to open a new scope and declare
+ * it as a variable. Doing this emphasizes how dangerous it
+ * would be to use this variable prior to here.
+ */
+ {
+ Thread_Control *executing = _Thread_Executing;
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
+ executing->Wait.queue = &the_message_queue->Wait_queue;
+ executing->Wait.id = id;
+ executing->Wait.return_argument_second.immutable_object = buffer;
+ executing->Wait.option = (uint32_t) size;
+ executing->Wait.count = submit_type;
+ _ISR_Enable( level );
+
+ _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+ }
+
+ return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT;
+ #endif
+}
diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c
new file mode 100644
index 0000000000..dcd2e778fe
--- /dev/null
+++ b/cpukit/score/src/coremutex.c
@@ -0,0 +1,94 @@
+/*
+ * Mutex Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Mutex Handler.
+ * This handler provides synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_mutex_Initialize
+ *
+ * This routine initializes a mutex at create time and set the control
+ * structure according to the values passed.
+ *
+ * Input parameters:
+ * the_mutex - the mutex control block to initialize
+ * the_mutex_attributes - the mutex attributes specified at create time
+ * initial_lock - mutex initial lock or unlocked status
+ *
+ * Output parameters: NONE
+ */
+
+CORE_mutex_Status _CORE_mutex_Initialize(
+ CORE_mutex_Control *the_mutex,
+ CORE_mutex_Attributes *the_mutex_attributes,
+ uint32_t initial_lock
+)
+{
+
+/* Add this to the RTEMS environment later ?????????
+ rtems_assert( initial_lock == CORE_MUTEX_LOCKED ||
+ initial_lock == CORE_MUTEX_UNLOCKED );
+ */
+
+ the_mutex->Attributes = *the_mutex_attributes;
+ the_mutex->lock = initial_lock;
+ the_mutex->blocked_count = 0;
+
+ if ( initial_lock == CORE_MUTEX_LOCKED ) {
+ the_mutex->nest_count = 1;
+ the_mutex->holder = _Thread_Executing;
+ the_mutex->holder_id = _Thread_Executing->Object.id;
+ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
+ _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+
+ if ( _Thread_Executing->current_priority <
+ the_mutex->Attributes.priority_ceiling )
+ return CORE_MUTEX_STATUS_CEILING_VIOLATED;
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ _Chain_Prepend_unprotected( &_Thread_Executing->lock_mutex,
+ &the_mutex->queue.lock_queue );
+ the_mutex->queue.priority_before = _Thread_Executing->current_priority;
+#endif
+
+ _Thread_Executing->resource_count++;
+ }
+ } else {
+ the_mutex->nest_count = 0;
+ the_mutex->holder = NULL;
+ the_mutex->holder_id = 0;
+ }
+
+ _Thread_queue_Initialize(
+ &the_mutex->Wait_queue,
+ _CORE_mutex_Is_fifo( the_mutex_attributes ) ?
+ THREAD_QUEUE_DISCIPLINE_FIFO : THREAD_QUEUE_DISCIPLINE_PRIORITY,
+ STATES_WAITING_FOR_MUTEX,
+ CORE_MUTEX_TIMEOUT
+ );
+
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+}
diff --git a/cpukit/score/src/coremutexflush.c b/cpukit/score/src/coremutexflush.c
new file mode 100644
index 0000000000..2006f2dee8
--- /dev/null
+++ b/cpukit/score/src/coremutexflush.c
@@ -0,0 +1,55 @@
+/*
+ * Mutex Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Mutex Handler.
+ * This handler provides synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_mutex_Flush
+ *
+ * This function a flushes the mutex's task wait queue.
+ *
+ * Input parameters:
+ * the_mutex - the mutex to be flushed
+ * remote_extract_callout - function to invoke remotely
+ * status - status to pass to thread
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_mutex_Flush(
+ CORE_mutex_Control *the_mutex,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+)
+{
+ _Thread_queue_Flush(
+ &the_mutex->Wait_queue,
+ remote_extract_callout,
+ status
+ );
+}
diff --git a/cpukit/score/src/coremutexseize.c b/cpukit/score/src/coremutexseize.c
new file mode 100644
index 0000000000..db6d513cb4
--- /dev/null
+++ b/cpukit/score/src/coremutexseize.c
@@ -0,0 +1,78 @@
+/*
+ * Mutex Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Mutex Handler.
+ * This handler provides synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
+void _CORE_mutex_Seize(
+ CORE_mutex_Control *_the_mutex,
+ Objects_Id _id,
+ bool _wait,
+ Watchdog_Interval _timeout,
+ ISR_Level _level
+)
+{
+ _CORE_mutex_Seize_body( _the_mutex, _id, _wait, _timeout, _level );
+}
+#endif
+
+/*PAGE
+ *
+ * _CORE_mutex_Seize (interrupt blocking support)
+ *
+ * This routine blocks the caller thread after an attempt attempts to obtain
+ * the specified mutex has failed.
+ *
+ * Input parameters:
+ * the_mutex - pointer to mutex control block
+ * timeout - number of ticks to wait (0 means forever)
+ */
+
+void _CORE_mutex_Seize_interrupt_blocking(
+ CORE_mutex_Control *the_mutex,
+ Watchdog_Interval timeout
+)
+{
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
+ if ( the_mutex->holder->current_priority > executing->current_priority ) {
+ _Thread_Change_priority(
+ the_mutex->holder,
+ executing->current_priority,
+ false
+ );
+ }
+ }
+
+ the_mutex->blocked_count++;
+ _Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout );
+
+ _Thread_Enable_dispatch();
+}
+
diff --git a/cpukit/score/src/coremutexseizeintr.c b/cpukit/score/src/coremutexseizeintr.c
new file mode 100644
index 0000000000..4e4e5c4a07
--- /dev/null
+++ b/cpukit/score/src/coremutexseizeintr.c
@@ -0,0 +1,33 @@
+/*
+ * Mutex Handler -- Seize interrupt disable version
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
+int _CORE_mutex_Seize_interrupt_trylock(
+ CORE_mutex_Control *the_mutex,
+ ISR_Level *level_p
+)
+{
+ return _CORE_mutex_Seize_interrupt_trylock_body( the_mutex, level_p );
+}
+#endif
diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c
new file mode 100644
index 0000000000..7e1a444215
--- /dev/null
+++ b/cpukit/score/src/coremutexsurrender.c
@@ -0,0 +1,231 @@
+/*
+ * Mutex Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Mutex Handler.
+ * This handler provides synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ static inline void _CORE_mutex_Push_priority(
+ CORE_mutex_Control *mutex,
+ Thread_Control *thread
+ )
+ {
+ _Chain_Prepend_unprotected(
+ &thread->lock_mutex,
+ &mutex->queue.lock_queue
+ );
+ mutex->queue.priority_before = thread->current_priority;
+ }
+
+ static inline CORE_mutex_Status _CORE_mutex_Pop_priority(
+ CORE_mutex_Control *mutex,
+ Thread_Control *holder
+ )
+ {
+ /*
+ * Check whether the holder release the mutex in LIFO order if not return
+ * error code.
+ */
+ if ( _Chain_First( holder->lock_mutex ) != &mutex->queue.lock_queue ) {
+ mutex->nest_count++;
+
+ return CORE_MUTEX_RELEASE_NOT_ORDER;
+ }
+
+ /*
+ * This pops the first node from the list.
+ */
+ _Chain_Get_first_unprotected( &holder->lock_mutex );
+
+ if ( mutex->queue.priority_before != holder->current_priority )
+ _Thread_Change_priority( holder, mutex->queue.priority_before, true );
+
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+ }
+#else
+ #define _CORE_mutex_Push_priority( mutex, thread ) ((void) 0)
+
+ #define _CORE_mutex_Pop_priority( mutex, thread ) \
+ CORE_MUTEX_STATUS_SUCCESSFUL
+#endif
+
+/*
+ * _CORE_mutex_Surrender
+ *
+ * DESCRIPTION:
+ *
+ * This routine frees a unit to the mutex. If a task was blocked waiting for
+ * a unit from this mutex, then that task will be readied and the unit
+ * given to that task. Otherwise, the unit will be returned to the mutex.
+ *
+ * Input parameters:
+ * the_mutex - the mutex to be flushed
+ * id - id of parent mutex
+ * api_mutex_mp_support - api dependent MP support actions
+ *
+ * Output parameters:
+ * CORE_MUTEX_STATUS_SUCCESSFUL - if successful
+ * core error code - if unsuccessful
+ */
+
+CORE_mutex_Status _CORE_mutex_Surrender(
+ CORE_mutex_Control *the_mutex,
+#if defined(RTEMS_MULTIPROCESSING)
+ Objects_Id id,
+ CORE_mutex_API_mp_support_callout api_mutex_mp_support
+#else
+ Objects_Id id __attribute__((unused)),
+ CORE_mutex_API_mp_support_callout api_mutex_mp_support __attribute__((unused))
+#endif
+)
+{
+ Thread_Control *the_thread;
+ Thread_Control *holder;
+
+ holder = the_mutex->holder;
+
+ /*
+ * The following code allows a thread (or ISR) other than the thread
+ * which acquired the mutex to release that mutex. This is only
+ * allowed when the mutex in quetion is FIFO or simple Priority
+ * discipline. But Priority Ceiling or Priority Inheritance mutexes
+ * must be released by the thread which acquired them.
+ */
+
+ if ( the_mutex->Attributes.only_owner_release ) {
+ if ( !_Thread_Is_executing( holder ) )
+ return CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE;
+ }
+
+ /* XXX already unlocked -- not right status */
+
+ if ( !the_mutex->nest_count )
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+
+ the_mutex->nest_count--;
+
+ if ( the_mutex->nest_count != 0 ) {
+ /*
+ * All error checking is on the locking side, so if the lock was
+ * allowed to acquired multiple times, then we should just deal with
+ * that. The RTEMS_DEBUG is just a validation.
+ */
+ #if defined(RTEMS_DEBUG)
+ switch ( the_mutex->Attributes.lock_nesting_behavior ) {
+ case CORE_MUTEX_NESTING_ACQUIRES:
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+ #if defined(RTEMS_POSIX_API)
+ case CORE_MUTEX_NESTING_IS_ERROR:
+ /* should never occur */
+ return CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
+ #endif
+ case CORE_MUTEX_NESTING_BLOCKS:
+ /* Currently no API exercises this behavior. */
+ break;
+ }
+ #else
+ /* must be CORE_MUTEX_NESTING_ACQUIRES or we wouldn't be here */
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+ #endif
+ }
+
+ /*
+ * Formally release the mutex before possibly transferring it to a
+ * blocked thread.
+ */
+ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
+ _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+ CORE_mutex_Status pop_status =
+ _CORE_mutex_Pop_priority( the_mutex, holder );
+
+ if ( pop_status != CORE_MUTEX_STATUS_SUCCESSFUL )
+ return pop_status;
+
+ holder->resource_count--;
+
+ /*
+ * Whether or not someone is waiting for the mutex, an
+ * inherited priority must be lowered if this is the last
+ * mutex (i.e. resource) this task has.
+ */
+ if ( holder->resource_count == 0 &&
+ holder->real_priority != holder->current_priority ) {
+ _Thread_Change_priority( holder, holder->real_priority, true );
+ }
+ }
+ the_mutex->holder = NULL;
+ the_mutex->holder_id = 0;
+
+ /*
+ * Now we check if another thread was waiting for this mutex. If so,
+ * transfer the mutex to that thread.
+ */
+ if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) ) {
+
+ the_mutex->holder = NULL;
+ the_mutex->holder_id = the_thread->Object.id;
+ the_mutex->nest_count = 1;
+
+ ( *api_mutex_mp_support)( the_thread, id );
+
+ } else
+#endif
+ {
+
+ the_mutex->holder = the_thread;
+ the_mutex->holder_id = the_thread->Object.id;
+ the_mutex->nest_count = 1;
+
+ switch ( the_mutex->Attributes.discipline ) {
+ case CORE_MUTEX_DISCIPLINES_FIFO:
+ case CORE_MUTEX_DISCIPLINES_PRIORITY:
+ break;
+ case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
+ _CORE_mutex_Push_priority( the_mutex, the_thread );
+ the_thread->resource_count++;
+ break;
+ case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
+ _CORE_mutex_Push_priority( the_mutex, the_thread );
+ the_thread->resource_count++;
+ if (the_mutex->Attributes.priority_ceiling <
+ the_thread->current_priority){
+ _Thread_Change_priority(
+ the_thread,
+ the_mutex->Attributes.priority_ceiling,
+ false
+ );
+ }
+ break;
+ }
+ }
+ } else
+ the_mutex->lock = CORE_MUTEX_UNLOCKED;
+
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+}
diff --git a/cpukit/score/src/corerwlock.c b/cpukit/score/src/corerwlock.c
new file mode 100644
index 0000000000..7bc988514e
--- /dev/null
+++ b/cpukit/score/src/corerwlock.c
@@ -0,0 +1,61 @@
+/*
+ * SuperCore RWLock Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is part of the implementation of the SuperCore RWLock Handler.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corerwlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_RWLock_Initialize
+ *
+ * This function initialize a rwlock and sets the initial value based
+ * on the given count.
+ *
+ * Input parameters:
+ * the_rwlock - the rwlock control block to initialize
+ * the_rwlock_attributes - the attributes specified at create time
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_RWLock_Initialize(
+ CORE_RWLock_Control *the_rwlock,
+ CORE_RWLock_Attributes *the_rwlock_attributes
+)
+{
+
+ the_rwlock->Attributes = *the_rwlock_attributes;
+/*
+ the_rwlock->number_of_waiting_threads = 0;
+*/
+ the_rwlock->number_of_readers = 0;
+ the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
+
+ _Thread_queue_Initialize(
+ &the_rwlock->Wait_queue,
+ THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_RWLOCK,
+ CORE_RWLOCK_TIMEOUT
+ );
+}
diff --git a/cpukit/score/src/corerwlockobtainread.c b/cpukit/score/src/corerwlockobtainread.c
new file mode 100644
index 0000000000..78b6ebc187
--- /dev/null
+++ b/cpukit/score/src/corerwlockobtainread.c
@@ -0,0 +1,108 @@
+/*
+ * SuperCore RWLock Handler -- Obtain RWLock for reading
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corerwlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _CORE_rwlock_Obtain_for_reading
+ *
+ * This function waits for the rwlock to become available. Optionally,
+ * a limit may be placed on the duration of the spin.
+ *
+ * Input parameters:
+ * the_rwlock - the rwlock control block to initialize
+ * timeout_allowed - true if timeout allowed
+ * timeout - the maximum number of ticks to spin
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_RWLock_Obtain_for_reading(
+ CORE_RWLock_Control *the_rwlock,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ CORE_RWLock_API_mp_support_callout api_rwlock_mp_support
+)
+{
+ ISR_Level level;
+ Thread_Control *executing = _Thread_Executing;
+
+ /*
+ * If unlocked, then OK to read.
+ * If locked for reading and no waiters, then OK to read.
+ * If any thread is waiting, then we wait.
+ */
+
+ _ISR_Disable( level );
+ switch ( the_rwlock->current_state ) {
+ case CORE_RWLOCK_UNLOCKED:
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
+ the_rwlock->number_of_readers += 1;
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ return;
+
+ case CORE_RWLOCK_LOCKED_FOR_READING: {
+ Thread_Control *waiter;
+ waiter = _Thread_queue_First( &the_rwlock->Wait_queue );
+ if ( !waiter ) {
+ the_rwlock->number_of_readers += 1;
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ return;
+ }
+ break;
+ }
+ case CORE_RWLOCK_LOCKED_FOR_WRITING:
+ break;
+ }
+
+ /*
+ * If the thread is not willing to wait, then return immediately.
+ */
+
+ if ( !wait ) {
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
+ return;
+ }
+
+ /*
+ * We need to wait to enter this critical section
+ */
+
+ _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue );
+ executing->Wait.queue = &the_rwlock->Wait_queue;
+ executing->Wait.id = id;
+ executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ _ISR_Enable( level );
+
+ _Thread_queue_Enqueue_with_handler(
+ &the_rwlock->Wait_queue,
+ timeout,
+ _CORE_RWLock_Timeout
+ );
+
+ /* return to API level so it can dispatch and we block */
+}
diff --git a/cpukit/score/src/corerwlockobtainwrite.c b/cpukit/score/src/corerwlockobtainwrite.c
new file mode 100644
index 0000000000..c3aae6e34c
--- /dev/null
+++ b/cpukit/score/src/corerwlockobtainwrite.c
@@ -0,0 +1,99 @@
+/*
+ * SuperCore RWLock Handler -- Obtain RWLock for writing
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corerwlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _CORE_rwlock_Obtain_for_writing
+ *
+ * This function waits for the rwlock to become available. Optionally,
+ * a limit may be placed on the duration of the spin.
+ *
+ * Input parameters:
+ * the_rwlock - the rwlock control block to initialize
+ * timeout_allowed - true if timeout allowed
+ * timeout - the maximum number of ticks to spin
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_RWLock_Obtain_for_writing(
+ CORE_RWLock_Control *the_rwlock,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout,
+ CORE_RWLock_API_mp_support_callout api_rwlock_mp_support
+)
+{
+ ISR_Level level;
+ Thread_Control *executing = _Thread_Executing;
+
+ /*
+ * If unlocked, then OK to read.
+ * Otherwise, we have to block.
+ * If locked for reading and no waiters, then OK to read.
+ * If any thread is waiting, then we wait.
+ */
+
+ _ISR_Disable( level );
+ switch ( the_rwlock->current_state ) {
+ case CORE_RWLOCK_UNLOCKED:
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ return;
+
+ case CORE_RWLOCK_LOCKED_FOR_READING:
+ case CORE_RWLOCK_LOCKED_FOR_WRITING:
+ break;
+ }
+
+ /*
+ * If the thread is not willing to wait, then return immediately.
+ */
+
+ if ( !wait ) {
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
+ return;
+ }
+
+ /*
+ * We need to wait to enter this critical section
+ */
+
+ _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue );
+ executing->Wait.queue = &the_rwlock->Wait_queue;
+ executing->Wait.id = id;
+ executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE;
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ _ISR_Enable( level );
+
+ _Thread_queue_Enqueue_with_handler(
+ &the_rwlock->Wait_queue,
+ timeout,
+ _CORE_RWLock_Timeout
+ );
+
+
+ /* return to API level so it can dispatch and we block */
+}
diff --git a/cpukit/score/src/corerwlockrelease.c b/cpukit/score/src/corerwlockrelease.c
new file mode 100644
index 0000000000..379fdebdec
--- /dev/null
+++ b/cpukit/score/src/corerwlockrelease.c
@@ -0,0 +1,106 @@
+/*
+ * SuperCore RWLock Handler -- Release a RWLock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corerwlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _CORE_RWLock_Release
+ *
+ * This function releases the rwlock.
+ *
+ * Input parameters:
+ * the_rwlock - the rwlock control block to initialize
+ *
+ * Output parameters: NONE
+ */
+
+CORE_RWLock_Status _CORE_RWLock_Release(
+ CORE_RWLock_Control *the_rwlock
+)
+{
+ ISR_Level level;
+ Thread_Control *executing = _Thread_Executing;
+ Thread_Control *next;
+
+ /*
+ * If unlocked, then OK to read.
+ * Otherwise, we have to block.
+ * If locked for reading and no waiters, then OK to read.
+ * If any thread is waiting, then we wait.
+ */
+
+ _ISR_Disable( level );
+ if ( the_rwlock->current_state == CORE_RWLOCK_UNLOCKED){
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
+ return CORE_RWLOCK_SUCCESSFUL;
+ }
+ if ( the_rwlock->current_state == CORE_RWLOCK_LOCKED_FOR_READING ) {
+ the_rwlock->number_of_readers -= 1;
+ if ( the_rwlock->number_of_readers != 0 ) {
+ /* must be unlocked again */
+ _ISR_Enable( level );
+ return CORE_RWLOCK_SUCCESSFUL;
+ }
+ }
+
+ /* CORE_RWLOCK_LOCKED_FOR_WRITING or READING with readers */
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+
+ /*
+ * Implicitly transition to "unlocked" and find another thread interested
+ * in obtaining this rwlock.
+ */
+ the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
+ _ISR_Enable( level );
+
+ next = _Thread_queue_Dequeue( &the_rwlock->Wait_queue );
+
+ if ( next ) {
+ if ( next->Wait.option == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE ) {
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
+ return CORE_RWLOCK_SUCCESSFUL;
+ }
+
+ /*
+ * Must be CORE_RWLOCK_THREAD_WAITING_FOR_READING
+ */
+ the_rwlock->number_of_readers += 1;
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
+
+ /*
+ * Now see if more readers can be let go.
+ */
+ while ( 1 ) {
+ next = _Thread_queue_First( &the_rwlock->Wait_queue );
+ if ( !next ||
+ next->Wait.option == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE )
+ return CORE_RWLOCK_SUCCESSFUL;
+ the_rwlock->number_of_readers += 1;
+ _Thread_queue_Extract( &the_rwlock->Wait_queue, next );
+ }
+ }
+
+ /* indentation is to match _ISR_Disable at top */
+
+ return CORE_RWLOCK_SUCCESSFUL;
+}
diff --git a/cpukit/score/src/corerwlocktimeout.c b/cpukit/score/src/corerwlocktimeout.c
new file mode 100644
index 0000000000..698b3f8095
--- /dev/null
+++ b/cpukit/score/src/corerwlocktimeout.c
@@ -0,0 +1,55 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corerwlock.h>
+#include <rtems/score/corerwlock.h>
+
+/*
+ * _CORE_RWLock_Timeout
+ *
+ * This routine processes a thread which timeouts while waiting on
+ * a thread queue. It is called by the watchdog handler.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_RWLock_Timeout(
+ Objects_Id id,
+ void *ignored
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+ case OBJECTS_ERROR:
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* impossible */
+#endif
+ break;
+ case OBJECTS_LOCAL:
+ _Thread_queue_Process_timeout( the_thread );
+ _Thread_Unnest_dispatch();
+ break;
+ }
+}
diff --git a/cpukit/score/src/coresem.c b/cpukit/score/src/coresem.c
new file mode 100644
index 0000000000..4f5e0720cb
--- /dev/null
+++ b/cpukit/score/src/coresem.c
@@ -0,0 +1,63 @@
+/*
+ * CORE Semaphore Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Semaphore Handler.
+ * This core object utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * CORE_semaphore_Initialize
+ *
+ * This function initialize a semaphore and sets the initial value based
+ * on the given count.
+ *
+ * Input parameters:
+ * the_semaphore - the semaphore control block to initialize
+ * the_semaphore_attributes - the attributes specified at create time
+ * initial_value - semaphore's initial value
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_semaphore_Initialize(
+ CORE_semaphore_Control *the_semaphore,
+ CORE_semaphore_Attributes *the_semaphore_attributes,
+ uint32_t initial_value
+)
+{
+
+ the_semaphore->Attributes = *the_semaphore_attributes;
+ the_semaphore->count = initial_value;
+
+ _Thread_queue_Initialize(
+ &the_semaphore->Wait_queue,
+ _CORE_semaphore_Is_priority( the_semaphore_attributes ) ?
+ THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_SEMAPHORE,
+ CORE_SEMAPHORE_TIMEOUT
+ );
+}
diff --git a/cpukit/score/src/coresemflush.c b/cpukit/score/src/coresemflush.c
new file mode 100644
index 0000000000..d4ec72cf22
--- /dev/null
+++ b/cpukit/score/src/coresemflush.c
@@ -0,0 +1,58 @@
+/*
+ * CORE Semaphore Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Semaphore Handler.
+ * This core object utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_semaphore_Flush
+ *
+ * This function a flushes the semaphore's task wait queue.
+ *
+ * Input parameters:
+ * the_semaphore - the semaphore to be flushed
+ * remote_extract_callout - function to invoke remotely
+ * status - status to pass to thread
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_semaphore_Flush(
+ CORE_semaphore_Control *the_semaphore,
+ Thread_queue_Flush_callout remote_extract_callout,
+ uint32_t status
+)
+{
+
+ _Thread_queue_Flush(
+ &the_semaphore->Wait_queue,
+ remote_extract_callout,
+ status
+ );
+
+}
diff --git a/cpukit/score/src/coresemseize.c b/cpukit/score/src/coresemseize.c
new file mode 100644
index 0000000000..a66690e148
--- /dev/null
+++ b/cpukit/score/src/coresemseize.c
@@ -0,0 +1,88 @@
+/*
+ * CORE Semaphore Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Semaphore Handler.
+ * This core object utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+#if defined(RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY)
+/*
+ * This routine attempts to allocate a core semaphore to the calling thread.
+ *
+ * Input parameters:
+ * the_semaphore - pointer to semaphore control block
+ * id - id of object to wait on
+ * wait - true if wait is allowed, false otherwise
+ * timeout - number of ticks to wait (0 means forever)
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * available
+ * wait
+ */
+
+void _CORE_semaphore_Seize(
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ Thread_Control *executing;
+ ISR_Level level;
+
+ executing = _Thread_Executing;
+ executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
+ _ISR_Disable( level );
+ if ( the_semaphore->count != 0 ) {
+ the_semaphore->count -= 1;
+ _ISR_Enable( level );
+ return;
+ }
+
+ /*
+ * If the semaphore was not available and the caller was not willing
+ * to block, then return immediately with a status indicating that
+ * the semaphore was not available and the caller never blocked.
+ */
+ if ( !wait ) {
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
+ return;
+ }
+
+ /*
+ * If the semaphore is not available and the caller is willing to
+ * block, then we now block the caller with optional timeout.
+ */
+ _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
+ executing->Wait.queue = &the_semaphore->Wait_queue;
+ executing->Wait.id = id;
+ _ISR_Enable( level );
+ _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
+}
+#endif
diff --git a/cpukit/score/src/coresemsurrender.c b/cpukit/score/src/coresemsurrender.c
new file mode 100644
index 0000000000..321d55e198
--- /dev/null
+++ b/cpukit/score/src/coresemsurrender.c
@@ -0,0 +1,76 @@
+/*
+ * CORE Semaphore Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the CORE Semaphore Handler.
+ * This core object utilizes standard Dijkstra counting semaphores to provide
+ * synchronization and mutual exclusion capabilities.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coresem.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_semaphore_Surrender
+ *
+ * Input parameters:
+ * the_semaphore - the semaphore to be flushed
+ * id - id of parent semaphore
+ * api_semaphore_mp_support - api dependent MP support actions
+ *
+ * Output parameters:
+ * CORE_SEMAPHORE_STATUS_SUCCESSFUL - if successful
+ * core error code - if unsuccessful
+ *
+ * Output parameters:
+ */
+
+CORE_semaphore_Status _CORE_semaphore_Surrender(
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ CORE_semaphore_API_mp_support_callout api_semaphore_mp_support
+)
+{
+ Thread_Control *the_thread;
+ ISR_Level level;
+ CORE_semaphore_Status status;
+
+ status = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
+
+ if ( (the_thread = _Thread_queue_Dequeue(&the_semaphore->Wait_queue)) ) {
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ (*api_semaphore_mp_support) ( the_thread, id );
+#endif
+
+ } else {
+ _ISR_Disable( level );
+ if ( the_semaphore->count < the_semaphore->Attributes.maximum_count )
+ the_semaphore->count += 1;
+ else
+ status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED;
+ _ISR_Enable( level );
+ }
+
+ return status;
+}
diff --git a/cpukit/score/src/corespinlock.c b/cpukit/score/src/corespinlock.c
new file mode 100644
index 0000000000..5eb3d327c3
--- /dev/null
+++ b/cpukit/score/src/corespinlock.c
@@ -0,0 +1,53 @@
+/*
+ * SuperCore Spinlock Handler
+ *
+ * DESCRIPTION:
+ *
+ * This package is part of the implementation of the SuperCore Spinlock Handler.
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corespinlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+/*PAGE
+ *
+ * _CORE_spinlock_Initialize
+ *
+ * This function initialize a spinlock and sets the initial value based
+ * on the given count.
+ *
+ * Input parameters:
+ * the_spinlock - the spinlock control block to initialize
+ * the_spinlock_attributes - the attributes specified at create time
+ *
+ * Output parameters: NONE
+ */
+
+void _CORE_spinlock_Initialize(
+ CORE_spinlock_Control *the_spinlock,
+ CORE_spinlock_Attributes *the_spinlock_attributes
+)
+{
+
+ the_spinlock->Attributes = *the_spinlock_attributes;
+
+ the_spinlock->lock = 0;
+ the_spinlock->users = 0;
+ the_spinlock->holder = 0;
+}
diff --git a/cpukit/score/src/corespinlockrelease.c b/cpukit/score/src/corespinlockrelease.c
new file mode 100644
index 0000000000..fe027448c1
--- /dev/null
+++ b/cpukit/score/src/corespinlockrelease.c
@@ -0,0 +1,72 @@
+/*
+ * SuperCore Spinlock Handler -- Release a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corespinlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _CORE_spinlock_Release
+ *
+ * This function releases the spinlock.
+ *
+ * Input parameters:
+ * the_spinlock - the spinlock control block to initialize
+ *
+ * Output parameters:
+ * CORE_SPINLOCK_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ *
+ */
+
+CORE_spinlock_Status _CORE_spinlock_Release(
+ CORE_spinlock_Control *the_spinlock
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+
+ /*
+ * It must locked before it can be unlocked.
+ */
+ if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) {
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_NOT_LOCKED;
+ }
+
+ /*
+ * It must locked by the current thread before it can be unlocked.
+ */
+ if ( the_spinlock->holder != _Thread_Executing->Object.id ) {
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_NOT_HOLDER;
+ }
+
+ /*
+ * Let it be unlocked.
+ */
+ the_spinlock->users -= 1;
+ the_spinlock->lock = CORE_SPINLOCK_UNLOCKED;
+ the_spinlock->holder = 0;
+
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_SUCCESSFUL;
+}
diff --git a/cpukit/score/src/corespinlockwait.c b/cpukit/score/src/corespinlockwait.c
new file mode 100644
index 0000000000..cf15163977
--- /dev/null
+++ b/cpukit/score/src/corespinlockwait.c
@@ -0,0 +1,114 @@
+/*
+ * SuperCore Spinlock Handler -- Wait for Spinlock
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/corespinlock.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _CORE_spinlock_Wait
+ *
+ * This function waits for the spinlock to become available. Optionally,
+ * a limit may be placed on the duration of the spin.
+ *
+ * Input parameters:
+ * the_spinlock - the spinlock control block to initialize
+ * wait - true if willing to wait
+ * timeout - the maximum number of ticks to spin (0 is forever)
+ *
+ * Output parameters: NONE
+ */
+
+CORE_spinlock_Status _CORE_spinlock_Wait(
+ CORE_spinlock_Control *the_spinlock,
+ bool wait,
+ Watchdog_Interval timeout
+)
+{
+ ISR_Level level;
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ Watchdog_Interval limit = _Watchdog_Ticks_since_boot + timeout;
+ #endif
+
+ _ISR_Disable( level );
+ if ( (the_spinlock->lock == CORE_SPINLOCK_LOCKED) &&
+ (the_spinlock->holder == _Thread_Executing->Object.id) ) {
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_HOLDER_RELOCKING;
+ }
+ the_spinlock->users += 1;
+ for ( ;; ) {
+ if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) {
+ the_spinlock->lock = CORE_SPINLOCK_LOCKED;
+ the_spinlock->holder = _Thread_Executing->Object.id;
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_SUCCESSFUL;
+ }
+
+ /*
+ * Spinlock is unavailable. If not willing to wait, return.
+ */
+ if ( !wait ) {
+ the_spinlock->users -= 1;
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_UNAVAILABLE;
+ }
+
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ /*
+ * They are willing to wait but there could be a timeout.
+ */
+ if ( timeout && (limit <= _Watchdog_Ticks_since_boot) ) {
+ the_spinlock->users -= 1;
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_TIMEOUT;
+ }
+ #endif
+
+ /*
+ * The thread is willing to spin so let's set things up so
+ * another thread has a chance of running. This spinlock has
+ * to be released by either another thread or an ISR. Since
+ * POSIX does not say anything about ISRs, that implies that
+ * another thread must be able to run while spinning. We are
+ * not blocking so that implies we are at least preemptible
+ * and possibly time-sliced.
+ *
+ * So first, we will enable interrpts to allow for them to happen.
+ * Then we will "flash" the thread dispatching critical section
+ * so other threads have a chance to run.
+ *
+ * A spinlock cannot be deleted while it is being used so we are
+ * safe from deletion.
+ */
+
+ _ISR_Enable( level );
+ /* An ISR could occur here */
+
+ _Thread_Enable_dispatch();
+ /* Another thread could get dispatched here */
+
+ /* Reenter the critical sections so we can attempt the lock again. */
+ _Thread_Disable_dispatch();
+
+ _ISR_Disable( level );
+ }
+
+}
diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c
new file mode 100644
index 0000000000..4da8dd4b4f
--- /dev/null
+++ b/cpukit/score/src/coretod.c
@@ -0,0 +1,47 @@
+/*
+ * Time of Day (TOD) Handler
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _TOD_Handler_initialization
+ *
+ * This routine initializes the time of day handler.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _TOD_Handler_initialization(void)
+{
+ /* POSIX format TOD (timespec) */
+ _Timestamp_Set( &_TOD_Now, TOD_SECONDS_1970_THROUGH_1988, 0 );
+
+ /* Uptime (timespec) */
+ _Timestamp_Set_to_zero( &_TOD_Uptime );
+
+ /* TOD has not been set */
+ _TOD_Is_set = false;
+ _TOD_Activate();
+}
diff --git a/cpukit/score/src/coretodget.c b/cpukit/score/src/coretodget.c
new file mode 100644
index 0000000000..953f3cb753
--- /dev/null
+++ b/cpukit/score/src/coretodget.c
@@ -0,0 +1,56 @@
+/*
+ * Time of Day (TOD) Handler - get TOD
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*
+ * _TOD_Get
+ *
+ * This routine is used to obtain the current date and time.
+ *
+ * Input parameters:
+ * time - pointer to the time and date structure
+ *
+ * Output parameters: NONE
+ */
+
+void _TOD_Get(
+ struct timespec *time
+)
+{
+ ISR_Level level;
+ Timestamp_Control offset;
+ Timestamp_Control now;
+ long nanoseconds;
+
+ /* assume time checked for NULL by caller */
+
+ /* _TOD_Now is the native current time */
+ _ISR_Disable( level );
+ now = _TOD_Now;
+ nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
+ _ISR_Enable( level );
+
+ _Timestamp_Set( &offset, 0, nanoseconds );
+ _Timestamp_Add_to( &now, &offset );
+ _Timestamp_To_timespec( &now, time );
+}
diff --git a/cpukit/score/src/coretodgetuptime.c b/cpukit/score/src/coretodgetuptime.c
new file mode 100644
index 0000000000..c5d940b0c0
--- /dev/null
+++ b/cpukit/score/src/coretodgetuptime.c
@@ -0,0 +1,56 @@
+/*
+ * Time of Day (TOD) Handler - get uptime
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*
+ * _TOD_Get_uptime
+ *
+ * This routine is used to obtain the system uptime
+ *
+ * Input parameters:
+ * time - pointer to the timestamp structure
+ *
+ * Output parameters: NONE
+ */
+
+void _TOD_Get_uptime(
+ Timestamp_Control *uptime
+)
+{
+ ISR_Level level;
+ Timestamp_Control offset;
+ Timestamp_Control up;
+ long nanoseconds;
+
+ /* assume time checked for NULL by caller */
+
+ /* _TOD_Uptime is in native timestamp format */
+ _ISR_Disable( level );
+ up = _TOD_Uptime;
+ nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
+ _ISR_Enable( level );
+
+ _Timestamp_Set( &offset, 0, nanoseconds );
+ _Timestamp_Add_to( &up, &offset );
+ *uptime = up;
+}
diff --git a/cpukit/score/src/coretodgetuptimetimespec.c b/cpukit/score/src/coretodgetuptimetimespec.c
new file mode 100644
index 0000000000..6d30a95d9c
--- /dev/null
+++ b/cpukit/score/src/coretodgetuptimetimespec.c
@@ -0,0 +1,44 @@
+/*
+ * Time of Day (TOD) Handler - get uptime
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+
+/*
+ * _TOD_Get_uptime_as_timespec
+ *
+ * This routine is used to obtain the system uptime
+ *
+ * Input parameters:
+ * time - pointer to the timestamp structure
+ *
+ * Output parameters: NONE
+ */
+
+void _TOD_Get_uptime_as_timespec(
+ struct timespec *uptime
+)
+{
+ Timestamp_Control uptime_ts;
+
+ /* assume time checked for NULL by caller */
+ _TOD_Get_uptime( &uptime_ts );
+ _Timestamp_To_timespec( &uptime_ts, uptime );
+}
diff --git a/cpukit/score/src/coretodmsecstoticks.c b/cpukit/score/src/coretodmsecstoticks.c
new file mode 100644
index 0000000000..cddd3d646d
--- /dev/null
+++ b/cpukit/score/src/coretodmsecstoticks.c
@@ -0,0 +1,25 @@
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/tod.h>
+
+uint32_t TOD_MILLISECONDS_TO_TICKS(
+ uint32_t milliseconds
+)
+{
+ return (milliseconds / rtems_configuration_get_milliseconds_per_tick());
+}
diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c
new file mode 100644
index 0000000000..9329fd7d8f
--- /dev/null
+++ b/cpukit/score/src/coretodset.c
@@ -0,0 +1,62 @@
+/*
+ * Time of Day (TOD) Handler -- Set Time
+ */
+
+/* COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _TOD_Set
+ *
+ * This rountine sets the current date and time with the specified
+ * new date and time structure.
+ *
+ * Input parameters:
+ * time - pointer to the time and date structure
+ *
+ * Output parameters: NONE
+ */
+
+void _TOD_Set(
+ const struct timespec *time
+)
+{
+ long seconds;
+
+ _Thread_Disable_dispatch();
+ _TOD_Deactivate();
+
+ seconds = _TOD_Seconds_since_epoch();
+
+ if ( time->tv_sec < seconds )
+ _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds - time->tv_sec );
+ else
+ _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, time->tv_sec - seconds );
+
+ /* POSIX format TOD (timespec) */
+ _Timestamp_Set( &_TOD_Now, time->tv_sec, time->tv_nsec );
+ _TOD_Is_set = true;
+
+ _TOD_Activate();
+
+ _Thread_Enable_dispatch();
+}
diff --git a/cpukit/score/src/coretodtickle.c b/cpukit/score/src/coretodtickle.c
new file mode 100644
index 0000000000..ddc8e4aac0
--- /dev/null
+++ b/cpukit/score/src/coretodtickle.c
@@ -0,0 +1,60 @@
+/*
+ * Time of Day (TOD) Handler -- Tickle Ticks
+ */
+
+/* COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/config.h>
+
+/*PAGE
+ *
+ * _TOD_Tickle_ticks
+ *
+ * This routine processes a clock tick.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _TOD_Tickle_ticks( void )
+{
+ Timestamp_Control tick;
+ uint32_t seconds;
+
+ /* Convert the tick quantum to a timestamp */
+ _Timestamp_Set( &tick, 0, rtems_configuration_get_nanoseconds_per_tick() );
+
+ /* Update the counter of ticks since boot */
+ _Watchdog_Ticks_since_boot += 1;
+
+ /* Update the timespec format uptime */
+ _Timestamp_Add_to( &_TOD_Uptime, &tick );
+ /* we do not care how much the uptime changed */
+
+ /* Update the timespec format TOD */
+ seconds = _Timestamp_Add_to_at_tick( &_TOD_Now, &tick );
+ while ( seconds ) {
+ _Watchdog_Tickle_seconds();
+ seconds--;
+ }
+}
+
diff --git a/cpukit/score/src/coretodtickspersec.c b/cpukit/score/src/coretodtickspersec.c
new file mode 100644
index 0000000000..ac6316ba7b
--- /dev/null
+++ b/cpukit/score/src/coretodtickspersec.c
@@ -0,0 +1,24 @@
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/tod.h>
+
+uint32_t TOD_TICKS_PER_SECOND_method(void)
+{
+ return (TOD_MICROSECONDS_PER_SECOND /
+ rtems_configuration_get_microseconds_per_tick());
+}
diff --git a/cpukit/score/src/coretodusectoticks.c b/cpukit/score/src/coretodusectoticks.c
new file mode 100644
index 0000000000..be2cbd7024
--- /dev/null
+++ b/cpukit/score/src/coretodusectoticks.c
@@ -0,0 +1,25 @@
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/tod.h>
+
+uint32_t TOD_MICROSECONDS_TO_TICKS(
+ uint32_t microseconds
+)
+{
+ return (microseconds / rtems_configuration_get_microseconds_per_tick());
+}
diff --git a/cpukit/score/src/heap.c b/cpukit/score/src/heap.c
new file mode 100644
index 0000000000..b972d84c3c
--- /dev/null
+++ b/cpukit/score/src/heap.c
@@ -0,0 +1,488 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2009, 2010 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/heap.h>
+#include <rtems/score/interr.h>
+
+#if CPU_ALIGNMENT == 0 || CPU_ALIGNMENT % 2 != 0
+ #error "invalid CPU_ALIGNMENT value"
+#endif
+
+static uint32_t instance = 0;
+
+/*PAGE
+ *
+ * _Heap_Initialize
+ *
+ * This kernel routine initializes a heap.
+ *
+ * Input parameters:
+ * heap - pointer to heap header
+ * area_begin - starting address of heap
+ * size - size of heap
+ * page_size - allocatable unit of memory
+ *
+ * Output parameters:
+ * returns - maximum memory available if RTEMS_SUCCESSFUL
+ * 0 - otherwise
+ *
+ * This is what a heap looks like in memory immediately after initialization:
+ *
+ *
+ * +--------------------------------+ <- begin = area_begin
+ * | unused space due to alignment |
+ * | size < page_size |
+ * 0 +--------------------------------+ <- first block
+ * | prev_size = page_size |
+ * 4 +--------------------------------+
+ * | size = size0 | 1 |
+ * 8 +---------------------+----------+ <- aligned on page_size
+ * | next = HEAP_TAIL | |
+ * 12 +---------------------+ |
+ * | prev = HEAP_HEAD | memory |
+ * +---------------------+ |
+ * | available |
+ * | |
+ * | for allocation |
+ * | |
+ * size0 +--------------------------------+ <- last dummy block
+ * | prev_size = size0 |
+ * +4 +--------------------------------+
+ * | size = page_size | 0 | <- prev block is free
+ * +8 +--------------------------------+ <- aligned on page_size
+ * | unused space due to alignment |
+ * | size < page_size |
+ * +--------------------------------+ <- end = begin + size
+ *
+ * Below is what a heap looks like after first allocation of SIZE bytes using
+ * _Heap_allocate(). BSIZE stands for SIZE + 4 aligned up on 'page_size'
+ * boundary.
+ * [NOTE: If allocation were performed by _Heap_Allocate_aligned(), the
+ * block size BSIZE is defined differently, and previously free block will
+ * be split so that upper part of it will become used block (see
+ * 'heapallocatealigned.c' for details).]
+ *
+ * +--------------------------------+ <- begin = area_begin
+ * | unused space due to alignment |
+ * | size < page_size |
+ * 0 +--------------------------------+ <- used block
+ * | prev_size = page_size |
+ * 4 +--------------------------------+
+ * | size = BSIZE | 1 | <- prev block is used
+ * 8 +--------------------------------+ <- aligned on page_size
+ * | . | Pointer returned to the user
+ * | . | is 8 for _Heap_Allocate()
+ * | . | and is in range
+ * 8 + | user-accessible | [8,8+page_size) for
+ * page_size +- - - - - -+ _Heap_Allocate_aligned()
+ * | area |
+ * | . |
+ * BSIZE +- - - - - . - - - - -+ <- free block
+ * | . |
+ * BSIZE +4 +--------------------------------+
+ * | size = S = size0 - BSIZE | 1 | <- prev block is used
+ * BSIZE +8 +-------------------+------------+ <- aligned on page_size
+ * | next = HEAP_TAIL | |
+ * BSIZE +12 +-------------------+ |
+ * | prev = HEAP_HEAD | memory |
+ * +-------------------+ |
+ * | . available |
+ * | . |
+ * | . for |
+ * | . |
+ * BSIZE +S+0 +-------------------+ allocation + <- last dummy block
+ * | prev_size = S | |
+ * +S+4 +-------------------+------------+
+ * | size = page_size | 0 | <- prev block is free
+ * +S+8 +--------------------------------+ <- aligned on page_size
+ * | unused space due to alignment |
+ * | size < page_size |
+ * +--------------------------------+ <- end = begin + size
+ *
+ */
+
+#ifdef HEAP_PROTECTION
+ static void _Heap_Protection_block_initialize_default(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ block->Protection_begin.protector [0] = HEAP_BEGIN_PROTECTOR_0;
+ block->Protection_begin.protector [1] = HEAP_BEGIN_PROTECTOR_1;
+ block->Protection_begin.next_delayed_free_block = NULL;
+ block->Protection_begin.task = _Thread_Executing;
+ block->Protection_begin.tag = NULL;
+ block->Protection_end.protector [0] = HEAP_END_PROTECTOR_0;
+ block->Protection_end.protector [1] = HEAP_END_PROTECTOR_1;
+ }
+
+ static void _Heap_Protection_block_check_default(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ if (
+ block->Protection_begin.protector [0] != HEAP_BEGIN_PROTECTOR_0
+ || block->Protection_begin.protector [1] != HEAP_BEGIN_PROTECTOR_1
+ || block->Protection_end.protector [0] != HEAP_END_PROTECTOR_0
+ || block->Protection_end.protector [1] != HEAP_END_PROTECTOR_1
+ ) {
+ _Heap_Protection_block_error( heap, block );
+ }
+ }
+
+ static void _Heap_Protection_block_error_default(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ /* FIXME */
+ _Internal_error_Occurred( 0xdeadbeef, false, 0xdeadbeef );
+ }
+#endif
+
+bool _Heap_Get_first_and_last_block(
+ uintptr_t heap_area_begin,
+ uintptr_t heap_area_size,
+ uintptr_t page_size,
+ uintptr_t min_block_size,
+ Heap_Block **first_block_ptr,
+ Heap_Block **last_block_ptr
+)
+{
+ uintptr_t const heap_area_end = heap_area_begin + heap_area_size;
+ uintptr_t const alloc_area_begin =
+ _Heap_Align_up( heap_area_begin + HEAP_BLOCK_HEADER_SIZE, page_size );
+ uintptr_t const first_block_begin =
+ alloc_area_begin - HEAP_BLOCK_HEADER_SIZE;
+ uintptr_t const overhead =
+ HEAP_BLOCK_HEADER_SIZE + (first_block_begin - heap_area_begin);
+ uintptr_t const first_block_size =
+ _Heap_Align_down( heap_area_size - overhead, page_size );
+ Heap_Block *const first_block = (Heap_Block *) first_block_begin;
+ Heap_Block *const last_block =
+ _Heap_Block_at( first_block, first_block_size );
+
+ if (
+ heap_area_end < heap_area_begin
+ || heap_area_size <= overhead
+ || first_block_size < min_block_size
+ ) {
+ /* Invalid area or area too small */
+ return false;
+ }
+
+ *first_block_ptr = first_block;
+ *last_block_ptr = last_block;
+
+ return true;
+}
+
+uintptr_t _Heap_Initialize(
+ Heap_Control *heap,
+ void *heap_area_begin_ptr,
+ uintptr_t heap_area_size,
+ uintptr_t page_size
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+ uintptr_t const heap_area_begin = (uintptr_t) heap_area_begin_ptr;
+ uintptr_t const heap_area_end = heap_area_begin + heap_area_size;
+ uintptr_t first_block_begin = 0;
+ uintptr_t first_block_size = 0;
+ uintptr_t last_block_begin = 0;
+ uintptr_t min_block_size = 0;
+ bool area_ok = false;
+ Heap_Block *first_block = NULL;
+ Heap_Block *last_block = NULL;
+
+ if ( page_size == 0 ) {
+ page_size = CPU_ALIGNMENT;
+ } else {
+ page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
+
+ if ( page_size < CPU_ALIGNMENT ) {
+ /* Integer overflow */
+ return 0;
+ }
+ }
+ min_block_size = _Heap_Align_up( sizeof( Heap_Block ), page_size );
+
+ area_ok = _Heap_Get_first_and_last_block(
+ heap_area_begin,
+ heap_area_size,
+ page_size,
+ min_block_size,
+ &first_block,
+ &last_block
+ );
+ if ( !area_ok ) {
+ return 0;
+ }
+
+ memset(heap, 0, sizeof(*heap));
+
+ #ifdef HEAP_PROTECTION
+ heap->Protection.block_initialize = _Heap_Protection_block_initialize_default;
+ heap->Protection.block_check = _Heap_Protection_block_check_default;
+ heap->Protection.block_error = _Heap_Protection_block_error_default;
+ #endif
+
+ first_block_begin = (uintptr_t) first_block;
+ last_block_begin = (uintptr_t) last_block;
+ first_block_size = last_block_begin - first_block_begin;
+
+ /* First block */
+ first_block->prev_size = heap_area_end;
+ first_block->size_and_flag = first_block_size | HEAP_PREV_BLOCK_USED;
+ first_block->next = _Heap_Free_list_tail( heap );
+ first_block->prev = _Heap_Free_list_head( heap );
+ _Heap_Protection_block_initialize( heap, first_block );
+
+ /* Heap control */
+ heap->page_size = page_size;
+ heap->min_block_size = min_block_size;
+ heap->area_begin = heap_area_begin;
+ heap->area_end = heap_area_end;
+ heap->first_block = first_block;
+ heap->last_block = last_block;
+ _Heap_Free_list_head( heap )->next = first_block;
+ _Heap_Free_list_tail( heap )->prev = first_block;
+
+ /* Last block */
+ last_block->prev_size = first_block_size;
+ last_block->size_and_flag = 0;
+ _Heap_Set_last_block_size( heap );
+ _Heap_Protection_block_initialize( heap, last_block );
+
+ /* Statistics */
+ stats->size = first_block_size;
+ stats->free_size = first_block_size;
+ stats->min_free_size = first_block_size;
+ stats->free_blocks = 1;
+ stats->max_free_blocks = 1;
+ stats->instance = instance++;
+
+ _HAssert( _Heap_Is_aligned( heap->page_size, CPU_ALIGNMENT ) );
+ _HAssert( _Heap_Is_aligned( heap->min_block_size, page_size ) );
+ _HAssert(
+ _Heap_Is_aligned( _Heap_Alloc_area_of_block( first_block ), page_size )
+ );
+ _HAssert(
+ _Heap_Is_aligned( _Heap_Alloc_area_of_block( last_block ), page_size )
+ );
+
+ return first_block_size;
+}
+
+static void _Heap_Block_split(
+ Heap_Control *heap,
+ Heap_Block *block,
+ Heap_Block *free_list_anchor,
+ uintptr_t alloc_size
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const min_block_size = heap->min_block_size;
+ uintptr_t const min_alloc_size = min_block_size - HEAP_BLOCK_HEADER_SIZE;
+
+ uintptr_t const block_size = _Heap_Block_size( block );
+
+ uintptr_t const used_size =
+ _Heap_Max( alloc_size, min_alloc_size ) + HEAP_BLOCK_HEADER_SIZE;
+ uintptr_t const used_block_size = _Heap_Align_up( used_size, page_size );
+
+ uintptr_t const free_size = block_size + HEAP_ALLOC_BONUS - used_size;
+ uintptr_t const free_size_limit = min_block_size + HEAP_ALLOC_BONUS;
+
+ Heap_Block *next_block = _Heap_Block_at( block, block_size );
+
+ _HAssert( used_size <= block_size + HEAP_ALLOC_BONUS );
+ _HAssert( used_size + free_size == block_size + HEAP_ALLOC_BONUS );
+
+ if ( free_size >= free_size_limit ) {
+ Heap_Block *const free_block = _Heap_Block_at( block, used_block_size );
+ uintptr_t free_block_size = block_size - used_block_size;
+
+ _HAssert( used_block_size + free_block_size == block_size );
+
+ _Heap_Block_set_size( block, used_block_size );
+
+ /* Statistics */
+ stats->free_size += free_block_size;
+
+ if ( _Heap_Is_used( next_block ) ) {
+ _Heap_Free_list_insert_after( free_list_anchor, free_block );
+
+ /* Statistics */
+ ++stats->free_blocks;
+ } else {
+ uintptr_t const next_block_size = _Heap_Block_size( next_block );
+
+ _Heap_Free_list_replace( next_block, free_block );
+
+ free_block_size += next_block_size;
+
+ next_block = _Heap_Block_at( free_block, free_block_size );
+ }
+
+ free_block->size_and_flag = free_block_size | HEAP_PREV_BLOCK_USED;
+
+ next_block->prev_size = free_block_size;
+ next_block->size_and_flag &= ~HEAP_PREV_BLOCK_USED;
+
+ _Heap_Protection_block_initialize( heap, free_block );
+ } else {
+ next_block->size_and_flag |= HEAP_PREV_BLOCK_USED;
+ }
+}
+
+static Heap_Block *_Heap_Block_allocate_from_begin(
+ Heap_Control *heap,
+ Heap_Block *block,
+ Heap_Block *free_list_anchor,
+ uintptr_t alloc_size
+)
+{
+ _Heap_Block_split( heap, block, free_list_anchor, alloc_size );
+
+ return block;
+}
+
+static Heap_Block *_Heap_Block_allocate_from_end(
+ Heap_Control *heap,
+ Heap_Block *block,
+ Heap_Block *free_list_anchor,
+ uintptr_t alloc_begin,
+ uintptr_t alloc_size
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+
+ uintptr_t block_begin = (uintptr_t) block;
+ uintptr_t block_size = _Heap_Block_size( block );
+ uintptr_t block_end = block_begin + block_size;
+
+ Heap_Block *const new_block =
+ _Heap_Block_of_alloc_area( alloc_begin, heap->page_size );
+ uintptr_t const new_block_begin = (uintptr_t) new_block;
+ uintptr_t const new_block_size = block_end - new_block_begin;
+
+ block_end = new_block_begin;
+ block_size = block_end - block_begin;
+
+ _HAssert( block_size >= heap->min_block_size );
+ _HAssert( new_block_size >= heap->min_block_size );
+
+ /* Statistics */
+ stats->free_size += block_size;
+
+ if ( _Heap_Is_prev_used( block ) ) {
+ _Heap_Free_list_insert_after( free_list_anchor, block );
+
+ free_list_anchor = block;
+
+ /* Statistics */
+ ++stats->free_blocks;
+ } else {
+ Heap_Block *const prev_block = _Heap_Prev_block( block );
+ uintptr_t const prev_block_size = _Heap_Block_size( prev_block );
+
+ block = prev_block;
+ block_size += prev_block_size;
+ }
+
+ block->size_and_flag = block_size | HEAP_PREV_BLOCK_USED;
+
+ new_block->prev_size = block_size;
+ new_block->size_and_flag = new_block_size;
+
+ _Heap_Block_split( heap, new_block, free_list_anchor, alloc_size );
+
+ return new_block;
+}
+
+Heap_Block *_Heap_Block_allocate(
+ Heap_Control *heap,
+ Heap_Block *block,
+ uintptr_t alloc_begin,
+ uintptr_t alloc_size
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+
+ uintptr_t const alloc_area_begin = _Heap_Alloc_area_of_block( block );
+ uintptr_t const alloc_area_offset = alloc_begin - alloc_area_begin;
+
+ Heap_Block *free_list_anchor = NULL;
+
+ _HAssert( alloc_area_begin <= alloc_begin );
+
+ if ( _Heap_Is_free( block ) ) {
+ free_list_anchor = block->prev;
+
+ _Heap_Free_list_remove( block );
+
+ /* Statistics */
+ --stats->free_blocks;
+ ++stats->used_blocks;
+ stats->free_size -= _Heap_Block_size( block );
+ } else {
+ free_list_anchor = _Heap_Free_list_head( heap );
+ }
+
+ if ( alloc_area_offset < heap->page_size ) {
+ alloc_size += alloc_area_offset;
+
+ block = _Heap_Block_allocate_from_begin(
+ heap,
+ block,
+ free_list_anchor,
+ alloc_size
+ );
+ } else {
+ block = _Heap_Block_allocate_from_end(
+ heap,
+ block,
+ free_list_anchor,
+ alloc_begin,
+ alloc_size
+ );
+ }
+
+ /* Statistics */
+ if ( stats->min_free_size > stats->free_size ) {
+ stats->min_free_size = stats->free_size;
+ }
+
+ _Heap_Protection_block_initialize( heap, block );
+
+ return block;
+}
diff --git a/cpukit/score/src/heapallocate.c b/cpukit/score/src/heapallocate.c
new file mode 100644
index 0000000000..61cebc2054
--- /dev/null
+++ b/cpukit/score/src/heapallocate.c
@@ -0,0 +1,280 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+#ifndef HEAP_PROTECTION
+ #define _Heap_Protection_free_delayed_blocks( heap, alloc_begin ) false
+#else
+ static bool _Heap_Protection_free_delayed_blocks(
+ Heap_Control *heap,
+ uintptr_t alloc_begin
+ )
+ {
+ bool search_again = false;
+ uintptr_t const blocks_to_free_count =
+ (heap->Protection.delayed_free_block_count + 1) / 2;
+
+ if ( alloc_begin == 0 && blocks_to_free_count > 0 ) {
+ Heap_Block *block_to_free = heap->Protection.first_delayed_free_block;
+ uintptr_t count = 0;
+
+ for ( count = 0; count < blocks_to_free_count; ++count ) {
+ Heap_Block *next_block_to_free =
+ block_to_free->Protection_begin.next_delayed_free_block;
+
+ block_to_free->Protection_begin.next_delayed_free_block =
+ HEAP_PROTECTION_OBOLUS;
+
+ _Heap_Free(
+ heap,
+ (void *) _Heap_Alloc_area_of_block( block_to_free )
+ );
+
+ block_to_free = next_block_to_free;
+ }
+
+ heap->Protection.delayed_free_block_count -= blocks_to_free_count;
+ heap->Protection.first_delayed_free_block = block_to_free;
+
+ search_again = true;
+ }
+
+ return search_again;
+ }
+#endif
+
+#ifdef RTEMS_HEAP_DEBUG
+ static void _Heap_Check_allocation(
+ const Heap_Control *heap,
+ const Heap_Block *block,
+ uintptr_t alloc_begin,
+ uintptr_t alloc_size,
+ uintptr_t alignment,
+ uintptr_t boundary
+ )
+ {
+ uintptr_t const min_block_size = heap->min_block_size;
+ uintptr_t const page_size = heap->page_size;
+
+ uintptr_t const block_begin = (uintptr_t) block;
+ uintptr_t const block_size = _Heap_Block_size( block );
+ uintptr_t const block_end = block_begin + block_size;
+
+ uintptr_t const alloc_end = alloc_begin + alloc_size;
+
+ uintptr_t const alloc_area_begin = _Heap_Alloc_area_of_block( block );
+ uintptr_t const alloc_area_offset = alloc_begin - alloc_area_begin;
+
+ _HAssert( block_size >= min_block_size );
+ _HAssert( block_begin < block_end );
+ _HAssert(
+ _Heap_Is_aligned( block_begin + HEAP_BLOCK_HEADER_SIZE, page_size )
+ );
+ _HAssert(
+ _Heap_Is_aligned( block_size, page_size )
+ );
+
+ _HAssert( alloc_end <= block_end + HEAP_ALLOC_BONUS );
+ _HAssert( alloc_area_begin == block_begin + HEAP_BLOCK_HEADER_SIZE);
+ _HAssert( alloc_area_offset < page_size );
+
+ _HAssert( _Heap_Is_aligned( alloc_area_begin, page_size ) );
+ if ( alignment == 0 ) {
+ _HAssert( alloc_begin == alloc_area_begin );
+ } else {
+ _HAssert( _Heap_Is_aligned( alloc_begin, alignment ) );
+ }
+
+ if ( boundary != 0 ) {
+ uintptr_t boundary_line = _Heap_Align_down( alloc_end, boundary );
+
+ _HAssert( alloc_size <= boundary );
+ _HAssert( boundary_line <= alloc_begin || alloc_end <= boundary_line );
+ }
+ }
+#else
+ #define _Heap_Check_allocation( h, b, ab, as, ag, bd ) ((void) 0)
+#endif
+
+static uintptr_t _Heap_Check_block(
+ const Heap_Control *heap,
+ const Heap_Block *block,
+ uintptr_t alloc_size,
+ uintptr_t alignment,
+ uintptr_t boundary
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const min_block_size = heap->min_block_size;
+
+ uintptr_t const block_begin = (uintptr_t) block;
+ uintptr_t const block_size = _Heap_Block_size( block );
+ uintptr_t const block_end = block_begin + block_size;
+
+ uintptr_t const alloc_begin_floor = _Heap_Alloc_area_of_block( block );
+ uintptr_t const alloc_begin_ceiling = block_end - min_block_size
+ + HEAP_BLOCK_HEADER_SIZE + page_size - 1;
+
+ uintptr_t alloc_end = block_end + HEAP_ALLOC_BONUS;
+ uintptr_t alloc_begin = alloc_end - alloc_size;
+
+ alloc_begin = _Heap_Align_down( alloc_begin, alignment );
+
+ /* Ensure that the we have a valid new block at the end */
+ if ( alloc_begin > alloc_begin_ceiling ) {
+ alloc_begin = _Heap_Align_down( alloc_begin_ceiling, alignment );
+ }
+
+ alloc_end = alloc_begin + alloc_size;
+
+ /* Ensure boundary constaint */
+ if ( boundary != 0 ) {
+ uintptr_t const boundary_floor = alloc_begin_floor + alloc_size;
+ uintptr_t boundary_line = _Heap_Align_down( alloc_end, boundary );
+
+ while ( alloc_begin < boundary_line && boundary_line < alloc_end ) {
+ if ( boundary_line < boundary_floor ) {
+ return 0;
+ }
+ alloc_begin = boundary_line - alloc_size;
+ alloc_begin = _Heap_Align_down( alloc_begin, alignment );
+ alloc_end = alloc_begin + alloc_size;
+ boundary_line = _Heap_Align_down( alloc_end, boundary );
+ }
+ }
+
+ /* Ensure that the we have a valid new block at the beginning */
+ if ( alloc_begin >= alloc_begin_floor ) {
+ uintptr_t const alloc_block_begin =
+ (uintptr_t) _Heap_Block_of_alloc_area( alloc_begin, page_size );
+ uintptr_t const free_size = alloc_block_begin - block_begin;
+
+ if ( free_size >= min_block_size || free_size == 0 ) {
+ return alloc_begin;
+ }
+ }
+
+ return 0;
+}
+
+void *_Heap_Allocate_aligned_with_boundary(
+ Heap_Control *heap,
+ uintptr_t alloc_size,
+ uintptr_t alignment,
+ uintptr_t boundary
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+ uintptr_t const block_size_floor = alloc_size + HEAP_BLOCK_HEADER_SIZE
+ - HEAP_ALLOC_BONUS;
+ uintptr_t const page_size = heap->page_size;
+ Heap_Block *block = NULL;
+ uintptr_t alloc_begin = 0;
+ uint32_t search_count = 0;
+ bool search_again = false;
+
+ if ( block_size_floor < alloc_size ) {
+ /* Integer overflow occured */
+ return NULL;
+ }
+
+ if ( boundary != 0 ) {
+ if ( boundary < alloc_size ) {
+ return NULL;
+ }
+
+ if ( alignment == 0 ) {
+ alignment = page_size;
+ }
+ }
+
+ do {
+ Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
+
+ block = _Heap_Free_list_first( heap );
+ while ( block != free_list_tail ) {
+ _HAssert( _Heap_Is_prev_used( block ) );
+
+ _Heap_Protection_block_check( heap, block );
+
+ /*
+ * The HEAP_PREV_BLOCK_USED flag is always set in the block size_and_flag
+ * field. Thus the value is about one unit larger than the real block
+ * size. The greater than operator takes this into account.
+ */
+ if ( block->size_and_flag > block_size_floor ) {
+ if ( alignment == 0 ) {
+ alloc_begin = _Heap_Alloc_area_of_block( block );
+ } else {
+ alloc_begin = _Heap_Check_block(
+ heap,
+ block,
+ alloc_size,
+ alignment,
+ boundary
+ );
+ }
+ }
+
+ /* Statistics */
+ ++search_count;
+
+ if ( alloc_begin != 0 ) {
+ break;
+ }
+
+ block = block->next;
+ }
+
+ search_again = _Heap_Protection_free_delayed_blocks( heap, alloc_begin );
+ } while ( search_again );
+
+ if ( alloc_begin != 0 ) {
+ /* Statistics */
+ ++stats->allocs;
+ stats->searches += search_count;
+
+ block = _Heap_Block_allocate( heap, block, alloc_begin, alloc_size );
+
+ _Heap_Check_allocation(
+ heap,
+ block,
+ alloc_begin,
+ alloc_size,
+ alignment,
+ boundary
+ );
+ }
+
+ /* Statistics */
+ if ( stats->max_search < search_count ) {
+ stats->max_search = search_count;
+ }
+
+ return (void *) alloc_begin;
+}
diff --git a/cpukit/score/src/heapextend.c b/cpukit/score/src/heapextend.c
new file mode 100644
index 0000000000..eab2a9482d
--- /dev/null
+++ b/cpukit/score/src/heapextend.c
@@ -0,0 +1,243 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2010 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+static void _Heap_Free_block( Heap_Control *heap, Heap_Block *block )
+{
+ Heap_Statistics *const stats = &heap->stats;
+
+ /* Statistics */
+ ++stats->used_blocks;
+ --stats->frees;
+
+ _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( block ));
+}
+
+static void _Heap_Merge_below(
+ Heap_Control *heap,
+ uintptr_t extend_area_begin,
+ Heap_Block *first_block
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const new_first_block_alloc_begin =
+ _Heap_Align_up( extend_area_begin + HEAP_BLOCK_HEADER_SIZE, page_size );
+ uintptr_t const new_first_block_begin =
+ new_first_block_alloc_begin - HEAP_BLOCK_HEADER_SIZE;
+ uintptr_t const first_block_begin = (uintptr_t) first_block;
+ uintptr_t const new_first_block_size =
+ first_block_begin - new_first_block_begin;
+ Heap_Block *const new_first_block = (Heap_Block *) new_first_block_begin;
+
+ new_first_block->prev_size = first_block->prev_size;
+ new_first_block->size_and_flag = new_first_block_size | HEAP_PREV_BLOCK_USED;
+
+ _Heap_Free_block( heap, new_first_block );
+}
+
+static void _Heap_Merge_above(
+ Heap_Control *heap,
+ Heap_Block *last_block,
+ uintptr_t extend_area_end
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const last_block_begin = (uintptr_t) last_block;
+ uintptr_t const last_block_new_size = _Heap_Align_down(
+ extend_area_end - last_block_begin - HEAP_BLOCK_HEADER_SIZE,
+ page_size
+ );
+ Heap_Block *const new_last_block =
+ _Heap_Block_at( last_block, last_block_new_size );
+
+ new_last_block->size_and_flag =
+ (last_block->size_and_flag - last_block_new_size)
+ | HEAP_PREV_BLOCK_USED;
+
+ _Heap_Block_set_size( last_block, last_block_new_size );
+
+ _Heap_Free_block( heap, last_block );
+}
+
+static void _Heap_Link_below(
+ Heap_Block *link,
+ Heap_Block *last_block
+)
+{
+ uintptr_t const last_block_begin = (uintptr_t) last_block;
+ uintptr_t const link_begin = (uintptr_t) link;
+
+ last_block->size_and_flag =
+ (link_begin - last_block_begin) | HEAP_PREV_BLOCK_USED;
+}
+
+static void _Heap_Link_above(
+ Heap_Block *link,
+ Heap_Block *first_block,
+ Heap_Block *last_block
+)
+{
+ uintptr_t const link_begin = (uintptr_t) link;
+ uintptr_t const first_block_begin = (uintptr_t) first_block;
+
+ _Heap_Block_set_size( link, first_block_begin - link_begin );
+
+ last_block->size_and_flag |= HEAP_PREV_BLOCK_USED;
+}
+
+bool _Heap_Extend(
+ Heap_Control *heap,
+ void *extend_area_begin_ptr,
+ uintptr_t extend_area_size,
+ uintptr_t *extended_size_ptr
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+ Heap_Block *const first_block = heap->first_block;
+ Heap_Block *start_block = first_block;
+ Heap_Block *merge_below_block = NULL;
+ Heap_Block *merge_above_block = NULL;
+ Heap_Block *link_below_block = NULL;
+ Heap_Block *link_above_block = NULL;
+ Heap_Block *extend_first_block = NULL;
+ Heap_Block *extend_last_block = NULL;
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const min_block_size = heap->min_block_size;
+ uintptr_t const extend_area_begin = (uintptr_t) extend_area_begin_ptr;
+ uintptr_t const extend_area_end = extend_area_begin + extend_area_size;
+ uintptr_t const free_size = stats->free_size;
+ uintptr_t extend_first_block_size = 0;
+ uintptr_t extended_size = 0;
+ bool extend_area_ok = false;
+
+ if ( extend_area_end < extend_area_begin ) {
+ return false;
+ }
+
+ extend_area_ok = _Heap_Get_first_and_last_block(
+ extend_area_begin,
+ extend_area_size,
+ page_size,
+ min_block_size,
+ &extend_first_block,
+ &extend_last_block
+ );
+ if (!extend_area_ok ) {
+ /* For simplicity we reject extend areas that are too small */
+ return false;
+ }
+
+ do {
+ uintptr_t const sub_area_begin = (start_block != first_block) ?
+ (uintptr_t) start_block : heap->area_begin;
+ uintptr_t const sub_area_end = start_block->prev_size;
+ Heap_Block *const end_block =
+ _Heap_Block_of_alloc_area( sub_area_end, page_size );
+
+ if (
+ sub_area_end > extend_area_begin && extend_area_end > sub_area_begin
+ ) {
+ return false;
+ }
+
+ if ( extend_area_end == sub_area_begin ) {
+ merge_below_block = start_block;
+ } else if ( extend_area_end < sub_area_end ) {
+ link_below_block = start_block;
+ }
+
+ if ( sub_area_end == extend_area_begin ) {
+ start_block->prev_size = extend_area_end;
+
+ merge_above_block = end_block;
+ } else if ( sub_area_end < extend_area_begin ) {
+ link_above_block = end_block;
+ }
+
+ start_block = _Heap_Block_at( end_block, _Heap_Block_size( end_block ) );
+ } while ( start_block != first_block );
+
+ if ( extend_area_begin < heap->area_begin ) {
+ heap->area_begin = extend_area_begin;
+ } else if ( heap->area_end < extend_area_end ) {
+ heap->area_end = extend_area_end;
+ }
+
+ extend_first_block_size =
+ (uintptr_t) extend_last_block - (uintptr_t) extend_first_block;
+
+ extend_first_block->prev_size = extend_area_end;
+ extend_first_block->size_and_flag =
+ extend_first_block_size | HEAP_PREV_BLOCK_USED;
+ _Heap_Protection_block_initialize( heap, extend_first_block );
+
+ extend_last_block->prev_size = extend_first_block_size;
+ extend_last_block->size_and_flag = 0;
+ _Heap_Protection_block_initialize( heap, extend_last_block );
+
+ if ( (uintptr_t) extend_first_block < (uintptr_t) heap->first_block ) {
+ heap->first_block = extend_first_block;
+ } else if ( (uintptr_t) extend_last_block > (uintptr_t) heap->last_block ) {
+ heap->last_block = extend_last_block;
+ }
+
+ if ( merge_below_block != NULL ) {
+ _Heap_Merge_below( heap, extend_area_begin, merge_below_block );
+ } else if ( link_below_block != NULL ) {
+ _Heap_Link_below(
+ link_below_block,
+ extend_last_block
+ );
+ }
+
+ if ( merge_above_block != NULL ) {
+ _Heap_Merge_above( heap, merge_above_block, extend_area_end );
+ } else if ( link_above_block != NULL ) {
+ _Heap_Link_above(
+ link_above_block,
+ extend_first_block,
+ extend_last_block
+ );
+ }
+
+ if ( merge_below_block == NULL && merge_above_block == NULL ) {
+ _Heap_Free_block( heap, extend_first_block );
+ }
+
+ _Heap_Set_last_block_size( heap );
+
+ extended_size = stats->free_size - free_size;
+
+ /* Statistics */
+ stats->size += extended_size;
+
+ if ( extended_size_ptr != NULL )
+ *extended_size_ptr = extended_size;
+
+ return true;
+}
diff --git a/cpukit/score/src/heapfree.c b/cpukit/score/src/heapfree.c
new file mode 100644
index 0000000000..25a1e6964d
--- /dev/null
+++ b/cpukit/score/src/heapfree.c
@@ -0,0 +1,215 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/heap.h>
+
+#ifndef HEAP_PROTECTION
+ #define _Heap_Protection_determine_block_free( heap, block ) true
+#else
+ static void _Heap_Protection_delay_block_free(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ uintptr_t *const pattern_begin = (uintptr_t *)
+ _Heap_Alloc_area_of_block( block );
+ uintptr_t *const pattern_end = (uintptr_t *)
+ ((uintptr_t) block + _Heap_Block_size( block ) + HEAP_ALLOC_BONUS);
+ uintptr_t const delayed_free_block_count =
+ heap->Protection.delayed_free_block_count;
+ uintptr_t *current = NULL;
+
+ block->Protection_begin.next_delayed_free_block = block;
+ block->Protection_begin.task = _Thread_Executing;
+
+ if ( delayed_free_block_count > 0 ) {
+ Heap_Block *const last = heap->Protection.last_delayed_free_block;
+
+ last->Protection_begin.next_delayed_free_block = block;
+ } else {
+ heap->Protection.first_delayed_free_block = block;
+ }
+ heap->Protection.last_delayed_free_block = block;
+ heap->Protection.delayed_free_block_count = delayed_free_block_count + 1;
+
+ for ( current = pattern_begin; current != pattern_end; ++current ) {
+ *current = HEAP_FREE_PATTERN;
+ }
+ }
+
+ static void _Heap_Protection_check_free_block(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ uintptr_t *const pattern_begin = (uintptr_t *)
+ _Heap_Alloc_area_of_block( block );
+ uintptr_t *const pattern_end = (uintptr_t *)
+ ((uintptr_t) block + _Heap_Block_size( block ) + HEAP_ALLOC_BONUS);
+ uintptr_t *current = NULL;
+
+ for ( current = pattern_begin; current != pattern_end; ++current ) {
+ if ( *current != HEAP_FREE_PATTERN ) {
+ _Heap_Protection_block_error( heap, block );
+ break;
+ }
+ }
+ }
+
+ static bool _Heap_Protection_determine_block_free(
+ Heap_Control *heap,
+ Heap_Block *block
+ )
+ {
+ bool do_free = true;
+
+ /*
+ * Sometimes after a free the allocated area is still in use. An example
+ * is the task stack of a thread that deletes itself. The thread dispatch
+ * disable level is a way to detect this use case.
+ */
+ if ( _Thread_Dispatch_disable_level == 0 ) {
+ Heap_Block *const next = block->Protection_begin.next_delayed_free_block;
+ if ( next == NULL ) {
+ _Heap_Protection_delay_block_free( heap, block );
+ do_free = false;
+ } else if ( next == HEAP_PROTECTION_OBOLUS ) {
+ _Heap_Protection_check_free_block( heap, block );
+ } else {
+ _Heap_Protection_block_error( heap, block );
+ }
+ }
+
+ return do_free;
+ }
+#endif
+
+bool _Heap_Free( Heap_Control *heap, void *alloc_begin_ptr )
+{
+ Heap_Statistics *const stats = &heap->stats;
+ uintptr_t alloc_begin;
+ Heap_Block *block;
+ Heap_Block *next_block = NULL;
+ uintptr_t block_size = 0;
+ uintptr_t next_block_size = 0;
+ bool next_is_free = false;
+
+ /*
+ * If NULL return true so a free on NULL is considered a valid release. This
+ * is a special case that could be handled by the in heap check how-ever that
+ * would result in false being returned which is wrong.
+ */
+ if ( alloc_begin_ptr == NULL ) {
+ return true;
+ }
+
+ alloc_begin = (uintptr_t) alloc_begin_ptr;
+ block = _Heap_Block_of_alloc_area( alloc_begin, heap->page_size );
+
+ if ( !_Heap_Is_block_in_heap( heap, block ) ) {
+ return false;
+ }
+
+ _Heap_Protection_block_check( heap, block );
+
+ block_size = _Heap_Block_size( block );
+ next_block = _Heap_Block_at( block, block_size );
+
+ if ( !_Heap_Is_block_in_heap( heap, next_block ) ) {
+ return false;
+ }
+
+ _Heap_Protection_block_check( heap, next_block );
+
+ if ( !_Heap_Is_prev_used( next_block ) ) {
+ _Heap_Protection_block_error( heap, block );
+ return false;
+ }
+
+ if ( !_Heap_Protection_determine_block_free( heap, block ) ) {
+ return true;
+ }
+
+ next_block_size = _Heap_Block_size( next_block );
+ next_is_free = next_block != heap->last_block
+ && !_Heap_Is_prev_used( _Heap_Block_at( next_block, next_block_size ));
+
+ if ( !_Heap_Is_prev_used( block ) ) {
+ uintptr_t const prev_size = block->prev_size;
+ Heap_Block * const prev_block = _Heap_Block_at( block, -prev_size );
+
+ if ( !_Heap_Is_block_in_heap( heap, prev_block ) ) {
+ _HAssert( false );
+ return( false );
+ }
+
+ /* As we always coalesce free blocks, the block that preceedes prev_block
+ must have been used. */
+ if ( !_Heap_Is_prev_used ( prev_block) ) {
+ _HAssert( false );
+ return( false );
+ }
+
+ if ( next_is_free ) { /* coalesce both */
+ uintptr_t const size = block_size + prev_size + next_block_size;
+ _Heap_Free_list_remove( next_block );
+ stats->free_blocks -= 1;
+ prev_block->size_and_flag = size | HEAP_PREV_BLOCK_USED;
+ next_block = _Heap_Block_at( prev_block, size );
+ _HAssert(!_Heap_Is_prev_used( next_block));
+ next_block->prev_size = size;
+ } else { /* coalesce prev */
+ uintptr_t const size = block_size + prev_size;
+ prev_block->size_and_flag = size | HEAP_PREV_BLOCK_USED;
+ next_block->size_and_flag &= ~HEAP_PREV_BLOCK_USED;
+ next_block->prev_size = size;
+ }
+ } else if ( next_is_free ) { /* coalesce next */
+ uintptr_t const size = block_size + next_block_size;
+ _Heap_Free_list_replace( next_block, block );
+ block->size_and_flag = size | HEAP_PREV_BLOCK_USED;
+ next_block = _Heap_Block_at( block, size );
+ next_block->prev_size = size;
+ } else { /* no coalesce */
+ /* Add 'block' to the head of the free blocks list as it tends to
+ produce less fragmentation than adding to the tail. */
+ _Heap_Free_list_insert_after( _Heap_Free_list_head( heap), block );
+ block->size_and_flag = block_size | HEAP_PREV_BLOCK_USED;
+ next_block->size_and_flag &= ~HEAP_PREV_BLOCK_USED;
+ next_block->prev_size = block_size;
+
+ /* Statistics */
+ ++stats->free_blocks;
+ if ( stats->max_free_blocks < stats->free_blocks ) {
+ stats->max_free_blocks = stats->free_blocks;
+ }
+ }
+
+ /* Statistics */
+ --stats->used_blocks;
+ ++stats->frees;
+ stats->free_size += block_size;
+
+ return( true );
+}
diff --git a/cpukit/score/src/heapgetfreeinfo.c b/cpukit/score/src/heapgetfreeinfo.c
new file mode 100644
index 0000000000..406ed81d39
--- /dev/null
+++ b/cpukit/score/src/heapgetfreeinfo.c
@@ -0,0 +1,54 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2004.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+void _Heap_Get_free_information(
+ Heap_Control *the_heap,
+ Heap_Information *info
+)
+{
+ Heap_Block *the_block;
+ Heap_Block *const tail = _Heap_Free_list_tail(the_heap);
+
+ info->number = 0;
+ info->largest = 0;
+ info->total = 0;
+
+ for(the_block = _Heap_Free_list_first(the_heap);
+ the_block != tail;
+ the_block = the_block->next)
+ {
+ uint32_t const the_size = _Heap_Block_size(the_block);
+
+ /* As we always coalesce free blocks, prev block must have been used. */
+ _HAssert(_Heap_Is_prev_used(the_block));
+
+ info->number++;
+ info->total += the_size;
+ if ( info->largest < the_size )
+ info->largest = the_size;
+ }
+}
diff --git a/cpukit/score/src/heapgetinfo.c b/cpukit/score/src/heapgetinfo.c
new file mode 100644
index 0000000000..bcb5a7f68d
--- /dev/null
+++ b/cpukit/score/src/heapgetinfo.c
@@ -0,0 +1,57 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+void _Heap_Get_information(
+ Heap_Control *the_heap,
+ Heap_Information_block *the_info
+)
+{
+ Heap_Block *the_block = the_heap->first_block;
+ Heap_Block *const end = the_heap->last_block;
+
+ memset(the_info, 0, sizeof(*the_info));
+
+ while ( the_block != end ) {
+ uintptr_t const the_size = _Heap_Block_size(the_block);
+ Heap_Block *const next_block = _Heap_Block_at(the_block, the_size);
+ Heap_Information *info;
+
+ if ( _Heap_Is_prev_used(next_block) )
+ info = &the_info->Used;
+ else
+ info = &the_info->Free;
+
+ info->number++;
+ info->total += the_size;
+ if ( info->largest < the_size )
+ info->largest = the_size;
+
+ the_block = next_block;
+ }
+}
diff --git a/cpukit/score/src/heapresizeblock.c b/cpukit/score/src/heapresizeblock.c
new file mode 100644
index 0000000000..2d3528645f
--- /dev/null
+++ b/cpukit/score/src/heapresizeblock.c
@@ -0,0 +1,119 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2009 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+static Heap_Resize_status _Heap_Resize_block_checked(
+ Heap_Control *heap,
+ Heap_Block *block,
+ uintptr_t alloc_begin,
+ uintptr_t new_alloc_size,
+ uintptr_t *old_size,
+ uintptr_t *new_size
+)
+{
+ Heap_Statistics *const stats = &heap->stats;
+
+ uintptr_t const block_begin = (uintptr_t) block;
+ uintptr_t block_size = _Heap_Block_size( block );
+ uintptr_t block_end = block_begin + block_size;
+
+ uintptr_t alloc_size = block_end - alloc_begin + HEAP_ALLOC_BONUS;
+
+ Heap_Block *next_block = _Heap_Block_at( block, block_size );
+ uintptr_t next_block_size = _Heap_Block_size( next_block );
+ bool next_block_is_free = _Heap_Is_free( next_block );;
+
+ _HAssert( _Heap_Is_block_in_heap( heap, next_block ) );
+ _HAssert( _Heap_Is_prev_used( next_block ) );
+
+ *old_size = alloc_size;
+
+ if ( next_block_is_free ) {
+ block_size += next_block_size;
+ alloc_size += next_block_size;
+ }
+
+ if ( new_alloc_size > alloc_size ) {
+ return HEAP_RESIZE_UNSATISFIED;
+ }
+
+ if ( next_block_is_free ) {
+ _Heap_Block_set_size( block, block_size );
+
+ _Heap_Free_list_remove( next_block );
+
+ next_block = _Heap_Block_at( block, block_size );
+ next_block->size_and_flag |= HEAP_PREV_BLOCK_USED;
+
+ /* Statistics */
+ --stats->free_blocks;
+ stats->free_size -= next_block_size;
+ }
+
+ block = _Heap_Block_allocate( heap, block, alloc_begin, new_alloc_size );
+
+ block_size = _Heap_Block_size( block );
+ next_block = _Heap_Block_at( block, block_size );
+ *new_size = (uintptr_t) next_block - alloc_begin + HEAP_ALLOC_BONUS;
+
+ /* Statistics */
+ ++stats->resizes;
+
+ return HEAP_RESIZE_SUCCESSFUL;
+}
+
+Heap_Resize_status _Heap_Resize_block(
+ Heap_Control *heap,
+ void *alloc_begin_ptr,
+ uintptr_t new_alloc_size,
+ uintptr_t *old_size,
+ uintptr_t *new_size
+)
+{
+ uintptr_t const page_size = heap->page_size;
+
+ uintptr_t const alloc_begin = (uintptr_t) alloc_begin_ptr;
+
+ Heap_Block *const block = _Heap_Block_of_alloc_area( alloc_begin, page_size );
+
+ *old_size = 0;
+ *new_size = 0;
+
+ if ( _Heap_Is_block_in_heap( heap, block ) ) {
+ _Heap_Protection_block_check( heap, block );
+ return _Heap_Resize_block_checked(
+ heap,
+ block,
+ alloc_begin,
+ new_alloc_size,
+ old_size,
+ new_size
+ );
+ }
+ return HEAP_RESIZE_FATAL_ERROR;
+}
diff --git a/cpukit/score/src/heapsizeofuserarea.c b/cpukit/score/src/heapsizeofuserarea.c
new file mode 100644
index 0000000000..0a8b150811
--- /dev/null
+++ b/cpukit/score/src/heapsizeofuserarea.c
@@ -0,0 +1,58 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+
+bool _Heap_Size_of_alloc_area(
+ Heap_Control *heap,
+ void *alloc_begin_ptr,
+ uintptr_t *alloc_size
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const alloc_begin = (uintptr_t) alloc_begin_ptr;
+ Heap_Block *block = _Heap_Block_of_alloc_area( alloc_begin, page_size );
+ Heap_Block *next_block = NULL;
+ uintptr_t block_size = 0;
+
+ if ( !_Heap_Is_block_in_heap( heap, block ) ) {
+ return false;
+ }
+
+ block_size = _Heap_Block_size( block );
+ next_block = _Heap_Block_at( block, block_size );
+
+ if (
+ !_Heap_Is_block_in_heap( heap, next_block )
+ || !_Heap_Is_prev_used( next_block )
+ ) {
+ return false;
+ }
+
+ *alloc_size = (uintptr_t) next_block + HEAP_ALLOC_BONUS - alloc_begin;
+
+ return true;
+}
+
diff --git a/cpukit/score/src/heapwalk.c b/cpukit/score/src/heapwalk.c
new file mode 100644
index 0000000000..fae0bd6330
--- /dev/null
+++ b/cpukit/score/src/heapwalk.c
@@ -0,0 +1,421 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT ( c ) 1989-2007.
+ * On-Line Applications Research Corporation ( OAR ).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/heap.h>
+#include <rtems/score/interr.h>
+#include <rtems/bspIo.h>
+
+typedef void (*Heap_Walk_printer)(int, bool, const char*, ...);
+
+static void _Heap_Walk_print_nothing(
+ int source,
+ bool error,
+ const char *fmt,
+ ...
+)
+{
+ /* Do nothing */
+}
+
+static void _Heap_Walk_print( int source, bool error, const char *fmt, ... )
+{
+ va_list ap;
+
+ if ( error ) {
+ printk( "FAIL[%d]: ", source );
+ } else {
+ printk( "PASS[%d]: ", source );
+ }
+
+ va_start( ap, fmt );
+ vprintk( fmt, ap );
+ va_end( ap );
+}
+
+static bool _Heap_Walk_check_free_list(
+ int source,
+ Heap_Walk_printer printer,
+ Heap_Control *heap
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ const Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
+ const Heap_Block *const first_free_block = _Heap_Free_list_first( heap );
+ const Heap_Block *prev_block = free_list_tail;
+ const Heap_Block *free_block = first_free_block;
+
+ while ( free_block != free_list_tail ) {
+ if ( !_Heap_Is_block_in_heap( heap, free_block ) ) {
+ (*printer)(
+ source,
+ true,
+ "free block 0x%08x: not in heap\n",
+ free_block
+ );
+
+ return false;
+ }
+
+ if (
+ !_Heap_Is_aligned( _Heap_Alloc_area_of_block( free_block ), page_size )
+ ) {
+ (*printer)(
+ source,
+ true,
+ "free block 0x%08x: alloc area not page aligned\n",
+ free_block
+ );
+
+ return false;
+ }
+
+ if ( _Heap_Is_used( free_block ) ) {
+ (*printer)(
+ source,
+ true,
+ "free block 0x%08x: is used\n",
+ free_block
+ );
+
+ return false;
+ }
+
+ if ( free_block->prev != prev_block ) {
+ (*printer)(
+ source,
+ true,
+ "free block 0x%08x: invalid previous block 0x%08x\n",
+ free_block,
+ free_block->prev
+ );
+
+ return false;
+ }
+
+ prev_block = free_block;
+ free_block = free_block->next;
+ }
+
+ return true;
+}
+
+static bool _Heap_Walk_is_in_free_list(
+ Heap_Control *heap,
+ Heap_Block *block
+)
+{
+ const Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
+ const Heap_Block *free_block = _Heap_Free_list_first( heap );
+
+ while ( free_block != free_list_tail ) {
+ if ( free_block == block ) {
+ return true;
+ }
+ free_block = free_block->next;
+ }
+
+ return false;
+}
+
+static bool _Heap_Walk_check_control(
+ int source,
+ Heap_Walk_printer printer,
+ Heap_Control *heap
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const min_block_size = heap->min_block_size;
+ Heap_Block *const first_free_block = _Heap_Free_list_first( heap );
+ Heap_Block *const last_free_block = _Heap_Free_list_last( heap );
+ Heap_Block *const first_block = heap->first_block;
+ Heap_Block *const last_block = heap->last_block;
+
+ (*printer)(
+ source,
+ false,
+ "page size %u, min block size %u\n"
+ "\tarea begin 0x%08x, area end 0x%08x\n"
+ "\tfirst block 0x%08x, last block 0x%08x\n"
+ "\tfirst free 0x%08x, last free 0x%08x\n",
+ page_size, min_block_size,
+ heap->area_begin, heap->area_end,
+ first_block, last_block,
+ first_free_block, last_free_block
+ );
+
+ if ( page_size == 0 ) {
+ (*printer)( source, true, "page size is zero\n" );
+
+ return false;
+ }
+
+ if ( !_Addresses_Is_aligned( (void *) page_size ) ) {
+ (*printer)(
+ source,
+ true,
+ "page size %u not CPU aligned\n",
+ page_size
+ );
+
+ return false;
+ }
+
+ if ( !_Heap_Is_aligned( min_block_size, page_size ) ) {
+ (*printer)(
+ source,
+ true,
+ "min block size %u not page aligned\n",
+ min_block_size
+ );
+
+ return false;
+ }
+
+ if (
+ !_Heap_Is_aligned( _Heap_Alloc_area_of_block( first_block ), page_size )
+ ) {
+ (*printer)(
+ source,
+ true,
+ "first block 0x%08x: alloc area not page aligned\n",
+ first_block
+ );
+
+ return false;
+ }
+
+ if ( !_Heap_Is_prev_used( first_block ) ) {
+ (*printer)(
+ source,
+ true,
+ "first block: HEAP_PREV_BLOCK_USED is cleared\n"
+ );
+
+ return false;
+ }
+
+ if ( _Heap_Is_free( last_block ) ) {
+ (*printer)(
+ source,
+ true,
+ "last block: is free\n"
+ );
+
+ return false;
+ }
+
+ if (
+ _Heap_Block_at( last_block, _Heap_Block_size( last_block ) ) != first_block
+ ) {
+ (*printer)(
+ source,
+ true,
+ "last block: next block is not the first block\n"
+ );
+
+ return false;
+ }
+
+ return _Heap_Walk_check_free_list( source, printer, heap );
+}
+
+static bool _Heap_Walk_check_free_block(
+ int source,
+ Heap_Walk_printer printer,
+ Heap_Control *heap,
+ Heap_Block *block
+)
+{
+ Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
+ Heap_Block *const free_list_head = _Heap_Free_list_head( heap );
+ Heap_Block *const first_free_block = _Heap_Free_list_first( heap );
+ Heap_Block *const last_free_block = _Heap_Free_list_last( heap );
+ bool const prev_used = _Heap_Is_prev_used( block );
+ uintptr_t const block_size = _Heap_Block_size( block );
+ Heap_Block *const next_block = _Heap_Block_at( block, block_size );
+
+ (*printer)(
+ source,
+ false,
+ "block 0x%08x: size %u, prev 0x%08x%s, next 0x%08x%s\n",
+ block,
+ block_size,
+ block->prev,
+ block->prev == first_free_block ?
+ " (= first free)"
+ : (block->prev == free_list_head ? " (= head)" : ""),
+ block->next,
+ block->next == last_free_block ?
+ " (= last free)"
+ : (block->next == free_list_tail ? " (= tail)" : "")
+ );
+
+ if ( block_size != next_block->prev_size ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: size %u != size %u (in next block 0x%08x)\n",
+ block,
+ block_size,
+ next_block->prev_size,
+ next_block
+ );
+
+ return false;
+ }
+
+ if ( !prev_used ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: two consecutive blocks are free\n",
+ block
+ );
+
+ return false;
+ }
+
+ if ( !_Heap_Walk_is_in_free_list( heap, block ) ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: free block not in free list\n",
+ block
+ );
+
+ return false;
+ }
+
+ return true;
+}
+
+bool _Heap_Walk(
+ Heap_Control *heap,
+ int source,
+ bool dump
+)
+{
+ uintptr_t const page_size = heap->page_size;
+ uintptr_t const min_block_size = heap->min_block_size;
+ Heap_Block *const first_block = heap->first_block;
+ Heap_Block *const last_block = heap->last_block;
+ Heap_Block *block = first_block;
+ Heap_Walk_printer printer = dump ?
+ _Heap_Walk_print : _Heap_Walk_print_nothing;
+
+ if ( !_System_state_Is_up( _System_state_Get() ) ) {
+ return true;
+ }
+
+ if ( !_Heap_Walk_check_control( source, printer, heap ) ) {
+ return false;
+ }
+
+ do {
+ uintptr_t const block_begin = (uintptr_t) block;
+ uintptr_t const block_size = _Heap_Block_size( block );
+ bool const prev_used = _Heap_Is_prev_used( block );
+ Heap_Block *const next_block = _Heap_Block_at( block, block_size );
+ uintptr_t const next_block_begin = (uintptr_t) next_block;
+ bool const is_not_last_block = block != last_block;
+
+ if ( !_Heap_Is_block_in_heap( heap, next_block ) ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: next block 0x%08x not in heap\n",
+ block,
+ next_block
+ );
+
+ return false;
+ }
+
+ if ( !_Heap_Is_aligned( block_size, page_size ) && is_not_last_block ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: block size %u not page aligned\n",
+ block,
+ block_size
+ );
+
+ return false;
+ }
+
+ if ( block_size < min_block_size && is_not_last_block ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: size %u < min block size %u\n",
+ block,
+ block_size,
+ min_block_size
+ );
+
+ return false;
+ }
+
+ if ( next_block_begin <= block_begin && is_not_last_block ) {
+ (*printer)(
+ source,
+ true,
+ "block 0x%08x: next block 0x%08x is not a successor\n",
+ block,
+ next_block
+ );
+
+ return false;
+ }
+
+ if ( !_Heap_Is_prev_used( next_block ) ) {
+ if ( !_Heap_Walk_check_free_block( source, printer, heap, block ) ) {
+ return false;
+ }
+ } else if (prev_used) {
+ (*printer)(
+ source,
+ false,
+ "block 0x%08x: size %u\n",
+ block,
+ block_size
+ );
+ } else {
+ (*printer)(
+ source,
+ false,
+ "block 0x%08x: size %u, prev_size %u\n",
+ block,
+ block_size,
+ block->prev_size
+ );
+ }
+
+ block = next_block;
+ } while ( block != first_block );
+
+ return true;
+}
diff --git a/cpukit/score/src/interr.c b/cpukit/score/src/interr.c
new file mode 100644
index 0000000000..cd9e09121e
--- /dev/null
+++ b/cpukit/score/src/interr.c
@@ -0,0 +1,65 @@
+/*
+ * Internal Error Handler
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/userext.h>
+
+/*PAGE
+ *
+ * _Internal_error_Occurred
+ *
+ * This routine will invoke the fatal error handler supplied by the user
+ * followed by the the default one provided by the executive. The default
+ * error handler assumes no hardware is present to help inform the user
+ * of the problem. Halt stores the error code in a known register,
+ * disables interrupts, and halts the CPU. If the CPU does not have a
+ * halt instruction, it will loop to itself.
+ *
+ * Input parameters:
+ * the_source - what subsystem the error originated in
+ * is_internal - if the error was internally generated
+ * the_error - fatal error status code
+ *
+ * Output parameters:
+ * As much information as possible is stored in a CPU dependent fashion.
+ * See the CPU dependent code for more information.
+ *
+ * NOTE: The the_error is not necessarily a directive status code.
+ */
+
+void _Internal_error_Occurred(
+ Internal_errors_Source the_source,
+ bool is_internal,
+ Internal_errors_t the_error
+)
+{
+
+ _Internal_errors_What_happened.the_source = the_source;
+ _Internal_errors_What_happened.is_internal = is_internal;
+ _Internal_errors_What_happened.the_error = the_error;
+
+ _User_extensions_Fatal( the_source, is_internal, the_error );
+
+ _System_state_Set( SYSTEM_STATE_FAILED );
+
+ _CPU_Fatal_halt( the_error );
+
+ /* will not return from this routine */
+ while (true);
+}
diff --git a/cpukit/score/src/isr.c b/cpukit/score/src/isr.c
new file mode 100644
index 0000000000..799bb08dbb
--- /dev/null
+++ b/cpukit/score/src/isr.c
@@ -0,0 +1,83 @@
+/*
+ * ISR Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/stack.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/config.h>
+
+/* _ISR_Handler_initialization
+ *
+ * This routine initializes the ISR handler.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _ISR_Handler_initialization( void )
+{
+ _ISR_Nest_level = 0;
+
+#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
+ _ISR_Vector_table = _Workspace_Allocate_or_fatal_error(
+ sizeof(ISR_Handler_entry) * ISR_NUMBER_OF_VECTORS
+ );
+#endif
+
+ _CPU_Initialize_vectors();
+
+#if ( CPU_ALLOCATE_INTERRUPT_STACK == TRUE )
+
+ if ( !_Stack_Is_enough(Configuration.interrupt_stack_size) )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL
+ );
+
+ _CPU_Interrupt_stack_low = _Workspace_Allocate_or_fatal_error(
+ Configuration.interrupt_stack_size
+ );
+
+ _CPU_Interrupt_stack_high = _Addresses_Add_offset(
+ _CPU_Interrupt_stack_low,
+ Configuration.interrupt_stack_size
+ );
+
+#if (CPU_STACK_ALIGNMENT != 0)
+ _CPU_Interrupt_stack_high = (void *)
+ ((uintptr_t) _CPU_Interrupt_stack_high & ~(CPU_STACK_ALIGNMENT - 1));
+#endif
+
+ /* Interrupt stack might have to be aligned and/or setup
+ * in a specific way.
+ */
+#if defined(_CPU_Interrupt_stack_setup)
+ _CPU_Interrupt_stack_setup(_CPU_Interrupt_stack_low, _CPU_Interrupt_stack_high);
+#endif
+
+#endif
+
+#if ( CPU_HAS_HARDWARE_INTERRUPT_STACK == TRUE )
+ _CPU_Install_interrupt_stack();
+#endif
+
+}
diff --git a/cpukit/score/src/iterateoverthreads.c b/cpukit/score/src/iterateoverthreads.c
new file mode 100644
index 0000000000..8c65becc4c
--- /dev/null
+++ b/cpukit/score/src/iterateoverthreads.c
@@ -0,0 +1,55 @@
+/*
+ * rtems_iterate_over_all_threads
+ *
+ * This function operates by as follows:
+ * for all threads
+ * invoke specified function
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+
+void rtems_iterate_over_all_threads(rtems_per_thread_routine routine)
+{
+ uint32_t i;
+ uint32_t api_index;
+ Thread_Control *the_thread;
+ Objects_Information *information;
+
+ if ( !routine )
+ return;
+
+ for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
+ #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
+ if ( !_Objects_Information_table[ api_index ] )
+ continue;
+ #endif
+
+ information = _Objects_Information_table[ api_index ][ 1 ];
+ if ( !information )
+ continue;
+
+ for ( i=1 ; i <= information->maximum ; i++ ) {
+ the_thread = (Thread_Control *)information->local_table[ i ];
+
+ if ( !the_thread )
+ continue;
+
+ (*routine)(the_thread);
+ }
+ }
+
+}
diff --git a/cpukit/score/src/mpci.c b/cpukit/score/src/mpci.c
new file mode 100644
index 0000000000..d8f68ebc89
--- /dev/null
+++ b/cpukit/score/src/mpci.c
@@ -0,0 +1,540 @@
+/*
+ * Multiprocessing Communications Interface (MPCI) Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#include <rtems/score/mppkt.h>
+#endif
+#include <rtems/config.h>
+#include <rtems/score/cpu.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/sysstate.h>
+
+#include <rtems/score/coresem.h>
+#include <rtems/config.h>
+
+/**
+ * This is the core semaphore which the MPCI Receive Server blocks on.
+ */
+CORE_semaphore_Control _MPCI_Semaphore;
+
+/*PAGE
+ *
+ * _MPCI_Handler_initialization
+ *
+ * This subprogram performs the initialization necessary for this handler.
+ */
+
+void _MPCI_Handler_initialization(
+ uint32_t timeout_status
+)
+{
+ CORE_semaphore_Attributes attributes;
+ MPCI_Control *users_mpci_table;
+
+ users_mpci_table = _Configuration_MP_table->User_mpci_table;
+
+ if ( _System_state_Is_multiprocessing && !users_mpci_table )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_NO_MPCI
+ );
+
+ _MPCI_table = users_mpci_table;
+
+ if ( !_System_state_Is_multiprocessing )
+ return;
+
+ /*
+ * Register the MP Process Packet routine.
+ */
+
+ _MPCI_Register_packet_processor(
+ MP_PACKET_MPCI_INTERNAL,
+ _MPCI_Internal_packets_Process_packet
+ );
+
+ /*
+ * Create the counting semaphore used by the MPCI Receive Server.
+ */
+
+ attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
+
+ _CORE_semaphore_Initialize(
+ &_MPCI_Semaphore,
+ &attributes, /* the_semaphore_attributes */
+ 0 /* initial_value */
+ );
+
+ _Thread_queue_Initialize(
+ &_MPCI_Remote_blocked_threads,
+ THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_RPC_REPLY,
+ timeout_status
+ );
+}
+
+/*PAGE
+ *
+ * _MPCI_Create_server
+ *
+ * This subprogram creates the MPCI receive server.
+ */
+
+void _MPCI_Create_server( void )
+{
+ Objects_Name name;
+
+
+ if ( !_System_state_Is_multiprocessing )
+ return;
+
+ /*
+ * Initialize the MPCI Receive Server
+ */
+
+ _MPCI_Receive_server_tcb = _Thread_Internal_allocate();
+
+ name.name_u32 = _Objects_Build_name( 'M', 'P', 'C', 'I' );
+ _Thread_Initialize(
+ &_Thread_Internal_information,
+ _MPCI_Receive_server_tcb,
+ NULL, /* allocate the stack */
+ _Stack_Minimum() +
+ CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK +
+ _Configuration_MP_table->extra_mpci_receive_server_stack,
+ CPU_ALL_TASKS_ARE_FP,
+ PRIORITY_MINIMUM,
+ false, /* no preempt */
+ THREAD_CPU_BUDGET_ALGORITHM_NONE,
+ NULL, /* no budget algorithm callout */
+ 0, /* all interrupts enabled */
+ name
+ );
+
+ _Thread_Start(
+ _MPCI_Receive_server_tcb,
+ THREAD_START_NUMERIC,
+ (void *) _MPCI_Receive_server,
+ NULL,
+ 0
+ );
+}
+
+/*PAGE
+ *
+ * _MPCI_Initialization
+ *
+ * This subprogram initializes the MPCI driver by
+ * invoking the user provided MPCI initialization callout.
+ */
+
+void _MPCI_Initialization ( void )
+{
+ (*_MPCI_table->initialization)();
+}
+
+/*PAGE
+ *
+ * _MPCI_Register_packet_processor
+ *
+ * This routine registers the MPCI packet processor for the
+ * designated object class.
+ */
+
+void _MPCI_Register_packet_processor(
+ MP_packet_Classes the_class,
+ MPCI_Packet_processor the_packet_processor
+
+)
+{
+ _MPCI_Packet_processors[ the_class ] = the_packet_processor;
+}
+
+/*PAGE
+ *
+ * _MPCI_Get_packet
+ *
+ * This subprogram obtains a packet by invoking the user provided
+ * MPCI get packet callout.
+ */
+
+MP_packet_Prefix *_MPCI_Get_packet ( void )
+{
+ MP_packet_Prefix *the_packet;
+
+ (*_MPCI_table->get_packet)( &the_packet );
+
+ if ( the_packet == NULL )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_OUT_OF_PACKETS
+ );
+
+ /*
+ * Put in a default timeout that will be used for
+ * all packets that do not otherwise have a timeout.
+ */
+
+ the_packet->timeout = MPCI_DEFAULT_TIMEOUT;
+
+ return the_packet;
+}
+
+/*PAGE
+ *
+ * _MPCI_Return_packet
+ *
+ * This subprogram returns a packet by invoking the user provided
+ * MPCI return packet callout.
+ */
+
+void _MPCI_Return_packet (
+ MP_packet_Prefix *the_packet
+)
+{
+ (*_MPCI_table->return_packet)( the_packet );
+}
+
+/*PAGE
+ *
+ * _MPCI_Send_process_packet
+ *
+ * This subprogram sends a process packet by invoking the user provided
+ * MPCI send callout.
+ */
+
+void _MPCI_Send_process_packet (
+ uint32_t destination,
+ MP_packet_Prefix *the_packet
+)
+{
+ the_packet->source_tid = _Thread_Executing->Object.id;
+ the_packet->to_convert =
+ ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
+
+ (*_MPCI_table->send_packet)( destination, the_packet );
+}
+
+/*PAGE
+ *
+ * _MPCI_Send_request_packet
+ *
+ * This subprogram sends a request packet by invoking the user provided
+ * MPCI send callout.
+ */
+
+uint32_t _MPCI_Send_request_packet (
+ uint32_t destination,
+ MP_packet_Prefix *the_packet,
+ States_Control extra_state
+)
+{
+ the_packet->source_tid = _Thread_Executing->Object.id;
+ the_packet->source_priority = _Thread_Executing->current_priority;
+ the_packet->to_convert =
+ ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
+
+ _Thread_Executing->Wait.id = the_packet->id;
+
+ _Thread_Executing->Wait.queue = &_MPCI_Remote_blocked_threads;
+
+ _Thread_Disable_dispatch();
+
+ (*_MPCI_table->send_packet)( destination, the_packet );
+
+ _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads );
+
+ /*
+ * See if we need a default timeout
+ */
+
+ if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
+ the_packet->timeout = _MPCI_table->default_timeout;
+
+ _Thread_queue_Enqueue( &_MPCI_Remote_blocked_threads, the_packet->timeout );
+
+ _Thread_Executing->current_state =
+ _States_Set( extra_state, _Thread_Executing->current_state );
+
+ _Thread_Enable_dispatch();
+
+ return _Thread_Executing->Wait.return_code;
+}
+
+/*PAGE
+ *
+ * _MPCI_Send_response_packet
+ *
+ * This subprogram sends a response packet by invoking the user provided
+ * MPCI send callout.
+ */
+
+void _MPCI_Send_response_packet (
+ uint32_t destination,
+ MP_packet_Prefix *the_packet
+)
+{
+ the_packet->source_tid = _Thread_Executing->Object.id;
+
+ (*_MPCI_table->send_packet)( destination, the_packet );
+}
+
+/*PAGE
+ *
+ * _MPCI_Receive_packet
+ *
+ * This subprogram receives a packet by invoking the user provided
+ * MPCI receive callout.
+ */
+
+MP_packet_Prefix *_MPCI_Receive_packet ( void )
+{
+ MP_packet_Prefix *the_packet;
+
+ (*_MPCI_table->receive_packet)( &the_packet );
+
+ return the_packet;
+}
+
+/*PAGE
+ *
+ * _MPCI_Process_response
+ *
+ * This subprogram obtains a packet by invoking the user provided
+ * MPCI get packet callout.
+ */
+
+Thread_Control *_MPCI_Process_response (
+ MP_packet_Prefix *the_packet
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( the_packet->id, &location );
+ switch ( location ) {
+ case OBJECTS_ERROR:
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+#endif
+ the_thread = NULL; /* IMPOSSIBLE */
+ break;
+ case OBJECTS_LOCAL:
+ _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread );
+ the_thread->Wait.return_code = the_packet->return_code;
+ _Thread_Unnest_dispatch();
+ break;
+ }
+
+ return the_thread;
+}
+
+/*PAGE
+ *
+ * _MPCI_Receive_server
+ *
+ */
+
+Thread _MPCI_Receive_server(
+ uint32_t ignored
+)
+{
+
+ MP_packet_Prefix *the_packet;
+ MPCI_Packet_processor the_function;
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+
+ for ( ; ; ) {
+
+ executing->receive_packet = NULL;
+
+ _Thread_Disable_dispatch();
+ _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, true, WATCHDOG_NO_TIMEOUT );
+ _Thread_Enable_dispatch();
+
+ for ( ; ; ) {
+ the_packet = _MPCI_Receive_packet();
+
+ if ( !the_packet )
+ break;
+
+ executing->receive_packet = the_packet;
+
+ if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
+ break;
+
+ the_function = _MPCI_Packet_processors[ the_packet->the_class ];
+
+ if ( !the_function )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_BAD_PACKET
+ );
+
+ (*the_function)( the_packet );
+ }
+ }
+
+ return 0; /* unreached - only to remove warnings */
+}
+
+/*PAGE
+ *
+ * _MPCI_Announce
+ *
+ */
+
+void _MPCI_Announce ( void )
+{
+ _Thread_Disable_dispatch();
+ (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
+ _Thread_Enable_dispatch();
+}
+
+/*PAGE
+ *
+ * _MPCI_Internal_packets_Send_process_packet
+ *
+ */
+
+void _MPCI_Internal_packets_Send_process_packet (
+ MPCI_Internal_Remote_operations operation
+)
+{
+ MPCI_Internal_packet *the_packet;
+
+ switch ( operation ) {
+
+ case MPCI_PACKETS_SYSTEM_VERIFY:
+
+ the_packet = _MPCI_Internal_packets_Get_packet();
+ the_packet->Prefix.the_class = MP_PACKET_MPCI_INTERNAL;
+ the_packet->Prefix.length = sizeof ( MPCI_Internal_packet );
+ the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
+ the_packet->operation = operation;
+
+ the_packet->maximum_nodes = _Objects_Maximum_nodes;
+
+ the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
+
+ _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _MPCI_Internal_packets_Send_request_packet
+ *
+ * This subprogram is not needed since there are no request
+ * packets to be sent by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _MPCI_Internal_packets_Send_response_packet
+ *
+ * This subprogram is not needed since there are no response
+ * packets to be sent by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ *
+ * _MPCI_Internal_packets_Process_packet
+ *
+ */
+
+void _MPCI_Internal_packets_Process_packet (
+ MP_packet_Prefix *the_packet_prefix
+)
+{
+ MPCI_Internal_packet *the_packet;
+ uint32_t maximum_nodes;
+ uint32_t maximum_global_objects;
+
+ the_packet = (MPCI_Internal_packet *) the_packet_prefix;
+
+ switch ( the_packet->operation ) {
+
+ case MPCI_PACKETS_SYSTEM_VERIFY:
+
+ maximum_nodes = the_packet->maximum_nodes;
+ maximum_global_objects = the_packet->maximum_global_objects;
+ if ( maximum_nodes != _Objects_Maximum_nodes ||
+ maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
+
+ _MPCI_Return_packet( the_packet_prefix );
+
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
+ );
+ }
+
+ _MPCI_Return_packet( the_packet_prefix );
+
+ break;
+ }
+}
+
+/*PAGE
+ *
+ * _MPCI_Internal_packets_Send_object_was_deleted
+ *
+ * This subprogram is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _MPCI_Internal_packets_Send_extract_proxy
+ *
+ * This subprogram is not needed since there are no objects
+ * deleted by this manager.
+ *
+ */
+
+/*PAGE
+ *
+ * _MPCI_Internal_packets_Get_packet
+ *
+ */
+
+MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
+{
+ return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
+}
+
+/* end of file */
diff --git a/cpukit/score/src/objectallocate.c b/cpukit/score/src/objectallocate.c
new file mode 100644
index 0000000000..ac98945a74
--- /dev/null
+++ b/cpukit/score/src/objectallocate.c
@@ -0,0 +1,102 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/* #define RTEMS_DEBUG_OBJECT_ALLOCATION */
+
+#if defined(RTEMS_DEBUG_OBJECT_ALLOCATION)
+#include <rtems/bspIo.h>
+#endif
+
+/*PAGE
+ *
+ * _Objects_Allocate
+ *
+ * DESCRIPTION:
+ *
+ * This function allocates a object control block from
+ * the inactive chain of free object control blocks.
+ */
+
+Objects_Control *_Objects_Allocate(
+ Objects_Information *information
+)
+{
+ Objects_Control *the_object;
+
+ /*
+ * If the application is using the optional manager stubs and
+ * still attempts to create the object, the information block
+ * should be all zeroed out because it is in the BSS. So let's
+ * check that code for this manager is even present.
+ */
+ if ( information->size == 0 )
+ return NULL;
+
+ /*
+ * OK. The manager should be initialized and configured to have objects.
+ * With any luck, it is safe to attempt to allocate an object.
+ */
+ the_object = (Objects_Control *) _Chain_Get( &information->Inactive );
+
+ if ( information->auto_extend ) {
+ /*
+ * If the list is empty then we are out of objects and need to
+ * extend information base.
+ */
+
+ if ( !the_object ) {
+ _Objects_Extend_information( information );
+ the_object = (Objects_Control *) _Chain_Get( &information->Inactive );
+ }
+
+ if ( the_object ) {
+ uint32_t block;
+
+ block = (uint32_t) _Objects_Get_index( the_object->id ) -
+ _Objects_Get_index( information->minimum_id );
+ block /= information->allocation_size;
+
+ information->inactive_per_block[ block ]--;
+ information->inactive--;
+ }
+ }
+
+#if defined(RTEMS_DEBUG_OBJECT_ALLOCATION)
+ if ( !the_object ) {
+ printk(
+ "OBJECT ALLOCATION FAILURE! API/Class %d/%d\n",
+ information->the_api,
+ information->the_class
+ );
+ }
+#endif
+
+ return the_object;
+}
diff --git a/cpukit/score/src/objectapimaximumclass.c b/cpukit/score/src/objectapimaximumclass.c
new file mode 100644
index 0000000000..bb61371278
--- /dev/null
+++ b/cpukit/score/src/objectapimaximumclass.c
@@ -0,0 +1,36 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+
+unsigned int _Objects_API_maximum_class(
+ uint32_t api
+)
+{
+ switch (api) {
+ case OBJECTS_INTERNAL_API:
+ return OBJECTS_INTERNAL_CLASSES_LAST;
+ case OBJECTS_CLASSIC_API:
+ return OBJECTS_RTEMS_CLASSES_LAST;
+ case OBJECTS_POSIX_API:
+ return OBJECTS_POSIX_CLASSES_LAST;
+ case OBJECTS_NO_API:
+ default:
+ break;
+ }
+ return 0;
+}
+
diff --git a/cpukit/score/src/objectclose.c b/cpukit/score/src/objectclose.c
new file mode 100644
index 0000000000..1ed76b7fbe
--- /dev/null
+++ b/cpukit/score/src/objectclose.c
@@ -0,0 +1,28 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/wkspace.h>
+
+void _Objects_Close(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ _Objects_Invalidate_Id( information, the_object );
+
+ _Objects_Namespace_remove( information, the_object );
+}
diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c
new file mode 100644
index 0000000000..0839e0f6be
--- /dev/null
+++ b/cpukit/score/src/objectextendinformation.c
@@ -0,0 +1,266 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+#include <string.h> /* for memcpy() */
+
+/*PAGE
+ *
+ * _Objects_Extend_information
+ *
+ * This routine extends all object information related data structures.
+ *
+ * Input parameters:
+ * information - object information table
+ *
+ * Output parameters: NONE
+ */
+
+void _Objects_Extend_information(
+ Objects_Information *information
+)
+{
+ Objects_Control *the_object;
+ Chain_Control Inactive;
+ uint32_t block_count;
+ uint32_t block;
+ uint32_t index_base;
+ uint32_t minimum_index;
+ uint32_t index;
+ uint32_t maximum;
+ size_t block_size;
+ void *new_object_block;
+ bool do_extend;
+
+ /*
+ * Search for a free block of indexes. If we do NOT need to allocate or
+ * extend the block table, then we will change do_extend.
+ */
+ do_extend = true;
+ minimum_index = _Objects_Get_index( information->minimum_id );
+ index_base = minimum_index;
+ block = 0;
+
+ /* if ( information->maximum < minimum_index ) */
+ if ( information->object_blocks == NULL )
+ block_count = 0;
+ else {
+ block_count = information->maximum / information->allocation_size;
+
+ for ( ; block < block_count; block++ ) {
+ if ( information->object_blocks[ block ] == NULL ) {
+ do_extend = false;
+ break;
+ } else
+ index_base += information->allocation_size;
+ }
+ }
+
+ maximum = (uint32_t) information->maximum + information->allocation_size;
+
+ /*
+ * We need to limit the number of objects to the maximum number
+ * representable in the index portion of the object Id. In the
+ * case of 16-bit Ids, this is only 256 object instances.
+ */
+ if ( maximum > OBJECTS_ID_FINAL_INDEX ) {
+ return;
+ }
+
+ /*
+ * Allocate the name table, and the objects and if it fails either return or
+ * generate a fatal error depending on auto-extending being active.
+ */
+ block_size = information->allocation_size * information->size;
+ if ( information->auto_extend ) {
+ new_object_block = _Workspace_Allocate( block_size );
+ if ( !new_object_block )
+ return;
+ } else {
+ new_object_block = _Workspace_Allocate_or_fatal_error( block_size );
+ }
+
+ /*
+ * Do we need to grow the tables?
+ */
+ if ( do_extend ) {
+ ISR_Level level;
+ void **object_blocks;
+ uint32_t *inactive_per_block;
+ Objects_Control **local_table;
+ void *old_tables;
+ size_t block_size;
+
+ /*
+ * Growing the tables means allocating a new area, doing a copy and
+ * updating the information table.
+ *
+ * If the maximum is minimum we do not have a table to copy. First
+ * time through.
+ *
+ * The allocation has :
+ *
+ * void *objects[block_count];
+ * uint32_t inactive_count[block_count];
+ * Objects_Control *local_table[maximum];
+ *
+ * This is the order in memory. Watch changing the order. See the memcpy
+ * below.
+ */
+
+ /*
+ * Up the block count and maximum
+ */
+ block_count++;
+
+ /*
+ * Allocate the tables and break it up.
+ */
+ block_size = block_count *
+ (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) +
+ ((maximum + minimum_index) * sizeof(Objects_Control *));
+ object_blocks = (void**) _Workspace_Allocate( block_size );
+
+ if ( !object_blocks ) {
+ _Workspace_Free( new_object_block );
+ return;
+ }
+
+ /*
+ * Break the block into the various sections.
+ */
+ inactive_per_block = (uint32_t *) _Addresses_Add_offset(
+ object_blocks, block_count * sizeof(void*) );
+ local_table = (Objects_Control **) _Addresses_Add_offset(
+ inactive_per_block, block_count * sizeof(uint32_t) );
+
+ /*
+ * Take the block count down. Saves all the (block_count - 1)
+ * in the copies.
+ */
+ block_count--;
+
+ if ( information->maximum > minimum_index ) {
+
+ /*
+ * Copy each section of the table over. This has to be performed as
+ * separate parts as size of each block has changed.
+ */
+
+ memcpy( object_blocks,
+ information->object_blocks,
+ block_count * sizeof(void*) );
+ memcpy( inactive_per_block,
+ information->inactive_per_block,
+ block_count * sizeof(uint32_t) );
+ memcpy( local_table,
+ information->local_table,
+ (information->maximum + minimum_index) * sizeof(Objects_Control *) );
+ } else {
+
+ /*
+ * Deal with the special case of the 0 to minimum_index
+ */
+ for ( index = 0; index < minimum_index; index++ ) {
+ local_table[ index ] = NULL;
+ }
+ }
+
+ /*
+ * Initialise the new entries in the table.
+ */
+ object_blocks[block_count] = NULL;
+ inactive_per_block[block_count] = 0;
+
+ for ( index=index_base ;
+ index < ( information->allocation_size + index_base );
+ index++ ) {
+ local_table[ index ] = NULL;
+ }
+
+ _ISR_Disable( level );
+
+ old_tables = information->object_blocks;
+
+ information->object_blocks = object_blocks;
+ information->inactive_per_block = inactive_per_block;
+ information->local_table = local_table;
+ information->maximum = (Objects_Maximum) maximum;
+ information->maximum_id = _Objects_Build_id(
+ information->the_api,
+ information->the_class,
+ _Objects_Local_node,
+ information->maximum
+ );
+
+ _ISR_Enable( level );
+
+ _Workspace_Free( old_tables );
+
+ block_count++;
+ }
+
+ /*
+ * Assign the new object block to the object block table.
+ */
+ information->object_blocks[ block ] = new_object_block;
+
+ /*
+ * Initialize objects .. add to a local chain first.
+ */
+ _Chain_Initialize(
+ &Inactive,
+ information->object_blocks[ block ],
+ information->allocation_size,
+ information->size
+ );
+
+ /*
+ * Move from the local chain, initialise, then append to the inactive chain
+ */
+ index = index_base;
+
+ while ((the_object = (Objects_Control *) _Chain_Get( &Inactive )) != NULL ) {
+
+ the_object->id = _Objects_Build_id(
+ information->the_api,
+ information->the_class,
+ _Objects_Local_node,
+ index
+ );
+
+ _Chain_Append( &information->Inactive, &the_object->Node );
+
+ index++;
+ }
+
+ information->inactive_per_block[ block ] = information->allocation_size;
+ information->inactive =
+ (Objects_Maximum)(information->inactive + information->allocation_size);
+}
diff --git a/cpukit/score/src/objectfree.c b/cpukit/score/src/objectfree.c
new file mode 100644
index 0000000000..f74394d0fa
--- /dev/null
+++ b/cpukit/score/src/objectfree.c
@@ -0,0 +1,69 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Free
+ *
+ * DESCRIPTION:
+ *
+ * This function frees a object control block to the
+ * inactive chain of free object control blocks.
+ */
+
+void _Objects_Free(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ uint32_t allocation_size = information->allocation_size;
+
+ _Chain_Append( &information->Inactive, &the_object->Node );
+
+ if ( information->auto_extend ) {
+ uint32_t block;
+
+ block = (uint32_t) (_Objects_Get_index( the_object->id ) -
+ _Objects_Get_index( information->minimum_id ));
+ block /= information->allocation_size;
+
+ information->inactive_per_block[ block ]++;
+ information->inactive++;
+
+ /*
+ * Check if the threshold level has been met of
+ * 1.5 x allocation_size are free.
+ */
+
+ if ( information->inactive > ( allocation_size + ( allocation_size >> 1 ) ) ) {
+ _Objects_Shrink_information( information );
+ }
+ }
+}
diff --git a/cpukit/score/src/objectget.c b/cpukit/score/src/objectget.c
new file mode 100644
index 0000000000..2abcc389fb
--- /dev/null
+++ b/cpukit/score/src/objectget.c
@@ -0,0 +1,108 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Get
+ *
+ * This routine sets the object pointer for the given
+ * object id based on the given object information structure.
+ *
+ * Input parameters:
+ * information - pointer to entry in table for this class
+ * id - object id to search for
+ * location - address of where to store the location
+ *
+ * Output parameters:
+ * returns - address of object if local
+ * location - one of the following:
+ * OBJECTS_ERROR - invalid object ID
+ * OBJECTS_REMOTE - remote object
+ * OBJECTS_LOCAL - local object
+ */
+
+Objects_Control *_Objects_Get(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ Objects_Control *the_object;
+ uint32_t index;
+
+ /*
+ * Extract the index portion of an Id in a way that produces a valid
+ * index for objects within this class and an invalid value for objects
+ * outside this class.
+ *
+ * If the Id matches the api, class, and node but index portion is 0,
+ * then the subtraction will underflow and the addition of 1 will
+ * result in a 0 index. The zeroth element in the local_table is
+ * always NULL.
+ *
+ * If the Id is valid but the object has not been created yet, then
+ * the local_table entry will be NULL.
+ */
+ index = id - information->minimum_id + 1;
+
+ /*
+ * If the index is less than maximum, then it is OK to use it to
+ * index into the local_table array.
+ */
+ if ( index <= information->maximum ) {
+ _Thread_Disable_dispatch();
+ if ( (the_object = information->local_table[ index ]) != NULL ) {
+ *location = OBJECTS_LOCAL;
+ return the_object;
+ }
+
+ /*
+ * Valid Id for this API, Class and Node but the object has not
+ * been allocated yet.
+ */
+ _Thread_Enable_dispatch();
+ *location = OBJECTS_ERROR;
+ return NULL;
+ }
+
+ /*
+ * Object Id is not within this API and Class on this node. So
+ * it may be global in a multiprocessing system. But it is clearly
+ * invalid on a single processor system.
+ */
+ *location = OBJECTS_ERROR;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _Objects_MP_Is_remote( information, id, location, &the_object );
+ return the_object;
+#else
+ return NULL;
+#endif
+}
diff --git a/cpukit/score/src/objectgetinfo.c b/cpukit/score/src/objectgetinfo.c
new file mode 100644
index 0000000000..da3e79713e
--- /dev/null
+++ b/cpukit/score/src/objectgetinfo.c
@@ -0,0 +1,62 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+Objects_Information *_Objects_Get_information(
+ Objects_APIs the_api,
+ uint16_t the_class
+)
+{
+ Objects_Information *info;
+ int the_class_api_maximum;
+
+ if ( !the_class )
+ return NULL;
+
+ /*
+ * This call implicitly validates the_api so we do not call
+ * _Objects_Is_api_valid above here.
+ */
+ the_class_api_maximum = _Objects_API_maximum_class( the_api );
+ if ( the_class_api_maximum == 0 )
+ return NULL;
+
+ if ( the_class > (uint32_t) the_class_api_maximum )
+ return NULL;
+
+ if ( !_Objects_Information_table[ the_api ] )
+ return NULL;
+
+ info = _Objects_Information_table[ the_api ][ the_class ];
+ if ( !info )
+ return NULL;
+
+ /*
+ * In a multprocessing configuration, we may access remote objects.
+ * Thus we may have 0 local instances and still have a valid object
+ * pointer.
+ */
+ #if !defined(RTEMS_MULTIPROCESSING)
+ if ( info->maximum == 0 )
+ return NULL;
+ #endif
+
+ return info;
+}
+
diff --git a/cpukit/score/src/objectgetinfoid.c b/cpukit/score/src/objectgetinfoid.c
new file mode 100644
index 0000000000..729135a9dc
--- /dev/null
+++ b/cpukit/score/src/objectgetinfoid.c
@@ -0,0 +1,28 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+
+Objects_Information *_Objects_Get_information_id(
+ Objects_Id id
+)
+{
+ return _Objects_Get_information(
+ _Objects_Get_API( id ),
+ _Objects_Get_class( id )
+ );
+}
diff --git a/cpukit/score/src/objectgetisr.c b/cpukit/score/src/objectgetisr.c
new file mode 100644
index 0000000000..aca5f0d059
--- /dev/null
+++ b/cpukit/score/src/objectgetisr.c
@@ -0,0 +1,86 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Get_isr_disable
+ *
+ * This routine sets the object pointer for the given
+ * object id based on the given object information structure.
+ *
+ * Input parameters:
+ * information - pointer to entry in table for this class
+ * id - object id to search for
+ * location - address of where to store the location
+ * level - pointer to previous interrupt level
+ *
+ * Output parameters:
+ * returns - address of object if local
+ * location - one of the following:
+ * OBJECTS_ERROR - invalid object ID
+ * OBJECTS_REMOTE - remote object
+ * OBJECTS_LOCAL - local object
+ * *level - previous interrupt level
+ */
+
+Objects_Control *_Objects_Get_isr_disable(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location,
+ ISR_Level *level_p
+)
+{
+ Objects_Control *the_object;
+ uint32_t index;
+ ISR_Level level;
+
+ index = id - information->minimum_id + 1;
+
+ _ISR_Disable( level );
+ if ( information->maximum >= index ) {
+ if ( (the_object = information->local_table[ index ]) != NULL ) {
+ *location = OBJECTS_LOCAL;
+ *level_p = level;
+ return the_object;
+ }
+ _ISR_Enable( level );
+ *location = OBJECTS_ERROR;
+ return NULL;
+ }
+ _ISR_Enable( level );
+ *location = OBJECTS_ERROR;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ _Objects_MP_Is_remote( information, id, location, &the_object );
+ return the_object;
+#else
+ return NULL;
+#endif
+}
diff --git a/cpukit/score/src/objectgetnameasstring.c b/cpukit/score/src/objectgetnameasstring.c
new file mode 100644
index 0000000000..4c15cd9811
--- /dev/null
+++ b/cpukit/score/src/objectgetnameasstring.c
@@ -0,0 +1,96 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+/*
+ * This method objects the name of an object and returns its name
+ * in the form of a C string. It attempts to be careful about
+ * overflowing the user's string and about returning unprintable characters.
+ */
+
+char *_Objects_Get_name_as_string(
+ Objects_Id id,
+ size_t length,
+ char *name
+)
+{
+ Objects_Information *information;
+ const char *s;
+ char *d;
+ uint32_t i;
+ char lname[5];
+ Objects_Control *the_object;
+ Objects_Locations location;
+ Objects_Id tmpId;
+
+ if ( length == 0 )
+ return NULL;
+
+ if ( name == NULL )
+ return NULL;
+
+ tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id;
+
+ information = _Objects_Get_information_id( tmpId );
+ if ( !information )
+ return NULL;
+
+ the_object = _Objects_Get( information, tmpId, &location );
+ switch ( location ) {
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE:
+ /* not supported */
+#endif
+ case OBJECTS_ERROR:
+ return NULL;
+
+ case OBJECTS_LOCAL:
+
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ if ( information->is_string ) {
+ s = the_object->name.name_p;
+ } else
+ #endif
+ {
+ uint32_t u32_name = (uint32_t) the_object->name.name_u32;
+
+ lname[ 0 ] = (u32_name >> 24) & 0xff;
+ lname[ 1 ] = (u32_name >> 16) & 0xff;
+ lname[ 2 ] = (u32_name >> 8) & 0xff;
+ lname[ 3 ] = (u32_name >> 0) & 0xff;
+ lname[ 4 ] = '\0';
+ s = lname;
+ }
+
+ d = name;
+ if ( s ) {
+ for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
+ *d = (isprint((unsigned char)*s)) ? *s : '*';
+ }
+ }
+ *d = '\0';
+
+ _Thread_Enable_dispatch();
+ return name;
+ }
+ return NULL; /* unreachable path */
+}
diff --git a/cpukit/score/src/objectgetnext.c b/cpukit/score/src/objectgetnext.c
new file mode 100644
index 0000000000..206dbf3134
--- /dev/null
+++ b/cpukit/score/src/objectgetnext.c
@@ -0,0 +1,103 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Get_next
+ *
+ * Like _Objects_Get, but considers the 'id' as a "hint" and
+ * finds next valid one after that point.
+ * Mostly used for monitor and debug traversal of an object.
+ *
+ * Input parameters:
+ * information - pointer to entry in table for this class
+ * id - object id to search for
+ * location - address of where to store the location
+ * next_id - address to store next id to try
+ *
+ * Output parameters:
+ * returns - address of object if local
+ * location - one of the following:
+ * OBJECTS_ERROR - invalid object ID
+ * OBJECTS_REMOTE - remote object
+ * OBJECTS_LOCAL - local object
+ * next_id - will contain a reasonable "next" id to continue traversal
+ *
+ * NOTE:
+ * assumes can add '1' to an id to get to next index.
+ */
+
+Objects_Control *
+_Objects_Get_next(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location_p,
+ Objects_Id *next_id_p
+)
+{
+ Objects_Control *object;
+ Objects_Id next_id;
+
+ if ( !information )
+ return NULL;
+
+ if ( !location_p )
+ return NULL;
+
+ if ( !next_id_p )
+ return NULL;
+
+ if (_Objects_Get_index(id) == OBJECTS_ID_INITIAL_INDEX)
+ next_id = information->minimum_id;
+ else
+ next_id = id;
+
+ do {
+ /* walked off end of list? */
+ if (_Objects_Get_index(next_id) > information->maximum)
+ {
+ *location_p = OBJECTS_ERROR;
+ goto final;
+ }
+
+ /* try to grab one */
+ object = _Objects_Get(information, next_id, location_p);
+
+ next_id++;
+
+ } while (*location_p != OBJECTS_LOCAL);
+
+ *next_id_p = next_id;
+ return object;
+
+final:
+ *next_id_p = OBJECTS_ID_FINAL;
+ return 0;
+}
diff --git a/cpukit/score/src/objectgetnoprotection.c b/cpukit/score/src/objectgetnoprotection.c
new file mode 100644
index 0000000000..d969477747
--- /dev/null
+++ b/cpukit/score/src/objectgetnoprotection.c
@@ -0,0 +1,79 @@
+/*
+ * Object Handler -- Object Get
+ *
+ *
+ * COPYRIGHT (c) 1989-2002.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Get_no_protection
+ *
+ * This routine sets the object pointer for the given
+ * object id based on the given object information structure.
+ *
+ * Input parameters:
+ * information - pointer to entry in table for this class
+ * id - object id to search for
+ * location - address of where to store the location
+ *
+ * Output parameters:
+ * returns - address of object if local
+ * location - one of the following:
+ * OBJECTS_ERROR - invalid object ID
+ * OBJECTS_REMOTE - remote object
+ * OBJECTS_LOCAL - local object
+ */
+
+Objects_Control *_Objects_Get_no_protection(
+ Objects_Information *information,
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ Objects_Control *the_object;
+ uint32_t index;
+
+ /*
+ * You can't just extract the index portion or you can get tricked
+ * by a value between 1 and maximum.
+ */
+ index = id - information->minimum_id + 1;
+
+ if ( information->maximum >= index ) {
+ if ( (the_object = information->local_table[ index ]) != NULL ) {
+ *location = OBJECTS_LOCAL;
+ return the_object;
+ }
+ }
+
+ /*
+ * This isn't supported or required yet for Global objects so
+ * if it isn't local, we don't find it.
+ */
+ *location = OBJECTS_ERROR;
+ return NULL;
+}
diff --git a/cpukit/score/src/objectidtoname.c b/cpukit/score/src/objectidtoname.c
new file mode 100644
index 0000000000..870d424986
--- /dev/null
+++ b/cpukit/score/src/objectidtoname.c
@@ -0,0 +1,79 @@
+/*
+ * Obtain Object Name Given ID
+ *
+ *
+ * COPYRIGHT (c) 1989-2003.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+
+/*
+ * _Objects_Id_to_name
+ *
+ * DESCRIPTION:
+ *
+ * This routine returns the name associated with the given ID.
+ *
+ * INPUT:
+ *
+ * id - id of object to lookup name
+ * name - pointer to location in which to store name
+ *
+ */
+Objects_Name_or_id_lookup_errors _Objects_Id_to_name (
+ Objects_Id id,
+ Objects_Name *name
+)
+{
+ uint32_t the_api;
+ uint32_t the_class;
+ Objects_Id tmpId;
+ Objects_Information *information;
+ Objects_Control *the_object = (Objects_Control *) 0;
+ Objects_Locations ignored_location;
+
+ /*
+ * Caller is trusted for name != NULL.
+ */
+
+ tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id;
+
+ the_api = _Objects_Get_API( tmpId );
+ if ( !_Objects_Is_api_valid( the_api ) )
+ return OBJECTS_INVALID_ID;
+
+ if ( !_Objects_Information_table[ the_api ] )
+ return OBJECTS_INVALID_ID;
+
+ the_class = _Objects_Get_class( tmpId );
+
+ information = _Objects_Information_table[ the_api ][ the_class ];
+ if ( !information )
+ return OBJECTS_INVALID_ID;
+
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ if ( information->is_string )
+ return OBJECTS_INVALID_ID;
+ #endif
+
+ the_object = _Objects_Get( information, tmpId, &ignored_location );
+ if ( !the_object )
+ return OBJECTS_INVALID_ID;
+
+ *name = the_object->name;
+ _Thread_Enable_dispatch();
+ return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;
+}
diff --git a/cpukit/score/src/objectinitializeinformation.c b/cpukit/score/src/objectinitializeinformation.c
new file mode 100644
index 0000000000..b59b64ae97
--- /dev/null
+++ b/cpukit/score/src/objectinitializeinformation.c
@@ -0,0 +1,178 @@
+/*
+ * Object Handler Initialization per Object Class
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Initialize_information
+ *
+ * This routine initializes all object information related data structures.
+ *
+ * Input parameters:
+ * information - object information table
+ * maximum - maximum objects of this class
+ * size - size of this object's control block
+ * is_string - true if names for this object are strings
+ * maximum_name_length - maximum length of each object's name
+ * When multiprocessing is configured,
+ * supports_global - true if this is a global object class
+ * extract_callout - pointer to threadq extract callout
+ *
+ * Output parameters: NONE
+ */
+
+void _Objects_Initialize_information(
+ Objects_Information *information,
+ Objects_APIs the_api,
+ uint16_t the_class,
+ uint32_t maximum,
+ uint16_t size,
+ bool is_string,
+ uint32_t maximum_name_length
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ bool supports_global,
+ Objects_Thread_queue_Extract_callout extract
+#endif
+)
+{
+ static Objects_Control *null_local_table = NULL;
+ uint32_t minimum_index;
+ uint32_t name_length;
+ uint32_t maximum_per_allocation;
+ #if defined(RTEMS_MULTIPROCESSING)
+ uint32_t index;
+ #endif
+
+ information->the_api = the_api;
+ information->the_class = the_class;
+ information->size = size;
+ information->local_table = 0;
+ information->inactive_per_block = 0;
+ information->object_blocks = 0;
+ information->inactive = 0;
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ information->is_string = is_string;
+ #endif
+
+ /*
+ * Set the maximum value to 0. It will be updated when objects are
+ * added to the inactive set from _Objects_Extend_information()
+ */
+ information->maximum = 0;
+
+ /*
+ * Register this Object Class in the Object Information Table.
+ */
+ _Objects_Information_table[ the_api ][ the_class ] = information;
+
+ /*
+ * Are we operating in limited or unlimited (e.g. auto-extend) mode.
+ */
+ information->auto_extend =
+ (maximum & OBJECTS_UNLIMITED_OBJECTS) ? true : false;
+ maximum_per_allocation = maximum & ~OBJECTS_UNLIMITED_OBJECTS;
+
+ /*
+ * Unlimited and maximum of zero is illogical.
+ */
+ if ( information->auto_extend && maximum_per_allocation == 0) {
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0
+ );
+ }
+
+ /*
+ * The allocation unit is the maximum value
+ */
+ information->allocation_size = maximum_per_allocation;
+
+ /*
+ * Provide a null local table entry for the case of any empty table.
+ */
+ information->local_table = &null_local_table;
+
+ /*
+ * Calculate minimum and maximum Id's
+ */
+ minimum_index = (maximum_per_allocation == 0) ? 0 : 1;
+ information->minimum_id =
+ _Objects_Build_id( the_api, the_class, _Objects_Local_node, minimum_index );
+
+ /*
+ * Calculate the maximum name length
+ *
+ * NOTE: Always 4 bytes long in Class so aligned. It is POSIX name
+ * lengths that may be an odd number of bytes.
+ */
+ name_length = maximum_name_length;
+
+ #if defined(RTEMS_POSIX_API)
+ if ( name_length & (OBJECTS_NAME_ALIGNMENT-1) )
+ name_length = (name_length + OBJECTS_NAME_ALIGNMENT) &
+ ~(OBJECTS_NAME_ALIGNMENT-1);
+ #endif
+
+ information->name_length = name_length;
+
+ _Chain_Initialize_empty( &information->Inactive );
+
+ /*
+ * Initialize objects .. if there are any
+ */
+ if ( maximum_per_allocation ) {
+ /*
+ * Always have the maximum size available so the current performance
+ * figures are create are met. If the user moves past the maximum
+ * number then a performance hit is taken.
+ */
+ _Objects_Extend_information( information );
+ }
+
+ /*
+ * Take care of multiprocessing
+ */
+ #if defined(RTEMS_MULTIPROCESSING)
+ information->extract = extract;
+
+ if ( (supports_global == true) && _System_state_Is_multiprocessing ) {
+
+ information->global_table =
+ (Chain_Control *) _Workspace_Allocate_or_fatal_error(
+ (_Objects_Maximum_nodes + 1) * sizeof(Chain_Control)
+ );
+
+ for ( index=1; index <= _Objects_Maximum_nodes ; index++ )
+ _Chain_Initialize_empty( &information->global_table[ index ] );
+ }
+ else
+ information->global_table = NULL;
+ #endif
+}
diff --git a/cpukit/score/src/objectmp.c b/cpukit/score/src/objectmp.c
new file mode 100644
index 0000000000..5564b52f1f
--- /dev/null
+++ b/cpukit/score/src/objectmp.c
@@ -0,0 +1,307 @@
+/*
+ * Multiprocessing Support for the Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/thread.h>
+
+/*PAGE
+ *
+ * _Objects_MP_Handler_early_initialization
+ *
+ */
+void _Objects_MP_Handler_early_initialization(void)
+{
+ uint32_t node;
+ uint32_t maximum_nodes;
+
+ node = _Configuration_MP_table->node;
+ maximum_nodes = _Configuration_MP_table->maximum_nodes;
+
+ if ( node < 1 || node > maximum_nodes )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_INVALID_NODE
+ );
+
+ _Objects_Local_node = node;
+ _Objects_Maximum_nodes = maximum_nodes;
+}
+
+/*PAGE
+ *
+ * _Objects_MP_Handler_initialization
+ *
+ */
+
+void _Objects_MP_Handler_initialization(void)
+{
+
+ uint32_t maximum_global_objects;
+
+ maximum_global_objects = _Configuration_MP_table->maximum_global_objects;
+
+ _Objects_MP_Maximum_global_objects = maximum_global_objects;
+
+ if ( maximum_global_objects == 0 ) {
+ _Chain_Initialize_empty( &_Objects_MP_Inactive_global_objects );
+ return;
+ }
+
+ _Chain_Initialize(
+ &_Objects_MP_Inactive_global_objects,
+ _Workspace_Allocate_or_fatal_error(
+ maximum_global_objects * sizeof( Objects_MP_Control )
+ ),
+ maximum_global_objects,
+ sizeof( Objects_MP_Control )
+ );
+
+}
+
+/*PAGE
+ *
+ * _Objects_MP_Open
+ *
+ */
+
+void _Objects_MP_Open (
+ Objects_Information *information,
+ Objects_MP_Control *the_global_object,
+ uint32_t the_name, /* XXX -- wrong for variable */
+ Objects_Id the_id
+)
+{
+ the_global_object->Object.id = the_id;
+ the_global_object->name = the_name;
+
+ _Chain_Prepend(
+ &information->global_table[ _Objects_Get_node( the_id ) ],
+ &the_global_object->Object.Node
+ );
+
+}
+
+/*PAGE
+ *
+ * _Objects_MP_Allocate_and_open
+ *
+ */
+
+bool _Objects_MP_Allocate_and_open (
+ Objects_Information *information,
+ uint32_t the_name, /* XXX -- wrong for variable */
+ Objects_Id the_id,
+ bool is_fatal_error
+)
+{
+ Objects_MP_Control *the_global_object;
+
+ the_global_object = _Objects_MP_Allocate_global_object();
+ if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
+
+ if ( is_fatal_error == false )
+ return false;
+
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_OUT_OF_GLOBAL_OBJECTS
+ );
+
+ }
+
+ _Objects_MP_Open( information, the_global_object, the_name, the_id );
+
+ return true;
+}
+
+/*PAGE
+ *
+ * _Objects_MP_Close
+ *
+ */
+
+void _Objects_MP_Close (
+ Objects_Information *information,
+ Objects_Id the_id
+)
+{
+ Chain_Control *the_chain;
+ Chain_Node *the_node;
+ Objects_MP_Control *the_object;
+
+ the_chain = &information->global_table[ _Objects_Get_node( the_id ) ];
+
+ for ( the_node = _Chain_First( the_chain ) ;
+ !_Chain_Is_tail( the_chain, the_node ) ;
+ the_node = _Chain_Next( the_node ) ) {
+
+ the_object = (Objects_MP_Control *) the_node;
+
+ if ( _Objects_Are_ids_equal( the_object->Object.id, the_id ) ) {
+
+ _Chain_Extract( the_node );
+ _Objects_MP_Free_global_object( the_object );
+ return;
+ }
+
+ }
+
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_INVALID_GLOBAL_ID
+ );
+}
+
+/*PAGE
+ *
+ * _Objects_MP_Global_name_search
+ *
+ */
+
+Objects_Name_or_id_lookup_errors _Objects_MP_Global_name_search (
+ Objects_Information *information,
+ Objects_Name the_name,
+ uint32_t nodes_to_search,
+ Objects_Id *the_id
+)
+{
+ uint32_t low_node;
+ uint32_t high_node;
+ uint32_t node_index;
+ Chain_Control *the_chain;
+ Chain_Node *the_node;
+ Objects_MP_Control *the_object;
+ uint32_t name_to_use;
+
+ name_to_use = the_name.name_u32; /* XXX only fixed length names */
+
+ if ( nodes_to_search > _Objects_Maximum_nodes )
+ return OBJECTS_INVALID_NODE;
+
+ if ( information->global_table == NULL )
+ return OBJECTS_INVALID_NAME;
+
+ if ( nodes_to_search == OBJECTS_SEARCH_ALL_NODES ||
+ nodes_to_search == OBJECTS_SEARCH_OTHER_NODES ) {
+ low_node = 1;
+ high_node = _Objects_Maximum_nodes;
+ } else {
+ low_node =
+ high_node = nodes_to_search;
+ }
+
+ _Thread_Disable_dispatch();
+
+ for ( node_index = low_node ; node_index <= high_node ; node_index++ ) {
+
+ /*
+ * NOTE: The local node was search (if necessary) by
+ * _Objects_Name_to_id_XXX before this was invoked.
+ */
+
+ if ( !_Objects_Is_local_node( node_index ) ) {
+ the_chain = &information->global_table[ node_index ];
+
+ for ( the_node = _Chain_First( the_chain ) ;
+ !_Chain_Is_tail( the_chain, the_node ) ;
+ the_node = _Chain_Next( the_node ) ) {
+
+ the_object = (Objects_MP_Control *) the_node;
+
+ if ( the_object->name == name_to_use ) {
+ *the_id = the_object->Object.id;
+ _Thread_Enable_dispatch();
+ return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;
+ }
+ }
+ }
+ }
+
+ _Thread_Enable_dispatch();
+ return OBJECTS_INVALID_NAME;
+}
+
+/*PAGE
+ *
+ * _Objects_MP_Is_remote
+ *
+ */
+
+void _Objects_MP_Is_remote (
+ Objects_Information *information,
+ Objects_Id the_id,
+ Objects_Locations *location,
+ Objects_Control **the_object
+)
+{
+ uint32_t node;
+ Chain_Control *the_chain;
+ Chain_Node *the_node;
+ Objects_MP_Control *the_global_object;
+
+ node = _Objects_Get_node( the_id );
+
+ /*
+ * NOTE: The local node was search (if necessary) by
+ * _Objects_Name_to_id_XXX before this was invoked.
+ *
+ * The NODE field of an object id cannot be 0
+ * because 0 is an invalid node number.
+ */
+
+ if ( node == 0 ||
+ _Objects_Is_local_node( node ) ||
+ node > _Objects_Maximum_nodes ||
+ information->global_table == NULL ) {
+
+ *location = OBJECTS_ERROR;
+ *the_object = NULL;
+ return;
+ }
+
+ _Thread_Disable_dispatch();
+
+ the_chain = &information->global_table[ node ];
+
+ for ( the_node = _Chain_First( the_chain ) ;
+ !_Chain_Is_tail( the_chain, the_node ) ;
+ the_node = _Chain_Next( the_node ) ) {
+
+ the_global_object = (Objects_MP_Control *) the_node;
+
+ if ( _Objects_Are_ids_equal( the_global_object->Object.id, the_id ) ) {
+ _Thread_Unnest_dispatch();
+ *location = OBJECTS_REMOTE;
+ *the_object = (Objects_Control *) the_global_object;
+ return;
+ }
+ }
+
+ _Thread_Enable_dispatch();
+ *location = OBJECTS_ERROR;
+ *the_object = NULL;
+
+}
+
diff --git a/cpukit/score/src/objectnamespaceremove.c b/cpukit/score/src/objectnamespaceremove.c
new file mode 100644
index 0000000000..d6c0968f90
--- /dev/null
+++ b/cpukit/score/src/objectnamespaceremove.c
@@ -0,0 +1,40 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/wkspace.h>
+
+void _Objects_Namespace_remove(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ /*
+ * If this is a string format name, then free the memory.
+ */
+ if ( information->is_string )
+ _Workspace_Free( (void *)the_object->name.name_p );
+ #endif
+
+ /*
+ * Clear out either format.
+ */
+ #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ the_object->name.name_p = NULL;
+ #endif
+ the_object->name.name_u32 = 0;
+}
diff --git a/cpukit/score/src/objectnametoid.c b/cpukit/score/src/objectnametoid.c
new file mode 100644
index 0000000000..9cd75a274c
--- /dev/null
+++ b/cpukit/score/src/objectnametoid.c
@@ -0,0 +1,102 @@
+/*
+ * Object Handler
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Name_to_id_u32
+ *
+ * These kernel routines search the object table(s) for the given
+ * object name and returns the associated object id.
+ *
+ * Input parameters:
+ * information - object information
+ * name - user defined object name
+ * node - node indentifier (0 indicates any node)
+ * id - address of return ID
+ *
+ * Output parameters:
+ * id - object id
+ * OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
+ Objects_Information *information,
+ uint32_t name,
+ uint32_t node,
+ Objects_Id *id
+)
+{
+ bool search_local_node;
+ Objects_Control *the_object;
+ uint32_t index;
+#if defined(RTEMS_MULTIPROCESSING)
+ Objects_Name name_for_mp;
+#endif
+
+ /* ASSERT: information->is_string == false */
+
+ if ( !id )
+ return OBJECTS_INVALID_ADDRESS;
+
+ if ( name == 0 )
+ return OBJECTS_INVALID_NAME;
+
+ search_local_node = false;
+
+ if ( information->maximum != 0 &&
+ (node == OBJECTS_SEARCH_ALL_NODES ||
+ node == OBJECTS_SEARCH_LOCAL_NODE ||
+ _Objects_Is_local_node( node )
+ ))
+ search_local_node = true;
+
+ if ( search_local_node ) {
+ for ( index = 1; index <= information->maximum; index++ ) {
+ the_object = information->local_table[ index ];
+ if ( !the_object )
+ continue;
+
+ if ( name == the_object->name.name_u32 ) {
+ *id = the_object->id;
+ return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;
+ }
+ }
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Objects_Is_local_node( node ) || node == OBJECTS_SEARCH_LOCAL_NODE )
+ return OBJECTS_INVALID_NAME;
+
+ name_for_mp.name_u32 = name;
+ return _Objects_MP_Global_name_search( information, name_for_mp, node, id );
+#else
+ return OBJECTS_INVALID_NAME;
+#endif
+}
diff --git a/cpukit/score/src/objectnametoidstring.c b/cpukit/score/src/objectnametoidstring.c
new file mode 100644
index 0000000000..17b43d725d
--- /dev/null
+++ b/cpukit/score/src/objectnametoidstring.c
@@ -0,0 +1,87 @@
+/*
+ * Object Handler - Object ID to Name (String)
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+/*PAGE
+ *
+ * _Objects_Name_to_id_string
+ *
+ * These kernel routines search the object table(s) for the given
+ * object name and returns the associated object id.
+ *
+ * Input parameters:
+ * information - object information
+ * name - user defined object name
+ * id - address of return ID
+ *
+ * Output parameters:
+ * id - object id
+ * OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+Objects_Name_or_id_lookup_errors _Objects_Name_to_id_string(
+ Objects_Information *information,
+ const char *name,
+ Objects_Id *id
+)
+{
+ Objects_Control *the_object;
+ uint32_t index;
+
+ /* ASSERT: information->is_string == true */
+
+ if ( !id )
+ return OBJECTS_INVALID_ADDRESS;
+
+ if ( !name )
+ return OBJECTS_INVALID_NAME;
+
+ if ( information->maximum != 0 ) {
+
+ for ( index = 1; index <= information->maximum; index++ ) {
+ the_object = information->local_table[ index ];
+ if ( !the_object )
+ continue;
+
+ if ( !the_object->name.name_p )
+ continue;
+
+ if (!strncmp( name, the_object->name.name_p, information->name_length)) {
+ *id = the_object->id;
+ return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;
+ }
+ }
+ }
+
+ return OBJECTS_INVALID_NAME;
+}
+#endif
diff --git a/cpukit/score/src/objectsetname.c b/cpukit/score/src/objectsetname.c
new file mode 100644
index 0000000000..793e0914dd
--- /dev/null
+++ b/cpukit/score/src/objectsetname.c
@@ -0,0 +1,69 @@
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include <string.h>
+
+
+/*
+ * This method sets the name of an object based upon a C string.
+ */
+
+bool _Objects_Set_name(
+ Objects_Information *information,
+ Objects_Control *the_object,
+ const char *name
+)
+{
+ size_t length;
+ const char *s;
+
+ s = name;
+ length = strnlen( name, information->name_length );
+
+#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+ if ( information->is_string ) {
+ char *d;
+
+ d = _Workspace_Allocate( length + 1 );
+ if ( !d )
+ return false;
+
+ _Workspace_Free( (void *)the_object->name.name_p );
+ the_object->name.name_p = NULL;
+
+ strncpy( d, name, length );
+ d[length] = '\0';
+ the_object->name.name_p = d;
+ } else
+#endif
+ {
+ the_object->name.name_u32 = _Objects_Build_name(
+ ((0 <= length) ? s[ 0 ] : ' '),
+ ((1 < length) ? s[ 1 ] : ' '),
+ ((2 < length) ? s[ 2 ] : ' '),
+ ((3 < length) ? s[ 3 ] : ' ')
+ );
+
+ }
+
+ return true;
+}
diff --git a/cpukit/score/src/objectshrinkinformation.c b/cpukit/score/src/objectshrinkinformation.c
new file mode 100644
index 0000000000..18123fab68
--- /dev/null
+++ b/cpukit/score/src/objectshrinkinformation.c
@@ -0,0 +1,102 @@
+/*
+ * Object Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/address.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/object.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/objectmp.h>
+#endif
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Objects_Shrink_information
+ *
+ * This routine shrinks object information related data structures.
+ * The object's name and object space are released. The local_table
+ * etc block does not shrink. The InActive list needs to be scanned
+ * to find the objects are remove them.
+ * Input parameters:
+ * information - object information table
+ * the_block - the block to remove
+ *
+ * Output parameters: NONE
+ */
+
+void _Objects_Shrink_information(
+ Objects_Information *information
+)
+{
+ Objects_Control *the_object;
+ Objects_Control *extract_me;
+ uint32_t block_count;
+ uint32_t block;
+ uint32_t index_base;
+ uint32_t index;
+
+ /*
+ * Search the list to find block or chunk with all objects inactive.
+ */
+
+ index_base = _Objects_Get_index( information->minimum_id );
+ block_count = (information->maximum - index_base) /
+ information->allocation_size;
+
+ for ( block = 0; block < block_count; block++ ) {
+ if ( information->inactive_per_block[ block ] ==
+ information->allocation_size ) {
+
+ /*
+ * Assume the Inactive chain is never empty at this point
+ */
+ the_object = (Objects_Control *) _Chain_First( &information->Inactive );
+
+ do {
+ index = _Objects_Get_index( the_object->id );
+ /*
+ * Get the next node before the node is extracted
+ */
+ extract_me = the_object;
+ the_object = (Objects_Control *) the_object->Node.next;
+ if ((index >= index_base) &&
+ (index < (index_base + information->allocation_size))) {
+ _Chain_Extract( &extract_me->Node );
+ }
+ }
+ while ( the_object );
+ /*
+ * Free the memory and reset the structures in the object' information
+ */
+
+ _Workspace_Free( information->object_blocks[ block ] );
+ information->object_blocks[ block ] = NULL;
+ information->inactive_per_block[ block ] = 0;
+
+ information->inactive -= information->allocation_size;
+
+ return;
+ }
+
+ index_base += information->allocation_size;
+ }
+}
diff --git a/cpukit/score/src/percpu.c b/cpukit/score/src/percpu.c
new file mode 100644
index 0000000000..2d429b4db9
--- /dev/null
+++ b/cpukit/score/src/percpu.c
@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/percpu.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/config.h>
+#include <rtems/bspsmp.h>
+#include <string.h>
+
+#if defined(RTEMS_SMP)
+ void _SMP_Handler_initialize(void)
+ {
+ int cpu;
+ size_t size;
+ uintptr_t ptr;
+
+ /*
+ * Initialize per CPU structures.
+ */
+ size = (_SMP_Processor_count) * sizeof(Per_CPU_Control);
+ memset( _Per_CPU_Information, '\0', size );
+
+ /*
+ * Initialize per cpu pointer table
+ */
+ size = Configuration.interrupt_stack_size;
+ _Per_CPU_Information_p[0] = &_Per_CPU_Information[0];
+ for (cpu=1 ; cpu < _SMP_Processor_count ; cpu++ ) {
+ Per_CPU_Control *p = &_Per_CPU_Information[cpu];
+
+ _Per_CPU_Information_p[cpu] = p;
+
+ p->interrupt_stack_low = _Workspace_Allocate_or_fatal_error( size );
+
+ ptr = (uintptr_t) _Addresses_Add_offset( p->interrupt_stack_low, size );
+ ptr &= ~CPU_STACK_ALIGNMENT;
+ p->interrupt_stack_high = (void *)ptr;
+ p->state = RTEMS_BSP_SMP_CPU_INITIAL_STATE;
+ RTEMS_COMPILER_MEMORY_BARRIER();
+ }
+ }
+#else
+ /*
+ * On single core systems, we can efficiently directly access a single
+ * statically allocated per cpu structure. And the fields are initialized
+ * as individual elements just like it has always been done.
+ */
+ Per_CPU_Control _Per_CPU_Information[1];
+#endif
diff --git a/cpukit/score/src/pheapallocate.c b/cpukit/score/src/pheapallocate.c
new file mode 100644
index 0000000000..b4888dc8ea
--- /dev/null
+++ b/cpukit/score/src/pheapallocate.c
@@ -0,0 +1,46 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+void *_Protected_heap_Allocate_aligned_with_boundary(
+ Heap_Control *heap,
+ uintptr_t size,
+ uintptr_t alignment,
+ uintptr_t boundary
+)
+{
+ void *p;
+
+ _RTEMS_Lock_allocator();
+ p = _Heap_Allocate_aligned_with_boundary(
+ heap,
+ size,
+ alignment,
+ boundary
+ );
+ _RTEMS_Unlock_allocator();
+
+ return p;
+}
diff --git a/cpukit/score/src/pheapextend.c b/cpukit/score/src/pheapextend.c
new file mode 100644
index 0000000000..e71fb1bd8c
--- /dev/null
+++ b/cpukit/score/src/pheapextend.c
@@ -0,0 +1,41 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Extend(
+ Heap_Control *the_heap,
+ void *starting_address,
+ uintptr_t size
+)
+{
+ bool extend_ok;
+ uintptr_t amount_extended;
+
+ _RTEMS_Lock_allocator();
+ extend_ok = _Heap_Extend(the_heap, starting_address, size, &amount_extended);
+ _RTEMS_Unlock_allocator();
+ return extend_ok;
+}
+
diff --git a/cpukit/score/src/pheapfree.c b/cpukit/score/src/pheapfree.c
new file mode 100644
index 0000000000..eb57ded669
--- /dev/null
+++ b/cpukit/score/src/pheapfree.c
@@ -0,0 +1,38 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Free(
+ Heap_Control *the_heap,
+ void *start_address
+)
+{
+ bool status;
+
+ _RTEMS_Lock_allocator();
+ status = _Heap_Free( the_heap, start_address );
+ _RTEMS_Unlock_allocator();
+ return status;
+}
diff --git a/cpukit/score/src/pheapgetblocksize.c b/cpukit/score/src/pheapgetblocksize.c
new file mode 100644
index 0000000000..0591abdd6e
--- /dev/null
+++ b/cpukit/score/src/pheapgetblocksize.c
@@ -0,0 +1,39 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Get_block_size(
+ Heap_Control *the_heap,
+ void *starting_address,
+ uintptr_t *size
+)
+{
+ bool status;
+
+ _RTEMS_Lock_allocator();
+ status = _Heap_Size_of_alloc_area( the_heap, starting_address, size );
+ _RTEMS_Unlock_allocator();
+ return status;
+}
diff --git a/cpukit/score/src/pheapgetfreeinfo.c b/cpukit/score/src/pheapgetfreeinfo.c
new file mode 100644
index 0000000000..e95bffe0ba
--- /dev/null
+++ b/cpukit/score/src/pheapgetfreeinfo.c
@@ -0,0 +1,42 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Get_free_information(
+ Heap_Control *the_heap,
+ Heap_Information *info
+)
+{
+ /*
+ * TBD: _Heap_Get_free_information does not error check or return status.
+ */
+
+ _RTEMS_Lock_allocator();
+ _Heap_Get_free_information( the_heap, info );
+ _RTEMS_Unlock_allocator();
+
+ return true;
+}
+
diff --git a/cpukit/score/src/pheapgetinfo.c b/cpukit/score/src/pheapgetinfo.c
new file mode 100644
index 0000000000..2c4a287edd
--- /dev/null
+++ b/cpukit/score/src/pheapgetinfo.c
@@ -0,0 +1,43 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Get_information(
+ Heap_Control *the_heap,
+ Heap_Information_block *the_info
+)
+{
+ if ( !the_heap )
+ return false;
+
+ if ( !the_info )
+ return false;
+
+ _RTEMS_Lock_allocator();
+ _Heap_Get_information( the_heap, the_info );
+ _RTEMS_Unlock_allocator();
+
+ return true;
+}
diff --git a/cpukit/score/src/pheapgetsize.c b/cpukit/score/src/pheapgetsize.c
new file mode 100644
index 0000000000..fbf90ea3a4
--- /dev/null
+++ b/cpukit/score/src/pheapgetsize.c
@@ -0,0 +1,32 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+uintptr_t _Protected_heap_Get_size(
+ Heap_Control *the_heap
+)
+{
+ return _Heap_Get_size( the_heap );
+}
diff --git a/cpukit/score/src/pheapinit.c b/cpukit/score/src/pheapinit.c
new file mode 100644
index 0000000000..f2a11a7be9
--- /dev/null
+++ b/cpukit/score/src/pheapinit.c
@@ -0,0 +1,27 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+
diff --git a/cpukit/score/src/pheapresizeblock.c b/cpukit/score/src/pheapresizeblock.c
new file mode 100644
index 0000000000..14dc522cff
--- /dev/null
+++ b/cpukit/score/src/pheapresizeblock.c
@@ -0,0 +1,43 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Resize_block(
+ Heap_Control *the_heap,
+ void *starting_address,
+ uintptr_t size
+)
+{
+ Heap_Resize_status status;
+ uintptr_t old_mem_size;
+ uintptr_t avail_mem_size;
+
+ _RTEMS_Lock_allocator();
+ status = _Heap_Resize_block(
+ the_heap, starting_address, size, &old_mem_size, &avail_mem_size );
+ _RTEMS_Unlock_allocator();
+ return (status == HEAP_RESIZE_SUCCESSFUL);
+}
+
diff --git a/cpukit/score/src/pheapwalk.c b/cpukit/score/src/pheapwalk.c
new file mode 100644
index 0000000000..4aa2279902
--- /dev/null
+++ b/cpukit/score/src/pheapwalk.c
@@ -0,0 +1,50 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief Protected Heap Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/protectedheap.h>
+
+bool _Protected_heap_Walk(
+ Heap_Control *the_heap,
+ int source,
+ bool do_dump
+)
+{
+ bool status;
+
+ /*
+ * If we are called from within a dispatching critical section,
+ * then it is forbidden to lock a mutex. But since we are inside
+ * a critical section, it should be safe to walk it unlocked.
+ *
+ * NOTE: Dispatching is also disabled during initialization.
+ */
+ if ( !_Thread_Dispatch_disable_level ) {
+ _RTEMS_Lock_allocator();
+ status = _Heap_Walk( the_heap, source, do_dump );
+ _RTEMS_Unlock_allocator();
+ } else {
+ status = _Heap_Walk( the_heap, source, do_dump );
+ }
+ return status;
+}
diff --git a/cpukit/score/src/scheduler.c b/cpukit/score/src/scheduler.c
new file mode 100644
index 0000000000..71938a728c
--- /dev/null
+++ b/cpukit/score/src/scheduler.c
@@ -0,0 +1,25 @@
+/*
+ * Scheduler Handler / Initialization
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/scheduler.h>
+
+void _Scheduler_Handler_initialization(void)
+{
+ (*_Scheduler.Operations.initialize)();
+}
diff --git a/cpukit/score/src/schedulerpriority.c b/cpukit/score/src/schedulerpriority.c
new file mode 100644
index 0000000000..279f42de6c
--- /dev/null
+++ b/cpukit/score/src/schedulerpriority.c
@@ -0,0 +1,33 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/prioritybitmap.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+
+/* Instantiate any global variables needed by the priority scheduler */
+volatile Priority_bit_map_Control _Priority_Major_bit_map;
+
+Priority_bit_map_Control _Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT;
+
+void _Scheduler_priority_Initialize(void)
+{
+ _Scheduler_priority_Ready_queue_initialize();
+ _Priority_bit_map_Handler_initialization();
+}
diff --git a/cpukit/score/src/schedulerpriorityallocate.c b/cpukit/score/src/schedulerpriorityallocate.c
new file mode 100644
index 0000000000..9df1e9ee5e
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityallocate.c
@@ -0,0 +1,35 @@
+/*
+ * Scheduler Priority Handler / Allocate
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/wkspace.h>
+
+void* _Scheduler_priority_Allocate (
+ Thread_Control *the_thread
+)
+{
+ void *sched;
+
+ sched = _Workspace_Allocate( sizeof(Scheduler_priority_Per_thread) );
+
+ the_thread->scheduler_info = (Scheduler_priority_Per_thread*) sched;
+
+ return sched;
+}
diff --git a/cpukit/score/src/schedulerpriorityblock.c b/cpukit/score/src/schedulerpriorityblock.c
new file mode 100644
index 0000000000..702ea48034
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityblock.c
@@ -0,0 +1,42 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/thread.h>
+
+void _Scheduler_priority_Block(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Ready_queue_extract( the_thread );
+
+ /* TODO: flash critical section? */
+
+ if ( _Thread_Is_heir( the_thread ) )
+ _Scheduler_priority_Schedule_body();
+
+ if ( _Thread_Is_executing( the_thread ) )
+ _Thread_Dispatch_necessary = true;
+
+}
diff --git a/cpukit/score/src/schedulerpriorityenqueue.c b/cpukit/score/src/schedulerpriorityenqueue.c
new file mode 100644
index 0000000000..82e192ac8c
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityenqueue.c
@@ -0,0 +1,26 @@
+/*
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+
+void _Scheduler_priority_Enqueue(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Ready_queue_enqueue( the_thread );
+}
diff --git a/cpukit/score/src/schedulerpriorityenqueuefirst.c b/cpukit/score/src/schedulerpriorityenqueuefirst.c
new file mode 100644
index 0000000000..56573b7bb8
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityenqueuefirst.c
@@ -0,0 +1,27 @@
+/*
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/schedulerpriority.h>
+
+void _Scheduler_priority_Enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Ready_queue_enqueue_first( the_thread );
+}
+
diff --git a/cpukit/score/src/schedulerpriorityextract.c b/cpukit/score/src/schedulerpriorityextract.c
new file mode 100644
index 0000000000..83f5d28f9f
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityextract.c
@@ -0,0 +1,27 @@
+/* Scheduler Simple Handler / Extract
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/schedulerpriority.h>
+
+void _Scheduler_priority_Extract(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Ready_queue_extract( the_thread );
+}
diff --git a/cpukit/score/src/schedulerpriorityfree.c b/cpukit/score/src/schedulerpriorityfree.c
new file mode 100644
index 0000000000..27757755e3
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityfree.c
@@ -0,0 +1,29 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/wkspace.h>
+
+void _Scheduler_priority_Free (
+ Thread_Control *the_thread
+)
+{
+ _Workspace_Free( the_thread->scheduler_info );
+}
diff --git a/cpukit/score/src/schedulerpriorityschedule.c b/cpukit/score/src/schedulerpriorityschedule.c
new file mode 100644
index 0000000000..e608e1f1f0
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityschedule.c
@@ -0,0 +1,25 @@
+/*
+ * Scheduler Handler / Scheduler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+
+void _Scheduler_priority_Schedule(void)
+{
+ _Scheduler_priority_Schedule_body();
+}
diff --git a/cpukit/score/src/schedulerpriorityunblock.c b/cpukit/score/src/schedulerpriorityunblock.c
new file mode 100644
index 0000000000..8c0f490c8c
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityunblock.c
@@ -0,0 +1,48 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+
+void _Scheduler_priority_Unblock (
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_priority_Ready_queue_enqueue(the_thread);
+
+ /* TODO: flash critical section? */
+
+ /*
+ * If the thread that was unblocked is more important than the heir,
+ * then we have a new heir. This may or may not result in a
+ * context switch.
+ *
+ * Normal case:
+ * If the current thread is preemptible, then we need to do
+ * a context switch.
+ * Pseudo-ISR case:
+ * Even if the thread isn't preemptible, if the new heir is
+ * a pseudo-ISR system task, we need to do a context switch.
+ */
+ if ( the_thread->current_priority < _Thread_Heir->current_priority ) {
+ _Thread_Heir = the_thread;
+ if ( _Thread_Executing->is_preemptible ||
+ the_thread->current_priority == 0 )
+ _Thread_Dispatch_necessary = true;
+ }
+}
diff --git a/cpukit/score/src/schedulerpriorityupdate.c b/cpukit/score/src/schedulerpriorityupdate.c
new file mode 100644
index 0000000000..59b2432cf2
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityupdate.c
@@ -0,0 +1,42 @@
+/*
+ * Scheduler Handler
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/prioritybitmap.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/thread.h>
+
+void _Scheduler_priority_Update(
+ Thread_Control *the_thread
+)
+{
+ Scheduler_priority_Per_thread *sched_info;
+ Chain_Control *rq;
+
+ sched_info = (Scheduler_priority_Per_thread *) the_thread->scheduler_info;
+ rq = (Chain_Control *) _Scheduler.information;
+
+ sched_info->ready_chain = &rq[ the_thread->current_priority ];
+
+ _Priority_bit_map_Initialize_information(
+ &sched_info->Priority_map,
+ the_thread->current_priority
+ );
+}
diff --git a/cpukit/score/src/schedulerpriorityyield.c b/cpukit/score/src/schedulerpriorityyield.c
new file mode 100644
index 0000000000..ba46a08f3d
--- /dev/null
+++ b/cpukit/score/src/schedulerpriorityyield.c
@@ -0,0 +1,55 @@
+/*
+ * Scheduler Priority Handler / Yield
+ *
+ * Copyright (C) 2010 Gedare Bloom.
+ * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/thread.h>
+
+/*
+ * INTERRUPT LATENCY:
+ * ready chain
+ * select heir
+ */
+
+void _Scheduler_priority_Yield(void)
+{
+ Scheduler_priority_Per_thread *sched_info;
+ ISR_Level level;
+ Thread_Control *executing;
+ Chain_Control *ready;
+
+ executing = _Thread_Executing;
+ sched_info = (Scheduler_priority_Per_thread *) executing->scheduler_info;
+ ready = sched_info->ready_chain;
+ _ISR_Disable( level );
+ if ( !_Chain_Has_only_one_node( ready ) ) {
+ _Chain_Extract_unprotected( &executing->Object.Node );
+ _Chain_Append_unprotected( ready, &executing->Object.Node );
+
+ _ISR_Flash( level );
+
+ if ( _Thread_Is_heir( executing ) )
+ _Thread_Heir = (Thread_Control *) _Chain_First( ready );
+ _Thread_Dispatch_necessary = true;
+ }
+ else if ( !_Thread_Is_heir( executing ) )
+ _Thread_Dispatch_necessary = true;
+
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/schedulersimple.c b/cpukit/score/src/schedulersimple.c
new file mode 100644
index 0000000000..7a7ed944f4
--- /dev/null
+++ b/cpukit/score/src/schedulersimple.c
@@ -0,0 +1,84 @@
+/*
+ * Scheduler Simple Handler / Initialize
+ * Scheduler Simple Handler / Allocate (Empty Routine)
+ * Scheduler Simple Handler / Update (Empty Routine)
+ * Scheduler Simple Handler / Free (Empty Routine)
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulersimple.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule allocate
+ *
+ * Note: returns a non-zero value, or else thread initialize thinks the
+ * allocation failed.
+ *
+ * The overhead of a function call will still be imposed.
+ */
+void * _Scheduler_simple_Allocate(
+ Thread_Control *the_thread
+)
+{
+ return (void*)-1; /* maybe pick an appropriate poison value */
+}
+
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule update
+ *
+ * The overhead of a function call will still be imposed.
+ */
+void _Scheduler_simple_Update(
+ Thread_Control *the_thread
+)
+{
+}
+
+/**
+ * This routine does nothing, and is used as a stub for Schedule free
+ *
+ * The overhead of a function call will still be imposed.
+ */
+void _Scheduler_simple_Free(
+ Thread_Control *the_thread
+)
+{
+}
+
+/**
+ * This routine initializes the simple scheduler.
+ */
+void _Scheduler_simple_Initialize ( void )
+{
+ void *f;
+
+ /*
+ * Initialize Ready Queue
+ */
+
+ /* allocate ready queue structures */
+ f = _Workspace_Allocate_or_fatal_error( sizeof(Chain_Control) );
+ _Scheduler.information = f;
+
+ /* initialize ready queue structure */
+ _Chain_Initialize_empty( (Chain_Control *)f );
+}
diff --git a/cpukit/score/src/schedulersimpleblock.c b/cpukit/score/src/schedulersimpleblock.c
new file mode 100644
index 0000000000..212f4f10bf
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleblock.c
@@ -0,0 +1,39 @@
+/*
+ * Scheduler Simple Handler / Block
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Block(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Extract(the_thread);
+
+ if ( _Thread_Is_heir( the_thread ) )
+ _Scheduler_simple_Schedule();
+
+ if ( _Thread_Is_executing( the_thread ) )
+ _Thread_Dispatch_necessary = true;
+}
diff --git a/cpukit/score/src/schedulersimpleenqueue.c b/cpukit/score/src/schedulersimpleenqueue.c
new file mode 100644
index 0000000000..8e5e6381c5
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleenqueue.c
@@ -0,0 +1,29 @@
+/*
+ * Schedule Simple Handler / Enqueue
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Enqueue(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Ready_queue_Enqueue( the_thread );
+}
diff --git a/cpukit/score/src/schedulersimpleenqueuefirst.c b/cpukit/score/src/schedulersimpleenqueuefirst.c
new file mode 100644
index 0000000000..d6fd7dda98
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleenqueuefirst.c
@@ -0,0 +1,28 @@
+/*
+ * Schedule Simple Handler / Enqueue First
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Ready_queue_Enqueue_first( the_thread );
+}
diff --git a/cpukit/score/src/schedulersimpleextract.c b/cpukit/score/src/schedulersimpleextract.c
new file mode 100644
index 0000000000..208fcb55bd
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleextract.c
@@ -0,0 +1,28 @@
+/*
+ * Schedule Simple Handler / Extract
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Extract(
+ Thread_Control *the_thread
+)
+{
+ _Chain_Extract_unprotected( &the_thread->Object.Node );
+}
diff --git a/cpukit/score/src/schedulersimplereadyqueueenqueue.c b/cpukit/score/src/schedulersimplereadyqueueenqueue.c
new file mode 100644
index 0000000000..788f94b20b
--- /dev/null
+++ b/cpukit/score/src/schedulersimplereadyqueueenqueue.c
@@ -0,0 +1,48 @@
+/*
+ * Schedule Simple Handler / Ready Queue Enqueue
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Ready_queue_Enqueue(
+ Thread_Control *the_thread
+)
+{
+ Chain_Control *ready;
+ Chain_Node *the_node;
+ Thread_Control *current;
+
+ ready = (Chain_Control *)_Scheduler.information;
+ the_node = _Chain_First( ready );
+ current = (Thread_Control *)ready;
+
+ for ( ; !_Chain_Is_tail( ready, the_node ) ; the_node = the_node->next ) {
+ current = (Thread_Control *) the_node;
+
+ /* break when AT END OR PAST our priority */
+ if ( the_thread->current_priority < current->current_priority ) {
+ current = (Thread_Control *)current->Object.Node.previous;
+ break;
+ }
+ }
+
+ /* enqueue */
+ _Chain_Insert_unprotected( (Chain_Node *)current, &the_thread->Object.Node );
+}
diff --git a/cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c b/cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c
new file mode 100644
index 0000000000..dee0bbd116
--- /dev/null
+++ b/cpukit/score/src/schedulersimplereadyqueueenqueuefirst.c
@@ -0,0 +1,52 @@
+/*
+ * Schedule Simple Handler / Ready Queue Enqueue First
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Ready_queue_Enqueue_first(
+ Thread_Control *the_thread
+)
+{
+ Chain_Control *ready;
+ Chain_Node *the_node;
+ Thread_Control *current;
+
+ ready = (Chain_Control *)_Scheduler.information;
+ current = (Thread_Control *)ready;
+
+ /*
+ * Do NOT need to check for end of chain because there is always
+ * at least one task on the ready chain -- the IDLE task. It can
+ * never block, should never attempt to obtain a semaphore or mutex,
+ * and thus will always be there.
+ */
+ for ( the_node = _Chain_First(ready) ; ; the_node = the_node->next ) {
+ current = (Thread_Control *) the_node;
+
+ /* break when AT HEAD OF (or PAST) our priority */
+ if ( the_thread->current_priority <= current->current_priority ) {
+ current = (Thread_Control *)current->Object.Node.previous;
+ break;
+ }
+ }
+
+ /* enqueue */
+ _Chain_Insert_unprotected( (Chain_Node *)current, &the_thread->Object.Node );
+}
diff --git a/cpukit/score/src/schedulersimpleschedule.c b/cpukit/score/src/schedulersimpleschedule.c
new file mode 100644
index 0000000000..354e61f705
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleschedule.c
@@ -0,0 +1,34 @@
+/*
+ * Scheduler Simple Handler / Schedule
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/percpu.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Schedule(void)
+{
+ _Thread_Heir = (Thread_Control *) _Chain_First(
+ (Chain_Control *) _Scheduler.information
+ );
+}
diff --git a/cpukit/score/src/schedulersimpleunblock.c b/cpukit/score/src/schedulersimpleunblock.c
new file mode 100644
index 0000000000..5be5c16ad9
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleunblock.c
@@ -0,0 +1,47 @@
+/*
+ * Scheduler Simple Handler / Unblock
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/schedulersimple.h>
+#include <rtems/score/thread.h>
+
+void _Scheduler_simple_Unblock(
+ Thread_Control *the_thread
+)
+{
+ _Scheduler_simple_Ready_queue_Enqueue(the_thread);
+
+ /*
+ * If the thread that was unblocked is more important than the heir,
+ * then we have a new heir. This may or may not result in a
+ * context switch.
+ *
+ * Normal case:
+ * If the current thread is preemptible, then we need to do
+ * a context switch.
+ * Pseudo-ISR case:
+ * Even if the thread isn't preemptible, if the new heir is
+ * a pseudo-ISR system task, we need to do a context switch.
+ */
+ if ( the_thread->current_priority < _Thread_Heir->current_priority ) {
+ _Thread_Heir = the_thread;
+ if ( _Thread_Executing->is_preemptible ||
+ the_thread->current_priority == 0 )
+ _Thread_Dispatch_necessary = true;
+ }
+}
diff --git a/cpukit/score/src/schedulersimpleyield.c b/cpukit/score/src/schedulersimpleyield.c
new file mode 100644
index 0000000000..61e80db7e2
--- /dev/null
+++ b/cpukit/score/src/schedulersimpleyield.c
@@ -0,0 +1,42 @@
+/*
+ * Scheduler Simple Handler / Yield
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/schedulersimple.h>
+
+void _Scheduler_simple_Yield( void )
+{
+ ISR_Level level;
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+ _ISR_Disable( level );
+
+ _Scheduler_simple_Ready_queue_Requeue(&_Scheduler, executing);
+
+ _ISR_Flash( level );
+
+ _Scheduler_simple_Schedule();
+
+ if ( !_Thread_Is_heir( executing ) )
+ _Thread_Dispatch_necessary = true;
+
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/smp.c b/cpukit/score/src/smp.c
new file mode 100644
index 0000000000..4a0c13947f
--- /dev/null
+++ b/cpukit/score/src/smp.c
@@ -0,0 +1,153 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/bspsmp.h>
+#include <rtems/score/thread.h>
+
+#if defined(RTEMS_SMP)
+#define SMP_DEBUG
+
+#if defined(SMP_DEBUG)
+ #include <rtems/bspIo.h>
+#endif
+
+void rtems_smp_run_first_task(int cpu)
+{
+ Thread_Control *heir;
+
+ /*
+ * This CPU has an heir thread so we need to dispatch it.
+ */
+ heir = _Thread_Heir;
+
+ /*
+ * This is definitely a hack until we have SMP scheduling. Since there
+ * is only one executing and heir right now, we have to fake this out.
+ */
+ _Thread_Dispatch_disable_level = 1;
+ _Thread_Executing = heir;
+ _CPU_Context_switch_to_first_task_smp( &heir->Registers );
+}
+
+void rtems_smp_secondary_cpu_initialize(void)
+{
+ int cpu;
+
+ cpu = bsp_smp_processor_id();
+
+ bsp_smp_secondary_cpu_initialize(cpu);
+
+ #if defined(SMP_DEBUG)
+ printk( "Made it to %d -- ", cpu );
+ #endif
+
+ /*
+ * Inform the primary CPU that this secondary CPU is initialized
+ * and ready to dispatch to the first thread it is supposed to
+ * execute when the primary CPU is ready.
+ */
+ _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_INITIALIZED;
+
+ /*
+ * HACK: Should not have to enable interrupts in real system here.
+ * It should happen as part of switching to the first task.
+ */
+
+ _Per_CPU_Information[cpu].isr_nest_level = 1;
+ _ISR_Set_level( 0 );
+ while(1) ;
+}
+
+void rtems_smp_process_interrupt(void)
+{
+ int cpu;
+ uint32_t message;
+ ISR_Level level;
+
+ cpu = bsp_smp_processor_id();
+
+ level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
+ message = _Per_CPU_Information[cpu].message;
+ _Per_CPU_Information[cpu].message &= ~message;
+ _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
+
+ #if defined(SMP_DEBUG)
+ {
+ void *sp = __builtin_frame_address(0);
+ if ( !(message & RTEMS_BSP_SMP_SHUTDOWN) )
+ printk( "ISR on CPU %d -- (0x%02x) (0x%p)\n", cpu, message, sp );
+ printk( "Dispatch level %d\n", _Thread_Dispatch_disable_level );
+ }
+ #endif
+
+ if ( message & RTEMS_BSP_SMP_FIRST_TASK ) {
+ _Per_CPU_Information[cpu].isr_nest_level = 0;
+ _Per_CPU_Information[cpu].message = 0;
+ _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_INITIALIZED;
+ rtems_smp_run_first_task(cpu);
+ /* does not return */
+ }
+
+ if ( message & RTEMS_BSP_SMP_SHUTDOWN ) {
+ ISR_Level level;
+ _Thread_Dispatch_disable_level = 0;
+ _Per_CPU_Information[cpu].isr_nest_level = 0;
+ _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_SHUTDOWN;
+ _ISR_Disable( level );
+ while(1)
+ ;
+ /* does not continue past here */
+ }
+
+ if ( message & RTEMS_BSP_SMP_CONTEXT_SWITCH_NECESSARY ) {
+ printk( "switch needed\n" );
+ _Per_CPU_Information[cpu].dispatch_necessary = true;
+ }
+}
+
+void rtems_smp_send_message(
+ int cpu,
+ uint32_t message
+)
+{
+ ISR_Level level;
+
+ level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
+ _Per_CPU_Information[cpu].message |= message;
+ _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
+ bsp_smp_interrupt_cpu( cpu );
+}
+
+void rtems_smp_broadcast_message(
+ uint32_t message
+)
+{
+ int dest_cpu;
+ int cpu;
+ ISR_Level level;
+
+ cpu = bsp_smp_processor_id();
+
+ for ( dest_cpu=0 ; dest_cpu < _SMP_Processor_count; dest_cpu++ ) {
+ if ( cpu == dest_cpu )
+ continue;
+ level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
+ _Per_CPU_Information[dest_cpu].message |= message;
+ _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
+ }
+ bsp_smp_broadcast_interrupt();
+}
+#endif
diff --git a/cpukit/score/src/smplock.c b/cpukit/score/src/smplock.c
new file mode 100644
index 0000000000..1dd691835b
--- /dev/null
+++ b/cpukit/score/src/smplock.c
@@ -0,0 +1,49 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/smplock.h>
+
+void _SMP_lock_Spinlock_Initialize(
+ SMP_lock_Control *lock
+)
+{
+ *lock = 0;
+}
+
+ISR_Level _SMP_lock_Spinlock_Obtain(
+ SMP_lock_Control *lock
+)
+{
+ ISR_Level level;
+ uint32_t value = 1;
+ uint32_t previous;
+
+ /* Note: Disable provides an implicit memory barrier. */
+ _ISR_Disable( level );
+ do {
+ SMP_CPU_SWAP( lock, value, previous );
+ } while (previous == 1);
+ return level;
+}
+
+void _SMP_lock_Spinlock_Release(
+ SMP_lock_Control *lock,
+ ISR_Level level
+)
+{
+ *lock = 0;
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/thread.c b/cpukit/score/src/thread.c
new file mode 100644
index 0000000000..7a0eb38502
--- /dev/null
+++ b/cpukit/score/src/thread.c
@@ -0,0 +1,123 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/config.h>
+
+#if defined(RTEMS_SMP)
+ #include <rtems/bspsmp.h>
+#endif
+
+/*
+ * _Thread_Handler_initialization
+ *
+ * This routine initializes all thread manager related data structures.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_Handler_initialization(void)
+{
+ uint32_t ticks_per_timeslice;
+ uint32_t maximum_extensions;
+ uint32_t maximum_internal_threads;
+ #if defined(RTEMS_MULTIPROCESSING)
+ uint32_t maximum_proxies;
+ #endif
+
+ ticks_per_timeslice = Configuration.ticks_per_timeslice;
+ maximum_extensions = Configuration.maximum_extensions;
+ #if defined(RTEMS_MULTIPROCESSING)
+ maximum_proxies = _Configuration_MP_table->maximum_proxies;
+ #endif
+ /*
+ * BOTH stacks hooks must be set or both must be NULL.
+ * Do not allow mixture.
+ */
+ if ( !( (!Configuration.stack_allocate_hook)
+ == (!Configuration.stack_free_hook) ) )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_BAD_STACK_HOOK
+ );
+
+ _Thread_Dispatch_necessary = false;
+ _Thread_Executing = NULL;
+ _Thread_Heir = NULL;
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ _Thread_Allocated_fp = NULL;
+#endif
+
+ _Thread_Maximum_extensions = maximum_extensions;
+
+ _Thread_Ticks_per_timeslice = ticks_per_timeslice;
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Thread_MP_Handler_initialization( maximum_proxies );
+ #endif
+
+ /*
+ * Initialize the internal class of threads. We need an IDLE thread
+ * per CPU in an SMP system. In addition, if this is a loosely
+ * coupled multiprocessing system, account for the MPCI Server Thread.
+ */
+ #if defined(RTEMS_SMP)
+ maximum_internal_threads = rtems_smp_maximum_processors;
+ #else
+ maximum_internal_threads = 1;
+ #endif
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _System_state_Is_multiprocessing )
+ maximum_internal_threads += 1;
+ #endif
+
+ _Objects_Initialize_information(
+ &_Thread_Internal_information,
+ OBJECTS_INTERNAL_API,
+ OBJECTS_INTERNAL_THREADS,
+ maximum_internal_threads,
+ sizeof( Thread_Control ),
+ /* size of this object's control block */
+ false, /* true if names for this object are strings */
+ 8 /* maximum length of each object's name */
+ #if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+ #endif
+ );
+
+}
diff --git a/cpukit/score/src/threadblockingoperationcancel.c b/cpukit/score/src/threadblockingoperationcancel.c
new file mode 100644
index 0000000000..354df0c7e9
--- /dev/null
+++ b/cpukit/score/src/threadblockingoperationcancel.c
@@ -0,0 +1,89 @@
+/*
+ * Cancel Thread Blocking Operation
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/thread.h>
+#if defined(RTEMS_DEBUG)
+#include <rtems/score/interr.h>
+#endif
+
+void _Thread_blocking_operation_Cancel(
+#if defined(RTEMS_DEBUG)
+ Thread_blocking_operation_States sync_state,
+#else
+ Thread_blocking_operation_States sync_state __attribute__((unused)),
+#endif
+ Thread_Control *the_thread,
+ ISR_Level level
+)
+{
+ /*
+ * Cases that should not happen and why.
+ *
+ * THREAD_BLOCKING_OPERATION_SYNCHRONIZED:
+ *
+ * This indicates that someone did not enter a blocking
+ * operation critical section.
+ *
+ * THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED:
+ *
+ * This indicates that there was nothing to cancel so
+ * we should not have been called.
+ */
+
+ #if defined(RTEMS_DEBUG)
+ if ( (sync_state == THREAD_BLOCKING_OPERATION_SYNCHRONIZED) ||
+ (sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ) {
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL
+ );
+ }
+ #endif
+
+ /*
+ * The thread is not waiting on anything after this completes.
+ */
+ the_thread->Wait.queue = NULL;
+
+ /*
+ * If the sync state is timed out, this is very likely not needed.
+ * But better safe than sorry when it comes to critical sections.
+ */
+ if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
+ _Watchdog_Deactivate( &the_thread->Timer );
+ _ISR_Enable( level );
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ } else
+ _ISR_Enable( level );
+
+ /*
+ * Global objects with thread queue's should not be operated on from an
+ * ISR. But the sync code still must allow short timeouts to be processed
+ * correctly.
+ */
+
+ _Thread_Unblock( the_thread );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ _Thread_MP_Free_proxy( the_thread );
+#endif
+
+}
diff --git a/cpukit/score/src/threadchangepriority.c b/cpukit/score/src/threadchangepriority.c
new file mode 100644
index 0000000000..95011d8237
--- /dev/null
+++ b/cpukit/score/src/threadchangepriority.c
@@ -0,0 +1,99 @@
+/*
+ * Thread Handler / Change Priority
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+void _Thread_Change_priority(
+ Thread_Control *the_thread,
+ Priority_Control new_priority,
+ bool prepend_it
+)
+{
+ ISR_Level level;
+ States_Control state, original_state;
+
+ /*
+ * Save original state
+ */
+ original_state = the_thread->current_state;
+
+ /*
+ * Set a transient state for the thread so it is pulled off the Ready chains.
+ * This will prevent it from being scheduled no matter what happens in an
+ * ISR.
+ */
+ _Thread_Set_transient( the_thread );
+
+ /*
+ * Do not bother recomputing all the priority related information if
+ * we are not REALLY changing priority.
+ */
+ if ( the_thread->current_priority != new_priority )
+ _Thread_Set_priority( the_thread, new_priority );
+
+ _ISR_Disable( level );
+
+ /*
+ * If the thread has more than STATES_TRANSIENT set, then it is blocked,
+ * If it is blocked on a thread queue, then we need to requeue it.
+ */
+ state = the_thread->current_state;
+ if ( state != STATES_TRANSIENT ) {
+ /* Only clear the transient state if it wasn't set already */
+ if ( ! _States_Is_transient( original_state ) )
+ the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
+ _ISR_Enable( level );
+ if ( _States_Is_waiting_on_thread_queue( state ) ) {
+ _Thread_queue_Requeue( the_thread->Wait.queue, the_thread );
+ }
+ return;
+ }
+
+ /* Only clear the transient state if it wasn't set already */
+ if ( ! _States_Is_transient( original_state ) ) {
+ /*
+ * Interrupts are STILL disabled.
+ * We now know the thread will be in the READY state when we remove
+ * the TRANSIENT state. So we have to place it on the appropriate
+ * Ready Queue with interrupts off.
+ */
+ the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
+
+ if ( prepend_it )
+ _Scheduler_Enqueue_first( the_thread );
+ else
+ _Scheduler_Enqueue( the_thread );
+ }
+
+ _ISR_Flash( level );
+
+ /*
+ * We altered the set of thread priorities. So let's figure out
+ * who is the heir and if we need to switch to them.
+ */
+ _Scheduler_Schedule();
+
+ if ( !_Thread_Is_executing_also_the_heir() &&
+ _Thread_Executing->is_preemptible )
+ _Thread_Dispatch_necessary = true;
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/threadclearstate.c b/cpukit/score/src/threadclearstate.c
new file mode 100644
index 0000000000..afeab04e8e
--- /dev/null
+++ b/cpukit/score/src/threadclearstate.c
@@ -0,0 +1,58 @@
+/*
+ * Thread Handler / Thread Clear State
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * INTERRUPT LATENCY:
+ * priority map
+ * select heir
+ */
+void _Thread_Clear_state(
+ Thread_Control *the_thread,
+ States_Control state
+)
+{
+ ISR_Level level;
+ States_Control current_state;
+
+ _ISR_Disable( level );
+ current_state = the_thread->current_state;
+
+ if ( current_state & state ) {
+ current_state =
+ the_thread->current_state = _States_Clear( state, current_state );
+
+ if ( _States_Is_ready( current_state ) ) {
+ _Scheduler_Unblock( the_thread );
+ }
+ }
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/threadclose.c b/cpukit/score/src/threadclose.c
new file mode 100644
index 0000000000..ea2ee5bda4
--- /dev/null
+++ b/cpukit/score/src/threadclose.c
@@ -0,0 +1,104 @@
+/*
+ * Thread Handler / Thread Close
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+void _Thread_Close(
+ Objects_Information *information,
+ Thread_Control *the_thread
+)
+{
+ /*
+ * Now we are in a dispatching critical section again and we
+ * can take the thread OUT of the published set. It is invalid
+ * to use this thread's Id after this call. This will prevent
+ * any other task from attempting to initiate a call on this task.
+ */
+ _Objects_Invalidate_Id( information, &the_thread->Object );
+
+ /*
+ * We assume the Allocator Mutex is locked when we get here.
+ * This provides sufficient protection to let the user extensions
+ * run but as soon as we get back, we will make the thread
+ * disappear and set a transient state on it. So we temporarily
+ * unnest dispatching.
+ */
+ _Thread_Unnest_dispatch();
+
+ _User_extensions_Thread_delete( the_thread );
+
+ _Thread_Disable_dispatch();
+
+ /*
+ * Now we are in a dispatching critical section again and we
+ * can take the thread OUT of the published set. It is invalid
+ * to use this thread's Id OR name after this call.
+ */
+ _Objects_Close( information, &the_thread->Object );
+
+ /*
+ * By setting the dormant state, the thread will not be considered
+ * for scheduling when we remove any blocking states.
+ */
+ _Thread_Set_state( the_thread, STATES_DORMANT );
+
+ if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) {
+ if ( _Watchdog_Is_active( &the_thread->Timer ) )
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ }
+
+ /*
+ * Free the per-thread scheduling information.
+ */
+ _Scheduler_Free( the_thread );
+
+ /*
+ * The thread might have been FP. So deal with that.
+ */
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
+ if ( _Thread_Is_allocated_fp( the_thread ) )
+ _Thread_Deallocate_fp();
+#endif
+ the_thread->fp_context = NULL;
+
+ _Workspace_Free( the_thread->Start.fp_context );
+#endif
+
+ /*
+ * Free the rest of the memory associated with this task
+ * and set the associated pointers to NULL for safety.
+ */
+ _Thread_Stack_Free( the_thread );
+ the_thread->Start.stack = NULL;
+
+ _Workspace_Free( the_thread->extensions );
+ the_thread->extensions = NULL;
+}
diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c
new file mode 100644
index 0000000000..6a4bf65e9c
--- /dev/null
+++ b/cpukit/score/src/threadcreateidle.c
@@ -0,0 +1,106 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/config.h>
+#include <rtems/bspsmp.h>
+
+static inline void _Thread_Create_idle_helper(
+ uint32_t name_u32,
+ int cpu
+)
+{
+ Objects_Name name;
+ Thread_Control *idle;
+
+ name.name_u32 = name_u32;
+
+ /*
+ * The entire workspace is zeroed during its initialization. Thus, all
+ * fields not explicitly assigned were explicitly zeroed by
+ * _Workspace_Initialization.
+ */
+ idle = _Thread_Internal_allocate();
+
+ /*
+ * This is only called during initialization and we better be sure
+ * that when _Thread_Initialize unnests dispatch that we do not
+ * do anything stupid.
+ */
+ _Thread_Disable_dispatch();
+
+ _Thread_Initialize(
+ &_Thread_Internal_information,
+ idle,
+ NULL, /* allocate the stack */
+ _Stack_Ensure_minimum( Configuration.idle_task_stack_size ),
+ CPU_IDLE_TASK_IS_FP,
+ PRIORITY_MAXIMUM,
+ true, /* preemptable */
+ THREAD_CPU_BUDGET_ALGORITHM_NONE,
+ NULL, /* no budget algorithm callout */
+ 0, /* all interrupts enabled */
+ name
+ );
+
+ _Thread_Unnest_dispatch();
+
+ /*
+ * WARNING!!! This is necessary to "kick" start the system and
+ * MUST be done before _Thread_Start is invoked.
+ */
+ _Per_CPU_Information[ cpu ].idle =
+ _Per_CPU_Information[ cpu ].heir =
+ _Per_CPU_Information[ cpu ].executing = idle;
+
+ _Thread_Start(
+ idle,
+ THREAD_START_NUMERIC,
+ Configuration.idle_task,
+ NULL,
+ 0
+ );
+}
+
+void _Thread_Create_idle( void )
+{
+ #if defined(RTEMS_SMP)
+ int cpu;
+
+ for ( cpu=0 ; cpu < _SMP_Processor_count ; cpu++ ) {
+ _Thread_Create_idle_helper(
+ _Objects_Build_name( 'I', 'D', 'L', 'E' ),
+ cpu
+ );
+ }
+ #else
+ _Thread_Create_idle_helper(_Objects_Build_name( 'I', 'D', 'L', 'E' ), 0);
+ #endif
+}
diff --git a/cpukit/score/src/threaddelayended.c b/cpukit/score/src/threaddelayended.c
new file mode 100644
index 0000000000..4f72764608
--- /dev/null
+++ b/cpukit/score/src/threaddelayended.c
@@ -0,0 +1,71 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _Thread_Delay_ended
+ *
+ * This routine processes a thread whose delay period has ended.
+ * It is called by the watchdog handler.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_Delay_ended(
+ Objects_Id id,
+ void *ignored __attribute__((unused))
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+ case OBJECTS_ERROR:
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* impossible */
+#endif
+ break;
+ case OBJECTS_LOCAL:
+ _Thread_Clear_state(
+ the_thread,
+ STATES_DELAYING
+ | STATES_WAITING_FOR_TIME
+ | STATES_INTERRUPTIBLE_BY_SIGNAL
+ );
+ _Thread_Unnest_dispatch();
+ break;
+ }
+}
diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c
new file mode 100644
index 0000000000..5e0828e2a6
--- /dev/null
+++ b/cpukit/score/src/threaddispatch.c
@@ -0,0 +1,193 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ #include <rtems/score/timestamp.h>
+#endif
+
+/*PAGE
+ *
+ * _Thread_Enable_dispatch
+ *
+ * This kernel routine exits a context switch disable critical section.
+ * This is the NOT INLINED version.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * dispatch thread
+ * no dispatch thread
+ */
+
+#if ( (defined(CPU_INLINE_ENABLE_DISPATCH) && \
+ (CPU_INLINE_ENABLE_DISPATCH == FALSE)) || \
+ (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1) )
+void _Thread_Enable_dispatch( void )
+{
+ if ( --_Thread_Dispatch_disable_level )
+ return;
+ _Thread_Dispatch();
+}
+#endif
+
+/*PAGE
+ *
+ * _Thread_Dispatch
+ *
+ * This kernel routine determines if a dispatch is needed, and if so
+ * dispatches to the heir thread. Once the heir is running an attempt
+ * is made to dispatch any ASRs.
+ *
+ * ALTERNATE ENTRY POINTS:
+ * void _Thread_Enable_dispatch();
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * dispatch thread
+ * no dispatch thread
+ */
+
+void _Thread_Dispatch( void )
+{
+ Thread_Control *executing;
+ Thread_Control *heir;
+ ISR_Level level;
+
+ executing = _Thread_Executing;
+ _ISR_Disable( level );
+ while ( _Thread_Dispatch_necessary == true ) {
+ heir = _Thread_Heir;
+ _Thread_Dispatch_disable_level = 1;
+ _Thread_Dispatch_necessary = false;
+ _Thread_Executing = heir;
+
+ /*
+ * When the heir and executing are the same, then we are being
+ * requested to do the post switch dispatching. This is normally
+ * done to dispatch signals.
+ */
+ if ( heir == executing )
+ goto post_switch;
+
+ /*
+ * Since heir and executing are not the same, we need to do a real
+ * context switch.
+ */
+#if __RTEMS_ADA__
+ executing->rtems_ada_self = rtems_ada_self;
+ rtems_ada_self = heir->rtems_ada_self;
+#endif
+ if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
+ heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
+
+ _ISR_Enable( level );
+
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ {
+ Timestamp_Control uptime, ran;
+ _TOD_Get_uptime( &uptime );
+ _Timestamp_Subtract(
+ &_Thread_Time_of_last_context_switch,
+ &uptime,
+ &ran
+ );
+ _Timestamp_Add_to( &executing->cpu_time_used, &ran );
+ _Thread_Time_of_last_context_switch = uptime;
+ }
+ #else
+ heir->cpu_time_used++;
+ #endif
+
+ /*
+ * Switch libc's task specific data.
+ */
+ if ( _Thread_libc_reent ) {
+ executing->libc_reent = *_Thread_libc_reent;
+ *_Thread_libc_reent = heir->libc_reent;
+ }
+
+ _User_extensions_Thread_switch( executing, heir );
+
+ /*
+ * If the CPU has hardware floating point, then we must address saving
+ * and restoring it as part of the context switch.
+ *
+ * The second conditional compilation section selects the algorithm used
+ * to context switch between floating point tasks. The deferred algorithm
+ * can be significantly better in a system with few floating point tasks
+ * because it reduces the total number of save and restore FP context
+ * operations. However, this algorithm can not be used on all CPUs due
+ * to unpredictable use of FP registers by some compilers for integer
+ * operations.
+ */
+
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
+ if ( executing->fp_context != NULL )
+ _Context_Save_fp( &executing->fp_context );
+#endif
+#endif
+
+ _Context_Switch( &executing->Registers, &heir->Registers );
+
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
+ if ( (executing->fp_context != NULL) &&
+ !_Thread_Is_allocated_fp( executing ) ) {
+ if ( _Thread_Allocated_fp != NULL )
+ _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
+ _Context_Restore_fp( &executing->fp_context );
+ _Thread_Allocated_fp = executing;
+ }
+#else
+ if ( executing->fp_context != NULL )
+ _Context_Restore_fp( &executing->fp_context );
+#endif
+#endif
+
+ executing = _Thread_Executing;
+
+ _ISR_Disable( level );
+ }
+
+post_switch:
+ _Thread_Dispatch_disable_level = 0;
+
+ _ISR_Enable( level );
+
+ _API_extensions_Run_postswitch();
+}
diff --git a/cpukit/score/src/threadget.c b/cpukit/score/src/threadget.c
new file mode 100644
index 0000000000..30574a3617
--- /dev/null
+++ b/cpukit/score/src/threadget.c
@@ -0,0 +1,100 @@
+/*
+ * Thread Handler - Object Id to Thread Pointer
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+
+
+/**
+ * This function maps thread IDs to thread control
+ * blocks. If ID corresponds to a local thread, then it
+ * returns the_thread control pointer which maps to ID
+ * and location is set to OBJECTS_LOCAL. If the thread ID is
+ * global and resides on a remote node, then location is set
+ * to OBJECTS_REMOTE, and the_thread is undefined.
+ * Otherwise, location is set to OBJECTS_ERROR and
+ * the_thread is undefined.
+ *
+ * @note The performance of many RTEMS services depends upon
+ * the quick execution of the "good object" path in this
+ * routine. If there is a possibility of saving a few
+ * cycles off the execution time, this routine is worth
+ * further optimization attention.
+ */
+Thread_Control *_Thread_Get (
+ Objects_Id id,
+ Objects_Locations *location
+)
+{
+ uint32_t the_api;
+ uint32_t the_class;
+ Objects_Information **api_information;
+ Objects_Information *information;
+ Thread_Control *tp = (Thread_Control *) 0;
+
+ if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
+ _Thread_Disable_dispatch();
+ *location = OBJECTS_LOCAL;
+ tp = _Thread_Executing;
+ goto done;
+ }
+
+ the_api = _Objects_Get_API( id );
+ if ( !_Objects_Is_api_valid( the_api ) ) {
+ *location = OBJECTS_ERROR;
+ goto done;
+ }
+
+ the_class = _Objects_Get_class( id );
+ if ( the_class != 1 ) { /* threads are always first class :) */
+ *location = OBJECTS_ERROR;
+ goto done;
+ }
+
+ api_information = _Objects_Information_table[ the_api ];
+ /*
+ * There is no way for this to happen if POSIX is enabled. But there
+ * is actually a test case in sp43 for this which trips it whether or
+ * not POSIX is enabled. So in the interest of safety, this is left
+ * on in all configurations.
+ */
+ if ( !api_information ) {
+ *location = OBJECTS_ERROR;
+ goto done;
+ }
+
+ information = api_information[ the_class ];
+ if ( !information ) {
+ *location = OBJECTS_ERROR;
+ goto done;
+ }
+
+ tp = (Thread_Control *) _Objects_Get( information, id, location );
+
+done:
+ return tp;
+}
+
diff --git a/cpukit/score/src/threadhandler.c b/cpukit/score/src/threadhandler.c
new file mode 100644
index 0000000000..37185ad745
--- /dev/null
+++ b/cpukit/score/src/threadhandler.c
@@ -0,0 +1,189 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+#if defined(__AVR__)
+ #undef __USE_INIT_FINI__
+#endif
+
+#if defined(__USE_INIT_FINI__)
+ #if defined(__M32R__)
+ #define INIT_NAME __init
+ #else
+ #define INIT_NAME _init
+ #endif
+
+ extern void INIT_NAME(void);
+ #define EXECUTE_GLOBAL_CONSTRUCTORS
+#endif
+
+#if defined(__USE__MAIN__)
+ extern void _main(void);
+ #define INIT_NAME __main
+ #define EXECUTE_GLOBAL_CONSTRUCTORS
+#endif
+
+/*PAGE
+ *
+ * _Thread_Handler
+ *
+ * This routine is the "primal" entry point for all threads.
+ * _Context_Initialize() dummies up the thread's initial context
+ * to cause the first Context_Switch() to jump to _Thread_Handler().
+ *
+ * This routine is the default thread exitted error handler. It is
+ * returned to when a thread exits. The configured fatal error handler
+ * is invoked to process the exit.
+ *
+ * NOTE:
+ *
+ * On entry, it is assumed all interrupts are blocked and that this
+ * routine needs to set the initial isr level. This may or may not
+ * actually be needed by the context switch routine and as a result
+ * interrupts may already be at there proper level. Either way,
+ * setting the initial isr level properly here is safe.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_Handler( void )
+{
+ ISR_Level level;
+ Thread_Control *executing;
+ #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
+ static char doneConstructors;
+ char doneCons;
+ #endif
+
+ executing = _Thread_Executing;
+
+ /*
+ * Some CPUs need to tinker with the call frame or registers when the
+ * thread actually begins to execute for the first time. This is a
+ * hook point where the port gets a shot at doing whatever it requires.
+ */
+ _Context_Initialization_at_thread_begin();
+
+ /*
+ * have to put level into a register for those cpu's that use
+ * inline asm here
+ */
+
+ level = executing->Start.isr_level;
+ _ISR_Set_level(level);
+
+ #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
+ doneCons = doneConstructors;
+ doneConstructors = 1;
+ #endif
+
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
+ if ( (executing->fp_context != NULL) &&
+ !_Thread_Is_allocated_fp( executing ) ) {
+ if ( _Thread_Allocated_fp != NULL )
+ _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
+ _Thread_Allocated_fp = executing;
+ }
+ #endif
+ #endif
+
+ /*
+ * Take care that 'begin' extensions get to complete before
+ * 'switch' extensions can run. This means must keep dispatch
+ * disabled until all 'begin' extensions complete.
+ */
+ _User_extensions_Thread_begin( executing );
+
+ /*
+ * At this point, the dispatch disable level BETTER be 1.
+ */
+ _Thread_Enable_dispatch();
+
+ #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
+ /*
+ * _init could be a weak symbol and we SHOULD test it but it isn't
+ * in any configuration I know of and it generates a warning on every
+ * RTEMS target configuration. --joel (12 May 2007)
+ */
+ if (!doneCons) /* && (volatile void *)_init) */ {
+ INIT_NAME ();
+ }
+ #endif
+
+ if ( executing->Start.prototype == THREAD_START_NUMERIC ) {
+ executing->Wait.return_argument =
+ (*(Thread_Entry_numeric) executing->Start.entry_point)(
+ executing->Start.numeric_argument
+ );
+ }
+ #if defined(RTEMS_POSIX_API)
+ else if ( executing->Start.prototype == THREAD_START_POINTER ) {
+ executing->Wait.return_argument =
+ (*(Thread_Entry_pointer) executing->Start.entry_point)(
+ executing->Start.pointer_argument
+ );
+ }
+ #endif
+ #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
+ else if ( executing->Start.prototype == THREAD_START_BOTH_POINTER_FIRST ) {
+ executing->Wait.return_argument =
+ (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
+ executing->Start.pointer_argument,
+ executing->Start.numeric_argument
+ );
+ }
+ else if ( executing->Start.prototype == THREAD_START_BOTH_NUMERIC_FIRST ) {
+ executing->Wait.return_argument =
+ (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
+ executing->Start.numeric_argument,
+ executing->Start.pointer_argument
+ );
+ }
+ #endif
+
+ /*
+ * In the switch above, the return code from the user thread body
+ * was placed in return_argument. This assumed that if it returned
+ * anything (which is not supporting in all APIs), then it would be
+ * able to fit in a (void *).
+ */
+
+ _User_extensions_Thread_exitted( executing );
+
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_THREAD_EXITTED
+ );
+}
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
new file mode 100644
index 0000000000..adb0567d14
--- /dev/null
+++ b/cpukit/score/src/threadinitialize.c
@@ -0,0 +1,242 @@
+/*
+ * Thread Handler / Thread Initialize
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _Thread_Initialize
+ *
+ * This routine initializes the specified the thread. It allocates
+ * all memory associated with this thread. It completes by adding
+ * the thread to the local object table so operations on this
+ * thread id are allowed.
+ */
+
+bool _Thread_Initialize(
+ Objects_Information *information,
+ Thread_Control *the_thread,
+ void *stack_area,
+ size_t stack_size,
+ bool is_fp,
+ Priority_Control priority,
+ bool is_preemptible,
+ Thread_CPU_budget_algorithms budget_algorithm,
+ Thread_CPU_budget_algorithm_callout budget_callout,
+ uint32_t isr_level,
+ Objects_Name name
+)
+{
+ size_t actual_stack_size = 0;
+ void *stack = NULL;
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ void *fp_area;
+ #endif
+ void *sched = NULL;
+ void *extensions_area;
+ bool extension_status;
+ int i;
+
+ /*
+ * Initialize the Ada self pointer
+ */
+ #if __RTEMS_ADA__
+ the_thread->rtems_ada_self = NULL;
+ #endif
+
+ /*
+ * Zero out all the allocated memory fields
+ */
+ for ( i=0 ; i <= THREAD_API_LAST ; i++ )
+ the_thread->API_Extensions[i] = NULL;
+
+ extensions_area = NULL;
+ the_thread->libc_reent = NULL;
+
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ fp_area = NULL;
+ #endif
+
+ /*
+ * Allocate and Initialize the stack for this thread.
+ */
+ #if !defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
+ actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
+ if ( !actual_stack_size || actual_stack_size < stack_size )
+ return false; /* stack allocation failed */
+
+ stack = the_thread->Start.stack;
+ #else
+ if ( !stack_area ) {
+ actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
+ if ( !actual_stack_size || actual_stack_size < stack_size )
+ return false; /* stack allocation failed */
+
+ stack = the_thread->Start.stack;
+ the_thread->Start.core_allocated_stack = true;
+ } else {
+ stack = stack_area;
+ actual_stack_size = stack_size;
+ the_thread->Start.core_allocated_stack = false;
+ }
+ #endif
+
+ _Stack_Initialize(
+ &the_thread->Start.Initial_stack,
+ stack,
+ actual_stack_size
+ );
+
+ /*
+ * Allocate the floating point area for this thread
+ */
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ if ( is_fp ) {
+ fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
+ if ( !fp_area )
+ goto failed;
+ fp_area = _Context_Fp_start( fp_area, 0 );
+ }
+ the_thread->fp_context = fp_area;
+ the_thread->Start.fp_context = fp_area;
+ #endif
+
+ /*
+ * Initialize the thread timer
+ */
+ _Watchdog_Initialize( &the_thread->Timer, NULL, 0, NULL );
+
+ #ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ /* Initialize the head of chain of held mutexes */
+ _Chain_Initialize_empty(&the_thread->lock_mutex);
+ #endif
+
+ /*
+ * Allocate the extensions area for this thread
+ */
+ if ( _Thread_Maximum_extensions ) {
+ extensions_area = _Workspace_Allocate(
+ (_Thread_Maximum_extensions + 1) * sizeof( void * )
+ );
+ if ( !extensions_area )
+ goto failed;
+ }
+ the_thread->extensions = (void **) extensions_area;
+
+ /*
+ * Clear the extensions area so extension users can determine
+ * if they are linked to the thread. An extension user may
+ * create the extension long after tasks have been created
+ * so they cannot rely on the thread create user extension
+ * call.
+ */
+ if ( the_thread->extensions ) {
+ for ( i = 0; i <= _Thread_Maximum_extensions ; i++ )
+ the_thread->extensions[i] = NULL;
+ }
+
+ /*
+ * General initialization
+ */
+
+ the_thread->Start.is_preemptible = is_preemptible;
+ the_thread->Start.budget_algorithm = budget_algorithm;
+ the_thread->Start.budget_callout = budget_callout;
+
+ switch ( budget_algorithm ) {
+ case THREAD_CPU_BUDGET_ALGORITHM_NONE:
+ case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
+ break;
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
+ case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
+ the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
+ break;
+ #endif
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
+ case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
+ break;
+ #endif
+ }
+
+ the_thread->Start.isr_level = isr_level;
+
+ the_thread->current_state = STATES_DORMANT;
+ the_thread->Wait.queue = NULL;
+ the_thread->resource_count = 0;
+ the_thread->real_priority = priority;
+ the_thread->Start.initial_priority = priority;
+ sched =_Scheduler_Allocate( the_thread );
+ if ( !sched )
+ goto failed;
+ _Thread_Set_priority( the_thread, priority );
+
+ /*
+ * Initialize the CPU usage statistics
+ */
+ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ _Timestamp_Set_to_zero( &the_thread->cpu_time_used );
+ #else
+ the_thread->cpu_time_used = 0;
+ #endif
+
+ /*
+ * Open the object
+ */
+ _Objects_Open( information, &the_thread->Object, name );
+
+ /*
+ * We assume the Allocator Mutex is locked and dispatching is
+ * enabled when we get here. We want to be able to run the
+ * user extensions with dispatching enabled. The Allocator
+ * Mutex provides sufficient protection to let the user extensions
+ * run safely.
+ */
+ extension_status = _User_extensions_Thread_create( the_thread );
+ if ( extension_status )
+ return true;
+
+failed:
+ _Workspace_Free( the_thread->libc_reent );
+
+ for ( i=0 ; i <= THREAD_API_LAST ; i++ )
+ _Workspace_Free( the_thread->API_Extensions[i] );
+
+ _Workspace_Free( extensions_area );
+
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ _Workspace_Free( fp_area );
+ #endif
+
+ _Workspace_Free( sched );
+
+ _Thread_Stack_Free( the_thread );
+ return false;
+}
diff --git a/cpukit/score/src/threadloadenv.c b/cpukit/score/src/threadloadenv.c
new file mode 100644
index 0000000000..a2d5318c78
--- /dev/null
+++ b/cpukit/score/src/threadloadenv.c
@@ -0,0 +1,74 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _Thread_Load_environment
+ *
+ * Load starting environment for another thread from its start area in the
+ * thread. Only called from t_restart and t_start.
+ *
+ * Input parameters:
+ * the_thread - thread control block pointer
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_Load_environment(
+ Thread_Control *the_thread
+)
+{
+ bool is_fp;
+
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ if ( the_thread->Start.fp_context ) {
+ the_thread->fp_context = the_thread->Start.fp_context;
+ _Context_Initialize_fp( &the_thread->fp_context );
+ is_fp = true;
+ } else
+#endif
+ is_fp = false;
+
+ the_thread->is_preemptible = the_thread->Start.is_preemptible;
+ the_thread->budget_algorithm = the_thread->Start.budget_algorithm;
+ the_thread->budget_callout = the_thread->Start.budget_callout;
+
+ _Context_Initialize(
+ &the_thread->Registers,
+ the_thread->Start.Initial_stack.area,
+ the_thread->Start.Initial_stack.size,
+ the_thread->Start.isr_level,
+ _Thread_Handler,
+ is_fp
+ );
+
+}
diff --git a/cpukit/score/src/threadmp.c b/cpukit/score/src/threadmp.c
new file mode 100644
index 0000000000..ffd611b4ac
--- /dev/null
+++ b/cpukit/score/src/threadmp.c
@@ -0,0 +1,168 @@
+/*
+ * Multiprocessing Support for the Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/mpci.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/isr.h>
+
+/*PAGE
+ *
+ * _Thread_MP_Handler_initialization
+ *
+ */
+
+void _Thread_MP_Handler_initialization (
+ uint32_t maximum_proxies
+)
+{
+
+ _Chain_Initialize_empty( &_Thread_MP_Active_proxies );
+
+ if ( maximum_proxies == 0 ) {
+ _Chain_Initialize_empty( &_Thread_MP_Inactive_proxies );
+ return;
+ }
+
+
+ _Chain_Initialize(
+ &_Thread_MP_Inactive_proxies,
+ _Workspace_Allocate_or_fatal_error(
+ maximum_proxies * sizeof( Thread_Proxy_control )
+ ),
+ maximum_proxies,
+ sizeof( Thread_Proxy_control )
+ );
+
+}
+
+/*PAGE
+ *
+ * _Thread_MP_Allocate_proxy
+ *
+ */
+
+Thread_Control *_Thread_MP_Allocate_proxy (
+ States_Control the_state
+)
+{
+ Thread_Control *the_thread;
+ Thread_Proxy_control *the_proxy;
+
+ the_thread = (Thread_Control *)_Chain_Get( &_Thread_MP_Inactive_proxies );
+
+ if ( !_Thread_Is_null( the_thread ) ) {
+
+ the_proxy = (Thread_Proxy_control *) the_thread;
+
+ _Thread_Executing->Wait.return_code = THREAD_STATUS_PROXY_BLOCKING;
+
+ the_proxy->receive_packet = _MPCI_Receive_server_tcb->receive_packet;
+
+ the_proxy->Object.id = _MPCI_Receive_server_tcb->receive_packet->source_tid;
+
+ the_proxy->current_priority =
+ _MPCI_Receive_server_tcb->receive_packet->source_priority;
+
+ the_proxy->current_state = _States_Set( STATES_DORMANT, the_state );
+
+ the_proxy->Wait = _Thread_Executing->Wait;
+
+ _Chain_Append( &_Thread_MP_Active_proxies, &the_proxy->Active );
+
+ return the_thread;
+ }
+
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_OUT_OF_PROXIES
+ );
+
+ /*
+ * NOTE: The following return ensures that the compiler will
+ * think that all paths return a value.
+ */
+
+ return NULL;
+}
+
+/*PAGE
+ *
+ * _Thread_MP_Find_proxy
+ *
+ */
+
+/*
+ * The following macro provides the offset of the Active element
+ * in the Thread_Proxy_control structure. This is the logical
+ * equivalent of the POSITION attribute in Ada.
+ */
+
+#define _Thread_MP_Proxy_Active_offset \
+ ((uint32_t)&(((Thread_Proxy_control *)0))->Active)
+
+Thread_Control *_Thread_MP_Find_proxy (
+ Objects_Id the_id
+)
+{
+
+ Chain_Node *proxy_node;
+ Thread_Control *the_thread;
+ ISR_Level level;
+
+restart:
+
+ _ISR_Disable( level );
+
+ for ( proxy_node = _Chain_First( &_Thread_MP_Active_proxies );
+ !_Chain_Is_tail( &_Thread_MP_Active_proxies, proxy_node ) ;
+ ) {
+
+ the_thread = (Thread_Control *) _Addresses_Subtract_offset(
+ proxy_node,
+ _Thread_MP_Proxy_Active_offset
+ );
+
+ if ( _Objects_Are_ids_equal( the_thread->Object.id, the_id ) ) {
+ _ISR_Enable( level );
+ return the_thread;
+ }
+
+ _ISR_Flash( level );
+
+ proxy_node = _Chain_Next( proxy_node );
+
+ /*
+ * A proxy which is only dormant is not in a blocking state.
+ * Therefore, we are looking at proxy which has been moved from
+ * active to inactive chain (by an ISR) and need to restart
+ * the search.
+ */
+
+ if ( _States_Is_only_dormant( the_thread->current_state ) ) {
+ _ISR_Enable( level );
+ goto restart;
+ }
+ }
+
+ _ISR_Enable( level );
+ return NULL;
+}
diff --git a/cpukit/score/src/threadq.c b/cpukit/score/src/threadq.c
new file mode 100644
index 0000000000..baa85a13e1
--- /dev/null
+++ b/cpukit/score/src/threadq.c
@@ -0,0 +1,66 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Initialize
+ *
+ * This routine initializes the specified threadq.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to a threadq header
+ * discipline - queueing discipline
+ * state - state of waiting threads
+ * timeout_status - return on a timeout
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_queue_Initialize(
+ Thread_queue_Control *the_thread_queue,
+ Thread_queue_Disciplines the_discipline,
+ States_Control state,
+ uint32_t timeout_status
+)
+{
+ the_thread_queue->state = state;
+ the_thread_queue->discipline = the_discipline;
+ the_thread_queue->timeout_status = timeout_status;
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+
+ if ( the_discipline == THREAD_QUEUE_DISCIPLINE_PRIORITY ) {
+ uint32_t index;
+
+ for( index=0 ;
+ index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
+ index++)
+ _Chain_Initialize_empty( &the_thread_queue->Queues.Priority[index] );
+ } else { /* must be THREAD_QUEUE_DISCIPLINE_FIFO */
+ _Chain_Initialize_empty( &the_thread_queue->Queues.Fifo );
+ }
+
+}
diff --git a/cpukit/score/src/threadqdequeue.c b/cpukit/score/src/threadqdequeue.c
new file mode 100644
index 0000000000..b9213968b8
--- /dev/null
+++ b/cpukit/score/src/threadqdequeue.c
@@ -0,0 +1,72 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Dequeue
+ *
+ * This routine removes a thread from the specified threadq. If the
+ * threadq discipline is FIFO, it unblocks a thread, and cancels its
+ * timeout timer. Priority discipline is processed elsewhere.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq
+ *
+ * Output parameters:
+ * returns - thread dequeued or NULL
+ *
+ * INTERRUPT LATENCY:
+ * check sync
+ */
+
+Thread_Control *_Thread_queue_Dequeue(
+ Thread_queue_Control *the_thread_queue
+)
+{
+ Thread_Control *(*dequeue_p)( Thread_queue_Control * );
+ Thread_Control *the_thread;
+ ISR_Level level;
+ Thread_blocking_operation_States sync_state;
+
+ if ( the_thread_queue->discipline == THREAD_QUEUE_DISCIPLINE_PRIORITY )
+ dequeue_p = _Thread_queue_Dequeue_priority;
+ else /* must be THREAD_QUEUE_DISCIPLINE_FIFO */
+ dequeue_p = _Thread_queue_Dequeue_fifo;
+
+ the_thread = (*dequeue_p)( the_thread_queue );
+ _ISR_Disable( level );
+ if ( !the_thread ) {
+ sync_state = the_thread_queue->sync_state;
+ if ( (sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT) ||
+ (sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ) {
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SATISFIED;
+ the_thread = _Thread_Executing;
+ }
+ }
+ _ISR_Enable( level );
+ return the_thread;
+}
diff --git a/cpukit/score/src/threadqdequeuefifo.c b/cpukit/score/src/threadqdequeuefifo.c
new file mode 100644
index 0000000000..0ea36791fc
--- /dev/null
+++ b/cpukit/score/src/threadqdequeuefifo.c
@@ -0,0 +1,79 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Dequeue_fifo
+ *
+ * This routine removes a thread from the specified threadq.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq
+ *
+ * Output parameters:
+ * returns - thread dequeued or NULL
+ *
+ * INTERRUPT LATENCY:
+ * check sync
+ * FIFO
+ */
+
+Thread_Control *_Thread_queue_Dequeue_fifo(
+ Thread_queue_Control *the_thread_queue
+)
+{
+ ISR_Level level;
+ Thread_Control *the_thread;
+
+ _ISR_Disable( level );
+ if ( !_Chain_Is_empty( &the_thread_queue->Queues.Fifo ) ) {
+
+ the_thread = (Thread_Control *)
+ _Chain_Get_first_unprotected( &the_thread_queue->Queues.Fifo );
+
+ the_thread->Wait.queue = NULL;
+ if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
+ _ISR_Enable( level );
+ _Thread_Unblock( the_thread );
+ } else {
+ _Watchdog_Deactivate( &the_thread->Timer );
+ _ISR_Enable( level );
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ _Thread_Unblock( the_thread );
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ _Thread_MP_Free_proxy( the_thread );
+#endif
+
+ return the_thread;
+ }
+
+ _ISR_Enable( level );
+ return NULL;
+}
diff --git a/cpukit/score/src/threadqdequeuepriority.c b/cpukit/score/src/threadqdequeuepriority.c
new file mode 100644
index 0000000000..1a7bc7037a
--- /dev/null
+++ b/cpukit/score/src/threadqdequeuepriority.c
@@ -0,0 +1,125 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Dequeue_priority
+ *
+ * This routine removes a thread from the specified PRIORITY based
+ * threadq, unblocks it, and cancels its timeout timer.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to thread queue
+ *
+ * Output parameters:
+ * returns - thread dequeued or NULL
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+Thread_Control *_Thread_queue_Dequeue_priority(
+ Thread_queue_Control *the_thread_queue
+)
+{
+ uint32_t index;
+ ISR_Level level;
+ Thread_Control *the_thread = NULL; /* just to remove warnings */
+ Thread_Control *new_first_thread;
+ Chain_Node *head;
+ Chain_Node *tail;
+ Chain_Node *new_first_node;
+ Chain_Node *new_second_node;
+ Chain_Node *last_node;
+ Chain_Node *next_node;
+ Chain_Node *previous_node;
+
+ _ISR_Disable( level );
+ for( index=0 ;
+ index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
+ index++ ) {
+ if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
+ the_thread = (Thread_Control *) _Chain_First(
+ &the_thread_queue->Queues.Priority[ index ]
+ );
+ goto dequeue;
+ }
+ }
+
+ /*
+ * We did not find a thread to unblock.
+ */
+ _ISR_Enable( level );
+ return NULL;
+
+dequeue:
+ the_thread->Wait.queue = NULL;
+ new_first_node = _Chain_First( &the_thread->Wait.Block2n );
+ new_first_thread = (Thread_Control *) new_first_node;
+ next_node = the_thread->Object.Node.next;
+ previous_node = the_thread->Object.Node.previous;
+
+ if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
+ last_node = _Chain_Last( &the_thread->Wait.Block2n );
+ new_second_node = new_first_node->next;
+
+ previous_node->next = new_first_node;
+ next_node->previous = new_first_node;
+ new_first_node->next = next_node;
+ new_first_node->previous = previous_node;
+
+ if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
+ /* > two threads on 2-n */
+ head = _Chain_Head( &new_first_thread->Wait.Block2n );
+ tail = _Chain_Tail( &new_first_thread->Wait.Block2n );
+
+ new_second_node->previous = head;
+ head->next = new_second_node;
+ tail->previous = last_node;
+ last_node->next = tail;
+ }
+ } else {
+ previous_node->next = next_node;
+ next_node->previous = previous_node;
+ }
+
+ if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
+ _ISR_Enable( level );
+ _Thread_Unblock( the_thread );
+ } else {
+ _Watchdog_Deactivate( &the_thread->Timer );
+ _ISR_Enable( level );
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ _Thread_Unblock( the_thread );
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ _Thread_MP_Free_proxy( the_thread );
+#endif
+ return( the_thread );
+}
diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c
new file mode 100644
index 0000000000..dbb1661feb
--- /dev/null
+++ b/cpukit/score/src/threadqenqueue.c
@@ -0,0 +1,97 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Enqueue_with_handler
+ *
+ * This routine blocks a thread, places it on a thread, and optionally
+ * starts a timeout timer.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq
+ * timeout - interval to wait
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+void _Thread_queue_Enqueue_with_handler(
+ Thread_queue_Control *the_thread_queue,
+ Watchdog_Interval timeout,
+ Thread_queue_Timeout_callout handler
+)
+{
+ Thread_Control *the_thread;
+ ISR_Level level;
+ Thread_blocking_operation_States sync_state;
+ Thread_blocking_operation_States (*enqueue_p)(
+ Thread_queue_Control *,
+ Thread_Control *,
+ ISR_Level *
+ );
+
+ the_thread = _Thread_Executing;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( _Thread_MP_Is_receive( the_thread ) && the_thread->receive_packet )
+ the_thread = _Thread_MP_Allocate_proxy( the_thread_queue->state );
+ else
+#endif
+ /*
+ * Set the blocking state for this thread queue in the thread.
+ */
+ _Thread_Set_state( the_thread, the_thread_queue->state );
+
+ /*
+ * If the thread wants to timeout, then schedule its timer.
+ */
+ if ( timeout ) {
+ _Watchdog_Initialize(
+ &the_thread->Timer,
+ handler,
+ the_thread->Object.id,
+ NULL
+ );
+
+ _Watchdog_Insert_ticks( &the_thread->Timer, timeout );
+ }
+
+ /*
+ * Now enqueue the thread per the discipline for this thread queue.
+ */
+ if ( the_thread_queue->discipline == THREAD_QUEUE_DISCIPLINE_PRIORITY )
+ enqueue_p = _Thread_queue_Enqueue_priority;
+ else /* must be THREAD_QUEUE_DISCIPLINE_FIFO */
+ enqueue_p = _Thread_queue_Enqueue_fifo;
+
+ sync_state = (*enqueue_p)( the_thread_queue, the_thread, &level );
+ if ( sync_state != THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED )
+ _Thread_blocking_operation_Cancel( sync_state, the_thread, level );
+}
diff --git a/cpukit/score/src/threadqenqueuefifo.c b/cpukit/score/src/threadqenqueuefifo.c
new file mode 100644
index 0000000000..da3c809212
--- /dev/null
+++ b/cpukit/score/src/threadqenqueuefifo.c
@@ -0,0 +1,78 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Enqueue_fifo
+ *
+ * This routine places a blocked thread on a FIFO thread queue.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq
+ * the_thread - pointer to the thread to block
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * only case
+ */
+
+Thread_blocking_operation_States _Thread_queue_Enqueue_fifo (
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread,
+ ISR_Level *level_p
+)
+{
+ Thread_blocking_operation_States sync_state;
+ ISR_Level level;
+
+ _ISR_Disable( level );
+
+ sync_state = the_thread_queue->sync_state;
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+ if (sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) {
+ _Chain_Append_unprotected(
+ &the_thread_queue->Queues.Fifo,
+ &the_thread->Object.Node
+ );
+ the_thread->Wait.queue = the_thread_queue;
+
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+ _ISR_Enable( level );
+ return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
+ }
+
+ /*
+ * An interrupt completed the thread's blocking request.
+ * For example, the blocking thread could have been given
+ * the mutex by an ISR or timed out.
+ *
+ * WARNING! Returning with interrupts disabled!
+ */
+ *level_p = level;
+ return sync_state;
+}
diff --git a/cpukit/score/src/threadqenqueuepriority.c b/cpukit/score/src/threadqenqueuepriority.c
new file mode 100644
index 0000000000..0d30529e0f
--- /dev/null
+++ b/cpukit/score/src/threadqenqueuepriority.c
@@ -0,0 +1,197 @@
+/*
+ * Thread Queue Handler - Enqueue By Priority
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*
+ * Support the user forcing the unrolling to be disabled.
+ */
+#if __RTEMS_DO_NOT_UNROLL_THREADQ_ENQUEUE_PRIORITY__
+ #undef CPU_UNROLL_ENQUEUE_PRIORITY
+ #define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
+#endif
+
+/*PAGE
+ *
+ * _Thread_queue_Enqueue_priority
+ *
+ * This routine places a blocked thread on a priority thread queue.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq
+ * thread - thread to insert
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * forward less than
+ * forward equal
+ */
+
+Thread_blocking_operation_States _Thread_queue_Enqueue_priority (
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread,
+ ISR_Level *level_p
+)
+{
+ Priority_Control search_priority;
+ Thread_Control *search_thread;
+ ISR_Level level;
+ Chain_Control *header;
+ uint32_t header_index;
+ Chain_Node *the_node;
+ Chain_Node *next_node;
+ Chain_Node *previous_node;
+ Chain_Node *search_node;
+ Priority_Control priority;
+ States_Control block_state;
+
+ _Chain_Initialize_empty( &the_thread->Wait.Block2n );
+
+ priority = the_thread->current_priority;
+ header_index = _Thread_queue_Header_number( priority );
+ header = &the_thread_queue->Queues.Priority[ header_index ];
+ block_state = the_thread_queue->state;
+
+ if ( _Thread_queue_Is_reverse_search( priority ) )
+ goto restart_reverse_search;
+
+restart_forward_search:
+ search_priority = PRIORITY_MINIMUM - 1;
+ _ISR_Disable( level );
+ search_thread = (Thread_Control *) _Chain_First( header );
+ while ( !_Chain_Is_tail( header, (Chain_Node *)search_thread ) ) {
+ search_priority = search_thread->current_priority;
+ if ( priority <= search_priority )
+ break;
+
+#if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE )
+ search_thread = (Thread_Control *) search_thread->Object.Node.next;
+ if ( _Chain_Is_tail( header, (Chain_Node *)search_thread ) )
+ break;
+ search_priority = search_thread->current_priority;
+ if ( priority <= search_priority )
+ break;
+#endif
+ _ISR_Flash( level );
+ if ( !_States_Are_set( search_thread->current_state, block_state) ) {
+ _ISR_Enable( level );
+ goto restart_forward_search;
+ }
+ search_thread =
+ (Thread_Control *)search_thread->Object.Node.next;
+ }
+
+ if ( the_thread_queue->sync_state !=
+ THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED )
+ goto synchronize;
+
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+
+ if ( priority == search_priority )
+ goto equal_priority;
+
+ search_node = (Chain_Node *) search_thread;
+ previous_node = search_node->previous;
+ the_node = (Chain_Node *) the_thread;
+
+ the_node->next = search_node;
+ the_node->previous = previous_node;
+ previous_node->next = the_node;
+ search_node->previous = the_node;
+ the_thread->Wait.queue = the_thread_queue;
+ _ISR_Enable( level );
+ return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
+
+restart_reverse_search:
+ search_priority = PRIORITY_MAXIMUM + 1;
+
+ _ISR_Disable( level );
+ search_thread = (Thread_Control *) _Chain_Last( header );
+ while ( !_Chain_Is_head( header, (Chain_Node *)search_thread ) ) {
+ search_priority = search_thread->current_priority;
+ if ( priority >= search_priority )
+ break;
+#if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE )
+ search_thread = (Thread_Control *) search_thread->Object.Node.previous;
+ if ( _Chain_Is_head( header, (Chain_Node *)search_thread ) )
+ break;
+ search_priority = search_thread->current_priority;
+ if ( priority >= search_priority )
+ break;
+#endif
+ _ISR_Flash( level );
+ if ( !_States_Are_set( search_thread->current_state, block_state) ) {
+ _ISR_Enable( level );
+ goto restart_reverse_search;
+ }
+ search_thread = (Thread_Control *)
+ search_thread->Object.Node.previous;
+ }
+
+ if ( the_thread_queue->sync_state !=
+ THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED )
+ goto synchronize;
+
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+
+ if ( priority == search_priority )
+ goto equal_priority;
+
+ search_node = (Chain_Node *) search_thread;
+ next_node = search_node->next;
+ the_node = (Chain_Node *) the_thread;
+
+ the_node->next = next_node;
+ the_node->previous = search_node;
+ search_node->next = the_node;
+ next_node->previous = the_node;
+ the_thread->Wait.queue = the_thread_queue;
+ _ISR_Enable( level );
+ return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
+
+equal_priority: /* add at end of priority group */
+ search_node = _Chain_Tail( &search_thread->Wait.Block2n );
+ previous_node = search_node->previous;
+ the_node = (Chain_Node *) the_thread;
+
+ the_node->next = search_node;
+ the_node->previous = previous_node;
+ previous_node->next = the_node;
+ search_node->previous = the_node;
+ the_thread->Wait.queue = the_thread_queue;
+ _ISR_Enable( level );
+ return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
+
+synchronize:
+ /*
+ * An interrupt completed the thread's blocking request.
+ * For example, the blocking thread could have been given
+ * the mutex by an ISR or timed out.
+ *
+ * WARNING! Returning with interrupts disabled!
+ */
+ *level_p = level;
+ return the_thread_queue->sync_state;
+}
diff --git a/cpukit/score/src/threadqextract.c b/cpukit/score/src/threadqextract.c
new file mode 100644
index 0000000000..21aa2c2a46
--- /dev/null
+++ b/cpukit/score/src/threadqextract.c
@@ -0,0 +1,58 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Extract
+ *
+ * This routine removes a specific thread from the specified threadq,
+ * deletes any timeout, and unblocks the thread.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to a threadq header
+ * the_thread - pointer to a thread control block
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY: NONE
+ */
+
+void _Thread_queue_Extract(
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread
+)
+{
+ /*
+ * Can not use indirect function pointer here since Extract priority
+ * is a macro and the underlying methods do not have the same signature.
+ */
+ if ( the_thread_queue->discipline == THREAD_QUEUE_DISCIPLINE_PRIORITY )
+ _Thread_queue_Extract_priority( the_thread_queue, the_thread );
+ else /* must be THREAD_QUEUE_DISCIPLINE_FIFO */
+ _Thread_queue_Extract_fifo( the_thread_queue, the_thread );
+
+}
diff --git a/cpukit/score/src/threadqextractfifo.c b/cpukit/score/src/threadqextractfifo.c
new file mode 100644
index 0000000000..f40464d73c
--- /dev/null
+++ b/cpukit/score/src/threadqextractfifo.c
@@ -0,0 +1,78 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Extract_fifo
+ *
+ * This routine removes a specific thread from the specified threadq,
+ * deletes any timeout, and unblocks the thread.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to a threadq header
+ * the_thread - pointer to the thread to block
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * EXTRACT_FIFO
+ */
+
+void _Thread_queue_Extract_fifo(
+ Thread_queue_Control *the_thread_queue __attribute__((unused)),
+ Thread_Control *the_thread
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+
+ if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) {
+ _ISR_Enable( level );
+ return;
+ }
+
+ _Chain_Extract_unprotected( &the_thread->Object.Node );
+
+ the_thread->Wait.queue = NULL;
+
+ if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
+ _ISR_Enable( level );
+ } else {
+ _Watchdog_Deactivate( &the_thread->Timer );
+ _ISR_Enable( level );
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ }
+
+ _Thread_Unblock( the_thread );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ _Thread_MP_Free_proxy( the_thread );
+#endif
+
+}
diff --git a/cpukit/score/src/threadqextractpriority.c b/cpukit/score/src/threadqextractpriority.c
new file mode 100644
index 0000000000..d4ddc2aa84
--- /dev/null
+++ b/cpukit/score/src/threadqextractpriority.c
@@ -0,0 +1,125 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Extract_priority
+ *
+ * This routine removes a specific thread from the specified threadq,
+ * deletes any timeout, and unblocks the thread.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to a threadq header
+ * the_thread - pointer to a thread control block
+ * requeuing - true if requeuing and should not alter timeout or state
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY:
+ * EXTRACT_PRIORITY
+ */
+
+void _Thread_queue_Extract_priority_helper(
+ Thread_queue_Control *the_thread_queue __attribute__((unused)),
+ Thread_Control *the_thread,
+ bool requeuing
+)
+{
+ ISR_Level level;
+ Chain_Node *head;
+ Chain_Node *tail;
+ Chain_Node *the_node;
+ Chain_Node *next_node;
+ Chain_Node *previous_node;
+ Thread_Control *new_first_thread;
+ Chain_Node *new_first_node;
+ Chain_Node *new_second_node;
+ Chain_Node *last_node;
+
+ the_node = (Chain_Node *) the_thread;
+ _ISR_Disable( level );
+ if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) {
+ _ISR_Enable( level );
+ return;
+ }
+
+ /*
+ * The thread was actually waiting on a thread queue so let's remove it.
+ */
+
+ next_node = the_node->next;
+ previous_node = the_node->previous;
+
+ if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
+ new_first_node = _Chain_First( &the_thread->Wait.Block2n );
+ new_first_thread = (Thread_Control *) new_first_node;
+ last_node = _Chain_Last( &the_thread->Wait.Block2n );
+ new_second_node = new_first_node->next;
+
+ previous_node->next = new_first_node;
+ next_node->previous = new_first_node;
+ new_first_node->next = next_node;
+ new_first_node->previous = previous_node;
+
+ if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
+ /* > two threads on 2-n */
+ head = _Chain_Head( &new_first_thread->Wait.Block2n );
+ tail = _Chain_Tail( &new_first_thread->Wait.Block2n );
+
+ new_second_node->previous = head;
+ head->next = new_second_node;
+ tail->previous = last_node;
+ last_node->next = tail;
+ }
+ } else {
+ previous_node->next = next_node;
+ next_node->previous = previous_node;
+ }
+
+ /*
+ * If we are not supposed to touch timers or the thread's state, return.
+ */
+
+ if ( requeuing ) {
+ _ISR_Enable( level );
+ return;
+ }
+
+ if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
+ _ISR_Enable( level );
+ } else {
+ _Watchdog_Deactivate( &the_thread->Timer );
+ _ISR_Enable( level );
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ }
+ _Thread_Unblock( the_thread );
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ _Thread_MP_Free_proxy( the_thread );
+#endif
+}
diff --git a/cpukit/score/src/threadqextractwithproxy.c b/cpukit/score/src/threadqextractwithproxy.c
new file mode 100644
index 0000000000..450702b0e4
--- /dev/null
+++ b/cpukit/score/src/threadqextractwithproxy.c
@@ -0,0 +1,67 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Extract_with_proxy
+ *
+ * This routine extracts the_thread from the_thread_queue
+ * and ensures that if there is a proxy for this task on
+ * another node, it is also dealt with.
+ *
+ * XXX
+ */
+
+bool _Thread_queue_Extract_with_proxy(
+ Thread_Control *the_thread
+)
+{
+ States_Control state;
+
+ state = the_thread->current_state;
+
+ if ( _States_Is_waiting_on_thread_queue( state ) ) {
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _States_Is_waiting_for_rpc_reply( state ) &&
+ _States_Is_locally_blocked( state ) ) {
+ Objects_Information *the_information;
+ Objects_Thread_queue_Extract_callout proxy_extract_callout;
+
+ the_information = _Objects_Get_information_id( the_thread->Wait.id );
+ proxy_extract_callout =
+ (Objects_Thread_queue_Extract_callout) the_information->extract;
+
+ if ( proxy_extract_callout )
+ (*proxy_extract_callout)( the_thread );
+ }
+ #endif
+ _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
+
+ return true;
+ }
+ return false;
+}
diff --git a/cpukit/score/src/threadqfirst.c b/cpukit/score/src/threadqfirst.c
new file mode 100644
index 0000000000..8e268b87d9
--- /dev/null
+++ b/cpukit/score/src/threadqfirst.c
@@ -0,0 +1,54 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_First
+ *
+ * This routines returns a pointer to the first thread on the
+ * specified threadq.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to thread queue
+ *
+ * Output parameters:
+ * returns - first thread or NULL
+ */
+
+Thread_Control *_Thread_queue_First(
+ Thread_queue_Control *the_thread_queue
+)
+{
+ Thread_Control * (*first_p)(Thread_queue_Control *);
+
+ if ( the_thread_queue->discipline == THREAD_QUEUE_DISCIPLINE_PRIORITY )
+ first_p = _Thread_queue_First_priority;
+ else /* must be THREAD_QUEUE_DISCIPLINE_FIFO */
+ first_p = _Thread_queue_First_fifo;
+
+ return (*first_p)( the_thread_queue );
+}
diff --git a/cpukit/score/src/threadqfirstfifo.c b/cpukit/score/src/threadqfirstfifo.c
new file mode 100644
index 0000000000..bde7b45054
--- /dev/null
+++ b/cpukit/score/src/threadqfirstfifo.c
@@ -0,0 +1,50 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_First_fifo
+ *
+ * This routines returns a pointer to the first thread on the
+ * specified threadq.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq
+ *
+ * Output parameters:
+ * returns - first thread or NULL
+ */
+
+Thread_Control *_Thread_queue_First_fifo(
+ Thread_queue_Control *the_thread_queue
+)
+{
+ if ( !_Chain_Is_empty( &the_thread_queue->Queues.Fifo ) )
+ return (Thread_Control *) _Chain_First( &the_thread_queue->Queues.Fifo );
+
+ return NULL;
+}
diff --git a/cpukit/score/src/threadqfirstpriority.c b/cpukit/score/src/threadqfirstpriority.c
new file mode 100644
index 0000000000..e5f4bccfe4
--- /dev/null
+++ b/cpukit/score/src/threadqfirstpriority.c
@@ -0,0 +1,57 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_First_priority
+ *
+ * This routines returns a pointer to the first thread on the
+ * specified threadq.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to thread queue
+ *
+ * Output parameters:
+ * returns - first thread or NULL
+ */
+
+Thread_Control *_Thread_queue_First_priority (
+ Thread_queue_Control *the_thread_queue
+)
+{
+ uint32_t index;
+
+ for( index=0 ;
+ index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
+ index++ ) {
+ if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) )
+ return (Thread_Control *) _Chain_First(
+ &the_thread_queue->Queues.Priority[ index ]
+ );
+ }
+ return NULL;
+}
diff --git a/cpukit/score/src/threadqflush.c b/cpukit/score/src/threadqflush.c
new file mode 100644
index 0000000000..b777aa3fa1
--- /dev/null
+++ b/cpukit/score/src/threadqflush.c
@@ -0,0 +1,62 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Flush
+ *
+ * This kernel routine flushes the given thread queue.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to threadq to be flushed
+ * remote_extract_callout - pointer to routine which extracts a remote thread
+ * status - status to return to the thread
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_queue_Flush(
+ Thread_queue_Control *the_thread_queue,
+#if defined(RTEMS_MULTIPROCESSING)
+ Thread_queue_Flush_callout remote_extract_callout,
+#else
+ Thread_queue_Flush_callout remote_extract_callout __attribute__((unused)),
+#endif
+ uint32_t status
+)
+{
+ Thread_Control *the_thread;
+
+ while ( (the_thread = _Thread_queue_Dequeue( the_thread_queue )) ) {
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( !_Objects_Is_local_id( the_thread->Object.id ) )
+ ( *remote_extract_callout )( the_thread );
+ else
+#endif
+ the_thread->Wait.return_code = status;
+ }
+}
diff --git a/cpukit/score/src/threadqprocesstimeout.c b/cpukit/score/src/threadqprocesstimeout.c
new file mode 100644
index 0000000000..9683a6e728
--- /dev/null
+++ b/cpukit/score/src/threadqprocesstimeout.c
@@ -0,0 +1,57 @@
+/*
+ * Thread Queue Handler - Process Timeout Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+void _Thread_queue_Process_timeout(
+ Thread_Control *the_thread
+)
+{
+ Thread_queue_Control *the_thread_queue = the_thread->Wait.queue;
+
+ /*
+ * If the_thread_queue is not synchronized, then it is either
+ * "nothing happened", "timeout", or "satisfied". If the_thread
+ * is the executing thread, then it is in the process of blocking
+ * and it is the thread which is responsible for the synchronization
+ * process.
+ *
+ * If it is not satisfied, then it is "nothing happened" and
+ * this is the "timeout" transition. After a request is satisfied,
+ * a timeout is not allowed to occur.
+ */
+
+ if ( the_thread_queue->sync_state != THREAD_BLOCKING_OPERATION_SYNCHRONIZED &&
+ _Thread_Is_executing( the_thread ) ) {
+ if ( the_thread_queue->sync_state != THREAD_BLOCKING_OPERATION_SATISFIED ) {
+ the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
+ the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_TIMEOUT;
+ }
+ } else {
+ the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
+ _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
+ }
+}
+
diff --git a/cpukit/score/src/threadqrequeue.c b/cpukit/score/src/threadqrequeue.c
new file mode 100644
index 0000000000..bba22148fb
--- /dev/null
+++ b/cpukit/score/src/threadqrequeue.c
@@ -0,0 +1,74 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*PAGE
+ *
+ * _Thread_queue_Requeue
+ *
+ * This routine is invoked when a thread changes priority and should be
+ * moved to a different position on the thread queue.
+ *
+ * Input parameters:
+ * the_thread_queue - pointer to a threadq header
+ * the_thread - pointer to a thread control block
+ *
+ * Output parameters: NONE
+ *
+ * INTERRUPT LATENCY: NONE
+ */
+
+void _Thread_queue_Requeue(
+ Thread_queue_Control *the_thread_queue,
+ Thread_Control *the_thread
+)
+{
+ /*
+ * Just in case the thread really wasn't blocked on a thread queue
+ * when we get here.
+ */
+ if ( !the_thread_queue )
+ return;
+
+ /*
+ * If queueing by FIFO, there is nothing to do. This only applies to
+ * priority blocking discipline.
+ */
+ if ( the_thread_queue->discipline == THREAD_QUEUE_DISCIPLINE_PRIORITY ) {
+ Thread_queue_Control *tq = the_thread_queue;
+ ISR_Level level;
+ ISR_Level level_ignored;
+
+ _ISR_Disable( level );
+ if ( _States_Is_waiting_on_thread_queue( the_thread->current_state ) ) {
+ _Thread_queue_Enter_critical_section( tq );
+ _Thread_queue_Extract_priority_helper( tq, the_thread, true );
+ (void) _Thread_queue_Enqueue_priority( tq, the_thread, &level_ignored );
+ }
+ _ISR_Enable( level );
+ }
+}
+
diff --git a/cpukit/score/src/threadqtimeout.c b/cpukit/score/src/threadqtimeout.c
new file mode 100644
index 0000000000..4fa1d5817b
--- /dev/null
+++ b/cpukit/score/src/threadqtimeout.c
@@ -0,0 +1,60 @@
+/*
+ * Thread Queue Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/tqdata.h>
+
+/*
+ * _Thread_queue_Timeout
+ *
+ * This routine processes a thread which timeouts while waiting on
+ * a thread queue. It is called by the watchdog handler.
+ *
+ * Input parameters:
+ * id - thread id
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_queue_Timeout(
+ Objects_Id id,
+ void *ignored __attribute__((unused))
+)
+{
+ Thread_Control *the_thread;
+ Objects_Locations location;
+
+ the_thread = _Thread_Get( id, &location );
+ switch ( location ) {
+ case OBJECTS_ERROR:
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* impossible */
+#endif
+ break;
+ case OBJECTS_LOCAL:
+ _Thread_queue_Process_timeout( the_thread );
+ _Thread_Unnest_dispatch();
+ break;
+ }
+}
diff --git a/cpukit/score/src/threadready.c b/cpukit/score/src/threadready.c
new file mode 100644
index 0000000000..9e3a285d22
--- /dev/null
+++ b/cpukit/score/src/threadready.c
@@ -0,0 +1,51 @@
+/*
+ * Thread Handler / Thread Ready
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * INTERRUPT LATENCY:
+ * ready chain
+ * select heir
+ */
+void _Thread_Ready(
+ Thread_Control *the_thread
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+
+ the_thread->current_state = STATES_READY;
+
+ _Scheduler_Unblock( the_thread );
+
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/threadreset.c b/cpukit/score/src/threadreset.c
new file mode 100644
index 0000000000..57b5605d30
--- /dev/null
+++ b/cpukit/score/src/threadreset.c
@@ -0,0 +1,67 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Thread_Reset
+ *
+ * DESCRIPTION:
+ *
+ * This routine resets a thread to its initial stat but does
+ * not actually restart it. Some APIs do this in separate
+ * operations and this division helps support this.
+ */
+
+void _Thread_Reset(
+ Thread_Control *the_thread,
+ void *pointer_argument,
+ Thread_Entry_numeric_type numeric_argument
+)
+{
+ the_thread->resource_count = 0;
+ the_thread->is_preemptible = the_thread->Start.is_preemptible;
+ the_thread->budget_algorithm = the_thread->Start.budget_algorithm;
+ the_thread->budget_callout = the_thread->Start.budget_callout;
+
+ the_thread->Start.pointer_argument = pointer_argument;
+ the_thread->Start.numeric_argument = numeric_argument;
+
+ if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) {
+
+ if ( _Watchdog_Is_active( &the_thread->Timer ) )
+ (void) _Watchdog_Remove( &the_thread->Timer );
+ }
+
+ if ( the_thread->current_priority != the_thread->Start.initial_priority ) {
+ the_thread->real_priority = the_thread->Start.initial_priority;
+ _Thread_Set_priority( the_thread, the_thread->Start.initial_priority );
+ }
+}
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
new file mode 100644
index 0000000000..37af4d805f
--- /dev/null
+++ b/cpukit/score/src/threadrestart.c
@@ -0,0 +1,68 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Thread_Restart
+ *
+ * DESCRIPTION:
+ *
+ * This support routine restarts the specified task in a way that the
+ * next time this thread executes, it will begin execution at its
+ * original starting point.
+ */
+
+bool _Thread_Restart(
+ Thread_Control *the_thread,
+ void *pointer_argument,
+ Thread_Entry_numeric_type numeric_argument
+)
+{
+ if ( !_States_Is_dormant( the_thread->current_state ) ) {
+
+ _Thread_Set_transient( the_thread );
+
+ _Thread_Reset( the_thread, pointer_argument, numeric_argument );
+
+ _Thread_Load_environment( the_thread );
+
+ _Thread_Ready( the_thread );
+
+ _User_extensions_Thread_restart( the_thread );
+
+ if ( _Thread_Is_executing ( the_thread ) )
+ _Thread_Restart_self();
+
+ return true;
+ }
+
+ return false;
+}
diff --git a/cpukit/score/src/threadsetpriority.c b/cpukit/score/src/threadsetpriority.c
new file mode 100644
index 0000000000..678df56fc8
--- /dev/null
+++ b/cpukit/score/src/threadsetpriority.c
@@ -0,0 +1,30 @@
+/*
+ * Thread Handler / Thread Set Priority
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/thread.h>
+
+void _Thread_Set_priority(
+ Thread_Control *the_thread,
+ Priority_Control new_priority
+)
+{
+ the_thread->current_priority = new_priority;
+
+ _Scheduler_Update( the_thread );
+}
diff --git a/cpukit/score/src/threadsetstate.c b/cpukit/score/src/threadsetstate.c
new file mode 100644
index 0000000000..1dcf33344c
--- /dev/null
+++ b/cpukit/score/src/threadsetstate.c
@@ -0,0 +1,58 @@
+/*
+ * Thread Handler / Thread Set State
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * INTERRUPT LATENCY:
+ * ready chain
+ * select map
+ */
+void _Thread_Set_state(
+ Thread_Control *the_thread,
+ States_Control state
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+ if ( !_States_Is_ready( the_thread->current_state ) ) {
+ the_thread->current_state =
+ _States_Set( state, the_thread->current_state );
+ _ISR_Enable( level );
+ return;
+ }
+
+ the_thread->current_state = state;
+
+ _Scheduler_Block( the_thread );
+
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/threadsettransient.c b/cpukit/score/src/threadsettransient.c
new file mode 100644
index 0000000000..11f91ed30e
--- /dev/null
+++ b/cpukit/score/src/threadsettransient.c
@@ -0,0 +1,56 @@
+/*
+ * Thread Handler / Thread Set Transient
+ *
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/schedulerpriority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * INTERRUPT LATENCY:
+ * only case
+ */
+void _Thread_Set_transient(
+ Thread_Control *the_thread
+)
+{
+ ISR_Level level;
+ uint32_t old_state;
+
+ _ISR_Disable( level );
+
+ old_state = the_thread->current_state;
+ the_thread->current_state = _States_Set( STATES_TRANSIENT, old_state );
+
+ if ( _States_Is_ready( old_state ) ) {
+ _Scheduler_Extract( the_thread );
+ }
+
+ _ISR_Enable( level );
+
+}
diff --git a/cpukit/score/src/threadstackallocate.c b/cpukit/score/src/threadstackallocate.c
new file mode 100644
index 0000000000..d8e21ea1f6
--- /dev/null
+++ b/cpukit/score/src/threadstackallocate.c
@@ -0,0 +1,84 @@
+/*
+ * Thread Handler - Stack Allocate Helper
+ *
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/config.h>
+
+/*PAGE
+ *
+ * _Thread_Stack_Allocate
+ *
+ * Allocate the requested stack space for the thread.
+ * return the actual size allocated after any adjustment
+ * or return zero if the allocation failed.
+ * Set the Start.stack field to the address of the stack
+ */
+
+size_t _Thread_Stack_Allocate(
+ Thread_Control *the_thread,
+ size_t stack_size
+)
+{
+ void *stack_addr = 0;
+ size_t the_stack_size;
+
+ the_stack_size = _Stack_Ensure_minimum( stack_size );
+
+ /*
+ * Call ONLY the CPU table stack allocate hook, _or_ the
+ * the RTEMS workspace allocate. This is so the stack free
+ * routine can call the correct deallocation routine.
+ */
+
+ if ( Configuration.stack_allocate_hook ) {
+ stack_addr = (*Configuration.stack_allocate_hook)( the_stack_size );
+ } else {
+
+ /*
+ * First pad the requested size so we allocate enough memory
+ * so the context initialization can align it properly. The address
+ * returned the workspace allocate must be directly stored in the
+ * stack control block because it is later used in the free sequence.
+ *
+ * Thus it is the responsibility of the CPU dependent code to
+ * get and keep the stack adjust factor, the stack alignment, and
+ * the context initialization sequence in sync.
+ */
+
+ the_stack_size = _Stack_Adjust_size( the_stack_size );
+ stack_addr = _Workspace_Allocate( the_stack_size );
+ }
+
+ if ( !stack_addr )
+ the_stack_size = 0;
+
+ the_thread->Start.stack = stack_addr;
+
+ return the_stack_size;
+}
diff --git a/cpukit/score/src/threadstackfree.c b/cpukit/score/src/threadstackfree.c
new file mode 100644
index 0000000000..64e0278e1b
--- /dev/null
+++ b/cpukit/score/src/threadstackfree.c
@@ -0,0 +1,62 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/config.h>
+
+/*
+ * _Thread_Stack_Free
+ *
+ * Deallocate the Thread's stack.
+ */
+
+void _Thread_Stack_Free(
+ Thread_Control *the_thread
+)
+{
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
+ /*
+ * If the API provided the stack space, then don't free it.
+ */
+ if ( !the_thread->Start.core_allocated_stack )
+ return;
+ #endif
+
+ /*
+ * Call ONLY the CPU table stack free hook, or the
+ * the RTEMS workspace free. This is so the free
+ * routine properly matches the allocation of the stack.
+ */
+
+ if ( Configuration.stack_free_hook )
+ (*Configuration.stack_free_hook)( the_thread->Start.Initial_stack.area );
+ else
+ _Workspace_Free( the_thread->Start.Initial_stack.area );
+}
diff --git a/cpukit/score/src/threadstart.c b/cpukit/score/src/threadstart.c
new file mode 100644
index 0000000000..1bc293c96f
--- /dev/null
+++ b/cpukit/score/src/threadstart.c
@@ -0,0 +1,69 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*
+ * _Thread_Start
+ *
+ * DESCRIPTION:
+ *
+ * This routine initializes the executable information for a thread
+ * and makes it ready to execute. After this routine executes, the
+ * thread competes with all other threads for CPU time.
+ */
+
+bool _Thread_Start(
+ Thread_Control *the_thread,
+ Thread_Start_types the_prototype,
+ void *entry_point,
+ void *pointer_argument,
+ Thread_Entry_numeric_type numeric_argument
+)
+{
+ if ( _States_Is_dormant( the_thread->current_state ) ) {
+
+ the_thread->Start.entry_point = (Thread_Entry) entry_point;
+
+ the_thread->Start.prototype = the_prototype;
+ the_thread->Start.pointer_argument = pointer_argument;
+ the_thread->Start.numeric_argument = numeric_argument;
+
+ _Thread_Load_environment( the_thread );
+
+ _Thread_Ready( the_thread );
+
+ _User_extensions_Thread_start( the_thread );
+
+ return true;
+ }
+
+ return false;
+}
diff --git a/cpukit/score/src/threadstartmultitasking.c b/cpukit/score/src/threadstartmultitasking.c
new file mode 100644
index 0000000000..efb2dae189
--- /dev/null
+++ b/cpukit/score/src/threadstartmultitasking.c
@@ -0,0 +1,91 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _Thread_Start_multitasking
+ *
+ * This kernel routine readies the requested thread, the thread chain
+ * is adjusted. A new heir thread may be selected.
+ *
+ * Input parameters:
+ * system_thread - pointer to system initialization thread control block
+ * idle_thread - pointer to idle thread control block
+ *
+ * Output parameters: NONE
+ *
+ * NOTE: This routine uses the "blocking" heir selection mechanism.
+ * This ensures the correct heir after a thread restart.
+ *
+ * INTERRUPT LATENCY:
+ * ready chain
+ * select heir
+ */
+
+void _Thread_Start_multitasking( void )
+{
+ /*
+ * The system is now multitasking and completely initialized.
+ * This system thread now "hides" in a single processor until
+ * the system is shut down.
+ */
+
+ _System_state_Set( SYSTEM_STATE_UP );
+
+ _Thread_Dispatch_necessary = false;
+
+ _Thread_Executing = _Thread_Heir;
+
+ /*
+ * Get the init task(s) running.
+ *
+ * Note: Thread_Dispatch() is normally used to dispatch threads. As
+ * part of its work, Thread_Dispatch() restores floating point
+ * state for the heir task.
+ *
+ * This code avoids Thread_Dispatch(), and so we have to restore
+ * (actually initialize) the floating point state "by hand".
+ *
+ * Ignore the CPU_USE_DEFERRED_FP_SWITCH because we must always
+ * switch in the first thread if it is FP.
+ */
+#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ /*
+ * don't need to worry about saving BSP's floating point state
+ */
+
+ if ( _Thread_Heir->fp_context != NULL )
+ _Context_Restore_fp( &_Thread_Heir->fp_context );
+#endif
+
+ _Context_Switch( &_Thread_BSP_context, &_Thread_Heir->Registers );
+}
diff --git a/cpukit/score/src/threadtickletimeslice.c b/cpukit/score/src/threadtickletimeslice.c
new file mode 100644
index 0000000000..50ded7f6a7
--- /dev/null
+++ b/cpukit/score/src/threadtickletimeslice.c
@@ -0,0 +1,105 @@
+/*
+ * Thread Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/apiext.h>
+#include <rtems/score/context.h>
+#include <rtems/score/interr.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/object.h>
+#include <rtems/score/priority.h>
+#include <rtems/score/scheduler.h>
+#include <rtems/score/states.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/threadq.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+
+/*PAGE
+ *
+ * _Thread_Tickle_timeslice
+ *
+ * This scheduler routine determines if timeslicing is enabled
+ * for the currently executing thread and, if so, updates the
+ * timeslice count and checks for timeslice expiration.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Thread_Tickle_timeslice( void )
+{
+ Thread_Control *executing;
+
+ executing = _Thread_Executing;
+
+ #ifdef __RTEMS_USE_TICKS_FOR_STATISTICS__
+ /*
+ * Increment the number of ticks this thread has been executing
+ */
+ executing->cpu_time_used++;
+ #endif
+
+ /*
+ * If the thread is not preemptible or is not ready, then
+ * just return.
+ */
+
+ if ( !executing->is_preemptible )
+ return;
+
+ if ( !_States_Is_ready( executing->current_state ) )
+ return;
+
+ /*
+ * The cpu budget algorithm determines what happens next.
+ */
+
+ switch ( executing->budget_algorithm ) {
+ case THREAD_CPU_BUDGET_ALGORITHM_NONE:
+ break;
+
+ case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
+ case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
+ #endif
+ if ( (int)(--executing->cpu_time_budget) <= 0 ) {
+
+ /*
+ * A yield performs the ready chain mechanics needed when
+ * resetting a timeslice. If no other thread's are ready
+ * at the priority of the currently executing thread, then the
+ * executing thread's timeslice is reset. Otherwise, the
+ * currently executing thread is placed at the rear of the
+ * FIFO for this priority and a new heir is selected.
+ */
+ _Scheduler_Yield( );
+ executing->cpu_time_budget = _Thread_Ticks_per_timeslice;
+ }
+ break;
+
+ #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
+ case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
+ if ( --executing->cpu_time_budget == 0 )
+ (*executing->budget_callout)( executing );
+ break;
+ #endif
+ }
+}
diff --git a/cpukit/score/src/timespecaddto.c b/cpukit/score/src/timespecaddto.c
new file mode 100644
index 0000000000..ac764b83c1
--- /dev/null
+++ b/cpukit/score/src/timespecaddto.c
@@ -0,0 +1,51 @@
+/**
+ * @file score/src/timespecaddto.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ *
+ * This routines adds two timespecs. The second argument is added
+ * to the first.
+ */
+
+uint32_t _Timespec_Add_to(
+ struct timespec *time,
+ const struct timespec *add
+)
+{
+ uint32_t seconds = add->tv_sec;
+
+ /* Add the basics */
+ time->tv_sec += add->tv_sec;
+ time->tv_nsec += add->tv_nsec;
+
+ /* Now adjust it so nanoseconds is in range */
+ while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
+ time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
+ time->tv_sec++;
+ seconds++;
+ }
+
+ return seconds;
+}
diff --git a/cpukit/score/src/timespecdivide.c b/cpukit/score/src/timespecdivide.c
new file mode 100644
index 0000000000..5e2cd2a65a
--- /dev/null
+++ b/cpukit/score/src/timespecdivide.c
@@ -0,0 +1,59 @@
+/**
+ * @file score/src/timespecdivide.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+void _Timespec_Divide(
+ const struct timespec *lhs,
+ const struct timespec *rhs,
+ uint32_t *ival_percentage,
+ uint32_t *fval_percentage
+)
+{
+ uint64_t left, right, answer;
+
+ /*
+ * For math simplicity just convert the timespec to nanoseconds
+ * in a 64-bit integer.
+ */
+ left = lhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
+ left += lhs->tv_nsec;
+ right = rhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
+ right += rhs->tv_nsec;
+
+ if ( right == 0 ) {
+ *ival_percentage = 0;
+ *fval_percentage = 0;
+ return;
+ }
+
+ /*
+ * Put it back in the timespec result.
+ *
+ * TODO: Rounding on the last digit of the fval.
+ */
+
+ answer = (left * 100000) / right;
+
+ *ival_percentage = answer / 1000;
+ *fval_percentage = answer % 1000;
+}
diff --git a/cpukit/score/src/timespecdividebyinteger.c b/cpukit/score/src/timespecdividebyinteger.c
new file mode 100644
index 0000000000..118fd24ee3
--- /dev/null
+++ b/cpukit/score/src/timespecdividebyinteger.c
@@ -0,0 +1,53 @@
+/**
+ * @file score/src/timespecdividebyinteger.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+void _Timespec_Divide_by_integer(
+ const struct timespec *time,
+ uint32_t iterations,
+ struct timespec *result
+)
+{
+ uint64_t t;
+
+ /*
+ * For math simplicity just convert the timespec to nanoseconds
+ * in a 64-bit integer.
+ */
+ t = time->tv_sec;
+ t *= TOD_NANOSECONDS_PER_SECOND;
+ t += time->tv_nsec;
+
+ /*
+ * Divide to get nanoseconds per iteration
+ */
+
+ t /= iterations;
+
+ /*
+ * Put it back in the timespec result
+ */
+
+ result->tv_sec = t / TOD_NANOSECONDS_PER_SECOND;
+ result->tv_nsec = t % TOD_NANOSECONDS_PER_SECOND;
+}
diff --git a/cpukit/score/src/timespecfromticks.c b/cpukit/score/src/timespecfromticks.c
new file mode 100644
index 0000000000..a3f44977fc
--- /dev/null
+++ b/cpukit/score/src/timespecfromticks.c
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <time.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+void _Timespec_From_ticks(
+ uint32_t ticks,
+ struct timespec *time
+)
+{
+ uint32_t usecs;
+
+ usecs = ticks * rtems_configuration_get_microseconds_per_tick();
+
+ time->tv_sec = usecs / TOD_MICROSECONDS_PER_SECOND;
+ time->tv_nsec = (usecs % TOD_MICROSECONDS_PER_SECOND) *
+ TOD_NANOSECONDS_PER_MICROSECOND;
+}
diff --git a/cpukit/score/src/timespecgreaterthan.c b/cpukit/score/src/timespecgreaterthan.c
new file mode 100644
index 0000000000..b0e7870ac6
--- /dev/null
+++ b/cpukit/score/src/timespecgreaterthan.c
@@ -0,0 +1,42 @@
+/**
+ * @file score/src/timespecgreaterthan.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+bool _Timespec_Greater_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+)
+{
+ if ( lhs->tv_sec > rhs->tv_sec )
+ return true;
+
+ if ( lhs->tv_sec < rhs->tv_sec )
+ return false;
+
+ /* ASSERT: lhs->tv_sec == rhs->tv_sec */
+ if ( lhs->tv_nsec > rhs->tv_nsec )
+ return true;
+
+ return false;
+}
diff --git a/cpukit/score/src/timespecisvalid.c b/cpukit/score/src/timespecisvalid.c
new file mode 100644
index 0000000000..3347052ba9
--- /dev/null
+++ b/cpukit/score/src/timespecisvalid.c
@@ -0,0 +1,43 @@
+/**
+ * @file score/src/timespecisvalid.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+bool _Timespec_Is_valid(
+ const struct timespec *time
+)
+{
+ if ( !time )
+ return false;
+
+ if ( time->tv_sec < 0 )
+ return false;
+
+ if ( time->tv_nsec < 0 )
+ return false;
+
+ if ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
+ return false;
+
+ return true;
+}
diff --git a/cpukit/score/src/timespeclessthan.c b/cpukit/score/src/timespeclessthan.c
new file mode 100644
index 0000000000..fb54e69dc9
--- /dev/null
+++ b/cpukit/score/src/timespeclessthan.c
@@ -0,0 +1,42 @@
+/**
+ * @file score/src/timespeclessthan.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+bool _Timespec_Less_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+)
+{
+ if ( lhs->tv_sec < rhs->tv_sec )
+ return true;
+
+ if ( lhs->tv_sec > rhs->tv_sec )
+ return false;
+
+ /* ASSERT: lhs->tv_sec == rhs->tv_sec */
+ if ( lhs->tv_nsec < rhs->tv_nsec )
+ return true;
+
+ return false;
+}
diff --git a/cpukit/score/src/timespecsubtract.c b/cpukit/score/src/timespecsubtract.c
new file mode 100644
index 0000000000..44e9f21c25
--- /dev/null
+++ b/cpukit/score/src/timespecsubtract.c
@@ -0,0 +1,41 @@
+/**
+ * @file score/src/timespecsubtract.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+void _Timespec_Subtract(
+ const struct timespec *start,
+ const struct timespec *end,
+ struct timespec *result
+)
+{
+
+ if (end->tv_nsec < start->tv_nsec) {
+ result->tv_sec = end->tv_sec - start->tv_sec - 1;
+ result->tv_nsec =
+ (TOD_NANOSECONDS_PER_SECOND - start->tv_nsec) + end->tv_nsec;
+ } else {
+ result->tv_sec = end->tv_sec - start->tv_sec;
+ result->tv_nsec = end->tv_nsec - start->tv_nsec;
+ }
+}
diff --git a/cpukit/score/src/timespectoticks.c b/cpukit/score/src/timespectoticks.c
new file mode 100644
index 0000000000..ddd82e67a7
--- /dev/null
+++ b/cpukit/score/src/timespectoticks.c
@@ -0,0 +1,50 @@
+/**
+ * @file score/src/timespectoticks.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ *
+ * This routines converts a timespec to the corresponding number of ticks.
+ */
+
+uint32_t _Timespec_To_ticks(
+ const struct timespec *time
+)
+{
+ uint32_t ticks;
+
+ if ( (time->tv_sec == 0) && (time->tv_nsec == 0) )
+ return 0;
+
+ ticks = time->tv_sec * TOD_TICKS_PER_SECOND;
+
+ ticks += time->tv_nsec / rtems_configuration_get_nanoseconds_per_tick();
+
+ if (ticks)
+ return ticks;
+
+ return 1;
+}
diff --git a/cpukit/score/src/ts64addto.c b/cpukit/score/src/ts64addto.c
new file mode 100644
index 0000000000..14439de0f3
--- /dev/null
+++ b/cpukit/score/src/ts64addto.c
@@ -0,0 +1,34 @@
+/**
+ * @file score/src/ts64addto.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+void _Timestamp64_Add_to(
+ Timestamp64_Control *_time,
+ Timestamp64_Control *_add
+)
+{
+ *_time += *_add;
+}
+#endif
diff --git a/cpukit/score/src/ts64divide.c b/cpukit/score/src/ts64divide.c
new file mode 100644
index 0000000000..01e2661ac4
--- /dev/null
+++ b/cpukit/score/src/ts64divide.c
@@ -0,0 +1,52 @@
+/**
+ * @file score/src/ts64divide.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timestamp.h>
+
+/* This method is never inlined. */
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
+void _Timestamp64_Divide(
+ const Timestamp64_Control *_lhs,
+ const Timestamp64_Control *_rhs,
+ uint32_t *_ival_percentage,
+ uint32_t *_fval_percentage
+)
+{
+ Timestamp64_Control answer;
+
+ if ( *_rhs == 0 ) {
+ *_ival_percentage = 0;
+ *_fval_percentage = 0;
+ return;
+ }
+
+ /*
+ * This looks odd but gives the results the proper precision.
+ *
+ * TODO: Rounding on the last digit of the fval.
+ */
+
+ answer = (*_lhs * 100000) / *_rhs;
+
+ *_ival_percentage = answer / 1000;
+ *_fval_percentage = answer % 1000;
+}
+#endif
diff --git a/cpukit/score/src/ts64dividebyinteger.c b/cpukit/score/src/ts64dividebyinteger.c
new file mode 100644
index 0000000000..f815078322
--- /dev/null
+++ b/cpukit/score/src/ts64dividebyinteger.c
@@ -0,0 +1,35 @@
+/**
+ * @file score/src/ts64dividebyinteger.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+void _Timestamp64_Divide_by_integer(
+ Timestamp64_Control *_time,
+ uint32_t _iterations,
+ Timestamp64_Control *_result
+)
+{
+ *_result = *_time / _iterations;
+}
+#endif
diff --git a/cpukit/score/src/ts64equalto.c b/cpukit/score/src/ts64equalto.c
new file mode 100644
index 0000000000..d6c9eca998
--- /dev/null
+++ b/cpukit/score/src/ts64equalto.c
@@ -0,0 +1,34 @@
+/**
+ * @file score/src/ts64equalto.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+bool _Timestamp64_Equal_to(
+ Timestamp64_Control *_lhs,
+ Timestamp64_Control *_rhs
+)
+{
+ return (*(_lhs) == *(_rhs));
+}
+#endif
diff --git a/cpukit/score/src/ts64getnanoseconds.c b/cpukit/score/src/ts64getnanoseconds.c
new file mode 100644
index 0000000000..f9d57a9ab1
--- /dev/null
+++ b/cpukit/score/src/ts64getnanoseconds.c
@@ -0,0 +1,33 @@
+/**
+ * @file score/src/ts64toticks.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+uint32_t _Timestamp64_Get_nanoseconds(
+ Timestamp64_Control *_time
+)
+{
+ return *(_time) % 1000000000;
+}
+#endif
diff --git a/cpukit/score/src/ts64getseconds.c b/cpukit/score/src/ts64getseconds.c
new file mode 100644
index 0000000000..f459ee07a5
--- /dev/null
+++ b/cpukit/score/src/ts64getseconds.c
@@ -0,0 +1,33 @@
+/**
+ * @file score/src/ts64getseconds.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+uint32_t _Timestamp64_Get_seconds(
+ Timestamp64_Control *_time
+)
+{
+ return *(_time) / 1000000000;
+}
+#endif
diff --git a/cpukit/score/src/ts64greaterthan.c b/cpukit/score/src/ts64greaterthan.c
new file mode 100644
index 0000000000..571adca4c1
--- /dev/null
+++ b/cpukit/score/src/ts64greaterthan.c
@@ -0,0 +1,34 @@
+/**
+ * @file score/src/ts64greaterthan.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+bool _Timestamp64_Greater_than(
+ Timestamp64_Control *_lhs,
+ Timestamp64_Control *_rhs
+)
+{
+ return (*(_lhs) > *(_rhs));
+}
+#endif
diff --git a/cpukit/score/src/ts64lessthan.c b/cpukit/score/src/ts64lessthan.c
new file mode 100644
index 0000000000..1df5eb11f8
--- /dev/null
+++ b/cpukit/score/src/ts64lessthan.c
@@ -0,0 +1,34 @@
+/**
+ * @file score/src/ts64lessthan.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+bool _Timestamp64_Less_than(
+ Timestamp64_Control *_lhs,
+ Timestamp64_Control *_rhs
+)
+{
+ return (*(_lhs) < *(_rhs));
+}
+#endif
diff --git a/cpukit/score/src/ts64set.c b/cpukit/score/src/ts64set.c
new file mode 100644
index 0000000000..f4ed3c40e7
--- /dev/null
+++ b/cpukit/score/src/ts64set.c
@@ -0,0 +1,39 @@
+/**
+ * @file score/src/ts64set.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+void _Timestamp64_Set(
+ Timestamp64_Control *_time,
+ long _seconds,
+ long _nanoseconds
+)
+{
+ int64_t time;
+
+ time = (int64_t)_seconds * 1000000000;
+ time += (int64_t)_nanoseconds;
+ *_time = time;
+}
+#endif
diff --git a/cpukit/score/src/ts64settozero.c b/cpukit/score/src/ts64settozero.c
new file mode 100644
index 0000000000..f5cd78194d
--- /dev/null
+++ b/cpukit/score/src/ts64settozero.c
@@ -0,0 +1,33 @@
+/**
+ * @file score/src/ts64settozero.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+void _Timestamp64_Set_to_zero(
+ Timestamp64_Control *_time
+)
+{
+ *_time = 0;
+}
+#endif
diff --git a/cpukit/score/src/ts64subtract.c b/cpukit/score/src/ts64subtract.c
new file mode 100644
index 0000000000..be7445b2e6
--- /dev/null
+++ b/cpukit/score/src/ts64subtract.c
@@ -0,0 +1,35 @@
+/**
+ * @file score/src/ts64subtract.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+void _Timestamp64_Subtract(
+ Timestamp64_Control *_start,
+ Timestamp64_Control *_end,
+ Timestamp64_Control *_result
+)
+{
+ *_result = *_end - *_start;
+}
+#endif
diff --git a/cpukit/score/src/ts64toticks.c b/cpukit/score/src/ts64toticks.c
new file mode 100644
index 0000000000..273bcc15b4
--- /dev/null
+++ b/cpukit/score/src/ts64toticks.c
@@ -0,0 +1,40 @@
+/**
+ * @file score/src/ts64toticks.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/timestamp.h>
+#include <rtems/score/tod.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+uint32_t _Timestamp64_To_ticks(
+ const Timestamp64_Control *time
+)
+{
+ uint32_t ticks;
+
+ ticks = *time / rtems_configuration_get_nanoseconds_per_tick();
+ if ( ticks )
+ return ticks;
+ return 1;
+}
+#endif
diff --git a/cpukit/score/src/ts64totimespec.c b/cpukit/score/src/ts64totimespec.c
new file mode 100644
index 0000000000..92c2b690bc
--- /dev/null
+++ b/cpukit/score/src/ts64totimespec.c
@@ -0,0 +1,35 @@
+/**
+ * @file score/src/ts64totimespec.c
+*/
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timestamp.h>
+
+#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64) && \
+ !defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
+void _Timestamp64_To_timespec(
+ Timestamp64_Control *_timestamp,
+ struct timespec *_timespec
+)
+{
+ _timespec->tv_sec = *_timestamp / 1000000000;
+ _timespec->tv_nsec = *_timestamp % 1000000000;
+}
+#endif
diff --git a/cpukit/score/src/userext.c b/cpukit/score/src/userext.c
new file mode 100644
index 0000000000..d0e8efc6c9
--- /dev/null
+++ b/cpukit/score/src/userext.c
@@ -0,0 +1,61 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/userext.h>
+#include <rtems/score/wkspace.h>
+#include <string.h>
+
+void _User_extensions_Handler_initialization(void)
+{
+ User_extensions_Control *extension;
+ uint32_t i;
+ uint32_t number_of_extensions;
+ User_extensions_Table *initial_extensions;
+
+ number_of_extensions = Configuration.number_of_initial_extensions;
+ initial_extensions = Configuration.User_extension_table;
+
+ _Chain_Initialize_empty( &_User_extensions_List );
+ _Chain_Initialize_empty( &_User_extensions_Switches_list );
+
+ if ( initial_extensions ) {
+ extension = (User_extensions_Control *)
+ _Workspace_Allocate_or_fatal_error(
+ number_of_extensions * sizeof( User_extensions_Control )
+ );
+
+ memset (
+ extension,
+ 0,
+ number_of_extensions * sizeof( User_extensions_Control )
+ );
+
+ for ( i = 0 ; i < number_of_extensions ; i++ ) {
+ _User_extensions_Add_set_with_table (extension, &initial_extensions[i]);
+ extension++;
+ }
+ }
+}
+
diff --git a/cpukit/score/src/userextaddset.c b/cpukit/score/src/userextaddset.c
new file mode 100644
index 0000000000..fd732e73c4
--- /dev/null
+++ b/cpukit/score/src/userextaddset.c
@@ -0,0 +1,45 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Add_set(
+ User_extensions_Control *the_extension
+)
+{
+ _Chain_Append( &_User_extensions_List, &the_extension->Node );
+
+ /*
+ * If a switch handler is present, append it to the switch chain.
+ */
+
+ if ( the_extension->Callouts.thread_switch != NULL ) {
+ the_extension->Switch.thread_switch =
+ the_extension->Callouts.thread_switch;
+ _Chain_Append(
+ &_User_extensions_Switches_list,
+ &the_extension->Switch.Node
+ );
+ }
+}
diff --git a/cpukit/score/src/userextremoveset.c b/cpukit/score/src/userextremoveset.c
new file mode 100644
index 0000000000..a7f23da536
--- /dev/null
+++ b/cpukit/score/src/userextremoveset.c
@@ -0,0 +1,39 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Remove_set (
+ User_extensions_Control *the_extension
+)
+{
+ _Chain_Extract( &the_extension->Node );
+
+ /*
+ * If a switch handler is present, remove it.
+ */
+
+ if ( the_extension->Callouts.thread_switch != NULL )
+ _Chain_Extract( &the_extension->Switch.Node );
+}
diff --git a/cpukit/score/src/userextthreadbegin.c b/cpukit/score/src/userextthreadbegin.c
new file mode 100644
index 0000000000..9fed82ac4a
--- /dev/null
+++ b/cpukit/score/src/userextthreadbegin.c
@@ -0,0 +1,81 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Thread_begin (
+ Thread_Control *executing
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_First( &_User_extensions_List );
+ !_Chain_Is_tail( &_User_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.thread_begin != NULL )
+ (*the_extension->Callouts.thread_begin)( executing );
+ }
+}
+
+void _User_extensions_Thread_exitted (
+ Thread_Control *executing
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_Last( &_User_extensions_List );
+ !_Chain_Is_head( &_User_extensions_List, the_node ) ;
+ the_node = the_node->previous ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.thread_exitted != NULL )
+ (*the_extension->Callouts.thread_exitted)( executing );
+ }
+}
+
+void _User_extensions_Fatal (
+ Internal_errors_Source the_source,
+ bool is_internal,
+ Internal_errors_t the_error
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_Last( &_User_extensions_List );
+ !_Chain_Is_head( &_User_extensions_List, the_node ) ;
+ the_node = the_node->previous ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.fatal != NULL )
+ (*the_extension->Callouts.fatal)( the_source, is_internal, the_error );
+ }
+}
diff --git a/cpukit/score/src/userextthreadcreate.c b/cpukit/score/src/userextthreadcreate.c
new file mode 100644
index 0000000000..a2950ee37e
--- /dev/null
+++ b/cpukit/score/src/userextthreadcreate.c
@@ -0,0 +1,52 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+bool _User_extensions_Thread_create (
+ Thread_Control *the_thread
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+ bool status;
+
+ for ( the_node = _Chain_First( &_User_extensions_List );
+ !_Chain_Is_tail( &_User_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.thread_create != NULL ) {
+ status = (*the_extension->Callouts.thread_create)(
+ _Thread_Executing,
+ the_thread
+ );
+ if ( !status )
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/cpukit/score/src/userextthreaddelete.c b/cpukit/score/src/userextthreaddelete.c
new file mode 100644
index 0000000000..39397fea84
--- /dev/null
+++ b/cpukit/score/src/userextthreaddelete.c
@@ -0,0 +1,46 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Thread_delete (
+ Thread_Control *the_thread
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_Last( &_User_extensions_List );
+ !_Chain_Is_head( &_User_extensions_List, the_node ) ;
+ the_node = the_node->previous ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.thread_delete != NULL )
+ (*the_extension->Callouts.thread_delete)(
+ _Thread_Executing,
+ the_thread
+ );
+ }
+}
diff --git a/cpukit/score/src/userextthreadrestart.c b/cpukit/score/src/userextthreadrestart.c
new file mode 100644
index 0000000000..c2a4d69e6a
--- /dev/null
+++ b/cpukit/score/src/userextthreadrestart.c
@@ -0,0 +1,46 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Thread_restart (
+ Thread_Control *the_thread
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_First( &_User_extensions_List );
+ !_Chain_Is_tail( &_User_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.thread_restart != NULL )
+ (*the_extension->Callouts.thread_restart)(
+ _Thread_Executing,
+ the_thread
+ );
+ }
+}
diff --git a/cpukit/score/src/userextthreadstart.c b/cpukit/score/src/userextthreadstart.c
new file mode 100644
index 0000000000..0fbe6ab755
--- /dev/null
+++ b/cpukit/score/src/userextthreadstart.c
@@ -0,0 +1,46 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Thread_start (
+ Thread_Control *the_thread
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Control *the_extension;
+
+ for ( the_node = _Chain_First( &_User_extensions_List );
+ !_Chain_Is_tail( &_User_extensions_List, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension = (User_extensions_Control *) the_node;
+
+ if ( the_extension->Callouts.thread_start != NULL )
+ (*the_extension->Callouts.thread_start)(
+ _Thread_Executing,
+ the_thread
+ );
+ }
+}
diff --git a/cpukit/score/src/userextthreadswitch.c b/cpukit/score/src/userextthreadswitch.c
new file mode 100644
index 0000000000..026b56d9de
--- /dev/null
+++ b/cpukit/score/src/userextthreadswitch.c
@@ -0,0 +1,43 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreUserExt
+ *
+ * @brief User Extension Handler implementation.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/userext.h>
+
+void _User_extensions_Thread_switch (
+ Thread_Control *executing,
+ Thread_Control *heir
+)
+{
+ Chain_Node *the_node;
+ User_extensions_Switch_control *the_extension_switch;
+
+ for ( the_node = _Chain_First( &_User_extensions_Switches_list );
+ !_Chain_Is_tail( &_User_extensions_Switches_list, the_node ) ;
+ the_node = the_node->next ) {
+
+ the_extension_switch = (User_extensions_Switch_control *) the_node;
+
+ (*the_extension_switch->thread_switch)( executing, heir );
+ }
+}
diff --git a/cpukit/score/src/watchdog.c b/cpukit/score/src/watchdog.c
new file mode 100644
index 0000000000..591f2de117
--- /dev/null
+++ b/cpukit/score/src/watchdog.c
@@ -0,0 +1,42 @@
+/*
+ * Watchdog Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _Watchdog_Handler_initialization
+ *
+ * This routine initializes the watchdog handler.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ */
+
+void _Watchdog_Handler_initialization( void )
+{
+ _Watchdog_Sync_count = 0;
+ _Watchdog_Sync_level = 0;
+ _Watchdog_Ticks_since_boot = 0;
+
+ _Chain_Initialize_empty( &_Watchdog_Ticks_chain );
+ _Chain_Initialize_empty( &_Watchdog_Seconds_chain );
+}
diff --git a/cpukit/score/src/watchdogadjust.c b/cpukit/score/src/watchdogadjust.c
new file mode 100644
index 0000000000..89d4859906
--- /dev/null
+++ b/cpukit/score/src/watchdogadjust.c
@@ -0,0 +1,87 @@
+/*
+ * Watchdog Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _Watchdog_Adjust
+ *
+ * This routine adjusts the delta chain backward or forward in response
+ * to a time change.
+ *
+ * Input parameters:
+ * header - pointer to the delta chain to be adjusted
+ * direction - forward or backward adjustment to delta chain
+ * units - units to adjust
+ *
+ * Output parameters:
+ */
+
+void _Watchdog_Adjust(
+ Chain_Control *header,
+ Watchdog_Adjust_directions direction,
+ Watchdog_Interval units
+)
+{
+ ISR_Level level;
+
+ _ISR_Disable( level );
+
+ /*
+ * NOTE: It is safe NOT to make 'header' a pointer
+ * to volatile data (contrast this with watchdoginsert.c)
+ * because we call _Watchdog_Tickle() below and
+ * hence the compiler must not assume *header to remain
+ * unmodified across that call.
+ *
+ * Till Straumann, 7/2003
+ */
+ if ( !_Chain_Is_empty( header ) ) {
+ switch ( direction ) {
+ case WATCHDOG_BACKWARD:
+ _Watchdog_First( header )->delta_interval += units;
+ break;
+ case WATCHDOG_FORWARD:
+ while ( units ) {
+ if ( units < _Watchdog_First( header )->delta_interval ) {
+ _Watchdog_First( header )->delta_interval -= units;
+ break;
+ } else {
+ units -= _Watchdog_First( header )->delta_interval;
+ _Watchdog_First( header )->delta_interval = 1;
+
+ _ISR_Enable( level );
+
+ _Watchdog_Tickle( header );
+
+ _ISR_Disable( level );
+
+ if ( _Chain_Is_empty( header ) )
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ _ISR_Enable( level );
+
+}
diff --git a/cpukit/score/src/watchdogadjusttochain.c b/cpukit/score/src/watchdogadjusttochain.c
new file mode 100644
index 0000000000..569a9364f7
--- /dev/null
+++ b/cpukit/score/src/watchdogadjusttochain.c
@@ -0,0 +1,83 @@
+/**
+ * @file watchdogadjusttochain.c
+ *
+ * This is used by the Timer Server task.
+ */
+
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+
+void _Watchdog_Adjust_to_chain(
+ Chain_Control *header,
+ Watchdog_Interval units_arg,
+ Chain_Control *to_fire
+
+)
+{
+ Watchdog_Interval units = units_arg;
+ ISR_Level level;
+ Watchdog_Control *first;
+
+ if ( units <= 0 ) {
+ return;
+ }
+
+ _ISR_Disable( level );
+
+ while ( 1 ) {
+ if ( units <= 0 ) {
+ break;
+ }
+ if ( _Chain_Is_empty( header ) ) {
+ break;
+ }
+ first = _Watchdog_First( header );
+
+ /*
+ * If it is longer than "units" until the first element on the chain
+ * fires, then bump it and quit.
+ */
+ if ( units < first->delta_interval ) {
+ first->delta_interval -= units;
+ break;
+ }
+
+ /*
+ * The first set happens in less than units, so take all of them
+ * off the chain and adjust units to reflect this.
+ */
+ units -= first->delta_interval;
+ first->delta_interval = 0;
+
+ while ( 1 ) {
+ _Chain_Extract_unprotected( &first->Node );
+ _Chain_Append_unprotected( to_fire, &first->Node );
+
+ _ISR_Flash( level );
+
+ if ( _Chain_Is_empty( header ) )
+ break;
+ first = _Watchdog_First( header );
+ if ( first->delta_interval != 0 )
+ break;
+ }
+ }
+
+ _ISR_Enable( level );
+}
+
diff --git a/cpukit/score/src/watchdoginsert.c b/cpukit/score/src/watchdoginsert.c
new file mode 100644
index 0000000000..e4b86bd271
--- /dev/null
+++ b/cpukit/score/src/watchdoginsert.c
@@ -0,0 +1,100 @@
+/*
+ * Watchdog Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _Watchdog_Insert
+ *
+ * This routine inserts a watchdog timer on to the appropriate delta
+ * chain while updating the delta interval counters.
+ */
+
+void _Watchdog_Insert(
+ Chain_Control *header,
+ Watchdog_Control *the_watchdog
+)
+{
+ ISR_Level level;
+ Watchdog_Control *after;
+ uint32_t insert_isr_nest_level;
+ Watchdog_Interval delta_interval;
+
+
+ insert_isr_nest_level = _ISR_Nest_level;
+
+ _ISR_Disable( level );
+
+ /*
+ * Check to see if the watchdog has just been inserted by a
+ * higher priority interrupt. If so, abandon this insert.
+ */
+
+ if ( the_watchdog->state != WATCHDOG_INACTIVE ) {
+ _ISR_Enable( level );
+ return;
+ }
+
+ the_watchdog->state = WATCHDOG_BEING_INSERTED;
+ _Watchdog_Sync_count++;
+
+restart:
+ delta_interval = the_watchdog->initial;
+
+ for ( after = _Watchdog_First( header ) ;
+ ;
+ after = _Watchdog_Next( after ) ) {
+
+ if ( delta_interval == 0 || !_Watchdog_Next( after ) )
+ break;
+
+ if ( delta_interval < after->delta_interval ) {
+ after->delta_interval -= delta_interval;
+ break;
+ }
+
+ delta_interval -= after->delta_interval;
+
+ _ISR_Flash( level );
+
+ if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) {
+ goto exit_insert;
+ }
+
+ if ( _Watchdog_Sync_level > insert_isr_nest_level ) {
+ _Watchdog_Sync_level = insert_isr_nest_level;
+ goto restart;
+ }
+ }
+
+ _Watchdog_Activate( the_watchdog );
+
+ the_watchdog->delta_interval = delta_interval;
+
+ _Chain_Insert_unprotected( after->Node.previous, &the_watchdog->Node );
+
+ the_watchdog->start_time = _Watchdog_Ticks_since_boot;
+
+exit_insert:
+ _Watchdog_Sync_level = insert_isr_nest_level;
+ _Watchdog_Sync_count--;
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/watchdognanoseconds.c b/cpukit/score/src/watchdognanoseconds.c
new file mode 100644
index 0000000000..b3d3e7b028
--- /dev/null
+++ b/cpukit/score/src/watchdognanoseconds.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+
+Watchdog_Nanoseconds_since_last_tick_routine
+ _Watchdog_Nanoseconds_since_tick_handler =
+ _Watchdog_Nanoseconds_since_tick_default_handler;
+
+uint32_t _Watchdog_Nanoseconds_since_tick_default_handler( void )
+{
+ return 0;
+}
diff --git a/cpukit/score/src/watchdogremove.c b/cpukit/score/src/watchdogremove.c
new file mode 100644
index 0000000000..3ce3367657
--- /dev/null
+++ b/cpukit/score/src/watchdogremove.c
@@ -0,0 +1,73 @@
+/*
+ * Watchdog Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _Watchdog_Remove
+ *
+ * The routine removes a watchdog from a delta chain and updates
+ * the delta counters of the remaining watchdogs.
+ */
+
+Watchdog_States _Watchdog_Remove(
+ Watchdog_Control *the_watchdog
+)
+{
+ ISR_Level level;
+ Watchdog_States previous_state;
+ Watchdog_Control *next_watchdog;
+
+ _ISR_Disable( level );
+ previous_state = the_watchdog->state;
+ switch ( previous_state ) {
+ case WATCHDOG_INACTIVE:
+ break;
+
+ case WATCHDOG_BEING_INSERTED:
+
+ /*
+ * It is not actually on the chain so just change the state and
+ * the Insert operation we interrupted will be aborted.
+ */
+ the_watchdog->state = WATCHDOG_INACTIVE;
+ break;
+
+ case WATCHDOG_ACTIVE:
+ case WATCHDOG_REMOVE_IT:
+
+ the_watchdog->state = WATCHDOG_INACTIVE;
+ next_watchdog = _Watchdog_Next( the_watchdog );
+
+ if ( _Watchdog_Next(next_watchdog) )
+ next_watchdog->delta_interval += the_watchdog->delta_interval;
+
+ if ( _Watchdog_Sync_count )
+ _Watchdog_Sync_level = _ISR_Nest_level;
+
+ _Chain_Extract_unprotected( &the_watchdog->Node );
+ break;
+ }
+ the_watchdog->stop_time = _Watchdog_Ticks_since_boot;
+
+ _ISR_Enable( level );
+ return( previous_state );
+}
diff --git a/cpukit/score/src/watchdogreport.c b/cpukit/score/src/watchdogreport.c
new file mode 100644
index 0000000000..58bce56959
--- /dev/null
+++ b/cpukit/score/src/watchdogreport.c
@@ -0,0 +1,41 @@
+/**
+ * @file watchdogreport.c
+ *
+ * This should only be used for debugging.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/bspIo.h>
+
+void _Watchdog_Report(
+ const char *name,
+ Watchdog_Control *watch
+)
+{
+ printk(
+ "%s%s%4d %5d %p %p 0x%08x %p\n",
+ ((name) ? name : ""),
+ ((name) ? " " : ""),
+ watch->delta_interval,
+ watch->initial,
+ watch,
+ watch->routine,
+ watch->id,
+ watch->user_data
+ );
+}
diff --git a/cpukit/score/src/watchdogreportchain.c b/cpukit/score/src/watchdogreportchain.c
new file mode 100644
index 0000000000..8b616914c6
--- /dev/null
+++ b/cpukit/score/src/watchdogreportchain.c
@@ -0,0 +1,50 @@
+/**
+ * @file watchdogreportchain.c
+ *
+ * This should only be used for debugging.
+ */
+
+/* COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/score/isr.h>
+#include <rtems/bspIo.h>
+
+void _Watchdog_Report_chain(
+ const char *name,
+ Chain_Control *header
+)
+{
+ ISR_Level level;
+ Chain_Node *node;
+
+ _ISR_Disable( level );
+ printk( "Watchdog Chain: %s %p\n", name, header );
+ if ( !_Chain_Is_empty( header ) ) {
+ for ( node = _Chain_First( header ) ;
+ node != _Chain_Tail(header) ;
+ node = node->next )
+ {
+ Watchdog_Control *watch = (Watchdog_Control *) node;
+
+ _Watchdog_Report( NULL, watch );
+ }
+ printk( "== end of %s \n", name );
+ } else {
+ printk( "Chain is empty\n" );
+ }
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/watchdogtickle.c b/cpukit/score/src/watchdogtickle.c
new file mode 100644
index 0000000000..09b3c7bf09
--- /dev/null
+++ b/cpukit/score/src/watchdogtickle.c
@@ -0,0 +1,129 @@
+/*
+ * Watchdog Handler
+ *
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * _Watchdog_Tickle
+ *
+ * This routine decrements the delta counter in response to a tick. The
+ * delta chain is updated accordingly.
+ *
+ * Input parameters:
+ * header - pointer to the delta chain to be tickled
+ *
+ * Output parameters: NONE
+ */
+
+void _Watchdog_Tickle(
+ Chain_Control *header
+)
+{
+ ISR_Level level;
+ Watchdog_Control *the_watchdog;
+ Watchdog_States watchdog_state;
+
+ /*
+ * See the comment in watchdoginsert.c and watchdogadjust.c
+ * about why it's safe not to declare header a pointer to
+ * volatile data - till, 2003/7
+ */
+
+ _ISR_Disable( level );
+
+ if ( _Chain_Is_empty( header ) )
+ goto leave;
+
+ the_watchdog = _Watchdog_First( header );
+
+ /*
+ * For some reason, on rare occasions the_watchdog->delta_interval
+ * of the head of the watchdog chain is 0. Before this test was
+ * added, on these occasions an event (which usually was supposed
+ * to have a timeout of 1 tick would have a delta_interval of 0, which
+ * would be decremented to 0xFFFFFFFF by the unprotected
+ * "the_watchdog->delta_interval--;" operation.
+ * This would mean the event would not timeout, and also the chain would
+ * be blocked, because a timeout with a very high number would be at the
+ * head, rather than at the end.
+ * The test "if (the_watchdog->delta_interval != 0)"
+ * here prevents this from occuring.
+ *
+ * We were not able to categorically identify the situation that causes
+ * this, but proved it to be true empirically. So this check causes
+ * correct behaviour in this circumstance.
+ *
+ * The belief is that a race condition exists whereby an event at the head
+ * of the chain is removed (by a pending ISR or higher priority task)
+ * during the _ISR_Flash( level ); in _Watchdog_Insert, but the watchdog
+ * to be inserted has already had its delta_interval adjusted to 0, and
+ * so is added to the head of the chain with a delta_interval of 0.
+ *
+ * Steven Johnson - 12/2005 (gcc-3.2.3 -O3 on powerpc)
+ */
+ if (the_watchdog->delta_interval != 0) {
+ the_watchdog->delta_interval--;
+ if ( the_watchdog->delta_interval != 0 )
+ goto leave;
+ }
+
+ do {
+ watchdog_state = _Watchdog_Remove( the_watchdog );
+
+ _ISR_Enable( level );
+
+ switch( watchdog_state ) {
+ case WATCHDOG_ACTIVE:
+ (*the_watchdog->routine)(
+ the_watchdog->id,
+ the_watchdog->user_data
+ );
+ break;
+
+ case WATCHDOG_INACTIVE:
+ /*
+ * This state indicates that the watchdog is not on any chain.
+ * Thus, it is NOT on a chain being tickled. This case should
+ * never occur.
+ */
+ break;
+
+ case WATCHDOG_BEING_INSERTED:
+ /*
+ * This state indicates that the watchdog is in the process of
+ * BEING inserted on the chain. Thus, it can NOT be on a chain
+ * being tickled. This case should never occur.
+ */
+ break;
+
+ case WATCHDOG_REMOVE_IT:
+ break;
+ }
+
+ _ISR_Disable( level );
+
+ the_watchdog = _Watchdog_First( header );
+ } while ( !_Chain_Is_empty( header ) &&
+ (the_watchdog->delta_interval == 0) );
+
+leave:
+ _ISR_Enable(level);
+}
diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c
new file mode 100644
index 0000000000..568bfc1ce7
--- /dev/null
+++ b/cpukit/score/src/wkspace.c
@@ -0,0 +1,125 @@
+/*
+ * Workspace Handler
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/config.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/interr.h>
+
+#include <string.h> /* for memset */
+
+/* #define DEBUG_WORKSPACE */
+#if defined(DEBUG_WORKSPACE)
+ #include <rtems/bspIo.h>
+#endif
+
+/*
+ * _Workspace_Handler_initialization
+ */
+void _Workspace_Handler_initialization(void)
+{
+ uintptr_t memory_available = 0;
+ void *starting_address = Configuration.work_space_start;
+ uintptr_t size = Configuration.work_space_size;
+
+ if ( Configuration.do_zero_of_workspace )
+ memset( starting_address, 0, size );
+
+ memory_available = _Heap_Initialize(
+ &_Workspace_Area,
+ starting_address,
+ size,
+ CPU_HEAP_ALIGNMENT
+ );
+
+ if ( memory_available == 0 )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
+ );
+}
+
+/*
+ * _Workspace_Allocate
+ */
+void *_Workspace_Allocate(
+ size_t size
+)
+{
+ void *memory;
+
+ memory = _Heap_Allocate( &_Workspace_Area, size );
+ #if defined(DEBUG_WORKSPACE)
+ printk(
+ "Workspace_Allocate(%d) from %p/%p -> %p\n",
+ size,
+ __builtin_return_address( 0 ),
+ __builtin_return_address( 1 ),
+ memory
+ );
+ #endif
+ return memory;
+}
+
+/*
+ * _Workspace_Free
+ */
+void _Workspace_Free(
+ void *block
+)
+{
+ #if defined(DEBUG_WORKSPACE)
+ printk(
+ "Workspace_Free(%p) from %p/%p\n",
+ block,
+ __builtin_return_address( 0 ),
+ __builtin_return_address( 1 )
+ );
+ #endif
+ _Heap_Free( &_Workspace_Area, block );
+}
+
+/*
+ * _Workspace_Allocate_or_fatal_error
+ */
+void *_Workspace_Allocate_or_fatal_error(
+ size_t size
+)
+{
+ void *memory;
+
+ memory = _Heap_Allocate( &_Workspace_Area, size );
+ #if defined(DEBUG_WORKSPACE)
+ printk(
+ "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n",
+ size,
+ __builtin_return_address( 0 ),
+ __builtin_return_address( 1 ),
+ memory
+ );
+ #endif
+
+ if ( memory == NULL )
+ _Internal_error_Occurred(
+ INTERNAL_ERROR_CORE,
+ true,
+ INTERNAL_ERROR_WORKSPACE_ALLOCATION
+ );
+
+ return memory;
+}
diff --git a/cpukit/telnetd/.cvsignore b/cpukit/telnetd/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/telnetd/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/telnetd/Makefile.am b/cpukit/telnetd/Makefile.am
new file mode 100644
index 0000000000..a2b581a700
--- /dev/null
+++ b/cpukit/telnetd/Makefile.am
@@ -0,0 +1,21 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/compile.am
+
+if LIBNETWORKING
+if LIBSHELL
+include_rtemsdir = $(includedir)/rtems
+include_rtems_HEADERS = pty.h telnetd.h passwd.h
+
+project_lib_LIBRARIES = libtelnetd.a
+libtelnetd_a_SOURCES = check_passwd.c des.c icmds.c pty.c telnetd.c
+libtelnetd_a_CPPFLAGS = $(AM_CPPFLAGS)
+endif
+endif
+
+EXTRA_DIST = README
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/telnetd/README b/cpukit/telnetd/README
new file mode 100644
index 0000000000..626b458f23
--- /dev/null
+++ b/cpukit/telnetd/README
@@ -0,0 +1,27 @@
+#
+# $Id$
+#
+
+Author: fernando.ruiz@ctv.es (correo@fernando-ruiz.com)
+
+This directory contains a telnetd server
+primary features:
+
+ + create a user shell pseudo-terminal task.
+
+This code has not been extensively tested. It is provided as a tool
+for RTEMS users to open more shell tcp/ip pseudo-terminal.
+Suggestions and comments are appreciated.
+
+Read libmisc/shell for more information.
+
+NOTES:
+
+1. OOB not yet implemented. Only a reduced negotiation is implemented.
+
+2. If you have tcp/ip initialied you can start telnetd daemon.
+ You need register pseudo-terminals driver into device drivers table.
+
+Enjoy it.
+
+FUTURE:
diff --git a/cpukit/telnetd/check_passwd.c b/cpukit/telnetd/check_passwd.c
new file mode 100644
index 0000000000..51d08723b8
--- /dev/null
+++ b/cpukit/telnetd/check_passwd.c
@@ -0,0 +1,109 @@
+/* $Id$ */
+
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2003-2007
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ *
+ * Copyright (c) 2009 embedded brains GmbH and others.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <termios.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+
+#include <rtems/telnetd.h>
+
+#include "passwd.h"
+
+char *__des_crypt_r( const char *, const char *, char *, int);
+
+/**
+ * @brief Standard Telnet login check that uses DES to encrypt the passphrase.
+ *
+ * Takes a @a passphrase, encrypts it and compares it to the encrypted
+ * passphrase in the @c TELNETD_PASSWD environment variable. No password is
+ * required if @c TELNETD_PASSWD is unset. The argument @a user is ignored.
+ */
+bool rtems_telnetd_login_check(
+ const char *user,
+ const char *passphrase
+)
+{
+ char *pw = getenv( "TELNETD_PASSWD");
+ char cryptbuf [21];
+ char salt [3];
+
+ if (pw == NULL || strlen( pw) == 0) {
+ #ifdef TELNETD_DEFAULT_PASSWD
+ pw = TELNETD_DEFAULT_PASSWD;
+ #else
+ return true;
+ #endif
+ }
+
+ strncpy( salt, pw, 2);
+ salt [2] = '\0';
+
+ return strcmp(
+ __des_crypt_r( passphrase, salt, cryptbuf, sizeof( cryptbuf)),
+ pw
+ ) == 0;
+}
diff --git a/cpukit/telnetd/des.c b/cpukit/telnetd/des.c
new file mode 100644
index 0000000000..74e4b8e378
--- /dev/null
+++ b/cpukit/telnetd/des.c
@@ -0,0 +1,879 @@
+/*
+ * FreeSec: libcrypt for NetBSD
+ *
+ * Copyright (c) 1994 David Burren
+ * All rights reserved.
+ *
+ * Ported to RTEMS and made reentrant by Till Straumann, 9/2003
+ *
+ * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet
+ * this file should now *only* export crypt(), in order to make
+ * binaries of libcrypt exportable from the USA
+ *
+ * Adapted for FreeBSD-4.0 by Mark R V Murray
+ * this file should now *only* export crypt_des(), in order to make
+ * a module that can be optionally included in libcrypt.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of other contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This is an original implementation of the DES and the crypt(3) interfaces
+ * by David Burren <davidb@werj.com.au>.
+ *
+ * An excellent reference on the underlying algorithm (and related
+ * algorithms) is:
+ *
+ * B. Schneier, Applied Cryptography: protocols, algorithms,
+ * and source code in C, John Wiley & Sons, 1994.
+ *
+ * Note that in that book's description of DES the lookups for the initial,
+ * pbox, and final permutations are inverted (this has been brought to the
+ * attention of the author). A list of errata for this book has been
+ * posted to the sci.crypt newsgroup by the author and is available for FTP.
+ *
+ * ARCHITECTURE ASSUMPTIONS:
+ * It is assumed that the 8-byte arrays passed by reference can be
+ * addressed as arrays of u_int32_t's (ie. the CPU is not picky about
+ * alignment).
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define __FORCE_GLIBC
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#ifndef __rtems__
+#include <pwd.h>
+#include <string.h>
+#include <crypt.h>
+#endif
+#include <stdlib.h>
+
+#define REENTRANT
+/* Re-entrantify me -- all this junk needs to be in
+ * struct crypt_data to make this really reentrant... */
+
+/* TS; not really - only the stuff in Des_Context */
+static struct fixed1 {
+u_char inv_key_perm[64];
+u_char inv_comp_perm[56];
+u_char u_sbox[8][64];
+u_char un_pbox[32];
+} des1_f;
+static struct fixed2 {
+u_int32_t ip_maskl[8][256], ip_maskr[8][256];
+} des2_f;
+static struct fixed3 {
+u_int32_t fp_maskl[8][256], fp_maskr[8][256];
+} des3_f;
+static struct fixed4 {
+u_int32_t key_perm_maskl[8][128], key_perm_maskr[8][128];
+u_int32_t comp_maskl[8][128], comp_maskr[8][128];
+} des4_f;
+
+#define inv_key_perm des1_f.inv_key_perm
+#define inv_comp_perm des1_f.inv_comp_perm
+#define u_sbox des1_f.u_sbox
+#define un_pbox des1_f.un_pbox
+#define ip_maskl des2_f.ip_maskl
+#define ip_maskr des2_f.ip_maskr
+#define fp_maskl des3_f.fp_maskl
+#define fp_maskr des3_f.fp_maskr
+#define key_perm_maskl des4_f.key_perm_maskl
+#define key_perm_maskr des4_f.key_perm_maskr
+#define comp_maskl des4_f.comp_maskl
+#define comp_maskr des4_f.comp_maskr
+
+/* These need to be maintained per-process */
+struct Des_Context {
+u_int32_t en_keysl[16], en_keysr[16];
+u_int32_t de_keysl[16], de_keysr[16];
+u_int32_t saltbits;
+u_int32_t old_salt;
+u_int32_t old_rawkey0, old_rawkey1;
+};
+
+#ifndef REENTRANT
+static struct Des_Context single;
+#endif
+
+#define en_keysl des_ctx->en_keysl
+#define en_keysr des_ctx->en_keysr
+#define de_keysl des_ctx->de_keysl
+#define de_keysr des_ctx->de_keysr
+#define saltbits des_ctx->saltbits
+#define old_salt des_ctx->old_salt
+#define old_rawkey0 des_ctx->old_rawkey0
+#define old_rawkey1 des_ctx->old_rawkey1
+
+/* Static stuff that stays resident and doesn't change after
+ * being initialized, and therefore doesn't need to be made
+ * reentrant. */
+static u_char init_perm[64], final_perm[64];
+static u_char m_sbox[4][4096];
+static u_int32_t psbox[4][256];
+
+
+
+
+/* A pile of data */
+static const u_char ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+static const u_char IP[64] = {
+ 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
+ 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
+ 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
+ 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
+};
+
+static const u_char key_perm[56] = {
+ 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
+ 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
+ 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
+ 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
+};
+
+static const u_char key_shifts[16] = {
+ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
+};
+
+static const u_char comp_perm[48] = {
+ 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
+ 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
+ 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
+ 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
+};
+
+/*
+ * No E box is used, as it's replaced by some ANDs, shifts, and ORs.
+ */
+
+static const u_char sbox[8][64] = {
+ {
+ 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
+ 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
+ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
+ 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
+ },
+ {
+ 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
+ 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
+ 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
+ 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
+ },
+ {
+ 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
+ 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
+ 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
+ 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
+ },
+ {
+ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
+ 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
+ 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
+ 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
+ },
+ {
+ 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
+ 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
+ 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
+ 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
+ },
+ {
+ 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
+ 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
+ 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
+ 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
+ },
+ {
+ 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
+ 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
+ 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
+ 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
+ },
+ {
+ 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
+ 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
+ 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
+ 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
+ }
+};
+
+static const u_char pbox[32] = {
+ 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
+ 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
+};
+
+static const u_int32_t bits32[32] =
+{
+ 0x80000000, 0x40000000, 0x20000000, 0x10000000,
+ 0x08000000, 0x04000000, 0x02000000, 0x01000000,
+ 0x00800000, 0x00400000, 0x00200000, 0x00100000,
+ 0x00080000, 0x00040000, 0x00020000, 0x00010000,
+ 0x00008000, 0x00004000, 0x00002000, 0x00001000,
+ 0x00000800, 0x00000400, 0x00000200, 0x00000100,
+ 0x00000080, 0x00000040, 0x00000020, 0x00000010,
+ 0x00000008, 0x00000004, 0x00000002, 0x00000001
+};
+
+static const u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+static const u_int32_t *bits28, *bits24;
+
+
+static int
+ascii_to_bin(char ch)
+{
+ if (ch > 'z')
+ return(0);
+ if (ch >= 'a')
+ return(ch - 'a' + 38);
+ if (ch > 'Z')
+ return(0);
+ if (ch >= 'A')
+ return(ch - 'A' + 12);
+ if (ch > '9')
+ return(0);
+ if (ch >= '.')
+ return(ch - '.');
+ return(0);
+}
+
+struct Des_Context *
+des_ctx_init(void)
+{
+struct Des_Context *des_ctx;
+#ifdef REENTRANT
+ des_ctx = malloc(sizeof(*des_ctx));
+#else
+ des_ctx = &single;
+#endif
+ old_rawkey0 = old_rawkey1 = 0L;
+ saltbits = 0L;
+ old_salt = 0L;
+
+ return des_ctx;
+}
+
+static void
+des_init(void)
+{
+ int i, j, b, k, inbit, obit;
+ u_int32_t *p, *il, *ir, *fl, *fr;
+ static int des_initialised = 0;
+
+ if (des_initialised==1)
+ return;
+
+#ifndef REENTRANT
+ des_ctx_init();
+#endif
+
+ bits24 = (bits28 = bits32 + 4) + 4;
+
+ /*
+ * Invert the S-boxes, reordering the input bits.
+ */
+ for (i = 0; i < 8; i++)
+ for (j = 0; j < 64; j++) {
+ b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
+ u_sbox[i][j] = sbox[i][b];
+ }
+
+ /*
+ * Convert the inverted S-boxes into 4 arrays of 8 bits.
+ * Each will handle 12 bits of the S-box input.
+ */
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 64; i++)
+ for (j = 0; j < 64; j++)
+ m_sbox[b][(i << 6) | j] =
+ (u_char)((u_sbox[(b << 1)][i] << 4) |
+ u_sbox[(b << 1) + 1][j]);
+
+ /*
+ * Set up the initial & final permutations into a useful form, and
+ * initialise the inverted key permutation.
+ */
+ for (i = 0; i < 64; i++) {
+ init_perm[final_perm[i] = IP[i] - 1] = (u_char)i;
+ inv_key_perm[i] = 255;
+ }
+
+ /*
+ * Invert the key permutation and initialise the inverted key
+ * compression permutation.
+ */
+ for (i = 0; i < 56; i++) {
+ inv_key_perm[key_perm[i] - 1] = (u_char)i;
+ inv_comp_perm[i] = 255;
+ }
+
+ /*
+ * Invert the key compression permutation.
+ */
+ for (i = 0; i < 48; i++) {
+ inv_comp_perm[comp_perm[i] - 1] = (u_char)i;
+ }
+
+ /*
+ * Set up the OR-mask arrays for the initial and final permutations,
+ * and for the key initial and compression permutations.
+ */
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 256; i++) {
+ *(il = &ip_maskl[k][i]) = 0L;
+ *(ir = &ip_maskr[k][i]) = 0L;
+ *(fl = &fp_maskl[k][i]) = 0L;
+ *(fr = &fp_maskr[k][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j]) {
+ if ((obit = init_perm[inbit]) < 32)
+ *il |= bits32[obit];
+ else
+ *ir |= bits32[obit-32];
+ if ((obit = final_perm[inbit]) < 32)
+ *fl |= bits32[obit];
+ else
+ *fr |= bits32[obit - 32];
+ }
+ }
+ }
+ for (i = 0; i < 128; i++) {
+ *(il = &key_perm_maskl[k][i]) = 0L;
+ *(ir = &key_perm_maskr[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_key_perm[inbit]) == 255)
+ continue;
+ if (obit < 28)
+ *il |= bits28[obit];
+ else
+ *ir |= bits28[obit - 28];
+ }
+ }
+ *(il = &comp_maskl[k][i]) = 0L;
+ *(ir = &comp_maskr[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 7 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit=inv_comp_perm[inbit]) == 255)
+ continue;
+ if (obit < 24)
+ *il |= bits24[obit];
+ else
+ *ir |= bits24[obit - 24];
+ }
+ }
+ }
+ }
+
+ /*
+ * Invert the P-box permutation, and convert into OR-masks for
+ * handling the output of the S-box arrays setup above.
+ */
+ for (i = 0; i < 32; i++)
+ un_pbox[pbox[i] - 1] = (u_char)i;
+
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 256; i++) {
+ *(p = &psbox[b][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ if (i & bits8[j])
+ *p |= bits32[un_pbox[8 * b + j]];
+ }
+ }
+
+ des_initialised = 1;
+}
+
+
+static void
+setup_salt(long salt, struct Des_Context *des_ctx)
+{
+ u_int32_t obit, saltbit;
+ int i;
+
+ if (salt == old_salt)
+ return;
+ old_salt = salt;
+
+ saltbits = 0L;
+ saltbit = 1;
+ obit = 0x800000;
+ for (i = 0; i < 24; i++) {
+ if (salt & saltbit)
+ saltbits |= obit;
+ saltbit <<= 1;
+ obit >>= 1;
+ }
+}
+
+
+static int
+des_setkey(const char *key, struct Des_Context *des_ctx)
+{
+ u_int32_t k0, k1, rawkey0, rawkey1;
+ int shifts, round;
+
+ des_init();
+
+ rawkey0 = ntohl(*(const u_int32_t *) key);
+ rawkey1 = ntohl(*(const u_int32_t *) (key + 4));
+
+ if ((rawkey0 | rawkey1)
+ && rawkey0 == old_rawkey0
+ && rawkey1 == old_rawkey1) {
+ /*
+ * Already setup for this key.
+ * This optimisation fails on a zero key (which is weak and
+ * has bad parity anyway) in order to simplify the starting
+ * conditions.
+ */
+ return(0);
+ }
+ old_rawkey0 = rawkey0;
+ old_rawkey1 = rawkey1;
+
+ /*
+ * Do key permutation and split into two 28-bit subkeys.
+ */
+ k0 = key_perm_maskl[0][rawkey0 >> 25]
+ | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskl[4][rawkey1 >> 25]
+ | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
+ k1 = key_perm_maskr[0][rawkey0 >> 25]
+ | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskr[4][rawkey1 >> 25]
+ | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
+ /*
+ * Rotate subkeys and do compression permutation.
+ */
+ shifts = 0;
+ for (round = 0; round < 16; round++) {
+ u_int32_t t0, t1;
+
+ shifts += key_shifts[round];
+
+ t0 = (k0 << shifts) | (k0 >> (28 - shifts));
+ t1 = (k1 << shifts) | (k1 >> (28 - shifts));
+
+ de_keysl[15 - round] =
+ en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
+ | comp_maskl[1][(t0 >> 14) & 0x7f]
+ | comp_maskl[2][(t0 >> 7) & 0x7f]
+ | comp_maskl[3][t0 & 0x7f]
+ | comp_maskl[4][(t1 >> 21) & 0x7f]
+ | comp_maskl[5][(t1 >> 14) & 0x7f]
+ | comp_maskl[6][(t1 >> 7) & 0x7f]
+ | comp_maskl[7][t1 & 0x7f];
+
+ de_keysr[15 - round] =
+ en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
+ | comp_maskr[1][(t0 >> 14) & 0x7f]
+ | comp_maskr[2][(t0 >> 7) & 0x7f]
+ | comp_maskr[3][t0 & 0x7f]
+ | comp_maskr[4][(t1 >> 21) & 0x7f]
+ | comp_maskr[5][(t1 >> 14) & 0x7f]
+ | comp_maskr[6][(t1 >> 7) & 0x7f]
+ | comp_maskr[7][t1 & 0x7f];
+ }
+ return(0);
+}
+
+
+static int
+do_des( u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, int count, struct Des_Context *des_ctx)
+{
+ /*
+ * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
+ */
+ u_int32_t l, r, *kl, *kr, *kl1, *kr1;
+ u_int32_t f, r48l, r48r;
+ int round;
+
+ if (count == 0) {
+ return(1);
+ } else if (count > 0) {
+ /*
+ * Encrypting
+ */
+ kl1 = en_keysl;
+ kr1 = en_keysr;
+ } else {
+ /*
+ * Decrypting
+ */
+ count = -count;
+ kl1 = de_keysl;
+ kr1 = de_keysr;
+ }
+
+ /*
+ * Do initial permutation (IP).
+ */
+ l = ip_maskl[0][l_in >> 24]
+ | ip_maskl[1][(l_in >> 16) & 0xff]
+ | ip_maskl[2][(l_in >> 8) & 0xff]
+ | ip_maskl[3][l_in & 0xff]
+ | ip_maskl[4][r_in >> 24]
+ | ip_maskl[5][(r_in >> 16) & 0xff]
+ | ip_maskl[6][(r_in >> 8) & 0xff]
+ | ip_maskl[7][r_in & 0xff];
+ r = ip_maskr[0][l_in >> 24]
+ | ip_maskr[1][(l_in >> 16) & 0xff]
+ | ip_maskr[2][(l_in >> 8) & 0xff]
+ | ip_maskr[3][l_in & 0xff]
+ | ip_maskr[4][r_in >> 24]
+ | ip_maskr[5][(r_in >> 16) & 0xff]
+ | ip_maskr[6][(r_in >> 8) & 0xff]
+ | ip_maskr[7][r_in & 0xff];
+
+ while (count--) {
+ /*
+ * Do each round.
+ */
+ kl = kl1;
+ kr = kr1;
+ round = 16;
+ while (round--) {
+ /*
+ * Expand R to 48 bits (simulate the E-box).
+ */
+ r48l = ((r & 0x00000001) << 23)
+ | ((r & 0xf8000000) >> 9)
+ | ((r & 0x1f800000) >> 11)
+ | ((r & 0x01f80000) >> 13)
+ | ((r & 0x001f8000) >> 15);
+
+ r48r = ((r & 0x0001f800) << 7)
+ | ((r & 0x00001f80) << 5)
+ | ((r & 0x000001f8) << 3)
+ | ((r & 0x0000001f) << 1)
+ | ((r & 0x80000000) >> 31);
+ /*
+ * Do salting for crypt() and friends, and
+ * XOR with the permuted key.
+ */
+ f = (r48l ^ r48r) & saltbits;
+ r48l ^= f ^ *kl++;
+ r48r ^= f ^ *kr++;
+ /*
+ * Do sbox lookups (which shrink it back to 32 bits)
+ * and do the pbox permutation at the same time.
+ */
+ f = psbox[0][m_sbox[0][r48l >> 12]]
+ | psbox[1][m_sbox[1][r48l & 0xfff]]
+ | psbox[2][m_sbox[2][r48r >> 12]]
+ | psbox[3][m_sbox[3][r48r & 0xfff]];
+ /*
+ * Now that we've permuted things, complete f().
+ */
+ f ^= l;
+ l = r;
+ r = f;
+ }
+ r = l;
+ l = f;
+ }
+ /*
+ * Do final permutation (inverse of IP).
+ */
+ *l_out = fp_maskl[0][l >> 24]
+ | fp_maskl[1][(l >> 16) & 0xff]
+ | fp_maskl[2][(l >> 8) & 0xff]
+ | fp_maskl[3][l & 0xff]
+ | fp_maskl[4][r >> 24]
+ | fp_maskl[5][(r >> 16) & 0xff]
+ | fp_maskl[6][(r >> 8) & 0xff]
+ | fp_maskl[7][r & 0xff];
+ *r_out = fp_maskr[0][l >> 24]
+ | fp_maskr[1][(l >> 16) & 0xff]
+ | fp_maskr[2][(l >> 8) & 0xff]
+ | fp_maskr[3][l & 0xff]
+ | fp_maskr[4][r >> 24]
+ | fp_maskr[5][(r >> 16) & 0xff]
+ | fp_maskr[6][(r >> 8) & 0xff]
+ | fp_maskr[7][r & 0xff];
+ return(0);
+}
+
+
+#if 0
+static int
+des_cipher(const char *in, char *out, u_int32_t salt, int count)
+{
+ u_int32_t l_out, r_out, rawl, rawr;
+ int retval;
+ union {
+ u_int32_t *ui32;
+ const char *c;
+ } trans;
+
+ des_init();
+
+ setup_salt(salt);
+
+ trans.c = in;
+ rawl = ntohl(*trans.ui32++);
+ rawr = ntohl(*trans.ui32);
+
+ retval = do_des(rawl, rawr, &l_out, &r_out, count);
+
+ trans.c = out;
+ *trans.ui32++ = htonl(l_out);
+ *trans.ui32 = htonl(r_out);
+ return(retval);
+}
+#endif
+
+
+#ifndef REENTRANT
+void
+setkey(const char *key)
+{
+ int i, j;
+ u_int32_t packed_keys[2];
+ u_char *p;
+
+ p = (u_char *) packed_keys;
+
+ for (i = 0; i < 8; i++) {
+ p[i] = 0;
+ for (j = 0; j < 8; j++)
+ if (*key++ & 1)
+ p[i] |= bits8[j];
+ }
+ des_setkey(p, &single);
+}
+#endif
+
+
+#ifndef REENTRANT
+void
+encrypt(char *block, int flag)
+{
+ u_int32_t io[2];
+ u_char *p;
+ int i, j;
+
+ des_init();
+
+ setup_salt(0L, &single);
+ p = block;
+ for (i = 0; i < 2; i++) {
+ io[i] = 0L;
+ for (j = 0; j < 32; j++)
+ if (*p++ & 1)
+ io[i] |= bits32[j];
+ }
+ do_des(io[0], io[1], io, io + 1, flag ? -1 : 1, &single);
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 32; j++)
+ block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0;
+}
+
+#endif
+
+char *
+__des_crypt_r(const char *key, const char *setting, char *output, int sz)
+{
+ char *rval = 0;
+ struct Des_Context *des_ctx;
+ u_int32_t count, salt, l, r0, r1, keybuf[2];
+ u_char *p, *q;
+
+ if (sz < 21)
+ return NULL;
+
+ des_init();
+ des_ctx = des_ctx_init();
+
+ /*
+ * Copy the key, shifting each character up by one bit
+ * and padding with zeros.
+ */
+ q = (u_char *)keybuf;
+ while (q - (u_char *)keybuf - 8) {
+ *q++ = *key << 1;
+ if (*(q - 1))
+ key++;
+ }
+ if (des_setkey((char *)keybuf, des_ctx))
+ goto bailout;
+
+#if 0
+ if (*setting == _PASSWORD_EFMT1) {
+ int i;
+ /*
+ * "new"-style:
+ * setting - underscore, 4 bytes of count, 4 bytes of salt
+ * key - unlimited characters
+ */
+ for (i = 1, count = 0L; i < 5; i++)
+ count |= ascii_to_bin(setting[i]) << ((i - 1) * 6);
+
+ for (i = 5, salt = 0L; i < 9; i++)
+ salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6);
+
+ while (*key) {
+ /*
+ * Encrypt the key with itself.
+ */
+ if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1))
+ goto bailout;
+ /*
+ * And XOR with the next 8 characters of the key.
+ */
+ q = (u_char *)keybuf;
+ while (q - (u_char *)keybuf - 8 && *key)
+ *q++ ^= *key++ << 1;
+
+ if (des_setkey((char *)keybuf))
+ goto bailout;
+ }
+ strncpy(output, setting, 9);
+
+ /*
+ * Double check that we weren't given a short setting.
+ * If we were, the above code will probably have created
+ * wierd values for count and salt, but we don't really care.
+ * Just make sure the output string doesn't have an extra
+ * NUL in it.
+ */
+ output[9] = '\0';
+ p = (u_char *)output + strlen(output);
+ } else
+#endif
+ {
+ /*
+ * "old"-style:
+ * setting - 2 bytes of salt
+ * key - up to 8 characters
+ */
+ count = 25;
+
+ salt = (ascii_to_bin(setting[1]) << 6)
+ | ascii_to_bin(setting[0]);
+
+ output[0] = setting[0];
+ /*
+ * If the encrypted password that the salt was extracted from
+ * is only 1 character long, the salt will be corrupted. We
+ * need to ensure that the output string doesn't have an extra
+ * NUL in it!
+ */
+ output[1] = setting[1] ? setting[1] : output[0];
+
+ p = (u_char *)output + 2;
+ }
+ setup_salt(salt, des_ctx);
+ /*
+ * Do it.
+ */
+ if (do_des(0L, 0L, &r0, &r1, (int)count, des_ctx))
+ goto bailout;
+ /*
+ * Now encode the result...
+ */
+ l = (r0 >> 8);
+ *p++ = ascii64[(l >> 18) & 0x3f];
+ *p++ = ascii64[(l >> 12) & 0x3f];
+ *p++ = ascii64[(l >> 6) & 0x3f];
+ *p++ = ascii64[l & 0x3f];
+
+ l = (r0 << 16) | ((r1 >> 16) & 0xffff);
+ *p++ = ascii64[(l >> 18) & 0x3f];
+ *p++ = ascii64[(l >> 12) & 0x3f];
+ *p++ = ascii64[(l >> 6) & 0x3f];
+ *p++ = ascii64[l & 0x3f];
+
+ l = r1 << 2;
+ *p++ = ascii64[(l >> 12) & 0x3f];
+ *p++ = ascii64[(l >> 6) & 0x3f];
+ *p++ = ascii64[l & 0x3f];
+ *p = 0;
+
+ rval = output;
+bailout:
+ free(des_ctx);
+ return rval;
+}
+
+char *
+__des_crypt(const char *key, const char *setting)
+{
+ static char output[21];
+ return __des_crypt_r(key, setting, output, sizeof(output));
+}
+
+
+#ifdef DEBUG
+
+void
+des_snap(void **pf, void **pd)
+{
+ uint8* pfc;
+ *pf = malloc(sizeof(struct fixed1) + sizeof(struct fixed2) + sizeof(struct fixed3) + sizeof(struct fixed4));
+ pfc = *pf;
+ memcpy(pfc, &des1_f, sizeof(des1_f));
+ pfc += sizeof(des1_f);
+ memcpy(pfc, &des2_f, sizeof(des2_f));
+ pfc += sizeof(des2_f);
+ memcpy(pfc, &des3_f, sizeof(des3_f));
+ pfc += sizeof(des3_f);
+ memcpy(pfc, &des4_f, sizeof(des4_f));
+// *pd = malloc(sizeof(struct Des_Context));
+// memcpy(*pd, &des_ctx, sizeof(des_ctx));
+}
+
+void
+des_check(void *pf, void *pd)
+{
+ uint8* pfc1, pfc2, pfc3, pfc4;
+ pfc1 = pf;
+ pfc2 = pfc1 + sizeof(des1_f);
+ pfc3 = pfc2 + sizeof(des2_f);
+ pfc4 = pfc3 + sizeof(des3_f);
+ printf("Fixed: do%s differ"/*", Context: do%s differ"*/"\n",
+ (memcmp(pfc1, &des1_f, sizeof(des1_f)) ||
+ memcmp(pfc2, &des2_f, sizeof(des2_f)) ||
+ memcmp(pfc3, &des4_f, sizeof(des3_f)) ||
+ memcmp(pfc4, &des4_f, sizeof(des4_f))) ? "" : "nt");
+}
+
+#endif
diff --git a/cpukit/telnetd/genpw.c b/cpukit/telnetd/genpw.c
new file mode 100644
index 0000000000..1cb30bc684
--- /dev/null
+++ b/cpukit/telnetd/genpw.c
@@ -0,0 +1,79 @@
+/*
+ * Authorship
+ * ----------
+ * This software was created by
+ * Till Straumann <strauman@slac.stanford.edu>, 2003-2007
+ * Stanford Linear Accelerator Center, Stanford University.
+ *
+ * Acknowledgement of sponsorship
+ * ------------------------------
+ * This software was produced by
+ * the Stanford Linear Accelerator Center, Stanford University,
+ * under Contract DE-AC03-76SFO0515 with the Department of Energy.
+ *
+ * Government disclaimer of liability
+ * ----------------------------------
+ * Neither the United States nor the United States Department of Energy,
+ * nor any of their employees, makes any warranty, express or implied, or
+ * assumes any legal liability or responsibility for the accuracy,
+ * completeness, or usefulness of any data, apparatus, product, or process
+ * disclosed, or represents that its use would not infringe privately owned
+ * rights.
+ *
+ * Stanford disclaimer of liability
+ * --------------------------------
+ * Stanford University makes no representations or warranties, express or
+ * implied, nor assumes any liability for the use of this software.
+ *
+ * Stanford disclaimer of copyright
+ * --------------------------------
+ * Stanford University, owner of the copyright, hereby disclaims its
+ * copyright and all other rights in this software. Hence, anyone may
+ * freely use it for any purpose without restriction.
+ *
+ * Maintenance of notices
+ * ----------------------
+ * In the interest of clarity regarding the origin and status of this
+ * SLAC software, this and all the preceding Stanford University notices
+ * are to remain affixed to any copy or derivative of this software made
+ * or distributed by the recipient and are to be affixed to any copy of
+ * software made or distributed by the recipient that contains a copy or
+ * derivative of this software.
+ *
+ * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <crypt.h>
+#include <stdio.h>
+#include <unistd.h>
+
+static void
+usage(char *nm)
+{
+ fprintf(stderr,"Usage: %s [-h] [-s salt] cleartext_password\n", nm);
+}
+
+int
+main(int argc, char **argv)
+{
+int ch;
+char *salt="td";
+ while ( (ch=getopt(argc, argv, "hs:")) >=0 ) {
+ switch (ch) {
+ default: fprintf(stderr,"Unknown Option '%c'\n",ch);
+ case 'h': usage(argv[0]);
+ return 0;
+ case 's': salt=optarg;
+ break;
+ }
+ }
+ if ( optind >= argc ) {
+ usage(argv[0]);
+ return 1;
+ }
+ printf("#define TELNETD_DEFAULT_PASSWD \"%s\"\n",crypt(argv[optind],salt));
+}
diff --git a/cpukit/telnetd/icmds.c b/cpukit/telnetd/icmds.c
new file mode 100644
index 0000000000..400fafc539
--- /dev/null
+++ b/cpukit/telnetd/icmds.c
@@ -0,0 +1,64 @@
+/*
+ * Author: Fernando RUIZ CASAS (fernando.ruiz@ctv.es)
+ * May 2001
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/shell.h>
+#include <rtems/rtems_bsdnet.h>
+
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_inet(int argc,char * argv[]) {
+ rtems_bsdnet_show_inet_routes ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_mbuf(int argc,char * argv[]) {
+ rtems_bsdnet_show_mbuf_stats ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_if(int argc,char * argv[]) {
+ rtems_bsdnet_show_if_stats ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_ip(int argc,char * argv[]) {
+ rtems_bsdnet_show_ip_stats ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_icmp(int argc,char * argv[]) {
+ rtems_bsdnet_show_icmp_stats ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_tcp(int argc,char * argv[]) {
+ rtems_bsdnet_show_tcp_stats ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+static int main_udp(int argc,char * argv[]) {
+ rtems_bsdnet_show_udp_stats ();
+ return 0;
+}
+/*+++++++++++++++++++++++++++++++++++++++++++++*/
+
+void _rtems_telnetd_register_icmds(void) {
+ rtems_shell_add_cmd("inet" ,"net","inet routes" ,main_inet);
+ rtems_shell_add_cmd("mbuf" ,"net","mbuf stats" ,main_mbuf);
+ rtems_shell_add_cmd("if" ,"net","if stats" ,main_if );
+ rtems_shell_add_cmd("ip" ,"net","ip stats" ,main_ip );
+ rtems_shell_add_cmd("icmp" ,"net","icmp stats" ,main_icmp);
+ rtems_shell_add_cmd("tcp" ,"net","tcp stats" ,main_tcp );
+ rtems_shell_add_cmd("udp" ,"net","udp stats" ,main_udp );
+}
diff --git a/cpukit/telnetd/passwd.h b/cpukit/telnetd/passwd.h
new file mode 100644
index 0000000000..e6f15f7d84
--- /dev/null
+++ b/cpukit/telnetd/passwd.h
@@ -0,0 +1,27 @@
+/* $Id$ */
+
+/* Define a default password for telnetd here.
+ * NOTES:
+ * - this can be overridden at run-time by setting
+ * the "TELNETD_PASSWD" environment variable.
+ * As soon as that variable is set, the new password
+ * is effective - no need to restart telnetd.
+ * - this must be set to an _encrypted_ password, NOT
+ * the cleartext. Use the 'genpw' utility to generate
+ * a password string:
+ *
+ * 1) Compile 'genpw.c' for the HOST, i.e.
+ * cc -o genpw genpw.c -lcrypt
+ * 1) delete an old password definition from this file.
+ * 2) run './genpw >> passwd.h'. This will append
+ * a new definition to this file.
+ *
+ * - if no password is defined here, no authentication
+ * is needed, i.e. telnet is open to the world.
+ *
+ * T. Straumann <strauman@slac.stanford.edu>
+ */
+
+/* #undef TELNETD_DEFAULT_PASSWD */
+/* Default password: 'rtems' */
+#define TELNETD_DEFAULT_PASSWD "tduDcyLX12owo"
diff --git a/cpukit/telnetd/preinstall.am b/cpukit/telnetd/preinstall.am
new file mode 100644
index 0000000000..68bf81f457
--- /dev/null
+++ b/cpukit/telnetd/preinstall.am
@@ -0,0 +1,49 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+if LIBNETWORKING
+if LIBSHELL
+$(PROJECT_INCLUDE)/rtems/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/rtems
+ @: > $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+
+$(PROJECT_INCLUDE)/rtems/pty.h: pty.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/pty.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/pty.h
+
+$(PROJECT_INCLUDE)/rtems/telnetd.h: telnetd.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/telnetd.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/telnetd.h
+
+$(PROJECT_INCLUDE)/rtems/passwd.h: passwd.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/passwd.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/passwd.h
+
+$(PROJECT_LIB)/libtelnetd.a: libtelnetd.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libtelnetd.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libtelnetd.a
+endif
+endif
diff --git a/cpukit/telnetd/pty.c b/cpukit/telnetd/pty.c
new file mode 100644
index 0000000000..fae95126cb
--- /dev/null
+++ b/cpukit/telnetd/pty.c
@@ -0,0 +1,654 @@
+/*
+ * /dev/ptyXX (Support for pseudo-terminals)
+ *
+ * Original Author: Fernando RUIZ CASAS (fernando.ruiz@ctv.es)
+ * May 2001
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Till Straumann <strauman@slac.stanford.edu>
+ *
+ * - converted into a loadable module
+ * - NAWS support / ioctls for querying/setting the window
+ * size added.
+ * - don't delete the running task when the connection
+ * is closed. Rather let 'read()' return a 0 count so
+ * they may cleanup. Some magic hack works around termios
+ * limitation.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define DEBUG_WH (1<<0)
+#define DEBUG_DETAIL (1<<1)
+
+/* #define DEBUG DEBUG_WH */
+
+/*-----------------------------------------*/
+#include <termios.h>
+#include <rtems/termiostypes.h>
+#include <sys/ttycom.h>
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <rtems/bspIo.h>
+#include <errno.h>
+#include <sys/socket.h>
+/*-----------------------------------------*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+/*-----------------------------------------*/
+#define IAC_ESC 255
+#define IAC_DONT 254
+#define IAC_DO 253
+#define IAC_WONT 252
+#define IAC_WILL 251
+#define IAC_SB 250
+#define IAC_GA 249
+#define IAC_EL 248
+#define IAC_EC 247
+#define IAC_AYT 246
+#define IAC_AO 245
+#define IAC_IP 244
+#define IAC_BRK 243
+#define IAC_DMARK 242
+#define IAC_NOP 241
+#define IAC_SE 240
+#define IAC_EOR 239
+
+#define SB_MAX 16
+
+extern int rtems_telnetd_maximum_ptys;
+
+struct pty_tt;
+typedef struct pty_tt pty_t;
+
+struct pty_tt {
+ char *devname;
+ struct rtems_termios_tty *ttyp;
+ tcflag_t c_cflag;
+ int opened;
+ int socket;
+ int last_cr;
+ unsigned iac_mode;
+ unsigned char sb_buf[SB_MAX];
+ int sb_ind;
+ int width;
+ int height;
+};
+
+
+static int telnet_pty_inited=FALSE;
+static pty_t *telnet_ptys;
+
+static rtems_device_major_number pty_major;
+
+
+/* This procedure returns the devname for a pty slot free.
+ * If not slot availiable (field socket>=0)
+ * then the socket argument is closed
+ */
+
+char * telnet_get_pty(int socket)
+{
+ int ndx;
+
+ if (telnet_pty_inited) {
+#if 0
+ if ( rtems_telnetd_maximum_ptys < 5 )
+ rtems_telnetd_maximum_ptys = 5;
+
+ telnet_ptys = malloc( rtems_telnetd_maximum_ptys * sizeof (pty_t) );
+#endif
+ if ( !telnet_ptys ) {
+ return NULL;
+ }
+
+ for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) {
+
+ if (telnet_ptys[ndx].socket<0) {
+ struct timeval t;
+ /* set a long polling interval to save CPU time */
+ t.tv_sec=2;
+ t.tv_usec=00000;
+ setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
+ telnet_ptys[ndx].socket=socket;
+ return telnet_ptys[ndx].devname;
+ };
+ };
+ }
+ close(socket);
+ return NULL;
+}
+
+
+/*-----------------------------------------------------------*/
+/*
+ * The NVT terminal is negociated in PollRead and PollWrite
+ * with every BYTE sendded or received.
+ * A litle status machine in the pty_read_byte(int minor)
+ *
+ */
+static const char IAC_AYT_RSP[]="\r\nAYT? Yes, RTEMS-SHELL is here\r\n";
+static const char IAC_BRK_RSP[]="<*Break*>";
+static const char IAC_IP_RSP []="<*Interrupt*>";
+
+static
+int send_iac(int minor,unsigned char mode,unsigned char option)
+{
+ unsigned char buf[3];
+
+ buf[0]=IAC_ESC;
+ buf[1]=mode;
+ buf[2]=option;
+ return write(telnet_ptys[minor].socket,buf,sizeof(buf));
+}
+
+static int
+handleSB(pty_t *pty)
+{
+ switch (pty->sb_buf[0]) {
+ case 31: /* NAWS */
+ pty->width = (pty->sb_buf[1]<<8) + pty->sb_buf[2];
+ pty->height = (pty->sb_buf[3]<<8) + pty->sb_buf[4];
+#if DEBUG & DEBUG_WH
+ fprintf(stderr,
+ "Setting width/height to %ix%i\n",
+ pty->width,
+ pty->height);
+#endif
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static int read_pty(int minor)
+{ /* Characters written to the client side*/
+ unsigned char value;
+ unsigned int omod;
+ int count;
+ int result;
+ pty_t *pty=telnet_ptys+minor;
+
+ count=read(pty->socket,&value,sizeof(value));
+ if (count<0)
+ return -1;
+
+ if (count<1) {
+ /* Unfortunately, there is no way of passing an EOF
+ * condition through the termios driver. Hence, we
+ * resort to an ugly hack. Setting cindex>ccount
+ * causes the termios driver to return a read count
+ * of '0' which is what we want here. We leave
+ * 'errno' untouched.
+ */
+ pty->ttyp->cindex=pty->ttyp->ccount+1;
+ return pty->ttyp->termios.c_cc[VEOF];
+ };
+
+ omod=pty->iac_mode;
+ pty->iac_mode=0;
+ switch(omod & 0xff) {
+ case IAC_ESC:
+ switch(value) {
+ case IAC_ESC :
+ /* in case this is an ESC ESC sequence in SB mode */
+ pty->iac_mode = omod>>8;
+ return IAC_ESC;
+ case IAC_DONT:
+ case IAC_DO :
+ case IAC_WONT:
+ case IAC_WILL:
+ pty->iac_mode=value;
+ return -1;
+ case IAC_SB :
+#if DEBUG & DEBUG_DETAIL
+ printk("SB\n");
+#endif
+ pty->iac_mode=value;
+ pty->sb_ind=0;
+ return -100;
+ case IAC_GA :
+ return -1;
+ case IAC_EL :
+ return 0x03; /* Ctrl-C*/
+ case IAC_EC :
+ return '\b';
+ case IAC_AYT :
+ write(pty->socket,IAC_AYT_RSP,strlen(IAC_AYT_RSP));
+ return -1;
+ case IAC_AO :
+ return -1;
+ case IAC_IP :
+ write(pty->socket,IAC_IP_RSP,strlen(IAC_IP_RSP));
+ return -1;
+ case IAC_BRK :
+ write(pty->socket,IAC_BRK_RSP,strlen(IAC_BRK_RSP));
+ return -1;
+ case IAC_DMARK:
+ return -2;
+ case IAC_NOP :
+ return -1;
+ case IAC_SE :
+#if DEBUG & DEBUG_DETAIL
+ {
+ int i;
+ printk("SE");
+ for (i=0; i<pty->sb_ind; i++)
+ printk(" %02x",pty->sb_buf[i]);
+ printk("\n");
+ }
+#endif
+ handleSB(pty);
+ return -101;
+ case IAC_EOR :
+ return -102;
+ default :
+ return -1;
+ };
+ break;
+
+ case IAC_SB:
+ pty->iac_mode=omod;
+ if (IAC_ESC==value) {
+ pty->iac_mode=(omod<<8)|value;
+ } else {
+ if (pty->sb_ind < SB_MAX)
+ pty->sb_buf[pty->sb_ind++]=value;
+ }
+ return -1;
+
+ case IAC_WILL:
+ if (value==34){
+ send_iac(minor,IAC_DONT, 34); /*LINEMODE*/
+ send_iac(minor,IAC_DO , 1); /*ECHO */
+ } else if (value==31) {
+ send_iac(minor,IAC_DO , 31); /*NAWS */
+#if DEBUG & DEBUG_DETAIL
+ printk("replied DO NAWS\n");
+#endif
+ } else {
+ send_iac(minor,IAC_DONT,value);
+ }
+ return -1;
+ case IAC_DONT:
+ return -1;
+ case IAC_DO :
+ if (value==3) {
+ send_iac(minor,IAC_WILL, 3); /* GO AHEAD*/
+ } else if (value==1) {
+ /* ECHO */
+ } else {
+ send_iac(minor,IAC_WONT,value);
+ };
+ return -1;
+ case IAC_WONT:
+ if (value==1) {
+ send_iac(minor,IAC_WILL, 1);
+ } else { /* ECHO */
+ send_iac(minor,IAC_WONT,value);
+ }
+ return -1;
+ default:
+ if (value==IAC_ESC) {
+ pty->iac_mode=value;
+ return -1;
+ } else {
+ result=value;
+ if ( 0
+#if 0 /* pass CRLF through - they should use termios to handle it */
+ || ((value=='\n') && (pty->last_cr))
+#endif
+ /* but map telnet CRNUL to CR down here */
+ || ((value==0) && pty->last_cr)
+ ) result=-1;
+ pty->last_cr=(value=='\r');
+ return result;
+ };
+ };
+ /* should never get here but keep compiler happy */
+ return -1;
+}
+
+/*-----------------------------------------------------------*/
+static int ptySetAttributes(int minor,const struct termios *t);
+static int ptyPollInitialize(int major,int minor,void * arg) ;
+static int ptyShutdown(int major,int minor,void * arg) ;
+static ssize_t ptyPollWrite(int minor, const char * buf, size_t len) ;
+static int ptyPollRead(int minor) ;
+static const rtems_termios_callbacks * pty_get_termios_handlers(int polled) ;
+/*-----------------------------------------------------------*/
+/* Set the 'Hardware' */
+/*-----------------------------------------------------------*/
+static int
+ptySetAttributes(int minor,const struct termios *t) {
+ if (minor<rtems_telnetd_maximum_ptys) {
+ telnet_ptys[minor].c_cflag=t->c_cflag;
+ } else {
+ return -1;
+ };
+ return 0;
+}
+/*-----------------------------------------------------------*/
+static int
+ptyPollInitialize(int major,int minor,void * arg) {
+ rtems_libio_open_close_args_t * args = (rtems_libio_open_close_args_t*)arg;
+ struct termios t;
+ if (minor<rtems_telnetd_maximum_ptys) {
+ if (telnet_ptys[minor].socket<0) return -1;
+ telnet_ptys[minor].opened=TRUE;
+ telnet_ptys[minor].ttyp= (struct rtems_termios_tty *) args->iop->data1;
+ telnet_ptys[minor].iac_mode=0;
+ telnet_ptys[minor].sb_ind=0;
+ telnet_ptys[minor].width=0;
+ telnet_ptys[minor].height=0;
+ t.c_cflag=B9600|CS8;/* termios default */
+ return ptySetAttributes(minor,&t);
+ } else {
+ return -1;
+ }
+}
+/*-----------------------------------------------------------*/
+static int
+ptyShutdown(int major,int minor,void * arg) {
+ if (minor<rtems_telnetd_maximum_ptys) {
+ telnet_ptys[minor].opened=FALSE;
+ if (telnet_ptys[minor].socket>=0) close(telnet_ptys[minor].socket);
+ telnet_ptys[minor].socket=-1;
+ chown(telnet_ptys[minor].devname,2,0);
+ } else {
+ return -1;
+ }
+ return 0;
+}
+/*-----------------------------------------------------------*/
+/* Write Characters into pty device */
+/*-----------------------------------------------------------*/
+static ssize_t
+ptyPollWrite(int minor, const char * buf, size_t len) {
+ size_t count;
+ if (minor<rtems_telnetd_maximum_ptys) {
+ if (telnet_ptys[minor].socket<0)
+ return -1;
+ count=write(telnet_ptys[minor].socket,buf,len);
+ } else {
+ count=-1;
+ }
+ return count;
+}
+/*-----------------------------------------------------------*/
+static int
+ptyPollRead(int minor) {
+ int result;
+
+ if (minor<rtems_telnetd_maximum_ptys) {
+ if (telnet_ptys[minor].socket<0)
+ return -1;
+ result=read_pty(minor);
+ return result;
+ }
+ return -1;
+}
+/*-----------------------------------------------------------*/
+/* pty_initialize
+ *
+ * This routine initializes the pty IO driver.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ *
+ * Return values:
+ */
+/*-----------------------------------------------------------*/
+static
+rtems_device_driver my_pty_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ int ndx;
+ rtems_status_code status;
+
+ if ( rtems_telnetd_maximum_ptys < 5 )
+ rtems_telnetd_maximum_ptys = 5;
+
+ telnet_ptys = malloc( rtems_telnetd_maximum_ptys * sizeof (pty_t) );
+
+ /*
+ * Set up ptys
+ */
+
+ for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) {
+ telnet_ptys[ndx].devname = (char*)malloc(strlen("/dev/ptyXX")+1);
+ sprintf(telnet_ptys[ndx].devname,"/dev/pty%X",ndx);
+ telnet_ptys[ndx].ttyp = NULL;
+ telnet_ptys[ndx].c_cflag = CS8|B9600;
+ telnet_ptys[ndx].socket = -1;
+ telnet_ptys[ndx].opened = FALSE;
+ telnet_ptys[ndx].sb_ind = 0;
+ telnet_ptys[ndx].width = 0;
+ telnet_ptys[ndx].height = 0;
+
+ }
+
+ /*
+ * Register the devices
+ */
+ for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) {
+ status = rtems_io_register_name(telnet_ptys[ndx].devname, major, ndx);
+ if (status != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred(status);
+ chmod(telnet_ptys[ndx].devname,0660);
+ chown(telnet_ptys[ndx].devname,2,0); /* tty,root*/
+ };
+ printk("Device: /dev/pty%X../dev/pty%X (%d)pseudo-terminals registered.\n",
+ 0,rtems_telnetd_maximum_ptys-1,rtems_telnetd_maximum_ptys);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+static int pty_do_finalize(void)
+{
+ int ndx;
+ rtems_status_code status;
+
+ if ( !telnet_pty_inited )
+ return 0;
+
+ for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) {
+ if (telnet_ptys[ndx].opened) {
+ fprintf(stderr,
+ "There are still opened PTY devices, unable to proceed\n");
+ return -1;
+ }
+ }
+ if (RTEMS_SUCCESSFUL != rtems_io_unregister_driver(pty_major)) {
+ fprintf(stderr,"Unable to remove this driver\n");
+ return -1;
+ }
+ for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) {
+ /* rtems_io_register_name() actually creates a node in the filesystem
+ * (mknod())
+ */
+ status = (rtems_status_code)unlink(telnet_ptys[ndx].devname);
+ if (status != RTEMS_SUCCESSFUL)
+ perror("removing pty device node from file system");
+ else
+ free(telnet_ptys[ndx].devname);
+ };
+
+ free ( telnet_ptys );
+
+ fprintf(stderr,"PTY driver unloaded successfully\n");
+ telnet_pty_inited=FALSE;
+ return 0;
+}
+
+/*
+ * Open entry point
+ */
+
+static
+rtems_device_driver my_pty_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ rtems_status_code sc;
+ sc = rtems_termios_open(major,minor,arg,pty_get_termios_handlers(FALSE));
+ return sc;
+}
+
+/*
+ * Close entry point
+ */
+
+static
+rtems_device_driver my_pty_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ return rtems_termios_close(arg);
+}
+
+/*
+ * read bytes from the pty
+ */
+
+static
+rtems_device_driver my_pty_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ return rtems_termios_read(arg);
+}
+
+/*
+ * write bytes to the pty
+ */
+
+static
+rtems_device_driver my_pty_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ return rtems_termios_write(arg);
+}
+
+/*
+ * IO Control entry point
+ */
+
+static
+rtems_device_driver my_pty_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t*)arg;
+ struct winsize *wp = (struct winsize*)args->buffer;
+ pty_t *p = &telnet_ptys[minor];
+
+ switch (args->command) {
+
+ case TIOCGWINSZ:
+
+ wp->ws_row = p->height;
+ wp->ws_col = p->width;
+ args->ioctl_return=0;
+#if DEBUG & DEBUG_WH
+ fprintf(stderr,
+ "ioctl(TIOCGWINSZ), returning %ix%i\n",
+ wp->ws_col,
+ wp->ws_row);
+#endif
+
+ return RTEMS_SUCCESSFUL;
+
+ case TIOCSWINSZ:
+#if DEBUG & DEBUG_WH
+ fprintf(stderr,
+ "ioctl(TIOCGWINSZ), setting %ix%i\n",
+ wp->ws_col,
+ wp->ws_row);
+#endif
+
+ p->height = wp->ws_row;
+ p->width = wp->ws_col;
+ args->ioctl_return=0;
+
+ return RTEMS_SUCCESSFUL;
+
+ default:
+
+ break;
+ }
+
+ return rtems_termios_ioctl(arg);
+}
+
+static rtems_driver_address_table drvPty = {
+ my_pty_initialize,
+ my_pty_open,
+ my_pty_close,
+ my_pty_read,
+ my_pty_write,
+ my_pty_control
+};
+
+/*-----------------------------------------------------------*/
+static const rtems_termios_callbacks pty_poll_callbacks = {
+ ptyPollInitialize, /* FirstOpen */
+ ptyShutdown, /* LastClose */
+ ptyPollRead, /* PollRead */
+ ptyPollWrite, /* Write */
+ ptySetAttributes, /* setAttributes */
+ NULL, /* stopRemoteTX */
+ NULL, /* StartRemoteTX */
+ 0 /* outputUsesInterrupts */
+};
+/*-----------------------------------------------------------*/
+static const rtems_termios_callbacks * pty_get_termios_handlers(int polled) {
+ return &pty_poll_callbacks;
+}
+/*-----------------------------------------------------------*/
+
+static int pty_do_initialize(void)
+{
+ if ( !telnet_pty_inited ) {
+ if (RTEMS_SUCCESSFUL==rtems_io_register_driver(0, &drvPty, &pty_major))
+ telnet_pty_inited=TRUE;
+ else
+ fprintf(stderr,"WARNING: registering the PTY driver FAILED\n");
+ }
+ return telnet_pty_inited;
+}
+
+int telnet_pty_initialize(void)
+{
+ return pty_do_initialize();
+}
+
+int telnet_pty_finalize(void)
+{
+ return pty_do_finalize();
+}
diff --git a/cpukit/telnetd/pty.h b/cpukit/telnetd/pty.h
new file mode 100644
index 0000000000..503fb9444d
--- /dev/null
+++ b/cpukit/telnetd/pty.h
@@ -0,0 +1,70 @@
+/*
+ * /dev/ptyXX (A first version for pseudo-terminals)
+ *
+ * Author: Fernando RUIZ CASAS (fernando.ruiz@ctv.es)
+ * May 2001
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_PTY_H
+#define _RTEMS_PTY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems.h>
+
+/* Number of ptys to setup */
+extern size_t rtems_pty_maximum_ptys;
+
+/* Return the devname for a free pty slot.
+ * If no slot available (socket>=0)
+ * then the socket argument is closed
+ */
+char * rtems_pty_get(int socket);
+
+
+/* OBSOLETE */
+#define get_pty rtems_pty_get
+
+rtems_device_driver pty_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg);
+rtems_device_driver pty_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg);
+rtems_device_driver pty_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg);
+rtems_device_driver pty_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg);
+rtems_device_driver pty_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg);
+rtems_device_driver pty_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg);
+
+
+#define PTY_DRIVER_TABLE_ENTRY \
+ { pty_initialize , pty_open , pty_close , \
+ pty_read , pty_write , pty_control }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
new file mode 100644
index 0000000000..903b6dfb51
--- /dev/null
+++ b/cpukit/telnetd/telnetd.c
@@ -0,0 +1,512 @@
+/***********************************************************/
+/*
+ *
+ * The telnet DAEMON
+ *
+ * Author: 17,may 2001
+ *
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * After start the net you can start this daemon.
+ * It uses the previously inited pseudo-terminales (pty.c)
+ * getting a new terminal with getpty(). This function
+ * gives a terminal name passing a opened socket like parameter.
+ *
+ * With register_telnetd() you add a new command in the shell to start
+ * this daemon interactively. (Login in /dev/console of course)
+ *
+ * Sorry but OOB is not still implemented. (This is the first version)
+ *
+ * Till Straumann <strauman@slac.stanford.edu>
+ * - made the 'shell' interface more generic, i.e. it is now
+ * possible to have 'telnetd' run an arbitrary 'shell'
+ * program.
+ *
+ * Copyright (c) 2009 embedded brains GmbH and others.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/pty.h>
+#include <rtems/shell.h>
+#include <rtems/telnetd.h>
+#include <rtems/bspIo.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+
+#include <rtems/userenv.h>
+#include <rtems/error.h>
+#include <rtems/rtems_bsdnet.h>
+
+#define PARANOIA
+
+extern char *telnet_get_pty(int socket);
+extern int telnet_pty_initialize(void);
+
+struct shell_args {
+ char *devname;
+ void *arg;
+ char peername[16];
+ char delete_myself;
+};
+
+typedef union uni_sa {
+ struct sockaddr_in sin;
+ struct sockaddr sa;
+} uni_sa;
+
+static int sockpeername(int sock, char *buf, int bufsz);
+
+rtems_id telnetd_dflt_spawn(
+ const char *name,
+ unsigned priority,
+ unsigned stackSize,
+ void (*fn)(void*),
+ void *fnarg
+);
+
+/***********************************************************/
+static rtems_id telnetd_task_id = RTEMS_ID_NONE;
+
+rtems_id (*telnetd_spawn_task)(
+ const char *,
+ unsigned,
+ unsigned,
+ void (*)(void*),
+ void *
+) = telnetd_dflt_spawn;
+
+static char *grab_a_Connection(
+ int des_socket,
+ uni_sa *srv,
+ char *peername,
+ int sz
+)
+{
+ char *rval = 0;
+#if 0
+ socklen_t size_adr = sizeof(srv->sin);
+#else
+ /* 4.6 doesn't have socklen_t */
+ uint32_t size_adr = sizeof(srv->sin);
+#endif
+ int acp_sock;
+
+ acp_sock = accept(des_socket,&srv->sa,&size_adr);
+
+ if (acp_sock<0) {
+ perror("telnetd:accept");
+ goto bailout;
+ };
+
+ if ( !(rval=telnet_get_pty(acp_sock)) ) {
+ syslog( LOG_DAEMON | LOG_ERR, "telnetd: unable to obtain PTY");
+ /* NOTE: failing 'do_get_pty()' closed the socket */
+ goto bailout;
+ }
+
+ if (sockpeername(acp_sock, peername, sz))
+ strncpy(peername, "<UNKNOWN>", sz);
+
+#ifdef PARANOIA
+ syslog(LOG_DAEMON | LOG_INFO,
+ "telnetd: accepted connection from %s on %s",
+ peername,
+ rval);
+#endif
+
+bailout:
+
+ return rval;
+}
+
+
+static void release_a_Connection(char *devname, char *peername, FILE **pstd, int n)
+{
+
+#ifdef PARANOIA
+ syslog( LOG_DAEMON | LOG_INFO,
+ "telnetd: releasing connection from %s on %s",
+ peername,
+ devname );
+#endif
+
+ while (--n>=0)
+ if (pstd[n]) fclose(pstd[n]);
+
+}
+
+static int sockpeername(int sock, char *buf, int bufsz)
+{
+ uni_sa peer;
+ int rval = sock < 0;
+#if 0
+ socklen_t len = sizeof(peer.sin);
+#else
+ /* 4.6 doesn't have socklen_t */
+ uint32_t len = sizeof(peer.sin);
+#endif
+
+ if ( !rval )
+ rval = getpeername(sock, &peer.sa, &len);
+
+ if ( !rval )
+ rval = !inet_ntop( AF_INET, &peer.sin.sin_addr, buf, bufsz );
+
+ return rval;
+}
+
+static void
+spawned_shell(void *arg);
+
+/***********************************************************/
+static void
+rtems_task_telnetd(void *task_argument)
+{
+ int des_socket;
+ uni_sa srv;
+ char *devname;
+ char peername[16];
+ int i=1;
+ int size_adr;
+ struct shell_args *arg = NULL;
+
+ if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
+ perror("telnetd:socket");
+ telnetd_task_id = RTEMS_ID_NONE;
+ rtems_task_delete(RTEMS_SELF);
+ };
+ setsockopt(des_socket,SOL_SOCKET,SO_KEEPALIVE,&i,sizeof(i));
+
+ memset(&srv,0,sizeof(srv));
+ srv.sin.sin_family=AF_INET;
+ srv.sin.sin_port=htons(23);
+ size_adr=sizeof(srv.sin);
+ if ((bind(des_socket,&srv.sa,size_adr))<0) {
+ perror("telnetd:bind");
+ close(des_socket);
+ telnetd_task_id = RTEMS_ID_NONE;
+ rtems_task_delete(RTEMS_SELF);
+ };
+ if ((listen(des_socket,5))<0) {
+ perror("telnetd:listen");
+ close(des_socket);
+ telnetd_task_id = RTEMS_ID_NONE;
+ rtems_task_delete(RTEMS_SELF);
+ };
+
+ /* we don't redirect stdio as this probably
+ * was started from the console anyways..
+ */
+ do {
+ if (rtems_telnetd_config.keep_stdio) {
+ bool start = true;
+ char device_name [32];
+
+ ttyname_r( 1, device_name, sizeof( device_name));
+ if (rtems_telnetd_config.login_check != NULL) {
+ start = rtems_shell_login_prompt(
+ stdin,
+ stderr,
+ device_name,
+ rtems_telnetd_config.login_check
+ );
+ }
+ if (start) {
+ rtems_telnetd_config.command( device_name, arg->arg);
+ } else {
+ syslog(
+ LOG_AUTHPRIV | LOG_WARNING,
+ "telnetd: to many wrong passwords entered from %s",
+ device_name
+ );
+ }
+ } else {
+ devname = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
+
+ if ( !devname ) {
+ /* if something went wrong, sleep for some time */
+ sleep(10);
+ continue;
+ }
+
+ arg = malloc( sizeof(*arg) );
+
+ arg->devname = devname;
+ arg->arg = rtems_telnetd_config.arg;
+ strncpy(arg->peername, peername, sizeof(arg->peername));
+
+ telnetd_task_id = telnetd_spawn_task(
+ devname,
+ rtems_telnetd_config.priority,
+ rtems_telnetd_config.stack_size,
+ spawned_shell,
+ arg
+ );
+ if (telnetd_task_id == RTEMS_ID_NONE) {
+ FILE *dummy;
+
+ if ( telnetd_spawn_task != telnetd_dflt_spawn ) {
+ fprintf(stderr,"Telnetd: Unable to spawn child task\n");
+ }
+
+ /* hmm - the pty driver slot can only be
+ * released by opening and subsequently
+ * closing the PTY - this also closes
+ * the underlying socket. So we mock up
+ * a stream...
+ */
+
+ if ( !(dummy=fopen(devname,"r+")) )
+ perror("Unable to dummy open the pty, losing a slot :-(");
+ release_a_Connection(devname, peername, &dummy, 1);
+ free(arg);
+ sleep(2); /* don't accept connections too fast */
+ }
+ }
+ } while(1);
+
+ /* TODO: how to free the connection semaphore? But then -
+ * stopping the daemon is probably only needed during
+ * development/debugging.
+ * Finalizer code should collect all the connection semaphore
+ * counts and eventually clean up...
+ */
+ close(des_socket);
+ telnetd_task_id = RTEMS_ID_NONE;
+}
+
+rtems_status_code rtems_telnetd_initialize( void)
+{
+ if (telnetd_task_id != RTEMS_ID_NONE) {
+ fprintf(stderr, "telnetd already started\n");
+ return RTEMS_RESOURCE_IN_USE;
+ }
+
+ if (rtems_telnetd_config.command == NULL) {
+ fprintf(stderr, "telnetd setup with invalid command\n");
+ return RTEMS_IO_ERROR;
+ }
+
+ if ( !telnet_pty_initialize() ) {
+ fprintf(stderr, "telnetd cannot initialize PTY driver\n");
+ return RTEMS_IO_ERROR;
+ }
+
+ /* Check priority */
+ if (rtems_telnetd_config.priority <= 0) {
+ rtems_telnetd_config.priority = rtems_bsdnet_config.network_task_priority;
+ }
+ if (rtems_telnetd_config.priority < 2) {
+ rtems_telnetd_config.priority = 100;
+ }
+
+ /* Check stack size */
+ if (rtems_telnetd_config.stack_size <= 0) {
+ rtems_telnetd_config.stack_size = (size_t)32 * 1024;
+ }
+
+ /* Spawn task */
+ telnetd_task_id = telnetd_spawn_task(
+ "TNTD",
+ rtems_telnetd_config.priority,
+ rtems_telnetd_config.stack_size,
+ rtems_task_telnetd,
+ 0
+ );
+ if (telnetd_task_id == RTEMS_ID_NONE) {
+ return RTEMS_IO_ERROR;
+ }
+
+ /* Print status */
+ if (!rtems_telnetd_config.keep_stdio) {
+ fprintf(
+ stderr,
+ "telnetd started with stacksize = %u and priority = %d\n",
+ (unsigned) rtems_telnetd_config.stack_size,
+ (unsigned) rtems_telnetd_config.priority
+ );
+ }
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/* utility wrapper */
+static void
+spawned_shell(void *targ)
+{
+ rtems_status_code sc;
+ FILE *nstd[3]={0};
+ FILE *ostd[3]={ stdin, stdout, stderr };
+ int i=0;
+ struct shell_args *arg = targ;
+ bool login_failed = false;
+ bool start = true;
+
+ sc=rtems_libio_set_private_env();
+
+ /* newlib hack/workaround. Before we change stdin/out/err we must make
+ * sure the internal data are initialized (fileno(stdout) has this sideeffect).
+ * This should probably be done from RTEMS' libc support layer...
+ * (T.S., newlibc-1.13; 2005/10)
+ */
+
+ fileno(stdout);
+
+ if (RTEMS_SUCCESSFUL != sc) {
+ rtems_error(sc,"rtems_libio_set_private_env");
+ goto cleanup;
+ }
+
+ /* redirect stdio */
+ for (i=0; i<3; i++) {
+ if ( !(nstd[i]=fopen(arg->devname,"r+")) ) {
+ perror("unable to open stdio");
+ goto cleanup;
+ }
+ }
+
+ stdin = nstd[0];
+ stdout = nstd[1];
+ stderr = nstd[2];
+
+ #if 0
+ printk("STDOUT is now %x (%x) (FD %i/%i)\n",
+ stdout,nstd[1],fileno(stdout),fileno(nstd[1]));
+ printf("hello\n");
+ write(fileno(stdout),"hellofd\n",8);
+ #endif
+
+ /* call their routine */
+ if (rtems_telnetd_config.login_check != NULL) {
+ start = rtems_shell_login_prompt(
+ stdin,
+ stderr,
+ arg->devname,
+ rtems_telnetd_config.login_check
+ );
+ login_failed = !start;
+ }
+ if (start) {
+ rtems_telnetd_config.command( arg->devname, arg->arg);
+ }
+
+ stdin = ostd[0];
+ stdout = ostd[1];
+ stderr = ostd[2];
+
+ if (login_failed) {
+ syslog(
+ LOG_AUTHPRIV | LOG_WARNING,
+ "telnetd: to many wrong passwords entered from %s",
+ arg->peername
+ );
+ }
+
+cleanup:
+ release_a_Connection(arg->devname, arg->peername, nstd, i);
+ free(arg);
+}
+
+struct wrap_delete_args {
+ void (*t)(void *);
+ void *a;
+};
+
+static rtems_task
+wrap_delete(rtems_task_argument arg)
+{
+ struct wrap_delete_args *pwa = (struct wrap_delete_args *)arg;
+ register void (*t)(void *) = pwa->t;
+ register void *a = pwa->a;
+
+ /* free argument before calling function (which may never return if
+ * they choose to delete themselves)
+ */
+ free(pwa);
+ t(a);
+ rtems_task_delete(RTEMS_SELF);
+}
+
+rtems_id
+telnetd_dflt_spawn(const char *name, unsigned int priority, unsigned int stackSize, void (*fn)(void *), void* fnarg)
+{
+ rtems_status_code sc;
+ rtems_id task_id = RTEMS_ID_NONE;
+ char nm[4] = {'X','X','X','X' };
+ struct wrap_delete_args *pwa = malloc(sizeof(*pwa));
+
+ strncpy(nm, name, 4);
+
+ if ( !pwa ) {
+ perror("Telnetd: no memory\n");
+ return RTEMS_ID_NONE;
+ }
+
+ pwa->t = fn;
+ pwa->a = fnarg;
+
+ if ((sc=rtems_task_create(
+ rtems_build_name(nm[0], nm[1], nm[2], nm[3]),
+ (rtems_task_priority)priority,
+ stackSize,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
+ &task_id)) ||
+ (sc=rtems_task_start(
+ task_id,
+ wrap_delete,
+ (rtems_task_argument)pwa))) {
+ free(pwa);
+ rtems_error(sc,"Telnetd: spawning task failed");
+ return RTEMS_ID_NONE;
+ }
+ return task_id;
+}
+
+/* convenience routines for CEXP (retrieve stdio descriptors
+ * from reent structure)
+ */
+#ifdef stdin
+static __inline__ FILE *
+_stdin(void) { return stdin; }
+#undef stdin
+FILE *stdin(void) { return _stdin(); }
+#endif
+#ifdef stdout
+static __inline__ FILE *
+_stdout(void) { return stdout; }
+#undef stdout
+FILE *stdout(void) { return _stdout(); }
+#endif
+#ifdef stderr
+static __inline__ FILE *
+_stderr(void) { return stderr; }
+#undef stderr
+FILE *stderr(void) { return _stderr(); }
+#endif
+
+/* MUST NOT USE stdin & friends below here !!!!!!!!!!!!! */
diff --git a/cpukit/telnetd/telnetd.h b/cpukit/telnetd/telnetd.h
new file mode 100644
index 0000000000..a146ad942b
--- /dev/null
+++ b/cpukit/telnetd/telnetd.h
@@ -0,0 +1,112 @@
+/*
+ * Original Author: Fernando RUIZ CASAS (fernando.ruiz@ctv.es)
+ * May 2001
+ * Reworked by Till Straumann and .h overhauled by Joel Sherrill.
+ *
+ * Copyright (c) 2009 embedded brains GmbH and others.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_TELNETD_H
+#define _RTEMS_TELNETD_H
+
+#include <rtems.h>
+#include <rtems/shell.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool rtems_telnetd_login_check(
+ const char *user,
+ const char *passphrase
+);
+
+/**
+ * @brief Telnet command type.
+ */
+typedef void (*rtems_telnetd_command)(
+ char * /* device name */,
+ void * /* arg */
+);
+
+/**
+ * @brief Telnet configuration structure.
+ */
+typedef struct {
+ /**
+ * @brief Function invoked for each Telnet connection.
+ *
+ * The first parameter contains the device name. The second parameter
+ * contains the argument pointer of this configuration table.
+ */
+ rtems_telnetd_command command;
+
+ /**
+ * @brief Argument for command function.
+ */
+ void *arg;
+
+ /**
+ * @brief Task priority.
+ *
+ * If this parameter is equal to zero, then the priority of network task is
+ * used or 100 if this priority is less than two.
+ */
+ rtems_task_priority priority;
+
+ /**
+ * @brief Task stack size.
+ */
+ size_t stack_size;
+
+ /**
+ * @brief Login check function.
+ *
+ * Method used for login checks. Use @c NULL to disable a login check.
+ */
+ rtems_shell_login_check_t login_check;
+
+ /**
+ * @brief Keep standard IO of the caller.
+ *
+ * Telnet takes over the standard input, output and error associated with
+ * task, if this parameter is set to @c true. In this case, it will @b not
+ * listen on any sockets. When this parameter is @c false, Telnet will
+ * create other tasks for the shell which listen on sockets.
+ */
+ bool keep_stdio;
+} rtems_telnetd_config_table;
+
+/**
+ * @brief Telnet configuration.
+ *
+ * The application must provide this configuration table. It is used by
+ * rtems_telnetd_initialize() to configure the Telnet subsystem. Do not modify
+ * the entries after the intialization since it is used internally.
+ */
+extern rtems_telnetd_config_table rtems_telnetd_config;
+
+/**
+ * @brief Initializes the Telnet subsystem.
+ *
+ * Uses the application provided @ref rtems_telnetd_config configuration table.
+ */
+rtems_status_code rtems_telnetd_initialize(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/wrapup/.cvsignore b/cpukit/wrapup/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/wrapup/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/wrapup/Makefile.am b/cpukit/wrapup/Makefile.am
new file mode 100644
index 0000000000..b5b89fb73f
--- /dev/null
+++ b/cpukit/wrapup/Makefile.am
@@ -0,0 +1,113 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+## Setup the variant build subdirectory
+ARCH = o-optimize
+
+project_lib_LIBRARIES = librtemscpu.a
+librtemscpu_a_SOURCES =
+
+TMP_LIBS =
+TMP_LIBS += ../score/cpu/@RTEMS_CPU@/libscorecpu.a
+TMP_LIBS += ../score/libscore.a
+TMP_LIBS += ../sapi/libsapi.a
+TMP_LIBS += ../rtems/librtems.a
+TMP_LIBS += ../posix/libposix.a
+
+if LIBGNAT
+TMP_LIBS += ../libgnat/libgnat.a
+endif
+
+TMP_LIBS += ../libcsupport/libcsupport.a
+TMP_LIBS += ../libblock/libblock.a
+if LIBDOSFS
+TMP_LIBS += ../libfs/libdosfs.a
+endif
+TMP_LIBS += ../libfs/libdefaultfs.a
+TMP_LIBS += ../libfs/libdevfs.a
+TMP_LIBS += ../libfs/libimfs.a
+TMP_LIBS += ../libfs/librfs.a
+
+TMP_LIBS += ../libmisc/libmonitor.a
+TMP_LIBS += ../libmisc/libuntar.a
+TMP_LIBS += ../libmisc/libstackchk.a
+TMP_LIBS += ../libmisc/libcpuuse.a
+
+## XXX temporarily removed because it causes a
+## XXX number of BSPs to not link "main(){}" used by autoconf
+# if LIBSERDBG
+# TMP_LIBS += ../libmisc/libserdbg.a
+# endif
+
+if LIBSHELL
+TMP_LIBS += ../libmisc/libshell.a
+endif
+
+TMP_LIBS += ../libmisc/libbspcmdline.a
+TMP_LIBS += ../libmisc/libcapture.a
+TMP_LIBS += ../libmisc/libdumpbuf.a
+TMP_LIBS += ../libmisc/libdevnull.a
+TMP_LIBS += ../libmisc/libdummy.a
+TMP_LIBS += ../libmisc/libfsmount.a
+TMP_LIBS += ../libmisc/libmouse.a
+TMP_LIBS += ../libmisc/libmw-fb.a
+TMP_LIBS += ../libmisc/libstringto.a
+TMP_LIBS += ../libmisc/libuuid.a
+
+TMP_LIBS += ../libi2c/libi2c.a
+
+if LIBNETWORKING
+TMP_LIBS += ../libnetworking/libnetworking.a
+TMP_LIBS += ../libnetworking/libc.a
+TMP_LIBS += ../libnetworking/lib.a
+endif
+
+if LIBRPC
+TMP_LIBS += ../librpc/librpc.a
+TMP_LIBS += ../librpc/libxdr.a
+endif
+
+if NEWLIB
+TMP_LIBS += ../libmd/libmd.a
+endif
+
+librtemscpu.a: $(TMP_LIBS)
+ rm -f $@
+ $(MKDIR_P) $(ARCH)
+ rm -rf $(ARCH)/*.$(OBJEXT) $(ARCH)/*.rel
+ for f in $(TMP_LIBS); do \
+ case $$f in \
+ *.$(OBJEXT) | *.rel) \
+ if test -f $(ARCH)/`basename $$f`; then \
+ if cmp $$f $(ARCH)/`basename $$f`; then \
+ true; \
+ else \
+ echo 1>&2 "ERROR -- `basename $$f` in multiple files"; \
+ exit 1; \
+ fi; \
+ else \
+ cp $$f $(ARCH)/; \
+ chmod a-w $(ARCH)/`basename $$f`; \
+ fi; \
+ ;; \
+ *.a) \
+ cd $(ARCH); \
+ $(AR) xv ../$$f || exit 1; \
+ chmod a-w * ; \
+ cd ..; \
+ ;; \
+ esac; \
+ done
+ ls $(ARCH)/* > $@-list
+ $(AR) rc $@ @$@-list
+ rm -f $@-list $(ARCH)/*.$(OBJEXT) $(ARCH)/*.rel
+ $(RANLIB) $@
+
+all-local: $(TMPINSTALL_FILES)
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/wrapup/preinstall.am b/cpukit/wrapup/preinstall.am
new file mode 100644
index 0000000000..0c39a9cf28
--- /dev/null
+++ b/cpukit/wrapup/preinstall.am
@@ -0,0 +1,24 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+$(PROJECT_LIB)/librtemscpu.a: librtemscpu.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/librtemscpu.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/librtemscpu.a
+
diff --git a/cpukit/zlib/.cvsignore b/cpukit/zlib/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/cpukit/zlib/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cpukit/zlib/ChangeLog b/cpukit/zlib/ChangeLog
index 6d046ee44b..cc4f466598 100644
--- a/cpukit/zlib/ChangeLog
+++ b/cpukit/zlib/ChangeLog
@@ -1,1130 +1,58 @@
+2010-03-22 Joel Sherrill <joel.sherrill@oarcorp.com>
- ChangeLog file for zlib
+ * ChangeLog.zlib, FAQ, Makefile.am, README, adler32.c, compress.c,
+ crc32.c, deflate.c, deflate.h, infback.c, inffast.c, inflate.c,
+ inflate.h, inftrees.c, inftrees.h, trees.c, uncompr.c, zconf.h,
+ zlib.3, zlib.h, zutil.c, zutil.h: Update to zlib 1.2.4.
+ * gzclose.c, gzguts.h, gzlib.c, gzread.c, gzwrite.c, doc/algorithm.txt:
+ New files.
+ * algorithm.txt, gzio.c: Removed.
-Changes in 1.2.4 (14 Mar 2010)
-- Fix VER3 extraction in configure for no fourth subversion
-- Update zlib.3, add docs to Makefile.in to make .pdf out of it
-- Add zlib.3.pdf to distribution
-- Don't set error code in gzerror() if passed pointer is NULL
-- Apply destination directory fixes to CMakeLists.txt [Lowman]
-- Move #cmakedefine's to a new zconf.in.cmakein
-- Restore zconf.h for builds that don't use configure or cmake
-- Add distclean to dummy Makefile for convenience
-- Update and improve INDEX, README, and FAQ
-- Update CMakeLists.txt for the return of zconf.h [Lowman]
-- Update contrib/vstudio/vc9 and vc10 [Vollant]
-- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc
-- Apply license and readme changes to contrib/asm686 [Raiter]
-- Check file name lengths and add -c option in minigzip.c [Li]
-- Update contrib/amd64 and contrib/masmx86/ [Vollant]
-- Avoid use of "eof" parameter in trees.c to not shadow library variable
-- Update make_vms.com for removal of zlibdefs.h [Zinser]
-- Update assembler code and vstudio projects in contrib [Vollant]
-- Remove outdated assembler code contrib/masm686 and contrib/asm586
-- Remove old vc7 and vc8 from contrib/vstudio
-- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe]
-- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open()
-- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant]
-- Remove *64 functions from win32/zlib.def (they're not 64-bit yet)
-- Fix bug in void-returning vsprintf() case in gzwrite.c
-- Fix name change from inflate.h in contrib/inflate86/inffas86.c
-- Check if temporary file exists before removing in make_vms.com [Zinser]
-- Fix make install and uninstall for --static option
-- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta]
-- Update readme.txt in contrib/masmx64 and masmx86 to assemble
+2008-12-18 Joel Sherrill <joel.sherrill@oarcorp.com>
-Changes in 1.2.3.9 (21 Feb 2010)
-- Expunge gzio.c
-- Move as400 build information to old
-- Fix updates in contrib/minizip and contrib/vstudio
-- Add const to vsnprintf test in configure to avoid warnings [Weigelt]
-- Delete zconf.h (made by configure) [Weigelt]
-- Change zconf.in.h to zconf.h.in per convention [Weigelt]
-- Check for NULL buf in gzgets()
-- Return empty string for gzgets() with len == 1 (like fgets())
-- Fix description of gzgets() in zlib.h for end-of-file, NULL return
-- Update minizip to 1.1 [Vollant]
-- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c
-- Note in zlib.h that gzerror() should be used to distinguish from EOF
-- Remove use of snprintf() from gzlib.c
-- Fix bug in gzseek()
-- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant]
-- Fix zconf.h generation in CMakeLists.txt [Lowman]
-- Improve comments in zconf.h where modified by configure
+ * zutil.c, zutil.h: Make code match prototype to eliminate warnings.
-Changes in 1.2.3.8 (13 Feb 2010)
-- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer]
-- Use z_off64_t in gz_zero() and gz_skip() to match state->skip
-- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t)
-- Revert to Makefile.in from 1.2.3.6 (live with the clutter)
-- Fix missing error return in gzflush(), add zlib.h note
-- Add *64 functions to zlib.map [Levin]
-- Fix signed/unsigned comparison in gz_comp()
-- Use SFLAGS when testing shared linking in configure
-- Add --64 option to ./configure to use -m64 with gcc
-- Fix ./configure --help to correctly name options
-- Have make fail if a test fails [Levin]
-- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson]
-- Remove assembler object files from contrib
+2008-09-02 Ralf Corsépius <ralf.corsepius@rtems.org>
-Changes in 1.2.3.7 (24 Jan 2010)
-- Always gzopen() with O_LARGEFILE if available
-- Fix gzdirect() to work immediately after gzopen() or gzdopen()
-- Make gzdirect() more precise when the state changes while reading
-- Improve zlib.h documentation in many places
-- Catch memory allocation failure in gz_open()
-- Complete close operation if seek forward in gzclose_w() fails
-- Return Z_ERRNO from gzclose_r() if close() fails
-- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL
-- Return zero for gzwrite() errors to match zlib.h description
-- Return -1 on gzputs() error to match zlib.h description
-- Add zconf.in.h to allow recovery from configure modification [Weigelt]
-- Fix static library permissions in Makefile.in [Weigelt]
-- Avoid warnings in configure tests that hide functionality [Weigelt]
-- Add *BSD and DragonFly to Linux case in configure [gentoo 123571]
-- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212]
-- Avoid access of uninitialized data for first inflateReset2 call [Gomes]
-- Keep object files in subdirectories to reduce the clutter somewhat
-- Remove default Makefile and zlibdefs.h, add dummy Makefile
-- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_
-- Remove zlibdefs.h completely -- modify zconf.h instead
+ * adler32.c, compress.c, crc32.c, deflate.c, gzio.c, infback.c,
+ inflate.c, inffast.c, inftrees.c, trees.c, uncompr.c, zutil.c:
+ Stop using old-style function definitions.
-Changes in 1.2.3.6 (17 Jan 2010)
-- Avoid void * arithmetic in gzread.c and gzwrite.c
-- Make compilers happier with const char * for gz_error message
-- Avoid unused parameter warning in inflate.c
-- Avoid signed-unsigned comparison warning in inflate.c
-- Indent #pragma's for traditional C
-- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
-- Correct email address in configure for system options
-- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
-- Update zlib.map [Brown]
-- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Tšršk]
-- Apply various fixes to CMakeLists.txt [Lowman]
-- Add checks on len in gzread() and gzwrite()
-- Add error message for no more room for gzungetc()
-- Remove zlib version check in gzwrite()
-- Defer compression of gzprintf() result until need to
-- Use snprintf() in gzdopen() if available
-- Remove USE_MMAP configuration determination (only used by minigzip)
-- Remove examples/pigz.c (available separately)
-- Update examples/gun.c to 1.6
+2008-09-01 Ralf Corsépius <ralf.corsepius@rtems.org>
-Changes in 1.2.3.5 (8 Jan 2010)
-- Add space after #if in zutil.h for some compilers
-- Fix relatively harmless bug in deflate_fast() [Exarevsky]
-- Fix same problem in deflate_slow()
-- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown]
-- Add deflate_rle() for faster Z_RLE strategy run-length encoding
-- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding
-- Change name of "write" variable in inffast.c to avoid library collisions
-- Fix premature EOF from gzread() in gzio.c [Brown]
-- Use zlib header window size if windowBits is 0 in inflateInit2()
-- Remove compressBound() call in deflate.c to avoid linking compress.o
-- Replace use of errno in gz* with functions, support WinCE [Alves]
-- Provide alternative to perror() in minigzip.c for WinCE [Alves]
-- Don't use _vsnprintf on later versions of MSVC [Lowman]
-- Add CMake build script and input file [Lowman]
-- Update contrib/minizip to 1.1 [Svensson, Vollant]
-- Moved nintendods directory from contrib to .
-- Replace gzio.c with a new set of routines with the same functionality
-- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
-- Update contrib/minizip to 1.1b
-- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
+ * ChangeLog.zlib, README, adler32.c, compress.c, crc32.c, deflate.c,
+ deflate.h, gzio.c, infback.c, inflate.c, inftrees.c, inftrees.h,
+ trees.c, uncompr.c, zconf.h, zlib.3, zlib.h, zutil.c, zutil.h:
+ Upgrade to zlib-1.2.3.
-Changes in 1.2.3.4 (21 Dec 2009)
-- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
-- Update comments in configure and Makefile.in for default --shared
-- Fix test -z's in configure [Marquess]
-- Build examplesh and minigzipsh when not testing
-- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h
-- Import LDFLAGS from the environment in configure
-- Fix configure to populate SFLAGS with discovered CFLAGS options
-- Adapt make_vms.com to the new Makefile.in [Zinser]
-- Add zlib2ansi script for C++ compilation [Marquess]
-- Add _FILE_OFFSET_BITS=64 test to make test (when applicable)
-- Add AMD64 assembler code for longest match to contrib [Teterin]
-- Include options from $SFLAGS when doing $LDSHARED
-- Simplify 64-bit file support by introducing z_off64_t type
-- Make shared object files in objs directory to work around old Sun cc
-- Use only three-part version number for Darwin shared compiles
-- Add rc option to ar in Makefile.in for when ./configure not run
-- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4*
-- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile
-- Protect against _FILE_OFFSET_BITS being defined when compiling zlib
-- Rename Makefile.in targets allstatic to static and allshared to shared
-- Fix static and shared Makefile.in targets to be independent
-- Correct error return bug in gz_open() by setting state [Brown]
-- Put spaces before ;;'s in configure for better sh compatibility
-- Add pigz.c (parallel implementation of gzip) to examples/
-- Correct constant in crc32.c to UL [Leventhal]
-- Reject negative lengths in crc32_combine()
-- Add inflateReset2() function to work like inflateEnd()/inflateInit2()
-- Include sys/types.h for _LARGEFILE64_SOURCE [Brown]
-- Correct typo in doc/algorithm.txt [Janik]
-- Fix bug in adler32_combine() [Zhu]
-- Catch missing-end-of-block-code error in all inflates and in puff
- Assures that random input to inflate eventually results in an error
-- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/
-- Update ENOUGH and its usage to reflect discovered bounds
-- Fix gzerror() error report on empty input file [Brown]
-- Add ush casts in trees.c to avoid pedantic runtime errors
-- Fix typo in zlib.h uncompress() description [Reiss]
-- Correct inflate() comments with regard to automatic header detection
-- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays)
-- Put new version of gzlog (2.0) in examples with interruption recovery
-- Add puff compile option to permit invalid distance-too-far streams
-- Add puff TEST command options, ability to read piped input
-- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but
- _LARGEFILE64_SOURCE not defined
-- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart
-- Fix deflateSetDictionary() to use all 32K for output consistency
-- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h)
-- Clear bytes after deflate lookahead to avoid use of uninitialized data
-- Change a limit in inftrees.c to be more transparent to Coverity Prevent
-- Update win32/zlib.def with exported symbols from zlib.h
-- Correct spelling error in zlib.h [Willem]
-- Allow Z_BLOCK for deflate() to force a new block
-- Allow negative bits in inflatePrime() to delete existing bit buffer
-- Add Z_TREES flush option to inflate() to return at end of trees
-- Add inflateMark() to return current state information for random access
-- Add Makefile for NintendoDS to contrib [Costa]
-- Add -w in configure compile tests to avoid spurious warnings [Beucler]
-- Fix typos in zlib.h comments for deflateSetDictionary()
-- Fix EOF detection in transparent gzread() [Maier]
+2005-10-30 Ralf Corsepius <ralf.corsepius@rtems.org>
-Changes in 1.2.3.3 (2 October 2006)
-- Make --shared the default for configure, add a --static option
-- Add compile option to permit invalid distance-too-far streams
-- Add inflateUndermine() function which is required to enable above
-- Remove use of "this" variable name for C++ compatibility [Marquess]
-- Add testing of shared library in make test, if shared library built
-- Use ftello() and fseeko() if available instead of ftell() and fseek()
-- Provide two versions of all functions that use the z_off_t type for
- binary compatibility -- a normal version and a 64-bit offset version,
- per the Large File Support Extension when _LARGEFILE64_SOURCE is
- defined; use the 64-bit versions by default when _FILE_OFFSET_BITS
- is defined to be 64
-- Add a --uname= option to configure to perhaps help with cross-compiling
+ * zconf.h: Hard-code using unistd.h.
+ Hard-code Z_PREFIX.
-Changes in 1.2.3.2 (3 September 2006)
-- Turn off silly Borland warnings [Hay]
-- Use off64_t and define _LARGEFILE64_SOURCE when present
-- Fix missing dependency on inffixed.h in Makefile.in
-- Rig configure --shared to build both shared and static [Teredesai, Truta]
-- Remove zconf.in.h and instead create a new zlibdefs.h file
-- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant]
-- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt]
+2005-10-28 Ralf Corsepius <ralf.corsepius@rtems.org>
-Changes in 1.2.3.1 (16 August 2006)
-- Add watcom directory with OpenWatcom make files [Daniel]
-- Remove #undef of FAR in zconf.in.h for MVS [Fedtke]
-- Update make_vms.com [Zinser]
-- Use -fPIC for shared build in configure [Teredesai, Nicholson]
-- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen]
-- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck]
-- Add some FAQ entries about the contrib directory
-- Update the MVS question in the FAQ
-- Avoid extraneous reads after EOF in gzio.c [Brown]
-- Correct spelling of "successfully" in gzio.c [Randers-Pehrson]
-- Add comments to zlib.h about gzerror() usage [Brown]
-- Set extra flags in gzip header in gzopen() like deflate() does
-- Make configure options more compatible with double-dash conventions
- [Weigelt]
-- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen]
-- Fix uninstall target in Makefile.in [Truta]
-- Add pkgconfig support [Weigelt]
-- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt]
-- Replace set_data_type() with a more accurate detect_data_type() in
- trees.c, according to the txtvsbin.txt document [Truta]
-- Swap the order of #include <stdio.h> and #include "zlib.h" in
- gzio.c, example.c and minigzip.c [Truta]
-- Shut up annoying VS2005 warnings about standard C deprecation [Rowe,
- Truta] (where?)
-- Fix target "clean" from win32/Makefile.bor [Truta]
-- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe]
-- Update zlib www home address in win32/DLL_FAQ.txt [Truta]
-- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove]
-- Enable browse info in the "Debug" and "ASM Debug" configurations in
- the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta]
-- Add pkgconfig support [Weigelt]
-- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h,
- for use in win32/zlib1.rc [Polushin, Rowe, Truta]
-- Add a document that explains the new text detection scheme to
- doc/txtvsbin.txt [Truta]
-- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta]
-- Move algorithm.txt into doc/ [Truta]
-- Synchronize FAQ with website
-- Fix compressBound(), was low for some pathological cases [Fearnley]
-- Take into account wrapper variations in deflateBound()
-- Set examples/zpipe.c input and output to binary mode for Windows
-- Update examples/zlib_how.html with new zpipe.c (also web site)
-- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems
- that gcc became pickier in 4.0)
-- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain
- un-versioned, the patch adds versioning only for symbols introduced in
- zlib-1.2.0 or later. It also declares as local those symbols which are
- not designed to be exported." [Levin]
-- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure
-- Do not initialize global static by default in trees.c, add a response
- NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess]
-- Don't use strerror() in gzio.c under WinCE [Yakimov]
-- Don't use errno.h in zutil.h under WinCE [Yakimov]
-- Move arguments for AR to its usage to allow replacing ar [Marot]
-- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson]
-- Improve inflateInit() and inflateInit2() documentation
-- Fix structure size comment in inflate.h
-- Change configure help option from --h* to --help [Santos]
+ * zconf.in.h: Remove (Unused).
+ * zconf.h: Use uint_least*_t types.
+ * crc32.c, zutil.c, zutil.h: Misc. type fixes.
-Changes in 1.2.3 (18 July 2005)
-- Apply security vulnerability fixes to contrib/infback9 as well
-- Clean up some text files (carriage returns, trailing space)
-- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
+2005-10-28 Ralf Corsepius <ralf.corsepius@rtems.org>
-Changes in 1.2.2.4 (11 July 2005)
-- Add inflatePrime() function for starting inflation at bit boundary
-- Avoid some Visual C warnings in deflate.c
-- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
- compile
-- Fix some spelling errors in comments [Betts]
-- Correct inflateInit2() error return documentation in zlib.h
-- Add zran.c example of compressed data random access to examples
- directory, shows use of inflatePrime()
-- Fix cast for assignments to strm->state in inflate.c and infback.c
-- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
-- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
-- Add cast in trees.c t avoid a warning [Oberhumer]
-- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
-- Update make_vms.com [Zinser]
-- Initialize state->write in inflateReset() since copied in inflate_fast()
-- Be more strict on incomplete code sets in inflate_table() and increase
- ENOUGH and MAXD -- this repairs a possible security vulnerability for
- invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
- discovering the vulnerability and providing test cases.
-- Add ia64 support to configure for HP-UX [Smith]
-- Add error return to gzread() for format or i/o error [Levin]
-- Use malloc.h for OS/2 [Necasek]
+ * Makefile.am: New.
+ * preinstall.am: New.
-Changes in 1.2.2.3 (27 May 2005)
-- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
-- Typecast fread() return values in gzio.c [Vollant]
-- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
-- Fix crc check bug in gzread() after gzungetc() [Heiner]
-- Add the deflateTune() function to adjust internal compression parameters
-- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
-- Remove an incorrect assertion in examples/zpipe.c
-- Add C++ wrapper in infback9.h [Donais]
-- Fix bug in inflateCopy() when decoding fixed codes
-- Note in zlib.h how much deflateSetDictionary() actually uses
-- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
-- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
-- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
-- Add gzdirect() function to indicate transparent reads
-- Update contrib/minizip [Vollant]
-- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
-- Add casts in crc32.c to avoid warnings [Oberhumer]
-- Add contrib/masmx64 [Vollant]
-- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
+2005-10-28 Ralf Corsepius <ralf.corsepius@rtems.org>
-Changes in 1.2.2.2 (30 December 2004)
-- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
- avoid implicit memcpy calls (portability for no-library compilation)
-- Increase sprintf() buffer size in gzdopen() to allow for large numbers
-- Add INFLATE_STRICT to check distances against zlib header
-- Improve WinCE errno handling and comments [Chang]
-- Remove comment about no gzip header processing in FAQ
-- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
-- Add updated make_vms.com [Coghlan], update README
-- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
- fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
-- Add FAQ entry and comments in deflate.c on uninitialized memory access
-- Add Solaris 9 make options in configure [Gilbert]
-- Allow strerror() usage in gzio.c for STDC
-- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
-- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
-- Use z_off_t for adler32_combine() and crc32_combine() lengths
-- Make adler32() much faster for small len
-- Use OS_CODE in deflate() default gzip header
+ * adler32.c, compress.c, crc32.c, deflate.c, deflate.h, gzio.c,
+ trees.c, uncompr.c, zconf.h, zconf.in.h, zutil.c, zutil.h: Reformat
+ CVS Ids.
-Changes in 1.2.2.1 (31 October 2004)
-- Allow inflateSetDictionary() call for raw inflate
-- Fix inflate header crc check bug for file names and comments
-- Add deflateSetHeader() and gz_header structure for custom gzip headers
-- Add inflateGetheader() to retrieve gzip headers
-- Add crc32_combine() and adler32_combine() functions
-- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
-- Use zstreamp consistently in zlib.h (inflate_back functions)
-- Remove GUNZIP condition from definition of inflate_mode in inflate.h
- and in contrib/inflate86/inffast.S [Truta, Anderson]
-- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
-- Update projects/README.projects and projects/visualc6 [Truta]
-- Update win32/DLL_FAQ.txt [Truta]
-- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
-- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
-- Use a new algorithm for setting strm->data_type in trees.c [Truta]
-- Do not define an exit() prototype in zutil.c unless DEBUG defined
-- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
-- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
-- Fix Darwin build version identification [Peterson]
+2005-10-28 Ralf Corsepius <ralf.corsepius@rtems.org>
-Changes in 1.2.2 (3 October 2004)
-- Update zlib.h comments on gzip in-memory processing
-- Set adler to 1 in inflateReset() to support Java test suite [Walles]
-- Add contrib/dotzlib [Ravn]
-- Update win32/DLL_FAQ.txt [Truta]
-- Update contrib/minizip [Vollant]
-- Move contrib/visual-basic.txt to old/ [Truta]
-- Fix assembler builds in projects/visualc6/ [Truta]
+ * ChangeLog.zlib: Renamed version of zlib's ChangeLog.
+ * FAQ, INDEX, README, adler32.c, algorithm.txt, compress.c, crc32.c,
+ crc32.h, deflate.c, deflate.h, gzio.c, infback.c, inffast.c,
+ inffast.h, inffixed.h, inflate.c, inflate.h, trees.c, trees.h,
+ uncompr.c, zconf.h, zconf.in.h, zlib.3, zlib.h, zutil.c, zutil.h,
+ inftrees.h, inftrees.c, ChangeLog: Import from zlib-1.2.2.2.tar.gz.
-Changes in 1.2.1.2 (9 September 2004)
-- Update INDEX file
-- Fix trees.c to update strm->data_type (no one ever noticed!)
-- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
-- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
-- Add limited multitasking protection to DYNAMIC_CRC_TABLE
-- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
-- Don't declare strerror() under VMS [Mozilla]
-- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
-- Update contrib/ada [Anisimkov]
-- Update contrib/minizip [Vollant]
-- Fix configure to not hardcode directories for Darwin [Peterson]
-- Fix gzio.c to not return error on empty files [Brown]
-- Fix indentation; update version in contrib/delphi/ZLib.pas and
- contrib/pascal/zlibpas.pas [Truta]
-- Update mkasm.bat in contrib/masmx86 [Truta]
-- Update contrib/untgz [Truta]
-- Add projects/README.projects [Truta]
-- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
-- Update win32/DLL_FAQ.txt [Truta]
-- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
-- Remove an unnecessary assignment to curr in inftrees.c [Truta]
-- Add OS/2 to exe builds in configure [Poltorak]
-- Remove err dummy parameter in zlib.h [Kientzle]
-
-Changes in 1.2.1.1 (9 January 2004)
-- Update email address in README
-- Several FAQ updates
-- Fix a big fat bug in inftrees.c that prevented decoding valid
- dynamic blocks with only literals and no distance codes --
- Thanks to "Hot Emu" for the bug report and sample file
-- Add a note to puff.c on no distance codes case.
-
-Changes in 1.2.1 (17 November 2003)
-- Remove a tab in contrib/gzappend/gzappend.c
-- Update some interfaces in contrib for new zlib functions
-- Update zlib version number in some contrib entries
-- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
-- Support shared libraries on Hurd and KFreeBSD [Brown]
-- Fix error in NO_DIVIDE option of adler32.c
-
-Changes in 1.2.0.8 (4 November 2003)
-- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
-- Add experimental NO_DIVIDE #define in adler32.c
- - Possibly faster on some processors (let me know if it is)
-- Correct Z_BLOCK to not return on first inflate call if no wrap
-- Fix strm->data_type on inflate() return to correctly indicate EOB
-- Add deflatePrime() function for appending in the middle of a byte
-- Add contrib/gzappend for an example of appending to a stream
-- Update win32/DLL_FAQ.txt [Truta]
-- Delete Turbo C comment in README [Truta]
-- Improve some indentation in zconf.h [Truta]
-- Fix infinite loop on bad input in configure script [Church]
-- Fix gzeof() for concatenated gzip files [Johnson]
-- Add example to contrib/visual-basic.txt [Michael B.]
-- Add -p to mkdir's in Makefile.in [vda]
-- Fix configure to properly detect presence or lack of printf functions
-- Add AS400 support [Monnerat]
-- Add a little Cygwin support [Wilson]
-
-Changes in 1.2.0.7 (21 September 2003)
-- Correct some debug formats in contrib/infback9
-- Cast a type in a debug statement in trees.c
-- Change search and replace delimiter in configure from % to # [Beebe]
-- Update contrib/untgz to 0.2 with various fixes [Truta]
-- Add build support for Amiga [Nikl]
-- Remove some directories in old that have been updated to 1.2
-- Add dylib building for Mac OS X in configure and Makefile.in
-- Remove old distribution stuff from Makefile
-- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
-- Update links in README
-
-Changes in 1.2.0.6 (13 September 2003)
-- Minor FAQ updates
-- Update contrib/minizip to 1.00 [Vollant]
-- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
-- Update POSTINC comment for 68060 [Nikl]
-- Add contrib/infback9 with deflate64 decoding (unsupported)
-- For MVS define NO_vsnprintf and undefine FAR [van Burik]
-- Add pragma for fdopen on MVS [van Burik]
-
-Changes in 1.2.0.5 (8 September 2003)
-- Add OF to inflateBackEnd() declaration in zlib.h
-- Remember start when using gzdopen in the middle of a file
-- Use internal off_t counters in gz* functions to properly handle seeks
-- Perform more rigorous check for distance-too-far in inffast.c
-- Add Z_BLOCK flush option to return from inflate at block boundary
-- Set strm->data_type on return from inflate
- - Indicate bits unused, if at block boundary, and if in last block
-- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
-- Add condition so old NO_DEFLATE define still works for compatibility
-- FAQ update regarding the Windows DLL [Truta]
-- INDEX update: add qnx entry, remove aix entry [Truta]
-- Install zlib.3 into mandir [Wilson]
-- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
-- Adapt the zlib interface to the new DLL convention guidelines [Truta]
-- Introduce ZLIB_WINAPI macro to allow the export of functions using
- the WINAPI calling convention, for Visual Basic [Vollant, Truta]
-- Update msdos and win32 scripts and makefiles [Truta]
-- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
-- Add contrib/ada [Anisimkov]
-- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
-- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
-- Add contrib/masm686 [Truta]
-- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
- [Truta, Vollant]
-- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
-- Remove contrib/delphi2; add a new contrib/delphi [Truta]
-- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
- and fix some method prototypes [Truta]
-- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
- [Truta]
-- Avoid the use of backslash (\) in contrib/minizip [Vollant]
-- Fix file time handling in contrib/untgz; update makefiles [Truta]
-- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
- [Vollant]
-- Remove contrib/vstudio/vc15_16 [Vollant]
-- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
-- Update README.contrib [Truta]
-- Invert the assignment order of match_head and s->prev[...] in
- INSERT_STRING [Truta]
-- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
- [Truta]
-- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
-- Fix prototype of syncsearch in inflate.c [Truta]
-- Introduce ASMINF macro to be enabled when using an ASM implementation
- of inflate_fast [Truta]
-- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
-- Modify test_gzio in example.c to take a single file name as a
- parameter [Truta]
-- Exit the example.c program if gzopen fails [Truta]
-- Add type casts around strlen in example.c [Truta]
-- Remove casting to sizeof in minigzip.c; give a proper type
- to the variable compared with SUFFIX_LEN [Truta]
-- Update definitions of STDC and STDC99 in zconf.h [Truta]
-- Synchronize zconf.h with the new Windows DLL interface [Truta]
-- Use SYS16BIT instead of __32BIT__ to distinguish between
- 16- and 32-bit platforms [Truta]
-- Use far memory allocators in small 16-bit memory models for
- Turbo C [Truta]
-- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
- zlibCompileFlags [Truta]
-- Cygwin has vsnprintf [Wilson]
-- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
-- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
-
-Changes in 1.2.0.4 (10 August 2003)
-- Minor FAQ updates
-- Be more strict when checking inflateInit2's windowBits parameter
-- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
-- Add gzip wrapper option to deflateInit2 using windowBits
-- Add updated QNX rule in configure and qnx directory [Bonnefoy]
-- Make inflate distance-too-far checks more rigorous
-- Clean up FAR usage in inflate
-- Add casting to sizeof() in gzio.c and minigzip.c
-
-Changes in 1.2.0.3 (19 July 2003)
-- Fix silly error in gzungetc() implementation [Vollant]
-- Update contrib/minizip and contrib/vstudio [Vollant]
-- Fix printf format in example.c
-- Correct cdecl support in zconf.in.h [Anisimkov]
-- Minor FAQ updates
-
-Changes in 1.2.0.2 (13 July 2003)
-- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
-- Attempt to avoid warnings in crc32.c for pointer-int conversion
-- Add AIX to configure, remove aix directory [Bakker]
-- Add some casts to minigzip.c
-- Improve checking after insecure sprintf() or vsprintf() calls
-- Remove #elif's from crc32.c
-- Change leave label to inf_leave in inflate.c and infback.c to avoid
- library conflicts
-- Remove inflate gzip decoding by default--only enable gzip decoding by
- special request for stricter backward compatibility
-- Add zlibCompileFlags() function to return compilation information
-- More typecasting in deflate.c to avoid warnings
-- Remove leading underscore from _Capital #defines [Truta]
-- Fix configure to link shared library when testing
-- Add some Windows CE target adjustments [Mai]
-- Remove #define ZLIB_DLL in zconf.h [Vollant]
-- Add zlib.3 [Rodgers]
-- Update RFC URL in deflate.c and algorithm.txt [Mai]
-- Add zlib_dll_FAQ.txt to contrib [Truta]
-- Add UL to some constants [Truta]
-- Update minizip and vstudio [Vollant]
-- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
-- Expand use of NO_DUMMY_DECL to avoid all dummy structures
-- Added iostream3 to contrib [Schwardt]
-- Replace rewind() with fseek() for WinCE [Truta]
-- Improve setting of zlib format compression level flags
- - Report 0 for huffman and rle strategies and for level == 0 or 1
- - Report 2 only for level == 6
-- Only deal with 64K limit when necessary at compile time [Truta]
-- Allow TOO_FAR check to be turned off at compile time [Truta]
-- Add gzclearerr() function [Souza]
-- Add gzungetc() function
-
-Changes in 1.2.0.1 (17 March 2003)
-- Add Z_RLE strategy for run-length encoding [Truta]
- - When Z_RLE requested, restrict matches to distance one
- - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
-- Correct FASTEST compilation to allow level == 0
-- Clean up what gets compiled for FASTEST
-- Incorporate changes to zconf.in.h [Vollant]
- - Refine detection of Turbo C need for dummy returns
- - Refine ZLIB_DLL compilation
- - Include additional header file on VMS for off_t typedef
-- Try to use _vsnprintf where it supplants vsprintf [Vollant]
-- Add some casts in inffast.c
-- Enchance comments in zlib.h on what happens if gzprintf() tries to
- write more than 4095 bytes before compression
-- Remove unused state from inflateBackEnd()
-- Remove exit(0) from minigzip.c, example.c
-- Get rid of all those darn tabs
-- Add "check" target to Makefile.in that does the same thing as "test"
-- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
-- Update contrib/inflate86 [Anderson]
-- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
-- Add msdos and win32 directories with makefiles [Truta]
-- More additions and improvements to the FAQ
-
-Changes in 1.2.0 (9 March 2003)
-- New and improved inflate code
- - About 20% faster
- - Does not allocate 32K window unless and until needed
- - Automatically detects and decompresses gzip streams
- - Raw inflate no longer needs an extra dummy byte at end
- - Added inflateBack functions using a callback interface--even faster
- than inflate, useful for file utilities (gzip, zip)
- - Added inflateCopy() function to record state for random access on
- externally generated deflate streams (e.g. in gzip files)
- - More readable code (I hope)
-- New and improved crc32()
- - About 50% faster, thanks to suggestions from Rodney Brown
-- Add deflateBound() and compressBound() functions
-- Fix memory leak in deflateInit2()
-- Permit setting dictionary for raw deflate (for parallel deflate)
-- Fix const declaration for gzwrite()
-- Check for some malloc() failures in gzio.c
-- Fix bug in gzopen() on single-byte file 0x1f
-- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
- and next buffer doesn't start with 0x8b
-- Fix uncompress() to return Z_DATA_ERROR on truncated input
-- Free memory at end of example.c
-- Remove MAX #define in trees.c (conflicted with some libraries)
-- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
-- Declare malloc() and free() in gzio.c if STDC not defined
-- Use malloc() instead of calloc() in zutil.c if int big enough
-- Define STDC for AIX
-- Add aix/ with approach for compiling shared library on AIX
-- Add HP-UX support for shared libraries in configure
-- Add OpenUNIX support for shared libraries in configure
-- Use $cc instead of gcc to build shared library
-- Make prefix directory if needed when installing
-- Correct Macintosh avoidance of typedef Byte in zconf.h
-- Correct Turbo C memory allocation when under Linux
-- Use libz.a instead of -lz in Makefile (assure use of compiled library)
-- Update configure to check for snprintf or vsnprintf functions and their
- return value, warn during make if using an insecure function
-- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
- is lost when library is used--resolution is to build new zconf.h
-- Documentation improvements (in zlib.h):
- - Document raw deflate and inflate
- - Update RFCs URL
- - Point out that zlib and gzip formats are different
- - Note that Z_BUF_ERROR is not fatal
- - Document string limit for gzprintf() and possible buffer overflow
- - Note requirement on avail_out when flushing
- - Note permitted values of flush parameter of inflate()
-- Add some FAQs (and even answers) to the FAQ
-- Add contrib/inflate86/ for x86 faster inflate
-- Add contrib/blast/ for PKWare Data Compression Library decompression
-- Add contrib/puff/ simple inflate for deflate format description
-
-Changes in 1.1.4 (11 March 2002)
-- ZFREE was repeated on same allocation on some error conditions.
- This creates a security problem described in
- http://www.zlib.org/advisory-2002-03-11.txt
-- Returned incorrect error (Z_MEM_ERROR) on some invalid data
-- Avoid accesses before window for invalid distances with inflate window
- less than 32K.
-- force windowBits > 8 to avoid a bug in the encoder for a window size
- of 256 bytes. (A complete fix will be available in 1.1.5).
-
-Changes in 1.1.3 (9 July 1998)
-- fix "an inflate input buffer bug that shows up on rare but persistent
- occasions" (Mark)
-- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
-- fix gzseek(..., SEEK_SET) in write mode
-- fix crc check after a gzeek (Frank Faubert)
-- fix miniunzip when the last entry in a zip file is itself a zip file
- (J Lillge)
-- add contrib/asm586 and contrib/asm686 (Brian Raiter)
- See http://www.muppetlabs.com/~breadbox/software/assembly.html
-- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
-- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
-- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
-- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
-- added a FAQ file
-
-- Support gzdopen on Mac with Metrowerks (Jason Linhart)
-- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
-- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
-- avoid some warnings with Borland C (Tom Tanner)
-- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
-- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
-- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
-- use libdir and includedir in Makefile.in (Tim Mooney)
-- support shared libraries on OSF1 V4 (Tim Mooney)
-- remove so_locations in "make clean" (Tim Mooney)
-- fix maketree.c compilation error (Glenn, Mark)
-- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
-- new Makefile.riscos (Rich Walker)
-- initialize static descriptors in trees.c for embedded targets (Nick Smith)
-- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
-- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
-- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
-- fix maketree.c to allow clean compilation of inffixed.h (Mark)
-- fix parameter check in deflateCopy (Gunther Nikl)
-- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
-- Many portability patches by Christian Spieler:
- . zutil.c, zutil.h: added "const" for zmem*
- . Make_vms.com: fixed some typos
- . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
- . msdos/Makefile.msc: remove "default rtl link library" info from obj files
- . msdos/Makefile.*: use model-dependent name for the built zlib library
- . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
- new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
-- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
-- replace __far with _far for better portability (Christian Spieler, Tom Lane)
-- fix test for errno.h in configure (Tim Newsham)
-
-Changes in 1.1.2 (19 March 98)
-- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
- See http://www.winimage.com/zLibDll/unzip.html
-- preinitialize the inflate tables for fixed codes, to make the code
- completely thread safe (Mark)
-- some simplifications and slight speed-up to the inflate code (Mark)
-- fix gzeof on non-compressed files (Allan Schrum)
-- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
-- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
-- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
-- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
-- do not wrap extern "C" around system includes (Tom Lane)
-- mention zlib binding for TCL in README (Andreas Kupries)
-- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
-- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
-- allow "configure --prefix $HOME" (Tim Mooney)
-- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
-- move Makefile.sas to amiga/Makefile.sas
-
-Changes in 1.1.1 (27 Feb 98)
-- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
-- remove block truncation heuristic which had very marginal effect for zlib
- (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
- compression ratio on some files. This also allows inlining _tr_tally for
- matches in deflate_slow.
-- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
-
-Changes in 1.1.0 (24 Feb 98)
-- do not return STREAM_END prematurely in inflate (John Bowler)
-- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
-- compile with -DFASTEST to get compression code optimized for speed only
-- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
-- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
- on Sun but significant on HP)
-
-- add a pointer to experimental unzip library in README (Gilles Vollant)
-- initialize variable gcc in configure (Chris Herborth)
-
-Changes in 1.0.9 (17 Feb 1998)
-- added gzputs and gzgets functions
-- do not clear eof flag in gzseek (Mark Diekhans)
-- fix gzseek for files in transparent mode (Mark Diekhans)
-- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
-- replace EXPORT with ZEXPORT to avoid conflict with other programs
-- added compress2 in zconf.h, zlib.def, zlib.dnt
-- new asm code from Gilles Vollant in contrib/asm386
-- simplify the inflate code (Mark):
- . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
- . ZALLOC the length list in inflate_trees_fixed() instead of using stack
- . ZALLOC the value area for huft_build() instead of using stack
- . Simplify Z_FINISH check in inflate()
-
-- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
-- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
-- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
- the declaration of FAR (Gilles VOllant)
-- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
-- read_buf buf parameter of type Bytef* instead of charf*
-- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
-- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
-- fix check for presence of directories in "make install" (Ian Willis)
-
-Changes in 1.0.8 (27 Jan 1998)
-- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
-- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
-- added compress2() to allow setting the compression level
-- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
-- use constant arrays for the static trees in trees.c instead of computing
- them at run time (thanks to Ken Raeburn for this suggestion). To create
- trees.h, compile with GEN_TREES_H and run "make test".
-- check return code of example in "make test" and display result
-- pass minigzip command line options to file_compress
-- simplifying code of inflateSync to avoid gcc 2.8 bug
-
-- support CC="gcc -Wall" in configure -s (QingLong)
-- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
-- fix test for shared library support to avoid compiler warnings
-- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
-- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
-- do not use fdopen for Metrowerks on Mac (Brad Pettit))
-- add checks for gzputc and gzputc in example.c
-- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
-- use const for the CRC table (Ken Raeburn)
-- fixed "make uninstall" for shared libraries
-- use Tracev instead of Trace in infblock.c
-- in example.c use correct compressed length for test_sync
-- suppress +vnocompatwarnings in configure for HPUX (not always supported)
-
-Changes in 1.0.7 (20 Jan 1998)
-- fix gzseek which was broken in write mode
-- return error for gzseek to negative absolute position
-- fix configure for Linux (Chun-Chung Chen)
-- increase stack space for MSC (Tim Wegner)
-- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
-- define EXPORTVA for gzprintf (Gilles Vollant)
-- added man page zlib.3 (Rick Rodgers)
-- for contrib/untgz, fix makedir() and improve Makefile
-
-- check gzseek in write mode in example.c
-- allocate extra buffer for seeks only if gzseek is actually called
-- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
-- add inflateSyncPoint in zconf.h
-- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
-
-Changes in 1.0.6 (19 Jan 1998)
-- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
- gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
-- Fix a deflate bug occurring only with compression level 0 (thanks to
- Andy Buckler for finding this one).
-- In minigzip, pass transparently also the first byte for .Z files.
-- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
-- check Z_FINISH in inflate (thanks to Marc Schluper)
-- Implement deflateCopy (thanks to Adam Costello)
-- make static libraries by default in configure, add --shared option.
-- move MSDOS or Windows specific files to directory msdos
-- suppress the notion of partial flush to simplify the interface
- (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
-- suppress history buffer provided by application to simplify the interface
- (this feature was not implemented anyway in 1.0.4)
-- next_in and avail_in must be initialized before calling inflateInit or
- inflateInit2
-- add EXPORT in all exported functions (for Windows DLL)
-- added Makefile.nt (thanks to Stephen Williams)
-- added the unsupported "contrib" directory:
- contrib/asm386/ by Gilles Vollant <info@winimage.com>
- 386 asm code replacing longest_match().
- contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
- A C++ I/O streams interface to the zlib gz* functions
- contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
- Another C++ I/O streams interface
- contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
- A very simple tar.gz file extractor using zlib
- contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
- How to use compress(), uncompress() and the gz* functions from VB.
-- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
- level) in minigzip (thanks to Tom Lane)
-
-- use const for rommable constants in deflate
-- added test for gzseek and gztell in example.c
-- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
-- add undocumented function zError to convert error code to string
- (for Tim Smithers)
-- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
-- Use default memcpy for Symantec MSDOS compiler.
-- Add EXPORT keyword for check_func (needed for Windows DLL)
-- add current directory to LD_LIBRARY_PATH for "make test"
-- create also a link for libz.so.1
-- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
-- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
-- added -soname for Linux in configure (Chun-Chung Chen,
-- assign numbers to the exported functions in zlib.def (for Windows DLL)
-- add advice in zlib.h for best usage of deflateSetDictionary
-- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
-- allow compilation with ANSI keywords only enabled for TurboC in large model
-- avoid "versionString"[0] (Borland bug)
-- add NEED_DUMMY_RETURN for Borland
-- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
-- allow compilation with CC
-- defined STDC for OS/2 (David Charlap)
-- limit external names to 8 chars for MVS (Thomas Lund)
-- in minigzip.c, use static buffers only for 16-bit systems
-- fix suffix check for "minigzip -d foo.gz"
-- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
-- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
-- added makelcc.bat for lcc-win32 (Tom St Denis)
-- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
-- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
-- check for unistd.h in configure (for off_t)
-- remove useless check parameter in inflate_blocks_free
-- avoid useless assignment of s->check to itself in inflate_blocks_new
-- do not flush twice in gzclose (thanks to Ken Raeburn)
-- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
-- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
-- work around buggy fclose on pipes for HP/UX
-- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
-- fix configure if CC is already equal to gcc
-
-Changes in 1.0.5 (3 Jan 98)
-- Fix inflate to terminate gracefully when fed corrupted or invalid data
-- Use const for rommable constants in inflate
-- Eliminate memory leaks on error conditions in inflate
-- Removed some vestigial code in inflate
-- Update web address in README
-
-Changes in 1.0.4 (24 Jul 96)
-- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
- bit, so the decompressor could decompress all the correct data but went
- on to attempt decompressing extra garbage data. This affected minigzip too.
-- zlibVersion and gzerror return const char* (needed for DLL)
-- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
-- use z_error only for DEBUG (avoid problem with DLLs)
-
-Changes in 1.0.3 (2 Jul 96)
-- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
- small and medium models; this makes the library incompatible with previous
- versions for these models. (No effect in large model or on other systems.)
-- return OK instead of BUF_ERROR if previous deflate call returned with
- avail_out as zero but there is nothing to do
-- added memcmp for non STDC compilers
-- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
-- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
-- better check for 16-bit mode MSC (avoids problem with Symantec)
-
-Changes in 1.0.2 (23 May 96)
-- added Windows DLL support
-- added a function zlibVersion (for the DLL support)
-- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
-- Bytef is define's instead of typedef'd only for Borland C
-- avoid reading uninitialized memory in example.c
-- mention in README that the zlib format is now RFC1950
-- updated Makefile.dj2
-- added algorithm.doc
-
-Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
-- fix array overlay in deflate.c which sometimes caused bad compressed data
-- fix inflate bug with empty stored block
-- fix MSDOS medium model which was broken in 0.99
-- fix deflateParams() which could generated bad compressed data.
-- Bytef is define'd instead of typedef'ed (work around Borland bug)
-- added an INDEX file
-- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
- Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
-- speed up adler32 for modern machines without auto-increment
-- added -ansi for IRIX in configure
-- static_init_done in trees.c is an int
-- define unlink as delete for VMS
-- fix configure for QNX
-- add configure branch for SCO and HPUX
-- avoid many warnings (unused variables, dead assignments, etc...)
-- no fdopen for BeOS
-- fix the Watcom fix for 32 bit mode (define FAR as empty)
-- removed redefinition of Byte for MKWERKS
-- work around an MWKERKS bug (incorrect merge of all .h files)
-
-Changes in 0.99 (27 Jan 96)
-- allow preset dictionary shared between compressor and decompressor
-- allow compression level 0 (no compression)
-- add deflateParams in zlib.h: allow dynamic change of compression level
- and compression strategy.
-- test large buffers and deflateParams in example.c
-- add optional "configure" to build zlib as a shared library
-- suppress Makefile.qnx, use configure instead
-- fixed deflate for 64-bit systems (detected on Cray)
-- fixed inflate_blocks for 64-bit systems (detected on Alpha)
-- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
-- always return Z_BUF_ERROR when deflate() has nothing to do
-- deflateInit and inflateInit are now macros to allow version checking
-- prefix all global functions and types with z_ with -DZ_PREFIX
-- make falloc completely reentrant (inftrees.c)
-- fixed very unlikely race condition in ct_static_init
-- free in reverse order of allocation to help memory manager
-- use zlib-1.0/* instead of zlib/* inside the tar.gz
-- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
- -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
-- allow gzread on concatenated .gz files
-- deflateEnd now returns Z_DATA_ERROR if it was premature
-- deflate is finally (?) fully deterministic (no matches beyond end of input)
-- Document Z_SYNC_FLUSH
-- add uninstall in Makefile
-- Check for __cpluplus in zlib.h
-- Better test in ct_align for partial flush
-- avoid harmless warnings for Borland C++
-- initialize hash_head in deflate.c
-- avoid warning on fdopen (gzio.c) for HP cc -Aa
-- include stdlib.h for STDC compilers
-- include errno.h for Cray
-- ignore error if ranlib doesn't exist
-- call ranlib twice for NeXTSTEP
-- use exec_prefix instead of prefix for libz.a
-- renamed ct_* as _tr_* to avoid conflict with applications
-- clear z->msg in inflateInit2 before any error return
-- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
-- fixed typo in zconf.h (_GNUC__ => __GNUC__)
-- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
-- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
-- in fcalloc, normalize pointer if size > 65520 bytes
-- don't use special fcalloc for 32 bit Borland C++
-- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
-- use Z_BINARY instead of BINARY
-- document that gzclose after gzdopen will close the file
-- allow "a" as mode in gzopen.
-- fix error checking in gzread
-- allow skipping .gz extra-field on pipes
-- added reference to Perl interface in README
-- put the crc table in FAR data (I dislike more and more the medium model :)
-- added get_crc_table
-- added a dimension to all arrays (Borland C can't count).
-- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
-- guard against multiple inclusion of *.h (for precompiled header on Mac)
-- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
-- don't use unsized arrays to avoid silly warnings by Visual C++:
- warning C4746: 'inflate_mask' : unsized array treated as '__far'
- (what's wrong with far data in far model?).
-- define enum out of inflate_blocks_state to allow compilation with C++
-
-Changes in 0.95 (16 Aug 95)
-- fix MSDOS small and medium model (now easier to adapt to any compiler)
-- inlined send_bits
-- fix the final (:-) bug for deflate with flush (output was correct but
- not completely flushed in rare occasions).
-- default window size is same for compression and decompression
- (it's now sufficient to set MAX_WBITS in zconf.h).
-- voidp -> voidpf and voidnp -> voidp (for consistency with other
- typedefs and because voidnp was not near in large model).
-
-Changes in 0.94 (13 Aug 95)
-- support MSDOS medium model
-- fix deflate with flush (could sometimes generate bad output)
-- fix deflateReset (zlib header was incorrectly suppressed)
-- added support for VMS
-- allow a compression level in gzopen()
-- gzflush now calls fflush
-- For deflate with flush, flush even if no more input is provided.
-- rename libgz.a as libz.a
-- avoid complex expression in infcodes.c triggering Turbo C bug
-- work around a problem with gcc on Alpha (in INSERT_STRING)
-- don't use inline functions (problem with some gcc versions)
-- allow renaming of Byte, uInt, etc... with #define.
-- avoid warning about (unused) pointer before start of array in deflate.c
-- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
-- avoid reserved word 'new' in trees.c
-
-Changes in 0.93 (25 June 95)
-- temporarily disable inline functions
-- make deflate deterministic
-- give enough lookahead for PARTIAL_FLUSH
-- Set binary mode for stdin/stdout in minigzip.c for OS/2
-- don't even use signed char in inflate (not portable enough)
-- fix inflate memory leak for segmented architectures
-
-Changes in 0.92 (3 May 95)
-- don't assume that char is signed (problem on SGI)
-- Clear bit buffer when starting a stored block
-- no memcpy on Pyramid
-- suppressed inftest.c
-- optimized fill_window, put longest_match inline for gcc
-- optimized inflate on stored blocks.
-- untabify all sources to simplify patches
-
-Changes in 0.91 (2 May 95)
-- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
-- Document the memory requirements in zconf.h
-- added "make install"
-- fix sync search logic in inflateSync
-- deflate(Z_FULL_FLUSH) now works even if output buffer too short
-- after inflateSync, don't scare people with just "lo world"
-- added support for DJGPP
-
-Changes in 0.9 (1 May 95)
-- don't assume that zalloc clears the allocated memory (the TurboC bug
- was Mark's bug after all :)
-- let again gzread copy uncompressed data unchanged (was working in 0.71)
-- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
-- added a test of inflateSync in example.c
-- moved MAX_WBITS to zconf.h because users might want to change that.
-- document explicitly that zalloc(64K) on MSDOS must return a normalized
- pointer (zero offset)
-- added Makefiles for Microsoft C, Turbo C, Borland C++
-- faster crc32()
-
-Changes in 0.8 (29 April 95)
-- added fast inflate (inffast.c)
-- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
- is incompatible with previous versions of zlib which returned Z_OK.
-- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
- (actually that was not a compiler bug, see 0.81 above)
-- gzread no longer reads one extra byte in certain cases
-- In gzio destroy(), don't reference a freed structure
-- avoid many warnings for MSDOS
-- avoid the ERROR symbol which is used by MS Windows
-
-Changes in 0.71 (14 April 95)
-- Fixed more MSDOS compilation problems :( There is still a bug with
- TurboC large model.
-
-Changes in 0.7 (14 April 95)
-- Added full inflate support.
-- Simplified the crc32() interface. The pre- and post-conditioning
- (one's complement) is now done inside crc32(). WARNING: this is
- incompatible with previous versions; see zlib.h for the new usage.
-
-Changes in 0.61 (12 April 95)
-- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
-
-Changes in 0.6 (11 April 95)
-- added minigzip.c
-- added gzdopen to reopen a file descriptor as gzFile
-- added transparent reading of non-gziped files in gzread.
-- fixed bug in gzread (don't read crc as data)
-- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
-- don't allocate big arrays in the stack (for MSDOS)
-- fix some MSDOS compilation problems
-
-Changes in 0.5:
-- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
- not yet Z_FULL_FLUSH.
-- support decompression but only in a single step (forced Z_FINISH)
-- added opaque object for zalloc and zfree.
-- added deflateReset and inflateReset
-- added a variable zlib_version for consistency checking.
-- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
- Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
-
-Changes in 0.4:
-- avoid "zip" everywhere, use zlib instead of ziplib.
-- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
- if compression method == 8.
-- added adler32 and crc32
-- renamed deflateOptions as deflateInit2, call one or the other but not both
-- added the method parameter for deflateInit2.
-- added inflateInit2
-- simplied considerably deflateInit and inflateInit by not supporting
- user-provided history buffer. This is supported only in deflateInit2
- and inflateInit2.
-
-Changes in 0.3:
-- prefix all macro names with Z_
-- use Z_FINISH instead of deflateEnd to finish compression.
-- added Z_HUFFMAN_ONLY
-- added gzerror()
diff --git a/cpukit/zlib/ChangeLog.zlib b/cpukit/zlib/ChangeLog.zlib
new file mode 100644
index 0000000000..6d046ee44b
--- /dev/null
+++ b/cpukit/zlib/ChangeLog.zlib
@@ -0,0 +1,1130 @@
+
+ ChangeLog file for zlib
+
+Changes in 1.2.4 (14 Mar 2010)
+- Fix VER3 extraction in configure for no fourth subversion
+- Update zlib.3, add docs to Makefile.in to make .pdf out of it
+- Add zlib.3.pdf to distribution
+- Don't set error code in gzerror() if passed pointer is NULL
+- Apply destination directory fixes to CMakeLists.txt [Lowman]
+- Move #cmakedefine's to a new zconf.in.cmakein
+- Restore zconf.h for builds that don't use configure or cmake
+- Add distclean to dummy Makefile for convenience
+- Update and improve INDEX, README, and FAQ
+- Update CMakeLists.txt for the return of zconf.h [Lowman]
+- Update contrib/vstudio/vc9 and vc10 [Vollant]
+- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc
+- Apply license and readme changes to contrib/asm686 [Raiter]
+- Check file name lengths and add -c option in minigzip.c [Li]
+- Update contrib/amd64 and contrib/masmx86/ [Vollant]
+- Avoid use of "eof" parameter in trees.c to not shadow library variable
+- Update make_vms.com for removal of zlibdefs.h [Zinser]
+- Update assembler code and vstudio projects in contrib [Vollant]
+- Remove outdated assembler code contrib/masm686 and contrib/asm586
+- Remove old vc7 and vc8 from contrib/vstudio
+- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe]
+- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open()
+- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant]
+- Remove *64 functions from win32/zlib.def (they're not 64-bit yet)
+- Fix bug in void-returning vsprintf() case in gzwrite.c
+- Fix name change from inflate.h in contrib/inflate86/inffas86.c
+- Check if temporary file exists before removing in make_vms.com [Zinser]
+- Fix make install and uninstall for --static option
+- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta]
+- Update readme.txt in contrib/masmx64 and masmx86 to assemble
+
+Changes in 1.2.3.9 (21 Feb 2010)
+- Expunge gzio.c
+- Move as400 build information to old
+- Fix updates in contrib/minizip and contrib/vstudio
+- Add const to vsnprintf test in configure to avoid warnings [Weigelt]
+- Delete zconf.h (made by configure) [Weigelt]
+- Change zconf.in.h to zconf.h.in per convention [Weigelt]
+- Check for NULL buf in gzgets()
+- Return empty string for gzgets() with len == 1 (like fgets())
+- Fix description of gzgets() in zlib.h for end-of-file, NULL return
+- Update minizip to 1.1 [Vollant]
+- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c
+- Note in zlib.h that gzerror() should be used to distinguish from EOF
+- Remove use of snprintf() from gzlib.c
+- Fix bug in gzseek()
+- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant]
+- Fix zconf.h generation in CMakeLists.txt [Lowman]
+- Improve comments in zconf.h where modified by configure
+
+Changes in 1.2.3.8 (13 Feb 2010)
+- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer]
+- Use z_off64_t in gz_zero() and gz_skip() to match state->skip
+- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t)
+- Revert to Makefile.in from 1.2.3.6 (live with the clutter)
+- Fix missing error return in gzflush(), add zlib.h note
+- Add *64 functions to zlib.map [Levin]
+- Fix signed/unsigned comparison in gz_comp()
+- Use SFLAGS when testing shared linking in configure
+- Add --64 option to ./configure to use -m64 with gcc
+- Fix ./configure --help to correctly name options
+- Have make fail if a test fails [Levin]
+- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson]
+- Remove assembler object files from contrib
+
+Changes in 1.2.3.7 (24 Jan 2010)
+- Always gzopen() with O_LARGEFILE if available
+- Fix gzdirect() to work immediately after gzopen() or gzdopen()
+- Make gzdirect() more precise when the state changes while reading
+- Improve zlib.h documentation in many places
+- Catch memory allocation failure in gz_open()
+- Complete close operation if seek forward in gzclose_w() fails
+- Return Z_ERRNO from gzclose_r() if close() fails
+- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL
+- Return zero for gzwrite() errors to match zlib.h description
+- Return -1 on gzputs() error to match zlib.h description
+- Add zconf.in.h to allow recovery from configure modification [Weigelt]
+- Fix static library permissions in Makefile.in [Weigelt]
+- Avoid warnings in configure tests that hide functionality [Weigelt]
+- Add *BSD and DragonFly to Linux case in configure [gentoo 123571]
+- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212]
+- Avoid access of uninitialized data for first inflateReset2 call [Gomes]
+- Keep object files in subdirectories to reduce the clutter somewhat
+- Remove default Makefile and zlibdefs.h, add dummy Makefile
+- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_
+- Remove zlibdefs.h completely -- modify zconf.h instead
+
+Changes in 1.2.3.6 (17 Jan 2010)
+- Avoid void * arithmetic in gzread.c and gzwrite.c
+- Make compilers happier with const char * for gz_error message
+- Avoid unused parameter warning in inflate.c
+- Avoid signed-unsigned comparison warning in inflate.c
+- Indent #pragma's for traditional C
+- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
+- Correct email address in configure for system options
+- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
+- Update zlib.map [Brown]
+- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Tšršk]
+- Apply various fixes to CMakeLists.txt [Lowman]
+- Add checks on len in gzread() and gzwrite()
+- Add error message for no more room for gzungetc()
+- Remove zlib version check in gzwrite()
+- Defer compression of gzprintf() result until need to
+- Use snprintf() in gzdopen() if available
+- Remove USE_MMAP configuration determination (only used by minigzip)
+- Remove examples/pigz.c (available separately)
+- Update examples/gun.c to 1.6
+
+Changes in 1.2.3.5 (8 Jan 2010)
+- Add space after #if in zutil.h for some compilers
+- Fix relatively harmless bug in deflate_fast() [Exarevsky]
+- Fix same problem in deflate_slow()
+- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown]
+- Add deflate_rle() for faster Z_RLE strategy run-length encoding
+- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding
+- Change name of "write" variable in inffast.c to avoid library collisions
+- Fix premature EOF from gzread() in gzio.c [Brown]
+- Use zlib header window size if windowBits is 0 in inflateInit2()
+- Remove compressBound() call in deflate.c to avoid linking compress.o
+- Replace use of errno in gz* with functions, support WinCE [Alves]
+- Provide alternative to perror() in minigzip.c for WinCE [Alves]
+- Don't use _vsnprintf on later versions of MSVC [Lowman]
+- Add CMake build script and input file [Lowman]
+- Update contrib/minizip to 1.1 [Svensson, Vollant]
+- Moved nintendods directory from contrib to .
+- Replace gzio.c with a new set of routines with the same functionality
+- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
+- Update contrib/minizip to 1.1b
+- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
+
+Changes in 1.2.3.4 (21 Dec 2009)
+- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
+- Update comments in configure and Makefile.in for default --shared
+- Fix test -z's in configure [Marquess]
+- Build examplesh and minigzipsh when not testing
+- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h
+- Import LDFLAGS from the environment in configure
+- Fix configure to populate SFLAGS with discovered CFLAGS options
+- Adapt make_vms.com to the new Makefile.in [Zinser]
+- Add zlib2ansi script for C++ compilation [Marquess]
+- Add _FILE_OFFSET_BITS=64 test to make test (when applicable)
+- Add AMD64 assembler code for longest match to contrib [Teterin]
+- Include options from $SFLAGS when doing $LDSHARED
+- Simplify 64-bit file support by introducing z_off64_t type
+- Make shared object files in objs directory to work around old Sun cc
+- Use only three-part version number for Darwin shared compiles
+- Add rc option to ar in Makefile.in for when ./configure not run
+- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4*
+- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile
+- Protect against _FILE_OFFSET_BITS being defined when compiling zlib
+- Rename Makefile.in targets allstatic to static and allshared to shared
+- Fix static and shared Makefile.in targets to be independent
+- Correct error return bug in gz_open() by setting state [Brown]
+- Put spaces before ;;'s in configure for better sh compatibility
+- Add pigz.c (parallel implementation of gzip) to examples/
+- Correct constant in crc32.c to UL [Leventhal]
+- Reject negative lengths in crc32_combine()
+- Add inflateReset2() function to work like inflateEnd()/inflateInit2()
+- Include sys/types.h for _LARGEFILE64_SOURCE [Brown]
+- Correct typo in doc/algorithm.txt [Janik]
+- Fix bug in adler32_combine() [Zhu]
+- Catch missing-end-of-block-code error in all inflates and in puff
+ Assures that random input to inflate eventually results in an error
+- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/
+- Update ENOUGH and its usage to reflect discovered bounds
+- Fix gzerror() error report on empty input file [Brown]
+- Add ush casts in trees.c to avoid pedantic runtime errors
+- Fix typo in zlib.h uncompress() description [Reiss]
+- Correct inflate() comments with regard to automatic header detection
+- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays)
+- Put new version of gzlog (2.0) in examples with interruption recovery
+- Add puff compile option to permit invalid distance-too-far streams
+- Add puff TEST command options, ability to read piped input
+- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but
+ _LARGEFILE64_SOURCE not defined
+- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart
+- Fix deflateSetDictionary() to use all 32K for output consistency
+- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h)
+- Clear bytes after deflate lookahead to avoid use of uninitialized data
+- Change a limit in inftrees.c to be more transparent to Coverity Prevent
+- Update win32/zlib.def with exported symbols from zlib.h
+- Correct spelling error in zlib.h [Willem]
+- Allow Z_BLOCK for deflate() to force a new block
+- Allow negative bits in inflatePrime() to delete existing bit buffer
+- Add Z_TREES flush option to inflate() to return at end of trees
+- Add inflateMark() to return current state information for random access
+- Add Makefile for NintendoDS to contrib [Costa]
+- Add -w in configure compile tests to avoid spurious warnings [Beucler]
+- Fix typos in zlib.h comments for deflateSetDictionary()
+- Fix EOF detection in transparent gzread() [Maier]
+
+Changes in 1.2.3.3 (2 October 2006)
+- Make --shared the default for configure, add a --static option
+- Add compile option to permit invalid distance-too-far streams
+- Add inflateUndermine() function which is required to enable above
+- Remove use of "this" variable name for C++ compatibility [Marquess]
+- Add testing of shared library in make test, if shared library built
+- Use ftello() and fseeko() if available instead of ftell() and fseek()
+- Provide two versions of all functions that use the z_off_t type for
+ binary compatibility -- a normal version and a 64-bit offset version,
+ per the Large File Support Extension when _LARGEFILE64_SOURCE is
+ defined; use the 64-bit versions by default when _FILE_OFFSET_BITS
+ is defined to be 64
+- Add a --uname= option to configure to perhaps help with cross-compiling
+
+Changes in 1.2.3.2 (3 September 2006)
+- Turn off silly Borland warnings [Hay]
+- Use off64_t and define _LARGEFILE64_SOURCE when present
+- Fix missing dependency on inffixed.h in Makefile.in
+- Rig configure --shared to build both shared and static [Teredesai, Truta]
+- Remove zconf.in.h and instead create a new zlibdefs.h file
+- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant]
+- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt]
+
+Changes in 1.2.3.1 (16 August 2006)
+- Add watcom directory with OpenWatcom make files [Daniel]
+- Remove #undef of FAR in zconf.in.h for MVS [Fedtke]
+- Update make_vms.com [Zinser]
+- Use -fPIC for shared build in configure [Teredesai, Nicholson]
+- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen]
+- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck]
+- Add some FAQ entries about the contrib directory
+- Update the MVS question in the FAQ
+- Avoid extraneous reads after EOF in gzio.c [Brown]
+- Correct spelling of "successfully" in gzio.c [Randers-Pehrson]
+- Add comments to zlib.h about gzerror() usage [Brown]
+- Set extra flags in gzip header in gzopen() like deflate() does
+- Make configure options more compatible with double-dash conventions
+ [Weigelt]
+- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen]
+- Fix uninstall target in Makefile.in [Truta]
+- Add pkgconfig support [Weigelt]
+- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt]
+- Replace set_data_type() with a more accurate detect_data_type() in
+ trees.c, according to the txtvsbin.txt document [Truta]
+- Swap the order of #include <stdio.h> and #include "zlib.h" in
+ gzio.c, example.c and minigzip.c [Truta]
+- Shut up annoying VS2005 warnings about standard C deprecation [Rowe,
+ Truta] (where?)
+- Fix target "clean" from win32/Makefile.bor [Truta]
+- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe]
+- Update zlib www home address in win32/DLL_FAQ.txt [Truta]
+- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove]
+- Enable browse info in the "Debug" and "ASM Debug" configurations in
+ the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta]
+- Add pkgconfig support [Weigelt]
+- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h,
+ for use in win32/zlib1.rc [Polushin, Rowe, Truta]
+- Add a document that explains the new text detection scheme to
+ doc/txtvsbin.txt [Truta]
+- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta]
+- Move algorithm.txt into doc/ [Truta]
+- Synchronize FAQ with website
+- Fix compressBound(), was low for some pathological cases [Fearnley]
+- Take into account wrapper variations in deflateBound()
+- Set examples/zpipe.c input and output to binary mode for Windows
+- Update examples/zlib_how.html with new zpipe.c (also web site)
+- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems
+ that gcc became pickier in 4.0)
+- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain
+ un-versioned, the patch adds versioning only for symbols introduced in
+ zlib-1.2.0 or later. It also declares as local those symbols which are
+ not designed to be exported." [Levin]
+- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure
+- Do not initialize global static by default in trees.c, add a response
+ NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess]
+- Don't use strerror() in gzio.c under WinCE [Yakimov]
+- Don't use errno.h in zutil.h under WinCE [Yakimov]
+- Move arguments for AR to its usage to allow replacing ar [Marot]
+- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson]
+- Improve inflateInit() and inflateInit2() documentation
+- Fix structure size comment in inflate.h
+- Change configure help option from --h* to --help [Santos]
+
+Changes in 1.2.3 (18 July 2005)
+- Apply security vulnerability fixes to contrib/infback9 as well
+- Clean up some text files (carriage returns, trailing space)
+- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
+
+Changes in 1.2.2.4 (11 July 2005)
+- Add inflatePrime() function for starting inflation at bit boundary
+- Avoid some Visual C warnings in deflate.c
+- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
+ compile
+- Fix some spelling errors in comments [Betts]
+- Correct inflateInit2() error return documentation in zlib.h
+- Add zran.c example of compressed data random access to examples
+ directory, shows use of inflatePrime()
+- Fix cast for assignments to strm->state in inflate.c and infback.c
+- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
+- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
+- Add cast in trees.c t avoid a warning [Oberhumer]
+- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
+- Update make_vms.com [Zinser]
+- Initialize state->write in inflateReset() since copied in inflate_fast()
+- Be more strict on incomplete code sets in inflate_table() and increase
+ ENOUGH and MAXD -- this repairs a possible security vulnerability for
+ invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
+ discovering the vulnerability and providing test cases.
+- Add ia64 support to configure for HP-UX [Smith]
+- Add error return to gzread() for format or i/o error [Levin]
+- Use malloc.h for OS/2 [Necasek]
+
+Changes in 1.2.2.3 (27 May 2005)
+- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
+- Typecast fread() return values in gzio.c [Vollant]
+- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
+- Fix crc check bug in gzread() after gzungetc() [Heiner]
+- Add the deflateTune() function to adjust internal compression parameters
+- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
+- Remove an incorrect assertion in examples/zpipe.c
+- Add C++ wrapper in infback9.h [Donais]
+- Fix bug in inflateCopy() when decoding fixed codes
+- Note in zlib.h how much deflateSetDictionary() actually uses
+- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
+- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
+- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
+- Add gzdirect() function to indicate transparent reads
+- Update contrib/minizip [Vollant]
+- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
+- Add casts in crc32.c to avoid warnings [Oberhumer]
+- Add contrib/masmx64 [Vollant]
+- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
+
+Changes in 1.2.2.2 (30 December 2004)
+- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
+ avoid implicit memcpy calls (portability for no-library compilation)
+- Increase sprintf() buffer size in gzdopen() to allow for large numbers
+- Add INFLATE_STRICT to check distances against zlib header
+- Improve WinCE errno handling and comments [Chang]
+- Remove comment about no gzip header processing in FAQ
+- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
+- Add updated make_vms.com [Coghlan], update README
+- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
+ fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
+- Add FAQ entry and comments in deflate.c on uninitialized memory access
+- Add Solaris 9 make options in configure [Gilbert]
+- Allow strerror() usage in gzio.c for STDC
+- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
+- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
+- Use z_off_t for adler32_combine() and crc32_combine() lengths
+- Make adler32() much faster for small len
+- Use OS_CODE in deflate() default gzip header
+
+Changes in 1.2.2.1 (31 October 2004)
+- Allow inflateSetDictionary() call for raw inflate
+- Fix inflate header crc check bug for file names and comments
+- Add deflateSetHeader() and gz_header structure for custom gzip headers
+- Add inflateGetheader() to retrieve gzip headers
+- Add crc32_combine() and adler32_combine() functions
+- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
+- Use zstreamp consistently in zlib.h (inflate_back functions)
+- Remove GUNZIP condition from definition of inflate_mode in inflate.h
+ and in contrib/inflate86/inffast.S [Truta, Anderson]
+- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
+- Update projects/README.projects and projects/visualc6 [Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
+- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
+- Use a new algorithm for setting strm->data_type in trees.c [Truta]
+- Do not define an exit() prototype in zutil.c unless DEBUG defined
+- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
+- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
+- Fix Darwin build version identification [Peterson]
+
+Changes in 1.2.2 (3 October 2004)
+- Update zlib.h comments on gzip in-memory processing
+- Set adler to 1 in inflateReset() to support Java test suite [Walles]
+- Add contrib/dotzlib [Ravn]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update contrib/minizip [Vollant]
+- Move contrib/visual-basic.txt to old/ [Truta]
+- Fix assembler builds in projects/visualc6/ [Truta]
+
+Changes in 1.2.1.2 (9 September 2004)
+- Update INDEX file
+- Fix trees.c to update strm->data_type (no one ever noticed!)
+- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
+- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
+- Add limited multitasking protection to DYNAMIC_CRC_TABLE
+- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
+- Don't declare strerror() under VMS [Mozilla]
+- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
+- Update contrib/ada [Anisimkov]
+- Update contrib/minizip [Vollant]
+- Fix configure to not hardcode directories for Darwin [Peterson]
+- Fix gzio.c to not return error on empty files [Brown]
+- Fix indentation; update version in contrib/delphi/ZLib.pas and
+ contrib/pascal/zlibpas.pas [Truta]
+- Update mkasm.bat in contrib/masmx86 [Truta]
+- Update contrib/untgz [Truta]
+- Add projects/README.projects [Truta]
+- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
+- Remove an unnecessary assignment to curr in inftrees.c [Truta]
+- Add OS/2 to exe builds in configure [Poltorak]
+- Remove err dummy parameter in zlib.h [Kientzle]
+
+Changes in 1.2.1.1 (9 January 2004)
+- Update email address in README
+- Several FAQ updates
+- Fix a big fat bug in inftrees.c that prevented decoding valid
+ dynamic blocks with only literals and no distance codes --
+ Thanks to "Hot Emu" for the bug report and sample file
+- Add a note to puff.c on no distance codes case.
+
+Changes in 1.2.1 (17 November 2003)
+- Remove a tab in contrib/gzappend/gzappend.c
+- Update some interfaces in contrib for new zlib functions
+- Update zlib version number in some contrib entries
+- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
+- Support shared libraries on Hurd and KFreeBSD [Brown]
+- Fix error in NO_DIVIDE option of adler32.c
+
+Changes in 1.2.0.8 (4 November 2003)
+- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
+- Add experimental NO_DIVIDE #define in adler32.c
+ - Possibly faster on some processors (let me know if it is)
+- Correct Z_BLOCK to not return on first inflate call if no wrap
+- Fix strm->data_type on inflate() return to correctly indicate EOB
+- Add deflatePrime() function for appending in the middle of a byte
+- Add contrib/gzappend for an example of appending to a stream
+- Update win32/DLL_FAQ.txt [Truta]
+- Delete Turbo C comment in README [Truta]
+- Improve some indentation in zconf.h [Truta]
+- Fix infinite loop on bad input in configure script [Church]
+- Fix gzeof() for concatenated gzip files [Johnson]
+- Add example to contrib/visual-basic.txt [Michael B.]
+- Add -p to mkdir's in Makefile.in [vda]
+- Fix configure to properly detect presence or lack of printf functions
+- Add AS400 support [Monnerat]
+- Add a little Cygwin support [Wilson]
+
+Changes in 1.2.0.7 (21 September 2003)
+- Correct some debug formats in contrib/infback9
+- Cast a type in a debug statement in trees.c
+- Change search and replace delimiter in configure from % to # [Beebe]
+- Update contrib/untgz to 0.2 with various fixes [Truta]
+- Add build support for Amiga [Nikl]
+- Remove some directories in old that have been updated to 1.2
+- Add dylib building for Mac OS X in configure and Makefile.in
+- Remove old distribution stuff from Makefile
+- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
+- Update links in README
+
+Changes in 1.2.0.6 (13 September 2003)
+- Minor FAQ updates
+- Update contrib/minizip to 1.00 [Vollant]
+- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
+- Update POSTINC comment for 68060 [Nikl]
+- Add contrib/infback9 with deflate64 decoding (unsupported)
+- For MVS define NO_vsnprintf and undefine FAR [van Burik]
+- Add pragma for fdopen on MVS [van Burik]
+
+Changes in 1.2.0.5 (8 September 2003)
+- Add OF to inflateBackEnd() declaration in zlib.h
+- Remember start when using gzdopen in the middle of a file
+- Use internal off_t counters in gz* functions to properly handle seeks
+- Perform more rigorous check for distance-too-far in inffast.c
+- Add Z_BLOCK flush option to return from inflate at block boundary
+- Set strm->data_type on return from inflate
+ - Indicate bits unused, if at block boundary, and if in last block
+- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
+- Add condition so old NO_DEFLATE define still works for compatibility
+- FAQ update regarding the Windows DLL [Truta]
+- INDEX update: add qnx entry, remove aix entry [Truta]
+- Install zlib.3 into mandir [Wilson]
+- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
+- Adapt the zlib interface to the new DLL convention guidelines [Truta]
+- Introduce ZLIB_WINAPI macro to allow the export of functions using
+ the WINAPI calling convention, for Visual Basic [Vollant, Truta]
+- Update msdos and win32 scripts and makefiles [Truta]
+- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
+- Add contrib/ada [Anisimkov]
+- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
+- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
+- Add contrib/masm686 [Truta]
+- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
+ [Truta, Vollant]
+- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
+- Remove contrib/delphi2; add a new contrib/delphi [Truta]
+- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
+ and fix some method prototypes [Truta]
+- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
+ [Truta]
+- Avoid the use of backslash (\) in contrib/minizip [Vollant]
+- Fix file time handling in contrib/untgz; update makefiles [Truta]
+- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
+ [Vollant]
+- Remove contrib/vstudio/vc15_16 [Vollant]
+- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
+- Update README.contrib [Truta]
+- Invert the assignment order of match_head and s->prev[...] in
+ INSERT_STRING [Truta]
+- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
+ [Truta]
+- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
+- Fix prototype of syncsearch in inflate.c [Truta]
+- Introduce ASMINF macro to be enabled when using an ASM implementation
+ of inflate_fast [Truta]
+- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
+- Modify test_gzio in example.c to take a single file name as a
+ parameter [Truta]
+- Exit the example.c program if gzopen fails [Truta]
+- Add type casts around strlen in example.c [Truta]
+- Remove casting to sizeof in minigzip.c; give a proper type
+ to the variable compared with SUFFIX_LEN [Truta]
+- Update definitions of STDC and STDC99 in zconf.h [Truta]
+- Synchronize zconf.h with the new Windows DLL interface [Truta]
+- Use SYS16BIT instead of __32BIT__ to distinguish between
+ 16- and 32-bit platforms [Truta]
+- Use far memory allocators in small 16-bit memory models for
+ Turbo C [Truta]
+- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
+ zlibCompileFlags [Truta]
+- Cygwin has vsnprintf [Wilson]
+- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
+- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
+
+Changes in 1.2.0.4 (10 August 2003)
+- Minor FAQ updates
+- Be more strict when checking inflateInit2's windowBits parameter
+- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
+- Add gzip wrapper option to deflateInit2 using windowBits
+- Add updated QNX rule in configure and qnx directory [Bonnefoy]
+- Make inflate distance-too-far checks more rigorous
+- Clean up FAR usage in inflate
+- Add casting to sizeof() in gzio.c and minigzip.c
+
+Changes in 1.2.0.3 (19 July 2003)
+- Fix silly error in gzungetc() implementation [Vollant]
+- Update contrib/minizip and contrib/vstudio [Vollant]
+- Fix printf format in example.c
+- Correct cdecl support in zconf.in.h [Anisimkov]
+- Minor FAQ updates
+
+Changes in 1.2.0.2 (13 July 2003)
+- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
+- Attempt to avoid warnings in crc32.c for pointer-int conversion
+- Add AIX to configure, remove aix directory [Bakker]
+- Add some casts to minigzip.c
+- Improve checking after insecure sprintf() or vsprintf() calls
+- Remove #elif's from crc32.c
+- Change leave label to inf_leave in inflate.c and infback.c to avoid
+ library conflicts
+- Remove inflate gzip decoding by default--only enable gzip decoding by
+ special request for stricter backward compatibility
+- Add zlibCompileFlags() function to return compilation information
+- More typecasting in deflate.c to avoid warnings
+- Remove leading underscore from _Capital #defines [Truta]
+- Fix configure to link shared library when testing
+- Add some Windows CE target adjustments [Mai]
+- Remove #define ZLIB_DLL in zconf.h [Vollant]
+- Add zlib.3 [Rodgers]
+- Update RFC URL in deflate.c and algorithm.txt [Mai]
+- Add zlib_dll_FAQ.txt to contrib [Truta]
+- Add UL to some constants [Truta]
+- Update minizip and vstudio [Vollant]
+- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
+- Expand use of NO_DUMMY_DECL to avoid all dummy structures
+- Added iostream3 to contrib [Schwardt]
+- Replace rewind() with fseek() for WinCE [Truta]
+- Improve setting of zlib format compression level flags
+ - Report 0 for huffman and rle strategies and for level == 0 or 1
+ - Report 2 only for level == 6
+- Only deal with 64K limit when necessary at compile time [Truta]
+- Allow TOO_FAR check to be turned off at compile time [Truta]
+- Add gzclearerr() function [Souza]
+- Add gzungetc() function
+
+Changes in 1.2.0.1 (17 March 2003)
+- Add Z_RLE strategy for run-length encoding [Truta]
+ - When Z_RLE requested, restrict matches to distance one
+ - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
+- Correct FASTEST compilation to allow level == 0
+- Clean up what gets compiled for FASTEST
+- Incorporate changes to zconf.in.h [Vollant]
+ - Refine detection of Turbo C need for dummy returns
+ - Refine ZLIB_DLL compilation
+ - Include additional header file on VMS for off_t typedef
+- Try to use _vsnprintf where it supplants vsprintf [Vollant]
+- Add some casts in inffast.c
+- Enchance comments in zlib.h on what happens if gzprintf() tries to
+ write more than 4095 bytes before compression
+- Remove unused state from inflateBackEnd()
+- Remove exit(0) from minigzip.c, example.c
+- Get rid of all those darn tabs
+- Add "check" target to Makefile.in that does the same thing as "test"
+- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
+- Update contrib/inflate86 [Anderson]
+- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
+- Add msdos and win32 directories with makefiles [Truta]
+- More additions and improvements to the FAQ
+
+Changes in 1.2.0 (9 March 2003)
+- New and improved inflate code
+ - About 20% faster
+ - Does not allocate 32K window unless and until needed
+ - Automatically detects and decompresses gzip streams
+ - Raw inflate no longer needs an extra dummy byte at end
+ - Added inflateBack functions using a callback interface--even faster
+ than inflate, useful for file utilities (gzip, zip)
+ - Added inflateCopy() function to record state for random access on
+ externally generated deflate streams (e.g. in gzip files)
+ - More readable code (I hope)
+- New and improved crc32()
+ - About 50% faster, thanks to suggestions from Rodney Brown
+- Add deflateBound() and compressBound() functions
+- Fix memory leak in deflateInit2()
+- Permit setting dictionary for raw deflate (for parallel deflate)
+- Fix const declaration for gzwrite()
+- Check for some malloc() failures in gzio.c
+- Fix bug in gzopen() on single-byte file 0x1f
+- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
+ and next buffer doesn't start with 0x8b
+- Fix uncompress() to return Z_DATA_ERROR on truncated input
+- Free memory at end of example.c
+- Remove MAX #define in trees.c (conflicted with some libraries)
+- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
+- Declare malloc() and free() in gzio.c if STDC not defined
+- Use malloc() instead of calloc() in zutil.c if int big enough
+- Define STDC for AIX
+- Add aix/ with approach for compiling shared library on AIX
+- Add HP-UX support for shared libraries in configure
+- Add OpenUNIX support for shared libraries in configure
+- Use $cc instead of gcc to build shared library
+- Make prefix directory if needed when installing
+- Correct Macintosh avoidance of typedef Byte in zconf.h
+- Correct Turbo C memory allocation when under Linux
+- Use libz.a instead of -lz in Makefile (assure use of compiled library)
+- Update configure to check for snprintf or vsnprintf functions and their
+ return value, warn during make if using an insecure function
+- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
+ is lost when library is used--resolution is to build new zconf.h
+- Documentation improvements (in zlib.h):
+ - Document raw deflate and inflate
+ - Update RFCs URL
+ - Point out that zlib and gzip formats are different
+ - Note that Z_BUF_ERROR is not fatal
+ - Document string limit for gzprintf() and possible buffer overflow
+ - Note requirement on avail_out when flushing
+ - Note permitted values of flush parameter of inflate()
+- Add some FAQs (and even answers) to the FAQ
+- Add contrib/inflate86/ for x86 faster inflate
+- Add contrib/blast/ for PKWare Data Compression Library decompression
+- Add contrib/puff/ simple inflate for deflate format description
+
+Changes in 1.1.4 (11 March 2002)
+- ZFREE was repeated on same allocation on some error conditions.
+ This creates a security problem described in
+ http://www.zlib.org/advisory-2002-03-11.txt
+- Returned incorrect error (Z_MEM_ERROR) on some invalid data
+- Avoid accesses before window for invalid distances with inflate window
+ less than 32K.
+- force windowBits > 8 to avoid a bug in the encoder for a window size
+ of 256 bytes. (A complete fix will be available in 1.1.5).
+
+Changes in 1.1.3 (9 July 1998)
+- fix "an inflate input buffer bug that shows up on rare but persistent
+ occasions" (Mark)
+- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
+- fix gzseek(..., SEEK_SET) in write mode
+- fix crc check after a gzeek (Frank Faubert)
+- fix miniunzip when the last entry in a zip file is itself a zip file
+ (J Lillge)
+- add contrib/asm586 and contrib/asm686 (Brian Raiter)
+ See http://www.muppetlabs.com/~breadbox/software/assembly.html
+- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
+- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
+- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
+- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
+- added a FAQ file
+
+- Support gzdopen on Mac with Metrowerks (Jason Linhart)
+- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
+- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
+- avoid some warnings with Borland C (Tom Tanner)
+- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
+- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
+- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
+- use libdir and includedir in Makefile.in (Tim Mooney)
+- support shared libraries on OSF1 V4 (Tim Mooney)
+- remove so_locations in "make clean" (Tim Mooney)
+- fix maketree.c compilation error (Glenn, Mark)
+- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
+- new Makefile.riscos (Rich Walker)
+- initialize static descriptors in trees.c for embedded targets (Nick Smith)
+- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
+- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
+- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
+- fix maketree.c to allow clean compilation of inffixed.h (Mark)
+- fix parameter check in deflateCopy (Gunther Nikl)
+- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
+- Many portability patches by Christian Spieler:
+ . zutil.c, zutil.h: added "const" for zmem*
+ . Make_vms.com: fixed some typos
+ . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
+ . msdos/Makefile.msc: remove "default rtl link library" info from obj files
+ . msdos/Makefile.*: use model-dependent name for the built zlib library
+ . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
+ new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
+- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
+- replace __far with _far for better portability (Christian Spieler, Tom Lane)
+- fix test for errno.h in configure (Tim Newsham)
+
+Changes in 1.1.2 (19 March 98)
+- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
+ See http://www.winimage.com/zLibDll/unzip.html
+- preinitialize the inflate tables for fixed codes, to make the code
+ completely thread safe (Mark)
+- some simplifications and slight speed-up to the inflate code (Mark)
+- fix gzeof on non-compressed files (Allan Schrum)
+- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
+- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
+- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
+- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
+- do not wrap extern "C" around system includes (Tom Lane)
+- mention zlib binding for TCL in README (Andreas Kupries)
+- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
+- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
+- allow "configure --prefix $HOME" (Tim Mooney)
+- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
+- move Makefile.sas to amiga/Makefile.sas
+
+Changes in 1.1.1 (27 Feb 98)
+- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
+- remove block truncation heuristic which had very marginal effect for zlib
+ (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
+ compression ratio on some files. This also allows inlining _tr_tally for
+ matches in deflate_slow.
+- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
+
+Changes in 1.1.0 (24 Feb 98)
+- do not return STREAM_END prematurely in inflate (John Bowler)
+- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
+- compile with -DFASTEST to get compression code optimized for speed only
+- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
+- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
+ on Sun but significant on HP)
+
+- add a pointer to experimental unzip library in README (Gilles Vollant)
+- initialize variable gcc in configure (Chris Herborth)
+
+Changes in 1.0.9 (17 Feb 1998)
+- added gzputs and gzgets functions
+- do not clear eof flag in gzseek (Mark Diekhans)
+- fix gzseek for files in transparent mode (Mark Diekhans)
+- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
+- replace EXPORT with ZEXPORT to avoid conflict with other programs
+- added compress2 in zconf.h, zlib.def, zlib.dnt
+- new asm code from Gilles Vollant in contrib/asm386
+- simplify the inflate code (Mark):
+ . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
+ . ZALLOC the length list in inflate_trees_fixed() instead of using stack
+ . ZALLOC the value area for huft_build() instead of using stack
+ . Simplify Z_FINISH check in inflate()
+
+- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
+- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
+- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
+ the declaration of FAR (Gilles VOllant)
+- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
+- read_buf buf parameter of type Bytef* instead of charf*
+- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
+- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
+- fix check for presence of directories in "make install" (Ian Willis)
+
+Changes in 1.0.8 (27 Jan 1998)
+- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
+- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
+- added compress2() to allow setting the compression level
+- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
+- use constant arrays for the static trees in trees.c instead of computing
+ them at run time (thanks to Ken Raeburn for this suggestion). To create
+ trees.h, compile with GEN_TREES_H and run "make test".
+- check return code of example in "make test" and display result
+- pass minigzip command line options to file_compress
+- simplifying code of inflateSync to avoid gcc 2.8 bug
+
+- support CC="gcc -Wall" in configure -s (QingLong)
+- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
+- fix test for shared library support to avoid compiler warnings
+- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
+- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
+- do not use fdopen for Metrowerks on Mac (Brad Pettit))
+- add checks for gzputc and gzputc in example.c
+- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
+- use const for the CRC table (Ken Raeburn)
+- fixed "make uninstall" for shared libraries
+- use Tracev instead of Trace in infblock.c
+- in example.c use correct compressed length for test_sync
+- suppress +vnocompatwarnings in configure for HPUX (not always supported)
+
+Changes in 1.0.7 (20 Jan 1998)
+- fix gzseek which was broken in write mode
+- return error for gzseek to negative absolute position
+- fix configure for Linux (Chun-Chung Chen)
+- increase stack space for MSC (Tim Wegner)
+- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
+- define EXPORTVA for gzprintf (Gilles Vollant)
+- added man page zlib.3 (Rick Rodgers)
+- for contrib/untgz, fix makedir() and improve Makefile
+
+- check gzseek in write mode in example.c
+- allocate extra buffer for seeks only if gzseek is actually called
+- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
+- add inflateSyncPoint in zconf.h
+- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
+
+Changes in 1.0.6 (19 Jan 1998)
+- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
+ gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
+- Fix a deflate bug occurring only with compression level 0 (thanks to
+ Andy Buckler for finding this one).
+- In minigzip, pass transparently also the first byte for .Z files.
+- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
+- check Z_FINISH in inflate (thanks to Marc Schluper)
+- Implement deflateCopy (thanks to Adam Costello)
+- make static libraries by default in configure, add --shared option.
+- move MSDOS or Windows specific files to directory msdos
+- suppress the notion of partial flush to simplify the interface
+ (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
+- suppress history buffer provided by application to simplify the interface
+ (this feature was not implemented anyway in 1.0.4)
+- next_in and avail_in must be initialized before calling inflateInit or
+ inflateInit2
+- add EXPORT in all exported functions (for Windows DLL)
+- added Makefile.nt (thanks to Stephen Williams)
+- added the unsupported "contrib" directory:
+ contrib/asm386/ by Gilles Vollant <info@winimage.com>
+ 386 asm code replacing longest_match().
+ contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
+ A C++ I/O streams interface to the zlib gz* functions
+ contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
+ Another C++ I/O streams interface
+ contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
+ A very simple tar.gz file extractor using zlib
+ contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
+ How to use compress(), uncompress() and the gz* functions from VB.
+- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
+ level) in minigzip (thanks to Tom Lane)
+
+- use const for rommable constants in deflate
+- added test for gzseek and gztell in example.c
+- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
+- add undocumented function zError to convert error code to string
+ (for Tim Smithers)
+- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
+- Use default memcpy for Symantec MSDOS compiler.
+- Add EXPORT keyword for check_func (needed for Windows DLL)
+- add current directory to LD_LIBRARY_PATH for "make test"
+- create also a link for libz.so.1
+- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
+- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
+- added -soname for Linux in configure (Chun-Chung Chen,
+- assign numbers to the exported functions in zlib.def (for Windows DLL)
+- add advice in zlib.h for best usage of deflateSetDictionary
+- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
+- allow compilation with ANSI keywords only enabled for TurboC in large model
+- avoid "versionString"[0] (Borland bug)
+- add NEED_DUMMY_RETURN for Borland
+- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
+- allow compilation with CC
+- defined STDC for OS/2 (David Charlap)
+- limit external names to 8 chars for MVS (Thomas Lund)
+- in minigzip.c, use static buffers only for 16-bit systems
+- fix suffix check for "minigzip -d foo.gz"
+- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
+- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
+- added makelcc.bat for lcc-win32 (Tom St Denis)
+- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
+- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
+- check for unistd.h in configure (for off_t)
+- remove useless check parameter in inflate_blocks_free
+- avoid useless assignment of s->check to itself in inflate_blocks_new
+- do not flush twice in gzclose (thanks to Ken Raeburn)
+- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
+- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
+- work around buggy fclose on pipes for HP/UX
+- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
+- fix configure if CC is already equal to gcc
+
+Changes in 1.0.5 (3 Jan 98)
+- Fix inflate to terminate gracefully when fed corrupted or invalid data
+- Use const for rommable constants in inflate
+- Eliminate memory leaks on error conditions in inflate
+- Removed some vestigial code in inflate
+- Update web address in README
+
+Changes in 1.0.4 (24 Jul 96)
+- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
+ bit, so the decompressor could decompress all the correct data but went
+ on to attempt decompressing extra garbage data. This affected minigzip too.
+- zlibVersion and gzerror return const char* (needed for DLL)
+- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
+- use z_error only for DEBUG (avoid problem with DLLs)
+
+Changes in 1.0.3 (2 Jul 96)
+- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
+ small and medium models; this makes the library incompatible with previous
+ versions for these models. (No effect in large model or on other systems.)
+- return OK instead of BUF_ERROR if previous deflate call returned with
+ avail_out as zero but there is nothing to do
+- added memcmp for non STDC compilers
+- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
+- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
+- better check for 16-bit mode MSC (avoids problem with Symantec)
+
+Changes in 1.0.2 (23 May 96)
+- added Windows DLL support
+- added a function zlibVersion (for the DLL support)
+- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
+- Bytef is define's instead of typedef'd only for Borland C
+- avoid reading uninitialized memory in example.c
+- mention in README that the zlib format is now RFC1950
+- updated Makefile.dj2
+- added algorithm.doc
+
+Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
+- fix array overlay in deflate.c which sometimes caused bad compressed data
+- fix inflate bug with empty stored block
+- fix MSDOS medium model which was broken in 0.99
+- fix deflateParams() which could generated bad compressed data.
+- Bytef is define'd instead of typedef'ed (work around Borland bug)
+- added an INDEX file
+- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
+ Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
+- speed up adler32 for modern machines without auto-increment
+- added -ansi for IRIX in configure
+- static_init_done in trees.c is an int
+- define unlink as delete for VMS
+- fix configure for QNX
+- add configure branch for SCO and HPUX
+- avoid many warnings (unused variables, dead assignments, etc...)
+- no fdopen for BeOS
+- fix the Watcom fix for 32 bit mode (define FAR as empty)
+- removed redefinition of Byte for MKWERKS
+- work around an MWKERKS bug (incorrect merge of all .h files)
+
+Changes in 0.99 (27 Jan 96)
+- allow preset dictionary shared between compressor and decompressor
+- allow compression level 0 (no compression)
+- add deflateParams in zlib.h: allow dynamic change of compression level
+ and compression strategy.
+- test large buffers and deflateParams in example.c
+- add optional "configure" to build zlib as a shared library
+- suppress Makefile.qnx, use configure instead
+- fixed deflate for 64-bit systems (detected on Cray)
+- fixed inflate_blocks for 64-bit systems (detected on Alpha)
+- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
+- always return Z_BUF_ERROR when deflate() has nothing to do
+- deflateInit and inflateInit are now macros to allow version checking
+- prefix all global functions and types with z_ with -DZ_PREFIX
+- make falloc completely reentrant (inftrees.c)
+- fixed very unlikely race condition in ct_static_init
+- free in reverse order of allocation to help memory manager
+- use zlib-1.0/* instead of zlib/* inside the tar.gz
+- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
+ -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
+- allow gzread on concatenated .gz files
+- deflateEnd now returns Z_DATA_ERROR if it was premature
+- deflate is finally (?) fully deterministic (no matches beyond end of input)
+- Document Z_SYNC_FLUSH
+- add uninstall in Makefile
+- Check for __cpluplus in zlib.h
+- Better test in ct_align for partial flush
+- avoid harmless warnings for Borland C++
+- initialize hash_head in deflate.c
+- avoid warning on fdopen (gzio.c) for HP cc -Aa
+- include stdlib.h for STDC compilers
+- include errno.h for Cray
+- ignore error if ranlib doesn't exist
+- call ranlib twice for NeXTSTEP
+- use exec_prefix instead of prefix for libz.a
+- renamed ct_* as _tr_* to avoid conflict with applications
+- clear z->msg in inflateInit2 before any error return
+- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
+- fixed typo in zconf.h (_GNUC__ => __GNUC__)
+- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
+- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
+- in fcalloc, normalize pointer if size > 65520 bytes
+- don't use special fcalloc for 32 bit Borland C++
+- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
+- use Z_BINARY instead of BINARY
+- document that gzclose after gzdopen will close the file
+- allow "a" as mode in gzopen.
+- fix error checking in gzread
+- allow skipping .gz extra-field on pipes
+- added reference to Perl interface in README
+- put the crc table in FAR data (I dislike more and more the medium model :)
+- added get_crc_table
+- added a dimension to all arrays (Borland C can't count).
+- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
+- guard against multiple inclusion of *.h (for precompiled header on Mac)
+- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
+- don't use unsized arrays to avoid silly warnings by Visual C++:
+ warning C4746: 'inflate_mask' : unsized array treated as '__far'
+ (what's wrong with far data in far model?).
+- define enum out of inflate_blocks_state to allow compilation with C++
+
+Changes in 0.95 (16 Aug 95)
+- fix MSDOS small and medium model (now easier to adapt to any compiler)
+- inlined send_bits
+- fix the final (:-) bug for deflate with flush (output was correct but
+ not completely flushed in rare occasions).
+- default window size is same for compression and decompression
+ (it's now sufficient to set MAX_WBITS in zconf.h).
+- voidp -> voidpf and voidnp -> voidp (for consistency with other
+ typedefs and because voidnp was not near in large model).
+
+Changes in 0.94 (13 Aug 95)
+- support MSDOS medium model
+- fix deflate with flush (could sometimes generate bad output)
+- fix deflateReset (zlib header was incorrectly suppressed)
+- added support for VMS
+- allow a compression level in gzopen()
+- gzflush now calls fflush
+- For deflate with flush, flush even if no more input is provided.
+- rename libgz.a as libz.a
+- avoid complex expression in infcodes.c triggering Turbo C bug
+- work around a problem with gcc on Alpha (in INSERT_STRING)
+- don't use inline functions (problem with some gcc versions)
+- allow renaming of Byte, uInt, etc... with #define.
+- avoid warning about (unused) pointer before start of array in deflate.c
+- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
+- avoid reserved word 'new' in trees.c
+
+Changes in 0.93 (25 June 95)
+- temporarily disable inline functions
+- make deflate deterministic
+- give enough lookahead for PARTIAL_FLUSH
+- Set binary mode for stdin/stdout in minigzip.c for OS/2
+- don't even use signed char in inflate (not portable enough)
+- fix inflate memory leak for segmented architectures
+
+Changes in 0.92 (3 May 95)
+- don't assume that char is signed (problem on SGI)
+- Clear bit buffer when starting a stored block
+- no memcpy on Pyramid
+- suppressed inftest.c
+- optimized fill_window, put longest_match inline for gcc
+- optimized inflate on stored blocks.
+- untabify all sources to simplify patches
+
+Changes in 0.91 (2 May 95)
+- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
+- Document the memory requirements in zconf.h
+- added "make install"
+- fix sync search logic in inflateSync
+- deflate(Z_FULL_FLUSH) now works even if output buffer too short
+- after inflateSync, don't scare people with just "lo world"
+- added support for DJGPP
+
+Changes in 0.9 (1 May 95)
+- don't assume that zalloc clears the allocated memory (the TurboC bug
+ was Mark's bug after all :)
+- let again gzread copy uncompressed data unchanged (was working in 0.71)
+- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
+- added a test of inflateSync in example.c
+- moved MAX_WBITS to zconf.h because users might want to change that.
+- document explicitly that zalloc(64K) on MSDOS must return a normalized
+ pointer (zero offset)
+- added Makefiles for Microsoft C, Turbo C, Borland C++
+- faster crc32()
+
+Changes in 0.8 (29 April 95)
+- added fast inflate (inffast.c)
+- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
+ is incompatible with previous versions of zlib which returned Z_OK.
+- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
+ (actually that was not a compiler bug, see 0.81 above)
+- gzread no longer reads one extra byte in certain cases
+- In gzio destroy(), don't reference a freed structure
+- avoid many warnings for MSDOS
+- avoid the ERROR symbol which is used by MS Windows
+
+Changes in 0.71 (14 April 95)
+- Fixed more MSDOS compilation problems :( There is still a bug with
+ TurboC large model.
+
+Changes in 0.7 (14 April 95)
+- Added full inflate support.
+- Simplified the crc32() interface. The pre- and post-conditioning
+ (one's complement) is now done inside crc32(). WARNING: this is
+ incompatible with previous versions; see zlib.h for the new usage.
+
+Changes in 0.61 (12 April 95)
+- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
+
+Changes in 0.6 (11 April 95)
+- added minigzip.c
+- added gzdopen to reopen a file descriptor as gzFile
+- added transparent reading of non-gziped files in gzread.
+- fixed bug in gzread (don't read crc as data)
+- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
+- don't allocate big arrays in the stack (for MSDOS)
+- fix some MSDOS compilation problems
+
+Changes in 0.5:
+- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
+ not yet Z_FULL_FLUSH.
+- support decompression but only in a single step (forced Z_FINISH)
+- added opaque object for zalloc and zfree.
+- added deflateReset and inflateReset
+- added a variable zlib_version for consistency checking.
+- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
+ Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
+
+Changes in 0.4:
+- avoid "zip" everywhere, use zlib instead of ziplib.
+- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
+ if compression method == 8.
+- added adler32 and crc32
+- renamed deflateOptions as deflateInit2, call one or the other but not both
+- added the method parameter for deflateInit2.
+- added inflateInit2
+- simplied considerably deflateInit and inflateInit by not supporting
+ user-provided history buffer. This is supported only in deflateInit2
+ and inflateInit2.
+
+Changes in 0.3:
+- prefix all macro names with Z_
+- use Z_FINISH instead of deflateEnd to finish compression.
+- added Z_HUFFMAN_ONLY
+- added gzerror()
diff --git a/cpukit/zlib/Makefile b/cpukit/zlib/Makefile
deleted file mode 100644
index 6bba86c73f..0000000000
--- a/cpukit/zlib/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-all:
- -@echo "Please use ./configure first. Thank you."
-
-distclean:
- make -f Makefile.in distclean
diff --git a/cpukit/zlib/Makefile.am b/cpukit/zlib/Makefile.am
new file mode 100644
index 0000000000..4efda6b828
--- /dev/null
+++ b/cpukit/zlib/Makefile.am
@@ -0,0 +1,28 @@
+#
+# $Id$
+#
+
+include $(top_srcdir)/automake/compile.am
+
+project_lib_LIBRARIES = libz.a
+
+libz_a_SOURCES = adler32.c
+libz_a_SOURCES += compress.c
+libz_a_SOURCES += crc32.c crc32.h
+libz_a_SOURCES += deflate.c deflate.h
+libz_a_SOURCES += gzclose.c gzguts.h gzlib.c gzread.c gzwrite.c
+libz_a_SOURCES += infback.c
+libz_a_SOURCES += inffast.c inffast.h
+libz_a_SOURCES += inffixed.h
+libz_a_SOURCES += inflate.c inflate.h
+libz_a_SOURCES += inftrees.c inftrees.h
+libz_a_SOURCES += trees.c trees.h
+libz_a_SOURCES += uncompr.c
+libz_a_SOURCES += zconf.h
+libz_a_SOURCES += zlib.h
+libz_a_SOURCES += zutil.c zutil.h
+
+include_HEADERS = zlib.h zconf.h
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/zlib/Makefile.in b/cpukit/zlib/Makefile.in
deleted file mode 100644
index 5a2300a8cc..0000000000
--- a/cpukit/zlib/Makefile.in
+++ /dev/null
@@ -1,252 +0,0 @@
-# Makefile for zlib
-# Copyright (C) 1995-2010 Jean-loup Gailly.
-# For conditions of distribution and use, see copyright notice in zlib.h
-
-# To compile and test, type:
-# ./configure; make test
-# Normally configure builds both a static and a shared library.
-# If you want to build just a static library, use: ./configure --static
-
-# To use the asm code, type:
-# cp contrib/asm?86/match.S ./match.S
-# make LOC=-DASMV OBJA=match.o
-
-# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
-# make install
-# To install in $HOME instead of /usr/local, use:
-# make install prefix=$HOME
-
-CC=cc
-
-CFLAGS=-O
-#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
-#CFLAGS=-g -DDEBUG
-#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
-# -Wstrict-prototypes -Wmissing-prototypes
-
-SFLAGS=-O
-
-LDFLAGS=-L. libz.a
-LDSHARED=$(CC)
-CPP=$(CC) -E
-
-STATICLIB=libz.a
-SHAREDLIB=libz.so
-SHAREDLIBV=libz.so.1.2.4
-SHAREDLIBM=libz.so.1
-LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
-
-AR=ar rc
-RANLIB=ranlib
-TAR=tar
-SHELL=/bin/sh
-EXE=
-
-prefix = /usr/local
-exec_prefix = ${prefix}
-libdir = ${exec_prefix}/lib
-includedir = ${prefix}/include
-mandir = ${prefix}/share/man
-man3dir = ${mandir}/man3
-pkgconfigdir = ${libdir}/pkgconfig
-
-OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
- gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
-
-PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo \
- gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo
-
-# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
-OBJA =
-PIC_OBJA =
-
-OBJS = $(OBJC) $(OBJA)
-
-PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
-
-all: static shared
-
-static: example$(EXE) minigzip$(EXE)
-
-shared: examplesh$(EXE) minigzipsh$(EXE)
-
-all64: example64$(EXE) minigzip64$(EXE)
-
-check: test
-
-test: all teststatic testshared
-
-teststatic: static
- @if echo hello world | ./minigzip | ./minigzip -d && ./example; then \
- echo ' *** zlib test OK ***'; \
- else \
- echo ' *** zlib test FAILED ***'; false; \
- fi
- -@rm -f foo.gz
-
-testshared: shared
- @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
- LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
- DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
- SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
- if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh; then \
- echo ' *** zlib shared test OK ***'; \
- else \
- echo ' *** zlib shared test FAILED ***'; false; \
- fi
- -@rm -f foo.gz
-
-test64: all64
- @if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64; then \
- echo ' *** zlib 64-bit test OK ***'; \
- else \
- echo ' *** zlib 64-bit test FAILED ***'; false; \
- fi
- -@rm -f foo.gz
-
-libz.a: $(OBJS)
- $(AR) $@ $(OBJS)
- -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
-
-match.o: match.S
- $(CPP) match.S > _match.s
- $(CC) -c _match.s
- mv _match.o match.o
- rm -f _match.s
-
-match.lo: match.S
- $(CPP) match.S > _match.s
- $(CC) -c -fPIC _match.s
- mv _match.o match.lo
- rm -f _match.s
-
-example64.o: example.c zlib.h zconf.h
- $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
-
-minigzip64.o: minigzip.c zlib.h zconf.h
- $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
-
-.SUFFIXES: .lo
-
-.c.lo:
- -@if [ ! -d objs ]; then mkdir objs; fi
- $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
- -@mv objs/$*.o $@
-
-$(SHAREDLIBV): $(PIC_OBJS)
- $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) -lc
- rm -f $(SHAREDLIB) $(SHAREDLIBM)
- ln -s $@ $(SHAREDLIB)
- ln -s $@ $(SHAREDLIBM)
- -@rmdir objs
-
-example$(EXE): example.o $(STATICLIB)
- $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
-
-minigzip$(EXE): minigzip.o $(STATICLIB)
- $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
-
-examplesh$(EXE): example.o $(SHAREDLIBV)
- $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
-
-minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
- $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
-
-example64$(EXE): example64.o $(STATICLIB)
- $(CC) $(CFLAGS) -o $@ example64.o $(LDFLAGS)
-
-minigzip64$(EXE): minigzip64.o $(STATICLIB)
- $(CC) $(CFLAGS) -o $@ minigzip64.o $(LDFLAGS)
-
-install-libs: $(LIBS)
- -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
- -@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
- -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
- -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
- cp $(LIBS) $(DESTDIR)$(libdir)
- cd $(DESTDIR)$(libdir); chmod u=rw,go=r $(STATICLIB)
- -@(cd $(DESTDIR)$(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
- -@cd $(DESTDIR)$(libdir); if test "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
- chmod 755 $(SHAREDLIBV); \
- rm -f $(SHAREDLIB) $(SHAREDLIBM); \
- ln -s $(SHAREDLIBV) $(SHAREDLIB); \
- ln -s $(SHAREDLIBV) $(SHAREDLIBM); \
- (ldconfig || true) >/dev/null 2>&1; \
- fi
- cp zlib.3 $(DESTDIR)$(man3dir)
- chmod 644 $(DESTDIR)$(man3dir)/zlib.3
- cp zlib.pc $(DESTDIR)$(pkgconfigdir)
- chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
-# The ranlib in install is needed on NeXTSTEP which checks file times
-# ldconfig is for Linux
-
-install: install-libs
- -@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
- cp zlib.h zconf.h $(DESTDIR)$(includedir)
- chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
-
-uninstall:
- cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
- cd $(DESTDIR)$(libdir); rm -f libz.a; \
- if test "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
- rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
- fi
- cd $(DESTDIR)$(man3dir); rm -f zlib.3
- cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc
-
-docs: zlib.3.pdf
-
-zlib.3.pdf: zlib.3
- groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
-
-zconf.h.in: zconf.h.cmakein
- sed "/^#cmakedefine/D" < zconf.h.cmakein > zconf.h.in
- touch -r zconf.h.cmakein zconf.h.in
-
-zconf: zconf.h.in
- cp -p zconf.h.in zconf.h
-
-mostlyclean: clean
-clean:
- rm -f *.o *.lo *~ \
- example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
- example64$(EXE) minigzip64$(EXE) \
- libz.* foo.gz so_locations \
- _match.s maketree contrib/infback9/*.o
- rm -rf objs
-
-maintainer-clean: distclean
-distclean: clean zconf docs
- rm -f Makefile zlib.pc
- -@rm -f .DS_Store
- -@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile
- -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile
- -@touch -r Makefile.in Makefile
-
-tags:
- etags *.[ch]
-
-depend:
- makedepend -- $(CFLAGS) -- *.[ch]
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-adler32.o zutil.o: zutil.h zlib.h zconf.h
-gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h
-compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h
-crc32.o: zutil.h zlib.h zconf.h crc32.h
-deflate.o: deflate.h zutil.h zlib.h zconf.h
-infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
-inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inftrees.o: zutil.h zlib.h zconf.h inftrees.h
-trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
-
-adler32.lo zutil.lo: zutil.h zlib.h zconf.h
-gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h
-compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h
-crc32.lo: zutil.h zlib.h zconf.h crc32.h
-deflate.lo: deflate.h zutil.h zlib.h zconf.h
-infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
-inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inftrees.lo: zutil.h zlib.h zconf.h inftrees.h
-trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h
diff --git a/cpukit/zlib/algorithm.txt b/cpukit/zlib/algorithm.txt
deleted file mode 100644
index b022dde312..0000000000
--- a/cpukit/zlib/algorithm.txt
+++ /dev/null
@@ -1,209 +0,0 @@
-1. Compression algorithm (deflate)
-
-The deflation algorithm used by gzip (also zip and zlib) is a variation of
-LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
-the input data. The second occurrence of a string is replaced by a
-pointer to the previous string, in the form of a pair (distance,
-length). Distances are limited to 32K bytes, and lengths are limited
-to 258 bytes. When a string does not occur anywhere in the previous
-32K bytes, it is emitted as a sequence of literal bytes. (In this
-description, `string' must be taken as an arbitrary sequence of bytes,
-and is not restricted to printable characters.)
-
-Literals or match lengths are compressed with one Huffman tree, and
-match distances are compressed with another tree. The trees are stored
-in a compact form at the start of each block. The blocks can have any
-size (except that the compressed data for one block must fit in
-available memory). A block is terminated when deflate() determines that
-it would be useful to start another block with fresh trees. (This is
-somewhat similar to the behavior of LZW-based _compress_.)
-
-Duplicated strings are found using a hash table. All input strings of
-length 3 are inserted in the hash table. A hash index is computed for
-the next 3 bytes. If the hash chain for this index is not empty, all
-strings in the chain are compared with the current input string, and
-the longest match is selected.
-
-The hash chains are searched starting with the most recent strings, to
-favor small distances and thus take advantage of the Huffman encoding.
-The hash chains are singly linked. There are no deletions from the
-hash chains, the algorithm simply discards matches that are too old.
-
-To avoid a worst-case situation, very long hash chains are arbitrarily
-truncated at a certain length, determined by a runtime option (level
-parameter of deflateInit). So deflate() does not always find the longest
-possible match but generally finds a match which is long enough.
-
-deflate() also defers the selection of matches with a lazy evaluation
-mechanism. After a match of length N has been found, deflate() searches for
-a longer match at the next input byte. If a longer match is found, the
-previous match is truncated to a length of one (thus producing a single
-literal byte) and the process of lazy evaluation begins again. Otherwise,
-the original match is kept, and the next match search is attempted only N
-steps later.
-
-The lazy match evaluation is also subject to a runtime parameter. If
-the current match is long enough, deflate() reduces the search for a longer
-match, thus speeding up the whole process. If compression ratio is more
-important than speed, deflate() attempts a complete second search even if
-the first match is already long enough.
-
-The lazy match evaluation is not performed for the fastest compression
-modes (level parameter 1 to 3). For these fast modes, new strings
-are inserted in the hash table only when no match was found, or
-when the match is not too long. This degrades the compression ratio
-but saves time since there are both fewer insertions and fewer searches.
-
-
-2. Decompression algorithm (inflate)
-
-2.1 Introduction
-
-The key question is how to represent a Huffman code (or any prefix code) so
-that you can decode fast. The most important characteristic is that shorter
-codes are much more common than longer codes, so pay attention to decoding the
-short codes fast, and let the long codes take longer to decode.
-
-inflate() sets up a first level table that covers some number of bits of
-input less than the length of longest code. It gets that many bits from the
-stream, and looks it up in the table. The table will tell if the next
-code is that many bits or less and how many, and if it is, it will tell
-the value, else it will point to the next level table for which inflate()
-grabs more bits and tries to decode a longer code.
-
-How many bits to make the first lookup is a tradeoff between the time it
-takes to decode and the time it takes to build the table. If building the
-table took no time (and if you had infinite memory), then there would only
-be a first level table to cover all the way to the longest code. However,
-building the table ends up taking a lot longer for more bits since short
-codes are replicated many times in such a table. What inflate() does is
-simply to make the number of bits in the first table a variable, and then
-to set that variable for the maximum speed.
-
-For inflate, which has 286 possible codes for the literal/length tree, the size
-of the first table is nine bits. Also the distance trees have 30 possible
-values, and the size of the first table is six bits. Note that for each of
-those cases, the table ended up one bit longer than the ``average'' code
-length, i.e. the code length of an approximately flat code which would be a
-little more than eight bits for 286 symbols and a little less than five bits
-for 30 symbols.
-
-
-2.2 More details on the inflate table lookup
-
-Ok, you want to know what this cleverly obfuscated inflate tree actually
-looks like. You are correct that it's not a Huffman tree. It is simply a
-lookup table for the first, let's say, nine bits of a Huffman symbol. The
-symbol could be as short as one bit or as long as 15 bits. If a particular
-symbol is shorter than nine bits, then that symbol's translation is duplicated
-in all those entries that start with that symbol's bits. For example, if the
-symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a
-symbol is nine bits long, it appears in the table once.
-
-If the symbol is longer than nine bits, then that entry in the table points
-to another similar table for the remaining bits. Again, there are duplicated
-entries as needed. The idea is that most of the time the symbol will be short
-and there will only be one table look up. (That's whole idea behind data
-compression in the first place.) For the less frequent long symbols, there
-will be two lookups. If you had a compression method with really long
-symbols, you could have as many levels of lookups as is efficient. For
-inflate, two is enough.
-
-So a table entry either points to another table (in which case nine bits in
-the above example are gobbled), or it contains the translation for the symbol
-and the number of bits to gobble. Then you start again with the next
-ungobbled bit.
-
-You may wonder: why not just have one lookup table for how ever many bits the
-longest symbol is? The reason is that if you do that, you end up spending
-more time filling in duplicate symbol entries than you do actually decoding.
-At least for deflate's output that generates new trees every several 10's of
-kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
-would take too long if you're only decoding several thousand symbols. At the
-other extreme, you could make a new table for every bit in the code. In fact,
-that's essentially a Huffman tree. But then you spend two much time
-traversing the tree while decoding, even for short symbols.
-
-So the number of bits for the first lookup table is a trade of the time to
-fill out the table vs. the time spent looking at the second level and above of
-the table.
-
-Here is an example, scaled down:
-
-The code being decoded, with 10 symbols, from 1 to 6 bits long:
-
-A: 0
-B: 10
-C: 1100
-D: 11010
-E: 11011
-F: 11100
-G: 11101
-H: 11110
-I: 111110
-J: 111111
-
-Let's make the first table three bits long (eight entries):
-
-000: A,1
-001: A,1
-010: A,1
-011: A,1
-100: B,2
-101: B,2
-110: -> table X (gobble 3 bits)
-111: -> table Y (gobble 3 bits)
-
-Each entry is what the bits decode as and how many bits that is, i.e. how
-many bits to gobble. Or the entry points to another table, with the number of
-bits to gobble implicit in the size of the table.
-
-Table X is two bits long since the longest code starting with 110 is five bits
-long:
-
-00: C,1
-01: C,1
-10: D,2
-11: E,2
-
-Table Y is three bits long since the longest code starting with 111 is six
-bits long:
-
-000: F,2
-001: F,2
-010: G,2
-011: G,2
-100: H,2
-101: H,2
-110: I,3
-111: J,3
-
-So what we have here are three tables with a total of 20 entries that had to
-be constructed. That's compared to 64 entries for a single table. Or
-compared to 16 entries for a Huffman tree (six two entry tables and one four
-entry table). Assuming that the code ideally represents the probability of
-the symbols, it takes on the average 1.25 lookups per symbol. That's compared
-to one lookup for the single table, or 1.66 lookups per symbol for the
-Huffman tree.
-
-There, I think that gives you a picture of what's going on. For inflate, the
-meaning of a particular symbol is often more than just a letter. It can be a
-byte (a "literal"), or it can be either a length or a distance which
-indicates a base value and a number of bits to fetch after the code that is
-added to the base value. Or it might be the special end-of-block code. The
-data structures created in inftrees.c try to encode all that information
-compactly in the tables.
-
-
-Jean-loup Gailly Mark Adler
-jloup@gzip.org madler@alumni.caltech.edu
-
-
-References:
-
-[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
-Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
-pp. 337-343.
-
-``DEFLATE Compressed Data Format Specification'' available in
-http://www.ietf.org/rfc/rfc1951.txt
diff --git a/cpukit/zlib/amiga/Makefile.pup b/cpukit/zlib/amiga/Makefile.pup
deleted file mode 100644
index 8940c120fb..0000000000
--- a/cpukit/zlib/amiga/Makefile.pup
+++ /dev/null
@@ -1,69 +0,0 @@
-# Amiga powerUP (TM) Makefile
-# makefile for libpng and SAS C V6.58/7.00 PPC compiler
-# Copyright (C) 1998 by Andreas R. Kleinert
-
-LIBNAME = libzip.a
-
-CC = scppc
-CFLAGS = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL \
- OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8 NOVER
-AR = ppc-amigaos-ar cr
-RANLIB = ppc-amigaos-ranlib
-LD = ppc-amigaos-ld -r
-LDFLAGS = -o
-LDLIBS = LIB:scppc.a LIB:end.o
-RM = delete quiet
-
-OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \
- uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
-
-TEST_OBJS = example.o minigzip.o
-
-all: example minigzip
-
-check: test
-test: all
- example
- echo hello world | minigzip | minigzip -d
-
-$(LIBNAME): $(OBJS)
- $(AR) $@ $(OBJS)
- -$(RANLIB) $@
-
-example: example.o $(LIBNAME)
- $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS)
-
-minigzip: minigzip.o $(LIBNAME)
- $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS)
-
-mostlyclean: clean
-clean:
- $(RM) *.o example minigzip $(LIBNAME) foo.gz
-
-zip:
- zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \
- descrip.mms *.[ch]
-
-tgz:
- cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \
- zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch]
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-adler32.o: zlib.h zconf.h
-compress.o: zlib.h zconf.h
-crc32.o: crc32.h zlib.h zconf.h
-deflate.o: deflate.h zutil.h zlib.h zconf.h
-example.o: zlib.h zconf.h
-gzclose.o: zlib.h zconf.h gzguts.h
-gzlib.o: zlib.h zconf.h gzguts.h
-gzread.o: zlib.h zconf.h gzguts.h
-gzwrite.o: zlib.h zconf.h gzguts.h
-inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inftrees.o: zutil.h zlib.h zconf.h inftrees.h
-minigzip.o: zlib.h zconf.h
-trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
-uncompr.o: zlib.h zconf.h
-zutil.o: zutil.h zlib.h zconf.h
diff --git a/cpukit/zlib/amiga/Makefile.sas b/cpukit/zlib/amiga/Makefile.sas
deleted file mode 100644
index 749e291527..0000000000
--- a/cpukit/zlib/amiga/Makefile.sas
+++ /dev/null
@@ -1,68 +0,0 @@
-# SMakefile for zlib
-# Modified from the standard UNIX Makefile Copyright Jean-loup Gailly
-# Osma Ahvenlampi <Osma.Ahvenlampi@hut.fi>
-# Amiga, SAS/C 6.56 & Smake
-
-CC=sc
-CFLAGS=OPT
-#CFLAGS=OPT CPU=68030
-#CFLAGS=DEBUG=LINE
-LDFLAGS=LIB z.lib
-
-SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \
- NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \
- DEF=POSTINC
-
-OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \
- uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
-
-TEST_OBJS = example.o minigzip.o
-
-all: SCOPTIONS example minigzip
-
-check: test
-test: all
- example
- echo hello world | minigzip | minigzip -d
-
-install: z.lib
- copy clone zlib.h zconf.h INCLUDE:
- copy clone z.lib LIB:
-
-z.lib: $(OBJS)
- oml z.lib r $(OBJS)
-
-example: example.o z.lib
- $(CC) $(CFLAGS) LINK TO $@ example.o $(LDFLAGS)
-
-minigzip: minigzip.o z.lib
- $(CC) $(CFLAGS) LINK TO $@ minigzip.o $(LDFLAGS)
-
-mostlyclean: clean
-clean:
- -delete force quiet example minigzip *.o z.lib foo.gz *.lnk SCOPTIONS
-
-SCOPTIONS: Makefile.sas
- copy to $@ <from <
-$(SCOPTIONS)
-<
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-adler32.o: zlib.h zconf.h
-compress.o: zlib.h zconf.h
-crc32.o: crc32.h zlib.h zconf.h
-deflate.o: deflate.h zutil.h zlib.h zconf.h
-example.o: zlib.h zconf.h
-gzclose.o: zlib.h zconf.h gzguts.h
-gzlib.o: zlib.h zconf.h gzguts.h
-gzread.o: zlib.h zconf.h gzguts.h
-gzwrite.o: zlib.h zconf.h gzguts.h
-inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inftrees.o: zutil.h zlib.h zconf.h inftrees.h
-minigzip.o: zlib.h zconf.h
-trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
-uncompr.o: zlib.h zconf.h
-zutil.o: zutil.h zlib.h zconf.h
diff --git a/cpukit/zlib/as400/bndsrc b/cpukit/zlib/as400/bndsrc
deleted file mode 100644
index 9cf94bb356..0000000000
--- a/cpukit/zlib/as400/bndsrc
+++ /dev/null
@@ -1,132 +0,0 @@
-STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('ZLIB')
-
-/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
-/* Version 1.1.3 entry points. */
-/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
-
-/********************************************************************/
-/* *MODULE ADLER32 ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("adler32")
-
-/********************************************************************/
-/* *MODULE COMPRESS ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("compress")
- EXPORT SYMBOL("compress2")
-
-/********************************************************************/
-/* *MODULE CRC32 ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("crc32")
- EXPORT SYMBOL("get_crc_table")
-
-/********************************************************************/
-/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("deflate")
- EXPORT SYMBOL("deflateEnd")
- EXPORT SYMBOL("deflateSetDictionary")
- EXPORT SYMBOL("deflateCopy")
- EXPORT SYMBOL("deflateReset")
- EXPORT SYMBOL("deflateParams")
- EXPORT SYMBOL("deflatePrime")
- EXPORT SYMBOL("deflateInit_")
- EXPORT SYMBOL("deflateInit2_")
-
-/********************************************************************/
-/* *MODULE GZIO ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("gzopen")
- EXPORT SYMBOL("gzdopen")
- EXPORT SYMBOL("gzsetparams")
- EXPORT SYMBOL("gzread")
- EXPORT SYMBOL("gzwrite")
- EXPORT SYMBOL("gzprintf")
- EXPORT SYMBOL("gzputs")
- EXPORT SYMBOL("gzgets")
- EXPORT SYMBOL("gzputc")
- EXPORT SYMBOL("gzgetc")
- EXPORT SYMBOL("gzflush")
- EXPORT SYMBOL("gzseek")
- EXPORT SYMBOL("gzrewind")
- EXPORT SYMBOL("gztell")
- EXPORT SYMBOL("gzeof")
- EXPORT SYMBOL("gzclose")
- EXPORT SYMBOL("gzerror")
-
-/********************************************************************/
-/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("inflate")
- EXPORT SYMBOL("inflateEnd")
- EXPORT SYMBOL("inflateSetDictionary")
- EXPORT SYMBOL("inflateSync")
- EXPORT SYMBOL("inflateReset")
- EXPORT SYMBOL("inflateInit_")
- EXPORT SYMBOL("inflateInit2_")
- EXPORT SYMBOL("inflateSyncPoint")
-
-/********************************************************************/
-/* *MODULE UNCOMPR ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("uncompress")
-
-/********************************************************************/
-/* *MODULE ZUTIL ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("zlibVersion")
- EXPORT SYMBOL("zError")
-
-/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
-/* Version 1.2.1 additional entry points. */
-/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
-
-/********************************************************************/
-/* *MODULE COMPRESS ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("compressBound")
-
-/********************************************************************/
-/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("deflateBound")
-
-/********************************************************************/
-/* *MODULE GZIO ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("gzungetc")
- EXPORT SYMBOL("gzclearerr")
-
-/********************************************************************/
-/* *MODULE INFBACK ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("inflateBack")
- EXPORT SYMBOL("inflateBackEnd")
- EXPORT SYMBOL("inflateBackInit_")
-
-/********************************************************************/
-/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("inflateCopy")
-
-/********************************************************************/
-/* *MODULE ZUTIL ZLIB 01/02/01 00:15:09 */
-/********************************************************************/
-
- EXPORT SYMBOL("zlibCompileFlags")
-
-ENDPGMEXP
diff --git a/cpukit/zlib/as400/compile.clp b/cpukit/zlib/as400/compile.clp
deleted file mode 100644
index 8554951500..0000000000
--- a/cpukit/zlib/as400/compile.clp
+++ /dev/null
@@ -1,123 +0,0 @@
-/******************************************************************************/
-/* */
-/* ZLIB */
-/* */
-/* Compile sources into modules and link them into a service program. */
-/* */
-/******************************************************************************/
-
- PGM
-
-/* Configuration adjustable parameters. */
-
- DCL VAR(&SRCLIB) TYPE(*CHAR) LEN(10) +
- VALUE('ZLIB') /* Source library. */
- DCL VAR(&SRCFILE) TYPE(*CHAR) LEN(10) +
- VALUE('SOURCES') /* Source member file. */
- DCL VAR(&CTLFILE) TYPE(*CHAR) LEN(10) +
- VALUE('TOOLS') /* Control member file. */
-
- DCL VAR(&MODLIB) TYPE(*CHAR) LEN(10) +
- VALUE('ZLIB') /* Module library. */
-
- DCL VAR(&SRVLIB) TYPE(*CHAR) LEN(10) +
- VALUE('LGPL') /* Service program library. */
-
- DCL VAR(&CFLAGS) TYPE(*CHAR) +
- VALUE('OPTIMIZE(40)') /* Compile options. */
-
-
-/* Working storage. */
-
- DCL VAR(&CMDLEN) TYPE(*DEC) LEN(15 5) VALUE(300) /* Command length. */
- DCL VAR(&CMD) TYPE(*CHAR) LEN(512)
-
-
-/* Compile sources into modules. */
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/ADLER32) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/COMPRESS) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/CRC32) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/DEFLATE) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/GZIO) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/INFBACK) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/INFFAST) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/INFLATE) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/INFTREES) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/TREES) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/UNCOMPR) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
- CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT +
- '/ZUTIL) SRCFILE(' *TCAT +
- &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT +
- ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS)
- CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN)
-
-
-/* Link modules into a service program. */
-
- CRTSRVPGM SRVPGM(&SRVLIB/ZLIB) +
- MODULE(&MODLIB/ADLER32 &MODLIB/COMPRESS +
- &MODLIB/CRC32 &MODLIB/DEFLATE +
- &MODLIB/GZIO &MODLIB/INFBACK +
- &MODLIB/INFFAST &MODLIB/INFLATE +
- &MODLIB/INFTREES &MODLIB/TREES +
- &MODLIB/UNCOMPR &MODLIB/ZUTIL) +
- SRCFILE(&SRCLIB/&CTLFILE) SRCMBR(BNDSRC) +
- TEXT('ZLIB 1.2.3') TGTRLS(V4R4M0)
-
- ENDPGM
diff --git a/cpukit/zlib/as400/readme.txt b/cpukit/zlib/as400/readme.txt
deleted file mode 100644
index beae13f565..0000000000
--- a/cpukit/zlib/as400/readme.txt
+++ /dev/null
@@ -1,111 +0,0 @@
- ZLIB version 1.2.3 for AS400 installation instructions
-
-I) From an AS400 *SAVF file:
-
-1) Unpacking archive to an AS400 save file
-
-On the AS400:
-
-_ Create the ZLIB AS400 library:
-
- CRTLIB LIB(ZLIB) TYPE(PROD) TEXT('ZLIB compression API library')
-
-_ Create a work save file, for example:
-
- CRTSAVF FILE(ZLIB/ZLIBSAVF)
-
-On a PC connected to the target AS400:
-
-_ Unpack the save file image to a PC file "ZLIBSAVF"
-_ Upload this file into the save file on the AS400, for example
- using ftp in BINARY mode.
-
-
-2) Populating the ZLIB AS400 source library
-
-On the AS400:
-
-_ Extract the saved objects into the ZLIB AS400 library using:
-
-RSTOBJ OBJ(*ALL) SAVLIB(ZLIB) DEV(*SAVF) SAVF(ZLIB/ZLIBSAVF) RSTLIB(ZLIB)
-
-
-3) Customize installation:
-
-_ Edit CL member ZLIB/TOOLS(COMPILE) and change parameters if needed,
- according to the comments.
-
-_ Compile this member with:
-
- CRTCLPGM PGM(ZLIB/COMPILE) SRCFILE(ZLIB/TOOLS) SRCMBR(COMPILE)
-
-
-4) Compile and generate the service program:
-
-_ This can now be done by executing:
-
- CALL PGM(ZLIB/COMPILE)
-
-
-
-II) From the original source distribution:
-
-1) On the AS400, create the source library:
-
- CRTLIB LIB(ZLIB) TYPE(PROD) TEXT('ZLIB compression API library')
-
-2) Create the source files:
-
- CRTSRCPF FILE(ZLIB/SOURCES) RCDLEN(112) TEXT('ZLIB library modules')
- CRTSRCPF FILE(ZLIB/H) RCDLEN(112) TEXT('ZLIB library includes')
- CRTSRCPF FILE(ZLIB/TOOLS) RCDLEN(112) TEXT('ZLIB library control utilities')
-
-3) From the machine hosting the distribution files, upload them (with
- FTP in text mode, for example) according to the following table:
-
- Original AS400 AS400 AS400 AS400
- file file member type description
- SOURCES Original ZLIB C subprogram sources
- adler32.c ADLER32 C ZLIB - Compute the Adler-32 checksum of a dta strm
- compress.c COMPRESS C ZLIB - Compress a memory buffer
- crc32.c CRC32 C ZLIB - Compute the CRC-32 of a data stream
- deflate.c DEFLATE C ZLIB - Compress data using the deflation algorithm
- gzio.c GZIO C ZLIB - IO on .gz files
- infback.c INFBACK C ZLIB - Inflate using a callback interface
- inffast.c INFFAST C ZLIB - Fast proc. literals & length/distance pairs
- inflate.c INFLATE C ZLIB - Interface to inflate modules
- inftrees.c INFTREES C ZLIB - Generate Huffman trees for efficient decode
- trees.c TREES C ZLIB - Output deflated data using Huffman coding
- uncompr.c UNCOMPR C ZLIB - Decompress a memory buffer
- zutil.c ZUTIL C ZLIB - Target dependent utility functions
- H Original ZLIB C and ILE/RPG include files
- crc32.h CRC32 C ZLIB - CRC32 tables
- deflate.h DEFLATE C ZLIB - Internal compression state
- inffast.h INFFAST C ZLIB - Header to use inffast.c
- inffixed.h INFFIXED C ZLIB - Table for decoding fixed codes
- inflate.h INFLATE C ZLIB - Internal inflate state definitions
- inftrees.h INFTREES C ZLIB - Header to use inftrees.c
- trees.h TREES C ZLIB - Created automatically with -DGEN_TREES_H
- zconf.h ZCONF C ZLIB - Compression library configuration
- zlib.h ZLIB C ZLIB - Compression library C user interface
- as400/zlib.inc ZLIB.INC RPGLE ZLIB - Compression library ILE RPG user interface
- zutil.h ZUTIL C ZLIB - Internal interface and configuration
- TOOLS Building source software & AS/400 README
- as400/bndsrc BNDSRC Entry point exportation list
- as400/compile.clp COMPILE CLP Compile sources & generate service program
- as400/readme.txt README TXT Installation instructions
-
-4) Continue as in I)3).
-
-
-
-
-Notes: For AS400 ILE RPG programmers, a /copy member defining the ZLIB
- API prototypes for ILE RPG can be found in ZLIB/H(ZLIB.INC).
- Please read comments in this member for more information.
-
- Remember that most foreign textual data are ASCII coded: this
- implementation does not handle conversion from/to ASCII, so
- text data code conversions must be done explicitely.
-
- Always open zipped files in binary mode.
diff --git a/cpukit/zlib/as400/zlib.inc b/cpukit/zlib/as400/zlib.inc
deleted file mode 100644
index 7bbfb7e417..0000000000
--- a/cpukit/zlib/as400/zlib.inc
+++ /dev/null
@@ -1,331 +0,0 @@
- * ZLIB.INC - Interface to the general purpose compression library
- *
- * ILE RPG400 version by Patrick Monnerat, DATASPHERE.
- * Version 1.2.3
- *
- *
- * WARNING:
- * Procedures inflateInit(), inflateInit2(), deflateInit(),
- * deflateInit2() and inflateBackInit() need to be called with
- * two additional arguments:
- * the package version string and the stream control structure.
- * size. This is needed because RPG lacks some macro feature.
- * Call these procedures as:
- * inflateInit(...: ZLIB_VERSION: %size(z_stream))
- *
- /if not defined(ZLIB_H_)
- /define ZLIB_H_
- *
- **************************************************************************
- * Constants
- **************************************************************************
- *
- * Versioning information.
- *
- D ZLIB_VERSION C '1.2.3'
- D ZLIB_VERNUM C X'1230'
- *
- * Other equates.
- *
- D Z_NO_FLUSH C 0
- D Z_SYNC_FLUSH C 2
- D Z_FULL_FLUSH C 3
- D Z_FINISH C 4
- D Z_BLOCK C 5
- *
- D Z_OK C 0
- D Z_STREAM_END C 1
- D Z_NEED_DICT C 2
- D Z_ERRNO C -1
- D Z_STREAM_ERROR C -2
- D Z_DATA_ERROR C -3
- D Z_MEM_ERROR C -4
- D Z_BUF_ERROR C -5
- DZ_VERSION_ERROR C -6
- *
- D Z_NO_COMPRESSION...
- D C 0
- D Z_BEST_SPEED C 1
- D Z_BEST_COMPRESSION...
- D C 9
- D Z_DEFAULT_COMPRESSION...
- D C -1
- *
- D Z_FILTERED C 1
- D Z_HUFFMAN_ONLY C 2
- D Z_RLE C 3
- D Z_DEFAULT_STRATEGY...
- D C 0
- *
- D Z_BINARY C 0
- D Z_ASCII C 1
- D Z_UNKNOWN C 2
- *
- D Z_DEFLATED C 8
- *
- D Z_NULL C 0
- *
- **************************************************************************
- * Types
- **************************************************************************
- *
- D z_streamp S * Stream struct ptr
- D gzFile S * File pointer
- D z_off_t S 10i 0 Stream offsets
- *
- **************************************************************************
- * Structures
- **************************************************************************
- *
- * The GZIP encode/decode stream support structure.
- *
- D z_stream DS align based(z_streamp)
- D zs_next_in * Next input byte
- D zs_avail_in 10U 0 Byte cnt at next_in
- D zs_total_in 10U 0 Total bytes read
- D zs_next_out * Output buffer ptr
- D zs_avail_out 10U 0 Room left @ next_out
- D zs_total_out 10U 0 Total bytes written
- D zs_msg * Last errmsg or null
- D zs_state * Internal state
- D zs_zalloc * procptr Int. state allocator
- D zs_free * procptr Int. state dealloc.
- D zs_opaque * Private alloc. data
- D zs_data_type 10i 0 ASC/BIN best guess
- D zs_adler 10u 0 Uncompr. adler32 val
- D 10U 0 Reserved
- D 10U 0 Ptr. alignment
- *
- **************************************************************************
- * Utility function prototypes
- **************************************************************************
- *
- D compress PR 10I 0 extproc('compress')
- D dest 32767 options(*varsize) Destination buffer
- D destLen 10U 0 Destination length
- D source 32767 const options(*varsize) Source buffer
- D sourceLen 10u 0 value Source length
- *
- D compress2 PR 10I 0 extproc('compress2')
- D dest 32767 options(*varsize) Destination buffer
- D destLen 10U 0 Destination length
- D source 32767 const options(*varsize) Source buffer
- D sourceLen 10U 0 value Source length
- D level 10I 0 value Compression level
- *
- D compressBound PR 10U 0 extproc('compressBound')
- D sourceLen 10U 0 value
- *
- D uncompress PR 10I 0 extproc('uncompress')
- D dest 32767 options(*varsize) Destination buffer
- D destLen 10U 0 Destination length
- D source 32767 const options(*varsize) Source buffer
- D sourceLen 10U 0 value Source length
- *
- D gzopen PR extproc('gzopen')
- D like(gzFile)
- D path * value options(*string) File pathname
- D mode * value options(*string) Open mode
- *
- D gzdopen PR extproc('gzdopen')
- D like(gzFile)
- D fd 10i 0 value File descriptor
- D mode * value options(*string) Open mode
- *
- D gzsetparams PR 10I 0 extproc('gzsetparams')
- D file value like(gzFile) File pointer
- D level 10I 0 value
- D strategy 10i 0 value
- *
- D gzread PR 10I 0 extproc('gzread')
- D file value like(gzFile) File pointer
- D buf 32767 options(*varsize) Buffer
- D len 10u 0 value Buffer length
- *
- D gzwrite PR 10I 0 extproc('gzwrite')
- D file value like(gzFile) File pointer
- D buf 32767 const options(*varsize) Buffer
- D len 10u 0 value Buffer length
- *
- D gzputs PR 10I 0 extproc('gzputs')
- D file value like(gzFile) File pointer
- D s * value options(*string) String to output
- *
- D gzgets PR * extproc('gzgets')
- D file value like(gzFile) File pointer
- D buf 32767 options(*varsize) Read buffer
- D len 10i 0 value Buffer length
- *
- D gzflush PR 10i 0 extproc('gzflush')
- D file value like(gzFile) File pointer
- D flush 10I 0 value Type of flush
- *
- D gzseek PR extproc('gzseek')
- D like(z_off_t)
- D file value like(gzFile) File pointer
- D offset value like(z_off_t) Offset
- D whence 10i 0 value Origin
- *
- D gzrewind PR 10i 0 extproc('gzrewind')
- D file value like(gzFile) File pointer
- *
- D gztell PR extproc('gztell')
- D like(z_off_t)
- D file value like(gzFile) File pointer
- *
- D gzeof PR 10i 0 extproc('gzeof')
- D file value like(gzFile) File pointer
- *
- D gzclose PR 10i 0 extproc('gzclose')
- D file value like(gzFile) File pointer
- *
- D gzerror PR * extproc('gzerror') Error string
- D file value like(gzFile) File pointer
- D errnum 10I 0 Error code
- *
- D gzclearerr PR extproc('gzclearerr')
- D file value like(gzFile) File pointer
- *
- **************************************************************************
- * Basic function prototypes
- **************************************************************************
- *
- D zlibVersion PR * extproc('zlibVersion') Version string
- *
- D deflateInit PR 10I 0 extproc('deflateInit_') Init. compression
- D strm like(z_stream) Compression stream
- D level 10I 0 value Compression level
- D version * value options(*string) Version string
- D stream_size 10i 0 value Stream struct. size
- *
- D deflate PR 10I 0 extproc('deflate') Compress data
- D strm like(z_stream) Compression stream
- D flush 10I 0 value Flush type required
- *
- D deflateEnd PR 10I 0 extproc('deflateEnd') Termin. compression
- D strm like(z_stream) Compression stream
- *
- D inflateInit PR 10I 0 extproc('inflateInit_') Init. expansion
- D strm like(z_stream) Expansion stream
- D version * value options(*string) Version string
- D stream_size 10i 0 value Stream struct. size
- *
- D inflate PR 10I 0 extproc('inflate') Expand data
- D strm like(z_stream) Expansion stream
- D flush 10I 0 value Flush type required
- *
- D inflateEnd PR 10I 0 extproc('inflateEnd') Termin. expansion
- D strm like(z_stream) Expansion stream
- *
- **************************************************************************
- * Advanced function prototypes
- **************************************************************************
- *
- D deflateInit2 PR 10I 0 extproc('deflateInit2_') Init. compression
- D strm like(z_stream) Compression stream
- D level 10I 0 value Compression level
- D method 10I 0 value Compression method
- D windowBits 10I 0 value log2(window size)
- D memLevel 10I 0 value Mem/cmpress tradeoff
- D strategy 10I 0 value Compression stategy
- D version * value options(*string) Version string
- D stream_size 10i 0 value Stream struct. size
- *
- D deflateSetDictionary...
- D PR 10I 0 extproc('deflateSetDictionary') Init. dictionary
- D strm like(z_stream) Compression stream
- D dictionary 32767 const options(*varsize) Dictionary bytes
- D dictLength 10U 0 value Dictionary length
- *
- D deflateCopy PR 10I 0 extproc('deflateCopy') Compress strm 2 strm
- D dest like(z_stream) Destination stream
- D source like(z_stream) Source stream
- *
- D deflateReset PR 10I 0 extproc('deflateReset') End and init. stream
- D strm like(z_stream) Compression stream
- *
- D deflateParams PR 10I 0 extproc('deflateParams') Change level & strat
- D strm like(z_stream) Compression stream
- D level 10I 0 value Compression level
- D strategy 10I 0 value Compression stategy
- *
- D deflateBound PR 10U 0 extproc('deflateBound') Change level & strat
- D strm like(z_stream) Compression stream
- D sourcelen 10U 0 value Compression level
- *
- D deflatePrime PR 10I 0 extproc('deflatePrime') Change level & strat
- D strm like(z_stream) Compression stream
- D bits 10I 0 value Number of bits to insert
- D value 10I 0 value Bits to insert
- *
- D inflateInit2 PR 10I 0 extproc('inflateInit2_') Init. expansion
- D strm like(z_stream) Expansion stream
- D windowBits 10I 0 value log2(window size)
- D version * value options(*string) Version string
- D stream_size 10i 0 value Stream struct. size
- *
- D inflateSetDictionary...
- D PR 10I 0 extproc('inflateSetDictionary') Init. dictionary
- D strm like(z_stream) Expansion stream
- D dictionary 32767 const options(*varsize) Dictionary bytes
- D dictLength 10U 0 value Dictionary length
- *
- D inflateSync PR 10I 0 extproc('inflateSync') Sync. expansion
- D strm like(z_stream) Expansion stream
- *
- D inflateCopy PR 10I 0 extproc('inflateCopy')
- D dest like(z_stream) Destination stream
- D source like(z_stream) Source stream
- *
- D inflateReset PR 10I 0 extproc('inflateReset') End and init. stream
- D strm like(z_stream) Expansion stream
- *
- D inflateBackInit...
- D PR 10I 0 extproc('inflateBackInit_')
- D strm like(z_stream) Expansion stream
- D windowBits 10I 0 value Log2(buffer size)
- D window 32767 options(*varsize) Buffer
- D version * value options(*string) Version string
- D stream_size 10i 0 value Stream struct. size
- *
- D inflateBack PR 10I 0 extproc('inflateBack')
- D strm like(z_stream) Expansion stream
- D in * value procptr Input function
- D in_desc * value Input descriptor
- D out * value procptr Output function
- D out_desc * value Output descriptor
- *
- D inflateBackEnd PR 10I 0 extproc('inflateBackEnd')
- D strm like(z_stream) Expansion stream
- *
- D zlibCompileFlags...
- D PR 10U 0 extproc('zlibCompileFlags')
- *
- **************************************************************************
- * Checksum function prototypes
- **************************************************************************
- *
- D adler32 PR 10U 0 extproc('adler32') New checksum
- D adler 10U 0 value Old checksum
- D buf 32767 const options(*varsize) Bytes to accumulate
- D len 10U 0 value Buffer length
- *
- D crc32 PR 10U 0 extproc('crc32') New checksum
- D crc 10U 0 value Old checksum
- D buf 32767 const options(*varsize) Bytes to accumulate
- D len 10U 0 value Buffer length
- *
- **************************************************************************
- * Miscellaneous function prototypes
- **************************************************************************
- *
- D zError PR * extproc('zError') Error string
- D err 10I 0 value Error code
- *
- D inflateSyncPoint...
- D PR 10I 0 extproc('inflateSyncPoint')
- D strm like(z_stream) Expansion stream
- *
- D get_crc_table PR * extproc('get_crc_table') Ptr to ulongs
- *
- /endif
diff --git a/cpukit/zlib/configure b/cpukit/zlib/configure
deleted file mode 100755
index 672fd3711d..0000000000
--- a/cpukit/zlib/configure
+++ /dev/null
@@ -1,546 +0,0 @@
-#!/bin/sh
-# configure script for zlib.
-#
-# Normally configure builds both a static and a shared library.
-# If you want to build just a static library, use: ./configure --static
-#
-# To impose specific compiler or flags or install directory, use for example:
-# prefix=$HOME CC=cc CFLAGS="-O4" ./configure
-# or for csh/tcsh users:
-# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
-
-# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
-# If you have problems, try without defining CC and CFLAGS before reporting
-# an error.
-
-STATICLIB=libz.a
-LDFLAGS="${LDFLAGS} -L. ${STATICLIB}"
-VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
-VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
-VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
-VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
-AR=${AR-"ar"}
-AR_RC="${AR} rc"
-RANLIB=${RANLIB-"ranlib"}
-prefix=${prefix-/usr/local}
-exec_prefix=${exec_prefix-'${prefix}'}
-libdir=${libdir-'${exec_prefix}/lib'}
-includedir=${includedir-'${prefix}/include'}
-mandir=${mandir-'${prefix}/share/man'}
-shared_ext='.so'
-shared=1
-zprefix=0
-build64=0
-gcc=0
-old_cc="$CC"
-old_cflags="$CFLAGS"
-
-while test $# -ge 1
-do
-case "$1" in
- -h* | --help)
- echo 'usage:'
- echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]'
- echo ' [--static] [--64] [--libdir=LIBDIR] [--includedir=INCLUDEDIR]'
- exit 0 ;;
- -p*=* | --prefix=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
- -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
- -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
- -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
- -u*=* | --uname=*) uname=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
- -p* | --prefix) prefix="$2"; shift; shift ;;
- -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
- -l* | --libdir) libdir="$2"; shift; shift ;;
- -i* | --includedir) includedir="$2"; shift; shift ;;
- -s* | --shared | --enable-shared) shared=1; shift ;;
- -t | --static) shared=0; shift ;;
- -z* | --zprefix) zprefix=1; shift ;;
- -6* | --64) build64=1; shift ;;
- --sysconfdir=*) echo "ignored option: --sysconfdir"; shift ;;
- --localstatedir=*) echo "ignored option: --localstatedir"; shift ;;
- *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
- esac
-done
-
-test=ztest$$
-cat > $test.c <<EOF
-extern int getchar();
-int hello() {return getchar();}
-EOF
-
-test -z "$CC" && echo Checking for gcc...
-cc=${CC-gcc}
-cflags=${CFLAGS-"-O3"}
-# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
-case "$cc" in
- *gcc*) gcc=1 ;;
-esac
-
-if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
- CC="$cc"
- SFLAGS="${CFLAGS-"-O3"} -fPIC"
- CFLAGS="${CFLAGS-"-O3"}"
- if test $build64 -eq 1; then
- CFLAGS="${CFLAGS} -m64"
- SFLAGS="${SFLAGS} -m64"
- fi
- if test "${ZLIBGCCWARN}" = "YES"; then
- CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
- fi
- if test -z "$uname"; then
- uname=`(uname -s || echo unknown) 2>/dev/null`
- fi
- case "$uname" in
- Linux | linux | GNU | GNU/* | *BSD | DragonFly) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
- CYGWIN* | Cygwin* | cygwin* | OS/2* )
- EXE='.exe' ;;
- QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
- # (alain.bonnefoy@icbt.com)
- LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
- HP-UX*)
- LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
- case `(uname -m || echo unknown) 2>/dev/null` in
- ia64)
- shared_ext='.so'
- SHAREDLIB='libz.so' ;;
- *)
- shared_ext='.sl'
- SHAREDLIB='libz.sl' ;;
- esac ;;
- Darwin*) shared_ext='.dylib'
- SHAREDLIB=libz$shared_ext
- SHAREDLIBV=libz.$VER$shared_ext
- SHAREDLIBM=libz.$VER1$shared_ext
- LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} ;;
- *) LDSHARED=${LDSHARED-"$cc -shared"} ;;
- esac
-else
- # find system name and corresponding cc options
- CC=${CC-cc}
- if test -z "$uname"; then
- uname=`(uname -sr || echo unknown) 2>/dev/null`
- fi
- case "$uname" in
- HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
- CFLAGS=${CFLAGS-"-O"}
-# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
- LDSHARED=${LDSHARED-"ld -b"}
- case `(uname -m || echo unknown) 2>/dev/null` in
- ia64)
- shared_ext='.so'
- SHAREDLIB='libz.so' ;;
- *)
- shared_ext='.sl'
- SHAREDLIB='libz.sl' ;;
- esac ;;
- IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
- CFLAGS=${CFLAGS-"-ansi -O2"}
- LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
- OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
- CFLAGS=${CFLAGS-"-O -std1"}
- LDFLAGS="${LDFLAGS} -Wl,-rpath,."
- LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
- OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
- CFLAGS=${CFLAGS-"-O -std1"}
- LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
- QNX*) SFLAGS=${CFLAGS-"-4 -O"}
- CFLAGS=${CFLAGS-"-4 -O"}
- LDSHARED=${LDSHARED-"cc"}
- RANLIB=${RANLIB-"true"}
- AR_RC="cc -A" ;;
- SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
- CFLAGS=${CFLAGS-"-O3"}
- LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
- SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
- case `(uname -m || echo unknown) 2>/dev/null` in
- i86*)
- SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
- CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
- *)
- SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
- CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
- esac ;;
- SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
- CFLAGS=${CFLAGS-"-O2"}
- LDSHARED=${LDSHARED-"ld"} ;;
- SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
- CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
- LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
- UNIX_System_V\ 4.2.0)
- SFLAGS=${CFLAGS-"-KPIC -O"}
- CFLAGS=${CFLAGS-"-O"}
- LDSHARED=${LDSHARED-"cc -G"} ;;
- UNIX_SV\ 4.2MP)
- SFLAGS=${CFLAGS-"-Kconform_pic -O"}
- CFLAGS=${CFLAGS-"-O"}
- LDSHARED=${LDSHARED-"cc -G"} ;;
- OpenUNIX\ 5)
- SFLAGS=${CFLAGS-"-KPIC -O"}
- CFLAGS=${CFLAGS-"-O"}
- LDSHARED=${LDSHARED-"cc -G"} ;;
- AIX*) # Courtesy of dbakker@arrayasolutions.com
- SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
- CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
- LDSHARED=${LDSHARED-"xlc -G"} ;;
- # send working options for other systems to zlib@gzip.org
- *) SFLAGS=${CFLAGS-"-O"}
- CFLAGS=${CFLAGS-"-O"}
- LDSHARED=${LDSHARED-"cc -shared"} ;;
- esac
-fi
-
-SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
-SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
-SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
-
-if test $shared -eq 1; then
- echo Checking for shared library support...
- # we must test in two steps (cc then ld), required at least on SunOS 4.x
- if test "`($CC -w -c $SFLAGS $test.c) 2>&1`" = "" &&
- test "`($LDSHARED $SFLAGS -o $test$shared_ext $test.o) 2>&1`" = ""; then
- echo Building shared library $SHAREDLIBV with $CC.
- elif test -z "$old_cc" -a -z "$old_cflags"; then
- echo No shared library support.
- shared=0;
- else
- echo Tested $CC -w -c $SFLAGS $test.c
- $CC -w -c $SFLAGS $test.c
- echo Tested $LDSHARED $SFLAGS -o $test$shared_ext $test.o
- $LDSHARED $SFLAGS -o $test$shared_ext $test.o
- echo 'No shared library support; try without defining CC and CFLAGS'
- shared=0;
- fi
-fi
-if test $shared -eq 0; then
- LDSHARED="$CC"
- ALL="static"
- TEST="all teststatic"
- SHAREDLIB=""
- SHAREDLIBV=""
- SHAREDLIBM=""
- echo Building static library $STATICLIB version $VER with $CC.
-else
- ALL="static shared"
- TEST="all teststatic testshared"
-fi
-
-cat > $test.c <<EOF
-#include <sys/types.h>
-off64_t dummy = 0;
-EOF
-if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c) 2>&1`" = ""; then
- CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
- SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
- ALL="${ALL} all64"
- TEST="${TEST} test64"
- echo "Checking for off64_t... Yes."
- echo "Checking for fseeko... Yes."
-else
- echo "Checking for off64_t... No."
- cat > $test.c <<EOF
-#include <stdio.h>
-int main(void) {
- fseeko(NULL, 0, 0);
- return 0;
-}
-EOF
- if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
- echo "Checking for fseeko... Yes."
- else
- CFLAGS="${CFLAGS} -DNO_FSEEKO"
- SFLAGS="${SFLAGS} -DNO_FSEEKO"
- echo "Checking for fseeko... No."
- fi
-fi
-
-cp -p zconf.h.in zconf.h
-
-cat > $test.c <<EOF
-#include <unistd.h>
-int main() { return 0; }
-EOF
-if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
- mv zconf.temp.h zconf.h
- echo "Checking for unistd.h... Yes."
-else
- echo "Checking for unistd.h... No."
-fi
-
-if test $zprefix -eq 1; then
- sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
- mv zconf.temp.h zconf.h
- echo "Using z_ prefix on all symbols."
-fi
-
-cat > $test.c <<EOF
-#include <stdio.h>
-#include <stdarg.h>
-#include "zconf.h"
-
-int main()
-{
-#ifndef STDC
- choke me
-#endif
-
- return 0;
-}
-EOF
-
-if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
-
- cat > $test.c <<EOF
-#include <stdio.h>
-#include <stdarg.h>
-
-int mytest(const char *fmt, ...)
-{
- char buf[20];
- va_list ap;
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- return 0;
-}
-
-int main()
-{
- return (mytest("Hello%d\n", 1));
-}
-EOF
-
- if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
- echo "Checking for vsnprintf() in stdio.h... Yes."
-
- cat >$test.c <<EOF
-#include <stdio.h>
-#include <stdarg.h>
-
-int mytest(const char *fmt, ...)
-{
- int n;
- char buf[20];
- va_list ap;
-
- va_start(ap, fmt);
- n = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- return n;
-}
-
-int main()
-{
- return (mytest("Hello%d\n", 1));
-}
-EOF
-
- if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- echo "Checking for return value of vsnprintf()... Yes."
- else
- CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
- SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
- echo "Checking for return value of vsnprintf()... No."
- echo " WARNING: apparently vsnprintf() does not return a value. zlib"
- echo " can build but will be open to possible string-format security"
- echo " vulnerabilities."
- fi
- else
- CFLAGS="$CFLAGS -DNO_vsnprintf"
- SFLAGS="$SFLAGS -DNO_vsnprintf"
- echo "Checking for vsnprintf() in stdio.h... No."
- echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
- echo " can build but will be open to possible buffer-overflow security"
- echo " vulnerabilities."
-
- cat >$test.c <<EOF
-#include <stdio.h>
-#include <stdarg.h>
-
-int mytest(const char *fmt, ...)
-{
- int n;
- char buf[20];
- va_list ap;
-
- va_start(ap, fmt);
- n = vsprintf(buf, fmt, ap);
- va_end(ap);
- return n;
-}
-
-int main()
-{
- return (mytest("Hello%d\n", 1));
-}
-EOF
-
- if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- echo "Checking for return value of vsprintf()... Yes."
- else
- CFLAGS="$CFLAGS -DHAS_vsprintf_void"
- SFLAGS="$SFLAGS -DHAS_vsprintf_void"
- echo "Checking for return value of vsprintf()... No."
- echo " WARNING: apparently vsprintf() does not return a value. zlib"
- echo " can build but will be open to possible string-format security"
- echo " vulnerabilities."
- fi
- fi
-else
- echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
-
- cat >$test.c <<EOF
-#include <stdio.h>
-
-int mytest()
-{
- char buf[20];
-
- snprintf(buf, sizeof(buf), "%s", "foo");
- return 0;
-}
-
-int main()
-{
- return (mytest());
-}
-EOF
-
- if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
- echo "Checking for snprintf() in stdio.h... Yes."
-
- cat >$test.c <<EOF
-#include <stdio.h>
-
-int mytest()
-{
- char buf[20];
-
- return snprintf(buf, sizeof(buf), "%s", "foo");
-}
-
-int main()
-{
- return (mytest());
-}
-EOF
-
- if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- echo "Checking for return value of snprintf()... Yes."
- else
- CFLAGS="$CFLAGS -DHAS_snprintf_void"
- SFLAGS="$SFLAGS -DHAS_snprintf_void"
- echo "Checking for return value of snprintf()... No."
- echo " WARNING: apparently snprintf() does not return a value. zlib"
- echo " can build but will be open to possible string-format security"
- echo " vulnerabilities."
- fi
- else
- CFLAGS="$CFLAGS -DNO_snprintf"
- SFLAGS="$SFLAGS -DNO_snprintf"
- echo "Checking for snprintf() in stdio.h... No."
- echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
- echo " can build but will be open to possible buffer-overflow security"
- echo " vulnerabilities."
-
- cat >$test.c <<EOF
-#include <stdio.h>
-
-int mytest()
-{
- char buf[20];
-
- return sprintf(buf, "%s", "foo");
-}
-
-int main()
-{
- return (mytest());
-}
-EOF
-
- if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- echo "Checking for return value of sprintf()... Yes."
- else
- CFLAGS="$CFLAGS -DHAS_sprintf_void"
- SFLAGS="$SFLAGS -DHAS_sprintf_void"
- echo "Checking for return value of sprintf()... No."
- echo " WARNING: apparently sprintf() does not return a value. zlib"
- echo " can build but will be open to possible string-format security"
- echo " vulnerabilities."
- fi
- fi
-fi
-
-cat >$test.c <<EOF
-#include <errno.h>
-int main() { return 0; }
-EOF
-if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
- echo "Checking for errno.h... Yes."
-else
- echo "Checking for errno.h... No."
- CFLAGS="$CFLAGS -DNO_ERRNO_H"
- SFLAGS="$SFLAGS -DNO_ERRNO_H"
-fi
-
-CPP=${CPP-"$CC -E"}
-case $CFLAGS in
- *ASMV*)
- if test "`nm $test.o | grep _hello`" = ""; then
- CPP="$CPP -DNO_UNDERLINE"
- echo Checking for underline in external names... No.
- else
- echo Checking for underline in external names... Yes.
- fi ;;
-esac
-
-rm -f $test.[co] $test $test$shared_ext
-
-# udpate Makefile
-sed < Makefile.in "
-/^CC *=/s#=.*#=$CC#
-/^CFLAGS *=/s#=.*#=$CFLAGS#
-/^SFLAGS *=/s#=.*#=$SFLAGS#
-/^LDFLAGS *=/s#=.*#=$LDFLAGS#
-/^LDSHARED *=/s#=.*#=$LDSHARED#
-/^CPP *=/s#=.*#=$CPP#
-/^STATICLIB *=/s#=.*#=$STATICLIB#
-/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
-/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
-/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
-/^AR *=/s#=.*#=$AR_RC#
-/^RANLIB *=/s#=.*#=$RANLIB#
-/^EXE *=/s#=.*#=$EXE#
-/^prefix *=/s#=.*#=$prefix#
-/^exec_prefix *=/s#=.*#=$exec_prefix#
-/^libdir *=/s#=.*#=$libdir#
-/^includedir *=/s#=.*#=$includedir#
-/^mandir *=/s#=.*#=$mandir#
-/^all: */s#:.*#: $ALL#
-/^test: */s#:.*#: $TEST#
-" > Makefile
-
-sed < zlib.pc.in "
-/^CC *=/s#=.*#=$CC#
-/^CFLAGS *=/s#=.*#=$CFLAGS#
-/^CPP *=/s#=.*#=$CPP#
-/^LDSHARED *=/s#=.*#=$LDSHARED#
-/^STATICLIB *=/s#=.*#=$STATICLIB#
-/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
-/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
-/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
-/^AR *=/s#=.*#=$AR_RC#
-/^RANLIB *=/s#=.*#=$RANLIB#
-/^EXE *=/s#=.*#=$EXE#
-/^prefix *=/s#=.*#=$prefix#
-/^exec_prefix *=/s#=.*#=$exec_prefix#
-/^libdir *=/s#=.*#=$libdir#
-/^includedir *=/s#=.*#=$includedir#
-/^mandir *=/s#=.*#=$mandir#
-/^LDFLAGS *=/s#=.*#=$LDFLAGS#
-" | sed -e "
-s/\@VERSION\@/$VER/g;
-" > zlib.pc
diff --git a/cpukit/zlib/contrib/README.contrib b/cpukit/zlib/contrib/README.contrib
deleted file mode 100644
index dd2285d960..0000000000
--- a/cpukit/zlib/contrib/README.contrib
+++ /dev/null
@@ -1,77 +0,0 @@
-All files under this contrib directory are UNSUPPORTED. There were
-provided by users of zlib and were not tested by the authors of zlib.
-Use at your own risk. Please contact the authors of the contributions
-for help about these, not the zlib authors. Thanks.
-
-
-ada/ by Dmitriy Anisimkov <anisimkov@yahoo.com>
- Support for Ada
- See http://zlib-ada.sourceforge.net/
-
-amd64/ by Mikhail Teterin <mi@ALDAN.algebra.com>
- asm code for AMD64
- See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393
-
-asm686/ by Brian Raiter <breadbox@muppetlabs.com>
- asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax
- See http://www.muppetlabs.com/~breadbox/software/assembly.html
-
-blast/ by Mark Adler <madler@alumni.caltech.edu>
- Decompressor for output of PKWare Data Compression Library (DCL)
-
-delphi/ by Cosmin Truta <cosmint@cs.ubbcluj.ro>
- Support for Delphi and C++ Builder
-
-dotzlib/ by Henrik Ravn <henrik@ravn.com>
- Support for Microsoft .Net and Visual C++ .Net
-
-gcc_gvmat64/by Gilles Vollant <info@winimage.com>
- GCC Version of x86 64-bit (AMD64 and Intel EM64t) code for x64
- assembler to replace longest_match() and inflate_fast()
-
-infback9/ by Mark Adler <madler@alumni.caltech.edu>
- Unsupported diffs to infback to decode the deflate64 format
-
-inflate86/ by Chris Anderson <christop@charm.net>
- Tuned x86 gcc asm code to replace inflate_fast()
-
-iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
- A C++ I/O streams interface to the zlib gz* functions
-
-iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
- Another C++ I/O streams interface
-
-iostream3/ by Ludwig Schwardt <schwardt@sun.ac.za>
- and Kevin Ruland <kevin@rodin.wustl.edu>
- Yet another C++ I/O streams interface
-
-masmx64/ by Gilles Vollant <info@winimage.com>
- x86 64-bit (AMD64 and Intel EM64t) code for x64 assembler to
- replace longest_match() and inflate_fast(), also masm x86
- 64-bits translation of Chris Anderson inflate_fast()
-
-masmx86/ by Gilles Vollant <info@winimage.com>
- x86 asm code to replace longest_match() and inflate_fast(),
- for Visual C++ and MASM (32 bits).
- Based on Brian Raiter (asm686) and Chris Anderson (inflate86)
-
-minizip/ by Gilles Vollant <info@winimage.com>
- Mini zip and unzip based on zlib
- Includes Zip64 support by Mathias Svensson <mathias@result42.com>
- See http://www.winimage.com/zLibDll/unzip.html
-
-pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al.
- Support for Pascal
-
-puff/ by Mark Adler <madler@alumni.caltech.edu>
- Small, low memory usage inflate. Also serves to provide an
- unambiguous description of the deflate format.
-
-testzlib/ by Gilles Vollant <info@winimage.com>
- Example of the use of zlib
-
-untgz/ by Pedro A. Aranda Gutierrez <paag@tid.es>
- A very simple tar.gz file extractor using zlib
-
-vstudio/ by Gilles Vollant <info@winimage.com>
- Building a minizip-enhanced zlib with Microsoft Visual Studio
diff --git a/cpukit/zlib/contrib/ada/buffer_demo.adb b/cpukit/zlib/contrib/ada/buffer_demo.adb
deleted file mode 100644
index cd63fa48f8..0000000000
--- a/cpukit/zlib/contrib/ada/buffer_demo.adb
+++ /dev/null
@@ -1,106 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2004 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
---
--- $Id$
-
--- This demo program provided by Dr Steve Sangwine <sjs@essex.ac.uk>
---
--- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer
--- of exactly the correct size is used for decompressed data, and the last
--- few bytes passed in to Zlib are checksum bytes.
-
--- This program compresses a string of text, and then decompresses the
--- compressed text into a buffer of the same size as the original text.
-
-with Ada.Streams; use Ada.Streams;
-with Ada.Text_IO;
-
-with ZLib; use ZLib;
-
-procedure Buffer_Demo is
- EOL : Character renames ASCII.LF;
- Text : constant String
- := "Four score and seven years ago our fathers brought forth," & EOL &
- "upon this continent, a new nation, conceived in liberty," & EOL &
- "and dedicated to the proposition that `all men are created equal'.";
-
- Source : Stream_Element_Array (1 .. Text'Length);
- for Source'Address use Text'Address;
-
-begin
- Ada.Text_IO.Put (Text);
- Ada.Text_IO.New_Line;
- Ada.Text_IO.Put_Line
- ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes");
-
- declare
- Compressed_Data : Stream_Element_Array (1 .. Text'Length);
- L : Stream_Element_Offset;
- begin
- Compress : declare
- Compressor : Filter_Type;
- I : Stream_Element_Offset;
- begin
- Deflate_Init (Compressor);
-
- -- Compress the whole of T at once.
-
- Translate (Compressor, Source, I, Compressed_Data, L, Finish);
- pragma Assert (I = Source'Last);
-
- Close (Compressor);
-
- Ada.Text_IO.Put_Line
- ("Compressed size : "
- & Stream_Element_Offset'Image (L) & " bytes");
- end Compress;
-
- -- Now we decompress the data, passing short blocks of data to Zlib
- -- (because this demonstrates the problem - the last block passed will
- -- contain checksum information and there will be no output, only a
- -- check inside Zlib that the checksum is correct).
-
- Decompress : declare
- Decompressor : Filter_Type;
-
- Uncompressed_Data : Stream_Element_Array (1 .. Text'Length);
-
- Block_Size : constant := 4;
- -- This makes sure that the last block contains
- -- only Adler checksum data.
-
- P : Stream_Element_Offset := Compressed_Data'First - 1;
- O : Stream_Element_Offset;
- begin
- Inflate_Init (Decompressor);
-
- loop
- Translate
- (Decompressor,
- Compressed_Data
- (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)),
- P,
- Uncompressed_Data
- (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last),
- O,
- No_Flush);
-
- Ada.Text_IO.Put_Line
- ("Total in : " & Count'Image (Total_In (Decompressor)) &
- ", out : " & Count'Image (Total_Out (Decompressor)));
-
- exit when P = L;
- end loop;
-
- Ada.Text_IO.New_Line;
- Ada.Text_IO.Put_Line
- ("Decompressed text matches original text : "
- & Boolean'Image (Uncompressed_Data = Source));
- end Decompress;
- end;
-end Buffer_Demo;
diff --git a/cpukit/zlib/contrib/ada/mtest.adb b/cpukit/zlib/contrib/ada/mtest.adb
deleted file mode 100644
index 5f17228cd2..0000000000
--- a/cpukit/zlib/contrib/ada/mtest.adb
+++ /dev/null
@@ -1,156 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
--- Continuous test for ZLib multithreading. If the test would fail
--- we should provide thread safe allocation routines for the Z_Stream.
---
--- $Id$
-
-with ZLib;
-with Ada.Streams;
-with Ada.Numerics.Discrete_Random;
-with Ada.Text_IO;
-with Ada.Exceptions;
-with Ada.Task_Identification;
-
-procedure MTest is
- use Ada.Streams;
- use ZLib;
-
- Stop : Boolean := False;
-
- pragma Atomic (Stop);
-
- subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#;
-
- package Random_Elements is
- new Ada.Numerics.Discrete_Random (Visible_Symbols);
-
- task type Test_Task;
-
- task body Test_Task is
- Buffer : Stream_Element_Array (1 .. 100_000);
- Gen : Random_Elements.Generator;
-
- Buffer_First : Stream_Element_Offset;
- Compare_First : Stream_Element_Offset;
-
- Deflate : Filter_Type;
- Inflate : Filter_Type;
-
- procedure Further (Item : in Stream_Element_Array);
-
- procedure Read_Buffer
- (Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset);
-
- -------------
- -- Further --
- -------------
-
- procedure Further (Item : in Stream_Element_Array) is
-
- procedure Compare (Item : in Stream_Element_Array);
-
- -------------
- -- Compare --
- -------------
-
- procedure Compare (Item : in Stream_Element_Array) is
- Next_First : Stream_Element_Offset := Compare_First + Item'Length;
- begin
- if Buffer (Compare_First .. Next_First - 1) /= Item then
- raise Program_Error;
- end if;
-
- Compare_First := Next_First;
- end Compare;
-
- procedure Compare_Write is new ZLib.Write (Write => Compare);
- begin
- Compare_Write (Inflate, Item, No_Flush);
- end Further;
-
- -----------------
- -- Read_Buffer --
- -----------------
-
- procedure Read_Buffer
- (Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset)
- is
- Buff_Diff : Stream_Element_Offset := Buffer'Last - Buffer_First;
- Next_First : Stream_Element_Offset;
- begin
- if Item'Length <= Buff_Diff then
- Last := Item'Last;
-
- Next_First := Buffer_First + Item'Length;
-
- Item := Buffer (Buffer_First .. Next_First - 1);
-
- Buffer_First := Next_First;
- else
- Last := Item'First + Buff_Diff;
- Item (Item'First .. Last) := Buffer (Buffer_First .. Buffer'Last);
- Buffer_First := Buffer'Last + 1;
- end if;
- end Read_Buffer;
-
- procedure Translate is new Generic_Translate
- (Data_In => Read_Buffer,
- Data_Out => Further);
-
- begin
- Random_Elements.Reset (Gen);
-
- Buffer := (others => 20);
-
- Main : loop
- for J in Buffer'Range loop
- Buffer (J) := Random_Elements.Random (Gen);
-
- Deflate_Init (Deflate);
- Inflate_Init (Inflate);
-
- Buffer_First := Buffer'First;
- Compare_First := Buffer'First;
-
- Translate (Deflate);
-
- if Compare_First /= Buffer'Last + 1 then
- raise Program_Error;
- end if;
-
- Ada.Text_IO.Put_Line
- (Ada.Task_Identification.Image
- (Ada.Task_Identification.Current_Task)
- & Stream_Element_Offset'Image (J)
- & ZLib.Count'Image (Total_Out (Deflate)));
-
- Close (Deflate);
- Close (Inflate);
-
- exit Main when Stop;
- end loop;
- end loop Main;
- exception
- when E : others =>
- Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E));
- Stop := True;
- end Test_Task;
-
- Test : array (1 .. 4) of Test_Task;
-
- pragma Unreferenced (Test);
-
- Dummy : Character;
-
-begin
- Ada.Text_IO.Get_Immediate (Dummy);
- Stop := True;
-end MTest;
diff --git a/cpukit/zlib/contrib/ada/read.adb b/cpukit/zlib/contrib/ada/read.adb
deleted file mode 100644
index 00effd7209..0000000000
--- a/cpukit/zlib/contrib/ada/read.adb
+++ /dev/null
@@ -1,156 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
--- Test/demo program for the generic read interface.
-
-with Ada.Numerics.Discrete_Random;
-with Ada.Streams;
-with Ada.Text_IO;
-
-with ZLib;
-
-procedure Read is
-
- use Ada.Streams;
-
- ------------------------------------
- -- Test configuration parameters --
- ------------------------------------
-
- File_Size : Stream_Element_Offset := 100_000;
-
- Continuous : constant Boolean := False;
- -- If this constant is True, the test would be repeated again and again,
- -- with increment File_Size for every iteration.
-
- Header : constant ZLib.Header_Type := ZLib.Default;
- -- Do not use Header other than Default in ZLib versions 1.1.4 and older.
-
- Init_Random : constant := 8;
- -- We are using the same random sequence, in case of we catch bug,
- -- so we would be able to reproduce it.
-
- -- End --
-
- Pack_Size : Stream_Element_Offset;
- Offset : Stream_Element_Offset;
-
- Filter : ZLib.Filter_Type;
-
- subtype Visible_Symbols
- is Stream_Element range 16#20# .. 16#7E#;
-
- package Random_Elements is new
- Ada.Numerics.Discrete_Random (Visible_Symbols);
-
- Gen : Random_Elements.Generator;
- Period : constant Stream_Element_Offset := 200;
- -- Period constant variable for random generator not to be very random.
- -- Bigger period, harder random.
-
- Read_Buffer : Stream_Element_Array (1 .. 2048);
- Read_First : Stream_Element_Offset;
- Read_Last : Stream_Element_Offset;
-
- procedure Reset;
-
- procedure Read
- (Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset);
- -- this procedure is for generic instantiation of
- -- ZLib.Read
- -- reading data from the File_In.
-
- procedure Read is new ZLib.Read
- (Read,
- Read_Buffer,
- Rest_First => Read_First,
- Rest_Last => Read_Last);
-
- ----------
- -- Read --
- ----------
-
- procedure Read
- (Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset) is
- begin
- Last := Stream_Element_Offset'Min
- (Item'Last,
- Item'First + File_Size - Offset);
-
- for J in Item'First .. Last loop
- if J < Item'First + Period then
- Item (J) := Random_Elements.Random (Gen);
- else
- Item (J) := Item (J - Period);
- end if;
-
- Offset := Offset + 1;
- end loop;
- end Read;
-
- -----------
- -- Reset --
- -----------
-
- procedure Reset is
- begin
- Random_Elements.Reset (Gen, Init_Random);
- Pack_Size := 0;
- Offset := 1;
- Read_First := Read_Buffer'Last + 1;
- Read_Last := Read_Buffer'Last;
- end Reset;
-
-begin
- Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version);
-
- loop
- for Level in ZLib.Compression_Level'Range loop
-
- Ada.Text_IO.Put ("Level ="
- & ZLib.Compression_Level'Image (Level));
-
- -- Deflate using generic instantiation.
-
- ZLib.Deflate_Init
- (Filter,
- Level,
- Header => Header);
-
- Reset;
-
- Ada.Text_IO.Put
- (Stream_Element_Offset'Image (File_Size) & " ->");
-
- loop
- declare
- Buffer : Stream_Element_Array (1 .. 1024);
- Last : Stream_Element_Offset;
- begin
- Read (Filter, Buffer, Last);
-
- Pack_Size := Pack_Size + Last - Buffer'First + 1;
-
- exit when Last < Buffer'Last;
- end;
- end loop;
-
- Ada.Text_IO.Put_Line (Stream_Element_Offset'Image (Pack_Size));
-
- ZLib.Close (Filter);
- end loop;
-
- exit when not Continuous;
-
- File_Size := File_Size + 1;
- end loop;
-end Read;
diff --git a/cpukit/zlib/contrib/ada/readme.txt b/cpukit/zlib/contrib/ada/readme.txt
deleted file mode 100644
index ce4d2cadf0..0000000000
--- a/cpukit/zlib/contrib/ada/readme.txt
+++ /dev/null
@@ -1,65 +0,0 @@
- ZLib for Ada thick binding (ZLib.Ada)
- Release 1.3
-
-ZLib.Ada is a thick binding interface to the popular ZLib data
-compression library, available at http://www.gzip.org/zlib/.
-It provides Ada-style access to the ZLib C library.
-
-
- Here are the main changes since ZLib.Ada 1.2:
-
-- Attension: ZLib.Read generic routine have a initialization requirement
- for Read_Last parameter now. It is a bit incompartible with previous version,
- but extends functionality, we could use new parameters Allow_Read_Some and
- Flush now.
-
-- Added Is_Open routines to ZLib and ZLib.Streams packages.
-
-- Add pragma Assert to check Stream_Element is 8 bit.
-
-- Fix extraction to buffer with exact known decompressed size. Error reported by
- Steve Sangwine.
-
-- Fix definition of ULong (changed to unsigned_long), fix regression on 64 bits
- computers. Patch provided by Pascal Obry.
-
-- Add Status_Error exception definition.
-
-- Add pragma Assertion that Ada.Streams.Stream_Element size is 8 bit.
-
-
- How to build ZLib.Ada under GNAT
-
-You should have the ZLib library already build on your computer, before
-building ZLib.Ada. Make the directory of ZLib.Ada sources current and
-issue the command:
-
- gnatmake test -largs -L<directory where libz.a is> -lz
-
-Or use the GNAT project file build for GNAT 3.15 or later:
-
- gnatmake -Pzlib.gpr -L<directory where libz.a is>
-
-
- How to build ZLib.Ada under Aonix ObjectAda for Win32 7.2.2
-
-1. Make a project with all *.ads and *.adb files from the distribution.
-2. Build the libz.a library from the ZLib C sources.
-3. Rename libz.a to z.lib.
-4. Add the library z.lib to the project.
-5. Add the libc.lib library from the ObjectAda distribution to the project.
-6. Build the executable using test.adb as a main procedure.
-
-
- How to use ZLib.Ada
-
-The source files test.adb and read.adb are small demo programs that show
-the main functionality of ZLib.Ada.
-
-The routines from the package specifications are commented.
-
-
-Homepage: http://zlib-ada.sourceforge.net/
-Author: Dmitriy Anisimkov <anisimkov@yahoo.com>
-
-Contributors: Pascal Obry <pascal@obry.org>, Steve Sangwine <sjs@essex.ac.uk>
diff --git a/cpukit/zlib/contrib/ada/test.adb b/cpukit/zlib/contrib/ada/test.adb
deleted file mode 100644
index 8444647144..0000000000
--- a/cpukit/zlib/contrib/ada/test.adb
+++ /dev/null
@@ -1,463 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
--- The program has a few aims.
--- 1. Test ZLib.Ada95 thick binding functionality.
--- 2. Show the example of use main functionality of the ZLib.Ada95 binding.
--- 3. Build this program automatically compile all ZLib.Ada95 packages under
--- GNAT Ada95 compiler.
-
-with ZLib.Streams;
-with Ada.Streams.Stream_IO;
-with Ada.Numerics.Discrete_Random;
-
-with Ada.Text_IO;
-
-with Ada.Calendar;
-
-procedure Test is
-
- use Ada.Streams;
- use Stream_IO;
-
- ------------------------------------
- -- Test configuration parameters --
- ------------------------------------
-
- File_Size : Count := 100_000;
- Continuous : constant Boolean := False;
-
- Header : constant ZLib.Header_Type := ZLib.Default;
- -- ZLib.None;
- -- ZLib.Auto;
- -- ZLib.GZip;
- -- Do not use Header other then Default in ZLib versions 1.1.4
- -- and older.
-
- Strategy : constant ZLib.Strategy_Type := ZLib.Default_Strategy;
- Init_Random : constant := 10;
-
- -- End --
-
- In_File_Name : constant String := "testzlib.in";
- -- Name of the input file
-
- Z_File_Name : constant String := "testzlib.zlb";
- -- Name of the compressed file.
-
- Out_File_Name : constant String := "testzlib.out";
- -- Name of the decompressed file.
-
- File_In : File_Type;
- File_Out : File_Type;
- File_Back : File_Type;
- File_Z : ZLib.Streams.Stream_Type;
-
- Filter : ZLib.Filter_Type;
-
- Time_Stamp : Ada.Calendar.Time;
-
- procedure Generate_File;
- -- Generate file of spetsified size with some random data.
- -- The random data is repeatable, for the good compression.
-
- procedure Compare_Streams
- (Left, Right : in out Root_Stream_Type'Class);
- -- The procedure compearing data in 2 streams.
- -- It is for compare data before and after compression/decompression.
-
- procedure Compare_Files (Left, Right : String);
- -- Compare files. Based on the Compare_Streams.
-
- procedure Copy_Streams
- (Source, Target : in out Root_Stream_Type'Class;
- Buffer_Size : in Stream_Element_Offset := 1024);
- -- Copying data from one stream to another. It is for test stream
- -- interface of the library.
-
- procedure Data_In
- (Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset);
- -- this procedure is for generic instantiation of
- -- ZLib.Generic_Translate.
- -- reading data from the File_In.
-
- procedure Data_Out (Item : in Stream_Element_Array);
- -- this procedure is for generic instantiation of
- -- ZLib.Generic_Translate.
- -- writing data to the File_Out.
-
- procedure Stamp;
- -- Store the timestamp to the local variable.
-
- procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count);
- -- Print the time statistic with the message.
-
- procedure Translate is new ZLib.Generic_Translate
- (Data_In => Data_In,
- Data_Out => Data_Out);
- -- This procedure is moving data from File_In to File_Out
- -- with compression or decompression, depend on initialization of
- -- Filter parameter.
-
- -------------------
- -- Compare_Files --
- -------------------
-
- procedure Compare_Files (Left, Right : String) is
- Left_File, Right_File : File_Type;
- begin
- Open (Left_File, In_File, Left);
- Open (Right_File, In_File, Right);
- Compare_Streams (Stream (Left_File).all, Stream (Right_File).all);
- Close (Left_File);
- Close (Right_File);
- end Compare_Files;
-
- ---------------------
- -- Compare_Streams --
- ---------------------
-
- procedure Compare_Streams
- (Left, Right : in out Ada.Streams.Root_Stream_Type'Class)
- is
- Left_Buffer, Right_Buffer : Stream_Element_Array (0 .. 16#FFF#);
- Left_Last, Right_Last : Stream_Element_Offset;
- begin
- loop
- Read (Left, Left_Buffer, Left_Last);
- Read (Right, Right_Buffer, Right_Last);
-
- if Left_Last /= Right_Last then
- Ada.Text_IO.Put_Line ("Compare error :"
- & Stream_Element_Offset'Image (Left_Last)
- & " /= "
- & Stream_Element_Offset'Image (Right_Last));
-
- raise Constraint_Error;
-
- elsif Left_Buffer (0 .. Left_Last)
- /= Right_Buffer (0 .. Right_Last)
- then
- Ada.Text_IO.Put_Line ("ERROR: IN and OUT files is not equal.");
- raise Constraint_Error;
-
- end if;
-
- exit when Left_Last < Left_Buffer'Last;
- end loop;
- end Compare_Streams;
-
- ------------------
- -- Copy_Streams --
- ------------------
-
- procedure Copy_Streams
- (Source, Target : in out Ada.Streams.Root_Stream_Type'Class;
- Buffer_Size : in Stream_Element_Offset := 1024)
- is
- Buffer : Stream_Element_Array (1 .. Buffer_Size);
- Last : Stream_Element_Offset;
- begin
- loop
- Read (Source, Buffer, Last);
- Write (Target, Buffer (1 .. Last));
-
- exit when Last < Buffer'Last;
- end loop;
- end Copy_Streams;
-
- -------------
- -- Data_In --
- -------------
-
- procedure Data_In
- (Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset) is
- begin
- Read (File_In, Item, Last);
- end Data_In;
-
- --------------
- -- Data_Out --
- --------------
-
- procedure Data_Out (Item : in Stream_Element_Array) is
- begin
- Write (File_Out, Item);
- end Data_Out;
-
- -------------------
- -- Generate_File --
- -------------------
-
- procedure Generate_File is
- subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#;
-
- package Random_Elements is
- new Ada.Numerics.Discrete_Random (Visible_Symbols);
-
- Gen : Random_Elements.Generator;
- Buffer : Stream_Element_Array := (1 .. 77 => 16#20#) & 10;
-
- Buffer_Count : constant Count := File_Size / Buffer'Length;
- -- Number of same buffers in the packet.
-
- Density : constant Count := 30; -- from 0 to Buffer'Length - 2;
-
- procedure Fill_Buffer (J, D : in Count);
- -- Change the part of the buffer.
-
- -----------------
- -- Fill_Buffer --
- -----------------
-
- procedure Fill_Buffer (J, D : in Count) is
- begin
- for K in 0 .. D loop
- Buffer
- (Stream_Element_Offset ((J + K) mod (Buffer'Length - 1) + 1))
- := Random_Elements.Random (Gen);
-
- end loop;
- end Fill_Buffer;
-
- begin
- Random_Elements.Reset (Gen, Init_Random);
-
- Create (File_In, Out_File, In_File_Name);
-
- Fill_Buffer (1, Buffer'Length - 2);
-
- for J in 1 .. Buffer_Count loop
- Write (File_In, Buffer);
-
- Fill_Buffer (J, Density);
- end loop;
-
- -- fill remain size.
-
- Write
- (File_In,
- Buffer
- (1 .. Stream_Element_Offset
- (File_Size - Buffer'Length * Buffer_Count)));
-
- Flush (File_In);
- Close (File_In);
- end Generate_File;
-
- ---------------------
- -- Print_Statistic --
- ---------------------
-
- procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count) is
- use Ada.Calendar;
- use Ada.Text_IO;
-
- package Count_IO is new Integer_IO (ZLib.Count);
-
- Curr_Dur : Duration := Clock - Time_Stamp;
- begin
- Put (Msg);
-
- Set_Col (20);
- Ada.Text_IO.Put ("size =");
-
- Count_IO.Put
- (Data_Size,
- Width => Stream_IO.Count'Image (File_Size)'Length);
-
- Put_Line (" duration =" & Duration'Image (Curr_Dur));
- end Print_Statistic;
-
- -----------
- -- Stamp --
- -----------
-
- procedure Stamp is
- begin
- Time_Stamp := Ada.Calendar.Clock;
- end Stamp;
-
-begin
- Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version);
-
- loop
- Generate_File;
-
- for Level in ZLib.Compression_Level'Range loop
-
- Ada.Text_IO.Put_Line ("Level ="
- & ZLib.Compression_Level'Image (Level));
-
- -- Test generic interface.
- Open (File_In, In_File, In_File_Name);
- Create (File_Out, Out_File, Z_File_Name);
-
- Stamp;
-
- -- Deflate using generic instantiation.
-
- ZLib.Deflate_Init
- (Filter => Filter,
- Level => Level,
- Strategy => Strategy,
- Header => Header);
-
- Translate (Filter);
- Print_Statistic ("Generic compress", ZLib.Total_Out (Filter));
- ZLib.Close (Filter);
-
- Close (File_In);
- Close (File_Out);
-
- Open (File_In, In_File, Z_File_Name);
- Create (File_Out, Out_File, Out_File_Name);
-
- Stamp;
-
- -- Inflate using generic instantiation.
-
- ZLib.Inflate_Init (Filter, Header => Header);
-
- Translate (Filter);
- Print_Statistic ("Generic decompress", ZLib.Total_Out (Filter));
-
- ZLib.Close (Filter);
-
- Close (File_In);
- Close (File_Out);
-
- Compare_Files (In_File_Name, Out_File_Name);
-
- -- Test stream interface.
-
- -- Compress to the back stream.
-
- Open (File_In, In_File, In_File_Name);
- Create (File_Back, Out_File, Z_File_Name);
-
- Stamp;
-
- ZLib.Streams.Create
- (Stream => File_Z,
- Mode => ZLib.Streams.Out_Stream,
- Back => ZLib.Streams.Stream_Access
- (Stream (File_Back)),
- Back_Compressed => True,
- Level => Level,
- Strategy => Strategy,
- Header => Header);
-
- Copy_Streams
- (Source => Stream (File_In).all,
- Target => File_Z);
-
- -- Flushing internal buffers to the back stream.
-
- ZLib.Streams.Flush (File_Z, ZLib.Finish);
-
- Print_Statistic ("Write compress",
- ZLib.Streams.Write_Total_Out (File_Z));
-
- ZLib.Streams.Close (File_Z);
-
- Close (File_In);
- Close (File_Back);
-
- -- Compare reading from original file and from
- -- decompression stream.
-
- Open (File_In, In_File, In_File_Name);
- Open (File_Back, In_File, Z_File_Name);
-
- ZLib.Streams.Create
- (Stream => File_Z,
- Mode => ZLib.Streams.In_Stream,
- Back => ZLib.Streams.Stream_Access
- (Stream (File_Back)),
- Back_Compressed => True,
- Header => Header);
-
- Stamp;
- Compare_Streams (Stream (File_In).all, File_Z);
-
- Print_Statistic ("Read decompress",
- ZLib.Streams.Read_Total_Out (File_Z));
-
- ZLib.Streams.Close (File_Z);
- Close (File_In);
- Close (File_Back);
-
- -- Compress by reading from compression stream.
-
- Open (File_Back, In_File, In_File_Name);
- Create (File_Out, Out_File, Z_File_Name);
-
- ZLib.Streams.Create
- (Stream => File_Z,
- Mode => ZLib.Streams.In_Stream,
- Back => ZLib.Streams.Stream_Access
- (Stream (File_Back)),
- Back_Compressed => False,
- Level => Level,
- Strategy => Strategy,
- Header => Header);
-
- Stamp;
- Copy_Streams
- (Source => File_Z,
- Target => Stream (File_Out).all);
-
- Print_Statistic ("Read compress",
- ZLib.Streams.Read_Total_Out (File_Z));
-
- ZLib.Streams.Close (File_Z);
-
- Close (File_Out);
- Close (File_Back);
-
- -- Decompress to decompression stream.
-
- Open (File_In, In_File, Z_File_Name);
- Create (File_Back, Out_File, Out_File_Name);
-
- ZLib.Streams.Create
- (Stream => File_Z,
- Mode => ZLib.Streams.Out_Stream,
- Back => ZLib.Streams.Stream_Access
- (Stream (File_Back)),
- Back_Compressed => False,
- Header => Header);
-
- Stamp;
-
- Copy_Streams
- (Source => Stream (File_In).all,
- Target => File_Z);
-
- Print_Statistic ("Write decompress",
- ZLib.Streams.Write_Total_Out (File_Z));
-
- ZLib.Streams.Close (File_Z);
- Close (File_In);
- Close (File_Back);
-
- Compare_Files (In_File_Name, Out_File_Name);
- end loop;
-
- Ada.Text_IO.Put_Line (Count'Image (File_Size) & " Ok.");
-
- exit when not Continuous;
-
- File_Size := File_Size + 1;
- end loop;
-end Test;
diff --git a/cpukit/zlib/contrib/ada/zlib-streams.adb b/cpukit/zlib/contrib/ada/zlib-streams.adb
deleted file mode 100644
index 10a4732959..0000000000
--- a/cpukit/zlib/contrib/ada/zlib-streams.adb
+++ /dev/null
@@ -1,225 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
-with Ada.Unchecked_Deallocation;
-
-package body ZLib.Streams is
-
- -----------
- -- Close --
- -----------
-
- procedure Close (Stream : in out Stream_Type) is
- procedure Free is new Ada.Unchecked_Deallocation
- (Stream_Element_Array, Buffer_Access);
- begin
- if Stream.Mode = Out_Stream or Stream.Mode = Duplex then
- -- We should flush the data written by the writer.
-
- Flush (Stream, Finish);
-
- Close (Stream.Writer);
- end if;
-
- if Stream.Mode = In_Stream or Stream.Mode = Duplex then
- Close (Stream.Reader);
- Free (Stream.Buffer);
- end if;
- end Close;
-
- ------------
- -- Create --
- ------------
-
- procedure Create
- (Stream : out Stream_Type;
- Mode : in Stream_Mode;
- Back : in Stream_Access;
- Back_Compressed : in Boolean;
- Level : in Compression_Level := Default_Compression;
- Strategy : in Strategy_Type := Default_Strategy;
- Header : in Header_Type := Default;
- Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset
- := Default_Buffer_Size;
- Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset
- := Default_Buffer_Size)
- is
-
- subtype Buffer_Subtype is Stream_Element_Array (1 .. Read_Buffer_Size);
-
- procedure Init_Filter
- (Filter : in out Filter_Type;
- Compress : in Boolean);
-
- -----------------
- -- Init_Filter --
- -----------------
-
- procedure Init_Filter
- (Filter : in out Filter_Type;
- Compress : in Boolean) is
- begin
- if Compress then
- Deflate_Init
- (Filter, Level, Strategy, Header => Header);
- else
- Inflate_Init (Filter, Header => Header);
- end if;
- end Init_Filter;
-
- begin
- Stream.Back := Back;
- Stream.Mode := Mode;
-
- if Mode = Out_Stream or Mode = Duplex then
- Init_Filter (Stream.Writer, Back_Compressed);
- Stream.Buffer_Size := Write_Buffer_Size;
- else
- Stream.Buffer_Size := 0;
- end if;
-
- if Mode = In_Stream or Mode = Duplex then
- Init_Filter (Stream.Reader, not Back_Compressed);
-
- Stream.Buffer := new Buffer_Subtype;
- Stream.Rest_First := Stream.Buffer'Last + 1;
- Stream.Rest_Last := Stream.Buffer'Last;
- end if;
- end Create;
-
- -----------
- -- Flush --
- -----------
-
- procedure Flush
- (Stream : in out Stream_Type;
- Mode : in Flush_Mode := Sync_Flush)
- is
- Buffer : Stream_Element_Array (1 .. Stream.Buffer_Size);
- Last : Stream_Element_Offset;
- begin
- loop
- Flush (Stream.Writer, Buffer, Last, Mode);
-
- Ada.Streams.Write (Stream.Back.all, Buffer (1 .. Last));
-
- exit when Last < Buffer'Last;
- end loop;
- end Flush;
-
- -------------
- -- Is_Open --
- -------------
-
- function Is_Open (Stream : Stream_Type) return Boolean is
- begin
- return Is_Open (Stream.Reader) or else Is_Open (Stream.Writer);
- end Is_Open;
-
- ----------
- -- Read --
- ----------
-
- procedure Read
- (Stream : in out Stream_Type;
- Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset)
- is
-
- procedure Read
- (Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset);
-
- ----------
- -- Read --
- ----------
-
- procedure Read
- (Item : out Stream_Element_Array;
- Last : out Stream_Element_Offset) is
- begin
- Ada.Streams.Read (Stream.Back.all, Item, Last);
- end Read;
-
- procedure Read is new ZLib.Read
- (Read => Read,
- Buffer => Stream.Buffer.all,
- Rest_First => Stream.Rest_First,
- Rest_Last => Stream.Rest_Last);
-
- begin
- Read (Stream.Reader, Item, Last);
- end Read;
-
- -------------------
- -- Read_Total_In --
- -------------------
-
- function Read_Total_In (Stream : in Stream_Type) return Count is
- begin
- return Total_In (Stream.Reader);
- end Read_Total_In;
-
- --------------------
- -- Read_Total_Out --
- --------------------
-
- function Read_Total_Out (Stream : in Stream_Type) return Count is
- begin
- return Total_Out (Stream.Reader);
- end Read_Total_Out;
-
- -----------
- -- Write --
- -----------
-
- procedure Write
- (Stream : in out Stream_Type;
- Item : in Stream_Element_Array)
- is
-
- procedure Write (Item : in Stream_Element_Array);
-
- -----------
- -- Write --
- -----------
-
- procedure Write (Item : in Stream_Element_Array) is
- begin
- Ada.Streams.Write (Stream.Back.all, Item);
- end Write;
-
- procedure Write is new ZLib.Write
- (Write => Write,
- Buffer_Size => Stream.Buffer_Size);
-
- begin
- Write (Stream.Writer, Item, No_Flush);
- end Write;
-
- --------------------
- -- Write_Total_In --
- --------------------
-
- function Write_Total_In (Stream : in Stream_Type) return Count is
- begin
- return Total_In (Stream.Writer);
- end Write_Total_In;
-
- ---------------------
- -- Write_Total_Out --
- ---------------------
-
- function Write_Total_Out (Stream : in Stream_Type) return Count is
- begin
- return Total_Out (Stream.Writer);
- end Write_Total_Out;
-
-end ZLib.Streams;
diff --git a/cpukit/zlib/contrib/ada/zlib-streams.ads b/cpukit/zlib/contrib/ada/zlib-streams.ads
deleted file mode 100644
index 7dcbf7e8b6..0000000000
--- a/cpukit/zlib/contrib/ada/zlib-streams.ads
+++ /dev/null
@@ -1,114 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
-package ZLib.Streams is
-
- type Stream_Mode is (In_Stream, Out_Stream, Duplex);
-
- type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
-
- type Stream_Type is
- new Ada.Streams.Root_Stream_Type with private;
-
- procedure Read
- (Stream : in out Stream_Type;
- Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset);
-
- procedure Write
- (Stream : in out Stream_Type;
- Item : in Ada.Streams.Stream_Element_Array);
-
- procedure Flush
- (Stream : in out Stream_Type;
- Mode : in Flush_Mode := Sync_Flush);
- -- Flush the written data to the back stream,
- -- all data placed to the compressor is flushing to the Back stream.
- -- Should not be used untill necessary, becouse it is decreasing
- -- compression.
-
- function Read_Total_In (Stream : in Stream_Type) return Count;
- pragma Inline (Read_Total_In);
- -- Return total number of bytes read from back stream so far.
-
- function Read_Total_Out (Stream : in Stream_Type) return Count;
- pragma Inline (Read_Total_Out);
- -- Return total number of bytes read so far.
-
- function Write_Total_In (Stream : in Stream_Type) return Count;
- pragma Inline (Write_Total_In);
- -- Return total number of bytes written so far.
-
- function Write_Total_Out (Stream : in Stream_Type) return Count;
- pragma Inline (Write_Total_Out);
- -- Return total number of bytes written to the back stream.
-
- procedure Create
- (Stream : out Stream_Type;
- Mode : in Stream_Mode;
- Back : in Stream_Access;
- Back_Compressed : in Boolean;
- Level : in Compression_Level := Default_Compression;
- Strategy : in Strategy_Type := Default_Strategy;
- Header : in Header_Type := Default;
- Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset
- := Default_Buffer_Size;
- Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset
- := Default_Buffer_Size);
- -- Create the Comression/Decompression stream.
- -- If mode is In_Stream then Write operation is disabled.
- -- If mode is Out_Stream then Read operation is disabled.
-
- -- If Back_Compressed is true then
- -- Data written to the Stream is compressing to the Back stream
- -- and data read from the Stream is decompressed data from the Back stream.
-
- -- If Back_Compressed is false then
- -- Data written to the Stream is decompressing to the Back stream
- -- and data read from the Stream is compressed data from the Back stream.
-
- -- !!! When the Need_Header is False ZLib-Ada is using undocumented
- -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers.
-
- function Is_Open (Stream : Stream_Type) return Boolean;
-
- procedure Close (Stream : in out Stream_Type);
-
-private
-
- use Ada.Streams;
-
- type Buffer_Access is access all Stream_Element_Array;
-
- type Stream_Type
- is new Root_Stream_Type with
- record
- Mode : Stream_Mode;
-
- Buffer : Buffer_Access;
- Rest_First : Stream_Element_Offset;
- Rest_Last : Stream_Element_Offset;
- -- Buffer for Read operation.
- -- We need to have this buffer in the record
- -- becouse not all read data from back stream
- -- could be processed during the read operation.
-
- Buffer_Size : Stream_Element_Offset;
- -- Buffer size for write operation.
- -- We do not need to have this buffer
- -- in the record becouse all data could be
- -- processed in the write operation.
-
- Back : Stream_Access;
- Reader : Filter_Type;
- Writer : Filter_Type;
- end record;
-
-end ZLib.Streams;
diff --git a/cpukit/zlib/contrib/ada/zlib-thin.adb b/cpukit/zlib/contrib/ada/zlib-thin.adb
deleted file mode 100644
index 30924ed7ab..0000000000
--- a/cpukit/zlib/contrib/ada/zlib-thin.adb
+++ /dev/null
@@ -1,141 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
-package body ZLib.Thin is
-
- ZLIB_VERSION : constant Chars_Ptr := zlibVersion;
-
- Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit;
-
- --------------
- -- Avail_In --
- --------------
-
- function Avail_In (Strm : in Z_Stream) return UInt is
- begin
- return Strm.Avail_In;
- end Avail_In;
-
- ---------------
- -- Avail_Out --
- ---------------
-
- function Avail_Out (Strm : in Z_Stream) return UInt is
- begin
- return Strm.Avail_Out;
- end Avail_Out;
-
- ------------------
- -- Deflate_Init --
- ------------------
-
- function Deflate_Init
- (strm : Z_Streamp;
- level : Int;
- method : Int;
- windowBits : Int;
- memLevel : Int;
- strategy : Int)
- return Int is
- begin
- return deflateInit2
- (strm,
- level,
- method,
- windowBits,
- memLevel,
- strategy,
- ZLIB_VERSION,
- Z_Stream_Size);
- end Deflate_Init;
-
- ------------------
- -- Inflate_Init --
- ------------------
-
- function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is
- begin
- return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size);
- end Inflate_Init;
-
- ------------------------
- -- Last_Error_Message --
- ------------------------
-
- function Last_Error_Message (Strm : in Z_Stream) return String is
- use Interfaces.C.Strings;
- begin
- if Strm.msg = Null_Ptr then
- return "";
- else
- return Value (Strm.msg);
- end if;
- end Last_Error_Message;
-
- ------------
- -- Set_In --
- ------------
-
- procedure Set_In
- (Strm : in out Z_Stream;
- Buffer : in Voidp;
- Size : in UInt) is
- begin
- Strm.Next_In := Buffer;
- Strm.Avail_In := Size;
- end Set_In;
-
- ------------------
- -- Set_Mem_Func --
- ------------------
-
- procedure Set_Mem_Func
- (Strm : in out Z_Stream;
- Opaque : in Voidp;
- Alloc : in alloc_func;
- Free : in free_func) is
- begin
- Strm.opaque := Opaque;
- Strm.zalloc := Alloc;
- Strm.zfree := Free;
- end Set_Mem_Func;
-
- -------------
- -- Set_Out --
- -------------
-
- procedure Set_Out
- (Strm : in out Z_Stream;
- Buffer : in Voidp;
- Size : in UInt) is
- begin
- Strm.Next_Out := Buffer;
- Strm.Avail_Out := Size;
- end Set_Out;
-
- --------------
- -- Total_In --
- --------------
-
- function Total_In (Strm : in Z_Stream) return ULong is
- begin
- return Strm.Total_In;
- end Total_In;
-
- ---------------
- -- Total_Out --
- ---------------
-
- function Total_Out (Strm : in Z_Stream) return ULong is
- begin
- return Strm.Total_Out;
- end Total_Out;
-
-end ZLib.Thin;
diff --git a/cpukit/zlib/contrib/ada/zlib-thin.ads b/cpukit/zlib/contrib/ada/zlib-thin.ads
deleted file mode 100644
index 2bc085f0aa..0000000000
--- a/cpukit/zlib/contrib/ada/zlib-thin.ads
+++ /dev/null
@@ -1,450 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2003 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
-with Interfaces.C.Strings;
-
-with System;
-
-private package ZLib.Thin is
-
- -- From zconf.h
-
- MAX_MEM_LEVEL : constant := 9; -- zconf.h:105
- -- zconf.h:105
- MAX_WBITS : constant := 15; -- zconf.h:115
- -- 32K LZ77 window
- -- zconf.h:115
- SEEK_SET : constant := 8#0000#; -- zconf.h:244
- -- Seek from beginning of file.
- -- zconf.h:244
- SEEK_CUR : constant := 1; -- zconf.h:245
- -- Seek from current position.
- -- zconf.h:245
- SEEK_END : constant := 2; -- zconf.h:246
- -- Set file pointer to EOF plus "offset"
- -- zconf.h:246
-
- type Byte is new Interfaces.C.unsigned_char; -- 8 bits
- -- zconf.h:214
- type UInt is new Interfaces.C.unsigned; -- 16 bits or more
- -- zconf.h:216
- type Int is new Interfaces.C.int;
-
- type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more
- -- zconf.h:217
- subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr;
-
- type ULong_Access is access ULong;
- type Int_Access is access Int;
-
- subtype Voidp is System.Address; -- zconf.h:232
-
- subtype Byte_Access is Voidp;
-
- Nul : constant Voidp := System.Null_Address;
- -- end from zconf
-
- Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125
- -- zlib.h:125
- Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126
- -- will be removed, use
- -- Z_SYNC_FLUSH instead
- -- zlib.h:126
- Z_SYNC_FLUSH : constant := 2; -- zlib.h:127
- -- zlib.h:127
- Z_FULL_FLUSH : constant := 3; -- zlib.h:128
- -- zlib.h:128
- Z_FINISH : constant := 4; -- zlib.h:129
- -- zlib.h:129
- Z_OK : constant := 8#0000#; -- zlib.h:132
- -- zlib.h:132
- Z_STREAM_END : constant := 1; -- zlib.h:133
- -- zlib.h:133
- Z_NEED_DICT : constant := 2; -- zlib.h:134
- -- zlib.h:134
- Z_ERRNO : constant := -1; -- zlib.h:135
- -- zlib.h:135
- Z_STREAM_ERROR : constant := -2; -- zlib.h:136
- -- zlib.h:136
- Z_DATA_ERROR : constant := -3; -- zlib.h:137
- -- zlib.h:137
- Z_MEM_ERROR : constant := -4; -- zlib.h:138
- -- zlib.h:138
- Z_BUF_ERROR : constant := -5; -- zlib.h:139
- -- zlib.h:139
- Z_VERSION_ERROR : constant := -6; -- zlib.h:140
- -- zlib.h:140
- Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145
- -- zlib.h:145
- Z_BEST_SPEED : constant := 1; -- zlib.h:146
- -- zlib.h:146
- Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147
- -- zlib.h:147
- Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148
- -- zlib.h:148
- Z_FILTERED : constant := 1; -- zlib.h:151
- -- zlib.h:151
- Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152
- -- zlib.h:152
- Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153
- -- zlib.h:153
- Z_BINARY : constant := 8#0000#; -- zlib.h:156
- -- zlib.h:156
- Z_ASCII : constant := 1; -- zlib.h:157
- -- zlib.h:157
- Z_UNKNOWN : constant := 2; -- zlib.h:158
- -- zlib.h:158
- Z_DEFLATED : constant := 8; -- zlib.h:161
- -- zlib.h:161
- Z_NULL : constant := 8#0000#; -- zlib.h:164
- -- for initializing zalloc, zfree, opaque
- -- zlib.h:164
- type gzFile is new Voidp; -- zlib.h:646
-
- type Z_Stream is private;
-
- type Z_Streamp is access all Z_Stream; -- zlib.h:89
-
- type alloc_func is access function
- (Opaque : Voidp;
- Items : UInt;
- Size : UInt)
- return Voidp; -- zlib.h:63
-
- type free_func is access procedure (opaque : Voidp; address : Voidp);
-
- function zlibVersion return Chars_Ptr;
-
- function Deflate (strm : Z_Streamp; flush : Int) return Int;
-
- function DeflateEnd (strm : Z_Streamp) return Int;
-
- function Inflate (strm : Z_Streamp; flush : Int) return Int;
-
- function InflateEnd (strm : Z_Streamp) return Int;
-
- function deflateSetDictionary
- (strm : Z_Streamp;
- dictionary : Byte_Access;
- dictLength : UInt)
- return Int;
-
- function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int;
- -- zlib.h:478
-
- function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495
-
- function deflateParams
- (strm : Z_Streamp;
- level : Int;
- strategy : Int)
- return Int; -- zlib.h:506
-
- function inflateSetDictionary
- (strm : Z_Streamp;
- dictionary : Byte_Access;
- dictLength : UInt)
- return Int; -- zlib.h:548
-
- function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565
-
- function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580
-
- function compress
- (dest : Byte_Access;
- destLen : ULong_Access;
- source : Byte_Access;
- sourceLen : ULong)
- return Int; -- zlib.h:601
-
- function compress2
- (dest : Byte_Access;
- destLen : ULong_Access;
- source : Byte_Access;
- sourceLen : ULong;
- level : Int)
- return Int; -- zlib.h:615
-
- function uncompress
- (dest : Byte_Access;
- destLen : ULong_Access;
- source : Byte_Access;
- sourceLen : ULong)
- return Int;
-
- function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile;
-
- function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile;
-
- function gzsetparams
- (file : gzFile;
- level : Int;
- strategy : Int)
- return Int;
-
- function gzread
- (file : gzFile;
- buf : Voidp;
- len : UInt)
- return Int;
-
- function gzwrite
- (file : in gzFile;
- buf : in Voidp;
- len : in UInt)
- return Int;
-
- function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int;
-
- function gzputs (file : in gzFile; s : in Chars_Ptr) return Int;
-
- function gzgets
- (file : gzFile;
- buf : Chars_Ptr;
- len : Int)
- return Chars_Ptr;
-
- function gzputc (file : gzFile; char : Int) return Int;
-
- function gzgetc (file : gzFile) return Int;
-
- function gzflush (file : gzFile; flush : Int) return Int;
-
- function gzseek
- (file : gzFile;
- offset : Int;
- whence : Int)
- return Int;
-
- function gzrewind (file : gzFile) return Int;
-
- function gztell (file : gzFile) return Int;
-
- function gzeof (file : gzFile) return Int;
-
- function gzclose (file : gzFile) return Int;
-
- function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr;
-
- function adler32
- (adler : ULong;
- buf : Byte_Access;
- len : UInt)
- return ULong;
-
- function crc32
- (crc : ULong;
- buf : Byte_Access;
- len : UInt)
- return ULong;
-
- function deflateInit
- (strm : Z_Streamp;
- level : Int;
- version : Chars_Ptr;
- stream_size : Int)
- return Int;
-
- function deflateInit2
- (strm : Z_Streamp;
- level : Int;
- method : Int;
- windowBits : Int;
- memLevel : Int;
- strategy : Int;
- version : Chars_Ptr;
- stream_size : Int)
- return Int;
-
- function Deflate_Init
- (strm : Z_Streamp;
- level : Int;
- method : Int;
- windowBits : Int;
- memLevel : Int;
- strategy : Int)
- return Int;
- pragma Inline (Deflate_Init);
-
- function inflateInit
- (strm : Z_Streamp;
- version : Chars_Ptr;
- stream_size : Int)
- return Int;
-
- function inflateInit2
- (strm : in Z_Streamp;
- windowBits : in Int;
- version : in Chars_Ptr;
- stream_size : in Int)
- return Int;
-
- function inflateBackInit
- (strm : in Z_Streamp;
- windowBits : in Int;
- window : in Byte_Access;
- version : in Chars_Ptr;
- stream_size : in Int)
- return Int;
- -- Size of window have to be 2**windowBits.
-
- function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int;
- pragma Inline (Inflate_Init);
-
- function zError (err : Int) return Chars_Ptr;
-
- function inflateSyncPoint (z : Z_Streamp) return Int;
-
- function get_crc_table return ULong_Access;
-
- -- Interface to the available fields of the z_stream structure.
- -- The application must update next_in and avail_in when avail_in has
- -- dropped to zero. It must update next_out and avail_out when avail_out
- -- has dropped to zero. The application must initialize zalloc, zfree and
- -- opaque before calling the init function.
-
- procedure Set_In
- (Strm : in out Z_Stream;
- Buffer : in Voidp;
- Size : in UInt);
- pragma Inline (Set_In);
-
- procedure Set_Out
- (Strm : in out Z_Stream;
- Buffer : in Voidp;
- Size : in UInt);
- pragma Inline (Set_Out);
-
- procedure Set_Mem_Func
- (Strm : in out Z_Stream;
- Opaque : in Voidp;
- Alloc : in alloc_func;
- Free : in free_func);
- pragma Inline (Set_Mem_Func);
-
- function Last_Error_Message (Strm : in Z_Stream) return String;
- pragma Inline (Last_Error_Message);
-
- function Avail_Out (Strm : in Z_Stream) return UInt;
- pragma Inline (Avail_Out);
-
- function Avail_In (Strm : in Z_Stream) return UInt;
- pragma Inline (Avail_In);
-
- function Total_In (Strm : in Z_Stream) return ULong;
- pragma Inline (Total_In);
-
- function Total_Out (Strm : in Z_Stream) return ULong;
- pragma Inline (Total_Out);
-
- function inflateCopy
- (dest : in Z_Streamp;
- Source : in Z_Streamp)
- return Int;
-
- function compressBound (Source_Len : in ULong) return ULong;
-
- function deflateBound
- (Strm : in Z_Streamp;
- Source_Len : in ULong)
- return ULong;
-
- function gzungetc (C : in Int; File : in gzFile) return Int;
-
- function zlibCompileFlags return ULong;
-
-private
-
- type Z_Stream is record -- zlib.h:68
- Next_In : Voidp := Nul; -- next input byte
- Avail_In : UInt := 0; -- number of bytes available at next_in
- Total_In : ULong := 0; -- total nb of input bytes read so far
- Next_Out : Voidp := Nul; -- next output byte should be put there
- Avail_Out : UInt := 0; -- remaining free space at next_out
- Total_Out : ULong := 0; -- total nb of bytes output so far
- msg : Chars_Ptr; -- last error message, NULL if no error
- state : Voidp; -- not visible by applications
- zalloc : alloc_func := null; -- used to allocate the internal state
- zfree : free_func := null; -- used to free the internal state
- opaque : Voidp; -- private data object passed to
- -- zalloc and zfree
- data_type : Int; -- best guess about the data type:
- -- ascii or binary
- adler : ULong; -- adler32 value of the uncompressed
- -- data
- reserved : ULong; -- reserved for future use
- end record;
-
- pragma Convention (C, Z_Stream);
-
- pragma Import (C, zlibVersion, "zlibVersion");
- pragma Import (C, Deflate, "deflate");
- pragma Import (C, DeflateEnd, "deflateEnd");
- pragma Import (C, Inflate, "inflate");
- pragma Import (C, InflateEnd, "inflateEnd");
- pragma Import (C, deflateSetDictionary, "deflateSetDictionary");
- pragma Import (C, deflateCopy, "deflateCopy");
- pragma Import (C, deflateReset, "deflateReset");
- pragma Import (C, deflateParams, "deflateParams");
- pragma Import (C, inflateSetDictionary, "inflateSetDictionary");
- pragma Import (C, inflateSync, "inflateSync");
- pragma Import (C, inflateReset, "inflateReset");
- pragma Import (C, compress, "compress");
- pragma Import (C, compress2, "compress2");
- pragma Import (C, uncompress, "uncompress");
- pragma Import (C, gzopen, "gzopen");
- pragma Import (C, gzdopen, "gzdopen");
- pragma Import (C, gzsetparams, "gzsetparams");
- pragma Import (C, gzread, "gzread");
- pragma Import (C, gzwrite, "gzwrite");
- pragma Import (C, gzprintf, "gzprintf");
- pragma Import (C, gzputs, "gzputs");
- pragma Import (C, gzgets, "gzgets");
- pragma Import (C, gzputc, "gzputc");
- pragma Import (C, gzgetc, "gzgetc");
- pragma Import (C, gzflush, "gzflush");
- pragma Import (C, gzseek, "gzseek");
- pragma Import (C, gzrewind, "gzrewind");
- pragma Import (C, gztell, "gztell");
- pragma Import (C, gzeof, "gzeof");
- pragma Import (C, gzclose, "gzclose");
- pragma Import (C, gzerror, "gzerror");
- pragma Import (C, adler32, "adler32");
- pragma Import (C, crc32, "crc32");
- pragma Import (C, deflateInit, "deflateInit_");
- pragma Import (C, inflateInit, "inflateInit_");
- pragma Import (C, deflateInit2, "deflateInit2_");
- pragma Import (C, inflateInit2, "inflateInit2_");
- pragma Import (C, zError, "zError");
- pragma Import (C, inflateSyncPoint, "inflateSyncPoint");
- pragma Import (C, get_crc_table, "get_crc_table");
-
- -- since zlib 1.2.0:
-
- pragma Import (C, inflateCopy, "inflateCopy");
- pragma Import (C, compressBound, "compressBound");
- pragma Import (C, deflateBound, "deflateBound");
- pragma Import (C, gzungetc, "gzungetc");
- pragma Import (C, zlibCompileFlags, "zlibCompileFlags");
-
- pragma Import (C, inflateBackInit, "inflateBackInit_");
-
- -- I stopped binding the inflateBack routines, becouse realize that
- -- it does not support zlib and gzip headers for now, and have no
- -- symmetric deflateBack routines.
- -- ZLib-Ada is symmetric regarding deflate/inflate data transformation
- -- and has a similar generic callback interface for the
- -- deflate/inflate transformation based on the regular Deflate/Inflate
- -- routines.
-
- -- pragma Import (C, inflateBack, "inflateBack");
- -- pragma Import (C, inflateBackEnd, "inflateBackEnd");
-
-end ZLib.Thin;
diff --git a/cpukit/zlib/contrib/ada/zlib.adb b/cpukit/zlib/contrib/ada/zlib.adb
deleted file mode 100644
index 8927b48f1b..0000000000
--- a/cpukit/zlib/contrib/ada/zlib.adb
+++ /dev/null
@@ -1,701 +0,0 @@
-----------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2004 Dmitriy Anisimkov --
--- --
--- Open source license information is in the zlib.ads file. --
-----------------------------------------------------------------
-
--- $Id$
-
-with Ada.Exceptions;
-with Ada.Unchecked_Conversion;
-with Ada.Unchecked_Deallocation;
-
-with Interfaces.C.Strings;
-
-with ZLib.Thin;
-
-package body ZLib is
-
- use type Thin.Int;
-
- type Z_Stream is new Thin.Z_Stream;
-
- type Return_Code_Enum is
- (OK,
- STREAM_END,
- NEED_DICT,
- ERRNO,
- STREAM_ERROR,
- DATA_ERROR,
- MEM_ERROR,
- BUF_ERROR,
- VERSION_ERROR);
-
- type Flate_Step_Function is access
- function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int;
- pragma Convention (C, Flate_Step_Function);
-
- type Flate_End_Function is access
- function (Ctrm : in Thin.Z_Streamp) return Thin.Int;
- pragma Convention (C, Flate_End_Function);
-
- type Flate_Type is record
- Step : Flate_Step_Function;
- Done : Flate_End_Function;
- end record;
-
- subtype Footer_Array is Stream_Element_Array (1 .. 8);
-
- Simple_GZip_Header : constant Stream_Element_Array (1 .. 10)
- := (16#1f#, 16#8b#, -- Magic header
- 16#08#, -- Z_DEFLATED
- 16#00#, -- Flags
- 16#00#, 16#00#, 16#00#, 16#00#, -- Time
- 16#00#, -- XFlags
- 16#03# -- OS code
- );
- -- The simplest gzip header is not for informational, but just for
- -- gzip format compatibility.
- -- Note that some code below is using assumption
- -- Simple_GZip_Header'Last > Footer_Array'Last, so do not make
- -- Simple_GZip_Header'Last <= Footer_Array'Last.
-
- Return_Code : constant array (Thin.Int range <>) of Return_Code_Enum
- := (0 => OK,
- 1 => STREAM_END,
- 2 => NEED_DICT,
- -1 => ERRNO,
- -2 => STREAM_ERROR,
- -3 => DATA_ERROR,
- -4 => MEM_ERROR,
- -5 => BUF_ERROR,
- -6 => VERSION_ERROR);
-
- Flate : constant array (Boolean) of Flate_Type
- := (True => (Step => Thin.Deflate'Access,
- Done => Thin.DeflateEnd'Access),
- False => (Step => Thin.Inflate'Access,
- Done => Thin.InflateEnd'Access));
-
- Flush_Finish : constant array (Boolean) of Flush_Mode
- := (True => Finish, False => No_Flush);
-
- procedure Raise_Error (Stream : in Z_Stream);
- pragma Inline (Raise_Error);
-
- procedure Raise_Error (Message : in String);
- pragma Inline (Raise_Error);
-
- procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int);
-
- procedure Free is new Ada.Unchecked_Deallocation
- (Z_Stream, Z_Stream_Access);
-
- function To_Thin_Access is new Ada.Unchecked_Conversion
- (Z_Stream_Access, Thin.Z_Streamp);
-
- procedure Translate_GZip
- (Filter : in out Filter_Type;
- In_Data : in Ada.Streams.Stream_Element_Array;
- In_Last : out Ada.Streams.Stream_Element_Offset;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode);
- -- Separate translate routine for make gzip header.
-
- procedure Translate_Auto
- (Filter : in out Filter_Type;
- In_Data : in Ada.Streams.Stream_Element_Array;
- In_Last : out Ada.Streams.Stream_Element_Offset;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode);
- -- translate routine without additional headers.
-
- -----------------
- -- Check_Error --
- -----------------
-
- procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is
- use type Thin.Int;
- begin
- if Code /= Thin.Z_OK then
- Raise_Error
- (Return_Code_Enum'Image (Return_Code (Code))
- & ": " & Last_Error_Message (Stream));
- end if;
- end Check_Error;
-
- -----------
- -- Close --
- -----------
-
- procedure Close
- (Filter : in out Filter_Type;
- Ignore_Error : in Boolean := False)
- is
- Code : Thin.Int;
- begin
- if not Ignore_Error and then not Is_Open (Filter) then
- raise Status_Error;
- end if;
-
- Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm));
-
- if Ignore_Error or else Code = Thin.Z_OK then
- Free (Filter.Strm);
- else
- declare
- Error_Message : constant String
- := Last_Error_Message (Filter.Strm.all);
- begin
- Free (Filter.Strm);
- Ada.Exceptions.Raise_Exception
- (ZLib_Error'Identity,
- Return_Code_Enum'Image (Return_Code (Code))
- & ": " & Error_Message);
- end;
- end if;
- end Close;
-
- -----------
- -- CRC32 --
- -----------
-
- function CRC32
- (CRC : in Unsigned_32;
- Data : in Ada.Streams.Stream_Element_Array)
- return Unsigned_32
- is
- use Thin;
- begin
- return Unsigned_32 (crc32 (ULong (CRC),
- Data'Address,
- Data'Length));
- end CRC32;
-
- procedure CRC32
- (CRC : in out Unsigned_32;
- Data : in Ada.Streams.Stream_Element_Array) is
- begin
- CRC := CRC32 (CRC, Data);
- end CRC32;
-
- ------------------
- -- Deflate_Init --
- ------------------
-
- procedure Deflate_Init
- (Filter : in out Filter_Type;
- Level : in Compression_Level := Default_Compression;
- Strategy : in Strategy_Type := Default_Strategy;
- Method : in Compression_Method := Deflated;
- Window_Bits : in Window_Bits_Type := Default_Window_Bits;
- Memory_Level : in Memory_Level_Type := Default_Memory_Level;
- Header : in Header_Type := Default)
- is
- use type Thin.Int;
- Win_Bits : Thin.Int := Thin.Int (Window_Bits);
- begin
- if Is_Open (Filter) then
- raise Status_Error;
- end if;
-
- -- We allow ZLib to make header only in case of default header type.
- -- Otherwise we would either do header by ourselfs, or do not do
- -- header at all.
-
- if Header = None or else Header = GZip then
- Win_Bits := -Win_Bits;
- end if;
-
- -- For the GZip CRC calculation and make headers.
-
- if Header = GZip then
- Filter.CRC := 0;
- Filter.Offset := Simple_GZip_Header'First;
- else
- Filter.Offset := Simple_GZip_Header'Last + 1;
- end if;
-
- Filter.Strm := new Z_Stream;
- Filter.Compression := True;
- Filter.Stream_End := False;
- Filter.Header := Header;
-
- if Thin.Deflate_Init
- (To_Thin_Access (Filter.Strm),
- Level => Thin.Int (Level),
- method => Thin.Int (Method),
- windowBits => Win_Bits,
- memLevel => Thin.Int (Memory_Level),
- strategy => Thin.Int (Strategy)) /= Thin.Z_OK
- then
- Raise_Error (Filter.Strm.all);
- end if;
- end Deflate_Init;
-
- -----------
- -- Flush --
- -----------
-
- procedure Flush
- (Filter : in out Filter_Type;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode)
- is
- No_Data : Stream_Element_Array := (1 .. 0 => 0);
- Last : Stream_Element_Offset;
- begin
- Translate (Filter, No_Data, Last, Out_Data, Out_Last, Flush);
- end Flush;
-
- -----------------------
- -- Generic_Translate --
- -----------------------
-
- procedure Generic_Translate
- (Filter : in out ZLib.Filter_Type;
- In_Buffer_Size : in Integer := Default_Buffer_Size;
- Out_Buffer_Size : in Integer := Default_Buffer_Size)
- is
- In_Buffer : Stream_Element_Array
- (1 .. Stream_Element_Offset (In_Buffer_Size));
- Out_Buffer : Stream_Element_Array
- (1 .. Stream_Element_Offset (Out_Buffer_Size));
- Last : Stream_Element_Offset;
- In_Last : Stream_Element_Offset;
- In_First : Stream_Element_Offset;
- Out_Last : Stream_Element_Offset;
- begin
- Main : loop
- Data_In (In_Buffer, Last);
-
- In_First := In_Buffer'First;
-
- loop
- Translate
- (Filter => Filter,
- In_Data => In_Buffer (In_First .. Last),
- In_Last => In_Last,
- Out_Data => Out_Buffer,
- Out_Last => Out_Last,
- Flush => Flush_Finish (Last < In_Buffer'First));
-
- if Out_Buffer'First <= Out_Last then
- Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last));
- end if;
-
- exit Main when Stream_End (Filter);
-
- -- The end of in buffer.
-
- exit when In_Last = Last;
-
- In_First := In_Last + 1;
- end loop;
- end loop Main;
-
- end Generic_Translate;
-
- ------------------
- -- Inflate_Init --
- ------------------
-
- procedure Inflate_Init
- (Filter : in out Filter_Type;
- Window_Bits : in Window_Bits_Type := Default_Window_Bits;
- Header : in Header_Type := Default)
- is
- use type Thin.Int;
- Win_Bits : Thin.Int := Thin.Int (Window_Bits);
-
- procedure Check_Version;
- -- Check the latest header types compatibility.
-
- procedure Check_Version is
- begin
- if Version <= "1.1.4" then
- Raise_Error
- ("Inflate header type " & Header_Type'Image (Header)
- & " incompatible with ZLib version " & Version);
- end if;
- end Check_Version;
-
- begin
- if Is_Open (Filter) then
- raise Status_Error;
- end if;
-
- case Header is
- when None =>
- Check_Version;
-
- -- Inflate data without headers determined
- -- by negative Win_Bits.
-
- Win_Bits := -Win_Bits;
- when GZip =>
- Check_Version;
-
- -- Inflate gzip data defined by flag 16.
-
- Win_Bits := Win_Bits + 16;
- when Auto =>
- Check_Version;
-
- -- Inflate with automatic detection
- -- of gzip or native header defined by flag 32.
-
- Win_Bits := Win_Bits + 32;
- when Default => null;
- end case;
-
- Filter.Strm := new Z_Stream;
- Filter.Compression := False;
- Filter.Stream_End := False;
- Filter.Header := Header;
-
- if Thin.Inflate_Init
- (To_Thin_Access (Filter.Strm), Win_Bits) /= Thin.Z_OK
- then
- Raise_Error (Filter.Strm.all);
- end if;
- end Inflate_Init;
-
- -------------
- -- Is_Open --
- -------------
-
- function Is_Open (Filter : in Filter_Type) return Boolean is
- begin
- return Filter.Strm /= null;
- end Is_Open;
-
- -----------------
- -- Raise_Error --
- -----------------
-
- procedure Raise_Error (Message : in String) is
- begin
- Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message);
- end Raise_Error;
-
- procedure Raise_Error (Stream : in Z_Stream) is
- begin
- Raise_Error (Last_Error_Message (Stream));
- end Raise_Error;
-
- ----------
- -- Read --
- ----------
-
- procedure Read
- (Filter : in out Filter_Type;
- Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode := No_Flush)
- is
- In_Last : Stream_Element_Offset;
- Item_First : Ada.Streams.Stream_Element_Offset := Item'First;
- V_Flush : Flush_Mode := Flush;
-
- begin
- pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1);
- pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last);
-
- loop
- if Rest_Last = Buffer'First - 1 then
- V_Flush := Finish;
-
- elsif Rest_First > Rest_Last then
- Read (Buffer, Rest_Last);
- Rest_First := Buffer'First;
-
- if Rest_Last < Buffer'First then
- V_Flush := Finish;
- end if;
- end if;
-
- Translate
- (Filter => Filter,
- In_Data => Buffer (Rest_First .. Rest_Last),
- In_Last => In_Last,
- Out_Data => Item (Item_First .. Item'Last),
- Out_Last => Last,
- Flush => V_Flush);
-
- Rest_First := In_Last + 1;
-
- exit when Stream_End (Filter)
- or else Last = Item'Last
- or else (Last >= Item'First and then Allow_Read_Some);
-
- Item_First := Last + 1;
- end loop;
- end Read;
-
- ----------------
- -- Stream_End --
- ----------------
-
- function Stream_End (Filter : in Filter_Type) return Boolean is
- begin
- if Filter.Header = GZip and Filter.Compression then
- return Filter.Stream_End
- and then Filter.Offset = Footer_Array'Last + 1;
- else
- return Filter.Stream_End;
- end if;
- end Stream_End;
-
- --------------
- -- Total_In --
- --------------
-
- function Total_In (Filter : in Filter_Type) return Count is
- begin
- return Count (Thin.Total_In (To_Thin_Access (Filter.Strm).all));
- end Total_In;
-
- ---------------
- -- Total_Out --
- ---------------
-
- function Total_Out (Filter : in Filter_Type) return Count is
- begin
- return Count (Thin.Total_Out (To_Thin_Access (Filter.Strm).all));
- end Total_Out;
-
- ---------------
- -- Translate --
- ---------------
-
- procedure Translate
- (Filter : in out Filter_Type;
- In_Data : in Ada.Streams.Stream_Element_Array;
- In_Last : out Ada.Streams.Stream_Element_Offset;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode) is
- begin
- if Filter.Header = GZip and then Filter.Compression then
- Translate_GZip
- (Filter => Filter,
- In_Data => In_Data,
- In_Last => In_Last,
- Out_Data => Out_Data,
- Out_Last => Out_Last,
- Flush => Flush);
- else
- Translate_Auto
- (Filter => Filter,
- In_Data => In_Data,
- In_Last => In_Last,
- Out_Data => Out_Data,
- Out_Last => Out_Last,
- Flush => Flush);
- end if;
- end Translate;
-
- --------------------
- -- Translate_Auto --
- --------------------
-
- procedure Translate_Auto
- (Filter : in out Filter_Type;
- In_Data : in Ada.Streams.Stream_Element_Array;
- In_Last : out Ada.Streams.Stream_Element_Offset;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode)
- is
- use type Thin.Int;
- Code : Thin.Int;
-
- begin
- if not Is_Open (Filter) then
- raise Status_Error;
- end if;
-
- if Out_Data'Length = 0 and then In_Data'Length = 0 then
- raise Constraint_Error;
- end if;
-
- Set_Out (Filter.Strm.all, Out_Data'Address, Out_Data'Length);
- Set_In (Filter.Strm.all, In_Data'Address, In_Data'Length);
-
- Code := Flate (Filter.Compression).Step
- (To_Thin_Access (Filter.Strm),
- Thin.Int (Flush));
-
- if Code = Thin.Z_STREAM_END then
- Filter.Stream_End := True;
- else
- Check_Error (Filter.Strm.all, Code);
- end if;
-
- In_Last := In_Data'Last
- - Stream_Element_Offset (Avail_In (Filter.Strm.all));
- Out_Last := Out_Data'Last
- - Stream_Element_Offset (Avail_Out (Filter.Strm.all));
- end Translate_Auto;
-
- --------------------
- -- Translate_GZip --
- --------------------
-
- procedure Translate_GZip
- (Filter : in out Filter_Type;
- In_Data : in Ada.Streams.Stream_Element_Array;
- In_Last : out Ada.Streams.Stream_Element_Offset;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode)
- is
- Out_First : Stream_Element_Offset;
-
- procedure Add_Data (Data : in Stream_Element_Array);
- -- Add data to stream from the Filter.Offset till necessary,
- -- used for add gzip headr/footer.
-
- procedure Put_32
- (Item : in out Stream_Element_Array;
- Data : in Unsigned_32);
- pragma Inline (Put_32);
-
- --------------
- -- Add_Data --
- --------------
-
- procedure Add_Data (Data : in Stream_Element_Array) is
- Data_First : Stream_Element_Offset renames Filter.Offset;
- Data_Last : Stream_Element_Offset;
- Data_Len : Stream_Element_Offset; -- -1
- Out_Len : Stream_Element_Offset; -- -1
- begin
- Out_First := Out_Last + 1;
-
- if Data_First > Data'Last then
- return;
- end if;
-
- Data_Len := Data'Last - Data_First;
- Out_Len := Out_Data'Last - Out_First;
-
- if Data_Len <= Out_Len then
- Out_Last := Out_First + Data_Len;
- Data_Last := Data'Last;
- else
- Out_Last := Out_Data'Last;
- Data_Last := Data_First + Out_Len;
- end if;
-
- Out_Data (Out_First .. Out_Last) := Data (Data_First .. Data_Last);
-
- Data_First := Data_Last + 1;
- Out_First := Out_Last + 1;
- end Add_Data;
-
- ------------
- -- Put_32 --
- ------------
-
- procedure Put_32
- (Item : in out Stream_Element_Array;
- Data : in Unsigned_32)
- is
- D : Unsigned_32 := Data;
- begin
- for J in Item'First .. Item'First + 3 loop
- Item (J) := Stream_Element (D and 16#FF#);
- D := Shift_Right (D, 8);
- end loop;
- end Put_32;
-
- begin
- Out_Last := Out_Data'First - 1;
-
- if not Filter.Stream_End then
- Add_Data (Simple_GZip_Header);
-
- Translate_Auto
- (Filter => Filter,
- In_Data => In_Data,
- In_Last => In_Last,
- Out_Data => Out_Data (Out_First .. Out_Data'Last),
- Out_Last => Out_Last,
- Flush => Flush);
-
- CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last));
- end if;
-
- if Filter.Stream_End and then Out_Last <= Out_Data'Last then
- -- This detection method would work only when
- -- Simple_GZip_Header'Last > Footer_Array'Last
-
- if Filter.Offset = Simple_GZip_Header'Last + 1 then
- Filter.Offset := Footer_Array'First;
- end if;
-
- declare
- Footer : Footer_Array;
- begin
- Put_32 (Footer, Filter.CRC);
- Put_32 (Footer (Footer'First + 4 .. Footer'Last),
- Unsigned_32 (Total_In (Filter)));
- Add_Data (Footer);
- end;
- end if;
- end Translate_GZip;
-
- -------------
- -- Version --
- -------------
-
- function Version return String is
- begin
- return Interfaces.C.Strings.Value (Thin.zlibVersion);
- end Version;
-
- -----------
- -- Write --
- -----------
-
- procedure Write
- (Filter : in out Filter_Type;
- Item : in Ada.Streams.Stream_Element_Array;
- Flush : in Flush_Mode := No_Flush)
- is
- Buffer : Stream_Element_Array (1 .. Buffer_Size);
- In_Last : Stream_Element_Offset;
- Out_Last : Stream_Element_Offset;
- In_First : Stream_Element_Offset := Item'First;
- begin
- if Item'Length = 0 and Flush = No_Flush then
- return;
- end if;
-
- loop
- Translate
- (Filter => Filter,
- In_Data => Item (In_First .. Item'Last),
- In_Last => In_Last,
- Out_Data => Buffer,
- Out_Last => Out_Last,
- Flush => Flush);
-
- if Out_Last >= Buffer'First then
- Write (Buffer (1 .. Out_Last));
- end if;
-
- exit when In_Last = Item'Last or Stream_End (Filter);
-
- In_First := In_Last + 1;
- end loop;
- end Write;
-
-end ZLib;
diff --git a/cpukit/zlib/contrib/ada/zlib.ads b/cpukit/zlib/contrib/ada/zlib.ads
deleted file mode 100644
index 9ada859572..0000000000
--- a/cpukit/zlib/contrib/ada/zlib.ads
+++ /dev/null
@@ -1,328 +0,0 @@
-------------------------------------------------------------------------------
--- ZLib for Ada thick binding. --
--- --
--- Copyright (C) 2002-2004 Dmitriy Anisimkov --
--- --
--- This library is free software; you can redistribute it and/or modify --
--- it under the terms of the GNU General Public License as published by --
--- the Free Software Foundation; either version 2 of the License, or (at --
--- your option) any later version. --
--- --
--- This library is distributed in the hope that it will be useful, but --
--- WITHOUT ANY WARRANTY; without even the implied warranty of --
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
--- General Public License for more details. --
--- --
--- You should have received a copy of the GNU General Public License --
--- along with this library; if not, write to the Free Software Foundation, --
--- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
--- --
--- As a special exception, if other files instantiate generics from this --
--- unit, or you link this unit with other files to produce an executable, --
--- this unit does not by itself cause the resulting executable to be --
--- covered by the GNU General Public License. This exception does not --
--- however invalidate any other reasons why the executable file might be --
--- covered by the GNU Public License. --
-------------------------------------------------------------------------------
-
--- $Id$
-
-with Ada.Streams;
-
-with Interfaces;
-
-package ZLib is
-
- ZLib_Error : exception;
- Status_Error : exception;
-
- type Compression_Level is new Integer range -1 .. 9;
-
- type Flush_Mode is private;
-
- type Compression_Method is private;
-
- type Window_Bits_Type is new Integer range 8 .. 15;
-
- type Memory_Level_Type is new Integer range 1 .. 9;
-
- type Unsigned_32 is new Interfaces.Unsigned_32;
-
- type Strategy_Type is private;
-
- type Header_Type is (None, Auto, Default, GZip);
- -- Header type usage have a some limitation for inflate.
- -- See comment for Inflate_Init.
-
- subtype Count is Ada.Streams.Stream_Element_Count;
-
- Default_Memory_Level : constant Memory_Level_Type := 8;
- Default_Window_Bits : constant Window_Bits_Type := 15;
-
- ----------------------------------
- -- Compression method constants --
- ----------------------------------
-
- Deflated : constant Compression_Method;
- -- Only one method allowed in this ZLib version
-
- ---------------------------------
- -- Compression level constants --
- ---------------------------------
-
- No_Compression : constant Compression_Level := 0;
- Best_Speed : constant Compression_Level := 1;
- Best_Compression : constant Compression_Level := 9;
- Default_Compression : constant Compression_Level := -1;
-
- --------------------------
- -- Flush mode constants --
- --------------------------
-
- No_Flush : constant Flush_Mode;
- -- Regular way for compression, no flush
-
- Partial_Flush : constant Flush_Mode;
- -- Will be removed, use Z_SYNC_FLUSH instead
-
- Sync_Flush : constant Flush_Mode;
- -- All pending output is flushed to the output buffer and the output
- -- is aligned on a byte boundary, so that the decompressor can get all
- -- input data available so far. (In particular avail_in is zero after the
- -- call if enough output space has been provided before the call.)
- -- Flushing may degrade compression for some compression algorithms and so
- -- it should be used only when necessary.
-
- Block_Flush : constant Flush_Mode;
- -- Z_BLOCK requests that inflate() stop
- -- if and when it get to the next deflate block boundary. When decoding the
- -- zlib or gzip format, this will cause inflate() to return immediately
- -- after the header and before the first block. When doing a raw inflate,
- -- inflate() will go ahead and process the first block, and will return
- -- when it gets to the end of that block, or when it runs out of data.
-
- Full_Flush : constant Flush_Mode;
- -- All output is flushed as with SYNC_FLUSH, and the compression state
- -- is reset so that decompression can restart from this point if previous
- -- compressed data has been damaged or if random access is desired. Using
- -- Full_Flush too often can seriously degrade the compression.
-
- Finish : constant Flush_Mode;
- -- Just for tell the compressor that input data is complete.
-
- ------------------------------------
- -- Compression strategy constants --
- ------------------------------------
-
- -- RLE stategy could be used only in version 1.2.0 and later.
-
- Filtered : constant Strategy_Type;
- Huffman_Only : constant Strategy_Type;
- RLE : constant Strategy_Type;
- Default_Strategy : constant Strategy_Type;
-
- Default_Buffer_Size : constant := 4096;
-
- type Filter_Type is tagged limited private;
- -- The filter is for compression and for decompression.
- -- The usage of the type is depend of its initialization.
-
- function Version return String;
- pragma Inline (Version);
- -- Return string representation of the ZLib version.
-
- procedure Deflate_Init
- (Filter : in out Filter_Type;
- Level : in Compression_Level := Default_Compression;
- Strategy : in Strategy_Type := Default_Strategy;
- Method : in Compression_Method := Deflated;
- Window_Bits : in Window_Bits_Type := Default_Window_Bits;
- Memory_Level : in Memory_Level_Type := Default_Memory_Level;
- Header : in Header_Type := Default);
- -- Compressor initialization.
- -- When Header parameter is Auto or Default, then default zlib header
- -- would be provided for compressed data.
- -- When Header is GZip, then gzip header would be set instead of
- -- default header.
- -- When Header is None, no header would be set for compressed data.
-
- procedure Inflate_Init
- (Filter : in out Filter_Type;
- Window_Bits : in Window_Bits_Type := Default_Window_Bits;
- Header : in Header_Type := Default);
- -- Decompressor initialization.
- -- Default header type mean that ZLib default header is expecting in the
- -- input compressed stream.
- -- Header type None mean that no header is expecting in the input stream.
- -- GZip header type mean that GZip header is expecting in the
- -- input compressed stream.
- -- Auto header type mean that header type (GZip or Native) would be
- -- detected automatically in the input stream.
- -- Note that header types parameter values None, GZip and Auto are
- -- supported for inflate routine only in ZLib versions 1.2.0.2 and later.
- -- Deflate_Init is supporting all header types.
-
- function Is_Open (Filter : in Filter_Type) return Boolean;
- pragma Inline (Is_Open);
- -- Is the filter opened for compression or decompression.
-
- procedure Close
- (Filter : in out Filter_Type;
- Ignore_Error : in Boolean := False);
- -- Closing the compression or decompressor.
- -- If stream is closing before the complete and Ignore_Error is False,
- -- The exception would be raised.
-
- generic
- with procedure Data_In
- (Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset);
- with procedure Data_Out
- (Item : in Ada.Streams.Stream_Element_Array);
- procedure Generic_Translate
- (Filter : in out Filter_Type;
- In_Buffer_Size : in Integer := Default_Buffer_Size;
- Out_Buffer_Size : in Integer := Default_Buffer_Size);
- -- Compress/decompress data fetch from Data_In routine and pass the result
- -- to the Data_Out routine. User should provide Data_In and Data_Out
- -- for compression/decompression data flow.
- -- Compression or decompression depend on Filter initialization.
-
- function Total_In (Filter : in Filter_Type) return Count;
- pragma Inline (Total_In);
- -- Returns total number of input bytes read so far
-
- function Total_Out (Filter : in Filter_Type) return Count;
- pragma Inline (Total_Out);
- -- Returns total number of bytes output so far
-
- function CRC32
- (CRC : in Unsigned_32;
- Data : in Ada.Streams.Stream_Element_Array)
- return Unsigned_32;
- pragma Inline (CRC32);
- -- Compute CRC32, it could be necessary for make gzip format
-
- procedure CRC32
- (CRC : in out Unsigned_32;
- Data : in Ada.Streams.Stream_Element_Array);
- pragma Inline (CRC32);
- -- Compute CRC32, it could be necessary for make gzip format
-
- -------------------------------------------------
- -- Below is more complex low level routines. --
- -------------------------------------------------
-
- procedure Translate
- (Filter : in out Filter_Type;
- In_Data : in Ada.Streams.Stream_Element_Array;
- In_Last : out Ada.Streams.Stream_Element_Offset;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode);
- -- Compress/decompress the In_Data buffer and place the result into
- -- Out_Data. In_Last is the index of last element from In_Data accepted by
- -- the Filter. Out_Last is the last element of the received data from
- -- Filter. To tell the filter that incoming data are complete put the
- -- Flush parameter to Finish.
-
- function Stream_End (Filter : in Filter_Type) return Boolean;
- pragma Inline (Stream_End);
- -- Return the true when the stream is complete.
-
- procedure Flush
- (Filter : in out Filter_Type;
- Out_Data : out Ada.Streams.Stream_Element_Array;
- Out_Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode);
- pragma Inline (Flush);
- -- Flushing the data from the compressor.
-
- generic
- with procedure Write
- (Item : in Ada.Streams.Stream_Element_Array);
- -- User should provide this routine for accept
- -- compressed/decompressed data.
-
- Buffer_Size : in Ada.Streams.Stream_Element_Offset
- := Default_Buffer_Size;
- -- Buffer size for Write user routine.
-
- procedure Write
- (Filter : in out Filter_Type;
- Item : in Ada.Streams.Stream_Element_Array;
- Flush : in Flush_Mode := No_Flush);
- -- Compress/Decompress data from Item to the generic parameter procedure
- -- Write. Output buffer size could be set in Buffer_Size generic parameter.
-
- generic
- with procedure Read
- (Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset);
- -- User should provide data for compression/decompression
- -- thru this routine.
-
- Buffer : in out Ada.Streams.Stream_Element_Array;
- -- Buffer for keep remaining data from the previous
- -- back read.
-
- Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset;
- -- Rest_First have to be initialized to Buffer'Last + 1
- -- Rest_Last have to be initialized to Buffer'Last
- -- before usage.
-
- Allow_Read_Some : in Boolean := False;
- -- Is it allowed to return Last < Item'Last before end of data.
-
- procedure Read
- (Filter : in out Filter_Type;
- Item : out Ada.Streams.Stream_Element_Array;
- Last : out Ada.Streams.Stream_Element_Offset;
- Flush : in Flush_Mode := No_Flush);
- -- Compress/Decompress data from generic parameter procedure Read to the
- -- Item. User should provide Buffer and initialized Rest_First, Rest_Last
- -- indicators. If Allow_Read_Some is True, Read routines could return
- -- Last < Item'Last only at end of stream.
-
-private
-
- use Ada.Streams;
-
- pragma Assert (Ada.Streams.Stream_Element'Size = 8);
- pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8);
-
- type Flush_Mode is new Integer range 0 .. 5;
-
- type Compression_Method is new Integer range 8 .. 8;
-
- type Strategy_Type is new Integer range 0 .. 3;
-
- No_Flush : constant Flush_Mode := 0;
- Partial_Flush : constant Flush_Mode := 1;
- Sync_Flush : constant Flush_Mode := 2;
- Full_Flush : constant Flush_Mode := 3;
- Finish : constant Flush_Mode := 4;
- Block_Flush : constant Flush_Mode := 5;
-
- Filtered : constant Strategy_Type := 1;
- Huffman_Only : constant Strategy_Type := 2;
- RLE : constant Strategy_Type := 3;
- Default_Strategy : constant Strategy_Type := 0;
-
- Deflated : constant Compression_Method := 8;
-
- type Z_Stream;
-
- type Z_Stream_Access is access all Z_Stream;
-
- type Filter_Type is tagged limited record
- Strm : Z_Stream_Access;
- Compression : Boolean;
- Stream_End : Boolean;
- Header : Header_Type;
- CRC : Unsigned_32;
- Offset : Stream_Element_Offset;
- -- Offset for gzip header/footer output.
- end record;
-
-end ZLib;
diff --git a/cpukit/zlib/contrib/ada/zlib.gpr b/cpukit/zlib/contrib/ada/zlib.gpr
deleted file mode 100644
index 296b22aa96..0000000000
--- a/cpukit/zlib/contrib/ada/zlib.gpr
+++ /dev/null
@@ -1,20 +0,0 @@
-project Zlib is
-
- for Languages use ("Ada");
- for Source_Dirs use (".");
- for Object_Dir use ".";
- for Main use ("test.adb", "mtest.adb", "read.adb", "buffer_demo");
-
- package Compiler is
- for Default_Switches ("ada") use ("-gnatwcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst");
- end Compiler;
-
- package Linker is
- for Default_Switches ("ada") use ("-lz");
- end Linker;
-
- package Builder is
- for Default_Switches ("ada") use ("-s", "-gnatQ");
- end Builder;
-
-end Zlib;
diff --git a/cpukit/zlib/contrib/asm586/README.586 b/cpukit/zlib/contrib/asm586/README.586
deleted file mode 100644
index 6bb78f3206..0000000000
--- a/cpukit/zlib/contrib/asm586/README.586
+++ /dev/null
@@ -1,43 +0,0 @@
-This is a patched version of zlib modified to use
-Pentium-optimized assembly code in the deflation algorithm. The files
-changed/added by this patch are:
-
-README.586
-match.S
-
-The effectiveness of these modifications is a bit marginal, as the the
-program's bottleneck seems to be mostly L1-cache contention, for which
-there is no real way to work around without rewriting the basic
-algorithm. The speedup on average is around 5-10% (which is generally
-less than the amount of variance between subsequent executions).
-However, when used at level 9 compression, the cache contention can
-drop enough for the assembly version to achieve 10-20% speedup (and
-sometimes more, depending on the amount of overall redundancy in the
-files). Even here, though, cache contention can still be the limiting
-factor, depending on the nature of the program using the zlib library.
-This may also mean that better improvements will be seen on a Pentium
-with MMX, which suffers much less from L1-cache contention, but I have
-not yet verified this.
-
-Note that this code has been tailored for the Pentium in particular,
-and will not perform well on the Pentium Pro (due to the use of a
-partial register in the inner loop).
-
-If you are using an assembler other than GNU as, you will have to
-translate match.S to use your assembler's syntax. (Have fun.)
-
-Brian Raiter
-breadbox@muppetlabs.com
-April, 1998
-
-
-Added for zlib 1.1.3:
-
-The patches come from
-http://www.muppetlabs.com/~breadbox/software/assembly.html
-
-To compile zlib with this asm file, copy match.S to the zlib directory
-then do:
-
-CFLAGS="-O3 -DASMV" ./configure
-make OBJA=match.o
diff --git a/cpukit/zlib/contrib/asm586/match.S b/cpukit/zlib/contrib/asm586/match.S
deleted file mode 100644
index 0368b35fe3..0000000000
--- a/cpukit/zlib/contrib/asm586/match.S
+++ /dev/null
@@ -1,364 +0,0 @@
-/* match.s -- Pentium-optimized version of longest_match()
- * Written for zlib 1.1.2
- * Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License.
- */
-
-#ifndef NO_UNDERLINE
-#define match_init _match_init
-#define longest_match _longest_match
-#endif
-
-#define MAX_MATCH (258)
-#define MIN_MATCH (3)
-#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
-#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7)
-
-/* stack frame offsets */
-
-#define wmask 0 /* local copy of s->wmask */
-#define window 4 /* local copy of s->window */
-#define windowbestlen 8 /* s->window + bestlen */
-#define chainlenscanend 12 /* high word: current chain len */
- /* low word: last bytes sought */
-#define scanstart 16 /* first two bytes of string */
-#define scanalign 20 /* dword-misalignment of string */
-#define nicematch 24 /* a good enough match size */
-#define bestlen 28 /* size of best match so far */
-#define scan 32 /* ptr to string wanting match */
-
-#define LocalVarsSize (36)
-/* saved ebx 36 */
-/* saved edi 40 */
-/* saved esi 44 */
-/* saved ebp 48 */
-/* return address 52 */
-#define deflatestate 56 /* the function arguments */
-#define curmatch 60
-
-/* Offsets for fields in the deflate_state structure. These numbers
- * are calculated from the definition of deflate_state, with the
- * assumption that the compiler will dword-align the fields. (Thus,
- * changing the definition of deflate_state could easily cause this
- * program to crash horribly, without so much as a warning at
- * compile time. Sigh.)
- */
-
-/* All the +zlib1222add offsets are due to the addition of fields
- * in zlib in the deflate_state structure since the asm code was first written
- * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
- * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
- * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
- */
-
-#define zlib1222add (8)
-
-#define dsWSize (36+zlib1222add)
-#define dsWMask (44+zlib1222add)
-#define dsWindow (48+zlib1222add)
-#define dsPrev (56+zlib1222add)
-#define dsMatchLen (88+zlib1222add)
-#define dsPrevMatch (92+zlib1222add)
-#define dsStrStart (100+zlib1222add)
-#define dsMatchStart (104+zlib1222add)
-#define dsLookahead (108+zlib1222add)
-#define dsPrevLen (112+zlib1222add)
-#define dsMaxChainLen (116+zlib1222add)
-#define dsGoodMatch (132+zlib1222add)
-#define dsNiceMatch (136+zlib1222add)
-
-
-.file "match.S"
-
-.globl match_init, longest_match
-
-.text
-
-/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
-
-longest_match:
-
-/* Save registers that the compiler may be using, and adjust %esp to */
-/* make room for our stack frame. */
-
- pushl %ebp
- pushl %edi
- pushl %esi
- pushl %ebx
- subl $LocalVarsSize, %esp
-
-/* Retrieve the function arguments. %ecx will hold cur_match */
-/* throughout the entire function. %edx will hold the pointer to the */
-/* deflate_state structure during the function's setup (before */
-/* entering the main loop). */
-
- movl deflatestate(%esp), %edx
- movl curmatch(%esp), %ecx
-
-/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */
-
- movl dsNiceMatch(%edx), %eax
- movl dsLookahead(%edx), %ebx
- cmpl %eax, %ebx
- jl LookaheadLess
- movl %eax, %ebx
-LookaheadLess: movl %ebx, nicematch(%esp)
-
-/* register Bytef *scan = s->window + s->strstart; */
-
- movl dsWindow(%edx), %esi
- movl %esi, window(%esp)
- movl dsStrStart(%edx), %ebp
- lea (%esi,%ebp), %edi
- movl %edi, scan(%esp)
-
-/* Determine how many bytes the scan ptr is off from being */
-/* dword-aligned. */
-
- movl %edi, %eax
- negl %eax
- andl $3, %eax
- movl %eax, scanalign(%esp)
-
-/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */
-/* s->strstart - (IPos)MAX_DIST(s) : NIL; */
-
- movl dsWSize(%edx), %eax
- subl $MIN_LOOKAHEAD, %eax
- subl %eax, %ebp
- jg LimitPositive
- xorl %ebp, %ebp
-LimitPositive:
-
-/* unsigned chain_length = s->max_chain_length; */
-/* if (s->prev_length >= s->good_match) { */
-/* chain_length >>= 2; */
-/* } */
-
- movl dsPrevLen(%edx), %eax
- movl dsGoodMatch(%edx), %ebx
- cmpl %ebx, %eax
- movl dsMaxChainLen(%edx), %ebx
- jl LastMatchGood
- shrl $2, %ebx
-LastMatchGood:
-
-/* chainlen is decremented once beforehand so that the function can */
-/* use the sign flag instead of the zero flag for the exit test. */
-/* It is then shifted into the high word, to make room for the scanend */
-/* scanend value, which it will always accompany. */
-
- decl %ebx
- shll $16, %ebx
-
-/* int best_len = s->prev_length; */
-
- movl dsPrevLen(%edx), %eax
- movl %eax, bestlen(%esp)
-
-/* Store the sum of s->window + best_len in %esi locally, and in %esi. */
-
- addl %eax, %esi
- movl %esi, windowbestlen(%esp)
-
-/* register ush scan_start = *(ushf*)scan; */
-/* register ush scan_end = *(ushf*)(scan+best_len-1); */
-
- movw (%edi), %bx
- movw %bx, scanstart(%esp)
- movw -1(%edi,%eax), %bx
- movl %ebx, chainlenscanend(%esp)
-
-/* Posf *prev = s->prev; */
-/* uInt wmask = s->w_mask; */
-
- movl dsPrev(%edx), %edi
- movl dsWMask(%edx), %edx
- mov %edx, wmask(%esp)
-
-/* Jump into the main loop. */
-
- jmp LoopEntry
-
-.balign 16
-
-/* do {
- * match = s->window + cur_match;
- * if (*(ushf*)(match+best_len-1) != scan_end ||
- * *(ushf*)match != scan_start) continue;
- * [...]
- * } while ((cur_match = prev[cur_match & wmask]) > limit
- * && --chain_length != 0);
- *
- * Here is the inner loop of the function. The function will spend the
- * majority of its time in this loop, and majority of that time will
- * be spent in the first ten instructions.
- *
- * Within this loop:
- * %ebx = chainlenscanend - i.e., ((chainlen << 16) | scanend)
- * %ecx = curmatch
- * %edx = curmatch & wmask
- * %esi = windowbestlen - i.e., (window + bestlen)
- * %edi = prev
- * %ebp = limit
- *
- * Two optimization notes on the choice of instructions:
- *
- * The first instruction uses a 16-bit address, which costs an extra,
- * unpairable cycle. This is cheaper than doing a 32-bit access and
- * zeroing the high word, due to the 3-cycle misalignment penalty which
- * would occur half the time. This also turns out to be cheaper than
- * doing two separate 8-bit accesses, as the memory is so rarely in the
- * L1 cache.
- *
- * The window buffer, however, apparently spends a lot of time in the
- * cache, and so it is faster to retrieve the word at the end of the
- * match string with two 8-bit loads. The instructions that test the
- * word at the beginning of the match string, however, are executed
- * much less frequently, and there it was cheaper to use 16-bit
- * instructions, which avoided the necessity of saving off and
- * subsequently reloading one of the other registers.
- */
-LookupLoop:
- /* 1 U & V */
- movw (%edi,%edx,2), %cx /* 2 U pipe */
- movl wmask(%esp), %edx /* 2 V pipe */
- cmpl %ebp, %ecx /* 3 U pipe */
- jbe LeaveNow /* 3 V pipe */
- subl $0x00010000, %ebx /* 4 U pipe */
- js LeaveNow /* 4 V pipe */
-LoopEntry: movb -1(%esi,%ecx), %al /* 5 U pipe */
- andl %ecx, %edx /* 5 V pipe */
- cmpb %bl, %al /* 6 U pipe */
- jnz LookupLoop /* 6 V pipe */
- movb (%esi,%ecx), %ah
- cmpb %bh, %ah
- jnz LookupLoop
- movl window(%esp), %eax
- movw (%eax,%ecx), %ax
- cmpw scanstart(%esp), %ax
- jnz LookupLoop
-
-/* Store the current value of chainlen. */
-
- movl %ebx, chainlenscanend(%esp)
-
-/* Point %edi to the string under scrutiny, and %esi to the string we */
-/* are hoping to match it up with. In actuality, %esi and %edi are */
-/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */
-/* initialized to -(MAX_MATCH_8 - scanalign). */
-
- movl window(%esp), %esi
- movl scan(%esp), %edi
- addl %ecx, %esi
- movl scanalign(%esp), %eax
- movl $(-MAX_MATCH_8), %edx
- lea MAX_MATCH_8(%edi,%eax), %edi
- lea MAX_MATCH_8(%esi,%eax), %esi
-
-/* Test the strings for equality, 8 bytes at a time. At the end,
- * adjust %edx so that it is offset to the exact byte that mismatched.
- *
- * We already know at this point that the first three bytes of the
- * strings match each other, and they can be safely passed over before
- * starting the compare loop. So what this code does is skip over 0-3
- * bytes, as much as necessary in order to dword-align the %edi
- * pointer. (%esi will still be misaligned three times out of four.)
- *
- * It should be confessed that this loop usually does not represent
- * much of the total running time. Replacing it with a more
- * straightforward "rep cmpsb" would not drastically degrade
- * performance.
- */
-LoopCmps:
- movl (%esi,%edx), %eax
- movl (%edi,%edx), %ebx
- xorl %ebx, %eax
- jnz LeaveLoopCmps
- movl 4(%esi,%edx), %eax
- movl 4(%edi,%edx), %ebx
- xorl %ebx, %eax
- jnz LeaveLoopCmps4
- addl $8, %edx
- jnz LoopCmps
- jmp LenMaximum
-LeaveLoopCmps4: addl $4, %edx
-LeaveLoopCmps: testl $0x0000FFFF, %eax
- jnz LenLower
- addl $2, %edx
- shrl $16, %eax
-LenLower: subb $1, %al
- adcl $0, %edx
-
-/* Calculate the length of the match. If it is longer than MAX_MATCH, */
-/* then automatically accept it as the best possible match and leave. */
-
- lea (%edi,%edx), %eax
- movl scan(%esp), %edi
- subl %edi, %eax
- cmpl $MAX_MATCH, %eax
- jge LenMaximum
-
-/* If the length of the match is not longer than the best match we */
-/* have so far, then forget it and return to the lookup loop. */
-
- movl deflatestate(%esp), %edx
- movl bestlen(%esp), %ebx
- cmpl %ebx, %eax
- jg LongerMatch
- movl chainlenscanend(%esp), %ebx
- movl windowbestlen(%esp), %esi
- movl dsPrev(%edx), %edi
- movl wmask(%esp), %edx
- andl %ecx, %edx
- jmp LookupLoop
-
-/* s->match_start = cur_match; */
-/* best_len = len; */
-/* if (len >= nice_match) break; */
-/* scan_end = *(ushf*)(scan+best_len-1); */
-
-LongerMatch: movl nicematch(%esp), %ebx
- movl %eax, bestlen(%esp)
- movl %ecx, dsMatchStart(%edx)
- cmpl %ebx, %eax
- jge LeaveNow
- movl window(%esp), %esi
- addl %eax, %esi
- movl %esi, windowbestlen(%esp)
- movl chainlenscanend(%esp), %ebx
- movw -1(%edi,%eax), %bx
- movl dsPrev(%edx), %edi
- movl %ebx, chainlenscanend(%esp)
- movl wmask(%esp), %edx
- andl %ecx, %edx
- jmp LookupLoop
-
-/* Accept the current string, with the maximum possible length. */
-
-LenMaximum: movl deflatestate(%esp), %edx
- movl $MAX_MATCH, bestlen(%esp)
- movl %ecx, dsMatchStart(%edx)
-
-/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */
-/* return s->lookahead; */
-
-LeaveNow:
- movl deflatestate(%esp), %edx
- movl bestlen(%esp), %ebx
- movl dsLookahead(%edx), %eax
- cmpl %eax, %ebx
- jg LookaheadRet
- movl %ebx, %eax
-LookaheadRet:
-
-/* Restore the stack and return from whence we came. */
-
- addl $LocalVarsSize, %esp
- popl %ebx
- popl %esi
- popl %edi
- popl %ebp
-match_init: ret
diff --git a/cpukit/zlib/contrib/asm686/README.686 b/cpukit/zlib/contrib/asm686/README.686
deleted file mode 100644
index a0bf3bea4a..0000000000
--- a/cpukit/zlib/contrib/asm686/README.686
+++ /dev/null
@@ -1,51 +0,0 @@
-This is a patched version of zlib, modified to use
-Pentium-Pro-optimized assembly code in the deflation algorithm. The
-files changed/added by this patch are:
-
-README.686
-match.S
-
-The speedup that this patch provides varies, depending on whether the
-compiler used to build the original version of zlib falls afoul of the
-PPro's speed traps. My own tests show a speedup of around 10-20% at
-the default compression level, and 20-30% using -9, against a version
-compiled using gcc 2.7.2.3. Your mileage may vary.
-
-Note that this code has been tailored for the PPro/PII in particular,
-and will not perform particuarly well on a Pentium.
-
-If you are using an assembler other than GNU as, you will have to
-translate match.S to use your assembler's syntax. (Have fun.)
-
-Brian Raiter
-breadbox@muppetlabs.com
-April, 1998
-
-
-Added for zlib 1.1.3:
-
-The patches come from
-http://www.muppetlabs.com/~breadbox/software/assembly.html
-
-To compile zlib with this asm file, copy match.S to the zlib directory
-then do:
-
-CFLAGS="-O3 -DASMV" ./configure
-make OBJA=match.o
-
-
-Update:
-
-I've been ignoring these assembly routines for years, believing that
-gcc's generated code had caught up with it sometime around gcc 2.95
-and the major rearchitecting of the Pentium 4. However, I recently
-learned that, despite what I believed, this code still has some life
-in it. On the Pentium 4 and AMD64 chips, it continues to run about 8%
-faster than the code produced by gcc 4.1.
-
-In acknowledgement of its continuing usefulness, I've altered the
-license to match that of the rest of zlib. Share and Enjoy!
-
-Brian Raiter
-breadbox@muppetlabs.com
-April, 2007
diff --git a/cpukit/zlib/contrib/asm686/match.S b/cpukit/zlib/contrib/asm686/match.S
deleted file mode 100644
index 06817e1dd0..0000000000
--- a/cpukit/zlib/contrib/asm686/match.S
+++ /dev/null
@@ -1,343 +0,0 @@
-/* match.S -- x86 assembly version of the zlib longest_match() function.
- * Optimized for the Intel 686 chips (PPro and later).
- *
- * Copyright (C) 1998, 2007 Brian Raiter <breadbox@muppetlabs.com>
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the author be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef NO_UNDERLINE
-#define match_init _match_init
-#define longest_match _longest_match
-#endif
-
-#define MAX_MATCH (258)
-#define MIN_MATCH (3)
-#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
-#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7)
-
-/* stack frame offsets */
-
-#define chainlenwmask 0 /* high word: current chain len */
- /* low word: s->wmask */
-#define window 4 /* local copy of s->window */
-#define windowbestlen 8 /* s->window + bestlen */
-#define scanstart 16 /* first two bytes of string */
-#define scanend 12 /* last two bytes of string */
-#define scanalign 20 /* dword-misalignment of string */
-#define nicematch 24 /* a good enough match size */
-#define bestlen 28 /* size of best match so far */
-#define scan 32 /* ptr to string wanting match */
-
-#define LocalVarsSize (36)
-/* saved ebx 36 */
-/* saved edi 40 */
-/* saved esi 44 */
-/* saved ebp 48 */
-/* return address 52 */
-#define deflatestate 56 /* the function arguments */
-#define curmatch 60
-
-/* All the +zlib1222add offsets are due to the addition of fields
- * in zlib in the deflate_state structure since the asm code was first written
- * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
- * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
- * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
- */
-
-#define zlib1222add (8)
-
-#define dsWSize (36+zlib1222add)
-#define dsWMask (44+zlib1222add)
-#define dsWindow (48+zlib1222add)
-#define dsPrev (56+zlib1222add)
-#define dsMatchLen (88+zlib1222add)
-#define dsPrevMatch (92+zlib1222add)
-#define dsStrStart (100+zlib1222add)
-#define dsMatchStart (104+zlib1222add)
-#define dsLookahead (108+zlib1222add)
-#define dsPrevLen (112+zlib1222add)
-#define dsMaxChainLen (116+zlib1222add)
-#define dsGoodMatch (132+zlib1222add)
-#define dsNiceMatch (136+zlib1222add)
-
-
-.file "match.S"
-
-.globl match_init, longest_match
-
-.text
-
-/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
-
-longest_match:
-
-/* Save registers that the compiler may be using, and adjust %esp to */
-/* make room for our stack frame. */
-
- pushl %ebp
- pushl %edi
- pushl %esi
- pushl %ebx
- subl $LocalVarsSize, %esp
-
-/* Retrieve the function arguments. %ecx will hold cur_match */
-/* throughout the entire function. %edx will hold the pointer to the */
-/* deflate_state structure during the function's setup (before */
-/* entering the main loop). */
-
- movl deflatestate(%esp), %edx
- movl curmatch(%esp), %ecx
-
-/* uInt wmask = s->w_mask; */
-/* unsigned chain_length = s->max_chain_length; */
-/* if (s->prev_length >= s->good_match) { */
-/* chain_length >>= 2; */
-/* } */
-
- movl dsPrevLen(%edx), %eax
- movl dsGoodMatch(%edx), %ebx
- cmpl %ebx, %eax
- movl dsWMask(%edx), %eax
- movl dsMaxChainLen(%edx), %ebx
- jl LastMatchGood
- shrl $2, %ebx
-LastMatchGood:
-
-/* chainlen is decremented once beforehand so that the function can */
-/* use the sign flag instead of the zero flag for the exit test. */
-/* It is then shifted into the high word, to make room for the wmask */
-/* value, which it will always accompany. */
-
- decl %ebx
- shll $16, %ebx
- orl %eax, %ebx
- movl %ebx, chainlenwmask(%esp)
-
-/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */
-
- movl dsNiceMatch(%edx), %eax
- movl dsLookahead(%edx), %ebx
- cmpl %eax, %ebx
- jl LookaheadLess
- movl %eax, %ebx
-LookaheadLess: movl %ebx, nicematch(%esp)
-
-/* register Bytef *scan = s->window + s->strstart; */
-
- movl dsWindow(%edx), %esi
- movl %esi, window(%esp)
- movl dsStrStart(%edx), %ebp
- lea (%esi,%ebp), %edi
- movl %edi, scan(%esp)
-
-/* Determine how many bytes the scan ptr is off from being */
-/* dword-aligned. */
-
- movl %edi, %eax
- negl %eax
- andl $3, %eax
- movl %eax, scanalign(%esp)
-
-/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */
-/* s->strstart - (IPos)MAX_DIST(s) : NIL; */
-
- movl dsWSize(%edx), %eax
- subl $MIN_LOOKAHEAD, %eax
- subl %eax, %ebp
- jg LimitPositive
- xorl %ebp, %ebp
-LimitPositive:
-
-/* int best_len = s->prev_length; */
-
- movl dsPrevLen(%edx), %eax
- movl %eax, bestlen(%esp)
-
-/* Store the sum of s->window + best_len in %esi locally, and in %esi. */
-
- addl %eax, %esi
- movl %esi, windowbestlen(%esp)
-
-/* register ush scan_start = *(ushf*)scan; */
-/* register ush scan_end = *(ushf*)(scan+best_len-1); */
-/* Posf *prev = s->prev; */
-
- movzwl (%edi), %ebx
- movl %ebx, scanstart(%esp)
- movzwl -1(%edi,%eax), %ebx
- movl %ebx, scanend(%esp)
- movl dsPrev(%edx), %edi
-
-/* Jump into the main loop. */
-
- movl chainlenwmask(%esp), %edx
- jmp LoopEntry
-
-.balign 16
-
-/* do {
- * match = s->window + cur_match;
- * if (*(ushf*)(match+best_len-1) != scan_end ||
- * *(ushf*)match != scan_start) continue;
- * [...]
- * } while ((cur_match = prev[cur_match & wmask]) > limit
- * && --chain_length != 0);
- *
- * Here is the inner loop of the function. The function will spend the
- * majority of its time in this loop, and majority of that time will
- * be spent in the first ten instructions.
- *
- * Within this loop:
- * %ebx = scanend
- * %ecx = curmatch
- * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
- * %esi = windowbestlen - i.e., (window + bestlen)
- * %edi = prev
- * %ebp = limit
- */
-LookupLoop:
- andl %edx, %ecx
- movzwl (%edi,%ecx,2), %ecx
- cmpl %ebp, %ecx
- jbe LeaveNow
- subl $0x00010000, %edx
- js LeaveNow
-LoopEntry: movzwl -1(%esi,%ecx), %eax
- cmpl %ebx, %eax
- jnz LookupLoop
- movl window(%esp), %eax
- movzwl (%eax,%ecx), %eax
- cmpl scanstart(%esp), %eax
- jnz LookupLoop
-
-/* Store the current value of chainlen. */
-
- movl %edx, chainlenwmask(%esp)
-
-/* Point %edi to the string under scrutiny, and %esi to the string we */
-/* are hoping to match it up with. In actuality, %esi and %edi are */
-/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */
-/* initialized to -(MAX_MATCH_8 - scanalign). */
-
- movl window(%esp), %esi
- movl scan(%esp), %edi
- addl %ecx, %esi
- movl scanalign(%esp), %eax
- movl $(-MAX_MATCH_8), %edx
- lea MAX_MATCH_8(%edi,%eax), %edi
- lea MAX_MATCH_8(%esi,%eax), %esi
-
-/* Test the strings for equality, 8 bytes at a time. At the end,
- * adjust %edx so that it is offset to the exact byte that mismatched.
- *
- * We already know at this point that the first three bytes of the
- * strings match each other, and they can be safely passed over before
- * starting the compare loop. So what this code does is skip over 0-3
- * bytes, as much as necessary in order to dword-align the %edi
- * pointer. (%esi will still be misaligned three times out of four.)
- *
- * It should be confessed that this loop usually does not represent
- * much of the total running time. Replacing it with a more
- * straightforward "rep cmpsb" would not drastically degrade
- * performance.
- */
-LoopCmps:
- movl (%esi,%edx), %eax
- xorl (%edi,%edx), %eax
- jnz LeaveLoopCmps
- movl 4(%esi,%edx), %eax
- xorl 4(%edi,%edx), %eax
- jnz LeaveLoopCmps4
- addl $8, %edx
- jnz LoopCmps
- jmp LenMaximum
-LeaveLoopCmps4: addl $4, %edx
-LeaveLoopCmps: testl $0x0000FFFF, %eax
- jnz LenLower
- addl $2, %edx
- shrl $16, %eax
-LenLower: subb $1, %al
- adcl $0, %edx
-
-/* Calculate the length of the match. If it is longer than MAX_MATCH, */
-/* then automatically accept it as the best possible match and leave. */
-
- lea (%edi,%edx), %eax
- movl scan(%esp), %edi
- subl %edi, %eax
- cmpl $MAX_MATCH, %eax
- jge LenMaximum
-
-/* If the length of the match is not longer than the best match we */
-/* have so far, then forget it and return to the lookup loop. */
-
- movl deflatestate(%esp), %edx
- movl bestlen(%esp), %ebx
- cmpl %ebx, %eax
- jg LongerMatch
- movl windowbestlen(%esp), %esi
- movl dsPrev(%edx), %edi
- movl scanend(%esp), %ebx
- movl chainlenwmask(%esp), %edx
- jmp LookupLoop
-
-/* s->match_start = cur_match; */
-/* best_len = len; */
-/* if (len >= nice_match) break; */
-/* scan_end = *(ushf*)(scan+best_len-1); */
-
-LongerMatch: movl nicematch(%esp), %ebx
- movl %eax, bestlen(%esp)
- movl %ecx, dsMatchStart(%edx)
- cmpl %ebx, %eax
- jge LeaveNow
- movl window(%esp), %esi
- addl %eax, %esi
- movl %esi, windowbestlen(%esp)
- movzwl -1(%edi,%eax), %ebx
- movl dsPrev(%edx), %edi
- movl %ebx, scanend(%esp)
- movl chainlenwmask(%esp), %edx
- jmp LookupLoop
-
-/* Accept the current string, with the maximum possible length. */
-
-LenMaximum: movl deflatestate(%esp), %edx
- movl $MAX_MATCH, bestlen(%esp)
- movl %ecx, dsMatchStart(%edx)
-
-/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */
-/* return s->lookahead; */
-
-LeaveNow:
- movl deflatestate(%esp), %edx
- movl bestlen(%esp), %ebx
- movl dsLookahead(%edx), %eax
- cmpl %eax, %ebx
- jg LookaheadRet
- movl %ebx, %eax
-LookaheadRet:
-
-/* Restore the stack and return from whence we came. */
-
- addl $LocalVarsSize, %esp
- popl %ebx
- popl %esi
- popl %edi
- popl %ebp
-match_init: ret
diff --git a/cpukit/zlib/contrib/blast/Makefile b/cpukit/zlib/contrib/blast/Makefile
deleted file mode 100644
index 9be80bafe0..0000000000
--- a/cpukit/zlib/contrib/blast/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-blast: blast.c blast.h
- cc -DTEST -o blast blast.c
-
-test: blast
- blast < test.pk | cmp - test.txt
-
-clean:
- rm -f blast blast.o
diff --git a/cpukit/zlib/contrib/blast/README b/cpukit/zlib/contrib/blast/README
deleted file mode 100644
index e3a60b3f5c..0000000000
--- a/cpukit/zlib/contrib/blast/README
+++ /dev/null
@@ -1,4 +0,0 @@
-Read blast.h for purpose and usage.
-
-Mark Adler
-madler@alumni.caltech.edu
diff --git a/cpukit/zlib/contrib/blast/blast.c b/cpukit/zlib/contrib/blast/blast.c
deleted file mode 100644
index 4ce697a41f..0000000000
--- a/cpukit/zlib/contrib/blast/blast.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/* blast.c
- * Copyright (C) 2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in blast.h
- * version 1.1, 16 Feb 2003
- *
- * blast.c decompresses data compressed by the PKWare Compression Library.
- * This function provides functionality similar to the explode() function of
- * the PKWare library, hence the name "blast".
- *
- * This decompressor is based on the excellent format description provided by
- * Ben Rudiak-Gould in comp.compression on August 13, 2001. Interestingly, the
- * example Ben provided in the post is incorrect. The distance 110001 should
- * instead be 111000. When corrected, the example byte stream becomes:
- *
- * 00 04 82 24 25 8f 80 7f
- *
- * which decompresses to "AIAIAIAIAIAIA" (without the quotes).
- */
-
-/*
- * Change history:
- *
- * 1.0 12 Feb 2003 - First version
- * 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data
- */
-
-#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
-#include "blast.h" /* prototype for blast() */
-
-#define local static /* for local function definitions */
-#define MAXBITS 13 /* maximum code length */
-#define MAXWIN 4096 /* maximum window size */
-
-/* input and output state */
-struct state {
- /* input state */
- blast_in infun; /* input function provided by user */
- void *inhow; /* opaque information passed to infun() */
- unsigned char *in; /* next input location */
- unsigned left; /* available input at in */
- int bitbuf; /* bit buffer */
- int bitcnt; /* number of bits in bit buffer */
-
- /* input limit error return state for bits() and decode() */
- jmp_buf env;
-
- /* output state */
- blast_out outfun; /* output function provided by user */
- void *outhow; /* opaque information passed to outfun() */
- unsigned next; /* index of next write location in out[] */
- int first; /* true to check distances (for first 4K) */
- unsigned char out[MAXWIN]; /* output buffer and sliding window */
-};
-
-/*
- * Return need bits from the input stream. This always leaves less than
- * eight bits in the buffer. bits() works properly for need == 0.
- *
- * Format notes:
- *
- * - Bits are stored in bytes from the least significant bit to the most
- * significant bit. Therefore bits are dropped from the bottom of the bit
- * buffer, using shift right, and new bytes are appended to the top of the
- * bit buffer, using shift left.
- */
-local int bits(struct state *s, int need)
-{
- int val; /* bit accumulator */
-
- /* load at least need bits into val */
- val = s->bitbuf;
- while (s->bitcnt < need) {
- if (s->left == 0) {
- s->left = s->infun(s->inhow, &(s->in));
- if (s->left == 0) longjmp(s->env, 1); /* out of input */
- }
- val |= (int)(*(s->in)++) << s->bitcnt; /* load eight bits */
- s->left--;
- s->bitcnt += 8;
- }
-
- /* drop need bits and update buffer, always zero to seven bits left */
- s->bitbuf = val >> need;
- s->bitcnt -= need;
-
- /* return need bits, zeroing the bits above that */
- return val & ((1 << need) - 1);
-}
-
-/*
- * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of
- * each length, which for a canonical code are stepped through in order.
- * symbol[] are the symbol values in canonical order, where the number of
- * entries is the sum of the counts in count[]. The decoding process can be
- * seen in the function decode() below.
- */
-struct huffman {
- short *count; /* number of symbols of each length */
- short *symbol; /* canonically ordered symbols */
-};
-
-/*
- * Decode a code from the stream s using huffman table h. Return the symbol or
- * a negative value if there is an error. If all of the lengths are zero, i.e.
- * an empty code, or if the code is incomplete and an invalid code is received,
- * then -9 is returned after reading MAXBITS bits.
- *
- * Format notes:
- *
- * - The codes as stored in the compressed data are bit-reversed relative to
- * a simple integer ordering of codes of the same lengths. Hence below the
- * bits are pulled from the compressed data one at a time and used to
- * build the code value reversed from what is in the stream in order to
- * permit simple integer comparisons for decoding.
- *
- * - The first code for the shortest length is all ones. Subsequent codes of
- * the same length are simply integer decrements of the previous code. When
- * moving up a length, a one bit is appended to the code. For a complete
- * code, the last code of the longest length will be all zeros. To support
- * this ordering, the bits pulled during decoding are inverted to apply the
- * more "natural" ordering starting with all zeros and incrementing.
- */
-local int decode(struct state *s, struct huffman *h)
-{
- int len; /* current number of bits in code */
- int code; /* len bits being decoded */
- int first; /* first code of length len */
- int count; /* number of codes of length len */
- int index; /* index of first code of length len in symbol table */
- int bitbuf; /* bits from stream */
- int left; /* bits left in next or left to process */
- short *next; /* next number of codes */
-
- bitbuf = s->bitbuf;
- left = s->bitcnt;
- code = first = index = 0;
- len = 1;
- next = h->count + 1;
- while (1) {
- while (left--) {
- code |= (bitbuf & 1) ^ 1; /* invert code */
- bitbuf >>= 1;
- count = *next++;
- if (code < first + count) { /* if length len, return symbol */
- s->bitbuf = bitbuf;
- s->bitcnt = (s->bitcnt - len) & 7;
- return h->symbol[index + (code - first)];
- }
- index += count; /* else update for next length */
- first += count;
- first <<= 1;
- code <<= 1;
- len++;
- }
- left = (MAXBITS+1) - len;
- if (left == 0) break;
- if (s->left == 0) {
- s->left = s->infun(s->inhow, &(s->in));
- if (s->left == 0) longjmp(s->env, 1); /* out of input */
- }
- bitbuf = *(s->in)++;
- s->left--;
- if (left > 8) left = 8;
- }
- return -9; /* ran out of codes */
-}
-
-/*
- * Given a list of repeated code lengths rep[0..n-1], where each byte is a
- * count (high four bits + 1) and a code length (low four bits), generate the
- * list of code lengths. This compaction reduces the size of the object code.
- * Then given the list of code lengths length[0..n-1] representing a canonical
- * Huffman code for n symbols, construct the tables required to decode those
- * codes. Those tables are the number of codes of each length, and the symbols
- * sorted by length, retaining their original order within each length. The
- * return value is zero for a complete code set, negative for an over-
- * subscribed code set, and positive for an incomplete code set. The tables
- * can be used if the return value is zero or positive, but they cannot be used
- * if the return value is negative. If the return value is zero, it is not
- * possible for decode() using that table to return an error--any stream of
- * enough bits will resolve to a symbol. If the return value is positive, then
- * it is possible for decode() using that table to return an error for received
- * codes past the end of the incomplete lengths.
- */
-local int construct(struct huffman *h, const unsigned char *rep, int n)
-{
- int symbol; /* current symbol when stepping through length[] */
- int len; /* current length when stepping through h->count[] */
- int left; /* number of possible codes left of current length */
- short offs[MAXBITS+1]; /* offsets in symbol table for each length */
- short length[256]; /* code lengths */
-
- /* convert compact repeat counts into symbol bit length list */
- symbol = 0;
- do {
- len = *rep++;
- left = (len >> 4) + 1;
- len &= 15;
- do {
- length[symbol++] = len;
- } while (--left);
- } while (--n);
- n = symbol;
-
- /* count number of codes of each length */
- for (len = 0; len <= MAXBITS; len++)
- h->count[len] = 0;
- for (symbol = 0; symbol < n; symbol++)
- (h->count[length[symbol]])++; /* assumes lengths are within bounds */
- if (h->count[0] == n) /* no codes! */
- return 0; /* complete, but decode() will fail */
-
- /* check for an over-subscribed or incomplete set of lengths */
- left = 1; /* one possible code of zero length */
- for (len = 1; len <= MAXBITS; len++) {
- left <<= 1; /* one more bit, double codes left */
- left -= h->count[len]; /* deduct count from possible codes */
- if (left < 0) return left; /* over-subscribed--return negative */
- } /* left > 0 means incomplete */
-
- /* generate offsets into symbol table for each length for sorting */
- offs[1] = 0;
- for (len = 1; len < MAXBITS; len++)
- offs[len + 1] = offs[len] + h->count[len];
-
- /*
- * put symbols in table sorted by length, by symbol order within each
- * length
- */
- for (symbol = 0; symbol < n; symbol++)
- if (length[symbol] != 0)
- h->symbol[offs[length[symbol]]++] = symbol;
-
- /* return zero for complete set, positive for incomplete set */
- return left;
-}
-
-/*
- * Decode PKWare Compression Library stream.
- *
- * Format notes:
- *
- * - First byte is 0 if literals are uncoded or 1 if they are coded. Second
- * byte is 4, 5, or 6 for the number of extra bits in the distance code.
- * This is the base-2 logarithm of the dictionary size minus six.
- *
- * - Compressed data is a combination of literals and length/distance pairs
- * terminated by an end code. Literals are either Huffman coded or
- * uncoded bytes. A length/distance pair is a coded length followed by a
- * coded distance to represent a string that occurs earlier in the
- * uncompressed data that occurs again at the current location.
- *
- * - A bit preceding a literal or length/distance pair indicates which comes
- * next, 0 for literals, 1 for length/distance.
- *
- * - If literals are uncoded, then the next eight bits are the literal, in the
- * normal bit order in th stream, i.e. no bit-reversal is needed. Similarly,
- * no bit reversal is needed for either the length extra bits or the distance
- * extra bits.
- *
- * - Literal bytes are simply written to the output. A length/distance pair is
- * an instruction to copy previously uncompressed bytes to the output. The
- * copy is from distance bytes back in the output stream, copying for length
- * bytes.
- *
- * - Distances pointing before the beginning of the output data are not
- * permitted.
- *
- * - Overlapped copies, where the length is greater than the distance, are
- * allowed and common. For example, a distance of one and a length of 518
- * simply copies the last byte 518 times. A distance of four and a length of
- * twelve copies the last four bytes three times. A simple forward copy
- * ignoring whether the length is greater than the distance or not implements
- * this correctly.
- */
-local int decomp(struct state *s)
-{
- int lit; /* true if literals are coded */
- int dict; /* log2(dictionary size) - 6 */
- int symbol; /* decoded symbol, extra bits for distance */
- int len; /* length for copy */
- int dist; /* distance for copy */
- int copy; /* copy counter */
- unsigned char *from, *to; /* copy pointers */
- static int virgin = 1; /* build tables once */
- static short litcnt[MAXBITS+1], litsym[256]; /* litcode memory */
- static short lencnt[MAXBITS+1], lensym[16]; /* lencode memory */
- static short distcnt[MAXBITS+1], distsym[64]; /* distcode memory */
- static struct huffman litcode = {litcnt, litsym}; /* length code */
- static struct huffman lencode = {lencnt, lensym}; /* length code */
- static struct huffman distcode = {distcnt, distsym};/* distance code */
- /* bit lengths of literal codes */
- static const unsigned char litlen[] = {
- 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8,
- 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5,
- 7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12,
- 8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27,
- 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45,
- 44, 173};
- /* bit lengths of length codes 0..15 */
- static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23};
- /* bit lengths of distance codes 0..63 */
- static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248};
- static const short base[16] = { /* base for length codes */
- 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264};
- static const char extra[16] = { /* extra bits for length codes */
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8};
-
- /* set up decoding tables (once--might not be thread-safe) */
- if (virgin) {
- construct(&litcode, litlen, sizeof(litlen));
- construct(&lencode, lenlen, sizeof(lenlen));
- construct(&distcode, distlen, sizeof(distlen));
- virgin = 0;
- }
-
- /* read header */
- lit = bits(s, 8);
- if (lit > 1) return -1;
- dict = bits(s, 8);
- if (dict < 4 || dict > 6) return -2;
-
- /* decode literals and length/distance pairs */
- do {
- if (bits(s, 1)) {
- /* get length */
- symbol = decode(s, &lencode);
- len = base[symbol] + bits(s, extra[symbol]);
- if (len == 519) break; /* end code */
-
- /* get distance */
- symbol = len == 2 ? 2 : dict;
- dist = decode(s, &distcode) << symbol;
- dist += bits(s, symbol);
- dist++;
- if (s->first && dist > s->next)
- return -3; /* distance too far back */
-
- /* copy length bytes from distance bytes back */
- do {
- to = s->out + s->next;
- from = to - dist;
- copy = MAXWIN;
- if (s->next < dist) {
- from += copy;
- copy = dist;
- }
- copy -= s->next;
- if (copy > len) copy = len;
- len -= copy;
- s->next += copy;
- do {
- *to++ = *from++;
- } while (--copy);
- if (s->next == MAXWIN) {
- if (s->outfun(s->outhow, s->out, s->next)) return 1;
- s->next = 0;
- s->first = 0;
- }
- } while (len != 0);
- }
- else {
- /* get literal and write it */
- symbol = lit ? decode(s, &litcode) : bits(s, 8);
- s->out[s->next++] = symbol;
- if (s->next == MAXWIN) {
- if (s->outfun(s->outhow, s->out, s->next)) return 1;
- s->next = 0;
- s->first = 0;
- }
- }
- } while (1);
- return 0;
-}
-
-/* See comments in blast.h */
-int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
-{
- struct state s; /* input/output state */
- int err; /* return value */
-
- /* initialize input state */
- s.infun = infun;
- s.inhow = inhow;
- s.left = 0;
- s.bitbuf = 0;
- s.bitcnt = 0;
-
- /* initialize output state */
- s.outfun = outfun;
- s.outhow = outhow;
- s.next = 0;
- s.first = 1;
-
- /* return if bits() or decode() tries to read past available input */
- if (setjmp(s.env) != 0) /* if came back here via longjmp(), */
- err = 2; /* then skip decomp(), return error */
- else
- err = decomp(&s); /* decompress */
-
- /* write any leftover output and update the error code if needed */
- if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0)
- err = 1;
- return err;
-}
-
-#ifdef TEST
-/* Example of how to use blast() */
-#include <stdio.h>
-#include <stdlib.h>
-
-#define CHUNK 16384
-
-local unsigned inf(void *how, unsigned char **buf)
-{
- static unsigned char hold[CHUNK];
-
- *buf = hold;
- return fread(hold, 1, CHUNK, (FILE *)how);
-}
-
-local int outf(void *how, unsigned char *buf, unsigned len)
-{
- return fwrite(buf, 1, len, (FILE *)how) != len;
-}
-
-/* Decompress a PKWare Compression Library stream from stdin to stdout */
-int main(void)
-{
- int ret, n;
-
- /* decompress to stdout */
- ret = blast(inf, stdin, outf, stdout);
- if (ret != 0) fprintf(stderr, "blast error: %d\n", ret);
-
- /* see if there are any leftover bytes */
- n = 0;
- while (getchar() != EOF) n++;
- if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n);
-
- /* return blast() error code */
- return ret;
-}
-#endif
diff --git a/cpukit/zlib/contrib/blast/blast.h b/cpukit/zlib/contrib/blast/blast.h
deleted file mode 100644
index ce9e5410f4..0000000000
--- a/cpukit/zlib/contrib/blast/blast.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* blast.h -- interface for blast.c
- Copyright (C) 2003 Mark Adler
- version 1.1, 16 Feb 2003
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Mark Adler madler@alumni.caltech.edu
- */
-
-
-/*
- * blast() decompresses the PKWare Data Compression Library (DCL) compressed
- * format. It provides the same functionality as the explode() function in
- * that library. (Note: PKWare overused the "implode" verb, and the format
- * used by their library implode() function is completely different and
- * incompatible with the implode compression method supported by PKZIP.)
- */
-
-
-typedef unsigned (*blast_in)(void *how, unsigned char **buf);
-typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
-/* Definitions for input/output functions passed to blast(). See below for
- * what the provided functions need to do.
- */
-
-
-int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
-/* Decompress input to output using the provided infun() and outfun() calls.
- * On success, the return value of blast() is zero. If there is an error in
- * the source data, i.e. it is not in the proper format, then a negative value
- * is returned. If there is not enough input available or there is not enough
- * output space, then a positive error is returned.
- *
- * The input function is invoked: len = infun(how, &buf), where buf is set by
- * infun() to point to the input buffer, and infun() returns the number of
- * available bytes there. If infun() returns zero, then blast() returns with
- * an input error. (blast() only asks for input if it needs it.) inhow is for
- * use by the application to pass an input descriptor to infun(), if desired.
- *
- * The output function is invoked: err = outfun(how, buf, len), where the bytes
- * to be written are buf[0..len-1]. If err is not zero, then blast() returns
- * with an output error. outfun() is always called with len <= 4096. outhow
- * is for use by the application to pass an output descriptor to outfun(), if
- * desired.
- *
- * The return codes are:
- *
- * 2: ran out of input before completing decompression
- * 1: output error before completing decompression
- * 0: successful decompression
- * -1: literal flag not zero or one
- * -2: dictionary size not in 4..6
- * -3: distance is too far back
- *
- * At the bottom of blast.c is an example program that uses blast() that can be
- * compiled to produce a command-line decompression filter by defining TEST.
- */
diff --git a/cpukit/zlib/contrib/blast/test.pk b/cpukit/zlib/contrib/blast/test.pk
deleted file mode 100644
index be10b2bbb2..0000000000
--- a/cpukit/zlib/contrib/blast/test.pk
+++ /dev/null
Binary files differ
diff --git a/cpukit/zlib/contrib/blast/test.txt b/cpukit/zlib/contrib/blast/test.txt
deleted file mode 100644
index bfdf1c5dca..0000000000
--- a/cpukit/zlib/contrib/blast/test.txt
+++ /dev/null
@@ -1 +0,0 @@
-AIAIAIAIAIAIA \ No newline at end of file
diff --git a/cpukit/zlib/contrib/delphi/ZLib.pas b/cpukit/zlib/contrib/delphi/ZLib.pas
deleted file mode 100644
index 179f9a90cc..0000000000
--- a/cpukit/zlib/contrib/delphi/ZLib.pas
+++ /dev/null
@@ -1,557 +0,0 @@
-{*******************************************************}
-{ }
-{ Borland Delphi Supplemental Components }
-{ ZLIB Data Compression Interface Unit }
-{ }
-{ Copyright (c) 1997,99 Borland Corporation }
-{ }
-{*******************************************************}
-
-{ Updated for zlib 1.2.x by Cosmin Truta <cosmint@cs.ubbcluj.ro> }
-
-unit ZLib;
-
-interface
-
-uses SysUtils, Classes;
-
-type
- TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer; cdecl;
- TFree = procedure (AppData, Block: Pointer); cdecl;
-
- // Internal structure. Ignore.
- TZStreamRec = packed record
- next_in: PChar; // next input byte
- avail_in: Integer; // number of bytes available at next_in
- total_in: Longint; // total nb of input bytes read so far
-
- next_out: PChar; // next output byte should be put here
- avail_out: Integer; // remaining free space at next_out
- total_out: Longint; // total nb of bytes output so far
-
- msg: PChar; // last error message, NULL if no error
- internal: Pointer; // not visible by applications
-
- zalloc: TAlloc; // used to allocate the internal state
- zfree: TFree; // used to free the internal state
- AppData: Pointer; // private data object passed to zalloc and zfree
-
- data_type: Integer; // best guess about the data type: ascii or binary
- adler: Longint; // adler32 value of the uncompressed data
- reserved: Longint; // reserved for future use
- end;
-
- // Abstract ancestor class
- TCustomZlibStream = class(TStream)
- private
- FStrm: TStream;
- FStrmPos: Integer;
- FOnProgress: TNotifyEvent;
- FZRec: TZStreamRec;
- FBuffer: array [Word] of Char;
- protected
- procedure Progress(Sender: TObject); dynamic;
- property OnProgress: TNotifyEvent read FOnProgress write FOnProgress;
- constructor Create(Strm: TStream);
- end;
-
-{ TCompressionStream compresses data on the fly as data is written to it, and
- stores the compressed data to another stream.
-
- TCompressionStream is write-only and strictly sequential. Reading from the
- stream will raise an exception. Using Seek to move the stream pointer
- will raise an exception.
-
- Output data is cached internally, written to the output stream only when
- the internal output buffer is full. All pending output data is flushed
- when the stream is destroyed.
-
- The Position property returns the number of uncompressed bytes of
- data that have been written to the stream so far.
-
- CompressionRate returns the on-the-fly percentage by which the original
- data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100
- If raw data size = 100 and compressed data size = 25, the CompressionRate
- is 75%
-
- The OnProgress event is called each time the output buffer is filled and
- written to the output stream. This is useful for updating a progress
- indicator when you are writing a large chunk of data to the compression
- stream in a single call.}
-
-
- TCompressionLevel = (clNone, clFastest, clDefault, clMax);
-
- TCompressionStream = class(TCustomZlibStream)
- private
- function GetCompressionRate: Single;
- public
- constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream);
- destructor Destroy; override;
- function Read(var Buffer; Count: Longint): Longint; override;
- function Write(const Buffer; Count: Longint): Longint; override;
- function Seek(Offset: Longint; Origin: Word): Longint; override;
- property CompressionRate: Single read GetCompressionRate;
- property OnProgress;
- end;
-
-{ TDecompressionStream decompresses data on the fly as data is read from it.
-
- Compressed data comes from a separate source stream. TDecompressionStream
- is read-only and unidirectional; you can seek forward in the stream, but not
- backwards. The special case of setting the stream position to zero is
- allowed. Seeking forward decompresses data until the requested position in
- the uncompressed data has been reached. Seeking backwards, seeking relative
- to the end of the stream, requesting the size of the stream, and writing to
- the stream will raise an exception.
-
- The Position property returns the number of bytes of uncompressed data that
- have been read from the stream so far.
-
- The OnProgress event is called each time the internal input buffer of
- compressed data is exhausted and the next block is read from the input stream.
- This is useful for updating a progress indicator when you are reading a
- large chunk of data from the decompression stream in a single call.}
-
- TDecompressionStream = class(TCustomZlibStream)
- public
- constructor Create(Source: TStream);
- destructor Destroy; override;
- function Read(var Buffer; Count: Longint): Longint; override;
- function Write(const Buffer; Count: Longint): Longint; override;
- function Seek(Offset: Longint; Origin: Word): Longint; override;
- property OnProgress;
- end;
-
-
-
-{ CompressBuf compresses data, buffer to buffer, in one call.
- In: InBuf = ptr to compressed data
- InBytes = number of bytes in InBuf
- Out: OutBuf = ptr to newly allocated buffer containing decompressed data
- OutBytes = number of bytes in OutBuf }
-procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
- out OutBuf: Pointer; out OutBytes: Integer);
-
-
-{ DecompressBuf decompresses data, buffer to buffer, in one call.
- In: InBuf = ptr to compressed data
- InBytes = number of bytes in InBuf
- OutEstimate = zero, or est. size of the decompressed data
- Out: OutBuf = ptr to newly allocated buffer containing decompressed data
- OutBytes = number of bytes in OutBuf }
-procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
- OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
-
-{ DecompressToUserBuf decompresses data, buffer to buffer, in one call.
- In: InBuf = ptr to compressed data
- InBytes = number of bytes in InBuf
- Out: OutBuf = ptr to user-allocated buffer to contain decompressed data
- BufSize = number of bytes in OutBuf }
-procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
- const OutBuf: Pointer; BufSize: Integer);
-
-const
- zlib_version = '1.2.4';
-
-type
- EZlibError = class(Exception);
- ECompressionError = class(EZlibError);
- EDecompressionError = class(EZlibError);
-
-implementation
-
-uses ZLibConst;
-
-const
- Z_NO_FLUSH = 0;
- Z_PARTIAL_FLUSH = 1;
- Z_SYNC_FLUSH = 2;
- Z_FULL_FLUSH = 3;
- Z_FINISH = 4;
-
- Z_OK = 0;
- Z_STREAM_END = 1;
- Z_NEED_DICT = 2;
- Z_ERRNO = (-1);
- Z_STREAM_ERROR = (-2);
- Z_DATA_ERROR = (-3);
- Z_MEM_ERROR = (-4);
- Z_BUF_ERROR = (-5);
- Z_VERSION_ERROR = (-6);
-
- Z_NO_COMPRESSION = 0;
- Z_BEST_SPEED = 1;
- Z_BEST_COMPRESSION = 9;
- Z_DEFAULT_COMPRESSION = (-1);
-
- Z_FILTERED = 1;
- Z_HUFFMAN_ONLY = 2;
- Z_RLE = 3;
- Z_DEFAULT_STRATEGY = 0;
-
- Z_BINARY = 0;
- Z_ASCII = 1;
- Z_UNKNOWN = 2;
-
- Z_DEFLATED = 8;
-
-
-{$L adler32.obj}
-{$L compress.obj}
-{$L crc32.obj}
-{$L deflate.obj}
-{$L infback.obj}
-{$L inffast.obj}
-{$L inflate.obj}
-{$L inftrees.obj}
-{$L trees.obj}
-{$L uncompr.obj}
-{$L zutil.obj}
-
-procedure adler32; external;
-procedure compressBound; external;
-procedure crc32; external;
-procedure deflateInit2_; external;
-procedure deflateParams; external;
-
-function _malloc(Size: Integer): Pointer; cdecl;
-begin
- Result := AllocMem(Size);
-end;
-
-procedure _free(Block: Pointer); cdecl;
-begin
- FreeMem(Block);
-end;
-
-procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
-begin
- FillChar(P^, count, B);
-end;
-
-procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
-begin
- Move(source^, dest^, count);
-end;
-
-
-
-// deflate compresses data
-function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;
- recsize: Integer): Integer; external;
-function deflate(var strm: TZStreamRec; flush: Integer): Integer; external;
-function deflateEnd(var strm: TZStreamRec): Integer; external;
-
-// inflate decompresses data
-function inflateInit_(var strm: TZStreamRec; version: PChar;
- recsize: Integer): Integer; external;
-function inflate(var strm: TZStreamRec; flush: Integer): Integer; external;
-function inflateEnd(var strm: TZStreamRec): Integer; external;
-function inflateReset(var strm: TZStreamRec): Integer; external;
-
-
-function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl;
-begin
-// GetMem(Result, Items*Size);
- Result := AllocMem(Items * Size);
-end;
-
-procedure zlibFreeMem(AppData, Block: Pointer); cdecl;
-begin
- FreeMem(Block);
-end;
-
-{function zlibCheck(code: Integer): Integer;
-begin
- Result := code;
- if code < 0 then
- raise EZlibError.Create('error'); //!!
-end;}
-
-function CCheck(code: Integer): Integer;
-begin
- Result := code;
- if code < 0 then
- raise ECompressionError.Create('error'); //!!
-end;
-
-function DCheck(code: Integer): Integer;
-begin
- Result := code;
- if code < 0 then
- raise EDecompressionError.Create('error'); //!!
-end;
-
-procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
- out OutBuf: Pointer; out OutBytes: Integer);
-var
- strm: TZStreamRec;
- P: Pointer;
-begin
- FillChar(strm, sizeof(strm), 0);
- strm.zalloc := zlibAllocMem;
- strm.zfree := zlibFreeMem;
- OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255;
- GetMem(OutBuf, OutBytes);
- try
- strm.next_in := InBuf;
- strm.avail_in := InBytes;
- strm.next_out := OutBuf;
- strm.avail_out := OutBytes;
- CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
- try
- while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do
- begin
- P := OutBuf;
- Inc(OutBytes, 256);
- ReallocMem(OutBuf, OutBytes);
- strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
- strm.avail_out := 256;
- end;
- finally
- CCheck(deflateEnd(strm));
- end;
- ReallocMem(OutBuf, strm.total_out);
- OutBytes := strm.total_out;
- except
- FreeMem(OutBuf);
- raise
- end;
-end;
-
-
-procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
- OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
-var
- strm: TZStreamRec;
- P: Pointer;
- BufInc: Integer;
-begin
- FillChar(strm, sizeof(strm), 0);
- strm.zalloc := zlibAllocMem;
- strm.zfree := zlibFreeMem;
- BufInc := (InBytes + 255) and not 255;
- if OutEstimate = 0 then
- OutBytes := BufInc
- else
- OutBytes := OutEstimate;
- GetMem(OutBuf, OutBytes);
- try
- strm.next_in := InBuf;
- strm.avail_in := InBytes;
- strm.next_out := OutBuf;
- strm.avail_out := OutBytes;
- DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
- try
- while DCheck(inflate(strm, Z_NO_FLUSH)) <> Z_STREAM_END do
- begin
- P := OutBuf;
- Inc(OutBytes, BufInc);
- ReallocMem(OutBuf, OutBytes);
- strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
- strm.avail_out := BufInc;
- end;
- finally
- DCheck(inflateEnd(strm));
- end;
- ReallocMem(OutBuf, strm.total_out);
- OutBytes := strm.total_out;
- except
- FreeMem(OutBuf);
- raise
- end;
-end;
-
-procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
- const OutBuf: Pointer; BufSize: Integer);
-var
- strm: TZStreamRec;
-begin
- FillChar(strm, sizeof(strm), 0);
- strm.zalloc := zlibAllocMem;
- strm.zfree := zlibFreeMem;
- strm.next_in := InBuf;
- strm.avail_in := InBytes;
- strm.next_out := OutBuf;
- strm.avail_out := BufSize;
- DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
- try
- if DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END then
- raise EZlibError.CreateRes(@sTargetBufferTooSmall);
- finally
- DCheck(inflateEnd(strm));
- end;
-end;
-
-// TCustomZlibStream
-
-constructor TCustomZLibStream.Create(Strm: TStream);
-begin
- inherited Create;
- FStrm := Strm;
- FStrmPos := Strm.Position;
- FZRec.zalloc := zlibAllocMem;
- FZRec.zfree := zlibFreeMem;
-end;
-
-procedure TCustomZLibStream.Progress(Sender: TObject);
-begin
- if Assigned(FOnProgress) then FOnProgress(Sender);
-end;
-
-
-// TCompressionStream
-
-constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel;
- Dest: TStream);
-const
- Levels: array [TCompressionLevel] of ShortInt =
- (Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION);
-begin
- inherited Create(Dest);
- FZRec.next_out := FBuffer;
- FZRec.avail_out := sizeof(FBuffer);
- CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec)));
-end;
-
-destructor TCompressionStream.Destroy;
-begin
- FZRec.next_in := nil;
- FZRec.avail_in := 0;
- try
- if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
- while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END)
- and (FZRec.avail_out = 0) do
- begin
- FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
- FZRec.next_out := FBuffer;
- FZRec.avail_out := sizeof(FBuffer);
- end;
- if FZRec.avail_out < sizeof(FBuffer) then
- FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out);
- finally
- deflateEnd(FZRec);
- end;
- inherited Destroy;
-end;
-
-function TCompressionStream.Read(var Buffer; Count: Longint): Longint;
-begin
- raise ECompressionError.CreateRes(@sInvalidStreamOp);
-end;
-
-function TCompressionStream.Write(const Buffer; Count: Longint): Longint;
-begin
- FZRec.next_in := @Buffer;
- FZRec.avail_in := Count;
- if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
- while (FZRec.avail_in > 0) do
- begin
- CCheck(deflate(FZRec, 0));
- if FZRec.avail_out = 0 then
- begin
- FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
- FZRec.next_out := FBuffer;
- FZRec.avail_out := sizeof(FBuffer);
- FStrmPos := FStrm.Position;
- Progress(Self);
- end;
- end;
- Result := Count;
-end;
-
-function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
-begin
- if (Offset = 0) and (Origin = soFromCurrent) then
- Result := FZRec.total_in
- else
- raise ECompressionError.CreateRes(@sInvalidStreamOp);
-end;
-
-function TCompressionStream.GetCompressionRate: Single;
-begin
- if FZRec.total_in = 0 then
- Result := 0
- else
- Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0;
-end;
-
-
-// TDecompressionStream
-
-constructor TDecompressionStream.Create(Source: TStream);
-begin
- inherited Create(Source);
- FZRec.next_in := FBuffer;
- FZRec.avail_in := 0;
- DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec)));
-end;
-
-destructor TDecompressionStream.Destroy;
-begin
- FStrm.Seek(-FZRec.avail_in, 1);
- inflateEnd(FZRec);
- inherited Destroy;
-end;
-
-function TDecompressionStream.Read(var Buffer; Count: Longint): Longint;
-begin
- FZRec.next_out := @Buffer;
- FZRec.avail_out := Count;
- if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
- while (FZRec.avail_out > 0) do
- begin
- if FZRec.avail_in = 0 then
- begin
- FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer));
- if FZRec.avail_in = 0 then
- begin
- Result := Count - FZRec.avail_out;
- Exit;
- end;
- FZRec.next_in := FBuffer;
- FStrmPos := FStrm.Position;
- Progress(Self);
- end;
- CCheck(inflate(FZRec, 0));
- end;
- Result := Count;
-end;
-
-function TDecompressionStream.Write(const Buffer; Count: Longint): Longint;
-begin
- raise EDecompressionError.CreateRes(@sInvalidStreamOp);
-end;
-
-function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
-var
- I: Integer;
- Buf: array [0..4095] of Char;
-begin
- if (Offset = 0) and (Origin = soFromBeginning) then
- begin
- DCheck(inflateReset(FZRec));
- FZRec.next_in := FBuffer;
- FZRec.avail_in := 0;
- FStrm.Position := 0;
- FStrmPos := 0;
- end
- else if ( (Offset >= 0) and (Origin = soFromCurrent)) or
- ( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then
- begin
- if Origin = soFromBeginning then Dec(Offset, FZRec.total_out);
- if Offset > 0 then
- begin
- for I := 1 to Offset div sizeof(Buf) do
- ReadBuffer(Buf, sizeof(Buf));
- ReadBuffer(Buf, Offset mod sizeof(Buf));
- end;
- end
- else
- raise EDecompressionError.CreateRes(@sInvalidStreamOp);
- Result := FZRec.total_out;
-end;
-
-
-end.
diff --git a/cpukit/zlib/contrib/delphi/ZLibConst.pas b/cpukit/zlib/contrib/delphi/ZLibConst.pas
deleted file mode 100644
index cdfe13671d..0000000000
--- a/cpukit/zlib/contrib/delphi/ZLibConst.pas
+++ /dev/null
@@ -1,11 +0,0 @@
-unit ZLibConst;
-
-interface
-
-resourcestring
- sTargetBufferTooSmall = 'ZLib error: target buffer may be too small';
- sInvalidStreamOp = 'Invalid stream operation';
-
-implementation
-
-end.
diff --git a/cpukit/zlib/contrib/delphi/readme.txt b/cpukit/zlib/contrib/delphi/readme.txt
deleted file mode 100644
index 2dc9a8bba2..0000000000
--- a/cpukit/zlib/contrib/delphi/readme.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-
-Overview
-========
-
-This directory contains an update to the ZLib interface unit,
-distributed by Borland as a Delphi supplemental component.
-
-The original ZLib unit is Copyright (c) 1997,99 Borland Corp.,
-and is based on zlib version 1.0.4. There are a series of bugs
-and security problems associated with that old zlib version, and
-we recommend the users to update their ZLib unit.
-
-
-Summary of modifications
-========================
-
-- Improved makefile, adapted to zlib version 1.2.1.
-
-- Some field types from TZStreamRec are changed from Integer to
- Longint, for consistency with the zlib.h header, and for 64-bit
- readiness.
-
-- The zlib_version constant is updated.
-
-- The new Z_RLE strategy has its corresponding symbolic constant.
-
-- The allocation and deallocation functions and function types
- (TAlloc, TFree, zlibAllocMem and zlibFreeMem) are now cdecl,
- and _malloc and _free are added as C RTL stubs. As a result,
- the original C sources of zlib can be compiled out of the box,
- and linked to the ZLib unit.
-
-
-Suggestions for improvements
-============================
-
-Currently, the ZLib unit provides only a limited wrapper around
-the zlib library, and much of the original zlib functionality is
-missing. Handling compressed file formats like ZIP/GZIP or PNG
-cannot be implemented without having this functionality.
-Applications that handle these formats are either using their own,
-duplicated code, or not using the ZLib unit at all.
-
-Here are a few suggestions:
-
-- Checksum class wrappers around adler32() and crc32(), similar
- to the Java classes that implement the java.util.zip.Checksum
- interface.
-
-- The ability to read and write raw deflate streams, without the
- zlib stream header and trailer. Raw deflate streams are used
- in the ZIP file format.
-
-- The ability to read and write gzip streams, used in the GZIP
- file format, and normally produced by the gzip program.
-
-- The ability to select a different compression strategy, useful
- to PNG and MNG image compression, and to multimedia compression
- in general. Besides the compression level
-
- TCompressionLevel = (clNone, clFastest, clDefault, clMax);
-
- which, in fact, could have used the 'z' prefix and avoided
- TColor-like symbols
-
- TCompressionLevel = (zcNone, zcFastest, zcDefault, zcMax);
-
- there could be a compression strategy
-
- TCompressionStrategy = (zsDefault, zsFiltered, zsHuffmanOnly, zsRle);
-
-- ZIP and GZIP stream handling via TStreams.
-
-
---
-Cosmin Truta <cosmint@cs.ubbcluj.ro>
diff --git a/cpukit/zlib/contrib/delphi/zlibd32.mak b/cpukit/zlib/contrib/delphi/zlibd32.mak
deleted file mode 100644
index 0d0699a69a..0000000000
--- a/cpukit/zlib/contrib/delphi/zlibd32.mak
+++ /dev/null
@@ -1,99 +0,0 @@
-# Makefile for zlib
-# For use with Delphi and C++ Builder under Win32
-# Updated for zlib 1.2.x by Cosmin Truta
-
-# ------------ Borland C++ ------------
-
-# This project uses the Delphi (fastcall/register) calling convention:
-LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl
-
-CC = bcc32
-LD = bcc32
-AR = tlib
-# do not use "-pr" in CFLAGS
-CFLAGS = -a -d -k- -O2 $(LOC)
-LDFLAGS =
-
-
-# variables
-ZLIB_LIB = zlib.lib
-
-OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj
-OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj
-OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
-
-
-# targets
-all: $(ZLIB_LIB) example.exe minigzip.exe
-
-.c.obj:
- $(CC) -c $(CFLAGS) $*.c
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-example.obj: example.c zlib.h zconf.h
-
-minigzip.obj: minigzip.c zlib.h zconf.h
-
-
-# For the sake of the old Borland make,
-# the command line is cut to fit in the MS-DOS 128 byte limit:
-$(ZLIB_LIB): $(OBJ1) $(OBJ2)
- -del $(ZLIB_LIB)
- $(AR) $(ZLIB_LIB) $(OBJP1)
- $(AR) $(ZLIB_LIB) $(OBJP2)
-
-
-# testing
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-example.exe: example.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
-
-minigzip.exe: minigzip.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
-
-
-# cleanup
-clean:
- -del *.obj
- -del *.exe
- -del *.lib
- -del *.tds
- -del zlib.bak
- -del foo.gz
-
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib.build b/cpukit/zlib/contrib/dotzlib/DotZLib.build
deleted file mode 100644
index 7f90d6bc7c..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib.build
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<project name="DotZLib" default="build" basedir="./DotZLib">
- <description>A .Net wrapper library around ZLib1.dll</description>
-
- <property name="nunit.location" value="c:/program files/NUnit V2.1/bin" />
- <property name="build.root" value="bin" />
-
- <property name="debug" value="true" />
- <property name="nunit" value="true" />
-
- <property name="build.folder" value="${build.root}/debug/" if="${debug}" />
- <property name="build.folder" value="${build.root}/release/" unless="${debug}" />
-
- <target name="clean" description="Remove all generated files">
- <delete dir="${build.root}" failonerror="false" />
- </target>
-
- <target name="build" description="compiles the source code">
-
- <mkdir dir="${build.folder}" />
- <csc target="library" output="${build.folder}DotZLib.dll" debug="${debug}">
- <references basedir="${nunit.location}">
- <includes if="${nunit}" name="nunit.framework.dll" />
- </references>
- <sources>
- <includes name="*.cs" />
- <excludes name="UnitTests.cs" unless="${nunit}" />
- </sources>
- <arg value="/d:nunit" if="${nunit}" />
- </csc>
- </target>
-
-</project> \ No newline at end of file
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib.chm b/cpukit/zlib/contrib/dotzlib/DotZLib.chm
deleted file mode 100644
index f214a444ae..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib.chm
+++ /dev/null
Binary files differ
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib.sln b/cpukit/zlib/contrib/dotzlib/DotZLib.sln
deleted file mode 100644
index ac45ca048b..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib.sln
+++ /dev/null
@@ -1,21 +0,0 @@
-Microsoft Visual Studio Solution File, Format Version 8.00
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotZLib", "DotZLib\DotZLib.csproj", "{BB1EE0B1-1808-46CB-B786-949D91117FC5}"
- ProjectSection(ProjectDependencies) = postProject
- EndProjectSection
-EndProject
-Global
- GlobalSection(SolutionConfiguration) = preSolution
- Debug = Debug
- Release = Release
- EndGlobalSection
- GlobalSection(ProjectConfiguration) = postSolution
- {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.ActiveCfg = Debug|.NET
- {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.Build.0 = Debug|.NET
- {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.ActiveCfg = Release|.NET
- {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.Build.0 = Release|.NET
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- EndGlobalSection
- GlobalSection(ExtensibilityAddIns) = postSolution
- EndGlobalSection
-EndGlobal
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs
deleted file mode 100644
index 0491bfc2b0..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-//
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-//
-[assembly: AssemblyTitle("DotZLib")]
-[assembly: AssemblyDescription(".Net bindings for ZLib compression dll 1.2.x")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Henrik Ravn")]
-[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("(c) 2004 by Henrik Ravn")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Revision and Build Numbers
-// by using the '*' as shown below:
-
-[assembly: AssemblyVersion("1.0.*")]
-
-//
-// In order to sign your assembly you must specify a key to use. Refer to the
-// Microsoft .NET Framework documentation for more information on assembly signing.
-//
-// Use the attributes below to control which key is used for signing.
-//
-// Notes:
-// (*) If no key is specified, the assembly is not signed.
-// (*) KeyName refers to a key that has been installed in the Crypto Service
-// Provider (CSP) on your machine. KeyFile refers to a file which contains
-// a key.
-// (*) If the KeyFile and the KeyName values are both specified, the
-// following processing occurs:
-// (1) If the KeyName can be found in the CSP, that key is used.
-// (2) If the KeyName does not exist and the KeyFile does exist, the key
-// in the KeyFile is installed into the CSP and used.
-// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
-// When specifying the KeyFile, the location of the KeyFile should be
-// relative to the project output directory which is
-// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
-// located in the project directory, you would specify the AssemblyKeyFile
-// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
-// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
-// documentation for more information on this.
-//
-[assembly: AssemblyDelaySign(false)]
-[assembly: AssemblyKeyFile("")]
-[assembly: AssemblyKeyName("")]
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
deleted file mode 100644
index 788b2fcece..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
+++ /dev/null
@@ -1,202 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.Runtime.InteropServices;
-using System.Text;
-
-
-namespace DotZLib
-{
- #region ChecksumGeneratorBase
- /// <summary>
- /// Implements the common functionality needed for all <see cref="ChecksumGenerator"/>s
- /// </summary>
- /// <example></example>
- public abstract class ChecksumGeneratorBase : ChecksumGenerator
- {
- /// <summary>
- /// The value of the current checksum
- /// </summary>
- protected uint _current;
-
- /// <summary>
- /// Initializes a new instance of the checksum generator base - the current checksum is
- /// set to zero
- /// </summary>
- public ChecksumGeneratorBase()
- {
- _current = 0;
- }
-
- /// <summary>
- /// Initializes a new instance of the checksum generator basewith a specified value
- /// </summary>
- /// <param name="initialValue">The value to set the current checksum to</param>
- public ChecksumGeneratorBase(uint initialValue)
- {
- _current = initialValue;
- }
-
- /// <summary>
- /// Resets the current checksum to zero
- /// </summary>
- public void Reset() { _current = 0; }
-
- /// <summary>
- /// Gets the current checksum value
- /// </summary>
- public uint Value { get { return _current; } }
-
- /// <summary>
- /// Updates the current checksum with part of an array of bytes
- /// </summary>
- /// <param name="data">The data to update the checksum with</param>
- /// <param name="offset">Where in <c>data</c> to start updating</param>
- /// <param name="count">The number of bytes from <c>data</c> to use</param>
- /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
- /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception>
- /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
- /// <remarks>All the other <c>Update</c> methods are implmeneted in terms of this one.
- /// This is therefore the only method a derived class has to implement</remarks>
- public abstract void Update(byte[] data, int offset, int count);
-
- /// <summary>
- /// Updates the current checksum with an array of bytes.
- /// </summary>
- /// <param name="data">The data to update the checksum with</param>
- public void Update(byte[] data)
- {
- Update(data, 0, data.Length);
- }
-
- /// <summary>
- /// Updates the current checksum with the data from a string
- /// </summary>
- /// <param name="data">The string to update the checksum with</param>
- /// <remarks>The characters in the string are converted by the UTF-8 encoding</remarks>
- public void Update(string data)
- {
- Update(Encoding.UTF8.GetBytes(data));
- }
-
- /// <summary>
- /// Updates the current checksum with the data from a string, using a specific encoding
- /// </summary>
- /// <param name="data">The string to update the checksum with</param>
- /// <param name="encoding">The encoding to use</param>
- public void Update(string data, Encoding encoding)
- {
- Update(encoding.GetBytes(data));
- }
-
- }
- #endregion
-
- #region CRC32
- /// <summary>
- /// Implements a CRC32 checksum generator
- /// </summary>
- public sealed class CRC32Checksum : ChecksumGeneratorBase
- {
- #region DLL imports
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern uint crc32(uint crc, int data, uint length);
-
- #endregion
-
- /// <summary>
- /// Initializes a new instance of the CRC32 checksum generator
- /// </summary>
- public CRC32Checksum() : base() {}
-
- /// <summary>
- /// Initializes a new instance of the CRC32 checksum generator with a specified value
- /// </summary>
- /// <param name="initialValue">The value to set the current checksum to</param>
- public CRC32Checksum(uint initialValue) : base(initialValue) {}
-
- /// <summary>
- /// Updates the current checksum with part of an array of bytes
- /// </summary>
- /// <param name="data">The data to update the checksum with</param>
- /// <param name="offset">Where in <c>data</c> to start updating</param>
- /// <param name="count">The number of bytes from <c>data</c> to use</param>
- /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
- /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception>
- /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
- public override void Update(byte[] data, int offset, int count)
- {
- if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
- if ((offset+count) > data.Length) throw new ArgumentException();
- GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned);
- try
- {
- _current = crc32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count);
- }
- finally
- {
- hData.Free();
- }
- }
-
- }
- #endregion
-
- #region Adler
- /// <summary>
- /// Implements a checksum generator that computes the Adler checksum on data
- /// </summary>
- public sealed class AdlerChecksum : ChecksumGeneratorBase
- {
- #region DLL imports
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern uint adler32(uint adler, int data, uint length);
-
- #endregion
-
- /// <summary>
- /// Initializes a new instance of the Adler checksum generator
- /// </summary>
- public AdlerChecksum() : base() {}
-
- /// <summary>
- /// Initializes a new instance of the Adler checksum generator with a specified value
- /// </summary>
- /// <param name="initialValue">The value to set the current checksum to</param>
- public AdlerChecksum(uint initialValue) : base(initialValue) {}
-
- /// <summary>
- /// Updates the current checksum with part of an array of bytes
- /// </summary>
- /// <param name="data">The data to update the checksum with</param>
- /// <param name="offset">Where in <c>data</c> to start updating</param>
- /// <param name="count">The number of bytes from <c>data</c> to use</param>
- /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
- /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception>
- /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
- public override void Update(byte[] data, int offset, int count)
- {
- if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
- if ((offset+count) > data.Length) throw new ArgumentException();
- GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned);
- try
- {
- _current = adler32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count);
- }
- finally
- {
- hData.Free();
- }
- }
-
- }
- #endregion
-
-} \ No newline at end of file
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs
deleted file mode 100644
index c1cab3a02c..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.Diagnostics;
-
-namespace DotZLib
-{
-
- /// <summary>
- /// This class implements a circular buffer
- /// </summary>
- internal class CircularBuffer
- {
- #region Private data
- private int _capacity;
- private int _head;
- private int _tail;
- private int _size;
- private byte[] _buffer;
- #endregion
-
- public CircularBuffer(int capacity)
- {
- Debug.Assert( capacity > 0 );
- _buffer = new byte[capacity];
- _capacity = capacity;
- _head = 0;
- _tail = 0;
- _size = 0;
- }
-
- public int Size { get { return _size; } }
-
- public int Put(byte[] source, int offset, int count)
- {
- Debug.Assert( count > 0 );
- int trueCount = Math.Min(count, _capacity - Size);
- for (int i = 0; i < trueCount; ++i)
- _buffer[(_tail+i) % _capacity] = source[offset+i];
- _tail += trueCount;
- _tail %= _capacity;
- _size += trueCount;
- return trueCount;
- }
-
- public bool Put(byte b)
- {
- if (Size == _capacity) // no room
- return false;
- _buffer[_tail++] = b;
- _tail %= _capacity;
- ++_size;
- return true;
- }
-
- public int Get(byte[] destination, int offset, int count)
- {
- int trueCount = Math.Min(count,Size);
- for (int i = 0; i < trueCount; ++i)
- destination[offset + i] = _buffer[(_head+i) % _capacity];
- _head += trueCount;
- _head %= _capacity;
- _size -= trueCount;
- return trueCount;
- }
-
- public int Get()
- {
- if (Size == 0)
- return -1;
-
- int result = (int)_buffer[_head++ % _capacity];
- --_size;
- return result;
- }
-
- }
-}
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/CodecBase.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
deleted file mode 100644
index 42e6da3a56..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
+++ /dev/null
@@ -1,198 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace DotZLib
-{
- /// <summary>
- /// Implements the common functionality needed for all <see cref="Codec"/>s
- /// </summary>
- public abstract class CodecBase : Codec, IDisposable
- {
-
- #region Data members
-
- /// <summary>
- /// Instance of the internal zlib buffer structure that is
- /// passed to all functions in the zlib dll
- /// </summary>
- internal ZStream _ztream = new ZStream();
-
- /// <summary>
- /// True if the object instance has been disposed, false otherwise
- /// </summary>
- protected bool _isDisposed = false;
-
- /// <summary>
- /// The size of the internal buffers
- /// </summary>
- protected const int kBufferSize = 16384;
-
- private byte[] _outBuffer = new byte[kBufferSize];
- private byte[] _inBuffer = new byte[kBufferSize];
-
- private GCHandle _hInput;
- private GCHandle _hOutput;
-
- private uint _checksum = 0;
-
- #endregion
-
- /// <summary>
- /// Initializes a new instance of the <c>CodeBase</c> class.
- /// </summary>
- public CodecBase()
- {
- try
- {
- _hInput = GCHandle.Alloc(_inBuffer, GCHandleType.Pinned);
- _hOutput = GCHandle.Alloc(_outBuffer, GCHandleType.Pinned);
- }
- catch (Exception)
- {
- CleanUp(false);
- throw;
- }
- }
-
-
- #region Codec Members
-
- /// <summary>
- /// Occurs when more processed data are available.
- /// </summary>
- public event DataAvailableHandler DataAvailable;
-
- /// <summary>
- /// Fires the <see cref="DataAvailable"/> event
- /// </summary>
- protected void OnDataAvailable()
- {
- if (_ztream.total_out > 0)
- {
- if (DataAvailable != null)
- DataAvailable( _outBuffer, 0, (int)_ztream.total_out);
- resetOutput();
- }
- }
-
- /// <summary>
- /// Adds more data to the codec to be processed.
- /// </summary>
- /// <param name="data">Byte array containing the data to be added to the codec</param>
- /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
- public void Add(byte[] data)
- {
- Add(data,0,data.Length);
- }
-
- /// <summary>
- /// Adds more data to the codec to be processed.
- /// </summary>
- /// <param name="data">Byte array containing the data to be added to the codec</param>
- /// <param name="offset">The index of the first byte to add from <c>data</c></param>
- /// <param name="count">The number of bytes to add</param>
- /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
- /// <remarks>This must be implemented by a derived class</remarks>
- public abstract void Add(byte[] data, int offset, int count);
-
- /// <summary>
- /// Finishes up any pending data that needs to be processed and handled.
- /// </summary>
- /// <remarks>This must be implemented by a derived class</remarks>
- public abstract void Finish();
-
- /// <summary>
- /// Gets the checksum of the data that has been added so far
- /// </summary>
- public uint Checksum { get { return _checksum; } }
-
- #endregion
-
- #region Destructor & IDisposable stuff
-
- /// <summary>
- /// Destroys this instance
- /// </summary>
- ~CodecBase()
- {
- CleanUp(false);
- }
-
- /// <summary>
- /// Releases any unmanaged resources and calls the <see cref="CleanUp()"/> method of the derived class
- /// </summary>
- public void Dispose()
- {
- CleanUp(true);
- }
-
- /// <summary>
- /// Performs any codec specific cleanup
- /// </summary>
- /// <remarks>This must be implemented by a derived class</remarks>
- protected abstract void CleanUp();
-
- // performs the release of the handles and calls the dereived CleanUp()
- private void CleanUp(bool isDisposing)
- {
- if (!_isDisposed)
- {
- CleanUp();
- if (_hInput.IsAllocated)
- _hInput.Free();
- if (_hOutput.IsAllocated)
- _hOutput.Free();
-
- _isDisposed = true;
- }
- }
-
-
- #endregion
-
- #region Helper methods
-
- /// <summary>
- /// Copies a number of bytes to the internal codec buffer - ready for proccesing
- /// </summary>
- /// <param name="data">The byte array that contains the data to copy</param>
- /// <param name="startIndex">The index of the first byte to copy</param>
- /// <param name="count">The number of bytes to copy from <c>data</c></param>
- protected void copyInput(byte[] data, int startIndex, int count)
- {
- Array.Copy(data, startIndex, _inBuffer,0, count);
- _ztream.next_in = _hInput.AddrOfPinnedObject();
- _ztream.total_in = 0;
- _ztream.avail_in = (uint)count;
-
- }
-
- /// <summary>
- /// Resets the internal output buffers to a known state - ready for processing
- /// </summary>
- protected void resetOutput()
- {
- _ztream.total_out = 0;
- _ztream.avail_out = kBufferSize;
- _ztream.next_out = _hOutput.AddrOfPinnedObject();
- }
-
- /// <summary>
- /// Updates the running checksum property
- /// </summary>
- /// <param name="newSum">The new checksum value</param>
- protected void setChecksum(uint newSum)
- {
- _checksum = newSum;
- }
- #endregion
-
- }
-}
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/Deflater.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/Deflater.cs
deleted file mode 100644
index c2477925b6..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/Deflater.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace DotZLib
-{
-
- /// <summary>
- /// Implements a data compressor, using the deflate algorithm in the ZLib dll
- /// </summary>
- public sealed class Deflater : CodecBase
- {
- #region Dll imports
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
- private static extern int deflateInit_(ref ZStream sz, int level, string vs, int size);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int deflate(ref ZStream sz, int flush);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int deflateReset(ref ZStream sz);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int deflateEnd(ref ZStream sz);
- #endregion
-
- /// <summary>
- /// Constructs an new instance of the <c>Deflater</c>
- /// </summary>
- /// <param name="level">The compression level to use for this <c>Deflater</c></param>
- public Deflater(CompressLevel level) : base()
- {
- int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream));
- if (retval != 0)
- throw new ZLibException(retval, "Could not initialize deflater");
-
- resetOutput();
- }
-
- /// <summary>
- /// Adds more data to the codec to be processed.
- /// </summary>
- /// <param name="data">Byte array containing the data to be added to the codec</param>
- /// <param name="offset">The index of the first byte to add from <c>data</c></param>
- /// <param name="count">The number of bytes to add</param>
- /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
- public override void Add(byte[] data, int offset, int count)
- {
- if (data == null) throw new ArgumentNullException();
- if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
- if ((offset+count) > data.Length) throw new ArgumentException();
-
- int total = count;
- int inputIndex = offset;
- int err = 0;
-
- while (err >= 0 && inputIndex < total)
- {
- copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize));
- while (err >= 0 && _ztream.avail_in > 0)
- {
- err = deflate(ref _ztream, (int)FlushTypes.None);
- if (err == 0)
- while (_ztream.avail_out == 0)
- {
- OnDataAvailable();
- err = deflate(ref _ztream, (int)FlushTypes.None);
- }
- inputIndex += (int)_ztream.total_in;
- }
- }
- setChecksum( _ztream.adler );
- }
-
-
- /// <summary>
- /// Finishes up any pending data that needs to be processed and handled.
- /// </summary>
- public override void Finish()
- {
- int err;
- do
- {
- err = deflate(ref _ztream, (int)FlushTypes.Finish);
- OnDataAvailable();
- }
- while (err == 0);
- setChecksum( _ztream.adler );
- deflateReset(ref _ztream);
- resetOutput();
- }
-
- /// <summary>
- /// Closes the internal zlib deflate stream
- /// </summary>
- protected override void CleanUp() { deflateEnd(ref _ztream); }
-
- }
-}
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.cs
deleted file mode 100644
index be184b4c71..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.cs
+++ /dev/null
@@ -1,288 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-using System.Text;
-
-
-namespace DotZLib
-{
-
- #region Internal types
-
- /// <summary>
- /// Defines constants for the various flush types used with zlib
- /// </summary>
- internal enum FlushTypes
- {
- None, Partial, Sync, Full, Finish, Block
- }
-
- #region ZStream structure
- // internal mapping of the zlib zstream structure for marshalling
- [StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0, CharSet=CharSet.Ansi)]
- internal struct ZStream
- {
- public IntPtr next_in;
- public uint avail_in;
- public uint total_in;
-
- public IntPtr next_out;
- public uint avail_out;
- public uint total_out;
-
- [MarshalAs(UnmanagedType.LPStr)]
- string msg;
- uint state;
-
- uint zalloc;
- uint zfree;
- uint opaque;
-
- int data_type;
- public uint adler;
- uint reserved;
- }
-
- #endregion
-
- #endregion
-
- #region Public enums
- /// <summary>
- /// Defines constants for the available compression levels in zlib
- /// </summary>
- public enum CompressLevel : int
- {
- /// <summary>
- /// The default compression level with a reasonable compromise between compression and speed
- /// </summary>
- Default = -1,
- /// <summary>
- /// No compression at all. The data are passed straight through.
- /// </summary>
- None = 0,
- /// <summary>
- /// The maximum compression rate available.
- /// </summary>
- Best = 9,
- /// <summary>
- /// The fastest available compression level.
- /// </summary>
- Fastest = 1
- }
- #endregion
-
- #region Exception classes
- /// <summary>
- /// The exception that is thrown when an error occurs on the zlib dll
- /// </summary>
- public class ZLibException : ApplicationException
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="ZLibException"/> class with a specified
- /// error message and error code
- /// </summary>
- /// <param name="errorCode">The zlib error code that caused the exception</param>
- /// <param name="msg">A message that (hopefully) describes the error</param>
- public ZLibException(int errorCode, string msg) : base(String.Format("ZLib error {0} {1}", errorCode, msg))
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ZLibException"/> class with a specified
- /// error code
- /// </summary>
- /// <param name="errorCode">The zlib error code that caused the exception</param>
- public ZLibException(int errorCode) : base(String.Format("ZLib error {0}", errorCode))
- {
- }
- }
- #endregion
-
- #region Interfaces
-
- /// <summary>
- /// Declares methods and properties that enables a running checksum to be calculated
- /// </summary>
- public interface ChecksumGenerator
- {
- /// <summary>
- /// Gets the current value of the checksum
- /// </summary>
- uint Value { get; }
-
- /// <summary>
- /// Clears the current checksum to 0
- /// </summary>
- void Reset();
-
- /// <summary>
- /// Updates the current checksum with an array of bytes
- /// </summary>
- /// <param name="data">The data to update the checksum with</param>
- void Update(byte[] data);
-
- /// <summary>
- /// Updates the current checksum with part of an array of bytes
- /// </summary>
- /// <param name="data">The data to update the checksum with</param>
- /// <param name="offset">Where in <c>data</c> to start updating</param>
- /// <param name="count">The number of bytes from <c>data</c> to use</param>
- /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
- /// <exception cref="ArgumentNullException"><c>data</c> is a null reference</exception>
- /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
- void Update(byte[] data, int offset, int count);
-
- /// <summary>
- /// Updates the current checksum with the data from a string
- /// </summary>
- /// <param name="data">The string to update the checksum with</param>
- /// <remarks>The characters in the string are converted by the UTF-8 encoding</remarks>
- void Update(string data);
-
- /// <summary>
- /// Updates the current checksum with the data from a string, using a specific encoding
- /// </summary>
- /// <param name="data">The string to update the checksum with</param>
- /// <param name="encoding">The encoding to use</param>
- void Update(string data, Encoding encoding);
- }
-
-
- /// <summary>
- /// Represents the method that will be called from a codec when new data
- /// are available.
- /// </summary>
- /// <paramref name="data">The byte array containing the processed data</paramref>
- /// <paramref name="startIndex">The index of the first processed byte in <c>data</c></paramref>
- /// <paramref name="count">The number of processed bytes available</paramref>
- /// <remarks>On return from this method, the data may be overwritten, so grab it while you can.
- /// You cannot assume that startIndex will be zero.
- /// </remarks>
- public delegate void DataAvailableHandler(byte[] data, int startIndex, int count);
-
- /// <summary>
- /// Declares methods and events for implementing compressors/decompressors
- /// </summary>
- public interface Codec
- {
- /// <summary>
- /// Occurs when more processed data are available.
- /// </summary>
- event DataAvailableHandler DataAvailable;
-
- /// <summary>
- /// Adds more data to the codec to be processed.
- /// </summary>
- /// <param name="data">Byte array containing the data to be added to the codec</param>
- /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
- void Add(byte[] data);
-
- /// <summary>
- /// Adds more data to the codec to be processed.
- /// </summary>
- /// <param name="data">Byte array containing the data to be added to the codec</param>
- /// <param name="offset">The index of the first byte to add from <c>data</c></param>
- /// <param name="count">The number of bytes to add</param>
- /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
- void Add(byte[] data, int offset, int count);
-
- /// <summary>
- /// Finishes up any pending data that needs to be processed and handled.
- /// </summary>
- void Finish();
-
- /// <summary>
- /// Gets the checksum of the data that has been added so far
- /// </summary>
- uint Checksum { get; }
-
-
- }
-
- #endregion
-
- #region Classes
- /// <summary>
- /// Encapsulates general information about the ZLib library
- /// </summary>
- public class Info
- {
- #region DLL imports
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern uint zlibCompileFlags();
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern string zlibVersion();
- #endregion
-
- #region Private stuff
- private uint _flags;
-
- // helper function that unpacks a bitsize mask
- private static int bitSize(uint bits)
- {
- switch (bits)
- {
- case 0: return 16;
- case 1: return 32;
- case 2: return 64;
- }
- return -1;
- }
- #endregion
-
- /// <summary>
- /// Constructs an instance of the <c>Info</c> class.
- /// </summary>
- public Info()
- {
- _flags = zlibCompileFlags();
- }
-
- /// <summary>
- /// True if the library is compiled with debug info
- /// </summary>
- public bool HasDebugInfo { get { return 0 != (_flags & 0x100); } }
-
- /// <summary>
- /// True if the library is compiled with assembly optimizations
- /// </summary>
- public bool UsesAssemblyCode { get { return 0 != (_flags & 0x200); } }
-
- /// <summary>
- /// Gets the size of the unsigned int that was compiled into Zlib
- /// </summary>
- public int SizeOfUInt { get { return bitSize(_flags & 3); } }
-
- /// <summary>
- /// Gets the size of the unsigned long that was compiled into Zlib
- /// </summary>
- public int SizeOfULong { get { return bitSize((_flags >> 2) & 3); } }
-
- /// <summary>
- /// Gets the size of the pointers that were compiled into Zlib
- /// </summary>
- public int SizeOfPointer { get { return bitSize((_flags >> 4) & 3); } }
-
- /// <summary>
- /// Gets the size of the z_off_t type that was compiled into Zlib
- /// </summary>
- public int SizeOfOffset { get { return bitSize((_flags >> 6) & 3); } }
-
- /// <summary>
- /// Gets the version of ZLib as a string, e.g. "1.2.1"
- /// </summary>
- public static string Version { get { return zlibVersion(); } }
- }
-
- #endregion
-
-}
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj b/cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj
deleted file mode 100644
index 71eeb8590a..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj
+++ /dev/null
@@ -1,141 +0,0 @@
-<VisualStudioProject>
- <CSHARP
- ProjectType = "Local"
- ProductVersion = "7.10.3077"
- SchemaVersion = "2.0"
- ProjectGuid = "{BB1EE0B1-1808-46CB-B786-949D91117FC5}"
- >
- <Build>
- <Settings
- ApplicationIcon = ""
- AssemblyKeyContainerName = ""
- AssemblyName = "DotZLib"
- AssemblyOriginatorKeyFile = ""
- DefaultClientScript = "JScript"
- DefaultHTMLPageLayout = "Grid"
- DefaultTargetSchema = "IE50"
- DelaySign = "false"
- OutputType = "Library"
- PreBuildEvent = ""
- PostBuildEvent = ""
- RootNamespace = "DotZLib"
- RunPostBuildEvent = "OnBuildSuccess"
- StartupObject = ""
- >
- <Config
- Name = "Debug"
- AllowUnsafeBlocks = "false"
- BaseAddress = "285212672"
- CheckForOverflowUnderflow = "false"
- ConfigurationOverrideFile = ""
- DefineConstants = "DEBUG;TRACE"
- DocumentationFile = "docs\DotZLib.xml"
- DebugSymbols = "true"
- FileAlignment = "4096"
- IncrementalBuild = "false"
- NoStdLib = "false"
- NoWarn = "1591"
- Optimize = "false"
- OutputPath = "bin\Debug\"
- RegisterForComInterop = "false"
- RemoveIntegerChecks = "false"
- TreatWarningsAsErrors = "false"
- WarningLevel = "4"
- />
- <Config
- Name = "Release"
- AllowUnsafeBlocks = "false"
- BaseAddress = "285212672"
- CheckForOverflowUnderflow = "false"
- ConfigurationOverrideFile = ""
- DefineConstants = "TRACE"
- DocumentationFile = "docs\DotZLib.xml"
- DebugSymbols = "false"
- FileAlignment = "4096"
- IncrementalBuild = "false"
- NoStdLib = "false"
- NoWarn = ""
- Optimize = "true"
- OutputPath = "bin\Release\"
- RegisterForComInterop = "false"
- RemoveIntegerChecks = "false"
- TreatWarningsAsErrors = "false"
- WarningLevel = "4"
- />
- </Settings>
- <References>
- <Reference
- Name = "System"
- AssemblyName = "System"
- HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll"
- />
- <Reference
- Name = "System.Data"
- AssemblyName = "System.Data"
- HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
- />
- <Reference
- Name = "System.XML"
- AssemblyName = "System.Xml"
- HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
- />
- <Reference
- Name = "nunit.framework"
- AssemblyName = "nunit.framework"
- HintPath = "E:\apps\NUnit V2.1\\bin\nunit.framework.dll"
- AssemblyFolderKey = "hklm\dn\nunit.framework"
- />
- </References>
- </Build>
- <Files>
- <Include>
- <File
- RelPath = "AssemblyInfo.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "ChecksumImpl.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "CircularBuffer.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "CodecBase.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "Deflater.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "DotZLib.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "GZipStream.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "Inflater.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
- RelPath = "UnitTests.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- </Include>
- </Files>
- </CSHARP>
-</VisualStudioProject>
-
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/GZipStream.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
deleted file mode 100644
index b161300b18..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
+++ /dev/null
@@ -1,301 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-
-namespace DotZLib
-{
- /// <summary>
- /// Implements a compressed <see cref="Stream"/>, in GZip (.gz) format.
- /// </summary>
- public class GZipStream : Stream, IDisposable
- {
- #region Dll Imports
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
- private static extern IntPtr gzopen(string name, string mode);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int gzclose(IntPtr gzFile);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int gzwrite(IntPtr gzFile, int data, int length);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int gzread(IntPtr gzFile, int data, int length);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int gzgetc(IntPtr gzFile);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int gzputc(IntPtr gzFile, int c);
-
- #endregion
-
- #region Private data
- private IntPtr _gzFile;
- private bool _isDisposed = false;
- private bool _isWriting;
- #endregion
-
- #region Constructors
- /// <summary>
- /// Creates a new file as a writeable GZipStream
- /// </summary>
- /// <param name="fileName">The name of the compressed file to create</param>
- /// <param name="level">The compression level to use when adding data</param>
- /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception>
- public GZipStream(string fileName, CompressLevel level)
- {
- _isWriting = true;
- _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level));
- if (_gzFile == IntPtr.Zero)
- throw new ZLibException(-1, "Could not open " + fileName);
- }
-
- /// <summary>
- /// Opens an existing file as a readable GZipStream
- /// </summary>
- /// <param name="fileName">The name of the file to open</param>
- /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception>
- public GZipStream(string fileName)
- {
- _isWriting = false;
- _gzFile = gzopen(fileName, "rb");
- if (_gzFile == IntPtr.Zero)
- throw new ZLibException(-1, "Could not open " + fileName);
-
- }
- #endregion
-
- #region Access properties
- /// <summary>
- /// Returns true of this stream can be read from, false otherwise
- /// </summary>
- public override bool CanRead
- {
- get
- {
- return !_isWriting;
- }
- }
-
-
- /// <summary>
- /// Returns false.
- /// </summary>
- public override bool CanSeek
- {
- get
- {
- return false;
- }
- }
-
- /// <summary>
- /// Returns true if this tsream is writeable, false otherwise
- /// </summary>
- public override bool CanWrite
- {
- get
- {
- return _isWriting;
- }
- }
- #endregion
-
- #region Destructor & IDispose stuff
-
- /// <summary>
- /// Destroys this instance
- /// </summary>
- ~GZipStream()
- {
- cleanUp(false);
- }
-
- /// <summary>
- /// Closes the external file handle
- /// </summary>
- public void Dispose()
- {
- cleanUp(true);
- }
-
- // Does the actual closing of the file handle.
- private void cleanUp(bool isDisposing)
- {
- if (!_isDisposed)
- {
- gzclose(_gzFile);
- _isDisposed = true;
- }
- }
- #endregion
-
- #region Basic reading and writing
- /// <summary>
- /// Attempts to read a number of bytes from the stream.
- /// </summary>
- /// <param name="buffer">The destination data buffer</param>
- /// <param name="offset">The index of the first destination byte in <c>buffer</c></param>
- /// <param name="count">The number of bytes requested</param>
- /// <returns>The number of bytes read</returns>
- /// <exception cref="ArgumentNullException">If <c>buffer</c> is null</exception>
- /// <exception cref="ArgumentOutOfRangeException">If <c>count</c> or <c>offset</c> are negative</exception>
- /// <exception cref="ArgumentException">If <c>offset</c> + <c>count</c> is &gt; buffer.Length</exception>
- /// <exception cref="NotSupportedException">If this stream is not readable.</exception>
- /// <exception cref="ObjectDisposedException">If this stream has been disposed.</exception>
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (!CanRead) throw new NotSupportedException();
- if (buffer == null) throw new ArgumentNullException();
- if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
- if ((offset+count) > buffer.Length) throw new ArgumentException();
- if (_isDisposed) throw new ObjectDisposedException("GZipStream");
-
- GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
- int result;
- try
- {
- result = gzread(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count);
- if (result < 0)
- throw new IOException();
- }
- finally
- {
- h.Free();
- }
- return result;
- }
-
- /// <summary>
- /// Attempts to read a single byte from the stream.
- /// </summary>
- /// <returns>The byte that was read, or -1 in case of error or End-Of-File</returns>
- public override int ReadByte()
- {
- if (!CanRead) throw new NotSupportedException();
- if (_isDisposed) throw new ObjectDisposedException("GZipStream");
- return gzgetc(_gzFile);
- }
-
- /// <summary>
- /// Writes a number of bytes to the stream
- /// </summary>
- /// <param name="buffer"></param>
- /// <param name="offset"></param>
- /// <param name="count"></param>
- /// <exception cref="ArgumentNullException">If <c>buffer</c> is null</exception>
- /// <exception cref="ArgumentOutOfRangeException">If <c>count</c> or <c>offset</c> are negative</exception>
- /// <exception cref="ArgumentException">If <c>offset</c> + <c>count</c> is &gt; buffer.Length</exception>
- /// <exception cref="NotSupportedException">If this stream is not writeable.</exception>
- /// <exception cref="ObjectDisposedException">If this stream has been disposed.</exception>
- public override void Write(byte[] buffer, int offset, int count)
- {
- if (!CanWrite) throw new NotSupportedException();
- if (buffer == null) throw new ArgumentNullException();
- if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
- if ((offset+count) > buffer.Length) throw new ArgumentException();
- if (_isDisposed) throw new ObjectDisposedException("GZipStream");
-
- GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
- try
- {
- int result = gzwrite(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count);
- if (result < 0)
- throw new IOException();
- }
- finally
- {
- h.Free();
- }
- }
-
- /// <summary>
- /// Writes a single byte to the stream
- /// </summary>
- /// <param name="value">The byte to add to the stream.</param>
- /// <exception cref="NotSupportedException">If this stream is not writeable.</exception>
- /// <exception cref="ObjectDisposedException">If this stream has been disposed.</exception>
- public override void WriteByte(byte value)
- {
- if (!CanWrite) throw new NotSupportedException();
- if (_isDisposed) throw new ObjectDisposedException("GZipStream");
-
- int result = gzputc(_gzFile, (int)value);
- if (result < 0)
- throw new IOException();
- }
- #endregion
-
- #region Position & length stuff
- /// <summary>
- /// Not supported.
- /// </summary>
- /// <param name="value"></param>
- /// <exception cref="NotSupportedException">Always thrown</exception>
- public override void SetLength(long value)
- {
- throw new NotSupportedException();
- }
-
- /// <summary>
- /// Not suppported.
- /// </summary>
- /// <param name="offset"></param>
- /// <param name="origin"></param>
- /// <returns></returns>
- /// <exception cref="NotSupportedException">Always thrown</exception>
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotSupportedException();
- }
-
- /// <summary>
- /// Flushes the <c>GZipStream</c>.
- /// </summary>
- /// <remarks>In this implementation, this method does nothing. This is because excessive
- /// flushing may degrade the achievable compression rates.</remarks>
- public override void Flush()
- {
- // left empty on purpose
- }
-
- /// <summary>
- /// Gets/sets the current position in the <c>GZipStream</c>. Not suppported.
- /// </summary>
- /// <remarks>In this implementation this property is not supported</remarks>
- /// <exception cref="NotSupportedException">Always thrown</exception>
- public override long Position
- {
- get
- {
- throw new NotSupportedException();
- }
- set
- {
- throw new NotSupportedException();
- }
- }
-
- /// <summary>
- /// Gets the size of the stream. Not suppported.
- /// </summary>
- /// <remarks>In this implementation this property is not supported</remarks>
- /// <exception cref="NotSupportedException">Always thrown</exception>
- public override long Length
- {
- get
- {
- throw new NotSupportedException();
- }
- }
- #endregion
- }
-}
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/Inflater.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/Inflater.cs
deleted file mode 100644
index 8ed5451d66..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/Inflater.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace DotZLib
-{
-
- /// <summary>
- /// Implements a data decompressor, using the inflate algorithm in the ZLib dll
- /// </summary>
- public class Inflater : CodecBase
- {
- #region Dll imports
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
- private static extern int inflateInit_(ref ZStream sz, string vs, int size);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int inflate(ref ZStream sz, int flush);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int inflateReset(ref ZStream sz);
-
- [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
- private static extern int inflateEnd(ref ZStream sz);
- #endregion
-
- /// <summary>
- /// Constructs an new instance of the <c>Inflater</c>
- /// </summary>
- public Inflater() : base()
- {
- int retval = inflateInit_(ref _ztream, Info.Version, Marshal.SizeOf(_ztream));
- if (retval != 0)
- throw new ZLibException(retval, "Could not initialize inflater");
-
- resetOutput();
- }
-
-
- /// <summary>
- /// Adds more data to the codec to be processed.
- /// </summary>
- /// <param name="data">Byte array containing the data to be added to the codec</param>
- /// <param name="offset">The index of the first byte to add from <c>data</c></param>
- /// <param name="count">The number of bytes to add</param>
- /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
- public override void Add(byte[] data, int offset, int count)
- {
- if (data == null) throw new ArgumentNullException();
- if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
- if ((offset+count) > data.Length) throw new ArgumentException();
-
- int total = count;
- int inputIndex = offset;
- int err = 0;
-
- while (err >= 0 && inputIndex < total)
- {
- copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize));
- err = inflate(ref _ztream, (int)FlushTypes.None);
- if (err == 0)
- while (_ztream.avail_out == 0)
- {
- OnDataAvailable();
- err = inflate(ref _ztream, (int)FlushTypes.None);
- }
-
- inputIndex += (int)_ztream.total_in;
- }
- setChecksum( _ztream.adler );
- }
-
-
- /// <summary>
- /// Finishes up any pending data that needs to be processed and handled.
- /// </summary>
- public override void Finish()
- {
- int err;
- do
- {
- err = inflate(ref _ztream, (int)FlushTypes.Finish);
- OnDataAvailable();
- }
- while (err == 0);
- setChecksum( _ztream.adler );
- inflateReset(ref _ztream);
- resetOutput();
- }
-
- /// <summary>
- /// Closes the internal zlib inflate stream
- /// </summary>
- protected override void CleanUp() { inflateEnd(ref _ztream); }
-
-
- }
-}
diff --git a/cpukit/zlib/contrib/dotzlib/DotZLib/UnitTests.cs b/cpukit/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
deleted file mode 100644
index 42c45884bb..0000000000
--- a/cpukit/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
+++ /dev/null
@@ -1,274 +0,0 @@
-//
-// © Copyright Henrik Ravn 2004
-//
-// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-using System;
-using System.Collections;
-using System.IO;
-
-// uncomment the define below to include unit tests
-//#define nunit
-#if nunit
-using NUnit.Framework;
-
-// Unit tests for the DotZLib class library
-// ----------------------------------------
-//
-// Use this with NUnit 2 from http://www.nunit.org
-//
-
-namespace DotZLibTests
-{
- using DotZLib;
-
- // helper methods
- internal class Utils
- {
- public static bool byteArrEqual( byte[] lhs, byte[] rhs )
- {
- if (lhs.Length != rhs.Length)
- return false;
- for (int i = lhs.Length-1; i >= 0; --i)
- if (lhs[i] != rhs[i])
- return false;
- return true;
- }
-
- }
-
-
- [TestFixture]
- public class CircBufferTests
- {
- #region Circular buffer tests
- [Test]
- public void SinglePutGet()
- {
- CircularBuffer buf = new CircularBuffer(10);
- Assert.AreEqual( 0, buf.Size );
- Assert.AreEqual( -1, buf.Get() );
-
- Assert.IsTrue(buf.Put( 1 ));
- Assert.AreEqual( 1, buf.Size );
- Assert.AreEqual( 1, buf.Get() );
- Assert.AreEqual( 0, buf.Size );
- Assert.AreEqual( -1, buf.Get() );
- }
-
- [Test]
- public void BlockPutGet()
- {
- CircularBuffer buf = new CircularBuffer(10);
- byte[] arr = {1,2,3,4,5,6,7,8,9,10};
- Assert.AreEqual( 10, buf.Put(arr,0,10) );
- Assert.AreEqual( 10, buf.Size );
- Assert.IsFalse( buf.Put(11) );
- Assert.AreEqual( 1, buf.Get() );
- Assert.IsTrue( buf.Put(11) );
-
- byte[] arr2 = (byte[])arr.Clone();
- Assert.AreEqual( 9, buf.Get(arr2,1,9) );
- Assert.IsTrue( Utils.byteArrEqual(arr,arr2) );
- }
-
- #endregion
- }
-
- [TestFixture]
- public class ChecksumTests
- {
- #region CRC32 Tests
- [Test]
- public void CRC32_Null()
- {
- CRC32Checksum crc32 = new CRC32Checksum();
- Assert.AreEqual( 0, crc32.Value );
-
- crc32 = new CRC32Checksum(1);
- Assert.AreEqual( 1, crc32.Value );
-
- crc32 = new CRC32Checksum(556);
- Assert.AreEqual( 556, crc32.Value );
- }
-
- [Test]
- public void CRC32_Data()
- {
- CRC32Checksum crc32 = new CRC32Checksum();
- byte[] data = { 1,2,3,4,5,6,7 };
- crc32.Update(data);
- Assert.AreEqual( 0x70e46888, crc32.Value );
-
- crc32 = new CRC32Checksum();
- crc32.Update("penguin");
- Assert.AreEqual( 0x0e5c1a120, crc32.Value );
-
- crc32 = new CRC32Checksum(1);
- crc32.Update("penguin");
- Assert.AreEqual(0x43b6aa94, crc32.Value);
-
- }
- #endregion
-
- #region Adler tests
-
- [Test]
- public void Adler_Null()
- {
- AdlerChecksum adler = new AdlerChecksum();
- Assert.AreEqual(0, adler.Value);
-
- adler = new AdlerChecksum(1);
- Assert.AreEqual( 1, adler.Value );
-
- adler = new AdlerChecksum(556);
- Assert.AreEqual( 556, adler.Value );
- }
-
- [Test]
- public void Adler_Data()
- {
- AdlerChecksum adler = new AdlerChecksum(1);
- byte[] data = { 1,2,3,4,5,6,7 };
- adler.Update(data);
- Assert.AreEqual( 0x5b001d, adler.Value );
-
- adler = new AdlerChecksum();
- adler.Update("penguin");
- Assert.AreEqual(0x0bcf02f6, adler.Value );
-
- adler = new AdlerChecksum(1);
- adler.Update("penguin");
- Assert.AreEqual(0x0bd602f7, adler.Value);
-
- }
- #endregion
- }
-
- [TestFixture]
- public class InfoTests
- {
- #region Info tests
- [Test]
- public void Info_Version()
- {
- Info info = new Info();
- Assert.AreEqual("1.2.4", Info.Version);
- Assert.AreEqual(32, info.SizeOfUInt);
- Assert.AreEqual(32, info.SizeOfULong);
- Assert.AreEqual(32, info.SizeOfPointer);
- Assert.AreEqual(32, info.SizeOfOffset);
- }
- #endregion
- }
-
- [TestFixture]
- public class DeflateInflateTests
- {
- #region Deflate tests
- [Test]
- public void Deflate_Init()
- {
- using (Deflater def = new Deflater(CompressLevel.Default))
- {
- }
- }
-
- private ArrayList compressedData = new ArrayList();
- private uint adler1;
-
- private ArrayList uncompressedData = new ArrayList();
- private uint adler2;
-
- public void CDataAvail(byte[] data, int startIndex, int count)
- {
- for (int i = 0; i < count; ++i)
- compressedData.Add(data[i+startIndex]);
- }
-
- [Test]
- public void Deflate_Compress()
- {
- compressedData.Clear();
-
- byte[] testData = new byte[35000];
- for (int i = 0; i < testData.Length; ++i)
- testData[i] = 5;
-
- using (Deflater def = new Deflater((CompressLevel)5))
- {
- def.DataAvailable += new DataAvailableHandler(CDataAvail);
- def.Add(testData);
- def.Finish();
- adler1 = def.Checksum;
- }
- }
- #endregion
-
- #region Inflate tests
- [Test]
- public void Inflate_Init()
- {
- using (Inflater inf = new Inflater())
- {
- }
- }
-
- private void DDataAvail(byte[] data, int startIndex, int count)
- {
- for (int i = 0; i < count; ++i)
- uncompressedData.Add(data[i+startIndex]);
- }
-
- [Test]
- public void Inflate_Expand()
- {
- uncompressedData.Clear();
-
- using (Inflater inf = new Inflater())
- {
- inf.DataAvailable += new DataAvailableHandler(DDataAvail);
- inf.Add((byte[])compressedData.ToArray(typeof(byte)));
- inf.Finish();
- adler2 = inf.Checksum;
- }
- Assert.AreEqual( adler1, adler2 );
- }
- #endregion
- }
-
- [TestFixture]
- public class GZipStreamTests
- {
- #region GZipStream test
- [Test]
- public void GZipStream_WriteRead()
- {
- using (GZipStream gzOut = new GZipStream("gzstream.gz", CompressLevel.Best))
- {
- BinaryWriter writer = new BinaryWriter(gzOut);
- writer.Write("hi there");
- writer.Write(Math.PI);
- writer.Write(42);
- }
-
- using (GZipStream gzIn = new GZipStream("gzstream.gz"))
- {
- BinaryReader reader = new BinaryReader(gzIn);
- string s = reader.ReadString();
- Assert.AreEqual("hi there",s);
- double d = reader.ReadDouble();
- Assert.AreEqual(Math.PI, d);
- int i = reader.ReadInt32();
- Assert.AreEqual(42,i);
- }
-
- }
- #endregion
- }
-}
-
-#endif \ No newline at end of file
diff --git a/cpukit/zlib/contrib/dotzlib/LICENSE_1_0.txt b/cpukit/zlib/contrib/dotzlib/LICENSE_1_0.txt
deleted file mode 100644
index 30aac2cf47..0000000000
--- a/cpukit/zlib/contrib/dotzlib/LICENSE_1_0.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-Boost Software License - Version 1.0 - August 17th, 2003
-
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE. \ No newline at end of file
diff --git a/cpukit/zlib/contrib/dotzlib/readme.txt b/cpukit/zlib/contrib/dotzlib/readme.txt
deleted file mode 100644
index b2395720d4..0000000000
--- a/cpukit/zlib/contrib/dotzlib/readme.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-This directory contains a .Net wrapper class library for the ZLib1.dll
-
-The wrapper includes support for inflating/deflating memory buffers,
-.Net streaming wrappers for the gz streams part of zlib, and wrappers
-for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples.
-
-Directory structure:
---------------------
-
-LICENSE_1_0.txt - License file.
-readme.txt - This file.
-DotZLib.chm - Class library documentation
-DotZLib.build - NAnt build file
-DotZLib.sln - Microsoft Visual Studio 2003 solution file
-
-DotZLib\*.cs - Source files for the class library
-
-Unit tests:
------------
-The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher.
-To include unit tests in the build, define nunit before building.
-
-
-Build instructions:
--------------------
-
-1. Using Visual Studio.Net 2003:
- Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll)
- will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on
- you are building the release or debug version of the library. Check
- DotZLib/UnitTests.cs for instructions on how to include unit tests in the
- build.
-
-2. Using NAnt:
- Open a command prompt with access to the build environment and run nant
- in the same directory as the DotZLib.build file.
- You can define 2 properties on the nant command-line to control the build:
- debug={true|false} to toggle between release/debug builds (default=true).
- nunit={true|false} to include or esclude unit tests (default=true).
- Also the target clean will remove binaries.
- Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release
- or ./DotZLib/bin/debug, depending on whether you are building the release
- or debug version of the library.
-
- Examples:
- nant -D:debug=false -D:nunit=false
- will build a release mode version of the library without unit tests.
- nant
- will build a debug version of the library with unit tests
- nant clean
- will remove all previously built files.
-
-
----------------------------------
-Copyright (c) Henrik Ravn 2004
-
-Use, modification and distribution are subject to the Boost Software License, Version 1.0.
-(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
diff --git a/cpukit/zlib/contrib/infback9/README b/cpukit/zlib/contrib/infback9/README
deleted file mode 100644
index e75ed13294..0000000000
--- a/cpukit/zlib/contrib/infback9/README
+++ /dev/null
@@ -1 +0,0 @@
-See infback9.h for what this is and how to use it.
diff --git a/cpukit/zlib/contrib/infback9/infback9.c b/cpukit/zlib/contrib/infback9/infback9.c
deleted file mode 100644
index 7bbe90ced2..0000000000
--- a/cpukit/zlib/contrib/infback9/infback9.c
+++ /dev/null
@@ -1,617 +0,0 @@
-/* infback9.c -- inflate deflate64 data using a call-back interface
- * Copyright (C) 1995-2008 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "zutil.h"
-#include "infback9.h"
-#include "inftree9.h"
-#include "inflate9.h"
-
-#define WSIZE 65536UL
-
-/*
- strm provides memory allocation functions in zalloc and zfree, or
- Z_NULL to use the library memory allocation functions.
-
- window is a user-supplied window and output buffer that is 64K bytes.
- */
-int ZEXPORT inflateBack9Init_(strm, window, version, stream_size)
-z_stream FAR *strm;
-unsigned char FAR *window;
-const char *version;
-int stream_size;
-{
- struct inflate_state FAR *state;
-
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
- stream_size != (int)(sizeof(z_stream)))
- return Z_VERSION_ERROR;
- if (strm == Z_NULL || window == Z_NULL)
- return Z_STREAM_ERROR;
- strm->msg = Z_NULL; /* in case we return an error */
- if (strm->zalloc == (alloc_func)0) {
- strm->zalloc = zcalloc;
- strm->opaque = (voidpf)0;
- }
- if (strm->zfree == (free_func)0) strm->zfree = zcfree;
- state = (struct inflate_state FAR *)ZALLOC(strm, 1,
- sizeof(struct inflate_state));
- if (state == Z_NULL) return Z_MEM_ERROR;
- Tracev((stderr, "inflate: allocated\n"));
- strm->state = (voidpf)state;
- state->window = window;
- return Z_OK;
-}
-
-/*
- Build and output length and distance decoding tables for fixed code
- decoding.
- */
-#ifdef MAKEFIXED
-#include <stdio.h>
-
-void makefixed9(void)
-{
- unsigned sym, bits, low, size;
- code *next, *lenfix, *distfix;
- struct inflate_state state;
- code fixed[544];
-
- /* literal/length table */
- sym = 0;
- while (sym < 144) state.lens[sym++] = 8;
- while (sym < 256) state.lens[sym++] = 9;
- while (sym < 280) state.lens[sym++] = 7;
- while (sym < 288) state.lens[sym++] = 8;
- next = fixed;
- lenfix = next;
- bits = 9;
- inflate_table9(LENS, state.lens, 288, &(next), &(bits), state.work);
-
- /* distance table */
- sym = 0;
- while (sym < 32) state.lens[sym++] = 5;
- distfix = next;
- bits = 5;
- inflate_table9(DISTS, state.lens, 32, &(next), &(bits), state.work);
-
- /* write tables */
- puts(" /* inffix9.h -- table for decoding deflate64 fixed codes");
- puts(" * Generated automatically by makefixed9().");
- puts(" */");
- puts("");
- puts(" /* WARNING: this file should *not* be used by applications.");
- puts(" It is part of the implementation of this library and is");
- puts(" subject to change. Applications should only use zlib.h.");
- puts(" */");
- puts("");
- size = 1U << 9;
- printf(" static const code lenfix[%u] = {", size);
- low = 0;
- for (;;) {
- if ((low % 6) == 0) printf("\n ");
- printf("{%u,%u,%d}", lenfix[low].op, lenfix[low].bits,
- lenfix[low].val);
- if (++low == size) break;
- putchar(',');
- }
- puts("\n };");
- size = 1U << 5;
- printf("\n static const code distfix[%u] = {", size);
- low = 0;
- for (;;) {
- if ((low % 5) == 0) printf("\n ");
- printf("{%u,%u,%d}", distfix[low].op, distfix[low].bits,
- distfix[low].val);
- if (++low == size) break;
- putchar(',');
- }
- puts("\n };");
-}
-#endif /* MAKEFIXED */
-
-/* Macros for inflateBack(): */
-
-/* Clear the input bit accumulator */
-#define INITBITS() \
- do { \
- hold = 0; \
- bits = 0; \
- } while (0)
-
-/* Assure that some input is available. If input is requested, but denied,
- then return a Z_BUF_ERROR from inflateBack(). */
-#define PULL() \
- do { \
- if (have == 0) { \
- have = in(in_desc, &next); \
- if (have == 0) { \
- next = Z_NULL; \
- ret = Z_BUF_ERROR; \
- goto inf_leave; \
- } \
- } \
- } while (0)
-
-/* Get a byte of input into the bit accumulator, or return from inflateBack()
- with an error if there is no input available. */
-#define PULLBYTE() \
- do { \
- PULL(); \
- have--; \
- hold += (unsigned long)(*next++) << bits; \
- bits += 8; \
- } while (0)
-
-/* Assure that there are at least n bits in the bit accumulator. If there is
- not enough available input to do that, then return from inflateBack() with
- an error. */
-#define NEEDBITS(n) \
- do { \
- while (bits < (unsigned)(n)) \
- PULLBYTE(); \
- } while (0)
-
-/* Return the low n bits of the bit accumulator (n <= 16) */
-#define BITS(n) \
- ((unsigned)hold & ((1U << (n)) - 1))
-
-/* Remove n bits from the bit accumulator */
-#define DROPBITS(n) \
- do { \
- hold >>= (n); \
- bits -= (unsigned)(n); \
- } while (0)
-
-/* Remove zero to seven bits as needed to go to a byte boundary */
-#define BYTEBITS() \
- do { \
- hold >>= bits & 7; \
- bits -= bits & 7; \
- } while (0)
-
-/* Assure that some output space is available, by writing out the window
- if it's full. If the write fails, return from inflateBack() with a
- Z_BUF_ERROR. */
-#define ROOM() \
- do { \
- if (left == 0) { \
- put = window; \
- left = WSIZE; \
- wrap = 1; \
- if (out(out_desc, put, (unsigned)left)) { \
- ret = Z_BUF_ERROR; \
- goto inf_leave; \
- } \
- } \
- } while (0)
-
-/*
- strm provides the memory allocation functions and window buffer on input,
- and provides information on the unused input on return. For Z_DATA_ERROR
- returns, strm will also provide an error message.
-
- in() and out() are the call-back input and output functions. When
- inflateBack() needs more input, it calls in(). When inflateBack() has
- filled the window with output, or when it completes with data in the
- window, it calls out() to write out the data. The application must not
- change the provided input until in() is called again or inflateBack()
- returns. The application must not change the window/output buffer until
- inflateBack() returns.
-
- in() and out() are called with a descriptor parameter provided in the
- inflateBack() call. This parameter can be a structure that provides the
- information required to do the read or write, as well as accumulated
- information on the input and output such as totals and check values.
-
- in() should return zero on failure. out() should return non-zero on
- failure. If either in() or out() fails, than inflateBack() returns a
- Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
- was in() or out() that caused in the error. Otherwise, inflateBack()
- returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
- error, or Z_MEM_ERROR if it could not allocate memory for the state.
- inflateBack() can also return Z_STREAM_ERROR if the input parameters
- are not correct, i.e. strm is Z_NULL or the state was not initialized.
- */
-int ZEXPORT inflateBack9(strm, in, in_desc, out, out_desc)
-z_stream FAR *strm;
-in_func in;
-void FAR *in_desc;
-out_func out;
-void FAR *out_desc;
-{
- struct inflate_state FAR *state;
- unsigned char FAR *next; /* next input */
- unsigned char FAR *put; /* next output */
- unsigned have; /* available input */
- unsigned long left; /* available output */
- inflate_mode mode; /* current inflate mode */
- int lastblock; /* true if processing last block */
- int wrap; /* true if the window has wrapped */
- unsigned long write; /* window write index */
- unsigned char FAR *window; /* allocated sliding window, if needed */
- unsigned long hold; /* bit buffer */
- unsigned bits; /* bits in bit buffer */
- unsigned extra; /* extra bits needed */
- unsigned long length; /* literal or length of data to copy */
- unsigned long offset; /* distance back to copy string from */
- unsigned long copy; /* number of stored or match bytes to copy */
- unsigned char FAR *from; /* where to copy match bytes from */
- code const FAR *lencode; /* starting table for length/literal codes */
- code const FAR *distcode; /* starting table for distance codes */
- unsigned lenbits; /* index bits for lencode */
- unsigned distbits; /* index bits for distcode */
- code here; /* current decoding table entry */
- code last; /* parent table entry */
- unsigned len; /* length to copy for repeats, bits to drop */
- int ret; /* return code */
- static const unsigned short order[19] = /* permutation of code lengths */
- {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-#include "inffix9.h"
-
- /* Check that the strm exists and that the state was initialized */
- if (strm == Z_NULL || strm->state == Z_NULL)
- return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
-
- /* Reset the state */
- strm->msg = Z_NULL;
- mode = TYPE;
- lastblock = 0;
- write = 0;
- wrap = 0;
- window = state->window;
- next = strm->next_in;
- have = next != Z_NULL ? strm->avail_in : 0;
- hold = 0;
- bits = 0;
- put = window;
- left = WSIZE;
- lencode = Z_NULL;
- distcode = Z_NULL;
-
- /* Inflate until end of block marked as last */
- for (;;)
- switch (mode) {
- case TYPE:
- /* determine and dispatch block type */
- if (lastblock) {
- BYTEBITS();
- mode = DONE;
- break;
- }
- NEEDBITS(3);
- lastblock = BITS(1);
- DROPBITS(1);
- switch (BITS(2)) {
- case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
- lastblock ? " (last)" : ""));
- mode = STORED;
- break;
- case 1: /* fixed block */
- lencode = lenfix;
- lenbits = 9;
- distcode = distfix;
- distbits = 5;
- Tracev((stderr, "inflate: fixed codes block%s\n",
- lastblock ? " (last)" : ""));
- mode = LEN; /* decode codes */
- break;
- case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
- lastblock ? " (last)" : ""));
- mode = TABLE;
- break;
- case 3:
- strm->msg = (char *)"invalid block type";
- mode = BAD;
- }
- DROPBITS(2);
- break;
-
- case STORED:
- /* get and verify stored block length */
- BYTEBITS(); /* go to byte boundary */
- NEEDBITS(32);
- if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
- strm->msg = (char *)"invalid stored block lengths";
- mode = BAD;
- break;
- }
- length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %lu\n",
- length));
- INITBITS();
-
- /* copy stored block from input to output */
- while (length != 0) {
- copy = length;
- PULL();
- ROOM();
- if (copy > have) copy = have;
- if (copy > left) copy = left;
- zmemcpy(put, next, copy);
- have -= copy;
- next += copy;
- left -= copy;
- put += copy;
- length -= copy;
- }
- Tracev((stderr, "inflate: stored end\n"));
- mode = TYPE;
- break;
-
- case TABLE:
- /* get dynamic table entries descriptor */
- NEEDBITS(14);
- state->nlen = BITS(5) + 257;
- DROPBITS(5);
- state->ndist = BITS(5) + 1;
- DROPBITS(5);
- state->ncode = BITS(4) + 4;
- DROPBITS(4);
- if (state->nlen > 286) {
- strm->msg = (char *)"too many length symbols";
- mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: table sizes ok\n"));
-
- /* get code length code lengths (not a typo) */
- state->have = 0;
- while (state->have < state->ncode) {
- NEEDBITS(3);
- state->lens[order[state->have++]] = (unsigned short)BITS(3);
- DROPBITS(3);
- }
- while (state->have < 19)
- state->lens[order[state->have++]] = 0;
- state->next = state->codes;
- lencode = (code const FAR *)(state->next);
- lenbits = 7;
- ret = inflate_table9(CODES, state->lens, 19, &(state->next),
- &(lenbits), state->work);
- if (ret) {
- strm->msg = (char *)"invalid code lengths set";
- mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: code lengths ok\n"));
-
- /* get length and distance code code lengths */
- state->have = 0;
- while (state->have < state->nlen + state->ndist) {
- for (;;) {
- here = lencode[BITS(lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if (here.val < 16) {
- NEEDBITS(here.bits);
- DROPBITS(here.bits);
- state->lens[state->have++] = here.val;
- }
- else {
- if (here.val == 16) {
- NEEDBITS(here.bits + 2);
- DROPBITS(here.bits);
- if (state->have == 0) {
- strm->msg = (char *)"invalid bit length repeat";
- mode = BAD;
- break;
- }
- len = (unsigned)(state->lens[state->have - 1]);
- copy = 3 + BITS(2);
- DROPBITS(2);
- }
- else if (here.val == 17) {
- NEEDBITS(here.bits + 3);
- DROPBITS(here.bits);
- len = 0;
- copy = 3 + BITS(3);
- DROPBITS(3);
- }
- else {
- NEEDBITS(here.bits + 7);
- DROPBITS(here.bits);
- len = 0;
- copy = 11 + BITS(7);
- DROPBITS(7);
- }
- if (state->have + copy > state->nlen + state->ndist) {
- strm->msg = (char *)"invalid bit length repeat";
- mode = BAD;
- break;
- }
- while (copy--)
- state->lens[state->have++] = (unsigned short)len;
- }
- }
-
- /* handle error breaks in while */
- if (mode == BAD) break;
-
- /* check for end-of-block code (better have one) */
- if (state->lens[256] == 0) {
- strm->msg = (char *)"invalid code -- missing end-of-block";
- mode = BAD;
- break;
- }
-
- /* build code tables -- note: do not change the lenbits or distbits
- values here (9 and 6) without reading the comments in inftree9.h
- concerning the ENOUGH constants, which depend on those values */
- state->next = state->codes;
- lencode = (code const FAR *)(state->next);
- lenbits = 9;
- ret = inflate_table9(LENS, state->lens, state->nlen,
- &(state->next), &(lenbits), state->work);
- if (ret) {
- strm->msg = (char *)"invalid literal/lengths set";
- mode = BAD;
- break;
- }
- distcode = (code const FAR *)(state->next);
- distbits = 6;
- ret = inflate_table9(DISTS, state->lens + state->nlen,
- state->ndist, &(state->next), &(distbits),
- state->work);
- if (ret) {
- strm->msg = (char *)"invalid distances set";
- mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: codes ok\n"));
- mode = LEN;
-
- case LEN:
- /* get a literal, length, or end-of-block code */
- for (;;) {
- here = lencode[BITS(lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if (here.op && (here.op & 0xf0) == 0) {
- last = here;
- for (;;) {
- here = lencode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
- PULLBYTE();
- }
- DROPBITS(last.bits);
- }
- DROPBITS(here.bits);
- length = (unsigned)here.val;
-
- /* process literal */
- if (here.op == 0) {
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
- "inflate: literal '%c'\n" :
- "inflate: literal 0x%02x\n", here.val));
- ROOM();
- *put++ = (unsigned char)(length);
- left--;
- mode = LEN;
- break;
- }
-
- /* process end of block */
- if (here.op & 32) {
- Tracevv((stderr, "inflate: end of block\n"));
- mode = TYPE;
- break;
- }
-
- /* invalid code */
- if (here.op & 64) {
- strm->msg = (char *)"invalid literal/length code";
- mode = BAD;
- break;
- }
-
- /* length code -- get extra bits, if any */
- extra = (unsigned)(here.op) & 31;
- if (extra != 0) {
- NEEDBITS(extra);
- length += BITS(extra);
- DROPBITS(extra);
- }
- Tracevv((stderr, "inflate: length %lu\n", length));
-
- /* get distance code */
- for (;;) {
- here = distcode[BITS(distbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if ((here.op & 0xf0) == 0) {
- last = here;
- for (;;) {
- here = distcode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
- PULLBYTE();
- }
- DROPBITS(last.bits);
- }
- DROPBITS(here.bits);
- if (here.op & 64) {
- strm->msg = (char *)"invalid distance code";
- mode = BAD;
- break;
- }
- offset = (unsigned)here.val;
-
- /* get distance extra bits, if any */
- extra = (unsigned)(here.op) & 15;
- if (extra != 0) {
- NEEDBITS(extra);
- offset += BITS(extra);
- DROPBITS(extra);
- }
- if (offset > WSIZE - (wrap ? 0: left)) {
- strm->msg = (char *)"invalid distance too far back";
- mode = BAD;
- break;
- }
- Tracevv((stderr, "inflate: distance %lu\n", offset));
-
- /* copy match from window to output */
- do {
- ROOM();
- copy = WSIZE - offset;
- if (copy < left) {
- from = put + copy;
- copy = left - copy;
- }
- else {
- from = put - offset;
- copy = left;
- }
- if (copy > length) copy = length;
- length -= copy;
- left -= copy;
- do {
- *put++ = *from++;
- } while (--copy);
- } while (length != 0);
- break;
-
- case DONE:
- /* inflate stream terminated properly -- write leftover output */
- ret = Z_STREAM_END;
- if (left < WSIZE) {
- if (out(out_desc, window, (unsigned)(WSIZE - left)))
- ret = Z_BUF_ERROR;
- }
- goto inf_leave;
-
- case BAD:
- ret = Z_DATA_ERROR;
- goto inf_leave;
-
- default: /* can't happen, but makes compilers happy */
- ret = Z_STREAM_ERROR;
- goto inf_leave;
- }
-
- /* Return unused input */
- inf_leave:
- strm->next_in = next;
- strm->avail_in = have;
- return ret;
-}
-
-int ZEXPORT inflateBack9End(strm)
-z_stream FAR *strm;
-{
- if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
- return Z_STREAM_ERROR;
- ZFREE(strm, strm->state);
- strm->state = Z_NULL;
- Tracev((stderr, "inflate: end\n"));
- return Z_OK;
-}
diff --git a/cpukit/zlib/contrib/infback9/infback9.h b/cpukit/zlib/contrib/infback9/infback9.h
deleted file mode 100644
index 1073c0a38e..0000000000
--- a/cpukit/zlib/contrib/infback9/infback9.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* infback9.h -- header for using inflateBack9 functions
- * Copyright (C) 2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- * This header file and associated patches provide a decoder for PKWare's
- * undocumented deflate64 compression method (method 9). Use with infback9.c,
- * inftree9.h, inftree9.c, and inffix9.h. These patches are not supported.
- * This should be compiled with zlib, since it uses zutil.h and zutil.o.
- * This code has not yet been tested on 16-bit architectures. See the
- * comments in zlib.h for inflateBack() usage. These functions are used
- * identically, except that there is no windowBits parameter, and a 64K
- * window must be provided. Also if int's are 16 bits, then a zero for
- * the third parameter of the "out" function actually means 65536UL.
- * zlib.h must be included before this header file.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-ZEXTERN int ZEXPORT inflateBack9 OF((z_stream FAR *strm,
- in_func in, void FAR *in_desc,
- out_func out, void FAR *out_desc));
-ZEXTERN int ZEXPORT inflateBack9End OF((z_stream FAR *strm));
-ZEXTERN int ZEXPORT inflateBack9Init_ OF((z_stream FAR *strm,
- unsigned char FAR *window,
- const char *version,
- int stream_size));
-#define inflateBack9Init(strm, window) \
- inflateBack9Init_((strm), (window), \
- ZLIB_VERSION, sizeof(z_stream))
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/cpukit/zlib/contrib/infback9/inffix9.h b/cpukit/zlib/contrib/infback9/inffix9.h
deleted file mode 100644
index ee5671d2df..0000000000
--- a/cpukit/zlib/contrib/infback9/inffix9.h
+++ /dev/null
@@ -1,107 +0,0 @@
- /* inffix9.h -- table for decoding deflate64 fixed codes
- * Generated automatically by makefixed9().
- */
-
- /* WARNING: this file should *not* be used by applications.
- It is part of the implementation of this library and is
- subject to change. Applications should only use zlib.h.
- */
-
- static const code lenfix[512] = {
- {96,7,0},{0,8,80},{0,8,16},{132,8,115},{130,7,31},{0,8,112},
- {0,8,48},{0,9,192},{128,7,10},{0,8,96},{0,8,32},{0,9,160},
- {0,8,0},{0,8,128},{0,8,64},{0,9,224},{128,7,6},{0,8,88},
- {0,8,24},{0,9,144},{131,7,59},{0,8,120},{0,8,56},{0,9,208},
- {129,7,17},{0,8,104},{0,8,40},{0,9,176},{0,8,8},{0,8,136},
- {0,8,72},{0,9,240},{128,7,4},{0,8,84},{0,8,20},{133,8,227},
- {131,7,43},{0,8,116},{0,8,52},{0,9,200},{129,7,13},{0,8,100},
- {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},
- {128,7,8},{0,8,92},{0,8,28},{0,9,152},{132,7,83},{0,8,124},
- {0,8,60},{0,9,216},{130,7,23},{0,8,108},{0,8,44},{0,9,184},
- {0,8,12},{0,8,140},{0,8,76},{0,9,248},{128,7,3},{0,8,82},
- {0,8,18},{133,8,163},{131,7,35},{0,8,114},{0,8,50},{0,9,196},
- {129,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},{0,8,130},
- {0,8,66},{0,9,228},{128,7,7},{0,8,90},{0,8,26},{0,9,148},
- {132,7,67},{0,8,122},{0,8,58},{0,9,212},{130,7,19},{0,8,106},
- {0,8,42},{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},
- {128,7,5},{0,8,86},{0,8,22},{65,8,0},{131,7,51},{0,8,118},
- {0,8,54},{0,9,204},{129,7,15},{0,8,102},{0,8,38},{0,9,172},
- {0,8,6},{0,8,134},{0,8,70},{0,9,236},{128,7,9},{0,8,94},
- {0,8,30},{0,9,156},{132,7,99},{0,8,126},{0,8,62},{0,9,220},
- {130,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
- {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{133,8,131},
- {130,7,31},{0,8,113},{0,8,49},{0,9,194},{128,7,10},{0,8,97},
- {0,8,33},{0,9,162},{0,8,1},{0,8,129},{0,8,65},{0,9,226},
- {128,7,6},{0,8,89},{0,8,25},{0,9,146},{131,7,59},{0,8,121},
- {0,8,57},{0,9,210},{129,7,17},{0,8,105},{0,8,41},{0,9,178},
- {0,8,9},{0,8,137},{0,8,73},{0,9,242},{128,7,4},{0,8,85},
- {0,8,21},{144,8,3},{131,7,43},{0,8,117},{0,8,53},{0,9,202},
- {129,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},
- {0,8,69},{0,9,234},{128,7,8},{0,8,93},{0,8,29},{0,9,154},
- {132,7,83},{0,8,125},{0,8,61},{0,9,218},{130,7,23},{0,8,109},
- {0,8,45},{0,9,186},{0,8,13},{0,8,141},{0,8,77},{0,9,250},
- {128,7,3},{0,8,83},{0,8,19},{133,8,195},{131,7,35},{0,8,115},
- {0,8,51},{0,9,198},{129,7,11},{0,8,99},{0,8,35},{0,9,166},
- {0,8,3},{0,8,131},{0,8,67},{0,9,230},{128,7,7},{0,8,91},
- {0,8,27},{0,9,150},{132,7,67},{0,8,123},{0,8,59},{0,9,214},
- {130,7,19},{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},
- {0,8,75},{0,9,246},{128,7,5},{0,8,87},{0,8,23},{77,8,0},
- {131,7,51},{0,8,119},{0,8,55},{0,9,206},{129,7,15},{0,8,103},
- {0,8,39},{0,9,174},{0,8,7},{0,8,135},{0,8,71},{0,9,238},
- {128,7,9},{0,8,95},{0,8,31},{0,9,158},{132,7,99},{0,8,127},
- {0,8,63},{0,9,222},{130,7,27},{0,8,111},{0,8,47},{0,9,190},
- {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},
- {0,8,16},{132,8,115},{130,7,31},{0,8,112},{0,8,48},{0,9,193},
- {128,7,10},{0,8,96},{0,8,32},{0,9,161},{0,8,0},{0,8,128},
- {0,8,64},{0,9,225},{128,7,6},{0,8,88},{0,8,24},{0,9,145},
- {131,7,59},{0,8,120},{0,8,56},{0,9,209},{129,7,17},{0,8,104},
- {0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},{0,9,241},
- {128,7,4},{0,8,84},{0,8,20},{133,8,227},{131,7,43},{0,8,116},
- {0,8,52},{0,9,201},{129,7,13},{0,8,100},{0,8,36},{0,9,169},
- {0,8,4},{0,8,132},{0,8,68},{0,9,233},{128,7,8},{0,8,92},
- {0,8,28},{0,9,153},{132,7,83},{0,8,124},{0,8,60},{0,9,217},
- {130,7,23},{0,8,108},{0,8,44},{0,9,185},{0,8,12},{0,8,140},
- {0,8,76},{0,9,249},{128,7,3},{0,8,82},{0,8,18},{133,8,163},
- {131,7,35},{0,8,114},{0,8,50},{0,9,197},{129,7,11},{0,8,98},
- {0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
- {128,7,7},{0,8,90},{0,8,26},{0,9,149},{132,7,67},{0,8,122},
- {0,8,58},{0,9,213},{130,7,19},{0,8,106},{0,8,42},{0,9,181},
- {0,8,10},{0,8,138},{0,8,74},{0,9,245},{128,7,5},{0,8,86},
- {0,8,22},{65,8,0},{131,7,51},{0,8,118},{0,8,54},{0,9,205},
- {129,7,15},{0,8,102},{0,8,38},{0,9,173},{0,8,6},{0,8,134},
- {0,8,70},{0,9,237},{128,7,9},{0,8,94},{0,8,30},{0,9,157},
- {132,7,99},{0,8,126},{0,8,62},{0,9,221},{130,7,27},{0,8,110},
- {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},
- {96,7,0},{0,8,81},{0,8,17},{133,8,131},{130,7,31},{0,8,113},
- {0,8,49},{0,9,195},{128,7,10},{0,8,97},{0,8,33},{0,9,163},
- {0,8,1},{0,8,129},{0,8,65},{0,9,227},{128,7,6},{0,8,89},
- {0,8,25},{0,9,147},{131,7,59},{0,8,121},{0,8,57},{0,9,211},
- {129,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},{0,8,137},
- {0,8,73},{0,9,243},{128,7,4},{0,8,85},{0,8,21},{144,8,3},
- {131,7,43},{0,8,117},{0,8,53},{0,9,203},{129,7,13},{0,8,101},
- {0,8,37},{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},
- {128,7,8},{0,8,93},{0,8,29},{0,9,155},{132,7,83},{0,8,125},
- {0,8,61},{0,9,219},{130,7,23},{0,8,109},{0,8,45},{0,9,187},
- {0,8,13},{0,8,141},{0,8,77},{0,9,251},{128,7,3},{0,8,83},
- {0,8,19},{133,8,195},{131,7,35},{0,8,115},{0,8,51},{0,9,199},
- {129,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
- {0,8,67},{0,9,231},{128,7,7},{0,8,91},{0,8,27},{0,9,151},
- {132,7,67},{0,8,123},{0,8,59},{0,9,215},{130,7,19},{0,8,107},
- {0,8,43},{0,9,183},{0,8,11},{0,8,139},{0,8,75},{0,9,247},
- {128,7,5},{0,8,87},{0,8,23},{77,8,0},{131,7,51},{0,8,119},
- {0,8,55},{0,9,207},{129,7,15},{0,8,103},{0,8,39},{0,9,175},
- {0,8,7},{0,8,135},{0,8,71},{0,9,239},{128,7,9},{0,8,95},
- {0,8,31},{0,9,159},{132,7,99},{0,8,127},{0,8,63},{0,9,223},
- {130,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},
- {0,8,79},{0,9,255}
- };
-
- static const code distfix[32] = {
- {128,5,1},{135,5,257},{131,5,17},{139,5,4097},{129,5,5},
- {137,5,1025},{133,5,65},{141,5,16385},{128,5,3},{136,5,513},
- {132,5,33},{140,5,8193},{130,5,9},{138,5,2049},{134,5,129},
- {142,5,32769},{128,5,2},{135,5,385},{131,5,25},{139,5,6145},
- {129,5,7},{137,5,1537},{133,5,97},{141,5,24577},{128,5,4},
- {136,5,769},{132,5,49},{140,5,12289},{130,5,13},{138,5,3073},
- {134,5,193},{142,5,49153}
- };
diff --git a/cpukit/zlib/contrib/infback9/inflate9.h b/cpukit/zlib/contrib/infback9/inflate9.h
deleted file mode 100644
index ee9a79394b..0000000000
--- a/cpukit/zlib/contrib/infback9/inflate9.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* inflate9.h -- internal inflate state definition
- * Copyright (C) 1995-2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* WARNING: this file should *not* be used by applications. It is
- part of the implementation of the compression library and is
- subject to change. Applications should only use zlib.h.
- */
-
-/* Possible inflate modes between inflate() calls */
-typedef enum {
- TYPE, /* i: waiting for type bits, including last-flag bit */
- STORED, /* i: waiting for stored size (length and complement) */
- TABLE, /* i: waiting for dynamic block table lengths */
- LEN, /* i: waiting for length/lit code */
- DONE, /* finished check, done -- remain here until reset */
- BAD /* got a data error -- remain here until reset */
-} inflate_mode;
-
-/*
- State transitions between above modes -
-
- (most modes can go to the BAD mode -- not shown for clarity)
-
- Read deflate blocks:
- TYPE -> STORED or TABLE or LEN or DONE
- STORED -> TYPE
- TABLE -> LENLENS -> CODELENS -> LEN
- Read deflate codes:
- LEN -> LEN or TYPE
- */
-
-/* state maintained between inflate() calls. Approximately 7K bytes. */
-struct inflate_state {
- /* sliding window */
- unsigned char FAR *window; /* allocated sliding window, if needed */
- /* dynamic table building */
- unsigned ncode; /* number of code length code lengths */
- unsigned nlen; /* number of length code lengths */
- unsigned ndist; /* number of distance code lengths */
- unsigned have; /* number of code lengths in lens[] */
- code FAR *next; /* next available space in codes[] */
- unsigned short lens[320]; /* temporary storage for code lengths */
- unsigned short work[288]; /* work area for code table building */
- code codes[ENOUGH]; /* space for code tables */
-};
diff --git a/cpukit/zlib/contrib/infback9/inftree9.c b/cpukit/zlib/contrib/infback9/inftree9.c
deleted file mode 100644
index 510bba694e..0000000000
--- a/cpukit/zlib/contrib/infback9/inftree9.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/* inftree9.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-2010 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "zutil.h"
-#include "inftree9.h"
-
-#define MAXBITS 15
-
-const char inflate9_copyright[] =
- " inflate9 1.2.4 Copyright 1995-2010 Mark Adler ";
-/*
- If you use the zlib library in a product, an acknowledgment is welcome
- in the documentation of your product. If for some reason you cannot
- include such an acknowledgment, I would appreciate that you keep this
- copyright string in the executable of your product.
- */
-
-/*
- Build a set of tables to decode the provided canonical Huffman code.
- The code lengths are lens[0..codes-1]. The result starts at *table,
- whose indices are 0..2^bits-1. work is a writable array of at least
- lens shorts, which is used as a work area. type is the type of code
- to be generated, CODES, LENS, or DISTS. On return, zero is success,
- -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
- on return points to the next available entry's address. bits is the
- requested root table index bits, and on return it is the actual root
- table index bits. It will differ if the request is greater than the
- longest code or if it is less than the shortest code.
- */
-int inflate_table9(type, lens, codes, table, bits, work)
-codetype type;
-unsigned short FAR *lens;
-unsigned codes;
-code FAR * FAR *table;
-unsigned FAR *bits;
-unsigned short FAR *work;
-{
- unsigned len; /* a code's length in bits */
- unsigned sym; /* index of code symbols */
- unsigned min, max; /* minimum and maximum code lengths */
- unsigned root; /* number of index bits for root table */
- unsigned curr; /* number of index bits for current table */
- unsigned drop; /* code bits to drop for sub-table */
- int left; /* number of prefix codes available */
- unsigned used; /* code entries in table used */
- unsigned huff; /* Huffman code */
- unsigned incr; /* for incrementing code, index */
- unsigned fill; /* index for replicating entries */
- unsigned low; /* low bits for current root entry */
- unsigned mask; /* mask for low root bits */
- code this; /* table entry for duplication */
- code FAR *next; /* next available space in table */
- const unsigned short FAR *base; /* base value table to use */
- const unsigned short FAR *extra; /* extra bits table to use */
- int end; /* use base and extra for symbol > end */
- unsigned short count[MAXBITS+1]; /* number of codes of each length */
- unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
- static const unsigned short lbase[31] = { /* Length codes 257..285 base */
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17,
- 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115,
- 131, 163, 195, 227, 3, 0, 0};
- static const unsigned short lext[31] = { /* Length codes 257..285 extra */
- 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
- 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
- 133, 133, 133, 133, 144, 64, 195};
- static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
- 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
- 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153};
- static const unsigned short dext[32] = { /* Distance codes 0..31 extra */
- 128, 128, 128, 128, 129, 129, 130, 130, 131, 131, 132, 132,
- 133, 133, 134, 134, 135, 135, 136, 136, 137, 137, 138, 138,
- 139, 139, 140, 140, 141, 141, 142, 142};
-
- /*
- Process a set of code lengths to create a canonical Huffman code. The
- code lengths are lens[0..codes-1]. Each length corresponds to the
- symbols 0..codes-1. The Huffman code is generated by first sorting the
- symbols by length from short to long, and retaining the symbol order
- for codes with equal lengths. Then the code starts with all zero bits
- for the first code of the shortest length, and the codes are integer
- increments for the same length, and zeros are appended as the length
- increases. For the deflate format, these bits are stored backwards
- from their more natural integer increment ordering, and so when the
- decoding tables are built in the large loop below, the integer codes
- are incremented backwards.
-
- This routine assumes, but does not check, that all of the entries in
- lens[] are in the range 0..MAXBITS. The caller must assure this.
- 1..MAXBITS is interpreted as that code length. zero means that that
- symbol does not occur in this code.
-
- The codes are sorted by computing a count of codes for each length,
- creating from that a table of starting indices for each length in the
- sorted table, and then entering the symbols in order in the sorted
- table. The sorted table is work[], with that space being provided by
- the caller.
-
- The length counts are used for other purposes as well, i.e. finding
- the minimum and maximum length codes, determining if there are any
- codes at all, checking for a valid set of lengths, and looking ahead
- at length counts to determine sub-table sizes when building the
- decoding tables.
- */
-
- /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
- for (len = 0; len <= MAXBITS; len++)
- count[len] = 0;
- for (sym = 0; sym < codes; sym++)
- count[lens[sym]]++;
-
- /* bound code lengths, force root to be within code lengths */
- root = *bits;
- for (max = MAXBITS; max >= 1; max--)
- if (count[max] != 0) break;
- if (root > max) root = max;
- if (max == 0) return -1; /* no codes! */
- for (min = 1; min <= MAXBITS; min++)
- if (count[min] != 0) break;
- if (root < min) root = min;
-
- /* check for an over-subscribed or incomplete set of lengths */
- left = 1;
- for (len = 1; len <= MAXBITS; len++) {
- left <<= 1;
- left -= count[len];
- if (left < 0) return -1; /* over-subscribed */
- }
- if (left > 0 && (type == CODES || max != 1))
- return -1; /* incomplete set */
-
- /* generate offsets into symbol table for each length for sorting */
- offs[1] = 0;
- for (len = 1; len < MAXBITS; len++)
- offs[len + 1] = offs[len] + count[len];
-
- /* sort symbols by length, by symbol order within each length */
- for (sym = 0; sym < codes; sym++)
- if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
-
- /*
- Create and fill in decoding tables. In this loop, the table being
- filled is at next and has curr index bits. The code being used is huff
- with length len. That code is converted to an index by dropping drop
- bits off of the bottom. For codes where len is less than drop + curr,
- those top drop + curr - len bits are incremented through all values to
- fill the table with replicated entries.
-
- root is the number of index bits for the root table. When len exceeds
- root, sub-tables are created pointed to by the root entry with an index
- of the low root bits of huff. This is saved in low to check for when a
- new sub-table should be started. drop is zero when the root table is
- being filled, and drop is root when sub-tables are being filled.
-
- When a new sub-table is needed, it is necessary to look ahead in the
- code lengths to determine what size sub-table is needed. The length
- counts are used for this, and so count[] is decremented as codes are
- entered in the tables.
-
- used keeps track of how many table entries have been allocated from the
- provided *table space. It is checked for LENS and DIST tables against
- the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
- the initial root table size constants. See the comments in inftree9.h
- for more information.
-
- sym increments through all symbols, and the loop terminates when
- all codes of length max, i.e. all codes, have been processed. This
- routine permits incomplete codes, so another loop after this one fills
- in the rest of the decoding tables with invalid code markers.
- */
-
- /* set up for code type */
- switch (type) {
- case CODES:
- base = extra = work; /* dummy value--not used */
- end = 19;
- break;
- case LENS:
- base = lbase;
- base -= 257;
- extra = lext;
- extra -= 257;
- end = 256;
- break;
- default: /* DISTS */
- base = dbase;
- extra = dext;
- end = -1;
- }
-
- /* initialize state for loop */
- huff = 0; /* starting code */
- sym = 0; /* starting code symbol */
- len = min; /* starting code length */
- next = *table; /* current table to fill in */
- curr = root; /* current table index bits */
- drop = 0; /* current bits to drop from code for index */
- low = (unsigned)(-1); /* trigger new sub-table when len > root */
- used = 1U << root; /* use root table entries */
- mask = used - 1; /* mask for comparing low */
-
- /* check available table space */
- if ((type == LENS && used >= ENOUGH_LENS) ||
- (type == DISTS && used >= ENOUGH_DISTS))
- return 1;
-
- /* process all codes and make table entries */
- for (;;) {
- /* create table entry */
- this.bits = (unsigned char)(len - drop);
- if ((int)(work[sym]) < end) {
- this.op = (unsigned char)0;
- this.val = work[sym];
- }
- else if ((int)(work[sym]) > end) {
- this.op = (unsigned char)(extra[work[sym]]);
- this.val = base[work[sym]];
- }
- else {
- this.op = (unsigned char)(32 + 64); /* end of block */
- this.val = 0;
- }
-
- /* replicate for those indices with low len bits equal to huff */
- incr = 1U << (len - drop);
- fill = 1U << curr;
- do {
- fill -= incr;
- next[(huff >> drop) + fill] = this;
- } while (fill != 0);
-
- /* backwards increment the len-bit code huff */
- incr = 1U << (len - 1);
- while (huff & incr)
- incr >>= 1;
- if (incr != 0) {
- huff &= incr - 1;
- huff += incr;
- }
- else
- huff = 0;
-
- /* go to next symbol, update count, len */
- sym++;
- if (--(count[len]) == 0) {
- if (len == max) break;
- len = lens[work[sym]];
- }
-
- /* create new sub-table if needed */
- if (len > root && (huff & mask) != low) {
- /* if first time, transition to sub-tables */
- if (drop == 0)
- drop = root;
-
- /* increment past last table */
- next += 1U << curr;
-
- /* determine length of next table */
- curr = len - drop;
- left = (int)(1 << curr);
- while (curr + drop < max) {
- left -= count[curr + drop];
- if (left <= 0) break;
- curr++;
- left <<= 1;
- }
-
- /* check for enough space */
- used += 1U << curr;
- if ((type == LENS && used >= ENOUGH_LENS) ||
- (type == DISTS && used >= ENOUGH_DISTS))
- return 1;
-
- /* point entry in root table to sub-table */
- low = huff & mask;
- (*table)[low].op = (unsigned char)curr;
- (*table)[low].bits = (unsigned char)root;
- (*table)[low].val = (unsigned short)(next - *table);
- }
- }
-
- /*
- Fill in rest of table for incomplete codes. This loop is similar to the
- loop above in incrementing huff for table indices. It is assumed that
- len is equal to curr + drop, so there is no loop needed to increment
- through high index bits. When the current sub-table is filled, the loop
- drops back to the root table to fill in any remaining entries there.
- */
- this.op = (unsigned char)64; /* invalid code marker */
- this.bits = (unsigned char)(len - drop);
- this.val = (unsigned short)0;
- while (huff != 0) {
- /* when done with sub-table, drop back to root table */
- if (drop != 0 && (huff & mask) != low) {
- drop = 0;
- len = root;
- next = *table;
- curr = root;
- this.bits = (unsigned char)len;
- }
-
- /* put invalid code marker in table */
- next[huff >> drop] = this;
-
- /* backwards increment the len-bit code huff */
- incr = 1U << (len - 1);
- while (huff & incr)
- incr >>= 1;
- if (incr != 0) {
- huff &= incr - 1;
- huff += incr;
- }
- else
- huff = 0;
- }
-
- /* set return parameters */
- *table += used;
- *bits = root;
- return 0;
-}
diff --git a/cpukit/zlib/contrib/infback9/inftree9.h b/cpukit/zlib/contrib/infback9/inftree9.h
deleted file mode 100644
index 5ab21f0c6d..0000000000
--- a/cpukit/zlib/contrib/infback9/inftree9.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* inftree9.h -- header to use inftree9.c
- * Copyright (C) 1995-2008 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* WARNING: this file should *not* be used by applications. It is
- part of the implementation of the compression library and is
- subject to change. Applications should only use zlib.h.
- */
-
-/* Structure for decoding tables. Each entry provides either the
- information needed to do the operation requested by the code that
- indexed that table entry, or it provides a pointer to another
- table that indexes more bits of the code. op indicates whether
- the entry is a pointer to another table, a literal, a length or
- distance, an end-of-block, or an invalid code. For a table
- pointer, the low four bits of op is the number of index bits of
- that table. For a length or distance, the low four bits of op
- is the number of extra bits to get after the code. bits is
- the number of bits in this code or part of the code to drop off
- of the bit buffer. val is the actual byte to output in the case
- of a literal, the base length or distance, or the offset from
- the current table to the next table. Each entry is four bytes. */
-typedef struct {
- unsigned char op; /* operation, extra bits, table bits */
- unsigned char bits; /* bits in this part of the code */
- unsigned short val; /* offset in table or code value */
-} code;
-
-/* op values as set by inflate_table():
- 00000000 - literal
- 0000tttt - table link, tttt != 0 is the number of table index bits
- 100eeeee - length or distance, eeee is the number of extra bits
- 01100000 - end of block
- 01000000 - invalid code
- */
-
-/* Maximum size of the dynamic table. The maximum number of code structures is
- 1446, which is the sum of 852 for literal/length codes and 594 for distance
- codes. These values were found by exhaustive searches using the program
- examples/enough.c found in the zlib distribtution. The arguments to that
- program are the number of symbols, the initial root table size, and the
- maximum bit length of a code. "enough 286 9 15" for literal/length codes
- returns returns 852, and "enough 32 6 15" for distance codes returns 594.
- The initial root table size (9 or 6) is found in the fifth argument of the
- inflate_table() calls in infback9.c. If the root table size is changed,
- then these maximum sizes would be need to be recalculated and updated. */
-#define ENOUGH_LENS 852
-#define ENOUGH_DISTS 594
-#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
-
-/* Type of code to build for inflate_table9() */
-typedef enum {
- CODES,
- LENS,
- DISTS
-} codetype;
-
-extern int inflate_table9 OF((codetype type, unsigned short FAR *lens,
- unsigned codes, code FAR * FAR *table,
- unsigned FAR *bits, unsigned short FAR *work));
diff --git a/cpukit/zlib/contrib/inflate86/inffas86.c b/cpukit/zlib/contrib/inflate86/inffas86.c
deleted file mode 100644
index 7292f67b75..0000000000
--- a/cpukit/zlib/contrib/inflate86/inffas86.c
+++ /dev/null
@@ -1,1157 +0,0 @@
-/* inffas86.c is a hand tuned assembler version of
- *
- * inffast.c -- fast decoding
- * Copyright (C) 1995-2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- *
- * Copyright (C) 2003 Chris Anderson <christop@charm.net>
- * Please use the copyright conditions above.
- *
- * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also
- * slightly quicker on x86 systems because, instead of using rep movsb to copy
- * data, it uses rep movsw, which moves data in 2-byte chunks instead of single
- * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates
- * from http://fedora.linux.duke.edu/fc1_x86_64
- * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with
- * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version,
- * when decompressing mozilla-source-1.3.tar.gz.
- *
- * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
- * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at
- * the moment. I have successfully compiled and tested this code with gcc2.96,
- * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S
- * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
- * enabled. I will attempt to merge the MMX code into this version. Newer
- * versions of this and inffast.S can be found at
- * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
- */
-
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "inffast.h"
-
-/* Mark Adler's comments from inffast.c: */
-
-/*
- Decode literal, length, and distance codes and write out the resulting
- literal and match bytes until either not enough input or output is
- available, an end-of-block is encountered, or a data error is encountered.
- When large enough input and output buffers are supplied to inflate(), for
- example, a 16K input buffer and a 64K output buffer, more than 95% of the
- inflate execution time is spent in this routine.
-
- Entry assumptions:
-
- state->mode == LEN
- strm->avail_in >= 6
- strm->avail_out >= 258
- start >= strm->avail_out
- state->bits < 8
-
- On return, state->mode is one of:
-
- LEN -- ran out of enough output space or enough available input
- TYPE -- reached end of block code, inflate() to interpret next block
- BAD -- error in block data
-
- Notes:
-
- - The maximum input bits used by a length/distance pair is 15 bits for the
- length code, 5 bits for the length extra, 15 bits for the distance code,
- and 13 bits for the distance extra. This totals 48 bits, or six bytes.
- Therefore if strm->avail_in >= 6, then there is enough input to avoid
- checking for available input while decoding.
-
- - The maximum bytes that a single length/distance pair can output is 258
- bytes, which is the maximum length that can be coded. inflate_fast()
- requires strm->avail_out >= 258 for each loop to avoid checking for
- output space.
- */
-void inflate_fast(strm, start)
-z_streamp strm;
-unsigned start; /* inflate()'s starting value for strm->avail_out */
-{
- struct inflate_state FAR *state;
- struct inffast_ar {
-/* 64 32 x86 x86_64 */
-/* ar offset register */
-/* 0 0 */ void *esp; /* esp save */
-/* 8 4 */ void *ebp; /* ebp save */
-/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */
-/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */
-/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */
-/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */
-/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */
-/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */
-/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */
-/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */
-/* 80 40 */ unsigned long hold; /* edx rdx local strm->hold */
-/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */
-/* 92 48 */ unsigned wsize; /* window size */
-/* 96 52 */ unsigned write; /* window write index */
-/*100 56 */ unsigned lmask; /* r12 mask for lcode */
-/*104 60 */ unsigned dmask; /* r13 mask for dcode */
-/*108 64 */ unsigned len; /* r14 match length */
-/*112 68 */ unsigned dist; /* r15 match distance */
-/*116 72 */ unsigned status; /* set when state chng*/
- } ar;
-
-#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )
-#define PAD_AVAIL_IN 6
-#define PAD_AVAIL_OUT 258
-#else
-#define PAD_AVAIL_IN 5
-#define PAD_AVAIL_OUT 257
-#endif
-
- /* copy state to local variables */
- state = (struct inflate_state FAR *)strm->state;
- ar.in = strm->next_in;
- ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN);
- ar.out = strm->next_out;
- ar.beg = ar.out - (start - strm->avail_out);
- ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT);
- ar.wsize = state->wsize;
- ar.write = state->wnext;
- ar.window = state->window;
- ar.hold = state->hold;
- ar.bits = state->bits;
- ar.lcode = state->lencode;
- ar.dcode = state->distcode;
- ar.lmask = (1U << state->lenbits) - 1;
- ar.dmask = (1U << state->distbits) - 1;
-
- /* decode literals and length/distances until end-of-block or not enough
- input data or output space */
-
- /* align in on 1/2 hold size boundary */
- while (((unsigned long)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) {
- ar.hold += (unsigned long)*ar.in++ << ar.bits;
- ar.bits += 8;
- }
-
-#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )
- __asm__ __volatile__ (
-" leaq %0, %%rax\n"
-" movq %%rbp, 8(%%rax)\n" /* save regs rbp and rsp */
-" movq %%rsp, (%%rax)\n"
-" movq %%rax, %%rsp\n" /* make rsp point to &ar */
-" movq 16(%%rsp), %%rsi\n" /* rsi = in */
-" movq 32(%%rsp), %%rdi\n" /* rdi = out */
-" movq 24(%%rsp), %%r9\n" /* r9 = last */
-" movq 48(%%rsp), %%r10\n" /* r10 = end */
-" movq 64(%%rsp), %%rbp\n" /* rbp = lcode */
-" movq 72(%%rsp), %%r11\n" /* r11 = dcode */
-" movq 80(%%rsp), %%rdx\n" /* rdx = hold */
-" movl 88(%%rsp), %%ebx\n" /* ebx = bits */
-" movl 100(%%rsp), %%r12d\n" /* r12d = lmask */
-" movl 104(%%rsp), %%r13d\n" /* r13d = dmask */
- /* r14d = len */
- /* r15d = dist */
-" cld\n"
-" cmpq %%rdi, %%r10\n"
-" je .L_one_time\n" /* if only one decode left */
-" cmpq %%rsi, %%r9\n"
-" je .L_one_time\n"
-" jmp .L_do_loop\n"
-
-".L_one_time:\n"
-" movq %%r12, %%r8\n" /* r8 = lmask */
-" cmpb $32, %%bl\n"
-" ja .L_get_length_code_one_time\n"
-
-" lodsl\n" /* eax = *(uint *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $32, %%bl\n" /* bits += 32 */
-" shlq %%cl, %%rax\n"
-" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */
-" jmp .L_get_length_code_one_time\n"
-
-".align 32,0x90\n"
-".L_while_test:\n"
-" cmpq %%rdi, %%r10\n"
-" jbe .L_break_loop\n"
-" cmpq %%rsi, %%r9\n"
-" jbe .L_break_loop\n"
-
-".L_do_loop:\n"
-" movq %%r12, %%r8\n" /* r8 = lmask */
-" cmpb $32, %%bl\n"
-" ja .L_get_length_code\n" /* if (32 < bits) */
-
-" lodsl\n" /* eax = *(uint *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $32, %%bl\n" /* bits += 32 */
-" shlq %%cl, %%rax\n"
-" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */
-
-".L_get_length_code:\n"
-" andq %%rdx, %%r8\n" /* r8 &= hold */
-" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */
-
-" movb %%ah, %%cl\n" /* cl = this.bits */
-" subb %%ah, %%bl\n" /* bits -= this.bits */
-" shrq %%cl, %%rdx\n" /* hold >>= this.bits */
-
-" testb %%al, %%al\n"
-" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */
-
-" movq %%r12, %%r8\n" /* r8 = lmask */
-" shrl $16, %%eax\n" /* output this.val char */
-" stosb\n"
-
-".L_get_length_code_one_time:\n"
-" andq %%rdx, %%r8\n" /* r8 &= hold */
-" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */
-
-".L_dolen:\n"
-" movb %%ah, %%cl\n" /* cl = this.bits */
-" subb %%ah, %%bl\n" /* bits -= this.bits */
-" shrq %%cl, %%rdx\n" /* hold >>= this.bits */
-
-" testb %%al, %%al\n"
-" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */
-
-" shrl $16, %%eax\n" /* output this.val char */
-" stosb\n"
-" jmp .L_while_test\n"
-
-".align 32,0x90\n"
-".L_test_for_length_base:\n"
-" movl %%eax, %%r14d\n" /* len = this */
-" shrl $16, %%r14d\n" /* len = this.val */
-" movb %%al, %%cl\n"
-
-" testb $16, %%al\n"
-" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */
-" andb $15, %%cl\n" /* op &= 15 */
-" jz .L_decode_distance\n" /* if (!op) */
-
-".L_add_bits_to_len:\n"
-" subb %%cl, %%bl\n"
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n"
-" andl %%edx, %%eax\n" /* eax &= hold */
-" shrq %%cl, %%rdx\n"
-" addl %%eax, %%r14d\n" /* len += hold & mask[op] */
-
-".L_decode_distance:\n"
-" movq %%r13, %%r8\n" /* r8 = dmask */
-" cmpb $32, %%bl\n"
-" ja .L_get_distance_code\n" /* if (32 < bits) */
-
-" lodsl\n" /* eax = *(uint *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $32, %%bl\n" /* bits += 32 */
-" shlq %%cl, %%rax\n"
-" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */
-
-".L_get_distance_code:\n"
-" andq %%rdx, %%r8\n" /* r8 &= hold */
-" movl (%%r11,%%r8,4), %%eax\n" /* eax = dcode[hold & dmask] */
-
-".L_dodist:\n"
-" movl %%eax, %%r15d\n" /* dist = this */
-" shrl $16, %%r15d\n" /* dist = this.val */
-" movb %%ah, %%cl\n"
-" subb %%ah, %%bl\n" /* bits -= this.bits */
-" shrq %%cl, %%rdx\n" /* hold >>= this.bits */
-" movb %%al, %%cl\n" /* cl = this.op */
-
-" testb $16, %%al\n" /* if ((op & 16) == 0) */
-" jz .L_test_for_second_level_dist\n"
-" andb $15, %%cl\n" /* op &= 15 */
-" jz .L_check_dist_one\n"
-
-".L_add_bits_to_dist:\n"
-" subb %%cl, %%bl\n"
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n" /* (1 << op) - 1 */
-" andl %%edx, %%eax\n" /* eax &= hold */
-" shrq %%cl, %%rdx\n"
-" addl %%eax, %%r15d\n" /* dist += hold & ((1 << op) - 1) */
-
-".L_check_window:\n"
-" movq %%rsi, %%r8\n" /* save in so from can use it's reg */
-" movq %%rdi, %%rax\n"
-" subq 40(%%rsp), %%rax\n" /* nbytes = out - beg */
-
-" cmpl %%r15d, %%eax\n"
-" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */
-
-" movl %%r14d, %%ecx\n" /* ecx = len */
-" movq %%rdi, %%rsi\n"
-" subq %%r15, %%rsi\n" /* from = out - dist */
-
-" sarl %%ecx\n"
-" jnc .L_copy_two\n" /* if len % 2 == 0 */
-
-" rep movsw\n"
-" movb (%%rsi), %%al\n"
-" movb %%al, (%%rdi)\n"
-" incq %%rdi\n"
-
-" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */
-" jmp .L_while_test\n"
-
-".L_copy_two:\n"
-" rep movsw\n"
-" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */
-" jmp .L_while_test\n"
-
-".align 32,0x90\n"
-".L_check_dist_one:\n"
-" cmpl $1, %%r15d\n" /* if dist 1, is a memset */
-" jne .L_check_window\n"
-" cmpq %%rdi, 40(%%rsp)\n" /* if out == beg, outside window */
-" je .L_check_window\n"
-
-" movl %%r14d, %%ecx\n" /* ecx = len */
-" movb -1(%%rdi), %%al\n"
-" movb %%al, %%ah\n"
-
-" sarl %%ecx\n"
-" jnc .L_set_two\n"
-" movb %%al, (%%rdi)\n"
-" incq %%rdi\n"
-
-".L_set_two:\n"
-" rep stosw\n"
-" jmp .L_while_test\n"
-
-".align 32,0x90\n"
-".L_test_for_second_level_length:\n"
-" testb $64, %%al\n"
-" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */
-
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n"
-" andl %%edx, %%eax\n" /* eax &= hold */
-" addl %%r14d, %%eax\n" /* eax += len */
-" movl (%%rbp,%%rax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/
-" jmp .L_dolen\n"
-
-".align 32,0x90\n"
-".L_test_for_second_level_dist:\n"
-" testb $64, %%al\n"
-" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */
-
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n"
-" andl %%edx, %%eax\n" /* eax &= hold */
-" addl %%r15d, %%eax\n" /* eax += dist */
-" movl (%%r11,%%rax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/
-" jmp .L_dodist\n"
-
-".align 32,0x90\n"
-".L_clip_window:\n"
-" movl %%eax, %%ecx\n" /* ecx = nbytes */
-" movl 92(%%rsp), %%eax\n" /* eax = wsize, prepare for dist cmp */
-" negl %%ecx\n" /* nbytes = -nbytes */
-
-" cmpl %%r15d, %%eax\n"
-" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */
-
-" addl %%r15d, %%ecx\n" /* nbytes = dist - nbytes */
-" cmpl $0, 96(%%rsp)\n"
-" jne .L_wrap_around_window\n" /* if (write != 0) */
-
-" movq 56(%%rsp), %%rsi\n" /* from = window */
-" subl %%ecx, %%eax\n" /* eax -= nbytes */
-" addq %%rax, %%rsi\n" /* from += wsize - nbytes */
-
-" movl %%r14d, %%eax\n" /* eax = len */
-" cmpl %%ecx, %%r14d\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* eax -= nbytes */
-" rep movsb\n"
-" movq %%rdi, %%rsi\n"
-" subq %%r15, %%rsi\n" /* from = &out[ -dist ] */
-" jmp .L_do_copy\n"
-
-".align 32,0x90\n"
-".L_wrap_around_window:\n"
-" movl 96(%%rsp), %%eax\n" /* eax = write */
-" cmpl %%eax, %%ecx\n"
-" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */
-
-" movl 92(%%rsp), %%esi\n" /* from = wsize */
-" addq 56(%%rsp), %%rsi\n" /* from += window */
-" addq %%rax, %%rsi\n" /* from += write */
-" subq %%rcx, %%rsi\n" /* from -= nbytes */
-" subl %%eax, %%ecx\n" /* nbytes -= write */
-
-" movl %%r14d, %%eax\n" /* eax = len */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movq 56(%%rsp), %%rsi\n" /* from = window */
-" movl 96(%%rsp), %%ecx\n" /* nbytes = write */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movq %%rdi, %%rsi\n"
-" subq %%r15, %%rsi\n" /* from = out - dist */
-" jmp .L_do_copy\n"
-
-".align 32,0x90\n"
-".L_contiguous_in_window:\n"
-" movq 56(%%rsp), %%rsi\n" /* rsi = window */
-" addq %%rax, %%rsi\n"
-" subq %%rcx, %%rsi\n" /* from += write - nbytes */
-
-" movl %%r14d, %%eax\n" /* eax = len */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movq %%rdi, %%rsi\n"
-" subq %%r15, %%rsi\n" /* from = out - dist */
-" jmp .L_do_copy\n" /* if (nbytes >= len) */
-
-".align 32,0x90\n"
-".L_do_copy:\n"
-" movl %%eax, %%ecx\n" /* ecx = len */
-" rep movsb\n"
-
-" movq %%r8, %%rsi\n" /* move in back to %esi, toss from */
-" jmp .L_while_test\n"
-
-".L_test_for_end_of_block:\n"
-" testb $32, %%al\n"
-" jz .L_invalid_literal_length_code\n"
-" movl $1, 116(%%rsp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_invalid_literal_length_code:\n"
-" movl $2, 116(%%rsp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_invalid_distance_code:\n"
-" movl $3, 116(%%rsp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_invalid_distance_too_far:\n"
-" movl $4, 116(%%rsp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_break_loop:\n"
-" movl $0, 116(%%rsp)\n"
-
-".L_break_loop_with_status:\n"
-/* put in, out, bits, and hold back into ar and pop esp */
-" movq %%rsi, 16(%%rsp)\n" /* in */
-" movq %%rdi, 32(%%rsp)\n" /* out */
-" movl %%ebx, 88(%%rsp)\n" /* bits */
-" movq %%rdx, 80(%%rsp)\n" /* hold */
-" movq (%%rsp), %%rax\n" /* restore rbp and rsp */
-" movq 8(%%rsp), %%rbp\n"
-" movq %%rax, %%rsp\n"
- :
- : "m" (ar)
- : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi",
- "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
- );
-#elif ( defined( __GNUC__ ) || defined( __ICC ) ) && defined( __i386 )
- __asm__ __volatile__ (
-" leal %0, %%eax\n"
-" movl %%esp, (%%eax)\n" /* save esp, ebp */
-" movl %%ebp, 4(%%eax)\n"
-" movl %%eax, %%esp\n"
-" movl 8(%%esp), %%esi\n" /* esi = in */
-" movl 16(%%esp), %%edi\n" /* edi = out */
-" movl 40(%%esp), %%edx\n" /* edx = hold */
-" movl 44(%%esp), %%ebx\n" /* ebx = bits */
-" movl 32(%%esp), %%ebp\n" /* ebp = lcode */
-
-" cld\n"
-" jmp .L_do_loop\n"
-
-".align 32,0x90\n"
-".L_while_test:\n"
-" cmpl %%edi, 24(%%esp)\n" /* out < end */
-" jbe .L_break_loop\n"
-" cmpl %%esi, 12(%%esp)\n" /* in < last */
-" jbe .L_break_loop\n"
-
-".L_do_loop:\n"
-" cmpb $15, %%bl\n"
-" ja .L_get_length_code\n" /* if (15 < bits) */
-
-" xorl %%eax, %%eax\n"
-" lodsw\n" /* al = *(ushort *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $16, %%bl\n" /* bits += 16 */
-" shll %%cl, %%eax\n"
-" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
-
-".L_get_length_code:\n"
-" movl 56(%%esp), %%eax\n" /* eax = lmask */
-" andl %%edx, %%eax\n" /* eax &= hold */
-" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */
-
-".L_dolen:\n"
-" movb %%ah, %%cl\n" /* cl = this.bits */
-" subb %%ah, %%bl\n" /* bits -= this.bits */
-" shrl %%cl, %%edx\n" /* hold >>= this.bits */
-
-" testb %%al, %%al\n"
-" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */
-
-" shrl $16, %%eax\n" /* output this.val char */
-" stosb\n"
-" jmp .L_while_test\n"
-
-".align 32,0x90\n"
-".L_test_for_length_base:\n"
-" movl %%eax, %%ecx\n" /* len = this */
-" shrl $16, %%ecx\n" /* len = this.val */
-" movl %%ecx, 64(%%esp)\n" /* save len */
-" movb %%al, %%cl\n"
-
-" testb $16, %%al\n"
-" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */
-" andb $15, %%cl\n" /* op &= 15 */
-" jz .L_decode_distance\n" /* if (!op) */
-" cmpb %%cl, %%bl\n"
-" jae .L_add_bits_to_len\n" /* if (op <= bits) */
-
-" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */
-" xorl %%eax, %%eax\n"
-" lodsw\n" /* al = *(ushort *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $16, %%bl\n" /* bits += 16 */
-" shll %%cl, %%eax\n"
-" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
-" movb %%ch, %%cl\n" /* move op back to ecx */
-
-".L_add_bits_to_len:\n"
-" subb %%cl, %%bl\n"
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n"
-" andl %%edx, %%eax\n" /* eax &= hold */
-" shrl %%cl, %%edx\n"
-" addl %%eax, 64(%%esp)\n" /* len += hold & mask[op] */
-
-".L_decode_distance:\n"
-" cmpb $15, %%bl\n"
-" ja .L_get_distance_code\n" /* if (15 < bits) */
-
-" xorl %%eax, %%eax\n"
-" lodsw\n" /* al = *(ushort *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $16, %%bl\n" /* bits += 16 */
-" shll %%cl, %%eax\n"
-" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
-
-".L_get_distance_code:\n"
-" movl 60(%%esp), %%eax\n" /* eax = dmask */
-" movl 36(%%esp), %%ecx\n" /* ecx = dcode */
-" andl %%edx, %%eax\n" /* eax &= hold */
-" movl (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */
-
-".L_dodist:\n"
-" movl %%eax, %%ebp\n" /* dist = this */
-" shrl $16, %%ebp\n" /* dist = this.val */
-" movb %%ah, %%cl\n"
-" subb %%ah, %%bl\n" /* bits -= this.bits */
-" shrl %%cl, %%edx\n" /* hold >>= this.bits */
-" movb %%al, %%cl\n" /* cl = this.op */
-
-" testb $16, %%al\n" /* if ((op & 16) == 0) */
-" jz .L_test_for_second_level_dist\n"
-" andb $15, %%cl\n" /* op &= 15 */
-" jz .L_check_dist_one\n"
-" cmpb %%cl, %%bl\n"
-" jae .L_add_bits_to_dist\n" /* if (op <= bits) 97.6% */
-
-" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */
-" xorl %%eax, %%eax\n"
-" lodsw\n" /* al = *(ushort *)in++ */
-" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
-" addb $16, %%bl\n" /* bits += 16 */
-" shll %%cl, %%eax\n"
-" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
-" movb %%ch, %%cl\n" /* move op back to ecx */
-
-".L_add_bits_to_dist:\n"
-" subb %%cl, %%bl\n"
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n" /* (1 << op) - 1 */
-" andl %%edx, %%eax\n" /* eax &= hold */
-" shrl %%cl, %%edx\n"
-" addl %%eax, %%ebp\n" /* dist += hold & ((1 << op) - 1) */
-
-".L_check_window:\n"
-" movl %%esi, 8(%%esp)\n" /* save in so from can use it's reg */
-" movl %%edi, %%eax\n"
-" subl 20(%%esp), %%eax\n" /* nbytes = out - beg */
-
-" cmpl %%ebp, %%eax\n"
-" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */
-
-" movl 64(%%esp), %%ecx\n" /* ecx = len */
-" movl %%edi, %%esi\n"
-" subl %%ebp, %%esi\n" /* from = out - dist */
-
-" sarl %%ecx\n"
-" jnc .L_copy_two\n" /* if len % 2 == 0 */
-
-" rep movsw\n"
-" movb (%%esi), %%al\n"
-" movb %%al, (%%edi)\n"
-" incl %%edi\n"
-
-" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */
-" movl 32(%%esp), %%ebp\n" /* ebp = lcode */
-" jmp .L_while_test\n"
-
-".L_copy_two:\n"
-" rep movsw\n"
-" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */
-" movl 32(%%esp), %%ebp\n" /* ebp = lcode */
-" jmp .L_while_test\n"
-
-".align 32,0x90\n"
-".L_check_dist_one:\n"
-" cmpl $1, %%ebp\n" /* if dist 1, is a memset */
-" jne .L_check_window\n"
-" cmpl %%edi, 20(%%esp)\n"
-" je .L_check_window\n" /* out == beg, if outside window */
-
-" movl 64(%%esp), %%ecx\n" /* ecx = len */
-" movb -1(%%edi), %%al\n"
-" movb %%al, %%ah\n"
-
-" sarl %%ecx\n"
-" jnc .L_set_two\n"
-" movb %%al, (%%edi)\n"
-" incl %%edi\n"
-
-".L_set_two:\n"
-" rep stosw\n"
-" movl 32(%%esp), %%ebp\n" /* ebp = lcode */
-" jmp .L_while_test\n"
-
-".align 32,0x90\n"
-".L_test_for_second_level_length:\n"
-" testb $64, %%al\n"
-" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */
-
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n"
-" andl %%edx, %%eax\n" /* eax &= hold */
-" addl 64(%%esp), %%eax\n" /* eax += len */
-" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/
-" jmp .L_dolen\n"
-
-".align 32,0x90\n"
-".L_test_for_second_level_dist:\n"
-" testb $64, %%al\n"
-" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */
-
-" xorl %%eax, %%eax\n"
-" incl %%eax\n"
-" shll %%cl, %%eax\n"
-" decl %%eax\n"
-" andl %%edx, %%eax\n" /* eax &= hold */
-" addl %%ebp, %%eax\n" /* eax += dist */
-" movl 36(%%esp), %%ecx\n" /* ecx = dcode */
-" movl (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/
-" jmp .L_dodist\n"
-
-".align 32,0x90\n"
-".L_clip_window:\n"
-" movl %%eax, %%ecx\n"
-" movl 48(%%esp), %%eax\n" /* eax = wsize */
-" negl %%ecx\n" /* nbytes = -nbytes */
-" movl 28(%%esp), %%esi\n" /* from = window */
-
-" cmpl %%ebp, %%eax\n"
-" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */
-
-" addl %%ebp, %%ecx\n" /* nbytes = dist - nbytes */
-" cmpl $0, 52(%%esp)\n"
-" jne .L_wrap_around_window\n" /* if (write != 0) */
-
-" subl %%ecx, %%eax\n"
-" addl %%eax, %%esi\n" /* from += wsize - nbytes */
-
-" movl 64(%%esp), %%eax\n" /* eax = len */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movl %%edi, %%esi\n"
-" subl %%ebp, %%esi\n" /* from = out - dist */
-" jmp .L_do_copy\n"
-
-".align 32,0x90\n"
-".L_wrap_around_window:\n"
-" movl 52(%%esp), %%eax\n" /* eax = write */
-" cmpl %%eax, %%ecx\n"
-" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */
-
-" addl 48(%%esp), %%esi\n" /* from += wsize */
-" addl %%eax, %%esi\n" /* from += write */
-" subl %%ecx, %%esi\n" /* from -= nbytes */
-" subl %%eax, %%ecx\n" /* nbytes -= write */
-
-" movl 64(%%esp), %%eax\n" /* eax = len */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movl 28(%%esp), %%esi\n" /* from = window */
-" movl 52(%%esp), %%ecx\n" /* nbytes = write */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movl %%edi, %%esi\n"
-" subl %%ebp, %%esi\n" /* from = out - dist */
-" jmp .L_do_copy\n"
-
-".align 32,0x90\n"
-".L_contiguous_in_window:\n"
-" addl %%eax, %%esi\n"
-" subl %%ecx, %%esi\n" /* from += write - nbytes */
-
-" movl 64(%%esp), %%eax\n" /* eax = len */
-" cmpl %%ecx, %%eax\n"
-" jbe .L_do_copy\n" /* if (nbytes >= len) */
-
-" subl %%ecx, %%eax\n" /* len -= nbytes */
-" rep movsb\n"
-" movl %%edi, %%esi\n"
-" subl %%ebp, %%esi\n" /* from = out - dist */
-" jmp .L_do_copy\n" /* if (nbytes >= len) */
-
-".align 32,0x90\n"
-".L_do_copy:\n"
-" movl %%eax, %%ecx\n"
-" rep movsb\n"
-
-" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */
-" movl 32(%%esp), %%ebp\n" /* ebp = lcode */
-" jmp .L_while_test\n"
-
-".L_test_for_end_of_block:\n"
-" testb $32, %%al\n"
-" jz .L_invalid_literal_length_code\n"
-" movl $1, 72(%%esp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_invalid_literal_length_code:\n"
-" movl $2, 72(%%esp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_invalid_distance_code:\n"
-" movl $3, 72(%%esp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_invalid_distance_too_far:\n"
-" movl 8(%%esp), %%esi\n"
-" movl $4, 72(%%esp)\n"
-" jmp .L_break_loop_with_status\n"
-
-".L_break_loop:\n"
-" movl $0, 72(%%esp)\n"
-
-".L_break_loop_with_status:\n"
-/* put in, out, bits, and hold back into ar and pop esp */
-" movl %%esi, 8(%%esp)\n" /* save in */
-" movl %%edi, 16(%%esp)\n" /* save out */
-" movl %%ebx, 44(%%esp)\n" /* save bits */
-" movl %%edx, 40(%%esp)\n" /* save hold */
-" movl 4(%%esp), %%ebp\n" /* restore esp, ebp */
-" movl (%%esp), %%esp\n"
- :
- : "m" (ar)
- : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
- );
-#elif defined( _MSC_VER ) && ! defined( _M_AMD64 )
- __asm {
- lea eax, ar
- mov [eax], esp /* save esp, ebp */
- mov [eax+4], ebp
- mov esp, eax
- mov esi, [esp+8] /* esi = in */
- mov edi, [esp+16] /* edi = out */
- mov edx, [esp+40] /* edx = hold */
- mov ebx, [esp+44] /* ebx = bits */
- mov ebp, [esp+32] /* ebp = lcode */
-
- cld
- jmp L_do_loop
-
-ALIGN 4
-L_while_test:
- cmp [esp+24], edi
- jbe L_break_loop
- cmp [esp+12], esi
- jbe L_break_loop
-
-L_do_loop:
- cmp bl, 15
- ja L_get_length_code /* if (15 < bits) */
-
- xor eax, eax
- lodsw /* al = *(ushort *)in++ */
- mov cl, bl /* cl = bits, needs it for shifting */
- add bl, 16 /* bits += 16 */
- shl eax, cl
- or edx, eax /* hold |= *((ushort *)in)++ << bits */
-
-L_get_length_code:
- mov eax, [esp+56] /* eax = lmask */
- and eax, edx /* eax &= hold */
- mov eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */
-
-L_dolen:
- mov cl, ah /* cl = this.bits */
- sub bl, ah /* bits -= this.bits */
- shr edx, cl /* hold >>= this.bits */
-
- test al, al
- jnz L_test_for_length_base /* if (op != 0) 45.7% */
-
- shr eax, 16 /* output this.val char */
- stosb
- jmp L_while_test
-
-ALIGN 4
-L_test_for_length_base:
- mov ecx, eax /* len = this */
- shr ecx, 16 /* len = this.val */
- mov [esp+64], ecx /* save len */
- mov cl, al
-
- test al, 16
- jz L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
- and cl, 15 /* op &= 15 */
- jz L_decode_distance /* if (!op) */
- cmp bl, cl
- jae L_add_bits_to_len /* if (op <= bits) */
-
- mov ch, cl /* stash op in ch, freeing cl */
- xor eax, eax
- lodsw /* al = *(ushort *)in++ */
- mov cl, bl /* cl = bits, needs it for shifting */
- add bl, 16 /* bits += 16 */
- shl eax, cl
- or edx, eax /* hold |= *((ushort *)in)++ << bits */
- mov cl, ch /* move op back to ecx */
-
-L_add_bits_to_len:
- sub bl, cl
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax
- and eax, edx /* eax &= hold */
- shr edx, cl
- add [esp+64], eax /* len += hold & mask[op] */
-
-L_decode_distance:
- cmp bl, 15
- ja L_get_distance_code /* if (15 < bits) */
-
- xor eax, eax
- lodsw /* al = *(ushort *)in++ */
- mov cl, bl /* cl = bits, needs it for shifting */
- add bl, 16 /* bits += 16 */
- shl eax, cl
- or edx, eax /* hold |= *((ushort *)in)++ << bits */
-
-L_get_distance_code:
- mov eax, [esp+60] /* eax = dmask */
- mov ecx, [esp+36] /* ecx = dcode */
- and eax, edx /* eax &= hold */
- mov eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */
-
-L_dodist:
- mov ebp, eax /* dist = this */
- shr ebp, 16 /* dist = this.val */
- mov cl, ah
- sub bl, ah /* bits -= this.bits */
- shr edx, cl /* hold >>= this.bits */
- mov cl, al /* cl = this.op */
-
- test al, 16 /* if ((op & 16) == 0) */
- jz L_test_for_second_level_dist
- and cl, 15 /* op &= 15 */
- jz L_check_dist_one
- cmp bl, cl
- jae L_add_bits_to_dist /* if (op <= bits) 97.6% */
-
- mov ch, cl /* stash op in ch, freeing cl */
- xor eax, eax
- lodsw /* al = *(ushort *)in++ */
- mov cl, bl /* cl = bits, needs it for shifting */
- add bl, 16 /* bits += 16 */
- shl eax, cl
- or edx, eax /* hold |= *((ushort *)in)++ << bits */
- mov cl, ch /* move op back to ecx */
-
-L_add_bits_to_dist:
- sub bl, cl
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax /* (1 << op) - 1 */
- and eax, edx /* eax &= hold */
- shr edx, cl
- add ebp, eax /* dist += hold & ((1 << op) - 1) */
-
-L_check_window:
- mov [esp+8], esi /* save in so from can use it's reg */
- mov eax, edi
- sub eax, [esp+20] /* nbytes = out - beg */
-
- cmp eax, ebp
- jb L_clip_window /* if (dist > nbytes) 4.2% */
-
- mov ecx, [esp+64] /* ecx = len */
- mov esi, edi
- sub esi, ebp /* from = out - dist */
-
- sar ecx, 1
- jnc L_copy_two
-
- rep movsw
- mov al, [esi]
- mov [edi], al
- inc edi
-
- mov esi, [esp+8] /* move in back to %esi, toss from */
- mov ebp, [esp+32] /* ebp = lcode */
- jmp L_while_test
-
-L_copy_two:
- rep movsw
- mov esi, [esp+8] /* move in back to %esi, toss from */
- mov ebp, [esp+32] /* ebp = lcode */
- jmp L_while_test
-
-ALIGN 4
-L_check_dist_one:
- cmp ebp, 1 /* if dist 1, is a memset */
- jne L_check_window
- cmp [esp+20], edi
- je L_check_window /* out == beg, if outside window */
-
- mov ecx, [esp+64] /* ecx = len */
- mov al, [edi-1]
- mov ah, al
-
- sar ecx, 1
- jnc L_set_two
- mov [edi], al /* memset out with from[-1] */
- inc edi
-
-L_set_two:
- rep stosw
- mov ebp, [esp+32] /* ebp = lcode */
- jmp L_while_test
-
-ALIGN 4
-L_test_for_second_level_length:
- test al, 64
- jnz L_test_for_end_of_block /* if ((op & 64) != 0) */
-
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax
- and eax, edx /* eax &= hold */
- add eax, [esp+64] /* eax += len */
- mov eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/
- jmp L_dolen
-
-ALIGN 4
-L_test_for_second_level_dist:
- test al, 64
- jnz L_invalid_distance_code /* if ((op & 64) != 0) */
-
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax
- and eax, edx /* eax &= hold */
- add eax, ebp /* eax += dist */
- mov ecx, [esp+36] /* ecx = dcode */
- mov eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/
- jmp L_dodist
-
-ALIGN 4
-L_clip_window:
- mov ecx, eax
- mov eax, [esp+48] /* eax = wsize */
- neg ecx /* nbytes = -nbytes */
- mov esi, [esp+28] /* from = window */
-
- cmp eax, ebp
- jb L_invalid_distance_too_far /* if (dist > wsize) */
-
- add ecx, ebp /* nbytes = dist - nbytes */
- cmp dword ptr [esp+52], 0
- jne L_wrap_around_window /* if (write != 0) */
-
- sub eax, ecx
- add esi, eax /* from += wsize - nbytes */
-
- mov eax, [esp+64] /* eax = len */
- cmp eax, ecx
- jbe L_do_copy /* if (nbytes >= len) */
-
- sub eax, ecx /* len -= nbytes */
- rep movsb
- mov esi, edi
- sub esi, ebp /* from = out - dist */
- jmp L_do_copy
-
-ALIGN 4
-L_wrap_around_window:
- mov eax, [esp+52] /* eax = write */
- cmp ecx, eax
- jbe L_contiguous_in_window /* if (write >= nbytes) */
-
- add esi, [esp+48] /* from += wsize */
- add esi, eax /* from += write */
- sub esi, ecx /* from -= nbytes */
- sub ecx, eax /* nbytes -= write */
-
- mov eax, [esp+64] /* eax = len */
- cmp eax, ecx
- jbe L_do_copy /* if (nbytes >= len) */
-
- sub eax, ecx /* len -= nbytes */
- rep movsb
- mov esi, [esp+28] /* from = window */
- mov ecx, [esp+52] /* nbytes = write */
- cmp eax, ecx
- jbe L_do_copy /* if (nbytes >= len) */
-
- sub eax, ecx /* len -= nbytes */
- rep movsb
- mov esi, edi
- sub esi, ebp /* from = out - dist */
- jmp L_do_copy
-
-ALIGN 4
-L_contiguous_in_window:
- add esi, eax
- sub esi, ecx /* from += write - nbytes */
-
- mov eax, [esp+64] /* eax = len */
- cmp eax, ecx
- jbe L_do_copy /* if (nbytes >= len) */
-
- sub eax, ecx /* len -= nbytes */
- rep movsb
- mov esi, edi
- sub esi, ebp /* from = out - dist */
- jmp L_do_copy
-
-ALIGN 4
-L_do_copy:
- mov ecx, eax
- rep movsb
-
- mov esi, [esp+8] /* move in back to %esi, toss from */
- mov ebp, [esp+32] /* ebp = lcode */
- jmp L_while_test
-
-L_test_for_end_of_block:
- test al, 32
- jz L_invalid_literal_length_code
- mov dword ptr [esp+72], 1
- jmp L_break_loop_with_status
-
-L_invalid_literal_length_code:
- mov dword ptr [esp+72], 2
- jmp L_break_loop_with_status
-
-L_invalid_distance_code:
- mov dword ptr [esp+72], 3
- jmp L_break_loop_with_status
-
-L_invalid_distance_too_far:
- mov esi, [esp+4]
- mov dword ptr [esp+72], 4
- jmp L_break_loop_with_status
-
-L_break_loop:
- mov dword ptr [esp+72], 0
-
-L_break_loop_with_status:
-/* put in, out, bits, and hold back into ar and pop esp */
- mov [esp+8], esi /* save in */
- mov [esp+16], edi /* save out */
- mov [esp+44], ebx /* save bits */
- mov [esp+40], edx /* save hold */
- mov ebp, [esp+4] /* restore esp, ebp */
- mov esp, [esp]
- }
-#else
-#error "x86 architecture not defined"
-#endif
-
- if (ar.status > 1) {
- if (ar.status == 2)
- strm->msg = "invalid literal/length code";
- else if (ar.status == 3)
- strm->msg = "invalid distance code";
- else
- strm->msg = "invalid distance too far back";
- state->mode = BAD;
- }
- else if ( ar.status == 1 ) {
- state->mode = TYPE;
- }
-
- /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
- ar.len = ar.bits >> 3;
- ar.in -= ar.len;
- ar.bits -= ar.len << 3;
- ar.hold &= (1U << ar.bits) - 1;
-
- /* update state and return */
- strm->next_in = ar.in;
- strm->next_out = ar.out;
- strm->avail_in = (unsigned)(ar.in < ar.last ?
- PAD_AVAIL_IN + (ar.last - ar.in) :
- PAD_AVAIL_IN - (ar.in - ar.last));
- strm->avail_out = (unsigned)(ar.out < ar.end ?
- PAD_AVAIL_OUT + (ar.end - ar.out) :
- PAD_AVAIL_OUT - (ar.out - ar.end));
- state->hold = ar.hold;
- state->bits = ar.bits;
- return;
-}
-
diff --git a/cpukit/zlib/contrib/inflate86/inffast.S b/cpukit/zlib/contrib/inflate86/inffast.S
deleted file mode 100644
index 2245a2905b..0000000000
--- a/cpukit/zlib/contrib/inflate86/inffast.S
+++ /dev/null
@@ -1,1368 +0,0 @@
-/*
- * inffast.S is a hand tuned assembler version of:
- *
- * inffast.c -- fast decoding
- * Copyright (C) 1995-2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- *
- * Copyright (C) 2003 Chris Anderson <christop@charm.net>
- * Please use the copyright conditions above.
- *
- * This version (Jan-23-2003) of inflate_fast was coded and tested under
- * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that
- * machine, I found that gzip style archives decompressed about 20% faster than
- * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will
- * depend on how large of a buffer is used for z_stream.next_in & next_out
- * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in
- * stream processing I/O and crc32/addler32. In my case, this routine used
- * 70% of the cpu time and crc32 used 20%.
- *
- * I am confident that this version will work in the general case, but I have
- * not tested a wide variety of datasets or a wide variety of platforms.
- *
- * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating.
- * It should be a runtime flag instead of compile time flag...
- *
- * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction.
- * With -DUSE_MMX, only MMX code is compiled. With -DNO_MMX, only non-MMX code
- * is compiled. Without either option, runtime detection is enabled. Runtime
- * detection should work on all modern cpus and the recomended algorithm (flip
- * ID bit on eflags and then use the cpuid instruction) is used in many
- * multimedia applications. Tested under win2k with gcc-2.95 and gas-2.12
- * distributed with cygwin3. Compiling with gcc-2.95 -c inffast.S -o
- * inffast.obj generates a COFF object which can then be linked with MSVC++
- * compiled code. Tested under FreeBSD 4.7 with gcc-2.95.
- *
- * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and
- * slower than compiler generated code). Adjusted cpuid check to use the MMX
- * code only for Pentiums < P4 until I have more data on the P4. Speed
- * improvment is only about 15% on the Athlon when compared with code generated
- * with MSVC++. Not sure yet, but I think the P4 will also be slower using the
- * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and
- * have less latency than MMX ops. Added code to buffer the last 11 bytes of
- * the input stream since the MMX code grabs bits in chunks of 32, which
- * differs from the inffast.c algorithm. I don't think there would have been
- * read overruns where a page boundary was crossed (a segfault), but there
- * could have been overruns when next_in ends on unaligned memory (unintialized
- * memory read).
- *
- * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX. I created a C
- * version of the non-MMX code so that it doesn't depend on zstrm and zstate
- * structure offsets which are hard coded in this file. This was last tested
- * with zlib-1.2.0 which is currently in beta testing, newer versions of this
- * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and
- * http://www.charm.net/~christop/zlib/
- */
-
-
-/*
- * if you have underscore linking problems (_inflate_fast undefined), try
- * using -DGAS_COFF
- */
-#if ! defined( GAS_COFF ) && ! defined( GAS_ELF )
-
-#if defined( WIN32 ) || defined( __CYGWIN__ )
-#define GAS_COFF /* windows object format */
-#else
-#define GAS_ELF
-#endif
-
-#endif /* ! GAS_COFF && ! GAS_ELF */
-
-
-#if defined( GAS_COFF )
-
-/* coff externals have underscores */
-#define inflate_fast _inflate_fast
-#define inflate_fast_use_mmx _inflate_fast_use_mmx
-
-#endif /* GAS_COFF */
-
-
-.file "inffast.S"
-
-.globl inflate_fast
-
-.text
-.align 4,0
-.L_invalid_literal_length_code_msg:
-.string "invalid literal/length code"
-
-.align 4,0
-.L_invalid_distance_code_msg:
-.string "invalid distance code"
-
-.align 4,0
-.L_invalid_distance_too_far_msg:
-.string "invalid distance too far back"
-
-#if ! defined( NO_MMX )
-.align 4,0
-.L_mask: /* mask[N] = ( 1 << N ) - 1 */
-.long 0
-.long 1
-.long 3
-.long 7
-.long 15
-.long 31
-.long 63
-.long 127
-.long 255
-.long 511
-.long 1023
-.long 2047
-.long 4095
-.long 8191
-.long 16383
-.long 32767
-.long 65535
-.long 131071
-.long 262143
-.long 524287
-.long 1048575
-.long 2097151
-.long 4194303
-.long 8388607
-.long 16777215
-.long 33554431
-.long 67108863
-.long 134217727
-.long 268435455
-.long 536870911
-.long 1073741823
-.long 2147483647
-.long 4294967295
-#endif /* NO_MMX */
-
-.text
-
-/*
- * struct z_stream offsets, in zlib.h
- */
-#define next_in_strm 0 /* strm->next_in */
-#define avail_in_strm 4 /* strm->avail_in */
-#define next_out_strm 12 /* strm->next_out */
-#define avail_out_strm 16 /* strm->avail_out */
-#define msg_strm 24 /* strm->msg */
-#define state_strm 28 /* strm->state */
-
-/*
- * struct inflate_state offsets, in inflate.h
- */
-#define mode_state 0 /* state->mode */
-#define wsize_state 32 /* state->wsize */
-#define write_state 40 /* state->write */
-#define window_state 44 /* state->window */
-#define hold_state 48 /* state->hold */
-#define bits_state 52 /* state->bits */
-#define lencode_state 68 /* state->lencode */
-#define distcode_state 72 /* state->distcode */
-#define lenbits_state 76 /* state->lenbits */
-#define distbits_state 80 /* state->distbits */
-
-/*
- * inflate_fast's activation record
- */
-#define local_var_size 64 /* how much local space for vars */
-#define strm_sp 88 /* first arg: z_stream * (local_var_size + 24) */
-#define start_sp 92 /* second arg: unsigned int (local_var_size + 28) */
-
-/*
- * offsets for local vars on stack
- */
-#define out 60 /* unsigned char* */
-#define window 56 /* unsigned char* */
-#define wsize 52 /* unsigned int */
-#define write 48 /* unsigned int */
-#define in 44 /* unsigned char* */
-#define beg 40 /* unsigned char* */
-#define buf 28 /* char[ 12 ] */
-#define len 24 /* unsigned int */
-#define last 20 /* unsigned char* */
-#define end 16 /* unsigned char* */
-#define dcode 12 /* code* */
-#define lcode 8 /* code* */
-#define dmask 4 /* unsigned int */
-#define lmask 0 /* unsigned int */
-
-/*
- * typedef enum inflate_mode consts, in inflate.h
- */
-#define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */
-#define INFLATE_MODE_BAD 26
-
-
-#if ! defined( USE_MMX ) && ! defined( NO_MMX )
-
-#define RUN_TIME_MMX
-
-#define CHECK_MMX 1
-#define DO_USE_MMX 2
-#define DONT_USE_MMX 3
-
-.globl inflate_fast_use_mmx
-
-.data
-
-.align 4,0
-inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */
-.long CHECK_MMX
-
-#if defined( GAS_ELF )
-/* elf info */
-.type inflate_fast_use_mmx,@object
-.size inflate_fast_use_mmx,4
-#endif
-
-#endif /* RUN_TIME_MMX */
-
-#if defined( GAS_COFF )
-/* coff info: scl 2 = extern, type 32 = function */
-.def inflate_fast; .scl 2; .type 32; .endef
-#endif
-
-.text
-
-.align 32,0x90
-inflate_fast:
- pushl %edi
- pushl %esi
- pushl %ebp
- pushl %ebx
- pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */
- subl $local_var_size, %esp
- cld
-
-#define strm_r %esi
-#define state_r %edi
-
- movl strm_sp(%esp), strm_r
- movl state_strm(strm_r), state_r
-
- /* in = strm->next_in;
- * out = strm->next_out;
- * last = in + strm->avail_in - 11;
- * beg = out - (start - strm->avail_out);
- * end = out + (strm->avail_out - 257);
- */
- movl avail_in_strm(strm_r), %edx
- movl next_in_strm(strm_r), %eax
-
- addl %eax, %edx /* avail_in += next_in */
- subl $11, %edx /* avail_in -= 11 */
-
- movl %eax, in(%esp)
- movl %edx, last(%esp)
-
- movl start_sp(%esp), %ebp
- movl avail_out_strm(strm_r), %ecx
- movl next_out_strm(strm_r), %ebx
-
- subl %ecx, %ebp /* start -= avail_out */
- negl %ebp /* start = -start */
- addl %ebx, %ebp /* start += next_out */
-
- subl $257, %ecx /* avail_out -= 257 */
- addl %ebx, %ecx /* avail_out += out */
-
- movl %ebx, out(%esp)
- movl %ebp, beg(%esp)
- movl %ecx, end(%esp)
-
- /* wsize = state->wsize;
- * write = state->write;
- * window = state->window;
- * hold = state->hold;
- * bits = state->bits;
- * lcode = state->lencode;
- * dcode = state->distcode;
- * lmask = ( 1 << state->lenbits ) - 1;
- * dmask = ( 1 << state->distbits ) - 1;
- */
-
- movl lencode_state(state_r), %eax
- movl distcode_state(state_r), %ecx
-
- movl %eax, lcode(%esp)
- movl %ecx, dcode(%esp)
-
- movl $1, %eax
- movl lenbits_state(state_r), %ecx
- shll %cl, %eax
- decl %eax
- movl %eax, lmask(%esp)
-
- movl $1, %eax
- movl distbits_state(state_r), %ecx
- shll %cl, %eax
- decl %eax
- movl %eax, dmask(%esp)
-
- movl wsize_state(state_r), %eax
- movl write_state(state_r), %ecx
- movl window_state(state_r), %edx
-
- movl %eax, wsize(%esp)
- movl %ecx, write(%esp)
- movl %edx, window(%esp)
-
- movl hold_state(state_r), %ebp
- movl bits_state(state_r), %ebx
-
-#undef strm_r
-#undef state_r
-
-#define in_r %esi
-#define from_r %esi
-#define out_r %edi
-
- movl in(%esp), in_r
- movl last(%esp), %ecx
- cmpl in_r, %ecx
- ja .L_align_long /* if in < last */
-
- addl $11, %ecx /* ecx = &in[ avail_in ] */
- subl in_r, %ecx /* ecx = avail_in */
- movl $12, %eax
- subl %ecx, %eax /* eax = 12 - avail_in */
- leal buf(%esp), %edi
- rep movsb /* memcpy( buf, in, avail_in ) */
- movl %eax, %ecx
- xorl %eax, %eax
- rep stosb /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */
- leal buf(%esp), in_r /* in = buf */
- movl in_r, last(%esp) /* last = in, do just one iteration */
- jmp .L_is_aligned
-
- /* align in_r on long boundary */
-.L_align_long:
- testl $3, in_r
- jz .L_is_aligned
- xorl %eax, %eax
- movb (in_r), %al
- incl in_r
- movl %ebx, %ecx
- addl $8, %ebx
- shll %cl, %eax
- orl %eax, %ebp
- jmp .L_align_long
-
-.L_is_aligned:
- movl out(%esp), out_r
-
-#if defined( NO_MMX )
- jmp .L_do_loop
-#endif
-
-#if defined( USE_MMX )
- jmp .L_init_mmx
-#endif
-
-/*** Runtime MMX check ***/
-
-#if defined( RUN_TIME_MMX )
-.L_check_mmx:
- cmpl $DO_USE_MMX, inflate_fast_use_mmx
- je .L_init_mmx
- ja .L_do_loop /* > 2 */
-
- pushl %eax
- pushl %ebx
- pushl %ecx
- pushl %edx
- pushf
- movl (%esp), %eax /* copy eflags to eax */
- xorl $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21)
- * to see if cpu supports cpuid...
- * ID bit method not supported by NexGen but
- * bios may load a cpuid instruction and
- * cpuid may be disabled on Cyrix 5-6x86 */
- popf
- pushf
- popl %edx /* copy new eflags to edx */
- xorl %eax, %edx /* test if ID bit is flipped */
- jz .L_dont_use_mmx /* not flipped if zero */
- xorl %eax, %eax
- cpuid
- cmpl $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */
- jne .L_dont_use_mmx
- cmpl $0x6c65746e, %ecx
- jne .L_dont_use_mmx
- cmpl $0x49656e69, %edx
- jne .L_dont_use_mmx
- movl $1, %eax
- cpuid /* get cpu features */
- shrl $8, %eax
- andl $15, %eax
- cmpl $6, %eax /* check for Pentium family, is 0xf for P4 */
- jne .L_dont_use_mmx
- testl $0x800000, %edx /* test if MMX feature is set (bit 23) */
- jnz .L_use_mmx
- jmp .L_dont_use_mmx
-.L_use_mmx:
- movl $DO_USE_MMX, inflate_fast_use_mmx
- jmp .L_check_mmx_pop
-.L_dont_use_mmx:
- movl $DONT_USE_MMX, inflate_fast_use_mmx
-.L_check_mmx_pop:
- popl %edx
- popl %ecx
- popl %ebx
- popl %eax
- jmp .L_check_mmx
-#endif
-
-
-/*** Non-MMX code ***/
-
-#if defined ( NO_MMX ) || defined( RUN_TIME_MMX )
-
-#define hold_r %ebp
-#define bits_r %bl
-#define bitslong_r %ebx
-
-.align 32,0x90
-.L_while_test:
- /* while (in < last && out < end)
- */
- cmpl out_r, end(%esp)
- jbe .L_break_loop /* if (out >= end) */
-
- cmpl in_r, last(%esp)
- jbe .L_break_loop
-
-.L_do_loop:
- /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
- *
- * do {
- * if (bits < 15) {
- * hold |= *((unsigned short *)in)++ << bits;
- * bits += 16
- * }
- * this = lcode[hold & lmask]
- */
- cmpb $15, bits_r
- ja .L_get_length_code /* if (15 < bits) */
-
- xorl %eax, %eax
- lodsw /* al = *(ushort *)in++ */
- movb bits_r, %cl /* cl = bits, needs it for shifting */
- addb $16, bits_r /* bits += 16 */
- shll %cl, %eax
- orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
-
-.L_get_length_code:
- movl lmask(%esp), %edx /* edx = lmask */
- movl lcode(%esp), %ecx /* ecx = lcode */
- andl hold_r, %edx /* edx &= hold */
- movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */
-
-.L_dolen:
- /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
- *
- * dolen:
- * bits -= this.bits;
- * hold >>= this.bits
- */
- movb %ah, %cl /* cl = this.bits */
- subb %ah, bits_r /* bits -= this.bits */
- shrl %cl, hold_r /* hold >>= this.bits */
-
- /* check if op is a literal
- * if (op == 0) {
- * PUP(out) = this.val;
- * }
- */
- testb %al, %al
- jnz .L_test_for_length_base /* if (op != 0) 45.7% */
-
- shrl $16, %eax /* output this.val char */
- stosb
- jmp .L_while_test
-
-.L_test_for_length_base:
- /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len
- *
- * else if (op & 16) {
- * len = this.val
- * op &= 15
- * if (op) {
- * if (op > bits) {
- * hold |= *((unsigned short *)in)++ << bits;
- * bits += 16
- * }
- * len += hold & mask[op];
- * bits -= op;
- * hold >>= op;
- * }
- */
-#define len_r %edx
- movl %eax, len_r /* len = this */
- shrl $16, len_r /* len = this.val */
- movb %al, %cl
-
- testb $16, %al
- jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
- andb $15, %cl /* op &= 15 */
- jz .L_save_len /* if (!op) */
- cmpb %cl, bits_r
- jae .L_add_bits_to_len /* if (op <= bits) */
-
- movb %cl, %ch /* stash op in ch, freeing cl */
- xorl %eax, %eax
- lodsw /* al = *(ushort *)in++ */
- movb bits_r, %cl /* cl = bits, needs it for shifting */
- addb $16, bits_r /* bits += 16 */
- shll %cl, %eax
- orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
- movb %ch, %cl /* move op back to ecx */
-
-.L_add_bits_to_len:
- movl $1, %eax
- shll %cl, %eax
- decl %eax
- subb %cl, bits_r
- andl hold_r, %eax /* eax &= hold */
- shrl %cl, hold_r
- addl %eax, len_r /* len += hold & mask[op] */
-
-.L_save_len:
- movl len_r, len(%esp) /* save len */
-#undef len_r
-
-.L_decode_distance:
- /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist
- *
- * if (bits < 15) {
- * hold |= *((unsigned short *)in)++ << bits;
- * bits += 16
- * }
- * this = dcode[hold & dmask];
- * dodist:
- * bits -= this.bits;
- * hold >>= this.bits;
- * op = this.op;
- */
-
- cmpb $15, bits_r
- ja .L_get_distance_code /* if (15 < bits) */
-
- xorl %eax, %eax
- lodsw /* al = *(ushort *)in++ */
- movb bits_r, %cl /* cl = bits, needs it for shifting */
- addb $16, bits_r /* bits += 16 */
- shll %cl, %eax
- orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
-
-.L_get_distance_code:
- movl dmask(%esp), %edx /* edx = dmask */
- movl dcode(%esp), %ecx /* ecx = dcode */
- andl hold_r, %edx /* edx &= hold */
- movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */
-
-#define dist_r %edx
-.L_dodist:
- movl %eax, dist_r /* dist = this */
- shrl $16, dist_r /* dist = this.val */
- movb %ah, %cl
- subb %ah, bits_r /* bits -= this.bits */
- shrl %cl, hold_r /* hold >>= this.bits */
-
- /* if (op & 16) {
- * dist = this.val
- * op &= 15
- * if (op > bits) {
- * hold |= *((unsigned short *)in)++ << bits;
- * bits += 16
- * }
- * dist += hold & mask[op];
- * bits -= op;
- * hold >>= op;
- */
- movb %al, %cl /* cl = this.op */
-
- testb $16, %al /* if ((op & 16) == 0) */
- jz .L_test_for_second_level_dist
- andb $15, %cl /* op &= 15 */
- jz .L_check_dist_one
- cmpb %cl, bits_r
- jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */
-
- movb %cl, %ch /* stash op in ch, freeing cl */
- xorl %eax, %eax
- lodsw /* al = *(ushort *)in++ */
- movb bits_r, %cl /* cl = bits, needs it for shifting */
- addb $16, bits_r /* bits += 16 */
- shll %cl, %eax
- orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
- movb %ch, %cl /* move op back to ecx */
-
-.L_add_bits_to_dist:
- movl $1, %eax
- shll %cl, %eax
- decl %eax /* (1 << op) - 1 */
- subb %cl, bits_r
- andl hold_r, %eax /* eax &= hold */
- shrl %cl, hold_r
- addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */
- jmp .L_check_window
-
-.L_check_window:
- /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
- * %ecx = nbytes
- *
- * nbytes = out - beg;
- * if (dist <= nbytes) {
- * from = out - dist;
- * do {
- * PUP(out) = PUP(from);
- * } while (--len > 0) {
- * }
- */
-
- movl in_r, in(%esp) /* save in so from can use it's reg */
- movl out_r, %eax
- subl beg(%esp), %eax /* nbytes = out - beg */
-
- cmpl dist_r, %eax
- jb .L_clip_window /* if (dist > nbytes) 4.2% */
-
- movl len(%esp), %ecx
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
-
- subl $3, %ecx
- movb (from_r), %al
- movb %al, (out_r)
- movb 1(from_r), %al
- movb 2(from_r), %dl
- addl $3, from_r
- movb %al, 1(out_r)
- movb %dl, 2(out_r)
- addl $3, out_r
- rep movsb
-
- movl in(%esp), in_r /* move in back to %esi, toss from */
- jmp .L_while_test
-
-.align 16,0x90
-.L_check_dist_one:
- cmpl $1, dist_r
- jne .L_check_window
- cmpl out_r, beg(%esp)
- je .L_check_window
-
- decl out_r
- movl len(%esp), %ecx
- movb (out_r), %al
- subl $3, %ecx
-
- movb %al, 1(out_r)
- movb %al, 2(out_r)
- movb %al, 3(out_r)
- addl $4, out_r
- rep stosb
-
- jmp .L_while_test
-
-.align 16,0x90
-.L_test_for_second_level_length:
- /* else if ((op & 64) == 0) {
- * this = lcode[this.val + (hold & mask[op])];
- * }
- */
- testb $64, %al
- jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */
-
- movl $1, %eax
- shll %cl, %eax
- decl %eax
- andl hold_r, %eax /* eax &= hold */
- addl %edx, %eax /* eax += this.val */
- movl lcode(%esp), %edx /* edx = lcode */
- movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */
- jmp .L_dolen
-
-.align 16,0x90
-.L_test_for_second_level_dist:
- /* else if ((op & 64) == 0) {
- * this = dcode[this.val + (hold & mask[op])];
- * }
- */
- testb $64, %al
- jnz .L_invalid_distance_code /* if ((op & 64) != 0) */
-
- movl $1, %eax
- shll %cl, %eax
- decl %eax
- andl hold_r, %eax /* eax &= hold */
- addl %edx, %eax /* eax += this.val */
- movl dcode(%esp), %edx /* edx = dcode */
- movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */
- jmp .L_dodist
-
-.align 16,0x90
-.L_clip_window:
- /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
- * %ecx = nbytes
- *
- * else {
- * if (dist > wsize) {
- * invalid distance
- * }
- * from = window;
- * nbytes = dist - nbytes;
- * if (write == 0) {
- * from += wsize - nbytes;
- */
-#define nbytes_r %ecx
- movl %eax, nbytes_r
- movl wsize(%esp), %eax /* prepare for dist compare */
- negl nbytes_r /* nbytes = -nbytes */
- movl window(%esp), from_r /* from = window */
-
- cmpl dist_r, %eax
- jb .L_invalid_distance_too_far /* if (dist > wsize) */
-
- addl dist_r, nbytes_r /* nbytes = dist - nbytes */
- cmpl $0, write(%esp)
- jne .L_wrap_around_window /* if (write != 0) */
-
- subl nbytes_r, %eax
- addl %eax, from_r /* from += wsize - nbytes */
-
- /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
- * %ecx = nbytes, %eax = len
- *
- * if (nbytes < len) {
- * len -= nbytes;
- * do {
- * PUP(out) = PUP(from);
- * } while (--nbytes);
- * from = out - dist;
- * }
- * }
- */
-#define len_r %eax
- movl len(%esp), len_r
- cmpl nbytes_r, len_r
- jbe .L_do_copy1 /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
- jmp .L_do_copy1
-
- cmpl nbytes_r, len_r
- jbe .L_do_copy1 /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
- jmp .L_do_copy1
-
-.L_wrap_around_window:
- /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
- * %ecx = nbytes, %eax = write, %eax = len
- *
- * else if (write < nbytes) {
- * from += wsize + write - nbytes;
- * nbytes -= write;
- * if (nbytes < len) {
- * len -= nbytes;
- * do {
- * PUP(out) = PUP(from);
- * } while (--nbytes);
- * from = window;
- * nbytes = write;
- * if (nbytes < len) {
- * len -= nbytes;
- * do {
- * PUP(out) = PUP(from);
- * } while(--nbytes);
- * from = out - dist;
- * }
- * }
- * }
- */
-#define write_r %eax
- movl write(%esp), write_r
- cmpl write_r, nbytes_r
- jbe .L_contiguous_in_window /* if (write >= nbytes) */
-
- addl wsize(%esp), from_r
- addl write_r, from_r
- subl nbytes_r, from_r /* from += wsize + write - nbytes */
- subl write_r, nbytes_r /* nbytes -= write */
-#undef write_r
-
- movl len(%esp), len_r
- cmpl nbytes_r, len_r
- jbe .L_do_copy1 /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl window(%esp), from_r /* from = window */
- movl write(%esp), nbytes_r /* nbytes = write */
- cmpl nbytes_r, len_r
- jbe .L_do_copy1 /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
- jmp .L_do_copy1
-
-.L_contiguous_in_window:
- /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
- * %ecx = nbytes, %eax = write, %eax = len
- *
- * else {
- * from += write - nbytes;
- * if (nbytes < len) {
- * len -= nbytes;
- * do {
- * PUP(out) = PUP(from);
- * } while (--nbytes);
- * from = out - dist;
- * }
- * }
- */
-#define write_r %eax
- addl write_r, from_r
- subl nbytes_r, from_r /* from += write - nbytes */
-#undef write_r
-
- movl len(%esp), len_r
- cmpl nbytes_r, len_r
- jbe .L_do_copy1 /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
-
-.L_do_copy1:
- /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out
- * %eax = len
- *
- * while (len > 0) {
- * PUP(out) = PUP(from);
- * len--;
- * }
- * }
- * } while (in < last && out < end);
- */
-#undef nbytes_r
-#define in_r %esi
- movl len_r, %ecx
- rep movsb
-
- movl in(%esp), in_r /* move in back to %esi, toss from */
- jmp .L_while_test
-
-#undef len_r
-#undef dist_r
-
-#endif /* NO_MMX || RUN_TIME_MMX */
-
-
-/*** MMX code ***/
-
-#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
-
-.align 32,0x90
-.L_init_mmx:
- emms
-
-#undef bits_r
-#undef bitslong_r
-#define bitslong_r %ebp
-#define hold_mm %mm0
- movd %ebp, hold_mm
- movl %ebx, bitslong_r
-
-#define used_mm %mm1
-#define dmask2_mm %mm2
-#define lmask2_mm %mm3
-#define lmask_mm %mm4
-#define dmask_mm %mm5
-#define tmp_mm %mm6
-
- movd lmask(%esp), lmask_mm
- movq lmask_mm, lmask2_mm
- movd dmask(%esp), dmask_mm
- movq dmask_mm, dmask2_mm
- pxor used_mm, used_mm
- movl lcode(%esp), %ebx /* ebx = lcode */
- jmp .L_do_loop_mmx
-
-.align 32,0x90
-.L_while_test_mmx:
- /* while (in < last && out < end)
- */
- cmpl out_r, end(%esp)
- jbe .L_break_loop /* if (out >= end) */
-
- cmpl in_r, last(%esp)
- jbe .L_break_loop
-
-.L_do_loop_mmx:
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
-
- cmpl $32, bitslong_r
- ja .L_get_length_code_mmx /* if (32 < bits) */
-
- movd bitslong_r, tmp_mm
- movd (in_r), %mm7
- addl $4, in_r
- psllq tmp_mm, %mm7
- addl $32, bitslong_r
- por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */
-
-.L_get_length_code_mmx:
- pand hold_mm, lmask_mm
- movd lmask_mm, %eax
- movq lmask2_mm, lmask_mm
- movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */
-
-.L_dolen_mmx:
- movzbl %ah, %ecx /* ecx = this.bits */
- movd %ecx, used_mm
- subl %ecx, bitslong_r /* bits -= this.bits */
-
- testb %al, %al
- jnz .L_test_for_length_base_mmx /* if (op != 0) 45.7% */
-
- shrl $16, %eax /* output this.val char */
- stosb
- jmp .L_while_test_mmx
-
-.L_test_for_length_base_mmx:
-#define len_r %edx
- movl %eax, len_r /* len = this */
- shrl $16, len_r /* len = this.val */
-
- testb $16, %al
- jz .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */
- andl $15, %eax /* op &= 15 */
- jz .L_decode_distance_mmx /* if (!op) */
-
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
- movd %eax, used_mm
- movd hold_mm, %ecx
- subl %eax, bitslong_r
- andl .L_mask(,%eax,4), %ecx
- addl %ecx, len_r /* len += hold & mask[op] */
-
-.L_decode_distance_mmx:
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
-
- cmpl $32, bitslong_r
- ja .L_get_dist_code_mmx /* if (32 < bits) */
-
- movd bitslong_r, tmp_mm
- movd (in_r), %mm7
- addl $4, in_r
- psllq tmp_mm, %mm7
- addl $32, bitslong_r
- por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */
-
-.L_get_dist_code_mmx:
- movl dcode(%esp), %ebx /* ebx = dcode */
- pand hold_mm, dmask_mm
- movd dmask_mm, %eax
- movq dmask2_mm, dmask_mm
- movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */
-
-.L_dodist_mmx:
-#define dist_r %ebx
- movzbl %ah, %ecx /* ecx = this.bits */
- movl %eax, dist_r
- shrl $16, dist_r /* dist = this.val */
- subl %ecx, bitslong_r /* bits -= this.bits */
- movd %ecx, used_mm
-
- testb $16, %al /* if ((op & 16) == 0) */
- jz .L_test_for_second_level_dist_mmx
- andl $15, %eax /* op &= 15 */
- jz .L_check_dist_one_mmx
-
-.L_add_bits_to_dist_mmx:
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
- movd %eax, used_mm /* save bit length of current op */
- movd hold_mm, %ecx /* get the next bits on input stream */
- subl %eax, bitslong_r /* bits -= op bits */
- andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */
- addl %ecx, dist_r /* dist += hold & mask[op] */
-
-.L_check_window_mmx:
- movl in_r, in(%esp) /* save in so from can use it's reg */
- movl out_r, %eax
- subl beg(%esp), %eax /* nbytes = out - beg */
-
- cmpl dist_r, %eax
- jb .L_clip_window_mmx /* if (dist > nbytes) 4.2% */
-
- movl len_r, %ecx
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
-
- subl $3, %ecx
- movb (from_r), %al
- movb %al, (out_r)
- movb 1(from_r), %al
- movb 2(from_r), %dl
- addl $3, from_r
- movb %al, 1(out_r)
- movb %dl, 2(out_r)
- addl $3, out_r
- rep movsb
-
- movl in(%esp), in_r /* move in back to %esi, toss from */
- movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
- jmp .L_while_test_mmx
-
-.align 16,0x90
-.L_check_dist_one_mmx:
- cmpl $1, dist_r
- jne .L_check_window_mmx
- cmpl out_r, beg(%esp)
- je .L_check_window_mmx
-
- decl out_r
- movl len_r, %ecx
- movb (out_r), %al
- subl $3, %ecx
-
- movb %al, 1(out_r)
- movb %al, 2(out_r)
- movb %al, 3(out_r)
- addl $4, out_r
- rep stosb
-
- movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
- jmp .L_while_test_mmx
-
-.align 16,0x90
-.L_test_for_second_level_length_mmx:
- testb $64, %al
- jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */
-
- andl $15, %eax
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
- movd hold_mm, %ecx
- andl .L_mask(,%eax,4), %ecx
- addl len_r, %ecx
- movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */
- jmp .L_dolen_mmx
-
-.align 16,0x90
-.L_test_for_second_level_dist_mmx:
- testb $64, %al
- jnz .L_invalid_distance_code /* if ((op & 64) != 0) */
-
- andl $15, %eax
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
- movd hold_mm, %ecx
- andl .L_mask(,%eax,4), %ecx
- movl dcode(%esp), %eax /* ecx = dcode */
- addl dist_r, %ecx
- movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */
- jmp .L_dodist_mmx
-
-.align 16,0x90
-.L_clip_window_mmx:
-#define nbytes_r %ecx
- movl %eax, nbytes_r
- movl wsize(%esp), %eax /* prepare for dist compare */
- negl nbytes_r /* nbytes = -nbytes */
- movl window(%esp), from_r /* from = window */
-
- cmpl dist_r, %eax
- jb .L_invalid_distance_too_far /* if (dist > wsize) */
-
- addl dist_r, nbytes_r /* nbytes = dist - nbytes */
- cmpl $0, write(%esp)
- jne .L_wrap_around_window_mmx /* if (write != 0) */
-
- subl nbytes_r, %eax
- addl %eax, from_r /* from += wsize - nbytes */
-
- cmpl nbytes_r, len_r
- jbe .L_do_copy1_mmx /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
- jmp .L_do_copy1_mmx
-
- cmpl nbytes_r, len_r
- jbe .L_do_copy1_mmx /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
- jmp .L_do_copy1_mmx
-
-.L_wrap_around_window_mmx:
-#define write_r %eax
- movl write(%esp), write_r
- cmpl write_r, nbytes_r
- jbe .L_contiguous_in_window_mmx /* if (write >= nbytes) */
-
- addl wsize(%esp), from_r
- addl write_r, from_r
- subl nbytes_r, from_r /* from += wsize + write - nbytes */
- subl write_r, nbytes_r /* nbytes -= write */
-#undef write_r
-
- cmpl nbytes_r, len_r
- jbe .L_do_copy1_mmx /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl window(%esp), from_r /* from = window */
- movl write(%esp), nbytes_r /* nbytes = write */
- cmpl nbytes_r, len_r
- jbe .L_do_copy1_mmx /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
- jmp .L_do_copy1_mmx
-
-.L_contiguous_in_window_mmx:
-#define write_r %eax
- addl write_r, from_r
- subl nbytes_r, from_r /* from += write - nbytes */
-#undef write_r
-
- cmpl nbytes_r, len_r
- jbe .L_do_copy1_mmx /* if (nbytes >= len) */
-
- subl nbytes_r, len_r /* len -= nbytes */
- rep movsb
- movl out_r, from_r
- subl dist_r, from_r /* from = out - dist */
-
-.L_do_copy1_mmx:
-#undef nbytes_r
-#define in_r %esi
- movl len_r, %ecx
- rep movsb
-
- movl in(%esp), in_r /* move in back to %esi, toss from */
- movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
- jmp .L_while_test_mmx
-
-#undef hold_r
-#undef bitslong_r
-
-#endif /* USE_MMX || RUN_TIME_MMX */
-
-
-/*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/
-
-.L_invalid_distance_code:
- /* else {
- * strm->msg = "invalid distance code";
- * state->mode = BAD;
- * }
- */
- movl $.L_invalid_distance_code_msg, %ecx
- movl $INFLATE_MODE_BAD, %edx
- jmp .L_update_stream_state
-
-.L_test_for_end_of_block:
- /* else if (op & 32) {
- * state->mode = TYPE;
- * break;
- * }
- */
- testb $32, %al
- jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */
-
- movl $0, %ecx
- movl $INFLATE_MODE_TYPE, %edx
- jmp .L_update_stream_state
-
-.L_invalid_literal_length_code:
- /* else {
- * strm->msg = "invalid literal/length code";
- * state->mode = BAD;
- * }
- */
- movl $.L_invalid_literal_length_code_msg, %ecx
- movl $INFLATE_MODE_BAD, %edx
- jmp .L_update_stream_state
-
-.L_invalid_distance_too_far:
- /* strm->msg = "invalid distance too far back";
- * state->mode = BAD;
- */
- movl in(%esp), in_r /* from_r has in's reg, put in back */
- movl $.L_invalid_distance_too_far_msg, %ecx
- movl $INFLATE_MODE_BAD, %edx
- jmp .L_update_stream_state
-
-.L_update_stream_state:
- /* set strm->msg = %ecx, strm->state->mode = %edx */
- movl strm_sp(%esp), %eax
- testl %ecx, %ecx /* if (msg != NULL) */
- jz .L_skip_msg
- movl %ecx, msg_strm(%eax) /* strm->msg = msg */
-.L_skip_msg:
- movl state_strm(%eax), %eax /* state = strm->state */
- movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */
- jmp .L_break_loop
-
-.align 32,0x90
-.L_break_loop:
-
-/*
- * Regs:
- *
- * bits = %ebp when mmx, and in %ebx when non-mmx
- * hold = %hold_mm when mmx, and in %ebp when non-mmx
- * in = %esi
- * out = %edi
- */
-
-#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
-
-#if defined( RUN_TIME_MMX )
-
- cmpl $DO_USE_MMX, inflate_fast_use_mmx
- jne .L_update_next_in
-
-#endif /* RUN_TIME_MMX */
-
- movl %ebp, %ebx
-
-.L_update_next_in:
-
-#endif
-
-#define strm_r %eax
-#define state_r %edx
-
- /* len = bits >> 3;
- * in -= len;
- * bits -= len << 3;
- * hold &= (1U << bits) - 1;
- * state->hold = hold;
- * state->bits = bits;
- * strm->next_in = in;
- * strm->next_out = out;
- */
- movl strm_sp(%esp), strm_r
- movl %ebx, %ecx
- movl state_strm(strm_r), state_r
- shrl $3, %ecx
- subl %ecx, in_r
- shll $3, %ecx
- subl %ecx, %ebx
- movl out_r, next_out_strm(strm_r)
- movl %ebx, bits_state(state_r)
- movl %ebx, %ecx
-
- leal buf(%esp), %ebx
- cmpl %ebx, last(%esp)
- jne .L_buf_not_used /* if buf != last */
-
- subl %ebx, in_r /* in -= buf */
- movl next_in_strm(strm_r), %ebx
- movl %ebx, last(%esp) /* last = strm->next_in */
- addl %ebx, in_r /* in += strm->next_in */
- movl avail_in_strm(strm_r), %ebx
- subl $11, %ebx
- addl %ebx, last(%esp) /* last = &strm->next_in[ avail_in - 11 ] */
-
-.L_buf_not_used:
- movl in_r, next_in_strm(strm_r)
-
- movl $1, %ebx
- shll %cl, %ebx
- decl %ebx
-
-#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
-
-#if defined( RUN_TIME_MMX )
-
- cmpl $DO_USE_MMX, inflate_fast_use_mmx
- jne .L_update_hold
-
-#endif /* RUN_TIME_MMX */
-
- psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
- movd hold_mm, %ebp
-
- emms
-
-.L_update_hold:
-
-#endif /* USE_MMX || RUN_TIME_MMX */
-
- andl %ebx, %ebp
- movl %ebp, hold_state(state_r)
-
-#define last_r %ebx
-
- /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */
- movl last(%esp), last_r
- cmpl in_r, last_r
- jbe .L_last_is_smaller /* if (in >= last) */
-
- subl in_r, last_r /* last -= in */
- addl $11, last_r /* last += 11 */
- movl last_r, avail_in_strm(strm_r)
- jmp .L_fixup_out
-.L_last_is_smaller:
- subl last_r, in_r /* in -= last */
- negl in_r /* in = -in */
- addl $11, in_r /* in += 11 */
- movl in_r, avail_in_strm(strm_r)
-
-#undef last_r
-#define end_r %ebx
-
-.L_fixup_out:
- /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/
- movl end(%esp), end_r
- cmpl out_r, end_r
- jbe .L_end_is_smaller /* if (out >= end) */
-
- subl out_r, end_r /* end -= out */
- addl $257, end_r /* end += 257 */
- movl end_r, avail_out_strm(strm_r)
- jmp .L_done
-.L_end_is_smaller:
- subl end_r, out_r /* out -= end */
- negl out_r /* out = -out */
- addl $257, out_r /* out += 257 */
- movl out_r, avail_out_strm(strm_r)
-
-#undef end_r
-#undef strm_r
-#undef state_r
-
-.L_done:
- addl $local_var_size, %esp
- popf
- popl %ebx
- popl %ebp
- popl %esi
- popl %edi
- ret
-
-#if defined( GAS_ELF )
-/* elf info */
-.type inflate_fast,@function
-.size inflate_fast,.-inflate_fast
-#endif
diff --git a/cpukit/zlib/contrib/iostream/test.cpp b/cpukit/zlib/contrib/iostream/test.cpp
deleted file mode 100644
index 7d265b3b5c..0000000000
--- a/cpukit/zlib/contrib/iostream/test.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-
-#include "zfstream.h"
-
-int main() {
-
- // Construct a stream object with this filebuffer. Anything sent
- // to this stream will go to standard out.
- gzofstream os( 1, ios::out );
-
- // This text is getting compressed and sent to stdout.
- // To prove this, run 'test | zcat'.
- os << "Hello, Mommy" << endl;
-
- os << setcompressionlevel( Z_NO_COMPRESSION );
- os << "hello, hello, hi, ho!" << endl;
-
- setcompressionlevel( os, Z_DEFAULT_COMPRESSION )
- << "I'm compressing again" << endl;
-
- os.close();
-
- return 0;
-
-}
diff --git a/cpukit/zlib/contrib/iostream/zfstream.cpp b/cpukit/zlib/contrib/iostream/zfstream.cpp
deleted file mode 100644
index d0cd85faaf..0000000000
--- a/cpukit/zlib/contrib/iostream/zfstream.cpp
+++ /dev/null
@@ -1,329 +0,0 @@
-
-#include "zfstream.h"
-
-gzfilebuf::gzfilebuf() :
- file(NULL),
- mode(0),
- own_file_descriptor(0)
-{ }
-
-gzfilebuf::~gzfilebuf() {
-
- sync();
- if ( own_file_descriptor )
- close();
-
-}
-
-gzfilebuf *gzfilebuf::open( const char *name,
- int io_mode ) {
-
- if ( is_open() )
- return NULL;
-
- char char_mode[10];
- char *p = char_mode;
-
- if ( io_mode & ios::in ) {
- mode = ios::in;
- *p++ = 'r';
- } else if ( io_mode & ios::app ) {
- mode = ios::app;
- *p++ = 'a';
- } else {
- mode = ios::out;
- *p++ = 'w';
- }
-
- if ( io_mode & ios::binary ) {
- mode |= ios::binary;
- *p++ = 'b';
- }
-
- // Hard code the compression level
- if ( io_mode & (ios::out|ios::app )) {
- *p++ = '9';
- }
-
- // Put the end-of-string indicator
- *p = '\0';
-
- if ( (file = gzopen(name, char_mode)) == NULL )
- return NULL;
-
- own_file_descriptor = 1;
-
- return this;
-
-}
-
-gzfilebuf *gzfilebuf::attach( int file_descriptor,
- int io_mode ) {
-
- if ( is_open() )
- return NULL;
-
- char char_mode[10];
- char *p = char_mode;
-
- if ( io_mode & ios::in ) {
- mode = ios::in;
- *p++ = 'r';
- } else if ( io_mode & ios::app ) {
- mode = ios::app;
- *p++ = 'a';
- } else {
- mode = ios::out;
- *p++ = 'w';
- }
-
- if ( io_mode & ios::binary ) {
- mode |= ios::binary;
- *p++ = 'b';
- }
-
- // Hard code the compression level
- if ( io_mode & (ios::out|ios::app )) {
- *p++ = '9';
- }
-
- // Put the end-of-string indicator
- *p = '\0';
-
- if ( (file = gzdopen(file_descriptor, char_mode)) == NULL )
- return NULL;
-
- own_file_descriptor = 0;
-
- return this;
-
-}
-
-gzfilebuf *gzfilebuf::close() {
-
- if ( is_open() ) {
-
- sync();
- gzclose( file );
- file = NULL;
-
- }
-
- return this;
-
-}
-
-int gzfilebuf::setcompressionlevel( int comp_level ) {
-
- return gzsetparams(file, comp_level, -2);
-
-}
-
-int gzfilebuf::setcompressionstrategy( int comp_strategy ) {
-
- return gzsetparams(file, -2, comp_strategy);
-
-}
-
-
-streampos gzfilebuf::seekoff( streamoff off, ios::seek_dir dir, int which ) {
-
- return streampos(EOF);
-
-}
-
-int gzfilebuf::underflow() {
-
- // If the file hasn't been opened for reading, error.
- if ( !is_open() || !(mode & ios::in) )
- return EOF;
-
- // if a buffer doesn't exists, allocate one.
- if ( !base() ) {
-
- if ( (allocate()) == EOF )
- return EOF;
- setp(0,0);
-
- } else {
-
- if ( in_avail() )
- return (unsigned char) *gptr();
-
- if ( out_waiting() ) {
- if ( flushbuf() == EOF )
- return EOF;
- }
-
- }
-
- // Attempt to fill the buffer.
-
- int result = fillbuf();
- if ( result == EOF ) {
- // disable get area
- setg(0,0,0);
- return EOF;
- }
-
- return (unsigned char) *gptr();
-
-}
-
-int gzfilebuf::overflow( int c ) {
-
- if ( !is_open() || !(mode & ios::out) )
- return EOF;
-
- if ( !base() ) {
- if ( allocate() == EOF )
- return EOF;
- setg(0,0,0);
- } else {
- if (in_avail()) {
- return EOF;
- }
- if (out_waiting()) {
- if (flushbuf() == EOF)
- return EOF;
- }
- }
-
- int bl = blen();
- setp( base(), base() + bl);
-
- if ( c != EOF ) {
-
- *pptr() = c;
- pbump(1);
-
- }
-
- return 0;
-
-}
-
-int gzfilebuf::sync() {
-
- if ( !is_open() )
- return EOF;
-
- if ( out_waiting() )
- return flushbuf();
-
- return 0;
-
-}
-
-int gzfilebuf::flushbuf() {
-
- int n;
- char *q;
-
- q = pbase();
- n = pptr() - q;
-
- if ( gzwrite( file, q, n) < n )
- return EOF;
-
- setp(0,0);
-
- return 0;
-
-}
-
-int gzfilebuf::fillbuf() {
-
- int required;
- char *p;
-
- p = base();
-
- required = blen();
-
- int t = gzread( file, p, required );
-
- if ( t <= 0) return EOF;
-
- setg( base(), base(), base()+t);
-
- return t;
-
-}
-
-gzfilestream_common::gzfilestream_common() :
- ios( gzfilestream_common::rdbuf() )
-{ }
-
-gzfilestream_common::~gzfilestream_common()
-{ }
-
-void gzfilestream_common::attach( int fd, int io_mode ) {
-
- if ( !buffer.attach( fd, io_mode) )
- clear( ios::failbit | ios::badbit );
- else
- clear();
-
-}
-
-void gzfilestream_common::open( const char *name, int io_mode ) {
-
- if ( !buffer.open( name, io_mode ) )
- clear( ios::failbit | ios::badbit );
- else
- clear();
-
-}
-
-void gzfilestream_common::close() {
-
- if ( !buffer.close() )
- clear( ios::failbit | ios::badbit );
-
-}
-
-gzfilebuf *gzfilestream_common::rdbuf()
-{
- return &buffer;
-}
-
-gzifstream::gzifstream() :
- ios( gzfilestream_common::rdbuf() )
-{
- clear( ios::badbit );
-}
-
-gzifstream::gzifstream( const char *name, int io_mode ) :
- ios( gzfilestream_common::rdbuf() )
-{
- gzfilestream_common::open( name, io_mode );
-}
-
-gzifstream::gzifstream( int fd, int io_mode ) :
- ios( gzfilestream_common::rdbuf() )
-{
- gzfilestream_common::attach( fd, io_mode );
-}
-
-gzifstream::~gzifstream() { }
-
-gzofstream::gzofstream() :
- ios( gzfilestream_common::rdbuf() )
-{
- clear( ios::badbit );
-}
-
-gzofstream::gzofstream( const char *name, int io_mode ) :
- ios( gzfilestream_common::rdbuf() )
-{
- gzfilestream_common::open( name, io_mode );
-}
-
-gzofstream::gzofstream( int fd, int io_mode ) :
- ios( gzfilestream_common::rdbuf() )
-{
- gzfilestream_common::attach( fd, io_mode );
-}
-
-gzofstream::~gzofstream() { }
diff --git a/cpukit/zlib/contrib/iostream/zfstream.h b/cpukit/zlib/contrib/iostream/zfstream.h
deleted file mode 100644
index ed79098a3a..0000000000
--- a/cpukit/zlib/contrib/iostream/zfstream.h
+++ /dev/null
@@ -1,128 +0,0 @@
-
-#ifndef zfstream_h
-#define zfstream_h
-
-#include <fstream.h>
-#include "zlib.h"
-
-class gzfilebuf : public streambuf {
-
-public:
-
- gzfilebuf( );
- virtual ~gzfilebuf();
-
- gzfilebuf *open( const char *name, int io_mode );
- gzfilebuf *attach( int file_descriptor, int io_mode );
- gzfilebuf *close();
-
- int setcompressionlevel( int comp_level );
- int setcompressionstrategy( int comp_strategy );
-
- inline int is_open() const { return (file !=NULL); }
-
- virtual streampos seekoff( streamoff, ios::seek_dir, int );
-
- virtual int sync();
-
-protected:
-
- virtual int underflow();
- virtual int overflow( int = EOF );
-
-private:
-
- gzFile file;
- short mode;
- short own_file_descriptor;
-
- int flushbuf();
- int fillbuf();
-
-};
-
-class gzfilestream_common : virtual public ios {
-
- friend class gzifstream;
- friend class gzofstream;
- friend gzofstream &setcompressionlevel( gzofstream &, int );
- friend gzofstream &setcompressionstrategy( gzofstream &, int );
-
-public:
- virtual ~gzfilestream_common();
-
- void attach( int fd, int io_mode );
- void open( const char *name, int io_mode );
- void close();
-
-protected:
- gzfilestream_common();
-
-private:
- gzfilebuf *rdbuf();
-
- gzfilebuf buffer;
-
-};
-
-class gzifstream : public gzfilestream_common, public istream {
-
-public:
-
- gzifstream();
- gzifstream( const char *name, int io_mode = ios::in );
- gzifstream( int fd, int io_mode = ios::in );
-
- virtual ~gzifstream();
-
-};
-
-class gzofstream : public gzfilestream_common, public ostream {
-
-public:
-
- gzofstream();
- gzofstream( const char *name, int io_mode = ios::out );
- gzofstream( int fd, int io_mode = ios::out );
-
- virtual ~gzofstream();
-
-};
-
-template<class T> class gzomanip {
- friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &);
-public:
- gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { }
-private:
- gzofstream &(*func)(gzofstream &, T);
- T val;
-};
-
-template<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m)
-{
- return (*m.func)(s, m.val);
-}
-
-inline gzofstream &setcompressionlevel( gzofstream &s, int l )
-{
- (s.rdbuf())->setcompressionlevel(l);
- return s;
-}
-
-inline gzofstream &setcompressionstrategy( gzofstream &s, int l )
-{
- (s.rdbuf())->setcompressionstrategy(l);
- return s;
-}
-
-inline gzomanip<int> setcompressionlevel(int l)
-{
- return gzomanip<int>(&setcompressionlevel,l);
-}
-
-inline gzomanip<int> setcompressionstrategy(int l)
-{
- return gzomanip<int>(&setcompressionstrategy,l);
-}
-
-#endif
diff --git a/cpukit/zlib/contrib/iostream2/zstream.h b/cpukit/zlib/contrib/iostream2/zstream.h
deleted file mode 100644
index 861ef2bad9..0000000000
--- a/cpukit/zlib/contrib/iostream2/zstream.h
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- *
- * Copyright (c) 1997
- * Christian Michelsen Research AS
- * Advanced Computing
- * Fantoftvegen 38, 5036 BERGEN, Norway
- * http://www.cmr.no
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Christian Michelsen Research AS makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#ifndef ZSTREAM__H
-#define ZSTREAM__H
-
-/*
- * zstream.h - C++ interface to the 'zlib' general purpose compression library
- * $Id$
- */
-
-#include <strstream.h>
-#include <string.h>
-#include <stdio.h>
-#include "zlib.h"
-
-#if defined(_WIN32)
-# include <fcntl.h>
-# include <io.h>
-# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-# define SET_BINARY_MODE(file)
-#endif
-
-class zstringlen {
-public:
- zstringlen(class izstream&);
- zstringlen(class ozstream&, const char*);
- size_t value() const { return val.word; }
-private:
- struct Val { unsigned char byte; size_t word; } val;
-};
-
-// ----------------------------- izstream -----------------------------
-
-class izstream
-{
- public:
- izstream() : m_fp(0) {}
- izstream(FILE* fp) : m_fp(0) { open(fp); }
- izstream(const char* name) : m_fp(0) { open(name); }
- ~izstream() { close(); }
-
- /* Opens a gzip (.gz) file for reading.
- * open() can be used to read a file which is not in gzip format;
- * in this case read() will directly read from the file without
- * decompression. errno can be checked to distinguish two error
- * cases (if errno is zero, the zlib error is Z_MEM_ERROR).
- */
- void open(const char* name) {
- if (m_fp) close();
- m_fp = ::gzopen(name, "rb");
- }
-
- void open(FILE* fp) {
- SET_BINARY_MODE(fp);
- if (m_fp) close();
- m_fp = ::gzdopen(fileno(fp), "rb");
- }
-
- /* Flushes all pending input if necessary, closes the compressed file
- * and deallocates all the (de)compression state. The return value is
- * the zlib error number (see function error() below).
- */
- int close() {
- int r = ::gzclose(m_fp);
- m_fp = 0; return r;
- }
-
- /* Binary read the given number of bytes from the compressed file.
- */
- int read(void* buf, size_t len) {
- return ::gzread(m_fp, buf, len);
- }
-
- /* Returns the error message for the last error which occurred on the
- * given compressed file. errnum is set to zlib error number. If an
- * error occurred in the file system and not in the compression library,
- * errnum is set to Z_ERRNO and the application may consult errno
- * to get the exact error code.
- */
- const char* error(int* errnum) {
- return ::gzerror(m_fp, errnum);
- }
-
- gzFile fp() { return m_fp; }
-
- private:
- gzFile m_fp;
-};
-
-/*
- * Binary read the given (array of) object(s) from the compressed file.
- * If the input file was not in gzip format, read() copies the objects number
- * of bytes into the buffer.
- * returns the number of uncompressed bytes actually read
- * (0 for end of file, -1 for error).
- */
-template <class T, class Items>
-inline int read(izstream& zs, T* x, Items items) {
- return ::gzread(zs.fp(), x, items*sizeof(T));
-}
-
-/*
- * Binary input with the '>' operator.
- */
-template <class T>
-inline izstream& operator>(izstream& zs, T& x) {
- ::gzread(zs.fp(), &x, sizeof(T));
- return zs;
-}
-
-
-inline zstringlen::zstringlen(izstream& zs) {
- zs > val.byte;
- if (val.byte == 255) zs > val.word;
- else val.word = val.byte;
-}
-
-/*
- * Read length of string + the string with the '>' operator.
- */
-inline izstream& operator>(izstream& zs, char* x) {
- zstringlen len(zs);
- ::gzread(zs.fp(), x, len.value());
- x[len.value()] = '\0';
- return zs;
-}
-
-inline char* read_string(izstream& zs) {
- zstringlen len(zs);
- char* x = new char[len.value()+1];
- ::gzread(zs.fp(), x, len.value());
- x[len.value()] = '\0';
- return x;
-}
-
-// ----------------------------- ozstream -----------------------------
-
-class ozstream
-{
- public:
- ozstream() : m_fp(0), m_os(0) {
- }
- ozstream(FILE* fp, int level = Z_DEFAULT_COMPRESSION)
- : m_fp(0), m_os(0) {
- open(fp, level);
- }
- ozstream(const char* name, int level = Z_DEFAULT_COMPRESSION)
- : m_fp(0), m_os(0) {
- open(name, level);
- }
- ~ozstream() {
- close();
- }
-
- /* Opens a gzip (.gz) file for writing.
- * The compression level parameter should be in 0..9
- * errno can be checked to distinguish two error cases
- * (if errno is zero, the zlib error is Z_MEM_ERROR).
- */
- void open(const char* name, int level = Z_DEFAULT_COMPRESSION) {
- char mode[4] = "wb\0";
- if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level;
- if (m_fp) close();
- m_fp = ::gzopen(name, mode);
- }
-
- /* open from a FILE pointer.
- */
- void open(FILE* fp, int level = Z_DEFAULT_COMPRESSION) {
- SET_BINARY_MODE(fp);
- char mode[4] = "wb\0";
- if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level;
- if (m_fp) close();
- m_fp = ::gzdopen(fileno(fp), mode);
- }
-
- /* Flushes all pending output if necessary, closes the compressed file
- * and deallocates all the (de)compression state. The return value is
- * the zlib error number (see function error() below).
- */
- int close() {
- if (m_os) {
- ::gzwrite(m_fp, m_os->str(), m_os->pcount());
- delete[] m_os->str(); delete m_os; m_os = 0;
- }
- int r = ::gzclose(m_fp); m_fp = 0; return r;
- }
-
- /* Binary write the given number of bytes into the compressed file.
- */
- int write(const void* buf, size_t len) {
- return ::gzwrite(m_fp, (voidp) buf, len);
- }
-
- /* Flushes all pending output into the compressed file. The parameter
- * _flush is as in the deflate() function. The return value is the zlib
- * error number (see function gzerror below). flush() returns Z_OK if
- * the flush_ parameter is Z_FINISH and all output could be flushed.
- * flush() should be called only when strictly necessary because it can
- * degrade compression.
- */
- int flush(int _flush) {
- os_flush();
- return ::gzflush(m_fp, _flush);
- }
-
- /* Returns the error message for the last error which occurred on the
- * given compressed file. errnum is set to zlib error number. If an
- * error occurred in the file system and not in the compression library,
- * errnum is set to Z_ERRNO and the application may consult errno
- * to get the exact error code.
- */
- const char* error(int* errnum) {
- return ::gzerror(m_fp, errnum);
- }
-
- gzFile fp() { return m_fp; }
-
- ostream& os() {
- if (m_os == 0) m_os = new ostrstream;
- return *m_os;
- }
-
- void os_flush() {
- if (m_os && m_os->pcount()>0) {
- ostrstream* oss = new ostrstream;
- oss->fill(m_os->fill());
- oss->flags(m_os->flags());
- oss->precision(m_os->precision());
- oss->width(m_os->width());
- ::gzwrite(m_fp, m_os->str(), m_os->pcount());
- delete[] m_os->str(); delete m_os; m_os = oss;
- }
- }
-
- private:
- gzFile m_fp;
- ostrstream* m_os;
-};
-
-/*
- * Binary write the given (array of) object(s) into the compressed file.
- * returns the number of uncompressed bytes actually written
- * (0 in case of error).
- */
-template <class T, class Items>
-inline int write(ozstream& zs, const T* x, Items items) {
- return ::gzwrite(zs.fp(), (voidp) x, items*sizeof(T));
-}
-
-/*
- * Binary output with the '<' operator.
- */
-template <class T>
-inline ozstream& operator<(ozstream& zs, const T& x) {
- ::gzwrite(zs.fp(), (voidp) &x, sizeof(T));
- return zs;
-}
-
-inline zstringlen::zstringlen(ozstream& zs, const char* x) {
- val.byte = 255; val.word = ::strlen(x);
- if (val.word < 255) zs < (val.byte = val.word);
- else zs < val;
-}
-
-/*
- * Write length of string + the string with the '<' operator.
- */
-inline ozstream& operator<(ozstream& zs, const char* x) {
- zstringlen len(zs, x);
- ::gzwrite(zs.fp(), (voidp) x, len.value());
- return zs;
-}
-
-#ifdef _MSC_VER
-inline ozstream& operator<(ozstream& zs, char* const& x) {
- return zs < (const char*) x;
-}
-#endif
-
-/*
- * Ascii write with the << operator;
- */
-template <class T>
-inline ostream& operator<<(ozstream& zs, const T& x) {
- zs.os_flush();
- return zs.os() << x;
-}
-
-#endif
diff --git a/cpukit/zlib/contrib/iostream2/zstream_test.cpp b/cpukit/zlib/contrib/iostream2/zstream_test.cpp
deleted file mode 100644
index 6273f62d62..0000000000
--- a/cpukit/zlib/contrib/iostream2/zstream_test.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "zstream.h"
-#include <math.h>
-#include <stdlib.h>
-#include <iomanip.h>
-
-void main() {
- char h[256] = "Hello";
- char* g = "Goodbye";
- ozstream out("temp.gz");
- out < "This works well" < h < g;
- out.close();
-
- izstream in("temp.gz"); // read it back
- char *x = read_string(in), *y = new char[256], z[256];
- in > y > z;
- in.close();
- cout << x << endl << y << endl << z << endl;
-
- out.open("temp.gz"); // try ascii output; zcat temp.gz to see the results
- out << setw(50) << setfill('#') << setprecision(20) << x << endl << y << endl << z << endl;
- out << z << endl << y << endl << x << endl;
- out << 1.1234567890123456789 << endl;
-
- delete[] x; delete[] y;
-}
diff --git a/cpukit/zlib/contrib/iostream3/README b/cpukit/zlib/contrib/iostream3/README
deleted file mode 100644
index f7b319ab91..0000000000
--- a/cpukit/zlib/contrib/iostream3/README
+++ /dev/null
@@ -1,35 +0,0 @@
-These classes provide a C++ stream interface to the zlib library. It allows you
-to do things like:
-
- gzofstream outf("blah.gz");
- outf << "These go into the gzip file " << 123 << endl;
-
-It does this by deriving a specialized stream buffer for gzipped files, which is
-the way Stroustrup would have done it. :->
-
-The gzifstream and gzofstream classes were originally written by Kevin Ruland
-and made available in the zlib contrib/iostream directory. The older version still
-compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of
-this version.
-
-The new classes are as standard-compliant as possible, closely following the
-approach of the standard library's fstream classes. It compiles under gcc versions
-3.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard
-library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs
-from the previous one in the following respects:
-- added showmanyc
-- added setbuf, with support for unbuffered output via setbuf(0,0)
-- a few bug fixes of stream behavior
-- gzipped output file opened with default compression level instead of maximum level
-- setcompressionlevel()/strategy() members replaced by single setcompression()
-
-The code is provided "as is", with the permission to use, copy, modify, distribute
-and sell it for any purpose without fee.
-
-Ludwig Schwardt
-<schwardt@sun.ac.za>
-
-DSP Lab
-Electrical & Electronic Engineering Department
-University of Stellenbosch
-South Africa
diff --git a/cpukit/zlib/contrib/iostream3/TODO b/cpukit/zlib/contrib/iostream3/TODO
deleted file mode 100644
index 7032f97be0..0000000000
--- a/cpukit/zlib/contrib/iostream3/TODO
+++ /dev/null
@@ -1,17 +0,0 @@
-Possible upgrades to gzfilebuf:
-
-- The ability to do putback (e.g. putbackfail)
-
-- The ability to seek (zlib supports this, but could be slow/tricky)
-
-- Simultaneous read/write access (does it make sense?)
-
-- Support for ios_base::ate open mode
-
-- Locale support?
-
-- Check public interface to see which calls give problems
- (due to dependence on library internals)
-
-- Override operator<<(ostream&, gzfilebuf*) to allow direct copying
- of stream buffer to stream ( i.e. os << is.rdbuf(); )
diff --git a/cpukit/zlib/contrib/iostream3/test.cc b/cpukit/zlib/contrib/iostream3/test.cc
deleted file mode 100644
index 94235334f2..0000000000
--- a/cpukit/zlib/contrib/iostream3/test.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Test program for gzifstream and gzofstream
- *
- * by Ludwig Schwardt <schwardt@sun.ac.za>
- * original version by Kevin Ruland <kevin@rodin.wustl.edu>
- */
-
-#include "zfstream.h"
-#include <iostream> // for cout
-
-int main() {
-
- gzofstream outf;
- gzifstream inf;
- char buf[80];
-
- outf.open("test1.txt.gz");
- outf << "The quick brown fox sidestepped the lazy canine\n"
- << 1.3 << "\nPlan " << 9 << std::endl;
- outf.close();
- std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n"
- << "The quick brown fox sidestepped the lazy canine\n"
- << 1.3 << "\nPlan " << 9 << std::endl;
-
- std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n";
- inf.open("test1.txt.gz");
- while (inf.getline(buf,80,'\n')) {
- std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
- }
- inf.close();
-
- outf.rdbuf()->pubsetbuf(0,0);
- outf.open("test2.txt.gz");
- outf << setcompression(Z_NO_COMPRESSION)
- << "The quick brown fox sidestepped the lazy canine\n"
- << 1.3 << "\nPlan " << 9 << std::endl;
- outf.close();
- std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form";
-
- std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n";
- inf.rdbuf()->pubsetbuf(0,0);
- inf.open("test2.txt.gz");
- while (inf.getline(buf,80,'\n')) {
- std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
- }
- inf.close();
-
- return 0;
-
-}
diff --git a/cpukit/zlib/contrib/iostream3/zfstream.cc b/cpukit/zlib/contrib/iostream3/zfstream.cc
deleted file mode 100644
index 94eb933444..0000000000
--- a/cpukit/zlib/contrib/iostream3/zfstream.cc
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
- * A C++ I/O streams interface to the zlib gz* functions
- *
- * by Ludwig Schwardt <schwardt@sun.ac.za>
- * original version by Kevin Ruland <kevin@rodin.wustl.edu>
- *
- * This version is standard-compliant and compatible with gcc 3.x.
- */
-
-#include "zfstream.h"
-#include <cstring> // for strcpy, strcat, strlen (mode strings)
-#include <cstdio> // for BUFSIZ
-
-// Internal buffer sizes (default and "unbuffered" versions)
-#define BIGBUFSIZE BUFSIZ
-#define SMALLBUFSIZE 1
-
-/*****************************************************************************/
-
-// Default constructor
-gzfilebuf::gzfilebuf()
-: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false),
- buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true)
-{
- // No buffers to start with
- this->disable_buffer();
-}
-
-// Destructor
-gzfilebuf::~gzfilebuf()
-{
- // Sync output buffer and close only if responsible for file
- // (i.e. attached streams should be left open at this stage)
- this->sync();
- if (own_fd)
- this->close();
- // Make sure internal buffer is deallocated
- this->disable_buffer();
-}
-
-// Set compression level and strategy
-int
-gzfilebuf::setcompression(int comp_level,
- int comp_strategy)
-{
- return gzsetparams(file, comp_level, comp_strategy);
-}
-
-// Open gzipped file
-gzfilebuf*
-gzfilebuf::open(const char *name,
- std::ios_base::openmode mode)
-{
- // Fail if file already open
- if (this->is_open())
- return NULL;
- // Don't support simultaneous read/write access (yet)
- if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
- return NULL;
-
- // Build mode string for gzopen and check it [27.8.1.3.2]
- char char_mode[6] = "\0\0\0\0\0";
- if (!this->open_mode(mode, char_mode))
- return NULL;
-
- // Attempt to open file
- if ((file = gzopen(name, char_mode)) == NULL)
- return NULL;
-
- // On success, allocate internal buffer and set flags
- this->enable_buffer();
- io_mode = mode;
- own_fd = true;
- return this;
-}
-
-// Attach to gzipped file
-gzfilebuf*
-gzfilebuf::attach(int fd,
- std::ios_base::openmode mode)
-{
- // Fail if file already open
- if (this->is_open())
- return NULL;
- // Don't support simultaneous read/write access (yet)
- if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
- return NULL;
-
- // Build mode string for gzdopen and check it [27.8.1.3.2]
- char char_mode[6] = "\0\0\0\0\0";
- if (!this->open_mode(mode, char_mode))
- return NULL;
-
- // Attempt to attach to file
- if ((file = gzdopen(fd, char_mode)) == NULL)
- return NULL;
-
- // On success, allocate internal buffer and set flags
- this->enable_buffer();
- io_mode = mode;
- own_fd = false;
- return this;
-}
-
-// Close gzipped file
-gzfilebuf*
-gzfilebuf::close()
-{
- // Fail immediately if no file is open
- if (!this->is_open())
- return NULL;
- // Assume success
- gzfilebuf* retval = this;
- // Attempt to sync and close gzipped file
- if (this->sync() == -1)
- retval = NULL;
- if (gzclose(file) < 0)
- retval = NULL;
- // File is now gone anyway (postcondition [27.8.1.3.8])
- file = NULL;
- own_fd = false;
- // Destroy internal buffer if it exists
- this->disable_buffer();
- return retval;
-}
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-// Convert int open mode to mode string
-bool
-gzfilebuf::open_mode(std::ios_base::openmode mode,
- char* c_mode) const
-{
- bool testb = mode & std::ios_base::binary;
- bool testi = mode & std::ios_base::in;
- bool testo = mode & std::ios_base::out;
- bool testt = mode & std::ios_base::trunc;
- bool testa = mode & std::ios_base::app;
-
- // Check for valid flag combinations - see [27.8.1.3.2] (Table 92)
- // Original zfstream hardcoded the compression level to maximum here...
- // Double the time for less than 1% size improvement seems
- // excessive though - keeping it at the default level
- // To change back, just append "9" to the next three mode strings
- if (!testi && testo && !testt && !testa)
- strcpy(c_mode, "w");
- if (!testi && testo && !testt && testa)
- strcpy(c_mode, "a");
- if (!testi && testo && testt && !testa)
- strcpy(c_mode, "w");
- if (testi && !testo && !testt && !testa)
- strcpy(c_mode, "r");
- // No read/write mode yet
-// if (testi && testo && !testt && !testa)
-// strcpy(c_mode, "r+");
-// if (testi && testo && testt && !testa)
-// strcpy(c_mode, "w+");
-
- // Mode string should be empty for invalid combination of flags
- if (strlen(c_mode) == 0)
- return false;
- if (testb)
- strcat(c_mode, "b");
- return true;
-}
-
-// Determine number of characters in internal get buffer
-std::streamsize
-gzfilebuf::showmanyc()
-{
- // Calls to underflow will fail if file not opened for reading
- if (!this->is_open() || !(io_mode & std::ios_base::in))
- return -1;
- // Make sure get area is in use
- if (this->gptr() && (this->gptr() < this->egptr()))
- return std::streamsize(this->egptr() - this->gptr());
- else
- return 0;
-}
-
-// Fill get area from gzipped file
-gzfilebuf::int_type
-gzfilebuf::underflow()
-{
- // If something is left in the get area by chance, return it
- // (this shouldn't normally happen, as underflow is only supposed
- // to be called when gptr >= egptr, but it serves as error check)
- if (this->gptr() && (this->gptr() < this->egptr()))
- return traits_type::to_int_type(*(this->gptr()));
-
- // If the file hasn't been opened for reading, produce error
- if (!this->is_open() || !(io_mode & std::ios_base::in))
- return traits_type::eof();
-
- // Attempt to fill internal buffer from gzipped file
- // (buffer must be guaranteed to exist...)
- int bytes_read = gzread(file, buffer, buffer_size);
- // Indicates error or EOF
- if (bytes_read <= 0)
- {
- // Reset get area
- this->setg(buffer, buffer, buffer);
- return traits_type::eof();
- }
- // Make all bytes read from file available as get area
- this->setg(buffer, buffer, buffer + bytes_read);
-
- // Return next character in get area
- return traits_type::to_int_type(*(this->gptr()));
-}
-
-// Write put area to gzipped file
-gzfilebuf::int_type
-gzfilebuf::overflow(int_type c)
-{
- // Determine whether put area is in use
- if (this->pbase())
- {
- // Double-check pointer range
- if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
- return traits_type::eof();
- // Add extra character to buffer if not EOF
- if (!traits_type::eq_int_type(c, traits_type::eof()))
- {
- *(this->pptr()) = traits_type::to_char_type(c);
- this->pbump(1);
- }
- // Number of characters to write to file
- int bytes_to_write = this->pptr() - this->pbase();
- // Overflow doesn't fail if nothing is to be written
- if (bytes_to_write > 0)
- {
- // If the file hasn't been opened for writing, produce error
- if (!this->is_open() || !(io_mode & std::ios_base::out))
- return traits_type::eof();
- // If gzipped file won't accept all bytes written to it, fail
- if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write)
- return traits_type::eof();
- // Reset next pointer to point to pbase on success
- this->pbump(-bytes_to_write);
- }
- }
- // Write extra character to file if not EOF
- else if (!traits_type::eq_int_type(c, traits_type::eof()))
- {
- // If the file hasn't been opened for writing, produce error
- if (!this->is_open() || !(io_mode & std::ios_base::out))
- return traits_type::eof();
- // Impromptu char buffer (allows "unbuffered" output)
- char_type last_char = traits_type::to_char_type(c);
- // If gzipped file won't accept this character, fail
- if (gzwrite(file, &last_char, 1) != 1)
- return traits_type::eof();
- }
-
- // If you got here, you have succeeded (even if c was EOF)
- // The return value should therefore be non-EOF
- if (traits_type::eq_int_type(c, traits_type::eof()))
- return traits_type::not_eof(c);
- else
- return c;
-}
-
-// Assign new buffer
-std::streambuf*
-gzfilebuf::setbuf(char_type* p,
- std::streamsize n)
-{
- // First make sure stuff is sync'ed, for safety
- if (this->sync() == -1)
- return NULL;
- // If buffering is turned off on purpose via setbuf(0,0), still allocate one...
- // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at
- // least a buffer of size 1 (very inefficient though, therefore make it bigger?)
- // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems)
- if (!p || !n)
- {
- // Replace existing buffer (if any) with small internal buffer
- this->disable_buffer();
- buffer = NULL;
- buffer_size = 0;
- own_buffer = true;
- this->enable_buffer();
- }
- else
- {
- // Replace existing buffer (if any) with external buffer
- this->disable_buffer();
- buffer = p;
- buffer_size = n;
- own_buffer = false;
- this->enable_buffer();
- }
- return this;
-}
-
-// Write put area to gzipped file (i.e. ensures that put area is empty)
-int
-gzfilebuf::sync()
-{
- return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0;
-}
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-// Allocate internal buffer
-void
-gzfilebuf::enable_buffer()
-{
- // If internal buffer required, allocate one
- if (own_buffer && !buffer)
- {
- // Check for buffered vs. "unbuffered"
- if (buffer_size > 0)
- {
- // Allocate internal buffer
- buffer = new char_type[buffer_size];
- // Get area starts empty and will be expanded by underflow as need arises
- this->setg(buffer, buffer, buffer);
- // Setup entire internal buffer as put area.
- // The one-past-end pointer actually points to the last element of the buffer,
- // so that overflow(c) can safely add the extra character c to the sequence.
- // These pointers remain in place for the duration of the buffer
- this->setp(buffer, buffer + buffer_size - 1);
- }
- else
- {
- // Even in "unbuffered" case, (small?) get buffer is still required
- buffer_size = SMALLBUFSIZE;
- buffer = new char_type[buffer_size];
- this->setg(buffer, buffer, buffer);
- // "Unbuffered" means no put buffer
- this->setp(0, 0);
- }
- }
- else
- {
- // If buffer already allocated, reset buffer pointers just to make sure no
- // stale chars are lying around
- this->setg(buffer, buffer, buffer);
- this->setp(buffer, buffer + buffer_size - 1);
- }
-}
-
-// Destroy internal buffer
-void
-gzfilebuf::disable_buffer()
-{
- // If internal buffer exists, deallocate it
- if (own_buffer && buffer)
- {
- // Preserve unbuffered status by zeroing size
- if (!this->pbase())
- buffer_size = 0;
- delete[] buffer;
- buffer = NULL;
- this->setg(0, 0, 0);
- this->setp(0, 0);
- }
- else
- {
- // Reset buffer pointers to initial state if external buffer exists
- this->setg(buffer, buffer, buffer);
- if (buffer)
- this->setp(buffer, buffer + buffer_size - 1);
- else
- this->setp(0, 0);
- }
-}
-
-/*****************************************************************************/
-
-// Default constructor initializes stream buffer
-gzifstream::gzifstream()
-: std::istream(NULL), sb()
-{ this->init(&sb); }
-
-// Initialize stream buffer and open file
-gzifstream::gzifstream(const char* name,
- std::ios_base::openmode mode)
-: std::istream(NULL), sb()
-{
- this->init(&sb);
- this->open(name, mode);
-}
-
-// Initialize stream buffer and attach to file
-gzifstream::gzifstream(int fd,
- std::ios_base::openmode mode)
-: std::istream(NULL), sb()
-{
- this->init(&sb);
- this->attach(fd, mode);
-}
-
-// Open file and go into fail() state if unsuccessful
-void
-gzifstream::open(const char* name,
- std::ios_base::openmode mode)
-{
- if (!sb.open(name, mode | std::ios_base::in))
- this->setstate(std::ios_base::failbit);
- else
- this->clear();
-}
-
-// Attach to file and go into fail() state if unsuccessful
-void
-gzifstream::attach(int fd,
- std::ios_base::openmode mode)
-{
- if (!sb.attach(fd, mode | std::ios_base::in))
- this->setstate(std::ios_base::failbit);
- else
- this->clear();
-}
-
-// Close file
-void
-gzifstream::close()
-{
- if (!sb.close())
- this->setstate(std::ios_base::failbit);
-}
-
-/*****************************************************************************/
-
-// Default constructor initializes stream buffer
-gzofstream::gzofstream()
-: std::ostream(NULL), sb()
-{ this->init(&sb); }
-
-// Initialize stream buffer and open file
-gzofstream::gzofstream(const char* name,
- std::ios_base::openmode mode)
-: std::ostream(NULL), sb()
-{
- this->init(&sb);
- this->open(name, mode);
-}
-
-// Initialize stream buffer and attach to file
-gzofstream::gzofstream(int fd,
- std::ios_base::openmode mode)
-: std::ostream(NULL), sb()
-{
- this->init(&sb);
- this->attach(fd, mode);
-}
-
-// Open file and go into fail() state if unsuccessful
-void
-gzofstream::open(const char* name,
- std::ios_base::openmode mode)
-{
- if (!sb.open(name, mode | std::ios_base::out))
- this->setstate(std::ios_base::failbit);
- else
- this->clear();
-}
-
-// Attach to file and go into fail() state if unsuccessful
-void
-gzofstream::attach(int fd,
- std::ios_base::openmode mode)
-{
- if (!sb.attach(fd, mode | std::ios_base::out))
- this->setstate(std::ios_base::failbit);
- else
- this->clear();
-}
-
-// Close file
-void
-gzofstream::close()
-{
- if (!sb.close())
- this->setstate(std::ios_base::failbit);
-}
diff --git a/cpukit/zlib/contrib/iostream3/zfstream.h b/cpukit/zlib/contrib/iostream3/zfstream.h
deleted file mode 100644
index 8574479ae1..0000000000
--- a/cpukit/zlib/contrib/iostream3/zfstream.h
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * A C++ I/O streams interface to the zlib gz* functions
- *
- * by Ludwig Schwardt <schwardt@sun.ac.za>
- * original version by Kevin Ruland <kevin@rodin.wustl.edu>
- *
- * This version is standard-compliant and compatible with gcc 3.x.
- */
-
-#ifndef ZFSTREAM_H
-#define ZFSTREAM_H
-
-#include <istream> // not iostream, since we don't need cin/cout
-#include <ostream>
-#include "zlib.h"
-
-/*****************************************************************************/
-
-/**
- * @brief Gzipped file stream buffer class.
- *
- * This class implements basic_filebuf for gzipped files. It doesn't yet support
- * seeking (allowed by zlib but slow/limited), putback and read/write access
- * (tricky). Otherwise, it attempts to be a drop-in replacement for the standard
- * file streambuf.
-*/
-class gzfilebuf : public std::streambuf
-{
-public:
- // Default constructor.
- gzfilebuf();
-
- // Destructor.
- virtual
- ~gzfilebuf();
-
- /**
- * @brief Set compression level and strategy on the fly.
- * @param comp_level Compression level (see zlib.h for allowed values)
- * @param comp_strategy Compression strategy (see zlib.h for allowed values)
- * @return Z_OK on success, Z_STREAM_ERROR otherwise.
- *
- * Unfortunately, these parameters cannot be modified separately, as the
- * previous zfstream version assumed. Since the strategy is seldom changed,
- * it can default and setcompression(level) then becomes like the old
- * setcompressionlevel(level).
- */
- int
- setcompression(int comp_level,
- int comp_strategy = Z_DEFAULT_STRATEGY);
-
- /**
- * @brief Check if file is open.
- * @return True if file is open.
- */
- bool
- is_open() const { return (file != NULL); }
-
- /**
- * @brief Open gzipped file.
- * @param name File name.
- * @param mode Open mode flags.
- * @return @c this on success, NULL on failure.
- */
- gzfilebuf*
- open(const char* name,
- std::ios_base::openmode mode);
-
- /**
- * @brief Attach to already open gzipped file.
- * @param fd File descriptor.
- * @param mode Open mode flags.
- * @return @c this on success, NULL on failure.
- */
- gzfilebuf*
- attach(int fd,
- std::ios_base::openmode mode);
-
- /**
- * @brief Close gzipped file.
- * @return @c this on success, NULL on failure.
- */
- gzfilebuf*
- close();
-
-protected:
- /**
- * @brief Convert ios open mode int to mode string used by zlib.
- * @return True if valid mode flag combination.
- */
- bool
- open_mode(std::ios_base::openmode mode,
- char* c_mode) const;
-
- /**
- * @brief Number of characters available in stream buffer.
- * @return Number of characters.
- *
- * This indicates number of characters in get area of stream buffer.
- * These characters can be read without accessing the gzipped file.
- */
- virtual std::streamsize
- showmanyc();
-
- /**
- * @brief Fill get area from gzipped file.
- * @return First character in get area on success, EOF on error.
- *
- * This actually reads characters from gzipped file to stream
- * buffer. Always buffered.
- */
- virtual int_type
- underflow();
-
- /**
- * @brief Write put area to gzipped file.
- * @param c Extra character to add to buffer contents.
- * @return Non-EOF on success, EOF on error.
- *
- * This actually writes characters in stream buffer to
- * gzipped file. With unbuffered output this is done one
- * character at a time.
- */
- virtual int_type
- overflow(int_type c = traits_type::eof());
-
- /**
- * @brief Installs external stream buffer.
- * @param p Pointer to char buffer.
- * @param n Size of external buffer.
- * @return @c this on success, NULL on failure.
- *
- * Call setbuf(0,0) to enable unbuffered output.
- */
- virtual std::streambuf*
- setbuf(char_type* p,
- std::streamsize n);
-
- /**
- * @brief Flush stream buffer to file.
- * @return 0 on success, -1 on error.
- *
- * This calls underflow(EOF) to do the job.
- */
- virtual int
- sync();
-
-//
-// Some future enhancements
-//
-// virtual int_type uflow();
-// virtual int_type pbackfail(int_type c = traits_type::eof());
-// virtual pos_type
-// seekoff(off_type off,
-// std::ios_base::seekdir way,
-// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
-// virtual pos_type
-// seekpos(pos_type sp,
-// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
-
-private:
- /**
- * @brief Allocate internal buffer.
- *
- * This function is safe to call multiple times. It will ensure
- * that a proper internal buffer exists if it is required. If the
- * buffer already exists or is external, the buffer pointers will be
- * reset to their original state.
- */
- void
- enable_buffer();
-
- /**
- * @brief Destroy internal buffer.
- *
- * This function is safe to call multiple times. It will ensure
- * that the internal buffer is deallocated if it exists. In any
- * case, it will also reset the buffer pointers.
- */
- void
- disable_buffer();
-
- /**
- * Underlying file pointer.
- */
- gzFile file;
-
- /**
- * Mode in which file was opened.
- */
- std::ios_base::openmode io_mode;
-
- /**
- * @brief True if this object owns file descriptor.
- *
- * This makes the class responsible for closing the file
- * upon destruction.
- */
- bool own_fd;
-
- /**
- * @brief Stream buffer.
- *
- * For simplicity this remains allocated on the free store for the
- * entire life span of the gzfilebuf object, unless replaced by setbuf.
- */
- char_type* buffer;
-
- /**
- * @brief Stream buffer size.
- *
- * Defaults to system default buffer size (typically 8192 bytes).
- * Modified by setbuf.
- */
- std::streamsize buffer_size;
-
- /**
- * @brief True if this object owns stream buffer.
- *
- * This makes the class responsible for deleting the buffer
- * upon destruction.
- */
- bool own_buffer;
-};
-
-/*****************************************************************************/
-
-/**
- * @brief Gzipped file input stream class.
- *
- * This class implements ifstream for gzipped files. Seeking and putback
- * is not supported yet.
-*/
-class gzifstream : public std::istream
-{
-public:
- // Default constructor
- gzifstream();
-
- /**
- * @brief Construct stream on gzipped file to be opened.
- * @param name File name.
- * @param mode Open mode flags (forced to contain ios::in).
- */
- explicit
- gzifstream(const char* name,
- std::ios_base::openmode mode = std::ios_base::in);
-
- /**
- * @brief Construct stream on already open gzipped file.
- * @param fd File descriptor.
- * @param mode Open mode flags (forced to contain ios::in).
- */
- explicit
- gzifstream(int fd,
- std::ios_base::openmode mode = std::ios_base::in);
-
- /**
- * Obtain underlying stream buffer.
- */
- gzfilebuf*
- rdbuf() const
- { return const_cast<gzfilebuf*>(&sb); }
-
- /**
- * @brief Check if file is open.
- * @return True if file is open.
- */
- bool
- is_open() { return sb.is_open(); }
-
- /**
- * @brief Open gzipped file.
- * @param name File name.
- * @param mode Open mode flags (forced to contain ios::in).
- *
- * Stream will be in state good() if file opens successfully;
- * otherwise in state fail(). This differs from the behavior of
- * ifstream, which never sets the state to good() and therefore
- * won't allow you to reuse the stream for a second file unless
- * you manually clear() the state. The choice is a matter of
- * convenience.
- */
- void
- open(const char* name,
- std::ios_base::openmode mode = std::ios_base::in);
-
- /**
- * @brief Attach to already open gzipped file.
- * @param fd File descriptor.
- * @param mode Open mode flags (forced to contain ios::in).
- *
- * Stream will be in state good() if attach succeeded; otherwise
- * in state fail().
- */
- void
- attach(int fd,
- std::ios_base::openmode mode = std::ios_base::in);
-
- /**
- * @brief Close gzipped file.
- *
- * Stream will be in state fail() if close failed.
- */
- void
- close();
-
-private:
- /**
- * Underlying stream buffer.
- */
- gzfilebuf sb;
-};
-
-/*****************************************************************************/
-
-/**
- * @brief Gzipped file output stream class.
- *
- * This class implements ofstream for gzipped files. Seeking and putback
- * is not supported yet.
-*/
-class gzofstream : public std::ostream
-{
-public:
- // Default constructor
- gzofstream();
-
- /**
- * @brief Construct stream on gzipped file to be opened.
- * @param name File name.
- * @param mode Open mode flags (forced to contain ios::out).
- */
- explicit
- gzofstream(const char* name,
- std::ios_base::openmode mode = std::ios_base::out);
-
- /**
- * @brief Construct stream on already open gzipped file.
- * @param fd File descriptor.
- * @param mode Open mode flags (forced to contain ios::out).
- */
- explicit
- gzofstream(int fd,
- std::ios_base::openmode mode = std::ios_base::out);
-
- /**
- * Obtain underlying stream buffer.
- */
- gzfilebuf*
- rdbuf() const
- { return const_cast<gzfilebuf*>(&sb); }
-
- /**
- * @brief Check if file is open.
- * @return True if file is open.
- */
- bool
- is_open() { return sb.is_open(); }
-
- /**
- * @brief Open gzipped file.
- * @param name File name.
- * @param mode Open mode flags (forced to contain ios::out).
- *
- * Stream will be in state good() if file opens successfully;
- * otherwise in state fail(). This differs from the behavior of
- * ofstream, which never sets the state to good() and therefore
- * won't allow you to reuse the stream for a second file unless
- * you manually clear() the state. The choice is a matter of
- * convenience.
- */
- void
- open(const char* name,
- std::ios_base::openmode mode = std::ios_base::out);
-
- /**
- * @brief Attach to already open gzipped file.
- * @param fd File descriptor.
- * @param mode Open mode flags (forced to contain ios::out).
- *
- * Stream will be in state good() if attach succeeded; otherwise
- * in state fail().
- */
- void
- attach(int fd,
- std::ios_base::openmode mode = std::ios_base::out);
-
- /**
- * @brief Close gzipped file.
- *
- * Stream will be in state fail() if close failed.
- */
- void
- close();
-
-private:
- /**
- * Underlying stream buffer.
- */
- gzfilebuf sb;
-};
-
-/*****************************************************************************/
-
-/**
- * @brief Gzipped file output stream manipulator class.
- *
- * This class defines a two-argument manipulator for gzofstream. It is used
- * as base for the setcompression(int,int) manipulator.
-*/
-template<typename T1, typename T2>
- class gzomanip2
- {
- public:
- // Allows insertor to peek at internals
- template <typename Ta, typename Tb>
- friend gzofstream&
- operator<<(gzofstream&,
- const gzomanip2<Ta,Tb>&);
-
- // Constructor
- gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2),
- T1 v1,
- T2 v2);
- private:
- // Underlying manipulator function
- gzofstream&
- (*func)(gzofstream&, T1, T2);
-
- // Arguments for manipulator function
- T1 val1;
- T2 val2;
- };
-
-/*****************************************************************************/
-
-// Manipulator function thunks through to stream buffer
-inline gzofstream&
-setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY)
-{
- (gzs.rdbuf())->setcompression(l, s);
- return gzs;
-}
-
-// Manipulator constructor stores arguments
-template<typename T1, typename T2>
- inline
- gzomanip2<T1,T2>::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2),
- T1 v1,
- T2 v2)
- : func(f), val1(v1), val2(v2)
- { }
-
-// Insertor applies underlying manipulator function to stream
-template<typename T1, typename T2>
- inline gzofstream&
- operator<<(gzofstream& s, const gzomanip2<T1,T2>& m)
- { return (*m.func)(s, m.val1, m.val2); }
-
-// Insert this onto stream to simplify setting of compression level
-inline gzomanip2<int,int>
-setcompression(int l, int s = Z_DEFAULT_STRATEGY)
-{ return gzomanip2<int,int>(&setcompression, l, s); }
-
-#endif // ZFSTREAM_H
diff --git a/cpukit/zlib/contrib/masm686/match.asm b/cpukit/zlib/contrib/masm686/match.asm
deleted file mode 100644
index 4b03a71abd..0000000000
--- a/cpukit/zlib/contrib/masm686/match.asm
+++ /dev/null
@@ -1,413 +0,0 @@
-
-; match.asm -- Pentium-Pro optimized version of longest_match()
-;
-; Updated for zlib 1.1.3 and converted to MASM 6.1x
-; Copyright (C) 2000 Dan Higdon <hdan@kinesoft.com>
-; and Chuck Walbourn <chuckw@kinesoft.com>
-; Corrections by Cosmin Truta <cosmint@cs.ubbcluj.ro>
-;
-; This is free software; you can redistribute it and/or modify it
-; under the terms of the GNU General Public License.
-
-; Based on match.S
-; Written for zlib 1.1.2
-; Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
-;
-; Modified by Gilles Vollant (2005) for add gzhead and gzindex
-
- .686P
- .MODEL FLAT
-
-;===========================================================================
-; EQUATES
-;===========================================================================
-
-MAX_MATCH EQU 258
-MIN_MATCH EQU 3
-MIN_LOOKAHEAD EQU (MAX_MATCH + MIN_MATCH + 1)
-MAX_MATCH_8 EQU ((MAX_MATCH + 7) AND (NOT 7))
-
-;===========================================================================
-; STRUCTURES
-;===========================================================================
-
-; This STRUCT assumes a 4-byte alignment
-
-DEFLATE_STATE STRUCT
-ds_strm dd ?
-ds_status dd ?
-ds_pending_buf dd ?
-ds_pending_buf_size dd ?
-ds_pending_out dd ?
-ds_pending dd ?
-ds_wrap dd ?
-; gzhead and gzindex are added in zlib 1.2.2.2 (see deflate.h)
-ds_gzhead dd ?
-ds_gzindex dd ?
-ds_data_type db ?
-ds_method db ?
- db ? ; padding
- db ? ; padding
-ds_last_flush dd ?
-ds_w_size dd ? ; used
-ds_w_bits dd ?
-ds_w_mask dd ? ; used
-ds_window dd ? ; used
-ds_window_size dd ?
-ds_prev dd ? ; used
-ds_head dd ?
-ds_ins_h dd ?
-ds_hash_size dd ?
-ds_hash_bits dd ?
-ds_hash_mask dd ?
-ds_hash_shift dd ?
-ds_block_start dd ?
-ds_match_length dd ? ; used
-ds_prev_match dd ? ; used
-ds_match_available dd ?
-ds_strstart dd ? ; used
-ds_match_start dd ? ; used
-ds_lookahead dd ? ; used
-ds_prev_length dd ? ; used
-ds_max_chain_length dd ? ; used
-ds_max_laxy_match dd ?
-ds_level dd ?
-ds_strategy dd ?
-ds_good_match dd ? ; used
-ds_nice_match dd ? ; used
-
-; Don't need anymore of the struct for match
-DEFLATE_STATE ENDS
-
-;===========================================================================
-; CODE
-;===========================================================================
-_TEXT SEGMENT
-
-;---------------------------------------------------------------------------
-; match_init
-;---------------------------------------------------------------------------
- ALIGN 4
-PUBLIC _match_init
-_match_init PROC
- ; no initialization needed
- ret
-_match_init ENDP
-
-;---------------------------------------------------------------------------
-; uInt longest_match(deflate_state *deflatestate, IPos curmatch)
-;---------------------------------------------------------------------------
- ALIGN 4
-
-PUBLIC _longest_match
-_longest_match PROC
-
-; Since this code uses EBP for a scratch register, the stack frame must
-; be manually constructed and referenced relative to the ESP register.
-
-; Stack image
-; Variables
-chainlenwmask = 0 ; high word: current chain len
- ; low word: s->wmask
-window = 4 ; local copy of s->window
-windowbestlen = 8 ; s->window + bestlen
-scanend = 12 ; last two bytes of string
-scanstart = 16 ; first two bytes of string
-scanalign = 20 ; dword-misalignment of string
-nicematch = 24 ; a good enough match size
-bestlen = 28 ; size of best match so far
-scan = 32 ; ptr to string wanting match
-varsize = 36 ; number of bytes (also offset to last saved register)
-
-; Saved Registers (actually pushed into place)
-ebx_save = 36
-edi_save = 40
-esi_save = 44
-ebp_save = 48
-
-; Parameters
-retaddr = 52
-deflatestate = 56
-curmatch = 60
-
-; Save registers that the compiler may be using
- push ebp
- push edi
- push esi
- push ebx
-
-; Allocate local variable space
- sub esp,varsize
-
-; Retrieve the function arguments. ecx will hold cur_match
-; throughout the entire function. edx will hold the pointer to the
-; deflate_state structure during the function's setup (before
-; entering the main loop).
-
- mov edx, [esp+deflatestate]
-ASSUME edx:PTR DEFLATE_STATE
-
- mov ecx, [esp+curmatch]
-
-; uInt wmask = s->w_mask;
-; unsigned chain_length = s->max_chain_length;
-; if (s->prev_length >= s->good_match) {
-; chain_length >>= 2;
-; }
-
- mov eax, [edx].ds_prev_length
- mov ebx, [edx].ds_good_match
- cmp eax, ebx
- mov eax, [edx].ds_w_mask
- mov ebx, [edx].ds_max_chain_length
- jl SHORT LastMatchGood
- shr ebx, 2
-LastMatchGood:
-
-; chainlen is decremented once beforehand so that the function can
-; use the sign flag instead of the zero flag for the exit test.
-; It is then shifted into the high word, to make room for the wmask
-; value, which it will always accompany.
-
- dec ebx
- shl ebx, 16
- or ebx, eax
- mov [esp+chainlenwmask], ebx
-
-; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
-
- mov eax, [edx].ds_nice_match
- mov ebx, [edx].ds_lookahead
- cmp ebx, eax
- jl SHORT LookaheadLess
- mov ebx, eax
-LookaheadLess:
- mov [esp+nicematch], ebx
-
-;/* register Bytef *scan = s->window + s->strstart; */
-
- mov esi, [edx].ds_window
- mov [esp+window], esi
- mov ebp, [edx].ds_strstart
- lea edi, [esi+ebp]
- mov [esp+scan],edi
-
-;/* Determine how many bytes the scan ptr is off from being */
-;/* dword-aligned. */
-
- mov eax, edi
- neg eax
- and eax, 3
- mov [esp+scanalign], eax
-
-;/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */
-;/* s->strstart - (IPos)MAX_DIST(s) : NIL; */
-
- mov eax, [edx].ds_w_size
- sub eax, MIN_LOOKAHEAD
- sub ebp, eax
- jg SHORT LimitPositive
- xor ebp, ebp
-LimitPositive:
-
-;/* int best_len = s->prev_length; */
-
- mov eax, [edx].ds_prev_length
- mov [esp+bestlen], eax
-
-;/* Store the sum of s->window + best_len in %esi locally, and in %esi. */
-
- add esi, eax
- mov [esp+windowbestlen], esi
-
-;/* register ush scan_start = *(ushf*)scan; */
-;/* register ush scan_end = *(ushf*)(scan+best_len-1); */
-;/* Posf *prev = s->prev; */
-
- movzx ebx, WORD PTR[edi]
- mov [esp+scanstart], ebx
- movzx ebx, WORD PTR[eax+edi-1]
- mov [esp+scanend], ebx
- mov edi, [edx].ds_prev
-
-;/* Jump into the main loop. */
-
- mov edx, [esp+chainlenwmask]
- jmp SHORT LoopEntry
-
-;/* do {
-; * match = s->window + cur_match;
-; * if (*(ushf*)(match+best_len-1) != scan_end ||
-; * *(ushf*)match != scan_start) continue;
-; * [...]
-; * } while ((cur_match = prev[cur_match & wmask]) > limit
-; * && --chain_length != 0);
-; *
-; * Here is the inner loop of the function. The function will spend the
-; * majority of its time in this loop, and majority of that time will
-; * be spent in the first ten instructions.
-; *
-; * Within this loop:
-; * %ebx = scanend
-; * %ecx = curmatch
-; * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
-; * %esi = windowbestlen - i.e., (window + bestlen)
-; * %edi = prev
-; * %ebp = limit
-; */
-
- ALIGN 4
-LookupLoop:
- and ecx, edx
- movzx ecx, WORD PTR[edi+ecx*2]
- cmp ecx, ebp
- jbe LeaveNow
- sub edx, 000010000H
- js LeaveNow
-
-LoopEntry:
- movzx eax, WORD PTR[esi+ecx-1]
- cmp eax, ebx
- jnz SHORT LookupLoop
-
- mov eax, [esp+window]
- movzx eax, WORD PTR[eax+ecx]
- cmp eax, [esp+scanstart]
- jnz SHORT LookupLoop
-
-;/* Store the current value of chainlen. */
-
- mov [esp+chainlenwmask], edx
-
-;/* Point %edi to the string under scrutiny, and %esi to the string we */
-;/* are hoping to match it up with. In actuality, %esi and %edi are */
-;/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */
-;/* initialized to -(MAX_MATCH_8 - scanalign). */
-
- mov esi, [esp+window]
- mov edi, [esp+scan]
- add esi, ecx
- mov eax, [esp+scanalign]
- mov edx, -MAX_MATCH_8
- lea edi, [edi+eax+MAX_MATCH_8]
- lea esi, [esi+eax+MAX_MATCH_8]
-
-;/* Test the strings for equality, 8 bytes at a time. At the end,
-; * adjust %edx so that it is offset to the exact byte that mismatched.
-; *
-; * We already know at this point that the first three bytes of the
-; * strings match each other, and they can be safely passed over before
-; * starting the compare loop. So what this code does is skip over 0-3
-; * bytes, as much as necessary in order to dword-align the %edi
-; * pointer. (%esi will still be misaligned three times out of four.)
-; *
-; * It should be confessed that this loop usually does not represent
-; * much of the total running time. Replacing it with a more
-; * straightforward "rep cmpsb" would not drastically degrade
-; * performance.
-; */
-
-LoopCmps:
- mov eax, DWORD PTR[esi+edx]
- xor eax, DWORD PTR[edi+edx]
- jnz SHORT LeaveLoopCmps
-
- mov eax, DWORD PTR[esi+edx+4]
- xor eax, DWORD PTR[edi+edx+4]
- jnz SHORT LeaveLoopCmps4
-
- add edx, 8
- jnz SHORT LoopCmps
- jmp LenMaximum
- ALIGN 4
-
-LeaveLoopCmps4:
- add edx, 4
-
-LeaveLoopCmps:
- test eax, 00000FFFFH
- jnz SHORT LenLower
-
- add edx, 2
- shr eax, 16
-
-LenLower:
- sub al, 1
- adc edx, 0
-
-;/* Calculate the length of the match. If it is longer than MAX_MATCH, */
-;/* then automatically accept it as the best possible match and leave. */
-
- lea eax, [edi+edx]
- mov edi, [esp+scan]
- sub eax, edi
- cmp eax, MAX_MATCH
- jge SHORT LenMaximum
-
-;/* If the length of the match is not longer than the best match we */
-;/* have so far, then forget it and return to the lookup loop. */
-
- mov edx, [esp+deflatestate]
- mov ebx, [esp+bestlen]
- cmp eax, ebx
- jg SHORT LongerMatch
- mov esi, [esp+windowbestlen]
- mov edi, [edx].ds_prev
- mov ebx, [esp+scanend]
- mov edx, [esp+chainlenwmask]
- jmp LookupLoop
- ALIGN 4
-
-;/* s->match_start = cur_match; */
-;/* best_len = len; */
-;/* if (len >= nice_match) break; */
-;/* scan_end = *(ushf*)(scan+best_len-1); */
-
-LongerMatch:
- mov ebx, [esp+nicematch]
- mov [esp+bestlen], eax
- mov [edx].ds_match_start, ecx
- cmp eax, ebx
- jge SHORT LeaveNow
- mov esi, [esp+window]
- add esi, eax
- mov [esp+windowbestlen], esi
- movzx ebx, WORD PTR[edi+eax-1]
- mov edi, [edx].ds_prev
- mov [esp+scanend], ebx
- mov edx, [esp+chainlenwmask]
- jmp LookupLoop
- ALIGN 4
-
-;/* Accept the current string, with the maximum possible length. */
-
-LenMaximum:
- mov edx, [esp+deflatestate]
- mov DWORD PTR[esp+bestlen], MAX_MATCH
- mov [edx].ds_match_start, ecx
-
-;/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */
-;/* return s->lookahead; */
-
-LeaveNow:
- mov edx, [esp+deflatestate]
- mov ebx, [esp+bestlen]
- mov eax, [edx].ds_lookahead
- cmp ebx, eax
- jg SHORT LookaheadRet
- mov eax, ebx
-LookaheadRet:
-
-; Restore the stack and return from whence we came.
-
- add esp, varsize
- pop ebx
- pop esi
- pop edi
- pop ebp
- ret
-
-_longest_match ENDP
-
-_TEXT ENDS
-END
diff --git a/cpukit/zlib/contrib/masmx64/bld_ml64.bat b/cpukit/zlib/contrib/masmx64/bld_ml64.bat
deleted file mode 100644
index 8f9343d0af..0000000000
--- a/cpukit/zlib/contrib/masmx64/bld_ml64.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-ml64.exe /Flinffasx64 /c /Zi inffasx64.asm
-ml64.exe /Flgvmat64 /c /Zi gvmat64.asm
diff --git a/cpukit/zlib/contrib/masmx64/gvmat64.asm b/cpukit/zlib/contrib/masmx64/gvmat64.asm
deleted file mode 100644
index 9879c28b90..0000000000
--- a/cpukit/zlib/contrib/masmx64/gvmat64.asm
+++ /dev/null
@@ -1,553 +0,0 @@
-;uInt longest_match_x64(
-; deflate_state *s,
-; IPos cur_match); /* current match */
-
-; gvmat64.asm -- Asm portion of the optimized longest_match for 32 bits x86_64
-; (AMD64 on Athlon 64, Opteron, Phenom
-; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7)
-; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant.
-;
-; File written by Gilles Vollant, by converting to assembly the longest_match
-; from Jean-loup Gailly in deflate.c of zLib and infoZip zip.
-;
-; and by taking inspiration on asm686 with masm, optimised assembly code
-; from Brian Raiter, written 1998
-;
-; This software is provided 'as-is', without any express or implied
-; warranty. In no event will the authors be held liable for any damages
-; arising from the use of this software.
-;
-; Permission is granted to anyone to use this software for any purpose,
-; including commercial applications, and to alter it and redistribute it
-; freely, subject to the following restrictions:
-;
-; 1. The origin of this software must not be misrepresented; you must not
-; claim that you wrote the original software. If you use this software
-; in a product, an acknowledgment in the product documentation would be
-; appreciated but is not required.
-; 2. Altered source versions must be plainly marked as such, and must not be
-; misrepresented as being the original software
-; 3. This notice may not be removed or altered from any source distribution.
-;
-;
-;
-; http://www.zlib.net
-; http://www.winimage.com/zLibDll
-; http://www.muppetlabs.com/~breadbox/software/assembly.html
-;
-; to compile this file for infozip Zip, I use option:
-; ml64.exe /Flgvmat64 /c /Zi /DINFOZIP gvmat64.asm
-;
-; to compile this file for zLib, I use option:
-; ml64.exe /Flgvmat64 /c /Zi gvmat64.asm
-; Be carrefull to adapt zlib1222add below to your version of zLib
-; (if you use a version of zLib before 1.0.4 or after 1.2.2.2, change
-; value of zlib1222add later)
-;
-; This file compile with Microsoft Macro Assembler (x64) for AMD64
-;
-; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK
-;
-; (you can get Windows WDK with ml64 for AMD64 from
-; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price)
-;
-
-
-;uInt longest_match(s, cur_match)
-; deflate_state *s;
-; IPos cur_match; /* current match */
-.code
-longest_match PROC
-
-
-;LocalVarsSize equ 88
- LocalVarsSize equ 72
-
-; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12
-; free register : r14,r15
-; register can be saved : rsp
-
- chainlenwmask equ rsp + 8 - LocalVarsSize ; high word: current chain len
- ; low word: s->wmask
-;window equ rsp + xx - LocalVarsSize ; local copy of s->window ; stored in r10
-;windowbestlen equ rsp + xx - LocalVarsSize ; s->window + bestlen , use r10+r11
-;scanstart equ rsp + xx - LocalVarsSize ; first two bytes of string ; stored in r12w
-;scanend equ rsp + xx - LocalVarsSize ; last two bytes of string use ebx
-;scanalign equ rsp + xx - LocalVarsSize ; dword-misalignment of string r13
-;bestlen equ rsp + xx - LocalVarsSize ; size of best match so far -> r11d
-;scan equ rsp + xx - LocalVarsSize ; ptr to string wanting match -> r9
-IFDEF INFOZIP
-ELSE
- nicematch equ (rsp + 16 - LocalVarsSize) ; a good enough match size
-ENDIF
-
-save_rdi equ rsp + 24 - LocalVarsSize
-save_rsi equ rsp + 32 - LocalVarsSize
-save_rbx equ rsp + 40 - LocalVarsSize
-save_rbp equ rsp + 48 - LocalVarsSize
-save_r12 equ rsp + 56 - LocalVarsSize
-save_r13 equ rsp + 64 - LocalVarsSize
-;save_r14 equ rsp + 72 - LocalVarsSize
-;save_r15 equ rsp + 80 - LocalVarsSize
-
-
-; summary of register usage
-; scanend ebx
-; scanendw bx
-; chainlenwmask edx
-; curmatch rsi
-; curmatchd esi
-; windowbestlen r8
-; scanalign r9
-; scanalignd r9d
-; window r10
-; bestlen r11
-; bestlend r11d
-; scanstart r12d
-; scanstartw r12w
-; scan r13
-; nicematch r14d
-; limit r15
-; limitd r15d
-; prev rcx
-
-; all the +4 offsets are due to the addition of pending_buf_size (in zlib
-; in the deflate_state structure since the asm code was first written
-; (if you compile with zlib 1.0.4 or older, remove the +4).
-; Note : these value are good with a 8 bytes boundary pack structure
-
-
- MAX_MATCH equ 258
- MIN_MATCH equ 3
- MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
-
-
-;;; Offsets for fields in the deflate_state structure. These numbers
-;;; are calculated from the definition of deflate_state, with the
-;;; assumption that the compiler will dword-align the fields. (Thus,
-;;; changing the definition of deflate_state could easily cause this
-;;; program to crash horribly, without so much as a warning at
-;;; compile time. Sigh.)
-
-; all the +zlib1222add offsets are due to the addition of fields
-; in zlib in the deflate_state structure since the asm code was first written
-; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
-; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
-; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
-
-
-IFDEF INFOZIP
-
-_DATA SEGMENT
-COMM window_size:DWORD
-; WMask ; 7fff
-COMM window:BYTE:010040H
-COMM prev:WORD:08000H
-; MatchLen : unused
-; PrevMatch : unused
-COMM strstart:DWORD
-COMM match_start:DWORD
-; Lookahead : ignore
-COMM prev_length:DWORD ; PrevLen
-COMM max_chain_length:DWORD
-COMM good_match:DWORD
-COMM nice_match:DWORD
-prev_ad equ OFFSET prev
-window_ad equ OFFSET window
-nicematch equ nice_match
-_DATA ENDS
-WMask equ 07fffh
-
-ELSE
-
- IFNDEF zlib1222add
- zlib1222add equ 8
- ENDIF
-dsWSize equ 56+zlib1222add+(zlib1222add/2)
-dsWMask equ 64+zlib1222add+(zlib1222add/2)
-dsWindow equ 72+zlib1222add
-dsPrev equ 88+zlib1222add
-dsMatchLen equ 128+zlib1222add
-dsPrevMatch equ 132+zlib1222add
-dsStrStart equ 140+zlib1222add
-dsMatchStart equ 144+zlib1222add
-dsLookahead equ 148+zlib1222add
-dsPrevLen equ 152+zlib1222add
-dsMaxChainLen equ 156+zlib1222add
-dsGoodMatch equ 172+zlib1222add
-dsNiceMatch equ 176+zlib1222add
-
-window_size equ [ rcx + dsWSize]
-WMask equ [ rcx + dsWMask]
-window_ad equ [ rcx + dsWindow]
-prev_ad equ [ rcx + dsPrev]
-strstart equ [ rcx + dsStrStart]
-match_start equ [ rcx + dsMatchStart]
-Lookahead equ [ rcx + dsLookahead] ; 0ffffffffh on infozip
-prev_length equ [ rcx + dsPrevLen]
-max_chain_length equ [ rcx + dsMaxChainLen]
-good_match equ [ rcx + dsGoodMatch]
-nice_match equ [ rcx + dsNiceMatch]
-ENDIF
-
-; parameter 1 in r8(deflate state s), param 2 in rdx (cur match)
-
-; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and
-; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp
-;
-; All registers must be preserved across the call, except for
-; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch.
-
-
-
-;;; Save registers that the compiler may be using, and adjust esp to
-;;; make room for our stack frame.
-
-
-;;; Retrieve the function arguments. r8d will hold cur_match
-;;; throughout the entire function. edx will hold the pointer to the
-;;; deflate_state structure during the function's setup (before
-;;; entering the main loop.
-
-; parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match)
-
-; this clear high 32 bits of r8, which can be garbage in both r8 and rdx
-
- mov [save_rdi],rdi
- mov [save_rsi],rsi
- mov [save_rbx],rbx
- mov [save_rbp],rbp
-IFDEF INFOZIP
- mov r8d,ecx
-ELSE
- mov r8d,edx
-ENDIF
- mov [save_r12],r12
- mov [save_r13],r13
-; mov [save_r14],r14
-; mov [save_r15],r15
-
-
-;;; uInt wmask = s->w_mask;
-;;; unsigned chain_length = s->max_chain_length;
-;;; if (s->prev_length >= s->good_match) {
-;;; chain_length >>= 2;
-;;; }
-
- mov edi, prev_length
- mov esi, good_match
- mov eax, WMask
- mov ebx, max_chain_length
- cmp edi, esi
- jl LastMatchGood
- shr ebx, 2
-LastMatchGood:
-
-;;; chainlen is decremented once beforehand so that the function can
-;;; use the sign flag instead of the zero flag for the exit test.
-;;; It is then shifted into the high word, to make room for the wmask
-;;; value, which it will always accompany.
-
- dec ebx
- shl ebx, 16
- or ebx, eax
-
-;;; on zlib only
-;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
-
-IFDEF INFOZIP
- mov [chainlenwmask], ebx
-; on infozip nice_match = [nice_match]
-ELSE
- mov eax, nice_match
- mov [chainlenwmask], ebx
- mov r10d, Lookahead
- cmp r10d, eax
- cmovnl r10d, eax
- mov [nicematch],r10d
-ENDIF
-
-;;; register Bytef *scan = s->window + s->strstart;
- mov r10, window_ad
- mov ebp, strstart
- lea r13, [r10 + rbp]
-
-;;; Determine how many bytes the scan ptr is off from being
-;;; dword-aligned.
-
- mov r9,r13
- neg r13
- and r13,3
-
-;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
-;;; s->strstart - (IPos)MAX_DIST(s) : NIL;
-IFDEF INFOZIP
- mov eax,07efah ; MAX_DIST = (WSIZE-MIN_LOOKAHEAD) (0x8000-(3+8+1))
-ELSE
- mov eax, window_size
- sub eax, MIN_LOOKAHEAD
-ENDIF
- xor edi,edi
- sub ebp, eax
-
- mov r11d, prev_length
-
- cmovng ebp,edi
-
-;;; int best_len = s->prev_length;
-
-
-;;; Store the sum of s->window + best_len in esi locally, and in esi.
-
- lea rsi,[r10+r11]
-
-;;; register ush scan_start = *(ushf*)scan;
-;;; register ush scan_end = *(ushf*)(scan+best_len-1);
-;;; Posf *prev = s->prev;
-
- movzx r12d,word ptr [r9]
- movzx ebx, word ptr [r9 + r11 - 1]
-
- mov rdi, prev_ad
-
-;;; Jump into the main loop.
-
- mov edx, [chainlenwmask]
-
- cmp bx,word ptr [rsi + r8 - 1]
- jz LookupLoopIsZero
-
-LookupLoop1:
- and r8d, edx
-
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
-
-LoopEntry1:
- cmp bx,word ptr [rsi + r8 - 1]
- jz LookupLoopIsZero
-
-LookupLoop2:
- and r8d, edx
-
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
-
-LoopEntry2:
- cmp bx,word ptr [rsi + r8 - 1]
- jz LookupLoopIsZero
-
-LookupLoop4:
- and r8d, edx
-
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
-
-LoopEntry4:
-
- cmp bx,word ptr [rsi + r8 - 1]
- jnz LookupLoop1
- jmp LookupLoopIsZero
-
-
-;;; do {
-;;; match = s->window + cur_match;
-;;; if (*(ushf*)(match+best_len-1) != scan_end ||
-;;; *(ushf*)match != scan_start) continue;
-;;; [...]
-;;; } while ((cur_match = prev[cur_match & wmask]) > limit
-;;; && --chain_length != 0);
-;;;
-;;; Here is the inner loop of the function. The function will spend the
-;;; majority of its time in this loop, and majority of that time will
-;;; be spent in the first ten instructions.
-;;;
-;;; Within this loop:
-;;; ebx = scanend
-;;; r8d = curmatch
-;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
-;;; esi = windowbestlen - i.e., (window + bestlen)
-;;; edi = prev
-;;; ebp = limit
-
-LookupLoop:
- and r8d, edx
-
- movzx r8d, word ptr [rdi + r8*2]
- cmp r8d, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
-
-LoopEntry:
-
- cmp bx,word ptr [rsi + r8 - 1]
- jnz LookupLoop1
-LookupLoopIsZero:
- cmp r12w, word ptr [r10 + r8]
- jnz LookupLoop1
-
-
-;;; Store the current value of chainlen.
- mov [chainlenwmask], edx
-
-;;; Point edi to the string under scrutiny, and esi to the string we
-;;; are hoping to match it up with. In actuality, esi and edi are
-;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is
-;;; initialized to -(MAX_MATCH_8 - scanalign).
-
- lea rsi,[r8+r10]
- mov rdx, 0fffffffffffffef8h; -(MAX_MATCH_8)
- lea rsi, [rsi + r13 + 0108h] ;MAX_MATCH_8]
- lea rdi, [r9 + r13 + 0108h] ;MAX_MATCH_8]
-
- prefetcht1 [rsi+rdx]
- prefetcht1 [rdi+rdx]
-
-
-;;; Test the strings for equality, 8 bytes at a time. At the end,
-;;; adjust rdx so that it is offset to the exact byte that mismatched.
-;;;
-;;; We already know at this point that the first three bytes of the
-;;; strings match each other, and they can be safely passed over before
-;;; starting the compare loop. So what this code does is skip over 0-3
-;;; bytes, as much as necessary in order to dword-align the edi
-;;; pointer. (rsi will still be misaligned three times out of four.)
-;;;
-;;; It should be confessed that this loop usually does not represent
-;;; much of the total running time. Replacing it with a more
-;;; straightforward "rep cmpsb" would not drastically degrade
-;;; performance.
-
-
-LoopCmps:
- mov rax, [rsi + rdx]
- xor rax, [rdi + rdx]
- jnz LeaveLoopCmps
-
- mov rax, [rsi + rdx + 8]
- xor rax, [rdi + rdx + 8]
- jnz LeaveLoopCmps8
-
-
- mov rax, [rsi + rdx + 8+8]
- xor rax, [rdi + rdx + 8+8]
- jnz LeaveLoopCmps16
-
- add rdx,8+8+8
-
- jnz short LoopCmps
- jmp short LenMaximum
-LeaveLoopCmps16: add rdx,8
-LeaveLoopCmps8: add rdx,8
-LeaveLoopCmps:
-
- test eax, 0000FFFFh
- jnz LenLower
-
- test eax,0ffffffffh
-
- jnz LenLower32
-
- add rdx,4
- shr rax,32
- or ax,ax
- jnz LenLower
-
-LenLower32:
- shr eax,16
- add rdx,2
-LenLower: sub al, 1
- adc rdx, 0
-;;; Calculate the length of the match. If it is longer than MAX_MATCH,
-;;; then automatically accept it as the best possible match and leave.
-
- lea rax, [rdi + rdx]
- sub rax, r9
- cmp eax, MAX_MATCH
- jge LenMaximum
-
-;;; If the length of the match is not longer than the best match we
-;;; have so far, then forget it and return to the lookup loop.
-;///////////////////////////////////
-
- cmp eax, r11d
- jg LongerMatch
-
- lea rsi,[r10+r11]
-
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- jmp LookupLoop
-
-;;; s->match_start = cur_match;
-;;; best_len = len;
-;;; if (len >= nice_match) break;
-;;; scan_end = *(ushf*)(scan+best_len-1);
-
-LongerMatch:
- mov r11d, eax
- mov match_start, r8d
- cmp eax, [nicematch]
- jge LeaveNow
-
- lea rsi,[r10+rax]
-
- movzx ebx, word ptr [r9 + rax - 1]
- mov rdi, prev_ad
- mov edx, [chainlenwmask]
- jmp LookupLoop
-
-;;; Accept the current string, with the maximum possible length.
-
-LenMaximum:
- mov r11d,MAX_MATCH
- mov match_start, r8d
-
-;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
-;;; return s->lookahead;
-
-LeaveNow:
-IFDEF INFOZIP
- mov eax,r11d
-ELSE
- mov eax, Lookahead
- cmp r11d, eax
- cmovng eax, r11d
-ENDIF
-
-;;; Restore the stack and return from whence we came.
-
-
- mov rsi,[save_rsi]
- mov rdi,[save_rdi]
- mov rbx,[save_rbx]
- mov rbp,[save_rbp]
- mov r12,[save_r12]
- mov r13,[save_r13]
-; mov r14,[save_r14]
-; mov r15,[save_r15]
-
-
- ret 0
-; please don't remove this string !
-; Your can freely use gvmat64 in any free or commercial app
-; but it is far better don't remove the string in the binary!
- db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0
-longest_match ENDP
-
-match_init PROC
- ret 0
-match_init ENDP
-
-
-END
diff --git a/cpukit/zlib/contrib/masmx64/inffas8664.c b/cpukit/zlib/contrib/masmx64/inffas8664.c
deleted file mode 100644
index e8af06fa02..0000000000
--- a/cpukit/zlib/contrib/masmx64/inffas8664.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding
- * version for AMD64 on Windows using Microsoft C compiler
- *
- * Copyright (C) 1995-2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- *
- * Copyright (C) 2003 Chris Anderson <christop@charm.net>
- * Please use the copyright conditions above.
- *
- * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant
- *
- * inffas8664.c call function inffas8664fnc in inffasx64.asm
- * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c
- *
- * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also
- * slightly quicker on x86 systems because, instead of using rep movsb to copy
- * data, it uses rep movsw, which moves data in 2-byte chunks instead of single
- * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates
- * from http://fedora.linux.duke.edu/fc1_x86_64
- * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with
- * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version,
- * when decompressing mozilla-source-1.3.tar.gz.
- *
- * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
- * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at
- * the moment. I have successfully compiled and tested this code with gcc2.96,
- * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S
- * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
- * enabled. I will attempt to merge the MMX code into this version. Newer
- * versions of this and inffast.S can be found at
- * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
- *
- */
-
-#include <stdio.h>
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "inffast.h"
-
-/* Mark Adler's comments from inffast.c: */
-
-/*
- Decode literal, length, and distance codes and write out the resulting
- literal and match bytes until either not enough input or output is
- available, an end-of-block is encountered, or a data error is encountered.
- When large enough input and output buffers are supplied to inflate(), for
- example, a 16K input buffer and a 64K output buffer, more than 95% of the
- inflate execution time is spent in this routine.
-
- Entry assumptions:
-
- state->mode == LEN
- strm->avail_in >= 6
- strm->avail_out >= 258
- start >= strm->avail_out
- state->bits < 8
-
- On return, state->mode is one of:
-
- LEN -- ran out of enough output space or enough available input
- TYPE -- reached end of block code, inflate() to interpret next block
- BAD -- error in block data
-
- Notes:
-
- - The maximum input bits used by a length/distance pair is 15 bits for the
- length code, 5 bits for the length extra, 15 bits for the distance code,
- and 13 bits for the distance extra. This totals 48 bits, or six bytes.
- Therefore if strm->avail_in >= 6, then there is enough input to avoid
- checking for available input while decoding.
-
- - The maximum bytes that a single length/distance pair can output is 258
- bytes, which is the maximum length that can be coded. inflate_fast()
- requires strm->avail_out >= 258 for each loop to avoid checking for
- output space.
- */
-
-
-
- typedef struct inffast_ar {
-/* 64 32 x86 x86_64 */
-/* ar offset register */
-/* 0 0 */ void *esp; /* esp save */
-/* 8 4 */ void *ebp; /* ebp save */
-/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */
-/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */
-/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */
-/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */
-/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */
-/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */
-/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */
-/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */
-/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */
-/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */
-/* 92 48 */ unsigned wsize; /* window size */
-/* 96 52 */ unsigned write; /* window write index */
-/*100 56 */ unsigned lmask; /* r12 mask for lcode */
-/*104 60 */ unsigned dmask; /* r13 mask for dcode */
-/*108 64 */ unsigned len; /* r14 match length */
-/*112 68 */ unsigned dist; /* r15 match distance */
-/*116 72 */ unsigned status; /* set when state chng*/
- } type_ar;
-#ifdef ASMINF
-
-void inflate_fast(strm, start)
-z_streamp strm;
-unsigned start; /* inflate()'s starting value for strm->avail_out */
-{
- struct inflate_state FAR *state;
- type_ar ar;
- void inffas8664fnc(struct inffast_ar * par);
-
-
-
-#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64))
-#define PAD_AVAIL_IN 6
-#define PAD_AVAIL_OUT 258
-#else
-#define PAD_AVAIL_IN 5
-#define PAD_AVAIL_OUT 257
-#endif
-
- /* copy state to local variables */
- state = (struct inflate_state FAR *)strm->state;
-
- ar.in = strm->next_in;
- ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN);
- ar.out = strm->next_out;
- ar.beg = ar.out - (start - strm->avail_out);
- ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT);
- ar.wsize = state->wsize;
- ar.write = state->wnext;
- ar.window = state->window;
- ar.hold = state->hold;
- ar.bits = state->bits;
- ar.lcode = state->lencode;
- ar.dcode = state->distcode;
- ar.lmask = (1U << state->lenbits) - 1;
- ar.dmask = (1U << state->distbits) - 1;
-
- /* decode literals and length/distances until end-of-block or not enough
- input data or output space */
-
- /* align in on 1/2 hold size boundary */
- while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) {
- ar.hold += (unsigned long)*ar.in++ << ar.bits;
- ar.bits += 8;
- }
-
- inffas8664fnc(&ar);
-
- if (ar.status > 1) {
- if (ar.status == 2)
- strm->msg = "invalid literal/length code";
- else if (ar.status == 3)
- strm->msg = "invalid distance code";
- else
- strm->msg = "invalid distance too far back";
- state->mode = BAD;
- }
- else if ( ar.status == 1 ) {
- state->mode = TYPE;
- }
-
- /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
- ar.len = ar.bits >> 3;
- ar.in -= ar.len;
- ar.bits -= ar.len << 3;
- ar.hold &= (1U << ar.bits) - 1;
-
- /* update state and return */
- strm->next_in = ar.in;
- strm->next_out = ar.out;
- strm->avail_in = (unsigned)(ar.in < ar.last ?
- PAD_AVAIL_IN + (ar.last - ar.in) :
- PAD_AVAIL_IN - (ar.in - ar.last));
- strm->avail_out = (unsigned)(ar.out < ar.end ?
- PAD_AVAIL_OUT + (ar.end - ar.out) :
- PAD_AVAIL_OUT - (ar.out - ar.end));
- state->hold = (unsigned long)ar.hold;
- state->bits = ar.bits;
- return;
-}
-
-#endif
diff --git a/cpukit/zlib/contrib/masmx64/inffasx64.asm b/cpukit/zlib/contrib/masmx64/inffasx64.asm
deleted file mode 100644
index 60a8d89b71..0000000000
--- a/cpukit/zlib/contrib/masmx64/inffasx64.asm
+++ /dev/null
@@ -1,396 +0,0 @@
-; inffasx64.asm is a hand tuned assembler version of inffast.c - fast decoding
-; version for AMD64 on Windows using Microsoft C compiler
-;
-; inffasx64.asm is automatically convert from AMD64 portion of inffas86.c
-; inffasx64.asm is called by inffas8664.c, which contain more info.
-
-
-; to compile this file, I use option
-; ml64.exe /Flinffasx64 /c /Zi inffasx64.asm
-; with Microsoft Macro Assembler (x64) for AMD64
-;
-
-; This file compile with Microsoft Macro Assembler (x64) for AMD64
-;
-; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK
-;
-; (you can get Windows WDK with ml64 for AMD64 from
-; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price)
-;
-
-
-.code
-inffas8664fnc PROC
-
-; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and
-; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp
-;
-; All registers must be preserved across the call, except for
-; rax, rcx, rdx, r8, r-9, r10, and r11, which are scratch.
-
-
- mov [rsp-8],rsi
- mov [rsp-16],rdi
- mov [rsp-24],r12
- mov [rsp-32],r13
- mov [rsp-40],r14
- mov [rsp-48],r15
- mov [rsp-56],rbx
-
- mov rax,rcx
-
- mov [rax+8], rbp ; /* save regs rbp and rsp */
- mov [rax], rsp
-
- mov rsp, rax ; /* make rsp point to &ar */
-
- mov rsi, [rsp+16] ; /* rsi = in */
- mov rdi, [rsp+32] ; /* rdi = out */
- mov r9, [rsp+24] ; /* r9 = last */
- mov r10, [rsp+48] ; /* r10 = end */
- mov rbp, [rsp+64] ; /* rbp = lcode */
- mov r11, [rsp+72] ; /* r11 = dcode */
- mov rdx, [rsp+80] ; /* rdx = hold */
- mov ebx, [rsp+88] ; /* ebx = bits */
- mov r12d, [rsp+100] ; /* r12d = lmask */
- mov r13d, [rsp+104] ; /* r13d = dmask */
- ; /* r14d = len */
- ; /* r15d = dist */
-
-
- cld
- cmp r10, rdi
- je L_one_time ; /* if only one decode left */
- cmp r9, rsi
-
- jne L_do_loop
-
-
-L_one_time:
- mov r8, r12 ; /* r8 = lmask */
- cmp bl, 32
- ja L_get_length_code_one_time
-
- lodsd ; /* eax = *(uint *)in++ */
- mov cl, bl ; /* cl = bits, needs it for shifting */
- add bl, 32 ; /* bits += 32 */
- shl rax, cl
- or rdx, rax ; /* hold |= *((uint *)in)++ << bits */
- jmp L_get_length_code_one_time
-
-ALIGN 4
-L_while_test:
- cmp r10, rdi
- jbe L_break_loop
- cmp r9, rsi
- jbe L_break_loop
-
-L_do_loop:
- mov r8, r12 ; /* r8 = lmask */
- cmp bl, 32
- ja L_get_length_code ; /* if (32 < bits) */
-
- lodsd ; /* eax = *(uint *)in++ */
- mov cl, bl ; /* cl = bits, needs it for shifting */
- add bl, 32 ; /* bits += 32 */
- shl rax, cl
- or rdx, rax ; /* hold |= *((uint *)in)++ << bits */
-
-L_get_length_code:
- and r8, rdx ; /* r8 &= hold */
- mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */
-
- mov cl, ah ; /* cl = this.bits */
- sub bl, ah ; /* bits -= this.bits */
- shr rdx, cl ; /* hold >>= this.bits */
-
- test al, al
- jnz L_test_for_length_base ; /* if (op != 0) 45.7% */
-
- mov r8, r12 ; /* r8 = lmask */
- shr eax, 16 ; /* output this.val char */
- stosb
-
-L_get_length_code_one_time:
- and r8, rdx ; /* r8 &= hold */
- mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */
-
-L_dolen:
- mov cl, ah ; /* cl = this.bits */
- sub bl, ah ; /* bits -= this.bits */
- shr rdx, cl ; /* hold >>= this.bits */
-
- test al, al
- jnz L_test_for_length_base ; /* if (op != 0) 45.7% */
-
- shr eax, 16 ; /* output this.val char */
- stosb
- jmp L_while_test
-
-ALIGN 4
-L_test_for_length_base:
- mov r14d, eax ; /* len = this */
- shr r14d, 16 ; /* len = this.val */
- mov cl, al
-
- test al, 16
- jz L_test_for_second_level_length ; /* if ((op & 16) == 0) 8% */
- and cl, 15 ; /* op &= 15 */
- jz L_decode_distance ; /* if (!op) */
-
-L_add_bits_to_len:
- sub bl, cl
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax
- and eax, edx ; /* eax &= hold */
- shr rdx, cl
- add r14d, eax ; /* len += hold & mask[op] */
-
-L_decode_distance:
- mov r8, r13 ; /* r8 = dmask */
- cmp bl, 32
- ja L_get_distance_code ; /* if (32 < bits) */
-
- lodsd ; /* eax = *(uint *)in++ */
- mov cl, bl ; /* cl = bits, needs it for shifting */
- add bl, 32 ; /* bits += 32 */
- shl rax, cl
- or rdx, rax ; /* hold |= *((uint *)in)++ << bits */
-
-L_get_distance_code:
- and r8, rdx ; /* r8 &= hold */
- mov eax, [r11+r8*4] ; /* eax = dcode[hold & dmask] */
-
-L_dodist:
- mov r15d, eax ; /* dist = this */
- shr r15d, 16 ; /* dist = this.val */
- mov cl, ah
- sub bl, ah ; /* bits -= this.bits */
- shr rdx, cl ; /* hold >>= this.bits */
- mov cl, al ; /* cl = this.op */
-
- test al, 16 ; /* if ((op & 16) == 0) */
- jz L_test_for_second_level_dist
- and cl, 15 ; /* op &= 15 */
- jz L_check_dist_one
-
-L_add_bits_to_dist:
- sub bl, cl
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax ; /* (1 << op) - 1 */
- and eax, edx ; /* eax &= hold */
- shr rdx, cl
- add r15d, eax ; /* dist += hold & ((1 << op) - 1) */
-
-L_check_window:
- mov r8, rsi ; /* save in so from can use it's reg */
- mov rax, rdi
- sub rax, [rsp+40] ; /* nbytes = out - beg */
-
- cmp eax, r15d
- jb L_clip_window ; /* if (dist > nbytes) 4.2% */
-
- mov ecx, r14d ; /* ecx = len */
- mov rsi, rdi
- sub rsi, r15 ; /* from = out - dist */
-
- sar ecx, 1
- jnc L_copy_two ; /* if len % 2 == 0 */
-
- rep movsw
- mov al, [rsi]
- mov [rdi], al
- inc rdi
-
- mov rsi, r8 ; /* move in back to %rsi, toss from */
- jmp L_while_test
-
-L_copy_two:
- rep movsw
- mov rsi, r8 ; /* move in back to %rsi, toss from */
- jmp L_while_test
-
-ALIGN 4
-L_check_dist_one:
- cmp r15d, 1 ; /* if dist 1, is a memset */
- jne L_check_window
- cmp [rsp+40], rdi ; /* if out == beg, outside window */
- je L_check_window
-
- mov ecx, r14d ; /* ecx = len */
- mov al, [rdi-1]
- mov ah, al
-
- sar ecx, 1
- jnc L_set_two
- mov [rdi], al
- inc rdi
-
-L_set_two:
- rep stosw
- jmp L_while_test
-
-ALIGN 4
-L_test_for_second_level_length:
- test al, 64
- jnz L_test_for_end_of_block ; /* if ((op & 64) != 0) */
-
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax
- and eax, edx ; /* eax &= hold */
- add eax, r14d ; /* eax += len */
- mov eax, [rbp+rax*4] ; /* eax = lcode[val+(hold&mask[op])]*/
- jmp L_dolen
-
-ALIGN 4
-L_test_for_second_level_dist:
- test al, 64
- jnz L_invalid_distance_code ; /* if ((op & 64) != 0) */
-
- xor eax, eax
- inc eax
- shl eax, cl
- dec eax
- and eax, edx ; /* eax &= hold */
- add eax, r15d ; /* eax += dist */
- mov eax, [r11+rax*4] ; /* eax = dcode[val+(hold&mask[op])]*/
- jmp L_dodist
-
-ALIGN 4
-L_clip_window:
- mov ecx, eax ; /* ecx = nbytes */
- mov eax, [rsp+92] ; /* eax = wsize, prepare for dist cmp */
- neg ecx ; /* nbytes = -nbytes */
-
- cmp eax, r15d
- jb L_invalid_distance_too_far ; /* if (dist > wsize) */
-
- add ecx, r15d ; /* nbytes = dist - nbytes */
- cmp dword ptr [rsp+96], 0
- jne L_wrap_around_window ; /* if (write != 0) */
-
- mov rsi, [rsp+56] ; /* from = window */
- sub eax, ecx ; /* eax -= nbytes */
- add rsi, rax ; /* from += wsize - nbytes */
-
- mov eax, r14d ; /* eax = len */
- cmp r14d, ecx
- jbe L_do_copy ; /* if (nbytes >= len) */
-
- sub eax, ecx ; /* eax -= nbytes */
- rep movsb
- mov rsi, rdi
- sub rsi, r15 ; /* from = &out[ -dist ] */
- jmp L_do_copy
-
-ALIGN 4
-L_wrap_around_window:
- mov eax, [rsp+96] ; /* eax = write */
- cmp ecx, eax
- jbe L_contiguous_in_window ; /* if (write >= nbytes) */
-
- mov esi, [rsp+92] ; /* from = wsize */
- add rsi, [rsp+56] ; /* from += window */
- add rsi, rax ; /* from += write */
- sub rsi, rcx ; /* from -= nbytes */
- sub ecx, eax ; /* nbytes -= write */
-
- mov eax, r14d ; /* eax = len */
- cmp eax, ecx
- jbe L_do_copy ; /* if (nbytes >= len) */
-
- sub eax, ecx ; /* len -= nbytes */
- rep movsb
- mov rsi, [rsp+56] ; /* from = window */
- mov ecx, [rsp+96] ; /* nbytes = write */
- cmp eax, ecx
- jbe L_do_copy ; /* if (nbytes >= len) */
-
- sub eax, ecx ; /* len -= nbytes */
- rep movsb
- mov rsi, rdi
- sub rsi, r15 ; /* from = out - dist */
- jmp L_do_copy
-
-ALIGN 4
-L_contiguous_in_window:
- mov rsi, [rsp+56] ; /* rsi = window */
- add rsi, rax
- sub rsi, rcx ; /* from += write - nbytes */
-
- mov eax, r14d ; /* eax = len */
- cmp eax, ecx
- jbe L_do_copy ; /* if (nbytes >= len) */
-
- sub eax, ecx ; /* len -= nbytes */
- rep movsb
- mov rsi, rdi
- sub rsi, r15 ; /* from = out - dist */
- jmp L_do_copy ; /* if (nbytes >= len) */
-
-ALIGN 4
-L_do_copy:
- mov ecx, eax ; /* ecx = len */
- rep movsb
-
- mov rsi, r8 ; /* move in back to %esi, toss from */
- jmp L_while_test
-
-L_test_for_end_of_block:
- test al, 32
- jz L_invalid_literal_length_code
- mov dword ptr [rsp+116], 1
- jmp L_break_loop_with_status
-
-L_invalid_literal_length_code:
- mov dword ptr [rsp+116], 2
- jmp L_break_loop_with_status
-
-L_invalid_distance_code:
- mov dword ptr [rsp+116], 3
- jmp L_break_loop_with_status
-
-L_invalid_distance_too_far:
- mov dword ptr [rsp+116], 4
- jmp L_break_loop_with_status
-
-L_break_loop:
- mov dword ptr [rsp+116], 0
-
-L_break_loop_with_status:
-; /* put in, out, bits, and hold back into ar and pop esp */
- mov [rsp+16], rsi ; /* in */
- mov [rsp+32], rdi ; /* out */
- mov [rsp+88], ebx ; /* bits */
- mov [rsp+80], rdx ; /* hold */
-
- mov rax, [rsp] ; /* restore rbp and rsp */
- mov rbp, [rsp+8]
- mov rsp, rax
-
-
-
- mov rsi,[rsp-8]
- mov rdi,[rsp-16]
- mov r12,[rsp-24]
- mov r13,[rsp-32]
- mov r14,[rsp-40]
- mov r15,[rsp-48]
- mov rbx,[rsp-56]
-
- ret 0
-; :
-; : "m" (ar)
-; : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi",
-; "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
-; );
-
-inffas8664fnc ENDP
-;_TEXT ENDS
-END
diff --git a/cpukit/zlib/contrib/masmx64/inffasx64.obj b/cpukit/zlib/contrib/masmx64/inffasx64.obj
deleted file mode 100644
index 8df5d82616..0000000000
--- a/cpukit/zlib/contrib/masmx64/inffasx64.obj
+++ /dev/null
Binary files differ
diff --git a/cpukit/zlib/contrib/masmx64/readme.txt b/cpukit/zlib/contrib/masmx64/readme.txt
deleted file mode 100644
index 2da6733412..0000000000
--- a/cpukit/zlib/contrib/masmx64/readme.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-Summary
--------
-This directory contains ASM implementations of the functions
-longest_match() and inflate_fast(), for 64 bits x86 (both AMD64 and Intel EM64t),
-for use with Microsoft Macro Assembler (x64) for AMD64 and Microsoft C++ 64 bits.
-
-gvmat64.asm is written by Gilles Vollant (2005), by using Brian Raiter 686/32 bits
- assembly optimized version from Jean-loup Gailly original longest_match function
-
-inffasx64.asm and inffas8664.c were written by Chris Anderson, by optimizing
- original function from Mark Adler
-
-Use instructions
-----------------
-Assemble the .asm files using MASM and put the object files into the zlib source
-directory. You can also get object files here:
-
- http://www.winimage.com/zLibDll/zlib124_masm_obj.zip
-
-define ASMV and ASMINF in your project. Include inffas8664.c in your source tree,
-and inffasx64.obj and gvmat64.obj as object to link.
-
-
-Build instructions
-------------------
-run bld_64.bat with Microsoft Macro Assembler (x64) for AMD64 (ml64.exe)
-
-ml64.exe is given with Visual Studio 2005, Windows 2003 server DDK
-
-You can get Windows 2003 server DDK with ml64 and cl for AMD64 from
- http://www.microsoft.com/whdc/devtools/ddk/default.mspx for low price)
diff --git a/cpukit/zlib/contrib/masmx86/bld_ml32.bat b/cpukit/zlib/contrib/masmx86/bld_ml32.bat
deleted file mode 100644
index e1b86bf68a..0000000000
--- a/cpukit/zlib/contrib/masmx86/bld_ml32.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-ml /coff /Zi /c /Flmatch686.lst match686.asm
-ml /coff /Zi /c /Flinffas32.lst inffas32.asm
diff --git a/cpukit/zlib/contrib/masmx86/gvmat32.asm b/cpukit/zlib/contrib/masmx86/gvmat32.asm
deleted file mode 100644
index 874bb2d482..0000000000
--- a/cpukit/zlib/contrib/masmx86/gvmat32.asm
+++ /dev/null
@@ -1,972 +0,0 @@
-; gvmat32.asm -- Asm portion of the optimized longest_match for 32 bits x86
-; Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant.
-; File written by Gilles Vollant, by modifiying the longest_match
-; from Jean-loup Gailly in deflate.c
-;
-; http://www.zlib.net
-; http://www.winimage.com/zLibDll
-; http://www.muppetlabs.com/~breadbox/software/assembly.html
-;
-; For Visual C++ 4.x and higher and ML 6.x and higher
-; ml.exe is in directory \MASM611C of Win95 DDK
-; ml.exe is also distributed in http://www.masm32.com/masmdl.htm
-; and in VC++2003 toolkit at http://msdn.microsoft.com/visualc/vctoolkit2003/
-;
-; this file contain two implementation of longest_match
-;
-; longest_match_7fff : written 1996 by Gilles Vollant optimized for
-; first Pentium. Assume s->w_mask == 0x7fff
-; longest_match_686 : written by Brian raiter (1998), optimized for Pentium Pro
-;
-; for using an seembly version of longest_match, you need define ASMV in project
-; There is two way in using gvmat32.asm
-;
-; A) Suggested method
-; if you want include both longest_match_7fff and longest_match_686
-; compile the asm file running
-; ml /coff /Zi /Flgvmat32.lst /c gvmat32.asm
-; and include gvmat32c.c in your project
-; if you have an old cpu (386,486 or first Pentium) and s->w_mask==0x7fff,
-; longest_match_7fff will be used
-; if you have a more modern CPU (Pentium Pro, II and higher)
-; longest_match_686 will be used
-; on old cpu with s->w_mask!=0x7fff, longest_match_686 will be used,
-; but this is not a sitation you'll find often
-;
-; B) Alternative
-; if you are not interresed in old cpu performance and want the smaller
-; binaries possible
-;
-; compile the asm file running
-; ml /coff /Zi /c /Flgvmat32.lst /DNOOLDPENTIUMCODE gvmat32.asm
-; and do not include gvmat32c.c in your project (ou define also
-; NOOLDPENTIUMCODE)
-;
-; note : as I known, longest_match_686 is very faster than longest_match_7fff
-; on pentium Pro/II/III, faster (but less) in P4, but it seem
-; longest_match_7fff can be faster (very very litte) on AMD Athlon64/K8
-;
-; see below : zlib1222add must be adjuster if you use a zlib version < 1.2.2.2
-
-;uInt longest_match_7fff(s, cur_match)
-; deflate_state *s;
-; IPos cur_match; /* current match */
-
- NbStack equ 76
- cur_match equ dword ptr[esp+NbStack-0]
- str_s equ dword ptr[esp+NbStack-4]
-; 5 dword on top (ret,ebp,esi,edi,ebx)
- adrret equ dword ptr[esp+NbStack-8]
- pushebp equ dword ptr[esp+NbStack-12]
- pushedi equ dword ptr[esp+NbStack-16]
- pushesi equ dword ptr[esp+NbStack-20]
- pushebx equ dword ptr[esp+NbStack-24]
-
- chain_length equ dword ptr [esp+NbStack-28]
- limit equ dword ptr [esp+NbStack-32]
- best_len equ dword ptr [esp+NbStack-36]
- window equ dword ptr [esp+NbStack-40]
- prev equ dword ptr [esp+NbStack-44]
- scan_start equ word ptr [esp+NbStack-48]
- wmask equ dword ptr [esp+NbStack-52]
- match_start_ptr equ dword ptr [esp+NbStack-56]
- nice_match equ dword ptr [esp+NbStack-60]
- scan equ dword ptr [esp+NbStack-64]
-
- windowlen equ dword ptr [esp+NbStack-68]
- match_start equ dword ptr [esp+NbStack-72]
- strend equ dword ptr [esp+NbStack-76]
- NbStackAdd equ (NbStack-24)
-
- .386p
-
- name gvmatch
- .MODEL FLAT
-
-
-
-; all the +zlib1222add offsets are due to the addition of fields
-; in zlib in the deflate_state structure since the asm code was first written
-; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
-; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
-; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
-
- zlib1222add equ 8
-
-; Note : these value are good with a 8 bytes boundary pack structure
- dep_chain_length equ 74h+zlib1222add
- dep_window equ 30h+zlib1222add
- dep_strstart equ 64h+zlib1222add
- dep_prev_length equ 70h+zlib1222add
- dep_nice_match equ 88h+zlib1222add
- dep_w_size equ 24h+zlib1222add
- dep_prev equ 38h+zlib1222add
- dep_w_mask equ 2ch+zlib1222add
- dep_good_match equ 84h+zlib1222add
- dep_match_start equ 68h+zlib1222add
- dep_lookahead equ 6ch+zlib1222add
-
-
-_TEXT segment
-
-IFDEF NOUNDERLINE
- IFDEF NOOLDPENTIUMCODE
- public longest_match
- public match_init
- ELSE
- public longest_match_7fff
- public cpudetect32
- public longest_match_686
- ENDIF
-ELSE
- IFDEF NOOLDPENTIUMCODE
- public _longest_match
- public _match_init
- ELSE
- public _longest_match_7fff
- public _cpudetect32
- public _longest_match_686
- ENDIF
-ENDIF
-
- MAX_MATCH equ 258
- MIN_MATCH equ 3
- MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
-
-
-
-IFNDEF NOOLDPENTIUMCODE
-IFDEF NOUNDERLINE
-longest_match_7fff proc near
-ELSE
-_longest_match_7fff proc near
-ENDIF
-
- mov edx,[esp+4]
-
-
-
- push ebp
- push edi
- push esi
- push ebx
-
- sub esp,NbStackAdd
-
-; initialize or check the variables used in match.asm.
- mov ebp,edx
-
-; chain_length = s->max_chain_length
-; if (prev_length>=good_match) chain_length >>= 2
- mov edx,[ebp+dep_chain_length]
- mov ebx,[ebp+dep_prev_length]
- cmp [ebp+dep_good_match],ebx
- ja noshr
- shr edx,2
-noshr:
-; we increment chain_length because in the asm, the --chain_lenght is in the beginning of the loop
- inc edx
- mov edi,[ebp+dep_nice_match]
- mov chain_length,edx
- mov eax,[ebp+dep_lookahead]
- cmp eax,edi
-; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
- jae nolookaheadnicematch
- mov edi,eax
-nolookaheadnicematch:
-; best_len = s->prev_length
- mov best_len,ebx
-
-; window = s->window
- mov esi,[ebp+dep_window]
- mov ecx,[ebp+dep_strstart]
- mov window,esi
-
- mov nice_match,edi
-; scan = window + strstart
- add esi,ecx
- mov scan,esi
-; dx = *window
- mov dx,word ptr [esi]
-; bx = *(window+best_len-1)
- mov bx,word ptr [esi+ebx-1]
- add esi,MAX_MATCH-1
-; scan_start = *scan
- mov scan_start,dx
-; strend = scan + MAX_MATCH-1
- mov strend,esi
-; bx = scan_end = *(window+best_len-1)
-
-; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
-; s->strstart - (IPos)MAX_DIST(s) : NIL;
-
- mov esi,[ebp+dep_w_size]
- sub esi,MIN_LOOKAHEAD
-; here esi = MAX_DIST(s)
- sub ecx,esi
- ja nodist
- xor ecx,ecx
-nodist:
- mov limit,ecx
-
-; prev = s->prev
- mov edx,[ebp+dep_prev]
- mov prev,edx
-
-;
- mov edx,dword ptr [ebp+dep_match_start]
- mov bp,scan_start
- mov eax,cur_match
- mov match_start,edx
-
- mov edx,window
- mov edi,edx
- add edi,best_len
- mov esi,prev
- dec edi
-; windowlen = window + best_len -1
- mov windowlen,edi
-
- jmp beginloop2
- align 4
-
-; here, in the loop
-; eax = ax = cur_match
-; ecx = limit
-; bx = scan_end
-; bp = scan_start
-; edi = windowlen (window + best_len -1)
-; esi = prev
-
-
-;// here; chain_length <=16
-normalbeg0add16:
- add chain_length,16
- jz exitloop
-normalbeg0:
- cmp word ptr[edi+eax],bx
- je normalbeg2noroll
-rcontlabnoroll:
-; cur_match = prev[cur_match & wmask]
- and eax,7fffh
- mov ax,word ptr[esi+eax*2]
-; if cur_match > limit, go to exitloop
- cmp ecx,eax
- jnb exitloop
-; if --chain_length != 0, go to exitloop
- dec chain_length
- jnz normalbeg0
- jmp exitloop
-
-normalbeg2noroll:
-; if (scan_start==*(cur_match+window)) goto normalbeg2
- cmp bp,word ptr[edx+eax]
- jne rcontlabnoroll
- jmp normalbeg2
-
-contloop3:
- mov edi,windowlen
-
-; cur_match = prev[cur_match & wmask]
- and eax,7fffh
- mov ax,word ptr[esi+eax*2]
-; if cur_match > limit, go to exitloop
- cmp ecx,eax
-jnbexitloopshort1:
- jnb exitloop
-; if --chain_length != 0, go to exitloop
-
-
-; begin the main loop
-beginloop2:
- sub chain_length,16+1
-; if chain_length <=16, don't use the unrolled loop
- jna normalbeg0add16
-
-do16:
- cmp word ptr[edi+eax],bx
- je normalbeg2dc0
-
-maccn MACRO lab
- and eax,7fffh
- mov ax,word ptr[esi+eax*2]
- cmp ecx,eax
- jnb exitloop
- cmp word ptr[edi+eax],bx
- je lab
- ENDM
-
-rcontloop0:
- maccn normalbeg2dc1
-
-rcontloop1:
- maccn normalbeg2dc2
-
-rcontloop2:
- maccn normalbeg2dc3
-
-rcontloop3:
- maccn normalbeg2dc4
-
-rcontloop4:
- maccn normalbeg2dc5
-
-rcontloop5:
- maccn normalbeg2dc6
-
-rcontloop6:
- maccn normalbeg2dc7
-
-rcontloop7:
- maccn normalbeg2dc8
-
-rcontloop8:
- maccn normalbeg2dc9
-
-rcontloop9:
- maccn normalbeg2dc10
-
-rcontloop10:
- maccn short normalbeg2dc11
-
-rcontloop11:
- maccn short normalbeg2dc12
-
-rcontloop12:
- maccn short normalbeg2dc13
-
-rcontloop13:
- maccn short normalbeg2dc14
-
-rcontloop14:
- maccn short normalbeg2dc15
-
-rcontloop15:
- and eax,7fffh
- mov ax,word ptr[esi+eax*2]
- cmp ecx,eax
- jnb exitloop
-
- sub chain_length,16
- ja do16
- jmp normalbeg0add16
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-normbeg MACRO rcontlab,valsub
-; if we are here, we know that *(match+best_len-1) == scan_end
- cmp bp,word ptr[edx+eax]
-; if (match != scan_start) goto rcontlab
- jne rcontlab
-; calculate the good chain_length, and we'll compare scan and match string
- add chain_length,16-valsub
- jmp iseq
- ENDM
-
-
-normalbeg2dc11:
- normbeg rcontloop11,11
-
-normalbeg2dc12:
- normbeg short rcontloop12,12
-
-normalbeg2dc13:
- normbeg short rcontloop13,13
-
-normalbeg2dc14:
- normbeg short rcontloop14,14
-
-normalbeg2dc15:
- normbeg short rcontloop15,15
-
-normalbeg2dc10:
- normbeg rcontloop10,10
-
-normalbeg2dc9:
- normbeg rcontloop9,9
-
-normalbeg2dc8:
- normbeg rcontloop8,8
-
-normalbeg2dc7:
- normbeg rcontloop7,7
-
-normalbeg2dc6:
- normbeg rcontloop6,6
-
-normalbeg2dc5:
- normbeg rcontloop5,5
-
-normalbeg2dc4:
- normbeg rcontloop4,4
-
-normalbeg2dc3:
- normbeg rcontloop3,3
-
-normalbeg2dc2:
- normbeg rcontloop2,2
-
-normalbeg2dc1:
- normbeg rcontloop1,1
-
-normalbeg2dc0:
- normbeg rcontloop0,0
-
-
-; we go in normalbeg2 because *(ushf*)(match+best_len-1) == scan_end
-
-normalbeg2:
- mov edi,window
-
- cmp bp,word ptr[edi+eax]
- jne contloop3 ; if *(ushf*)match != scan_start, continue
-
-iseq:
-; if we are here, we know that *(match+best_len-1) == scan_end
-; and (match == scan_start)
-
- mov edi,edx
- mov esi,scan ; esi = scan
- add edi,eax ; edi = window + cur_match = match
-
- mov edx,[esi+3] ; compare manually dword at match+3
- xor edx,[edi+3] ; and scan +3
-
- jz begincompare ; if equal, go to long compare
-
-; we will determine the unmatch byte and calculate len (in esi)
- or dl,dl
- je eq1rr
- mov esi,3
- jmp trfinval
-eq1rr:
- or dx,dx
- je eq1
-
- mov esi,4
- jmp trfinval
-eq1:
- and edx,0ffffffh
- jz eq11
- mov esi,5
- jmp trfinval
-eq11:
- mov esi,6
- jmp trfinval
-
-begincompare:
- ; here we now scan and match begin same
- add edi,6
- add esi,6
- mov ecx,(MAX_MATCH-(2+4))/4 ; scan for at most MAX_MATCH bytes
- repe cmpsd ; loop until mismatch
-
- je trfin ; go to trfin if not unmatch
-; we determine the unmatch byte
- sub esi,4
- mov edx,[edi-4]
- xor edx,[esi]
-
- or dl,dl
- jnz trfin
- inc esi
-
- or dx,dx
- jnz trfin
- inc esi
-
- and edx,0ffffffh
- jnz trfin
- inc esi
-
-trfin:
- sub esi,scan ; esi = len
-trfinval:
-; here we have finised compare, and esi contain len of equal string
- cmp esi,best_len ; if len > best_len, go newbestlen
- ja short newbestlen
-; now we restore edx, ecx and esi, for the big loop
- mov esi,prev
- mov ecx,limit
- mov edx,window
- jmp contloop3
-
-newbestlen:
- mov best_len,esi ; len become best_len
-
- mov match_start,eax ; save new position as match_start
- cmp esi,nice_match ; if best_len >= nice_match, exit
- jae exitloop
- mov ecx,scan
- mov edx,window ; restore edx=window
- add ecx,esi
- add esi,edx
-
- dec esi
- mov windowlen,esi ; windowlen = window + best_len-1
- mov bx,[ecx-1] ; bx = *(scan+best_len-1) = scan_end
-
-; now we restore ecx and esi, for the big loop :
- mov esi,prev
- mov ecx,limit
- jmp contloop3
-
-exitloop:
-; exit : s->match_start=match_start
- mov ebx,match_start
- mov ebp,str_s
- mov ecx,best_len
- mov dword ptr [ebp+dep_match_start],ebx
- mov eax,dword ptr [ebp+dep_lookahead]
- cmp ecx,eax
- ja minexlo
- mov eax,ecx
-minexlo:
-; return min(best_len,s->lookahead)
-
-; restore stack and register ebx,esi,edi,ebp
- add esp,NbStackAdd
-
- pop ebx
- pop esi
- pop edi
- pop ebp
- ret
-InfoAuthor:
-; please don't remove this string !
-; Your are free use gvmat32 in any fre or commercial apps if you don't remove the string in the binary!
- db 0dh,0ah,"GVMat32 optimised assembly code written 1996-98 by Gilles Vollant",0dh,0ah
-
-
-
-IFDEF NOUNDERLINE
-longest_match_7fff endp
-ELSE
-_longest_match_7fff endp
-ENDIF
-
-
-IFDEF NOUNDERLINE
-cpudetect32 proc near
-ELSE
-_cpudetect32 proc near
-ENDIF
-
- push ebx
-
- pushfd ; push original EFLAGS
- pop eax ; get original EFLAGS
- mov ecx, eax ; save original EFLAGS
- xor eax, 40000h ; flip AC bit in EFLAGS
- push eax ; save new EFLAGS value on stack
- popfd ; replace current EFLAGS value
- pushfd ; get new EFLAGS
- pop eax ; store new EFLAGS in EAX
- xor eax, ecx ; can’t toggle AC bit, processor=80386
- jz end_cpu_is_386 ; jump if 80386 processor
- push ecx
- popfd ; restore AC bit in EFLAGS first
-
- pushfd
- pushfd
- pop ecx
-
- mov eax, ecx ; get original EFLAGS
- xor eax, 200000h ; flip ID bit in EFLAGS
- push eax ; save new EFLAGS value on stack
- popfd ; replace current EFLAGS value
- pushfd ; get new EFLAGS
- pop eax ; store new EFLAGS in EAX
- popfd ; restore original EFLAGS
- xor eax, ecx ; can’t toggle ID bit,
- je is_old_486 ; processor=old
-
- mov eax,1
- db 0fh,0a2h ;CPUID
-
-exitcpudetect:
- pop ebx
- ret
-
-end_cpu_is_386:
- mov eax,0300h
- jmp exitcpudetect
-
-is_old_486:
- mov eax,0400h
- jmp exitcpudetect
-
-IFDEF NOUNDERLINE
-cpudetect32 endp
-ELSE
-_cpudetect32 endp
-ENDIF
-ENDIF
-
-MAX_MATCH equ 258
-MIN_MATCH equ 3
-MIN_LOOKAHEAD equ (MAX_MATCH + MIN_MATCH + 1)
-MAX_MATCH_8_ equ ((MAX_MATCH + 7) AND 0FFF0h)
-
-
-;;; stack frame offsets
-
-chainlenwmask equ esp + 0 ; high word: current chain len
- ; low word: s->wmask
-window equ esp + 4 ; local copy of s->window
-windowbestlen equ esp + 8 ; s->window + bestlen
-scanstart equ esp + 16 ; first two bytes of string
-scanend equ esp + 12 ; last two bytes of string
-scanalign equ esp + 20 ; dword-misalignment of string
-nicematch equ esp + 24 ; a good enough match size
-bestlen equ esp + 28 ; size of best match so far
-scan equ esp + 32 ; ptr to string wanting match
-
-LocalVarsSize equ 36
-; saved ebx byte esp + 36
-; saved edi byte esp + 40
-; saved esi byte esp + 44
-; saved ebp byte esp + 48
-; return address byte esp + 52
-deflatestate equ esp + 56 ; the function arguments
-curmatch equ esp + 60
-
-;;; Offsets for fields in the deflate_state structure. These numbers
-;;; are calculated from the definition of deflate_state, with the
-;;; assumption that the compiler will dword-align the fields. (Thus,
-;;; changing the definition of deflate_state could easily cause this
-;;; program to crash horribly, without so much as a warning at
-;;; compile time. Sigh.)
-
-dsWSize equ 36+zlib1222add
-dsWMask equ 44+zlib1222add
-dsWindow equ 48+zlib1222add
-dsPrev equ 56+zlib1222add
-dsMatchLen equ 88+zlib1222add
-dsPrevMatch equ 92+zlib1222add
-dsStrStart equ 100+zlib1222add
-dsMatchStart equ 104+zlib1222add
-dsLookahead equ 108+zlib1222add
-dsPrevLen equ 112+zlib1222add
-dsMaxChainLen equ 116+zlib1222add
-dsGoodMatch equ 132+zlib1222add
-dsNiceMatch equ 136+zlib1222add
-
-
-;;; match.asm -- Pentium-Pro-optimized version of longest_match()
-;;; Written for zlib 1.1.2
-;;; Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
-;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html
-;;;
-;;; This is free software; you can redistribute it and/or modify it
-;;; under the terms of the GNU General Public License.
-
-;GLOBAL _longest_match, _match_init
-
-
-;SECTION .text
-
-;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch)
-
-;_longest_match:
-IFDEF NOOLDPENTIUMCODE
- IFDEF NOUNDERLINE
- longest_match proc near
- ELSE
- _longest_match proc near
- ENDIF
-ELSE
- IFDEF NOUNDERLINE
- longest_match_686 proc near
- ELSE
- _longest_match_686 proc near
- ENDIF
-ENDIF
-
-;;; Save registers that the compiler may be using, and adjust esp to
-;;; make room for our stack frame.
-
- push ebp
- push edi
- push esi
- push ebx
- sub esp, LocalVarsSize
-
-;;; Retrieve the function arguments. ecx will hold cur_match
-;;; throughout the entire function. edx will hold the pointer to the
-;;; deflate_state structure during the function's setup (before
-;;; entering the main loop.
-
- mov edx, [deflatestate]
- mov ecx, [curmatch]
-
-;;; uInt wmask = s->w_mask;
-;;; unsigned chain_length = s->max_chain_length;
-;;; if (s->prev_length >= s->good_match) {
-;;; chain_length >>= 2;
-;;; }
-
- mov eax, [edx + dsPrevLen]
- mov ebx, [edx + dsGoodMatch]
- cmp eax, ebx
- mov eax, [edx + dsWMask]
- mov ebx, [edx + dsMaxChainLen]
- jl LastMatchGood
- shr ebx, 2
-LastMatchGood:
-
-;;; chainlen is decremented once beforehand so that the function can
-;;; use the sign flag instead of the zero flag for the exit test.
-;;; It is then shifted into the high word, to make room for the wmask
-;;; value, which it will always accompany.
-
- dec ebx
- shl ebx, 16
- or ebx, eax
- mov [chainlenwmask], ebx
-
-;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
-
- mov eax, [edx + dsNiceMatch]
- mov ebx, [edx + dsLookahead]
- cmp ebx, eax
- jl LookaheadLess
- mov ebx, eax
-LookaheadLess: mov [nicematch], ebx
-
-;;; register Bytef *scan = s->window + s->strstart;
-
- mov esi, [edx + dsWindow]
- mov [window], esi
- mov ebp, [edx + dsStrStart]
- lea edi, [esi + ebp]
- mov [scan], edi
-
-;;; Determine how many bytes the scan ptr is off from being
-;;; dword-aligned.
-
- mov eax, edi
- neg eax
- and eax, 3
- mov [scanalign], eax
-
-;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
-;;; s->strstart - (IPos)MAX_DIST(s) : NIL;
-
- mov eax, [edx + dsWSize]
- sub eax, MIN_LOOKAHEAD
- sub ebp, eax
- jg LimitPositive
- xor ebp, ebp
-LimitPositive:
-
-;;; int best_len = s->prev_length;
-
- mov eax, [edx + dsPrevLen]
- mov [bestlen], eax
-
-;;; Store the sum of s->window + best_len in esi locally, and in esi.
-
- add esi, eax
- mov [windowbestlen], esi
-
-;;; register ush scan_start = *(ushf*)scan;
-;;; register ush scan_end = *(ushf*)(scan+best_len-1);
-;;; Posf *prev = s->prev;
-
- movzx ebx, word ptr [edi]
- mov [scanstart], ebx
- movzx ebx, word ptr [edi + eax - 1]
- mov [scanend], ebx
- mov edi, [edx + dsPrev]
-
-;;; Jump into the main loop.
-
- mov edx, [chainlenwmask]
- jmp short LoopEntry
-
-align 4
-
-;;; do {
-;;; match = s->window + cur_match;
-;;; if (*(ushf*)(match+best_len-1) != scan_end ||
-;;; *(ushf*)match != scan_start) continue;
-;;; [...]
-;;; } while ((cur_match = prev[cur_match & wmask]) > limit
-;;; && --chain_length != 0);
-;;;
-;;; Here is the inner loop of the function. The function will spend the
-;;; majority of its time in this loop, and majority of that time will
-;;; be spent in the first ten instructions.
-;;;
-;;; Within this loop:
-;;; ebx = scanend
-;;; ecx = curmatch
-;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
-;;; esi = windowbestlen - i.e., (window + bestlen)
-;;; edi = prev
-;;; ebp = limit
-
-LookupLoop:
- and ecx, edx
- movzx ecx, word ptr [edi + ecx*2]
- cmp ecx, ebp
- jbe LeaveNow
- sub edx, 00010000h
- js LeaveNow
-LoopEntry: movzx eax, word ptr [esi + ecx - 1]
- cmp eax, ebx
- jnz LookupLoop
- mov eax, [window]
- movzx eax, word ptr [eax + ecx]
- cmp eax, [scanstart]
- jnz LookupLoop
-
-;;; Store the current value of chainlen.
-
- mov [chainlenwmask], edx
-
-;;; Point edi to the string under scrutiny, and esi to the string we
-;;; are hoping to match it up with. In actuality, esi and edi are
-;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is
-;;; initialized to -(MAX_MATCH_8 - scanalign).
-
- mov esi, [window]
- mov edi, [scan]
- add esi, ecx
- mov eax, [scanalign]
- mov edx, 0fffffef8h; -(MAX_MATCH_8)
- lea edi, [edi + eax + 0108h] ;MAX_MATCH_8]
- lea esi, [esi + eax + 0108h] ;MAX_MATCH_8]
-
-;;; Test the strings for equality, 8 bytes at a time. At the end,
-;;; adjust edx so that it is offset to the exact byte that mismatched.
-;;;
-;;; We already know at this point that the first three bytes of the
-;;; strings match each other, and they can be safely passed over before
-;;; starting the compare loop. So what this code does is skip over 0-3
-;;; bytes, as much as necessary in order to dword-align the edi
-;;; pointer. (esi will still be misaligned three times out of four.)
-;;;
-;;; It should be confessed that this loop usually does not represent
-;;; much of the total running time. Replacing it with a more
-;;; straightforward "rep cmpsb" would not drastically degrade
-;;; performance.
-
-LoopCmps:
- mov eax, [esi + edx]
- xor eax, [edi + edx]
- jnz LeaveLoopCmps
- mov eax, [esi + edx + 4]
- xor eax, [edi + edx + 4]
- jnz LeaveLoopCmps4
- add edx, 8
- jnz LoopCmps
- jmp short LenMaximum
-LeaveLoopCmps4: add edx, 4
-LeaveLoopCmps: test eax, 0000FFFFh
- jnz LenLower
- add edx, 2
- shr eax, 16
-LenLower: sub al, 1
- adc edx, 0
-
-;;; Calculate the length of the match. If it is longer than MAX_MATCH,
-;;; then automatically accept it as the best possible match and leave.
-
- lea eax, [edi + edx]
- mov edi, [scan]
- sub eax, edi
- cmp eax, MAX_MATCH
- jge LenMaximum
-
-;;; If the length of the match is not longer than the best match we
-;;; have so far, then forget it and return to the lookup loop.
-
- mov edx, [deflatestate]
- mov ebx, [bestlen]
- cmp eax, ebx
- jg LongerMatch
- mov esi, [windowbestlen]
- mov edi, [edx + dsPrev]
- mov ebx, [scanend]
- mov edx, [chainlenwmask]
- jmp LookupLoop
-
-;;; s->match_start = cur_match;
-;;; best_len = len;
-;;; if (len >= nice_match) break;
-;;; scan_end = *(ushf*)(scan+best_len-1);
-
-LongerMatch: mov ebx, [nicematch]
- mov [bestlen], eax
- mov [edx + dsMatchStart], ecx
- cmp eax, ebx
- jge LeaveNow
- mov esi, [window]
- add esi, eax
- mov [windowbestlen], esi
- movzx ebx, word ptr [edi + eax - 1]
- mov edi, [edx + dsPrev]
- mov [scanend], ebx
- mov edx, [chainlenwmask]
- jmp LookupLoop
-
-;;; Accept the current string, with the maximum possible length.
-
-LenMaximum: mov edx, [deflatestate]
- mov dword ptr [bestlen], MAX_MATCH
- mov [edx + dsMatchStart], ecx
-
-;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
-;;; return s->lookahead;
-
-LeaveNow:
- mov edx, [deflatestate]
- mov ebx, [bestlen]
- mov eax, [edx + dsLookahead]
- cmp ebx, eax
- jg LookaheadRet
- mov eax, ebx
-LookaheadRet:
-
-;;; Restore the stack and return from whence we came.
-
- add esp, LocalVarsSize
- pop ebx
- pop esi
- pop edi
- pop ebp
-
- ret
-; please don't remove this string !
-; Your can freely use gvmat32 in any free or commercial app if you don't remove the string in the binary!
- db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998",0dh,0ah
-
-
-IFDEF NOOLDPENTIUMCODE
- IFDEF NOUNDERLINE
- longest_match endp
- ELSE
- _longest_match endp
- ENDIF
-
- IFDEF NOUNDERLINE
- match_init proc near
- ret
- match_init endp
- ELSE
- _match_init proc near
- ret
- _match_init endp
- ENDIF
-ELSE
- IFDEF NOUNDERLINE
- longest_match_686 endp
- ELSE
- _longest_match_686 endp
- ENDIF
-ENDIF
-
-_TEXT ends
-end
diff --git a/cpukit/zlib/contrib/masmx86/gvmat32c.c b/cpukit/zlib/contrib/masmx86/gvmat32c.c
deleted file mode 100644
index 7ad2b27943..0000000000
--- a/cpukit/zlib/contrib/masmx86/gvmat32c.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* gvmat32.c -- C portion of the optimized longest_match for 32 bits x86
- * Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant.
- * File written by Gilles Vollant, by modifiying the longest_match
- * from Jean-loup Gailly in deflate.c
- * it prepare all parameters and call the assembly longest_match_gvasm
- * longest_match execute standard C code is wmask != 0x7fff
- * (assembly code is faster with a fixed wmask)
- *
- * Read comment at beginning of gvmat32.asm for more information
- */
-
-#if defined(ASMV) && (!defined(NOOLDPENTIUMCODE))
-#include "deflate.h"
-
-/* if your C compiler don't add underline before function name,
- define ADD_UNDERLINE_ASMFUNC */
-#ifdef ADD_UNDERLINE_ASMFUNC
-#define longest_match_7fff _longest_match_7fff
-#define longest_match_686 _longest_match_686
-#define cpudetect32 _cpudetect32
-#endif
-
-
-unsigned long cpudetect32();
-
-uInt longest_match_c(
- deflate_state *s,
- IPos cur_match); /* current match */
-
-
-uInt longest_match_7fff(
- deflate_state *s,
- IPos cur_match); /* current match */
-
-uInt longest_match_686(
- deflate_state *s,
- IPos cur_match); /* current match */
-
-
-static uInt iIsPPro=2;
-
-void match_init ()
-{
- iIsPPro = (((cpudetect32()/0x100)&0xf)>=6) ? 1 : 0;
-}
-
-uInt longest_match(
- deflate_state *s,
- IPos cur_match) /* current match */
-{
- if (iIsPPro!=0)
- return longest_match_686(s,cur_match);
-
- if (s->w_mask != 0x7fff)
- return longest_match_686(s,cur_match);
-
- /* now ((s->w_mask == 0x7fff) && (iIsPPro==0)) */
- return longest_match_7fff(s,cur_match);
-}
-
-
-#endif /* defined(ASMV) && (!defined(NOOLDPENTIUMCODE)) */
diff --git a/cpukit/zlib/contrib/masmx86/inffas32.asm b/cpukit/zlib/contrib/masmx86/inffas32.asm
deleted file mode 100644
index 92ac22ad9d..0000000000
--- a/cpukit/zlib/contrib/masmx86/inffas32.asm
+++ /dev/null
@@ -1,1083 +0,0 @@
-;/* inffas32.asm is a hand tuned assembler version of inffast.c -- fast decoding
-; *
-; * inffas32.asm is derivated from inffas86.c, with translation of assembly code
-; *
-; * Copyright (C) 1995-2003 Mark Adler
-; * For conditions of distribution and use, see copyright notice in zlib.h
-; *
-; * Copyright (C) 2003 Chris Anderson <christop@charm.net>
-; * Please use the copyright conditions above.
-; *
-; * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
-; * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at
-; * the moment. I have successfully compiled and tested this code with gcc2.96,
-; * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S
-; * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
-; * enabled. I will attempt to merge the MMX code into this version. Newer
-; * versions of this and inffast.S can be found at
-; * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
-; *
-; * 2005 : modification by Gilles Vollant
-; */
-; For Visual C++ 4.x and higher and ML 6.x and higher
-; ml.exe is in directory \MASM611C of Win95 DDK
-; ml.exe is also distributed in http://www.masm32.com/masmdl.htm
-; and in VC++2003 toolkit at http://msdn.microsoft.com/visualc/vctoolkit2003/
-;
-;
-; compile with command line option
-; ml /coff /Zi /c /Flinffas32.lst inffas32.asm
-
-; if you define NO_GZIP (see inflate.h), compile with
-; ml /coff /Zi /c /Flinffas32.lst /DNO_GUNZIP inffas32.asm
-
-
-; zlib122sup is 0 fort zlib 1.2.2.1 and lower
-; zlib122sup is 8 fort zlib 1.2.2.2 and more (with addition of dmax and head
-; in inflate_state in inflate.h)
-zlib1222sup equ 8
-
-
-IFDEF GUNZIP
- INFLATE_MODE_TYPE equ 11
- INFLATE_MODE_BAD equ 26
-ELSE
- IFNDEF NO_GUNZIP
- INFLATE_MODE_TYPE equ 11
- INFLATE_MODE_BAD equ 26
- ELSE
- INFLATE_MODE_TYPE equ 3
- INFLATE_MODE_BAD equ 17
- ENDIF
-ENDIF
-
-
-; 75 "inffast.S"
-;FILE "inffast.S"
-
-;;;GLOBAL _inflate_fast
-
-;;;SECTION .text
-
-
-
- .586p
- .mmx
-
- name inflate_fast_x86
- .MODEL FLAT
-
-_DATA segment
-inflate_fast_use_mmx:
- dd 1
-
-
-_TEXT segment
-PUBLIC _inflate_fast
-
-ALIGN 4
-_inflate_fast:
- jmp inflate_fast_entry
-
-
-
-ALIGN 4
- db 'Fast decoding Code from Chris Anderson'
- db 0
-
-ALIGN 4
-invalid_literal_length_code_msg:
- db 'invalid literal/length code'
- db 0
-
-ALIGN 4
-invalid_distance_code_msg:
- db 'invalid distance code'
- db 0
-
-ALIGN 4
-invalid_distance_too_far_msg:
- db 'invalid distance too far back'
- db 0
-
-
-ALIGN 4
-inflate_fast_mask:
-dd 0
-dd 1
-dd 3
-dd 7
-dd 15
-dd 31
-dd 63
-dd 127
-dd 255
-dd 511
-dd 1023
-dd 2047
-dd 4095
-dd 8191
-dd 16383
-dd 32767
-dd 65535
-dd 131071
-dd 262143
-dd 524287
-dd 1048575
-dd 2097151
-dd 4194303
-dd 8388607
-dd 16777215
-dd 33554431
-dd 67108863
-dd 134217727
-dd 268435455
-dd 536870911
-dd 1073741823
-dd 2147483647
-dd 4294967295
-
-
-mode_state equ 0 ;/* state->mode */
-wsize_state equ (32+zlib1222sup) ;/* state->wsize */
-write_state equ (36+4+zlib1222sup) ;/* state->write */
-window_state equ (40+4+zlib1222sup) ;/* state->window */
-hold_state equ (44+4+zlib1222sup) ;/* state->hold */
-bits_state equ (48+4+zlib1222sup) ;/* state->bits */
-lencode_state equ (64+4+zlib1222sup) ;/* state->lencode */
-distcode_state equ (68+4+zlib1222sup) ;/* state->distcode */
-lenbits_state equ (72+4+zlib1222sup) ;/* state->lenbits */
-distbits_state equ (76+4+zlib1222sup) ;/* state->distbits */
-
-
-;;SECTION .text
-; 205 "inffast.S"
-;GLOBAL inflate_fast_use_mmx
-
-;SECTION .data
-
-
-; GLOBAL inflate_fast_use_mmx:object
-;.size inflate_fast_use_mmx, 4
-; 226 "inffast.S"
-;SECTION .text
-
-ALIGN 4
-inflate_fast_entry:
- push edi
- push esi
- push ebp
- push ebx
- pushfd
- sub esp,64
- cld
-
-
-
-
- mov esi, [esp+88]
- mov edi, [esi+28]
-
-
-
-
-
-
-
- mov edx, [esi+4]
- mov eax, [esi+0]
-
- add edx,eax
- sub edx,11
-
- mov [esp+44],eax
- mov [esp+20],edx
-
- mov ebp, [esp+92]
- mov ecx, [esi+16]
- mov ebx, [esi+12]
-
- sub ebp,ecx
- neg ebp
- add ebp,ebx
-
- sub ecx,257
- add ecx,ebx
-
- mov [esp+60],ebx
- mov [esp+40],ebp
- mov [esp+16],ecx
-; 285 "inffast.S"
- mov eax, [edi+lencode_state]
- mov ecx, [edi+distcode_state]
-
- mov [esp+8],eax
- mov [esp+12],ecx
-
- mov eax,1
- mov ecx, [edi+lenbits_state]
- shl eax,cl
- dec eax
- mov [esp+0],eax
-
- mov eax,1
- mov ecx, [edi+distbits_state]
- shl eax,cl
- dec eax
- mov [esp+4],eax
-
- mov eax, [edi+wsize_state]
- mov ecx, [edi+write_state]
- mov edx, [edi+window_state]
-
- mov [esp+52],eax
- mov [esp+48],ecx
- mov [esp+56],edx
-
- mov ebp, [edi+hold_state]
- mov ebx, [edi+bits_state]
-; 321 "inffast.S"
- mov esi, [esp+44]
- mov ecx, [esp+20]
- cmp ecx,esi
- ja L_align_long
-
- add ecx,11
- sub ecx,esi
- mov eax,12
- sub eax,ecx
- lea edi, [esp+28]
- rep movsb
- mov ecx,eax
- xor eax,eax
- rep stosb
- lea esi, [esp+28]
- mov [esp+20],esi
- jmp L_is_aligned
-
-
-L_align_long:
- test esi,3
- jz L_is_aligned
- xor eax,eax
- mov al, [esi]
- inc esi
- mov ecx,ebx
- add ebx,8
- shl eax,cl
- or ebp,eax
- jmp L_align_long
-
-L_is_aligned:
- mov edi, [esp+60]
-; 366 "inffast.S"
-L_check_mmx:
- cmp dword ptr [inflate_fast_use_mmx],2
- je L_init_mmx
- ja L_do_loop
-
- push eax
- push ebx
- push ecx
- push edx
- pushfd
- mov eax, [esp]
- xor dword ptr [esp],0200000h
-
-
-
-
- popfd
- pushfd
- pop edx
- xor edx,eax
- jz L_dont_use_mmx
- xor eax,eax
- cpuid
- cmp ebx,0756e6547h
- jne L_dont_use_mmx
- cmp ecx,06c65746eh
- jne L_dont_use_mmx
- cmp edx,049656e69h
- jne L_dont_use_mmx
- mov eax,1
- cpuid
- shr eax,8
- and eax,15
- cmp eax,6
- jne L_dont_use_mmx
- test edx,0800000h
- jnz L_use_mmx
- jmp L_dont_use_mmx
-L_use_mmx:
- mov dword ptr [inflate_fast_use_mmx],2
- jmp L_check_mmx_pop
-L_dont_use_mmx:
- mov dword ptr [inflate_fast_use_mmx],3
-L_check_mmx_pop:
- pop edx
- pop ecx
- pop ebx
- pop eax
- jmp L_check_mmx
-; 426 "inffast.S"
-ALIGN 4
-L_do_loop:
-; 437 "inffast.S"
- cmp bl,15
- ja L_get_length_code
-
- xor eax,eax
- lodsw
- mov cl,bl
- add bl,16
- shl eax,cl
- or ebp,eax
-
-L_get_length_code:
- mov edx, [esp+0]
- mov ecx, [esp+8]
- and edx,ebp
- mov eax, [ecx+edx*4]
-
-L_dolen:
-
-
-
-
-
-
- mov cl,ah
- sub bl,ah
- shr ebp,cl
-
-
-
-
-
-
- test al,al
- jnz L_test_for_length_base
-
- shr eax,16
- stosb
-
-L_while_test:
-
-
- cmp [esp+16],edi
- jbe L_break_loop
-
- cmp [esp+20],esi
- ja L_do_loop
- jmp L_break_loop
-
-L_test_for_length_base:
-; 502 "inffast.S"
- mov edx,eax
- shr edx,16
- mov cl,al
-
- test al,16
- jz L_test_for_second_level_length
- and cl,15
- jz L_save_len
- cmp bl,cl
- jae L_add_bits_to_len
-
- mov ch,cl
- xor eax,eax
- lodsw
- mov cl,bl
- add bl,16
- shl eax,cl
- or ebp,eax
- mov cl,ch
-
-L_add_bits_to_len:
- mov eax,1
- shl eax,cl
- dec eax
- sub bl,cl
- and eax,ebp
- shr ebp,cl
- add edx,eax
-
-L_save_len:
- mov [esp+24],edx
-
-
-L_decode_distance:
-; 549 "inffast.S"
- cmp bl,15
- ja L_get_distance_code
-
- xor eax,eax
- lodsw
- mov cl,bl
- add bl,16
- shl eax,cl
- or ebp,eax
-
-L_get_distance_code:
- mov edx, [esp+4]
- mov ecx, [esp+12]
- and edx,ebp
- mov eax, [ecx+edx*4]
-
-
-L_dodist:
- mov edx,eax
- shr edx,16
- mov cl,ah
- sub bl,ah
- shr ebp,cl
-; 584 "inffast.S"
- mov cl,al
-
- test al,16
- jz L_test_for_second_level_dist
- and cl,15
- jz L_check_dist_one
- cmp bl,cl
- jae L_add_bits_to_dist
-
- mov ch,cl
- xor eax,eax
- lodsw
- mov cl,bl
- add bl,16
- shl eax,cl
- or ebp,eax
- mov cl,ch
-
-L_add_bits_to_dist:
- mov eax,1
- shl eax,cl
- dec eax
- sub bl,cl
- and eax,ebp
- shr ebp,cl
- add edx,eax
- jmp L_check_window
-
-L_check_window:
-; 625 "inffast.S"
- mov [esp+44],esi
- mov eax,edi
- sub eax, [esp+40]
-
- cmp eax,edx
- jb L_clip_window
-
- mov ecx, [esp+24]
- mov esi,edi
- sub esi,edx
-
- sub ecx,3
- mov al, [esi]
- mov [edi],al
- mov al, [esi+1]
- mov dl, [esi+2]
- add esi,3
- mov [edi+1],al
- mov [edi+2],dl
- add edi,3
- rep movsb
-
- mov esi, [esp+44]
- jmp L_while_test
-
-ALIGN 4
-L_check_dist_one:
- cmp edx,1
- jne L_check_window
- cmp [esp+40],edi
- je L_check_window
-
- dec edi
- mov ecx, [esp+24]
- mov al, [edi]
- sub ecx,3
-
- mov [edi+1],al
- mov [edi+2],al
- mov [edi+3],al
- add edi,4
- rep stosb
-
- jmp L_while_test
-
-ALIGN 4
-L_test_for_second_level_length:
-
-
-
-
- test al,64
- jnz L_test_for_end_of_block
-
- mov eax,1
- shl eax,cl
- dec eax
- and eax,ebp
- add eax,edx
- mov edx, [esp+8]
- mov eax, [edx+eax*4]
- jmp L_dolen
-
-ALIGN 4
-L_test_for_second_level_dist:
-
-
-
-
- test al,64
- jnz L_invalid_distance_code
-
- mov eax,1
- shl eax,cl
- dec eax
- and eax,ebp
- add eax,edx
- mov edx, [esp+12]
- mov eax, [edx+eax*4]
- jmp L_dodist
-
-ALIGN 4
-L_clip_window:
-; 721 "inffast.S"
- mov ecx,eax
- mov eax, [esp+52]
- neg ecx
- mov esi, [esp+56]
-
- cmp eax,edx
- jb L_invalid_distance_too_far
-
- add ecx,edx
- cmp dword ptr [esp+48],0
- jne L_wrap_around_window
-
- sub eax,ecx
- add esi,eax
-; 749 "inffast.S"
- mov eax, [esp+24]
- cmp eax,ecx
- jbe L_do_copy1
-
- sub eax,ecx
- rep movsb
- mov esi,edi
- sub esi,edx
- jmp L_do_copy1
-
- cmp eax,ecx
- jbe L_do_copy1
-
- sub eax,ecx
- rep movsb
- mov esi,edi
- sub esi,edx
- jmp L_do_copy1
-
-L_wrap_around_window:
-; 793 "inffast.S"
- mov eax, [esp+48]
- cmp ecx,eax
- jbe L_contiguous_in_window
-
- add esi, [esp+52]
- add esi,eax
- sub esi,ecx
- sub ecx,eax
-
-
- mov eax, [esp+24]
- cmp eax,ecx
- jbe L_do_copy1
-
- sub eax,ecx
- rep movsb
- mov esi, [esp+56]
- mov ecx, [esp+48]
- cmp eax,ecx
- jbe L_do_copy1
-
- sub eax,ecx
- rep movsb
- mov esi,edi
- sub esi,edx
- jmp L_do_copy1
-
-L_contiguous_in_window:
-; 836 "inffast.S"
- add esi,eax
- sub esi,ecx
-
-
- mov eax, [esp+24]
- cmp eax,ecx
- jbe L_do_copy1
-
- sub eax,ecx
- rep movsb
- mov esi,edi
- sub esi,edx
-
-L_do_copy1:
-; 862 "inffast.S"
- mov ecx,eax
- rep movsb
-
- mov esi, [esp+44]
- jmp L_while_test
-; 878 "inffast.S"
-ALIGN 4
-L_init_mmx:
- emms
-
-
-
-
-
- movd mm0,ebp
- mov ebp,ebx
-; 896 "inffast.S"
- movd mm4,dword ptr [esp+0]
- movq mm3,mm4
- movd mm5,dword ptr [esp+4]
- movq mm2,mm5
- pxor mm1,mm1
- mov ebx, [esp+8]
- jmp L_do_loop_mmx
-
-ALIGN 4
-L_do_loop_mmx:
- psrlq mm0,mm1
-
- cmp ebp,32
- ja L_get_length_code_mmx
-
- movd mm6,ebp
- movd mm7,dword ptr [esi]
- add esi,4
- psllq mm7,mm6
- add ebp,32
- por mm0,mm7
-
-L_get_length_code_mmx:
- pand mm4,mm0
- movd eax,mm4
- movq mm4,mm3
- mov eax, [ebx+eax*4]
-
-L_dolen_mmx:
- movzx ecx,ah
- movd mm1,ecx
- sub ebp,ecx
-
- test al,al
- jnz L_test_for_length_base_mmx
-
- shr eax,16
- stosb
-
-L_while_test_mmx:
-
-
- cmp [esp+16],edi
- jbe L_break_loop
-
- cmp [esp+20],esi
- ja L_do_loop_mmx
- jmp L_break_loop
-
-L_test_for_length_base_mmx:
-
- mov edx,eax
- shr edx,16
-
- test al,16
- jz L_test_for_second_level_length_mmx
- and eax,15
- jz L_decode_distance_mmx
-
- psrlq mm0,mm1
- movd mm1,eax
- movd ecx,mm0
- sub ebp,eax
- and ecx, [inflate_fast_mask+eax*4]
- add edx,ecx
-
-L_decode_distance_mmx:
- psrlq mm0,mm1
-
- cmp ebp,32
- ja L_get_dist_code_mmx
-
- movd mm6,ebp
- movd mm7,dword ptr [esi]
- add esi,4
- psllq mm7,mm6
- add ebp,32
- por mm0,mm7
-
-L_get_dist_code_mmx:
- mov ebx, [esp+12]
- pand mm5,mm0
- movd eax,mm5
- movq mm5,mm2
- mov eax, [ebx+eax*4]
-
-L_dodist_mmx:
-
- movzx ecx,ah
- mov ebx,eax
- shr ebx,16
- sub ebp,ecx
- movd mm1,ecx
-
- test al,16
- jz L_test_for_second_level_dist_mmx
- and eax,15
- jz L_check_dist_one_mmx
-
-L_add_bits_to_dist_mmx:
- psrlq mm0,mm1
- movd mm1,eax
- movd ecx,mm0
- sub ebp,eax
- and ecx, [inflate_fast_mask+eax*4]
- add ebx,ecx
-
-L_check_window_mmx:
- mov [esp+44],esi
- mov eax,edi
- sub eax, [esp+40]
-
- cmp eax,ebx
- jb L_clip_window_mmx
-
- mov ecx,edx
- mov esi,edi
- sub esi,ebx
-
- sub ecx,3
- mov al, [esi]
- mov [edi],al
- mov al, [esi+1]
- mov dl, [esi+2]
- add esi,3
- mov [edi+1],al
- mov [edi+2],dl
- add edi,3
- rep movsb
-
- mov esi, [esp+44]
- mov ebx, [esp+8]
- jmp L_while_test_mmx
-
-ALIGN 4
-L_check_dist_one_mmx:
- cmp ebx,1
- jne L_check_window_mmx
- cmp [esp+40],edi
- je L_check_window_mmx
-
- dec edi
- mov ecx,edx
- mov al, [edi]
- sub ecx,3
-
- mov [edi+1],al
- mov [edi+2],al
- mov [edi+3],al
- add edi,4
- rep stosb
-
- mov ebx, [esp+8]
- jmp L_while_test_mmx
-
-ALIGN 4
-L_test_for_second_level_length_mmx:
- test al,64
- jnz L_test_for_end_of_block
-
- and eax,15
- psrlq mm0,mm1
- movd ecx,mm0
- and ecx, [inflate_fast_mask+eax*4]
- add ecx,edx
- mov eax, [ebx+ecx*4]
- jmp L_dolen_mmx
-
-ALIGN 4
-L_test_for_second_level_dist_mmx:
- test al,64
- jnz L_invalid_distance_code
-
- and eax,15
- psrlq mm0,mm1
- movd ecx,mm0
- and ecx, [inflate_fast_mask+eax*4]
- mov eax, [esp+12]
- add ecx,ebx
- mov eax, [eax+ecx*4]
- jmp L_dodist_mmx
-
-ALIGN 4
-L_clip_window_mmx:
-
- mov ecx,eax
- mov eax, [esp+52]
- neg ecx
- mov esi, [esp+56]
-
- cmp eax,ebx
- jb L_invalid_distance_too_far
-
- add ecx,ebx
- cmp dword ptr [esp+48],0
- jne L_wrap_around_window_mmx
-
- sub eax,ecx
- add esi,eax
-
- cmp edx,ecx
- jbe L_do_copy1_mmx
-
- sub edx,ecx
- rep movsb
- mov esi,edi
- sub esi,ebx
- jmp L_do_copy1_mmx
-
- cmp edx,ecx
- jbe L_do_copy1_mmx
-
- sub edx,ecx
- rep movsb
- mov esi,edi
- sub esi,ebx
- jmp L_do_copy1_mmx
-
-L_wrap_around_window_mmx:
-
- mov eax, [esp+48]
- cmp ecx,eax
- jbe L_contiguous_in_window_mmx
-
- add esi, [esp+52]
- add esi,eax
- sub esi,ecx
- sub ecx,eax
-
-
- cmp edx,ecx
- jbe L_do_copy1_mmx
-
- sub edx,ecx
- rep movsb
- mov esi, [esp+56]
- mov ecx, [esp+48]
- cmp edx,ecx
- jbe L_do_copy1_mmx
-
- sub edx,ecx
- rep movsb
- mov esi,edi
- sub esi,ebx
- jmp L_do_copy1_mmx
-
-L_contiguous_in_window_mmx:
-
- add esi,eax
- sub esi,ecx
-
-
- cmp edx,ecx
- jbe L_do_copy1_mmx
-
- sub edx,ecx
- rep movsb
- mov esi,edi
- sub esi,ebx
-
-L_do_copy1_mmx:
-
-
- mov ecx,edx
- rep movsb
-
- mov esi, [esp+44]
- mov ebx, [esp+8]
- jmp L_while_test_mmx
-; 1174 "inffast.S"
-L_invalid_distance_code:
-
-
-
-
-
- mov ecx, invalid_distance_code_msg
- mov edx,INFLATE_MODE_BAD
- jmp L_update_stream_state
-
-L_test_for_end_of_block:
-
-
-
-
-
- test al,32
- jz L_invalid_literal_length_code
-
- mov ecx,0
- mov edx,INFLATE_MODE_TYPE
- jmp L_update_stream_state
-
-L_invalid_literal_length_code:
-
-
-
-
-
- mov ecx, invalid_literal_length_code_msg
- mov edx,INFLATE_MODE_BAD
- jmp L_update_stream_state
-
-L_invalid_distance_too_far:
-
-
-
- mov esi, [esp+44]
- mov ecx, invalid_distance_too_far_msg
- mov edx,INFLATE_MODE_BAD
- jmp L_update_stream_state
-
-L_update_stream_state:
-
- mov eax, [esp+88]
- test ecx,ecx
- jz L_skip_msg
- mov [eax+24],ecx
-L_skip_msg:
- mov eax, [eax+28]
- mov [eax+mode_state],edx
- jmp L_break_loop
-
-ALIGN 4
-L_break_loop:
-; 1243 "inffast.S"
- cmp dword ptr [inflate_fast_use_mmx],2
- jne L_update_next_in
-
-
-
- mov ebx,ebp
-
-L_update_next_in:
-; 1266 "inffast.S"
- mov eax, [esp+88]
- mov ecx,ebx
- mov edx, [eax+28]
- shr ecx,3
- sub esi,ecx
- shl ecx,3
- sub ebx,ecx
- mov [eax+12],edi
- mov [edx+bits_state],ebx
- mov ecx,ebx
-
- lea ebx, [esp+28]
- cmp [esp+20],ebx
- jne L_buf_not_used
-
- sub esi,ebx
- mov ebx, [eax+0]
- mov [esp+20],ebx
- add esi,ebx
- mov ebx, [eax+4]
- sub ebx,11
- add [esp+20],ebx
-
-L_buf_not_used:
- mov [eax+0],esi
-
- mov ebx,1
- shl ebx,cl
- dec ebx
-
-
-
-
-
- cmp dword ptr [inflate_fast_use_mmx],2
- jne L_update_hold
-
-
-
- psrlq mm0,mm1
- movd ebp,mm0
-
- emms
-
-L_update_hold:
-
-
-
- and ebp,ebx
- mov [edx+hold_state],ebp
-
-
-
-
- mov ebx, [esp+20]
- cmp ebx,esi
- jbe L_last_is_smaller
-
- sub ebx,esi
- add ebx,11
- mov [eax+4],ebx
- jmp L_fixup_out
-L_last_is_smaller:
- sub esi,ebx
- neg esi
- add esi,11
- mov [eax+4],esi
-
-
-
-
-L_fixup_out:
-
- mov ebx, [esp+16]
- cmp ebx,edi
- jbe L_end_is_smaller
-
- sub ebx,edi
- add ebx,257
- mov [eax+16],ebx
- jmp L_done
-L_end_is_smaller:
- sub edi,ebx
- neg edi
- add edi,257
- mov [eax+16],edi
-
-
-
-
-
-L_done:
- add esp,64
- popfd
- pop ebx
- pop ebp
- pop esi
- pop edi
- ret
-
-_TEXT ends
-end
diff --git a/cpukit/zlib/contrib/masmx86/mkasm.bat b/cpukit/zlib/contrib/masmx86/mkasm.bat
deleted file mode 100755
index 70a51f8377..0000000000
--- a/cpukit/zlib/contrib/masmx86/mkasm.bat
+++ /dev/null
@@ -1,3 +0,0 @@
-cl /DASMV /I..\.. /O2 /c gvmat32c.c
-ml /coff /Zi /c /Flgvmat32.lst gvmat32.asm
-ml /coff /Zi /c /Flinffas32.lst inffas32.asm
diff --git a/cpukit/zlib/contrib/masmx86/readme.txt b/cpukit/zlib/contrib/masmx86/readme.txt
deleted file mode 100644
index 3271f720a1..0000000000
--- a/cpukit/zlib/contrib/masmx86/readme.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-
-Summary
--------
-This directory contains ASM implementations of the functions
-longest_match() and inflate_fast().
-
-
-Use instructions
-----------------
-Assemble using MASM, and copy the object files into the zlib source
-directory, then run the appropriate makefile, as suggested below. You can
-donwload MASM from here:
-
- http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64
-
-You can also get objects files here:
-
- http://www.winimage.com/zLibDll/zlib124_masm_obj.zip
-
-Build instructions
-------------------
-* With Microsoft C and MASM:
-nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj"
-
-* With Borland C and TASM:
-make -f win32/Makefile.bor LOCAL_ZLIB="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" OBJPA="+match686c.obj+match686.obj+inffas32.obj"
-
diff --git a/cpukit/zlib/contrib/minizip/ChangeLogUnzip b/cpukit/zlib/contrib/minizip/ChangeLogUnzip
deleted file mode 100644
index 50ca6a9e0f..0000000000
--- a/cpukit/zlib/contrib/minizip/ChangeLogUnzip
+++ /dev/null
@@ -1,67 +0,0 @@
-Change in 1.01e (12 feb 05)
-- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
-- Fix possible memory leak in unzip.c (Zoran Stevanovic)
-
-Change in 1.01b (20 may 04)
-- Integrate patch from Debian package (submited by Mark Brown)
-- Add tools mztools from Xavier Roche
-
-Change in 1.01 (8 may 04)
-- fix buffer overrun risk in unzip.c (Xavier Roche)
-- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
-
-Change in 1.00: (10 sept 03)
-- rename to 1.00
-- cosmetic code change
-
-Change in 0.22: (19 May 03)
-- crypting support (unless you define NOCRYPT)
-- append file in existing zipfile
-
-Change in 0.21: (10 Mar 03)
-- bug fixes
-
-Change in 0.17: (27 Jan 02)
-- bug fixes
-
-Change in 0.16: (19 Jan 02)
-- Support of ioapi for virtualize zip file access
-
-Change in 0.15: (19 Mar 98)
-- fix memory leak in minizip.c
-
-Change in 0.14: (10 Mar 98)
-- fix bugs in minizip.c sample for zipping big file
-- fix problem in month in date handling
-- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
- comment handling
-
-Change in 0.13: (6 Mar 98)
-- fix bugs in zip.c
-- add real minizip sample
-
-Change in 0.12: (4 Mar 98)
-- add zip.c and zip.h for creates .zip file
-- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
-- fix miniunz.c for file without specific record for directory
-
-Change in 0.11: (3 Mar 98)
-- fix bug in unzGetCurrentFileInfo for get extra field and comment
-- enhance miniunz sample, remove the bad unztst.c sample
-
-Change in 0.10: (2 Mar 98)
-- fix bug in unzReadCurrentFile
-- rename unzip* to unz* function and structure
-- remove Windows-like hungary notation variable name
-- modify some structure in unzip.h
-- add somes comment in source
-- remove unzipGetcCurrentFile function
-- replace ZUNZEXPORT by ZEXPORT
-- add unzGetLocalExtrafield for get the local extrafield info
-- add a new sample, miniunz.c
-
-Change in 0.4: (25 Feb 98)
-- suppress the type unzipFileInZip.
- Only on file in the zipfile can be open at the same time
-- fix somes typo in code
-- added tm_unz structure in unzip_file_info (date/time in readable format)
diff --git a/cpukit/zlib/contrib/minizip/Makefile b/cpukit/zlib/contrib/minizip/Makefile
deleted file mode 100644
index 84eaad20d4..0000000000
--- a/cpukit/zlib/contrib/minizip/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-CC=cc
-CFLAGS=-O -I../..
-
-UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
-ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
-
-.c.o:
- $(CC) -c $(CFLAGS) $*.c
-
-all: miniunz minizip
-
-miniunz: $(UNZ_OBJS)
- $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
-
-minizip: $(ZIP_OBJS)
- $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
-
-test: miniunz minizip
- ./minizip test readme.txt
- ./miniunz -l test.zip
- mv readme.txt readme.old
- ./miniunz test.zip
-
-clean:
- /bin/rm -f *.o *~ minizip miniunz
diff --git a/cpukit/zlib/contrib/minizip/crypt.h b/cpukit/zlib/contrib/minizip/crypt.h
deleted file mode 100644
index a01d08d932..0000000000
--- a/cpukit/zlib/contrib/minizip/crypt.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/* crypt.h -- base code for crypt/uncrypt ZIPfile
-
-
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-
- This code is a modified version of crypting code in Infozip distribution
-
- The encryption/decryption parts of this source code (as opposed to the
- non-echoing password parts) were originally written in Europe. The
- whole source package can be freely distributed, including from the USA.
- (Prior to January 2000, re-export from the US was a violation of US law.)
-
- This encryption code is a direct transcription of the algorithm from
- Roger Schlafly, described by Phil Katz in the file appnote.txt. This
- file (appnote.txt) is distributed with the PKZIP program (even in the
- version without encryption capabilities).
-
- If you don't need crypting in your application, just define symbols
- NOCRYPT and NOUNCRYPT.
-
- This code support the "Traditional PKWARE Encryption".
-
- The new AES encryption added on Zip format by Winzip (see the page
- http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
- Encryption is not supported.
-*/
-
-#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
-
-/***********************************************************************
- * Return the next byte in the pseudo-random sequence
- */
-static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
-{
- unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
- * unpredictable manner on 16-bit systems; not a problem
- * with any known compiler so far, though */
-
- temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
- return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
-}
-
-/***********************************************************************
- * Update the encryption keys with the next byte of plain text
- */
-static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
-{
- (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
- (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
- (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
- {
- register int keyshift = (int)((*(pkeys+1)) >> 24);
- (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
- }
- return c;
-}
-
-
-/***********************************************************************
- * Initialize the encryption keys and the random header according to
- * the given password.
- */
-static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
-{
- *(pkeys+0) = 305419896L;
- *(pkeys+1) = 591751049L;
- *(pkeys+2) = 878082192L;
- while (*passwd != '\0') {
- update_keys(pkeys,pcrc_32_tab,(int)*passwd);
- passwd++;
- }
-}
-
-#define zdecode(pkeys,pcrc_32_tab,c) \
- (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
-
-#define zencode(pkeys,pcrc_32_tab,c,t) \
- (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
-
-#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-
-#define RAND_HEAD_LEN 12
- /* "last resort" source for second part of crypt seed pattern */
-# ifndef ZCR_SEED2
-# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
-# endif
-
-static int crypthead(const char* passwd, /* password string */
- unsigned char* buf, /* where to write header */
- int bufSize,
- unsigned long* pkeys,
- const unsigned long* pcrc_32_tab,
- unsigned long crcForCrypting)
-{
- int n; /* index in random header */
- int t; /* temporary */
- int c; /* random byte */
- unsigned char header[RAND_HEAD_LEN-2]; /* random header */
- static unsigned calls = 0; /* ensure different random header each time */
-
- if (bufSize<RAND_HEAD_LEN)
- return 0;
-
- /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
- * output of rand() to get less predictability, since rand() is
- * often poorly implemented.
- */
- if (++calls == 1)
- {
- srand((unsigned)(time(NULL) ^ ZCR_SEED2));
- }
- init_keys(passwd, pkeys, pcrc_32_tab);
- for (n = 0; n < RAND_HEAD_LEN-2; n++)
- {
- c = (rand() >> 7) & 0xff;
- header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
- }
- /* Encrypt random header (last two bytes is high word of crc) */
- init_keys(passwd, pkeys, pcrc_32_tab);
- for (n = 0; n < RAND_HEAD_LEN-2; n++)
- {
- buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
- }
- buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
- buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
- return n;
-}
-
-#endif
diff --git a/cpukit/zlib/contrib/minizip/ioapi.c b/cpukit/zlib/contrib/minizip/ioapi.c
deleted file mode 100644
index 49958f61ff..0000000000
--- a/cpukit/zlib/contrib/minizip/ioapi.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-*/
-
-#if (defined(_WIN32))
- #define _CRT_SECURE_NO_WARNINGS
-#endif
-
-#include "ioapi.h"
-
-voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
-{
- if (pfilefunc->zfile_func64.zopen64_file != NULL)
- return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
- else
- {
- return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
- }
-}
-
-long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
-{
- if (pfilefunc->zfile_func64.zseek64_file != NULL)
- return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
- else
- {
- uLong offsetTruncated = (uLong)offset;
- if (offsetTruncated != offset)
- return -1;
- else
- return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
- }
-}
-
-ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
-{
- if (pfilefunc->zfile_func64.zseek64_file != NULL)
- return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
- else
- {
- uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
- if ((tell_uLong) == ((uLong)-1))
- return (ZPOS64_T)-1;
- else
- return tell_uLong;
- }
-}
-
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
-{
- p_filefunc64_32->zfile_func64.zopen64_file = NULL;
- p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
- p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
- p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
- p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
- p_filefunc64_32->zfile_func64.ztell64_file = NULL;
- p_filefunc64_32->zfile_func64.zseek64_file = NULL;
- p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
- p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
- p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
- p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
- p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
-}
-
-
-
-static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
-static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
-static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
-static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
-static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
-
-static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
-{
- FILE* file = NULL;
- const char* mode_fopen = NULL;
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- mode_fopen = "rb";
- else
- if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- mode_fopen = "r+b";
- else
- if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- mode_fopen = "wb";
-
- if ((filename!=NULL) && (mode_fopen != NULL))
- file = fopen(filename, mode_fopen);
- return file;
-}
-
-static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
-{
- FILE* file = NULL;
- const char* mode_fopen = NULL;
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- mode_fopen = "rb";
- else
- if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- mode_fopen = "r+b";
- else
- if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- mode_fopen = "wb";
-
- if ((filename!=NULL) && (mode_fopen != NULL))
- file = fopen64((const char*)filename, mode_fopen);
- return file;
-}
-
-
-static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
-{
- uLong ret;
- ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
- return ret;
-}
-
-static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
-{
- uLong ret;
- ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
- return ret;
-}
-
-static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
-{
- long ret;
- ret = ftell((FILE *)stream);
- return ret;
-}
-
-
-static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
-{
- ZPOS64_T ret;
- ret = ftello64((FILE *)stream);
- return ret;
-}
-
-static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
-{
- int fseek_origin=0;
- long ret;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- fseek_origin = SEEK_CUR;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- fseek_origin = SEEK_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- fseek_origin = SEEK_SET;
- break;
- default: return -1;
- }
- ret = 0;
- if (fseek((FILE *)stream, offset, fseek_origin) != 0)
- ret = -1;
- return ret;
-}
-
-static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
-{
- int fseek_origin=0;
- long ret;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- fseek_origin = SEEK_CUR;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- fseek_origin = SEEK_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- fseek_origin = SEEK_SET;
- break;
- default: return -1;
- }
- ret = 0;
-
- if(fseeko64((FILE *)stream, offset, fseek_origin) != 0)
- ret = -1;
-
- return ret;
-}
-
-
-static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
-{
- int ret;
- ret = fclose((FILE *)stream);
- return ret;
-}
-
-static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
-{
- int ret;
- ret = ferror((FILE *)stream);
- return ret;
-}
-
-void fill_fopen_filefunc (pzlib_filefunc_def)
- zlib_filefunc_def* pzlib_filefunc_def;
-{
- pzlib_filefunc_def->zopen_file = fopen_file_func;
- pzlib_filefunc_def->zread_file = fread_file_func;
- pzlib_filefunc_def->zwrite_file = fwrite_file_func;
- pzlib_filefunc_def->ztell_file = ftell_file_func;
- pzlib_filefunc_def->zseek_file = fseek_file_func;
- pzlib_filefunc_def->zclose_file = fclose_file_func;
- pzlib_filefunc_def->zerror_file = ferror_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = fopen64_file_func;
- pzlib_filefunc_def->zread_file = fread_file_func;
- pzlib_filefunc_def->zwrite_file = fwrite_file_func;
- pzlib_filefunc_def->ztell64_file = ftell64_file_func;
- pzlib_filefunc_def->zseek64_file = fseek64_file_func;
- pzlib_filefunc_def->zclose_file = fclose_file_func;
- pzlib_filefunc_def->zerror_file = ferror_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
diff --git a/cpukit/zlib/contrib/minizip/ioapi.h b/cpukit/zlib/contrib/minizip/ioapi.h
deleted file mode 100644
index 8309c4cf8f..0000000000
--- a/cpukit/zlib/contrib/minizip/ioapi.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- Changes
-
- Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
- Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
- More if/def section may be needed to support other platforms
- Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
- (but you should use iowin32.c for windows instead)
-
-*/
-
-#ifndef _ZLIBIOAPI64_H
-#define _ZLIBIOAPI64_H
-
-#if (!defined(_WIN32)) && (!defined(WIN32))
-
- // Linux needs this to support file operation on files larger then 4+GB
- // But might need better if/def to select just the platforms that needs them.
-
- #ifndef __USE_FILE_OFFSET64
- #define __USE_FILE_OFFSET64
- #endif
- #ifndef __USE_LARGEFILE64
- #define __USE_LARGEFILE64
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
- #ifndef _FILE_OFFSET_BIT
- #define _FILE_OFFSET_BIT 64
- #endif
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "zlib.h"
-
-#if defined(USE_FILE32API)
-#define fopen64 fopen
-#define ftello64 ftell
-#define fseeko64 fseek
-#else
-#ifdef _MSC_VER
- #define fopen64 fopen
- #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
- #define ftello64 _ftelli64
- #define fseeko64 _fseeki64
- #else // old MSC
- #define ftello64 ftell
- #define fseeko64 fseek
- #endif
-#endif
-#endif
-
-/*
-#ifndef ZPOS64_T
- #ifdef _WIN32
- #define ZPOS64_T fpos_t
- #else
- #include <stdint.h>
- #define ZPOS64_T uint64_t
- #endif
-#endif
-*/
-
-#ifdef HAVE_MINIZIP64_CONF_H
-#include "mz64conf.h"
-#endif
-
-/* a type choosen by DEFINE */
-#ifdef HAVE_64BIT_INT_CUSTOM
-typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
-#else
-#ifdef HAS_STDINT_H
-#include "stdint.h"
-typedef uint64_t ZPOS64_T;
-#else
-
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef unsigned __int64 ZPOS64_T;
-#else
-typedef unsigned long long int ZPOS64_T;
-#endif
-#endif
-#endif
-
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define ZLIB_FILEFUNC_SEEK_CUR (1)
-#define ZLIB_FILEFUNC_SEEK_END (2)
-#define ZLIB_FILEFUNC_SEEK_SET (0)
-
-#define ZLIB_FILEFUNC_MODE_READ (1)
-#define ZLIB_FILEFUNC_MODE_WRITE (2)
-#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
-
-#define ZLIB_FILEFUNC_MODE_EXISTING (4)
-#define ZLIB_FILEFUNC_MODE_CREATE (8)
-
-
-#ifndef ZCALLBACK
- #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
- #define ZCALLBACK CALLBACK
- #else
- #define ZCALLBACK
- #endif
-#endif
-
-
-
-
-typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
-typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
-typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
-
-typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
-typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
-
-
-/* here is the "old" 32 bits structure structure */
-typedef struct zlib_filefunc_def_s
-{
- open_file_func zopen_file;
- read_file_func zread_file;
- write_file_func zwrite_file;
- tell_file_func ztell_file;
- seek_file_func zseek_file;
- close_file_func zclose_file;
- testerror_file_func zerror_file;
- voidpf opaque;
-} zlib_filefunc_def;
-
-typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
-typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
-
-typedef struct zlib_filefunc64_def_s
-{
- open64_file_func zopen64_file;
- read_file_func zread_file;
- write_file_func zwrite_file;
- tell64_file_func ztell64_file;
- seek64_file_func zseek64_file;
- close_file_func zclose_file;
- testerror_file_func zerror_file;
- voidpf opaque;
-} zlib_filefunc64_def;
-
-void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-
-/* now internal definition, only for zip.c and unzip.h */
-typedef struct zlib_filefunc64_32_def_s
-{
- zlib_filefunc64_def zfile_func64;
- open_file_func zopen32_file;
- tell_file_func ztell32_file;
- seek_file_func zseek32_file;
-} zlib_filefunc64_32_def;
-
-
-#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
-#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
-//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
-//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
-#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
-#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
-
-voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
-long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
-ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
-
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
-
-#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
-#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
-#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/cpukit/zlib/contrib/minizip/iowin32.c b/cpukit/zlib/contrib/minizip/iowin32.c
deleted file mode 100644
index 6a2a883be7..0000000000
--- a/cpukit/zlib/contrib/minizip/iowin32.c
+++ /dev/null
@@ -1,389 +0,0 @@
-/* iowin32.c -- IO base function header for compress/uncompress .zip
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-*/
-
-#include <stdlib.h>
-
-#include "zlib.h"
-#include "ioapi.h"
-#include "iowin32.h"
-
-#ifndef INVALID_HANDLE_VALUE
-#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
-#endif
-
-#ifndef INVALID_SET_FILE_POINTER
-#define INVALID_SET_FILE_POINTER ((DWORD)-1)
-#endif
-
-voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
-uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
-long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
-int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
-
-typedef struct
-{
- HANDLE hf;
- int error;
-} WIN32FILE_IOWIN;
-
-
-static void win32_translate_open_mode(int mode,
- DWORD* lpdwDesiredAccess,
- DWORD* lpdwCreationDisposition,
- DWORD* lpdwShareMode,
- DWORD* lpdwFlagsAndAttributes)
-{
- *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
-
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- {
- *lpdwDesiredAccess = GENERIC_READ;
- *lpdwCreationDisposition = OPEN_EXISTING;
- *lpdwShareMode = FILE_SHARE_READ;
- }
- else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- {
- *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
- *lpdwCreationDisposition = OPEN_EXISTING;
- }
- else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- {
- *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
- *lpdwCreationDisposition = CREATE_ALWAYS;
- }
-}
-
-static voidpf win32_build_iowin(HANDLE hFile)
-{
- voidpf ret=NULL;
-
- if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
- {
- WIN32FILE_IOWIN w32fiow;
- w32fiow.hf = hFile;
- w32fiow.error = 0;
- ret = malloc(sizeof(WIN32FILE_IOWIN));
-
- if (ret==NULL)
- CloseHandle(hFile);
- else
- *((WIN32FILE_IOWIN*)ret) = w32fiow;
- }
- return ret;
-}
-
-voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-
- return win32_build_iowin(hFile);
-}
-
-
-voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-
- return win32_build_iowin(hFile);
-}
-
-
-voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-
- return win32_build_iowin(hFile);
-}
-
-
-voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-
- return win32_build_iowin(hFile);
-}
-
-
-uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
-{
- uLong ret=0;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-
- if (hFile != NULL)
- {
- if (!ReadFile(hFile, buf, size, &ret, NULL))
- {
- DWORD dwErr = GetLastError();
- if (dwErr == ERROR_HANDLE_EOF)
- dwErr = 0;
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- }
- }
-
- return ret;
-}
-
-
-uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
-{
- uLong ret=0;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-
- if (hFile != NULL)
- {
- if (!WriteFile(hFile, buf, size, &ret, NULL))
- {
- DWORD dwErr = GetLastError();
- if (dwErr == ERROR_HANDLE_EOF)
- dwErr = 0;
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- }
- }
-
- return ret;
-}
-
-long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
-{
- long ret=-1;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
- if (hFile != NULL)
- {
- DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
- if (dwSet == INVALID_SET_FILE_POINTER)
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = -1;
- }
- else
- ret=(long)dwSet;
- }
- return ret;
-}
-
-ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
-{
- ZPOS64_T ret= (ZPOS64_T)-1;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream)->hf;
-
- if (hFile)
- {
- LARGE_INTEGER li;
- li.QuadPart = 0;
- li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_CURRENT);
- if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = (ZPOS64_T)-1;
- }
- else
- ret=li.QuadPart;
- }
- return ret;
-}
-
-
-long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
-{
- DWORD dwMoveMethod=0xFFFFFFFF;
- HANDLE hFile = NULL;
-
- long ret=-1;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- dwMoveMethod = FILE_CURRENT;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- dwMoveMethod = FILE_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- dwMoveMethod = FILE_BEGIN;
- break;
- default: return -1;
- }
-
- if (hFile != NULL)
- {
- DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
- if (dwSet == INVALID_SET_FILE_POINTER)
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = -1;
- }
- else
- ret=0;
- }
- return ret;
-}
-
-long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
-{
- DWORD dwMoveMethod=0xFFFFFFFF;
- HANDLE hFile = NULL;
- long ret=-1;
-
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream)->hf;
-
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- dwMoveMethod = FILE_CURRENT;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- dwMoveMethod = FILE_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- dwMoveMethod = FILE_BEGIN;
- break;
- default: return -1;
- }
-
- if (hFile)
- {
- LARGE_INTEGER* li = (LARGE_INTEGER*)&offset;
- DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMoveMethod);
- if (dwSet == INVALID_SET_FILE_POINTER)
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = -1;
- }
- else
- ret=0;
- }
- return ret;
-}
-
-int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
-{
- int ret=-1;
-
- if (stream!=NULL)
- {
- HANDLE hFile;
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
- if (hFile != NULL)
- {
- CloseHandle(hFile);
- ret=0;
- }
- free(stream);
- }
- return ret;
-}
-
-int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
-{
- int ret=-1;
- if (stream!=NULL)
- {
- ret = ((WIN32FILE_IOWIN*)stream) -> error;
- }
- return ret;
-}
-
-void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen_file = win32_open_file_func;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell_file = win32_tell_file_func;
- pzlib_filefunc_def->zseek_file = win32_seek_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
- pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-
-void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
- pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-
-void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
- pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
diff --git a/cpukit/zlib/contrib/minizip/iowin32.h b/cpukit/zlib/contrib/minizip/iowin32.h
deleted file mode 100644
index 0ca0969a7d..0000000000
--- a/cpukit/zlib/contrib/minizip/iowin32.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* iowin32.h -- IO base function header for compress/uncompress .zip
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-*/
-
-#include <windows.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/cpukit/zlib/contrib/minizip/miniunz.c b/cpukit/zlib/contrib/minizip/miniunz.c
deleted file mode 100644
index 9ed009fbd9..0000000000
--- a/cpukit/zlib/contrib/minizip/miniunz.c
+++ /dev/null
@@ -1,648 +0,0 @@
-/*
- miniunz.c
- Version 1.1, February 14h, 2010
- sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-*/
-
-#ifndef _WIN32
- #ifndef __USE_FILE_OFFSET64
- #define __USE_FILE_OFFSET64
- #endif
- #ifndef __USE_LARGEFILE64
- #define __USE_LARGEFILE64
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
- #ifndef _FILE_OFFSET_BIT
- #define _FILE_OFFSET_BIT 64
- #endif
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef unix
-# include <unistd.h>
-# include <utime.h>
-#else
-# include <direct.h>
-# include <io.h>
-#endif
-
-#include "unzip.h"
-
-#define CASESENSITIVITY (0)
-#define WRITEBUFFERSIZE (8192)
-#define MAXFILENAME (256)
-
-#ifdef _WIN32
-#define USEWIN32IOAPI
-#include "iowin32.h"
-#endif
-/*
- mini unzip, demo of unzip package
-
- usage :
- Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]
-
- list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
- if it exists
-*/
-
-
-/* change_file_date : change the date/time of a file
- filename : the filename of the file where date/time must be modified
- dosdate : the new date at the MSDos format (4 bytes)
- tmu_date : the SAME new date at the tm_unz format */
-void change_file_date(filename,dosdate,tmu_date)
- const char *filename;
- uLong dosdate;
- tm_unz tmu_date;
-{
-#ifdef _WIN32
- HANDLE hFile;
- FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
-
- hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
- 0,NULL,OPEN_EXISTING,0,NULL);
- GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
- DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
- LocalFileTimeToFileTime(&ftLocal,&ftm);
- SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
- CloseHandle(hFile);
-#else
-#ifdef unix
- struct utimbuf ut;
- struct tm newdate;
- newdate.tm_sec = tmu_date.tm_sec;
- newdate.tm_min=tmu_date.tm_min;
- newdate.tm_hour=tmu_date.tm_hour;
- newdate.tm_mday=tmu_date.tm_mday;
- newdate.tm_mon=tmu_date.tm_mon;
- if (tmu_date.tm_year > 1900)
- newdate.tm_year=tmu_date.tm_year - 1900;
- else
- newdate.tm_year=tmu_date.tm_year ;
- newdate.tm_isdst=-1;
-
- ut.actime=ut.modtime=mktime(&newdate);
- utime(filename,&ut);
-#endif
-#endif
-}
-
-
-/* mymkdir and change_file_date are not 100 % portable
- As I don't know well Unix, I wait feedback for the unix portion */
-
-int mymkdir(dirname)
- const char* dirname;
-{
- int ret=0;
-#ifdef _WIN32
- ret = _mkdir(dirname);
-#else
-#ifdef unix
- ret = mkdir (dirname,0775);
-#endif
-#endif
- return ret;
-}
-
-int makedir (newdir)
- char *newdir;
-{
- char *buffer ;
- char *p;
- int len = (int)strlen(newdir);
-
- if (len <= 0)
- return 0;
-
- buffer = (char*)malloc(len+1);
- if (buffer==NULL)
- {
- printf("Error allocating memory\n");
- return UNZ_INTERNALERROR;
- }
- strcpy(buffer,newdir);
-
- if (buffer[len-1] == '/') {
- buffer[len-1] = '\0';
- }
- if (mymkdir(buffer) == 0)
- {
- free(buffer);
- return 1;
- }
-
- p = buffer+1;
- while (1)
- {
- char hold;
-
- while(*p && *p != '\\' && *p != '/')
- p++;
- hold = *p;
- *p = 0;
- if ((mymkdir(buffer) == -1) && (errno == ENOENT))
- {
- printf("couldn't create directory %s\n",buffer);
- free(buffer);
- return 0;
- }
- if (hold == 0)
- break;
- *p++ = hold;
- }
- free(buffer);
- return 1;
-}
-
-void do_banner()
-{
- printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
- printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
-}
-
-void do_help()
-{
- printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
- " -e Extract without pathname (junk paths)\n" \
- " -x Extract with pathname\n" \
- " -v list files\n" \
- " -l list files\n" \
- " -d directory to extract into\n" \
- " -o overwrite files without prompting\n" \
- " -p extract crypted file using password\n\n");
-}
-
-void Display64BitsSize(ZPOS64_T n, int size_char)
-{
- /* to avoid compatibility problem , we do here the conversion */
- char number[21];
- int offset=19;
- int pos_string = 19;
- number[20]=0;
- for (;;) {
- number[offset]=(char)((n%10)+'0');
- if (number[offset] != '0')
- pos_string=offset;
- n/=10;
- if (offset==0)
- break;
- offset--;
- }
- {
- int size_display_string = 19-pos_string;
- while (size_char > size_display_string)
- {
- size_char--;
- printf(" ");
- }
- }
-
- printf("%s",&number[pos_string]);
-}
-
-int do_list(uf)
- unzFile uf;
-{
- uLong i;
- unz_global_info64 gi;
- int err;
-
- err = unzGetGlobalInfo64(uf,&gi);
- if (err!=UNZ_OK)
- printf("error %d with zipfile in unzGetGlobalInfo \n",err);
- printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
- printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
- for (i=0;i<gi.number_entry;i++)
- {
- char filename_inzip[256];
- unz_file_info64 file_info;
- uLong ratio=0;
- const char *string_method;
- char charCrypt=' ';
- err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
- break;
- }
- if (file_info.uncompressed_size>0)
- ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
-
- /* display a '*' if the file is crypted */
- if ((file_info.flag & 1) != 0)
- charCrypt='*';
-
- if (file_info.compression_method==0)
- string_method="Stored";
- else
- if (file_info.compression_method==Z_DEFLATED)
- {
- uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
- if (iLevel==0)
- string_method="Defl:N";
- else if (iLevel==1)
- string_method="Defl:X";
- else if ((iLevel==2) || (iLevel==3))
- string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
- }
- else
- if (file_info.compression_method==Z_BZIP2ED)
- {
- string_method="BZip2 ";
- }
- else
- string_method="Unkn. ";
-
- Display64BitsSize(file_info.uncompressed_size,7);
- printf(" %6s%c",string_method,charCrypt);
- Display64BitsSize(file_info.compressed_size,7);
- printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
- ratio,
- (uLong)file_info.tmu_date.tm_mon + 1,
- (uLong)file_info.tmu_date.tm_mday,
- (uLong)file_info.tmu_date.tm_year % 100,
- (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
- (uLong)file_info.crc,filename_inzip);
- if ((i+1)<gi.number_entry)
- {
- err = unzGoToNextFile(uf);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGoToNextFile\n",err);
- break;
- }
- }
- }
-
- return 0;
-}
-
-
-int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
- unzFile uf;
- const int* popt_extract_without_path;
- int* popt_overwrite;
- const char* password;
-{
- char filename_inzip[256];
- char* filename_withoutpath;
- char* p;
- int err=UNZ_OK;
- FILE *fout=NULL;
- void* buf;
- uInt size_buf;
-
- unz_file_info64 file_info;
- uLong ratio=0;
- err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
-
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
- return err;
- }
-
- size_buf = WRITEBUFFERSIZE;
- buf = (void*)malloc(size_buf);
- if (buf==NULL)
- {
- printf("Error allocating memory\n");
- return UNZ_INTERNALERROR;
- }
-
- p = filename_withoutpath = filename_inzip;
- while ((*p) != '\0')
- {
- if (((*p)=='/') || ((*p)=='\\'))
- filename_withoutpath = p+1;
- p++;
- }
-
- if ((*filename_withoutpath)=='\0')
- {
- if ((*popt_extract_without_path)==0)
- {
- printf("creating directory: %s\n",filename_inzip);
- mymkdir(filename_inzip);
- }
- }
- else
- {
- const char* write_filename;
- int skip=0;
-
- if ((*popt_extract_without_path)==0)
- write_filename = filename_inzip;
- else
- write_filename = filename_withoutpath;
-
- err = unzOpenCurrentFilePassword(uf,password);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
- }
-
- if (((*popt_overwrite)==0) && (err==UNZ_OK))
- {
- char rep=0;
- FILE* ftestexist;
- ftestexist = fopen64(write_filename,"rb");
- if (ftestexist!=NULL)
- {
- fclose(ftestexist);
- do
- {
- char answer[128];
- int ret;
-
- printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
- ret = scanf("%1s",answer);
- if (ret != 1)
- {
- exit(EXIT_FAILURE);
- }
- rep = answer[0] ;
- if ((rep>='a') && (rep<='z'))
- rep -= 0x20;
- }
- while ((rep!='Y') && (rep!='N') && (rep!='A'));
- }
-
- if (rep == 'N')
- skip = 1;
-
- if (rep == 'A')
- *popt_overwrite=1;
- }
-
- if ((skip==0) && (err==UNZ_OK))
- {
- fout=fopen64(write_filename,"wb");
-
- /* some zipfile don't contain directory alone before file */
- if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
- (filename_withoutpath!=(char*)filename_inzip))
- {
- char c=*(filename_withoutpath-1);
- *(filename_withoutpath-1)='\0';
- makedir(write_filename);
- *(filename_withoutpath-1)=c;
- fout=fopen64(write_filename,"wb");
- }
-
- if (fout==NULL)
- {
- printf("error opening %s\n",write_filename);
- }
- }
-
- if (fout!=NULL)
- {
- printf(" extracting: %s\n",write_filename);
-
- do
- {
- err = unzReadCurrentFile(uf,buf,size_buf);
- if (err<0)
- {
- printf("error %d with zipfile in unzReadCurrentFile\n",err);
- break;
- }
- if (err>0)
- if (fwrite(buf,err,1,fout)!=1)
- {
- printf("error in writing extracted file\n");
- err=UNZ_ERRNO;
- break;
- }
- }
- while (err>0);
- if (fout)
- fclose(fout);
-
- if (err==0)
- change_file_date(write_filename,file_info.dosDate,
- file_info.tmu_date);
- }
-
- if (err==UNZ_OK)
- {
- err = unzCloseCurrentFile (uf);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzCloseCurrentFile\n",err);
- }
- }
- else
- unzCloseCurrentFile(uf); /* don't lose the error */
- }
-
- free(buf);
- return err;
-}
-
-
-int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
- unzFile uf;
- int opt_extract_without_path;
- int opt_overwrite;
- const char* password;
-{
- uLong i;
- unz_global_info64 gi;
- int err;
- FILE* fout=NULL;
-
- err = unzGetGlobalInfo64(uf,&gi);
- if (err!=UNZ_OK)
- printf("error %d with zipfile in unzGetGlobalInfo \n",err);
-
- for (i=0;i<gi.number_entry;i++)
- {
- if (do_extract_currentfile(uf,&opt_extract_without_path,
- &opt_overwrite,
- password) != UNZ_OK)
- break;
-
- if ((i+1)<gi.number_entry)
- {
- err = unzGoToNextFile(uf);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGoToNextFile\n",err);
- break;
- }
- }
- }
-
- return 0;
-}
-
-int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
- unzFile uf;
- const char* filename;
- int opt_extract_without_path;
- int opt_overwrite;
- const char* password;
-{
- int err = UNZ_OK;
- if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
- {
- printf("file %s not found in the zipfile\n",filename);
- return 2;
- }
-
- if (do_extract_currentfile(uf,&opt_extract_without_path,
- &opt_overwrite,
- password) == UNZ_OK)
- return 0;
- else
- return 1;
-}
-
-
-int main(argc,argv)
- int argc;
- char *argv[];
-{
- const char *zipfilename=NULL;
- const char *filename_to_extract=NULL;
- const char *password=NULL;
- char filename_try[MAXFILENAME+16] = "";
- int i;
- int ret_value=0;
- int opt_do_list=0;
- int opt_do_extract=1;
- int opt_do_extract_withoutpath=0;
- int opt_overwrite=0;
- int opt_extractdir=0;
- const char *dirname=NULL;
- unzFile uf=NULL;
-
- do_banner();
- if (argc==1)
- {
- do_help();
- return 0;
- }
- else
- {
- for (i=1;i<argc;i++)
- {
- if ((*argv[i])=='-')
- {
- const char *p=argv[i]+1;
-
- while ((*p)!='\0')
- {
- char c=*(p++);;
- if ((c=='l') || (c=='L'))
- opt_do_list = 1;
- if ((c=='v') || (c=='V'))
- opt_do_list = 1;
- if ((c=='x') || (c=='X'))
- opt_do_extract = 1;
- if ((c=='e') || (c=='E'))
- opt_do_extract = opt_do_extract_withoutpath = 1;
- if ((c=='o') || (c=='O'))
- opt_overwrite=1;
- if ((c=='d') || (c=='D'))
- {
- opt_extractdir=1;
- dirname=argv[i+1];
- }
-
- if (((c=='p') || (c=='P')) && (i+1<argc))
- {
- password=argv[i+1];
- i++;
- }
- }
- }
- else
- {
- if (zipfilename == NULL)
- zipfilename = argv[i];
- else if ((filename_to_extract==NULL) && (!opt_extractdir))
- filename_to_extract = argv[i] ;
- }
- }
- }
-
- if (zipfilename!=NULL)
- {
-
-# ifdef USEWIN32IOAPI
- zlib_filefunc64_def ffunc;
-# endif
-
- strncpy(filename_try, zipfilename,MAXFILENAME-1);
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
- filename_try[ MAXFILENAME ] = '\0';
-
-# ifdef USEWIN32IOAPI
- fill_win32_filefunc64A(&ffunc);
- uf = unzOpen2_64(zipfilename,&ffunc);
-# else
- uf = unzOpen64(zipfilename);
-# endif
- if (uf==NULL)
- {
- strcat(filename_try,".zip");
-# ifdef USEWIN32IOAPI
- uf = unzOpen2_64(filename_try,&ffunc);
-# else
- uf = unzOpen64(filename_try);
-# endif
- }
- }
-
- if (uf==NULL)
- {
- printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
- return 1;
- }
- printf("%s opened\n",filename_try);
-
- if (opt_do_list==1)
- ret_value = do_list(uf);
- else if (opt_do_extract==1)
- {
-#ifdef _WIN32
- if (opt_extractdir && _chdir(dirname))
-#else
- if (opt_extractdir && chdir(dirname))
-#endif
- {
- printf("Error changing into %s, aborting\n", dirname);
- exit(-1);
- }
-
- if (filename_to_extract == NULL)
- ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
- else
- ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
- }
-
- unzClose(uf);
-
- return ret_value;
-}
diff --git a/cpukit/zlib/contrib/minizip/minizip.c b/cpukit/zlib/contrib/minizip/minizip.c
deleted file mode 100644
index 7a4fa5a643..0000000000
--- a/cpukit/zlib/contrib/minizip/minizip.c
+++ /dev/null
@@ -1,507 +0,0 @@
-/*
- minizip.c
- Version 1.1, February 14h, 2010
- sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-*/
-
-
-#ifndef _WIN32
- #ifndef __USE_FILE_OFFSET64
- #define __USE_FILE_OFFSET64
- #endif
- #ifndef __USE_LARGEFILE64
- #define __USE_LARGEFILE64
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
- #ifndef _FILE_OFFSET_BIT
- #define _FILE_OFFSET_BIT 64
- #endif
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef unix
-# include <unistd.h>
-# include <utime.h>
-# include <sys/types.h>
-# include <sys/stat.h>
-#else
-# include <direct.h>
-# include <io.h>
-#endif
-
-#include "zip.h"
-
-#ifdef _WIN32
- #define USEWIN32IOAPI
- #include "iowin32.h"
-#endif
-
-
-
-#define WRITEBUFFERSIZE (16384)
-#define MAXFILENAME (256)
-
-#ifdef _WIN32
-uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
- uLong *dt; /* dostime */
-{
- int ret = 0;
- {
- FILETIME ftLocal;
- HANDLE hFind;
- WIN32_FIND_DATAA ff32;
-
- hFind = FindFirstFileA(f,&ff32);
- if (hFind != INVALID_HANDLE_VALUE)
- {
- FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
- FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
- FindClose(hFind);
- ret = 1;
- }
- }
- return ret;
-}
-#else
-#ifdef unix
-uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
- uLong *dt; /* dostime */
-{
- int ret=0;
- struct stat s; /* results of stat() */
- struct tm* filedate;
- time_t tm_t=0;
-
- if (strcmp(f,"-")!=0)
- {
- char name[MAXFILENAME+1];
- int len = strlen(f);
- if (len > MAXFILENAME)
- len = MAXFILENAME;
-
- strncpy(name, f,MAXFILENAME-1);
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
- name[ MAXFILENAME ] = '\0';
-
- if (name[len - 1] == '/')
- name[len - 1] = '\0';
- /* not all systems allow stat'ing a file with / appended */
- if (stat(name,&s)==0)
- {
- tm_t = s.st_mtime;
- ret = 1;
- }
- }
- filedate = localtime(&tm_t);
-
- tmzip->tm_sec = filedate->tm_sec;
- tmzip->tm_min = filedate->tm_min;
- tmzip->tm_hour = filedate->tm_hour;
- tmzip->tm_mday = filedate->tm_mday;
- tmzip->tm_mon = filedate->tm_mon ;
- tmzip->tm_year = filedate->tm_year;
-
- return ret;
-}
-#else
-uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
- uLong *dt; /* dostime */
-{
- return 0;
-}
-#endif
-#endif
-
-
-
-
-int check_exist_file(filename)
- const char* filename;
-{
- FILE* ftestexist;
- int ret = 1;
- ftestexist = fopen64(filename,"rb");
- if (ftestexist==NULL)
- ret = 0;
- else
- fclose(ftestexist);
- return ret;
-}
-
-void do_banner()
-{
- printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
- printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
-}
-
-void do_help()
-{
- printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
- " -o Overwrite existing file.zip\n" \
- " -a Append to existing file.zip\n" \
- " -0 Store only\n" \
- " -1 Compress faster\n" \
- " -9 Compress better\n\n" \
- " -j exclude path. store only the file name.\n\n");
-}
-
-/* calculate the CRC32 of a file,
- because to encrypt a file, we need known the CRC32 of the file before */
-int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
-{
- unsigned long calculate_crc=0;
- int err=ZIP_OK;
- FILE * fin = fopen64(filenameinzip,"rb");
- unsigned long size_read = 0;
- unsigned long total_read = 0;
- if (fin==NULL)
- {
- err = ZIP_ERRNO;
- }
-
- if (err == ZIP_OK)
- do
- {
- err = ZIP_OK;
- size_read = (int)fread(buf,1,size_buf,fin);
- if (size_read < size_buf)
- if (feof(fin)==0)
- {
- printf("error in reading %s\n",filenameinzip);
- err = ZIP_ERRNO;
- }
-
- if (size_read>0)
- calculate_crc = crc32(calculate_crc,buf,size_read);
- total_read += size_read;
-
- } while ((err == ZIP_OK) && (size_read>0));
-
- if (fin)
- fclose(fin);
-
- *result_crc=calculate_crc;
- printf("file %s crc %lx\n", filenameinzip, calculate_crc);
- return err;
-}
-
-int isLargeFile(const char* filename)
-{
- int largeFile = 0;
- ZPOS64_T pos = 0;
- FILE* pFile = fopen64(filename, "rb");
-
- if(pFile != NULL)
- {
- int n = fseeko64(pFile, 0, SEEK_END);
-
- pos = ftello64(pFile);
-
- printf("File : %s is %lld bytes\n", filename, pos);
-
- if(pos >= 0xffffffff)
- largeFile = 1;
-
- fclose(pFile);
- }
-
- return largeFile;
-}
-
-int main(argc,argv)
- int argc;
- char *argv[];
-{
- int i;
- int opt_overwrite=0;
- int opt_compress_level=Z_DEFAULT_COMPRESSION;
- int opt_exclude_path=0;
- int zipfilenamearg = 0;
- char filename_try[MAXFILENAME+16];
- int zipok;
- int err=0;
- int size_buf=0;
- void* buf=NULL;
- const char* password=NULL;
-
-
- do_banner();
- if (argc==1)
- {
- do_help();
- return 0;
- }
- else
- {
- for (i=1;i<argc;i++)
- {
- if ((*argv[i])=='-')
- {
- const char *p=argv[i]+1;
-
- while ((*p)!='\0')
- {
- char c=*(p++);;
- if ((c=='o') || (c=='O'))
- opt_overwrite = 1;
- if ((c=='a') || (c=='A'))
- opt_overwrite = 2;
- if ((c>='0') && (c<='9'))
- opt_compress_level = c-'0';
- if ((c=='j') || (c=='J'))
- opt_exclude_path = 1;
-
- if (((c=='p') || (c=='P')) && (i+1<argc))
- {
- password=argv[i+1];
- i++;
- }
- }
- }
- else
- {
- if (zipfilenamearg == 0)
- {
- zipfilenamearg = i ;
- }
- }
- }
- }
-
- size_buf = WRITEBUFFERSIZE;
- buf = (void*)malloc(size_buf);
- if (buf==NULL)
- {
- printf("Error allocating memory\n");
- return ZIP_INTERNALERROR;
- }
-
- if (zipfilenamearg==0)
- {
- zipok=0;
- }
- else
- {
- int i,len;
- int dot_found=0;
-
- zipok = 1 ;
- strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
- filename_try[ MAXFILENAME ] = '\0';
-
- len=(int)strlen(filename_try);
- for (i=0;i<len;i++)
- if (filename_try[i]=='.')
- dot_found=1;
-
- if (dot_found==0)
- strcat(filename_try,".zip");
-
- if (opt_overwrite==2)
- {
- /* if the file don't exist, we not append file */
- if (check_exist_file(filename_try)==0)
- opt_overwrite=1;
- }
- else
- if (opt_overwrite==0)
- if (check_exist_file(filename_try)!=0)
- {
- char rep=0;
- do
- {
- char answer[128];
- int ret;
- printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
- ret = scanf("%1s",answer);
- if (ret != 1)
- {
- exit(EXIT_FAILURE);
- }
- rep = answer[0] ;
- if ((rep>='a') && (rep<='z'))
- rep -= 0x20;
- }
- while ((rep!='Y') && (rep!='N') && (rep!='A'));
- if (rep=='N')
- zipok = 0;
- if (rep=='A')
- opt_overwrite = 2;
- }
- }
-
- if (zipok==1)
- {
- zipFile zf;
- int errclose;
-# ifdef USEWIN32IOAPI
- zlib_filefunc64_def ffunc;
- fill_win32_filefunc64A(&ffunc);
- zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
-# else
- zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
-# endif
-
- if (zf == NULL)
- {
- printf("error opening %s\n",filename_try);
- err= ZIP_ERRNO;
- }
- else
- printf("creating %s\n",filename_try);
-
- for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
- {
- if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
- ((argv[i][1]=='o') || (argv[i][1]=='O') ||
- (argv[i][1]=='a') || (argv[i][1]=='A') ||
- (argv[i][1]=='p') || (argv[i][1]=='P') ||
- ((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
- (strlen(argv[i]) == 2)))
- {
- FILE * fin;
- int size_read;
- const char* filenameinzip = argv[i];
- const char *savefilenameinzip;
- zip_fileinfo zi;
- unsigned long crcFile=0;
- int zip64 = 0;
-
- zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
- zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
- zi.dosDate = 0;
- zi.internal_fa = 0;
- zi.external_fa = 0;
- filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
-
-/*
- err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
- NULL,0,NULL,0,NULL / * comment * /,
- (opt_compress_level != 0) ? Z_DEFLATED : 0,
- opt_compress_level);
-*/
- if ((password != NULL) && (err==ZIP_OK))
- err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
-
- zip64 = isLargeFile(filenameinzip);
-
- /* The path name saved, should not include a leading slash. */
- /*if it did, windows/xp and dynazip couldn't read the zip file. */
- savefilenameinzip = filenameinzip;
- while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
- {
- savefilenameinzip++;
- }
-
- /*should the zip file contain any path at all?*/
- if( opt_exclude_path )
- {
- const char *tmpptr;
- const char *lastslash = 0;
- for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
- {
- if( *tmpptr == '\\' || *tmpptr == '/')
- {
- lastslash = tmpptr;
- }
- }
- if( lastslash != NULL )
- {
- savefilenameinzip = lastslash+1; // base filename follows last slash.
- }
- }
-
- /**/
- err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
- NULL,0,NULL,0,NULL /* comment*/,
- (opt_compress_level != 0) ? Z_DEFLATED : 0,
- opt_compress_level,0,
- /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- password,crcFile, zip64);
-
- if (err != ZIP_OK)
- printf("error in opening %s in zipfile\n",filenameinzip);
- else
- {
- fin = fopen64(filenameinzip,"rb");
- if (fin==NULL)
- {
- err=ZIP_ERRNO;
- printf("error in opening %s for reading\n",filenameinzip);
- }
- }
-
- if (err == ZIP_OK)
- do
- {
- err = ZIP_OK;
- size_read = (int)fread(buf,1,size_buf,fin);
- if (size_read < size_buf)
- if (feof(fin)==0)
- {
- printf("error in reading %s\n",filenameinzip);
- err = ZIP_ERRNO;
- }
-
- if (size_read>0)
- {
- err = zipWriteInFileInZip (zf,buf,size_read);
- if (err<0)
- {
- printf("error in writing %s in the zipfile\n",
- filenameinzip);
- }
-
- }
- } while ((err == ZIP_OK) && (size_read>0));
-
- if (fin)
- fclose(fin);
-
- if (err<0)
- err=ZIP_ERRNO;
- else
- {
- err = zipCloseFileInZip(zf);
- if (err!=ZIP_OK)
- printf("error in closing %s in the zipfile\n",
- filenameinzip);
- }
- }
- }
- errclose = zipClose(zf,NULL);
- if (errclose != ZIP_OK)
- printf("error in closing %s\n",filename_try);
- }
- else
- {
- do_help();
- }
-
- free(buf);
- return 0;
-}
diff --git a/cpukit/zlib/contrib/minizip/mztools.c b/cpukit/zlib/contrib/minizip/mztools.c
deleted file mode 100644
index f9092e65ae..0000000000
--- a/cpukit/zlib/contrib/minizip/mztools.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- Additional tools for Minizip
- Code: Xavier Roche '2004
- License: Same as ZLIB (www.gzip.org)
-*/
-
-/* Code */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "zlib.h"
-#include "unzip.h"
-
-#define READ_8(adr) ((unsigned char)*(adr))
-#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
-#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
-
-#define WRITE_8(buff, n) do { \
- *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
-} while(0)
-#define WRITE_16(buff, n) do { \
- WRITE_8((unsigned char*)(buff), n); \
- WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
-} while(0)
-#define WRITE_32(buff, n) do { \
- WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
- WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
-} while(0)
-
-extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
-const char* file;
-const char* fileOut;
-const char* fileOutTmp;
-uLong* nRecovered;
-uLong* bytesRecovered;
-{
- int err = Z_OK;
- FILE* fpZip = fopen(file, "rb");
- FILE* fpOut = fopen(fileOut, "wb");
- FILE* fpOutCD = fopen(fileOutTmp, "wb");
- if (fpZip != NULL && fpOut != NULL) {
- int entries = 0;
- uLong totalBytes = 0;
- char header[30];
- char filename[256];
- char extra[1024];
- int offset = 0;
- int offsetCD = 0;
- while ( fread(header, 1, 30, fpZip) == 30 ) {
- int currentOffset = offset;
-
- /* File entry */
- if (READ_32(header) == 0x04034b50) {
- unsigned int version = READ_16(header + 4);
- unsigned int gpflag = READ_16(header + 6);
- unsigned int method = READ_16(header + 8);
- unsigned int filetime = READ_16(header + 10);
- unsigned int filedate = READ_16(header + 12);
- unsigned int crc = READ_32(header + 14); /* crc */
- unsigned int cpsize = READ_32(header + 18); /* compressed size */
- unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
- unsigned int fnsize = READ_16(header + 26); /* file name length */
- unsigned int extsize = READ_16(header + 28); /* extra field length */
- filename[0] = extra[0] = '\0';
-
- /* Header */
- if (fwrite(header, 1, 30, fpOut) == 30) {
- offset += 30;
- } else {
- err = Z_ERRNO;
- break;
- }
-
- /* Filename */
- if (fnsize > 0) {
- if (fread(filename, 1, fnsize, fpZip) == fnsize) {
- if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
- offset += fnsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_STREAM_ERROR;
- break;
- }
-
- /* Extra field */
- if (extsize > 0) {
- if (fread(extra, 1, extsize, fpZip) == extsize) {
- if (fwrite(extra, 1, extsize, fpOut) == extsize) {
- offset += extsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
- /* Data */
- {
- int dataSize = cpsize;
- if (dataSize == 0) {
- dataSize = uncpsize;
- }
- if (dataSize > 0) {
- char* data = malloc(dataSize);
- if (data != NULL) {
- if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
- if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
- offset += dataSize;
- totalBytes += dataSize;
- } else {
- err = Z_ERRNO;
- }
- } else {
- err = Z_ERRNO;
- }
- free(data);
- if (err != Z_OK) {
- break;
- }
- } else {
- err = Z_MEM_ERROR;
- break;
- }
- }
- }
-
- /* Central directory entry */
- {
- char header[46];
- char* comment = "";
- int comsize = (int) strlen(comment);
- WRITE_32(header, 0x02014b50);
- WRITE_16(header + 4, version);
- WRITE_16(header + 6, version);
- WRITE_16(header + 8, gpflag);
- WRITE_16(header + 10, method);
- WRITE_16(header + 12, filetime);
- WRITE_16(header + 14, filedate);
- WRITE_32(header + 16, crc);
- WRITE_32(header + 20, cpsize);
- WRITE_32(header + 24, uncpsize);
- WRITE_16(header + 28, fnsize);
- WRITE_16(header + 30, extsize);
- WRITE_16(header + 32, comsize);
- WRITE_16(header + 34, 0); /* disk # */
- WRITE_16(header + 36, 0); /* int attrb */
- WRITE_32(header + 38, 0); /* ext attrb */
- WRITE_32(header + 42, currentOffset);
- /* Header */
- if (fwrite(header, 1, 46, fpOutCD) == 46) {
- offsetCD += 46;
-
- /* Filename */
- if (fnsize > 0) {
- if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
- offsetCD += fnsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_STREAM_ERROR;
- break;
- }
-
- /* Extra field */
- if (extsize > 0) {
- if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
- offsetCD += extsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
- /* Comment field */
- if (comsize > 0) {
- if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
- offsetCD += comsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
-
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
- /* Success */
- entries++;
-
- } else {
- break;
- }
- }
-
- /* Final central directory */
- {
- int entriesZip = entries;
- char header[22];
- char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
- int comsize = (int) strlen(comment);
- if (entriesZip > 0xffff) {
- entriesZip = 0xffff;
- }
- WRITE_32(header, 0x06054b50);
- WRITE_16(header + 4, 0); /* disk # */
- WRITE_16(header + 6, 0); /* disk # */
- WRITE_16(header + 8, entriesZip); /* hack */
- WRITE_16(header + 10, entriesZip); /* hack */
- WRITE_32(header + 12, offsetCD); /* size of CD */
- WRITE_32(header + 16, offset); /* offset to CD */
- WRITE_16(header + 20, comsize); /* comment */
-
- /* Header */
- if (fwrite(header, 1, 22, fpOutCD) == 22) {
-
- /* Comment field */
- if (comsize > 0) {
- if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
- err = Z_ERRNO;
- }
- }
-
- } else {
- err = Z_ERRNO;
- }
- }
-
- /* Final merge (file + central directory) */
- fclose(fpOutCD);
- if (err == Z_OK) {
- fpOutCD = fopen(fileOutTmp, "rb");
- if (fpOutCD != NULL) {
- int nRead;
- char buffer[8192];
- while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
- if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
- err = Z_ERRNO;
- break;
- }
- }
- fclose(fpOutCD);
- }
- }
-
- /* Close */
- fclose(fpZip);
- fclose(fpOut);
-
- /* Wipe temporary file */
- (void)remove(fileOutTmp);
-
- /* Number of recovered entries */
- if (err == Z_OK) {
- if (nRecovered != NULL) {
- *nRecovered = entries;
- }
- if (bytesRecovered != NULL) {
- *bytesRecovered = totalBytes;
- }
- }
- } else {
- err = Z_STREAM_ERROR;
- }
- return err;
-}
diff --git a/cpukit/zlib/contrib/minizip/mztools.h b/cpukit/zlib/contrib/minizip/mztools.h
deleted file mode 100644
index 88b34592bf..0000000000
--- a/cpukit/zlib/contrib/minizip/mztools.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- Additional tools for Minizip
- Code: Xavier Roche '2004
- License: Same as ZLIB (www.gzip.org)
-*/
-
-#ifndef _zip_tools_H
-#define _zip_tools_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#include "unzip.h"
-
-/* Repair a ZIP file (missing central directory)
- file: file to recover
- fileOut: output file after recovery
- fileOutTmp: temporary file name used for recovery
-*/
-extern int ZEXPORT unzRepair(const char* file,
- const char* fileOut,
- const char* fileOutTmp,
- uLong* nRecovered,
- uLong* bytesRecovered);
-
-#endif
diff --git a/cpukit/zlib/contrib/minizip/unzip.c b/cpukit/zlib/contrib/minizip/unzip.c
deleted file mode 100644
index 7617f41f1c..0000000000
--- a/cpukit/zlib/contrib/minizip/unzip.c
+++ /dev/null
@@ -1,2125 +0,0 @@
-/* unzip.c -- IO for uncompress .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-
- ------------------------------------------------------------------------------------
- Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
- compatibility with older software. The following is from the original crypt.c.
- Code woven in by Terry Thorsen 1/2003.
-
- Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
-
- See the accompanying file LICENSE, version 2000-Apr-09 or later
- (the contents of which are also included in zip.h) for terms of use.
- If, for some reason, all these files are missing, the Info-ZIP license
- also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
-
- crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
-
- The encryption/decryption parts of this source code (as opposed to the
- non-echoing password parts) were originally written in Europe. The
- whole source package can be freely distributed, including from the USA.
- (Prior to January 2000, re-export from the US was a violation of US law.)
-
- This encryption code is a direct transcription of the algorithm from
- Roger Schlafly, described by Phil Katz in the file appnote.txt. This
- file (appnote.txt) is distributed with the PKZIP program (even in the
- version without encryption capabilities).
-
- ------------------------------------------------------------------------------------
-
- Changes in unzip.c
-
- 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
- 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
- 2007-2008 - Even Rouault - Remove old C style function prototypes
- 2007-2008 - Even Rouault - Add unzip support for ZIP64
-
- Copyright (C) 2007-2008 Even Rouault
-
-
- Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
- Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
- should only read the compressed/uncompressed size from the Zip64 format if
- the size from normal header was 0xFFFFFFFF
- Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
- Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
- Patch created by Daniel Borca
-
- Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
-
- Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
-
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef NOUNCRYPT
- #define NOUNCRYPT
-#endif
-
-#include "zlib.h"
-#include "unzip.h"
-
-#ifdef STDC
-# include <stddef.h>
-# include <string.h>
-# include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
- extern int errno;
-#else
-# include <errno.h>
-#endif
-
-
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-
-#ifndef CASESENSITIVITYDEFAULT_NO
-# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
-# define CASESENSITIVITYDEFAULT_NO
-# endif
-#endif
-
-
-#ifndef UNZ_BUFSIZE
-#define UNZ_BUFSIZE (16384)
-#endif
-
-#ifndef UNZ_MAXFILENAMEINZIP
-#define UNZ_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-
-
-const char unz_copyright[] =
- " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info64_internal_s
-{
- ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
-} unz_file_info64_internal;
-
-
-/* file_in_zip_read_info_s contain internal information about a file in zipfile,
- when reading and decompress it */
-typedef struct
-{
- char *read_buffer; /* internal buffer for compressed data */
- z_stream stream; /* zLib stream structure for inflate */
-
-#ifdef HAVE_BZIP2
- bz_stream bstream; /* bzLib stream structure for bziped */
-#endif
-
- ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
- uLong stream_initialised; /* flag set if stream structure is initialised*/
-
- ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
- uInt size_local_extrafield;/* size of the local extra field */
- ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/
- ZPOS64_T total_out_64;
-
- uLong crc32; /* crc32 of all data uncompressed */
- uLong crc32_wait; /* crc32 we must obtain after decompress all */
- ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
- ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
- zlib_filefunc64_32_def z_filefunc;
- voidpf filestream; /* io structore of the zipfile */
- uLong compression_method; /* compression method (0==store) */
- ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- int raw;
-} file_in_zip64_read_info_s;
-
-
-/* unz64_s contain internal information about the zipfile
-*/
-typedef struct
-{
- zlib_filefunc64_32_def z_filefunc;
- int is64bitOpenFunction;
- voidpf filestream; /* io structore of the zipfile */
- unz_global_info64 gi; /* public global information */
- ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- ZPOS64_T num_file; /* number of the current file in the zipfile*/
- ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
- ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
- ZPOS64_T central_pos; /* position of the beginning of the central dir*/
-
- ZPOS64_T size_central_dir; /* size of the central directory */
- ZPOS64_T offset_central_dir; /* offset of start of central directory with
- respect to the starting disk number */
-
- unz_file_info64 cur_file_info; /* public info about the current file in zip*/
- unz_file_info64_internal cur_file_info_internal; /* private info about it*/
- file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
- file if we are decompressing it */
- int encrypted;
-
- int isZip64;
-
-# ifndef NOUNCRYPT
- unsigned long keys[3]; /* keys defining the pseudo-random sequence */
- const unsigned long* pcrc_32_tab;
-# endif
-} unz64_s;
-
-
-#ifndef NOUNCRYPT
-#include "crypt.h"
-#endif
-
-/* ===========================================================================
- Read a byte from a gz_stream; update next_in and avail_in. Return EOF
- for end of file.
- IN assertion: the stream s has been sucessfully opened for reading.
-*/
-
-
-local int unz64local_getByte OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- int *pi));
-
-local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
-{
- unsigned char c;
- int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
- if (err==1)
- {
- *pi = (int)c;
- return UNZ_OK;
- }
- else
- {
- if (ZERROR64(*pzlib_filefunc_def,filestream))
- return UNZ_ERRNO;
- else
- return UNZ_EOF;
- }
-}
-
-
-/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int unz64local_getShort OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX));
-
-local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((uLong)i)<<8;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int unz64local_getLong OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX));
-
-local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((uLong)i)<<8;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((uLong)i)<<16;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<24;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int unz64local_getLong64 OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- ZPOS64_T *pX));
-
-
-local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- ZPOS64_T *pX)
-{
- ZPOS64_T x ;
- int i = 0;
- int err;
-
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (ZPOS64_T)i;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<8;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<16;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<24;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<32;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<40;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<48;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<56;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
-{
- for (;;)
- {
- char c1=*(fileName1++);
- char c2=*(fileName2++);
- if ((c1>='a') && (c1<='z'))
- c1 -= 0x20;
- if ((c2>='a') && (c2<='z'))
- c2 -= 0x20;
- if (c1=='\0')
- return ((c2=='\0') ? 0 : -1);
- if (c2=='\0')
- return 1;
- if (c1<c2)
- return -1;
- if (c1>c2)
- return 1;
- }
-}
-
-
-#ifdef CASESENSITIVITYDEFAULT_NO
-#define CASESENSITIVITYDEFAULTVALUE 2
-#else
-#define CASESENSITIVITYDEFAULTVALUE 1
-#endif
-
-#ifndef STRCMPCASENOSENTIVEFUNCTION
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
-#endif
-
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-
-*/
-extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity)
-
-{
- if (iCaseSensitivity==0)
- iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
-
- if (iCaseSensitivity==1)
- return strcmp(fileName1,fileName2);
-
- return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-
-/*
- Locate the Central directory of a zipfile (at the end, just before
- the global comment)
-*/
-local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos ;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- return uPosFound;
-}
-
-
-/*
- Locate the Central directory 64 of a zipfile (at the end, just before
- the global comment)
-*/
-local ZPOS64_T unz64local_SearchCentralDir64 OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream));
-
-local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
- uLong uL;
- ZPOS64_T relativeOffset;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- if (uPosFound == 0)
- return 0;
-
- /* Zip64 end of central directory locator */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature, already checked */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
-
- /* number of the disk with the start of the zip64 end of central directory */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
- if (uL != 0)
- return 0;
-
- /* relative offset of the zip64 end of central directory record */
- if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
- return 0;
-
- /* total number of disks */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
- if (uL != 1)
- return 0;
-
- /* Goto end of central directory record */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
-
- if (uL != 0x06064b50)
- return 0;
-
- return relativeOffset;
-}
-
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
- "zlib/zlib114.zip".
- If the zipfile cannot be opened (file doesn't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
-*/
-local unzFile unzOpenInternal (const void *path,
- zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
- int is64bitOpenFunction)
-{
- unz64_s us;
- unz64_s *s;
- ZPOS64_T central_pos;
- uLong uL;
-
- uLong number_disk; /* number of the current dist, used for
- spaning ZIP, unsupported, always 0*/
- uLong number_disk_with_CD; /* number the the disk with central dir, used
- for spaning ZIP, unsupported, always 0*/
- ZPOS64_T number_entry_CD; /* total number of entries in
- the central dir
- (same than number_entry on nospan) */
-
- int err=UNZ_OK;
-
- if (unz_copyright[0]!=' ')
- return NULL;
-
- us.z_filefunc.zseek32_file = NULL;
- us.z_filefunc.ztell32_file = NULL;
- if (pzlib_filefunc64_32_def==NULL)
- fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
- else
- us.z_filefunc = *pzlib_filefunc64_32_def;
- us.is64bitOpenFunction = is64bitOpenFunction;
-
-
-
- us.filestream = ZOPEN64(us.z_filefunc,
- path,
- ZLIB_FILEFUNC_MODE_READ |
- ZLIB_FILEFUNC_MODE_EXISTING);
- if (us.filestream==NULL)
- return NULL;
-
- central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
- if (central_pos)
- {
- uLong uS;
- ZPOS64_T uL64;
-
- us.isZip64 = 1;
-
- if (ZSEEK64(us.z_filefunc, us.filestream,
- central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
- /* the signature, already checked */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* size of zip64 end of central directory record */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* version made by */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* version needed to extract */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of this disk */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central directory on this disk */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central directory */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- if ((number_entry_CD!=us.gi.number_entry) ||
- (number_disk_with_CD!=0) ||
- (number_disk!=0))
- err=UNZ_BADZIPFILE;
-
- /* size of the central directory */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- us.gi.size_comment = 0;
- }
- else
- {
- central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
- if (central_pos==0)
- err=UNZ_ERRNO;
-
- us.isZip64 = 0;
-
- if (ZSEEK64(us.z_filefunc, us.filestream,
- central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
- /* the signature, already checked */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of this disk */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central dir on this disk */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- us.gi.number_entry = uL;
-
- /* total number of entries in the central dir */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- number_entry_CD = uL;
-
- if ((number_entry_CD!=us.gi.number_entry) ||
- (number_disk_with_CD!=0) ||
- (number_disk!=0))
- err=UNZ_BADZIPFILE;
-
- /* size of the central directory */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- us.size_central_dir = uL;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- us.offset_central_dir = uL;
-
- /* zipfile comment length */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
- (err==UNZ_OK))
- err=UNZ_BADZIPFILE;
-
- if (err!=UNZ_OK)
- {
- ZCLOSE64(us.z_filefunc, us.filestream);
- return NULL;
- }
-
- us.byte_before_the_zipfile = central_pos -
- (us.offset_central_dir+us.size_central_dir);
- us.central_pos = central_pos;
- us.pfile_in_zip_read = NULL;
- us.encrypted = 0;
-
-
- s=(unz64_s*)ALLOC(sizeof(unz64_s));
- if( s != NULL)
- {
- *s=us;
- unzGoToFirstFile((unzFile)s);
- }
- return (unzFile)s;
-}
-
-
-extern unzFile ZEXPORT unzOpen2 (const char *path,
- zlib_filefunc_def* pzlib_filefunc32_def)
-{
- if (pzlib_filefunc32_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
- return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
- }
- else
- return unzOpenInternal(path, NULL, 0);
-}
-
-extern unzFile ZEXPORT unzOpen2_64 (const void *path,
- zlib_filefunc64_def* pzlib_filefunc_def)
-{
- if (pzlib_filefunc_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
- zlib_filefunc64_32_def_fill.ztell32_file = NULL;
- zlib_filefunc64_32_def_fill.zseek32_file = NULL;
- return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
- }
- else
- return unzOpenInternal(path, NULL, 1);
-}
-
-extern unzFile ZEXPORT unzOpen (const char *path)
-{
- return unzOpenInternal(path, NULL, 0);
-}
-
-extern unzFile ZEXPORT unzOpen64 (const void *path)
-{
- return unzOpenInternal(path, NULL, 1);
-}
-
-/*
- Close a ZipFile opened with unzipOpen.
- If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (unzFile file)
-{
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- if (s->pfile_in_zip_read!=NULL)
- unzCloseCurrentFile(file);
-
- ZCLOSE64(s->z_filefunc, s->filestream);
- TRYFREE(s);
- return UNZ_OK;
-}
-
-
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
-{
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- *pglobal_info=s->gi;
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
-{
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- /* to do : check if number_entry is not truncated */
- pglobal_info32->number_entry = (uLong)s->gi.number_entry;
- pglobal_info32->size_comment = s->gi.size_comment;
- return UNZ_OK;
-}
-/*
- Translate date/time from Dos format to tm_unz (readable more easilty)
-*/
-local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
-{
- ZPOS64_T uDate;
- uDate = (ZPOS64_T)(ulDosDate>>16);
- ptm->tm_mday = (uInt)(uDate&0x1f) ;
- ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
- ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
-
- ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
- ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
- ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
-}
-
-/*
- Get Info about the current file in the zipfile, with internal only info
-*/
-local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
- unz_file_info64 *pfile_info,
- unz_file_info64_internal
- *pfile_info_internal,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-
-local int unz64local_GetCurrentFileInfoInternal (unzFile file,
- unz_file_info64 *pfile_info,
- unz_file_info64_internal
- *pfile_info_internal,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize)
-{
- unz64_s* s;
- unz_file_info64 file_info;
- unz_file_info64_internal file_info_internal;
- int err=UNZ_OK;
- uLong uMagic;
- long lSeek=0;
- uLong uL;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (ZSEEK64(s->z_filefunc, s->filestream,
- s->pos_in_central_dir+s->byte_before_the_zipfile,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
-
- /* we check the magic */
- if (err==UNZ_OK)
- {
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
- err=UNZ_ERRNO;
- else if (uMagic!=0x02014b50)
- err=UNZ_BADZIPFILE;
- }
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
- err=UNZ_ERRNO;
-
- unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- file_info.compressed_size = uL;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- file_info.uncompressed_size = uL;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
- err=UNZ_ERRNO;
-
- // relative offset of local header
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- file_info_internal.offset_curfile = uL;
-
- lSeek+=file_info.size_filename;
- if ((err==UNZ_OK) && (szFileName!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_filename<fileNameBufferSize)
- {
- *(szFileName+file_info.size_filename)='\0';
- uSizeRead = file_info.size_filename;
- }
- else
- uSizeRead = fileNameBufferSize;
-
- if ((file_info.size_filename>0) && (fileNameBufferSize>0))
- if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- lSeek -= uSizeRead;
- }
-
- // Read extrafield
- if ((err==UNZ_OK) && (extraField!=NULL))
- {
- ZPOS64_T uSizeRead ;
- if (file_info.size_file_extra<extraFieldBufferSize)
- uSizeRead = file_info.size_file_extra;
- else
- uSizeRead = extraFieldBufferSize;
-
- if (lSeek!=0)
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
-
- if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
- if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
-
- lSeek += file_info.size_file_extra - (uLong)uSizeRead;
- }
- else
- lSeek += file_info.size_file_extra;
-
-
- if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
- {
- uLong acc = 0;
-
- // since lSeek now points to after the extra field we need to move back
- lSeek -= file_info.size_file_extra;
-
- if (lSeek!=0)
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
-
- while(acc < file_info.size_file_extra)
- {
- uLong headerId;
- uLong dataSize;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
- err=UNZ_ERRNO;
-
- /* ZIP64 extra fields */
- if (headerId == 0x0001)
- {
- uLong uL;
-
- if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1)
- {
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1)
- {
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1)
- {
- /* Relative Header offset */
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if(file_info.disk_num_start == (unsigned long)-1)
- {
- /* Disk Start Number */
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- }
- else
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
- err=UNZ_ERRNO;
- }
-
- acc += 2 + 2 + dataSize;
- }
- }
-
- if ((err==UNZ_OK) && (szComment!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_file_comment<commentBufferSize)
- {
- *(szComment+file_info.size_file_comment)='\0';
- uSizeRead = file_info.size_file_comment;
- }
- else
- uSizeRead = commentBufferSize;
-
- if (lSeek!=0)
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
-
- if ((file_info.size_file_comment>0) && (commentBufferSize>0))
- if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- lSeek+=file_info.size_file_comment - uSizeRead;
- }
- else
- lSeek+=file_info.size_file_comment;
-
-
- if ((err==UNZ_OK) && (pfile_info!=NULL))
- *pfile_info=file_info;
-
- if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
- *pfile_info_internal=file_info_internal;
-
- return err;
-}
-
-
-
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem.
-*/
-extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
- unz_file_info64 * pfile_info,
- char * szFileName, uLong fileNameBufferSize,
- void *extraField, uLong extraFieldBufferSize,
- char* szComment, uLong commentBufferSize)
-{
- return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
- szFileName,fileNameBufferSize,
- extraField,extraFieldBufferSize,
- szComment,commentBufferSize);
-}
-
-extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
- unz_file_info * pfile_info,
- char * szFileName, uLong fileNameBufferSize,
- void *extraField, uLong extraFieldBufferSize,
- char* szComment, uLong commentBufferSize)
-{
- int err;
- unz_file_info64 file_info64;
- err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
- szFileName,fileNameBufferSize,
- extraField,extraFieldBufferSize,
- szComment,commentBufferSize);
- if (err==UNZ_OK)
- {
- pfile_info->version = file_info64.version;
- pfile_info->version_needed = file_info64.version_needed;
- pfile_info->flag = file_info64.flag;
- pfile_info->compression_method = file_info64.compression_method;
- pfile_info->dosDate = file_info64.dosDate;
- pfile_info->crc = file_info64.crc;
-
- pfile_info->size_filename = file_info64.size_filename;
- pfile_info->size_file_extra = file_info64.size_file_extra;
- pfile_info->size_file_comment = file_info64.size_file_comment;
-
- pfile_info->disk_num_start = file_info64.disk_num_start;
- pfile_info->internal_fa = file_info64.internal_fa;
- pfile_info->external_fa = file_info64.external_fa;
-
- pfile_info->tmu_date = file_info64.tmu_date,
-
-
- pfile_info->compressed_size = (uLong)file_info64.compressed_size;
- pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
-
- }
- return err;
-}
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-extern int ZEXPORT unzGoToFirstFile (unzFile file)
-{
- int err=UNZ_OK;
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- s->pos_in_central_dir=s->offset_central_dir;
- s->num_file=0;
- err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-extern int ZEXPORT unzGoToNextFile (unzFile file)
-{
- unz64_s* s;
- int err;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
- if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
- if (s->num_file+1==s->gi.number_entry)
- return UNZ_END_OF_LIST_OF_FILE;
-
- s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
- s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
- s->num_file++;
- err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzipStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
-{
- unz64_s* s;
- int err;
-
- /* We remember the 'current' position in the file so that we can jump
- * back there if we fail.
- */
- unz_file_info64 cur_file_infoSaved;
- unz_file_info64_internal cur_file_info_internalSaved;
- ZPOS64_T num_fileSaved;
- ZPOS64_T pos_in_central_dirSaved;
-
-
- if (file==NULL)
- return UNZ_PARAMERROR;
-
- if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
- return UNZ_PARAMERROR;
-
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
-
- /* Save the current state */
- num_fileSaved = s->num_file;
- pos_in_central_dirSaved = s->pos_in_central_dir;
- cur_file_infoSaved = s->cur_file_info;
- cur_file_info_internalSaved = s->cur_file_info_internal;
-
- err = unzGoToFirstFile(file);
-
- while (err == UNZ_OK)
- {
- char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
- err = unzGetCurrentFileInfo64(file,NULL,
- szCurrentFileName,sizeof(szCurrentFileName)-1,
- NULL,0,NULL,0);
- if (err == UNZ_OK)
- {
- if (unzStringFileNameCompare(szCurrentFileName,
- szFileName,iCaseSensitivity)==0)
- return UNZ_OK;
- err = unzGoToNextFile(file);
- }
- }
-
- /* We failed, so restore the state of the 'current file' to where we
- * were.
- */
- s->num_file = num_fileSaved ;
- s->pos_in_central_dir = pos_in_central_dirSaved ;
- s->cur_file_info = cur_file_infoSaved;
- s->cur_file_info_internal = cur_file_info_internalSaved;
- return err;
-}
-
-
-/*
-///////////////////////////////////////////
-// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
-// I need random access
-//
-// Further optimization could be realized by adding an ability
-// to cache the directory in memory. The goal being a single
-// comprehensive file read to put the file I need in a memory.
-*/
-
-/*
-typedef struct unz_file_pos_s
-{
- ZPOS64_T pos_in_zip_directory; // offset in file
- ZPOS64_T num_of_file; // # of file
-} unz_file_pos;
-*/
-
-extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
-{
- unz64_s* s;
-
- if (file==NULL || file_pos==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
-
- file_pos->pos_in_zip_directory = s->pos_in_central_dir;
- file_pos->num_of_file = s->num_file;
-
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzGetFilePos(
- unzFile file,
- unz_file_pos* file_pos)
-{
- unz64_file_pos file_pos64;
- int err = unzGetFilePos64(file,&file_pos64);
- if (err==UNZ_OK)
- {
- file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
- file_pos->num_of_file = (uLong)file_pos64.num_of_file;
- }
- return err;
-}
-
-extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
-{
- unz64_s* s;
- int err;
-
- if (file==NULL || file_pos==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- /* jump to the right spot */
- s->pos_in_central_dir = file_pos->pos_in_zip_directory;
- s->num_file = file_pos->num_of_file;
-
- /* set the current file */
- err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- /* return results */
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-extern int ZEXPORT unzGoToFilePos(
- unzFile file,
- unz_file_pos* file_pos)
-{
- unz64_file_pos file_pos64;
- if (file_pos == NULL)
- return UNZ_PARAMERROR;
-
- file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
- file_pos64.num_of_file = file_pos->num_of_file;
- return unzGoToFilePos64(file,&file_pos64);
-}
-
-/*
-// Unzip Helper Functions - should be here?
-///////////////////////////////////////////
-*/
-
-/*
- Read the local header of the current zipfile
- Check the coherency of the local header and info in the end of central
- directory about this file
- store in *piSizeVar the size of extra info in local header
- (filename and size of extra field data)
-*/
-local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
- ZPOS64_T * poffset_local_extrafield,
- uInt * psize_local_extrafield)
-{
- uLong uMagic,uData,uFlags;
- uLong size_filename;
- uLong size_extra_field;
- int err=UNZ_OK;
-
- *piSizeVar = 0;
- *poffset_local_extrafield = 0;
- *psize_local_extrafield = 0;
-
- if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
- s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
-
- if (err==UNZ_OK)
- {
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
- err=UNZ_ERRNO;
- else if (uMagic!=0x04034b50)
- err=UNZ_BADZIPFILE;
- }
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
- err=UNZ_ERRNO;
-/*
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
- err=UNZ_BADZIPFILE;
-*/
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
- err=UNZ_BADZIPFILE;
-
- if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
-/* #ifdef HAVE_BZIP2 */
- (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
-/* #endif */
- (s->cur_file_info.compression_method!=Z_DEFLATED))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
- err=UNZ_ERRNO;
- else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
- err=UNZ_ERRNO;
- else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
- err=UNZ_BADZIPFILE;
-
- *piSizeVar += (uInt)size_filename;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
- err=UNZ_ERRNO;
- *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
- SIZEZIPLOCALHEADER + size_filename;
- *psize_local_extrafield = (uInt)size_extra_field;
-
- *piSizeVar += (uInt)size_extra_field;
-
- return err;
-}
-
-/*
- Open for reading data the current file in the zipfile.
- If there is no error and the file is opened, the return value is UNZ_OK.
-*/
-extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
- int* level, int raw, const char* password)
-{
- int err=UNZ_OK;
- uInt iSizeVar;
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
- uInt size_local_extrafield; /* size of the local extra field */
-# ifndef NOUNCRYPT
- char source[12];
-# else
- if (password != NULL)
- return UNZ_PARAMERROR;
-# endif
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_PARAMERROR;
-
- if (s->pfile_in_zip_read != NULL)
- unzCloseCurrentFile(file);
-
- if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
- return UNZ_BADZIPFILE;
-
- pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
- if (pfile_in_zip_read_info==NULL)
- return UNZ_INTERNALERROR;
-
- pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
- pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
- pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
- pfile_in_zip_read_info->pos_local_extrafield=0;
- pfile_in_zip_read_info->raw=raw;
-
- if (pfile_in_zip_read_info->read_buffer==NULL)
- {
- TRYFREE(pfile_in_zip_read_info);
- return UNZ_INTERNALERROR;
- }
-
- pfile_in_zip_read_info->stream_initialised=0;
-
- if (method!=NULL)
- *method = (int)s->cur_file_info.compression_method;
-
- if (level!=NULL)
- {
- *level = 6;
- switch (s->cur_file_info.flag & 0x06)
- {
- case 6 : *level = 1; break;
- case 4 : *level = 2; break;
- case 2 : *level = 9; break;
- }
- }
-
- if ((s->cur_file_info.compression_method!=0) &&
-/* #ifdef HAVE_BZIP2 */
- (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
-/* #endif */
- (s->cur_file_info.compression_method!=Z_DEFLATED))
-
- err=UNZ_BADZIPFILE;
-
- pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
- pfile_in_zip_read_info->crc32=0;
- pfile_in_zip_read_info->total_out_64=0;
- pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
- pfile_in_zip_read_info->filestream=s->filestream;
- pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
- pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
-
- pfile_in_zip_read_info->stream.total_out = 0;
-
- if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
- {
-#ifdef HAVE_BZIP2
- pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
- pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
- pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
- pfile_in_zip_read_info->bstream.state = (voidpf)0;
-
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
- pfile_in_zip_read_info->stream.zfree = (free_func)0;
- pfile_in_zip_read_info->stream.opaque = (voidpf)0;
- pfile_in_zip_read_info->stream.next_in = (voidpf)0;
- pfile_in_zip_read_info->stream.avail_in = 0;
-
- err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
- if (err == Z_OK)
- pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
- else
- {
- TRYFREE(pfile_in_zip_read_info);
- return err;
- }
-#else
- pfile_in_zip_read_info->raw=1;
-#endif
- }
- else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
- {
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
- pfile_in_zip_read_info->stream.zfree = (free_func)0;
- pfile_in_zip_read_info->stream.opaque = (voidpf)0;
- pfile_in_zip_read_info->stream.next_in = 0;
- pfile_in_zip_read_info->stream.avail_in = 0;
-
- err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
- if (err == Z_OK)
- pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
- else
- {
- TRYFREE(pfile_in_zip_read_info);
- return err;
- }
- /* windowBits is passed < 0 to tell that there is no zlib header.
- * Note that in this case inflate *requires* an extra "dummy" byte
- * after the compressed stream in order to complete decompression and
- * return Z_STREAM_END.
- * In unzip, i don't wait absolutely Z_STREAM_END because I known the
- * size of both compressed and uncompressed data
- */
- }
- pfile_in_zip_read_info->rest_read_compressed =
- s->cur_file_info.compressed_size ;
- pfile_in_zip_read_info->rest_read_uncompressed =
- s->cur_file_info.uncompressed_size ;
-
-
- pfile_in_zip_read_info->pos_in_zipfile =
- s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
- iSizeVar;
-
- pfile_in_zip_read_info->stream.avail_in = (uInt)0;
-
- s->pfile_in_zip_read = pfile_in_zip_read_info;
- s->encrypted = 0;
-
-# ifndef NOUNCRYPT
- if (password != NULL)
- {
- int i;
- s->pcrc_32_tab = get_crc_table();
- init_keys(password,s->keys,s->pcrc_32_tab);
- if (ZSEEK64(s->z_filefunc, s->filestream,
- s->pfile_in_zip_read->pos_in_zipfile +
- s->pfile_in_zip_read->byte_before_the_zipfile,
- SEEK_SET)!=0)
- return UNZ_INTERNALERROR;
- if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
- return UNZ_INTERNALERROR;
-
- for (i = 0; i<12; i++)
- zdecode(s->keys,s->pcrc_32_tab,source[i]);
-
- s->pfile_in_zip_read->pos_in_zipfile+=12;
- s->encrypted=1;
- }
-# endif
-
-
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzOpenCurrentFile (unzFile file)
-{
- return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
-}
-
-extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
-{
- return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
-}
-
-extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
-{
- return unzOpenCurrentFile3(file, method, level, raw, NULL);
-}
-
-/** Addition for GDAL : START */
-
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- s=(unz64_s*)file;
- if (file==NULL)
- return 0; //UNZ_PARAMERROR;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
- if (pfile_in_zip_read_info==NULL)
- return 0; //UNZ_PARAMERROR;
- return pfile_in_zip_read_info->pos_in_zipfile +
- pfile_in_zip_read_info->byte_before_the_zipfile;
-}
-
-/** Addition for GDAL : END */
-
-/*
- Read bytes from the current file.
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
-{
- int err=UNZ_OK;
- uInt iRead = 0;
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
-
- if ((pfile_in_zip_read_info->read_buffer == NULL))
- return UNZ_END_OF_LIST_OF_FILE;
- if (len==0)
- return 0;
-
- pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
-
- pfile_in_zip_read_info->stream.avail_out = (uInt)len;
-
- if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
- (!(pfile_in_zip_read_info->raw)))
- pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
-
- if ((len>pfile_in_zip_read_info->rest_read_compressed+
- pfile_in_zip_read_info->stream.avail_in) &&
- (pfile_in_zip_read_info->raw))
- pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_compressed+
- pfile_in_zip_read_info->stream.avail_in;
-
- while (pfile_in_zip_read_info->stream.avail_out>0)
- {
- if ((pfile_in_zip_read_info->stream.avail_in==0) &&
- (pfile_in_zip_read_info->rest_read_compressed>0))
- {
- uInt uReadThis = UNZ_BUFSIZE;
- if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
- uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
- if (uReadThis == 0)
- return UNZ_EOF;
- if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->pos_in_zipfile +
- pfile_in_zip_read_info->byte_before_the_zipfile,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
- if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->read_buffer,
- uReadThis)!=uReadThis)
- return UNZ_ERRNO;
-
-
-# ifndef NOUNCRYPT
- if(s->encrypted)
- {
- uInt i;
- for(i=0;i<uReadThis;i++)
- pfile_in_zip_read_info->read_buffer[i] =
- zdecode(s->keys,s->pcrc_32_tab,
- pfile_in_zip_read_info->read_buffer[i]);
- }
-# endif
-
-
- pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
-
- pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
-
- pfile_in_zip_read_info->stream.next_in =
- (Bytef*)pfile_in_zip_read_info->read_buffer;
- pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
- }
-
- if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
- {
- uInt uDoCopy,i ;
-
- if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- return (iRead==0) ? UNZ_EOF : iRead;
-
- if (pfile_in_zip_read_info->stream.avail_out <
- pfile_in_zip_read_info->stream.avail_in)
- uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
- else
- uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
-
- for (i=0;i<uDoCopy;i++)
- *(pfile_in_zip_read_info->stream.next_out+i) =
- *(pfile_in_zip_read_info->stream.next_in+i);
-
- pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
-
- pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
- pfile_in_zip_read_info->stream.next_out,
- uDoCopy);
- pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
- pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
- pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
- pfile_in_zip_read_info->stream.next_out += uDoCopy;
- pfile_in_zip_read_info->stream.next_in += uDoCopy;
- pfile_in_zip_read_info->stream.total_out += uDoCopy;
- iRead += uDoCopy;
- }
- else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
- {
-#ifdef HAVE_BZIP2
- uLong uTotalOutBefore,uTotalOutAfter;
- const Bytef *bufBefore;
- uLong uOutThis;
-
- pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
- pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
- pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
- pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
- pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
- pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
- pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
- pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
-
- uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
- bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
-
- err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
-
- uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
- uOutThis = uTotalOutAfter-uTotalOutBefore;
-
- pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
-
- pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
- pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
- pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
- pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
- pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
- pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
- pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
- pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
-
- if (err==BZ_STREAM_END)
- return (iRead==0) ? UNZ_EOF : iRead;
- if (err!=BZ_OK)
- break;
-#endif
- } // end Z_BZIP2ED
- else
- {
- ZPOS64_T uTotalOutBefore,uTotalOutAfter;
- const Bytef *bufBefore;
- ZPOS64_T uOutThis;
- int flush=Z_SYNC_FLUSH;
-
- uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
- bufBefore = pfile_in_zip_read_info->stream.next_out;
-
- /*
- if ((pfile_in_zip_read_info->rest_read_uncompressed ==
- pfile_in_zip_read_info->stream.avail_out) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- flush = Z_FINISH;
- */
- err=inflate(&pfile_in_zip_read_info->stream,flush);
-
- if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
- err = Z_DATA_ERROR;
-
- uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
- uOutThis = uTotalOutAfter-uTotalOutBefore;
-
- pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
-
- pfile_in_zip_read_info->crc32 =
- crc32(pfile_in_zip_read_info->crc32,bufBefore,
- (uInt)(uOutThis));
-
- pfile_in_zip_read_info->rest_read_uncompressed -=
- uOutThis;
-
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
- if (err==Z_STREAM_END)
- return (iRead==0) ? UNZ_EOF : iRead;
- if (err!=Z_OK)
- break;
- }
- }
-
- if (err==Z_OK)
- return iRead;
- return err;
-}
-
-
-/*
- Give the current position in uncompressed data
-*/
-extern z_off_t ZEXPORT unztell (unzFile file)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- return (z_off_t)pfile_in_zip_read_info->stream.total_out;
-}
-
-extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
-{
-
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return (ZPOS64_T)-1;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return (ZPOS64_T)-1;
-
- return pfile_in_zip_read_info->total_out_64;
-}
-
-
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-extern int ZEXPORT unzeof (unzFile file)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
- return 1;
- else
- return 0;
-}
-
-
-
-/*
-Read extra field from the current file (opened by unzOpenCurrentFile)
-This is the local-header version of the extra field (sometimes, there is
-more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field that can be read
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- uInt read_now;
- ZPOS64_T size_to_read;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
- pfile_in_zip_read_info->pos_local_extrafield);
-
- if (buf==NULL)
- return (int)size_to_read;
-
- if (len>size_to_read)
- read_now = (uInt)size_to_read;
- else
- read_now = (uInt)len ;
-
- if (read_now==0)
- return 0;
-
- if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->offset_local_extrafield +
- pfile_in_zip_read_info->pos_local_extrafield,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
- if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- buf,read_now)!=read_now)
- return UNZ_ERRNO;
-
- return (int)read_now;
-}
-
-/*
- Close the file in zip opened with unzipOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-extern int ZEXPORT unzCloseCurrentFile (unzFile file)
-{
- int err=UNZ_OK;
-
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
-
- if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
- (!pfile_in_zip_read_info->raw))
- {
- if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
- err=UNZ_CRCERROR;
- }
-
-
- TRYFREE(pfile_in_zip_read_info->read_buffer);
- pfile_in_zip_read_info->read_buffer = NULL;
- if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
- inflateEnd(&pfile_in_zip_read_info->stream);
-#ifdef HAVE_BZIP2
- else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
- BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
-#endif
-
-
- pfile_in_zip_read_info->stream_initialised = 0;
- TRYFREE(pfile_in_zip_read_info);
-
- s->pfile_in_zip_read=NULL;
-
- return err;
-}
-
-
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
-{
- unz64_s* s;
- uLong uReadThis ;
- if (file==NULL)
- return (int)UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- uReadThis = uSizeBuf;
- if (uReadThis>s->gi.size_comment)
- uReadThis = s->gi.size_comment;
-
- if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
- if (uReadThis>0)
- {
- *szComment='\0';
- if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
- return UNZ_ERRNO;
- }
-
- if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
- *(szComment+s->gi.size_comment)='\0';
- return (int)uReadThis;
-}
-
-/* Additions by RX '2004 */
-extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
-{
- unz64_s* s;
-
- if (file==NULL)
- return 0; //UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return 0;
- if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
- if (s->num_file==s->gi.number_entry)
- return 0;
- return s->pos_in_central_dir;
-}
-
-extern uLong ZEXPORT unzGetOffset (unzFile file)
-{
- ZPOS64_T offset64;
-
- if (file==NULL)
- return 0; //UNZ_PARAMERROR;
- offset64 = unzGetOffset64(file);
- return (uLong)offset64;
-}
-
-extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
-{
- unz64_s* s;
- int err;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- s->pos_in_central_dir = pos;
- s->num_file = s->gi.number_entry; /* hack */
- err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
-{
- return unzSetOffset64(file,pos);
-}
diff --git a/cpukit/zlib/contrib/minizip/unzip.h b/cpukit/zlib/contrib/minizip/unzip.h
deleted file mode 100644
index 3183968b77..0000000000
--- a/cpukit/zlib/contrib/minizip/unzip.h
+++ /dev/null
@@ -1,437 +0,0 @@
-/* unzip.h -- IO for uncompress .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- ---------------------------------------------------------------------------------
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- ---------------------------------------------------------------------------------
-
- Changes
-
- See header of unzip64.c
-
-*/
-
-#ifndef _unz64_H
-#define _unz64_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#ifdef HAVE_BZIP2
-#include "bzlib.h"
-#endif
-
-#define Z_BZIP2ED 12
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK (0)
-#define UNZ_END_OF_LIST_OF_FILE (-100)
-#define UNZ_ERRNO (Z_ERRNO)
-#define UNZ_EOF (0)
-#define UNZ_PARAMERROR (-102)
-#define UNZ_BADZIPFILE (-103)
-#define UNZ_INTERNALERROR (-104)
-#define UNZ_CRCERROR (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
- These data comes from the end of central dir */
-typedef struct unz_global_info64_s
-{
- ZPOS64_T number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info64;
-
-typedef struct unz_global_info_s
-{
- uLong number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info;
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info64_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- ZPOS64_T compressed_size; /* compressed size 8 bytes */
- ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info64;
-
-typedef struct unz_file_info_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- uLong compressed_size; /* compressed size 4 bytes */
- uLong uncompressed_size; /* uncompressed size 4 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity));
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-extern unzFile ZEXPORT unzOpen64 OF((const void *path));
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
- "zlib/zlib113.zip".
- If the zipfile cannot be opened (file don't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
- the "64" function take a const void* pointer, because the path is just the
- value passed to the open64_file_func callback.
- Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
- is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
- does not describe the reality
-*/
-
-
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
- zlib_filefunc_def* pzlib_filefunc_def));
-/*
- Open a Zip file, like unzOpen, but provide a set of file low level API
- for read/write the zip file (see ioapi.h)
-*/
-
-extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
- zlib_filefunc64_def* pzlib_filefunc_def));
-/*
- Open a Zip file, like unz64Open, but provide a set of file low level API
- for read/write the zip file (see ioapi.h)
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
- Close a ZipFile opened with unzipOpen.
- If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
- return UNZ_OK if there is no problem. */
-
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
- unz_global_info *pglobal_info));
-
-extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
- unz_global_info64 *pglobal_info));
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-
-
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
- char *szComment,
- uLong uSizeBuf));
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
- const char *szFileName,
- int iCaseSensitivity));
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-/* ****************************************** */
-/* Ryan supplied functions */
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_pos_s
-{
- uLong pos_in_zip_directory; /* offset in zip file directory */
- uLong num_of_file; /* # of file */
-} unz_file_pos;
-
-extern int ZEXPORT unzGetFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-typedef struct unz64_file_pos_s
-{
- ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
- ZPOS64_T num_of_file; /* # of file */
-} unz64_file_pos;
-
-extern int ZEXPORT unzGetFilePos64(
- unzFile file,
- unz64_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos64(
- unzFile file,
- const unz64_file_pos* file_pos);
-
-/* ****************************************** */
-
-extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
- unz_file_info64 *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
- unz_file_info *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-/*
- Get Info about the current file
- if pfile_info!=NULL, the *pfile_info structure will contain somes info about
- the current file
- if szFileName!=NULL, the filemane string will be copied in szFileName
- (fileNameBufferSize is the size of the buffer)
- if extraField!=NULL, the extra field information will be copied in extraField
- (extraFieldBufferSize is the size of the buffer).
- This is the Central-header version of the extra field
- if szComment!=NULL, the comment string of the file will be copied in szComment
- (commentBufferSize is the size of the buffer)
-*/
-
-
-/** Addition for GDAL : START */
-
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
-
-/** Addition for GDAL : END */
-
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
- from it, and close it (you can close it before reading all the file)
- */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
- Open for reading data the current file in the zipfile.
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
- const char* password));
-/*
- Open for reading data the current file in the zipfile.
- password is a crypting password
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
- int* method,
- int* level,
- int raw));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
- int* method,
- int* level,
- int raw,
- const char* password));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
- Close the file in zip opened with unzOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read bytes from the current file (opened by unzOpenCurrentFile)
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-
-extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
-/*
- Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read extra field from the current file (opened by unzOpenCurrentFile)
- This is the local-header version of the extra field (sometimes, there is
- more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-
-/***************************************************************************/
-
-/* Get the current file offset */
-extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
-extern uLong ZEXPORT unzGetOffset (unzFile file);
-
-/* Set the current file offset */
-extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _unz64_H */
diff --git a/cpukit/zlib/contrib/minizip/zip.c b/cpukit/zlib/contrib/minizip/zip.c
deleted file mode 100644
index 3c34fc8bd4..0000000000
--- a/cpukit/zlib/contrib/minizip/zip.c
+++ /dev/null
@@ -1,2004 +0,0 @@
-/* zip.c -- IO on .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- Changes
- Oct-2009 - Mathias Svensson - Remove old C style function prototypes
- Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
- Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
- Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
- It is used when recreting zip archive with RAW when deleting items from a zip.
- ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed.
- Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
- Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
-
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "zlib.h"
-#include "zip.h"
-
-#ifdef STDC
-# include <stddef.h>
-# include <string.h>
-# include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
- extern int errno;
-#else
-# include <errno.h>
-#endif
-
-
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-#ifndef VERSIONMADEBY
-# define VERSIONMADEBY (0x0) /* platform depedent */
-#endif
-
-#ifndef Z_BUFSIZE
-#define Z_BUFSIZE (64*1024) //(16384)
-#endif
-
-#ifndef Z_MAXFILENAMEINZIP
-#define Z_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-/*
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-*/
-
-/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
-
-
-// NOT sure that this work on ALL platform
-#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
-
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END 2
-#endif
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-
-#ifndef DEF_MEM_LEVEL
-#if MAX_MEM_LEVEL >= 8
-# define DEF_MEM_LEVEL 8
-#else
-# define DEF_MEM_LEVEL MAX_MEM_LEVEL
-#endif
-#endif
-const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-
-#define SIZEDATA_INDATABLOCK (4096-(4*4))
-
-#define LOCALHEADERMAGIC (0x04034b50)
-#define CENTRALHEADERMAGIC (0x02014b50)
-#define ENDHEADERMAGIC (0x06054b50)
-#define ZIP64ENDHEADERMAGIC (0x6064b50)
-#define ZIP64ENDLOCHEADERMAGIC (0x7064b50)
-
-#define FLAG_LOCALHEADER_OFFSET (0x06)
-#define CRC_LOCALHEADER_OFFSET (0x0e)
-
-#define SIZECENTRALHEADER (0x2e) /* 46 */
-
-typedef struct linkedlist_datablock_internal_s
-{
- struct linkedlist_datablock_internal_s* next_datablock;
- uLong avail_in_this_block;
- uLong filled_in_this_block;
- uLong unused; /* for future use and alignement */
- unsigned char data[SIZEDATA_INDATABLOCK];
-} linkedlist_datablock_internal;
-
-typedef struct linkedlist_data_s
-{
- linkedlist_datablock_internal* first_block;
- linkedlist_datablock_internal* last_block;
-} linkedlist_data;
-
-
-typedef struct
-{
- z_stream stream; /* zLib stream structure for inflate */
-#ifdef HAVE_BZIP2
- bz_stream bstream; /* bzLib stream structure for bziped */
-#endif
-
- int stream_initialised; /* 1 is stream is initialised */
- uInt pos_in_buffered_data; /* last written byte in buffered_data */
-
- ZPOS64_T pos_local_header; /* offset of the local header of the file
- currenty writing */
- char* central_header; /* central header data for the current file */
- uLong size_centralExtra;
- uLong size_centralheader; /* size of the central header for cur file */
- uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
- uLong flag; /* flag of the file currently writing */
-
- int method; /* compression method of file currenty wr.*/
- int raw; /* 1 for directly writing raw data */
- Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
- uLong dosDate;
- uLong crc32;
- int encrypt;
- int zip64; /* Add ZIP64 extened information in the extra field */
- ZPOS64_T pos_zip64extrainfo;
- ZPOS64_T totalCompressedData;
- ZPOS64_T totalUncompressedData;
-#ifndef NOCRYPT
- unsigned long keys[3]; /* keys defining the pseudo-random sequence */
- const unsigned long* pcrc_32_tab;
- int crypt_header_size;
-#endif
-} curfile64_info;
-
-typedef struct
-{
- zlib_filefunc64_32_def z_filefunc;
- voidpf filestream; /* io structore of the zipfile */
- linkedlist_data central_dir;/* datablock with central dir in construction*/
- int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
- curfile64_info ci; /* info on the file curretly writing */
-
- ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
- ZPOS64_T add_position_when_writting_offset;
- ZPOS64_T number_entry;
-
-#ifndef NO_ADDFILEINEXISTINGZIP
- char *globalcomment;
-#endif
-
-} zip64_internal;
-
-
-#ifndef NOCRYPT
-#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-#include "crypt.h"
-#endif
-
-local linkedlist_datablock_internal* allocate_new_datablock()
-{
- linkedlist_datablock_internal* ldi;
- ldi = (linkedlist_datablock_internal*)
- ALLOC(sizeof(linkedlist_datablock_internal));
- if (ldi!=NULL)
- {
- ldi->next_datablock = NULL ;
- ldi->filled_in_this_block = 0 ;
- ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
- }
- return ldi;
-}
-
-local void free_datablock(linkedlist_datablock_internal* ldi)
-{
- while (ldi!=NULL)
- {
- linkedlist_datablock_internal* ldinext = ldi->next_datablock;
- TRYFREE(ldi);
- ldi = ldinext;
- }
-}
-
-local void init_linkedlist(linkedlist_data* ll)
-{
- ll->first_block = ll->last_block = NULL;
-}
-
-local void free_linkedlist(linkedlist_data* ll)
-{
- free_datablock(ll->first_block);
- ll->first_block = ll->last_block = NULL;
-}
-
-
-local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
-{
- linkedlist_datablock_internal* ldi;
- const unsigned char* from_copy;
-
- if (ll==NULL)
- return ZIP_INTERNALERROR;
-
- if (ll->last_block == NULL)
- {
- ll->first_block = ll->last_block = allocate_new_datablock();
- if (ll->first_block == NULL)
- return ZIP_INTERNALERROR;
- }
-
- ldi = ll->last_block;
- from_copy = (unsigned char*)buf;
-
- while (len>0)
- {
- uInt copy_this;
- uInt i;
- unsigned char* to_copy;
-
- if (ldi->avail_in_this_block==0)
- {
- ldi->next_datablock = allocate_new_datablock();
- if (ldi->next_datablock == NULL)
- return ZIP_INTERNALERROR;
- ldi = ldi->next_datablock ;
- ll->last_block = ldi;
- }
-
- if (ldi->avail_in_this_block < len)
- copy_this = (uInt)ldi->avail_in_this_block;
- else
- copy_this = (uInt)len;
-
- to_copy = &(ldi->data[ldi->filled_in_this_block]);
-
- for (i=0;i<copy_this;i++)
- *(to_copy+i)=*(from_copy+i);
-
- ldi->filled_in_this_block += copy_this;
- ldi->avail_in_this_block -= copy_this;
- from_copy += copy_this ;
- len -= copy_this;
- }
- return ZIP_OK;
-}
-
-
-
-/****************************************************************************/
-
-#ifndef NO_ADDFILEINEXISTINGZIP
-/* ===========================================================================
- Inputs a long in LSB order to the given file
- nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
-*/
-
-local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
-local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
-{
- unsigned char buf[8];
- int n;
- for (n = 0; n < nbByte; n++)
- {
- buf[n] = (unsigned char)(x & 0xff);
- x >>= 8;
- }
- if (x != 0)
- { /* data overflow - hack for ZIP64 (X Roche) */
- for (n = 0; n < nbByte; n++)
- {
- buf[n] = 0xff;
- }
- }
-
- if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
- return ZIP_ERRNO;
- else
- return ZIP_OK;
-}
-
-local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
-local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
-{
- unsigned char* buf=(unsigned char*)dest;
- int n;
- for (n = 0; n < nbByte; n++) {
- buf[n] = (unsigned char)(x & 0xff);
- x >>= 8;
- }
-
- if (x != 0)
- { /* data overflow - hack for ZIP64 */
- for (n = 0; n < nbByte; n++)
- {
- buf[n] = 0xff;
- }
- }
-}
-
-/****************************************************************************/
-
-
-local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
-{
- uLong year = (uLong)ptm->tm_year;
- if (year>=1980)
- year-=1980;
- else if (year>=80)
- year-=80;
- return
- (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
- ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
-}
-
-
-/****************************************************************************/
-
-local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
-
-local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
-{
- unsigned char c;
- int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
- if (err==1)
- {
- *pi = (int)c;
- return ZIP_OK;
- }
- else
- {
- if (ZERROR64(*pzlib_filefunc_def,filestream))
- return ZIP_ERRNO;
- else
- return ZIP_EOF;
- }
-}
-
-
-/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
-
-local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<8;
-
- if (err==ZIP_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
-
-local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<8;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<16;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<24;
-
- if (err==ZIP_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
-
-
-local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
-{
- ZPOS64_T x;
- int i = 0;
- int err;
-
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (ZPOS64_T)i;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<8;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<16;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<24;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<32;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<40;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<48;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<56;
-
- if (err==ZIP_OK)
- *pX = x;
- else
- *pX = 0;
-
- return err;
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-/*
- Locate the Central directory of a zipfile (at the end, just before
- the global comment)
-*/
-local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-
-local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos ;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- return uPosFound;
-}
-
-/*
-Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
-the global comment)
-*/
-local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-
-local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
- uLong uL;
- ZPOS64_T relativeOffset;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- {
- // Signature "0x07064b50" Zip64 end of central directory locater
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
- {
- uPosFound = uReadPos+i;
- break;
- }
- }
-
- if (uPosFound!=0)
- break;
- }
-
- TRYFREE(buf);
- if (uPosFound == 0)
- return 0;
-
- /* Zip64 end of central directory locator */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature, already checked */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
-
- /* number of the disk with the start of the zip64 end of central directory */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
- if (uL != 0)
- return 0;
-
- /* relative offset of the zip64 end of central directory record */
- if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
- return 0;
-
- /* total number of disks */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
- if (uL != 1)
- return 0;
-
- /* Goto Zip64 end of central directory record */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
-
- if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
- return 0;
-
- return relativeOffset;
-}
-
-int LoadCentralDirectoryRecord(zip64_internal* pziinit)
-{
- int err=ZIP_OK;
- ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-
- ZPOS64_T size_central_dir; /* size of the central directory */
- ZPOS64_T offset_central_dir; /* offset of start of central directory */
- ZPOS64_T central_pos;
- uLong uL;
-
- uLong number_disk; /* number of the current dist, used for
- spaning ZIP, unsupported, always 0*/
- uLong number_disk_with_CD; /* number the the disk with central dir, used
- for spaning ZIP, unsupported, always 0*/
- ZPOS64_T number_entry;
- ZPOS64_T number_entry_CD; /* total number of entries in
- the central dir
- (same than number_entry on nospan) */
- uLong VersionMadeBy;
- uLong VersionNeeded;
- uLong size_comment;
-
- int hasZIP64Record = 0;
-
- // check first if we find a ZIP64 record
- central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
- if(central_pos > 0)
- {
- hasZIP64Record = 1;
- }
- else if(central_pos == 0)
- {
- central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
- }
-
-/* disable to allow appending to empty ZIP archive
- if (central_pos==0)
- err=ZIP_ERRNO;
-*/
-
- if(hasZIP64Record)
- {
- ZPOS64_T sizeEndOfCentralDirectory;
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
- err=ZIP_ERRNO;
-
- /* the signature, already checked */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* size of zip64 end of central directory record */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* version made by */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* version needed to extract */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of this disk */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* total number of entries in the central directory on this disk */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* total number of entries in the central directory */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
- err=ZIP_BADZIPFILE;
-
- /* size of the central directory */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- // TODO..
- // read the comment from the standard central header.
- size_comment = 0;
- }
- else
- {
- // Read End of central Directory info
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=ZIP_ERRNO;
-
- /* the signature, already checked */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of this disk */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* total number of entries in the central dir on this disk */
- number_entry = 0;
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- number_entry = uL;
-
- /* total number of entries in the central dir */
- number_entry_CD = 0;
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- number_entry_CD = uL;
-
- if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
- err=ZIP_BADZIPFILE;
-
- /* size of the central directory */
- size_central_dir = 0;
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- size_central_dir = uL;
-
- /* offset of start of central directory with respect to the starting disk number */
- offset_central_dir = 0;
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- offset_central_dir = uL;
-
-
- /* zipfile global comment length */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
- err=ZIP_ERRNO;
- }
-
- if ((central_pos<offset_central_dir+size_central_dir) &&
- (err==ZIP_OK))
- err=ZIP_BADZIPFILE;
-
- if (err!=ZIP_OK)
- {
- ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
- return ZIP_ERRNO;
- }
-
- if (size_comment>0)
- {
- pziinit->globalcomment = (char*)ALLOC(size_comment+1);
- if (pziinit->globalcomment)
- {
- size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
- pziinit->globalcomment[size_comment]=0;
- }
- }
-
- byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
- pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
-
- {
- ZPOS64_T size_central_dir_to_read = size_central_dir;
- size_t buf_size = SIZEDATA_INDATABLOCK;
- void* buf_read = (void*)ALLOC(buf_size);
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
- err=ZIP_ERRNO;
-
- while ((size_central_dir_to_read>0) && (err==ZIP_OK))
- {
- ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
- if (read_this > size_central_dir_to_read)
- read_this = size_central_dir_to_read;
-
- if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
- err=ZIP_ERRNO;
-
- if (err==ZIP_OK)
- err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
-
- size_central_dir_to_read-=read_this;
- }
- TRYFREE(buf_read);
- }
- pziinit->begin_pos = byte_before_the_zipfile;
- pziinit->number_entry = number_entry_CD;
-
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
- err=ZIP_ERRNO;
-
- return err;
-}
-
-
-#endif /* !NO_ADDFILEINEXISTINGZIP*/
-
-
-/************************************************************/
-extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
-{
- zip64_internal ziinit;
- zip64_internal* zi;
- int err=ZIP_OK;
-
- ziinit.z_filefunc.zseek32_file = NULL;
- ziinit.z_filefunc.ztell32_file = NULL;
- if (pzlib_filefunc64_32_def==NULL)
- fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
- else
- ziinit.z_filefunc = *pzlib_filefunc64_32_def;
-
- ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
- pathname,
- (append == APPEND_STATUS_CREATE) ?
- (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
- (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
-
- if (ziinit.filestream == NULL)
- return NULL;
-
- if (append == APPEND_STATUS_CREATEAFTER)
- ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
-
- ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
- ziinit.in_opened_file_inzip = 0;
- ziinit.ci.stream_initialised = 0;
- ziinit.number_entry = 0;
- ziinit.add_position_when_writting_offset = 0;
- init_linkedlist(&(ziinit.central_dir));
-
-
-
- zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
- if (zi==NULL)
- {
- ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
- return NULL;
- }
-
- /* now we add file in a zipfile */
-# ifndef NO_ADDFILEINEXISTINGZIP
- ziinit.globalcomment = NULL;
- if (append == APPEND_STATUS_ADDINZIP)
- {
- // Read and Cache Central Directory Records
- err = LoadCentralDirectoryRecord(&ziinit);
- }
-
- if (globalcomment)
- {
- *globalcomment = ziinit.globalcomment;
- }
-# endif /* !NO_ADDFILEINEXISTINGZIP*/
-
- if (err != ZIP_OK)
- {
-# ifndef NO_ADDFILEINEXISTINGZIP
- TRYFREE(ziinit.globalcomment);
-# endif /* !NO_ADDFILEINEXISTINGZIP*/
- TRYFREE(zi);
- return NULL;
- }
- else
- {
- *zi = ziinit;
- return (zipFile)zi;
- }
-}
-
-extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
-{
- if (pzlib_filefunc32_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
- return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
- }
- else
- return zipOpen3(pathname, append, globalcomment, NULL);
-}
-
-extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
-{
- if (pzlib_filefunc_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
- zlib_filefunc64_32_def_fill.ztell32_file = NULL;
- zlib_filefunc64_32_def_fill.zseek32_file = NULL;
- return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
- }
- else
- return zipOpen3(pathname, append, globalcomment, NULL);
-}
-
-
-
-extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
-{
- return zipOpen3((const void*)pathname,append,NULL,NULL);
-}
-
-extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
-{
- return zipOpen3(pathname,append,NULL,NULL);
-}
-
-int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
-{
- /* write the local header */
- int err;
- uInt size_filename = (uInt)strlen(filename);
- uInt size_extrafield = size_extrafield_local;
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
-
- if (err==ZIP_OK)
- {
- if(zi->ci.zip64)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
- }
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
-
- // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
- if (err==ZIP_OK)
- {
- if(zi->ci.zip64)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
- }
- if (err==ZIP_OK)
- {
- if(zi->ci.zip64)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
- }
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
-
- if(zi->ci.zip64)
- {
- size_extrafield += 20;
- }
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
-
- if ((err==ZIP_OK) && (size_filename > 0))
- {
- if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
- err = ZIP_ERRNO;
- }
-
- if ((err==ZIP_OK) && (size_extrafield_local > 0))
- {
- if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
- err = ZIP_ERRNO;
- }
-
-
- if ((err==ZIP_OK) && (zi->ci.zip64))
- {
- // write the Zip64 extended info
- short HeaderID = 1;
- short DataSize = 16;
- ZPOS64_T CompressedSize = 0;
- ZPOS64_T UncompressedSize = 0;
-
- // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
- zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
-
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
-
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
- }
-
- return err;
-}
-
-/*
- NOTE.
- When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped
- before calling this function it can be done with zipRemoveExtraInfoBlock
-
- It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
- unnecessary allocations.
- */
-extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting,
- uLong versionMadeBy, uLong flagBase, int zip64)
-{
- zip64_internal* zi;
- uInt size_filename;
- uInt size_comment;
- uInt i;
- int err = ZIP_OK;
-
-# ifdef NOCRYPT
- if (password != NULL)
- return ZIP_PARAMERROR;
-# endif
-
- if (file == NULL)
- return ZIP_PARAMERROR;
-
-#ifdef HAVE_BZIP2
- if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
- return ZIP_PARAMERROR;
-#else
- if ((method!=0) && (method!=Z_DEFLATED))
- return ZIP_PARAMERROR;
-#endif
-
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 1)
- {
- err = zipCloseFileInZip (file);
- if (err != ZIP_OK)
- return err;
- }
-
- if (filename==NULL)
- filename="-";
-
- if (comment==NULL)
- size_comment = 0;
- else
- size_comment = (uInt)strlen(comment);
-
- size_filename = (uInt)strlen(filename);
-
- if (zipfi == NULL)
- zi->ci.dosDate = 0;
- else
- {
- if (zipfi->dosDate != 0)
- zi->ci.dosDate = zipfi->dosDate;
- else
- zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
- }
-
- zi->ci.flag = flagBase;
- if ((level==8) || (level==9))
- zi->ci.flag |= 2;
- if ((level==2))
- zi->ci.flag |= 4;
- if ((level==1))
- zi->ci.flag |= 6;
- if (password != NULL)
- zi->ci.flag |= 1;
-
- zi->ci.crc32 = 0;
- zi->ci.method = method;
- zi->ci.encrypt = 0;
- zi->ci.stream_initialised = 0;
- zi->ci.pos_in_buffered_data = 0;
- zi->ci.raw = raw;
- zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
-
- zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
- zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
-
- zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
-
- zi->ci.size_centralExtra = size_extrafield_global;
- zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
- /* version info */
- zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
- zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
- zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
- zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
- zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
- zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
- zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
- zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
- zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
- zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
- zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
- zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
-
- if (zipfi==NULL)
- zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
- else
- zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
-
- if (zipfi==NULL)
- zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
- else
- zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
-
- if(zi->ci.pos_local_header >= 0xffffffff)
- zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
- else
- zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4);
-
- for (i=0;i<size_filename;i++)
- *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
-
- for (i=0;i<size_extrafield_global;i++)
- *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
- *(((const char*)extrafield_global)+i);
-
- for (i=0;i<size_comment;i++)
- *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
- size_extrafield_global+i) = *(comment+i);
- if (zi->ci.central_header == NULL)
- return ZIP_INTERNALERROR;
-
- zi->ci.zip64 = zip64;
- zi->ci.totalCompressedData = 0;
- zi->ci.totalUncompressedData = 0;
- zi->ci.pos_zip64extrainfo = 0;
-
- err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
-
-#ifdef HAVE_BZIP2
- zi->ci.bstream.avail_in = (uInt)0;
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
- zi->ci.bstream.total_in_hi32 = 0;
- zi->ci.bstream.total_in_lo32 = 0;
- zi->ci.bstream.total_out_hi32 = 0;
- zi->ci.bstream.total_out_lo32 = 0;
-#endif
-
- zi->ci.stream.avail_in = (uInt)0;
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.stream.next_out = zi->ci.buffered_data;
- zi->ci.stream.total_in = 0;
- zi->ci.stream.total_out = 0;
- zi->ci.stream.data_type = Z_BINARY;
-
-#ifdef HAVE_BZIP2
- if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
-#else
- if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
-#endif
- {
- if(zi->ci.method == Z_DEFLATED)
- {
- zi->ci.stream.zalloc = (alloc_func)0;
- zi->ci.stream.zfree = (free_func)0;
- zi->ci.stream.opaque = (voidpf)0;
-
- if (windowBits>0)
- windowBits = -windowBits;
-
- err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
-
- if (err==Z_OK)
- zi->ci.stream_initialised = Z_DEFLATED;
- }
- else if(zi->ci.method == Z_BZIP2ED)
- {
-#ifdef HAVE_BZIP2
- // Init BZip stuff here
- zi->ci.bstream.bzalloc = 0;
- zi->ci.bstream.bzfree = 0;
- zi->ci.bstream.opaque = (voidpf)0;
-
- err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
- if(err == BZ_OK)
- zi->ci.stream_initialised = Z_BZIP2ED;
-#endif
- }
-
- }
-
-# ifndef NOCRYPT
- zi->ci.crypt_header_size = 0;
- if ((err==Z_OK) && (password != NULL))
- {
- unsigned char bufHead[RAND_HEAD_LEN];
- unsigned int sizeHead;
- zi->ci.encrypt = 1;
- zi->ci.pcrc_32_tab = get_crc_table();
- /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
-
- sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
- zi->ci.crypt_header_size = sizeHead;
-
- if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
- err = ZIP_ERRNO;
- }
-# endif
-
- if (err==Z_OK)
- zi->in_opened_file_inzip = 1;
- return err;
-}
-
-extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting,
- uLong versionMadeBy, uLong flagBase)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- windowBits, memLevel, strategy,
- password, crcForCrypting, versionMadeBy, flagBase, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- windowBits, memLevel, strategy,
- password, crcForCrypting, VERSIONMADEBY, 0, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting, int zip64)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- windowBits, memLevel, strategy,
- password, crcForCrypting, VERSIONMADEBY, 0, zip64);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw, int zip64)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, zip64);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void*extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int zip64)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, 0,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, zip64);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void*extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, 0,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, 0);
-}
-
-local int zip64FlushWriteBuffer(zip64_internal* zi)
-{
- int err=ZIP_OK;
-
- if (zi->ci.encrypt != 0)
- {
-#ifndef NOCRYPT
- uInt i;
- int t;
- for (i=0;i<zi->ci.pos_in_buffered_data;i++)
- zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
-#endif
- }
-
- if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
- err = ZIP_ERRNO;
-
- zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
-
-#ifdef HAVE_BZIP2
- if(zi->ci.method == Z_BZIP2ED)
- {
- zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
- zi->ci.bstream.total_in_lo32 = 0;
- zi->ci.bstream.total_in_hi32 = 0;
- }
- else
-#endif
- {
- zi->ci.totalUncompressedData += zi->ci.stream.total_in;
- zi->ci.stream.total_in = 0;
- }
-
-
- zi->ci.pos_in_buffered_data = 0;
-
- return err;
-}
-
-extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
-{
- zip64_internal* zi;
- int err=ZIP_OK;
-
- if (file == NULL)
- return ZIP_PARAMERROR;
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 0)
- return ZIP_PARAMERROR;
-
- zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
-
-#ifdef HAVE_BZIP2
- if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
- {
- zi->ci.bstream.next_in = (void*)buf;
- zi->ci.bstream.avail_in = len;
- err = BZ_RUN_OK;
-
- while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
- {
- if (zi->ci.bstream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
- }
-
-
- if(err != BZ_RUN_OK)
- break;
-
- if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
- {
- uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
-// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
- err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
- }
- }
-
- if(err == BZ_RUN_OK)
- err = ZIP_OK;
- }
- else
-#endif
- {
- zi->ci.stream.next_in = (Bytef*)buf;
- zi->ci.stream.avail_in = len;
-
- while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
- {
- if (zi->ci.stream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.stream.next_out = zi->ci.buffered_data;
- }
-
-
- if(err != ZIP_OK)
- break;
-
- if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
- {
- uLong uTotalOutBefore = zi->ci.stream.total_out;
- err=deflate(&zi->ci.stream, Z_NO_FLUSH);
- if(uTotalOutBefore > zi->ci.stream.total_out)
- {
- int bBreak = 0;
- bBreak++;
- }
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
- }
- else
- {
- uInt copy_this,i;
- if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
- copy_this = zi->ci.stream.avail_in;
- else
- copy_this = zi->ci.stream.avail_out;
-
- for (i = 0; i < copy_this; i++)
- *(((char*)zi->ci.stream.next_out)+i) =
- *(((const char*)zi->ci.stream.next_in)+i);
- {
- zi->ci.stream.avail_in -= copy_this;
- zi->ci.stream.avail_out-= copy_this;
- zi->ci.stream.next_in+= copy_this;
- zi->ci.stream.next_out+= copy_this;
- zi->ci.stream.total_in+= copy_this;
- zi->ci.stream.total_out+= copy_this;
- zi->ci.pos_in_buffered_data += copy_this;
- }
- }
- }// while(...)
- }
-
- return err;
-}
-
-extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
-{
- return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
-}
-
-extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
-{
- zip64_internal* zi;
- ZPOS64_T compressed_size;
- uLong invalidValue = 0xffffffff;
- short datasize = 0;
- int err=ZIP_OK;
-
- if (file == NULL)
- return ZIP_PARAMERROR;
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 0)
- return ZIP_PARAMERROR;
- zi->ci.stream.avail_in = 0;
-
- if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
- {
- while (err==ZIP_OK)
- {
- uLong uTotalOutBefore;
- if (zi->ci.stream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.stream.next_out = zi->ci.buffered_data;
- }
- uTotalOutBefore = zi->ci.stream.total_out;
- err=deflate(&zi->ci.stream, Z_FINISH);
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
- }
- }
- else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
- {
-#ifdef HAVE_BZIP2
- err = BZ_FINISH_OK;
- while (err==BZ_FINISH_OK)
- {
- uLong uTotalOutBefore;
- if (zi->ci.bstream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
- }
- uTotalOutBefore = zi->ci.bstream.total_out_lo32;
- err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
- if(err == BZ_STREAM_END)
- err = Z_STREAM_END;
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
- }
-
- if(err == BZ_FINISH_OK)
- err = ZIP_OK;
-#endif
- }
-
- if (err==Z_STREAM_END)
- err=ZIP_OK; /* this is normal */
-
- if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
- {
- if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
- err = ZIP_ERRNO;
- }
-
- if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
- {
- int tmp_err = deflateEnd(&zi->ci.stream);
- if (err == ZIP_OK)
- err = tmp_err;
- zi->ci.stream_initialised = 0;
- }
-#ifdef HAVE_BZIP2
- else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
- {
- int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
- if (err==ZIP_OK)
- err = tmperr;
- zi->ci.stream_initialised = 0;
- }
-#endif
-
- if (!zi->ci.raw)
- {
- crc32 = (uLong)zi->ci.crc32;
- uncompressed_size = zi->ci.totalUncompressedData;
- }
- compressed_size = zi->ci.totalCompressedData;
-
-# ifndef NOCRYPT
- compressed_size += zi->ci.crypt_header_size;
-# endif
-
- // update Current Item crc and sizes,
- if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
- {
- /*version Made by*/
- zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
- /*version needed*/
- zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
-
- }
-
- zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
-
-
- if(compressed_size >= 0xffffffff)
- zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
- else
- zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
-
- /// set internal file attributes field
- if (zi->ci.stream.data_type == Z_ASCII)
- zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
-
- if(uncompressed_size >= 0xffffffff)
- zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
- else
- zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
-
- // Add ZIP64 extra info field for uncompressed size
- if(uncompressed_size >= 0xffffffff)
- datasize += 8;
-
- // Add ZIP64 extra info field for compressed size
- if(compressed_size >= 0xffffffff)
- datasize += 8;
-
- // Add ZIP64 extra info field for relative offset to local file header of current file
- if(zi->ci.pos_local_header >= 0xffffffff)
- datasize += 8;
-
- if(datasize > 0)
- {
- char* p = NULL;
-
- if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
- {
- // we can not write more data to the buffer that we have room for.
- return ZIP_BADZIPFILE;
- }
-
- p = zi->ci.central_header + zi->ci.size_centralheader;
-
- // Add Extra Information Header for 'ZIP64 information'
- zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
- p += 2;
- zip64local_putValue_inmemory(p, datasize, 2); // DataSize
- p += 2;
-
- if(uncompressed_size >= 0xffffffff)
- {
- zip64local_putValue_inmemory(p, uncompressed_size, 8);
- p += 8;
- }
-
- if(compressed_size >= 0xffffffff)
- {
- zip64local_putValue_inmemory(p, compressed_size, 8);
- p += 8;
- }
-
- if(zi->ci.pos_local_header >= 0xffffffff)
- {
- zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
- p += 8;
- }
-
- // Update how much extra free space we got in the memory buffer
- // and increase the centralheader size so the new ZIP64 fields are included
- // ( 4 below is the size of HeaderID and DataSize field )
- zi->ci.size_centralExtraFree -= datasize + 4;
- zi->ci.size_centralheader += datasize + 4;
-
- // Update the extra info size field
- zi->ci.size_centralExtra += datasize + 4;
- zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
- }
-
- if (err==ZIP_OK)
- err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
-
- free(zi->ci.central_header);
-
- if (err==ZIP_OK)
- {
- // Update the LocalFileHeader with the new values.
-
- ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
-
- if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err = ZIP_ERRNO;
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
-
- if(uncompressed_size >= 0xffffffff)
- {
- if(zi->ci.pos_zip64extrainfo > 0)
- {
- // Update the size in the ZIP64 extended field.
- if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err = ZIP_ERRNO;
-
- if (err==ZIP_OK) /* compressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
-
- if (err==ZIP_OK) /* uncompressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
- }
- }
- else
- {
- if (err==ZIP_OK) /* compressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
-
- if (err==ZIP_OK) /* uncompressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
- }
-
- if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err = ZIP_ERRNO;
- }
-
- zi->number_entry ++;
- zi->in_opened_file_inzip = 0;
-
- return err;
-}
-
-extern int ZEXPORT zipCloseFileInZip (zipFile file)
-{
- return zipCloseFileInZipRaw (file,0,0);
-}
-
-int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
-{
- int err = ZIP_OK;
- ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
-
- /*num disks*/
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
-
- /*relative offset*/
- if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
-
- /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
-
- return err;
-}
-
-int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
-{
- int err = ZIP_OK;
-
- uLong Zip64DataSize = 44;
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
-
- if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
-
- if (err==ZIP_OK) /* version made by */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
-
- if (err==ZIP_OK) /* version needed */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
-
- if (err==ZIP_OK) /* number of this disk */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
-
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
-
- if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
-
- if (err==ZIP_OK) /* total number of entries in the central dir */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
-
- if (err==ZIP_OK) /* size of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
-
- if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
- {
- ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
- }
- return err;
-}
-int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
-{
- int err = ZIP_OK;
-
- /*signature*/
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
-
- if (err==ZIP_OK) /* number of this disk */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
-
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
-
- if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
- {
- {
- if(zi->number_entry >= 0xFFFF)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
- }
- }
-
- if (err==ZIP_OK) /* total number of entries in the central dir */
- {
- if(zi->number_entry >= 0xFFFF)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
- }
-
- if (err==ZIP_OK) /* size of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
-
- if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
- {
- ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
- if(pos >= 0xffffffff)
- {
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
- }
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
- }
-
- return err;
-}
-
-int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
-{
- int err = ZIP_OK;
- uInt size_global_comment = 0;
-
- if(global_comment != NULL)
- size_global_comment = (uInt)strlen(global_comment);
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
-
- if (err == ZIP_OK && size_global_comment > 0)
- {
- if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
- err = ZIP_ERRNO;
- }
- return err;
-}
-
-extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
-{
- zip64_internal* zi;
- int err = 0;
- uLong size_centraldir = 0;
- ZPOS64_T centraldir_pos_inzip;
- ZPOS64_T pos;
-
- if (file == NULL)
- return ZIP_PARAMERROR;
-
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 1)
- {
- err = zipCloseFileInZip (file);
- }
-
-#ifndef NO_ADDFILEINEXISTINGZIP
- if (global_comment==NULL)
- global_comment = zi->globalcomment;
-#endif
-
- centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
-
- if (err==ZIP_OK)
- {
- linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
- while (ldi!=NULL)
- {
- if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
- {
- if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
- err = ZIP_ERRNO;
- }
-
- size_centraldir += ldi->filled_in_this_block;
- ldi = ldi->next_datablock;
- }
- }
- free_linkedlist(&(zi->central_dir));
-
- pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
- if(pos >= 0xffffffff)
- {
- ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
- Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
-
- Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
- }
-
- if (err==ZIP_OK)
- err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
-
- if(err == ZIP_OK)
- err = Write_GlobalComment(zi, global_comment);
-
- if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
- if (err == ZIP_OK)
- err = ZIP_ERRNO;
-
-#ifndef NO_ADDFILEINEXISTINGZIP
- TRYFREE(zi->globalcomment);
-#endif
- TRYFREE(zi);
-
- return err;
-}
-
-extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
-{
- char* p = pData;
- int size = 0;
- char* pNewHeader;
- char* pTmp;
- short header;
- short dataSize;
-
- int retVal = ZIP_OK;
-
- if(pData == NULL || *dataLen < 4)
- return ZIP_PARAMERROR;
-
- pNewHeader = (char*)ALLOC(*dataLen);
- pTmp = pNewHeader;
-
- while(p < (pData + *dataLen))
- {
- header = *(short*)p;
- dataSize = *(((short*)p)+1);
-
- if( header == sHeader ) // Header found.
- {
- p += dataSize + 4; // skip it. do not copy to temp buffer
- }
- else
- {
- // Extra Info block should not be removed, So copy it to the temp buffer.
- memcpy(pTmp, p, dataSize + 4);
- p += dataSize + 4;
- size += dataSize + 4;
- }
-
- }
-
- if(size < *dataLen)
- {
- // clean old extra info block.
- memset(pData,0, *dataLen);
-
- // copy the new extra info block over the old
- if(size > 0)
- memcpy(pData, pNewHeader, size);
-
- // set the new extra info size
- *dataLen = size;
-
- retVal = ZIP_OK;
- }
- else
- retVal = ZIP_ERRNO;
-
- TRYFREE(pNewHeader);
-
- return retVal;
-}
diff --git a/cpukit/zlib/contrib/minizip/zip.h b/cpukit/zlib/contrib/minizip/zip.h
deleted file mode 100644
index 8aaebb6234..0000000000
--- a/cpukit/zlib/contrib/minizip/zip.h
+++ /dev/null
@@ -1,362 +0,0 @@
-/* zip.h -- IO on .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- ---------------------------------------------------------------------------
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- ---------------------------------------------------------------------------
-
- Changes
-
- See header of zip.h
-
-*/
-
-#ifndef _zip12_H
-#define _zip12_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//#define HAVE_BZIP2
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#ifdef HAVE_BZIP2
-#include "bzlib.h"
-#endif
-
-#define Z_BZIP2ED 12
-
-#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagzipFile__ { int unused; } zipFile__;
-typedef zipFile__ *zipFile;
-#else
-typedef voidp zipFile;
-#endif
-
-#define ZIP_OK (0)
-#define ZIP_EOF (0)
-#define ZIP_ERRNO (Z_ERRNO)
-#define ZIP_PARAMERROR (-102)
-#define ZIP_BADZIPFILE (-103)
-#define ZIP_INTERNALERROR (-104)
-
-#ifndef DEF_MEM_LEVEL
-# if MAX_MEM_LEVEL >= 8
-# define DEF_MEM_LEVEL 8
-# else
-# define DEF_MEM_LEVEL MAX_MEM_LEVEL
-# endif
-#endif
-/* default memLevel */
-
-/* tm_zip contain date/time info */
-typedef struct tm_zip_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_zip;
-
-typedef struct
-{
- tm_zip tmz_date; /* date in understandable format */
- uLong dosDate; /* if dos_date == 0, tmu_date is used */
-/* uLong flag; */ /* general purpose bit flag 2 bytes */
-
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-} zip_fileinfo;
-
-typedef const char* zipcharpc;
-
-
-#define APPEND_STATUS_CREATE (0)
-#define APPEND_STATUS_CREATEAFTER (1)
-#define APPEND_STATUS_ADDINZIP (2)
-
-extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
-extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
-/*
- Create a zipfile.
- pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
- an Unix computer "zlib/zlib113.zip".
- if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
- will be created at the end of the file.
- (useful if the file contain a self extractor code)
- if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
- add files in existing zip (be sure you don't add file that doesn't exist)
- If the zipfile cannot be opened, the return value is NULL.
- Else, the return value is a zipFile Handle, usable with other function
- of this zip package.
-*/
-
-/* Note : there is no delete function into a zipfile.
- If you want delete file into a zipfile, you must open a zipfile, and create another
- Of couse, you can use RAW reading and writing to copy the file you did not want delte
-*/
-
-extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
- int append,
- zipcharpc* globalcomment,
- zlib_filefunc_def* pzlib_filefunc_def));
-
-extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
- int append,
- zipcharpc* globalcomment,
- zlib_filefunc64_def* pzlib_filefunc_def));
-
-extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level));
-
-extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int zip64));
-
-/*
- Open a file in the ZIP for writing.
- filename : the filename in zip (if NULL, '-' without quote will be used
- *zipfi contain supplemental information
- if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
- contains the extrafield data the the local header
- if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
- contains the extrafield data the the local header
- if comment != NULL, comment contain the comment string
- method contain the compression method (0 for store, Z_DEFLATED for deflate)
- level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
- zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
- this MUST be '1' if the uncompressed size is >= 0xffffffff.
-
-*/
-
-
-extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw));
-
-
-extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int zip64));
-/*
- Same than zipOpenNewFileInZip, except if raw=1, we write raw file
- */
-
-extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting));
-
-extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting,
- int zip64
- ));
-
-/*
- Same than zipOpenNewFileInZip2, except
- windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
- password : crypting password (NULL for no crypting)
- crcForCrypting : crc of file to compress (needed for crypting)
- */
-
-extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting,
- uLong versionMadeBy,
- uLong flagBase
- ));
-
-
-extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting,
- uLong versionMadeBy,
- uLong flagBase,
- int zip64
- ));
-/*
- Same than zipOpenNewFileInZip4, except
- versionMadeBy : value for Version made by field
- flag : value for flag field (compression level info will be added)
- */
-
-
-extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
- const void* buf,
- unsigned len));
-/*
- Write data in the zipfile
-*/
-
-extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
-/*
- Close the current file in the zipfile
-*/
-
-extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
- uLong uncompressed_size,
- uLong crc32));
-
-extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
- ZPOS64_T uncompressed_size,
- uLong crc32));
-
-/*
- Close the current file in the zipfile, for file opened with
- parameter raw=1 in zipOpenNewFileInZip2
- uncompressed_size and crc32 are value for the uncompressed size
-*/
-
-extern int ZEXPORT zipClose OF((zipFile file,
- const char* global_comment));
-/*
- Close the zipfile
-*/
-
-
-extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
-/*
- zipRemoveExtraInfoBlock - Added by Mathias Svensson
-
- Remove extra information block from a extra information data for the local file header or central directory header
-
- It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
-
- 0x0001 is the signature header for the ZIP64 extra information blocks
-
- usage.
- Remove ZIP64 Extra information from a central director extra field data
- zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
-
- Remove ZIP64 Extra information from a Local File Header extra field data
- zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _zip64_H */
diff --git a/cpukit/zlib/contrib/pascal/example.pas b/cpukit/zlib/contrib/pascal/example.pas
deleted file mode 100644
index 5518b36a73..0000000000
--- a/cpukit/zlib/contrib/pascal/example.pas
+++ /dev/null
@@ -1,599 +0,0 @@
-(* example.c -- usage example of the zlib compression library
- * Copyright (C) 1995-2003 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- *
- * Pascal translation
- * Copyright (C) 1998 by Jacques Nomssi Nzali.
- * For conditions of distribution and use, see copyright notice in readme.txt
- *
- * Adaptation to the zlibpas interface
- * Copyright (C) 2003 by Cosmin Truta.
- * For conditions of distribution and use, see copyright notice in readme.txt
- *)
-
-program example;
-
-{$DEFINE TEST_COMPRESS}
-{DO NOT $DEFINE TEST_GZIO}
-{$DEFINE TEST_DEFLATE}
-{$DEFINE TEST_INFLATE}
-{$DEFINE TEST_FLUSH}
-{$DEFINE TEST_SYNC}
-{$DEFINE TEST_DICT}
-
-uses SysUtils, zlibpas;
-
-const TESTFILE = 'foo.gz';
-
-(* "hello world" would be more standard, but the repeated "hello"
- * stresses the compression code better, sorry...
- *)
-const hello: PChar = 'hello, hello!';
-
-const dictionary: PChar = 'hello';
-
-var dictId: LongInt; (* Adler32 value of the dictionary *)
-
-procedure CHECK_ERR(err: Integer; msg: String);
-begin
- if err <> Z_OK then
- begin
- WriteLn(msg, ' error: ', err);
- Halt(1);
- end;
-end;
-
-procedure EXIT_ERR(const msg: String);
-begin
- WriteLn('Error: ', msg);
- Halt(1);
-end;
-
-(* ===========================================================================
- * Test compress and uncompress
- *)
-{$IFDEF TEST_COMPRESS}
-procedure test_compress(compr: Pointer; comprLen: LongInt;
- uncompr: Pointer; uncomprLen: LongInt);
-var err: Integer;
- len: LongInt;
-begin
- len := StrLen(hello)+1;
-
- err := compress(compr, comprLen, hello, len);
- CHECK_ERR(err, 'compress');
-
- StrCopy(PChar(uncompr), 'garbage');
-
- err := uncompress(uncompr, uncomprLen, compr, comprLen);
- CHECK_ERR(err, 'uncompress');
-
- if StrComp(PChar(uncompr), hello) <> 0 then
- EXIT_ERR('bad uncompress')
- else
- WriteLn('uncompress(): ', PChar(uncompr));
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test read/write of .gz files
- *)
-{$IFDEF TEST_GZIO}
-procedure test_gzio(const fname: PChar; (* compressed file name *)
- uncompr: Pointer;
- uncomprLen: LongInt);
-var err: Integer;
- len: Integer;
- zfile: gzFile;
- pos: LongInt;
-begin
- len := StrLen(hello)+1;
-
- zfile := gzopen(fname, 'wb');
- if zfile = NIL then
- begin
- WriteLn('gzopen error');
- Halt(1);
- end;
- gzputc(zfile, 'h');
- if gzputs(zfile, 'ello') <> 4 then
- begin
- WriteLn('gzputs err: ', gzerror(zfile, err));
- Halt(1);
- end;
- {$IFDEF GZ_FORMAT_STRING}
- if gzprintf(zfile, ', %s!', 'hello') <> 8 then
- begin
- WriteLn('gzprintf err: ', gzerror(zfile, err));
- Halt(1);
- end;
- {$ELSE}
- if gzputs(zfile, ', hello!') <> 8 then
- begin
- WriteLn('gzputs err: ', gzerror(zfile, err));
- Halt(1);
- end;
- {$ENDIF}
- gzseek(zfile, 1, SEEK_CUR); (* add one zero byte *)
- gzclose(zfile);
-
- zfile := gzopen(fname, 'rb');
- if zfile = NIL then
- begin
- WriteLn('gzopen error');
- Halt(1);
- end;
-
- StrCopy(PChar(uncompr), 'garbage');
-
- if gzread(zfile, uncompr, uncomprLen) <> len then
- begin
- WriteLn('gzread err: ', gzerror(zfile, err));
- Halt(1);
- end;
- if StrComp(PChar(uncompr), hello) <> 0 then
- begin
- WriteLn('bad gzread: ', PChar(uncompr));
- Halt(1);
- end
- else
- WriteLn('gzread(): ', PChar(uncompr));
-
- pos := gzseek(zfile, -8, SEEK_CUR);
- if (pos <> 6) or (gztell(zfile) <> pos) then
- begin
- WriteLn('gzseek error, pos=', pos, ', gztell=', gztell(zfile));
- Halt(1);
- end;
-
- if gzgetc(zfile) <> ' ' then
- begin
- WriteLn('gzgetc error');
- Halt(1);
- end;
-
- if gzungetc(' ', zfile) <> ' ' then
- begin
- WriteLn('gzungetc error');
- Halt(1);
- end;
-
- gzgets(zfile, PChar(uncompr), uncomprLen);
- uncomprLen := StrLen(PChar(uncompr));
- if uncomprLen <> 7 then (* " hello!" *)
- begin
- WriteLn('gzgets err after gzseek: ', gzerror(zfile, err));
- Halt(1);
- end;
- if StrComp(PChar(uncompr), hello + 6) <> 0 then
- begin
- WriteLn('bad gzgets after gzseek');
- Halt(1);
- end
- else
- WriteLn('gzgets() after gzseek: ', PChar(uncompr));
-
- gzclose(zfile);
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test deflate with small buffers
- *)
-{$IFDEF TEST_DEFLATE}
-procedure test_deflate(compr: Pointer; comprLen: LongInt);
-var c_stream: z_stream; (* compression stream *)
- err: Integer;
- len: LongInt;
-begin
- len := StrLen(hello)+1;
-
- c_stream.zalloc := NIL;
- c_stream.zfree := NIL;
- c_stream.opaque := NIL;
-
- err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION);
- CHECK_ERR(err, 'deflateInit');
-
- c_stream.next_in := hello;
- c_stream.next_out := compr;
-
- while (c_stream.total_in <> len) and
- (c_stream.total_out < comprLen) do
- begin
- c_stream.avail_out := 1; { force small buffers }
- c_stream.avail_in := 1;
- err := deflate(c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, 'deflate');
- end;
-
- (* Finish the stream, still forcing small buffers: *)
- while TRUE do
- begin
- c_stream.avail_out := 1;
- err := deflate(c_stream, Z_FINISH);
- if err = Z_STREAM_END then
- break;
- CHECK_ERR(err, 'deflate');
- end;
-
- err := deflateEnd(c_stream);
- CHECK_ERR(err, 'deflateEnd');
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test inflate with small buffers
- *)
-{$IFDEF TEST_INFLATE}
-procedure test_inflate(compr: Pointer; comprLen : LongInt;
- uncompr: Pointer; uncomprLen : LongInt);
-var err: Integer;
- d_stream: z_stream; (* decompression stream *)
-begin
- StrCopy(PChar(uncompr), 'garbage');
-
- d_stream.zalloc := NIL;
- d_stream.zfree := NIL;
- d_stream.opaque := NIL;
-
- d_stream.next_in := compr;
- d_stream.avail_in := 0;
- d_stream.next_out := uncompr;
-
- err := inflateInit(d_stream);
- CHECK_ERR(err, 'inflateInit');
-
- while (d_stream.total_out < uncomprLen) and
- (d_stream.total_in < comprLen) do
- begin
- d_stream.avail_out := 1; (* force small buffers *)
- d_stream.avail_in := 1;
- err := inflate(d_stream, Z_NO_FLUSH);
- if err = Z_STREAM_END then
- break;
- CHECK_ERR(err, 'inflate');
- end;
-
- err := inflateEnd(d_stream);
- CHECK_ERR(err, 'inflateEnd');
-
- if StrComp(PChar(uncompr), hello) <> 0 then
- EXIT_ERR('bad inflate')
- else
- WriteLn('inflate(): ', PChar(uncompr));
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test deflate with large buffers and dynamic change of compression level
- *)
-{$IFDEF TEST_DEFLATE}
-procedure test_large_deflate(compr: Pointer; comprLen: LongInt;
- uncompr: Pointer; uncomprLen: LongInt);
-var c_stream: z_stream; (* compression stream *)
- err: Integer;
-begin
- c_stream.zalloc := NIL;
- c_stream.zfree := NIL;
- c_stream.opaque := NIL;
-
- err := deflateInit(c_stream, Z_BEST_SPEED);
- CHECK_ERR(err, 'deflateInit');
-
- c_stream.next_out := compr;
- c_stream.avail_out := Integer(comprLen);
-
- (* At this point, uncompr is still mostly zeroes, so it should compress
- * very well:
- *)
- c_stream.next_in := uncompr;
- c_stream.avail_in := Integer(uncomprLen);
- err := deflate(c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, 'deflate');
- if c_stream.avail_in <> 0 then
- EXIT_ERR('deflate not greedy');
-
- (* Feed in already compressed data and switch to no compression: *)
- deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
- c_stream.next_in := compr;
- c_stream.avail_in := Integer(comprLen div 2);
- err := deflate(c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, 'deflate');
-
- (* Switch back to compressing mode: *)
- deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
- c_stream.next_in := uncompr;
- c_stream.avail_in := Integer(uncomprLen);
- err := deflate(c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, 'deflate');
-
- err := deflate(c_stream, Z_FINISH);
- if err <> Z_STREAM_END then
- EXIT_ERR('deflate should report Z_STREAM_END');
-
- err := deflateEnd(c_stream);
- CHECK_ERR(err, 'deflateEnd');
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test inflate with large buffers
- *)
-{$IFDEF TEST_INFLATE}
-procedure test_large_inflate(compr: Pointer; comprLen: LongInt;
- uncompr: Pointer; uncomprLen: LongInt);
-var err: Integer;
- d_stream: z_stream; (* decompression stream *)
-begin
- StrCopy(PChar(uncompr), 'garbage');
-
- d_stream.zalloc := NIL;
- d_stream.zfree := NIL;
- d_stream.opaque := NIL;
-
- d_stream.next_in := compr;
- d_stream.avail_in := Integer(comprLen);
-
- err := inflateInit(d_stream);
- CHECK_ERR(err, 'inflateInit');
-
- while TRUE do
- begin
- d_stream.next_out := uncompr; (* discard the output *)
- d_stream.avail_out := Integer(uncomprLen);
- err := inflate(d_stream, Z_NO_FLUSH);
- if err = Z_STREAM_END then
- break;
- CHECK_ERR(err, 'large inflate');
- end;
-
- err := inflateEnd(d_stream);
- CHECK_ERR(err, 'inflateEnd');
-
- if d_stream.total_out <> 2 * uncomprLen + comprLen div 2 then
- begin
- WriteLn('bad large inflate: ', d_stream.total_out);
- Halt(1);
- end
- else
- WriteLn('large_inflate(): OK');
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test deflate with full flush
- *)
-{$IFDEF TEST_FLUSH}
-procedure test_flush(compr: Pointer; var comprLen : LongInt);
-var c_stream: z_stream; (* compression stream *)
- err: Integer;
- len: Integer;
-begin
- len := StrLen(hello)+1;
-
- c_stream.zalloc := NIL;
- c_stream.zfree := NIL;
- c_stream.opaque := NIL;
-
- err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION);
- CHECK_ERR(err, 'deflateInit');
-
- c_stream.next_in := hello;
- c_stream.next_out := compr;
- c_stream.avail_in := 3;
- c_stream.avail_out := Integer(comprLen);
- err := deflate(c_stream, Z_FULL_FLUSH);
- CHECK_ERR(err, 'deflate');
-
- Inc(PByteArray(compr)^[3]); (* force an error in first compressed block *)
- c_stream.avail_in := len - 3;
-
- err := deflate(c_stream, Z_FINISH);
- if err <> Z_STREAM_END then
- CHECK_ERR(err, 'deflate');
-
- err := deflateEnd(c_stream);
- CHECK_ERR(err, 'deflateEnd');
-
- comprLen := c_stream.total_out;
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test inflateSync()
- *)
-{$IFDEF TEST_SYNC}
-procedure test_sync(compr: Pointer; comprLen: LongInt;
- uncompr: Pointer; uncomprLen : LongInt);
-var err: Integer;
- d_stream: z_stream; (* decompression stream *)
-begin
- StrCopy(PChar(uncompr), 'garbage');
-
- d_stream.zalloc := NIL;
- d_stream.zfree := NIL;
- d_stream.opaque := NIL;
-
- d_stream.next_in := compr;
- d_stream.avail_in := 2; (* just read the zlib header *)
-
- err := inflateInit(d_stream);
- CHECK_ERR(err, 'inflateInit');
-
- d_stream.next_out := uncompr;
- d_stream.avail_out := Integer(uncomprLen);
-
- inflate(d_stream, Z_NO_FLUSH);
- CHECK_ERR(err, 'inflate');
-
- d_stream.avail_in := Integer(comprLen-2); (* read all compressed data *)
- err := inflateSync(d_stream); (* but skip the damaged part *)
- CHECK_ERR(err, 'inflateSync');
-
- err := inflate(d_stream, Z_FINISH);
- if err <> Z_DATA_ERROR then
- EXIT_ERR('inflate should report DATA_ERROR');
- (* Because of incorrect adler32 *)
-
- err := inflateEnd(d_stream);
- CHECK_ERR(err, 'inflateEnd');
-
- WriteLn('after inflateSync(): hel', PChar(uncompr));
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test deflate with preset dictionary
- *)
-{$IFDEF TEST_DICT}
-procedure test_dict_deflate(compr: Pointer; comprLen: LongInt);
-var c_stream: z_stream; (* compression stream *)
- err: Integer;
-begin
- c_stream.zalloc := NIL;
- c_stream.zfree := NIL;
- c_stream.opaque := NIL;
-
- err := deflateInit(c_stream, Z_BEST_COMPRESSION);
- CHECK_ERR(err, 'deflateInit');
-
- err := deflateSetDictionary(c_stream, dictionary, StrLen(dictionary));
- CHECK_ERR(err, 'deflateSetDictionary');
-
- dictId := c_stream.adler;
- c_stream.next_out := compr;
- c_stream.avail_out := Integer(comprLen);
-
- c_stream.next_in := hello;
- c_stream.avail_in := StrLen(hello)+1;
-
- err := deflate(c_stream, Z_FINISH);
- if err <> Z_STREAM_END then
- EXIT_ERR('deflate should report Z_STREAM_END');
-
- err := deflateEnd(c_stream);
- CHECK_ERR(err, 'deflateEnd');
-end;
-{$ENDIF}
-
-(* ===========================================================================
- * Test inflate with a preset dictionary
- *)
-{$IFDEF TEST_DICT}
-procedure test_dict_inflate(compr: Pointer; comprLen: LongInt;
- uncompr: Pointer; uncomprLen: LongInt);
-var err: Integer;
- d_stream: z_stream; (* decompression stream *)
-begin
- StrCopy(PChar(uncompr), 'garbage');
-
- d_stream.zalloc := NIL;
- d_stream.zfree := NIL;
- d_stream.opaque := NIL;
-
- d_stream.next_in := compr;
- d_stream.avail_in := Integer(comprLen);
-
- err := inflateInit(d_stream);
- CHECK_ERR(err, 'inflateInit');
-
- d_stream.next_out := uncompr;
- d_stream.avail_out := Integer(uncomprLen);
-
- while TRUE do
- begin
- err := inflate(d_stream, Z_NO_FLUSH);
- if err = Z_STREAM_END then
- break;
- if err = Z_NEED_DICT then
- begin
- if d_stream.adler <> dictId then
- EXIT_ERR('unexpected dictionary');
- err := inflateSetDictionary(d_stream, dictionary, StrLen(dictionary));
- end;
- CHECK_ERR(err, 'inflate with dict');
- end;
-
- err := inflateEnd(d_stream);
- CHECK_ERR(err, 'inflateEnd');
-
- if StrComp(PChar(uncompr), hello) <> 0 then
- EXIT_ERR('bad inflate with dict')
- else
- WriteLn('inflate with dictionary: ', PChar(uncompr));
-end;
-{$ENDIF}
-
-var compr, uncompr: Pointer;
- comprLen, uncomprLen: LongInt;
-
-begin
- if zlibVersion^ <> ZLIB_VERSION[1] then
- EXIT_ERR('Incompatible zlib version');
-
- WriteLn('zlib version: ', zlibVersion);
- WriteLn('zlib compile flags: ', Format('0x%x', [zlibCompileFlags]));
-
- comprLen := 10000 * SizeOf(Integer); (* don't overflow on MSDOS *)
- uncomprLen := comprLen;
- GetMem(compr, comprLen);
- GetMem(uncompr, uncomprLen);
- if (compr = NIL) or (uncompr = NIL) then
- EXIT_ERR('Out of memory');
- (* compr and uncompr are cleared to avoid reading uninitialized
- * data and to ensure that uncompr compresses well.
- *)
- FillChar(compr^, comprLen, 0);
- FillChar(uncompr^, uncomprLen, 0);
-
- {$IFDEF TEST_COMPRESS}
- WriteLn('** Testing compress');
- test_compress(compr, comprLen, uncompr, uncomprLen);
- {$ENDIF}
-
- {$IFDEF TEST_GZIO}
- WriteLn('** Testing gzio');
- if ParamCount >= 1 then
- test_gzio(ParamStr(1), uncompr, uncomprLen)
- else
- test_gzio(TESTFILE, uncompr, uncomprLen);
- {$ENDIF}
-
- {$IFDEF TEST_DEFLATE}
- WriteLn('** Testing deflate with small buffers');
- test_deflate(compr, comprLen);
- {$ENDIF}
- {$IFDEF TEST_INFLATE}
- WriteLn('** Testing inflate with small buffers');
- test_inflate(compr, comprLen, uncompr, uncomprLen);
- {$ENDIF}
-
- {$IFDEF TEST_DEFLATE}
- WriteLn('** Testing deflate with large buffers');
- test_large_deflate(compr, comprLen, uncompr, uncomprLen);
- {$ENDIF}
- {$IFDEF TEST_INFLATE}
- WriteLn('** Testing inflate with large buffers');
- test_large_inflate(compr, comprLen, uncompr, uncomprLen);
- {$ENDIF}
-
- {$IFDEF TEST_FLUSH}
- WriteLn('** Testing deflate with full flush');
- test_flush(compr, comprLen);
- {$ENDIF}
- {$IFDEF TEST_SYNC}
- WriteLn('** Testing inflateSync');
- test_sync(compr, comprLen, uncompr, uncomprLen);
- {$ENDIF}
- comprLen := uncomprLen;
-
- {$IFDEF TEST_DICT}
- WriteLn('** Testing deflate and inflate with preset dictionary');
- test_dict_deflate(compr, comprLen);
- test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
- {$ENDIF}
-
- FreeMem(compr, comprLen);
- FreeMem(uncompr, uncomprLen);
-end.
diff --git a/cpukit/zlib/contrib/pascal/readme.txt b/cpukit/zlib/contrib/pascal/readme.txt
deleted file mode 100644
index 60e87c8a33..0000000000
--- a/cpukit/zlib/contrib/pascal/readme.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-
-This directory contains a Pascal (Delphi, Kylix) interface to the
-zlib data compression library.
-
-
-Directory listing
-=================
-
-zlibd32.mak makefile for Borland C++
-example.pas usage example of zlib
-zlibpas.pas the Pascal interface to zlib
-readme.txt this file
-
-
-Compatibility notes
-===================
-
-- Although the name "zlib" would have been more normal for the
- zlibpas unit, this name is already taken by Borland's ZLib unit.
- This is somehow unfortunate, because that unit is not a genuine
- interface to the full-fledged zlib functionality, but a suite of
- class wrappers around zlib streams. Other essential features,
- such as checksums, are missing.
- It would have been more appropriate for that unit to have a name
- like "ZStreams", or something similar.
-
-- The C and zlib-supplied types int, uInt, long, uLong, etc. are
- translated directly into Pascal types of similar sizes (Integer,
- LongInt, etc.), to avoid namespace pollution. In particular,
- there is no conversion of unsigned int into a Pascal unsigned
- integer. The Word type is non-portable and has the same size
- (16 bits) both in a 16-bit and in a 32-bit environment, unlike
- Integer. Even if there is a 32-bit Cardinal type, there is no
- real need for unsigned int in zlib under a 32-bit environment.
-
-- Except for the callbacks, the zlib function interfaces are
- assuming the calling convention normally used in Pascal
- (__pascal for DOS and Windows16, __fastcall for Windows32).
- Since the cdecl keyword is used, the old Turbo Pascal does
- not work with this interface.
-
-- The gz* function interfaces are not translated, to avoid
- interfacing problems with the C runtime library. Besides,
- gzprintf(gzFile file, const char *format, ...)
- cannot be translated into Pascal.
-
-
-Legal issues
-============
-
-The zlibpas interface is:
- Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler.
- Copyright (C) 1998 by Bob Dellaca.
- Copyright (C) 2003 by Cosmin Truta.
-
-The example program is:
- Copyright (C) 1995-2003 by Jean-loup Gailly.
- Copyright (C) 1998,1999,2000 by Jacques Nomssi Nzali.
- Copyright (C) 2003 by Cosmin Truta.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
diff --git a/cpukit/zlib/contrib/pascal/zlibd32.mak b/cpukit/zlib/contrib/pascal/zlibd32.mak
deleted file mode 100644
index 0d0699a69a..0000000000
--- a/cpukit/zlib/contrib/pascal/zlibd32.mak
+++ /dev/null
@@ -1,99 +0,0 @@
-# Makefile for zlib
-# For use with Delphi and C++ Builder under Win32
-# Updated for zlib 1.2.x by Cosmin Truta
-
-# ------------ Borland C++ ------------
-
-# This project uses the Delphi (fastcall/register) calling convention:
-LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl
-
-CC = bcc32
-LD = bcc32
-AR = tlib
-# do not use "-pr" in CFLAGS
-CFLAGS = -a -d -k- -O2 $(LOC)
-LDFLAGS =
-
-
-# variables
-ZLIB_LIB = zlib.lib
-
-OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj
-OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj
-OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
-
-
-# targets
-all: $(ZLIB_LIB) example.exe minigzip.exe
-
-.c.obj:
- $(CC) -c $(CFLAGS) $*.c
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-example.obj: example.c zlib.h zconf.h
-
-minigzip.obj: minigzip.c zlib.h zconf.h
-
-
-# For the sake of the old Borland make,
-# the command line is cut to fit in the MS-DOS 128 byte limit:
-$(ZLIB_LIB): $(OBJ1) $(OBJ2)
- -del $(ZLIB_LIB)
- $(AR) $(ZLIB_LIB) $(OBJP1)
- $(AR) $(ZLIB_LIB) $(OBJP2)
-
-
-# testing
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-example.exe: example.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
-
-minigzip.exe: minigzip.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
-
-
-# cleanup
-clean:
- -del *.obj
- -del *.exe
- -del *.lib
- -del *.tds
- -del zlib.bak
- -del foo.gz
-
diff --git a/cpukit/zlib/contrib/pascal/zlibpas.pas b/cpukit/zlib/contrib/pascal/zlibpas.pas
deleted file mode 100644
index dc7d37dae0..0000000000
--- a/cpukit/zlib/contrib/pascal/zlibpas.pas
+++ /dev/null
@@ -1,236 +0,0 @@
-(* zlibpas -- Pascal interface to the zlib data compression library
- *
- * Copyright (C) 2003 Cosmin Truta.
- * Derived from original sources by Bob Dellaca.
- * For conditions of distribution and use, see copyright notice in readme.txt
- *)
-
-unit zlibpas;
-
-interface
-
-const
- ZLIB_VERSION = '1.2.4';
-
-type
- alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
- cdecl;
- free_func = procedure(opaque, address: Pointer);
- cdecl;
-
- in_func = function(opaque: Pointer; var buf: PByte): Integer;
- cdecl;
- out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer;
- cdecl;
-
- z_streamp = ^z_stream;
- z_stream = packed record
- next_in: PChar; (* next input byte *)
- avail_in: Integer; (* number of bytes available at next_in *)
- total_in: LongInt; (* total nb of input bytes read so far *)
-
- next_out: PChar; (* next output byte should be put there *)
- avail_out: Integer; (* remaining free space at next_out *)
- total_out: LongInt; (* total nb of bytes output so far *)
-
- msg: PChar; (* last error message, NULL if no error *)
- state: Pointer; (* not visible by applications *)
-
- zalloc: alloc_func; (* used to allocate the internal state *)
- zfree: free_func; (* used to free the internal state *)
- opaque: Pointer; (* private data object passed to zalloc and zfree *)
-
- data_type: Integer; (* best guess about the data type: ascii or binary *)
- adler: LongInt; (* adler32 value of the uncompressed data *)
- reserved: LongInt; (* reserved for future use *)
- end;
-
-(* constants *)
-const
- Z_NO_FLUSH = 0;
- Z_PARTIAL_FLUSH = 1;
- Z_SYNC_FLUSH = 2;
- Z_FULL_FLUSH = 3;
- Z_FINISH = 4;
-
- Z_OK = 0;
- Z_STREAM_END = 1;
- Z_NEED_DICT = 2;
- Z_ERRNO = -1;
- Z_STREAM_ERROR = -2;
- Z_DATA_ERROR = -3;
- Z_MEM_ERROR = -4;
- Z_BUF_ERROR = -5;
- Z_VERSION_ERROR = -6;
-
- Z_NO_COMPRESSION = 0;
- Z_BEST_SPEED = 1;
- Z_BEST_COMPRESSION = 9;
- Z_DEFAULT_COMPRESSION = -1;
-
- Z_FILTERED = 1;
- Z_HUFFMAN_ONLY = 2;
- Z_RLE = 3;
- Z_DEFAULT_STRATEGY = 0;
-
- Z_BINARY = 0;
- Z_ASCII = 1;
- Z_UNKNOWN = 2;
-
- Z_DEFLATED = 8;
-
-(* basic functions *)
-function zlibVersion: PChar;
-function deflateInit(var strm: z_stream; level: Integer): Integer;
-function deflate(var strm: z_stream; flush: Integer): Integer;
-function deflateEnd(var strm: z_stream): Integer;
-function inflateInit(var strm: z_stream): Integer;
-function inflate(var strm: z_stream; flush: Integer): Integer;
-function inflateEnd(var strm: z_stream): Integer;
-
-(* advanced functions *)
-function deflateInit2(var strm: z_stream; level, method, windowBits,
- memLevel, strategy: Integer): Integer;
-function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
- dictLength: Integer): Integer;
-function deflateCopy(var dest, source: z_stream): Integer;
-function deflateReset(var strm: z_stream): Integer;
-function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
-function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
-function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
-function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
-function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
- dictLength: Integer): Integer;
-function inflateSync(var strm: z_stream): Integer;
-function inflateCopy(var dest, source: z_stream): Integer;
-function inflateReset(var strm: z_stream): Integer;
-function inflateBackInit(var strm: z_stream;
- windowBits: Integer; window: PChar): Integer;
-function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
- out_fn: out_func; out_desc: Pointer): Integer;
-function inflateBackEnd(var strm: z_stream): Integer;
-function zlibCompileFlags: LongInt;
-
-(* utility functions *)
-function compress(dest: PChar; var destLen: LongInt;
- const source: PChar; sourceLen: LongInt): Integer;
-function compress2(dest: PChar; var destLen: LongInt;
- const source: PChar; sourceLen: LongInt;
- level: Integer): Integer;
-function compressBound(sourceLen: LongInt): LongInt;
-function uncompress(dest: PChar; var destLen: LongInt;
- const source: PChar; sourceLen: LongInt): Integer;
-
-(* checksum functions *)
-function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
-function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
-
-(* various hacks, don't look :) *)
-function deflateInit_(var strm: z_stream; level: Integer;
- const version: PChar; stream_size: Integer): Integer;
-function inflateInit_(var strm: z_stream; const version: PChar;
- stream_size: Integer): Integer;
-function deflateInit2_(var strm: z_stream;
- level, method, windowBits, memLevel, strategy: Integer;
- const version: PChar; stream_size: Integer): Integer;
-function inflateInit2_(var strm: z_stream; windowBits: Integer;
- const version: PChar; stream_size: Integer): Integer;
-function inflateBackInit_(var strm: z_stream;
- windowBits: Integer; window: PChar;
- const version: PChar; stream_size: Integer): Integer;
-
-
-implementation
-
-{$L adler32.obj}
-{$L compress.obj}
-{$L crc32.obj}
-{$L deflate.obj}
-{$L infback.obj}
-{$L inffast.obj}
-{$L inflate.obj}
-{$L inftrees.obj}
-{$L trees.obj}
-{$L uncompr.obj}
-{$L zutil.obj}
-
-function adler32; external;
-function compress; external;
-function compress2; external;
-function compressBound; external;
-function crc32; external;
-function deflate; external;
-function deflateBound; external;
-function deflateCopy; external;
-function deflateEnd; external;
-function deflateInit_; external;
-function deflateInit2_; external;
-function deflateParams; external;
-function deflatePrime; external;
-function deflateReset; external;
-function deflateSetDictionary; external;
-function inflate; external;
-function inflateBack; external;
-function inflateBackEnd; external;
-function inflateBackInit_; external;
-function inflateCopy; external;
-function inflateEnd; external;
-function inflateInit_; external;
-function inflateInit2_; external;
-function inflateReset; external;
-function inflateSetDictionary; external;
-function inflateSync; external;
-function uncompress; external;
-function zlibCompileFlags; external;
-function zlibVersion; external;
-
-function deflateInit(var strm: z_stream; level: Integer): Integer;
-begin
- Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
-end;
-
-function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
- strategy: Integer): Integer;
-begin
- Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
- ZLIB_VERSION, sizeof(z_stream));
-end;
-
-function inflateInit(var strm: z_stream): Integer;
-begin
- Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
-end;
-
-function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
-begin
- Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
-end;
-
-function inflateBackInit(var strm: z_stream;
- windowBits: Integer; window: PChar): Integer;
-begin
- Result := inflateBackInit_(strm, windowBits, window,
- ZLIB_VERSION, sizeof(z_stream));
-end;
-
-function _malloc(Size: Integer): Pointer; cdecl;
-begin
- GetMem(Result, Size);
-end;
-
-procedure _free(Block: Pointer); cdecl;
-begin
- FreeMem(Block);
-end;
-
-procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
-begin
- FillChar(P^, count, B);
-end;
-
-procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
-begin
- Move(source^, dest^, count);
-end;
-
-end.
diff --git a/cpukit/zlib/contrib/puff/Makefile b/cpukit/zlib/contrib/puff/Makefile
deleted file mode 100644
index b6b69404c7..0000000000
--- a/cpukit/zlib/contrib/puff/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-puff: puff.c puff.h
- cc -DTEST -o puff puff.c
-
-test: puff
- puff zeros.raw
-
-clean:
- rm -f puff puff.o
diff --git a/cpukit/zlib/contrib/puff/README b/cpukit/zlib/contrib/puff/README
deleted file mode 100644
index bbc4cb595e..0000000000
--- a/cpukit/zlib/contrib/puff/README
+++ /dev/null
@@ -1,63 +0,0 @@
-Puff -- A Simple Inflate
-3 Mar 2003
-Mark Adler
-madler@alumni.caltech.edu
-
-What this is --
-
-puff.c provides the routine puff() to decompress the deflate data format. It
-does so more slowly than zlib, but the code is about one-fifth the size of the
-inflate code in zlib, and written to be very easy to read.
-
-Why I wrote this --
-
-puff.c was written to document the deflate format unambiguously, by virtue of
-being working C code. It is meant to supplement RFC 1951, which formally
-describes the deflate format. I have received many questions on details of the
-deflate format, and I hope that reading this code will answer those questions.
-puff.c is heavily commented with details of the deflate format, especially
-those little nooks and cranies of the format that might not be obvious from a
-specification.
-
-puff.c may also be useful in applications where code size or memory usage is a
-very limited resource, and speed is not as important.
-
-How to use it --
-
-Well, most likely you should just be reading puff.c and using zlib for actual
-applications, but if you must ...
-
-Include puff.h in your code, which provides this prototype:
-
-int puff(unsigned char *dest, /* pointer to destination pointer */
- unsigned long *destlen, /* amount of output space */
- unsigned char *source, /* pointer to source data pointer */
- unsigned long *sourcelen); /* amount of input available */
-
-Then you can call puff() to decompress a deflate stream that is in memory in
-its entirety at source, to a sufficiently sized block of memory for the
-decompressed data at dest. puff() is the only external symbol in puff.c The
-only C library functions that puff.c needs are setjmp() and longjmp(), which
-are used to simplify error checking in the code to improve readabilty. puff.c
-does no memory allocation, and uses less than 2K bytes off of the stack.
-
-If destlen is not enough space for the uncompressed data, then inflate will
-return an error without writing more than destlen bytes. Note that this means
-that in order to decompress the deflate data successfully, you need to know
-the size of the uncompressed data ahead of time.
-
-If needed, puff() can determine the size of the uncompressed data with no
-output space. This is done by passing dest equal to (unsigned char *)0. Then
-the initial value of *destlen is ignored and *destlen is set to the length of
-the uncompressed data. So if the size of the uncompressed data is not known,
-then two passes of puff() can be used--first to determine the size, and second
-to do the actual inflation after allocating the appropriate memory. Not
-pretty, but it works. (This is one of the reasons you should be using zlib.)
-
-The deflate format is self-terminating. If the deflate stream does not end
-in *sourcelen bytes, puff() will return an error without reading at or past
-endsource.
-
-On return, *sourcelen is updated to the amount of input data consumed, and
-*destlen is updated to the size of the uncompressed data. See the comments
-in puff.c for the possible return codes for puff().
diff --git a/cpukit/zlib/contrib/puff/puff.c b/cpukit/zlib/contrib/puff/puff.c
deleted file mode 100644
index 650694e9ed..0000000000
--- a/cpukit/zlib/contrib/puff/puff.c
+++ /dev/null
@@ -1,955 +0,0 @@
-/*
- * puff.c
- * Copyright (C) 2002-2010 Mark Adler
- * For conditions of distribution and use, see copyright notice in puff.h
- * version 2.1, 4 Apr 2010
- *
- * puff.c is a simple inflate written to be an unambiguous way to specify the
- * deflate format. It is not written for speed but rather simplicity. As a
- * side benefit, this code might actually be useful when small code is more
- * important than speed, such as bootstrap applications. For typical deflate
- * data, zlib's inflate() is about four times as fast as puff(). zlib's
- * inflate compiles to around 20K on my machine, whereas puff.c compiles to
- * around 4K on my machine (a PowerPC using GNU cc). If the faster decode()
- * function here is used, then puff() is only twice as slow as zlib's
- * inflate().
- *
- * All dynamically allocated memory comes from the stack. The stack required
- * is less than 2K bytes. This code is compatible with 16-bit int's and
- * assumes that long's are at least 32 bits. puff.c uses the short data type,
- * assumed to be 16 bits, for arrays in order to to conserve memory. The code
- * works whether integers are stored big endian or little endian.
- *
- * In the comments below are "Format notes" that describe the inflate process
- * and document some of the less obvious aspects of the format. This source
- * code is meant to supplement RFC 1951, which formally describes the deflate
- * format:
- *
- * http://www.zlib.org/rfc-deflate.html
- */
-
-/*
- * Change history:
- *
- * 1.0 10 Feb 2002 - First version
- * 1.1 17 Feb 2002 - Clarifications of some comments and notes
- * - Update puff() dest and source pointers on negative
- * errors to facilitate debugging deflators
- * - Remove longest from struct huffman -- not needed
- * - Simplify offs[] index in construct()
- * - Add input size and checking, using longjmp() to
- * maintain easy readability
- * - Use short data type for large arrays
- * - Use pointers instead of long to specify source and
- * destination sizes to avoid arbitrary 4 GB limits
- * 1.2 17 Mar 2002 - Add faster version of decode(), doubles speed (!),
- * but leave simple version for readabilty
- * - Make sure invalid distances detected if pointers
- * are 16 bits
- * - Fix fixed codes table error
- * - Provide a scanning mode for determining size of
- * uncompressed data
- * 1.3 20 Mar 2002 - Go back to lengths for puff() parameters [Jean-loup]
- * - Add a puff.h file for the interface
- * - Add braces in puff() for else do [Jean-loup]
- * - Use indexes instead of pointers for readability
- * 1.4 31 Mar 2002 - Simplify construct() code set check
- * - Fix some comments
- * - Add FIXLCODES #define
- * 1.5 6 Apr 2002 - Minor comment fixes
- * 1.6 7 Aug 2002 - Minor format changes
- * 1.7 3 Mar 2003 - Added test code for distribution
- * - Added zlib-like license
- * 1.8 9 Jan 2004 - Added some comments on no distance codes case
- * 1.9 21 Feb 2008 - Fix bug on 16-bit integer architectures [Pohland]
- * - Catch missing end-of-block symbol error
- * 2.0 25 Jul 2008 - Add #define to permit distance too far back
- * - Add option in TEST code for puff to write the data
- * - Add option in TEST code to skip input bytes
- * - Allow TEST code to read from piped stdin
- * 2.1 4 Apr 2010 - Avoid variable initialization for happier compilers
- * - Avoid unsigned comparisons for even happier compilers
- */
-
-#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
-#include "puff.h" /* prototype for puff() */
-
-#define local static /* for local function definitions */
-#define NIL ((unsigned char *)0) /* for no output option */
-
-/*
- * Maximums for allocations and loops. It is not useful to change these --
- * they are fixed by the deflate format.
- */
-#define MAXBITS 15 /* maximum bits in a code */
-#define MAXLCODES 286 /* maximum number of literal/length codes */
-#define MAXDCODES 30 /* maximum number of distance codes */
-#define MAXCODES (MAXLCODES+MAXDCODES) /* maximum codes lengths to read */
-#define FIXLCODES 288 /* number of fixed literal/length codes */
-
-/* input and output state */
-struct state {
- /* output state */
- unsigned char *out; /* output buffer */
- unsigned long outlen; /* available space at out */
- unsigned long outcnt; /* bytes written to out so far */
-
- /* input state */
- unsigned char *in; /* input buffer */
- unsigned long inlen; /* available input at in */
- unsigned long incnt; /* bytes read so far */
- int bitbuf; /* bit buffer */
- int bitcnt; /* number of bits in bit buffer */
-
- /* input limit error return state for bits() and decode() */
- jmp_buf env;
-};
-
-/*
- * Return need bits from the input stream. This always leaves less than
- * eight bits in the buffer. bits() works properly for need == 0.
- *
- * Format notes:
- *
- * - Bits are stored in bytes from the least significant bit to the most
- * significant bit. Therefore bits are dropped from the bottom of the bit
- * buffer, using shift right, and new bytes are appended to the top of the
- * bit buffer, using shift left.
- */
-local int bits(struct state *s, int need)
-{
- long val; /* bit accumulator (can use up to 20 bits) */
-
- /* load at least need bits into val */
- val = s->bitbuf;
- while (s->bitcnt < need) {
- if (s->incnt == s->inlen) longjmp(s->env, 1); /* out of input */
- val |= (long)(s->in[s->incnt++]) << s->bitcnt; /* load eight bits */
- s->bitcnt += 8;
- }
-
- /* drop need bits and update buffer, always zero to seven bits left */
- s->bitbuf = (int)(val >> need);
- s->bitcnt -= need;
-
- /* return need bits, zeroing the bits above that */
- return (int)(val & ((1L << need) - 1));
-}
-
-/*
- * Process a stored block.
- *
- * Format notes:
- *
- * - After the two-bit stored block type (00), the stored block length and
- * stored bytes are byte-aligned for fast copying. Therefore any leftover
- * bits in the byte that has the last bit of the type, as many as seven, are
- * discarded. The value of the discarded bits are not defined and should not
- * be checked against any expectation.
- *
- * - The second inverted copy of the stored block length does not have to be
- * checked, but it's probably a good idea to do so anyway.
- *
- * - A stored block can have zero length. This is sometimes used to byte-align
- * subsets of the compressed data for random access or partial recovery.
- */
-local int stored(struct state *s)
-{
- unsigned len; /* length of stored block */
-
- /* discard leftover bits from current byte (assumes s->bitcnt < 8) */
- s->bitbuf = 0;
- s->bitcnt = 0;
-
- /* get length and check against its one's complement */
- if (s->incnt + 4 > s->inlen) return 2; /* not enough input */
- len = s->in[s->incnt++];
- len |= s->in[s->incnt++] << 8;
- if (s->in[s->incnt++] != (~len & 0xff) ||
- s->in[s->incnt++] != ((~len >> 8) & 0xff))
- return -2; /* didn't match complement! */
-
- /* copy len bytes from in to out */
- if (s->incnt + len > s->inlen) return 2; /* not enough input */
- if (s->out != NIL) {
- if (s->outcnt + len > s->outlen)
- return 1; /* not enough output space */
- while (len--)
- s->out[s->outcnt++] = s->in[s->incnt++];
- }
- else { /* just scanning */
- s->outcnt += len;
- s->incnt += len;
- }
-
- /* done with a valid stored block */
- return 0;
-}
-
-/*
- * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of
- * each length, which for a canonical code are stepped through in order.
- * symbol[] are the symbol values in canonical order, where the number of
- * entries is the sum of the counts in count[]. The decoding process can be
- * seen in the function decode() below.
- */
-struct huffman {
- short *count; /* number of symbols of each length */
- short *symbol; /* canonically ordered symbols */
-};
-
-/*
- * Decode a code from the stream s using huffman table h. Return the symbol or
- * a negative value if there is an error. If all of the lengths are zero, i.e.
- * an empty code, or if the code is incomplete and an invalid code is received,
- * then -10 is returned after reading MAXBITS bits.
- *
- * Format notes:
- *
- * - The codes as stored in the compressed data are bit-reversed relative to
- * a simple integer ordering of codes of the same lengths. Hence below the
- * bits are pulled from the compressed data one at a time and used to
- * build the code value reversed from what is in the stream in order to
- * permit simple integer comparisons for decoding. A table-based decoding
- * scheme (as used in zlib) does not need to do this reversal.
- *
- * - The first code for the shortest length is all zeros. Subsequent codes of
- * the same length are simply integer increments of the previous code. When
- * moving up a length, a zero bit is appended to the code. For a complete
- * code, the last code of the longest length will be all ones.
- *
- * - Incomplete codes are handled by this decoder, since they are permitted
- * in the deflate format. See the format notes for fixed() and dynamic().
- */
-#ifdef SLOW
-local int decode(struct state *s, struct huffman *h)
-{
- int len; /* current number of bits in code */
- int code; /* len bits being decoded */
- int first; /* first code of length len */
- int count; /* number of codes of length len */
- int index; /* index of first code of length len in symbol table */
-
- code = first = index = 0;
- for (len = 1; len <= MAXBITS; len++) {
- code |= bits(s, 1); /* get next bit */
- count = h->count[len];
- if (code - count < first) /* if length len, return symbol */
- return h->symbol[index + (code - first)];
- index += count; /* else update for next length */
- first += count;
- first <<= 1;
- code <<= 1;
- }
- return -10; /* ran out of codes */
-}
-
-/*
- * A faster version of decode() for real applications of this code. It's not
- * as readable, but it makes puff() twice as fast. And it only makes the code
- * a few percent larger.
- */
-#else /* !SLOW */
-local int decode(struct state *s, struct huffman *h)
-{
- int len; /* current number of bits in code */
- int code; /* len bits being decoded */
- int first; /* first code of length len */
- int count; /* number of codes of length len */
- int index; /* index of first code of length len in symbol table */
- int bitbuf; /* bits from stream */
- int left; /* bits left in next or left to process */
- short *next; /* next number of codes */
-
- bitbuf = s->bitbuf;
- left = s->bitcnt;
- code = first = index = 0;
- len = 1;
- next = h->count + 1;
- while (1) {
- while (left--) {
- code |= bitbuf & 1;
- bitbuf >>= 1;
- count = *next++;
- if (code - count < first) { /* if length len, return symbol */
- s->bitbuf = bitbuf;
- s->bitcnt = (s->bitcnt - len) & 7;
- return h->symbol[index + (code - first)];
- }
- index += count; /* else update for next length */
- first += count;
- first <<= 1;
- code <<= 1;
- len++;
- }
- left = (MAXBITS+1) - len;
- if (left == 0) break;
- if (s->incnt == s->inlen) longjmp(s->env, 1); /* out of input */
- bitbuf = s->in[s->incnt++];
- if (left > 8) left = 8;
- }
- return -10; /* ran out of codes */
-}
-#endif /* SLOW */
-
-/*
- * Given the list of code lengths length[0..n-1] representing a canonical
- * Huffman code for n symbols, construct the tables required to decode those
- * codes. Those tables are the number of codes of each length, and the symbols
- * sorted by length, retaining their original order within each length. The
- * return value is zero for a complete code set, negative for an over-
- * subscribed code set, and positive for an incomplete code set. The tables
- * can be used if the return value is zero or positive, but they cannot be used
- * if the return value is negative. If the return value is zero, it is not
- * possible for decode() using that table to return an error--any stream of
- * enough bits will resolve to a symbol. If the return value is positive, then
- * it is possible for decode() using that table to return an error for received
- * codes past the end of the incomplete lengths.
- *
- * Not used by decode(), but used for error checking, h->count[0] is the number
- * of the n symbols not in the code. So n - h->count[0] is the number of
- * codes. This is useful for checking for incomplete codes that have more than
- * one symbol, which is an error in a dynamic block.
- *
- * Assumption: for all i in 0..n-1, 0 <= length[i] <= MAXBITS
- * This is assured by the construction of the length arrays in dynamic() and
- * fixed() and is not verified by construct().
- *
- * Format notes:
- *
- * - Permitted and expected examples of incomplete codes are one of the fixed
- * codes and any code with a single symbol which in deflate is coded as one
- * bit instead of zero bits. See the format notes for fixed() and dynamic().
- *
- * - Within a given code length, the symbols are kept in ascending order for
- * the code bits definition.
- */
-local int construct(struct huffman *h, short *length, int n)
-{
- int symbol; /* current symbol when stepping through length[] */
- int len; /* current length when stepping through h->count[] */
- int left; /* number of possible codes left of current length */
- short offs[MAXBITS+1]; /* offsets in symbol table for each length */
-
- /* count number of codes of each length */
- for (len = 0; len <= MAXBITS; len++)
- h->count[len] = 0;
- for (symbol = 0; symbol < n; symbol++)
- (h->count[length[symbol]])++; /* assumes lengths are within bounds */
- if (h->count[0] == n) /* no codes! */
- return 0; /* complete, but decode() will fail */
-
- /* check for an over-subscribed or incomplete set of lengths */
- left = 1; /* one possible code of zero length */
- for (len = 1; len <= MAXBITS; len++) {
- left <<= 1; /* one more bit, double codes left */
- left -= h->count[len]; /* deduct count from possible codes */
- if (left < 0) return left; /* over-subscribed--return negative */
- } /* left > 0 means incomplete */
-
- /* generate offsets into symbol table for each length for sorting */
- offs[1] = 0;
- for (len = 1; len < MAXBITS; len++)
- offs[len + 1] = offs[len] + h->count[len];
-
- /*
- * put symbols in table sorted by length, by symbol order within each
- * length
- */
- for (symbol = 0; symbol < n; symbol++)
- if (length[symbol] != 0)
- h->symbol[offs[length[symbol]]++] = symbol;
-
- /* return zero for complete set, positive for incomplete set */
- return left;
-}
-
-/*
- * Decode literal/length and distance codes until an end-of-block code.
- *
- * Format notes:
- *
- * - Compressed data that is after the block type if fixed or after the code
- * description if dynamic is a combination of literals and length/distance
- * pairs terminated by and end-of-block code. Literals are simply Huffman
- * coded bytes. A length/distance pair is a coded length followed by a
- * coded distance to represent a string that occurs earlier in the
- * uncompressed data that occurs again at the current location.
- *
- * - Literals, lengths, and the end-of-block code are combined into a single
- * code of up to 286 symbols. They are 256 literals (0..255), 29 length
- * symbols (257..285), and the end-of-block symbol (256).
- *
- * - There are 256 possible lengths (3..258), and so 29 symbols are not enough
- * to represent all of those. Lengths 3..10 and 258 are in fact represented
- * by just a length symbol. Lengths 11..257 are represented as a symbol and
- * some number of extra bits that are added as an integer to the base length
- * of the length symbol. The number of extra bits is determined by the base
- * length symbol. These are in the static arrays below, lens[] for the base
- * lengths and lext[] for the corresponding number of extra bits.
- *
- * - The reason that 258 gets its own symbol is that the longest length is used
- * often in highly redundant files. Note that 258 can also be coded as the
- * base value 227 plus the maximum extra value of 31. While a good deflate
- * should never do this, it is not an error, and should be decoded properly.
- *
- * - If a length is decoded, including its extra bits if any, then it is
- * followed a distance code. There are up to 30 distance symbols. Again
- * there are many more possible distances (1..32768), so extra bits are added
- * to a base value represented by the symbol. The distances 1..4 get their
- * own symbol, but the rest require extra bits. The base distances and
- * corresponding number of extra bits are below in the static arrays dist[]
- * and dext[].
- *
- * - Literal bytes are simply written to the output. A length/distance pair is
- * an instruction to copy previously uncompressed bytes to the output. The
- * copy is from distance bytes back in the output stream, copying for length
- * bytes.
- *
- * - Distances pointing before the beginning of the output data are not
- * permitted.
- *
- * - Overlapped copies, where the length is greater than the distance, are
- * allowed and common. For example, a distance of one and a length of 258
- * simply copies the last byte 258 times. A distance of four and a length of
- * twelve copies the last four bytes three times. A simple forward copy
- * ignoring whether the length is greater than the distance or not implements
- * this correctly. You should not use memcpy() since its behavior is not
- * defined for overlapped arrays. You should not use memmove() or bcopy()
- * since though their behavior -is- defined for overlapping arrays, it is
- * defined to do the wrong thing in this case.
- */
-local int codes(struct state *s,
- struct huffman *lencode,
- struct huffman *distcode)
-{
- int symbol; /* decoded symbol */
- int len; /* length for copy */
- unsigned dist; /* distance for copy */
- static const short lens[29] = { /* Size base for length codes 257..285 */
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
- 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
- static const short lext[29] = { /* Extra bits for length codes 257..285 */
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
- static const short dists[30] = { /* Offset base for distance codes 0..29 */
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
- 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
- 8193, 12289, 16385, 24577};
- static const short dext[30] = { /* Extra bits for distance codes 0..29 */
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
- 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
- 12, 12, 13, 13};
-
- /* decode literals and length/distance pairs */
- do {
- symbol = decode(s, lencode);
- if (symbol < 0) return symbol; /* invalid symbol */
- if (symbol < 256) { /* literal: symbol is the byte */
- /* write out the literal */
- if (s->out != NIL) {
- if (s->outcnt == s->outlen) return 1;
- s->out[s->outcnt] = symbol;
- }
- s->outcnt++;
- }
- else if (symbol > 256) { /* length */
- /* get and compute length */
- symbol -= 257;
- if (symbol >= 29) return -10; /* invalid fixed code */
- len = lens[symbol] + bits(s, lext[symbol]);
-
- /* get and check distance */
- symbol = decode(s, distcode);
- if (symbol < 0) return symbol; /* invalid symbol */
- dist = dists[symbol] + bits(s, dext[symbol]);
-#ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- if (dist > s->outcnt)
- return -11; /* distance too far back */
-#endif
-
- /* copy length bytes from distance bytes back */
- if (s->out != NIL) {
- if (s->outcnt + len > s->outlen) return 1;
- while (len--) {
- s->out[s->outcnt] =
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- dist > s->outcnt ? 0 :
-#endif
- s->out[s->outcnt - dist];
- s->outcnt++;
- }
- }
- else
- s->outcnt += len;
- }
- } while (symbol != 256); /* end of block symbol */
-
- /* done with a valid fixed or dynamic block */
- return 0;
-}
-
-/*
- * Process a fixed codes block.
- *
- * Format notes:
- *
- * - This block type can be useful for compressing small amounts of data for
- * which the size of the code descriptions in a dynamic block exceeds the
- * benefit of custom codes for that block. For fixed codes, no bits are
- * spent on code descriptions. Instead the code lengths for literal/length
- * codes and distance codes are fixed. The specific lengths for each symbol
- * can be seen in the "for" loops below.
- *
- * - The literal/length code is complete, but has two symbols that are invalid
- * and should result in an error if received. This cannot be implemented
- * simply as an incomplete code since those two symbols are in the "middle"
- * of the code. They are eight bits long and the longest literal/length\
- * code is nine bits. Therefore the code must be constructed with those
- * symbols, and the invalid symbols must be detected after decoding.
- *
- * - The fixed distance codes also have two invalid symbols that should result
- * in an error if received. Since all of the distance codes are the same
- * length, this can be implemented as an incomplete code. Then the invalid
- * codes are detected while decoding.
- */
-local int fixed(struct state *s)
-{
- static int virgin = 1;
- static short lencnt[MAXBITS+1], lensym[FIXLCODES];
- static short distcnt[MAXBITS+1], distsym[MAXDCODES];
- static struct huffman lencode, distcode;
-
- /* build fixed huffman tables if first call (may not be thread safe) */
- if (virgin) {
- int symbol;
- short lengths[FIXLCODES];
-
- /* literal/length table */
- for (symbol = 0; symbol < 144; symbol++)
- lengths[symbol] = 8;
- for (; symbol < 256; symbol++)
- lengths[symbol] = 9;
- for (; symbol < 280; symbol++)
- lengths[symbol] = 7;
- for (; symbol < FIXLCODES; symbol++)
- lengths[symbol] = 8;
- construct(&lencode, lengths, FIXLCODES);
-
- /* distance table */
- for (symbol = 0; symbol < MAXDCODES; symbol++)
- lengths[symbol] = 5;
- construct(&distcode, lengths, MAXDCODES);
-
- /* construct lencode and distcode */
- lencode.count = lencnt;
- lencode.symbol = lensym;
- distcode.count = distcnt;
- distcode.symbol = distsym;
-
- /* do this just once */
- virgin = 0;
- }
-
- /* decode data until end-of-block code */
- return codes(s, &lencode, &distcode);
-}
-
-/*
- * Process a dynamic codes block.
- *
- * Format notes:
- *
- * - A dynamic block starts with a description of the literal/length and
- * distance codes for that block. New dynamic blocks allow the compressor to
- * rapidly adapt to changing data with new codes optimized for that data.
- *
- * - The codes used by the deflate format are "canonical", which means that
- * the actual bits of the codes are generated in an unambiguous way simply
- * from the number of bits in each code. Therefore the code descriptions
- * are simply a list of code lengths for each symbol.
- *
- * - The code lengths are stored in order for the symbols, so lengths are
- * provided for each of the literal/length symbols, and for each of the
- * distance symbols.
- *
- * - If a symbol is not used in the block, this is represented by a zero as
- * as the code length. This does not mean a zero-length code, but rather
- * that no code should be created for this symbol. There is no way in the
- * deflate format to represent a zero-length code.
- *
- * - The maximum number of bits in a code is 15, so the possible lengths for
- * any code are 1..15.
- *
- * - The fact that a length of zero is not permitted for a code has an
- * interesting consequence. Normally if only one symbol is used for a given
- * code, then in fact that code could be represented with zero bits. However
- * in deflate, that code has to be at least one bit. So for example, if
- * only a single distance base symbol appears in a block, then it will be
- * represented by a single code of length one, in particular one 0 bit. This
- * is an incomplete code, since if a 1 bit is received, it has no meaning,
- * and should result in an error. So incomplete distance codes of one symbol
- * should be permitted, and the receipt of invalid codes should be handled.
- *
- * - It is also possible to have a single literal/length code, but that code
- * must be the end-of-block code, since every dynamic block has one. This
- * is not the most efficient way to create an empty block (an empty fixed
- * block is fewer bits), but it is allowed by the format. So incomplete
- * literal/length codes of one symbol should also be permitted.
- *
- * - If there are only literal codes and no lengths, then there are no distance
- * codes. This is represented by one distance code with zero bits.
- *
- * - The list of up to 286 length/literal lengths and up to 30 distance lengths
- * are themselves compressed using Huffman codes and run-length encoding. In
- * the list of code lengths, a 0 symbol means no code, a 1..15 symbol means
- * that length, and the symbols 16, 17, and 18 are run-length instructions.
- * Each of 16, 17, and 18 are follwed by extra bits to define the length of
- * the run. 16 copies the last length 3 to 6 times. 17 represents 3 to 10
- * zero lengths, and 18 represents 11 to 138 zero lengths. Unused symbols
- * are common, hence the special coding for zero lengths.
- *
- * - The symbols for 0..18 are Huffman coded, and so that code must be
- * described first. This is simply a sequence of up to 19 three-bit values
- * representing no code (0) or the code length for that symbol (1..7).
- *
- * - A dynamic block starts with three fixed-size counts from which is computed
- * the number of literal/length code lengths, the number of distance code
- * lengths, and the number of code length code lengths (ok, you come up with
- * a better name!) in the code descriptions. For the literal/length and
- * distance codes, lengths after those provided are considered zero, i.e. no
- * code. The code length code lengths are received in a permuted order (see
- * the order[] array below) to make a short code length code length list more
- * likely. As it turns out, very short and very long codes are less likely
- * to be seen in a dynamic code description, hence what may appear initially
- * to be a peculiar ordering.
- *
- * - Given the number of literal/length code lengths (nlen) and distance code
- * lengths (ndist), then they are treated as one long list of nlen + ndist
- * code lengths. Therefore run-length coding can and often does cross the
- * boundary between the two sets of lengths.
- *
- * - So to summarize, the code description at the start of a dynamic block is
- * three counts for the number of code lengths for the literal/length codes,
- * the distance codes, and the code length codes. This is followed by the
- * code length code lengths, three bits each. This is used to construct the
- * code length code which is used to read the remainder of the lengths. Then
- * the literal/length code lengths and distance lengths are read as a single
- * set of lengths using the code length codes. Codes are constructed from
- * the resulting two sets of lengths, and then finally you can start
- * decoding actual compressed data in the block.
- *
- * - For reference, a "typical" size for the code description in a dynamic
- * block is around 80 bytes.
- */
-local int dynamic(struct state *s)
-{
- int nlen, ndist, ncode; /* number of lengths in descriptor */
- int index; /* index of lengths[] */
- int err; /* construct() return value */
- short lengths[MAXCODES]; /* descriptor code lengths */
- short lencnt[MAXBITS+1], lensym[MAXLCODES]; /* lencode memory */
- short distcnt[MAXBITS+1], distsym[MAXDCODES]; /* distcode memory */
- struct huffman lencode, distcode; /* length and distance codes */
- static const short order[19] = /* permutation of code length codes */
- {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
- /* construct lencode and distcode */
- lencode.count = lencnt;
- lencode.symbol = lensym;
- distcode.count = distcnt;
- distcode.symbol = distsym;
-
- /* get number of lengths in each table, check lengths */
- nlen = bits(s, 5) + 257;
- ndist = bits(s, 5) + 1;
- ncode = bits(s, 4) + 4;
- if (nlen > MAXLCODES || ndist > MAXDCODES)
- return -3; /* bad counts */
-
- /* read code length code lengths (really), missing lengths are zero */
- for (index = 0; index < ncode; index++)
- lengths[order[index]] = bits(s, 3);
- for (; index < 19; index++)
- lengths[order[index]] = 0;
-
- /* build huffman table for code lengths codes (use lencode temporarily) */
- err = construct(&lencode, lengths, 19);
- if (err != 0) return -4; /* require complete code set here */
-
- /* read length/literal and distance code length tables */
- index = 0;
- while (index < nlen + ndist) {
- int symbol; /* decoded value */
- int len; /* last length to repeat */
-
- symbol = decode(s, &lencode);
- if (symbol < 16) /* length in 0..15 */
- lengths[index++] = symbol;
- else { /* repeat instruction */
- len = 0; /* assume repeating zeros */
- if (symbol == 16) { /* repeat last length 3..6 times */
- if (index == 0) return -5; /* no last length! */
- len = lengths[index - 1]; /* last length */
- symbol = 3 + bits(s, 2);
- }
- else if (symbol == 17) /* repeat zero 3..10 times */
- symbol = 3 + bits(s, 3);
- else /* == 18, repeat zero 11..138 times */
- symbol = 11 + bits(s, 7);
- if (index + symbol > nlen + ndist)
- return -6; /* too many lengths! */
- while (symbol--) /* repeat last or zero symbol times */
- lengths[index++] = len;
- }
- }
-
- /* check for end-of-block code -- there better be one! */
- if (lengths[256] == 0)
- return -9;
-
- /* build huffman table for literal/length codes */
- err = construct(&lencode, lengths, nlen);
- if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1))
- return -7; /* only allow incomplete codes if just one code */
-
- /* build huffman table for distance codes */
- err = construct(&distcode, lengths + nlen, ndist);
- if (err < 0 || (err > 0 && ndist - distcode.count[0] != 1))
- return -8; /* only allow incomplete codes if just one code */
-
- /* decode data until end-of-block code */
- return codes(s, &lencode, &distcode);
-}
-
-/*
- * Inflate source to dest. On return, destlen and sourcelen are updated to the
- * size of the uncompressed data and the size of the deflate data respectively.
- * On success, the return value of puff() is zero. If there is an error in the
- * source data, i.e. it is not in the deflate format, then a negative value is
- * returned. If there is not enough input available or there is not enough
- * output space, then a positive error is returned. In that case, destlen and
- * sourcelen are not updated to facilitate retrying from the beginning with the
- * provision of more input data or more output space. In the case of invalid
- * inflate data (a negative error), the dest and source pointers are updated to
- * facilitate the debugging of deflators.
- *
- * puff() also has a mode to determine the size of the uncompressed output with
- * no output written. For this dest must be (unsigned char *)0. In this case,
- * the input value of *destlen is ignored, and on return *destlen is set to the
- * size of the uncompressed output.
- *
- * The return codes are:
- *
- * 2: available inflate data did not terminate
- * 1: output space exhausted before completing inflate
- * 0: successful inflate
- * -1: invalid block type (type == 3)
- * -2: stored block length did not match one's complement
- * -3: dynamic block code description: too many length or distance codes
- * -4: dynamic block code description: code lengths codes incomplete
- * -5: dynamic block code description: repeat lengths with no first length
- * -6: dynamic block code description: repeat more than specified lengths
- * -7: dynamic block code description: invalid literal/length code lengths
- * -8: dynamic block code description: invalid distance code lengths
- * -9: dynamic block code description: missing end-of-block code
- * -10: invalid literal/length or distance code in fixed or dynamic block
- * -11: distance is too far back in fixed or dynamic block
- *
- * Format notes:
- *
- * - Three bits are read for each block to determine the kind of block and
- * whether or not it is the last block. Then the block is decoded and the
- * process repeated if it was not the last block.
- *
- * - The leftover bits in the last byte of the deflate data after the last
- * block (if it was a fixed or dynamic block) are undefined and have no
- * expected values to check.
- */
-int puff(unsigned char *dest, /* pointer to destination pointer */
- unsigned long *destlen, /* amount of output space */
- unsigned char *source, /* pointer to source data pointer */
- unsigned long *sourcelen) /* amount of input available */
-{
- struct state s; /* input/output state */
- int last, type; /* block information */
- int err; /* return value */
-
- /* initialize output state */
- s.out = dest;
- s.outlen = *destlen; /* ignored if dest is NIL */
- s.outcnt = 0;
-
- /* initialize input state */
- s.in = source;
- s.inlen = *sourcelen;
- s.incnt = 0;
- s.bitbuf = 0;
- s.bitcnt = 0;
-
- /* return if bits() or decode() tries to read past available input */
- if (setjmp(s.env) != 0) /* if came back here via longjmp() */
- err = 2; /* then skip do-loop, return error */
- else {
- /* process blocks until last block or error */
- do {
- last = bits(&s, 1); /* one if last block */
- type = bits(&s, 2); /* block type 0..3 */
- err = type == 0 ? stored(&s) :
- (type == 1 ? fixed(&s) :
- (type == 2 ? dynamic(&s) :
- -1)); /* type == 3, invalid */
- if (err != 0) break; /* return with error */
- } while (!last);
- }
-
- /* update the lengths and return */
- if (err <= 0) {
- *destlen = s.outcnt;
- *sourcelen = s.incnt;
- }
- return err;
-}
-
-#ifdef TEST
-/* Examples of how to use puff().
-
- Usage: puff [-w] [-nnn] file
- ... | puff [-w] [-nnn]
-
- where file is the input file with deflate data, nnn is the number of bytes
- of input to skip before inflating (e.g. to skip a zlib or gzip header), and
- -w is used to write the decompressed data to stdout */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-/* Return size times approximately the cube root of 2, keeping the result as 1,
- 3, or 5 times a power of 2 -- the result is always > size, until the result
- is the maximum value of an unsigned long, where it remains. This is useful
- to keep reallocations less than ~33% over the actual data. */
-local size_t bythirds(size_t size)
-{
- int n;
- size_t m;
-
- m = size;
- for (n = 0; m; n++)
- m >>= 1;
- if (n < 3)
- return size + 1;
- n -= 3;
- m = size >> n;
- m += m == 6 ? 2 : 1;
- m <<= n;
- return m > size ? m : (size_t)(-1);
-}
-
-/* Read the input file *name, or stdin if name is NULL, into allocated memory.
- Reallocate to larger buffers until the entire file is read in. Return a
- pointer to the allocated data, or NULL if there was a memory allocation
- failure. *len is the number of bytes of data read from the input file (even
- if load() returns NULL). If the input file was empty or could not be opened
- or read, *len is zero. */
-local void *load(char *name, size_t *len)
-{
- size_t size;
- void *buf, *swap;
- FILE *in;
-
- *len = 0;
- buf = malloc(size = 4096);
- if (buf == NULL)
- return NULL;
- in = name == NULL ? stdin : fopen(name, "rb");
- if (in != NULL) {
- for (;;) {
- *len += fread((char *)buf + *len, 1, size - *len, in);
- if (*len < size) break;
- size = bythirds(size);
- if (size == *len || (swap = realloc(buf, size)) == NULL) {
- free(buf);
- buf = NULL;
- break;
- }
- buf = swap;
- }
- fclose(in);
- }
- return buf;
-}
-
-int main(int argc, char **argv)
-{
- int ret, put = 0;
- unsigned skip = 0;
- char *arg, *name = NULL;
- unsigned char *source = NULL, *dest;
- size_t len = 0;
- unsigned long sourcelen, destlen;
-
- /* process arguments */
- while (arg = *++argv, --argc)
- if (arg[0] == '-') {
- if (arg[1] == 'w' && arg[2] == 0)
- put = 1;
- else if (arg[1] >= '0' && arg[1] <= '9')
- skip = (unsigned)atoi(arg + 1);
- else {
- fprintf(stderr, "invalid option %s\n", arg);
- return 3;
- }
- }
- else if (name != NULL) {
- fprintf(stderr, "only one file name allowed\n");
- return 3;
- }
- else
- name = arg;
- source = load(name, &len);
- if (source == NULL) {
- fprintf(stderr, "memory allocation failure\n");
- return 4;
- }
- if (len == 0) {
- fprintf(stderr, "could not read %s, or it was empty\n",
- name == NULL ? "<stdin>" : name);
- free(source);
- return 3;
- }
- if (skip >= len) {
- fprintf(stderr, "skip request of %d leaves no input\n", skip);
- free(source);
- return 3;
- }
-
- /* test inflate data with offset skip */
- len -= skip;
- sourcelen = (unsigned long)len;
- ret = puff(NIL, &destlen, source + skip, &sourcelen);
- if (ret)
- fprintf(stderr, "puff() failed with return code %d\n", ret);
- else {
- fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen);
- if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n",
- len - sourcelen);
- }
-
- /* if requested, inflate again and write decompressd data to stdout */
- if (put) {
- dest = malloc(destlen);
- if (dest == NULL) {
- fprintf(stderr, "memory allocation failure\n");
- free(source);
- return 4;
- }
- puff(dest, &destlen, source + skip, &sourcelen);
- fwrite(dest, 1, destlen, stdout);
- free(dest);
- }
-
- /* clean up */
- free(source);
- return ret;
-}
-#endif
diff --git a/cpukit/zlib/contrib/puff/puff.h b/cpukit/zlib/contrib/puff/puff.h
deleted file mode 100644
index 88d1b3844f..0000000000
--- a/cpukit/zlib/contrib/puff/puff.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* puff.h
- Copyright (C) 2002-2010 Mark Adler, all rights reserved
- version 2.1, 4 Apr 2010
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Mark Adler madler@alumni.caltech.edu
- */
-
-
-/*
- * See puff.c for purpose and usage.
- */
-int puff(unsigned char *dest, /* pointer to destination pointer */
- unsigned long *destlen, /* amount of output space */
- unsigned char *source, /* pointer to source data pointer */
- unsigned long *sourcelen); /* amount of input available */
diff --git a/cpukit/zlib/contrib/puff/zeros.raw b/cpukit/zlib/contrib/puff/zeros.raw
deleted file mode 100644
index 637b7be6f5..0000000000
--- a/cpukit/zlib/contrib/puff/zeros.raw
+++ /dev/null
Binary files differ
diff --git a/cpukit/zlib/contrib/testzlib/testzlib.c b/cpukit/zlib/contrib/testzlib/testzlib.c
deleted file mode 100644
index 135888eb10..0000000000
--- a/cpukit/zlib/contrib/testzlib/testzlib.c
+++ /dev/null
@@ -1,275 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <windows.h>
-
-#include "zlib.h"
-
-
-void MyDoMinus64(LARGE_INTEGER *R,LARGE_INTEGER A,LARGE_INTEGER B)
-{
- R->HighPart = A.HighPart - B.HighPart;
- if (A.LowPart >= B.LowPart)
- R->LowPart = A.LowPart - B.LowPart;
- else
- {
- R->LowPart = A.LowPart - B.LowPart;
- R->HighPart --;
- }
-}
-
-#ifdef _M_X64
-// see http://msdn2.microsoft.com/library/twchhe95(en-us,vs.80).aspx for __rdtsc
-unsigned __int64 __rdtsc(void);
-void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64)
-{
- // printf("rdtsc = %I64x\n",__rdtsc());
- pbeginTime64->QuadPart=__rdtsc();
-}
-
-LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf)
-{
- LARGE_INTEGER LIres;
- unsigned _int64 res=__rdtsc()-((unsigned _int64)(beginTime64.QuadPart));
- LIres.QuadPart=res;
- // printf("rdtsc = %I64x\n",__rdtsc());
- return LIres;
-}
-#else
-#ifdef _M_IX86
-void myGetRDTSC32(LARGE_INTEGER * pbeginTime64)
-{
- DWORD dwEdx,dwEax;
- _asm
- {
- rdtsc
- mov dwEax,eax
- mov dwEdx,edx
- }
- pbeginTime64->LowPart=dwEax;
- pbeginTime64->HighPart=dwEdx;
-}
-
-void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64)
-{
- myGetRDTSC32(pbeginTime64);
-}
-
-LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf)
-{
- LARGE_INTEGER LIres,endTime64;
- myGetRDTSC32(&endTime64);
-
- LIres.LowPart=LIres.HighPart=0;
- MyDoMinus64(&LIres,endTime64,beginTime64);
- return LIres;
-}
-#else
-void myGetRDTSC32(LARGE_INTEGER * pbeginTime64)
-{
-}
-
-void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64)
-{
-}
-
-LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf)
-{
- LARGE_INTEGER lr;
- lr.QuadPart=0;
- return lr;
-}
-#endif
-#endif
-
-void BeginCountPerfCounter(LARGE_INTEGER * pbeginTime64,BOOL fComputeTimeQueryPerf)
-{
- if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(pbeginTime64)))
- {
- pbeginTime64->LowPart = GetTickCount();
- pbeginTime64->HighPart = 0;
- }
-}
-
-DWORD GetMsecSincePerfCounter(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf)
-{
- LARGE_INTEGER endTime64,ticksPerSecond,ticks;
- DWORDLONG ticksShifted,tickSecShifted;
- DWORD dwLog=16+0;
- DWORD dwRet;
- if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(&endTime64)))
- dwRet = (GetTickCount() - beginTime64.LowPart)*1;
- else
- {
- MyDoMinus64(&ticks,endTime64,beginTime64);
- QueryPerformanceFrequency(&ticksPerSecond);
-
-
- {
- ticksShifted = Int64ShrlMod32(*(DWORDLONG*)&ticks,dwLog);
- tickSecShifted = Int64ShrlMod32(*(DWORDLONG*)&ticksPerSecond,dwLog);
-
- }
-
- dwRet = (DWORD)((((DWORD)ticksShifted)*1000)/(DWORD)(tickSecShifted));
- dwRet *=1;
- }
- return dwRet;
-}
-
-int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr)
-{
- FILE* stream;
- void* ptr;
- int retVal=1;
- stream=fopen(filename, "rb");
- if (stream==NULL)
- return 0;
-
- fseek(stream,0,SEEK_END);
-
- *plFileSize=ftell(stream);
- fseek(stream,0,SEEK_SET);
- ptr=malloc((*plFileSize)+1);
- if (ptr==NULL)
- retVal=0;
- else
- {
- if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize))
- retVal=0;
- }
- fclose(stream);
- *pFilePtr=ptr;
- return retVal;
-}
-
-int main(int argc, char *argv[])
-{
- int BlockSizeCompress=0x8000;
- int BlockSizeUncompress=0x8000;
- int cprLevel=Z_DEFAULT_COMPRESSION ;
- long lFileSize;
- unsigned char* FilePtr;
- long lBufferSizeCpr;
- long lBufferSizeUncpr;
- long lCompressedSize=0;
- unsigned char* CprPtr;
- unsigned char* UncprPtr;
- long lSizeCpr,lSizeUncpr;
- DWORD dwGetTick,dwMsecQP;
- LARGE_INTEGER li_qp,li_rdtsc,dwResRdtsc;
-
- if (argc<=1)
- {
- printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n");
- return 0;
- }
-
- if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)
- {
- printf("error reading %s\n",argv[1]);
- return 1;
- }
- else printf("file %s read, %u bytes\n",argv[1],lFileSize);
-
- if (argc>=3)
- BlockSizeCompress=atol(argv[2]);
-
- if (argc>=4)
- BlockSizeUncompress=atol(argv[3]);
-
- if (argc>=5)
- cprLevel=(int)atol(argv[4]);
-
- lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200;
- lBufferSizeUncpr = lBufferSizeCpr;
-
- CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress);
-
- BeginCountPerfCounter(&li_qp,TRUE);
- dwGetTick=GetTickCount();
- BeginCountRdtsc(&li_rdtsc);
- {
- z_stream zcpr;
- int ret=Z_OK;
- long lOrigToDo = lFileSize;
- long lOrigDone = 0;
- int step=0;
- memset(&zcpr,0,sizeof(z_stream));
- deflateInit(&zcpr,cprLevel);
-
- zcpr.next_in = FilePtr;
- zcpr.next_out = CprPtr;
-
-
- do
- {
- long all_read_before = zcpr.total_in;
- zcpr.avail_in = min(lOrigToDo,BlockSizeCompress);
- zcpr.avail_out = BlockSizeCompress;
- ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH);
- lOrigDone += (zcpr.total_in-all_read_before);
- lOrigToDo -= (zcpr.total_in-all_read_before);
- step++;
- } while (ret==Z_OK);
-
- lSizeCpr=zcpr.total_out;
- deflateEnd(&zcpr);
- dwGetTick=GetTickCount()-dwGetTick;
- dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE);
- dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE);
- printf("total compress size = %u, in %u step\n",lSizeCpr,step);
- printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.);
- printf("defcpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.);
- printf("defcpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart);
- }
-
- CprPtr=(unsigned char*)realloc(CprPtr,lSizeCpr);
- UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress);
-
- BeginCountPerfCounter(&li_qp,TRUE);
- dwGetTick=GetTickCount();
- BeginCountRdtsc(&li_rdtsc);
- {
- z_stream zcpr;
- int ret=Z_OK;
- long lOrigToDo = lSizeCpr;
- long lOrigDone = 0;
- int step=0;
- memset(&zcpr,0,sizeof(z_stream));
- inflateInit(&zcpr);
-
- zcpr.next_in = CprPtr;
- zcpr.next_out = UncprPtr;
-
-
- do
- {
- long all_read_before = zcpr.total_in;
- zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress);
- zcpr.avail_out = BlockSizeUncompress;
- ret=inflate(&zcpr,Z_SYNC_FLUSH);
- lOrigDone += (zcpr.total_in-all_read_before);
- lOrigToDo -= (zcpr.total_in-all_read_before);
- step++;
- } while (ret==Z_OK);
-
- lSizeUncpr=zcpr.total_out;
- inflateEnd(&zcpr);
- dwGetTick=GetTickCount()-dwGetTick;
- dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE);
- dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE);
- printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step);
- printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.);
- printf("uncpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.);
- printf("uncpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart);
- }
-
- if (lSizeUncpr==lFileSize)
- {
- if (memcmp(FilePtr,UncprPtr,lFileSize)==0)
- printf("compare ok\n");
-
- }
-
- return 0;
-}
diff --git a/cpukit/zlib/contrib/testzlib/testzlib.sln b/cpukit/zlib/contrib/testzlib/testzlib.sln
deleted file mode 100644
index 86da7163d1..0000000000
--- a/cpukit/zlib/contrib/testzlib/testzlib.sln
+++ /dev/null
@@ -1,21 +0,0 @@
-Microsoft Visual Studio Solution File, Format Version 7.00
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
-EndProject
-Global
- GlobalSection(SolutionConfiguration) = preSolution
- ConfigName.0 = Debug
- ConfigName.1 = Release
- EndGlobalSection
- GlobalSection(ProjectDependencies) = postSolution
- EndGlobalSection
- GlobalSection(ProjectConfiguration) = postSolution
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- EndGlobalSection
- GlobalSection(ExtensibilityAddIns) = postSolution
- EndGlobalSection
-EndGlobal
diff --git a/cpukit/zlib/contrib/testzlib/testzlib.txt b/cpukit/zlib/contrib/testzlib/testzlib.txt
deleted file mode 100644
index 62258f1495..0000000000
--- a/cpukit/zlib/contrib/testzlib/testzlib.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-To build testzLib with Visual Studio 2005:
-
-copy to a directory file from :
-- root of zLib tree
-- contrib/testzlib
-- contrib/masmx86
-- contrib/masmx64
-- contrib/vstudio/vc7
-
-and open testzlib8.sln \ No newline at end of file
diff --git a/cpukit/zlib/contrib/testzlib/testzlib.vcproj b/cpukit/zlib/contrib/testzlib/testzlib.vcproj
deleted file mode 100644
index bd9b39bb9d..0000000000
--- a/cpukit/zlib/contrib/testzlib/testzlib.vcproj
+++ /dev/null
@@ -1,124 +0,0 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.00"
- Name="testzlib"
- ProjectGUID="{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
- Keyword="Win32Proj">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE"
- MinimalRebuild="TRUE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="5"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="2"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
- SubSystem="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="TRUE"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE"
- StringPooling="TRUE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="3"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateDebugInformation="TRUE"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- </Configurations>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
- <File
- RelativePath="testzlib.c">
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc">
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
- </Filter>
- <File
- RelativePath="zlibwapi.lib">
- </File>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/untgz/Makefile b/cpukit/zlib/contrib/untgz/Makefile
deleted file mode 100644
index b54266fba2..0000000000
--- a/cpukit/zlib/contrib/untgz/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-CC=cc
-CFLAGS=-g
-
-untgz: untgz.o ../../libz.a
- $(CC) $(CFLAGS) -o untgz untgz.o -L../.. -lz
-
-untgz.o: untgz.c ../../zlib.h
- $(CC) $(CFLAGS) -c -I../.. untgz.c
-
-../../libz.a:
- cd ../..; ./configure; make
-
-clean:
- rm -f untgz untgz.o *~
diff --git a/cpukit/zlib/contrib/untgz/Makefile.msc b/cpukit/zlib/contrib/untgz/Makefile.msc
deleted file mode 100644
index 77b8602213..0000000000
--- a/cpukit/zlib/contrib/untgz/Makefile.msc
+++ /dev/null
@@ -1,17 +0,0 @@
-CC=cl
-CFLAGS=-MD
-
-untgz.exe: untgz.obj ..\..\zlib.lib
- $(CC) $(CFLAGS) untgz.obj ..\..\zlib.lib
-
-untgz.obj: untgz.c ..\..\zlib.h
- $(CC) $(CFLAGS) -c -I..\.. untgz.c
-
-..\..\zlib.lib:
- cd ..\..
- $(MAKE) -f win32\makefile.msc
- cd contrib\untgz
-
-clean:
- -del untgz.obj
- -del untgz.exe
diff --git a/cpukit/zlib/contrib/untgz/untgz.c b/cpukit/zlib/contrib/untgz/untgz.c
deleted file mode 100644
index 2c391e5986..0000000000
--- a/cpukit/zlib/contrib/untgz/untgz.c
+++ /dev/null
@@ -1,674 +0,0 @@
-/*
- * untgz.c -- Display contents and extract files from a gzip'd TAR file
- *
- * written by Pedro A. Aranda Gutierrez <paag@tid.es>
- * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org>
- * various fixes by Cosmin Truta <cosmint@cs.ubbcluj.ro>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-
-#include "zlib.h"
-
-#ifdef unix
-# include <unistd.h>
-#else
-# include <direct.h>
-# include <io.h>
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-# ifndef F_OK
-# define F_OK 0
-# endif
-# define mkdir(dirname,mode) _mkdir(dirname)
-# ifdef _MSC_VER
-# define access(path,mode) _access(path,mode)
-# define chmod(path,mode) _chmod(path,mode)
-# define strdup(str) _strdup(str)
-# endif
-#else
-# include <utime.h>
-#endif
-
-
-/* values used in typeflag field */
-
-#define REGTYPE '0' /* regular file */
-#define AREGTYPE '\0' /* regular file */
-#define LNKTYPE '1' /* link */
-#define SYMTYPE '2' /* reserved */
-#define CHRTYPE '3' /* character special */
-#define BLKTYPE '4' /* block special */
-#define DIRTYPE '5' /* directory */
-#define FIFOTYPE '6' /* FIFO special */
-#define CONTTYPE '7' /* reserved */
-
-/* GNU tar extensions */
-
-#define GNUTYPE_DUMPDIR 'D' /* file names from dumped directory */
-#define GNUTYPE_LONGLINK 'K' /* long link name */
-#define GNUTYPE_LONGNAME 'L' /* long file name */
-#define GNUTYPE_MULTIVOL 'M' /* continuation of file from another volume */
-#define GNUTYPE_NAMES 'N' /* file name that does not fit into main hdr */
-#define GNUTYPE_SPARSE 'S' /* sparse file */
-#define GNUTYPE_VOLHDR 'V' /* tape/volume header */
-
-
-/* tar header */
-
-#define BLOCKSIZE 512
-#define SHORTNAMESIZE 100
-
-struct tar_header
-{ /* byte offset */
- char name[100]; /* 0 */
- char mode[8]; /* 100 */
- char uid[8]; /* 108 */
- char gid[8]; /* 116 */
- char size[12]; /* 124 */
- char mtime[12]; /* 136 */
- char chksum[8]; /* 148 */
- char typeflag; /* 156 */
- char linkname[100]; /* 157 */
- char magic[6]; /* 257 */
- char version[2]; /* 263 */
- char uname[32]; /* 265 */
- char gname[32]; /* 297 */
- char devmajor[8]; /* 329 */
- char devminor[8]; /* 337 */
- char prefix[155]; /* 345 */
- /* 500 */
-};
-
-union tar_buffer
-{
- char buffer[BLOCKSIZE];
- struct tar_header header;
-};
-
-struct attr_item
-{
- struct attr_item *next;
- char *fname;
- int mode;
- time_t time;
-};
-
-enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID };
-
-char *TGZfname OF((const char *));
-void TGZnotfound OF((const char *));
-
-int getoct OF((char *, int));
-char *strtime OF((time_t *));
-int setfiletime OF((char *, time_t));
-void push_attr OF((struct attr_item **, char *, int, time_t));
-void restore_attr OF((struct attr_item **));
-
-int ExprMatch OF((char *, char *));
-
-int makedir OF((char *));
-int matchname OF((int, int, char **, char *));
-
-void error OF((const char *));
-int tar OF((gzFile, int, int, int, char **));
-
-void help OF((int));
-int main OF((int, char **));
-
-char *prog;
-
-const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL };
-
-/* return the file name of the TGZ archive */
-/* or NULL if it does not exist */
-
-char *TGZfname (const char *arcname)
-{
- static char buffer[1024];
- int origlen,i;
-
- strcpy(buffer,arcname);
- origlen = strlen(buffer);
-
- for (i=0; TGZsuffix[i]; i++)
- {
- strcpy(buffer+origlen,TGZsuffix[i]);
- if (access(buffer,F_OK) == 0)
- return buffer;
- }
- return NULL;
-}
-
-
-/* error message for the filename */
-
-void TGZnotfound (const char *arcname)
-{
- int i;
-
- fprintf(stderr,"%s: Couldn't find ",prog);
- for (i=0;TGZsuffix[i];i++)
- fprintf(stderr,(TGZsuffix[i+1]) ? "%s%s, " : "or %s%s\n",
- arcname,
- TGZsuffix[i]);
- exit(1);
-}
-
-
-/* convert octal digits to int */
-/* on error return -1 */
-
-int getoct (char *p,int width)
-{
- int result = 0;
- char c;
-
- while (width--)
- {
- c = *p++;
- if (c == 0)
- break;
- if (c == ' ')
- continue;
- if (c < '0' || c > '7')
- return -1;
- result = result * 8 + (c - '0');
- }
- return result;
-}
-
-
-/* convert time_t to string */
-/* use the "YYYY/MM/DD hh:mm:ss" format */
-
-char *strtime (time_t *t)
-{
- struct tm *local;
- static char result[32];
-
- local = localtime(t);
- sprintf(result,"%4d/%02d/%02d %02d:%02d:%02d",
- local->tm_year+1900, local->tm_mon+1, local->tm_mday,
- local->tm_hour, local->tm_min, local->tm_sec);
- return result;
-}
-
-
-/* set file time */
-
-int setfiletime (char *fname,time_t ftime)
-{
-#ifdef WIN32
- static int isWinNT = -1;
- SYSTEMTIME st;
- FILETIME locft, modft;
- struct tm *loctm;
- HANDLE hFile;
- int result;
-
- loctm = localtime(&ftime);
- if (loctm == NULL)
- return -1;
-
- st.wYear = (WORD)loctm->tm_year + 1900;
- st.wMonth = (WORD)loctm->tm_mon + 1;
- st.wDayOfWeek = (WORD)loctm->tm_wday;
- st.wDay = (WORD)loctm->tm_mday;
- st.wHour = (WORD)loctm->tm_hour;
- st.wMinute = (WORD)loctm->tm_min;
- st.wSecond = (WORD)loctm->tm_sec;
- st.wMilliseconds = 0;
- if (!SystemTimeToFileTime(&st, &locft) ||
- !LocalFileTimeToFileTime(&locft, &modft))
- return -1;
-
- if (isWinNT < 0)
- isWinNT = (GetVersion() < 0x80000000) ? 1 : 0;
- hFile = CreateFile(fname, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
- (isWinNT ? FILE_FLAG_BACKUP_SEMANTICS : 0),
- NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- return -1;
- result = SetFileTime(hFile, NULL, NULL, &modft) ? 0 : -1;
- CloseHandle(hFile);
- return result;
-#else
- struct utimbuf settime;
-
- settime.actime = settime.modtime = ftime;
- return utime(fname,&settime);
-#endif
-}
-
-
-/* push file attributes */
-
-void push_attr(struct attr_item **list,char *fname,int mode,time_t time)
-{
- struct attr_item *item;
-
- item = (struct attr_item *)malloc(sizeof(struct attr_item));
- if (item == NULL)
- error("Out of memory");
- item->fname = strdup(fname);
- item->mode = mode;
- item->time = time;
- item->next = *list;
- *list = item;
-}
-
-
-/* restore file attributes */
-
-void restore_attr(struct attr_item **list)
-{
- struct attr_item *item, *prev;
-
- for (item = *list; item != NULL; )
- {
- setfiletime(item->fname,item->time);
- chmod(item->fname,item->mode);
- prev = item;
- item = item->next;
- free(prev);
- }
- *list = NULL;
-}
-
-
-/* match regular expression */
-
-#define ISSPECIAL(c) (((c) == '*') || ((c) == '/'))
-
-int ExprMatch (char *string,char *expr)
-{
- while (1)
- {
- if (ISSPECIAL(*expr))
- {
- if (*expr == '/')
- {
- if (*string != '\\' && *string != '/')
- return 0;
- string ++; expr++;
- }
- else if (*expr == '*')
- {
- if (*expr ++ == 0)
- return 1;
- while (*++string != *expr)
- if (*string == 0)
- return 0;
- }
- }
- else
- {
- if (*string != *expr)
- return 0;
- if (*expr++ == 0)
- return 1;
- string++;
- }
- }
-}
-
-
-/* recursive mkdir */
-/* abort on ENOENT; ignore other errors like "directory already exists" */
-/* return 1 if OK */
-/* 0 on error */
-
-int makedir (char *newdir)
-{
- char *buffer = strdup(newdir);
- char *p;
- int len = strlen(buffer);
-
- if (len <= 0) {
- free(buffer);
- return 0;
- }
- if (buffer[len-1] == '/') {
- buffer[len-1] = '\0';
- }
- if (mkdir(buffer, 0755) == 0)
- {
- free(buffer);
- return 1;
- }
-
- p = buffer+1;
- while (1)
- {
- char hold;
-
- while(*p && *p != '\\' && *p != '/')
- p++;
- hold = *p;
- *p = 0;
- if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT))
- {
- fprintf(stderr,"%s: Couldn't create directory %s\n",prog,buffer);
- free(buffer);
- return 0;
- }
- if (hold == 0)
- break;
- *p++ = hold;
- }
- free(buffer);
- return 1;
-}
-
-
-int matchname (int arg,int argc,char **argv,char *fname)
-{
- if (arg == argc) /* no arguments given (untgz tgzarchive) */
- return 1;
-
- while (arg < argc)
- if (ExprMatch(fname,argv[arg++]))
- return 1;
-
- return 0; /* ignore this for the moment being */
-}
-
-
-/* tar file list or extract */
-
-int tar (gzFile in,int action,int arg,int argc,char **argv)
-{
- union tar_buffer buffer;
- int len;
- int err;
- int getheader = 1;
- int remaining = 0;
- FILE *outfile = NULL;
- char fname[BLOCKSIZE];
- int tarmode;
- time_t tartime;
- struct attr_item *attributes = NULL;
-
- if (action == TGZ_LIST)
- printf(" date time size file\n"
- " ---------- -------- --------- -------------------------------------\n");
- while (1)
- {
- len = gzread(in, &buffer, BLOCKSIZE);
- if (len < 0)
- error(gzerror(in, &err));
- /*
- * Always expect complete blocks to process
- * the tar information.
- */
- if (len != BLOCKSIZE)
- {
- action = TGZ_INVALID; /* force error exit */
- remaining = 0; /* force I/O cleanup */
- }
-
- /*
- * If we have to get a tar header
- */
- if (getheader >= 1)
- {
- /*
- * if we met the end of the tar
- * or the end-of-tar block,
- * we are done
- */
- if (len == 0 || buffer.header.name[0] == 0)
- break;
-
- tarmode = getoct(buffer.header.mode,8);
- tartime = (time_t)getoct(buffer.header.mtime,12);
- if (tarmode == -1 || tartime == (time_t)-1)
- {
- buffer.header.name[0] = 0;
- action = TGZ_INVALID;
- }
-
- if (getheader == 1)
- {
- strncpy(fname,buffer.header.name,SHORTNAMESIZE);
- if (fname[SHORTNAMESIZE-1] != 0)
- fname[SHORTNAMESIZE] = 0;
- }
- else
- {
- /*
- * The file name is longer than SHORTNAMESIZE
- */
- if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0)
- error("bad long name");
- getheader = 1;
- }
-
- /*
- * Act according to the type flag
- */
- switch (buffer.header.typeflag)
- {
- case DIRTYPE:
- if (action == TGZ_LIST)
- printf(" %s <dir> %s\n",strtime(&tartime),fname);
- if (action == TGZ_EXTRACT)
- {
- makedir(fname);
- push_attr(&attributes,fname,tarmode,tartime);
- }
- break;
- case REGTYPE:
- case AREGTYPE:
- remaining = getoct(buffer.header.size,12);
- if (remaining == -1)
- {
- action = TGZ_INVALID;
- break;
- }
- if (action == TGZ_LIST)
- printf(" %s %9d %s\n",strtime(&tartime),remaining,fname);
- else if (action == TGZ_EXTRACT)
- {
- if (matchname(arg,argc,argv,fname))
- {
- outfile = fopen(fname,"wb");
- if (outfile == NULL) {
- /* try creating directory */
- char *p = strrchr(fname, '/');
- if (p != NULL) {
- *p = '\0';
- makedir(fname);
- *p = '/';
- outfile = fopen(fname,"wb");
- }
- }
- if (outfile != NULL)
- printf("Extracting %s\n",fname);
- else
- fprintf(stderr, "%s: Couldn't create %s",prog,fname);
- }
- else
- outfile = NULL;
- }
- getheader = 0;
- break;
- case GNUTYPE_LONGLINK:
- case GNUTYPE_LONGNAME:
- remaining = getoct(buffer.header.size,12);
- if (remaining < 0 || remaining >= BLOCKSIZE)
- {
- action = TGZ_INVALID;
- break;
- }
- len = gzread(in, fname, BLOCKSIZE);
- if (len < 0)
- error(gzerror(in, &err));
- if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining)
- {
- action = TGZ_INVALID;
- break;
- }
- getheader = 2;
- break;
- default:
- if (action == TGZ_LIST)
- printf(" %s <---> %s\n",strtime(&tartime),fname);
- break;
- }
- }
- else
- {
- unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining;
-
- if (outfile != NULL)
- {
- if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes)
- {
- fprintf(stderr,
- "%s: Error writing %s -- skipping\n",prog,fname);
- fclose(outfile);
- outfile = NULL;
- remove(fname);
- }
- }
- remaining -= bytes;
- }
-
- if (remaining == 0)
- {
- getheader = 1;
- if (outfile != NULL)
- {
- fclose(outfile);
- outfile = NULL;
- if (action != TGZ_INVALID)
- push_attr(&attributes,fname,tarmode,tartime);
- }
- }
-
- /*
- * Abandon if errors are found
- */
- if (action == TGZ_INVALID)
- {
- error("broken archive");
- break;
- }
- }
-
- /*
- * Restore file modes and time stamps
- */
- restore_attr(&attributes);
-
- if (gzclose(in) != Z_OK)
- error("failed gzclose");
-
- return 0;
-}
-
-
-/* ============================================================ */
-
-void help(int exitval)
-{
- printf("untgz version 0.2.1\n"
- " using zlib version %s\n\n",
- zlibVersion());
- printf("Usage: untgz file.tgz extract all files\n"
- " untgz file.tgz fname ... extract selected files\n"
- " untgz -l file.tgz list archive contents\n"
- " untgz -h display this help\n");
- exit(exitval);
-}
-
-void error(const char *msg)
-{
- fprintf(stderr, "%s: %s\n", prog, msg);
- exit(1);
-}
-
-
-/* ============================================================ */
-
-#if defined(WIN32) && defined(__GNUC__)
-int _CRT_glob = 0; /* disable argument globbing in MinGW */
-#endif
-
-int main(int argc,char **argv)
-{
- int action = TGZ_EXTRACT;
- int arg = 1;
- char *TGZfile;
- gzFile *f;
-
- prog = strrchr(argv[0],'\\');
- if (prog == NULL)
- {
- prog = strrchr(argv[0],'/');
- if (prog == NULL)
- {
- prog = strrchr(argv[0],':');
- if (prog == NULL)
- prog = argv[0];
- else
- prog++;
- }
- else
- prog++;
- }
- else
- prog++;
-
- if (argc == 1)
- help(0);
-
- if (strcmp(argv[arg],"-l") == 0)
- {
- action = TGZ_LIST;
- if (argc == ++arg)
- help(0);
- }
- else if (strcmp(argv[arg],"-h") == 0)
- {
- help(0);
- }
-
- if ((TGZfile = TGZfname(argv[arg])) == NULL)
- TGZnotfound(argv[arg]);
-
- ++arg;
- if ((action == TGZ_LIST) && (arg != argc))
- help(1);
-
-/*
- * Process the TGZ file
- */
- switch(action)
- {
- case TGZ_LIST:
- case TGZ_EXTRACT:
- f = gzopen(TGZfile,"rb");
- if (f == NULL)
- {
- fprintf(stderr,"%s: Couldn't gzopen %s\n",prog,TGZfile);
- return 1;
- }
- exit(tar(f, action, arg, argc, argv));
- break;
-
- default:
- error("Unknown option");
- exit(1);
- }
-
- return 0;
-}
diff --git a/cpukit/zlib/contrib/vstudio/readme.txt b/cpukit/zlib/contrib/vstudio/readme.txt
deleted file mode 100644
index 904888ba39..0000000000
--- a/cpukit/zlib/contrib/vstudio/readme.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-Building instructions for the DLL versions of Zlib 1.2.4
-========================================================
-
-This directory contains projects that build zlib and minizip using
-Microsoft Visual C++ 9.0/10.0, and Visual C++ .
-
-You don't need to build these projects yourself. You can download the
-binaries from:
- http://www.winimage.com/zLibDll
-
-More information can be found at this site.
-
-first compile assembly code by running
-bld_ml64.bat in contrib\masmx64
-bld_ml32.bat in contrib\masmx86
-
-
-
-
-Build instructions for Visual Studio 2008 (32 bits or 64 bits)
---------------------------------------------------------------
-- Uncompress current zlib, including all contrib/* files
-- Open contrib\vstudio\vc9\zlibvc.sln with Microsoft Visual C++ 2008.0
-- Or run: vcbuild /rebuild contrib\vstudio\vc9\zlibvc.sln "Release|Win32"
-
-Build instructions for Visual Studio 2010 (32 bits or 64 bits)
---------------------------------------------------------------
-- Uncompress current zlib, including all contrib/* files
-- Open contrib\vstudio\vc10\zlibvc.sln with Microsoft Visual C++ 2010.0
-
-
-Important
----------
-- To use zlibwapi.dll in your application, you must define the
- macro ZLIB_WINAPI when compiling your application's source files.
-
-
-Additional notes
-----------------
-- This DLL, named zlibwapi.dll, is compatible to the old zlib.dll built
- by Gilles Vollant from the zlib 1.1.x sources, and distributed at
- http://www.winimage.com/zLibDll
- It uses the WINAPI calling convention for the exported functions, and
- includes the minizip functionality. If your application needs that
- particular build of zlib.dll, you can rename zlibwapi.dll to zlib.dll.
-
-- The new DLL was renamed because there exist several incompatible
- versions of zlib.dll on the Internet.
-
-- There is also an official DLL build of zlib, named zlib1.dll. This one
- is exporting the functions using the CDECL convention. See the file
- win32\DLL_FAQ.txt found in this zlib distribution.
-
-- There used to be a ZLIB_DLL macro in zlib 1.1.x, but now this symbol
- has a slightly different effect. To avoid compatibility problems, do
- not define it here.
-
-
-Gilles Vollant
-info@winimage.com
diff --git a/cpukit/zlib/contrib/vstudio/vc7/miniunz.vcproj b/cpukit/zlib/contrib/vstudio/vc7/miniunz.vcproj
deleted file mode 100644
index ad5117c845..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/miniunz.vcproj
+++ /dev/null
@@ -1,126 +0,0 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.00"
- Name="miniunz"
- ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694382A}"
- Keyword="Win32Proj">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE"
- MinimalRebuild="TRUE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="5"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="2"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile="$(OutDir)/miniunz.pdb"
- SubSystem="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="TRUE"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE"
- StringPooling="TRUE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="3"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="1"
- GenerateDebugInformation="TRUE"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- </Configurations>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
- <File
- RelativePath="..\..\minizip\miniunz.c">
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc">
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
- </Filter>
- <File
- RelativePath="ReleaseDll\zlibwapi.lib">
- </File>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc7/minizip.vcproj b/cpukit/zlib/contrib/vstudio/vc7/minizip.vcproj
deleted file mode 100644
index fb5b6320d5..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/minizip.vcproj
+++ /dev/null
@@ -1,126 +0,0 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.00"
- Name="minizip"
- ProjectGUID="{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"
- Keyword="Win32Proj">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE"
- MinimalRebuild="TRUE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="5"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="2"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile="$(OutDir)/minizip.pdb"
- SubSystem="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="TRUE"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE"
- StringPooling="TRUE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="3"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="1"
- GenerateDebugInformation="TRUE"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- </Configurations>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
- <File
- RelativePath="..\..\minizip\minizip.c">
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc">
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
- </Filter>
- <File
- RelativePath="ReleaseDll\zlibwapi.lib">
- </File>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc7/zlib.rc b/cpukit/zlib/contrib/vstudio/vc7/zlib.rc
deleted file mode 100644
index 72cb8b4c31..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/zlib.rc
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <windows.h>
-
-#define IDR_VERSION1 1
-IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
- FILEVERSION 1,2,3,0
- PRODUCTVERSION 1,2,3,0
- FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
- FILEFLAGS 0
- FILEOS VOS_DOS_WINDOWS32
- FILETYPE VFT_DLL
- FILESUBTYPE 0 // not used
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904E4"
- //language ID = U.S. English, char set = Windows, Multilingual
-
- BEGIN
- VALUE "FileDescription", "zlib data compression library\0"
- VALUE "FileVersion", "1.2.3.0\0"
- VALUE "InternalName", "zlib\0"
- VALUE "OriginalFilename", "zlib.dll\0"
- VALUE "ProductName", "ZLib.DLL\0"
- VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
- VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x0409, 1252
- END
-END
diff --git a/cpukit/zlib/contrib/vstudio/vc7/zlibstat.vcproj b/cpukit/zlib/contrib/vstudio/vc7/zlibstat.vcproj
deleted file mode 100644
index 766d7a4d6e..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/zlibstat.vcproj
+++ /dev/null
@@ -1,246 +0,0 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.00"
- Name="zlibstat"
- SccProjectName=""
- SccLocalPath="">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory=".\zlibstatDebug"
- IntermediateDirectory=".\zlibstatDebug"
- ConfigurationType="4"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI"
- ExceptionHandling="FALSE"
- RuntimeLibrary="5"
- PrecompiledHeaderFile=".\zlibstatDebug/zlibstat.pch"
- AssemblerListingLocation=".\zlibstatDebug/"
- ObjectFile=".\zlibstatDebug/"
- ProgramDataBaseFileName=".\zlibstatDebug/"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"
- DebugInformationFormat="1"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/NODEFAULTLIB "
- OutputFile=".\zlibstatDebug\zlibstat.lib"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- </Configuration>
- <Configuration
- Name="ReleaseAxp|Win32"
- OutputDirectory=".\zlibsta0"
- IntermediateDirectory=".\zlibsta0"
- ConfigurationType="4"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\zlibsta0/zlibstat.pch"
- AssemblerListingLocation=".\zlibsta0/"
- ObjectFile=".\zlibsta0/"
- ProgramDataBaseFileName=".\zlibsta0/"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/NODEFAULTLIB "
- OutputFile=".\zlibsta0\zlibstat.lib"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory=".\zlibstat"
- IntermediateDirectory=".\zlibstat"
- ConfigurationType="4"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;ASMV;ASMINF"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\zlibstat/zlibstat.pch"
- AssemblerListingLocation=".\zlibstat/"
- ObjectFile=".\zlibstat/"
- ProgramDataBaseFileName=".\zlibstat/"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj /NODEFAULTLIB "
- OutputFile=".\zlibstat\zlibstat.lib"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Win32"
- OutputDirectory="zlibstatWithoutAsm"
- IntermediateDirectory="zlibstatWithoutAsm"
- ConfigurationType="4"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\zlibstat/zlibstat.pch"
- AssemblerListingLocation=".\zlibstatWithoutAsm/"
- ObjectFile=".\zlibstatWithoutAsm/"
- ProgramDataBaseFileName=".\zlibstatWithoutAsm/"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions=" /NODEFAULTLIB "
- OutputFile=".\zlibstatWithoutAsm\zlibstat.lib"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- </Configuration>
- </Configurations>
- <Files>
- <Filter
- Name="Source Files"
- Filter="">
- <File
- RelativePath="..\..\..\adler32.c">
- </File>
- <File
- RelativePath="..\..\..\compress.c">
- </File>
- <File
- RelativePath="..\..\..\crc32.c">
- </File>
- <File
- RelativePath="..\..\..\deflate.c">
- </File>
- <File
- RelativePath="..\..\masmx86\gvmat32c.c">
- </File>
- <File
- RelativePath="..\..\..\gzio.c">
- </File>
- <File
- RelativePath="..\..\..\infback.c">
- </File>
- <File
- RelativePath="..\..\..\inffast.c">
- </File>
- <File
- RelativePath="..\..\..\inflate.c">
- </File>
- <File
- RelativePath="..\..\..\inftrees.c">
- </File>
- <File
- RelativePath="..\..\minizip\ioapi.c">
- </File>
- <File
- RelativePath="..\..\..\trees.c">
- </File>
- <File
- RelativePath="..\..\..\uncompr.c">
- </File>
- <File
- RelativePath="..\..\minizip\unzip.c">
- </File>
- <File
- RelativePath="..\..\minizip\zip.c">
- </File>
- <File
- RelativePath=".\zlib.rc">
- </File>
- <File
- RelativePath=".\zlibvc.def">
- </File>
- <File
- RelativePath="..\..\..\zutil.c">
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc7/zlibvc.def b/cpukit/zlib/contrib/vstudio/vc7/zlibvc.def
deleted file mode 100644
index a40e71541f..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/zlibvc.def
+++ /dev/null
@@ -1,92 +0,0 @@
-
-VERSION 1.23
-
-HEAPSIZE 1048576,8192
-
-EXPORTS
- adler32 @1
- compress @2
- crc32 @3
- deflate @4
- deflateCopy @5
- deflateEnd @6
- deflateInit2_ @7
- deflateInit_ @8
- deflateParams @9
- deflateReset @10
- deflateSetDictionary @11
- gzclose @12
- gzdopen @13
- gzerror @14
- gzflush @15
- gzopen @16
- gzread @17
- gzwrite @18
- inflate @19
- inflateEnd @20
- inflateInit2_ @21
- inflateInit_ @22
- inflateReset @23
- inflateSetDictionary @24
- inflateSync @25
- uncompress @26
- zlibVersion @27
- gzprintf @28
- gzputc @29
- gzgetc @30
- gzseek @31
- gzrewind @32
- gztell @33
- gzeof @34
- gzsetparams @35
- zError @36
- inflateSyncPoint @37
- get_crc_table @38
- compress2 @39
- gzputs @40
- gzgets @41
- inflateCopy @42
- inflateBackInit_ @43
- inflateBack @44
- inflateBackEnd @45
- compressBound @46
- deflateBound @47
- gzclearerr @48
- gzungetc @49
- zlibCompileFlags @50
- deflatePrime @51
-
- unzOpen @61
- unzClose @62
- unzGetGlobalInfo @63
- unzGetCurrentFileInfo @64
- unzGoToFirstFile @65
- unzGoToNextFile @66
- unzOpenCurrentFile @67
- unzReadCurrentFile @68
- unzOpenCurrentFile3 @69
- unztell @70
- unzeof @71
- unzCloseCurrentFile @72
- unzGetGlobalComment @73
- unzStringFileNameCompare @74
- unzLocateFile @75
- unzGetLocalExtrafield @76
- unzOpen2 @77
- unzOpenCurrentFile2 @78
- unzOpenCurrentFilePassword @79
-
- zipOpen @80
- zipOpenNewFileInZip @81
- zipWriteInFileInZip @82
- zipCloseFileInZip @83
- zipClose @84
- zipOpenNewFileInZip2 @86
- zipCloseFileInZipRaw @87
- zipOpen2 @88
- zipOpenNewFileInZip3 @89
-
- unzGetFilePos @100
- unzGoToFilePos @101
-
- fill_win32_filefunc @110
diff --git a/cpukit/zlib/contrib/vstudio/vc7/zlibvc.sln b/cpukit/zlib/contrib/vstudio/vc7/zlibvc.sln
deleted file mode 100644
index 927b42b7bd..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/zlibvc.sln
+++ /dev/null
@@ -1,78 +0,0 @@
-Microsoft Visual Studio Solution File, Format Version 7.00
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testZlibDll", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654C}"
-EndProject
-Global
- GlobalSection(SolutionConfiguration) = preSolution
- ConfigName.0 = Debug
- ConfigName.1 = Release
- ConfigName.2 = ReleaseAxp
- ConfigName.3 = ReleaseWithoutAsm
- ConfigName.4 = ReleaseWithoutCrtdll
- EndGlobalSection
- GlobalSection(ProjectDependencies) = postSolution
- EndGlobalSection
- GlobalSection(ProjectConfiguration) = postSolution
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.ActiveCfg = Debug|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.Build.0 = Debug|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.ActiveCfg = Release|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.Build.0 = Release|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.Build.0 = ReleaseAxp|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseAxp|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.Build.0 = ReleaseAxp|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.ActiveCfg = Debug|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.Build.0 = Debug|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.ActiveCfg = Release|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.Build.0 = Release|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.Build.0 = ReleaseAxp|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseWithoutCrtdll|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.Build.0 = ReleaseWithoutCrtdll|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.ActiveCfg = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.Build.0 = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.ActiveCfg = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.Build.0 = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.Build.0 = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.ActiveCfg = Debug|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.Build.0 = Debug|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.ActiveCfg = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.Build.0 = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.ActiveCfg = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.Build.0 = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.ActiveCfg = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.Build.0 = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.Build.0 = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Debug.ActiveCfg = Debug|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Debug.Build.0 = Debug|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Release.ActiveCfg = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Release.Build.0 = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseAxp.ActiveCfg = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseAxp.Build.0 = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutAsm.ActiveCfg = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutAsm.Build.0 = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutCrtdll.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- EndGlobalSection
- GlobalSection(ExtensibilityAddIns) = postSolution
- EndGlobalSection
-EndGlobal
diff --git a/cpukit/zlib/contrib/vstudio/vc7/zlibvc.vcproj b/cpukit/zlib/contrib/vstudio/vc7/zlibvc.vcproj
deleted file mode 100644
index 8533b49475..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc7/zlibvc.vcproj
+++ /dev/null
@@ -1,445 +0,0 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.00"
- Name="zlibvc"
- SccProjectName=""
- SccLocalPath="">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory=".\DebugDll"
- IntermediateDirectory=".\DebugDll"
- ConfigurationType="2"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,ZLIB_WINAPI,ASMV,ASMINF"
- ExceptionHandling="FALSE"
- RuntimeLibrary="1"
- PrecompiledHeaderFile=".\DebugDll/zlibvc.pch"
- AssemblerListingLocation=".\DebugDll/"
- ObjectFile=".\DebugDll/"
- ProgramDataBaseFileName=".\DebugDll/"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"
- DebugInformationFormat="4"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj"
- OutputFile=".\DebugDll\zlibwapi.dll"
- LinkIncremental="2"
- SuppressStartupBanner="TRUE"
- ModuleDefinitionFile=".\zlibvc.def"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile=".\DebugDll/zlibwapi.pdb"
- SubSystem="2"
- ImportLibrary=".\DebugDll/zlibwapi.lib"/>
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="TRUE"
- SuppressStartupBanner="TRUE"
- TargetEnvironment="1"
- TypeLibraryName=".\DebugDll/zlibvc.tlb"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Win32"
- OutputDirectory=".\zlibDllWithoutAsm"
- IntermediateDirectory=".\zlibDllWithoutAsm"
- ConfigurationType="2"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE"
- WholeProgramOptimization="TRUE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,ZLIB_WINAPI"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\zlibDllWithoutAsm/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation=".\zlibDllWithoutAsm/"
- ObjectFile=".\zlibDllWithoutAsm/"
- ProgramDataBaseFileName=".\zlibDllWithoutAsm/"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="crtdll.lib"
- OutputFile=".\zlibDllWithoutAsm\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="TRUE"
- IgnoreAllDefaultLibraries="TRUE"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile=".\zlibDllWithoutAsm/zlibwapi.pdb"
- GenerateMapFile="TRUE"
- MapFileName=".\zlibDllWithoutAsm/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary=".\zlibDllWithoutAsm/zlibwapi.lib"/>
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="TRUE"
- SuppressStartupBanner="TRUE"
- TargetEnvironment="1"
- TypeLibraryName=".\zlibDllWithoutAsm/zlibvc.tlb"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="ReleaseWithoutCrtdll|Win32"
- OutputDirectory=".\zlibDllWithoutCrtDll"
- IntermediateDirectory=".\zlibDllWithoutCrtDll"
- ConfigurationType="2"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE"
- WholeProgramOptimization="TRUE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,ZLIB_WINAPI,ASMV,ASMINF"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\zlibDllWithoutCrtDll/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation=".\zlibDllWithoutCrtDll/"
- ObjectFile=".\zlibDllWithoutCrtDll/"
- ProgramDataBaseFileName=".\zlibDllWithoutCrtDll/"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj "
- OutputFile=".\zlibDllWithoutCrtDll\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="TRUE"
- IgnoreAllDefaultLibraries="FALSE"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile=".\zlibDllWithoutCrtDll/zlibwapi.pdb"
- GenerateMapFile="TRUE"
- MapFileName=".\zlibDllWithoutCrtDll/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary=".\zlibDllWithoutCrtDll/zlibwapi.lib"/>
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="TRUE"
- SuppressStartupBanner="TRUE"
- TargetEnvironment="1"
- TypeLibraryName=".\zlibDllWithoutCrtDll/zlibvc.tlb"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="ReleaseAxp|Win32"
- OutputDirectory=".\zlibvc__"
- IntermediateDirectory=".\zlibvc__"
- ConfigurationType="2"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE"
- WholeProgramOptimization="TRUE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,ZLIB_WINAPI"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\zlibvc__/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation=".\zlibvc__/"
- ObjectFile=".\zlibvc__/"
- ProgramDataBaseFileName=".\zlibvc__/"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="crtdll.lib"
- OutputFile="zlibvc__\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="TRUE"
- IgnoreAllDefaultLibraries="TRUE"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile=".\zlibvc__/zlibwapi.pdb"
- GenerateMapFile="TRUE"
- MapFileName=".\zlibvc__/zlibwapi.map"
- SubSystem="2"
- ImportLibrary=".\zlibvc__/zlibwapi.lib"/>
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="TRUE"
- SuppressStartupBanner="TRUE"
- TargetEnvironment="1"
- TypeLibraryName=".\zlibvc__/zlibvc.tlb"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory=".\ReleaseDll"
- IntermediateDirectory=".\ReleaseDll"
- ConfigurationType="2"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE"
- WholeProgramOptimization="TRUE">
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,ZLIB_WINAPI,ASMV,ASMINF"
- StringPooling="TRUE"
- ExceptionHandling="FALSE"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="TRUE"
- PrecompiledHeaderFile=".\ReleaseDll/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation=".\ReleaseDll/"
- ObjectFile=".\ReleaseDll/"
- ProgramDataBaseFileName=".\ReleaseDll/"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj crtdll.lib"
- OutputFile=".\ReleaseDll\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="TRUE"
- IgnoreAllDefaultLibraries="TRUE"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile=".\ReleaseDll/zlibwapi.pdb"
- GenerateMapFile="TRUE"
- MapFileName=".\ReleaseDll/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary=".\ReleaseDll/zlibwapi.lib"/>
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="TRUE"
- SuppressStartupBanner="TRUE"
- TargetEnvironment="1"
- TypeLibraryName=".\Release/zlibvc.tlb"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- </Configurations>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90">
- <File
- RelativePath="..\..\..\adler32.c">
- </File>
- <File
- RelativePath="..\..\..\compress.c">
- </File>
- <File
- RelativePath="..\..\..\crc32.c">
- </File>
- <File
- RelativePath="..\..\..\deflate.c">
- </File>
- <File
- RelativePath="..\..\masmx86\gvmat32c.c">
- <FileConfiguration
- Name="ReleaseWithoutAsm|Win32"
- ExcludedFromBuild="TRUE">
- <Tool
- Name="VCCLCompilerTool"/>
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\gzio.c">
- </File>
- <File
- RelativePath="..\..\..\infback.c">
- </File>
- <File
- RelativePath="..\..\..\inffast.c">
- </File>
- <File
- RelativePath="..\..\..\inflate.c">
- </File>
- <File
- RelativePath="..\..\..\inftrees.c">
- </File>
- <File
- RelativePath="..\..\minizip\ioapi.c">
- </File>
- <File
- RelativePath="..\..\minizip\iowin32.c">
- </File>
- <File
- RelativePath="..\..\..\trees.c">
- </File>
- <File
- RelativePath="..\..\..\uncompr.c">
- </File>
- <File
- RelativePath="..\..\minizip\unzip.c">
- <FileConfiguration
- Name="Release|Win32">
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"/>
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\minizip\zip.c">
- <FileConfiguration
- Name="Release|Win32">
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"/>
- </FileConfiguration>
- </File>
- <File
- RelativePath=".\zlib.rc">
- </File>
- <File
- RelativePath=".\zlibvc.def">
- </File>
- <File
- RelativePath="..\..\..\zutil.c">
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;fi;fd">
- <File
- RelativePath="..\..\..\deflate.h">
- </File>
- <File
- RelativePath="..\..\..\infblock.h">
- </File>
- <File
- RelativePath="..\..\..\infcodes.h">
- </File>
- <File
- RelativePath="..\..\..\inffast.h">
- </File>
- <File
- RelativePath="..\..\..\inftrees.h">
- </File>
- <File
- RelativePath="..\..\..\infutil.h">
- </File>
- <File
- RelativePath="..\..\..\zconf.h">
- </File>
- <File
- RelativePath="..\..\..\zlib.h">
- </File>
- <File
- RelativePath="..\..\..\zutil.h">
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc8/miniunz.vcproj b/cpukit/zlib/contrib/vstudio/vc8/miniunz.vcproj
deleted file mode 100644
index 4af53e8a31..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/miniunz.vcproj
+++ /dev/null
@@ -1,566 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8,00"
- Name="miniunz"
- ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694382A}"
- Keyword="Win32Proj"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- <Platform
- Name="Itanium"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="x86\MiniUnzip$(ConfigurationName)"
- IntermediateDirectory="x86\MiniUnzip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="1"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x86\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/miniunz.pdb"
- SubSystem="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="x64\MiniUnzip$(ConfigurationName)"
- IntermediateDirectory="x64\MiniUnzip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x64\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/miniunz.pdb"
- SubSystem="1"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Itanium"
- OutputDirectory="ia64\MiniUnzip$(ConfigurationName)"
- IntermediateDirectory="ia64\MiniUnzip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ia64\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/miniunz.pdb"
- SubSystem="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="x86\MiniUnzip$(ConfigurationName)"
- IntermediateDirectory="x86\MiniUnzip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x86\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="x64\MiniUnzip$(ConfigurationName)"
- IntermediateDirectory="x64\MiniUnzip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x64\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Itanium"
- OutputDirectory="ia64\MiniUnzip$(ConfigurationName)"
- IntermediateDirectory="ia64\MiniUnzip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ia64\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/miniunz.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
- >
- <File
- RelativePath="..\..\minizip\miniunz.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc"
- >
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
- >
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc8/minizip.vcproj b/cpukit/zlib/contrib/vstudio/vc8/minizip.vcproj
deleted file mode 100644
index 85f64c4d2a..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/minizip.vcproj
+++ /dev/null
@@ -1,563 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8,00"
- Name="minizip"
- ProjectGUID="{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"
- Keyword="Win32Proj"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- <Platform
- Name="Itanium"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="x86\MiniZip$(ConfigurationName)"
- IntermediateDirectory="x86\MiniZip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="1"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x86\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/minizip.pdb"
- SubSystem="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="x64\$(ConfigurationName)"
- IntermediateDirectory="x64\$(ConfigurationName)"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x64\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/minizip.pdb"
- SubSystem="1"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Itanium"
- OutputDirectory="ia64\$(ConfigurationName)"
- IntermediateDirectory="ia64\$(ConfigurationName)"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ia64\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/minizip.pdb"
- SubSystem="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="x86\MiniZip$(ConfigurationName)"
- IntermediateDirectory="x86\MiniZip$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x86\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="1"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="x64\$(ConfigurationName)"
- IntermediateDirectory="x64\$(ConfigurationName)"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x64\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="1"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Itanium"
- OutputDirectory="ia64\$(ConfigurationName)"
- IntermediateDirectory="ia64\$(ConfigurationName)"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ia64\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/minizip.exe"
- LinkIncremental="1"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
- >
- <File
- RelativePath="..\..\minizip\minizip.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc"
- >
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
- >
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc8/testzlib.vcproj b/cpukit/zlib/contrib/vstudio/vc8/testzlib.vcproj
deleted file mode 100644
index 68c3539911..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/testzlib.vcproj
+++ /dev/null
@@ -1,948 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8,00"
- Name="testzlib"
- ProjectGUID="{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
- RootNamespace="testzlib"
- Keyword="Win32Proj"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- <Platform
- Name="Itanium"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="x86\TestZlib$(ConfigurationName)"
- IntermediateDirectory="x86\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="1"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerOutput="4"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
- SubSystem="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="x64\TestZlib$(ConfigurationName)"
- IntermediateDirectory="x64\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- AssemblerListingLocation="$(IntDir)\"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj"
- GenerateManifest="false"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Itanium"
- OutputDirectory="ia64\TestZlib$(ConfigurationName)"
- IntermediateDirectory="ia64\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerOutput="4"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
- SubSystem="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Win32"
- OutputDirectory="x86\TestZlib$(ConfigurationName)"
- IntermediateDirectory="x86\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- CharacterSet="2"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|x64"
- OutputDirectory="x64\TestZlib$(ConfigurationName)"
- IntermediateDirectory="x64\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- AssemblerListingLocation="$(IntDir)\"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies=""
- GenerateManifest="false"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Itanium"
- OutputDirectory="ia64\TestZlib$(ConfigurationName)"
- IntermediateDirectory="ia64\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- CharacterSet="2"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="x86\TestZlib$(ConfigurationName)"
- IntermediateDirectory="x86\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- CharacterSet="2"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="x64\TestZlib$(ConfigurationName)"
- IntermediateDirectory="x64\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- AssemblerListingLocation="$(IntDir)\"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj"
- GenerateManifest="false"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Itanium"
- OutputDirectory="ia64\TestZlib$(ConfigurationName)"
- IntermediateDirectory="ia64\TestZlib$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- CharacterSet="2"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\.."
- PreprocessorDefinitions="ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
- >
- <File
- RelativePath="..\..\..\adler32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\compress.c"
- >
- </File>
- <File
- RelativePath="..\..\..\crc32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\deflate.c"
- >
- </File>
- <File
- RelativePath="..\..\masmx86\gvmat32c.c"
- >
- <FileConfiguration
- Name="Debug|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Win64 (AMD64)"
- ExcludedFromBuild="TRUE"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win64 (AMD64)"
- ExcludedFromBuild="TRUE"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseAsm|Win64 (AMD64)"
- ExcludedFromBuild="TRUE"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\infback.c"
- >
- </File>
- <File
- RelativePath="..\..\masmx64\inffas8664.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\inffast.c"
- >
- </File>
- <File
- RelativePath="..\..\..\inflate.c"
- >
- </File>
- <File
- RelativePath="..\..\..\inftrees.c"
- >
- </File>
- <File
- RelativePath="..\..\testzlib\testzlib.c"
- >
- </File>
- <File
- RelativePath="..\..\..\trees.c"
- >
- </File>
- <File
- RelativePath="..\..\..\uncompr.c"
- >
- </File>
- <File
- RelativePath="..\..\..\zutil.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc"
- >
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
- >
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc8/testzlibdll.vcproj b/cpukit/zlib/contrib/vstudio/vc8/testzlibdll.vcproj
deleted file mode 100644
index f38ab5e08a..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/testzlibdll.vcproj
+++ /dev/null
@@ -1,567 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8,00"
- Name="TestZlibDll"
- ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694366A}"
- Keyword="Win32Proj"
- SignManifests="true"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- <Platform
- Name="Itanium"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="x86\TestZlibDll$(ConfigurationName)"
- IntermediateDirectory="x86\TestZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="1"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x86\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
- SubSystem="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="x64\TestZlibDll$(ConfigurationName)"
- IntermediateDirectory="x64\TestZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x64\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
- SubSystem="1"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Itanium"
- OutputDirectory="ia64\TestZlibDll$(ConfigurationName)"
- IntermediateDirectory="ia64\TestZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64"
- MinimalRebuild="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ia64\ZlibDllDebug\zlibwapi.lib"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
- SubSystem="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="x86\TestZlibDll$(ConfigurationName)"
- IntermediateDirectory="x86\TestZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x86\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="x64\TestZlibDll$(ConfigurationName)"
- IntermediateDirectory="x64\TestZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="x64\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Itanium"
- OutputDirectory="ia64\TestZlibDll$(ConfigurationName)"
- IntermediateDirectory="ia64\TestZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="1"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="true"
- AdditionalIncludeDirectories="..\..\..;..\..\minizip"
- PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64"
- StringPooling="true"
- BasicRuntimeChecks="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- UsePrecompiledHeader="0"
- AssemblerListingLocation="$(IntDir)\"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ia64\ZlibDllRelease\zlibwapi.lib"
- OutputFile="$(OutDir)/testzlib.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="1"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
- >
- <File
- RelativePath="..\..\testzlib\testzlib.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc"
- >
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
- >
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc8/zlib.rc b/cpukit/zlib/contrib/vstudio/vc8/zlib.rc
deleted file mode 100644
index 72cb8b4c31..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/zlib.rc
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <windows.h>
-
-#define IDR_VERSION1 1
-IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
- FILEVERSION 1,2,3,0
- PRODUCTVERSION 1,2,3,0
- FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
- FILEFLAGS 0
- FILEOS VOS_DOS_WINDOWS32
- FILETYPE VFT_DLL
- FILESUBTYPE 0 // not used
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904E4"
- //language ID = U.S. English, char set = Windows, Multilingual
-
- BEGIN
- VALUE "FileDescription", "zlib data compression library\0"
- VALUE "FileVersion", "1.2.3.0\0"
- VALUE "InternalName", "zlib\0"
- VALUE "OriginalFilename", "zlib.dll\0"
- VALUE "ProductName", "ZLib.DLL\0"
- VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
- VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x0409, 1252
- END
-END
diff --git a/cpukit/zlib/contrib/vstudio/vc8/zlibstat.vcproj b/cpukit/zlib/contrib/vstudio/vc8/zlibstat.vcproj
deleted file mode 100644
index fb97037acf..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/zlibstat.vcproj
+++ /dev/null
@@ -1,870 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8,00"
- Name="zlibstat"
- ProjectGUID="{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- <Platform
- Name="Itanium"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="x86\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="x86\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- ExceptionHandling="0"
- RuntimeLibrary="1"
- BufferSecurityCheck="false"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="1"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:X86 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="x64\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="x64\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- ExceptionHandling="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="1"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:AMD64 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Itanium"
- OutputDirectory="ia64\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="ia64\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- ExceptionHandling="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="1"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:IA64 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="x86\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="x86\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ASMV;ASMINF"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:X86 /NODEFAULTLIB"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj "
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="x64\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="x64\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ASMV;ASMINF;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:AMD64 /NODEFAULTLIB"
- AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj "
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Itanium"
- OutputDirectory="ia64\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="ia64\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:IA64 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Win32"
- OutputDirectory="x86\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="x86\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="0"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:X86 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|x64"
- OutputDirectory="x64\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="x64\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:AMD64 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Itanium"
- OutputDirectory="ia64\ZlibStat$(ConfigurationName)"
- IntermediateDirectory="ia64\ZlibStat$(ConfigurationName)\Tmp"
- ConfigurationType="4"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="2"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibstat.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- AdditionalOptions="/MACHINE:IA64 /NODEFAULTLIB"
- OutputFile="$(OutDir)\zlibstat.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- >
- <File
- RelativePath="..\..\..\adler32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\compress.c"
- >
- </File>
- <File
- RelativePath="..\..\..\crc32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\deflate.c"
- >
- </File>
- <File
- RelativePath="..\..\masmx86\gvmat32c.c"
- >
- <FileConfiguration
- Name="Debug|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\gzio.c"
- >
- </File>
- <File
- RelativePath="..\..\..\infback.c"
- >
- </File>
- <File
- RelativePath="..\..\masmx64\inffas8664.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\inffast.c"
- >
- </File>
- <File
- RelativePath="..\..\..\inflate.c"
- >
- </File>
- <File
- RelativePath="..\..\..\inftrees.c"
- >
- </File>
- <File
- RelativePath="..\..\minizip\ioapi.c"
- >
- </File>
- <File
- RelativePath="..\..\..\trees.c"
- >
- </File>
- <File
- RelativePath="..\..\..\uncompr.c"
- >
- </File>
- <File
- RelativePath="..\..\minizip\unzip.c"
- >
- </File>
- <File
- RelativePath="..\..\minizip\zip.c"
- >
- </File>
- <File
- RelativePath=".\zlib.rc"
- >
- </File>
- <File
- RelativePath=".\zlibvc.def"
- >
- </File>
- <File
- RelativePath="..\..\..\zutil.c"
- >
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/contrib/vstudio/vc8/zlibvc.def b/cpukit/zlib/contrib/vstudio/vc8/zlibvc.def
deleted file mode 100644
index a40e71541f..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/zlibvc.def
+++ /dev/null
@@ -1,92 +0,0 @@
-
-VERSION 1.23
-
-HEAPSIZE 1048576,8192
-
-EXPORTS
- adler32 @1
- compress @2
- crc32 @3
- deflate @4
- deflateCopy @5
- deflateEnd @6
- deflateInit2_ @7
- deflateInit_ @8
- deflateParams @9
- deflateReset @10
- deflateSetDictionary @11
- gzclose @12
- gzdopen @13
- gzerror @14
- gzflush @15
- gzopen @16
- gzread @17
- gzwrite @18
- inflate @19
- inflateEnd @20
- inflateInit2_ @21
- inflateInit_ @22
- inflateReset @23
- inflateSetDictionary @24
- inflateSync @25
- uncompress @26
- zlibVersion @27
- gzprintf @28
- gzputc @29
- gzgetc @30
- gzseek @31
- gzrewind @32
- gztell @33
- gzeof @34
- gzsetparams @35
- zError @36
- inflateSyncPoint @37
- get_crc_table @38
- compress2 @39
- gzputs @40
- gzgets @41
- inflateCopy @42
- inflateBackInit_ @43
- inflateBack @44
- inflateBackEnd @45
- compressBound @46
- deflateBound @47
- gzclearerr @48
- gzungetc @49
- zlibCompileFlags @50
- deflatePrime @51
-
- unzOpen @61
- unzClose @62
- unzGetGlobalInfo @63
- unzGetCurrentFileInfo @64
- unzGoToFirstFile @65
- unzGoToNextFile @66
- unzOpenCurrentFile @67
- unzReadCurrentFile @68
- unzOpenCurrentFile3 @69
- unztell @70
- unzeof @71
- unzCloseCurrentFile @72
- unzGetGlobalComment @73
- unzStringFileNameCompare @74
- unzLocateFile @75
- unzGetLocalExtrafield @76
- unzOpen2 @77
- unzOpenCurrentFile2 @78
- unzOpenCurrentFilePassword @79
-
- zipOpen @80
- zipOpenNewFileInZip @81
- zipWriteInFileInZip @82
- zipCloseFileInZip @83
- zipClose @84
- zipOpenNewFileInZip2 @86
- zipCloseFileInZipRaw @87
- zipOpen2 @88
- zipOpenNewFileInZip3 @89
-
- unzGetFilePos @100
- unzGoToFilePos @101
-
- fill_win32_filefunc @110
diff --git a/cpukit/zlib/contrib/vstudio/vc8/zlibvc.sln b/cpukit/zlib/contrib/vstudio/vc8/zlibvc.sln
deleted file mode 100644
index a815a5549f..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/zlibvc.sln
+++ /dev/null
@@ -1,144 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 9.00
-# Visual Studio 2005
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestZlibDll", "testzlibdll.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}"
- ProjectSection(ProjectDependencies) = postProject
- {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D}
- EndProjectSection
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"
- ProjectSection(ProjectDependencies) = postProject
- {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D}
- EndProjectSection
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}"
- ProjectSection(ProjectDependencies) = postProject
- {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D}
- EndProjectSection
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Itanium = Debug|Itanium
- Debug|Win32 = Debug|Win32
- Debug|x64 = Debug|x64
- Release|Itanium = Release|Itanium
- Release|Win32 = Release|Win32
- Release|x64 = Release|x64
- ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium
- ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32
- ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = ReleaseWithoutAsm|x64
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = ReleaseWithoutAsm|x64
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64
- {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64
- {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64
- {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Itanium
- {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Itanium
- {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|Itanium
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/cpukit/zlib/contrib/vstudio/vc8/zlibvc.vcproj b/cpukit/zlib/contrib/vstudio/vc8/zlibvc.vcproj
deleted file mode 100644
index e717011df7..0000000000
--- a/cpukit/zlib/contrib/vstudio/vc8/zlibvc.vcproj
+++ /dev/null
@@ -1,1219 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8,00"
- Name="zlibvc"
- ProjectGUID="{8FD826F8-3739-44E6-8CC8-997122E53B8D}"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- <Platform
- Name="Itanium"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="x86\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="x86\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,_CRT_SECURE_NO_DEPRECATE,ZLIB_WINAPI,ASMV,ASMINF"
- ExceptionHandling="0"
- RuntimeLibrary="1"
- BufferSecurityCheck="false"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj"
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="2"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- ModuleDefinitionFile=".\zlibvc.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="x64\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="x64\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="3"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,_CRT_SECURE_NO_DEPRECATE,ZLIB_WINAPI,ASMV,ASMINF;WIN64"
- ExceptionHandling="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj "
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="2"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- ModuleDefinitionFile=".\zlibvc.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Itanium"
- OutputDirectory="ia64\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="ia64\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="_DEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="2"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;WIN64"
- ExceptionHandling="0"
- RuntimeLibrary="3"
- BufferSecurityCheck="false"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="2"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- ModuleDefinitionFile=".\zlibvc.def"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Win32"
- OutputDirectory="x86\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="x86\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,_CRT_SECURE_NO_DEPRECATE,ZLIB_WINAPI"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- IgnoreAllDefaultLibraries="false"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|x64"
- OutputDirectory="x64\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="x64\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="3"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,_CRT_SECURE_NO_DEPRECATE,ZLIB_WINAPI;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- IgnoreAllDefaultLibraries="false"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="ReleaseWithoutAsm|Itanium"
- OutputDirectory="ia64\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="ia64\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="2"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32,_CRT_SECURE_NO_DEPRECATE,ZLIB_WINAPI;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- IgnoreAllDefaultLibraries="false"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="x86\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="x86\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="1"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;ASMV;ASMINF"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/MACHINE:I386"
- AdditionalDependencies="..\..\masmx86\gvmat32.obj ..\..\masmx86\inffas32.obj "
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- IgnoreAllDefaultLibraries="false"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="x64\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="x64\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="3"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;ASMV;ASMINF;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj "
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- IgnoreAllDefaultLibraries="false"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Itanium"
- OutputDirectory="ia64\ZlibDll$(ConfigurationName)"
- IntermediateDirectory="ia64\ZlibDll$(ConfigurationName)\Tmp"
- ConfigurationType="2"
- InheritedPropertySheets="UpgradeFromVC70.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- PreprocessorDefinitions="NDEBUG"
- MkTypLibCompatible="true"
- SuppressStartupBanner="true"
- TargetEnvironment="2"
- TypeLibraryName="$(OutDir)/zlibvc.tlb"
- />
- <Tool
- Name="VCCLCompilerTool"
- InlineFunctionExpansion="1"
- AdditionalIncludeDirectories="..\..\..;..\..\masmx86"
- PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;WIN64"
- StringPooling="true"
- ExceptionHandling="0"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile="$(IntDir)/zlibvc.pch"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)\"
- ObjectFile="$(IntDir)\"
- ProgramDataBaseFileName="$(OutDir)\"
- BrowseInformation="0"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1036"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)\zlibwapi.dll"
- LinkIncremental="1"
- SuppressStartupBanner="true"
- GenerateManifest="false"
- IgnoreAllDefaultLibraries="false"
- ModuleDefinitionFile=".\zlibvc.def"
- ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb"
- GenerateMapFile="true"
- MapFileName="$(OutDir)/zlibwapi.map"
- SubSystem="2"
- OptimizeForWindows98="1"
- ImportLibrary="$(OutDir)/zlibwapi.lib"
- TargetMachine="5"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
- >
- <File
- RelativePath="..\..\..\adler32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\compress.c"
- >
- </File>
- <File
- RelativePath="..\..\..\crc32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\deflate.c"
- >
- </File>
- <File
- RelativePath="..\..\masmx86\gvmat32c.c"
- >
- <FileConfiguration
- Name="Debug|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|x64"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\gzio.c"
- >
- </File>
- <File
- RelativePath="..\..\..\infback.c"
- >
- </File>
- <File
- RelativePath="..\..\masmx64\inffas8664.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="ReleaseWithoutAsm|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\..\inffast.c"
- >
- </File>
- <File
- RelativePath="..\..\..\inflate.c"
- >
- </File>
- <File
- RelativePath="..\..\..\inftrees.c"
- >
- </File>
- <File
- RelativePath="..\..\minizip\ioapi.c"
- >
- </File>
- <File
- RelativePath="..\..\minizip\iowin32.c"
- >
- </File>
- <File
- RelativePath="..\..\..\trees.c"
- >
- </File>
- <File
- RelativePath="..\..\..\uncompr.c"
- >
- </File>
- <File
- RelativePath="..\..\minizip\unzip.c"
- >
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|x64"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\minizip\zip.c"
- >
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|x64"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Itanium"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="ZLIB_INTERNAL"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath=".\zlib.rc"
- >
- </File>
- <File
- RelativePath=".\zlibvc.def"
- >
- </File>
- <File
- RelativePath="..\..\..\zutil.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;fi;fd"
- >
- <File
- RelativePath="..\..\..\deflate.h"
- >
- </File>
- <File
- RelativePath="..\..\..\infblock.h"
- >
- </File>
- <File
- RelativePath="..\..\..\infcodes.h"
- >
- </File>
- <File
- RelativePath="..\..\..\inffast.h"
- >
- </File>
- <File
- RelativePath="..\..\..\inftrees.h"
- >
- </File>
- <File
- RelativePath="..\..\..\infutil.h"
- >
- </File>
- <File
- RelativePath="..\..\..\zconf.h"
- >
- </File>
- <File
- RelativePath="..\..\..\zlib.h"
- >
- </File>
- <File
- RelativePath="..\..\..\zutil.h"
- >
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
- >
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/cpukit/zlib/crc32.c b/cpukit/zlib/crc32.c
index 1acc7ed8e4..6b81fb4a1c 100644
--- a/cpukit/zlib/crc32.c
+++ b/cpukit/zlib/crc32.c
@@ -221,7 +221,7 @@ const unsigned long FAR * ZEXPORT get_crc_table()
unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
- unsigned len;
+ uInt len;
{
if (buf == Z_NULL) return 0UL;
diff --git a/cpukit/zlib/example.c b/cpukit/zlib/example.c
deleted file mode 100644
index 604736f15f..0000000000
--- a/cpukit/zlib/example.c
+++ /dev/null
@@ -1,565 +0,0 @@
-/* example.c -- usage example of the zlib compression library
- * Copyright (C) 1995-2006 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#include "zlib.h"
-#include <stdio.h>
-
-#ifdef STDC
-# include <string.h>
-# include <stdlib.h>
-#endif
-
-#if defined(VMS) || defined(RISCOS)
-# define TESTFILE "foo-gz"
-#else
-# define TESTFILE "foo.gz"
-#endif
-
-#define CHECK_ERR(err, msg) { \
- if (err != Z_OK) { \
- fprintf(stderr, "%s error: %d\n", msg, err); \
- exit(1); \
- } \
-}
-
-const char hello[] = "hello, hello!";
-/* "hello world" would be more standard, but the repeated "hello"
- * stresses the compression code better, sorry...
- */
-
-const char dictionary[] = "hello";
-uLong dictId; /* Adler32 value of the dictionary */
-
-void test_compress OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_gzio OF((const char *fname,
- Byte *uncompr, uLong uncomprLen));
-void test_deflate OF((Byte *compr, uLong comprLen));
-void test_inflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_large_deflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_large_inflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_flush OF((Byte *compr, uLong *comprLen));
-void test_sync OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_dict_deflate OF((Byte *compr, uLong comprLen));
-void test_dict_inflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-int main OF((int argc, char *argv[]));
-
-/* ===========================================================================
- * Test compress() and uncompress()
- */
-void test_compress(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
- int err;
- uLong len = (uLong)strlen(hello)+1;
-
- err = compress(compr, &comprLen, (const Bytef*)hello, len);
- CHECK_ERR(err, "compress");
-
- strcpy((char*)uncompr, "garbage");
-
- err = uncompress(uncompr, &uncomprLen, compr, comprLen);
- CHECK_ERR(err, "uncompress");
-
- if (strcmp((char*)uncompr, hello)) {
- fprintf(stderr, "bad uncompress\n");
- exit(1);
- } else {
- printf("uncompress(): %s\n", (char *)uncompr);
- }
-}
-
-/* ===========================================================================
- * Test read/write of .gz files
- */
-void test_gzio(fname, uncompr, uncomprLen)
- const char *fname; /* compressed file name */
- Byte *uncompr;
- uLong uncomprLen;
-{
-#ifdef NO_GZCOMPRESS
- fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
-#else
- int err;
- int len = (int)strlen(hello)+1;
- gzFile file;
- z_off_t pos;
-
- file = gzopen(fname, "wb");
- if (file == NULL) {
- fprintf(stderr, "gzopen error\n");
- exit(1);
- }
- gzputc(file, 'h');
- if (gzputs(file, "ello") != 4) {
- fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
- exit(1);
- }
- if (gzprintf(file, ", %s!", "hello") != 8) {
- fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
- exit(1);
- }
- gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
- gzclose(file);
-
- file = gzopen(fname, "rb");
- if (file == NULL) {
- fprintf(stderr, "gzopen error\n");
- exit(1);
- }
- strcpy((char*)uncompr, "garbage");
-
- if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
- fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
- exit(1);
- }
- if (strcmp((char*)uncompr, hello)) {
- fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
- exit(1);
- } else {
- printf("gzread(): %s\n", (char*)uncompr);
- }
-
- pos = gzseek(file, -8L, SEEK_CUR);
- if (pos != 6 || gztell(file) != pos) {
- fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
- (long)pos, (long)gztell(file));
- exit(1);
- }
-
- if (gzgetc(file) != ' ') {
- fprintf(stderr, "gzgetc error\n");
- exit(1);
- }
-
- if (gzungetc(' ', file) != ' ') {
- fprintf(stderr, "gzungetc error\n");
- exit(1);
- }
-
- gzgets(file, (char*)uncompr, (int)uncomprLen);
- if (strlen((char*)uncompr) != 7) { /* " hello!" */
- fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
- exit(1);
- }
- if (strcmp((char*)uncompr, hello + 6)) {
- fprintf(stderr, "bad gzgets after gzseek\n");
- exit(1);
- } else {
- printf("gzgets() after gzseek: %s\n", (char*)uncompr);
- }
-
- gzclose(file);
-#endif
-}
-
-/* ===========================================================================
- * Test deflate() with small buffers
- */
-void test_deflate(compr, comprLen)
- Byte *compr;
- uLong comprLen;
-{
- z_stream c_stream; /* compression stream */
- int err;
- uLong len = (uLong)strlen(hello)+1;
-
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
- c_stream.opaque = (voidpf)0;
-
- err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
- CHECK_ERR(err, "deflateInit");
-
- c_stream.next_in = (Bytef*)hello;
- c_stream.next_out = compr;
-
- while (c_stream.total_in != len && c_stream.total_out < comprLen) {
- c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
- err = deflate(&c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, "deflate");
- }
- /* Finish the stream, still forcing small buffers: */
- for (;;) {
- c_stream.avail_out = 1;
- err = deflate(&c_stream, Z_FINISH);
- if (err == Z_STREAM_END) break;
- CHECK_ERR(err, "deflate");
- }
-
- err = deflateEnd(&c_stream);
- CHECK_ERR(err, "deflateEnd");
-}
-
-/* ===========================================================================
- * Test inflate() with small buffers
- */
-void test_inflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
- int err;
- z_stream d_stream; /* decompression stream */
-
- strcpy((char*)uncompr, "garbage");
-
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
- d_stream.opaque = (voidpf)0;
-
- d_stream.next_in = compr;
- d_stream.avail_in = 0;
- d_stream.next_out = uncompr;
-
- err = inflateInit(&d_stream);
- CHECK_ERR(err, "inflateInit");
-
- while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
- d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
- err = inflate(&d_stream, Z_NO_FLUSH);
- if (err == Z_STREAM_END) break;
- CHECK_ERR(err, "inflate");
- }
-
- err = inflateEnd(&d_stream);
- CHECK_ERR(err, "inflateEnd");
-
- if (strcmp((char*)uncompr, hello)) {
- fprintf(stderr, "bad inflate\n");
- exit(1);
- } else {
- printf("inflate(): %s\n", (char *)uncompr);
- }
-}
-
-/* ===========================================================================
- * Test deflate() with large buffers and dynamic change of compression level
- */
-void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
- z_stream c_stream; /* compression stream */
- int err;
-
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
- c_stream.opaque = (voidpf)0;
-
- err = deflateInit(&c_stream, Z_BEST_SPEED);
- CHECK_ERR(err, "deflateInit");
-
- c_stream.next_out = compr;
- c_stream.avail_out = (uInt)comprLen;
-
- /* At this point, uncompr is still mostly zeroes, so it should compress
- * very well:
- */
- c_stream.next_in = uncompr;
- c_stream.avail_in = (uInt)uncomprLen;
- err = deflate(&c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, "deflate");
- if (c_stream.avail_in != 0) {
- fprintf(stderr, "deflate not greedy\n");
- exit(1);
- }
-
- /* Feed in already compressed data and switch to no compression: */
- deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
- c_stream.next_in = compr;
- c_stream.avail_in = (uInt)comprLen/2;
- err = deflate(&c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, "deflate");
-
- /* Switch back to compressing mode: */
- deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
- c_stream.next_in = uncompr;
- c_stream.avail_in = (uInt)uncomprLen;
- err = deflate(&c_stream, Z_NO_FLUSH);
- CHECK_ERR(err, "deflate");
-
- err = deflate(&c_stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- fprintf(stderr, "deflate should report Z_STREAM_END\n");
- exit(1);
- }
- err = deflateEnd(&c_stream);
- CHECK_ERR(err, "deflateEnd");
-}
-
-/* ===========================================================================
- * Test inflate() with large buffers
- */
-void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
- int err;
- z_stream d_stream; /* decompression stream */
-
- strcpy((char*)uncompr, "garbage");
-
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
- d_stream.opaque = (voidpf)0;
-
- d_stream.next_in = compr;
- d_stream.avail_in = (uInt)comprLen;
-
- err = inflateInit(&d_stream);
- CHECK_ERR(err, "inflateInit");
-
- for (;;) {
- d_stream.next_out = uncompr; /* discard the output */
- d_stream.avail_out = (uInt)uncomprLen;
- err = inflate(&d_stream, Z_NO_FLUSH);
- if (err == Z_STREAM_END) break;
- CHECK_ERR(err, "large inflate");
- }
-
- err = inflateEnd(&d_stream);
- CHECK_ERR(err, "inflateEnd");
-
- if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
- fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
- exit(1);
- } else {
- printf("large_inflate(): OK\n");
- }
-}
-
-/* ===========================================================================
- * Test deflate() with full flush
- */
-void test_flush(compr, comprLen)
- Byte *compr;
- uLong *comprLen;
-{
- z_stream c_stream; /* compression stream */
- int err;
- uInt len = (uInt)strlen(hello)+1;
-
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
- c_stream.opaque = (voidpf)0;
-
- err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
- CHECK_ERR(err, "deflateInit");
-
- c_stream.next_in = (Bytef*)hello;
- c_stream.next_out = compr;
- c_stream.avail_in = 3;
- c_stream.avail_out = (uInt)*comprLen;
- err = deflate(&c_stream, Z_FULL_FLUSH);
- CHECK_ERR(err, "deflate");
-
- compr[3]++; /* force an error in first compressed block */
- c_stream.avail_in = len - 3;
-
- err = deflate(&c_stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- CHECK_ERR(err, "deflate");
- }
- err = deflateEnd(&c_stream);
- CHECK_ERR(err, "deflateEnd");
-
- *comprLen = c_stream.total_out;
-}
-
-/* ===========================================================================
- * Test inflateSync()
- */
-void test_sync(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
- int err;
- z_stream d_stream; /* decompression stream */
-
- strcpy((char*)uncompr, "garbage");
-
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
- d_stream.opaque = (voidpf)0;
-
- d_stream.next_in = compr;
- d_stream.avail_in = 2; /* just read the zlib header */
-
- err = inflateInit(&d_stream);
- CHECK_ERR(err, "inflateInit");
-
- d_stream.next_out = uncompr;
- d_stream.avail_out = (uInt)uncomprLen;
-
- inflate(&d_stream, Z_NO_FLUSH);
- CHECK_ERR(err, "inflate");
-
- d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
- err = inflateSync(&d_stream); /* but skip the damaged part */
- CHECK_ERR(err, "inflateSync");
-
- err = inflate(&d_stream, Z_FINISH);
- if (err != Z_DATA_ERROR) {
- fprintf(stderr, "inflate should report DATA_ERROR\n");
- /* Because of incorrect adler32 */
- exit(1);
- }
- err = inflateEnd(&d_stream);
- CHECK_ERR(err, "inflateEnd");
-
- printf("after inflateSync(): hel%s\n", (char *)uncompr);
-}
-
-/* ===========================================================================
- * Test deflate() with preset dictionary
- */
-void test_dict_deflate(compr, comprLen)
- Byte *compr;
- uLong comprLen;
-{
- z_stream c_stream; /* compression stream */
- int err;
-
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
- c_stream.opaque = (voidpf)0;
-
- err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
- CHECK_ERR(err, "deflateInit");
-
- err = deflateSetDictionary(&c_stream,
- (const Bytef*)dictionary, sizeof(dictionary));
- CHECK_ERR(err, "deflateSetDictionary");
-
- dictId = c_stream.adler;
- c_stream.next_out = compr;
- c_stream.avail_out = (uInt)comprLen;
-
- c_stream.next_in = (Bytef*)hello;
- c_stream.avail_in = (uInt)strlen(hello)+1;
-
- err = deflate(&c_stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- fprintf(stderr, "deflate should report Z_STREAM_END\n");
- exit(1);
- }
- err = deflateEnd(&c_stream);
- CHECK_ERR(err, "deflateEnd");
-}
-
-/* ===========================================================================
- * Test inflate() with a preset dictionary
- */
-void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
- int err;
- z_stream d_stream; /* decompression stream */
-
- strcpy((char*)uncompr, "garbage");
-
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
- d_stream.opaque = (voidpf)0;
-
- d_stream.next_in = compr;
- d_stream.avail_in = (uInt)comprLen;
-
- err = inflateInit(&d_stream);
- CHECK_ERR(err, "inflateInit");
-
- d_stream.next_out = uncompr;
- d_stream.avail_out = (uInt)uncomprLen;
-
- for (;;) {
- err = inflate(&d_stream, Z_NO_FLUSH);
- if (err == Z_STREAM_END) break;
- if (err == Z_NEED_DICT) {
- if (d_stream.adler != dictId) {
- fprintf(stderr, "unexpected dictionary");
- exit(1);
- }
- err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
- sizeof(dictionary));
- }
- CHECK_ERR(err, "inflate with dict");
- }
-
- err = inflateEnd(&d_stream);
- CHECK_ERR(err, "inflateEnd");
-
- if (strcmp((char*)uncompr, hello)) {
- fprintf(stderr, "bad inflate with dict\n");
- exit(1);
- } else {
- printf("inflate with dictionary: %s\n", (char *)uncompr);
- }
-}
-
-/* ===========================================================================
- * Usage: example [output.gz [input.gz]]
- */
-
-int main(argc, argv)
- int argc;
- char *argv[];
-{
- Byte *compr, *uncompr;
- uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
- uLong uncomprLen = comprLen;
- static const char* myVersion = ZLIB_VERSION;
-
- if (zlibVersion()[0] != myVersion[0]) {
- fprintf(stderr, "incompatible zlib version\n");
- exit(1);
-
- } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
- fprintf(stderr, "warning: different zlib version\n");
- }
-
- printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
- ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
-
- compr = (Byte*)calloc((uInt)comprLen, 1);
- uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
- /* compr and uncompr are cleared to avoid reading uninitialized
- * data and to ensure that uncompr compresses well.
- */
- if (compr == Z_NULL || uncompr == Z_NULL) {
- printf("out of memory\n");
- exit(1);
- }
- test_compress(compr, comprLen, uncompr, uncomprLen);
-
- test_gzio((argc > 1 ? argv[1] : TESTFILE),
- uncompr, uncomprLen);
-
- test_deflate(compr, comprLen);
- test_inflate(compr, comprLen, uncompr, uncomprLen);
-
- test_large_deflate(compr, comprLen, uncompr, uncomprLen);
- test_large_inflate(compr, comprLen, uncompr, uncomprLen);
-
- test_flush(compr, &comprLen);
- test_sync(compr, comprLen, uncompr, uncomprLen);
- comprLen = uncomprLen;
-
- test_dict_deflate(compr, comprLen);
- test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
-
- free(compr);
- free(uncompr);
-
- return 0;
-}
diff --git a/cpukit/zlib/examples/README.examples b/cpukit/zlib/examples/README.examples
deleted file mode 100644
index 56a31714e5..0000000000
--- a/cpukit/zlib/examples/README.examples
+++ /dev/null
@@ -1,49 +0,0 @@
-This directory contains examples of the use of zlib and other relevant
-programs and documentation.
-
-enough.c
- calculation and justification of ENOUGH parameter in inftrees.h
- - calculates the maximum table space used in inflate tree
- construction over all possible Huffman codes
-
-fitblk.c
- compress just enough input to nearly fill a requested output size
- - zlib isn't designed to do this, but fitblk does it anyway
-
-gun.c
- uncompress a gzip file
- - illustrates the use of inflateBack() for high speed file-to-file
- decompression using call-back functions
- - is approximately twice as fast as gzip -d
- - also provides Unix uncompress functionality, again twice as fast
-
-gzappend.c
- append to a gzip file
- - illustrates the use of the Z_BLOCK flush parameter for inflate()
- - illustrates the use of deflatePrime() to start at any bit
-
-gzjoin.c
- join gzip files without recalculating the crc or recompressing
- - illustrates the use of the Z_BLOCK flush parameter for inflate()
- - illustrates the use of crc32_combine()
-
-gzlog.c
-gzlog.h
- efficiently and robustly maintain a message log file in gzip format
- - illustrates use of raw deflate, Z_PARTIAL_FLUSH, deflatePrime(),
- and deflateSetDictionary()
- - illustrates use of a gzip header extra field
-
-zlib_how.html
- painfully comprehensive description of zpipe.c (see below)
- - describes in excruciating detail the use of deflate() and inflate()
-
-zpipe.c
- reads and writes zlib streams from stdin to stdout
- - illustrates the proper use of deflate() and inflate()
- - deeply commented in zlib_how.html (see above)
-
-zran.c
- index a zlib or gzip stream and randomly access it
- - illustrates the use of Z_BLOCK, inflatePrime(), and
- inflateSetDictionary() to provide random access
diff --git a/cpukit/zlib/examples/fitblk.c b/cpukit/zlib/examples/fitblk.c
deleted file mode 100644
index c61de5c996..0000000000
--- a/cpukit/zlib/examples/fitblk.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/* fitblk.c: example of fitting compressed output to a specified size
- Not copyrighted -- provided to the public domain
- Version 1.1 25 November 2004 Mark Adler */
-
-/* Version history:
- 1.0 24 Nov 2004 First version
- 1.1 25 Nov 2004 Change deflateInit2() to deflateInit()
- Use fixed-size, stack-allocated raw buffers
- Simplify code moving compression to subroutines
- Use assert() for internal errors
- Add detailed description of approach
- */
-
-/* Approach to just fitting a requested compressed size:
-
- fitblk performs three compression passes on a portion of the input
- data in order to determine how much of that input will compress to
- nearly the requested output block size. The first pass generates
- enough deflate blocks to produce output to fill the requested
- output size plus a specfied excess amount (see the EXCESS define
- below). The last deflate block may go quite a bit past that, but
- is discarded. The second pass decompresses and recompresses just
- the compressed data that fit in the requested plus excess sized
- buffer. The deflate process is terminated after that amount of
- input, which is less than the amount consumed on the first pass.
- The last deflate block of the result will be of a comparable size
- to the final product, so that the header for that deflate block and
- the compression ratio for that block will be about the same as in
- the final product. The third compression pass decompresses the
- result of the second step, but only the compressed data up to the
- requested size minus an amount to allow the compressed stream to
- complete (see the MARGIN define below). That will result in a
- final compressed stream whose length is less than or equal to the
- requested size. Assuming sufficient input and a requested size
- greater than a few hundred bytes, the shortfall will typically be
- less than ten bytes.
-
- If the input is short enough that the first compression completes
- before filling the requested output size, then that compressed
- stream is return with no recompression.
-
- EXCESS is chosen to be just greater than the shortfall seen in a
- two pass approach similar to the above. That shortfall is due to
- the last deflate block compressing more efficiently with a smaller
- header on the second pass. EXCESS is set to be large enough so
- that there is enough uncompressed data for the second pass to fill
- out the requested size, and small enough so that the final deflate
- block of the second pass will be close in size to the final deflate
- block of the third and final pass. MARGIN is chosen to be just
- large enough to assure that the final compression has enough room
- to complete in all cases.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include "zlib.h"
-
-#define local static
-
-/* print nastygram and leave */
-local void quit(char *why)
-{
- fprintf(stderr, "fitblk abort: %s\n", why);
- exit(1);
-}
-
-#define RAWLEN 4096 /* intermediate uncompressed buffer size */
-
-/* compress from file to def until provided buffer is full or end of
- input reached; return last deflate() return value, or Z_ERRNO if
- there was read error on the file */
-local int partcompress(FILE *in, z_streamp def)
-{
- int ret, flush;
- unsigned char raw[RAWLEN];
-
- flush = Z_NO_FLUSH;
- do {
- def->avail_in = fread(raw, 1, RAWLEN, in);
- if (ferror(in))
- return Z_ERRNO;
- def->next_in = raw;
- if (feof(in))
- flush = Z_FINISH;
- ret = deflate(def, flush);
- assert(ret != Z_STREAM_ERROR);
- } while (def->avail_out != 0 && flush == Z_NO_FLUSH);
- return ret;
-}
-
-/* recompress from inf's input to def's output; the input for inf and
- the output for def are set in those structures before calling;
- return last deflate() return value, or Z_MEM_ERROR if inflate()
- was not able to allocate enough memory when it needed to */
-local int recompress(z_streamp inf, z_streamp def)
-{
- int ret, flush;
- unsigned char raw[RAWLEN];
-
- flush = Z_NO_FLUSH;
- do {
- /* decompress */
- inf->avail_out = RAWLEN;
- inf->next_out = raw;
- ret = inflate(inf, Z_NO_FLUSH);
- assert(ret != Z_STREAM_ERROR && ret != Z_DATA_ERROR &&
- ret != Z_NEED_DICT);
- if (ret == Z_MEM_ERROR)
- return ret;
-
- /* compress what was decompresed until done or no room */
- def->avail_in = RAWLEN - inf->avail_out;
- def->next_in = raw;
- if (inf->avail_out != 0)
- flush = Z_FINISH;
- ret = deflate(def, flush);
- assert(ret != Z_STREAM_ERROR);
- } while (ret != Z_STREAM_END && def->avail_out != 0);
- return ret;
-}
-
-#define EXCESS 256 /* empirically determined stream overage */
-#define MARGIN 8 /* amount to back off for completion */
-
-/* compress from stdin to fixed-size block on stdout */
-int main(int argc, char **argv)
-{
- int ret; /* return code */
- unsigned size; /* requested fixed output block size */
- unsigned have; /* bytes written by deflate() call */
- unsigned char *blk; /* intermediate and final stream */
- unsigned char *tmp; /* close to desired size stream */
- z_stream def, inf; /* zlib deflate and inflate states */
-
- /* get requested output size */
- if (argc != 2)
- quit("need one argument: size of output block");
- ret = strtol(argv[1], argv + 1, 10);
- if (argv[1][0] != 0)
- quit("argument must be a number");
- if (ret < 8) /* 8 is minimum zlib stream size */
- quit("need positive size of 8 or greater");
- size = (unsigned)ret;
-
- /* allocate memory for buffers and compression engine */
- blk = malloc(size + EXCESS);
- def.zalloc = Z_NULL;
- def.zfree = Z_NULL;
- def.opaque = Z_NULL;
- ret = deflateInit(&def, Z_DEFAULT_COMPRESSION);
- if (ret != Z_OK || blk == NULL)
- quit("out of memory");
-
- /* compress from stdin until output full, or no more input */
- def.avail_out = size + EXCESS;
- def.next_out = blk;
- ret = partcompress(stdin, &def);
- if (ret == Z_ERRNO)
- quit("error reading input");
-
- /* if it all fit, then size was undersubscribed -- done! */
- if (ret == Z_STREAM_END && def.avail_out >= EXCESS) {
- /* write block to stdout */
- have = size + EXCESS - def.avail_out;
- if (fwrite(blk, 1, have, stdout) != have || ferror(stdout))
- quit("error writing output");
-
- /* clean up and print results to stderr */
- ret = deflateEnd(&def);
- assert(ret != Z_STREAM_ERROR);
- free(blk);
- fprintf(stderr,
- "%u bytes unused out of %u requested (all input)\n",
- size - have, size);
- return 0;
- }
-
- /* it didn't all fit -- set up for recompression */
- inf.zalloc = Z_NULL;
- inf.zfree = Z_NULL;
- inf.opaque = Z_NULL;
- inf.avail_in = 0;
- inf.next_in = Z_NULL;
- ret = inflateInit(&inf);
- tmp = malloc(size + EXCESS);
- if (ret != Z_OK || tmp == NULL)
- quit("out of memory");
- ret = deflateReset(&def);
- assert(ret != Z_STREAM_ERROR);
-
- /* do first recompression close to the right amount */
- inf.avail_in = size + EXCESS;
- inf.next_in = blk;
- def.avail_out = size + EXCESS;
- def.next_out = tmp;
- ret = recompress(&inf, &def);
- if (ret == Z_MEM_ERROR)
- quit("out of memory");
-
- /* set up for next reocmpression */
- ret = inflateReset(&inf);
- assert(ret != Z_STREAM_ERROR);
- ret = deflateReset(&def);
- assert(ret != Z_STREAM_ERROR);
-
- /* do second and final recompression (third compression) */
- inf.avail_in = size - MARGIN; /* assure stream will complete */
- inf.next_in = tmp;
- def.avail_out = size;
- def.next_out = blk;
- ret = recompress(&inf, &def);
- if (ret == Z_MEM_ERROR)
- quit("out of memory");
- assert(ret == Z_STREAM_END); /* otherwise MARGIN too small */
-
- /* done -- write block to stdout */
- have = size - def.avail_out;
- if (fwrite(blk, 1, have, stdout) != have || ferror(stdout))
- quit("error writing output");
-
- /* clean up and print results to stderr */
- free(tmp);
- ret = inflateEnd(&inf);
- assert(ret != Z_STREAM_ERROR);
- ret = deflateEnd(&def);
- assert(ret != Z_STREAM_ERROR);
- free(blk);
- fprintf(stderr,
- "%u bytes unused out of %u requested (%lu input)\n",
- size - have, size, def.total_in);
- return 0;
-}
diff --git a/cpukit/zlib/examples/gzappend.c b/cpukit/zlib/examples/gzappend.c
deleted file mode 100644
index e9e878e116..0000000000
--- a/cpukit/zlib/examples/gzappend.c
+++ /dev/null
@@ -1,500 +0,0 @@
-/* gzappend -- command to append to a gzip file
-
- Copyright (C) 2003 Mark Adler, all rights reserved
- version 1.1, 4 Nov 2003
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Mark Adler madler@alumni.caltech.edu
- */
-
-/*
- * Change history:
- *
- * 1.0 19 Oct 2003 - First version
- * 1.1 4 Nov 2003 - Expand and clarify some comments and notes
- * - Add version and copyright to help
- * - Send help to stdout instead of stderr
- * - Add some preemptive typecasts
- * - Add L to constants in lseek() calls
- * - Remove some debugging information in error messages
- * - Use new data_type definition for zlib 1.2.1
- * - Simplfy and unify file operations
- * - Finish off gzip file in gztack()
- * - Use deflatePrime() instead of adding empty blocks
- * - Keep gzip file clean on appended file read errors
- * - Use in-place rotate instead of auxiliary buffer
- * (Why you ask? Because it was fun to write!)
- */
-
-/*
- gzappend takes a gzip file and appends to it, compressing files from the
- command line or data from stdin. The gzip file is written to directly, to
- avoid copying that file, in case it's large. Note that this results in the
- unfriendly behavior that if gzappend fails, the gzip file is corrupted.
-
- This program was written to illustrate the use of the new Z_BLOCK option of
- zlib 1.2.x's inflate() function. This option returns from inflate() at each
- block boundary to facilitate locating and modifying the last block bit at
- the start of the final deflate block. Also whether using Z_BLOCK or not,
- another required feature of zlib 1.2.x is that inflate() now provides the
- number of unusued bits in the last input byte used. gzappend will not work
- with versions of zlib earlier than 1.2.1.
-
- gzappend first decompresses the gzip file internally, discarding all but
- the last 32K of uncompressed data, and noting the location of the last block
- bit and the number of unused bits in the last byte of the compressed data.
- The gzip trailer containing the CRC-32 and length of the uncompressed data
- is verified. This trailer will be later overwritten.
-
- Then the last block bit is cleared by seeking back in the file and rewriting
- the byte that contains it. Seeking forward, the last byte of the compressed
- data is saved along with the number of unused bits to initialize deflate.
-
- A deflate process is initialized, using the last 32K of the uncompressed
- data from the gzip file to initialize the dictionary. If the total
- uncompressed data was less than 32K, then all of it is used to initialize
- the dictionary. The deflate output bit buffer is also initialized with the
- last bits from the original deflate stream. From here on, the data to
- append is simply compressed using deflate, and written to the gzip file.
- When that is complete, the new CRC-32 and uncompressed length are written
- as the trailer of the gzip file.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include "zlib.h"
-
-#define local static
-#define LGCHUNK 14
-#define CHUNK (1U << LGCHUNK)
-#define DSIZE 32768U
-
-/* print an error message and terminate with extreme prejudice */
-local void bye(char *msg1, char *msg2)
-{
- fprintf(stderr, "gzappend error: %s%s\n", msg1, msg2);
- exit(1);
-}
-
-/* return the greatest common divisor of a and b using Euclid's algorithm,
- modified to be fast when one argument much greater than the other, and
- coded to avoid unnecessary swapping */
-local unsigned gcd(unsigned a, unsigned b)
-{
- unsigned c;
-
- while (a && b)
- if (a > b) {
- c = b;
- while (a - c >= c)
- c <<= 1;
- a -= c;
- }
- else {
- c = a;
- while (b - c >= c)
- c <<= 1;
- b -= c;
- }
- return a + b;
-}
-
-/* rotate list[0..len-1] left by rot positions, in place */
-local void rotate(unsigned char *list, unsigned len, unsigned rot)
-{
- unsigned char tmp;
- unsigned cycles;
- unsigned char *start, *last, *to, *from;
-
- /* normalize rot and handle degenerate cases */
- if (len < 2) return;
- if (rot >= len) rot %= len;
- if (rot == 0) return;
-
- /* pointer to last entry in list */
- last = list + (len - 1);
-
- /* do simple left shift by one */
- if (rot == 1) {
- tmp = *list;
- memcpy(list, list + 1, len - 1);
- *last = tmp;
- return;
- }
-
- /* do simple right shift by one */
- if (rot == len - 1) {
- tmp = *last;
- memmove(list + 1, list, len - 1);
- *list = tmp;
- return;
- }
-
- /* otherwise do rotate as a set of cycles in place */
- cycles = gcd(len, rot); /* number of cycles */
- do {
- start = from = list + cycles; /* start index is arbitrary */
- tmp = *from; /* save entry to be overwritten */
- for (;;) {
- to = from; /* next step in cycle */
- from += rot; /* go right rot positions */
- if (from > last) from -= len; /* (pointer better not wrap) */
- if (from == start) break; /* all but one shifted */
- *to = *from; /* shift left */
- }
- *to = tmp; /* complete the circle */
- } while (--cycles);
-}
-
-/* structure for gzip file read operations */
-typedef struct {
- int fd; /* file descriptor */
- int size; /* 1 << size is bytes in buf */
- unsigned left; /* bytes available at next */
- unsigned char *buf; /* buffer */
- unsigned char *next; /* next byte in buffer */
- char *name; /* file name for error messages */
-} file;
-
-/* reload buffer */
-local int readin(file *in)
-{
- int len;
-
- len = read(in->fd, in->buf, 1 << in->size);
- if (len == -1) bye("error reading ", in->name);
- in->left = (unsigned)len;
- in->next = in->buf;
- return len;
-}
-
-/* read from file in, exit if end-of-file */
-local int readmore(file *in)
-{
- if (readin(in) == 0) bye("unexpected end of ", in->name);
- return 0;
-}
-
-#define read1(in) (in->left == 0 ? readmore(in) : 0, \
- in->left--, *(in->next)++)
-
-/* skip over n bytes of in */
-local void skip(file *in, unsigned n)
-{
- unsigned bypass;
-
- if (n > in->left) {
- n -= in->left;
- bypass = n & ~((1U << in->size) - 1);
- if (bypass) {
- if (lseek(in->fd, (off_t)bypass, SEEK_CUR) == -1)
- bye("seeking ", in->name);
- n -= bypass;
- }
- readmore(in);
- if (n > in->left)
- bye("unexpected end of ", in->name);
- }
- in->left -= n;
- in->next += n;
-}
-
-/* read a four-byte unsigned integer, little-endian, from in */
-unsigned long read4(file *in)
-{
- unsigned long val;
-
- val = read1(in);
- val += (unsigned)read1(in) << 8;
- val += (unsigned long)read1(in) << 16;
- val += (unsigned long)read1(in) << 24;
- return val;
-}
-
-/* skip over gzip header */
-local void gzheader(file *in)
-{
- int flags;
- unsigned n;
-
- if (read1(in) != 31 || read1(in) != 139) bye(in->name, " not a gzip file");
- if (read1(in) != 8) bye("unknown compression method in", in->name);
- flags = read1(in);
- if (flags & 0xe0) bye("unknown header flags set in", in->name);
- skip(in, 6);
- if (flags & 4) {
- n = read1(in);
- n += (unsigned)(read1(in)) << 8;
- skip(in, n);
- }
- if (flags & 8) while (read1(in) != 0) ;
- if (flags & 16) while (read1(in) != 0) ;
- if (flags & 2) skip(in, 2);
-}
-
-/* decompress gzip file "name", return strm with a deflate stream ready to
- continue compression of the data in the gzip file, and return a file
- descriptor pointing to where to write the compressed data -- the deflate
- stream is initialized to compress using level "level" */
-local int gzscan(char *name, z_stream *strm, int level)
-{
- int ret, lastbit, left, full;
- unsigned have;
- unsigned long crc, tot;
- unsigned char *window;
- off_t lastoff, end;
- file gz;
-
- /* open gzip file */
- gz.name = name;
- gz.fd = open(name, O_RDWR, 0);
- if (gz.fd == -1) bye("cannot open ", name);
- gz.buf = malloc(CHUNK);
- if (gz.buf == NULL) bye("out of memory", "");
- gz.size = LGCHUNK;
- gz.left = 0;
-
- /* skip gzip header */
- gzheader(&gz);
-
- /* prepare to decompress */
- window = malloc(DSIZE);
- if (window == NULL) bye("out of memory", "");
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
- strm->opaque = Z_NULL;
- ret = inflateInit2(strm, -15);
- if (ret != Z_OK) bye("out of memory", " or library mismatch");
-
- /* decompress the deflate stream, saving append information */
- lastbit = 0;
- lastoff = lseek(gz.fd, 0L, SEEK_CUR) - gz.left;
- left = 0;
- strm->avail_in = gz.left;
- strm->next_in = gz.next;
- crc = crc32(0L, Z_NULL, 0);
- have = full = 0;
- do {
- /* if needed, get more input */
- if (strm->avail_in == 0) {
- readmore(&gz);
- strm->avail_in = gz.left;
- strm->next_in = gz.next;
- }
-
- /* set up output to next available section of sliding window */
- strm->avail_out = DSIZE - have;
- strm->next_out = window + have;
-
- /* inflate and check for errors */
- ret = inflate(strm, Z_BLOCK);
- if (ret == Z_STREAM_ERROR) bye("internal stream error!", "");
- if (ret == Z_MEM_ERROR) bye("out of memory", "");
- if (ret == Z_DATA_ERROR)
- bye("invalid compressed data--format violated in", name);
-
- /* update crc and sliding window pointer */
- crc = crc32(crc, window + have, DSIZE - have - strm->avail_out);
- if (strm->avail_out)
- have = DSIZE - strm->avail_out;
- else {
- have = 0;
- full = 1;
- }
-
- /* process end of block */
- if (strm->data_type & 128) {
- if (strm->data_type & 64)
- left = strm->data_type & 0x1f;
- else {
- lastbit = strm->data_type & 0x1f;
- lastoff = lseek(gz.fd, 0L, SEEK_CUR) - strm->avail_in;
- }
- }
- } while (ret != Z_STREAM_END);
- inflateEnd(strm);
- gz.left = strm->avail_in;
- gz.next = strm->next_in;
-
- /* save the location of the end of the compressed data */
- end = lseek(gz.fd, 0L, SEEK_CUR) - gz.left;
-
- /* check gzip trailer and save total for deflate */
- if (crc != read4(&gz))
- bye("invalid compressed data--crc mismatch in ", name);
- tot = strm->total_out;
- if ((tot & 0xffffffffUL) != read4(&gz))
- bye("invalid compressed data--length mismatch in", name);
-
- /* if not at end of file, warn */
- if (gz.left || readin(&gz))
- fprintf(stderr,
- "gzappend warning: junk at end of gzip file overwritten\n");
-
- /* clear last block bit */
- lseek(gz.fd, lastoff - (lastbit != 0), SEEK_SET);
- if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name);
- *gz.buf = (unsigned char)(*gz.buf ^ (1 << ((8 - lastbit) & 7)));
- lseek(gz.fd, -1L, SEEK_CUR);
- if (write(gz.fd, gz.buf, 1) != 1) bye("writing after seek to ", name);
-
- /* if window wrapped, build dictionary from window by rotating */
- if (full) {
- rotate(window, DSIZE, have);
- have = DSIZE;
- }
-
- /* set up deflate stream with window, crc, total_in, and leftover bits */
- ret = deflateInit2(strm, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
- if (ret != Z_OK) bye("out of memory", "");
- deflateSetDictionary(strm, window, have);
- strm->adler = crc;
- strm->total_in = tot;
- if (left) {
- lseek(gz.fd, --end, SEEK_SET);
- if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name);
- deflatePrime(strm, 8 - left, *gz.buf);
- }
- lseek(gz.fd, end, SEEK_SET);
-
- /* clean up and return */
- free(window);
- free(gz.buf);
- return gz.fd;
-}
-
-/* append file "name" to gzip file gd using deflate stream strm -- if last
- is true, then finish off the deflate stream at the end */
-local void gztack(char *name, int gd, z_stream *strm, int last)
-{
- int fd, len, ret;
- unsigned left;
- unsigned char *in, *out;
-
- /* open file to compress and append */
- fd = 0;
- if (name != NULL) {
- fd = open(name, O_RDONLY, 0);
- if (fd == -1)
- fprintf(stderr, "gzappend warning: %s not found, skipping ...\n",
- name);
- }
-
- /* allocate buffers */
- in = fd == -1 ? NULL : malloc(CHUNK);
- out = malloc(CHUNK);
- if (out == NULL) bye("out of memory", "");
-
- /* compress input file and append to gzip file */
- do {
- /* get more input */
- len = fd == -1 ? 0 : read(fd, in, CHUNK);
- if (len == -1) {
- fprintf(stderr,
- "gzappend warning: error reading %s, skipping rest ...\n",
- name);
- len = 0;
- }
- strm->avail_in = (unsigned)len;
- strm->next_in = in;
- if (len) strm->adler = crc32(strm->adler, in, (unsigned)len);
-
- /* compress and write all available output */
- do {
- strm->avail_out = CHUNK;
- strm->next_out = out;
- ret = deflate(strm, last && len == 0 ? Z_FINISH : Z_NO_FLUSH);
- left = CHUNK - strm->avail_out;
- while (left) {
- len = write(gd, out + CHUNK - strm->avail_out - left, left);
- if (len == -1) bye("writing gzip file", "");
- left -= (unsigned)len;
- }
- } while (strm->avail_out == 0 && ret != Z_STREAM_END);
- } while (len != 0);
-
- /* write trailer after last entry */
- if (last) {
- deflateEnd(strm);
- out[0] = (unsigned char)(strm->adler);
- out[1] = (unsigned char)(strm->adler >> 8);
- out[2] = (unsigned char)(strm->adler >> 16);
- out[3] = (unsigned char)(strm->adler >> 24);
- out[4] = (unsigned char)(strm->total_in);
- out[5] = (unsigned char)(strm->total_in >> 8);
- out[6] = (unsigned char)(strm->total_in >> 16);
- out[7] = (unsigned char)(strm->total_in >> 24);
- len = 8;
- do {
- ret = write(gd, out + 8 - len, len);
- if (ret == -1) bye("writing gzip file", "");
- len -= ret;
- } while (len);
- close(gd);
- }
-
- /* clean up and return */
- free(out);
- if (in != NULL) free(in);
- if (fd > 0) close(fd);
-}
-
-/* process the compression level option if present, scan the gzip file, and
- append the specified files, or append the data from stdin if no other file
- names are provided on the command line -- the gzip file must be writable
- and seekable */
-int main(int argc, char **argv)
-{
- int gd, level;
- z_stream strm;
-
- /* ignore command name */
- argv++;
-
- /* provide usage if no arguments */
- if (*argv == NULL) {
- printf("gzappend 1.1 (4 Nov 2003) Copyright (C) 2003 Mark Adler\n");
- printf(
- "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n");
- return 0;
- }
-
- /* set compression level */
- level = Z_DEFAULT_COMPRESSION;
- if (argv[0][0] == '-') {
- if (argv[0][1] < '0' || argv[0][1] > '9' || argv[0][2] != 0)
- bye("invalid compression level", "");
- level = argv[0][1] - '0';
- if (*++argv == NULL) bye("no gzip file name after options", "");
- }
-
- /* prepare to append to gzip file */
- gd = gzscan(*argv++, &strm, level);
-
- /* append files on command line, or from stdin if none */
- if (*argv == NULL)
- gztack(NULL, gd, &strm, 1);
- else
- do {
- gztack(*argv, gd, &strm, argv[1] == NULL);
- } while (*++argv != NULL);
- return 0;
-}
diff --git a/cpukit/zlib/examples/gzjoin.c b/cpukit/zlib/examples/gzjoin.c
deleted file mode 100644
index 129347ce3c..0000000000
--- a/cpukit/zlib/examples/gzjoin.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/* gzjoin -- command to join gzip files into one gzip file
-
- Copyright (C) 2004 Mark Adler, all rights reserved
- version 1.0, 11 Dec 2004
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Mark Adler madler@alumni.caltech.edu
- */
-
-/*
- * Change history:
- *
- * 1.0 11 Dec 2004 - First version
- * 1.1 12 Jun 2005 - Changed ssize_t to long for portability
- */
-
-/*
- gzjoin takes one or more gzip files on the command line and writes out a
- single gzip file that will uncompress to the concatenation of the
- uncompressed data from the individual gzip files. gzjoin does this without
- having to recompress any of the data and without having to calculate a new
- crc32 for the concatenated uncompressed data. gzjoin does however have to
- decompress all of the input data in order to find the bits in the compressed
- data that need to be modified to concatenate the streams.
-
- gzjoin does not do an integrity check on the input gzip files other than
- checking the gzip header and decompressing the compressed data. They are
- otherwise assumed to be complete and correct.
-
- Each joint between gzip files removes at least 18 bytes of previous trailer
- and subsequent header, and inserts an average of about three bytes to the
- compressed data in order to connect the streams. The output gzip file
- has a minimal ten-byte gzip header with no file name or modification time.
-
- This program was written to illustrate the use of the Z_BLOCK option of
- inflate() and the crc32_combine() function. gzjoin will not compile with
- versions of zlib earlier than 1.2.3.
- */
-
-#include <stdio.h> /* fputs(), fprintf(), fwrite(), putc() */
-#include <stdlib.h> /* exit(), malloc(), free() */
-#include <fcntl.h> /* open() */
-#include <unistd.h> /* close(), read(), lseek() */
-#include "zlib.h"
- /* crc32(), crc32_combine(), inflateInit2(), inflate(), inflateEnd() */
-
-#define local static
-
-/* exit with an error (return a value to allow use in an expression) */
-local int bail(char *why1, char *why2)
-{
- fprintf(stderr, "gzjoin error: %s%s, output incomplete\n", why1, why2);
- exit(1);
- return 0;
-}
-
-/* -- simple buffered file input with access to the buffer -- */
-
-#define CHUNK 32768 /* must be a power of two and fit in unsigned */
-
-/* bin buffered input file type */
-typedef struct {
- char *name; /* name of file for error messages */
- int fd; /* file descriptor */
- unsigned left; /* bytes remaining at next */
- unsigned char *next; /* next byte to read */
- unsigned char *buf; /* allocated buffer of length CHUNK */
-} bin;
-
-/* close a buffered file and free allocated memory */
-local void bclose(bin *in)
-{
- if (in != NULL) {
- if (in->fd != -1)
- close(in->fd);
- if (in->buf != NULL)
- free(in->buf);
- free(in);
- }
-}
-
-/* open a buffered file for input, return a pointer to type bin, or NULL on
- failure */
-local bin *bopen(char *name)
-{
- bin *in;
-
- in = malloc(sizeof(bin));
- if (in == NULL)
- return NULL;
- in->buf = malloc(CHUNK);
- in->fd = open(name, O_RDONLY, 0);
- if (in->buf == NULL || in->fd == -1) {
- bclose(in);
- return NULL;
- }
- in->left = 0;
- in->next = in->buf;
- in->name = name;
- return in;
-}
-
-/* load buffer from file, return -1 on read error, 0 or 1 on success, with
- 1 indicating that end-of-file was reached */
-local int bload(bin *in)
-{
- long len;
-
- if (in == NULL)
- return -1;
- if (in->left != 0)
- return 0;
- in->next = in->buf;
- do {
- len = (long)read(in->fd, in->buf + in->left, CHUNK - in->left);
- if (len < 0)
- return -1;
- in->left += (unsigned)len;
- } while (len != 0 && in->left < CHUNK);
- return len == 0 ? 1 : 0;
-}
-
-/* get a byte from the file, bail if end of file */
-#define bget(in) (in->left ? 0 : bload(in), \
- in->left ? (in->left--, *(in->next)++) : \
- bail("unexpected end of file on ", in->name))
-
-/* get a four-byte little-endian unsigned integer from file */
-local unsigned long bget4(bin *in)
-{
- unsigned long val;
-
- val = bget(in);
- val += (unsigned long)(bget(in)) << 8;
- val += (unsigned long)(bget(in)) << 16;
- val += (unsigned long)(bget(in)) << 24;
- return val;
-}
-
-/* skip bytes in file */
-local void bskip(bin *in, unsigned skip)
-{
- /* check pointer */
- if (in == NULL)
- return;
-
- /* easy case -- skip bytes in buffer */
- if (skip <= in->left) {
- in->left -= skip;
- in->next += skip;
- return;
- }
-
- /* skip what's in buffer, discard buffer contents */
- skip -= in->left;
- in->left = 0;
-
- /* seek past multiples of CHUNK bytes */
- if (skip > CHUNK) {
- unsigned left;
-
- left = skip & (CHUNK - 1);
- if (left == 0) {
- /* exact number of chunks: seek all the way minus one byte to check
- for end-of-file with a read */
- lseek(in->fd, skip - 1, SEEK_CUR);
- if (read(in->fd, in->buf, 1) != 1)
- bail("unexpected end of file on ", in->name);
- return;
- }
-
- /* skip the integral chunks, update skip with remainder */
- lseek(in->fd, skip - left, SEEK_CUR);
- skip = left;
- }
-
- /* read more input and skip remainder */
- bload(in);
- if (skip > in->left)
- bail("unexpected end of file on ", in->name);
- in->left -= skip;
- in->next += skip;
-}
-
-/* -- end of buffered input functions -- */
-
-/* skip the gzip header from file in */
-local void gzhead(bin *in)
-{
- int flags;
-
- /* verify gzip magic header and compression method */
- if (bget(in) != 0x1f || bget(in) != 0x8b || bget(in) != 8)
- bail(in->name, " is not a valid gzip file");
-
- /* get and verify flags */
- flags = bget(in);
- if ((flags & 0xe0) != 0)
- bail("unknown reserved bits set in ", in->name);
-
- /* skip modification time, extra flags, and os */
- bskip(in, 6);
-
- /* skip extra field if present */
- if (flags & 4) {
- unsigned len;
-
- len = bget(in);
- len += (unsigned)(bget(in)) << 8;
- bskip(in, len);
- }
-
- /* skip file name if present */
- if (flags & 8)
- while (bget(in) != 0)
- ;
-
- /* skip comment if present */
- if (flags & 16)
- while (bget(in) != 0)
- ;
-
- /* skip header crc if present */
- if (flags & 2)
- bskip(in, 2);
-}
-
-/* write a four-byte little-endian unsigned integer to out */
-local void put4(unsigned long val, FILE *out)
-{
- putc(val & 0xff, out);
- putc((val >> 8) & 0xff, out);
- putc((val >> 16) & 0xff, out);
- putc((val >> 24) & 0xff, out);
-}
-
-/* Load up zlib stream from buffered input, bail if end of file */
-local void zpull(z_streamp strm, bin *in)
-{
- if (in->left == 0)
- bload(in);
- if (in->left == 0)
- bail("unexpected end of file on ", in->name);
- strm->avail_in = in->left;
- strm->next_in = in->next;
-}
-
-/* Write header for gzip file to out and initialize trailer. */
-local void gzinit(unsigned long *crc, unsigned long *tot, FILE *out)
-{
- fwrite("\x1f\x8b\x08\0\0\0\0\0\0\xff", 1, 10, out);
- *crc = crc32(0L, Z_NULL, 0);
- *tot = 0;
-}
-
-/* Copy the compressed data from name, zeroing the last block bit of the last
- block if clr is true, and adding empty blocks as needed to get to a byte
- boundary. If clr is false, then the last block becomes the last block of
- the output, and the gzip trailer is written. crc and tot maintains the
- crc and length (modulo 2^32) of the output for the trailer. The resulting
- gzip file is written to out. gzinit() must be called before the first call
- of gzcopy() to write the gzip header and to initialize crc and tot. */
-local void gzcopy(char *name, int clr, unsigned long *crc, unsigned long *tot,
- FILE *out)
-{
- int ret; /* return value from zlib functions */
- int pos; /* where the "last block" bit is in byte */
- int last; /* true if processing the last block */
- bin *in; /* buffered input file */
- unsigned char *start; /* start of compressed data in buffer */
- unsigned char *junk; /* buffer for uncompressed data -- discarded */
- z_off_t len; /* length of uncompressed data (support > 4 GB) */
- z_stream strm; /* zlib inflate stream */
-
- /* open gzip file and skip header */
- in = bopen(name);
- if (in == NULL)
- bail("could not open ", name);
- gzhead(in);
-
- /* allocate buffer for uncompressed data and initialize raw inflate
- stream */
- junk = malloc(CHUNK);
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit2(&strm, -15);
- if (junk == NULL || ret != Z_OK)
- bail("out of memory", "");
-
- /* inflate and copy compressed data, clear last-block bit if requested */
- len = 0;
- zpull(&strm, in);
- start = strm.next_in;
- last = start[0] & 1;
- if (last && clr)
- start[0] &= ~1;
- strm.avail_out = 0;
- for (;;) {
- /* if input used and output done, write used input and get more */
- if (strm.avail_in == 0 && strm.avail_out != 0) {
- fwrite(start, 1, strm.next_in - start, out);
- start = in->buf;
- in->left = 0;
- zpull(&strm, in);
- }
-
- /* decompress -- return early when end-of-block reached */
- strm.avail_out = CHUNK;
- strm.next_out = junk;
- ret = inflate(&strm, Z_BLOCK);
- switch (ret) {
- case Z_MEM_ERROR:
- bail("out of memory", "");
- case Z_DATA_ERROR:
- bail("invalid compressed data in ", in->name);
- }
-
- /* update length of uncompressed data */
- len += CHUNK - strm.avail_out;
-
- /* check for block boundary (only get this when block copied out) */
- if (strm.data_type & 128) {
- /* if that was the last block, then done */
- if (last)
- break;
-
- /* number of unused bits in last byte */
- pos = strm.data_type & 7;
-
- /* find the next last-block bit */
- if (pos != 0) {
- /* next last-block bit is in last used byte */
- pos = 0x100 >> pos;
- last = strm.next_in[-1] & pos;
- if (last && clr)
- strm.next_in[-1] &= ~pos;
- }
- else {
- /* next last-block bit is in next unused byte */
- if (strm.avail_in == 0) {
- /* don't have that byte yet -- get it */
- fwrite(start, 1, strm.next_in - start, out);
- start = in->buf;
- in->left = 0;
- zpull(&strm, in);
- }
- last = strm.next_in[0] & 1;
- if (last && clr)
- strm.next_in[0] &= ~1;
- }
- }
- }
-
- /* update buffer with unused input */
- in->left = strm.avail_in;
- in->next = strm.next_in;
-
- /* copy used input, write empty blocks to get to byte boundary */
- pos = strm.data_type & 7;
- fwrite(start, 1, in->next - start - 1, out);
- last = in->next[-1];
- if (pos == 0 || !clr)
- /* already at byte boundary, or last file: write last byte */
- putc(last, out);
- else {
- /* append empty blocks to last byte */
- last &= ((0x100 >> pos) - 1); /* assure unused bits are zero */
- if (pos & 1) {
- /* odd -- append an empty stored block */
- putc(last, out);
- if (pos == 1)
- putc(0, out); /* two more bits in block header */
- fwrite("\0\0\xff\xff", 1, 4, out);
- }
- else {
- /* even -- append 1, 2, or 3 empty fixed blocks */
- switch (pos) {
- case 6:
- putc(last | 8, out);
- last = 0;
- case 4:
- putc(last | 0x20, out);
- last = 0;
- case 2:
- putc(last | 0x80, out);
- putc(0, out);
- }
- }
- }
-
- /* update crc and tot */
- *crc = crc32_combine(*crc, bget4(in), len);
- *tot += (unsigned long)len;
-
- /* clean up */
- inflateEnd(&strm);
- free(junk);
- bclose(in);
-
- /* write trailer if this is the last gzip file */
- if (!clr) {
- put4(*crc, out);
- put4(*tot, out);
- }
-}
-
-/* join the gzip files on the command line, write result to stdout */
-int main(int argc, char **argv)
-{
- unsigned long crc, tot; /* running crc and total uncompressed length */
-
- /* skip command name */
- argc--;
- argv++;
-
- /* show usage if no arguments */
- if (argc == 0) {
- fputs("gzjoin usage: gzjoin f1.gz [f2.gz [f3.gz ...]] > fjoin.gz\n",
- stderr);
- return 0;
- }
-
- /* join gzip files on command line and write to stdout */
- gzinit(&crc, &tot, stdout);
- while (argc--)
- gzcopy(*argv++, argc, &crc, &tot, stdout);
-
- /* done */
- return 0;
-}
diff --git a/cpukit/zlib/examples/gzlog.c b/cpukit/zlib/examples/gzlog.c
deleted file mode 100644
index d70aacabae..0000000000
--- a/cpukit/zlib/examples/gzlog.c
+++ /dev/null
@@ -1,1058 +0,0 @@
-/*
- * gzlog.c
- * Copyright (C) 2004, 2008 Mark Adler, all rights reserved
- * For conditions of distribution and use, see copyright notice in gzlog.h
- * version 2.0, 25 Apr 2008
- */
-
-/*
- gzlog provides a mechanism for frequently appending short strings to a gzip
- file that is efficient both in execution time and compression ratio. The
- strategy is to write the short strings in an uncompressed form to the end of
- the gzip file, only compressing when the amount of uncompressed data has
- reached a given threshold.
-
- gzlog also provides protection against interruptions in the process due to
- system crashes. The status of the operation is recorded in an extra field
- in the gzip file, and is only updated once the gzip file is brought to a
- valid state. The last data to be appended or compressed is saved in an
- auxiliary file, so that if the operation is interrupted, it can be completed
- the next time an append operation is attempted.
-
- gzlog maintains another auxiliary file with the last 32K of data from the
- compressed portion, which is preloaded for the compression of the subsequent
- data. This minimizes the impact to the compression ratio of appending.
- */
-
-/*
- Operations Concept:
-
- Files (log name "foo"):
- foo.gz -- gzip file with the complete log
- foo.add -- last message to append or last data to compress
- foo.dict -- dictionary of the last 32K of data for next compression
- foo.temp -- temporary dictionary file for compression after this one
- foo.lock -- lock file for reading and writing the other files
- foo.repairs -- log file for log file recovery operations (not compressed)
-
- gzip file structure:
- - fixed-length (no file name) header with extra field (see below)
- - compressed data ending initially with empty stored block
- - uncompressed data filling out originally empty stored block and
- subsequent stored blocks as needed (16K max each)
- - gzip trailer
- - no junk at end (no other gzip streams)
-
- When appending data, the information in the first three items above plus the
- foo.add file are sufficient to recover an interrupted append operation. The
- extra field has the necessary information to restore the start of the last
- stored block and determine where to append the data in the foo.add file, as
- well as the crc and length of the gzip data before the append operation.
-
- The foo.add file is created before the gzip file is marked for append, and
- deleted after the gzip file is marked as complete. So if the append
- operation is interrupted, the data to add will still be there. If due to
- some external force, the foo.add file gets deleted between when the append
- operation was interrupted and when recovery is attempted, the gzip file will
- still be restored, but without the appended data.
-
- When compressing data, the information in the first two items above plus the
- foo.add file are sufficient to recover an interrupted compress operation.
- The extra field has the necessary information to find the end of the
- compressed data, and contains both the crc and length of just the compressed
- data and of the complete set of data including the contents of the foo.add
- file.
-
- Again, the foo.add file is maintained during the compress operation in case
- of an interruption. If in the unlikely event the foo.add file with the data
- to be compressed is missing due to some external force, a gzip file with
- just the previous compressed data will be reconstructed. In this case, all
- of the data that was to be compressed is lost (approximately one megabyte).
- This will not occur if all that happened was an interruption of the compress
- operation.
-
- The third state that is marked is the replacement of the old dictionary with
- the new dictionary after a compress operation. Once compression is
- complete, the gzip file is marked as being in the replace state. This
- completes the gzip file, so an interrupt after being so marked does not
- result in recompression. Then the dictionary file is replaced, and the gzip
- file is marked as completed. This state prevents the possibility of
- restarting compression with the wrong dictionary file.
-
- All three operations are wrapped by a lock/unlock procedure. In order to
- gain exclusive access to the log files, first a foo.lock file must be
- exclusively created. When all operations are complete, the lock is
- released by deleting the foo.lock file. If when attempting to create the
- lock file, it already exists and the modify time of the lock file is more
- than five minutes old (set by the PATIENCE define below), then the old
- lock file is considered stale and deleted, and the exclusive creation of
- the lock file is retried. To assure that there are no false assessments
- of the staleness of the lock file, the operations periodically touch the
- lock file to update the modified date.
-
- Following is the definition of the extra field with all of the information
- required to enable the above append and compress operations and their
- recovery if interrupted. Multi-byte values are stored little endian
- (consistent with the gzip format). File pointers are eight bytes long.
- The crc's and lengths for the gzip trailer are four bytes long. (Note that
- the length at the end of a gzip file is used for error checking only, and
- for large files is actually the length modulo 2^32.) The stored block
- length is two bytes long. The gzip extra field two-byte identification is
- "ap" for append. It is assumed that writing the extra field to the file is
- an "atomic" operation. That is, either all of the extra field is written
- to the file, or none of it is, if the operation is interrupted right at the
- point of updating the extra field. This is a reasonable assumption, since
- the extra field is within the first 52 bytes of the file, which is smaller
- than any expected block size for a mass storage device (usually 512 bytes or
- larger).
-
- Extra field (35 bytes):
- - Pointer to first stored block length -- this points to the two-byte length
- of the first stored block, which is followed by the two-byte, one's
- complement of that length. The stored block length is preceded by the
- three-bit header of the stored block, which is the actual start of the
- stored block in the deflate format. See the bit offset field below.
- - Pointer to the last stored block length. This is the same as above, but
- for the last stored block of the uncompressed data in the gzip file.
- Initially this is the same as the first stored block length pointer.
- When the stored block gets to 16K (see the MAX_STORE define), then a new
- stored block as added, at which point the last stored block length pointer
- is different from the first stored block length pointer. When they are
- different, the first bit of the last stored block header is eight bits, or
- one byte back from the block length.
- - Compressed data crc and length. This is the crc and length of the data
- that is in the compressed portion of the deflate stream. These are used
- only in the event that the foo.add file containing the data to compress is
- lost after a compress operation is interrupted.
- - Total data crc and length. This is the crc and length of all of the data
- stored in the gzip file, compressed and uncompressed. It is used to
- reconstruct the gzip trailer when compressing, as well as when recovering
- interrupted operations.
- - Final stored block length. This is used to quickly find where to append,
- and allows the restoration of the original final stored block state when
- an append operation is interrupted.
- - First stored block start as the number of bits back from the final stored
- block first length byte. This value is in the range of 3..10, and is
- stored as the low three bits of the final byte of the extra field after
- subtracting three (0..7). This allows the last-block bit of the stored
- block header to be updated when a new stored block is added, for the case
- when the first stored block and the last stored block are the same. (When
- they are different, the numbers of bits back is known to be eight.) This
- also allows for new compressed data to be appended to the old compressed
- data in the compress operation, overwriting the previous first stored
- block, or for the compressed data to be terminated and a valid gzip file
- reconstructed on the off chance that a compression operation was
- interrupted and the data to compress in the foo.add file was deleted.
- - The operation in process. This is the next two bits in the last byte (the
- bits under the mask 0x18). The are interpreted as 0: nothing in process,
- 1: append in process, 2: compress in process, 3: replace in process.
- - The top three bits of the last byte in the extra field are reserved and
- are currently set to zero.
-
- Main procedure:
- - Exclusively create the foo.lock file using the O_CREAT and O_EXCL modes of
- the system open() call. If the modify time of an existing lock file is
- more than PATIENCE seconds old, then the lock file is deleted and the
- exclusive create is retried.
- - Load the extra field from the foo.gz file, and see if an operation was in
- progress but not completed. If so, apply the recovery procedure below.
- - Perform the append procedure with the provided data.
- - If the uncompressed data in the foo.gz file is 1MB or more, apply the
- compress procedure.
- - Delete the foo.lock file.
-
- Append procedure:
- - Put what to append in the foo.add file so that the operation can be
- restarted if this procedure is interrupted.
- - Mark the foo.gz extra field with the append operation in progress.
- + Restore the original last-block bit and stored block length of the last
- stored block from the information in the extra field, in case a previous
- append operation was interrupted.
- - Append the provided data to the last stored block, creating new stored
- blocks as needed and updating the stored blocks last-block bits and
- lengths.
- - Update the crc and length with the new data, and write the gzip trailer.
- - Write over the extra field (with a single write operation) with the new
- pointers, lengths, and crc's, and mark the gzip file as not in process.
- Though there is still a foo.add file, it will be ignored since nothing
- is in process. If a foo.add file is leftover from a previously
- completed operation, it is truncated when writing new data to it.
- - Delete the foo.add file.
-
- Compress and replace procedures:
- - Read all of the uncompressed data in the stored blocks in foo.gz and write
- it to foo.add. Also write foo.temp with the last 32K of that data to
- provide a dictionary for the next invocation of this procedure.
- - Rewrite the extra field marking foo.gz with a compression in process.
- * If there is no data provided to compress (due to a missing foo.add file
- when recovering), reconstruct and truncate the foo.gz file to contain
- only the previous compressed data and proceed to the step after the next
- one. Otherwise ...
- - Compress the data with the dictionary in foo.dict, and write to the
- foo.gz file starting at the bit immediately following the last previously
- compressed block. If there is no foo.dict, proceed anyway with the
- compression at slightly reduced efficiency. (For the foo.dict file to be
- missing requires some external failure beyond simply the interruption of
- a compress operation.) During this process, the foo.lock file is
- periodically touched to assure that that file is not considered stale by
- another process before we're done. The deflation is terminated with a
- non-last empty static block (10 bits long), that is then located and
- written over by a last-bit-set empty stored block.
- - Append the crc and length of the data in the gzip file (previously
- calculated during the append operations).
- - Write over the extra field with the updated stored block offsets, bits
- back, crc's, and lengths, and mark foo.gz as in process for a replacement
- of the dictionary.
- @ Delete the foo.add file.
- - Replace foo.dict with foo.temp.
- - Write over the extra field, marking foo.gz as complete.
-
- Recovery procedure:
- - If not a replace recovery, read in the foo.add file, and provide that data
- to the appropriate recovery below. If there is no foo.add file, provide
- a zero data length to the recovery. In that case, the append recovery
- restores the foo.gz to the previous compressed + uncompressed data state.
- For the the compress recovery, a missing foo.add file results in foo.gz
- being restored to the previous compressed-only data state.
- - Append recovery:
- - Pick up append at + step above
- - Compress recovery:
- - Pick up compress at * step above
- - Replace recovery:
- - Pick up compress at @ step above
- - Log the repair with a date stamp in foo.repairs
- */
-
-#include <sys/types.h>
-#include <stdio.h> /* rename, fopen, fprintf, fclose */
-#include <stdlib.h> /* malloc, free */
-#include <string.h> /* strlen, strrchr, strcpy, strncpy, strcmp */
-#include <fcntl.h> /* open */
-#include <unistd.h> /* lseek, read, write, close, unlink, sleep, */
- /* ftruncate, fsync */
-#include <errno.h> /* errno */
-#include <time.h> /* time, ctime */
-#include <sys/stat.h> /* stat */
-#include <sys/time.h> /* utimes */
-#include "zlib.h" /* crc32 */
-
-#include "gzlog.h" /* header for external access */
-
-#define local static
-typedef unsigned int uint;
-typedef unsigned long ulong;
-
-/* Macro for debugging to deterministically force recovery operations */
-#ifdef DEBUG
- #include <setjmp.h> /* longjmp */
- jmp_buf gzlog_jump; /* where to go back to */
- int gzlog_bail = 0; /* which point to bail at (1..8) */
- int gzlog_count = -1; /* number of times through to wait */
-# define BAIL(n) do { if (n == gzlog_bail && gzlog_count-- == 0) \
- longjmp(gzlog_jump, gzlog_bail); } while (0)
-#else
-# define BAIL(n)
-#endif
-
-/* how old the lock file can be in seconds before considering it stale */
-#define PATIENCE 300
-
-/* maximum stored block size in Kbytes -- must be in 1..63 */
-#define MAX_STORE 16
-
-/* number of stored Kbytes to trigger compression (must be >= 32 to allow
- dictionary construction, and <= 204 * MAX_STORE, in order for >> 10 to
- discard the stored block headers contribution of five bytes each) */
-#define TRIGGER 1024
-
-/* size of a deflate dictionary (this cannot be changed) */
-#define DICT 32768U
-
-/* values for the operation (2 bits) */
-#define NO_OP 0
-#define APPEND_OP 1
-#define COMPRESS_OP 2
-#define REPLACE_OP 3
-
-/* macros to extract little-endian integers from an unsigned byte buffer */
-#define PULL2(p) ((p)[0]+((uint)((p)[1])<<8))
-#define PULL4(p) (PULL2(p)+((ulong)PULL2(p+2)<<16))
-#define PULL8(p) (PULL4(p)+((off_t)PULL4(p+4)<<32))
-
-/* macros to store integers into a byte buffer in little-endian order */
-#define PUT2(p,a) do {(p)[0]=a;(p)[1]=(a)>>8;} while(0)
-#define PUT4(p,a) do {PUT2(p,a);PUT2(p+2,a>>16);} while(0)
-#define PUT8(p,a) do {PUT4(p,a);PUT4(p+4,a>>32);} while(0)
-
-/* internal structure for log information */
-#define LOGID "\106\035\172" /* should be three non-zero characters */
-struct log {
- char id[4]; /* contains LOGID to detect inadvertent overwrites */
- int fd; /* file descriptor for .gz file, opened read/write */
- char *path; /* allocated path, e.g. "/var/log/foo" or "foo" */
- char *end; /* end of path, for appending suffices such as ".gz" */
- off_t first; /* offset of first stored block first length byte */
- int back; /* location of first block id in bits back from first */
- uint stored; /* bytes currently in last stored block */
- off_t last; /* offset of last stored block first length byte */
- ulong ccrc; /* crc of compressed data */
- ulong clen; /* length (modulo 2^32) of compressed data */
- ulong tcrc; /* crc of total data */
- ulong tlen; /* length (modulo 2^32) of total data */
- time_t lock; /* last modify time of our lock file */
-};
-
-/* gzip header for gzlog */
-local unsigned char log_gzhead[] = {
- 0x1f, 0x8b, /* magic gzip id */
- 8, /* compression method is deflate */
- 4, /* there is an extra field (no file name) */
- 0, 0, 0, 0, /* no modification time provided */
- 0, 0xff, /* no extra flags, no OS specified */
- 39, 0, 'a', 'p', 35, 0 /* extra field with "ap" subfield */
- /* 35 is EXTRA, 39 is EXTRA + 4 */
-};
-
-#define HEAD sizeof(log_gzhead) /* should be 16 */
-
-/* initial gzip extra field content (52 == HEAD + EXTRA + 1) */
-local unsigned char log_gzext[] = {
- 52, 0, 0, 0, 0, 0, 0, 0, /* offset of first stored block length */
- 52, 0, 0, 0, 0, 0, 0, 0, /* offset of last stored block length */
- 0, 0, 0, 0, 0, 0, 0, 0, /* compressed data crc and length */
- 0, 0, 0, 0, 0, 0, 0, 0, /* total data crc and length */
- 0, 0, /* final stored block data length */
- 5 /* op is NO_OP, last bit 8 bits back */
-};
-
-#define EXTRA sizeof(log_gzext) /* should be 35 */
-
-/* initial gzip data and trailer */
-local unsigned char log_gzbody[] = {
- 1, 0, 0, 0xff, 0xff, /* empty stored block (last) */
- 0, 0, 0, 0, /* crc */
- 0, 0, 0, 0 /* uncompressed length */
-};
-
-#define BODY sizeof(log_gzbody)
-
-/* Exclusively create foo.lock in order to negotiate exclusive access to the
- foo.* files. If the modify time of an existing lock file is greater than
- PATIENCE seconds in the past, then consider the lock file to have been
- abandoned, delete it, and try the exclusive create again. Save the lock
- file modify time for verification of ownership. Return 0 on success, or -1
- on failure, usually due to an access restriction or invalid path. Note that
- if stat() or unlink() fails, it may be due to another process noticing the
- abandoned lock file a smidge sooner and deleting it, so those are not
- flagged as an error. */
-local int log_lock(struct log *log)
-{
- int fd;
- struct stat st;
-
- strcpy(log->end, ".lock");
- while ((fd = open(log->path, O_CREAT | O_EXCL, 0644)) < 0) {
- if (errno != EEXIST)
- return -1;
- if (stat(log->path, &st) == 0 && time(NULL) - st.st_mtime > PATIENCE) {
- unlink(log->path);
- continue;
- }
- sleep(2); /* relinquish the CPU for two seconds while waiting */
- }
- close(fd);
- if (stat(log->path, &st) == 0)
- log->lock = st.st_mtime;
- return 0;
-}
-
-/* Update the modify time of the lock file to now, in order to prevent another
- task from thinking that the lock is stale. Save the lock file modify time
- for verification of ownership. */
-local void log_touch(struct log *log)
-{
- struct stat st;
-
- strcpy(log->end, ".lock");
- utimes(log->path, NULL);
- if (stat(log->path, &st) == 0)
- log->lock = st.st_mtime;
-}
-
-/* Check the log file modify time against what is expected. Return true if
- this is not our lock. If it is our lock, touch it to keep it. */
-local int log_check(struct log *log)
-{
- struct stat st;
-
- strcpy(log->end, ".lock");
- if (stat(log->path, &st) || st.st_mtime != log->lock)
- return 1;
- log_touch(log);
- return 0;
-}
-
-/* Unlock a previously acquired lock, but only if it's ours. */
-local void log_unlock(struct log *log)
-{
- if (log_check(log))
- return;
- strcpy(log->end, ".lock");
- unlink(log->path);
- log->lock = 0;
-}
-
-/* Check the gzip header and read in the extra field, filling in the values in
- the log structure. Return op on success or -1 if the gzip header was not as
- expected. op is the current operation in progress last written to the extra
- field. This assumes that the gzip file has already been opened, with the
- file descriptor log->fd. */
-local int log_head(struct log *log)
-{
- int op;
- unsigned char buf[HEAD + EXTRA];
-
- if (lseek(log->fd, 0, SEEK_SET) < 0 ||
- read(log->fd, buf, HEAD + EXTRA) != HEAD + EXTRA ||
- memcmp(buf, log_gzhead, HEAD)) {
- return -1;
- }
- log->first = PULL8(buf + HEAD);
- log->last = PULL8(buf + HEAD + 8);
- log->ccrc = PULL4(buf + HEAD + 16);
- log->clen = PULL4(buf + HEAD + 20);
- log->tcrc = PULL4(buf + HEAD + 24);
- log->tlen = PULL4(buf + HEAD + 28);
- log->stored = PULL2(buf + HEAD + 32);
- log->back = 3 + (buf[HEAD + 34] & 7);
- op = (buf[HEAD + 34] >> 3) & 3;
- return op;
-}
-
-/* Write over the extra field contents, marking the operation as op. Use fsync
- to assure that the device is written to, and in the requested order. This
- operation, and only this operation, is assumed to be atomic in order to
- assure that the log is recoverable in the event of an interruption at any
- point in the process. Return -1 if the write to foo.gz failed. */
-local int log_mark(struct log *log, int op)
-{
- int ret;
- unsigned char ext[EXTRA];
-
- PUT8(ext, log->first);
- PUT8(ext + 8, log->last);
- PUT4(ext + 16, log->ccrc);
- PUT4(ext + 20, log->clen);
- PUT4(ext + 24, log->tcrc);
- PUT4(ext + 28, log->tlen);
- PUT2(ext + 32, log->stored);
- ext[34] = log->back - 3 + (op << 3);
- fsync(log->fd);
- ret = lseek(log->fd, HEAD, SEEK_SET) < 0 ||
- write(log->fd, ext, EXTRA) != EXTRA ? -1 : 0;
- fsync(log->fd);
- return ret;
-}
-
-/* Rewrite the last block header bits and subsequent zero bits to get to a byte
- boundary, setting the last block bit if last is true, and then write the
- remainder of the stored block header (length and one's complement). Leave
- the file pointer after the end of the last stored block data. Return -1 if
- there is a read or write failure on the foo.gz file */
-local int log_last(struct log *log, int last)
-{
- int back, len, mask;
- unsigned char buf[6];
-
- /* determine the locations of the bytes and bits to modify */
- back = log->last == log->first ? log->back : 8;
- len = back > 8 ? 2 : 1; /* bytes back from log->last */
- mask = 0x80 >> ((back - 1) & 7); /* mask for block last-bit */
-
- /* get the byte to modify (one or two back) into buf[0] -- don't need to
- read the byte if the last-bit is eight bits back, since in that case
- the entire byte will be modified */
- buf[0] = 0;
- if (back != 8 && (lseek(log->fd, log->last - len, SEEK_SET) < 0 ||
- read(log->fd, buf, 1) != 1))
- return -1;
-
- /* change the last-bit of the last stored block as requested -- note
- that all bits above the last-bit are set to zero, per the type bits
- of a stored block being 00 and per the convention that the bits to
- bring the stream to a byte boundary are also zeros */
- buf[1] = 0;
- buf[2 - len] = (*buf & (mask - 1)) + (last ? mask : 0);
-
- /* write the modified stored block header and lengths, move the file
- pointer to after the last stored block data */
- PUT2(buf + 2, log->stored);
- PUT2(buf + 4, log->stored ^ 0xffff);
- return lseek(log->fd, log->last - len, SEEK_SET) < 0 ||
- write(log->fd, buf + 2 - len, len + 4) != len + 4 ||
- lseek(log->fd, log->stored, SEEK_CUR) < 0 ? -1 : 0;
-}
-
-/* Append len bytes from data to the locked and open log file. len may be zero
- if recovering and no .add file was found. In that case, the previous state
- of the foo.gz file is restored. The data is appended uncompressed in
- deflate stored blocks. Return -1 if there was an error reading or writing
- the foo.gz file. */
-local int log_append(struct log *log, unsigned char *data, size_t len)
-{
- uint put;
- off_t end;
- unsigned char buf[8];
-
- /* set the last block last-bit and length, in case recovering an
- interrupted append, then position the file pointer to append to the
- block */
- if (log_last(log, 1))
- return -1;
-
- /* append, adding stored blocks and updating the offset of the last stored
- block as needed, and update the total crc and length */
- while (len) {
- /* append as much as we can to the last block */
- put = (MAX_STORE << 10) - log->stored;
- if (put > len)
- put = (uint)len;
- if (put) {
- if (write(log->fd, data, put) != put)
- return -1;
- BAIL(1);
- log->tcrc = crc32(log->tcrc, data, put);
- log->tlen += put;
- log->stored += put;
- data += put;
- len -= put;
- }
-
- /* if we need to, add a new empty stored block */
- if (len) {
- /* mark current block as not last */
- if (log_last(log, 0))
- return -1;
-
- /* point to new, empty stored block */
- log->last += 4 + log->stored + 1;
- log->stored = 0;
- }
-
- /* mark last block as last, update its length */
- if (log_last(log, 1))
- return -1;
- BAIL(2);
- }
-
- /* write the new crc and length trailer, and truncate just in case (could
- be recovering from partial append with a missing foo.add file) */
- PUT4(buf, log->tcrc);
- PUT4(buf + 4, log->tlen);
- if (write(log->fd, buf, 8) != 8 ||
- (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end))
- return -1;
-
- /* write the extra field, marking the log file as done, delete .add file */
- if (log_mark(log, NO_OP))
- return -1;
- strcpy(log->end, ".add");
- unlink(log->path); /* ignore error, since may not exist */
- return 0;
-}
-
-/* Replace the foo.dict file with the foo.temp file. Also delete the foo.add
- file, since the compress operation may have been interrupted before that was
- done. Returns 1 if memory could not be allocated, or -1 if reading or
- writing foo.gz fails, or if the rename fails for some reason other than
- foo.temp not existing. foo.temp not existing is a permitted error, since
- the replace operation may have been interrupted after the rename is done,
- but before foo.gz is marked as complete. */
-local int log_replace(struct log *log)
-{
- int ret;
- char *dest;
-
- /* delete foo.add file */
- strcpy(log->end, ".add");
- unlink(log->path); /* ignore error, since may not exist */
- BAIL(3);
-
- /* rename foo.name to foo.dict, replacing foo.dict if it exists */
- strcpy(log->end, ".dict");
- dest = malloc(strlen(log->path) + 1);
- if (dest == NULL)
- return -2;
- strcpy(dest, log->path);
- strcpy(log->end, ".temp");
- ret = rename(log->path, dest);
- free(dest);
- if (ret && errno != ENOENT)
- return -1;
- BAIL(4);
-
- /* mark the foo.gz file as done */
- return log_mark(log, NO_OP);
-}
-
-/* Compress the len bytes at data and append the compressed data to the
- foo.gz deflate data immediately after the previous compressed data. This
- overwrites the previous uncompressed data, which was stored in foo.add
- and is the data provided in data[0..len-1]. If this operation is
- interrupted, it picks up at the start of this routine, with the foo.add
- file read in again. If there is no data to compress (len == 0), then we
- simply terminate the foo.gz file after the previously compressed data,
- appending a final empty stored block and the gzip trailer. Return -1 if
- reading or writing the log.gz file failed, or -2 if there was a memory
- allocation failure. */
-local int log_compress(struct log *log, unsigned char *data, size_t len)
-{
- int fd;
- uint got, max;
- ssize_t dict;
- off_t end;
- z_stream strm;
- unsigned char buf[DICT];
-
- /* compress and append compressed data */
- if (len) {
- /* set up for deflate, allocating memory */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8,
- Z_DEFAULT_STRATEGY) != Z_OK)
- return -2;
-
- /* read in dictionary (last 32K of data that was compressed) */
- strcpy(log->end, ".dict");
- fd = open(log->path, O_RDONLY, 0);
- if (fd >= 0) {
- dict = read(fd, buf, DICT);
- close(fd);
- if (dict < 0) {
- deflateEnd(&strm);
- return -1;
- }
- if (dict)
- deflateSetDictionary(&strm, buf, (uint)dict);
- }
- log_touch(log);
-
- /* prime deflate with last bits of previous block, position write
- pointer to write those bits and overwrite what follows */
- if (lseek(log->fd, log->first - (log->back > 8 ? 2 : 1),
- SEEK_SET) < 0 ||
- read(log->fd, buf, 1) != 1 || lseek(log->fd, -1, SEEK_CUR) < 0) {
- deflateEnd(&strm);
- return -1;
- }
- deflatePrime(&strm, (8 - log->back) & 7, *buf);
-
- /* compress, finishing with a partial non-last empty static block */
- strm.next_in = data;
- max = (((uint)0 - 1) >> 1) + 1; /* in case int smaller than size_t */
- do {
- strm.avail_in = len > max ? max : (uint)len;
- len -= strm.avail_in;
- do {
- strm.avail_out = DICT;
- strm.next_out = buf;
- deflate(&strm, len ? Z_NO_FLUSH : Z_PARTIAL_FLUSH);
- got = DICT - strm.avail_out;
- if (got && write(log->fd, buf, got) != got) {
- deflateEnd(&strm);
- return -1;
- }
- log_touch(log);
- } while (strm.avail_out == 0);
- } while (len);
- deflateEnd(&strm);
- BAIL(5);
-
- /* find start of empty static block -- scanning backwards the first one
- bit is the second bit of the block, if the last byte is zero, then
- we know the byte before that has a one in the top bit, since an
- empty static block is ten bits long */
- if ((log->first = lseek(log->fd, -1, SEEK_CUR)) < 0 ||
- read(log->fd, buf, 1) != 1)
- return -1;
- log->first++;
- if (*buf) {
- log->back = 1;
- while ((*buf & ((uint)1 << (8 - log->back++))) == 0)
- ; /* guaranteed to terminate, since *buf != 0 */
- }
- else
- log->back = 10;
-
- /* update compressed crc and length */
- log->ccrc = log->tcrc;
- log->clen = log->tlen;
- }
- else {
- /* no data to compress -- fix up existing gzip stream */
- log->tcrc = log->ccrc;
- log->tlen = log->clen;
- }
-
- /* complete and truncate gzip stream */
- log->last = log->first;
- log->stored = 0;
- PUT4(buf, log->tcrc);
- PUT4(buf + 4, log->tlen);
- if (log_last(log, 1) || write(log->fd, buf, 8) != 8 ||
- (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end))
- return -1;
- BAIL(6);
-
- /* mark as being in the replace operation */
- if (log_mark(log, REPLACE_OP))
- return -1;
-
- /* execute the replace operation and mark the file as done */
- return log_replace(log);
-}
-
-/* log a repair record to the .repairs file */
-local void log_log(struct log *log, int op, char *record)
-{
- time_t now;
- FILE *rec;
-
- now = time(NULL);
- strcpy(log->end, ".repairs");
- rec = fopen(log->path, "a");
- if (rec == NULL)
- return;
- fprintf(rec, "%.24s %s recovery: %s\n", ctime(&now), op == APPEND_OP ?
- "append" : (op == COMPRESS_OP ? "compress" : "replace"), record);
- fclose(rec);
- return;
-}
-
-/* Recover the interrupted operation op. First read foo.add for recovering an
- append or compress operation. Return -1 if there was an error reading or
- writing foo.gz or reading an existing foo.add, or -2 if there was a memory
- allocation failure. */
-local int log_recover(struct log *log, int op)
-{
- int fd, ret = 0;
- unsigned char *data = NULL;
- size_t len = 0;
- struct stat st;
-
- /* log recovery */
- log_log(log, op, "start");
-
- /* load foo.add file if expected and present */
- if (op == APPEND_OP || op == COMPRESS_OP) {
- strcpy(log->end, ".add");
- if (stat(log->path, &st) == 0 && st.st_size) {
- len = (size_t)(st.st_size);
- if (len != st.st_size || (data = malloc(st.st_size)) == NULL) {
- log_log(log, op, "allocation failure");
- return -2;
- }
- if ((fd = open(log->path, O_RDONLY, 0)) < 0) {
- log_log(log, op, ".add file read failure");
- return -1;
- }
- ret = read(fd, data, len) != len;
- close(fd);
- if (ret) {
- log_log(log, op, ".add file read failure");
- return -1;
- }
- log_log(log, op, "loaded .add file");
- }
- else
- log_log(log, op, "missing .add file!");
- }
-
- /* recover the interrupted operation */
- switch (op) {
- case APPEND_OP:
- ret = log_append(log, data, len);
- break;
- case COMPRESS_OP:
- ret = log_compress(log, data, len);
- break;
- case REPLACE_OP:
- ret = log_replace(log);
- }
-
- /* log status */
- log_log(log, op, ret ? "failure" : "complete");
-
- /* clean up */
- if (data != NULL)
- free(data);
- return ret;
-}
-
-/* Close the foo.gz file (if open) and release the lock. */
-local void log_close(struct log *log)
-{
- if (log->fd >= 0)
- close(log->fd);
- log->fd = -1;
- log_unlock(log);
-}
-
-/* Open foo.gz, verify the header, and load the extra field contents, after
- first creating the foo.lock file to gain exclusive access to the foo.*
- files. If foo.gz does not exist or is empty, then write the initial header,
- extra, and body content of an empty foo.gz log file. If there is an error
- creating the lock file due to access restrictions, or an error reading or
- writing the foo.gz file, or if the foo.gz file is not a proper log file for
- this object (e.g. not a gzip file or does not contain the expected extra
- field), then return true. If there is an error, the lock is released.
- Otherwise, the lock is left in place. */
-local int log_open(struct log *log)
-{
- int op;
-
- /* release open file resource if left over -- can occur if lock lost
- between gzlog_open() and gzlog_write() */
- if (log->fd >= 0)
- close(log->fd);
- log->fd = -1;
-
- /* negotiate exclusive access */
- if (log_lock(log) < 0)
- return -1;
-
- /* open the log file, foo.gz */
- strcpy(log->end, ".gz");
- log->fd = open(log->path, O_RDWR | O_CREAT, 0644);
- if (log->fd < 0) {
- log_close(log);
- return -1;
- }
-
- /* if new, initialize foo.gz with an empty log, delete old dictionary */
- if (lseek(log->fd, 0, SEEK_END) == 0) {
- if (write(log->fd, log_gzhead, HEAD) != HEAD ||
- write(log->fd, log_gzext, EXTRA) != EXTRA ||
- write(log->fd, log_gzbody, BODY) != BODY) {
- log_close(log);
- return -1;
- }
- strcpy(log->end, ".dict");
- unlink(log->path);
- }
-
- /* verify log file and load extra field information */
- if ((op = log_head(log)) < 0) {
- log_close(log);
- return -1;
- }
-
- /* check for interrupted process and if so, recover */
- if (op != NO_OP && log_recover(log, op)) {
- log_close(log);
- return -1;
- }
-
- /* touch the lock file to prevent another process from grabbing it */
- log_touch(log);
- return 0;
-}
-
-/* See gzlog.h for the description of the external methods below */
-gzlog *gzlog_open(char *path)
-{
- size_t n;
- struct log *log;
-
- /* check arguments */
- if (path == NULL || *path == 0)
- return NULL;
-
- /* allocate and initialize log structure */
- log = malloc(sizeof(struct log));
- if (log == NULL)
- return NULL;
- strcpy(log->id, LOGID);
- log->fd = -1;
-
- /* save path and end of path for name construction */
- n = strlen(path);
- log->path = malloc(n + 9); /* allow for ".repairs" */
- if (log->path == NULL) {
- free(log);
- return NULL;
- }
- strcpy(log->path, path);
- log->end = log->path + n;
-
- /* gain exclusive access and verify log file -- may perform a
- recovery operation if needed */
- if (log_open(log)) {
- free(log->path);
- free(log);
- return NULL;
- }
-
- /* return pointer to log structure */
- return log;
-}
-
-/* gzlog_compress() return values:
- 0: all good
- -1: file i/o error (usually access issue)
- -2: memory allocation failure
- -3: invalid log pointer argument */
-int gzlog_compress(gzlog *logd)
-{
- int fd, ret;
- uint block;
- size_t len, next;
- unsigned char *data, buf[5];
- struct log *log = logd;
-
- /* check arguments */
- if (log == NULL || strcmp(log->id, LOGID) || len < 0)
- return -3;
-
- /* see if we lost the lock -- if so get it again and reload the extra
- field information (it probably changed), recover last operation if
- necessary */
- if (log_check(log) && log_open(log))
- return -1;
-
- /* create space for uncompressed data */
- len = ((size_t)(log->last - log->first) & ~(((size_t)1 << 10) - 1)) +
- log->stored;
- if ((data = malloc(len)) == NULL)
- return -2;
-
- /* do statement here is just a cheap trick for error handling */
- do {
- /* read in the uncompressed data */
- if (lseek(log->fd, log->first - 1, SEEK_SET) < 0)
- break;
- next = 0;
- while (next < len) {
- if (read(log->fd, buf, 5) != 5)
- break;
- block = PULL2(buf + 1);
- if (next + block > len ||
- read(log->fd, (char *)data + next, block) != block)
- break;
- next += block;
- }
- if (lseek(log->fd, 0, SEEK_CUR) != log->last + 4 + log->stored)
- break;
- log_touch(log);
-
- /* write the uncompressed data to the .add file */
- strcpy(log->end, ".add");
- fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (fd < 0)
- break;
- ret = write(fd, data, len) != len;
- if (ret | close(fd))
- break;
- log_touch(log);
-
- /* write the dictionary for the next compress to the .temp file */
- strcpy(log->end, ".temp");
- fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (fd < 0)
- break;
- next = DICT > len ? len : DICT;
- ret = write(fd, (char *)data + len - next, next) != next;
- if (ret | close(fd))
- break;
- log_touch(log);
-
- /* roll back to compressed data, mark the compress in progress */
- log->last = log->first;
- log->stored = 0;
- if (log_mark(log, COMPRESS_OP))
- break;
- BAIL(7);
-
- /* compress and append the data (clears mark) */
- ret = log_compress(log, data, len);
- free(data);
- return ret;
- } while (0);
-
- /* broke out of do above on i/o error */
- free(data);
- return -1;
-}
-
-/* gzlog_write() return values:
- 0: all good
- -1: file i/o error (usually access issue)
- -2: memory allocation failure
- -3: invalid log pointer argument */
-int gzlog_write(gzlog *logd, void *data, size_t len)
-{
- int fd, ret;
- struct log *log = logd;
-
- /* check arguments */
- if (log == NULL || strcmp(log->id, LOGID) || len < 0)
- return -3;
- if (data == NULL || len == 0)
- return 0;
-
- /* see if we lost the lock -- if so get it again and reload the extra
- field information (it probably changed), recover last operation if
- necessary */
- if (log_check(log) && log_open(log))
- return -1;
-
- /* create and write .add file */
- strcpy(log->end, ".add");
- fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (fd < 0)
- return -1;
- ret = write(fd, data, len) != len;
- if (ret | close(fd))
- return -1;
- log_touch(log);
-
- /* mark log file with append in progress */
- if (log_mark(log, APPEND_OP))
- return -1;
- BAIL(8);
-
- /* append data (clears mark) */
- if (log_append(log, data, len))
- return -1;
-
- /* check to see if it's time to compress -- if not, then done */
- if (((log->last - log->first) >> 10) + (log->stored >> 10) < TRIGGER)
- return 0;
-
- /* time to compress */
- return gzlog_compress(log);
-}
-
-/* gzlog_close() return values:
- 0: ok
- -3: invalid log pointer argument */
-int gzlog_close(gzlog *logd)
-{
- struct log *log = logd;
-
- /* check arguments */
- if (log == NULL || strcmp(log->id, LOGID))
- return -3;
-
- /* close the log file and release the lock */
- log_close(log);
-
- /* free structure and return */
- if (log->path != NULL)
- free(log->path);
- strcpy(log->id, "bad");
- free(log);
- return 0;
-}
diff --git a/cpukit/zlib/examples/gzlog.h b/cpukit/zlib/examples/gzlog.h
deleted file mode 100644
index c46142673d..0000000000
--- a/cpukit/zlib/examples/gzlog.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/* gzlog.h
- Copyright (C) 2004, 2008 Mark Adler, all rights reserved
- version 2.0, 25 Apr 2008
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the author be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Mark Adler madler@alumni.caltech.edu
- */
-
-/* Version History:
- 1.0 26 Nov 2004 First version
- 2.0 25 Apr 2008 Complete redesign for recovery of interrupted operations
- Interface changed slightly in that now path is a prefix
- Compression now occurs as needed during gzlog_write()
- gzlog_write() now always leaves the log file as valid gzip
- */
-
-/*
- The gzlog object allows writing short messages to a gzipped log file,
- opening the log file locked for small bursts, and then closing it. The log
- object works by appending stored (uncompressed) data to the gzip file until
- 1 MB has been accumulated. At that time, the stored data is compressed, and
- replaces the uncompressed data in the file. The log file is truncated to
- its new size at that time. After each write operation, the log file is a
- valid gzip file that can decompressed to recover what was written.
-
- The gzlog operations can be interupted at any point due to an application or
- system crash, and the log file will be recovered the next time the log is
- opened with gzlog_open().
- */
-
-#ifndef GZLOG_H
-#define GZLOG_H
-
-/* gzlog object type */
-typedef void gzlog;
-
-/* Open a gzlog object, creating the log file if it does not exist. Return
- NULL on error. Note that gzlog_open() could take a while to complete if it
- has to wait to verify that a lock is stale (possibly for five minutes), or
- if there is significant contention with other instantiations of this object
- when locking the resource. path is the prefix of the file names created by
- this object. If path is "foo", then the log file will be "foo.gz", and
- other auxiliary files will be created and destroyed during the process:
- "foo.dict" for a compression dictionary, "foo.temp" for a temporary (next)
- dictionary, "foo.add" for data being added or compressed, "foo.lock" for the
- lock file, and "foo.repairs" to log recovery operations performed due to
- interrupted gzlog operations. A gzlog_open() followed by a gzlog_close()
- will recover a previously interrupted operation, if any. */
-gzlog *gzlog_open(char *path);
-
-/* Write to a gzlog object. Return zero on success, -1 if there is a file i/o
- error on any of the gzlog files (this should not happen if gzlog_open()
- succeeded, unless the device has run out of space or leftover auxiliary
- files have permissions or ownership that prevent their use), -2 if there is
- a memory allocation failure, or -3 if the log argument is invalid (e.g. if
- it was not created by gzlog_open()). This function will write data to the
- file uncompressed, until 1 MB has been accumulated, at which time that data
- will be compressed. The log file will be a valid gzip file upon successful
- return. */
-int gzlog_write(gzlog *log, void *data, size_t len);
-
-/* Force compression of any uncompressed data in the log. This should be used
- sparingly, if at all. The main application would be when a log file will
- not be appended to again. If this is used to compress frequently while
- appending, it will both significantly increase the execution time and
- reduce the compression ratio. The return codes are the same as for
- gzlog_write(). */
-int gzlog_compress(gzlog *log);
-
-/* Close a gzlog object. Return zero on success, -3 if the log argument is
- invalid. The log object is freed, and so cannot be referenced again. */
-int gzlog_close(gzlog *log);
-
-#endif
diff --git a/cpukit/zlib/examples/zlib_how.html b/cpukit/zlib/examples/zlib_how.html
deleted file mode 100644
index 444ff1c9a3..0000000000
--- a/cpukit/zlib/examples/zlib_how.html
+++ /dev/null
@@ -1,545 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
- "http://www.w3.org/TR/REC-html40/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>zlib Usage Example</title>
-<!-- Copyright (c) 2004, 2005 Mark Adler. -->
-</head>
-<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#00A000">
-<h2 align="center"> zlib Usage Example </h2>
-We often get questions about how the <tt>deflate()</tt> and <tt>inflate()</tt> functions should be used.
-Users wonder when they should provide more input, when they should use more output,
-what to do with a <tt>Z_BUF_ERROR</tt>, how to make sure the process terminates properly, and
-so on. So for those who have read <tt>zlib.h</tt> (a few times), and
-would like further edification, below is an annotated example in C of simple routines to compress and decompress
-from an input file to an output file using <tt>deflate()</tt> and <tt>inflate()</tt> respectively. The
-annotations are interspersed between lines of the code. So please read between the lines.
-We hope this helps explain some of the intricacies of <em>zlib</em>.
-<p>
-Without further adieu, here is the program <a href="zpipe.c"><tt>zpipe.c</tt></a>:
-<pre><b>
-/* zpipe.c: example of proper use of zlib's inflate() and deflate()
- Not copyrighted -- provided to the public domain
- Version 1.4 11 December 2005 Mark Adler */
-
-/* Version history:
- 1.0 30 Oct 2004 First version
- 1.1 8 Nov 2004 Add void casting for unused return values
- Use switch statement for inflate() return values
- 1.2 9 Nov 2004 Add assertions to document zlib guarantees
- 1.3 6 Apr 2005 Remove incorrect assertion in inf()
- 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
- Avoid some compiler warnings for input and output buffers
- */
-</b></pre><!-- -->
-We now include the header files for the required definitions. From
-<tt>stdio.h</tt> we use <tt>fopen()</tt>, <tt>fread()</tt>, <tt>fwrite()</tt>,
-<tt>feof()</tt>, <tt>ferror()</tt>, and <tt>fclose()</tt> for file i/o, and
-<tt>fputs()</tt> for error messages. From <tt>string.h</tt> we use
-<tt>strcmp()</tt> for command line argument processing.
-From <tt>assert.h</tt> we use the <tt>assert()</tt> macro.
-From <tt>zlib.h</tt>
-we use the basic compression functions <tt>deflateInit()</tt>,
-<tt>deflate()</tt>, and <tt>deflateEnd()</tt>, and the basic decompression
-functions <tt>inflateInit()</tt>, <tt>inflate()</tt>, and
-<tt>inflateEnd()</tt>.
-<pre><b>
-#include &lt;stdio.h&gt;
-#include &lt;string.h&gt;
-#include &lt;assert.h&gt;
-#include "zlib.h"
-</b></pre><!-- -->
-This is an ugly hack required to avoid corruption of the input and output data on
-Windows/MS-DOS systems. Without this, those systems would assume that the input and output
-files are text, and try to convert the end-of-line characters from one standard to
-another. That would corrupt binary data, and in particular would render the compressed data unusable.
-This sets the input and output to binary which suppresses the end-of-line conversions.
-<tt>SET_BINARY_MODE()</tt> will be used later on <tt>stdin</tt> and <tt>stdout</tt>, at the beginning of <tt>main()</tt>.
-<pre><b>
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-# include &lt;fcntl.h&gt;
-# include &lt;io.h&gt;
-# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-# define SET_BINARY_MODE(file)
-#endif
-</b></pre><!-- -->
-<tt>CHUNK</tt> is simply the buffer size for feeding data to and pulling data
-from the <em>zlib</em> routines. Larger buffer sizes would be more efficient,
-especially for <tt>inflate()</tt>. If the memory is available, buffers sizes
-on the order of 128K or 256K bytes should be used.
-<pre><b>
-#define CHUNK 16384
-</b></pre><!-- -->
-The <tt>def()</tt> routine compresses data from an input file to an output file. The output data
-will be in the <em>zlib</em> format, which is different from the <em>gzip</em> or <em>zip</em>
-formats. The <em>zlib</em> format has a very small header of only two bytes to identify it as
-a <em>zlib</em> stream and to provide decoding information, and a four-byte trailer with a fast
-check value to verify the integrity of the uncompressed data after decoding.
-<pre><b>
-/* Compress from file source to file dest until EOF on source.
- def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
- allocated for processing, Z_STREAM_ERROR if an invalid compression
- level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
- version of the library linked do not match, or Z_ERRNO if there is
- an error reading or writing the files. */
-int def(FILE *source, FILE *dest, int level)
-{
-</b></pre>
-Here are the local variables for <tt>def()</tt>. <tt>ret</tt> will be used for <em>zlib</em>
-return codes. <tt>flush</tt> will keep track of the current flushing state for <tt>deflate()</tt>,
-which is either no flushing, or flush to completion after the end of the input file is reached.
-<tt>have</tt> is the amount of data returned from <tt>deflate()</tt>. The <tt>strm</tt> structure
-is used to pass information to and from the <em>zlib</em> routines, and to maintain the
-<tt>deflate()</tt> state. <tt>in</tt> and <tt>out</tt> are the input and output buffers for
-<tt>deflate()</tt>.
-<pre><b>
- int ret, flush;
- unsigned have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
-</b></pre><!-- -->
-The first thing we do is to initialize the <em>zlib</em> state for compression using
-<tt>deflateInit()</tt>. This must be done before the first use of <tt>deflate()</tt>.
-The <tt>zalloc</tt>, <tt>zfree</tt>, and <tt>opaque</tt> fields in the <tt>strm</tt>
-structure must be initialized before calling <tt>deflateInit()</tt>. Here they are
-set to the <em>zlib</em> constant <tt>Z_NULL</tt> to request that <em>zlib</em> use
-the default memory allocation routines. An application may also choose to provide
-custom memory allocation routines here. <tt>deflateInit()</tt> will allocate on the
-order of 256K bytes for the internal state.
-(See <a href="zlib_tech.html"><em>zlib Technical Details</em></a>.)
-<p>
-<tt>deflateInit()</tt> is called with a pointer to the structure to be initialized and
-the compression level, which is an integer in the range of -1 to 9. Lower compression
-levels result in faster execution, but less compression. Higher levels result in
-greater compression, but slower execution. The <em>zlib</em> constant Z_DEFAULT_COMPRESSION,
-equal to -1,
-provides a good compromise between compression and speed and is equivalent to level 6.
-Level 0 actually does no compression at all, and in fact expands the data slightly to produce
-the <em>zlib</em> format (it is not a byte-for-byte copy of the input).
-More advanced applications of <em>zlib</em>
-may use <tt>deflateInit2()</tt> here instead. Such an application may want to reduce how
-much memory will be used, at some price in compression. Or it may need to request a
-<em>gzip</em> header and trailer instead of a <em>zlib</em> header and trailer, or raw
-encoding with no header or trailer at all.
-<p>
-We must check the return value of <tt>deflateInit()</tt> against the <em>zlib</em> constant
-<tt>Z_OK</tt> to make sure that it was able to
-allocate memory for the internal state, and that the provided arguments were valid.
-<tt>deflateInit()</tt> will also check that the version of <em>zlib</em> that the <tt>zlib.h</tt>
-file came from matches the version of <em>zlib</em> actually linked with the program. This
-is especially important for environments in which <em>zlib</em> is a shared library.
-<p>
-Note that an application can initialize multiple, independent <em>zlib</em> streams, which can
-operate in parallel. The state information maintained in the structure allows the <em>zlib</em>
-routines to be reentrant.
-<pre><b>
- /* allocate deflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&amp;strm, level);
- if (ret != Z_OK)
- return ret;
-</b></pre><!-- -->
-With the pleasantries out of the way, now we can get down to business. The outer <tt>do</tt>-loop
-reads all of the input file and exits at the bottom of the loop once end-of-file is reached.
-This loop contains the only call of <tt>deflate()</tt>. So we must make sure that all of the
-input data has been processed and that all of the output data has been generated and consumed
-before we fall out of the loop at the bottom.
-<pre><b>
- /* compress until end of file */
- do {
-</b></pre>
-We start off by reading data from the input file. The number of bytes read is put directly
-into <tt>avail_in</tt>, and a pointer to those bytes is put into <tt>next_in</tt>. We also
-check to see if end-of-file on the input has been reached. If we are at the end of file, then <tt>flush</tt> is set to the
-<em>zlib</em> constant <tt>Z_FINISH</tt>, which is later passed to <tt>deflate()</tt> to
-indicate that this is the last chunk of input data to compress. We need to use <tt>feof()</tt>
-to check for end-of-file as opposed to seeing if fewer than <tt>CHUNK</tt> bytes have been read. The
-reason is that if the input file length is an exact multiple of <tt>CHUNK</tt>, we will miss
-the fact that we got to the end-of-file, and not know to tell <tt>deflate()</tt> to finish
-up the compressed stream. If we are not yet at the end of the input, then the <em>zlib</em>
-constant <tt>Z_NO_FLUSH</tt> will be passed to <tt>deflate</tt> to indicate that we are still
-in the middle of the uncompressed data.
-<p>
-If there is an error in reading from the input file, the process is aborted with
-<tt>deflateEnd()</tt> being called to free the allocated <em>zlib</em> state before returning
-the error. We wouldn't want a memory leak, now would we? <tt>deflateEnd()</tt> can be called
-at any time after the state has been initialized. Once that's done, <tt>deflateInit()</tt> (or
-<tt>deflateInit2()</tt>) would have to be called to start a new compression process. There is
-no point here in checking the <tt>deflateEnd()</tt> return code. The deallocation can't fail.
-<pre><b>
- strm.avail_in = fread(in, 1, CHUNK, source);
- if (ferror(source)) {
- (void)deflateEnd(&amp;strm);
- return Z_ERRNO;
- }
- flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
- strm.next_in = in;
-</b></pre><!-- -->
-The inner <tt>do</tt>-loop passes our chunk of input data to <tt>deflate()</tt>, and then
-keeps calling <tt>deflate()</tt> until it is done producing output. Once there is no more
-new output, <tt>deflate()</tt> is guaranteed to have consumed all of the input, i.e.,
-<tt>avail_in</tt> will be zero.
-<pre><b>
- /* run deflate() on input until output buffer not full, finish
- compression if all of source has been read in */
- do {
-</b></pre>
-Output space is provided to <tt>deflate()</tt> by setting <tt>avail_out</tt> to the number
-of available output bytes and <tt>next_out</tt> to a pointer to that space.
-<pre><b>
- strm.avail_out = CHUNK;
- strm.next_out = out;
-</b></pre>
-Now we call the compression engine itself, <tt>deflate()</tt>. It takes as many of the
-<tt>avail_in</tt> bytes at <tt>next_in</tt> as it can process, and writes as many as
-<tt>avail_out</tt> bytes to <tt>next_out</tt>. Those counters and pointers are then
-updated past the input data consumed and the output data written. It is the amount of
-output space available that may limit how much input is consumed.
-Hence the inner loop to make sure that
-all of the input is consumed by providing more output space each time. Since <tt>avail_in</tt>
-and <tt>next_in</tt> are updated by <tt>deflate()</tt>, we don't have to mess with those
-between <tt>deflate()</tt> calls until it's all used up.
-<p>
-The parameters to <tt>deflate()</tt> are a pointer to the <tt>strm</tt> structure containing
-the input and output information and the internal compression engine state, and a parameter
-indicating whether and how to flush data to the output. Normally <tt>deflate</tt> will consume
-several K bytes of input data before producing any output (except for the header), in order
-to accumulate statistics on the data for optimum compression. It will then put out a burst of
-compressed data, and proceed to consume more input before the next burst. Eventually,
-<tt>deflate()</tt>
-must be told to terminate the stream, complete the compression with provided input data, and
-write out the trailer check value. <tt>deflate()</tt> will continue to compress normally as long
-as the flush parameter is <tt>Z_NO_FLUSH</tt>. Once the <tt>Z_FINISH</tt> parameter is provided,
-<tt>deflate()</tt> will begin to complete the compressed output stream. However depending on how
-much output space is provided, <tt>deflate()</tt> may have to be called several times until it
-has provided the complete compressed stream, even after it has consumed all of the input. The flush
-parameter must continue to be <tt>Z_FINISH</tt> for those subsequent calls.
-<p>
-There are other values of the flush parameter that are used in more advanced applications. You can
-force <tt>deflate()</tt> to produce a burst of output that encodes all of the input data provided
-so far, even if it wouldn't have otherwise, for example to control data latency on a link with
-compressed data. You can also ask that <tt>deflate()</tt> do that as well as erase any history up to
-that point so that what follows can be decompressed independently, for example for random access
-applications. Both requests will degrade compression by an amount depending on how often such
-requests are made.
-<p>
-<tt>deflate()</tt> has a return value that can indicate errors, yet we do not check it here. Why
-not? Well, it turns out that <tt>deflate()</tt> can do no wrong here. Let's go through
-<tt>deflate()</tt>'s return values and dispense with them one by one. The possible values are
-<tt>Z_OK</tt>, <tt>Z_STREAM_END</tt>, <tt>Z_STREAM_ERROR</tt>, or <tt>Z_BUF_ERROR</tt>. <tt>Z_OK</tt>
-is, well, ok. <tt>Z_STREAM_END</tt> is also ok and will be returned for the last call of
-<tt>deflate()</tt>. This is already guaranteed by calling <tt>deflate()</tt> with <tt>Z_FINISH</tt>
-until it has no more output. <tt>Z_STREAM_ERROR</tt> is only possible if the stream is not
-initialized properly, but we did initialize it properly. There is no harm in checking for
-<tt>Z_STREAM_ERROR</tt> here, for example to check for the possibility that some
-other part of the application inadvertently clobbered the memory containing the <em>zlib</em> state.
-<tt>Z_BUF_ERROR</tt> will be explained further below, but
-suffice it to say that this is simply an indication that <tt>deflate()</tt> could not consume
-more input or produce more output. <tt>deflate()</tt> can be called again with more output space
-or more available input, which it will be in this code.
-<pre><b>
- ret = deflate(&amp;strm, flush); /* no bad return value */
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
-</b></pre>
-Now we compute how much output <tt>deflate()</tt> provided on the last call, which is the
-difference between how much space was provided before the call, and how much output space
-is still available after the call. Then that data, if any, is written to the output file.
-We can then reuse the output buffer for the next call of <tt>deflate()</tt>. Again if there
-is a file i/o error, we call <tt>deflateEnd()</tt> before returning to avoid a memory leak.
-<pre><b>
- have = CHUNK - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
- (void)deflateEnd(&amp;strm);
- return Z_ERRNO;
- }
-</b></pre>
-The inner <tt>do</tt>-loop is repeated until the last <tt>deflate()</tt> call fails to fill the
-provided output buffer. Then we know that <tt>deflate()</tt> has done as much as it can with
-the provided input, and that all of that input has been consumed. We can then fall out of this
-loop and reuse the input buffer.
-<p>
-The way we tell that <tt>deflate()</tt> has no more output is by seeing that it did not fill
-the output buffer, leaving <tt>avail_out</tt> greater than zero. However suppose that
-<tt>deflate()</tt> has no more output, but just so happened to exactly fill the output buffer!
-<tt>avail_out</tt> is zero, and we can't tell that <tt>deflate()</tt> has done all it can.
-As far as we know, <tt>deflate()</tt>
-has more output for us. So we call it again. But now <tt>deflate()</tt> produces no output
-at all, and <tt>avail_out</tt> remains unchanged as <tt>CHUNK</tt>. That <tt>deflate()</tt> call
-wasn't able to do anything, either consume input or produce output, and so it returns
-<tt>Z_BUF_ERROR</tt>. (See, I told you I'd cover this later.) However this is not a problem at
-all. Now we finally have the desired indication that <tt>deflate()</tt> is really done,
-and so we drop out of the inner loop to provide more input to <tt>deflate()</tt>.
-<p>
-With <tt>flush</tt> set to <tt>Z_FINISH</tt>, this final set of <tt>deflate()</tt> calls will
-complete the output stream. Once that is done, subsequent calls of <tt>deflate()</tt> would return
-<tt>Z_STREAM_ERROR</tt> if the flush parameter is not <tt>Z_FINISH</tt>, and do no more processing
-until the state is reinitialized.
-<p>
-Some applications of <em>zlib</em> have two loops that call <tt>deflate()</tt>
-instead of the single inner loop we have here. The first loop would call
-without flushing and feed all of the data to <tt>deflate()</tt>. The second loop would call
-<tt>deflate()</tt> with no more
-data and the <tt>Z_FINISH</tt> parameter to complete the process. As you can see from this
-example, that can be avoided by simply keeping track of the current flush state.
-<pre><b>
- } while (strm.avail_out == 0);
- assert(strm.avail_in == 0); /* all input will be used */
-</b></pre><!-- -->
-Now we check to see if we have already processed all of the input file. That information was
-saved in the <tt>flush</tt> variable, so we see if that was set to <tt>Z_FINISH</tt>. If so,
-then we're done and we fall out of the outer loop. We're guaranteed to get <tt>Z_STREAM_END</tt>
-from the last <tt>deflate()</tt> call, since we ran it until the last chunk of input was
-consumed and all of the output was generated.
-<pre><b>
- /* done when last data in file processed */
- } while (flush != Z_FINISH);
- assert(ret == Z_STREAM_END); /* stream will be complete */
-</b></pre><!-- -->
-The process is complete, but we still need to deallocate the state to avoid a memory leak
-(or rather more like a memory hemorrhage if you didn't do this). Then
-finally we can return with a happy return value.
-<pre><b>
- /* clean up and return */
- (void)deflateEnd(&amp;strm);
- return Z_OK;
-}
-</b></pre><!-- -->
-Now we do the same thing for decompression in the <tt>inf()</tt> routine. <tt>inf()</tt>
-decompresses what is hopefully a valid <em>zlib</em> stream from the input file and writes the
-uncompressed data to the output file. Much of the discussion above for <tt>def()</tt>
-applies to <tt>inf()</tt> as well, so the discussion here will focus on the differences between
-the two.
-<pre><b>
-/* Decompress from file source to file dest until stream ends or EOF.
- inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
- allocated for processing, Z_DATA_ERROR if the deflate data is
- invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
- the version of the library linked do not match, or Z_ERRNO if there
- is an error reading or writing the files. */
-int inf(FILE *source, FILE *dest)
-{
-</b></pre>
-The local variables have the same functionality as they do for <tt>def()</tt>. The
-only difference is that there is no <tt>flush</tt> variable, since <tt>inflate()</tt>
-can tell from the <em>zlib</em> stream itself when the stream is complete.
-<pre><b>
- int ret;
- unsigned have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
-</b></pre><!-- -->
-The initialization of the state is the same, except that there is no compression level,
-of course, and two more elements of the structure are initialized. <tt>avail_in</tt>
-and <tt>next_in</tt> must be initialized before calling <tt>inflateInit()</tt>. This
-is because the application has the option to provide the start of the zlib stream in
-order for <tt>inflateInit()</tt> to have access to information about the compression
-method to aid in memory allocation. In the current implementation of <em>zlib</em>
-(up through versions 1.2.x), the method-dependent memory allocations are deferred to the first call of
-<tt>inflate()</tt> anyway. However those fields must be initialized since later versions
-of <em>zlib</em> that provide more compression methods may take advantage of this interface.
-In any case, no decompression is performed by <tt>inflateInit()</tt>, so the
-<tt>avail_out</tt> and <tt>next_out</tt> fields do not need to be initialized before calling.
-<p>
-Here <tt>avail_in</tt> is set to zero and <tt>next_in</tt> is set to <tt>Z_NULL</tt> to
-indicate that no input data is being provided.
-<pre><b>
- /* allocate inflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&amp;strm);
- if (ret != Z_OK)
- return ret;
-</b></pre><!-- -->
-The outer <tt>do</tt>-loop decompresses input until <tt>inflate()</tt> indicates
-that it has reached the end of the compressed data and has produced all of the uncompressed
-output. This is in contrast to <tt>def()</tt> which processes all of the input file.
-If end-of-file is reached before the compressed data self-terminates, then the compressed
-data is incomplete and an error is returned.
-<pre><b>
- /* decompress until deflate stream ends or end of file */
- do {
-</b></pre>
-We read input data and set the <tt>strm</tt> structure accordingly. If we've reached the
-end of the input file, then we leave the outer loop and report an error, since the
-compressed data is incomplete. Note that we may read more data than is eventually consumed
-by <tt>inflate()</tt>, if the input file continues past the <em>zlib</em> stream.
-For applications where <em>zlib</em> streams are embedded in other data, this routine would
-need to be modified to return the unused data, or at least indicate how much of the input
-data was not used, so the application would know where to pick up after the <em>zlib</em> stream.
-<pre><b>
- strm.avail_in = fread(in, 1, CHUNK, source);
- if (ferror(source)) {
- (void)inflateEnd(&amp;strm);
- return Z_ERRNO;
- }
- if (strm.avail_in == 0)
- break;
- strm.next_in = in;
-</b></pre><!-- -->
-The inner <tt>do</tt>-loop has the same function it did in <tt>def()</tt>, which is to
-keep calling <tt>inflate()</tt> until has generated all of the output it can with the
-provided input.
-<pre><b>
- /* run inflate() on input until output buffer not full */
- do {
-</b></pre>
-Just like in <tt>def()</tt>, the same output space is provided for each call of <tt>inflate()</tt>.
-<pre><b>
- strm.avail_out = CHUNK;
- strm.next_out = out;
-</b></pre>
-Now we run the decompression engine itself. There is no need to adjust the flush parameter, since
-the <em>zlib</em> format is self-terminating. The main difference here is that there are
-return values that we need to pay attention to. <tt>Z_DATA_ERROR</tt>
-indicates that <tt>inflate()</tt> detected an error in the <em>zlib</em> compressed data format,
-which means that either the data is not a <em>zlib</em> stream to begin with, or that the data was
-corrupted somewhere along the way since it was compressed. The other error to be processed is
-<tt>Z_MEM_ERROR</tt>, which can occur since memory allocation is deferred until <tt>inflate()</tt>
-needs it, unlike <tt>deflate()</tt>, whose memory is allocated at the start by <tt>deflateInit()</tt>.
-<p>
-Advanced applications may use
-<tt>deflateSetDictionary()</tt> to prime <tt>deflate()</tt> with a set of likely data to improve the
-first 32K or so of compression. This is noted in the <em>zlib</em> header, so <tt>inflate()</tt>
-requests that that dictionary be provided before it can start to decompress. Without the dictionary,
-correct decompression is not possible. For this routine, we have no idea what the dictionary is,
-so the <tt>Z_NEED_DICT</tt> indication is converted to a <tt>Z_DATA_ERROR</tt>.
-<p>
-<tt>inflate()</tt> can also return <tt>Z_STREAM_ERROR</tt>, which should not be possible here,
-but could be checked for as noted above for <tt>def()</tt>. <tt>Z_BUF_ERROR</tt> does not need to be
-checked for here, for the same reasons noted for <tt>def()</tt>. <tt>Z_STREAM_END</tt> will be
-checked for later.
-<pre><b>
- ret = inflate(&amp;strm, Z_NO_FLUSH);
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- switch (ret) {
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- (void)inflateEnd(&amp;strm);
- return ret;
- }
-</b></pre>
-The output of <tt>inflate()</tt> is handled identically to that of <tt>deflate()</tt>.
-<pre><b>
- have = CHUNK - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
- (void)inflateEnd(&amp;strm);
- return Z_ERRNO;
- }
-</b></pre>
-The inner <tt>do</tt>-loop ends when <tt>inflate()</tt> has no more output as indicated
-by not filling the output buffer, just as for <tt>deflate()</tt>. In this case, we cannot
-assert that <tt>strm.avail_in</tt> will be zero, since the deflate stream may end before the file
-does.
-<pre><b>
- } while (strm.avail_out == 0);
-</b></pre><!-- -->
-The outer <tt>do</tt>-loop ends when <tt>inflate()</tt> reports that it has reached the
-end of the input <em>zlib</em> stream, has completed the decompression and integrity
-check, and has provided all of the output. This is indicated by the <tt>inflate()</tt>
-return value <tt>Z_STREAM_END</tt>. The inner loop is guaranteed to leave <tt>ret</tt>
-equal to <tt>Z_STREAM_END</tt> if the last chunk of the input file read contained the end
-of the <em>zlib</em> stream. So if the return value is not <tt>Z_STREAM_END</tt>, the
-loop continues to read more input.
-<pre><b>
- /* done when inflate() says it's done */
- } while (ret != Z_STREAM_END);
-</b></pre><!-- -->
-At this point, decompression successfully completed, or we broke out of the loop due to no
-more data being available from the input file. If the last <tt>inflate()</tt> return value
-is not <tt>Z_STREAM_END</tt>, then the <em>zlib</em> stream was incomplete and a data error
-is returned. Otherwise, we return with a happy return value. Of course, <tt>inflateEnd()</tt>
-is called first to avoid a memory leak.
-<pre><b>
- /* clean up and return */
- (void)inflateEnd(&amp;strm);
- return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
-}
-</b></pre><!-- -->
-That ends the routines that directly use <em>zlib</em>. The following routines make this
-a command-line program by running data through the above routines from <tt>stdin</tt> to
-<tt>stdout</tt>, and handling any errors reported by <tt>def()</tt> or <tt>inf()</tt>.
-<p>
-<tt>zerr()</tt> is used to interpret the possible error codes from <tt>def()</tt>
-and <tt>inf()</tt>, as detailed in their comments above, and print out an error message.
-Note that these are only a subset of the possible return values from <tt>deflate()</tt>
-and <tt>inflate()</tt>.
-<pre><b>
-/* report a zlib or i/o error */
-void zerr(int ret)
-{
- fputs("zpipe: ", stderr);
- switch (ret) {
- case Z_ERRNO:
- if (ferror(stdin))
- fputs("error reading stdin\n", stderr);
- if (ferror(stdout))
- fputs("error writing stdout\n", stderr);
- break;
- case Z_STREAM_ERROR:
- fputs("invalid compression level\n", stderr);
- break;
- case Z_DATA_ERROR:
- fputs("invalid or incomplete deflate data\n", stderr);
- break;
- case Z_MEM_ERROR:
- fputs("out of memory\n", stderr);
- break;
- case Z_VERSION_ERROR:
- fputs("zlib version mismatch!\n", stderr);
- }
-}
-</b></pre><!-- -->
-Here is the <tt>main()</tt> routine used to test <tt>def()</tt> and <tt>inf()</tt>. The
-<tt>zpipe</tt> command is simply a compression pipe from <tt>stdin</tt> to <tt>stdout</tt>, if
-no arguments are given, or it is a decompression pipe if <tt>zpipe -d</tt> is used. If any other
-arguments are provided, no compression or decompression is performed. Instead a usage
-message is displayed. Examples are <tt>zpipe < foo.txt > foo.txt.z</tt> to compress, and
-<tt>zpipe -d < foo.txt.z > foo.txt</tt> to decompress.
-<pre><b>
-/* compress or decompress from stdin to stdout */
-int main(int argc, char **argv)
-{
- int ret;
-
- /* avoid end-of-line conversions */
- SET_BINARY_MODE(stdin);
- SET_BINARY_MODE(stdout);
-
- /* do compression if no arguments */
- if (argc == 1) {
- ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
- if (ret != Z_OK)
- zerr(ret);
- return ret;
- }
-
- /* do decompression if -d specified */
- else if (argc == 2 &amp;&amp; strcmp(argv[1], "-d") == 0) {
- ret = inf(stdin, stdout);
- if (ret != Z_OK)
- zerr(ret);
- return ret;
- }
-
- /* otherwise, report usage */
- else {
- fputs("zpipe usage: zpipe [-d] &lt; source &gt; dest\n", stderr);
- return 1;
- }
-}
-</b></pre>
-<hr>
-<i>Copyright (c) 2004, 2005 by Mark Adler<br>Last modified 11 December 2005</i>
-</body>
-</html>
diff --git a/cpukit/zlib/examples/zpipe.c b/cpukit/zlib/examples/zpipe.c
deleted file mode 100644
index 83535d1693..0000000000
--- a/cpukit/zlib/examples/zpipe.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/* zpipe.c: example of proper use of zlib's inflate() and deflate()
- Not copyrighted -- provided to the public domain
- Version 1.4 11 December 2005 Mark Adler */
-
-/* Version history:
- 1.0 30 Oct 2004 First version
- 1.1 8 Nov 2004 Add void casting for unused return values
- Use switch statement for inflate() return values
- 1.2 9 Nov 2004 Add assertions to document zlib guarantees
- 1.3 6 Apr 2005 Remove incorrect assertion in inf()
- 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
- Avoid some compiler warnings for input and output buffers
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include "zlib.h"
-
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-# include <fcntl.h>
-# include <io.h>
-# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-# define SET_BINARY_MODE(file)
-#endif
-
-#define CHUNK 16384
-
-/* Compress from file source to file dest until EOF on source.
- def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
- allocated for processing, Z_STREAM_ERROR if an invalid compression
- level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
- version of the library linked do not match, or Z_ERRNO if there is
- an error reading or writing the files. */
-int def(FILE *source, FILE *dest, int level)
-{
- int ret, flush;
- unsigned have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
-
- /* allocate deflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&strm, level);
- if (ret != Z_OK)
- return ret;
-
- /* compress until end of file */
- do {
- strm.avail_in = fread(in, 1, CHUNK, source);
- if (ferror(source)) {
- (void)deflateEnd(&strm);
- return Z_ERRNO;
- }
- flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
- strm.next_in = in;
-
- /* run deflate() on input until output buffer not full, finish
- compression if all of source has been read in */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = deflate(&strm, flush); /* no bad return value */
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- have = CHUNK - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
- (void)deflateEnd(&strm);
- return Z_ERRNO;
- }
- } while (strm.avail_out == 0);
- assert(strm.avail_in == 0); /* all input will be used */
-
- /* done when last data in file processed */
- } while (flush != Z_FINISH);
- assert(ret == Z_STREAM_END); /* stream will be complete */
-
- /* clean up and return */
- (void)deflateEnd(&strm);
- return Z_OK;
-}
-
-/* Decompress from file source to file dest until stream ends or EOF.
- inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
- allocated for processing, Z_DATA_ERROR if the deflate data is
- invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
- the version of the library linked do not match, or Z_ERRNO if there
- is an error reading or writing the files. */
-int inf(FILE *source, FILE *dest)
-{
- int ret;
- unsigned have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
-
- /* allocate inflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm);
- if (ret != Z_OK)
- return ret;
-
- /* decompress until deflate stream ends or end of file */
- do {
- strm.avail_in = fread(in, 1, CHUNK, source);
- if (ferror(source)) {
- (void)inflateEnd(&strm);
- return Z_ERRNO;
- }
- if (strm.avail_in == 0)
- break;
- strm.next_in = in;
-
- /* run inflate() on input until output buffer not full */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = inflate(&strm, Z_NO_FLUSH);
- assert(ret != Z_STREAM_ERROR); /* state not clobbered */
- switch (ret) {
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
- return ret;
- }
- have = CHUNK - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
- (void)inflateEnd(&strm);
- return Z_ERRNO;
- }
- } while (strm.avail_out == 0);
-
- /* done when inflate() says it's done */
- } while (ret != Z_STREAM_END);
-
- /* clean up and return */
- (void)inflateEnd(&strm);
- return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
-}
-
-/* report a zlib or i/o error */
-void zerr(int ret)
-{
- fputs("zpipe: ", stderr);
- switch (ret) {
- case Z_ERRNO:
- if (ferror(stdin))
- fputs("error reading stdin\n", stderr);
- if (ferror(stdout))
- fputs("error writing stdout\n", stderr);
- break;
- case Z_STREAM_ERROR:
- fputs("invalid compression level\n", stderr);
- break;
- case Z_DATA_ERROR:
- fputs("invalid or incomplete deflate data\n", stderr);
- break;
- case Z_MEM_ERROR:
- fputs("out of memory\n", stderr);
- break;
- case Z_VERSION_ERROR:
- fputs("zlib version mismatch!\n", stderr);
- }
-}
-
-/* compress or decompress from stdin to stdout */
-int main(int argc, char **argv)
-{
- int ret;
-
- /* avoid end-of-line conversions */
- SET_BINARY_MODE(stdin);
- SET_BINARY_MODE(stdout);
-
- /* do compression if no arguments */
- if (argc == 1) {
- ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
- if (ret != Z_OK)
- zerr(ret);
- return ret;
- }
-
- /* do decompression if -d specified */
- else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
- ret = inf(stdin, stdout);
- if (ret != Z_OK)
- zerr(ret);
- return ret;
- }
-
- /* otherwise, report usage */
- else {
- fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
- return 1;
- }
-}
diff --git a/cpukit/zlib/gzio.c b/cpukit/zlib/gzio.c
deleted file mode 100644
index 7e90f4928f..0000000000
--- a/cpukit/zlib/gzio.c
+++ /dev/null
@@ -1,1026 +0,0 @@
-/* gzio.c -- IO on .gz files
- * Copyright (C) 1995-2005 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- *
- * Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
- */
-
-/* @(#) $Id$ */
-
-#include <stdio.h>
-
-#include "zutil.h"
-
-#ifdef NO_DEFLATE /* for compatibility with old definition */
-# define NO_GZCOMPRESS
-#endif
-
-#ifndef NO_DUMMY_DECL
-struct internal_state {int dummy;}; /* for buggy compilers */
-#endif
-
-#ifndef Z_BUFSIZE
-# ifdef MAXSEG_64K
-# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
-# else
-# define Z_BUFSIZE 16384
-# endif
-#endif
-#ifndef Z_PRINTF_BUFSIZE
-# define Z_PRINTF_BUFSIZE 4096
-#endif
-
-#ifdef __MVS__
-# pragma map (fdopen , "\174\174FDOPEN")
- FILE *fdopen(int, const char *);
-#endif
-
-#ifndef STDC
-extern voidp malloc OF((uInt size));
-extern void free OF((voidpf ptr));
-#endif
-
-#define ALLOC(size) malloc(size)
-#define TRYFREE(p) {if (p) free(p);}
-
-static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
-
-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define RESERVED 0xE0 /* bits 5..7: reserved */
-
-typedef struct gz_stream {
- z_stream stream;
- int z_err; /* error code for last stream operation */
- int z_eof; /* set if end of input file */
- FILE *file; /* .gz file */
- Byte *inbuf; /* input buffer */
- Byte *outbuf; /* output buffer */
- uLong crc; /* crc32 of uncompressed data */
- char *msg; /* error message */
- char *path; /* path name for debugging only */
- int transparent; /* 1 if input file is not a .gz file */
- char mode; /* 'w' or 'r' */
- z_off_t start; /* start of compressed data in file (header skipped) */
- z_off_t in; /* bytes into deflate or inflate */
- z_off_t out; /* bytes out of deflate or inflate */
- int back; /* one character push-back */
- int last; /* true if push-back is last character */
-} gz_stream;
-
-
-local gzFile gz_open OF((const char *path, const char *mode, int fd));
-local int do_flush OF((gzFile file, int flush));
-local int get_byte OF((gz_stream *s));
-local void check_header OF((gz_stream *s));
-local int destroy OF((gz_stream *s));
-local void putLong OF((FILE *file, uLong x));
-local uLong getLong OF((gz_stream *s));
-
-/* ===========================================================================
- Opens a gzip (.gz) file for reading or writing. The mode parameter
- is as in fopen ("rb" or "wb"). The file is given either by file descriptor
- or path name (if fd == -1).
- gz_open returns NULL if the file could not be opened or if there was
- insufficient memory to allocate the (de)compression state; errno
- can be checked to distinguish the two cases (if errno is zero, the
- zlib error is Z_MEM_ERROR).
-*/
-local gzFile gz_open (path, mode, fd)
- const char *path;
- const char *mode;
- int fd;
-{
- int err;
- int level = Z_DEFAULT_COMPRESSION; /* compression level */
- int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
- char *p = (char*)mode;
- gz_stream *s;
- char fmode[80]; /* copy of mode, without the compression level */
- char *m = fmode;
-
- if (!path || !mode) return Z_NULL;
-
- s = (gz_stream *)ALLOC(sizeof(gz_stream));
- if (!s) return Z_NULL;
-
- s->stream.zalloc = (alloc_func)0;
- s->stream.zfree = (free_func)0;
- s->stream.opaque = (voidpf)0;
- s->stream.next_in = s->inbuf = Z_NULL;
- s->stream.next_out = s->outbuf = Z_NULL;
- s->stream.avail_in = s->stream.avail_out = 0;
- s->file = NULL;
- s->z_err = Z_OK;
- s->z_eof = 0;
- s->in = 0;
- s->out = 0;
- s->back = EOF;
- s->crc = crc32(0L, Z_NULL, 0);
- s->msg = NULL;
- s->transparent = 0;
-
- s->path = (char*)ALLOC(strlen(path)+1);
- if (s->path == NULL) {
- return destroy(s), (gzFile)Z_NULL;
- }
- strcpy(s->path, path); /* do this early for debugging */
-
- s->mode = '\0';
- do {
- if (*p == 'r') s->mode = 'r';
- if (*p == 'w' || *p == 'a') s->mode = 'w';
- if (*p >= '0' && *p <= '9') {
- level = *p - '0';
- } else if (*p == 'f') {
- strategy = Z_FILTERED;
- } else if (*p == 'h') {
- strategy = Z_HUFFMAN_ONLY;
- } else if (*p == 'R') {
- strategy = Z_RLE;
- } else {
- *m++ = *p; /* copy the mode */
- }
- } while (*p++ && m != fmode + sizeof(fmode));
- if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
-
- if (s->mode == 'w') {
-#ifdef NO_GZCOMPRESS
- err = Z_STREAM_ERROR;
-#else
- err = deflateInit2(&(s->stream), level,
- Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
- /* windowBits is passed < 0 to suppress zlib header */
-
- s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
-#endif
- if (err != Z_OK || s->outbuf == Z_NULL) {
- return destroy(s), (gzFile)Z_NULL;
- }
- } else {
- s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
-
- err = inflateInit2(&(s->stream), -MAX_WBITS);
- /* windowBits is passed < 0 to tell that there is no zlib header.
- * Note that in this case inflate *requires* an extra "dummy" byte
- * after the compressed stream in order to complete decompression and
- * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
- * present after the compressed stream.
- */
- if (err != Z_OK || s->inbuf == Z_NULL) {
- return destroy(s), (gzFile)Z_NULL;
- }
- }
- s->stream.avail_out = Z_BUFSIZE;
-
- errno = 0;
- s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
-
- if (s->file == NULL) {
- return destroy(s), (gzFile)Z_NULL;
- }
- if (s->mode == 'w') {
- /* Write a very simple .gz header:
- */
- fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
- Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
- s->start = 10L;
- /* We use 10L instead of ftell(s->file) to because ftell causes an
- * fflush on some systems. This version of the library doesn't use
- * start anyway in write mode, so this initialization is not
- * necessary.
- */
- } else {
- check_header(s); /* skip the .gz header */
- s->start = ftell(s->file) - s->stream.avail_in;
- }
-
- return (gzFile)s;
-}
-
-/* ===========================================================================
- Opens a gzip (.gz) file for reading or writing.
-*/
-gzFile ZEXPORT gzopen (path, mode)
- const char *path;
- const char *mode;
-{
- return gz_open (path, mode, -1);
-}
-
-/* ===========================================================================
- Associate a gzFile with the file descriptor fd. fd is not dup'ed here
- to mimic the behavio(u)r of fdopen.
-*/
-gzFile ZEXPORT gzdopen (fd, mode)
- int fd;
- const char *mode;
-{
- char name[46]; /* allow for up to 128-bit integers */
-
- if (fd < 0) return (gzFile)Z_NULL;
- sprintf(name, "<fd:%d>", fd); /* for debugging */
-
- return gz_open (name, mode, fd);
-}
-
-/* ===========================================================================
- * Update the compression level and strategy
- */
-int ZEXPORT gzsetparams (file, level, strategy)
- gzFile file;
- int level;
- int strategy;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
-
- /* Make room to allow flushing */
- if (s->stream.avail_out == 0) {
-
- s->stream.next_out = s->outbuf;
- if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
- s->z_err = Z_ERRNO;
- }
- s->stream.avail_out = Z_BUFSIZE;
- }
-
- return deflateParams (&(s->stream), level, strategy);
-}
-
-/* ===========================================================================
- Read a byte from a gz_stream; update next_in and avail_in. Return EOF
- for end of file.
- IN assertion: the stream s has been sucessfully opened for reading.
-*/
-local int get_byte(s)
- gz_stream *s;
-{
- if (s->z_eof) return EOF;
- if (s->stream.avail_in == 0) {
- errno = 0;
- s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
- if (s->stream.avail_in == 0) {
- s->z_eof = 1;
- if (ferror(s->file)) s->z_err = Z_ERRNO;
- return EOF;
- }
- s->stream.next_in = s->inbuf;
- }
- s->stream.avail_in--;
- return *(s->stream.next_in)++;
-}
-
-/* ===========================================================================
- Check the gzip header of a gz_stream opened for reading. Set the stream
- mode to transparent if the gzip magic header is not present; set s->err
- to Z_DATA_ERROR if the magic header is present but the rest of the header
- is incorrect.
- IN assertion: the stream s has already been created sucessfully;
- s->stream.avail_in is zero for the first time, but may be non-zero
- for concatenated .gz files.
-*/
-local void check_header(s)
- gz_stream *s;
-{
- int method; /* method byte */
- int flags; /* flags byte */
- uInt len;
- int c;
-
- /* Assure two bytes in the buffer so we can peek ahead -- handle case
- where first byte of header is at the end of the buffer after the last
- gzip segment */
- len = s->stream.avail_in;
- if (len < 2) {
- if (len) s->inbuf[0] = s->stream.next_in[0];
- errno = 0;
- len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
- if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
- s->stream.avail_in += len;
- s->stream.next_in = s->inbuf;
- if (s->stream.avail_in < 2) {
- s->transparent = s->stream.avail_in;
- return;
- }
- }
-
- /* Peek ahead to check the gzip magic header */
- if (s->stream.next_in[0] != gz_magic[0] ||
- s->stream.next_in[1] != gz_magic[1]) {
- s->transparent = 1;
- return;
- }
- s->stream.avail_in -= 2;
- s->stream.next_in += 2;
-
- /* Check the rest of the gzip header */
- method = get_byte(s);
- flags = get_byte(s);
- if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
- s->z_err = Z_DATA_ERROR;
- return;
- }
-
- /* Discard time, xflags and OS code: */
- for (len = 0; len < 6; len++) (void)get_byte(s);
-
- if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
- len = (uInt)get_byte(s);
- len += ((uInt)get_byte(s))<<8;
- /* len is garbage if EOF but the loop below will quit anyway */
- while (len-- != 0 && get_byte(s) != EOF) ;
- }
- if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
- while ((c = get_byte(s)) != 0 && c != EOF) ;
- }
- if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
- while ((c = get_byte(s)) != 0 && c != EOF) ;
- }
- if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
- for (len = 0; len < 2; len++) (void)get_byte(s);
- }
- s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
-}
-
- /* ===========================================================================
- * Cleanup then free the given gz_stream. Return a zlib error code.
- Try freeing in the reverse order of allocations.
- */
-local int destroy (s)
- gz_stream *s;
-{
- int err = Z_OK;
-
- if (!s) return Z_STREAM_ERROR;
-
- TRYFREE(s->msg);
-
- if (s->stream.state != NULL) {
- if (s->mode == 'w') {
-#ifdef NO_GZCOMPRESS
- err = Z_STREAM_ERROR;
-#else
- err = deflateEnd(&(s->stream));
-#endif
- } else if (s->mode == 'r') {
- err = inflateEnd(&(s->stream));
- }
- }
- if (s->file != NULL && fclose(s->file)) {
-#ifdef ESPIPE
- if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
-#endif
- err = Z_ERRNO;
- }
- if (s->z_err < 0) err = s->z_err;
-
- TRYFREE(s->inbuf);
- TRYFREE(s->outbuf);
- TRYFREE(s->path);
- TRYFREE(s);
- return err;
-}
-
-/* ===========================================================================
- Reads the given number of uncompressed bytes from the compressed file.
- gzread returns the number of bytes actually read (0 for end of file).
-*/
-int ZEXPORT gzread (file, buf, len)
- gzFile file;
- voidp buf;
- unsigned len;
-{
- gz_stream *s = (gz_stream*)file;
- Bytef *start = (Bytef*)buf; /* starting point for crc computation */
- Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
-
- if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
-
- if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
- if (s->z_err == Z_STREAM_END) return 0; /* EOF */
-
- next_out = (Byte*)buf;
- s->stream.next_out = (Bytef*)buf;
- s->stream.avail_out = len;
-
- if (s->stream.avail_out && s->back != EOF) {
- *next_out++ = s->back;
- s->stream.next_out++;
- s->stream.avail_out--;
- s->back = EOF;
- s->out++;
- start++;
- if (s->last) {
- s->z_err = Z_STREAM_END;
- return 1;
- }
- }
-
- while (s->stream.avail_out != 0) {
-
- if (s->transparent) {
- /* Copy first the lookahead bytes: */
- uInt n = s->stream.avail_in;
- if (n > s->stream.avail_out) n = s->stream.avail_out;
- if (n > 0) {
- zmemcpy(s->stream.next_out, s->stream.next_in, n);
- next_out += n;
- s->stream.next_out = next_out;
- s->stream.next_in += n;
- s->stream.avail_out -= n;
- s->stream.avail_in -= n;
- }
- if (s->stream.avail_out > 0) {
- s->stream.avail_out -=
- (uInt)fread(next_out, 1, s->stream.avail_out, s->file);
- }
- len -= s->stream.avail_out;
- s->in += len;
- s->out += len;
- if (len == 0) s->z_eof = 1;
- return (int)len;
- }
- if (s->stream.avail_in == 0 && !s->z_eof) {
-
- errno = 0;
- s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
- if (s->stream.avail_in == 0) {
- s->z_eof = 1;
- if (ferror(s->file)) {
- s->z_err = Z_ERRNO;
- break;
- }
- }
- s->stream.next_in = s->inbuf;
- }
- s->in += s->stream.avail_in;
- s->out += s->stream.avail_out;
- s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
- s->in -= s->stream.avail_in;
- s->out -= s->stream.avail_out;
-
- if (s->z_err == Z_STREAM_END) {
- /* Check CRC and original size */
- s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
- start = s->stream.next_out;
-
- if (getLong(s) != s->crc) {
- s->z_err = Z_DATA_ERROR;
- } else {
- (void)getLong(s);
- /* The uncompressed length returned by above getlong() may be
- * different from s->out in case of concatenated .gz files.
- * Check for such files:
- */
- check_header(s);
- if (s->z_err == Z_OK) {
- inflateReset(&(s->stream));
- s->crc = crc32(0L, Z_NULL, 0);
- }
- }
- }
- if (s->z_err != Z_OK || s->z_eof) break;
- }
- s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
-
- if (len == s->stream.avail_out &&
- (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO))
- return -1;
- return (int)(len - s->stream.avail_out);
-}
-
-
-/* ===========================================================================
- Reads one byte from the compressed file. gzgetc returns this byte
- or -1 in case of end of file or error.
-*/
-int ZEXPORT gzgetc(file)
- gzFile file;
-{
- unsigned char c;
-
- return gzread(file, &c, 1) == 1 ? c : -1;
-}
-
-
-/* ===========================================================================
- Push one byte back onto the stream.
-*/
-int ZEXPORT gzungetc(c, file)
- int c;
- gzFile file;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
- s->back = c;
- s->out--;
- s->last = (s->z_err == Z_STREAM_END);
- if (s->last) s->z_err = Z_OK;
- s->z_eof = 0;
- return c;
-}
-
-
-/* ===========================================================================
- Reads bytes from the compressed file until len-1 characters are
- read, or a newline character is read and transferred to buf, or an
- end-of-file condition is encountered. The string is then terminated
- with a null character.
- gzgets returns buf, or Z_NULL in case of error.
-
- The current implementation is not optimized at all.
-*/
-char * ZEXPORT gzgets(file, buf, len)
- gzFile file;
- char *buf;
- int len;
-{
- char *b = buf;
- if (buf == Z_NULL || len <= 0) return Z_NULL;
-
- while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
- *buf = '\0';
- return b == buf && len > 0 ? Z_NULL : b;
-}
-
-
-#ifndef NO_GZCOMPRESS
-/* ===========================================================================
- Writes the given number of uncompressed bytes into the compressed file.
- gzwrite returns the number of bytes actually written (0 in case of error).
-*/
-int ZEXPORT gzwrite (file, buf, len)
- gzFile file;
- voidpc buf;
- unsigned len;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
-
- s->stream.next_in = (Bytef*)buf;
- s->stream.avail_in = len;
-
- while (s->stream.avail_in != 0) {
-
- if (s->stream.avail_out == 0) {
-
- s->stream.next_out = s->outbuf;
- if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
- s->z_err = Z_ERRNO;
- break;
- }
- s->stream.avail_out = Z_BUFSIZE;
- }
- s->in += s->stream.avail_in;
- s->out += s->stream.avail_out;
- s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
- s->in -= s->stream.avail_in;
- s->out -= s->stream.avail_out;
- if (s->z_err != Z_OK) break;
- }
- s->crc = crc32(s->crc, (const Bytef *)buf, len);
-
- return (int)(len - s->stream.avail_in);
-}
-
-
-/* ===========================================================================
- Converts, formats, and writes the args to the compressed file under
- control of the format string, as in fprintf. gzprintf returns the number of
- uncompressed bytes actually written (0 in case of error).
-*/
-#ifdef STDC
-#include <stdarg.h>
-
-int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
-{
- char buf[Z_PRINTF_BUFSIZE];
- va_list va;
- int len;
-
- buf[sizeof(buf) - 1] = 0;
- va_start(va, format);
-#ifdef NO_vsnprintf
-# ifdef HAS_vsprintf_void
- (void)vsprintf(buf, format, va);
- va_end(va);
- for (len = 0; len < sizeof(buf); len++)
- if (buf[len] == 0) break;
-# else
- len = vsprintf(buf, format, va);
- va_end(va);
-# endif
-#else
-# ifdef HAS_vsnprintf_void
- (void)vsnprintf(buf, sizeof(buf), format, va);
- va_end(va);
- len = strlen(buf);
-# else
- len = vsnprintf(buf, sizeof(buf), format, va);
- va_end(va);
-# endif
-#endif
- if (len <= 0 || len >= (int)sizeof(buf) || buf[sizeof(buf) - 1] != 0)
- return 0;
- return gzwrite(file, buf, (unsigned)len);
-}
-#else /* not ANSI C */
-
-int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
- a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
- gzFile file;
- const char *format;
- int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
- a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
-{
- char buf[Z_PRINTF_BUFSIZE];
- int len;
-
- buf[sizeof(buf) - 1] = 0;
-#ifdef NO_snprintf
-# ifdef HAS_sprintf_void
- sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
- for (len = 0; len < sizeof(buf); len++)
- if (buf[len] == 0) break;
-# else
- len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-# endif
-#else
-# ifdef HAS_snprintf_void
- snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
- len = strlen(buf);
-# else
- len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-# endif
-#endif
- if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
- return 0;
- return gzwrite(file, buf, len);
-}
-#endif
-
-/* ===========================================================================
- Writes c, converted to an unsigned char, into the compressed file.
- gzputc returns the value that was written, or -1 in case of error.
-*/
-int ZEXPORT gzputc(file, c)
- gzFile file;
- int c;
-{
- unsigned char cc = (unsigned char) c; /* required for big endian systems */
-
- return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
-}
-
-
-/* ===========================================================================
- Writes the given null-terminated string to the compressed file, excluding
- the terminating null character.
- gzputs returns the number of characters written, or -1 in case of error.
-*/
-int ZEXPORT gzputs(file, s)
- gzFile file;
- const char *s;
-{
- return gzwrite(file, (char*)s, (unsigned)strlen(s));
-}
-
-
-/* ===========================================================================
- Flushes all pending output into the compressed file. The parameter
- flush is as in the deflate() function.
-*/
-local int do_flush (file, flush)
- gzFile file;
- int flush;
-{
- uInt len;
- int done = 0;
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
-
- s->stream.avail_in = 0; /* should be zero already anyway */
-
- for (;;) {
- len = Z_BUFSIZE - s->stream.avail_out;
-
- if (len != 0) {
- if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
- s->z_err = Z_ERRNO;
- return Z_ERRNO;
- }
- s->stream.next_out = s->outbuf;
- s->stream.avail_out = Z_BUFSIZE;
- }
- if (done) break;
- s->out += s->stream.avail_out;
- s->z_err = deflate(&(s->stream), flush);
- s->out -= s->stream.avail_out;
-
- /* Ignore the second of two consecutive flushes: */
- if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
-
- /* deflate has finished flushing only when it hasn't used up
- * all the available space in the output buffer:
- */
- done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
-
- if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
- }
- return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
-}
-
-int ZEXPORT gzflush (file, flush)
- gzFile file;
- int flush;
-{
- gz_stream *s = (gz_stream*)file;
- int err = do_flush (file, flush);
-
- if (err) return err;
- fflush(s->file);
- return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
-}
-#endif /* NO_GZCOMPRESS */
-
-/* ===========================================================================
- Sets the starting position for the next gzread or gzwrite on the given
- compressed file. The offset represents a number of bytes in the
- gzseek returns the resulting offset location as measured in bytes from
- the beginning of the uncompressed stream, or -1 in case of error.
- SEEK_END is not implemented, returns error.
- In this version of the library, gzseek can be extremely slow.
-*/
-z_off_t ZEXPORT gzseek (file, offset, whence)
- gzFile file;
- z_off_t offset;
- int whence;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || whence == SEEK_END ||
- s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
- return -1L;
- }
-
- if (s->mode == 'w') {
-#ifdef NO_GZCOMPRESS
- return -1L;
-#else
- if (whence == SEEK_SET) {
- offset -= s->in;
- }
- if (offset < 0) return -1L;
-
- /* At this point, offset is the number of zero bytes to write. */
- if (s->inbuf == Z_NULL) {
- s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
- if (s->inbuf == Z_NULL) return -1L;
- zmemzero(s->inbuf, Z_BUFSIZE);
- }
- while (offset > 0) {
- uInt size = Z_BUFSIZE;
- if (offset < Z_BUFSIZE) size = (uInt)offset;
-
- size = gzwrite(file, s->inbuf, size);
- if (size == 0) return -1L;
-
- offset -= size;
- }
- return s->in;
-#endif
- }
- /* Rest of function is for reading only */
-
- /* compute absolute position */
- if (whence == SEEK_CUR) {
- offset += s->out;
- }
- if (offset < 0) return -1L;
-
- if (s->transparent) {
- /* map to fseek */
- s->back = EOF;
- s->stream.avail_in = 0;
- s->stream.next_in = s->inbuf;
- if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
-
- s->in = s->out = offset;
- return offset;
- }
-
- /* For a negative seek, rewind and use positive seek */
- if (offset >= s->out) {
- offset -= s->out;
- } else if (gzrewind(file) < 0) {
- return -1L;
- }
- /* offset is now the number of bytes to skip. */
-
- if (offset != 0 && s->outbuf == Z_NULL) {
- s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
- if (s->outbuf == Z_NULL) return -1L;
- }
- if (offset && s->back != EOF) {
- s->back = EOF;
- s->out++;
- offset--;
- if (s->last) s->z_err = Z_STREAM_END;
- }
- while (offset > 0) {
- int size = Z_BUFSIZE;
- if (offset < Z_BUFSIZE) size = (int)offset;
-
- size = gzread(file, s->outbuf, (uInt)size);
- if (size <= 0) return -1L;
- offset -= size;
- }
- return s->out;
-}
-
-/* ===========================================================================
- Rewinds input file.
-*/
-int ZEXPORT gzrewind (file)
- gzFile file;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || s->mode != 'r') return -1;
-
- s->z_err = Z_OK;
- s->z_eof = 0;
- s->back = EOF;
- s->stream.avail_in = 0;
- s->stream.next_in = s->inbuf;
- s->crc = crc32(0L, Z_NULL, 0);
- if (!s->transparent) (void)inflateReset(&s->stream);
- s->in = 0;
- s->out = 0;
- return fseek(s->file, s->start, SEEK_SET);
-}
-
-/* ===========================================================================
- Returns the starting position for the next gzread or gzwrite on the
- given compressed file. This position represents a number of bytes in the
- uncompressed data stream.
-*/
-z_off_t ZEXPORT gztell (file)
- gzFile file;
-{
- return gzseek(file, 0L, SEEK_CUR);
-}
-
-/* ===========================================================================
- Returns 1 when EOF has previously been detected reading the given
- input stream, otherwise zero.
-*/
-int ZEXPORT gzeof (file)
- gzFile file;
-{
- gz_stream *s = (gz_stream*)file;
-
- /* With concatenated compressed files that can have embedded
- * crc trailers, z_eof is no longer the only/best indicator of EOF
- * on a gz_stream. Handle end-of-stream error explicitly here.
- */
- if (s == NULL || s->mode != 'r') return 0;
- if (s->z_eof) return 1;
- return s->z_err == Z_STREAM_END;
-}
-
-/* ===========================================================================
- Returns 1 if reading and doing so transparently, otherwise zero.
-*/
-int ZEXPORT gzdirect (file)
- gzFile file;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL || s->mode != 'r') return 0;
- return s->transparent;
-}
-
-/* ===========================================================================
- Outputs a long in LSB order to the given file
-*/
-local void putLong (file, x)
- FILE *file;
- uLong x;
-{
- int n;
- for (n = 0; n < 4; n++) {
- fputc((int)(x & 0xff), file);
- x >>= 8;
- }
-}
-
-/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets z_err in case
- of error.
-*/
-local uLong getLong (s)
- gz_stream *s;
-{
- uLong x = (uLong)get_byte(s);
- int c;
-
- x += ((uLong)get_byte(s))<<8;
- x += ((uLong)get_byte(s))<<16;
- c = get_byte(s);
- if (c == EOF) s->z_err = Z_DATA_ERROR;
- x += ((uLong)c)<<24;
- return x;
-}
-
-/* ===========================================================================
- Flushes all pending output if necessary, closes the compressed file
- and deallocates all the (de)compression state.
-*/
-int ZEXPORT gzclose (file)
- gzFile file;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL) return Z_STREAM_ERROR;
-
- if (s->mode == 'w') {
-#ifdef NO_GZCOMPRESS
- return Z_STREAM_ERROR;
-#else
- if (do_flush (file, Z_FINISH) != Z_OK)
- return destroy((gz_stream*)file);
-
- putLong (s->file, s->crc);
- putLong (s->file, (uLong)(s->in & 0xffffffff));
-#endif
- }
- return destroy((gz_stream*)file);
-}
-
-#ifdef STDC
-# define zstrerror(errnum) strerror(errnum)
-#else
-# define zstrerror(errnum) ""
-#endif
-
-/* ===========================================================================
- Returns the error message for the last error which occurred on the
- given compressed file. errnum is set to zlib error number. If an
- error occurred in the file system and not in the compression library,
- errnum is set to Z_ERRNO and the application may consult errno
- to get the exact error code.
-*/
-const char * ZEXPORT gzerror (file, errnum)
- gzFile file;
- int *errnum;
-{
- char *m;
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL) {
- *errnum = Z_STREAM_ERROR;
- return (const char*)ERR_MSG(Z_STREAM_ERROR);
- }
- *errnum = s->z_err;
- if (*errnum == Z_OK) return (const char*)"";
-
- m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
-
- if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
-
- TRYFREE(s->msg);
- s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
- if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR);
- strcpy(s->msg, s->path);
- strcat(s->msg, ": ");
- strcat(s->msg, m);
- return (const char*)s->msg;
-}
-
-/* ===========================================================================
- Clear the error and end-of-file flags, and do the same for the real file.
-*/
-void ZEXPORT gzclearerr (file)
- gzFile file;
-{
- gz_stream *s = (gz_stream*)file;
-
- if (s == NULL) return;
- if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
- s->z_eof = 0;
- clearerr(s->file);
-}
diff --git a/cpukit/zlib/make_vms.com b/cpukit/zlib/make_vms.com
deleted file mode 100644
index 6576490e65..0000000000
--- a/cpukit/zlib/make_vms.com
+++ /dev/null
@@ -1,804 +0,0 @@
-$! make libz under VMS written by
-$! Martin P.J. Zinser
-$!
-$! In case of problems with the install you might contact me at
-$! zinser@zinser.no-ip.info(preferred) or
-$! zinser@sysdev.deutsche-boerse.com (work)
-$!
-$! Make procedure history for Zlib
-$!
-$!------------------------------------------------------------------------------
-$! Version history
-$! 0.01 20060120 First version to receive a number
-$! 0.02 20061008 Adapt to new Makefile.in
-$! 0.03 20091224 Add support for large file check
-$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite
-$! 0.05 20100221 Exchange zlibdefs.h by zconf.h.in
-$!
-$ on error then goto err_exit
-$ set proc/parse=ext
-$!
-$ true = 1
-$ false = 0
-$ tmpnam = "temp_" + f$getjpi("","pid")
-$ tt = tmpnam + ".txt"
-$ tc = tmpnam + ".c"
-$ th = tmpnam + ".h"
-$ define/nolog tconfig 'th'
-$ its_decc = false
-$ its_vaxc = false
-$ its_gnuc = false
-$ s_case = False
-$!
-$! Setup variables holding "config" information
-$!
-$ Make = ""
-$ name = "Zlib"
-$ version = "?.?.?"
-$ v_string = "ZLIB_VERSION"
-$ v_file = "zlib.h"
-$ ccopt = ""
-$ lopts = ""
-$ dnsrl = ""
-$ aconf_in_file = "zconf.h.in#zconf.h_in"
-$ conf_check_string = ""
-$ linkonly = false
-$ optfile = name + ".opt"
-$ libdefs = ""
-$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096
-$!
-$ whoami = f$parse(f$enviornment("Procedure"),,,,"NO_CONCEAL")
-$ mydef = F$parse(whoami,,,"DEVICE")
-$ mydir = f$parse(whoami,,,"DIRECTORY") - "]["
-$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type")
-$!
-$! Check for MMK/MMS
-$!
-$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS"
-$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK"
-$!
-$!
-$ gosub find_version
-$!
-$ open/write topt tmp.opt
-$ open/write optf 'optfile'
-$!
-$ gosub check_opts
-$!
-$! Look for the compiler used
-$!
-$ gosub check_compiler
-$ close topt
-$!
-$ if its_decc
-$ then
-$ ccopt = "/prefix=all" + ccopt
-$ if f$trnlnm("SYS") .eqs. ""
-$ then
-$ if axp
-$ then
-$ define sys sys$library:
-$ else
-$ ccopt = "/decc" + ccopt
-$ define sys decc$library_include:
-$ endif
-$ endif
-$ endif
-$ if its_vaxc .or. its_gnuc
-$ then
-$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
-$ endif
-$!
-$! Build a fake configure input header
-$!
-$ open/write conf_hin config.hin
-$ write conf_hin "#undef _LARGEFILE64_SOURCE"
-$ close conf_hin
-$!
-$!
-$ i = 0
-$FIND_ACONF:
-$ fname = f$element(i,"#",aconf_in_file)
-$ if fname .eqs. "#" then goto AMISS_ERR
-$ if f$search(fname) .eqs. ""
-$ then
-$ i = i + 1
-$ goto find_aconf
-$ endif
-$ open/read/err=aconf_err aconf_in 'fname'
-$ open/write aconf zconf.h
-$ACONF_LOOP:
-$ read/end_of_file=aconf_exit aconf_in line
-$ work = f$edit(line, "compress,trim")
-$ if f$extract(0,6,work) .nes. "#undef"
-$ then
-$ if f$extract(0,12,work) .nes. "#cmakedefine"
-$ then
-$ write aconf line
-$ endif
-$ else
-$ cdef = f$element(1," ",work)
-$ gosub check_config
-$ endif
-$ goto aconf_loop
-$ACONF_EXIT:
-$ write aconf "#define VMS 1"
-$ write aconf "#include <unistd.h>"
-$ write aconf "#include <unixio.h>"
-$ write aconf "#ifdef _LARGEFILE"
-$ write aconf "#define off64_t __off64_t"
-$ write aconf "#define fopen64 fopen"
-$ write aconf "#define fseeko64 fseeko"
-$ write aconf "#define lseek64 lseek"
-$ write aconf "#define ftello64 ftell"
-$ write aconf "#endif"
-$ close aconf_in
-$ close aconf
-$ if f$search("''th'") .nes. "" then delete 'th';*
-$! Build the thing plain or with mms
-$!
-$ write sys$output "Compiling Zlib sources ..."
-$ if make.eqs.""
-$ then
-$ dele example.obj;*,minigzip.obj;*
-$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" -
- adler32.c zlib.h zconf.h
-$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" -
- compress.c zlib.h zconf.h
-$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
- crc32.c zlib.h zconf.h
-$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
- deflate.c deflate.h zutil.h zlib.h zconf.h
-$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" -
- gzclose.c zutil.h zlib.h zconf.h
-$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" -
- gzlib.c zutil.h zlib.h zconf.h
-$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" -
- gzread.c zutil.h zlib.h zconf.h
-$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" -
- gzwrite.c zutil.h zlib.h zconf.h
-$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" -
- infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
-$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
- inffast.c zutil.h zlib.h zconf.h inffast.h
-$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" -
- inflate.c zutil.h zlib.h zconf.h infblock.h
-$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" -
- inftrees.c zutil.h zlib.h zconf.h inftrees.h
-$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" -
- trees.c deflate.h zutil.h zlib.h zconf.h
-$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" -
- uncompr.c zlib.h zconf.h
-$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" -
- zutil.c zutil.h zlib.h zconf.h
-$ write sys$output "Building Zlib ..."
-$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ
-$ write sys$output "Building example..."
-$ CALL MAKE example.OBJ "CC ''CCOPT' example" -
- example.c zlib.h zconf.h
-$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb
-$ if f$search("x11vms:xvmsutils.olb") .nes. ""
-$ then
-$ write sys$output "Building minigzip..."
-$ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" -
- minigzip.c zlib.h zconf.h
-$ call make minigzip.exe -
- "LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" -
- minigzip.obj libz.olb
-$ endif
-$ else
-$ gosub crea_mms
-$ write sys$output "Make ''name' ''version' with ''Make' "
-$ 'make'
-$ endif
-$!
-$! Alpha gets a shareable image
-$!
-$ If axp
-$ Then
-$ gosub crea_olist
-$ write sys$output "Creating libzshr.exe"
-$ call anal_obj_axp modules.opt _link.opt
-$ if s_case
-$ then
-$ open/append optf modules.opt
-$ write optf "case_sensitive=YES"
-$ close optf
-$ endif
-$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,_link.opt/opt
-$ endif
-$ write sys$output "Zlib build completed"
-$ exit
-$CC_ERR:
-$ write sys$output "C compiler required to build ''name'"
-$ goto err_exit
-$ERR_EXIT:
-$ set message/facil/ident/sever/text
-$ close/nolog optf
-$ close/nolog topt
-$ close/nolog conf_hin
-$ close/nolog aconf_in
-$ close/nolog aconf
-$ close/nolog out
-$ close/nolog min
-$ close/nolog mod
-$ close/nolog h_in
-$ write sys$output "Exiting..."
-$ exit 2
-$!
-$!
-$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
-$ V = 'F$Verify(0)
-$! P1 = What we are trying to make
-$! P2 = Command to make it
-$! P3 - P8 What it depends on
-$
-$ If F$Search(P1) .Eqs. "" Then Goto Makeit
-$ Time = F$CvTime(F$File(P1,"RDT"))
-$arg=3
-$Loop:
-$ Argument = P'arg
-$ If Argument .Eqs. "" Then Goto Exit
-$ El=0
-$Loop2:
-$ File = F$Element(El," ",Argument)
-$ If File .Eqs. " " Then Goto Endl
-$ AFile = ""
-$Loop3:
-$ OFile = AFile
-$ AFile = F$Search(File)
-$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
-$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
-$ Goto Loop3
-$NextEL:
-$ El = El + 1
-$ Goto Loop2
-$EndL:
-$ arg=arg+1
-$ If arg .Le. 8 Then Goto Loop
-$ Goto Exit
-$
-$Makeit:
-$ VV=F$VERIFY(0)
-$ write sys$output P2
-$ 'P2
-$ VV='F$Verify(VV)
-$Exit:
-$ If V Then Set Verify
-$ENDSUBROUTINE
-$!------------------------------------------------------------------------------
-$!
-$! Check command line options and set symbols accordingly
-$!
-$!------------------------------------------------------------------------------
-$! Version history
-$! 0.01 20041206 First version to receive a number
-$! 0.02 20060126 Add new "HELP" target
-$ CHECK_OPTS:
-$ i = 1
-$ OPT_LOOP:
-$ if i .lt. 9
-$ then
-$ cparm = f$edit(p'i',"upcase")
-$!
-$! Check if parameter actually contains something
-$!
-$ if f$edit(cparm,"trim") .nes. ""
-$ then
-$ if cparm .eqs. "DEBUG"
-$ then
-$ ccopt = ccopt + "/noopt/deb"
-$ lopts = lopts + "/deb"
-$ endif
-$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm)
-$ then
-$ start = f$locate("=",cparm) + 1
-$ len = f$length(cparm) - start
-$ ccopt = ccopt + f$extract(start,len,cparm)
-$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) -
- then s_case = true
-$ endif
-$ if cparm .eqs. "LINK" then linkonly = true
-$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm)
-$ then
-$ start = f$locate("=",cparm) + 1
-$ len = f$length(cparm) - start
-$ lopts = lopts + f$extract(start,len,cparm)
-$ endif
-$ if f$locate("CC=",cparm) .lt. f$length(cparm)
-$ then
-$ start = f$locate("=",cparm) + 1
-$ len = f$length(cparm) - start
-$ cc_com = f$extract(start,len,cparm)
- if (cc_com .nes. "DECC") .and. -
- (cc_com .nes. "VAXC") .and. -
- (cc_com .nes. "GNUC")
-$ then
-$ write sys$output "Unsupported compiler choice ''cc_com' ignored"
-$ write sys$output "Use DECC, VAXC, or GNUC instead"
-$ else
-$ if cc_com .eqs. "DECC" then its_decc = true
-$ if cc_com .eqs. "VAXC" then its_vaxc = true
-$ if cc_com .eqs. "GNUC" then its_gnuc = true
-$ endif
-$ endif
-$ if f$locate("MAKE=",cparm) .lt. f$length(cparm)
-$ then
-$ start = f$locate("=",cparm) + 1
-$ len = f$length(cparm) - start
-$ mmks = f$extract(start,len,cparm)
-$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS")
-$ then
-$ make = mmks
-$ else
-$ write sys$output "Unsupported make choice ''mmks' ignored"
-$ write sys$output "Use MMK or MMS instead"
-$ endif
-$ endif
-$ if cparm .eqs. "HELP" then gosub bhelp
-$ endif
-$ i = i + 1
-$ goto opt_loop
-$ endif
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Look for the compiler used
-$!
-$! Version history
-$! 0.01 20040223 First version to receive a number
-$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists
-$! 0.03 20060202 Extend handling of GNU C
-$! 0.04 20090402 Compaq -> hp
-$CHECK_COMPILER:
-$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc))
-$ then
-$ its_decc = (f$search("SYS$SYSTEM:DECC$COMPILER.EXE") .nes. "")
-$ its_vaxc = .not. its_decc .and. (F$Search("SYS$System:VAXC.Exe") .nes. "")
-$ its_gnuc = .not. (its_decc .or. its_vaxc) .and. (f$trnlnm("gnu_cc") .nes. "")
-$ endif
-$!
-$! Exit if no compiler available
-$!
-$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc))
-$ then goto CC_ERR
-$ else
-$ if its_decc
-$ then
-$ write sys$output "CC compiler check ... hp C"
-$ if f$trnlnm("decc$no_rooted_search_lists") .nes. ""
-$ then
-$ dnrsl = f$trnlnm("decc$no_rooted_search_lists")
-$ endif
-$ define/nolog decc$no_rooted_search_lists 1
-$ else
-$ if its_vaxc then write sys$output "CC compiler check ... VAX C"
-$ if its_gnuc
-$ then
-$ write sys$output "CC compiler check ... GNU C"
-$ if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib"
-$ if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib"
-$ cc = "gcc"
-$ endif
-$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share"
-$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share"
-$ endif
-$ endif
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! If MMS/MMK are available dump out the descrip.mms if required
-$!
-$CREA_MMS:
-$ write sys$output "Creating descrip.mms..."
-$ create descrip.mms
-$ open/append out descrip.mms
-$ copy sys$input: out
-$ deck
-# descrip.mms: MMS description file for building zlib on VMS
-# written by Martin P.J. Zinser
-# <zinser@zinser.no-ip.info or zinser@sysdev.deutsche-boerse.com>
-
-OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\
- gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\
- deflate.obj, trees.obj, zutil.obj, inflate.obj, \
- inftrees.obj, inffast.obj
-
-$ eod
-$ write out "CFLAGS=", ccopt
-$ write out "LOPTS=", lopts
-$ copy sys$input: out
-$ deck
-
-all : example.exe minigzip.exe libz.olb
- @ write sys$output " Example applications available"
-
-libz.olb : libz.olb($(OBJS))
- @ write sys$output " libz available"
-
-example.exe : example.obj libz.olb
- link $(LOPTS) example,libz.olb/lib
-
-minigzip.exe : minigzip.obj libz.olb
- link $(LOPTS) minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib
-
-clean :
- delete *.obj;*,libz.olb;*,*.opt;*,*.exe;*
-
-
-# Other dependencies.
-adler32.obj : adler32.c zutil.h zlib.h zconf.h
-compress.obj : compress.c zlib.h zconf.h
-crc32.obj : crc32.c zutil.h zlib.h zconf.h
-deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h
-example.obj : example.c zlib.h zconf.h
-gzclose.obj : gzclose.c zutil.h zlib.h zconf.h
-gzlib.obj : gzlib.c zutil.h zlib.h zconf.h
-gzread.obj : gzread.c zutil.h zlib.h zconf.h
-gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h
-inffast.obj : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h
-inflate.obj : inflate.c zutil.h zlib.h zconf.h
-inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h
-minigzip.obj : minigzip.c zlib.h zconf.h
-trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h
-uncompr.obj : uncompr.c zlib.h zconf.h
-zutil.obj : zutil.c zutil.h zlib.h zconf.h
-infback.obj : infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
-$ eod
-$ close out
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Read list of core library sources from makefile.in and create options
-$! needed to build shareable image
-$!
-$CREA_OLIST:
-$ open/read min makefile.in
-$ open/write mod modules.opt
-$ src_check = "OBJC ="
-$MRLOOP:
-$ read/end=mrdone min rec
-$ if (f$extract(0,6,rec) .nes. src_check) then goto mrloop
-$ rec = rec - src_check
-$ gosub extra_filnam
-$ if (f$element(1,"\",rec) .eqs. "\") then goto mrdone
-$MRSLOOP:
-$ read/end=mrdone min rec
-$ gosub extra_filnam
-$ if (f$element(1,"\",rec) .nes. "\") then goto mrsloop
-$MRDONE:
-$ close min
-$ close mod
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Take record extracted in crea_olist and split it into single filenames
-$!
-$EXTRA_FILNAM:
-$ myrec = f$edit(rec - "\", "trim,compress")
-$ i = 0
-$FELOOP:
-$ srcfil = f$element(i," ", myrec)
-$ if (srcfil .nes. " ")
-$ then
-$ write mod f$parse(srcfil,,,"NAME"), ".obj"
-$ i = i + 1
-$ goto feloop
-$ endif
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Find current Zlib version number
-$!
-$FIND_VERSION:
-$ open/read h_in 'v_file'
-$hloop:
-$ read/end=hdone h_in rec
-$ rec = f$edit(rec,"TRIM")
-$ if (f$extract(0,1,rec) .nes. "#") then goto hloop
-$ rec = f$edit(rec - "#", "TRIM")
-$ if f$element(0," ",rec) .nes. "define" then goto hloop
-$ if f$element(1," ",rec) .eqs. v_string
-$ then
-$ version = 'f$element(2," ",rec)'
-$ goto hdone
-$ endif
-$ goto hloop
-$hdone:
-$ close h_in
-$ return
-$!------------------------------------------------------------------------------
-$!
-$CHECK_CONFIG:
-$!
-$ in_ldef = f$locate(cdef,libdefs)
-$ if (in_ldef .lt. f$length(libdefs))
-$ then
-$ write aconf "#define ''cdef' 1"
-$ libdefs = f$extract(0,in_ldef,libdefs) + -
- f$extract(in_ldef + f$length(cdef) + 1, -
- f$length(libdefs) - in_ldef - f$length(cdef) - 1, -
- libdefs)
-$ else
-$ if (f$type('cdef') .eqs. "INTEGER")
-$ then
-$ write aconf "#define ''cdef' ", 'cdef'
-$ else
-$ if (f$type('cdef') .eqs. "STRING")
-$ then
-$ write aconf "#define ''cdef' ", """", '''cdef'', """"
-$ else
-$ gosub check_cc_def
-$ endif
-$ endif
-$ endif
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Check if this is a define relating to the properties of the C/C++
-$! compiler
-$!
-$ CHECK_CC_DEF:
-$ if (cdef .eqs. "_LARGEFILE64_SOURCE")
-$ then
-$ copy sys$input: 'tc'
-$ deck
-#include "tconfig"
-#define _LARGEFILE
-#include <stdio.h>
-
-int main(){
-FILE *fp;
- fp = fopen("temp.txt","r");
- fseeko(fp,1,SEEK_SET);
- fclose(fp);
-}
-
-$ eod
-$ test_inv = false
-$ comm_h = false
-$ gosub cc_prop_check
-$ return
-$ endif
-$ write aconf "/* ", line, " */"
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Check for properties of C/C++ compiler
-$!
-$! Version history
-$! 0.01 20031020 First version to receive a number
-$! 0.02 20031022 Added logic for defines with value
-$! 0.03 20040309 Make sure local config file gets not deleted
-$! 0.04 20041230 Also write include for configure run
-$! 0.05 20050103 Add processing of "comment defines"
-$CC_PROP_CHECK:
-$ cc_prop = true
-$ is_need = false
-$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true)
-$ if f$search(th) .eqs. "" then create 'th'
-$ set message/nofac/noident/nosever/notext
-$ on error then continue
-$ cc 'tmpnam'
-$ if .not. ($status) then cc_prop = false
-$ on error then continue
-$! The headers might lie about the capabilities of the RTL
-$ link 'tmpnam',tmp.opt/opt
-$ if .not. ($status) then cc_prop = false
-$ set message/fac/ident/sever/text
-$ on error then goto err_exit
-$ delete/nolog 'tmpnam'.*;*/exclude='th'
-$ if (cc_prop .and. .not. is_need) .or. -
- (.not. cc_prop .and. is_need)
-$ then
-$ write sys$output "Checking for ''cdef'... yes"
-$ if f$type('cdef_val'_yes) .nes. ""
-$ then
-$ if f$type('cdef_val'_yes) .eqs. "INTEGER" -
- then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes)
-$ if f$type('cdef_val'_yes) .eqs. "STRING" -
- then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes)
-$ else
-$ call write_config f$fao("#define !AS 1",cdef)
-$ endif
-$ if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. -
- (cdef .eqs. "_LARGEFILE64_SOURCE") then -
- call write_config f$string("#define _LARGEFILE 1")
-$ else
-$ write sys$output "Checking for ''cdef'... no"
-$ if (comm_h)
-$ then
- call write_config f$fao("/* !AS */",line)
-$ else
-$ if f$type('cdef_val'_no) .nes. ""
-$ then
-$ if f$type('cdef_val'_no) .eqs. "INTEGER" -
- then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no)
-$ if f$type('cdef_val'_no) .eqs. "STRING" -
- then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no)
-$ else
-$ call write_config f$fao("#undef !AS",cdef)
-$ endif
-$ endif
-$ endif
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Check for properties of C/C++ compiler with multiple result values
-$!
-$! Version history
-$! 0.01 20040127 First version
-$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05
-$CC_MPROP_CHECK:
-$ cc_prop = true
-$ i = 1
-$ idel = 1
-$ MT_LOOP:
-$ if f$type(result_'i') .eqs. "STRING"
-$ then
-$ set message/nofac/noident/nosever/notext
-$ on error then continue
-$ cc 'tmpnam'_'i'
-$ if .not. ($status) then cc_prop = false
-$ on error then continue
-$! The headers might lie about the capabilities of the RTL
-$ link 'tmpnam'_'i',tmp.opt/opt
-$ if .not. ($status) then cc_prop = false
-$ set message/fac/ident/sever/text
-$ on error then goto err_exit
-$ delete/nolog 'tmpnam'_'i'.*;*
-$ if (cc_prop)
-$ then
-$ write sys$output "Checking for ''cdef'... ", mdef_'i'
-$ if f$type(mdef_'i') .eqs. "INTEGER" -
- then call write_config f$fao("#define !AS !UL",cdef,mdef_'i')
-$ if f$type('cdef_val'_yes) .eqs. "STRING" -
- then call write_config f$fao("#define !AS !AS",cdef,mdef_'i')
-$ goto msym_clean
-$ else
-$ i = i + 1
-$ goto mt_loop
-$ endif
-$ endif
-$ write sys$output "Checking for ''cdef'... no"
-$ call write_config f$fao("#undef !AS",cdef)
-$ MSYM_CLEAN:
-$ if (idel .le. msym_max)
-$ then
-$ delete/sym mdef_'idel'
-$ idel = idel + 1
-$ goto msym_clean
-$ endif
-$ return
-$!------------------------------------------------------------------------------
-$!
-$! Analyze Object files for OpenVMS AXP to extract Procedure and Data
-$! information to build a symbol vector for a shareable image
-$! All the "brains" of this logic was suggested by Hartmut Becker
-$! (Hartmut.Becker@compaq.com). All the bugs were introduced by me
-$! (zinser@zinser.no-ip.info), so if you do have problem reports please do not
-$! bother Hartmut/HP, but get in touch with me
-$!
-$! Version history
-$! 0.01 20040406 Skip over shareable images in option file
-$! 0.02 20041109 Fix option file for shareable images with case_sensitive=YES
-$! 0.03 20050107 Skip over Identification labels in option file
-$! 0.04 20060117 Add uppercase alias to code compiled with /name=as_is
-$!
-$ ANAL_OBJ_AXP: Subroutine
-$ V = 'F$Verify(0)
-$ SAY := "WRITE_ SYS$OUTPUT"
-$
-$ IF F$SEARCH("''P1'") .EQS. ""
-$ THEN
-$ SAY "ANAL_OBJ_AXP-E-NOSUCHFILE: Error, inputfile ''p1' not available"
-$ goto exit_aa
-$ ENDIF
-$ IF "''P2'" .EQS. ""
-$ THEN
-$ SAY "ANAL_OBJ_AXP: Error, no output file provided"
-$ goto exit_aa
-$ ENDIF
-$
-$ open/read in 'p1
-$ create a.tmp
-$ open/append atmp a.tmp
-$ loop:
-$ read/end=end_loop in line
-$ if f$locate("/SHARE",f$edit(line,"upcase")) .lt. f$length(line)
-$ then
-$ write sys$output "ANAL_SKP_SHR-i-skipshare, ''line'"
-$ goto loop
-$ endif
-$ if f$locate("IDENTIFICATION=",f$edit(line,"upcase")) .lt. f$length(line)
-$ then
-$ write sys$output "ANAL_OBJ_AXP-i-ident: Identification ", -
- f$element(1,"=",line)
-$ goto loop
-$ endif
-$ f= f$search(line)
-$ if f .eqs. ""
-$ then
-$ write sys$output "ANAL_OBJ_AXP-w-nosuchfile, ''line'"
-$ goto loop
-$ endif
-$ define/user sys$output nl:
-$ define/user sys$error nl:
-$ anal/obj/gsd 'f /out=x.tmp
-$ open/read xtmp x.tmp
-$ XLOOP:
-$ read/end=end_xloop xtmp xline
-$ xline = f$edit(xline,"compress")
-$ write atmp xline
-$ goto xloop
-$ END_XLOOP:
-$ close xtmp
-$ goto loop
-$ end_loop:
-$ close in
-$ close atmp
-$ if f$search("a.tmp") .eqs. "" -
- then $ exit
-$ ! all global definitions
-$ search a.tmp "symbol:","EGSY$V_DEF 1","EGSY$V_NORM 1"/out=b.tmp
-$ ! all procedures
-$ search b.tmp "EGSY$V_NORM 1"/wind=(0,1) /out=c.tmp
-$ search c.tmp "symbol:"/out=d.tmp
-$ define/user sys$output nl:
-$ edito/edt/command=sys$input d.tmp
-sub/symbol: "/symbol_vector=(/whole
-sub/"/=PROCEDURE)/whole
-exit
-$ ! all data
-$ search b.tmp "EGSY$V_DEF 1"/wind=(0,1) /out=e.tmp
-$ search e.tmp "symbol:"/out=f.tmp
-$ define/user sys$output nl:
-$ edito/edt/command=sys$input f.tmp
-sub/symbol: "/symbol_vector=(/whole
-sub/"/=DATA)/whole
-exit
-$ sort/nodupl d.tmp,f.tmp g.tmp
-$ open/read raw_vector g.tmp
-$ open/write case_vector 'p2'
-$ RAWLOOP:
-$ read/end=end_rawloop raw_vector raw_element
-$ write case_vector raw_element
-$ if f$locate("=PROCEDURE)",raw_element) .lt. f$length(raw_element)
-$ then
-$ name = f$element(1,"=",raw_element) - "("
-$ if f$edit(name,"UPCASE") .nes. name then -
- write case_vector f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)", -
- f$edit(name,"UPCASE"), name)
-$ endif
-$ if f$locate("=DATA)",raw_element) .lt. f$length(raw_element)
-$ then
-$ name = f$element(1,"=",raw_element) - "("
-$ if f$edit(name,"UPCASE") .nes. name then -
- write case_vector f$fao(" symbol_vector=(!AS/!AS=DATA)", -
- f$edit(name,"UPCASE"), name)
-$ endif
-$ goto rawloop
-$ END_RAWLOOP:
-$ close raw_vector
-$ close case_vector
-$ delete a.tmp;*,b.tmp;*,c.tmp;*,d.tmp;*,e.tmp;*,f.tmp;*,g.tmp;*
-$ if f$search("x.tmp") .nes. "" -
- then $ delete x.tmp;*
-$!
-$ EXIT_AA:
-$ if V then set verify
-$ endsubroutine
-$!------------------------------------------------------------------------------
-$!
-$! Write configuration to both permanent and temporary config file
-$!
-$! Version history
-$! 0.01 20031029 First version to receive a number
-$!
-$WRITE_CONFIG: SUBROUTINE
-$ write aconf 'p1'
-$ open/append confh 'th'
-$ write confh 'p1'
-$ close confh
-$ENDSUBROUTINE
-$!------------------------------------------------------------------------------
diff --git a/cpukit/zlib/minigzip.c b/cpukit/zlib/minigzip.c
deleted file mode 100644
index 84d823b72f..0000000000
--- a/cpukit/zlib/minigzip.c
+++ /dev/null
@@ -1,435 +0,0 @@
-/* minigzip.c -- simulate gzip using the zlib compression library
- * Copyright (C) 1995-2006, 2010 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- * minigzip is a minimal implementation of the gzip utility. This is
- * only an example of using zlib and isn't meant to replace the
- * full-featured gzip. No attempt is made to deal with file systems
- * limiting names to 14 or 8+3 characters, etc... Error checking is
- * very limited. So use minigzip only for testing; use gzip for the
- * real thing. On MSDOS, use only on file names without extension
- * or in pipe mode.
- */
-
-/* @(#) $Id$ */
-
-#include "zlib.h"
-#include <stdio.h>
-
-#ifdef STDC
-# include <string.h>
-# include <stdlib.h>
-#endif
-
-#ifdef USE_MMAP
-# include <sys/types.h>
-# include <sys/mman.h>
-# include <sys/stat.h>
-#endif
-
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-# include <fcntl.h>
-# include <io.h>
-# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-# define SET_BINARY_MODE(file)
-#endif
-
-#ifdef VMS
-# define unlink delete
-# define GZ_SUFFIX "-gz"
-#endif
-#ifdef RISCOS
-# define unlink remove
-# define GZ_SUFFIX "-gz"
-# define fileno(file) file->__file
-#endif
-#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-# include <unix.h> /* for fileno */
-#endif
-
-#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
- extern int unlink OF((const char *));
-#endif
-
-#if defined(UNDER_CE) && defined(NO_ERRNO_H)
-# include <windows.h>
-# define perror(s) pwinerror(s)
-
-/* Map the Windows error number in ERROR to a locale-dependent error
- message string and return a pointer to it. Typically, the values
- for ERROR come from GetLastError.
-
- The string pointed to shall not be modified by the application,
- but may be overwritten by a subsequent call to strwinerror
-
- The strwinerror function does not change the current setting
- of GetLastError. */
-
-static char *strwinerror (error)
- DWORD error;
-{
- static char buf[1024];
-
- wchar_t *msgbuf;
- DWORD lasterr = GetLastError();
- DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
- | FORMAT_MESSAGE_ALLOCATE_BUFFER,
- NULL,
- error,
- 0, /* Default language */
- (LPVOID)&msgbuf,
- 0,
- NULL);
- if (chars != 0) {
- /* If there is an \r\n appended, zap it. */
- if (chars >= 2
- && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
- chars -= 2;
- msgbuf[chars] = 0;
- }
-
- if (chars > sizeof (buf) - 1) {
- chars = sizeof (buf) - 1;
- msgbuf[chars] = 0;
- }
-
- wcstombs(buf, msgbuf, chars + 1);
- LocalFree(msgbuf);
- }
- else {
- sprintf(buf, "unknown win32 error (%ld)", error);
- }
-
- SetLastError(lasterr);
- return buf;
-}
-
-static void pwinerror (s)
- const char *s;
-{
- if (s && *s)
- fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ()));
- else
- fprintf(stderr, "%s\n", strwinerror(GetLastError ()));
-}
-
-#endif /* UNDER_CE && NO_ERRNO_H */
-
-#ifndef GZ_SUFFIX
-# define GZ_SUFFIX ".gz"
-#endif
-#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
-
-#define BUFLEN 16384
-#define MAX_NAME_LEN 1024
-
-#ifdef MAXSEG_64K
-# define local static
- /* Needed for systems with limitation on stack size. */
-#else
-# define local
-#endif
-
-char *prog;
-
-void error OF((const char *msg));
-void gz_compress OF((FILE *in, gzFile out));
-#ifdef USE_MMAP
-int gz_compress_mmap OF((FILE *in, gzFile out));
-#endif
-void gz_uncompress OF((gzFile in, FILE *out));
-void file_compress OF((char *file, char *mode));
-void file_uncompress OF((char *file));
-int main OF((int argc, char *argv[]));
-
-/* ===========================================================================
- * Display error message and exit
- */
-void error(msg)
- const char *msg;
-{
- fprintf(stderr, "%s: %s\n", prog, msg);
- exit(1);
-}
-
-/* ===========================================================================
- * Compress input to output then close both files.
- */
-
-void gz_compress(in, out)
- FILE *in;
- gzFile out;
-{
- local char buf[BUFLEN];
- int len;
- int err;
-
-#ifdef USE_MMAP
- /* Try first compressing with mmap. If mmap fails (minigzip used in a
- * pipe), use the normal fread loop.
- */
- if (gz_compress_mmap(in, out) == Z_OK) return;
-#endif
- for (;;) {
- len = (int)fread(buf, 1, sizeof(buf), in);
- if (ferror(in)) {
- perror("fread");
- exit(1);
- }
- if (len == 0) break;
-
- if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
- }
- fclose(in);
- if (gzclose(out) != Z_OK) error("failed gzclose");
-}
-
-#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
-
-/* Try compressing the input file at once using mmap. Return Z_OK if
- * if success, Z_ERRNO otherwise.
- */
-int gz_compress_mmap(in, out)
- FILE *in;
- gzFile out;
-{
- int len;
- int err;
- int ifd = fileno(in);
- caddr_t buf; /* mmap'ed buffer for the entire input file */
- off_t buf_len; /* length of the input file */
- struct stat sb;
-
- /* Determine the size of the file, needed for mmap: */
- if (fstat(ifd, &sb) < 0) return Z_ERRNO;
- buf_len = sb.st_size;
- if (buf_len <= 0) return Z_ERRNO;
-
- /* Now do the actual mmap: */
- buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
- if (buf == (caddr_t)(-1)) return Z_ERRNO;
-
- /* Compress the whole file at once: */
- len = gzwrite(out, (char *)buf, (unsigned)buf_len);
-
- if (len != (int)buf_len) error(gzerror(out, &err));
-
- munmap(buf, buf_len);
- fclose(in);
- if (gzclose(out) != Z_OK) error("failed gzclose");
- return Z_OK;
-}
-#endif /* USE_MMAP */
-
-/* ===========================================================================
- * Uncompress input to output then close both files.
- */
-void gz_uncompress(in, out)
- gzFile in;
- FILE *out;
-{
- local char buf[BUFLEN];
- int len;
- int err;
-
- for (;;) {
- len = gzread(in, buf, sizeof(buf));
- if (len < 0) error (gzerror(in, &err));
- if (len == 0) break;
-
- if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
- error("failed fwrite");
- }
- }
- if (fclose(out)) error("failed fclose");
-
- if (gzclose(in) != Z_OK) error("failed gzclose");
-}
-
-
-/* ===========================================================================
- * Compress the given file: create a corresponding .gz file and remove the
- * original.
- */
-void file_compress(file, mode)
- char *file;
- char *mode;
-{
- local char outfile[MAX_NAME_LEN];
- FILE *in;
- gzFile out;
-
- if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
- fprintf(stderr, "%s: filename too long\n", prog);
- exit(1);
- }
-
- strcpy(outfile, file);
- strcat(outfile, GZ_SUFFIX);
-
- in = fopen(file, "rb");
- if (in == NULL) {
- perror(file);
- exit(1);
- }
- out = gzopen(outfile, mode);
- if (out == NULL) {
- fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
- exit(1);
- }
- gz_compress(in, out);
-
- unlink(file);
-}
-
-
-/* ===========================================================================
- * Uncompress the given file and remove the original.
- */
-void file_uncompress(file)
- char *file;
-{
- local char buf[MAX_NAME_LEN];
- char *infile, *outfile;
- FILE *out;
- gzFile in;
- size_t len = strlen(file);
-
- if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
- fprintf(stderr, "%s: filename too long\n", prog);
- exit(1);
- }
-
- strcpy(buf, file);
-
- if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
- infile = file;
- outfile = buf;
- outfile[len-3] = '\0';
- } else {
- outfile = file;
- infile = buf;
- strcat(infile, GZ_SUFFIX);
- }
- in = gzopen(infile, "rb");
- if (in == NULL) {
- fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
- exit(1);
- }
- out = fopen(outfile, "wb");
- if (out == NULL) {
- perror(file);
- exit(1);
- }
-
- gz_uncompress(in, out);
-
- unlink(infile);
-}
-
-
-/* ===========================================================================
- * Usage: minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...]
- * -c : write to standard output
- * -d : decompress
- * -f : compress with Z_FILTERED
- * -h : compress with Z_HUFFMAN_ONLY
- * -r : compress with Z_RLE
- * -1 to -9 : compression level
- */
-
-int main(argc, argv)
- int argc;
- char *argv[];
-{
- int copyout = 0;
- int uncompr = 0;
- gzFile file;
- char *bname, outmode[20];
-
- strcpy(outmode, "wb6 ");
-
- prog = argv[0];
- bname = strrchr(argv[0], '/');
- if (bname)
- bname++;
- else
- bname = argv[0];
- argc--, argv++;
-
- if (!strcmp(bname, "gunzip"))
- uncompr = 1;
- else if (!strcmp(bname, "zcat"))
- copyout = uncompr = 1;
-
- while (argc > 0) {
- if (strcmp(*argv, "-c") == 0)
- copyout = 1;
- else if (strcmp(*argv, "-d") == 0)
- uncompr = 1;
- else if (strcmp(*argv, "-f") == 0)
- outmode[3] = 'f';
- else if (strcmp(*argv, "-h") == 0)
- outmode[3] = 'h';
- else if (strcmp(*argv, "-r") == 0)
- outmode[3] = 'R';
- else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
- (*argv)[2] == 0)
- outmode[2] = (*argv)[1];
- else
- break;
- argc--, argv++;
- }
- if (outmode[3] == ' ')
- outmode[3] = 0;
- if (argc == 0) {
- SET_BINARY_MODE(stdin);
- SET_BINARY_MODE(stdout);
- if (uncompr) {
- file = gzdopen(fileno(stdin), "rb");
- if (file == NULL) error("can't gzdopen stdin");
- gz_uncompress(file, stdout);
- } else {
- file = gzdopen(fileno(stdout), outmode);
- if (file == NULL) error("can't gzdopen stdout");
- gz_compress(stdin, file);
- }
- } else {
- if (copyout) {
- SET_BINARY_MODE(stdout);
- }
- do {
- if (uncompr) {
- if (copyout) {
- file = gzopen(*argv, "rb");
- if (file == NULL)
- fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
- else
- gz_uncompress(file, stdout);
- } else {
- file_uncompress(*argv);
- }
- } else {
- if (copyout) {
- FILE * in = fopen(*argv, "rb");
-
- if (in == NULL) {
- perror(*argv);
- } else {
- file = gzdopen(fileno(stdout), outmode);
- if (file == NULL) error("can't gzdopen stdout");
-
- gz_compress(in, file);
- }
-
- } else {
- file_compress(*argv, outmode);
- }
- }
- } while (argv++, --argc);
- }
- return 0;
-}
diff --git a/cpukit/zlib/msdos/Makefile.bor b/cpukit/zlib/msdos/Makefile.bor
deleted file mode 100644
index 0c1b99c9b9..0000000000
--- a/cpukit/zlib/msdos/Makefile.bor
+++ /dev/null
@@ -1,115 +0,0 @@
-# Makefile for zlib
-# Borland C++
-# Last updated: 15-Mar-2003
-
-# To use, do "make -fmakefile.bor"
-# To compile in small model, set below: MODEL=s
-
-# WARNING: the small model is supported but only for small values of
-# MAX_WBITS and MAX_MEM_LEVEL. For example:
-# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3
-# If you wish to reduce the memory requirements (default 256K for big
-# objects plus a few K), you can add to the LOC macro below:
-# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
-# See zconf.h for details about the memory requirements.
-
-# ------------ Turbo C++, Borland C++ ------------
-
-# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
-# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
-# to the declaration of LOC here:
-LOC = $(LOCAL_ZLIB)
-
-# type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
-CPU_TYP = 0
-
-# memory model: one of s, m, c, l (small, medium, compact, large)
-MODEL=l
-
-# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version
-CC=bcc
-LD=bcc
-AR=tlib
-
-# compiler flags
-# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0
-CFLAGS=-O2 -Z -m$(MODEL) $(LOC)
-
-LDFLAGS=-m$(MODEL) -f-
-
-
-# variables
-ZLIB_LIB = zlib_$(MODEL).lib
-
-OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj
-OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj
-OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
-
-
-# targets
-all: $(ZLIB_LIB) example.exe minigzip.exe
-
-.c.obj:
- $(CC) -c $(CFLAGS) $*.c
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-example.obj: example.c zlib.h zconf.h
-
-minigzip.obj: minigzip.c zlib.h zconf.h
-
-
-# the command line is cut to fit in the MS-DOS 128 byte limit:
-$(ZLIB_LIB): $(OBJ1) $(OBJ2)
- -del $(ZLIB_LIB)
- $(AR) $(ZLIB_LIB) $(OBJP1)
- $(AR) $(ZLIB_LIB) $(OBJP2)
-
-example.exe: example.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
-
-minigzip.exe: minigzip.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
-
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-clean:
- -del *.obj
- -del *.lib
- -del *.exe
- -del zlib_*.bak
- -del foo.gz
diff --git a/cpukit/zlib/msdos/Makefile.dj2 b/cpukit/zlib/msdos/Makefile.dj2
deleted file mode 100644
index 29b03954d7..0000000000
--- a/cpukit/zlib/msdos/Makefile.dj2
+++ /dev/null
@@ -1,104 +0,0 @@
-# Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96.
-# Copyright (C) 1995-1998 Jean-loup Gailly.
-# For conditions of distribution and use, see copyright notice in zlib.h
-
-# To compile, or to compile and test, type:
-#
-# make -fmakefile.dj2; make test -fmakefile.dj2
-#
-# To install libz.a, zconf.h and zlib.h in the djgpp directories, type:
-#
-# make install -fmakefile.dj2
-#
-# after first defining LIBRARY_PATH and INCLUDE_PATH in djgpp.env as
-# in the sample below if the pattern of the DJGPP distribution is to
-# be followed. Remember that, while <sp>'es around <=> are ignored in
-# makefiles, they are *not* in batch files or in djgpp.env.
-# - - - - -
-# [make]
-# INCLUDE_PATH=%\>;INCLUDE_PATH%%\DJDIR%\include
-# LIBRARY_PATH=%\>;LIBRARY_PATH%%\DJDIR%\lib
-# BUTT=-m486
-# - - - - -
-# Alternately, these variables may be defined below, overriding the values
-# in djgpp.env, as
-# INCLUDE_PATH=c:\usr\include
-# LIBRARY_PATH=c:\usr\lib
-
-CC=gcc
-
-#CFLAGS=-MMD -O
-#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
-#CFLAGS=-MMD -g -DDEBUG
-CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
- -Wstrict-prototypes -Wmissing-prototypes
-
-# If cp.exe is available, replace "copy /Y" with "cp -fp" .
-CP=copy /Y
-# If gnu install.exe is available, replace $(CP) with ginstall.
-INSTALL=$(CP)
-# The default value of RM is "rm -f." If "rm.exe" is found, comment out:
-RM=del
-LDLIBS=-L. -lz
-LD=$(CC) -s -o
-LDSHARED=$(CC)
-
-INCL=zlib.h zconf.h
-LIBS=libz.a
-
-AR=ar rcs
-
-prefix=/usr/local
-exec_prefix = $(prefix)
-
-OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \
- uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
-
-OBJA =
-# to use the asm code: make OBJA=match.o
-
-TEST_OBJS = example.o minigzip.o
-
-all: example.exe minigzip.exe
-
-check: test
-test: all
- ./example
- echo hello world | .\minigzip | .\minigzip -d
-
-%.o : %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-libz.a: $(OBJS) $(OBJA)
- $(AR) $@ $(OBJS) $(OBJA)
-
-%.exe : %.o $(LIBS)
- $(LD) $@ $< $(LDLIBS)
-
-# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env .
-
-.PHONY : uninstall clean
-
-install: $(INCL) $(LIBS)
- -@if not exist $(INCLUDE_PATH)\nul mkdir $(INCLUDE_PATH)
- -@if not exist $(LIBRARY_PATH)\nul mkdir $(LIBRARY_PATH)
- $(INSTALL) zlib.h $(INCLUDE_PATH)
- $(INSTALL) zconf.h $(INCLUDE_PATH)
- $(INSTALL) libz.a $(LIBRARY_PATH)
-
-uninstall:
- $(RM) $(INCLUDE_PATH)\zlib.h
- $(RM) $(INCLUDE_PATH)\zconf.h
- $(RM) $(LIBRARY_PATH)\libz.a
-
-clean:
- $(RM) *.d
- $(RM) *.o
- $(RM) *.exe
- $(RM) libz.a
- $(RM) foo.gz
-
-DEPS := $(wildcard *.d)
-ifneq ($(DEPS),)
-include $(DEPS)
-endif
diff --git a/cpukit/zlib/msdos/Makefile.emx b/cpukit/zlib/msdos/Makefile.emx
deleted file mode 100644
index 9c1b57a585..0000000000
--- a/cpukit/zlib/msdos/Makefile.emx
+++ /dev/null
@@ -1,69 +0,0 @@
-# Makefile for zlib. Modified for emx 0.9c by Chr. Spieler, 6/17/98.
-# Copyright (C) 1995-1998 Jean-loup Gailly.
-# For conditions of distribution and use, see copyright notice in zlib.h
-
-# To compile, or to compile and test, type:
-#
-# make -fmakefile.emx; make test -fmakefile.emx
-#
-
-CC=gcc
-
-#CFLAGS=-MMD -O
-#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
-#CFLAGS=-MMD -g -DDEBUG
-CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
- -Wstrict-prototypes -Wmissing-prototypes
-
-# If cp.exe is available, replace "copy /Y" with "cp -fp" .
-CP=copy /Y
-# If gnu install.exe is available, replace $(CP) with ginstall.
-INSTALL=$(CP)
-# The default value of RM is "rm -f." If "rm.exe" is found, comment out:
-RM=del
-LDLIBS=-L. -lzlib
-LD=$(CC) -s -o
-LDSHARED=$(CC)
-
-INCL=zlib.h zconf.h
-LIBS=zlib.a
-
-AR=ar rcs
-
-prefix=/usr/local
-exec_prefix = $(prefix)
-
-OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \
- uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
-
-TEST_OBJS = example.o minigzip.o
-
-all: example.exe minigzip.exe
-
-test: all
- ./example
- echo hello world | .\minigzip | .\minigzip -d
-
-%.o : %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-zlib.a: $(OBJS)
- $(AR) $@ $(OBJS)
-
-%.exe : %.o $(LIBS)
- $(LD) $@ $< $(LDLIBS)
-
-
-.PHONY : clean
-
-clean:
- $(RM) *.d
- $(RM) *.o
- $(RM) *.exe
- $(RM) zlib.a
- $(RM) foo.gz
-
-DEPS := $(wildcard *.d)
-ifneq ($(DEPS),)
-include $(DEPS)
-endif
diff --git a/cpukit/zlib/msdos/Makefile.msc b/cpukit/zlib/msdos/Makefile.msc
deleted file mode 100644
index cd2816fbf3..0000000000
--- a/cpukit/zlib/msdos/Makefile.msc
+++ /dev/null
@@ -1,112 +0,0 @@
-# Makefile for zlib
-# Microsoft C 5.1 or later
-# Last updated: 19-Mar-2003
-
-# To use, do "make makefile.msc"
-# To compile in small model, set below: MODEL=S
-
-# If you wish to reduce the memory requirements (default 256K for big
-# objects plus a few K), you can add to the LOC macro below:
-# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
-# See zconf.h for details about the memory requirements.
-
-# ------------- Microsoft C 5.1 and later -------------
-
-# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
-# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
-# to the declaration of LOC here:
-LOC = $(LOCAL_ZLIB)
-
-# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
-CPU_TYP = 0
-
-# Memory model: one of S, M, C, L (small, medium, compact, large)
-MODEL=L
-
-CC=cl
-CFLAGS=-nologo -A$(MODEL) -G$(CPU_TYP) -W3 -Oait -Gs $(LOC)
-#-Ox generates bad code with MSC 5.1
-LIB_CFLAGS=-Zl $(CFLAGS)
-
-LD=link
-LDFLAGS=/noi/e/st:0x1500/noe/farcall/packcode
-# "/farcall/packcode" are only useful for `large code' memory models
-# but should be a "no-op" for small code models.
-
-
-# variables
-ZLIB_LIB = zlib_$(MODEL).lib
-
-OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj
-OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-
-
-# targets
-all: $(ZLIB_LIB) example.exe minigzip.exe
-
-.c.obj:
- $(CC) -c $(LIB_CFLAGS) $*.c
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-example.obj: example.c zlib.h zconf.h
- $(CC) -c $(CFLAGS) $*.c
-
-minigzip.obj: minigzip.c zlib.h zconf.h
- $(CC) -c $(CFLAGS) $*.c
-
-
-# the command line is cut to fit in the MS-DOS 128 byte limit:
-$(ZLIB_LIB): $(OBJ1) $(OBJ2)
- if exist $(ZLIB_LIB) del $(ZLIB_LIB)
- lib $(ZLIB_LIB) $(OBJ1);
- lib $(ZLIB_LIB) $(OBJ2);
-
-example.exe: example.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) example.obj,,,$(ZLIB_LIB);
-
-minigzip.exe: minigzip.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) minigzip.obj,,,$(ZLIB_LIB);
-
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-clean:
- -del *.obj
- -del *.lib
- -del *.exe
- -del *.map
- -del zlib_*.bak
- -del foo.gz
diff --git a/cpukit/zlib/msdos/Makefile.tc b/cpukit/zlib/msdos/Makefile.tc
deleted file mode 100644
index bcd0d1889c..0000000000
--- a/cpukit/zlib/msdos/Makefile.tc
+++ /dev/null
@@ -1,100 +0,0 @@
-# Makefile for zlib
-# Turbo C 2.01, Turbo C++ 1.01
-# Last updated: 15-Mar-2003
-
-# To use, do "make -fmakefile.tc"
-# To compile in small model, set below: MODEL=s
-
-# WARNING: the small model is supported but only for small values of
-# MAX_WBITS and MAX_MEM_LEVEL. For example:
-# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
-# If you wish to reduce the memory requirements (default 256K for big
-# objects plus a few K), you can add to CFLAGS below:
-# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
-# See zconf.h for details about the memory requirements.
-
-# ------------ Turbo C 2.01, Turbo C++ 1.01 ------------
-MODEL=l
-CC=tcc
-LD=tcc
-AR=tlib
-# CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
-CFLAGS=-O2 -G -Z -m$(MODEL)
-LDFLAGS=-m$(MODEL) -f-
-
-
-# variables
-ZLIB_LIB = zlib_$(MODEL).lib
-
-OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj
-OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj
-OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
-
-
-# targets
-all: $(ZLIB_LIB) example.exe minigzip.exe
-
-.c.obj:
- $(CC) -c $(CFLAGS) $*.c
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-example.obj: example.c zlib.h zconf.h
-
-minigzip.obj: minigzip.c zlib.h zconf.h
-
-
-# the command line is cut to fit in the MS-DOS 128 byte limit:
-$(ZLIB_LIB): $(OBJ1) $(OBJ2)
- -del $(ZLIB_LIB)
- $(AR) $(ZLIB_LIB) $(OBJP1)
- $(AR) $(ZLIB_LIB) $(OBJP2)
-
-example.exe: example.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
-
-minigzip.exe: minigzip.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
-
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-clean:
- -del *.obj
- -del *.lib
- -del *.exe
- -del zlib_*.bak
- -del foo.gz
diff --git a/cpukit/zlib/old/Makefile.riscos b/cpukit/zlib/old/Makefile.riscos
deleted file mode 100644
index 57e29d3fba..0000000000
--- a/cpukit/zlib/old/Makefile.riscos
+++ /dev/null
@@ -1,151 +0,0 @@
-# Project: zlib_1_03
-# Patched for zlib 1.1.2 rw@shadow.org.uk 19980430
-# test works out-of-the-box, installs `somewhere' on demand
-
-# Toolflags:
-CCflags = -c -depend !Depend -IC: -g -throwback -DRISCOS -fah
-C++flags = -c -depend !Depend -IC: -throwback
-Linkflags = -aif -c++ -o $@
-ObjAsmflags = -throwback -NoCache -depend !Depend
-CMHGflags =
-LibFileflags = -c -l -o $@
-Squeezeflags = -o $@
-
-# change the line below to where _you_ want the library installed.
-libdest = lib:zlib
-
-# Final targets:
-@.lib: @.o.adler32 @.o.compress @.o.crc32 @.o.deflate @.o.gzio \
- @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil @.o.trees \
- @.o.uncompr @.o.zutil
- LibFile $(LibFileflags) @.o.adler32 @.o.compress @.o.crc32 @.o.deflate \
- @.o.gzio @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil \
- @.o.trees @.o.uncompr @.o.zutil
-test: @.minigzip @.example @.lib
- @copy @.lib @.libc A~C~DF~L~N~P~Q~RS~TV
- @echo running tests: hang on.
- @/@.minigzip -f -9 libc
- @/@.minigzip -d libc-gz
- @/@.minigzip -f -1 libc
- @/@.minigzip -d libc-gz
- @/@.minigzip -h -9 libc
- @/@.minigzip -d libc-gz
- @/@.minigzip -h -1 libc
- @/@.minigzip -d libc-gz
- @/@.minigzip -9 libc
- @/@.minigzip -d libc-gz
- @/@.minigzip -1 libc
- @/@.minigzip -d libc-gz
- @diff @.lib @.libc
- @echo that should have reported '@.lib and @.libc identical' if you have diff.
- @/@.example @.fred @.fred
- @echo that will have given lots of hello!'s.
-
-@.minigzip: @.o.minigzip @.lib C:o.Stubs
- Link $(Linkflags) @.o.minigzip @.lib C:o.Stubs
-@.example: @.o.example @.lib C:o.Stubs
- Link $(Linkflags) @.o.example @.lib C:o.Stubs
-
-install: @.lib
- cdir $(libdest)
- cdir $(libdest).h
- @copy @.h.zlib $(libdest).h.zlib A~C~DF~L~N~P~Q~RS~TV
- @copy @.h.zconf $(libdest).h.zconf A~C~DF~L~N~P~Q~RS~TV
- @copy @.lib $(libdest).lib A~C~DF~L~N~P~Q~RS~TV
- @echo okay, installed zlib in $(libdest)
-
-clean:; remove @.minigzip
- remove @.example
- remove @.libc
- -wipe @.o.* F~r~cV
- remove @.fred
-
-# User-editable dependencies:
-.c.o:
- cc $(ccflags) -o $@ $<
-
-# Static dependencies:
-
-# Dynamic dependencies:
-o.example: c.example
-o.example: h.zlib
-o.example: h.zconf
-o.minigzip: c.minigzip
-o.minigzip: h.zlib
-o.minigzip: h.zconf
-o.adler32: c.adler32
-o.adler32: h.zlib
-o.adler32: h.zconf
-o.compress: c.compress
-o.compress: h.zlib
-o.compress: h.zconf
-o.crc32: c.crc32
-o.crc32: h.zlib
-o.crc32: h.zconf
-o.deflate: c.deflate
-o.deflate: h.deflate
-o.deflate: h.zutil
-o.deflate: h.zlib
-o.deflate: h.zconf
-o.gzio: c.gzio
-o.gzio: h.zutil
-o.gzio: h.zlib
-o.gzio: h.zconf
-o.infblock: c.infblock
-o.infblock: h.zutil
-o.infblock: h.zlib
-o.infblock: h.zconf
-o.infblock: h.infblock
-o.infblock: h.inftrees
-o.infblock: h.infcodes
-o.infblock: h.infutil
-o.infcodes: c.infcodes
-o.infcodes: h.zutil
-o.infcodes: h.zlib
-o.infcodes: h.zconf
-o.infcodes: h.inftrees
-o.infcodes: h.infblock
-o.infcodes: h.infcodes
-o.infcodes: h.infutil
-o.infcodes: h.inffast
-o.inffast: c.inffast
-o.inffast: h.zutil
-o.inffast: h.zlib
-o.inffast: h.zconf
-o.inffast: h.inftrees
-o.inffast: h.infblock
-o.inffast: h.infcodes
-o.inffast: h.infutil
-o.inffast: h.inffast
-o.inflate: c.inflate
-o.inflate: h.zutil
-o.inflate: h.zlib
-o.inflate: h.zconf
-o.inflate: h.infblock
-o.inftrees: c.inftrees
-o.inftrees: h.zutil
-o.inftrees: h.zlib
-o.inftrees: h.zconf
-o.inftrees: h.inftrees
-o.inftrees: h.inffixed
-o.infutil: c.infutil
-o.infutil: h.zutil
-o.infutil: h.zlib
-o.infutil: h.zconf
-o.infutil: h.infblock
-o.infutil: h.inftrees
-o.infutil: h.infcodes
-o.infutil: h.infutil
-o.trees: c.trees
-o.trees: h.deflate
-o.trees: h.zutil
-o.trees: h.zlib
-o.trees: h.zconf
-o.trees: h.trees
-o.uncompr: c.uncompr
-o.uncompr: h.zlib
-o.uncompr: h.zconf
-o.zutil: c.zutil
-o.zutil: h.zutil
-o.zutil: h.zlib
-o.zutil: h.zconf
diff --git a/cpukit/zlib/old/README b/cpukit/zlib/old/README
deleted file mode 100644
index 800bf07982..0000000000
--- a/cpukit/zlib/old/README
+++ /dev/null
@@ -1,3 +0,0 @@
-This directory contains files that have not been updated for zlib 1.2.x
-
-(Volunteers are encouraged to help clean this up. Thanks.)
diff --git a/cpukit/zlib/old/descrip.mms b/cpukit/zlib/old/descrip.mms
deleted file mode 100644
index 7066da5b55..0000000000
--- a/cpukit/zlib/old/descrip.mms
+++ /dev/null
@@ -1,48 +0,0 @@
-# descrip.mms: MMS description file for building zlib on VMS
-# written by Martin P.J. Zinser <m.zinser@gsi.de>
-
-cc_defs =
-c_deb =
-
-.ifdef __DECC__
-pref = /prefix=all
-.endif
-
-OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj,\
- deflate.obj, trees.obj, zutil.obj, inflate.obj, infblock.obj,\
- inftrees.obj, infcodes.obj, infutil.obj, inffast.obj
-
-CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)
-
-all : example.exe minigzip.exe
- @ write sys$output " Example applications available"
-libz.olb : libz.olb($(OBJS))
- @ write sys$output " libz available"
-
-example.exe : example.obj libz.olb
- link example,libz.olb/lib
-
-minigzip.exe : minigzip.obj libz.olb
- link minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib
-
-clean :
- delete *.obj;*,libz.olb;*
-
-
-# Other dependencies.
-adler32.obj : zutil.h zlib.h zconf.h
-compress.obj : zlib.h zconf.h
-crc32.obj : zutil.h zlib.h zconf.h
-deflate.obj : deflate.h zutil.h zlib.h zconf.h
-example.obj : zlib.h zconf.h
-gzio.obj : zutil.h zlib.h zconf.h
-infblock.obj : zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
-infcodes.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
-inffast.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
-inflate.obj : zutil.h zlib.h zconf.h infblock.h
-inftrees.obj : zutil.h zlib.h zconf.h inftrees.h
-infutil.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h
-minigzip.obj : zlib.h zconf.h
-trees.obj : deflate.h zutil.h zlib.h zconf.h
-uncompr.obj : zlib.h zconf.h
-zutil.obj : zutil.h zlib.h zconf.h
diff --git a/cpukit/zlib/old/os2/Makefile.os2 b/cpukit/zlib/old/os2/Makefile.os2
deleted file mode 100644
index a105aaa5bb..0000000000
--- a/cpukit/zlib/old/os2/Makefile.os2
+++ /dev/null
@@ -1,136 +0,0 @@
-# Makefile for zlib under OS/2 using GCC (PGCC)
-# For conditions of distribution and use, see copyright notice in zlib.h
-
-# To compile and test, type:
-# cp Makefile.os2 ..
-# cd ..
-# make -f Makefile.os2 test
-
-# This makefile will build a static library z.lib, a shared library
-# z.dll and a import library zdll.lib. You can use either z.lib or
-# zdll.lib by specifying either -lz or -lzdll on gcc's command line
-
-CC=gcc -Zomf -s
-
-CFLAGS=-O6 -Wall
-#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
-#CFLAGS=-g -DDEBUG
-#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
-# -Wstrict-prototypes -Wmissing-prototypes
-
-#################### BUG WARNING: #####################
-## infcodes.c hits a bug in pgcc-1.0, so you have to use either
-## -O# where # <= 4 or one of (-fno-ommit-frame-pointer or -fno-force-mem)
-## This bug is reportedly fixed in pgcc >1.0, but this was not tested
-CFLAGS+=-fno-force-mem
-
-LDFLAGS=-s -L. -lzdll -Zcrtdll
-LDSHARED=$(CC) -s -Zomf -Zdll -Zcrtdll
-
-VER=1.1.0
-ZLIB=z.lib
-SHAREDLIB=z.dll
-SHAREDLIBIMP=zdll.lib
-LIBS=$(ZLIB) $(SHAREDLIB) $(SHAREDLIBIMP)
-
-AR=emxomfar cr
-IMPLIB=emximp
-RANLIB=echo
-TAR=tar
-SHELL=bash
-
-prefix=/usr/local
-exec_prefix = $(prefix)
-
-OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
- zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
-
-TEST_OBJS = example.o minigzip.o
-
-DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \
- algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \
- nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \
- contrib/asm386/*.asm contrib/asm386/*.c \
- contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/iostream/*.cpp \
- contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \
- contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32
-
-all: example.exe minigzip.exe
-
-test: all
- @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
- echo hello world | ./minigzip | ./minigzip -d || \
- echo ' *** minigzip test FAILED ***' ; \
- if ./example; then \
- echo ' *** zlib test OK ***'; \
- else \
- echo ' *** zlib test FAILED ***'; \
- fi
-
-$(ZLIB): $(OBJS)
- $(AR) $@ $(OBJS)
- -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
-
-$(SHAREDLIB): $(OBJS) os2/z.def
- $(LDSHARED) -o $@ $^
-
-$(SHAREDLIBIMP): os2/z.def
- $(IMPLIB) -o $@ $^
-
-example.exe: example.o $(LIBS)
- $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
-
-minigzip.exe: minigzip.o $(LIBS)
- $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
-
-clean:
- rm -f *.o *~ example minigzip libz.a libz.so* foo.gz
-
-distclean: clean
-
-zip:
- mv Makefile Makefile~; cp -p Makefile.in Makefile
- rm -f test.c ztest*.c
- v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
- zip -ul9 zlib$$v $(DISTFILES)
- mv Makefile~ Makefile
-
-dist:
- mv Makefile Makefile~; cp -p Makefile.in Makefile
- rm -f test.c ztest*.c
- d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
- rm -f $$d.tar.gz; \
- if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \
- files=""; \
- for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \
- cd ..; \
- GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \
- if test ! -d $$d; then rm -f $$d; fi
- mv Makefile~ Makefile
-
-tags:
- etags *.[ch]
-
-depend:
- makedepend -- $(CFLAGS) -- *.[ch]
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-adler32.o: zlib.h zconf.h
-compress.o: zlib.h zconf.h
-crc32.o: zlib.h zconf.h
-deflate.o: deflate.h zutil.h zlib.h zconf.h
-example.o: zlib.h zconf.h
-gzio.o: zutil.h zlib.h zconf.h
-infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h
-infcodes.o: zutil.h zlib.h zconf.h
-infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h
-inffast.o: zutil.h zlib.h zconf.h inftrees.h
-inffast.o: infblock.h infcodes.h infutil.h inffast.h
-inflate.o: zutil.h zlib.h zconf.h infblock.h
-inftrees.o: zutil.h zlib.h zconf.h inftrees.h
-infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
-minigzip.o: zlib.h zconf.h
-trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
-uncompr.o: zlib.h zconf.h
-zutil.o: zutil.h zlib.h zconf.h
diff --git a/cpukit/zlib/old/os2/zlib.def b/cpukit/zlib/old/os2/zlib.def
deleted file mode 100644
index 4c753f1a3b..0000000000
--- a/cpukit/zlib/old/os2/zlib.def
+++ /dev/null
@@ -1,51 +0,0 @@
-;
-; Slightly modified version of ../nt/zlib.dnt :-)
-;
-
-LIBRARY Z
-DESCRIPTION "Zlib compression library for OS/2"
-CODE PRELOAD MOVEABLE DISCARDABLE
-DATA PRELOAD MOVEABLE MULTIPLE
-
-EXPORTS
- adler32
- compress
- crc32
- deflate
- deflateCopy
- deflateEnd
- deflateInit2_
- deflateInit_
- deflateParams
- deflateReset
- deflateSetDictionary
- gzclose
- gzdopen
- gzerror
- gzflush
- gzopen
- gzread
- gzwrite
- inflate
- inflateEnd
- inflateInit2_
- inflateInit_
- inflateReset
- inflateSetDictionary
- inflateSync
- uncompress
- zlibVersion
- gzprintf
- gzputc
- gzgetc
- gzseek
- gzrewind
- gztell
- gzeof
- gzsetparams
- zError
- inflateSyncPoint
- get_crc_table
- compress2
- gzputs
- gzgets
diff --git a/cpukit/zlib/old/visual-basic.txt b/cpukit/zlib/old/visual-basic.txt
deleted file mode 100644
index 57efe58124..0000000000
--- a/cpukit/zlib/old/visual-basic.txt
+++ /dev/null
@@ -1,160 +0,0 @@
-See below some functions declarations for Visual Basic.
-
-Frequently Asked Question:
-
-Q: Each time I use the compress function I get the -5 error (not enough
- room in the output buffer).
-
-A: Make sure that the length of the compressed buffer is passed by
- reference ("as any"), not by value ("as long"). Also check that
- before the call of compress this length is equal to the total size of
- the compressed buffer and not zero.
-
-
-From: "Jon Caruana" <jon-net@usa.net>
-Subject: Re: How to port zlib declares to vb?
-Date: Mon, 28 Oct 1996 18:33:03 -0600
-
-Got the answer! (I haven't had time to check this but it's what I got, and
-looks correct):
-
-He has the following routines working:
- compress
- uncompress
- gzopen
- gzwrite
- gzread
- gzclose
-
-Declares follow: (Quoted from Carlos Rios <c_rios@sonda.cl>, in Vb4 form)
-
-#If Win16 Then 'Use Win16 calls.
-Declare Function compress Lib "ZLIB.DLL" (ByVal compr As
- String, comprLen As Any, ByVal buf As String, ByVal buflen
- As Long) As Integer
-Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr
- As String, uncomprLen As Any, ByVal compr As String, ByVal
- lcompr As Long) As Integer
-Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As
- String, ByVal mode As String) As Long
-Declare Function gzread Lib "ZLIB.DLL" (ByVal file As
- Long, ByVal uncompr As String, ByVal uncomprLen As Integer)
- As Integer
-Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As
- Long, ByVal uncompr As String, ByVal uncomprLen As Integer)
- As Integer
-Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As
- Long) As Integer
-#Else
-Declare Function compress Lib "ZLIB32.DLL"
- (ByVal compr As String, comprLen As Any, ByVal buf As
- String, ByVal buflen As Long) As Integer
-Declare Function uncompress Lib "ZLIB32.DLL"
- (ByVal uncompr As String, uncomprLen As Any, ByVal compr As
- String, ByVal lcompr As Long) As Long
-Declare Function gzopen Lib "ZLIB32.DLL"
- (ByVal file As String, ByVal mode As String) As Long
-Declare Function gzread Lib "ZLIB32.DLL"
- (ByVal file As Long, ByVal uncompr As String, ByVal
- uncomprLen As Long) As Long
-Declare Function gzwrite Lib "ZLIB32.DLL"
- (ByVal file As Long, ByVal uncompr As String, ByVal
- uncomprLen As Long) As Long
-Declare Function gzclose Lib "ZLIB32.DLL"
- (ByVal file As Long) As Long
-#End If
-
--Jon Caruana
-jon-net@usa.net
-Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member
-
-
-Here is another example from Michael <michael_borgsys@hotmail.com> that he
-says conforms to the VB guidelines, and that solves the problem of not
-knowing the uncompressed size by storing it at the end of the file:
-
-'Calling the functions:
-'bracket meaning: <parameter> [optional] {Range of possible values}
-'Call subCompressFile(<path with filename to compress> [, <path with
-filename to write to>, [level of compression {1..9}]])
-'Call subUncompressFile(<path with filename to compress>)
-
-Option Explicit
-Private lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller'
-Private Const SUCCESS As Long = 0
-Private Const strFilExt As String = ".cpr"
-Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef
-dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long,
-ByVal level As Integer) As Long
-Private Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRef
-dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long)
-As Long
-
-Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal
-strargCprFilPth As String, Optional ByVal intLvl As Integer = 9)
- Dim strCprPth As String
- Dim lngOriSiz As Long
- Dim lngCprSiz As Long
- Dim bytaryOri() As Byte
- Dim bytaryCpr() As Byte
- lngOriSiz = FileLen(strargOriFilPth)
- ReDim bytaryOri(lngOriSiz - 1)
- Open strargOriFilPth For Binary Access Read As #1
- Get #1, , bytaryOri()
- Close #1
- strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth)
-'Select file path and name
- strCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) =
-strFilExt, "", strFilExt) 'Add file extension if not exists
- lngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bit
-more space then original file size
- ReDim bytaryCpr(lngCprSiz - 1)
- If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) =
-SUCCESS Then
- lngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100
- ReDim Preserve bytaryCpr(lngCprSiz - 1)
- Open strCprPth For Binary Access Write As #1
- Put #1, , bytaryCpr()
- Put #1, , lngOriSiz 'Add the the original size value to the end
-(last 4 bytes)
- Close #1
- Else
- MsgBox "Compression error"
- End If
- Erase bytaryCpr
- Erase bytaryOri
-End Sub
-
-Public Sub subUncompressFile(ByVal strargFilPth As String)
- Dim bytaryCpr() As Byte
- Dim bytaryOri() As Byte
- Dim lngOriSiz As Long
- Dim lngCprSiz As Long
- Dim strOriPth As String
- lngCprSiz = FileLen(strargFilPth)
- ReDim bytaryCpr(lngCprSiz - 1)
- Open strargFilPth For Binary Access Read As #1
- Get #1, , bytaryCpr()
- Close #1
- 'Read the original file size value:
- lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _
- + bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _
- + bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _
- + bytaryCpr(lngCprSiz - 4)
- ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size value
- ReDim bytaryOri(lngOriSiz - 1)
- If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESS
-Then
- strOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt))
- Open strOriPth For Binary Access Write As #1
- Put #1, , bytaryOri()
- Close #1
- Else
- MsgBox "Uncompression error"
- End If
- Erase bytaryCpr
- Erase bytaryOri
-End Sub
-Public Property Get lngPercentSmaller() As Long
- lngPercentSmaller = lngpvtPcnSml
-End Property
diff --git a/cpukit/zlib/old/zlib.html b/cpukit/zlib/old/zlib.html
deleted file mode 100644
index 8c1b190c38..0000000000
--- a/cpukit/zlib/old/zlib.html
+++ /dev/null
@@ -1,971 +0,0 @@
-<html>
-<head>
- <title>
- zlib general purpose compression library version 1.1.4
- </title>
-</head>
-<body bgcolor="White" text="Black" vlink="Red" alink="Navy" link="Red">
-<!-- background="zlibbg.gif" -->
-
-<h1> zlib 1.1.4 Manual </h1>
-<hr>
-<a name="Contents"><h2>Contents</h2>
-<ol type="I">
-<li> <a href="#Prologue">Prologue</a>
-<li> <a href="#Introduction">Introduction</a>
-<li> <a href="#Utility functions">Utility functions</a>
-<li> <a href="#Basic functions">Basic functions</a>
-<li> <a href="#Advanced functions">Advanced functions</a>
-<li> <a href="#Constants">Constants</a>
-<li> <a href="#struct z_stream_s">struct z_stream_s</a>
-<li> <a href="#Checksum functions">Checksum functions</a>
-<li> <a href="#Misc">Misc</a>
-</ol>
-<hr>
-<a name="Prologue"><h2> Prologue </h2>
- 'zlib' general purpose compression library version 1.1.4, March 11th, 2002
- <p>
- Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
- <p>
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
- <p>
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
- <ol>
- <li> The origin of this software must not be misrepresented ; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- <li> Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- <li> This notice may not be removed or altered from any source distribution.
- </ol>
-
- <dl>
- <dt>Jean-loup Gailly
- <dd><a href="mailto:jloup@gzip.org">jloup@gzip.org</a>
- <dt>Mark Adler
- <dd><a href="mailto:madler@alumni.caltech.edu">madler@alumni.caltech.edu</a>
- </dl>
-
- The data format used by the zlib library is described by RFCs (Request for
- Comments) 1950 to 1952 in the files
- <a href="ftp://ds.internic.net/rfc/rfc1950.txt">
- ftp://ds.internic.net/rfc/rfc1950.txt </a>
- (zlib format),
- <a href="ftp://ds.internic.net/rfc/rfc1951.txt">
- rfc1951.txt </a>
- (<a href="#deflate">deflate</a> format) and
- <a href="ftp://ds.internic.net/rfc/rfc1952.txt">
- rfc1952.txt </a>
- (gzip format).
- <p>
- This manual is converted from zlib.h by
- <a href="mailto:piaip@csie.ntu.edu.tw"> piaip </a>
- <p>
- Visit <a href="http://ftp.cdrom.com/pub/infozip/zlib/">
- http://ftp.cdrom.com/pub/infozip/zlib/</a>
- for the official zlib web page.
- <p>
-
-<hr>
-<a name="Introduction"><h2> Introduction </h2>
- The 'zlib' compression library provides in-memory compression and
- decompression functions, including integrity checks of the uncompressed
- data. This version of the library supports only one compression method
- (deflation) but other algorithms will be added later and will have the same
- stream interface.
- <p>
-
- Compression can be done in a single step if the buffers are large
- enough (for example if an input file is mmap'ed), or can be done by
- repeated calls of the compression function. In the latter case, the
- application must provide more input and/or consume the output
- (providing more output space) before each call.
- <p>
-
- The library also supports reading and writing files in gzip (.gz) format
- with an interface similar to that of stdio.
- <p>
-
- The library does not install any signal handler. The decoder checks
- the consistency of the compressed data, so the library should never
- crash even in case of corrupted input.
- <p>
-
-<hr>
-<a name="Utility functions"><h2> Utility functions </h2>
- The following utility functions are implemented on top of the
- <a href="#Basic functions">basic stream-oriented functions</a>.
- To simplify the interface, some
- default options are assumed (compression level and memory usage,
- standard memory allocation functions). The source code of these
- utility functions can easily be modified if you need special options.
-<h3> Function list </h3>
-<ul>
-<li> int <a href="#compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
-<li> int <a href="#compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);
-<li> int <a href="#uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
-<li> typedef voidp gzFile;
-<li> gzFile <a href="#gzopen">gzopen</a> (const char *path, const char *mode);
-<li> gzFile <a href="#gzdopen">gzdopen</a> (int fd, const char *mode);
-<li> int <a href="#gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);
-<li> int <a href="#gzread">gzread</a> (gzFile file, voidp buf, unsigned len);
-<li> int <a href="#gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);
-<li> int VA <a href="#gzprintf">gzprintf</a> (gzFile file, const char *format, ...);
-<li> int <a href="#gzputs">gzputs</a> (gzFile file, const char *s);
-<li> char * <a href="#gzgets">gzgets</a> (gzFile file, char *buf, int len);
-<li> int <a href="#gzputc">gzputc</a> (gzFile file, int c);
-<li> int <a href="#gzgetc">gzgetc</a> (gzFile file);
-<li> int <a href="#gzflush">gzflush</a> (gzFile file, int flush);
-<li> z_off_t <a href="#gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);
-<li> z_off_t <a href="#gztell">gztell</a> (gzFile file);
-<li> int <a href="#gzrewind">gzrewind</a> (gzFile file);
-<li> int <a href="#gzeof">gzeof</a> (gzFile file);
-<li> int <a href="#gzclose">gzclose</a> (gzFile file);
-<li> const char * <a href="#gzerror">gzerror</a> (gzFile file, int *errnum);
-</ul>
-<h3> Function description </h3>
-<dl>
-<font color="Blue"><dt> int <a name="compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
-<dd>
- Compresses the source buffer into the destination buffer. sourceLen is
- the byte length of the source buffer. Upon entry, destLen is the total
- size of the destination buffer, which must be at least 0.1% larger than
- sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
- compressed buffer.<p>
- This function can be used to <a href="#compress">compress</a> a whole file at once if the
- input file is mmap'ed.<p>
- <a href="#compress">compress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
- enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
- buffer.<p>
-
-<font color="Blue"><dt> int <a name="compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);</font>
-<dd>
- Compresses the source buffer into the destination buffer. The level
- parameter has the same meaning as in <a href="#deflateInit">deflateInit</a>. sourceLen is the byte
- length of the source buffer. Upon entry, destLen is the total size of the
- destination buffer, which must be at least 0.1% larger than sourceLen plus
- 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
- <p>
-
- <a href="#compress2">compress2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
- memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer,
- <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the level parameter is invalid.
- <p>
-
-<font color="Blue"><dt> int <a name="uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
-<dd>
- Decompresses the source buffer into the destination buffer. sourceLen is
- the byte length of the source buffer. Upon entry, destLen is the total
- size of the destination buffer, which must be large enough to hold the
- entire uncompressed data. (The size of the uncompressed data must have
- been saved previously by the compressor and transmitted to the decompressor
- by some mechanism outside the scope of this compression library.)
- Upon exit, destLen is the actual size of the compressed buffer. <p>
- This function can be used to decompress a whole file at once if the
- input file is mmap'ed.
- <p>
-
- <a href="#uncompress">uncompress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
- enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
- buffer, or <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was corrupted.
- <p>
-
-<dt> typedef voidp gzFile;
-<dd> <p>
-
-<font color="Blue"><dt> gzFile <a name="gzopen">gzopen</a> (const char *path, const char *mode);</font>
-<dd>
- Opens a gzip (.gz) file for reading or writing. The mode parameter
- is as in fopen ("rb" or "wb") but can also include a compression level
- ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
- Huffman only compression as in "wb1h". (See the description
- of <a href="#deflateInit2">deflateInit2</a> for more information about the strategy parameter.)
- <p>
-
- <a href="#gzopen">gzopen</a> can be used to read a file which is not in gzip format ; in this
- case <a href="#gzread">gzread</a> will directly read from the file without decompression.
- <p>
-
- <a href="#gzopen">gzopen</a> returns NULL if the file could not be opened or if there was
- insufficient memory to allocate the (de)compression <a href="#state">state</a> ; errno
- can be checked to distinguish the two cases (if errno is zero, the
- zlib error is <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a>).
- <p>
-
-<font color="Blue"><dt> gzFile <a name="gzdopen">gzdopen</a> (int fd, const char *mode);</font>
-<dd>
- <a href="#gzdopen">gzdopen</a>() associates a gzFile with the file descriptor fd. File
- descriptors are obtained from calls like open, dup, creat, pipe or
- fileno (in the file has been previously opened with fopen).
- The mode parameter is as in <a href="#gzopen">gzopen</a>.
- <p>
- The next call of <a href="#gzclose">gzclose</a> on the returned gzFile will also close the
- file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
- descriptor fd. If you want to keep fd open, use <a href="#gzdopen">gzdopen</a>(dup(fd), mode).
- <p>
- <a href="#gzdopen">gzdopen</a> returns NULL if there was insufficient memory to allocate
- the (de)compression <a href="#state">state</a>.
- <p>
-
-<font color="Blue"><dt> int <a name="gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);</font>
-<dd>
- Dynamically update the compression level or strategy. See the description
- of <a href="#deflateInit2">deflateInit2</a> for the meaning of these parameters.
- <p>
- <a href="#gzsetparams">gzsetparams</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the file was not
- opened for writing.
- <p>
-
-<font color="Blue"><dt> int <a name="gzread">gzread</a> (gzFile file, voidp buf, unsigned len);</font>
-<dd>
- Reads the given number of uncompressed bytes from the compressed file.
- If the input file was not in gzip format, <a href="#gzread">gzread</a> copies the given number
- of bytes into the buffer.
- <p>
- <a href="#gzread">gzread</a> returns the number of uncompressed bytes actually read (0 for
- end of file, -1 for error).
- <p>
-
-<font color="Blue"><dt> int <a name="gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);</font>
-<dd>
- Writes the given number of uncompressed bytes into the compressed file.
- <a href="#gzwrite">gzwrite</a> returns the number of uncompressed bytes actually written
- (0 in case of error).
- <p>
-
-<font color="Blue"><dt> int VA <a name="gzprintf">gzprintf</a> (gzFile file, const char *format, ...);</font>
-<dd>
- Converts, formats, and writes the args to the compressed file under
- control of the format string, as in fprintf. <a href="#gzprintf">gzprintf</a> returns the number of
- uncompressed bytes actually written (0 in case of error).
- <p>
-
-<font color="Blue"><dt> int <a name="gzputs">gzputs</a> (gzFile file, const char *s);</font>
-<dd>
- Writes the given null-terminated string to the compressed file, excluding
- the terminating null character.
- <p>
- <a href="#gzputs">gzputs</a> returns the number of characters written, or -1 in case of error.
- <p>
-
-<font color="Blue"><dt> char * <a name="gzgets">gzgets</a> (gzFile file, char *buf, int len);</font>
-<dd>
- Reads bytes from the compressed file until len-1 characters are read, or
- a newline character is read and transferred to buf, or an end-of-file
- condition is encountered. The string is then terminated with a null
- character.
- <p>
- <a href="#gzgets">gzgets</a> returns buf, or <a href="#Z_NULL">Z_NULL</a> in case of error.
- <p>
-
-<font color="Blue"><dt> int <a name="gzputc">gzputc</a> (gzFile file, int c);</font>
-<dd>
- Writes c, converted to an unsigned char, into the compressed file.
- <a href="#gzputc">gzputc</a> returns the value that was written, or -1 in case of error.
- <p>
-
-<font color="Blue"><dt> int <a name="gzgetc">gzgetc</a> (gzFile file);</font>
-<dd>
- Reads one byte from the compressed file. <a href="#gzgetc">gzgetc</a> returns this byte
- or -1 in case of end of file or error.
- <p>
-
-<font color="Blue"><dt> int <a name="gzflush">gzflush</a> (gzFile file, int flush);</font>
-<dd>
- Flushes all pending output into the compressed file. The parameter
- flush is as in the <a href="#deflate">deflate</a>() function. The return value is the zlib
- error number (see function <a href="#gzerror">gzerror</a> below). <a href="#gzflush">gzflush</a> returns <a href="#Z_OK">Z_OK</a> if
- the flush parameter is <a href="#Z_FINISH">Z_FINISH</a> and all output could be flushed.
- <p>
- <a href="#gzflush">gzflush</a> should be called only when strictly necessary because it can
- degrade compression.
- <p>
-
-<font color="Blue"><dt> z_off_t <a name="gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);</font>
-<dd>
- Sets the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
- given compressed file. The offset represents a number of bytes in the
- uncompressed data stream. The whence parameter is defined as in lseek(2);
- the value SEEK_END is not supported.
- <p>
- If the file is opened for reading, this function is emulated but can be
- extremely slow. If the file is opened for writing, only forward seeks are
- supported ; <a href="#gzseek">gzseek</a> then compresses a sequence of zeroes up to the new
- starting position.
- <p>
- <a href="#gzseek">gzseek</a> returns the resulting offset location as measured in bytes from
- the beginning of the uncompressed stream, or -1 in case of error, in
- particular if the file is opened for writing and the new starting position
- would be before the current position.
- <p>
-
-<font color="Blue"><dt> int <a name="gzrewind">gzrewind</a> (gzFile file);</font>
-<dd>
- Rewinds the given file. This function is supported only for reading.
- <p>
- <a href="#gzrewind">gzrewind</a>(file) is equivalent to (int)<a href="#gzseek">gzseek</a>(file, 0L, SEEK_SET)
- <p>
-
-<font color="Blue"><dt> z_off_t <a name="gztell">gztell</a> (gzFile file);</font>
-<dd>
- Returns the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
- given compressed file. This position represents a number of bytes in the
- uncompressed data stream.
- <p>
-
- <a href="#gztell">gztell</a>(file) is equivalent to <a href="#gzseek">gzseek</a>(file, 0L, SEEK_CUR)
- <p>
-
-<font color="Blue"><dt> int <a name="gzeof">gzeof</a> (gzFile file);</font>
-<dd>
- Returns 1 when EOF has previously been detected reading the given
- input stream, otherwise zero.
- <p>
-
-<font color="Blue"><dt> int <a name="gzclose">gzclose</a> (gzFile file);</font>
-<dd>
- Flushes all pending output if necessary, closes the compressed file
- and deallocates all the (de)compression <a href="#state">state</a>. The return value is the zlib
- error number (see function <a href="#gzerror">gzerror</a> below).
- <p>
-
-<font color="Blue"><dt> const char * <a name="gzerror">gzerror</a> (gzFile file, int *errnum);</font>
-<dd>
- Returns the error message for the last error which occurred on the
- given compressed file. errnum is set to zlib error number. If an
- error occurred in the file system and not in the compression library,
- errnum is set to <a href="#Z_ERRNO">Z_ERRNO</a> and the application may consult errno
- to get the exact error code.
- <p>
-</dl>
-<hr>
-<a name="Basic functions"><h2> Basic functions </h2>
-<h3> Function list </h3>
-<ul>
-<li> const char * <a href="#zlibVersion">zlibVersion</a> (void);
-<li> int <a href="#deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);
-<li> int <a href="#deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
-<li> int <a href="#deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
-<li> int <a href="#inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);
-<li> int <a href="#inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
-<li> int <a href="#inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
-</ul>
-
-<h3> Function description </h3>
-<dl>
-<font color="Blue"><dt> const char * <a name="zlibVersion">zlibVersion</a> (void);</font>
-<dd> The application can compare <a href="#zlibVersion">zlibVersion</a> and ZLIB_VERSION for consistency.
- If the first character differs, the library code actually used is
- not compatible with the zlib.h header file used by the application.
- This check is automatically made by <a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a>.
- <p>
-
-<font color="Blue"><dt> int <a name="deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);</font>
-<dd>
- Initializes the internal stream <a href="#state">state</a> for compression. The fields
- <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by the caller.
- If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#deflateInit">deflateInit</a> updates them to
- use default allocation functions.
- <p>
-
- The compression level must be <a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a>, or between 0 and 9:
- 1 gives best speed, 9 gives best compression, 0 gives no compression at
- all (the input data is simply copied a block at a time).
- <p>
-
- <a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> requests a default compromise between speed and
- compression (currently equivalent to level 6).
- <p>
-
- <a href="#deflateInit">deflateInit</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
- enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if level is not a valid compression level,
- <a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version (<a href="#zlib_version">zlib_version</a>) is incompatible
- with the version assumed by the caller (ZLIB_VERSION).
- <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit">deflateInit</a> does not
- perform any compression: this will be done by <a href="#deflate">deflate</a>().
- <p>
-
-<font color="Blue"><dt> int <a name="deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
-<dd>
- <a href="#deflate">deflate</a> compresses as much data as possible, and stops when the input
- buffer becomes empty or the output buffer becomes full. It may introduce some
- output latency (reading input without producing any output) except when
- forced to flush.<p>
-
- The detailed semantics are as follows. <a href="#deflate">deflate</a> performs one or both of the
- following actions:
-
- <ul>
- <li> Compress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a>
- accordingly. If not all input can be processed (because there is not
- enough room in the output buffer), <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> are updated and
- processing will resume at this point for the next call of <a href="#deflate">deflate</a>().
-
- <li>
- Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a>
- accordingly. This action is forced if the parameter flush is non zero.
- Forcing flush frequently degrades the compression ratio, so this parameter
- should be set only when necessary (in interactive applications).
- Some output may be provided even if flush is not set.
- </ul> <p>
-
- Before the call of <a href="#deflate">deflate</a>(), the application should ensure that at least
- one of the actions is possible, by providing more input and/or consuming
- more output, and updating <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> accordingly ; <a href="#avail_out">avail_out</a>
- should never be zero before the call. The application can consume the
- compressed output when it wants, for example when the output buffer is full
- (<a href="#avail_out">avail_out</a> == 0), or after each call of <a href="#deflate">deflate</a>(). If <a href="#deflate">deflate</a> returns <a href="#Z_OK">Z_OK</a>
- and with zero <a href="#avail_out">avail_out</a>, it must be called again after making room in the
- output buffer because there might be more output pending.
- <p>
-
- If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, all pending output is
- flushed to the output buffer and the output is aligned on a byte boundary, so
- that the decompressor can get all input data available so far. (In particular
- <a href="#avail_in">avail_in</a> is zero after the call if enough output space has been provided
- before the call.) Flushing may degrade compression for some compression
- algorithms and so it should be used only when necessary.
- <p>
-
- If flush is set to <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>, all output is flushed as with
- <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, and the compression <a href="#state">state</a> is reset so that decompression can
- restart from this point if previous compressed data has been damaged or if
- random access is desired. Using <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a> too often can seriously degrade
- the compression.
- <p>
-
- If <a href="#deflate">deflate</a> returns with <a href="#avail_out">avail_out</a> == 0, this function must be called again
- with the same value of the flush parameter and more output space (updated
- <a href="#avail_out">avail_out</a>), until the flush is complete (<a href="#deflate">deflate</a> returns with non-zero
- <a href="#avail_out">avail_out</a>).
- <p>
-
- If the parameter flush is set to <a href="#Z_FINISH">Z_FINISH</a>, pending input is processed,
- pending output is flushed and <a href="#deflate">deflate</a> returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> if there
- was enough output space ; if <a href="#deflate">deflate</a> returns with <a href="#Z_OK">Z_OK</a>, this function must be
- called again with <a href="#Z_FINISH">Z_FINISH</a> and more output space (updated <a href="#avail_out">avail_out</a>) but no
- more input data, until it returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error. After
- <a href="#deflate">deflate</a> has returned <a href="#Z_STREAM_END">Z_STREAM_END</a>, the only possible operations on the
- stream are <a href="#deflateReset">deflateReset</a> or <a href="#deflateEnd">deflateEnd</a>.
- <p>
-
- <a href="#Z_FINISH">Z_FINISH</a> can be used immediately after <a href="#deflateInit">deflateInit</a> if all the compression
- is to be done in a single step. In this case, <a href="#avail_out">avail_out</a> must be at least
- 0.1% larger than <a href="#avail_in">avail_in</a> plus 12 bytes. If <a href="#deflate">deflate</a> does not return
- <a href="#Z_STREAM_END">Z_STREAM_END</a>, then it must be called again as described above.
- <p>
-
- <a href="#deflate">deflate</a>() sets strm-&gt <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all input read
- so far (that is, <a href="#total_in">total_in</a> bytes).
- <p>
-
- <a href="#deflate">deflate</a>() may update <a href="#data_type">data_type</a> if it can make a good guess about
- the input data type (<a href="#Z_ASCII">Z_ASCII</a> or <a href="#Z_BINARY">Z_BINARY</a>). In doubt, the data is considered
- binary. This field is only for information purposes and does not affect
- the compression algorithm in any manner.
- <p>
-
- <a href="#deflate">deflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input
- processed or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if all input has been
- consumed and all output has been produced (only when flush is set to
- <a href="#Z_FINISH">Z_FINISH</a>), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a> was inconsistent (for example
- if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible
- (for example <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> was zero).
- <p>
-
-<font color="Blue"><dt> int <a name="deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
-<dd>
- All dynamically allocated data structures for this stream are freed.
- This function discards any unprocessed input and does not flush any
- pending output.
- <p>
-
- <a href="#deflateEnd">deflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the
- stream <a href="#state">state</a> was inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the stream was freed
- prematurely (some input or output was discarded). In the error case,
- <a href="#msg">msg</a> may be set but then points to a static string (which must not be
- deallocated).
- <p>
-
-<font color="Blue"><dt> int <a name="inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
-<dd>
- Initializes the internal stream <a href="#state">state</a> for decompression. The fields
- <a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by
- the caller. If <a href="#next_in">next_in</a> is not <a href="#Z_NULL">Z_NULL</a> and <a href="#avail_in">avail_in</a> is large enough (the exact
- value depends on the compression method), <a href="#inflateInit">inflateInit</a> determines the
- compression method from the zlib header and allocates all data structures
- accordingly ; otherwise the allocation will be deferred to the first call of
- <a href="#inflate">inflate</a>. If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#inflateInit">inflateInit</a> updates them to
- use default allocation functions.
- <p>
-
- <a href="#inflateInit">inflateInit</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
- memory, <a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version is incompatible with the
- version assumed by the caller. <a href="#msg">msg</a> is set to null if there is no error
- message. <a href="#inflateInit">inflateInit</a> does not perform any decompression apart from reading
- the zlib header if present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and
- <a href="#avail_in">avail_in</a> may be modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)
- <p>
-
-<font color="Blue"><dt> int <a name="inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
-<dd>
- <a href="#inflate">inflate</a> decompresses as much data as possible, and stops when the input
- buffer becomes empty or the output buffer becomes full. It may some
- introduce some output latency (reading input without producing any output)
- except when forced to flush.
- <p>
-
- The detailed semantics are as follows. <a href="#inflate">inflate</a> performs one or both of the
- following actions:
-
- <ul>
- <li> Decompress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a>
- accordingly. If not all input can be processed (because there is not
- enough room in the output buffer), <a href="#next_in">next_in</a> is updated and processing
- will resume at this point for the next call of <a href="#inflate">inflate</a>().
-
- <li> Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and
- <a href="#avail_out">avail_out</a> accordingly. <a href="#inflate">inflate</a>() provides as much output as possible,
- until there is no more input data or no more space in the output buffer
- (see below about the flush parameter).
- </ul> <p>
-
- Before the call of <a href="#inflate">inflate</a>(), the application should ensure that at least
- one of the actions is possible, by providing more input and/or consuming
- more output, and updating the next_* and avail_* values accordingly.
- The application can consume the uncompressed output when it wants, for
- example when the output buffer is full (<a href="#avail_out">avail_out</a> == 0), or after each
- call of <a href="#inflate">inflate</a>(). If <a href="#inflate">inflate</a> returns <a href="#Z_OK">Z_OK</a> and with zero <a href="#avail_out">avail_out</a>, it
- must be called again after making room in the output buffer because there
- might be more output pending.
- <p>
-
- If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, <a href="#inflate">inflate</a> flushes as much
- output as possible to the output buffer. The flushing behavior of <a href="#inflate">inflate</a> is
- not specified for values of the flush parameter other than <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>
- and <a href="#Z_FINISH">Z_FINISH</a>, but the current implementation actually flushes as much output
- as possible anyway.
- <p>
-
- <a href="#inflate">inflate</a>() should normally be called until it returns <a href="#Z_STREAM_END">Z_STREAM_END</a> or an
- error. However if all decompression is to be performed in a single step
- (a single call of <a href="#inflate">inflate</a>), the parameter flush should be set to
- <a href="#Z_FINISH">Z_FINISH</a>. In this case all pending input is processed and all pending
- output is flushed ; <a href="#avail_out">avail_out</a> must be large enough to hold all the
- uncompressed data. (The size of the uncompressed data may have been saved
- by the compressor for this purpose.) The next operation on this stream must
- be <a href="#inflateEnd">inflateEnd</a> to deallocate the decompression <a href="#state">state</a>. The use of <a href="#Z_FINISH">Z_FINISH</a>
- is never required, but can be used to inform <a href="#inflate">inflate</a> that a faster routine
- may be used for the single <a href="#inflate">inflate</a>() call.
- <p>
-
- If a preset dictionary is needed at this point (see <a href="#inflateSetDictionary">inflateSetDictionary</a>
- below), <a href="#inflate">inflate</a> sets strm-<a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of the
- dictionary chosen by the compressor and returns <a href="#Z_NEED_DICT">Z_NEED_DICT</a> ; otherwise
- it sets strm-&gt <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all output produced
- so far (that is, <a href="#total_out">total_out</a> bytes) and returns <a href="#Z_OK">Z_OK</a>, <a href="#Z_STREAM_END">Z_STREAM_END</a> or
- an error code as described below. At the end of the stream, <a href="#inflate">inflate</a>()
- checks that its computed <a href="#adler32">adler32</a> checksum is equal to that saved by the
- compressor and returns <a href="#Z_STREAM_END">Z_STREAM_END</a> only if the checksum is correct.
- <p>
-
- <a href="#inflate">inflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input processed
- or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if the end of the compressed data has
- been reached and all uncompressed output has been produced, <a href="#Z_NEED_DICT">Z_NEED_DICT</a> if a
- preset dictionary is needed at this point, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was
- corrupted (input stream not conforming to the zlib format or incorrect
- <a href="#adler32">adler32</a> checksum), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent
- (for example if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
- enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible or if there was not
- enough room in the output buffer when <a href="#Z_FINISH">Z_FINISH</a> is used. In the <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a>
- case, the application may then call <a href="#inflateSync">inflateSync</a> to look for a good
- compression block.
- <p>
-
-<font color="Blue"><dt> int <a name="inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
-<dd>
- All dynamically allocated data structures for this stream are freed.
- This function discards any unprocessed input and does not flush any
- pending output.
- <p>
-
- <a href="#inflateEnd">inflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a>
- was inconsistent. In the error case, <a href="#msg">msg</a> may be set but then points to a
- static string (which must not be deallocated).
-</dl>
-<hr>
-<a name="Advanced functions"><h2> Advanced functions </h2>
- The following functions are needed only in some special applications.
-<h3> Function list </h3>
-<ul>
-<li> int <a href="#deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm,
-<li> int <a href="#deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
-<li> int <a href="#deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);
-<li> int <a href="#deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
-<li> int <a href="#deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);
-<li> int <a href="#inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);
-<li> int <a href="#inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
-<li> int <a href="#inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);
-<li> int <a href="#inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
-
-</ul>
-<h3> Function description </h3>
-<dl>
-<font color="Blue"><dt> int <a name="deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int method, int windowBits, int memLevel, int strategy);</font>
-
-<dd> This is another version of <a href="#deflateInit">deflateInit</a> with more compression options. The
- fields <a href="#next_in">next_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by
- the caller.<p>
-
- The method parameter is the compression method. It must be <a href="#Z_DEFLATED">Z_DEFLATED</a> in
- this version of the library.<p>
-
- The windowBits parameter is the base two logarithm of the window size
- (the size of the history buffer). It should be in the range 8..15 for this
- version of the library. Larger values of this parameter result in better
- compression at the expense of memory usage. The default value is 15 if
- <a href="#deflateInit">deflateInit</a> is used instead.<p>
-
- The memLevel parameter specifies how much memory should be allocated
- for the internal compression <a href="#state">state</a>. memLevel=1 uses minimum memory but
- is slow and reduces compression ratio ; memLevel=9 uses maximum memory
- for optimal speed. The default value is 8. See zconf.h for total memory
- usage as a function of windowBits and memLevel.<p>
-
- The strategy parameter is used to tune the compression algorithm. Use the
- value <a href="#Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> for normal data, <a href="#Z_FILTERED">Z_FILTERED</a> for data produced by a
- filter (or predictor), or <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> to force Huffman encoding only (no
- string match). Filtered data consists mostly of small values with a
- somewhat random distribution. In this case, the compression algorithm is
- tuned to <a href="#compress">compress</a> them better. The effect of <a href="#Z_FILTERED">Z_FILTERED</a> is to force more
- Huffman coding and less string matching ; it is somewhat intermediate
- between Z_DEFAULT and <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a>. The strategy parameter only affects
- the compression ratio but not the correctness of the compressed output even
- if it is not set appropriately.<p>
-
- <a href="#deflateInit2">deflateInit2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
- memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as an invalid
- method). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit2">deflateInit2</a> does
- not perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
-
-<font color="Blue"><dt> int <a name="deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
-<dd>
- Initializes the compression dictionary from the given byte sequence
- without producing any compressed output. This function must be called
- immediately after <a href="#deflateInit">deflateInit</a>, <a href="#deflateInit2">deflateInit2</a> or <a href="#deflateReset">deflateReset</a>, before any
- call of <a href="#deflate">deflate</a>. The compressor and decompressor must use exactly the same
- dictionary (see <a href="#inflateSetDictionary">inflateSetDictionary</a>).<p>
-
- The dictionary should consist of strings (byte sequences) that are likely
- to be encountered later in the data to be compressed, with the most commonly
- used strings preferably put towards the end of the dictionary. Using a
- dictionary is most useful when the data to be compressed is short and can be
- predicted with good accuracy ; the data can then be compressed better than
- with the default empty dictionary.<p>
-
- Depending on the size of the compression data structures selected by
- <a href="#deflateInit">deflateInit</a> or <a href="#deflateInit2">deflateInit2</a>, a part of the dictionary may in effect be
- discarded, for example if the dictionary is larger than the window size in
- <a href="#deflate">deflate</a> or deflate2. Thus the strings most likely to be useful should be
- put at the end of the dictionary, not at the front.<p>
-
- Upon return of this function, strm-&gt <a href="#adler">adler</a> is set to the Adler32 value
- of the dictionary ; the decompressor may later use this value to determine
- which dictionary has been used by the compressor. (The Adler32 value
- applies to the whole dictionary even if only a subset of the dictionary is
- actually used by the compressor.)<p>
-
- <a href="#deflateSetDictionary">deflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a
- parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
- inconsistent (for example if <a href="#deflate">deflate</a> has already been called for this stream
- or if the compression method is bsort). <a href="#deflateSetDictionary">deflateSetDictionary</a> does not
- perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
-
-<font color="Blue"><dt> int <a name="deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);</font>
-<dd>
- Sets the destination stream as a complete copy of the source stream.<p>
-
- This function can be useful when several compression strategies will be
- tried, for example when there are several ways of pre-processing the input
- data with a filter. The streams that will be discarded should then be freed
- by calling <a href="#deflateEnd">deflateEnd</a>. Note that <a href="#deflateCopy">deflateCopy</a> duplicates the internal
- compression <a href="#state">state</a> which can be quite large, so this strategy is slow and
- can consume lots of memory.<p>
-
- <a href="#deflateCopy">deflateCopy</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
- enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent
- (such as <a href="#zalloc">zalloc</a> being NULL). <a href="#msg">msg</a> is left unchanged in both source and
- destination.<p>
-
-<font color="Blue"><dt> int <a name="deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
-<dd> This function is equivalent to <a href="#deflateEnd">deflateEnd</a> followed by <a href="#deflateInit">deflateInit</a>,
- but does not free and reallocate all the internal compression <a href="#state">state</a>.
- The stream will keep the same compression level and any other attributes
- that may have been set by <a href="#deflateInit2">deflateInit2</a>.<p>
-
- <a href="#deflateReset">deflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
- stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).<p>
-
-<font color="Blue"><dt> int <a name="deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);</font>
-<dd>
- Dynamically update the compression level and compression strategy. The
- interpretation of level and strategy is as in <a href="#deflateInit2">deflateInit2</a>. This can be
- used to switch between compression and straight copy of the input data, or
- to switch to a different kind of input data requiring a different
- strategy. If the compression level is changed, the input available so far
- is compressed with the old level (and may be flushed); the new level will
- take effect only at the next call of <a href="#deflate">deflate</a>().<p>
-
- Before the call of <a href="#deflateParams">deflateParams</a>, the stream <a href="#state">state</a> must be set as for
- a call of <a href="#deflate">deflate</a>(), since the currently available input may have to
- be compressed and flushed. In particular, strm-&gt <a href="#avail_out">avail_out</a> must be
- non-zero.<p>
-
- <a href="#deflateParams">deflateParams</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
- stream <a href="#state">state</a> was inconsistent or if a parameter was invalid, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
- if strm-&gtavail_out was zero.<p>
-
-<font color="Blue"><dt> int <a name="inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);</font>
-
-<dd> This is another version of <a href="#inflateInit">inflateInit</a> with an extra parameter. The
- fields <a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized
- before by the caller.<p>
-
- The windowBits parameter is the base two logarithm of the maximum window
- size (the size of the history buffer). It should be in the range 8..15 for
- this version of the library. The default value is 15 if <a href="#inflateInit">inflateInit</a> is used
- instead. If a compressed stream with a larger window size is given as
- input, <a href="#inflate">inflate</a>() will return with the error code <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> instead of
- trying to allocate a larger window.<p>
-
- <a href="#inflateInit2">inflateInit2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
- memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as a negative
- memLevel). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#inflateInit2">inflateInit2</a>
- does not perform any decompression apart from reading the zlib header if
- present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> may be
- modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)<p>
-
-<font color="Blue"><dt> int <a name="inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
-<dd>
- Initializes the decompression dictionary from the given uncompressed byte
- sequence. This function must be called immediately after a call of <a href="#inflate">inflate</a>
- if this call returned <a href="#Z_NEED_DICT">Z_NEED_DICT</a>. The dictionary chosen by the compressor
- can be determined from the Adler32 value returned by this call of
- <a href="#inflate">inflate</a>. The compressor and decompressor must use exactly the same
- dictionary (see <a href="#deflateSetDictionary">deflateSetDictionary</a>).<p>
-
- <a href="#inflateSetDictionary">inflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a
- parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
- inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the given dictionary doesn't match the
- expected one (incorrect Adler32 value). <a href="#inflateSetDictionary">inflateSetDictionary</a> does not
- perform any decompression: this will be done by subsequent calls of
- <a href="#inflate">inflate</a>().<p>
-
-<font color="Blue"><dt> int <a name="inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
-
-<dd> Skips invalid compressed data until a full flush point (see above the
- description of <a href="#deflate">deflate</a> with <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>) can be found, or until all
- available input is skipped. No output is provided.<p>
-
- <a href="#inflateSync">inflateSync</a> returns <a href="#Z_OK">Z_OK</a> if a full flush point has been found, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
- if no more input was provided, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if no flush point has been found,
- or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent. In the success
- case, the application may save the current current value of <a href="#total_in">total_in</a> which
- indicates where valid compressed data was found. In the error case, the
- application may repeatedly call <a href="#inflateSync">inflateSync</a>, providing more input each time,
- until success or end of the input data.<p>
-
-<font color="Blue"><dt> int <a name="inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
-<dd>
- This function is equivalent to <a href="#inflateEnd">inflateEnd</a> followed by <a href="#inflateInit">inflateInit</a>,
- but does not free and reallocate all the internal decompression <a href="#state">state</a>.
- The stream will keep attributes that may have been set by <a href="#inflateInit2">inflateInit2</a>.
- <p>
-
- <a href="#inflateReset">inflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
- stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).
- <p>
-</dl>
-
-<hr>
-<a name="Checksum functions"><h2> Checksum functions </h2>
- These functions are not related to compression but are exported
- anyway because they might be useful in applications using the
- compression library.
-<h3> Function list </h3>
-<ul>
-<li> uLong <a href="#adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);
-<li> uLong <a href="#crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);
-</ul>
-<h3> Function description </h3>
-<dl>
-<font color="Blue"><dt> uLong <a name="adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);</font>
-<dd>
- Update a running Adler-32 checksum with the bytes buf[0..len-1] and
- return the updated checksum. If buf is NULL, this function returns
- the required initial value for the checksum.
- <p>
- An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
- much faster. Usage example:
- <pre>
-
- uLong <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
-
- while (read_buffer(buffer, length) != EOF) {
- <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(<a href="#adler">adler</a>, buffer, length);
- }
- if (<a href="#adler">adler</a> != original_adler) error();
- </pre>
-
-<font color="Blue"><dt> uLong <a name="crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);</font>
-<dd>
- Update a running crc with the bytes buf[0..len-1] and return the updated
- crc. If buf is NULL, this function returns the required initial value
- for the crc. Pre- and post-conditioning (one's complement) is performed
- within this function so it shouldn't be done by the application.
- Usage example:
- <pre>
-
- uLong crc = <a href="#crc32">crc32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
-
- while (read_buffer(buffer, length) != EOF) {
- crc = <a href="#crc32">crc32</a>(crc, buffer, length);
- }
- if (crc != original_crc) error();
- </pre>
-</dl>
-<hr>
-<a name="struct z_stream_s"><h2> struct z_stream_s </h2>
-<font color="Blue">
-<a name="z_stream_s">
-<pre>
-typedef struct z_stream_s {
- Bytef *<a name="next_in">next_in</a>; /* next input byte */
- uInt <a name="avail_in">avail_in</a>; /* number of bytes available at <a href="#next_in">next_in</a> */
- uLong <a name="total_in">total_in</a>; /* total nb of input bytes read so far */
-
- Bytef *<a name="next_out">next_out</a>; /* next output byte should be put there */
- uInt <a name="avail_out">avail_out</a>; /* remaining free space at <a href="#next_out">next_out</a> */
- uLong <a name="total_out">total_out</a>; /* total nb of bytes output so far */
-
- char *<a name="msg">msg</a>; /* last error message, NULL if no error */
- struct internal_state FAR *<a name="state">state</a>; /* not visible by applications */
-
- alloc_func <a name="zalloc">zalloc</a>; /* used to allocate the internal <a href="#state">state</a> */
- free_func <a name="zfree">zfree</a>; /* used to free the internal <a href="#state">state</a> */
- voidpf <a name="opaque">opaque</a>; /* private data object passed to <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> */
-
- int <a name="data_type">data_type</a>; /* best guess about the data type: ascii or binary */
- uLong <a name="adler">adler</a>; /* <a href="#adler32">adler32</a> value of the uncompressed data */
- uLong <a name="reserved">reserved</a>; /* <a href="#reserved">reserved</a> for future use */
-} <a href="#z_stream_s">z_stream</a> ;
-
-typedef <a href="#z_stream_s">z_stream</a> FAR * <a name="z_streamp">z_streamp</a>; ÿ
-</pre>
-</font>
- The application must update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> when <a href="#avail_in">avail_in</a> has
- dropped to zero. It must update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> when <a href="#avail_out">avail_out</a>
- has dropped to zero. The application must initialize <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and
- <a href="#opaque">opaque</a> before calling the init function. All other fields are set by the
- compression library and must not be updated by the application. <p>
-
- The <a href="#opaque">opaque</a> value provided by the application will be passed as the first
- parameter for calls of <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a>. This can be useful for custom
- memory management. The compression library attaches no meaning to the
- <a href="#opaque">opaque</a> value. <p>
-
- <a href="#zalloc">zalloc</a> must return <a href="#Z_NULL">Z_NULL</a> if there is not enough memory for the object.
- If zlib is used in a multi-threaded application, <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be
- thread safe. <p>
-
- On 16-bit systems, the functions <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be able to allocate
- exactly 65536 bytes, but will not be required to allocate more than this
- if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
- pointers returned by <a href="#zalloc">zalloc</a> for objects of exactly 65536 bytes *must*
- have their offset normalized to zero. The default allocation function
- provided by this library ensures this (see zutil.c). To reduce memory
- requirements and avoid any allocation of 64K objects, at the expense of
- compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
- <p>
-
- The fields <a href="#total_in">total_in</a> and <a href="#total_out">total_out</a> can be used for statistics or
- progress reports. After compression, <a href="#total_in">total_in</a> holds the total size of
- the uncompressed data and may be saved for use in the decompressor
- (particularly if the decompressor wants to decompress everything in
- a single step). <p>
-
-<hr>
-<a name="Constants"><h2> Constants </h2>
-<font color="Blue">
-<pre>
-#define <a name="Z_NO_FLUSH">Z_NO_FLUSH</a> 0
-#define <a name="Z_PARTIAL_FLUSH">Z_PARTIAL_FLUSH</a> 1
- /* will be removed, use <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> instead */
-#define <a name="Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> 2
-#define <a name="Z_FULL_FLUSH">Z_FULL_FLUSH</a> 3
-#define <a name="Z_FINISH">Z_FINISH</a> 4
-/* Allowed flush values ; see <a href="#deflate">deflate</a>() below for details */
-
-#define <a name="Z_OK">Z_OK</a> 0
-#define <a name="Z_STREAM_END">Z_STREAM_END</a> 1
-#define <a name="Z_NEED_DICT">Z_NEED_DICT</a> 2
-#define <a name="Z_ERRNO">Z_ERRNO</a> (-1)
-#define <a name="Z_STREAM_ERROR">Z_STREAM_ERROR</a> (-2)
-#define <a name="Z_DATA_ERROR">Z_DATA_ERROR</a> (-3)
-#define <a name="Z_MEM_ERROR">Z_MEM_ERROR</a> (-4)
-#define <a name="Z_BUF_ERROR">Z_BUF_ERROR</a> (-5)
-#define <a name="Z_VERSION_ERROR">Z_VERSION_ERROR</a> (-6)
-/* Return codes for the compression/decompression functions. Negative
- * values are errors, positive values are used for special but normal events.
- */
-
-#define <a name="Z_NO_COMPRESSION">Z_NO_COMPRESSION</a> 0
-#define <a name="Z_BEST_SPEED">Z_BEST_SPEED</a> 1
-#define <a name="Z_BEST_COMPRESSION">Z_BEST_COMPRESSION</a> 9
-#define <a name="Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> (-1)
-/* compression levels */
-
-#define <a name="Z_FILTERED">Z_FILTERED</a> 1
-#define <a name="Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> 2
-#define <a name="Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> 0
-/* compression strategy ; see <a href="#deflateInit2">deflateInit2</a>() below for details */
-
-#define <a name="Z_BINARY">Z_BINARY</a> 0
-#define <a name="Z_ASCII">Z_ASCII</a> 1
-#define <a name="Z_UNKNOWN">Z_UNKNOWN</a> 2
-/* Possible values of the <a href="#data_type">data_type</a> field */
-
-#define <a name="Z_DEFLATED">Z_DEFLATED</a> 8
-/* The <a href="#deflate">deflate</a> compression method (the only one supported in this version) */
-
-#define <a name="Z_NULL">Z_NULL</a> 0 /* for initializing <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a>, <a href="#opaque">opaque</a> */
-
-#define <a name="zlib_version">zlib_version</a> <a href="#zlibVersion">zlibVersion</a>()
-/* for compatibility with versions less than 1.0.2 */
-</pre>
-</font>
-
-<hr>
-<a name="Misc"><h2> Misc </h2>
- <a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a> are macros to allow checking the zlib version
- and the compiler's view of <a href="#z_stream_s">z_stream</a>.
- <p>
- Other functions:
- <dl>
- <font color="Blue"><dt> const char * <a name="zError">zError</a> (int err);</font>
- <font color="Blue"><dt> int <a name="inflateSyncPoint">inflateSyncPoint</a> (<a href="#z_streamp">z_streamp</a> z);</font>
- <font color="Blue"><dt> const uLongf * <a name="get_crc_table">get_crc_table</a> (void);</font>
- </dl>
- <hr>
- <font size="-1">
- Last update: Wed Oct 13 20:42:34 1999<br>
- piapi@csie.ntu.edu.tw
- </font>
-
-</body>
-</html>
diff --git a/cpukit/zlib/preinstall.am b/cpukit/zlib/preinstall.am
new file mode 100644
index 0000000000..c9c95eefc6
--- /dev/null
+++ b/cpukit/zlib/preinstall.am
@@ -0,0 +1,42 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES = $(PREINSTALL_DIRS)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES = $(TMPINSTALL_FILES)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES += $(PREINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_LIB)/libz.a: libz.a $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/libz.a
+TMPINSTALL_FILES += $(PROJECT_LIB)/libz.a
+
+$(PROJECT_INCLUDE)/zlib.h: zlib.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/zlib.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/zlib.h
+
+$(PROJECT_INCLUDE)/zconf.h: zconf.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/zconf.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/zconf.h
+
diff --git a/cpukit/zlib/projects/README.projects b/cpukit/zlib/projects/README.projects
deleted file mode 100644
index 1c029e4a34..0000000000
--- a/cpukit/zlib/projects/README.projects
+++ /dev/null
@@ -1,41 +0,0 @@
-This directory contains project files for building zlib under various
-Integrated Development Environments (IDE).
-
-If you wish to submit a new project to this directory, you should comply
-to the following requirements. Otherwise (e.g. if you wish to integrate
-a custom piece of code that changes the zlib interface or its behavior),
-please consider submitting the project to the contrib directory.
-
-
-Requirements
-============
-
-- The project must build zlib using the source files from the official
- zlib source distribution, exclusively.
-
-- If the project produces redistributable builds (e.g. shared objects
- or DLL files), these builds must be compatible to those produced by
- makefiles, if such makefiles exist in the zlib distribution.
- In particular, if the project produces a DLL build for the Win32
- platform, this build must comply to the officially-ammended Win32 DLL
- Application Binary Interface (ABI), described in win32/DLL_FAQ.txt.
-
-- The project may provide additional build targets, which depend on
- 3rd-party (unofficially-supported) software, present in the contrib
- directory. For example, it is possible to provide an "ASM build",
- besides the officially-supported build, and have ASM source files
- among its dependencies.
-
-- If there are significant differences between the project files created
- by different versions of an IDE (e.g. Visual C++ 6.0 vs. 7.0), the name
- of the project directory should contain the version number of the IDE
- for which the project is intended (e.g. "visualc6" for Visual C++ 6.0,
- or "visualc7" for Visual C++ 7.0 and 7.1).
-
-
-Current projects
-================
-
-visualc6/ by Simon-Pierre Cadieux <methodex@methodex.ca>
- and Cosmin Truta <cosmint@cs.ubbcluj.ro>
- Project for Microsoft Visual C++ 6.0
diff --git a/cpukit/zlib/projects/visualc6/README.txt b/cpukit/zlib/projects/visualc6/README.txt
deleted file mode 100644
index d0296c272c..0000000000
--- a/cpukit/zlib/projects/visualc6/README.txt
+++ /dev/null
@@ -1,73 +0,0 @@
-Microsoft Developer Studio Project Files, Format Version 6.00 for zlib.
-
-Copyright (C) 2000-2004 Simon-Pierre Cadieux.
-Copyright (C) 2004 Cosmin Truta.
-For conditions of distribution and use, see copyright notice in zlib.h.
-
-
-This project builds the zlib binaries as follows:
-
-* Win32_DLL_Release\zlib1.dll DLL build
-* Win32_DLL_Debug\zlib1d.dll DLL build (debug version)
-* Win32_DLL_ASM_Release\zlib1.dll DLL build using ASM code
-* Win32_DLL_ASM_Debug\zlib1d.dll DLL build using ASM code (debug version)
-* Win32_LIB_Release\zlib.lib static build
-* Win32_LIB_Debug\zlibd.lib static build (debug version)
-* Win32_LIB_ASM_Release\zlib.lib static build using ASM code
-* Win32_LIB_ASM_Debug\zlibd.lib static build using ASM code (debug version)
-
-
-For more information regarding the DLL builds, please see the DLL FAQ
-in ..\..\win32\DLL_FAQ.txt.
-
-
-To build and test:
-
-1) On the main menu, select "File | Open Workspace".
- Open "zlib.dsw".
-
-2) Select "Build | Set Active Configuration".
- Choose the configuration you wish to build.
-
-3) Select "Build | Clean".
-
-4) Select "Build | Build ... (F7)". Ignore warning messages about
- not being able to find certain include files (e.g. alloc.h).
-
-5) If you built one of the sample programs (example or minigzip),
- select "Build | Execute ... (Ctrl+F5)".
-
-
-To use:
-
-1) Select "Project | Settings (Alt+F7)".
- Make note of the configuration names used in your project.
- Usually, these names are "Win32 Release" and "Win32 Debug".
-
-2) In the Workspace window, select the "FileView" tab.
- Right-click on the root item "Workspace '...'".
- Select "Insert Project into Workspace".
- Switch on the checkbox "Dependency of:", and select the name
- of your project. Open "zlib.dsp".
-
-3) Select "Build | Configurations".
- For each configuration of your project:
- 3.1) Choose the zlib configuration you wish to use.
- 3.2) Click on "Add".
- 3.3) Set the new zlib configuration name to the name used by
- the configuration from the current iteration.
-
-4) Select "Build | Set Active Configuration".
- Choose the configuration you wish to build.
-
-5) Select "Build | Build ... (F7)".
-
-6) If you built an executable program, select
- "Build | Execute ... (Ctrl+F5)".
-
-
-Note:
-
-To build the ASM-enabled code, you need Microsoft Assembler
-(ML.EXE). You can get it by downloading and installing the
-latest Processor Pack for Visual C++ 6.0.
diff --git a/cpukit/zlib/projects/visualc6/example.dsp b/cpukit/zlib/projects/visualc6/example.dsp
deleted file mode 100644
index d3580525bd..0000000000
--- a/cpukit/zlib/projects/visualc6/example.dsp
+++ /dev/null
@@ -1,278 +0,0 @@
-# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=example - Win32 LIB Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "example.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 LIB Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "example - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 DLL Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 DLL Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 LIB Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "example - Win32 LIB Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "example - Win32 DLL ASM Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "example___Win32_DLL_ASM_Release"
-# PROP BASE Intermediate_Dir "example___Win32_DLL_ASM_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_DLL_ASM_Release"
-# PROP Intermediate_Dir "Win32_DLL_ASM_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "example - Win32 DLL ASM Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "example___Win32_DLL_ASM_Debug"
-# PROP BASE Intermediate_Dir "example___Win32_DLL_ASM_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_DLL_ASM_Debug"
-# PROP Intermediate_Dir "Win32_DLL_ASM_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "example - Win32 DLL Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "example___Win32_DLL_Release"
-# PROP BASE Intermediate_Dir "example___Win32_DLL_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_DLL_Release"
-# PROP Intermediate_Dir "Win32_DLL_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "example - Win32 DLL Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "example___Win32_DLL_Debug"
-# PROP BASE Intermediate_Dir "example___Win32_DLL_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_DLL_Debug"
-# PROP Intermediate_Dir "Win32_DLL_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "example - Win32 LIB ASM Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "example___Win32_LIB_ASM_Release"
-# PROP BASE Intermediate_Dir "example___Win32_LIB_ASM_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_LIB_ASM_Release"
-# PROP Intermediate_Dir "Win32_LIB_ASM_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "example - Win32 LIB ASM Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "example___Win32_LIB_ASM_Debug"
-# PROP BASE Intermediate_Dir "example___Win32_LIB_ASM_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_LIB_ASM_Debug"
-# PROP Intermediate_Dir "Win32_LIB_ASM_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "example - Win32 LIB Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "example___Win32_LIB_Release"
-# PROP BASE Intermediate_Dir "example___Win32_LIB_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_LIB_Release"
-# PROP Intermediate_Dir "Win32_LIB_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "example - Win32 LIB Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "example___Win32_LIB_Debug"
-# PROP BASE Intermediate_Dir "example___Win32_LIB_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_LIB_Debug"
-# PROP Intermediate_Dir "Win32_LIB_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "example - Win32 DLL ASM Release"
-# Name "example - Win32 DLL ASM Debug"
-# Name "example - Win32 DLL Release"
-# Name "example - Win32 DLL Debug"
-# Name "example - Win32 LIB ASM Release"
-# Name "example - Win32 LIB ASM Debug"
-# Name "example - Win32 LIB Release"
-# Name "example - Win32 LIB Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\..\example.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\..\zconf.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\zlib.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/cpukit/zlib/projects/visualc6/minigzip.dsp b/cpukit/zlib/projects/visualc6/minigzip.dsp
deleted file mode 100644
index 71034684d8..0000000000
--- a/cpukit/zlib/projects/visualc6/minigzip.dsp
+++ /dev/null
@@ -1,278 +0,0 @@
-# Microsoft Developer Studio Project File - Name="minigzip" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=minigzip - Win32 LIB Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "minigzip.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "minigzip.mak" CFG="minigzip - Win32 LIB Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "minigzip - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 DLL Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 DLL Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 LIB Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "minigzip - Win32 LIB Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "minigzip - Win32 DLL ASM Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "minigzip___Win32_DLL_ASM_Release"
-# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_ASM_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_DLL_ASM_Release"
-# PROP Intermediate_Dir "Win32_DLL_ASM_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 DLL ASM Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "minigzip___Win32_DLL_ASM_Debug"
-# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_ASM_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_DLL_ASM_Debug"
-# PROP Intermediate_Dir "Win32_DLL_ASM_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 DLL Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "minigzip___Win32_DLL_Release"
-# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_DLL_Release"
-# PROP Intermediate_Dir "Win32_DLL_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 DLL Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "minigzip___Win32_DLL_Debug"
-# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_DLL_Debug"
-# PROP Intermediate_Dir "Win32_DLL_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "minigzip___Win32_LIB_ASM_Release"
-# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_ASM_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_LIB_ASM_Release"
-# PROP Intermediate_Dir "Win32_LIB_ASM_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "minigzip___Win32_LIB_ASM_Debug"
-# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_ASM_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_LIB_ASM_Debug"
-# PROP Intermediate_Dir "Win32_LIB_ASM_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 LIB Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "minigzip___Win32_LIB_Release"
-# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_LIB_Release"
-# PROP Intermediate_Dir "Win32_LIB_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "minigzip - Win32 LIB Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "minigzip___Win32_LIB_Debug"
-# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_LIB_Debug"
-# PROP Intermediate_Dir "Win32_LIB_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "minigzip - Win32 DLL ASM Release"
-# Name "minigzip - Win32 DLL ASM Debug"
-# Name "minigzip - Win32 DLL Release"
-# Name "minigzip - Win32 DLL Debug"
-# Name "minigzip - Win32 LIB ASM Release"
-# Name "minigzip - Win32 LIB ASM Debug"
-# Name "minigzip - Win32 LIB Release"
-# Name "minigzip - Win32 LIB Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\..\minigzip.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\..\zconf.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\zlib.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/cpukit/zlib/projects/visualc6/zlib.dsp b/cpukit/zlib/projects/visualc6/zlib.dsp
deleted file mode 100644
index 00f54ea422..0000000000
--- a/cpukit/zlib/projects/visualc6/zlib.dsp
+++ /dev/null
@@ -1,621 +0,0 @@
-# Microsoft Developer Studio Project File - Name="zlib" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=zlib - Win32 LIB Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "zlib.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "zlib.mak" CFG="zlib - Win32 LIB Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "zlib - Win32 DLL ASM Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlib - Win32 DLL ASM Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlib - Win32 DLL Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlib - Win32 DLL Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlib - Win32 LIB ASM Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "zlib - Win32 LIB ASM Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE "zlib - Win32 LIB Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "zlib - Win32 LIB Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-
-!IF "$(CFG)" == "zlib - Win32 DLL ASM Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlib___Win32_DLL_ASM_Release"
-# PROP BASE Intermediate_Dir "zlib___Win32_DLL_ASM_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_DLL_ASM_Release"
-# PROP Intermediate_Dir "Win32_DLL_ASM_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /D "ASMV" /D "ASMINF" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 /nologo /dll /machine:I386 /out:"Win32_DLL_ASM_Release\zlib1.dll"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "zlib___Win32_DLL_ASM_Debug"
-# PROP BASE Intermediate_Dir "zlib___Win32_DLL_ASM_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_DLL_ASM_Debug"
-# PROP Intermediate_Dir "Win32_DLL_ASM_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /D "ASMV" /D "ASMINF" /FR /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"Win32_DLL_ASM_Debug\zlib1d.dll" /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlib___Win32_DLL_Release"
-# PROP BASE Intermediate_Dir "zlib___Win32_DLL_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_DLL_Release"
-# PROP Intermediate_Dir "Win32_DLL_Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 /nologo /dll /machine:I386 /out:"Win32_DLL_Release\zlib1.dll"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "zlib___Win32_DLL_Debug"
-# PROP BASE Intermediate_Dir "zlib___Win32_DLL_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_DLL_Debug"
-# PROP Intermediate_Dir "Win32_DLL_Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"Win32_DLL_Debug\zlib1d.dll" /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlib___Win32_LIB_ASM_Release"
-# PROP BASE Intermediate_Dir "zlib___Win32_LIB_ASM_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_LIB_ASM_Release"
-# PROP Intermediate_Dir "Win32_LIB_ASM_Release"
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /D "ASMV" /D "ASMINF" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "zlib___Win32_LIB_ASM_Debug"
-# PROP BASE Intermediate_Dir "zlib___Win32_LIB_ASM_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_LIB_ASM_Debug"
-# PROP Intermediate_Dir "Win32_LIB_ASM_Debug"
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /D "ASMV" /D "ASMINF" /FR /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"Win32_LIB_ASM_Debug\zlibd.lib"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlib___Win32_LIB_Release"
-# PROP BASE Intermediate_Dir "zlib___Win32_LIB_Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Win32_LIB_Release"
-# PROP Intermediate_Dir "Win32_LIB_Release"
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "zlib___Win32_LIB_Debug"
-# PROP BASE Intermediate_Dir "zlib___Win32_LIB_Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Win32_LIB_Debug"
-# PROP Intermediate_Dir "Win32_LIB_Debug"
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c
-# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-RSC=rc.exe
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"Win32_LIB_Debug\zlibd.lib"
-
-!ENDIF
-
-# Begin Target
-
-# Name "zlib - Win32 DLL ASM Release"
-# Name "zlib - Win32 DLL ASM Debug"
-# Name "zlib - Win32 DLL Release"
-# Name "zlib - Win32 DLL Debug"
-# Name "zlib - Win32 LIB ASM Release"
-# Name "zlib - Win32 LIB ASM Debug"
-# Name "zlib - Win32 LIB Release"
-# Name "zlib - Win32 LIB Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\..\adler32.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\compress.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\crc32.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\deflate.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\gzclose.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\gzlib.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\gzread.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\gzwrite.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\infback.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inffast.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inflate.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inftrees.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\trees.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\uncompr.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\win32\zlib.def
-
-!IF "$(CFG)" == "zlib - Win32 DLL ASM Release"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug"
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug"
-
-# PROP Exclude_From_Build 1
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\zutil.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\..\crc32.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\deflate.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inffast.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inffixed.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inflate.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\inftrees.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\trees.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\zconf.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\zlib.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\zutil.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# Begin Source File
-
-SOURCE=..\..\win32\zlib1.rc
-# End Source File
-# End Group
-# Begin Group "Assembler Files (Unsupported)"
-
-# PROP Default_Filter "asm;obj;c;cpp;cxx;h;hpp;hxx"
-# Begin Source File
-
-SOURCE=..\..\contrib\masmx86\gvmat32.asm
-
-!IF "$(CFG)" == "zlib - Win32 DLL ASM Release"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_DLL_ASM_Release
-InputPath=..\..\contrib\masmx86\gvmat32.asm
-InputName=gvmat32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_DLL_ASM_Debug
-InputPath=..\..\contrib\masmx86\gvmat32.asm
-InputName=gvmat32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_LIB_ASM_Release
-InputPath=..\..\contrib\masmx86\gvmat32.asm
-InputName=gvmat32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_LIB_ASM_Debug
-InputPath=..\..\contrib\masmx86\gvmat32.asm
-InputName=gvmat32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug"
-
-# PROP Exclude_From_Build 1
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\contrib\masmx86\gvmat32c.c
-
-!IF "$(CFG)" == "zlib - Win32 DLL ASM Release"
-
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug"
-
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release"
-
-# PROP Exclude_From_Build 1
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug"
-
-# PROP Exclude_From_Build 1
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release"
-
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug"
-
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release"
-
-# PROP Exclude_From_Build 1
-# ADD CPP /I "..\.."
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug"
-
-# PROP Exclude_From_Build 1
-# ADD CPP /I "..\.."
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\contrib\masmx86\inffas32.asm
-
-!IF "$(CFG)" == "zlib - Win32 DLL ASM Release"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_DLL_ASM_Release
-InputPath=..\..\contrib\masmx86\inffas32.asm
-InputName=inffas32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_DLL_ASM_Debug
-InputPath=..\..\contrib\masmx86\inffas32.asm
-InputName=inffas32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_LIB_ASM_Release
-InputPath=..\..\contrib\masmx86\inffas32.asm
-InputName=inffas32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug"
-
-# Begin Custom Build - Assembling...
-IntDir=.\Win32_LIB_ASM_Debug
-InputPath=..\..\contrib\masmx86\inffas32.asm
-InputName=inffas32
-
-"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)"
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release"
-
-# PROP Exclude_From_Build 1
-
-!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug"
-
-# PROP Exclude_From_Build 1
-
-!ENDIF
-
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\README.txt
-# End Source File
-# End Target
-# End Project
diff --git a/cpukit/zlib/projects/visualc6/zlib.dsw b/cpukit/zlib/projects/visualc6/zlib.dsw
deleted file mode 100644
index 3a771fce07..0000000000
--- a/cpukit/zlib/projects/visualc6/zlib.dsw
+++ /dev/null
@@ -1,59 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "example"=.\example.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name zlib
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "minigzip"=.\minigzip.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name zlib
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "zlib"=.\zlib.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/cpukit/zlib/qnx/package.qpg b/cpukit/zlib/qnx/package.qpg
deleted file mode 100644
index 470d2d5315..0000000000
--- a/cpukit/zlib/qnx/package.qpg
+++ /dev/null
@@ -1,141 +0,0 @@
-<QPG:Generation>
- <QPG:Options>
- <QPG:User unattended="no" verbosity="2" listfiles="yes"/>
- <QPG:Defaults type="qnx_package"/>
- <QPG:Source></QPG:Source>
- <QPG:Release number="+"/>
- <QPG:Build></QPG:Build>
- <QPG:FileSorting strip="yes"/>
- <QPG:Package targets="combine"/>
- <QPG:Repository generate="yes"/>
- <QPG:FinalDir></QPG:FinalDir>
- <QPG:Cleanup></QPG:Cleanup>
- </QPG:Options>
-
- <QPG:Responsible>
- <QPG:Company></QPG:Company>
- <QPG:Department></QPG:Department>
- <QPG:Group></QPG:Group>
- <QPG:Team></QPG:Team>
- <QPG:Employee></QPG:Employee>
- <QPG:EmailAddress></QPG:EmailAddress>
- </QPG:Responsible>
-
- <QPG:Values>
- <QPG:Files>
- <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
- <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
- <QPG:Add file="../libz.so.1.2.4" install="/opt/lib/" user="root:bin" permission="644"/>
- <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.4"/>
- <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.4"/>
- <QPG:Add file="../libz.so.1.2.4" install="/opt/lib/" component="slib"/>
- </QPG:Files>
-
- <QPG:PackageFilter>
- <QPM:PackageManifest>
- <QPM:PackageDescription>
- <QPM:PackageType>Library</QPM:PackageType>
- <QPM:PackageReleaseNotes></QPM:PackageReleaseNotes>
- <QPM:PackageReleaseUrgency>Medium</QPM:PackageReleaseUrgency>
- <QPM:PackageRepository></QPM:PackageRepository>
- <QPM:FileVersion>2.0</QPM:FileVersion>
- </QPM:PackageDescription>
-
- <QPM:ProductDescription>
- <QPM:ProductName>zlib</QPM:ProductName>
- <QPM:ProductIdentifier>zlib</QPM:ProductIdentifier>
- <QPM:ProductEmail>alain.bonnefoy@icbt.com</QPM:ProductEmail>
- <QPM:VendorName>Public</QPM:VendorName>
- <QPM:VendorInstallName>public</QPM:VendorInstallName>
- <QPM:VendorURL>www.gzip.org/zlib</QPM:VendorURL>
- <QPM:VendorEmbedURL></QPM:VendorEmbedURL>
- <QPM:VendorEmail></QPM:VendorEmail>
- <QPM:AuthorName>Jean-Loup Gailly,Mark Adler</QPM:AuthorName>
- <QPM:AuthorURL>www.gzip.org/zlib</QPM:AuthorURL>
- <QPM:AuthorEmbedURL></QPM:AuthorEmbedURL>
- <QPM:AuthorEmail>zlib@gzip.org</QPM:AuthorEmail>
- <QPM:ProductIconSmall></QPM:ProductIconSmall>
- <QPM:ProductIconLarge></QPM:ProductIconLarge>
- <QPM:ProductDescriptionShort>A massively spiffy yet delicately unobtrusive compression library.</QPM:ProductDescriptionShort>
- <QPM:ProductDescriptionLong>zlib is designed to be a free, general-purpose, legally unencumbered, lossless data compression library for use on virtually any computer hardware and operating system.</QPM:ProductDescriptionLong>
- <QPM:ProductDescriptionURL>http://www.gzip.org/zlib</QPM:ProductDescriptionURL>
- <QPM:ProductDescriptionEmbedURL></QPM:ProductDescriptionEmbedURL>
- </QPM:ProductDescription>
-
- <QPM:ReleaseDescription>
- <QPM:ReleaseVersion>1.2.4</QPM:ReleaseVersion>
- <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
- <QPM:ReleaseStability>Stable</QPM:ReleaseStability>
- <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
- <QPM:ReleaseNoteMajor></QPM:ReleaseNoteMajor>
- <QPM:ExcludeCountries>
- <QPM:Country></QPM:Country>
- </QPM:ExcludeCountries>
-
- <QPM:ReleaseCopyright>No License</QPM:ReleaseCopyright>
- </QPM:ReleaseDescription>
-
- <QPM:ContentDescription>
- <QPM:ContentTopic xmlmultiple="true">Software Development/Libraries and Extensions/C Libraries</QPM:ContentTopic>
- <QPM:ContentKeyword>zlib,compression</QPM:ContentKeyword>
- <QPM:TargetOS>qnx6</QPM:TargetOS>
- <QPM:HostOS>qnx6</QPM:HostOS>
- <QPM:DisplayEnvironment xmlmultiple="true">None</QPM:DisplayEnvironment>
- <QPM:TargetAudience xmlmultiple="true">Developer</QPM:TargetAudience>
- </QPM:ContentDescription>
- </QPM:PackageManifest>
- </QPG:PackageFilter>
-
- <QPG:PackageFilter proc="none" target="none">
- <QPM:PackageManifest>
- <QPM:ProductInstallationDependencies>
- <QPM:ProductRequirements></QPM:ProductRequirements>
- </QPM:ProductInstallationDependencies>
-
- <QPM:ProductInstallationProcedure>
- <QPM:Script xmlmultiple="true">
- <QPM:ScriptName></QPM:ScriptName>
- <QPM:ScriptType>Install</QPM:ScriptType>
- <QPM:ScriptTiming>Post</QPM:ScriptTiming>
- <QPM:ScriptBlocking>No</QPM:ScriptBlocking>
- <QPM:ScriptResult>Ignore</QPM:ScriptResult>
- <QPM:ShortDescription></QPM:ShortDescription>
- <QPM:UseBinaries>No</QPM:UseBinaries>
- <QPM:Priority>Optional</QPM:Priority>
- </QPM:Script>
- </QPM:ProductInstallationProcedure>
- </QPM:PackageManifest>
-
- <QPM:Launch>
- </QPM:Launch>
- </QPG:PackageFilter>
-
- <QPG:PackageFilter type="core" component="none">
- <QPM:PackageManifest>
- <QPM:ProductInstallationProcedure>
- <QPM:OrderDependency xmlmultiple="true">
- <QPM:Order>InstallOver</QPM:Order>
- <QPM:Product>zlib</QPM:Product>
- </QPM:OrderDependency>
- </QPM:ProductInstallationProcedure>
- </QPM:PackageManifest>
-
- <QPM:Launch>
- </QPM:Launch>
- </QPG:PackageFilter>
-
- <QPG:PackageFilter type="core" component="dev">
- <QPM:PackageManifest>
- <QPM:ProductInstallationProcedure>
- <QPM:OrderDependency xmlmultiple="true">
- <QPM:Order>InstallOver</QPM:Order>
- <QPM:Product>zlib-dev</QPM:Product>
- </QPM:OrderDependency>
- </QPM:ProductInstallationProcedure>
- </QPM:PackageManifest>
-
- <QPM:Launch>
- </QPM:Launch>
- </QPG:PackageFilter>
- </QPG:Values>
-</QPG:Generation>
diff --git a/cpukit/zlib/win32/DLL_FAQ.txt b/cpukit/zlib/win32/DLL_FAQ.txt
deleted file mode 100644
index 12c009018c..0000000000
--- a/cpukit/zlib/win32/DLL_FAQ.txt
+++ /dev/null
@@ -1,397 +0,0 @@
-
- Frequently Asked Questions about ZLIB1.DLL
-
-
-This document describes the design, the rationale, and the usage
-of the official DLL build of zlib, named ZLIB1.DLL. If you have
-general questions about zlib, you should see the file "FAQ" found
-in the zlib distribution, or at the following location:
- http://www.gzip.org/zlib/zlib_faq.html
-
-
- 1. What is ZLIB1.DLL, and how can I get it?
-
- - ZLIB1.DLL is the official build of zlib as a DLL.
- (Please remark the character '1' in the name.)
-
- Pointers to a precompiled ZLIB1.DLL can be found in the zlib
- web site at:
- http://www.zlib.net/
-
- Applications that link to ZLIB1.DLL can rely on the following
- specification:
-
- * The exported symbols are exclusively defined in the source
- files "zlib.h" and "zlib.def", found in an official zlib
- source distribution.
- * The symbols are exported by name, not by ordinal.
- * The exported names are undecorated.
- * The calling convention of functions is "C" (CDECL).
- * The ZLIB1.DLL binary is linked to MSVCRT.DLL.
-
- The archive in which ZLIB1.DLL is bundled contains compiled
- test programs that must run with a valid build of ZLIB1.DLL.
- It is recommended to download the prebuilt DLL from the zlib
- web site, instead of building it yourself, to avoid potential
- incompatibilities that could be introduced by your compiler
- and build settings. If you do build the DLL yourself, please
- make sure that it complies with all the above requirements,
- and it runs with the precompiled test programs, bundled with
- the original ZLIB1.DLL distribution.
-
- If, for any reason, you need to build an incompatible DLL,
- please use a different file name.
-
-
- 2. Why did you change the name of the DLL to ZLIB1.DLL?
- What happened to the old ZLIB.DLL?
-
- - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required
- compilation settings that were incompatible to those used by
- a static build. The DLL settings were supposed to be enabled
- by defining the macro ZLIB_DLL, before including "zlib.h".
- Incorrect handling of this macro was silently accepted at
- build time, resulting in two major problems:
-
- * ZLIB_DLL was missing from the old makefile. When building
- the DLL, not all people added it to the build options. In
- consequence, incompatible incarnations of ZLIB.DLL started
- to circulate around the net.
-
- * When switching from using the static library to using the
- DLL, applications had to define the ZLIB_DLL macro and
- to recompile all the sources that contained calls to zlib
- functions. Failure to do so resulted in creating binaries
- that were unable to run with the official ZLIB.DLL build.
-
- The only possible solution that we could foresee was to make
- a binary-incompatible change in the DLL interface, in order to
- remove the dependency on the ZLIB_DLL macro, and to release
- the new DLL under a different name.
-
- We chose the name ZLIB1.DLL, where '1' indicates the major
- zlib version number. We hope that we will not have to break
- the binary compatibility again, at least not as long as the
- zlib-1.x series will last.
-
- There is still a ZLIB_DLL macro, that can trigger a more
- efficient build and use of the DLL, but compatibility no
- longer dependents on it.
-
-
- 3. Can I build ZLIB.DLL from the new zlib sources, and replace
- an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier?
-
- - In principle, you can do it by assigning calling convention
- keywords to the macros ZEXPORT and ZEXPORTVA. In practice,
- it depends on what you mean by "an old ZLIB.DLL", because the
- old DLL exists in several mutually-incompatible versions.
- You have to find out first what kind of calling convention is
- being used in your particular ZLIB.DLL build, and to use the
- same one in the new build. If you don't know what this is all
- about, you might be better off if you would just leave the old
- DLL intact.
-
-
- 4. Can I compile my application using the new zlib interface, and
- link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or
- earlier?
-
- - The official answer is "no"; the real answer depends again on
- what kind of ZLIB.DLL you have. Even if you are lucky, this
- course of action is unreliable.
-
- If you rebuild your application and you intend to use a newer
- version of zlib (post- 1.1.4), it is strongly recommended to
- link it to the new ZLIB1.DLL.
-
-
- 5. Why are the zlib symbols exported by name, and not by ordinal?
-
- - Although exporting symbols by ordinal is a little faster, it
- is risky. Any single glitch in the maintenance or use of the
- DEF file that contains the ordinals can result in incompatible
- builds and frustrating crashes. Simply put, the benefits of
- exporting symbols by ordinal do not justify the risks.
-
- Technically, it should be possible to maintain ordinals in
- the DEF file, and still export the symbols by name. Ordinals
- exist in every DLL, and even if the dynamic linking performed
- at the DLL startup is searching for names, ordinals serve as
- hints, for a faster name lookup. However, if the DEF file
- contains ordinals, the Microsoft linker automatically builds
- an implib that will cause the executables linked to it to use
- those ordinals, and not the names. It is interesting to
- notice that the GNU linker for Win32 does not suffer from this
- problem.
-
- It is possible to avoid the DEF file if the exported symbols
- are accompanied by a "__declspec(dllexport)" attribute in the
- source files. You can do this in zlib by predefining the
- ZLIB_DLL macro.
-
-
- 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling
- convention. Why not use the STDCALL convention?
- STDCALL is the standard convention in Win32, and I need it in
- my Visual Basic project!
-
- (For readability, we use CDECL to refer to the convention
- triggered by the "__cdecl" keyword, STDCALL to refer to
- the convention triggered by "__stdcall", and FASTCALL to
- refer to the convention triggered by "__fastcall".)
-
- - Most of the native Windows API functions (without varargs) use
- indeed the WINAPI convention (which translates to STDCALL in
- Win32), but the standard C functions use CDECL. If a user
- application is intrinsically tied to the Windows API (e.g.
- it calls native Windows API functions such as CreateFile()),
- sometimes it makes sense to decorate its own functions with
- WINAPI. But if ANSI C or POSIX portability is a goal (e.g.
- it calls standard C functions such as fopen()), it is not a
- sound decision to request the inclusion of <windows.h>, or to
- use non-ANSI constructs, for the sole purpose to make the user
- functions STDCALL-able.
-
- The functionality offered by zlib is not in the category of
- "Windows functionality", but is more like "C functionality".
-
- Technically, STDCALL is not bad; in fact, it is slightly
- faster than CDECL, and it works with variable-argument
- functions, just like CDECL. It is unfortunate that, in spite
- of using STDCALL in the Windows API, it is not the default
- convention used by the C compilers that run under Windows.
- The roots of the problem reside deep inside the unsafety of
- the K&R-style function prototypes, where the argument types
- are not specified; but that is another story for another day.
-
- The remaining fact is that CDECL is the default convention.
- Even if an explicit convention is hard-coded into the function
- prototypes inside C headers, problems may appear. The
- necessity to expose the convention in users' callbacks is one
- of these problems.
-
- The calling convention issues are also important when using
- zlib in other programming languages. Some of them, like Ada
- (GNAT) and Fortran (GNU G77), have C bindings implemented
- initially on Unix, and relying on the C calling convention.
- On the other hand, the pre- .NET versions of Microsoft Visual
- Basic require STDCALL, while Borland Delphi prefers, although
- it does not require, FASTCALL.
-
- In fairness to all possible uses of zlib outside the C
- programming language, we choose the default "C" convention.
- Anyone interested in different bindings or conventions is
- encouraged to maintain specialized projects. The "contrib/"
- directory from the zlib distribution already holds a couple
- of foreign bindings, such as Ada, C++, and Delphi.
-
-
- 7. I need a DLL for my Visual Basic project. What can I do?
-
- - Define the ZLIB_WINAPI macro before including "zlib.h", when
- building both the DLL and the user application (except that
- you don't need to define anything when using the DLL in Visual
- Basic). The ZLIB_WINAPI macro will switch on the WINAPI
- (STDCALL) convention. The name of this DLL must be different
- than the official ZLIB1.DLL.
-
- Gilles Vollant has contributed a build named ZLIBWAPI.DLL,
- with the ZLIB_WINAPI macro turned on, and with the minizip
- functionality built in. For more information, please read
- the notes inside "contrib/vstudio/readme.txt", found in the
- zlib distribution.
-
-
- 8. I need to use zlib in my Microsoft .NET project. What can I
- do?
-
- - Henrik Ravn has contributed a .NET wrapper around zlib. Look
- into contrib/dotzlib/, inside the zlib distribution.
-
-
- 9. If my application uses ZLIB1.DLL, should I link it to
- MSVCRT.DLL? Why?
-
- - It is not required, but it is recommended to link your
- application to MSVCRT.DLL, if it uses ZLIB1.DLL.
-
- The executables (.EXE, .DLL, etc.) that are involved in the
- same process and are using the C run-time library (i.e. they
- are calling standard C functions), must link to the same
- library. There are several libraries in the Win32 system:
- CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.
- Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that
- depend on it should also be linked to MSVCRT.DLL.
-
-
-10. Why are you saying that ZLIB1.DLL and my application should
- be linked to the same C run-time (CRT) library? I linked my
- application and my DLLs to different C libraries (e.g. my
- application to a static library, and my DLLs to MSVCRT.DLL),
- and everything works fine.
-
- - If a user library invokes only pure Win32 API (accessible via
- <windows.h> and the related headers), its DLL build will work
- in any context. But if this library invokes standard C API,
- things get more complicated.
-
- There is a single Win32 library in a Win32 system. Every
- function in this library resides in a single DLL module, that
- is safe to call from anywhere. On the other hand, there are
- multiple versions of the C library, and each of them has its
- own separate internal state. Standalone executables and user
- DLLs that call standard C functions must link to a C run-time
- (CRT) library, be it static or shared (DLL). Intermixing
- occurs when an executable (not necessarily standalone) and a
- DLL are linked to different CRTs, and both are running in the
- same process.
-
- Intermixing multiple CRTs is possible, as long as their
- internal states are kept intact. The Microsoft Knowledge Base
- articles KB94248 "HOWTO: Use the C Run-Time" and KB140584
- "HOWTO: Link with the Correct C Run-Time (CRT) Library"
- mention the potential problems raised by intermixing.
-
- If intermixing works for you, it's because your application
- and DLLs are avoiding the corruption of each of the CRTs'
- internal states, maybe by careful design, or maybe by fortune.
-
- Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such
- as those provided by Borland, raises similar problems.
-
-
-11. Why are you linking ZLIB1.DLL to MSVCRT.DLL?
-
- - MSVCRT.DLL exists on every Windows 95 with a new service pack
- installed, or with Microsoft Internet Explorer 4 or later, and
- on all other Windows 4.x or later (Windows 98, Windows NT 4,
- or later). It is freely distributable; if not present in the
- system, it can be downloaded from Microsoft or from other
- software provider for free.
-
- The fact that MSVCRT.DLL does not exist on a virgin Windows 95
- is not so problematic. Windows 95 is scarcely found nowadays,
- Microsoft ended its support a long time ago, and many recent
- applications from various vendors, including Microsoft, do not
- even run on it. Furthermore, no serious user should run
- Windows 95 without a proper update installed.
-
-
-12. Why are you not linking ZLIB1.DLL to
- <<my favorite C run-time library>> ?
-
- - We considered and abandoned the following alternatives:
-
- * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or
- LIBCMT.LIB) is not a good option. People are using the DLL
- mainly to save disk space. If you are linking your program
- to a static C library, you may as well consider linking zlib
- in statically, too.
-
- * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because
- CRTDLL.DLL is present on every Win32 installation.
- Unfortunately, it has a series of problems: it does not
- work properly with Microsoft's C++ libraries, it does not
- provide support for 64-bit file offsets, (and so on...),
- and Microsoft discontinued its support a long time ago.
-
- * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied
- with the Microsoft .NET platform, and Visual C++ 7.0/7.1,
- raises problems related to the status of ZLIB1.DLL as a
- system component. According to the Microsoft Knowledge Base
- article KB326922 "INFO: Redistribution of the Shared C
- Runtime Component in Visual C++ .NET", MSVCR70.DLL and
- MSVCR71.DLL are not supposed to function as system DLLs,
- because they may clash with MSVCRT.DLL. Instead, the
- application's installer is supposed to put these DLLs
- (if needed) in the application's private directory.
- If ZLIB1.DLL depends on a non-system runtime, it cannot
- function as a redistributable system component.
-
- * Linking ZLIB1.DLL to non-Microsoft runtimes, such as
- Borland's, or Cygwin's, raises problems related to the
- reliable presence of these runtimes on Win32 systems.
- It's easier to let the DLL build of zlib up to the people
- who distribute these runtimes, and who may proceed as
- explained in the answer to Question 14.
-
-
-13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL,
- how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0
- (Visual Studio .NET) or newer?
-
- - Due to the problems explained in the Microsoft Knowledge Base
- article KB326922 (see the previous answer), the C runtime that
- comes with the VC7 environment is no longer considered a
- system component. That is, it should not be assumed that this
- runtime exists, or may be installed in a system directory.
- Since ZLIB1.DLL is supposed to be a system component, it may
- not depend on a non-system component.
-
- In order to link ZLIB1.DLL and your application to MSVCRT.DLL
- in VC7, you need the library of Visual C++ 6.0 or older. If
- you don't have this library at hand, it's probably best not to
- use ZLIB1.DLL.
-
- We are hoping that, in the future, Microsoft will provide a
- way to build applications linked to a proper system runtime,
- from the Visual C++ environment. Until then, you have a
- couple of alternatives, such as linking zlib in statically.
- If your application requires dynamic linking, you may proceed
- as explained in the answer to Question 14.
-
-
-14. I need to link my own DLL build to a CRT different than
- MSVCRT.DLL. What can I do?
-
- - Feel free to rebuild the DLL from the zlib sources, and link
- it the way you want. You should, however, clearly state that
- your build is unofficial. You should give it a different file
- name, and/or install it in a private directory that can be
- accessed by your application only, and is not visible to the
- others (i.e. it's neither in the PATH, nor in the SYSTEM or
- SYSTEM32 directories). Otherwise, your build may clash with
- applications that link to the official build.
-
- For example, in Cygwin, zlib is linked to the Cygwin runtime
- CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.
-
-
-15. May I include additional pieces of code that I find useful,
- link them in ZLIB1.DLL, and export them?
-
- - No. A legitimate build of ZLIB1.DLL must not include code
- that does not originate from the official zlib source code.
- But you can make your own private DLL build, under a different
- file name, as suggested in the previous answer.
-
- For example, zlib is a part of the VCL library, distributed
- with Borland Delphi and C++ Builder. The DLL build of VCL
- is a redistributable file, named VCLxx.DLL.
-
-
-16. May I remove some functionality out of ZLIB1.DLL, by enabling
- macros like NO_GZCOMPRESS or NO_GZIP at compile time?
-
- - No. A legitimate build of ZLIB1.DLL must provide the complete
- zlib functionality, as implemented in the official zlib source
- code. But you can make your own private DLL build, under a
- different file name, as suggested in the previous answer.
-
-
-17. I made my own ZLIB1.DLL build. Can I test it for compliance?
-
- - We prefer that you download the official DLL from the zlib
- web site. If you need something peculiar from this DLL, you
- can send your suggestion to the zlib mailing list.
-
- However, in case you do rebuild the DLL yourself, you can run
- it with the test programs found in the DLL distribution.
- Running these test programs is not a guarantee of compliance,
- but a failure can imply a detected problem.
-
-**
-
-This document is written and maintained by
-Cosmin Truta <cosmint@cs.ubbcluj.ro>
diff --git a/cpukit/zlib/win32/Makefile.bor b/cpukit/zlib/win32/Makefile.bor
deleted file mode 100644
index 3981d4246b..0000000000
--- a/cpukit/zlib/win32/Makefile.bor
+++ /dev/null
@@ -1,110 +0,0 @@
-# Makefile for zlib
-# Borland C++ for Win32
-#
-# Usage:
-# make -f win32/Makefile.bor
-# make -f win32/Makefile.bor LOCAL_ZLIB=-DASMV OBJA=match.obj OBJPA=+match.obj
-
-# ------------ Borland C++ ------------
-
-# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
-# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or
-# added to the declaration of LOC here:
-LOC = $(LOCAL_ZLIB)
-
-CC = bcc32
-AS = bcc32
-LD = bcc32
-AR = tlib
-CFLAGS = -a -d -k- -O2 $(LOC)
-ASFLAGS = $(LOC)
-LDFLAGS = $(LOC)
-
-
-# variables
-ZLIB_LIB = zlib.lib
-
-OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj
-OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-#OBJA =
-OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj
-OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
-#OBJPA=
-
-
-# targets
-all: $(ZLIB_LIB) example.exe minigzip.exe
-
-.c.obj:
- $(CC) -c $(CFLAGS) $<
-
-.asm.obj:
- $(AS) -c $(ASFLAGS) $<
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-example.obj: example.c zlib.h zconf.h
-
-minigzip.obj: minigzip.c zlib.h zconf.h
-
-
-# For the sake of the old Borland make,
-# the command line is cut to fit in the MS-DOS 128 byte limit:
-$(ZLIB_LIB): $(OBJ1) $(OBJ2) $(OBJA)
- -del $(ZLIB_LIB)
- $(AR) $(ZLIB_LIB) $(OBJP1)
- $(AR) $(ZLIB_LIB) $(OBJP2)
- $(AR) $(ZLIB_LIB) $(OBJPA)
-
-
-# testing
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-example.exe: example.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
-
-minigzip.exe: minigzip.obj $(ZLIB_LIB)
- $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
-
-
-# cleanup
-clean:
- -del $(ZLIB_LIB)
- -del *.obj
- -del *.exe
- -del *.tds
- -del zlib.bak
- -del foo.gz
diff --git a/cpukit/zlib/win32/Makefile.emx b/cpukit/zlib/win32/Makefile.emx
deleted file mode 100644
index 4d6ab0efa6..0000000000
--- a/cpukit/zlib/win32/Makefile.emx
+++ /dev/null
@@ -1,69 +0,0 @@
-# Makefile for zlib. Modified for emx/rsxnt by Chr. Spieler, 6/16/98.
-# Copyright (C) 1995-1998 Jean-loup Gailly.
-# For conditions of distribution and use, see copyright notice in zlib.h
-
-# To compile, or to compile and test, type:
-#
-# make -fmakefile.emx; make test -fmakefile.emx
-#
-
-CC=gcc -Zwin32
-
-#CFLAGS=-MMD -O
-#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
-#CFLAGS=-MMD -g -DDEBUG
-CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
- -Wstrict-prototypes -Wmissing-prototypes
-
-# If cp.exe is available, replace "copy /Y" with "cp -fp" .
-CP=copy /Y
-# If gnu install.exe is available, replace $(CP) with ginstall.
-INSTALL=$(CP)
-# The default value of RM is "rm -f." If "rm.exe" is found, comment out:
-RM=del
-LDLIBS=-L. -lzlib
-LD=$(CC) -s -o
-LDSHARED=$(CC)
-
-INCL=zlib.h zconf.h
-LIBS=zlib.a
-
-AR=ar rcs
-
-prefix=/usr/local
-exec_prefix = $(prefix)
-
-OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
- gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
-
-TEST_OBJS = example.o minigzip.o
-
-all: example.exe minigzip.exe
-
-test: all
- ./example
- echo hello world | .\minigzip | .\minigzip -d
-
-%.o : %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-zlib.a: $(OBJS)
- $(AR) $@ $(OBJS)
-
-%.exe : %.o $(LIBS)
- $(LD) $@ $< $(LDLIBS)
-
-
-.PHONY : clean
-
-clean:
- $(RM) *.d
- $(RM) *.o
- $(RM) *.exe
- $(RM) zlib.a
- $(RM) foo.gz
-
-DEPS := $(wildcard *.d)
-ifneq ($(DEPS),)
-include $(DEPS)
-endif
diff --git a/cpukit/zlib/win32/Makefile.gcc b/cpukit/zlib/win32/Makefile.gcc
deleted file mode 100644
index 0a33bf6a70..0000000000
--- a/cpukit/zlib/win32/Makefile.gcc
+++ /dev/null
@@ -1,164 +0,0 @@
-# Makefile for zlib, derived from Makefile.dj2.
-# Modified for mingw32 by C. Spieler, 6/16/98.
-# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003.
-# Last updated: 1-Aug-2003.
-# Tested under Cygwin and MinGW.
-
-# Copyright (C) 1995-2003 Jean-loup Gailly.
-# For conditions of distribution and use, see copyright notice in zlib.h
-
-# To compile, or to compile and test, type:
-#
-# make -fmakefile.gcc; make test testdll -fmakefile.gcc
-#
-# To use the asm code, type:
-# cp contrib/asm?86/match.S ./match.S
-# make LOC=-DASMV OBJA=match.o -fmakefile.gcc
-#
-# To install libz.a, zconf.h and zlib.h in the system directories, type:
-#
-# make install -fmakefile.gcc
-
-# Note:
-# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN),
-# the DLL name should be changed from "zlib1.dll".
-
-STATICLIB = libz.a
-SHAREDLIB = zlib1.dll
-IMPLIB = libzdll.a
-
-#
-# Set to 1 if shared object needs to be installed
-#
-SHARED_MODE=0
-
-#LOC = -DASMV
-#LOC = -DDEBUG -g
-
-PREFIX =
-CC = $(PREFIX)gcc
-CFLAGS = $(LOC) -O3 -Wall
-EXTRA_CFLAGS = -DNO_VIZ
-
-AS = $(CC)
-ASFLAGS = $(LOC) -Wall
-
-LD = $(CC)
-LDFLAGS = $(LOC)
-
-AR = $(PREFIX)ar
-ARFLAGS = rcs
-
-RC = $(PREFIX)windres
-RCFLAGS = --define GCC_WINDRES
-
-STRIP = $(PREFIX)strip
-
-CP = cp -fp
-# If GNU install is available, replace $(CP) with install.
-INSTALL = $(CP)
-RM = rm -f
-
-prefix = /usr/local
-exec_prefix = $(prefix)
-
-OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
- gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
-OBJA =
-
-all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe
-
-test: example.exe minigzip.exe
- ./example
- echo hello world | ./minigzip | ./minigzip -d
-
-testdll: example_d.exe minigzip_d.exe
- ./example_d
- echo hello world | ./minigzip_d | ./minigzip_d -d
-
-.c.o:
- $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
-
-.S.o:
- $(AS) $(ASFLAGS) -c -o $@ $<
-
-$(STATICLIB): $(OBJS) $(OBJA)
- $(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA)
-
-$(IMPLIB): $(SHAREDLIB)
-
-$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
- $(CC) -shared -Wl,--out-implib,$(IMPLIB) $(LDFLAGS) \
- -o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
- $(STRIP) $@
-
-example.exe: example.o $(STATICLIB)
- $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB)
- $(STRIP) $@
-
-minigzip.exe: minigzip.o $(STATICLIB)
- $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB)
- $(STRIP) $@
-
-example_d.exe: example.o $(IMPLIB)
- $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB)
- $(STRIP) $@
-
-minigzip_d.exe: minigzip.o $(IMPLIB)
- $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB)
- $(STRIP) $@
-
-zlibrc.o: win32/zlib1.rc
- $(RC) $(RCFLAGS) -o $@ win32/zlib1.rc
-
-
-# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set.
-
-.PHONY: install uninstall clean
-
-install: zlib.h zconf.h $(STATICLIB) $(IMPLIB)
- -@mkdir -p $(INCLUDE_PATH)
- -@mkdir -p $(LIBRARY_PATH)
- -if [ "$(SHARED_MODE)" = "1" ]; then \
- mkdir -p $(BINARY_PATH); \
- $(INSTALL) $(SHAREDLIB) $(BINARY_PATH); \
- $(INSTALL) $(IMPLIB) $(LIBRARY_PATH); \
- fi
- -$(INSTALL) zlib.h $(INCLUDE_PATH)
- -$(INSTALL) zconf.h $(INCLUDE_PATH)
- -$(INSTALL) $(STATICLIB) $(LIBRARY_PATH)
-
-uninstall:
- -if [ "$(SHARED_MODE)" = "1" ]; then \
- $(RM) $(BINARY_PATH)/$(SHAREDLIB); \
- $(RM) $(LIBRARY_PATH)/$(IMPLIB); \
- fi
- -$(RM) $(INCLUDE_PATH)/zlib.h
- -$(RM) $(INCLUDE_PATH)/zconf.h
- -$(RM) $(LIBRARY_PATH)/$(STATICLIB)
-
-clean:
- -$(RM) $(STATICLIB)
- -$(RM) $(SHAREDLIB)
- -$(RM) $(IMPLIB)
- -$(RM) *.o
- -$(RM) *.exe
- -$(RM) foo.gz
-
-adler32.o: zlib.h zconf.h
-compress.o: zlib.h zconf.h
-crc32.o: crc32.h zlib.h zconf.h
-deflate.o: deflate.h zutil.h zlib.h zconf.h
-example.o: zlib.h zconf.h
-gzclose.o: zlib.h zconf.h gzguts.h
-gzlib.o: zlib.h zconf.h gzguts.h
-gzread.o: zlib.h zconf.h gzguts.h
-gzwrite.o: zlib.h zconf.h gzguts.h
-inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
-inftrees.o: zutil.h zlib.h zconf.h inftrees.h
-minigzip.o: zlib.h zconf.h
-trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
-uncompr.o: zlib.h zconf.h
-zutil.o: zutil.h zlib.h zconf.h
diff --git a/cpukit/zlib/win32/Makefile.msc b/cpukit/zlib/win32/Makefile.msc
deleted file mode 100644
index fa10a1aa5f..0000000000
--- a/cpukit/zlib/win32/Makefile.msc
+++ /dev/null
@@ -1,157 +0,0 @@
-# Makefile for zlib using Microsoft (Visual) C
-# zlib is copyright (C) 1995-2006 Jean-loup Gailly and Mark Adler
-#
-# Usage:
-# nmake -f win32/Makefile.msc (standard build)
-# nmake -f win32/Makefile.msc LOC=-DFOO (nonstandard build)
-# nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" \
-# OBJA="inffas32.obj match686.obj" (use ASM code, x86)
-# nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF" \
-# OBJA="inffasx64.obj gvmat64.obj inffas8664.c" (use ASM code, x64)
-
-# optional build flags
-LOC =
-
-# variables
-STATICLIB = zlib.lib
-SHAREDLIB = zlib1.dll
-IMPLIB = zdll.lib
-
-CC = cl
-AS = ml
-LD = link
-AR = lib
-RC = rc
-CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
-WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
-ASFLAGS = -coff -Zi $(LOC)
-LDFLAGS = -nologo -debug -incremental:no -opt:ref
-ARFLAGS = -nologo
-RCFLAGS = /dWIN32 /r
-
-OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj \
- gzwrite.obj infback.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
-OBJA =
-
-
-# targets
-all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \
- example.exe minigzip.exe example_d.exe minigzip_d.exe
-
-$(STATICLIB): $(OBJS) $(OBJA)
- $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(OBJA)
-
-$(IMPLIB): $(SHAREDLIB)
-
-$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlib1.res
- $(LD) $(LDFLAGS) -def:win32/zlib.def -dll -implib:$(IMPLIB) \
- -out:$@ -base:0x5A4C0000 $(OBJS) $(OBJA) zlib1.res
- if exist $@.manifest \
- mt -nologo -manifest $@.manifest -outputresource:$@;2
-
-example.exe: example.obj $(STATICLIB)
- $(LD) $(LDFLAGS) example.obj $(STATICLIB)
- if exist $@.manifest \
- mt -nologo -manifest $@.manifest -outputresource:$@;1
-
-minigzip.exe: minigzip.obj $(STATICLIB)
- $(LD) $(LDFLAGS) minigzip.obj $(STATICLIB)
- if exist $@.manifest \
- mt -nologo -manifest $@.manifest -outputresource:$@;1
-
-example_d.exe: example.obj $(IMPLIB)
- $(LD) $(LDFLAGS) -out:$@ example.obj $(IMPLIB)
- if exist $@.manifest \
- mt -nologo -manifest $@.manifest -outputresource:$@;1
-
-minigzip_d.exe: minigzip.obj $(IMPLIB)
- $(LD) $(LDFLAGS) -out:$@ minigzip.obj $(IMPLIB)
- if exist $@.manifest \
- mt -nologo -manifest $@.manifest -outputresource:$@;1
-
-.c.obj:
- $(CC) -c $(WFLAGS) $(CFLAGS) $<
-
-{contrib/masmx64}.c.obj:
- $(CC) -c $(WFLAGS) $(CFLAGS) $<
-
-{contrib/masmx64}.asm.obj:
- $(AS) -c $(ASFLAGS) $<
-
-{contrib/masmx86}.asm.obj:
- $(AS) -c $(ASFLAGS) $<
-
-adler32.obj: adler32.c zlib.h zconf.h
-
-compress.obj: compress.c zlib.h zconf.h
-
-crc32.obj: crc32.c zlib.h zconf.h crc32.h
-
-deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
-
-gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
-
-gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
-
-gzread.obj: gzread.c zlib.h zconf.h gzguts.h
-
-gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
-
-infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h
-
-inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
- inffast.h inffixed.h
-
-inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
-
-trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
-
-uncompr.obj: uncompr.c zlib.h zconf.h
-
-zutil.obj: zutil.c zutil.h zlib.h zconf.h
-
-gvmat64.obj: contrib\masmx64\gvmat64.asm
-
-inffasx64.obj: contrib\masmx64\inffasx64.asm
-
-inffas8664.obj: contrib\masmx64\inffas8664.c zutil.h zlib.h zconf.h \
- inftrees.h inflate.h inffast.h
-
-inffas32.obj: contrib\masmx86\inffas32.asm
-
-match686.obj: contrib\masmx86\match686.asm
-
-example.obj: example.c zlib.h zconf.h
-
-minigzip.obj: minigzip.c zlib.h zconf.h
-
-zlib1.res: win32/zlib1.rc
- $(RC) $(RCFLAGS) /fo$@ win32/zlib1.rc
-
-
-# testing
-test: example.exe minigzip.exe
- example
- echo hello world | minigzip | minigzip -d
-
-testdll: example_d.exe minigzip_d.exe
- example_d
- echo hello world | minigzip_d | minigzip_d -d
-
-
-# cleanup
-clean:
- -del $(STATICLIB)
- -del $(SHAREDLIB)
- -del $(IMPLIB)
- -del *.obj
- -del *.res
- -del *.exp
- -del *.exe
- -del *.pdb
- -del *.manifest
- -del foo.gz
diff --git a/cpukit/zlib/win32/VisualC.txt b/cpukit/zlib/win32/VisualC.txt
deleted file mode 100644
index 579a5fc9e0..0000000000
--- a/cpukit/zlib/win32/VisualC.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-
-To build zlib using the Microsoft Visual C++ environment,
-use the appropriate project from the projects/ directory.
diff --git a/cpukit/zlib/win32/zlib.def b/cpukit/zlib/win32/zlib.def
deleted file mode 100644
index 03df8bf822..0000000000
--- a/cpukit/zlib/win32/zlib.def
+++ /dev/null
@@ -1,74 +0,0 @@
-LIBRARY
-; zlib data compression library
-
-EXPORTS
-; basic functions
- zlibVersion
- deflate
- deflateEnd
- inflate
- inflateEnd
-; advanced functions
- deflateSetDictionary
- deflateCopy
- deflateReset
- deflateParams
- deflateTune
- deflateBound
- deflatePrime
- deflateSetHeader
- inflateSetDictionary
- inflateSync
- inflateCopy
- inflateReset
- inflateReset2
- inflatePrime
- inflateMark
- inflateGetHeader
- inflateBack
- inflateBackEnd
- zlibCompileFlags
-; utility functions
- compress
- compress2
- compressBound
- uncompress
- gzopen
- gzdopen
- gzbuffer
- gzsetparams
- gzread
- gzwrite
- gzprintf
- gzputs
- gzgets
- gzputc
- gzgetc
- gzungetc
- gzflush
- gzseek
- gzrewind
- gztell
- gzoffset
- gzeof
- gzdirect
- gzclose
- gzclose_r
- gzclose_w
- gzerror
- gzclearerr
-; checksum functions
- adler32
- crc32
- adler32_combine
- crc32_combine
-; various hacks, don't look :)
- deflateInit_
- deflateInit2_
- inflateInit_
- inflateInit2_
- inflateBackInit_
- zError
- inflateSyncPoint
- get_crc_table
- inflateUndermine
diff --git a/cpukit/zlib/win32/zlib1.rc b/cpukit/zlib/win32/zlib1.rc
deleted file mode 100644
index 0d1d7ffcf7..0000000000
--- a/cpukit/zlib/win32/zlib1.rc
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <winver.h>
-#include "../zlib.h"
-
-#ifdef GCC_WINDRES
-VS_VERSION_INFO VERSIONINFO
-#else
-VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
-#endif
- FILEVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0
- PRODUCTVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0
- FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
-#ifdef _DEBUG
- FILEFLAGS 1
-#else
- FILEFLAGS 0
-#endif
- FILEOS VOS__WINDOWS32
- FILETYPE VFT_DLL
- FILESUBTYPE 0 // not used
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904E4"
- //language ID = U.S. English, char set = Windows, Multilingual
- BEGIN
- VALUE "FileDescription", "zlib data compression library\0"
- VALUE "FileVersion", ZLIB_VERSION "\0"
- VALUE "InternalName", "zlib1.dll\0"
- VALUE "LegalCopyright", "(C) 1995-2006 Jean-loup Gailly & Mark Adler\0"
- VALUE "OriginalFilename", "zlib1.dll\0"
- VALUE "ProductName", "zlib\0"
- VALUE "ProductVersion", ZLIB_VERSION "\0"
- VALUE "Comments", "For more information visit http://www.zlib.net/\0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x0409, 1252
- END
-END
diff --git a/cpukit/zlib/zconf.h b/cpukit/zlib/zconf.h
index 58880245c1..76be7915e6 100644
--- a/cpukit/zlib/zconf.h
+++ b/cpukit/zlib/zconf.h
@@ -333,11 +333,20 @@
# define FAR
#endif
+#if defined(__rtems__)
+#include <stdint.h>
+
+typedef uint_least8_t Byte;
+typedef uint_least16_t uInt;
+typedef uint_least32_t uLong;
+
+#else
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
+#endif
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
diff --git a/cpukit/zlib/zconf.in.h b/cpukit/zlib/zconf.in.h
deleted file mode 100644
index 03a9431c8b..0000000000
--- a/cpukit/zlib/zconf.in.h
+++ /dev/null
@@ -1,332 +0,0 @@
-/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2005 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#ifndef ZCONF_H
-#define ZCONF_H
-
-/*
- * If you *really* need a unique prefix for all types and library functions,
- * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
- */
-#ifdef Z_PREFIX
-# define deflateInit_ z_deflateInit_
-# define deflate z_deflate
-# define deflateEnd z_deflateEnd
-# define inflateInit_ z_inflateInit_
-# define inflate z_inflate
-# define inflateEnd z_inflateEnd
-# define deflateInit2_ z_deflateInit2_
-# define deflateSetDictionary z_deflateSetDictionary
-# define deflateCopy z_deflateCopy
-# define deflateReset z_deflateReset
-# define deflateParams z_deflateParams
-# define deflateBound z_deflateBound
-# define deflatePrime z_deflatePrime
-# define inflateInit2_ z_inflateInit2_
-# define inflateSetDictionary z_inflateSetDictionary
-# define inflateSync z_inflateSync
-# define inflateSyncPoint z_inflateSyncPoint
-# define inflateCopy z_inflateCopy
-# define inflateReset z_inflateReset
-# define inflateBack z_inflateBack
-# define inflateBackEnd z_inflateBackEnd
-# define compress z_compress
-# define compress2 z_compress2
-# define compressBound z_compressBound
-# define uncompress z_uncompress
-# define adler32 z_adler32
-# define crc32 z_crc32
-# define get_crc_table z_get_crc_table
-# define zError z_zError
-
-# define alloc_func z_alloc_func
-# define free_func z_free_func
-# define in_func z_in_func
-# define out_func z_out_func
-# define Byte z_Byte
-# define uInt z_uInt
-# define uLong z_uLong
-# define Bytef z_Bytef
-# define charf z_charf
-# define intf z_intf
-# define uIntf z_uIntf
-# define uLongf z_uLongf
-# define voidpf z_voidpf
-# define voidp z_voidp
-#endif
-
-#if defined(__MSDOS__) && !defined(MSDOS)
-# define MSDOS
-#endif
-#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
-# define OS2
-#endif
-#if defined(_WINDOWS) && !defined(WINDOWS)
-# define WINDOWS
-#endif
-#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
-# ifndef WIN32
-# define WIN32
-# endif
-#endif
-#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
-# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
-# ifndef SYS16BIT
-# define SYS16BIT
-# endif
-# endif
-#endif
-
-/*
- * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
- * than 64k bytes at a time (needed on systems with 16-bit int).
- */
-#ifdef SYS16BIT
-# define MAXSEG_64K
-#endif
-#ifdef MSDOS
-# define UNALIGNED_OK
-#endif
-
-#ifdef __STDC_VERSION__
-# ifndef STDC
-# define STDC
-# endif
-# if __STDC_VERSION__ >= 199901L
-# ifndef STDC99
-# define STDC99
-# endif
-# endif
-#endif
-#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
-# define STDC
-#endif
-#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
-# define STDC
-#endif
-#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
-# define STDC
-#endif
-#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
-# define STDC
-#endif
-
-#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
-# define STDC
-#endif
-
-#ifndef STDC
-# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
-# define const /* note: need a more gentle solution here */
-# endif
-#endif
-
-/* Some Mac compilers merge all .h files incorrectly: */
-#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
-# define NO_DUMMY_DECL
-#endif
-
-/* Maximum value for memLevel in deflateInit2 */
-#ifndef MAX_MEM_LEVEL
-# ifdef MAXSEG_64K
-# define MAX_MEM_LEVEL 8
-# else
-# define MAX_MEM_LEVEL 9
-# endif
-#endif
-
-/* Maximum value for windowBits in deflateInit2 and inflateInit2.
- * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
- * created by gzip. (Files created by minigzip can still be extracted by
- * gzip.)
- */
-#ifndef MAX_WBITS
-# define MAX_WBITS 15 /* 32K LZ77 window */
-#endif
-
-/* The memory requirements for deflate are (in bytes):
- (1 << (windowBits+2)) + (1 << (memLevel+9))
- that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
- plus a few kilobytes for small objects. For example, if you want to reduce
- the default memory requirements from 256K to 128K, compile with
- make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
- Of course this will generally degrade compression (there's no free lunch).
-
- The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus a few kilobytes
- for small objects.
-*/
-
- /* Type declarations */
-
-#ifndef OF /* function prototypes */
-# ifdef STDC
-# define OF(args) args
-# else
-# define OF(args) ()
-# endif
-#endif
-
-/* The following definitions for FAR are needed only for MSDOS mixed
- * model programming (small or medium model with some far allocations).
- * This was tested only with MSC; for other MSDOS compilers you may have
- * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
- * just define FAR to be empty.
- */
-#ifdef SYS16BIT
-# if defined(M_I86SM) || defined(M_I86MM)
- /* MSC small or medium model */
-# define SMALL_MEDIUM
-# ifdef _MSC_VER
-# define FAR _far
-# else
-# define FAR far
-# endif
-# endif
-# if (defined(__SMALL__) || defined(__MEDIUM__))
- /* Turbo C small or medium model */
-# define SMALL_MEDIUM
-# ifdef __BORLANDC__
-# define FAR _far
-# else
-# define FAR far
-# endif
-# endif
-#endif
-
-#if defined(WINDOWS) || defined(WIN32)
- /* If building or using zlib as a DLL, define ZLIB_DLL.
- * This is not mandatory, but it offers a little performance increase.
- */
-# ifdef ZLIB_DLL
-# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
-# ifdef ZLIB_INTERNAL
-# define ZEXTERN extern __declspec(dllexport)
-# else
-# define ZEXTERN extern __declspec(dllimport)
-# endif
-# endif
-# endif /* ZLIB_DLL */
- /* If building or using zlib with the WINAPI/WINAPIV calling convention,
- * define ZLIB_WINAPI.
- * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
- */
-# ifdef ZLIB_WINAPI
-# ifdef FAR
-# undef FAR
-# endif
-# include <windows.h>
- /* No need for _export, use ZLIB.DEF instead. */
- /* For complete Windows compatibility, use WINAPI, not __stdcall. */
-# define ZEXPORT WINAPI
-# ifdef WIN32
-# define ZEXPORTVA WINAPIV
-# else
-# define ZEXPORTVA FAR CDECL
-# endif
-# endif
-#endif
-
-#if defined (__BEOS__)
-# ifdef ZLIB_DLL
-# ifdef ZLIB_INTERNAL
-# define ZEXPORT __declspec(dllexport)
-# define ZEXPORTVA __declspec(dllexport)
-# else
-# define ZEXPORT __declspec(dllimport)
-# define ZEXPORTVA __declspec(dllimport)
-# endif
-# endif
-#endif
-
-#ifndef ZEXTERN
-# define ZEXTERN extern
-#endif
-#ifndef ZEXPORT
-# define ZEXPORT
-#endif
-#ifndef ZEXPORTVA
-# define ZEXPORTVA
-#endif
-
-#ifndef FAR
-# define FAR
-#endif
-
-#if !defined(__MACTYPES__)
-typedef unsigned char Byte; /* 8 bits */
-#endif
-typedef unsigned int uInt; /* 16 bits or more */
-typedef unsigned long uLong; /* 32 bits or more */
-
-#ifdef SMALL_MEDIUM
- /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
-# define Bytef Byte FAR
-#else
- typedef Byte FAR Bytef;
-#endif
-typedef char FAR charf;
-typedef int FAR intf;
-typedef uInt FAR uIntf;
-typedef uLong FAR uLongf;
-
-#ifdef STDC
- typedef void const *voidpc;
- typedef void FAR *voidpf;
- typedef void *voidp;
-#else
- typedef Byte const *voidpc;
- typedef Byte FAR *voidpf;
- typedef Byte *voidp;
-#endif
-
-#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
-# include <sys/types.h> /* for off_t */
-# include <unistd.h> /* for SEEK_* and off_t */
-# ifdef VMS
-# include <unixio.h> /* for off_t */
-# endif
-# define z_off_t off_t
-#endif
-#ifndef SEEK_SET
-# define SEEK_SET 0 /* Seek from beginning of file. */
-# define SEEK_CUR 1 /* Seek from current position. */
-# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
-#endif
-#ifndef z_off_t
-# define z_off_t long
-#endif
-
-#if defined(__OS400__)
-# define NO_vsnprintf
-#endif
-
-#if defined(__MVS__)
-# define NO_vsnprintf
-# ifdef FAR
-# undef FAR
-# endif
-#endif
-
-/* MVS linker does not support external names larger than 8 bytes */
-#if defined(__MVS__)
-# pragma map(deflateInit_,"DEIN")
-# pragma map(deflateInit2_,"DEIN2")
-# pragma map(deflateEnd,"DEEND")
-# pragma map(deflateBound,"DEBND")
-# pragma map(inflateInit_,"ININ")
-# pragma map(inflateInit2_,"ININ2")
-# pragma map(inflateEnd,"INEND")
-# pragma map(inflateSync,"INSY")
-# pragma map(inflateSetDictionary,"INSEDI")
-# pragma map(compressBound,"CMBND")
-# pragma map(inflate_table,"INTABL")
-# pragma map(inflate_fast,"INFA")
-# pragma map(inflate_copyright,"INCOPY")
-#endif
-
-#endif /* ZCONF_H */